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

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