@prisma-next/sql-runtime 0.3.0-dev.2 → 0.3.0-dev.20

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 (47) hide show
  1. package/README.md +1 -2
  2. package/dist/{accelerate-EEKAFGN3-SHR4XFVV.js → accelerate-EEKAFGN3-P6A6XJWJ.js} +28 -28
  3. package/dist/{accelerate-EEKAFGN3-SHR4XFVV.js.map → accelerate-EEKAFGN3-P6A6XJWJ.js.map} +1 -1
  4. package/dist/{dist-LCVVJCGI.js → dist-AQ3LWXOX.js} +13 -13
  5. package/dist/{dist-LCVVJCGI.js.map → dist-AQ3LWXOX.js.map} +1 -1
  6. package/dist/src/codecs/decoding.d.ts +4 -0
  7. package/dist/src/codecs/decoding.d.ts.map +1 -0
  8. package/dist/src/codecs/encoding.d.ts +5 -0
  9. package/dist/src/codecs/encoding.d.ts.map +1 -0
  10. package/dist/src/codecs/validation.d.ts +6 -0
  11. package/dist/src/codecs/validation.d.ts.map +1 -0
  12. package/dist/src/exports/index.d.ts +11 -0
  13. package/dist/src/exports/index.d.ts.map +1 -0
  14. package/dist/src/index.d.ts +2 -0
  15. package/dist/src/index.d.ts.map +1 -0
  16. package/dist/src/lower-sql-plan.d.ts +15 -0
  17. package/dist/src/lower-sql-plan.d.ts.map +1 -0
  18. package/dist/src/sql-context.d.ts +65 -0
  19. package/dist/src/sql-context.d.ts.map +1 -0
  20. package/dist/src/sql-family-adapter.d.ts +10 -0
  21. package/dist/src/sql-family-adapter.d.ts.map +1 -0
  22. package/dist/src/sql-marker.d.ts +22 -0
  23. package/dist/src/sql-marker.d.ts.map +1 -0
  24. package/dist/src/sql-runtime.d.ts +25 -0
  25. package/dist/src/sql-runtime.d.ts.map +1 -0
  26. package/dist/test/utils.d.ts +20 -24
  27. package/dist/test/utils.d.ts.map +1 -0
  28. package/dist/test/utils.js +25 -25
  29. package/dist/test/utils.js.map +1 -1
  30. package/package.json +21 -20
  31. package/src/codecs/decoding.ts +140 -0
  32. package/src/codecs/encoding.ts +76 -0
  33. package/src/codecs/validation.ts +67 -0
  34. package/src/exports/index.ts +38 -0
  35. package/src/index.ts +1 -0
  36. package/src/lower-sql-plan.ts +32 -0
  37. package/src/sql-context.ts +156 -0
  38. package/src/sql-family-adapter.ts +43 -0
  39. package/src/sql-marker.ts +105 -0
  40. package/src/sql-runtime.ts +166 -0
  41. package/test/async-iterable-result.test.ts +136 -0
  42. package/test/sql-context.test.ts +217 -0
  43. package/test/sql-family-adapter.test.ts +86 -0
  44. package/test/sql-runtime.test.ts +155 -0
  45. package/test/utils.ts +266 -0
  46. package/dist/index.d.ts +0 -29
  47. package/dist/sql-runtime-DgEbg2OP.d.ts +0 -109
