@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.
Files changed (62) hide show
  1. package/dist/authoring-B2H-9qCv.d.mts +1 -0
  2. package/dist/{codec-LWTqo1GG.d.mts → codec-Ce07W3Mz.d.mts} +2 -2
  3. package/dist/{codec-LWTqo1GG.d.mts.map → codec-Ce07W3Mz.d.mts.map} +1 -1
  4. package/dist/{codec-types-720XoDZ0-Br-QaYK3.d.mts → codec-types-D6VRj2RE-BLElXc-O.d.mts} +5 -5
  5. package/dist/{codec-types-720XoDZ0-Br-QaYK3.d.mts.map → codec-types-D6VRj2RE-BLElXc-O.d.mts.map} +1 -1
  6. package/dist/{components-CS6Hvdt6.d.mts → components-CGA_WwEG.d.mts} +4 -4
  7. package/dist/{components-CS6Hvdt6.d.mts.map → components-CGA_WwEG.d.mts.map} +1 -1
  8. package/dist/components.d.mts +15 -15
  9. package/dist/components.mjs +2 -2
  10. package/dist/components__authoring.d.mts +2 -2
  11. package/dist/components__codec.d.mts +2 -2
  12. package/dist/components__components.d.mts +3 -3
  13. package/dist/components__control.d.mts +2 -2
  14. package/dist/components__emission.d.mts +3 -3
  15. package/dist/components__execution.d.mts +1 -1
  16. package/dist/components__psl-ast.d.mts +3 -3
  17. package/dist/components__runtime.d.mts +2 -2
  18. package/dist/components__runtime.mjs +2 -2
  19. package/dist/{config-types-Dw7Nvsbm.d.mts → config-types-CW4PDwMC.d.mts} +6 -6
  20. package/dist/{config-types-Dw7Nvsbm.d.mts.map → config-types-CW4PDwMC.d.mts.map} +1 -1
  21. package/dist/config.d.mts +1 -1
  22. package/dist/config__config-types.d.mts +1 -1
  23. package/dist/contract-authoring.d.mts +3 -3
  24. package/dist/{control-2lID5ISA.d.mts → control-BF8qzdnM.d.mts} +7 -7
  25. package/dist/{control-2lID5ISA.d.mts.map → control-BF8qzdnM.d.mts.map} +1 -1
  26. package/dist/emission-CmUO03gQ.d.mts +2 -0
  27. package/dist/{emission-types-BY5gWxhC-DcGn4rl_.d.mts → emission-types-DLXP34Ki-CFms3VrX.d.mts} +4 -4
  28. package/dist/{emission-types-BY5gWxhC-DcGn4rl_.d.mts.map → emission-types-DLXP34Ki-CFms3VrX.d.mts.map} +1 -1
  29. package/dist/errors.d.mts +1 -1
  30. package/dist/errors__execution.d.mts +1 -1
  31. package/dist/{execution-j0w6KfPD.d.mts → execution-CSnQT8EX.d.mts} +2 -2
  32. package/dist/{execution-j0w6KfPD.d.mts.map → execution-CSnQT8EX.d.mts.map} +1 -1
  33. package/dist/{execution-D3yaOlOT.d.mts → execution-Cyl2dXxX.d.mts} +2 -2
  34. package/dist/{execution-D3yaOlOT.d.mts.map → execution-Cyl2dXxX.d.mts.map} +1 -1
  35. package/dist/{framework-authoring-CctmQY6c-DdJ4E7XK.d.mts → framework-authoring-BhctBwih-DQ_6noDM.d.mts} +3 -3
  36. package/dist/{framework-authoring-CctmQY6c-DdJ4E7XK.d.mts.map → framework-authoring-BhctBwih-DQ_6noDM.d.mts.map} +1 -1
  37. package/dist/{framework-components-p8N1lyvE-Cgl21LGI.d.mts → framework-components-hZ2tO-KH-CdRXBOYd.d.mts} +5 -5
  38. package/dist/{framework-components-p8N1lyvE-Cgl21LGI.d.mts.map → framework-components-hZ2tO-KH-CdRXBOYd.d.mts.map} +1 -1
  39. package/dist/ids.d.mts +1 -1
  40. package/dist/{parse-0ZJjj_2N-Ds7oY9eP.d.mts → parse-0ZJjj_2N-DhQpSVmQ.d.mts} +3 -3
  41. package/dist/{parse-0ZJjj_2N-Ds7oY9eP.d.mts.map → parse-0ZJjj_2N-DhQpSVmQ.d.mts.map} +1 -1
  42. package/dist/{psl-ast-Bxf2Zocj.d.mts → psl-ast-BXZoFQBk.d.mts} +4 -4
  43. package/dist/{psl-ast-Bxf2Zocj.d.mts.map → psl-ast-BXZoFQBk.d.mts.map} +1 -1
  44. package/dist/{psl-ast-GTXfHjAV-HsPDAkQr.d.mts → psl-ast-CWJQF8LA-Vr5JNPdn.d.mts} +4 -4
  45. package/dist/{psl-ast-GTXfHjAV-HsPDAkQr.d.mts.map → psl-ast-CWJQF8LA-Vr5JNPdn.d.mts.map} +1 -1
  46. package/dist/psl-parser.d.mts +8 -8
  47. package/dist/psl-parser__interpret.d.mts +3 -3
  48. package/dist/psl-parser__syntax.d.mts +1 -1
  49. package/dist/psl-printer.d.mts +6 -6
  50. package/dist/{runtime-DYTFHGwh.mjs → runtime-BqzioOmU.mjs} +241 -87
  51. package/dist/runtime-BqzioOmU.mjs.map +1 -0
  52. package/dist/{runtime-Cne6hBaG.d.mts → runtime-Cuxw8obj.d.mts} +326 -189
  53. package/dist/runtime-Cuxw8obj.d.mts.map +1 -0
  54. package/dist/{symbol-table-CZ7EVCTL-HNuzTvNC.d.mts → symbol-table-CZ7EVCTL-CR-ncCpD.d.mts} +5 -5
  55. package/dist/{symbol-table-CZ7EVCTL-HNuzTvNC.d.mts.map → symbol-table-CZ7EVCTL-CR-ncCpD.d.mts.map} +1 -1
  56. package/dist/{types-import-spec-C9FyCno_-CONzlg_q.d.mts → types-import-spec-3mjbVBhI-DQI6BvKU.d.mts} +3 -3
  57. package/dist/{types-import-spec-C9FyCno_-CONzlg_q.d.mts.map → types-import-spec-3mjbVBhI-DQI6BvKU.d.mts.map} +1 -1
  58. package/package.json +15 -15
  59. package/dist/authoring-D6-6Uhns.d.mts +0 -1
  60. package/dist/emission-aQb87dEn.d.mts +0 -2
  61. package/dist/runtime-Cne6hBaG.d.mts.map +0 -1
  62. package/dist/runtime-DYTFHGwh.mjs.map +0 -1
@@ -1,3 +1,4 @@
1
+ import { t as blindCast } from "./casts-DpaahrlC-Bd5n2coI.mjs";
1
2
  import { n as runtimeError } from "./runtime-error-BA9d7XjZ-BlT8t6LB.mjs";
2
3
  //#region ../../../1-framework/1-core/framework-components/dist/runtime.mjs
3
4
  /**
@@ -10,15 +11,16 @@ import { n as runtimeError } from "./runtime-error-BA9d7XjZ-BlT8t6LB.mjs";
10
11
  * - `'decode'` — abort fired during `decodeRow` / `decodeField`.
11
12
  * - `'stream'` — abort fired between rows or before any codec call
12
13
  * (already-aborted at entry).
13
- * - `'beforeExecute'` / `'afterExecute'` / `'onRow'` — abort fired
14
- * on entry to or during the corresponding middleware phase
14
+ * - `'beforeQuery'` / `'beforeExecute'` / `'afterQuery'` /
15
+ * `'afterExecute'` / `'onRow'` — abort fired on entry to or during
16
+ * the corresponding middleware phase
15
17
  * (cooperative cancellation per the param-transform seam).
16
18
  */
17
19
  const RUNTIME_ABORTED = "RUNTIME.ABORTED";
