@lunora/shard-engine 1.0.0-alpha.19 → 1.0.0-alpha.191

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 (168) hide show
  1. package/README.md +1 -1
  2. package/dist/conformance/index.mjs +1 -1
  3. package/dist/index.d.mts +1028 -227
  4. package/dist/index.d.ts +1028 -227
  5. package/dist/index.mjs +1 -1
  6. package/dist/packem_shared/ADMIN_FUNCTIONS-CSz3ZK2d.mjs +14 -0
  7. package/dist/packem_shared/ADMIN_TOKEN_TABLE-DfQ5osdI.mjs +1 -0
  8. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-C_ZipS9R.mjs +1 -0
  9. package/dist/packem_shared/AGG_COUNT-dVi3FAjZ.mjs +1 -0
  10. package/dist/packem_shared/AUDIT_LOG_TABLE-BFJ65SRS.mjs +8 -0
  11. package/dist/packem_shared/BIGINT_KEY_DIGITS-DE6yshOt.mjs +1 -0
  12. package/dist/packem_shared/CDC_LOG_TABLE-BFGgqai8.mjs +18 -0
  13. package/dist/packem_shared/CLIENT_WATERMARK_TABLE-De7z_OHV.mjs +7 -0
  14. package/dist/packem_shared/COMMIT_SEQ_FIELD-Da1DjGqo.mjs +4 -0
  15. package/dist/packem_shared/CURSOR_PREFIX-6offuG6M.mjs +1 -0
  16. package/dist/packem_shared/CompanionMemo-BXU5vfak.mjs +1 -0
  17. package/dist/packem_shared/CountRlsUnsupportedError-BvsDqfO2.mjs +1 -0
  18. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-CFvBS9-M.mjs +31 -0
  19. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BBtZ_jRj.mjs +1 -0
  20. package/dist/packem_shared/DEFAULT_MAX_RELAYS-Bc6PI-xy.mjs +8 -0
  21. package/dist/packem_shared/DEFAULT_PROMOTION_THRESHOLDS-VU44O5kq.mjs +1 -0
  22. package/dist/packem_shared/DEFAULT_TRANSACTION_LIMITS-D7p7Ys0M.mjs +1 -0
  23. package/dist/packem_shared/DurableStreamRunner-MMlV5qKQ.mjs +1 -0
  24. package/dist/packem_shared/GEO_DEFAULT_PRECISION-CqpQZ-J_.mjs +1 -0
  25. package/dist/packem_shared/GLOBAL_SHAPE_SNAPSHOT_TABLE-Bb6-aZuH.mjs +7 -0
  26. package/dist/packem_shared/GlobalPollTick-BNK4o-XT.mjs +1 -0
  27. package/dist/packem_shared/IDEMPOTENCY_TABLE-COrgeP3O.mjs +7 -0
  28. package/dist/packem_shared/MAIL_RETENTION-DMolrLYt.mjs +18 -0
  29. package/dist/packem_shared/MAX_SQL_ROWS-B4WlVI-e.mjs +5 -0
  30. package/dist/packem_shared/MAX_TOKEN_LENGTH-iFEGEcDL-DBPC6ZWl.mjs +1 -0
  31. package/dist/packem_shared/NotUniqueError-vJf9tj6U.mjs +1 -0
  32. package/dist/packem_shared/QUEUE_TABLE-C-goXtGd.mjs +17 -0
  33. package/dist/packem_shared/RANK_TIEBREAK-D3ye2GsL.mjs +1 -0
  34. package/dist/packem_shared/REACTOR_STATE_TABLE-D2Mn204f.mjs +28 -0
  35. package/dist/packem_shared/RELATED_DEFAULT_LIMIT-CVqN4JEu.mjs +1 -0
  36. package/dist/packem_shared/RELATION_EXISTS_KEY-wxgj6rSL.mjs +1 -0
  37. package/dist/packem_shared/RELAY_SIGNATURE_HEADER-CAfC4tqg.mjs +1 -0
  38. package/dist/packem_shared/REPROJECTION_MIGRATION_PREFIX-Czcb6_mO.mjs +1 -0
  39. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-H6J96vgK.mjs +1 -0
  40. package/dist/packem_shared/ReactiveCache-BG9z3FE9.mjs +1 -0
  41. package/dist/packem_shared/SCAN_DEP-B4Uu4g7l.mjs +1 -0
  42. package/dist/packem_shared/SCHEDULE_OUTBOX_TABLE-iyyiSjsO.mjs +18 -0
  43. package/dist/packem_shared/SCHEMA_HISTORY_MAX_VERSIONS-CEwFjj-O.mjs +6 -0
  44. package/dist/packem_shared/SEARCH_STATE_TABLE-D7w8mRsm.mjs +1 -0
  45. package/dist/packem_shared/SHAPE_POKE_CURSOR_TABLE-BGvY3sFI.mjs +8 -0
  46. package/dist/packem_shared/ShapeDiffCache-iNO-hUiy.mjs +1 -0
  47. package/dist/packem_shared/ShardRunner-CrveaPId.mjs +1 -0
  48. package/dist/packem_shared/UNVOUCHABLE_DEP-Ds9gxVqs.mjs +1 -0
  49. package/dist/packem_shared/VECTOR_BACKFILL_MAX_PAGES-DcQpf83n.mjs +1 -0
  50. package/dist/packem_shared/WORKERD_SQLITE_LIMITS-B_4w7tzY.mjs +1 -0
  51. package/dist/packem_shared/accepts-null-D1zmJbyR.mjs +1 -0
  52. package/dist/packem_shared/adminTokenExists-CjKKZzfY.mjs +7 -0
  53. package/dist/packem_shared/aggregateTableName-B_CtIQCS.mjs +1 -0
  54. package/dist/packem_shared/appendStreamChunk-BZYgGE9Y.mjs +17 -0
  55. package/dist/packem_shared/applyInsertDefaults-CVukTkQ5.mjs +1 -0
  56. package/dist/packem_shared/archiveCdcSegment-Cr8oGLfB.mjs +4 -0
  57. package/dist/packem_shared/{armRestore-BNzdvQ_o.mjs → armRestore-Bu1_8SUa.mjs} +1 -1
  58. package/dist/packem_shared/assertPatchAllowed-CA_H466g.mjs +1 -0
  59. package/dist/packem_shared/awaitWsDrain-DMcWBQ7I.mjs +1 -0
  60. package/dist/packem_shared/backfillAggregateIndexes-Pk0KLrfk.mjs +1 -0
  61. package/dist/packem_shared/buildIndexRange-BTChxh3k.mjs +1 -0
  62. package/dist/packem_shared/buildPokeFrames-WR-hp0mX.mjs +1 -0
  63. package/dist/packem_shared/buildReprojectionMigration-B8aEpETD.mjs +1 -0
  64. package/dist/packem_shared/buildSettings-CFkvTaHx.mjs +1 -0
  65. package/dist/packem_shared/buildShapeDiff-CdLJTijm.mjs +1 -0
  66. package/dist/packem_shared/clearMemoryTables-aMRERF0w.mjs +1 -0
  67. package/dist/packem_shared/compileWhereSql-TgKZIvWM.mjs +1 -0
  68. package/dist/packem_shared/computeRankPage-xm-70mLy.mjs +1 -0
  69. package/dist/packem_shared/constant-time-equal-BRh9yUCr.mjs +1 -0
  70. package/dist/packem_shared/createCompanionSync-CEht4hXX.mjs +1 -0
  71. package/dist/packem_shared/createReplicaLink-DtqXBi-0.mjs +7 -0
  72. package/dist/packem_shared/createSystemReader-BSCxr8Qs.mjs +1 -0
  73. package/dist/packem_shared/ctx-db-relay-shapes-DBobAek2.mjs +17 -0
  74. package/dist/packem_shared/ctx-db-search-state-CPKPy8N6.mjs +1 -0
  75. package/dist/packem_shared/defineEngineContractSuite-Bap9eB0W.mjs +1 -0
  76. package/dist/packem_shared/describeRelationWrites-omar6-u9.mjs +1 -0
  77. package/dist/packem_shared/diffExternalSource-B0FZlDoL.mjs +1 -0
  78. package/dist/packem_shared/do-sql-105TONaE.mjs +1 -0
  79. package/dist/packem_shared/effective-kind-BmG_zCAy.mjs +1 -0
  80. package/dist/packem_shared/envOptionalPositiveInt-D2pY-c64.mjs +1 -0
  81. package/dist/packem_shared/estimate-bytes-C-C35VXL.mjs +1 -0
  82. package/dist/packem_shared/exportShardRows-CZh4wrvI.mjs +1 -0
  83. package/dist/packem_shared/fts-companion-CE3EmIjk.mjs +1 -0
  84. package/dist/packem_shared/ftsCompanionDdl-B0bFCy6d.mjs +1 -0
  85. package/dist/packem_shared/hasTrigger-CjlwI4le.mjs +1 -0
  86. package/dist/packem_shared/isInternalTableName-BoljO2tP.mjs +1 -0
  87. package/dist/packem_shared/isPushableWhere-BeYAOjUb.mjs +1 -0
  88. package/dist/packem_shared/isSoftDeleted-BBWKE0Sm.mjs +9 -0
  89. package/dist/packem_shared/isTtlExpired-DNxmZA6e.mjs +1 -0
  90. package/dist/packem_shared/json-field-path-DeJW4U9z.mjs +1 -0
  91. package/dist/packem_shared/liftSourceId-CA3ENhXj.mjs +1 -0
  92. package/dist/packem_shared/materializeExternalRows-CHPRx8fu.mjs +1 -0
  93. package/dist/packem_shared/mergeChangedKeys-DPKhen6e.mjs +1 -0
  94. package/dist/packem_shared/relation-operators-BEg-CvCH.mjs +1 -0
  95. package/dist/packem_shared/relay-CKEdfUjH.mjs +1 -0
  96. package/dist/packem_shared/runDrizzle-RC09zZrh.mjs +1 -0
  97. package/dist/packem_shared/runShardMigrations-BPFg3Ht6.mjs +5 -0
  98. package/dist/packem_shared/runSocketPool-CZJ2X9cF.mjs +1 -0
  99. package/dist/packem_shared/selectShapeMembers-Dqx_m7BF.mjs +1 -0
  100. package/dist/packem_shared/serializeSqlValue-DeoBMpZ2.mjs +1 -0
  101. package/dist/packem_shared/stubByName-DQSivmvb.mjs +1 -0
  102. package/dist/packem_shared/where-sql-BjY4rnqb.mjs +1 -0
  103. package/package.json +5 -4
  104. package/dist/packem_shared/ADMIN_FUNCTIONS-OnYxyTXW.mjs +0 -1
  105. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CTo0-9iZ.mjs +0 -1
  106. package/dist/packem_shared/AGG_COUNT-CqQLWpb4.mjs +0 -1
  107. package/dist/packem_shared/AUDIT_LOG_TABLE-C6nwXFPd.mjs +0 -8
  108. package/dist/packem_shared/CDC_LOG_TABLE-ZqcflEen.mjs +0 -8
  109. package/dist/packem_shared/CLIENT_WATERMARK_TABLE-CzApRlyv.mjs +0 -7
  110. package/dist/packem_shared/CountRlsUnsupportedError-8BqPYQoP.mjs +0 -1
  111. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-BrpAGtXf.mjs +0 -31
  112. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-sPcXaWFW.mjs +0 -1
  113. package/dist/packem_shared/DEFAULT_MAX_RELAYS-CPBmX1FO.mjs +0 -1
  114. package/dist/packem_shared/DEFAULT_PROMOTION_THRESHOLDS-B2rUe1bg.mjs +0 -1
  115. package/dist/packem_shared/DEFAULT_TRANSACTION_LIMITS-q7ouI3i0.mjs +0 -1
  116. package/dist/packem_shared/GEO_DEFAULT_PRECISION-DyI5zggj.mjs +0 -1
  117. package/dist/packem_shared/GLOBAL_SHAPE_SNAPSHOT_TABLE-soMJDSBs.mjs +0 -7
  118. package/dist/packem_shared/IDEMPOTENCY_TABLE-Bvu9JkiL.mjs +0 -7
  119. package/dist/packem_shared/MAIL_RETENTION-BefR9Sei.mjs +0 -18
  120. package/dist/packem_shared/MAX_SQL_ROWS-nMwkxv5f.mjs +0 -2
  121. package/dist/packem_shared/NotUniqueError-BItFDsAw.mjs +0 -1
  122. package/dist/packem_shared/QUEUE_TABLE-DgBqWrXX.mjs +0 -17
  123. package/dist/packem_shared/RANK_TIEBREAK-DYDRmLKH.mjs +0 -1
  124. package/dist/packem_shared/RELATION_EXISTS_KEY-BaqSIFU1.mjs +0 -1
  125. package/dist/packem_shared/REPROJECTION_MIGRATION_PREFIX-D2dltRFC.mjs +0 -1
  126. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-DcqORh2s.mjs +0 -1
  127. package/dist/packem_shared/ReactiveCache-Cu8IfE1M.mjs +0 -1
  128. package/dist/packem_shared/SCAN_DEP-D_yR9EeV.mjs +0 -1
  129. package/dist/packem_shared/SCHEMA_HISTORY_MAX_VERSIONS-BEU0CuW5.mjs +0 -6
  130. package/dist/packem_shared/SEARCH_STATE_TABLE-BZ_fxI5l.mjs +0 -1
  131. package/dist/packem_shared/ShardRunner-DIqVdWtk.mjs +0 -1
  132. package/dist/packem_shared/aggregateTableName-DV-K7ft2.mjs +0 -1
  133. package/dist/packem_shared/applyOnDelete-BB6tr2G0.mjs +0 -1
  134. package/dist/packem_shared/applySelect-i17LYhIU.mjs +0 -1
  135. package/dist/packem_shared/awaitWsDrain-Bp2jKzIb.mjs +0 -1
  136. package/dist/packem_shared/backfillAggregateIndexes-tK0jrl43.mjs +0 -1
  137. package/dist/packem_shared/base64-fKomMf5D.mjs +0 -1
  138. package/dist/packem_shared/buildIndexRange-DFsdtPjD.mjs +0 -1
  139. package/dist/packem_shared/buildPokeFrames-CqxaN8_H.mjs +0 -1
  140. package/dist/packem_shared/buildReprojectionMigration-Ctl4r84d.mjs +0 -1
  141. package/dist/packem_shared/buildSettings-COIJsw7a.mjs +0 -1
  142. package/dist/packem_shared/compileWhereSql-B4rPariq.mjs +0 -1
  143. package/dist/packem_shared/computeRankPage-CRFgJbuz.mjs +0 -1
  144. package/dist/packem_shared/createCompanionSync-Gp-AesYj.mjs +0 -1
  145. package/dist/packem_shared/createReadFootprint-DIrrxRTE.mjs +0 -1
  146. package/dist/packem_shared/createSystemReader-DcDcrtM3.mjs +0 -1
  147. package/dist/packem_shared/ctx-db-companions-CAJOSdN-.mjs +0 -1
  148. package/dist/packem_shared/defineEngineContractSuite-CZccUN4c.mjs +0 -1
  149. package/dist/packem_shared/diffExternalSource-DMpkJta1.mjs +0 -1
  150. package/dist/packem_shared/do-sql-1Yi1_Yq0.mjs +0 -1
  151. package/dist/packem_shared/estimate-bytes-Drp8rhPs.mjs +0 -1
  152. package/dist/packem_shared/exportShardRows-Bbi_JGfn.mjs +0 -1
  153. package/dist/packem_shared/hasTrigger-CbkOHExZ.mjs +0 -1
  154. package/dist/packem_shared/isSoftDeleted-Bo-y3DOe.mjs +0 -9
  155. package/dist/packem_shared/liftSourceId-DApAbu7Q.mjs +0 -1
  156. package/dist/packem_shared/materializeExternalRows-DcCENzpV.mjs +0 -1
  157. package/dist/packem_shared/mergeChangedKeys-BXtUgIPW.mjs +0 -1
  158. package/dist/packem_shared/param-B5lF5Jd9.mjs +0 -1
  159. package/dist/packem_shared/runDrizzle-B6rnz3so.mjs +0 -1
  160. package/dist/packem_shared/runShardMigrations-n2dKcH5E.mjs +0 -5
  161. package/dist/packem_shared/runSocketPool-DPQLVyWF.mjs +0 -1
  162. package/dist/packem_shared/selectExpiredIds-C6nQK7E2.mjs +0 -1
  163. package/dist/packem_shared/selectShapeMemberIds-BdBcbrUP.mjs +0 -1
  164. package/dist/packem_shared/serializeSqlValue-BR4UOWoP.mjs +0 -1
  165. package/dist/packem_shared/sql-projection-jfoe331H.mjs +0 -1
  166. package/dist/packem_shared/stableStringify-BjLh4gvA.mjs +0 -1
  167. package/dist/packem_shared/stableWireKey-l3cjIt-9.mjs +0 -1
  168. package/dist/packem_shared/wire-codec-Dsy70M3Q.mjs +0 -1
package/dist/index.d.mts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { LunoraError } from '@lunora/errors';
2
+ import { R2BucketLike, ShardHost, SocketHost, SocketHandle } from '@lunora/platform';
2
3
  import { SQL, Name } from 'drizzle-orm';
