@nymphjs/client
Version:
Nymph.js - Client
64 lines (63 loc) • 3.46 kB
TypeScript
import Nymph from './Nymph.js';
import type { NymphOptions, Options, Selector } from './Nymph.types.js';
import type { EntityInstanceType } from './Entity.js';
import type { EntityConstructor, EntityInterface } from './Entity.types.js';
import type { PubSubCallbacks, PubSubConnectCallback, PubSubCountCallback, PubSubDisconnectCallback, PubSubEventType, PubSubRejectCallback, PubSubResolveCallback, PubSubErrorCallback, PubSubSubscribable, PubSubUpdate } from './PubSub.types.js';
export default class PubSub {
private nymph;
private authToken;
private switchToken;
private connection;
private waitForConnectionTimeout;
private pubsubUrl;
private WebSocket;
private subscriptions;
private connectCallbacks;
private disconnectCallbacks;
private errorCallbacks;
private noConsole;
constructor(nymphOptions: NymphOptions, nymph: Nymph);
subscribeEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
return: 'guid';
}, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<string[]>>;
subscribeEntities<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<EntityInstanceType<T>[]>>;
subscribeEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T> & {
return: 'guid';
}, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<string | null>>;
subscribeEntity<T extends EntityConstructor = EntityConstructor>(options: Options<T>, ...selectors: Selector[]): PubSubSubscribable<PubSubUpdate<EntityInstanceType<T> | null>>;
subscribeUID(name: string): (resolve?: PubSubResolveCallback<number> | undefined, reject?: PubSubRejectCallback | undefined, count?: PubSubCountCallback | undefined) => {
unsubscribe: () => void;
};
subscribeWith<T extends EntityInterface>(entity: T, resolve?: PubSubResolveCallback<T> | undefined, reject?: PubSubRejectCallback | undefined, count?: PubSubCountCallback | undefined): PubSubSubscription<T>;
connect(): void;
close(): void;
private _waitForConnection;
private _attemptConnect;
private _onopen;
private _onmessage;
private _onclose;
private _send;
isConnectionOpen(): boolean;
isConnectionConnecting(): boolean;
isConnection(): boolean;
private _subscribeQuery;
private _subscribeUID;
private _sendQuery;
private _sendUID;
private _isCountSubscribedQuery;
private _isCountSubscribedUID;
private _unsubscribeQuery;
private _unsubscribeUID;
private _sendUnQuery;
private _sendUnUID;
updateArray(current: EntityInterface[], update: PubSubUpdate<EntityInterface[]>): void;
on<T extends PubSubEventType>(event: T, callback: T extends 'connect' ? PubSubConnectCallback : T extends 'disconnect' ? PubSubDisconnectCallback : T extends 'error' ? PubSubErrorCallback : never): () => boolean;
off<T extends PubSubEventType>(event: T, callback: T extends 'connect' ? PubSubConnectCallback : T extends 'disconnect' ? PubSubDisconnectCallback : T extends 'error' ? PubSubErrorCallback : never): boolean;
authenticate(authToken: string | null, switchToken?: string | null): void;
}
export declare class PubSubSubscription<T> {
query: string;
callbacks: PubSubCallbacks<T>;
unsubscribe: () => void;
constructor(query: string, callbacks: PubSubCallbacks<T>, unsubscribe: () => void);
}