18
20
  /**
19
21
  * Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the
20
22
  * abort was observed — codec call sites (`encode` / `decode` / `stream`)
21
- * or middleware seams (`beforeExecute` / `afterExecute` / `onRow`), as
23
+ * or operation-specific middleware seams, as
22
24
  * enumerated on {@link RuntimeAbortedPhase}. Cause carries
23
25
  * `signal.reason` verbatim from the platform — native abort produces a
24
26
  * `DOMException`, explicit `controller.abort(reason)` produces whatever
@@ -246,17 +248,69 @@ async function raceAgainstAbort(work, signal, phase) {
246
248
  }
247
249
  }
248
250
  /**
251
+ * Runs every middleware's `beforeQuery` hook in registration order,
252
+ * threading through the (optional) family-specific `paramsMutator`.
253
+ *
254
+ * Why this lives outside {@link runQueryWithMiddleware}: middleware that
255
+ * mutates parameter values (e.g. cipherstash's bulk-encrypt SDK
256
+ * round-trip) must run *before* the family runtime encodes those
257
+ * parameters to driver wire format. Family runtimes call
258
+ * `runBeforeQueryChain` between the AST → plan lowering step and
259
+ * the parameter encode step; the encode then observes the mutator's
260
+ * `currentParams()` view. `runQueryWithMiddleware` retains the rest of
261
+ * the query lifecycle (`interceptQuery`, driver/row source loop, `onRow`,
262
+ * `afterQuery`) but no longer fires `beforeQuery` itself.
263
+ *
264
+ * Lifecycle within this helper:
265
+ *
266
+ * 1. For each middleware in registration order, if `beforeQuery`
267
+ * is implemented:
268
+ * - `checkAborted(ctx, 'beforeQuery')` short-circuits if the
269
+ * caller already aborted at entry.
270
+ * - The hook is invoked with `(plan, ctx, paramsMutator)`. A
271
+ * middleware body that ignores the mutator stays compatible —
272
+ * JavaScript allows extra positional arguments.
273
+ * - If the hook returns a Promise, it is raced against
274
+ * `ctx.signal` via {@link raceAgainstAbort} so cooperative
275
+ * cancellation surfaces a `RUNTIME.ABORTED { phase:
276
+ * 'beforeQuery' }` envelope even when the body itself
277
+ * ignores the signal.
278
+ *
279
+ * Error propagation: any error thrown by a `beforeQuery` body
280
+ * (or surfaced by the abort race) propagates out of this helper
281
+ * unchanged. Family runtime entry points await this helper before invoking
282
+ * `runQueryWithMiddleware`, so a rejection prevents the runner and its
283
+ * `afterQuery` hook from running.
284
+ *
285
+ * Relationship to {@link runQueryWithMiddleware}: the framework's
286
+ * `RuntimeCore.query` template calls this helper between
287
+ * `lower(plan)` and `runQueryWithMiddleware(...)`. Family runtimes that
288
+ * override query preparation (e.g. SQL, which inlines lower + encode for
289
+ * direct mutator threading) call this helper themselves at the
290
+ * equivalent point — between the family's AST → draft-plan
291
+ * lowering and the parameter-encode step.
292
+ *
293
+ * Intercept ordering: this helper fires unconditionally before
294
+ * `runQueryWithMiddleware`. `interceptQuery` (inside
295
+ * `runQueryWithMiddleware`) therefore observes the post-`beforeQuery`
296
+ * plan — mutator mutations are visible in the params interceptors see.
297
+ * The trade-off is documented on `RuntimeMiddleware.interceptQuery`.
298
+ */
299
+ function runBeforeQueryChain(plan, middleware, ctx, paramsMutator) {
300
+ return runBeforeChain(plan, middleware, ctx, paramsMutator, "beforeQuery", (mw) => mw.beforeQuery);
301
+ }
302
+ /**
249
303
  * Runs every middleware's `beforeExecute` hook in registration order,
250
304
  * threading through the (optional) family-specific `paramsMutator`.
251
305
  *
252
- * Why this lives outside {@link runWithMiddleware}: middleware that
306
+ * Why this lives outside {@link runExecuteWithMiddleware}: middleware that
253
307
  * mutates parameter values (e.g. cipherstash's bulk-encrypt SDK
254
308
  * round-trip) must run *before* the family runtime encodes those
255
309
  * parameters to driver wire format. Family runtimes call
256
310
  * `runBeforeExecuteChain` between the AST → plan lowering step and
257
311
  * the parameter encode step; the encode then observes the mutator's
258
- * `currentParams()` view. `runWithMiddleware` retains the rest of
259
- * the lifecycle (`intercept`, driver/row source loop, `onRow`,
312
+ * `currentParams()` view. `runExecuteWithMiddleware` retains the rest of
313
+ * the execute lifecycle (`interceptExecute`, driver statistics execution,
260
314
  * `afterExecute`) but no longer fires `beforeExecute` itself.
261
315
  *
262
316
  * Lifecycle within this helper:
@@ -276,76 +330,79 @@ async function raceAgainstAbort(work, signal, phase) {
276
330
  *
277
331
  * Error propagation: any error thrown by a `beforeExecute` body
278
332
  * (or surfaced by the abort race) propagates out of this helper
279
- * unchanged. The family runtime is responsible for converting it
280
- * into the appropriate `afterExecute(completed: false)` notification
281
- * once `runWithMiddleware` runs.
333
+ * unchanged. Family runtime entry points await this helper before invoking
334
+ * `runExecuteWithMiddleware`, so a rejection prevents the runner and its
335
+ * `afterExecute` hook from running.
282
336
  *
283
- * Relationship to {@link runWithMiddleware}: the framework's
337
+ * Relationship to {@link runExecuteWithMiddleware}: the framework's
284
338
  * `RuntimeCore.execute` template calls this helper between
285
- * `lower(plan)` and `runWithMiddleware(...)`. Family runtimes that
286
- * override `execute` (e.g. SQL, which inlines lower + encode for
339
+ * `lower(plan)` and `runExecuteWithMiddleware(...)`. Family runtimes that
340
+ * override execute (e.g. SQL, which inlines lower + encode for
287
341
  * direct mutator threading) call this helper themselves at the
288
342
  * equivalent point — between the family's AST → draft-plan
289
343
  * lowering and the parameter-encode step.
290
344
  *
291
345
  * Intercept ordering: this helper fires unconditionally before
292
- * `runWithMiddleware`. `intercept` (inside `runWithMiddleware`)
293
- * therefore observes the post-`beforeExecute` plan — mutator
294
- * mutations are visible in the params interceptors see. The
295
- * trade-off is documented on `RuntimeMiddleware.intercept`.
346
+ * `runExecuteWithMiddleware`. `interceptExecute` (inside
347
+ * `runExecuteWithMiddleware`) therefore observes the post-`beforeExecute`
348
+ * plan — mutator mutations are visible in the params interceptors see.
349
+ * The trade-off is documented on `RuntimeMiddleware.interceptExecute`.
296
350
  */
