UNPKG

socio

Version:

A WebSocket Real-Time Communication (RTC) API framework.

126 lines (125 loc) 5.25 kB
import * as diff_lib from 'recursive-diff'; import { LogHandler } from './logging.js'; import { ServerMessageKind } from './utils.js'; import type { id, PropKey, PropValue, PropOpts, Bit, ClientLifecycleHooks, ClientID, SocioFiles, LoggingOpts, ClientSubscribeOpts, data_result_block, discovery_resp_obj } from './types.d.ts'; import type { data_base, C_RES_data, C_AUTH_data } from './types.d.ts'; import type { RateLimit } from './ratelimit.js'; type SubscribeCallbackObjectSuccess = ((res: object | object[]) => void) | null; export type ProgressOnUpdate = (percentage: number) => void; type PropUpdateCallback = ((new_val: PropValue, diff?: diff_lib.rdiffResult[]) => void) | null; export type ClientProp = { val: PropValue | undefined; subs: { [id: id]: PropUpdateCallback; }; }; export type SocioClientOptions = { name?: string; keep_alive?: boolean; reconnect_tries?: number; persistent?: boolean; hooks?: Partial<ClientLifecycleHooks>; allow_rpc?: boolean; } & LoggingOpts; type DiscoveryBy = 'ID' | 'NAME' | 'AS_ARRAY'; type DiscoveryReturn = { ID: discovery_resp_obj; NAME: { [nameOrId: string]: { id: string; name?: string; ip: string; [key: string]: any; }; }; AS_ARRAY: { id: string; name?: string; ip: string; [key: string]: any; }[]; }; type PropSubOpts = { rate_limit?: RateLimit | null; receive_initial_update?: boolean; }; export declare class SocioClient extends LogHandler { #private; config: SocioClientOptions; key_generator: (() => number | string) | undefined; lifecycle_hooks: ClientLifecycleHooks; rpc_dict: { [f_name: string]: Function; }; constructor(url: string, { name, logging, keep_alive, reconnect_tries, persistent, hooks, allow_rpc, }?: SocioClientOptions); Send(kind: ServerMessageKind, ...data: any[]): void; SendFiles(files: File[], other_data?: object | undefined): Promise<C_RES_data>; SendBinary(blob: Blob | ArrayBuffer | ArrayBufferView): Promise<unknown>; CreateQueryPromise(): { id: id; prom: Promise<unknown>; }; Serv(data: any): Promise<unknown>; GetFiles(data: any): Promise<File[] | null>; Ping(id_num?: undefined): void; DiscoverSessions<K extends DiscoveryBy>(by?: K): Promise<DiscoveryReturn[K]>; UnsubscribeAll({ props, queries, force }?: { props?: boolean | undefined; queries?: boolean | undefined; force?: boolean | undefined; }): void; IdentifySelf(name: string): Promise<data_base & data_result_block>; Subscribe({ sql, endpoint, params }?: ClientSubscribeOpts, onUpdate?: SubscribeCallbackObjectSuccess, status_callbacks?: { error?: (e: string) => void; }, rate_limit?: RateLimit | null): id | null; Unsubscribe(sub_id: id, force?: boolean): Promise<false | Bit>; Query(sql: string, params?: object | null | Array<any>, { sql_is_endpoint, onUpdate, freq_ms }?: { sql_is_endpoint?: boolean; onUpdate?: ProgressOnUpdate; freq_ms?: number; }): Promise<unknown>; SetProp(prop_name: PropKey, new_val: PropValue, prop_upd_as_diff?: boolean): Promise<data_base & data_result_block> | null; GetProp(prop_name: PropKey, local?: boolean): Promise<any> | { result: { success: number; res: PropValue; }; }; SubscribeProp(prop_name: PropKey, onUpdate: PropUpdateCallback, { rate_limit, receive_initial_update }?: PropSubOpts): Promise<{ id: id; result: { success: Bit; }; } | any>; UnsubscribeProp(prop_name: PropKey, force?: boolean): Promise<false | Bit>; RegisterProp(prop_name: PropKey | undefined | null, initial_value?: any, prop_reg_opts?: Omit<PropOpts, "observationaly_temporary">): Promise<{ prop: PropKey; }> | null; Prop(prop_name: PropKey, { prop_sub_opts, prop_upd_as_diff }?: { prop_sub_opts?: PropSubOpts; prop_upd_as_diff?: boolean; }): Promise<any>; Authenticate(params?: object): Promise<C_AUTH_data>; get authenticated(): boolean; AskPermission(verb?: string, table?: string): Promise<boolean>; RPC(target_client: ClientID | string | null, f_name: string, ...args: any[]): Promise<any>; get GenKey(): id; get client_id(): string; get web_socket(): WebSocket | null; get client_address_info(): { url: string | undefined; protocol: string | undefined; extensions: string | undefined; }; get latency(): number; ready(): Promise<boolean>; Close(): void; RefreshReconToken(name?: string): Promise<void>; LogMaps(): void; TrackProgressOfQueryPromise(prom: Promise<any>, onUpdate: ProgressOnUpdate, freq_ms?: number): NodeJS.Timeout | null; TrackProgressOfQueryID(query_id: id, onUpdate: ProgressOnUpdate, freq_ms?: number): NodeJS.Timeout | null; } export declare function ParseSocioFiles(files: SocioFiles): File[]; export declare function SocioFileBase64ToUint8Array(base64?: string): Uint8Array; export declare function Uint8ArrayToSocioFileBase64(file_bin: ArrayBuffer, chunkSize?: number): string; export {};