/** * @category capability * Deferred numbering engine — store-clock-ordered, gap-free serials assigned * at an explicit numbering pass. See the design spec. */ import type { NoydbStore } from '../../kernel/types.js'; import { type EnclaveKey } from '../../kernel/enclave/index.js'; import type { DeferredNumberingConfig } from './descriptor.js'; export declare const NUMBERING_HEAD_COLLECTION = "_numbering_head"; export declare const NUMBERING_PENDING_COLLECTION = "_numbering_pending"; export interface Assignment { recordId: string; serial: number; } export declare class DeferredNumberingStore { private readonly adapter; private readonly vault; private readonly encrypted; private readonly getDEK; private readonly actor; private readonly configs; /** * Stamp a serial onto a USER record THROUGH the Collection layer (so the * cache, indexes, and MVs stay coherent — the engine must NOT write user * collections at the raw adapter level). Returns false if the record is * gone (the engine then skips it without burning a serial). Provided by the * vault; unit tests pass a Map-backed double. */ private readonly stamp; /** In-process registry: `${series}::${recordId}` → resolver for the live next() Promise. */ private readonly waiters; private readonly dekCache; constructor(opts: { adapter: NoydbStore; vault: string; encrypted: boolean; getDEK: (collectionName: string) => Promise; actor: string; configs: Map; stamp: (collection: string, recordId: string, field: string, serial: number) => Promise; }); has(series: string): boolean; private dek; private readJson; private writeJson; private pendingId; /** Current last-assigned serial for a series (0 if none). */ peek(series: string): Promise; /** * Enqueue a record for numbering: stamp it with the current store clock and * durably write a pending entry. The returned Promise resolves once the * record is durably enqueued; its `assigned` field resolves with the serial * at the next pass (the record's `field` is the durable source of truth — * `assigned` is an in-process convenience that a crash may drop). */ enqueue(series: string, recordId: string): Promise<{ assigned: Promise; }>; private listPending; /** * Run a numbering pass for `series`: select entries provably settled * (`storeLatest ≤ now.earliest` — commit-wait), order by * `(storeEarliest, recordId)`, assign serials after the head, stamp each * record's field, advance the head with one CAS, and consume the entries. * Idempotent/convergent: a losing concurrent pass returns `[]` and the next * pass reconciles. Resolves any in-process enqueue() `assigned` Promises. */ runPass(series: string): Promise; }