@prisma-next/sql-runtime 0.3.0-dev.13 → 0.3.0-dev.146

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 (170) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +141 -24
  3. package/dist/exports-DGa0ipuP.mjs +956 -0
  4. package/dist/exports-DGa0ipuP.mjs.map +1 -0
  5. package/dist/index-CDbmlDcn.d.mts +177 -0
  6. package/dist/index-CDbmlDcn.d.mts.map +1 -0
  7. package/dist/index.d.mts +2 -0
  8. package/dist/index.mjs +3 -0
  9. package/dist/test/utils.d.mts +77 -0
  10. package/dist/test/utils.d.mts.map +1 -0
  11. package/dist/test/utils.mjs +221 -0
  12. package/dist/test/utils.mjs.map +1 -0
  13. package/package.json +29 -22
  14. package/src/codecs/decoding.ts +84 -3
  15. package/src/codecs/encoding.ts +5 -15
  16. package/src/codecs/json-schema-validation.ts +61 -0
  17. package/src/codecs/validation.ts +6 -5
  18. package/src/exports/index.ts +19 -7
  19. package/src/lower-sql-plan.ts +9 -9
  20. package/src/plugins/budgets.ts +375 -0
  21. package/src/plugins/lints.ts +211 -0
  22. package/src/sql-context.ts +454 -108
  23. package/src/sql-family-adapter.ts +16 -22
  24. package/src/sql-marker.ts +2 -2
  25. package/src/sql-runtime.ts +136 -47
  26. package/test/async-iterable-result.test.ts +42 -37
  27. package/test/budgets.test.ts +481 -0
  28. package/test/context.types.test-d.ts +68 -0
  29. package/test/execution-stack.test.ts +164 -0
  30. package/test/json-schema-validation.test.ts +571 -0
  31. package/test/lints.test.ts +161 -0
  32. package/test/mutation-default-generators.test.ts +254 -0
  33. package/test/parameterized-types.test.ts +529 -0
  34. package/test/sql-context.test.ts +301 -134
  35. package/test/sql-family-adapter.test.ts +37 -20
  36. package/test/sql-runtime.test.ts +220 -49
  37. package/test/utils.ts +102 -64
  38. package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js +0 -137863
  39. package/dist/accelerate-EEKAFGN3-P6A6XJWJ.js.map +0 -1
  40. package/dist/amcheck-24VY6X5V.js +0 -13
  41. package/dist/amcheck-24VY6X5V.js.map +0 -1
  42. package/dist/bloom-VS74NLHT.js +0 -13
  43. package/dist/bloom-VS74NLHT.js.map +0 -1
  44. package/dist/btree_gin-WBC4EAAI.js +0 -13
  45. package/dist/btree_gin-WBC4EAAI.js.map +0 -1
  46. package/dist/btree_gist-UNC6QD3M.js +0 -13
  47. package/dist/btree_gist-UNC6QD3M.js.map +0 -1
  48. package/dist/chunk-3KTOEDFX.js +0 -49
  49. package/dist/chunk-3KTOEDFX.js.map +0 -1
  50. package/dist/chunk-47DZBRQC.js +0 -1280
  51. package/dist/chunk-47DZBRQC.js.map +0 -1
  52. package/dist/chunk-52N6AFZM.js +0 -133
  53. package/dist/chunk-52N6AFZM.js.map +0 -1
  54. package/dist/chunk-7D4SUZUM.js +0 -38
  55. package/dist/chunk-7D4SUZUM.js.map +0 -1
  56. package/dist/chunk-C6I3V3DM.js +0 -455
  57. package/dist/chunk-C6I3V3DM.js.map +0 -1
  58. package/dist/chunk-ECWIHLAT.js +0 -37
  59. package/dist/chunk-ECWIHLAT.js.map +0 -1
  60. package/dist/chunk-EI626SDC.js +0 -105
  61. package/dist/chunk-EI626SDC.js.map +0 -1
  62. package/dist/chunk-UKKOYUGL.js +0 -578
  63. package/dist/chunk-UKKOYUGL.js.map +0 -1
  64. package/dist/chunk-XPLNMXQV.js +0 -1537
  65. package/dist/chunk-XPLNMXQV.js.map +0 -1
  66. package/dist/citext-T7MXGUY7.js +0 -13
  67. package/dist/citext-T7MXGUY7.js.map +0 -1
  68. package/dist/client-5FENX6AW.js +0 -299
  69. package/dist/client-5FENX6AW.js.map +0 -1
  70. package/dist/cube-TFDQBZCI.js +0 -13
  71. package/dist/cube-TFDQBZCI.js.map +0 -1
  72. package/dist/dict_int-AEUOPGWP.js +0 -13
  73. package/dist/dict_int-AEUOPGWP.js.map +0 -1
  74. package/dist/dict_xsyn-DAAYX3FL.js +0 -13
  75. package/dist/dict_xsyn-DAAYX3FL.js.map +0 -1
  76. package/dist/dist-AQ3LWXOX.js +0 -570
  77. package/dist/dist-AQ3LWXOX.js.map +0 -1
  78. package/dist/dist-LBVX6BJW.js +0 -189
  79. package/dist/dist-LBVX6BJW.js.map +0 -1
  80. package/dist/dist-WLKUVDN2.js +0 -5127
  81. package/dist/dist-WLKUVDN2.js.map +0 -1
  82. package/dist/earthdistance-KIGTF4LE.js +0 -13
  83. package/dist/earthdistance-KIGTF4LE.js.map +0 -1
  84. package/dist/file_fdw-5N55UP6I.js +0 -13
  85. package/dist/file_fdw-5N55UP6I.js.map +0 -1
  86. package/dist/fuzzystrmatch-KN3YWBFP.js +0 -13
  87. package/dist/fuzzystrmatch-KN3YWBFP.js.map +0 -1
  88. package/dist/hstore-YX726NKN.js +0 -13
  89. package/dist/hstore-YX726NKN.js.map +0 -1
  90. package/dist/http-exception-FZY2H4OF.js +0 -8
  91. package/dist/http-exception-FZY2H4OF.js.map +0 -1
  92. package/dist/index.js +0 -30
  93. package/dist/index.js.map +0 -1
  94. package/dist/intarray-NKVXNO2D.js +0 -13
  95. package/dist/intarray-NKVXNO2D.js.map +0 -1
  96. package/dist/isn-FTEMJGEV.js +0 -13
  97. package/dist/isn-FTEMJGEV.js.map +0 -1
  98. package/dist/lo-DB7L4NGI.js +0 -13
  99. package/dist/lo-DB7L4NGI.js.map +0 -1
  100. package/dist/logger-WQ7SHNDD.js +0 -68
  101. package/dist/logger-WQ7SHNDD.js.map +0 -1
  102. package/dist/ltree-Z32TZT6W.js +0 -13
  103. package/dist/ltree-Z32TZT6W.js.map +0 -1
  104. package/dist/nodefs-NM46ACH7.js +0 -31
  105. package/dist/nodefs-NM46ACH7.js.map +0 -1
  106. package/dist/opfs-ahp-NJO33LVZ.js +0 -332
  107. package/dist/opfs-ahp-NJO33LVZ.js.map +0 -1
  108. package/dist/pageinspect-YP3IZR4X.js +0 -13
  109. package/dist/pageinspect-YP3IZR4X.js.map +0 -1
  110. package/dist/pg_buffercache-7TD5J2FB.js +0 -13
  111. package/dist/pg_buffercache-7TD5J2FB.js.map +0 -1
  112. package/dist/pg_dump-SG4KYBUB.js +0 -2492
  113. package/dist/pg_dump-SG4KYBUB.js.map +0 -1
  114. package/dist/pg_freespacemap-DZDNCPZK.js +0 -13
  115. package/dist/pg_freespacemap-DZDNCPZK.js.map +0 -1
  116. package/dist/pg_surgery-J2MUEWEP.js +0 -13
  117. package/dist/pg_surgery-J2MUEWEP.js.map +0 -1
  118. package/dist/pg_trgm-7VNQOYS6.js +0 -13
  119. package/dist/pg_trgm-7VNQOYS6.js.map +0 -1
  120. package/dist/pg_visibility-TTSIPHFL.js +0 -13
  121. package/dist/pg_visibility-TTSIPHFL.js.map +0 -1
  122. package/dist/pg_walinspect-KPFHSHRJ.js +0 -13
  123. package/dist/pg_walinspect-KPFHSHRJ.js.map +0 -1
  124. package/dist/proxy-signals-GUDAMDHV.js +0 -39
  125. package/dist/proxy-signals-GUDAMDHV.js.map +0 -1
  126. package/dist/seg-IYVDLE4O.js +0 -13
  127. package/dist/seg-IYVDLE4O.js.map +0 -1
  128. package/dist/src/codecs/decoding.d.ts +0 -4
  129. package/dist/src/codecs/decoding.d.ts.map +0 -1
  130. package/dist/src/codecs/encoding.d.ts +0 -5
  131. package/dist/src/codecs/encoding.d.ts.map +0 -1
  132. package/dist/src/codecs/validation.d.ts +0 -6
  133. package/dist/src/codecs/validation.d.ts.map +0 -1
  134. package/dist/src/exports/index.d.ts +0 -11
  135. package/dist/src/exports/index.d.ts.map +0 -1
  136. package/dist/src/index.d.ts +0 -2
  137. package/dist/src/index.d.ts.map +0 -1
  138. package/dist/src/lower-sql-plan.d.ts +0 -15
  139. package/dist/src/lower-sql-plan.d.ts.map +0 -1
  140. package/dist/src/sql-context.d.ts +0 -65
  141. package/dist/src/sql-context.d.ts.map +0 -1
  142. package/dist/src/sql-family-adapter.d.ts +0 -10
  143. package/dist/src/sql-family-adapter.d.ts.map +0 -1
  144. package/dist/src/sql-marker.d.ts +0 -22
  145. package/dist/src/sql-marker.d.ts.map +0 -1
  146. package/dist/src/sql-runtime.d.ts +0 -25
  147. package/dist/src/sql-runtime.d.ts.map +0 -1
  148. package/dist/tablefunc-EF4RCS7S.js +0 -13
  149. package/dist/tablefunc-EF4RCS7S.js.map +0 -1
  150. package/dist/tcn-3VT5BQYW.js +0 -13
  151. package/dist/tcn-3VT5BQYW.js.map +0 -1
  152. package/dist/test/utils.d.ts +0 -59
  153. package/dist/test/utils.d.ts.map +0 -1
  154. package/dist/test/utils.js +0 -24634
  155. package/dist/test/utils.js.map +0 -1
  156. package/dist/tiny-CW6F4GX6.js +0 -10
  157. package/dist/tiny-CW6F4GX6.js.map +0 -1
  158. package/dist/tsm_system_rows-ES7KNUQH.js +0 -13
  159. package/dist/tsm_system_rows-ES7KNUQH.js.map +0 -1
  160. package/dist/tsm_system_time-76WEIMBG.js +0 -13
  161. package/dist/tsm_system_time-76WEIMBG.js.map +0 -1
  162. package/dist/unaccent-7RYF3R64.js +0 -13
  163. package/dist/unaccent-7RYF3R64.js.map +0 -1
  164. package/dist/utility-Q5A254LJ-J4HTKZPT.js +0 -347
  165. package/dist/utility-Q5A254LJ-J4HTKZPT.js.map +0 -1
  166. package/dist/uuid_ossp-4ETE4FPE.js +0 -13
  167. package/dist/uuid_ossp-4ETE4FPE.js.map +0 -1
  168. package/dist/vector-74GPNV7V.js +0 -13
  169. package/dist/vector-74GPNV7V.js.map +0 -1
  170. package/src/index.ts +0 -1
