@lunora/do 1.0.0-alpha.2 → 1.0.0-alpha.20

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.
Files changed (39) hide show
  1. package/__assets__/package-og.svg +1 -1
  2. package/dist/index.d.mts +1160 -114
  3. package/dist/index.d.ts +1160 -114
  4. package/dist/index.mjs +27 -22
  5. package/dist/packem_shared/{ADMIN_FUNCTION_PREFIX-Dzdqq5J2.mjs → ADMIN_FUNCTIONS-DSUQ5fX9.mjs} +49 -3
  6. package/dist/packem_shared/{applyCdcChanges-Ctdmxmrv.mjs → CDC_LOG_TABLE-DSycmnDf.mjs} +5 -1
  7. package/dist/packem_shared/{DATA_MIGRATION_STATE_TABLE-PTtTiQ7U.mjs → DATA_MIGRATION_STATE_TABLE-DfPxn8I0.mjs} +5 -1
  8. package/dist/packem_shared/{assertFlatPredicate-DyVYReuT.mjs → DEFAULT_MAX_RELATION_KEYS-DU-Y4-LJ.mjs} +51 -2
  9. package/dist/packem_shared/{assertValidClientId-CBZ1zC96.mjs → NotUniqueError-Do5h_jiW.mjs} +127 -37
  10. package/dist/packem_shared/{rank-CrkEIpF4.mjs → RANK_TIEBREAK-CXhdcA1o.mjs} +2 -13
  11. package/dist/packem_shared/{guardWriter-u3UlnCH5.mjs → RLS_UNWRAP_SYMBOL-EtGQdC9d.mjs} +6 -2
  12. package/dist/packem_shared/{ROOT_DO_SIZE_WARN_BYTES-DQkmGiCS.mjs → ROOT_DO_SIZE_WARN_BYTES-BbHQKxG6.mjs} +2341 -200
  13. package/dist/packem_shared/{ReactiveCache-ByVzgH3d.mjs → ReactiveCache-BYlSGY0N.mjs} +1 -28
  14. package/dist/packem_shared/{applyOnDelete-CMif2RKw.mjs → applyOnDelete-BQ-8ZlZ1.mjs} +19 -9
  15. package/dist/packem_shared/{buildSeekWhere-lVsNXSLy.mjs → applySelect-BvZdFUBT.mjs} +18 -1
  16. package/dist/packem_shared/{backfillAggregateIndexes-BF5eL7kW.mjs → backfillAggregateIndexes-BZsOqDXP.mjs} +3 -2
  17. package/dist/packem_shared/{compileWhereSql-CXrhFA3G.mjs → compileWhereSql-MW_Lk8nJ.mjs} +3 -2
  18. package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +108 -0
  19. package/dist/packem_shared/ctx-db-shapes-0RaIOy7J.mjs +53 -0
  20. package/dist/packem_shared/diffExternalSource-Cx9HUPJj.mjs +44 -0
  21. package/dist/packem_shared/isSourceDue-9mJRJ9Ld.mjs +40 -0
  22. package/dist/packem_shared/materializeExternalRows-Bj6EXy50.mjs +23 -0
  23. package/dist/packem_shared/{runShardMigrations-C3bn5r93.mjs → runShardMigrations-nIwoQeOK.mjs} +6 -4
  24. package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +14 -0
  25. package/dist/packem_shared/{serveRelationFanout-Clr1a05L.mjs → serveRelationFanout-C5axmGDj.mjs} +1 -1
  26. package/dist/packem_shared/stableStringify-MydiuScU.mjs +40 -0
  27. package/dist/packem_shared/subscription-delivery-Z6nXHvQN.mjs +340 -0
  28. package/dist/packem_shared/subscriptionListDeltas-CXwfoEE_.mjs +1 -0
  29. package/package.json +2 -2
  30. package/dist/packem_shared/ctx-db-idempotency-DkC9rP91.mjs +0 -35
  31. package/dist/packem_shared/encodePartitionKey-C6blLR5K.mjs +0 -1
  32. /package/dist/packem_shared/{matchesStaticWhere-CFk6adSu.mjs → AGGREGATE_SQL_FUNCTION-CFk6adSu.mjs} +0 -0
  33. /package/dist/packem_shared/{AUTH_METRICS_BUCKET_MS-CiHHYeJi.mjs → AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs} +0 -0
  34. /package/dist/packem_shared/{ensureFunctionMetricsTables-UDNVD7FS.mjs → FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs} +0 -0
  35. /package/dist/packem_shared/{clearCapturedMail-CPpgl-dX.mjs → MAIL_RETENTION-CPpgl-dX.mjs} +0 -0
  36. /package/dist/packem_shared/{assertReadonly-dDcFE1YZ.mjs → MAX_SQL_ROWS-dDcFE1YZ.mjs} +0 -0
  37. /package/dist/packem_shared/{buildSecurityAudit-CCAvoFlr.mjs → MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs} +0 -0
  38. /package/dist/packem_shared/{ftsTableName-BLEMawrp.mjs → buildFtsMatch-BLEMawrp.mjs} +0 -0
  39. /package/dist/packem_shared/{runTriggers-5N6_Fx0A.mjs → hasTrigger-5N6_Fx0A.mjs} +0 -0
package/dist/index.d.ts CHANGED
@@ -195,10 +195,17 @@ interface RelationDefinitionLike {
195
195
  readonly references: string;
196
196
  readonly table: string;
197
197
  }
198
- /** Per-relation refinements: filter / order / cap / recurse into the children. */
198
+ /** Per-relation refinements: filter / order / cap / project / recurse into the children. */
199
199
  interface NestedWith {
200
200
  limit?: number;
201
201
  orderBy?: OrderByInput[];
202
+ /**
203
+ * Project each loaded child down to these fields (like the top-level
204
+ * `findMany` `select`). Applied AFTER grouping, so the join key stays
205
+ * available to map children to parents; `_id`/`_creationTime` and any deeper
206
+ * `with` relations are always retained.
207
+ */
208
+ select?: ReadonlyArray<string>;
202
209
  where?: WhereInput;
203
210
  with?: WithInput;
204
211
  }
@@ -212,8 +219,17 @@ interface WithInput {
212
219
  _count?: Record<string, true>;
213
220
  }
