//#region src/index.d.ts type MaybePromise = T | Promise; type ExportOptions = { from?: VersionVector; hooks?: ExportHooks; pruneTombstonesBefore?: number; peerId?: string; }; type ImportOptions = { bundle: ExportBundle; hooks?: ImportHooks; }; type VersionVectorEntry = { physicalTime: number; logicalCounter: number; }; interface VersionVector { [peer: string]: VersionVectorEntry | undefined; } declare function encodeVersionVector(vector: VersionVector): Uint8Array; declare function decodeVersionVector(bytes: Uint8Array): VersionVector; type Value = string | number | boolean | null | Array | { [key: string]: Value; }; type KeyPart = Value; type MetadataMap = Record; type ExportRecord = { c: string; d?: Value; m?: MetadataMap; }; type ExportBundle = { version: number; entries: Record; }; type EntryClock = { physicalTime: number; logicalCounter: number; peerId: string; }; type EntryInfo = { data?: Value; metadata: MetadataMap; clock: EntryClock; }; type ExportPayload = { data?: Value; metadata?: MetadataMap; }; type ExportHookContext = { key: KeyPart[]; clock: EntryClock; raw: ExportRecord; }; type ExportHooks = { transform?: (context: ExportHookContext, payload: ExportPayload) => MaybePromise; }; type ImportPayload = ExportPayload; type ImportHookContext = ExportHookContext; type ImportAccept = { accept: true; }; type ImportSkip = { accept: false; reason: string; }; type ImportDecision = ImportAccept | ImportSkip | ImportPayload | void; type ImportHooks = { preprocess?: (context: ImportHookContext, payload: ImportPayload) => MaybePromise; }; type ImportReport = { accepted: number; skipped: Array<{ key: KeyPart[]; reason: string; }>; }; type PutPayload = ExportPayload; type PutHookContext = { key: KeyPart[]; now?: number; }; type PutHooks = { transform?: (context: PutHookContext, payload: PutPayload) => MaybePromise; }; type PutWithMetaOptions = { metadata?: MetadataMap; now?: number; hooks?: PutHooks; }; type ScanBound = { kind: "inclusive"; key: KeyPart[]; } | { kind: "exclusive"; key: KeyPart[]; } | { kind: "unbounded"; }; type ScanOptions = { start?: ScanBound; end?: ScanBound; prefix?: KeyPart[]; }; type ScanRow = { key: KeyPart[]; raw: ExportRecord; value?: Value; }; type EventPayload = ExportPayload; type Event = { key: KeyPart[]; value?: Value; metadata?: MetadataMap; payload: EventPayload; }; type EventBatch = { source: string; events: Event[]; }; declare class Flock { private inner; private listeners; private nativeUnsubscribe; private readonly eventBatcher; constructor(peerId?: string); private static fromInner; static fromJson(bundle: ExportBundle, peerId: string): Flock; static checkConsistency(a: Flock, b: Flock): boolean; checkInvariants(): void; setPeerId(peerId: string): void; private putWithMetaInternal; private putWithMetaPrepared; private putWithMetaWithHooks; /** * Put a value into the flock. If the given entry already exists, this insert will be skipped. * @param key * @param value * @param now */ put(key: KeyPart[], value: Value | undefined, now?: number): void; putWithMeta(key: KeyPart[], value: Value | undefined, options?: PutWithMetaOptions): void | Promise; set(key: KeyPart[], value: Value | undefined, now?: number): void; /** * Delete a value from the flock. If the given entry does not exist, this delete will be skipped. * @param key * @param now */ delete(key: KeyPart[], now?: number): void; get(key: KeyPart[]): Value | undefined; /** * Returns the full entry payload (data, metadata, and clock) for a key. * * Unlike `get`, this distinguishes between a missing key (`undefined`) and a * tombstone (returns the clock and metadata with `data` omitted). Metadata is * cloned and defaults to `{}` when absent. */ getEntry(key: KeyPart[]): EntryInfo | undefined; merge(other: Flock): void; /** * Returns the exclusive/visible version vector. * * Only peers that currently own at least one visible entry are included. * This vector is consistent with current visible state and is the correct * baseline for incremental export/replication. * * Complexity: O(M + V log M + R (log L + log S)). * - M = memtablePeerCount * - V = vvPeerCount * - L = memtableLen * - R = scanned candidate rows in KV_BY_PEER_CLOCK * - S = storage key count in KV_BY_KEY * No full O(memtableSize) pre-scan is performed. * * Use this version when sending to other peers for incremental sync. */ version(): VersionVector; /** * Returns the inclusive/max-seen version vector. * * Tracks max seen clocks per peer for this process lifetime * (open/import/local writes), including peers that may no longer own visible * entries. * * Use this version for completeness checks, not incremental export baselines. */ inclusiveVersion(): VersionVector; private exportJsonInternal; private exportJsonWithHooks; exportJson(): ExportBundle; exportJson(from: VersionVector): ExportBundle; exportJson(from: VersionVector, pruneTombstonesBefore: number): ExportBundle; exportJson(options: ExportOptions): Promise; private importJsonInternal; private importJsonWithHooks; importJson(bundle: ExportBundle): ImportReport; importJson(options: ImportOptions): Promise; importJsonStr(bundle: string): ImportReport; getMaxPhysicalTime(): number; peerId(): string; digest(): string; kvToJson(): ExportBundle; putMvr(key: KeyPart[], value: Value, now?: number): void; getMvr(key: KeyPart[]): Value[]; scan(options?: ScanOptions): ScanRow[]; private ensureNativeSubscription; private handleBatch; private deliverBatch; subscribe(listener: (batch: EventBatch) => void): () => void; /** * Enable auto-debounce mode. Events will be accumulated and emitted after * the specified timeout of inactivity. Each new operation resets the timer. * * Use `commit()` to force immediate emission of pending events. * Use `disableAutoDebounceCommit()` to disable and emit pending events. * * @param timeout - Debounce timeout in milliseconds * @param options - Optional configuration object with maxDebounceTime (default: 10000ms) * @throws Error if called while a transaction is active * @throws Error if autoDebounceCommit is already active * * @example * ```ts * flock.autoDebounceCommit(100); * flock.put(["a"], 1); * flock.put(["b"], 2); * // No events emitted yet... * // After 100ms of inactivity, subscribers receive single EventBatch * // If operations keep coming, commit happens after maxDebounceTime (10s default) * ``` */ autoDebounceCommit(timeout: number, options?: { maxDebounceTime?: number; }): void; /** * Disable auto-debounce mode and emit any pending events immediately. * No-op if autoDebounceCommit is not active. */ disableAutoDebounceCommit(): void; /** * Force immediate emission of any pending debounced events. * Does not disable auto-debounce mode - new operations will continue to be debounced. * No-op if autoDebounceCommit is not active or no events are pending. */ commit(): void; /** * Check if auto-debounce mode is currently active. */ isAutoDebounceActive(): boolean; /** * Execute operations within a transaction. All put/delete operations inside * the callback will be batched and emitted as a single EventBatch when the * transaction commits successfully. * * If the callback throws an error, the transaction is rolled back and no * events are emitted. Note: Data changes are NOT rolled back - only event * emission is affected. * * The callback must be synchronous. For async operations, use FlockSQLite. * * @param callback - Synchronous function containing put/delete operations * @returns The return value of the callback * @throws Error if nested transaction attempted * @throws Error if import is called during the transaction (auto-commits first) * @throws Error if called while autoDebounceCommit is active * * @example * ```ts * flock.txn(() => { * flock.put(["a"], 1); * flock.put(["b"], 2); * flock.put(["c"], 3); * }); * // Subscribers receive a single EventBatch with 3 events * ``` */ txn(callback: () => T): T; /** * Check if a transaction is currently active. */ isInTxn(): boolean; } //#endregion export { EntryClock, EntryInfo, Event, EventBatch, EventPayload, ExportBundle, ExportHookContext, ExportHooks, ExportPayload, ExportRecord, Flock, ImportAccept, ImportDecision, ImportHookContext, ImportHooks, ImportPayload, ImportReport, ImportSkip, KeyPart, MetadataMap, PutHookContext, PutHooks, PutPayload, PutWithMetaOptions, ScanBound, ScanOptions, ScanRow, Value, VersionVector, VersionVectorEntry, decodeVersionVector, encodeVersionVector }; //# sourceMappingURL=index.d.ts.map