@prisma-next/sql-runtime 0.13.0-dev.3 → 0.13.0-dev.31
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 +24 -43
- package/dist/{exports-DDqF-xmg.mjs → exports-DJWGwqMq.mjs} +71 -115
- package/dist/exports-DJWGwqMq.mjs.map +1 -0
- package/dist/index.d.mts +80 -2
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +2 -2
- package/dist/{index-JOQlRa75.d.mts → prepared-statement-FQyyQnkC.d.mts} +172 -107
- package/dist/prepared-statement-FQyyQnkC.d.mts.map +1 -0
- package/dist/test/utils.d.mts +17 -6
- package/dist/test/utils.d.mts.map +1 -1
- package/dist/test/utils.mjs +22 -3
- package/dist/test/utils.mjs.map +1 -1
- package/package.json +12 -12
- package/src/codecs/ast-codec-resolver.ts +2 -44
- package/src/codecs/validation.ts +19 -30
- package/src/exports/index.ts +6 -2
- package/src/runtime-spi.ts +1 -1
- package/src/sql-context.ts +15 -56
- package/src/sql-runtime.ts +39 -48
- package/dist/exports-DDqF-xmg.mjs.map +0 -1
- package/dist/index-JOQlRa75.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -41,52 +41,31 @@ Execute SQL query Plans with deterministic verification, guardrails, and feedbac
|
|
|
41
41
|
|
|
42
42
|
## Usage
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
import postgresAdapter from '@prisma-next/adapter-postgres/runtime';
|
|
46
|
-
import postgresDriver from '@prisma-next/driver-postgres/runtime';
|
|
47
|
-
import pgvector from '@prisma-next/extension-pgvector/runtime';
|
|
48
|
-
import postgresTarget from '@prisma-next/target-postgres/runtime';
|
|
49
|
-
import { instantiateExecutionStack } from '@prisma-next/framework-components/execution';
|
|
50
|
-
import {
|
|
51
|
-
budgets,
|
|
52
|
-
createExecutionContext,
|
|
53
|
-
createRuntime,
|
|
54
|
-
createSqlExecutionStack,
|
|
55
|
-
} from '@prisma-next/sql-runtime';
|
|
56
|
-
|
|
57
|
-
const contract = postgresTarget.contractSerializer.deserializeContract(contractJson);
|
|
58
|
-
const stack = createSqlExecutionStack({
|
|
59
|
-
target: postgresTarget,
|
|
60
|
-
adapter: postgresAdapter,
|
|
61
|
-
driver: postgresDriver,
|
|
62
|
-
extensionPacks: [pgvector],
|
|
63
|
-
});
|
|
44
|
+
`SqlRuntime` is an abstract base class. Construct a runtime via the target factory — `postgres()` from `@prisma-next/postgres` or `sqlite()` from `@prisma-next/sqlite`. You do not call `new SqlRuntime()` directly.
|
|
64
45
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
driver,
|
|
46
|
+
```typescript
|
|
47
|
+
import postgres from '@prisma-next/postgres';
|
|
48
|
+
import { budgets } from '@prisma-next/sql-runtime';
|
|
49
|
+
import type { Contract } from './src/contract';
|
|
50
|
+
import contractJson from './src/contract.json' with { type: 'json' };
|
|
51
|
+
|
|
52
|
+
const db = postgres<Contract>({
|
|
53
|
+
contractJson,
|
|
54
|
+
url: process.env.DATABASE_URL,
|
|
75
55
|
middleware: [budgets()],
|
|
76
56
|
});
|
|
77
57
|
|
|
78
|
-
for await (const row of runtime.execute(plan)) {
|
|
58
|
+
for await (const row of db.runtime().execute(plan)) {
|
|
79
59
|
console.log(row);
|
|
80
60
|
}
|
|
81
61
|
```
|
|
82
62
|
|
|
83
|
-
|
|
63
|
+
Pass `verifyMarker: false` to skip the marker read entirely — e.g. during a known-skewed deploy window where contract drift is expected and tolerated.
|
|
84
64
|
|
|
85
65
|
```typescript
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
driver,
|
|
66
|
+
const db = postgres<Contract>({
|
|
67
|
+
contractJson,
|
|
68
|
+
url: process.env.DATABASE_URL,
|
|
90
69
|
verifyMarker: false,
|
|
91
70
|
middleware: [budgets()],
|
|
92
71
|
});
|
|
@@ -96,9 +75,9 @@ const runtime = createRuntime({
|
|
|
96
75
|
|
|
97
76
|
### Runtime
|
|
98
77
|
|
|
99
|
-
- `
|
|
100
|
-
- `Runtime` - Runtime instance
|
|
101
|
-
- `
|
|
78
|
+
- `SqlRuntime` - Abstract family-layer base class; subclass to build a target runtime (construction happens via target factories — `postgres()` from `@prisma-next/postgres`, `sqlite()` from `@prisma-next/sqlite`)
|
|
79
|
+
- `Runtime` - Runtime instance interface
|
|
80
|
+
- `withTransaction` - Helper to run a callback inside a transaction against any `Runtime`
|
|
102
81
|
- `VerifyMarkerOption` - Marker-verification option (`'onFirstUse'` default; `false` to skip)
|
|
103
82
|
- `RuntimeTelemetryEvent`, `TelemetryOutcome` - Telemetry event types
|
|
104
83
|
|
|
@@ -159,10 +138,12 @@ The `lints` middleware operates on `plan.ast` when it is a SQL `QueryAst`:
|
|
|
159
138
|
When `plan.ast` is missing, the middleware falls back to raw heuristic guardrails (`fallbackWhenAstMissing: 'raw'`) or skips linting (`fallbackWhenAstMissing: 'skip'`). Default is `'raw'`.
|
|
160
139
|
|
|
161
140
|
```typescript
|
|
162
|
-
import
|
|
141
|
+
import postgres from '@prisma-next/postgres';
|
|
142
|
+
import { lints } from '@prisma-next/sql-runtime';
|
|
163
143
|
|
|
164
|
-
const
|
|
165
|
-
|
|
144
|
+
const db = postgres<Contract>({
|
|
145
|
+
contractJson,
|
|
146
|
+
url: process.env.DATABASE_URL,
|
|
166
147
|
middleware: [lints({ severities: { noLimit: 'error' } })],
|
|
167
148
|
});
|
|
168
149
|
```
|
|
@@ -175,7 +156,7 @@ The SQL runtime extends the abstract `RuntimeCore` base class from `@prisma-next
|
|
|
175
156
|
2. **SqlStaticContributions**: Codecs, operation signatures, parameterized codecs, and mutation default generators contributed by each descriptor
|
|
176
157
|
3. **ExecutionContext**: Built from contract + stack descriptors (no instantiation)
|
|
177
158
|
4. **ExecutionStackInstance**: Instantiated components used at runtime for execution
|
|
178
|
-
5. **SqlRuntime**: `class
|
|
159
|
+
5. **SqlRuntime**: `class SqlRuntime extends RuntimeCore<SqlQueryPlan, SqlExecutionPlan, SqlMiddleware>` — overrides `lower` (with codec param-encoding), `runDriver`, `runBeforeCompile` (delegates to the SQL `beforeCompile` chain), and `close`. The execution path also wraps the `runWithMiddleware` helper from `framework-components/runtime` with codec row-decoding, marker verification (via the `RuntimeFamilyAdapter` defined in `runtime-spi.ts`), and telemetry fingerprinting (via `computeSqlFingerprint` from `fingerprint.ts`).
|
|
179
160
|
6. **SqlMarker**: Provides SQL statements for marker management
|
|
180
161
|
|
|
181
162
|
```mermaid
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
+
import { materializeCodec } from "@prisma-next/framework-components/codec";
|
|
1
2
|
import { AsyncIterableResult, RuntimeCore, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeError } from "@prisma-next/framework-components/runtime";
|
|
2
3
|
import { canonicalizeJson } from "@prisma-next/framework-components/utils";
|
|
3
4
|
import { PreparedParamRef, collectOrderedParamRefs, isQueryAst } from "@prisma-next/sql-relational-core/ast";
|
|
4
5
|
import { ifDefined } from "@prisma-next/utils/defined";
|
|
5
6
|
import { checkContractComponentRequirements, mergeCapabilityMatrices } from "@prisma-next/framework-components/components";
|
|
6
7
|
import { createExecutionStack } from "@prisma-next/framework-components/execution";
|
|
7
|
-
import { isPostgresEnumStorageEntry } from "@prisma-next/sql-contract/types";
|
|
8
8
|
import { blindCast } from "@prisma-next/utils/casts";
|
|
9
9
|
import { createSqlOperationRegistry } from "@prisma-next/sql-operations";
|
|
10
10
|
import { buildCodecDescriptorRegistry } from "@prisma-next/sql-relational-core/codec-descriptor-registry";
|
|
@@ -26,31 +26,11 @@ function createAstCodecResolver(descriptors, instanceContextFor) {
|
|
|
26
26
|
if (cached) return cached;
|
|
27
27
|
const descriptor = descriptors.descriptorFor(ref.codecId);
|
|
28
28
|
if (!descriptor) throw runtimeError("RUNTIME.CODEC_DESCRIPTOR_MISSING", `No codec descriptor registered for codecId '${ref.codecId}'.`, { codecId: ref.codecId });
|
|
29
|
-
const
|
|
30
|
-
...ref,
|
|
31
|
-
typeParams: {}
|
|
32
|
-
} : ref);
|
|
33
|
-
const ctx = instanceContextFor(ref);
|
|
34
|
-
const codec = descriptor.factory(validated)(ctx);
|
|
29
|
+
const codec = materializeCodec(descriptor, ref, instanceContextFor(ref));
|
|
35
30
|
cache.set(key, codec);
|
|
36
31
|
return codec;
|
|
37
32
|
} };
|
|
38
33
|
}
|
|
39
|
-
function validateTypeParams$1(paramsSchema, ref) {
|
|
40
|
-
const result = paramsSchema["~standard"].validate(ref.typeParams);
|
|
41
|
-
if (result instanceof Promise) throw runtimeError("RUNTIME.TYPE_PARAMS_INVALID", `paramsSchema for codec '${ref.codecId}' returned a Promise; runtime validation requires a synchronous Standard Schema validator.`, {
|
|
42
|
-
codecId: ref.codecId,
|
|
43
|
-
typeParams: ref.typeParams
|
|
44
|
-
});
|
|
45
|
-
if ("issues" in result && result.issues) {
|
|
46
|
-
const messages = result.issues.map((issue) => issue.message).join("; ");
|
|
47
|
-
throw runtimeError("RUNTIME.TYPE_PARAMS_INVALID", `Invalid typeParams for codec '${ref.codecId}': ${messages}`, {
|
|
48
|
-
codecId: ref.codecId,
|
|
49
|
-
typeParams: ref.typeParams
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
return result.value;
|
|
53
|
-
}
|
|
54
34
|
//#endregion
|
|
55
35
|
//#region src/codecs/ast-codec-registry.ts
|
|
56
36
|
/**
|
|
@@ -137,40 +117,30 @@ async function encodeParamsWithMetadata(values, metadata, ctx, contractCodecs) {
|
|
|
137
117
|
//#region src/codecs/validation.ts
|
|
138
118
|
function extractCodecIds(contract) {
|
|
139
119
|
const codecIds = /* @__PURE__ */ new Set();
|
|
140
|
-
for (const ns of Object.values(contract.storage.namespaces)) for (const table of Object.values(ns.entries.table)) for (const column of Object.values(table.columns)) {
|
|
120
|
+
for (const ns of Object.values(contract.storage.namespaces)) for (const table of Object.values(ns.entries.table ?? {})) for (const column of Object.values(table.columns)) {
|
|
141
121
|
const codecId = column.codecId;
|
|
142
122
|
codecIds.add(codecId);
|
|
143
123
|
}
|
|
144
124
|
return codecIds;
|
|
145
125
|
}
|
|
146
|
-
function
|
|
147
|
-
const
|
|
148
|
-
for (const ns of Object.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
126
|
+
function extractColumnCodecRefs(contract) {
|
|
127
|
+
const refs = [];
|
|
128
|
+
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const [columnName, column] of Object.entries(table.columns)) refs.push({
|
|
129
|
+
namespaceId,
|
|
130
|
+
table: tableName,
|
|
131
|
+
column: columnName,
|
|
132
|
+
codecId: column.codecId
|
|
133
|
+
});
|
|
134
|
+
return refs;
|
|
154
135
|
}
|
|
155
136
|
function validateContractCodecMappings(registry, contract) {
|
|
156
|
-
const
|
|
157
|
-
const invalidCodecs = [];
|
|
158
|
-
for (const [key, codecId] of codecIds.entries()) if (registry.descriptorFor(codecId) === void 0) {
|
|
159
|
-
const parts = key.split(".");
|
|
160
|
-
const table = parts[0] ?? "";
|
|
161
|
-
const column = parts[1] ?? "";
|
|
162
|
-
invalidCodecs.push({
|
|
163
|
-
table,
|
|
164
|
-
column,
|
|
165
|
-
codecId
|
|
166
|
-
});
|
|
167
|
-
}
|
|
137
|
+
const invalidCodecs = extractColumnCodecRefs(contract).filter((ref) => registry.descriptorFor(ref.codecId) === void 0);
|
|
168
138
|
if (invalidCodecs.length > 0) {
|
|
169
139
|
const details = {
|
|
170
140
|
contractTarget: contract.target,
|
|
171
141
|
invalidCodecs
|
|
172
142
|
};
|
|
173
|
-
throw runtimeError("RUNTIME.CODEC_MISSING", `Missing codec implementations for column codecIds: ${invalidCodecs.map((c) => `${c.table}.${c.column} (${c.codecId})`).join(", ")}`, details);
|
|
143
|
+
throw runtimeError("RUNTIME.CODEC_MISSING", `Missing codec implementations for column codecIds: ${invalidCodecs.map((c) => `${c.namespaceId}.${c.table}.${c.column} (${c.codecId})`).join(", ")}`, details);
|
|
174
144
|
}
|
|
175
145
|
}
|
|
176
146
|
function validateCodecRegistryCompleteness(registry, contract) {
|
|
@@ -472,6 +442,28 @@ function lints(options) {
|
|
|
472
442
|
});
|
|
473
443
|
}
|
|
474
444
|
//#endregion
|
|
445
|
+
//#region src/prepared/prepared-statement.ts
|
|
446
|
+
var PreparedStatementImpl = class {
|
|
447
|
+
sql;
|
|
448
|
+
ast;
|
|
449
|
+
meta;
|
|
450
|
+
slots;
|
|
451
|
+
decodeContext;
|
|
452
|
+
paramMetadata;
|
|
453
|
+
constructor(internals) {
|
|
454
|
+
this.sql = internals.sql;
|
|
455
|
+
this.ast = internals.ast;
|
|
456
|
+
this.meta = internals.meta;
|
|
457
|
+
this.slots = internals.slots;
|
|
458
|
+
this.decodeContext = internals.decodeContext;
|
|
459
|
+
this.paramMetadata = internals.paramMetadata;
|
|
460
|
+
Object.freeze(this);
|
|
461
|
+
}
|
|
462
|
+
execute(target, params, options) {
|
|
463
|
+
return target.executePrepared(this, params, options);
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
//#endregion
|
|
475
467
|
//#region src/sql-context.ts
|
|
476
468
|
function documentScopedCodecTypes(contract) {
|
|
477
469
|
return blindCast(contract.storage.types);
|
|
@@ -509,25 +501,6 @@ function assertExecutionStackContractRequirements(contract, stack) {
|
|
|
509
501
|
throw runtimeError("RUNTIME.MISSING_EXTENSION_PACK", `Contract requires extension pack(s) ${packIds.map((id) => `'${id}'`).join(", ")}, but runtime descriptors do not provide matching component(s).`, { packIds });
|
|
510
502
|
}
|
|
511
503
|
}
|
|
512
|
-
/**
|
|
513
|
-
* Resolves codec id + typeParams for a `SqlStorage.types` entry that
|
|
514
|
-
* represents an enum. The canonical contract path always pipes raw JSON
|
|
515
|
-
* through the `SqlStorage` constructor, which rejects raw
|
|
516
|
-
* `kind: 'postgres-enum'` envelopes that bypass the per-target
|
|
517
|
-
* `ContractSerializer.deserializeContract` hydration. By the time this
|
|
518
|
-
* function runs, the entry is a live IR-class instance that
|
|
519
|
-
* structurally satisfies `PostgresEnumStorageEntry` — `codecId` and
|
|
520
|
-
* `values` are enumerable own properties on the instance. Returns
|
|
521
|
-
* `undefined` when the entry is not enum-shaped, so callers fall
|
|
522
|
-
* through to the codec-typed path.
|
|
523
|
-
*/
|
|
524
|
-
function readEnumViewIfApplicable(typeInstance) {
|
|
525
|
-
if (!isPostgresEnumStorageEntry(typeInstance)) return;
|
|
526
|
-
return {
|
|
527
|
-
codecId: typeInstance.codecId,
|
|
528
|
-
typeParams: { values: typeInstance.values }
|
|
529
|
-
};
|
|
530
|
-
}
|
|
531
504
|
function validateTypeParams(typeParams, descriptor, context) {
|
|
532
505
|
const result = descriptor.paramsSchema["~standard"].validate(typeParams);
|
|
533
506
|
if (result instanceof Promise) throw runtimeError("RUNTIME.TYPE_PARAMS_INVALID", `paramsSchema for codec '${descriptor.codecId}' returned a Promise; runtime validation requires a synchronous Standard Schema validator.`, {
|
|
@@ -567,7 +540,7 @@ function collectCodecDescriptors(contributors) {
|
|
|
567
540
|
}
|
|
568
541
|
function collectTypeRefSites(storage) {
|
|
569
542
|
const sites = /* @__PURE__ */ new Map();
|
|
570
|
-
for (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table)) for (const [columnName, column] of Object.entries(table.columns)) {
|
|
543
|
+
for (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const [columnName, column] of Object.entries(table.columns)) {
|
|
571
544
|
if (typeof column.typeRef !== "string") continue;
|
|
572
545
|
const list = sites.get(column.typeRef);
|
|
573
546
|
const entry = {
|
|
@@ -584,9 +557,8 @@ function initializeTypeHelpers(storage, documentTypes, codecDescriptors) {
|
|
|
584
557
|
if (!documentTypes) return helpers;
|
|
585
558
|
const typeRefSites = collectTypeRefSites(storage);
|
|
586
559
|
for (const [typeName, typeInstance] of Object.entries(documentTypes)) {
|
|
587
|
-
const
|
|
588
|
-
const
|
|
589
|
-
const typeParams = enumView ? enumView.typeParams : typeInstance.typeParams;
|
|
560
|
+
const codecId = typeInstance.codecId;
|
|
561
|
+
const typeParams = typeInstance.typeParams;
|
|
590
562
|
const descriptor = codecDescriptors.get(codecId);
|
|
591
563
|
if (!descriptor) {
|
|
592
564
|
helpers[typeName] = typeInstance;
|
|
@@ -602,7 +574,7 @@ function initializeTypeHelpers(storage, documentTypes, codecDescriptors) {
|
|
|
602
574
|
return helpers;
|
|
603
575
|
}
|
|
604
576
|
function validateColumnTypeParams(storage, codecDescriptors) {
|
|
605
|
-
for (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table)) for (const [columnName, column] of Object.entries(table.columns)) if (column.typeParams) {
|
|
577
|
+
for (const ns of Object.values(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const [columnName, column] of Object.entries(table.columns)) if (column.typeParams) {
|
|
606
578
|
const descriptor = codecDescriptors.get(column.codecId);
|
|
607
579
|
if (descriptor) validateTypeParams(column.typeParams, descriptor, {
|
|
608
580
|
tableName,
|
|
@@ -622,7 +594,7 @@ function validateColumnTypeParams(storage, codecDescriptors) {
|
|
|
622
594
|
* Runs unconditionally from `createExecutionContext` so contract bugs fail fast at construction time instead of silently skipping affected columns in the codec registry's pre-population walk.
|
|
623
595
|
*/
|
|
624
596
|
function assertColumnCodecIntegrity(storage, codecDescriptors) {
|
|
625
|
-
for (const [namespaceId, ns] of Object.entries(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table)) for (const columnName of Object.keys(table.columns)) {
|
|
597
|
+
for (const [namespaceId, ns] of Object.entries(storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const columnName of Object.keys(table.columns)) {
|
|
626
598
|
const ref = codecDescriptors.codecRefForColumn(namespaceId, tableName, columnName);
|
|
627
599
|
if (!ref) continue;
|
|
628
600
|
const descriptor = codecDescriptors.descriptorFor(ref.codecId);
|
|
@@ -682,13 +654,8 @@ function buildContractCodecRegistry(contract, codecDescriptors) {
|
|
|
682
654
|
const nameByKey = /* @__PURE__ */ new Map();
|
|
683
655
|
const typeRefSites = collectTypeRefSites(contract.storage);
|
|
684
656
|
for (const [typeName, typeInstance] of Object.entries(documentScopedCodecTypes(contract) ?? {})) {
|
|
685
|
-
const
|
|
686
|
-
const
|
|
687
|
-
const hasParamKeys = instanceTypeParams !== void 0 && Object.keys(instanceTypeParams).length > 0;
|
|
688
|
-
const key = refKeyOf(enumView ? hasParamKeys ? {
|
|
689
|
-
codecId: enumView.codecId,
|
|
690
|
-
typeParams: instanceTypeParams
|
|
691
|
-
} : { codecId: enumView.codecId } : hasParamKeys ? {
|
|
657
|
+
const instanceTypeParams = typeInstance.typeParams;
|
|
658
|
+
const key = refKeyOf(instanceTypeParams !== void 0 && Object.keys(instanceTypeParams).length > 0 ? {
|
|
692
659
|
codecId: typeInstance.codecId,
|
|
693
660
|
typeParams: instanceTypeParams
|
|
694
661
|
} : { codecId: typeInstance.codecId });
|
|
@@ -700,7 +667,7 @@ function buildContractCodecRegistry(contract, codecDescriptors) {
|
|
|
700
667
|
nameByKey.set(key, typeName);
|
|
701
668
|
}
|
|
702
669
|
}
|
|
703
|
-
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table)) for (const [columnName, column] of Object.entries(table.columns)) {
|
|
670
|
+
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const [columnName, column] of Object.entries(table.columns)) {
|
|
704
671
|
if (column.typeRef !== void 0) continue;
|
|
705
672
|
const ref = codecDescriptors.codecRefForColumn(namespaceId, tableName, columnName);
|
|
706
673
|
if (!ref) continue;
|
|
@@ -724,7 +691,7 @@ function buildContractCodecRegistry(contract, codecDescriptors) {
|
|
|
724
691
|
usedAt: usedAtByKey.get(key) ?? []
|
|
725
692
|
};
|
|
726
693
|
});
|
|
727
|
-
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table)) for (const columnName of Object.keys(table.columns)) {
|
|
694
|
+
for (const [namespaceId, ns] of Object.entries(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table ?? {})) for (const columnName of Object.keys(table.columns)) {
|
|
728
695
|
const ref = codecDescriptors.codecRefForColumn(namespaceId, tableName, columnName);
|
|
729
696
|
if (!ref) continue;
|
|
730
697
|
resolver.forCodecRef(ref);
|
|
@@ -1134,28 +1101,6 @@ function resolvePreparedSlotValues(ps, userParams) {
|
|
|
1134
1101
|
});
|
|
1135
1102
|
}
|
|
1136
1103
|
//#endregion
|
|
1137
|
-
//#region src/prepared/prepared-statement.ts
|
|
1138
|
-
var PreparedStatementImpl = class {
|
|
1139
|
-
sql;
|
|
1140
|
-
ast;
|
|
1141
|
-
meta;
|
|
1142
|
-
slots;
|
|
1143
|
-
decodeContext;
|
|
1144
|
-
paramMetadata;
|
|
1145
|
-
constructor(internals) {
|
|
1146
|
-
this.sql = internals.sql;
|
|
1147
|
-
this.ast = internals.ast;
|
|
1148
|
-
this.meta = internals.meta;
|
|
1149
|
-
this.slots = internals.slots;
|
|
1150
|
-
this.decodeContext = internals.decodeContext;
|
|
1151
|
-
this.paramMetadata = internals.paramMetadata;
|
|
1152
|
-
Object.freeze(this);
|
|
1153
|
-
}
|
|
1154
|
-
execute(target, params, options) {
|
|
1155
|
-
return target.executePrepared(this, params, options);
|
|
1156
|
-
}
|
|
1157
|
-
};
|
|
1158
|
-
//#endregion
|
|
1159
1104
|
//#region src/sql-family-adapter.ts
|
|
1160
1105
|
var SqlFamilyAdapter = class {
|
|
1161
1106
|
contract;
|
|
@@ -1187,7 +1132,12 @@ const noopLog = {
|
|
|
1187
1132
|
warn: noopLogSink,
|
|
1188
1133
|
error: noopLogSink
|
|
1189
1134
|
};
|
|
1190
|
-
|
|
1135
|
+
/**
|
|
1136
|
+
* Abstract family-layer base for SQL runtimes. Subclass to build a target runtime
|
|
1137
|
+
* (e.g. `PostgresRuntimeImpl`); app code should consume the `Runtime` interface returned
|
|
1138
|
+
* by the target factories, never this class directly.
|
|
1139
|
+
*/
|
|
1140
|
+
var SqlRuntimeBase = class extends RuntimeCore {
|
|
1191
1141
|
contract;
|
|
1192
1142
|
adapter;
|
|
1193
1143
|
driver;
|
|
@@ -1305,6 +1255,15 @@ var SqlRuntimeImpl = class extends RuntimeCore {
|
|
|
1305
1255
|
executePrepared(ps, params, options) {
|
|
1306
1256
|
return this.executePreparedAgainstQueryable(ps, params, this.driver, options);
|
|
1307
1257
|
}
|
|
1258
|
+
/**
|
|
1259
|
+
* Returns the raw driver connection. The connection is a `SqlQueryable` — SQL
|
|
1260
|
+
* issued on it runs below the middleware/codec/telemetry pipeline. It carries
|
|
1261
|
+
* its own lifecycle (`release`/`destroy`/`beginTransaction`); the caller owns
|
|
1262
|
+
* disposal.
|
|
1263
|
+
*/
|
|
1264
|
+
acquireRawConnection() {
|
|
1265
|
+
return this.driver.acquireConnection();
|
|
1266
|
+
}
|
|
1308
1267
|
async *streamRows(exec, decodeContext, driverCall, codecCtx, execMiddlewareCtx) {
|
|
1309
1268
|
this.familyAdapter.validatePlan(exec, this.contract);
|
|
1310
1269
|
this._telemetry = null;
|
|
@@ -1332,6 +1291,11 @@ var SqlRuntimeImpl = class extends RuntimeCore {
|
|
|
1332
1291
|
if (outcome !== null) this.recordTelemetry(exec, outcome, Date.now() - startedAt);
|
|
1333
1292
|
}
|
|
1334
1293
|
}
|
|
1294
|
+
/**
|
|
1295
|
+
* Execute a plan against a caller-supplied queryable, running the full
|
|
1296
|
+
* middleware/codec/telemetry pipeline. Use `acquireRawConnection` to obtain a
|
|
1297
|
+
* queryable that subclasses can bind typed plans to.
|
|
1298
|
+
*/
|
|
1335
1299
|
executeAgainstQueryable(plan, queryable, options) {
|
|
1336
1300
|
this.ensureCodecRegistryValidated();
|
|
1337
1301
|
const self = this;
|
|
@@ -1400,6 +1364,10 @@ var SqlRuntimeImpl = class extends RuntimeCore {
|
|
|
1400
1364
|
paramMetadata
|
|
1401
1365
|
}));
|
|
1402
1366
|
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Execute a prepared statement against a caller-supplied queryable, running
|
|
1369
|
+
* the full middleware/codec/telemetry pipeline.
|
|
1370
|
+
*/
|
|
1403
1371
|
executePreparedAgainstQueryable(ps, userParams, queryable, options) {
|
|
1404
1372
|
this.ensureCodecRegistryValidated();
|
|
1405
1373
|
const self = this;
|
|
@@ -1618,19 +1586,7 @@ async function withTransaction(runtime, fn) {
|
|
|
1618
1586
|
if (!connectionDisposed) await connection.release();
|
|
1619
1587
|
}
|
|
1620
1588
|
}
|
|
1621
|
-
function createRuntime(options) {
|
|
1622
|
-
const { stackInstance, context, driver, verifyMarker, middleware, mode, log } = options;
|
|
1623
|
-
return new SqlRuntimeImpl({
|
|
1624
|
-
context,
|
|
1625
|
-
adapter: stackInstance.adapter,
|
|
1626
|
-
driver,
|
|
1627
|
-
...ifDefined("verifyMarker", verifyMarker),
|
|
1628
|
-
...ifDefined("middleware", middleware),
|
|
1629
|
-
...ifDefined("mode", mode),
|
|
1630
|
-
...ifDefined("log", log)
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
1589
|
//#endregion
|
|
1634
|
-
export {
|
|
1590
|
+
export { PreparedStatementImpl as a, lowerSqlPlan as c, validateContractCodecMappings as d, deriveParamMetadata as f, createSqlExecutionStack as i, extractCodecIds as l, createAstCodecRegistry as m, withTransaction as n, lints as o, encodeParamsWithMetadata as p, createExecutionContext as r, budgets as s, SqlRuntimeBase as t, validateCodecRegistryCompleteness as u };
|
|
1635
1591
|
|
|
1636
|
-
//# sourceMappingURL=exports-
|
|
1592
|
+
//# sourceMappingURL=exports-DJWGwqMq.mjs.map
|