3
- import { ShardHost, SocketHost, SocketHandle } from '@lunora/platform';
4
+ export { stableStringify, stableWireKey } from '@lunora/wire';
4
5
  interface KeyRange {
5
6
  hi: string;
6
7
  index: string;
@@ -22,15 +23,46 @@ declare const indexKeysForRow: (indexes: ReadonlyArray<{
22
23
  name: string;
23
24
  }>, row: Record<string, unknown>, serialize: (value: unknown) => unknown) => IndexKeyEntry[];
24
25
  declare const keysTouchRanges: (ranges: ReadonlyArray<KeyRange> | undefined, keys: ReadonlyArray<IndexKeyEntry> | undefined) => boolean;
26
+ interface RelationWriteBase {
27
+ readonly colocated: boolean;
28
+ readonly refusal?: string;
29
+ readonly table: string;
30
+ }
31
+ interface KeyedRelationWriteInfo extends RelationWriteBase {
32
+ readonly field: string;
33
+ readonly kind: "many" | "one";
34
+ readonly nullable: boolean;
35
+ readonly references: string;
36
+ readonly refusalNow?: never;
37
+ readonly through?: never;
38
+ }
39
+ interface ThroughRelationWriteInfo extends RelationWriteBase {
40
+ readonly kind: "many";
41
+ readonly pairIsOnlyUnique: boolean;
42
+ readonly refusalNow: () => string | undefined;
43
+ readonly through: {
44
+ readonly from: string;
45
+ readonly table: string;
46
+ readonly to: string;
47
+ };
48
+ }
49
+ type RelationWriteInfo = KeyedRelationWriteInfo | ThroughRelationWriteInfo;
50
+ type RelationWriteMap = Readonly<Record<string, Readonly<Record<string, RelationWriteInfo>>>>;
51
+ declare const describeRelationWrites: (schema: SchemaLike, inTransaction?: () => boolean) => RelationWriteMap;
25
52
  type SystemTableName = "_scheduled_functions" | "_storage";
26
53
  interface ScheduledFunctionDoc {
27
54
  args: Record<string, unknown>;
28
55
  attempts?: number;
56
+ completedAt?: number;
29
57
  enqueuedAt: number;
30
- functionPath: string;
58
+ error?: string;
59
+ functionPath?: string;
31
60
  id: string;
61
+ pool?: string;
32
62
  scheduledFor: number;
33
63
  shardKey?: string;
64
+ state?: "canceled" | "failed" | "pending" | "running" | "succeeded";
65
+ workflow?: string;
34
66
  }
35
67
  interface StorageMetadata {
36
68
  contentType?: string;
@@ -86,6 +118,89 @@ interface WhereInput {
86
118
  OR?: WhereInput[];
87
119
  }
88
120
  declare const RELATION_EXISTS_KEY = "__relationExists";
121
+ interface SubscriptionQuery {
122
+ args?: Record<string, unknown>;
123
+ functionPath?: string;
124
+ sinceClaims?: string;
125
+ sinceEpoch?: string;
126
+ sinceSeq?: number;
127
+ table?: string;
128
+ }
129
+ interface ShapeSubscriptionQuery {
130
+ args?: Record<string, unknown>;
131
+ name: string;
132
+ sinceEpoch?: string;
133
+ sinceSeq?: number;
134
+ }
135
+ interface SubscriptionEnvelope {
136
+ caps?: string[];
137
+ clientId?: string;
138
+ context?: Record<string, unknown>;
139
+ data?: unknown;
140
+ generation?: number;
141
+ id: string;
142
+ query?: SubscriptionQuery;
143
+ shape?: {
144
+ args?: Record<string, unknown>;
145
+ name: string;
146
+ };
147
+ sinceCheckpoint?: number;
148
+ sinceChunk?: number;
149
+ sinceClaims?: string;
150
+ sinceEpoch?: string;
151
+ token?: string;
152
+ topic?: string;
153
+ type: "ack" | "connect" | "shape_subscribe" | "shape_unsubscribe" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
154
+ }
155
+ interface RpcRequest {
156
+ args?: Record<string, unknown>;
157
+ functionPath: string;
158
+ }
159
+ interface SocketAttachment {
160
+ admin?: boolean;
161
+ adminBinding?: string;
162
+ authenticated?: boolean;
163
+ clientId?: string;
164
+ connected?: boolean;
165
+ connectionId?: string;
166
+ context?: Record<string, unknown>;
167
+ deliveryPermits?: Record<string, {
168
+ epoch: number;
169
+ scope: string;
170
+ }>;
171
+ expiresAt?: number;
172
+ identity?: Record<string, unknown>;
173
+ ip?: string;
174
+ liveGrants?: Record<string, string>;
175
+ pageDeltas?: boolean;
176
+ pendingSince?: number;
177
+ refreshBatch?: boolean;
178
+ revalidateAt?: number;
179
+ shapes?: Record<string, ShapeSubscriptionQuery>;
180
+ socketFunction?: string;
181
+ socketPath?: string;
182
+ subs: Record<string, SubscriptionQuery>;
183
+ userId?: string;
184
+ whispers?: string[];
185
+ }
186
+ interface ResolvedShape {
187
+ columns?: ReadonlyArray<string>;
188
+ effectiveWhere?: WhereInput;
189
+ global?: boolean;
190
+ table: string;
191
+ }
192
+ interface SubscriptionIdentity {
193
+ identity?: Record<string, unknown>;
194
+ ip?: string;
195
+ userId?: string;
196
+ }
197
+ interface ShardSocketLike {
198
+ readonly bufferedAmount?: number;
199
+ close?: (code?: number, reason?: string) => void;
200
+ deserializeAttachment?: () => unknown;
201
+ send: (data: string) => void;
202
+ serializeAttachment?: (value: unknown) => void;
203
+ }
89
204
  type AggregateOp = "avg" | "count" | "max" | "min" | "sum";
90
205
  interface AggregateIndexDefinitionLike {
91
206
  readonly by?: ReadonlyArray<string>;
@@ -137,6 +252,11 @@ interface ColumnMetaLike {
137
252
  interface ValidatorLike {
138
253
  readonly _meta?: {
139
254
  readonly column?: ColumnMetaLike;
255
+ readonly inner?: ValidatorLike;
256
+ readonly members?: ReadonlyArray<ValidatorLike>;
257
+ readonly shape?: Readonly<Record<string, ValidatorLike>>;
258
+ readonly tableName?: string;
259
+ readonly value?: unknown;
140
260
  };
141
261
  readonly kind?: string;
142
262
  readonly parse?: (value: unknown) => unknown;
@@ -144,7 +264,7 @@ interface ValidatorLike {
144
264
  type TriggerTimingLike = "after" | "before";
145
265
  type TriggerOpLike = "delete" | "insert" | "update";
146
266
  interface SchedulableWorkflowReferenceLike {
147
- readonly binding?: string;
267
+ readonly className?: string;
148
268
  readonly isLunoraWorkflow: true;
149
269
  readonly name?: string;
150
270
  }
@@ -178,11 +298,18 @@ interface SchemaLike {
178
298
  readonly rlsMode?: "required";
179
299
  readonly tables: Record<string, TableDefinitionLike>;
180
300
  }
301
+ type PatchVerifier = (previous: Record<string, unknown>, next: Record<string, unknown>) => boolean;
302
+ interface PatchWriteOptions {
303
+ verify?: PatchVerifier;
304
+ }
181
305
  interface TableDefinitionLike {
182
306
  readonly aggregateIndexes?: ReadonlyArray<AggregateIndexDefinitionLike>;
307
+ readonly commitOrderedMode?: boolean;
308
+ readonly dropStalePatchesMode?: boolean;
183
309
  readonly geoIndexes?: ReadonlyArray<GeoIndexDefinitionLike>;
184
310
  readonly indexes: ReadonlyArray<IndexDefinitionLike>;
185
311
  readonly isPublic?: boolean;
312
+ readonly memoryMode?: boolean;
186
313
  readonly rankIndexes?: ReadonlyArray<RankIndexDefinitionLike>;
187
314
  readonly relationMap?: Record<string, RelationDefinitionLike>;
188
315
  readonly searchIndexes?: ReadonlyArray<SearchIndexDefinitionLike>;
@@ -200,13 +327,25 @@ interface TableDefinitionLike {
200
327
  field: string;
201
328
  };
202
329
  }
203
- interface RelationDefinitionLike {
330
+ interface KeyedRelationDefinitionLike {
204
331
  readonly field: string;
205
332
  readonly kind: "many" | "one";
206
333
  readonly onDelete?: OnDeleteActionLike;
207
334
  readonly references: string;
208
335
  readonly table: string;
336
+ readonly through?: never;
337
+ }
338
+ interface RelationThroughLike {
339
+ readonly from: string;
340
+ readonly table: string;
341
+ readonly to: string;
209
342
  }
343
+ interface ThroughRelationDefinitionLike {
344
+ readonly kind: "many";
345
+ readonly table: string;
346
+ readonly through: RelationThroughLike;
347
+ }
348
+ type RelationDefinitionLike = KeyedRelationDefinitionLike | ThroughRelationDefinitionLike;
210
349
  type OnDeleteActionLike = "cascade" | "restrict" | "set null";
211
350
  interface NestedWith {
212
351
  limit?: number;
@@ -219,13 +358,11 @@ interface WithInput {
219
358
  [relationName: string]: NestedWith | Record<string, true> | boolean | undefined;
220
359
  _count?: Record<string, true>;
221
360
  }
222
- interface ApplyOnDeleteOptions$1 {
223
- database: DatabaseWriterLike;
224
- relation: RelationDefinitionLike;
225
- row: Record<string, unknown>;
226
- tableName: string;
361
+ interface FanOutBudget {
362
+ remaining: number;
227
363
  }
228
364
  interface ResolveWithOptions {
365
+ fanOutBudget?: FanOutBudget;
229
366
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
230
367
  groupedCounter: (tableName: string, whereField: string, values: unknown[], policyWhere?: WhereInput) => Promise<Map<unknown, number>>;
231
368
  parents: Record<string, unknown>[];
@@ -243,12 +380,19 @@ interface ResolveWithResult {
243
380
  rows: Record<string, unknown>[];
244
381
  }
245
382
  type SortDirection = "asc" | "desc";
246
- type OrderByInput = Record<string, SortDirection>;
383
+ type NullPlacement = "first" | "last";
384
+ type OrderByInput = Record<string, SortDirection | {
385
+ nulls: NullPlacement;
386
+ sort: SortDirection;
387
+ }>;
247
388
  interface QueryArgs {
248
389
  baseWhere?: WhereInput;
390
+ consistency?: "primary";
249
391
  cursor?: null | string;
392
+ endCursor?: null | string;
250
393
  includeDeleted?: boolean;
251
394
  limit?: number;
395
+ omitContinueCursor?: boolean;
252
396
  orderBy?: OrderByInput[];
253
397
  relationBaseWhere?: (table: string) => undefined | WhereInput;
254
398
  relationMask?: RelationMask;
@@ -264,15 +408,60 @@ interface CrossShardReadArgs {
264
408
  with?: WithInput;
265
409
  }
266
410
  type RelationMask = (table: string, rows: Record<string, unknown>[]) => Record<string, unknown>[];
411
+ interface QueryPlan {
412
+ params: unknown[];
413
+ plan: string[];
414
+ sql: string;
415
+ }
267
416
  interface QueryPage {
268
417
  continueCursor: null | string;
269
418
  isDone: boolean;
270
419
  page: Record<string, unknown>[];
271
420
  splitCursor?: null | string;
421
+ splitRequired?: boolean;
422
+ }
423
+ interface RelationEdge {
424
+ readonly array: boolean;
425
+ readonly column: string;
426
+ readonly name: string;
427
+ readonly sourceTable: string;
428
+ readonly targetTable: string;
429
+ }
430
+ interface RelatedStartReference {
431
+ id: string;
432
+ table: string;
433
+ }
434
+ type RelatedStart = (Record<string, unknown> & {
435
+ _id: string;
436
+ }) | RelatedStartReference;
437
+ type RelatedDirection = "both" | "in" | "out";
438
+ interface RelatedOptions {
439
+ cursor?: null | string;
440
+ depth?: number;
441
+ direction?: RelatedDirection;
442
+ edges?: ReadonlyArray<string>;
443
+ limit?: number;
444
+ relationBaseWhere?: (table: string) => undefined | WhereInput;
445
+ relationMask?: RelationMask;
446
+ }
447
+ interface RelatedNode {
448
+ depth: number;
449
+ document: Record<string, unknown>;
450
+ path: ReadonlyArray<string>;
451
+ pathIds: ReadonlyArray<string>;
452
+ score: number;
453
+ table: string;
454
+ }
455
+ interface RelatedPage {
456
+ continueCursor: null | string;
457
+ isDone: boolean;
458
+ nodes: RelatedNode[];
272
459
  }
273
460
  interface OrderKey {
274
461
  direction: SortDirection;
275
462
  field: string;
463
+ nullable: boolean;
464
+ nulls?: NullPlacement;
276
465
  }
277
466
  interface RestrictableQueryOptions {
278
467
  baseWhere?: WhereInput;
@@ -401,17 +590,15 @@ interface IndexRangeBuilderLike {
401
590
  lte: (field: string, value: unknown) => IndexRangeBuilderLike;
402
591
  }
403
592
  type BroadcastDelta = (delta: MutationDelta) => void;
404
- type ReadHook = (table: string, idOrScan?: string) => void;
593
+ type ReadHook = (table: string, idOrScan?: string, exact?: boolean) => void;
405
594
  interface LifecycleEvent {
406
595
  connectionId: string;
407
596
  context?: Record<string, unknown>;
408
597
  shardKey: string;
409
598
  userId: string | null;
410
599
  }
411
- interface LifecycleDispatchInfo {
600
+ interface LifecycleDispatchInfo extends SubscriptionIdentity {
412
601
  event: LifecycleEvent;
413
- identity: Record<string, unknown> | undefined;
414
- userId: string | undefined;
415
602
  }
416
603
  interface MutationDelta {
417
604
  indexKeys?: ReadonlyArray<IndexKeyEntry>;
@@ -423,9 +610,18 @@ interface MutationDelta {
423
610
  interface DatabaseWriterLike {
424
611
  aggregate: (tableName: string, options: AggregateOptions) => Promise<AggregateResult>;
425
612
  asId?: (tableName: string, id: string) => string;
613
+ assertPatchAllowed?: (table: string, id: string) => Promise<void>;
614
+ cdcChangedTables?: (sinceSeq: number, options?: {
615
+ cursorOnly?: boolean;
616
+ }) => Promise<{
617
+ cursor: number;
618
+ floor?: number;
619
+ tables: string[];
620
+ } | undefined>;
426
621
  count: (tableName: string, where?: RestrictableQueryOptions | WhereInput) => Promise<number>;
427
- delete: (id: string, expectedTable?: string, options?: {
622
+ delete: (table: string, id: string, options?: {
428
623
  hard?: boolean;
624
+ skipOnDelete?: boolean;
429
625
  }) => Promise<void>;
430
626
  deleteAll?: (tableName: string, options?: {
431
627
  chunkSize?: number;
@@ -433,20 +629,22 @@ interface DatabaseWriterLike {
433
629
  }) => Promise<{
434
630
  deleted: number;
435
631
  }>;
436
- deleteMany?: (ids: ReadonlyArray<string>, options?: {
632
+ deleteMany?: (table: string, ids: ReadonlyArray<string>, options?: {
437
633
  limit?: number;
438
- }, expectedTable?: string) => Promise<{
634
+ }) => Promise<{
439
635
  deleted: number;
440
636
  }>;
637
+ deleteRereadTables?: ReadonlySet<string>;
441
638
  deleteWhere?: (tableName: string, where: WhereInput, options?: {
442
639
  limit?: number;
443
640
  }) => Promise<{
444
641
  deleted: number;
445
642
  }>;
643
+ explain: (tableName: string, args?: QueryArgs) => Promise<QueryPlan>;
446
644
  findFirst: (tableName: string, args?: QueryArgs) => Promise<Record<string, unknown> | null>;
447
645
  findFirstOrThrow: (tableName: string, args?: QueryArgs) => Promise<Record<string, unknown>>;
448
646
  findMany: (tableName: string, args?: QueryArgs) => Promise<QueryPage>;
449
- get: (id: string, expectedTable?: string) => Promise<Record<string, unknown> | null>;
647
+ get: (table: string, id: string) => Promise<Record<string, unknown> | null>;
450
648
  groupBy: (tableName: string, options: GroupByOptions) => Promise<ReadonlyArray<GroupByEntry>>;
451
649
  insert: (tableName: string, document: Record<string, unknown>, options?: {
452
650
  allowExplicitId?: boolean;
@@ -460,18 +658,27 @@ interface DatabaseWriterLike {
460
658
  allowExplicitId?: boolean;
461
659
  limit?: number;
462
660
  }) => Promise<string[]>;
661
+ inTransaction?: () => boolean;
463
662
  lookupById?: (id: string, expectedTable?: string) => Promise<null | {
464
663
  row: Record<string, unknown>;
465
664
  tableName: string;
466
665
  }>;
467
666
  normalizeId: (tableName: string, id: string) => null | string;
468
- patch: (id: string, patch: Record<string, unknown>, expectedTable?: string) => Promise<void>;
469
- patchMany?: (patches: ReadonlyArray<{
667
+ patch: (table: string, id: string, patch: Record<string, unknown>, options?: PatchWriteOptions) => Promise<void>;
668
+ patchIf?: (tableName: string, id: string, args: {
669
+ patch: Record<string, unknown>;
670
+ verify?: PatchVerifier;
671
+ where: WhereInput;
672
+ }) => Promise<{
673
+ applied: boolean;
674
+ doc: Record<string, unknown> | null;
675
+ }>;
676
+ patchMany?: (table: string, patches: ReadonlyArray<{
470
677
  id: string;
471
678
  patch: Record<string, unknown>;
472
679
  }>, options?: {
473
680
  limit?: number;
474
- }, expectedTable?: string) => Promise<{
681
+ }) => Promise<{
475
682
  patched: number;
476
683
  }>;
477
684
  patchWhere?: (tableName: string, args: {
@@ -487,10 +694,14 @@ interface DatabaseWriterLike {
487
694
  rankBefore?: (tableName: string, indexName: string, options: RankBeforeOptions) => Promise<RankBeforeResult>;
488
695
  rankPage: (tableName: string, indexName: string, options?: RankPageOptions) => Promise<RankPage>;
489
696
  rankPageRows?: (tableName: string, indexName: string, options?: RankPageOptions) => Promise<ShardRankPageResult>;
490
- replace: (id: string, document: Record<string, unknown>, expectedTable?: string, options?: {
697
+ related?: (start: RelatedStart, options?: RelatedOptions) => Promise<RelatedPage>;
698
+ relationEdges?: ReadonlyArray<RelationEdge>;
699
+ relationWrites?: RelationWriteMap;
700
+ replace: (table: string, id: string, document: Record<string, unknown>, options?: {
491
701
  allowExplicitId?: boolean;
492
702
  }) => Promise<void>;
493
- restore?: (id: string, expectedTable?: string) => Promise<void>;
703
+ restore?: (table: string, id: string) => Promise<void>;
704
+ softDeleteFields?: ReadonlyMap<string, string>;
494
705
  system?: SystemDatabaseReader;
495
706
  wipeShard?: (options?: {
496
707
  chunkSize?: number;
@@ -515,17 +726,25 @@ interface ExportShardArgs {
515
726
  batchSize?: number;
516
727
  tables?: ReadonlyArray<string>;
517
728
  }
729
+ type ImportConflictMode = "replace" | "skip";
730
+ interface ImportRow extends ExportRow {
731
+ op?: string;
732
+ }
518
733
  interface ImportShardArgs {
519
- rows: ReadonlyArray<ExportRow>;
734
+ deletes?: boolean;
735
+ dryRun?: boolean;
736
+ onConflict?: ImportConflictMode;
737
+ rows: ReadonlyArray<ImportRow>;
520
738
  startLine?: number;
521
739
  }
522
740
  interface ImportShardResult {
523
741
  conflicts: number;
742
+ deleted: number;
524
743
  errors: ImportError[];
525
744
  inserted: Record<string, number>;
745
+ replaced: number;
526
746
  }
527
747
  declare const selectExportTables: (schema: SchemaLike, requested?: ReadonlyArray<string>) => string[];
528
- declare const exportShardTable: (writer: DatabaseWriterLike, table: string, batchSize?: number) => AsyncGenerator<ExportRow, void, undefined>;
529
748
  declare const exportShardRows: (writer: DatabaseWriterLike, schema: SchemaLike, args: ExportShardArgs) => AsyncGenerator<ExportRow, void, undefined>;
530
749
  declare const validateImportRow: (schema: SchemaLike, table: string, record: Record<string, unknown>) => string | undefined;
531
750
  declare const importShardRows: (writer: DatabaseWriterLike, schema: SchemaLike, args: ImportShardArgs) => Promise<ImportShardResult>;
@@ -534,47 +753,19 @@ interface ExportShardAdminArgs {
534
753
  tables?: ReadonlyArray<string>;
535
754
  }
536
755
  interface ImportShardAdminArgs {
537
- rows: ReadonlyArray<ExportRow>;
756
+ deletes: boolean;
757
+ dryRun: boolean;
758
+ onConflict: ImportConflictMode;
759
+ rows: ReadonlyArray<ImportRow>;
538
760
  startLine?: number;
539
761
  }
540
762
  declare const parseExportShardArgs: (args: Record<string, unknown>) => ExportShardAdminArgs;
541
763
  declare const parseImportShardArgs: (args: Record<string, unknown>) => ImportShardAdminArgs;
542
- declare const matchesStaticWhere: (document: Record<string, unknown>, predicate: Record<string, unknown>) => boolean;
543
- declare const normalizeCountArgument: (argument: RestrictableQueryOptions | undefined | WhereInput) => RestrictableQueryOptions;
544
- declare const AGGREGATE_SQL_FUNCTION: Record<string, string>;
545
- declare const aggregateSqlFunction: (op: string) => string;
546
- declare const throwingScheduler: SchedulerLike;
547
- declare const aggregateTableName: (table: string, indexName: string) => string;
548
- declare const coerceAggregateNumber: (value: unknown) => number | undefined;
549
- interface AggregateTally {
550
- count: number;
551
- value: null | number;
764
+ declare const clearCompanionSignatures: (sql: SqlExec) => void;
765
+ declare class CompanionMemo {
766
+ readonly verified: Set<string>;
767
+ invalidate(): void;
552
768
  }
553
- declare const foldAggregateTally: (tallies: Map<string, AggregateTally>, encoded: string, index: AggregateIndexDefinitionLike, record: Record<string, unknown>) => void;
554
- declare const readAggregateValue: (op: string, row: {
555
- count: number;
556
- value: null | number;
557
- } | undefined) => null | number;
558
- declare const encodeAggregateKey: (by: ReadonlyArray<string>, source: Record<string, unknown>) => string;
559
- declare class CountRlsUnsupportedError extends LunoraError {
560
- constructor(table?: string);
561
- }
562
- declare const mergeWhere: (left: undefined | WhereInput, right: undefined | WhereInput) => undefined | WhereInput;
563
- declare const planAggregateLookup: (index: AggregateIndexDefinitionLike, requestedWhere: Record<string, unknown> | undefined) => Record<string, unknown> | undefined;
564
- declare const selectIndexForCount: (indexes: ReadonlyArray<AggregateIndexDefinitionLike>, requestedWhere: Record<string, unknown> | undefined) => undefined | {
565
- index: AggregateIndexDefinitionLike;
566
- key: Record<string, unknown>;
567
- };
568
- declare const selectIndexForAggregate: (indexes: ReadonlyArray<AggregateIndexDefinitionLike>, op: AggregateOp, field: string, requestedWhere: Record<string, unknown> | undefined) => undefined | {
569
- index: AggregateIndexDefinitionLike;
570
- key: Record<string, unknown>;
571
- };
572
- declare const selectIndexForGroupBy: (indexes: ReadonlyArray<AggregateIndexDefinitionLike>, op: AggregateOp, field: string | undefined, by: ReadonlyArray<string>, requestedWhere: Record<string, unknown> | undefined) => undefined | {
573
- index: AggregateIndexDefinitionLike;
574
- partial: Record<string, unknown>;
575
- };
576
- declare const stableStringify: (value: unknown) => string;
577
- declare const stableWireKey: (value: unknown) => string;
578
769
  interface CacheEntry {
579
770
  bytes: number;
580
771
  deps: Set<string>;
@@ -600,6 +791,7 @@ declare class ReactiveCache {
600
791
  private readonly maxBytes;
601
792
  private readonly now;
602
793
  private monotonic;
794
+ private generation;
603
795
  constructor(options?: ReactiveCacheOptions);
604
796
  run<R>(key: string, deps: Set<string>, run: () => Promise<R>, ranges?: () => ReadonlyArray<KeyRange>): Promise<R>;
605
797
  invalidate(table: string, id: string, indexKeys?: ReadonlyArray<IndexKeyEntry>): string[];
@@ -627,28 +819,45 @@ declare class ReactiveCache {
627
819
  }
628
820
  declare const reactiveCacheKey: (functionPath: string, args: Record<string, unknown>, identity: null | string) => string;
629
821
  interface TransactionLimits {
822
+ maxReadBytes: number;
630
823
  maxReadRows: number;
631
824
  maxWrittenBytes: number;
632
825
  maxWrittenRows: number;
633
826
  }
634
827
  interface TransactionHeadroom {
828
+ readBytes: number;
635
829
  readRows: number;
830
+ remainingReadBytes: number;
636
831
  remainingReadRows: number;
637
832
  remainingWrittenBytes: number;
638
833
  remainingWrittenRows: number;
639
834
  writtenBytes: number;
640
835
  writtenRows: number;
641
836
  }
837
+ type TransactionLimitKind = "readBytes" | "readRows" | "writtenBytes" | "writtenRows";
838
+ interface TransactionLimitWarning {
839
+ kind: TransactionLimitKind;
840
+ limit: number;
841
+ used: number;
842
+ }
642
843
  declare const DEFAULT_TRANSACTION_LIMITS: TransactionLimits;
643
844
  declare class TransactionHeadroomTracker {
845
+ private readBytes;
644
846
  private readRows;
645
847
  private writtenRows;
646
848
  private writtenBytes;
647
849
  private readonly limits;
648
- constructor(limits?: Partial<TransactionLimits>);
850
+ private readonly onNearLimit;
851
+ private readonly warned;
852
+ private readonly chargedDocuments;
853
+ constructor(limits?: Partial<TransactionLimits>, onNearLimit?: (warning: TransactionLimitWarning) => void);
649
854
  recordRead(count: number): void;
855
+ recordReadBytes(bytes: number): void;
856
+ recordDocumentRead(key: string, bytes: number): void;
857
+ beginReadWindow(): void;
650
858
  recordWrite(row: unknown): void;
651
859
  headroom(): TransactionHeadroom;
860
+ private check;
652
861
  }
653
862
  interface RunTriggersOptions {
654
863
  ctx: TriggerContextLike;
@@ -660,12 +869,18 @@ interface RunTriggersOptions {
660
869
  }
661
870
  declare const runTriggers: (options: RunTriggersOptions) => Promise<void>;
662
871
  declare const hasTrigger: (schema: SchemaLike, tableName: string, op: TriggerOpLike) => boolean;
872
+ interface SearchBackfillProgress {
873
+ done: boolean;
874
+ pages: number;
875
+ }
663
876
  declare const backfillAggregateIndexes: (sql: SqlExec, schema: SchemaLike) => void;
664
877
  declare const backfillRankIndexes: (sql: SqlExec, schema: SchemaLike) => void;
665
878
  declare const backfillSearchIndexesForTable: (sql: SqlExec, tableName: string, definition: {
666
879
  searchIndexes?: ReadonlyArray<SearchIndexDefinitionLike>;
667
880
  }) => void;
668
- declare const backfillSearchIndexes: (sql: SqlExec, schema: SchemaLike) => void;
881
+ declare const backfillSearchIndexes: (sql: SqlExec, schema: SchemaLike, options?: {
882
+ maxPages?: number;
883
+ }) => SearchBackfillProgress;
669
884
  declare const CDC_LOG_TABLE = "__cdc_log";
670
885
  interface CdcChange {
671
886
  doc?: Record<string, unknown>;
@@ -675,19 +890,35 @@ interface CdcChange {
675
890
  table: string;
676
891
  ts: number;
677
892
  }
678
- declare const migrateCdcLog: (sql: SqlExec) => void;
893
+ declare const CDC_LOG_TABLE_SEQ_INDEX = "__cdc_log_table_seq";
894
+ declare const migrateCdcLog: (sql: SqlExec, options?: {
895
+ rowHistoryIndex?: boolean;
896
+ }) => void;
679
897
  declare const appendCdcChange: (sql: SqlExec, ts: number, table: string, id: string, op: CdcChange["op"], doc: Record<string, unknown> | undefined) => void;
680
898
  declare const readCdcChanges: (sql: SqlExec, options?: {
681
899
  limit?: number;
682
900
  sinceSeq?: number;
683
- tables?: ReadonlySet<string>;
684
901
  }) => {
685
902
  changes: CdcChange[];
686
903
  cursor: number;
687
904
  };
688
- declare const trimCdcChanges: (sql: SqlExec, throughSeq: number) => void;
905
+ declare const cdcTouchesTables: (sql: SqlExec, sinceSeq: number, tables: ReadonlySet<string>) => boolean;
906
+ declare const cdcCanVouchFor: (sql: SqlExec, deps: ReadonlySet<string>) => boolean;
907
+ interface CdcChangeKey {
908
+ id: string;
909
+ op: CdcChange["op"];
910
+ seq: number;
911
+ }
912
+ declare const readCdcChangeKeys: (sql: SqlExec, table: string, sinceSeq: number, upTo: number) => CdcChangeKey[];
913
+ declare const trimCdcChanges: (sql: SqlExec, throughSeq: number, maxRows: number) => void;
914
+ declare const compactCdcDocs: (sql: SqlExec, throughSeq: number, maxRows: number) => void;
915
+ declare const cdcSeqLeavingRows: (sql: SqlExec, keep: number) => number | undefined;
689
916
  declare const readCdcCursor: (sql: SqlExec) => number;
917
+ declare const cursorBelowRetainedFloor: (floor: number | undefined, sinceSeq: number) => boolean;
918
+ declare const cdcTrimmedError: (floor: number, sinceSeq: number, scope: "global" | "shard") => LunoraError;
919
+ declare const cdcForkedError: (cursor: number, sinceSeq: number, scope: "global" | "shard", epoch?: string) => LunoraError;
690
920
  declare const minCdcSeq: (sql: SqlExec) => number | undefined;
921
+ declare const minCdcReplayableSeq: (sql: SqlExec) => number | undefined;
691
922
  declare const CDC_META_TABLE = "__cdc_meta";
692
923
  declare const migrateCdcMeta: (sql: SqlExec) => void;
693
924
  declare const readCdcEpoch: (sql: SqlExec) => string;
@@ -697,12 +928,6 @@ declare const CLIENT_WATERMARK_TABLE = "__client_watermark";
697
928
  declare const migrateClientWatermark: (sql: SqlExec) => void;
698
929
  declare const readClientWatermark: (sql: SqlExec, identity: string, clientId: string) => number;
699
930
  declare const advanceClientWatermark: (sql: SqlExec, identity: string, clientId: string, mutationId: number) => void;
700
- declare const GLOBAL_SHAPE_SNAPSHOT_TABLE = "__global_shape_snapshot";
701
- declare const migrateGlobalShapeSnapshot: (sql: SqlExec) => void;
702
- declare const readGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string) => Map<string, string>;
703
- declare const writeGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string, snapshot: Map<string, string>) => void;
704
- declare const deleteGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string) => void;
705
- declare const deleteGlobalShapeSnapshotsForConnection: (sql: SqlExec, connectionId: string) => void;
706
931
  declare const IDEMPOTENCY_TABLE = "__idempotency";
707
932
  interface IdempotentRecord {
708
933
  resultJson: string;
@@ -714,61 +939,32 @@ declare const writeIdempotent: (sql: SqlExec, identity: string, mutationId: stri
714
939
  declare const trimIdempotent: (sql: SqlExec, olderThanTs: number) => void;
715
940
  declare const runShardMigrations: (sql: SqlExec, schema: SchemaLike, options?: {
716
941
  cdc?: boolean;
942
+ deferBlockedUniqueIndexes?: boolean;
717
943
  schemaSnapshot?: {
718
944
  hash: string;
719
945
  json: string;
720
946
  };
721
- }) => void;
722
- /**
723
- * How far a search companion's backfill has progressed, and what the next pass
724
- * should do about it.
725
- *
726
- * Neither stored analysis nor query policy, which is why it is its own module
727
- * rather than a third responsibility bolted onto one of them: it is *progress*,
728
- * the one piece of search state that is written as the index is built rather
729
- * than decided when it is read.
730
- *
731
- * The policy below is shared because when each engine owned a copy they
732
- * immediately disagreed about exactly the two cases that matter — whether a row
733
- * with no recorded profile may be resumed (it may not; nothing says what
734
- * analyzed it) and whether a never-started index is worth wiping (it is not;
735
- * there is nothing in it).
736
- */
737
- /**
738
- * How far a companion's backfill has progressed, and under which analysis.
739
- * Declared here rather than beside either engine's state table: both record the
740
- * same three facts, and the decisions made from them are the shared policy
741
- * below.
742
- */
743
- interface SearchBackfillState {
744
- /** Last `id` indexed, or `undefined` when no page has run yet. */
745
- cursor: string | undefined;
746
- /** True once a page came back short — the table is fully indexed. */
747
- done: boolean;
748
- /** Analyzer profile the stored rows were built with; `undefined` predates profile tracking. */
749
- profile: string | undefined;
750
- }
751
- declare const SEARCH_STATE_TABLE = "__lunora_search_state";
752
- declare const migrateSearchState: (sql: SqlExec) => void;
753
- declare const readSearchBackfillState: (sql: SqlExec, companion: string) => SearchBackfillState;
754
- declare const writeSearchBackfillState: (sql: SqlExec, companion: string, cursor: string | undefined, done: boolean, profile: string) => void;
947
+ }) => ReadonlyArray<string>;
755
948
  interface ShapeRow {
756
949
  doc: Record<string, unknown>;
757
950
  id: string;
758
951
  }
759
952
  declare const selectShapeRows: (sql: SqlExec, table: string, effectiveWhere: WhereInput | undefined) => ShapeRow[];
760
- declare const selectShapeMemberIds: (sql: SqlExec, table: string, effectiveWhere: WhereInput | undefined, ids: ReadonlyArray<string>) => Set<string>;
953
+ declare const selectShapeMembers: (sql: SqlExec, table: string, effectiveWhere: WhereInput | undefined, ids: ReadonlyArray<string>) => Map<string, Record<string, unknown>>;
761
954
  interface SqlExec {
762
955
  exec: <Row = Record<string, unknown>>(sql: string, ...params: unknown[]) => SqlCursor<Row>;
763
956
  }
764
957
  interface SqlCursor<Row> extends Iterable<Row> {
958
+ readonly columnNames?: string[];
765
959
  one: () => Row;
960
+ raw?: () => IterableIterator<unknown[]>;
766
961
  toArray: () => Row[];
767
962
  }
768
963
  type IndexUseHook = (table: string, indexName: string, kind: "geo" | "index" | "rank" | "search") => void;
769
964
  type Clock = () => number;
770
965
  type IdGenerator = () => string;
771
966
  declare const assertValidClientId: (clientId: string) => void;
967
+ declare const assertStorableRowId: (id: string) => void;
772
968
  interface WriteEvent {
773
969
  doc?: Record<string, unknown>;
774
970
  id: string;
@@ -778,18 +974,26 @@ interface WriteEvent {
778
974
  type WriteHook = (event: WriteEvent) => Promise<void> | void;
779
975
  interface CtxDbOptions {
780
976
  auth?: ServerDefaultContextLike["auth"];
977
+ baselineSeq?: () => number | undefined;
781
978
  broadcast?: BroadcastDelta;
782
979
  cache?: ReactiveCache;
783
980
  cdc?: boolean;
784
981
  clock?: Clock;
982
+ companionMemo?: CompanionMemo;
785
983
  enforceRls?: boolean;
786
984
  globalDb?: DatabaseWriterLike;
787
985
  headroom?: TransactionHeadroomTracker;
788
986
  idGenerator?: IdGenerator;
987
+ inTransaction?: () => boolean;
789
988
  maxRelationKeys?: number;
790
989
  onIndexUse?: IndexUseHook;
791
990
  onRead?: ReadHook;
792
991
  onReadRange?: (range: KeyRange) => void;
992
+ onStalePatchDropped?: (event: {
993
+ fields: string[];
994
+ id: string;
995
+ table: string;
996
+ }) => void;
793
997
  onWrite?: WriteHook;
794
998
  relationExistsPushDown?: "always" | "auto" | "never";
795
999
  scheduler?: SchedulerLike;
@@ -802,7 +1006,63 @@ declare class NotUniqueError extends LunoraError {
802
1006
  constructor(message?: string);
803
1007
  }
804
1008
  declare const normalizeIdStructurally: (schema: SchemaLike, tableName: string, id: string) => null | string;
1009
+ declare const assertNoExplicitUndefined: (op: "patch" | "patchIf" | "replace", document: Record<string, unknown>) => void;
1010
+ declare const stripReservedPatchFields: (patch: Record<string, unknown>) => Record<string, unknown>;
805
1011
  declare const createShardCtxDb: (options: CtxDbOptions) => DatabaseWriterLike;
1012
+ declare const ADMIN_TOKEN_TABLE = "__lunora_admin_tokens__";
1013
+ interface AdminTokenSummary {
1014
+ createdAt: number;
1015
+ expiresAt?: number;
1016
+ lastUsedAt?: number;
1017
+ name: string;
1018
+ }
1019
+ declare const createAdminTokenRecord: (sql: SqlExec, record: {
1020
+ createdAt: number;
1021
+ digest: string;
1022
+ expiresAt?: number;
1023
+ name: string;
1024
+ }) => boolean;
1025
+ declare const listAdminTokens: (sql: SqlExec) => AdminTokenSummary[];
1026
+ declare const revokeAdminTokenRecord: (sql: SqlExec, name: string, createdAt: number) => boolean;
1027
+ declare const verifyAdminTokenDigest: (sql: SqlExec, name: string, digest: string, now: number) => undefined | {
1028
+ createdAt: number;
1029
+ expiresAt?: number;
1030
+ };
1031
+ declare const adminTokenExists: (sql: SqlExec, name: string) => boolean;
1032
+ declare const matchesStaticWhere: (document: Record<string, unknown>, predicate: Record<string, unknown>) => boolean;
1033
+ declare const normalizeCountArgument: (argument: RestrictableQueryOptions | undefined | WhereInput) => RestrictableQueryOptions;
1034
+ declare const AGGREGATE_SQL_FUNCTION: Record<string, string>;
1035
+ declare const aggregateSqlFunction: (op: string) => string;
1036
+ declare const throwingScheduler: SchedulerLike;
1037
+ declare const aggregateTableName: (table: string, indexName: string) => string;
1038
+ declare const coerceAggregateNumber: (value: unknown) => number | undefined;
1039
+ interface AggregateTally {
1040
+ count: number;
1041
+ value: null | number;
1042
+ }
1043
+ declare const foldAggregateTally: (tallies: Map<string, AggregateTally>, encoded: string, index: AggregateIndexDefinitionLike, record: Record<string, unknown>) => void;
1044
+ declare const readAggregateValue: (op: string, row: {
1045
+ count: number;
1046
+ value: null | number;
1047
+ } | undefined) => null | number;
1048
+ declare const encodeAggregateKey: (by: ReadonlyArray<string>, source: Record<string, unknown>) => string;
1049
+ declare class CountRlsUnsupportedError extends LunoraError {
1050
+ constructor(table?: string);
1051
+ }
1052
+ declare const mergeWhere: (left: undefined | WhereInput, right: undefined | WhereInput) => undefined | WhereInput;
1053
+ declare const planAggregateLookup: (index: AggregateIndexDefinitionLike, requestedWhere: Record<string, unknown> | undefined) => Record<string, unknown> | undefined;
1054
+ declare const selectIndexForCount: (indexes: ReadonlyArray<AggregateIndexDefinitionLike>, requestedWhere: Record<string, unknown> | undefined) => undefined | {
1055
+ index: AggregateIndexDefinitionLike;
1056
+ key: Record<string, unknown>;
1057
+ };
1058
+ declare const selectIndexForAggregate: (indexes: ReadonlyArray<AggregateIndexDefinitionLike>, op: AggregateOp, field: string, requestedWhere: Record<string, unknown> | undefined) => undefined | {
1059
+ index: AggregateIndexDefinitionLike;
1060
+ key: Record<string, unknown>;
1061
+ };
1062
+ declare const selectIndexForGroupBy: (indexes: ReadonlyArray<AggregateIndexDefinitionLike>, op: AggregateOp, field: string | undefined, by: ReadonlyArray<string>, requestedWhere: Record<string, unknown> | undefined) => undefined | {
1063
+ index: AggregateIndexDefinitionLike;
1064
+ partial: Record<string, unknown>;
1065
+ };
806
1066
  declare const AUDIT_LOG_TABLE = "__lunora_audit__";
807
1067
  interface AuditEntry {
808
1068
  detail?: Record<string, unknown>;
@@ -825,68 +1085,23 @@ declare const readAuditLog: (sql: SqlExec, options?: {
825
1085
  limit?: number;
826
1086
  sinceSeq?: number;
827
1087
  }) => AuditEntry[];
828
- interface SubscriptionQuery {
829
- args?: Record<string, unknown>;
830
- functionPath?: string;
831
- sinceEpoch?: string;
832
- sinceSeq?: number;
833
- table?: string;
834
- }
835
- interface ShapeSubscriptionQuery {
836
- args?: Record<string, unknown>;
837
- name: string;
838
- sinceEpoch?: string;
839
- sinceSeq?: number;
840
- }
841
- interface SubscriptionEnvelope {
842
- clientId?: string;
843
- context?: Record<string, unknown>;
844
- data?: unknown;
845
- id: string;
846
- query?: SubscriptionQuery;
847
- shape?: {
848
- args?: Record<string, unknown>;
849
- name: string;
850
- };
851
- sinceCheckpoint?: number;
852
- sinceEpoch?: string;
853
- topic?: string;
854
- type: "ack" | "connect" | "shape_subscribe" | "shape_unsubscribe" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
855
- }
856
- interface RpcRequest {
857
- args?: Record<string, unknown>;
858
- functionPath: string;
859
- }
860
- interface SocketAttachment {
861
- admin?: boolean;
862
- clientId?: string;
863
- connected?: boolean;
864
- connectionId?: string;
865
- context?: Record<string, unknown>;
866
- expiresAt?: number;
867
- identity?: Record<string, unknown>;
868
- shapes?: Record<string, ShapeSubscriptionQuery>;
869
- subs: Record<string, SubscriptionQuery>;
870
- userId?: string;
871
- whispers?: string[];
872
- }
873
- interface ResolvedShape {
874
- columns?: ReadonlyArray<string>;
875
- effectiveWhere?: WhereInput;
876
- global?: boolean;
877
- table: string;
878
- }
879
- interface SubscriptionIdentity {
880
- identity?: Record<string, unknown>;
881
- userId?: string;
882
- }
883
- interface ShardSocketLike {
884
- readonly bufferedAmount?: number;
885
- close?: (code?: number, reason?: string) => void;
886
- deserializeAttachment?: () => unknown;
887
- send: (data: string) => void;
888
- serializeAttachment?: (value: unknown) => void;
889
- }
1088
+ interface CdcArchiveScope {
1089
+ epoch: string;
1090
+ shard: string;
1091
+ }
1092
+ declare const readCdcArchivedThrough: (sql: SqlExec) => number;
1093
+ declare const writeCdcArchivedThrough: (sql: SqlExec, seq: number) => void;
1094
+ declare const archiveCdcSegment: (bucket: R2BucketLike, scope: CdcArchiveScope, changes: CdcChange[]) => Promise<void>;
1095
+ declare const cdcArchiveRewound: (bucket: R2BucketLike, scope: CdcArchiveScope, archivedThrough: number) => Promise<boolean>;
1096
+ declare const readArchivedCdcChanges: (bucket: R2BucketLike, scope: CdcArchiveScope, sinceSeq: number, limit: number | undefined) => Promise<{
1097
+ changes: CdcChange[];
1098
+ cursor: number;
1099
+ } | undefined>;
1100
+ declare const COMMIT_SEQ_TABLE = "__commit_seq";
1101
+ declare const COMMIT_SEQ_FIELD = "_commitSeq";
1102
+ declare const migrateCommitSeq: (sql: SqlExec) => void;
1103
+ declare const readCommitSeq: (sql: SqlExec) => number;
1104
+ declare const allocateCommitSeq: (sql: SqlExec) => number;
890
1105
  interface CompanionSyncDeps {
891
1106
  broadcast: (delta: MutationDelta) => void;
892
1107
  indexKeysFor: (table: string, document?: Record<string, unknown>) => ReadonlyArray<{
@@ -897,6 +1112,7 @@ interface CompanionSyncDeps {
897
1112
  recordCdc: (table: string, id: string, op: "delete" | "insert" | "update", doc?: Record<string, unknown>) => void;
898
1113
  schema: SchemaLike;
899
1114
  sql: SqlExec;
1115
+ verified?: Set<string>;
900
1116
  }
901
1117
  interface CompanionSync {
902
1118
  ensureBackfilledForTable: (tableName: string) => void;
@@ -910,6 +1126,19 @@ interface CompanionSync {
910
1126
  syncSearch: (tableName: string, id: string, document: Record<string, unknown> | undefined, previous?: Record<string, unknown>) => void;
911
1127
  }
912
1128
  declare const createCompanionSync: (deps: CompanionSyncDeps) => CompanionSync;
1129
+ declare const GLOBAL_SHAPE_SNAPSHOT_TABLE = "__global_shape_snapshot";
1130
+ declare const migrateGlobalShapeSnapshot: (sql: SqlExec) => void;
1131
+ declare const readGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string) => Map<string, string> | undefined;
1132
+ declare const writeGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string, snapshot: Map<string, string>) => void;
1133
+ declare const deleteGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string) => void;
1134
+ declare const deleteGlobalShapeSnapshotsForConnection: (sql: SqlExec, connectionId: string) => void;
1135
+ declare const isMemoryTable: (definition: TableDefinitionLike | undefined) => boolean;
1136
+ declare const memoryTableNames: (schema: SchemaLike) => string[];
1137
+ declare const clearMemoryTables: (sql: SqlExec, schema: SchemaLike) => number;
1138
+ declare const resolveRankSeekTuple: (options: {
1139
+ after?: RankPageRowKey;
1140
+ cursor?: null | string;
1141
+ }) => unknown[] | undefined;
913
1142
  interface RankPageDeps {
914
1143
  assertRankPartitionLocal: (tableName: string, definition: TableDefinitionLike, index: RankIndexDefinitionLike) => void;
915
1144
  ensureRankBackfilled: (tableName: string, index: RankIndexDefinitionLike) => void;
@@ -927,8 +1156,92 @@ interface RankPageComputation {
927
1156
  key: RankPageRowKey;
928
1157
  }[];
929
1158
  }
930
- declare const hydrateDocsById: (deps: RankPageDeps, tableName: string, ids: ReadonlyArray<string>) => Map<string, Record<string, unknown>>;
931
1159
  declare const computeRankPage: (deps: RankPageDeps, tableName: string, indexName: string, rankPageOptions: RankPageOptions) => RankPageComputation;
1160
+ declare const SCHEDULE_OUTBOX_TABLE = "__schedule_outbox";
1161
+ interface ScheduleOutboxRow {
1162
+ attempts: number;
1163
+ envelopeJson: string;
1164
+ id: string;
1165
+ nextAttemptAt: number;
1166
+ }
1167
+ interface ScheduleOutboxEntry {
1168
+ attempts: number;
1169
+ createdAt: number;
1170
+ forever: boolean;
1171
+ id: string;
1172
+ nextAttemptAt: number;
1173
+ parked: boolean;
1174
+ target: string | undefined;
1175
+ when: number | undefined;
1176
+ }
1177
+ interface ScheduleOutboxEnvelope {
1178
+ args: unknown;
1179
+ options: Record<string, unknown> | undefined;
1180
+ target: unknown;
1181
+ when: number;
1182
+ }
1183
+ interface ScheduleOutbox {
1184
+ admit: (target: string) => number | undefined;
1185
+ forget: (id: string) => void;
1186
+ handOff?: (id: string, run: () => Promise<unknown>, token?: string) => Promise<void>;
1187
+ record: (id: string, envelope: ScheduleOutboxEnvelope) => string | undefined;
1188
+ wake: () => void;
1189
+ }
1190
+ declare const migrateScheduleOutbox: (sql: SqlExec) => void;
1191
+ declare const recordScheduleOutbox: (sql: SqlExec, id: string, envelopeJson: string, now: number) => void;
1192
+ declare const forgetScheduleOutbox: (sql: SqlExec, id: string) => void;
1193
+ declare const readDueScheduleOutbox: (sql: SqlExec, nowMs: number, limit: number) => ScheduleOutboxRow[];
1194
+ declare const readDueScheduleOutboxEntry: (sql: SqlExec, id: string, nowMs: number) => ScheduleOutboxRow | undefined;
1195
+ declare const deferScheduleOutbox: (sql: SqlExec, id: string, attempts: number, nextAttemptAt: number) => void;
1196
+ declare const parkScheduleOutbox: (sql: SqlExec, id: string, attempts: number, now: number) => void;
1197
+ declare const probeScheduleOutbox: (sql: SqlExec) => {
1198
+ dueAt: number | undefined;
1199
+ populated: boolean;
1200
+ };
1201
+ declare const trimScheduleOutbox: (sql: SqlExec, olderThanTs: number) => void;
1202
+ declare const readScheduleOutbox: (sql: SqlExec, limit: number, cursor?: string) => {
1203
+ entries: ScheduleOutboxEntry[];
1204
+ nextCursor: string | undefined;
1205
+ };
1206
+ declare const readScheduleOutboxState: (sql: SqlExec, id: string) => {
1207
+ createdAt: number;
1208
+ parked: boolean;
1209
+ version: string;
1210
+ } | undefined;
1211
+ declare const hasScheduleOutboxEntry: (sql: SqlExec, id: string) => boolean;
1212
+ declare const requeueScheduleOutbox: (sql: SqlExec, id: string, now: number) => boolean;
1213
+ declare const dropScheduleOutbox: (sql: SqlExec, id: string) => boolean;
1214
+ /**
1215
+ * How far a companion's backfill has progressed, and under which analysis.
1216
+ * Declared here rather than beside either engine's state table: both record the
1217
+ * same three facts, and the decisions made from them are the shared policy
1218
+ * below.
1219
+ */
1220
+ interface BackfillState {
1221
+ /** Last `id` indexed, or `undefined` when no page has run yet. */
1222
+ cursor: string | undefined;
1223
+ /** True once a page came back short — the table is fully indexed. */
1224
+ done: boolean;
1225
+ /** Analyzer profile the stored rows were built with; `undefined` predates profile tracking. */
1226
+ profile: string | undefined;
1227
+ }
1228
+ declare const SEARCH_STATE_TABLE = "__lunora_search_state";
1229
+ declare const migrateSearchState: (sql: SqlExec) => void;
1230
+ declare const readSearchBackfillState: (sql: SqlExec, companion: string) => BackfillState;
1231
+ declare const writeSearchBackfillState: (sql: SqlExec, companion: string, cursor: string | undefined, done: boolean, profile: string) => void;
1232
+ declare const SHAPE_POKE_CURSOR_TABLE = "__shape_poke_cursor";
1233
+ declare const migrateShapePokeCursor: (sql: SqlExec) => void;
1234
+ declare const readShapePokeCursor: (sql: SqlExec, connectionId: string, subId: string) => number | undefined;
1235
+ declare const writeShapePokeCursor: (sql: SqlExec, connectionId: string, subId: string, cursor: number) => void;
1236
+ interface ShapePokeCursorRow {
1237
+ connectionId: string;
1238
+ cursor: number;
1239
+ subId: string;
1240
+ }
1241
+ declare const writeShapePokeCursors: (sql: SqlExec, rows: ReadonlyArray<ShapePokeCursorRow>) => void;
1242
+ declare const minShapePokeCursor: (sql: SqlExec) => number | undefined;
1243
+ declare const deleteShapePokeCursor: (sql: SqlExec, connectionId: string, subId: string) => void;
1244
+ declare const deleteShapePokeCursorsForConnection: (sql: SqlExec, connectionId: string) => void;
932
1245
  declare const DATA_MIGRATION_STATE_TABLE = "__lunora_migrations";
933
1246
  type MigrationDirection = "down" | "up";
934
1247
  type MigrationStatus = "completed" | "failed" | "in_progress";
@@ -992,6 +1305,29 @@ interface DependencyTracker {
992
1305
  declare const createDependencyTracker: () => DependencyTracker;
993
1306
  declare const runSql: <Row = Record<string, unknown>>(sql: SqlExec, query: string, ...params: unknown[]) => SqlCursor<Row>;
994
1307
  declare const runDrizzle: <Row = Record<string, unknown>>(exec: SqlExec, query: SQL) => SqlCursor<Row>;
1308
+ type RangeOperandType = "boolean" | "number" | "string";
1309
+ interface WhereFragments<T> {
1310
+ binary: (reference: T, comparator: string, value: unknown) => T;
1311
+ connect: (left: T, right: T, connector: "AND" | "OR") => T;
1312
+ constant: (value: boolean) => T;
1313
+ contains: (reference: T, term: T) => T;
1314
+ inList: (reference: T, items: ReadonlyArray<unknown>, negated: boolean, budget: number) => T;
1315
+ negate: (inner: T) => T;
1316
+ nullCheck: (reference: T, negated: boolean) => T;
1317
+ value: (value: unknown) => T;
1318
+ }
1319
+ type FieldRefSql<T> = (field: string) => T;
1320
+ type SerializeValue = (value: unknown, field: string) => unknown;
1321
+ interface WhereSqlStrategy<T = SQL> {
1322
+ containsExpr?: (reference: T, term: T) => T;
1323
+ fieldRef: FieldRefSql<T>;
1324
+ inList?: (reference: T, items: ReadonlyArray<unknown>, negated: boolean, budget?: number) => T;
1325
+ rangeTypeGuard: (field: string, type: RangeOperandType) => T;
1326
+ relationExists?: (request: unknown) => T;
1327
+ serialize: SerializeValue;
1328
+ }
1329
+ declare const serverInList: (engine: "mysql" | "postgres") => (reference: SQL, items: ReadonlyArray<unknown>, negated: boolean, budget?: number) => SQL;
1330
+ declare const compileWhereSql: <T = SQL>(where: WhereInput | undefined, strategy: WhereSqlStrategy<T>, fragments?: WhereFragments<T>, reservedParams?: number) => T | undefined;
995
1331
  declare const quoteIdentifier: (name: string) => string;
996
1332
  declare const serializeSqlValue: (value: unknown) => unknown;
997
1333
  declare const DOC_COLUMN = "__doc__";
@@ -1005,10 +1341,16 @@ declare const AGG_KEY: Name;
1005
1341
  declare const AGG_VALUE: Name;
1006
1342
  declare const AGG_COUNT: Name;
1007
1343
  declare const aggUpsertSql: (aggTable: string, key: unknown, value: unknown, count: unknown, set: SQL) => SQL;
1008
- declare const tableColumns: (definition: TableDefinitionLike) => [string, ColumnMetaLike][];
1344
+ declare const tableColumns: (definition: TableDefinitionLike) => ReadonlyArray<readonly [string, ColumnMetaLike]>;
1009
1345
  declare const rowToDocument: (row: Record<string, unknown> | undefined) => Record<string, unknown> | undefined;
1010
1346
  declare const tryRowToDocument: (row: Record<string, unknown> | undefined) => Record<string, unknown> | undefined;
1011
- declare const isFtsAvailable: (sql: SqlExec) => boolean;
1347
+ declare const isFtsAvailable: (wrapper: SqlExec) => boolean;
1348
+ declare const WORKERD_SQLITE_LIMITS: {
1349
+ readonly boundParams: 100;
1350
+ readonly compoundSelect: 5;
1351
+ readonly likePattern: 50;
1352
+ readonly sqlTextLength: 100000;
1353
+ };
1012
1354
  type SqlEngine = "mysql" | "postgres" | "sqlite";
1013
1355
  interface RenderedSql {
1014
1356
  params: unknown[];
@@ -1016,6 +1358,79 @@ interface RenderedSql {
1016
1358
  }
1017
1359
  declare const renderSql: (engine: SqlEngine, query: SQL) => RenderedSql;
1018
1360
  declare const param: (value: unknown) => SQL;
1361
+ declare const unionAll: (branches: ReadonlyArray<SQL>) => SQL;
1362
+ declare const sqliteInList: (reference: SQL, items: ReadonlyArray<unknown>, negated: boolean, budget?: number) => SQL;
1363
+ type DurableStreamStatus = "complete" | "error" | "running";
1364
+ interface DurableStreamRun {
1365
+ error?: string;
1366
+ errorCode?: string;
1367
+ lastSeq: number;
1368
+ startedAt: number;
1369
+ status: DurableStreamStatus;
1370
+ }
1371
+ interface DurableStreamChunk {
1372
+ dataJson: string;
1373
+ seq: number;
1374
+ }
1375
+ declare const migrateDurableStreams: (sql: SqlExec) => void;
1376
+ declare const readStreamRun: (sql: SqlExec, runKey: string) => DurableStreamRun | undefined;
1377
+ declare const claimStreamRun: (sql: SqlExec, runKey: string, startedAt: number, ttlMs: number) => boolean;
1378
+ declare const deleteStreamRun: (sql: SqlExec, runKey: string) => void;
1379
+ declare const appendStreamChunk: (sql: SqlExec, runKey: string, seq: number, dataJson: string) => void;
1380
+ declare const readStreamChunks: (sql: SqlExec, runKey: string, sinceSeq: number) => DurableStreamChunk[];
1381
+ declare const finishStreamRun: (sql: SqlExec, runKey: string, status: "complete" | "error", lastSeq: number, failure?: {
1382
+ code: string;
1383
+ message: string;
1384
+ }) => void;
1385
+ declare const trimStreamRuns: (sql: SqlExec, now: number, live: ReadonlySet<string>) => void;
1386
+ declare const MAX_DURABLE_STREAM_CHUNKS = 50000;
1387
+ declare const MAX_DURABLE_STREAM_BYTES: number;
1388
+ interface DurableStreamSink {
1389
+ readonly chunk: (chunk: {
1390
+ data: unknown;
1391
+ generation?: number;
1392
+ seq: number;
1393
+ }) => boolean;
1394
+ readonly complete: () => void;
1395
+ readonly fail: (failure: {
1396
+ code: string;
1397
+ message: string;
1398
+ }) => void;
1399
+ }
1400
+ type DurableAttachDecision = "attach" | "interrupted" | "reclaim" | "replay-terminal";
1401
+ declare const decideDurableAttach: (run: DurableStreamRun | undefined, context: {
1402
+ generation?: number;
1403
+ live?: {
1404
+ generation: number;
1405
+ };
1406
+ resuming: boolean;
1407
+ }) => DurableAttachDecision;
1408
+ interface DurableStreamAttach {
1409
+ readonly generation?: number;
1410
+ readonly iterator: (signal: AbortSignal) => AsyncIterable<unknown>;
1411
+ readonly runKey: string;
1412
+ readonly sinceChunk: number;
1413
+ readonly sink: DurableStreamSink;
1414
+ readonly ttlMs?: number;
1415
+ }
1416
+ declare class DurableStreamRunner {
1417
+ private lastTrimAt;
1418
+ private readonly runs;
1419
+ private readonly sql;
1420
+ private readonly waitUntil;
1421
+ constructor(dependencies: {
1422
+ sql: () => SqlExec;
1423
+ waitUntil?: (promise: Promise<unknown>) => void;
1424
+ });
1425
+ attach(request: DurableStreamAttach): Promise<void>;
1426
+ detach(runKey: string, sink: DurableStreamSink): void;
1427
+ isLive(runKey: string): boolean;
1428
+ private attachOrThrow;
1429
+ private produce;
1430
+ private trim;
1431
+ }
1432
+ declare const envPositiveInt: (env: unknown, key: string, fallback: number) => number;
1433
+ declare const envOptionalPositiveInt: (env: unknown, key: string) => number | undefined;
1019
1434
  interface ExternalSourceDiffResult {
1020
1435
  changes: CdcChange[];
1021
1436
  nextBaseline: Map<string, string>;
@@ -1080,6 +1495,16 @@ declare const isSoftDeleted: (row: Record<string, unknown>, column: string) => b
1080
1495
  declare const pullExternalSourceIncrementalTick: (sql: SqlExec, writer: DatabaseWriterLike, client: SourceClientLike, table: string, source: ExternalSourceLike, shardKey: string, nowMs: number) => Promise<{
1081
1496
  applied: number;
1082
1497
  }>;
1498
+ declare const ftsRowidMapName: (companion: string) => string;
1499
+ interface FtsWriteOptions {
1500
+ guard?: SQL;
1501
+ unmappedRowids?: ReadonlyArray<number>;
1502
+ }
1503
+ declare const ftsCompanionDdl: (companion: string) => SQL[];
1504
+ declare const ftsWriteDocument: (companion: string, id: string, text: string, options?: FtsWriteOptions) => SQL[];
1505
+ declare const ftsPurgeDocument: (companion: string, id: string, options?: FtsWriteOptions) => SQL[];
1506
+ declare const ftsUnmappedPage: (companion: string, limit: number, after?: number) => SQL;
1507
+ declare const groupUnmappedRows: (rows: ReadonlyArray<Record<string, unknown>>) => Map<string, number[]>;
1083
1508
  declare const GEO_DEFAULT_PRECISION = 9;
1084
1509
  interface GeoPoint {
1085
1510
  lat: number;
@@ -1095,6 +1520,20 @@ declare const coveringGeohashes: (center: GeoPoint, radiusMeters: number) => str
1095
1520
  declare const pointInBoundingBox: (point: GeoPoint, box: GeoBoundingBox) => boolean;
1096
1521
  declare const boundingBoxCenter: (box: GeoBoundingBox) => GeoPoint;
1097
1522
  declare const boundingBoxGeohashes: (box: GeoBoundingBox) => string[];
1523
+ declare class GlobalPollTick {
1524
+ private readonly changedTables;
1525
+ private readonly reads;
1526
+ private resync;
1527
+ private skippedCount;
1528
+ constructor(changedTables?: Set<string>);
1529
+ get readCount(): number;
1530
+ get resyncRequested(): boolean;
1531
+ get skipped(): number;
1532
+ requestResync(): void;
1533
+ rows(key: string | undefined, load: () => Promise<ShapeRow[]>): Promise<ShapeRow[]>;
1534
+ shouldRead(table: string): boolean;
1535
+ }
1536
+ declare const isInternalTableName: (name: string) => boolean;
1098
1537
  declare const ADMIN_FUNCTION_PREFIX = "__lunora_admin__:";
1099
1538
  declare const RELATION_FUNCTION_PREFIX = "__lunora_relation__:";
1100
1539
  declare const FLAGS_FUNCTION_PREFIX = "__lunora_flags__:";
@@ -1102,23 +1541,29 @@ declare const ADMIN_FUNCTIONS: {
1102
1541
  readonly applyCdc: "__lunora_admin__:applyCdc";
1103
1542
  readonly aiAvailable: "__lunora_admin__:aiAvailable";
1104
1543
  readonly aiChartConfig: "__lunora_admin__:aiChartConfig";
1544
+ readonly aiCronExpression: "__lunora_admin__:aiCronExpression";
1105
1545
  readonly aiGenerateSql: "__lunora_admin__:aiGenerateSql";
1546
+ readonly aiNameQuery: "__lunora_admin__:aiNameQuery";
1106
1547
  readonly aiTableFilter: "__lunora_admin__:aiTableFilter";
1107
1548
  readonly assignIssue: "__lunora_admin__:assignIssue";
1549
+ readonly backfillSearch: "__lunora_admin__:backfillSearch";
1550
+ readonly backfillVectors: "__lunora_admin__:backfillVectors";
1108
1551
  readonly backRelationCounts: "__lunora_admin__:backRelationCounts";
1109
1552
  readonly cdcSync: "__lunora_admin__:cdcSync";
1110
1553
  readonly clearCapturedMail: "__lunora_admin__:clearCapturedMail";
1111
1554
  readonly clearQueueMessages: "__lunora_admin__:clearQueueMessages";
1112
1555
  readonly clearTable: "__lunora_admin__:clearTable";
1556
+ readonly createAdminToken: "__lunora_admin__:createAdminToken";
1113
1557
  readonly createWorkflowInstance: "__lunora_admin__:createWorkflowInstance";
1114
1558
  readonly deleteRows: "__lunora_admin__:deleteRows";
1115
1559
  readonly describeTable: "__lunora_admin__:describeTable";
1116
1560
  readonly describeTables: "__lunora_admin__:describeTables";
1561
+ readonly dropOutboxEntry: "__lunora_admin__:dropOutboxEntry";
1117
1562
  readonly explainIssue: "__lunora_admin__:explainIssue";
1118
1563
  readonly exportShard: "__lunora_admin__:exportShard";
1119
1564
  readonly facetColumn: "__lunora_admin__:facetColumn";
1565
+ readonly findRelated: "__lunora_admin__:findRelated";
1120
1566
  readonly getAdvisories: "__lunora_admin__:getAdvisories";
1121
- readonly getAdvisorProcedures: "__lunora_admin__:getAdvisorProcedures";
1122
1567
  readonly getAuditLog: "__lunora_admin__:getAuditLog";
1123
1568
  readonly getAuthMetrics: "__lunora_admin__:getAuthMetrics";
1124
1569
  readonly getCapturedMail: "__lunora_admin__:getCapturedMail";
@@ -1127,6 +1572,7 @@ declare const ADMIN_FUNCTIONS: {
1127
1572
  readonly getIssues: "__lunora_admin__:getIssues";
1128
1573
  readonly getMetricHistory: "__lunora_admin__:getMetricHistory";
1129
1574
  readonly getMetricSeries: "__lunora_admin__:getMetricSeries";
1575
+ readonly getScheduleOutbox: "__lunora_admin__:getScheduleOutbox";
1130
1576
  readonly listSubscriptions: "__lunora_admin__:listSubscriptions";
1131
1577
  readonly listTableIndexes: "__lunora_admin__:listTableIndexes";
1132
1578
  readonly listTablesIndexes: "__lunora_admin__:listTablesIndexes";
@@ -1142,23 +1588,30 @@ declare const ADMIN_FUNCTIONS: {
1142
1588
  readonly getWorkflowInstanceStatus: "__lunora_admin__:getWorkflowInstanceStatus";
1143
1589
  readonly ignoreIssue: "__lunora_admin__:ignoreIssue";
1144
1590
  readonly importShard: "__lunora_admin__:importShard";
1591
+ readonly listAdminTokens: "__lunora_admin__:listAdminTokens";
1145
1592
  readonly listFlags: "__lunora_admin__:listFlags";
1593
+ readonly listReactors: "__lunora_admin__:listReactors";
1146
1594
  readonly listQueues: "__lunora_admin__:listQueues";
1147
1595
  readonly lintSql: "__lunora_admin__:lintSql";
1148
1596
  readonly listTables: "__lunora_admin__:listTables";
1149
1597
  readonly listWorkflows: "__lunora_admin__:listWorkflows";
1150
1598
  readonly maskPolicies: "__lunora_admin__:maskPolicies";
1151
1599
  readonly migrationStatus: "__lunora_admin__:migrationStatus";
1600
+ readonly patchRows: "__lunora_admin__:patchRows";
1152
1601
  readonly pitrRestore: "__lunora_admin__:pitrRestore";
1153
1602
  readonly rankBefore: "__lunora_admin__:rankBefore";
1154
1603
  readonly rankPage: "__lunora_admin__:rankPage";
1155
1604
  readonly readTablePage: "__lunora_admin__:readTablePage";
1605
+ readonly rebuildCompanions: "__lunora_admin__:rebuildCompanions";
1156
1606
  readonly recordAuthEvent: "__lunora_admin__:recordAuthEvent";
1157
1607
  readonly recordContainerEvent: "__lunora_admin__:recordContainerEvent";
1158
1608
  readonly recordMail: "__lunora_admin__:recordMail";
1159
1609
  readonly recordQueueMessage: "__lunora_admin__:recordQueueMessage";
1610
+ readonly releaseShardRegistration: "__lunora_admin__:releaseShardRegistration";
1160
1611
  readonly replayQueueMessage: "__lunora_admin__:replayQueueMessage";
1612
+ readonly retryOutboxEntry: "__lunora_admin__:retryOutboxEntry";
1161
1613
  readonly resolveIssue: "__lunora_admin__:resolveIssue";
1614
+ readonly revokeAdminToken: "__lunora_admin__:revokeAdminToken";
1162
1615
  readonly rlsPolicies: "__lunora_admin__:rlsPolicies";
1163
1616
  readonly schemaHistory: "__lunora_admin__:schemaHistory";
1164
1617
  readonly schemaVersion: "__lunora_admin__:schemaVersion";
@@ -1167,11 +1620,13 @@ declare const ADMIN_FUNCTIONS: {
1167
1620
  readonly runSql: "__lunora_admin__:runSql";
1168
1621
  readonly sendQueueMessage: "__lunora_admin__:sendQueueMessage";
1169
1622
  readonly sendTestMail: "__lunora_admin__:sendTestMail";
1623
+ readonly sendWorkflowEvent: "__lunora_admin__:sendWorkflowEvent";
1170
1624
  readonly setIssueSeverity: "__lunora_admin__:setIssueSeverity";
1171
1625
  readonly storageOrphans: "__lunora_admin__:storageOrphans";
1172
1626
  readonly storageReferences: "__lunora_admin__:storageReferences";
1173
1627
  readonly storageRules: "__lunora_admin__:storageRules";
1174
1628
  readonly studioFeatures: "__lunora_admin__:studioFeatures";
1629
+ readonly verifyAdminToken: "__lunora_admin__:verifyAdminToken";
1175
1630
  readonly writeRow: "__lunora_admin__:writeRow";
1176
1631
  };
1177
1632
  interface TableInfo {
@@ -1226,8 +1681,12 @@ interface TablesIndexesResult {
1226
1681
  indexesByTable: Record<string, TableIndexInfo[]>;
1227
1682
  }
1228
1683
  interface ColumnMeta {
1684
+ bucket?: string;
1685
+ enumValues?: string[];
1229
1686
  isStorage?: boolean;
1230
1687
  name: string;
1688
+ nullable?: boolean;
1689
+ onDelete?: "cascade" | "restrict" | "set null";
1231
1690
  optional: boolean;
1232
1691
  pk?: boolean;
1233
1692
  ref?: string;
@@ -1279,9 +1738,6 @@ interface AdvisorProcedure {
1279
1738
  visibility: "internal" | "public";
1280
1739
  writesUserTable?: boolean;
1281
1740
  }
1282
- interface AdvisorProceduresResult {
1283
- procedures: AdvisorProcedure[];
1284
- }
1285
1741
  interface RlsPolicyMetadata {
1286
1742
  file: string;
1287
1743
  on: "delete" | "insert" | "read" | "update";
@@ -1324,6 +1780,12 @@ interface StudioFeaturesResult {
1324
1780
  mail: boolean;
1325
1781
  notifications: boolean;
1326
1782
  payments: boolean;
1783
+ platform?: {
1784
+ id: string;
1785
+ name: string;
1786
+ unsupported: string[];
1787
+ };
1788
+ privacy: boolean;
1327
1789
  queues: boolean;
1328
1790
  scheduler: boolean;
1329
1791
  storage: boolean;
@@ -1342,13 +1804,26 @@ interface FlagsResult {
1342
1804
  configured: boolean;
1343
1805
  flags: FlagEvaluation[];
1344
1806
  }
1807
+ interface ReactorMetadata {
1808
+ errors: number;
1809
+ lastError?: string;
1810
+ lastRanAt?: number;
1811
+ path: string;
1812
+ runs: number;
1813
+ state: "active" | "failing" | "idle";
1814
+ suppressed: number;
1815
+ tables?: ReadonlyArray<string>;
1816
+ }
1817
+ interface ReactorsResult {
1818
+ reactors: ReactorMetadata[];
1819
+ }
1345
1820
  interface WorkflowMetadata {
1346
- binding: string;
1347
1821
  className: string;
1348
1822
  exportName: string;
1349
1823
  name: string;
1350
1824
  }
1351
1825
  interface WorkflowsResult {
1826
+ eventTypes?: string[];
1352
1827
  workflows: WorkflowMetadata[];
1353
1828
  }
1354
1829
  interface QueueMetadata {
@@ -1357,11 +1832,12 @@ interface QueueMetadata {
1357
1832
  exportName: string;
1358
1833
  mode: "pull" | "push";
1359
1834
  name: string;
1835
+ topic?: string;
1360
1836
  }
1361
1837
  interface QueuesResult {
1362
1838
  queues: QueueMetadata[];
1363
1839
  }
1364
- type WorkflowInstanceState = "complete" | "errored" | "paused" | "queued" | "running" | "terminated" | "unknown" | "waiting" | "waitingForPause";
1840
+ type WorkflowInstanceState = "complete" | "errored" | "paused" | "queued" | "rollingBack" | "running" | "terminated" | "unknown" | "waiting" | "waitingForPause";
1365
1841
  interface CreateWorkflowInstanceResult {
1366
1842
  id: string;
1367
1843
  status: WorkflowInstanceState;
@@ -1400,12 +1876,15 @@ interface TablePage {
1400
1876
  columns: string[];
1401
1877
  refs?: Record<string, string>;
1402
1878
  rows: Record<string, unknown>[];
1879
+ sqlColumns: string[];
1403
1880
  total?: number;
1404
1881
  }
1405
- type FilterOperator = "contains" | "eq" | "gt" | "gte" | "lt" | "lte" | "ne";
1882
+ type ColumnKinds = Readonly<Record<string, string>>;
1883
+ type FilterOperator = "contains" | "eq" | "gt" | "gte" | "has" | "lt" | "lte" | "ne";
1406
1884
  interface FilterClause {
1407
1885
  column: string;
1408
1886
  operator: FilterOperator;
1887
+ path?: string[];
1409
1888
  value?: unknown;
1410
1889
  }
1411
1890
  interface OrderByClause {
@@ -1413,6 +1892,7 @@ interface OrderByClause {
1413
1892
  direction: SortDirection;
1414
1893
  }
1415
1894
  interface ReadTablePageOptions {
1895
+ columnKinds?: ColumnKinds;
1416
1896
  filters?: FilterClause[];
1417
1897
  limit?: number;
1418
1898
  offset?: number;
@@ -1423,6 +1903,8 @@ interface ReadTablePageOptions {
1423
1903
  table: string;
1424
1904
  }
1425
1905
  interface SelectMatchingIdsOptions {
1906
+ after?: string;
1907
+ columnKinds?: ColumnKinds;
1426
1908
  filters?: FilterClause[];
1427
1909
  limit?: number;
1428
1910
  search?: string;
@@ -1430,6 +1912,7 @@ interface SelectMatchingIdsOptions {
1430
1912
  }
1431
1913
  interface FacetColumnOptions {
1432
1914
  column: string;
1915
+ columnKinds?: ColumnKinds;
1433
1916
  filters?: FilterClause[];
1434
1917
  limit?: number;
1435
1918
  search?: string;
@@ -1445,6 +1928,7 @@ interface FacetColumnResult {
1445
1928
  }
1446
1929
  declare const MAX_PAGE_SIZE = 500;
1447
1930
  declare const listTables: (sql: SqlExec) => TableInfo[];
1931
+ declare const isVacuousFilterClause: (clause: FilterClause) => boolean;
1448
1932
  declare const readTablePage: (sql: SqlExec, options: ReadTablePageOptions) => TablePage;
1449
1933
  declare const selectMatchingIds: (sql: SqlExec, options: SelectMatchingIdsOptions) => {
1450
1934
  hasMore: boolean;
@@ -1463,6 +1947,7 @@ interface StorageReferenceResult {
1463
1947
  declare const findStorageReferences: (sql: SqlExec, storageColumns: Record<string, string[]>, keys: string[]) => StorageReferenceResult;
1464
1948
  interface SocketAttachmentLike {
1465
1949
  admin?: boolean;
1950
+ authenticated?: boolean;
1466
1951
  subs?: Record<string, SubscriptionInfo>;
1467
1952
  }
1468
1953
  declare const summarizeSubscriptions: (attachments: SocketAttachmentLike[]) => SubscriptionsResult;
@@ -1479,18 +1964,29 @@ interface FanoutPathCounters {
1479
1964
  socketsIterated: number;
1480
1965
  totalMs: number;
1481
1966
  }
1967
+ interface ShapeProbeCounters {
1968
+ run: number;
1969
+ served: number;
1970
+ }
1971
+ interface GlobalPollCounters {
1972
+ drains: number;
1973
+ pairsSkipped: number;
1974
+ }
1482
1975
  interface FanoutMetricsResult {
1976
+ globalPoll: GlobalPollCounters;
1483
1977
  maxRelays: number;
1484
1978
  peakSubscribers: number;
1485
1979
  promoted: boolean;
1486
1980
  relayCount: number;
1487
1981
  shapePoke: FanoutPathCounters;
1982
+ shapeProbe: ShapeProbeCounters;
1488
1983
  sinceMs: number;
1489
1984
  topics: FanoutTopicStat[];
1490
1985
  totalConnections: number;
1491
1986
  whisper: FanoutPathCounters;
1492
1987
  }
1493
1988
  interface FanoutAttachmentLike {
1989
+ authenticated?: boolean;
1494
1990
  shapes?: Record<string, {
1495
1991
  name?: string;
1496
1992
  }>;
@@ -1498,6 +1994,10 @@ interface FanoutAttachmentLike {
1498
1994
  }
1499
1995
  declare const DEFAULT_FANOUT_TOPIC_LIMIT = 20;
1500
1996
  declare const createFanoutCounters: () => FanoutPathCounters;
1997
+ declare const createShapeProbeCounters: () => ShapeProbeCounters;
1998
+ declare const createGlobalPollCounters: () => GlobalPollCounters;
1999
+ declare const recordGlobalPollPass: (counters: GlobalPollCounters, drains: number, pairsSkipped: number) => GlobalPollCounters;
2000
+ declare const recordShapeProbePass: (counters: ShapeProbeCounters, run: number, served: number) => ShapeProbeCounters;
1501
2001
  declare const recordFanoutPass: (counters: FanoutPathCounters, iterated: number, delivered: number, ms: number) => FanoutPathCounters;
1502
2002
  declare const summarizeFanoutTopics: (attachments: FanoutAttachmentLike[], limit?: number) => {
1503
2003
  peakSubscribers: number;
@@ -1545,6 +2045,11 @@ declare const clearCapturedMail: (sql: SqlExec) => {
1545
2045
  declare class NotFoundError extends LunoraError {
1546
2046
  constructor(message?: string);
1547
2047
  }
2048
+ declare const operatorFields: (definition: TableDefinitionLike, patch: Record<string, unknown>) => ReadonlySet<string>;
2049
+ declare const resolvePatch: (definition: TableDefinitionLike, patch: Record<string, unknown>, current: Record<string, unknown>) => Record<string, unknown>;
2050
+ declare const patchDependsOnRow: (definition: TableDefinitionLike, patch: Record<string, unknown>) => boolean;
2051
+ declare const assertPatchAllowed: (options: PatchWriteOptions | undefined, previous: Record<string, unknown>, next: Record<string, unknown>) => void;
2052
+ declare const readPatchField: (document: Record<string, unknown>, field: string) => unknown;
1548
2053
  interface PitrStorage {
1549
2054
  getBookmarkForTime?: (time: Date | number) => Promise<string>;
1550
2055
  getCurrentBookmark?: () => Promise<string>;
@@ -1566,7 +2071,22 @@ interface PitrRestoreArgs {
1566
2071
  }
1567
2072
  declare const readBookmark: (storage: PitrStorage, time?: number | string) => Promise<PitrBookmarkResult>;
1568
2073
  declare const armRestore: (storage: PitrStorage, args: PitrRestoreArgs) => Promise<Omit<PitrRestoreResult, "restarted">>;
1569
- declare const normalizeOrderKeys: (orderBy: OrderByInput[] | undefined) => OrderKey[];
2074
+ declare const tiebreakDirectionFor: (keys: ReadonlyArray<{
2075
+ direction?: string;
2076
+ }>) => SortDirection;
2077
+ declare const equalityPinnedFields: (where: undefined | WhereInput) => ReadonlySet<string>;
2078
+ declare const uniqueIndexFields: (indexes: ReadonlyArray<{
2079
+ fields: ReadonlyArray<string>;
2080
+ unique?: boolean;
2081
+ }> | undefined, shape: Record<string, ValidatorLike> | undefined) => ReadonlyArray<ReadonlyArray<string>>;
2082
+ interface OrderKeyConstraints {
2083
+ pinned?: ReadonlySet<string>;
2084
+ uniqueBy?: ReadonlyArray<ReadonlyArray<string>>;
2085
+ }
2086
+ declare const nullsFirstOf: (key: Pick<OrderKey, "direction" | "nulls">) => boolean;
2087
+ declare const nullsOrderSuffix: (nullsFirst: boolean) => string;
2088
+ declare const normalizeOrderKeys: (orderBy: OrderByInput[] | undefined, shape?: Record<string, ValidatorLike>, constraints?: OrderKeyConstraints) => OrderKey[];
2089
+ declare const CURSOR_PREFIX = "~4";
1570
2090
  declare const encodeCursor: (record: Record<string, unknown>, keys: OrderKey[]) => string;
1571
2091
  declare const decodeCursor: (cursor: string) => unknown[];
1572
2092
  declare const buildSeekWhere: (keys: OrderKey[], cursorValues: unknown[]) => WhereInput;
@@ -1626,24 +2146,70 @@ declare const rankKeyFromDocument: (index: RankIndexDefinitionLike, document_: R
1626
2146
  rowId: string;
1627
2147
  sortValues: unknown[];
1628
2148
  };
2149
+ declare const rankPivotConditionSql: (column: string, value: unknown, direction: "asc" | "desc", wantLater: boolean) => SQL | undefined;
1629
2150
  declare const matchesRankStaticWhere: (document: Record<string, unknown>, predicate: Record<string, unknown>) => boolean;
2151
+ declare const REACTOR_STATE_TABLE = "__reactor_state";
2152
+ interface ReactorState {
2153
+ digest: string;
2154
+ lastError?: string;
2155
+ lastRanAt: number;
2156
+ stats: ReactorStats;
2157
+ tables?: ReadonlyArray<string>;
2158
+ }
2159
+ interface ReactorStats {
2160
+ errors: number;
2161
+ runs: number;
2162
+ suppressed: number;
2163
+ }
2164
+ declare const migrateReactorState: (sql: SqlExec) => void;
2165
+ declare const readReactorState: (sql: SqlExec, path: string) => ReactorState | undefined;
2166
+ declare const listReactorStates: (sql: SqlExec) => {
2167
+ path: string;
2168
+ state: ReactorState;
2169
+ }[];
2170
+ type ReactorDispatchResult = "error" | "ran" | "suppressed";
2171
+ declare const writeReactorState: (sql: SqlExec, path: string, outcome: {
2172
+ digest?: string;
2173
+ error?: string;
2174
+ now: number;
2175
+ result: ReactorDispatchResult;
2176
+ tables?: ReadonlyArray<string>;
2177
+ }) => void;
2178
+ declare const reactorNeedsRun: (state: Pick<ReactorState, "tables"> | undefined, changed: ReadonlySet<string>) => boolean;
1630
2179
  interface ReadFootprint {
1631
- onRead: (table: string, idOrScan?: string) => void;
2180
+ onRead: (table: string, idOrScan?: string, exact?: boolean) => void;
1632
2181
  onReadRange: (range: KeyRange) => void;
1633
2182
  ranges: () => Map<string, KeyRange[]> | undefined;
1634
2183
  tables: Set<string>;
1635
2184
  }
1636
2185
  declare const createReadFootprint: () => ReadFootprint;
2186
+ declare const UNVOUCHABLE_DEP = "!unvouchable";
2187
+ declare const markUnvouchableReads: <T extends object>(facade: T, onRead: ReadFootprint["onRead"] | undefined, methods: ReadonlyArray<string>) => T;
2188
+ declare const WHERE_FILTER: unique symbol;
2189
+ type RowPredicate = (document: Record<string, unknown>) => boolean;
2190
+ type WhereFilter = RowPredicate & {
2191
+ readonly [WHERE_FILTER]: WhereInput;
2192
+ };
2193
+ declare const whereFilter: (where: WhereInput, predicate: RowPredicate) => WhereFilter;
2194
+ declare const whereOfFilter: (predicate: RowPredicate) => undefined | WhereInput;
2195
+ declare const isPushableWhere: (where: WhereInput, shape: Readonly<Record<string, ValidatorLike>>, exactText?: boolean) => boolean;
2196
+ declare const RELATED_MAX_DEPTH = 4;
2197
+ declare const RELATED_DEFAULT_LIMIT = 50;
2198
+ declare const RELATED_MAX_LIMIT = 200;
2199
+ declare const RELATED_DEPTH_DECAY = 0.5;
2200
+ declare const deriveRelationEdges: (schema: SchemaLike) => RelationEdge[];
2201
+ type RelationGraphReader = Pick<DatabaseWriterLike, "findMany"> & Pick<Partial<DatabaseWriterLike>, "lookupById">;
2202
+ declare const findRelated: (reader: RelationGraphReader, edges: ReadonlyArray<RelationEdge>, start: RelatedStart, options?: RelatedOptions) => Promise<RelatedPage>;
1637
2203
  declare const DEFAULT_MAX_RELATION_KEYS = 5000;
1638
2204
  interface RelationExistsMarker {
1639
2205
  childWhere: WhereInput;
1640
2206
  negated: boolean;
1641
2207
  parentTable: string;
1642
- relation: RelationDefinitionLike;
2208
+ relation: KeyedRelationDefinitionLike;
1643
2209
  }
1644
2210
  type ExistsPushMode = "always" | "auto";
1645
2211
  interface ResolveRelationPredicatesOptions {
1646
- canPushExists?: (relation: RelationDefinitionLike) => boolean;
2212
+ canPushExists?: (relation: KeyedRelationDefinitionLike) => boolean;
1647
2213
  existsPushMode?: ExistsPushMode;
1648
2214
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
1649
2215
  maxRelationKeys?: number;
@@ -1654,7 +2220,7 @@ interface ResolveRelationPredicatesOptions {
1654
2220
  tableName: string;
1655
2221
  }
1656
2222
  interface ResolveContext {
1657
- canPushExists?: (relation: RelationDefinitionLike) => boolean;
2223
+ canPushExists?: (relation: KeyedRelationDefinitionLike) => boolean;
1658
2224
  existsPushMode: ExistsPushMode;
1659
2225
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
1660
2226
  maxRelationKeys: number;
@@ -1667,15 +2233,30 @@ declare const isRelationPredicate: (value: unknown) => value is Record<string, W
1667
2233
  declare const containsRelationPredicate: (where: WhereInput, schema: ResolveContext["schema"], tableName: string) => boolean;
1668
2234
  declare const assertFlatPredicate: (where: WhereInput | undefined, schema: ResolveContext["schema"], tableName: string, op: string) => void;
1669
2235
  declare const resolveRelationPredicates: (where: WhereInput | undefined, options: ResolveRelationPredicatesOptions) => Promise<WhereInput | undefined>;
2236
+ declare const composeReadPredicate: (definition: TableDefinitionLike, args: QueryArgs, relation: Omit<ResolveRelationPredicatesOptions, "relationBaseWhere">) => Promise<{
2237
+ fetchLimit: number | undefined;
2238
+ limit: number | undefined;
2239
+ orderKeys: OrderKey[];
2240
+ predicate: WhereInput | undefined;
2241
+ }>;
2242
+ declare const findManyPage: (documents: Record<string, unknown>[], read: {
2243
+ endCursor?: null | string;
2244
+ limit: number | undefined;
2245
+ omitContinueCursor?: boolean;
2246
+ orderKeys: OrderKey[];
2247
+ }) => QueryPage;
1670
2248
  declare const assertShapeShardable: (effectiveWhere: WhereInput | undefined, schema: ResolveContext["schema"], table: string) => void;
1671
- declare const relationHooks: (args: Pick<QueryArgs, "relationBaseWhere" | "relationMask">) => Pick<QueryArgs, "relationBaseWhere" | "relationMask">;
2249
+ declare const relationHooks: (args: Pick<QueryArgs, "relationBaseWhere" | "relationMask">) => Pick<QueryArgs, "relationBaseWhere" | "relationMask"> & Pick<ResolveWithOptions, "fanOutBudget">;
1672
2250
  declare const fanOutScalarCounts: (counter: (tableName: string, where?: WhereInput) => Promise<number>, tableName: string, whereField: string, values: unknown[], policyWhere: WhereInput | undefined) => Promise<Map<unknown, number>>;
1673
2251
  declare const distinctValues: (rows: Record<string, unknown>[], field: string) => unknown[];
1674
2252
  declare const resolveWith: (options: ResolveWithOptions) => Promise<void>;
1675
2253
  interface ApplyOnDeleteOptions {
1676
2254
  deletedId: string;
1677
2255
  deletedReference: (references: string) => unknown;
1678
- findHolders: (holderTable: string, field: string, value: unknown) => Promise<Record<string, unknown>[]>;
2256
+ findHolders: (holderTable: string, field: string, value: unknown, page: {
2257
+ limit: number;
2258
+ select?: ReadonlyArray<string>;
2259
+ }) => Promise<Record<string, unknown>[]>;
1679
2260
  onCascade: (holderTable: string, id: string) => Promise<void>;
1680
2261
  onRestrict: (message: string) => never;
1681
2262
  onSetNull: (holderTable: string, id: string, field: string) => Promise<void>;
@@ -1685,7 +2266,15 @@ interface ApplyOnDeleteOptions {
1685
2266
  tableName: string;
1686
2267
  }
1687
2268
  declare const applyOnDelete: (options: ApplyOnDeleteOptions) => Promise<void>;
1688
- declare const runRowValidators: (definition: TableDefinitionLike, document: Record<string, unknown>, tolerateStoredNull?: boolean) => void;
2269
+ interface RowValidatorOptions {
2270
+ only?: ReadonlySet<string>;
2271
+ previous?: () => Readonly<Record<string, unknown>> | undefined;
2272
+ supplied?: Readonly<Record<string, unknown>>;
2273
+ tolerateStoredNull?: boolean;
2274
+ trusted?: boolean;
2275
+ }
2276
+ declare const applyInsertDefaults: (definition: TableDefinitionLike, document: Record<string, unknown>, auth: ServerDefaultContextLike["auth"]) => Record<string, unknown>;
2277
+ declare const runRowValidators: (definition: TableDefinitionLike, document: Record<string, unknown>, options?: RowValidatorOptions) => Record<string, unknown>;
1689
2278
  interface ShapeRowOp {
1690
2279
  key: string;
1691
2280
  op: "delete" | "insert" | "update";
@@ -1693,6 +2282,8 @@ interface ShapeRowOp {
1693
2282
  value?: Record<string, unknown>;
1694
2283
  }
1695
2284
  interface ShapePokePart {
2285
+ baseCheckpoint?: number;
2286
+ reset?: boolean;
1696
2287
  rowsPatch: ShapeRowOp[];
1697
2288
  shapeId: string;
1698
2289
  }
@@ -1727,15 +2318,18 @@ declare const clampPromotionThresholds: (tUp: number, tDownRaw: number) => Promo
1727
2318
  declare const relayCountFor: (subscribers: number, perRelayCapacity: number, maxRelays: number) => number;
1728
2319
  interface RelayAttach {
1729
2320
  relayIndex: number;
2321
+ seq?: number;
1730
2322
  type: "relay_attach";
1731
2323
  }
1732
2324
  interface RelayDetach {
1733
2325
  relayIndex: number;
2326
+ seq?: number;
1734
2327
  type: "relay_detach";
1735
2328
  }
1736
2329
  interface RelayFrame {
1737
2330
  cursor?: number;
1738
2331
  epoch?: string;
2332
+ exceptConnectionId?: string;
1739
2333
  frame: string;
1740
2334
  originRelay?: number;
1741
2335
  topic: string;
@@ -1753,6 +2347,12 @@ interface RelayShapeSubscribe {
1753
2347
  type: "relay_shape_subscribe";
1754
2348
  userId?: string;
1755
2349
  }
2350
+ interface RelayShapeUnsubscribe {
2351
+ connectionId: string;
2352
+ relayIndex: number;
2353
+ subId?: string;
2354
+ type: "relay_shape_unsubscribe";
2355
+ }
1756
2356
  interface RelayShapeSeed {
1757
2357
  cursor?: number;
1758
2358
  epoch?: string;
@@ -1772,44 +2372,88 @@ interface RelayShapePoke {
1772
2372
  targetConnectionId?: string;
1773
2373
  type: "relay_shape_poke";
1774
2374
  }
1775
- type OwnerRelayFrame = RelayAttach | RelayDetach | RelayFrame | RelayShapePoke | RelayShapeSubscribe;
1776
- declare const DEFAULT_MAX_RELAYS = 8;
1777
- interface RelayStub {
1778
- fetch: (url: string, init?: RequestInit) => Promise<Response>;
2375
+ interface RelayRoomEvent {
2376
+ attachment: Pick<SocketAttachment, "connectionId" | "context" | "expiresAt" | "identity" | "ip" | "revalidateAt" | "userId">;
2377
+ connectionId: string;
2378
+ data?: unknown;
2379
+ kind: "join" | "leave" | "message";
2380
+ relayIndex: number;
2381
+ topic: string;
2382
+ type: "relay_room_event";
2383
+ }
2384
+ interface RelayRoomVerdict {
2385
+ admitted: boolean;
2386
+ }
2387
+ interface LiveSocketControlCall {
2388
+ action: unknown;
2389
+ adminReauth?: true;
2390
+ callerId: string;
2391
+ connectionId: string;
2392
+ identity?: Record<string, unknown>;
2393
+ identityExpiry?: number;
2394
+ key: string;
2395
+ seq?: number;
2396
+ subscriptionId: string;
2397
+ }
2398
+ interface RelayLiveControl {
2399
+ control: LiveSocketControlCall;
2400
+ type: "relay_live_control";
1779
2401
  }
1780
- interface RelayNamespaceLike {
1781
- get: (id: unknown) => RelayStub;
1782
- getByName?: (name: string) => RelayStub;
1783
- idFromName: (name: string) => unknown;
2402
+ interface RelayLiveFrame {
2403
+ frame: string;
2404
+ key: string;
2405
+ topic: string;
2406
+ type: "relay_live_frame";
2407
+ }
2408
+ type OwnerRelayFrame = RelayAttach | RelayDetach | RelayFrame | RelayLiveControl | RelayLiveFrame | RelayRoomEvent | RelayShapePoke | RelayShapeSubscribe | RelayShapeUnsubscribe;
2409
+ declare const RELAY_SIGNATURE_HEADER = "x-lunora-relay-sig";
2410
+ declare const siblingSecretOf: (env: unknown) => string | undefined;
2411
+ declare const signSiblingBody: (secret: string, body: string) => Promise<string>;
2412
+ declare const verifySiblingBody: (env: unknown, supplied: null | string, raw: string) => Promise<boolean>;
2413
+ interface SiblingStub {
2414
+ fetch: (url: string, init?: RequestInit) => Promise<Response>;
1784
2415
  }
2416
+ declare const stubByName: (value: unknown, name: string, jurisdiction?: string) => SiblingStub | undefined;
2417
+ declare const DEFAULT_MAX_RELAYS = 8;
1785
2418
  interface RelayHost {
1786
2419
  buildShapeDiff: (resolved: ResolvedShape, fromCursor: number, toCursor: number) => ShapeRowOp[];
1787
2420
  computeOpLogShapeSeed: (shape: ShapeSubscriptionQuery, resolved: ResolvedShape) => {
1788
2421
  baseCheckpoint: number | undefined;
1789
2422
  cursor: number;
1790
2423
  epoch: string | undefined;
2424
+ reset: boolean;
1791
2425
  rowsPatch: ShapeRowOp[];
1792
2426
  };
1793
2427
  currentCdcEpoch: () => string | undefined;
2428
+ deliverLiveLocal: (topic: string, key: string, frame: string) => number;
1794
2429
  deliverWhisperLocal: (topic: string, frame: string, exclude: undefined | ShardSocketLike) => number;
1795
2430
  doName: () => string | undefined;
2431
+ dropIfLapsed: (ws: ShardSocketLike) => boolean;
1796
2432
  env: () => unknown;
1797
2433
  getWebSockets: () => ShardSocketLike[];
2434
+ liveControl: (control: LiveSocketControlCall) => Promise<Response>;
1798
2435
  maskMetadata: () => MaskPoliciesResult;
1799
2436
  nextPokeId: () => string;
1800
2437
  readAttachment: (ws: ShardSocketLike) => SocketAttachment;
1801
2438
  recordShapePokeFanout: (iterated: number, delivered: number, elapsedMs: number) => void;
2439
+ relayRoomEvent: (event: RelayRoomEvent) => Promise<RelayRoomVerdict>;
1802
2440
  resolveShape: (name: string, args: Record<string, unknown>, identity?: SubscriptionIdentity) => ResolvedShape | undefined;
1803
2441
  rlsMetadata: () => RlsPoliciesResult;
1804
2442
  shardBinding: () => string | undefined;
2443
+ shardJurisdiction: () => string | undefined;
1805
2444
  sql: () => SqlExec;
1806
2445
  }
2446
+ interface RelayPokeDelivery {
2447
+ delivered: number;
2448
+ matched: number;
2449
+ }
1807
2450
  declare abstract class RelayLink {
1808
2451
  protected readonly host: RelayHost;
1809
2452
  protected readonly roleId: {
1810
2453
  ownerKey: string;
1811
2454
  relayIndex?: number;
1812
2455
  };
2456
+ private lastSequence;
1813
2457
  protected constructor(host: RelayHost, roleId: {
1814
2458
  ownerKey: string;
1815
2459
  relayIndex?: number;
@@ -1817,81 +2461,188 @@ declare abstract class RelayLink {
1817
2461
  handleControl(request: Request): Promise<Response>;
1818
2462
  maxRelays(): number;
1819
2463
  protected canAddressSiblings(): boolean;
1820
- protected relayNamespace(): RelayNamespaceLike | undefined;
2464
+ protected isAdmitted(ws: ShardSocketLike): boolean;
2465
+ protected siblingStub(targetName: string): SiblingStub | undefined;
2466
+ protected bindingName(): string | undefined;
2467
+ protected nextRelaySeq(): number;
1821
2468
  protected postRelayMessage(targetName: string, message: OwnerRelayFrame): Promise<void>;
1822
2469
  protected requestRelayMessage(targetName: string, message: OwnerRelayFrame): Promise<Response | undefined>;
1823
- abstract forwardWhisper(topic: string, frame: string): Promise<void>;
2470
+ abstract forwardWhisper(topic: string, frame: string, exceptConnectionId?: string): Promise<void>;
1824
2471
  abstract onFlush(changed: Set<string>, frameCursor: number): Promise<void>;
1825
2472
  abstract seedRelayShape(ws: ShardSocketLike, subId: string, shape: ShapeSubscriptionQuery, identity: SubscriptionIdentity): Promise<"ok" | undefined | {
1826
2473
  code: string;
1827
2474
  message: string;
1828
2475
  }>;
1829
- abstract announce(): Promise<void>;
2476
+ abstract announce(): Promise<boolean>;
1830
2477
  abstract announceDrain(closing: ShardSocketLike): Promise<void>;
2478
+ abstract releaseRelayShapes(ws: ShardSocketLike, subId?: string): Promise<void>;
1831
2479
  abstract relayCount(): number;
1832
2480
  abstract isShapeRelayUniform(name: string, args: Record<string, unknown>): boolean;
1833
- protected abstract onAttach(index: number): void;
1834
- protected abstract onDetach(index: number): void;
2481
+ abstract minShapeCursor(): number | undefined;
2482
+ protected abstract onAttach(index: number, seq: number | undefined): boolean;
2483
+ protected abstract onDetach(index: number, seq: number | undefined): boolean;
2484
+ protected abstract onLiveControl(control: LiveSocketControlCall): Promise<Response>;
1835
2485
  protected abstract onWhisperFrame(message: RelayFrame): Promise<void>;
2486
+ protected abstract refusesAsIdle(): boolean;
1836
2487
  protected abstract onShapeSubscribe(message: RelayShapeSubscribe): RelayShapeSeed;
1837
- protected abstract onShapePoke(poke: RelayShapePoke): number;
2488
+ protected abstract onShapeUnsubscribe(message: RelayShapeUnsubscribe): void;
2489
+ protected abstract onShapePoke(poke: RelayShapePoke): RelayPokeDelivery;
1838
2490
  }
1839
2491
  declare class OwnerRelay extends RelayLink {
1840
2492
  private readonly shapeUniformCache;
1841
2493
  private relaySetCache;
1842
- private readonly relayShapeRegistry;
1843
- private readonly relayShapeProxies;
2494
+ private liveGrantRelayCache;
2495
+ private relayTablesReady;
2496
+ private readonly relaySeqMarks;
2497
+ private readonly pendingSubscribeRelays;
2498
+ private registryCache;
2499
+ private recorded;
1844
2500
  private promotionState;
1845
2501
  constructor(host: RelayHost, ownerKey: string);
1846
- forwardWhisper(topic: string, frame: string): Promise<void>;
2502
+ forwardWhisper(topic: string, frame: string, exceptConnectionId?: string): Promise<void>;
2503
+ forwardLiveControl(call: LiveSocketControlCall): Promise<Response | undefined>;
2504
+ forwardLiveFrame(topic: string, key: string, frame: string): Promise<void>;
1847
2505
  onFlush(changed: Set<string>, frameCursor: number): Promise<void>;
1848
2506
  seedRelayShape(): Promise<"ok" | undefined | {
1849
2507
  code: string;
1850
2508
  message: string;
1851
2509
  }>;
1852
- announce(): Promise<void>;
2510
+ announce(): Promise<boolean>;
1853
2511
  announceDrain(): Promise<void>;
2512
+ releaseRelayShapes(): Promise<void>;
1854
2513
  relayCount(): number;
2514
+ minShapeCursor(): number | undefined;
1855
2515
  isShapeRelayUniform(name: string, args: Record<string, unknown>): boolean;
1856
- protected onAttach(index: number): void;
1857
- protected onDetach(index: number): void;
2516
+ protected onShapeUnsubscribe(message: RelayShapeUnsubscribe): void;
2517
+ protected onAttach(index: number, seq: number | undefined): boolean;
2518
+ protected onDetach(index: number, seq: number | undefined): boolean;
2519
+ protected refusesAsIdle(): boolean;
2520
+ protected onLiveControl(control: LiveSocketControlCall): Promise<Response>;
1858
2521
  protected onWhisperFrame(message: RelayFrame): Promise<void>;
1859
2522
  protected onShapeSubscribe(message: RelayShapeSubscribe): RelayShapeSeed;
1860
- protected onShapePoke(): number;
2523
+ protected onShapePoke(): RelayPokeDelivery;
2524
+ private relaySeqMark;
2525
+ private recordRelaySeq;
2526
+ private acceptRelaySeq;
1861
2527
  private buildShapePoke;
1862
2528
  private multicastShapePokes;
2529
+ private multicastToRelays;
1863
2530
  private proxyShapePokes;
2531
+ private proxyToRelay;
1864
2532
  private buildShapeSeedFrames;
1865
- private ensureRelayTable;
2533
+ private ensureRelayTables;
2534
+ protected bindingName(): string | undefined;
2535
+ private relayShapes;
2536
+ private rewindShapeCursor;
1866
2537
  private ownerRelaySet;
2538
+ private liveGrantRelaySet;
2539
+ private recordLiveGrantRelay;
1867
2540
  private addRelayToSet;
2541
+ private forwardToRelay;
2542
+ private requestDroppingIdle;
1868
2543
  private removeRelayFromSet;
1869
2544
  private probeShapeRelayUniform;
1870
2545
  private tableHasAnyMask;
2546
+ private liveControlAnswer;
1871
2547
  }
1872
2548
  declare class RelayMember extends RelayLink {
1873
2549
  private relayAnnounced;
1874
- private readonly shapeRelayMemos;
2550
+ private readonly liveControlSeqs;
2551
+ private pendingAnnounce;
2552
+ private announceGeneration;
2553
+ private pendingDetach;
2554
+ private relayMemoCache;
2555
+ private readonly shapeControl;
1875
2556
  constructor(host: RelayHost, ownerKey: string, relayIndex: number);
1876
2557
  forwardWhisper(topic: string, frame: string): Promise<void>;
2558
+ forwardRoomEvent(event: Omit<RelayRoomEvent, "relayIndex" | "type">): Promise<boolean>;
1877
2559
  onFlush(): Promise<void>;
1878
2560
  seedRelayShape(ws: ShardSocketLike, subId: string, shape: ShapeSubscriptionQuery, identity: SubscriptionIdentity): Promise<"ok" | {
1879
2561
  code: string;
1880
2562
  message: string;
1881
2563
  }>;
1882
- announce(): Promise<void>;
2564
+ announce(): Promise<boolean>;
1883
2565
  announceDrain(closing: ShardSocketLike): Promise<void>;
2566
+ releaseRelayShapes(ws: ShardSocketLike, subId?: string): Promise<void>;
1884
2567
  relayCount(): number;
1885
2568
  isShapeRelayUniform(): boolean;
1886
- protected onAttach(): void;
1887
- protected onDetach(): void;
2569
+ minShapeCursor(): number | undefined;
2570
+ protected onAttach(): boolean;
2571
+ protected refusesAsIdle(): boolean;
2572
+ protected onDetach(): boolean;
2573
+ protected onLiveControl(control: LiveSocketControlCall): Promise<Response>;
1888
2574
  protected onWhisperFrame(): Promise<void>;
1889
2575
  protected onShapeSubscribe(): RelayShapeSeed;
1890
- protected onShapePoke(poke: RelayShapePoke): number;
2576
+ protected onShapeUnsubscribe(): void;
2577
+ protected onShapePoke(poke: RelayShapePoke): RelayPokeDelivery;
2578
+ private queueShapeControl;
2579
+ private relayMemos;
2580
+ private connectionMemos;
1891
2581
  private recordRelayShapeMemo;
2582
+ private forgetRelayShapeMemos;
1892
2583
  private deliverShapePoke;
2584
+ private pokeSocketShapes;
1893
2585
  }
1894
2586
  declare const createRelayLink: (host: RelayHost) => OwnerRelay | RelayMember | undefined;
2587
+ declare const REGION_HINTS: readonly ["wnam", "enam", "sam", "weur", "eeur", "apac", "apac-ne", "apac-se", "oc", "afr", "me"];
2588
+ type RegionHint = (typeof REGION_HINTS)[number];
2589
+ type ReplicaReadiness = "fresh" | "stale" | "unavailable";
2590
+ interface ShardSiblingHost {
2591
+ doName: () => string | undefined;
2592
+ env: () => unknown;
2593
+ shardBinding: () => string | undefined;
2594
+ shardJurisdiction: () => string | undefined;
2595
+ sql: () => SqlExec;
2596
+ }
2597
+ interface ReplicaOwnerHost extends ShardSiblingHost {
2598
+ exportRows: () => Promise<ExportRow[]>;
2599
+ ownerCursor: () => number | undefined;
2600
+ ownerEpoch: () => string | undefined;
2601
+ ownerFloor: () => number | undefined;
2602
+ readChanges: (sinceSeq: number, limit: number) => {
2603
+ changes: CdcChange[];
2604
+ cursor: number;
2605
+ };
2606
+ rowCount: () => number;
2607
+ }
2608
+ interface ReplicaFollowerHost extends ShardSiblingHost {
2609
+ applyChanges: (changes: ReadonlyArray<CdcChange>) => Promise<number>;
2610
+ exportRows: () => Promise<ExportRow[]>;
2611
+ importRows: (rows: ReadonlyArray<ExportRow>) => Promise<{
2612
+ errors: ReadonlyArray<unknown>;
2613
+ }>;
2614
+ reportError?: (scope: string, error: unknown) => void;
2615
+ transactionLimits: () => Partial<TransactionLimits>;
2616
+ }
2617
+ declare const handleReplicaControl: (host: ReplicaOwnerHost, request: Request) => Promise<Response>;
2618
+ declare class ShardReplica {
2619
+ private readonly host;
2620
+ readonly ownerKey: string;
2621
+ readonly region: RegionHint;
2622
+ private divergent;
2623
+ private inFlight;
2624
+ constructor(host: ReplicaFollowerHost, ownerKey: string, region: RegionHint);
2625
+ ensureFresh(minSeq?: number): Promise<ReplicaReadiness>;
2626
+ appliedSeq(): number;
2627
+ isDivergent(): boolean;
2628
+ private advance;
2629
+ private isCaughtUp;
2630
+ private catchUp;
2631
+ private verdict;
2632
+ private recover;
2633
+ private whenOwnerUnreachable;
2634
+ private applyPage;
2635
+ private applyAtomically;
2636
+ private fetchSnapshot;
2637
+ private resnapshot;
2638
+ private overWriteBudget;
2639
+ private bootstrap;
2640
+ private isFreshEnough;
2641
+ private pull;
2642
+ private request;
2643
+ }
2644
+ declare const createReplicaLink: (host: ReplicaFollowerHost) => ShardReplica | undefined;
2645
+ declare const gateReplicaDispatch: (replica: ShardReplica, request: Request, functionPath: string) => Promise<Response | undefined>;
1895
2646
  declare const REPROJECTION_MIGRATION_PREFIX = "__lunora_reproject__";
1896
2647
  declare const reprojectionMigrationId: (table: string) => string;
1897
2648
  declare const reprojectableFields: (definition: TableDefinitionLike) => string[];
@@ -1913,8 +2664,7 @@ interface GuardableSchema {
1913
2664
  }>;
1914
2665
  }
1915
2666
  type TableOfId = (id: string, expectedTable?: string) => Promise<string | undefined> | string | undefined;
1916
- type TablesOfIds = (ids: ReadonlyArray<string>, expectedTable?: string) => Promise<ReadonlyMap<string, string>> | ReadonlyMap<string, string>;
1917
- declare const guardWriter: <W>(raw: W, schema: GuardableSchema, tableOfId: TableOfId, tablesOfIds?: TablesOfIds) => W;
2667
+ declare const guardWriter: <W>(raw: W, schema: GuardableSchema, tableOfId: TableOfId, relationEdges?: ReadonlyArray<RelationEdge>) => W;
1918
2668
  declare const SCHEMA_HISTORY_MAX_VERSIONS = 50;
1919
2669
  interface SchemaVersionRow {
1920
2670
  appliedAt: number;
@@ -1925,8 +2675,24 @@ interface SchemaVersionRow {
1925
2675
  declare const recordSchemaVersion: (sql: SqlExec, hash: string, snapshotJson: string, now?: number) => boolean;
1926
2676
  declare const readSchemaHistory: (sql: SqlExec) => SchemaVersionRow[];
1927
2677
  declare const readSchemaVersion: (sql: SqlExec, hash: string) => SchemaVersionRow | undefined;
2678
+ declare const readDeployInfo: (rawEnv: unknown) => DeployInfo;
1928
2679
  declare const isDevEnvironment: (rawEnv: unknown) => boolean;
1929
2680
  declare const buildSettings: (rawEnv: unknown) => SettingsResult;
2681
+ declare class ShapeDiffCache {
2682
+ private readonly keyScans;
2683
+ private readonly memberProbes;
2684
+ private run;
2685
+ private served;
2686
+ get probesRun(): number;
2687
+ get probesServed(): number;
2688
+ changedKeys(rangeKey: string, load: () => CdcChangeKey[]): ReadonlyArray<CdcChangeKey>;
2689
+ members(resolved: ResolvedShape, rangeKey: string, load: () => Map<string, Record<string, unknown>>): ReadonlyMap<string, Record<string, unknown>>;
2690
+ private getOrLoad;
2691
+ }
2692
+ declare const createShapeDiffCache: () => ShapeDiffCache;
2693
+ declare const globalShapeReadKey: (resolved: ResolvedShape, identity: SubscriptionIdentity) => string | undefined;
2694
+ type ReadShapeCdcKeys = (sql: SqlExec, table: string, sinceSeq: number, upTo: number) => CdcChangeKey[];
2695
+ declare const buildShapeDiff: (sql: SqlExec, resolved: ResolvedShape, sinceSeq: number, upTo: number, cache: ShapeDiffCache, readKeys?: ReadShapeCdcKeys) => ShapeRowOp[];
1930
2696
  interface ShardRunnerOptions {
1931
2697
  handlers?: {
1932
2698
  handleAlarm?: () => Promise<void>;
@@ -1942,7 +2708,7 @@ declare class ShardRunner {
1942
2708
  socketFor(raw: unknown): ShardSocketLike;
1943
2709
  sockets(tag?: string): SocketHandle[];
1944
2710
  background(work: Promise<unknown>): boolean;
1945
- runInTransaction<T>(work: () => Promise<T>): Promise<T>;
2711
+ runInTransaction<T>(work: () => Promise<T>, onCommitted?: () => void): Promise<T>;
1946
2712
  handleFetch(request: Request): Promise<Response>;
1947
2713
  handleAlarm(): Promise<void>;
1948
2714
  }
@@ -1968,6 +2734,11 @@ interface SqlDiagnostic {
1968
2734
  source: "gate" | "plan" | "syntax";
1969
2735
  }
1970
2736
  declare const lintReadonlySql: (sql: SqlExec, query: string) => SqlLintResult;
2737
+ declare const BIGINT_KEY_DIGITS = 39;
2738
+ declare const bigintSqlKey: (value: bigint) => string;
2739
+ declare const decodeBigintSqlKey: (raw: string) => bigint | undefined;
2740
+ declare const float64SqlKey: (value: number) => string;
2741
+ declare const decodeFloat64SqlKey: (raw: string) => number | undefined;
1971
2742
  declare const subscriptionListDeltas: (previousJson: string, nextResult: unknown, table: string, frames?: string[]) => MutationDelta[] | undefined;
1972
2743
  interface FrameSink {
1973
2744
  send: (data: string) => void;
@@ -1976,7 +2747,18 @@ interface DrainableSink {
1976
2747
  readonly bufferedAmount?: unknown;
1977
2748
  }
1978
2749
  declare const trySendFrame: (ws: FrameSink, frame: string) => boolean;
1979
- declare const sendDeltaFrames: (ws: FrameSink, subId: string, deltaFrames: ReadonlyArray<string>, cursorSuffix: string, lastMutationId?: number) => boolean;
2750
+ interface SubscriptionFrameInput {
2751
+ cursorSuffix: string;
2752
+ diffKey?: object;
2753
+ lastMutationId?: number;
2754
+ nextResult: unknown;
2755
+ pageDeltas?: boolean;
2756
+ previousJson?: string;
2757
+ snapshotJson: string;
2758
+ subId: string;
2759
+ table: string;
2760
+ }
2761
+ declare const subscriptionFrames: (input: SubscriptionFrameInput) => string[];
1980
2762
  declare const awaitWsDrain: (ws: DrainableSink) => Promise<void>;
1981
2763
  interface SubscriptionReadFootprint {
1982
2764
  ranges?: Map<string, KeyRange[]>;
@@ -2004,13 +2786,32 @@ declare const selectExpiredIds: (sql: SqlExec, spec: TtlSweepSpec, now: number,
2004
2786
  hasMore: boolean;
2005
2787
  ids: string[];
2006
2788
  };
2007
- type FieldRefSql = (field: string) => SQL;
2008
- type SerializeValue = (value: unknown) => unknown;
2009
- interface WhereSqlStrategy {
2010
- fieldRef: FieldRefSql;
2011
- likeContains?: (reference: SQL, term: SQL) => SQL;
2012
- relationExists?: (request: unknown) => SQL;
2013
- serialize: SerializeValue;
2789
+ declare const isTtlExpired: (sql: SqlExec, spec: TtlSweepSpec, id: string, now: number) => boolean;
2790
+ declare const nextTtlExpiry: (sql: SqlExec, spec: TtlSweepSpec) => number | undefined;
2791
+ declare const VECTOR_BACKFILL_MAX_PAGES = 20;
2792
+ interface VectorBackfillTarget {
2793
+ profile: string;
2794
+ table: string;
2795
+ }
2796
+ interface VectorBackfillProgress {
2797
+ done: boolean;
2798
+ error?: string;
2799
+ failed: number;
2800
+ failedIds: string[];
2801
+ pages: number;
2802
+ rows: number;
2014
2803
  }
2015
- declare const compileWhereSql: (where: WhereInput | undefined, strategy: WhereSqlStrategy) => SQL | undefined;
2016
- export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, AGGREGATE_SQL_FUNCTION, AGG_COUNT, AGG_KEY, AGG_VALUE, AUDIT_LOG_TABLE, type AdvisorProcedure, type AdvisorProceduresResult, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type AppendAuditEntry, type ApplyOnDeleteOptions$1 as ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, type BroadcastDelta, CDC_LOG_TABLE, CDC_META_TABLE, CLIENT_WATERMARK_TABLE, type CacheEntry, type CapturedMailRow, type CdcChange, type ChangedKeys, type Clock, type ColumnMeta, type ColumnMetaLike, type CompanionSync, type CompanionSyncDeps, ConflictError, type ConflictKind, type CountArgs, CountRlsUnsupportedError, type CreateWorkflowInstanceResult, type CrossShardReadArgs, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_FANOUT_TOPIC_LIMIT, DEFAULT_MAX_RELATION_KEYS, DEFAULT_MAX_RELAYS, DEFAULT_PROMOTION_THRESHOLDS, DEFAULT_TRANSACTION_LIMITS, DOC_COLUMN, 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, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FanoutMetricsResult, type FanoutPathCounters, type FanoutTopicStat, type FieldOperators, type FilterClause, type FilterOperator, type FlagEvaluation, type FlagsResult, type FunctionCallStat, type FunctionScanAttribution, type FunctionStatsResult, GEO_DEFAULT_PRECISION, GLOBAL_SHAPE_SNAPSHOT_TABLE, type GeoBoundingBox, type GeoFilterBuilderLike, type GeoIndexDefinitionLike, type GeoPoint, type GeoScoredDocument, type GroupByEntry, type GroupByOptions, type GuardableSchema$1 as GuardableSchema, IDEMPOTENCY_TABLE, type IdGenerator, type IdempotentRecord, type ImportError, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IncrementalMaterializeResult, type IndexDefinitionLike, type IndexKeyEntry, type IndexRangeBuilderLike, type KeyRange, type LifecycleDispatchInfo, type LifecycleEvent, MAIL_RETENTION, MAIL_TABLE, MAX_PAGE_SIZE, MAX_SQL_ROWS, type MaskColumnMetadata, type MaskPoliciesResult, type MaterializeResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type OnDeleteActionLike, type OrderByClause, type OrderByInput, type OrderKey, OwnerRelay, type OwnerRelayFrame, type PaginationOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type PokeFrameMeta, type PromotionState, type PromotionThresholds, QUEUE_TABLE, type QueryArgs, type QueryPage, type QueueMessageOutcome, type QueueMessageRow, type QueueMetadata, type QueuesResult, RANK_TIEBREAK, RELATION_EXISTS_KEY, RELATION_FUNCTION_PREFIX, REPROJECTION_MIGRATION_PREFIX, RLS_UNWRAP_SYMBOL, type RankBeforeOptions, type RankBeforeResult, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageComputation, type RankPageDeps, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReadFootprint, type ReadHook, type ReadTablePageOptions, type RecordMailInput, type RecordQueueMessageInput, type RelationDefinitionLike, type RelationExistsMarker, type RelayAttach, type RelayDetach, type RelayFrame, type RelayHost, RelayMember, type RelayShapePoke, type RelayShapeSeed, type RelayShapeSubscribe, type RenderedSql, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type ResolveWithResult, type ResolvedShape, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunTriggersOptions, SCAN_DEP, SCHEMA_HISTORY_MAX_VERSIONS, SEARCH_STATE_TABLE, type SchedulableWorkflowReferenceLike, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type ScoredDocument, type SearchFilterBuilderLike, type SearchIndexDefinitionLike, type SearchScoredDocument, type SelectMatchingIdsOptions, type ServerDefaultContextLike, type SettingEntry, type SettingKind, type SettingsResult, type ShapePokePart, type ShapeRow, type ShapeRowOp, type ShapeSubscriptionQuery, type ShardRankPageResult, ShardRunner, type ShardRunnerOptions, type ShardSocketLike, type SocketAttachment, type SortDirection, type SourceClientLike, type SourceCursorLike, type SourceRefresh, type SqlConsoleResult, type SqlCursor, type SqlEngine, type SqlExec, type SqlLintResult, type StorageMetadata, type StorageReference, type StorageReferenceResult, type StorageRuleMetadata, type StorageRulesResult, type StudioFeaturesResult, type SubscriptionConnection, type SubscriptionEnvelope, type SubscriptionIdentity, type SubscriptionInfo, type SubscriptionQuery, type SubscriptionReadFootprint, type SubscriptionsResult, 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 TablesIndexesResult, type TransactionHeadroom, TransactionHeadroomTracker, type TransactionLimits, type TransactionSqlLike, type TriggerContextLike, type TriggerDefinitionLike, type TriggerEventLike, type TriggerOpLike, type TriggerTimingLike, type TtlSweepSpec, type ValidatorLike, type WhereInput, type WhereSqlStrategy, type WithInput, type WorkflowInstanceState, type WorkflowInstanceStatusResult, type WorkflowMetadata, type WorkflowsResult, type WriteEvent, type WriteHook, advanceClientWatermark, aggUpsertSql, aggregateSqlFunction, aggregateTableName, appendAuditEntry, appendCdcChange, applyCdcChanges, applyOnDelete, applySelect, armRestore, assertFlatPredicate, assertReadonly, assertShapeShardable, assertValidClientId, awaitWsDrain, backfillAggregateIndexes, backfillRankIndexes, backfillSearchIndexes, backfillSearchIndexesForTable, boundingBoxCenter, boundingBoxGeohashes, buildIndexRange, buildPokeFrames, buildReprojectionMigration, buildSeekBeforeWhere, buildSeekWhere, buildSettings, bumpCdcEpoch, clampPromotionThresholds, clearCapturedMail, clearQueueMessages, coerceAggregateNumber, compileWhereSql, computeRankPage, containsRelationPredicate, countLegacyRows, coveringGeohashes, createCompanionSync, createDependencyTracker, createFanoutCounters, createIndexSql, createReadFootprint, createRelayLink, createShardCtxDb, createSystemReader, decodeCursor, deleteGlobalShapeSnapshot, deleteGlobalShapeSnapshotsForConnection, depKey, diffExternalSource, diffGlobalMembership, distinctValues, encodeAggregateKey, encodeCursor, encodeGeohash, encodePartitionKey, encodeRowsPatch, ensureAuditTable, ensureMailTable, exportShardRows, exportShardTable, facetColumn, fanOutScalarCounts, findStorageReferences, foldAggregateTally, geoTableName, guardWriter, hasTrigger, haversineMeters, hydrateDocsById, importShardRows, indexKeysForRow, isDevEnvironment, isFtsAvailable, isLossyBody, isRelationPredicate, isSoftDeleted, isSourceDue, jsonPath, jsonPathSql, keysTouchRanges, liftSourceId, lintReadonlySql, listTables, matchesRankStaticWhere, matchesStaticWhere, materializeExternalRows, materializeExternalRowsIncremental, mergeChangedKeys, mergeWhere, migrateCdcLog, migrateCdcMeta, migrateClientWatermark, migrateGlobalShapeSnapshot, migrateIdempotency, migrateSearchState, minCdcSeq, nextPromotionState, normalizeCountArgument, normalizeIdStructurally, normalizeOrderKeys, normalizeSourceDocument, normalizeSourceValue, param, parseExportShardArgs, parseImportShardArgs, planAggregateLookup, pointInBoundingBox, projectColumns, pullExternalSourceIncrementalTick, pullExternalSourceTick, qualifiedJsonPath, qualifiedJsonPathSql, quoteIdentifier, rankKeyFromDocument as rankKeyFromDoc, rankTableName, reactiveCacheKey, readAggregateValue, readAuditLog, readBookmark, readCapturedMail, readCdcChanges, readCdcCursor, readCdcEpoch, readClientWatermark, readExternalSourceBaseline, readGlobalShapeSnapshot, readIdempotent, readMigrationStatus, readQueueMessageById, readQueueMessages, readSchemaHistory, readSchemaVersion, readSearchBackfillState, readTablePage, recordCapturedMail, recordChangedKeys, recordFanoutPass, recordQueueMessages, recordSchemaVersion, relationHooks, relayCountFor, renderSql, reprojectableFields, reprojectionMigrationId, reprojectionTables, resolveRankPartition, resolveRelationPredicates, resolveWith, rowToDocument, runDataMigration, runDrizzle, runExternalSourceTick, runReadonlySql, runRowValidators, runShardMigrations, runSocketPool, runSql, runTriggers, selectExpiredIds, selectExportTables, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy, selectMatchingIds, selectShapeMemberIds, selectShapeRows, sendDeltaFrames, serializeSqlValue, shapeRoutingKey, softDeleteScope, sortColumnName, stableStringify, stableWireKey, subscriptionListDeltas, summarizeFanoutTopics, summarizeSubscriptions, tableColumns, tableFromDepKey, throwingScheduler, trimCdcChanges, trimIdempotent, tryRowToDocument, trySendFrame, validateImportRow, writeGlobalShapeSnapshot, writeIdempotent, writeSearchBackfillState, writeTouchesMemo };
2804
+ type VectorPageSync = (table: string, rows: ReadonlyArray<{
2805
+ doc: Record<string, unknown>;
2806
+ id: string;
2807
+ }>) => Promise<ReadonlyArray<{
2808
+ error: unknown;
2809
+ id: string;
2810
+ }>>;
2811
+ type OrderedAfterWrites = <T, U>(read: () => T, work: (value: T) => Promise<U>) => Promise<U>;
2812
+ declare const backfillVectorIndexes: (sql: SqlExec, targets: ReadonlyArray<VectorBackfillTarget>, sync: VectorPageSync, options: {
2813
+ maxPages?: number;
2814
+ ordered: OrderedAfterWrites;
2815
+ restart?: boolean;
2816
+ }) => Promise<VectorBackfillProgress>;
2817
+ export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, ADMIN_TOKEN_TABLE, AGGREGATE_SQL_FUNCTION, AGG_COUNT, AGG_KEY, AGG_VALUE, AUDIT_LOG_TABLE, type AdminTokenSummary, type AdvisorProcedure, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type AppendAuditEntry, type ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, BIGINT_KEY_DIGITS, type BroadcastDelta, CDC_LOG_TABLE, CDC_LOG_TABLE_SEQ_INDEX, CDC_META_TABLE, CLIENT_WATERMARK_TABLE, COMMIT_SEQ_FIELD, COMMIT_SEQ_TABLE, CURSOR_PREFIX, type CacheEntry, type CapturedMailRow, type CdcArchiveScope, type CdcChange, type CdcChangeKey, type ChangedKeys, type Clock, type ColumnMeta, type ColumnMetaLike, CompanionMemo, type CompanionSync, type CompanionSyncDeps, ConflictError, type ConflictKind, type CountArgs, CountRlsUnsupportedError, type CreateWorkflowInstanceResult, type CrossShardReadArgs, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_FANOUT_TOPIC_LIMIT, DEFAULT_MAX_RELATION_KEYS, DEFAULT_MAX_RELAYS, DEFAULT_PROMOTION_THRESHOLDS, DEFAULT_TRANSACTION_LIMITS, DOC_COLUMN, type DataMigrationDocument, type DataMigrationLike, type DataMigrationTransform, type DatabaseWriterLike, type DependencyTracker, type DeployInfo, type DurableAttachDecision, type DurableStreamAttach, type DurableStreamRun, DurableStreamRunner, type DurableStreamSink, type ExportRow, type ExportShardAdminArgs, type ExportShardArgs, type ExternalSourceDiffResult, type ExternalSourceLike, FLAGS_FUNCTION_PREFIX, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FanOutBudget, type FanoutMetricsResult, type FanoutPathCounters, type FanoutTopicStat, type FieldOperators, type FilterClause, type FilterOperator, type FlagEvaluation, type FlagsResult, type FtsWriteOptions, type FunctionCallStat, type FunctionScanAttribution, type FunctionStatsResult, GEO_DEFAULT_PRECISION, GLOBAL_SHAPE_SNAPSHOT_TABLE, type GeoBoundingBox, type GeoFilterBuilderLike, type GeoIndexDefinitionLike, type GeoPoint, type GeoScoredDocument, type GlobalPollCounters, GlobalPollTick, type GroupByEntry, type GroupByOptions, type GuardableSchema$1 as GuardableSchema, IDEMPOTENCY_TABLE, type IdGenerator, type IdempotentRecord, type ImportConflictMode, type ImportError, type ImportRow, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IncrementalMaterializeResult, type IndexDefinitionLike, type IndexKeyEntry, type IndexRangeBuilderLike, type KeyRange, type KeyedRelationWriteInfo, type LifecycleDispatchInfo, type LifecycleEvent, type LiveSocketControlCall, MAIL_RETENTION, MAIL_TABLE, MAX_DURABLE_STREAM_BYTES, MAX_DURABLE_STREAM_CHUNKS, MAX_PAGE_SIZE, MAX_SQL_ROWS, type MaskColumnMetadata, type MaskPoliciesResult, type MaterializeResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type NullPlacement, type OnDeleteActionLike, type OrderByClause, type OrderByInput, type OrderKey, type OrderKeyConstraints, OwnerRelay, type OwnerRelayFrame, type PaginationOptions, type PatchVerifier, type PatchWriteOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type PokeFrameMeta, type PromotionState, type PromotionThresholds, QUEUE_TABLE, type QueryArgs, type QueryPage, type QueryPlan, type QueueMessageOutcome, type QueueMessageRow, type QueueMetadata, type QueuesResult, RANK_TIEBREAK, REACTOR_STATE_TABLE, RELATED_DEFAULT_LIMIT, RELATED_DEPTH_DECAY, RELATED_MAX_DEPTH, RELATED_MAX_LIMIT, RELATION_EXISTS_KEY, RELATION_FUNCTION_PREFIX, RELAY_SIGNATURE_HEADER, REPROJECTION_MIGRATION_PREFIX, RLS_UNWRAP_SYMBOL, type RangeOperandType, type RankBeforeOptions, type RankBeforeResult, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageComputation, type RankPageDeps, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReactorDispatchResult, type ReactorMetadata, type ReactorState, type ReactorStats, type ReactorsResult, type ReadFootprint, type ReadHook, type ReadTablePageOptions, type RecordMailInput, type RecordQueueMessageInput, type RelatedDirection, type RelatedNode, type RelatedOptions, type RelatedPage, type RelatedStart, type RelatedStartReference, type RelationDefinitionLike, type RelationEdge, type RelationExistsMarker, type RelationGraphReader, type RelationWriteInfo, type RelationWriteMap, type RelayAttach, type RelayDetach, type RelayFrame, type RelayHost, RelayMember, type RelayPokeDelivery, type RelayRoomEvent, type RelayRoomVerdict, type RelayShapePoke, type RelayShapeSeed, type RelayShapeSubscribe, type RelayShapeUnsubscribe, type RenderedSql, type ReplicaFollowerHost, type ReplicaOwnerHost, type ReplicaReadiness, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type ResolveWithResult, type ResolvedShape, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunTriggersOptions, SCAN_DEP, SCHEDULE_OUTBOX_TABLE, SCHEMA_HISTORY_MAX_VERSIONS, SEARCH_STATE_TABLE, SHAPE_POKE_CURSOR_TABLE, type SchedulableWorkflowReferenceLike, type ScheduleOutbox, type ScheduleOutboxEntry, type ScheduleOutboxEnvelope, type ScheduleOutboxRow, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type ScoredDocument, type SearchBackfillProgress, type SearchFilterBuilderLike, type SearchIndexDefinitionLike, type SearchScoredDocument, type SelectMatchingIdsOptions, type ServerDefaultContextLike, type SettingEntry, type SettingKind, type SettingsResult, ShapeDiffCache, type ShapePokeCursorRow, type ShapePokePart, type ShapeProbeCounters, type ShapeRow, type ShapeRowOp, type ShapeSubscriptionQuery, type ShardRankPageResult, ShardRunner, type ShardRunnerOptions, type ShardSiblingHost, type ShardSocketLike, type SocketAttachment, type SortDirection, type SourceClientLike, type SourceCursorLike, type SourceRefresh, type SqlConsoleResult, type SqlCursor, type SqlEngine, type SqlExec, type SqlLintResult, type StorageMetadata, type StorageReference, type StorageReferenceResult, type StorageRuleMetadata, type StorageRulesResult, type StudioFeaturesResult, type SubscriptionConnection, type SubscriptionEnvelope, type SubscriptionIdentity, type SubscriptionInfo, type SubscriptionQuery, type SubscriptionReadFootprint, type SubscriptionsResult, 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 TablesIndexesResult, type ThroughRelationWriteInfo, type TransactionHeadroom, TransactionHeadroomTracker, type TransactionLimitKind, type TransactionLimitWarning, type TransactionLimits, type TransactionSqlLike, type TriggerContextLike, type TriggerDefinitionLike, type TriggerEventLike, type TriggerOpLike, type TriggerTimingLike, type TtlSweepSpec, UNVOUCHABLE_DEP, VECTOR_BACKFILL_MAX_PAGES, type ValidatorLike, type VectorBackfillProgress, WORKERD_SQLITE_LIMITS, type WhereFilter, type WhereInput, type WhereSqlStrategy, type WithInput, type WorkflowInstanceState, type WorkflowInstanceStatusResult, type WorkflowMetadata, type WorkflowsResult, type WriteEvent, type WriteHook, adminTokenExists, advanceClientWatermark, aggUpsertSql, aggregateSqlFunction, aggregateTableName, allocateCommitSeq, appendAuditEntry, appendCdcChange, appendStreamChunk, applyCdcChanges, applyInsertDefaults, applyOnDelete, applySelect, archiveCdcSegment, armRestore, assertFlatPredicate, assertNoExplicitUndefined, assertPatchAllowed, assertReadonly, assertShapeShardable, assertStorableRowId, assertValidClientId, awaitWsDrain, backfillAggregateIndexes, backfillRankIndexes, backfillSearchIndexes, backfillSearchIndexesForTable, backfillVectorIndexes, bigintSqlKey, boundingBoxCenter, boundingBoxGeohashes, buildIndexRange, buildPokeFrames, buildReprojectionMigration, buildSeekBeforeWhere, buildSeekWhere, buildSettings, buildShapeDiff, bumpCdcEpoch, cdcArchiveRewound, cdcCanVouchFor, cdcForkedError, cdcSeqLeavingRows, cdcTouchesTables, cdcTrimmedError, claimStreamRun, clampPromotionThresholds, clearCapturedMail, clearCompanionSignatures, clearMemoryTables, clearQueueMessages, coerceAggregateNumber, compactCdcDocs, compileWhereSql, composeReadPredicate, computeRankPage, containsRelationPredicate, countLegacyRows, coveringGeohashes, createAdminTokenRecord, createCompanionSync, createDependencyTracker, createFanoutCounters, createGlobalPollCounters, createIndexSql, createReadFootprint, createRelayLink, createReplicaLink, createShapeDiffCache, createShapeProbeCounters, createShardCtxDb, createSystemReader, cursorBelowRetainedFloor, decideDurableAttach, decodeBigintSqlKey, decodeCursor, decodeFloat64SqlKey, deferScheduleOutbox, deleteGlobalShapeSnapshot, deleteGlobalShapeSnapshotsForConnection, deleteShapePokeCursor, deleteShapePokeCursorsForConnection, deleteStreamRun, depKey, deriveRelationEdges, describeRelationWrites, diffExternalSource, diffGlobalMembership, distinctValues, dropScheduleOutbox, encodeAggregateKey, encodeCursor, encodeGeohash, encodePartitionKey, encodeRowsPatch, ensureAuditTable, ensureMailTable, envOptionalPositiveInt, envPositiveInt, equalityPinnedFields, exportShardRows, facetColumn, fanOutScalarCounts, findManyPage, findRelated, findStorageReferences, finishStreamRun, float64SqlKey, foldAggregateTally, forgetScheduleOutbox, ftsCompanionDdl, ftsPurgeDocument, ftsRowidMapName, ftsUnmappedPage, ftsWriteDocument, gateReplicaDispatch, geoTableName, globalShapeReadKey, groupUnmappedRows, guardWriter, handleReplicaControl, hasScheduleOutboxEntry, hasTrigger, haversineMeters, importShardRows, indexKeysForRow, isDevEnvironment, isFtsAvailable, isInternalTableName, isLossyBody, isMemoryTable, isPushableWhere, isRelationPredicate, isSoftDeleted, isSourceDue, isTtlExpired, isVacuousFilterClause, jsonPath, jsonPathSql, keysTouchRanges, liftSourceId, lintReadonlySql, listAdminTokens, listReactorStates, listTables, markUnvouchableReads, matchesRankStaticWhere, matchesStaticWhere, materializeExternalRows, materializeExternalRowsIncremental, memoryTableNames, mergeChangedKeys, mergeWhere, migrateCdcLog, migrateCdcMeta, migrateClientWatermark, migrateCommitSeq, migrateDurableStreams, migrateGlobalShapeSnapshot, migrateIdempotency, migrateReactorState, migrateScheduleOutbox, migrateSearchState, migrateShapePokeCursor, minCdcReplayableSeq, minCdcSeq, minShapePokeCursor, nextPromotionState, nextTtlExpiry, normalizeCountArgument, normalizeIdStructurally, normalizeOrderKeys, normalizeSourceDocument, normalizeSourceValue, nullsFirstOf, nullsOrderSuffix, operatorFields, param, parkScheduleOutbox, parseExportShardArgs, parseImportShardArgs, patchDependsOnRow, planAggregateLookup, pointInBoundingBox, probeScheduleOutbox, projectColumns, pullExternalSourceIncrementalTick, pullExternalSourceTick, qualifiedJsonPath, qualifiedJsonPathSql, quoteIdentifier, rankKeyFromDocument as rankKeyFromDoc, rankPivotConditionSql, rankTableName, reactiveCacheKey, reactorNeedsRun, readAggregateValue, readArchivedCdcChanges, readAuditLog, readBookmark, readCapturedMail, readCdcArchivedThrough, readCdcChangeKeys, readCdcChanges, readCdcCursor, readCdcEpoch, readClientWatermark, readCommitSeq, readDeployInfo, readDueScheduleOutbox, readDueScheduleOutboxEntry, readExternalSourceBaseline, readGlobalShapeSnapshot, readIdempotent, readMigrationStatus, readPatchField, readQueueMessageById, readQueueMessages, readReactorState, readScheduleOutbox, readScheduleOutboxState, readSchemaHistory, readSchemaVersion, readSearchBackfillState, readShapePokeCursor, readStreamChunks, readStreamRun, readTablePage, recordCapturedMail, recordChangedKeys, recordFanoutPass, recordGlobalPollPass, recordQueueMessages, recordScheduleOutbox, recordSchemaVersion, recordShapeProbePass, relationHooks, relayCountFor, renderSql, reprojectableFields, reprojectionMigrationId, reprojectionTables, requeueScheduleOutbox, resolvePatch, resolveRankPartition, resolveRankSeekTuple, resolveRelationPredicates, resolveWith, revokeAdminTokenRecord, rowToDocument, runDataMigration, runDrizzle, runExternalSourceTick, runReadonlySql, runRowValidators, runShardMigrations, runSocketPool, runSql, runTriggers, selectExpiredIds, selectExportTables, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy, selectMatchingIds, selectShapeMembers, selectShapeRows, serializeSqlValue, serverInList, shapeRoutingKey, siblingSecretOf, signSiblingBody, softDeleteScope, sortColumnName, sqliteInList, stripReservedPatchFields, stubByName, subscriptionFrames, subscriptionListDeltas, summarizeFanoutTopics, summarizeSubscriptions, tableColumns, tableFromDepKey, throwingScheduler, tiebreakDirectionFor, trimCdcChanges, trimIdempotent, trimScheduleOutbox, trimStreamRuns, tryRowToDocument, trySendFrame, unionAll, uniqueIndexFields, validateImportRow, verifyAdminTokenDigest, verifySiblingBody, whereFilter, whereOfFilter, writeCdcArchivedThrough, writeGlobalShapeSnapshot, writeIdempotent, writeReactorState, writeSearchBackfillState, writeShapePokeCursor, writeShapePokeCursors, writeTouchesMemo };