Skip to content

Commit

Permalink
make topics/payloads of default pubsub module type safe and extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
adrtivv committed Dec 27, 2024
1 parent 0c7a426 commit 2e32328
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,21 @@ import { Readable } from 'stream'
type Mercurius = typeof mercurius

declare namespace mercurius {
export interface PubSub {
subscribe<TResult = any>(topics: string | string[]): Promise<Readable & AsyncIterableIterator<TResult>>;
publish<TResult = any>(event: { topic: string; payload: TResult }, callback?: () => void): void;
export interface PubSubTopics {
[topic: string]: any;
}

export interface PubSub<TPubSubTopics extends PubSubTopics = PubSubTopics> {
subscribe<TTopic extends Extract<keyof TPubSubTopics,string>>(

Check failure on line 31 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

A space is required after ','

Check failure on line 31 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

A space is required after ','

Check failure on line 31 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macOS-latest)

A space is required after ','

Check failure on line 31 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, ubuntu-latest)

A space is required after ','

Check failure on line 31 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, windows-latest)

A space is required after ','

Check failure on line 31 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, macOS-latest)

A space is required after ','
topics: TTopic| TTopic[],

Check failure on line 32 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

Operator '|' must be spaced

Check failure on line 32 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Operator '|' must be spaced

Check failure on line 32 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macOS-latest)

Operator '|' must be spaced

Check failure on line 32 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, ubuntu-latest)

Operator '|' must be spaced

Check failure on line 32 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, windows-latest)

Operator '|' must be spaced

Check failure on line 32 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, macOS-latest)

Operator '|' must be spaced
): Promise<Readable & AsyncIterableIterator<TPubSubTopics[TTopic]>>;
publish<TTopic extends Extract<keyof TPubSubTopics, string>>(
event: {

Check failure on line 35 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 35 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Trailing spaces not allowed

Check failure on line 35 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macOS-latest)

Trailing spaces not allowed

Check failure on line 35 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 35 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, windows-latest)

Trailing spaces not allowed

Check failure on line 35 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, macOS-latest)

Trailing spaces not allowed
topic: TTopic;

Check failure on line 36 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 36 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Trailing spaces not allowed

Check failure on line 36 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macOS-latest)

Trailing spaces not allowed

Check failure on line 36 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 36 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, windows-latest)

Trailing spaces not allowed

Check failure on line 36 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, macOS-latest)

Trailing spaces not allowed
payload: TPubSubTopics[TTopic];
},

Check failure on line 38 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 38 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, windows-latest)

Trailing spaces not allowed

Check failure on line 38 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (20.x, macOS-latest)

Trailing spaces not allowed

Check failure on line 38 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, ubuntu-latest)

Trailing spaces not allowed

Check failure on line 38 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, windows-latest)

Trailing spaces not allowed

Check failure on line 38 in index.d.ts

View workflow job for this annotation

GitHub Actions / test (22.x, macOS-latest)

Trailing spaces not allowed
callback?: () => void,
): void;
}

export interface MercuriusContext {
Expand Down

0 comments on commit 2e32328

Please sign in to comment.