@prisma-next/sql-runtime 0.3.0-dev.34 → 0.3.0-dev.37
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 +115 -24
- package/dist/exports-C8hi0N-a.mjs +622 -0
- package/dist/exports-C8hi0N-a.mjs.map +1 -0
- package/dist/index-SlQIrV_t.d.mts +131 -0
- package/dist/index-SlQIrV_t.d.mts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +3 -0
- package/dist/test/utils.d.mts +82 -0
- package/dist/test/utils.d.mts.map +1 -0
- package/dist/test/utils.mjs +212 -0
- package/dist/test/utils.mjs.map +1 -0
- package/package.json +26 -20
- package/src/codecs/decoding.ts +84 -3
- package/src/codecs/encoding.ts +15 -2
- package/src/codecs/json-schema-validation.ts +61 -0
- package/src/exports/index.ts +9 -4
- package/src/lower-sql-plan.ts +8 -8
- package/src/sql-context.ts +286 -245
- package/src/sql-family-adapter.ts +9 -5
- package/src/sql-marker.ts +2 -2
- package/src/sql-runtime.ts +89 -23
- package/test/async-iterable-result.test.ts +42 -34
- package/test/context.types.test-d.ts +12 -14
- package/test/execution-stack.test.ts +166 -0
- package/test/json-schema-validation.test.ts +653 -0
- package/test/parameterized-types.test.ts +182 -196
- package/test/sql-context.test.ts +292 -117
- package/test/sql-family-adapter.test.ts +7 -6
- package/test/sql-runtime.test.ts +117 -31
- package/test/utils.ts +76 -50
- package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js +0 -137863
- package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js.map +0 -1
- package/dist/amcheck-24VY6X5V.js +0 -13
- package/dist/amcheck-24VY6X5V.js.map +0 -1
- package/dist/bloom-VS74NLHT.js +0 -13
- package/dist/bloom-VS74NLHT.js.map +0 -1
- package/dist/btree_gin-WBC4EAAI.js +0 -13
- package/dist/btree_gin-WBC4EAAI.js.map +0 -1
- package/dist/btree_gist-UNC6QD3M.js +0 -13
- package/dist/btree_gist-UNC6QD3M.js.map +0 -1
- package/dist/chunk-3KTOEDFX.js +0 -49
- package/dist/chunk-3KTOEDFX.js.map +0 -1
- package/dist/chunk-47DZBRQC.js +0 -1280
- package/dist/chunk-47DZBRQC.js.map +0 -1
- package/dist/chunk-52N6AFZM.js +0 -133
- package/dist/chunk-52N6AFZM.js.map +0 -1
- package/dist/chunk-7D4SUZUM.js +0 -38
- package/dist/chunk-7D4SUZUM.js.map +0 -1
- package/dist/chunk-APA6GHYY.js +0 -537
- package/dist/chunk-APA6GHYY.js.map +0 -1
- package/dist/chunk-ECWIHLAT.js +0 -37
- package/dist/chunk-ECWIHLAT.js.map +0 -1
- package/dist/chunk-EI626SDC.js +0 -105
- package/dist/chunk-EI626SDC.js.map +0 -1
- package/dist/chunk-UKKOYUGL.js +0 -578
- package/dist/chunk-UKKOYUGL.js.map +0 -1
- package/dist/chunk-XPLNMXQV.js +0 -1537
- package/dist/chunk-XPLNMXQV.js.map +0 -1
- package/dist/citext-T7MXGUY7.js +0 -13
- package/dist/citext-T7MXGUY7.js.map +0 -1
- package/dist/client-5FENX6AW.js +0 -299
- package/dist/client-5FENX6AW.js.map +0 -1
- package/dist/cube-TFDQBZCI.js +0 -13
- package/dist/cube-TFDQBZCI.js.map +0 -1
- package/dist/dict_int-AEUOPGWP.js +0 -13
- package/dist/dict_int-AEUOPGWP.js.map +0 -1
- package/dist/dict_xsyn-DAAYX3FL.js +0 -13
- package/dist/dict_xsyn-DAAYX3FL.js.map +0 -1
- package/dist/dist-AQ3LWXOX.js +0 -570
- package/dist/dist-AQ3LWXOX.js.map +0 -1
- package/dist/dist-LBVX6BJW.js +0 -189
- package/dist/dist-LBVX6BJW.js.map +0 -1
- package/dist/dist-WLKUVDN2.js +0 -5127
- package/dist/dist-WLKUVDN2.js.map +0 -1
- package/dist/earthdistance-KIGTF4LE.js +0 -13
- package/dist/earthdistance-KIGTF4LE.js.map +0 -1
- package/dist/file_fdw-5N55UP6I.js +0 -13
- package/dist/file_fdw-5N55UP6I.js.map +0 -1
- package/dist/fuzzystrmatch-KN3YWBFP.js +0 -13
- package/dist/fuzzystrmatch-KN3YWBFP.js.map +0 -1
- package/dist/hstore-YX726NKN.js +0 -13
- package/dist/hstore-YX726NKN.js.map +0 -1
- package/dist/http-exception-FZY2H4OF.js +0 -8
- package/dist/http-exception-FZY2H4OF.js.map +0 -1
- package/dist/index.js +0 -30
- package/dist/index.js.map +0 -1
- package/dist/intarray-NKVXNO2D.js +0 -13
- package/dist/intarray-NKVXNO2D.js.map +0 -1
- package/dist/isn-FTEMJGEV.js +0 -13
- package/dist/isn-FTEMJGEV.js.map +0 -1
- package/dist/lo-DB7L4NGI.js +0 -13
- package/dist/lo-DB7L4NGI.js.map +0 -1
- package/dist/logger-WQ7SHNDD.js +0 -68
- package/dist/logger-WQ7SHNDD.js.map +0 -1
- package/dist/ltree-Z32TZT6W.js +0 -13
- package/dist/ltree-Z32TZT6W.js.map +0 -1
- package/dist/nodefs-NM46ACH7.js +0 -31
- package/dist/nodefs-NM46ACH7.js.map +0 -1
- package/dist/opfs-ahp-NJO33LVZ.js +0 -332
- package/dist/opfs-ahp-NJO33LVZ.js.map +0 -1
- package/dist/pageinspect-YP3IZR4X.js +0 -13
- package/dist/pageinspect-YP3IZR4X.js.map +0 -1
- package/dist/pg_buffercache-7TD5J2FB.js +0 -13
- package/dist/pg_buffercache-7TD5J2FB.js.map +0 -1
- package/dist/pg_dump-SG4KYBUB.js +0 -2492
- package/dist/pg_dump-SG4KYBUB.js.map +0 -1
- package/dist/pg_freespacemap-DZDNCPZK.js +0 -13
- package/dist/pg_freespacemap-DZDNCPZK.js.map +0 -1
- package/dist/pg_surgery-J2MUEWEP.js +0 -13
- package/dist/pg_surgery-J2MUEWEP.js.map +0 -1
- package/dist/pg_trgm-7VNQOYS6.js +0 -13
- package/dist/pg_trgm-7VNQOYS6.js.map +0 -1
- package/dist/pg_visibility-TTSIPHFL.js +0 -13
- package/dist/pg_visibility-TTSIPHFL.js.map +0 -1
- package/dist/pg_walinspect-KPFHSHRJ.js +0 -13
- package/dist/pg_walinspect-KPFHSHRJ.js.map +0 -1
- package/dist/proxy-signals-GUDAMDHV.js +0 -39
- package/dist/proxy-signals-GUDAMDHV.js.map +0 -1
- package/dist/seg-IYVDLE4O.js +0 -13
- package/dist/seg-IYVDLE4O.js.map +0 -1
- package/dist/src/codecs/decoding.d.ts +0 -4
- package/dist/src/codecs/decoding.d.ts.map +0 -1
- package/dist/src/codecs/encoding.d.ts +0 -5
- package/dist/src/codecs/encoding.d.ts.map +0 -1
- package/dist/src/codecs/validation.d.ts +0 -6
- package/dist/src/codecs/validation.d.ts.map +0 -1
- package/dist/src/exports/index.d.ts +0 -11
- package/dist/src/exports/index.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lower-sql-plan.d.ts +0 -15
- package/dist/src/lower-sql-plan.d.ts.map +0 -1
- package/dist/src/sql-context.d.ts +0 -130
- package/dist/src/sql-context.d.ts.map +0 -1
- package/dist/src/sql-family-adapter.d.ts +0 -10
- package/dist/src/sql-family-adapter.d.ts.map +0 -1
- package/dist/src/sql-marker.d.ts +0 -22
- package/dist/src/sql-marker.d.ts.map +0 -1
- package/dist/src/sql-runtime.d.ts +0 -25
- package/dist/src/sql-runtime.d.ts.map +0 -1
- package/dist/tablefunc-EF4RCS7S.js +0 -13
- package/dist/tablefunc-EF4RCS7S.js.map +0 -1
- package/dist/tcn-3VT5BQYW.js +0 -13
- package/dist/tcn-3VT5BQYW.js.map +0 -1
- package/dist/test/utils.d.ts +0 -60
- package/dist/test/utils.d.ts.map +0 -1
- package/dist/test/utils.js +0 -24635
- package/dist/test/utils.js.map +0 -1
- package/dist/tiny-CW6F4GX6.js +0 -10
- package/dist/tiny-CW6F4GX6.js.map +0 -1
- package/dist/tsm_system_rows-ES7KNUQH.js +0 -13
- package/dist/tsm_system_rows-ES7KNUQH.js.map +0 -1
- package/dist/tsm_system_time-76WEIMBG.js +0 -13
- package/dist/tsm_system_time-76WEIMBG.js.map +0 -1
- package/dist/unaccent-7RYF3R64.js +0 -13
- package/dist/unaccent-7RYF3R64.js.map +0 -1
- package/dist/utility-Q5A254LJ-J4HTKZPT.js +0 -347
- package/dist/utility-Q5A254LJ-J4HTKZPT.js.map +0 -1
- package/dist/uuid_ossp-4ETE4FPE.js +0 -13
- package/dist/uuid_ossp-4ETE4FPE.js.map +0 -1
- package/dist/vector-74GPNV7V.js +0 -13
- package/dist/vector-74GPNV7V.js.map +0 -1
- package/src/index.ts +0 -1
package/test/sql-runtime.test.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { coreHash } from '@prisma-next/contract/types';
|
|
2
|
+
import type { ExecutionStackInstance } from '@prisma-next/core-execution-plane/stack';
|
|
3
|
+
import { instantiateExecutionStack } from '@prisma-next/core-execution-plane/stack';
|
|
4
|
+
import type {
|
|
5
|
+
RuntimeDriverInstance,
|
|
6
|
+
RuntimeExtensionInstance,
|
|
7
|
+
} from '@prisma-next/core-execution-plane/types';
|
|
2
8
|
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
9
|
import type {
|
|
4
10
|
CodecRegistry,
|
|
@@ -8,15 +14,19 @@ import type {
|
|
|
8
14
|
} from '@prisma-next/sql-relational-core/ast';
|
|
9
15
|
import { codec, createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
10
16
|
import { describe, expect, it, vi } from 'vitest';
|
|
11
|
-
import type {
|
|
17
|
+
import type {
|
|
18
|
+
SqlRuntimeAdapterDescriptor,
|
|
19
|
+
SqlRuntimeAdapterInstance,
|
|
20
|
+
SqlRuntimeTargetDescriptor,
|
|
21
|
+
} from '../src/sql-context';
|
|
22
|
+
import { createExecutionContext, createSqlExecutionStack } from '../src/sql-context';
|
|
12
23
|
import { createRuntime } from '../src/sql-runtime';
|
|
13
24
|
|
|
14
|
-
// Minimal test contract
|
|
15
25
|
const testContract: SqlContract<SqlStorage> = {
|
|
16
26
|
schemaVersion: '1',
|
|
17
27
|
targetFamily: 'sql',
|
|
18
28
|
target: 'postgres',
|
|
19
|
-
|
|
29
|
+
storageHash: coreHash('sha256:test'),
|
|
20
30
|
models: {},
|
|
21
31
|
relations: {},
|
|
22
32
|
storage: { tables: {} },
|
|
@@ -30,7 +40,6 @@ const testContract: SqlContract<SqlStorage> = {
|
|
|
30
40
|
},
|
|
31
41
|
};
|
|
32
42
|
|
|
33
|
-
// Create a stub codec registry
|
|
34
43
|
function createStubCodecs(): CodecRegistry {
|
|
35
44
|
const registry = createCodecRegistry();
|
|
36
45
|
registry.register(
|
|
@@ -44,7 +53,6 @@ function createStubCodecs(): CodecRegistry {
|
|
|
44
53
|
return registry;
|
|
45
54
|
}
|
|
46
55
|
|
|
47
|
-
// Create a stub adapter
|
|
48
56
|
function createStubAdapter() {
|
|
49
57
|
const codecs = createStubCodecs();
|
|
50
58
|
return {
|
|
@@ -67,37 +75,103 @@ function createStubAdapter() {
|
|
|
67
75
|
};
|
|
68
76
|
}
|
|
69
77
|
|
|
70
|
-
// Create a mock driver that implements SqlDriver interface
|
|
71
78
|
function createMockDriver(): SqlDriver {
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
79
|
+
const queryable = {
|
|
80
|
+
execute: vi.fn().mockImplementation(async function* (_request: SqlExecuteRequest) {
|
|
81
|
+
yield { id: 1 };
|
|
82
|
+
}),
|
|
83
|
+
query: vi.fn().mockResolvedValue({ rows: [], rowCount: 0 }),
|
|
84
|
+
};
|
|
75
85
|
|
|
76
86
|
return {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
87
|
+
...queryable,
|
|
88
|
+
connect: vi.fn().mockImplementation(async (_binding?: undefined) => undefined),
|
|
89
|
+
acquireConnection: vi.fn().mockResolvedValue({
|
|
90
|
+
...queryable,
|
|
91
|
+
release: vi.fn().mockResolvedValue(undefined),
|
|
92
|
+
beginTransaction: vi.fn().mockResolvedValue({
|
|
93
|
+
...queryable,
|
|
94
|
+
commit: vi.fn().mockResolvedValue(undefined),
|
|
95
|
+
rollback: vi.fn().mockResolvedValue(undefined),
|
|
96
|
+
}),
|
|
97
|
+
}),
|
|
80
98
|
close: vi.fn().mockResolvedValue(undefined),
|
|
81
99
|
};
|
|
82
100
|
}
|
|
83
101
|
|
|
84
|
-
|
|
85
|
-
function createTestContext(contract: SqlContract<SqlStorage>): RuntimeContext<typeof contract> {
|
|
86
|
-
const adapter = createStubAdapter();
|
|
102
|
+
function createTestTargetDescriptor(): SqlRuntimeTargetDescriptor<'postgres'> {
|
|
87
103
|
return {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
104
|
+
kind: 'target',
|
|
105
|
+
id: 'postgres',
|
|
106
|
+
version: '0.0.1',
|
|
107
|
+
familyId: 'sql' as const,
|
|
108
|
+
targetId: 'postgres' as const,
|
|
109
|
+
codecs: () => createCodecRegistry(),
|
|
110
|
+
operationSignatures: () => [],
|
|
111
|
+
parameterizedCodecs: () => [],
|
|
112
|
+
create() {
|
|
113
|
+
return { familyId: 'sql' as const, targetId: 'postgres' as const };
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
function createTestAdapterDescriptor(
|
|
119
|
+
adapter: ReturnType<typeof createStubAdapter>,
|
|
120
|
+
): SqlRuntimeAdapterDescriptor<'postgres'> {
|
|
121
|
+
const codecRegistry = adapter.profile.codecs();
|
|
122
|
+
return {
|
|
123
|
+
kind: 'adapter',
|
|
124
|
+
id: 'test-adapter',
|
|
125
|
+
version: '0.0.1',
|
|
126
|
+
familyId: 'sql' as const,
|
|
127
|
+
targetId: 'postgres' as const,
|
|
128
|
+
codecs: () => codecRegistry,
|
|
129
|
+
operationSignatures: () => [],
|
|
130
|
+
parameterizedCodecs: () => [],
|
|
131
|
+
create() {
|
|
132
|
+
return Object.assign(
|
|
133
|
+
{ familyId: 'sql' as const, targetId: 'postgres' as const },
|
|
134
|
+
adapter,
|
|
135
|
+
) as SqlRuntimeAdapterInstance<'postgres'>;
|
|
136
|
+
},
|
|
92
137
|
};
|
|
93
138
|
}
|
|
94
139
|
|
|
140
|
+
function createTestSetup() {
|
|
141
|
+
const adapter = createStubAdapter();
|
|
142
|
+
const driver = createMockDriver();
|
|
143
|
+
|
|
144
|
+
const targetDescriptor = createTestTargetDescriptor();
|
|
145
|
+
const adapterDescriptor = createTestAdapterDescriptor(adapter);
|
|
146
|
+
|
|
147
|
+
const stack = createSqlExecutionStack({
|
|
148
|
+
target: targetDescriptor,
|
|
149
|
+
adapter: adapterDescriptor,
|
|
150
|
+
extensionPacks: [],
|
|
151
|
+
});
|
|
152
|
+
type SqlTestStackInstance = ExecutionStackInstance<
|
|
153
|
+
'sql',
|
|
154
|
+
'postgres',
|
|
155
|
+
SqlRuntimeAdapterInstance<'postgres'>,
|
|
156
|
+
RuntimeDriverInstance<'sql', 'postgres'>,
|
|
157
|
+
RuntimeExtensionInstance<'sql', 'postgres'>
|
|
158
|
+
>;
|
|
159
|
+
const stackInstance = instantiateExecutionStack(stack) as SqlTestStackInstance;
|
|
160
|
+
|
|
161
|
+
const context = createExecutionContext({
|
|
162
|
+
contract: testContract,
|
|
163
|
+
stack: { target: targetDescriptor, adapter: adapterDescriptor, extensionPacks: [] },
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
return { stackInstance, context, driver };
|
|
167
|
+
}
|
|
168
|
+
|
|
95
169
|
describe('createRuntime', () => {
|
|
96
|
-
it('creates runtime with
|
|
97
|
-
const context =
|
|
98
|
-
const driver = createMockDriver();
|
|
170
|
+
it('creates runtime with context and driver', () => {
|
|
171
|
+
const { stackInstance, context, driver } = createTestSetup();
|
|
99
172
|
|
|
100
173
|
const runtime = createRuntime({
|
|
174
|
+
stackInstance,
|
|
101
175
|
context,
|
|
102
176
|
driver,
|
|
103
177
|
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
@@ -111,10 +185,10 @@ describe('createRuntime', () => {
|
|
|
111
185
|
});
|
|
112
186
|
|
|
113
187
|
it('returns operations registry', () => {
|
|
114
|
-
const context =
|
|
115
|
-
const driver = createMockDriver();
|
|
188
|
+
const { stackInstance, context, driver } = createTestSetup();
|
|
116
189
|
|
|
117
190
|
const runtime = createRuntime({
|
|
191
|
+
stackInstance,
|
|
118
192
|
context,
|
|
119
193
|
driver,
|
|
120
194
|
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
@@ -126,24 +200,23 @@ describe('createRuntime', () => {
|
|
|
126
200
|
});
|
|
127
201
|
|
|
128
202
|
it('returns null telemetry when no events', () => {
|
|
129
|
-
const context =
|
|
130
|
-
const driver = createMockDriver();
|
|
203
|
+
const { stackInstance, context, driver } = createTestSetup();
|
|
131
204
|
|
|
132
205
|
const runtime = createRuntime({
|
|
206
|
+
stackInstance,
|
|
133
207
|
context,
|
|
134
208
|
driver,
|
|
135
209
|
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
136
210
|
});
|
|
137
211
|
|
|
138
|
-
// Before any execution, telemetry should be null
|
|
139
212
|
expect(runtime.telemetry()).toBeNull();
|
|
140
213
|
});
|
|
141
214
|
|
|
142
|
-
it('closes runtime', async () => {
|
|
143
|
-
const context =
|
|
144
|
-
const driver = createMockDriver();
|
|
215
|
+
it('closes runtime and driver', async () => {
|
|
216
|
+
const { stackInstance, context, driver } = createTestSetup();
|
|
145
217
|
|
|
146
218
|
const runtime = createRuntime({
|
|
219
|
+
stackInstance,
|
|
147
220
|
context,
|
|
148
221
|
driver,
|
|
149
222
|
verify: { mode: 'onFirstUse', requireMarker: false },
|
|
@@ -152,4 +225,17 @@ describe('createRuntime', () => {
|
|
|
152
225
|
await runtime.close();
|
|
153
226
|
expect(driver.close).toHaveBeenCalled();
|
|
154
227
|
});
|
|
228
|
+
|
|
229
|
+
it('validates codec registry at startup when verify mode is startup', () => {
|
|
230
|
+
const { stackInstance, context, driver } = createTestSetup();
|
|
231
|
+
|
|
232
|
+
const runtime = createRuntime({
|
|
233
|
+
stackInstance,
|
|
234
|
+
context,
|
|
235
|
+
driver,
|
|
236
|
+
verify: { mode: 'startup', requireMarker: false },
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
expect(runtime).toBeDefined();
|
|
240
|
+
});
|
|
155
241
|
});
|
package/test/utils.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import type { ExecutionPlan, ResultType } from '@prisma-next/contract/types';
|
|
2
|
+
import { coreHash, profileHash } from '@prisma-next/contract/types';
|
|
3
|
+
import { instantiateExecutionStack } from '@prisma-next/core-execution-plane/stack';
|
|
4
|
+
import type { RuntimeDriverDescriptor } from '@prisma-next/core-execution-plane/types';
|
|
2
5
|
import type { SqlContract, SqlStorage } from '@prisma-next/sql-contract/types';
|
|
3
6
|
import type { Adapter, LoweredStatement, SelectAst } from '@prisma-next/sql-relational-core/ast';
|
|
4
7
|
import { codec, createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
|
|
@@ -7,16 +10,20 @@ import { collectAsync, drainAsyncIterable } from '@prisma-next/test-utils';
|
|
|
7
10
|
import type { Client } from 'pg';
|
|
8
11
|
import type { SqlStatement } from '../src/exports';
|
|
9
12
|
import {
|
|
13
|
+
createExecutionContext,
|
|
10
14
|
type createRuntime,
|
|
11
|
-
|
|
15
|
+
createSqlExecutionStack,
|
|
12
16
|
ensureSchemaStatement,
|
|
13
17
|
ensureTableStatement,
|
|
14
18
|
writeContractMarker,
|
|
15
19
|
} from '../src/exports';
|
|
16
20
|
import type {
|
|
17
|
-
|
|
21
|
+
ExecutionContext,
|
|
22
|
+
SqlRuntimeAdapterDescriptor,
|
|
18
23
|
SqlRuntimeAdapterInstance,
|
|
24
|
+
SqlRuntimeDriverInstance,
|
|
19
25
|
SqlRuntimeExtensionDescriptor,
|
|
26
|
+
SqlRuntimeTargetDescriptor,
|
|
20
27
|
} from '../src/sql-context';
|
|
21
28
|
|
|
22
29
|
/**
|
|
@@ -71,8 +78,8 @@ export async function setupTestDatabase(
|
|
|
71
78
|
await executeStatement(client, ensureSchemaStatement);
|
|
72
79
|
await executeStatement(client, ensureTableStatement);
|
|
73
80
|
const write = writeContractMarker({
|
|
74
|
-
|
|
75
|
-
profileHash: contract.profileHash ?? contract.
|
|
81
|
+
storageHash: contract.storageHash,
|
|
82
|
+
profileHash: contract.profileHash ?? contract.storageHash,
|
|
76
83
|
contractJson: contract,
|
|
77
84
|
canonicalVersion: 1,
|
|
78
85
|
});
|
|
@@ -88,8 +95,8 @@ export async function writeTestContractMarker(
|
|
|
88
95
|
contract: SqlContract<SqlStorage>,
|
|
89
96
|
): Promise<void> {
|
|
90
97
|
const write = writeContractMarker({
|
|
91
|
-
|
|
92
|
-
profileHash: contract.profileHash ?? contract.
|
|
98
|
+
storageHash: contract.storageHash,
|
|
99
|
+
profileHash: contract.profileHash ?? contract.storageHash,
|
|
93
100
|
contractJson: contract,
|
|
94
101
|
canonicalVersion: 1,
|
|
95
102
|
});
|
|
@@ -98,56 +105,41 @@ export async function writeTestContractMarker(
|
|
|
98
105
|
|
|
99
106
|
/**
|
|
100
107
|
* Creates a test adapter descriptor from a raw adapter.
|
|
101
|
-
*
|
|
102
|
-
*
|
|
108
|
+
* Wraps the adapter in an SqlRuntimeAdapterDescriptor with static contributions
|
|
109
|
+
* derived from the adapter's codec registry.
|
|
103
110
|
*/
|
|
104
|
-
function createTestAdapterDescriptor(
|
|
111
|
+
export function createTestAdapterDescriptor(
|
|
105
112
|
adapter: Adapter<SelectAst, SqlContract<SqlStorage>, LoweredStatement>,
|
|
106
|
-
): {
|
|
107
|
-
|
|
108
|
-
readonly id: string;
|
|
109
|
-
readonly version: string;
|
|
110
|
-
readonly familyId: 'sql';
|
|
111
|
-
readonly targetId: 'postgres';
|
|
112
|
-
create(): SqlRuntimeAdapterInstance<'postgres'>;
|
|
113
|
-
} {
|
|
113
|
+
): SqlRuntimeAdapterDescriptor<'postgres'> {
|
|
114
|
+
const codecRegistry = adapter.profile.codecs();
|
|
114
115
|
return {
|
|
115
116
|
kind: 'adapter' as const,
|
|
116
117
|
id: 'test-adapter',
|
|
117
118
|
version: '0.0.1',
|
|
118
119
|
familyId: 'sql' as const,
|
|
119
120
|
targetId: 'postgres' as const,
|
|
121
|
+
codecs: () => codecRegistry,
|
|
122
|
+
operationSignatures: () => [],
|
|
123
|
+
parameterizedCodecs: () => [],
|
|
120
124
|
create(): SqlRuntimeAdapterInstance<'postgres'> {
|
|
121
|
-
|
|
122
|
-
return Object.assign(
|
|
123
|
-
{
|
|
124
|
-
familyId: 'sql' as const,
|
|
125
|
-
targetId: 'postgres' as const,
|
|
126
|
-
},
|
|
127
|
-
adapter,
|
|
128
|
-
);
|
|
125
|
+
return Object.assign({ familyId: 'sql' as const, targetId: 'postgres' as const }, adapter);
|
|
129
126
|
},
|
|
130
127
|
};
|
|
131
128
|
}
|
|
132
129
|
|
|
133
130
|
/**
|
|
134
|
-
* Creates a test target descriptor.
|
|
135
|
-
* This is a minimal descriptor for descriptor-first context creation in tests.
|
|
131
|
+
* Creates a test target descriptor with empty static contributions.
|
|
136
132
|
*/
|
|
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
|
-
} {
|
|
133
|
+
export function createTestTargetDescriptor(): SqlRuntimeTargetDescriptor<'postgres'> {
|
|
145
134
|
return {
|
|
146
135
|
kind: 'target' as const,
|
|
147
136
|
id: 'postgres',
|
|
148
137
|
version: '0.0.1',
|
|
149
138
|
familyId: 'sql' as const,
|
|
150
139
|
targetId: 'postgres' as const,
|
|
140
|
+
codecs: () => createCodecRegistry(),
|
|
141
|
+
operationSignatures: () => [],
|
|
142
|
+
parameterizedCodecs: () => [],
|
|
151
143
|
create() {
|
|
152
144
|
return { familyId: 'sql' as const, targetId: 'postgres' as const };
|
|
153
145
|
},
|
|
@@ -155,7 +147,7 @@ function createTestTargetDescriptor(): {
|
|
|
155
147
|
}
|
|
156
148
|
|
|
157
149
|
/**
|
|
158
|
-
* Creates
|
|
150
|
+
* Creates an ExecutionContext for testing.
|
|
159
151
|
* This helper DRYs up the common pattern of context creation in tests.
|
|
160
152
|
*
|
|
161
153
|
* Accepts a raw adapter and optional extension descriptors, wrapping the
|
|
@@ -167,13 +159,34 @@ export function createTestContext<TContract extends SqlContract<SqlStorage>>(
|
|
|
167
159
|
options?: {
|
|
168
160
|
extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;
|
|
169
161
|
},
|
|
170
|
-
):
|
|
171
|
-
return
|
|
162
|
+
): ExecutionContext<TContract> {
|
|
163
|
+
return createExecutionContext({
|
|
172
164
|
contract,
|
|
165
|
+
stack: {
|
|
166
|
+
target: createTestTargetDescriptor(),
|
|
167
|
+
adapter: createTestAdapterDescriptor(adapter),
|
|
168
|
+
extensionPacks: options?.extensionPacks ?? [],
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export function createTestStackInstance(options?: {
|
|
174
|
+
extensionPacks?: ReadonlyArray<SqlRuntimeExtensionDescriptor<'postgres'>>;
|
|
175
|
+
driver?: RuntimeDriverDescriptor<
|
|
176
|
+
'sql',
|
|
177
|
+
'postgres',
|
|
178
|
+
unknown,
|
|
179
|
+
SqlRuntimeDriverInstance<'postgres'>
|
|
180
|
+
>;
|
|
181
|
+
}) {
|
|
182
|
+
const stack = createSqlExecutionStack({
|
|
173
183
|
target: createTestTargetDescriptor(),
|
|
174
|
-
adapter: createTestAdapterDescriptor(
|
|
184
|
+
adapter: createTestAdapterDescriptor(createStubAdapter()),
|
|
185
|
+
driver: options?.driver,
|
|
175
186
|
extensionPacks: options?.extensionPacks ?? [],
|
|
176
187
|
});
|
|
188
|
+
|
|
189
|
+
return instantiateExecutionStack(stack);
|
|
177
190
|
}
|
|
178
191
|
|
|
179
192
|
/**
|
|
@@ -242,18 +255,31 @@ export function createStubAdapter(): Adapter<SelectAst, SqlContract<SqlStorage>,
|
|
|
242
255
|
* and returns the contract with proper typing.
|
|
243
256
|
* This helper allows tests to create contracts without depending on sql-query.
|
|
244
257
|
*/
|
|
245
|
-
export function createTestContract
|
|
246
|
-
contract: Partial<
|
|
247
|
-
|
|
248
|
-
|
|
258
|
+
export function createTestContract(
|
|
259
|
+
contract: Partial<Omit<SqlContract<SqlStorage>, 'storageHash' | 'profileHash'>> & {
|
|
260
|
+
storageHash?: string;
|
|
261
|
+
profileHash?: string;
|
|
262
|
+
},
|
|
263
|
+
): SqlContract<SqlStorage> {
|
|
264
|
+
const { execution, ...rest } = contract;
|
|
265
|
+
|
|
249
266
|
return {
|
|
250
|
-
...
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
267
|
+
...rest,
|
|
268
|
+
schemaVersion: rest.schemaVersion ?? '1',
|
|
269
|
+
target: rest.target ?? 'postgres',
|
|
270
|
+
targetFamily: rest.targetFamily ?? 'sql',
|
|
271
|
+
storage: rest.storage ?? { tables: {} },
|
|
272
|
+
models: rest.models ?? {},
|
|
273
|
+
relations: rest.relations ?? {},
|
|
274
|
+
mappings: rest.mappings ?? { codecTypes: {}, operationTypes: {} },
|
|
275
|
+
capabilities: rest.capabilities ?? {},
|
|
276
|
+
extensionPacks: rest.extensionPacks ?? {},
|
|
277
|
+
meta: rest.meta ?? {},
|
|
278
|
+
sources: rest.sources ?? {},
|
|
279
|
+
...(execution ? { execution } : {}),
|
|
280
|
+
storageHash: coreHash(rest.storageHash ?? 'sha256:testcore'),
|
|
281
|
+
profileHash: profileHash(rest.profileHash ?? 'sha256:testprofile'),
|
|
282
|
+
} satisfies SqlContract<SqlStorage>;
|
|
257
283
|
}
|
|
258
284
|
|
|
259
285
|
// Re-export generic utilities from test-utils
|