export namespace SharedWorker { export type ProtocolIdentifier = 'ava-4'; export type FactoryOptions = { negotiateProtocol (supported: readonly ['ava-4']): Protocol; // Add overloads for additional protocols. }; export type Factory = (options: FactoryOptions) => void; export type Protocol = { readonly initialData: Data; readonly protocol: 'ava-4'; broadcast: (data: Data) => BroadcastMessage; ready: () => Protocol; subscribe: () => AsyncIterableIterator>; testWorkers: () => AsyncIterableIterator>; }; export type BroadcastMessage = { readonly id: string; replies: () => AsyncIterableIterator>; }; export type PublishedMessage = { readonly id: string; replies: () => AsyncIterableIterator>; }; export type ReceivedMessage = { readonly data: Data; readonly id: string; readonly testWorker: TestWorker; reply: (data: Data) => PublishedMessage; }; export type TestWorker = { readonly id: string; readonly file: string; publish: (data: Data) => PublishedMessage; subscribe: () => AsyncIterableIterator>; teardown: (fn: (() => Promise) | (() => void)) => () => Promise; }; export namespace Plugin { export type RegistrationOptions = { readonly filename: string | URL; readonly initialData?: Data; readonly supportedProtocols: readonly Identifier[]; readonly teardown?: () => void; }; export type Protocol = { readonly available: Promise; readonly currentlyAvailable: boolean; readonly protocol: 'ava-4'; publish: (data: Data) => PublishedMessage; subscribe: () => AsyncIterableIterator>; }; export type PublishedMessage = { readonly id: string; replies: () => AsyncIterableIterator>; }; export type ReceivedMessage = { readonly data: Data; readonly id: string; reply: (data: Data) => PublishedMessage; }; } }