import type { LixEngine } from "../boot.js"; import type { Lix } from "../../lix/open-lix.js"; /** * Returns the next monotonic sequence number, starting at 0. * * Only available in deterministic mode. Provides a simple counter for cases where * you need sequential integers rather than timestamps or random values. * * - Requires `lix_deterministic_mode = true` * - Increments by exactly 1 per call (no gaps or duplicates) * - State persisted via `lix_deterministic_sequence_number` key value * - Clones continue from where the sequence left off * - Consider using {@link getTimestampSync}, {@link uuidV7}, or {@link nanoId} for most ID generation needs * * @example Basic usage (deterministic mode required) * ```ts * const lix = await openLix({ * keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true } }] * }); * const n1 = nextDeterministicSequenceNumber({ lix }); // 0 * const n2 = nextDeterministicSequenceNumber({ lix }); // 1 * const n3 = nextDeterministicSequenceNumber({ lix }); // 2 * ``` * * @example Collision-free IDs * ```ts * const n = nextDeterministicSequenceNumber({ lix }); // e.g. 7 * const id = `ENTITY_${n}`; // "ENTITY_7" * ``` * * @example Pagination cursors * ```ts * const cursor = nextDeterministicSequenceNumber({ lix }); * await lix.db.insertInto("page_view") * .values({ cursor, page_id: "home" }) * .execute(); * ``` * * @param args.lix - The Lix instance with sqlite and db connections * @returns The next number in the sequence (starting from 0) * @throws {Error} If `lix_deterministic_mode` is not enabled */ export declare function nextSequenceNumberSync(args: { engine: Pick; }): number; /** * Returns the next monotonic sequence number, starting at 0. * * Async wrapper around {@link nextSequenceNumberSync} that runs the computation * next to the database engine via the engine router. * * - Available only when `lix_deterministic_mode.enabled = true`. * - Persists state across `toBlob()`/`openLix({ blob })`. * - Consider {@link getTimestampSync}, {@link uuidV7}, or {@link nanoId} for typical IDs. * * @example * const lix = await openLix({ * keyValues: [{ key: "lix_deterministic_mode", value: { enabled: true } }] * }) * const n1 = await nextSequenceNumber({ lix }) // 0 * const n2 = await nextSequenceNumber({ lix }) // 1 */ export declare function nextSequenceNumber(args: { lix: Lix; }): Promise; /** * @internal * Flush the in-memory deterministic counter to persistent storage. * * Called automatically by Lix after each committing write and during * `lix.toBlob()` / `lix.close()`. **Not part of the public API.** */ export declare function commitSequenceNumberSync(args: { engine: Pick; timestamp?: string; }): void; //# sourceMappingURL=sequence.d.ts.map