/** * WASM FeltDB Binding * * This is the FFI interface to the Rust WASM implementation. */ import type { FreshnessCapability, Revision } from './freshness.js'; /** * WASM database instance */ export interface JsDb { /** * Execute an operation */ execute_op(operation: any): any; /** * Get sync info */ sync_info(): any; /** * Add a peer */ add_peer(peer_id: string): any; /** * Add sync peer */ add_sync_peer(peer_id: string): any; /** * Remove sync peer */ remove_sync_peer(peer_id: string): any; /** * Get pending operations for peer */ get_pending_for_peer(peer_id: string, since_sequence: number): any; /** * Acknowledge peer operations */ acknowledge_peer_operations(peer_id: string, sequence: number): any; /** * Query data */ query(query: string): any | Promise; /** Execute a bounded query at the runtime's storage boundary. */ authority_query?(query: unknown): Promise; /** * Plain `Collection.find(query)` should delegate to `authority_query`. * * Embedded runtimes may expose `authority_query` for bounded execution while * still keeping the unbounded Collection API on the local cache/index path. */ collection_queries_via_authority?: boolean; /** Explain a bounded query without executing it. */ explain_query?(query: unknown): unknown | Promise; /** Rebuild derived embedded indexes from authoritative records. */ rebuild_indexes?(): void | Promise; /** * Get a record */ get(key: string): any | Promise; /** * Insert a record */ insert(key: string, value: string): any | Promise; /** Update a record without changing collection semantics. */ update?(key: string, value: string): any | Promise; /** Delete a record when supported by the runtime. */ delete?(key: string): any | Promise; /** Subscribe to runtime-originated changes, including remote mutations. */ subscribe_changes?(callback: (collection: string) => void, collection?: string): () => void; close?(): void | Promise; /** * Get capability records */ get_capability_records(capability: string): any; /** * Get instance ID */ instance_id(): string; /** * Get sequence number. * * **Not a freshness token.** This means something different in every runtime: * a hardcoded `0` over HTTP, the number of mutations this handle performed in * the memory and browser runtimes, and the loaded snapshot's counter in the * file runtime. None of those reflect a write made by another process, tab, * or node. Use `freshness()` and `revision()` to decide whether a cached copy * is current. */ get_sequence(): number; /** * Declare what freshness validation this runtime can honestly support. * * A runtime implements this only if it has something true to say. Omitting it * is read as "explicit refresh only", which is the safe answer. * * See packages/core/src/freshness.ts for the rule this answer is held to. */ freshness?(): FreshnessCapability | Promise; /** * The current committed-state revision. * * Defined **only** by runtimes whose `freshness()` advertises * `validation: 'revision'`. A runtime that exposes this without advertising * it is a contract violation, because an exposed revision will eventually be * trusted. */ revision?(): Promise; /** Read durable mutation events when the runtime exposes an audit log. */ audit_events?(): any | Promise; /** Export and merge portable embedded-runtime operations. */ export_operations?(since_sequence: number): any | Promise; apply_remote_operations?(operations: any[]): any | Promise; /** * Atomic conditional create: insert only if key does not exist. * * Optional because a runtime may express the same condition through * `commit_transaction` instead. A caller should not branch on which one a * runtime provides -- `Collection.putIfAbsent` already routes between them. */ putIfAbsent?(key: string, value: string): Promise<{ inserted: boolean; value: string; }>; /** * Compare-and-set: atomically update only if version and epoch match. * * Optional for the same reason as `putIfAbsent`: a runtime may carry the * fence through `commit_transaction` instead, and * `Collection.updateIfVersion` routes between them. */ cas?(params: { key: string; expectedVersion: number; expectedEpoch?: number; expectedLeaseId?: string; rejectIfDiverged?: boolean; value: string; }): Promise<{ updated: boolean; currentVersion: number; currentEpoch?: number; conflictCode?: string; item?: any; }>; /** Atomic idempotent operation admission: durably admit unique operations. */ admitOperation?(input: any): Promise; /** Atomic operation lifecycle transition: versioned conditional state changes. */ transitionOperation?(input: any): Promise; /** * Commit several operations as one atomic, durable transaction. * * A runtime implements this only when it is backed by an authority that can * provide the guarantee. Runtimes that cannot leave it undefined, so callers * get an explicit refusal instead of a silent sequence of separate writes. */ commit_transaction?(request: { transactionId: string; operations: Array<{ collection: string; id: string; value?: Record; requireAbsent?: boolean; /** * Fence this write on the record's `__version`. Enforced by the * authority inside the transaction, not by the client. */ expectedVersion?: number; expectedEpoch?: number; expectedLeaseId?: string; }>; /** Conditions on records the transaction need not write. */ preconditions?: Array<{ collection: string; id: string; requireAbsent?: boolean; expectedVersion?: number; expectedEpoch?: number; expectedLeaseId?: string; }>; }): Promise<{ transactionId: string; duplicate: boolean; operations: number; stateBefore: number; stateAfter: number; baseRevision: number; commitRevision: number; revisionId: string; operationIds: string[]; }>; } /** * A row stored in the database */ export interface StoredRow { id: string | number; [key: string]: any; } //# sourceMappingURL=feltdb.d.ts.map