Skip to content

Commit

Permalink
Add LiveObjects access and subscription public API to the ably.d.ts
Browse files Browse the repository at this point in the history
This is barebones public API definitions (missing documentation) to
enable LiveObjects plugin package tests and TypeScript checks.
  • Loading branch information
VeskeR committed Nov 22, 2024
1 parent 245b6a2 commit 3281744
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion ably.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2028,7 +2028,44 @@ export declare interface PushChannel {
/**
* Enables the LiveObjects state to be subscribed to for a channel.
*/
export declare interface LiveObjects {}
export declare interface LiveObjects {
getRoot(): Promise<LiveMap>;
}

// TODO: document public API for LiveObjects

export declare interface LiveMap extends LiveObject<LiveMapUpdate> {
get(key: string): LiveObject | StateValue | undefined;
size(): number;
}

export declare interface LiveMapUpdate extends LiveObjectUpdate {
update: { [keyName: string]: 'updated' | 'removed' };
}

export type StateValue = string | number | boolean | Buffer | Uint8Array;

export declare interface LiveCounter extends LiveObject<LiveCounterUpdate> {
value(): number;
}

export declare interface LiveCounterUpdate extends LiveObjectUpdate {
update: { inc: number };
}

export declare interface LiveObject<TUpdate extends LiveObjectUpdate = LiveObjectUpdate> {
subscribe(listener: (update: TUpdate) => void): SubscribeResponse;
unsubscribe(listener: (update: TUpdate) => void): void;
unsubscribeAll(): void;
}

export declare interface LiveObjectUpdate {
update: any;
}

export declare interface SubscribeResponse {
unsubscribe(): void;
}

/**
* Enables messages to be published and historic messages to be retrieved for a channel.
Expand Down

0 comments on commit 3281744

Please sign in to comment.