/** * Public API for embedding RESPLite in your own Node.js application. * * High-level (recommended): * import { createRESPlite } from 'resplite/embed'; * const srv = await createRESPlite({ db: './my-app.db' }); * * Low-level (manual wiring): * import { handleConnection, createEngine, createPubSubBroker, openDb } from 'resplite/embed'; * const pubSub = createPubSubBroker(); // share across every connection of this server * const stats = createServerStats(); // share across every connection of this server (INFO counters) * handleConnection(socket, engine, hooks, commandPolicy, { pubSub, stats }); */ import { handleConnection } from './server/connection.ts'; import { createEngine } from './engine/engine.ts'; import { openDb } from './storage/sqlite/db.ts'; import { createPubSubBroker } from './pubsub/broker.ts'; import { createServerStats } from './server/stats.ts'; import type { CacheOptions } from './cache/cache.ts'; import type { SearchOptions } from './storage/sqlite/search.ts'; import type { CommandPolicy } from './commands/registry.ts'; import type { ScriptingPlugin } from './scripting/plugin.ts'; import type { CommandEvent, ConnectionHooks } from './types.ts'; import type { ConnectionServices } from './server/connection.ts'; export { handleConnection, createEngine, openDb, createPubSubBroker, createServerStats }; export type { ConnectionServices }; /** * Optional event hooks for observability (e.g. logging unknown commands or errors). * All hooks are optional. Called with plain objects; do not mutate. */ export interface RESPliteHooks extends ConnectionHooks { /** Invoked when the client sends a command not implemented by RESPLite. `argv` is the full command line as strings (e.g. `['CLIENT','LIST']`) for logging. */ onUnknownCommand?: (payload: CommandEvent) => void; /** Invoked when a command handler throws or returns an error (e.g. WRONGTYPE, invalid args). `argv` is the full command line as strings for logging. */ onCommandError?: (payload: CommandEvent) => void; /** Invoked when a connection socket emits an error (e.g. ECONNRESET). */ onSocketError?: (payload: { error: Error; clientAddress: string; connectionId: number; }) => void; } /** Options of {@link createRESPlite}. */ export interface CreateRESPliteOptions { /** SQLite file path, or ':memory:' for in-memory. Default ':memory:'. */ db?: string; /** Host to listen on. Default '127.0.0.1'. */ host?: string; /** Port to listen on (0 = OS-assigned). Default 0. */ port?: number; /** PRAGMA preset (default|performance|safety|minimal|none). Convention: this template is applied by default; no config needed. Default 'default'. */ pragmaTemplate?: string; /** Override specific pragmas only when needed (e.g. { synchronous: 'FULL' }). Applied after the template. */ pragma?: Record; /** Hot data cache configuration, or false to disable it. */ cache?: false | CacheOptions; /** FT.SEARCH guards: minPrefix, maxResults, timeoutMs. */ search?: SearchOptions; /** Optional event hooks for observability (onUnknownCommand, onCommandError, onSocketError). */ hooks?: RESPliteHooks; /** If true, register SIGTERM/SIGINT to call close(). Set false if you handle shutdown yourself to avoid double handlers. Default true. */ gracefulShutdown?: boolean; /** Optional: rename/disable commands for hardening. */ commandPolicy?: CommandPolicy | null; /** Prepared plugin from resplite/scripting; owned and closed by this server. */ scripting?: ScriptingPlugin | null; } /** A running embedded RESPLite server. */ export interface RESPliteServer { port: number; host: string; close: () => Promise; } /** Options of {@link createRESPliteGroup}. */ export interface CreateRESPliteGroupOptions { /** Register one SIGTERM/SIGINT handler for the group. Default true. */ gracefulShutdown?: boolean; } /** A running group of named embedded RESPLite servers. */ export interface RESPliteGroup { servers: Record; close: () => Promise; } /** * Start an embedded RESPLite server. */ export declare function createRESPlite({ db: dbPath, host, port, pragmaTemplate, pragma, cache: cacheOptions, search, hooks, gracefulShutdown, commandPolicy, scripting, }?: CreateRESPliteOptions): Promise; /** * Start and manage a named group of independent embedded RESPLite servers. * The group owns one pair of process signal handlers and rolls back servers * already started when a later instance fails. * * @param instances - Named createRESPlite option objects. */ export declare function createRESPliteGroup(instances: Record, { gracefulShutdown, }?: CreateRESPliteGroupOptions): Promise;