@lunora/shard-engine 1.0.0-alpha.15 → 1.0.0-alpha.151

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 (158) hide show
  1. package/README.md +1 -1
  2. package/dist/conformance/index.mjs +1 -1
  3. package/dist/index.d.mts +861 -173
  4. package/dist/index.d.ts +861 -173
  5. package/dist/index.mjs +1 -1
  6. package/dist/packem_shared/ADMIN_FUNCTIONS-Cug8Z4jD.mjs +1 -0
  7. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-C_ZipS9R.mjs +1 -0
  8. package/dist/packem_shared/AGG_COUNT-Ctb5Pnyl.mjs +1 -0
  9. package/dist/packem_shared/AUDIT_LOG_TABLE-BFJ65SRS.mjs +8 -0
  10. package/dist/packem_shared/BIGINT_KEY_DIGITS-DE6yshOt.mjs +1 -0
  11. package/dist/packem_shared/CDC_LOG_TABLE-C7o2xrt1.mjs +18 -0
  12. package/dist/packem_shared/CLIENT_WATERMARK_TABLE-De7z_OHV.mjs +7 -0
  13. package/dist/packem_shared/COMMIT_SEQ_FIELD-Da1DjGqo.mjs +4 -0
  14. package/dist/packem_shared/CURSOR_PREFIX-6offuG6M.mjs +1 -0
  15. package/dist/packem_shared/CountRlsUnsupportedError-BvsDqfO2.mjs +1 -0
  16. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-D1FtktFp.mjs +31 -0
  17. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-BeTWZQ4X.mjs +1 -0
  18. package/dist/packem_shared/DEFAULT_MAX_RELAYS-CrsP5Ldh.mjs +8 -0
  19. package/dist/packem_shared/DEFAULT_PROMOTION_THRESHOLDS-B3pRMuqb.mjs +1 -0
  20. package/dist/packem_shared/DEFAULT_TRANSACTION_LIMITS-Dmj5VBrV.mjs +1 -0
  21. package/dist/packem_shared/DurableStreamRunner-MMlV5qKQ.mjs +1 -0
  22. package/dist/packem_shared/GEO_DEFAULT_PRECISION-CqpQZ-J_.mjs +1 -0
  23. package/dist/packem_shared/GLOBAL_SHAPE_SNAPSHOT_TABLE-Bb6-aZuH.mjs +7 -0
  24. package/dist/packem_shared/GlobalPollTick-BNK4o-XT.mjs +1 -0
  25. package/dist/packem_shared/IDEMPOTENCY_TABLE-COrgeP3O.mjs +7 -0
  26. package/dist/packem_shared/MAIL_RETENTION-DMolrLYt.mjs +18 -0
  27. package/dist/packem_shared/MAX_SQL_ROWS-eRignWyO.mjs +4 -0
  28. package/dist/packem_shared/MAX_TOKEN_LENGTH-BakL9FUy-B3VwYY8C.mjs +1 -0
  29. package/dist/packem_shared/NotUniqueError-BR7jasrr.mjs +1 -0
  30. package/dist/packem_shared/QUEUE_TABLE-C-goXtGd.mjs +17 -0
  31. package/dist/packem_shared/RANK_TIEBREAK-D3ye2GsL.mjs +1 -0
  32. package/dist/packem_shared/REACTOR_STATE_TABLE-D2Mn204f.mjs +28 -0
  33. package/dist/packem_shared/RELATED_DEFAULT_LIMIT-CVqN4JEu.mjs +1 -0
  34. package/dist/packem_shared/RELATION_EXISTS_KEY-wxgj6rSL.mjs +1 -0
  35. package/dist/packem_shared/RELAY_SIGNATURE_HEADER-C_P73AOx.mjs +1 -0
  36. package/dist/packem_shared/REPROJECTION_MIGRATION_PREFIX-Czcb6_mO.mjs +1 -0
  37. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-J1tiBtRj.mjs +1 -0
  38. package/dist/packem_shared/ReactiveCache-DHhhLJtN.mjs +1 -0
  39. package/dist/packem_shared/SCAN_DEP-D7qE3iUe.mjs +1 -0
  40. package/dist/packem_shared/SCHEDULE_OUTBOX_TABLE-DcZI7Yhl.mjs +11 -0
  41. package/dist/packem_shared/SCHEMA_HISTORY_MAX_VERSIONS-CEwFjj-O.mjs +6 -0
  42. package/dist/packem_shared/SEARCH_STATE_TABLE-nYN2eKs_.mjs +1 -0
  43. package/dist/packem_shared/SHAPE_POKE_CURSOR_TABLE-BGvY3sFI.mjs +8 -0
  44. package/dist/packem_shared/ShapeDiffCache-iNO-hUiy.mjs +1 -0
  45. package/dist/packem_shared/ShardRunner-CrveaPId.mjs +1 -0
  46. package/dist/packem_shared/UNVOUCHABLE_DEP-C68htACn.mjs +1 -0
  47. package/dist/packem_shared/VECTOR_BACKFILL_MAX_PAGES-zxItOlPE.mjs +1 -0
  48. package/dist/packem_shared/WORKERD_SQLITE_LIMITS-B_4w7tzY.mjs +1 -0
  49. package/dist/packem_shared/accepts-null-D1zmJbyR.mjs +1 -0
  50. package/dist/packem_shared/aggregateTableName-B_CtIQCS.mjs +1 -0
  51. package/dist/packem_shared/appendStreamChunk-BZYgGE9Y.mjs +17 -0
  52. package/dist/packem_shared/applyInsertDefaults-vVfUyiJ2.mjs +1 -0
  53. package/dist/packem_shared/archiveCdcSegment-Cr8oGLfB.mjs +4 -0
  54. package/dist/packem_shared/{armRestore-BNzdvQ_o.mjs → armRestore-Bu1_8SUa.mjs} +1 -1
  55. package/dist/packem_shared/assertPatchAllowed-CA_H466g.mjs +1 -0
  56. package/dist/packem_shared/awaitWsDrain-N-oR29RI.mjs +1 -0
  57. package/dist/packem_shared/backfillAggregateIndexes-DSplGrR_.mjs +1 -0
  58. package/dist/packem_shared/buildIndexRange-DQ3eWAGd.mjs +1 -0
  59. package/dist/packem_shared/buildPokeFrames-WR-hp0mX.mjs +1 -0
  60. package/dist/packem_shared/buildReprojectionMigration-Ds2JaFo7.mjs +1 -0
  61. package/dist/packem_shared/buildSettings-BRkZd6_E.mjs +1 -0
  62. package/dist/packem_shared/buildShapeDiff-Dc9TOdHq.mjs +1 -0
  63. package/dist/packem_shared/clearCompanionSignatures-3MlVqWZD.mjs +1 -0
  64. package/dist/packem_shared/clearMemoryTables-aMRERF0w.mjs +1 -0
  65. package/dist/packem_shared/compileWhereSql-TgKZIvWM.mjs +1 -0
  66. package/dist/packem_shared/computeRankPage-BZIpATcs.mjs +1 -0
  67. package/dist/packem_shared/createCompanionSync-BMS8yYTx.mjs +1 -0
  68. package/dist/packem_shared/createReplicaLink-CSbJvezn.mjs +7 -0
  69. package/dist/packem_shared/createSystemReader-DcDLFfC-.mjs +1 -0
  70. package/dist/packem_shared/ctx-db-relay-shapes-DV0VO4HG.mjs +17 -0
  71. package/dist/packem_shared/ctx-db-search-state-FjgzTFok.mjs +1 -0
  72. package/dist/packem_shared/defineEngineContractSuite-BiXyk2gE.mjs +1 -0
  73. package/dist/packem_shared/describeRelationWrites-omar6-u9.mjs +1 -0
  74. package/dist/packem_shared/diffExternalSource-B0FZlDoL.mjs +1 -0
  75. package/dist/packem_shared/do-sql-BWrJQAOh.mjs +1 -0
  76. package/dist/packem_shared/effective-kind-BmG_zCAy.mjs +1 -0
  77. package/dist/packem_shared/envOptionalPositiveInt-D2pY-c64.mjs +1 -0
  78. package/dist/packem_shared/estimate-bytes-_k74s6LZ.mjs +1 -0
  79. package/dist/packem_shared/exportShardRows-b0pfdTXz.mjs +1 -0
  80. package/dist/packem_shared/fts-companion-CA8mLJWq.mjs +1 -0
  81. package/dist/packem_shared/ftsCompanionDdl-0y8d4YvE.mjs +1 -0
  82. package/dist/packem_shared/hasTrigger-CjlwI4le.mjs +1 -0
  83. package/dist/packem_shared/isInternalTableName-BoljO2tP.mjs +1 -0
  84. package/dist/packem_shared/isPushableWhere-BeYAOjUb.mjs +1 -0
  85. package/dist/packem_shared/isSoftDeleted-DXANkomm.mjs +9 -0
  86. package/dist/packem_shared/json-field-path-DeJW4U9z.mjs +1 -0
  87. package/dist/packem_shared/liftSourceId-CA3ENhXj.mjs +1 -0
  88. package/dist/packem_shared/materializeExternalRows-rYWz87LR.mjs +1 -0
  89. package/dist/packem_shared/mergeChangedKeys-CF2mjYuy.mjs +1 -0
  90. package/dist/packem_shared/relation-operators-BEg-CvCH.mjs +1 -0
  91. package/dist/packem_shared/runDrizzle-RC09zZrh.mjs +1 -0
  92. package/dist/packem_shared/runShardMigrations-CEZTl9LV.mjs +5 -0
  93. package/dist/packem_shared/runSocketPool-CZJ2X9cF.mjs +1 -0
  94. package/dist/packem_shared/selectExpiredIds-DDQyqbLk.mjs +1 -0
  95. package/dist/packem_shared/selectShapeMembers-BCfKypfN.mjs +1 -0
  96. package/dist/packem_shared/serializeSqlValue-DeoBMpZ2.mjs +1 -0
  97. package/dist/packem_shared/where-sql-BjY4rnqb.mjs +1 -0
  98. package/package.json +5 -4
  99. package/dist/packem_shared/ADMIN_FUNCTIONS-xKxYOiRC.mjs +0 -1
  100. package/dist/packem_shared/AGGREGATE_SQL_FUNCTION-CTo0-9iZ.mjs +0 -1
  101. package/dist/packem_shared/AGG_COUNT-B0Pb1nQZ.mjs +0 -1
  102. package/dist/packem_shared/AUDIT_LOG_TABLE-C6nwXFPd.mjs +0 -8
  103. package/dist/packem_shared/CDC_LOG_TABLE-D__2M4gX.mjs +0 -8
  104. package/dist/packem_shared/CLIENT_WATERMARK_TABLE-CzApRlyv.mjs +0 -7
  105. package/dist/packem_shared/CountRlsUnsupportedError-8BqPYQoP.mjs +0 -1
  106. package/dist/packem_shared/DATA_MIGRATION_STATE_TABLE-BrpAGtXf.mjs +0 -31
  107. package/dist/packem_shared/DEFAULT_MAX_RELATION_KEYS-DOox9BFi.mjs +0 -1
  108. package/dist/packem_shared/DEFAULT_MAX_RELAYS-AcHLNxha.mjs +0 -1
  109. package/dist/packem_shared/DEFAULT_PROMOTION_THRESHOLDS-BdmnUGLO.mjs +0 -1
  110. package/dist/packem_shared/DEFAULT_TRANSACTION_LIMITS-BH5q0Ror.mjs +0 -1
  111. package/dist/packem_shared/GEO_DEFAULT_PRECISION-DyI5zggj.mjs +0 -1
  112. package/dist/packem_shared/GLOBAL_SHAPE_SNAPSHOT_TABLE-soMJDSBs.mjs +0 -7
  113. package/dist/packem_shared/IDEMPOTENCY_TABLE-Bvu9JkiL.mjs +0 -7
  114. package/dist/packem_shared/MAIL_RETENTION-BefR9Sei.mjs +0 -18
  115. package/dist/packem_shared/MAX_SQL_ROWS-nMwkxv5f.mjs +0 -2
  116. package/dist/packem_shared/NotUniqueError-C32BFrv1.mjs +0 -1
  117. package/dist/packem_shared/QUEUE_TABLE-DgBqWrXX.mjs +0 -17
  118. package/dist/packem_shared/RANK_TIEBREAK-D541BOFR.mjs +0 -1
  119. package/dist/packem_shared/RELATION_EXISTS_KEY-BaqSIFU1.mjs +0 -1
  120. package/dist/packem_shared/RLS_UNWRAP_SYMBOL-DcqORh2s.mjs +0 -1
  121. package/dist/packem_shared/ReactiveCache-iWA9VRqk.mjs +0 -1
  122. package/dist/packem_shared/SCAN_DEP-D_yR9EeV.mjs +0 -1
  123. package/dist/packem_shared/SCHEMA_HISTORY_MAX_VERSIONS-BEU0CuW5.mjs +0 -6
  124. package/dist/packem_shared/SEARCH_STATE_TABLE-BZ_fxI5l.mjs +0 -1
  125. package/dist/packem_shared/ShardRunner-DIqVdWtk.mjs +0 -1
  126. package/dist/packem_shared/aggregateTableName-DKo6dwBP.mjs +0 -1
  127. package/dist/packem_shared/applyOnDelete-fMu_5DR5.mjs +0 -1
  128. package/dist/packem_shared/applySelect-BjgwvZmI.mjs +0 -1
  129. package/dist/packem_shared/awaitWsDrain-DKycCSBS.mjs +0 -1
  130. package/dist/packem_shared/backfillAggregateIndexes-BVNrfFcI.mjs +0 -1
  131. package/dist/packem_shared/buildIndexRange-DFsdtPjD.mjs +0 -1
  132. package/dist/packem_shared/buildPokeFrames-CCxYXd2V.mjs +0 -1
  133. package/dist/packem_shared/buildSettings-COIJsw7a.mjs +0 -1
  134. package/dist/packem_shared/compileWhereSql-B4rPariq.mjs +0 -1
  135. package/dist/packem_shared/computeRankPage-B7U6t1fW.mjs +0 -1
  136. package/dist/packem_shared/createCompanionSync-Dym8huD9.mjs +0 -1
  137. package/dist/packem_shared/createReadFootprint-DIrrxRTE.mjs +0 -1
  138. package/dist/packem_shared/createSystemReader-DcDcrtM3.mjs +0 -1
  139. package/dist/packem_shared/ctx-db-companions-7fIu-E2H.mjs +0 -1
  140. package/dist/packem_shared/defineEngineContractSuite-LKRHlQwE.mjs +0 -1
  141. package/dist/packem_shared/diffExternalSource-DMpkJta1.mjs +0 -1
  142. package/dist/packem_shared/estimate-bytes-DwQON1Ky.mjs +0 -1
  143. package/dist/packem_shared/exportShardRows-Bbi_JGfn.mjs +0 -1
  144. package/dist/packem_shared/hasTrigger-CbkOHExZ.mjs +0 -1
  145. package/dist/packem_shared/isSoftDeleted-doD_8AwX.mjs +0 -9
  146. package/dist/packem_shared/liftSourceId-DApAbu7Q.mjs +0 -1
  147. package/dist/packem_shared/materializeExternalRows-BR8MvZTz.mjs +0 -1
  148. package/dist/packem_shared/mergeChangedKeys-BXtUgIPW.mjs +0 -1
  149. package/dist/packem_shared/param-B5lF5Jd9.mjs +0 -1
  150. package/dist/packem_shared/runDrizzle-B6rnz3so.mjs +0 -1
  151. package/dist/packem_shared/runShardMigrations-DhZLG0bn.mjs +0 -5
  152. package/dist/packem_shared/runSocketPool-DPQLVyWF.mjs +0 -1
  153. package/dist/packem_shared/selectExpiredIds-DxFEwNlT.mjs +0 -1
  154. package/dist/packem_shared/selectShapeMemberIds-BD3JiZn-.mjs +0 -1
  155. package/dist/packem_shared/serializeSqlValue-DnpyaLcw.mjs +0 -1
  156. package/dist/packem_shared/stableStringify-BjLh4gvA.mjs +0 -1
  157. package/dist/packem_shared/stableWireKey-C4JfdJ_e.mjs +0 -1
  158. package/dist/packem_shared/wire-codec-D_fiax9d.mjs +0 -1
