import type { Adapter } from '@livestore/common'; import * as WorkerSchema from '../common/worker-schema.ts'; /** * Checks if SharedWorker API is available in the current browser context. * * Returns false on Android Chrome and other browsers without SharedWorker support. * * @see https://github.com/livestorejs/livestore/issues/321 * @see https://issues.chromium.org/issues/40290702 */ export declare const canUseSharedWorker: () => boolean; export type WebAdapterOptions = { worker: ((options: { name: string; }) => globalThis.Worker) | (new (options: { name: string; }) => globalThis.Worker); /** * This is mostly an implementation detail and needed to be exposed into app code * due to a current Vite limitation (https://github.com/vitejs/vite/issues/8427). * * In most cases this should look like: * ```ts * import LiveStoreSharedWorker from '@livestore/adapter-web/shared-worker?sharedworker' * * const adapter = makePersistedAdapter({ * sharedWorker: LiveStoreSharedWorker, * // ... * }) * ``` */ sharedWorker: ((options: { name: string; }) => globalThis.SharedWorker) | (new (options: { name: string; }) => globalThis.SharedWorker); /** * Specifies where to persist data for this adapter */ storage: WorkerSchema.StorageTypeEncoded; /** * Warning: This will reset both the app and eventlog database. * This should only be used during development. * * @default false */ resetPersistence?: boolean; /** * By default the adapter will initially generate a random clientId (via `nanoid(5)`), * store it in `localStorage` and restore it for subsequent client sessions. It's the same across all tabs/windows. */ clientId?: string; /** * By default the adapter will initially generate a random sessionId (via `nanoid(5)`), * store it in `sessionStorage` and restore it for subsequent client sessions in the same tab/window. */ sessionId?: string; experimental?: { /** * When set to `true`, the adapter will always start with a snapshot from the leader * instead of trying to load a snapshot from storage. * * @default false */ disableFastPath?: boolean; /** * Controls whether to wait for the shared worker to be terminated when LiveStore gets shut down. * This prevents a race condition where a new LiveStore instance connects to a shutting-down shared * worker from a previous instance. * * @default false * * @remarks * * In multi-tab scenarios, we don't want to await shared worker termination because the shared worker * won't actually shut down when one tab closes - it stays alive to serve other tabs. Awaiting * termination would cause unnecessary blocking since the termination will never happen until all * tabs are closed. */ awaitSharedWorkerTermination?: boolean; }; }; /** * Creates a web adapter with persistent storage (currently only supports OPFS). * Requires both a web worker and a shared worker. * * On browsers without SharedWorker support (e.g. Android Chrome), this adapter * automatically falls back to single-tab mode. In single-tab mode: * - Each tab runs independently with its own leader worker * - Multi-tab synchronization is not available * - Devtools are not supported * * @see https://github.com/livestorejs/livestore/issues/321 - SharedWorker tracking issue * @see https://issues.chromium.org/issues/40290702 - Chromium SharedWorker bug * * @example * ```ts * import { makePersistedAdapter } from '@livestore/adapter-web' * import LiveStoreWorker from './livestore.worker.ts?worker' * import LiveStoreSharedWorker from '@livestore/adapter-web/shared-worker?sharedworker' * * const adapter = makePersistedAdapter({ * worker: LiveStoreWorker, * sharedWorker: LiveStoreSharedWorker, * storage: { type: 'opfs' }, * }) * ``` */ export declare const makePersistedAdapter: (options: WebAdapterOptions) => Adapter; //# sourceMappingURL=persisted-adapter.d.ts.map