socio
Version:
A WebSocket Real-Time Communication (RTC) API framework.
89 lines (88 loc) • 3.6 kB
TypeScript
import { WebSocketServer } from 'ws';
import { LogHandler } from './logging.js';
import { type SocioSecurity } from './secure.js';
import { SocioSession, type SubObj } from './core-session.js';
import { ClientMessageKind } from './utils.js';
import type { ServerOptions, AddressInfo } from 'ws';
import type { id, PropKey, PropValue, PropAssigner, PropOpts, ClientID, ServerLifecycleHooks, LoggingOpts, Bit, SessionOpts } from './types.d.ts';
import type { RateLimit } from './ratelimit.js';
export type QueryFuncParams = {
id?: id;
sql: string;
params?: any;
};
export type QueryFunction = (client: SocioSession, id: id, sql: string, params?: any) => Promise<object>;
type SessionsDefaults = {
timeouts: boolean;
timeouts_check_interval_ms?: number;
session_delete_delay_ms?: number;
recon_ttl_ms?: number;
} & SessionOpts;
type DecryptOptions = {
decrypt_sql: boolean;
decrypt_prop: boolean;
decrypt_endpoint: boolean;
};
type DBOpts = {
Query?: QueryFunction;
Arbiter?: (initiator: {
client: SocioSession;
sql: string;
params: any;
}, current: {
client: SocioSession;
hook: SubObj;
}) => boolean | Promise<boolean>;
allowed_SQL_verbs?: string[];
};
type SocioServerOptions = {
db: DBOpts;
socio_security?: SocioSecurity | null;
decrypt_opts?: DecryptOptions;
allow_discovery?: boolean;
allow_rpc?: boolean;
hard_crash?: boolean;
session_defaults?: SessionsDefaults;
prop_upd_diff?: boolean;
auto_recon_by_ip?: boolean;
send_sensitive_error_msgs_to_client?: boolean;
hooks?: Partial<ServerLifecycleHooks>;
[key: string]: any;
} & LoggingOpts;
export declare class SocioServer extends LogHandler {
#private;
db: DBOpts;
session_defaults: SessionsDefaults;
lifecycle_hooks: ServerLifecycleHooks;
prop_reg_timeout_ms: number;
auto_recon_by_ip: boolean;
send_sensitive_error_msgs_to_client: boolean;
allow_rpc: boolean;
constructor(opts: ServerOptions | undefined, { db, socio_security, allow_discovery, allow_rpc, logging, decrypt_opts, session_defaults, prop_upd_diff, prop_reg_timeout_ms, auto_recon_by_ip, send_sensitive_error_msgs_to_client, hooks, }: SocioServerOptions);
get new_global_id(): number;
Update(initiator: SocioSession, sql: string, params: object | null): Promise<void>;
RegisterRateLimit(f_name: string, ratelimit?: RateLimit | null): void;
UnRegisterRateLimit(f_name: string): void;
get RateLimitNames(): string[];
GetClientSession(client_id?: string): SocioSession | undefined;
RegisterProp(key: PropKey, val: PropValue, { assigner, client_writable, send_as_diff, emit_to_sender, observationaly_temporary }?: {
assigner?: PropAssigner;
} & PropOpts): void;
UnRegisterProp(key: PropKey): void;
GetPropVal(key: PropKey): PropValue | undefined;
UpdatePropVal(key: PropKey, new_val: PropValue, sender_client_id: ClientID | null, send_as_diff?: boolean): Bit;
SetPropVal(key: PropKey, new_val: PropValue): boolean;
SendToClients(clients?: (ClientID | string)[], data?: object, kind?: ClientMessageKind): Promise<never[]>;
get methods(): string[];
ReconnectClientSession(new_session: SocioSession, old_session: SocioSession, client_notify_msg_id?: id): void;
GetSessionsInfo(): {
[k: string]: {
name: string | undefined;
ip: string;
};
};
get session_ids(): MapIterator<string>;
get server_info(): string | AddressInfo;
get raw_websocket_server(): WebSocketServer;
}
export {};