@absolutejs/sync 1.24.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,10 +10,10 @@
10
10
  "/**\n * Sync packs — Convex Components without the lock-in. A pack bundles\n * schemas + collections + mutations + scheduled + permissions + readers/\n * writers + CRDT field declarations into one npm-distributable module\n * registered with a single {@link SyncEngine.registerPack} call.\n *\n * See `syncPacks.design.md` for the rationale and the worked examples.\n *\n * Pack design rules (enforced at register time):\n *\n * - A pack declares which tables it `ownsTables`. Two registered packs\n * cannot claim the same table; the host app's directly-registered\n * tables are NOT counted (host registrations always win).\n * - Name construction (namespacing) is the pack's job — each published\n * pack ships as a factory `create<Name>Pack(config)` that builds names\n * from a `tablePrefix` and the host's user/auth context.\n * - Packs compose via the subscription layer (read each other's\n * collections), never via cross-pack `runMutation` calls.\n */\n\nimport type {\n\tCollectionContext,\n\tCollectionDefinition,\n\tJoinCollectionDefinition\n} from './collection';\nimport type { GraphCollectionDefinition } from './graph';\nimport type { MutationDefinition, TableWriter } from './mutation';\nimport type { PermissionsDefinition, TablePermissions } from './permissions';\nimport type { ReactiveQueryDefinition, TableReader } from './reactive';\nimport type { ScheduleDefinition } from './schedule';\nimport type { SchemaDefinition, TableSchema } from './schema';\nimport type { SearchCollectionDefinition } from './search';\nimport type { CrdtMergeable } from '../crdt';\n\n/**\n * Same shape as the engine's per-table CRDT field map (see\n * {@link SyncEngine.registerCrdt}). A pack declares CRDT field types\n * here; the engine wires them on registration.\n */\nexport type CrdtFieldsMap = Record<\n\tstring,\n\tRecord<string, CrdtMergeable<unknown>>\n>;\n\n/**\n * A pack — a self-contained bundle of every registration the engine\n * already accepts. The engine's `registerPack(pack)` dispatches each\n * field to the matching `engine.register*` method. There is no new\n * persistence path; packs are pure composition.\n */\nexport type SyncPack = {\n\t/**\n\t * Pack identifier. Used for devtools labelling and conflict\n\t * diagnostics. Should match the npm package name (e.g.\n\t * \"@absolutejs/sync-pack-presence\").\n\t */\n\tname: string;\n\t/**\n\t * Pack semver. Surfaced in {@link EngineInspection.packs} and in\n\t * conflict diagnostics (e.g. \"table 'comments' is owned by\n\t * sync-pack-comments@2.1.0\").\n\t */\n\tversion: string;\n\t/**\n\t * Tables this pack OWNS. The engine rejects another pack that also\n\t * claims one of these. Direct host registrations (e.g.\n\t * `engine.registerSchema(\"foo\", ...)`) are NOT tracked as ownership,\n\t * so the host can still extend a pack's table or override its\n\t * schema/permissions.\n\t */\n\townsTables: string[];\n\t/**\n\t * Tables this pack reads but does NOT own (e.g. a comments pack\n\t * reads the host's `users` table for author info). Reported in\n\t * {@link EngineInspection.packs}; not enforced unless\n\t * {@link requireDependencies} is `true`.\n\t */\n\treadsTables?: string[];\n\t/**\n\t * When `true`, the engine throws {@link PackMissingDependencyError}\n\t * at register time if any table in `readsTables` has no registered\n\t * reader. Default `false` — host-app reads can be wired lazily.\n\t */\n\trequireDependencies?: boolean;\n\n\tschemas?: SchemaDefinition;\n\tpermissions?: PermissionsDefinition<any>;\n\treaders?: Record<string, TableReader<any>>;\n\twriters?: Record<string, TableWriter<any, any, any>>;\n\tcrdt?: CrdtFieldsMap;\n\n\t// Generic params use `any` (not `unknown`) on purpose: TypeScript's\n\t// function-parameter contravariance would reject a\n\t// `MutationDefinition<{id: string}, ...>` if the slot were\n\t// `MutationDefinition<unknown, ...>`. `any` keeps the slot permissive\n\t// while each `defineMutation` call retains its inferred shape. Same\n\t// shape as the engine's internal maps.\n\tcollections?: CollectionDefinition<any, any, any>[];\n\tjoinCollections?: JoinCollectionDefinition<any, any, any, any, any>[];\n\tgraphCollections?: GraphCollectionDefinition<any, any, any>[];\n\tsearchCollections?: SearchCollectionDefinition<any, any, any>[];\n\treactiveQueries?: ReactiveQueryDefinition<any, any, any>[];\n\n\tmutations?: MutationDefinition<any, any, any>[];\n\tschedules?: ScheduleDefinition[];\n};\n\n/**\n * Pack metadata stored on the engine and surfaced via\n * {@link EngineInspection.packs}.\n */\nexport type RegisteredPack = {\n\tname: string;\n\tversion: string;\n\townsTables: string[];\n\treadsTables: string[];\n};\n\n/**\n * Thrown by {@link SyncEngine.registerPack} when a pack claims a table\n * that another registered pack already owns. The message names both\n * packs and the colliding table so the operator can pick a\n * `tablePrefix`.\n */\nexport class PackTableConflictError extends Error {\n\treadonly table: string;\n\treadonly existingPack: string;\n\treadonly newPack: string;\n\tconstructor(table: string, existingPack: string, newPack: string) {\n\t\tsuper(\n\t\t\t`Pack \"${newPack}\" claims table \"${table}\", but \"${existingPack}\" already owns it. Use a tablePrefix on one of them.`\n\t\t);\n\t\tthis.name = 'PackTableConflictError';\n\t\tthis.table = table;\n\t\tthis.existingPack = existingPack;\n\t\tthis.newPack = newPack;\n\t}\n}\n\n/**\n * Thrown by {@link SyncEngine.registerPack} when a pack has\n * `requireDependencies: true` and at least one table in\n * {@link SyncPack.readsTables} has no registered reader at register\n * time. Pack authors opt into this when their pack cannot function\n * without the host having wired the dependency up front.\n */\nexport class PackMissingDependencyError extends Error {\n\treadonly pack: string;\n\treadonly missingTable: string;\n\tconstructor(pack: string, missingTable: string) {\n\t\tsuper(\n\t\t\t`Pack \"${pack}\" requires a reader for table \"${missingTable}\" but none is registered. Call engine.registerReader(\"${missingTable}\", ...) before engine.registerPack.`\n\t\t);\n\t\tthis.name = 'PackMissingDependencyError';\n\t\tthis.pack = pack;\n\t\tthis.missingTable = missingTable;\n\t}\n}\n\n/**\n * Identity helper. A pack is plain data — the helper exists for type\n * inference, not for runtime behavior.\n *\n * @example\n * export const createPresencePack = (config: PresencePackConfig) =>\n * defineSyncPack({\n * name: '@absolutejs/sync-pack-presence',\n * version: '0.1.0',\n * ownsTables: [resolveTableName('presence', config.tablePrefix)],\n * schemas: { ... },\n * collections: [ ... ],\n * mutations: [ ... ],\n * schedules: [ ... ],\n * });\n */\nexport const defineSyncPack = (pack: SyncPack): SyncPack => pack;\n",
11
11
  "import type { CollectionContext } from './collection';\nimport type { RowKey } from './types';\n\n/**\n * A scored search result: the matched row and its relevance score (higher is\n * more relevant). A search collection sorts hits descending and tags each\n * emitted row with its score (see {@link SEARCH_SCORE_FIELD}).\n */\nexport type SearchHit<T> = { row: T; score: number };\n\n/**\n * An incremental search index over a row set, queried by `Q` (a string for\n * full-text, a vector for similarity). Maintained as rows are added/removed, so\n * the collection that owns it stays live as the corpus changes.\n * {@link createTextIndex} and {@link createVectorIndex} implement it.\n */\nexport type SearchIndex<T, Q> = {\n\t/** Add or replace a row (upsert by key). */\n\tadd: (row: T) => void;\n\t/** Remove a row by key. */\n\tremove: (key: RowKey) => void;\n\t/** Top-`limit` hits for `query`, sorted by descending score. */\n\tsearch: (query: Q, limit: number) => SearchHit<T>[];\n\t/** Number of indexed rows. */\n\tsize: () => number;\n\t/** Drop every indexed row. */\n\tclear: () => void;\n};\n\n/** The field a search collection adds to each emitted row carrying its score. */\nexport const SEARCH_SCORE_FIELD = '_score';\n\nexport type SearchCollectionDefinition<\n\tT,\n\tQuery = string,\n\tCtx = CollectionContext\n> = {\n\t/** Collection name — its identity for subscribe. */\n\tname: string;\n\tkind: 'search';\n\t/** Source table whose committed changes keep the index live. */\n\ttable: string;\n\t/** Build the (empty) index — e.g. `() => createTextIndex({ ... })`. */\n\tindex: () => SearchIndex<T, Query>;\n\t/** The full corpus to index on first subscribe (e.g. a DB read). */\n\tsource: () => Promise<Iterable<T>> | Iterable<T>;\n\t/** Row identity. */\n\tkey: (row: T) => RowKey;\n\t/** Max results returned. Defaults to 20. */\n\tlimit?: number;\n\t/** Access control: return `false` (or throw) to deny the subscription. */\n\tauthorize?: (query: Query, ctx: Ctx) => boolean | Promise<boolean>;\n};\n\n/**\n * Define a live search collection: an index (full-text via {@link createTextIndex}\n * or vector via {@link createVectorIndex}) maintained from a source table's\n * change feed. The subscription's `params` *are* the query — a string for\n * full-text, a vector for similarity. Register it with\n * {@link SyncEngine.registerSearch}; the client receives the ranked top-K as a\n * normal collection, re-ranked live as rows change. Each emitted row carries its\n * relevance under {@link SEARCH_SCORE_FIELD}, so the client can sort by it.\n *\n * The corpus is the whole table; a row-level read permission on the table (see\n * {@link definePermissions}) still filters a caller's hits.\n */\nexport const defineSearchCollection = <\n\tT,\n\tQuery = string,\n\tCtx = CollectionContext\n>(\n\tdefinition: Omit<SearchCollectionDefinition<T, Query, Ctx>, 'kind'>\n): SearchCollectionDefinition<T, Query, Ctx> => ({\n\t...definition,\n\tkind: 'search'\n});\n",
12
12
  "/**\n * Tenant migration primitives. Closes G7 from the deep-research\n * audit: \"move a tenant from engine A to engine B.\"\n *\n * The substrate offers three composable verbs:\n *\n * - **`engine.fence({ reason })`** — pause new mutations on the\n * source so its captured state stops drifting. Subscribers continue\n * to read; only `runMutation` rejects (with\n * {@link EngineFencedError}). Returns a {@link FenceHandle} with\n * `lift()` to undo.\n * - **`engine.exportSnapshot({ tables?, ctx? })`** — walk the\n * registered readers and return a portable\n * {@link EngineSnapshot} carrying the source `instanceId`,\n * `version`, and current rows per table. Cheap and synchronous from\n * the operator's POV.\n * - **`engine.importSnapshot(snapshot, options?)`** — on the target,\n * bulk-load the rows via each table's registered writer. Tracks\n * per-table progress. Returns a {@link MigrationImportResult} with\n * row counts.\n *\n * The intended choreography for a cross-region tenant move:\n *\n * ```ts\n * // ── on the source ──\n * const fence = source.fence({ reason: 'tenant-7 → us-east-2' });\n * try {\n * const snapshot = await source.exportSnapshot();\n * await transport(snapshot); // S3, message bus, etc.\n * // ── on the target ──\n * await target.importSnapshot(snapshot, {\n * onProgress: (table, done, total) =>\n * console.log(`${table}: ${done}/${total}`)\n * });\n * await cutoverDns(); // direct clients at target\n * } finally {\n * fence.lift();\n * }\n * ```\n *\n * Out of scope: out-of-band writes (CDC drivers, raw SQL) — the\n * caller is responsible for pausing those before fencing, otherwise\n * the captured snapshot drifts.\n *\n * Added in 1.24.0.\n */\n\n/**\n * Portable per-tenant state captured by\n * {@link SyncEngine.exportSnapshot}. Consumed by\n * {@link SyncEngine.importSnapshot} on the target engine.\n */\nexport type EngineSnapshot = {\n\t/** The exporting engine's `instanceId` (for audit / forensics). */\n\tsourceInstanceId: string;\n\t/** Source engine's monotonic version at snapshot time. */\n\tversion: number;\n\t/** `Date.now()` at export — used by hosts for staleness checks. */\n\texportedAt: number;\n\t/** Current rows per table, read from each table's registered reader. */\n\ttables: Record<string, ReadonlyArray<unknown>>;\n};\n\n/**\n * Returned by {@link SyncEngine.importSnapshot}.\n */\nexport type MigrationImportResult = {\n\t/** Number of tables that had at least one row imported. */\n\ttablesImported: number;\n\t/** Total rows inserted across all tables. */\n\trowsImported: number;\n\t/** Rows inserted per table. Tables with zero rows are still listed. */\n\tperTable: Record<string, number>;\n\t/**\n\t * Tables present in the snapshot that the target engine has no\n\t * registered writer for — skipped silently. Surface this to\n\t * operators so they can catch \"I forgot to register `tasks` on\n\t * the new shard\" cleanly.\n\t */\n\tskipped: ReadonlyArray<string>;\n};\n\n/**\n * Returned by {@link SyncEngine.fence}. Hold this and call `lift()`\n * to re-enable mutations. Holding multiple fences is supported — the\n * engine stays fenced until every handle has been lifted.\n */\nexport type FenceHandle = {\n\t/** `Date.now()` at fence time. */\n\tfencedAt: number;\n\t/** Human-readable reason — surfaced on {@link EngineFencedError}. */\n\treason: string;\n\t/** Re-enable mutations. Idempotent (later calls are no-ops). */\n\tlift: () => void;\n};\n\nexport type ExportSnapshotOptions = {\n\t/**\n\t * Narrow the export to a subset of registered tables. Useful for\n\t * per-tenant cuts when readers expose `ctx`-scoped data.\n\t */\n\ttables?: ReadonlyArray<string>;\n\t/**\n\t * Context passed to each reader's `all(ctx)`. The default `{}`\n\t * works for engines whose readers ignore context.\n\t */\n\tctx?: unknown;\n};\n\nexport type ImportSnapshotOptions = {\n\t/**\n\t * Narrow the import to a subset of tables in the snapshot.\n\t * Tables outside the filter are skipped (NOT recorded in\n\t * `skipped`; that field is for tables with no writer).\n\t */\n\ttables?: ReadonlyArray<string>;\n\t/**\n\t * Called for each row insertion. Fires synchronously inside the\n\t * import loop; keep it cheap or schedule heavy work elsewhere.\n\t */\n\tonProgress?: (table: string, done: number, total: number) => void;\n\t/**\n\t * Context passed to each writer's `insert(data, ctx, tx)`. The\n\t * default `{}` works for writers that ignore context.\n\t */\n\tctx?: unknown;\n};\n\n/**\n * Thrown by `runMutation` when the engine is fenced. The reason\n * carries through so operators can correlate denied calls to the\n * fence that caused them.\n */\nexport class EngineFencedError extends Error {\n\treadonly reason: string;\n\tconstructor(reason: string) {\n\t\tsuper(`[sync] Engine is fenced for migration: ${reason}`);\n\t\tthis.name = 'EngineFencedError';\n\t\tthis.reason = reason;\n\t}\n}\n",
13
- "import {\n\tABS_ATTRS,\n\ttracerOrNoop,\n\ttype TracerProvider as TelemetryTracerProvider\n} from '@absolutejs/telemetry';\nimport type {\n\tCollectionContext,\n\tCollectionDefinition,\n\tJoinCollectionDefinition\n} from './collection';\nimport { createEquiJoin } from './equiJoin';\nimport type { EquiJoin } from './equiJoin';\nimport type { GraphCollectionDefinition, GraphInstance } from './graph';\nimport { createMaterializedView, isEmptyViewDiff } from './materializedView';\nimport type { MaterializedView } from './materializedView';\nimport type {\n\tMutationActions,\n\tMutationDefinition,\n\tTableWriter,\n\tTransactionRunner\n} from './mutation';\nimport type {\n\tReactiveQueryDefinition,\n\tReadHandle,\n\tTableReader\n} from './reactive';\nimport {\n\texponentialBackoff,\n\tisSerializationFailure,\n\tRetriesExhaustedError\n} from './retry';\nimport {\n\ttype BridgeFetchConfig,\n\ttype HandlerMetricsHook,\n\ttype HandlerMetricsRecord,\n\tmakeSandboxedHandler\n} from './sandbox';\nimport type {\n\tPermissionsDefinition,\n\tReadRule,\n\tTablePermissions,\n\tWriteRule\n} from './permissions';\nimport { PackMissingDependencyError, PackTableConflictError } from './pack';\nimport type { RegisteredPack, SyncPack } from './pack';\nimport type { SearchCollectionDefinition, SearchIndex } from './search';\nimport { SEARCH_SCORE_FIELD } from './search';\nimport type { ScheduleDefinition } from './schedule';\nimport type {\n\tCollectionKind,\n\tEngineActivity,\n\tEngineInspection,\n\tEngineMetrics\n} from './devtools';\nimport type { SchemaDefinition, TableSchema } from './schema';\nimport {\n\tEngineFencedError,\n\ttype EngineSnapshot,\n\ttype ExportSnapshotOptions,\n\ttype FenceHandle,\n\ttype ImportSnapshotOptions,\n\ttype MigrationImportResult\n} from './migrate';\nimport type { CrdtMergeable } from '../crdt';\nimport type { ClusterBus } from './cluster';\nimport type { ChangeSource, RowChange, RowKey, ViewDiff } from './types';\n\n/**\n * Which fields of a `Row` are CRDT values, and the {@link CrdtMergeable} backend\n * (e.g. `rgaText`, or `yjsText` from `@absolutejs/sync-yjs`) used to merge each.\n * Pass to `engine.registerCrdt` so the engine merges those fields on write.\n */\nexport type CrdtFields<Row> = {\n\t[Field in keyof Row]?: CrdtMergeable<Row[Field]>;\n};\n\n/**\n * Thrown when `authorize` denies a subscribe or a mutation. The message names\n * the denied action; the message always starts with \"Not authorized\".\n */\nexport class UnauthorizedError extends Error {\n\tconstructor(subject: string) {\n\t\tsuper(`Not authorized: ${subject}`);\n\t\tthis.name = 'UnauthorizedError';\n\t}\n}\n\n/**\n * Thrown by `engine.subscribe` / `engine.hydrate` (1.15.0+) when the caller's\n * `AbortSignal` fires before the operation reaches a `Subscription` /\n * resolved value. The `name` is `'AbortError'` to match the DOM-standard\n * spelling so existing `catch (error) { if (error.name === 'AbortError') ... }`\n * patterns work unchanged.\n */\nexport class AbortError extends Error {\n\tconstructor(reason?: string) {\n\t\tsuper(reason ?? 'Aborted');\n\t\tthis.name = 'AbortError';\n\t}\n}\n\nconst checkAborted = (signal?: AbortSignal): void => {\n\tif (signal?.aborted) {\n\t\tthrow new AbortError(\n\t\t\tsignal.reason instanceof Error\n\t\t\t\t? signal.reason.message\n\t\t\t\t: typeof signal.reason === 'string'\n\t\t\t\t\t? signal.reason\n\t\t\t\t\t: 'Aborted'\n\t\t);\n\t}\n};\n\nconst linkAbortToUnsubscribe = (\n\tsignal: AbortSignal | undefined,\n\tunsubscribe: () => void\n): void => {\n\tif (signal === undefined) return;\n\tif (signal.aborted) {\n\t\tunsubscribe();\n\t\treturn;\n\t}\n\tconst handler = () => {\n\t\ttry {\n\t\t\tunsubscribe();\n\t\t} catch {\n\t\t\t/* idempotent unsubscribes shouldn't surface here */\n\t\t}\n\t};\n\tsignal.addEventListener('abort', handler, { once: true });\n};\n\n/**\n * Thrown when a mutation's write fails its table's schema (see\n * {@link defineSchema}). The message names the offending field.\n */\nexport class SchemaError extends Error {\n\tconstructor(table: string, fieldName: string) {\n\t\tsuper(`Schema violation on \"${table}\": invalid field \"${fieldName}\"`);\n\t\tthis.name = 'SchemaError';\n\t}\n}\n\nexport type SubscribeArgs<T, P, Ctx> = {\n\t/** Registered collection name. */\n\tcollection: string;\n\t/** Query params (e.g. a filter value); passed to hydrate/match/authorize. */\n\tparams: P;\n\t/** Caller context (e.g. session); passed to hydrate/match/authorize. */\n\tctx: Ctx;\n\t/**\n\t * Receives every non-empty diff (with its version) after the initial\n\t * reply. 1.18.0+: a third optional `cursor` argument carries the\n\t * cross-instance resume cursor as of this diff. Callers that ignore\n\t * the 3rd arg keep working unchanged.\n\t */\n\tonDiff: (diff: ViewDiff<T>, version: number, cursor?: string) => void;\n\t/**\n\t * Resume from a point the client already applied. When the change log still\n\t * covers `(since, now]` for a single-table collection, the engine replies\n\t * with a catch-up diff instead of a full snapshot; otherwise it falls back\n\t * to a snapshot.\n\t *\n\t * Accepts `number` (legacy pre-1.17 — interpreted as the version of THIS\n\t * engine instance) or a `string` cursor (1.17.0+ — opaque vector of\n\t * `(instanceId, version)` per origin, returned by the engine on every\n\t * subscription/diff and round-tripped by the client unmodified). Use the\n\t * cursor form for cross-instance resume.\n\t */\n\tsince?: number | string;\n\t/**\n\t * Cancellation handle (1.15.0). Two effects:\n\t * 1. If the signal is already aborted when `subscribe` is called, the\n\t * engine throws {@link AbortError} immediately — no authorize, no\n\t * hydrate, no subscription.\n\t * 2. If the signal fires AFTER the subscription is live, the engine\n\t * auto-calls `unsubscribe()`. The consumer never has to thread two\n\t * handles for the same lifetime.\n\t *\n\t * Backwards-compatible — omit `signal` and the engine behaves exactly\n\t * as in pre-1.15.0.\n\t */\n\tsignal?: AbortSignal;\n};\n\nexport type Subscription<T> = {\n\t/** The result set at subscribe time — a snapshot (empty when resuming). */\n\tinitial: T[];\n\t/** Catch-up diff when resuming via `since` (instead of `initial`). */\n\tcatchup?: ViewDiff<T>;\n\t/** The engine's local version this reply brings the client up to. */\n\tversion: number;\n\t/**\n\t * Opaque cross-instance resume cursor (1.17.0+). Encodes the per-origin\n\t * vector of `(instanceId, version)` the client is now up-to-date with;\n\t * pass it back as `SubscribeArgs.since` on reconnect. Works for resume\n\t * against ANY instance in a cluster, not just the one that issued it —\n\t * the receiving instance decodes the cursor, walks its log for entries\n\t * the client hasn't seen yet, and either replies with a catch-up diff\n\t * or a fresh snapshot.\n\t */\n\tcursor: string;\n\t/** Stop receiving diffs and release the view. */\n\tunsubscribe: () => void;\n};\n\nexport type SyncEngine = {\n\t/** Register a collection definition (see {@link defineCollection}). */\n\tregister: <T, P = void, Ctx = CollectionContext>(\n\t\tcollection: CollectionDefinition<T, P, Ctx>\n\t) => void;\n\t/** Register an incremental join collection (see {@link defineJoinCollection}). */\n\tregisterJoin: <L, R, Out, P = void, Ctx = CollectionContext>(\n\t\tcollection: JoinCollectionDefinition<L, R, Out, P, Ctx>\n\t) => void;\n\t/** Register an operator-graph collection (see {@link defineGraphCollection}). */\n\tregisterGraph: <Out, P = void, Ctx = CollectionContext>(\n\t\tcollection: GraphCollectionDefinition<Out, P, Ctx>\n\t) => void;\n\t/**\n\t * Register a live search collection (see {@link defineSearchCollection}): a\n\t * full-text or vector index maintained from a source table's change feed and\n\t * queried by the subscription's params, returning the ranked top-K live.\n\t */\n\tregisterSearch: <T, Query = string, Ctx = CollectionContext>(\n\t\tcollection: SearchCollectionDefinition<T, Query, Ctx>\n\t) => void;\n\t/**\n\t * Register a scheduled function (see {@link defineSchedule}): server-triggered\n\t * work whose `actions` writes go live through the change feed. Wire the cron\n\t * triggers with the `scheduled` Elysia plugin.\n\t */\n\tregisterSchedule: (schedule: ScheduleDefinition) => void;\n\t/**\n\t * Run a registered schedule's handler now: its writes commit (in the\n\t * configured transaction) and emit as one live batch. The `scheduled` plugin\n\t * calls this on each cron fire; call it directly to trigger on demand.\n\t */\n\trunSchedule: (name: string) => Promise<void>;\n\t/** Registered schedules (name + cron pattern) — used by the `scheduled` plugin. */\n\tlistSchedules: () => ScheduleDefinition[];\n\t/**\n\t * Open a live subscription: authorize, hydrate the initial set, and stream\n\t * diffs as changes arrive. Rejects with {@link UnauthorizedError} on deny.\n\t */\n\tsubscribe: <T, P = void, Ctx = CollectionContext>(\n\t\targs: SubscribeArgs<T, P, Ctx>\n\t) => Promise<Subscription<T>>;\n\t/**\n\t * One-shot read: authorize and return a collection's current rows without\n\t * subscribing. Powers an Eden-typed HTTP hydrate route (and SSR). Rejects\n\t * with {@link UnauthorizedError} on deny.\n\t *\n\t * Pass `options.signal` (1.15.0+) to cancel the operation mid-flight —\n\t * the engine throws {@link AbortError} after the next await point if\n\t * the signal has fired.\n\t */\n\thydrate: (\n\t\tcollection: string,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\toptions?: { signal?: AbortSignal }\n\t) => Promise<unknown[]>;\n\t/**\n\t * Feed a committed change to `table` into the engine, fanning the resulting\n\t * diff to every live subscription of every collection that reads that table.\n\t * Call after a mutation, or wire a {@link ChangeSource} via `connectSource`.\n\t * Single-table subscriptions diff the row; multi-table / refetch ones\n\t * re-hydrate.\n\t */\n\tapplyChange: <T>(table: string, change: RowChange<T>) => Promise<void>;\n\t/**\n\t * Connect a change source (e.g. a CDC adapter): its emitted changes flow into\n\t * `applyChange`. Resolves to a disconnect function that stops the source.\n\t */\n\tconnectSource: (source: ChangeSource) => Promise<() => Promise<void>>;\n\t/**\n\t * Join a cluster (see {@link ClusterBus}): broadcast this instance's committed\n\t * changes to peers and apply theirs locally, so subscribers on every instance\n\t * stay live. Resolves to a disconnect function. Run once per instance.\n\t */\n\tconnectCluster: (bus: ClusterBus) => Promise<() => Promise<void>>;\n\t/** Active subscription count, optionally for one collection. */\n\tsubscriptionCount: (collection?: string) => number;\n\t/** Register a mutation definition (see {@link defineMutation}). */\n\tregisterMutation: <Args, Ctx = CollectionContext, Result = unknown>(\n\t\tmutation: MutationDefinition<Args, Ctx, Result>\n\t) => void;\n\t/**\n\t * Register how to persist a `table` (any ORM), so a mutation's\n\t * `actions.insert/update/delete` write to your store and emit the live change\n\t * in one step — you can't write without going live. See {@link TableWriter}.\n\t */\n\tregisterWriter: <Row = unknown, Ctx = CollectionContext, Tx = unknown>(\n\t\ttable: string,\n\t\twriter: TableWriter<Row, Ctx, Tx>\n\t) => void;\n\t/**\n\t * Register a read-set-tracked reactive query (see {@link defineReactiveQuery}):\n\t * it re-runs and re-pushes whenever any table it read changes — no `match`, no\n\t * operator graph, no manual change emission.\n\t */\n\tregisterReactive: <T, P = void, Ctx = CollectionContext>(\n\t\tquery: ReactiveQueryDefinition<T, P, Ctx>\n\t) => void;\n\t/**\n\t * Teach the engine how to read a table for reactive queries' `ctx.db` (any\n\t * ORM). Required for every table a reactive query reads.\n\t */\n\tregisterReader: <Ctx = CollectionContext>(\n\t\ttable: string,\n\t\treader: TableReader<Ctx>\n\t) => void;\n\t/**\n\t * Register declarative, row-level permissions for a `table` (see\n\t * {@link definePermissions}). Read rules filter every row the engine emits for\n\t * the table; write rules gate `actions.insert/update/delete`. Equivalent to a\n\t * `permissions` entry on {@link createSyncEngine}.\n\t */\n\tregisterPermissions: <Row = unknown, Ctx = CollectionContext>(\n\t\ttable: string,\n\t\trules: TablePermissions<Row, Ctx>\n\t) => void;\n\t/**\n\t * Register a `table`'s schema (see {@link defineSchema}): writes are validated\n\t * against it (a bad write rejects the mutation with {@link SchemaError}), and\n\t * its `migrate` lazily upcasts rows on read. Equivalent to a `schemas` entry\n\t * on {@link createSyncEngine}.\n\t */\n\tregisterSchema: <Row = unknown>(\n\t\ttable: string,\n\t\tschema: TableSchema<Row>\n\t) => void;\n\t/**\n\t * Declare which fields on a `table` are CRDT values (see {@link CrdtMergeable}\n\t * — e.g. `rgaText` from `@absolutejs/sync/crdt`, or `yjsText` from\n\t * `@absolutejs/sync-yjs`). The engine then MERGES those fields on\n\t * `actions.insert/update` instead of overwriting them, so concurrent writers\n\t * converge with no clobbering — conflict-free collaborative editing with no\n\t * merge code in your mutation. It also registers a ready-made\n\t * `\"<table>:merge\"` mutation that upserts a row patch, so a client (e.g. the\n\t * `useCollaborativeText` framework hooks) needs no custom server mutation.\n\t */\n\tregisterCrdt: <Row = Record<string, unknown>>(\n\t\ttable: string,\n\t\tfields: CrdtFields<Row>\n\t) => void;\n\t/**\n\t * Apply a table's schema `migrate` to a raw/stored row (identity when there's\n\t * no schema or migration). Use it wherever you read raw rows the engine\n\t * doesn't (e.g. a search collection's `source`); the engine already migrates\n\t * reactive `ctx.db` reads, view hydrates, and the one-shot hydrate.\n\t */\n\tmigrate: <Row = unknown>(table: string, row: Row) => Row;\n\t/**\n\t * Run a registered mutation: authorize, invoke its handler (which writes and\n\t * emits changes via `applyChange`), and resolve with the handler's result.\n\t * Rejects with {@link UnauthorizedError} on deny, or an error for an unknown\n\t * mutation / a handler throw. Drive this from the transport's mutate frame.\n\t */\n\trunMutation: (\n\t\tname: string,\n\t\targs: unknown,\n\t\tctx: unknown\n\t) => Promise<unknown>;\n\t/**\n\t * Atomically run N mutations in a single transaction (sync 1.11+).\n\t * Each `{ name, args }` spec is authorized, then handlers fire in\n\t * order against shared buffered changes. If any handler throws, the\n\t * entire transaction rolls back — no partial commits, no fanned-out\n\t * diffs. On success the accumulated changes apply as ONE live batch\n\t * and the per-mutation results return in order.\n\t *\n\t * No retry policy applies to batches in v0.2; configure per-mutation\n\t * retries on individual `runMutation` calls when atomicity isn't\n\t * needed. A failed batch passes the original error through with no\n\t * wrapping.\n\t *\n\t * Requires `transaction` to be set in {@link SyncEngineOptions} for\n\t * actual DB-level atomicity; without it the batch still buffers\n\t * changes into one fan-out but the underlying adapter writes\n\t * piecemeal.\n\t */\n\trunMutations: (\n\t\tspecs: Array<{ name: string; args: unknown }>,\n\t\tctx: unknown\n\t) => Promise<unknown[]>;\n\t/**\n\t * A point-in-time snapshot of the engine for devtools: registered collections\n\t * (+ kind, tables, live subscription counts), mutations, schedules, readers,\n\t * writers, the change-feed version, and recent changes. See `syncDevtools`.\n\t */\n\tinspect: () => EngineInspection;\n\t/**\n\t * Operator-shaped engine metrics — counters + memory estimates + throughput\n\t * totals since engine start. Distinct from {@link SyncEngine.inspect}: this\n\t * is what a PaaS host scrapes on an interval to answer \"is this engine\n\t * healthy\" and \"what's its resource footprint.\" Feed it to\n\t * `@absolutejs/metering` for per-engine cost attribution.\n\t *\n\t * Added in 1.13.0.\n\t */\n\tmetrics: () => EngineMetrics;\n\t/**\n\t * Capture the engine's change log + version as a serializable\n\t * {@link ChangeLogSnapshot} the host can persist (disk, S3, the cluster\n\t * bus) and restore on the next boot via\n\t * {@link SyncEngineOptions.initialChangeLog} or\n\t * {@link SyncEngine.importChangeLog}. The receiving engine MUST share this\n\t * engine's `instanceId` — otherwise the resume contract silently breaks.\n\t *\n\t * Cheap: the snapshot's `entries` is a shallow copy of the bounded log\n\t * (capped by `changeLogSize` / `changeLogRetainMs`). Call on a timer or on\n\t * graceful shutdown — both are fine; the snapshot is monotonic in commit\n\t * order, so a partial roll-forward (apply entries newer than the snapshot\n\t * from another source) is safe.\n\t *\n\t * Added in 1.19.0.\n\t */\n\texportChangeLog: () => ChangeLogSnapshot;\n\t/**\n\t * Adopt a {@link ChangeLogSnapshot} into a running engine that has not yet\n\t * committed any local changes (its `version` is 0). The snapshot's\n\t * `instanceId` MUST match this engine's `instanceId`. Throws otherwise.\n\t *\n\t * Convenience for hosts that want to set up the engine, register surfaces,\n\t * AND THEN restore. Equivalent to passing the snapshot via\n\t * `createSyncEngine({ initialChangeLog })` if you have it at construction\n\t * time. Returns the number of entries imported.\n\t *\n\t * Added in 1.19.0.\n\t */\n\timportChangeLog: (snapshot: ChangeLogSnapshot) => number;\n\t/**\n\t * Reconstruct the state of registered tables as of a target\n\t * timestamp by walking the change log forward and folding each op\n\t * into a per-table view. Useful for forensic incident response\n\t * (\"what did the tenant see at 14:32?\") and the \"I deleted prod\n\t * — restore us to 2h ago\" recovery story.\n\t *\n\t * The reconstruction is exact when the log spans `targetAt` (i.e.\n\t * the log's oldest entry is at version 1). When the log has been\n\t * trimmed (`changeLogSize` / `changeLogRetainMs` evicted older\n\t * entries) AND `targetAt` falls in the gap, the result is\n\t * best-effort: state walked forward from the OLDEST retained\n\t * entry, with `truncated: true` so the caller knows.\n\t *\n\t * Added in 1.22.0.\n\t *\n\t * @example\n\t * ```ts\n\t * const twoHoursAgo = Date.now() - 2 * 60 * 60 * 1000;\n\t * const result = await engine.replayTo({ at: twoHoursAgo, tables: ['orders'] });\n\t * if (result.truncated) {\n\t * console.warn('Replay truncated — log retention window too short.');\n\t * }\n\t * console.log(result.rows.orders); // orders as of two hours ago\n\t * ```\n\t */\n\treplayTo: (options: ReplayOptions) => Promise<ReplayResult>;\n\t/**\n\t * Pause new mutations on the engine — the source half of the G7 tenant\n\t * migration contract. While at least one fence is held, `runMutation`\n\t * rejects with {@link EngineFencedError}; subscribe/hydrate continue to\n\t * work, so live readers stay served while the snapshot is in flight.\n\t *\n\t * Multiple fence handles compose — the engine stays fenced until every\n\t * handle has been `lift()`-ed. Lifting is idempotent.\n\t *\n\t * Out of scope: out-of-band writes (CDC drivers, raw SQL). The caller\n\t * is responsible for halting those before fencing, otherwise the\n\t * snapshot will drift between `exportSnapshot` and import on the target.\n\t *\n\t * Added in 1.24.0.\n\t */\n\tfence: (options: { reason: string }) => FenceHandle;\n\t/**\n\t * Capture the engine's current per-table state into a portable\n\t * {@link EngineSnapshot}. Walks every registered reader's `all(ctx)`\n\t * and collects the rows. Used to ship a tenant between engines (G7).\n\t *\n\t * Pair with `fence()` on the source to stop drift, then\n\t * `importSnapshot()` on the target. The shape is intentionally\n\t * detached from `ChangeLogSnapshot` — snapshots carry live state, not\n\t * history. Use `exportChangeLog()` separately if you need forensic\n\t * continuity at the target instanceId.\n\t *\n\t * Added in 1.24.0.\n\t *\n\t * @example\n\t * const fence = source.fence({ reason: 'tenant move' });\n\t * try {\n\t * const snapshot = await source.exportSnapshot();\n\t * await target.importSnapshot(snapshot);\n\t * } finally { fence.lift(); }\n\t */\n\texportSnapshot: (options?: ExportSnapshotOptions) => Promise<EngineSnapshot>;\n\t/**\n\t * Bulk-load an {@link EngineSnapshot} into this engine via each table's\n\t * registered writer. Tables present in the snapshot but missing a\n\t * writer here are surfaced in `result.skipped` so the operator can\n\t * detect a misconfigured target. The target half of the G7 migration\n\t * contract.\n\t *\n\t * Inserts do NOT emit change events to subscribers — the import is\n\t * meant to land on a fresh target whose clients will re-hydrate after\n\t * the DNS cutover. If you need to fan changes out (e.g. mid-flight\n\t * cutover), drain the change log via `streamChanges()` and\n\t * `applyChange()` separately.\n\t *\n\t * Added in 1.24.0.\n\t */\n\timportSnapshot: (\n\t\tsnapshot: EngineSnapshot,\n\t\toptions?: ImportSnapshotOptions\n\t) => Promise<MigrationImportResult>;\n\t/**\n\t * Subscribe to the live engine activity stream (changes, mutation outcomes,\n\t * subscribe/unsubscribe). Returns an unsubscribe. Powers the devtools feed.\n\t */\n\tonActivity: (listener: (event: EngineActivity) => void) => () => void;\n\t/**\n\t * Outbound CDC stream — yield every committed change as a {@link LoggedChange},\n\t * historical first (entries with `version > since`) then continuously tailing\n\t * live commits. Use it to feed downstream pipelines (Kafka, search indexers,\n\t * audit logs, analytics warehouses).\n\t *\n\t * The iterator is notify-driven (no polling): it parks on a Promise that\n\t * resolves the instant a new commit lands.\n\t *\n\t * If `since` falls before the oldest entry retained in the bounded change\n\t * log, the iterator throws {@link MissedChangesError} so the consumer\n\t * notices the gap instead of silently skipping commits. Resubscribe with\n\t * `since = engine.inspect().recentChanges[0].version` after re-bootstrapping.\n\t *\n\t * If the consumer iterates slower than the engine commits and the in-flight\n\t * buffer overflows (`maxBuffer`, default 10000), the iterator throws\n\t * {@link CdcConsumerSlowError} for the same reason.\n\t *\n\t * @example\n\t * for await (const entry of engine.streamChanges({ since: lastCursor })) {\n\t * await kafka.send('sync.changes', JSON.stringify(entry));\n\t * lastCursor = entry.version;\n\t * }\n\t */\n\tstreamChanges: (\n\t\toptions?: StreamChangesOptions\n\t) => AsyncIterable<LoggedChange>;\n\t/**\n\t * Register a {@link SyncPack} — a self-contained bundle of schemas,\n\t * permissions, readers/writers, collections, mutations, and schedules.\n\t * Dispatches each field to the matching `register*` method. Rejects\n\t * with {@link PackTableConflictError} if the pack claims a table\n\t * another registered pack already owns; with\n\t * {@link PackMissingDependencyError} if `requireDependencies` is set\n\t * and a `readsTables` entry has no registered reader.\n\t *\n\t * See `syncPacks.design.md` for the rationale.\n\t */\n\tregisterPack: (pack: SyncPack) => void;\n};\n\n/**\n * 1.18.0: `OnDiff` receives an opaque `cursor` string alongside the version.\n * The cursor is the engine's cross-instance resume cursor as of this batch\n * — the connection layer forwards it to the client on the wire so a\n * reconnect can resume across shards. Pre-1.18 callers that ignore the 3rd\n * arg keep working unchanged.\n */\ntype OnDiff = (diff: ViewDiff<unknown>, version: number, cursor?: string) => void;\n\ntype JoinState = {\n\top: EquiJoin<unknown, unknown, unknown>;\n\tleftTable: string;\n\trightTable: string;\n\t/** Per-side filters (bound to params/ctx) — a failing change leaves the join. */\n\tleftMatch?: (row: unknown) => boolean;\n\trightMatch?: (row: unknown) => boolean;\n};\n\ntype ActiveSubscription =\n\t| {\n\t\t\tkind: 'view';\n\t\t\tcollection: string;\n\t\t\tview: MaterializedView<unknown>;\n\t\t\t/** Incremental (has a predicate) vs refetch fallback. */\n\t\t\tincremental: boolean;\n\t\t\t/** Re-run the bound hydrate for the refetch fallback. */\n\t\t\trehydrate: () => Promise<Iterable<unknown>>;\n\t\t\t/** Result-row identity (used to net a batch's diffs). */\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'join';\n\t\t\tcollection: string;\n\t\t\tjoin: JoinState;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'graph';\n\t\t\tcollection: string;\n\t\t\tinstance: GraphInstance<unknown>;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'reactive';\n\t\t\tcollection: string;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\t/** Re-run; returns the new rows and the read set (tables/keys/ranges). */\n\t\t\trerun: () => Promise<{\n\t\t\t\trows: unknown[];\n\t\t\t\treadTables: Set<string>;\n\t\t\t\treadKeys: Set<string>;\n\t\t\t\trangeDeps: RangeDep[];\n\t\t\t}>;\n\t\t\t/**\n\t\t\t * Stable key over `(collection, params, ctx)`. Subscriptions sharing\n\t\t\t * the same key are equivalent on the read side, so a single rerun\n\t\t\t * per change batch can serve all of them (see `reactivePairs`).\n\t\t\t */\n\t\t\trerunKey: string;\n\t\t\t/** Current result set, keyed (diffed against the next re-run). */\n\t\t\tcurrent: Map<RowKey, unknown>;\n\t\t\t/** Full-table dependencies (from `db.all`). */\n\t\t\treadTables: Set<string>;\n\t\t\t/** Row-level dependencies `table\\0key` (from `db.get`). */\n\t\t\treadKeys: Set<string>;\n\t\t\t/** Range dependencies (from `db.where`) — predicate + matched keys. */\n\t\t\trangeDeps: RangeDep[];\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'search';\n\t\t\tcollection: string;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\t/** Re-run the search against the (now-updated) shared index. */\n\t\t\trerun: () => unknown[];\n\t\t\t/** Current ranked result set, keyed (diffed against the next re-run). */\n\t\t\tcurrent: Map<RowKey, unknown>;\n\t\t\tonDiff: OnDiff;\n\t };\n\n/** A `db.where` dependency: the predicate plus the keys that matched at read. */\ntype RangeDep = {\n\ttable: string;\n\tpredicate: (row: unknown) => boolean;\n\tkeys: Set<RowKey>;\n};\n\n/**\n * A single committed change as it appears in the engine's change log and on\n * the {@link SyncEngine.streamChanges} CDC stream. Versions are monotonic\n * across the engine: a single mutation that writes N rows emits N entries\n * all sharing the same `version`.\n */\nexport type LoggedChange = {\n\t/** This engine's local monotonic version when the change was logged. */\n\tversion: number;\n\ttable: string;\n\tchange: RowChange<unknown>;\n\t/**\n\t * Wall-clock when this change was logged (Date.now()). Used by the\n\t * engine's time-based retention sweep (`changeLogRetainMs`) and\n\t * surfaced as the change-log age in {@link SyncEngine.metrics}.\n\t * Added in 1.13.0; pre-1.13.0 consumers of `LoggedChange` ignore it.\n\t */\n\tat: number;\n\t/**\n\t * Instance id that originated this change. For locally-committed changes\n\t * this is the engine's own `instanceId`; for cluster-received changes,\n\t * the originating peer's id.\n\t *\n\t * Added in 1.17.0; pre-1.17 consumers ignore it.\n\t */\n\torigin: string;\n\t/**\n\t * The ORIGINATOR's local version at commit time. For locally-committed\n\t * changes this equals `version`; for cluster-received changes, the\n\t * peer's version. Resume cursors (1.17.0+) carry `(origin, originVersion)`\n\t * pairs so a client's last-seen point matches against peer entries this\n\t * engine has logged via the bus.\n\t *\n\t * Added in 1.17.0; pre-1.17 consumers ignore it.\n\t */\n\toriginVersion: number;\n};\n\n/** Thrown by {@link SyncEngine.streamChanges} when `since` is older than the\n * oldest entry retained in the bounded change log (i.e. the consumer was\n * disconnected long enough that the engine has lost the diff). The consumer\n * should re-bootstrap from a fresh hydrate and resume from `availableSince`. */\nexport class MissedChangesError extends Error {\n\treadonly requestedSince: number;\n\treadonly availableSince: number;\n\tconstructor(requestedSince: number, availableSince: number) {\n\t\tsuper(\n\t\t\t`Change log no longer covers version ${requestedSince}; oldest available is ${availableSince}. ` +\n\t\t\t\t`Re-bootstrap and resume from ${availableSince}.`\n\t\t);\n\t\tthis.name = 'MissedChangesError';\n\t\tthis.requestedSince = requestedSince;\n\t\tthis.availableSince = availableSince;\n\t}\n}\n\n/** Options for {@link SyncEngine.streamChanges}. */\nexport type StreamChangesOptions = {\n\t/**\n\t * Last version the consumer has already processed. The stream yields\n\t * entries with `version > since`. Defaults to `0` (replay everything in\n\t * the log, then tail).\n\t */\n\tsince?: number;\n\t/**\n\t * Cancel the stream cleanly. When the signal aborts, the iterator\n\t * resolves to `done` on its next yield and unregisters its subscriber.\n\t */\n\tsignal?: AbortSignal;\n\t/**\n\t * Hard cap on the in-flight buffer for this consumer. If the engine\n\t * commits faster than the consumer iterates and the buffer overflows,\n\t * the stream rejects so the consumer notices instead of silently\n\t * skipping entries. Defaults to 10000.\n\t */\n\tmaxBuffer?: number;\n};\n\n/** Thrown by {@link SyncEngine.streamChanges} when the consumer fell so far\n * behind that the in-flight buffer overflowed. Resubscribe from the last\n * cursor the consumer successfully processed. */\nexport class CdcConsumerSlowError extends Error {\n\treadonly maxBuffer: number;\n\treadonly lastDeliveredVersion: number;\n\tconstructor(maxBuffer: number, lastDeliveredVersion: number) {\n\t\tsuper(\n\t\t\t`CDC stream buffer overflowed (max ${maxBuffer}); consumer fell behind. ` +\n\t\t\t\t`Last delivered version: ${lastDeliveredVersion}. Resubscribe with since=${lastDeliveredVersion}.`\n\t\t);\n\t\tthis.name = 'CdcConsumerSlowError';\n\t\tthis.maxBuffer = maxBuffer;\n\t\tthis.lastDeliveredVersion = lastDeliveredVersion;\n\t}\n}\n\n/**\n * Thrown by `runMutation` / `runMutations` when `mutationConcurrency` is\n * saturated AND the waiting queue is already at `mutationQueueLimit`. The\n * caller sees this immediately (no queue time) so the host can shed load\n * with a clean 429 instead of letting the queue grow unboundedly. Added\n * in 1.20.0.\n */\nexport class MutationQueueOverflowError extends Error {\n\treadonly queueLimit: number;\n\tconstructor(queueLimit: number) {\n\t\tsuper(\n\t\t\t`Mutation queue overflowed (limit ${queueLimit}); the engine is at ` +\n\t\t\t\t`its mutationConcurrency cap and the waiting queue is full. ` +\n\t\t\t\t`Retry later or shed load at the gateway.`\n\t\t);\n\t\tthis.name = 'MutationQueueOverflowError';\n\t\tthis.queueLimit = queueLimit;\n\t}\n}\n\n/**\n * Thrown by `engine.subscribe` when the calling tenant's active-subscription\n * count is already at the configured `subscriptionLimit.max`. The caller sees\n * this immediately — BEFORE authorize, hydrate, or any subscription state\n * allocation — so a rejected call leaks nothing. Added in 1.20.1.\n */\nexport class SubscriptionLimitError extends Error {\n\treadonly tenantKey: string;\n\treadonly limit: number;\n\treadonly active: number;\n\tconstructor(tenantKey: string, limit: number, active: number) {\n\t\tsuper(\n\t\t\t`Tenant \"${tenantKey}\" is at the subscription cap ` +\n\t\t\t\t`(${active}/${limit}). Close an existing subscription before opening another.`\n\t\t);\n\t\tthis.name = 'SubscriptionLimitError';\n\t\tthis.tenantKey = tenantKey;\n\t\tthis.limit = limit;\n\t\tthis.active = active;\n\t}\n}\n\n/**\n * Serializable snapshot of an engine's change log + monotonic version, returned\n * by {@link SyncEngine.exportChangeLog} and consumed by\n * {@link SyncEngineOptions.initialChangeLog} or\n * {@link SyncEngine.importChangeLog}.\n *\n * The PaaS host persists this on shard rotation (every N seconds or on graceful\n * shutdown) and hands it back to the replacement engine so resume cursors\n * referencing this `instanceId` keep working past the restart. Bounded by the\n * receiving engine's `changeLogSize` + `changeLogRetainMs` policies — entries\n * that exceed either cap on import are trimmed exactly as if they had been\n * logged live.\n *\n * Added in 1.19.0.\n */\nexport type ChangeLogSnapshot = {\n\t/** The exporting engine's `instanceId`. Receiver MUST match. */\n\tinstanceId: string;\n\t/** The exporting engine's monotonic version at snapshot time. */\n\tversion: number;\n\t/** Every retained log entry, in commit order (oldest first). */\n\tentries: ReadonlyArray<LoggedChange>;\n\t/**\n\t * Optional version-stamp the host may use to compare snapshots without\n\t * deserializing the entries (e.g. for incremental persistence). Set to\n\t * `Date.now()` at export time. Receivers ignore this field.\n\t */\n\texportedAt?: number;\n};\n\n/**\n * Options for {@link SyncEngine.replayTo}. Added in 1.22.0.\n */\nexport type ReplayOptions = {\n\t/**\n\t * Target timestamp (`Date.now()`-shaped). The engine walks the\n\t * change log forward, applying entries with `at <= targetAt`. The\n\t * result is the state as-of `targetAt` (or as close as the log\n\t * permits — see `truncated`).\n\t */\n\tat: number;\n\t/**\n\t * Optional table filter. When set, only entries whose `table` is\n\t * in this list are folded into the result; entries for other\n\t * tables are skipped. Useful for \"show me what `tasks` looked\n\t * like at T\" without paying to reconstruct every table.\n\t */\n\ttables?: ReadonlyArray<string>;\n};\n\n/**\n * Returned by {@link SyncEngine.replayTo}. Added in 1.22.0.\n *\n * - `rows` — per-table arrays of rows that existed as of `asOfAt`.\n * Keys are table names; values are the row objects (in last-write\n * order — last write wins for duplicate-keyed inserts).\n * - `asOfVersion` / `asOfAt` — the version + wall-clock of the LAST\n * entry folded into the result. May be earlier than `targetAt` if\n * no entries existed between the last-included entry and the\n * target.\n * - `truncated` — `true` when the log has been trimmed past the\n * target window (`changeLog[0].version > 1 && changeLog[0].at >\n * targetAt`). In this case, `rows` represents the state walked\n * forward from the OLDEST retained entry — NOT the actual state\n * at `targetAt`. The caller should treat the result as\n * \"best-effort given retention window\" and warn the operator.\n */\nexport type ReplayResult = {\n\tasOfVersion: number;\n\tasOfAt: number;\n\trows: Record<string, ReadonlyArray<unknown>>;\n\ttruncated: boolean;\n};\n\nexport type SyncEngineOptions = {\n\t/**\n\t * Stable identifier for this engine instance. Defaults to a per-process\n\t * random UUID. Pass a stable value (e.g. `${hostname}:${shardId}`) when\n\t * running a fleet of engines behind a cluster bus — 1.17.0+ resume\n\t * cursors carry the originating `instanceId`, so a client that reconnects\n\t * to a different shard can request a catch-up against the original's\n\t * change feed only if that instance's id matches a peer the new shard\n\t * knows about.\n\t */\n\tinstanceId?: string;\n\t/**\n\t * How many recent changes to retain for resumable reconnects. A client that\n\t * reconnects within this window gets a catch-up diff; beyond it, a fresh\n\t * snapshot. Defaults to 1024.\n\t */\n\tchangeLogSize?: number;\n\t/**\n\t * Time-based change-log retention: drop entries older than this many ms,\n\t * in addition to the count cap above. Lets a high-throughput engine keep\n\t * a SHORT log (e.g. \"60s of changes\") regardless of count, which both\n\t * bounds memory and bounds the catch-up work on reconnect. Defaults to\n\t * `null` — only the count cap (`changeLogSize`) applies.\n\t *\n\t * Added in 1.13.0.\n\t */\n\tchangeLogRetainMs?: number | null;\n\t/**\n\t * Run every mutation inside your database's transaction (see\n\t * {@link TransactionRunner}): the handler's writes commit all-or-nothing, and\n\t * the engine emits the resulting diff only after the commit. Omit to run\n\t * mutations without a transaction (each writer call is its own DB op).\n\t */\n\ttransaction?: TransactionRunner;\n\t/**\n\t * Declarative, row-level permissions keyed by table (see\n\t * {@link definePermissions}). Read rules filter every row the engine emits;\n\t * write rules gate `actions.insert/update/delete`. Add more later with\n\t * {@link SyncEngine.registerPermissions}. Type the rules at the\n\t * `definePermissions<YourCtx>(...)` call site; the engine accepts any context\n\t * (it threads `ctx` untyped to your rules).\n\t */\n\tpermissions?: PermissionsDefinition<any>;\n\t/**\n\t * Declarative row schemas keyed by table (see {@link defineSchema}): writes\n\t * are validated against them, and `migrate` lazily upcasts rows on read. Add\n\t * more later with {@link SyncEngine.registerSchema}.\n\t */\n\tschemas?: SchemaDefinition;\n\t/**\n\t * Cross-client cache for reactive query results, keyed by\n\t * `(collection, params, ctx)` — equivalent subscribers reuse a single\n\t * cached snapshot on initial subscribe instead of each re-running the\n\t * query body. Per-batch dedup (already in `reactivePairs` since 1.1) is\n\t * unchanged; this adds *cross-batch* sharing.\n\t *\n\t * Entries are invalidated when a write overlaps their read set (same\n\t * `isReactiveAffected` check live subscriptions use), and bounded by an\n\t * LRU + an optional TTL.\n\t *\n\t * Defaults: `{ max: 256, ttlMs: 60_000 }`. Pass `{ max: 0 }` to disable.\n\t */\n\treactiveCache?: {\n\t\tmax?: number;\n\t\tttlMs?: number;\n\t};\n\t/**\n\t * Per-call telemetry for `sandboxedHandler` mutations. When set, every\n\t * sandboxed call fires `onMetrics(record)` after completion with\n\t * `{ id, mutationName, durationMs, cpuMs, heapBytes, ok, errorName,\n\t * errorMessage, timestamp }`. Wire to a sync collection, your\n\t * observability backend, a Drizzle table, anything you want.\n\t *\n\t * Hook failures are swallowed (a misbehaving metrics sink must NOT\n\t * crash the caller's mutation). Adding the hook switches the runner\n\t * to `callable.callWithMetrics`, which is a small per-call cost\n\t * (~0.05 ms) — disable for hot-path mutations that don't need it.\n\t *\n\t * Off by default.\n\t *\n\t * @see {@link HandlerMetricsRecord}\n\t */\n\thandlerMetrics?: HandlerMetricsHook;\n\t/**\n\t * Allowlist + auth-injection map for `actions.fetch(url, init)` calls\n\t * issued from inside a `sandboxedHandler`. Each entry is keyed by\n\t * hostname (`'api.stripe.com'`); the value's `authorization` is a\n\t * sync or async callback computed on the host so the secret never\n\t * crosses into the JSC sandbox. Requests to non-allowlisted hosts\n\t * are rejected before any network call.\n\t *\n\t * Without this set, `actions.fetch` throws \"no bridgeFetch config.\"\n\t * Plain (non-sandboxed) handlers don't use this — they can just call\n\t * `fetch` directly since they run in the host process.\n\t *\n\t * @see {@link BridgeFetchConfig}\n\t */\n\tbridgeFetch?: BridgeFetchConfig;\n\t/**\n\t * Seed the engine's change log on boot from a prior snapshot — produced by\n\t * {@link SyncEngine.exportChangeLog} on the previous instance, persisted by\n\t * the host across a shard reboot, then handed back here. Cursors that\n\t * referenced this engine's `instanceId` stay resumable past the restart\n\t * (provided their last-seen point still lives in the retained log).\n\t *\n\t * The snapshot's `instanceId` MUST match `options.instanceId` (otherwise\n\t * `createSyncEngine` throws — a wrong-id restore would silently break the\n\t * resume contract). Snapshot `version` becomes this engine's local\n\t * monotonic version; entries are inserted in version order. Subscribers,\n\t * permissions, schemas, schedules, packs, mutations, and the reactive\n\t * cache are NOT in the snapshot — re-register them as normal after\n\t * `createSyncEngine` returns. Added in 1.19.0.\n\t */\n\tinitialChangeLog?: ChangeLogSnapshot;\n\t/**\n\t * Maximum concurrent in-flight mutations (`runMutation` + `runMutations`).\n\t * Calls beyond the limit wait in a FIFO queue and run as slots free up;\n\t * `engine.metrics().mutations.queued` surfaces the queue depth.\n\t *\n\t * A single tenant flooding `runMutation` can otherwise drive unbounded\n\t * memory growth (per-mutation `actions` buffers, retry timers, sandbox\n\t * invocations queued against the isolate pool). Set this to a value\n\t * appropriate for the host's tenant tier — e.g. `32` for a free tier,\n\t * `256` for paid. Without this option the engine is unbounded\n\t * (matching pre-1.20 behavior).\n\t *\n\t * Sandboxed mutations are gated by the same semaphore. If you need\n\t * finer-grained control (sandbox-only throttling), see\n\t * `@absolutejs/isolated-jsc`'s pool size — that's the lower layer.\n\t *\n\t * Added in 1.20.0.\n\t */\n\tmutationConcurrency?: number;\n\t/**\n\t * Cap on the queue of waiting mutations once `mutationConcurrency` is\n\t * saturated. Calls beyond this cap throw {@link MutationQueueOverflowError}\n\t * immediately instead of queueing — the host can surface a clean 429 or\n\t * apply a tenant-specific shed policy. Defaults to unbounded (queue\n\t * never rejects). Only meaningful when `mutationConcurrency` is set.\n\t *\n\t * Added in 1.20.0.\n\t */\n\tmutationQueueLimit?: number;\n\t/**\n\t * Per-tenant active-subscription cap. Symmetric to\n\t * {@link SyncEngineOptions.mutationConcurrency} on the read side: a\n\t * single tenant opening thousands of subscriptions would otherwise\n\t * exhaust the engine's per-subscription bookkeeping\n\t * (`active`/`tableIndex` Maps, the reactive cache, per-row diff\n\t * computation cost).\n\t *\n\t * `key` derives a tenant identifier from `(ctx, args)`; returning\n\t * `undefined` skips the cap for that call (e.g. internal/system\n\t * subscriptions). When the active count for a key reaches `max`, the\n\t * next `subscribe` throws {@link SubscriptionLimitError} BEFORE any\n\t * authorize, hydrate, or state allocation — so a denied call leaks\n\t * nothing.\n\t *\n\t * Active counts are surfaced through `engine.metrics().subscriptions.byTenant`\n\t * for tier monitoring. Added in 1.20.1.\n\t */\n\tsubscriptionLimit?: {\n\t\tmax: number;\n\t\tkey: (ctx: unknown, args: { collection: string }) => string | undefined;\n\t};\n\t/**\n\t * Optional OpenTelemetry tracer provider. When set, the engine\n\t * wraps `subscribe`, `runMutation`, `runMutations`, and cluster\n\t * fan-out in spans named `sync.<op>` with `ABS_ATTRS` semantic\n\t * conventions (`abs.engine.id`, `abs.collection`, `abs.mutation`,\n\t * etc.). When absent, all tracing is a zero-allocation noop —\n\t * existing call sites pay nothing. Added in 1.21.0.\n\t *\n\t * Pass any `@opentelemetry/api`-compatible `TracerProvider`. See\n\t * `@absolutejs/telemetry` for the type shape — sync re-uses its\n\t * helpers but doesn't peer-dep `@opentelemetry/api` directly.\n\t *\n\t * @example\n\t * ```ts\n\t * import { NodeTracerProvider } from '@opentelemetry/sdk-node';\n\t * const tp = new NodeTracerProvider({ ... });\n\t * tp.register();\n\t * const engine = createSyncEngine({ tracerProvider: tp });\n\t * ```\n\t */\n\ttracerProvider?: TelemetryTracerProvider;\n};\n\nconst defaultKey = (row: unknown): RowKey => (row as { id: RowKey }).id;\n\nconst shallowEqual = (a: unknown, b: unknown): boolean => {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\tif (\n\t\ttypeof a !== 'object' ||\n\t\ttypeof b !== 'object' ||\n\t\ta === null ||\n\t\tb === null\n\t) {\n\t\treturn false;\n\t}\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\treturn (\n\t\taKeys.length === bKeys.length &&\n\t\taKeys.every(\n\t\t\t(k) =>\n\t\t\t\t(a as Record<string, unknown>)[k] ===\n\t\t\t\t(b as Record<string, unknown>)[k]\n\t\t)\n\t);\n};\n\n/**\n * Per-object stable identifier — paired with {@link stableSubKey} so two\n * subscriptions that share the same `(collection, params, ctx)` get the same\n * key and have their reactive rerun deduplicated within a change batch (the\n * fan-out fix in {@link reactivePairs}). Falls back to an incrementing id\n * stored on a WeakMap for values JSON can't represent (functions, classes,\n * cyclic structures), so identity-equal ctxs still share a key while\n * different-identity ones don't accidentally merge.\n */\nconst subKeyIds = new WeakMap<object, string>();\nlet subKeyCounter = 0;\nconst stableValueKey = (value: unknown): string => {\n\tif (value === undefined) return 'u';\n\tif (value === null) return 'n';\n\tconst tag = typeof value;\n\tif (tag === 'string') return `s:${value as string}`;\n\tif (tag === 'number' || tag === 'boolean' || tag === 'bigint') {\n\t\treturn `${tag[0]}:${String(value)}`;\n\t}\n\tif (tag !== 'object') return `${tag[0]}:fn`;\n\ttry {\n\t\t// Stable ordering: sort keys before serialising so { a, b } and { b, a }\n\t\t// produce the same string. JSON.stringify with a replacer keeps it tight.\n\t\treturn `o:${JSON.stringify(value, (_k, v): unknown => {\n\t\t\tif (v === null || typeof v !== 'object' || Array.isArray(v))\n\t\t\t\treturn v;\n\t\t\tconst record = v as Record<string, unknown>;\n\t\t\tconst sorted: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(record).sort()) {\n\t\t\t\tsorted[key] = record[key];\n\t\t\t}\n\n\t\t\treturn sorted;\n\t\t})}`;\n\t} catch {\n\t\t// Cyclic or unserializable — fall back to per-object identity.\n\t\tconst obj = value as object;\n\t\tlet id = subKeyIds.get(obj);\n\t\tif (id === undefined) {\n\t\t\tsubKeyCounter += 1;\n\t\t\tid = `i${subKeyCounter}`;\n\t\t\tsubKeyIds.set(obj, id);\n\t\t}\n\n\t\treturn `i:${id}`;\n\t}\n};\n\nconst stableSubKey = (\n\tcollection: string,\n\tparams: unknown,\n\tctx: unknown\n): string => `${collection}|${stableValueKey(params)}|${stableValueKey(ctx)}`;\n\n/** Shallow-equal ignoring the search score field — used to suppress re-emitting\n * a search result whose only change is BM25 score drift as the corpus grows. */\nconst equalsIgnoringScore = (a: unknown, b: unknown): boolean => {\n\tif (\n\t\ttypeof a !== 'object' ||\n\t\ttypeof b !== 'object' ||\n\t\ta === null ||\n\t\tb === null\n\t) {\n\t\treturn a === b;\n\t}\n\tconst strip = (value: Record<string, unknown>) =>\n\t\tObject.keys(value).filter((k) => k !== SEARCH_SCORE_FIELD);\n\tconst aKeys = strip(a as Record<string, unknown>);\n\tconst bKeys = strip(b as Record<string, unknown>);\n\treturn (\n\t\taKeys.length === bKeys.length &&\n\t\taKeys.every(\n\t\t\t(k) =>\n\t\t\t\t(a as Record<string, unknown>)[k] ===\n\t\t\t\t(b as Record<string, unknown>)[k]\n\t\t)\n\t);\n};\n\n/**\n * The Tier 3 sync engine: a registry of collections plus the view syncer. It is\n * transport-agnostic — `subscribe` returns the initial snapshot and an\n * `onDiff` stream, which an Elysia/SSE layer wires to a connection, and\n * `applyChange` is the change feed you drive from your mutations.\n *\n * Access control is first-class: every subscribe runs the collection's\n * `authorize`, and a collection's `match`/`hydrate` scope rows to the caller, so\n * a change to a row the caller can't see never reaches them.\n */\nexport const createSyncEngine = (\n\toptions: SyncEngineOptions = {}\n): SyncEngine => {\n\t// Heterogeneous registry: `any` here is what lets collections of different\n\t// row/param/context types share one map (the public `register`/`subscribe`\n\t// surface stays fully typed).\n\tconst registry = new Map<\n\t\tstring,\n\t\t| CollectionDefinition<any, any, any>\n\t\t| JoinCollectionDefinition<any, any, any, any, any>\n\t\t| GraphCollectionDefinition<any, any, any>\n\t\t| ReactiveQueryDefinition<any, any, any>\n\t\t| SearchCollectionDefinition<any, any, any>\n\t>();\n\tconst mutations = new Map<string, MutationDefinition<any, any, any>>();\n\t// Lazy sandbox runners keyed by mutation name. Built on first call to a\n\t// mutation that has `sandboxedHandler` set; reused thereafter. Engine has\n\t// no teardown; the OS reaps the isolate workers on process exit.\n\tconst sandboxRunners = new Map<\n\t\tstring,\n\t\t(\n\t\t\targs: unknown,\n\t\t\tctx: unknown,\n\t\t\tactions: MutationActions\n\t\t) => Promise<unknown>\n\t>();\n\tconst writers = new Map<string, TableWriter>();\n\tconst readers = new Map<string, TableReader>();\n\tconst schedules = new Map<string, ScheduleDefinition>();\n\t// Pack registry — table -> owning pack name, and the list of registered\n\t// packs for engine.inspect().packs.\n\tconst packTableOwners = new Map<string, string>();\n\tconst registeredPacks: RegisteredPack[] = [];\n\t// Declarative row-level permissions, keyed by table. Stored with an `unknown`\n\t// context — the engine threads ctx untyped — while the public\n\t// `definePermissions`/`registerPermissions` surface stays fully typed.\n\tconst permissions = new Map<string, TablePermissions<unknown, unknown>>();\n\tfor (const [table, rules] of Object.entries(options.permissions ?? {})) {\n\t\tpermissions.set(table, rules as TablePermissions<unknown, unknown>);\n\t}\n\tconst readRuleFor = (\n\t\ttable: string\n\t): ReadRule<unknown, unknown> | undefined => permissions.get(table)?.read;\n\tconst writeRuleFor = (\n\t\ttable: string,\n\t\top: 'insert' | 'update' | 'delete'\n\t): WriteRule<unknown, unknown> | undefined => {\n\t\tconst rules = permissions.get(table);\n\t\treturn rules?.[op] ?? rules?.write;\n\t};\n\t// Declarative row schemas, keyed by table.\n\tconst schemas = new Map<string, TableSchema<unknown>>();\n\tfor (const [table, schema] of Object.entries(options.schemas ?? {})) {\n\t\tschemas.set(table, schema as TableSchema<unknown>);\n\t}\n\t// CRDT fields, keyed by table: field name -> mergeable backend. Set via\n\t// registerCrdt; consulted in makeActions to merge (not overwrite) on write.\n\tconst crdtFields = new Map<\n\t\tstring,\n\t\tRecord<string, CrdtMergeable<unknown>>\n\t>();\n\t// Validate a write against its table's schema: every field on insert; only\n\t// the supplied fields on update. Throws SchemaError naming the bad field.\n\tconst validateWrite = (\n\t\ttable: string,\n\t\top: 'insert' | 'update',\n\t\trow: unknown\n\t) => {\n\t\tconst schema = schemas.get(table);\n\t\tif (schema === undefined || typeof row !== 'object' || row === null) {\n\t\t\treturn;\n\t\t}\n\t\tconst record = row as Record<string, unknown>;\n\t\tfor (const [fieldName, validate] of Object.entries(schema.fields)) {\n\t\t\tconst present = fieldName in record;\n\t\t\tif (op === 'update' && !present) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!validate(record[fieldName])) {\n\t\t\t\tthrow new SchemaError(table, fieldName);\n\t\t\t}\n\t\t}\n\t};\n\t// Lazily upcast a stored/raw row to the current shape (identity if no migrate).\n\tconst migrateRow = (table: string, row: unknown): unknown => {\n\t\tconst migrate = schemas.get(table)?.migrate;\n\t\treturn migrate ? migrate(row) : row;\n\t};\n\t// Reactive (read-set-tracked) subscriptions, scanned on each change since\n\t// their dependencies (the tables they read) are dynamic, not in tableIndex.\n\tconst reactiveSubs = new Set<\n\t\tExtract<ActiveSubscription, { kind: 'reactive' }>\n\t>();\n\t// Search subscriptions + one shared index per search collection, kept live\n\t// from the source table's change feed (like reactiveSubs, not in tableIndex).\n\tconst searchSubs = new Set<\n\t\tExtract<ActiveSubscription, { kind: 'search' }>\n\t>();\n\tconst searchIndexes = new Map<\n\t\tstring,\n\t\t{\n\t\t\tindex: SearchIndex<unknown, unknown>;\n\t\t\tdefinition: SearchCollectionDefinition<unknown, unknown, unknown>;\n\t\t\thydrated: boolean;\n\t\t}\n\t>();\n\tconst active = new Map<string, Set<ActiveSubscription>>();\n\t// Which collections read each table — so a table change fans to all of them.\n\tconst tableIndex = new Map<string, Set<string>>();\n\n\t// Monotonic change feed: every applyChange bumps `version` and appends to a\n\t// bounded log, so a client can resume from the version it last applied.\n\tconst changeLogSize = options.changeLogSize ?? 1024;\n\tconst changeLogRetainMs = options.changeLogRetainMs ?? null;\n\tconst changeLog: LoggedChange[] = [];\n\tlet version = 0;\n\t// Engine-level counters surfaced via `engine.metrics()` (1.13.0).\n\tconst engineStartedAt = Date.now();\n\tlet mutationsCompleted = 0;\n\tlet mutationsFailed = 0;\n\tlet mutationsRetried = 0;\n\tlet mutationsInFlight = 0;\n\n\t// 1.20.0: optional FIFO semaphore gating mutation entry. Capacity is\n\t// `mutationConcurrency`; waiters queue with optional `mutationQueueLimit`\n\t// rejection. New arrivals that find ANY queued waiter also queue (FIFO\n\t// preservation), so a steady arrival rate can't starve an early waiter.\n\tconst mutationWaiters: (() => void)[] = [];\n\tlet mutationsQueued = 0;\n\n\t// 1.24.0: G7 migration fence. While `activeFences` is non-empty,\n\t// `runMutation` rejects with EngineFencedError. Reads remain\n\t// available so the snapshot transport doesn't block subscribers.\n\t// Multi-fence compose: every handle must lift() before the engine\n\t// unfences. The reason of the OLDEST fence is reported on rejection.\n\tconst activeFences = new Set<FenceHandle>();\n\n\tconst acquireMutationSlot = async (): Promise<void> => {\n\t\tconst limit = options.mutationConcurrency;\n\t\tif (limit === undefined) {\n\t\t\t// No semaphore — still bump the metric so `inFlight` is\n\t\t\t// always accurate, but skip all the queue plumbing.\n\t\t\tmutationsInFlight += 1;\n\t\t\treturn;\n\t\t}\n\t\t// FIFO: if a slot is open AND no waiters are queued, take it\n\t\t// synchronously. The increment is part of the same synchronous\n\t\t// step as the check, so two arrivals can't both pass when only\n\t\t// one slot remains.\n\t\tif (mutationsInFlight < limit && mutationWaiters.length === 0) {\n\t\t\tmutationsInFlight += 1;\n\t\t\treturn;\n\t\t}\n\t\t// Queue, or reject if the queue is also capped.\n\t\tconst queueLimit = options.mutationQueueLimit;\n\t\tif (queueLimit !== undefined && mutationsQueued >= queueLimit) {\n\t\t\tthrow new MutationQueueOverflowError(queueLimit);\n\t\t}\n\t\tmutationsQueued += 1;\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tmutationWaiters.push(resolve);\n\t\t\t});\n\t\t} finally {\n\t\t\tmutationsQueued -= 1;\n\t\t}\n\t\t// Wake means a slot just opened up FOR US (`releaseMutationSlot`\n\t\t// only resolves one waiter per release). Claim it now — atomic\n\t\t// with the wake step.\n\t\tmutationsInFlight += 1;\n\t};\n\n\tconst releaseMutationSlot = (): void => {\n\t\tmutationsInFlight -= 1;\n\t\tif (options.mutationConcurrency === undefined) return;\n\t\tconst next = mutationWaiters.shift();\n\t\tif (next !== undefined) next();\n\t};\n\n\t// 1.20.1: per-tenant subscription cap. Active count keyed by the\n\t// host-supplied `subscriptionLimit.key(ctx, args)`. `undefined` from\n\t// `key()` means \"exempt this call from the cap\" — internal / system\n\t// subscriptions can skip the bookkeeping entirely.\n\tconst subscriptionsByTenant = new Map<string, number>();\n\n\tconst acquireSubscriptionSlot = (\n\t\tctx: unknown,\n\t\targs: { collection: string }\n\t): string | undefined => {\n\t\tconst cap = options.subscriptionLimit;\n\t\tif (cap === undefined) return undefined;\n\t\tconst tenantKey = cap.key(ctx, args);\n\t\tif (tenantKey === undefined) return undefined;\n\t\tconst active = subscriptionsByTenant.get(tenantKey) ?? 0;\n\t\tif (active >= cap.max) {\n\t\t\tthrow new SubscriptionLimitError(tenantKey, cap.max, active);\n\t\t}\n\t\tsubscriptionsByTenant.set(tenantKey, active + 1);\n\t\treturn tenantKey;\n\t};\n\n\tconst releaseSubscriptionSlot = (tenantKey: string | undefined): void => {\n\t\tif (tenantKey === undefined) return;\n\t\tconst active = subscriptionsByTenant.get(tenantKey);\n\t\tif (active === undefined || active <= 1) {\n\t\t\tsubscriptionsByTenant.delete(tenantKey);\n\t\t} else {\n\t\t\tsubscriptionsByTenant.set(tenantKey, active - 1);\n\t\t}\n\t};\n\n\t// Cross-client reactive query cache (1.3+). Keyed by stableSubKey, holds\n\t// the result + read set so a fresh subscribe with the same key reuses the\n\t// rerun instead of hitting the DB again. Per-batch dedup (since 1.1) is\n\t// already in `reactivePairs`; this lifts the sharing across batches.\n\t//\n\t// Entries are invalidated when a write overlaps the cached read set (same\n\t// `isReactiveAffected` check live subs use). LRU-bounded; optional TTL.\n\tconst reactiveCacheMax = options.reactiveCache?.max ?? 256;\n\tconst reactiveCacheTtlMs = options.reactiveCache?.ttlMs ?? 60_000;\n\ttype CachedRerun = {\n\t\trerunKey: string;\n\t\trows: unknown[];\n\t\treadTables: Set<string>;\n\t\treadKeys: Set<string>;\n\t\trangeDeps: RangeDep[];\n\t\tversion: number;\n\t\texpiresAt: number;\n\t};\n\t// `Map` preserves insertion order — re-set on access for LRU semantics.\n\tconst cachedReruns = new Map<string, CachedRerun>();\n\tconst touchCacheEntry = (key: string, entry: CachedRerun) => {\n\t\tcachedReruns.delete(key);\n\t\tcachedReruns.set(key, entry);\n\t};\n\tconst readCacheEntry = (key: string): CachedRerun | undefined => {\n\t\tif (reactiveCacheMax <= 0) return undefined;\n\t\tconst entry = cachedReruns.get(key);\n\t\tif (entry === undefined) return undefined;\n\t\tif (reactiveCacheTtlMs > 0 && entry.expiresAt < Date.now()) {\n\t\t\tcachedReruns.delete(key);\n\n\t\t\treturn undefined;\n\t\t}\n\t\ttouchCacheEntry(key, entry);\n\n\t\treturn entry;\n\t};\n\tconst writeCacheEntry = (entry: CachedRerun) => {\n\t\tif (reactiveCacheMax <= 0) return;\n\t\tcachedReruns.set(entry.rerunKey, entry);\n\t\t// LRU eviction: oldest insertion wins out when over budget.\n\t\twhile (cachedReruns.size > reactiveCacheMax) {\n\t\t\tconst oldest = cachedReruns.keys().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tcachedReruns.delete(oldest);\n\t\t}\n\t};\n\t// Devtools activity stream — listeners are notified of changes, mutation\n\t// outcomes, and subscribe/unsubscribe. Cheap (a no-op) when no one's watching.\n\tconst activityListeners = new Set<(event: EngineActivity) => void>();\n\tconst emitActivity = (event: EngineActivity) => {\n\t\tfor (const listener of activityListeners) {\n\t\t\tlistener(event);\n\t\t}\n\t};\n\t// Outbound CDC stream subscribers — `streamChanges()` adds itself here.\n\t// Notifications fire from `logChange` so every appended log entry reaches\n\t// every active streamer atomically with the log push.\n\tconst streamSubscribers = new Set<(entry: LoggedChange) => void>();\n\tconst runInTransaction = options.transaction;\n\t// Cluster fan-out: a stable id so we ignore our own broadcasts, and the bus\n\t// (set by connectCluster) we publish locally-committed changes to. Pass\n\t// `options.instanceId` for stable cross-process identity (e.g. the\n\t// hostname or a config-supplied UUID) — 1.17.0+ resume cursors travel\n\t// across instances, so the id needs to be stable across restarts if you\n\t// want resume to keep working past a reboot.\n\tconst instanceId =\n\t\toptions.instanceId ??\n\t\tglobalThis.crypto?.randomUUID?.() ??\n\t\t`i${Math.random()}`;\n\tlet clusterBus: ClusterBus | undefined;\n\n\t// 1.21.0: OTel tracer (noop when options.tracerProvider is unset).\n\t// All hot-path tracing flows through this — zero allocations when\n\t// the provider is absent because the noop tracer is a singleton.\n\tconst tracer = tracerOrNoop(options.tracerProvider, '@absolutejs/sync');\n\n\t// 1.19.0: optional boot-time restore from a prior engine's snapshot. Must\n\t// happen BEFORE any local writes — we validate by checking version === 0\n\t// inside importChangeLog and call it once here from the construction path.\n\tconst importChangeLog = (snapshot: ChangeLogSnapshot): number => {\n\t\tif (version !== 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`[sync] importChangeLog: engine already has version ${version}; ` +\n\t\t\t\t\t`restore must happen before any local writes commit.`\n\t\t\t);\n\t\t}\n\t\tif (snapshot.instanceId !== instanceId) {\n\t\t\tthrow new Error(\n\t\t\t\t`[sync] importChangeLog: snapshot instanceId \"${snapshot.instanceId}\" ` +\n\t\t\t\t\t`does not match this engine's instanceId \"${instanceId}\". ` +\n\t\t\t\t\t`Pass options.instanceId = \"${snapshot.instanceId}\" to createSyncEngine.`\n\t\t\t);\n\t\t}\n\t\t// Adopt version + entries. logChange's retention sweeps still apply,\n\t\t// so over-large snapshots get trimmed exactly like live logs would.\n\t\tversion = snapshot.version;\n\t\tfor (const entry of snapshot.entries) {\n\t\t\tchangeLog.push(entry);\n\t\t}\n\t\t// Apply count cap once after the bulk push (cheaper than per-entry).\n\t\twhile (changeLog.length > changeLogSize) {\n\t\t\tchangeLog.shift();\n\t\t}\n\t\t// Apply time-based retention to the imported tail.\n\t\tif (changeLogRetainMs !== null && changeLogRetainMs > 0) {\n\t\t\tconst cutoff = Date.now() - changeLogRetainMs;\n\t\t\twhile (changeLog.length > 0 && changeLog[0]!.at < cutoff) {\n\t\t\t\tchangeLog.shift();\n\t\t\t}\n\t\t}\n\t\treturn snapshot.entries.length;\n\t};\n\n\tif (options.initialChangeLog !== undefined) {\n\t\timportChangeLog(options.initialChangeLog);\n\t}\n\n\tconst broadcast = (\n\t\tchanges: { table: string; change: RowChange<unknown> }[],\n\t\t// 1.17.0 — the local version at the moment of this broadcast, so\n\t\t// peers can log the changes against `(instanceId, originVersion)`\n\t\t// and serve cross-instance resume from their own log.\n\t\toriginVersion: number\n\t) => {\n\t\tif (clusterBus !== undefined && changes.length > 0) {\n\t\t\tvoid clusterBus.publish({ changes, origin: instanceId, originVersion });\n\t\t}\n\t};\n\n\tconst subsFor = (collection: string) => {\n\t\tlet set = active.get(collection);\n\t\tif (set === undefined) {\n\t\t\tset = new Set();\n\t\t\tactive.set(collection, set);\n\t\t}\n\t\treturn set;\n\t};\n\n\tconst addTableIndex = (table: string, name: string) => {\n\t\tlet set = tableIndex.get(table);\n\t\tif (set === undefined) {\n\t\t\tset = new Set();\n\t\t\ttableIndex.set(table, set);\n\t\t}\n\t\tset.add(name);\n\t};\n\n\t/** A side change that fails its filter becomes a leave (delete from the join). */\n\tconst sideChange = (\n\t\tchange: RowChange<unknown>,\n\t\tmatch?: (row: unknown) => boolean\n\t): RowChange<unknown> =>\n\t\tchange.op !== 'delete' && match !== undefined && !match(change.row)\n\t\t\t? { op: 'delete', row: change.row }\n\t\t\t: change;\n\n\tconst EMPTY_DIFF: ViewDiff<unknown> = {\n\t\tadded: [],\n\t\tremoved: [],\n\t\tchanged: []\n\t};\n\n\t/** Apply one change to a subscription's state and return its diff (no emit). */\n\tconst subscriptionDiff = async (\n\t\tsubscription: ActiveSubscription,\n\t\ttable: string,\n\t\tchange: RowChange<unknown>\n\t): Promise<ViewDiff<unknown>> => {\n\t\tif (subscription.kind === 'graph') {\n\t\t\treturn subscription.instance.applyChange(table, change);\n\t\t}\n\t\tif (subscription.kind === 'join') {\n\t\t\tconst js = subscription.join;\n\t\t\tif (table === js.leftTable) {\n\t\t\t\treturn js.op.applyLeft(sideChange(change, js.leftMatch));\n\t\t\t}\n\t\t\tif (table === js.rightTable) {\n\t\t\t\treturn js.op.applyRight(sideChange(change, js.rightMatch));\n\t\t\t}\n\t\t\treturn EMPTY_DIFF;\n\t\t}\n\t\tif (subscription.kind === 'reactive') {\n\t\t\t// Reactive subs re-run as a whole (see reactivePairs), not per change.\n\t\t\treturn EMPTY_DIFF;\n\t\t}\n\t\tif (subscription.kind === 'search') {\n\t\t\t// Search subs re-rank as a whole (see searchPairs), not per change.\n\t\t\treturn EMPTY_DIFF;\n\t\t}\n\t\tif (subscription.incremental) {\n\t\t\ttry {\n\t\t\t\treturn subscription.view.apply(change);\n\t\t\t} catch {\n\t\t\t\t// The predicate couldn't decide this change (e.g. an operator the\n\t\t\t\t// inferred matcher doesn't support) — degrade to a correct refetch\n\t\t\t\t// rather than a wrong diff.\n\t\t\t\treturn subscription.view.reset(await subscription.rehydrate());\n\t\t\t}\n\t\t}\n\t\treturn subscription.view.reset(await subscription.rehydrate());\n\t};\n\n\t/** Active subscriptions whose collection reads `table`. */\n\tconst subscriptionsForTable = function* (\n\t\ttable: string\n\t): Generator<ActiveSubscription> {\n\t\tconst names = tableIndex.get(table);\n\t\tif (names === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const name of names) {\n\t\t\tconst set = active.get(name);\n\t\t\tif (set === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tyield* set;\n\t\t}\n\t};\n\n\t/**\n\t * Net a batch's per-change diffs by key, relative to the pre-batch state, so a\n\t * mutation that touches the same row twice collapses to one coherent change:\n\t * add-then-remove cancels, add-then-update stays an add, remove-then-add\n\t * becomes a change.\n\t */\n\tconst mergeViewDiffs = (\n\t\tdiffs: ViewDiff<unknown>[],\n\t\tkey: (row: unknown) => RowKey\n\t): ViewDiff<unknown> => {\n\t\ttype Net = { state: 'added' | 'changed' | 'removed'; row: unknown };\n\t\tconst net = new Map<RowKey, Net>();\n\t\tfor (const diff of diffs) {\n\t\t\tfor (const row of diff.removed) {\n\t\t\t\tconst previous = net.get(key(row));\n\t\t\t\tif (previous?.state === 'added') {\n\t\t\t\t\tnet.delete(key(row));\n\t\t\t\t} else {\n\t\t\t\t\tnet.set(key(row), { state: 'removed', row });\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const row of diff.added) {\n\t\t\t\tconst previous = net.get(key(row));\n\t\t\t\tnet.set(key(row), {\n\t\t\t\t\tstate: previous?.state === 'removed' ? 'changed' : 'added',\n\t\t\t\t\trow\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const row of diff.changed) {\n\t\t\t\tconst previous = net.get(key(row));\n\t\t\t\tnet.set(key(row), {\n\t\t\t\t\tstate: previous?.state === 'added' ? 'added' : 'changed',\n\t\t\t\t\trow\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst added: unknown[] = [];\n\t\tconst changed: unknown[] = [];\n\t\tconst removed: unknown[] = [];\n\t\tfor (const { state, row } of net.values()) {\n\t\t\tif (state === 'added') {\n\t\t\t\tadded.push(row);\n\t\t\t} else if (state === 'changed') {\n\t\t\t\tchanged.push(row);\n\t\t\t} else {\n\t\t\t\tremoved.push(row);\n\t\t\t}\n\t\t}\n\t\treturn { added, changed, removed };\n\t};\n\n\ttype ReactiveSub = Extract<ActiveSubscription, { kind: 'reactive' }>;\n\n\tconst depKey = (table: string, key: RowKey): string => `${table} ${key}`;\n\n\t/** The key of a changed row under its table's reader key (if one is set). */\n\tconst changedKeyFor = (\n\t\ttable: string,\n\t\tchange: RowChange<unknown>\n\t): RowKey | undefined => readers.get(table)?.key?.(change.row);\n\n\t/**\n\t * An instrumented read handle: `all` records a full-table dependency; `get`\n\t * records a precise row-key dependency when the table's reader has a `key`\n\t * (else falls back to a table dependency).\n\t */\n\tconst makeReadHandle = (\n\t\tctx: unknown,\n\t\treadTables: Set<string>,\n\t\treadKeys: Set<string>,\n\t\trangeDeps: RangeDep[],\n\t\t// Schedules read unscoped (trusted server code); subscriptions apply rules.\n\t\tapplyRules = true\n\t): ReadHandle => {\n\t\tconst readerFor = (table: string): TableReader => {\n\t\t\tconst reader = readers.get(table);\n\t\t\tif (reader === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No reader registered for table \"${table}\" — register one with engine.registerReader`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn reader;\n\t\t};\n\t\tconst ruleFor = (table: string) =>\n\t\t\tapplyRules ? readRuleFor(table) : undefined;\n\n\t\treturn {\n\t\t\tall: async (table) => {\n\t\t\t\treadTables.add(table);\n\t\t\t\t// Migrate raw rows to the current shape, then scope by read rule.\n\t\t\t\tconst rows = [...(await readerFor(table).all(ctx))].map((row) =>\n\t\t\t\t\tmigrateRow(table, row)\n\t\t\t\t);\n\t\t\t\tconst rule = ruleFor(table);\n\t\t\t\treturn (\n\t\t\t\t\trule ? rows.filter((row) => rule(ctx, row)) : rows\n\t\t\t\t) as never[];\n\t\t\t},\n\t\t\tget: async (table, key) => {\n\t\t\t\tconst reader = readerFor(table);\n\t\t\t\tif (reader.get === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Reader for table \"${table}\" has no get(); use db.all() or add get`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (reader.key !== undefined) {\n\t\t\t\t\treadKeys.add(depKey(table, key));\n\t\t\t\t} else {\n\t\t\t\t\treadTables.add(table);\n\t\t\t\t}\n\t\t\t\tconst raw = await reader.get(key, ctx);\n\t\t\t\tconst row =\n\t\t\t\t\traw === undefined ? undefined : migrateRow(table, raw);\n\t\t\t\tconst rule = ruleFor(table);\n\t\t\t\t// A row the caller can't read reads as absent.\n\t\t\t\treturn (\n\t\t\t\t\trule && row !== undefined && !rule(ctx, row)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: row\n\t\t\t\t) as never;\n\t\t\t},\n\t\t\twhere: async (table, predicate) => {\n\t\t\t\tconst reader = readerFor(table);\n\t\t\t\tconst rule = ruleFor(table);\n\t\t\t\t// Fold the read rule into the range predicate, so an unreadable row\n\t\t\t\t// never matches and a visibility flip still re-runs the query.\n\t\t\t\tconst effective = (\n\t\t\t\t\trule\n\t\t\t\t\t\t? (row: unknown) =>\n\t\t\t\t\t\t\t\t(predicate as (r: unknown) => boolean)(row) &&\n\t\t\t\t\t\t\t\trule(ctx, row)\n\t\t\t\t\t\t: (predicate as (row: unknown) => boolean)\n\t\t\t\t) as (row: unknown) => boolean;\n\t\t\t\tconst matched = [...(await reader.all(ctx))]\n\t\t\t\t\t.map((row) => migrateRow(table, row))\n\t\t\t\t\t.filter(effective);\n\t\t\t\tif (reader.key !== undefined) {\n\t\t\t\t\t// Remember which rows matched, so an update/delete that pulls a\n\t\t\t\t\t// row out of the range still re-runs (it's in this key set).\n\t\t\t\t\tconst key = reader.key;\n\t\t\t\t\trangeDeps.push({\n\t\t\t\t\t\ttable,\n\t\t\t\t\t\tpredicate: effective,\n\t\t\t\t\t\tkeys: new Set(matched.map(key))\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\treadTables.add(table);\n\t\t\t\t}\n\t\t\t\treturn matched as never[];\n\t\t\t}\n\t\t};\n\t};\n\n\tconst writerFor = (table: string): TableWriter => {\n\t\tconst writer = writers.get(table);\n\t\tif (writer === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`No writer registered for table \"${table}\" — register one with engine.registerWriter, or use actions.change`\n\t\t\t);\n\t\t}\n\t\treturn writer;\n\t};\n\n\t// Load the committed row a write targets (by the table's reader), if any — so\n\t// authorization and CRDT merge both reflect committed state, not the payload.\n\tconst readExisting = async (\n\t\ttable: string,\n\t\tvalue: unknown,\n\t\tctx: unknown\n\t): Promise<unknown> => {\n\t\tconst reader = readers.get(table);\n\t\tif (reader?.get === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst id = reader.key\n\t\t\t? reader.key(value)\n\t\t\t: (value as { id?: RowKey }).id;\n\t\treturn id === undefined ? undefined : reader.get(id, ctx);\n\t};\n\n\t// Enforce a table's declarative write rule before the writer runs (so a deny\n\t// rolls the transaction back). For update/delete, evaluate the rule against the\n\t// *existing* row when a reader can load it — so the check reflects committed\n\t// state, not a client-supplied payload.\n\tconst authorizeWrite = async (\n\t\ttable: string,\n\t\top: 'insert' | 'update' | 'delete',\n\t\tvalue: unknown,\n\t\tctx: unknown\n\t) => {\n\t\tconst rule = writeRuleFor(table, op);\n\t\tif (rule === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tlet subject = value;\n\t\tif (op !== 'insert') {\n\t\t\tconst existing = await readExisting(table, value, ctx);\n\t\t\tif (existing !== undefined) {\n\t\t\t\tsubject = existing;\n\t\t\t}\n\t\t}\n\t\tif (!rule(ctx, subject)) {\n\t\t\tthrow new UnauthorizedError(`${op} on table \"${table}\"`);\n\t\t}\n\t};\n\n\t// Merge a write's CRDT fields into the committed row (so concurrent writers\n\t// converge) instead of overwriting them. A no-op for tables without CRDT\n\t// fields. On insert the base is the empty state; on update it's the stored\n\t// field value. Returns the row patch the writer should persist.\n\tconst mergeCrdtFields = async (\n\t\ttable: string,\n\t\top: 'insert' | 'update',\n\t\tdata: unknown,\n\t\tctx: unknown\n\t): Promise<unknown> => {\n\t\tconst fields = crdtFields.get(table);\n\t\tif (fields === undefined || data === null || typeof data !== 'object') {\n\t\t\treturn data;\n\t\t}\n\t\tconst incoming = data as Record<string, unknown>;\n\t\tconst existing =\n\t\t\top === 'update' ? await readExisting(table, data, ctx) : undefined;\n\t\tconst base =\n\t\t\texisting !== null && typeof existing === 'object'\n\t\t\t\t? (existing as Record<string, unknown>)\n\t\t\t\t: undefined;\n\t\tconst merged: Record<string, unknown> = { ...incoming };\n\t\tfor (const [field, adapter] of Object.entries(fields)) {\n\t\t\tif (incoming[field] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmerged[field] = adapter.merge(\n\t\t\t\tbase?.[field] ?? adapter.empty(),\n\t\t\t\tincoming[field]\n\t\t\t);\n\t\t}\n\t\treturn merged;\n\t};\n\n\t/**\n\t * Build the write actions a mutation or schedule handler uses, collecting its\n\t * changes into a fresh buffer (so a transaction that retries/rolls back never\n\t * double-emits). `tx` threads to each writer. `enforce` applies write\n\t * permission rules (mutations); schedules run trusted, so they pass `false`.\n\t */\n\tconst makeActions = (tx: unknown, ctx: unknown, enforce: boolean) => {\n\t\tconst buffered: { table: string; change: RowChange<unknown> }[] = [];\n\t\tconst actions: MutationActions = {\n\t\t\tchange: (collection, change) => {\n\t\t\t\tbuffered.push({\n\t\t\t\t\ttable: collection,\n\t\t\t\t\tchange: change as RowChange<unknown>\n\t\t\t\t});\n\t\t\t\treturn Promise.resolve();\n\t\t\t},\n\t\t\tinsert: async (table, data) => {\n\t\t\t\t// Schema is data integrity — validated for trusted schedules too.\n\t\t\t\tvalidateWrite(table, 'insert', data);\n\t\t\t\tif (enforce) {\n\t\t\t\t\tawait authorizeWrite(table, 'insert', data, ctx);\n\t\t\t\t}\n\t\t\t\tconst merged = await mergeCrdtFields(\n\t\t\t\t\ttable,\n\t\t\t\t\t'insert',\n\t\t\t\t\tdata,\n\t\t\t\t\tctx\n\t\t\t\t);\n\t\t\t\tconst row = await writerFor(table).insert(merged, ctx, tx);\n\t\t\t\tbuffered.push({ table, change: { op: 'insert', row } });\n\t\t\t\treturn row;\n\t\t\t},\n\t\t\tupdate: async (table, data) => {\n\t\t\t\tvalidateWrite(table, 'update', data);\n\t\t\t\tif (enforce) {\n\t\t\t\t\tawait authorizeWrite(table, 'update', data, ctx);\n\t\t\t\t}\n\t\t\t\tconst merged = await mergeCrdtFields(\n\t\t\t\t\ttable,\n\t\t\t\t\t'update',\n\t\t\t\t\tdata,\n\t\t\t\t\tctx\n\t\t\t\t);\n\t\t\t\tconst row = await writerFor(table).update(merged, ctx, tx);\n\t\t\t\tbuffered.push({ table, change: { op: 'update', row } });\n\t\t\t\treturn row;\n\t\t\t},\n\t\t\tdelete: async (table, row) => {\n\t\t\t\tif (enforce) {\n\t\t\t\t\tawait authorizeWrite(table, 'delete', row, ctx);\n\t\t\t\t}\n\t\t\t\tawait writerFor(table).delete(row, ctx, tx);\n\t\t\t\tbuffered.push({ table, change: { op: 'delete', row } });\n\t\t\t},\n\t\t\t// Default wall clock. Replay / rebase paths can wrap and pin\n\t\t\t// this; today it's just Date.now().\n\t\t\tnow: () => Date.now()\n\t\t};\n\t\treturn { actions, buffered };\n\t};\n\n\t/** Diff a re-run against a sub's current set; updates `current`. Shared by the\n\t * reactive and search kinds (both re-run wholesale and diff). `equals` decides\n\t * whether a still-present row counts as changed. */\n\tconst diffRerun = (\n\t\tsub: {\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tcurrent: Map<RowKey, unknown>;\n\t\t},\n\t\trows: unknown[],\n\t\tequals: (a: unknown, b: unknown) => boolean = shallowEqual\n\t): ViewDiff<unknown> => {\n\t\tconst next = new Map<RowKey, unknown>();\n\t\tfor (const row of rows) {\n\t\t\tnext.set(sub.key(row), row);\n\t\t}\n\t\tconst added: unknown[] = [];\n\t\tconst removed: unknown[] = [];\n\t\tconst changed: unknown[] = [];\n\t\tfor (const [rowKey, row] of next) {\n\t\t\tconst previous = sub.current.get(rowKey);\n\t\t\tif (previous === undefined) {\n\t\t\t\tadded.push(row);\n\t\t\t} else if (!equals(previous, row)) {\n\t\t\t\tchanged.push(row);\n\t\t\t}\n\t\t}\n\t\tfor (const [rowKey, row] of sub.current) {\n\t\t\tif (!next.has(rowKey)) {\n\t\t\t\tremoved.push(row);\n\t\t\t}\n\t\t}\n\t\tsub.current = next;\n\t\treturn { added, removed, changed };\n\t};\n\n\t/** Re-run every reactive query whose read set intersects the changed tables. */\n\ttype ReactiveChange = {\n\t\ttable: string;\n\t\tkey: RowKey | undefined;\n\t\trow: unknown;\n\t};\n\n\t/** Does a change fall in a range dep — matched now, or a member at last read? */\n\tconst inRange = (dep: RangeDep, change: ReactiveChange): boolean =>\n\t\tdep.table === change.table &&\n\t\t((change.key !== undefined && dep.keys.has(change.key)) ||\n\t\t\tdep.predicate(change.row));\n\n\t/** Does any change in the batch overlap this read set? Used for both live\n\t * sub invalidation and cross-client cache invalidation. */\n\tconst readSetOverlaps = (\n\t\treadTables: Set<string>,\n\t\treadKeys: Set<string>,\n\t\trangeDeps: RangeDep[],\n\t\tchanges: ReactiveChange[]\n\t): boolean =>\n\t\tchanges.some(\n\t\t\t(change) =>\n\t\t\t\treadTables.has(change.table) ||\n\t\t\t\t(change.key !== undefined &&\n\t\t\t\t\treadKeys.has(depKey(change.table, change.key))) ||\n\t\t\t\trangeDeps.some((dep) => inRange(dep, change))\n\t\t);\n\n\t/** Did this batch touch a table, row key, or range the sub read? */\n\tconst isReactiveAffected = (\n\t\tsub: ReactiveSub,\n\t\tchanges: ReactiveChange[]\n\t): boolean =>\n\t\treadSetOverlaps(sub.readTables, sub.readKeys, sub.rangeDeps, changes);\n\n\t/** Drop cached reruns whose read set overlaps this write batch. Cheap walk —\n\t * the cache is bounded by `reactiveCache.max` (default 256). */\n\tconst invalidateCacheForChanges = (changes: ReactiveChange[]) => {\n\t\tif (cachedReruns.size === 0) return;\n\t\tfor (const [key, entry] of cachedReruns) {\n\t\t\tif (\n\t\t\t\treadSetOverlaps(\n\t\t\t\t\tentry.readTables,\n\t\t\t\t\tentry.readKeys,\n\t\t\t\t\tentry.rangeDeps,\n\t\t\t\t\tchanges\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcachedReruns.delete(key);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst reactivePairs = async (\n\t\tchanges: ReactiveChange[]\n\t): Promise<[ActiveSubscription, ViewDiff<unknown>][]> => {\n\t\t// Drop now-stale cache entries before reruns — otherwise a fresh\n\t\t// subscriber landing during the batch could read the OLD value.\n\t\tinvalidateCacheForChanges(changes);\n\n\t\tconst pairs: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\t// Dedupe: subscriptions sharing the same `(collection, params, ctx)`\n\t\t// only need ONE rerun per change batch. With 1000 subs on the same\n\t\t// query, this drops per-change CPU from O(N) reruns to O(1) — every\n\t\t// sub then diffs the shared result against its own `current` and\n\t\t// receives its own per-sub frame (which the transport still writes\n\t\t// per-WS, see #22 batch-frame fan-out for the next step).\n\t\tconst sharedRuns = new Map<\n\t\t\tstring,\n\t\t\tPromise<Awaited<ReturnType<ReactiveSub['rerun']>>>\n\t\t>();\n\t\tfor (const sub of reactiveSubs) {\n\t\t\tif (!isReactiveAffected(sub, changes)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet runPromise = sharedRuns.get(sub.rerunKey);\n\t\t\tif (runPromise === undefined) {\n\t\t\t\trunPromise = sub.rerun();\n\t\t\t\tsharedRuns.set(sub.rerunKey, runPromise);\n\t\t\t}\n\t\t\tconst { rows, readTables, readKeys, rangeDeps } = await runPromise;\n\t\t\tsub.readTables = readTables;\n\t\t\tsub.readKeys = readKeys;\n\t\t\tsub.rangeDeps = rangeDeps;\n\t\t\tconst diff = diffRerun(sub, rows);\n\t\t\tif (!isEmptyViewDiff(diff)) {\n\t\t\t\tpairs.push([sub, diff]);\n\t\t\t}\n\t\t}\n\t\t// Refresh cache entries with the freshly-computed rows so subsequent\n\t\t// subscribers reuse them without hitting the DB.\n\t\tfor (const [key, runPromise] of sharedRuns) {\n\t\t\trunPromise\n\t\t\t\t.then(({ rows, readTables, readKeys, rangeDeps }) => {\n\t\t\t\t\twriteCacheEntry({\n\t\t\t\t\t\texpiresAt: Date.now() + reactiveCacheTtlMs,\n\t\t\t\t\t\trangeDeps,\n\t\t\t\t\t\treadKeys,\n\t\t\t\t\t\treadTables,\n\t\t\t\t\t\trerunKey: key,\n\t\t\t\t\t\trows,\n\t\t\t\t\t\tversion\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// rerun threw — leave cache as-is (already invalidated above)\n\t\t\t\t});\n\t\t}\n\n\t\treturn pairs;\n\t};\n\n\t/** Lazily build + hydrate a search collection's shared index (once). */\n\tconst ensureSearchIndex = async (\n\t\tdefinition: SearchCollectionDefinition<unknown, unknown, unknown>\n\t) => {\n\t\tlet entry = searchIndexes.get(definition.name);\n\t\tif (entry === undefined) {\n\t\t\tentry = { index: definition.index(), definition, hydrated: false };\n\t\t\tsearchIndexes.set(definition.name, entry);\n\t\t}\n\t\tif (!entry.hydrated) {\n\t\t\tfor (const row of await definition.source()) {\n\t\t\t\tentry.index.add(row);\n\t\t\t}\n\t\t\tentry.hydrated = true;\n\t\t}\n\t\treturn entry;\n\t};\n\n\t/**\n\t * Keep search indexes live and re-rank affected search subs: apply each change\n\t * to its collection's index, then re-run every sub whose collection changed.\n\t * Synchronous — the index ops and re-ranks don't touch the DB.\n\t */\n\tconst searchPairs = (\n\t\tchanges: { table: string; change: RowChange<unknown> }[]\n\t): [ActiveSubscription, ViewDiff<unknown>][] => {\n\t\tconst touched = new Set<string>();\n\t\tfor (const { table, change } of changes) {\n\t\t\tfor (const entry of searchIndexes.values()) {\n\t\t\t\tif (!entry.hydrated || entry.definition.table !== table) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (change.op === 'delete') {\n\t\t\t\t\tentry.index.remove(entry.definition.key(change.row));\n\t\t\t\t} else {\n\t\t\t\t\tentry.index.add(change.row);\n\t\t\t\t}\n\t\t\t\ttouched.add(entry.definition.name);\n\t\t\t}\n\t\t}\n\t\tconst pairs: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\tfor (const sub of searchSubs) {\n\t\t\tif (!touched.has(sub.collection)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Ignore pure score drift (BM25 idf shifts as the corpus grows), so a\n\t\t\t// result only re-emits when it enters/leaves or its content changes —\n\t\t\t// not on every unrelated insert.\n\t\t\tconst diff = diffRerun(sub, sub.rerun(), equalsIgnoringScore);\n\t\t\tif (!isEmptyViewDiff(diff)) {\n\t\t\t\tpairs.push([sub, diff]);\n\t\t\t}\n\t\t}\n\t\treturn pairs;\n\t};\n\n\tconst logChange = (changeVersion: number, entry: LoggedChange) => {\n\t\tchangeLog.push(entry);\n\t\t// Count-based cap.\n\t\tif (changeLog.length > changeLogSize) {\n\t\t\tchangeLog.shift();\n\t\t}\n\t\t// Time-based retention (1.13.0): drop entries older than the\n\t\t// configured window. Cheap when the log is small or the head is\n\t\t// fresh — we stop the moment we find a young-enough entry.\n\t\tif (changeLogRetainMs !== null && changeLogRetainMs > 0) {\n\t\t\tconst cutoff = entry.at - changeLogRetainMs;\n\t\t\twhile (changeLog.length > 0 && changeLog[0]!.at < cutoff) {\n\t\t\t\tchangeLog.shift();\n\t\t\t}\n\t\t}\n\t\t// Atomic with the log push — every active CDC streamer sees every\n\t\t// entry exactly once, in version order, with no chance of a missed\n\t\t// commit between phase-1 catch-up and phase-2 tail.\n\t\tfor (const subscriber of streamSubscribers) {\n\t\t\tsubscriber(entry);\n\t\t}\n\t};\n\n\t// 1.17.0 cross-instance cursor encode/decode. Opaque to clients —\n\t// shaped as base64-ish JSON internally. The client must round-trip\n\t// what the server returned, unmodified.\n\tconst encodeCursor = (versions: Record<string, number>): string =>\n\t\t// Plain JSON is fine; clients treat it as opaque. We don't base64\n\t\t// because the cursor lives in a JSON payload anyway (snapshot frame).\n\t\tJSON.stringify(versions);\n\tconst decodeCursor = (cursor: string): Record<string, number> | null => {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(cursor);\n\t\t\tif (typeof parsed !== 'object' || parsed === null) return null;\n\t\t\tconst out: Record<string, number> = {};\n\t\t\tfor (const [k, v] of Object.entries(parsed)) {\n\t\t\t\tif (typeof v === 'number') out[k] = v;\n\t\t\t}\n\t\t\treturn out;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t};\n\tconst currentCursor = (): string => {\n\t\t// Snapshot the highest local version + each peer's highest origin\n\t\t// version seen so far. Cheap O(log) — single backwards walk grabs\n\t\t// the most-recent originVersion per peer.\n\t\tconst versions: Record<string, number> = { [instanceId]: version };\n\t\tfor (let i = changeLog.length - 1; i >= 0; i--) {\n\t\t\tconst entry = changeLog[i]!;\n\t\t\tif (versions[entry.origin] === undefined) {\n\t\t\t\tversions[entry.origin] = entry.originVersion;\n\t\t\t}\n\t\t}\n\t\treturn encodeCursor(versions);\n\t};\n\n\t/** Apply a single committed change at its own version (CDC / direct writes). */\n\tconst applyChange = async (\n\t\ttable: string,\n\t\tchange: RowChange<unknown>,\n\t\tshouldBroadcast = true\n\t) => {\n\t\tversion += 1;\n\t\tconst changeVersion = version;\n\t\tconst at = Date.now();\n\t\tlogChange(changeVersion, {\n\t\t\tversion: changeVersion,\n\t\t\ttable,\n\t\t\tchange,\n\t\t\tat,\n\t\t\torigin: instanceId,\n\t\t\toriginVersion: changeVersion\n\t\t});\n\t\temitActivity({\n\t\t\ttype: 'change',\n\t\t\tat,\n\t\t\ttable,\n\t\t\top: change.op,\n\t\t\tversion: changeVersion\n\t\t});\n\t\t// Collect, then emit once at the end: reactive re-runs are async, and\n\t\t// emitting before they finish would let the transport flush a partial frame.\n\t\tconst emissions: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\tfor (const subscription of subscriptionsForTable(table)) {\n\t\t\tconst diff = await subscriptionDiff(subscription, table, change);\n\t\t\tif (!isEmptyViewDiff(diff)) {\n\t\t\t\temissions.push([subscription, diff]);\n\t\t\t}\n\t\t}\n\t\temissions.push(\n\t\t\t...(await reactivePairs([\n\t\t\t\t{ table, key: changedKeyFor(table, change), row: change.row }\n\t\t\t]))\n\t\t);\n\t\temissions.push(...searchPairs([{ table, change }]));\n\t\tconst cursorForBatch = currentCursor();\n\t\tfor (const [subscription, diff] of emissions) {\n\t\t\tsubscription.onDiff(diff, changeVersion, cursorForBatch);\n\t\t}\n\t\tif (shouldBroadcast) {\n\t\t\tbroadcast([{ table, change }], changeVersion);\n\t\t}\n\t};\n\n\t/**\n\t * Apply a set of changes atomically: one version bump for the whole batch and\n\t * a single net-merged diff per affected subscription. Used by mutations so a\n\t * client never renders a torn intermediate state mid-mutation.\n\t */\n\tconst applyChangeBatch = async (\n\t\tchanges: { table: string; change: RowChange<unknown> }[],\n\t\tshouldBroadcast = true,\n\t\t/**\n\t\t * 1.17.0 — peer-relayed batches override the change-log entry's\n\t\t * `origin` + `originVersion` so a cross-instance client cursor can\n\t\t * later match the entry. Local batches leave this `undefined` and\n\t\t * the entry inherits the engine's own identity.\n\t\t */\n\t\tpeerOrigin?: { origin: string; originVersion: number }\n\t) => {\n\t\tif (changes.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tversion += 1;\n\t\tconst batchVersion = version;\n\t\tconst perSubscription = new Map<\n\t\t\tActiveSubscription,\n\t\t\tViewDiff<unknown>[]\n\t\t>();\n\t\tconst reactiveChanges: ReactiveChange[] = [];\n\t\tconst batchAt = Date.now();\n\t\t// 1.17.0: peer-relayed batches override origin/originVersion via\n\t\t// `peerOrigin` (set when applyChangeBatch is called from the cluster\n\t\t// subscribe path). Defaults to this engine's identity.\n\t\tconst batchOrigin = peerOrigin?.origin ?? instanceId;\n\t\tconst batchOriginVersion = peerOrigin?.originVersion ?? batchVersion;\n\t\tfor (const { table, change } of changes) {\n\t\t\tlogChange(batchVersion, {\n\t\t\t\tversion: batchVersion,\n\t\t\t\ttable,\n\t\t\t\tchange,\n\t\t\t\tat: batchAt,\n\t\t\t\torigin: batchOrigin,\n\t\t\t\toriginVersion: batchOriginVersion\n\t\t\t});\n\t\t\temitActivity({\n\t\t\t\ttype: 'change',\n\t\t\t\tat: batchAt,\n\t\t\t\ttable,\n\t\t\t\top: change.op,\n\t\t\t\tversion: batchVersion\n\t\t\t});\n\t\t\treactiveChanges.push({\n\t\t\t\ttable,\n\t\t\t\tkey: changedKeyFor(table, change),\n\t\t\t\trow: change.row\n\t\t\t});\n\t\t\tfor (const subscription of subscriptionsForTable(table)) {\n\t\t\t\t// Apply in order to keep operator state correct; collect to merge.\n\t\t\t\tconst diff = await subscriptionDiff(\n\t\t\t\t\tsubscription,\n\t\t\t\t\ttable,\n\t\t\t\t\tchange\n\t\t\t\t);\n\t\t\t\tconst list = perSubscription.get(subscription);\n\t\t\t\tif (list === undefined) {\n\t\t\t\t\tperSubscription.set(subscription, [diff]);\n\t\t\t\t} else {\n\t\t\t\t\tlist.push(diff);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Gather all emissions before sending any, so the whole batch — view diffs\n\t\t// and reactive re-runs (async) — leaves as one coalesced frame.\n\t\tconst emissions: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\tfor (const [subscription, diffs] of perSubscription) {\n\t\t\tconst merged =\n\t\t\t\tdiffs.length === 1\n\t\t\t\t\t? diffs[0]!\n\t\t\t\t\t: mergeViewDiffs(diffs, subscription.key);\n\t\t\tif (!isEmptyViewDiff(merged)) {\n\t\t\t\temissions.push([subscription, merged]);\n\t\t\t}\n\t\t}\n\t\temissions.push(...(await reactivePairs(reactiveChanges)));\n\t\temissions.push(...searchPairs(changes));\n\t\tconst cursorForBatch = currentCursor();\n\t\tfor (const [subscription, diff] of emissions) {\n\t\t\tsubscription.onDiff(diff, batchVersion, cursorForBatch);\n\t\t}\n\t\tif (shouldBroadcast) {\n\t\t\tbroadcast(changes, batchVersion);\n\t\t}\n\t};\n\n\t/**\n\t * Normalize a `since` value (number or cursor string) into a per-origin\n\t * version vector. A bare `number` is treated as legacy 1.16- form — the\n\t * version of THIS instance. A cursor string is the 1.17.0+ multi-origin\n\t * shape encoded by `currentCursor()`.\n\t */\n\tconst normalizeSince = (since: number | string): Record<string, number> | null => {\n\t\tif (typeof since === 'number') {\n\t\t\treturn { [instanceId]: since };\n\t\t}\n\t\treturn decodeCursor(since);\n\t};\n\n\t/**\n\t * Can we replay `(since, now]` from the log for `tables`? With a cursor,\n\t * this is a per-origin coverage check — every entry the client hasn't\n\t * seen MUST be present in our log. Pre-1.16 `number` form matches when\n\t * the local log covers `(since.version, now]`. Returns `false` for\n\t * non-incremental subs (refetch/join/graph/search), since those can't be\n\t * replayed precisely from a row-change log.\n\t */\n\tconst canResume = (since: number | string, incremental: boolean): boolean => {\n\t\tif (!incremental) {\n\t\t\treturn false;\n\t\t}\n\t\tconst sinceVec = normalizeSince(since);\n\t\tif (sinceVec === null) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Walk the log backwards: every entry with `origin === O` and\n\t\t// `originVersion > sinceVec[O]` MUST appear in the log. If the log\n\t\t// has been trimmed past any such entry, we can't catch up.\n\t\t// Per-origin: for each origin O we've seen, check that the oldest\n\t\t// entry with that origin is no newer than `sinceVec[O] + 1`. For\n\t\t// an unknown origin, we fall back to \"no coverage\" (caller gets a\n\t\t// snapshot, just like pre-1.17 behavior).\n\t\tconst oldestPerOrigin = new Map<string, number>();\n\t\tfor (const entry of changeLog) {\n\t\t\tconst current = oldestPerOrigin.get(entry.origin);\n\t\t\tif (current === undefined || entry.originVersion < current) {\n\t\t\t\toldestPerOrigin.set(entry.origin, entry.originVersion);\n\t\t\t}\n\t\t}\n\n\t\t// Log-wide watermark: the smallest version still in the log. If this\n\t\t// is past `lastSeen + 1`, ANY entries between the cursor and oldestLogVersion\n\t\t// were trimmed (regardless of origin).\n\t\tconst oldestLogVersion = changeLog[0]?.version;\n\t\tfor (const [origin, lastSeen] of Object.entries(sinceVec)) {\n\t\t\t// Special case: if we've never seen any entry from this origin,\n\t\t\t// but the client claims to have seen up to `lastSeen` from it,\n\t\t\t// we DEFINITELY can't reconstruct — snapshot it.\n\t\t\tif (origin === instanceId) {\n\t\t\t\t// Local origin: standard check.\n\t\t\t\tif (lastSeen >= version) continue; // nothing newer\n\t\t\t\tconst oldestLocal = oldestPerOrigin.get(instanceId);\n\t\t\t\t// If we have local entries, walk them: they must reach back\n\t\t\t\t// to lastSeen + 1.\n\t\t\t\tif (oldestLocal !== undefined) {\n\t\t\t\t\tif (oldestLocal > lastSeen + 1) return false;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// No local entries — the version bumps since mint were all\n\t\t\t\t// from peer broadcasts. Resume is safe ONLY if the log itself\n\t\t\t\t// hasn't been trimmed past the mint point (otherwise some\n\t\t\t\t// local entries existed but were retired).\n\t\t\t\tif (\n\t\t\t\t\toldestLogVersion !== undefined &&\n\t\t\t\t\toldestLogVersion > lastSeen + 1\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Peer origin: same check against the peer's entries.\n\t\t\t\tconst oldestPeer = oldestPerOrigin.get(origin);\n\t\t\t\tif (oldestPeer === undefined) {\n\t\t\t\t\t// We've never logged any change from this peer. If the client\n\t\t\t\t\t// has seen entries from this peer, we can't help.\n\t\t\t\t\tif (lastSeen > 0) return false;\n\t\t\t\t} else if (oldestPeer > lastSeen + 1) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t};\n\n\t/**\n\t * Build a catch-up diff from the log for one subscription (last op per\n\t * key wins). Multi-origin aware (1.17.0+): walks every entry whose\n\t * `(origin, originVersion)` is newer than the client's last-seen for\n\t * that origin.\n\t */\n\tconst buildCatchup = (\n\t\tsince: number | string,\n\t\ttables: string[],\n\t\tkey: (row: unknown) => RowKey,\n\t\tmatch: (row: unknown) => boolean\n\t): ViewDiff<unknown> => {\n\t\tconst sinceVec = normalizeSince(since) ?? {};\n\t\tconst latest = new Map<\n\t\t\tRowKey,\n\t\t\t{ op: 'upsert' | 'remove'; row: unknown }\n\t\t>();\n\t\tfor (const entry of changeLog) {\n\t\t\tif (!tables.includes(entry.table)) continue;\n\t\t\t// Skip entries the client has already seen for this origin.\n\t\t\tconst lastSeen = sinceVec[entry.origin];\n\t\t\tif (lastSeen !== undefined && entry.originVersion <= lastSeen) continue;\n\t\t\tconst row = entry.change.row;\n\t\t\tconst present =\n\t\t\t\tentry.change.op !== 'delete' && match(row)\n\t\t\t\t\t? 'upsert'\n\t\t\t\t\t: 'remove';\n\t\t\tlatest.set(key(row), { op: present, row });\n\t\t}\n\t\tconst changed: unknown[] = [];\n\t\tconst removed: unknown[] = [];\n\t\tfor (const { op, row } of latest.values()) {\n\t\t\t(op === 'upsert' ? changed : removed).push(row);\n\t\t}\n\t\treturn { added: [], removed, changed };\n\t};\n\n\tconst subscribeJoin = async (\n\t\tcollection: string,\n\t\tdefinition: JoinCollectionDefinition<\n\t\t\tunknown,\n\t\t\tunknown,\n\t\t\tunknown,\n\t\t\tunknown,\n\t\t\tunknown\n\t\t>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst { left, right } = definition;\n\t\tconst op = createEquiJoin<unknown, unknown, unknown>({\n\t\t\tleftKey: left.key,\n\t\t\trightKey: right.key,\n\t\t\tleftOn: left.on,\n\t\t\trightOn: right.on,\n\t\t\tselect: definition.select\n\t\t});\n\t\top.hydrate(\n\t\t\t[...(await left.hydrate(params, ctx))],\n\t\t\t[...(await right.hydrate(params, ctx))]\n\t\t);\n\t\tconst atVersion = version;\n\n\t\tconst subscription: ActiveSubscription = {\n\t\t\tkind: 'join',\n\t\t\tcollection,\n\t\t\tjoin: {\n\t\t\t\top,\n\t\t\t\tleftTable: left.table,\n\t\t\t\trightTable: right.table,\n\t\t\t\tleftMatch: left.match\n\t\t\t\t\t? (row) => left.match!(row, params, ctx)\n\t\t\t\t\t: undefined,\n\t\t\t\trightMatch: right.match\n\t\t\t\t\t? (row) => right.match!(row, params, ctx)\n\t\t\t\t\t: undefined\n\t\t\t},\n\t\t\tkey: definition.key as (row: unknown) => RowKey,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\n\t\treturn {\n\t\t\tinitial: op.rows(),\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst subscribeGraph = async (\n\t\tcollection: string,\n\t\tdefinition: GraphCollectionDefinition<unknown, unknown, unknown>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst instance = definition.query.instantiate(params, ctx);\n\t\tconst initial = await instance.hydrate();\n\t\tconst atVersion = version;\n\t\tconst subscription: ActiveSubscription = {\n\t\t\tkind: 'graph',\n\t\t\tcollection,\n\t\t\tinstance,\n\t\t\tkey: definition.key as (row: unknown) => RowKey,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\t\treturn {\n\t\t\tinitial,\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst subscribeReactive = async (\n\t\tcollection: string,\n\t\tdefinition: ReactiveQueryDefinition<unknown, unknown, unknown>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Each run gets a fresh read set; the handle records tables + row keys read.\n\t\tconst rerun = async () => {\n\t\t\tconst readTables = new Set<string>();\n\t\t\tconst readKeys = new Set<string>();\n\t\t\tconst rangeDeps: RangeDep[] = [];\n\t\t\tconst db = makeReadHandle(ctx, readTables, readKeys, rangeDeps);\n\t\t\tconst rows = [...(await definition.run({ ctx, db, params }))];\n\t\t\treturn { rangeDeps, readKeys, readTables, rows };\n\t\t};\n\t\tconst rerunKey = stableSubKey(collection, params, ctx);\n\t\t// Cross-client cache hit (1.3+): a previous subscriber with the same\n\t\t// (collection, params, ctx) ran the query body recently and its\n\t\t// result is still valid (no overlapping write since). Reuse it\n\t\t// instead of hitting the DB again. Cache misses fall through to\n\t\t// `rerun()` and populate the cache for the next subscriber.\n\t\tconst cached = readCacheEntry(rerunKey);\n\t\tconst first =\n\t\t\tcached !== undefined\n\t\t\t\t? {\n\t\t\t\t\t\trangeDeps: cached.rangeDeps,\n\t\t\t\t\t\treadKeys: cached.readKeys,\n\t\t\t\t\t\treadTables: cached.readTables,\n\t\t\t\t\t\trows: cached.rows\n\t\t\t\t\t}\n\t\t\t\t: await rerun();\n\t\tif (cached === undefined) {\n\t\t\twriteCacheEntry({\n\t\t\t\texpiresAt: Date.now() + reactiveCacheTtlMs,\n\t\t\t\trangeDeps: first.rangeDeps,\n\t\t\t\treadKeys: first.readKeys,\n\t\t\t\treadTables: first.readTables,\n\t\t\t\trerunKey,\n\t\t\t\trows: first.rows,\n\t\t\t\tversion\n\t\t\t});\n\t\t}\n\t\tconst current = new Map<RowKey, unknown>();\n\t\tfor (const row of first.rows) {\n\t\t\tcurrent.set(definition.key(row), row);\n\t\t}\n\t\tconst atVersion = version;\n\t\tconst subscription: ReactiveSub = {\n\t\t\tkind: 'reactive',\n\t\t\tcollection,\n\t\t\tkey: definition.key,\n\t\t\trerun,\n\t\t\trerunKey,\n\t\t\tcurrent,\n\t\t\treadTables: first.readTables,\n\t\t\treadKeys: first.readKeys,\n\t\t\trangeDeps: first.rangeDeps,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\t\treactiveSubs.add(subscription);\n\t\treturn {\n\t\t\tinitial: first.rows,\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t\treactiveSubs.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst subscribeSearch = async (\n\t\tcollection: string,\n\t\tdefinition: SearchCollectionDefinition<unknown, unknown, unknown>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\t// The subscription params are the query (a string for text, a vector for\n\t\t// similarity).\n\t\tconst query = params;\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(query, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst entry = await ensureSearchIndex(definition);\n\t\tconst limit = definition.limit ?? 20;\n\t\tconst readRule = readRuleFor(definition.table);\n\t\t// Re-rank: top-K from the (shared, live) index, scoped by the read rule,\n\t\t// each row tagged with its score so the client can sort by relevance.\n\t\tconst rerun = (): unknown[] => {\n\t\t\tconst candidates = entry.index.search(\n\t\t\t\tquery,\n\t\t\t\treadRule ? limit * 5 : limit\n\t\t\t);\n\t\t\tconst visible = readRule\n\t\t\t\t? candidates.filter((hit) => readRule(ctx, hit.row))\n\t\t\t\t: candidates;\n\t\t\treturn visible.slice(0, limit).map((hit) => ({\n\t\t\t\t...(hit.row as Record<string, unknown>),\n\t\t\t\t[SEARCH_SCORE_FIELD]: hit.score\n\t\t\t}));\n\t\t};\n\t\tconst initial = rerun();\n\t\tconst current = new Map<RowKey, unknown>();\n\t\tfor (const row of initial) {\n\t\t\tcurrent.set(definition.key(row), row);\n\t\t}\n\t\tconst atVersion = version;\n\t\tconst subscription: Extract<ActiveSubscription, { kind: 'search' }> = {\n\t\t\tkind: 'search',\n\t\t\tcollection,\n\t\t\tkey: definition.key,\n\t\t\trerun,\n\t\t\tcurrent,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\t\tsearchSubs.add(subscription);\n\t\treturn {\n\t\t\tinitial,\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t\tsearchSubs.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst engine: SyncEngine = {\n\t\tregister: (collection) => {\n\t\t\tregistry.set(collection.name, collection);\n\t\t\tfor (const table of collection.tables ?? [collection.name]) {\n\t\t\t\taddTableIndex(table, collection.name);\n\t\t\t}\n\t\t},\n\n\t\tregisterJoin: (collection) => {\n\t\t\tregistry.set(collection.name, collection);\n\t\t\taddTableIndex(collection.left.table, collection.name);\n\t\t\taddTableIndex(collection.right.table, collection.name);\n\t\t},\n\n\t\tregisterGraph: (collection) => {\n\t\t\tregistry.set(collection.name, collection);\n\t\t\tfor (const table of collection.query.tables()) {\n\t\t\t\taddTableIndex(table, collection.name);\n\t\t\t}\n\t\t},\n\n\t\tregisterSearch: (collection) => {\n\t\t\t// Like reactive: not in tableIndex — its index is driven directly by\n\t\t\t// searchPairs off the change feed.\n\t\t\tregistry.set(collection.name, collection);\n\t\t},\n\n\t\tsubscribe: async ({ collection, params, ctx, onDiff, since, signal }) => {\n\t\t\t// 1.21.0: wrap subscribe setup in a span. The Subscription\n\t\t\t// lives past `subscribe()` returning — the span only covers\n\t\t\t// the setup cost (authorize / hydrate / view materialization),\n\t\t\t// not the ongoing reactive lifetime.\n\t\t\tconst subscribeSpan = tracer.startSpan('sync.subscribe', {\n\t\t\t\tattributes: {\n\t\t\t\t\t[ABS_ATTRS.engineId]: instanceId,\n\t\t\t\t\t[ABS_ATTRS.collection]: collection\n\t\t\t\t}\n\t\t\t});\n\t\t\ttry {\n\t\t\t// (1.15.0) Cheap up-front check — if the consumer already aborted\n\t\t\t// before we got here, throw before any side effect (no authorize,\n\t\t\t// no hydrate, no view materialization).\n\t\t\tcheckAborted(signal);\n\n\t\t\tconst registered = registry.get(collection);\n\t\t\tif (registered === undefined) {\n\t\t\t\tthrow new Error(`Unknown collection \"${collection}\"`);\n\t\t\t}\n\n\t\t\t// (1.20.1) Per-tenant cap. Acquired BEFORE authorize/hydrate/any\n\t\t\t// state allocation. If subscribe throws between here and the\n\t\t\t// successful return (auth rejection, abort, schema error, etc.)\n\t\t\t// we release in the `catch` below — otherwise the wrapped\n\t\t\t// `unsubscribe` is the release path.\n\t\t\tconst tenantSlot = acquireSubscriptionSlot(ctx, { collection });\n\t\t\tlet slotHandedOff = false;\n\t\t\ttry {\n\n\t\t\tconst typedOnDiff = onDiff as OnDiff;\n\t\t\tconst subscribeSet = subsFor(collection);\n\n\t\t\t// Wrap the eventual return so we (a) re-check signal after the\n\t\t\t// async setup (catches mid-flight aborts), (b) auto-call\n\t\t\t// unsubscribe when signal fires after the subscription is live,\n\t\t\t// and (c) decrement the tenant's active-sub count idempotently\n\t\t\t// when unsubscribe runs.\n\t\t\tconst wrapReturn = <T>(sub: Subscription<T>): Subscription<T> => {\n\t\t\t\tcheckAborted(signal);\n\t\t\t\tconst innerUnsubscribe = sub.unsubscribe;\n\t\t\t\tlet released = false;\n\t\t\t\tconst wrappedUnsubscribe = (): void => {\n\t\t\t\t\tif (released) return;\n\t\t\t\t\treleased = true;\n\t\t\t\t\treleaseSubscriptionSlot(tenantSlot);\n\t\t\t\t\tinnerUnsubscribe();\n\t\t\t\t};\n\t\t\t\tconst wrapped = { ...sub, unsubscribe: wrappedUnsubscribe };\n\t\t\t\tlinkAbortToUnsubscribe(signal, wrappedUnsubscribe);\n\t\t\t\tslotHandedOff = true;\n\t\t\t\treturn wrapped;\n\t\t\t};\n\n\t\t\tconst registeredKind = (registered as { kind?: string }).kind;\n\t\t\tif (registeredKind === 'join') {\n\t\t\t\tconst joined = await subscribeJoin(\n\t\t\t\t\tcollection,\n\t\t\t\t\tregistered as JoinCollectionDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>,\n\t\t\t\t\tparams,\n\t\t\t\t\tctx,\n\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\tsubscribeSet\n\t\t\t\t);\n\t\t\t\treturn wrapReturn(joined) as Subscription<never>;\n\t\t\t}\n\t\t\tif (registeredKind === 'graph') {\n\t\t\t\tconst graphed = await subscribeGraph(\n\t\t\t\t\tcollection,\n\t\t\t\t\tregistered as GraphCollectionDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>,\n\t\t\t\t\tparams,\n\t\t\t\t\tctx,\n\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\tsubscribeSet\n\t\t\t\t);\n\t\t\t\treturn wrapReturn(graphed) as Subscription<never>;\n\t\t\t}\n\t\t\tif (registeredKind === 'reactive') {\n\t\t\t\tconst reactived = await subscribeReactive(\n\t\t\t\t\tcollection,\n\t\t\t\t\tregistered as ReactiveQueryDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>,\n\t\t\t\t\tparams,\n\t\t\t\t\tctx,\n\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\tsubscribeSet\n\t\t\t\t);\n\t\t\t\treturn wrapReturn(reactived) as Subscription<never>;\n\t\t\t}\n\t\t\tif (registeredKind === 'search') {\n\t\t\t\tconst searched = await subscribeSearch(\n\t\t\t\t\tcollection,\n\t\t\t\t\tregistered as SearchCollectionDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>,\n\t\t\t\t\tparams,\n\t\t\t\t\tctx,\n\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\tsubscribeSet\n\t\t\t\t);\n\t\t\t\treturn wrapReturn(searched) as Subscription<never>;\n\t\t\t}\n\t\t\tconst definition = registered as CollectionDefinition<\n\t\t\t\tunknown,\n\t\t\t\tunknown,\n\t\t\t\tunknown\n\t\t\t>;\n\n\t\t\tif (definition.authorize !== undefined) {\n\t\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\t\tif (!allowed) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tconst key = definition.key ?? defaultKey;\n\t\t\tconst match = definition.match;\n\t\t\tconst tables = definition.tables ?? [collection];\n\t\t\t// Declarative read rule + schema migration apply to single-table\n\t\t\t// collections (their rows are that table's rows); join/aggregate\n\t\t\t// collections scope via match.\n\t\t\tconst scopedTable = tables.length === 1 ? tables[0]! : undefined;\n\t\t\tconst readRule =\n\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t? readRuleFor(scopedTable)\n\t\t\t\t\t: undefined;\n\t\t\t// Migrate the DB result to the current shape, then filter it through the\n\t\t\t// read rule — so the initial snapshot and the refetch fallback are\n\t\t\t// always current-shape and never include a row the caller can't see.\n\t\t\tconst rehydrate = async () => {\n\t\t\t\tconst raw = [...(await definition.hydrate(params, ctx))];\n\t\t\t\tconst rows =\n\t\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t\t? raw.map((row) => migrateRow(scopedTable, row))\n\t\t\t\t\t\t: raw;\n\t\t\t\treturn readRule\n\t\t\t\t\t? rows.filter((row) => readRule(ctx, row))\n\t\t\t\t\t: rows;\n\t\t\t};\n\t\t\t// Incremental matching only applies to single-table collections; a\n\t\t\t// join/aggregate spanning tables can't match a single row, so it uses\n\t\t\t// the refetch fallback.\n\t\t\tconst incremental = match !== undefined && tables.length === 1;\n\t\t\t// Fold the read rule into the incremental predicate (also used by the\n\t\t\t// catch-up builder), so an unreadable row never enters the view.\n\t\t\tconst boundMatch = incremental\n\t\t\t\t? (row: unknown) =>\n\t\t\t\t\t\tmatch(row, params, ctx) &&\n\t\t\t\t\t\t(readRule ? readRule(ctx, row) : true)\n\t\t\t\t: () => true;\n\t\t\tconst view = createMaterializedView<unknown>({\n\t\t\t\tkey,\n\t\t\t\tmatch: boundMatch\n\t\t\t});\n\n\t\t\t// Resume from the log when possible (catch-up diff); else send a\n\t\t\t// snapshot. The view is hydrated either way so future changes match.\n\t\t\tconst resuming =\n\t\t\t\tsince !== undefined && canResume(since, incremental);\n\t\t\tview.hydrate([...(await rehydrate())]);\n\t\t\tconst atVersion = version;\n\n\t\t\tconst subscription: ActiveSubscription = {\n\t\t\t\tkind: 'view',\n\t\t\t\tcollection,\n\t\t\t\tview,\n\t\t\t\tincremental,\n\t\t\t\trehydrate,\n\t\t\t\tkey,\n\t\t\t\tonDiff: typedOnDiff\n\t\t\t};\n\t\t\tsubscribeSet.add(subscription);\n\n\t\t\tconst unsubscribe = () => {\n\t\t\t\tsubscribeSet.delete(subscription);\n\t\t\t};\n\n\t\t\tif (resuming) {\n\t\t\t\treturn wrapReturn({\n\t\t\t\t\tinitial: [],\n\t\t\t\t\tcatchup: buildCatchup(\n\t\t\t\t\t\tsince,\n\t\t\t\t\t\ttables,\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tboundMatch\n\t\t\t\t\t) as ViewDiff<never>,\n\t\t\t\t\tcursor: currentCursor(),\n\t\t\t\t\tversion: atVersion,\n\t\t\t\t\tunsubscribe\n\t\t\t\t}) as Subscription<never>;\n\t\t\t}\n\t\t\treturn wrapReturn({\n\t\t\t\tinitial: view.rows() as never[],\n\t\t\t\tcursor: currentCursor(),\n\t\t\t\tversion: atVersion,\n\t\t\t\tunsubscribe\n\t\t\t}) as Subscription<never>;\n\t\t\t} catch (error) {\n\t\t\t\t// (1.20.1) If anything between acquire and the successful\n\t\t\t\t// return throws (authorize, abort, schema error, etc.),\n\t\t\t\t// release the tenant slot so the cap doesn't leak by one\n\t\t\t\t// per failed call.\n\t\t\t\tif (!slotHandedOff) releaseSubscriptionSlot(tenantSlot);\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\t} catch (spanError) {\n\t\t\t\t// 1.21.0: outer span wrap — re-throw, recording any\n\t\t\t\t// failure (subscribe-time errors are common and worth\n\t\t\t\t// surfacing).\n\t\t\t\tsubscribeSpan.recordException(spanError);\n\t\t\t\tsubscribeSpan.setStatus({\n\t\t\t\t\tcode: 2 /* SpanStatusCode.ERROR */,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tspanError instanceof Error\n\t\t\t\t\t\t\t? spanError.message\n\t\t\t\t\t\t\t: String(spanError)\n\t\t\t\t});\n\t\t\t\tthrow spanError;\n\t\t\t} finally {\n\t\t\t\tsubscribeSpan.end();\n\t\t\t}\n\t\t},\n\n\t\thydrate: async (collection, params, ctx, options) => {\n\t\t\tconst signal = options?.signal;\n\t\t\tcheckAborted(signal);\n\t\t\tconst definition = registry.get(collection) as\n\t\t\t\t| CollectionDefinition<unknown, unknown, unknown>\n\t\t\t\t| undefined;\n\t\t\tif (definition === undefined) {\n\t\t\t\tthrow new Error(`Unknown collection \"${collection}\"`);\n\t\t\t}\n\t\t\tif (definition.authorize !== undefined) {\n\t\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\t\tcheckAborted(signal);\n\t\t\t\tif (!allowed) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t`hydrate collection \"${collection}\"`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst raw = [...(await definition.hydrate(params, ctx))];\n\t\t\tcheckAborted(signal);\n\t\t\tconst tables = definition.tables ?? [collection];\n\t\t\tconst scopedTable = tables.length === 1 ? tables[0]! : undefined;\n\t\t\tconst rows =\n\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t? raw.map((row) => migrateRow(scopedTable, row))\n\t\t\t\t\t: raw;\n\t\t\tconst readRule =\n\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t? readRuleFor(scopedTable)\n\t\t\t\t\t: undefined;\n\t\t\treturn readRule ? rows.filter((row) => readRule(ctx, row)) : rows;\n\t\t},\n\n\t\tapplyChange: (table, change) =>\n\t\t\tapplyChange(table, change as RowChange<unknown>),\n\n\t\tconnectSource: async (source) => {\n\t\t\tawait source.start((table, change) => applyChange(table, change));\n\t\t\treturn async () => {\n\t\t\t\tawait source.stop();\n\t\t\t};\n\t\t},\n\n\t\tconnectCluster: async (bus) => {\n\t\t\tconst unsubscribe = await bus.subscribe((message) => {\n\t\t\t\t// Ignore our own broadcasts; apply peers' changes locally without\n\t\t\t\t// re-broadcasting (that would loop).\n\t\t\t\tif (message.origin === instanceId) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// 1.17.0 — log peer changes with their origin + originVersion\n\t\t\t\t// so a client carrying a cross-instance cursor can resume\n\t\t\t\t// against them. Pre-1.17 buses that don't carry originVersion\n\t\t\t\t// default to 0 (any cross-instance resume falls back to a\n\t\t\t\t// snapshot — matches pre-1.17 behavior exactly).\n\t\t\t\tvoid applyChangeBatch(message.changes, false, {\n\t\t\t\t\torigin: message.origin,\n\t\t\t\t\toriginVersion: message.originVersion ?? 0\n\t\t\t\t});\n\t\t\t});\n\t\t\tclusterBus = bus;\n\n\t\t\treturn async () => {\n\t\t\t\tclusterBus = undefined;\n\t\t\t\tawait unsubscribe();\n\t\t\t};\n\t\t},\n\n\t\tsubscriptionCount: (collection) => {\n\t\t\tif (collection !== undefined) {\n\t\t\t\treturn active.get(collection)?.size ?? 0;\n\t\t\t}\n\t\t\tlet total = 0;\n\t\t\tfor (const set of active.values()) {\n\t\t\t\ttotal += set.size;\n\t\t\t}\n\t\t\treturn total;\n\t\t},\n\n\t\tregisterMutation: (mutation) => {\n\t\t\tif (\n\t\t\t\tmutation.handler === undefined &&\n\t\t\t\tmutation.sandboxedHandler === undefined\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Mutation \"${mutation.name}\" must define either \\`handler\\` or \\`sandboxedHandler\\``\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmutation.handler !== undefined &&\n\t\t\t\tmutation.sandboxedHandler !== undefined\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Mutation \"${mutation.name}\" defines both \\`handler\\` and \\`sandboxedHandler\\` — pick one`\n\t\t\t\t);\n\t\t\t}\n\t\t\tmutations.set(mutation.name, mutation);\n\t\t\t// Build the sandbox runner eagerly only if we know the source —\n\t\t\t// the actual isolate spawn is still lazy (inside makeSandboxedHandler).\n\t\t\tif (mutation.sandboxedHandler !== undefined) {\n\t\t\t\tsandboxRunners.set(\n\t\t\t\t\tmutation.name,\n\t\t\t\t\tmakeSandboxedHandler(\n\t\t\t\t\t\tmutation.sandboxedHandler,\n\t\t\t\t\t\tmutation.sandbox,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbridgeFetch: options.bridgeFetch,\n\t\t\t\t\t\t\tmetricsHook:\n\t\t\t\t\t\t\t\toptions.handlerMetrics === undefined\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\tmutationName: mutation.name,\n\t\t\t\t\t\t\t\t\t\t\tonMetrics: options.handlerMetrics\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\tregisterWriter: (table, writer) => {\n\t\t\twriters.set(table, writer as TableWriter);\n\t\t},\n\n\t\tregisterReactive: (query) => {\n\t\t\tregistry.set(query.name, query);\n\t\t},\n\n\t\tregisterReader: (table, reader) => {\n\t\t\treaders.set(table, reader as TableReader);\n\t\t},\n\n\t\tregisterPermissions: (table, rules) => {\n\t\t\tpermissions.set(table, rules as TablePermissions<unknown, unknown>);\n\t\t},\n\n\t\tregisterSchema: (table, schema) => {\n\t\t\tschemas.set(table, schema as TableSchema<unknown>);\n\t\t},\n\n\t\tregisterCrdt: (table, fields) => {\n\t\t\tcrdtFields.set(\n\t\t\t\ttable,\n\t\t\t\tfields as Record<string, CrdtMergeable<unknown>>\n\t\t\t);\n\t\t\t// A ready-made merge mutation so a client needs no custom server code:\n\t\t\t// upsert the row patch — the CRDT auto-merge in makeActions folds the\n\t\t\t// declared fields into the stored row. Named \"<table>:merge\".\n\t\t\tconst name = `${table}:merge`;\n\t\t\tmutations.set(name, {\n\t\t\t\thandler: async (args, ctx, actions) => {\n\t\t\t\t\tconst existing = await readExisting(table, args, ctx);\n\t\t\t\t\treturn existing === undefined\n\t\t\t\t\t\t? actions.insert(table, args)\n\t\t\t\t\t\t: actions.update(table, args);\n\t\t\t\t},\n\t\t\t\tname\n\t\t\t} as MutationDefinition<unknown, unknown, unknown>);\n\t\t},\n\n\t\tmigrate: (table, row) => migrateRow(table, row) as typeof row,\n\n\t\trunMutation: async (name, args, ctx) => {\n\t\t\t// 1.21.0: wrap the entire mutation lifecycle in a span. Noop\n\t\t\t// when no tracerProvider was supplied.\n\t\t\tconst span = tracer.startSpan('sync.runMutation', {\n\t\t\t\tattributes: {\n\t\t\t\t\t[ABS_ATTRS.engineId]: instanceId,\n\t\t\t\t\t[ABS_ATTRS.mutation]: name\n\t\t\t\t}\n\t\t\t});\n\t\t\ttry {\n\t\t\t\t// 1.24.0: reject early when fenced — before authorize, before\n\t\t\t\t// slot acquisition. Operators expect a fenced engine to be a\n\t\t\t\t// hard wall, not a queue.\n\t\t\t\tif (activeFences.size > 0) {\n\t\t\t\t\tconst oldest = activeFences.values().next()\n\t\t\t\t\t\t.value as FenceHandle;\n\t\t\t\t\tthrow new EngineFencedError(oldest.reason);\n\t\t\t\t}\n\t\t\t\tconst mutation = mutations.get(name);\n\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\tthrow new Error(`Unknown mutation \"${name}\"`);\n\t\t\t\t}\n\t\t\tif (mutation.authorize !== undefined) {\n\t\t\t\tconst allowed = await mutation.authorize(args, ctx);\n\t\t\t\tif (!allowed) {\n\t\t\t\t\tthrow new UnauthorizedError(`run mutation \"${name}\"`);\n\t\t\t\t}\n\t\t\t}\n\t\t\t// 1.20.0: gate at the entry. Wait if `mutationConcurrency`\n\t\t\t// is saturated; throw `MutationQueueOverflowError` if the\n\t\t\t// queue is also capped and full. Authorization fails before\n\t\t\t// the gate so a denied call never burns a slot.\n\t\t\tawait acquireMutationSlot();\n\n\t\t\t// Pick the handler shape: in-process function or sandboxed string\n\t\t\t// source (runs inside @absolutejs/isolated-jsc). Sandbox runner is\n\t\t\t// built lazily and pre-cached in registerMutation.\n\t\t\tconst sandboxRunner = sandboxRunners.get(name);\n\t\t\tconst invokeHandler =\n\t\t\t\tsandboxRunner !== undefined\n\t\t\t\t\t? sandboxRunner\n\t\t\t\t\t: (\n\t\t\t\t\t\t\ta: unknown,\n\t\t\t\t\t\t\tc: unknown,\n\t\t\t\t\t\t\tactions: MutationActions\n\t\t\t\t\t\t): Promise<unknown> =>\n\t\t\t\t\t\t\tPromise.resolve(\n\t\t\t\t\t\t\t\t// Non-null assertion: registerMutation guarantees one of\n\t\t\t\t\t\t\t\t// handler/sandboxedHandler is defined.\n\t\t\t\t\t\t\t\tmutation.handler!(a, c, actions)\n\t\t\t\t\t\t\t);\n\n\t\t\t// Run the handler (optionally inside the DB transaction), collecting its\n\t\t\t// changes into a fresh buffer per attempt — so a transaction that retries\n\t\t\t// or rolls back never double-emits or leaks a half-applied batch.\n\t\t\tconst runHandler = async (tx: unknown) => {\n\t\t\t\tconst { actions, buffered } = makeActions(tx, ctx, true);\n\t\t\t\tconst result = await invokeHandler(args, ctx, actions);\n\t\t\t\treturn { buffered, result };\n\t\t\t};\n\n\t\t\t// Resolve the retry policy once per call. When `mutation.retry` is\n\t\t\t// undefined we still go through the loop, but bounded to one\n\t\t\t// attempt with no backoff (cheaper than a separate code path).\n\t\t\tconst retry = mutation.retry;\n\t\t\tconst maxAttempts =\n\t\t\t\tretry === undefined ? 1 : (retry.maxAttempts ?? 5);\n\t\t\tconst isRetryable = retry?.isRetryable ?? isSerializationFailure;\n\t\t\tconst computeDelay = retry?.backoff ?? exponentialBackoff();\n\t\t\tconst maxElapsedMs = retry?.maxElapsedMs ?? 30_000;\n\t\t\tconst startedAt = Date.now();\n\n\t\t\t// Each attempt builds fresh `actions`/`buffered` via the makeActions\n\t\t\t// call inside runHandler, so a retry never inherits half-applied\n\t\t\t// buffered changes from a failed attempt. Transactions reopen too:\n\t\t\t// runInTransaction wraps each individual attempt.\n\t\t\tlet lastError: unknown;\n\t\t\tlet attemptsMade = 0;\n\t\t\ttry {\n\t\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\t\tattemptsMade = attempt;\n\t\t\t\ttry {\n\t\t\t\t\tconst { buffered, result } =\n\t\t\t\t\t\trunInTransaction !== undefined\n\t\t\t\t\t\t\t? await runInTransaction((tx) => runHandler(tx))\n\t\t\t\t\t\t\t: await runHandler(undefined);\n\t\t\t\t\tawait applyChangeBatch(buffered);\n\t\t\t\t\tmutationsCompleted += 1;\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'mutation',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tstatus: 'ok'\n\t\t\t\t\t});\n\t\t\t\t\treturn result;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlastError = error;\n\t\t\t\t\tconst elapsedMs = Date.now() - startedAt;\n\t\t\t\t\tconst canRetry =\n\t\t\t\t\t\tattempt < maxAttempts &&\n\t\t\t\t\t\tisRetryable(error) &&\n\t\t\t\t\t\telapsedMs < maxElapsedMs;\n\t\t\t\t\tif (!canRetry) break;\n\t\t\t\t\tmutationsRetried += 1;\n\n\t\t\t\t\tconst rawDelay = computeDelay(attempt);\n\t\t\t\t\t// Cap the delay so we don't blow past maxElapsedMs while\n\t\t\t\t\t// sleeping. If the cap would be negative we're already past\n\t\t\t\t\t// the budget; treat as exhausted.\n\t\t\t\t\tconst remaining = maxElapsedMs - elapsedMs;\n\t\t\t\t\tif (remaining <= 0) break;\n\t\t\t\t\tconst delayMs = Math.max(0, Math.min(rawDelay, remaining));\n\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'mutationRetry',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\tdelayMs,\n\t\t\t\t\t\terrorName:\n\t\t\t\t\t\t\terror instanceof Error ? error.name : 'Error',\n\t\t\t\t\t\terrorMessage:\n\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t\t: String(error)\n\t\t\t\t\t});\n\t\t\t\t\tif (delayMs > 0) {\n\t\t\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\t\t\tsetTimeout(resolve, delayMs)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tmutationsFailed += 1;\n\t\t\temitActivity({\n\t\t\t\ttype: 'mutation',\n\t\t\t\tat: Date.now(),\n\t\t\t\tname,\n\t\t\t\tstatus: 'error'\n\t\t\t});\n\t\t\t// Wrap only when we actually burned through more than one attempt\n\t\t\t// — a non-retryable first-attempt failure passes through with its\n\t\t\t// original error preserved, even if `retry` is configured.\n\t\t\tif (attemptsMade > 1) {\n\t\t\t\tthrow new RetriesExhaustedError(\n\t\t\t\t\tattemptsMade,\n\t\t\t\t\tDate.now() - startedAt,\n\t\t\t\t\tlastError\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow lastError;\n\t\t\t} finally {\n\t\t\t\treleaseMutationSlot();\n\t\t\t}\n\t\t\t} catch (spanError) {\n\t\t\t\t// 1.21.0: outer span wrap — record any throw, rethrow.\n\t\t\t\tspan.recordException(spanError);\n\t\t\t\tspan.setStatus({\n\t\t\t\t\tcode: 2 /* SpanStatusCode.ERROR */,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tspanError instanceof Error\n\t\t\t\t\t\t\t? spanError.message\n\t\t\t\t\t\t\t: String(spanError)\n\t\t\t\t});\n\t\t\t\tthrow spanError;\n\t\t\t} finally {\n\t\t\t\tspan.end();\n\t\t\t}\n\t\t},\n\n\t\trunMutations: async (specs, ctx) => {\n\t\t\t// Empty batch: short-circuit. Don't open a DB tx for nothing —\n\t\t\t// some adapters (PG with auto-commit, MySQL with implicit\n\t\t\t// commit, etc.) count even an empty BEGIN/COMMIT as a real\n\t\t\t// transaction, which is wasteful and noisy in observability.\n\t\t\tif (specs.length === 0) return [];\n\t\t\t// Snapshot the requested mutation names up front so the\n\t\t\t// authorization + handler resolution happens BEFORE we open\n\t\t\t// the DB transaction. A typo'd name aborts cleanly without\n\t\t\t// burning a tx.\n\t\t\tconst resolved = specs.map((spec) => {\n\t\t\t\tconst mutation = mutations.get(spec.name);\n\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\tthrow new Error(`Unknown mutation \"${spec.name}\"`);\n\t\t\t\t}\n\t\t\t\treturn { args: spec.args, mutation, name: spec.name };\n\t\t\t});\n\t\t\t// 1.20.0: the whole batch is one slot. Resolve names BEFORE\n\t\t\t// the gate so an unknown-mutation typo never queues.\n\t\t\tawait acquireMutationSlot();\n\n\t\t\tconst runBatch = async (tx: unknown) => {\n\t\t\t\tconst results: unknown[] = [];\n\t\t\t\tconst accumulated: {\n\t\t\t\t\ttable: string;\n\t\t\t\t\tchange: RowChange<unknown>;\n\t\t\t\t}[] = [];\n\t\t\t\tfor (const { args, mutation, name } of resolved) {\n\t\t\t\t\tif (mutation.authorize !== undefined) {\n\t\t\t\t\t\tconst allowed = await mutation.authorize(args, ctx);\n\t\t\t\t\t\tif (!allowed) {\n\t\t\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\t\t`run mutation \"${name}\"`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst sandboxRunner = sandboxRunners.get(name);\n\t\t\t\t\tconst invokeHandler =\n\t\t\t\t\t\tsandboxRunner !== undefined\n\t\t\t\t\t\t\t? sandboxRunner\n\t\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\t\ta: unknown,\n\t\t\t\t\t\t\t\t\tc: unknown,\n\t\t\t\t\t\t\t\t\tactions: MutationActions\n\t\t\t\t\t\t\t\t): Promise<unknown> =>\n\t\t\t\t\t\t\t\t\tPromise.resolve(\n\t\t\t\t\t\t\t\t\t\tmutation.handler!(a, c, actions)\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t// Each handler gets its own `actions`/`buffered` so per-\n\t\t\t\t\t// call validation + crdt merges still work — we collect\n\t\t\t\t\t// the buffered tail into `accumulated` after each\n\t\t\t\t\t// handler returns. If the next handler throws, the\n\t\t\t\t\t// surrounding `runInTransaction` rolls everything back;\n\t\t\t\t\t// applyChangeBatch never runs.\n\t\t\t\t\tconst { actions, buffered } = makeActions(tx, ctx, true);\n\t\t\t\t\tconst result = await invokeHandler(args, ctx, actions);\n\t\t\t\t\tresults.push(result);\n\t\t\t\t\taccumulated.push(...buffered);\n\t\t\t\t}\n\t\t\t\treturn { accumulated, results };\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst { accumulated, results } =\n\t\t\t\t\trunInTransaction !== undefined\n\t\t\t\t\t\t? await runInTransaction((tx) => runBatch(tx))\n\t\t\t\t\t\t: await runBatch(undefined);\n\t\t\t\tawait applyChangeBatch(accumulated);\n\t\t\t\temitActivity({\n\t\t\t\t\ttype: 'mutationBatch',\n\t\t\t\t\tat: Date.now(),\n\t\t\t\t\tnames: resolved.map((entry) => entry.name),\n\t\t\t\t\tstatus: 'ok'\n\t\t\t\t});\n\t\t\t\treturn results;\n\t\t\t} catch (error) {\n\t\t\t\temitActivity({\n\t\t\t\t\ttype: 'mutationBatch',\n\t\t\t\t\tat: Date.now(),\n\t\t\t\t\tnames: resolved.map((entry) => entry.name),\n\t\t\t\t\tstatus: 'error'\n\t\t\t\t});\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\treleaseMutationSlot();\n\t\t\t}\n\t\t},\n\n\t\tregisterSchedule: (schedule) => {\n\t\t\tschedules.set(schedule.name, schedule);\n\t\t},\n\n\t\tlistSchedules: () => [...schedules.values()],\n\n\t\trunSchedule: async (name) => {\n\t\t\tconst schedule = schedules.get(name);\n\t\t\tif (schedule === undefined) {\n\t\t\t\tthrow new Error(`Unknown schedule \"${name}\"`);\n\t\t\t}\n\t\t\t// A schedule reads unscoped and writes without permission checks (it's\n\t\t\t// trusted server code); its writes emit as one live batch like a mutation.\n\t\t\tconst runHandler = async (tx: unknown) => {\n\t\t\t\tconst { actions, buffered } = makeActions(tx, {}, false);\n\t\t\t\tconst db = makeReadHandle({}, new Set(), new Set(), [], false);\n\t\t\t\tawait schedule.run({ actions, db });\n\t\t\t\treturn buffered;\n\t\t\t};\n\n\t\t\tconst retry = schedule.retry;\n\t\t\tconst maxAttempts =\n\t\t\t\tretry === undefined ? 1 : (retry.maxAttempts ?? 5);\n\t\t\tconst isRetryable = retry?.isRetryable ?? isSerializationFailure;\n\t\t\tconst computeDelay = retry?.backoff ?? exponentialBackoff();\n\t\t\tconst maxElapsedMs = retry?.maxElapsedMs ?? 30_000;\n\t\t\tconst startedAt = Date.now();\n\n\t\t\tlet lastError: unknown;\n\t\t\tlet attemptsMade = 0;\n\t\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\t\tattemptsMade = attempt;\n\t\t\t\ttry {\n\t\t\t\t\tconst buffered =\n\t\t\t\t\t\trunInTransaction !== undefined\n\t\t\t\t\t\t\t? await runInTransaction((tx) => runHandler(tx))\n\t\t\t\t\t\t\t: await runHandler(undefined);\n\t\t\t\t\tawait applyChangeBatch(buffered);\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'schedule',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tstatus: 'ok'\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlastError = error;\n\t\t\t\t\tconst elapsedMs = Date.now() - startedAt;\n\t\t\t\t\tconst canRetry =\n\t\t\t\t\t\tattempt < maxAttempts &&\n\t\t\t\t\t\tisRetryable(error) &&\n\t\t\t\t\t\telapsedMs < maxElapsedMs;\n\t\t\t\t\tif (!canRetry) break;\n\n\t\t\t\t\tconst rawDelay = computeDelay(attempt);\n\t\t\t\t\tconst remaining = maxElapsedMs - elapsedMs;\n\t\t\t\t\tif (remaining <= 0) break;\n\t\t\t\t\tconst delayMs = Math.max(0, Math.min(rawDelay, remaining));\n\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'scheduleRetry',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\tdelayMs,\n\t\t\t\t\t\terrorName:\n\t\t\t\t\t\t\terror instanceof Error ? error.name : 'Error',\n\t\t\t\t\t\terrorMessage:\n\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t\t: String(error)\n\t\t\t\t\t});\n\t\t\t\t\tif (delayMs > 0) {\n\t\t\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\t\t\tsetTimeout(resolve, delayMs)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\temitActivity({\n\t\t\t\ttype: 'schedule',\n\t\t\t\tat: Date.now(),\n\t\t\t\tname,\n\t\t\t\tstatus: 'error'\n\t\t\t});\n\t\t\tif (attemptsMade > 1) {\n\t\t\t\tthrow new RetriesExhaustedError(\n\t\t\t\t\tattemptsMade,\n\t\t\t\t\tDate.now() - startedAt,\n\t\t\t\t\tlastError\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow lastError;\n\t\t},\n\n\t\tregisterPack: (pack) => {\n\t\t\tfor (const table of pack.ownsTables) {\n\t\t\t\tconst existing = packTableOwners.get(table);\n\t\t\t\tif (existing !== undefined) {\n\t\t\t\t\tthrow new PackTableConflictError(\n\t\t\t\t\t\ttable,\n\t\t\t\t\t\texisting,\n\t\t\t\t\t\tpack.name\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.requireDependencies === true) {\n\t\t\t\tfor (const table of pack.readsTables ?? []) {\n\t\t\t\t\tif (!readers.has(table)) {\n\t\t\t\t\t\tthrow new PackMissingDependencyError(pack.name, table);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.schemas !== undefined) {\n\t\t\t\tfor (const [table, schema] of Object.entries(pack.schemas)) {\n\t\t\t\t\tengine.registerSchema(table, schema);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.permissions !== undefined) {\n\t\t\t\tfor (const [table, rules] of Object.entries(pack.permissions)) {\n\t\t\t\t\tengine.registerPermissions(table, rules);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.readers !== undefined) {\n\t\t\t\tfor (const [table, reader] of Object.entries(pack.readers)) {\n\t\t\t\t\tengine.registerReader(table, reader);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.writers !== undefined) {\n\t\t\t\tfor (const [table, writer] of Object.entries(pack.writers)) {\n\t\t\t\t\tengine.registerWriter(table, writer);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.crdt !== undefined) {\n\t\t\t\tfor (const [table, fields] of Object.entries(pack.crdt)) {\n\t\t\t\t\tengine.registerCrdt(table, fields);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const collection of pack.collections ?? []) {\n\t\t\t\tengine.register(collection);\n\t\t\t}\n\t\t\tfor (const collection of pack.joinCollections ?? []) {\n\t\t\t\tengine.registerJoin(collection);\n\t\t\t}\n\t\t\tfor (const collection of pack.graphCollections ?? []) {\n\t\t\t\tengine.registerGraph(collection);\n\t\t\t}\n\t\t\tfor (const collection of pack.searchCollections ?? []) {\n\t\t\t\tengine.registerSearch(collection);\n\t\t\t}\n\t\t\tfor (const query of pack.reactiveQueries ?? []) {\n\t\t\t\tengine.registerReactive(query);\n\t\t\t}\n\t\t\tfor (const mutation of pack.mutations ?? []) {\n\t\t\t\tengine.registerMutation(mutation);\n\t\t\t}\n\t\t\tfor (const schedule of pack.schedules ?? []) {\n\t\t\t\tengine.registerSchedule(schedule);\n\t\t\t}\n\t\t\tfor (const table of pack.ownsTables) {\n\t\t\t\tpackTableOwners.set(table, pack.name);\n\t\t\t}\n\t\t\tregisteredPacks.push({\n\t\t\t\tname: pack.name,\n\t\t\t\tversion: pack.version,\n\t\t\t\townsTables: [...pack.ownsTables],\n\t\t\t\treadsTables: [...(pack.readsTables ?? [])]\n\t\t\t});\n\t\t},\n\n\t\tinspect: () => {\n\t\t\tconst collections = [...registry.entries()].map(([name, def]) => {\n\t\t\t\tconst kind = ((def as { kind?: CollectionKind }).kind ??\n\t\t\t\t\t'view') as CollectionKind;\n\t\t\t\tlet tables: string[] = [];\n\t\t\t\tif (kind === 'join') {\n\t\t\t\t\tconst join = def as JoinCollectionDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>;\n\t\t\t\t\ttables = [join.left.table, join.right.table];\n\t\t\t\t} else if (kind === 'graph') {\n\t\t\t\t\ttables = (\n\t\t\t\t\t\tdef as GraphCollectionDefinition<\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t>\n\t\t\t\t\t).query.tables();\n\t\t\t\t} else if (kind === 'search') {\n\t\t\t\t\ttables = [\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tdef as SearchCollectionDefinition<\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t).table\n\t\t\t\t\t];\n\t\t\t\t} else if (kind === 'view') {\n\t\t\t\t\ttables = (\n\t\t\t\t\t\tdef as CollectionDefinition<unknown, unknown, unknown>\n\t\t\t\t\t).tables ?? [name];\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\tkind,\n\t\t\t\t\ttables,\n\t\t\t\t\tsubscriptions: active.get(name)?.size ?? 0\n\t\t\t\t};\n\t\t\t});\n\t\t\tconst DEVTOOLS_RECENT = 50;\n\t\t\treturn {\n\t\t\t\tversion,\n\t\t\t\tcollections,\n\t\t\t\tmutations: [...mutations.keys()],\n\t\t\t\tschedules: [...schedules.values()].map((schedule) => ({\n\t\t\t\t\tname: schedule.name,\n\t\t\t\t\tpattern: schedule.pattern\n\t\t\t\t})),\n\t\t\t\treaders: [...readers.keys()],\n\t\t\t\twriters: [...writers.keys()],\n\t\t\t\trecentChanges: changeLog\n\t\t\t\t\t.slice(-DEVTOOLS_RECENT)\n\t\t\t\t\t.map((entry) => ({\n\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\ttable: entry.table,\n\t\t\t\t\t\top: entry.change.op\n\t\t\t\t\t})),\n\t\t\t\tpacks: registeredPacks.map((pack) => ({\n\t\t\t\t\tname: pack.name,\n\t\t\t\t\tversion: pack.version,\n\t\t\t\t\townsTables: [...pack.ownsTables],\n\t\t\t\t\treadsTables: [...pack.readsTables]\n\t\t\t\t}))\n\t\t\t};\n\t\t},\n\n\t\texportChangeLog: () => ({\n\t\t\tentries: changeLog.slice(),\n\t\t\texportedAt: Date.now(),\n\t\t\tinstanceId,\n\t\t\tversion\n\t\t}),\n\n\t\timportChangeLog,\n\n\t\treplayTo: async ({ at, tables }) => {\n\t\t\t// 1.22.0: walk the bounded change log forward to targetAt,\n\t\t\t// folding each op into a per-table keyed view. Last write\n\t\t\t// wins per key. Delete removes the key.\n\t\t\tconst filterTables =\n\t\t\t\ttables !== undefined ? new Set(tables) : undefined;\n\t\t\tconst state = new Map<string, Map<RowKey, unknown>>();\n\t\t\tlet asOfVersion = 0;\n\t\t\tlet asOfAt = 0;\n\t\t\t// Truncation: the log doesn't extend back to `at`. We've\n\t\t\t// trimmed entries that may have mattered for the\n\t\t\t// reconstruction, so the result is \"state walked forward\n\t\t\t// from the OLDEST retained entry\" rather than the actual\n\t\t\t// state at `at`. Distinguishable from \"no history at all\"\n\t\t\t// (`changeLog[0]?.version === 1`).\n\t\t\tconst oldest = changeLog[0];\n\t\t\tconst truncated =\n\t\t\t\toldest !== undefined &&\n\t\t\t\toldest.version > 1 &&\n\t\t\t\toldest.at > at;\n\t\t\tfor (const entry of changeLog) {\n\t\t\t\tif (entry.at > at) break;\n\t\t\t\tif (\n\t\t\t\t\tfilterTables !== undefined &&\n\t\t\t\t\t!filterTables.has(entry.table)\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlet tableState = state.get(entry.table);\n\t\t\t\tif (tableState === undefined) {\n\t\t\t\t\ttableState = new Map();\n\t\t\t\t\tstate.set(entry.table, tableState);\n\t\t\t\t}\n\t\t\t\tconst reader = readers.get(entry.table);\n\t\t\t\tconst key =\n\t\t\t\t\treader?.key?.(entry.change.row) ??\n\t\t\t\t\t((entry.change.row as { id?: RowKey })?.id as RowKey);\n\t\t\t\tif (key === undefined) {\n\t\t\t\t\t// Without a stable key we can't apply ops idempotently\n\t\t\t\t\t// — skip silently. In practice every table the\n\t\t\t\t\t// engine has emitted changes for has a reader (the\n\t\t\t\t\t// engine's own change-emit path doesn't run without\n\t\t\t\t\t// one), so this branch is defensive.\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (entry.change.op === 'delete') {\n\t\t\t\t\ttableState.delete(key);\n\t\t\t\t} else {\n\t\t\t\t\ttableState.set(key, entry.change.row);\n\t\t\t\t}\n\t\t\t\tasOfVersion = entry.version;\n\t\t\t\tasOfAt = entry.at;\n\t\t\t}\n\t\t\tconst rows: Record<string, ReadonlyArray<unknown>> = {};\n\t\t\tfor (const [table, map] of state) {\n\t\t\t\trows[table] = [...map.values()];\n\t\t\t}\n\t\t\treturn { asOfAt, asOfVersion, rows, truncated };\n\t\t},\n\n\t\tfence: ({ reason }) => {\n\t\t\tconst handle: FenceHandle = {\n\t\t\t\tfencedAt: Date.now(),\n\t\t\t\treason,\n\t\t\t\tlift: () => {\n\t\t\t\t\tactiveFences.delete(handle);\n\t\t\t\t}\n\t\t\t};\n\t\t\tactiveFences.add(handle);\n\t\t\treturn handle;\n\t\t},\n\n\t\texportSnapshot: async ({ tables, ctx = {} }: ExportSnapshotOptions = {}) => {\n\t\t\tconst tableFilter = tables !== undefined ? new Set(tables) : undefined;\n\t\t\tconst rows: Record<string, ReadonlyArray<unknown>> = {};\n\t\t\tfor (const [table, reader] of readers) {\n\t\t\t\tif (tableFilter !== undefined && !tableFilter.has(table)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst iterable = await reader.all(ctx);\n\t\t\t\trows[table] = [...iterable];\n\t\t\t}\n\t\t\treturn {\n\t\t\t\texportedAt: Date.now(),\n\t\t\t\tsourceInstanceId: instanceId,\n\t\t\t\ttables: rows,\n\t\t\t\tversion\n\t\t\t};\n\t\t},\n\n\t\timportSnapshot: async (\n\t\t\tsnapshot,\n\t\t\t{ tables, onProgress, ctx = {} }: ImportSnapshotOptions = {}\n\t\t) => {\n\t\t\tconst tableFilter = tables !== undefined ? new Set(tables) : undefined;\n\t\t\tconst perTable: Record<string, number> = {};\n\t\t\tconst skipped: string[] = [];\n\t\t\tlet tablesImported = 0;\n\t\t\tlet rowsImported = 0;\n\t\t\tfor (const [table, snapshotRows] of Object.entries(\n\t\t\t\tsnapshot.tables\n\t\t\t)) {\n\t\t\t\tif (tableFilter !== undefined && !tableFilter.has(table)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst writer = writers.get(table);\n\t\t\t\tif (writer === undefined) {\n\t\t\t\t\tskipped.push(table);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst total = snapshotRows.length;\n\t\t\t\tlet done = 0;\n\t\t\t\tfor (const row of snapshotRows) {\n\t\t\t\t\tawait writer.insert(row, ctx, undefined);\n\t\t\t\t\tdone += 1;\n\t\t\t\t\trowsImported += 1;\n\t\t\t\t\tif (onProgress !== undefined) {\n\t\t\t\t\t\tonProgress(table, done, total);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tperTable[table] = done;\n\t\t\t\tif (done > 0) tablesImported += 1;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tperTable,\n\t\t\t\trowsImported,\n\t\t\t\tskipped,\n\t\t\t\ttablesImported\n\t\t\t};\n\t\t},\n\n\t\tmetrics: () => {\n\t\t\tconst now = Date.now();\n\t\t\tconst byCollection: Record<string, number> = {};\n\t\t\tlet totalSubscriptions = 0;\n\t\t\tfor (const [name, subs] of active) {\n\t\t\t\tbyCollection[name] = subs.size;\n\t\t\t\ttotalSubscriptions += subs.size;\n\t\t\t}\n\t\t\tconst oldest = changeLog[0];\n\t\t\treturn {\n\t\t\t\tat: now,\n\t\t\t\tchangeLog: {\n\t\t\t\t\tcapacity: changeLogSize,\n\t\t\t\t\tentries: changeLog.length,\n\t\t\t\t\toldestAgeMs: oldest ? now - oldest.at : null,\n\t\t\t\t\toldestVersion: oldest ? oldest.version : null,\n\t\t\t\t\tretainMs: changeLogRetainMs\n\t\t\t\t},\n\t\t\t\tmutations: {\n\t\t\t\t\tcompleted: mutationsCompleted,\n\t\t\t\t\tfailed: mutationsFailed,\n\t\t\t\t\tinFlight: mutationsInFlight,\n\t\t\t\t\tqueued: mutationsQueued,\n\t\t\t\t\tretried: mutationsRetried\n\t\t\t\t},\n\t\t\t\treactiveCache: {\n\t\t\t\t\tcapacity: reactiveCacheMax,\n\t\t\t\t\tentries: cachedReruns.size\n\t\t\t\t},\n\t\t\t\tschedules: {\n\t\t\t\t\tregistered: schedules.size\n\t\t\t\t},\n\t\t\t\tsubscriptions: {\n\t\t\t\t\tbyCollection,\n\t\t\t\t\tbyTenant: Object.fromEntries(subscriptionsByTenant),\n\t\t\t\t\ttotal: totalSubscriptions\n\t\t\t\t},\n\t\t\t\tuptimeMs: now - engineStartedAt,\n\t\t\t\tversion\n\t\t\t};\n\t\t},\n\n\t\tonActivity: (listener) => {\n\t\t\tactivityListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tactivityListeners.delete(listener);\n\t\t\t};\n\t\t},\n\n\t\tstreamChanges: ({\n\t\t\tsince = 0,\n\t\t\tsignal,\n\t\t\tmaxBuffer = 10_000\n\t\t}: StreamChangesOptions = {}) => {\n\t\t\t// Detect a gap up front so the consumer's `for await` sees the\n\t\t\t// throw immediately rather than after the first historical entry.\n\t\t\t// (We tolerate `since === 0`, which means \"give me everything in\n\t\t\t// the log\"; the gap check only kicks in for a non-zero cursor.)\n\t\t\tconst oldest = changeLog[0];\n\t\t\tif (\n\t\t\t\tsince > 0 &&\n\t\t\t\toldest !== undefined &&\n\t\t\t\toldest.version > since + 1\n\t\t\t) {\n\t\t\t\tconst err = new MissedChangesError(since, oldest.version);\n\t\t\t\treturn {\n\t\t\t\t\t[Symbol.asyncIterator]() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnext: () => Promise.reject(err)\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Register the subscriber BEFORE snapshotting history so a commit\n\t\t\t// landing between the snapshot and the live tail can't be missed.\n\t\t\t// Phase 2 dedupes against `cursor`.\n\t\t\tconst buffer: LoggedChange[] = [];\n\t\t\tlet waiter: (() => void) | null = null;\n\t\t\tlet overflow = false;\n\t\t\tconst wake = () => {\n\t\t\t\tif (waiter !== null) {\n\t\t\t\t\tconst resume = waiter;\n\t\t\t\t\twaiter = null;\n\t\t\t\t\tresume();\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst subscriber = (entry: LoggedChange) => {\n\t\t\t\tif (buffer.length >= maxBuffer) {\n\t\t\t\t\toverflow = true;\n\t\t\t\t\twake();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbuffer.push(entry);\n\t\t\t\twake();\n\t\t\t};\n\t\t\tstreamSubscribers.add(subscriber);\n\n\t\t\tconst onAbort = () => wake();\n\t\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\n\t\t\tlet lastDelivered = since;\n\n\t\t\treturn {\n\t\t\t\tasync *[Symbol.asyncIterator]() {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Phase 1: historical entries. Copy the array so a\n\t\t\t\t\t\t// concurrent log.shift() (when the ring buffer rotates)\n\t\t\t\t\t\t// can't surprise us mid-iteration.\n\t\t\t\t\t\t//\n\t\t\t\t\t\t// A single batched mutation writes N rows that all\n\t\t\t\t\t\t// share one version, so we filter on `entry.version >\n\t\t\t\t\t\t// since` directly (no per-yield cursor bump — that\n\t\t\t\t\t\t// would deliver only the first row of every batch).\n\t\t\t\t\t\tconst history = [...changeLog];\n\t\t\t\t\t\tconst headVersion =\n\t\t\t\t\t\t\thistory.length > 0\n\t\t\t\t\t\t\t\t? history[history.length - 1]!.version\n\t\t\t\t\t\t\t\t: since;\n\t\t\t\t\t\tfor (const entry of history) {\n\t\t\t\t\t\t\tif (signal?.aborted) return;\n\t\t\t\t\t\t\tif (entry.version > since) {\n\t\t\t\t\t\t\t\tlastDelivered = entry.version;\n\t\t\t\t\t\t\t\tyield entry;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Phase 2: live tail. Dedupe against `headVersion`\n\t\t\t\t\t\t// (the head of the log when phase 1 finished): any\n\t\t\t\t\t\t// buffered entry with `version <= headVersion` was\n\t\t\t\t\t\t// already yielded from history (a commit between\n\t\t\t\t\t\t// subscriber registration and the snapshot lands in\n\t\t\t\t\t\t// both the buffer and the snapshot).\n\t\t\t\t\t\twhile (!signal?.aborted) {\n\t\t\t\t\t\t\twhile (buffer.length > 0) {\n\t\t\t\t\t\t\t\tconst entry = buffer.shift()!;\n\t\t\t\t\t\t\t\tif (entry.version > headVersion) {\n\t\t\t\t\t\t\t\t\tlastDelivered = entry.version;\n\t\t\t\t\t\t\t\t\tyield entry;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (overflow) {\n\t\t\t\t\t\t\t\tthrow new CdcConsumerSlowError(\n\t\t\t\t\t\t\t\t\tmaxBuffer,\n\t\t\t\t\t\t\t\t\tlastDelivered\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (signal?.aborted) return;\n\t\t\t\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\t\t\t\twaiter = resolve;\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tstreamSubscribers.delete(subscriber);\n\t\t\t\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t};\n\n\treturn engine;\n};\n",
13
+ "import {\n\tABS_ATTRS,\n\ttracerOrNoop,\n\ttype TracerProvider as TelemetryTracerProvider\n} from '@absolutejs/telemetry';\nimport type {\n\tCollectionContext,\n\tCollectionDefinition,\n\tJoinCollectionDefinition\n} from './collection';\nimport { createEquiJoin } from './equiJoin';\nimport type { EquiJoin } from './equiJoin';\nimport type { GraphCollectionDefinition, GraphInstance } from './graph';\nimport { createMaterializedView, isEmptyViewDiff } from './materializedView';\nimport type { MaterializedView } from './materializedView';\nimport type {\n\tMutationActions,\n\tMutationDefinition,\n\tTableWriter,\n\tTransactionRunner\n} from './mutation';\nimport type {\n\tReactiveQueryDefinition,\n\tReadHandle,\n\tTableReader\n} from './reactive';\nimport {\n\texponentialBackoff,\n\tisSerializationFailure,\n\tRetriesExhaustedError\n} from './retry';\nimport {\n\ttype BridgeFetchConfig,\n\ttype HandlerMetricsHook,\n\ttype HandlerMetricsRecord,\n\tmakeSandboxedHandler\n} from './sandbox';\nimport type {\n\tPermissionsDefinition,\n\tReadRule,\n\tTablePermissions,\n\tWriteRule\n} from './permissions';\nimport { PackMissingDependencyError, PackTableConflictError } from './pack';\nimport type { RegisteredPack, SyncPack } from './pack';\nimport type { SearchCollectionDefinition, SearchIndex } from './search';\nimport { SEARCH_SCORE_FIELD } from './search';\nimport type { ScheduleDefinition } from './schedule';\nimport type {\n\tCollectionKind,\n\tEngineActivity,\n\tEngineInspection,\n\tEngineMetrics\n} from './devtools';\nimport type { SchemaDefinition, TableSchema } from './schema';\nimport {\n\tEngineFencedError,\n\ttype EngineSnapshot,\n\ttype ExportSnapshotOptions,\n\ttype FenceHandle,\n\ttype ImportSnapshotOptions,\n\ttype MigrationImportResult\n} from './migrate';\nimport type { CrdtMergeable } from '../crdt';\nimport type { ClusterBus } from './cluster';\nimport type { ChangeSource, RowChange, RowKey, ViewDiff } from './types';\n\n/**\n * Which fields of a `Row` are CRDT values, and the {@link CrdtMergeable} backend\n * (e.g. `rgaText`, or `yjsText` from `@absolutejs/sync-yjs`) used to merge each.\n * Pass to `engine.registerCrdt` so the engine merges those fields on write.\n */\nexport type CrdtFields<Row> = {\n\t[Field in keyof Row]?: CrdtMergeable<Row[Field]>;\n};\n\n/**\n * Thrown when `authorize` denies a subscribe or a mutation. The message names\n * the denied action; the message always starts with \"Not authorized\".\n */\nexport class UnauthorizedError extends Error {\n\tconstructor(subject: string) {\n\t\tsuper(`Not authorized: ${subject}`);\n\t\tthis.name = 'UnauthorizedError';\n\t}\n}\n\n/**\n * Thrown by `engine.subscribe` / `engine.hydrate` (1.15.0+) when the caller's\n * `AbortSignal` fires before the operation reaches a `Subscription` /\n * resolved value. The `name` is `'AbortError'` to match the DOM-standard\n * spelling so existing `catch (error) { if (error.name === 'AbortError') ... }`\n * patterns work unchanged.\n */\nexport class AbortError extends Error {\n\tconstructor(reason?: string) {\n\t\tsuper(reason ?? 'Aborted');\n\t\tthis.name = 'AbortError';\n\t}\n}\n\nconst checkAborted = (signal?: AbortSignal): void => {\n\tif (signal?.aborted) {\n\t\tthrow new AbortError(\n\t\t\tsignal.reason instanceof Error\n\t\t\t\t? signal.reason.message\n\t\t\t\t: typeof signal.reason === 'string'\n\t\t\t\t\t? signal.reason\n\t\t\t\t\t: 'Aborted'\n\t\t);\n\t}\n};\n\nconst linkAbortToUnsubscribe = (\n\tsignal: AbortSignal | undefined,\n\tunsubscribe: () => void\n): void => {\n\tif (signal === undefined) return;\n\tif (signal.aborted) {\n\t\tunsubscribe();\n\t\treturn;\n\t}\n\tconst handler = () => {\n\t\ttry {\n\t\t\tunsubscribe();\n\t\t} catch {\n\t\t\t/* idempotent unsubscribes shouldn't surface here */\n\t\t}\n\t};\n\tsignal.addEventListener('abort', handler, { once: true });\n};\n\n/**\n * Thrown when a mutation's write fails its table's schema (see\n * {@link defineSchema}). The message names the offending field.\n */\nexport class SchemaError extends Error {\n\tconstructor(table: string, fieldName: string) {\n\t\tsuper(`Schema violation on \"${table}\": invalid field \"${fieldName}\"`);\n\t\tthis.name = 'SchemaError';\n\t}\n}\n\nexport type SubscribeArgs<T, P, Ctx> = {\n\t/** Registered collection name. */\n\tcollection: string;\n\t/** Query params (e.g. a filter value); passed to hydrate/match/authorize. */\n\tparams: P;\n\t/** Caller context (e.g. session); passed to hydrate/match/authorize. */\n\tctx: Ctx;\n\t/**\n\t * Receives every non-empty diff (with its version) after the initial\n\t * reply. 1.18.0+: a third optional `cursor` argument carries the\n\t * cross-instance resume cursor as of this diff. Callers that ignore\n\t * the 3rd arg keep working unchanged.\n\t */\n\tonDiff: (diff: ViewDiff<T>, version: number, cursor?: string) => void;\n\t/**\n\t * Resume from a point the client already applied. When the change log still\n\t * covers `(since, now]` for a single-table collection, the engine replies\n\t * with a catch-up diff instead of a full snapshot; otherwise it falls back\n\t * to a snapshot.\n\t *\n\t * Accepts `number` (legacy pre-1.17 — interpreted as the version of THIS\n\t * engine instance) or a `string` cursor (1.17.0+ — opaque vector of\n\t * `(instanceId, version)` per origin, returned by the engine on every\n\t * subscription/diff and round-tripped by the client unmodified). Use the\n\t * cursor form for cross-instance resume.\n\t */\n\tsince?: number | string;\n\t/**\n\t * Cancellation handle (1.15.0). Two effects:\n\t * 1. If the signal is already aborted when `subscribe` is called, the\n\t * engine throws {@link AbortError} immediately — no authorize, no\n\t * hydrate, no subscription.\n\t * 2. If the signal fires AFTER the subscription is live, the engine\n\t * auto-calls `unsubscribe()`. The consumer never has to thread two\n\t * handles for the same lifetime.\n\t *\n\t * Backwards-compatible — omit `signal` and the engine behaves exactly\n\t * as in pre-1.15.0.\n\t */\n\tsignal?: AbortSignal;\n};\n\nexport type Subscription<T> = {\n\t/** The result set at subscribe time — a snapshot (empty when resuming). */\n\tinitial: T[];\n\t/** Catch-up diff when resuming via `since` (instead of `initial`). */\n\tcatchup?: ViewDiff<T>;\n\t/** The engine's local version this reply brings the client up to. */\n\tversion: number;\n\t/**\n\t * Opaque cross-instance resume cursor (1.17.0+). Encodes the per-origin\n\t * vector of `(instanceId, version)` the client is now up-to-date with;\n\t * pass it back as `SubscribeArgs.since` on reconnect. Works for resume\n\t * against ANY instance in a cluster, not just the one that issued it —\n\t * the receiving instance decodes the cursor, walks its log for entries\n\t * the client hasn't seen yet, and either replies with a catch-up diff\n\t * or a fresh snapshot.\n\t */\n\tcursor: string;\n\t/** Stop receiving diffs and release the view. */\n\tunsubscribe: () => void;\n};\n\nexport type SyncEngine = {\n\t/** Register a collection definition (see {@link defineCollection}). */\n\tregister: <T, P = void, Ctx = CollectionContext>(\n\t\tcollection: CollectionDefinition<T, P, Ctx>\n\t) => void;\n\t/** Register an incremental join collection (see {@link defineJoinCollection}). */\n\tregisterJoin: <L, R, Out, P = void, Ctx = CollectionContext>(\n\t\tcollection: JoinCollectionDefinition<L, R, Out, P, Ctx>\n\t) => void;\n\t/** Register an operator-graph collection (see {@link defineGraphCollection}). */\n\tregisterGraph: <Out, P = void, Ctx = CollectionContext>(\n\t\tcollection: GraphCollectionDefinition<Out, P, Ctx>\n\t) => void;\n\t/**\n\t * Register a live search collection (see {@link defineSearchCollection}): a\n\t * full-text or vector index maintained from a source table's change feed and\n\t * queried by the subscription's params, returning the ranked top-K live.\n\t */\n\tregisterSearch: <T, Query = string, Ctx = CollectionContext>(\n\t\tcollection: SearchCollectionDefinition<T, Query, Ctx>\n\t) => void;\n\t/**\n\t * Register a scheduled function (see {@link defineSchedule}): server-triggered\n\t * work whose `actions` writes go live through the change feed. Wire the cron\n\t * triggers with the `scheduled` Elysia plugin.\n\t */\n\tregisterSchedule: (schedule: ScheduleDefinition) => void;\n\t/**\n\t * Run a registered schedule's handler now: its writes commit (in the\n\t * configured transaction) and emit as one live batch. The `scheduled` plugin\n\t * calls this on each cron fire; call it directly to trigger on demand.\n\t */\n\trunSchedule: (name: string) => Promise<void>;\n\t/** Registered schedules (name + cron pattern) — used by the `scheduled` plugin. */\n\tlistSchedules: () => ScheduleDefinition[];\n\t/**\n\t * Open a live subscription: authorize, hydrate the initial set, and stream\n\t * diffs as changes arrive. Rejects with {@link UnauthorizedError} on deny.\n\t */\n\tsubscribe: <T, P = void, Ctx = CollectionContext>(\n\t\targs: SubscribeArgs<T, P, Ctx>\n\t) => Promise<Subscription<T>>;\n\t/**\n\t * One-shot read: authorize and return a collection's current rows without\n\t * subscribing. Powers an Eden-typed HTTP hydrate route (and SSR). Rejects\n\t * with {@link UnauthorizedError} on deny.\n\t *\n\t * Pass `options.signal` (1.15.0+) to cancel the operation mid-flight —\n\t * the engine throws {@link AbortError} after the next await point if\n\t * the signal has fired.\n\t */\n\thydrate: (\n\t\tcollection: string,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\toptions?: { signal?: AbortSignal }\n\t) => Promise<unknown[]>;\n\t/**\n\t * Feed a committed change to `table` into the engine, fanning the resulting\n\t * diff to every live subscription of every collection that reads that table.\n\t * Call after a mutation, or wire a {@link ChangeSource} via `connectSource`.\n\t * Single-table subscriptions diff the row; multi-table / refetch ones\n\t * re-hydrate.\n\t */\n\tapplyChange: <T>(table: string, change: RowChange<T>) => Promise<void>;\n\t/**\n\t * Connect a change source (e.g. a CDC adapter): its emitted changes flow into\n\t * `applyChange`. Resolves to a disconnect function that stops the source.\n\t */\n\tconnectSource: (source: ChangeSource) => Promise<() => Promise<void>>;\n\t/**\n\t * Join a cluster (see {@link ClusterBus}): broadcast this instance's committed\n\t * changes to peers and apply theirs locally, so subscribers on every instance\n\t * stay live. Resolves to a disconnect function. Run once per instance.\n\t */\n\tconnectCluster: (bus: ClusterBus) => Promise<() => Promise<void>>;\n\t/** Active subscription count, optionally for one collection. */\n\tsubscriptionCount: (collection?: string) => number;\n\t/** Register a mutation definition (see {@link defineMutation}). */\n\tregisterMutation: <Args, Ctx = CollectionContext, Result = unknown>(\n\t\tmutation: MutationDefinition<Args, Ctx, Result>\n\t) => void;\n\t/**\n\t * Register how to persist a `table` (any ORM), so a mutation's\n\t * `actions.insert/update/delete` write to your store and emit the live change\n\t * in one step — you can't write without going live. See {@link TableWriter}.\n\t */\n\tregisterWriter: <Row = unknown, Ctx = CollectionContext, Tx = unknown>(\n\t\ttable: string,\n\t\twriter: TableWriter<Row, Ctx, Tx>\n\t) => void;\n\t/**\n\t * Register a read-set-tracked reactive query (see {@link defineReactiveQuery}):\n\t * it re-runs and re-pushes whenever any table it read changes — no `match`, no\n\t * operator graph, no manual change emission.\n\t */\n\tregisterReactive: <T, P = void, Ctx = CollectionContext>(\n\t\tquery: ReactiveQueryDefinition<T, P, Ctx>\n\t) => void;\n\t/**\n\t * Teach the engine how to read a table for reactive queries' `ctx.db` (any\n\t * ORM). Required for every table a reactive query reads.\n\t */\n\tregisterReader: <Ctx = CollectionContext>(\n\t\ttable: string,\n\t\treader: TableReader<Ctx>\n\t) => void;\n\t/**\n\t * Register declarative, row-level permissions for a `table` (see\n\t * {@link definePermissions}). Read rules filter every row the engine emits for\n\t * the table; write rules gate `actions.insert/update/delete`. Equivalent to a\n\t * `permissions` entry on {@link createSyncEngine}.\n\t */\n\tregisterPermissions: <Row = unknown, Ctx = CollectionContext>(\n\t\ttable: string,\n\t\trules: TablePermissions<Row, Ctx>\n\t) => void;\n\t/**\n\t * Register a `table`'s schema (see {@link defineSchema}): writes are validated\n\t * against it (a bad write rejects the mutation with {@link SchemaError}), and\n\t * its `migrate` lazily upcasts rows on read. Equivalent to a `schemas` entry\n\t * on {@link createSyncEngine}.\n\t */\n\tregisterSchema: <Row = unknown>(\n\t\ttable: string,\n\t\tschema: TableSchema<Row>\n\t) => void;\n\t/**\n\t * Declare which fields on a `table` are CRDT values (see {@link CrdtMergeable}\n\t * — e.g. `rgaText` from `@absolutejs/sync/crdt`, or `yjsText` from\n\t * `@absolutejs/sync-yjs`). The engine then MERGES those fields on\n\t * `actions.insert/update` instead of overwriting them, so concurrent writers\n\t * converge with no clobbering — conflict-free collaborative editing with no\n\t * merge code in your mutation. It also registers a ready-made\n\t * `\"<table>:merge\"` mutation that upserts a row patch, so a client (e.g. the\n\t * `useCollaborativeText` framework hooks) needs no custom server mutation.\n\t */\n\tregisterCrdt: <Row = Record<string, unknown>>(\n\t\ttable: string,\n\t\tfields: CrdtFields<Row>\n\t) => void;\n\t/**\n\t * Apply a table's schema `migrate` to a raw/stored row (identity when there's\n\t * no schema or migration). Use it wherever you read raw rows the engine\n\t * doesn't (e.g. a search collection's `source`); the engine already migrates\n\t * reactive `ctx.db` reads, view hydrates, and the one-shot hydrate.\n\t */\n\tmigrate: <Row = unknown>(table: string, row: Row) => Row;\n\t/**\n\t * Run a registered mutation: authorize, invoke its handler (which writes and\n\t * emits changes via `applyChange`), and resolve with the handler's result.\n\t * Rejects with {@link UnauthorizedError} on deny, or an error for an unknown\n\t * mutation / a handler throw. Drive this from the transport's mutate frame.\n\t */\n\trunMutation: (\n\t\tname: string,\n\t\targs: unknown,\n\t\tctx: unknown\n\t) => Promise<unknown>;\n\t/**\n\t * Atomically run N mutations in a single transaction (sync 1.11+).\n\t * Each `{ name, args }` spec is authorized, then handlers fire in\n\t * order against shared buffered changes. If any handler throws, the\n\t * entire transaction rolls back — no partial commits, no fanned-out\n\t * diffs. On success the accumulated changes apply as ONE live batch\n\t * and the per-mutation results return in order.\n\t *\n\t * No retry policy applies to batches in v0.2; configure per-mutation\n\t * retries on individual `runMutation` calls when atomicity isn't\n\t * needed. A failed batch passes the original error through with no\n\t * wrapping.\n\t *\n\t * Requires `transaction` to be set in {@link SyncEngineOptions} for\n\t * actual DB-level atomicity; without it the batch still buffers\n\t * changes into one fan-out but the underlying adapter writes\n\t * piecemeal.\n\t */\n\trunMutations: (\n\t\tspecs: Array<{ name: string; args: unknown }>,\n\t\tctx: unknown\n\t) => Promise<unknown[]>;\n\t/**\n\t * A point-in-time snapshot of the engine for devtools: registered collections\n\t * (+ kind, tables, live subscription counts), mutations, schedules, readers,\n\t * writers, the change-feed version, and recent changes. See `syncDevtools`.\n\t */\n\tinspect: () => EngineInspection;\n\t/**\n\t * Operator-shaped engine metrics — counters + memory estimates + throughput\n\t * totals since engine start. Distinct from {@link SyncEngine.inspect}: this\n\t * is what a PaaS host scrapes on an interval to answer \"is this engine\n\t * healthy\" and \"what's its resource footprint.\" Feed it to\n\t * `@absolutejs/metering` for per-engine cost attribution.\n\t *\n\t * Added in 1.13.0.\n\t */\n\tmetrics: () => EngineMetrics;\n\t/**\n\t * Capture the engine's change log + version as a serializable\n\t * {@link ChangeLogSnapshot} the host can persist (disk, S3, the cluster\n\t * bus) and restore on the next boot via\n\t * {@link SyncEngineOptions.initialChangeLog} or\n\t * {@link SyncEngine.importChangeLog}. The receiving engine MUST share this\n\t * engine's `instanceId` — otherwise the resume contract silently breaks.\n\t *\n\t * Cheap: the snapshot's `entries` is a shallow copy of the bounded log\n\t * (capped by `changeLogSize` / `changeLogRetainMs`). Call on a timer or on\n\t * graceful shutdown — both are fine; the snapshot is monotonic in commit\n\t * order, so a partial roll-forward (apply entries newer than the snapshot\n\t * from another source) is safe.\n\t *\n\t * Added in 1.19.0.\n\t */\n\texportChangeLog: () => ChangeLogSnapshot;\n\t/**\n\t * Adopt a {@link ChangeLogSnapshot} into a running engine that has not yet\n\t * committed any local changes (its `version` is 0). The snapshot's\n\t * `instanceId` MUST match this engine's `instanceId`. Throws otherwise.\n\t *\n\t * Convenience for hosts that want to set up the engine, register surfaces,\n\t * AND THEN restore. Equivalent to passing the snapshot via\n\t * `createSyncEngine({ initialChangeLog })` if you have it at construction\n\t * time. Returns the number of entries imported.\n\t *\n\t * Added in 1.19.0.\n\t */\n\timportChangeLog: (snapshot: ChangeLogSnapshot) => number;\n\t/**\n\t * Reconstruct the state of registered tables as of a target\n\t * timestamp by walking the change log forward and folding each op\n\t * into a per-table view. Useful for forensic incident response\n\t * (\"what did the tenant see at 14:32?\") and the \"I deleted prod\n\t * — restore us to 2h ago\" recovery story.\n\t *\n\t * The reconstruction is exact when the log spans `targetAt` (i.e.\n\t * the log's oldest entry is at version 1). When the log has been\n\t * trimmed (`changeLogSize` / `changeLogRetainMs` evicted older\n\t * entries) AND `targetAt` falls in the gap, the result is\n\t * best-effort: state walked forward from the OLDEST retained\n\t * entry, with `truncated: true` so the caller knows.\n\t *\n\t * Added in 1.22.0.\n\t *\n\t * @example\n\t * ```ts\n\t * const twoHoursAgo = Date.now() - 2 * 60 * 60 * 1000;\n\t * const result = await engine.replayTo({ at: twoHoursAgo, tables: ['orders'] });\n\t * if (result.truncated) {\n\t * console.warn('Replay truncated — log retention window too short.');\n\t * }\n\t * console.log(result.rows.orders); // orders as of two hours ago\n\t * ```\n\t */\n\treplayTo: (options: ReplayOptions) => Promise<ReplayResult>;\n\t/**\n\t * Pause new mutations on the engine — the source half of the G7 tenant\n\t * migration contract. While at least one fence is held, `runMutation`\n\t * rejects with {@link EngineFencedError}; subscribe/hydrate continue to\n\t * work, so live readers stay served while the snapshot is in flight.\n\t *\n\t * Multiple fence handles compose — the engine stays fenced until every\n\t * handle has been `lift()`-ed. Lifting is idempotent.\n\t *\n\t * Out of scope: out-of-band writes (CDC drivers, raw SQL). The caller\n\t * is responsible for halting those before fencing, otherwise the\n\t * snapshot will drift between `exportSnapshot` and import on the target.\n\t *\n\t * Added in 1.24.0.\n\t */\n\tfence: (options: { reason: string }) => FenceHandle;\n\t/**\n\t * Capture the engine's current per-table state into a portable\n\t * {@link EngineSnapshot}. Walks every registered reader's `all(ctx)`\n\t * and collects the rows. Used to ship a tenant between engines (G7).\n\t *\n\t * Pair with `fence()` on the source to stop drift, then\n\t * `importSnapshot()` on the target. The shape is intentionally\n\t * detached from `ChangeLogSnapshot` — snapshots carry live state, not\n\t * history. Use `exportChangeLog()` separately if you need forensic\n\t * continuity at the target instanceId.\n\t *\n\t * Added in 1.24.0.\n\t *\n\t * @example\n\t * const fence = source.fence({ reason: 'tenant move' });\n\t * try {\n\t * const snapshot = await source.exportSnapshot();\n\t * await target.importSnapshot(snapshot);\n\t * } finally { fence.lift(); }\n\t */\n\texportSnapshot: (\n\t\toptions?: ExportSnapshotOptions\n\t) => Promise<EngineSnapshot>;\n\t/**\n\t * Bulk-load an {@link EngineSnapshot} into this engine via each table's\n\t * registered writer. Tables present in the snapshot but missing a\n\t * writer here are surfaced in `result.skipped` so the operator can\n\t * detect a misconfigured target. The target half of the G7 migration\n\t * contract.\n\t *\n\t * Inserts do NOT emit change events to subscribers — the import is\n\t * meant to land on a fresh target whose clients will re-hydrate after\n\t * the DNS cutover. If you need to fan changes out (e.g. mid-flight\n\t * cutover), drain the change log via `streamChanges()` and\n\t * `applyChange()` separately.\n\t *\n\t * Added in 1.24.0.\n\t */\n\timportSnapshot: (\n\t\tsnapshot: EngineSnapshot,\n\t\toptions?: ImportSnapshotOptions\n\t) => Promise<MigrationImportResult>;\n\t/**\n\t * Subscribe to the live engine activity stream (changes, mutation outcomes,\n\t * subscribe/unsubscribe). Returns an unsubscribe. Powers the devtools feed.\n\t */\n\tonActivity: (listener: (event: EngineActivity) => void) => () => void;\n\t/**\n\t * Outbound CDC stream — yield every committed change as a {@link LoggedChange},\n\t * historical first (entries with `version > since`) then continuously tailing\n\t * live commits. Use it to feed downstream pipelines (Kafka, search indexers,\n\t * audit logs, analytics warehouses).\n\t *\n\t * The iterator is notify-driven (no polling): it parks on a Promise that\n\t * resolves the instant a new commit lands.\n\t *\n\t * If `since` falls before the oldest entry retained in the bounded change\n\t * log, the iterator throws {@link MissedChangesError} so the consumer\n\t * notices the gap instead of silently skipping commits. Resubscribe with\n\t * `since = engine.inspect().recentChanges[0].version` after re-bootstrapping.\n\t *\n\t * If the consumer iterates slower than the engine commits and the in-flight\n\t * buffer overflows (`maxBuffer`, default 10000), the iterator throws\n\t * {@link CdcConsumerSlowError} for the same reason.\n\t *\n\t * @example\n\t * for await (const entry of engine.streamChanges({ since: lastCursor })) {\n\t * await kafka.send('sync.changes', JSON.stringify(entry));\n\t * lastCursor = entry.version;\n\t * }\n\t */\n\tstreamChanges: (\n\t\toptions?: StreamChangesOptions\n\t) => AsyncIterable<LoggedChange>;\n\t/**\n\t * Register a {@link SyncPack} — a self-contained bundle of schemas,\n\t * permissions, readers/writers, collections, mutations, and schedules.\n\t * Dispatches each field to the matching `register*` method. Rejects\n\t * with {@link PackTableConflictError} if the pack claims a table\n\t * another registered pack already owns; with\n\t * {@link PackMissingDependencyError} if `requireDependencies` is set\n\t * and a `readsTables` entry has no registered reader.\n\t *\n\t * See `syncPacks.design.md` for the rationale.\n\t */\n\tregisterPack: (pack: SyncPack) => void;\n};\n\n/**\n * 1.18.0: `OnDiff` receives an opaque `cursor` string alongside the version.\n * The cursor is the engine's cross-instance resume cursor as of this batch\n * — the connection layer forwards it to the client on the wire so a\n * reconnect can resume across shards. Pre-1.18 callers that ignore the 3rd\n * arg keep working unchanged.\n */\ntype OnDiff = (\n\tdiff: ViewDiff<unknown>,\n\tversion: number,\n\tcursor?: string\n) => void;\n\ntype JoinState = {\n\top: EquiJoin<unknown, unknown, unknown>;\n\tleftTable: string;\n\trightTable: string;\n\t/** Per-side filters (bound to params/ctx) — a failing change leaves the join. */\n\tleftMatch?: (row: unknown) => boolean;\n\trightMatch?: (row: unknown) => boolean;\n};\n\ntype ActiveSubscription =\n\t| {\n\t\t\tkind: 'view';\n\t\t\tcollection: string;\n\t\t\tview: MaterializedView<unknown>;\n\t\t\t/** Incremental (has a predicate) vs refetch fallback. */\n\t\t\tincremental: boolean;\n\t\t\t/** Re-run the bound hydrate for the refetch fallback. */\n\t\t\trehydrate: () => Promise<Iterable<unknown>>;\n\t\t\t/** Result-row identity (used to net a batch's diffs). */\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'join';\n\t\t\tcollection: string;\n\t\t\tjoin: JoinState;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'graph';\n\t\t\tcollection: string;\n\t\t\tinstance: GraphInstance<unknown>;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'reactive';\n\t\t\tcollection: string;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\t/** Re-run; returns the new rows and the read set (tables/keys/ranges). */\n\t\t\trerun: () => Promise<{\n\t\t\t\trows: unknown[];\n\t\t\t\treadTables: Set<string>;\n\t\t\t\treadKeys: Set<string>;\n\t\t\t\trangeDeps: RangeDep[];\n\t\t\t}>;\n\t\t\t/**\n\t\t\t * Stable key over `(collection, params, ctx)`. Subscriptions sharing\n\t\t\t * the same key are equivalent on the read side, so a single rerun\n\t\t\t * per change batch can serve all of them (see `reactivePairs`).\n\t\t\t */\n\t\t\trerunKey: string;\n\t\t\t/** Current result set, keyed (diffed against the next re-run). */\n\t\t\tcurrent: Map<RowKey, unknown>;\n\t\t\t/** Full-table dependencies (from `db.all`). */\n\t\t\treadTables: Set<string>;\n\t\t\t/** Row-level dependencies `table\\0key` (from `db.get`). */\n\t\t\treadKeys: Set<string>;\n\t\t\t/** Range dependencies (from `db.where`) — predicate + matched keys. */\n\t\t\trangeDeps: RangeDep[];\n\t\t\tonDiff: OnDiff;\n\t }\n\t| {\n\t\t\tkind: 'search';\n\t\t\tcollection: string;\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\t/** Re-run the search against the (now-updated) shared index. */\n\t\t\trerun: () => unknown[];\n\t\t\t/** Current ranked result set, keyed (diffed against the next re-run). */\n\t\t\tcurrent: Map<RowKey, unknown>;\n\t\t\tonDiff: OnDiff;\n\t };\n\n/** A `db.where` dependency: the predicate plus the keys that matched at read. */\ntype RangeDep = {\n\ttable: string;\n\tpredicate: (row: unknown) => boolean;\n\tkeys: Set<RowKey>;\n};\n\n/**\n * A single committed change as it appears in the engine's change log and on\n * the {@link SyncEngine.streamChanges} CDC stream. Versions are monotonic\n * across the engine: a single mutation that writes N rows emits N entries\n * all sharing the same `version`.\n */\nexport type LoggedChange = {\n\t/** This engine's local monotonic version when the change was logged. */\n\tversion: number;\n\ttable: string;\n\tchange: RowChange<unknown>;\n\t/**\n\t * Wall-clock when this change was logged (Date.now()). Used by the\n\t * engine's time-based retention sweep (`changeLogRetainMs`) and\n\t * surfaced as the change-log age in {@link SyncEngine.metrics}.\n\t * Added in 1.13.0; pre-1.13.0 consumers of `LoggedChange` ignore it.\n\t */\n\tat: number;\n\t/**\n\t * Instance id that originated this change. For locally-committed changes\n\t * this is the engine's own `instanceId`; for cluster-received changes,\n\t * the originating peer's id.\n\t *\n\t * Added in 1.17.0; pre-1.17 consumers ignore it.\n\t */\n\torigin: string;\n\t/**\n\t * The ORIGINATOR's local version at commit time. For locally-committed\n\t * changes this equals `version`; for cluster-received changes, the\n\t * peer's version. Resume cursors (1.17.0+) carry `(origin, originVersion)`\n\t * pairs so a client's last-seen point matches against peer entries this\n\t * engine has logged via the bus.\n\t *\n\t * Added in 1.17.0; pre-1.17 consumers ignore it.\n\t */\n\toriginVersion: number;\n};\n\n/** Thrown by {@link SyncEngine.streamChanges} when `since` is older than the\n * oldest entry retained in the bounded change log (i.e. the consumer was\n * disconnected long enough that the engine has lost the diff). The consumer\n * should re-bootstrap from a fresh hydrate and resume from `availableSince`. */\nexport class MissedChangesError extends Error {\n\treadonly requestedSince: number;\n\treadonly availableSince: number;\n\tconstructor(requestedSince: number, availableSince: number) {\n\t\tsuper(\n\t\t\t`Change log no longer covers version ${requestedSince}; oldest available is ${availableSince}. ` +\n\t\t\t\t`Re-bootstrap and resume from ${availableSince}.`\n\t\t);\n\t\tthis.name = 'MissedChangesError';\n\t\tthis.requestedSince = requestedSince;\n\t\tthis.availableSince = availableSince;\n\t}\n}\n\n/** Options for {@link SyncEngine.streamChanges}. */\nexport type StreamChangesOptions = {\n\t/**\n\t * Last version the consumer has already processed. The stream yields\n\t * entries with `version > since`. Defaults to `0` (replay everything in\n\t * the log, then tail).\n\t */\n\tsince?: number;\n\t/**\n\t * Cancel the stream cleanly. When the signal aborts, the iterator\n\t * resolves to `done` on its next yield and unregisters its subscriber.\n\t */\n\tsignal?: AbortSignal;\n\t/**\n\t * Hard cap on the in-flight buffer for this consumer. If the engine\n\t * commits faster than the consumer iterates and the buffer overflows,\n\t * the stream rejects so the consumer notices instead of silently\n\t * skipping entries. Defaults to 10000.\n\t */\n\tmaxBuffer?: number;\n};\n\n/** Thrown by {@link SyncEngine.streamChanges} when the consumer fell so far\n * behind that the in-flight buffer overflowed. Resubscribe from the last\n * cursor the consumer successfully processed. */\nexport class CdcConsumerSlowError extends Error {\n\treadonly maxBuffer: number;\n\treadonly lastDeliveredVersion: number;\n\tconstructor(maxBuffer: number, lastDeliveredVersion: number) {\n\t\tsuper(\n\t\t\t`CDC stream buffer overflowed (max ${maxBuffer}); consumer fell behind. ` +\n\t\t\t\t`Last delivered version: ${lastDeliveredVersion}. Resubscribe with since=${lastDeliveredVersion}.`\n\t\t);\n\t\tthis.name = 'CdcConsumerSlowError';\n\t\tthis.maxBuffer = maxBuffer;\n\t\tthis.lastDeliveredVersion = lastDeliveredVersion;\n\t}\n}\n\n/**\n * Thrown by `runMutation` / `runMutations` when `mutationConcurrency` is\n * saturated AND the waiting queue is already at `mutationQueueLimit`. The\n * caller sees this immediately (no queue time) so the host can shed load\n * with a clean 429 instead of letting the queue grow unboundedly. Added\n * in 1.20.0.\n */\nexport class MutationQueueOverflowError extends Error {\n\treadonly queueLimit: number;\n\tconstructor(queueLimit: number) {\n\t\tsuper(\n\t\t\t`Mutation queue overflowed (limit ${queueLimit}); the engine is at ` +\n\t\t\t\t`its mutationConcurrency cap and the waiting queue is full. ` +\n\t\t\t\t`Retry later or shed load at the gateway.`\n\t\t);\n\t\tthis.name = 'MutationQueueOverflowError';\n\t\tthis.queueLimit = queueLimit;\n\t}\n}\n\n/**\n * Thrown by `engine.subscribe` when the calling tenant's active-subscription\n * count is already at the configured `subscriptionLimit.max`. The caller sees\n * this immediately — BEFORE authorize, hydrate, or any subscription state\n * allocation — so a rejected call leaks nothing. Added in 1.20.1.\n */\nexport class SubscriptionLimitError extends Error {\n\treadonly tenantKey: string;\n\treadonly limit: number;\n\treadonly active: number;\n\tconstructor(tenantKey: string, limit: number, active: number) {\n\t\tsuper(\n\t\t\t`Tenant \"${tenantKey}\" is at the subscription cap ` +\n\t\t\t\t`(${active}/${limit}). Close an existing subscription before opening another.`\n\t\t);\n\t\tthis.name = 'SubscriptionLimitError';\n\t\tthis.tenantKey = tenantKey;\n\t\tthis.limit = limit;\n\t\tthis.active = active;\n\t}\n}\n\n/**\n * Serializable snapshot of an engine's change log + monotonic version, returned\n * by {@link SyncEngine.exportChangeLog} and consumed by\n * {@link SyncEngineOptions.initialChangeLog} or\n * {@link SyncEngine.importChangeLog}.\n *\n * The PaaS host persists this on shard rotation (every N seconds or on graceful\n * shutdown) and hands it back to the replacement engine so resume cursors\n * referencing this `instanceId` keep working past the restart. Bounded by the\n * receiving engine's `changeLogSize` + `changeLogRetainMs` policies — entries\n * that exceed either cap on import are trimmed exactly as if they had been\n * logged live.\n *\n * Added in 1.19.0.\n */\nexport type ChangeLogSnapshot = {\n\t/** The exporting engine's `instanceId`. Receiver MUST match. */\n\tinstanceId: string;\n\t/** The exporting engine's monotonic version at snapshot time. */\n\tversion: number;\n\t/** Every retained log entry, in commit order (oldest first). */\n\tentries: ReadonlyArray<LoggedChange>;\n\t/**\n\t * Optional version-stamp the host may use to compare snapshots without\n\t * deserializing the entries (e.g. for incremental persistence). Set to\n\t * `Date.now()` at export time. Receivers ignore this field.\n\t */\n\texportedAt?: number;\n};\n\n/**\n * Options for {@link SyncEngine.replayTo}. Added in 1.22.0.\n */\nexport type ReplayOptions = {\n\t/**\n\t * Target timestamp (`Date.now()`-shaped). The engine walks the\n\t * change log forward, applying entries with `at <= targetAt`. The\n\t * result is the state as-of `targetAt` (or as close as the log\n\t * permits — see `truncated`).\n\t */\n\tat: number;\n\t/**\n\t * Optional table filter. When set, only entries whose `table` is\n\t * in this list are folded into the result; entries for other\n\t * tables are skipped. Useful for \"show me what `tasks` looked\n\t * like at T\" without paying to reconstruct every table.\n\t */\n\ttables?: ReadonlyArray<string>;\n};\n\n/**\n * Returned by {@link SyncEngine.replayTo}. Added in 1.22.0.\n *\n * - `rows` — per-table arrays of rows that existed as of `asOfAt`.\n * Keys are table names; values are the row objects (in last-write\n * order — last write wins for duplicate-keyed inserts).\n * - `asOfVersion` / `asOfAt` — the version + wall-clock of the LAST\n * entry folded into the result. May be earlier than `targetAt` if\n * no entries existed between the last-included entry and the\n * target.\n * - `truncated` — `true` when the log has been trimmed past the\n * target window (`changeLog[0].version > 1 && changeLog[0].at >\n * targetAt`). In this case, `rows` represents the state walked\n * forward from the OLDEST retained entry — NOT the actual state\n * at `targetAt`. The caller should treat the result as\n * \"best-effort given retention window\" and warn the operator.\n */\nexport type ReplayResult = {\n\tasOfVersion: number;\n\tasOfAt: number;\n\trows: Record<string, ReadonlyArray<unknown>>;\n\ttruncated: boolean;\n};\n\nexport type SyncEngineOptions = {\n\t/**\n\t * Stable identifier for this engine instance. Defaults to a per-process\n\t * random UUID. Pass a stable value (e.g. `${hostname}:${shardId}`) when\n\t * running a fleet of engines behind a cluster bus — 1.17.0+ resume\n\t * cursors carry the originating `instanceId`, so a client that reconnects\n\t * to a different shard can request a catch-up against the original's\n\t * change feed only if that instance's id matches a peer the new shard\n\t * knows about.\n\t */\n\tinstanceId?: string;\n\t/**\n\t * How many recent changes to retain for resumable reconnects. A client that\n\t * reconnects within this window gets a catch-up diff; beyond it, a fresh\n\t * snapshot. Defaults to 1024.\n\t */\n\tchangeLogSize?: number;\n\t/**\n\t * Time-based change-log retention: drop entries older than this many ms,\n\t * in addition to the count cap above. Lets a high-throughput engine keep\n\t * a SHORT log (e.g. \"60s of changes\") regardless of count, which both\n\t * bounds memory and bounds the catch-up work on reconnect. Defaults to\n\t * `null` — only the count cap (`changeLogSize`) applies.\n\t *\n\t * Added in 1.13.0.\n\t */\n\tchangeLogRetainMs?: number | null;\n\t/**\n\t * Run every mutation inside your database's transaction (see\n\t * {@link TransactionRunner}): the handler's writes commit all-or-nothing, and\n\t * the engine emits the resulting diff only after the commit. Omit to run\n\t * mutations without a transaction (each writer call is its own DB op).\n\t */\n\ttransaction?: TransactionRunner;\n\t/**\n\t * Declarative, row-level permissions keyed by table (see\n\t * {@link definePermissions}). Read rules filter every row the engine emits;\n\t * write rules gate `actions.insert/update/delete`. Add more later with\n\t * {@link SyncEngine.registerPermissions}. Type the rules at the\n\t * `definePermissions<YourCtx>(...)` call site; the engine accepts any context\n\t * (it threads `ctx` untyped to your rules).\n\t */\n\tpermissions?: PermissionsDefinition<any>;\n\t/**\n\t * Declarative row schemas keyed by table (see {@link defineSchema}): writes\n\t * are validated against them, and `migrate` lazily upcasts rows on read. Add\n\t * more later with {@link SyncEngine.registerSchema}.\n\t */\n\tschemas?: SchemaDefinition;\n\t/**\n\t * Cross-client cache for reactive query results, keyed by\n\t * `(collection, params, ctx)` — equivalent subscribers reuse a single\n\t * cached snapshot on initial subscribe instead of each re-running the\n\t * query body. Per-batch dedup (already in `reactivePairs` since 1.1) is\n\t * unchanged; this adds *cross-batch* sharing.\n\t *\n\t * Entries are invalidated when a write overlaps their read set (same\n\t * `isReactiveAffected` check live subscriptions use), and bounded by an\n\t * LRU + an optional TTL.\n\t *\n\t * Defaults: `{ max: 256, ttlMs: 60_000 }`. Pass `{ max: 0 }` to disable.\n\t */\n\treactiveCache?: {\n\t\tmax?: number;\n\t\tttlMs?: number;\n\t};\n\t/**\n\t * Per-call telemetry for `sandboxedHandler` mutations. When set, every\n\t * sandboxed call fires `onMetrics(record)` after completion with\n\t * `{ id, mutationName, durationMs, cpuMs, heapBytes, ok, errorName,\n\t * errorMessage, timestamp }`. Wire to a sync collection, your\n\t * observability backend, a Drizzle table, anything you want.\n\t *\n\t * Hook failures are swallowed (a misbehaving metrics sink must NOT\n\t * crash the caller's mutation). Adding the hook switches the runner\n\t * to `callable.callWithMetrics`, which is a small per-call cost\n\t * (~0.05 ms) — disable for hot-path mutations that don't need it.\n\t *\n\t * Off by default.\n\t *\n\t * @see {@link HandlerMetricsRecord}\n\t */\n\thandlerMetrics?: HandlerMetricsHook;\n\t/**\n\t * Allowlist + auth-injection map for `actions.fetch(url, init)` calls\n\t * issued from inside a `sandboxedHandler`. Each entry is keyed by\n\t * hostname (`'api.stripe.com'`); the value's `authorization` is a\n\t * sync or async callback computed on the host so the secret never\n\t * crosses into the JSC sandbox. Requests to non-allowlisted hosts\n\t * are rejected before any network call.\n\t *\n\t * Without this set, `actions.fetch` throws \"no bridgeFetch config.\"\n\t * Plain (non-sandboxed) handlers don't use this — they can just call\n\t * `fetch` directly since they run in the host process.\n\t *\n\t * @see {@link BridgeFetchConfig}\n\t */\n\tbridgeFetch?: BridgeFetchConfig;\n\t/**\n\t * Seed the engine's change log on boot from a prior snapshot — produced by\n\t * {@link SyncEngine.exportChangeLog} on the previous instance, persisted by\n\t * the host across a shard reboot, then handed back here. Cursors that\n\t * referenced this engine's `instanceId` stay resumable past the restart\n\t * (provided their last-seen point still lives in the retained log).\n\t *\n\t * The snapshot's `instanceId` MUST match `options.instanceId` (otherwise\n\t * `createSyncEngine` throws — a wrong-id restore would silently break the\n\t * resume contract). Snapshot `version` becomes this engine's local\n\t * monotonic version; entries are inserted in version order. Subscribers,\n\t * permissions, schemas, schedules, packs, mutations, and the reactive\n\t * cache are NOT in the snapshot — re-register them as normal after\n\t * `createSyncEngine` returns. Added in 1.19.0.\n\t */\n\tinitialChangeLog?: ChangeLogSnapshot;\n\t/**\n\t * Maximum concurrent in-flight mutations (`runMutation` + `runMutations`).\n\t * Calls beyond the limit wait in a FIFO queue and run as slots free up;\n\t * `engine.metrics().mutations.queued` surfaces the queue depth.\n\t *\n\t * A single tenant flooding `runMutation` can otherwise drive unbounded\n\t * memory growth (per-mutation `actions` buffers, retry timers, sandbox\n\t * invocations queued against the isolate pool). Set this to a value\n\t * appropriate for the host's tenant tier — e.g. `32` for a free tier,\n\t * `256` for paid. Without this option the engine is unbounded\n\t * (matching pre-1.20 behavior).\n\t *\n\t * Sandboxed mutations are gated by the same semaphore. If you need\n\t * finer-grained control (sandbox-only throttling), see\n\t * `@absolutejs/isolated-jsc`'s pool size — that's the lower layer.\n\t *\n\t * Added in 1.20.0.\n\t */\n\tmutationConcurrency?: number;\n\t/**\n\t * Cap on the queue of waiting mutations once `mutationConcurrency` is\n\t * saturated. Calls beyond this cap throw {@link MutationQueueOverflowError}\n\t * immediately instead of queueing — the host can surface a clean 429 or\n\t * apply a tenant-specific shed policy. Defaults to unbounded (queue\n\t * never rejects). Only meaningful when `mutationConcurrency` is set.\n\t *\n\t * Added in 1.20.0.\n\t */\n\tmutationQueueLimit?: number;\n\t/**\n\t * Per-tenant active-subscription cap. Symmetric to\n\t * {@link SyncEngineOptions.mutationConcurrency} on the read side: a\n\t * single tenant opening thousands of subscriptions would otherwise\n\t * exhaust the engine's per-subscription bookkeeping\n\t * (`active`/`tableIndex` Maps, the reactive cache, per-row diff\n\t * computation cost).\n\t *\n\t * `key` derives a tenant identifier from `(ctx, args)`; returning\n\t * `undefined` skips the cap for that call (e.g. internal/system\n\t * subscriptions). When the active count for a key reaches `max`, the\n\t * next `subscribe` throws {@link SubscriptionLimitError} BEFORE any\n\t * authorize, hydrate, or state allocation — so a denied call leaks\n\t * nothing.\n\t *\n\t * Active counts are surfaced through `engine.metrics().subscriptions.byTenant`\n\t * for tier monitoring. Added in 1.20.1.\n\t */\n\tsubscriptionLimit?: {\n\t\tmax: number;\n\t\tkey: (ctx: unknown, args: { collection: string }) => string | undefined;\n\t};\n\t/**\n\t * Optional OpenTelemetry tracer provider. When set, the engine\n\t * wraps `subscribe`, `runMutation`, `runMutations`, and cluster\n\t * fan-out in spans named `sync.<op>` with `ABS_ATTRS` semantic\n\t * conventions (`abs.engine.id`, `abs.collection`, `abs.mutation`,\n\t * etc.). When absent, all tracing is a zero-allocation noop —\n\t * existing call sites pay nothing. Added in 1.21.0.\n\t *\n\t * Pass any `@opentelemetry/api`-compatible `TracerProvider`. See\n\t * `@absolutejs/telemetry` for the type shape — sync re-uses its\n\t * helpers but doesn't peer-dep `@opentelemetry/api` directly.\n\t *\n\t * @example\n\t * ```ts\n\t * import { NodeTracerProvider } from '@opentelemetry/sdk-node';\n\t * const tp = new NodeTracerProvider({ ... });\n\t * tp.register();\n\t * const engine = createSyncEngine({ tracerProvider: tp });\n\t * ```\n\t */\n\ttracerProvider?: TelemetryTracerProvider;\n};\n\nconst defaultKey = (row: unknown): RowKey => (row as { id: RowKey }).id;\n\nconst shallowEqual = (a: unknown, b: unknown): boolean => {\n\tif (a === b) {\n\t\treturn true;\n\t}\n\tif (\n\t\ttypeof a !== 'object' ||\n\t\ttypeof b !== 'object' ||\n\t\ta === null ||\n\t\tb === null\n\t) {\n\t\treturn false;\n\t}\n\tconst aKeys = Object.keys(a);\n\tconst bKeys = Object.keys(b);\n\treturn (\n\t\taKeys.length === bKeys.length &&\n\t\taKeys.every(\n\t\t\t(k) =>\n\t\t\t\t(a as Record<string, unknown>)[k] ===\n\t\t\t\t(b as Record<string, unknown>)[k]\n\t\t)\n\t);\n};\n\n/**\n * Per-object stable identifier — paired with {@link stableSubKey} so two\n * subscriptions that share the same `(collection, params, ctx)` get the same\n * key and have their reactive rerun deduplicated within a change batch (the\n * fan-out fix in {@link reactivePairs}). Falls back to an incrementing id\n * stored on a WeakMap for values JSON can't represent (functions, classes,\n * cyclic structures), so identity-equal ctxs still share a key while\n * different-identity ones don't accidentally merge.\n */\nconst subKeyIds = new WeakMap<object, string>();\nlet subKeyCounter = 0;\nconst stableValueKey = (value: unknown): string => {\n\tif (value === undefined) return 'u';\n\tif (value === null) return 'n';\n\tconst tag = typeof value;\n\tif (tag === 'string') return `s:${value as string}`;\n\tif (tag === 'number' || tag === 'boolean' || tag === 'bigint') {\n\t\treturn `${tag[0]}:${String(value)}`;\n\t}\n\tif (tag !== 'object') return `${tag[0]}:fn`;\n\ttry {\n\t\t// Stable ordering: sort keys before serialising so { a, b } and { b, a }\n\t\t// produce the same string. JSON.stringify with a replacer keeps it tight.\n\t\treturn `o:${JSON.stringify(value, (_k, v): unknown => {\n\t\t\tif (v === null || typeof v !== 'object' || Array.isArray(v))\n\t\t\t\treturn v;\n\t\t\tconst record = v as Record<string, unknown>;\n\t\t\tconst sorted: Record<string, unknown> = {};\n\t\t\tfor (const key of Object.keys(record).sort()) {\n\t\t\t\tsorted[key] = record[key];\n\t\t\t}\n\n\t\t\treturn sorted;\n\t\t})}`;\n\t} catch {\n\t\t// Cyclic or unserializable — fall back to per-object identity.\n\t\tconst obj = value as object;\n\t\tlet id = subKeyIds.get(obj);\n\t\tif (id === undefined) {\n\t\t\tsubKeyCounter += 1;\n\t\t\tid = `i${subKeyCounter}`;\n\t\t\tsubKeyIds.set(obj, id);\n\t\t}\n\n\t\treturn `i:${id}`;\n\t}\n};\n\nconst stableSubKey = (\n\tcollection: string,\n\tparams: unknown,\n\tctx: unknown\n): string => `${collection}|${stableValueKey(params)}|${stableValueKey(ctx)}`;\n\n/** Shallow-equal ignoring the search score field — used to suppress re-emitting\n * a search result whose only change is BM25 score drift as the corpus grows. */\nconst equalsIgnoringScore = (a: unknown, b: unknown): boolean => {\n\tif (\n\t\ttypeof a !== 'object' ||\n\t\ttypeof b !== 'object' ||\n\t\ta === null ||\n\t\tb === null\n\t) {\n\t\treturn a === b;\n\t}\n\tconst strip = (value: Record<string, unknown>) =>\n\t\tObject.keys(value).filter((k) => k !== SEARCH_SCORE_FIELD);\n\tconst aKeys = strip(a as Record<string, unknown>);\n\tconst bKeys = strip(b as Record<string, unknown>);\n\treturn (\n\t\taKeys.length === bKeys.length &&\n\t\taKeys.every(\n\t\t\t(k) =>\n\t\t\t\t(a as Record<string, unknown>)[k] ===\n\t\t\t\t(b as Record<string, unknown>)[k]\n\t\t)\n\t);\n};\n\n/**\n * The Tier 3 sync engine: a registry of collections plus the view syncer. It is\n * transport-agnostic — `subscribe` returns the initial snapshot and an\n * `onDiff` stream, which an Elysia/SSE layer wires to a connection, and\n * `applyChange` is the change feed you drive from your mutations.\n *\n * Access control is first-class: every subscribe runs the collection's\n * `authorize`, and a collection's `match`/`hydrate` scope rows to the caller, so\n * a change to a row the caller can't see never reaches them.\n */\nexport const createSyncEngine = (\n\toptions: SyncEngineOptions = {}\n): SyncEngine => {\n\t// Heterogeneous registry: `any` here is what lets collections of different\n\t// row/param/context types share one map (the public `register`/`subscribe`\n\t// surface stays fully typed).\n\tconst registry = new Map<\n\t\tstring,\n\t\t| CollectionDefinition<any, any, any>\n\t\t| JoinCollectionDefinition<any, any, any, any, any>\n\t\t| GraphCollectionDefinition<any, any, any>\n\t\t| ReactiveQueryDefinition<any, any, any>\n\t\t| SearchCollectionDefinition<any, any, any>\n\t>();\n\tconst mutations = new Map<string, MutationDefinition<any, any, any>>();\n\t// Lazy sandbox runners keyed by mutation name. Built on first call to a\n\t// mutation that has `sandboxedHandler` set; reused thereafter. Engine has\n\t// no teardown; the OS reaps the isolate workers on process exit.\n\tconst sandboxRunners = new Map<\n\t\tstring,\n\t\t(\n\t\t\targs: unknown,\n\t\t\tctx: unknown,\n\t\t\tactions: MutationActions\n\t\t) => Promise<unknown>\n\t>();\n\tconst writers = new Map<string, TableWriter>();\n\tconst readers = new Map<string, TableReader>();\n\tconst schedules = new Map<string, ScheduleDefinition>();\n\t// Pack registry — table -> owning pack name, and the list of registered\n\t// packs for engine.inspect().packs.\n\tconst packTableOwners = new Map<string, string>();\n\tconst registeredPacks: RegisteredPack[] = [];\n\t// Declarative row-level permissions, keyed by table. Stored with an `unknown`\n\t// context — the engine threads ctx untyped — while the public\n\t// `definePermissions`/`registerPermissions` surface stays fully typed.\n\tconst permissions = new Map<string, TablePermissions<unknown, unknown>>();\n\tfor (const [table, rules] of Object.entries(options.permissions ?? {})) {\n\t\tpermissions.set(table, rules as TablePermissions<unknown, unknown>);\n\t}\n\tconst readRuleFor = (\n\t\ttable: string\n\t): ReadRule<unknown, unknown> | undefined => permissions.get(table)?.read;\n\tconst writeRuleFor = (\n\t\ttable: string,\n\t\top: 'insert' | 'update' | 'delete'\n\t): WriteRule<unknown, unknown> | undefined => {\n\t\tconst rules = permissions.get(table);\n\t\treturn rules?.[op] ?? rules?.write;\n\t};\n\t// Declarative row schemas, keyed by table.\n\tconst schemas = new Map<string, TableSchema<unknown>>();\n\tfor (const [table, schema] of Object.entries(options.schemas ?? {})) {\n\t\tschemas.set(table, schema as TableSchema<unknown>);\n\t}\n\t// CRDT fields, keyed by table: field name -> mergeable backend. Set via\n\t// registerCrdt; consulted in makeActions to merge (not overwrite) on write.\n\tconst crdtFields = new Map<\n\t\tstring,\n\t\tRecord<string, CrdtMergeable<unknown>>\n\t>();\n\t// Validate a write against its table's schema: every field on insert; only\n\t// the supplied fields on update. Throws SchemaError naming the bad field.\n\tconst validateWrite = (\n\t\ttable: string,\n\t\top: 'insert' | 'update',\n\t\trow: unknown\n\t) => {\n\t\tconst schema = schemas.get(table);\n\t\tif (schema === undefined || typeof row !== 'object' || row === null) {\n\t\t\treturn;\n\t\t}\n\t\tconst record = row as Record<string, unknown>;\n\t\tfor (const [fieldName, validate] of Object.entries(schema.fields)) {\n\t\t\tconst present = fieldName in record;\n\t\t\tif (op === 'update' && !present) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!validate(record[fieldName])) {\n\t\t\t\tthrow new SchemaError(table, fieldName);\n\t\t\t}\n\t\t}\n\t};\n\t// Lazily upcast a stored/raw row to the current shape (identity if no migrate).\n\tconst migrateRow = (table: string, row: unknown): unknown => {\n\t\tconst migrate = schemas.get(table)?.migrate;\n\t\treturn migrate ? migrate(row) : row;\n\t};\n\t// Reactive (read-set-tracked) subscriptions, scanned on each change since\n\t// their dependencies (the tables they read) are dynamic, not in tableIndex.\n\tconst reactiveSubs = new Set<\n\t\tExtract<ActiveSubscription, { kind: 'reactive' }>\n\t>();\n\t// Search subscriptions + one shared index per search collection, kept live\n\t// from the source table's change feed (like reactiveSubs, not in tableIndex).\n\tconst searchSubs = new Set<\n\t\tExtract<ActiveSubscription, { kind: 'search' }>\n\t>();\n\tconst searchIndexes = new Map<\n\t\tstring,\n\t\t{\n\t\t\tindex: SearchIndex<unknown, unknown>;\n\t\t\tdefinition: SearchCollectionDefinition<unknown, unknown, unknown>;\n\t\t\thydrated: boolean;\n\t\t}\n\t>();\n\tconst active = new Map<string, Set<ActiveSubscription>>();\n\t// Which collections read each table — so a table change fans to all of them.\n\tconst tableIndex = new Map<string, Set<string>>();\n\n\t// Monotonic change feed: every applyChange bumps `version` and appends to a\n\t// bounded log, so a client can resume from the version it last applied.\n\tconst changeLogSize = options.changeLogSize ?? 1024;\n\tconst changeLogRetainMs = options.changeLogRetainMs ?? null;\n\tconst changeLog: LoggedChange[] = [];\n\tlet version = 0;\n\t// Engine-level counters surfaced via `engine.metrics()` (1.13.0).\n\tconst engineStartedAt = Date.now();\n\tlet mutationsCompleted = 0;\n\tlet mutationsFailed = 0;\n\tlet mutationsRetried = 0;\n\tlet mutationsInFlight = 0;\n\n\t// 1.20.0: optional FIFO semaphore gating mutation entry. Capacity is\n\t// `mutationConcurrency`; waiters queue with optional `mutationQueueLimit`\n\t// rejection. New arrivals that find ANY queued waiter also queue (FIFO\n\t// preservation), so a steady arrival rate can't starve an early waiter.\n\tconst mutationWaiters: (() => void)[] = [];\n\tlet mutationsQueued = 0;\n\n\t// 1.24.0: G7 migration fence. While `activeFences` is non-empty,\n\t// `runMutation` rejects with EngineFencedError. Reads remain\n\t// available so the snapshot transport doesn't block subscribers.\n\t// Multi-fence compose: every handle must lift() before the engine\n\t// unfences. The reason of the OLDEST fence is reported on rejection.\n\tconst activeFences = new Set<FenceHandle>();\n\n\tconst acquireMutationSlot = async (): Promise<void> => {\n\t\tconst limit = options.mutationConcurrency;\n\t\tif (limit === undefined) {\n\t\t\t// No semaphore — still bump the metric so `inFlight` is\n\t\t\t// always accurate, but skip all the queue plumbing.\n\t\t\tmutationsInFlight += 1;\n\t\t\treturn;\n\t\t}\n\t\t// FIFO: if a slot is open AND no waiters are queued, take it\n\t\t// synchronously. The increment is part of the same synchronous\n\t\t// step as the check, so two arrivals can't both pass when only\n\t\t// one slot remains.\n\t\tif (mutationsInFlight < limit && mutationWaiters.length === 0) {\n\t\t\tmutationsInFlight += 1;\n\t\t\treturn;\n\t\t}\n\t\t// Queue, or reject if the queue is also capped.\n\t\tconst queueLimit = options.mutationQueueLimit;\n\t\tif (queueLimit !== undefined && mutationsQueued >= queueLimit) {\n\t\t\tthrow new MutationQueueOverflowError(queueLimit);\n\t\t}\n\t\tmutationsQueued += 1;\n\t\ttry {\n\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\tmutationWaiters.push(resolve);\n\t\t\t});\n\t\t} finally {\n\t\t\tmutationsQueued -= 1;\n\t\t}\n\t\t// Wake means a slot just opened up FOR US (`releaseMutationSlot`\n\t\t// only resolves one waiter per release). Claim it now — atomic\n\t\t// with the wake step.\n\t\tmutationsInFlight += 1;\n\t};\n\n\tconst releaseMutationSlot = (): void => {\n\t\tmutationsInFlight -= 1;\n\t\tif (options.mutationConcurrency === undefined) return;\n\t\tconst next = mutationWaiters.shift();\n\t\tif (next !== undefined) next();\n\t};\n\n\t// 1.20.1: per-tenant subscription cap. Active count keyed by the\n\t// host-supplied `subscriptionLimit.key(ctx, args)`. `undefined` from\n\t// `key()` means \"exempt this call from the cap\" — internal / system\n\t// subscriptions can skip the bookkeeping entirely.\n\tconst subscriptionsByTenant = new Map<string, number>();\n\n\tconst acquireSubscriptionSlot = (\n\t\tctx: unknown,\n\t\targs: { collection: string }\n\t): string | undefined => {\n\t\tconst cap = options.subscriptionLimit;\n\t\tif (cap === undefined) return undefined;\n\t\tconst tenantKey = cap.key(ctx, args);\n\t\tif (tenantKey === undefined) return undefined;\n\t\tconst active = subscriptionsByTenant.get(tenantKey) ?? 0;\n\t\tif (active >= cap.max) {\n\t\t\tthrow new SubscriptionLimitError(tenantKey, cap.max, active);\n\t\t}\n\t\tsubscriptionsByTenant.set(tenantKey, active + 1);\n\t\treturn tenantKey;\n\t};\n\n\tconst releaseSubscriptionSlot = (tenantKey: string | undefined): void => {\n\t\tif (tenantKey === undefined) return;\n\t\tconst active = subscriptionsByTenant.get(tenantKey);\n\t\tif (active === undefined || active <= 1) {\n\t\t\tsubscriptionsByTenant.delete(tenantKey);\n\t\t} else {\n\t\t\tsubscriptionsByTenant.set(tenantKey, active - 1);\n\t\t}\n\t};\n\n\t// Cross-client reactive query cache (1.3+). Keyed by stableSubKey, holds\n\t// the result + read set so a fresh subscribe with the same key reuses the\n\t// rerun instead of hitting the DB again. Per-batch dedup (since 1.1) is\n\t// already in `reactivePairs`; this lifts the sharing across batches.\n\t//\n\t// Entries are invalidated when a write overlaps the cached read set (same\n\t// `isReactiveAffected` check live subs use). LRU-bounded; optional TTL.\n\tconst reactiveCacheMax = options.reactiveCache?.max ?? 256;\n\tconst reactiveCacheTtlMs = options.reactiveCache?.ttlMs ?? 60_000;\n\ttype CachedRerun = {\n\t\trerunKey: string;\n\t\trows: unknown[];\n\t\treadTables: Set<string>;\n\t\treadKeys: Set<string>;\n\t\trangeDeps: RangeDep[];\n\t\tversion: number;\n\t\texpiresAt: number;\n\t};\n\t// `Map` preserves insertion order — re-set on access for LRU semantics.\n\tconst cachedReruns = new Map<string, CachedRerun>();\n\tconst touchCacheEntry = (key: string, entry: CachedRerun) => {\n\t\tcachedReruns.delete(key);\n\t\tcachedReruns.set(key, entry);\n\t};\n\tconst readCacheEntry = (key: string): CachedRerun | undefined => {\n\t\tif (reactiveCacheMax <= 0) return undefined;\n\t\tconst entry = cachedReruns.get(key);\n\t\tif (entry === undefined) return undefined;\n\t\tif (reactiveCacheTtlMs > 0 && entry.expiresAt < Date.now()) {\n\t\t\tcachedReruns.delete(key);\n\n\t\t\treturn undefined;\n\t\t}\n\t\ttouchCacheEntry(key, entry);\n\n\t\treturn entry;\n\t};\n\tconst writeCacheEntry = (entry: CachedRerun) => {\n\t\tif (reactiveCacheMax <= 0) return;\n\t\tcachedReruns.set(entry.rerunKey, entry);\n\t\t// LRU eviction: oldest insertion wins out when over budget.\n\t\twhile (cachedReruns.size > reactiveCacheMax) {\n\t\t\tconst oldest = cachedReruns.keys().next().value;\n\t\t\tif (oldest === undefined) break;\n\t\t\tcachedReruns.delete(oldest);\n\t\t}\n\t};\n\t// Devtools activity stream — listeners are notified of changes, mutation\n\t// outcomes, and subscribe/unsubscribe. Cheap (a no-op) when no one's watching.\n\tconst activityListeners = new Set<(event: EngineActivity) => void>();\n\tconst emitActivity = (event: EngineActivity) => {\n\t\tfor (const listener of activityListeners) {\n\t\t\tlistener(event);\n\t\t}\n\t};\n\t// Outbound CDC stream subscribers — `streamChanges()` adds itself here.\n\t// Notifications fire from `logChange` so every appended log entry reaches\n\t// every active streamer atomically with the log push.\n\tconst streamSubscribers = new Set<(entry: LoggedChange) => void>();\n\tconst runInTransaction = options.transaction;\n\t// Cluster fan-out: a stable id so we ignore our own broadcasts, and the bus\n\t// (set by connectCluster) we publish locally-committed changes to. Pass\n\t// `options.instanceId` for stable cross-process identity (e.g. the\n\t// hostname or a config-supplied UUID) — 1.17.0+ resume cursors travel\n\t// across instances, so the id needs to be stable across restarts if you\n\t// want resume to keep working past a reboot.\n\tconst instanceId =\n\t\toptions.instanceId ??\n\t\tglobalThis.crypto?.randomUUID?.() ??\n\t\t`i${Math.random()}`;\n\tlet clusterBus: ClusterBus | undefined;\n\n\t// 1.21.0: OTel tracer (noop when options.tracerProvider is unset).\n\t// All hot-path tracing flows through this — zero allocations when\n\t// the provider is absent because the noop tracer is a singleton.\n\tconst tracer = tracerOrNoop(options.tracerProvider, '@absolutejs/sync');\n\n\t// 1.19.0: optional boot-time restore from a prior engine's snapshot. Must\n\t// happen BEFORE any local writes — we validate by checking version === 0\n\t// inside importChangeLog and call it once here from the construction path.\n\tconst importChangeLog = (snapshot: ChangeLogSnapshot): number => {\n\t\tif (version !== 0) {\n\t\t\tthrow new Error(\n\t\t\t\t`[sync] importChangeLog: engine already has version ${version}; ` +\n\t\t\t\t\t`restore must happen before any local writes commit.`\n\t\t\t);\n\t\t}\n\t\tif (snapshot.instanceId !== instanceId) {\n\t\t\tthrow new Error(\n\t\t\t\t`[sync] importChangeLog: snapshot instanceId \"${snapshot.instanceId}\" ` +\n\t\t\t\t\t`does not match this engine's instanceId \"${instanceId}\". ` +\n\t\t\t\t\t`Pass options.instanceId = \"${snapshot.instanceId}\" to createSyncEngine.`\n\t\t\t);\n\t\t}\n\t\t// Adopt version + entries. logChange's retention sweeps still apply,\n\t\t// so over-large snapshots get trimmed exactly like live logs would.\n\t\tversion = snapshot.version;\n\t\tfor (const entry of snapshot.entries) {\n\t\t\tchangeLog.push(entry);\n\t\t}\n\t\t// Apply count cap once after the bulk push (cheaper than per-entry).\n\t\twhile (changeLog.length > changeLogSize) {\n\t\t\tchangeLog.shift();\n\t\t}\n\t\t// Apply time-based retention to the imported tail.\n\t\tif (changeLogRetainMs !== null && changeLogRetainMs > 0) {\n\t\t\tconst cutoff = Date.now() - changeLogRetainMs;\n\t\t\twhile (changeLog.length > 0 && changeLog[0]!.at < cutoff) {\n\t\t\t\tchangeLog.shift();\n\t\t\t}\n\t\t}\n\t\treturn snapshot.entries.length;\n\t};\n\n\tif (options.initialChangeLog !== undefined) {\n\t\timportChangeLog(options.initialChangeLog);\n\t}\n\n\tconst broadcast = (\n\t\tchanges: { table: string; change: RowChange<unknown> }[],\n\t\t// 1.17.0 — the local version at the moment of this broadcast, so\n\t\t// peers can log the changes against `(instanceId, originVersion)`\n\t\t// and serve cross-instance resume from their own log.\n\t\toriginVersion: number\n\t) => {\n\t\tif (clusterBus !== undefined && changes.length > 0) {\n\t\t\tvoid clusterBus.publish({\n\t\t\t\tchanges,\n\t\t\t\torigin: instanceId,\n\t\t\t\toriginVersion\n\t\t\t});\n\t\t}\n\t};\n\n\tconst subsFor = (collection: string) => {\n\t\tlet set = active.get(collection);\n\t\tif (set === undefined) {\n\t\t\tset = new Set();\n\t\t\tactive.set(collection, set);\n\t\t}\n\t\treturn set;\n\t};\n\n\tconst addTableIndex = (table: string, name: string) => {\n\t\tlet set = tableIndex.get(table);\n\t\tif (set === undefined) {\n\t\t\tset = new Set();\n\t\t\ttableIndex.set(table, set);\n\t\t}\n\t\tset.add(name);\n\t};\n\n\t/** A side change that fails its filter becomes a leave (delete from the join). */\n\tconst sideChange = (\n\t\tchange: RowChange<unknown>,\n\t\tmatch?: (row: unknown) => boolean\n\t): RowChange<unknown> =>\n\t\tchange.op !== 'delete' && match !== undefined && !match(change.row)\n\t\t\t? { op: 'delete', row: change.row }\n\t\t\t: change;\n\n\tconst EMPTY_DIFF: ViewDiff<unknown> = {\n\t\tadded: [],\n\t\tremoved: [],\n\t\tchanged: []\n\t};\n\n\t/** Apply one change to a subscription's state and return its diff (no emit). */\n\tconst subscriptionDiff = async (\n\t\tsubscription: ActiveSubscription,\n\t\ttable: string,\n\t\tchange: RowChange<unknown>\n\t): Promise<ViewDiff<unknown>> => {\n\t\tif (subscription.kind === 'graph') {\n\t\t\treturn subscription.instance.applyChange(table, change);\n\t\t}\n\t\tif (subscription.kind === 'join') {\n\t\t\tconst js = subscription.join;\n\t\t\tif (table === js.leftTable) {\n\t\t\t\treturn js.op.applyLeft(sideChange(change, js.leftMatch));\n\t\t\t}\n\t\t\tif (table === js.rightTable) {\n\t\t\t\treturn js.op.applyRight(sideChange(change, js.rightMatch));\n\t\t\t}\n\t\t\treturn EMPTY_DIFF;\n\t\t}\n\t\tif (subscription.kind === 'reactive') {\n\t\t\t// Reactive subs re-run as a whole (see reactivePairs), not per change.\n\t\t\treturn EMPTY_DIFF;\n\t\t}\n\t\tif (subscription.kind === 'search') {\n\t\t\t// Search subs re-rank as a whole (see searchPairs), not per change.\n\t\t\treturn EMPTY_DIFF;\n\t\t}\n\t\tif (subscription.incremental) {\n\t\t\ttry {\n\t\t\t\treturn subscription.view.apply(change);\n\t\t\t} catch {\n\t\t\t\t// The predicate couldn't decide this change (e.g. an operator the\n\t\t\t\t// inferred matcher doesn't support) — degrade to a correct refetch\n\t\t\t\t// rather than a wrong diff.\n\t\t\t\treturn subscription.view.reset(await subscription.rehydrate());\n\t\t\t}\n\t\t}\n\t\treturn subscription.view.reset(await subscription.rehydrate());\n\t};\n\n\t/** Active subscriptions whose collection reads `table`. */\n\tconst subscriptionsForTable = function* (\n\t\ttable: string\n\t): Generator<ActiveSubscription> {\n\t\tconst names = tableIndex.get(table);\n\t\tif (names === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tfor (const name of names) {\n\t\t\tconst set = active.get(name);\n\t\t\tif (set === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tyield* set;\n\t\t}\n\t};\n\n\t/**\n\t * Net a batch's per-change diffs by key, relative to the pre-batch state, so a\n\t * mutation that touches the same row twice collapses to one coherent change:\n\t * add-then-remove cancels, add-then-update stays an add, remove-then-add\n\t * becomes a change.\n\t */\n\tconst mergeViewDiffs = (\n\t\tdiffs: ViewDiff<unknown>[],\n\t\tkey: (row: unknown) => RowKey\n\t): ViewDiff<unknown> => {\n\t\ttype Net = { state: 'added' | 'changed' | 'removed'; row: unknown };\n\t\tconst net = new Map<RowKey, Net>();\n\t\tfor (const diff of diffs) {\n\t\t\tfor (const row of diff.removed) {\n\t\t\t\tconst previous = net.get(key(row));\n\t\t\t\tif (previous?.state === 'added') {\n\t\t\t\t\tnet.delete(key(row));\n\t\t\t\t} else {\n\t\t\t\t\tnet.set(key(row), { state: 'removed', row });\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const row of diff.added) {\n\t\t\t\tconst previous = net.get(key(row));\n\t\t\t\tnet.set(key(row), {\n\t\t\t\t\tstate: previous?.state === 'removed' ? 'changed' : 'added',\n\t\t\t\t\trow\n\t\t\t\t});\n\t\t\t}\n\t\t\tfor (const row of diff.changed) {\n\t\t\t\tconst previous = net.get(key(row));\n\t\t\t\tnet.set(key(row), {\n\t\t\t\t\tstate: previous?.state === 'added' ? 'added' : 'changed',\n\t\t\t\t\trow\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tconst added: unknown[] = [];\n\t\tconst changed: unknown[] = [];\n\t\tconst removed: unknown[] = [];\n\t\tfor (const { state, row } of net.values()) {\n\t\t\tif (state === 'added') {\n\t\t\t\tadded.push(row);\n\t\t\t} else if (state === 'changed') {\n\t\t\t\tchanged.push(row);\n\t\t\t} else {\n\t\t\t\tremoved.push(row);\n\t\t\t}\n\t\t}\n\t\treturn { added, changed, removed };\n\t};\n\n\ttype ReactiveSub = Extract<ActiveSubscription, { kind: 'reactive' }>;\n\n\tconst depKey = (table: string, key: RowKey): string => `${table} ${key}`;\n\n\t/** The key of a changed row under its table's reader key (if one is set). */\n\tconst changedKeyFor = (\n\t\ttable: string,\n\t\tchange: RowChange<unknown>\n\t): RowKey | undefined => readers.get(table)?.key?.(change.row);\n\n\t/**\n\t * An instrumented read handle: `all` records a full-table dependency; `get`\n\t * records a precise row-key dependency when the table's reader has a `key`\n\t * (else falls back to a table dependency).\n\t */\n\tconst makeReadHandle = (\n\t\tctx: unknown,\n\t\treadTables: Set<string>,\n\t\treadKeys: Set<string>,\n\t\trangeDeps: RangeDep[],\n\t\t// Schedules read unscoped (trusted server code); subscriptions apply rules.\n\t\tapplyRules = true\n\t): ReadHandle => {\n\t\tconst readerFor = (table: string): TableReader => {\n\t\t\tconst reader = readers.get(table);\n\t\t\tif (reader === undefined) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`No reader registered for table \"${table}\" — register one with engine.registerReader`\n\t\t\t\t);\n\t\t\t}\n\t\t\treturn reader;\n\t\t};\n\t\tconst ruleFor = (table: string) =>\n\t\t\tapplyRules ? readRuleFor(table) : undefined;\n\n\t\treturn {\n\t\t\tall: async (table) => {\n\t\t\t\treadTables.add(table);\n\t\t\t\t// Migrate raw rows to the current shape, then scope by read rule.\n\t\t\t\tconst rows = [...(await readerFor(table).all(ctx))].map((row) =>\n\t\t\t\t\tmigrateRow(table, row)\n\t\t\t\t);\n\t\t\t\tconst rule = ruleFor(table);\n\t\t\t\treturn (\n\t\t\t\t\trule ? rows.filter((row) => rule(ctx, row)) : rows\n\t\t\t\t) as never[];\n\t\t\t},\n\t\t\tget: async (table, key) => {\n\t\t\t\tconst reader = readerFor(table);\n\t\t\t\tif (reader.get === undefined) {\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Reader for table \"${table}\" has no get(); use db.all() or add get`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (reader.key !== undefined) {\n\t\t\t\t\treadKeys.add(depKey(table, key));\n\t\t\t\t} else {\n\t\t\t\t\treadTables.add(table);\n\t\t\t\t}\n\t\t\t\tconst raw = await reader.get(key, ctx);\n\t\t\t\tconst row =\n\t\t\t\t\traw === undefined ? undefined : migrateRow(table, raw);\n\t\t\t\tconst rule = ruleFor(table);\n\t\t\t\t// A row the caller can't read reads as absent.\n\t\t\t\treturn (\n\t\t\t\t\trule && row !== undefined && !rule(ctx, row)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: row\n\t\t\t\t) as never;\n\t\t\t},\n\t\t\twhere: async (table, predicate) => {\n\t\t\t\tconst reader = readerFor(table);\n\t\t\t\tconst rule = ruleFor(table);\n\t\t\t\t// Fold the read rule into the range predicate, so an unreadable row\n\t\t\t\t// never matches and a visibility flip still re-runs the query.\n\t\t\t\tconst effective = (\n\t\t\t\t\trule\n\t\t\t\t\t\t? (row: unknown) =>\n\t\t\t\t\t\t\t\t(predicate as (r: unknown) => boolean)(row) &&\n\t\t\t\t\t\t\t\trule(ctx, row)\n\t\t\t\t\t\t: (predicate as (row: unknown) => boolean)\n\t\t\t\t) as (row: unknown) => boolean;\n\t\t\t\tconst matched = [...(await reader.all(ctx))]\n\t\t\t\t\t.map((row) => migrateRow(table, row))\n\t\t\t\t\t.filter(effective);\n\t\t\t\tif (reader.key !== undefined) {\n\t\t\t\t\t// Remember which rows matched, so an update/delete that pulls a\n\t\t\t\t\t// row out of the range still re-runs (it's in this key set).\n\t\t\t\t\tconst key = reader.key;\n\t\t\t\t\trangeDeps.push({\n\t\t\t\t\t\ttable,\n\t\t\t\t\t\tpredicate: effective,\n\t\t\t\t\t\tkeys: new Set(matched.map(key))\n\t\t\t\t\t});\n\t\t\t\t} else {\n\t\t\t\t\treadTables.add(table);\n\t\t\t\t}\n\t\t\t\treturn matched as never[];\n\t\t\t}\n\t\t};\n\t};\n\n\tconst writerFor = (table: string): TableWriter => {\n\t\tconst writer = writers.get(table);\n\t\tif (writer === undefined) {\n\t\t\tthrow new Error(\n\t\t\t\t`No writer registered for table \"${table}\" — register one with engine.registerWriter, or use actions.change`\n\t\t\t);\n\t\t}\n\t\treturn writer;\n\t};\n\n\t// Load the committed row a write targets (by the table's reader), if any — so\n\t// authorization and CRDT merge both reflect committed state, not the payload.\n\tconst readExisting = async (\n\t\ttable: string,\n\t\tvalue: unknown,\n\t\tctx: unknown\n\t): Promise<unknown> => {\n\t\tconst reader = readers.get(table);\n\t\tif (reader?.get === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst id = reader.key\n\t\t\t? reader.key(value)\n\t\t\t: (value as { id?: RowKey }).id;\n\t\treturn id === undefined ? undefined : reader.get(id, ctx);\n\t};\n\n\t// Enforce a table's declarative write rule before the writer runs (so a deny\n\t// rolls the transaction back). For update/delete, evaluate the rule against the\n\t// *existing* row when a reader can load it — so the check reflects committed\n\t// state, not a client-supplied payload.\n\tconst authorizeWrite = async (\n\t\ttable: string,\n\t\top: 'insert' | 'update' | 'delete',\n\t\tvalue: unknown,\n\t\tctx: unknown\n\t) => {\n\t\tconst rule = writeRuleFor(table, op);\n\t\tif (rule === undefined) {\n\t\t\treturn;\n\t\t}\n\t\tlet subject = value;\n\t\tif (op !== 'insert') {\n\t\t\tconst existing = await readExisting(table, value, ctx);\n\t\t\tif (existing !== undefined) {\n\t\t\t\tsubject = existing;\n\t\t\t}\n\t\t}\n\t\tif (!rule(ctx, subject)) {\n\t\t\tthrow new UnauthorizedError(`${op} on table \"${table}\"`);\n\t\t}\n\t};\n\n\t// Merge a write's CRDT fields into the committed row (so concurrent writers\n\t// converge) instead of overwriting them. A no-op for tables without CRDT\n\t// fields. On insert the base is the empty state; on update it's the stored\n\t// field value. Returns the row patch the writer should persist.\n\tconst mergeCrdtFields = async (\n\t\ttable: string,\n\t\top: 'insert' | 'update',\n\t\tdata: unknown,\n\t\tctx: unknown\n\t): Promise<unknown> => {\n\t\tconst fields = crdtFields.get(table);\n\t\tif (fields === undefined || data === null || typeof data !== 'object') {\n\t\t\treturn data;\n\t\t}\n\t\tconst incoming = data as Record<string, unknown>;\n\t\tconst existing =\n\t\t\top === 'update' ? await readExisting(table, data, ctx) : undefined;\n\t\tconst base =\n\t\t\texisting !== null && typeof existing === 'object'\n\t\t\t\t? (existing as Record<string, unknown>)\n\t\t\t\t: undefined;\n\t\tconst merged: Record<string, unknown> = { ...incoming };\n\t\tfor (const [field, adapter] of Object.entries(fields)) {\n\t\t\tif (incoming[field] === undefined) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tmerged[field] = adapter.merge(\n\t\t\t\tbase?.[field] ?? adapter.empty(),\n\t\t\t\tincoming[field]\n\t\t\t);\n\t\t}\n\t\treturn merged;\n\t};\n\n\t/**\n\t * Build the write actions a mutation or schedule handler uses, collecting its\n\t * changes into a fresh buffer (so a transaction that retries/rolls back never\n\t * double-emits). `tx` threads to each writer. `enforce` applies write\n\t * permission rules (mutations); schedules run trusted, so they pass `false`.\n\t */\n\tconst makeActions = (tx: unknown, ctx: unknown, enforce: boolean) => {\n\t\tconst buffered: { table: string; change: RowChange<unknown> }[] = [];\n\t\tconst actions: MutationActions = {\n\t\t\tchange: (collection, change) => {\n\t\t\t\tbuffered.push({\n\t\t\t\t\ttable: collection,\n\t\t\t\t\tchange: change as RowChange<unknown>\n\t\t\t\t});\n\t\t\t\treturn Promise.resolve();\n\t\t\t},\n\t\t\tinsert: async (table, data) => {\n\t\t\t\t// Schema is data integrity — validated for trusted schedules too.\n\t\t\t\tvalidateWrite(table, 'insert', data);\n\t\t\t\tif (enforce) {\n\t\t\t\t\tawait authorizeWrite(table, 'insert', data, ctx);\n\t\t\t\t}\n\t\t\t\tconst merged = await mergeCrdtFields(\n\t\t\t\t\ttable,\n\t\t\t\t\t'insert',\n\t\t\t\t\tdata,\n\t\t\t\t\tctx\n\t\t\t\t);\n\t\t\t\tconst row = await writerFor(table).insert(merged, ctx, tx);\n\t\t\t\tbuffered.push({ table, change: { op: 'insert', row } });\n\t\t\t\treturn row;\n\t\t\t},\n\t\t\tupdate: async (table, data) => {\n\t\t\t\tvalidateWrite(table, 'update', data);\n\t\t\t\tif (enforce) {\n\t\t\t\t\tawait authorizeWrite(table, 'update', data, ctx);\n\t\t\t\t}\n\t\t\t\tconst merged = await mergeCrdtFields(\n\t\t\t\t\ttable,\n\t\t\t\t\t'update',\n\t\t\t\t\tdata,\n\t\t\t\t\tctx\n\t\t\t\t);\n\t\t\t\tconst row = await writerFor(table).update(merged, ctx, tx);\n\t\t\t\tbuffered.push({ table, change: { op: 'update', row } });\n\t\t\t\treturn row;\n\t\t\t},\n\t\t\tdelete: async (table, row) => {\n\t\t\t\tif (enforce) {\n\t\t\t\t\tawait authorizeWrite(table, 'delete', row, ctx);\n\t\t\t\t}\n\t\t\t\tawait writerFor(table).delete(row, ctx, tx);\n\t\t\t\tbuffered.push({ table, change: { op: 'delete', row } });\n\t\t\t},\n\t\t\t// Default wall clock. Replay / rebase paths can wrap and pin\n\t\t\t// this; today it's just Date.now().\n\t\t\tnow: () => Date.now()\n\t\t};\n\t\treturn { actions, buffered };\n\t};\n\n\t/** Diff a re-run against a sub's current set; updates `current`. Shared by the\n\t * reactive and search kinds (both re-run wholesale and diff). `equals` decides\n\t * whether a still-present row counts as changed. */\n\tconst diffRerun = (\n\t\tsub: {\n\t\t\tkey: (row: unknown) => RowKey;\n\t\t\tcurrent: Map<RowKey, unknown>;\n\t\t},\n\t\trows: unknown[],\n\t\tequals: (a: unknown, b: unknown) => boolean = shallowEqual\n\t): ViewDiff<unknown> => {\n\t\tconst next = new Map<RowKey, unknown>();\n\t\tfor (const row of rows) {\n\t\t\tnext.set(sub.key(row), row);\n\t\t}\n\t\tconst added: unknown[] = [];\n\t\tconst removed: unknown[] = [];\n\t\tconst changed: unknown[] = [];\n\t\tfor (const [rowKey, row] of next) {\n\t\t\tconst previous = sub.current.get(rowKey);\n\t\t\tif (previous === undefined) {\n\t\t\t\tadded.push(row);\n\t\t\t} else if (!equals(previous, row)) {\n\t\t\t\tchanged.push(row);\n\t\t\t}\n\t\t}\n\t\tfor (const [rowKey, row] of sub.current) {\n\t\t\tif (!next.has(rowKey)) {\n\t\t\t\tremoved.push(row);\n\t\t\t}\n\t\t}\n\t\tsub.current = next;\n\t\treturn { added, removed, changed };\n\t};\n\n\t/** Re-run every reactive query whose read set intersects the changed tables. */\n\ttype ReactiveChange = {\n\t\ttable: string;\n\t\tkey: RowKey | undefined;\n\t\trow: unknown;\n\t};\n\n\t/** Does a change fall in a range dep — matched now, or a member at last read? */\n\tconst inRange = (dep: RangeDep, change: ReactiveChange): boolean =>\n\t\tdep.table === change.table &&\n\t\t((change.key !== undefined && dep.keys.has(change.key)) ||\n\t\t\tdep.predicate(change.row));\n\n\t/** Does any change in the batch overlap this read set? Used for both live\n\t * sub invalidation and cross-client cache invalidation. */\n\tconst readSetOverlaps = (\n\t\treadTables: Set<string>,\n\t\treadKeys: Set<string>,\n\t\trangeDeps: RangeDep[],\n\t\tchanges: ReactiveChange[]\n\t): boolean =>\n\t\tchanges.some(\n\t\t\t(change) =>\n\t\t\t\treadTables.has(change.table) ||\n\t\t\t\t(change.key !== undefined &&\n\t\t\t\t\treadKeys.has(depKey(change.table, change.key))) ||\n\t\t\t\trangeDeps.some((dep) => inRange(dep, change))\n\t\t);\n\n\t/** Did this batch touch a table, row key, or range the sub read? */\n\tconst isReactiveAffected = (\n\t\tsub: ReactiveSub,\n\t\tchanges: ReactiveChange[]\n\t): boolean =>\n\t\treadSetOverlaps(sub.readTables, sub.readKeys, sub.rangeDeps, changes);\n\n\t/** Drop cached reruns whose read set overlaps this write batch. Cheap walk —\n\t * the cache is bounded by `reactiveCache.max` (default 256). */\n\tconst invalidateCacheForChanges = (changes: ReactiveChange[]) => {\n\t\tif (cachedReruns.size === 0) return;\n\t\tfor (const [key, entry] of cachedReruns) {\n\t\t\tif (\n\t\t\t\treadSetOverlaps(\n\t\t\t\t\tentry.readTables,\n\t\t\t\t\tentry.readKeys,\n\t\t\t\t\tentry.rangeDeps,\n\t\t\t\t\tchanges\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tcachedReruns.delete(key);\n\t\t\t}\n\t\t}\n\t};\n\n\tconst reactivePairs = async (\n\t\tchanges: ReactiveChange[]\n\t): Promise<[ActiveSubscription, ViewDiff<unknown>][]> => {\n\t\t// Drop now-stale cache entries before reruns — otherwise a fresh\n\t\t// subscriber landing during the batch could read the OLD value.\n\t\tinvalidateCacheForChanges(changes);\n\n\t\tconst pairs: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\t// Dedupe: subscriptions sharing the same `(collection, params, ctx)`\n\t\t// only need ONE rerun per change batch. With 1000 subs on the same\n\t\t// query, this drops per-change CPU from O(N) reruns to O(1) — every\n\t\t// sub then diffs the shared result against its own `current` and\n\t\t// receives its own per-sub frame (which the transport still writes\n\t\t// per-WS, see #22 batch-frame fan-out for the next step).\n\t\tconst sharedRuns = new Map<\n\t\t\tstring,\n\t\t\tPromise<Awaited<ReturnType<ReactiveSub['rerun']>>>\n\t\t>();\n\t\tfor (const sub of reactiveSubs) {\n\t\t\tif (!isReactiveAffected(sub, changes)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tlet runPromise = sharedRuns.get(sub.rerunKey);\n\t\t\tif (runPromise === undefined) {\n\t\t\t\trunPromise = sub.rerun();\n\t\t\t\tsharedRuns.set(sub.rerunKey, runPromise);\n\t\t\t}\n\t\t\tconst { rows, readTables, readKeys, rangeDeps } = await runPromise;\n\t\t\tsub.readTables = readTables;\n\t\t\tsub.readKeys = readKeys;\n\t\t\tsub.rangeDeps = rangeDeps;\n\t\t\tconst diff = diffRerun(sub, rows);\n\t\t\tif (!isEmptyViewDiff(diff)) {\n\t\t\t\tpairs.push([sub, diff]);\n\t\t\t}\n\t\t}\n\t\t// Refresh cache entries with the freshly-computed rows so subsequent\n\t\t// subscribers reuse them without hitting the DB.\n\t\tfor (const [key, runPromise] of sharedRuns) {\n\t\t\trunPromise\n\t\t\t\t.then(({ rows, readTables, readKeys, rangeDeps }) => {\n\t\t\t\t\twriteCacheEntry({\n\t\t\t\t\t\texpiresAt: Date.now() + reactiveCacheTtlMs,\n\t\t\t\t\t\trangeDeps,\n\t\t\t\t\t\treadKeys,\n\t\t\t\t\t\treadTables,\n\t\t\t\t\t\trerunKey: key,\n\t\t\t\t\t\trows,\n\t\t\t\t\t\tversion\n\t\t\t\t\t});\n\t\t\t\t})\n\t\t\t\t.catch(() => {\n\t\t\t\t\t// rerun threw — leave cache as-is (already invalidated above)\n\t\t\t\t});\n\t\t}\n\n\t\treturn pairs;\n\t};\n\n\t/** Lazily build + hydrate a search collection's shared index (once). */\n\tconst ensureSearchIndex = async (\n\t\tdefinition: SearchCollectionDefinition<unknown, unknown, unknown>\n\t) => {\n\t\tlet entry = searchIndexes.get(definition.name);\n\t\tif (entry === undefined) {\n\t\t\tentry = { index: definition.index(), definition, hydrated: false };\n\t\t\tsearchIndexes.set(definition.name, entry);\n\t\t}\n\t\tif (!entry.hydrated) {\n\t\t\tfor (const row of await definition.source()) {\n\t\t\t\tentry.index.add(row);\n\t\t\t}\n\t\t\tentry.hydrated = true;\n\t\t}\n\t\treturn entry;\n\t};\n\n\t/**\n\t * Keep search indexes live and re-rank affected search subs: apply each change\n\t * to its collection's index, then re-run every sub whose collection changed.\n\t * Synchronous — the index ops and re-ranks don't touch the DB.\n\t */\n\tconst searchPairs = (\n\t\tchanges: { table: string; change: RowChange<unknown> }[]\n\t): [ActiveSubscription, ViewDiff<unknown>][] => {\n\t\tconst touched = new Set<string>();\n\t\tfor (const { table, change } of changes) {\n\t\t\tfor (const entry of searchIndexes.values()) {\n\t\t\t\tif (!entry.hydrated || entry.definition.table !== table) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (change.op === 'delete') {\n\t\t\t\t\tentry.index.remove(entry.definition.key(change.row));\n\t\t\t\t} else {\n\t\t\t\t\tentry.index.add(change.row);\n\t\t\t\t}\n\t\t\t\ttouched.add(entry.definition.name);\n\t\t\t}\n\t\t}\n\t\tconst pairs: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\tfor (const sub of searchSubs) {\n\t\t\tif (!touched.has(sub.collection)) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\t// Ignore pure score drift (BM25 idf shifts as the corpus grows), so a\n\t\t\t// result only re-emits when it enters/leaves or its content changes —\n\t\t\t// not on every unrelated insert.\n\t\t\tconst diff = diffRerun(sub, sub.rerun(), equalsIgnoringScore);\n\t\t\tif (!isEmptyViewDiff(diff)) {\n\t\t\t\tpairs.push([sub, diff]);\n\t\t\t}\n\t\t}\n\t\treturn pairs;\n\t};\n\n\tconst logChange = (changeVersion: number, entry: LoggedChange) => {\n\t\tchangeLog.push(entry);\n\t\t// Count-based cap.\n\t\tif (changeLog.length > changeLogSize) {\n\t\t\tchangeLog.shift();\n\t\t}\n\t\t// Time-based retention (1.13.0): drop entries older than the\n\t\t// configured window. Cheap when the log is small or the head is\n\t\t// fresh — we stop the moment we find a young-enough entry.\n\t\tif (changeLogRetainMs !== null && changeLogRetainMs > 0) {\n\t\t\tconst cutoff = entry.at - changeLogRetainMs;\n\t\t\twhile (changeLog.length > 0 && changeLog[0]!.at < cutoff) {\n\t\t\t\tchangeLog.shift();\n\t\t\t}\n\t\t}\n\t\t// Atomic with the log push — every active CDC streamer sees every\n\t\t// entry exactly once, in version order, with no chance of a missed\n\t\t// commit between phase-1 catch-up and phase-2 tail.\n\t\tfor (const subscriber of streamSubscribers) {\n\t\t\tsubscriber(entry);\n\t\t}\n\t};\n\n\t// 1.17.0 cross-instance cursor encode/decode. Opaque to clients —\n\t// shaped as base64-ish JSON internally. The client must round-trip\n\t// what the server returned, unmodified.\n\tconst encodeCursor = (versions: Record<string, number>): string =>\n\t\t// Plain JSON is fine; clients treat it as opaque. We don't base64\n\t\t// because the cursor lives in a JSON payload anyway (snapshot frame).\n\t\tJSON.stringify(versions);\n\tconst decodeCursor = (cursor: string): Record<string, number> | null => {\n\t\ttry {\n\t\t\tconst parsed = JSON.parse(cursor);\n\t\t\tif (typeof parsed !== 'object' || parsed === null) return null;\n\t\t\tconst out: Record<string, number> = {};\n\t\t\tfor (const [k, v] of Object.entries(parsed)) {\n\t\t\t\tif (typeof v === 'number') out[k] = v;\n\t\t\t}\n\t\t\treturn out;\n\t\t} catch {\n\t\t\treturn null;\n\t\t}\n\t};\n\tconst currentCursor = (): string => {\n\t\t// Snapshot the highest local version + each peer's highest origin\n\t\t// version seen so far. Cheap O(log) — single backwards walk grabs\n\t\t// the most-recent originVersion per peer.\n\t\tconst versions: Record<string, number> = { [instanceId]: version };\n\t\tfor (let i = changeLog.length - 1; i >= 0; i--) {\n\t\t\tconst entry = changeLog[i]!;\n\t\t\tif (versions[entry.origin] === undefined) {\n\t\t\t\tversions[entry.origin] = entry.originVersion;\n\t\t\t}\n\t\t}\n\t\treturn encodeCursor(versions);\n\t};\n\n\t/** Apply a single committed change at its own version (CDC / direct writes). */\n\tconst applyChange = async (\n\t\ttable: string,\n\t\tchange: RowChange<unknown>,\n\t\tshouldBroadcast = true\n\t) => {\n\t\tversion += 1;\n\t\tconst changeVersion = version;\n\t\tconst at = Date.now();\n\t\tlogChange(changeVersion, {\n\t\t\tversion: changeVersion,\n\t\t\ttable,\n\t\t\tchange,\n\t\t\tat,\n\t\t\torigin: instanceId,\n\t\t\toriginVersion: changeVersion\n\t\t});\n\t\temitActivity({\n\t\t\ttype: 'change',\n\t\t\tat,\n\t\t\ttable,\n\t\t\top: change.op,\n\t\t\tversion: changeVersion\n\t\t});\n\t\t// Collect, then emit once at the end: reactive re-runs are async, and\n\t\t// emitting before they finish would let the transport flush a partial frame.\n\t\tconst emissions: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\tfor (const subscription of subscriptionsForTable(table)) {\n\t\t\tconst diff = await subscriptionDiff(subscription, table, change);\n\t\t\tif (!isEmptyViewDiff(diff)) {\n\t\t\t\temissions.push([subscription, diff]);\n\t\t\t}\n\t\t}\n\t\temissions.push(\n\t\t\t...(await reactivePairs([\n\t\t\t\t{ table, key: changedKeyFor(table, change), row: change.row }\n\t\t\t]))\n\t\t);\n\t\temissions.push(...searchPairs([{ table, change }]));\n\t\tconst cursorForBatch = currentCursor();\n\t\tfor (const [subscription, diff] of emissions) {\n\t\t\tsubscription.onDiff(diff, changeVersion, cursorForBatch);\n\t\t}\n\t\tif (shouldBroadcast) {\n\t\t\tbroadcast([{ table, change }], changeVersion);\n\t\t}\n\t};\n\n\t/**\n\t * Apply a set of changes atomically: one version bump for the whole batch and\n\t * a single net-merged diff per affected subscription. Used by mutations so a\n\t * client never renders a torn intermediate state mid-mutation.\n\t */\n\tconst applyChangeBatch = async (\n\t\tchanges: { table: string; change: RowChange<unknown> }[],\n\t\tshouldBroadcast = true,\n\t\t/**\n\t\t * 1.17.0 — peer-relayed batches override the change-log entry's\n\t\t * `origin` + `originVersion` so a cross-instance client cursor can\n\t\t * later match the entry. Local batches leave this `undefined` and\n\t\t * the entry inherits the engine's own identity.\n\t\t */\n\t\tpeerOrigin?: { origin: string; originVersion: number }\n\t) => {\n\t\tif (changes.length === 0) {\n\t\t\treturn;\n\t\t}\n\t\tversion += 1;\n\t\tconst batchVersion = version;\n\t\tconst perSubscription = new Map<\n\t\t\tActiveSubscription,\n\t\t\tViewDiff<unknown>[]\n\t\t>();\n\t\tconst reactiveChanges: ReactiveChange[] = [];\n\t\tconst batchAt = Date.now();\n\t\t// 1.17.0: peer-relayed batches override origin/originVersion via\n\t\t// `peerOrigin` (set when applyChangeBatch is called from the cluster\n\t\t// subscribe path). Defaults to this engine's identity.\n\t\tconst batchOrigin = peerOrigin?.origin ?? instanceId;\n\t\tconst batchOriginVersion = peerOrigin?.originVersion ?? batchVersion;\n\t\tfor (const { table, change } of changes) {\n\t\t\tlogChange(batchVersion, {\n\t\t\t\tversion: batchVersion,\n\t\t\t\ttable,\n\t\t\t\tchange,\n\t\t\t\tat: batchAt,\n\t\t\t\torigin: batchOrigin,\n\t\t\t\toriginVersion: batchOriginVersion\n\t\t\t});\n\t\t\temitActivity({\n\t\t\t\ttype: 'change',\n\t\t\t\tat: batchAt,\n\t\t\t\ttable,\n\t\t\t\top: change.op,\n\t\t\t\tversion: batchVersion\n\t\t\t});\n\t\t\treactiveChanges.push({\n\t\t\t\ttable,\n\t\t\t\tkey: changedKeyFor(table, change),\n\t\t\t\trow: change.row\n\t\t\t});\n\t\t\tfor (const subscription of subscriptionsForTable(table)) {\n\t\t\t\t// Apply in order to keep operator state correct; collect to merge.\n\t\t\t\tconst diff = await subscriptionDiff(\n\t\t\t\t\tsubscription,\n\t\t\t\t\ttable,\n\t\t\t\t\tchange\n\t\t\t\t);\n\t\t\t\tconst list = perSubscription.get(subscription);\n\t\t\t\tif (list === undefined) {\n\t\t\t\t\tperSubscription.set(subscription, [diff]);\n\t\t\t\t} else {\n\t\t\t\t\tlist.push(diff);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// Gather all emissions before sending any, so the whole batch — view diffs\n\t\t// and reactive re-runs (async) — leaves as one coalesced frame.\n\t\tconst emissions: [ActiveSubscription, ViewDiff<unknown>][] = [];\n\t\tfor (const [subscription, diffs] of perSubscription) {\n\t\t\tconst merged =\n\t\t\t\tdiffs.length === 1\n\t\t\t\t\t? diffs[0]!\n\t\t\t\t\t: mergeViewDiffs(diffs, subscription.key);\n\t\t\tif (!isEmptyViewDiff(merged)) {\n\t\t\t\temissions.push([subscription, merged]);\n\t\t\t}\n\t\t}\n\t\temissions.push(...(await reactivePairs(reactiveChanges)));\n\t\temissions.push(...searchPairs(changes));\n\t\tconst cursorForBatch = currentCursor();\n\t\tfor (const [subscription, diff] of emissions) {\n\t\t\tsubscription.onDiff(diff, batchVersion, cursorForBatch);\n\t\t}\n\t\tif (shouldBroadcast) {\n\t\t\tbroadcast(changes, batchVersion);\n\t\t}\n\t};\n\n\t/**\n\t * Normalize a `since` value (number or cursor string) into a per-origin\n\t * version vector. A bare `number` is treated as legacy 1.16- form — the\n\t * version of THIS instance. A cursor string is the 1.17.0+ multi-origin\n\t * shape encoded by `currentCursor()`.\n\t */\n\tconst normalizeSince = (\n\t\tsince: number | string\n\t): Record<string, number> | null => {\n\t\tif (typeof since === 'number') {\n\t\t\treturn { [instanceId]: since };\n\t\t}\n\t\treturn decodeCursor(since);\n\t};\n\n\t/**\n\t * Can we replay `(since, now]` from the log for `tables`? With a cursor,\n\t * this is a per-origin coverage check — every entry the client hasn't\n\t * seen MUST be present in our log. Pre-1.16 `number` form matches when\n\t * the local log covers `(since.version, now]`. Returns `false` for\n\t * non-incremental subs (refetch/join/graph/search), since those can't be\n\t * replayed precisely from a row-change log.\n\t */\n\tconst canResume = (\n\t\tsince: number | string,\n\t\tincremental: boolean\n\t): boolean => {\n\t\tif (!incremental) {\n\t\t\treturn false;\n\t\t}\n\t\tconst sinceVec = normalizeSince(since);\n\t\tif (sinceVec === null) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// Walk the log backwards: every entry with `origin === O` and\n\t\t// `originVersion > sinceVec[O]` MUST appear in the log. If the log\n\t\t// has been trimmed past any such entry, we can't catch up.\n\t\t// Per-origin: for each origin O we've seen, check that the oldest\n\t\t// entry with that origin is no newer than `sinceVec[O] + 1`. For\n\t\t// an unknown origin, we fall back to \"no coverage\" (caller gets a\n\t\t// snapshot, just like pre-1.17 behavior).\n\t\tconst oldestPerOrigin = new Map<string, number>();\n\t\tfor (const entry of changeLog) {\n\t\t\tconst current = oldestPerOrigin.get(entry.origin);\n\t\t\tif (current === undefined || entry.originVersion < current) {\n\t\t\t\toldestPerOrigin.set(entry.origin, entry.originVersion);\n\t\t\t}\n\t\t}\n\n\t\t// Log-wide watermark: the smallest version still in the log. If this\n\t\t// is past `lastSeen + 1`, ANY entries between the cursor and oldestLogVersion\n\t\t// were trimmed (regardless of origin).\n\t\tconst oldestLogVersion = changeLog[0]?.version;\n\t\tfor (const [origin, lastSeen] of Object.entries(sinceVec)) {\n\t\t\t// Special case: if we've never seen any entry from this origin,\n\t\t\t// but the client claims to have seen up to `lastSeen` from it,\n\t\t\t// we DEFINITELY can't reconstruct — snapshot it.\n\t\t\tif (origin === instanceId) {\n\t\t\t\t// Local origin: standard check.\n\t\t\t\tif (lastSeen >= version) continue; // nothing newer\n\t\t\t\tconst oldestLocal = oldestPerOrigin.get(instanceId);\n\t\t\t\t// If we have local entries, walk them: they must reach back\n\t\t\t\t// to lastSeen + 1.\n\t\t\t\tif (oldestLocal !== undefined) {\n\t\t\t\t\tif (oldestLocal > lastSeen + 1) return false;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\t// No local entries — the version bumps since mint were all\n\t\t\t\t// from peer broadcasts. Resume is safe ONLY if the log itself\n\t\t\t\t// hasn't been trimmed past the mint point (otherwise some\n\t\t\t\t// local entries existed but were retired).\n\t\t\t\tif (\n\t\t\t\t\toldestLogVersion !== undefined &&\n\t\t\t\t\toldestLogVersion > lastSeen + 1\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Peer origin: same check against the peer's entries.\n\t\t\t\tconst oldestPeer = oldestPerOrigin.get(origin);\n\t\t\t\tif (oldestPeer === undefined) {\n\t\t\t\t\t// We've never logged any change from this peer. If the client\n\t\t\t\t\t// has seen entries from this peer, we can't help.\n\t\t\t\t\tif (lastSeen > 0) return false;\n\t\t\t\t} else if (oldestPeer > lastSeen + 1) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn true;\n\t};\n\n\t/**\n\t * Build a catch-up diff from the log for one subscription (last op per\n\t * key wins). Multi-origin aware (1.17.0+): walks every entry whose\n\t * `(origin, originVersion)` is newer than the client's last-seen for\n\t * that origin.\n\t */\n\tconst buildCatchup = (\n\t\tsince: number | string,\n\t\ttables: string[],\n\t\tkey: (row: unknown) => RowKey,\n\t\tmatch: (row: unknown) => boolean\n\t): ViewDiff<unknown> => {\n\t\tconst sinceVec = normalizeSince(since) ?? {};\n\t\tconst latest = new Map<\n\t\t\tRowKey,\n\t\t\t{ op: 'upsert' | 'remove'; row: unknown }\n\t\t>();\n\t\tfor (const entry of changeLog) {\n\t\t\tif (!tables.includes(entry.table)) continue;\n\t\t\t// Skip entries the client has already seen for this origin.\n\t\t\tconst lastSeen = sinceVec[entry.origin];\n\t\t\tif (lastSeen !== undefined && entry.originVersion <= lastSeen)\n\t\t\t\tcontinue;\n\t\t\tconst row = entry.change.row;\n\t\t\tconst present =\n\t\t\t\tentry.change.op !== 'delete' && match(row)\n\t\t\t\t\t? 'upsert'\n\t\t\t\t\t: 'remove';\n\t\t\tlatest.set(key(row), { op: present, row });\n\t\t}\n\t\tconst changed: unknown[] = [];\n\t\tconst removed: unknown[] = [];\n\t\tfor (const { op, row } of latest.values()) {\n\t\t\t(op === 'upsert' ? changed : removed).push(row);\n\t\t}\n\t\treturn { added: [], removed, changed };\n\t};\n\n\tconst subscribeJoin = async (\n\t\tcollection: string,\n\t\tdefinition: JoinCollectionDefinition<\n\t\t\tunknown,\n\t\t\tunknown,\n\t\t\tunknown,\n\t\t\tunknown,\n\t\t\tunknown\n\t\t>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst { left, right } = definition;\n\t\tconst op = createEquiJoin<unknown, unknown, unknown>({\n\t\t\tleftKey: left.key,\n\t\t\trightKey: right.key,\n\t\t\tleftOn: left.on,\n\t\t\trightOn: right.on,\n\t\t\tselect: definition.select\n\t\t});\n\t\top.hydrate(\n\t\t\t[...(await left.hydrate(params, ctx))],\n\t\t\t[...(await right.hydrate(params, ctx))]\n\t\t);\n\t\tconst atVersion = version;\n\n\t\tconst subscription: ActiveSubscription = {\n\t\t\tkind: 'join',\n\t\t\tcollection,\n\t\t\tjoin: {\n\t\t\t\top,\n\t\t\t\tleftTable: left.table,\n\t\t\t\trightTable: right.table,\n\t\t\t\tleftMatch: left.match\n\t\t\t\t\t? (row) => left.match!(row, params, ctx)\n\t\t\t\t\t: undefined,\n\t\t\t\trightMatch: right.match\n\t\t\t\t\t? (row) => right.match!(row, params, ctx)\n\t\t\t\t\t: undefined\n\t\t\t},\n\t\t\tkey: definition.key as (row: unknown) => RowKey,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\n\t\treturn {\n\t\t\tinitial: op.rows(),\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst subscribeGraph = async (\n\t\tcollection: string,\n\t\tdefinition: GraphCollectionDefinition<unknown, unknown, unknown>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst instance = definition.query.instantiate(params, ctx);\n\t\tconst initial = await instance.hydrate();\n\t\tconst atVersion = version;\n\t\tconst subscription: ActiveSubscription = {\n\t\t\tkind: 'graph',\n\t\t\tcollection,\n\t\t\tinstance,\n\t\t\tkey: definition.key as (row: unknown) => RowKey,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\t\treturn {\n\t\t\tinitial,\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst subscribeReactive = async (\n\t\tcollection: string,\n\t\tdefinition: ReactiveQueryDefinition<unknown, unknown, unknown>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\t// Each run gets a fresh read set; the handle records tables + row keys read.\n\t\tconst rerun = async () => {\n\t\t\tconst readTables = new Set<string>();\n\t\t\tconst readKeys = new Set<string>();\n\t\t\tconst rangeDeps: RangeDep[] = [];\n\t\t\tconst db = makeReadHandle(ctx, readTables, readKeys, rangeDeps);\n\t\t\tconst rows = [...(await definition.run({ ctx, db, params }))];\n\t\t\treturn { rangeDeps, readKeys, readTables, rows };\n\t\t};\n\t\tconst rerunKey = stableSubKey(collection, params, ctx);\n\t\t// Cross-client cache hit (1.3+): a previous subscriber with the same\n\t\t// (collection, params, ctx) ran the query body recently and its\n\t\t// result is still valid (no overlapping write since). Reuse it\n\t\t// instead of hitting the DB again. Cache misses fall through to\n\t\t// `rerun()` and populate the cache for the next subscriber.\n\t\tconst cached = readCacheEntry(rerunKey);\n\t\tconst first =\n\t\t\tcached !== undefined\n\t\t\t\t? {\n\t\t\t\t\t\trangeDeps: cached.rangeDeps,\n\t\t\t\t\t\treadKeys: cached.readKeys,\n\t\t\t\t\t\treadTables: cached.readTables,\n\t\t\t\t\t\trows: cached.rows\n\t\t\t\t\t}\n\t\t\t\t: await rerun();\n\t\tif (cached === undefined) {\n\t\t\twriteCacheEntry({\n\t\t\t\texpiresAt: Date.now() + reactiveCacheTtlMs,\n\t\t\t\trangeDeps: first.rangeDeps,\n\t\t\t\treadKeys: first.readKeys,\n\t\t\t\treadTables: first.readTables,\n\t\t\t\trerunKey,\n\t\t\t\trows: first.rows,\n\t\t\t\tversion\n\t\t\t});\n\t\t}\n\t\tconst current = new Map<RowKey, unknown>();\n\t\tfor (const row of first.rows) {\n\t\t\tcurrent.set(definition.key(row), row);\n\t\t}\n\t\tconst atVersion = version;\n\t\tconst subscription: ReactiveSub = {\n\t\t\tkind: 'reactive',\n\t\t\tcollection,\n\t\t\tkey: definition.key,\n\t\t\trerun,\n\t\t\trerunKey,\n\t\t\tcurrent,\n\t\t\treadTables: first.readTables,\n\t\t\treadKeys: first.readKeys,\n\t\t\trangeDeps: first.rangeDeps,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\t\treactiveSubs.add(subscription);\n\t\treturn {\n\t\t\tinitial: first.rows,\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t\treactiveSubs.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst subscribeSearch = async (\n\t\tcollection: string,\n\t\tdefinition: SearchCollectionDefinition<unknown, unknown, unknown>,\n\t\tparams: unknown,\n\t\tctx: unknown,\n\t\tonDiff: OnDiff,\n\t\tset: Set<ActiveSubscription>\n\t): Promise<Subscription<unknown>> => {\n\t\t// The subscription params are the query (a string for text, a vector for\n\t\t// similarity).\n\t\tconst query = params;\n\t\tif (definition.authorize !== undefined) {\n\t\t\tconst allowed = await definition.authorize(query, ctx);\n\t\t\tif (!allowed) {\n\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t\tconst entry = await ensureSearchIndex(definition);\n\t\tconst limit = definition.limit ?? 20;\n\t\tconst readRule = readRuleFor(definition.table);\n\t\t// Re-rank: top-K from the (shared, live) index, scoped by the read rule,\n\t\t// each row tagged with its score so the client can sort by relevance.\n\t\tconst rerun = (): unknown[] => {\n\t\t\tconst candidates = entry.index.search(\n\t\t\t\tquery,\n\t\t\t\treadRule ? limit * 5 : limit\n\t\t\t);\n\t\t\tconst visible = readRule\n\t\t\t\t? candidates.filter((hit) => readRule(ctx, hit.row))\n\t\t\t\t: candidates;\n\t\t\treturn visible.slice(0, limit).map((hit) => ({\n\t\t\t\t...(hit.row as Record<string, unknown>),\n\t\t\t\t[SEARCH_SCORE_FIELD]: hit.score\n\t\t\t}));\n\t\t};\n\t\tconst initial = rerun();\n\t\tconst current = new Map<RowKey, unknown>();\n\t\tfor (const row of initial) {\n\t\t\tcurrent.set(definition.key(row), row);\n\t\t}\n\t\tconst atVersion = version;\n\t\tconst subscription: Extract<ActiveSubscription, { kind: 'search' }> = {\n\t\t\tkind: 'search',\n\t\t\tcollection,\n\t\t\tkey: definition.key,\n\t\t\trerun,\n\t\t\tcurrent,\n\t\t\tonDiff\n\t\t};\n\t\tset.add(subscription);\n\t\tsearchSubs.add(subscription);\n\t\treturn {\n\t\t\tinitial,\n\t\t\tcursor: currentCursor(),\n\t\t\tversion: atVersion,\n\t\t\tunsubscribe: () => {\n\t\t\t\tset.delete(subscription);\n\t\t\t\tsearchSubs.delete(subscription);\n\t\t\t}\n\t\t};\n\t};\n\n\tconst engine: SyncEngine = {\n\t\tregister: (collection) => {\n\t\t\tregistry.set(collection.name, collection);\n\t\t\tfor (const table of collection.tables ?? [collection.name]) {\n\t\t\t\taddTableIndex(table, collection.name);\n\t\t\t}\n\t\t},\n\n\t\tregisterJoin: (collection) => {\n\t\t\tregistry.set(collection.name, collection);\n\t\t\taddTableIndex(collection.left.table, collection.name);\n\t\t\taddTableIndex(collection.right.table, collection.name);\n\t\t},\n\n\t\tregisterGraph: (collection) => {\n\t\t\tregistry.set(collection.name, collection);\n\t\t\tfor (const table of collection.query.tables()) {\n\t\t\t\taddTableIndex(table, collection.name);\n\t\t\t}\n\t\t},\n\n\t\tregisterSearch: (collection) => {\n\t\t\t// Like reactive: not in tableIndex — its index is driven directly by\n\t\t\t// searchPairs off the change feed.\n\t\t\tregistry.set(collection.name, collection);\n\t\t},\n\n\t\tsubscribe: async ({\n\t\t\tcollection,\n\t\t\tparams,\n\t\t\tctx,\n\t\t\tonDiff,\n\t\t\tsince,\n\t\t\tsignal\n\t\t}) => {\n\t\t\t// 1.21.0: wrap subscribe setup in a span. The Subscription\n\t\t\t// lives past `subscribe()` returning — the span only covers\n\t\t\t// the setup cost (authorize / hydrate / view materialization),\n\t\t\t// not the ongoing reactive lifetime.\n\t\t\tconst subscribeSpan = tracer.startSpan('sync.subscribe', {\n\t\t\t\tattributes: {\n\t\t\t\t\t[ABS_ATTRS.engineId]: instanceId,\n\t\t\t\t\t[ABS_ATTRS.collection]: collection\n\t\t\t\t}\n\t\t\t});\n\t\t\ttry {\n\t\t\t\t// (1.15.0) Cheap up-front check — if the consumer already aborted\n\t\t\t\t// before we got here, throw before any side effect (no authorize,\n\t\t\t\t// no hydrate, no view materialization).\n\t\t\t\tcheckAborted(signal);\n\n\t\t\t\tconst registered = registry.get(collection);\n\t\t\t\tif (registered === undefined) {\n\t\t\t\t\tthrow new Error(`Unknown collection \"${collection}\"`);\n\t\t\t\t}\n\n\t\t\t\t// (1.20.1) Per-tenant cap. Acquired BEFORE authorize/hydrate/any\n\t\t\t\t// state allocation. If subscribe throws between here and the\n\t\t\t\t// successful return (auth rejection, abort, schema error, etc.)\n\t\t\t\t// we release in the `catch` below — otherwise the wrapped\n\t\t\t\t// `unsubscribe` is the release path.\n\t\t\t\tconst tenantSlot = acquireSubscriptionSlot(ctx, { collection });\n\t\t\t\tlet slotHandedOff = false;\n\t\t\t\ttry {\n\t\t\t\t\tconst typedOnDiff = onDiff as OnDiff;\n\t\t\t\t\tconst subscribeSet = subsFor(collection);\n\n\t\t\t\t\t// Wrap the eventual return so we (a) re-check signal after the\n\t\t\t\t\t// async setup (catches mid-flight aborts), (b) auto-call\n\t\t\t\t\t// unsubscribe when signal fires after the subscription is live,\n\t\t\t\t\t// and (c) decrement the tenant's active-sub count idempotently\n\t\t\t\t\t// when unsubscribe runs.\n\t\t\t\t\tconst wrapReturn = <T>(\n\t\t\t\t\t\tsub: Subscription<T>\n\t\t\t\t\t): Subscription<T> => {\n\t\t\t\t\t\tcheckAborted(signal);\n\t\t\t\t\t\tconst innerUnsubscribe = sub.unsubscribe;\n\t\t\t\t\t\tlet released = false;\n\t\t\t\t\t\tconst wrappedUnsubscribe = (): void => {\n\t\t\t\t\t\t\tif (released) return;\n\t\t\t\t\t\t\treleased = true;\n\t\t\t\t\t\t\treleaseSubscriptionSlot(tenantSlot);\n\t\t\t\t\t\t\tinnerUnsubscribe();\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst wrapped = {\n\t\t\t\t\t\t\t...sub,\n\t\t\t\t\t\t\tunsubscribe: wrappedUnsubscribe\n\t\t\t\t\t\t};\n\t\t\t\t\t\tlinkAbortToUnsubscribe(signal, wrappedUnsubscribe);\n\t\t\t\t\t\tslotHandedOff = true;\n\t\t\t\t\t\treturn wrapped;\n\t\t\t\t\t};\n\n\t\t\t\t\tconst registeredKind = (registered as { kind?: string })\n\t\t\t\t\t\t.kind;\n\t\t\t\t\tif (registeredKind === 'join') {\n\t\t\t\t\t\tconst joined = await subscribeJoin(\n\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\tregistered as JoinCollectionDefinition<\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\t\t\tsubscribeSet\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn wrapReturn(joined) as Subscription<never>;\n\t\t\t\t\t}\n\t\t\t\t\tif (registeredKind === 'graph') {\n\t\t\t\t\t\tconst graphed = await subscribeGraph(\n\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\tregistered as GraphCollectionDefinition<\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\t\t\tsubscribeSet\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn wrapReturn(graphed) as Subscription<never>;\n\t\t\t\t\t}\n\t\t\t\t\tif (registeredKind === 'reactive') {\n\t\t\t\t\t\tconst reactived = await subscribeReactive(\n\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\tregistered as ReactiveQueryDefinition<\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\t\t\tsubscribeSet\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn wrapReturn(reactived) as Subscription<never>;\n\t\t\t\t\t}\n\t\t\t\t\tif (registeredKind === 'search') {\n\t\t\t\t\t\tconst searched = await subscribeSearch(\n\t\t\t\t\t\t\tcollection,\n\t\t\t\t\t\t\tregistered as SearchCollectionDefinition<\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t>,\n\t\t\t\t\t\t\tparams,\n\t\t\t\t\t\t\tctx,\n\t\t\t\t\t\t\ttypedOnDiff,\n\t\t\t\t\t\t\tsubscribeSet\n\t\t\t\t\t\t);\n\t\t\t\t\t\treturn wrapReturn(searched) as Subscription<never>;\n\t\t\t\t\t}\n\t\t\t\t\tconst definition = registered as CollectionDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>;\n\n\t\t\t\t\tif (definition.authorize !== undefined) {\n\t\t\t\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\t\t\t\tif (!allowed) {\n\t\t\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\t\t`subscribe to collection \"${collection}\"`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst key = definition.key ?? defaultKey;\n\t\t\t\t\tconst match = definition.match;\n\t\t\t\t\tconst tables = definition.tables ?? [collection];\n\t\t\t\t\t// Declarative read rule + schema migration apply to single-table\n\t\t\t\t\t// collections (their rows are that table's rows); join/aggregate\n\t\t\t\t\t// collections scope via match.\n\t\t\t\t\tconst scopedTable =\n\t\t\t\t\t\ttables.length === 1 ? tables[0]! : undefined;\n\t\t\t\t\tconst readRule =\n\t\t\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t\t\t? readRuleFor(scopedTable)\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t// Migrate the DB result to the current shape, then filter it through the\n\t\t\t\t\t// read rule — so the initial snapshot and the refetch fallback are\n\t\t\t\t\t// always current-shape and never include a row the caller can't see.\n\t\t\t\t\tconst rehydrate = async () => {\n\t\t\t\t\t\tconst raw = [\n\t\t\t\t\t\t\t...(await definition.hydrate(params, ctx))\n\t\t\t\t\t\t];\n\t\t\t\t\t\tconst rows =\n\t\t\t\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t\t\t\t? raw.map((row) => migrateRow(scopedTable, row))\n\t\t\t\t\t\t\t\t: raw;\n\t\t\t\t\t\treturn readRule\n\t\t\t\t\t\t\t? rows.filter((row) => readRule(ctx, row))\n\t\t\t\t\t\t\t: rows;\n\t\t\t\t\t};\n\t\t\t\t\t// Incremental matching only applies to single-table collections; a\n\t\t\t\t\t// join/aggregate spanning tables can't match a single row, so it uses\n\t\t\t\t\t// the refetch fallback.\n\t\t\t\t\tconst incremental =\n\t\t\t\t\t\tmatch !== undefined && tables.length === 1;\n\t\t\t\t\t// Fold the read rule into the incremental predicate (also used by the\n\t\t\t\t\t// catch-up builder), so an unreadable row never enters the view.\n\t\t\t\t\tconst boundMatch = incremental\n\t\t\t\t\t\t? (row: unknown) =>\n\t\t\t\t\t\t\t\tmatch(row, params, ctx) &&\n\t\t\t\t\t\t\t\t(readRule ? readRule(ctx, row) : true)\n\t\t\t\t\t\t: () => true;\n\t\t\t\t\tconst view = createMaterializedView<unknown>({\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tmatch: boundMatch\n\t\t\t\t\t});\n\n\t\t\t\t\t// Resume from the log when possible (catch-up diff); else send a\n\t\t\t\t\t// snapshot. The view is hydrated either way so future changes match.\n\t\t\t\t\tconst resuming =\n\t\t\t\t\t\tsince !== undefined && canResume(since, incremental);\n\t\t\t\t\tview.hydrate([...(await rehydrate())]);\n\t\t\t\t\tconst atVersion = version;\n\n\t\t\t\t\tconst subscription: ActiveSubscription = {\n\t\t\t\t\t\tkind: 'view',\n\t\t\t\t\t\tcollection,\n\t\t\t\t\t\tview,\n\t\t\t\t\t\tincremental,\n\t\t\t\t\t\trehydrate,\n\t\t\t\t\t\tkey,\n\t\t\t\t\t\tonDiff: typedOnDiff\n\t\t\t\t\t};\n\t\t\t\t\tsubscribeSet.add(subscription);\n\n\t\t\t\t\tconst unsubscribe = () => {\n\t\t\t\t\t\tsubscribeSet.delete(subscription);\n\t\t\t\t\t};\n\n\t\t\t\t\tif (resuming) {\n\t\t\t\t\t\treturn wrapReturn({\n\t\t\t\t\t\t\tinitial: [],\n\t\t\t\t\t\t\tcatchup: buildCatchup(\n\t\t\t\t\t\t\t\tsince,\n\t\t\t\t\t\t\t\ttables,\n\t\t\t\t\t\t\t\tkey,\n\t\t\t\t\t\t\t\tboundMatch\n\t\t\t\t\t\t\t) as ViewDiff<never>,\n\t\t\t\t\t\t\tcursor: currentCursor(),\n\t\t\t\t\t\t\tversion: atVersion,\n\t\t\t\t\t\t\tunsubscribe\n\t\t\t\t\t\t}) as Subscription<never>;\n\t\t\t\t\t}\n\t\t\t\t\treturn wrapReturn({\n\t\t\t\t\t\tinitial: view.rows() as never[],\n\t\t\t\t\t\tcursor: currentCursor(),\n\t\t\t\t\t\tversion: atVersion,\n\t\t\t\t\t\tunsubscribe\n\t\t\t\t\t}) as Subscription<never>;\n\t\t\t\t} catch (error) {\n\t\t\t\t\t// (1.20.1) If anything between acquire and the successful\n\t\t\t\t\t// return throws (authorize, abort, schema error, etc.),\n\t\t\t\t\t// release the tenant slot so the cap doesn't leak by one\n\t\t\t\t\t// per failed call.\n\t\t\t\t\tif (!slotHandedOff) releaseSubscriptionSlot(tenantSlot);\n\t\t\t\t\tthrow error;\n\t\t\t\t}\n\t\t\t} catch (spanError) {\n\t\t\t\t// 1.21.0: outer span wrap — re-throw, recording any\n\t\t\t\t// failure (subscribe-time errors are common and worth\n\t\t\t\t// surfacing).\n\t\t\t\tsubscribeSpan.recordException(spanError);\n\t\t\t\tsubscribeSpan.setStatus({\n\t\t\t\t\tcode: 2 /* SpanStatusCode.ERROR */,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tspanError instanceof Error\n\t\t\t\t\t\t\t? spanError.message\n\t\t\t\t\t\t\t: String(spanError)\n\t\t\t\t});\n\t\t\t\tthrow spanError;\n\t\t\t} finally {\n\t\t\t\tsubscribeSpan.end();\n\t\t\t}\n\t\t},\n\n\t\thydrate: async (collection, params, ctx, options) => {\n\t\t\tconst signal = options?.signal;\n\t\t\tcheckAborted(signal);\n\t\t\tconst definition = registry.get(collection) as\n\t\t\t\t| CollectionDefinition<unknown, unknown, unknown>\n\t\t\t\t| undefined;\n\t\t\tif (definition === undefined) {\n\t\t\t\tthrow new Error(`Unknown collection \"${collection}\"`);\n\t\t\t}\n\t\t\tif (definition.authorize !== undefined) {\n\t\t\t\tconst allowed = await definition.authorize(params, ctx);\n\t\t\t\tcheckAborted(signal);\n\t\t\t\tif (!allowed) {\n\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t`hydrate collection \"${collection}\"`\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tconst raw = [...(await definition.hydrate(params, ctx))];\n\t\t\tcheckAborted(signal);\n\t\t\tconst tables = definition.tables ?? [collection];\n\t\t\tconst scopedTable = tables.length === 1 ? tables[0]! : undefined;\n\t\t\tconst rows =\n\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t? raw.map((row) => migrateRow(scopedTable, row))\n\t\t\t\t\t: raw;\n\t\t\tconst readRule =\n\t\t\t\tscopedTable !== undefined\n\t\t\t\t\t? readRuleFor(scopedTable)\n\t\t\t\t\t: undefined;\n\t\t\treturn readRule ? rows.filter((row) => readRule(ctx, row)) : rows;\n\t\t},\n\n\t\tapplyChange: (table, change) =>\n\t\t\tapplyChange(table, change as RowChange<unknown>),\n\n\t\tconnectSource: async (source) => {\n\t\t\tawait source.start((table, change) => applyChange(table, change));\n\t\t\treturn async () => {\n\t\t\t\tawait source.stop();\n\t\t\t};\n\t\t},\n\n\t\tconnectCluster: async (bus) => {\n\t\t\tconst unsubscribe = await bus.subscribe((message) => {\n\t\t\t\t// Ignore our own broadcasts; apply peers' changes locally without\n\t\t\t\t// re-broadcasting (that would loop).\n\t\t\t\tif (message.origin === instanceId) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// 1.17.0 — log peer changes with their origin + originVersion\n\t\t\t\t// so a client carrying a cross-instance cursor can resume\n\t\t\t\t// against them. Pre-1.17 buses that don't carry originVersion\n\t\t\t\t// default to 0 (any cross-instance resume falls back to a\n\t\t\t\t// snapshot — matches pre-1.17 behavior exactly).\n\t\t\t\tvoid applyChangeBatch(message.changes, false, {\n\t\t\t\t\torigin: message.origin,\n\t\t\t\t\toriginVersion: message.originVersion ?? 0\n\t\t\t\t});\n\t\t\t});\n\t\t\tclusterBus = bus;\n\n\t\t\treturn async () => {\n\t\t\t\tclusterBus = undefined;\n\t\t\t\tawait unsubscribe();\n\t\t\t};\n\t\t},\n\n\t\tsubscriptionCount: (collection) => {\n\t\t\tif (collection !== undefined) {\n\t\t\t\treturn active.get(collection)?.size ?? 0;\n\t\t\t}\n\t\t\tlet total = 0;\n\t\t\tfor (const set of active.values()) {\n\t\t\t\ttotal += set.size;\n\t\t\t}\n\t\t\treturn total;\n\t\t},\n\n\t\tregisterMutation: (mutation) => {\n\t\t\tif (\n\t\t\t\tmutation.handler === undefined &&\n\t\t\t\tmutation.sandboxedHandler === undefined\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Mutation \"${mutation.name}\" must define either \\`handler\\` or \\`sandboxedHandler\\``\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (\n\t\t\t\tmutation.handler !== undefined &&\n\t\t\t\tmutation.sandboxedHandler !== undefined\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Mutation \"${mutation.name}\" defines both \\`handler\\` and \\`sandboxedHandler\\` — pick one`\n\t\t\t\t);\n\t\t\t}\n\t\t\tmutations.set(mutation.name, mutation);\n\t\t\t// Build the sandbox runner eagerly only if we know the source —\n\t\t\t// the actual isolate spawn is still lazy (inside makeSandboxedHandler).\n\t\t\tif (mutation.sandboxedHandler !== undefined) {\n\t\t\t\tsandboxRunners.set(\n\t\t\t\t\tmutation.name,\n\t\t\t\t\tmakeSandboxedHandler(\n\t\t\t\t\t\tmutation.sandboxedHandler,\n\t\t\t\t\t\tmutation.sandbox,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tbridgeFetch: options.bridgeFetch,\n\t\t\t\t\t\t\tmetricsHook:\n\t\t\t\t\t\t\t\toptions.handlerMetrics === undefined\n\t\t\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\t\t\t\tmutationName: mutation.name,\n\t\t\t\t\t\t\t\t\t\t\tonMetrics: options.handlerMetrics\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\t\t},\n\n\t\tregisterWriter: (table, writer) => {\n\t\t\twriters.set(table, writer as TableWriter);\n\t\t},\n\n\t\tregisterReactive: (query) => {\n\t\t\tregistry.set(query.name, query);\n\t\t},\n\n\t\tregisterReader: (table, reader) => {\n\t\t\treaders.set(table, reader as TableReader);\n\t\t},\n\n\t\tregisterPermissions: (table, rules) => {\n\t\t\tpermissions.set(table, rules as TablePermissions<unknown, unknown>);\n\t\t},\n\n\t\tregisterSchema: (table, schema) => {\n\t\t\tschemas.set(table, schema as TableSchema<unknown>);\n\t\t},\n\n\t\tregisterCrdt: (table, fields) => {\n\t\t\tcrdtFields.set(\n\t\t\t\ttable,\n\t\t\t\tfields as Record<string, CrdtMergeable<unknown>>\n\t\t\t);\n\t\t\t// A ready-made merge mutation so a client needs no custom server code:\n\t\t\t// upsert the row patch — the CRDT auto-merge in makeActions folds the\n\t\t\t// declared fields into the stored row. Named \"<table>:merge\".\n\t\t\tconst name = `${table}:merge`;\n\t\t\tmutations.set(name, {\n\t\t\t\thandler: async (args, ctx, actions) => {\n\t\t\t\t\tconst existing = await readExisting(table, args, ctx);\n\t\t\t\t\treturn existing === undefined\n\t\t\t\t\t\t? actions.insert(table, args)\n\t\t\t\t\t\t: actions.update(table, args);\n\t\t\t\t},\n\t\t\t\tname\n\t\t\t} as MutationDefinition<unknown, unknown, unknown>);\n\t\t},\n\n\t\tmigrate: (table, row) => migrateRow(table, row) as typeof row,\n\n\t\trunMutation: async (name, args, ctx) => {\n\t\t\t// 1.21.0: wrap the entire mutation lifecycle in a span. Noop\n\t\t\t// when no tracerProvider was supplied.\n\t\t\tconst span = tracer.startSpan('sync.runMutation', {\n\t\t\t\tattributes: {\n\t\t\t\t\t[ABS_ATTRS.engineId]: instanceId,\n\t\t\t\t\t[ABS_ATTRS.mutation]: name\n\t\t\t\t}\n\t\t\t});\n\t\t\ttry {\n\t\t\t\t// 1.24.0: reject early when fenced — before authorize, before\n\t\t\t\t// slot acquisition. Operators expect a fenced engine to be a\n\t\t\t\t// hard wall, not a queue.\n\t\t\t\tif (activeFences.size > 0) {\n\t\t\t\t\tconst oldest = activeFences.values().next()\n\t\t\t\t\t\t.value as FenceHandle;\n\t\t\t\t\tthrow new EngineFencedError(oldest.reason);\n\t\t\t\t}\n\t\t\t\tconst mutation = mutations.get(name);\n\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\tthrow new Error(`Unknown mutation \"${name}\"`);\n\t\t\t\t}\n\t\t\t\tif (mutation.authorize !== undefined) {\n\t\t\t\t\tconst allowed = await mutation.authorize(args, ctx);\n\t\t\t\t\tif (!allowed) {\n\t\t\t\t\t\tthrow new UnauthorizedError(`run mutation \"${name}\"`);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// 1.20.0: gate at the entry. Wait if `mutationConcurrency`\n\t\t\t\t// is saturated; throw `MutationQueueOverflowError` if the\n\t\t\t\t// queue is also capped and full. Authorization fails before\n\t\t\t\t// the gate so a denied call never burns a slot.\n\t\t\t\tawait acquireMutationSlot();\n\n\t\t\t\t// Pick the handler shape: in-process function or sandboxed string\n\t\t\t\t// source (runs inside @absolutejs/isolated-jsc). Sandbox runner is\n\t\t\t\t// built lazily and pre-cached in registerMutation.\n\t\t\t\tconst sandboxRunner = sandboxRunners.get(name);\n\t\t\t\tconst invokeHandler =\n\t\t\t\t\tsandboxRunner !== undefined\n\t\t\t\t\t\t? sandboxRunner\n\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\ta: unknown,\n\t\t\t\t\t\t\t\tc: unknown,\n\t\t\t\t\t\t\t\tactions: MutationActions\n\t\t\t\t\t\t\t): Promise<unknown> =>\n\t\t\t\t\t\t\t\tPromise.resolve(\n\t\t\t\t\t\t\t\t\t// Non-null assertion: registerMutation guarantees one of\n\t\t\t\t\t\t\t\t\t// handler/sandboxedHandler is defined.\n\t\t\t\t\t\t\t\t\tmutation.handler!(a, c, actions)\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t// Run the handler (optionally inside the DB transaction), collecting its\n\t\t\t\t// changes into a fresh buffer per attempt — so a transaction that retries\n\t\t\t\t// or rolls back never double-emits or leaks a half-applied batch.\n\t\t\t\tconst runHandler = async (tx: unknown) => {\n\t\t\t\t\tconst { actions, buffered } = makeActions(tx, ctx, true);\n\t\t\t\t\tconst result = await invokeHandler(args, ctx, actions);\n\t\t\t\t\treturn { buffered, result };\n\t\t\t\t};\n\n\t\t\t\t// Resolve the retry policy once per call. When `mutation.retry` is\n\t\t\t\t// undefined we still go through the loop, but bounded to one\n\t\t\t\t// attempt with no backoff (cheaper than a separate code path).\n\t\t\t\tconst retry = mutation.retry;\n\t\t\t\tconst maxAttempts =\n\t\t\t\t\tretry === undefined ? 1 : (retry.maxAttempts ?? 5);\n\t\t\t\tconst isRetryable =\n\t\t\t\t\tretry?.isRetryable ?? isSerializationFailure;\n\t\t\t\tconst computeDelay = retry?.backoff ?? exponentialBackoff();\n\t\t\t\tconst maxElapsedMs = retry?.maxElapsedMs ?? 30_000;\n\t\t\t\tconst startedAt = Date.now();\n\n\t\t\t\t// Each attempt builds fresh `actions`/`buffered` via the makeActions\n\t\t\t\t// call inside runHandler, so a retry never inherits half-applied\n\t\t\t\t// buffered changes from a failed attempt. Transactions reopen too:\n\t\t\t\t// runInTransaction wraps each individual attempt.\n\t\t\t\tlet lastError: unknown;\n\t\t\t\tlet attemptsMade = 0;\n\t\t\t\ttry {\n\t\t\t\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\t\t\t\tattemptsMade = attempt;\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst { buffered, result } =\n\t\t\t\t\t\t\t\trunInTransaction !== undefined\n\t\t\t\t\t\t\t\t\t? await runInTransaction((tx) =>\n\t\t\t\t\t\t\t\t\t\t\trunHandler(tx)\n\t\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t\t: await runHandler(undefined);\n\t\t\t\t\t\t\tawait applyChangeBatch(buffered);\n\t\t\t\t\t\t\tmutationsCompleted += 1;\n\t\t\t\t\t\t\temitActivity({\n\t\t\t\t\t\t\t\ttype: 'mutation',\n\t\t\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tstatus: 'ok'\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\treturn result;\n\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\tlastError = error;\n\t\t\t\t\t\t\tconst elapsedMs = Date.now() - startedAt;\n\t\t\t\t\t\t\tconst canRetry =\n\t\t\t\t\t\t\t\tattempt < maxAttempts &&\n\t\t\t\t\t\t\t\tisRetryable(error) &&\n\t\t\t\t\t\t\t\telapsedMs < maxElapsedMs;\n\t\t\t\t\t\t\tif (!canRetry) break;\n\t\t\t\t\t\t\tmutationsRetried += 1;\n\n\t\t\t\t\t\t\tconst rawDelay = computeDelay(attempt);\n\t\t\t\t\t\t\t// Cap the delay so we don't blow past maxElapsedMs while\n\t\t\t\t\t\t\t// sleeping. If the cap would be negative we're already past\n\t\t\t\t\t\t\t// the budget; treat as exhausted.\n\t\t\t\t\t\t\tconst remaining = maxElapsedMs - elapsedMs;\n\t\t\t\t\t\t\tif (remaining <= 0) break;\n\t\t\t\t\t\t\tconst delayMs = Math.max(\n\t\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t\t\tMath.min(rawDelay, remaining)\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\temitActivity({\n\t\t\t\t\t\t\t\ttype: 'mutationRetry',\n\t\t\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\t\t\tname,\n\t\t\t\t\t\t\t\tattempt,\n\t\t\t\t\t\t\t\tdelayMs,\n\t\t\t\t\t\t\t\terrorName:\n\t\t\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t\t\t? error.name\n\t\t\t\t\t\t\t\t\t\t: 'Error',\n\t\t\t\t\t\t\t\terrorMessage:\n\t\t\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t\t\t\t: String(error)\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (delayMs > 0) {\n\t\t\t\t\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\t\t\t\t\tsetTimeout(resolve, delayMs)\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tmutationsFailed += 1;\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'mutation',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tstatus: 'error'\n\t\t\t\t\t});\n\t\t\t\t\t// Wrap only when we actually burned through more than one attempt\n\t\t\t\t\t// — a non-retryable first-attempt failure passes through with its\n\t\t\t\t\t// original error preserved, even if `retry` is configured.\n\t\t\t\t\tif (attemptsMade > 1) {\n\t\t\t\t\t\tthrow new RetriesExhaustedError(\n\t\t\t\t\t\t\tattemptsMade,\n\t\t\t\t\t\t\tDate.now() - startedAt,\n\t\t\t\t\t\t\tlastError\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tthrow lastError;\n\t\t\t\t} finally {\n\t\t\t\t\treleaseMutationSlot();\n\t\t\t\t}\n\t\t\t} catch (spanError) {\n\t\t\t\t// 1.21.0: outer span wrap — record any throw, rethrow.\n\t\t\t\tspan.recordException(spanError);\n\t\t\t\tspan.setStatus({\n\t\t\t\t\tcode: 2 /* SpanStatusCode.ERROR */,\n\t\t\t\t\tmessage:\n\t\t\t\t\t\tspanError instanceof Error\n\t\t\t\t\t\t\t? spanError.message\n\t\t\t\t\t\t\t: String(spanError)\n\t\t\t\t});\n\t\t\t\tthrow spanError;\n\t\t\t} finally {\n\t\t\t\tspan.end();\n\t\t\t}\n\t\t},\n\n\t\trunMutations: async (specs, ctx) => {\n\t\t\t// Empty batch: short-circuit. Don't open a DB tx for nothing —\n\t\t\t// some adapters (PG with auto-commit, MySQL with implicit\n\t\t\t// commit, etc.) count even an empty BEGIN/COMMIT as a real\n\t\t\t// transaction, which is wasteful and noisy in observability.\n\t\t\tif (specs.length === 0) return [];\n\t\t\t// Snapshot the requested mutation names up front so the\n\t\t\t// authorization + handler resolution happens BEFORE we open\n\t\t\t// the DB transaction. A typo'd name aborts cleanly without\n\t\t\t// burning a tx.\n\t\t\tconst resolved = specs.map((spec) => {\n\t\t\t\tconst mutation = mutations.get(spec.name);\n\t\t\t\tif (mutation === undefined) {\n\t\t\t\t\tthrow new Error(`Unknown mutation \"${spec.name}\"`);\n\t\t\t\t}\n\t\t\t\treturn { args: spec.args, mutation, name: spec.name };\n\t\t\t});\n\t\t\t// 1.20.0: the whole batch is one slot. Resolve names BEFORE\n\t\t\t// the gate so an unknown-mutation typo never queues.\n\t\t\tawait acquireMutationSlot();\n\n\t\t\tconst runBatch = async (tx: unknown) => {\n\t\t\t\tconst results: unknown[] = [];\n\t\t\t\tconst accumulated: {\n\t\t\t\t\ttable: string;\n\t\t\t\t\tchange: RowChange<unknown>;\n\t\t\t\t}[] = [];\n\t\t\t\tfor (const { args, mutation, name } of resolved) {\n\t\t\t\t\tif (mutation.authorize !== undefined) {\n\t\t\t\t\t\tconst allowed = await mutation.authorize(args, ctx);\n\t\t\t\t\t\tif (!allowed) {\n\t\t\t\t\t\t\tthrow new UnauthorizedError(\n\t\t\t\t\t\t\t\t`run mutation \"${name}\"`\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tconst sandboxRunner = sandboxRunners.get(name);\n\t\t\t\t\tconst invokeHandler =\n\t\t\t\t\t\tsandboxRunner !== undefined\n\t\t\t\t\t\t\t? sandboxRunner\n\t\t\t\t\t\t\t: (\n\t\t\t\t\t\t\t\t\ta: unknown,\n\t\t\t\t\t\t\t\t\tc: unknown,\n\t\t\t\t\t\t\t\t\tactions: MutationActions\n\t\t\t\t\t\t\t\t): Promise<unknown> =>\n\t\t\t\t\t\t\t\t\tPromise.resolve(\n\t\t\t\t\t\t\t\t\t\tmutation.handler!(a, c, actions)\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t// Each handler gets its own `actions`/`buffered` so per-\n\t\t\t\t\t// call validation + crdt merges still work — we collect\n\t\t\t\t\t// the buffered tail into `accumulated` after each\n\t\t\t\t\t// handler returns. If the next handler throws, the\n\t\t\t\t\t// surrounding `runInTransaction` rolls everything back;\n\t\t\t\t\t// applyChangeBatch never runs.\n\t\t\t\t\tconst { actions, buffered } = makeActions(tx, ctx, true);\n\t\t\t\t\tconst result = await invokeHandler(args, ctx, actions);\n\t\t\t\t\tresults.push(result);\n\t\t\t\t\taccumulated.push(...buffered);\n\t\t\t\t}\n\t\t\t\treturn { accumulated, results };\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst { accumulated, results } =\n\t\t\t\t\trunInTransaction !== undefined\n\t\t\t\t\t\t? await runInTransaction((tx) => runBatch(tx))\n\t\t\t\t\t\t: await runBatch(undefined);\n\t\t\t\tawait applyChangeBatch(accumulated);\n\t\t\t\temitActivity({\n\t\t\t\t\ttype: 'mutationBatch',\n\t\t\t\t\tat: Date.now(),\n\t\t\t\t\tnames: resolved.map((entry) => entry.name),\n\t\t\t\t\tstatus: 'ok'\n\t\t\t\t});\n\t\t\t\treturn results;\n\t\t\t} catch (error) {\n\t\t\t\temitActivity({\n\t\t\t\t\ttype: 'mutationBatch',\n\t\t\t\t\tat: Date.now(),\n\t\t\t\t\tnames: resolved.map((entry) => entry.name),\n\t\t\t\t\tstatus: 'error'\n\t\t\t\t});\n\t\t\t\tthrow error;\n\t\t\t} finally {\n\t\t\t\treleaseMutationSlot();\n\t\t\t}\n\t\t},\n\n\t\tregisterSchedule: (schedule) => {\n\t\t\tschedules.set(schedule.name, schedule);\n\t\t},\n\n\t\tlistSchedules: () => [...schedules.values()],\n\n\t\trunSchedule: async (name) => {\n\t\t\tconst schedule = schedules.get(name);\n\t\t\tif (schedule === undefined) {\n\t\t\t\tthrow new Error(`Unknown schedule \"${name}\"`);\n\t\t\t}\n\t\t\t// A schedule reads unscoped and writes without permission checks (it's\n\t\t\t// trusted server code); its writes emit as one live batch like a mutation.\n\t\t\tconst runHandler = async (tx: unknown) => {\n\t\t\t\tconst { actions, buffered } = makeActions(tx, {}, false);\n\t\t\t\tconst db = makeReadHandle({}, new Set(), new Set(), [], false);\n\t\t\t\tawait schedule.run({ actions, db });\n\t\t\t\treturn buffered;\n\t\t\t};\n\n\t\t\tconst retry = schedule.retry;\n\t\t\tconst maxAttempts =\n\t\t\t\tretry === undefined ? 1 : (retry.maxAttempts ?? 5);\n\t\t\tconst isRetryable = retry?.isRetryable ?? isSerializationFailure;\n\t\t\tconst computeDelay = retry?.backoff ?? exponentialBackoff();\n\t\t\tconst maxElapsedMs = retry?.maxElapsedMs ?? 30_000;\n\t\t\tconst startedAt = Date.now();\n\n\t\t\tlet lastError: unknown;\n\t\t\tlet attemptsMade = 0;\n\t\t\tfor (let attempt = 1; attempt <= maxAttempts; attempt++) {\n\t\t\t\tattemptsMade = attempt;\n\t\t\t\ttry {\n\t\t\t\t\tconst buffered =\n\t\t\t\t\t\trunInTransaction !== undefined\n\t\t\t\t\t\t\t? await runInTransaction((tx) => runHandler(tx))\n\t\t\t\t\t\t\t: await runHandler(undefined);\n\t\t\t\t\tawait applyChangeBatch(buffered);\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'schedule',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tstatus: 'ok'\n\t\t\t\t\t});\n\t\t\t\t\treturn;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tlastError = error;\n\t\t\t\t\tconst elapsedMs = Date.now() - startedAt;\n\t\t\t\t\tconst canRetry =\n\t\t\t\t\t\tattempt < maxAttempts &&\n\t\t\t\t\t\tisRetryable(error) &&\n\t\t\t\t\t\telapsedMs < maxElapsedMs;\n\t\t\t\t\tif (!canRetry) break;\n\n\t\t\t\t\tconst rawDelay = computeDelay(attempt);\n\t\t\t\t\tconst remaining = maxElapsedMs - elapsedMs;\n\t\t\t\t\tif (remaining <= 0) break;\n\t\t\t\t\tconst delayMs = Math.max(0, Math.min(rawDelay, remaining));\n\n\t\t\t\t\temitActivity({\n\t\t\t\t\t\ttype: 'scheduleRetry',\n\t\t\t\t\t\tat: Date.now(),\n\t\t\t\t\t\tname,\n\t\t\t\t\t\tattempt,\n\t\t\t\t\t\tdelayMs,\n\t\t\t\t\t\terrorName:\n\t\t\t\t\t\t\terror instanceof Error ? error.name : 'Error',\n\t\t\t\t\t\terrorMessage:\n\t\t\t\t\t\t\terror instanceof Error\n\t\t\t\t\t\t\t\t? error.message\n\t\t\t\t\t\t\t\t: String(error)\n\t\t\t\t\t});\n\t\t\t\t\tif (delayMs > 0) {\n\t\t\t\t\t\tawait new Promise((resolve) =>\n\t\t\t\t\t\t\tsetTimeout(resolve, delayMs)\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\temitActivity({\n\t\t\t\ttype: 'schedule',\n\t\t\t\tat: Date.now(),\n\t\t\t\tname,\n\t\t\t\tstatus: 'error'\n\t\t\t});\n\t\t\tif (attemptsMade > 1) {\n\t\t\t\tthrow new RetriesExhaustedError(\n\t\t\t\t\tattemptsMade,\n\t\t\t\t\tDate.now() - startedAt,\n\t\t\t\t\tlastError\n\t\t\t\t);\n\t\t\t}\n\t\t\tthrow lastError;\n\t\t},\n\n\t\tregisterPack: (pack) => {\n\t\t\tfor (const table of pack.ownsTables) {\n\t\t\t\tconst existing = packTableOwners.get(table);\n\t\t\t\tif (existing !== undefined) {\n\t\t\t\t\tthrow new PackTableConflictError(\n\t\t\t\t\t\ttable,\n\t\t\t\t\t\texisting,\n\t\t\t\t\t\tpack.name\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.requireDependencies === true) {\n\t\t\t\tfor (const table of pack.readsTables ?? []) {\n\t\t\t\t\tif (!readers.has(table)) {\n\t\t\t\t\t\tthrow new PackMissingDependencyError(pack.name, table);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.schemas !== undefined) {\n\t\t\t\tfor (const [table, schema] of Object.entries(pack.schemas)) {\n\t\t\t\t\tengine.registerSchema(table, schema);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.permissions !== undefined) {\n\t\t\t\tfor (const [table, rules] of Object.entries(pack.permissions)) {\n\t\t\t\t\tengine.registerPermissions(table, rules);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.readers !== undefined) {\n\t\t\t\tfor (const [table, reader] of Object.entries(pack.readers)) {\n\t\t\t\t\tengine.registerReader(table, reader);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.writers !== undefined) {\n\t\t\t\tfor (const [table, writer] of Object.entries(pack.writers)) {\n\t\t\t\t\tengine.registerWriter(table, writer);\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (pack.crdt !== undefined) {\n\t\t\t\tfor (const [table, fields] of Object.entries(pack.crdt)) {\n\t\t\t\t\tengine.registerCrdt(table, fields);\n\t\t\t\t}\n\t\t\t}\n\t\t\tfor (const collection of pack.collections ?? []) {\n\t\t\t\tengine.register(collection);\n\t\t\t}\n\t\t\tfor (const collection of pack.joinCollections ?? []) {\n\t\t\t\tengine.registerJoin(collection);\n\t\t\t}\n\t\t\tfor (const collection of pack.graphCollections ?? []) {\n\t\t\t\tengine.registerGraph(collection);\n\t\t\t}\n\t\t\tfor (const collection of pack.searchCollections ?? []) {\n\t\t\t\tengine.registerSearch(collection);\n\t\t\t}\n\t\t\tfor (const query of pack.reactiveQueries ?? []) {\n\t\t\t\tengine.registerReactive(query);\n\t\t\t}\n\t\t\tfor (const mutation of pack.mutations ?? []) {\n\t\t\t\tengine.registerMutation(mutation);\n\t\t\t}\n\t\t\tfor (const schedule of pack.schedules ?? []) {\n\t\t\t\tengine.registerSchedule(schedule);\n\t\t\t}\n\t\t\tfor (const table of pack.ownsTables) {\n\t\t\t\tpackTableOwners.set(table, pack.name);\n\t\t\t}\n\t\t\tregisteredPacks.push({\n\t\t\t\tname: pack.name,\n\t\t\t\tversion: pack.version,\n\t\t\t\townsTables: [...pack.ownsTables],\n\t\t\t\treadsTables: [...(pack.readsTables ?? [])]\n\t\t\t});\n\t\t},\n\n\t\tinspect: () => {\n\t\t\tconst collections = [...registry.entries()].map(([name, def]) => {\n\t\t\t\tconst kind = ((def as { kind?: CollectionKind }).kind ??\n\t\t\t\t\t'view') as CollectionKind;\n\t\t\t\tlet tables: string[] = [];\n\t\t\t\tif (kind === 'join') {\n\t\t\t\t\tconst join = def as JoinCollectionDefinition<\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown,\n\t\t\t\t\t\tunknown\n\t\t\t\t\t>;\n\t\t\t\t\ttables = [join.left.table, join.right.table];\n\t\t\t\t} else if (kind === 'graph') {\n\t\t\t\t\ttables = (\n\t\t\t\t\t\tdef as GraphCollectionDefinition<\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t>\n\t\t\t\t\t).query.tables();\n\t\t\t\t} else if (kind === 'search') {\n\t\t\t\t\ttables = [\n\t\t\t\t\t\t(\n\t\t\t\t\t\t\tdef as SearchCollectionDefinition<\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown,\n\t\t\t\t\t\t\t\tunknown\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t).table\n\t\t\t\t\t];\n\t\t\t\t} else if (kind === 'view') {\n\t\t\t\t\ttables = (\n\t\t\t\t\t\tdef as CollectionDefinition<unknown, unknown, unknown>\n\t\t\t\t\t).tables ?? [name];\n\t\t\t\t}\n\t\t\t\treturn {\n\t\t\t\t\tname,\n\t\t\t\t\tkind,\n\t\t\t\t\ttables,\n\t\t\t\t\tsubscriptions: active.get(name)?.size ?? 0\n\t\t\t\t};\n\t\t\t});\n\t\t\tconst DEVTOOLS_RECENT = 50;\n\t\t\treturn {\n\t\t\t\tversion,\n\t\t\t\tcollections,\n\t\t\t\tmutations: [...mutations.keys()],\n\t\t\t\tschedules: [...schedules.values()].map((schedule) => ({\n\t\t\t\t\tname: schedule.name,\n\t\t\t\t\tpattern: schedule.pattern\n\t\t\t\t})),\n\t\t\t\treaders: [...readers.keys()],\n\t\t\t\twriters: [...writers.keys()],\n\t\t\t\trecentChanges: changeLog\n\t\t\t\t\t.slice(-DEVTOOLS_RECENT)\n\t\t\t\t\t.map((entry) => ({\n\t\t\t\t\t\tversion: entry.version,\n\t\t\t\t\t\ttable: entry.table,\n\t\t\t\t\t\top: entry.change.op\n\t\t\t\t\t})),\n\t\t\t\tpacks: registeredPacks.map((pack) => ({\n\t\t\t\t\tname: pack.name,\n\t\t\t\t\tversion: pack.version,\n\t\t\t\t\townsTables: [...pack.ownsTables],\n\t\t\t\t\treadsTables: [...pack.readsTables]\n\t\t\t\t}))\n\t\t\t};\n\t\t},\n\n\t\texportChangeLog: () => ({\n\t\t\tentries: changeLog.slice(),\n\t\t\texportedAt: Date.now(),\n\t\t\tinstanceId,\n\t\t\tversion\n\t\t}),\n\n\t\timportChangeLog,\n\n\t\treplayTo: async ({ at, tables }) => {\n\t\t\t// 1.22.0: walk the bounded change log forward to targetAt,\n\t\t\t// folding each op into a per-table keyed view. Last write\n\t\t\t// wins per key. Delete removes the key.\n\t\t\tconst filterTables =\n\t\t\t\ttables !== undefined ? new Set(tables) : undefined;\n\t\t\tconst state = new Map<string, Map<RowKey, unknown>>();\n\t\t\tlet asOfVersion = 0;\n\t\t\tlet asOfAt = 0;\n\t\t\t// Truncation: the log doesn't extend back to `at`. We've\n\t\t\t// trimmed entries that may have mattered for the\n\t\t\t// reconstruction, so the result is \"state walked forward\n\t\t\t// from the OLDEST retained entry\" rather than the actual\n\t\t\t// state at `at`. Distinguishable from \"no history at all\"\n\t\t\t// (`changeLog[0]?.version === 1`).\n\t\t\tconst oldest = changeLog[0];\n\t\t\tconst truncated =\n\t\t\t\toldest !== undefined && oldest.version > 1 && oldest.at > at;\n\t\t\tfor (const entry of changeLog) {\n\t\t\t\tif (entry.at > at) break;\n\t\t\t\tif (\n\t\t\t\t\tfilterTables !== undefined &&\n\t\t\t\t\t!filterTables.has(entry.table)\n\t\t\t\t) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tlet tableState = state.get(entry.table);\n\t\t\t\tif (tableState === undefined) {\n\t\t\t\t\ttableState = new Map();\n\t\t\t\t\tstate.set(entry.table, tableState);\n\t\t\t\t}\n\t\t\t\tconst reader = readers.get(entry.table);\n\t\t\t\tconst key =\n\t\t\t\t\treader?.key?.(entry.change.row) ??\n\t\t\t\t\t((entry.change.row as { id?: RowKey })?.id as RowKey);\n\t\t\t\tif (key === undefined) {\n\t\t\t\t\t// Without a stable key we can't apply ops idempotently\n\t\t\t\t\t// — skip silently. In practice every table the\n\t\t\t\t\t// engine has emitted changes for has a reader (the\n\t\t\t\t\t// engine's own change-emit path doesn't run without\n\t\t\t\t\t// one), so this branch is defensive.\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tif (entry.change.op === 'delete') {\n\t\t\t\t\ttableState.delete(key);\n\t\t\t\t} else {\n\t\t\t\t\ttableState.set(key, entry.change.row);\n\t\t\t\t}\n\t\t\t\tasOfVersion = entry.version;\n\t\t\t\tasOfAt = entry.at;\n\t\t\t}\n\t\t\tconst rows: Record<string, ReadonlyArray<unknown>> = {};\n\t\t\tfor (const [table, map] of state) {\n\t\t\t\trows[table] = [...map.values()];\n\t\t\t}\n\t\t\treturn { asOfAt, asOfVersion, rows, truncated };\n\t\t},\n\n\t\tfence: ({ reason }) => {\n\t\t\tconst handle: FenceHandle = {\n\t\t\t\tfencedAt: Date.now(),\n\t\t\t\treason,\n\t\t\t\tlift: () => {\n\t\t\t\t\tactiveFences.delete(handle);\n\t\t\t\t}\n\t\t\t};\n\t\t\tactiveFences.add(handle);\n\t\t\treturn handle;\n\t\t},\n\n\t\texportSnapshot: async ({\n\t\t\ttables,\n\t\t\tctx = {}\n\t\t}: ExportSnapshotOptions = {}) => {\n\t\t\tconst tableFilter =\n\t\t\t\ttables !== undefined ? new Set(tables) : undefined;\n\t\t\tconst rows: Record<string, ReadonlyArray<unknown>> = {};\n\t\t\tfor (const [table, reader] of readers) {\n\t\t\t\tif (tableFilter !== undefined && !tableFilter.has(table)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst iterable = await reader.all(ctx);\n\t\t\t\trows[table] = [...iterable];\n\t\t\t}\n\t\t\treturn {\n\t\t\t\texportedAt: Date.now(),\n\t\t\t\tsourceInstanceId: instanceId,\n\t\t\t\ttables: rows,\n\t\t\t\tversion\n\t\t\t};\n\t\t},\n\n\t\timportSnapshot: async (\n\t\t\tsnapshot,\n\t\t\t{ tables, onProgress, ctx = {} }: ImportSnapshotOptions = {}\n\t\t) => {\n\t\t\tconst tableFilter =\n\t\t\t\ttables !== undefined ? new Set(tables) : undefined;\n\t\t\tconst perTable: Record<string, number> = {};\n\t\t\tconst skipped: string[] = [];\n\t\t\tlet tablesImported = 0;\n\t\t\tlet rowsImported = 0;\n\t\t\tfor (const [table, snapshotRows] of Object.entries(\n\t\t\t\tsnapshot.tables\n\t\t\t)) {\n\t\t\t\tif (tableFilter !== undefined && !tableFilter.has(table)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst writer = writers.get(table);\n\t\t\t\tif (writer === undefined) {\n\t\t\t\t\tskipped.push(table);\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tconst total = snapshotRows.length;\n\t\t\t\tlet done = 0;\n\t\t\t\tfor (const row of snapshotRows) {\n\t\t\t\t\tawait writer.insert(row, ctx, undefined);\n\t\t\t\t\tdone += 1;\n\t\t\t\t\trowsImported += 1;\n\t\t\t\t\tif (onProgress !== undefined) {\n\t\t\t\t\t\tonProgress(table, done, total);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tperTable[table] = done;\n\t\t\t\tif (done > 0) tablesImported += 1;\n\t\t\t}\n\t\t\treturn {\n\t\t\t\tperTable,\n\t\t\t\trowsImported,\n\t\t\t\tskipped,\n\t\t\t\ttablesImported\n\t\t\t};\n\t\t},\n\n\t\tmetrics: () => {\n\t\t\tconst now = Date.now();\n\t\t\tconst byCollection: Record<string, number> = {};\n\t\t\tlet totalSubscriptions = 0;\n\t\t\tfor (const [name, subs] of active) {\n\t\t\t\tbyCollection[name] = subs.size;\n\t\t\t\ttotalSubscriptions += subs.size;\n\t\t\t}\n\t\t\tconst oldest = changeLog[0];\n\t\t\treturn {\n\t\t\t\tat: now,\n\t\t\t\tchangeLog: {\n\t\t\t\t\tcapacity: changeLogSize,\n\t\t\t\t\tentries: changeLog.length,\n\t\t\t\t\toldestAgeMs: oldest ? now - oldest.at : null,\n\t\t\t\t\toldestVersion: oldest ? oldest.version : null,\n\t\t\t\t\tretainMs: changeLogRetainMs\n\t\t\t\t},\n\t\t\t\tmutations: {\n\t\t\t\t\tcompleted: mutationsCompleted,\n\t\t\t\t\tfailed: mutationsFailed,\n\t\t\t\t\tinFlight: mutationsInFlight,\n\t\t\t\t\tqueued: mutationsQueued,\n\t\t\t\t\tretried: mutationsRetried\n\t\t\t\t},\n\t\t\t\treactiveCache: {\n\t\t\t\t\tcapacity: reactiveCacheMax,\n\t\t\t\t\tentries: cachedReruns.size\n\t\t\t\t},\n\t\t\t\tschedules: {\n\t\t\t\t\tregistered: schedules.size\n\t\t\t\t},\n\t\t\t\tsubscriptions: {\n\t\t\t\t\tbyCollection,\n\t\t\t\t\tbyTenant: Object.fromEntries(subscriptionsByTenant),\n\t\t\t\t\ttotal: totalSubscriptions\n\t\t\t\t},\n\t\t\t\tuptimeMs: now - engineStartedAt,\n\t\t\t\tversion\n\t\t\t};\n\t\t},\n\n\t\tonActivity: (listener) => {\n\t\t\tactivityListeners.add(listener);\n\t\t\treturn () => {\n\t\t\t\tactivityListeners.delete(listener);\n\t\t\t};\n\t\t},\n\n\t\tstreamChanges: ({\n\t\t\tsince = 0,\n\t\t\tsignal,\n\t\t\tmaxBuffer = 10_000\n\t\t}: StreamChangesOptions = {}) => {\n\t\t\t// Detect a gap up front so the consumer's `for await` sees the\n\t\t\t// throw immediately rather than after the first historical entry.\n\t\t\t// (We tolerate `since === 0`, which means \"give me everything in\n\t\t\t// the log\"; the gap check only kicks in for a non-zero cursor.)\n\t\t\tconst oldest = changeLog[0];\n\t\t\tif (\n\t\t\t\tsince > 0 &&\n\t\t\t\toldest !== undefined &&\n\t\t\t\toldest.version > since + 1\n\t\t\t) {\n\t\t\t\tconst err = new MissedChangesError(since, oldest.version);\n\t\t\t\treturn {\n\t\t\t\t\t[Symbol.asyncIterator]() {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\tnext: () => Promise.reject(err)\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t}\n\n\t\t\t// Register the subscriber BEFORE snapshotting history so a commit\n\t\t\t// landing between the snapshot and the live tail can't be missed.\n\t\t\t// Phase 2 dedupes against `cursor`.\n\t\t\tconst buffer: LoggedChange[] = [];\n\t\t\tlet waiter: (() => void) | null = null;\n\t\t\tlet overflow = false;\n\t\t\tconst wake = () => {\n\t\t\t\tif (waiter !== null) {\n\t\t\t\t\tconst resume = waiter;\n\t\t\t\t\twaiter = null;\n\t\t\t\t\tresume();\n\t\t\t\t}\n\t\t\t};\n\t\t\tconst subscriber = (entry: LoggedChange) => {\n\t\t\t\tif (buffer.length >= maxBuffer) {\n\t\t\t\t\toverflow = true;\n\t\t\t\t\twake();\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tbuffer.push(entry);\n\t\t\t\twake();\n\t\t\t};\n\t\t\tstreamSubscribers.add(subscriber);\n\n\t\t\tconst onAbort = () => wake();\n\t\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\n\t\t\tlet lastDelivered = since;\n\n\t\t\treturn {\n\t\t\t\tasync *[Symbol.asyncIterator]() {\n\t\t\t\t\ttry {\n\t\t\t\t\t\t// Phase 1: historical entries. Copy the array so a\n\t\t\t\t\t\t// concurrent log.shift() (when the ring buffer rotates)\n\t\t\t\t\t\t// can't surprise us mid-iteration.\n\t\t\t\t\t\t//\n\t\t\t\t\t\t// A single batched mutation writes N rows that all\n\t\t\t\t\t\t// share one version, so we filter on `entry.version >\n\t\t\t\t\t\t// since` directly (no per-yield cursor bump — that\n\t\t\t\t\t\t// would deliver only the first row of every batch).\n\t\t\t\t\t\tconst history = [...changeLog];\n\t\t\t\t\t\tconst headVersion =\n\t\t\t\t\t\t\thistory.length > 0\n\t\t\t\t\t\t\t\t? history[history.length - 1]!.version\n\t\t\t\t\t\t\t\t: since;\n\t\t\t\t\t\tfor (const entry of history) {\n\t\t\t\t\t\t\tif (signal?.aborted) return;\n\t\t\t\t\t\t\tif (entry.version > since) {\n\t\t\t\t\t\t\t\tlastDelivered = entry.version;\n\t\t\t\t\t\t\t\tyield entry;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// Phase 2: live tail. Dedupe against `headVersion`\n\t\t\t\t\t\t// (the head of the log when phase 1 finished): any\n\t\t\t\t\t\t// buffered entry with `version <= headVersion` was\n\t\t\t\t\t\t// already yielded from history (a commit between\n\t\t\t\t\t\t// subscriber registration and the snapshot lands in\n\t\t\t\t\t\t// both the buffer and the snapshot).\n\t\t\t\t\t\twhile (!signal?.aborted) {\n\t\t\t\t\t\t\twhile (buffer.length > 0) {\n\t\t\t\t\t\t\t\tconst entry = buffer.shift()!;\n\t\t\t\t\t\t\t\tif (entry.version > headVersion) {\n\t\t\t\t\t\t\t\t\tlastDelivered = entry.version;\n\t\t\t\t\t\t\t\t\tyield entry;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (overflow) {\n\t\t\t\t\t\t\t\tthrow new CdcConsumerSlowError(\n\t\t\t\t\t\t\t\t\tmaxBuffer,\n\t\t\t\t\t\t\t\t\tlastDelivered\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (signal?.aborted) return;\n\t\t\t\t\t\t\tawait new Promise<void>((resolve) => {\n\t\t\t\t\t\t\t\twaiter = resolve;\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t}\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tstreamSubscribers.delete(subscriber);\n\t\t\t\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t};\n\t\t}\n\t};\n\n\treturn engine;\n};\n",
14
14
  "/**\n * `@absolutejs/sync/testing` — small helpers for testing sync engines and\n * sync packs. Importable from a focused subpath so pack repos don't pull\n * the whole sync barrel into their test surface area.\n *\n * What's here is intentionally tiny. Sync's own tests use\n * `createSyncEngine` directly, and that's still the right call for engine-\n * internal tests. This subpath is for *pack* tests and *consumer* tests\n * where the boilerplate of \"boot an engine, expect an async throw, drive\n * a mutation with a labelled actor\" repeats across every file.\n *\n * No new test framework is introduced — these are plain helpers you can\n * use with `bun:test`, `vitest`, or anything else.\n */\n\nimport {\n\tcreateSyncEngine,\n\ttype SyncEngine,\n\ttype SyncEngineOptions\n} from './engine/syncEngine';\n\n/**\n * Construct a {@link SyncEngine} for tests. Today this is a documented\n * re-export of {@link createSyncEngine} — the wrapper exists so callers\n * can clearly signal \"this engine is test-scoped\" at the call site, and\n * so future test-mode defaults (e.g. a synchronous in-memory transaction\n * runner) can be added without churning every test.\n *\n * Pass options through if you need a real transaction runner, schemas,\n * permissions, etc. — same shape as {@link createSyncEngine}.\n */\nexport const createTestEngine = (options?: SyncEngineOptions): SyncEngine =>\n\tcreateSyncEngine(options);\n\n/**\n * Await `work` and return the thrown value. Throws if `work` resolves —\n * use it inside tests that expect a specific rejection without relying\n * on `expect(...).rejects.toThrow(...)`, which has been flaky on Bun\n * 1.3.x (oven-sh/bun#31462). Equivalent to the `rejection()` helper\n * sync's own tests use.\n *\n * @example\n * const error = await expectRejection(() =>\n * engine.runMutation('comments:edit', { commentId, body }, { userId: 'eve' }),\n * );\n * expect((error as Error).message).toMatch(/not author/);\n */\nexport const expectRejection = async (\n\twork: () => unknown\n): Promise<unknown> => {\n\ttry {\n\t\tawait work();\n\t} catch (error) {\n\t\treturn error;\n\t}\n\tthrow new Error('expected `work` to reject but it resolved');\n};\n\n/**\n * Convenience: call `engine.runMutation` with an actor-id-shaped ctx.\n * Matches the standard pack convention (`getActorId: (ctx) => ctx.userId`).\n * Tests that don't need to vary other ctx fields can avoid the\n * `{ userId: 'alice' }` boilerplate.\n *\n * @example\n * await runAsActor(engine, 'alice', 'comments:create', {\n * resourceId: 'doc-1',\n * body: 'first',\n * });\n */\nexport const runAsActor = (\n\tengine: SyncEngine,\n\tactorId: string,\n\tmutation: string,\n\targs: unknown,\n\textraCtx?: Record<string, unknown>\n): Promise<unknown> =>\n\tengine.runMutation(mutation, args, { ...extraCtx, userId: actorId });\n"
15
15
  ],
16
- "mappings": ";;;;;;;;;;;;;;;;;;AAcA,IAAI,oBAAoB;AAAA,EACtB,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ,SAAS;AACX;AACA,IAAI,WAAW;AAAA,EACb,UAAU,MAAM;AAAA,EAChB,KAAK,MAAM;AAAA,EACX,aAAa,MAAM;AAAA,EACnB,iBAAiB,MAAM;AAAA,EACvB,cAAc,MAAM;AAAA,EACpB,eAAe,MAAM;AAAA,EACrB,WAAW,MAAM;AA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