forked from avajs/ava
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plugin.d.ts
79 lines (67 loc) · 2.55 KB
/
plugin.d.ts
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
export namespace SharedWorker {
export type ProtocolIdentifier = 'experimental';
export type FactoryOptions = {
negotiateProtocol <Data = unknown>(supported: readonly ['experimental']): Experimental.Protocol<Data>;
// Add overloads for additional protocols.
};
export type Factory = (options: FactoryOptions) => void;
export namespace Experimental {
export type Protocol<Data = unknown> = {
readonly initialData: Data;
readonly protocol: 'experimental';
broadcast: (data: Data) => BroadcastMessage<Data>;
ready: () => Protocol<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
testWorkers: () => AsyncIterableIterator<TestWorker<Data>>;
};
export type BroadcastMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
export type PublishedMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
export type ReceivedMessage<Data = unknown> = {
readonly data: Data;
readonly id: string;
readonly testWorker: TestWorker;
reply: (data: Data) => PublishedMessage<Data>;
};
export type TestWorker<Data = unknown> = {
readonly id: string;
readonly file: string;
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
teardown: <TeardownFn extends () => void> (fn: TeardownFn) => TeardownFn;
};
}
export namespace Plugin {
export type RegistrationOptions<Identifier extends ProtocolIdentifier, Data = unknown> = {
readonly filename: string;
readonly initialData?: Data;
readonly supportedProtocols: readonly Identifier[];
readonly teardown?: () => void;
};
export namespace Experimental {
export type Protocol<Data = unknown> = {
readonly available: Promise<void>;
readonly currentlyAvailable: boolean;
readonly protocol: 'experimental';
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
export type PublishedMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
export type ReceivedMessage<Data = unknown> = {
readonly data: Data;
readonly id: string;
reply: (data: Data) => PublishedMessage<Data>;
};
}
}
}
export function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'experimental', Data>): SharedWorker.Plugin.Experimental.Protocol<Data>;
// Add overloads for additional protocols.