@@ -0,0 +1,155 @@
1
+ import { createOperationRegistry } from '@prisma-next/operations';
2
+ import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
3
+ import type {
4
+ CodecRegistry,
5
+ SelectAst,
6
+ SqlDriver,
7
+ SqlExecuteRequest,
8
+ } from '@prisma-next/sql-relational-core/ast';
9
+ import { codec, createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
10
+ import { describe, expect, it, vi } from 'vitest';
11
+ import type { RuntimeContext } from '../src/sql-context';
12
+ import { createRuntime } from '../src/sql-runtime';
13
+
14
+ // Minimal test contract
15
+ const testContract: SqlContract<SqlStorage> = {
16
+ schemaVersion: '1',
17
+ targetFamily: 'sql',
18
+ target: 'postgres',
19
+ coreHash: 'sha256:test',
20
+ models: {},
21
+ relations: {},
22
+ storage: { tables: {} },
23
+ extensionPacks: {},
24
+ capabilities: {},
25
+ meta: {},
26
+ sources: {},
27
+ mappings: {
28
+ codecTypes: {},
29
+ operationTypes: {},
30
+ },
31
+ };
32
+
33
+ // Create a stub codec registry
34
+ function createStubCodecs(): CodecRegistry {
35
+ const registry = createCodecRegistry();
36
+ registry.register(
37
+ codec({
38
+ typeId: 'pg/int4@1',
39
+ targetTypes: ['int4'],
40
+ encode: (v: number) => v,
41
+ decode: (w: number) => w,
42
+ }),
43
+ );
44
+ return registry;
45
+ }
46
+
47
+ // Create a stub adapter
48
+ function createStubAdapter() {
49
+ const codecs = createStubCodecs();
50
+ return {
51
+ familyId: 'sql' as const,
52
+ targetId: 'postgres' as const,
53
+ profile: {
54
+ id: 'test-profile',
55
+ target: 'postgres',
56
+ capabilities: {},
57
+ codecs() {
58
+ return codecs;
59
+ },
60
+ },
61
+ lower(ast: SelectAst) {
62
+ return {
63
+ profileId: 'test-profile',
64
+ body: Object.freeze({ sql: JSON.stringify(ast), params: [] }),
65
+ };
66
+ },
67
+ };
68
+ }
69
+
70
+ // Create a mock driver that implements SqlDriver interface
71
+ function createMockDriver(): SqlDriver {
72
+ const execute = vi.fn().mockImplementation(async function* (_request: SqlExecuteRequest) {
73
+ yield { id: 1 };
74
+ });
75
+
76
+ return {
77
+ connect: vi.fn().mockResolvedValue(undefined),
78
+ execute,
79
+ query: vi.fn().mockResolvedValue({ rows: [], rowCount: 0 }),
80
+ close: vi.fn().mockResolvedValue(undefined),
81
+ };
82
+ }
83
+
84
+ // Create a test runtime context
85
+ function createTestContext(contract: SqlContract<SqlStorage>): RuntimeContext<typeof contract> {
86
+ const adapter = createStubAdapter();
87
+ return {
88
+ contract,
89
+ adapter,
90
+ codecs: adapter.profile.codecs(),
91
+ operations: createOperationRegistry(),
92
+ };
93
+ }
94
+
95
+ describe('createRuntime', () => {
96
+ it('creates runtime with valid options', () => {
97
+ const context = createTestContext(testContract);
98
+ const driver = createMockDriver();
99
+
100
+ const runtime = createRuntime({
101
+ context,
102
+ driver,
103
+ verify: { mode: 'onFirstUse', requireMarker: false },
104
+ });
105
+
106
+ expect(runtime).toBeDefined();
107
+ expect(runtime.execute).toBeDefined();
108
+ expect(runtime.telemetry).toBeDefined();
109
+ expect(runtime.operations).toBeDefined();
110
+ expect(runtime.close).toBeDefined();
111
+ });
112
+
113
+ it('returns operations registry', () => {
114
+ const context = createTestContext(testContract);
115
+ const driver = createMockDriver();
116
+
117
+ const runtime = createRuntime({
118
+ context,
119
+ driver,
120
+ verify: { mode: 'onFirstUse', requireMarker: false },
121
+ });
122
+
123
+ const ops = runtime.operations();
124
+ expect(ops).toBeDefined();
125
+ expect(ops.byType).toBeDefined();
126
+ });
127
+
128
+ it('returns null telemetry when no events', () => {
129
+ const context = createTestContext(testContract);
130
+ const driver = createMockDriver();
131
+
132
+ const runtime = createRuntime({
133
+ context,
134
+ driver,
135
+ verify: { mode: 'onFirstUse', requireMarker: false },
136
+ });
137
+
138
+ // Before any execution, telemetry should be null
139
+ expect(runtime.telemetry()).toBeNull();
140
+ });
141
+
142
+ it('closes runtime', async () => {
143
+ const context = createTestContext(testContract);
144
+ const driver = createMockDriver();
145
+
146
+ const runtime = createRuntime({
147
+ context,
148
+ driver,
149
+ verify: { mode: 'onFirstUse', requireMarker: false },
150
+ });
151
+
152
+ await runtime.close();
153
+ expect(driver.close).toHaveBeenCalled();
154
+ });
155
+ });
package/test/utils.ts ADDED
@@ -0,0 +1,266 @@
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 { codec, createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
5
+ import type { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
6
+ import { collectAsync, drainAsyncIterable } from '@prisma-next/test-utils';
7
+ import type { Client } from 'pg';
8
+ import type { SqlStatement } from '../src/exports';
9
+ import {
10
+ type createRuntime,
11
+ createRuntimeContext,
12
+ ensureSchemaStatement,
13
+ ensureTableStatement,
14
+ writeContractMarker,
15
+ } from '../src/exports';
16
+ import type {
17
+ RuntimeContext,
18
+ SqlRuntimeAdapterInstance,
19
+ SqlRuntimeExtensionDescriptor,
20
+ } from '../src/sql-context';
21
+
22
+ /**
23
+ * Executes a plan and collects all results into an array.
24
+ * This helper DRYs up the common pattern of executing plans in tests.
25
+ * The return type is inferred from the plan's type parameter.
26
+ */
27
+ export async function executePlanAndCollect<
28
+ P extends ExecutionPlan<ResultType<P>> | SqlQueryPlan<ResultType<P>>,
29
+ >(runtime: ReturnType<typeof createRuntime>, plan: P): Promise<ResultType<P>[]> {
30
+ type Row = ResultType<P>;
31
+ return collectAsync<Row>(runtime.execute<Row>(plan));
32
+ }
33
+
34
+ /**
35
+ * Drains a plan execution, consuming all results without collecting them.
36
+ * Useful for testing side effects without memory overhead.
37
+ */
38
+ export async function drainPlanExecution(
39
+ runtime: ReturnType<typeof createRuntime>,
40
+ plan: ExecutionPlan | SqlQueryPlan<unknown>,
41
+ ): Promise<void> {
42
+ return drainAsyncIterable(runtime.execute(plan));
43
+ }
44
+
45
+ /**
46
+ * Executes a SQL statement on a database client.
47
+ */
48
+ export async function executeStatement(client: Client, statement: SqlStatement): Promise<void> {
49
+ if (statement.params.length > 0) {
50
+ await client.query(statement.sql, [...statement.params]);
51
+ return;
52
+ }
53
+
54
+ await client.query(statement.sql);
55
+ }
56
+
57
+ /**
58
+ * Sets up database schema and data, then writes the contract marker.
59
+ * This helper DRYs up the common pattern of database setup in tests.
60
+ */
61
+ export async function setupTestDatabase(
62
+ client: Client,
63
+ contract: SqlContract<SqlStorage>,
64
+ setupFn: (client: Client) => Promise<void>,
65
+ ): Promise<void> {
66
+ await client.query('drop schema if exists prisma_contract cascade');
67
+ await client.query('create schema if not exists public');
68
+
69
+ await setupFn(client);
70
+
71
+ await executeStatement(client, ensureSchemaStatement);
72
+ await executeStatement(client, ensureTableStatement);
73
+ const write = writeContractMarker({
74
+ coreHash: contract.coreHash,
75
+ profileHash: contract.profileHash ?? contract.coreHash,
76
+ contractJson: contract,
77
+ canonicalVersion: 1,
78
+ });
79
+ await executeStatement(client, write.insert);
80
+ }
81
+
82
+ /**
83
+ * Writes a contract marker to the database.
84
+ * This helper DRYs up the common pattern of writing contract markers in tests.
85
+ */
86
+ export async function writeTestContractMarker(
87
+ client: Client,
88
+ contract: SqlContract<SqlStorage>,
89
+ ): Promise<void> {
90
+ const write = writeContractMarker({
91
+ coreHash: contract.coreHash,
92
+ profileHash: contract.profileHash ?? contract.coreHash,
93
+ contractJson: contract,
94
+ canonicalVersion: 1,
95
+ });
96
+ await executeStatement(client, write.insert);
97
+ }
98
+
99
+ /**
100
+ * Creates a test adapter descriptor from a raw adapter.
101
+ * This wraps the adapter in a descriptor for descriptor-first context creation in tests.
102
+ * The adapter instance IS an Adapter (via intersection), with identity properties added.
103
+ */
104
+ function createTestAdapterDescriptor(
105
+ adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
106
+ ): {
107
+ readonly kind: 'adapter';
108
+ readonly id: string;
109
+ readonly version: string;
110
+ readonly familyId: 'sql';
111
+ readonly targetId: 'postgres';
112
+ create(): SqlRuntimeAdapterInstance<'postgres'>;
113
+ } {
114
+ return {
115
+ kind: 'adapter' as const,
116
+ id: 'test-adapter',
117
+ version: '0.0.1',
118
+ familyId: 'sql' as const,
119
+ targetId: 'postgres' as const,
120
+ create(): SqlRuntimeAdapterInstance<'postgres'> {
121
+ // Return an object that combines identity properties with the adapter's methods
122
+ return Object.assign(
123
+ {
124
+ familyId: 'sql' as const,
125
+ targetId: 'postgres' as const,
126
+ },
127
+ adapter,
128
+ );
129
+ },
130
+ };
131
+ }
132
+
133
+ /**
134
+ * Creates a test target descriptor.
135
+ * This is a minimal descriptor for descriptor-first context creation in tests.
136
+ */
137
+ function createTestTargetDescriptor(): {
138
+ readonly kind: 'target';
139
+ readonly id: string;
140
+ readonly version: string;
141
+ readonly familyId: 'sql';
142
+ readonly targetId: 'postgres';
143
+ create(): { readonly familyId: 'sql'; readonly targetId: 'postgres' };
144
+ } {
145
+ return {
146
+ kind: 'target' as const,
147
+ id: 'postgres',
148
+ version: '0.0.1',
149
+ familyId: 'sql' as const,
150
+ targetId: 'postgres' as const,
151
+ create() {
152
+ return { familyId: 'sql' as const, targetId: 'postgres' as const };
153
+ },
154
+ };
155
+ }
156
+
157
+ /**
158
+ * Creates a runtime context with standard test configuration.
159
+ * This helper DRYs up the common pattern of context creation in tests.
160
+ *
161
+ * Accepts a raw adapter and optional extension descriptors, wrapping the
162
+ * adapter in a descriptor internally for descriptor-first context creation.
163
+ */
164
+ export function createTestContext<TContract extends SqlContract<SqlStorage>>(
165
+ contract: TContract,
166
+ adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
167
+ options?: {
168
+ extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;
169
+ },
170
+ ): RuntimeContext<TContract> {
171
+ return createRuntimeContext<TContract, 'postgres'>({
172
+ contract,
173
+ target: createTestTargetDescriptor(),
174
+ adapter: createTestAdapterDescriptor(adapter),
175
+ extensionPacks: options?.extensionPacks ?? [],
176
+ });
177
+ }
178
+
179
+ /**
180
+ * Creates a stub adapter for testing.
181
+ * This helper DRYs up the common pattern of adapter creation in tests.
182
+ *
183
+ * The stub adapter includes simple codecs for common test types (pg/int4@1, pg/text@1, pg/timestamptz@1)
184
+ * to enable type inference in tests without requiring the postgres adapter package.
185
+ */
186
+ export function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement> {
187
+ const codecRegistry = createCodecRegistry();
188
+
189
+ // Register stub codecs for common test types
190
+ // These match the codec IDs used in test contracts (pg/int4@1, pg/text@1, pg/timestamptz@1)
191
+ // but don't require importing from the postgres adapter package
192
+ codecRegistry.register(
193
+ codec({
194
+ typeId: 'pg/int4@1',
195
+ targetTypes: ['int4'],
196
+ encode: (value: number) => value,
197
+ decode: (wire: number) => wire,
198
+ }),
199
+ );
200
+
201
+ codecRegistry.register(
202
+ codec({
203
+ typeId: 'pg/text@1',
204
+ targetTypes: ['text'],
205
+ encode: (value: string) => value,
206
+ decode: (wire: string) => wire,
207
+ }),
208
+ );
209
+
210
+ codecRegistry.register(
211
+ codec({
212
+ typeId: 'pg/timestamptz@1',
213
+ targetTypes: ['timestamptz'],
214
+ encode: (value: string | Date) => (value instanceof Date ? value.toISOString() : value),
215
+ decode: (wire: string | Date) =>
216
+ typeof wire === 'string' ? wire : wire instanceof Date ? wire.toISOString() : String(wire),
217
+ }),
218
+ );
219
+
220
+ return {
221
+ profile: {
222
+ id: 'stub-profile',
223
+ target: 'postgres',
224
+ capabilities: {},
225
+ codecs() {
226
+ return codecRegistry;
227
+ },
228
+ },
229
+ lower(ast: SelectAst, ctx: { contract: SqlContract<SqlStorage>; params?: readonly unknown[] }) {
230
+ const sqlText = JSON.stringify(ast);
231
+ return {
232
+ profileId: this.profile.id,
233
+ body: Object.freeze({ sql: sqlText, params: ctx.params ? [...ctx.params] : [] }),
234
+ };
235
+ },
236
+ };
237
+ }
238
+
239
+ /**
240
+ * Creates a valid test contract without using validateContract.
241
+ * Ensures all required fields are present (mappings, capabilities, extensionPacks, meta, sources)
242
+ * and returns the contract with proper typing.
243
+ * This helper allows tests to create contracts without depending on sql-query.
244
+ */
245
+ export function createTestContract<T extends SqlContract<SqlStorage>>(
246
+ contract: Partial<T> &
247
+ Omit<T, 'mappings' | 'capabilities' | 'extensionPacks' | 'meta' | 'sources'>,
248
+ ): T {
249
+ return {
250
+ ...contract,
251
+ mappings: contract.mappings ?? { codecTypes: {}, operationTypes: {} },
252
+ capabilities: contract.capabilities ?? {},
253
+ extensionPacks: contract.extensionPacks ?? {},
254
+ meta: contract.meta ?? {},
255
+ sources: contract.sources ?? {},
256
+ } as T;
257
+ }
258
+
259
+ // Re-export generic utilities from test-utils
260
+ export {
261
+ collectAsync,
262
+ createDevDatabase,
263
+ type DevDatabase,
264
+ teardownTestDatabase,
265
+ withClient,
266
+ } from '@prisma-next/test-utils';
package/dist/index.d.ts DELETED
@@ -1,29 +0,0 @@
1
- export { AfterExecuteResult, BudgetsOptions, LintsOptions, Log, Plugin, PluginContext, RuntimeTelemetryEvent, RuntimeVerifyOptions, TelemetryOutcome, budgets, lints } from '@prisma-next/runtime-executor';
2
- import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
3
- import { CodecRegistry } from '@prisma-next/sql-relational-core/ast';
4
- import { ExecutionPlan } from '@prisma-next/contract/types';
5
- import { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
6
- import { R as RuntimeContext } from './sql-runtime-DgEbg2OP.js';
7
- export { C as CreateRuntimeContextOptions, g as Runtime, h as RuntimeOptions, S as SqlRuntimeAdapterInstance, a as SqlRuntimeExtensionDescriptor, b as SqlRuntimeExtensionInstance, d as SqlStatement, i as createRuntime, c as createRuntimeContext, e as ensureSchemaStatement, f as ensureTableStatement, r as readContractMarker, w as writeContractMarker } from './sql-runtime-DgEbg2OP.js';
8
- import '@prisma-next/operations';
9
- import '@prisma-next/core-execution-plane/types';
10
- import '@prisma-next/sql-operations';
11
- import '@prisma-next/sql-relational-core/query-lane-context';
12
-
13
- declare function extractCodecIds(contract: SqlContract<SqlStorage>): Set<string>;
14
- declare function validateContractCodecMappings(registry: CodecRegistry, contract: SqlContract<SqlStorage>): void;
15
- declare function validateCodecRegistryCompleteness(registry: CodecRegistry, contract: SqlContract<SqlStorage>): void;
16
-
17
- /**
18
- * Lowers a SQL query plan to an executable Plan by calling the adapter's lower method.
19
- *
20
- * This function is responsible for converting a lane-produced SqlQueryPlan (which contains
21
- * AST and params but no SQL) into a fully executable Plan (which includes SQL string).
22
- *
23
- * @param context - Runtime context containing the adapter
24
- * @param queryPlan - SQL query plan from a lane (contains AST, params, meta, but no SQL)
25
- * @returns Fully executable Plan with SQL string
26
- */
27
- declare function lowerSqlPlan<Row>(context: RuntimeContext, queryPlan: SqlQueryPlan<Row>): ExecutionPlan<Row>;
28
-
29
- export { RuntimeContext, extractCodecIds, lowerSqlPlan, validateCodecRegistryCompleteness, validateContractCodecMappings };
@@ -1,109 +0,0 @@
1
- import { MarkerStatement, AsyncIterableResult, RuntimeTelemetryEvent, RuntimeVerifyOptions, Plugin, Log } from '@prisma-next/runtime-executor';
2
- import { ExecutionPlan } from '@prisma-next/contract/types';
3
- import { OperationRegistry } from '@prisma-next/operations';
4
- import { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
5
- import { Adapter, QueryAst, LoweredStatement, CodecRegistry, SqlDriver, SelectAst } from '@prisma-next/sql-relational-core/ast';
6
- import { SqlQueryPlan } from '@prisma-next/sql-relational-core/plan';
7
- import { RuntimeTargetDescriptor, RuntimeAdapterDescriptor, RuntimeAdapterInstance, RuntimeExtensionDescriptor, RuntimeExtensionInstance } from '@prisma-next/core-execution-plane/types';
8
- import { SqlOperationSignature } from '@prisma-next/sql-operations';
9
- import { QueryLaneContext } from '@prisma-next/sql-relational-core/query-lane-context';
10
-
11
- /**
12
- * SQL runtime extension instance.
13
- * Extends the framework RuntimeExtensionInstance with SQL-specific hooks
14
- * for contributing codecs and operations to the runtime context.
15
- *
16
- * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
17
- */
18
- interface SqlRuntimeExtensionInstance<TTargetId extends string> extends RuntimeExtensionInstance<'sql', TTargetId> {
19
- /** Returns codecs to register in the runtime context. */
20
- codecs?(): CodecRegistry;
21
- /** Returns operations to register in the runtime context. */
22
- operations?(): ReadonlyArray<SqlOperationSignature>;
23
- }
24
- /**
25
- * SQL runtime extension descriptor.
26
- * Extends the framework RuntimeExtensionDescriptor with SQL-specific instance type.
27
- *
28
- * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
29
- */
30
- interface SqlRuntimeExtensionDescriptor<TTargetId extends string> extends RuntimeExtensionDescriptor<'sql', TTargetId, SqlRuntimeExtensionInstance<TTargetId>> {
31
- create(): SqlRuntimeExtensionInstance<TTargetId>;
32
- }
33
- /**
34
- * SQL runtime adapter instance interface.
35
- * Combines RuntimeAdapterInstance identity with SQL Adapter behavior.
36
- * The instance IS an Adapter (via intersection), not HAS an adapter property.
37
- *
38
- * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
39
- */
40
- type SqlRuntimeAdapterInstance<TTargetId extends string = string> = RuntimeAdapterInstance<'sql', TTargetId> & Adapter<QueryAst, SqlContract<SqlStorage>, LoweredStatement>;
41
- interface RuntimeContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> extends QueryLaneContext<TContract> {
42
- readonly adapter: Adapter<QueryAst, TContract, LoweredStatement> | Adapter<QueryAst, SqlContract<SqlStorage>, LoweredStatement>;
43
- }
44
- /**
45
- * Descriptor-first options for creating a SQL runtime context.
46
- * Takes the same framework composition as control-plane: target, adapter, extensionPacks.
47
- *
48
- * @template TContract - The SQL contract type
49
- * @template TTargetId - The target ID (e.g., 'postgres', 'mysql')
50
- */
51
- interface CreateRuntimeContextOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, TTargetId extends string = string> {
52
- readonly contract: TContract;
53
- readonly target: RuntimeTargetDescriptor<'sql', TTargetId>;
54
- readonly adapter: RuntimeAdapterDescriptor<'sql', TTargetId, SqlRuntimeAdapterInstance<TTargetId>>;
55
- readonly extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<TTargetId>>;
56
- }
57
- /**
58
- * Creates a SQL runtime context from descriptor-first composition.
59
- *
60
- * The context includes:
61
- * - The validated contract
62
- * - The adapter instance (created from descriptor)
63
- * - Codec registry (populated from adapter + extension instances)
64
- * - Operation registry (populated from extension instances)
65
- *
66
- * @param options - Descriptor-first composition options
67
- * @returns RuntimeContext with registries wired from all components
68
- */
69
- declare function createRuntimeContext<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>, TTargetId extends string = string>(options: CreateRuntimeContextOptions<TContract, TTargetId>): RuntimeContext<TContract>;
70
-
71
- interface SqlStatement {
72
- readonly sql: string;
73
- readonly params: readonly unknown[];
74
- }
75
- interface WriteMarkerInput {
76
- readonly coreHash: string;
77
- readonly profileHash: string;
78
- readonly contractJson?: unknown;
79
- readonly canonicalVersion?: number;
80
- readonly appTag?: string;
81
- readonly meta?: Record<string, unknown>;
82
- }
83
- declare const ensureSchemaStatement: SqlStatement;
84
- declare const ensureTableStatement: SqlStatement;
85
- declare function readContractMarker(): MarkerStatement;
86
- interface WriteContractMarkerStatements {
87
- readonly insert: SqlStatement;
88
- readonly update: SqlStatement;
89
- }
90
- declare function writeContractMarker(input: WriteMarkerInput): WriteContractMarkerStatements;
91
-
92
- interface RuntimeOptions<TContract extends SqlContract<SqlStorage> = SqlContract<SqlStorage>> {
93
- readonly driver: SqlDriver;
94
- readonly verify: RuntimeVerifyOptions;
95
- readonly context: RuntimeContext<TContract>;
96
- readonly plugins?: readonly Plugin<TContract, Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>, SqlDriver>[];
97
- readonly mode?: 'strict' | 'permissive';
98
- readonly log?: Log;
99
- }
100
- interface Runtime {
101
- execute<Row = Record<string, unknown>>(plan: ExecutionPlan<Row> | SqlQueryPlan<Row>): AsyncIterableResult<Row>;
102
- telemetry(): RuntimeTelemetryEvent | null;
103
- close(): Promise<void>;
104
- operations(): OperationRegistry;
105
- }
106
-
107
- declare function createRuntime<TContract extends SqlContract<SqlStorage>>(options: RuntimeOptions<TContract>): Runtime;
108
-
109
- export { type CreateRuntimeContextOptions as C, type RuntimeContext as R, type SqlRuntimeAdapterInstance as S, type SqlRuntimeExtensionDescriptor as a, type SqlRuntimeExtensionInstance as b, createRuntimeContext as c, type SqlStatement as d, ensureSchemaStatement as e, ensureTableStatement as f, type Runtime as g, type RuntimeOptions as h, createRuntime as i, readContractMarker as r, writeContractMarker as w };