@prisma-next/adapter-postgres 0.3.0-dev.33 → 0.3.0-dev.36

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 (88) hide show
  1. package/README.md +64 -2
  2. package/dist/adapter-DB1CK2jM.mjs +265 -0
  3. package/dist/adapter-DB1CK2jM.mjs.map +1 -0
  4. package/dist/adapter.d.mts +23 -0
  5. package/dist/adapter.d.mts.map +1 -0
  6. package/dist/adapter.mjs +3 -0
  7. package/dist/codec-ids-Bsm9c7ns.mjs +29 -0
  8. package/dist/codec-ids-Bsm9c7ns.mjs.map +1 -0
  9. package/dist/codec-types.d.mts +141 -0
  10. package/dist/codec-types.d.mts.map +1 -0
  11. package/dist/codec-types.mjs +3 -0
  12. package/dist/codecs-DcC1nPzh.mjs +206 -0
  13. package/dist/codecs-DcC1nPzh.mjs.map +1 -0
  14. package/dist/column-types.d.mts +110 -0
  15. package/dist/column-types.d.mts.map +1 -0
  16. package/dist/column-types.mjs +180 -0
  17. package/dist/column-types.mjs.map +1 -0
  18. package/dist/control.d.mts +111 -0
  19. package/dist/control.d.mts.map +1 -0
  20. package/dist/control.mjs +405 -0
  21. package/dist/control.mjs.map +1 -0
  22. package/dist/descriptor-meta-D7pxo-wo.mjs +996 -0
  23. package/dist/descriptor-meta-D7pxo-wo.mjs.map +1 -0
  24. package/dist/runtime.d.mts +19 -0
  25. package/dist/runtime.d.mts.map +1 -0
  26. package/dist/runtime.mjs +85 -0
  27. package/dist/runtime.mjs.map +1 -0
  28. package/dist/types-BY395pUv.d.mts +19 -0
  29. package/dist/types-BY395pUv.d.mts.map +1 -0
  30. package/dist/types.d.mts +2 -0
  31. package/dist/types.mjs +1 -0
  32. package/package.json +32 -41
  33. package/src/core/adapter.ts +90 -17
  34. package/src/core/codec-ids.ts +28 -0
  35. package/src/core/codecs.ts +316 -19
  36. package/src/core/control-adapter.ts +341 -180
  37. package/src/core/default-normalizer.ts +77 -0
  38. package/src/core/descriptor-meta.ts +221 -9
  39. package/src/core/enum-control-hooks.ts +735 -0
  40. package/src/core/json-schema-type-expression.ts +131 -0
  41. package/src/core/json-schema-validator.ts +53 -0
  42. package/src/core/parameterized-types.ts +118 -0
  43. package/src/core/sql-utils.ts +111 -0
  44. package/src/core/standard-schema.ts +71 -0
  45. package/src/exports/codec-types.ts +73 -1
  46. package/src/exports/column-types.ts +233 -9
  47. package/src/exports/control.ts +16 -9
  48. package/src/exports/runtime.ts +61 -18
  49. package/dist/chunk-HD5YISNQ.js +0 -47
  50. package/dist/chunk-HD5YISNQ.js.map +0 -1
  51. package/dist/chunk-J3XSOAM2.js +0 -162
  52. package/dist/chunk-J3XSOAM2.js.map +0 -1
  53. package/dist/chunk-Y6L4BBLR.js +0 -309
  54. package/dist/chunk-Y6L4BBLR.js.map +0 -1
  55. package/dist/core/adapter.d.ts +0 -19
  56. package/dist/core/adapter.d.ts.map +0 -1
  57. package/dist/core/codecs.d.ts +0 -110
  58. package/dist/core/codecs.d.ts.map +0 -1
  59. package/dist/core/control-adapter.d.ts +0 -33
  60. package/dist/core/control-adapter.d.ts.map +0 -1
  61. package/dist/core/descriptor-meta.d.ts +0 -72
  62. package/dist/core/descriptor-meta.d.ts.map +0 -1
  63. package/dist/core/types.d.ts +0 -16
  64. package/dist/core/types.d.ts.map +0 -1
  65. package/dist/exports/adapter.d.ts +0 -2
  66. package/dist/exports/adapter.d.ts.map +0 -1
  67. package/dist/exports/adapter.js +0 -8
  68. package/dist/exports/adapter.js.map +0 -1
  69. package/dist/exports/codec-types.d.ts +0 -11
  70. package/dist/exports/codec-types.d.ts.map +0 -1
  71. package/dist/exports/codec-types.js +0 -7
  72. package/dist/exports/codec-types.js.map +0 -1
  73. package/dist/exports/column-types.d.ts +0 -17
  74. package/dist/exports/column-types.d.ts.map +0 -1
  75. package/dist/exports/column-types.js +0 -49
  76. package/dist/exports/column-types.js.map +0 -1
  77. package/dist/exports/control.d.ts +0 -8
  78. package/dist/exports/control.d.ts.map +0 -1
  79. package/dist/exports/control.js +0 -279
  80. package/dist/exports/control.js.map +0 -1
  81. package/dist/exports/runtime.d.ts +0 -15
  82. package/dist/exports/runtime.d.ts.map +0 -1
  83. package/dist/exports/runtime.js +0 -20
  84. package/dist/exports/runtime.js.map +0 -1
  85. package/dist/exports/types.d.ts +0 -2
  86. package/dist/exports/types.d.ts.map +0 -1
  87. package/dist/exports/types.js +0 -1
  88. package/dist/exports/types.js.map +0 -1
