@prisma-next/framework-components 0.5.0-dev.27 → 0.5.0-dev.29
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/README.md +31 -0
- package/dist/authoring.d.mts +1 -1
- package/dist/authoring.mjs +1 -1
- package/dist/authoring.mjs.map +1 -1
- package/dist/{codec-types-DQ1Agjom.d.mts → codec-types-DXv-ROhF.d.mts} +33 -7
- package/dist/codec-types-DXv-ROhF.d.mts.map +1 -0
- package/dist/codec.d.mts +2 -2
- package/dist/codec.mjs +1 -1
- package/dist/codec.mjs.map +1 -1
- package/dist/components.d.mts +1 -1
- package/dist/components.mjs +1 -1
- package/dist/control.d.mts +54 -13
- package/dist/control.d.mts.map +1 -1
- package/dist/control.mjs +11 -5
- package/dist/control.mjs.map +1 -1
- package/dist/{emission-types-BPAALJbF.d.mts → emission-types-D234HxUz.d.mts} +3 -3
- package/dist/emission-types-D234HxUz.d.mts.map +1 -0
- package/dist/emission.d.mts +2 -2
- package/dist/execution.d.mts +5 -5
- package/dist/execution.d.mts.map +1 -1
- package/dist/execution.mjs +3 -3
- package/dist/execution.mjs.map +1 -1
- package/dist/{framework-authoring-D1-JZ37B.d.mts → framework-authoring-BdrFDx4x.d.mts} +2 -2
- package/dist/framework-authoring-BdrFDx4x.d.mts.map +1 -0
- package/dist/{framework-components-C8ZhSwXe.mjs → framework-components-BsWST1Rn.mjs} +2 -2
- package/dist/framework-components-BsWST1Rn.mjs.map +1 -0
- package/dist/{framework-components-DFZMi2h7.d.mts → framework-components-Buvf7mnC.d.mts} +6 -6
- package/dist/framework-components-Buvf7mnC.d.mts.map +1 -0
- package/dist/psl-ast-9X5rwo98.d.mts +159 -0
- package/dist/psl-ast-9X5rwo98.d.mts.map +1 -0
- package/dist/psl-ast.d.mts +2 -0
- package/dist/psl-ast.mjs +1 -0
- package/dist/runtime.d.mts +110 -25
- package/dist/runtime.d.mts.map +1 -1
- package/dist/runtime.mjs +103 -8
- package/dist/runtime.mjs.map +1 -1
- package/dist/{types-import-spec-C4sc7wbb.d.mts → types-import-spec-D-O6GotH.d.mts} +2 -2
- package/dist/types-import-spec-D-O6GotH.d.mts.map +1 -0
- package/package.json +5 -4
- package/src/control/control-capabilities.ts +71 -0
- package/src/{control-descriptors.ts → control/control-descriptors.ts} +7 -7
- package/src/{control-instances.ts → control/control-instances.ts} +6 -6
- package/src/{control-migration-types.ts → control/control-migration-types.ts} +1 -1
- package/src/control/control-operation-preview.ts +23 -0
- package/src/{control-stack.ts → control/control-stack.ts} +13 -13
- package/src/{emission-types.ts → control/emission-types.ts} +1 -1
- package/src/control/psl-ast.ts +193 -0
- package/src/{execution-descriptors.ts → execution/execution-descriptors.ts} +7 -7
- package/src/{execution-instances.ts → execution/execution-instances.ts} +1 -1
- package/src/{execution-requirements.ts → execution/execution-requirements.ts} +1 -1
- package/src/execution/race-against-abort.ts +85 -0
- package/src/{runtime-core.ts → execution/runtime-core.ts} +27 -3
- package/src/{runtime-error.ts → execution/runtime-error.ts} +28 -0
- package/src/{runtime-middleware.ts → execution/runtime-middleware.ts} +17 -1
- package/src/exports/authoring.ts +2 -2
- package/src/exports/codec.ts +2 -2
- package/src/exports/components.ts +2 -2
- package/src/exports/control.ts +26 -12
- package/src/exports/emission.ts +2 -2
- package/src/exports/execution.ts +5 -5
- package/src/exports/psl-ast.ts +1 -0
- package/src/exports/runtime.ts +16 -9
- package/src/{codec-types.ts → shared/codec-types.ts} +31 -4
- package/dist/codec-types-DQ1Agjom.d.mts.map +0 -1
- package/dist/emission-types-BPAALJbF.d.mts.map +0 -1
- package/dist/framework-authoring-D1-JZ37B.d.mts.map +0 -1
- package/dist/framework-components-C8ZhSwXe.mjs.map +0 -1
- package/dist/framework-components-DFZMi2h7.d.mts.map +0 -1
- package/dist/types-import-spec-C4sc7wbb.d.mts.map +0 -1
- package/src/control-capabilities.ts +0 -34
- /package/src/{control-result-types.ts → control/control-result-types.ts} +0 -0
- /package/src/{control-schema-view.ts → control/control-schema-view.ts} +0 -0
- /package/src/{async-iterable-result.ts → execution/async-iterable-result.ts} +0 -0
- /package/src/{execution-stack.ts → execution/execution-stack.ts} +0 -0
- /package/src/{query-plan.ts → execution/query-plan.ts} +0 -0
- /package/src/{run-with-middleware.ts → execution/run-with-middleware.ts} +0 -0
- /package/src/{framework-authoring.ts → shared/framework-authoring.ts} +0 -0
- /package/src/{framework-components.ts → shared/framework-components.ts} +0 -0
- /package/src/{mutation-default-types.ts → shared/mutation-default-types.ts} +0 -0
- /package/src/{types-import-spec.ts → shared/types-import-spec.ts} +0 -0
package/dist/runtime.d.mts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { n as CodecCallContext } from "./codec-types-DXv-ROhF.mjs";
|
|
1
2
|
import { PlanMeta } from "@prisma-next/contract/types";
|
|
2
3
|
|
|
3
|
-
//#region src/async-iterable-result.d.ts
|
|
4
|
+
//#region src/execution/async-iterable-result.d.ts
|
|
4
5
|
declare class AsyncIterableResult<Row> implements AsyncIterable<Row>, PromiseLike<Row[]> {
|
|
5
6
|
private readonly generator;
|
|
6
7
|
private consumed;
|
|
@@ -14,7 +15,7 @@ declare class AsyncIterableResult<Row> implements AsyncIterable<Row>, PromiseLik
|
|
|
14
15
|
then<TResult1 = Row[], TResult2 = never>(onfulfilled?: ((value: Row[]) => TResult1 | PromiseLike<TResult1>) | undefined | null, onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null): PromiseLike<TResult1 | TResult2>;
|
|
15
16
|
}
|
|
16
17
|
//#endregion
|
|
17
|
-
//#region src/query-plan.d.ts
|
|
18
|
+
//#region src/execution/query-plan.d.ts
|
|
18
19
|
/**
|
|
19
20
|
* Family-agnostic plan marker.
|
|
20
21
|
*
|
|
@@ -63,7 +64,87 @@ type ResultType<P> = '_row' extends keyof P ? P extends {
|
|
|
63
64
|
readonly _row?: infer R;
|
|
64
65
|
} ? R : never : never;
|
|
65
66
|
//#endregion
|
|
66
|
-
//#region src/runtime-
|
|
67
|
+
//#region src/execution/runtime-error.d.ts
|
|
68
|
+
interface RuntimeErrorEnvelope extends Error {
|
|
69
|
+
readonly code: string;
|
|
70
|
+
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';
|
|
71
|
+
readonly severity: 'error';
|
|
72
|
+
readonly details?: Record<string, unknown>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stable code emitted by the runtime when an in-flight `execute()`
|
|
76
|
+
* is cancelled via the per-query `AbortSignal`. The envelope's
|
|
77
|
+
* `details.phase` distinguishes where the abort was observed:
|
|
78
|
+
*
|
|
79
|
+
* - `'encode'` — abort fired during `encodeParams` (SQL) or
|
|
80
|
+
* `resolveValue` (Mongo).
|
|
81
|
+
* - `'decode'` — abort fired during `decodeRow` / `decodeField`.
|
|
82
|
+
* - `'stream'` — abort fired between rows or before any codec call
|
|
83
|
+
* (already-aborted at entry).
|
|
84
|
+
*/
|
|
85
|
+
declare const RUNTIME_ABORTED: "RUNTIME.ABORTED";
|
|
86
|
+
/** Discriminator placed in `details.phase` of a `RUNTIME.ABORTED` envelope. */
|
|
87
|
+
type RuntimeAbortedPhase = 'encode' | 'decode' | 'stream';
|
|
88
|
+
/**
|
|
89
|
+
* Type guard for the runtime-error envelope produced by `runtimeError`.
|
|
90
|
+
*
|
|
91
|
+
* Prefer this over duck-typing on `error.code` directly so consumers stay
|
|
92
|
+
* insulated from the envelope's internal shape.
|
|
93
|
+
*/
|
|
94
|
+
declare function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope;
|
|
95
|
+
declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
|
|
96
|
+
/**
|
|
97
|
+
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the
|
|
98
|
+
* abort was observed (encode / decode / stream); cause carries `signal.reason`
|
|
99
|
+
* verbatim from the platform — native abort produces a `DOMException`,
|
|
100
|
+
* explicit `controller.abort(reason)` produces whatever the caller passed.
|
|
101
|
+
* No synthesis happens here.
|
|
102
|
+
*/
|
|
103
|
+
declare function runtimeAborted(phase: RuntimeAbortedPhase, cause?: unknown): RuntimeErrorEnvelope;
|
|
104
|
+
//#endregion
|
|
105
|
+
//#region src/execution/race-against-abort.d.ts
|
|
106
|
+
/**
|
|
107
|
+
* Throw a phase-tagged `RUNTIME.ABORTED` envelope if the supplied
|
|
108
|
+
* codec-call context is already aborted at the precheck site. Centralises
|
|
109
|
+
* the `if (ctx.signal?.aborted) throw runtimeAborted(...)` pattern that
|
|
110
|
+
* every codec dispatch site repeats.
|
|
111
|
+
*/
|
|
112
|
+
declare function checkAborted(ctx: CodecCallContext, phase: RuntimeAbortedPhase): void;
|
|
113
|
+
/**
|
|
114
|
+
* Race a per-cell `Promise.all` (or any other in-flight work promise) against
|
|
115
|
+
* the supplied abort signal so the runtime returns `RUNTIME.ABORTED` promptly
|
|
116
|
+
* even when codec bodies ignore the signal. In-flight bodies that ignore the
|
|
117
|
+
* signal are abandoned and run to completion in the background — the
|
|
118
|
+
* cooperative-cancellation contract documented in ADR 204.
|
|
119
|
+
*
|
|
120
|
+
* Call sites still SHOULD pre-check `signal.aborted` and short-circuit with
|
|
121
|
+
* a phase-tagged `RUNTIME.ABORTED` envelope before invoking this helper —
|
|
122
|
+
* that path is the canonical "aborted at entry" surface and avoids
|
|
123
|
+
* scheduling the work promise. As a defensive belt-and-braces, this helper
|
|
124
|
+
* also handles the already-aborted case internally: `AbortSignal` does not
|
|
125
|
+
* replay past abort events to listeners registered after the abort, so we
|
|
126
|
+
* inspect `signal.aborted` synchronously and reject with the sentinel
|
|
127
|
+
* before installing the listener. The rejection is still attributed to the
|
|
128
|
+
* abort path via the sentinel-identity check.
|
|
129
|
+
*
|
|
130
|
+
* Distinguishing the rejection source is load-bearing for AC-ERR4
|
|
131
|
+
* (`RUNTIME.ENCODE_FAILED` / `RUNTIME.DECODE_FAILED` pass through unchanged).
|
|
132
|
+
* The semantically equivalent `abortable(signal)` helper in
|
|
133
|
+
* `@prisma-next/utils` rejects with `signal.reason ?? new DOMException(...)`,
|
|
134
|
+
* which is not stably distinguishable from a codec-thrown error by identity
|
|
135
|
+
* alone (a fresh fallback DOMException is allocated per call). We instead
|
|
136
|
+
* track abort attribution with a unique sentinel: only the `onAbort` listener
|
|
137
|
+
* installed here ever rejects with the sentinel, so an `error === sentinel`
|
|
138
|
+
* identity check after the race is unambiguous.
|
|
139
|
+
*
|
|
140
|
+
* Lives in `framework-components` (rather than the SQL family, where it
|
|
141
|
+
* originated in m2) so every family runtime that needs cooperative
|
|
142
|
+
* cancellation around a codec-dispatch `Promise.all` (SQL encode + decode
|
|
143
|
+
* today, Mongo encode in m3) shares the same attribution logic.
|
|
144
|
+
*/
|
|
145
|
+
declare function raceAgainstAbort<T>(work: Promise<T>, signal: AbortSignal | undefined, phase: RuntimeAbortedPhase): Promise<T>;
|
|
146
|
+
//#endregion
|
|
147
|
+
//#region src/execution/runtime-middleware.d.ts
|
|
67
148
|
interface RuntimeLog {
|
|
68
149
|
info(event: unknown): void;
|
|
69
150
|
warn(event: unknown): void;
|
|
@@ -97,6 +178,18 @@ interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan> {
|
|
|
97
178
|
onRow?(row: Record<string, unknown>, plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
98
179
|
afterExecute?(plan: TPlan, result: AfterExecuteResult, ctx: RuntimeMiddlewareContext): Promise<void>;
|
|
99
180
|
}
|
|
181
|
+
/**
|
|
182
|
+
* Optional per-`execute` options accepted by every family runtime.
|
|
183
|
+
*
|
|
184
|
+
* `signal` is the per-query cancellation signal. The runtime threads the
|
|
185
|
+
* signal through to every codec call for the query and uses it to short-
|
|
186
|
+
* circuit the row stream with `RUNTIME.ABORTED` when the caller aborts.
|
|
187
|
+
* Omitting the option (or passing `undefined`) preserves today's behavior
|
|
188
|
+
* bit-for-bit.
|
|
189
|
+
*/
|
|
190
|
+
interface RuntimeExecuteOptions {
|
|
191
|
+
readonly signal?: AbortSignal;
|
|
192
|
+
}
|
|
100
193
|
/**
|
|
101
194
|
* Cross-family SPI for any runtime that can execute plans and be shut down.
|
|
102
195
|
* Each family runtime (SQL, Mongo) satisfies this interface — SQL nominally,
|
|
@@ -108,12 +201,12 @@ interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan> {
|
|
|
108
201
|
interface RuntimeExecutor<TPlan extends QueryPlan> {
|
|
109
202
|
execute<Row>(plan: TPlan & {
|
|
110
203
|
readonly _row?: Row;
|
|
111
|
-
}): AsyncIterableResult<Row>;
|
|
204
|
+
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
112
205
|
close(): Promise<void>;
|
|
113
206
|
}
|
|
114
207
|
declare function checkMiddlewareCompatibility(middleware: RuntimeMiddleware, runtimeFamilyId: string, runtimeTargetId: string): void;
|
|
115
208
|
//#endregion
|
|
116
|
-
//#region src/run-with-middleware.d.ts
|
|
209
|
+
//#region src/execution/run-with-middleware.d.ts
|
|
117
210
|
/**
|
|
118
211
|
* Drives a single execution of `runDriver()` through the middleware lifecycle.
|
|
119
212
|
*
|
|
@@ -134,7 +227,7 @@ declare function checkMiddlewareCompatibility(middleware: RuntimeMiddleware, run
|
|
|
134
227
|
*/
|
|
135
228
|
declare function runWithMiddleware<TExec extends ExecutionPlan, Row>(exec: TExec, middleware: ReadonlyArray<RuntimeMiddleware<TExec>>, ctx: RuntimeMiddlewareContext, runDriver: () => AsyncIterable<Row>): AsyncIterableResult<Row>;
|
|
136
229
|
//#endregion
|
|
137
|
-
//#region src/runtime-core.d.ts
|
|
230
|
+
//#region src/execution/runtime-core.d.ts
|
|
138
231
|
/**
|
|
139
232
|
* Constructor options shared by every concrete `RuntimeCore` subclass.
|
|
140
233
|
*
|
|
@@ -185,8 +278,16 @@ declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends Execut
|
|
|
185
278
|
* Lower a pre-lowering `TPlan` into the family's executable `TExec`.
|
|
186
279
|
* Family-specific: SQL produces `{ sql, params, ast?, ... }`; Mongo
|
|
187
280
|
* produces `{ command, ... }`.
|
|
281
|
+
*
|
|
282
|
+
* `ctx` carries per-query cancellation (and any future fields on
|
|
283
|
+
* `CodecCallContext`); concrete subclasses forward it to the
|
|
284
|
+
* encode-side codec dispatch site (e.g. SQL's `encodeParams` in m2,
|
|
285
|
+
* Mongo's `resolveValue` in m3). The runtime allocates one ctx per
|
|
286
|
+
* `execute()` call and threads the same reference everywhere; the
|
|
287
|
+
* `signal` field inside may be `undefined`, but the ctx object itself
|
|
288
|
+
* is always present.
|
|
188
289
|
*/
|
|
189
|
-
protected abstract lower(plan: TPlan): TExec | Promise<TExec>;
|
|
290
|
+
protected abstract lower(plan: TPlan, ctx: CodecCallContext): TExec | Promise<TExec>;
|
|
190
291
|
/**
|
|
191
292
|
* Drive the underlying transport for a lowered `TExec`. Yields raw rows
|
|
192
293
|
* directly from the driver as `Record<string, unknown>`; codec decoding
|
|
@@ -201,24 +302,8 @@ declare abstract class RuntimeCore<TPlan extends QueryPlan, TExec extends Execut
|
|
|
201
302
|
abstract close(): Promise<void>;
|
|
202
303
|
execute<Row>(plan: TPlan & {
|
|
203
304
|
readonly _row?: Row;
|
|
204
|
-
}): AsyncIterableResult<Row>;
|
|
205
|
-
}
|
|
206
|
-
//#endregion
|
|
207
|
-
//#region src/runtime-error.d.ts
|
|
208
|
-
interface RuntimeErrorEnvelope extends Error {
|
|
209
|
-
readonly code: string;
|
|
210
|
-
readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';
|
|
211
|
-
readonly severity: 'error';
|
|
212
|
-
readonly details?: Record<string, unknown>;
|
|
305
|
+
}, options?: RuntimeExecuteOptions): AsyncIterableResult<Row>;
|
|
213
306
|
}
|
|
214
|
-
/**
|
|
215
|
-
* Type guard for the runtime-error envelope produced by `runtimeError`.
|
|
216
|
-
*
|
|
217
|
-
* Prefer this over duck-typing on `error.code` directly so consumers stay
|
|
218
|
-
* insulated from the envelope's internal shape.
|
|
219
|
-
*/
|
|
220
|
-
declare function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope;
|
|
221
|
-
declare function runtimeError(code: string, message: string, details?: Record<string, unknown>): RuntimeErrorEnvelope;
|
|
222
307
|
//#endregion
|
|
223
|
-
export { type AfterExecuteResult, AsyncIterableResult, type ExecutionPlan, type QueryPlan, type ResultType, RuntimeCore, type RuntimeCoreOptions, type RuntimeErrorEnvelope, type RuntimeExecutor, type RuntimeLog, type RuntimeMiddleware, type RuntimeMiddlewareContext, checkMiddlewareCompatibility, isRuntimeError, runWithMiddleware, runtimeError };
|
|
308
|
+
export { type AfterExecuteResult, AsyncIterableResult, type ExecutionPlan, type QueryPlan, RUNTIME_ABORTED, type ResultType, type RuntimeAbortedPhase, RuntimeCore, type RuntimeCoreOptions, type RuntimeErrorEnvelope, type RuntimeExecuteOptions, type RuntimeExecutor, type RuntimeLog, type RuntimeMiddleware, type RuntimeMiddlewareContext, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runWithMiddleware, runtimeAborted, runtimeError };
|
|
224
309
|
//# sourceMappingURL=runtime.d.mts.map
|
package/dist/runtime.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/async-iterable-result.ts","../src/query-plan.ts","../src/runtime-
|
|
1
|
+
{"version":3,"file":"runtime.d.mts","names":[],"sources":["../src/execution/async-iterable-result.ts","../src/execution/query-plan.ts","../src/execution/runtime-error.ts","../src/execution/race-against-abort.ts","../src/execution/runtime-middleware.ts","../src/execution/run-with-middleware.ts","../src/execution/runtime-core.ts"],"sourcesContent":[],"mappings":";;;;cAEa,oCAAoC,cAAc,MAAM,YAAY;;;;EAApE,QAAA,oBAAmB;EAA+B,WAAA,CAAA,SAAA,EAMtC,cANsC,CAMvB,GANuB,EAAA,IAAA,EAAA,OAAA,CAAA;EAAkB,CAU9E,MAAA,CAAO,aAAA,GAVuE,EAU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AmBW,SAAA,UAAA,EMXE,aNWF,CMXgB,WNWhB,CAAA;EAAR,SAAA,GAAA,EMVG,wBNUH;;;;;;;;;;;;;;;;;;;;;;ACjBb;AAkBA;AAgBA;;;uBKCsB,0BACN,yBACA,mCACM,kBAAkB,mBAC3B,gBAAgB;EJrDZ,mBAAA,UAAqB,EIuDL,aJvDa,CIuDC,WJvDI,CAAA;EAkBtC,mBAA4C,GAAA,EIsC/B,wBJtC+B;EAG7C,WAAA,CAAA,OAAA,EIqCW,kBJrCQ,CIqCW,WJrCX,CAAA;EAQf;AAUhB;AAwCA;;;mCIXmC,QAAQ,QAAQ,QAAQ;EH1D3C;AAsChB;;;;;;;;;;;AC5CA;EAOiB,mBAAA,KAAA,CAAA,IAAwB,EE0ER,KF1EQ,EAAA,GAIzB,EEsE6B,gBFtEnB,CAAA,EEsEsC,KFtEtC,GEsE8C,OFtE9C,CEsEsD,KFtEtD,CAAA;EAGT;AAcjB;;;;;;;;;EAKoF,mBAAA,SAAA,CAAA,IAAA,EE4D/C,KF5D+C,CAAA,EE4DvC,aF5DuC,CE4DzB,MF5DyB,CAAA,MAAA,EAAA,OAAA,CAAA,CAAA;EAE1E,SAAA,KAAA,CAAA,CAAA,EE4DU,OF5DV,CAAA,IAAA,CAAA;EACE,OAAA,CAAA,GAAA,CAAA,CAAA,IAAA,EE8DF,KF9DE,GAAA;IACH,SAAA,IAAA,CAAA,EE6D2B,GF7D3B;EACJ,CAAA,EAAA,OAAA,CAAA,EE6DS,qBF7DT,CAAA,EE8DA,mBF9DA,CE8DoB,GF9DpB,CAAA"}
|
package/dist/runtime.mjs
CHANGED
|
@@ -1,4 +1,16 @@
|
|
|
1
|
-
//#region src/runtime-error.ts
|
|
1
|
+
//#region src/execution/runtime-error.ts
|
|
2
|
+
/**
|
|
3
|
+
* Stable code emitted by the runtime when an in-flight `execute()`
|
|
4
|
+
* is cancelled via the per-query `AbortSignal`. The envelope's
|
|
5
|
+
* `details.phase` distinguishes where the abort was observed:
|
|
6
|
+
*
|
|
7
|
+
* - `'encode'` — abort fired during `encodeParams` (SQL) or
|
|
8
|
+
* `resolveValue` (Mongo).
|
|
9
|
+
* - `'decode'` — abort fired during `decodeRow` / `decodeField`.
|
|
10
|
+
* - `'stream'` — abort fired between rows or before any codec call
|
|
11
|
+
* (already-aborted at entry).
|
|
12
|
+
*/
|
|
13
|
+
const RUNTIME_ABORTED = "RUNTIME.ABORTED";
|
|
2
14
|
/**
|
|
3
15
|
* Type guard for the runtime-error envelope produced by `runtimeError`.
|
|
4
16
|
*
|
|
@@ -32,9 +44,20 @@ function resolveCategory(code) {
|
|
|
32
44
|
default: return "RUNTIME";
|
|
33
45
|
}
|
|
34
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the
|
|
49
|
+
* abort was observed (encode / decode / stream); cause carries `signal.reason`
|
|
50
|
+
* verbatim from the platform — native abort produces a `DOMException`,
|
|
51
|
+
* explicit `controller.abort(reason)` produces whatever the caller passed.
|
|
52
|
+
* No synthesis happens here.
|
|
53
|
+
*/
|
|
54
|
+
function runtimeAborted(phase, cause) {
|
|
55
|
+
const envelope = runtimeError(RUNTIME_ABORTED, `Operation aborted during ${phase}`, { phase });
|
|
56
|
+
return Object.assign(envelope, { cause });
|
|
57
|
+
}
|
|
35
58
|
|
|
36
59
|
//#endregion
|
|
37
|
-
//#region src/async-iterable-result.ts
|
|
60
|
+
//#region src/execution/async-iterable-result.ts
|
|
38
61
|
var AsyncIterableResult = class {
|
|
39
62
|
generator;
|
|
40
63
|
consumed = false;
|
|
@@ -81,7 +104,76 @@ var AsyncIterableResult = class {
|
|
|
81
104
|
};
|
|
82
105
|
|
|
83
106
|
//#endregion
|
|
84
|
-
//#region src/
|
|
107
|
+
//#region src/execution/race-against-abort.ts
|
|
108
|
+
/**
|
|
109
|
+
* Throw a phase-tagged `RUNTIME.ABORTED` envelope if the supplied
|
|
110
|
+
* codec-call context is already aborted at the precheck site. Centralises
|
|
111
|
+
* the `if (ctx.signal?.aborted) throw runtimeAborted(...)` pattern that
|
|
112
|
+
* every codec dispatch site repeats.
|
|
113
|
+
*/
|
|
114
|
+
function checkAborted(ctx, phase) {
|
|
115
|
+
if (ctx.signal?.aborted) throw runtimeAborted(phase, ctx.signal.reason);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Race a per-cell `Promise.all` (or any other in-flight work promise) against
|
|
119
|
+
* the supplied abort signal so the runtime returns `RUNTIME.ABORTED` promptly
|
|
120
|
+
* even when codec bodies ignore the signal. In-flight bodies that ignore the
|
|
121
|
+
* signal are abandoned and run to completion in the background — the
|
|
122
|
+
* cooperative-cancellation contract documented in ADR 204.
|
|
123
|
+
*
|
|
124
|
+
* Call sites still SHOULD pre-check `signal.aborted` and short-circuit with
|
|
125
|
+
* a phase-tagged `RUNTIME.ABORTED` envelope before invoking this helper —
|
|
126
|
+
* that path is the canonical "aborted at entry" surface and avoids
|
|
127
|
+
* scheduling the work promise. As a defensive belt-and-braces, this helper
|
|
128
|
+
* also handles the already-aborted case internally: `AbortSignal` does not
|
|
129
|
+
* replay past abort events to listeners registered after the abort, so we
|
|
130
|
+
* inspect `signal.aborted` synchronously and reject with the sentinel
|
|
131
|
+
* before installing the listener. The rejection is still attributed to the
|
|
132
|
+
* abort path via the sentinel-identity check.
|
|
133
|
+
*
|
|
134
|
+
* Distinguishing the rejection source is load-bearing for AC-ERR4
|
|
135
|
+
* (`RUNTIME.ENCODE_FAILED` / `RUNTIME.DECODE_FAILED` pass through unchanged).
|
|
136
|
+
* The semantically equivalent `abortable(signal)` helper in
|
|
137
|
+
* `@prisma-next/utils` rejects with `signal.reason ?? new DOMException(...)`,
|
|
138
|
+
* which is not stably distinguishable from a codec-thrown error by identity
|
|
139
|
+
* alone (a fresh fallback DOMException is allocated per call). We instead
|
|
140
|
+
* track abort attribution with a unique sentinel: only the `onAbort` listener
|
|
141
|
+
* installed here ever rejects with the sentinel, so an `error === sentinel`
|
|
142
|
+
* identity check after the race is unambiguous.
|
|
143
|
+
*
|
|
144
|
+
* Lives in `framework-components` (rather than the SQL family, where it
|
|
145
|
+
* originated in m2) so every family runtime that needs cooperative
|
|
146
|
+
* cancellation around a codec-dispatch `Promise.all` (SQL encode + decode
|
|
147
|
+
* today, Mongo encode in m3) shares the same attribution logic.
|
|
148
|
+
*/
|
|
149
|
+
async function raceAgainstAbort(work, signal, phase) {
|
|
150
|
+
if (signal === void 0) return await work;
|
|
151
|
+
const sentinel = { reason: void 0 };
|
|
152
|
+
let onAbort;
|
|
153
|
+
const abortPromise = new Promise((_, reject) => {
|
|
154
|
+
if (signal.aborted) {
|
|
155
|
+
sentinel.reason = signal.reason;
|
|
156
|
+
reject(sentinel);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
onAbort = () => {
|
|
160
|
+
sentinel.reason = signal.reason;
|
|
161
|
+
reject(sentinel);
|
|
162
|
+
};
|
|
163
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
164
|
+
});
|
|
165
|
+
try {
|
|
166
|
+
return await Promise.race([work, abortPromise]);
|
|
167
|
+
} catch (error) {
|
|
168
|
+
if (error === sentinel) throw runtimeAborted(phase, sentinel.reason);
|
|
169
|
+
throw error;
|
|
170
|
+
} finally {
|
|
171
|
+
if (onAbort) signal.removeEventListener("abort", onAbort);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
//#endregion
|
|
176
|
+
//#region src/execution/run-with-middleware.ts
|
|
85
177
|
/**
|
|
86
178
|
* Drives a single execution of `runDriver()` through the middleware lifecycle.
|
|
87
179
|
*
|
|
@@ -135,7 +227,7 @@ function runWithMiddleware(exec, middleware, ctx, runDriver) {
|
|
|
135
227
|
}
|
|
136
228
|
|
|
137
229
|
//#endregion
|
|
138
|
-
//#region src/runtime-core.ts
|
|
230
|
+
//#region src/execution/runtime-core.ts
|
|
139
231
|
/**
|
|
140
232
|
* Family-agnostic abstract runtime base.
|
|
141
233
|
*
|
|
@@ -176,11 +268,14 @@ var RuntimeCore = class {
|
|
|
176
268
|
runBeforeCompile(plan) {
|
|
177
269
|
return plan;
|
|
178
270
|
}
|
|
179
|
-
execute(plan) {
|
|
271
|
+
execute(plan, options) {
|
|
180
272
|
const self = this;
|
|
273
|
+
const signal = options?.signal;
|
|
274
|
+
const codecCtx = signal === void 0 ? {} : { signal };
|
|
181
275
|
async function* generator() {
|
|
276
|
+
checkAborted(codecCtx, "stream");
|
|
182
277
|
const compiled = await self.runBeforeCompile(plan);
|
|
183
|
-
const exec = await self.lower(compiled);
|
|
278
|
+
const exec = await self.lower(compiled, codecCtx);
|
|
184
279
|
yield* runWithMiddleware(exec, self.middleware, self.ctx, () => self.runDriver(exec));
|
|
185
280
|
}
|
|
186
281
|
return new AsyncIterableResult(generator());
|
|
@@ -188,7 +283,7 @@ var RuntimeCore = class {
|
|
|
188
283
|
};
|
|
189
284
|
|
|
190
285
|
//#endregion
|
|
191
|
-
//#region src/runtime-middleware.ts
|
|
286
|
+
//#region src/execution/runtime-middleware.ts
|
|
192
287
|
function checkMiddlewareCompatibility(middleware, runtimeFamilyId, runtimeTargetId) {
|
|
193
288
|
if (middleware.targetId !== void 0 && middleware.familyId === void 0) throw runtimeError("RUNTIME.MIDDLEWARE_INCOMPATIBLE", `Middleware '${middleware.name}' specifies targetId '${middleware.targetId}' without familyId`, {
|
|
194
289
|
middleware: middleware.name,
|
|
@@ -207,5 +302,5 @@ function checkMiddlewareCompatibility(middleware, runtimeFamilyId, runtimeTarget
|
|
|
207
302
|
}
|
|
208
303
|
|
|
209
304
|
//#endregion
|
|
210
|
-
export { AsyncIterableResult, RuntimeCore, checkMiddlewareCompatibility, isRuntimeError, runWithMiddleware, runtimeError };
|
|
305
|
+
export { AsyncIterableResult, RUNTIME_ABORTED, RuntimeCore, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runWithMiddleware, runtimeAborted, runtimeError };
|
|
211
306
|
//# sourceMappingURL=runtime.mjs.map
|
package/dist/runtime.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"runtime.mjs","names":["out: Row[]","latencyMs"],"sources":["../src/runtime-error.ts","../src/async-iterable-result.ts","../src/run-with-middleware.ts","../src/runtime-core.ts","../src/runtime-middleware.ts"],"sourcesContent":["export interface RuntimeErrorEnvelope extends Error {\n readonly code: string;\n readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';\n readonly severity: 'error';\n readonly details?: Record<string, unknown>;\n}\n\n/**\n * Type guard for the runtime-error envelope produced by `runtimeError`.\n *\n * Prefer this over duck-typing on `error.code` directly so consumers stay\n * insulated from the envelope's internal shape.\n */\nexport function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope {\n return (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as { code?: unknown }).code === 'string' &&\n 'category' in error &&\n 'severity' in error\n );\n}\n\nexport function runtimeError(\n code: string,\n message: string,\n details?: Record<string, unknown>,\n): RuntimeErrorEnvelope {\n const error = new Error(message) as RuntimeErrorEnvelope;\n Object.defineProperty(error, 'name', {\n value: 'RuntimeError',\n configurable: true,\n });\n\n return Object.assign(error, {\n code,\n category: resolveCategory(code),\n severity: 'error' as const,\n message,\n details,\n });\n}\n\nfunction resolveCategory(code: string): RuntimeErrorEnvelope['category'] {\n const prefix = code.split('.')[0] ?? 'RUNTIME';\n switch (prefix) {\n case 'PLAN':\n case 'CONTRACT':\n case 'LINT':\n case 'BUDGET':\n return prefix;\n default:\n return 'RUNTIME';\n }\n}\n","import { runtimeError } from './runtime-error';\n\nexport class AsyncIterableResult<Row> implements AsyncIterable<Row>, PromiseLike<Row[]> {\n private readonly generator: AsyncGenerator<Row, void, unknown>;\n private consumed = false;\n private consumedBy: 'bufferedArray' | 'iterator' | undefined;\n private bufferedArrayPromise: Promise<Row[]> | undefined;\n\n constructor(generator: AsyncGenerator<Row, void, unknown>) {\n this.generator = generator;\n }\n\n [Symbol.asyncIterator](): AsyncIterator<Row> {\n if (this.consumed) {\n throw runtimeError(\n 'RUNTIME.ITERATOR_CONSUMED',\n `AsyncIterableResult iterator has already been consumed via ${this.consumedBy === 'bufferedArray' ? 'toArray()/then()' : 'for-await loop'}. Each AsyncIterableResult can only be iterated once.`,\n {\n consumedBy: this.consumedBy,\n suggestion:\n this.consumedBy === 'bufferedArray'\n ? 'If you need to iterate multiple times, store the results from toArray() in a variable and reuse that.'\n : 'If you need to iterate multiple times, use toArray() to collect all results first.',\n },\n );\n }\n this.consumed = true;\n this.consumedBy = 'iterator';\n return this.generator;\n }\n\n toArray(): Promise<Row[]> {\n if (this.consumedBy === 'iterator') {\n return Promise.reject(\n runtimeError(\n 'RUNTIME.ITERATOR_CONSUMED',\n 'AsyncIterableResult iterator has already been consumed via for-await loop. Each AsyncIterableResult can only be iterated once.',\n {\n consumedBy: this.consumedBy,\n suggestion:\n 'The iterator was already consumed by a for-await loop. Use toArray() or await the result before iterating.',\n },\n ),\n );\n }\n\n if (this.bufferedArrayPromise) {\n return this.bufferedArrayPromise;\n }\n\n this.consumed = true;\n this.consumedBy = 'bufferedArray';\n this.bufferedArrayPromise = (async () => {\n const out: Row[] = [];\n for await (const item of this.generator) {\n out.push(item);\n }\n return out;\n })();\n return this.bufferedArrayPromise;\n }\n\n async first(): Promise<Row | null> {\n const rows = await this.toArray();\n return rows[0] ?? null;\n }\n\n async firstOrThrow(): Promise<Row> {\n const row = await this.first();\n if (row === null)\n throw runtimeError(\n 'RUNTIME.NO_ROWS',\n 'Expected at least one row, but none were returned',\n {},\n );\n return row;\n }\n\n // biome-ignore lint/suspicious/noThenProperty: PromiseLike implementation is intentional for await support.\n then<TResult1 = Row[], TResult2 = never>(\n onfulfilled?: ((value: Row[]) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): PromiseLike<TResult1 | TResult2> {\n return this.toArray().then(onfulfilled, onrejected);\n }\n}\n","import { AsyncIterableResult } from './async-iterable-result';\nimport type { ExecutionPlan } from './query-plan';\nimport type { RuntimeMiddleware, RuntimeMiddlewareContext } from './runtime-middleware';\n\n/**\n * Drives a single execution of `runDriver()` through the middleware lifecycle.\n *\n * Lifecycle, in order:\n * 1. For each middleware in registration order: `beforeExecute(exec, ctx)`.\n * 2. For each row yielded by `runDriver()`: for each middleware in registration\n * order: `onRow(row, exec, ctx)`; then yield the row to the consumer.\n * 3. On successful completion: for each middleware in registration order:\n * `afterExecute(exec, { rowCount, latencyMs, completed: true }, ctx)`.\n * 4. On any error thrown by the driver loop: for each middleware in\n * registration order: `afterExecute(exec, { rowCount, latencyMs,\n * completed: false }, ctx)`. Errors thrown by `afterExecute` during the\n * error path are swallowed so they do not mask the original driver error.\n * The original error is then rethrown.\n *\n * This helper is the single canonical implementation of the middleware\n * orchestration loop; family runtimes should not reimplement it.\n */\nexport function runWithMiddleware<TExec extends ExecutionPlan, Row>(\n exec: TExec,\n middleware: ReadonlyArray<RuntimeMiddleware<TExec>>,\n ctx: RuntimeMiddlewareContext,\n runDriver: () => AsyncIterable<Row>,\n): AsyncIterableResult<Row> {\n const iterator = async function* (): AsyncGenerator<Row, void, unknown> {\n const startedAt = Date.now();\n let rowCount = 0;\n let completed = false;\n\n try {\n for (const mw of middleware) {\n if (mw.beforeExecute) {\n await mw.beforeExecute(exec, ctx);\n }\n }\n\n for await (const row of runDriver()) {\n for (const mw of middleware) {\n if (mw.onRow) {\n await mw.onRow(row as Record<string, unknown>, exec, ctx);\n }\n }\n rowCount++;\n yield row;\n }\n\n completed = true;\n } catch (error) {\n const latencyMs = Date.now() - startedAt;\n for (const mw of middleware) {\n if (mw.afterExecute) {\n try {\n await mw.afterExecute(exec, { rowCount, latencyMs, completed }, ctx);\n } catch {\n // Swallow afterExecute errors during the error path so they do not\n // mask the original driver error.\n }\n }\n }\n\n throw error;\n }\n\n const latencyMs = Date.now() - startedAt;\n for (const mw of middleware) {\n if (mw.afterExecute) {\n await mw.afterExecute(exec, { rowCount, latencyMs, completed }, ctx);\n }\n }\n };\n\n return new AsyncIterableResult(iterator());\n}\n","import { AsyncIterableResult } from './async-iterable-result';\nimport type { ExecutionPlan, QueryPlan } from './query-plan';\nimport { runWithMiddleware } from './run-with-middleware';\nimport type {\n RuntimeExecutor,\n RuntimeMiddleware,\n RuntimeMiddlewareContext,\n} from './runtime-middleware';\n\n/**\n * Constructor options shared by every concrete `RuntimeCore` subclass.\n *\n * Family runtimes typically build the middleware list and the\n * `RuntimeMiddlewareContext` themselves (running compatibility checks,\n * narrowing the context's `contract` field, etc.) before calling `super`.\n */\nexport interface RuntimeCoreOptions<TMiddleware extends RuntimeMiddleware<ExecutionPlan>> {\n readonly middleware: ReadonlyArray<TMiddleware>;\n readonly ctx: RuntimeMiddlewareContext;\n}\n\n/**\n * Family-agnostic abstract runtime base.\n *\n * Defines the entire `execute(plan)` template in one place:\n *\n * 1. `runBeforeCompile(plan)` — concrete; defaults to identity. SQL overrides\n * this to run its `beforeCompile` middleware-hook chain.\n * 2. `lower(plan)` — abstract. Each family produces its `*ExecutionPlan`\n * (SQL via `lowerSqlPlan`, Mongo via `adapter.lower`).\n * 3. `runWithMiddleware(exec, this.middleware, this.ctx,\n * () => runDriver(exec))` — concrete; lifts the middleware lifecycle\n * out of the family runtimes into the canonical helper.\n *\n * Concrete subclasses must implement `lower`, `runDriver`, and `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 `runWithMiddleware` invokes the\n * `beforeExecute` / `onRow` / `afterExecute` hooks with the lowered\n * `TExec`. (The spec/plan wording \"RuntimeMiddleware<TPlan>\" is\n * tightened to `<TExec>` here so the helper call typechecks; the\n * intent is unchanged — middleware sees the post-lowering plan.)\n */\nexport abstract class RuntimeCore<\n TPlan extends QueryPlan,\n TExec extends ExecutionPlan,\n TMiddleware extends RuntimeMiddleware<TExec>,\n> implements RuntimeExecutor<TPlan>\n{\n protected readonly middleware: ReadonlyArray<TMiddleware>;\n protected readonly ctx: RuntimeMiddlewareContext;\n\n constructor(options: RuntimeCoreOptions<TMiddleware>) {\n this.middleware = options.middleware;\n this.ctx = options.ctx;\n }\n\n /**\n * Pre-lowering hook for plan rewriting. Defaults to identity. Subclasses\n * may override to run a `beforeCompile` middleware chain (SQL does this\n * to support typed AST rewrites — see `before-compile-chain.ts`).\n */\n protected runBeforeCompile(plan: TPlan): TPlan | Promise<TPlan> {\n return plan;\n }\n\n /**\n * Lower a pre-lowering `TPlan` into the family's executable `TExec`.\n * Family-specific: SQL produces `{ sql, params, ast?, ... }`; Mongo\n * produces `{ command, ... }`.\n */\n protected abstract lower(plan: TPlan): TExec | Promise<TExec>;\n\n /**\n * Drive the underlying transport for a lowered `TExec`. Yields raw rows\n * directly from the driver as `Record<string, unknown>`; codec decoding\n * (if any) is the subclass's responsibility, applied by wrapping\n * `execute()` rather than living inside this hook.\n *\n * The `Row` type parameter on `execute()` is satisfied by the caller via\n * the plan's phantom `_row`; the runtime treats rows as opaque records\n * here and trusts the caller's row typing.\n */\n protected abstract runDriver(exec: TExec): AsyncIterable<Record<string, unknown>>;\n\n abstract close(): Promise<void>;\n\n execute<Row>(plan: TPlan & { readonly _row?: Row }): AsyncIterableResult<Row> {\n const self = this;\n\n async function* generator(): AsyncGenerator<Row, void, unknown> {\n const compiled = await self.runBeforeCompile(plan);\n const exec = await self.lower(compiled);\n // The driver yields raw `Record<string, unknown>`; we cast to `Row` here.\n // The Row contract is enforced by the caller via `plan._row`.\n yield* runWithMiddleware<TExec, Row>(\n exec,\n self.middleware,\n self.ctx,\n () => self.runDriver(exec) as AsyncIterable<Row>,\n );\n }\n\n return new AsyncIterableResult(generator());\n }\n}\n","import type { AsyncIterableResult } from './async-iterable-result';\nimport type { QueryPlan } from './query-plan';\nimport { runtimeError } from './runtime-error';\n\nexport interface RuntimeLog {\n info(event: unknown): void;\n warn(event: unknown): void;\n error(event: unknown): void;\n debug?(event: unknown): void;\n}\n\nexport interface RuntimeMiddlewareContext {\n readonly contract: unknown;\n readonly mode: 'strict' | 'permissive';\n readonly now: () => number;\n readonly log: RuntimeLog;\n}\n\nexport interface AfterExecuteResult {\n readonly rowCount: number;\n readonly latencyMs: number;\n readonly completed: boolean;\n}\n\n/**\n * Family-agnostic middleware SPI parameterized over the plan marker.\n *\n * `TPlan` defaults to the framework `QueryPlan` marker so a generic\n * middleware (e.g. cross-family telemetry) can be authored without\n * naming a family. Family-specific middleware (`SqlMiddleware`,\n * `MongoMiddleware`) narrow `TPlan` to their concrete plan type.\n */\nexport interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan> {\n readonly name: string;\n readonly familyId?: string;\n readonly targetId?: string;\n beforeExecute?(plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;\n onRow?(row: Record<string, unknown>, plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;\n afterExecute?(\n plan: TPlan,\n result: AfterExecuteResult,\n ctx: RuntimeMiddlewareContext,\n ): Promise<void>;\n}\n\n/**\n * Cross-family SPI for any runtime that can execute plans and be shut down.\n * Each family runtime (SQL, Mongo) satisfies this interface — SQL nominally,\n * Mongo structurally (due to its phantom Row parameter using a unique symbol).\n *\n * The `_row` intersection on `execute` connects the `Row` type parameter to the\n * plan, mirroring how `QueryPlan<Row>` carries a phantom `_row?: Row`.\n */\nexport interface RuntimeExecutor<TPlan extends QueryPlan> {\n execute<Row>(plan: TPlan & { readonly _row?: Row }): AsyncIterableResult<Row>;\n close(): Promise<void>;\n}\n\nexport function checkMiddlewareCompatibility(\n middleware: RuntimeMiddleware,\n runtimeFamilyId: string,\n runtimeTargetId: string,\n): void {\n if (middleware.targetId !== undefined && middleware.familyId === undefined) {\n throw runtimeError(\n 'RUNTIME.MIDDLEWARE_INCOMPATIBLE',\n `Middleware '${middleware.name}' specifies targetId '${middleware.targetId}' without familyId`,\n { middleware: middleware.name, targetId: middleware.targetId },\n );\n }\n\n if (middleware.familyId !== undefined && middleware.familyId !== runtimeFamilyId) {\n throw runtimeError(\n 'RUNTIME.MIDDLEWARE_FAMILY_MISMATCH',\n `Middleware '${middleware.name}' requires family '${middleware.familyId}' but the runtime is configured for family '${runtimeFamilyId}'`,\n { middleware: middleware.name, middlewareFamilyId: middleware.familyId, runtimeFamilyId },\n );\n }\n\n if (middleware.targetId !== undefined && middleware.targetId !== runtimeTargetId) {\n throw runtimeError(\n 'RUNTIME.MIDDLEWARE_TARGET_MISMATCH',\n `Middleware '${middleware.name}' requires target '${middleware.targetId}' but the runtime is configured for target '${runtimeTargetId}'`,\n { middleware: middleware.name, middlewareTargetId: middleware.targetId, runtimeTargetId },\n );\n }\n}\n"],"mappings":";;;;;;;AAaA,SAAgB,eAAe,OAA+C;AAC5E,QACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAA6B,SAAS,YAC9C,cAAc,SACd,cAAc;;AAIlB,SAAgB,aACd,MACA,SACA,SACsB;CACtB,MAAM,QAAQ,IAAI,MAAM,QAAQ;AAChC,QAAO,eAAe,OAAO,QAAQ;EACnC,OAAO;EACP,cAAc;EACf,CAAC;AAEF,QAAO,OAAO,OAAO,OAAO;EAC1B;EACA,UAAU,gBAAgB,KAAK;EAC/B,UAAU;EACV;EACA;EACD,CAAC;;AAGJ,SAAS,gBAAgB,MAAgD;CACvE,MAAM,SAAS,KAAK,MAAM,IAAI,CAAC,MAAM;AACrC,SAAQ,QAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO;EACT,QACE,QAAO;;;;;;AClDb,IAAa,sBAAb,MAAwF;CACtF,AAAiB;CACjB,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CAER,YAAY,WAA+C;AACzD,OAAK,YAAY;;CAGnB,CAAC,OAAO,iBAAqC;AAC3C,MAAI,KAAK,SACP,OAAM,aACJ,6BACA,8DAA8D,KAAK,eAAe,kBAAkB,qBAAqB,iBAAi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WAAW,SAAS,8CAA8C,gBAAgB,IACtI;EAAE,YAAY,WAAW;EAAM,oBAAoB,WAAW;EAAU;EAAiB,CAC1F"}
|
|
1
|
+
{"version":3,"file":"runtime.mjs","names":["out: Row[]","sentinel: { reason: unknown }","onAbort: (() => void) | undefined","latencyMs","codecCtx: CodecCallContext"],"sources":["../src/execution/runtime-error.ts","../src/execution/async-iterable-result.ts","../src/execution/race-against-abort.ts","../src/execution/run-with-middleware.ts","../src/execution/runtime-core.ts","../src/execution/runtime-middleware.ts"],"sourcesContent":["export interface RuntimeErrorEnvelope extends Error {\n readonly code: string;\n readonly category: 'PLAN' | 'CONTRACT' | 'LINT' | 'BUDGET' | 'RUNTIME';\n readonly severity: 'error';\n readonly details?: Record<string, unknown>;\n}\n\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 */\nexport const RUNTIME_ABORTED = 'RUNTIME.ABORTED' as const;\n\n/** Discriminator placed in `details.phase` of a `RUNTIME.ABORTED` envelope. */\nexport type RuntimeAbortedPhase = 'encode' | 'decode' | 'stream';\n\n/**\n * Type guard for the runtime-error envelope produced by `runtimeError`.\n *\n * Prefer this over duck-typing on `error.code` directly so consumers stay\n * insulated from the envelope's internal shape.\n */\nexport function isRuntimeError(error: unknown): error is RuntimeErrorEnvelope {\n return (\n error instanceof Error &&\n 'code' in error &&\n typeof (error as { code?: unknown }).code === 'string' &&\n 'category' in error &&\n 'severity' in error\n );\n}\n\nexport function runtimeError(\n code: string,\n message: string,\n details?: Record<string, unknown>,\n): RuntimeErrorEnvelope {\n const error = new Error(message) as RuntimeErrorEnvelope;\n Object.defineProperty(error, 'name', {\n value: 'RuntimeError',\n configurable: true,\n });\n\n return Object.assign(error, {\n code,\n category: resolveCategory(code),\n severity: 'error' as const,\n message,\n details,\n });\n}\n\nfunction resolveCategory(code: string): RuntimeErrorEnvelope['category'] {\n const prefix = code.split('.')[0] ?? 'RUNTIME';\n switch (prefix) {\n case 'PLAN':\n case 'CONTRACT':\n case 'LINT':\n case 'BUDGET':\n return prefix;\n default:\n return 'RUNTIME';\n }\n}\n\n/**\n * Construct a `RUNTIME.ABORTED` envelope. Phase distinguishes where the\n * abort was observed (encode / decode / stream); cause carries `signal.reason`\n * verbatim from the platform — native abort produces a `DOMException`,\n * explicit `controller.abort(reason)` produces whatever the caller passed.\n * No synthesis happens here.\n */\nexport function runtimeAborted(phase: RuntimeAbortedPhase, cause?: unknown): RuntimeErrorEnvelope {\n const envelope = runtimeError(RUNTIME_ABORTED, `Operation aborted during ${phase}`, { phase });\n return Object.assign(envelope, { cause });\n}\n","import { runtimeError } from './runtime-error';\n\nexport class AsyncIterableResult<Row> implements AsyncIterable<Row>, PromiseLike<Row[]> {\n private readonly generator: AsyncGenerator<Row, void, unknown>;\n private consumed = false;\n private consumedBy: 'bufferedArray' | 'iterator' | undefined;\n private bufferedArrayPromise: Promise<Row[]> | undefined;\n\n constructor(generator: AsyncGenerator<Row, void, unknown>) {\n this.generator = generator;\n }\n\n [Symbol.asyncIterator](): AsyncIterator<Row> {\n if (this.consumed) {\n throw runtimeError(\n 'RUNTIME.ITERATOR_CONSUMED',\n `AsyncIterableResult iterator has already been consumed via ${this.consumedBy === 'bufferedArray' ? 'toArray()/then()' : 'for-await loop'}. Each AsyncIterableResult can only be iterated once.`,\n {\n consumedBy: this.consumedBy,\n suggestion:\n this.consumedBy === 'bufferedArray'\n ? 'If you need to iterate multiple times, store the results from toArray() in a variable and reuse that.'\n : 'If you need to iterate multiple times, use toArray() to collect all results first.',\n },\n );\n }\n this.consumed = true;\n this.consumedBy = 'iterator';\n return this.generator;\n }\n\n toArray(): Promise<Row[]> {\n if (this.consumedBy === 'iterator') {\n return Promise.reject(\n runtimeError(\n 'RUNTIME.ITERATOR_CONSUMED',\n 'AsyncIterableResult iterator has already been consumed via for-await loop. Each AsyncIterableResult can only be iterated once.',\n {\n consumedBy: this.consumedBy,\n suggestion:\n 'The iterator was already consumed by a for-await loop. Use toArray() or await the result before iterating.',\n },\n ),\n );\n }\n\n if (this.bufferedArrayPromise) {\n return this.bufferedArrayPromise;\n }\n\n this.consumed = true;\n this.consumedBy = 'bufferedArray';\n this.bufferedArrayPromise = (async () => {\n const out: Row[] = [];\n for await (const item of this.generator) {\n out.push(item);\n }\n return out;\n })();\n return this.bufferedArrayPromise;\n }\n\n async first(): Promise<Row | null> {\n const rows = await this.toArray();\n return rows[0] ?? null;\n }\n\n async firstOrThrow(): Promise<Row> {\n const row = await this.first();\n if (row === null)\n throw runtimeError(\n 'RUNTIME.NO_ROWS',\n 'Expected at least one row, but none were returned',\n {},\n );\n return row;\n }\n\n // biome-ignore lint/suspicious/noThenProperty: PromiseLike implementation is intentional for await support.\n then<TResult1 = Row[], TResult2 = never>(\n onfulfilled?: ((value: Row[]) => TResult1 | PromiseLike<TResult1>) | undefined | null,\n onrejected?: ((reason: unknown) => TResult2 | PromiseLike<TResult2>) | undefined | null,\n ): PromiseLike<TResult1 | TResult2> {\n return this.toArray().then(onfulfilled, onrejected);\n }\n}\n","import type { CodecCallContext } from '../shared/codec-types';\nimport type { RuntimeAbortedPhase } from './runtime-error';\nimport { runtimeAborted } from './runtime-error';\n\n/**\n * Throw a phase-tagged `RUNTIME.ABORTED` envelope if the supplied\n * codec-call context is already aborted at the precheck site. Centralises\n * the `if (ctx.signal?.aborted) throw runtimeAborted(...)` pattern that\n * every codec dispatch site repeats.\n */\nexport function checkAborted(ctx: CodecCallContext, phase: RuntimeAbortedPhase): void {\n if (ctx.signal?.aborted) {\n throw runtimeAborted(phase, ctx.signal.reason);\n }\n}\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 * `@prisma-next/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 */\nexport async function raceAgainstAbort<T>(\n work: Promise<T>,\n signal: AbortSignal | undefined,\n phase: RuntimeAbortedPhase,\n): Promise<T> {\n if (signal === undefined) {\n return await work;\n }\n const sentinel: { reason: unknown } = { reason: undefined };\n let onAbort: (() => void) | undefined;\n\n const abortPromise = new Promise<never>((_, reject) => {\n if (signal.aborted) {\n sentinel.reason = signal.reason;\n reject(sentinel);\n return;\n }\n onAbort = () => {\n sentinel.reason = signal.reason;\n reject(sentinel);\n };\n signal.addEventListener('abort', onAbort, { once: true });\n });\n\n try {\n return await Promise.race([work, abortPromise]);\n } catch (error) {\n if (error === sentinel) {\n throw runtimeAborted(phase, sentinel.reason);\n }\n throw error;\n } finally {\n if (onAbort) {\n signal.removeEventListener('abort', onAbort);\n }\n }\n}\n","import { AsyncIterableResult } from './async-iterable-result';\nimport type { ExecutionPlan } from './query-plan';\nimport type { RuntimeMiddleware, RuntimeMiddlewareContext } from './runtime-middleware';\n\n/**\n * Drives a single execution of `runDriver()` through the middleware lifecycle.\n *\n * Lifecycle, in order:\n * 1. For each middleware in registration order: `beforeExecute(exec, ctx)`.\n * 2. For each row yielded by `runDriver()`: for each middleware in registration\n * order: `onRow(row, exec, ctx)`; then yield the row to the consumer.\n * 3. On successful completion: for each middleware in registration order:\n * `afterExecute(exec, { rowCount, latencyMs, completed: true }, ctx)`.\n * 4. On any error thrown by the driver loop: for each middleware in\n * registration order: `afterExecute(exec, { rowCount, latencyMs,\n * completed: false }, ctx)`. Errors thrown by `afterExecute` during the\n * error path are swallowed so they do not mask the original driver error.\n * The original error is then rethrown.\n *\n * This helper is the single canonical implementation of the middleware\n * orchestration loop; family runtimes should not reimplement it.\n */\nexport function runWithMiddleware<TExec extends ExecutionPlan, Row>(\n exec: TExec,\n middleware: ReadonlyArray<RuntimeMiddleware<TExec>>,\n ctx: RuntimeMiddlewareContext,\n runDriver: () => AsyncIterable<Row>,\n): AsyncIterableResult<Row> {\n const iterator = async function* (): AsyncGenerator<Row, void, unknown> {\n const startedAt = Date.now();\n let rowCount = 0;\n let completed = false;\n\n try {\n for (const mw of middleware) {\n if (mw.beforeExecute) {\n await mw.beforeExecute(exec, ctx);\n }\n }\n\n for await (const row of runDriver()) {\n for (const mw of middleware) {\n if (mw.onRow) {\n await mw.onRow(row as Record<string, unknown>, exec, ctx);\n }\n }\n rowCount++;\n yield row;\n }\n\n completed = true;\n } catch (error) {\n const latencyMs = Date.now() - startedAt;\n for (const mw of middleware) {\n if (mw.afterExecute) {\n try {\n await mw.afterExecute(exec, { rowCount, latencyMs, completed }, ctx);\n } catch {\n // Swallow afterExecute errors during the error path so they do not\n // mask the original driver error.\n }\n }\n }\n\n throw error;\n }\n\n const latencyMs = Date.now() - startedAt;\n for (const mw of middleware) {\n if (mw.afterExecute) {\n await mw.afterExecute(exec, { rowCount, latencyMs, completed }, ctx);\n }\n }\n };\n\n return new AsyncIterableResult(iterator());\n}\n","import type { CodecCallContext } from '../shared/codec-types';\nimport { AsyncIterableResult } from './async-iterable-result';\nimport type { ExecutionPlan, QueryPlan } from './query-plan';\nimport { checkAborted } from './race-against-abort';\nimport { runWithMiddleware } from './run-with-middleware';\nimport type {\n RuntimeExecuteOptions,\n RuntimeExecutor,\n RuntimeMiddleware,\n RuntimeMiddlewareContext,\n} from './runtime-middleware';\n\n/**\n * Constructor options shared by every concrete `RuntimeCore` subclass.\n *\n * Family runtimes typically build the middleware list and the\n * `RuntimeMiddlewareContext` themselves (running compatibility checks,\n * narrowing the context's `contract` field, etc.) before calling `super`.\n */\nexport interface RuntimeCoreOptions<TMiddleware extends RuntimeMiddleware<ExecutionPlan>> {\n readonly middleware: ReadonlyArray<TMiddleware>;\n readonly ctx: RuntimeMiddlewareContext;\n}\n\n/**\n * Family-agnostic abstract runtime base.\n *\n * Defines the entire `execute(plan)` template in one place:\n *\n * 1. `runBeforeCompile(plan)` — concrete; defaults to identity. SQL overrides\n * this to run its `beforeCompile` middleware-hook chain.\n * 2. `lower(plan)` — abstract. Each family produces its `*ExecutionPlan`\n * (SQL via `lowerSqlPlan`, Mongo via `adapter.lower`).\n * 3. `runWithMiddleware(exec, this.middleware, this.ctx,\n * () => runDriver(exec))` — concrete; lifts the middleware lifecycle\n * out of the family runtimes into the canonical helper.\n *\n * Concrete subclasses must implement `lower`, `runDriver`, and `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 `runWithMiddleware` invokes the\n * `beforeExecute` / `onRow` / `afterExecute` hooks with the lowered\n * `TExec`. (The spec/plan wording \"RuntimeMiddleware<TPlan>\" is\n * tightened to `<TExec>` here so the helper call typechecks; the\n * intent is unchanged — middleware sees the post-lowering plan.)\n */\nexport abstract class RuntimeCore<\n TPlan extends QueryPlan,\n TExec extends ExecutionPlan,\n TMiddleware extends RuntimeMiddleware<TExec>,\n> implements RuntimeExecutor<TPlan>\n{\n protected readonly middleware: ReadonlyArray<TMiddleware>;\n protected readonly ctx: RuntimeMiddlewareContext;\n\n constructor(options: RuntimeCoreOptions<TMiddleware>) {\n this.middleware = options.middleware;\n this.ctx = options.ctx;\n }\n\n /**\n * Pre-lowering hook for plan rewriting. Defaults to identity. Subclasses\n * may override to run a `beforeCompile` middleware chain (SQL does this\n * to support typed AST rewrites — see `before-compile-chain.ts`).\n */\n protected runBeforeCompile(plan: TPlan): TPlan | Promise<TPlan> {\n return plan;\n }\n\n /**\n * Lower a pre-lowering `TPlan` into the family's executable `TExec`.\n * Family-specific: SQL produces `{ sql, params, ast?, ... }`; Mongo\n * produces `{ command, ... }`.\n *\n * `ctx` carries per-query cancellation (and any future fields on\n * `CodecCallContext`); concrete subclasses forward it to the\n * encode-side codec dispatch site (e.g. SQL's `encodeParams` in m2,\n * Mongo's `resolveValue` in m3). The runtime allocates one ctx per\n * `execute()` call and threads the same reference everywhere; the\n * `signal` field inside may be `undefined`, but the ctx object itself\n * is always present.\n */\n protected abstract lower(plan: TPlan, ctx: CodecCallContext): TExec | Promise<TExec>;\n\n /**\n * Drive the underlying transport for a lowered `TExec`. Yields raw rows\n * directly from the driver as `Record<string, unknown>`; codec decoding\n * (if any) is the subclass's responsibility, applied by wrapping\n * `execute()` rather than living inside this hook.\n *\n * The `Row` type parameter on `execute()` is satisfied by the caller via\n * the plan's phantom `_row`; the runtime treats rows as opaque records\n * here and trusts the caller's row typing.\n */\n protected abstract runDriver(exec: TExec): AsyncIterable<Record<string, unknown>>;\n\n abstract close(): Promise<void>;\n\n execute<Row>(\n plan: TPlan & { readonly _row?: Row },\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row> {\n const self = this;\n const signal = options?.signal;\n // One ctx per execute() call. The ctx object is always allocated; the\n // `signal` field is only included when a signal was supplied (required\n // under exactOptionalPropertyTypes — `{ signal: undefined }` would not\n // satisfy `signal?: AbortSignal`).\n const codecCtx: CodecCallContext = signal === undefined ? {} : { signal };\n\n async function* generator(): AsyncGenerator<Row, void, unknown> {\n // Pre-check the signal at entry so an already-aborted caller observes\n // RUNTIME.ABORTED on the first `next()` without any work being done.\n checkAborted(codecCtx, 'stream');\n\n const compiled = await self.runBeforeCompile(plan);\n const exec = await self.lower(compiled, codecCtx);\n // The driver yields raw `Record<string, unknown>`; we cast to `Row` here.\n // The Row contract is enforced by the caller via `plan._row`.\n yield* runWithMiddleware<TExec, Row>(\n exec,\n self.middleware,\n self.ctx,\n () => self.runDriver(exec) as AsyncIterable<Row>,\n );\n }\n\n return new AsyncIterableResult(generator());\n }\n}\n","import type { AsyncIterableResult } from './async-iterable-result';\nimport type { QueryPlan } from './query-plan';\nimport { runtimeError } from './runtime-error';\n\nexport interface RuntimeLog {\n info(event: unknown): void;\n warn(event: unknown): void;\n error(event: unknown): void;\n debug?(event: unknown): void;\n}\n\nexport interface RuntimeMiddlewareContext {\n readonly contract: unknown;\n readonly mode: 'strict' | 'permissive';\n readonly now: () => number;\n readonly log: RuntimeLog;\n}\n\nexport interface AfterExecuteResult {\n readonly rowCount: number;\n readonly latencyMs: number;\n readonly completed: boolean;\n}\n\n/**\n * Family-agnostic middleware SPI parameterized over the plan marker.\n *\n * `TPlan` defaults to the framework `QueryPlan` marker so a generic\n * middleware (e.g. cross-family telemetry) can be authored without\n * naming a family. Family-specific middleware (`SqlMiddleware`,\n * `MongoMiddleware`) narrow `TPlan` to their concrete plan type.\n */\nexport interface RuntimeMiddleware<TPlan extends QueryPlan = QueryPlan> {\n readonly name: string;\n readonly familyId?: string;\n readonly targetId?: string;\n beforeExecute?(plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;\n onRow?(row: Record<string, unknown>, plan: TPlan, ctx: RuntimeMiddlewareContext): Promise<void>;\n afterExecute?(\n plan: TPlan,\n result: AfterExecuteResult,\n ctx: RuntimeMiddlewareContext,\n ): Promise<void>;\n}\n\n/**\n * Optional per-`execute` options accepted by every family runtime.\n *\n * `signal` is the per-query cancellation signal. The runtime threads the\n * signal through to every codec call for the query and uses it to short-\n * circuit the row stream with `RUNTIME.ABORTED` when the caller aborts.\n * Omitting the option (or passing `undefined`) preserves today's behavior\n * bit-for-bit.\n */\nexport interface RuntimeExecuteOptions {\n readonly signal?: AbortSignal;\n}\n\n/**\n * Cross-family SPI for any runtime that can execute plans and be shut down.\n * Each family runtime (SQL, Mongo) satisfies this interface — SQL nominally,\n * Mongo structurally (due to its phantom Row parameter using a unique symbol).\n *\n * The `_row` intersection on `execute` connects the `Row` type parameter to the\n * plan, mirroring how `QueryPlan<Row>` carries a phantom `_row?: Row`.\n */\nexport interface RuntimeExecutor<TPlan extends QueryPlan> {\n execute<Row>(\n plan: TPlan & { readonly _row?: Row },\n options?: RuntimeExecuteOptions,\n ): AsyncIterableResult<Row>;\n close(): Promise<void>;\n}\n\nexport function checkMiddlewareCompatibility(\n middleware: RuntimeMiddleware,\n runtimeFamilyId: string,\n runtimeTargetId: string,\n): void {\n if (middleware.targetId !== undefined && middleware.familyId === undefined) {\n throw runtimeError(\n 'RUNTIME.MIDDLEWARE_INCOMPATIBLE',\n `Middleware '${middleware.name}' specifies targetId '${middleware.targetId}' without familyId`,\n { middleware: middleware.name, targetId: middleware.targetId },\n );\n }\n\n if (middleware.familyId !== undefined && middleware.familyId !== runtimeFamilyId) {\n throw runtimeError(\n 'RUNTIME.MIDDLEWARE_FAMILY_MISMATCH',\n `Middleware '${middleware.name}' requires family '${middleware.familyId}' but the runtime is configured for family '${runtimeFamilyId}'`,\n { middleware: middleware.name, middlewareFamilyId: middleware.familyId, runtimeFamilyId },\n );\n }\n\n if (middleware.targetId !== undefined && middleware.targetId !== runtimeTargetId) {\n throw runtimeError(\n 'RUNTIME.MIDDLEWARE_TARGET_MISMATCH',\n `Middleware '${middleware.name}' requires target '${middleware.targetId}' but the runtime is configured for target '${runtimeTargetId}'`,\n { middleware: middleware.name, middlewareTargetId: middleware.targetId, runtimeTargetId },\n );\n }\n}\n"],"mappings":";;;;;;;;;;;;AAkBA,MAAa,kBAAkB;;;;;;;AAW/B,SAAgB,eAAe,OAA+C;AAC5E,QACE,iBAAiB,SACjB,UAAU,SACV,OAAQ,MAA6B,SAAS,YAC9C,cAAc,SACd,cAAc;;AAIlB,SAAgB,aACd,MACA,SACA,SACsB;CACtB,MAAM,QAAQ,IAAI,MAAM,QAAQ;AAChC,QAAO,eAAe,OAAO,QAAQ;EACnC,OAAO;EACP,cAAc;EACf,CAAC;AAEF,QAAO,OAAO,OAAO,OAAO;EAC1B;EACA,UAAU,gBAAgB,KAAK;EAC/B,UAAU;EACV;EACA;EACD,CAAC;;AAGJ,SAAS,gBAAgB,MAAgD;CACvE,MAAM,SAAS,KAAK,MAAM,IAAI,CAAC,MAAM;AACrC,SAAQ,QAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,QAAO;EACT,QACE,QAAO;;;;;;;;;;AAWb,SAAgB,eAAe,OAA4B,OAAuC;CAChG,MAAM,WAAW,aAAa,iBAAiB,4BAA4B,SAAS,EAAE,OAAO,CAAC;AAC9F,QAAO,OAAO,OAAO,UAAU,EAAE,OAAO,CAAC;;;;;AC/E3C,IAAa,sBAAb,MAAwF;CACtF,AAAiB;CACjB,AAAQ,WAAW;CACnB,AAAQ;CACR,AAAQ;CAER,YAAY,WAA+C;AACzD,OAAK,YAAY;;CAGnB,CAAC,OAAO,iBAAqC;AAC3C,MAAI,KAAK,SACP,OAAM,aACJ,6BACA,8DAA8D,KAAK,eAAe,kBAAkB,qBAAqB,iBAAiB,wDAC1I;GACE,YAAY,KAAK;GACjB,YACE,KAAK,eAAe,kBAChB,0GACA;GACP,CACF;AAEH,OAAK,WAAW;AAChB,OAAK,aAAa;AA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9D,gBAAa,UAAU,SAAS;GAEhC,MAAM,WAAW,MAAM,KAAK,iBAAiB,KAAK;GAClD,MAAM,OAAO,MAAM,KAAK,MAAM,UAAU,SAAS;AAGjD,UAAO,kBACL,MACA,KAAK,YACL,KAAK,WACC,KAAK,UAAU,KAAK,CAC3B;;AAGH,SAAO,IAAI,oBAAoB,WAAW,CAAC;;;;;;ACxD/C,SAAgB,6BACd,YACA,iBACA,iBACM;AACN,KAAI,WAAW,aAAa,UAAa,WAAW,aAAa,OAC/D,OAAM,aACJ,mCACA,eAAe,WAAW,KAAK,wBAAwB,WAAW,SAAS,qBAC3E;EAAE,YAAY,WAAW;EAAM,UAAU,WAAW;EAAU,CAC/D;AAGH,KAAI,WAAW,aAAa,UAAa,WAAW,aAAa,gBAC/D,OAAM,aACJ,sCACA,eAAe,WAAW,KAAK,qBAAqB,WAAW,SAAS,8CAA8C,gBAAgB,IACtI;EAAE,YAAY,WAAW;EAAM,oBAAoB,WAAW;EAAU;EAAiB,CAC1F;AAGH,KAAI,WAAW,aAAa,UAAa,WAAW,aAAa,gBAC/D,OAAM,aACJ,sCACA,eAAe,WAAW,KAAK,qBAAqB,WAAW,SAAS,8CAA8C,gBAAgB,IACtI;EAAE,YAAY,WAAW;EAAM,oBAAoB,WAAW;EAAU;EAAiB,CAC1F"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
//#region src/types-import-spec.d.ts
|
|
1
|
+
//#region src/shared/types-import-spec.d.ts
|
|
2
2
|
/**
|
|
3
3
|
* Specifies how to import TypeScript types from a package.
|
|
4
4
|
* Used in extension pack manifests to declare codec and operation type imports.
|
|
@@ -10,4 +10,4 @@ interface TypesImportSpec {
|
|
|
10
10
|
}
|
|
11
11
|
//#endregion
|
|
12
12
|
export { TypesImportSpec as t };
|
|
13
|
-
//# sourceMappingURL=types-import-spec-
|
|
13
|
+
//# sourceMappingURL=types-import-spec-D-O6GotH.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-import-spec-D-O6GotH.d.mts","names":[],"sources":["../src/shared/types-import-spec.ts"],"sourcesContent":[],"mappings":";;AAIA;;;UAAiB,eAAA"}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/framework-components",
|
|
3
|
-
"version": "0.5.0-dev.
|
|
3
|
+
"version": "0.5.0-dev.29",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "Framework component types, assembly logic, and stack creation for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@prisma-next/contract": "0.5.0-dev.
|
|
9
|
-
"@prisma-next/operations": "0.5.0-dev.
|
|
10
|
-
"@prisma-next/utils": "0.5.0-dev.
|
|
8
|
+
"@prisma-next/contract": "0.5.0-dev.29",
|
|
9
|
+
"@prisma-next/operations": "0.5.0-dev.29",
|
|
10
|
+
"@prisma-next/utils": "0.5.0-dev.29"
|
|
11
11
|
},
|
|
12
12
|
"devDependencies": {
|
|
13
13
|
"tsdown": "0.18.4",
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"./control": "./dist/control.mjs",
|
|
28
28
|
"./emission": "./dist/emission.mjs",
|
|
29
29
|
"./execution": "./dist/execution.mjs",
|
|
30
|
+
"./psl-ast": "./dist/psl-ast.mjs",
|
|
30
31
|
"./runtime": "./dist/runtime.mjs",
|
|
31
32
|
"./package.json": "./package.json"
|
|
32
33
|
},
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import type { ControlTargetDescriptor } from './control-descriptors';
|
|
2
|
+
import type { ControlFamilyInstance } from './control-instances';
|
|
3
|
+
import type { MigrationPlanOperation, TargetMigrationsCapability } from './control-migration-types';
|
|
4
|
+
import type { OperationPreview } from './control-operation-preview';
|
|
5
|
+
import type { CoreSchemaView } from './control-schema-view';
|
|
6
|
+
import type { PslDocumentAst } from './psl-ast';
|
|
7
|
+
|
|
8
|
+
export interface MigratableTargetDescriptor<
|
|
9
|
+
TFamilyId extends string,
|
|
10
|
+
TTargetId extends string,
|
|
11
|
+
TFamilyInstance extends ControlFamilyInstance<TFamilyId, unknown> = ControlFamilyInstance<
|
|
12
|
+
TFamilyId,
|
|
13
|
+
unknown
|
|
14
|
+
>,
|
|
15
|
+
> extends ControlTargetDescriptor<TFamilyId, TTargetId> {
|
|
16
|
+
readonly migrations: TargetMigrationsCapability<TFamilyId, TTargetId, TFamilyInstance>;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function hasMigrations<TFamilyId extends string, TTargetId extends string>(
|
|
20
|
+
target: ControlTargetDescriptor<TFamilyId, TTargetId>,
|
|
21
|
+
): target is MigratableTargetDescriptor<TFamilyId, TTargetId> {
|
|
22
|
+
return 'migrations' in target && !!(target as Record<string, unknown>)['migrations'];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface SchemaViewCapable<TSchemaIR = unknown> {
|
|
26
|
+
toSchemaView(schema: TSchemaIR): CoreSchemaView;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function hasSchemaView<TFamilyId extends string, TSchemaIR>(
|
|
30
|
+
instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,
|
|
31
|
+
): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & SchemaViewCapable<TSchemaIR> {
|
|
32
|
+
return (
|
|
33
|
+
'toSchemaView' in instance &&
|
|
34
|
+
typeof (instance as Record<string, unknown>)['toSchemaView'] === 'function'
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Capability declaring that a family can infer a PSL contract AST from its
|
|
40
|
+
* opaque introspected schema IR. Consumed by `prisma-next contract infer`.
|
|
41
|
+
*/
|
|
42
|
+
export interface PslContractInferCapable<TSchemaIR = unknown> {
|
|
43
|
+
inferPslContract(schemaIR: TSchemaIR): PslDocumentAst;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function hasPslContractInfer<TFamilyId extends string, TSchemaIR>(
|
|
47
|
+
instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,
|
|
48
|
+
): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & PslContractInferCapable<TSchemaIR> {
|
|
49
|
+
return (
|
|
50
|
+
'inferPslContract' in instance &&
|
|
51
|
+
typeof (instance as Record<string, unknown>)['inferPslContract'] === 'function'
|
|
52
|
+
);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Capability declaring that a family can render a textual preview of migration
|
|
57
|
+
* operations for the CLI's "DDL preview" output. SQL families emit
|
|
58
|
+
* `language: 'sql'` statements; Mongo families emit `language: 'mongodb-shell'`.
|
|
59
|
+
*/
|
|
60
|
+
export interface OperationPreviewCapable {
|
|
61
|
+
toOperationPreview(operations: readonly MigrationPlanOperation[]): OperationPreview;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export function hasOperationPreview<TFamilyId extends string, TSchemaIR>(
|
|
65
|
+
instance: ControlFamilyInstance<TFamilyId, TSchemaIR>,
|
|
66
|
+
): instance is ControlFamilyInstance<TFamilyId, TSchemaIR> & OperationPreviewCapable {
|
|
67
|
+
return (
|
|
68
|
+
'toOperationPreview' in instance &&
|
|
69
|
+
typeof (instance as Record<string, unknown>)['toOperationPreview'] === 'function'
|
|
70
|
+
);
|
|
71
|
+
}
|
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
AdapterDescriptor,
|
|
3
|
+
DriverDescriptor,
|
|
4
|
+
ExtensionDescriptor,
|
|
5
|
+
FamilyDescriptor,
|
|
6
|
+
TargetDescriptor,
|
|
7
|
+
} from '../shared/framework-components';
|
|
1
8
|
import type {
|
|
2
9
|
ControlAdapterInstance,
|
|
3
10
|
ControlDriverInstance,
|
|
@@ -7,13 +14,6 @@ import type {
|
|
|
7
14
|
} from './control-instances';
|
|
8
15
|
import type { ControlStack } from './control-stack';
|
|
9
16
|
import type { EmissionSpi } from './emission-types';
|
|
10
|
-
import type {
|
|
11
|
-
AdapterDescriptor,
|
|
12
|
-
DriverDescriptor,
|
|
13
|
-
ExtensionDescriptor,
|
|
14
|
-
FamilyDescriptor,
|
|
15
|
-
TargetDescriptor,
|
|
16
|
-
} from './framework-components';
|
|
17
17
|
|
|
18
18
|
export interface ControlFamilyDescriptor<
|
|
19
19
|
TFamilyId extends string,
|