@prisma-next/sql-runtime 0.13.0-dev.4 → 0.13.0-dev.40

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 CHANGED
@@ -41,52 +41,31 @@ Execute SQL query Plans with deterministic verification, guardrails, and feedbac
41
41
 
42
42
  ## Usage
43
43
 
44
- ```typescript
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
- // Static context (no instantiation needed)
66
- const context = createExecutionContext({ contract, stack });
67
-
68
- // Dynamic runtime
69
- const stackInstance = instantiateExecutionStack(stack);
70
- const driver = stack.driver.create({ connect: { connectionString: process.env.DATABASE_URL } });
71
- const runtime = createRuntime({
72
- stackInstance,
73
- context,
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
- Use `verifyMarker: false` to skip the marker read entirely — e.g. during a known-skewed deploy window where contract drift is expected and tolerated.
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 runtime = createRuntime({
87
- stackInstance,
88
- context,
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
- - `createRuntime` - Create a SQL runtime instance
100
- - `Runtime` - Runtime instance type
101
- - `CreateRuntimeOptions` - Options for `createRuntime`
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 { createRuntime, lints } from '@prisma-next/sql-runtime';
141
+ import postgres from '@prisma-next/postgres';
142
+ import { lints } from '@prisma-next/sql-runtime';
163
143
 
164
- const runtime = createRuntime({
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 SqlRuntimeImpl 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`).
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 { AsyncIterableResult, RuntimeCore, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeError } from "@prisma-next/framework-components/runtime";
1
+ import { materializeCodec, resolveCodecDescriptorOrThrow } from "@prisma-next/framework-components/codec";
2
2
  import { canonicalizeJson } from "@prisma-next/framework-components/utils";
3
+ import { AsyncIterableResult, RuntimeCore, checkAborted, checkMiddlewareCompatibility, isRuntimeError, raceAgainstAbort, runBeforeExecuteChain, runWithMiddleware, runtimeError } from "@prisma-next/framework-components/runtime";
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";
@@ -24,33 +24,11 @@ function createAstCodecResolver(descriptors, instanceContextFor) {
24
24
  const key = `${ref.codecId}:${canonicalizeJson(ref.typeParams)}`;
25
25
  const cached = cache.get(key);
26
26
  if (cached) return cached;
27
- const descriptor = descriptors.descriptorFor(ref.codecId);
28
- if (!descriptor) throw runtimeError("RUNTIME.CODEC_DESCRIPTOR_MISSING", `No codec descriptor registered for codecId '${ref.codecId}'.`, { codecId: ref.codecId });
29
- const validated = validateTypeParams$1(descriptor.paramsSchema, descriptor.isParameterized && ref.typeParams === void 0 ? {
30
- ...ref,
31
- typeParams: {}
32
- } : ref);
33
- const ctx = instanceContextFor(ref);
34
- const codec = descriptor.factory(validated)(ctx);
27
+ const codec = materializeCodec(resolveCodecDescriptorOrThrow((id) => descriptors.descriptorFor(id), ref, "RUNTIME.CODEC_DESCRIPTOR_MISSING"), ref, instanceContextFor(ref));
35
28
  cache.set(key, codec);
36
29
  return codec;
37
30
  } };
38
31
  }
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
32
  //#endregion
55
33
  //#region src/codecs/ast-codec-registry.ts
56
34
  /**
@@ -137,40 +115,30 @@ async function encodeParamsWithMetadata(values, metadata, ctx, contractCodecs) {
137
115
  //#region src/codecs/validation.ts
138
116
  function extractCodecIds(contract) {
139
117
  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)) {
118
+ 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
119
  const codecId = column.codecId;
142
120
  codecIds.add(codecId);
143
121
  }
144
122
  return codecIds;
145
123
  }
146
- function extractCodecIdsFromColumns(contract) {
147
- const codecIds = /* @__PURE__ */ new Map();
148
- for (const ns of Object.values(contract.storage.namespaces)) for (const [tableName, table] of Object.entries(ns.entries.table)) for (const [columnName, column] of Object.entries(table.columns)) {
149
- const codecId = column.codecId;
150
- const key = `${tableName}.${columnName}`;
151
- codecIds.set(key, codecId);
152
- }
153
- return codecIds;
124
+ function extractColumnCodecRefs(contract) {
125
+ const refs = [];
126
+ 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({
127
+ namespaceId,
128
+ table: tableName,
129
+ column: columnName,
130
+ codecId: column.codecId
131
+ });
132
+ return refs;
154
133
  }
