import type { URL } from 'node:url'; import { type Adapter, type SyncOptions } from '@livestore/common'; import { Schema } from '@livestore/utils/effect'; import type { TestingOverrides } from '../leader-thread-shared.ts'; import * as WorkerSchema from '../worker-schema.ts'; export interface NodeAdapterOptions { storage: WorkerSchema.StorageType; /** The default is the hostname of the current machine */ clientId?: string; /** * Warning: This adapter doesn't currently support multiple client sessions for the same client (i.e. same storeId + clientId) * @default 'static' */ sessionId?: string; /** * Warning: This will reset both the app and eventlog database. This should only be used during development. * * @default false */ resetPersistence?: boolean; devtools?: { schemaPath: string | URL; /** * Where to run the devtools server (via Vite) * * @default 4242 */ port?: number; /** * @default 'localhost' */ host?: string; /** * Whether to use existing devtools server * * @default false */ useExistingDevtoolsServer?: boolean; }; /** Only used internally for testing */ testing?: { overrides?: TestingOverrides; }; } /** * Creates a single-threaded LiveStore adapter for Node.js applications. * * This adapter runs the leader thread (persistence and sync) in the same thread as * your application. Suitable for CLI tools, scripts, and applications where simplicity * is preferred over maximum performance. * * For production servers or performance-critical applications, consider `makeWorkerAdapter` * which runs persistence/sync in a separate worker thread. * * @example * ```ts * import { makeAdapter } from '@livestore/adapter-node' * import { makeWsSync } from '@livestore/sync-cf/client' * * const adapter = makeAdapter({ * storage: { type: 'fs', baseDirectory: './data' }, * sync: { * backend: makeWsSync({ url: 'wss://api.example.com/sync' }), * }, * }) * ``` * * @example * ```ts * // With DevTools support * const adapter = makeAdapter({ * storage: { type: 'fs', baseDirectory: './data' }, * devtools: { * schemaPath: new URL('./schema.ts', import.meta.url), * port: 4242, * }, * }) * ``` * * @see https://livestore.dev/docs/reference/adapters/node for setup guide */ export declare const makeAdapter: ({ sync, ...options }: NodeAdapterOptions & { sync?: SyncOptions; }) => Adapter; /** * Creates a multi-threaded LiveStore adapter for Node.js applications. * * This adapter runs the leader thread (persistence, sync, and heavy SQLite operations) * in a separate worker thread, keeping your main thread responsive. Recommended for * production servers and performance-critical applications. * * You must create a worker file that calls `makeLeaderWorker()` and pass its URL * to this function. * * @example * ```ts * // In your main file: * import { makeWorkerAdapter } from '@livestore/adapter-node' * * const adapter = makeWorkerAdapter({ * storage: { type: 'fs', baseDirectory: './data' }, * workerUrl: new URL('./livestore.worker.ts', import.meta.url), * }) * ``` * * @example * ```ts * // In livestore.worker.ts: * import { makeLeaderWorker } from '@livestore/adapter-node/worker' * import { schema } from './schema' * * makeLeaderWorker({ schema }) * ``` * * @see https://livestore.dev/docs/reference/adapters/node for setup guide */ export declare const makeWorkerAdapter: ({ workerUrl, workerExtraArgs, ...options }: NodeAdapterOptions & { /** * Example: `new URL('./livestore.worker.ts', import.meta.url)` */ workerUrl: URL; /** * Extra arguments to pass to the worker which can be accessed in the worker * via `getWorkerArgs()` */ workerExtraArgs?: Schema.JsonValue; }) => Adapter; //# sourceMappingURL=adapter.d.ts.map