214
221
  interface ResolveWithOptions {
215
- counter: (tableName: string, where?: WhereInput) => Promise<number>;
216
222
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
223
+ /**
224
+ * Grouped aggregate: for every FK value in `values`, return the count of
225
+ * child rows in `tableName` whose `whereField` equals that value,
226
+ * optionally AND-ing in `policyWhere` (the child table's RLS read filter).
227
+ * Returns a `Map` keyed by FK value with the per-group count — missing
228
+ * keys (groups with zero children) are not included; callers default to 0.
229
+ * A single `GROUP BY :whereField … WHERE :whereField IN (values)` query
230
+ * replaces the former one-query-per-distinct-value loop.
231
+ */
232
+ groupedCounter: (tableName: string, whereField: string, values: unknown[], policyWhere?: WhereInput) => Promise<Map<unknown, number>>;
217
233
  parents: Record<string, unknown>[];
218
234
  /**
219
235
  * Per-target-table read filter (RLS) applied to each relation fetch/count and
@@ -227,7 +243,18 @@ interface ResolveWithOptions {
227
243
  tableName: string;
228
244
  with: WithInput;
229
245
  }
246
+ /**
247
+ * Cross-backend fan-out for grouped `_count` on backends whose `groupedCounter`
248
+ * must fall back to scalar calls (e.g. a DO's global-D1 child or the sql-store's
249
+ * cross-shard reverse direction). Issues one `counter(table, where)` per FK
250
+ * value in parallel and collects the results into a Map.
251
+ *
252
+ * Used by both the DO and sql-store `relationGroupedCounter` implementations so
253
+ * the parallel fan-out logic isn't duplicated.
254
+ */
255
+ declare const fanOutScalarCounts: (counter: (tableName: string, where?: WhereInput) => Promise<number>, tableName: string, whereField: string, values: unknown[], policyWhere: WhereInput | undefined) => Promise<Map<unknown, number>>;
230
256
  /** Distinct, non-nullish values of `field` across `rows`, preserving first-seen order. */
257
+
231
258
  /**
232
259
  * Resolve every requested relation on `parents` (a single already-fetched
233
260
  * page), mutating each parent in place: `one` → `Doc | null`, `many` →
@@ -289,9 +316,9 @@ declare const applyOnDelete: (options: ApplyOnDeleteOptions) => Promise<void>;
289
316
  * fakes (which never carry a runtime parser) keep working.
290
317
  */
291
318
  declare const runRowValidators: (definition: TableDefinitionLike, document: Record<string, unknown>) => void;
292
- type SortDirection$1 = "asc" | "desc";
319
+ type SortDirection = "asc" | "desc";
293
320
  /** A single `{ field: "asc" | "desc" }` entry; `orderBy` is an ordered list of these. */
294
- type OrderByInput = Record<string, SortDirection$1>;
321
+ type OrderByInput = Record<string, SortDirection>;
295
322
  interface QueryArgs {
296
323
  /**
297
324
  * Predicate injected by the runtime (e.g. by `@lunora/server`'s RLS
@@ -304,6 +331,12 @@ interface QueryArgs {
304
331
  */
305
332
  baseWhere?: WhereInput;
306
333
  cursor?: null | string;
334
+ /**
335
+ * Opt a list read OUT of soft-delete scoping: when `true`, rows whose
336
+ * soft-delete column is set are INCLUDED. Has no effect on a table without
337
+ * `.softDelete()`. Default (absent/false) hides soft-deleted rows.
338
+ */
339
+ includeDeleted?: boolean;
307
340
  limit?: number;
308
341
  orderBy?: OrderByInput[];
309
342
  /**
@@ -324,6 +357,15 @@ interface QueryArgs {
324
357
  * reads (`findMany`/`findFirst`) — this flag specifically guards `count`.
325
358
  */
326
359
  restrictsCounts?: boolean;
360
+ /**
361
+ * Project each returned row down to these fields. The system fields `_id` and
362
+ * `_creationTime` are always retained (cursors + by-id reuse depend on them),
363
+ * and any relations attached via `with` (their relation keys and `_count`)
364
+ * survive the trim. Applied AFTER the rows are read and relations resolved, so
365
+ * read-dependency tracking and cursor encoding see the full row — only the
366
+ * payload returned to the caller is narrowed. Omit for the full document.
367
+ */
368
+ select?: ReadonlyArray<string>;
327
369
  where?: WhereInput;
328
370
  with?: WithInput;
329
371
  }
@@ -341,7 +383,7 @@ interface QueryPage {
341
383
  splitCursor?: null | string;
342
384
  }
343
385
  interface OrderKey {
344
- direction: SortDirection$1;
386
+ direction: SortDirection;
345
387
  field: string;
346
388
  }
347
389
  /**
@@ -376,6 +418,26 @@ declare const buildSeekWhere: (keys: OrderKey[], cursorValues: unknown[]) => Whe
376
418
  * the page it terminates. Reactive pagination uses this for a page's fixed end
377
419
  * cursor; the shared compiler renders it per dialect.
378
420
  */
421
+
422
+ /**
423
+ * Project `page` rows down to `select` — plus the always-kept system fields and
424
+ * the relation/`_count` keys attached by a `with` load (passed as `withInput`,
425
+ * the same object handed to `findMany`). Returns the page unchanged when
426
+ * `select` is undefined. Pure; callers apply it AFTER relation resolution +
427
+ * cursor encoding so only the returned payload is trimmed (dependency tracking +
428
+ * the cursor still see the full row).
429
+ */
430
+ declare const applySelect: (page: Record<string, unknown>[], select: ReadonlyArray<string> | undefined, withInput?: Record<string, unknown>) => Record<string, unknown>[];
431
+ /**
432
+ * The read-scope predicate that hides soft-deleted rows — `{ [field]: { isNull:
433
+ * true } }` matching the live rows whose soft-delete column is null/absent — or
434
+ * `undefined` when the table isn't `.softDelete()` or the read opted in via
435
+ * `includeDeleted`. AND-merge it into a list read's `where` (the by-id path
436
+ * never calls this, so `get`/`patch`/`replace`/`restore` still address the row).
437
+ */
438
+ declare const softDeleteScope: (softDeleteMode: {
439
+ field: string;
440
+ } | undefined, includeDeleted: boolean | undefined) => undefined | WhereInput;
379
441
  type RankDirection = "asc" | "desc";
380
442
  interface RankSortKeyLike {
381
443
  readonly direction: RankDirection;
@@ -554,6 +616,7 @@ declare const rankTableName: (table: string, indexName: string) => string;
554
616
  * - `sortValues[i]` === `serializeSqlValue(doc[index.sortBy[i].field])` — the same transform `syncRankIndexEntry` applies to the stored `__sort_k&lt;i>__` column, so the comparison is byte-for-byte (and JSON-safe for the cross-shard wire) regardless of which shard owns the row. `rankBefore` re-applies it idempotently, so a direct caller passing raw values still works.
555
617
  * - `rowId` === `doc._id`, the `__id__` tiebreak.
556
618
  */
619
+ declare const stableStringify: (value: unknown) => string;
557
620
  /** A single memoized result, the deps it read, and any active subscribers. */
558
621
  interface CacheEntry {
559
622
  /** Approximate serialized size of `result`, charged against `maxBytes`. */
@@ -686,16 +749,6 @@ declare class ReactiveCache {
686
749
  private evict;
687
750
  }
688
751
  /**
689
- * Stable, sorted JSON encoding of `args` for use in a cache key. Object keys
690
- * are visited in lexical order at every depth so `{ a: 1, b: 2 }` and
691
- * `{ b: 2, a: 1 }` hash to the same string. Arrays preserve their order
692
- * (the index IS the key). `undefined` values are skipped at the object level
693
- * so `{ a: undefined }` collides with `{}` — matches Convex behavior and
694
- * avoids spurious cache misses on optional args. Inside arrays `undefined`
695
- * encodes as `null` to keep positional semantics.
696
- */
697
- declare const stableStringify: (value: unknown) => string;
698
- /**
699
752
  * Compose a cache key from a function path, a stably-encoded args object, and
700
753
  * the caller's identity discriminator. Exported so the wiring layer and tests
701
754
  * build identical keys without each side reinventing the format.
@@ -951,7 +1004,32 @@ interface SubscriptionQuery {
951
1004
  */
952
1005
  table?: string;
953
1006
  }
1007
+ /**
1008
+ * A live shape subscription registered on a socket — the partial-replication
1009
+ * parallel to {@link SubscriptionQuery}. The client names a `defineShape` shape
1010
+ * and supplies validated `args`; the DO resolves it to a table + RLS-composed
1011
+ * `effectiveWhere` under the socket's verified identity (never the client's
1012
+ * word) and pokes the membership diff. `sinceSeq`/`sinceEpoch` carry the
1013
+ * client's last applied checkpoint for resume.
1014
+ */
1015
+ interface ShapeSubscriptionQuery {
1016
+ /** Validated shape arguments (e.g. `{ channelId }`); forwarded to `resolveShape`. */
1017
+ args?: Record<string, unknown>;
1018
+ /** Registered shape name (the `defineShape` export the codegen subclass resolves). */
1019
+ name: string;
1020
+ /** Resume epoch the client persisted alongside {@link ShapeSubscriptionQuery.sinceSeq} (see {@link SubscriptionQuery.sinceEpoch}). */
1021
+ sinceEpoch?: string;
1022
+ /** Resume checkpoint: the `__cdc_log` cursor the client's view of this shape last reflected (see {@link SubscriptionQuery.sinceSeq}). */
1023
+ sinceSeq?: number;
1024
+ }
954
1025
  interface SubscriptionEnvelope {
1026
+ /**
1027
+ * Stable per-client id carried by the `connect` envelope. Recorded on the
1028
+ * socket attachment so a shape poke can echo this client's
1029
+ * `__client_watermark` as its `lastMutationId`. Ignored on other envelope
1030
+ * types; absent for clients that don't use custom mutators.
1031
+ */
1032
+ clientId?: string;
955
1033
  /**
956
1034
  * App-supplied connection context carried by the `connect` envelope (e.g.
957
1035
  * `{ roomId, sessionId }`). Merged into the socket attachment and forwarded
@@ -966,6 +1044,19 @@ interface SubscriptionEnvelope {
966
1044
  id: string;
967
1045
  query?: SubscriptionQuery;
968
1046
  /**
1047
+ * Shape descriptor of a `shape_subscribe` envelope: the named shape + its
1048
+ * validated args. Carries the client's resume checkpoint via
1049
+ * {@link SubscriptionEnvelope.sinceCheckpoint}/{@link SubscriptionEnvelope.sinceEpoch}.
1050
+ */
1051
+ shape?: {
1052
+ args?: Record<string, unknown>;
1053
+ name: string;
1054
+ };
1055
+ /** Resume checkpoint on a `shape_subscribe` envelope (the `__cdc_log` cursor the client's shape view is at). */
1056
+ sinceCheckpoint?: number;
1057
+ /** CDC epoch the {@link SubscriptionEnvelope.sinceCheckpoint} belongs to. */
1058
+ sinceEpoch?: string;
1059
+ /**
969
1060
  * Topic of a `whisper`/`whisper_subscribe`/`whisper_unsubscribe` envelope —
970
1061
  * an app-chosen channel name (e.g. `"room:42:cursors"`) scoped to this shard.
971
1062
  */
@@ -983,7 +1074,7 @@ interface SubscriptionEnvelope {
983
1074
  * this shard with NO SQLite/CDC write (AnyCable-style whispering — typing
984
1075
  * indicators, live cursors). The sender never receives its own whisper.
985
1076
  */
986
- type: "ack" | "connect" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
1077
+ type: "ack" | "connect" | "shape_subscribe" | "shape_unsubscribe" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
987
1078
  }
988
1079
  /**
989
1080
  * The argument a connection-lifecycle hook receives. Structurally matches
@@ -1058,6 +1149,15 @@ interface SocketAttachment {
1058
1149
  */
1059
1150
  admin?: boolean;
1060
1151
  /**
1152
+ * Stable per-client id from the `connect` envelope (the same id the client
1153
+ * stamps on its custom-mutator pushes). Lets a shape poke echo this client's
1154
+ * `__client_watermark` as the poke's `lastMutationId`, so a `@lunora/db`
1155
+ * collection can drop the optimistic overlay for writes this poke has
1156
+ * synced. Absent for clients that don't use custom mutators. Persisted so it
1157
+ * survives hibernation.
1158
+ */
1159
+ clientId?: string;
1160
+ /**
1061
1161
  * `true` once the socket's `connect` envelope has fired the `onConnect`
1062
1162
  * hooks. Gates the dispatch so a client that re-sends `connect` (or a
1063
1163
  * duplicate frame) can't re-fire the hooks for an already-announced socket —
@@ -1091,6 +1191,14 @@ interface SocketAttachment {
1091
1191
  * hooks so they run under the connecting user.
1092
1192
  */
1093
1193
  identity?: Record<string, unknown>;
1194
+ /**
1195
+ * Live shape subscriptions registered on this socket, keyed by the
1196
+ * client-supplied subscription id. The partial-replication parallel to
1197
+ * {@link SocketAttachment.subs}: the poke protocol fans membership diffs to
1198
+ * these, while `subs` drives the legacy `data`/`delta` re-execution path.
1199
+ * Absent until the socket sends its first `shape_subscribe`.
1200
+ */
1201
+ shapes?: Record<string, ShapeSubscriptionQuery>;
1094
1202
  subs: Record<string, SubscriptionQuery>;
1095
1203
  /**
1096
1204
  * Verified user id resolved at upgrade (from `x-lunora-userid`), or absent
@@ -1106,6 +1214,36 @@ interface SocketAttachment {
1106
1214
  whispers?: string[];
1107
1215
  }
1108
1216
  /**
1217
+ * A `shape_subscribe`'s resolved query: which `table` to replicate, the
1218
+ * identity-scoped `effectiveWhere` (the shape predicate AND-merged with the
1219
+ * table's RLS read base-where), the optional projected `columns` allow-list,
1220
+ * and whether the table is `.global()` (served by the latency-tiered poll path
1221
+ * rather than the CDC poke path). The codegen subclass's `resolveShape` builds
1222
+ * it under the socket's verified identity, so the membership query the poke
1223
+ * protocol runs is RLS-correct by construction.
1224
+ */
1225
+ interface ResolvedShape {
1226
+ columns?: ReadonlyArray<string>;
1227
+ effectiveWhere?: WhereInput;
1228
+ /** `true` when the shape's table is `.global()` (lives in D1, not this DO's SQLite) — no per-DO op-log to diff, so served by the poll path. */
1229
+ global?: boolean;
1230
+ table: string;
1231
+ }
1232
+ /**
1233
+ * Identity a subscription/shape query is executed under, threaded EXPLICITLY
1234
+ * into the codegen `resolveShape`/`buildCtx` rather than read from the shared,
1235
+ * per-request identity fields. The value passed is the socket's OWN verified
1236
+ * identity (stamped on the {@link SocketAttachment} at the WS upgrade from the
1237
+ * runtime-minted `x-lunora-userid`/`x-lunora-identity` headers the client can't
1238
+ * forge), passed BY VALUE so a deferred refresh or interleaved RPC can't clobber
1239
+ * it. An anonymous socket leaves both fields `undefined`, so an RLS/`ctx.auth`
1240
+ * query fails closed (empty/denied) rather than leaking another user's data.
1241
+ */
1242
+ interface SubscriptionIdentity {
1243
+ identity?: Record<string, unknown>;
1244
+ userId?: string;
1245
+ }
1246
+ /**
1109
1247
  * One-shot backfill of every declared aggregate index. Used by tests and
1110
1248
  * production hosts that want to populate counters up-front instead of on first
1111
1249
  * read. Idempotent: counter rows that already exist are left alone, so it's
@@ -1147,10 +1285,16 @@ interface CdcChange {
1147
1285
  * Read changelog entries newer than `sinceSeq` in commit order, up to `limit`
1148
1286
  * (clamped to [1, 10000]). Returns the rows plus the cursor to resume from (the
1149
1287
  * last `seq`, or `sinceSeq` when the page is empty).
1288
+ *
1289
+ * The optional `tables` set narrows the page to changes on those tables — the
1290
+ * shape/poke path reads one filtered page per flush so it never scans op-log
1291
+ * entries for tables no live shape is watching. Omit it (or pass an empty set)
1292
+ * for the full, unfiltered page (the existing streaming-export/resume callers).
1150
1293
  */
1151
1294
  declare const readCdcChanges: (sql: SqlExec, options?: {
1152
1295
  limit?: number;
1153
1296
  sinceSeq?: number;
1297
+ tables?: ReadonlySet<string>;
1154
1298
  }) => {
1155
1299
  changes: CdcChange[];
1156
1300
  cursor: number;
@@ -1186,6 +1330,11 @@ declare const applyCdcChanges: (writer: DatabaseWriterLike, changes: ReadonlyArr
1186
1330
  declare const runShardMigrations: (sql: SqlExec, schema: SchemaLike, options?: {
1187
1331
  cdc?: boolean;
1188
1332
  }) => void;
1333
+ /** One shape member: its `_id` key plus the decoded document (id + creationTime merged in). */
1334
+ interface ShapeRow {
1335
+ doc: Record<string, unknown>;
1336
+ id: string;
1337
+ }
1189
1338
  /**
1190
1339
  * Structural projection of `state.storage.sql` (workerd's SqlStorage). We
1191
1340
  * only require the `exec` overload — the cursor it returns is iterable and
@@ -1233,6 +1382,16 @@ interface TableDefinitionLike {
1233
1382
  field?: string;
1234
1383
  kind: "global" | "root" | "shardBy";
1235
1384
  };
1385
+ /**
1386
+ * Mirror of `@lunora/server`'s `TableDefinition.softDeleteMode` (set by
1387
+ * `.softDelete()`). When present, `delete()` flips the `field` column to a
1388
+ * timestamp instead of physically removing the row (cascading as a soft
1389
+ * delete), and list reads scope out rows whose `field` is set unless
1390
+ * `includeDeleted` is passed. By-id reads/writes are unaffected.
1391
+ */
1392
+ readonly softDeleteMode?: {
1393
+ field: string;
1394
+ };
1236
1395
  readonly triggerMap?: Record<string, TriggerDefinitionLike>;
1237
1396
  }
1238
1397
  interface IndexDefinitionLike {
@@ -1525,7 +1684,16 @@ interface DatabaseWriterLike {
1525
1684
  * RLS-aware ctx seam from §3.2).
1526
1685
  */
1527
1686
  count: (tableName: string, where?: RestrictableQueryOptions | WhereInput) => Promise<number>;
1528
- delete: (id: string, expectedTable?: string) => Promise<void>;
1687
+ /**
1688
+ * Delete a row by id. On a `.softDelete()` table this flips the marker column
1689
+ * (cascading as a soft delete) instead of removing the row; pass
1690
+ * `options.hard` to force a physical removal (which cascades as a physical
1691
+ * delete, reaching already-soft-deleted children too). Non-soft tables ignore
1692
+ * `options.hard` — they always delete physically.
1693
+ */
1694
+ delete: (id: string, expectedTable?: string, options?: {
1695
+ hard?: boolean;
1696
+ }) => Promise<void>;
1529
1697
  /**
1530
1698
  * Delete many rows by id in one call (a loop over `delete()`). The returned
1531
1699
  * `deleted` is the number of ids **requested**, not rows actually removed (an
@@ -1702,6 +1870,14 @@ interface DatabaseWriterLike {
1702
1870
  rankPageRows?: (tableName: string, indexName: string, options?: RankPageOptions) => Promise<ShardRankPageResult>;
1703
1871
  replace: (id: string, document: Record<string, unknown>, expectedTable?: string) => Promise<void>;
1704
1872
  /**
1873
+ * Un-soft-delete a row: clears the `.softDelete()` marker column (a by-id
1874
+ * UPDATE, so it works on a row that list reads currently hide). Throws when
1875
+ * the row's table isn't `.softDelete()`. Optional on the interface — the DO
1876
+ * writer implements it; the `.global()` twin does too, so a restore on a
1877
+ * global table routes through the DO writer's global fallback.
1878
+ */
1879
+ restore?: (id: string, expectedTable?: string) => Promise<void>;
1880
+ /**
1705
1881
  * Best-effort, read-only reader over Lunora's system tables
1706
1882
  * (`_scheduled_functions`, `_storage`). Eventually consistent and **not**
1707
1883
  * part of the shard's transaction snapshot — see {@link SystemDatabaseReader}.
@@ -1918,6 +2094,22 @@ declare const readAggregateValue: (op: string, row: {
1918
2094
  * string.
1919
2095
  */
1920
2096
  declare const encodeAggregateKey: (by: ReadonlyArray<string>, source: Record<string, unknown>) => string;
2097
+ /** One recorded admin operation, in monotonic `seq` order. */
2098
+ interface AuditEntry {
2099
+ /** JSON-decoded extra context (the acting user, op-specific counts, …); absent when none was recorded. */
2100
+ detail?: Record<string, unknown>;
2101
+ /** Primary key of the affected row, when the op targets one. */
2102
+ id?: string;
2103
+ /** Short op identifier, e.g. `writeRow` or `runMigration`. */
2104
+ op: string;
2105
+ /** Monotonic per-shard cursor — strictly increasing, never reused. */
2106
+ seq: number;
2107
+ /** Affected table, when the op targets one. */
2108
+ table?: string;
2109
+ /** Wall-clock millis when the op was recorded. */
2110
+ ts: number;
2111
+ }
2112
+ /** Fields accepted when appending one audit entry; `seq` is assigned by the table. */
1921
2113
  /** Reserved single-row auth accumulator table. Auto-hidden from the data browser by the `__lunora` prefix. */
1922
2114
  declare const AUTH_METRICS_TABLE = "__lunora_auth_metrics";
1923
2115
  /** Reserved coarse time-series table: app-wide auth attempt/failure counts bucketed by a fixed window. */
@@ -2155,6 +2347,112 @@ interface RenderedSql {
2155
2347
  * identifiers quoted and placeholders numbered the way that engine expects.
2156
2348
  */
2157
2349
  declare const renderSql: (engine: SqlEngine, query: SQL) => RenderedSql;
2350
+ /** The result of {@link diffExternalSource}: the changes to replay, and the baseline the next tick diffs from. */
2351
+ interface ExternalSourceDiffResult {
2352
+ /** Ordered for `applyCdcChanges`: upserts in pulled order, then deletes in baseline order. */
2353
+ changes: CdcChange[];
2354
+ /** `id → canonical-value JSON` — pass back as the `baseline` next tick (or persist for an incremental cursor). */
2355
+ nextBaseline: Map<string, string>;
2356
+ }
2357
+ /**
2358
+ * Project a row to the document the ingest loop stores + compares on: `_id` plus
2359
+ * either the `columns` allow-list or every field except the framework-assigned
2360
+ * `_creationTime` (which the source never supplies). Returned as a plain object;
2361
+ * key order is irrelevant because {@link stableStringify} sorts keys. Used for BOTH
2362
+ * the pulled side here and the local baseline, so the two are byte-identical for an
2363
+ * unchanged row.
2364
+ */
2365
+
2366
+ /**
2367
+ * Diff a sourced table's freshly-pulled membership against the local baseline.
2368
+ * Returns the `CdcChange[]` to apply (in stable order: upserts in pulled order,
2369
+ * then deletes in baseline order) and the next baseline (`id → canonical JSON`).
2370
+ */
2371
+ declare const diffExternalSource: (pulled: ReadonlyArray<Record<string, unknown>>, baseline: ReadonlyMap<string, string>, options: {
2372
+ columns?: ReadonlyArray<string>;
2373
+ table: string;
2374
+ }) => ExternalSourceDiffResult;
2375
+ /** The outcome of one materialize pass: how many changes were applied, and the baseline the next tick diffs from. */
2376
+ interface MaterializeResult {
2377
+ /** Number of `CdcChange`s applied (inserts + updates + deletes). Zero on a steady-state tick. */
2378
+ applied: number;
2379
+ /** `id → projected-value JSON` — the post-tick membership, to feed back as `baseline` next tick. */
2380
+ nextBaseline: Map<string, string>;
2381
+ }
2382
+ /**
2383
+ * Diff `pulled` against `baseline` and apply the delta to `writer`. Returns the
2384
+ * applied count and the next baseline. A steady-state tick (membership unchanged)
2385
+ * applies nothing and returns `applied: 0`.
2386
+ */
2387
+ declare const materializeExternalRows: (writer: DatabaseWriterLike, pulled: ReadonlyArray<Record<string, unknown>>, baseline: ReadonlyMap<string, string>, options: {
2388
+ columns?: ReadonlyArray<string>;
2389
+ table: string;
2390
+ }) => Promise<MaterializeResult>;
2391
+ /**
2392
+ * Read the materialized table's current membership as the canonical full-pull
2393
+ * baseline (`id → canonical JSON`). Reuses the shape scanner (`selectShapeRows`)
2394
+ * and the SAME {@link projectExternalSourceRow} + {@link stableStringify} the diff
2395
+ * uses, so a stored row (with `_creationTime` + arbitrary key order) compares
2396
+ * byte-identical to its freshly-pulled source counterpart — an unchanged row
2397
+ * produces no spurious update.
2398
+ */
2399
+ declare const readExternalSourceBaseline: (sql: SqlExec, table: string, columns?: ReadonlyArray<string>) => Map<string, string>;
2400
+ /**
2401
+ * Run one full-pull materialize tick: read the table's current membership as the
2402
+ * baseline, diff the freshly-pulled rows against it, and apply the delta. This is
2403
+ * the system-driven loop body the DO poll alarm calls — the table IS the baseline
2404
+ * (design §1 Fact A), so no separate snapshot is kept. Pass both the read handle
2405
+ * (`sql`) and the validated `writer` (the DO has both); they must address the same
2406
+ * table.
2407
+ */
2408
+ declare const runExternalSourceTick: (sql: SqlExec, writer: DatabaseWriterLike, pulled: ReadonlyArray<Record<string, unknown>>, options: {
2409
+ columns?: ReadonlyArray<string>;
2410
+ table: string;
2411
+ }) => Promise<MaterializeResult>;
2412
+ /** The minimal SqlClient surface the poll loop calls (mirrors `@lunora/hyperdrive`'s `SqlClient`). */
2413
+ interface SourceClientLike {
2414
+ query: <Row = Record<string, unknown>>(text: string, parameters?: ReadonlyArray<unknown>) => Promise<Row[]>;
2415
+ }
2416
+ /** Poll cadence: `"manual"` (never auto-poll) or a minimum interval between polls. */
2417
+ type SourceRefresh = "manual" | {
2418
+ everyMs: number;
2419
+ };
2420
+ /** The runtime `.source(...)` config the poll loop reads — a structural mirror of `@lunora/server`'s `ExternalSourceDefinition` (only the fields the tick uses). */
2421
+ interface ExternalSourceLike {
2422
+ binding: string;
2423
+ columns?: ReadonlyArray<string>;
2424
+ idColumn?: string;
2425
+ map?: (row: Record<string, unknown>) => Record<string, unknown>;
2426
+ query: string;
2427
+ refresh?: SourceRefresh;
2428
+ tenantBy?: (shardKey: string) => ReadonlyArray<unknown>;
2429
+ }
2430
+ /**
2431
+ * Lift an external row to a Lunora document: the `idColumn` value becomes a
2432
+ * stringified `_id`, then either `map` shapes the body or every other column is
2433
+ * copied verbatim. Throws on a missing/null id, and on a non-scalar id, so a
2434
+ * misconfigured query fails loudly instead of materializing rows under the literal
2435
+ * id `"undefined"` (or collapsing many rows onto one id). Shared with
2436
+ * `@lunora/hyperdrive`'s `projectSourceRow`.
2437
+ */
2438
+ declare const liftSourceId: (row: Record<string, unknown>, options?: {
2439
+ idColumn?: string;
2440
+ map?: (row: Record<string, unknown>) => Record<string, unknown>;
2441
+ }) => Record<string, unknown>;
2442
+ /**
2443
+ * Whether a source should poll on this alarm tick. `"manual"` never auto-polls;
2444
+ * `{ everyMs }` polls at most once per interval (the alarm floor still bounds it
2445
+ * from below); an omitted `refresh` polls every tick. `lastPolledMs` is `undefined`
2446
+ * before the first poll (always due).
2447
+ */
2448
+ declare const isSourceDue: (refresh: SourceRefresh | undefined, lastPolledMs: number | undefined, nowMs: number) => boolean;
2449
+ /**
2450
+ * Pull a sourced table's tenant slice from `client`, project each row through
2451
+ * {@link liftSourceId}, and materialize it via {@link runExternalSourceTick}
2452
+ * (read local baseline → diff → apply through the validated CDC writer). The
2453
+ * per-table body the DO poll alarm runs; `shardKey` binds into `tenantBy`.
2454
+ */
2455
+ declare const pullExternalSourceTick: (sql: SqlExec, writer: DatabaseWriterLike, client: SourceClientLike, table: string, source: ExternalSourceLike, shardKey: string) => Promise<MaterializeResult>;
2158
2456
  /**
2159
2457
  * Reserved `functionPath` prefix for admin introspection RPCs. These travel
2160
2458
  * over the same `/_lunora/rpc` → shard `/rpc` path as ordinary functions, but
@@ -2177,6 +2475,19 @@ declare const ADMIN_FUNCTION_PREFIX = "__lunora_admin__:";
2177
2475
  */
2178
2476
  declare const RELATION_FUNCTION_PREFIX = "__lunora_relation__:";
2179
2477
  /**
2478
+ * Reserved `functionPath` prefix for live feature-flag reads. The React client's
2479
+ * `useFlag`/`useFlags` subscribe to `__lunora_flags__:eval` over the same WS
2480
+ * channel as a user query; `ShardDO` intercepts it before user dispatch and
2481
+ * serves it from the codegen-overridden flag-subscription read hook, which
2482
+ * evaluates the flag through the app's OpenFeature provider under the socket's
2483
+ * verified identity. Like the other reserved prefixes it is NOT admin-gated (a
2484
+ * flag read is public, scoped to the subscriber's own targeting context), and
2485
+ * the `__lunora_` namespace is reserved so a real `&lt;file>:&lt;function>` can't
2486
+ * collide. Re-evaluated on every write-flush so values stay live within a
2487
+ * session (provider-side flips with no intervening write surface on reconnect).
2488
+ */
2489
+ declare const FLAGS_FUNCTION_PREFIX = "__lunora_flags__:";
2490
+ /**
2180
2491
  * Fully-qualified reserved paths the data browser invokes. The
2181
2492
  * `__lunora_admin__:` prefix is spelled out inline rather than interpolated so
2182
2493
  * the values stay emittable under `--isolatedDeclarations`.
@@ -2196,6 +2507,7 @@ declare const ADMIN_FUNCTIONS: {
2196
2507
  readonly getAuditLog: "__lunora_admin__:getAuditLog";
2197
2508
  readonly getAuthMetrics: "__lunora_admin__:getAuthMetrics";
2198
2509
  readonly getCapturedMail: "__lunora_admin__:getCapturedMail";
2510
+ readonly getFanoutMetrics: "__lunora_admin__:getFanoutMetrics";
2199
2511
  readonly getFunctionStats: "__lunora_admin__:getFunctionStats";
2200
2512
  readonly listSubscriptions: "__lunora_admin__:listSubscriptions";
2201
2513
  readonly listTableIndexes: "__lunora_admin__:listTableIndexes";
@@ -2207,6 +2519,8 @@ declare const ADMIN_FUNCTIONS: {
2207
2519
  readonly getSettings: "__lunora_admin__:getSettings";
2208
2520
  readonly getWorkflowInstanceStatus: "__lunora_admin__:getWorkflowInstanceStatus";
2209
2521
  readonly importShard: "__lunora_admin__:importShard";
2522
+ readonly listFlags: "__lunora_admin__:listFlags";
2523
+ readonly listQueues: "__lunora_admin__:listQueues";
2210
2524
  readonly listTables: "__lunora_admin__:listTables";
2211
2525
  readonly listWorkflows: "__lunora_admin__:listWorkflows";
2212
2526
  readonly maskPolicies: "__lunora_admin__:maskPolicies";
@@ -2234,30 +2548,6 @@ interface TableInfo {
2234
2548
  name: string;
2235
2549
  rowCount: number;
2236
2550
  }
2237
- /**
2238
- * One recorded admin operation served by `__lunora_admin__:getAuditLog`, sourced
2239
- * from the reserved `__lunora_audit__` table (see `audit-log.ts`). Unlike the
2240
- * in-memory `getMetrics`/`getFunctionStats` counters, the audit log is durable —
2241
- * it survives hibernation/restart and is bounded only by a retention cap. `seq`
2242
- * is a monotonic per-shard cursor the studio pages through; `op` is the short
2243
- * op name (`writeRow`, `runMigration`, `importShard`, `applyCdc`); `table`/`id`
2244
- * are present when the op targets one; `detail` carries op-specific context
2245
- * (notably the acting `userId`).
2246
- */
2247
- interface AuditEntry {
2248
- /** JSON extra context (acting user, op-specific counts, …); absent when none was recorded. */
2249
- detail?: Record<string, unknown>;
2250
- /** Primary key of the affected row, when the op targets one. */
2251
- id?: string;
2252
- /** Short op identifier, e.g. `writeRow`. */
2253
- op: string;
2254
- /** Monotonic per-shard cursor — strictly increasing, never reused. */
2255
- seq: number;
2256
- /** Affected table, when the op targets one. */
2257
- table?: string;
2258
- /** Epoch-ms the op was recorded. */
2259
- ts: number;
2260
- }
2261
2551
  /** Payload of a `__lunora_admin__:getAuditLog` call: the recorded entries, newest first. */
2262
2552
  interface AuditLogResult {
2263
2553
  entries: AuditEntry[];
@@ -2510,20 +2800,64 @@ interface StorageRulesResult {
2510
2800
  * package's tests and the studio's fails the build if the two key sets diverge.
2511
2801
  */
2512
2802
  interface StudioFeaturesResult {
2803
+ /** `@lunora/bindings/analytics` / `ctx.analytics` is used, or it is a declared dependency. */
2804
+ analytics: boolean;
2805
+ /** `@lunora/auth` is a declared dependency (backs the Users / Sessions / Organizations / Configuration pages). */
2806
+ auth: boolean;
2807
+ /** `@lunora/flags` / `ctx.flags` is used, or it is a declared dependency. */
2808
+ flags: boolean;
2809
+ /** `@lunora/bindings/kv` / `ctx.kv` is used, or it is a declared dependency. */
2810
+ kv: boolean;
2513
2811
  /** `@lunora/mail` is imported by a `lunora/` source or a declared dependency. */
2514
2812
  mail: boolean;
2515
2813
  /** `@lunora/payment` is used (import or `ctx.payments`) or a declared dependency. */
2516
2814
  payments: boolean;
2815
+ /** `@lunora/queue` / `ctx.queues` is used, the app declares queues, or it is a declared dependency. */
2816
+ queues: boolean;
2517
2817
  /** `@lunora/scheduler` / `ctx.scheduler` is used, the app declares crons, or it is a declared dependency. */
2518
2818
  scheduler: boolean;
2519
2819
  /** `@lunora/storage` / `ctx.storage` is used, the schema declares storage columns/rules, or it is a declared dependency. */
2520
2820
  storage: boolean;
2521
- /** The schema declares vector indexes, `@lunora/vectors` / `ctx.vectors` is used, or it is a declared dependency. */
2821
+ /** The schema declares vector indexes, `@lunora/bindings/vectors` / `ctx.vectors` is used, or it is a declared dependency. */
2522
2822
  vectors: boolean;
2523
2823
  /** `@lunora/workflow` / `ctx.workflows` is used, the app declares workflows, or it is a declared dependency. */
2524
2824
  workflows: boolean;
2525
2825
  }
2526
2826
  /**
2827
+ * One feature flag evaluated under a supplied targeting context, surfaced by
2828
+ * `__lunora_admin__:listFlags` for the studio's read-only Flags page. The `key`
2829
+ * and `type` are statically discovered by `@lunora/codegen` from the app's
2830
+ * `ctx.flags.&lt;type>("key", …)` reads; `value`/`reason`/`variant`/`errorCode`
2831
+ * come from the live OpenFeature evaluation (the codegen subclass overrides the
2832
+ * base `evaluateFlags` hook). `value` is the resolved flag value as JSON.
2833
+ */
2834
+ interface FlagEvaluation {
2835
+ /** OpenFeature `errorCode` when the evaluation failed (the value falls back to the default). */
2836
+ errorCode?: string;
2837
+ /** The discovered flag key (the first argument of a `ctx.flags.&lt;type>(...)` read). */
2838
+ key: string;
2839
+ /** OpenFeature `reason` for the resolution (`TARGETING_MATCH`, `DEFAULT`, `ERROR`, …). */
2840
+ reason?: string;
2841
+ /** The flag's value type, derived from which `ctx.flags.&lt;type>` method read it. */
2842
+ type: "boolean" | "number" | "object" | "string";
2843
+ /** The resolved value (JSON), or the type default when unconfigured / on error. */
2844
+ value: unknown;
2845
+ /** OpenFeature `variant` identifier when the provider reports one. */
2846
+ variant?: string;
2847
+ }
2848
+ /**
2849
+ * Payload of a `__lunora_admin__:listFlags` call: every statically-discovered
2850
+ * flag evaluated under the supplied targeting context. `configured` is `false`
2851
+ * when the app wires no `@lunora/flags` provider (the base hook), so the studio
2852
+ * can distinguish "no flags configured" from "configured but zero flags read".
2853
+ */
2854
+ interface FlagsResult {
2855
+ /** `true` when an `@lunora/flags` provider is wired (the codegen override ran). */
2856
+ configured: boolean;
2857
+ /** Each discovered flag evaluated under the request's targeting context. */
2858
+ flags: FlagEvaluation[];
2859
+ }
2860
+ /**
2527
2861
  * One declared Cloudflare Workflow, surfaced by `__lunora_admin__:listWorkflows`
2528
2862
  * for the studio's Workflows page. Statically discovered by `@lunora/codegen`
2529
2863
  * from `lunora/workflows.ts` (the codegen subclass overrides the base hook);
@@ -2544,6 +2878,28 @@ interface WorkflowsResult {
2544
2878
  workflows: WorkflowMetadata[];
2545
2879
  }
2546
2880
  /**
2881
+ * One declared Cloudflare Queue, surfaced by `__lunora_admin__:listQueues` for
2882
+ * the studio's Queues page. Statically discovered by `@lunora/codegen` from
2883
+ * `lunora/queues.ts` (the codegen subclass overrides the base hook); queues are
2884
+ * not Durable Objects and carry no runtime state in the shard, so this is pure
2885
+ * declaration metadata. `binding` is the generated `QUEUE_*` producer binding,
2886
+ * `name` the deployed `queues.producers[].queue`, `exportName` the
2887
+ * `lunora/queues.ts` export (`ctx.queues.&lt;exportName>`), `mode` whether the
2888
+ * queue is consumed by a worker (`push`) or polled externally (`pull`), and
2889
+ * `deadLetterQueue` the optional DLQ a push consumer dead-letters to.
2890
+ */
2891
+ interface QueueMetadata {
2892
+ binding: string;
2893
+ deadLetterQueue?: string;
2894
+ exportName: string;
2895
+ mode: "pull" | "push";
2896
+ name: string;
2897
+ }
2898
+ /** Payload of a `__lunora_admin__:listQueues` call: every declared queue, sorted by export name. */
2899
+ interface QueuesResult {
2900
+ queues: QueueMetadata[];
2901
+ }
2902
+ /**
2547
2903
  * Lifecycle state of a workflow instance, mirrored from `@lunora/workflow`'s
2548
2904
  * `WorkflowInstanceStatus` so `@lunora/do` carries no dependency on the workflow
2549
2905
  * package. Returned by `getWorkflowInstanceStatus` and `createWorkflowInstance`.
@@ -2617,7 +2973,12 @@ interface TablePage {
2617
2973
  */
2618
2974
  refs?: Record<string, string>;
2619
2975
  rows: Record<string, unknown>[];
2620
- total: number;
2976
+ /**
2977
+ * Total rows matching the predicate. Absent when the read passed
2978
+ * `skipCount: true` (the caller sources the count from a separate,
2979
+ * predicate-keyed read instead of recomputing it per page).
2980
+ */
2981
+ total?: number;
2621
2982
  }
2622
2983
  /** Comparison a {@link FilterClause} applies. `contains` is a case-sensitive substring (LIKE); the rest are direct SQL comparisons. */
2623
2984
  type FilterOperator = "contains" | "eq" | "gt" | "gte" | "lt" | "lte" | "ne";
@@ -2633,8 +2994,6 @@ interface FilterClause {
2633
2994
  operator: FilterOperator;
2634
2995
  value?: unknown;
2635
2996
  }
2636
- /** Sort direction for an {@link OrderByClause}. */
2637
- type SortDirection = "asc" | "desc";
2638
2997
  /**
2639
2998
  * A server-side sort over one displayed column. `column` resolves the same way a
2640
2999
  * {@link FilterClause}'s does — a physical/meta column orders by its identifier, a
@@ -2675,6 +3034,14 @@ interface ReadTablePageOptions {
2675
3034
  * Empty/whitespace is treated as no filter.
2676
3035
  */
2677
3036
  search?: string;
3037
+ /**
3038
+ * Skip the `SELECT COUNT(*)` and return the page with `total` absent. The
3039
+ * data browser splits the row count into a separate predicate-keyed read (one
3040
+ * that excludes `offset`), so paging never re-counts; the page read passes
3041
+ * this to avoid recomputing the same total per offset. Unset → the COUNT runs
3042
+ * (today's behavior) and `total` is populated.
3043
+ */
3044
+ skipCount?: boolean;
2678
3045
  table: string;
2679
3046
  }
2680
3047
  /**
@@ -3284,6 +3651,16 @@ declare const assertFlatPredicate: (where: WhereInput | undefined, schema: Resol
3284
3651
  * and issues no extra query).
3285
3652
  */
3286
3653
  declare const resolveRelationPredicates: (where: WhereInput | undefined, options: ResolveRelationPredicatesOptions) => Promise<WhereInput | undefined>;
3654
+ /**
3655
+ * Registration-time guard for partial-replication shapes. A live shape can only
3656
+ * be poked from the op-log of its OWN shard Durable Object, so an
3657
+ * `effectiveWhere` that joins to a `.shardBy()` table reaches rows that live in
3658
+ * other DOs the poke loop can never observe. Reject such a shape up front with
3659
+ * the two supported remedies. Called from the generated `resolveShape` override
3660
+ * the moment a socket subscribes (the first point the compiled predicate and the
3661
+ * schema's shard modes are both in hand).
3662
+ */
3663
+ declare const assertShapeShardable: (effectiveWhere: WhereInput | undefined, schema: ResolveContext["schema"], table: string) => void;
3287
3664
  /** Severity of a `ctx.log.*` call, mirroring the console method names (`log` is the default level, distinct from `info`). */
3288
3665
  type ContextLogLevel = "debug" | "error" | "info" | "log" | "warn";
3289
3666
  /** The fields {@link emitLogEvent} ships for one `ctx.log.*` call. */
@@ -3582,6 +3959,44 @@ declare class SessionDO {
3582
3959
  private handleRevoke;
3583
3960
  }
3584
3961
  /**
3962
+ * Diff the previously-sent list snapshot (`previousJson`, the memo's
3963
+ * `lastJson`) against the new query result and produce per-row
3964
+ * {@link MutationDelta}s the client can merge in place via `applyDelta` —
3965
+ * Convex-parity live-pagination deltas (server half of gap #20).
3966
+ *
3967
+ * Returns `undefined` (caller falls back to a full `{type:"data"}` snapshot)
3968
+ * unless ALL of these hold:
3969
+ *
3970
+ * 1. `previousJson` parses to an array (there IS a previous list to diff against).
3971
+ * 2. `nextResult` is also an array.
3972
+ * 3. Every row in both arrays is a plain object carrying a string `_id`.
3973
+ * 4. Order preservation — rows present in BOTH arrays appear in the same relative order.
3974
+ * 5. Chattiness cap — the number of deltas does not exceed the new array length (a near-total change is cheaper as a snapshot).
3975
+ *
3976
+ * Diff is keyed by `_id`: rows only in prev → `delete`; rows only in next →
3977
+ * `insert`; rows in both whose JSON differs → `update`. Insert/update carry the
3978
+ * full new `row`; delete omits it (matching the wire contract `@lunora/client`
3979
+ * parses). Deltas are ordered deletes-then-inserts/updates so the client never
3980
+ * sees a transient over-length page.
3981
+ *
3982
+ * Per-row serialization is done exactly **once** per refresh (finding #6). Each
3983
+ * row is stringified a single time into a fingerprint reused for both the
3984
+ * `prev !== next` change-detection compare and — when the caller passes the
3985
+ * optional `frames` sink — the pre-serialized delta frame body. The returned
3986
+ * `MutationDelta[]` shape is unchanged; `frames`, when supplied, receives the
3987
+ * exact `JSON.stringify(delta)` string for each returned delta, in the same
3988
+ * order, so the caller can splice it straight into the `{type:"delta"}` frame
3989
+ * without serializing the delta (and the row inside it) a second time.
3990
+ * @returns the per-row deltas to send, or `undefined` when any precondition fails and a full snapshot should be sent instead
3991
+ */
3992
+ declare const subscriptionListDeltas: (previousJson: string, nextResult: unknown, table: string, frames?: string[]) => MutationDelta[] | undefined;
3993
+ /**
3994
+ * Send one WebSocket frame, reporting whether it left the socket. A throw from
3995
+ * `ws.send` (socket closed mid-flush, outbound buffer gone) is the only
3996
+ * delivery-failure signal the runtime exposes; callers use the boolean to decide
3997
+ * whether to advance a subscription's delivered-diff baseline.
3998
+ */
3999
+ /**
3585
4000
  * Optional programmatic log sink, resolved from `createShardDO({ observability })`.
3586
4001
  * Structurally a subset of `@lunora/runtime`'s `ObservabilitySink`, so a user can
3587
4002
  * pass the SAME sink object to `createWorker` (which drives `onRpc`) and
@@ -3634,6 +4049,13 @@ interface ShardDOState {
3634
4049
  getCurrentBookmark?: () => Promise<string>;
3635
4050
  /** Native PITR: arm a restore to `bookmark` on next restart; returns the undo bookmark. */
3636
4051
  onNextSessionRestoreBookmark?: (bookmark: string) => Promise<string>;
4052
+ /**
4053
+ * Arm the DO's single alarm to fire at `scheduledTime` (ms epoch),
4054
+ * waking {@link ShardDO.alarm}. Used by the global-shape poll loop.
4055
+ * Optional: present on the real runtime, absent in the unit harness
4056
+ * (where the poll loop degrades to seed-only).
4057
+ */
4058
+ setAlarm?: (scheduledTime: Date | number) => Promise<void>;
3637
4059
  sql: {
3638
4060
  [key: string]: unknown;
3639
4061
  /**
@@ -3678,34 +4100,15 @@ interface SubscriptionOutcome {
3678
4100
  tables: Set<string>;
3679
4101
  }
3680
4102
  /**
3681
- * Identity a subscription query is executed under, threaded EXPLICITLY into
3682
- * `executeSubscription` `buildCtx` rather than read from the shared,
3683
- * per-request `currentRequestUserId`/`currentRequestIdentity` instance fields.
3684
- *
3685
- * The value passed is the socket's OWN verified identity, captured at the WS
3686
- * upgrade from the runtime-forwarded, server-minted `x-lunora-userid` /
3687
- * `x-lunora-identity` headers (the client cannot forge them — the runtime
3688
- * strips any client-supplied copies) and stamped on the {@link SocketAttachment}.
3689
- * `seedSubscription` and `refreshSubscriptions` read it off the attachment and
3690
- * pass it here BY VALUE — never by reading the mutable per-request
3691
- * `currentRequestUserId`/`currentRequestIdentity` instance fields, which a
3692
- * deferred (`waitUntil`) refresh or a concurrently-interleaved RPC could be
3693
- * mutating. That value-passing is what keeps a subscription re-run from
3694
- * observing or clobbering an in-flight RPC's identity.
3695
- *
3696
- * Developer-facing consequence: a query that authorizes or filters on the
3697
- * caller's identity — via `.use(rls(...))` or by reading `ctx.auth.userId` —
3698
- * evaluates over the live channel under the CONNECTING user, so its seed and
3699
- * every write-driven refresh return that user's rows, matching the one-shot
3700
- * `fetch` RPC. An anonymous socket (no identity resolved at upgrade) leaves
3701
- * both fields `undefined`, so such a query fails closed (empty/denied) rather
3702
- * than leaking another user's data. See the lunora-realtime skill
3703
- * ("Authorization & live queries").
4103
+ * Classification of a watermarked custom-mutator push against the shard's
4104
+ * `__client_watermark`: `expected` is the next in-order sequence, `kind`
4105
+ * whether the push is a replay (`"already"`), the next one (`"next"`), or an
4106
+ * out-of-order arrival (`"gap"`).
3704
4107
  */
3705
- interface SubscriptionIdentity {
3706
- identity?: Record<string, unknown>;
3707
- userId?: string;
3708
- }
4108
+ type ClientMutationClass = {
4109
+ expected: number;
4110
+ kind: "already" | "gap" | "next";
4111
+ };
3709
4112
  /**
3710
4113
  * Optional shard-level configuration passed through `super(state, env, …)`.
3711
4114
  * Reserved as a bag rather than positional args so subclasses don't break
@@ -3834,38 +4237,6 @@ interface RunShardRankPageArgs {
3834
4237
  take?: number;
3835
4238
  }
3836
4239
  /**
3837
- * Diff the previously-sent list snapshot (`previousJson`, the memo's
3838
- * `lastJson`) against the new query result and produce per-row
3839
- * {@link MutationDelta}s the client can merge in place via `applyDelta` —
3840
- * Convex-parity live-pagination deltas (server half of gap #20).
3841
- *
3842
- * Returns `undefined` (caller falls back to a full `{type:"data"}` snapshot)
3843
- * unless ALL of these hold:
3844
- *
3845
- * 1. `previousJson` parses to an array (there IS a previous list to diff against).
3846
- * 2. `nextResult` is also an array.
3847
- * 3. Every row in both arrays is a plain object carrying a string `_id`.
3848
- * 4. Order preservation — rows present in BOTH arrays appear in the same relative order.
3849
- * 5. Chattiness cap — the number of deltas does not exceed the new array length (a near-total change is cheaper as a snapshot).
3850
- *
3851
- * Diff is keyed by `_id`: rows only in prev → `delete`; rows only in next →
3852
- * `insert`; rows in both whose JSON differs → `update`. Insert/update carry the
3853
- * full new `row`; delete omits it (matching the wire contract `@lunora/client`
3854
- * parses). Deltas are ordered deletes-then-inserts/updates so the client never
3855
- * sees a transient over-length page.
3856
- *
3857
- * Per-row serialization is done exactly **once** per refresh (finding #6). Each
3858
- * row is stringified a single time into a fingerprint reused for both the
3859
- * `prev !== next` change-detection compare and — when the caller passes the
3860
- * optional `frames` sink — the pre-serialized delta frame body. The returned
3861
- * `MutationDelta[]` shape is unchanged; `frames`, when supplied, receives the
3862
- * exact `JSON.stringify(delta)` string for each returned delta, in the same
3863
- * order, so the caller can splice it straight into the `{type:"delta"}` frame
3864
- * without serializing the delta (and the row inside it) a second time.
3865
- * @returns the per-row deltas to send, or `undefined` when any precondition fails and a full snapshot should be sent instead
3866
- */
3867
- declare const subscriptionListDeltas: (previousJson: string, nextResult: unknown, table: string, frames?: string[]) => MutationDelta[] | undefined;
3868
- /**
3869
4240
  * Threshold at which a `__root__` DO triggers the size warning. 1 GiB —
3870
4241
  * exactly 10% of the 10 GiB per-DO SQLite ceiling, leaving plenty of runway
3871
4242
  * to plan a `.shardBy()` migration before the wall hits.
@@ -3918,6 +4289,28 @@ declare abstract class ShardDO {
3918
4289
  */
3919
4290
  protected static readonly MAX_SUBSCRIPTIONS_PER_SOCKET = 32;
3920
4291
  /**
4292
+ * Poll interval (ms) for `.global()`-table shapes. A global table lives in
4293
+ * D1 with no per-DO op-log, so its shapes can't be poke-live; the DO re-reads
4294
+ * each subscribed global shape's membership from D1 on an alarm every
4295
+ * `GLOBAL_SHAPE_POLL_INTERVAL_MS` and pokes only the diff. This is the
4296
+ * latency floor for a global-shape update — deliberately coarse (seconds, not
4297
+ * the sub-millisecond poke-live path) since the D1 read fans out per tick.
4298
+ */
4299
+ protected static readonly GLOBAL_SHAPE_POLL_INTERVAL_MS = 2e3;
4300
+ /**
4301
+ * Upper bound on a `.global()`-shape's materialized membership. Each global
4302
+ * shape keeps its ENTIRE current membership as a per-socket snapshot
4303
+ * (`Map&lt;rowKey, hash&gt;`) so the poll loop can diff it; that snapshot — and the
4304
+ * read buffer feeding it — scale with the membership size, multiplied by every
4305
+ * subscribed socket. An unbounded membership (a global table with no narrowing
4306
+ * shape predicate or RLS read scope) would grow them without limit and evict
4307
+ * the DO. A shape whose membership exceeds this cap is failed closed (left
4308
+ * empty, logged) rather than retained — the developer must narrow it. Sized
4309
+ * well above any reasonable per-identity replicated set so legitimate shapes
4310
+ * never trip it.
4311
+ */
4312
+ protected static readonly GLOBAL_SHAPE_MAX_ROWS = 5e4;
4313
+ /**
3921
4314
  * Per-socket whisper-topic cap. Topic membership rides the same hibernation
3922
4315
  * attachment as `subs`, so bound it for the same reason — a runaway
3923
4316
  * `whisper_subscribe` loop must not wedge the attachment past the runtime's
@@ -4017,6 +4410,39 @@ declare abstract class ShardDO {
4017
4410
  */
4018
4411
  private currentRequestMutationId;
4019
4412
  /**
4413
+ * Stable per-device client id for the in-flight custom-mutator push,
4414
+ * forwarded via the `x-lunora-client-id` header. Backs the
4415
+ * `__client_watermark` table: the dispatch path classifies the paired
4416
+ * `currentRequestClientSeq` against the stored high-watermark (already
4417
+ * processed / next / out-of-order gap). Absent on legacy mutations and
4418
+ * queries (those keep the `__idempotency` path). Cleared in `fetch`'s
4419
+ * `finally`.
4420
+ */
4421
+ private currentRequestClientId;
4422
+ /**
4423
+ * Monotonic per-client mutation sequence for the in-flight custom-mutator
4424
+ * push, forwarded via the `x-lunora-client-seq` header (numeric). Paired
4425
+ * with `currentRequestClientId` to drive the watermark classification.
4426
+ * `undefined` when absent or non-numeric.
4427
+ */
4428
+ private currentRequestClientSeq;
4429
+ /**
4430
+ * The in-flight push's custom-mutator classification, stashed by `fetch`
4431
+ * before `handleRpc` so the in-transaction bookkeeping ({@link
4432
+ * ShardDO.commitMutationBookkeeping}) can advance the `__client_watermark` for
4433
+ * a `"next"` push inside the same commit as the writes. `undefined` for an
4434
+ * ordinary mutation / non-mutator push. Cleared per request.
4435
+ */
4436
+ private currentMutatorClass;
4437
+ /**
4438
+ * Set once a mutation's replay bookkeeping (idempotency row + watermark
4439
+ * advance) has committed INSIDE the handler transaction, so the post-dispatch
4440
+ * path skips the now-redundant best-effort writes. Cleared per request; stays
4441
+ * `false` for actions/queries (no transaction wrapper) so their dispatch-level
4442
+ * idempotency persist still runs.
4443
+ */
4444
+ private mutationBookkeepingCommitted;
4445
+ /**
4020
4446
  * Wall-clock millis of the last `__idempotency` GC sweep on this warm
4021
4447
  * instance. The dedup write throttles `trimIdempotent` to at most once an
4022
4448
  * hour off this field (in-memory, so a fresh instance just sweeps on its
@@ -4047,6 +4473,18 @@ declare abstract class ShardDO {
4047
4473
  */
4048
4474
  private pendingChangedTables;
4049
4475
  /**
4476
+ * Coalesced set of tables awaiting a subscription-refresh pass, merged
4477
+ * across every {@link ShardDO.flushChangedTables} call that lands while a
4478
+ * pass is already draining. The single drain loop
4479
+ * ({@link ShardDO.drainSubscriptionRefreshes}) owns this set; a burst of N
4480
+ * writes to the same table therefore collapses into one (or two) refresh
4481
+ * passes instead of N, so each affected subscription's handler re-runs once
4482
+ * per burst rather than once per write. `undefined` when nothing is pending.
4483
+ */
4484
+ private pendingRefreshTables;
4485
+ /** True while {@link ShardDO.drainSubscriptionRefreshes} is running; the single-waiter gate that coalesces concurrent flushes. */
4486
+ private refreshInFlight;
4487
+ /**
4050
4488
  * Last pushed result per `(socket, subId)`, keyed by socket. Lets
4051
4489
  * `refreshSubscriptions` skip re-running queries whose tables were
4052
4490
  * untouched and suppress pushes when the re-run result is unchanged. Held
@@ -4054,6 +4492,39 @@ declare abstract class ShardDO {
4054
4492
  * memo simply forces one re-run and (at most) one redundant push.
4055
4493
  */
4056
4494
  private readonly subMemos;
4495
+ /**
4496
+ * Per-socket poke baseline for shape subscriptions: maps each shape's
4497
+ * subscription id to the `__cdc_log` cursor it has been poked through.
4498
+ * `pokeShapeSubscribers` reads each op page since this cursor and advances
4499
+ * it to the flush watermark. In-memory only (like {@link ShardDO.subMemos});
4500
+ * a cold memo on a reconnected/hibernated socket re-seeds from the client's
4501
+ * `sinceCheckpoint`.
4502
+ */
4503
+ private readonly shapeMemos;
4504
+ /**
4505
+ * Per-socket, per-**global**-shape membership snapshot: maps each global
4506
+ * shape's subscription id to a `key → projected-value JSON` map of the rows
4507
+ * last poked to that socket. A `.global()` (D1) table has no op-log to diff,
4508
+ * so {@link ShardDO.refreshGlobalShape} re-reads the full membership on each
4509
+ * alarm tick and diffs it against this snapshot to compute the poke. Parallel
4510
+ * to {@link ShardDO.shapeMemos} (the cursor baseline for poke-live shapes).
4511
+ *
4512
+ * This is a hot in-memory **cache** over the durable `__global_shape_snapshot`
4513
+ * table (keyed by the socket's `connectionId` + subId): a hibernation eviction
4514
+ * clears the WeakMap, so on the next alarm wake {@link ShardDO.readGlobalSnapshot}
4515
+ * misses and re-loads the baseline from SQLite — without it, the diff would run
4516
+ * against an empty baseline and a row deleted from D1 while the DO slept would
4517
+ * never be poked as a `delete`, lingering on the client as a phantom row.
4518
+ */
4519
+ private readonly globalShapeSnapshots;
4520
+ /**
4521
+ * Whether a global-shape poll alarm is currently armed. Guards
4522
+ * {@link ShardDO.scheduleGlobalPoll} from re-arming on every seed; reset in
4523
+ * {@link ShardDO.alarm} before the poll so a still-subscribed shape re-arms.
4524
+ */
4525
+ private globalPollScheduled;
4526
+ /** Monotonic per-DO poke id source; correlates a poke's `pokeStart`/`pokePart`/`pokeEnd` frames. */
4527
+ private pokeSequence;
4057
4528
  /** Per-socket whisper-rate token bucket (see {@link ShardDO.WHISPER_RATE_BURST}). In-memory; resets on hibernation. */
4058
4529
  private readonly whisperBuckets;
4059
4530
  /**
@@ -4072,6 +4543,35 @@ declare abstract class ShardDO {
4072
4543
  */
4073
4544
  private readonly metrics;
4074
4545
  /**
4546
+ * Running fan-out cost counters surfaced by the
4547
+ * `__lunora_admin__:getFanoutMetrics` RPC — one tally for the reactive
4548
+ * shape-poke path (`pokeShapeSubscribers`) and one for the whisper broadcast
4549
+ * path (`broadcastWhisper`). Each pass records the sockets it iterated (the
4550
+ * O(subscribers) cost) and delivered to. In-memory and reset on
4551
+ * hibernation/restart, sharing `metrics.sinceMs` as the "since this instance
4552
+ * woke" epoch. This is the observability half of plan 075's auto-elastic
4553
+ * relay tier (Phase 1): measure the per-flush fan-out cost so the promotion
4554
+ * threshold is grounded in real numbers, with no behavior change.
4555
+ */
4556
+ private readonly fanout;
4557
+ /**
4558
+ * The runtime's Durable Object namespace binding name (e.g. `"SHARD"`),
4559
+ * forwarded as `x-lunora-shard-binding` on every request so a DO can address
4560
+ * its siblings (`this.env[binding].getByName(...)`) for the relay hub. Absent
4561
+ * in single-DO mode / the unit harness — when absent, the relay tier is inert
4562
+ * and whispers stay shard-local (no behavior change). In-memory; re-learned per
4563
+ * request.
4564
+ */
4565
+ private shardBinding;
4566
+ /**
4567
+ * The auto-elastic fan-out relay collaborator (plan 075) — an {@link OwnerRelay}
4568
+ * or {@link RelayMember} chosen ONCE from this DO's name, or `undefined` for an
4569
+ * unnamed (single-DO) DO where the relay tier is inert. All relay state +
4570
+ * transport lives on it, reached back through the {@link RelayHost} adapter, so
4571
+ * owner-only state can never sit next to relay-only state on this class.
4572
+ */
4573
+ private readonly relay;
4574
+ /**
4075
4575
  * Declared indexes (`table:index`) a query has exercised since this instance
4076
4576
  * woke, stamped by `getCtxDbIndexUseHook`. In-memory and reset on
4077
4577
  * hibernation/restart — drives the `unused_index` runtime advisory.
@@ -4172,6 +4672,15 @@ declare abstract class ShardDO {
4172
4672
  webSocketClose(ws: WebSocket, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
4173
4673
  /** Hibernation API: invoked on socket error. */
4174
4674
  webSocketError(_ws: WebSocket, _error: unknown): void;
4675
+ /**
4676
+ * Durable Object alarm handler — the heartbeat for `.global()`-table shapes.
4677
+ * The runtime wakes this when the poll alarm armed by `scheduleGlobalPoll`
4678
+ * fires; it refreshes every subscribed global shape (diff-poke from the global
4679
+ * backend) and re-arms while any remain. With no global subscribers left, the
4680
+ * alarm is not re-armed and the DO goes idle. A base-only / global-free DO
4681
+ * never arms it, so this stays dormant there.
4682
+ */
4683
+ alarm(): Promise<void>;
4175
4684
  /** Subclasses implement function dispatch. */
4176
4685
  abstract handleRpc(functionPath: string, args: Record<string, unknown>): Promise<unknown>;
4177
4686
  /**
@@ -4418,6 +4927,35 @@ declare abstract class ShardDO {
4418
4927
  */
4419
4928
  protected studioFeatures(): StudioFeaturesResult;
4420
4929
  /**
4930
+ * Evaluate every statically-discovered feature flag under `context` for the
4931
+ * studio's read-only Flags page (`__lunora_admin__:listFlags`). The flag keys
4932
+ * + value types are discovered by `@lunora/codegen` from the app's
4933
+ * `ctx.flags.&lt;type>("key", …)` reads and evaluated through the configured
4934
+ * `@lunora/flags` provider — work only the codegen subclass can do, so it
4935
+ * overrides this. The base class wires no provider and reports
4936
+ * `configured: false` with zero flags (an un-generated `ShardDO` has none).
4937
+ */
4938
+ protected evaluateFlags(_context?: Record<string, unknown>): Promise<FlagsResult>;
4939
+ /**
4940
+ * Serve one reserved {@link FLAGS_FUNCTION_PREFIX} live flag read for the
4941
+ * React client's `useFlag`/`useFlags`. `functionPath` carries the flag key +
4942
+ * type and `args` the per-subscriber targeting context; the codegen subclass
4943
+ * overrides this to evaluate the flag through the app's `@lunora/flags`
4944
+ * provider under `identity` and return the resolved value. The base class
4945
+ * wires no provider, so it returns `null` — `resolveReactiveOutcome` reads
4946
+ * `null` as "nothing to deliver" and the subscriber keeps its default.
4947
+ */
4948
+ protected runFlagSubscriptionRead(_functionPath: string, _arguments: Record<string, unknown>, _identity?: SubscriptionIdentity): Promise<unknown>;
4949
+ /**
4950
+ * The Cloudflare Queues declared by this app, surfaced via
4951
+ * `__lunora_admin__:listQueues` for the studio's Queues page. Queues are NOT
4952
+ * Durable Objects and hold no shard state, so this is pure declaration
4953
+ * metadata statically discovered by `@lunora/codegen` from `lunora/queues.ts`
4954
+ * and emitted into the generated subclass, which overrides this. The base
4955
+ * class can't see the user's project, so it reports none.
4956
+ */
4957
+ protected queuesMetadata(): QueuesResult;
4958
+ /**
4421
4959
  * The Cloudflare Workflows declared by this app, surfaced via
4422
4960
  * `__lunora_admin__:listWorkflows` for the studio's Workflows page. Workflows
4423
4961
  * are NOT Durable Objects and hold no shard state, so this is pure
@@ -4580,16 +5118,117 @@ declare abstract class ShardDO {
4580
5118
  * unless the request carried an `x-lunora-mutation-id` header (queries and
4581
5119
  * legacy clients leave `currentRequestMutationId` undefined).
4582
5120
  *
4583
- * Called on the live dispatch path right after the handler's writes have
4584
- * auto-committed, through the same `this.sql` handle, so the dedup row is
4585
- * durable iff those writes are. (The DO has no ambient BEGIN/COMMIT around a
4586
- * mutation `handleRpc` invokes the user handler directly so this can't
4587
- * piggyback on a surrounding transaction; it commits as its own statement
4588
- * immediately after.) `INSERT OR IGNORE` keeps a concurrent double-dispatch
4589
- * of the same id idempotent. Also runs the throttled dedup-table GC.
5121
+ * For a mutation this runs INSIDE the handler's transaction (via
5122
+ * {@link ShardDO.commitMutationBookkeeping}, which `handleRpc` invokes before
5123
+ * the transaction commits), so the dedup row is durable iff the writes are —
5124
+ * closing the crash window where the writes commit but the replay guard does
5125
+ * not. Actions/queries aren't transaction-wrapped, so they call this on the
5126
+ * live dispatch path right after the handler resolves, through the same
5127
+ * `this.sql` handle. `INSERT OR IGNORE` keeps a concurrent double-dispatch (or
5128
+ * the now-skipped post-dispatch call) of the same id idempotent. Also runs the
5129
+ * throttled dedup-table GC.
4590
5130
  */
4591
5131
  protected persistIdempotentResult(result: unknown): void;
4592
5132
  /**
5133
+ * Whether `functionPath` names a registered custom mutator (a `defineMutator`
5134
+ * declaration) rather than an ordinary `mutation`. The base class knows of no
5135
+ * mutators, so the default is `false`; the codegen-generated subclass
5136
+ * overrides this to consult its mutator registry. When `true` (and the push
5137
+ * carries a `clientId`/`clientSeq`), the dispatch path applies the
5138
+ * `__client_watermark` ordering semantics instead of the legacy idempotency
5139
+ * dedup.
5140
+ */
5141
+ protected isCustomMutator(_functionPath: string): boolean;
5142
+ /**
5143
+ * Classify an in-flight custom-mutator push against the shard's stored
5144
+ * high-watermark for `currentRequestClientId`. The watermark is the highest
5145
+ * per-client sequence the DO has applied, so the push is exactly one of:
5146
+ *
5147
+ * - `"already"` — `seq &lt;= watermark`: a replay of a confirmed (or in-flight,
5148
+ * now-resent) mutation. The handler must NOT re-run; the dispatch path returns
5149
+ * a benign ack so the client drops the pending overlay.
5150
+ * - `"next"` — `seq == watermark + 1`: the next mutation in order. Run the
5151
+ * authoritative `server` impl and advance the watermark in the same commit.
5152
+ * - `"gap"` — `seq > watermark + 1`: an out-of-order arrival (an earlier push
5153
+ * was lost). Halt: the client must resend from `watermark + 1`.
5154
+ *
5155
+ * Returns `undefined` when the push is not a watermarked custom mutator
5156
+ * (missing client id/seq, or a stub `sql` handle without the table) so the
5157
+ * caller falls through to the legacy idempotency path.
5158
+ */
5159
+ protected classifyClientMutation(): ClientMutationClass | undefined;
5160
+ /**
5161
+ * Terminal response for a watermarked custom-mutator push that is NOT the
5162
+ * next-in-order mutation — an idempotent replay ack (`"already"`) or an
5163
+ * out-of-order halt (`"gap"`). Returns `undefined` for an ordinary mutation
5164
+ * or a `"next"` push so `fetch` proceeds to the authoritative handler. Records
5165
+ * the function call on the short-circuit paths so metrics stay attributed.
5166
+ */
5167
+ protected rejectNonNextMutation(functionPath: string, mutatorClass: ClientMutationClass | undefined, dispatchStartedAt: number): Response | undefined;
5168
+ /**
5169
+ * Respond to a dispatch that hit the `(identity, mutationId)` idempotency
5170
+ * cache. Records the (zero-work) function call, then: for a `"next"` custom
5171
+ * mutator whose handler already committed but whose watermark advance was
5172
+ * lost to a crash in between, re-advance and echo `lastMutationId` exactly as
5173
+ * the post-commit path does (otherwise the cached branch returns a bare
5174
+ * result with a stale watermark and the client reports every later seq as a
5175
+ * gap forever); for everything else, return the bare cached `{ result }`.
5176
+ */
5177
+ protected respondFromIdempotencyCache(functionPath: string, dispatchStartedAt: number, mutatorClass: ClientMutationClass | undefined, cachedValue: unknown): Response;
5178
+ /**
5179
+ * The CDC cursor a just-committed plain mutation landed at — the post-write
5180
+ * high-watermark, on the same scale as the `cursor` on `data`/`delta` frames.
5181
+ * The client drops a pending per-call optimistic overlay once it sees a frame
5182
+ * with `cursor >= commitCursor` (gapless reconciliation that keeps mutations
5183
+ * concurrent, without the serialized custom-mutator watermark). Scoped to a
5184
+ * mutation (carries an `x-lunora-mutation-id`) on a CDC-enabled shard;
5185
+ * `undefined` otherwise, leaving the wire byte-identical for queries/actions
5186
+ * and CDC-off shards.
5187
+ */
5188
+ protected mutationCommitCursor(): number | undefined;
5189
+ /**
5190
+ * Build the success response for a dispatched RPC. A `"next"` custom-mutator
5191
+ * push echoes the applied `lastMutationId` so the client drops the pending
5192
+ * optimistic overlay as soon as the ack lands; a plain mutation echoes
5193
+ * `commitCursor` (see {@link mutationCommitCursor}); other calls return the
5194
+ * bare `{ result }` envelope unchanged.
5195
+ */
5196
+ protected buildDispatchResponse(mutatorClass: ClientMutationClass | undefined, result: unknown): Response;
5197
+ /**
5198
+ * Commit a mutation's replay bookkeeping — the `(identity, mutationId)`
5199
+ * idempotency dedup row and, for a `"next"` custom-mutator push, the
5200
+ * `__client_watermark` advance — INSIDE the handler's transaction. Called by
5201
+ * the generated `handleRpc` mutation branch after the user handler resolves
5202
+ * but before the transaction commits, so the writes, the dedup row, and the
5203
+ * watermark land in one atomic commit: a crash can't leave the writes durable
5204
+ * without the replay guard (which a re-dispatch would otherwise re-run) nor
5205
+ * without the watermark. Sets {@link ShardDO.mutationBookkeepingCommitted} so
5206
+ * `fetch` skips the redundant post-dispatch persist.
5207
+ */
5208
+ protected commitMutationBookkeeping(result: unknown): void;
5209
+ /**
5210
+ * Best-effort replay bookkeeping for the live dispatch path, run after
5211
+ * `handleRpc` returns. A generated mutation already committed it atomically
5212
+ * inside its transaction (via {@link ShardDO.commitMutationBookkeeping}, which
5213
+ * sets the flag), so this skips. Actions/queries aren't transaction-wrapped,
5214
+ * so they record their dedup row here (a no-op without an `x-lunora-mutation-id`),
5215
+ * and a `"next"` push advances its watermark (the gap self-heals on replay).
5216
+ */
5217
+ protected recordPostDispatchBookkeeping(result: unknown, mutatorClass: ClientMutationClass | undefined): void;
5218
+ /**
5219
+ * Advance the stored high-watermark for the in-flight custom mutator to
5220
+ * `currentRequestClientSeq` through the same `this.sql` handle. On the
5221
+ * transactional path ({@link ShardDO.commitMutationBookkeeping}, `strict`) it
5222
+ * runs inside the handler's commit, so the watermark is durable iff the writes
5223
+ * are; a failure rethrows to roll the mutation back. On the best-effort
5224
+ * cache-hit recovery path (`strict` omitted) a missing table is swallowed —
5225
+ * the replay re-runs and re-advances (the read side treats a missing row as
5226
+ * watermark 0), so the gap self-heals.
5227
+ */
5228
+ protected advanceClientMutationWatermark(options?: {
5229
+ strict?: boolean;
5230
+ }): void;
5231
+ /**
4593
5232
  * Replay a batch of CDC changes into this shard (point-in-time recovery).
4594
5233
  * Schema-aware — it builds a `createShardCtxDb` writer — so the base class
4595
5234
  * can't implement it; the codegen-generated subclass overrides this to call
@@ -4608,6 +5247,17 @@ declare abstract class ShardDO {
4608
5247
  protected subscribe(ws: WebSocket, subId: string, query: SubscriptionQuery): "ok" | "serialize_failed" | "too_many";
4609
5248
  protected unsubscribe(ws: WebSocket, subId: string): void;
4610
5249
  /**
5250
+ * Register a live shape subscription on a socket — the partial-replication
5251
+ * parallel to {@link ShardDO.subscribe}. Stores the descriptor in the
5252
+ * attachment's `shapes` registry (created lazily) so it survives
5253
+ * hibernation, sharing the per-socket cap with `subs`. Returns a status the
5254
+ * caller surfaces as a structured error frame; never throws (a thrown
5255
+ * `webSocketMessage` is a fatal-channel error under the hibernation API).
5256
+ */
5257
+ protected shapeSubscribe(ws: WebSocket, subId: string, shape: ShapeSubscriptionQuery): "ok" | "serialize_failed" | "too_many";
5258
+ /** Remove a shape subscription and its poke baseline. Mirrors {@link ShardDO.unsubscribe}'s rollback-on-serialize-failure contract. */
5259
+ protected shapeUnsubscribe(ws: WebSocket, subId: string): void;
5260
+ /**
4611
5261
  * Decide whether a single subscription is interested in a mutation
4612
5262
  * delta. The default implementation checks the table name, then runs a
4613
5263
  * shallow-equality predicate over `query.args` against `delta.row`. A
@@ -4645,6 +5295,74 @@ declare abstract class ShardDO {
4645
5295
  */
4646
5296
  protected executeSubscription(_functionPath: string, _args: Record<string, unknown>, _identity?: SubscriptionIdentity): Promise<SubscriptionOutcome | null>;
4647
5297
  /**
5298
+ * Resolve a named shape to its concrete query plan for `identity`. The base
5299
+ * class has no shape registry, so it returns `undefined` — partial
5300
+ * replication is disabled and a `shape_subscribe` is rejected. The
5301
+ * codegen-generated subclass overrides this to look the shape up in the
5302
+ * project's `defineShape` registry, evaluate its `where(ctx, args)` under the
5303
+ * subscriber's verified identity, and AND-compose it with the table's RLS
5304
+ * read base-where into {@link ResolvedShape.effectiveWhere}.
5305
+ *
5306
+ * `identity` is the socket's OWN verified identity (the same unforgeable
5307
+ * value `refreshSubscriptions` threads), passed by value so this never reads
5308
+ * the mutable per-request identity fields. Returning `undefined` is the
5309
+ * fail-closed signal — an unknown shape, or an RLS-required table with no
5310
+ * policy resolving for this identity, yields no subscription rather than
5311
+ * leaking rows.
5312
+ */
5313
+ protected resolveShape(_name: string, _args: Record<string, unknown>, _identity?: SubscriptionIdentity): ResolvedShape | undefined;
5314
+ /**
5315
+ * The RLS-uniform gate (plan 075 Phase 3): whether a reactive shape may be
5316
+ * relay-multicast — i.e. one delta is correct for **every** subscriber. The owner
5317
+ * decides it (see {@link OwnerRelay.isShapeRelayUniform} — a static RLS read-policy
5318
+ * guard plus claim-exhaustive `Proxy` probes, fail-closed); this thin delegation
5319
+ * is the seam the gate test exercises. A non-owner DO is never relay-uniform.
5320
+ */
5321
+ protected isShapeRelayUniform(name: string, args: Record<string, unknown>): boolean;
5322
+ /**
5323
+ * Read the FULL current membership of a `.global()`-table shape from its D1
5324
+ * (or Hyperdrive) backend — the seed/poll source for the latency-tiered
5325
+ * global shape path. A `.global()` table lives in another store with no
5326
+ * per-DO op-log, so this is the only way to learn its rows from inside the
5327
+ * shard DO; {@link ShardDO.seedGlobalShape} calls it once on subscribe and
5328
+ * {@link ShardDO.refreshGlobalShape} on every alarm tick, diffing the result
5329
+ * against the per-socket snapshot to compute the poke.
5330
+ *
5331
+ * The base class has no global backend, so it returns `[]` (a base-only DO,
5332
+ * or a project with no global tables, never resolves a global shape). The
5333
+ * codegen subclass overrides it to drain `globalDb.findMany(table, { where:
5334
+ * effectiveWhere })` under the socket's verified `identity` — the same
5335
+ * unforgeable value `resolveShape` composed the RLS predicate with, so the
5336
+ * D1 read is identity-scoped exactly like the poke-live path.
5337
+ */
5338
+ protected readGlobalShapeRows(_resolved: ResolvedShape, _identity?: SubscriptionIdentity): Promise<ShapeRow[]>;
5339
+ /**
5340
+ * Poll external-source (`.source(...)`) tables once (plan 077): materialize
5341
+ * each sourced table's freshly-pulled tenant slice into this DO's SQLite. The
5342
+ * base `ShardDO` has no sourced tables, so it returns `0` and the ingest tier
5343
+ * stays dormant — zero behavior change for every existing DO. The codegen
5344
+ * subclass overrides it to, per sourced table, build a `createShardCtxDb`
5345
+ * writer, read the tenant slice from Hyperdrive under this DO's shard key, and
5346
+ * run `runExternalSourceTick` (read local baseline → diff → apply via the
5347
+ * validated CDC writer). Returns the number of sourced tables still being
5348
+ * polled, so the shared poll alarm ({@link ShardDO.alarm}) re-arms while ingest
5349
+ * is active.
5350
+ */
5351
+ protected pollExternalSources(): Promise<number>;
5352
+ /**
5353
+ * Arm the shared poll alarm for external-source ingest (plan 077). The alarm is
5354
+ * shared with the global-shape poll tier; the codegen subclass calls this once
5355
+ * (on construction / first sourced write) so a sourced DO starts its ingest
5356
+ * loop, after which {@link ShardDO.alarm} re-arms itself while
5357
+ * {@link ShardDO.pollExternalSources} reports remaining work. Idempotent; a
5358
+ * no-op when the runtime exposes no `setAlarm` (unit harness).
5359
+ */
5360
+ protected scheduleSourcePoll(): Promise<void>;
5361
+ /** This DO's shard key (its DO name), or `__root__` for the single-DO default. The `tenantBy` mapper binds it into the source query. */
5362
+ protected currentShardKey(): string;
5363
+ /** Record a contained external-source ingest failure (one sourced table's poll) into the log ring without aborting the others. */
5364
+ protected recordExternalSourceError(table: string, error: unknown): void;
5365
+ /**
4648
5366
  * Look up a streaming-query function and return a thunk that produces the
4649
5367
  * `AsyncIterable&lt;unknown>` when handed an {@link AbortSignal}. The codegen
4650
5368
  * subclass overrides this to dispatch via `LUNORA_FUNCTIONS`; the base
@@ -4837,6 +5555,26 @@ declare abstract class ShardDO {
4837
5555
  */
4838
5556
  private errorToResponse;
4839
5557
  /**
5558
+ * Batch dispatch (plan 088). Applies each `calls[]` entry through the SAME
5559
+ * single-call `/rpc` path (via a nested `this.fetch`), **sequentially**, so
5560
+ * the per-`(identity, mutationId)` idempotency dedup and the per-client
5561
+ * `__client_watermark` ordering are enforced entry-by-entry exactly as for an
5562
+ * individual call — no duplication of the dispatch core, no reordering.
5563
+ *
5564
+ * Failures are **per-slot, not fail-fast**: an entry that throws (or a
5565
+ * custom-mutator `OUT_OF_ORDER` gap) is captured in its own result slot and
5566
+ * later entries still run. Ordering is still safe — a later same-client
5567
+ * mutator after a gap re-classifies as a gap too (the watermark never
5568
+ * advanced), so it cannot apply out of order; unrelated entries/queries are
5569
+ * independent. The response is `{ results: [{ id, status, body }] }` in
5570
+ * request order; each `body` is the untouched single-call envelope (its
5571
+ * `result` already wire-encoded), so the client demuxes + decodes each
5572
+ * exactly as one call.
5573
+ */
5574
+ private handleBatchRpc;
5575
+ /** Dispatch one batch entry through the single-call `/rpc` path and capture its envelope (plan 088). */
5576
+ private dispatchBatchEntry;
5577
+ /**
4840
5578
  * Serve a reserved admin-introspection RPC (`__lunora_admin__:*`) for the
4841
5579
  * data browser. Gated by `env.LUNORA_ADMIN_TOKEN`: introspection is
4842
5580
  * **disabled unless the token is configured**, and when it is, the request
@@ -4920,6 +5658,16 @@ declare abstract class ShardDO {
4920
5658
  */
4921
5659
  private handleGetWorkflowInstanceStatus;
4922
5660
  /**
5661
+ * Serve `__lunora_admin__:listFlags` — the studio's read-only Flags page.
5662
+ * Evaluates every statically-discovered feature flag under an optional
5663
+ * `args.context` targeting context (the studio's editable context editor)
5664
+ * via the {@link evaluateFlags} hook, which the codegen subclass overrides
5665
+ * with live OpenFeature evaluation. Read-only: a flag lookup mutates no shard
5666
+ * state, so nothing is flushed or audited. Admin-gated by `handleAdminRpc`'s
5667
+ * caller.
5668
+ */
5669
+ private handleListFlags;
5670
+ /**
4923
5671
  * Run `run()` with the per-request identity pinned to (`userId`, `identity`),
4924
5672
  * then restore the prior values in a `finally` (even if `run()` throws), so the
4925
5673
  * forced identity can never leak into a later dispatch on this DO instance. The
@@ -5111,6 +5859,20 @@ declare abstract class ShardDO {
5111
5859
  * Read-only: it touches no SQLite and mutates no socket state.
5112
5860
  */
5113
5861
  private collectSubscriptions;
5862
+ /**
5863
+ * Assemble the `__lunora_admin__:getFanoutMetrics` payload for the Studio
5864
+ * fan-out observability panel (plan 075 Phase 1). The point-in-time topic
5865
+ * subscriber counts are folded live from each socket's attachment via
5866
+ * {@link summarizeFanoutTopics}; the running per-path cost counters are the
5867
+ * in-memory {@link ShardDO.fanout} tallies, sharing `metrics.sinceMs` as the
5868
+ * "since this instance woke" epoch. Touches no SQLite and mutates no socket
5869
+ * state; it does call `relay.relayCount()`, which advances the promotion
5870
+ * latch — safe here because that transition is a pure, monotonic function of
5871
+ * the live socket count (DOs are single-threaded), so a metrics poll only ever
5872
+ * drives the latch to the same state the routing path would compute for the
5873
+ * same count, never a divergent one.
5874
+ */
5875
+ private collectFanoutMetrics;
5114
5876
  /** Resolve a `getAuditLog` admin read, parsing the optional `limit`/`sinceSeq` cursor args and ensuring the reserved table first. */
5115
5877
  private readAdminAuditLog;
5116
5878
  /**
@@ -5179,6 +5941,49 @@ declare abstract class ShardDO {
5179
5941
  */
5180
5942
  private executeAdminSubscription;
5181
5943
  /**
5944
+ * Resolve one subscription (seed or refresh) to its {@link SubscriptionOutcome}
5945
+ * by routing the `functionPath` to the right read path — shared by
5946
+ * {@link seedSubscription} and {@link refreshSubscriptions} so both branch
5947
+ * identically:
5948
+ * - `__lunora_admin__:*` → {@link executeAdminSubscription} (raw SQLite read).
5949
+ * - {@link FLAGS_FUNCTION_PREFIX} → {@link runFlagSubscriptionRead} (the codegen subclass evaluates the flag through the configured provider). The value isn't bound to any table, so it is tagged with the {@link ADMIN_WILDCARD} dep — re-evaluated on every write-flush so a live `useFlag` stays current within a session. A `null` read means "nothing to deliver" (no provider, or a flag that resolved to `null`).
5950
+ * - everything else → {@link executeSubscription} (the user query, under the socket's own by-value identity).
5951
+ */
5952
+ private resolveReactiveOutcome;
5953
+ /**
5954
+ * SECURITY BOUNDARY for cross-socket reactive dedup. A read is
5955
+ * identity-INDEPENDENT only when its result cannot vary by the caller's
5956
+ * verified identity — i.e. the admin/reserved introspection reads, which
5957
+ * route to {@link executeAdminSubscription} and ignore the
5958
+ * {@link SubscriptionIdentity} entirely.
5959
+ *
5960
+ * Everything else is identity-DEPENDENT and must NEVER be shared across
5961
+ * sockets: a user query may be `rls()` / `ctx.auth`-scoped (different rows
5962
+ * per identity), and a flag read ({@link FLAGS_FUNCTION_PREFIX}) evaluates
5963
+ * the provider with the subscriber's identity (per-user targeting). Sharing
5964
+ * one socket's result with another would leak one identity's rows/flags to a
5965
+ * different identity, so this predicate gates {@link resolveReactiveOutcomeDeduped}
5966
+ * shut for them.
5967
+ */
5968
+ protected isIdentityIndependent(functionPath: string): boolean;
5969
+ /**
5970
+ * Memoizing wrapper over {@link resolveReactiveOutcome}: flush-local sharing across sockets.
5971
+ * Within a single {@link refreshSubscriptions} pass, N sockets subscribed to
5972
+ * the SAME identity-independent `(functionPath, args)` re-run the query N
5973
+ * times today (see the Case-6 fan-out characterization). When the read is
5974
+ * identity-independent (admin/reserved — see {@link isIdentityIndependent})
5975
+ * its result is the same for every socket, so the first run is cached (by its
5976
+ * in-flight Promise, since the bounded worker pool runs sockets in parallel)
5977
+ * and shared with the rest — collapsing N runs to ONE.
5978
+ *
5979
+ * Identity-DEPENDENT reads are passed straight through, UNCACHED: each socket
5980
+ * must evaluate under its own by-value identity (RLS / `ctx.auth` / per-user
5981
+ * flags), so they never share a result. The `cache` is created fresh per
5982
+ * flush by the caller, so a result is never reused across passes (it would go
5983
+ * stale after the next write).
5984
+ */
5985
+ private resolveReactiveOutcomeDeduped;
5986
+ /**
5182
5987
  * Constant-time bearer check against `env.LUNORA_ADMIN_TOKEN`. Returns
5183
5988
  * `false` (closed) when the token is unset so admin introspection is
5184
5989
  * opt-in rather than exposed by default.
@@ -5210,6 +6015,17 @@ declare abstract class ShardDO {
5210
6015
  */
5211
6016
  private flushChangedTables;
5212
6017
  /**
6018
+ * Drain {@link ShardDO.pendingRefreshTables} one coalesced batch at a time
6019
+ * until it is empty, then release the {@link ShardDO.refreshInFlight} gate.
6020
+ * Tables merged by a `flushChangedTables` that lands mid-pass are picked up
6021
+ * by the next loop iteration, so every committed write is observed by a
6022
+ * refresh that runs after it — bursts simply share a pass. The post-write
6023
+ * high-watermark and live-socket set are re-read inside each
6024
+ * `refreshSubscriptions` / `pokeShapeSubscribers` call, so a later batch
6025
+ * always reflects the latest committed state.
6026
+ */
6027
+ private drainSubscriptionRefreshes;
6028
+ /**
5213
6029
  * For every live subscription whose query reads one of `changed`, re-run
5214
6030
  * the query and push a fresh `{ type: "data" }` frame when the result
5215
6031
  * differs from the last one sent. Subscriptions with no `functionPath`
@@ -5282,6 +6098,216 @@ declare abstract class ShardDO {
5282
6098
  */
5283
6099
  private seedSubscription;
5284
6100
  /**
6101
+ * Drive the full `shape_subscribe` flow as one failure-aware unit: persist the
6102
+ * attachment, seed the shape, and ack ONLY once both succeed. A persist
6103
+ * rejection (`too_many`/`serialize_failed`) or a seed that can't resolve the
6104
+ * shape (unknown / RLS-denied / cross-shard-invalid) rolls the attachment back
6105
+ * and sends an `error` frame instead of acking — so a client is never left
6106
+ * acked but subscribed to a shape that will never deliver. Never throws (a
6107
+ * thrown `webSocketMessage` is fatal to the hibernating socket).
6108
+ */
6109
+ private handleShapeSubscribe;
6110
+ /** Send a structured `error` frame for a failed `shape_subscribe`, swallowing a send on an already-closed socket. */
6111
+ private sendShapeSubscribeError;
6112
+ /**
6113
+ * Seed a freshly-registered shape subscription. Resolves the shape under the
6114
+ * socket's verified identity, then ships either:
6115
+ *
6116
+ * - a **catch-up** poke (the membership diff in `(sinceCheckpoint, cursor]`)
6117
+ * when the client supplied a still-current checkpoint within the CDC retention
6118
+ * window and on this epoch — the cheap reconnect path; or
6119
+ * - a **full** insert-poke of the shape's entire current membership — a
6120
+ * first-time subscribe, or a reconnect that fell outside retention / forked
6121
+ * epoch.
6122
+ *
6123
+ * Either way the per-socket shape memo advances to the flush watermark so
6124
+ * later `pokeShapeSubscribers` passes diff from the right point.
6125
+ *
6126
+ * Returns `"ok"` once the shape resolved and its seed poke was attempted, or a
6127
+ * `{ code, message }` failure when the shape can't be resolved — an unknown /
6128
+ * RLS-denied shape (a base class with no registry resolves nothing), or a
6129
+ * `resolveShape` that threw (e.g. a cross-shard-join guard). The caller rolls
6130
+ * back the persisted attachment and errors instead of acking, so a client is
6131
+ * never left subscribed to a shape that will never deliver.
6132
+ */
6133
+ private seedShapeSubscription;
6134
+ /**
6135
+ * Seed a non-`.global()` (op-log-backed) shape: either a catch-up diff over
6136
+ * `(sinceSeq, cursor]` when the client supplied a still-current checkpoint on
6137
+ * this epoch within the CDC retention window, or a full membership insert-poke
6138
+ * otherwise. The memo advances to `cursor` only once the poke is delivered, so
6139
+ * a failed send re-diffs from the prior point rather than skipping rows. May
6140
+ * throw (a stub `sql` handle, a membership probe failure); the caller converts
6141
+ * it to a structured `shape_subscribe` error.
6142
+ */
6143
+ private seedOpLogShape;
6144
+ /**
6145
+ * Compute an op-log shape seed (cursor, epoch, the resume base, and the
6146
+ * membership `rowsPatch`) WITHOUT sending — the shared core of
6147
+ * {@link ShardDO.seedOpLogShape} (sends to a local socket) and the owner relay's
6148
+ * `buildShapeSeedFrames` (serializes the frames for a relay to deliver, plan 075
6149
+ * Phase 3, via the {@link RelayHost} seam). Resume only when CDC is on, the client is on this
6150
+ * epoch, its checkpoint doesn't run ahead of ours, and the log still covers it;
6151
+ * else a full re-seed. A fully-compacted log only proves "nothing missed" when
6152
+ * the client is already at `cursor`.
6153
+ * @returns the cursor/epoch, the resume base (`baseCheckpoint`), and the membership patch
6154
+ */
6155
+ private computeOpLogShapeSeed;
6156
+ /**
6157
+ * Fan the membership diff of every shape affected by this flush to its
6158
+ * subscribers — the partial-replication parallel to
6159
+ * {@link ShardDO.refreshSubscriptions}, called alongside it from
6160
+ * {@link ShardDO.flushChangedTables}. For each socket (bounded fan-out, same
6161
+ * concurrency + `awaitWsDrain` backpressure as the subscription path) it
6162
+ * resolves each shape under the socket's identity, diffs only the shapes
6163
+ * whose table changed in `(memoCursor, frameCursor]`, and emits one poke
6164
+ * carrying a part per changed shape. No-op when no socket holds a shape.
6165
+ */
6166
+ private pokeShapeSubscribers;
6167
+ /**
6168
+ * Diff every op-log-backed shape a socket holds against this flush, splitting
6169
+ * the results into the poke parts to send and the per-shape memo advances. A
6170
+ * `.global()` shape (driven by the alarm poll loop, not this flush) and a shape
6171
+ * whose table didn't change are skipped; a shape whose resolve/diff throws is
6172
+ * logged and skipped with its memo unadvanced so a later flush retries. Empty
6173
+ * diffs advance unconditionally; part-bearing shapes advance only once the
6174
+ * caller confirms the poke was delivered.
6175
+ */
6176
+ private collectShapePokeParts;
6177
+ /**
6178
+ * Drain the op-log range `(sinceSeq, upTo]` for `table` into the latest op per
6179
+ * row id (collapsing multiple ops on the same row to the newest). Within one
6180
+ * flush, every shape over the SAME `(table, sinceSeq, upTo)` reads the
6181
+ * identical changelog slice, so the drained map is memoized in the
6182
+ * caller-supplied `cache` (created fresh per flush) — N shapes on a table
6183
+ * share ONE changelog drain instead of re-scanning it per shape. The
6184
+ * per-shape membership probe still runs per shape (its predicate is
6185
+ * identity/args-specific), so only the shared op read is collapsed.
6186
+ */
6187
+ private readShapeOpRange;
6188
+ /**
6189
+ * Read one page of the `__cdc_log` for a shape diff (table-scoped). A thin
6190
+ * protected seam over {@link readCdcChanges}: it isolates the single
6191
+ * changelog read that {@link readShapeOpRange} memoizes per flush, and gives
6192
+ * tests a point to count the reads the op-range cache collapses.
6193
+ */
6194
+ protected readShapeCdcPage(sql: SqlExec, sinceSeq: number, tables: ReadonlySet<string>): {
6195
+ changes: CdcChange[];
6196
+ cursor: number;
6197
+ };
6198
+ /**
6199
+ * Build the row-ops for a shape over the op range `(sinceSeq, upTo]`. Reads
6200
+ * the changelog (drained across pages via {@link readShapeOpRange}, shared
6201
+ * across same-range shapes in a flush), collapses to the latest op per row,
6202
+ * then runs ONE membership probe ({@link selectShapeMemberIds}) over the
6203
+ * changed ids: a row still in the set → upsert with its post-image doc
6204
+ * (projected to the shape's columns); a row that left the set, or any delete,
6205
+ * → `delete(key)` (a delete carries no post-image, so membership is
6206
+ * unknowable from the op alone — the client no-ops an unknown key).
6207
+ */
6208
+ private buildShapeDiff;
6209
+ /** Build the full insert-poke of a shape's current membership — the first-seed/full-reseed rowset. */
6210
+ private buildShapeSeed;
6211
+ /**
6212
+ * Seed a `.global()`-table shape: read its full membership from D1, ship it
6213
+ * as one insert-poke, record the membership snapshot the alarm poll loop will
6214
+ * diff against, and arm the poll alarm. A global shape has no op-log cursor,
6215
+ * so the poke is stamped at this DO's current cursor (informational only) and
6216
+ * carries no resume base — a reconnect always re-seeds full.
6217
+ */
6218
+ private seedGlobalShape;
6219
+ /**
6220
+ * Re-read a global shape's membership from D1 and poke only the diff against
6221
+ * the socket's last snapshot: a new key → `insert`, a changed projected value
6222
+ * → `update`, a vanished key → `delete`. The snapshot advances to the fresh
6223
+ * membership even when the diff is empty, so the next tick compares from here.
6224
+ * No frame is sent when nothing changed (the common steady-state tick).
6225
+ */
6226
+ private refreshGlobalShape;
6227
+ /**
6228
+ * Read a socket's global-shape baseline, preferring the hot in-memory cache
6229
+ * and falling back to the durable `__global_shape_snapshot` table on a miss (a
6230
+ * cold socket after a hibernation eviction). The loaded baseline repopulates
6231
+ * the cache so subsequent ticks in this wake hit memory. An empty
6232
+ * `connectionId` (a socket that never went through the lifecycle-aware upgrade,
6233
+ * e.g. a unit harness) skips the durable read and behaves as in-memory-only.
6234
+ */
6235
+ private readGlobalSnapshot;
6236
+ /** Record a socket's latest global-shape membership snapshot in the in-memory cache (creating the per-socket map lazily). */
6237
+ private recordGlobalSnapshot;
6238
+ /**
6239
+ * Load a durable global-shape baseline from SQLite, or an empty map when none
6240
+ * is stored / the durable path is unavailable. A stub `sql` handle (unit
6241
+ * harness) or a missing table degrades to in-memory-only behavior rather than
6242
+ * failing the poll tick.
6243
+ */
6244
+ private loadGlobalSnapshot;
6245
+ /**
6246
+ * Persist a socket's global-shape baseline to SQLite so the poll-loop diff
6247
+ * survives hibernation. A no-op for a connection-id-less socket or a stub
6248
+ * `sql` handle (the in-memory cache then carries the baseline for the DO's
6249
+ * lifetime, matching the pre-durable behavior).
6250
+ */
6251
+ private saveGlobalSnapshot;
6252
+ /**
6253
+ * Arm the poll alarm for `.global()` shapes if one isn't already pending.
6254
+ * Idempotent — every global-shape seed calls it, but only the first arms the
6255
+ * alarm. Degrades to a no-op when the runtime exposes no `setAlarm` (the unit
6256
+ * harness): a global shape is then seed-only, which the poll-loop tests assert
6257
+ * by driving {@link ShardDO.alarm} directly.
6258
+ */
6259
+ private scheduleGlobalPoll;
6260
+ /**
6261
+ * Record a contained shape-tier error (poll / poke / seed) into the DO's log
6262
+ * ring without aborting the rest of the pass. The shape pipeline is a
6263
+ * best-effort fan-out: one socket's read or one shape's resolve failing must
6264
+ * never take down the others — so callers swallow the throw and surface it
6265
+ * here for diagnosis. `context` is a synthetic `shape:phase:subId` path.
6266
+ */
6267
+ private recordShapeError;
6268
+ /**
6269
+ * Guard a global shape's materialized membership against {@link
6270
+ * ShardDO.GLOBAL_SHAPE_MAX_ROWS}. Returns `true` when the row count is within
6271
+ * the cap; otherwise records a diagnosable error and returns `false` so the
6272
+ * caller fails the shape closed (no snapshot retained, no poke sent) rather
6273
+ * than risking a DO eviction on an unbounded global table. The transient read
6274
+ * buffer is bounded by the same gate — an over-cap membership is dropped, not
6275
+ * snapshotted per socket.
6276
+ */
6277
+ private withinGlobalShapeBound;
6278
+ /**
6279
+ * Refresh every `.global()`-table shape held across all live sockets, one
6280
+ * diff-poke per (socket, shape). Returns the number of global shapes still
6281
+ * subscribed so {@link ShardDO.alarm} knows whether to re-arm. Expired sockets
6282
+ * are dropped in passing (mirrors {@link ShardDO.pokeShapeSubscribers}).
6283
+ */
6284
+ private pollGlobalShapes;
6285
+ /**
6286
+ * Refresh one socket's `.global()`-table shapes, containing per-shape
6287
+ * failures so a single throw never aborts the poll tick (and with it the
6288
+ * re-arm). Returns the count of global shapes still subscribed on this socket
6289
+ * — a failed `resolveShape`/read keeps its shape counted so the alarm keeps
6290
+ * polling and retries next tick.
6291
+ */
6292
+ private pollSocketGlobalShapes;
6293
+ /**
6294
+ * Send one poke (`pokeStart` → `pokePart` per shape → `pokeEnd`) to a socket.
6295
+ * All parts apply atomically at `pokeEnd`. Returns `true` when every frame was
6296
+ * handed to the socket, `false` when a send threw mid-poke (the socket closed)
6297
+ * — callers must NOT advance their shape baselines on a `false` so the client
6298
+ * re-receives the rows on its next flush/reconnect instead of losing them.
6299
+ */
6300
+ private sendPoke;
6301
+ /**
6302
+ * The recipient client's `__client_watermark` for stamping a poke's
6303
+ * `lastMutationId`, or `undefined` when the socket announced no `clientId`
6304
+ * (a client that doesn't use custom mutators — nothing to drop an overlay
6305
+ * for). Read off the attachment so it survives hibernation.
6306
+ */
6307
+ private socketClientWatermark;
6308
+ /** Record a shape's poke baseline cursor on a socket (creating the per-socket map lazily). */
6309
+ private recordShapeMemo;
6310
+ /**
5285
6311
  * Record `outcome` as this socket's diff baseline for `subId` without
5286
6312
  * sending a frame. Used by the resume fast-path, where the client keeps its
5287
6313
  * cached value but the server still needs a baseline so the next
@@ -5353,6 +6379,15 @@ declare abstract class ShardDO {
5353
6379
  * on older runtimes, where it degrades to a no-op.
5354
6380
  */
5355
6381
  private armWebSocketKeepalive;
6382
+ /**
6383
+ * Route the non-RPC requests `fetch` handles before the shard-local RPC
6384
+ * endpoint: a WebSocket upgrade, and the internal `/_lunora/relay` owner↔relay
6385
+ * control channel (never reachable by a client — the runtime forwards only
6386
+ * worker-internal traffic there). Returns `undefined` for an RPC request, which
6387
+ * `fetch` then dispatches.
6388
+ * @returns the routed response, or `undefined` when this is an RPC request
6389
+ */
6390
+ private routeNonRpc;
5356
6391
  private handleWebSocketUpgrade;
5357
6392
  /**
5358
6393
  * Whether this shard has a `__cdc_log` table. The single source of the
@@ -5400,6 +6435,14 @@ declare abstract class ShardDO {
5400
6435
  * but per-topic auth does not exist here; see `whisperSubscribe` on the client.
5401
6436
  */
5402
6437
  private broadcastWhisper;
6438
+ /**
6439
+ * Deliver an already-serialized whisper `frame` to every local socket joined to
6440
+ * `topic`, excluding `exclude` (the sender, or `undefined` for a frame the relay
6441
+ * hub forwarded in — its sender lives on another DO). Records the fan-out pass
6442
+ * for `getFanoutMetrics` (plan 075 Phase 1). Pure delivery — no SQLite, no CDC.
6443
+ * @returns the number of sockets the frame was sent to
6444
+ */
6445
+ private deliverWhisperLocal;
5403
6446
  private readAttachment;
5404
6447
  }
5405
6448
  /**
@@ -5573,8 +6616,11 @@ interface WhereSqlStrategy {
5573
6616
  fieldRef: FieldRefSql;
5574
6617
  /**
5575
6618
  * Dialect `contains` rendering given the field reference and the (already
5576
- * bound) search term. Absent ⇒ the portable `… LIKE '%' || term || '%'`
5577
- * concat form (SQLite/Postgres); MySQL supplies a `CONCAT(...)` variant.
6619
+ * bound, already wildcard-escaped) search term. Absent ⇒ the portable
6620
+ * `… LIKE '%' || term || '%' ESCAPE '\'` concat form (SQLite/Postgres); MySQL
6621
+ * supplies a `CONCAT(...)` variant. The term is escaped by
6622
+ * {@link compileContains}, so an implementation MUST pair it with
6623
+ * `ESCAPE '\'` for the literal-match to hold.
5578
6624
  */
5579
6625
  likeContains?: (reference: SQL, term: SQL) => SQL;
5580
6626
  /**
@@ -5596,4 +6642,4 @@ interface WhereSqlStrategy {
5596
6642
  * `undefined` when the input imposes no constraint (empty `where`).
5597
6643
  */
5598
6644
  declare const compileWhereSql: (where: WhereInput | undefined, strategy: WhereSqlStrategy) => SQL | undefined;
5599
- export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, AGGREGATE_SQL_FUNCTION, AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, type AuthMetrics, type AuthMetricsBucket, type BroadcastDelta, CDC_LOG_TABLE, type CacheEntry, type CapturedMailRow, type CdcChange, type Clock, type ColumnMeta, type ColumnMetaLike, ConflictError, type CountArgs, CountRlsUnsupportedError, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_MAX_RELATION_KEYS, type DataMigrationDocument, type DataMigrationLike, type DataMigrationTransform, type DatabaseWriterLike, type DependencyTracker, type DeployInfo, type ExportRow, type ExportShardAdminArgs, type ExportShardArgs, FUNCTION_METRICS_BUCKETS_TABLE, FUNCTION_METRICS_BUCKET_MS, FUNCTION_METRICS_BUCKET_RETENTION, FUNCTION_METRICS_INDEX_TABLE, FUNCTION_METRICS_TABLE, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FieldOperators, type FunctionCallStat, type FunctionMetricBucket, type FunctionMetricIndexHit, type FunctionStatsResult, type GroupByEntry, type GroupByOptions, type HibernatableWebSocket, type IdGenerator, type ImportError, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IndexDefinitionLike, type IndexRangeBuilderLike, LogBuffer, type LogEntry, type LogEventInput, type LogLevel, type LogSink, MAIL_RETENTION, MAIL_TABLE, MAX_SQL_ROWS, MIN_ADMIN_TOKEN_LENGTH, MIN_AUTH_SECRET_LENGTH, type MaskColumnMetadata, type MaskPoliciesResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type OnDeleteActionLike, type OrderByInput, type OrderKey, type PaginationOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type QueryArgs, type QueryPage, RANK_TIEBREAK, RELATION_FUNCTION_PREFIX, RLS_UNWRAP_SYMBOL, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReadHook, type ReadTablePageOptions, type RecordAuthEventInput, type RecordFunctionMetricInput, type RecordMailInput, type RelationDefinitionLike, type RenderedSql, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkDeleteArgs, type RunShardBulkDeleteResult, type RunShardExportArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, type RunTriggersOptions, SCAN_DEP, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type SearchFilterBuilderLike, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, type SelectMatchingIdsOptions, type ServerDefaultContextLike, SessionDO, type SessionRecord, type SettingEntry, type SettingKind, type SettingsResult, ShardDO, type ShardDOOptions, type ShardDOState, type ShardRankPageResult, ShardRegistryDO, type SocketAttachment, type SortDirection$1 as SortDirection, type SqlConsoleResult, type SqlCursor, type SqlEngine, type SqlExec, type StorageRuleMetadata, type StorageRulesResult, type StudioFeaturesResult, type SubscriptionEnvelope, type SubscriptionOutcome, type SubscriptionQuery, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemReaderOptions, type SystemReaderSchedulerLike, type SystemReaderStorageLike, type SystemTableName, type TableColumnsResult, type TableDefinitionLike, type TableIndexInfo, type TableIndexesResult, type TableInfo, type TablePage, type TableReaderLike, type TablesColumnsResult, type TransactionSqlLike, type TriggerContextLike, type TriggerDefinitionLike, type TriggerEventLike, type TriggerOpLike, type TriggerTimingLike, type ValidatorLike, type WhereInput, type WhereSqlStrategy, type WithInput, type WorkflowMetadata, type WorkflowsResult, type WriteEvent, type WriteHook, aggregateSqlFunction, aggregateTableName, applyCdcChanges, applyOnDelete, armRestore, assertFlatPredicate, assertReadonly, assertValidClientId, backfillAggregateIndexes, backfillRankIndexes, buildFtsMatch, buildSecurityAudit, buildSeekWhere, clearCapturedMail, coerceAggregateNumber, compileWhereSql, containsRelationPredicate, createDependencyTracker, createShardCtxDb, createSystemReader, decodeCursor, depKey, encodeAggregateKey, encodeCursor, encodePartitionKey, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureMailTable, exportShardRows, exportShardTable, facetColumn, foldAggregateTally, ftsTableName, guardWriter, hasTrigger, importShardRows, isRelationPredicate, listTables, matchesRankStaticWhere, matchesStaticWhere, mergeWhere, normalizeCountArgument, normalizeIdStructurally, normalizeOrderKeys, parseExportShardArgs, parseImportShardArgs, planAggregateLookup, rankTableName, reactiveCacheKey, readAggregateValue, readAuthMetrics, readBookmark, readCapturedMail, readCdcChanges, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetrics, readFunctionMetricsTotals, readMigrationStatus, readTablePage, recordAuthEvent, recordCapturedMail, recordFunctionMetric, renderSql, resolveRankPartition, resolveRelationPredicates, resolveWith, runDataMigration, runReadonlySql, runRowValidators, runShardMigrations, runTriggers, scoreDocument, selectExportTables, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy, selectMatchingIds, serveRelationFanout, sortColumnName, stableStringify, stringifySearchText, subscriptionListDeltas, throwingScheduler, tokenizeSearch, trimCdcChanges, validateImportRow };
6645
+ export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, AGGREGATE_SQL_FUNCTION, AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, type AuthMetrics, type AuthMetricsBucket, type BroadcastDelta, CDC_LOG_TABLE, type CacheEntry, type CapturedMailRow, type CdcChange, type Clock, type ColumnMeta, type ColumnMetaLike, ConflictError, type CountArgs, CountRlsUnsupportedError, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_MAX_RELATION_KEYS, type DataMigrationDocument, type DataMigrationLike, type DataMigrationTransform, type DatabaseWriterLike, type DependencyTracker, type DeployInfo, type ExportRow, type ExportShardAdminArgs, type ExportShardArgs, type ExternalSourceDiffResult, type ExternalSourceLike, FLAGS_FUNCTION_PREFIX, FUNCTION_METRICS_BUCKETS_TABLE, FUNCTION_METRICS_BUCKET_MS, FUNCTION_METRICS_BUCKET_RETENTION, FUNCTION_METRICS_INDEX_TABLE, FUNCTION_METRICS_TABLE, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FieldOperators, type FlagEvaluation, type FlagsResult, type FunctionCallStat, type FunctionMetricBucket, type FunctionMetricIndexHit, type FunctionStatsResult, type GroupByEntry, type GroupByOptions, type HibernatableWebSocket, type IdGenerator, type ImportError, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IndexDefinitionLike, type IndexRangeBuilderLike, LogBuffer, type LogEntry, type LogEventInput, type LogLevel, type LogSink, MAIL_RETENTION, MAIL_TABLE, MAX_SQL_ROWS, MIN_ADMIN_TOKEN_LENGTH, MIN_AUTH_SECRET_LENGTH, type MaskColumnMetadata, type MaskPoliciesResult, type MaterializeResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type OnDeleteActionLike, type OrderByInput, type OrderKey, type PaginationOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type QueryArgs, type QueryPage, type QueueMetadata, type QueuesResult, RANK_TIEBREAK, RELATION_FUNCTION_PREFIX, RLS_UNWRAP_SYMBOL, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReadHook, type ReadTablePageOptions, type RecordAuthEventInput, type RecordFunctionMetricInput, type RecordMailInput, type RelationDefinitionLike, type RenderedSql, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkDeleteArgs, type RunShardBulkDeleteResult, type RunShardExportArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, type RunTriggersOptions, SCAN_DEP, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type SearchFilterBuilderLike, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, type SelectMatchingIdsOptions, type ServerDefaultContextLike, SessionDO, type SessionRecord, type SettingEntry, type SettingKind, type SettingsResult, type ShapeSubscriptionQuery, ShardDO, type ShardDOOptions, type ShardDOState, type ShardRankPageResult, ShardRegistryDO, type SocketAttachment, type SortDirection, type SourceClientLike, type SourceRefresh, type SqlConsoleResult, type SqlCursor, type SqlEngine, type SqlExec, type StorageRuleMetadata, type StorageRulesResult, type StudioFeaturesResult, type SubscriptionEnvelope, type SubscriptionOutcome, type SubscriptionQuery, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemReaderOptions, type SystemReaderSchedulerLike, type SystemReaderStorageLike, type SystemTableName, type TableColumnsResult, type TableDefinitionLike, type TableIndexInfo, type TableIndexesResult, type TableInfo, type TablePage, type TableReaderLike, type TablesColumnsResult, type TransactionSqlLike, type TriggerContextLike, type TriggerDefinitionLike, type TriggerEventLike, type TriggerOpLike, type TriggerTimingLike, type ValidatorLike, type WhereInput, type WhereSqlStrategy, type WithInput, type WorkflowMetadata, type WorkflowsResult, type WriteEvent, type WriteHook, aggregateSqlFunction, aggregateTableName, applyCdcChanges, applyOnDelete, applySelect, armRestore, assertFlatPredicate, assertReadonly, assertShapeShardable, assertValidClientId, backfillAggregateIndexes, backfillRankIndexes, buildFtsMatch, buildSecurityAudit, buildSeekWhere, clearCapturedMail, coerceAggregateNumber, compileWhereSql, containsRelationPredicate, createDependencyTracker, createShardCtxDb, createSystemReader, decodeCursor, depKey, diffExternalSource, encodeAggregateKey, encodeCursor, encodePartitionKey, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureMailTable, exportShardRows, exportShardTable, facetColumn, fanOutScalarCounts, foldAggregateTally, ftsTableName, guardWriter, hasTrigger, importShardRows, isRelationPredicate, isSourceDue, liftSourceId, listTables, matchesRankStaticWhere, matchesStaticWhere, materializeExternalRows, mergeWhere, normalizeCountArgument, normalizeIdStructurally, normalizeOrderKeys, parseExportShardArgs, parseImportShardArgs, planAggregateLookup, pullExternalSourceTick, rankTableName, reactiveCacheKey, readAggregateValue, readAuthMetrics, readBookmark, readCapturedMail, readCdcChanges, readExternalSourceBaseline, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetrics, readFunctionMetricsTotals, readMigrationStatus, readTablePage, recordAuthEvent, recordCapturedMail, recordFunctionMetric, renderSql, resolveRankPartition, resolveRelationPredicates, resolveWith, runDataMigration, runExternalSourceTick, runReadonlySql, runRowValidators, runShardMigrations, runTriggers, scoreDocument, selectExportTables, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy, selectMatchingIds, serveRelationFanout, softDeleteScope, sortColumnName, stableStringify, stringifySearchText, subscriptionListDeltas, throwingScheduler, tokenizeSearch, trimCdcChanges, validateImportRow };