297
- async function runBeforeExecuteChain(plan, middleware, ctx, paramsMutator) {
351
+ function runBeforeExecuteChain(plan, middleware, ctx, paramsMutator) {
352
+ return runBeforeChain(plan, middleware, ctx, paramsMutator, "beforeExecute", (mw) => mw.beforeExecute);
353
+ }
354
+ async function runBeforeChain(plan, middleware, ctx, paramsMutator, phase, selectHook) {
298
355
  for (const mw of middleware) {
299
- if (!mw.beforeExecute) continue;
300
- checkAborted(ctx, "beforeExecute");
301
- const work = mw.beforeExecute(plan, ctx, paramsMutator);
302
- if (work !== void 0) await raceAgainstAbort(Promise.resolve(work), ctx.signal, "beforeExecute");
356
+ const hook = selectHook(mw);
357
+ if (hook === void 0) continue;
358
+ checkAborted(ctx, phase);
359
+ const work = hook(plan, ctx, paramsMutator);
360
+ if (work !== void 0) await raceAgainstAbort(Promise.resolve(work), ctx.signal, phase);
303
361
  }
304
362
  }
305
363
  /**
306
- * Drives a single execution of `runDriver()` through the middleware
307
- * lifecycle's intercept + row-source + termination phases.
364
+ * Drives a single query execution of `runDriver()` through the middleware
365
+ * lifecycle's `interceptQuery` + row-source + termination phases.
308
366
  *
309
367
  * Lifecycle, in order:
310
- * 1. For each middleware in registration order: `intercept(exec, ctx)`. The
311
- * first non-`undefined` result wins; subsequent middleware's `intercept`
312
- * does not fire. On a hit, the runtime emits a `middleware.intercept`
313
- * debug event naming the winning middleware, switches the row source to
314
- * the intercepted rows, and proceeds with `source: 'middleware'`. On
315
- * all-passthrough (every `intercept` returns `undefined` or is omitted),
316
- * `source: 'driver'` is used and the row source is `runDriver()`.
368
+ * 1. For each middleware in registration order: `interceptQuery(exec, ctx)`.
369
+ * The first non-`undefined` result wins; subsequent middleware's
370
+ * `interceptQuery` does not fire. On a hit, the runtime emits a
371
+ * `middleware.interceptQuery` debug event naming the winning middleware,
372
+ * switches the row source to the intercepted rows, and proceeds with
373
+ * `source: 'middleware'`. On all-passthrough (every `interceptQuery`
374
+ * returns `undefined` or is omitted), `source: 'driver'` is used and the
375
+ * row source is `runDriver()`.
317
376
  * 2. Iterate the row source. On the driver path, for each row, for each
318
377
  * middleware in registration order: `onRow(row, exec, ctx)`; then yield
319
378
  * the row. On the intercepted hit path, `onRow` is skipped — intercepted
320
379
  * rows did not originate from a driver row stream — but rows are still
321
380
  * yielded to the consumer in order.
322
381
  * 3. On successful completion: for each middleware in registration order:
323
- * `afterExecute(exec, { rowCount, latencyMs, completed: true, source },
382
+ * `afterQuery(exec, { rowCount, latencyMs, completed: true, source },
324
383
  * ctx)`.
325
384
  * 4. On any error thrown during steps 1–2: for each middleware in
326
- * registration order: `afterExecute(exec, { rowCount, latencyMs,
327
- * completed: false, source }, ctx)`. Errors thrown by `afterExecute`
385
+ * registration order: `afterQuery(exec, { rowCount, latencyMs,
386
+ * completed: false, source }, ctx)`. Errors thrown by `afterQuery`
328
387
  * during the error path are swallowed so they do not mask the original
329
388
  * error. The original error is then rethrown.
330
389
  *
331
- * `beforeExecute` is **not** fired here — see
332
- * {@link runBeforeExecuteChain} in `before-execute-chain.ts`. Family
333
- * runtimes call that helper between the AST → plan lowering step and
334
- * the parameter encode step so middleware that mutates ParamRef
335
- * values (e.g. cipherstash bulk-encrypt) can have its mutations
336
- * visible to encode. `runWithMiddleware` operates on the fully-
337
- * encoded plan; interceptors therefore observe a fully-mutated,
390
+ * `beforeQuery` is **not** fired here — see
391
+ * {@link runBeforeQueryChain} in `before-execute-chain.ts`. Family runtimes
392
+ * call that helper between the AST → plan lowering step and the parameter
393
+ * encode step so middleware that mutates ParamRef values can have its
394
+ * mutations visible to encode. `runQueryWithMiddleware` operates on the
395
+ * fully-encoded plan; interceptors therefore observe a fully-mutated,
338
396
  * encoded plan.
339
397
  *
340
- * The `source` field on `AfterExecuteResult` lets observers (telemetry,
341
- * lints, budgets) distinguish driver-served from middleware-served
342
- * executions without needing their own out-of-band signal.
398
+ * The `source` field on `AfterQueryResult` lets observers (telemetry, lints,
399
+ * budgets) distinguish driver-served from middleware-served executions
400
+ * without needing their own out-of-band signal.
343
401
  *
344
402
  * This helper is the single canonical implementation of the
345
- * intercept-and-row-source loop; family runtimes should not
346
- * reimplement it.
403
+ * intercept-and-row-source loop; family runtimes should not reimplement it.
347
404
  */
348
- function runWithMiddleware(exec, middleware, ctx, runDriver) {
405
+ function runQueryWithMiddleware(exec, middleware, ctx, runDriver) {
349
406
  const iterator = async function* () {
350
407
  const startedAt = Date.now();
351
408
  let rowCount = 0;
@@ -354,18 +411,18 @@ function runWithMiddleware(exec, middleware, ctx, runDriver) {
354
411
  let rowSource;
355
412
  try {
356
413
  for (const mw of middleware) {
357
- if (!mw.intercept) continue;
414
+ if (!mw.interceptQuery) continue;
358
415
  source = "middleware";
359
- const result = await mw.intercept(exec, ctx);
416
+ const result = await mw.interceptQuery(exec, ctx);
360
417
  if (result === void 0) {
361
418
  source = "driver";
362
419
  continue;
363
420
  }
364
421
  ctx.log.debug?.({
365
- event: "middleware.intercept",
422
+ event: "middleware.interceptQuery",
366
423
  middleware: mw.name
367
424
  });
368
- rowSource = result.rows;
425
+ rowSource = blindCast(result.rows);
369
426
  break;
370
427
  }
371
428
  if (source === "driver") rowSource = runDriver();
@@ -378,58 +435,138 @@ function runWithMiddleware(exec, middleware, ctx, runDriver) {
378
435
  }
379
436
  completed = true;
380
437
  } catch (error) {
381
- const latencyMs = Date.now() - startedAt;
382
- for (const mw of middleware) if (mw.afterExecute) try {
383
- await mw.afterExecute(exec, {
384
- rowCount,
385
- latencyMs,
386
- completed,
387
- source
388
- }, ctx);
389
- } catch {}
438
+ await notifyQueryCompletion(middleware, exec, ctx, {
439
+ rowCount,
440
+ latencyMs: Date.now() - startedAt,
441
+ completed,
442
+ source
443
+ }, true);
390
444
  throw error;
391
445
  }
392
- const latencyMs = Date.now() - startedAt;
393
- for (const mw of middleware) if (mw.afterExecute) await mw.afterExecute(exec, {
446
+ await notifyQueryCompletion(middleware, exec, ctx, {
394
447
  rowCount,
395
- latencyMs,
448
+ latencyMs: Date.now() - startedAt,
396
449
  completed,
397
450
  source
398
- }, ctx);
451
+ }, false);
399
452
  };
400
453
  return new AsyncIterableResult(iterator());
401
454
  }
402
455
  /**
456
+ * Drives a single execute operation through the middleware
457
+ * `interceptExecute` + statistics + termination phases.
458
+ *
459
+ * Lifecycle, in order:
460
+ * 1. For each middleware in registration order: `interceptExecute(exec, ctx)`.
461
+ * The first non-`undefined` result wins; subsequent middleware's
462
+ * `interceptExecute` does not fire. On a hit, the runtime emits a
463
+ * `middleware.interceptExecute` debug event naming the winning middleware,
464
+ * uses the returned `stats`, and proceeds with `source: 'middleware'`.
465
+ * On all-passthrough (every `interceptExecute` returns `undefined` or is
466
+ * omitted), `source: 'driver'` is used and `runDriver()` supplies the
467
+ * statistics.
468
+ * 2. Execute operations return eager statistics. There is no row stream and
469
+ * `onRow` does not fire.
470
+ * 3. On successful completion: for each middleware in registration order:
471
+ * `afterExecute(exec, { stats, latencyMs, completed: true, source }, ctx)`.
472
+ * 4. On any error thrown during steps 1–2: for each middleware in
473
+ * registration order: `afterExecute(exec, { latencyMs, completed: false,
474
+ * source }, ctx)`. Errors thrown by `afterExecute` during the error path
475
+ * are swallowed so they do not mask the original error. The original
476
+ * error is then rethrown.
477
+ *
478
+ * `beforeExecute` is **not** fired here — see
479
+ * {@link runBeforeExecuteChain} in `before-execute-chain.ts`. Family runtimes
480
+ * call that helper between the AST → plan lowering step and the parameter
481
+ * encode step so middleware that mutates ParamRef values can have its
482
+ * mutations visible to encode. `runExecuteWithMiddleware` operates on the
483
+ * fully-encoded plan; interceptors therefore observe a fully-mutated,
484
+ * encoded plan.
485
+ *
486
+ * The `source` field on `AfterExecuteResult` lets observers (telemetry, lints,
487
+ * budgets) distinguish driver-served from middleware-served executions
488
+ * without needing their own out-of-band signal.
489
+ */
490
+ async function runExecuteWithMiddleware(exec, middleware, ctx, runDriver) {
491
+ const startedAt = Date.now();
492
+ let source = "driver";
493
+ let stats;
494
+ try {
495
+ for (const mw of middleware) {
496
+ if (!mw.interceptExecute) continue;
497
+ source = "middleware";
498
+ const result = await mw.interceptExecute(exec, ctx);
499
+ if (result === void 0) {
500
+ source = "driver";
501
+ continue;
502
+ }
503
+ ctx.log.debug?.({
504
+ event: "middleware.interceptExecute",
505
+ middleware: mw.name
506
+ });
507
+ stats = result.stats;
508
+ break;
509
+ }
510
+ if (stats === void 0) stats = await runDriver();
511
+ } catch (error) {
512
+ const latencyMs = Date.now() - startedAt;
513
+ for (const mw of middleware) {
514
+ if (!mw.afterExecute) continue;
515
+ try {
516
+ await mw.afterExecute(exec, {
517
+ latencyMs,
518
+ completed: false,
519
+ source
520
+ }, ctx);
521
+ } catch {}
522
+ }
523
+ throw error;
524
+ }
525
+ const latencyMs = Date.now() - startedAt;
526
+ for (const mw of middleware) if (mw.afterExecute) await mw.afterExecute(exec, {
527
+ stats,
528
+ latencyMs,
529
+ completed: true,
530
+ source
531
+ }, ctx);
532
+ return stats;
533
+ }
534
+ async function notifyQueryCompletion(middleware, exec, ctx, result, swallowErrors) {
535
+ for (const mw of middleware) {
536
+ if (!mw.afterQuery) continue;
537
+ if (swallowErrors) try {
538
+ await mw.afterQuery(exec, result, ctx);
539
+ } catch {}
540
+ else await mw.afterQuery(exec, result, ctx);
541
+ }
542
+ }
543
+ /**
403
544
  * Family-agnostic abstract runtime base.
404
545
  *
405
- * Defines the entire `execute(plan)` template in one place:
546
+ * Defines the shared operation-specific middleware lifecycles:
406
547
  *
407
548
  * 1. `runBeforeCompile(plan)` — concrete; defaults to identity. SQL overrides
408
- * this to run its `beforeCompile` middleware-hook chain.
549
+ * this to run its shared `beforeCompile` middleware-hook chain.
409
550
  * 2. `lower(plan)` — abstract. Each family produces its `*ExecutionPlan`
410
551
  * (SQL via `lowerSqlPlan`, Mongo via `adapter.lower`).
411
- * 3. `runBeforeExecuteChain(exec, this.middleware, this.ctx)` concrete;
412
- * runs every middleware's `beforeExecute` hook after lowering but
413
- * before the row source is opened. Family runtimes that need a
414
- * params mutator visible to a downstream encode step (SQL) override
415
- * `execute` and call this helper themselves at the equivalent
416
- * pre-encode point.
417
- * 4. `runWithMiddleware(exec, this.middleware, this.ctx,
418
- * () => runDriver(exec))` — concrete; runs the intercept chain,
419
- * drives the row source, fires `onRow` / `afterExecute`. Does
420
- * **not** fire `beforeExecute` — see step 3.
421
- *
422
- * Concrete subclasses must implement `lower`, `runDriver`, and `close`.
552
+ * 3. Queries run `beforeQuery`; statements run `beforeExecute`. Both chains
553
+ * run after lowering and before their matching driver terminal. Family
554
+ * runtimes that expose a params mutator to downstream encoding override
555
+ * the operation and call the matching helper at the pre-encode point.
556
+ * 4. The matching runner processes `interceptQuery` or `interceptExecute`
557
+ * before invoking the driver. Queries then fire `onRow` and `afterQuery`;
558
+ * statements fire `afterExecute`.
559
+ *
560
+ * Concrete subclasses must implement `lower`, `runDriver`, `runExecute`, and
561
+ * `close`.
423
562
  *
424
563
  * The class is generic over:
425
564
  * - `TPlan` — the family's pre-lowering plan type.
426
565
  * - `TExec` — the family's post-lowering (executable) plan type.
427
566
  * - `TMiddleware` — the family's middleware type. Constrained to
428
- * `RuntimeMiddleware<TExec>` because `runWithMiddleware` invokes the
429
- * `beforeExecute` / `onRow` / `afterExecute` hooks with the lowered
430
- * `TExec`. (The spec/plan wording "RuntimeMiddleware<TPlan>" is
431
- * tightened to `<TExec>` here so the helper call typechecks; the
432
- * intent is unchanged — middleware sees the post-lowering plan.)
567
+ * `RuntimeMiddleware<TExec>` because the operation-specific runners invoke
568
+ * hooks with the lowered `TExec`. Middleware therefore sees the
569
+ * post-lowering plan.
433
570
  */
434
571
  var RuntimeCore = class {
435
572
  middleware;
@@ -446,23 +583,40 @@ var RuntimeCore = class {
446
583
  runBeforeCompile(plan) {
447
584
  return plan;
448
585
  }
449
- execute(plan, options) {
586
+ query(plan, options) {
450
587
  const self = this;
451
588
  const signal = options?.signal;
452
589
  const codecCtx = signal === void 0 ? {} : { signal };
453
590
  const execCtx = {
454
591
  ...self.ctx,
592
+ ...codecCtx,
593
+ scope: options?.scope ?? self.ctx.scope,
455
594
  planExecutionId: crypto.randomUUID()
456
595
  };
457
596
  async function* generator() {
458
597
  checkAborted(codecCtx, "stream");
459
598
  const compiled = await self.runBeforeCompile(plan);
460
599
  const exec = await self.lower(compiled, codecCtx);
461
- await runBeforeExecuteChain(exec, self.middleware, execCtx);
462
- yield* runWithMiddleware(exec, self.middleware, execCtx, () => self.runDriver(exec));
600
+ await runBeforeQueryChain(exec, self.middleware, execCtx);
601
+ yield* runQueryWithMiddleware(exec, self.middleware, execCtx, () => self.runDriver(exec));
463
602
  }
464
603
  return new AsyncIterableResult(generator());
465
604
  }
605
+ async execute(plan, options) {
606
+ const signal = options?.signal;
607
+ const codecCtx = signal === void 0 ? {} : { signal };
608
+ const execCtx = {
609
+ ...this.ctx,
610
+ ...codecCtx,
611
+ scope: options?.scope ?? this.ctx.scope,
612
+ planExecutionId: crypto.randomUUID()
613
+ };
614
+ checkAborted(codecCtx, "stream");
615
+ const compiled = await this.runBeforeCompile(plan);
616
+ const exec = await this.lower(compiled, codecCtx);
617
+ await runBeforeExecuteChain(exec, this.middleware, execCtx);
618
+ return runExecuteWithMiddleware(exec, this.middleware, execCtx, () => this.runExecute(exec));
619
+ }
466
620
  };
467
621
  function checkMiddlewareCompatibility(middleware, runtimeFamilyId, runtimeTargetId) {
468
622
  if (middleware.targetId !== void 0 && middleware.familyId === void 0) throw runtimeError("RUNTIME.MIDDLEWARE_INCOMPATIBLE", `Middleware '${middleware.name}' specifies targetId '${middleware.targetId}' without familyId`, {
@@ -511,6 +665,6 @@ function createMetaBuilder(kind, terminalName) {
511
665
  return new MetaBuilderImpl(kind, terminalName);
512
666
  }
513
667
  //#endregion
514
- export { checkAborted as a, defineAnnotation as c, runWithMiddleware as d, runtimeAborted as f, assertAnnotationsApplicable as i, raceAgainstAbort as l, RUNTIME_ABORTED as n, checkMiddlewareCompatibility as o, RuntimeCore as r, createMetaBuilder as s, AsyncIterableResult as t, runBeforeExecuteChain as u };
668
+ export { checkAborted as a, defineAnnotation as c, runBeforeQueryChain as d, runExecuteWithMiddleware as f, assertAnnotationsApplicable as i, raceAgainstAbort as l, runtimeAborted as m, RUNTIME_ABORTED as n, checkMiddlewareCompatibility as o, runQueryWithMiddleware as p, RuntimeCore as r, createMetaBuilder as s, AsyncIterableResult as t, runBeforeExecuteChain as u };
515
669
 
516
- //# sourceMappingURL=runtime-DYTFHGwh.mjs.map
670
+ //# sourceMappingURL=runtime-BqzioOmU.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-BqzioOmU.mjs","names":["#kind","#terminalName","#annotations"],"sources":["../../../../1-framework/1-core/framework-components/dist/runtime.mjs"],"sourcesContent":["import { n as runtimeError, t as isRuntimeError } from \"./runtime-error-BA9d7XjZ.mjs\";\nimport { blindCast } from \"@internal/utils/casts\";\n//#region src/execution/runtime-error.ts\n/**\n* Stable code emitted by the runtime when an in-flight `execute()`\n* is cancelled via the per-query `AbortSignal`. The envelope's\n* `details.phase` distinguishes where the abort was observed:\n*\n* - `'encode'` — abort fired during `encodeParams` (SQL) or\n* `resolveValue` (Mongo).\n* - `'decode'` — abort fired during `decodeRow` / `decodeField`.\n* - `'stream'` — abort fired between rows or before any codec call\n* (already-aborted at entry).\n* - `'beforeQuery'` / `'beforeExecute'` / `'afterQuery'` /\n* `'afterExecute'` / `'onRow'` — abort fired on entry to or during\n* the corresponding middleware phase\n* (cooperative cancellation per the param-transform seam).\n*/\nconst RUNTIME_ABORTED = \"RUNTIME.ABORTED\";\n/**\n* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the\n* abort was observed — codec call sites (`encode` / `decode` / `stream`)\n* or operation-specific middleware seams, as\n* enumerated on {@link RuntimeAbortedPhase}. Cause carries\n* `signal.reason` verbatim from the platform — native abort produces a\n* `DOMException`, explicit `controller.abort(reason)` produces whatever\n* the caller passed. No synthesis happens here.\n*/\nfunction runtimeAborted(phase, cause) {\n\tconst envelope = runtimeError(RUNTIME_ABORTED, `Operation aborted during ${phase}`, { phase });\n\treturn Object.assign(envelope, { cause });\n}\n//#endregion\n//#region src/annotations.ts\n/**\n* Defines a typed annotation handle.\n*\n* Two-step call form. The first step takes the `Payload` type argument\n* (TypeScript cannot infer `Payload` from anything in the options, so it\n* must be supplied explicitly); the second step takes the runtime options\n* and infers `Kinds` from the `applicableTo` array via a `const` type\n* parameter, so the operation kinds appear exactly once at the call site.\n*\n* @example\n* ```typescript\n* // Read-only annotation. Lane terminals like `db.User.first(...)` accept\n* // it; `db.User.create(...)` rejects it at the type level.\n* const cacheAnnotation = defineAnnotation<{ ttl?: number; skip?: boolean }>()({\n* namespace: 'cache',\n* applicableTo: ['read'],\n* }); // Kinds inferred as 'read'\n*\n* // Write-only annotation. Mirror image.\n* const auditAnnotation = defineAnnotation<{ actor: string }>()({\n* namespace: 'audit',\n* applicableTo: ['write'],\n* }); // Kinds inferred as 'write'\n*\n* // Annotation applicable to both kinds (e.g. tracing).\n* const otelAnnotation = defineAnnotation<{ traceId: string }>()({\n* namespace: 'otel',\n* applicableTo: ['read', 'write'],\n* }); // Kinds inferred as 'read' | 'write'\n* ```\n*\n* **Reserved namespaces.** See `DefineAnnotationOptions.namespace` for the\n* list of framework-internal namespaces (`codecs`, target-specific keys).\n* `defineAnnotation` does not structurally prevent a user from naming a\n* reserved namespace, but the framework makes no compatibility guarantee\n* about handles that do.\n*/\nfunction defineAnnotation() {\n\treturn (options) => {\n\t\tconst namespace = options.namespace;\n\t\tconst applicableTo = Object.freeze(new Set(options.applicableTo));\n\t\tfunction handle(value) {\n\t\t\treturn Object.freeze({\n\t\t\t\t__annotation: true,\n\t\t\t\tnamespace,\n\t\t\t\tvalue,\n\t\t\t\tapplicableTo\n\t\t\t});\n\t\t}\n\t\tfunction read(plan) {\n\t\t\tconst stored = plan.meta.annotations?.[namespace];\n\t\t\tif (!isAnnotationValue(stored)) return;\n\t\t\tif (stored.namespace !== namespace) return;\n\t\t\treturn stored.value;\n\t\t}\n\t\treturn Object.freeze(Object.assign(handle, {\n\t\t\tnamespace,\n\t\t\tapplicableTo,\n\t\t\tread\n\t\t}));\n\t};\n}\n/**\n* Runtime applicability gate. Throws `RUNTIME.ANNOTATION_INAPPLICABLE` if\n* any annotation in `annotations` declares an `applicableTo` set that does\n* not include `kind`. Used by lane terminals (SQL DSL builders' `.build()`,\n* ORM `Collection` terminals) to fail closed when the type-level\n* `ValidAnnotations` gate is bypassed via cast / `any` / dynamic\n* invocation.\n*\n* Passes silently on:\n* - empty arrays\n* - annotations whose `applicableTo` includes `kind`\n*\n* Throws on:\n* - any annotation whose `applicableTo` does not include `kind`. The\n* error names the offending annotation's `namespace` and the\n* `terminalName` so users can locate the misuse.\n*\n* @example\n* ```typescript\n* // Inside an ORM read terminal:\n* assertAnnotationsApplicable(annotations, 'read', 'first');\n* ```\n*/\nfunction assertAnnotationsApplicable(annotations, kind, terminalName) {\n\tfor (const annotation of annotations) if (!annotation.applicableTo.has(kind)) throw runtimeError(\"RUNTIME.ANNOTATION_INAPPLICABLE\", `Annotation '${annotation.namespace}' is not applicable to '${kind}' operations (terminal: '${terminalName}'). The annotation declares applicableTo = [${Array.from(annotation.applicableTo).map((k) => `'${k}'`).join(\", \")}].`, {\n\t\tnamespace: annotation.namespace,\n\t\tterminalName,\n\t\tkind,\n\t\tapplicableTo: Array.from(annotation.applicableTo)\n\t});\n}\n/**\n* Type guard for branded annotation values stored in `plan.meta.annotations`.\n*\n* Internal — used by `AnnotationHandle.read` to distinguish user\n* annotations (created by calling a handle returned from\n* `defineAnnotation(...)`) from framework-internal metadata that may\n* happen to live under the same namespace key.\n*/\nfunction isAnnotationValue(value) {\n\tif (value === null || typeof value !== \"object\") return false;\n\treturn value.__annotation === true;\n}\n//#endregion\n//#region src/execution/async-iterable-result.ts\nvar AsyncIterableResult = class {\n\tgenerator;\n\tconsumed = false;\n\tconsumedBy;\n\tbufferedArrayPromise;\n\tconstructor(generator) {\n\t\tthis.generator = generator;\n\t}\n\t[Symbol.asyncIterator]() {\n\t\tif (this.consumed) throw runtimeError(\"RUNTIME.ITERATOR_CONSUMED\", `AsyncIterableResult iterator has already been consumed via ${this.consumedBy === \"bufferedArray\" ? \"toArray()/then()\" : \"for-await loop\"}. Each AsyncIterableResult can only be iterated once.`, {\n\t\t\tconsumedBy: this.consumedBy,\n\t\t\tsuggestion: this.consumedBy === \"bufferedArray\" ? \"If you need to iterate multiple times, store the results from toArray() in a variable and reuse that.\" : \"If you need to iterate multiple times, use toArray() to collect all results first.\"\n\t\t});\n\t\tthis.consumed = true;\n\t\tthis.consumedBy = \"iterator\";\n\t\treturn this.generator;\n\t}\n\ttoArray() {\n\t\tif (this.consumedBy === \"iterator\") return Promise.reject(runtimeError(\"RUNTIME.ITERATOR_CONSUMED\", \"AsyncIterableResult iterator has already been consumed via for-await loop. Each AsyncIterableResult can only be iterated once.\", {\n\t\t\tconsumedBy: this.consumedBy,\n\t\t\tsuggestion: \"The iterator was already consumed by a for-await loop. Use toArray() or await the result before iterating.\"\n\t\t}));\n\t\tif (this.bufferedArrayPromise) return this.bufferedArrayPromise;\n\t\tthis.consumed = true;\n\t\tthis.consumedBy = \"bufferedArray\";\n\t\tthis.bufferedArrayPromise = (async () => {\n\t\t\tconst out = [];\n\t\t\tfor await (const item of this.generator) out.push(item);\n\t\t\treturn out;\n\t\t})();\n\t\treturn this.bufferedArrayPromise;\n\t}\n\tasync first() {\n\t\treturn (await this.toArray())[0] ?? null;\n\t}\n\tasync firstOrThrow() {\n\t\tconst row = await this.first();\n\t\tif (row === null) throw runtimeError(\"RUNTIME.NO_ROWS\", \"Expected at least one row, but none were returned\", {});\n\t\treturn row;\n\t}\n\tthen(onfulfilled, onrejected) {\n\t\treturn this.toArray().then(onfulfilled, onrejected);\n\t}\n};\n//#endregion\n//#region src/execution/race-against-abort.ts\n/**\n* Throw a phase-tagged `RUNTIME.ABORTED` envelope if the supplied\n* context is already aborted at the precheck site. Centralises the\n* `if (ctx.signal?.aborted) throw runtimeAborted(...)` pattern that\n* every codec dispatch site (and the `beforeExecute` middleware phase)\n* repeats. Accepts both the framework `CodecCallContext` and the\n* `RuntimeMiddlewareContext`; both expose `signal?: AbortSignal`.\n*/\nfunction checkAborted(ctx, phase) {\n\tif (ctx.signal?.aborted) throw runtimeAborted(phase, ctx.signal.reason);\n}\n/**\n* Race a per-cell `Promise.all` (or any other in-flight work promise) against\n* the supplied abort signal so the runtime returns `RUNTIME.ABORTED` promptly\n* even when codec bodies ignore the signal. In-flight bodies that ignore the\n* signal are abandoned and run to completion in the background — the\n* cooperative-cancellation contract documented in ADR 204.\n*\n* Call sites still SHOULD pre-check `signal.aborted` and short-circuit with\n* a phase-tagged `RUNTIME.ABORTED` envelope before invoking this helper —\n* that path is the canonical \"aborted at entry\" surface and avoids\n* scheduling the work promise. As a defensive belt-and-braces, this helper\n* also handles the already-aborted case internally: `AbortSignal` does not\n* replay past abort events to listeners registered after the abort, so we\n* inspect `signal.aborted` synchronously and reject with the sentinel\n* before installing the listener. The rejection is still attributed to the\n* abort path via the sentinel-identity check.\n*\n* Distinguishing the rejection source is load-bearing for AC-ERR4\n* (`RUNTIME.ENCODE_FAILED` / `RUNTIME.DECODE_FAILED` pass through unchanged).\n* The semantically equivalent `abortable(signal)` helper in\n* `@internal/utils` rejects with `signal.reason ?? new DOMException(...)`,\n* which is not stably distinguishable from a codec-thrown error by identity\n* alone (a fresh fallback DOMException is allocated per call). We instead\n* track abort attribution with a unique sentinel: only the `onAbort` listener\n* installed here ever rejects with the sentinel, so an `error === sentinel`\n* identity check after the race is unambiguous.\n*\n* Lives in `framework-components` (rather than the SQL family, where it\n* originated in m2) so every family runtime that needs cooperative\n* cancellation around a codec-dispatch `Promise.all` (SQL encode + decode\n* today, Mongo encode in m3) shares the same attribution logic.\n*/\nasync function raceAgainstAbort(work, signal, phase) {\n\tif (signal === void 0) return await work;\n\tconst sentinel = { reason: void 0 };\n\tlet onAbort;\n\tconst abortPromise = new Promise((_, reject) => {\n\t\tif (signal.aborted) {\n\t\t\tsentinel.reason = signal.reason;\n\t\t\treject(sentinel);\n\t\t\treturn;\n\t\t}\n\t\tonAbort = () => {\n\t\t\tsentinel.reason = signal.reason;\n\t\t\treject(sentinel);\n\t\t};\n\t\tsignal.addEventListener(\"abort\", onAbort, { once: true });\n\t});\n\ttry {\n\t\treturn await Promise.race([work, abortPromise]);\n\t} catch (error) {\n\t\tif (error === sentinel) throw runtimeAborted(phase, sentinel.reason);\n\t\tthrow error;\n\t} finally {\n\t\tif (onAbort) signal.removeEventListener(\"abort\", onAbort);\n\t}\n}\n//#endregion\n//#region src/execution/before-execute-chain.ts\n/**\n* Runs every middleware's `beforeQuery` hook in registration order,\n* threading through the (optional) family-specific `paramsMutator`.\n*\n* Why this lives outside {@link runQueryWithMiddleware}: middleware that\n* mutates parameter values (e.g. cipherstash's bulk-encrypt SDK\n* round-trip) must run *before* the family runtime encodes those\n* parameters to driver wire format. Family runtimes call\n* `runBeforeQueryChain` between the AST → plan lowering step and\n* the parameter encode step; the encode then observes the mutator's\n* `currentParams()` view. `runQueryWithMiddleware` retains the rest of\n* the query lifecycle (`interceptQuery`, driver/row source loop, `onRow`,\n* `afterQuery`) but no longer fires `beforeQuery` itself.\n*\n* Lifecycle within this helper:\n*\n* 1. For each middleware in registration order, if `beforeQuery`\n* is implemented:\n* - `checkAborted(ctx, 'beforeQuery')` short-circuits if the\n* caller already aborted at entry.\n* - The hook is invoked with `(plan, ctx, paramsMutator)`. A\n* middleware body that ignores the mutator stays compatible —\n* JavaScript allows extra positional arguments.\n* - If the hook returns a Promise, it is raced against\n* `ctx.signal` via {@link raceAgainstAbort} so cooperative\n* cancellation surfaces a `RUNTIME.ABORTED { phase:\n* 'beforeQuery' }` envelope even when the body itself\n* ignores the signal.\n*\n* Error propagation: any error thrown by a `beforeQuery` body\n* (or surfaced by the abort race) propagates out of this helper\n* unchanged. Family runtime entry points await this helper before invoking\n* `runQueryWithMiddleware`, so a rejection prevents the runner and its\n* `afterQuery` hook from running.\n*\n* Relationship to {@link runQueryWithMiddleware}: the framework's\n* `RuntimeCore.query` template calls this helper between\n* `lower(plan)` and `runQueryWithMiddleware(...)`. Family runtimes that\n* override query preparation (e.g. SQL, which inlines lower + encode for\n* direct mutator threading) call this helper themselves at the\n* equivalent point — between the family's AST → draft-plan\n* lowering and the parameter-encode step.\n*\n* Intercept ordering: this helper fires unconditionally before\n* `runQueryWithMiddleware`. `interceptQuery` (inside\n* `runQueryWithMiddleware`) therefore observes the post-`beforeQuery`\n* plan — mutator mutations are visible in the params interceptors see.\n* The trade-off is documented on `RuntimeMiddleware.interceptQuery`.\n*/\nfunction runBeforeQueryChain(plan, middleware, ctx, paramsMutator) {\n\treturn runBeforeChain(plan, middleware, ctx, paramsMutator, \"beforeQuery\", (mw) => mw.beforeQuery);\n}\n/**\n* Runs every middleware's `beforeExecute` hook in registration order,\n* threading through the (optional) family-specific `paramsMutator`.\n*\n* Why this lives outside {@link runExecuteWithMiddleware}: middleware that\n* mutates parameter values (e.g. cipherstash's bulk-encrypt SDK\n* round-trip) must run *before* the family runtime encodes those\n* parameters to driver wire format. Family runtimes call\n* `runBeforeExecuteChain` between the AST → plan lowering step and\n* the parameter encode step; the encode then observes the mutator's\n* `currentParams()` view. `runExecuteWithMiddleware` retains the rest of\n* the execute lifecycle (`interceptExecute`, driver statistics execution,\n* `afterExecute`) but no longer fires `beforeExecute` itself.\n*\n* Lifecycle within this helper:\n*\n* 1. For each middleware in registration order, if `beforeExecute`\n* is implemented:\n* - `checkAborted(ctx, 'beforeExecute')` short-circuits if the\n* caller already aborted at entry.\n* - The hook is invoked with `(plan, ctx, paramsMutator)`. A\n* middleware body that ignores the mutator stays compatible —\n* JavaScript allows extra positional arguments.\n* - If the hook returns a Promise, it is raced against\n* `ctx.signal` via {@link raceAgainstAbort} so cooperative\n* cancellation surfaces a `RUNTIME.ABORTED { phase:\n* 'beforeExecute' }` envelope even when the body itself\n* ignores the signal.\n*\n* Error propagation: any error thrown by a `beforeExecute` body\n* (or surfaced by the abort race) propagates out of this helper\n* unchanged. Family runtime entry points await this helper before invoking\n* `runExecuteWithMiddleware`, so a rejection prevents the runner and its\n* `afterExecute` hook from running.\n*\n* Relationship to {@link runExecuteWithMiddleware}: the framework's\n* `RuntimeCore.execute` template calls this helper between\n* `lower(plan)` and `runExecuteWithMiddleware(...)`. Family runtimes that\n* override execute (e.g. SQL, which inlines lower + encode for\n* direct mutator threading) call this helper themselves at the\n* equivalent point — between the family's AST → draft-plan\n* lowering and the parameter-encode step.\n*\n* Intercept ordering: this helper fires unconditionally before\n* `runExecuteWithMiddleware`. `interceptExecute` (inside\n* `runExecuteWithMiddleware`) therefore observes the post-`beforeExecute`\n* plan — mutator mutations are visible in the params interceptors see.\n* The trade-off is documented on `RuntimeMiddleware.interceptExecute`.\n*/\nfunction runBeforeExecuteChain(plan, middleware, ctx, paramsMutator) {\n\treturn runBeforeChain(plan, middleware, ctx, paramsMutator, \"beforeExecute\", (mw) => mw.beforeExecute);\n}\nasync function runBeforeChain(plan, middleware, ctx, paramsMutator, phase, selectHook) {\n\tfor (const mw of middleware) {\n\t\tconst hook = selectHook(mw);\n\t\tif (hook === void 0) continue;\n\t\tcheckAborted(ctx, phase);\n\t\tconst work = hook(plan, ctx, paramsMutator);\n\t\tif (work !== void 0) await raceAgainstAbort(Promise.resolve(work), ctx.signal, phase);\n\t}\n}\n//#endregion\n//#region src/execution/run-with-middleware.ts\n/**\n* Drives a single query execution of `runDriver()` through the middleware\n* lifecycle's `interceptQuery` + row-source + termination phases.\n*\n* Lifecycle, in order:\n* 1. For each middleware in registration order: `interceptQuery(exec, ctx)`.\n* The first non-`undefined` result wins; subsequent middleware's\n* `interceptQuery` does not fire. On a hit, the runtime emits a\n* `middleware.interceptQuery` debug event naming the winning middleware,\n* switches the row source to the intercepted rows, and proceeds with\n* `source: 'middleware'`. On all-passthrough (every `interceptQuery`\n* returns `undefined` or is omitted), `source: 'driver'` is used and the\n* row source is `runDriver()`.\n* 2. Iterate the row source. On the driver path, for each row, for each\n* middleware in registration order: `onRow(row, exec, ctx)`; then yield\n* the row. On the intercepted hit path, `onRow` is skipped — intercepted\n* rows did not originate from a driver row stream — but rows are still\n* yielded to the consumer in order.\n* 3. On successful completion: for each middleware in registration order:\n* `afterQuery(exec, { rowCount, latencyMs, completed: true, source },\n* ctx)`.\n* 4. On any error thrown during steps 1–2: for each middleware in\n* registration order: `afterQuery(exec, { rowCount, latencyMs,\n* completed: false, source }, ctx)`. Errors thrown by `afterQuery`\n* during the error path are swallowed so they do not mask the original\n* error. The original error is then rethrown.\n*\n* `beforeQuery` is **not** fired here — see\n* {@link runBeforeQueryChain} in `before-execute-chain.ts`. Family runtimes\n* call that helper between the AST → plan lowering step and the parameter\n* encode step so middleware that mutates ParamRef values can have its\n* mutations visible to encode. `runQueryWithMiddleware` operates on the\n* fully-encoded plan; interceptors therefore observe a fully-mutated,\n* encoded plan.\n*\n* The `source` field on `AfterQueryResult` lets observers (telemetry, lints,\n* budgets) distinguish driver-served from middleware-served executions\n* without needing their own out-of-band signal.\n*\n* This helper is the single canonical implementation of the\n* intercept-and-row-source loop; family runtimes should not reimplement it.\n*/\nfunction runQueryWithMiddleware(exec, middleware, ctx, runDriver) {\n\tconst iterator = async function* () {\n\t\tconst startedAt = Date.now();\n\t\tlet rowCount = 0;\n\t\tlet completed = false;\n\t\tlet source = \"driver\";\n\t\tlet rowSource;\n\t\ttry {\n\t\t\tfor (const mw of middleware) {\n\t\t\t\tif (!mw.interceptQuery) continue;\n\t\t\t\tsource = \"middleware\";\n\t\t\t\tconst result = await mw.interceptQuery(exec, ctx);\n\t\t\t\tif (result === void 0) {\n\t\t\t\t\tsource = \"driver\";\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t\tctx.log.debug?.({\n\t\t\t\t\tevent: \"middleware.interceptQuery\",\n\t\t\t\t\tmiddleware: mw.name\n\t\t\t\t});\n\t\t\t\trowSource = blindCast(result.rows);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tif (source === \"driver\") rowSource = runDriver();\n\t\t\tfor await (const row of rowSource) {\n\t\t\t\tif (source === \"driver\") {\n\t\t\t\t\tfor (const mw of middleware) if (mw.onRow) await mw.onRow(row, exec, ctx);\n\t\t\t\t}\n\t\t\t\trowCount++;\n\t\t\t\tyield row;\n\t\t\t}\n\t\t\tcompleted = true;\n\t\t} catch (error) {\n\t\t\tawait notifyQueryCompletion(middleware, exec, ctx, {\n\t\t\t\trowCount,\n\t\t\t\tlatencyMs: Date.now() - startedAt,\n\t\t\t\tcompleted,\n\t\t\t\tsource\n\t\t\t}, true);\n\t\t\tthrow error;\n\t\t}\n\t\tawait notifyQueryCompletion(middleware, exec, ctx, {\n\t\t\trowCount,\n\t\t\tlatencyMs: Date.now() - startedAt,\n\t\t\tcompleted,\n\t\t\tsource\n\t\t}, false);\n\t};\n\treturn new AsyncIterableResult(iterator());\n}\n/**\n* Drives a single execute operation through the middleware\n* `interceptExecute` + statistics + termination phases.\n*\n* Lifecycle, in order:\n* 1. For each middleware in registration order: `interceptExecute(exec, ctx)`.\n* The first non-`undefined` result wins; subsequent middleware's\n* `interceptExecute` does not fire. On a hit, the runtime emits a\n* `middleware.interceptExecute` debug event naming the winning middleware,\n* uses the returned `stats`, and proceeds with `source: 'middleware'`.\n* On all-passthrough (every `interceptExecute` returns `undefined` or is\n* omitted), `source: 'driver'` is used and `runDriver()` supplies the\n* statistics.\n* 2. Execute operations return eager statistics. There is no row stream and\n* `onRow` does not fire.\n* 3. On successful completion: for each middleware in registration order:\n* `afterExecute(exec, { stats, latencyMs, completed: true, source }, ctx)`.\n* 4. On any error thrown during steps 1–2: for each middleware in\n* registration order: `afterExecute(exec, { latencyMs, completed: false,\n* source }, ctx)`. Errors thrown by `afterExecute` during the error path\n* are swallowed so they do not mask the original error. The original\n* error is then rethrown.\n*\n* `beforeExecute` is **not** fired here — see\n* {@link runBeforeExecuteChain} in `before-execute-chain.ts`. Family runtimes\n* call that helper between the AST → plan lowering step and the parameter\n* encode step so middleware that mutates ParamRef values can have its\n* mutations visible to encode. `runExecuteWithMiddleware` operates on the\n* fully-encoded plan; interceptors therefore observe a fully-mutated,\n* encoded plan.\n*\n* The `source` field on `AfterExecuteResult` lets observers (telemetry, lints,\n* budgets) distinguish driver-served from middleware-served executions\n* without needing their own out-of-band signal.\n*/\nasync function runExecuteWithMiddleware(exec, middleware, ctx, runDriver) {\n\tconst startedAt = Date.now();\n\tlet source = \"driver\";\n\tlet stats;\n\ttry {\n\t\tfor (const mw of middleware) {\n\t\t\tif (!mw.interceptExecute) continue;\n\t\t\tsource = \"middleware\";\n\t\t\tconst result = await mw.interceptExecute(exec, ctx);\n\t\t\tif (result === void 0) {\n\t\t\t\tsource = \"driver\";\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tctx.log.debug?.({\n\t\t\t\tevent: \"middleware.interceptExecute\",\n\t\t\t\tmiddleware: mw.name\n\t\t\t});\n\t\t\tstats = result.stats;\n\t\t\tbreak;\n\t\t}\n\t\tif (stats === void 0) stats = await runDriver();\n\t} catch (error) {\n\t\tconst latencyMs = Date.now() - startedAt;\n\t\tfor (const mw of middleware) {\n\t\t\tif (!mw.afterExecute) continue;\n\t\t\ttry {\n\t\t\t\tawait mw.afterExecute(exec, {\n\t\t\t\t\tlatencyMs,\n\t\t\t\t\tcompleted: false,\n\t\t\t\t\tsource\n\t\t\t\t}, ctx);\n\t\t\t} catch {}\n\t\t}\n\t\tthrow error;\n\t}\n\tconst latencyMs = Date.now() - startedAt;\n\tfor (const mw of middleware) if (mw.afterExecute) await mw.afterExecute(exec, {\n\t\tstats,\n\t\tlatencyMs,\n\t\tcompleted: true,\n\t\tsource\n\t}, ctx);\n\treturn stats;\n}\nasync function notifyQueryCompletion(middleware, exec, ctx, result, swallowErrors) {\n\tfor (const mw of middleware) {\n\t\tif (!mw.afterQuery) continue;\n\t\tif (swallowErrors) try {\n\t\t\tawait mw.afterQuery(exec, result, ctx);\n\t\t} catch {}\n\t\telse await mw.afterQuery(exec, result, ctx);\n\t}\n}\n//#endregion\n//#region src/execution/runtime-core.ts\n/**\n* Family-agnostic abstract runtime base.\n*\n* Defines the shared operation-specific middleware lifecycles:\n*\n* 1. `runBeforeCompile(plan)` — concrete; defaults to identity. SQL overrides\n* this to run its shared `beforeCompile` middleware-hook chain.\n* 2. `lower(plan)` — abstract. Each family produces its `*ExecutionPlan`\n* (SQL via `lowerSqlPlan`, Mongo via `adapter.lower`).\n* 3. Queries run `beforeQuery`; statements run `beforeExecute`. Both chains\n* run after lowering and before their matching driver terminal. Family\n* runtimes that expose a params mutator to downstream encoding override\n* the operation and call the matching helper at the pre-encode point.\n* 4. The matching runner processes `interceptQuery` or `interceptExecute`\n* before invoking the driver. Queries then fire `onRow` and `afterQuery`;\n* statements fire `afterExecute`.\n*\n* Concrete subclasses must implement `lower`, `runDriver`, `runExecute`, and\n* `close`.\n*\n* The class is generic over:\n* - `TPlan` — the family's pre-lowering plan type.\n* - `TExec` — the family's post-lowering (executable) plan type.\n* - `TMiddleware` — the family's middleware type. Constrained to\n* `RuntimeMiddleware<TExec>` because the operation-specific runners invoke\n* hooks with the lowered `TExec`. Middleware therefore sees the\n* post-lowering plan.\n*/\nvar RuntimeCore = class {\n\tmiddleware;\n\tctx;\n\tconstructor(options) {\n\t\tthis.middleware = options.middleware;\n\t\tthis.ctx = options.ctx;\n\t}\n\t/**\n\t* Pre-lowering hook for plan rewriting. Defaults to identity. Subclasses\n\t* may override to run a `beforeCompile` middleware chain (SQL does this\n\t* to support typed AST rewrites — see `before-compile-chain.ts`).\n\t*/\n\trunBeforeCompile(plan) {\n\t\treturn plan;\n\t}\n\tquery(plan, options) {\n\t\tconst self = this;\n\t\tconst signal = options?.signal;\n\t\tconst codecCtx = signal === void 0 ? {} : { signal };\n\t\tconst execCtx = {\n\t\t\t...self.ctx,\n\t\t\t...codecCtx,\n\t\t\tscope: options?.scope ?? self.ctx.scope,\n\t\t\tplanExecutionId: crypto.randomUUID()\n\t\t};\n\t\tasync function* generator() {\n\t\t\tcheckAborted(codecCtx, \"stream\");\n\t\t\tconst compiled = await self.runBeforeCompile(plan);\n\t\t\tconst exec = await self.lower(compiled, codecCtx);\n\t\t\tawait runBeforeQueryChain(exec, self.middleware, execCtx);\n\t\t\tyield* runQueryWithMiddleware(exec, self.middleware, execCtx, () => self.runDriver(exec));\n\t\t}\n\t\treturn new AsyncIterableResult(generator());\n\t}\n\tasync execute(plan, options) {\n\t\tconst signal = options?.signal;\n\t\tconst codecCtx = signal === void 0 ? {} : { signal };\n\t\tconst execCtx = {\n\t\t\t...this.ctx,\n\t\t\t...codecCtx,\n\t\t\tscope: options?.scope ?? this.ctx.scope,\n\t\t\tplanExecutionId: crypto.randomUUID()\n\t\t};\n\t\tcheckAborted(codecCtx, \"stream\");\n\t\tconst compiled = await this.runBeforeCompile(plan);\n\t\tconst exec = await this.lower(compiled, codecCtx);\n\t\tawait runBeforeExecuteChain(exec, this.middleware, execCtx);\n\t\treturn runExecuteWithMiddleware(exec, this.middleware, execCtx, () => this.runExecute(exec));\n\t}\n};\n//#endregion\n//#region src/execution/runtime-middleware.ts\nfunction checkMiddlewareCompatibility(middleware, runtimeFamilyId, runtimeTargetId) {\n\tif (middleware.targetId !== void 0 && middleware.familyId === void 0) throw runtimeError(\"RUNTIME.MIDDLEWARE_INCOMPATIBLE\", `Middleware '${middleware.name}' specifies targetId '${middleware.targetId}' without familyId`, {\n\t\tmiddleware: middleware.name,\n\t\ttargetId: middleware.targetId\n\t});\n\tif (middleware.familyId !== void 0 && middleware.familyId !== runtimeFamilyId) throw runtimeError(\"RUNTIME.MIDDLEWARE_FAMILY_MISMATCH\", `Middleware '${middleware.name}' requires family '${middleware.familyId}' but the runtime is configured for family '${runtimeFamilyId}'`, {\n\t\tmiddleware: middleware.name,\n\t\tmiddlewareFamilyId: middleware.familyId,\n\t\truntimeFamilyId\n\t});\n\tif (middleware.targetId !== void 0 && middleware.targetId !== runtimeTargetId) throw runtimeError(\"RUNTIME.MIDDLEWARE_TARGET_MISMATCH\", `Middleware '${middleware.name}' requires target '${middleware.targetId}' but the runtime is configured for target '${runtimeTargetId}'`, {\n\t\tmiddleware: middleware.name,\n\t\tmiddlewareTargetId: middleware.targetId,\n\t\truntimeTargetId\n\t});\n}\n//#endregion\n//#region src/meta-builder.ts\nvar MetaBuilderImpl = class {\n\t#kind;\n\t#terminalName;\n\t#annotations = /* @__PURE__ */ new Map();\n\tconstructor(kind, terminalName) {\n\t\tthis.#kind = kind;\n\t\tthis.#terminalName = terminalName;\n\t}\n\tget annotations() {\n\t\treturn this.#annotations;\n\t}\n\tannotate(annotation) {\n\t\tconst value = annotation;\n\t\tassertAnnotationsApplicable([value], this.#kind, this.#terminalName);\n\t\tthis.#annotations.set(value.namespace, value);\n\t\treturn this;\n\t}\n};\n/**\n* Construct a lane-side meta builder for a terminal of operation kind `K`.\n*\n* Lane terminals call this with their `kind` (`'read'` or `'write'`) and a\n* `terminalName` for error messages, hand the resulting builder to the\n* user-supplied configurator callback (typed as `MetaBuilder<K>`, the\n* narrower public view), and read `meta.annotations` afterwards to thread\n* the recorded values into `plan.meta.annotations`.\n*/\nfunction createMetaBuilder(kind, terminalName) {\n\treturn new MetaBuilderImpl(kind, terminalName);\n}\n//#endregion\nexport { AsyncIterableResult, RUNTIME_ABORTED, RuntimeCore, assertAnnotationsApplicable, checkAborted, checkMiddlewareCompatibility, createMetaBuilder, defineAnnotation, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runBeforeQueryChain, runExecuteWithMiddleware, runQueryWithMiddleware, runtimeAborted, runtimeError };\n\n//# sourceMappingURL=runtime.mjs.map"],"mappings":";;;;;;;;;;;;;;;;;;AAkBA,MAAM,kBAAkB;;;;;;;;;;AAUxB,SAAS,eAAe,OAAO,OAAO;CACrC,MAAM,WAAW,aAAa,iBAAiB,4BAA4B,SAAS,EAAE,MAAM,CAAC;CAC7F,OAAO,OAAO,OAAO,UAAU,EAAE,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