@lunora/do 1.0.0-alpha.1 → 1.0.0-alpha.10
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.
- package/__assets__/package-og.svg +1 -1
- package/dist/index.d.mts +832 -84
- package/dist/index.d.ts +832 -84
- package/dist/index.mjs +22 -20
- package/dist/packem_shared/{ADMIN_FUNCTION_PREFIX-Dzdqq5J2.mjs → ADMIN_FUNCTIONS-D_UiYJFk.mjs} +4 -1
- package/dist/packem_shared/{applyCdcChanges-Ctdmxmrv.mjs → CDC_LOG_TABLE-DSycmnDf.mjs} +5 -1
- package/dist/packem_shared/{assertFlatPredicate-DyVYReuT.mjs → DEFAULT_MAX_RELATION_KEYS-DU-Y4-LJ.mjs} +51 -2
- package/dist/packem_shared/{assertValidClientId-CBZ1zC96.mjs → NotUniqueError-DZQtH02h.mjs} +126 -36
- package/dist/packem_shared/{rank-CrkEIpF4.mjs → RANK_TIEBREAK-CXhdcA1o.mjs} +2 -13
- package/dist/packem_shared/{guardWriter-u3UlnCH5.mjs → RLS_UNWRAP_SYMBOL-EtGQdC9d.mjs} +6 -2
- package/dist/packem_shared/{ROOT_DO_SIZE_WARN_BYTES-DQkmGiCS.mjs → ROOT_DO_SIZE_WARN_BYTES-DKwBF3Jp.mjs} +1143 -156
- package/dist/packem_shared/{ReactiveCache-ByVzgH3d.mjs → ReactiveCache-1hDydFyv.mjs} +1 -28
- package/dist/packem_shared/{applyOnDelete-CMif2RKw.mjs → applyOnDelete-BQ-8ZlZ1.mjs} +19 -9
- package/dist/packem_shared/{buildSeekWhere-lVsNXSLy.mjs → applySelect-BvZdFUBT.mjs} +18 -1
- package/dist/packem_shared/{backfillAggregateIndexes-BF5eL7kW.mjs → backfillAggregateIndexes-BZsOqDXP.mjs} +3 -2
- package/dist/packem_shared/ctx-db-idempotency-BdcNpvY4.mjs +108 -0
- package/dist/packem_shared/ctx-db-shapes-DVoeZpo-.mjs +53 -0
- package/dist/packem_shared/{runShardMigrations-C3bn5r93.mjs → runShardMigrations-nIwoQeOK.mjs} +6 -4
- package/dist/packem_shared/serialize-sql-BlRUoiQe.mjs +14 -0
- package/dist/packem_shared/{serveRelationFanout-Clr1a05L.mjs → serveRelationFanout-C6lDaesn.mjs} +1 -1
- package/dist/packem_shared/stableStringify-CyHKJXre.mjs +30 -0
- package/dist/packem_shared/subscriptionListDeltas-ce84gpwL.mjs +111 -0
- package/package.json +2 -2
- package/dist/packem_shared/ctx-db-idempotency-DkC9rP91.mjs +0 -35
- package/dist/packem_shared/encodePartitionKey-C6blLR5K.mjs +0 -1
- /package/dist/packem_shared/{matchesStaticWhere-CFk6adSu.mjs → AGGREGATE_SQL_FUNCTION-CFk6adSu.mjs} +0 -0
- /package/dist/packem_shared/{AUTH_METRICS_BUCKET_MS-CiHHYeJi.mjs → AUTH_METRICS_BUCKETS_TABLE-CiHHYeJi.mjs} +0 -0
- /package/dist/packem_shared/{ensureFunctionMetricsTables-UDNVD7FS.mjs → FUNCTION_METRICS_BUCKETS_TABLE-UDNVD7FS.mjs} +0 -0
- /package/dist/packem_shared/{clearCapturedMail-CPpgl-dX.mjs → MAIL_RETENTION-CPpgl-dX.mjs} +0 -0
- /package/dist/packem_shared/{assertReadonly-dDcFE1YZ.mjs → MAX_SQL_ROWS-dDcFE1YZ.mjs} +0 -0
- /package/dist/packem_shared/{buildSecurityAudit-CCAvoFlr.mjs → MIN_ADMIN_TOKEN_LENGTH-CCAvoFlr.mjs} +0 -0
- /package/dist/packem_shared/{ftsTableName-BLEMawrp.mjs → buildFtsMatch-BLEMawrp.mjs} +0 -0
- /package/dist/packem_shared/{runTriggers-5N6_Fx0A.mjs → hasTrigger-5N6_Fx0A.mjs} +0 -0
package/dist/index.d.mts
CHANGED
|
@@ -195,10 +195,17 @@ interface RelationDefinitionLike {
|
|
|
195
195
|
readonly references: string;
|
|
196
196
|
readonly table: string;
|
|
197
197
|
}
|
|
198
|
-
/** Per-relation refinements: filter / order / cap / recurse into the children. */
|
|
198
|
+
/** Per-relation refinements: filter / order / cap / project / recurse into the children. */
|
|
199
199
|
interface NestedWith {
|
|
200
200
|
limit?: number;
|
|
201
201
|
orderBy?: OrderByInput[];
|
|
202
|
+
/**
|
|
203
|
+
* Project each loaded child down to these fields (like the top-level
|
|
204
|
+
* `findMany` `select`). Applied AFTER grouping, so the join key stays
|
|
205
|
+
* available to map children to parents; `_id`/`_creationTime` and any deeper
|
|
206
|
+
* `with` relations are always retained.
|
|
207
|
+
*/
|
|
208
|
+
select?: ReadonlyArray<string>;
|
|
202
209
|
where?: WhereInput;
|
|
203
210
|
with?: WithInput;
|
|
204
211
|
}
|
|
@@ -212,8 +219,17 @@ interface WithInput {
|
|
|
212
219
|
_count?: Record<string, true>;
|
|
213
220
|
}
|
|
214
221
|
interface ResolveWithOptions {
|
|
215
|
-
counter: (tableName: string, where?: WhereInput) => Promise<number>;
|
|
216
222
|
fetcher: (tableName: string, args: QueryArgs) => Promise<QueryPage>;
|
|
223
|
+
/**
|
|
224
|
+
* Grouped aggregate: for every FK value in `values`, return the count of
|
|
225
|
+
* child rows in `tableName` whose `whereField` equals that value,
|
|
226
|
+
* optionally AND-ing in `policyWhere` (the child table's RLS read filter).
|
|
227
|
+
* Returns a `Map` keyed by FK value with the per-group count — missing
|
|
228
|
+
* keys (groups with zero children) are not included; callers default to 0.
|
|
229
|
+
* A single `GROUP BY :whereField … WHERE :whereField IN (values)` query
|
|
230
|
+
* replaces the former one-query-per-distinct-value loop.
|
|
231
|
+
*/
|
|
232
|
+
groupedCounter: (tableName: string, whereField: string, values: unknown[], policyWhere?: WhereInput) => Promise<Map<unknown, number>>;
|
|
217
233
|
parents: Record<string, unknown>[];
|
|
218
234
|
/**
|
|
219
235
|
* Per-target-table read filter (RLS) applied to each relation fetch/count and
|
|
@@ -227,7 +243,18 @@ interface ResolveWithOptions {
|
|
|
227
243
|
tableName: string;
|
|
228
244
|
with: WithInput;
|
|
229
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* Cross-backend fan-out for grouped `_count` on backends whose `groupedCounter`
|
|
248
|
+
* must fall back to scalar calls (e.g. a DO's global-D1 child or the sql-store's
|
|
249
|
+
* cross-shard reverse direction). Issues one `counter(table, where)` per FK
|
|
250
|
+
* value in parallel and collects the results into a Map.
|
|
251
|
+
*
|
|
252
|
+
* Used by both the DO and sql-store `relationGroupedCounter` implementations so
|
|
253
|
+
* the parallel fan-out logic isn't duplicated.
|
|
254
|
+
*/
|
|
255
|
+
declare const fanOutScalarCounts: (counter: (tableName: string, where?: WhereInput) => Promise<number>, tableName: string, whereField: string, values: unknown[], policyWhere: WhereInput | undefined) => Promise<Map<unknown, number>>;
|
|
230
256
|
/** Distinct, non-nullish values of `field` across `rows`, preserving first-seen order. */
|
|
257
|
+
|
|
231
258
|
/**
|
|
232
259
|
* Resolve every requested relation on `parents` (a single already-fetched
|
|
233
260
|
* page), mutating each parent in place: `one` → `Doc | null`, `many` →
|
|
@@ -289,9 +316,9 @@ declare const applyOnDelete: (options: ApplyOnDeleteOptions) => Promise<void>;
|
|
|
289
316
|
* fakes (which never carry a runtime parser) keep working.
|
|
290
317
|
*/
|
|
291
318
|
declare const runRowValidators: (definition: TableDefinitionLike, document: Record<string, unknown>) => void;
|
|
292
|
-
type SortDirection
|
|
319
|
+
type SortDirection = "asc" | "desc";
|
|
293
320
|
/** A single `{ field: "asc" | "desc" }` entry; `orderBy` is an ordered list of these. */
|
|
294
|
-
type OrderByInput = Record<string, SortDirection
|
|
321
|
+
type OrderByInput = Record<string, SortDirection>;
|
|
295
322
|
interface QueryArgs {
|
|
296
323
|
/**
|
|
297
324
|
* Predicate injected by the runtime (e.g. by `@lunora/server`'s RLS
|
|
@@ -304,6 +331,12 @@ interface QueryArgs {
|
|
|
304
331
|
*/
|
|
305
332
|
baseWhere?: WhereInput;
|
|
306
333
|
cursor?: null | string;
|
|
334
|
+
/**
|
|
335
|
+
* Opt a list read OUT of soft-delete scoping: when `true`, rows whose
|
|
336
|
+
* soft-delete column is set are INCLUDED. Has no effect on a table without
|
|
337
|
+
* `.softDelete()`. Default (absent/false) hides soft-deleted rows.
|
|
338
|
+
*/
|
|
339
|
+
includeDeleted?: boolean;
|
|
307
340
|
limit?: number;
|
|
308
341
|
orderBy?: OrderByInput[];
|
|
309
342
|
/**
|
|
@@ -324,6 +357,15 @@ interface QueryArgs {
|
|
|
324
357
|
* reads (`findMany`/`findFirst`) — this flag specifically guards `count`.
|
|
325
358
|
*/
|
|
326
359
|
restrictsCounts?: boolean;
|
|
360
|
+
/**
|
|
361
|
+
* Project each returned row down to these fields. The system fields `_id` and
|
|
362
|
+
* `_creationTime` are always retained (cursors + by-id reuse depend on them),
|
|
363
|
+
* and any relations attached via `with` (their relation keys and `_count`)
|
|
364
|
+
* survive the trim. Applied AFTER the rows are read and relations resolved, so
|
|
365
|
+
* read-dependency tracking and cursor encoding see the full row — only the
|
|
366
|
+
* payload returned to the caller is narrowed. Omit for the full document.
|
|
367
|
+
*/
|
|
368
|
+
select?: ReadonlyArray<string>;
|
|
327
369
|
where?: WhereInput;
|
|
328
370
|
with?: WithInput;
|
|
329
371
|
}
|
|
@@ -341,7 +383,7 @@ interface QueryPage {
|
|
|
341
383
|
splitCursor?: null | string;
|
|
342
384
|
}
|
|
343
385
|
interface OrderKey {
|
|
344
|
-
direction: SortDirection
|
|
386
|
+
direction: SortDirection;
|
|
345
387
|
field: string;
|
|
346
388
|
}
|
|
347
389
|
/**
|
|
@@ -376,6 +418,26 @@ declare const buildSeekWhere: (keys: OrderKey[], cursorValues: unknown[]) => Whe
|
|
|
376
418
|
* the page it terminates. Reactive pagination uses this for a page's fixed end
|
|
377
419
|
* cursor; the shared compiler renders it per dialect.
|
|
378
420
|
*/
|
|
421
|
+
|
|
422
|
+
/**
|
|
423
|
+
* Project `page` rows down to `select` — plus the always-kept system fields and
|
|
424
|
+
* the relation/`_count` keys attached by a `with` load (passed as `withInput`,
|
|
425
|
+
* the same object handed to `findMany`). Returns the page unchanged when
|
|
426
|
+
* `select` is undefined. Pure; callers apply it AFTER relation resolution +
|
|
427
|
+
* cursor encoding so only the returned payload is trimmed (dependency tracking +
|
|
428
|
+
* the cursor still see the full row).
|
|
429
|
+
*/
|
|
430
|
+
declare const applySelect: (page: Record<string, unknown>[], select: ReadonlyArray<string> | undefined, withInput?: Record<string, unknown>) => Record<string, unknown>[];
|
|
431
|
+
/**
|
|
432
|
+
* The read-scope predicate that hides soft-deleted rows — `{ [field]: { isNull:
|
|
433
|
+
* true } }` matching the live rows whose soft-delete column is null/absent — or
|
|
434
|
+
* `undefined` when the table isn't `.softDelete()` or the read opted in via
|
|
435
|
+
* `includeDeleted`. AND-merge it into a list read's `where` (the by-id path
|
|
436
|
+
* never calls this, so `get`/`patch`/`replace`/`restore` still address the row).
|
|
437
|
+
*/
|
|
438
|
+
declare const softDeleteScope: (softDeleteMode: {
|
|
439
|
+
field: string;
|
|
440
|
+
} | undefined, includeDeleted: boolean | undefined) => undefined | WhereInput;
|
|
379
441
|
type RankDirection = "asc" | "desc";
|
|
380
442
|
interface RankSortKeyLike {
|
|
381
443
|
readonly direction: RankDirection;
|
|
@@ -554,6 +616,7 @@ declare const rankTableName: (table: string, indexName: string) => string;
|
|
|
554
616
|
* - `sortValues[i]` === `serializeSqlValue(doc[index.sortBy[i].field])` — the same transform `syncRankIndexEntry` applies to the stored `__sort_k<i>__` column, so the comparison is byte-for-byte (and JSON-safe for the cross-shard wire) regardless of which shard owns the row. `rankBefore` re-applies it idempotently, so a direct caller passing raw values still works.
|
|
555
617
|
* - `rowId` === `doc._id`, the `__id__` tiebreak.
|
|
556
618
|
*/
|
|
619
|
+
declare const stableStringify: (value: unknown) => string;
|
|
557
620
|
/** A single memoized result, the deps it read, and any active subscribers. */
|
|
558
621
|
interface CacheEntry {
|
|
559
622
|
/** Approximate serialized size of `result`, charged against `maxBytes`. */
|
|
@@ -686,16 +749,6 @@ declare class ReactiveCache {
|
|
|
686
749
|
private evict;
|
|
687
750
|
}
|
|
688
751
|
/**
|
|
689
|
-
* Stable, sorted JSON encoding of `args` for use in a cache key. Object keys
|
|
690
|
-
* are visited in lexical order at every depth so `{ a: 1, b: 2 }` and
|
|
691
|
-
* `{ b: 2, a: 1 }` hash to the same string. Arrays preserve their order
|
|
692
|
-
* (the index IS the key). `undefined` values are skipped at the object level
|
|
693
|
-
* so `{ a: undefined }` collides with `{}` — matches Convex behavior and
|
|
694
|
-
* avoids spurious cache misses on optional args. Inside arrays `undefined`
|
|
695
|
-
* encodes as `null` to keep positional semantics.
|
|
696
|
-
*/
|
|
697
|
-
declare const stableStringify: (value: unknown) => string;
|
|
698
|
-
/**
|
|
699
752
|
* Compose a cache key from a function path, a stably-encoded args object, and
|
|
700
753
|
* the caller's identity discriminator. Exported so the wiring layer and tests
|
|
701
754
|
* build identical keys without each side reinventing the format.
|
|
@@ -951,7 +1004,32 @@ interface SubscriptionQuery {
|
|
|
951
1004
|
*/
|
|
952
1005
|
table?: string;
|
|
953
1006
|
}
|
|
1007
|
+
/**
|
|
1008
|
+
* A live shape subscription registered on a socket — the partial-replication
|
|
1009
|
+
* parallel to {@link SubscriptionQuery}. The client names a `defineShape` shape
|
|
1010
|
+
* and supplies validated `args`; the DO resolves it to a table + RLS-composed
|
|
1011
|
+
* `effectiveWhere` under the socket's verified identity (never the client's
|
|
1012
|
+
* word) and pokes the membership diff. `sinceSeq`/`sinceEpoch` carry the
|
|
1013
|
+
* client's last applied checkpoint for resume.
|
|
1014
|
+
*/
|
|
1015
|
+
interface ShapeSubscriptionQuery {
|
|
1016
|
+
/** Validated shape arguments (e.g. `{ channelId }`); forwarded to `resolveShape`. */
|
|
1017
|
+
args?: Record<string, unknown>;
|
|
1018
|
+
/** Registered shape name (the `defineShape` export the codegen subclass resolves). */
|
|
1019
|
+
name: string;
|
|
1020
|
+
/** Resume epoch the client persisted alongside {@link ShapeSubscriptionQuery.sinceSeq} (see {@link SubscriptionQuery.sinceEpoch}). */
|
|
1021
|
+
sinceEpoch?: string;
|
|
1022
|
+
/** Resume checkpoint: the `__cdc_log` cursor the client's view of this shape last reflected (see {@link SubscriptionQuery.sinceSeq}). */
|
|
1023
|
+
sinceSeq?: number;
|
|
1024
|
+
}
|
|
954
1025
|
interface SubscriptionEnvelope {
|
|
1026
|
+
/**
|
|
1027
|
+
* Stable per-client id carried by the `connect` envelope. Recorded on the
|
|
1028
|
+
* socket attachment so a shape poke can echo this client's
|
|
1029
|
+
* `__client_watermark` as its `lastMutationId`. Ignored on other envelope
|
|
1030
|
+
* types; absent for clients that don't use custom mutators.
|
|
1031
|
+
*/
|
|
1032
|
+
clientId?: string;
|
|
955
1033
|
/**
|
|
956
1034
|
* App-supplied connection context carried by the `connect` envelope (e.g.
|
|
957
1035
|
* `{ roomId, sessionId }`). Merged into the socket attachment and forwarded
|
|
@@ -966,6 +1044,19 @@ interface SubscriptionEnvelope {
|
|
|
966
1044
|
id: string;
|
|
967
1045
|
query?: SubscriptionQuery;
|
|
968
1046
|
/**
|
|
1047
|
+
* Shape descriptor of a `shape_subscribe` envelope: the named shape + its
|
|
1048
|
+
* validated args. Carries the client's resume checkpoint via
|
|
1049
|
+
* {@link SubscriptionEnvelope.sinceCheckpoint}/{@link SubscriptionEnvelope.sinceEpoch}.
|
|
1050
|
+
*/
|
|
1051
|
+
shape?: {
|
|
1052
|
+
args?: Record<string, unknown>;
|
|
1053
|
+
name: string;
|
|
1054
|
+
};
|
|
1055
|
+
/** Resume checkpoint on a `shape_subscribe` envelope (the `__cdc_log` cursor the client's shape view is at). */
|
|
1056
|
+
sinceCheckpoint?: number;
|
|
1057
|
+
/** CDC epoch the {@link SubscriptionEnvelope.sinceCheckpoint} belongs to. */
|
|
1058
|
+
sinceEpoch?: string;
|
|
1059
|
+
/**
|
|
969
1060
|
* Topic of a `whisper`/`whisper_subscribe`/`whisper_unsubscribe` envelope —
|
|
970
1061
|
* an app-chosen channel name (e.g. `"room:42:cursors"`) scoped to this shard.
|
|
971
1062
|
*/
|
|
@@ -983,7 +1074,7 @@ interface SubscriptionEnvelope {
|
|
|
983
1074
|
* this shard with NO SQLite/CDC write (AnyCable-style whispering — typing
|
|
984
1075
|
* indicators, live cursors). The sender never receives its own whisper.
|
|
985
1076
|
*/
|
|
986
|
-
type: "ack" | "connect" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
|
|
1077
|
+
type: "ack" | "connect" | "shape_subscribe" | "shape_unsubscribe" | "stream" | "subscribe" | "unsubscribe" | "whisper" | "whisper_subscribe" | "whisper_unsubscribe";
|
|
987
1078
|
}
|
|
988
1079
|
/**
|
|
989
1080
|
* The argument a connection-lifecycle hook receives. Structurally matches
|
|
@@ -1058,6 +1149,15 @@ interface SocketAttachment {
|
|
|
1058
1149
|
*/
|
|
1059
1150
|
admin?: boolean;
|
|
1060
1151
|
/**
|
|
1152
|
+
* Stable per-client id from the `connect` envelope (the same id the client
|
|
1153
|
+
* stamps on its custom-mutator pushes). Lets a shape poke echo this client's
|
|
1154
|
+
* `__client_watermark` as the poke's `lastMutationId`, so a `@lunora/db`
|
|
1155
|
+
* collection can drop the optimistic overlay for writes this poke has
|
|
1156
|
+
* synced. Absent for clients that don't use custom mutators. Persisted so it
|
|
1157
|
+
* survives hibernation.
|
|
1158
|
+
*/
|
|
1159
|
+
clientId?: string;
|
|
1160
|
+
/**
|
|
1061
1161
|
* `true` once the socket's `connect` envelope has fired the `onConnect`
|
|
1062
1162
|
* hooks. Gates the dispatch so a client that re-sends `connect` (or a
|
|
1063
1163
|
* duplicate frame) can't re-fire the hooks for an already-announced socket —
|
|
@@ -1091,6 +1191,14 @@ interface SocketAttachment {
|
|
|
1091
1191
|
* hooks so they run under the connecting user.
|
|
1092
1192
|
*/
|
|
1093
1193
|
identity?: Record<string, unknown>;
|
|
1194
|
+
/**
|
|
1195
|
+
* Live shape subscriptions registered on this socket, keyed by the
|
|
1196
|
+
* client-supplied subscription id. The partial-replication parallel to
|
|
1197
|
+
* {@link SocketAttachment.subs}: the poke protocol fans membership diffs to
|
|
1198
|
+
* these, while `subs` drives the legacy `data`/`delta` re-execution path.
|
|
1199
|
+
* Absent until the socket sends its first `shape_subscribe`.
|
|
1200
|
+
*/
|
|
1201
|
+
shapes?: Record<string, ShapeSubscriptionQuery>;
|
|
1094
1202
|
subs: Record<string, SubscriptionQuery>;
|
|
1095
1203
|
/**
|
|
1096
1204
|
* Verified user id resolved at upgrade (from `x-lunora-userid`), or absent
|
|
@@ -1147,10 +1255,16 @@ interface CdcChange {
|
|
|
1147
1255
|
* Read changelog entries newer than `sinceSeq` in commit order, up to `limit`
|
|
1148
1256
|
* (clamped to [1, 10000]). Returns the rows plus the cursor to resume from (the
|
|
1149
1257
|
* last `seq`, or `sinceSeq` when the page is empty).
|
|
1258
|
+
*
|
|
1259
|
+
* The optional `tables` set narrows the page to changes on those tables — the
|
|
1260
|
+
* shape/poke path reads one filtered page per flush so it never scans op-log
|
|
1261
|
+
* entries for tables no live shape is watching. Omit it (or pass an empty set)
|
|
1262
|
+
* for the full, unfiltered page (the existing streaming-export/resume callers).
|
|
1150
1263
|
*/
|
|
1151
1264
|
declare const readCdcChanges: (sql: SqlExec, options?: {
|
|
1152
1265
|
limit?: number;
|
|
1153
1266
|
sinceSeq?: number;
|
|
1267
|
+
tables?: ReadonlySet<string>;
|
|
1154
1268
|
}) => {
|
|
1155
1269
|
changes: CdcChange[];
|
|
1156
1270
|
cursor: number;
|
|
@@ -1186,6 +1300,11 @@ declare const applyCdcChanges: (writer: DatabaseWriterLike, changes: ReadonlyArr
|
|
|
1186
1300
|
declare const runShardMigrations: (sql: SqlExec, schema: SchemaLike, options?: {
|
|
1187
1301
|
cdc?: boolean;
|
|
1188
1302
|
}) => void;
|
|
1303
|
+
/** One shape member: its `_id` key plus the decoded document (id + creationTime merged in). */
|
|
1304
|
+
interface ShapeRow {
|
|
1305
|
+
doc: Record<string, unknown>;
|
|
1306
|
+
id: string;
|
|
1307
|
+
}
|
|
1189
1308
|
/**
|
|
1190
1309
|
* Structural projection of `state.storage.sql` (workerd's SqlStorage). We
|
|
1191
1310
|
* only require the `exec` overload — the cursor it returns is iterable and
|
|
@@ -1233,6 +1352,16 @@ interface TableDefinitionLike {
|
|
|
1233
1352
|
field?: string;
|
|
1234
1353
|
kind: "global" | "root" | "shardBy";
|
|
1235
1354
|
};
|
|
1355
|
+
/**
|
|
1356
|
+
* Mirror of `@lunora/server`'s `TableDefinition.softDeleteMode` (set by
|
|
1357
|
+
* `.softDelete()`). When present, `delete()` flips the `field` column to a
|
|
1358
|
+
* timestamp instead of physically removing the row (cascading as a soft
|
|
1359
|
+
* delete), and list reads scope out rows whose `field` is set unless
|
|
1360
|
+
* `includeDeleted` is passed. By-id reads/writes are unaffected.
|
|
1361
|
+
*/
|
|
1362
|
+
readonly softDeleteMode?: {
|
|
1363
|
+
field: string;
|
|
1364
|
+
};
|
|
1236
1365
|
readonly triggerMap?: Record<string, TriggerDefinitionLike>;
|
|
1237
1366
|
}
|
|
1238
1367
|
interface IndexDefinitionLike {
|
|
@@ -1525,7 +1654,16 @@ interface DatabaseWriterLike {
|
|
|
1525
1654
|
* RLS-aware ctx seam from §3.2).
|
|
1526
1655
|
*/
|
|
1527
1656
|
count: (tableName: string, where?: RestrictableQueryOptions | WhereInput) => Promise<number>;
|
|
1528
|
-
|
|
1657
|
+
/**
|
|
1658
|
+
* Delete a row by id. On a `.softDelete()` table this flips the marker column
|
|
1659
|
+
* (cascading as a soft delete) instead of removing the row; pass
|
|
1660
|
+
* `options.hard` to force a physical removal (which cascades as a physical
|
|
1661
|
+
* delete, reaching already-soft-deleted children too). Non-soft tables ignore
|
|
1662
|
+
* `options.hard` — they always delete physically.
|
|
1663
|
+
*/
|
|
1664
|
+
delete: (id: string, expectedTable?: string, options?: {
|
|
1665
|
+
hard?: boolean;
|
|
1666
|
+
}) => Promise<void>;
|
|
1529
1667
|
/**
|
|
1530
1668
|
* Delete many rows by id in one call (a loop over `delete()`). The returned
|
|
1531
1669
|
* `deleted` is the number of ids **requested**, not rows actually removed (an
|
|
@@ -1702,6 +1840,14 @@ interface DatabaseWriterLike {
|
|
|
1702
1840
|
rankPageRows?: (tableName: string, indexName: string, options?: RankPageOptions) => Promise<ShardRankPageResult>;
|
|
1703
1841
|
replace: (id: string, document: Record<string, unknown>, expectedTable?: string) => Promise<void>;
|
|
1704
1842
|
/**
|
|
1843
|
+
* Un-soft-delete a row: clears the `.softDelete()` marker column (a by-id
|
|
1844
|
+
* UPDATE, so it works on a row that list reads currently hide). Throws when
|
|
1845
|
+
* the row's table isn't `.softDelete()`. Optional on the interface — the DO
|
|
1846
|
+
* writer implements it; the `.global()` twin does too, so a restore on a
|
|
1847
|
+
* global table routes through the DO writer's global fallback.
|
|
1848
|
+
*/
|
|
1849
|
+
restore?: (id: string, expectedTable?: string) => Promise<void>;
|
|
1850
|
+
/**
|
|
1705
1851
|
* Best-effort, read-only reader over Lunora's system tables
|
|
1706
1852
|
* (`_scheduled_functions`, `_storage`). Eventually consistent and **not**
|
|
1707
1853
|
* part of the shard's transaction snapshot — see {@link SystemDatabaseReader}.
|
|
@@ -1918,6 +2064,22 @@ declare const readAggregateValue: (op: string, row: {
|
|
|
1918
2064
|
* string.
|
|
1919
2065
|
*/
|
|
1920
2066
|
declare const encodeAggregateKey: (by: ReadonlyArray<string>, source: Record<string, unknown>) => string;
|
|
2067
|
+
/** One recorded admin operation, in monotonic `seq` order. */
|
|
2068
|
+
interface AuditEntry {
|
|
2069
|
+
/** JSON-decoded extra context (the acting user, op-specific counts, …); absent when none was recorded. */
|
|
2070
|
+
detail?: Record<string, unknown>;
|
|
2071
|
+
/** Primary key of the affected row, when the op targets one. */
|
|
2072
|
+
id?: string;
|
|
2073
|
+
/** Short op identifier, e.g. `writeRow` or `runMigration`. */
|
|
2074
|
+
op: string;
|
|
2075
|
+
/** Monotonic per-shard cursor — strictly increasing, never reused. */
|
|
2076
|
+
seq: number;
|
|
2077
|
+
/** Affected table, when the op targets one. */
|
|
2078
|
+
table?: string;
|
|
2079
|
+
/** Wall-clock millis when the op was recorded. */
|
|
2080
|
+
ts: number;
|
|
2081
|
+
}
|
|
2082
|
+
/** Fields accepted when appending one audit entry; `seq` is assigned by the table. */
|
|
1921
2083
|
/** Reserved single-row auth accumulator table. Auto-hidden from the data browser by the `__lunora` prefix. */
|
|
1922
2084
|
declare const AUTH_METRICS_TABLE = "__lunora_auth_metrics";
|
|
1923
2085
|
/** Reserved coarse time-series table: app-wide auth attempt/failure counts bucketed by a fixed window. */
|
|
@@ -2177,6 +2339,19 @@ declare const ADMIN_FUNCTION_PREFIX = "__lunora_admin__:";
|
|
|
2177
2339
|
*/
|
|
2178
2340
|
declare const RELATION_FUNCTION_PREFIX = "__lunora_relation__:";
|
|
2179
2341
|
/**
|
|
2342
|
+
* Reserved `functionPath` prefix for live feature-flag reads. The React client's
|
|
2343
|
+
* `useFlag`/`useFlags` subscribe to `__lunora_flags__:eval` over the same WS
|
|
2344
|
+
* channel as a user query; `ShardDO` intercepts it before user dispatch and
|
|
2345
|
+
* serves it from the codegen-overridden flag-subscription read hook, which
|
|
2346
|
+
* evaluates the flag through the app's OpenFeature provider under the socket's
|
|
2347
|
+
* verified identity. Like the other reserved prefixes it is NOT admin-gated (a
|
|
2348
|
+
* flag read is public, scoped to the subscriber's own targeting context), and
|
|
2349
|
+
* the `__lunora_` namespace is reserved so a real `<file>:<function>` can't
|
|
2350
|
+
* collide. Re-evaluated on every write-flush so values stay live within a
|
|
2351
|
+
* session (provider-side flips with no intervening write surface on reconnect).
|
|
2352
|
+
*/
|
|
2353
|
+
declare const FLAGS_FUNCTION_PREFIX = "__lunora_flags__:";
|
|
2354
|
+
/**
|
|
2180
2355
|
* Fully-qualified reserved paths the data browser invokes. The
|
|
2181
2356
|
* `__lunora_admin__:` prefix is spelled out inline rather than interpolated so
|
|
2182
2357
|
* the values stay emittable under `--isolatedDeclarations`.
|
|
@@ -2207,6 +2382,8 @@ declare const ADMIN_FUNCTIONS: {
|
|
|
2207
2382
|
readonly getSettings: "__lunora_admin__:getSettings";
|
|
2208
2383
|
readonly getWorkflowInstanceStatus: "__lunora_admin__:getWorkflowInstanceStatus";
|
|
2209
2384
|
readonly importShard: "__lunora_admin__:importShard";
|
|
2385
|
+
readonly listFlags: "__lunora_admin__:listFlags";
|
|
2386
|
+
readonly listQueues: "__lunora_admin__:listQueues";
|
|
2210
2387
|
readonly listTables: "__lunora_admin__:listTables";
|
|
2211
2388
|
readonly listWorkflows: "__lunora_admin__:listWorkflows";
|
|
2212
2389
|
readonly maskPolicies: "__lunora_admin__:maskPolicies";
|
|
@@ -2234,30 +2411,6 @@ interface TableInfo {
|
|
|
2234
2411
|
name: string;
|
|
2235
2412
|
rowCount: number;
|
|
2236
2413
|
}
|
|
2237
|
-
/**
|
|
2238
|
-
* One recorded admin operation served by `__lunora_admin__:getAuditLog`, sourced
|
|
2239
|
-
* from the reserved `__lunora_audit__` table (see `audit-log.ts`). Unlike the
|
|
2240
|
-
* in-memory `getMetrics`/`getFunctionStats` counters, the audit log is durable —
|
|
2241
|
-
* it survives hibernation/restart and is bounded only by a retention cap. `seq`
|
|
2242
|
-
* is a monotonic per-shard cursor the studio pages through; `op` is the short
|
|
2243
|
-
* op name (`writeRow`, `runMigration`, `importShard`, `applyCdc`); `table`/`id`
|
|
2244
|
-
* are present when the op targets one; `detail` carries op-specific context
|
|
2245
|
-
* (notably the acting `userId`).
|
|
2246
|
-
*/
|
|
2247
|
-
interface AuditEntry {
|
|
2248
|
-
/** JSON extra context (acting user, op-specific counts, …); absent when none was recorded. */
|
|
2249
|
-
detail?: Record<string, unknown>;
|
|
2250
|
-
/** Primary key of the affected row, when the op targets one. */
|
|
2251
|
-
id?: string;
|
|
2252
|
-
/** Short op identifier, e.g. `writeRow`. */
|
|
2253
|
-
op: string;
|
|
2254
|
-
/** Monotonic per-shard cursor — strictly increasing, never reused. */
|
|
2255
|
-
seq: number;
|
|
2256
|
-
/** Affected table, when the op targets one. */
|
|
2257
|
-
table?: string;
|
|
2258
|
-
/** Epoch-ms the op was recorded. */
|
|
2259
|
-
ts: number;
|
|
2260
|
-
}
|
|
2261
2414
|
/** Payload of a `__lunora_admin__:getAuditLog` call: the recorded entries, newest first. */
|
|
2262
2415
|
interface AuditLogResult {
|
|
2263
2416
|
entries: AuditEntry[];
|
|
@@ -2510,20 +2663,58 @@ interface StorageRulesResult {
|
|
|
2510
2663
|
* package's tests and the studio's fails the build if the two key sets diverge.
|
|
2511
2664
|
*/
|
|
2512
2665
|
interface StudioFeaturesResult {
|
|
2666
|
+
/** `@lunora/flags` / `ctx.flags` is used, or it is a declared dependency. */
|
|
2667
|
+
flags: boolean;
|
|
2513
2668
|
/** `@lunora/mail` is imported by a `lunora/` source or a declared dependency. */
|
|
2514
2669
|
mail: boolean;
|
|
2515
2670
|
/** `@lunora/payment` is used (import or `ctx.payments`) or a declared dependency. */
|
|
2516
2671
|
payments: boolean;
|
|
2672
|
+
/** `@lunora/queue` / `ctx.queues` is used, the app declares queues, or it is a declared dependency. */
|
|
2673
|
+
queues: boolean;
|
|
2517
2674
|
/** `@lunora/scheduler` / `ctx.scheduler` is used, the app declares crons, or it is a declared dependency. */
|
|
2518
2675
|
scheduler: boolean;
|
|
2519
2676
|
/** `@lunora/storage` / `ctx.storage` is used, the schema declares storage columns/rules, or it is a declared dependency. */
|
|
2520
2677
|
storage: boolean;
|
|
2521
|
-
/** The schema declares vector indexes, `@lunora/vectors` / `ctx.vectors` is used, or it is a declared dependency. */
|
|
2678
|
+
/** The schema declares vector indexes, `@lunora/bindings/vectors` / `ctx.vectors` is used, or it is a declared dependency. */
|
|
2522
2679
|
vectors: boolean;
|
|
2523
2680
|
/** `@lunora/workflow` / `ctx.workflows` is used, the app declares workflows, or it is a declared dependency. */
|
|
2524
2681
|
workflows: boolean;
|
|
2525
2682
|
}
|
|
2526
2683
|
/**
|
|
2684
|
+
* One feature flag evaluated under a supplied targeting context, surfaced by
|
|
2685
|
+
* `__lunora_admin__:listFlags` for the studio's read-only Flags page. The `key`
|
|
2686
|
+
* and `type` are statically discovered by `@lunora/codegen` from the app's
|
|
2687
|
+
* `ctx.flags.<type>("key", …)` reads; `value`/`reason`/`variant`/`errorCode`
|
|
2688
|
+
* come from the live OpenFeature evaluation (the codegen subclass overrides the
|
|
2689
|
+
* base `evaluateFlags` hook). `value` is the resolved flag value as JSON.
|
|
2690
|
+
*/
|
|
2691
|
+
interface FlagEvaluation {
|
|
2692
|
+
/** OpenFeature `errorCode` when the evaluation failed (the value falls back to the default). */
|
|
2693
|
+
errorCode?: string;
|
|
2694
|
+
/** The discovered flag key (the first argument of a `ctx.flags.<type>(...)` read). */
|
|
2695
|
+
key: string;
|
|
2696
|
+
/** OpenFeature `reason` for the resolution (`TARGETING_MATCH`, `DEFAULT`, `ERROR`, …). */
|
|
2697
|
+
reason?: string;
|
|
2698
|
+
/** The flag's value type, derived from which `ctx.flags.<type>` method read it. */
|
|
2699
|
+
type: "boolean" | "number" | "object" | "string";
|
|
2700
|
+
/** The resolved value (JSON), or the type default when unconfigured / on error. */
|
|
2701
|
+
value: unknown;
|
|
2702
|
+
/** OpenFeature `variant` identifier when the provider reports one. */
|
|
2703
|
+
variant?: string;
|
|
2704
|
+
}
|
|
2705
|
+
/**
|
|
2706
|
+
* Payload of a `__lunora_admin__:listFlags` call: every statically-discovered
|
|
2707
|
+
* flag evaluated under the supplied targeting context. `configured` is `false`
|
|
2708
|
+
* when the app wires no `@lunora/flags` provider (the base hook), so the studio
|
|
2709
|
+
* can distinguish "no flags configured" from "configured but zero flags read".
|
|
2710
|
+
*/
|
|
2711
|
+
interface FlagsResult {
|
|
2712
|
+
/** `true` when an `@lunora/flags` provider is wired (the codegen override ran). */
|
|
2713
|
+
configured: boolean;
|
|
2714
|
+
/** Each discovered flag evaluated under the request's targeting context. */
|
|
2715
|
+
flags: FlagEvaluation[];
|
|
2716
|
+
}
|
|
2717
|
+
/**
|
|
2527
2718
|
* One declared Cloudflare Workflow, surfaced by `__lunora_admin__:listWorkflows`
|
|
2528
2719
|
* for the studio's Workflows page. Statically discovered by `@lunora/codegen`
|
|
2529
2720
|
* from `lunora/workflows.ts` (the codegen subclass overrides the base hook);
|
|
@@ -2544,6 +2735,28 @@ interface WorkflowsResult {
|
|
|
2544
2735
|
workflows: WorkflowMetadata[];
|
|
2545
2736
|
}
|
|
2546
2737
|
/**
|
|
2738
|
+
* One declared Cloudflare Queue, surfaced by `__lunora_admin__:listQueues` for
|
|
2739
|
+
* the studio's Queues page. Statically discovered by `@lunora/codegen` from
|
|
2740
|
+
* `lunora/queues.ts` (the codegen subclass overrides the base hook); queues are
|
|
2741
|
+
* not Durable Objects and carry no runtime state in the shard, so this is pure
|
|
2742
|
+
* declaration metadata. `binding` is the generated `QUEUE_*` producer binding,
|
|
2743
|
+
* `name` the deployed `queues.producers[].queue`, `exportName` the
|
|
2744
|
+
* `lunora/queues.ts` export (`ctx.queues.<exportName>`), `mode` whether the
|
|
2745
|
+
* queue is consumed by a worker (`push`) or polled externally (`pull`), and
|
|
2746
|
+
* `deadLetterQueue` the optional DLQ a push consumer dead-letters to.
|
|
2747
|
+
*/
|
|
2748
|
+
interface QueueMetadata {
|
|
2749
|
+
binding: string;
|
|
2750
|
+
deadLetterQueue?: string;
|
|
2751
|
+
exportName: string;
|
|
2752
|
+
mode: "pull" | "push";
|
|
2753
|
+
name: string;
|
|
2754
|
+
}
|
|
2755
|
+
/** Payload of a `__lunora_admin__:listQueues` call: every declared queue, sorted by export name. */
|
|
2756
|
+
interface QueuesResult {
|
|
2757
|
+
queues: QueueMetadata[];
|
|
2758
|
+
}
|
|
2759
|
+
/**
|
|
2547
2760
|
* Lifecycle state of a workflow instance, mirrored from `@lunora/workflow`'s
|
|
2548
2761
|
* `WorkflowInstanceStatus` so `@lunora/do` carries no dependency on the workflow
|
|
2549
2762
|
* package. Returned by `getWorkflowInstanceStatus` and `createWorkflowInstance`.
|
|
@@ -2633,8 +2846,6 @@ interface FilterClause {
|
|
|
2633
2846
|
operator: FilterOperator;
|
|
2634
2847
|
value?: unknown;
|
|
2635
2848
|
}
|
|
2636
|
-
/** Sort direction for an {@link OrderByClause}. */
|
|
2637
|
-
type SortDirection = "asc" | "desc";
|
|
2638
2849
|
/**
|
|
2639
2850
|
* A server-side sort over one displayed column. `column` resolves the same way a
|
|
2640
2851
|
* {@link FilterClause}'s does — a physical/meta column orders by its identifier, a
|
|
@@ -3284,6 +3495,16 @@ declare const assertFlatPredicate: (where: WhereInput | undefined, schema: Resol
|
|
|
3284
3495
|
* and issues no extra query).
|
|
3285
3496
|
*/
|
|
3286
3497
|
declare const resolveRelationPredicates: (where: WhereInput | undefined, options: ResolveRelationPredicatesOptions) => Promise<WhereInput | undefined>;
|
|
3498
|
+
/**
|
|
3499
|
+
* Registration-time guard for partial-replication shapes. A live shape can only
|
|
3500
|
+
* be poked from the op-log of its OWN shard Durable Object, so an
|
|
3501
|
+
* `effectiveWhere` that joins to a `.shardBy()` table reaches rows that live in
|
|
3502
|
+
* other DOs the poke loop can never observe. Reject such a shape up front with
|
|
3503
|
+
* the two supported remedies. Called from the generated `resolveShape` override
|
|
3504
|
+
* the moment a socket subscribes (the first point the compiled predicate and the
|
|
3505
|
+
* schema's shard modes are both in hand).
|
|
3506
|
+
*/
|
|
3507
|
+
declare const assertShapeShardable: (effectiveWhere: WhereInput | undefined, schema: ResolveContext["schema"], table: string) => void;
|
|
3287
3508
|
/** Severity of a `ctx.log.*` call, mirroring the console method names (`log` is the default level, distinct from `info`). */
|
|
3288
3509
|
type ContextLogLevel = "debug" | "error" | "info" | "log" | "warn";
|
|
3289
3510
|
/** The fields {@link emitLogEvent} ships for one `ctx.log.*` call. */
|
|
@@ -3582,6 +3803,44 @@ declare class SessionDO {
|
|
|
3582
3803
|
private handleRevoke;
|
|
3583
3804
|
}
|
|
3584
3805
|
/**
|
|
3806
|
+
* Diff the previously-sent list snapshot (`previousJson`, the memo's
|
|
3807
|
+
* `lastJson`) against the new query result and produce per-row
|
|
3808
|
+
* {@link MutationDelta}s the client can merge in place via `applyDelta` —
|
|
3809
|
+
* Convex-parity live-pagination deltas (server half of gap #20).
|
|
3810
|
+
*
|
|
3811
|
+
* Returns `undefined` (caller falls back to a full `{type:"data"}` snapshot)
|
|
3812
|
+
* unless ALL of these hold:
|
|
3813
|
+
*
|
|
3814
|
+
* 1. `previousJson` parses to an array (there IS a previous list to diff against).
|
|
3815
|
+
* 2. `nextResult` is also an array.
|
|
3816
|
+
* 3. Every row in both arrays is a plain object carrying a string `_id`.
|
|
3817
|
+
* 4. Order preservation — rows present in BOTH arrays appear in the same relative order.
|
|
3818
|
+
* 5. Chattiness cap — the number of deltas does not exceed the new array length (a near-total change is cheaper as a snapshot).
|
|
3819
|
+
*
|
|
3820
|
+
* Diff is keyed by `_id`: rows only in prev → `delete`; rows only in next →
|
|
3821
|
+
* `insert`; rows in both whose JSON differs → `update`. Insert/update carry the
|
|
3822
|
+
* full new `row`; delete omits it (matching the wire contract `@lunora/client`
|
|
3823
|
+
* parses). Deltas are ordered deletes-then-inserts/updates so the client never
|
|
3824
|
+
* sees a transient over-length page.
|
|
3825
|
+
*
|
|
3826
|
+
* Per-row serialization is done exactly **once** per refresh (finding #6). Each
|
|
3827
|
+
* row is stringified a single time into a fingerprint reused for both the
|
|
3828
|
+
* `prev !== next` change-detection compare and — when the caller passes the
|
|
3829
|
+
* optional `frames` sink — the pre-serialized delta frame body. The returned
|
|
3830
|
+
* `MutationDelta[]` shape is unchanged; `frames`, when supplied, receives the
|
|
3831
|
+
* exact `JSON.stringify(delta)` string for each returned delta, in the same
|
|
3832
|
+
* order, so the caller can splice it straight into the `{type:"delta"}` frame
|
|
3833
|
+
* without serializing the delta (and the row inside it) a second time.
|
|
3834
|
+
* @returns the per-row deltas to send, or `undefined` when any precondition fails and a full snapshot should be sent instead
|
|
3835
|
+
*/
|
|
3836
|
+
declare const subscriptionListDeltas: (previousJson: string, nextResult: unknown, table: string, frames?: string[]) => MutationDelta[] | undefined;
|
|
3837
|
+
/**
|
|
3838
|
+
* Send one WebSocket frame, reporting whether it left the socket. A throw from
|
|
3839
|
+
* `ws.send` (socket closed mid-flush, outbound buffer gone) is the only
|
|
3840
|
+
* delivery-failure signal the runtime exposes; callers use the boolean to decide
|
|
3841
|
+
* whether to advance a subscription's delivered-diff baseline.
|
|
3842
|
+
*/
|
|
3843
|
+
/**
|
|
3585
3844
|
* Optional programmatic log sink, resolved from `createShardDO({ observability })`.
|
|
3586
3845
|
* Structurally a subset of `@lunora/runtime`'s `ObservabilitySink`, so a user can
|
|
3587
3846
|
* pass the SAME sink object to `createWorker` (which drives `onRpc`) and
|
|
@@ -3634,6 +3893,13 @@ interface ShardDOState {
|
|
|
3634
3893
|
getCurrentBookmark?: () => Promise<string>;
|
|
3635
3894
|
/** Native PITR: arm a restore to `bookmark` on next restart; returns the undo bookmark. */
|
|
3636
3895
|
onNextSessionRestoreBookmark?: (bookmark: string) => Promise<string>;
|
|
3896
|
+
/**
|
|
3897
|
+
* Arm the DO's single alarm to fire at `scheduledTime` (ms epoch),
|
|
3898
|
+
* waking {@link ShardDO.alarm}. Used by the global-shape poll loop.
|
|
3899
|
+
* Optional: present on the real runtime, absent in the unit harness
|
|
3900
|
+
* (where the poll loop degrades to seed-only).
|
|
3901
|
+
*/
|
|
3902
|
+
setAlarm?: (scheduledTime: Date | number) => Promise<void>;
|
|
3637
3903
|
sql: {
|
|
3638
3904
|
[key: string]: unknown;
|
|
3639
3905
|
/**
|
|
@@ -3678,6 +3944,41 @@ interface SubscriptionOutcome {
|
|
|
3678
3944
|
tables: Set<string>;
|
|
3679
3945
|
}
|
|
3680
3946
|
/**
|
|
3947
|
+
* A shape resolved to its concrete query plan, the return of the
|
|
3948
|
+
* {@link ShardDO.resolveShape} hook. The codegen subclass composes the shape's
|
|
3949
|
+
* own predicate with the caller's RLS read base-where into `effectiveWhere`
|
|
3950
|
+
* under the socket's verified identity (the client never supplies it), so the
|
|
3951
|
+
* membership query the poke protocol runs is RLS-correct by construction.
|
|
3952
|
+
*
|
|
3953
|
+
* `columns`, when present, projects each row-op's `value` to that subset (the
|
|
3954
|
+
* shape's declared column allow-list); absent ⇒ the full document is shipped.
|
|
3955
|
+
*/
|
|
3956
|
+
interface ResolvedShape {
|
|
3957
|
+
columns?: ReadonlyArray<string>;
|
|
3958
|
+
effectiveWhere?: WhereInput;
|
|
3959
|
+
/**
|
|
3960
|
+
* `true` when the shape's table is `.global()` (lives in D1, not this DO's
|
|
3961
|
+
* SQLite). A global shape has **no per-DO op-log** to diff, so it is served
|
|
3962
|
+
* by the **latency-tiered poll path** ({@link ShardDO.seedGlobalShape} +
|
|
3963
|
+
* {@link ShardDO.refreshGlobalShape}) instead of the CDC poke path — seeded
|
|
3964
|
+
* from {@link ShardDO.readGlobalShapeRows} and refreshed on an alarm tick.
|
|
3965
|
+
* The codegen subclass sets it from the schema's `shardMode`; absent ⇒ a
|
|
3966
|
+
* shard-local (poke-live) shape.
|
|
3967
|
+
*/
|
|
3968
|
+
global?: boolean;
|
|
3969
|
+
table: string;
|
|
3970
|
+
}
|
|
3971
|
+
/**
|
|
3972
|
+
* Classification of a watermarked custom-mutator push against the shard's
|
|
3973
|
+
* `__client_watermark`: `expected` is the next in-order sequence, `kind`
|
|
3974
|
+
* whether the push is a replay (`"already"`), the next one (`"next"`), or an
|
|
3975
|
+
* out-of-order arrival (`"gap"`).
|
|
3976
|
+
*/
|
|
3977
|
+
type ClientMutationClass = {
|
|
3978
|
+
expected: number;
|
|
3979
|
+
kind: "already" | "gap" | "next";
|
|
3980
|
+
};
|
|
3981
|
+
/**
|
|
3681
3982
|
* Identity a subscription query is executed under, threaded EXPLICITLY into
|
|
3682
3983
|
* `executeSubscription` → `buildCtx` rather than read from the shared,
|
|
3683
3984
|
* per-request `currentRequestUserId`/`currentRequestIdentity` instance fields.
|
|
@@ -3834,38 +4135,6 @@ interface RunShardRankPageArgs {
|
|
|
3834
4135
|
take?: number;
|
|
3835
4136
|
}
|
|
3836
4137
|
/**
|
|
3837
|
-
* Diff the previously-sent list snapshot (`previousJson`, the memo's
|
|
3838
|
-
* `lastJson`) against the new query result and produce per-row
|
|
3839
|
-
* {@link MutationDelta}s the client can merge in place via `applyDelta` —
|
|
3840
|
-
* Convex-parity live-pagination deltas (server half of gap #20).
|
|
3841
|
-
*
|
|
3842
|
-
* Returns `undefined` (caller falls back to a full `{type:"data"}` snapshot)
|
|
3843
|
-
* unless ALL of these hold:
|
|
3844
|
-
*
|
|
3845
|
-
* 1. `previousJson` parses to an array (there IS a previous list to diff against).
|
|
3846
|
-
* 2. `nextResult` is also an array.
|
|
3847
|
-
* 3. Every row in both arrays is a plain object carrying a string `_id`.
|
|
3848
|
-
* 4. Order preservation — rows present in BOTH arrays appear in the same relative order.
|
|
3849
|
-
* 5. Chattiness cap — the number of deltas does not exceed the new array length (a near-total change is cheaper as a snapshot).
|
|
3850
|
-
*
|
|
3851
|
-
* Diff is keyed by `_id`: rows only in prev → `delete`; rows only in next →
|
|
3852
|
-
* `insert`; rows in both whose JSON differs → `update`. Insert/update carry the
|
|
3853
|
-
* full new `row`; delete omits it (matching the wire contract `@lunora/client`
|
|
3854
|
-
* parses). Deltas are ordered deletes-then-inserts/updates so the client never
|
|
3855
|
-
* sees a transient over-length page.
|
|
3856
|
-
*
|
|
3857
|
-
* Per-row serialization is done exactly **once** per refresh (finding #6). Each
|
|
3858
|
-
* row is stringified a single time into a fingerprint reused for both the
|
|
3859
|
-
* `prev !== next` change-detection compare and — when the caller passes the
|
|
3860
|
-
* optional `frames` sink — the pre-serialized delta frame body. The returned
|
|
3861
|
-
* `MutationDelta[]` shape is unchanged; `frames`, when supplied, receives the
|
|
3862
|
-
* exact `JSON.stringify(delta)` string for each returned delta, in the same
|
|
3863
|
-
* order, so the caller can splice it straight into the `{type:"delta"}` frame
|
|
3864
|
-
* without serializing the delta (and the row inside it) a second time.
|
|
3865
|
-
* @returns the per-row deltas to send, or `undefined` when any precondition fails and a full snapshot should be sent instead
|
|
3866
|
-
*/
|
|
3867
|
-
declare const subscriptionListDeltas: (previousJson: string, nextResult: unknown, table: string, frames?: string[]) => MutationDelta[] | undefined;
|
|
3868
|
-
/**
|
|
3869
4138
|
* Threshold at which a `__root__` DO triggers the size warning. 1 GiB —
|
|
3870
4139
|
* exactly 10% of the 10 GiB per-DO SQLite ceiling, leaving plenty of runway
|
|
3871
4140
|
* to plan a `.shardBy()` migration before the wall hits.
|
|
@@ -3918,6 +4187,28 @@ declare abstract class ShardDO {
|
|
|
3918
4187
|
*/
|
|
3919
4188
|
protected static readonly MAX_SUBSCRIPTIONS_PER_SOCKET = 32;
|
|
3920
4189
|
/**
|
|
4190
|
+
* Poll interval (ms) for `.global()`-table shapes. A global table lives in
|
|
4191
|
+
* D1 with no per-DO op-log, so its shapes can't be poke-live; the DO re-reads
|
|
4192
|
+
* each subscribed global shape's membership from D1 on an alarm every
|
|
4193
|
+
* `GLOBAL_SHAPE_POLL_INTERVAL_MS` and pokes only the diff. This is the
|
|
4194
|
+
* latency floor for a global-shape update — deliberately coarse (seconds, not
|
|
4195
|
+
* the sub-millisecond poke-live path) since the D1 read fans out per tick.
|
|
4196
|
+
*/
|
|
4197
|
+
protected static readonly GLOBAL_SHAPE_POLL_INTERVAL_MS = 2e3;
|
|
4198
|
+
/**
|
|
4199
|
+
* Upper bound on a `.global()`-shape's materialized membership. Each global
|
|
4200
|
+
* shape keeps its ENTIRE current membership as a per-socket snapshot
|
|
4201
|
+
* (`Map<rowKey, hash>`) so the poll loop can diff it; that snapshot — and the
|
|
4202
|
+
* read buffer feeding it — scale with the membership size, multiplied by every
|
|
4203
|
+
* subscribed socket. An unbounded membership (a global table with no narrowing
|
|
4204
|
+
* shape predicate or RLS read scope) would grow them without limit and evict
|
|
4205
|
+
* the DO. A shape whose membership exceeds this cap is failed closed (left
|
|
4206
|
+
* empty, logged) rather than retained — the developer must narrow it. Sized
|
|
4207
|
+
* well above any reasonable per-identity replicated set so legitimate shapes
|
|
4208
|
+
* never trip it.
|
|
4209
|
+
*/
|
|
4210
|
+
protected static readonly GLOBAL_SHAPE_MAX_ROWS = 5e4;
|
|
4211
|
+
/**
|
|
3921
4212
|
* Per-socket whisper-topic cap. Topic membership rides the same hibernation
|
|
3922
4213
|
* attachment as `subs`, so bound it for the same reason — a runaway
|
|
3923
4214
|
* `whisper_subscribe` loop must not wedge the attachment past the runtime's
|
|
@@ -4017,6 +4308,39 @@ declare abstract class ShardDO {
|
|
|
4017
4308
|
*/
|
|
4018
4309
|
private currentRequestMutationId;
|
|
4019
4310
|
/**
|
|
4311
|
+
* Stable per-device client id for the in-flight custom-mutator push,
|
|
4312
|
+
* forwarded via the `x-lunora-client-id` header. Backs the
|
|
4313
|
+
* `__client_watermark` table: the dispatch path classifies the paired
|
|
4314
|
+
* `currentRequestClientSeq` against the stored high-watermark (already
|
|
4315
|
+
* processed / next / out-of-order gap). Absent on legacy mutations and
|
|
4316
|
+
* queries (those keep the `__idempotency` path). Cleared in `fetch`'s
|
|
4317
|
+
* `finally`.
|
|
4318
|
+
*/
|
|
4319
|
+
private currentRequestClientId;
|
|
4320
|
+
/**
|
|
4321
|
+
* Monotonic per-client mutation sequence for the in-flight custom-mutator
|
|
4322
|
+
* push, forwarded via the `x-lunora-client-seq` header (numeric). Paired
|
|
4323
|
+
* with `currentRequestClientId` to drive the watermark classification.
|
|
4324
|
+
* `undefined` when absent or non-numeric.
|
|
4325
|
+
*/
|
|
4326
|
+
private currentRequestClientSeq;
|
|
4327
|
+
/**
|
|
4328
|
+
* The in-flight push's custom-mutator classification, stashed by `fetch`
|
|
4329
|
+
* before `handleRpc` so the in-transaction bookkeeping ({@link
|
|
4330
|
+
* ShardDO.commitMutationBookkeeping}) can advance the `__client_watermark` for
|
|
4331
|
+
* a `"next"` push inside the same commit as the writes. `undefined` for an
|
|
4332
|
+
* ordinary mutation / non-mutator push. Cleared per request.
|
|
4333
|
+
*/
|
|
4334
|
+
private currentMutatorClass;
|
|
4335
|
+
/**
|
|
4336
|
+
* Set once a mutation's replay bookkeeping (idempotency row + watermark
|
|
4337
|
+
* advance) has committed INSIDE the handler transaction, so the post-dispatch
|
|
4338
|
+
* path skips the now-redundant best-effort writes. Cleared per request; stays
|
|
4339
|
+
* `false` for actions/queries (no transaction wrapper) so their dispatch-level
|
|
4340
|
+
* idempotency persist still runs.
|
|
4341
|
+
*/
|
|
4342
|
+
private mutationBookkeepingCommitted;
|
|
4343
|
+
/**
|
|
4020
4344
|
* Wall-clock millis of the last `__idempotency` GC sweep on this warm
|
|
4021
4345
|
* instance. The dedup write throttles `trimIdempotent` to at most once an
|
|
4022
4346
|
* hour off this field (in-memory, so a fresh instance just sweeps on its
|
|
@@ -4047,6 +4371,18 @@ declare abstract class ShardDO {
|
|
|
4047
4371
|
*/
|
|
4048
4372
|
private pendingChangedTables;
|
|
4049
4373
|
/**
|
|
4374
|
+
* Coalesced set of tables awaiting a subscription-refresh pass, merged
|
|
4375
|
+
* across every {@link ShardDO.flushChangedTables} call that lands while a
|
|
4376
|
+
* pass is already draining. The single drain loop
|
|
4377
|
+
* ({@link ShardDO.drainSubscriptionRefreshes}) owns this set; a burst of N
|
|
4378
|
+
* writes to the same table therefore collapses into one (or two) refresh
|
|
4379
|
+
* passes instead of N, so each affected subscription's handler re-runs once
|
|
4380
|
+
* per burst rather than once per write. `undefined` when nothing is pending.
|
|
4381
|
+
*/
|
|
4382
|
+
private pendingRefreshTables;
|
|
4383
|
+
/** True while {@link ShardDO.drainSubscriptionRefreshes} is running; the single-waiter gate that coalesces concurrent flushes. */
|
|
4384
|
+
private refreshInFlight;
|
|
4385
|
+
/**
|
|
4050
4386
|
* Last pushed result per `(socket, subId)`, keyed by socket. Lets
|
|
4051
4387
|
* `refreshSubscriptions` skip re-running queries whose tables were
|
|
4052
4388
|
* untouched and suppress pushes when the re-run result is unchanged. Held
|
|
@@ -4054,6 +4390,39 @@ declare abstract class ShardDO {
|
|
|
4054
4390
|
* memo simply forces one re-run and (at most) one redundant push.
|
|
4055
4391
|
*/
|
|
4056
4392
|
private readonly subMemos;
|
|
4393
|
+
/**
|
|
4394
|
+
* Per-socket poke baseline for shape subscriptions: maps each shape's
|
|
4395
|
+
* subscription id to the `__cdc_log` cursor it has been poked through.
|
|
4396
|
+
* `pokeShapeSubscribers` reads each op page since this cursor and advances
|
|
4397
|
+
* it to the flush watermark. In-memory only (like {@link ShardDO.subMemos});
|
|
4398
|
+
* a cold memo on a reconnected/hibernated socket re-seeds from the client's
|
|
4399
|
+
* `sinceCheckpoint`.
|
|
4400
|
+
*/
|
|
4401
|
+
private readonly shapeMemos;
|
|
4402
|
+
/**
|
|
4403
|
+
* Per-socket, per-**global**-shape membership snapshot: maps each global
|
|
4404
|
+
* shape's subscription id to a `key → projected-value JSON` map of the rows
|
|
4405
|
+
* last poked to that socket. A `.global()` (D1) table has no op-log to diff,
|
|
4406
|
+
* so {@link ShardDO.refreshGlobalShape} re-reads the full membership on each
|
|
4407
|
+
* alarm tick and diffs it against this snapshot to compute the poke. Parallel
|
|
4408
|
+
* to {@link ShardDO.shapeMemos} (the cursor baseline for poke-live shapes).
|
|
4409
|
+
*
|
|
4410
|
+
* This is a hot in-memory **cache** over the durable `__global_shape_snapshot`
|
|
4411
|
+
* table (keyed by the socket's `connectionId` + subId): a hibernation eviction
|
|
4412
|
+
* clears the WeakMap, so on the next alarm wake {@link ShardDO.readGlobalSnapshot}
|
|
4413
|
+
* misses and re-loads the baseline from SQLite — without it, the diff would run
|
|
4414
|
+
* against an empty baseline and a row deleted from D1 while the DO slept would
|
|
4415
|
+
* never be poked as a `delete`, lingering on the client as a phantom row.
|
|
4416
|
+
*/
|
|
4417
|
+
private readonly globalShapeSnapshots;
|
|
4418
|
+
/**
|
|
4419
|
+
* Whether a global-shape poll alarm is currently armed. Guards
|
|
4420
|
+
* {@link ShardDO.scheduleGlobalPoll} from re-arming on every seed; reset in
|
|
4421
|
+
* {@link ShardDO.alarm} before the poll so a still-subscribed shape re-arms.
|
|
4422
|
+
*/
|
|
4423
|
+
private globalPollScheduled;
|
|
4424
|
+
/** Monotonic per-DO poke id source; correlates a poke's `pokeStart`/`pokePart`/`pokeEnd` frames. */
|
|
4425
|
+
private pokeSequence;
|
|
4057
4426
|
/** Per-socket whisper-rate token bucket (see {@link ShardDO.WHISPER_RATE_BURST}). In-memory; resets on hibernation. */
|
|
4058
4427
|
private readonly whisperBuckets;
|
|
4059
4428
|
/**
|
|
@@ -4172,6 +4541,15 @@ declare abstract class ShardDO {
|
|
|
4172
4541
|
webSocketClose(ws: WebSocket, _code: number, _reason: string, _wasClean: boolean): Promise<void>;
|
|
4173
4542
|
/** Hibernation API: invoked on socket error. */
|
|
4174
4543
|
webSocketError(_ws: WebSocket, _error: unknown): void;
|
|
4544
|
+
/**
|
|
4545
|
+
* Durable Object alarm handler — the heartbeat for `.global()`-table shapes.
|
|
4546
|
+
* The runtime wakes this when the poll alarm armed by `scheduleGlobalPoll`
|
|
4547
|
+
* fires; it refreshes every subscribed global shape (diff-poke from the global
|
|
4548
|
+
* backend) and re-arms while any remain. With no global subscribers left, the
|
|
4549
|
+
* alarm is not re-armed and the DO goes idle. A base-only / global-free DO
|
|
4550
|
+
* never arms it, so this stays dormant there.
|
|
4551
|
+
*/
|
|
4552
|
+
alarm(): Promise<void>;
|
|
4175
4553
|
/** Subclasses implement function dispatch. */
|
|
4176
4554
|
abstract handleRpc(functionPath: string, args: Record<string, unknown>): Promise<unknown>;
|
|
4177
4555
|
/**
|
|
@@ -4418,6 +4796,35 @@ declare abstract class ShardDO {
|
|
|
4418
4796
|
*/
|
|
4419
4797
|
protected studioFeatures(): StudioFeaturesResult;
|
|
4420
4798
|
/**
|
|
4799
|
+
* Evaluate every statically-discovered feature flag under `context` for the
|
|
4800
|
+
* studio's read-only Flags page (`__lunora_admin__:listFlags`). The flag keys
|
|
4801
|
+
* + value types are discovered by `@lunora/codegen` from the app's
|
|
4802
|
+
* `ctx.flags.<type>("key", …)` reads and evaluated through the configured
|
|
4803
|
+
* `@lunora/flags` provider — work only the codegen subclass can do, so it
|
|
4804
|
+
* overrides this. The base class wires no provider and reports
|
|
4805
|
+
* `configured: false` with zero flags (an un-generated `ShardDO` has none).
|
|
4806
|
+
*/
|
|
4807
|
+
protected evaluateFlags(_context?: Record<string, unknown>): Promise<FlagsResult>;
|
|
4808
|
+
/**
|
|
4809
|
+
* Serve one reserved {@link FLAGS_FUNCTION_PREFIX} live flag read for the
|
|
4810
|
+
* React client's `useFlag`/`useFlags`. `functionPath` carries the flag key +
|
|
4811
|
+
* type and `args` the per-subscriber targeting context; the codegen subclass
|
|
4812
|
+
* overrides this to evaluate the flag through the app's `@lunora/flags`
|
|
4813
|
+
* provider under `identity` and return the resolved value. The base class
|
|
4814
|
+
* wires no provider, so it returns `null` — `resolveReactiveOutcome` reads
|
|
4815
|
+
* `null` as "nothing to deliver" and the subscriber keeps its default.
|
|
4816
|
+
*/
|
|
4817
|
+
protected runFlagSubscriptionRead(_functionPath: string, _arguments: Record<string, unknown>, _identity?: SubscriptionIdentity): Promise<unknown>;
|
|
4818
|
+
/**
|
|
4819
|
+
* The Cloudflare Queues declared by this app, surfaced via
|
|
4820
|
+
* `__lunora_admin__:listQueues` for the studio's Queues page. Queues are NOT
|
|
4821
|
+
* Durable Objects and hold no shard state, so this is pure declaration
|
|
4822
|
+
* metadata statically discovered by `@lunora/codegen` from `lunora/queues.ts`
|
|
4823
|
+
* and emitted into the generated subclass, which overrides this. The base
|
|
4824
|
+
* class can't see the user's project, so it reports none.
|
|
4825
|
+
*/
|
|
4826
|
+
protected queuesMetadata(): QueuesResult;
|
|
4827
|
+
/**
|
|
4421
4828
|
* The Cloudflare Workflows declared by this app, surfaced via
|
|
4422
4829
|
* `__lunora_admin__:listWorkflows` for the studio's Workflows page. Workflows
|
|
4423
4830
|
* are NOT Durable Objects and hold no shard state, so this is pure
|
|
@@ -4580,16 +4987,105 @@ declare abstract class ShardDO {
|
|
|
4580
4987
|
* unless the request carried an `x-lunora-mutation-id` header (queries and
|
|
4581
4988
|
* legacy clients leave `currentRequestMutationId` undefined).
|
|
4582
4989
|
*
|
|
4583
|
-
*
|
|
4584
|
-
*
|
|
4585
|
-
*
|
|
4586
|
-
*
|
|
4587
|
-
*
|
|
4588
|
-
*
|
|
4589
|
-
*
|
|
4990
|
+
* For a mutation this runs INSIDE the handler's transaction (via
|
|
4991
|
+
* {@link ShardDO.commitMutationBookkeeping}, which `handleRpc` invokes before
|
|
4992
|
+
* the transaction commits), so the dedup row is durable iff the writes are —
|
|
4993
|
+
* closing the crash window where the writes commit but the replay guard does
|
|
4994
|
+
* not. Actions/queries aren't transaction-wrapped, so they call this on the
|
|
4995
|
+
* live dispatch path right after the handler resolves, through the same
|
|
4996
|
+
* `this.sql` handle. `INSERT OR IGNORE` keeps a concurrent double-dispatch (or
|
|
4997
|
+
* the now-skipped post-dispatch call) of the same id idempotent. Also runs the
|
|
4998
|
+
* throttled dedup-table GC.
|
|
4590
4999
|
*/
|
|
4591
5000
|
protected persistIdempotentResult(result: unknown): void;
|
|
4592
5001
|
/**
|
|
5002
|
+
* Whether `functionPath` names a registered custom mutator (a `defineMutator`
|
|
5003
|
+
* declaration) rather than an ordinary `mutation`. The base class knows of no
|
|
5004
|
+
* mutators, so the default is `false`; the codegen-generated subclass
|
|
5005
|
+
* overrides this to consult its mutator registry. When `true` (and the push
|
|
5006
|
+
* carries a `clientId`/`clientSeq`), the dispatch path applies the
|
|
5007
|
+
* `__client_watermark` ordering semantics instead of the legacy idempotency
|
|
5008
|
+
* dedup.
|
|
5009
|
+
*/
|
|
5010
|
+
protected isCustomMutator(_functionPath: string): boolean;
|
|
5011
|
+
/**
|
|
5012
|
+
* Classify an in-flight custom-mutator push against the shard's stored
|
|
5013
|
+
* high-watermark for `currentRequestClientId`. The watermark is the highest
|
|
5014
|
+
* per-client sequence the DO has applied, so the push is exactly one of:
|
|
5015
|
+
*
|
|
5016
|
+
* - `"already"` — `seq <= watermark`: a replay of a confirmed (or in-flight,
|
|
5017
|
+
* now-resent) mutation. The handler must NOT re-run; the dispatch path returns
|
|
5018
|
+
* a benign ack so the client drops the pending overlay.
|
|
5019
|
+
* - `"next"` — `seq == watermark + 1`: the next mutation in order. Run the
|
|
5020
|
+
* authoritative `server` impl and advance the watermark in the same commit.
|
|
5021
|
+
* - `"gap"` — `seq > watermark + 1`: an out-of-order arrival (an earlier push
|
|
5022
|
+
* was lost). Halt: the client must resend from `watermark + 1`.
|
|
5023
|
+
*
|
|
5024
|
+
* Returns `undefined` when the push is not a watermarked custom mutator
|
|
5025
|
+
* (missing client id/seq, or a stub `sql` handle without the table) so the
|
|
5026
|
+
* caller falls through to the legacy idempotency path.
|
|
5027
|
+
*/
|
|
5028
|
+
protected classifyClientMutation(): ClientMutationClass | undefined;
|
|
5029
|
+
/**
|
|
5030
|
+
* Terminal response for a watermarked custom-mutator push that is NOT the
|
|
5031
|
+
* next-in-order mutation — an idempotent replay ack (`"already"`) or an
|
|
5032
|
+
* out-of-order halt (`"gap"`). Returns `undefined` for an ordinary mutation
|
|
5033
|
+
* or a `"next"` push so `fetch` proceeds to the authoritative handler. Records
|
|
5034
|
+
* the function call on the short-circuit paths so metrics stay attributed.
|
|
5035
|
+
*/
|
|
5036
|
+
protected rejectNonNextMutation(functionPath: string, mutatorClass: ClientMutationClass | undefined, dispatchStartedAt: number): Response | undefined;
|
|
5037
|
+
/**
|
|
5038
|
+
* Respond to a dispatch that hit the `(identity, mutationId)` idempotency
|
|
5039
|
+
* cache. Records the (zero-work) function call, then: for a `"next"` custom
|
|
5040
|
+
* mutator whose handler already committed but whose watermark advance was
|
|
5041
|
+
* lost to a crash in between, re-advance and echo `lastMutationId` exactly as
|
|
5042
|
+
* the post-commit path does (otherwise the cached branch returns a bare
|
|
5043
|
+
* result with a stale watermark and the client reports every later seq as a
|
|
5044
|
+
* gap forever); for everything else, return the bare cached `{ result }`.
|
|
5045
|
+
*/
|
|
5046
|
+
protected respondFromIdempotencyCache(functionPath: string, dispatchStartedAt: number, mutatorClass: ClientMutationClass | undefined, cachedValue: unknown): Response;
|
|
5047
|
+
/**
|
|
5048
|
+
* Build the success response for a dispatched RPC. A `"next"` custom-mutator
|
|
5049
|
+
* push echoes the applied `lastMutationId` so the client drops the pending
|
|
5050
|
+
* optimistic overlay as soon as the ack lands; ordinary calls return the bare
|
|
5051
|
+
* `{ result }` envelope unchanged.
|
|
5052
|
+
*/
|
|
5053
|
+
protected buildDispatchResponse(mutatorClass: ClientMutationClass | undefined, result: unknown): Response;
|
|
5054
|
+
/**
|
|
5055
|
+
* Commit a mutation's replay bookkeeping — the `(identity, mutationId)`
|
|
5056
|
+
* idempotency dedup row and, for a `"next"` custom-mutator push, the
|
|
5057
|
+
* `__client_watermark` advance — INSIDE the handler's transaction. Called by
|
|
5058
|
+
* the generated `handleRpc` mutation branch after the user handler resolves
|
|
5059
|
+
* but before the transaction commits, so the writes, the dedup row, and the
|
|
5060
|
+
* watermark land in one atomic commit: a crash can't leave the writes durable
|
|
5061
|
+
* without the replay guard (which a re-dispatch would otherwise re-run) nor
|
|
5062
|
+
* without the watermark. Sets {@link ShardDO.mutationBookkeepingCommitted} so
|
|
5063
|
+
* `fetch` skips the redundant post-dispatch persist.
|
|
5064
|
+
*/
|
|
5065
|
+
protected commitMutationBookkeeping(result: unknown): void;
|
|
5066
|
+
/**
|
|
5067
|
+
* Best-effort replay bookkeeping for the live dispatch path, run after
|
|
5068
|
+
* `handleRpc` returns. A generated mutation already committed it atomically
|
|
5069
|
+
* inside its transaction (via {@link ShardDO.commitMutationBookkeeping}, which
|
|
5070
|
+
* sets the flag), so this skips. Actions/queries aren't transaction-wrapped,
|
|
5071
|
+
* so they record their dedup row here (a no-op without an `x-lunora-mutation-id`),
|
|
5072
|
+
* and a `"next"` push advances its watermark (the gap self-heals on replay).
|
|
5073
|
+
*/
|
|
5074
|
+
protected recordPostDispatchBookkeeping(result: unknown, mutatorClass: ClientMutationClass | undefined): void;
|
|
5075
|
+
/**
|
|
5076
|
+
* Advance the stored high-watermark for the in-flight custom mutator to
|
|
5077
|
+
* `currentRequestClientSeq` through the same `this.sql` handle. On the
|
|
5078
|
+
* transactional path ({@link ShardDO.commitMutationBookkeeping}, `strict`) it
|
|
5079
|
+
* runs inside the handler's commit, so the watermark is durable iff the writes
|
|
5080
|
+
* are; a failure rethrows to roll the mutation back. On the best-effort
|
|
5081
|
+
* cache-hit recovery path (`strict` omitted) a missing table is swallowed —
|
|
5082
|
+
* the replay re-runs and re-advances (the read side treats a missing row as
|
|
5083
|
+
* watermark 0), so the gap self-heals.
|
|
5084
|
+
*/
|
|
5085
|
+
protected advanceClientMutationWatermark(options?: {
|
|
5086
|
+
strict?: boolean;
|
|
5087
|
+
}): void;
|
|
5088
|
+
/**
|
|
4593
5089
|
* Replay a batch of CDC changes into this shard (point-in-time recovery).
|
|
4594
5090
|
* Schema-aware — it builds a `createShardCtxDb` writer — so the base class
|
|
4595
5091
|
* can't implement it; the codegen-generated subclass overrides this to call
|
|
@@ -4608,6 +5104,17 @@ declare abstract class ShardDO {
|
|
|
4608
5104
|
protected subscribe(ws: WebSocket, subId: string, query: SubscriptionQuery): "ok" | "serialize_failed" | "too_many";
|
|
4609
5105
|
protected unsubscribe(ws: WebSocket, subId: string): void;
|
|
4610
5106
|
/**
|
|
5107
|
+
* Register a live shape subscription on a socket — the partial-replication
|
|
5108
|
+
* parallel to {@link ShardDO.subscribe}. Stores the descriptor in the
|
|
5109
|
+
* attachment's `shapes` registry (created lazily) so it survives
|
|
5110
|
+
* hibernation, sharing the per-socket cap with `subs`. Returns a status the
|
|
5111
|
+
* caller surfaces as a structured error frame; never throws (a thrown
|
|
5112
|
+
* `webSocketMessage` is a fatal-channel error under the hibernation API).
|
|
5113
|
+
*/
|
|
5114
|
+
protected shapeSubscribe(ws: WebSocket, subId: string, shape: ShapeSubscriptionQuery): "ok" | "serialize_failed" | "too_many";
|
|
5115
|
+
/** Remove a shape subscription and its poke baseline. Mirrors {@link ShardDO.unsubscribe}'s rollback-on-serialize-failure contract. */
|
|
5116
|
+
protected shapeUnsubscribe(ws: WebSocket, subId: string): void;
|
|
5117
|
+
/**
|
|
4611
5118
|
* Decide whether a single subscription is interested in a mutation
|
|
4612
5119
|
* delta. The default implementation checks the table name, then runs a
|
|
4613
5120
|
* shallow-equality predicate over `query.args` against `delta.row`. A
|
|
@@ -4645,6 +5152,40 @@ declare abstract class ShardDO {
|
|
|
4645
5152
|
*/
|
|
4646
5153
|
protected executeSubscription(_functionPath: string, _args: Record<string, unknown>, _identity?: SubscriptionIdentity): Promise<SubscriptionOutcome | null>;
|
|
4647
5154
|
/**
|
|
5155
|
+
* Resolve a named shape to its concrete query plan for `identity`. The base
|
|
5156
|
+
* class has no shape registry, so it returns `undefined` — partial
|
|
5157
|
+
* replication is disabled and a `shape_subscribe` is rejected. The
|
|
5158
|
+
* codegen-generated subclass overrides this to look the shape up in the
|
|
5159
|
+
* project's `defineShape` registry, evaluate its `where(ctx, args)` under the
|
|
5160
|
+
* subscriber's verified identity, and AND-compose it with the table's RLS
|
|
5161
|
+
* read base-where into {@link ResolvedShape.effectiveWhere}.
|
|
5162
|
+
*
|
|
5163
|
+
* `identity` is the socket's OWN verified identity (the same unforgeable
|
|
5164
|
+
* value `refreshSubscriptions` threads), passed by value so this never reads
|
|
5165
|
+
* the mutable per-request identity fields. Returning `undefined` is the
|
|
5166
|
+
* fail-closed signal — an unknown shape, or an RLS-required table with no
|
|
5167
|
+
* policy resolving for this identity, yields no subscription rather than
|
|
5168
|
+
* leaking rows.
|
|
5169
|
+
*/
|
|
5170
|
+
protected resolveShape(_name: string, _args: Record<string, unknown>, _identity?: SubscriptionIdentity): ResolvedShape | undefined;
|
|
5171
|
+
/**
|
|
5172
|
+
* Read the FULL current membership of a `.global()`-table shape from its D1
|
|
5173
|
+
* (or Hyperdrive) backend — the seed/poll source for the latency-tiered
|
|
5174
|
+
* global shape path. A `.global()` table lives in another store with no
|
|
5175
|
+
* per-DO op-log, so this is the only way to learn its rows from inside the
|
|
5176
|
+
* shard DO; {@link ShardDO.seedGlobalShape} calls it once on subscribe and
|
|
5177
|
+
* {@link ShardDO.refreshGlobalShape} on every alarm tick, diffing the result
|
|
5178
|
+
* against the per-socket snapshot to compute the poke.
|
|
5179
|
+
*
|
|
5180
|
+
* The base class has no global backend, so it returns `[]` (a base-only DO,
|
|
5181
|
+
* or a project with no global tables, never resolves a global shape). The
|
|
5182
|
+
* codegen subclass overrides it to drain `globalDb.findMany(table, { where:
|
|
5183
|
+
* effectiveWhere })` under the socket's verified `identity` — the same
|
|
5184
|
+
* unforgeable value `resolveShape` composed the RLS predicate with, so the
|
|
5185
|
+
* D1 read is identity-scoped exactly like the poke-live path.
|
|
5186
|
+
*/
|
|
5187
|
+
protected readGlobalShapeRows(_resolved: ResolvedShape, _identity?: SubscriptionIdentity): Promise<ShapeRow[]>;
|
|
5188
|
+
/**
|
|
4648
5189
|
* Look up a streaming-query function and return a thunk that produces the
|
|
4649
5190
|
* `AsyncIterable<unknown>` when handed an {@link AbortSignal}. The codegen
|
|
4650
5191
|
* subclass overrides this to dispatch via `LUNORA_FUNCTIONS`; the base
|
|
@@ -4920,6 +5461,16 @@ declare abstract class ShardDO {
|
|
|
4920
5461
|
*/
|
|
4921
5462
|
private handleGetWorkflowInstanceStatus;
|
|
4922
5463
|
/**
|
|
5464
|
+
* Serve `__lunora_admin__:listFlags` — the studio's read-only Flags page.
|
|
5465
|
+
* Evaluates every statically-discovered feature flag under an optional
|
|
5466
|
+
* `args.context` targeting context (the studio's editable context editor)
|
|
5467
|
+
* via the {@link evaluateFlags} hook, which the codegen subclass overrides
|
|
5468
|
+
* with live OpenFeature evaluation. Read-only: a flag lookup mutates no shard
|
|
5469
|
+
* state, so nothing is flushed or audited. Admin-gated by `handleAdminRpc`'s
|
|
5470
|
+
* caller.
|
|
5471
|
+
*/
|
|
5472
|
+
private handleListFlags;
|
|
5473
|
+
/**
|
|
4923
5474
|
* Run `run()` with the per-request identity pinned to (`userId`, `identity`),
|
|
4924
5475
|
* then restore the prior values in a `finally` (even if `run()` throws), so the
|
|
4925
5476
|
* forced identity can never leak into a later dispatch on this DO instance. The
|
|
@@ -5179,6 +5730,16 @@ declare abstract class ShardDO {
|
|
|
5179
5730
|
*/
|
|
5180
5731
|
private executeAdminSubscription;
|
|
5181
5732
|
/**
|
|
5733
|
+
* Resolve one subscription (seed or refresh) to its {@link SubscriptionOutcome}
|
|
5734
|
+
* by routing the `functionPath` to the right read path — shared by
|
|
5735
|
+
* {@link seedSubscription} and {@link refreshSubscriptions} so both branch
|
|
5736
|
+
* identically:
|
|
5737
|
+
* - `__lunora_admin__:*` → {@link executeAdminSubscription} (raw SQLite read).
|
|
5738
|
+
* - {@link FLAGS_FUNCTION_PREFIX} → {@link runFlagSubscriptionRead} (the codegen subclass evaluates the flag through the configured provider). The value isn't bound to any table, so it is tagged with the {@link ADMIN_WILDCARD} dep — re-evaluated on every write-flush so a live `useFlag` stays current within a session. A `null` read means "nothing to deliver" (no provider, or a flag that resolved to `null`).
|
|
5739
|
+
* - everything else → {@link executeSubscription} (the user query, under the socket's own by-value identity).
|
|
5740
|
+
*/
|
|
5741
|
+
private resolveReactiveOutcome;
|
|
5742
|
+
/**
|
|
5182
5743
|
* Constant-time bearer check against `env.LUNORA_ADMIN_TOKEN`. Returns
|
|
5183
5744
|
* `false` (closed) when the token is unset so admin introspection is
|
|
5184
5745
|
* opt-in rather than exposed by default.
|
|
@@ -5210,6 +5771,17 @@ declare abstract class ShardDO {
|
|
|
5210
5771
|
*/
|
|
5211
5772
|
private flushChangedTables;
|
|
5212
5773
|
/**
|
|
5774
|
+
* Drain {@link ShardDO.pendingRefreshTables} one coalesced batch at a time
|
|
5775
|
+
* until it is empty, then release the {@link ShardDO.refreshInFlight} gate.
|
|
5776
|
+
* Tables merged by a `flushChangedTables` that lands mid-pass are picked up
|
|
5777
|
+
* by the next loop iteration, so every committed write is observed by a
|
|
5778
|
+
* refresh that runs after it — bursts simply share a pass. The post-write
|
|
5779
|
+
* high-watermark and live-socket set are re-read inside each
|
|
5780
|
+
* `refreshSubscriptions` / `pokeShapeSubscribers` call, so a later batch
|
|
5781
|
+
* always reflects the latest committed state.
|
|
5782
|
+
*/
|
|
5783
|
+
private drainSubscriptionRefreshes;
|
|
5784
|
+
/**
|
|
5213
5785
|
* For every live subscription whose query reads one of `changed`, re-run
|
|
5214
5786
|
* the query and push a fresh `{ type: "data" }` frame when the result
|
|
5215
5787
|
* differs from the last one sent. Subscriptions with no `functionPath`
|
|
@@ -5282,6 +5854,182 @@ declare abstract class ShardDO {
|
|
|
5282
5854
|
*/
|
|
5283
5855
|
private seedSubscription;
|
|
5284
5856
|
/**
|
|
5857
|
+
* Drive the full `shape_subscribe` flow as one failure-aware unit: persist the
|
|
5858
|
+
* attachment, seed the shape, and ack ONLY once both succeed. A persist
|
|
5859
|
+
* rejection (`too_many`/`serialize_failed`) or a seed that can't resolve the
|
|
5860
|
+
* shape (unknown / RLS-denied / cross-shard-invalid) rolls the attachment back
|
|
5861
|
+
* and sends an `error` frame instead of acking — so a client is never left
|
|
5862
|
+
* acked but subscribed to a shape that will never deliver. Never throws (a
|
|
5863
|
+
* thrown `webSocketMessage` is fatal to the hibernating socket).
|
|
5864
|
+
*/
|
|
5865
|
+
private handleShapeSubscribe;
|
|
5866
|
+
/** Send a structured `error` frame for a failed `shape_subscribe`, swallowing a send on an already-closed socket. */
|
|
5867
|
+
private sendShapeSubscribeError;
|
|
5868
|
+
/**
|
|
5869
|
+
* Seed a freshly-registered shape subscription. Resolves the shape under the
|
|
5870
|
+
* socket's verified identity, then ships either:
|
|
5871
|
+
*
|
|
5872
|
+
* - a **catch-up** poke (the membership diff in `(sinceCheckpoint, cursor]`)
|
|
5873
|
+
* when the client supplied a still-current checkpoint within the CDC retention
|
|
5874
|
+
* window and on this epoch — the cheap reconnect path; or
|
|
5875
|
+
* - a **full** insert-poke of the shape's entire current membership — a
|
|
5876
|
+
* first-time subscribe, or a reconnect that fell outside retention / forked
|
|
5877
|
+
* epoch.
|
|
5878
|
+
*
|
|
5879
|
+
* Either way the per-socket shape memo advances to the flush watermark so
|
|
5880
|
+
* later `pokeShapeSubscribers` passes diff from the right point.
|
|
5881
|
+
*
|
|
5882
|
+
* Returns `"ok"` once the shape resolved and its seed poke was attempted, or a
|
|
5883
|
+
* `{ code, message }` failure when the shape can't be resolved — an unknown /
|
|
5884
|
+
* RLS-denied shape (a base class with no registry resolves nothing), or a
|
|
5885
|
+
* `resolveShape` that threw (e.g. a cross-shard-join guard). The caller rolls
|
|
5886
|
+
* back the persisted attachment and errors instead of acking, so a client is
|
|
5887
|
+
* never left subscribed to a shape that will never deliver.
|
|
5888
|
+
*/
|
|
5889
|
+
private seedShapeSubscription;
|
|
5890
|
+
/**
|
|
5891
|
+
* Seed a non-`.global()` (op-log-backed) shape: either a catch-up diff over
|
|
5892
|
+
* `(sinceSeq, cursor]` when the client supplied a still-current checkpoint on
|
|
5893
|
+
* this epoch within the CDC retention window, or a full membership insert-poke
|
|
5894
|
+
* otherwise. The memo advances to `cursor` only once the poke is delivered, so
|
|
5895
|
+
* a failed send re-diffs from the prior point rather than skipping rows. May
|
|
5896
|
+
* throw (a stub `sql` handle, a membership probe failure); the caller converts
|
|
5897
|
+
* it to a structured `shape_subscribe` error.
|
|
5898
|
+
*/
|
|
5899
|
+
private seedOpLogShape;
|
|
5900
|
+
/**
|
|
5901
|
+
* Fan the membership diff of every shape affected by this flush to its
|
|
5902
|
+
* subscribers — the partial-replication parallel to
|
|
5903
|
+
* {@link ShardDO.refreshSubscriptions}, called alongside it from
|
|
5904
|
+
* {@link ShardDO.flushChangedTables}. For each socket (bounded fan-out, same
|
|
5905
|
+
* concurrency + `awaitWsDrain` backpressure as the subscription path) it
|
|
5906
|
+
* resolves each shape under the socket's identity, diffs only the shapes
|
|
5907
|
+
* whose table changed in `(memoCursor, frameCursor]`, and emits one poke
|
|
5908
|
+
* carrying a part per changed shape. No-op when no socket holds a shape.
|
|
5909
|
+
*/
|
|
5910
|
+
private pokeShapeSubscribers;
|
|
5911
|
+
/**
|
|
5912
|
+
* Diff every op-log-backed shape a socket holds against this flush, splitting
|
|
5913
|
+
* the results into the poke parts to send and the per-shape memo advances. A
|
|
5914
|
+
* `.global()` shape (driven by the alarm poll loop, not this flush) and a shape
|
|
5915
|
+
* whose table didn't change are skipped; a shape whose resolve/diff throws is
|
|
5916
|
+
* logged and skipped with its memo unadvanced so a later flush retries. Empty
|
|
5917
|
+
* diffs advance unconditionally; part-bearing shapes advance only once the
|
|
5918
|
+
* caller confirms the poke was delivered.
|
|
5919
|
+
*/
|
|
5920
|
+
private collectShapePokeParts;
|
|
5921
|
+
/**
|
|
5922
|
+
* Build the row-ops for a shape over the op range `(sinceSeq, upTo]`. Reads
|
|
5923
|
+
* the changelog (drained across pages), collapses to the latest op per row,
|
|
5924
|
+
* then runs ONE membership probe ({@link selectShapeMemberIds}) over the
|
|
5925
|
+
* changed ids: a row still in the set → upsert with its post-image doc
|
|
5926
|
+
* (projected to the shape's columns); a row that left the set, or any delete,
|
|
5927
|
+
* → `delete(key)` (a delete carries no post-image, so membership is
|
|
5928
|
+
* unknowable from the op alone — the client no-ops an unknown key).
|
|
5929
|
+
*/
|
|
5930
|
+
private buildShapeDiff;
|
|
5931
|
+
/** Build the full insert-poke of a shape's current membership — the first-seed/full-reseed rowset. */
|
|
5932
|
+
private buildShapeSeed;
|
|
5933
|
+
/**
|
|
5934
|
+
* Seed a `.global()`-table shape: read its full membership from D1, ship it
|
|
5935
|
+
* as one insert-poke, record the membership snapshot the alarm poll loop will
|
|
5936
|
+
* diff against, and arm the poll alarm. A global shape has no op-log cursor,
|
|
5937
|
+
* so the poke is stamped at this DO's current cursor (informational only) and
|
|
5938
|
+
* carries no resume base — a reconnect always re-seeds full.
|
|
5939
|
+
*/
|
|
5940
|
+
private seedGlobalShape;
|
|
5941
|
+
/**
|
|
5942
|
+
* Re-read a global shape's membership from D1 and poke only the diff against
|
|
5943
|
+
* the socket's last snapshot: a new key → `insert`, a changed projected value
|
|
5944
|
+
* → `update`, a vanished key → `delete`. The snapshot advances to the fresh
|
|
5945
|
+
* membership even when the diff is empty, so the next tick compares from here.
|
|
5946
|
+
* No frame is sent when nothing changed (the common steady-state tick).
|
|
5947
|
+
*/
|
|
5948
|
+
private refreshGlobalShape;
|
|
5949
|
+
/**
|
|
5950
|
+
* Read a socket's global-shape baseline, preferring the hot in-memory cache
|
|
5951
|
+
* and falling back to the durable `__global_shape_snapshot` table on a miss (a
|
|
5952
|
+
* cold socket after a hibernation eviction). The loaded baseline repopulates
|
|
5953
|
+
* the cache so subsequent ticks in this wake hit memory. An empty
|
|
5954
|
+
* `connectionId` (a socket that never went through the lifecycle-aware upgrade,
|
|
5955
|
+
* e.g. a unit harness) skips the durable read and behaves as in-memory-only.
|
|
5956
|
+
*/
|
|
5957
|
+
private readGlobalSnapshot;
|
|
5958
|
+
/** Record a socket's latest global-shape membership snapshot in the in-memory cache (creating the per-socket map lazily). */
|
|
5959
|
+
private recordGlobalSnapshot;
|
|
5960
|
+
/**
|
|
5961
|
+
* Load a durable global-shape baseline from SQLite, or an empty map when none
|
|
5962
|
+
* is stored / the durable path is unavailable. A stub `sql` handle (unit
|
|
5963
|
+
* harness) or a missing table degrades to in-memory-only behavior rather than
|
|
5964
|
+
* failing the poll tick.
|
|
5965
|
+
*/
|
|
5966
|
+
private loadGlobalSnapshot;
|
|
5967
|
+
/**
|
|
5968
|
+
* Persist a socket's global-shape baseline to SQLite so the poll-loop diff
|
|
5969
|
+
* survives hibernation. A no-op for a connection-id-less socket or a stub
|
|
5970
|
+
* `sql` handle (the in-memory cache then carries the baseline for the DO's
|
|
5971
|
+
* lifetime, matching the pre-durable behavior).
|
|
5972
|
+
*/
|
|
5973
|
+
private saveGlobalSnapshot;
|
|
5974
|
+
/**
|
|
5975
|
+
* Arm the poll alarm for `.global()` shapes if one isn't already pending.
|
|
5976
|
+
* Idempotent — every global-shape seed calls it, but only the first arms the
|
|
5977
|
+
* alarm. Degrades to a no-op when the runtime exposes no `setAlarm` (the unit
|
|
5978
|
+
* harness): a global shape is then seed-only, which the poll-loop tests assert
|
|
5979
|
+
* by driving {@link ShardDO.alarm} directly.
|
|
5980
|
+
*/
|
|
5981
|
+
private scheduleGlobalPoll;
|
|
5982
|
+
/**
|
|
5983
|
+
* Record a contained shape-tier error (poll / poke / seed) into the DO's log
|
|
5984
|
+
* ring without aborting the rest of the pass. The shape pipeline is a
|
|
5985
|
+
* best-effort fan-out: one socket's read or one shape's resolve failing must
|
|
5986
|
+
* never take down the others — so callers swallow the throw and surface it
|
|
5987
|
+
* here for diagnosis. `context` is a synthetic `shape:phase:subId` path.
|
|
5988
|
+
*/
|
|
5989
|
+
private recordShapeError;
|
|
5990
|
+
/**
|
|
5991
|
+
* Guard a global shape's materialized membership against {@link
|
|
5992
|
+
* ShardDO.GLOBAL_SHAPE_MAX_ROWS}. Returns `true` when the row count is within
|
|
5993
|
+
* the cap; otherwise records a diagnosable error and returns `false` so the
|
|
5994
|
+
* caller fails the shape closed (no snapshot retained, no poke sent) rather
|
|
5995
|
+
* than risking a DO eviction on an unbounded global table. The transient read
|
|
5996
|
+
* buffer is bounded by the same gate — an over-cap membership is dropped, not
|
|
5997
|
+
* snapshotted per socket.
|
|
5998
|
+
*/
|
|
5999
|
+
private withinGlobalShapeBound;
|
|
6000
|
+
/**
|
|
6001
|
+
* Refresh every `.global()`-table shape held across all live sockets, one
|
|
6002
|
+
* diff-poke per (socket, shape). Returns the number of global shapes still
|
|
6003
|
+
* subscribed so {@link ShardDO.alarm} knows whether to re-arm. Expired sockets
|
|
6004
|
+
* are dropped in passing (mirrors {@link ShardDO.pokeShapeSubscribers}).
|
|
6005
|
+
*/
|
|
6006
|
+
private pollGlobalShapes;
|
|
6007
|
+
/**
|
|
6008
|
+
* Refresh one socket's `.global()`-table shapes, containing per-shape
|
|
6009
|
+
* failures so a single throw never aborts the poll tick (and with it the
|
|
6010
|
+
* re-arm). Returns the count of global shapes still subscribed on this socket
|
|
6011
|
+
* — a failed `resolveShape`/read keeps its shape counted so the alarm keeps
|
|
6012
|
+
* polling and retries next tick.
|
|
6013
|
+
*/
|
|
6014
|
+
private pollSocketGlobalShapes;
|
|
6015
|
+
/**
|
|
6016
|
+
* Send one poke (`pokeStart` → `pokePart` per shape → `pokeEnd`) to a socket.
|
|
6017
|
+
* All parts apply atomically at `pokeEnd`. Returns `true` when every frame was
|
|
6018
|
+
* handed to the socket, `false` when a send threw mid-poke (the socket closed)
|
|
6019
|
+
* — callers must NOT advance their shape baselines on a `false` so the client
|
|
6020
|
+
* re-receives the rows on its next flush/reconnect instead of losing them.
|
|
6021
|
+
*/
|
|
6022
|
+
private sendPoke;
|
|
6023
|
+
/**
|
|
6024
|
+
* The recipient client's `__client_watermark` for stamping a poke's
|
|
6025
|
+
* `lastMutationId`, or `undefined` when the socket announced no `clientId`
|
|
6026
|
+
* (a client that doesn't use custom mutators — nothing to drop an overlay
|
|
6027
|
+
* for). Read off the attachment so it survives hibernation.
|
|
6028
|
+
*/
|
|
6029
|
+
private socketClientWatermark;
|
|
6030
|
+
/** Record a shape's poke baseline cursor on a socket (creating the per-socket map lazily). */
|
|
6031
|
+
private recordShapeMemo;
|
|
6032
|
+
/**
|
|
5285
6033
|
* Record `outcome` as this socket's diff baseline for `subId` without
|
|
5286
6034
|
* sending a frame. Used by the resume fast-path, where the client keeps its
|
|
5287
6035
|
* cached value but the server still needs a baseline so the next
|
|
@@ -5596,4 +6344,4 @@ interface WhereSqlStrategy {
|
|
|
5596
6344
|
* `undefined` when the input imposes no constraint (empty `where`).
|
|
5597
6345
|
*/
|
|
5598
6346
|
declare const compileWhereSql: (where: WhereInput | undefined, strategy: WhereSqlStrategy) => SQL | undefined;
|
|
5599
|
-
export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, AGGREGATE_SQL_FUNCTION, AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, type AuthMetrics, type AuthMetricsBucket, type BroadcastDelta, CDC_LOG_TABLE, type CacheEntry, type CapturedMailRow, type CdcChange, type Clock, type ColumnMeta, type ColumnMetaLike, ConflictError, type CountArgs, CountRlsUnsupportedError, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_MAX_RELATION_KEYS, type DataMigrationDocument, type DataMigrationLike, type DataMigrationTransform, type DatabaseWriterLike, type DependencyTracker, type DeployInfo, type ExportRow, type ExportShardAdminArgs, type ExportShardArgs, FUNCTION_METRICS_BUCKETS_TABLE, FUNCTION_METRICS_BUCKET_MS, FUNCTION_METRICS_BUCKET_RETENTION, FUNCTION_METRICS_INDEX_TABLE, FUNCTION_METRICS_TABLE, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FieldOperators, type FunctionCallStat, type FunctionMetricBucket, type FunctionMetricIndexHit, type FunctionStatsResult, type GroupByEntry, type GroupByOptions, type HibernatableWebSocket, type IdGenerator, type ImportError, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IndexDefinitionLike, type IndexRangeBuilderLike, LogBuffer, type LogEntry, type LogEventInput, type LogLevel, type LogSink, MAIL_RETENTION, MAIL_TABLE, MAX_SQL_ROWS, MIN_ADMIN_TOKEN_LENGTH, MIN_AUTH_SECRET_LENGTH, type MaskColumnMetadata, type MaskPoliciesResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type OnDeleteActionLike, type OrderByInput, type OrderKey, type PaginationOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type QueryArgs, type QueryPage, RANK_TIEBREAK, RELATION_FUNCTION_PREFIX, RLS_UNWRAP_SYMBOL, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReadHook, type ReadTablePageOptions, type RecordAuthEventInput, type RecordFunctionMetricInput, type RecordMailInput, type RelationDefinitionLike, type RenderedSql, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkDeleteArgs, type RunShardBulkDeleteResult, type RunShardExportArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, type RunTriggersOptions, SCAN_DEP, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type SearchFilterBuilderLike, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, type SelectMatchingIdsOptions, type ServerDefaultContextLike, SessionDO, type SessionRecord, type SettingEntry, type SettingKind, type SettingsResult, ShardDO, type ShardDOOptions, type ShardDOState, type ShardRankPageResult, ShardRegistryDO, type SocketAttachment, type SortDirection
|
|
6347
|
+
export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, AGGREGATE_SQL_FUNCTION, AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, type AuthMetrics, type AuthMetricsBucket, type BroadcastDelta, CDC_LOG_TABLE, type CacheEntry, type CapturedMailRow, type CdcChange, type Clock, type ColumnMeta, type ColumnMetaLike, ConflictError, type CountArgs, CountRlsUnsupportedError, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_MAX_RELATION_KEYS, type DataMigrationDocument, type DataMigrationLike, type DataMigrationTransform, type DatabaseWriterLike, type DependencyTracker, type DeployInfo, type ExportRow, type ExportShardAdminArgs, type ExportShardArgs, FLAGS_FUNCTION_PREFIX, FUNCTION_METRICS_BUCKETS_TABLE, FUNCTION_METRICS_BUCKET_MS, FUNCTION_METRICS_BUCKET_RETENTION, FUNCTION_METRICS_INDEX_TABLE, FUNCTION_METRICS_TABLE, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FieldOperators, type FlagEvaluation, type FlagsResult, type FunctionCallStat, type FunctionMetricBucket, type FunctionMetricIndexHit, type FunctionStatsResult, type GroupByEntry, type GroupByOptions, type HibernatableWebSocket, type IdGenerator, type ImportError, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IndexDefinitionLike, type IndexRangeBuilderLike, LogBuffer, type LogEntry, type LogEventInput, type LogLevel, type LogSink, MAIL_RETENTION, MAIL_TABLE, MAX_SQL_ROWS, MIN_ADMIN_TOKEN_LENGTH, MIN_AUTH_SECRET_LENGTH, type MaskColumnMetadata, type MaskPoliciesResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type OnDeleteActionLike, type OrderByInput, type OrderKey, type PaginationOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type QueryArgs, type QueryPage, type QueueMetadata, type QueuesResult, RANK_TIEBREAK, RELATION_FUNCTION_PREFIX, RLS_UNWRAP_SYMBOL, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReadHook, type ReadTablePageOptions, type RecordAuthEventInput, type RecordFunctionMetricInput, type RecordMailInput, type RelationDefinitionLike, type RenderedSql, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkDeleteArgs, type RunShardBulkDeleteResult, type RunShardExportArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, type RunTriggersOptions, SCAN_DEP, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type SearchFilterBuilderLike, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, type SelectMatchingIdsOptions, type ServerDefaultContextLike, SessionDO, type SessionRecord, type SettingEntry, type SettingKind, type SettingsResult, type ShapeSubscriptionQuery, ShardDO, type ShardDOOptions, type ShardDOState, type ShardRankPageResult, ShardRegistryDO, type SocketAttachment, type SortDirection, type SqlConsoleResult, type SqlCursor, type SqlEngine, type SqlExec, type StorageRuleMetadata, type StorageRulesResult, type StudioFeaturesResult, type SubscriptionEnvelope, type SubscriptionOutcome, type SubscriptionQuery, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemReaderOptions, type SystemReaderSchedulerLike, type SystemReaderStorageLike, type SystemTableName, type TableColumnsResult, type TableDefinitionLike, type TableIndexInfo, type TableIndexesResult, type TableInfo, type TablePage, type TableReaderLike, type TablesColumnsResult, type TransactionSqlLike, type TriggerContextLike, type TriggerDefinitionLike, type TriggerEventLike, type TriggerOpLike, type TriggerTimingLike, type ValidatorLike, type WhereInput, type WhereSqlStrategy, type WithInput, type WorkflowMetadata, type WorkflowsResult, type WriteEvent, type WriteHook, aggregateSqlFunction, aggregateTableName, applyCdcChanges, applyOnDelete, applySelect, armRestore, assertFlatPredicate, assertReadonly, assertShapeShardable, assertValidClientId, backfillAggregateIndexes, backfillRankIndexes, buildFtsMatch, buildSecurityAudit, buildSeekWhere, clearCapturedMail, coerceAggregateNumber, compileWhereSql, containsRelationPredicate, createDependencyTracker, createShardCtxDb, createSystemReader, decodeCursor, depKey, encodeAggregateKey, encodeCursor, encodePartitionKey, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureMailTable, exportShardRows, exportShardTable, facetColumn, fanOutScalarCounts, foldAggregateTally, ftsTableName, guardWriter, hasTrigger, importShardRows, isRelationPredicate, listTables, matchesRankStaticWhere, matchesStaticWhere, mergeWhere, normalizeCountArgument, normalizeIdStructurally, normalizeOrderKeys, parseExportShardArgs, parseImportShardArgs, planAggregateLookup, rankTableName, reactiveCacheKey, readAggregateValue, readAuthMetrics, readBookmark, readCapturedMail, readCdcChanges, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetrics, readFunctionMetricsTotals, readMigrationStatus, readTablePage, recordAuthEvent, recordCapturedMail, recordFunctionMetric, renderSql, resolveRankPartition, resolveRelationPredicates, resolveWith, runDataMigration, runReadonlySql, runRowValidators, runShardMigrations, runTriggers, scoreDocument, selectExportTables, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy, selectMatchingIds, serveRelationFanout, softDeleteScope, sortColumnName, stableStringify, stringifySearchText, subscriptionListDeltas, throwingScheduler, tokenizeSearch, trimCdcChanges, validateImportRow };
|