@@ -11,11 +11,89 @@
11
11
  * at compile time (to derive CodecTypes).
12
12
  */
13
13
 
14
- import { codec, defineCodecs } from '@prisma-next/sql-relational-core/ast';
14
+ import type { Codec, CodecMeta } from '@prisma-next/sql-relational-core/ast';
15
+ import { codec, defineCodecs, sqlCodecDefinitions } from '@prisma-next/sql-relational-core/ast';
16
+ import { ifDefined } from '@prisma-next/utils/defined';
17
+ import { type as arktype } from 'arktype';
18
+ import {
19
+ PG_BIT_CODEC_ID,
20
+ PG_BOOL_CODEC_ID,
21
+ PG_CHAR_CODEC_ID,
22
+ PG_ENUM_CODEC_ID,
23
+ PG_FLOAT_CODEC_ID,
24
+ PG_FLOAT4_CODEC_ID,
25
+ PG_FLOAT8_CODEC_ID,
26
+ PG_INT_CODEC_ID,
27
+ PG_INT2_CODEC_ID,
28
+ PG_INT4_CODEC_ID,
29
+ PG_INT8_CODEC_ID,
30
+ PG_INTERVAL_CODEC_ID,
31
+ PG_JSON_CODEC_ID,
32
+ PG_JSONB_CODEC_ID,
33
+ PG_NUMERIC_CODEC_ID,
34
+ PG_TEXT_CODEC_ID,
35
+ PG_TIME_CODEC_ID,
36
+ PG_TIMESTAMP_CODEC_ID,
37
+ PG_TIMESTAMPTZ_CODEC_ID,
38
+ PG_TIMETZ_CODEC_ID,
39
+ PG_VARBIT_CODEC_ID,
40
+ PG_VARCHAR_CODEC_ID,
41
+ } from './codec-ids';
42
+
43
+ const lengthParamsSchema = arktype({
44
+ length: 'number.integer > 0',
45
+ });
46
+
47
+ const numericParamsSchema = arktype({
48
+ precision: 'number.integer > 0 & number.integer <= 1000',
49
+ 'scale?': 'number.integer >= 0',
50
+ });
51
+
52
+ const precisionParamsSchema = arktype({
53
+ 'precision?': 'number.integer >= 0 & number.integer <= 6',
54
+ });
55
+
56
+ function aliasCodec<
57
+ Id extends string,
58
+ TWire,
59
+ TJs,
60
+ TParams = Record<string, unknown>,
61
+ THelper = unknown,
62
+ >(
63
+ base: Codec<string, TWire, TJs, TParams, THelper>,
64
+ options: {
65
+ readonly typeId: Id;
66
+ readonly targetTypes: readonly string[];
67
+ readonly meta?: CodecMeta;
68
+ },
69
+ ): Codec<Id, TWire, TJs, TParams, THelper> {
70
+ return {
71
+ id: options.typeId,
72
+ targetTypes: options.targetTypes,
73
+ ...ifDefined('meta', options.meta),
74
+ ...ifDefined('paramsSchema', base.paramsSchema),
75
+ ...ifDefined('init', base.init),
76
+ ...ifDefined('encode', base.encode),
77
+ decode: base.decode,
78
+ };
79
+ }
80
+
81
+ const sqlCharCodec = sqlCodecDefinitions.char.codec;
82
+ const sqlVarcharCodec = sqlCodecDefinitions.varchar.codec;
83
+ const sqlIntCodec = sqlCodecDefinitions.int.codec;
84
+ const sqlFloatCodec = sqlCodecDefinitions.float.codec;
85
+
86
+ export type JsonValue =
87
+ | string
88
+ | number
89
+ | boolean
90
+ | null
91
+ | { readonly [key: string]: JsonValue }
92
+ | readonly JsonValue[];
15
93
 
