mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
SDK Fixes websocket subscription output typing (#19791)
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
This commit is contained in:
5
.changeset/polite-pears-exercise.md
Normal file
5
.changeset/polite-pears-exercise.md
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@directus/sdk": patch
|
||||
---
|
||||
|
||||
Fixed WebSocket subscription output typing in the SDK
|
||||
@@ -226,7 +226,7 @@ export function realtime(config: WebSocketConfig = {}) {
|
||||
|
||||
socket?.send(JSON.stringify(message));
|
||||
},
|
||||
async subscribe<Collection extends keyof Schema, Options extends SubscribeOptions<Schema, Collection>>(
|
||||
async subscribe<Collection extends keyof Schema, const Options extends SubscribeOptions<Schema, Collection>>(
|
||||
collection: Collection,
|
||||
options = {} as Options
|
||||
) {
|
||||
|
||||
@@ -34,7 +34,7 @@ export interface WebSocketClient<Schema extends object> {
|
||||
onWebSocket(event: 'message', callback: (this: WebSocket, ev: any) => any): RemoveEventHandler;
|
||||
onWebSocket(event: WebSocketEvents, callback: WebSocketEventHandler): RemoveEventHandler;
|
||||
sendMessage(message: string | Record<string, any>): void;
|
||||
subscribe<Collection extends keyof Schema, Options extends SubscribeOptions<Schema, Collection>>(
|
||||
subscribe<Collection extends keyof Schema, const Options extends SubscribeOptions<Schema, Collection>>(
|
||||
collection: Collection,
|
||||
options?: Options
|
||||
): Promise<{
|
||||
@@ -64,9 +64,12 @@ export type SubscriptionOutput<
|
||||
TItem = TQuery extends Query<Schema, Schema[Collection]>
|
||||
? ApplyQueryFields<Schema, CollectionType<Schema, Collection>, TQuery['fields']>
|
||||
: Partial<Schema[Collection]>
|
||||
> = { type: 'subscription' } & {
|
||||
[Event in Events]: SubscriptionPayload<TItem>[Event];
|
||||
}[Events];
|
||||
> = { type: 'subscription'; uid?: string } & (
|
||||
| {
|
||||
[Event in Events]: { event: Event; data: SubscriptionPayload<TItem>[Event] };
|
||||
}[Events]
|
||||
| { event: 'error'; error: { code: string; message: string } }
|
||||
);
|
||||
|
||||
export type SubscriptionPayload<Item> = {
|
||||
init: Item[];
|
||||
|
||||
Reference in New Issue
Block a user