@prisma-next/sql-runtime 0.3.0-pr.71.6 → 0.3.0-pr.71.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.md +1 -2
  2. package/dist/src/codecs/decoding.d.ts +4 -0
  3. package/dist/src/codecs/decoding.d.ts.map +1 -0
  4. package/dist/src/codecs/encoding.d.ts +5 -0
  5. package/dist/src/codecs/encoding.d.ts.map +1 -0
  6. package/dist/src/codecs/validation.d.ts +6 -0
  7. package/dist/src/codecs/validation.d.ts.map +1 -0
  8. package/dist/src/exports/index.d.ts +11 -0
  9. package/dist/src/exports/index.d.ts.map +1 -0
  10. package/dist/src/index.d.ts +2 -0
  11. package/dist/src/index.d.ts.map +1 -0
  12. package/dist/src/lower-sql-plan.d.ts +15 -0
  13. package/dist/src/lower-sql-plan.d.ts.map +1 -0
  14. package/dist/src/sql-context.d.ts +65 -0
  15. package/dist/src/sql-context.d.ts.map +1 -0
  16. package/dist/src/sql-family-adapter.d.ts +10 -0
  17. package/dist/src/sql-family-adapter.d.ts.map +1 -0
  18. package/dist/src/sql-marker.d.ts +22 -0
  19. package/dist/src/sql-marker.d.ts.map +1 -0
  20. package/dist/src/sql-runtime.d.ts +25 -0
  21. package/dist/src/sql-runtime.d.ts.map +1 -0
  22. package/dist/test/utils.d.ts +18 -23
  23. package/dist/test/utils.d.ts.map +1 -0
  24. package/package.json +13 -11
  25. package/src/codecs/decoding.ts +140 -0
  26. package/src/codecs/encoding.ts +76 -0
  27. package/src/codecs/validation.ts +67 -0
  28. package/src/exports/index.ts +38 -0
  29. package/src/index.ts +1 -0
  30. package/src/lower-sql-plan.ts +32 -0
  31. package/src/sql-context.ts +156 -0
  32. package/src/sql-family-adapter.ts +43 -0
  33. package/src/sql-marker.ts +105 -0
  34. package/src/sql-runtime.ts +166 -0
  35. package/test/async-iterable-result.test.ts +136 -0
  36. package/test/sql-context.test.ts +217 -0
  37. package/test/sql-family-adapter.test.ts +86 -0
  38. package/test/sql-runtime.test.ts +155 -0
  39. package/test/utils.ts +262 -0
  40. package/dist/index.d.ts +0 -29
  41. package/dist/sql-runtime-DgEbg2OP.d.ts +0 -109
package/README.md CHANGED
@@ -28,8 +28,7 @@ Execute SQL query Plans with deterministic verification, guardrails, and feedbac
28
28
  ## Dependencies
29
29
 
30
30
  - `@prisma-next/runtime-executor` - Target-neutral execution engine
31
- - `@prisma-next/sql-contract` - SQL contract types
32
- - `@prisma-next/sql-target` - SQL family interfaces (legacy transitional package)
31
+ - `@prisma-next/sql-contract` - SQL contract types (via `@prisma-next/sql-contract/types`)
33
32
  - `@prisma-next/operations` - Operation registry
34
33
 
35
34
  ## Usage