16
94
  // Create individual codec instances
17
95
  const pgTextCodec = codec({
18
- typeId: 'pg/text@1',
96
+ typeId: PG_TEXT_CODEC_ID,
19
97
  targetTypes: ['text'],
20
98
  encode: (value: string): string => value,
21
99
  decode: (wire: string): string => wire,
@@ -30,8 +108,64 @@ const pgTextCodec = codec({
30
108
  },
31
109
  });
32
110
 
33
- const pgInt4Codec = codec<'pg/int4@1', number, number>({
34
- typeId: 'pg/int4@1',
111
+ const pgCharCodec = aliasCodec(sqlCharCodec, {
112
+ typeId: PG_CHAR_CODEC_ID,
113
+ targetTypes: ['character'],
114
+ meta: {
115
+ db: {
116
+ sql: {
117
+ postgres: {
118
+ nativeType: 'character',
119
+ },
120
+ },
121
+ },
122
+ },
123
+ });
124
+
125
+ const pgVarcharCodec = aliasCodec(sqlVarcharCodec, {
126
+ typeId: PG_VARCHAR_CODEC_ID,
127
+ targetTypes: ['character varying'],
128
+ meta: {
129
+ db: {
130
+ sql: {
131
+ postgres: {
132
+ nativeType: 'character varying',
133
+ },
134
+ },
135
+ },
136
+ },
137
+ });
138
+
139
+ const pgIntCodec = aliasCodec(sqlIntCodec, {
140
+ typeId: PG_INT_CODEC_ID,
141
+ targetTypes: ['int4'],
142
+ meta: {
143
+ db: {
144
+ sql: {
145
+ postgres: {
146
+ nativeType: 'integer',
147
+ },
148
+ },
149
+ },
150
+ },
151
+ });
152
+
153
+ const pgFloatCodec = aliasCodec(sqlFloatCodec, {
154
+ typeId: PG_FLOAT_CODEC_ID,
155
+ targetTypes: ['float8'],
156
+ meta: {
157
+ db: {
158
+ sql: {
159
+ postgres: {
160
+ nativeType: 'double precision',
161
+ },
162
+ },
163
+ },
164
+ },
165
+ });
166
+
167
+ const pgInt4Codec = codec<typeof PG_INT4_CODEC_ID, number, number>({
168
+ typeId: PG_INT4_CODEC_ID,
35
169
  targetTypes: ['int4'],
36
170
  encode: (value) => value,
37
171
  decode: (wire) => wire,
@@ -46,8 +180,28 @@ const pgInt4Codec = codec<'pg/int4@1', number, number>({
46
180
  },
47
181
  });
48
182
 
49
- const pgInt2Codec = codec<'pg/int2@1', number, number>({
50
- typeId: 'pg/int2@1',
183
+ const pgNumericCodec = codec<typeof PG_NUMERIC_CODEC_ID, string, string>({
184
+ typeId: PG_NUMERIC_CODEC_ID,
185
+ targetTypes: ['numeric', 'decimal'],
186
+ encode: (value: string): string => value,
187
+ decode: (wire: string | number): string => {
188
+ if (typeof wire === 'number') return String(wire);
189
+ return wire;
190
+ },
191
+ paramsSchema: numericParamsSchema,
192
+ meta: {
193
+ db: {
194
+ sql: {
195
+ postgres: {
196
+ nativeType: 'numeric',
197
+ },
198
+ },
199
+ },
200
+ },
201
+ });
202
+
203
+ const pgInt2Codec = codec<typeof PG_INT2_CODEC_ID, number, number>({
204
+ typeId: PG_INT2_CODEC_ID,
51
205
  targetTypes: ['int2'],
52
206
  encode: (value) => value,
53
207
  decode: (wire) => wire,
@@ -62,8 +216,8 @@ const pgInt2Codec = codec<'pg/int2@1', number, number>({
62
216
  },
63
217
  });
64
218
 
65
- const pgInt8Codec = codec<'pg/int8@1', number, number>({
66
- typeId: 'pg/int8@1',
219
+ const pgInt8Codec = codec<typeof PG_INT8_CODEC_ID, number, number>({
220
+ typeId: PG_INT8_CODEC_ID,
67
221
  targetTypes: ['int8'],
68
222
  encode: (value) => value,
69
223
  decode: (wire) => wire,
@@ -78,8 +232,8 @@ const pgInt8Codec = codec<'pg/int8@1', number, number>({
78
232
  },
79
233
  });
80
234
 
81
- const pgFloat4Codec = codec<'pg/float4@1', number, number>({
82
- typeId: 'pg/float4@1',
235
+ const pgFloat4Codec = codec<typeof PG_FLOAT4_CODEC_ID, number, number>({
236
+ typeId: PG_FLOAT4_CODEC_ID,
83
237
  targetTypes: ['float4'],
84
238
  encode: (value) => value,
85
239
  decode: (wire) => wire,
@@ -94,8 +248,8 @@ const pgFloat4Codec = codec<'pg/float4@1', number, number>({
94
248
  },
95
249
  });
96
250
 
97
- const pgFloat8Codec = codec<'pg/float8@1', number, number>({
98
- typeId: 'pg/float8@1',
251
+ const pgFloat8Codec = codec<typeof PG_FLOAT8_CODEC_ID, number, number>({
252
+ typeId: PG_FLOAT8_CODEC_ID,
99
253
  targetTypes: ['float8'],
100
254
  encode: (value) => value,
101
255
  decode: (wire) => wire,
@@ -110,8 +264,8 @@ const pgFloat8Codec = codec<'pg/float8@1', number, number>({
110
264
  },
111
265
  });
112
266
 
113
- const pgTimestampCodec = codec<'pg/timestamp@1', string | Date, string>({
114
- typeId: 'pg/timestamp@1',
267
+ const pgTimestampCodec = codec<typeof PG_TIMESTAMP_CODEC_ID, string | Date, string>({
268
+ typeId: PG_TIMESTAMP_CODEC_ID,
115
269
  targetTypes: ['timestamp'],
116
270
  encode: (value: string | Date): string => {
117
271
  if (value instanceof Date) return value.toISOString();
@@ -123,6 +277,7 @@ const pgTimestampCodec = codec<'pg/timestamp@1', string | Date, string>({
123
277
  if (wire instanceof Date) return wire.toISOString();
124
278
  return String(wire);
125
279
  },
280
+ paramsSchema: precisionParamsSchema,
126
281
  meta: {
127
282
  db: {
128
283
  sql: {
@@ -134,8 +289,8 @@ const pgTimestampCodec = codec<'pg/timestamp@1', string | Date, string>({
134
289
  },
135
290
  });
136
291
 
137
- const pgTimestamptzCodec = codec<'pg/timestamptz@1', string | Date, string>({
138
- typeId: 'pg/timestamptz@1',
292
+ const pgTimestamptzCodec = codec<typeof PG_TIMESTAMPTZ_CODEC_ID, string | Date, string>({
293
+ typeId: PG_TIMESTAMPTZ_CODEC_ID,
139
294
  targetTypes: ['timestamptz'],
140
295
  encode: (value: string | Date): string => {
141
296
  if (value instanceof Date) return value.toISOString();
@@ -147,6 +302,7 @@ const pgTimestamptzCodec = codec<'pg/timestamptz@1', string | Date, string>({
147
302
  if (wire instanceof Date) return wire.toISOString();
148
303
  return String(wire);
149
304
  },
305
+ paramsSchema: precisionParamsSchema,
150
306
  meta: {
151
307
  db: {
152
308
  sql: {
@@ -158,8 +314,42 @@ const pgTimestamptzCodec = codec<'pg/timestamptz@1', string | Date, string>({
158
314
  },
159
315
  });
160
316
 
161
- const pgBoolCodec = codec<'pg/bool@1', boolean, boolean>({
162
- typeId: 'pg/bool@1',
317
+ const pgTimeCodec = codec<typeof PG_TIME_CODEC_ID, string, string>({
318
+ typeId: PG_TIME_CODEC_ID,
319
+ targetTypes: ['time'],
320
+ encode: (value: string): string => value,
321
+ decode: (wire: string): string => wire,
322
+ paramsSchema: precisionParamsSchema,
323
+ meta: {
324
+ db: {
325
+ sql: {
326
+ postgres: {
327
+ nativeType: 'time',
328
+ },
329
+ },
330
+ },
331
+ },
332
+ });
333
+
334
+ const pgTimetzCodec = codec<typeof PG_TIMETZ_CODEC_ID, string, string>({
335
+ typeId: PG_TIMETZ_CODEC_ID,
336
+ targetTypes: ['timetz'],
337
+ encode: (value: string): string => value,
338
+ decode: (wire: string): string => wire,
339
+ paramsSchema: precisionParamsSchema,
340
+ meta: {
341
+ db: {
342
+ sql: {
343
+ postgres: {
344
+ nativeType: 'timetz',
345
+ },
346
+ },
347
+ },
348
+ },
349
+ });
350
+
351
+ const pgBoolCodec = codec<typeof PG_BOOL_CODEC_ID, boolean, boolean>({
352
+ typeId: PG_BOOL_CODEC_ID,
163
353
  targetTypes: ['bool'],
164
354
  encode: (value) => value,
165
355
  decode: (wire) => wire,
@@ -174,17 +364,124 @@ const pgBoolCodec = codec<'pg/bool@1', boolean, boolean>({
174
364
  },
175
365
  });
176
366
 
367
+ const pgBitCodec = codec<typeof PG_BIT_CODEC_ID, string, string>({
368
+ typeId: PG_BIT_CODEC_ID,
369
+ targetTypes: ['bit'],
370
+ encode: (value: string): string => value,
371
+ decode: (wire: string): string => wire,
372
+ paramsSchema: lengthParamsSchema,
373
+ meta: {
374
+ db: {
375
+ sql: {
376
+ postgres: {
377
+ nativeType: 'bit',
378
+ },
379
+ },
380
+ },
381
+ },
382
+ });
383
+
384
+ const pgVarbitCodec = codec<typeof PG_VARBIT_CODEC_ID, string, string>({
385
+ typeId: PG_VARBIT_CODEC_ID,
386
+ targetTypes: ['bit varying'],
387
+ encode: (value: string): string => value,
388
+ decode: (wire: string): string => wire,
389
+ paramsSchema: lengthParamsSchema,
390
+ meta: {
391
+ db: {
392
+ sql: {
393
+ postgres: {
394
+ nativeType: 'bit varying',
395
+ },
396
+ },
397
+ },
398
+ },
399
+ });
400
+
401
+ const pgEnumCodec = codec<typeof PG_ENUM_CODEC_ID, string, string>({
402
+ typeId: PG_ENUM_CODEC_ID,
403
+ targetTypes: ['enum'],
404
+ encode: (value) => value,
405
+ decode: (wire) => wire,
406
+ });
407
+
408
+ const pgIntervalCodec = codec<typeof PG_INTERVAL_CODEC_ID, string, string>({
409
+ typeId: PG_INTERVAL_CODEC_ID,
410
+ targetTypes: ['interval'],
411
+ encode: (value: string): string => value,
412
+ decode: (wire: string): string => wire,
413
+ paramsSchema: precisionParamsSchema,
414
+ meta: {
415
+ db: {
416
+ sql: {
417
+ postgres: {
418
+ nativeType: 'interval',
419
+ },
420
+ },
421
+ },
422
+ },
423
+ });
424
+
425
+ const pgJsonCodec = codec<typeof PG_JSON_CODEC_ID, string | JsonValue, JsonValue>({
426
+ typeId: PG_JSON_CODEC_ID,
427
+ targetTypes: ['json'],
428
+ encode: (value) => JSON.stringify(value),
429
+ decode: (wire) => (typeof wire === 'string' ? JSON.parse(wire) : wire),
430
+ meta: {
431
+ db: {
432
+ sql: {
433
+ postgres: {
434
+ nativeType: 'json',
435
+ },
436
+ },
437
+ },
438
+ },
439
+ });
440
+
441
+ const pgJsonbCodec = codec<typeof PG_JSONB_CODEC_ID, string | JsonValue, JsonValue>({
442
+ typeId: PG_JSONB_CODEC_ID,
443
+ targetTypes: ['jsonb'],
444
+ encode: (value) => JSON.stringify(value),
445
+ decode: (wire) => (typeof wire === 'string' ? JSON.parse(wire) : wire),
446
+ meta: {
447
+ db: {
448
+ sql: {
449
+ postgres: {
450
+ nativeType: 'jsonb',
451
+ },
452
+ },
453
+ },
454
+ },
455
+ });
456
+
177
457
  // Build codec definitions using the builder DSL
178
458
  const codecs = defineCodecs()
459
+ .add('char', sqlCharCodec)
460
+ .add('varchar', sqlVarcharCodec)
461
+ .add('int', sqlIntCodec)
462
+ .add('float', sqlFloatCodec)
179
463
  .add('text', pgTextCodec)
464
+ .add('character', pgCharCodec)
465
+ .add('character varying', pgVarcharCodec)
466
+ .add('integer', pgIntCodec)
467
+ .add('double precision', pgFloatCodec)
180
468
  .add('int4', pgInt4Codec)
181
469
  .add('int2', pgInt2Codec)
182
470
  .add('int8', pgInt8Codec)
183
471
  .add('float4', pgFloat4Codec)
184
472
  .add('float8', pgFloat8Codec)
473
+ .add('numeric', pgNumericCodec)
185
474
  .add('timestamp', pgTimestampCodec)
186
475
  .add('timestamptz', pgTimestamptzCodec)
187
- .add('bool', pgBoolCodec);
476
+ .add('time', pgTimeCodec)
477
+ .add('timetz', pgTimetzCodec)
478
+ .add('bool', pgBoolCodec)
479
+ .add('bit', pgBitCodec)
480
+ .add('bit varying', pgVarbitCodec)
481
+ .add('interval', pgIntervalCodec)
482
+ .add('enum', pgEnumCodec)
483
+ .add('json', pgJsonCodec)
484
+ .add('jsonb', pgJsonbCodec);
188
485
 
189
486
  // Export derived structures directly from codecs builder
190
487
  export const codecDefinitions = codecs.codecDefinitions;