@@ -0,0 +1,529 @@
1
+ import type { Contract } from '@prisma-next/contract/types';
2
+ import { coreHash, profileHash } from '@prisma-next/contract/types';
3
+ import type { SqlStorage, StorageTypeInstance } from '@prisma-next/sql-contract/types';
4
+ import { codec, createCodecRegistry } from '@prisma-next/sql-relational-core/ast';
5
+ import { ifDefined } from '@prisma-next/utils/defined';
6
+ import type { Type } from 'arktype';
7
+ import { type as arktype } from 'arktype';
8
+ import { describe, expect, it } from 'vitest';
9
+ import type {
10
+ RuntimeParameterizedCodecDescriptor,
11
+ SqlRuntimeExtensionDescriptor,
12
+ } from '../src/sql-context';
13
+ import { createStubAdapter, createTestContext } from './utils';
14
+
15
+ // =============================================================================
16
+ // Test helpers
17
+ // =============================================================================
18
+
19
+ function createParamTypesTestContract(
20
+ options?: Partial<{
21
+ types: Record<string, StorageTypeInstance>;
22
+ tableColumns: Record<
23
+ string,
24
+ {
25
+ nativeType: string;
26
+ codecId: string;
27
+ nullable: boolean;
28
+ typeParams?: Record<string, unknown>;
29
+ typeRef?: string;
30
+ }
31
+ >;
32
+ }>,
33
+ ): Contract<SqlStorage> {
34
+ return {
35
+ targetFamily: 'sql',
36
+ target: 'postgres',
37
+ profileHash: profileHash('sha256:test'),
38
+ models: {},
39
+ roots: {},
40
+ storage: {
41
+ storageHash: coreHash('sha256:test'),
42
+ tables: {
43
+ test: {
44
+ columns: options?.tableColumns ?? {
45
+ id: { nativeType: 'int4', codecId: 'pg/int4@1', nullable: false },
46
+ },
47
+ primaryKey: { columns: ['id'] },
48
+ uniques: [],
49
+ indexes: [],
50
+ foreignKeys: [],
51
+ },
52
+ },
53
+ ...ifDefined('types', options?.types),
54
+ },
55
+ extensionPacks: {},
56
+ capabilities: {},
57
+ meta: {},
58
+ };
59
+ }
60
+
61
+ // =============================================================================
62
+ // Tests: Parameterized type validation
63
+ // =============================================================================
64
+
65
+ describe('parameterized types', () => {
66
+ describe('storage.types validation', () => {
67
+ it('creates context with empty storage.types', () => {
68
+ const contract = createParamTypesTestContract({ types: {} });
69
+ const context = createTestContext(contract, createStubAdapter());
70
+
71
+ expect(context.contract.storage.types).toEqual({});
72
+ expect(context.types).toEqual({});
73
+ });
74
+
75
+ it('creates context with storage.types containing valid type instances', () => {
76
+ const contract = createParamTypesTestContract({
77
+ types: {
78
+ Vector1536: {
79
+ codecId: 'pg/vector@1',
80
+ nativeType: 'vector',
81
+ typeParams: { length: 1536 },
82
+ },
83
+ },
84
+ });
85
+ const context = createTestContext(contract, createStubAdapter());
86
+
87
+ expect(context.contract.storage.types).toEqual({
88
+ Vector1536: {
89
+ codecId: 'pg/vector@1',
90
+ nativeType: 'vector',
91
+ typeParams: { length: 1536 },
92
+ },
93
+ });
94
+ // types registry should contain the raw type instance (no init hook provided)
95
+ expect(context.types['Vector1536']).toBeDefined();
96
+ });
97
+ });
98
+
99
+ describe('typeParams validation with paramsSchema', () => {
100
+ const vectorParamsSchema = arktype({
101
+ length: 'number',
102
+ });
103
+
104
+ function createVectorExtensionDescriptor(options?: {
105
+ paramsSchema?: Type<{ length: number }>;
106
+ init?: (params: { length: number }) => { dimensions: number };
107
+ }): SqlRuntimeExtensionDescriptor<'postgres'> {
108
+ // biome-ignore lint/suspicious/noExplicitAny: test helper with flexible type params
109
+ const parameterizedCodecs: RuntimeParameterizedCodecDescriptor<any, any>[] = [
110
+ {
111
+ codecId: 'pg/vector@1',
112
+ paramsSchema: options?.paramsSchema ?? vectorParamsSchema,
113
+ ...ifDefined('init', options?.init),
114
+ },
115
+ ];
116
+
117
+ const registry = createCodecRegistry();
118
+ registry.register(
119
+ codec({
120
+ typeId: 'pg/vector@1',
121
+ targetTypes: ['vector'],
122
+ encode: (v: number[]) => v,
123
+ decode: (w: number[]) => w,
124
+ }),
125
+ );
126
+
127
+ return {
128
+ kind: 'extension' as const,
129
+ id: 'pgvector',
130
+ version: '0.0.1',
131
+ familyId: 'sql' as const,
132
+ targetId: 'postgres' as const,
133
+ codecs: () => registry,
134
+ parameterizedCodecs: () => parameterizedCodecs,
135
+ create() {
136
+ return {
137
+ familyId: 'sql' as const,
138
+ targetId: 'postgres' as const,
139
+ };
140
+ },
141
+ };
142
+ }
143
+
144
+ it('validates typeParams against codec paramsSchema', () => {
145
+ const contract = createParamTypesTestContract({
146
+ types: {
147
+ Vector1536: {
148
+ codecId: 'pg/vector@1',
149
+ nativeType: 'vector',
150
+ typeParams: { length: 1536 },
151
+ },
152
+ },
153
+ });
154
+
155
+ const context = createTestContext(contract, createStubAdapter(), {
156
+ extensionPacks: [createVectorExtensionDescriptor()],
157
+ });
158
+
159
+ expect(context.types['Vector1536']).toBeDefined();
160
+ });
161
+
162
+ it('rejects invalid typeParams with stable error code', () => {
163
+ const contract = createParamTypesTestContract({
164
+ types: {
165
+ InvalidVector: {
166
+ codecId: 'pg/vector@1',
167
+ nativeType: 'vector',
168
+ typeParams: { length: 'not-a-number' },
169
+ },
170
+ },
171
+ });
172
+
173
+ let thrownError: unknown;
174
+ try {
175
+ createTestContext(contract, createStubAdapter(), {
176
+ extensionPacks: [createVectorExtensionDescriptor()],
177
+ });
178
+ } catch (e) {
179
+ thrownError = e;
180
+ }
181
+
182
+ expect(thrownError).toBeDefined();
183
+ expect(thrownError).toMatchObject({
184
+ code: 'RUNTIME.TYPE_PARAMS_INVALID',
185
+ category: 'RUNTIME',
186
+ severity: 'error',
187
+ details: {
188
+ codecId: 'pg/vector@1',
189
+ typeName: 'InvalidVector',
190
+ },
191
+ });
192
+ });
193
+
194
+ it('rejects missing required typeParams with stable error code', () => {
195
+ const contract = createParamTypesTestContract({
196
+ types: {
197
+ InvalidVector: {
198
+ codecId: 'pg/vector@1',
199
+ nativeType: 'vector',
200
+ typeParams: {},
201
+ },
202
+ },
203
+ });
204
+
205
+ let thrownError: unknown;
206
+ try {
207
+ createTestContext(contract, createStubAdapter(), {
208
+ extensionPacks: [createVectorExtensionDescriptor()],
209
+ });
210
+ } catch (e) {
211
+ thrownError = e;
212
+ }
213
+
214
+ expect(thrownError).toBeDefined();
215
+ expect(thrownError).toMatchObject({
216
+ code: 'RUNTIME.TYPE_PARAMS_INVALID',
217
+ category: 'RUNTIME',
218
+ severity: 'error',
219
+ });
220
+ });
221
+ });
222
+
223
+ describe('init hook for type helpers', () => {
224
+ it('calls init hook and stores result in context.types', () => {
225
+ const vectorParamsSchema = arktype({
226
+ length: 'number',
227
+ });
228
+
229
+ const initFn = (params: { length: number }) => ({
230
+ dimensions: params.length,
231
+ isVector: true,
232
+ });
233
+
234
+ const registry = createCodecRegistry();
235
+ registry.register(
236
+ codec({
237
+ typeId: 'pg/vector@1',
238
+ targetTypes: ['vector'],
239
+ encode: (v: number[]) => v,
240
+ decode: (w: number[]) => w,
241
+ }),
242
+ );
243
+
244
+ const parameterizedCodecs = [
245
+ {
246
+ codecId: 'pg/vector@1',
247
+ paramsSchema: vectorParamsSchema,
248
+ init: initFn,
249
+ },
250
+ ];
251
+
252
+ const extensionDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
253
+ kind: 'extension' as const,
254
+ id: 'pgvector',
255
+ version: '0.0.1',
256
+ familyId: 'sql' as const,
257
+ targetId: 'postgres' as const,
258
+ codecs: () => registry,
259
+ parameterizedCodecs: () => parameterizedCodecs,
260
+ create() {
261
+ return {
262
+ familyId: 'sql' as const,
263
+ targetId: 'postgres' as const,
264
+ };
265
+ },
266
+ };
267
+
268
+ const contract = createParamTypesTestContract({
269
+ types: {
270
+ Vector1536: {
271
+ codecId: 'pg/vector@1',
272
+ nativeType: 'vector',
273
+ typeParams: { length: 1536 },
274
+ },
275
+ },
276
+ });
277
+
278
+ const context = createTestContext(contract, createStubAdapter(), {
279
+ extensionPacks: [extensionDescriptor],
280
+ });
281
+
282
+ expect(context.types['Vector1536']).toEqual({
283
+ dimensions: 1536,
284
+ isVector: true,
285
+ });
286
+ });
287
+
288
+ it('stores full type instance when no init hook is provided', () => {
289
+ const vectorParamsSchema = arktype({
290
+ length: 'number',
291
+ });
292
+
293
+ const registry = createCodecRegistry();
294
+ registry.register(
295
+ codec({
296
+ typeId: 'pg/vector@1',
297
+ targetTypes: ['vector'],
298
+ encode: (v: number[]) => v,
299
+ decode: (w: number[]) => w,
300
+ }),
301
+ );
302
+
303
+ const parameterizedCodecs = [
304
+ {
305
+ codecId: 'pg/vector@1',
306
+ paramsSchema: vectorParamsSchema,
307
+ },
308
+ ];
309
+
310
+ const extensionDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
311
+ kind: 'extension' as const,
312
+ id: 'pgvector',
313
+ version: '0.0.1',
314
+ familyId: 'sql' as const,
315
+ targetId: 'postgres' as const,
316
+ codecs: () => registry,
317
+ parameterizedCodecs: () => parameterizedCodecs,
318
+ create() {
319
+ return {
320
+ familyId: 'sql' as const,
321
+ targetId: 'postgres' as const,
322
+ };
323
+ },
324
+ };
325
+
326
+ const contract = createParamTypesTestContract({
327
+ types: {
328
+ Vector1536: {
329
+ codecId: 'pg/vector@1',
330
+ nativeType: 'vector',
331
+ typeParams: { length: 1536 },
332
+ },
333
+ },
334
+ });
335
+
336
+ const context = createTestContext(contract, createStubAdapter(), {
337
+ extensionPacks: [extensionDescriptor],
338
+ });
339
+
340
+ // Without init hook, stores the full type instance (matches contract typing)
341
+ expect(context.types['Vector1536']).toEqual({
342
+ codecId: 'pg/vector@1',
343
+ nativeType: 'vector',
344
+ typeParams: { length: 1536 },
345
+ });
346
+ });
347
+ });
348
+
349
+ describe('column typeParams validation', () => {
350
+ it('validates inline column typeParams against codec paramsSchema', () => {
351
+ const vectorParamsSchema = arktype({
352
+ length: 'number',
353
+ });
354
+
355
+ const registry = createCodecRegistry();
356
+ registry.register(
357
+ codec({
358
+ typeId: 'pg/vector@1',
359
+ targetTypes: ['vector'],
360
+ encode: (v: number[]) => v,
361
+ decode: (w: number[]) => w,
362
+ }),
363
+ );
364
+
365
+ const parameterizedCodecs = [
366
+ {
367
+ codecId: 'pg/vector@1',
368
+ paramsSchema: vectorParamsSchema,
369
+ },
370
+ ];
371
+
372
+ const extensionDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
373
+ kind: 'extension' as const,
374
+ id: 'pgvector',
375
+ version: '0.0.1',
376
+ familyId: 'sql' as const,
377
+ targetId: 'postgres' as const,
378
+ codecs: () => registry,
379
+ parameterizedCodecs: () => parameterizedCodecs,
380
+ create() {
381
+ return {
382
+ familyId: 'sql' as const,
383
+ targetId: 'postgres' as const,
384
+ };
385
+ },
386
+ };
387
+
388
+ const contract = createParamTypesTestContract({
389
+ tableColumns: {
390
+ id: { nativeType: 'int4', codecId: 'pg/int4@1', nullable: false },
391
+ embedding: {
392
+ nativeType: 'vector',
393
+ codecId: 'pg/vector@1',
394
+ nullable: false,
395
+ typeParams: { length: 1536 },
396
+ },
397
+ },
398
+ });
399
+
400
+ // Should not throw - valid typeParams
401
+ const context = createTestContext(contract, createStubAdapter(), {
402
+ extensionPacks: [extensionDescriptor],
403
+ });
404
+
405
+ expect(context.contract).toBe(contract);
406
+ });
407
+
408
+ it('rejects invalid inline column typeParams with stable error code', () => {
409
+ const vectorParamsSchema = arktype({
410
+ length: 'number',
411
+ });
412
+
413
+ const registry = createCodecRegistry();
414
+ registry.register(
415
+ codec({
416
+ typeId: 'pg/vector@1',
417
+ targetTypes: ['vector'],
418
+ encode: (v: number[]) => v,
419
+ decode: (w: number[]) => w,
420
+ }),
421
+ );
422
+
423
+ const parameterizedCodecs = [
424
+ {
425
+ codecId: 'pg/vector@1',
426
+ paramsSchema: vectorParamsSchema,
427
+ },
428
+ ];
429
+
430
+ const extensionDescriptor: SqlRuntimeExtensionDescriptor<'postgres'> = {
431
+ kind: 'extension' as const,
432
+ id: 'pgvector',
433
+ version: '0.0.1',
434
+ familyId: 'sql' as const,
435
+ targetId: 'postgres' as const,
436
+ codecs: () => registry,
437
+ parameterizedCodecs: () => parameterizedCodecs,
438
+ create() {
439
+ return {
440
+ familyId: 'sql' as const,
441
+ targetId: 'postgres' as const,
442
+ };
443
+ },
444
+ };
445
+
446
+ const contract = createParamTypesTestContract({
447
+ tableColumns: {
448
+ id: { nativeType: 'int4', codecId: 'pg/int4@1', nullable: false },
449
+ embedding: {
450
+ nativeType: 'vector',
451
+ codecId: 'pg/vector@1',
452
+ nullable: false,
453
+ typeParams: { length: 'invalid' },
454
+ },
455
+ },
456
+ });
457
+
458
+ let thrownError: unknown;
459
+ try {
460
+ createTestContext(contract, createStubAdapter(), {
461
+ extensionPacks: [extensionDescriptor],
462
+ });
463
+ } catch (e) {
464
+ thrownError = e;
465
+ }
466
+
467
+ expect(thrownError).toBeDefined();
468
+ expect(thrownError).toMatchObject({
469
+ code: 'RUNTIME.TYPE_PARAMS_INVALID',
470
+ category: 'RUNTIME',
471
+ severity: 'error',
472
+ details: {
473
+ tableName: 'test',
474
+ columnName: 'embedding',
475
+ },
476
+ });
477
+ });
478
+ });
479
+
480
+ describe('duplicate codec descriptor detection', () => {
481
+ it('throws RUNTIME.DUPLICATE_PARAMETERIZED_CODEC when multiple extensions provide same codecId', () => {
482
+ const vectorParamsSchema = arktype({
483
+ length: 'number',
484
+ });
485
+
486
+ function createVectorExtension(id: string): SqlRuntimeExtensionDescriptor<'postgres'> {
487
+ const parameterizedCodecs = [
488
+ {
489
+ codecId: 'pg/vector@1',
490
+ paramsSchema: vectorParamsSchema,
491
+ },
492
+ ];
493
+
494
+ return {
495
+ kind: 'extension' as const,
496
+ id,
497
+ version: '0.0.1',
498
+ familyId: 'sql' as const,
499
+ targetId: 'postgres' as const,
500
+ codecs: () => createCodecRegistry(),
501
+ parameterizedCodecs: () => parameterizedCodecs,
502
+ create() {
503
+ return {
504
+ familyId: 'sql' as const,
505
+ targetId: 'postgres' as const,
506
+ };
507
+ },
508
+ };
509
+ }
510
+
511
+ const contract = createParamTypesTestContract();
512
+
513
+ expect(() =>
514
+ createTestContext(contract, createStubAdapter(), {
515
+ extensionPacks: [createVectorExtension('ext-1'), createVectorExtension('ext-2')],
516
+ }),
517
+ ).toThrow(
518
+ expect.objectContaining({
519
+ code: 'RUNTIME.DUPLICATE_PARAMETERIZED_CODEC',
520
+ category: 'RUNTIME',
521
+ severity: 'error',
522
+ details: {
523
+ codecId: 'pg/vector@1',
524
+ },
525
+ }),
526
+ );
527
+ });
528
+ });
529
+ });