@@ -0,0 +1,4 @@
1
+ import type { ExecutionPlan } from '@prisma-next/contract/types';
2
+ import type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
+ export declare function decodeRow(row: Record<string, unknown>, plan: ExecutionPlan, registry: CodecRegistry): Record<string, unknown>;
4
+ //# sourceMappingURL=decoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"decoding.d.ts","sourceRoot":"","sources":["../../../src/codecs/decoding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAS,aAAa,EAAE,MAAM,sCAAsC,CAAC;AA4BjF,wBAAgB,SAAS,CACvB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC5B,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,aAAa,GACtB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CA0GzB"}
@@ -0,0 +1,5 @@
1
+ import type { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';
2
+ import type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
+ export declare function encodeParam(value: unknown, paramDescriptor: ParamDescriptor, plan: ExecutionPlan, registry: CodecRegistry): unknown;
4
+ export declare function encodeParams(plan: ExecutionPlan, registry: CodecRegistry): readonly unknown[];
5
+ //# sourceMappingURL=encoding.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoding.d.ts","sourceRoot":"","sources":["../../../src/codecs/encoding.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EAAS,aAAa,EAAE,MAAM,sCAAsC,CAAC;AA2BjF,wBAAgB,WAAW,CACzB,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,eAAe,EAChC,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,aAAa,GACtB,OAAO,CAqBT;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,aAAa,GAAG,SAAS,OAAO,EAAE,CAmB7F"}
@@ -0,0 +1,6 @@
1
+ import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
2
+ import type { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
+ export declare function extractCodecIds(contract: SqlContract<SqlStorage>): Set<string>;
4
+ export declare function validateContractCodecMappings(registry: CodecRegistry, contract: SqlContract<SqlStorage>): void;
5
+ export declare function validateCodecRegistryCompleteness(registry: CodecRegistry, contract: SqlContract<SqlStorage>): void;
6
+ //# sourceMappingURL=validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../../../src/codecs/validation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sCAAsC,CAAC;AAE1E,wBAAgB,eAAe,CAAC,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAW9E;AAgBD,wBAAgB,6BAA6B,CAC3C,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,GAChC,IAAI,CAyBN;AAED,wBAAgB,iCAAiC,CAC/C,QAAQ,EAAE,aAAa,EACvB,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,GAChC,IAAI,CAEN"}
@@ -0,0 +1,11 @@
1
+ export type { AfterExecuteResult, BudgetsOptions, LintsOptions, Log, Plugin, PluginContext, } from '@prisma-next/runtime-executor';
2
+ export { budgets, lints } from '@prisma-next/runtime-executor';
3
+ export { extractCodecIds, validateCodecRegistryCompleteness, validateContractCodecMappings, } from '../codecs/validation';
4
+ export { lowerSqlPlan } from '../lower-sql-plan';
5
+ export type { CreateRuntimeContextOptions, RuntimeContext, SqlRuntimeAdapterInstance, SqlRuntimeExtensionDescriptor, SqlRuntimeExtensionInstance, } from '../sql-context';
6
+ export { createRuntimeContext } from '../sql-context';
7
+ export type { SqlStatement } from '../sql-marker';
8
+ export { ensureSchemaStatement, ensureTableStatement, readContractMarker, writeContractMarker, } from '../sql-marker';
9
+ export type { Runtime, RuntimeOptions, RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome, } from '../sql-runtime';
10
+ export { createRuntime } from '../sql-runtime';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/exports/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,kBAAkB,EAClB,cAAc,EACd,YAAY,EACZ,GAAG,EACH,MAAM,EACN,aAAa,GACd,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EACL,eAAe,EACf,iCAAiC,EACjC,6BAA6B,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EACV,2BAA2B,EAC3B,cAAc,EACd,yBAAyB,EACzB,6BAA6B,EAC7B,2BAA2B,GAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,OAAO,EACP,cAAc,EACd,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './exports';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { ExecutionPlan } from '@prisma-next/contract/types';
2
+ import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
3
+ import type { RuntimeContext } from './sql-context';
4
+ /**
5
+ * Lowers a SQL query plan to an executable Plan by calling the adapter's lower method.
6
+ *
7
+ * This function is responsible for converting a lane-produced SqlQueryPlan (which contains
8
+ * AST and params but no SQL) into a fully executable Plan (which includes SQL string).
9
+ *
10
+ * @param context - Runtime context containing the adapter
11
+ * @param queryPlan - SQL query plan from a lane (contains AST, params, meta, but no SQL)
12
+ * @returns Fully executable Plan with SQL string
13
+ */
14
+ export declare function lowerSqlPlan<Row>(context: RuntimeContext, queryPlan: SqlQueryPlan<Row>): ExecutionPlan<Row>;
15
+ //# sourceMappingURL=lower-sql-plan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lower-sql-plan.d.ts","sourceRoot":"","sources":["../../src/lower-sql-plan.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAC1E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEpD;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAC9B,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,YAAY,CAAC,GAAG,CAAC,GAC3B,aAAa,CAAC,GAAG,CAAC,CAcpB"}
@@ -0,0 +1,65 @@
1
+ import type { RuntimeAdapterDescriptor, RuntimeAdapterInstance, RuntimeExtensionDescriptor, RuntimeExtensionInstance, RuntimeTargetDescriptor } from '@prisma-next/core-execution-plane/types';
2
+ import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
3
+ import type { SqlOperationSignature } from '@prisma-next/sql-operations';
4
+ import type { Adapter, CodecRegistry, LoweredStatement, QueryAst } from '@prisma-next/sql-relational-core/ast';
5
+ import type { QueryLaneContext } from '@prisma-next/sql-relational-core/query-lane-context';
6
+ /**
7
+ * SQL runtime extension instance.
8
+ * Extends the framework RuntimeExtensionInstance with SQL-specific hooks
9
+ * for contributing codecs and operations to the runtime context.
10
+ *
11
+ * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
12
+ */
13
+ export interface SqlRuntimeExtensionInstance<TTargetId extends string> extends RuntimeExtensionInstance<'sql', TTargetId> {
14
+ /** Returns codecs to register in the runtime context. */
15
+ codecs?(): CodecRegistry;
16
+ /** Returns operations to register in the runtime context. */
17
+ operations?(): ReadonlyArray<SqlOperationSignature>;
18
+ }
19
+ /**
20
+ * SQL runtime extension descriptor.
21
+ * Extends the framework RuntimeExtensionDescriptor with SQL-specific instance type.
22
+ *
23
+ * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
24
+ */
25
+ export interface SqlRuntimeExtensionDescriptor<TTargetId extends string> extends RuntimeExtensionDescriptor<'sql', TTargetId, SqlRuntimeExtensionInstance<TTargetId>> {
26
+ create(): SqlRuntimeExtensionInstance<TTargetId>;
27
+ }
28
+ /**
29
+ * SQL runtime adapter instance interface.
30
+ * Combines RuntimeAdapterInstance identity with SQL Adapter behavior.
31
+ * The instance IS an Adapter (via intersection), not HAS an adapter property.
32
+ *
33
+ * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
34
+ */
35
+ export type SqlRuntimeAdapterInstance<TTargetId extends string = string> = RuntimeAdapterInstance<'sql', TTargetId> & Adapter<QueryAst, SqlContract<SqlStorage>, LoweredStatement>;
36
+ export interface RuntimeContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> extends QueryLaneContext<TContract> {
37
+ readonly adapter: Adapter<QueryAst, TContract, LoweredStatement> | Adapter<QueryAst, SqlContract<SqlStorage>, LoweredStatement>;
38
+ }
39
+ /**
40
+ * Descriptor-first options for creating a SQL runtime context.
41
+ * Takes the same framework composition as control-plane: target, adapter, extensionPacks.
42
+ *
43
+ * @template TContract - The SQL contract type
44
+ * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
45
+ */
46
+ export interface CreateRuntimeContextOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, TTargetId extends string = string> {
47
+ readonly contract: TContract;
48
+ readonly target: RuntimeTargetDescriptor<'sql', TTargetId>;
49
+ readonly adapter: RuntimeAdapterDescriptor<'sql', TTargetId, SqlRuntimeAdapterInstance<TTargetId>>;
50
+ readonly extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<TTargetId>>;
51
+ }
52
+ /**
53
+ * Creates a SQL runtime context from descriptor-first composition.
54
+ *
55
+ * The context includes:
56
+ * - The validated contract
57
+ * - The adapter instance (created from descriptor)
58
+ * - Codec registry (populated from adapter + extension instances)
59
+ * - Operation registry (populated from extension instances)
60
+ *
61
+ * @param options - Descriptor-first composition options
62
+ * @returns RuntimeContext with registries wired from all components
63
+ */
64
+ export declare function createRuntimeContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, TTargetId extends string = string>(options: CreateRuntimeContextOptions<TContract, TTargetId>): RuntimeContext<TContract>;
65
+ //# sourceM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AC,GAAG,WAAW,CAAC,UAAU,CAAC,CACjG,SAAQ,gBAAgB,CAAC,SAAS,CAAC;IACnC,QAAQ,CAAC,OAAO,EACZ,OAAO,CAAC,QAAQ,EAAE,SAAS,EAAE,gBAAgB,CAAC,GAC9C,OAAO,CAAC,QAAQ,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAAC;CAClE;AAED;;;;;;GAMG;AACH,MAAM,WAAW,2BAA2B,CAC1C,SAAS,SAAS,WAAW,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,EACnE,SAAS,SAAS,MAAM,GAAG,MAAM;IAEjC,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,MAAM,EAAE,uBAAuB,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC;IAC3D,QAAQ,CAAC,OAAO,EAAE,wBAAwB,CACxC,KAAK,EACL,SAAS,EACT,yBAAyB,CAAC,SAAS,CAAC,CACrC,CAAC;IACF,QAAQ,CAAC,cAAc,CAAC,EAAE,aAAa,CAAC,6BAA6B,CAAC,SAAS,CAAC,CAAC,CAAC;CACnF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,WAAW,CAAC,UAAU,CAAC,GAAG,WAAW,CAAC,UAAU,CAAC,EACnE,SAAS,SAAS,MAAM,GAAG,MAAM,EACjC,OAAO,EAAE,2BAA2B,CAAC,SAAS,EAAE,SAAS,CAAC,GAAG,cAAc,CAAC,SAAS,CAAC,CA0CvF"}
@@ -0,0 +1,10 @@
1
+ import type { ExecutionPlan } from '@prisma-next/contract/types';
2
+ import type { MarkerReader, RuntimeFamilyAdapter } from '@prisma-next/runtime-executor';
3
+ import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
4
+ export declare class SqlFamilyAdapter<TContract extends SqlContract<SqlStorage>> implements RuntimeFamilyAdapter<TContract> {
5
+ readonly contract: TContract;
6
+ readonly markerReader: MarkerReader;
7
+ constructor(contract: TContract);
8
+ validatePlan(plan: ExecutionPlan, contract: TContract): void;
9
+ }
10
+ //# sourceMappingURL=sql-family-adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-family-adapter.d.ts","sourceRoot":"","sources":["../../src/sql-family-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EACV,YAAY,EAEZ,oBAAoB,EACrB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAS/E,qBAAa,gBAAgB,CAAC,SAAS,SAAS,WAAW,CAAC,UAAU,CAAC,CACrE,YAAW,oBAAoB,CAAC,SAAS,CAAC;IAE1C,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,YAAY,CAAC;gBAExB,QAAQ,EAAE,SAAS;IAK/B,YAAY,CAAC,IAAI,EAAE,aAAa,EAAE,QAAQ,EAAE,SAAS,GAAG,IAAI;CAe7D"}
@@ -0,0 +1,22 @@
1
+ import type { MarkerStatement } from '@prisma-next/runtime-executor';
2
+ export interface SqlStatement {
3
+ readonly sql: string;
4
+ readonly params: readonly unknown[];
5
+ }
6
+ export interface WriteMarkerInput {
7
+ readonly coreHash: string;
8
+ readonly profileHash: string;
9
+ readonly contractJson?: unknown;
10
+ readonly canonicalVersion?: number;
11
+ readonly appTag?: string;
12
+ readonly meta?: Record<string, unknown>;
13
+ }
14
+ export declare const ensureSchemaStatement: SqlStatement;
15
+ export declare const ensureTableStatement: SqlStatement;
16
+ export declare function readContractMarker(): MarkerStatement;
17
+ export interface WriteContractMarkerStatements {
18
+ readonly insert: SqlStatement;
19
+ readonly update: SqlStatement;
20
+ }
21
+ export declare function writeContractMarker(input: WriteMarkerInput): WriteContractMarkerStatements;
22
+ //# sourceMappingURL=sql-marker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-marker.d.ts","sourceRoot":"","sources":["../../src/sql-marker.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,MAAM,EAAE,SAAS,OAAO,EAAE,CAAC;CACrC;AAED,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;IAChC,QAAQ,CAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACzC;AAED,eAAO,MAAM,qBAAqB,EAAE,YAGnC,CAAC;AAEF,eAAO,MAAM,oBAAoB,EAAE,YAYlC,CAAC;AAEF,wBAAgB,kBAAkB,IAAI,eAAe,CAcpD;AAED,MAAM,WAAW,6BAA6B;IAC5C,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC/B;AAED,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,6BAA6B,CAgD1F"}
@@ -0,0 +1,25 @@
1
+ import type { ExecutionPlan } from '@prisma-next/contract/types';
2
+ import type { OperationRegistry } from '@prisma-next/operations';
3
+ import type { Log, Plugin, RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome } from '@prisma-next/runtime-executor';
4
+ import { AsyncIterableResult } from '@prisma-next/runtime-executor';
5
+ import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
6
+ import type { Adapter, LoweredStatement, SelectAst, SqlDriver } from '@prisma-next/sql-relational-core/ast';
7
+ import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
8
+ import type { RuntimeContext } from './sql-context';
9
+ export interface RuntimeOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
10
+ readonly driver: SqlDriver;
11
+ readonly verify: RuntimeVerifyOptions;
12
+ readonly context: RuntimeContext<TContract>;
13
+ readonly plugins?: readonly Plugin<TContract, Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, SqlDriver>[];
14
+ readonly mode?: 'strict' | 'permissive';
15
+ readonly log?: Log;
16
+ }
17
+ export interface Runtime {
18
+ execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row> | SqlQueryPlan<Row>): AsyncIterableResult<Row>;
19
+ telemetry(): RuntimeTelemetryEvent | null;
20
+ close(): Promise<void>;
21
+ operations(): OperationRegistry;
22
+ }
23
+ export type { RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome };
24
+ export declare function createRuntime<TContract extends SqlContract<SqlStorage>>(options: RuntimeOptions<TContract>): Runtime;
25
+ //# sourceMappingURL=sql-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sql-runtime.d.ts","sourceRoot":"","sources":["../../src/sql-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EACV,GAAG,EACH,MAAM,EAGN,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAqB,MAAM,+BAA+B,CAAC;AACvF,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EACV,OAAO,EAEP,gBAAgB,EAChB,SAA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
1
- import { ExecutionPlan, ResultType } from '@prisma-next/contract/types';
2
- import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
3
- import { Adapter, SelectAst, LoweredStatement } from '@prisma-next/sql-relational-core/ast';
4
- import { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
5
- import { Client } from 'pg';
6
- import { i as createRuntime, d as SqlStatement, a as SqlRuntimeExtensionDescriptor, R as RuntimeContext } from '../sql-runtime-DgEbg2OP.js';
7
- export { DevDatabase, collectAsync, createDevDatabase, teardownTestDatabase, withClient } from '@prisma-next/test-utils';
8
- import '@prisma-next/runtime-executor';
9
- import '@prisma-next/operations';
10
- import '@prisma-next/core-execution-plane/types';
11
- import '@prisma-next/sql-operations';
12
- import '@prisma-next/sql-relational-core/query-lane-context';
13
-
1
+ import type { ExecutionPlan, ResultType } from '@prisma-next/contract/types';
2
+ import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
3
+ import type { Adapter, LoweredStatement, SelectAst } from '@prisma-next/sql-relational-core/ast';
4
+ import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
5
+ import type { Client } from 'pg';
6
+ import type { SqlStatement } from '../src/exports';
7
+ import { type createRuntime } from '../src/exports';
8
+ import type { RuntimeContext, SqlRuntimeExtensionDescriptor } from '../src/sql-context';
14
9
  /**
15
10
  * Executes a plan and collects all results into an array.
16
11
  * This helper DRYs up the common pattern of executing plans in tests.
17
12
  * The return type is inferred from the plan's type parameter.
18
13
  */
19
- declare function executePlanAndCollect<P extends ExecutionPlan<ResultType<P>> | SqlQueryPlan<ResultType<P>>>(runtime: ReturnType<typeof createRuntime>, plan: P): Promise<ResultType<P>[]>;
14
+ export declare function executePlanAndCollect<P extends ExecutionPlan<ResultType<P>> | SqlQueryPlan<ResultType<P>>>(runtime: ReturnType<typeof createRuntime>, plan: P): Promise<ResultType<P>[]>;
20
15
  /**
21
16
  * Drains a plan execution, consuming all results without collecting them.
22
17
  * Useful for testing side effects without memory overhead.
23
18
  */
24
- declare function drainPlanExecution(runtime: ReturnType<typeof createRuntime>, plan: ExecutionPlan | SqlQueryPlan<unknown>): Promise<void>;
19
+ export declare function drainPlanExecution(runtime: ReturnType<typeof createRuntime>, plan: ExecutionPlan | SqlQueryPlan<unknown>): Promise<void>;
25
20
  /**
26
21
  * Executes a SQL statement on a database client.
27
22
  */
28
- declare function executeStatement(client: Client, statement: SqlStatement): Promise<void>;
23
+ export declare function executeStatement(client: Client, statement: SqlStatement): Promise<void>;
29
24
  /**
30
25
  * Sets up database schema and data, then writes the contract marker.
31
26
  * This helper DRYs up the common pattern of database setup in tests.
32
27
  */
33
- declare function setupTestDatabase(client: Client, contract: SqlContract<SqlStorage>, setupFn: (client: Client) => Promise<void>): Promise<void>;
28
+ export declare function setupTestDatabase(client: Client, contract: SqlContract<SqlStorage>, setupFn: (client: Client) => Promise<void>): Promise<void>;
34
29
  /**
35
30
  * Writes a contract marker to the database.
36
31
  * This helper DRYs up the common pattern of writing contract markers in tests.
37
32
  */
38
- declare function writeTestContractMarker(client: Client, contract: SqlContract<SqlStorage>): Promise<void>;
33
+ export declare function writeTestContractMarker(client: Client, contract: SqlContract<SqlStorage>): Promise<void>;
39
34
  /**
40
35
  * Creates a runtime context with standard test configuration.
41
36
  * This helper DRYs up the common pattern of context creation in tests.
@@ -43,7 +38,7 @@ declare function writeTestContractMarker(client: Client, contract: SqlContract<S
43
38
  * Accepts a raw adapter and optional extension descriptors, wrapping the
44
39
  * adapter in a descriptor internally for descriptor-first context creation.
45
40
  */
46
- declare function createTestContext<TContract extends SqlContract<SqlStorage>>(contract: TContract, adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, options?: {
41
+ export declare function createTestContext<TContract extends SqlContract<SqlStorage>>(contract: TContract, adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, options?: {
47
42
  extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;
48
43
  }): RuntimeContext<TContract>;
49
44
  /**
@@ -53,12 +48,12 @@ declare function createTestContext<TContract extends SqlContract<SqlStorage>>(co
53
48
  * The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1)
54
49
  * to enable type inference in tests without requiring the postgres adapter package.
55
50
  */
56
- declare function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>;
51
+ export declare function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>;
57
52
  /**
58
53
  * Creates a valid test contract without using validateContract.
59
54
  * Ensures mappings are present and returns the contract with proper typing.
60
55
  * This helper allows tests to create contracts without depending on sql-query.
61
56
  */
62
- declare function createTestContract<T extends SqlContract<SqlStorage>>(contract: T): T;
63
-
64
- export { createStubAdapter, createTestContext, createTestContract, drainPlanExecution, executePlanAndCollect, executeStatement, setupTestDatabase, writeTestContractMarker };
57
+ export declare function createTestContract<T extends SqlContract<SqlStorage>>(contract: T): T;
58
+ export { collectAsync, createDevDatabase, type DevDatabase, teardownTestDatabase, withClient, } from '@prisma-next/test-utils';
59
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC7E,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC/E,OAAO,KAAK,EAAE,OAAO,EAAE,gBAAgB,EAAE,SAAS,EAAE,MAAM,sCAAsC,CAAC;AAEjG,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uCAAuC,CAAC;AAE1E,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AACjC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EACL,KAAK,aAAa,EAKnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,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6B,CAAC,UAAU,CAAC,CAAC,CAAC;CAC3E,GACA,cAAc,CAAC,SAAS,CAAC,CAO3B;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC,UAAU,CAAC,EAAE,gBAAgB,CAAC,CAmDjG;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,WAAW,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CASpF;AAGD,OAAO,EACL,YAAY,EACZ,iBAAiB,EACjB,KAAK,WAAW,EAChB,oBAAoB,EACpB,UAAU,GACX,MAAM,yBAAyB,CAAC"}
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-runtime",
3
- "version": "0.3.0-pr.71.6",
3
+ "version": "0.3.0-pr.71.8",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "SQL runtime implementation for Prisma Next",
7
7
  "dependencies": {
8
- "@prisma-next/contract": "0.3.0-pr.71.6",
9
- "@prisma-next/core-execution-plane": "0.3.0-pr.71.6",
10
- "@prisma-next/operations": "0.3.0-pr.71.6",
11
- "@prisma-next/runtime-executor": "0.3.0-pr.71.6",
12
- "@prisma-next/sql-contract": "0.3.0-pr.71.6",
13
- "@prisma-next/sql-operations": "0.3.0-pr.71.6",
14
- "@prisma-next/sql-relational-core": "0.3.0-pr.71.6"
8
+ "@prisma-next/contract": "0.3.0-pr.71.8",
9
+ "@prisma-next/core-execution-plane": "0.3.0-pr.71.8",
10
+ "@prisma-next/operations": "0.3.0-pr.71.8",
11
+ "@prisma-next/runtime-executor": "0.3.0-pr.71.8",
12
+ "@prisma-next/sql-contract": "0.3.0-pr.71.8",
13
+ "@prisma-next/sql-operations": "0.3.0-pr.71.8",
14
+ "@prisma-next/sql-relational-core": "0.3.0-pr.71.8"
15
15
  },
16
16
  "devDependencies": {
17
17
  "@types/pg": "8.16.0",
@@ -23,11 +23,13 @@
23
23
  "@prisma-next/test-utils": "0.0.1"
24
24
  },
25
25
  "files": [
26
- "dist"
26
+ "dist",
27
+ "src",
28
+ "test"
27
29
  ],
28
30
  "exports": {
29
31
  ".": {
30
- "types": "./dist/index.d.ts",
32
+ "types": "./dist/src/index.d.ts",
31
33
  "import": "./dist/index.js"
32
34
  },
33
35
  "./test/utils": {
@@ -36,7 +38,7 @@
36
38
  }
37
39
  },
38
40
  "scripts": {
39
- "build": "tsup --config tsup.config.ts",
41
+ "build": "tsup --config tsup.config.ts && tsc --project tsconfig.build.json",
40
42
  "test": "vitest run --passWithNoTests",
41
43
  "test:coverage": "vitest run --coverage --passWithNoTests",
42
44
  "typecheck": "tsc --project tsconfig.json --noEmit",
@@ -0,0 +1,140 @@
1
+ import type { ExecutionPlan } from '@prisma-next/contract/types';
2
+ import type { Codec, CodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
+
4
+ function resolveRowCodec(
5
+ alias: string,
6
+ plan: ExecutionPlan,
7
+ registry: CodecRegistry,
8
+ ): Codec | null {
9
+ const planCodecId = plan.meta.annotations?.codecs?.[alias] as string | undefined;
10
+ if (planCodecId) {
11
+ const codec = registry.get(planCodecId);
12
+ if (codec) {
13
+ return codec;
14
+ }
15
+ }
16
+
17
+ if (plan.meta.projectionTypes) {
18
+ const typeId = plan.meta.projectionTypes[alias];
19
+ if (typeId) {
20
+ const codec = registry.get(typeId);
21
+ if (codec) {
22
+ return codec;
23
+ }
24
+ }
25
+ }
26
+
27
+ return null;
28
+ }
29
+
30
+ export function decodeRow(
31
+ row: Record<string, unknown>,
32
+ plan: ExecutionPlan,
33
+ registry: CodecRegistry,
34
+ ): Record<string, unknown> {
35
+ const decoded: Record<string, unknown> = {};
36
+
37
+ let aliases: readonly string[];
38
+ const projection = plan.meta.projection;
39
+ if (projection && !Array.isArray(projection)) {
40
+ aliases = Object.keys(projection);
41
+ } else if (projection && Array.isArray(projection)) {
42
+ aliases = projection;
43
+ } else {
44
+ aliases = Object.keys(row);
45
+ }
46
+
47
+ for (const alias of aliases) {
48
+ const wireValue = row[alias];
49
+
50
+ const projection = plan.meta.projection;
51
+ const projectionValue =
52
+ projection && typeof projection === 'object' && !Array.isArray(projection)
53
+ ? (projection as Record<string, string>)[alias]
54
+ : undefined;
55
+
56
+ if (typeof projectionValue === 'string' && projectionValue.startsWith('include:')) {
57
+ if (wireValue === null || wireValue === undefined) {
58
+ decoded[alias] = [];
59
+ continue;
60
+ }
61
+
62
+ try {
63
+ let parsed: unknown;
64
+ if (typeof wireValue === 'string') {
65
+ parsed = JSON.parse(wireValue);
66
+ } else if (Array.isArray(wireValue)) {
67
+ parsed = wireValue;
68
+ } else {
69
+ parsed = JSON.parse(String(wireValue));
70
+ }
71
+
72
+ if (!Array.isArray(parsed)) {
73
+ throw new Error(`Expected array for include alias '${alias}', got ${typeof parsed}`);
74
+ }
75
+
76
+ decoded[alias] = parsed;
77
+ } catch (error) {
78
+ const decodeError = new Error(
79
+ `Failed to parse JSON array for include alias '${alias}': ${error instanceof Error ? error.message : String(error)}`,
80
+ ) as Error & {
81
+ code: string;
82
+ category: string;
83
+ severity: string;
84
+ details?: Record<string, unknown>;
85
+ };
86
+ decodeError.code = 'RUNTIME.DECODE_FAILED';
87
+ decodeError.category = 'RUNTIME';
88
+ decodeError.severity = 'error';
89
+ decodeError.details = {
90
+ alias,
91
+ wirePreview:
92
+ typeof wireValue === 'string' && wireValue.length > 100
93
+ ? `${wireValue.substring(0, 100)}...`
94
+ : String(wireValue).substring(0, 100),
95
+ };
96
+ throw decodeError;
97
+ }
98
+ continue;
99
+ }
100
+
101
+ if (wireValue === null || wireValue === undefined) {
102
+ decoded[alias] = wireValue;
103
+ continue;
104
+ }
105
+
106
+ const codec = resolveRowCodec(alias, plan, registry);
107
+
108
+ if (!codec) {
109
+ decoded[alias] = wireValue;
110
+ continue;
111
+ }
112
+
113
+ try {
114
+ decoded[alias] = codec.decode(wireValue);
115
+ } catch (error) {
116
+ const decodeError = new Error(
117
+ `Failed to decode row alias '${alias}' with codec '${codec.id}': ${error instanceof Error ? error.message : String(error)}`,
118
+ ) as Error & {
119
+ code: string;
120
+ category: string;
121
+ severity: string;
122
+ details?: Record<string, unknown>;
123
+ };
124
+ decodeError.code = 'RUNTIME.DECODE_FAILED';
125
+ decodeError.category = 'RUNTIME';
126
+ decodeError.severity = 'error';
127
+ decodeError.details = {
128
+ alias,
129
+ codec: codec.id,
130
+ wirePreview:
131
+ typeof wireValue === 'string' && wireValue.length > 100
132
+ ? `${wireValue.substring(0, 100)}...`
133
+ : String(wireValue).substring(0, 100),
134
+ };
135
+ throw decodeError;
136
+ }
137
+ }
138
+
139
+ return decoded;
140
+ }
@@ -0,0 +1,76 @@
1
+ import type { ExecutionPlan, ParamDescriptor } from '@prisma-next/contract/types';
2
+ import type { Codec, CodecRegistry } from '@prisma-next/sql-relational-core/ast';
3
+
4
+ function resolveParamCodec(
5
+ paramDescriptor: ParamDescriptor,
6
+ plan: ExecutionPlan,
7
+ registry: CodecRegistry,
8
+ ): Codec | null {
9
+ const paramName = paramDescriptor.name ?? `param_${paramDescriptor.index ?? 0}`;
10
+
11
+ const planCodecId = plan.meta.annotations?.codecs?.[paramName] as string | undefined;
12
+ if (planCodecId) {
13
+ const codec = registry.get(planCodecId);
14
+ if (codec) {
15
+ return codec;
16
+ }
17
+ }
18
+
19
+ if (paramDescriptor.codecId) {
20
+ const codec = registry.get(paramDescriptor.codecId);
21
+ if (codec) {
22
+ return codec;
23
+ }
24
+ }
25
+
26
+ return null;
27
+ }
28
+
29
+ export function encodeParam(
30
+ value: unknown,
31
+ paramDescriptor: ParamDescriptor,
32
+ plan: ExecutionPlan,
33
+ registry: CodecRegistry,
34
+ ): unknown {
35
+ if (value === null || value === undefined) {
36
+ return null;
37
+ }
38
+
39
+ const codec = resolveParamCodec(paramDescriptor, plan, registry);
40
+ if (!codec) {
41
+ return value;
42
+ }
43
+
44
+ if (codec.encode) {
45
+ try {
46
+ return codec.encode(value);
47
+ } catch (error) {
48
+ throw new Error(
49
+ `Failed to encode parameter ${paramDescriptor.name ?? paramDescriptor.index}: ${error instanceof Error ? error.message : String(error)}`,
50
+ );
51
+ }
52
+ }
53
+
54
+ return value;
55
+ }
56
+
57
+ export function encodeParams(plan: ExecutionPlan, registry: CodecRegistry): readonly unknown[] {
58
+ if (plan.params.length === 0) {
59
+ return plan.params;
60
+ }
61
+
62
+ const encoded: unknown[] = [];
63
+
64
+ for (let i = 0; i < plan.params.length; i++) {
65
+ const paramValue = plan.params[i];
66
+ const paramDescriptor = plan.meta.paramDescriptors[i];
67
+
68
+ if (paramDescriptor) {
69
+ encoded.push(encodeParam(paramValue, paramDescriptor, plan, registry));
70
+ } else {
71
+ encoded.push(paramValue);
72
+ }
73
+ }
74
+
75
+ return Object.freeze(encoded);
76
+ }