Skip to content

Commit

Permalink
Update dependencies; more type tweaks
Browse files Browse the repository at this point in the history
* Upgrade to TypeScript 4.8. Keep testing with 4.7 to ensure backwards compatibility.
* Update dev dependencies
* Update dependencies
* Tweak type definitions used in exports map for TS 4.8 compatibility. Duplicate and export shared types where appropriate, but don't export from the other export file since it seems to confuse things.
  • Loading branch information
novemberborn authored Sep 25, 2022
1 parent 3ebe65c commit 48dcafa
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 150 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
ts-version: [~4.7]
ts-version: [~4.7, ~4.8]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
Expand Down
14 changes: 12 additions & 2 deletions entrypoints/main.d.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,12 @@
export * from './main.cjs';
export {default} from './main.cjs';
import type {TestFn} from '../types/test-fn.cjs';

export * from '../types/assertions.cjs';
export * from '../types/try-fn.cjs';
export * from '../types/test-fn.cjs';
export * from '../types/subscribable.cjs';

/** Call to declare a test, or chain to declare hooks or test modifiers */
declare const test: TestFn;

/** Call to declare a test, or chain to declare hooks or test modifiers */
export default test;
77 changes: 3 additions & 74 deletions entrypoints/plugin.d.cts
Original file line number Diff line number Diff line change
@@ -1,77 +1,6 @@
import type {URL} from 'node:url';

export namespace SharedWorker {
export type ProtocolIdentifier = 'ava-4';

export type FactoryOptions = {
negotiateProtocol <Data = unknown>(supported: readonly ['ava-4']): Protocol<Data>;
// Add overloads for additional protocols.
};

export type Factory = (options: FactoryOptions) => void;

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>>;
};

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: (fn: (() => Promise<void>) | (() => void)) => () => Promise<void>;
};

export namespace Plugin {
export type RegistrationOptions<Identifier extends ProtocolIdentifier, Data = unknown> = {
readonly filename: string | URL;
readonly initialData?: Data;
readonly supportedProtocols: readonly Identifier[];
readonly teardown?: () => void;
};

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>>;
};

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>;
};
}
}
import type {SharedWorker} from '../types/shared-worker.cjs';

export function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol<Data>;
// Add overloads for additional protocols.

export type {SharedWorker} from '../types/shared-worker.cjs';
7 changes: 6 additions & 1 deletion entrypoints/plugin.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export type * from './plugin.cjs';
import type {SharedWorker} from '../types/shared-worker.cjs';

export function registerSharedWorker<Data = unknown>(options: SharedWorker.Plugin.RegistrationOptions<'ava-4', Data>): SharedWorker.Plugin.Protocol<Data>;
// Add overloads for additional protocols.

export type {SharedWorker} from '../types/shared-worker.cjs';
Loading

0 comments on commit 48dcafa

Please sign in to comment.