Files
codeql-action/node_modules/ava/plugin.d.ts
T

78 lines
2.4 KiB
TypeScript
Raw Normal View History

2022-02-01 18:01:11 +00:00
import {URL} from 'node:url';
2021-10-21 15:24:20 -07:00
export namespace SharedWorker {
2022-02-01 18:01:11 +00:00
export type ProtocolIdentifier = 'ava-4';
2021-10-21 15:24:20 -07:00
export type FactoryOptions = {
2022-02-01 18:01:11 +00:00
negotiateProtocol <Data = unknown>(supported: readonly ['ava-4']): Protocol<Data>;
2021-10-21 15:24:20 -07:00
// Add overloads for additional protocols.
};
export type Factory = (options: FactoryOptions) => void;
2022-02-01 18:01:11 +00:00
export type Protocol<Data = unknown> = {
readonly initialData: Data;
readonly protocol: 'ava-4';
broadcast: (data: Data) => BroadcastMessage<Data>;
ready: () => Protocol<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
testWorkers: () => AsyncIterableIterator<TestWorker<Data>>;
};
2021-10-21 15:24:20 -07:00
2022-02-01 18:01:11 +00:00
export type BroadcastMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
2021-10-21 15:24:20 -07:00
2022-02-01 18:01:11 +00:00
export type PublishedMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
2021-10-21 15:24:20 -07:00
2022-02-01 18:01:11 +00:00
export type ReceivedMessage<Data = unknown> = {
readonly data: Data;
readonly id: string;
readonly testWorker: TestWorker;
reply: (data: Data) => PublishedMessage<Data>;
};
2021-10-21 15:24:20 -07:00
2022-02-01 18:01:11 +00:00
export type TestWorker<Data = unknown> = {
readonly id: string;
readonly file: string;
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
2022-09-02 18:02:07 +01:00
teardown: (fn: (() => Promise<void>) | (() => void)) => () => Promise<void>;
2022-02-01 18:01:11 +00:00
};
2021-10-21 15:24:20 -07:00
export namespace Plugin {
export type RegistrationOptions<Identifier extends ProtocolIdentifier, Data = unknown> = {
2022-02-01 18:01:11 +00:00
readonly filename: string | URL;
2021-10-21 15:24:20 -07:00
readonly initialData?: Data;
readonly supportedProtocols: readonly Identifier[];
readonly teardown?: () => void;
};
2022-02-01 18:01:11 +00:00
export type Protocol<Data = unknown> = {
readonly available: Promise<void>;
readonly currentlyAvailable: boolean;
readonly protocol: 'ava-4';
publish: (data: Data) => PublishedMessage<Data>;
subscribe: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
2021-10-21 15:24:20 -07:00
2022-02-01 18:01:11 +00:00
export type PublishedMessage<Data = unknown> = {
readonly id: string;
replies: () => AsyncIterableIterator<ReceivedMessage<Data>>;
};
2021-10-21 15:24:20 -07:00
2022-02-01 18:01:11 +00:00
export type ReceivedMessage<Data = unknown> = {
readonly data: Data;
readonly id: string;
reply: (data: Data) => PublishedMessage<Data>;
};
2021-10-21 15:24:20 -07:00
}
}
2022-02-01 18:01:11 +00:00
export function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol<Data>;
2021-10-21 15:24:20 -07:00
// Add overloads for additional protocols.