@lunora/do 1.0.0-alpha.13 → 1.0.0-alpha.15
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/dist/index.d.mts +260 -55
- package/dist/index.d.ts +260 -55
- package/dist/index.mjs +10 -7
- package/dist/packem_shared/{ADMIN_FUNCTIONS-D_UiYJFk.mjs → ADMIN_FUNCTIONS-fMl1vyt1.mjs} +40 -1
- package/dist/packem_shared/{NotUniqueError-DZQtH02h.mjs → NotUniqueError-BXn2j5vu.mjs} +1 -1
- package/dist/packem_shared/{ROOT_DO_SIZE_WARN_BYTES-XEs4csIH.mjs → ROOT_DO_SIZE_WARN_BYTES-CEVhBec2.mjs} +1033 -89
- package/dist/packem_shared/{ReactiveCache-1hDydFyv.mjs → ReactiveCache-BYlSGY0N.mjs} +1 -1
- package/dist/packem_shared/{ctx-db-shapes-DVoeZpo-.mjs → ctx-db-shapes-BQapRFjB.mjs} +1 -1
- package/dist/packem_shared/diffExternalSource-Cx9HUPJj.mjs +44 -0
- package/dist/packem_shared/isSourceDue-BMTJv65e.mjs +40 -0
- package/dist/packem_shared/materializeExternalRows-uKBx9H0s.mjs +23 -0
- package/dist/packem_shared/{serveRelationFanout-C6lDaesn.mjs → serveRelationFanout-EZLD9-O3.mjs} +1 -1
- package/dist/packem_shared/{stableStringify-CyHKJXre.mjs → stableStringify-MydiuScU.mjs} +10 -0
- package/dist/packem_shared/subscription-delivery-Z6nXHvQN.mjs +340 -0
- package/dist/packem_shared/subscriptionListDeltas-CXwfoEE_.mjs +1 -0
- package/package.json +1 -1
- package/dist/packem_shared/subscriptionListDeltas-ce84gpwL.mjs +0 -111
package/dist/index.d.mts
CHANGED
|
@@ -1214,6 +1214,36 @@ interface SocketAttachment {
|
|
|
1214
1214
|
whispers?: string[];
|
|
1215
1215
|
}
|
|
1216
1216
|
/**
|
|
1217
|
+
* A `shape_subscribe`'s resolved query: which `table` to replicate, the
|
|
1218
|
+
* identity-scoped `effectiveWhere` (the shape predicate AND-merged with the
|
|
1219
|
+
* table's RLS read base-where), the optional projected `columns` allow-list,
|
|
1220
|
+
* and whether the table is `.global()` (served by the latency-tiered poll path
|
|
1221
|
+
* rather than the CDC poke path). The codegen subclass's `resolveShape` builds
|
|
1222
|
+
* it under the socket's verified identity, so the membership query the poke
|
|
1223
|
+
* protocol runs is RLS-correct by construction.
|
|
1224
|
+
*/
|
|
1225
|
+
interface ResolvedShape {
|
|
1226
|
+
columns?: ReadonlyArray<string>;
|
|
1227
|
+
effectiveWhere?: WhereInput;
|
|
1228
|
+
/** `true` when the shape's table is `.global()` (lives in D1, not this DO's SQLite) — no per-DO op-log to diff, so served by the poll path. */
|
|
1229
|
+
global?: boolean;
|
|
1230
|
+
table: string;
|
|
1231
|
+
}
|
|
1232
|
+
/**
|
|
1233
|
+
* Identity a subscription/shape query is executed under, threaded EXPLICITLY
|
|
1234
|
+
* into the codegen `resolveShape`/`buildCtx` rather than read from the shared,
|
|
1235
|
+
* per-request identity fields. The value passed is the socket's OWN verified
|
|
1236
|
+
* identity (stamped on the {@link SocketAttachment} at the WS upgrade from the
|
|
1237
|
+
* runtime-minted `x-lunora-userid`/`x-lunora-identity` headers the client can't
|
|
1238
|
+
* forge), passed BY VALUE so a deferred refresh or interleaved RPC can't clobber
|
|
1239
|
+
* it. An anonymous socket leaves both fields `undefined`, so an RLS/`ctx.auth`
|
|
1240
|
+
* query fails closed (empty/denied) rather than leaking another user's data.
|
|
1241
|
+
*/
|
|
1242
|
+
interface SubscriptionIdentity {
|
|
1243
|
+
identity?: Record<string, unknown>;
|
|
1244
|
+
userId?: string;
|
|
1245
|
+
}
|
|
1246
|
+
/**
|
|
1217
1247
|
* One-shot backfill of every declared aggregate index. Used by tests and
|
|
1218
1248
|
* production hosts that want to populate counters up-front instead of on first
|
|
1219
1249
|
* read. Idempotent: counter rows that already exist are left alone, so it's
|
|
@@ -2317,6 +2347,112 @@ interface RenderedSql {
|
|
|
2317
2347
|
* identifiers quoted and placeholders numbered the way that engine expects.
|
|
2318
2348
|
*/
|
|
2319
2349
|
declare const renderSql: (engine: SqlEngine, query: SQL) => RenderedSql;
|
|
2350
|
+
/** The result of {@link diffExternalSource}: the changes to replay, and the baseline the next tick diffs from. */
|
|
2351
|
+
interface ExternalSourceDiffResult {
|
|
2352
|
+
/** Ordered for `applyCdcChanges`: upserts in pulled order, then deletes in baseline order. */
|
|
2353
|
+
changes: CdcChange[];
|
|
2354
|
+
/** `id → canonical-value JSON` — pass back as the `baseline` next tick (or persist for an incremental cursor). */
|
|
2355
|
+
nextBaseline: Map<string, string>;
|
|
2356
|
+
}
|
|
2357
|
+
/**
|
|
2358
|
+
* Project a row to the document the ingest loop stores + compares on: `_id` plus
|
|
2359
|
+
* either the `columns` allow-list or every field except the framework-assigned
|
|
2360
|
+
* `_creationTime` (which the source never supplies). Returned as a plain object;
|
|
2361
|
+
* key order is irrelevant because {@link stableStringify} sorts keys. Used for BOTH
|
|
2362
|
+
* the pulled side here and the local baseline, so the two are byte-identical for an
|
|
2363
|
+
* unchanged row.
|
|
2364
|
+
*/
|
|
2365
|
+
|
|
2366
|
+
/**
|
|
2367
|
+
* Diff a sourced table's freshly-pulled membership against the local baseline.
|
|
2368
|
+
* Returns the `CdcChange[]` to apply (in stable order: upserts in pulled order,
|
|
2369
|
+
* then deletes in baseline order) and the next baseline (`id → canonical JSON`).
|
|
2370
|
+
*/
|
|
2371
|
+
declare const diffExternalSource: (pulled: ReadonlyArray<Record<string, unknown>>, baseline: ReadonlyMap<string, string>, options: {
|
|
2372
|
+
columns?: ReadonlyArray<string>;
|
|
2373
|
+
table: string;
|
|
2374
|
+
}) => ExternalSourceDiffResult;
|
|
2375
|
+
/** The outcome of one materialize pass: how many changes were applied, and the baseline the next tick diffs from. */
|
|
2376
|
+
interface MaterializeResult {
|
|
2377
|
+
/** Number of `CdcChange`s applied (inserts + updates + deletes). Zero on a steady-state tick. */
|
|
2378
|
+
applied: number;
|
|
2379
|
+
/** `id → projected-value JSON` — the post-tick membership, to feed back as `baseline` next tick. */
|
|
2380
|
+
nextBaseline: Map<string, string>;
|
|
2381
|
+
}
|
|
2382
|
+
/**
|
|
2383
|
+
* Diff `pulled` against `baseline` and apply the delta to `writer`. Returns the
|
|
2384
|
+
* applied count and the next baseline. A steady-state tick (membership unchanged)
|
|
2385
|
+
* applies nothing and returns `applied: 0`.
|
|
2386
|
+
*/
|
|
2387
|
+
declare const materializeExternalRows: (writer: DatabaseWriterLike, pulled: ReadonlyArray<Record<string, unknown>>, baseline: ReadonlyMap<string, string>, options: {
|
|
2388
|
+
columns?: ReadonlyArray<string>;
|
|
2389
|
+
table: string;
|
|
2390
|
+
}) => Promise<MaterializeResult>;
|
|
2391
|
+
/**
|
|
2392
|
+
* Read the materialized table's current membership as the canonical full-pull
|
|
2393
|
+
* baseline (`id → canonical JSON`). Reuses the shape scanner (`selectShapeRows`)
|
|
2394
|
+
* and the SAME {@link projectExternalSourceRow} + {@link stableStringify} the diff
|
|
2395
|
+
* uses, so a stored row (with `_creationTime` + arbitrary key order) compares
|
|
2396
|
+
* byte-identical to its freshly-pulled source counterpart — an unchanged row
|
|
2397
|
+
* produces no spurious update.
|
|
2398
|
+
*/
|
|
2399
|
+
declare const readExternalSourceBaseline: (sql: SqlExec, table: string, columns?: ReadonlyArray<string>) => Map<string, string>;
|
|
2400
|
+
/**
|
|
2401
|
+
* Run one full-pull materialize tick: read the table's current membership as the
|
|
2402
|
+
* baseline, diff the freshly-pulled rows against it, and apply the delta. This is
|
|
2403
|
+
* the system-driven loop body the DO poll alarm calls — the table IS the baseline
|
|
2404
|
+
* (design §1 Fact A), so no separate snapshot is kept. Pass both the read handle
|
|
2405
|
+
* (`sql`) and the validated `writer` (the DO has both); they must address the same
|
|
2406
|
+
* table.
|
|
2407
|
+
*/
|
|
2408
|
+
declare const runExternalSourceTick: (sql: SqlExec, writer: DatabaseWriterLike, pulled: ReadonlyArray<Record<string, unknown>>, options: {
|
|
2409
|
+
columns?: ReadonlyArray<string>;
|
|
2410
|
+
table: string;
|
|
2411
|
+
}) => Promise<MaterializeResult>;
|
|
2412
|
+
/** The minimal SqlClient surface the poll loop calls (mirrors `@lunora/hyperdrive`'s `SqlClient`). */
|
|
2413
|
+
interface SourceClientLike {
|
|
2414
|
+
query: <Row = Record<string, unknown>>(text: string, parameters?: ReadonlyArray<unknown>) => Promise<Row[]>;
|
|
2415
|
+
}
|
|
2416
|
+
/** Poll cadence: `"manual"` (never auto-poll) or a minimum interval between polls. */
|
|
2417
|
+
type SourceRefresh = "manual" | {
|
|
2418
|
+
everyMs: number;
|
|
2419
|
+
};
|
|
2420
|
+
/** The runtime `.source(...)` config the poll loop reads — a structural mirror of `@lunora/server`'s `ExternalSourceDefinition` (only the fields the tick uses). */
|
|
2421
|
+
interface ExternalSourceLike {
|
|
2422
|
+
binding: string;
|
|
2423
|
+
columns?: ReadonlyArray<string>;
|
|
2424
|
+
idColumn?: string;
|
|
2425
|
+
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
2426
|
+
query: string;
|
|
2427
|
+
refresh?: SourceRefresh;
|
|
2428
|
+
tenantBy?: (shardKey: string) => ReadonlyArray<unknown>;
|
|
2429
|
+
}
|
|
2430
|
+
/**
|
|
2431
|
+
* Lift an external row to a Lunora document: the `idColumn` value becomes a
|
|
2432
|
+
* stringified `_id`, then either `map` shapes the body or every other column is
|
|
2433
|
+
* copied verbatim. Throws on a missing/null id, and on a non-scalar id, so a
|
|
2434
|
+
* misconfigured query fails loudly instead of materializing rows under the literal
|
|
2435
|
+
* id `"undefined"` (or collapsing many rows onto one id). Shared with
|
|
2436
|
+
* `@lunora/hyperdrive`'s `projectSourceRow`.
|
|
2437
|
+
*/
|
|
2438
|
+
declare const liftSourceId: (row: Record<string, unknown>, options?: {
|
|
2439
|
+
idColumn?: string;
|
|
2440
|
+
map?: (row: Record<string, unknown>) => Record<string, unknown>;
|
|
2441
|
+
}) => Record<string, unknown>;
|
|
2442
|
+
/**
|
|
2443
|
+
* Whether a source should poll on this alarm tick. `"manual"` never auto-polls;
|
|
2444
|
+
* `{ everyMs }` polls at most once per interval (the alarm floor still bounds it
|
|
2445
|
+
* from below); an omitted `refresh` polls every tick. `lastPolledMs` is `undefined`
|
|
2446
|
+
* before the first poll (always due).
|
|
2447
|
+
*/
|
|
2448
|
+
declare const isSourceDue: (refresh: SourceRefresh | undefined, lastPolledMs: number | undefined, nowMs: number) => boolean;
|
|
2449
|
+
/**
|
|
2450
|
+
* Pull a sourced table's tenant slice from `client`, project each row through
|
|
2451
|
+
* {@link liftSourceId}, and materialize it via {@link runExternalSourceTick}
|
|
2452
|
+
* (read local baseline → diff → apply through the validated CDC writer). The
|
|
2453
|
+
* per-table body the DO poll alarm runs; `shardKey` binds into `tenantBy`.
|
|
2454
|
+
*/
|
|
2455
|
+
declare const pullExternalSourceTick: (sql: SqlExec, writer: DatabaseWriterLike, client: SourceClientLike, table: string, source: ExternalSourceLike, shardKey: string) => Promise<MaterializeResult>;
|
|
2320
2456
|
/**
|
|
2321
2457
|
* Reserved `functionPath` prefix for admin introspection RPCs. These travel
|
|
2322
2458
|
* over the same `/_lunora/rpc` → shard `/rpc` path as ordinary functions, but
|
|
@@ -2371,6 +2507,7 @@ declare const ADMIN_FUNCTIONS: {
|
|
|
2371
2507
|
readonly getAuditLog: "__lunora_admin__:getAuditLog";
|
|
2372
2508
|
readonly getAuthMetrics: "__lunora_admin__:getAuthMetrics";
|
|
2373
2509
|
readonly getCapturedMail: "__lunora_admin__:getCapturedMail";
|
|
2510
|
+
readonly getFanoutMetrics: "__lunora_admin__:getFanoutMetrics";
|
|
2374
2511
|
readonly getFunctionStats: "__lunora_admin__:getFunctionStats";
|
|
2375
2512
|
readonly listSubscriptions: "__lunora_admin__:listSubscriptions";
|
|
2376
2513
|
readonly listTableIndexes: "__lunora_admin__:listTableIndexes";
|
|
@@ -3944,31 +4081,6 @@ interface SubscriptionOutcome {
|
|
|
3944
4081
|
tables: Set<string>;
|
|
3945
4082
|
}
|
|
3946
4083
|
/**
|
|
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
4084
|
* Classification of a watermarked custom-mutator push against the shard's
|
|
3973
4085
|
* `__client_watermark`: `expected` is the next in-order sequence, `kind`
|
|
3974
4086
|
* whether the push is a replay (`"already"`), the next one (`"next"`), or an
|
|
@@ -3979,35 +4091,6 @@ type ClientMutationClass = {
|
|
|
3979
4091
|
kind: "already" | "gap" | "next";
|
|
3980
4092
|
};
|
|
3981
4093
|
/**
|
|
3982
|
-
* Identity a subscription query is executed under, threaded EXPLICITLY into
|
|
3983
|
-
* `executeSubscription` → `buildCtx` rather than read from the shared,
|
|
3984
|
-
* per-request `currentRequestUserId`/`currentRequestIdentity` instance fields.
|
|
3985
|
-
*
|
|
3986
|
-
* The value passed is the socket's OWN verified identity, captured at the WS
|
|
3987
|
-
* upgrade from the runtime-forwarded, server-minted `x-lunora-userid` /
|
|
3988
|
-
* `x-lunora-identity` headers (the client cannot forge them — the runtime
|
|
3989
|
-
* strips any client-supplied copies) and stamped on the {@link SocketAttachment}.
|
|
3990
|
-
* `seedSubscription` and `refreshSubscriptions` read it off the attachment and
|
|
3991
|
-
* pass it here BY VALUE — never by reading the mutable per-request
|
|
3992
|
-
* `currentRequestUserId`/`currentRequestIdentity` instance fields, which a
|
|
3993
|
-
* deferred (`waitUntil`) refresh or a concurrently-interleaved RPC could be
|
|
3994
|
-
* mutating. That value-passing is what keeps a subscription re-run from
|
|
3995
|
-
* observing or clobbering an in-flight RPC's identity.
|
|
3996
|
-
*
|
|
3997
|
-
* Developer-facing consequence: a query that authorizes or filters on the
|
|
3998
|
-
* caller's identity — via `.use(rls(...))` or by reading `ctx.auth.userId` —
|
|
3999
|
-
* evaluates over the live channel under the CONNECTING user, so its seed and
|
|
4000
|
-
* every write-driven refresh return that user's rows, matching the one-shot
|
|
4001
|
-
* `fetch` RPC. An anonymous socket (no identity resolved at upgrade) leaves
|
|
4002
|
-
* both fields `undefined`, so such a query fails closed (empty/denied) rather
|
|
4003
|
-
* than leaking another user's data. See the lunora-realtime skill
|
|
4004
|
-
* ("Authorization & live queries").
|
|
4005
|
-
*/
|
|
4006
|
-
interface SubscriptionIdentity {
|
|
4007
|
-
identity?: Record<string, unknown>;
|
|
4008
|
-
userId?: string;
|
|
4009
|
-
}
|
|
4010
|
-
/**
|
|
4011
4094
|
* Optional shard-level configuration passed through `super(state, env, …)`.
|
|
4012
4095
|
* Reserved as a bag rather than positional args so subclasses don't break
|
|
4013
4096
|
* when new knobs land. Today the only knob is the reactive cache; future
|
|
@@ -4441,6 +4524,35 @@ declare abstract class ShardDO {
|
|
|
4441
4524
|
*/
|
|
4442
4525
|
private readonly metrics;
|
|
4443
4526
|
/**
|
|
4527
|
+
* Running fan-out cost counters surfaced by the
|
|
4528
|
+
* `__lunora_admin__:getFanoutMetrics` RPC — one tally for the reactive
|
|
4529
|
+
* shape-poke path (`pokeShapeSubscribers`) and one for the whisper broadcast
|
|
4530
|
+
* path (`broadcastWhisper`). Each pass records the sockets it iterated (the
|
|
4531
|
+
* O(subscribers) cost) and delivered to. In-memory and reset on
|
|
4532
|
+
* hibernation/restart, sharing `metrics.sinceMs` as the "since this instance
|
|
4533
|
+
* woke" epoch. This is the observability half of plan 075's auto-elastic
|
|
4534
|
+
* relay tier (Phase 1): measure the per-flush fan-out cost so the promotion
|
|
4535
|
+
* threshold is grounded in real numbers, with no behavior change.
|
|
4536
|
+
*/
|
|
4537
|
+
private readonly fanout;
|
|
4538
|
+
/**
|
|
4539
|
+
* The runtime's Durable Object namespace binding name (e.g. `"SHARD"`),
|
|
4540
|
+
* forwarded as `x-lunora-shard-binding` on every request so a DO can address
|
|
4541
|
+
* its siblings (`this.env[binding].getByName(...)`) for the relay hub. Absent
|
|
4542
|
+
* in single-DO mode / the unit harness — when absent, the relay tier is inert
|
|
4543
|
+
* and whispers stay shard-local (no behavior change). In-memory; re-learned per
|
|
4544
|
+
* request.
|
|
4545
|
+
*/
|
|
4546
|
+
private shardBinding;
|
|
4547
|
+
/**
|
|
4548
|
+
* The auto-elastic fan-out relay collaborator (plan 075) — an {@link OwnerRelay}
|
|
4549
|
+
* or {@link RelayMember} chosen ONCE from this DO's name, or `undefined` for an
|
|
4550
|
+
* unnamed (single-DO) DO where the relay tier is inert. All relay state +
|
|
4551
|
+
* transport lives on it, reached back through the {@link RelayHost} adapter, so
|
|
4552
|
+
* owner-only state can never sit next to relay-only state on this class.
|
|
4553
|
+
*/
|
|
4554
|
+
private readonly relay;
|
|
4555
|
+
/**
|
|
4444
4556
|
* Declared indexes (`table:index`) a query has exercised since this instance
|
|
4445
4557
|
* woke, stamped by `getCtxDbIndexUseHook`. In-memory and reset on
|
|
4446
4558
|
* hibernation/restart — drives the `unused_index` runtime advisory.
|
|
@@ -5181,6 +5293,14 @@ declare abstract class ShardDO {
|
|
|
5181
5293
|
*/
|
|
5182
5294
|
protected resolveShape(_name: string, _args: Record<string, unknown>, _identity?: SubscriptionIdentity): ResolvedShape | undefined;
|
|
5183
5295
|
/**
|
|
5296
|
+
* The RLS-uniform gate (plan 075 Phase 3): whether a reactive shape may be
|
|
5297
|
+
* relay-multicast — i.e. one delta is correct for **every** subscriber. The owner
|
|
5298
|
+
* decides it (see {@link OwnerRelay.isShapeRelayUniform} — a static RLS read-policy
|
|
5299
|
+
* guard plus claim-exhaustive `Proxy` probes, fail-closed); this thin delegation
|
|
5300
|
+
* is the seam the gate test exercises. A non-owner DO is never relay-uniform.
|
|
5301
|
+
*/
|
|
5302
|
+
protected isShapeRelayUniform(name: string, args: Record<string, unknown>): boolean;
|
|
5303
|
+
/**
|
|
5184
5304
|
* Read the FULL current membership of a `.global()`-table shape from its D1
|
|
5185
5305
|
* (or Hyperdrive) backend — the seed/poll source for the latency-tiered
|
|
5186
5306
|
* global shape path. A `.global()` table lives in another store with no
|
|
@@ -5198,6 +5318,32 @@ declare abstract class ShardDO {
|
|
|
5198
5318
|
*/
|
|
5199
5319
|
protected readGlobalShapeRows(_resolved: ResolvedShape, _identity?: SubscriptionIdentity): Promise<ShapeRow[]>;
|
|
5200
5320
|
/**
|
|
5321
|
+
* Poll external-source (`.source(...)`) tables once (plan 077): materialize
|
|
5322
|
+
* each sourced table's freshly-pulled tenant slice into this DO's SQLite. The
|
|
5323
|
+
* base `ShardDO` has no sourced tables, so it returns `0` and the ingest tier
|
|
5324
|
+
* stays dormant — zero behavior change for every existing DO. The codegen
|
|
5325
|
+
* subclass overrides it to, per sourced table, build a `createShardCtxDb`
|
|
5326
|
+
* writer, read the tenant slice from Hyperdrive under this DO's shard key, and
|
|
5327
|
+
* run `runExternalSourceTick` (read local baseline → diff → apply via the
|
|
5328
|
+
* validated CDC writer). Returns the number of sourced tables still being
|
|
5329
|
+
* polled, so the shared poll alarm ({@link ShardDO.alarm}) re-arms while ingest
|
|
5330
|
+
* is active.
|
|
5331
|
+
*/
|
|
5332
|
+
protected pollExternalSources(): Promise<number>;
|
|
5333
|
+
/**
|
|
5334
|
+
* Arm the shared poll alarm for external-source ingest (plan 077). The alarm is
|
|
5335
|
+
* shared with the global-shape poll tier; the codegen subclass calls this once
|
|
5336
|
+
* (on construction / first sourced write) so a sourced DO starts its ingest
|
|
5337
|
+
* loop, after which {@link ShardDO.alarm} re-arms itself while
|
|
5338
|
+
* {@link ShardDO.pollExternalSources} reports remaining work. Idempotent; a
|
|
5339
|
+
* no-op when the runtime exposes no `setAlarm` (unit harness).
|
|
5340
|
+
*/
|
|
5341
|
+
protected scheduleSourcePoll(): Promise<void>;
|
|
5342
|
+
/** This DO's shard key (its DO name), or `__root__` for the single-DO default. The `tenantBy` mapper binds it into the source query. */
|
|
5343
|
+
protected currentShardKey(): string;
|
|
5344
|
+
/** Record a contained external-source ingest failure (one sourced table's poll) into the log ring without aborting the others. */
|
|
5345
|
+
protected recordExternalSourceError(table: string, error: unknown): void;
|
|
5346
|
+
/**
|
|
5201
5347
|
* Look up a streaming-query function and return a thunk that produces the
|
|
5202
5348
|
* `AsyncIterable<unknown>` when handed an {@link AbortSignal}. The codegen
|
|
5203
5349
|
* subclass overrides this to dispatch via `LUNORA_FUNCTIONS`; the base
|
|
@@ -5390,6 +5536,26 @@ declare abstract class ShardDO {
|
|
|
5390
5536
|
*/
|
|
5391
5537
|
private errorToResponse;
|
|
5392
5538
|
/**
|
|
5539
|
+
* Batch dispatch (plan 088). Applies each `calls[]` entry through the SAME
|
|
5540
|
+
* single-call `/rpc` path (via a nested `this.fetch`), **sequentially**, so
|
|
5541
|
+
* the per-`(identity, mutationId)` idempotency dedup and the per-client
|
|
5542
|
+
* `__client_watermark` ordering are enforced entry-by-entry exactly as for an
|
|
5543
|
+
* individual call — no duplication of the dispatch core, no reordering.
|
|
5544
|
+
*
|
|
5545
|
+
* Failures are **per-slot, not fail-fast**: an entry that throws (or a
|
|
5546
|
+
* custom-mutator `OUT_OF_ORDER` gap) is captured in its own result slot and
|
|
5547
|
+
* later entries still run. Ordering is still safe — a later same-client
|
|
5548
|
+
* mutator after a gap re-classifies as a gap too (the watermark never
|
|
5549
|
+
* advanced), so it cannot apply out of order; unrelated entries/queries are
|
|
5550
|
+
* independent. The response is `{ results: [{ id, status, body }] }` in
|
|
5551
|
+
* request order; each `body` is the untouched single-call envelope (its
|
|
5552
|
+
* `result` already wire-encoded), so the client demuxes + decodes each
|
|
5553
|
+
* exactly as one call.
|
|
5554
|
+
*/
|
|
5555
|
+
private handleBatchRpc;
|
|
5556
|
+
/** Dispatch one batch entry through the single-call `/rpc` path and capture its envelope (plan 088). */
|
|
5557
|
+
private dispatchBatchEntry;
|
|
5558
|
+
/**
|
|
5393
5559
|
* Serve a reserved admin-introspection RPC (`__lunora_admin__:*`) for the
|
|
5394
5560
|
* data browser. Gated by `env.LUNORA_ADMIN_TOKEN`: introspection is
|
|
5395
5561
|
* **disabled unless the token is configured**, and when it is, the request
|
|
@@ -5674,6 +5840,16 @@ declare abstract class ShardDO {
|
|
|
5674
5840
|
* Read-only: it touches no SQLite and mutates no socket state.
|
|
5675
5841
|
*/
|
|
5676
5842
|
private collectSubscriptions;
|
|
5843
|
+
/**
|
|
5844
|
+
* Assemble the `__lunora_admin__:getFanoutMetrics` payload for the Studio
|
|
5845
|
+
* fan-out observability panel (plan 075 Phase 1). The point-in-time topic
|
|
5846
|
+
* subscriber counts are folded live from each socket's attachment via
|
|
5847
|
+
* {@link summarizeFanoutTopics}; the running per-path cost counters are the
|
|
5848
|
+
* in-memory {@link ShardDO.fanout} tallies, sharing `metrics.sinceMs` as the
|
|
5849
|
+
* "since this instance woke" epoch. Read-only: touches no SQLite and mutates
|
|
5850
|
+
* no socket state.
|
|
5851
|
+
*/
|
|
5852
|
+
private collectFanoutMetrics;
|
|
5677
5853
|
/** Resolve a `getAuditLog` admin read, parsing the optional `limit`/`sinceSeq` cursor args and ensuring the reserved table first. */
|
|
5678
5854
|
private readAdminAuditLog;
|
|
5679
5855
|
/**
|
|
@@ -5943,6 +6119,18 @@ declare abstract class ShardDO {
|
|
|
5943
6119
|
*/
|
|
5944
6120
|
private seedOpLogShape;
|
|
5945
6121
|
/**
|
|
6122
|
+
* Compute an op-log shape seed (cursor, epoch, the resume base, and the
|
|
6123
|
+
* membership `rowsPatch`) WITHOUT sending — the shared core of
|
|
6124
|
+
* {@link ShardDO.seedOpLogShape} (sends to a local socket) and the owner relay's
|
|
6125
|
+
* `buildShapeSeedFrames` (serializes the frames for a relay to deliver, plan 075
|
|
6126
|
+
* Phase 3, via the {@link RelayHost} seam). Resume only when CDC is on, the client is on this
|
|
6127
|
+
* epoch, its checkpoint doesn't run ahead of ours, and the log still covers it;
|
|
6128
|
+
* else a full re-seed. A fully-compacted log only proves "nothing missed" when
|
|
6129
|
+
* the client is already at `cursor`.
|
|
6130
|
+
* @returns the cursor/epoch, the resume base (`baseCheckpoint`), and the membership patch
|
|
6131
|
+
*/
|
|
6132
|
+
private computeOpLogShapeSeed;
|
|
6133
|
+
/**
|
|
5946
6134
|
* Fan the membership diff of every shape affected by this flush to its
|
|
5947
6135
|
* subscribers — the partial-replication parallel to
|
|
5948
6136
|
* {@link ShardDO.refreshSubscriptions}, called alongside it from
|
|
@@ -6168,6 +6356,15 @@ declare abstract class ShardDO {
|
|
|
6168
6356
|
* on older runtimes, where it degrades to a no-op.
|
|
6169
6357
|
*/
|
|
6170
6358
|
private armWebSocketKeepalive;
|
|
6359
|
+
/**
|
|
6360
|
+
* Route the non-RPC requests `fetch` handles before the shard-local RPC
|
|
6361
|
+
* endpoint: a WebSocket upgrade, and the internal `/_lunora/relay` owner↔relay
|
|
6362
|
+
* control channel (never reachable by a client — the runtime forwards only
|
|
6363
|
+
* worker-internal traffic there). Returns `undefined` for an RPC request, which
|
|
6364
|
+
* `fetch` then dispatches.
|
|
6365
|
+
* @returns the routed response, or `undefined` when this is an RPC request
|
|
6366
|
+
*/
|
|
6367
|
+
private routeNonRpc;
|
|
6171
6368
|
private handleWebSocketUpgrade;
|
|
6172
6369
|
/**
|
|
6173
6370
|
* Whether this shard has a `__cdc_log` table. The single source of the
|
|
@@ -6215,6 +6412,14 @@ declare abstract class ShardDO {
|
|
|
6215
6412
|
* but per-topic auth does not exist here; see `whisperSubscribe` on the client.
|
|
6216
6413
|
*/
|
|
6217
6414
|
private broadcastWhisper;
|
|
6415
|
+
/**
|
|
6416
|
+
* Deliver an already-serialized whisper `frame` to every local socket joined to
|
|
6417
|
+
* `topic`, excluding `exclude` (the sender, or `undefined` for a frame the relay
|
|
6418
|
+
* hub forwarded in — its sender lives on another DO). Records the fan-out pass
|
|
6419
|
+
* for `getFanoutMetrics` (plan 075 Phase 1). Pure delivery — no SQLite, no CDC.
|
|
6420
|
+
* @returns the number of sockets the frame was sent to
|
|
6421
|
+
*/
|
|
6422
|
+
private deliverWhisperLocal;
|
|
6218
6423
|
private readAttachment;
|
|
6219
6424
|
}
|
|
6220
6425
|
/**
|
|
@@ -6411,4 +6616,4 @@ interface WhereSqlStrategy {
|
|
|
6411
6616
|
* `undefined` when the input imposes no constraint (empty `where`).
|
|
6412
6617
|
*/
|
|
6413
6618
|
declare const compileWhereSql: (where: WhereInput | undefined, strategy: WhereSqlStrategy) => SQL | undefined;
|
|
6414
|
-
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 };
|
|
6619
|
+
export { ADMIN_FUNCTIONS, ADMIN_FUNCTION_PREFIX, AGGREGATE_SQL_FUNCTION, AUTH_METRICS_BUCKETS_TABLE, AUTH_METRICS_BUCKET_MS, AUTH_METRICS_BUCKET_RETENTION, AUTH_METRICS_TABLE, type AdvisoriesResult, type AdvisoryFinding, type AggregateIndexDefinitionLike, type AggregateOp, type AggregateOptions, type AggregateResult, type AggregateTally, type ApplyOnDeleteOptions, type AuditEntry, type AuditLogResult, type AuthMetrics, type AuthMetricsBucket, type BroadcastDelta, CDC_LOG_TABLE, type CacheEntry, type CapturedMailRow, type CdcChange, type Clock, type ColumnMeta, type ColumnMetaLike, ConflictError, type CountArgs, CountRlsUnsupportedError, type CtxDbOptions, DATA_MIGRATION_STATE_TABLE, DEFAULT_MAX_RELATION_KEYS, type DataMigrationDocument, type DataMigrationLike, type DataMigrationTransform, type DatabaseWriterLike, type DependencyTracker, type DeployInfo, type ExportRow, type ExportShardAdminArgs, type ExportShardArgs, type ExternalSourceDiffResult, type ExternalSourceLike, FLAGS_FUNCTION_PREFIX, FUNCTION_METRICS_BUCKETS_TABLE, FUNCTION_METRICS_BUCKET_MS, FUNCTION_METRICS_BUCKET_RETENTION, FUNCTION_METRICS_INDEX_TABLE, FUNCTION_METRICS_TABLE, type FacetColumnOptions, type FacetColumnResult, type FacetValue, type FieldOperators, type FlagEvaluation, type FlagsResult, type FunctionCallStat, type FunctionMetricBucket, type FunctionMetricIndexHit, type FunctionStatsResult, type GroupByEntry, type GroupByOptions, type HibernatableWebSocket, type IdGenerator, type ImportError, type ImportShardAdminArgs, type ImportShardArgs, type ImportShardResult, type IndexDefinitionLike, type IndexRangeBuilderLike, LogBuffer, type LogEntry, type LogEventInput, type LogLevel, type LogSink, MAIL_RETENTION, MAIL_TABLE, MAX_SQL_ROWS, MIN_ADMIN_TOKEN_LENGTH, MIN_AUTH_SECRET_LENGTH, type MaskColumnMetadata, type MaskPoliciesResult, type MaterializeResult, type MigrationDirection, type MigrationRunResult, type MigrationStatus, type MigrationStatusRow, type MutationDelta, type NestedWith, NotFoundError, NotUniqueError, type OnDeleteActionLike, type OrderByInput, type OrderKey, type PaginationOptions, type PitrBookmarkResult, type PitrRestoreArgs, type PitrRestoreResult, type PitrStorage, type QueryArgs, type QueryPage, type QueueMetadata, type QueuesResult, RANK_TIEBREAK, RELATION_FUNCTION_PREFIX, RLS_UNWRAP_SYMBOL, ROOT_DO_SIZE_WARN_BYTES, ROOT_SHARD_NAME, type RankDirection, type RankIndexDefinitionLike, type RankOptions, type RankPage, type RankPageOptions, type RankPageRow, type RankPageRowKey, type RankResult, type RankSortKeyLike, ReactiveCache, type ReactiveCacheOptions, type ReadHook, type ReadTablePageOptions, type RecordAuthEventInput, type RecordFunctionMetricInput, type RecordMailInput, type RelationDefinitionLike, type RenderedSql, type ResolveRelationPredicatesOptions, type ResolveWithOptions, type RestrictableQueryOptions, type RlsPoliciesResult, type RlsPolicyMetadata, RlsRequiredError, type RlsRoleMetadata, type RpcRequest, type RunDataMigrationOptions, type RunShardApplyCdcArgs, type RunShardApplyCdcResult, type RunShardBulkDeleteArgs, type RunShardBulkDeleteResult, type RunShardExportArgs, type RunShardImportArgs, type RunShardMigrationArgs, type RunShardRankBeforeArgs, type RunShardRankPageArgs, type RunShardWriteArgs, type RunShardWriteResult, type RunTriggersOptions, SCAN_DEP, SESSION_DO_TTL_DEFAULT, SHARD_REGISTRY_DO_NAME, type ScheduledFunctionDoc, type SchedulerLike, type SchemaLike, type SearchFilterBuilderLike, type SecurityAuditResult, type SecurityFinding, type SecurityFindingKind, type SecurityFindingLevel, type SelectMatchingIdsOptions, type ServerDefaultContextLike, SessionDO, type SessionRecord, type SettingEntry, type SettingKind, type SettingsResult, type ShapeSubscriptionQuery, ShardDO, type ShardDOOptions, type ShardDOState, type ShardRankPageResult, ShardRegistryDO, type SocketAttachment, type SortDirection, type SourceClientLike, type SourceRefresh, type SqlConsoleResult, type SqlCursor, type SqlEngine, type SqlExec, type StorageRuleMetadata, type StorageRulesResult, type StudioFeaturesResult, type SubscriptionEnvelope, type SubscriptionOutcome, type SubscriptionQuery, type SystemDatabaseReader, type SystemDoc, type SystemQuery, type SystemReaderOptions, type SystemReaderSchedulerLike, type SystemReaderStorageLike, type SystemTableName, type TableColumnsResult, type TableDefinitionLike, type TableIndexInfo, type TableIndexesResult, type TableInfo, type TablePage, type TableReaderLike, type TablesColumnsResult, type TransactionSqlLike, type TriggerContextLike, type TriggerDefinitionLike, type TriggerEventLike, type TriggerOpLike, type TriggerTimingLike, type ValidatorLike, type WhereInput, type WhereSqlStrategy, type WithInput, type WorkflowMetadata, type WorkflowsResult, type WriteEvent, type WriteHook, aggregateSqlFunction, aggregateTableName, applyCdcChanges, applyOnDelete, applySelect, armRestore, assertFlatPredicate, assertReadonly, assertShapeShardable, assertValidClientId, backfillAggregateIndexes, backfillRankIndexes, buildFtsMatch, buildSecurityAudit, buildSeekWhere, clearCapturedMail, coerceAggregateNumber, compileWhereSql, containsRelationPredicate, createDependencyTracker, createShardCtxDb, createSystemReader, decodeCursor, depKey, diffExternalSource, encodeAggregateKey, encodeCursor, encodePartitionKey, ensureAuthMetricsTables, ensureFunctionMetricsTables, ensureMailTable, exportShardRows, exportShardTable, facetColumn, fanOutScalarCounts, foldAggregateTally, ftsTableName, guardWriter, hasTrigger, importShardRows, isRelationPredicate, isSourceDue, liftSourceId, listTables, matchesRankStaticWhere, matchesStaticWhere, materializeExternalRows, mergeWhere, normalizeCountArgument, normalizeIdStructurally, normalizeOrderKeys, parseExportShardArgs, parseImportShardArgs, planAggregateLookup, pullExternalSourceTick, rankTableName, reactiveCacheKey, readAggregateValue, readAuthMetrics, readBookmark, readCapturedMail, readCdcChanges, readExternalSourceBaseline, readFunctionMetricBuckets, readFunctionMetricIndexHits, readFunctionMetrics, readFunctionMetricsTotals, readMigrationStatus, readTablePage, recordAuthEvent, recordCapturedMail, recordFunctionMetric, renderSql, resolveRankPartition, resolveRelationPredicates, resolveWith, runDataMigration, runExternalSourceTick, runReadonlySql, runRowValidators, runShardMigrations, runTriggers, scoreDocument, selectExportTables, selectIndexForAggregate, selectIndexForCount, selectIndexForGroupBy, selectMatchingIds, serveRelationFanout, softDeleteScope, sortColumnName, stableStringify, stringifySearchText, subscriptionListDeltas, throwingScheduler, tokenizeSearch, trimCdcChanges, validateImportRow };
|