@prisma/orm-family-sql 8.0.0-rc.1-dev.41 → 8.0.0-rc.1-dev.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{aggregate-descriptor-registry-DSap8YyW.mjs → aggregate-descriptor-registry-CTo0ry7h.mjs} +2 -2
- package/dist/{aggregate-descriptor-registry-DSap8YyW.mjs.map → aggregate-descriptor-registry-CTo0ry7h.mjs.map} +1 -1
- package/dist/{ast-B-eeN74F.mjs → ast-BJdOHZrL.mjs} +2 -2
- package/dist/{ast-B-eeN74F.mjs.map → ast-BJdOHZrL.mjs.map} +1 -1
- package/dist/{ast-DRbUiQ-9.d.mts → ast-D8qqdDX_.d.mts} +5 -82
- package/dist/ast-D8qqdDX_.d.mts.map +1 -0
- package/dist/builder.d.mts +2 -2
- package/dist/builder__runtime.d.mts +6 -6
- package/dist/builder__runtime.mjs +2 -2
- package/dist/builder__types.d.mts +2 -2
- package/dist/{control-DI9DC2AS.d.mts → control-DssujEJW.d.mts} +7 -6
- package/dist/control-DssujEJW.d.mts.map +1 -0
- package/dist/{control-adapter-C99J7aEF-DsxImHyk.d.mts → control-adapter-C99J7aEF-Vx9xXYOy.d.mts} +5 -4
- package/dist/control-adapter-C99J7aEF-Vx9xXYOy.d.mts.map +1 -0
- package/dist/control-adapter-CLID4Q6Z.d.mts +1 -0
- package/dist/{db-C5jmOFPM-BGm-QfKd.d.mts → db-C5jmOFPM-Cd-fni61.d.mts} +6 -6
- package/dist/{db-C5jmOFPM-BGm-QfKd.d.mts.map → db-C5jmOFPM-Cd-fni61.d.mts.map} +1 -1
- package/dist/{ddl-types-CnLSuwXa-Bv46yIe9.d.mts → ddl-types-BtT82FGO-Du_-9SlZ.d.mts} +3 -3
- package/dist/{ddl-types-CnLSuwXa-Bv46yIe9.d.mts.map → ddl-types-BtT82FGO-Du_-9SlZ.d.mts.map} +1 -1
- package/dist/{diff-DVvZXmFv.d.mts → diff-pl1Xal4J.d.mts} +3 -3
- package/dist/{diff-DVvZXmFv.d.mts.map → diff-pl1Xal4J.d.mts.map} +1 -1
- package/dist/driver-types-BQtRkOJ0-Bv2RPSfr.d.mts +81 -0
- package/dist/driver-types-BQtRkOJ0-Bv2RPSfr.d.mts.map +1 -0
- package/dist/{expression-CYVKobXp.mjs → expression-D30W-gkF.mjs} +2 -2
- package/dist/{expression-CYVKobXp.mjs.map → expression-D30W-gkF.mjs.map} +1 -1
- package/dist/{expression-D7H1kyVG.d.mts → expression-Q_yaDQPb.d.mts} +2 -2
- package/dist/{expression-D7H1kyVG.d.mts.map → expression-Q_yaDQPb.d.mts.map} +1 -1
- package/dist/family.d.mts +7 -7
- package/dist/family__control-adapter.d.mts +2 -2
- package/dist/family__control.d.mts +2 -2
- package/dist/family__diff.d.mts +2 -2
- package/dist/family__migration.d.mts +1 -1
- package/dist/family__runtime.d.mts +1 -1
- package/dist/index-DIHXLCbY.d.mts +84 -0
- package/dist/index-DIHXLCbY.d.mts.map +1 -0
- package/dist/{middleware-Bp5oIYM0-Ek8bISDH.d.mts → middleware-BS7u8VFR-DyUcAFid.d.mts} +3 -3
- package/dist/{middleware-Bp5oIYM0-Ek8bISDH.d.mts.map → middleware-BS7u8VFR-DyUcAFid.d.mts.map} +1 -1
- package/dist/middleware-Cy_OqpBi.d.mts +1 -0
- package/dist/{migration-Dtymew3g.d.mts → migration-CGlaINey.d.mts} +2 -2
- package/dist/{migration-Dtymew3g.d.mts.map → migration-CGlaINey.d.mts.map} +1 -1
- package/dist/orm-client.d.mts +7 -7
- package/dist/orm-client.mjs +32 -49
- package/dist/orm-client.mjs.map +1 -1
- package/dist/{plan-DfLDIdep-6R1mLkcW.d.mts → plan-BC_trt1i-In5gOKCT.d.mts} +3 -3
- package/dist/plan-BC_trt1i-In5gOKCT.d.mts.map +1 -0
- package/dist/plan-DrOMooQt.d.mts +2 -0
- package/dist/prepared-query-BDLztUzY-CaDR0Rqc.mjs +14 -0
- package/dist/prepared-query-BDLztUzY-CaDR0Rqc.mjs.map +1 -0
- package/dist/{index-Ddquditw.d.mts → prepared-statement-z9bBbTph-BlzhaRTY.d.mts} +96 -142
- package/dist/prepared-statement-z9bBbTph-BlzhaRTY.d.mts.map +1 -0
- package/dist/query-lane-context-D62vkQhf.d.mts +1 -0
- package/dist/{query-lane-context-DyDSQVS--CyCznt67.d.mts → query-lane-context-gwWUcacE-DdWNrc8q.d.mts} +3 -3
- package/dist/{query-lane-context-DyDSQVS--CyCznt67.d.mts.map → query-lane-context-gwWUcacE-DdWNrc8q.d.mts.map} +1 -1
- package/dist/relational-core.d.mts +12 -11
- package/dist/relational-core.mjs +3 -3
- package/dist/relational-core__aggregate-descriptor-registry.d.mts +1 -1
- package/dist/relational-core__aggregate-descriptor-registry.mjs +1 -1
- package/dist/relational-core__ast.d.mts +4 -3
- package/dist/relational-core__ast.mjs +2 -2
- package/dist/relational-core__codec-descriptor-registry.d.mts +2 -2
- package/dist/relational-core__contract-free.d.mts +2 -2
- package/dist/relational-core__contract-free.mjs +1 -1
- package/dist/relational-core__contract-free.mjs.map +1 -1
- package/dist/relational-core__expression.d.mts +1 -1
- package/dist/relational-core__expression.mjs +1 -1
- package/dist/relational-core__middleware.d.mts +2 -2
- package/dist/relational-core__plan.d.mts +3 -3
- package/dist/relational-core__query-lane-context.d.mts +2 -2
- package/dist/relational-core__types.d.mts +2 -2
- package/dist/{runtime-CjXCGPS4.d.mts → runtime-cPrAp99G.d.mts} +3 -2
- package/dist/runtime-cPrAp99G.d.mts.map +1 -0
- package/dist/runtime.d.mts +5 -4
- package/dist/runtime.mjs +187 -130
- package/dist/runtime.mjs.map +1 -1
- package/dist/runtime__internal__prepared-query.d.mts +2 -0
- package/dist/runtime__internal__prepared-query.mjs +2 -0
- package/dist/{sql-execution-plan-qxvHnFcA-HjRSS3l9.d.mts → sql-execution-plan-D0ZTnszb-DnCRtfQO.d.mts} +3 -3
- package/dist/sql-execution-plan-D0ZTnszb-DnCRtfQO.d.mts.map +1 -0
- package/dist/types-0c4HyrXd.d.mts +1 -0
- package/dist/{types-CSP6WmWn-DVuxsZJW.mjs → types-B7_v-z12-De5tf8LE.mjs} +3 -3
- package/dist/types-B7_v-z12-De5tf8LE.mjs.map +1 -0
- package/dist/{types-CLN9Y3BH-BHUrV7MD.d.mts → types-C9FZXc9Q-C6LM1k-O.d.mts} +14 -11
- package/dist/types-C9FZXc9Q-C6LM1k-O.d.mts.map +1 -0
- package/dist/{types-ZzeQKmYD-kI_QWHEx.d.mts → types-DH6Sqzxu-DfzaLX0o.d.mts} +3 -3
- package/dist/{types-ZzeQKmYD-kI_QWHEx.d.mts.map → types-DH6Sqzxu-DfzaLX0o.d.mts.map} +1 -1
- package/dist/{types-IqZMLrFC-Dk3bHKmk.d.mts → types-IqZMLrFC-B0YziCVx.d.mts} +2 -2
- package/dist/{types-IqZMLrFC-Dk3bHKmk.d.mts.map → types-IqZMLrFC-B0YziCVx.d.mts.map} +1 -1
- package/package.json +19 -18
- package/dist/ast-DRbUiQ-9.d.mts.map +0 -1
- package/dist/control-DI9DC2AS.d.mts.map +0 -1
- package/dist/control-adapter-BdOcXTOm.d.mts +0 -1
- package/dist/control-adapter-C99J7aEF-DsxImHyk.d.mts.map +0 -1
- package/dist/index-Ddquditw.d.mts.map +0 -1
- package/dist/middleware-aFpB1ZhU.d.mts +0 -1
- package/dist/plan-DfLDIdep-6R1mLkcW.d.mts.map +0 -1
- package/dist/plan-HWPzzUxh.d.mts +0 -2
- package/dist/query-lane-context-qfJzguc9.d.mts +0 -1
- package/dist/runtime-CjXCGPS4.d.mts.map +0 -1
- package/dist/sql-execution-plan-qxvHnFcA-HjRSS3l9.d.mts.map +0 -1
- package/dist/types-4u1EPYY6.d.mts +0 -1
- package/dist/types-CLN9Y3BH-BHUrV7MD.d.mts.map +0 -1
- package/dist/types-CSP6WmWn-DVuxsZJW.mjs.map +0 -1
package/dist/runtime.mjs
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { t as createSqlOperationRegistry } from "./dist-C_q1_QR9.mjs";
|
|
2
|
-
import { A as PreparedParamRef, H as isQueryAst } from "./types-
|
|
2
|
+
import { A as PreparedParamRef, H as isQueryAst } from "./types-B7_v-z12-De5tf8LE.mjs";
|
|
3
3
|
import { t as collectOrderedParamRefs } from "./util-DQQgv2j1-D6INZaRG.mjs";
|
|
4
4
|
import { t as createSqlParamRefMutator } from "./middleware-CMr4CHNz-DHIUdxlm.mjs";
|
|
5
|
-
import { t as buildSqlAggregateDescriptorRegistry } from "./aggregate-descriptor-registry-
|
|
5
|
+
import { t as buildSqlAggregateDescriptorRegistry } from "./aggregate-descriptor-registry-CTo0ry7h.mjs";
|
|
6
6
|
import { t as buildCodecDescriptorRegistry } from "./codec-descriptor-registry-N0dhtKaH.mjs";
|
|
7
|
+
import { n as runPreparedQuery, t as preparedStatementQuery } from "./prepared-query-BDLztUzY-CaDR0Rqc.mjs";
|
|
7
8
|
import { isStructuredError } from "@prisma/orm-framework/utils/structured-error";
|
|
8
9
|
import { createHash } from "node:crypto";
|
|
9
10
|
import { assertNever } from "@prisma/orm-framework/utils/internal-error";
|
|
@@ -12,11 +13,11 @@ import { blindCast } from "@prisma/orm-framework/utils/casts";
|
|
|
12
13
|
import { canonicalStringify } from "@prisma/orm-framework/utils/canonical-stringify";
|
|
13
14
|
import { checkContractComponentRequirements, mergeCapabilityMatrices } from "@prisma/orm-framework/components/components";
|
|
14
15
|
import { materializeCodec, resolveCodecDescriptorOrThrow } from "@prisma/orm-framework/components/codec";
|
|
15
|
-
import { AsyncIterableResult, RuntimeCore, checkAborted, checkMiddlewareCompatibility, raceAgainstAbort, runBeforeExecuteChain,
|
|
16
|
+
import { AsyncIterableResult, RuntimeCore, checkAborted, checkMiddlewareCompatibility, raceAgainstAbort, runBeforeExecuteChain, runBeforeQueryChain, runExecuteWithMiddleware, runQueryWithMiddleware, runtimeError } from "@prisma/orm-framework/components/runtime";
|
|
16
17
|
import { canonicalizeJson } from "@prisma/orm-framework/components/utils";
|
|
17
18
|
import { createExecutionStack } from "@prisma/orm-framework/components/execution";
|
|
18
19
|
import { hashContent } from "@prisma/orm-framework/utils/hash-content";
|
|
19
|
-
//#region ../../../2-sql/5-runtime/dist/exports-
|
|
20
|
+
//#region ../../../2-sql/5-runtime/dist/exports-CNtR1FrC.mjs
|
|
20
21
|
/**
|
|
21
22
|
* Build an {@link AstCodecResolver} bound to a descriptor registry and a per-call instance-context factory.
|
|
22
23
|
*
|
|
@@ -222,13 +223,25 @@ function budgets(options) {
|
|
|
222
223
|
const rowSeverity = options?.severities?.rowCount ?? "error";
|
|
223
224
|
const latencySeverity = options?.severities?.latency ?? "warn";
|
|
224
225
|
const observedRowsByPlan = /* @__PURE__ */ new WeakMap();
|
|
226
|
+
const beforeOperation = async (plan, ctx) => {
|
|
227
|
+
observedRowsByPlan.set(plan, { count: 0 });
|
|
228
|
+
if (isQueryAst(plan.ast) && plan.ast.kind === "select") evaluateSelectAst(plan.ast, ctx);
|
|
229
|
+
};
|
|
230
|
+
const afterOperation = async (_plan, result, ctx) => {
|
|
231
|
+
const latencyMs = result.latencyMs;
|
|
232
|
+
if (latencyMs > maxLatencyMs) {
|
|
233
|
+
const shouldBlock = latencySeverity === "error" || ctx.mode === "strict";
|
|
234
|
+
emitBudgetViolation(runtimeError("BUDGET.TIME_EXCEEDED", "Query latency exceeds budget", {
|
|
235
|
+
latencyMs,
|
|
236
|
+
maxLatencyMs
|
|
237
|
+
}), shouldBlock, ctx);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
225
240
|
return Object.freeze({
|
|
226
241
|
name: "budgets",
|
|
227
242
|
familyId: "sql",
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
if (isQueryAst(plan.ast) && plan.ast.kind === "select") return evaluateSelectAst(plan.ast, ctx);
|
|
231
|
-
},
|
|
243
|
+
beforeQuery: beforeOperation,
|
|
244
|
+
beforeExecute: beforeOperation,
|
|
232
245
|
async onRow(_row, plan, _ctx) {
|
|
233
246
|
const state = observedRowsByPlan.get(plan);
|
|
234
247
|
if (!state) return;
|
|
@@ -239,16 +252,8 @@ function budgets(options) {
|
|
|
239
252
|
maxRows
|
|
240
253
|
});
|
|
241
254
|
},
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
if (latencyMs > maxLatencyMs) {
|
|
245
|
-
const shouldBlock = latencySeverity === "error" || ctx.mode === "strict";
|
|
246
|
-
emitBudgetViolation(runtimeError("BUDGET.TIME_EXCEEDED", "Query latency exceeds budget", {
|
|
247
|
-
latencyMs,
|
|
248
|
-
maxLatencyMs
|
|
249
|
-
}), shouldBlock, ctx);
|
|
250
|
-
}
|
|
251
|
-
}
|
|
255
|
+
afterQuery: afterOperation,
|
|
256
|
+
afterExecute: afterOperation
|
|
252
257
|
});
|
|
253
258
|
function evaluateSelectAst(ast, ctx) {
|
|
254
259
|
const hasAggNoGroup = hasAggregateWithoutGroupBy(ast);
|
|
@@ -430,25 +435,27 @@ function getConfiguredSeverity(code, options) {
|
|
|
430
435
|
*/
|
|
431
436
|
function lints(options) {
|
|
432
437
|
const fallback = options?.fallbackWhenAstMissing ?? "raw";
|
|
438
|
+
const beforeOperation = async (plan, ctx) => {
|
|
439
|
+
const findings = [];
|
|
440
|
+
if (isQueryAst(plan.ast)) {
|
|
441
|
+
findings.push(...evaluateAstLints(plan.ast));
|
|
442
|
+
if (plan.ast.kind === "raw-sql") findings.push(...evaluateRawGuardrails(plan).lints);
|
|
443
|
+
} else if (fallback !== "skip") findings.push(...evaluateRawGuardrails(plan).lints);
|
|
444
|
+
for (const lint of findings) {
|
|
445
|
+
const effectiveSeverity = getConfiguredSeverity(lint.code, options) ?? lint.severity;
|
|
446
|
+
if (effectiveSeverity === "error") throw runtimeError(lint.code, lint.message, lint.details);
|
|
447
|
+
if (effectiveSeverity === "warn") ctx.log.warn({
|
|
448
|
+
code: lint.code,
|
|
449
|
+
message: lint.message,
|
|
450
|
+
details: lint.details
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
};
|
|
433
454
|
return Object.freeze({
|
|
434
455
|
name: "lints",
|
|
435
456
|
familyId: "sql",
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
if (isQueryAst(plan.ast)) {
|
|
439
|
-
findings.push(...evaluateAstLints(plan.ast));
|
|
440
|
-
if (plan.ast.kind === "raw-sql") findings.push(...evaluateRawGuardrails(plan).lints);
|
|
441
|
-
} else if (fallback !== "skip") findings.push(...evaluateRawGuardrails(plan).lints);
|
|
442
|
-
for (const lint of findings) {
|
|
443
|
-
const effectiveSeverity = getConfiguredSeverity(lint.code, options) ?? lint.severity;
|
|
444
|
-
if (effectiveSeverity === "error") throw runtimeError(lint.code, lint.message, lint.details);
|
|
445
|
-
if (effectiveSeverity === "warn") ctx.log.warn({
|
|
446
|
-
code: lint.code,
|
|
447
|
-
message: lint.message,
|
|
448
|
-
details: lint.details
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
}
|
|
457
|
+
beforeQuery: beforeOperation,
|
|
458
|
+
beforeExecute: beforeOperation
|
|
452
459
|
});
|
|
453
460
|
}
|
|
454
461
|
var PreparedStatementImpl = class {
|
|
@@ -467,8 +474,8 @@ var PreparedStatementImpl = class {
|
|
|
467
474
|
this.paramMetadata = internals.paramMetadata;
|
|
468
475
|
Object.freeze(this);
|
|
469
476
|
}
|
|
470
|
-
|
|
471
|
-
return target
|
|
477
|
+
query(target, params, options) {
|
|
478
|
+
return runPreparedQuery(target, this, params, options);
|
|
472
479
|
}
|
|
473
480
|
};
|
|
474
481
|
function documentScopedCodecTypes(contract) {
|
|
@@ -1120,10 +1127,14 @@ function buildBindSiteParams(declaration) {
|
|
|
1120
1127
|
* surface `RUNTIME.PREPARE_MISSING_PARAM` so the caller cannot silently
|
|
1121
1128
|
* bind `undefined`.
|
|
1122
1129
|
*/
|
|
1130
|
+
function isRecord(value) {
|
|
1131
|
+
return typeof value === "object" && value !== null;
|
|
1132
|
+
}
|
|
1123
1133
|
function resolvePreparedSlotValues(ps, userParams) {
|
|
1134
|
+
if (!isRecord(userParams)) throw runtimeError("RUNTIME.PREPARE_MISSING_PARAM", "Prepared statement parameters must be an object");
|
|
1124
1135
|
return ps.slots.map((slot) => {
|
|
1125
1136
|
if (slot.kind === "literal") return slot.value;
|
|
1126
|
-
if (!Object.hasOwn(userParams, slot.name)) throw runtimeError("RUNTIME.PREPARE_MISSING_PARAM", `Prepared statement
|
|
1137
|
+
if (!Object.hasOwn(userParams, slot.name)) throw runtimeError("RUNTIME.PREPARE_MISSING_PARAM", `Prepared statement query is missing parameter '${slot.name}'`, { name: slot.name });
|
|
1127
1138
|
return userParams[slot.name];
|
|
1128
1139
|
});
|
|
1129
1140
|
}
|
|
@@ -1181,7 +1192,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1181
1192
|
mode: mode ?? "strict",
|
|
1182
1193
|
now: () => Date.now(),
|
|
1183
1194
|
log: log ?? noopLog,
|
|
1184
|
-
contentHash: (exec) => computeSqlContentHash(exec),
|
|
1195
|
+
contentHash: (exec) => computeSqlContentHash(blindCast(exec)),
|
|
1185
1196
|
scope: "runtime",
|
|
1186
1197
|
planExecutionId: ""
|
|
1187
1198
|
};
|
|
@@ -1206,15 +1217,14 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1206
1217
|
* with encoded parameters ready for the driver.
|
|
1207
1218
|
*
|
|
1208
1219
|
* Implementation note: SQL splits lower-then-encode across
|
|
1209
|
-
* {@link lowerToDraft} + {@link encodeDraftParams} so the
|
|
1210
|
-
*
|
|
1211
|
-
*
|
|
1212
|
-
*
|
|
1213
|
-
*
|
|
1214
|
-
*
|
|
1215
|
-
*
|
|
1216
|
-
*
|
|
1217
|
-
* `beforeExecute` lands between the two halves.
|
|
1220
|
+
* {@link lowerToDraft} + {@link encodeDraftParams} so the selected
|
|
1221
|
+
* operation's middleware chain can run between them:
|
|
1222
|
+
* {@link prepareQueryExecution} uses `runBeforeQueryChain` for `query()`,
|
|
1223
|
+
* while {@link prepareExecuteExecution} uses `runBeforeExecuteChain` for
|
|
1224
|
+
* `execute()` (cipherstash bulk-encrypt, for example, mutates pre-encode
|
|
1225
|
+
* `ParamRef.value` slots). This protected hook composes the two back into
|
|
1226
|
+
* the cross-family `lower()` shape `RuntimeCore` expects. The production
|
|
1227
|
+
* operation methods use the matching split form before driver execution.
|
|
1218
1228
|
*
|
|
1219
1229
|
* `ctx: SqlCodecCallContext` is forwarded to `encodeParams` so
|
|
1220
1230
|
* per-query cancellation reaches every codec body during parameter
|
|
@@ -1226,20 +1236,20 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1226
1236
|
return await this.encodeDraftParams(draft, ctx);
|
|
1227
1237
|
}
|
|
1228
1238
|
/**
|
|
1229
|
-
* AST → pre-encode draft
|
|
1230
|
-
* `params` populated with the
|
|
1231
|
-
* collected from `ParamRef` nodes. No
|
|
1232
|
-
* yet; consumers can mutate `params` via the
|
|
1233
|
-
* before {@link encodeDraftParams} runs.
|
|
1239
|
+
* AST → pre-encode draft for the selected `query()` or `execute()` operation.
|
|
1240
|
+
* The returned plan has `sql` rendered and `params` populated with the
|
|
1241
|
+
* user-domain values the lowering site collected from `ParamRef` nodes. No
|
|
1242
|
+
* codec encode has happened yet; consumers can mutate `params` via the
|
|
1243
|
+
* `SqlParamRefMutator` before {@link encodeDraftParams} runs.
|
|
1234
1244
|
*/
|
|
1235
1245
|
lowerToDraft(plan) {
|
|
1236
1246
|
return lowerSqlPlan(this.adapter, this.contract, plan);
|
|
1237
1247
|
}
|
|
1238
1248
|
/**
|
|
1239
|
-
* Encode a draft plan's params
|
|
1240
|
-
*
|
|
1241
|
-
* sees. Errors surface as
|
|
1242
|
-
* {@link encodeParams}.
|
|
1249
|
+
* Encode a draft plan's params for the selected `query()` or `execute()`
|
|
1250
|
+
* operation through the per-column codecs and freeze the result into the
|
|
1251
|
+
* final `SqlExecutionPlan` the driver sees. Errors surface as
|
|
1252
|
+
* `RUNTIME.ENCODE_FAILED` envelopes from {@link encodeParams}.
|
|
1243
1253
|
*/
|
|
1244
1254
|
async encodeDraftParams(draft, ctx) {
|
|
1245
1255
|
return Object.freeze({
|
|
@@ -1247,9 +1257,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1247
1257
|
params: await encodeParams(draft, ctx, this.contractCodecs)
|
|
1248
1258
|
});
|
|
1249
1259
|
}
|
|
1250
|
-
/**
|
|
1251
|
-
* Default driver invocation required by the abstract `RuntimeCore` contract. Every production path overrides `execute()` and routes through `executeAgainstQueryable`, so this hook is defensive only — subclasses that delegate back to `super.execute()` would land here.
|
|
1252
|
-
*/
|
|
1260
|
+
/** Default query invocation required by the abstract `RuntimeCore` contract. */
|
|
1253
1261
|
// v8 ignore next 6
|
|
1254
1262
|
runDriver(exec) {
|
|
1255
1263
|
return this.driver.query({
|
|
@@ -1257,26 +1265,38 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1257
1265
|
params: exec.params
|
|
1258
1266
|
});
|
|
1259
1267
|
}
|
|
1268
|
+
runExecute(exec) {
|
|
1269
|
+
return this.driver.execute({
|
|
1270
|
+
sql: exec.sql,
|
|
1271
|
+
params: exec.params
|
|
1272
|
+
});
|
|
1273
|
+
}
|
|
1260
1274
|
/**
|
|
1261
1275
|
* SQL pre-compile hook. Runs the registered middleware `beforeCompile` chain over the plan's draft (AST + meta). Returns the original plan unchanged when no middleware rewrote the AST; otherwise returns a new plan carrying the rewritten AST and meta. The AST is the authoritative source of execution metadata, so a rewrite needs no sidecar reconciliation here — the lowering adapter and the encoder both walk the rewritten
|
|
1262
1276
|
* AST directly.
|
|
1263
1277
|
*/
|
|
1264
|
-
|
|
1278
|
+
runBeforeCompile(plan) {
|
|
1279
|
+
return this.compilePlan(plan, this.sqlCtx);
|
|
1280
|
+
}
|
|
1281
|
+
async compilePlan(plan, middlewareCtx) {
|
|
1265
1282
|
const rewrittenDraft = await runBeforeCompileChain(this.middleware, {
|
|
1266
1283
|
ast: plan.ast,
|
|
1267
1284
|
meta: plan.meta
|
|
1268
|
-
},
|
|
1285
|
+
}, middlewareCtx);
|
|
1269
1286
|
return rewrittenDraft.ast === plan.ast ? plan : {
|
|
1270
1287
|
...plan,
|
|
1271
1288
|
ast: rewrittenDraft.ast,
|
|
1272
1289
|
meta: rewrittenDraft.meta
|
|
1273
1290
|
};
|
|
1274
1291
|
}
|
|
1292
|
+
query(plan, options) {
|
|
1293
|
+
return this.queryAgainstQueryable(plan, this.driver, options);
|
|
1294
|
+
}
|
|
1275
1295
|
execute(plan, options) {
|
|
1276
|
-
return this.
|
|
1296
|
+
return this.executeStatisticsAgainstQueryable(plan, this.driver, options);
|
|
1277
1297
|
}
|
|
1278
|
-
|
|
1279
|
-
return this.
|
|
1298
|
+
[preparedStatementQuery](ps, params, options) {
|
|
1299
|
+
return this.runPreparedQueryAgainstQueryable(blindCast(ps), params, this.driver, options);
|
|
1280
1300
|
}
|
|
1281
1301
|
/**
|
|
1282
1302
|
* Returns the raw driver connection. The connection is a `SqlQueryable` — SQL
|
|
@@ -1287,15 +1307,18 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1287
1307
|
acquireRawConnection() {
|
|
1288
1308
|
return this.driver.acquireConnection();
|
|
1289
1309
|
}
|
|
1290
|
-
async
|
|
1310
|
+
async setupDriverExecution(exec) {
|
|
1291
1311
|
this.familyAdapter.validatePlan(exec, this.contract);
|
|
1292
1312
|
this._telemetry = null;
|
|
1293
1313
|
if (this.verifyMarkerPromise === null) this.verifyMarkerPromise = this.verifyMarker();
|
|
1294
1314
|
await this.verifyMarkerPromise;
|
|
1315
|
+
}
|
|
1316
|
+
async *streamRows(exec, decodeContext, driverCall, codecCtx, execMiddlewareCtx) {
|
|
1317
|
+
await this.setupDriverExecution(exec);
|
|
1295
1318
|
const startedAt = Date.now();
|
|
1296
1319
|
let outcome = null;
|
|
1297
1320
|
try {
|
|
1298
|
-
const iterator =
|
|
1321
|
+
const iterator = runQueryWithMiddleware(exec, this.middleware, execMiddlewareCtx, driverCall)[Symbol.asyncIterator]();
|
|
1299
1322
|
try {
|
|
1300
1323
|
while (true) {
|
|
1301
1324
|
checkAborted(codecCtx, "stream");
|
|
@@ -1314,55 +1337,84 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1314
1337
|
if (outcome !== null) this.recordTelemetry(exec, outcome, Date.now() - startedAt);
|
|
1315
1338
|
}
|
|
1316
1339
|
}
|
|
1317
|
-
|
|
1318
|
-
* Execute a plan against a caller-supplied queryable, running the full
|
|
1319
|
-
* middleware/codec/telemetry pipeline. Use `acquireRawConnection` to obtain a
|
|
1320
|
-
* queryable that subclasses can bind typed plans to.
|
|
1321
|
-
*/
|
|
1322
|
-
executeAgainstQueryable(plan, queryable, options) {
|
|
1323
|
-
this.ensureCodecRegistryValidated();
|
|
1324
|
-
const self = this;
|
|
1340
|
+
createQueryContexts(options) {
|
|
1325
1341
|
const signal = options?.signal;
|
|
1326
1342
|
const scope = options?.scope ?? "runtime";
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1343
|
+
return {
|
|
1344
|
+
codecCtx: signal === void 0 ? {} : { signal },
|
|
1345
|
+
middlewareCtx: {
|
|
1346
|
+
...this.sqlCtx,
|
|
1347
|
+
...ifDefined("signal", signal),
|
|
1348
|
+
...scope !== "runtime" ? { scope } : {},
|
|
1349
|
+
planExecutionId: crypto.randomUUID()
|
|
1350
|
+
}
|
|
1333
1351
|
};
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1352
|
+
}
|
|
1353
|
+
prepareQueryExecution(plan, codecCtx, middlewareCtx) {
|
|
1354
|
+
return this.prepareOperation(plan, codecCtx, middlewareCtx, runBeforeQueryChain);
|
|
1355
|
+
}
|
|
1356
|
+
prepareExecuteExecution(plan, codecCtx, middlewareCtx) {
|
|
1357
|
+
return this.prepareOperation(plan, codecCtx, middlewareCtx, runBeforeExecuteChain);
|
|
1358
|
+
}
|
|
1359
|
+
async prepareOperation(plan, codecCtx, middlewareCtx, runBefore) {
|
|
1360
|
+
checkAborted(codecCtx, "stream");
|
|
1361
|
+
if (isExecutionPlan(plan)) {
|
|
1362
|
+
const mutator = createSqlParamRefMutator(plan);
|
|
1363
|
+
await runBefore(plan, this.middleware, middlewareCtx, mutator);
|
|
1364
|
+
return Object.freeze({
|
|
1365
|
+
...plan,
|
|
1366
|
+
params: await encodeParams({
|
|
1341
1367
|
...plan,
|
|
1342
|
-
params:
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1349
|
-
|
|
1350
|
-
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1368
|
+
params: mutator.currentParams()
|
|
1369
|
+
}, codecCtx, this.contractCodecs)
|
|
1370
|
+
});
|
|
1371
|
+
}
|
|
1372
|
+
const compiled = await this.compilePlan(plan, middlewareCtx);
|
|
1373
|
+
const draft = this.lowerToDraft(compiled);
|
|
1374
|
+
const mutator = createSqlParamRefMutator(draft);
|
|
1375
|
+
await runBefore(draft, this.middleware, middlewareCtx, mutator);
|
|
1376
|
+
const draftWithMutations = Object.freeze({
|
|
1377
|
+
...draft,
|
|
1378
|
+
params: mutator.currentParams()
|
|
1379
|
+
});
|
|
1380
|
+
return this.encodeDraftParams(draftWithMutations, codecCtx);
|
|
1381
|
+
}
|
|
1382
|
+
/** Query rows against a caller-supplied queryable through the shared preparation pipeline. */
|
|
1383
|
+
queryAgainstQueryable(plan, queryable, options) {
|
|
1384
|
+
this.ensureCodecRegistryValidated();
|
|
1385
|
+
const self = this;
|
|
1386
|
+
const { codecCtx, middlewareCtx } = this.createQueryContexts(options);
|
|
1387
|
+
const generator = async function* () {
|
|
1388
|
+
const exec = await self.prepareQueryExecution(plan, codecCtx, middlewareCtx);
|
|
1358
1389
|
const decodeContext = buildDecodeContext(exec.ast, self.contractCodecs);
|
|
1359
1390
|
yield* self.streamRows(exec, decodeContext, () => queryable.query({
|
|
1360
1391
|
sql: exec.sql,
|
|
1361
1392
|
params: exec.params
|
|
1362
|
-
}), codecCtx,
|
|
1393
|
+
}), codecCtx, middlewareCtx);
|
|
1363
1394
|
};
|
|
1364
1395
|
return new AsyncIterableResult(generator());
|
|
1365
1396
|
}
|
|
1397
|
+
/** Execute statistics against a caller-supplied queryable through the shared preparation pipeline. */
|
|
1398
|
+
async executeStatisticsAgainstQueryable(plan, queryable, options) {
|
|
1399
|
+
this.ensureCodecRegistryValidated();
|
|
1400
|
+
const { codecCtx, middlewareCtx } = this.createQueryContexts(options);
|
|
1401
|
+
const exec = await this.prepareExecuteExecution(plan, codecCtx, middlewareCtx);
|
|
1402
|
+
await this.setupDriverExecution(exec);
|
|
1403
|
+
checkAborted(codecCtx, "stream");
|
|
1404
|
+
const startedAt = Date.now();
|
|
1405
|
+
let outcome = "success";
|
|
1406
|
+
try {
|
|
1407
|
+
return await runExecuteWithMiddleware(exec, this.middleware, middlewareCtx, () => queryable.execute({
|
|
1408
|
+
sql: exec.sql,
|
|
1409
|
+
params: exec.params
|
|
1410
|
+
}));
|
|
1411
|
+
} catch (error) {
|
|
1412
|
+
outcome = "runtime-error";
|
|
1413
|
+
throw error;
|
|
1414
|
+
} finally {
|
|
1415
|
+
this.recordTelemetry(exec, outcome, Date.now() - startedAt);
|
|
1416
|
+
}
|
|
1417
|
+
}
|
|
1366
1418
|
async prepare(declaration, callback) {
|
|
1367
1419
|
this.ensureCodecRegistryValidated();
|
|
1368
1420
|
const userPlan = callback(buildBindSiteParams(declaration));
|
|
@@ -1387,22 +1439,11 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1387
1439
|
paramMetadata
|
|
1388
1440
|
}));
|
|
1389
1441
|
}
|
|
1390
|
-
/**
|
|
1391
|
-
|
|
1392
|
-
* the full middleware/codec/telemetry pipeline.
|
|
1393
|
-
*/
|
|
1394
|
-
executePreparedAgainstQueryable(ps, userParams, queryable, options) {
|
|
1442
|
+
/** Query prepared rows against a caller-supplied queryable through the full pipeline. */
|
|
1443
|
+
runPreparedQueryAgainstQueryable(ps, userParams, queryable, options) {
|
|
1395
1444
|
this.ensureCodecRegistryValidated();
|
|
1396
1445
|
const self = this;
|
|
1397
|
-
const
|
|
1398
|
-
const scope = options?.scope ?? "runtime";
|
|
1399
|
-
const codecCtx = signal === void 0 ? {} : { signal };
|
|
1400
|
-
const execMiddlewareCtx = {
|
|
1401
|
-
...self.ctx,
|
|
1402
|
-
...ifDefined("signal", signal),
|
|
1403
|
-
...scope !== "runtime" ? { scope } : {},
|
|
1404
|
-
planExecutionId: crypto.randomUUID()
|
|
1405
|
-
};
|
|
1446
|
+
const { codecCtx, middlewareCtx: execMiddlewareCtx } = this.createQueryContexts(options);
|
|
1406
1447
|
const generator = async function* () {
|
|
1407
1448
|
checkAborted(codecCtx, "stream");
|
|
1408
1449
|
const preEncodeValues = resolvePreparedSlotValues(ps, userParams);
|
|
@@ -1413,7 +1454,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1413
1454
|
meta: ps.meta
|
|
1414
1455
|
};
|
|
1415
1456
|
const mutator = createSqlParamRefMutator(preEncodeExec);
|
|
1416
|
-
await
|
|
1457
|
+
await runBeforeQueryChain(preEncodeExec, self.middleware, execMiddlewareCtx, mutator);
|
|
1417
1458
|
const encodedParams = await encodeParamsWithMetadata(mutator.currentParams(), ps.paramMetadata, codecCtx, self.contractCodecs);
|
|
1418
1459
|
const exec = {
|
|
1419
1460
|
sql: ps.sql,
|
|
@@ -1450,14 +1491,20 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1450
1491
|
async destroy(reason) {
|
|
1451
1492
|
await driverConn.destroy(reason);
|
|
1452
1493
|
},
|
|
1494
|
+
query(plan, options) {
|
|
1495
|
+
return self.queryAgainstQueryable(plan, driverConn, {
|
|
1496
|
+
...options,
|
|
1497
|
+
scope: "connection"
|
|
1498
|
+
});
|
|
1499
|
+
},
|
|
1453
1500
|
execute(plan, options) {
|
|
1454
|
-
return self.
|
|
1501
|
+
return self.executeStatisticsAgainstQueryable(plan, driverConn, {
|
|
1455
1502
|
...options,
|
|
1456
1503
|
scope: "connection"
|
|
1457
1504
|
});
|
|
1458
1505
|
},
|
|
1459
|
-
|
|
1460
|
-
return self.
|
|
1506
|
+
[preparedStatementQuery](ps, params, options) {
|
|
1507
|
+
return self.runPreparedQueryAgainstQueryable(blindCast(ps), params, driverConn, {
|
|
1461
1508
|
...options,
|
|
1462
1509
|
scope: "connection"
|
|
1463
1510
|
});
|
|
@@ -1473,14 +1520,20 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1473
1520
|
async rollback() {
|
|
1474
1521
|
await driverTx.rollback();
|
|
1475
1522
|
},
|
|
1523
|
+
query(plan, options) {
|
|
1524
|
+
return self.queryAgainstQueryable(plan, driverTx, {
|
|
1525
|
+
...options,
|
|
1526
|
+
scope: "transaction"
|
|
1527
|
+
});
|
|
1528
|
+
},
|
|
1476
1529
|
execute(plan, options) {
|
|
1477
|
-
return self.
|
|
1530
|
+
return self.executeStatisticsAgainstQueryable(plan, driverTx, {
|
|
1478
1531
|
...options,
|
|
1479
1532
|
scope: "transaction"
|
|
1480
1533
|
});
|
|
1481
1534
|
},
|
|
1482
|
-
|
|
1483
|
-
return self.
|
|
1535
|
+
[preparedStatementQuery](ps, params, options) {
|
|
1536
|
+
return self.runPreparedQueryAgainstQueryable(blindCast(ps), params, driverTx, {
|
|
1484
1537
|
...options,
|
|
1485
1538
|
scope: "transaction"
|
|
1486
1539
|
});
|
|
@@ -1543,7 +1596,7 @@ var SqlRuntimeBase = class extends RuntimeCore {
|
|
|
1543
1596
|
}
|
|
1544
1597
|
};
|
|
1545
1598
|
function transactionClosedError() {
|
|
1546
|
-
return runtimeError("RUNTIME.TRANSACTION_CLOSED", "Cannot
|
|
1599
|
+
return runtimeError("RUNTIME.TRANSACTION_CLOSED", "Cannot use a transaction operation after the transaction has ended. Consume query results and await execute calls inside the transaction callback.", {});
|
|
1547
1600
|
}
|
|
1548
1601
|
async function withTransaction(runtime, fn) {
|
|
1549
1602
|
const connection = await runtime.connection();
|
|
@@ -1560,13 +1613,17 @@ async function withTransaction(runtime, fn) {
|
|
|
1560
1613
|
get invalidated() {
|
|
1561
1614
|
return invalidated;
|
|
1562
1615
|
},
|
|
1563
|
-
|
|
1616
|
+
query(plan, options) {
|
|
1617
|
+
if (invalidated) throw transactionClosedError();
|
|
1618
|
+
return new AsyncIterableResult(guardedStream(transaction.query(plan, options)));
|
|
1619
|
+
},
|
|
1620
|
+
async execute(plan, options) {
|
|
1564
1621
|
if (invalidated) throw transactionClosedError();
|
|
1565
|
-
return
|
|
1622
|
+
return transaction.execute(plan, options);
|
|
1566
1623
|
},
|
|
1567
|
-
|
|
1624
|
+
[preparedStatementQuery](ps, params, options) {
|
|
1568
1625
|
if (invalidated) throw transactionClosedError();
|
|
1569
|
-
return new AsyncIterableResult(guardedStream(transaction
|
|
1626
|
+
return new AsyncIterableResult(guardedStream(runPreparedQuery(transaction, ps, params, options)));
|
|
1570
1627
|
}
|
|
1571
1628
|
};
|
|
1572
1629
|
let connectionDisposed = false;
|