UNPKG

connect-surreal

Version:

SurrealDB session store for Connect

66 lines (65 loc) 2.13 kB
import { Store } from "express-session"; import WebSocketStrategy, { Surreal } from "surrealdb"; export type SurrealDBStoreOptions = { /** * URL used to connect to SurrealDB * e.g. http://127.0.0.1:8000/rpc */ url: string; /** * Table to use for storing the sessions * @default `user_sessions` */ tableName: string; /** * Options for the initial SurrealDB connection */ connectionOpts: Parameters<Surreal['connect']>[1]; /** * Sign-in options */ signinOpts: Parameters<WebSocketStrategy['signin']>[0]; /** * Use options (Select namespace, database) * @optional */ useOpts?: Parameters<WebSocketStrategy['use']>[0]; /** * Optional surreal db instance override. */ surreal?: Surreal; }; export declare class SurrealDBStore extends Store { private readonly options; private db; private tableName; private lastConnectionAttempt; private hasConnected; private isConnected; constructor(options: SurrealDBStoreOptions); /** * Perform the initial connection to the database. This also sets the scope of our connection. */ private _connect; /** * Reconnect to the database if our connection drops. This uses a connection * throttling technique to prevent connection storming. */ private _reconnect; /** * Check the connection state and attempt to reconnect before continuing * This ensures that sessions shouldn't observe disruptions in edge cases * where the connection gets lost and we can't connect immediately. * * If there's 50 minutes between the drop and a new connection, the user won't * get an error screen and need to refresh their page. */ private _checkConnectionAndReconnect; get(sessionId: string, cb: Function): void; set(sessionId: string, session: any, cb: Function): void; touch(sid: string, session: any, cb: Function): void; destroy(sessionId: string, cb: Function): void; length(cb: Function): void; all(cb: Function): void; clear(cb: Function): void; }