package/dist/index.d.ts 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,43 @@ 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;
29
56
  enqueuedAt: number;
30
- functionPath: string;
57
+ functionPath?: string;
31
58
  id: string;
59
+ pool?: string;
32
60
  scheduledFor: number;
33
61
  shardKey?: string;
62
+ workflow?: string;
34
63
  }
35
64
  interface StorageMetadata {
36
65
  contentType?: string;
@@ -86,6 +115,82 @@ interface WhereInput {
86
115
  OR?: WhereInput[];
87
116
  }
88
117
  declare const RELATION_EXISTS_KEY = "__relationExists";
118
+ interface SubscriptionQuery {
119
+ args?: Record<string, unknown>;
120
+ functionPath?: string;
121
+ sinceEpoch?: string;
122
+ sinceSeq?: number;
123
+ table?: string;
124
+ }
125
+ interface ShapeSubscriptionQuery {
126
+ args?: Record<string, unknown>;
127
+ name: string;
128
+ sinceEpoch?: string;
129
+ sinceSeq?: number;
130
+ }
131
+ interface SubscriptionEnvelope {
132
+ caps?: string[];
133
+ clientId?: string;
134
+ context?: Record<string, unknown>;
135
+ data?: unknown;
136
+ generation?: number;
137
+ id: string;
138
+ query?: SubscriptionQuery;
139
+ shape?: {
140
+ args?: Record<string, unknown>;
141
+ name: string;
142
+ };
143
+ sinceCheckpoint?: number;
144
+ sinceChunk?: number;
145
+ sinceEpoch?: string;
146
+ topic?: string;
147
+ type: "ack" | "connect" | "shape_subscribe" | "shape_unsubscribe" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
148
+ }
149
+ interface RpcRequest {
150
+ args?: Record<string, unknown>;
151
+ functionPath: string;
152
+ }
153
+ interface SocketAttachment {
154
+ admin?: boolean;
155
+ adminBinding?: string;
156
+ clientId?: string;
157
+ connected?: boolean;
158
+ connectionId?: string;
159
+ context?: Record<string, unknown>;
160
+ deliveryPermits?: Record<string, {
161
+ epoch: number;
162
+ scope: string;
163
+ }>;
164
+ expiresAt?: number;
165
+ identity?: Record<string, unknown>;
166
+ ip?: string;
167
+ liveGrants?: Record<string, string>;
168
+ pageDeltas?: boolean;
169
+ shapes?: Record<string, ShapeSubscriptionQuery>;
170
+ socketFunction?: string;
171
+ socketPath?: string;
172
+ subs: Record<string, SubscriptionQuery>;
173
+ userId?: string;
174
+ whispers?: string[];
175
+ }
176
+ interface ResolvedShape {
177
+ columns?: ReadonlyArray<string>;
178
+ effectiveWhere?: WhereInput;
179
+ global?: boolean;
180
+ table: string;
181
+ }
182
+ interface SubscriptionIdentity {
183
+ identity?: Record<string, unknown>;
184
+ ip?: string;
185
+ userId?: string;
186
+ }
187
+ interface ShardSocketLike {
188
+ readonly bufferedAmount?: number;
189
+ close?: (code?: number, reason?: string) => void;
190
+ deserializeAttachment?: () => unknown;
191
+ send: (data: string) => void;
192
+ serializeAttachment?: (value: unknown) => void;
193
+ }
89
194
  type AggregateOp = "avg" | "count" | "max" | "min" | "sum";
90
195
  interface AggregateIndexDefinitionLike {
91
196
  readonly by?: ReadonlyArray<string>;
@@ -137,6 +242,11 @@ interface ColumnMetaLike {
137
242
  interface ValidatorLike {
138
243
  readonly _meta?: {
139
244
  readonly column?: ColumnMetaLike;
245
+ readonly inner?: ValidatorLike;
246
+ readonly members?: ReadonlyArray<ValidatorLike>;
247
+ readonly shape?: Readonly<Record<string, ValidatorLike>>;
248
+ readonly tableName?: string;
249
+ readonly value?: unknown;
140
250
  };
141
251
  readonly kind?: string;
142
252
  readonly parse?: (value: unknown) => unknown;
@@ -144,7 +254,7 @@ interface ValidatorLike {
144
254
  type TriggerTimingLike = "after" | "before";
145
255
  type TriggerOpLike = "delete" | "insert" | "update";
146
256
  interface SchedulableWorkflowReferenceLike {
147
- readonly binding?: string;
257
+ readonly className?: string;
148
258
  readonly isLunoraWorkflow: true;
149
259
  readonly name?: string;
150
260
  }
@@ -178,11 +288,18 @@ interface SchemaLike {
178
288
  readonly rlsMode?: "required";
179
289
  readonly tables: Record<string, TableDefinitionLike>;
180
290
  }
291
+ type PatchVerifier = (previous: Record<string, unknown>, next: Record<string, unknown>) => boolean;
292
+ interface PatchWriteOptions {
293
+ verify?: PatchVerifier;
294
+ }
181
295
  interface TableDefinitionLike {
182
296
  readonly aggregateIndexes?: ReadonlyArray<AggregateIndexDefinitionLike>;
297
+ readonly commitOrderedMode?: boolean;
298
+ readonly dropStalePatchesMode?: boolean;
183
299
  readonly geoIndexes?: ReadonlyArray<GeoIndexDefinitionLike>;
184
300
  readonly indexes: ReadonlyArray<IndexDefinitionLike>;
185
301
  readonly isPublic?: boolean;
302
+ readonly memoryMode?: boolean;
186
303
  readonly rankIndexes?: ReadonlyArray<RankIndexDefinitionLike>;
187
304
  readonly relationMap?: Record<string, RelationDefinitionLike>;
188
305
  readonly searchIndexes?: ReadonlyArray<SearchIndexDefinitionLike>;
@@ -200,13 +317,25 @@ interface TableDefinitionLike {
200
317
  field: string;
201
318
  };
202
319
  }
203
- interface RelationDefinitionLike {
320
+ interface KeyedRelationDefinitionLike {
204
321
  readonly field: string;
205
322
  readonly kind: "many" | "one";
206
323
  readonly onDelete?: OnDeleteActionLike;
207
324
  readonly references: string;
208
325
  readonly table: string;
326
+ readonly through?: never;
327
+ }
328
+ interface RelationThroughLike {
329
+ readonly from: string;
330
+ readonly table: string;
331
+ readonly to: string;
209
332
  }
333
+ interface ThroughRelationDefinitionLike {
334
+ readonly kind: "many";
335
+ readonly table: string;
336
+ readonly through: RelationThroughLike;
337
+ }
338
+ type RelationDefinitionLike = KeyedRelationDefinitionLike | ThroughRelationDefinitionLike;
210
339
  type OnDeleteActionLike = "cascade" | "restrict" | "set null";
211
340
  interface NestedWith {
212
341
  limit?: number;
@@ -219,13 +348,11 @@ interface WithInput {
219
348
  [relationName: string]: NestedWith | Record<string, true> | boolean | undefined;
220
349
  _count?: Record<string, true>;
221
350
  }
222
- interface ApplyOnDeleteOptions$1 {
223
- database: DatabaseWriterLike;
224
- relation: RelationDefinitionLike;
225
- row: Record<string, unknown>;
226
- tableName: string;
351
+ interface FanOutBudget {
352
+ remaining: number;
227
353
  }
228
354
  interface ResolveWithOptions {
355
+ fanOutBudget?: FanOutBudget;
229
356
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
230
357
  groupedCounter: (tableName: string, whereField: string, values: unknown[], policyWhere?: WhereInput) => Promise<Map<unknown, number>>;
231
358
  parents: Record<string, unknown>[];
@@ -243,12 +370,17 @@ interface ResolveWithResult {
243
370
  rows: Record<string, unknown>[];
244
371
  }
245
372
  type SortDirection = "asc" | "desc";
246
- type OrderByInput = Record<string, SortDirection>;
373
+ type NullPlacement = "first" | "last";
374
+ type OrderByInput = Record<string, SortDirection | {
375
+ nulls: NullPlacement;
376
+ sort: SortDirection;
377
+ }>;
247
378
  interface QueryArgs {
248
379
  baseWhere?: WhereInput;
249
380
  cursor?: null | string;
250
381
  includeDeleted?: boolean;
251
382
  limit?: number;
383
+ omitContinueCursor?: boolean;
252
384
  orderBy?: OrderByInput[];
253
385
  relationBaseWhere?: (table: string) => undefined | WhereInput;
254
386
  relationMask?: RelationMask;
@@ -264,15 +396,59 @@ interface CrossShardReadArgs {
264
396
  with?: WithInput;
265
397
  }
266
398
  type RelationMask = (table: string, rows: Record<string, unknown>[]) => Record<string, unknown>[];
399
+ interface QueryPlan {
400
+ params: unknown[];
401
+ plan: string[];
402
+ sql: string;
403
+ }
267
404
  interface QueryPage {
268
405
  continueCursor: null | string;
269
406
  isDone: boolean;
270
407
  page: Record<string, unknown>[];
271
408
  splitCursor?: null | string;
272
409
  }
410
+ interface RelationEdge {
411
+ readonly array: boolean;
412
+ readonly column: string;
413
+ readonly name: string;
414
+ readonly sourceTable: string;
415
+ readonly targetTable: string;
416
+ }
417
+ interface RelatedStartReference {
418
+ id: string;
419
+ table: string;
420
+ }
421
+ type RelatedStart = (Record<string, unknown> & {
422
+ _id: string;
423
+ }) | RelatedStartReference;
424
+ type RelatedDirection = "both" | "in" | "out";
425
+ interface RelatedOptions {
426
+ cursor?: null | string;
427
+ depth?: number;
428
+ direction?: RelatedDirection;
429
+ edges?: ReadonlyArray<string>;
430
+ limit?: number;
431
+ relationBaseWhere?: (table: string) => undefined | WhereInput;
432
+ relationMask?: RelationMask;
433
+ }
434
+ interface RelatedNode {
435
+ depth: number;
436
+ document: Record<string, unknown>;
437
+ path: ReadonlyArray<string>;
438
+ pathIds: ReadonlyArray<string>;
439
+ score: number;
440
+ table: string;
441
+ }
442
+ interface RelatedPage {
443
+ continueCursor: null | string;
444
+ isDone: boolean;
445
+ nodes: RelatedNode[];
446
+ }
273
447
  interface OrderKey {
274
448
  direction: SortDirection;
275
449
  field: string;
450
+ nullable: boolean;
451
+ nulls?: NullPlacement;
276
452
  }
277
453
  interface RestrictableQueryOptions {
278
454
  baseWhere?: WhereInput;
@@ -408,10 +584,8 @@ interface LifecycleEvent {
408
584
  shardKey: string;
409
585
  userId: string | null;
410
586
  }
411
- interface LifecycleDispatchInfo {
587
+ interface LifecycleDispatchInfo extends SubscriptionIdentity {
412
588
  event: LifecycleEvent;
413
- identity: Record<string, unknown> | undefined;
414
- userId: string | undefined;
415
589
  }
416
590
  interface MutationDelta {
417
591
  indexKeys?: ReadonlyArray<IndexKeyEntry>;
@@ -423,6 +597,14 @@ interface MutationDelta {
423
597
  interface DatabaseWriterLike {
424
598
  aggregate: (tableName: string, options: AggregateOptions) => Promise<AggregateResult>;
425
599
  asId?: (tableName: string, id: string) => string;
600
+ assertPatchAllowed?: (id: string, expectedTable?: string) => Promise<void>;
601
+ cdcChangedTables?: (sinceSeq: number, options?: {
602
+ cursorOnly?: boolean;
603
+ }) => Promise<{
604
+ cursor: number;
605
+ floor?: number;
606
+ tables: string[];
607
+ } | undefined>;
426
608
  count: (tableName: string, where?: RestrictableQueryOptions | WhereInput) => Promise<number>;
427
609
  delete: (id: string, expectedTable?: string, options?: {
428
610
  hard?: boolean;
@@ -438,11 +620,13 @@ interface DatabaseWriterLike {
438
620
  }, expectedTable?: string) => Promise<{
439
621
  deleted: number;
440
622
  }>;
623
+ deleteRereadTables?: ReadonlySet<string>;
441
624
  deleteWhere?: (tableName: string, where: WhereInput, options?: {
442
625
  limit?: number;
443
626
  }) => Promise<{
444
627
  deleted: number;
445
628
  }>;
629
+ explain: (tableName: string, args?: QueryArgs) => Promise<QueryPlan>;
446
630
  findFirst: (tableName: string, args?: QueryArgs) => Promise<Record<string, unknown> | null>;
447
631
  findFirstOrThrow: (tableName: string, args?: QueryArgs) => Promise<Record<string, unknown>>;
448
632
  findMany: (tableName: string, args?: QueryArgs) => Promise<QueryPage>;
@@ -460,12 +644,21 @@ interface DatabaseWriterLike {
460
644
  allowExplicitId?: boolean;
461
645
  limit?: number;
462
646
  }) => Promise<string[]>;
647
+ inTransaction?: () => boolean;
463
648
  lookupById?: (id: string, expectedTable?: string) => Promise<null | {
464
649
  row: Record<string, unknown>;
465
650
  tableName: string;
466
651
  }>;
467
652
  normalizeId: (tableName: string, id: string) => null | string;
468
- patch: (id: string, patch: Record<string, unknown>, expectedTable?: string) => Promise<void>;
653
+ patch: (id: string, patch: Record<string, unknown>, expectedTable?: string, options?: PatchWriteOptions) => Promise<void>;
654
+ patchIf?: (tableName: string, id: string, args: {
655
+ patch: Record<string, unknown>;
656
+ verify?: PatchVerifier;
657
+ where: WhereInput;
658
+ }) => Promise<{
659
+ applied: boolean;
660
+ doc: Record<string, unknown> | null;
661
+ }>;
469
662
  patchMany?: (patches: ReadonlyArray<{
470
663
  id: string;
471
664
  patch: Record<string, unknown>;
@@ -487,10 +680,14 @@ interface DatabaseWriterLike {
487
680
  rankBefore?: (tableName: string, indexName: string, options: RankBeforeOptions) => Promise<RankBeforeResult>;
488
681
  rankPage: (tableName: string, indexName: string, options?: RankPageOptions) => Promise<RankPage>;
489
682
  rankPageRows?: (tableName: string, indexName: string, options?: RankPageOptions) => Promise<ShardRankPageResult>;
683
+ related?: (start: RelatedStart, options?: RelatedOptions) => Promise<RelatedPage>;
684
+ relationEdges?: ReadonlyArray<RelationEdge>;
685
+ relationWrites?: RelationWriteMap;
490
686
  replace: (id: string, document: Record<string, unknown>, expectedTable?: string, options?: {
491
687
  allowExplicitId?: boolean;
492
688
  }) => Promise<void>;
493
689
  restore?: (id: string, expectedTable?: string) => Promise<void>;
690
+ softDeleteFields?: ReadonlyMap<string, string>;
494
691
  system?: SystemDatabaseReader;
495
692
  wipeShard?: (options?: {
496
693
  chunkSize?: number;
@@ -525,7 +722,6 @@ interface ImportShardResult {
525
722
  inserted: Record<string, number>;
526
723
  }
527
724
  declare const selectExportTables: (schema: SchemaLike, requested?: ReadonlyArray<string>) => string[];
528
- declare const exportShardTable: (writer: DatabaseWriterLike, table: string, batchSize?: number) => AsyncGenerator<ExportRow, void, undefined>;
529
725
  declare const exportShardRows: (writer: DatabaseWriterLike, schema: SchemaLike, args: ExportShardArgs) => AsyncGenerator<ExportRow, void, undefined>;
530
726
  declare const validateImportRow: (schema: SchemaLike, table: string, record: Record<string, unknown>) => string | undefined;
531
727
  declare const importShardRows: (writer: DatabaseWriterLike, schema: SchemaLike, args: ImportShardArgs) => Promise<ImportShardResult>;
@@ -573,8 +769,6 @@ declare const selectIndexForGroupBy: (indexes: ReadonlyArray<AggregateIndexDefin
573
769
  index: AggregateIndexDefinitionLike;
574
770
  partial: Record<string, unknown>;
575
771
  };
576
- declare const stableStringify: (value: unknown) => string;
577
- declare const stableWireKey: (value: unknown) => string;
578
772
  interface CacheEntry {
579
773
  bytes: number;
580
774
  deps: Set<string>;
@@ -600,6 +794,7 @@ declare class ReactiveCache {
600
794
  private readonly maxBytes;
601
795
  private readonly now;
602
796
  private monotonic;
797
+ private generation;
603
798
  constructor(options?: ReactiveCacheOptions);
604
799
  run<R>(key: string, deps: Set<string>, run: () => Promise<R>, ranges?: () => ReadonlyArray<KeyRange>): Promise<R>;
605
800
  invalidate(table: string, id: string, indexKeys?: ReadonlyArray<IndexKeyEntry>): string[];
@@ -660,12 +855,18 @@ interface RunTriggersOptions {
660
855
  }
661
856
  declare const runTriggers: (options: RunTriggersOptions) => Promise<void>;
662
857
  declare const hasTrigger: (schema: SchemaLike, tableName: string, op: TriggerOpLike) => boolean;
858
+ interface SearchBackfillProgress {
859
+ done: boolean;
860
+ pages: number;
861
+ }
663
862
  declare const backfillAggregateIndexes: (sql: SqlExec, schema: SchemaLike) => void;
664
863
  declare const backfillRankIndexes: (sql: SqlExec, schema: SchemaLike) => void;
665
864
  declare const backfillSearchIndexesForTable: (sql: SqlExec, tableName: string, definition: {
666
865
  searchIndexes?: ReadonlyArray<SearchIndexDefinitionLike>;
667
866
  }) => void;
668
- declare const backfillSearchIndexes: (sql: SqlExec, schema: SchemaLike) => void;
867
+ declare const backfillSearchIndexes: (sql: SqlExec, schema: SchemaLike, options?: {
868
+ maxPages?: number;
869
+ }) => SearchBackfillProgress;
669
870
  declare const CDC_LOG_TABLE = "__cdc_log";
670
871
  interface CdcChange {
671
872
  doc?: Record<string, unknown>;
@@ -675,19 +876,35 @@ interface CdcChange {
675
876
  table: string;
676
877
  ts: number;
677
878
  }
678
- declare const migrateCdcLog: (sql: SqlExec) => void;
879
+ declare const CDC_LOG_TABLE_SEQ_INDEX = "__cdc_log_table_seq";
880
+ declare const migrateCdcLog: (sql: SqlExec, options?: {
881
+ rowHistoryIndex?: boolean;
882
+ }) => void;
679
883
  declare const appendCdcChange: (sql: SqlExec, ts: number, table: string, id: string, op: CdcChange["op"], doc: Record<string, unknown> | undefined) => void;
680
884
  declare const readCdcChanges: (sql: SqlExec, options?: {
681
885
  limit?: number;
682
886
  sinceSeq?: number;
683
- tables?: ReadonlySet<string>;
684
887
  }) => {
685
888
  changes: CdcChange[];
686
889
  cursor: number;
687
890
  };
688
- declare const trimCdcChanges: (sql: SqlExec, throughSeq: number) => void;
891
+ declare const cdcTouchesTables: (sql: SqlExec, sinceSeq: number, tables: ReadonlySet<string>) => boolean;
892
+ declare const cdcCanVouchFor: (sql: SqlExec, deps: ReadonlySet<string>) => boolean;
893
+ interface CdcChangeKey {
894
+ id: string;
895
+ op: CdcChange["op"];
896
+ seq: number;
897
+ }
898
+ declare const readCdcChangeKeys: (sql: SqlExec, table: string, sinceSeq: number, upTo: number) => CdcChangeKey[];
899
+ declare const trimCdcChanges: (sql: SqlExec, throughSeq: number, maxRows: number) => void;
900
+ declare const compactCdcDocs: (sql: SqlExec, throughSeq: number, maxRows: number) => void;
901
+ declare const cdcSeqLeavingRows: (sql: SqlExec, keep: number) => number | undefined;
689
902
  declare const readCdcCursor: (sql: SqlExec) => number;
903
+ declare const cursorBelowRetainedFloor: (floor: number | undefined, sinceSeq: number) => boolean;
904
+ declare const cdcTrimmedError: (floor: number, sinceSeq: number, scope: "global" | "shard") => LunoraError;
905
+ declare const cdcForkedError: (cursor: number, sinceSeq: number, scope: "global" | "shard", epoch?: string) => LunoraError;
690
906
  declare const minCdcSeq: (sql: SqlExec) => number | undefined;
907
+ declare const minCdcReplayableSeq: (sql: SqlExec) => number | undefined;
691
908
  declare const CDC_META_TABLE = "__cdc_meta";
692
909
  declare const migrateCdcMeta: (sql: SqlExec) => void;
693
910
  declare const readCdcEpoch: (sql: SqlExec) => string;
@@ -697,12 +914,6 @@ declare const CLIENT_WATERMARK_TABLE = "__client_watermark";
697
914
  declare const migrateClientWatermark: (sql: SqlExec) => void;
698
915
  declare const readClientWatermark: (sql: SqlExec, identity: string, clientId: string) => number;
699
916
  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
917
  declare const IDEMPOTENCY_TABLE = "__idempotency";
707
918
  interface IdempotentRecord {
708
919
  resultJson: string;
@@ -714,55 +925,25 @@ declare const writeIdempotent: (sql: SqlExec, identity: string, mutationId: stri
714
925
  declare const trimIdempotent: (sql: SqlExec, olderThanTs: number) => void;
715
926
  declare const runShardMigrations: (sql: SqlExec, schema: SchemaLike, options?: {
716
927
  cdc?: boolean;
928
+ deferBlockedUniqueIndexes?: boolean;
717
929
  schemaSnapshot?: {
718
930
  hash: string;
719
931
  json: string;
720
932
  };
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;
933
+ }) => ReadonlyArray<string>;
755
934
  interface ShapeRow {
756
935
  doc: Record<string, unknown>;
757
936
  id: string;
758
937
  }
759
938
  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>;
939
+ declare const selectShapeMembers: (sql: SqlExec, table: string, effectiveWhere: WhereInput | undefined, ids: ReadonlyArray<string>) => Map<string, Record<string, unknown>>;
761
940
  interface SqlExec {
762
941
  exec: <Row = Record<string, unknown>>(sql: string, ...params: unknown[]) => SqlCursor<Row>;
763
942
  }
764
943
  interface SqlCursor<Row> extends Iterable<Row> {
944
+ readonly columnNames?: string[];
765
945
  one: () => Row;
946
+ raw?: () => IterableIterator<unknown[]>;
766
947
  toArray: () => Row[];
767
948
  }
768
949
  type IndexUseHook = (table: string, indexName: string, kind: "geo" | "index" | "rank" | "search") => void;
@@ -778,6 +959,7 @@ interface WriteEvent {
778
959
  type WriteHook = (event: WriteEvent) => Promise<void> | void;
779
960
  interface CtxDbOptions {
780
961
  auth?: ServerDefaultContextLike["auth"];
962
+ baselineSeq?: () => number | undefined;
781
963
  broadcast?: BroadcastDelta;
782
964
  cache?: ReactiveCache;
783
965
  cdc?: boolean;
@@ -786,10 +968,16 @@ interface CtxDbOptions {
786
968
  globalDb?: DatabaseWriterLike;
787
969
  headroom?: TransactionHeadroomTracker;
788
970
  idGenerator?: IdGenerator;
971
+ inTransaction?: () => boolean;
789
972
  maxRelationKeys?: number;
790
973
  onIndexUse?: IndexUseHook;
791
974
  onRead?: ReadHook;
792
975
  onReadRange?: (range: KeyRange) => void;
976
+ onStalePatchDropped?: (event: {
977
+ fields: string[];
978
+ id: string;
979
+ table: string;
980
+ }) => void;
793
981
  onWrite?: WriteHook;
794
982
  relationExistsPushDown?: "always" | "auto" | "never";
795
983
  scheduler?: SchedulerLike;
@@ -802,6 +990,8 @@ declare class NotUniqueError extends LunoraError {
802
990
  constructor(message?: string);
803
991
  }
804
992
  declare const normalizeIdStructurally: (schema: SchemaLike, tableName: string, id: string) => null | string;
993
+ declare const assertNoExplicitUndefined: (op: "patch" | "patchIf" | "replace", document: Record<string, unknown>) => void;
994
+ declare const stripReservedPatchFields: (patch: Record<string, unknown>) => Record<string, unknown>;
805
995
  declare const createShardCtxDb: (options: CtxDbOptions) => DatabaseWriterLike;
806
996
  declare const AUDIT_LOG_TABLE = "__lunora_audit__";
807
997
  interface AuditEntry {
@@ -825,68 +1015,24 @@ declare const readAuditLog: (sql: SqlExec, options?: {
825
1015
  limit?: number;
826
1016
  sinceSeq?: number;
827
1017
  }) => 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
- }
1018
+ interface CdcArchiveScope {
1019
+ epoch: string;
1020
+ shard: string;
1021
+ }
1022
+ declare const readCdcArchivedThrough: (sql: SqlExec) => number;
1023
+ declare const writeCdcArchivedThrough: (sql: SqlExec, seq: number) => void;
1024
+ declare const archiveCdcSegment: (bucket: R2BucketLike, scope: CdcArchiveScope, changes: CdcChange[]) => Promise<void>;
1025
+ declare const cdcArchiveRewound: (bucket: R2BucketLike, scope: CdcArchiveScope, archivedThrough: number) => Promise<boolean>;
1026
+ declare const readArchivedCdcChanges: (bucket: R2BucketLike, scope: CdcArchiveScope, sinceSeq: number, limit: number | undefined) => Promise<{
1027
+ changes: CdcChange[];
1028
+ cursor: number;
1029
+ } | undefined>;
1030
+ declare const COMMIT_SEQ_TABLE = "__commit_seq";
1031
+ declare const COMMIT_SEQ_FIELD = "_commitSeq";
1032
+ declare const migrateCommitSeq: (sql: SqlExec) => void;
1033
+ declare const readCommitSeq: (sql: SqlExec) => number;
1034
+ declare const allocateCommitSeq: (sql: SqlExec) => number;
1035
+ declare const clearCompanionSignatures: (sql: SqlExec) => void;
890
1036
  interface CompanionSyncDeps {
891
1037
  broadcast: (delta: MutationDelta) => void;
892
1038
  indexKeysFor: (table: string, document?: Record<string, unknown>) => ReadonlyArray<{
@@ -910,6 +1056,19 @@ interface CompanionSync {
910
1056
  syncSearch: (tableName: string, id: string, document: Record<string, unknown> | undefined, previous?: Record<string, unknown>) => void;
911
1057
  }
912
1058
  declare const createCompanionSync: (deps: CompanionSyncDeps) => CompanionSync;
1059
+ declare const GLOBAL_SHAPE_SNAPSHOT_TABLE = "__global_shape_snapshot";
1060
+ declare const migrateGlobalShapeSnapshot: (sql: SqlExec) => void;
1061
+ declare const readGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string) => Map<string, string> | undefined;
1062
+ declare const writeGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string, snapshot: Map<string, string>) => void;
1063
+ declare const deleteGlobalShapeSnapshot: (sql: SqlExec, connectionId: string, subId: string) => void;
1064
+ declare const deleteGlobalShapeSnapshotsForConnection: (sql: SqlExec, connectionId: string) => void;
1065
+ declare const isMemoryTable: (definition: TableDefinitionLike | undefined) => boolean;
1066
+ declare const memoryTableNames: (schema: SchemaLike) => string[];
1067
+ declare const clearMemoryTables: (sql: SqlExec, schema: SchemaLike) => number;
1068
+ declare const resolveRankSeekTuple: (options: {
1069
+ after?: RankPageRowKey;
1070
+ cursor?: null | string;
1071
+ }) => unknown[] | undefined;
913
1072
  interface RankPageDeps {
914
1073
  assertRankPartitionLocal: (tableName: string, definition: TableDefinitionLike, index: RankIndexDefinitionLike) => void;
915
1074
  ensureRankBackfilled: (tableName: string, index: RankIndexDefinitionLike) => void;
@@ -927,8 +1086,68 @@ interface RankPageComputation {
927
1086
  key: RankPageRowKey;
928
1087
  }[];
929
1088
  }
930
- declare const hydrateDocsById: (deps: RankPageDeps, tableName: string, ids: ReadonlyArray<string>) => Map<string, Record<string, unknown>>;
931
1089
  declare const computeRankPage: (deps: RankPageDeps, tableName: string, indexName: string, rankPageOptions: RankPageOptions) => RankPageComputation;
1090
+ declare const SCHEDULE_OUTBOX_TABLE = "__schedule_outbox";
1091
+ interface ScheduleOutboxRow {
1092
+ attempts: number;
1093
+ envelopeJson: string;
1094
+ id: string;
1095
+ nextAttemptAt: number;
1096
+ }
1097
+ interface ScheduleOutboxEnvelope {
1098
+ args: unknown;
1099
+ options: Record<string, unknown> | undefined;
1100
+ target: unknown;
1101
+ when: number;
1102
+ }
1103
+ interface ScheduleOutbox {
1104
+ admit: (target: string) => number | undefined;
1105
+ forget: (id: string) => void;
1106
+ record: (id: string, envelope: ScheduleOutboxEnvelope) => void;
1107
+ wake: () => void;
1108
+ }
1109
+ declare const migrateScheduleOutbox: (sql: SqlExec) => void;
1110
+ declare const recordScheduleOutbox: (sql: SqlExec, id: string, envelopeJson: string, now: number) => void;
1111
+ declare const forgetScheduleOutbox: (sql: SqlExec, id: string) => void;
1112
+ declare const readDueScheduleOutbox: (sql: SqlExec, nowMs: number, limit: number) => ScheduleOutboxRow[];
1113
+ declare const deferScheduleOutbox: (sql: SqlExec, id: string, attempts: number, nextAttemptAt: number) => void;
1114
+ declare const parkScheduleOutbox: (sql: SqlExec, id: string, attempts: number) => void;
1115
+ declare const probeScheduleOutbox: (sql: SqlExec) => {
1116
+ dueAt: number | undefined;
1117
+ populated: boolean;
1118
+ };
1119
+ declare const trimScheduleOutbox: (sql: SqlExec, olderThanTs: number) => void;
1120
+ /**
1121
+ * How far a companion's backfill has progressed, and under which analysis.
1122
+ * Declared here rather than beside either engine's state table: both record the
1123
+ * same three facts, and the decisions made from them are the shared policy
1124
+ * below.
1125
+ */
1126
+ interface BackfillState {
1127
+ /** Last `id` indexed, or `undefined` when no page has run yet. */
1128
+ cursor: string | undefined;
1129
+ /** True once a page came back short — the table is fully indexed. */
1130
+ done: boolean;
1131
+ /** Analyzer profile the stored rows were built with; `undefined` predates profile tracking. */
1132
+ profile: string | undefined;
1133
+ }
1134
+ declare const SEARCH_STATE_TABLE = "__lunora_search_state";
1135
+ declare const migrateSearchState: (sql: SqlExec) => void;
1136
+ declare const readSearchBackfillState: (sql: SqlExec, companion: string) => BackfillState;
1137
+ declare const writeSearchBackfillState: (sql: SqlExec, companion: string, cursor: string | undefined, done: boolean, profile: string) => void;
1138
+ declare const SHAPE_POKE_CURSOR_TABLE = "__shape_poke_cursor";
1139
+ declare const migrateShapePokeCursor: (sql: SqlExec) => void;
1140
+ declare const readShapePokeCursor: (sql: SqlExec, connectionId: string, subId: string) => number | undefined;
1141
+ declare const writeShapePokeCursor: (sql: SqlExec, connectionId: string, subId: string, cursor: number) => void;
1142
+ interface ShapePokeCursorRow {
1143
+ connectionId: string;
1144
+ cursor: number;
1145
+ subId: string;
1146
+ }
1147
+ declare const writeShapePokeCursors: (sql: SqlExec, rows: ReadonlyArray<ShapePokeCursorRow>) => void;
1148
+ declare const minShapePokeCursor: (sql: SqlExec) => number | undefined;
1149
+ declare const deleteShapePokeCursor: (sql: SqlExec, connectionId: string, subId: string) => void;
1150
+ declare const deleteShapePokeCursorsForConnection: (sql: SqlExec, connectionId: string) => void;
932
1151
  declare const DATA_MIGRATION_STATE_TABLE = "__lunora_migrations";
933
1152
  type MigrationDirection = "down" | "up";
934
1153
  type MigrationStatus = "completed" | "failed" | "in_progress";
@@ -992,6 +1211,29 @@ interface DependencyTracker {
992
1211
  declare const createDependencyTracker: () => DependencyTracker;
993
1212
  declare const runSql: <Row = Record<string, unknown>>(sql: SqlExec, query: string, ...params: unknown[]) => SqlCursor<Row>;
994
1213
  declare const runDrizzle: <Row = Record<string, unknown>>(exec: SqlExec, query: SQL) => SqlCursor<Row>;
1214
+ type RangeOperandType = "boolean" | "number" | "string";
1215
+ interface WhereFragments<T> {
1216
+ binary: (reference: T, comparator: string, value: unknown) => T;
1217
+ connect: (left: T, right: T, connector: "AND" | "OR") => T;
1218
+ constant: (value: boolean) => T;
1219
+ contains: (reference: T, term: T) => T;
1220
+ inList: (reference: T, items: ReadonlyArray<unknown>, negated: boolean, budget: number) => T;
1221
+ negate: (inner: T) => T;
1222
+ nullCheck: (reference: T, negated: boolean) => T;
1223
+ value: (value: unknown) => T;
1224
+ }
1225
+ type FieldRefSql<T> = (field: string) => T;
1226
+ type SerializeValue = (value: unknown, field: string) => unknown;
1227
+ interface WhereSqlStrategy<T = SQL> {
1228
+ containsExpr?: (reference: T, term: T) => T;
1229
+ fieldRef: FieldRefSql<T>;
1230
+ inList?: (reference: T, items: ReadonlyArray<unknown>, negated: boolean, budget?: number) => T;
1231
+ rangeTypeGuard: (field: string, type: RangeOperandType) => T;
1232
+ relationExists?: (request: unknown) => T;
1233
+ serialize: SerializeValue;
1234
+ }
1235
+ declare const serverInList: (engine: "mysql" | "postgres") => (reference: SQL, items: ReadonlyArray<unknown>, negated: boolean, budget?: number) => SQL;
1236
+ declare const compileWhereSql: <T = SQL>(where: WhereInput | undefined, strategy: WhereSqlStrategy<T>, fragments?: WhereFragments<T>, reservedParams?: number) => T | undefined;
995
1237
  declare const quoteIdentifier: (name: string) => string;
996
1238
  declare const serializeSqlValue: (value: unknown) => unknown;
997
1239
  declare const DOC_COLUMN = "__doc__";
@@ -1005,10 +1247,16 @@ declare const AGG_KEY: Name;
1005
1247
  declare const AGG_VALUE: Name;
1006
1248
  declare const AGG_COUNT: Name;
1007
1249
  declare const aggUpsertSql: (aggTable: string, key: unknown, value: unknown, count: unknown, set: SQL) => SQL;
1008
- declare const tableColumns: (definition: TableDefinitionLike) => [string, ColumnMetaLike][];
1250
+ declare const tableColumns: (definition: TableDefinitionLike) => ReadonlyArray<readonly [string, ColumnMetaLike]>;
1009
1251
  declare const rowToDocument: (row: Record<string, unknown> | undefined) => Record<string, unknown> | undefined;
1010
1252
  declare const tryRowToDocument: (row: Record<string, unknown> | undefined) => Record<string, unknown> | undefined;
1011
1253
  declare const isFtsAvailable: (sql: SqlExec) => boolean;
1254
+ declare const WORKERD_SQLITE_LIMITS: {
1255
+ readonly boundParams: 100;
1256
+ readonly compoundSelect: 5;
1257
+ readonly likePattern: 50;
1258
+ readonly sqlTextLength: 100000;
1259
+ };
1012
1260
  type SqlEngine = "mysql" | "postgres" | "sqlite";
1013
1261
  interface RenderedSql {
1014
1262
  params: unknown[];
@@ -1016,6 +1264,79 @@ interface RenderedSql {
1016
1264
  }
1017
1265
  declare const renderSql: (engine: SqlEngine, query: SQL) => RenderedSql;
1018
1266
  declare const param: (value: unknown) => SQL;
1267
+ declare const unionAll: (branches: ReadonlyArray<SQL>) => SQL;
1268
+ declare const sqliteInList: (reference: SQL, items: ReadonlyArray<unknown>, negated: boolean, budget?: number) => SQL;
1269
+ type DurableStreamStatus = "complete" | "error" | "running";
1270
+ interface DurableStreamRun {
1271
+ error?: string;
1272
+ errorCode?: string;
1273
+ lastSeq: number;
1274
+ startedAt: number;
1275
+ status: DurableStreamStatus;
1276
+ }
1277
+ interface DurableStreamChunk {
1278
+ dataJson: string;
1279
+ seq: number;
1280
+ }
1281
+ declare const migrateDurableStreams: (sql: SqlExec) => void;
1282
+ declare const readStreamRun: (sql: SqlExec, runKey: string) => DurableStreamRun | undefined;
1283
+ declare const claimStreamRun: (sql: SqlExec, runKey: string, startedAt: number, ttlMs: number) => boolean;
1284
+ declare const deleteStreamRun: (sql: SqlExec, runKey: string) => void;
1285
+ declare const appendStreamChunk: (sql: SqlExec, runKey: string, seq: number, dataJson: string) => void;
1286
+ declare const readStreamChunks: (sql: SqlExec, runKey: string, sinceSeq: number) => DurableStreamChunk[];
1287
+ declare const finishStreamRun: (sql: SqlExec, runKey: string, status: "complete" | "error", lastSeq: number, failure?: {
1288
+ code: string;
1289
+ message: string;
1290
+ }) => void;
1291
+ declare const trimStreamRuns: (sql: SqlExec, now: number, live: ReadonlySet<string>) => void;
1292
+ declare const MAX_DURABLE_STREAM_CHUNKS = 50000;
1293
+ declare const MAX_DURABLE_STREAM_BYTES: number;
1294
+ interface DurableStreamSink {
1295
+ readonly chunk: (chunk: {
1296
+ data: unknown;
1297
+ generation?: number;
1298
+ seq: number;
1299
+ }) => boolean;
1300
+ readonly complete: () => void;
1301
+ readonly fail: (failure: {
1302
+ code: string;
1303
+ message: string;
1304
+ }) => void;
1305
+ }
1306
+ type DurableAttachDecision = "attach" | "interrupted" | "reclaim" | "replay-terminal";
1307
+ declare const decideDurableAttach: (run: DurableStreamRun | undefined, context: {
1308
+ generation?: number;
1309
+ live?: {
1310
+ generation: number;
1311
+ };
1312
+ resuming: boolean;
1313
+ }) => DurableAttachDecision;
1314
+ interface DurableStreamAttach {
1315
+ readonly generation?: number;
1316
+ readonly iterator: (signal: AbortSignal) => AsyncIterable<unknown>;
1317
+ readonly runKey: string;
1318
+ readonly sinceChunk: number;
1319
+ readonly sink: DurableStreamSink;
1320
+ readonly ttlMs?: number;
1321
+ }
1322
+ declare class DurableStreamRunner {
1323
+ private lastTrimAt;
1324
+ private readonly runs;
1325
+ private readonly sql;
1326
+ private readonly waitUntil;
1327
+ constructor(dependencies: {
1328
+ sql: () => SqlExec;
1329
+ waitUntil?: (promise: Promise<unknown>) => void;
1330
+ });
1331
+ attach(request: DurableStreamAttach): Promise<void>;
1332
+ detach(runKey: string, sink: DurableStreamSink): void;
1333
+ isLive(runKey: string): boolean;
1334
+ private attachOrThrow;
1335
+ private produce;
1336
+ private trim;
1337
+ }
1338
+ declare const envPositiveInt: (env: unknown, key: string, fallback: number) => number;
1339
+ declare const envOptionalPositiveInt: (env: unknown, key: string) => number | undefined;
1019
1340
  interface ExternalSourceDiffResult {
1020
1341
  changes: CdcChange[];
1021
1342
  nextBaseline: Map<string, string>;
@@ -1080,6 +1401,16 @@ declare const isSoftDeleted: (row: Record<string, unknown>, column: string) => b
1080
1401
  declare const pullExternalSourceIncrementalTick: (sql: SqlExec, writer: DatabaseWriterLike, client: SourceClientLike, table: string, source: ExternalSourceLike, shardKey: string, nowMs: number) => Promise<{
1081
1402
  applied: number;
1082
1403
  }>;
1404
+ declare const ftsRowidMapName: (companion: string) => string;
1405
+ interface FtsWriteOptions {
1406
+ guard?: SQL;
1407
+ unmappedRowids?: ReadonlyArray<number>;
1408
+ }
1409
+ declare const ftsCompanionDdl: (companion: string) => SQL[];
1410
+ declare const ftsWriteDocument: (companion: string, id: string, text: string, options?: FtsWriteOptions) => SQL[];
1411
+ declare const ftsPurgeDocument: (companion: string, id: string, options?: FtsWriteOptions) => SQL[];
1412
+ declare const ftsUnmappedPage: (companion: string, limit: number, after?: number) => SQL;
1413
+ declare const groupUnmappedRows: (rows: ReadonlyArray<Record<string, unknown>>) => Map<string, number[]>;
1083
1414
  declare const GEO_DEFAULT_PRECISION = 9;
1084
1415
  interface GeoPoint {
1085
1416
  lat: number;
@@ -1095,6 +1426,20 @@ declare const coveringGeohashes: (center: GeoPoint, radiusMeters: number) => str
1095
1426
  declare const pointInBoundingBox: (point: GeoPoint, box: GeoBoundingBox) => boolean;
1096
1427
  declare const boundingBoxCenter: (box: GeoBoundingBox) => GeoPoint;
1097
1428
  declare const boundingBoxGeohashes: (box: GeoBoundingBox) => string[];
1429
+ declare class GlobalPollTick {
1430
+ private readonly changedTables;
1431
+ private readonly reads;
1432
+ private resync;
1433
+ private skippedCount;
1434
+ constructor(changedTables?: Set<string>);
1435
+ get readCount(): number;
1436
+ get resyncRequested(): boolean;
1437
+ get skipped(): number;
1438
+ requestResync(): void;
1439
+ rows(key: string | undefined, load: () => Promise<ShapeRow[]>): Promise<ShapeRow[]>;
1440
+ shouldRead(table: string): boolean;
1441
+ }
1442
+ declare const isInternalTableName: (name: string) => boolean;
1098
1443
  declare const ADMIN_FUNCTION_PREFIX = "__lunora_admin__:";
1099
1444
  declare const RELATION_FUNCTION_PREFIX = "__lunora_relation__:";
1100
1445
  declare const FLAGS_FUNCTION_PREFIX = "__lunora_flags__:";
@@ -1105,6 +1450,8 @@ declare const ADMIN_FUNCTIONS: {
1105
1450
  readonly aiGenerateSql: "__lunora_admin__:aiGenerateSql";
1106
1451
  readonly aiTableFilter: "__lunora_admin__:aiTableFilter";
1107
1452
  readonly assignIssue: "__lunora_admin__:assignIssue";
1453
+ readonly backfillSearch: "__lunora_admin__:backfillSearch";
1454
+ readonly backfillVectors: "__lunora_admin__:backfillVectors";
1108
1455
  readonly backRelationCounts: "__lunora_admin__:backRelationCounts";
1109
1456
  readonly cdcSync: "__lunora_admin__:cdcSync";
1110
1457
  readonly clearCapturedMail: "__lunora_admin__:clearCapturedMail";
@@ -1117,6 +1464,7 @@ declare const ADMIN_FUNCTIONS: {
1117
1464
  readonly explainIssue: "__lunora_admin__:explainIssue";
1118
1465
  readonly exportShard: "__lunora_admin__:exportShard";
1119
1466
  readonly facetColumn: "__lunora_admin__:facetColumn";
1467
+ readonly findRelated: "__lunora_admin__:findRelated";
1120
1468
  readonly getAdvisories: "__lunora_admin__:getAdvisories";
1121
1469
  readonly getAdvisorProcedures: "__lunora_admin__:getAdvisorProcedures";
1122
1470
  readonly getAuditLog: "__lunora_admin__:getAuditLog";
@@ -1143,20 +1491,24 @@ declare const ADMIN_FUNCTIONS: {
1143
1491
  readonly ignoreIssue: "__lunora_admin__:ignoreIssue";
1144
1492
  readonly importShard: "__lunora_admin__:importShard";
1145
1493
  readonly listFlags: "__lunora_admin__:listFlags";
1494
+ readonly listReactors: "__lunora_admin__:listReactors";
1146
1495
  readonly listQueues: "__lunora_admin__:listQueues";
1147
1496
  readonly lintSql: "__lunora_admin__:lintSql";
1148
1497
  readonly listTables: "__lunora_admin__:listTables";
1149
1498
  readonly listWorkflows: "__lunora_admin__:listWorkflows";
1150
1499
  readonly maskPolicies: "__lunora_admin__:maskPolicies";
1151
1500
  readonly migrationStatus: "__lunora_admin__:migrationStatus";
1501
+ readonly patchRows: "__lunora_admin__:patchRows";
1152
1502
  readonly pitrRestore: "__lunora_admin__:pitrRestore";
1153
1503
  readonly rankBefore: "__lunora_admin__:rankBefore";
1154
1504
  readonly rankPage: "__lunora_admin__:rankPage";
1155
1505
  readonly readTablePage: "__lunora_admin__:readTablePage";
1506
+ readonly rebuildCompanions: "__lunora_admin__:rebuildCompanions";
1156
1507
  readonly recordAuthEvent: "__lunora_admin__:recordAuthEvent";
1157
1508
  readonly recordContainerEvent: "__lunora_admin__:recordContainerEvent";
1158
1509
  readonly recordMail: "__lunora_admin__:recordMail";
1159
1510
  readonly recordQueueMessage: "__lunora_admin__:recordQueueMessage";
1511
+ readonly releaseShardRegistration: "__lunora_admin__:releaseShardRegistration";
1160
1512
  readonly replayQueueMessage: "__lunora_admin__:replayQueueMessage";
1161
1513
  readonly resolveIssue: "__lunora_admin__:resolveIssue";
1162
1514
  readonly rlsPolicies: "__lunora_admin__:rlsPolicies";
@@ -1226,8 +1578,12 @@ interface TablesIndexesResult {
1226
1578
  indexesByTable: Record<string, TableIndexInfo[]>;
1227
1579
  }
1228
1580
  interface ColumnMeta {
1581
+ bucket?: string;
1582
+ enumValues?: string[];
1229
1583
  isStorage?: boolean;
1230
1584
  name: string;
1585
+ nullable?: boolean;
1586
+ onDelete?: "cascade" | "restrict" | "set null";
1231
1587
  optional: boolean;
1232
1588
  pk?: boolean;
1233
1589
  ref?: string;
@@ -1324,6 +1680,12 @@ interface StudioFeaturesResult {
1324
1680
  mail: boolean;
1325
1681
  notifications: boolean;
1326
1682
  payments: boolean;
1683
+ platform?: {
1684
+ id: string;
1685
+ name: string;
1686
+ unsupported: string[];
1687
+ };
1688
+ privacy: boolean;
1327
1689
  queues: boolean;
1328
1690
  scheduler: boolean;
1329
1691
  storage: boolean;
@@ -1342,8 +1704,20 @@ interface FlagsResult {
1342
1704
  configured: boolean;
1343
1705
  flags: FlagEvaluation[];
1344
1706
  }
1707
+ interface ReactorMetadata {
1708
+ errors: number;
1709
+ lastError?: string;
1710
+ lastRanAt?: number;
1711
+ path: string;
1712
+ runs: number;
1713
+ state: "active" | "failing" | "idle";
1714
+ suppressed: number;
1715
+ tables?: ReadonlyArray<string>;
1716
+ }
1717
+ interface ReactorsResult {
1718
+ reactors: ReactorMetadata[];
1719
+ }
1345
1720
  interface WorkflowMetadata {
1346
- binding: string;
1347
1721
  className: string;
1348
1722
  exportName: string;
1349
1723
  name: string;
@@ -1357,11 +1731,12 @@ interface QueueMetadata {
1357
1731
  exportName: string;
1358
1732
  mode: "pull" | "push";
1359
1733
  name: string;
1734
+ topic?: string;
1360
1735
  }
1361
1736
  interface QueuesResult {
1362
1737
  queues: QueueMetadata[];
1363
1738
  }
1364
- type WorkflowInstanceState = "complete" | "errored" | "paused" | "queued" | "running" | "terminated" | "unknown" | "waiting" | "waitingForPause";
1739
+ type WorkflowInstanceState = "complete" | "errored" | "paused" | "queued" | "rollingBack" | "running" | "terminated" | "unknown" | "waiting" | "waitingForPause";
1365
1740
  interface CreateWorkflowInstanceResult {
1366
1741
  id: string;
1367
1742
  status: WorkflowInstanceState;
@@ -1400,8 +1775,10 @@ interface TablePage {
1400
1775
  columns: string[];
1401
1776
  refs?: Record<string, string>;
1402
1777
  rows: Record<string, unknown>[];
1778
+ sqlColumns: string[];
1403
1779
  total?: number;
1404
1780
  }
1781
+ type ColumnKinds = Readonly<Record<string, string>>;
1405
1782
  type FilterOperator = "contains" | "eq" | "gt" | "gte" | "lt" | "lte" | "ne";
1406
1783
  interface FilterClause {
1407
1784
  column: string;
@@ -1413,6 +1790,7 @@ interface OrderByClause {
1413
1790
  direction: SortDirection;
1414
1791
  }
1415
1792
  interface ReadTablePageOptions {
1793
+ columnKinds?: ColumnKinds;
1416
1794
  filters?: FilterClause[];
1417
1795
  limit?: number;
1418
1796
  offset?: number;
@@ -1423,6 +1801,8 @@ interface ReadTablePageOptions {
1423
1801
  table: string;
1424
1802
  }
1425
1803
  interface SelectMatchingIdsOptions {
1804
+ after?: string;
1805
+ columnKinds?: ColumnKinds;
1426
1806
  filters?: FilterClause[];
1427
1807
  limit?: number;
1428
1808
  search?: string;
@@ -1430,6 +1810,7 @@ interface SelectMatchingIdsOptions {
1430
1810
  }
1431
1811
  interface FacetColumnOptions {
1432
1812
  column: string;
1813
+ columnKinds?: ColumnKinds;
1433
1814
  filters?: FilterClause[];
1434
1815
  limit?: number;
1435
1816
  search?: string;
@@ -1445,6 +1826,7 @@ interface FacetColumnResult {
1445
1826
  }
1446
1827
  declare const MAX_PAGE_SIZE = 500;
1447
1828
  declare const listTables: (sql: SqlExec) => TableInfo[];
1829
+ declare const isVacuousFilterClause: (clause: FilterClause) => boolean;
1448
1830
  declare const readTablePage: (sql: SqlExec, options: ReadTablePageOptions) => TablePage;
1449
1831
  declare const selectMatchingIds: (sql: SqlExec, options: SelectMatchingIdsOptions) => {
1450
1832
  hasMore: boolean;
@@ -1479,12 +1861,22 @@ interface FanoutPathCounters {
1479
1861
  socketsIterated: number;
1480
1862
  totalMs: number;
1481
1863
  }
1864
+ interface ShapeProbeCounters {
1865
+ run: number;
1866
+ served: number;
1867
+ }
1868
+ interface GlobalPollCounters {
1869
+ drains: number;
1870
+ pairsSkipped: number;
1871
+ }
1482
1872
  interface FanoutMetricsResult {
1873
+ globalPoll: GlobalPollCounters;
1483
1874
  maxRelays: number;
1484
1875
  peakSubscribers: number;
1485
1876
  promoted: boolean;
1486
1877
  relayCount: number;
1487
1878
  shapePoke: FanoutPathCounters;
1879
+ shapeProbe: ShapeProbeCounters;
1488
1880
  sinceMs: number;
1489
1881
  topics: FanoutTopicStat[];
1490
1882
  totalConnections: number;
@@ -1498,6 +1890,10 @@ interface FanoutAttachmentLike {
1498
1890
  }
1499
1891
  declare const DEFAULT_FANOUT_TOPIC_LIMIT = 20;
1500
1892
  declare const createFanoutCounters: () => FanoutPathCounters;
1893
+ declare const createShapeProbeCounters: () => ShapeProbeCounters;
1894
+ declare const createGlobalPollCounters: () => GlobalPollCounters;
1895
+ declare const recordGlobalPollPass: (counters: GlobalPollCounters, drains: number, pairsSkipped: number) => GlobalPollCounters;
1896
+ declare const recordShapeProbePass: (counters: ShapeProbeCounters, run: number, served: number) => ShapeProbeCounters;
1501
1897
  declare const recordFanoutPass: (counters: FanoutPathCounters, iterated: number, delivered: number, ms: number) => FanoutPathCounters;
1502
1898
  declare const summarizeFanoutTopics: (attachments: FanoutAttachmentLike[], limit?: number) => {
1503
1899
  peakSubscribers: number;
@@ -1545,6 +1941,11 @@ declare const clearCapturedMail: (sql: SqlExec) => {
1545
1941
  declare class NotFoundError extends LunoraError {
1546
1942
  constructor(message?: string);
1547
1943
  }
1944
+ declare const operatorFields: (definition: TableDefinitionLike, patch: Record<string, unknown>) => ReadonlySet<string>;
1945
+ declare const resolvePatch: (definition: TableDefinitionLike, patch: Record<string, unknown>, current: Record<string, unknown>) => Record<string, unknown>;
1946
+ declare const patchDependsOnRow: (definition: TableDefinitionLike, patch: Record<string, unknown>) => boolean;
1947
+ declare const assertPatchAllowed: (options: PatchWriteOptions | undefined, previous: Record<string, unknown>, next: Record<string, unknown>) => void;
1948
+ declare const readPatchField: (document: Record<string, unknown>, field: string) => unknown;
1548
1949
  interface PitrStorage {
1549
1950
  getBookmarkForTime?: (time: Date | number) => Promise<string>;
1550
1951
  getCurrentBookmark?: () => Promise<string>;
@@ -1566,7 +1967,22 @@ interface PitrRestoreArgs {
1566
1967
  }
1567
1968
  declare const readBookmark: (storage: PitrStorage, time?: number | string) => Promise<PitrBookmarkResult>;
1568
1969
  declare const armRestore: (storage: PitrStorage, args: PitrRestoreArgs) => Promise<Omit<PitrRestoreResult, "restarted">>;
1569
- declare const normalizeOrderKeys: (orderBy: OrderByInput[] | undefined) => OrderKey[];
1970
+ declare const tiebreakDirectionFor: (keys: ReadonlyArray<{
1971
+ direction?: string;
1972
+ }>) => SortDirection;
1973
+ declare const equalityPinnedFields: (where: undefined | WhereInput) => ReadonlySet<string>;
1974
+ declare const uniqueIndexFields: (indexes: ReadonlyArray<{
1975
+ fields: ReadonlyArray<string>;
1976
+ unique?: boolean;
1977
+ }> | undefined, shape: Record<string, ValidatorLike> | undefined) => ReadonlyArray<ReadonlyArray<string>>;
1978
+ interface OrderKeyConstraints {
1979
+ pinned?: ReadonlySet<string>;
1980
+ uniqueBy?: ReadonlyArray<ReadonlyArray<string>>;
1981
+ }
1982
+ declare const nullsFirstOf: (key: Pick<OrderKey, "direction" | "nulls">) => boolean;
1983
+ declare const nullsOrderSuffix: (nullsFirst: boolean) => string;
1984
+ declare const normalizeOrderKeys: (orderBy: OrderByInput[] | undefined, shape?: Record<string, ValidatorLike>, constraints?: OrderKeyConstraints) => OrderKey[];
1985
+ declare const CURSOR_PREFIX = "~4";
1570
1986
  declare const encodeCursor: (record: Record<string, unknown>, keys: OrderKey[]) => string;
1571
1987
  declare const decodeCursor: (cursor: string) => unknown[];
1572
1988
  declare const buildSeekWhere: (keys: OrderKey[], cursorValues: unknown[]) => WhereInput;
@@ -1626,7 +2042,36 @@ declare const rankKeyFromDocument: (index: RankIndexDefinitionLike, document_: R
1626
2042
  rowId: string;
1627
2043
  sortValues: unknown[];
1628
2044
  };
2045
+ declare const rankPivotConditionSql: (column: string, value: unknown, direction: "asc" | "desc", wantLater: boolean) => SQL | undefined;
1629
2046
  declare const matchesRankStaticWhere: (document: Record<string, unknown>, predicate: Record<string, unknown>) => boolean;
2047
+ declare const REACTOR_STATE_TABLE = "__reactor_state";
2048
+ interface ReactorState {
2049
+ digest: string;
2050
+ lastError?: string;
2051
+ lastRanAt: number;
2052
+ stats: ReactorStats;
2053
+ tables?: ReadonlyArray<string>;
2054
+ }
2055
+ interface ReactorStats {
2056
+ errors: number;
2057
+ runs: number;
2058
+ suppressed: number;
2059
+ }
2060
+ declare const migrateReactorState: (sql: SqlExec) => void;
2061
+ declare const readReactorState: (sql: SqlExec, path: string) => ReactorState | undefined;
2062
+ declare const listReactorStates: (sql: SqlExec) => {
2063
+ path: string;
2064
+ state: ReactorState;
2065
+ }[];
2066
+ type ReactorDispatchResult = "error" | "ran" | "suppressed";
2067
+ declare const writeReactorState: (sql: SqlExec, path: string, outcome: {
2068
+ digest?: string;
2069
+ error?: string;
2070
+ now: number;
2071
+ result: ReactorDispatchResult;
2072
+ tables?: ReadonlyArray<string>;
2073
+ }) => void;
2074
+ declare const reactorNeedsRun: (state: Pick<ReactorState, "tables"> | undefined, changed: ReadonlySet<string>) => boolean;
1630
2075
  interface ReadFootprint {
1631
2076
  onRead: (table: string, idOrScan?: string) => void;
1632
2077
  onReadRange: (range: KeyRange) => void;
@@ -1634,16 +2079,33 @@ interface ReadFootprint {
1634
2079
  tables: Set<string>;
1635
2080
  }
1636
2081
  declare const createReadFootprint: () => ReadFootprint;
2082
+ declare const UNVOUCHABLE_DEP = "!unvouchable";
2083
+ declare const markUnvouchableReads: <T extends object>(facade: T, onRead: ReadFootprint["onRead"] | undefined, methods: ReadonlyArray<string>) => T;
2084
+ declare const WHERE_FILTER: unique symbol;
2085
+ type RowPredicate = (document: Record<string, unknown>) => boolean;
2086
+ type WhereFilter = RowPredicate & {
2087
+ readonly [WHERE_FILTER]: WhereInput;
2088
+ };
2089
+ declare const whereFilter: (where: WhereInput, predicate: RowPredicate) => WhereFilter;
2090
+ declare const whereOfFilter: (predicate: RowPredicate) => undefined | WhereInput;
2091
+ declare const isPushableWhere: (where: WhereInput, shape: Readonly<Record<string, ValidatorLike>>, exactText?: boolean) => boolean;
2092
+ declare const RELATED_MAX_DEPTH = 4;
2093
+ declare const RELATED_DEFAULT_LIMIT = 50;
2094
+ declare const RELATED_MAX_LIMIT = 200;
2095
+ declare const RELATED_DEPTH_DECAY = 0.5;
2096
+ declare const deriveRelationEdges: (schema: SchemaLike) => RelationEdge[];
2097
+ type RelationGraphReader = Pick<DatabaseWriterLike, "findMany"> & Pick<Partial<DatabaseWriterLike>, "lookupById">;
2098
+ declare const findRelated: (reader: RelationGraphReader, edges: ReadonlyArray<RelationEdge>, start: RelatedStart, options?: RelatedOptions) => Promise<RelatedPage>;
1637
2099
  declare const DEFAULT_MAX_RELATION_KEYS = 5000;
1638
2100
  interface RelationExistsMarker {
1639
2101
  childWhere: WhereInput;
1640
2102
  negated: boolean;
1641
2103
  parentTable: string;
1642
- relation: RelationDefinitionLike;
2104
+ relation: KeyedRelationDefinitionLike;
1643
2105
  }
1644
2106
  type ExistsPushMode = "always" | "auto";
1645
2107
  interface ResolveRelationPredicatesOptions {
1646
- canPushExists?: (relation: RelationDefinitionLike) => boolean;
2108
+ canPushExists?: (relation: KeyedRelationDefinitionLike) => boolean;
1647
2109
  existsPushMode?: ExistsPushMode;
1648
2110
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
1649
2111
  maxRelationKeys?: number;
@@ -1654,7 +2116,7 @@ interface ResolveRelationPredicatesOptions {
1654
2116
  tableName: string;
1655
2117
  }
1656
2118
  interface ResolveContext {
1657
- canPushExists?: (relation: RelationDefinitionLike) => boolean;
2119
+ canPushExists?: (relation: KeyedRelationDefinitionLike) => boolean;
1658
2120
  existsPushMode: ExistsPushMode;
1659
2121
  fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
1660
2122
  maxRelationKeys: number;
@@ -1667,8 +2129,14 @@ declare const isRelationPredicate: (value: unknown) => value is Record<string, W
1667
2129
  declare const containsRelationPredicate: (where: WhereInput, schema: ResolveContext["schema"], tableName: string) => boolean;
1668
2130
  declare const assertFlatPredicate: (where: WhereInput | undefined, schema: ResolveContext["schema"], tableName: string, op: string) => void;
1669
2131
  declare const resolveRelationPredicates: (where: WhereInput | undefined, options: ResolveRelationPredicatesOptions) => Promise<WhereInput | undefined>;
2132
+ declare const composeReadPredicate: (definition: TableDefinitionLike, args: QueryArgs, relation: Omit<ResolveRelationPredicatesOptions, "relationBaseWhere">) => Promise<{
2133
+ fetchLimit: number | undefined;
2134
+ limit: number | undefined;
2135
+ orderKeys: OrderKey[];
2136
+ predicate: WhereInput | undefined;
2137
+ }>;
1670
2138
  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">;
2139
+ declare const relationHooks: (args: Pick<QueryArgs, "relationBaseWhere" | "relationMask">) => Pick<QueryArgs, "relationBaseWhere" | "relationMask"> & Pick<ResolveWithOptions, "fanOutBudget">;
1672
2140
  declare const fanOutScalarCounts: (counter: (tableName: string, where?: WhereInput) => Promise<number>, tableName: string, whereField: string, values: unknown[], policyWhere: WhereInput | undefined) => Promise<Map<unknown, number>>;
1673
2141
  declare const distinctValues: (rows: Record<string, unknown>[], field: string) => unknown[];
1674
2142
  declare const resolveWith: (options: ResolveWithOptions) => Promise<void>;
@@ -1685,7 +2153,15 @@ interface ApplyOnDeleteOptions {
1685
2153
  tableName: string;
1686
2154
  }
1687
2155
  declare const applyOnDelete: (options: ApplyOnDeleteOptions) => Promise<void>;
1688
- declare const runRowValidators: (definition: TableDefinitionLike, document: Record<string, unknown>, tolerateStoredNull?: boolean) => void;
2156
+ interface RowValidatorOptions {
2157
+ only?: ReadonlySet<string>;
2158
+ previous?: () => Readonly<Record<string, unknown>> | undefined;
2159
+ supplied?: Readonly<Record<string, unknown>>;
2160
+ tolerateStoredNull?: boolean;
2161
+ trusted?: boolean;
2162
+ }
2163
+ declare const applyInsertDefaults: (definition: TableDefinitionLike, document: Record<string, unknown>, auth: ServerDefaultContextLike["auth"]) => Record<string, unknown>;
2164
+ declare const runRowValidators: (definition: TableDefinitionLike, document: Record<string, unknown>, options?: RowValidatorOptions) => Record<string, unknown>;
1689
2165
  interface ShapeRowOp {
1690
2166
  key: string;
1691
2167
  op: "delete" | "insert" | "update";
@@ -1693,6 +2169,8 @@ interface ShapeRowOp {
1693
2169
  value?: Record<string, unknown>;
1694
2170
  }
1695
2171
  interface ShapePokePart {
2172
+ baseCheckpoint?: number;
2173
+ reset?: boolean;
1696
2174
  rowsPatch: ShapeRowOp[];
1697
2175
  shapeId: string;
1698
2176
  }
@@ -1727,15 +2205,18 @@ declare const clampPromotionThresholds: (tUp: number, tDownRaw: number) => Promo
1727
2205
  declare const relayCountFor: (subscribers: number, perRelayCapacity: number, maxRelays: number) => number;
1728
2206
  interface RelayAttach {
1729
2207
  relayIndex: number;
2208
+ seq?: number;
1730
2209
  type: "relay_attach";
1731
2210
  }
1732
2211
  interface RelayDetach {
1733
2212
  relayIndex: number;
2213
+ seq?: number;
1734
2214
  type: "relay_detach";
1735
2215
  }
1736
2216
  interface RelayFrame {
1737
2217
  cursor?: number;
1738
2218
  epoch?: string;
2219
+ exceptConnectionId?: string;
1739
2220
  frame: string;
1740
2221
  originRelay?: number;
1741
2222
  topic: string;
@@ -1753,6 +2234,12 @@ interface RelayShapeSubscribe {
1753
2234
  type: "relay_shape_subscribe";
1754
2235
  userId?: string;
1755
2236
  }
2237
+ interface RelayShapeUnsubscribe {
2238
+ connectionId: string;
2239
+ relayIndex: number;
2240
+ subId?: string;
2241
+ type: "relay_shape_unsubscribe";
2242
+ }
1756
2243
  interface RelayShapeSeed {
1757
2244
  cursor?: number;
1758
2245
  epoch?: string;
@@ -1772,44 +2259,85 @@ interface RelayShapePoke {
1772
2259
  targetConnectionId?: string;
1773
2260
  type: "relay_shape_poke";
1774
2261
  }
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>;
2262
+ interface RelayRoomEvent {
2263
+ attachment: Pick<SocketAttachment, "connectionId" | "context" | "identity" | "ip" | "userId">;
2264
+ connectionId: string;
2265
+ data?: unknown;
2266
+ kind: "join" | "leave" | "message";
2267
+ relayIndex: number;
2268
+ topic: string;
2269
+ type: "relay_room_event";
2270
+ }
2271
+ interface RelayRoomVerdict {
2272
+ admitted: boolean;
2273
+ }
2274
+ interface LiveSocketControlCall {
2275
+ action: unknown;
2276
+ callerId: string;
2277
+ connectionId: string;
2278
+ identityExpiry?: number;
2279
+ key: string;
2280
+ seq?: number;
2281
+ subscriptionId: string;
1779
2282
  }
1780
- interface RelayNamespaceLike {
1781
- get: (id: unknown) => RelayStub;
1782
- getByName?: (name: string) => RelayStub;
1783
- idFromName: (name: string) => unknown;
2283
+ interface RelayLiveControl {
2284
+ control: LiveSocketControlCall;
2285
+ type: "relay_live_control";
1784
2286
  }
2287
+ interface RelayLiveFrame {
2288
+ frame: string;
2289
+ key: string;
2290
+ topic: string;
2291
+ type: "relay_live_frame";
2292
+ }
2293
+ type OwnerRelayFrame = RelayAttach | RelayDetach | RelayFrame | RelayLiveControl | RelayLiveFrame | RelayRoomEvent | RelayShapePoke | RelayShapeSubscribe | RelayShapeUnsubscribe;
2294
+ declare const RELAY_SIGNATURE_HEADER = "x-lunora-relay-sig";
2295
+ declare const siblingSecretOf: (env: unknown) => string | undefined;
2296
+ declare const signSiblingBody: (secret: string, body: string) => Promise<string>;
2297
+ declare const verifySiblingBody: (env: unknown, supplied: null | string, raw: string) => Promise<boolean>;
2298
+ interface SiblingStub {
2299
+ fetch: (url: string, init?: RequestInit) => Promise<Response>;
2300
+ }
2301
+ declare const stubByName: (value: unknown, name: string, jurisdiction?: string) => SiblingStub | undefined;
2302
+ declare const DEFAULT_MAX_RELAYS = 8;
1785
2303
  interface RelayHost {
1786
2304
  buildShapeDiff: (resolved: ResolvedShape, fromCursor: number, toCursor: number) => ShapeRowOp[];
1787
2305
  computeOpLogShapeSeed: (shape: ShapeSubscriptionQuery, resolved: ResolvedShape) => {
1788
2306
  baseCheckpoint: number | undefined;
1789
2307
  cursor: number;
1790
2308
  epoch: string | undefined;
2309
+ reset: boolean;
1791
2310
  rowsPatch: ShapeRowOp[];
1792
2311
  };
1793
2312
  currentCdcEpoch: () => string | undefined;
2313
+ deliverLiveLocal: (topic: string, key: string, frame: string) => number;
1794
2314
  deliverWhisperLocal: (topic: string, frame: string, exclude: undefined | ShardSocketLike) => number;
1795
2315
  doName: () => string | undefined;
1796
2316
  env: () => unknown;
1797
2317
  getWebSockets: () => ShardSocketLike[];
2318
+ liveControl: (control: LiveSocketControlCall) => Promise<Response>;
1798
2319
  maskMetadata: () => MaskPoliciesResult;
1799
2320
  nextPokeId: () => string;
1800
2321
  readAttachment: (ws: ShardSocketLike) => SocketAttachment;
1801
2322
  recordShapePokeFanout: (iterated: number, delivered: number, elapsedMs: number) => void;
2323
+ relayRoomEvent: (event: RelayRoomEvent) => Promise<RelayRoomVerdict>;
1802
2324
  resolveShape: (name: string, args: Record<string, unknown>, identity?: SubscriptionIdentity) => ResolvedShape | undefined;
1803
2325
  rlsMetadata: () => RlsPoliciesResult;
1804
2326
  shardBinding: () => string | undefined;
2327
+ shardJurisdiction: () => string | undefined;
1805
2328
  sql: () => SqlExec;
1806
2329
  }
2330
+ interface RelayPokeDelivery {
2331
+ delivered: number;
2332
+ matched: number;
2333
+ }
1807
2334
  declare abstract class RelayLink {
1808
2335
  protected readonly host: RelayHost;
1809
2336
  protected readonly roleId: {
1810
2337
  ownerKey: string;
1811
2338
  relayIndex?: number;
1812
2339
  };
2340
+ private lastSequence;
1813
2341
  protected constructor(host: RelayHost, roleId: {
1814
2342
  ownerKey: string;
1815
2343
  relayIndex?: number;
@@ -1817,81 +2345,193 @@ declare abstract class RelayLink {
1817
2345
  handleControl(request: Request): Promise<Response>;
1818
2346
  maxRelays(): number;
1819
2347
  protected canAddressSiblings(): boolean;
1820
- protected relayNamespace(): RelayNamespaceLike | undefined;
2348
+ protected siblingStub(targetName: string): SiblingStub | undefined;
2349
+ protected bindingName(): string | undefined;
2350
+ protected nextRelaySeq(): number;
1821
2351
  protected postRelayMessage(targetName: string, message: OwnerRelayFrame): Promise<void>;
1822
2352
  protected requestRelayMessage(targetName: string, message: OwnerRelayFrame): Promise<Response | undefined>;
1823
- abstract forwardWhisper(topic: string, frame: string): Promise<void>;
2353
+ abstract forwardWhisper(topic: string, frame: string, exceptConnectionId?: string): Promise<void>;
1824
2354
  abstract onFlush(changed: Set<string>, frameCursor: number): Promise<void>;
1825
2355
  abstract seedRelayShape(ws: ShardSocketLike, subId: string, shape: ShapeSubscriptionQuery, identity: SubscriptionIdentity): Promise<"ok" | undefined | {
1826
2356
  code: string;
1827
2357
  message: string;
1828
2358
  }>;
1829
- abstract announce(): Promise<void>;
2359
+ abstract announce(): Promise<boolean>;
1830
2360
  abstract announceDrain(closing: ShardSocketLike): Promise<void>;
2361
+ abstract releaseRelayShapes(ws: ShardSocketLike, subId?: string): Promise<void>;
1831
2362
  abstract relayCount(): number;
1832
2363
  abstract isShapeRelayUniform(name: string, args: Record<string, unknown>): boolean;
1833
- protected abstract onAttach(index: number): void;
1834
- protected abstract onDetach(index: number): void;
2364
+ abstract minShapeCursor(): number | undefined;
2365
+ protected abstract onAttach(index: number, seq: number | undefined): boolean;
2366
+ protected abstract onDetach(index: number, seq: number | undefined): boolean;
2367
+ protected abstract onLiveControl(control: LiveSocketControlCall): Promise<Response>;
1835
2368
  protected abstract onWhisperFrame(message: RelayFrame): Promise<void>;
2369
+ protected abstract refusesAsIdle(): boolean;
1836
2370
  protected abstract onShapeSubscribe(message: RelayShapeSubscribe): RelayShapeSeed;
1837
- protected abstract onShapePoke(poke: RelayShapePoke): number;
2371
+ protected abstract onShapeUnsubscribe(message: RelayShapeUnsubscribe): void;
2372
+ protected abstract onShapePoke(poke: RelayShapePoke): RelayPokeDelivery;
1838
2373
  }
1839
2374
  declare class OwnerRelay extends RelayLink {
1840
2375
  private readonly shapeUniformCache;
1841
2376
  private relaySetCache;
1842
- private readonly relayShapeRegistry;
1843
- private readonly relayShapeProxies;
2377
+ private liveGrantRelayCache;
2378
+ private relayTablesReady;
2379
+ private readonly relaySeqMarks;
2380
+ private readonly pendingSubscribeRelays;
2381
+ private registryCache;
2382
+ private recordedBinding;
1844
2383
  private promotionState;
1845
2384
  constructor(host: RelayHost, ownerKey: string);
1846
- forwardWhisper(topic: string, frame: string): Promise<void>;
2385
+ forwardWhisper(topic: string, frame: string, exceptConnectionId?: string): Promise<void>;
2386
+ forwardLiveControl(call: LiveSocketControlCall): Promise<Response | undefined>;
2387
+ forwardLiveFrame(topic: string, key: string, frame: string): Promise<void>;
1847
2388
  onFlush(changed: Set<string>, frameCursor: number): Promise<void>;
1848
2389
  seedRelayShape(): Promise<"ok" | undefined | {
1849
2390
  code: string;
1850
2391
  message: string;
1851
2392
  }>;
1852
- announce(): Promise<void>;
2393
+ announce(): Promise<boolean>;
1853
2394
  announceDrain(): Promise<void>;
2395
+ releaseRelayShapes(): Promise<void>;
1854
2396
  relayCount(): number;
2397
+ minShapeCursor(): number | undefined;
1855
2398
  isShapeRelayUniform(name: string, args: Record<string, unknown>): boolean;
1856
- protected onAttach(index: number): void;
1857
- protected onDetach(index: number): void;
2399
+ protected onShapeUnsubscribe(message: RelayShapeUnsubscribe): void;
2400
+ protected onAttach(index: number, seq: number | undefined): boolean;
2401
+ protected onDetach(index: number, seq: number | undefined): boolean;
2402
+ protected refusesAsIdle(): boolean;
2403
+ protected onLiveControl(control: LiveSocketControlCall): Promise<Response>;
1858
2404
  protected onWhisperFrame(message: RelayFrame): Promise<void>;
1859
2405
  protected onShapeSubscribe(message: RelayShapeSubscribe): RelayShapeSeed;
1860
- protected onShapePoke(): number;
2406
+ protected onShapePoke(): RelayPokeDelivery;
2407
+ private relaySeqMark;
2408
+ private recordRelaySeq;
2409
+ private acceptRelaySeq;
1861
2410
  private buildShapePoke;
1862
2411
  private multicastShapePokes;
2412
+ private multicastToRelays;
1863
2413
  private proxyShapePokes;
2414
+ private proxyToRelay;
1864
2415
  private buildShapeSeedFrames;
1865
- private ensureRelayTable;
2416
+ private ensureRelayTables;
2417
+ protected bindingName(): string | undefined;
2418
+ private relayShapes;
2419
+ private rewindShapeCursor;
1866
2420
  private ownerRelaySet;
2421
+ private liveGrantRelaySet;
2422
+ private recordLiveGrantRelay;
1867
2423
  private addRelayToSet;
2424
+ private forwardToRelay;
2425
+ private requestDroppingIdle;
1868
2426
  private removeRelayFromSet;
1869
2427
  private probeShapeRelayUniform;
1870
2428
  private tableHasAnyMask;
2429
+ private liveControlAnswer;
1871
2430
  }
1872
2431
  declare class RelayMember extends RelayLink {
1873
2432
  private relayAnnounced;
1874
- private readonly shapeRelayMemos;
2433
+ private readonly liveControlSeqs;
2434
+ private pendingAnnounce;
2435
+ private announceGeneration;
2436
+ private pendingDetach;
2437
+ private relayMemoCache;
2438
+ private readonly shapeControl;
1875
2439
  constructor(host: RelayHost, ownerKey: string, relayIndex: number);
1876
2440
  forwardWhisper(topic: string, frame: string): Promise<void>;
2441
+ forwardRoomEvent(event: Omit<RelayRoomEvent, "relayIndex" | "type">): Promise<boolean>;
1877
2442
  onFlush(): Promise<void>;
1878
2443
  seedRelayShape(ws: ShardSocketLike, subId: string, shape: ShapeSubscriptionQuery, identity: SubscriptionIdentity): Promise<"ok" | {
1879
2444
  code: string;
1880
2445
  message: string;
1881
2446
  }>;
1882
- announce(): Promise<void>;
2447
+ announce(): Promise<boolean>;
1883
2448
  announceDrain(closing: ShardSocketLike): Promise<void>;
2449
+ releaseRelayShapes(ws: ShardSocketLike, subId?: string): Promise<void>;
1884
2450
  relayCount(): number;
1885
2451
  isShapeRelayUniform(): boolean;
1886
- protected onAttach(): void;
1887
- protected onDetach(): void;
2452
+ minShapeCursor(): number | undefined;
2453
+ protected onAttach(): boolean;
2454
+ protected refusesAsIdle(): boolean;
2455
+ protected onDetach(): boolean;
2456
+ protected onLiveControl(control: LiveSocketControlCall): Promise<Response>;
1888
2457
  protected onWhisperFrame(): Promise<void>;
1889
2458
  protected onShapeSubscribe(): RelayShapeSeed;
1890
- protected onShapePoke(poke: RelayShapePoke): number;
2459
+ protected onShapeUnsubscribe(): void;
2460
+ protected onShapePoke(poke: RelayShapePoke): RelayPokeDelivery;
2461
+ private queueShapeControl;
2462
+ private relayMemos;
2463
+ private connectionMemos;
1891
2464
  private recordRelayShapeMemo;
2465
+ private forgetRelayShapeMemos;
1892
2466
  private deliverShapePoke;
2467
+ private pokeSocketShapes;
1893
2468
  }
1894
2469
  declare const createRelayLink: (host: RelayHost) => OwnerRelay | RelayMember | undefined;
2470
+ declare const REGION_HINTS: readonly ["wnam", "enam", "sam", "weur", "eeur", "apac", "apac-ne", "apac-se", "oc", "afr", "me"];
2471
+ type RegionHint = (typeof REGION_HINTS)[number];
2472
+ type ReplicaReadiness = "fresh" | "stale" | "unavailable";
2473
+ interface ShardSiblingHost {
2474
+ doName: () => string | undefined;
2475
+ env: () => unknown;
2476
+ shardBinding: () => string | undefined;
2477
+ shardJurisdiction: () => string | undefined;
2478
+ sql: () => SqlExec;
2479
+ }
2480
+ interface ReplicaOwnerHost extends ShardSiblingHost {
2481
+ exportRows: () => Promise<ExportRow[]>;
2482
+ ownerCursor: () => number | undefined;
2483
+ ownerEpoch: () => string | undefined;
2484
+ ownerFloor: () => number | undefined;
2485
+ readChanges: (sinceSeq: number, limit: number) => {
2486
+ changes: CdcChange[];
2487
+ cursor: number;
2488
+ };
2489
+ rowCount: () => number;
2490
+ }
2491
+ interface ReplicaFollowerHost extends ShardSiblingHost {
2492
+ applyChanges: (changes: ReadonlyArray<CdcChange>) => Promise<number>;
2493
+ exportRows: () => Promise<ExportRow[]>;
2494
+ importRows: (rows: ReadonlyArray<ExportRow>) => Promise<{
2495
+ errors: ReadonlyArray<unknown>;
2496
+ }>;
2497
+ reportError?: (scope: string, error: unknown) => void;
2498
+ transactionLimits: () => Partial<TransactionLimits>;
2499
+ }
2500
+ declare const handleReplicaControl: (host: ReplicaOwnerHost, request: Request) => Promise<Response>;
2501
+ declare class ShardReplica {
2502
+ private readonly host;
2503
+ readonly ownerKey: string;
2504
+ readonly region: RegionHint;
2505
+ private divergent;
2506
+ private inFlight;
2507
+ constructor(host: ReplicaFollowerHost, ownerKey: string, region: RegionHint);
2508
+ ensureFresh(minSeq?: number): Promise<ReplicaReadiness>;
2509
+ appliedSeq(): number;
2510
+ isDivergent(): boolean;
2511
+ private advance;
2512
+ private isCaughtUp;
2513
+ private catchUp;
2514
+ private verdict;
2515
+ private recover;
2516
+ private whenOwnerUnreachable;
2517
+ private applyPage;
2518
+ private applyAtomically;
2519
+ private fetchSnapshot;
2520
+ private resnapshot;
2521
+ private overWriteBudget;
2522
+ private bootstrap;
2523
+ private isFreshEnough;
2524
+ private pull;
2525
+ private request;
2526
+ }
2527
+ declare const createReplicaLink: (host: ReplicaFollowerHost) => ShardReplica | undefined;
2528
+ declare const gateReplicaDispatch: (replica: ShardReplica, request: Request, functionPath: string) => Promise<Response | undefined>;
2529
+ declare const REPROJECTION_MIGRATION_PREFIX = "__lunora_reproject__";
2530
+ declare const reprojectionMigrationId: (table: string) => string;
2531
+ declare const reprojectableFields: (definition: TableDefinitionLike) => string[];
2532
+ declare const reprojectionTables: (schema: SchemaLike) => string[];
2533
+ declare const countLegacyRows: (sql: SqlExec, table: string, fields: ReadonlyArray<string>) => number;
2534
+ declare const buildReprojectionMigration: (id: string, schema: SchemaLike, sql: SqlExec) => DataMigrationLike | undefined;
1895
2535
  declare const RLS_UNWRAP_SYMBOL: symbol;
1896
2536
  declare class RlsRequiredError extends LunoraError {
1897
2537
  readonly table: string;
@@ -1908,7 +2548,7 @@ interface GuardableSchema {
1908
2548
  }
1909
2549
  type TableOfId = (id: string, expectedTable?: string) => Promise<string | undefined> | string | undefined;
1910
2550
  type TablesOfIds = (ids: ReadonlyArray<string>, expectedTable?: string) => Promise<ReadonlyMap<string, string>> | ReadonlyMap<string, string>;
1911
- declare const guardWriter: <W>(raw: W, schema: GuardableSchema, tableOfId: TableOfId, tablesOfIds?: TablesOfIds) => W;
2551
+ declare const guardWriter: <W>(raw: W, schema: GuardableSchema, tableOfId: TableOfId, tablesOfIds?: TablesOfIds, relationEdges?: ReadonlyArray<RelationEdge>) => W;
1912
2552
  declare const SCHEMA_HISTORY_MAX_VERSIONS = 50;
1913
2553
  interface SchemaVersionRow {
1914
2554
  appliedAt: number;
@@ -1919,8 +2559,24 @@ interface SchemaVersionRow {
1919
2559
  declare const recordSchemaVersion: (sql: SqlExec, hash: string, snapshotJson: string, now?: number) => boolean;
1920
2560
  declare const readSchemaHistory: (sql: SqlExec) => SchemaVersionRow[];
1921
2561
  declare const readSchemaVersion: (sql: SqlExec, hash: string) => SchemaVersionRow | undefined;
2562
+ declare const readDeployInfo: (rawEnv: unknown) => DeployInfo;
1922
2563
  declare const isDevEnvironment: (rawEnv: unknown) => boolean;
1923
2564
  declare const buildSettings: (rawEnv: unknown) => SettingsResult;
2565
+ declare class ShapeDiffCache {
2566
+ private readonly keyScans;
2567
+ private readonly memberProbes;
2568
+ private run;
2569
+ private served;
2570
+ get probesRun(): number;
2571
+ get probesServed(): number;
2572
+ changedKeys(rangeKey: string, load: () => CdcChangeKey[]): ReadonlyArray<CdcChangeKey>;
2573
+ members(resolved: ResolvedShape, rangeKey: string, load: () => Map<string, Record<string, unknown>>): ReadonlyMap<string, Record<string, unknown>>;
2574
+ private getOrLoad;
2575
+ }
2576
+ declare const createShapeDiffCache: () => ShapeDiffCache;
2577
+ declare const globalShapeReadKey: (resolved: ResolvedShape, identity: SubscriptionIdentity) => string | undefined;
2578
+ type ReadShapeCdcKeys = (sql: SqlExec, table: string, sinceSeq: number, upTo: number) => CdcChangeKey[];
2579
+ declare const buildShapeDiff: (sql: SqlExec, resolved: ResolvedShape, sinceSeq: number, upTo: number, cache: ShapeDiffCache, readKeys?: ReadShapeCdcKeys) => ShapeRowOp[];
1924
2580
  interface ShardRunnerOptions {
1925
2581
  handlers?: {
1926
2582
  handleAlarm?: () => Promise<void>;
@@ -1936,7 +2592,7 @@ declare class ShardRunner {
1936
2592
  socketFor(raw: unknown): ShardSocketLike;
1937
2593
  sockets(tag?: string): SocketHandle[];
1938
2594
  background(work: Promise<unknown>): boolean;
1939
- runInTransaction<T>(work: () => Promise<T>): Promise<T>;
2595
+ runInTransaction<T>(work: () => Promise<T>, onCommitted?: () => void): Promise<T>;
1940
2596
  handleFetch(request: Request): Promise<Response>;
1941
2597
  handleAlarm(): Promise<void>;
1942
2598
  }
@@ -1962,6 +2618,11 @@ interface SqlDiagnostic {
1962
2618
  source: "gate" | "plan" | "syntax";
1963
2619
  }
1964
2620
  declare const lintReadonlySql: (sql: SqlExec, query: string) => SqlLintResult;
2621
+ declare const BIGINT_KEY_DIGITS = 39;
2622
+ declare const bigintSqlKey: (value: bigint) => string;
2623
+ declare const decodeBigintSqlKey: (raw: string) => bigint | undefined;
2624
+ declare const float64SqlKey: (value: number) => string;
2625
+ declare const decodeFloat64SqlKey: (raw: string) => number | undefined;
1965
2626
  declare const subscriptionListDeltas: (previousJson: string, nextResult: unknown, table: string, frames?: string[]) => MutationDelta[] | undefined;
1966
2627
  interface FrameSink {
1967
2628
  send: (data: string) => void;
@@ -1970,7 +2631,17 @@ interface DrainableSink {
1970
2631
  readonly bufferedAmount?: unknown;
1971
2632
  }
1972
2633
  declare const trySendFrame: (ws: FrameSink, frame: string) => boolean;
1973
- declare const sendDeltaFrames: (ws: FrameSink, subId: string, deltaFrames: ReadonlyArray<string>, cursorSuffix: string, lastMutationId?: number) => boolean;
2634
+ interface SubscriptionFrameInput {
2635
+ cursorSuffix: string;
2636
+ lastMutationId?: number;
2637
+ nextResult: unknown;
2638
+ pageDeltas?: boolean;
2639
+ previousJson?: string;
2640
+ snapshotJson: string;
2641
+ subId: string;
2642
+ table: string;
2643
+ }
2644
+ declare const subscriptionFrames: (input: SubscriptionFrameInput) => string[];
1974
2645
  declare const awaitWsDrain: (ws: DrainableSink) => Promise<void>;
1975
2646
  interface SubscriptionReadFootprint {
1976
2647
  ranges?: Map<string, KeyRange[]>;
@@ -1998,13 +2669,30 @@ declare const selectExpiredIds: (sql: SqlExec, spec: TtlSweepSpec, now: number,
1998
2669
  hasMore: boolean;
1999
2670
  ids: string[];
2000
2671
  };
2001
- type FieldRefSql = (field: string) => SQL;
2002
- type SerializeValue = (value: unknown) => unknown;
2003
- interface WhereSqlStrategy {
2004
- fieldRef: FieldRefSql;
2005
- likeContains?: (reference: SQL, term: SQL) => SQL;
2006
- relationExists?: (request: unknown) => SQL;
2007
- serialize: SerializeValue;
2672
+ declare const VECTOR_BACKFILL_MAX_PAGES = 20;
2673
+ interface VectorBackfillTarget {
2674
+ profile: string;
2675
+ table: string;
2676
+ }
2677
+ interface VectorBackfillProgress {
2678
+ done: boolean;
2679
+ error?: string;
2680
+ failed: number;
2681
+ failedIds: string[];
2682
+ pages: number;
2683
+ rows: number;
2008
2684
  }
2009
- declare const compileWhereSql: (where: WhereInput | undefined, strategy: WhereSqlStrategy) => SQL | undefined;
2010
- 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, 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, buildSeekBeforeWhere, buildSeekWhere, buildSettings, bumpCdcEpoch, clampPromotionThresholds, clearCapturedMail, clearQueueMessages, coerceAggregateNumber, compileWhereSql, computeRankPage, containsRelationPredicate, 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, 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 };
2685
+ type VectorPageSync = (table: string, rows: ReadonlyArray<{
2686
+ doc: Record<string, unknown>;
2687
+ id: string;
2688
+ }>) => Promise<ReadonlyArray<{
2689
+ error: unknown;
2690
+ id: string;
2691
+ }>>;
2692
+ type OrderedAfterWrites = <T, U>(read: () => T, work: (value: T) => Promise<U>) => Promise<U>;
2693
+ declare const backfillVectorIndexes: (sql: SqlExec, targets: ReadonlyArray<VectorBackfillTarget>, sync: VectorPageSync, options: {
2694
+ maxPages?: number;
2695
+ ordered: OrderedAfterWrites;
2696
+ restart?: boolean;
2697
+ }) => Promise<VectorBackfillProgress>;
2698
+ 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, 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, 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 ImportError, 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 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 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, advanceClientWatermark, aggUpsertSql, aggregateSqlFunction, aggregateTableName, allocateCommitSeq, appendAuditEntry, appendCdcChange, appendStreamChunk, applyCdcChanges, applyInsertDefaults, applyOnDelete, applySelect, archiveCdcSegment, armRestore, assertFlatPredicate, assertNoExplicitUndefined, assertPatchAllowed, assertReadonly, assertShapeShardable, 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, 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, encodeAggregateKey, encodeCursor, encodeGeohash, encodePartitionKey, encodeRowsPatch, ensureAuditTable, ensureMailTable, envOptionalPositiveInt, envPositiveInt, equalityPinnedFields, exportShardRows, facetColumn, fanOutScalarCounts, findRelated, findStorageReferences, finishStreamRun, float64SqlKey, foldAggregateTally, forgetScheduleOutbox, ftsCompanionDdl, ftsPurgeDocument, ftsRowidMapName, ftsUnmappedPage, ftsWriteDocument, gateReplicaDispatch, geoTableName, globalShapeReadKey, groupUnmappedRows, guardWriter, handleReplicaControl, hasTrigger, haversineMeters, importShardRows, indexKeysForRow, isDevEnvironment, isFtsAvailable, isInternalTableName, isLossyBody, isMemoryTable, isPushableWhere, isRelationPredicate, isSoftDeleted, isSourceDue, isVacuousFilterClause, jsonPath, jsonPathSql, keysTouchRanges, liftSourceId, lintReadonlySql, 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, 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, readExternalSourceBaseline, readGlobalShapeSnapshot, readIdempotent, readMigrationStatus, readPatchField, readQueueMessageById, readQueueMessages, readReactorState, readSchemaHistory, readSchemaVersion, readSearchBackfillState, readShapePokeCursor, readStreamChunks, readStreamRun, readTablePage, recordCapturedMail, recordChangedKeys, recordFanoutPass, recordGlobalPollPass, recordQueueMessages, recordScheduleOutbox, recordSchemaVersion, recordShapeProbePass, relationHooks, relayCountFor, renderSql, reprojectableFields, reprojectionMigrationId, reprojectionTables, resolvePatch, resolveRankPartition, resolveRankSeekTuple, resolveRelationPredicates, resolveWith, 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, verifySiblingBody, whereFilter, whereOfFilter, writeCdcArchivedThrough, writeGlobalShapeSnapshot, writeIdempotent, writeReactorState, writeSearchBackfillState, writeShapePokeCursor, writeShapePokeCursors, writeTouchesMemo };