@prisma/orm-framework 8.0.0-rc.1-dev.41 → 8.0.0-rc.1-dev.43
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/authoring-B2H-9qCv.d.mts +1 -0
- package/dist/{codec-LWTqo1GG.d.mts → codec-Ce07W3Mz.d.mts} +2 -2
- package/dist/{codec-LWTqo1GG.d.mts.map → codec-Ce07W3Mz.d.mts.map} +1 -1
- package/dist/{codec-types-720XoDZ0-Br-QaYK3.d.mts → codec-types-D6VRj2RE-BLElXc-O.d.mts} +5 -5
- package/dist/{codec-types-720XoDZ0-Br-QaYK3.d.mts.map → codec-types-D6VRj2RE-BLElXc-O.d.mts.map} +1 -1
- package/dist/{components-CS6Hvdt6.d.mts → components-CGA_WwEG.d.mts} +4 -4
- package/dist/{components-CS6Hvdt6.d.mts.map → components-CGA_WwEG.d.mts.map} +1 -1
- package/dist/components.d.mts +15 -15
- package/dist/components.mjs +2 -2
- package/dist/components__authoring.d.mts +2 -2
- package/dist/components__codec.d.mts +2 -2
- package/dist/components__components.d.mts +3 -3
- package/dist/components__control.d.mts +2 -2
- package/dist/components__emission.d.mts +3 -3
- package/dist/components__execution.d.mts +1 -1
- package/dist/components__psl-ast.d.mts +3 -3
- package/dist/components__runtime.d.mts +2 -2
- package/dist/components__runtime.mjs +2 -2
- package/dist/{config-types-Dw7Nvsbm.d.mts → config-types-CW4PDwMC.d.mts} +6 -6
- package/dist/{config-types-Dw7Nvsbm.d.mts.map → config-types-CW4PDwMC.d.mts.map} +1 -1
- package/dist/config.d.mts +1 -1
- package/dist/config__config-types.d.mts +1 -1
- package/dist/contract-authoring.d.mts +3 -3
- package/dist/{control-2lID5ISA.d.mts → control-BF8qzdnM.d.mts} +7 -7
- package/dist/{control-2lID5ISA.d.mts.map → control-BF8qzdnM.d.mts.map} +1 -1
- package/dist/emission-CmUO03gQ.d.mts +2 -0
- package/dist/{emission-types-BY5gWxhC-DcGn4rl_.d.mts → emission-types-DLXP34Ki-CFms3VrX.d.mts} +4 -4
- package/dist/{emission-types-BY5gWxhC-DcGn4rl_.d.mts.map → emission-types-DLXP34Ki-CFms3VrX.d.mts.map} +1 -1
- package/dist/errors.d.mts +1 -1
- package/dist/errors__execution.d.mts +1 -1
- package/dist/{execution-j0w6KfPD.d.mts → execution-CSnQT8EX.d.mts} +2 -2
- package/dist/{execution-j0w6KfPD.d.mts.map → execution-CSnQT8EX.d.mts.map} +1 -1
- package/dist/{execution-D3yaOlOT.d.mts → execution-Cyl2dXxX.d.mts} +2 -2
- package/dist/{execution-D3yaOlOT.d.mts.map → execution-Cyl2dXxX.d.mts.map} +1 -1
- package/dist/{framework-authoring-CctmQY6c-DdJ4E7XK.d.mts → framework-authoring-BhctBwih-DQ_6noDM.d.mts} +3 -3
- package/dist/{framework-authoring-CctmQY6c-DdJ4E7XK.d.mts.map → framework-authoring-BhctBwih-DQ_6noDM.d.mts.map} +1 -1
- package/dist/{framework-components-p8N1lyvE-Cgl21LGI.d.mts → framework-components-hZ2tO-KH-CdRXBOYd.d.mts} +5 -5
- package/dist/{framework-components-p8N1lyvE-Cgl21LGI.d.mts.map → framework-components-hZ2tO-KH-CdRXBOYd.d.mts.map} +1 -1
- package/dist/ids.d.mts +1 -1
- package/dist/{parse-0ZJjj_2N-Ds7oY9eP.d.mts → parse-0ZJjj_2N-DhQpSVmQ.d.mts} +3 -3
- package/dist/{parse-0ZJjj_2N-Ds7oY9eP.d.mts.map → parse-0ZJjj_2N-DhQpSVmQ.d.mts.map} +1 -1
- package/dist/{psl-ast-Bxf2Zocj.d.mts → psl-ast-BXZoFQBk.d.mts} +4 -4
- package/dist/{psl-ast-Bxf2Zocj.d.mts.map → psl-ast-BXZoFQBk.d.mts.map} +1 -1
- package/dist/{psl-ast-GTXfHjAV-HsPDAkQr.d.mts → psl-ast-CWJQF8LA-Vr5JNPdn.d.mts} +4 -4
- package/dist/{psl-ast-GTXfHjAV-HsPDAkQr.d.mts.map → psl-ast-CWJQF8LA-Vr5JNPdn.d.mts.map} +1 -1
- package/dist/psl-parser.d.mts +8 -8
- package/dist/psl-parser__interpret.d.mts +3 -3
- package/dist/psl-parser__syntax.d.mts +1 -1
- package/dist/psl-printer.d.mts +6 -6
- package/dist/{runtime-DYTFHGwh.mjs → runtime-BqzioOmU.mjs} +241 -87
- package/dist/runtime-BqzioOmU.mjs.map +1 -0
- package/dist/{runtime-Cne6hBaG.d.mts → runtime-Cuxw8obj.d.mts} +326 -189
- package/dist/runtime-Cuxw8obj.d.mts.map +1 -0
- package/dist/{symbol-table-CZ7EVCTL-HNuzTvNC.d.mts → symbol-table-CZ7EVCTL-CR-ncCpD.d.mts} +5 -5
- package/dist/{symbol-table-CZ7EVCTL-HNuzTvNC.d.mts.map → symbol-table-CZ7EVCTL-CR-ncCpD.d.mts.map} +1 -1
- package/dist/{types-import-spec-C9FyCno_-CONzlg_q.d.mts → types-import-spec-3mjbVBhI-DQI6BvKU.d.mts} +3 -3
- package/dist/{types-import-spec-C9FyCno_-CONzlg_q.d.mts.map → types-import-spec-3mjbVBhI-DQI6BvKU.d.mts.map} +1 -1
- package/package.json +15 -15
- package/dist/authoring-D6-6Uhns.d.mts +0 -1
- package/dist/emission-aQb87dEn.d.mts +0 -2
- package/dist/runtime-Cne6hBaG.d.mts.map +0 -1
- package/dist/runtime-DYTFHGwh.mjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { U as PlanMeta } from "./domain-envelope-D6Wn9AmZ-BqZKTT9U.mjs";
|
|
2
|
-
import { r as CodecCallContext } from "./codec-types-
|
|
2
|
+
import { r as CodecCallContext } from "./codec-types-D6VRj2RE-BLElXc-O.mjs";
|
|
3
3
|
//#region ../../../1-framework/1-core/framework-components/dist/runtime.d.mts
|
|
4
4
|
//#region src/annotations.d.ts
|
|
5
5
|
/**
|
|
@@ -302,23 +302,22 @@ interface RuntimeLog {
|
|
|
302
302
|
debug?(event: unknown): void;
|
|
303
303
|
}
|
|
304
304
|
/**
|
|
305
|
-
* Per-
|
|
306
|
-
* (`
|
|
307
|
-
* `
|
|
308
|
-
* middleware in
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* `CodecCallContext` (ADR 207). Middleware that wraps a
|
|
314
|
-
* network-backed SDK forwards `ctx.signal` into that SDK to
|
|
315
|
-
*
|
|
316
|
-
*
|
|
317
|
-
* Symmetric plumbing across all middleware phases
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* `onRow` needs the same cancellation reach as its
|
|
321
|
-
* counterpart.
|
|
305
|
+
* Per-operation context threaded through every middleware phase
|
|
306
|
+
* (`beforeQuery`, `interceptQuery`, `onRow`, `afterQuery` for queries, and
|
|
307
|
+
* `beforeExecute`, `interceptExecute`, `afterExecute` for executes). Allocated
|
|
308
|
+
* once per runtime operation and shared by reference across all middleware in
|
|
309
|
+
* the chain.
|
|
310
|
+
*
|
|
311
|
+
* - `signal` carries the per-operation `AbortSignal` -- the same reference
|
|
312
|
+
* passed to the runtime call and the same reference threaded into the
|
|
313
|
+
* per-call `CodecCallContext` (ADR 207). Middleware that wraps a
|
|
314
|
+
* network-backed SDK forwards `ctx.signal` into that SDK to propagate caller
|
|
315
|
+
* cancellation; pure-CPU middleware ignores it.
|
|
316
|
+
*
|
|
317
|
+
* Symmetric plumbing across all middleware phases is a deliberate choice: a
|
|
318
|
+
* middleware that wraps a downstream observability hook or post-processor in
|
|
319
|
+
* `afterQuery` / `afterExecute`, `interceptQuery` / `interceptExecute`, or
|
|
320
|
+
* `onRow` needs the same cancellation reach as its before hook.
|
|
322
321
|
*/
|
|
323
322
|
interface RuntimeMiddlewareContext {
|
|
324
323
|
readonly contract: unknown;
|
|
@@ -344,21 +343,22 @@ interface RuntimeMiddlewareContext {
|
|
|
344
343
|
*/
|
|
345
344
|
contentHash(exec: ExecutionPlan): Promise<string>;
|
|
346
345
|
/**
|
|
347
|
-
* Per-
|
|
348
|
-
* phase. Middleware that wraps async work or downstream
|
|
349
|
-
* primitives should observe this and abort early when the
|
|
350
|
-
* cancels.
|
|
346
|
+
* Per-operation cancellation signal threaded through every selected
|
|
347
|
+
* middleware phase. Middleware that wraps async work or downstream
|
|
348
|
+
* cancellable primitives should observe this and abort early when the
|
|
349
|
+
* consumer cancels.
|
|
351
350
|
*/
|
|
352
351
|
readonly signal?: AbortSignal;
|
|
353
352
|
/**
|
|
354
|
-
* Identifies the queryable scope this
|
|
353
|
+
* Identifies the queryable scope this operation is running under.
|
|
355
354
|
*
|
|
356
|
-
* - `'runtime'` — top-level `runtime.execute(plan)`.
|
|
357
|
-
* used by the standard read/write paths.
|
|
358
|
-
* - `'connection'` — `connection.execute(plan)`
|
|
359
|
-
* `runtime.connection()` checked out a connection from the pool.
|
|
360
|
-
* - `'transaction'` — `transaction.
|
|
361
|
-
* transaction
|
|
355
|
+
* - `'runtime'` — top-level `runtime.query(plan)` or `runtime.execute(plan)`.
|
|
356
|
+
* The default scope used by the standard read/write paths.
|
|
357
|
+
* - `'connection'` — `connection.query(plan)` or `connection.execute(plan)`
|
|
358
|
+
* after `runtime.connection()` checked out a connection from the pool.
|
|
359
|
+
* - `'transaction'` — `transaction.query(plan)` or
|
|
360
|
+
* `transaction.execute(plan)` inside an explicit transaction, or an
|
|
361
|
+
* operation routed through `withTransaction`.
|
|
362
362
|
*
|
|
363
363
|
* Middleware that should only act at the top level read this field to
|
|
364
364
|
* bypass non-runtime scopes. The cache middleware uses it to skip
|
|
@@ -372,28 +372,28 @@ interface RuntimeMiddlewareContext {
|
|
|
372
372
|
*/
|
|
373
373
|
readonly scope: 'runtime' | 'connection' | 'transaction';
|
|
374
374
|
/**
|
|
375
|
-
* Identity for one `execute()` call. The runtime mints a fresh
|
|
376
|
-
* `crypto.randomUUID()` when it constructs the per-
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
-
*
|
|
380
|
-
*
|
|
381
|
-
* correlate observations across the lifecycle of a single execute call
|
|
375
|
+
* Identity for one `query()` or `execute()` call. The runtime mints a fresh
|
|
376
|
+
* value via `crypto.randomUUID()` when it constructs the per-operation
|
|
377
|
+
* context, then threads that context through every hook in the selected
|
|
378
|
+
* query or execute lifecycle. Every hook in one call therefore observes
|
|
379
|
+
* the same `planExecutionId`; two calls for the same plan observe distinct
|
|
380
|
+
* values. Use this to correlate observations across a single operation
|
|
382
381
|
* (tracing, timing, audit). See ADR 220.
|
|
383
382
|
*/
|
|
384
383
|
readonly planExecutionId: string;
|
|
385
384
|
}
|
|
386
|
-
interface
|
|
387
|
-
readonly rowCount: number;
|
|
385
|
+
interface AfterResultBase {
|
|
388
386
|
readonly latencyMs: number;
|
|
389
|
-
readonly completed: boolean;
|
|
390
387
|
/**
|
|
391
|
-
* Indicates
|
|
388
|
+
* Indicates which execution path was selected.
|
|
392
389
|
*
|
|
393
|
-
* - `'driver'` — the default.
|
|
394
|
-
* `runDriver` / `
|
|
395
|
-
*
|
|
396
|
-
*
|
|
390
|
+
* - `'driver'` — the default. The result came from the underlying driver via
|
|
391
|
+
* `runDriver` / `runQueryWithMiddleware` or
|
|
392
|
+
* `runExecuteWithMiddleware`'s normal path.
|
|
393
|
+
* - `'middleware'` — a `RuntimeMiddleware.interceptQuery` or
|
|
394
|
+
* `RuntimeMiddleware.interceptExecute` hook selected the middleware
|
|
395
|
+
* interception path. This includes both supplying the result directly and
|
|
396
|
+
* completing with an interceptor error; the driver was not invoked.
|
|
397
397
|
*
|
|
398
398
|
* Observers (telemetry, lints, budgets) that need to distinguish between
|
|
399
399
|
* driver-served and middleware-served executions read this field.
|
|
@@ -401,37 +401,30 @@ interface AfterExecuteResult {
|
|
|
401
401
|
*/
|
|
402
402
|
readonly source: 'driver' | 'middleware';
|
|
403
403
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
* via `Symbol.asyncIterator` / `Symbol.iterator` fallback, so the
|
|
416
|
-
* orchestrator does not need to branch on the variant. Cached arrays in
|
|
417
|
-
* the cache middleware are the common case; streaming variants support
|
|
418
|
-
* future use cases like mock layers replaying recordings.
|
|
419
|
-
*
|
|
420
|
-
* Row shape is `Record<string, unknown>` — the same untyped shape
|
|
421
|
-
* `onRow` receives. The SQL runtime decodes intercepted rows through its
|
|
422
|
-
* normal codec pass, so interceptors cache and return raw (undecoded)
|
|
423
|
-
* rows.
|
|
424
|
-
*/
|
|
425
|
-
interface InterceptResult {
|
|
404
|
+
interface AfterQueryResult extends AfterResultBase {
|
|
405
|
+
readonly rowCount: number;
|
|
406
|
+
readonly completed: boolean;
|
|
407
|
+
}
|
|
408
|
+
type AfterExecuteResult = AfterResultBase & ({
|
|
409
|
+
readonly stats: RuntimeStatementStats;
|
|
410
|
+
readonly completed: true;
|
|
411
|
+
} | {
|
|
412
|
+
readonly completed: false;
|
|
413
|
+
});
|
|
414
|
+
interface QueryInterceptResult {
|
|
426
415
|
readonly rows: AsyncIterable<Record<string, unknown>> | Iterable<Record<string, unknown>>;
|
|
427
416
|
}
|
|
417
|
+
interface ExecuteInterceptResult {
|
|
418
|
+
readonly stats: RuntimeStatementStats;
|
|
419
|
+
}
|
|
428
420
|
/**
|
|
429
421
|
* Marker interface for family-specific param-ref mutators threaded into
|
|
430
|
-
* `beforeExecute` as the third argument. The framework treats
|
|
431
|
-
* opaquely — it allocates and forwards the family's mutator
|
|
432
|
-
*
|
|
433
|
-
* `SqlParamRefMutator` (over
|
|
434
|
-
* `MongoParamRefMutator` (over
|
|
422
|
+
* `beforeQuery` or `beforeExecute` as the third argument. The framework treats
|
|
423
|
+
* the mutator opaquely — it allocates and forwards the family's mutator
|
|
424
|
+
* instance so the operation-specific middleware runners can stay
|
|
425
|
+
* family-agnostic. SQL extends this with `SqlParamRefMutator` (over
|
|
426
|
+
* `ParamRef`); Mongo extends this with `MongoParamRefMutator` (over
|
|
427
|
+
* `MongoParamRef`).
|
|
435
428
|
*
|
|
436
429
|
* Extension authors target the family-specific mutator type, not this
|
|
437
430
|
* marker.
|
|
@@ -449,66 +442,124 @@ type ParamRefMutator = {
|
|
|
449
442
|
* `MongoMiddleware`) narrow `TPlan` to their concrete plan type.
|
|
450
443
|
*
|
|
451
444
|
* `TMutator` is the family-specific {@link ParamRefMutator} the runtime
|
|
452
|
-
* threads into `
|
|
453
|
-
*
|
|
454
|
-
*
|
|
455
|
-
*
|
|
445
|
+
* threads into `beforeQuery(plan, ctx, params)` or
|
|
446
|
+
* `beforeExecute(plan, ctx, params)` as a third argument. Existing
|
|
447
|
+
* `(plan)` / `(plan, ctx)` middleware bodies continue to compile — TypeScript
|
|
448
|
+
* permits assigning a function with fewer parameters to a function-typed slot
|
|
449
|
+
* that declares more. The third arg is additive.
|
|
456
450
|
*/
|
|
457
451
|
interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan, TMutator extends ParamRefMutator = ParamRefMutator> {
|
|
458
452
|
readonly name: string;
|
|
459
453
|
readonly familyId?: string;
|
|
460
454
|
readonly targetId?: string;
|
|
461
455
|
/**
|
|
462
|
-
*
|
|
463
|
-
* the
|
|
464
|
-
*
|
|
465
|
-
*
|
|
466
|
-
*
|
|
456
|
+
* Fires after the family runtime has produced a draft execution plan from
|
|
457
|
+
* the AST, but before the family encodes parameter values to driver wire
|
|
458
|
+
* format. Mutations applied via the family-specific `params` mutator are
|
|
459
|
+
* visible to the subsequent encode step.
|
|
460
|
+
*
|
|
461
|
+
* Lifecycle position (SQL example):
|
|
462
|
+
* `runBeforeCompile → lowerSqlPlan → beforeQuery → encodeParams → interceptQuery → driver query`.
|
|
463
|
+
*
|
|
464
|
+
* The `params` argument is a family-specific {@link ParamRefMutator}
|
|
465
|
+
* scoped to the value slots of `ParamRef` nodes in the plan's AST.
|
|
466
|
+
* Middleware that doesn't need to mutate params can ignore the argument;
|
|
467
|
+
* existing `(plan)` / `(plan, ctx)` bodies stay compatible.
|
|
468
|
+
*
|
|
469
|
+
* `ctx.signal` carries the per-operation `AbortSignal`; middleware that
|
|
470
|
+
* wraps a network SDK forwards it. Cooperative cancellation surfaces a
|
|
471
|
+
* `RUNTIME.ABORTED { phase: 'beforeQuery' }` envelope promptly even when the
|
|
472
|
+
* body ignores the signal.
|
|
473
|
+
*
|
|
474
|
+
* Intercept ordering: `interceptQuery` runs *after* this hook; an
|
|
475
|
+
* interceptor that short-circuits the driver path still observes the
|
|
476
|
+
* post-`beforeQuery`, fully-encoded plan. The trade-off is that any
|
|
477
|
+
* `beforeQuery` SDK round-trips happen even when a downstream interceptor
|
|
478
|
+
* would have skipped the driver entirely.
|
|
479
|
+
*/
|
|
480
|
+
beforeQuery?(plan: TPlan, ctx: RuntimeMiddlewareContext, params?: TMutator): void | Promise<void>;
|
|
481
|
+
/**
|
|
482
|
+
* Optional short-circuit hook for query executions. Runs inside
|
|
483
|
+
* `runQueryWithMiddleware`, after the orchestrator receives the lowered plan
|
|
484
|
+
* and after the `beforeQuery` hook fires. Middleware run in registration
|
|
485
|
+
* order; the first to return a non-`undefined` `QueryInterceptResult` wins,
|
|
486
|
+
* and subsequent middleware's `interceptQuery` does not fire.
|
|
467
487
|
*
|
|
468
|
-
* On a hit, `
|
|
469
|
-
* `
|
|
488
|
+
* On a hit, `beforeQuery` has already fired; `runDriver` and `onRow` are
|
|
489
|
+
* skipped. `afterQuery` still fires with `source: 'middleware'`.
|
|
470
490
|
*
|
|
471
|
-
* Returning `undefined` (or omitting the hook entirely) signals
|
|
472
|
-
*
|
|
491
|
+
* Returning `undefined` (or omitting the hook entirely) signals passthrough
|
|
492
|
+
* — execution proceeds through the normal driver path.
|
|
473
493
|
*
|
|
474
|
-
* Errors thrown inside `
|
|
475
|
-
* as the original `Error` — no envelope is
|
|
476
|
-
* Before rethrowing, `
|
|
477
|
-
* `source: 'middleware'`. Errors thrown by
|
|
478
|
-
* error path remain swallowed (existing semantics,
|
|
494
|
+
* Errors thrown inside `interceptQuery` are rethrown by
|
|
495
|
+
* `runQueryWithMiddleware` as the original `Error` — no envelope is
|
|
496
|
+
* guaranteed at this layer. Before rethrowing, `afterQuery` fires with
|
|
497
|
+
* `completed: false` and `source: 'middleware'`. Errors thrown by
|
|
498
|
+
* `afterQuery` during the error path remain swallowed (existing semantics,
|
|
499
|
+
* unchanged).
|
|
479
500
|
*
|
|
480
|
-
* Used by middleware that need to short-circuit execution and supply
|
|
501
|
+
* Used by middleware that need to short-circuit query execution and supply
|
|
481
502
|
* rows directly: caching, mocks, rate limiting, circuit breaking.
|
|
503
|
+
*
|
|
504
|
+
* `rows` accepts both `Iterable` (arrays, sync generators) and `AsyncIterable`
|
|
505
|
+
* (async generators). `for await` natively handles both via
|
|
506
|
+
* `Symbol.asyncIterator` / `Symbol.iterator` fallback, so the orchestrator
|
|
507
|
+
* does not need to branch on the variant. Cached arrays in the cache
|
|
508
|
+
* middleware are the common case; streaming variants support future use
|
|
509
|
+
* cases like mock layers replaying recordings.
|
|
510
|
+
*
|
|
511
|
+
* Row shape is `Record<string, unknown>` — the same untyped shape `onRow`
|
|
512
|
+
* receives. The SQL runtime decodes intercepted rows through its normal
|
|
513
|
+
* codec pass, so interceptors cache and return raw (undecoded) rows.
|
|
482
514
|
*/
|
|
483
|
-
|
|
515
|
+
interceptQuery?(plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<QueryInterceptResult | undefined>;
|
|
516
|
+
onRow?(row: Record<string, unknown>, plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
517
|
+
afterQuery?(plan: TPlan, result: AfterQueryResult, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
484
518
|
/**
|
|
485
|
-
* Fires after the family runtime has produced a draft execution
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
*
|
|
489
|
-
* encode step.
|
|
519
|
+
* Fires after the family runtime has produced a draft execution plan from
|
|
520
|
+
* the AST, but before the family encodes parameter values to driver wire
|
|
521
|
+
* format. Mutations applied via the family-specific `params` mutator are
|
|
522
|
+
* visible to the subsequent encode step.
|
|
490
523
|
*
|
|
491
524
|
* Lifecycle position (SQL example):
|
|
492
|
-
* `runBeforeCompile → lowerSqlPlan → beforeExecute → encodeParams →
|
|
525
|
+
* `runBeforeCompile → lowerSqlPlan → beforeExecute → encodeParams → interceptExecute → driver execute`.
|
|
493
526
|
*
|
|
494
527
|
* The `params` argument is a family-specific {@link ParamRefMutator}
|
|
495
528
|
* scoped to the value slots of `ParamRef` nodes in the plan's AST.
|
|
496
|
-
* Middleware that doesn't need to mutate params can ignore the
|
|
497
|
-
*
|
|
529
|
+
* Middleware that doesn't need to mutate params can ignore the argument;
|
|
530
|
+
* existing `(plan)` / `(plan, ctx)` bodies stay compatible.
|
|
498
531
|
*
|
|
499
|
-
* `ctx.signal` carries the per-
|
|
500
|
-
* wraps a network SDK forwards it. Cooperative cancellation
|
|
501
|
-
*
|
|
502
|
-
*
|
|
532
|
+
* `ctx.signal` carries the per-operation `AbortSignal`; middleware that
|
|
533
|
+
* wraps a network SDK forwards it. Cooperative cancellation surfaces a
|
|
534
|
+
* `RUNTIME.ABORTED { phase: 'beforeExecute' }` envelope promptly even when
|
|
535
|
+
* the body ignores the signal.
|
|
503
536
|
*
|
|
504
|
-
* Intercept ordering: `
|
|
505
|
-
* interceptor that short-circuits the driver path still observes
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
537
|
+
* Intercept ordering: `interceptExecute` runs *after* this hook; an
|
|
538
|
+
* interceptor that short-circuits the driver path still observes the
|
|
539
|
+
* post-`beforeExecute`, fully-encoded plan. The trade-off is that any
|
|
540
|
+
* `beforeExecute` SDK round-trips happen even when a downstream interceptor
|
|
541
|
+
* would have skipped the driver entirely.
|
|
509
542
|
*/
|
|
510
543
|
beforeExecute?(plan: TPlan, ctx: RuntimeMiddlewareContext, params?: TMutator): void | Promise<void>;
|
|
511
|
-
|
|
544
|
+
/**
|
|
545
|
+
* Optional short-circuit hook for execute operations. Middleware run in
|
|
546
|
+
* registration order; the first to return a non-`undefined`
|
|
547
|
+
* `ExecuteInterceptResult` wins, and subsequent middleware's
|
|
548
|
+
* `interceptExecute` does not fire.
|
|
549
|
+
*
|
|
550
|
+
* On a hit, `beforeExecute` has already fired; only the driver execute is
|
|
551
|
+
* skipped. The statistics supplied in `stats` are returned eagerly; there is
|
|
552
|
+
* no row stream and `onRow` is not fired. `afterExecute` still fires with
|
|
553
|
+
* `source: 'middleware'`.
|
|
554
|
+
*
|
|
555
|
+
* Returning `undefined` (or omitting the hook entirely) signals passthrough
|
|
556
|
+
* — execution proceeds through the normal driver path. Errors thrown inside
|
|
557
|
+
* `interceptExecute` are rethrown by `runExecuteWithMiddleware` as the
|
|
558
|
+
* original `Error`. Before rethrowing, `afterExecute` fires with
|
|
559
|
+
* `completed: false`; errors thrown by `afterExecute` during the error path
|
|
560
|
+
* remain swallowed.
|
|
561
|
+
*/
|
|
562
|
+
interceptExecute?(plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<ExecuteInterceptResult | undefined>;
|
|
512
563
|
afterExecute?(plan: TPlan, result: AfterExecuteResult, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
513
564
|
}
|
|
514
565
|
/**
|
|
@@ -537,47 +588,100 @@ type CrossFamilyMiddleware<TPlan extends QueryPlan = QueryPlan> = RuntimeMiddlew
|
|
|
537
588
|
readonly targetId?: undefined;
|
|
538
589
|
};
|
|
539
590
|
/**
|
|
540
|
-
* Optional per
|
|
591
|
+
* Optional per-operation options accepted by every family runtime.
|
|
541
592
|
*
|
|
542
|
-
* `signal` is the per-
|
|
543
|
-
*
|
|
544
|
-
*
|
|
545
|
-
*
|
|
546
|
-
* bit-for-bit.
|
|
593
|
+
* `signal` is the per-operation cancellation signal. The runtime threads it
|
|
594
|
+
* through middleware and codec calls; query row streams stop with
|
|
595
|
+
* `RUNTIME.ABORTED` when the caller aborts. Omitting the option (or passing
|
|
596
|
+
* `undefined`) preserves today's behavior bit-for-bit.
|
|
547
597
|
*/
|
|
548
598
|
interface RuntimeExecuteOptions {
|
|
549
599
|
readonly signal?: AbortSignal;
|
|
550
600
|
readonly scope?: 'runtime' | 'connection' | 'transaction';
|
|
551
601
|
}
|
|
552
602
|
/**
|
|
553
|
-
* Cross-family SPI for any runtime that can execute plans and be shut down.
|
|
603
|
+
* Cross-family SPI for any runtime that can query or execute plans and be shut down.
|
|
554
604
|
* Each family runtime (SQL, Mongo) satisfies this interface — SQL nominally,
|
|
555
605
|
* Mongo structurally (due to its phantom Row parameter using a unique symbol).
|
|
556
606
|
*
|
|
557
|
-
* The `_row` intersection on `
|
|
607
|
+
* The `_row` intersection on `query` connects the `Row` type parameter to the
|
|
558
608
|
* plan, mirroring how `QueryPlan<Row>` carries a phantom `_row?: Row`.
|
|
559
609
|
*/
|
|
610
|
+
interface RuntimeStatementStats {
|
|
611
|
+
readonly affectedRows: number;
|
|
612
|
+
}
|
|
560
613
|
interface RuntimeExecutor<TPlan extends QueryPlan> {
|
|
561
|
-
|
|
614
|
+
query<Row>(plan: TPlan & {
|
|
562
615
|
readonly _row?: Row;
|
|
563
616
|
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
617
|
+
execute(plan: TPlan, options?: RuntimeExecuteOptions): Promise<RuntimeStatementStats>;
|
|
564
618
|
close(): Promise<void>;
|
|
565
619
|
}
|
|
566
620
|
declare function checkMiddlewareCompatibility(middleware: RuntimeMiddleware, runtimeFamilyId: string, runtimeTargetId: string): void;
|
|
567
621
|
//#endregion
|
|
568
622
|
//#region src/execution/before-execute-chain.d.ts
|
|
623
|
+
/**
|
|
624
|
+
* Runs every middleware's `beforeQuery` hook in registration order,
|
|
625
|
+
* threading through the (optional) family-specific `paramsMutator`.
|
|
626
|
+
*
|
|
627
|
+
* Why this lives outside {@link runQueryWithMiddleware}: middleware that
|
|
628
|
+
* mutates parameter values (e.g. cipherstash's bulk-encrypt SDK
|
|
629
|
+
* round-trip) must run *before* the family runtime encodes those
|
|
630
|
+
* parameters to driver wire format. Family runtimes call
|
|
631
|
+
* `runBeforeQueryChain` between the AST → plan lowering step and
|
|
632
|
+
* the parameter encode step; the encode then observes the mutator's
|
|
633
|
+
* `currentParams()` view. `runQueryWithMiddleware` retains the rest of
|
|
634
|
+
* the query lifecycle (`interceptQuery`, driver/row source loop, `onRow`,
|
|
635
|
+
* `afterQuery`) but no longer fires `beforeQuery` itself.
|
|
636
|
+
*
|
|
637
|
+
* Lifecycle within this helper:
|
|
638
|
+
*
|
|
639
|
+
* 1. For each middleware in registration order, if `beforeQuery`
|
|
640
|
+
* is implemented:
|
|
641
|
+
* - `checkAborted(ctx, 'beforeQuery')` short-circuits if the
|
|
642
|
+
* caller already aborted at entry.
|
|
643
|
+
* - The hook is invoked with `(plan, ctx, paramsMutator)`. A
|
|
644
|
+
* middleware body that ignores the mutator stays compatible —
|
|
645
|
+
* JavaScript allows extra positional arguments.
|
|
646
|
+
* - If the hook returns a Promise, it is raced against
|
|
647
|
+
* `ctx.signal` via {@link raceAgainstAbort} so cooperative
|
|
648
|
+
* cancellation surfaces a `RUNTIME.ABORTED { phase:
|
|
649
|
+
* 'beforeQuery' }` envelope even when the body itself
|
|
650
|
+
* ignores the signal.
|
|
651
|
+
*
|
|
652
|
+
* Error propagation: any error thrown by a `beforeQuery` body
|
|
653
|
+
* (or surfaced by the abort race) propagates out of this helper
|
|
654
|
+
* unchanged. Family runtime entry points await this helper before invoking
|
|
655
|
+
* `runQueryWithMiddleware`, so a rejection prevents the runner and its
|
|
656
|
+
* `afterQuery` hook from running.
|
|
657
|
+
*
|
|
658
|
+
* Relationship to {@link runQueryWithMiddleware}: the framework's
|
|
659
|
+
* `RuntimeCore.query` template calls this helper between
|
|
660
|
+
* `lower(plan)` and `runQueryWithMiddleware(...)`. Family runtimes that
|
|
661
|
+
* override query preparation (e.g. SQL, which inlines lower + encode for
|
|
662
|
+
* direct mutator threading) call this helper themselves at the
|
|
663
|
+
* equivalent point — between the family's AST → draft-plan
|
|
664
|
+
* lowering and the parameter-encode step.
|
|
665
|
+
*
|
|
666
|
+
* Intercept ordering: this helper fires unconditionally before
|
|
667
|
+
* `runQueryWithMiddleware`. `interceptQuery` (inside
|
|
668
|
+
* `runQueryWithMiddleware`) therefore observes the post-`beforeQuery`
|
|
669
|
+
* plan — mutator mutations are visible in the params interceptors see.
|
|
670
|
+
* The trade-off is documented on `RuntimeMiddleware.interceptQuery`.
|
|
671
|
+
*/
|
|
672
|
+
declare function runBeforeQueryChain<TExec extends ExecutionPlan, TMutator extends ParamRefMutator = ParamRefMutator>(plan: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec, TMutator>>, ctx: RuntimeMiddlewareContext, paramsMutator?: TMutator): Promise<void>;
|
|
569
673
|
/**
|
|
570
674
|
* Runs every middleware's `beforeExecute` hook in registration order,
|
|
571
675
|
* threading through the (optional) family-specific `paramsMutator`.
|
|
572
676
|
*
|
|
573
|
-
* Why this lives outside {@link
|
|
677
|
+
* Why this lives outside {@link runExecuteWithMiddleware}: middleware that
|
|
574
678
|
* mutates parameter values (e.g. cipherstash's bulk-encrypt SDK
|
|
575
679
|
* round-trip) must run *before* the family runtime encodes those
|
|
576
680
|
* parameters to driver wire format. Family runtimes call
|
|
577
681
|
* `runBeforeExecuteChain` between the AST → plan lowering step and
|
|
578
682
|
* the parameter encode step; the encode then observes the mutator's
|
|
579
|
-
* `currentParams()` view. `
|
|
580
|
-
* the lifecycle (`
|
|
683
|
+
* `currentParams()` view. `runExecuteWithMiddleware` retains the rest of
|
|
684
|
+
* the execute lifecycle (`interceptExecute`, driver statistics execution,
|
|
581
685
|
* `afterExecute`) but no longer fires `beforeExecute` itself.
|
|
582
686
|
*
|
|
583
687
|
* Lifecycle within this helper:
|
|
@@ -597,23 +701,23 @@ declare function checkMiddlewareCompatibility(middleware: RuntimeMiddleware, run
|
|
|
597
701
|
*
|
|
598
702
|
* Error propagation: any error thrown by a `beforeExecute` body
|
|
599
703
|
* (or surfaced by the abort race) propagates out of this helper
|
|
600
|
-
* unchanged.
|
|
601
|
-
*
|
|
602
|
-
*
|
|
704
|
+
* unchanged. Family runtime entry points await this helper before invoking
|
|
705
|
+
* `runExecuteWithMiddleware`, so a rejection prevents the runner and its
|
|
706
|
+
* `afterExecute` hook from running.
|
|
603
707
|
*
|
|
604
|
-
* Relationship to {@link
|
|
708
|
+
* Relationship to {@link runExecuteWithMiddleware}: the framework's
|
|
605
709
|
* `RuntimeCore.execute` template calls this helper between
|
|
606
|
-
* `lower(plan)` and `
|
|
607
|
-
* override
|
|
710
|
+
* `lower(plan)` and `runExecuteWithMiddleware(...)`. Family runtimes that
|
|
711
|
+
* override execute (e.g. SQL, which inlines lower + encode for
|
|
608
712
|
* direct mutator threading) call this helper themselves at the
|
|
609
713
|
* equivalent point — between the family's AST → draft-plan
|
|
610
714
|
* lowering and the parameter-encode step.
|
|
611
715
|
*
|
|
612
716
|
* Intercept ordering: this helper fires unconditionally before
|
|
613
|
-
* `
|
|
614
|
-
* therefore observes the post-`beforeExecute`
|
|
615
|
-
* mutations are visible in the params interceptors see.
|
|
616
|
-
* trade-off is documented on `RuntimeMiddleware.
|
|
717
|
+
* `runExecuteWithMiddleware`. `interceptExecute` (inside
|
|
718
|
+
* `runExecuteWithMiddleware`) therefore observes the post-`beforeExecute`
|
|
719
|
+
* plan — mutator mutations are visible in the params interceptors see.
|
|
720
|
+
* The trade-off is documented on `RuntimeMiddleware.interceptExecute`.
|
|
617
721
|
*/
|
|
618
722
|
declare function runBeforeExecuteChain<TExec extends ExecutionPlan, TMutator extends ParamRefMutator = ParamRefMutator>(plan: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec, TMutator>>, ctx: RuntimeMiddlewareContext, paramsMutator?: TMutator): Promise<void>;
|
|
619
723
|
//#endregion
|
|
@@ -644,17 +748,18 @@ declare function runtimeError(code: string, message: string, details?: Record<st
|
|
|
644
748
|
* - `'decode'` — abort fired during `decodeRow` / `decodeField`.
|
|
645
749
|
* - `'stream'` — abort fired between rows or before any codec call
|
|
646
750
|
* (already-aborted at entry).
|
|
647
|
-
* - `'
|
|
648
|
-
* on entry to or during
|
|
751
|
+
* - `'beforeQuery'` / `'beforeExecute'` / `'afterQuery'` /
|
|
752
|
+
* `'afterExecute'` / `'onRow'` — abort fired on entry to or during
|
|
753
|
+
* the corresponding middleware phase
|
|
649
754
|
* (cooperative cancellation per the param-transform seam).
|
|
650
755
|
*/
|
|
651
756
|
declare const RUNTIME_ABORTED: "RUNTIME.ABORTED";
|
|
652
757
|
/** Discriminator placed in `details.phase` of a `RUNTIME.ABORTED` envelope. */
|
|
653
|
-
type RuntimeAbortedPhase = 'encode' | 'decode' | 'stream' | 'beforeExecute' | 'afterExecute' | 'onRow';
|
|
758
|
+
type RuntimeAbortedPhase = 'encode' | 'decode' | 'stream' | 'beforeQuery' | 'beforeExecute' | 'afterQuery' | 'afterExecute' | 'onRow';
|
|
654
759
|
/**
|
|
655
760
|
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the
|
|
656
761
|
* abort was observed — codec call sites (`encode` / `decode` / `stream`)
|
|
657
|
-
* or middleware seams
|
|
762
|
+
* or operation-specific middleware seams, as
|
|
658
763
|
* enumerated on {@link RuntimeAbortedPhase}. Cause carries
|
|
659
764
|
* `signal.reason` verbatim from the platform — native abort produces a
|
|
660
765
|
* `DOMException`, explicit `controller.abort(reason)` produces whatever
|
|
@@ -710,49 +815,84 @@ declare function raceAgainstAbort<T>(work: Promise<T>, signal: AbortSignal | und
|
|
|
710
815
|
//#endregion
|
|
711
816
|
//#region src/execution/run-with-middleware.d.ts
|
|
712
817
|
/**
|
|
713
|
-
* Drives a single execution of `runDriver()` through the middleware
|
|
714
|
-
* lifecycle's
|
|
818
|
+
* Drives a single query execution of `runDriver()` through the middleware
|
|
819
|
+
* lifecycle's `interceptQuery` + row-source + termination phases.
|
|
715
820
|
*
|
|
716
821
|
* Lifecycle, in order:
|
|
717
|
-
* 1. For each middleware in registration order: `
|
|
718
|
-
* first non-`undefined` result wins; subsequent middleware's
|
|
719
|
-
* does not fire. On a hit, the runtime emits a
|
|
720
|
-
* debug event naming the winning middleware,
|
|
721
|
-
* the intercepted rows, and proceeds with
|
|
722
|
-
* all-passthrough (every `
|
|
723
|
-
* `source: 'driver'` is used and the
|
|
822
|
+
* 1. For each middleware in registration order: `interceptQuery(exec, ctx)`.
|
|
823
|
+
* The first non-`undefined` result wins; subsequent middleware's
|
|
824
|
+
* `interceptQuery` does not fire. On a hit, the runtime emits a
|
|
825
|
+
* `middleware.interceptQuery` debug event naming the winning middleware,
|
|
826
|
+
* switches the row source to the intercepted rows, and proceeds with
|
|
827
|
+
* `source: 'middleware'`. On all-passthrough (every `interceptQuery`
|
|
828
|
+
* returns `undefined` or is omitted), `source: 'driver'` is used and the
|
|
829
|
+
* row source is `runDriver()`.
|
|
724
830
|
* 2. Iterate the row source. On the driver path, for each row, for each
|
|
725
831
|
* middleware in registration order: `onRow(row, exec, ctx)`; then yield
|
|
726
832
|
* the row. On the intercepted hit path, `onRow` is skipped — intercepted
|
|
727
833
|
* rows did not originate from a driver row stream — but rows are still
|
|
728
834
|
* yielded to the consumer in order.
|
|
729
835
|
* 3. On successful completion: for each middleware in registration order:
|
|
730
|
-
* `
|
|
836
|
+
* `afterQuery(exec, { rowCount, latencyMs, completed: true, source },
|
|
731
837
|
* ctx)`.
|
|
732
838
|
* 4. On any error thrown during steps 1–2: for each middleware in
|
|
733
|
-
* registration order: `
|
|
734
|
-
* completed: false, source }, ctx)`. Errors thrown by `
|
|
839
|
+
* registration order: `afterQuery(exec, { rowCount, latencyMs,
|
|
840
|
+
* completed: false, source }, ctx)`. Errors thrown by `afterQuery`
|
|
735
841
|
* during the error path are swallowed so they do not mask the original
|
|
736
842
|
* error. The original error is then rethrown.
|
|
737
843
|
*
|
|
738
|
-
* `
|
|
739
|
-
* {@link
|
|
740
|
-
*
|
|
741
|
-
*
|
|
742
|
-
*
|
|
743
|
-
*
|
|
744
|
-
* encoded plan; interceptors therefore observe a fully-mutated,
|
|
844
|
+
* `beforeQuery` is **not** fired here — see
|
|
845
|
+
* {@link runBeforeQueryChain} in `before-execute-chain.ts`. Family runtimes
|
|
846
|
+
* call that helper between the AST → plan lowering step and the parameter
|
|
847
|
+
* encode step so middleware that mutates ParamRef values can have its
|
|
848
|
+
* mutations visible to encode. `runQueryWithMiddleware` operates on the
|
|
849
|
+
* fully-encoded plan; interceptors therefore observe a fully-mutated,
|
|
745
850
|
* encoded plan.
|
|
746
851
|
*
|
|
747
|
-
* The `source` field on `
|
|
748
|
-
*
|
|
749
|
-
*
|
|
852
|
+
* The `source` field on `AfterQueryResult` lets observers (telemetry, lints,
|
|
853
|
+
* budgets) distinguish driver-served from middleware-served executions
|
|
854
|
+
* without needing their own out-of-band signal.
|
|
750
855
|
*
|
|
751
856
|
* This helper is the single canonical implementation of the
|
|
752
|
-
* intercept-and-row-source loop; family runtimes should not
|
|
753
|
-
|
|
857
|
+
* intercept-and-row-source loop; family runtimes should not reimplement it.
|
|
858
|
+
*/
|
|
859
|
+
declare function runQueryWithMiddleware<TExec extends ExecutionPlan, Row>(exec: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec>>, ctx: RuntimeMiddlewareContext, runDriver: () => AsyncIterable<Row>): AsyncIterableResult<Row>;
|
|
860
|
+
/**
|
|
861
|
+
* Drives a single execute operation through the middleware
|
|
862
|
+
* `interceptExecute` + statistics + termination phases.
|
|
863
|
+
*
|
|
864
|
+
* Lifecycle, in order:
|
|
865
|
+
* 1. For each middleware in registration order: `interceptExecute(exec, ctx)`.
|
|
866
|
+
* The first non-`undefined` result wins; subsequent middleware's
|
|
867
|
+
* `interceptExecute` does not fire. On a hit, the runtime emits a
|
|
868
|
+
* `middleware.interceptExecute` debug event naming the winning middleware,
|
|
869
|
+
* uses the returned `stats`, and proceeds with `source: 'middleware'`.
|
|
870
|
+
* On all-passthrough (every `interceptExecute` returns `undefined` or is
|
|
871
|
+
* omitted), `source: 'driver'` is used and `runDriver()` supplies the
|
|
872
|
+
* statistics.
|
|
873
|
+
* 2. Execute operations return eager statistics. There is no row stream and
|
|
874
|
+
* `onRow` does not fire.
|
|
875
|
+
* 3. On successful completion: for each middleware in registration order:
|
|
876
|
+
* `afterExecute(exec, { stats, latencyMs, completed: true, source }, ctx)`.
|
|
877
|
+
* 4. On any error thrown during steps 1–2: for each middleware in
|
|
878
|
+
* registration order: `afterExecute(exec, { latencyMs, completed: false,
|
|
879
|
+
* source }, ctx)`. Errors thrown by `afterExecute` during the error path
|
|
880
|
+
* are swallowed so they do not mask the original error. The original
|
|
881
|
+
* error is then rethrown.
|
|
882
|
+
*
|
|
883
|
+
* `beforeExecute` is **not** fired here — see
|
|
884
|
+
* {@link runBeforeExecuteChain} in `before-execute-chain.ts`. Family runtimes
|
|
885
|
+
* call that helper between the AST → plan lowering step and the parameter
|
|
886
|
+
* encode step so middleware that mutates ParamRef values can have its
|
|
887
|
+
* mutations visible to encode. `runExecuteWithMiddleware` operates on the
|
|
888
|
+
* fully-encoded plan; interceptors therefore observe a fully-mutated,
|
|
889
|
+
* encoded plan.
|
|
890
|
+
*
|
|
891
|
+
* The `source` field on `AfterExecuteResult` lets observers (telemetry, lints,
|
|
892
|
+
* budgets) distinguish driver-served from middleware-served executions
|
|
893
|
+
* without needing their own out-of-band signal.
|
|
754
894
|
*/
|
|
755
|
-
declare function
|
|
895
|
+
declare function runExecuteWithMiddleware<TExec extends ExecutionPlan>(exec: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec>>, ctx: RuntimeMiddlewareContext, runDriver: () => Promise<RuntimeStatementStats>): Promise<RuntimeStatementStats>;
|
|
756
896
|
//#endregion
|
|
757
897
|
//#region src/execution/runtime-core.d.ts
|
|
758
898
|
/**
|
|
@@ -769,34 +909,30 @@ interface RuntimeCoreOptions<TMiddleware extends RuntimeMiddleware<ExecutionPlan
|
|
|
769
909
|
/**
|
|
770
910
|
* Family-agnostic abstract runtime base.
|
|
771
911
|
*
|
|
772
|
-
* Defines the
|
|
912
|
+
* Defines the shared operation-specific middleware lifecycles:
|
|
773
913
|
*
|
|
774
914
|
* 1. `runBeforeCompile(plan)` — concrete; defaults to identity. SQL overrides
|
|
775
|
-
* this to run its `beforeCompile` middleware-hook chain.
|
|
915
|
+
* this to run its shared `beforeCompile` middleware-hook chain.
|
|
776
916
|
* 2. `lower(plan)` — abstract. Each family produces its `*ExecutionPlan`
|
|
777
917
|
* (SQL via `lowerSqlPlan`, Mongo via `adapter.lower`).
|
|
778
|
-
* 3. `
|
|
779
|
-
*
|
|
780
|
-
*
|
|
781
|
-
*
|
|
782
|
-
*
|
|
783
|
-
*
|
|
784
|
-
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
* Concrete subclasses must implement `lower`, `runDriver`, and `close`.
|
|
918
|
+
* 3. Queries run `beforeQuery`; statements run `beforeExecute`. Both chains
|
|
919
|
+
* run after lowering and before their matching driver terminal. Family
|
|
920
|
+
* runtimes that expose a params mutator to downstream encoding override
|
|
921
|
+
* the operation and call the matching helper at the pre-encode point.
|
|
922
|
+
* 4. The matching runner processes `interceptQuery` or `interceptExecute`
|
|
923
|
+
* before invoking the driver. Queries then fire `onRow` and `afterQuery`;
|
|
924
|
+
* statements fire `afterExecute`.
|
|
925
|
+
*
|
|
926
|
+
* Concrete subclasses must implement `lower`, `runDriver`, `runExecute`, and
|
|
927
|
+
* `close`.
|
|
790
928
|
*
|
|
791
929
|
* The class is generic over:
|
|
792
930
|
* - `TPlan` — the family's pre-lowering plan type.
|
|
793
931
|
* - `TExec` — the family's post-lowering (executable) plan type.
|
|
794
932
|
* - `TMiddleware` — the family's middleware type. Constrained to
|
|
795
|
-
* `RuntimeMiddleware<TExec>` because
|
|
796
|
-
*
|
|
797
|
-
*
|
|
798
|
-
* tightened to `<TExec>` here so the helper call typechecks; the
|
|
799
|
-
* intent is unchanged — middleware sees the post-lowering plan.)
|
|
933
|
+
* `RuntimeMiddleware<TExec>` because the operation-specific runners invoke
|
|
934
|
+
* hooks with the lowered `TExec`. Middleware therefore sees the
|
|
935
|
+
* post-lowering plan.
|
|
800
936
|
*/
|
|
801
937
|
declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends ExecutionPlan, TMiddleware extends RuntimeMiddleware<TExec>> implements RuntimeExecutor<TPlan> {
|
|
802
938
|
protected readonly middleware: ReadonlyArray<TMiddleware>;
|
|
@@ -813,11 +949,10 @@ declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends Execut
|
|
|
813
949
|
* Family-specific: SQL produces `{ sql, params, ast?, ... }`; Mongo
|
|
814
950
|
* produces `{ command, ... }`.
|
|
815
951
|
*
|
|
816
|
-
* `ctx` carries per-
|
|
817
|
-
* `CodecCallContext`); concrete subclasses forward it to the
|
|
818
|
-
*
|
|
819
|
-
*
|
|
820
|
-
* `execute()` call and threads the same reference everywhere; the
|
|
952
|
+
* `ctx` carries per-operation cancellation (and any future fields on
|
|
953
|
+
* `CodecCallContext`); concrete subclasses forward it to the encode-side
|
|
954
|
+
* codec dispatch site. The runtime allocates one ctx per operation call
|
|
955
|
+
* and threads the same reference everywhere; the
|
|
821
956
|
* `signal` field inside may be `undefined`, but the ctx object itself
|
|
822
957
|
* is always present.
|
|
823
958
|
*/
|
|
@@ -826,17 +961,19 @@ declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends Execut
|
|
|
826
961
|
* Drive the underlying transport for a lowered `TExec`. Yields raw rows
|
|
827
962
|
* directly from the driver as `Record<string, unknown>`; codec decoding
|
|
828
963
|
* (if any) is the subclass's responsibility, applied by wrapping
|
|
829
|
-
* `
|
|
964
|
+
* `query()` rather than living inside this hook.
|
|
830
965
|
*
|
|
831
|
-
* The `Row` type parameter on `
|
|
966
|
+
* The `Row` type parameter on `query()` is satisfied by the caller via
|
|
832
967
|
* the plan's phantom `_row`; the runtime treats rows as opaque records
|
|
833
968
|
* here and trusts the caller's row typing.
|
|
834
969
|
*/
|
|
835
970
|
protected abstract runDriver(exec: TExec): AsyncIterable<Record<string, unknown>>;
|
|
971
|
+
protected abstract runExecute(exec: TExec): Promise<RuntimeStatementStats>;
|
|
836
972
|
abstract close(): Promise<void>;
|
|
837
|
-
|
|
973
|
+
query<Row>(plan: TPlan & {
|
|
838
974
|
readonly _row?: Row;
|
|
839
975
|
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
976
|
+
execute(plan: TPlan, options?: RuntimeExecuteOptions): Promise<RuntimeStatementStats>;
|
|
840
977
|
}
|
|
841
978
|
//#endregion
|
|
842
979
|
//#region src/meta-builder.d.ts
|
|
@@ -897,5 +1034,5 @@ interface LaneMetaBuilder<K extends OperationKind> extends MetaBuilder<K> {
|
|
|
897
1034
|
*/
|
|
898
1035
|
declare function createMetaBuilder<K extends OperationKind>(kind: K, terminalName: string): LaneMetaBuilder<K>;
|
|
899
1036
|
//#endregion
|
|
900
|
-
export {
|
|
901
|
-
//# sourceMappingURL=runtime-
|
|
1037
|
+
export { checkAborted as A, runtimeAborted as B, RuntimeExecutor as C, RuntimeStatementStats as D, RuntimeMiddlewareContext as E, raceAgainstAbort as F, runBeforeExecuteChain as I, runBeforeQueryChain as L, createMetaBuilder as M, defineAnnotation as N, ValidAnnotations as O, isRuntimeError as P, runExecuteWithMiddleware as R, RuntimeExecuteOptions as S, RuntimeMiddleware as T, runtimeError as V, ResultType as _, AsyncIterableResult as a, RuntimeCoreOptions as b, ExecuteInterceptResult as c, MetaBuilder as d, OperationKind as f, RUNTIME_ABORTED as g, QueryPlan as h, AnnotationValue as i, checkMiddlewareCompatibility as j, assertAnnotationsApplicable as k, ExecutionPlan as l, QueryInterceptResult as m, AfterQueryResult as n, CrossFamilyMiddleware as o, ParamRefMutator as p, AnnotationHandle as r, DefineAnnotationOptions as s, AfterExecuteResult as t, LaneMetaBuilder as u, RuntimeAbortedPhase as v, RuntimeLog as w, RuntimeErrorEnvelope as x, RuntimeCore as y, runQueryWithMiddleware as z };
|
|
1038
|
+
//# sourceMappingURL=runtime-Cuxw8obj.d.mts.map
|