-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathraycast-api-mock.ts
More file actions
80 lines (65 loc) · 1.99 KB
/
Copy pathraycast-api-mock.ts
File metadata and controls
80 lines (65 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
type Listener = () => void;
const stores = new Map<string, Map<string, string>>();
const listeners = new Map<string, Set<Listener>>();
export class Cache {
private readonly namespace: string;
constructor(options?: { namespace?: string }) {
this.namespace = options?.namespace || "root";
}
get = (key: string) => stores.get(this.namespace)?.get(key);
set = (key: string, value: string) => {
let store = stores.get(this.namespace);
if (!store) {
store = new Map();
stores.set(this.namespace, store);
}
store.set(key, value);
listeners.get(this.namespace)?.forEach((listener) => listener());
};
subscribe = (listener: Listener) => {
let namespaceListeners = listeners.get(this.namespace);
if (!namespaceListeners) {
namespaceListeners = new Set();
listeners.set(this.namespace, namespaceListeners);
}
namespaceListeners.add(listener);
return () => namespaceListeners.delete(listener);
};
}
export function resetMockCache() {
stores.clear();
listeners.clear();
}
export function getMockCacheEntryCount() {
return Array.from(stores.values()).reduce((count, store) => count + store.size, 0);
}
export const environment = {
assetsPath: process.cwd(),
commandMode: "view",
isDevelopment: true,
launchType: "background",
supportPath: process.cwd(),
};
export const LaunchType = { Background: "background" };
export const Toast = { Style: { Failure: "failure" } };
export const Clipboard = { copy() {} };
export function open() {}
export async function showToast() {}
type PKCEClientOptions = {
redirectMethod: string;
providerName: string;
providerIcon?: unknown;
providerId?: string;
description?: string;
};
class MockPKCEClient {
options: PKCEClientOptions;
constructor(options: PKCEClientOptions) {
this.options = options;
}
}
export const OAuth = {
RedirectMethod: { Web: "web", App: "app", AppURI: "appURI" },
PKCEClient: MockPKCEClient,
};
export const Color = { PrimaryText: "raycast-primary-text" };