155
134
  function validateContractCodecMappings(registry, contract) {
156
- const codecIds = extractCodecIdsFromColumns(contract);
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
- }
135
+ const invalidCodecs = extractColumnCodecRefs(contract).filter((ref) => registry.descriptorFor(ref.codecId) === void 0);
168
136
  if (invalidCodecs.length > 0) {
169
137
  const details = {
170
138
  contractTarget: contract.target,
171
139
  invalidCodecs
172
140
  };
173
- throw runtimeError("RUNTIME.CODEC_MISSING", `Missing codec implementations for column codecIds: ${invalidCodecs.map((c) => `${c.table}.${c.column} (${c.codecId})`).join(", ")}`, details);
141
+ 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
142
  }
175
143
  }
176
144
  function validateCodecRegistryCompleteness(registry, contract) {
@@ -210,16 +178,19 @@ function hasAggregateWithoutGroupBy(ast) {
210
178
  return ast.projection.some((item) => item.expr.kind === "aggregate");
211
179
  }
212
180
  function primaryTableFromAst(ast) {
181
+ if (ast.from === void 0) return void 0;
213
182
  switch (ast.from.kind) {
214
183
  case "table-source": return ast.from.name;
215
184
  case "derived-table-source": return ast.from.alias;
185
+ case "function-source": return ast.from.fn;
216
186
  // v8 ignore next 4
217
187
  default: throw new Error(`Unsupported source kind: ${ast.from.kind}`);
218
188
  }
219
189
  }
220
190
  function estimateRowsFromAst(ast, tableRows, defaultTableRows, hasAggregateWithoutGroup) {
221
191
  if (hasAggregateWithoutGroup) return 1;
222
- const tableEstimate = tableRows[primaryTableFromAst(ast)] ?? defaultTableRows;
192
+ const primaryTable = primaryTableFromAst(ast);
193
+ const tableEstimate = (primaryTable !== void 0 ? tableRows[primaryTable] : void 0) ?? defaultTableRows;
223
194
  if (typeof ast.limit === "number") return Math.min(ast.limit, tableEstimate);
224
195
  return tableEstimate;
225
196
  }
@@ -371,6 +342,7 @@ function getFromSourceTableDetail(source) {
371
342
  switch (source.kind) {
372
343
  case "table-source": return source.name;
373
344
  case "derived-table-source": return source.alias;
345
+ case "function-source": return source.fn;
374
346
  // v8 ignore next 4
375
347
  default: throw new Error(`Unsupported source kind: ${source.kind}`);
376
348
  }
@@ -396,7 +368,7 @@ function evaluateAstLints(ast) {
396
368
  break;
397
369
  case "select":
398
370
  if (ast.limit === void 0) {
399
- const table = getFromSourceTableDetail(ast.from);
371
+ const table = ast.from !== void 0 ? getFromSourceTableDetail(ast.from) : void 0;
400
372
  findings.push({
401
373
  code: "LINT.NO_LIMIT",
402
374
  severity: "warn",
@@ -472,6 +444,28 @@ function lints(options) {
472
444
  });
473
445
  }
474
446
  //#endregion
447
+ //#region src/prepared/prepared-statement.ts
448
+ var PreparedStatementImpl = class {
449
+ sql;
450
+ ast;
451
+ meta;
452
+ slots;
453
+ decodeContext;
454
+ paramMetadata;
455
+ constructor(internals) {
456
+ this.sql = internals.sql;
457
+ this.ast = internals.ast;
458
+ this.meta = internals.meta;
459
+ this.slots = internals.slots;
460
+ this.decodeContext = internals.decodeContext;
461
+ this.paramMetadata = internals.paramMetadata;
462
+ Object.freeze(this);
463
+ }
464
+ execute(target, params, options) {
465
+ return target.executePrepared(this, params, options);
466
+ }
467
+ };
468
+ //#endregion
475
469
  //#region src/sql-context.ts
476
470
  function documentScopedCodecTypes(contract) {
477
471
  return blindCast(contract.storage.types);
@@ -509,25 +503,6 @@ function assertExecutionStackContractRequirements(contract, stack) {
509
503
  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
504
  }
511
505
  }
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
506
  function validateTypeParams(typeParams, descriptor, context) {
532
507
  const result = descriptor.paramsSchema["~standard"].validate(typeParams);
533
508
  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 +542,7 @@ function collectCodecDescriptors(contributors) {
567
542
  }
568
543
  function collectTypeRefSites(storage) {
569
544
  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)) {
545
+ 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
546
  if (typeof column.typeRef !== "string") continue;
572
547
  const list = sites.get(column.typeRef);
573
548
  const entry = {
@@ -584,9 +559,8 @@ function initializeTypeHelpers(storage, documentTypes, codecDescriptors) {
584
559
  if (!documentTypes) return helpers;
585
560
  const typeRefSites = collectTypeRefSites(storage);
586
561
  for (const [typeName, typeInstance] of Object.entries(documentTypes)) {
587
- const enumView = readEnumViewIfApplicable(typeInstance);
588
- const codecId = enumView ? enumView.codecId : typeInstance.codecId;
589
- const typeParams = enumView ? enumView.typeParams : typeInstance.typeParams;
562
+ const codecId = typeInstance.codecId;
563
+ const typeParams = typeInstance.typeParams;
590
564
  const descriptor = codecDescriptors.get(codecId);
591
565
  if (!descriptor) {
592
566
  helpers[typeName] = typeInstance;
@@ -602,7 +576,7 @@ function initializeTypeHelpers(storage, documentTypes, codecDescriptors) {
602
576
  return helpers;
603
577
  }
604
578
  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) {
579
+ 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
580
  const descriptor = codecDescriptors.get(column.codecId);
607
581
  if (descriptor) validateTypeParams(column.typeParams, descriptor, {
608
582
  tableName,
@@ -622,7 +596,7 @@ function validateColumnTypeParams(storage, codecDescriptors) {
622
596
  * 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
597
  */
624
598
  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)) {
599
+ 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
600
  const ref = codecDescriptors.codecRefForColumn(namespaceId, tableName, columnName);
627
601
  if (!ref) continue;
628
602
  const descriptor = codecDescriptors.descriptorFor(ref.codecId);
@@ -682,13 +656,8 @@ function buildContractCodecRegistry(contract, codecDescriptors) {
682
656
  const nameByKey = /* @__PURE__ */ new Map();
683
657
  const typeRefSites = collectTypeRefSites(contract.storage);
684
658
  for (const [typeName, typeInstance] of Object.entries(documentScopedCodecTypes(contract) ?? {})) {
685
- const enumView = readEnumViewIfApplicable(typeInstance);
686
- const instanceTypeParams = enumView ? enumView.typeParams : typeInstance.typeParams;
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 ? {
659
+ const instanceTypeParams = typeInstance.typeParams;
660
+ const key = refKeyOf(instanceTypeParams !== void 0 && Object.keys(instanceTypeParams).length > 0 ? {
692
661
  codecId: typeInstance.codecId,
693
662
  typeParams: instanceTypeParams
694
663
  } : { codecId: typeInstance.codecId });
@@ -700,7 +669,7 @@ function buildContractCodecRegistry(contract, codecDescriptors) {
700
669
  nameByKey.set(key, typeName);
701
670
  }
702
671
  }
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)) {
672
+ 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
673
  if (column.typeRef !== void 0) continue;
705
674
  const ref = codecDescriptors.codecRefForColumn(namespaceId, tableName, columnName);
706
675
  if (!ref) continue;
@@ -724,7 +693,7 @@ function buildContractCodecRegistry(contract, codecDescriptors) {
724
693
  usedAt: usedAtByKey.get(key) ?? []
725
694
  };
726
695
  });
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)) {
696
+ 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
697
  const ref = codecDescriptors.codecRefForColumn(namespaceId, tableName, columnName);
729
698
  if (!ref) continue;
730
699
  resolver.forCodecRef(ref);
@@ -1134,28 +1103,6 @@ function resolvePreparedSlotValues(ps, userParams) {
1134
1103
  });
1135
1104
  }
1136
1105
  //#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
1106
  //#region src/sql-family-adapter.ts
1160
1107
  var SqlFamilyAdapter = class {
1161
1108
  contract;
@@ -1187,7 +1134,12 @@ const noopLog = {
1187
1134
  warn: noopLogSink,
1188
1135
  error: noopLogSink
1189
1136
  };
1190
- var SqlRuntimeImpl = class extends RuntimeCore {
1137
+ /**
1138
+ * Abstract family-layer base for SQL runtimes. Subclass to build a target runtime
1139
+ * (e.g. `PostgresRuntimeImpl`); app code should consume the `Runtime` interface returned
1140
+ * by the target factories, never this class directly.
1141
+ */
1142
+ var SqlRuntimeBase = class extends RuntimeCore {
1191
1143
  contract;
1192
1144
  adapter;
1193
1145
  driver;
@@ -1305,6 +1257,15 @@ var SqlRuntimeImpl = class extends RuntimeCore {
1305
1257
  executePrepared(ps, params, options) {
1306
1258
  return this.executePreparedAgainstQueryable(ps, params, this.driver, options);
1307
1259
  }
1260
+ /**
1261
+ * Returns the raw driver connection. The connection is a `SqlQueryable` — SQL
1262
+ * issued on it runs below the middleware/codec/telemetry pipeline. It carries
1263
+ * its own lifecycle (`release`/`destroy`/`beginTransaction`); the caller owns
1264
+ * disposal.
1265
+ */
1266
+ acquireRawConnection() {
1267
+ return this.driver.acquireConnection();
1268
+ }
1308
1269
  async *streamRows(exec, decodeContext, driverCall, codecCtx, execMiddlewareCtx) {
1309
1270
  this.familyAdapter.validatePlan(exec, this.contract);
1310
1271
  this._telemetry = null;
@@ -1332,6 +1293,11 @@ var SqlRuntimeImpl = class extends RuntimeCore {
1332
1293
  if (outcome !== null) this.recordTelemetry(exec, outcome, Date.now() - startedAt);
1333
1294
  }
1334
1295
  }
1296
+ /**
1297
+ * Execute a plan against a caller-supplied queryable, running the full
1298
+ * middleware/codec/telemetry pipeline. Use `acquireRawConnection` to obtain a
1299
+ * queryable that subclasses can bind typed plans to.
1300
+ */
1335
1301
  executeAgainstQueryable(plan, queryable, options) {
1336
1302
  this.ensureCodecRegistryValidated();
1337
1303
  const self = this;
@@ -1400,6 +1366,10 @@ var SqlRuntimeImpl = class extends RuntimeCore {
1400
1366
  paramMetadata
1401
1367
  }));
1402
1368
  }
1369
+ /**
1370
+ * Execute a prepared statement against a caller-supplied queryable, running
1371
+ * the full middleware/codec/telemetry pipeline.
1372
+ */
1403
1373
  executePreparedAgainstQueryable(ps, userParams, queryable, options) {
1404
1374
  this.ensureCodecRegistryValidated();
1405
1375
  const self = this;
@@ -1618,19 +1588,7 @@ async function withTransaction(runtime, fn) {
1618
1588
  if (!connectionDisposed) await connection.release();
1619
1589
  }
1620
1590
  }
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
1591
  //#endregion
1634
- export { lints as a, extractCodecIds as c, deriveParamMetadata as d, encodeParamsWithMetadata as f, createSqlExecutionStack as i, validateCodecRegistryCompleteness as l, withTransaction as n, budgets as o, createAstCodecRegistry as p, createExecutionContext as r, lowerSqlPlan as s, createRuntime as t, validateContractCodecMappings as u };
1592
+ 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
1593
 
1636
- //# sourceMappingURL=exports-DDqF-xmg.mjs.map
1594
+ //# sourceMappingURL=exports-69rais4r.mjs.map