@prisma-next/adapter-postgres 0.3.0-pr.99.6 → 0.3.0

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 (92) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +64 -2
  3. package/dist/adapter-7pXt8ej9.mjs +369 -0
  4. package/dist/adapter-7pXt8ej9.mjs.map +1 -0
  5. package/dist/adapter.d.mts +23 -0
  6. package/dist/adapter.d.mts.map +1 -0
  7. package/dist/adapter.mjs +3 -0
  8. package/dist/codec-ids-BwjcIf74.mjs +29 -0
  9. package/dist/codec-ids-BwjcIf74.mjs.map +1 -0
  10. package/dist/codec-types.d.mts +107 -0
  11. package/dist/codec-types.d.mts.map +1 -0
  12. package/dist/codec-types.mjs +3 -0
  13. package/dist/codecs-C3wlpdV7.mjs +385 -0
  14. package/dist/codecs-C3wlpdV7.mjs.map +1 -0
  15. package/dist/column-types.d.mts +122 -0
  16. package/dist/column-types.d.mts.map +1 -0
  17. package/dist/column-types.mjs +180 -0
  18. package/dist/column-types.mjs.map +1 -0
  19. package/dist/control.d.mts +77 -0
  20. package/dist/control.d.mts.map +1 -0
  21. package/dist/control.mjs +776 -0
  22. package/dist/control.mjs.map +1 -0
  23. package/dist/descriptor-meta-DemWrTfB.mjs +768 -0
  24. package/dist/descriptor-meta-DemWrTfB.mjs.map +1 -0
  25. package/dist/runtime.d.mts +19 -0
  26. package/dist/runtime.d.mts.map +1 -0
  27. package/dist/runtime.mjs +98 -0
  28. package/dist/runtime.mjs.map +1 -0
  29. package/dist/sql-utils-CSfAGEwF.mjs +78 -0
  30. package/dist/sql-utils-CSfAGEwF.mjs.map +1 -0
  31. package/dist/types-DxaTd7aP.d.mts +20 -0
  32. package/dist/types-DxaTd7aP.d.mts.map +1 -0
  33. package/dist/types.d.mts +2 -0
  34. package/dist/types.mjs +1 -0
  35. package/package.json +31 -40
  36. package/src/core/adapter.ts +535 -256
  37. package/src/core/codec-ids.ts +30 -0
  38. package/src/core/codecs.ts +487 -36
  39. package/src/core/control-adapter.ts +405 -184
  40. package/src/core/control-mutation-defaults.ts +335 -0
  41. package/src/core/default-normalizer.ts +145 -0
  42. package/src/core/descriptor-meta.ts +227 -9
  43. package/src/core/enum-control-hooks.ts +739 -0
  44. package/src/core/json-schema-type-expression.ts +131 -0
  45. package/src/core/json-schema-validator.ts +53 -0
  46. package/src/core/sql-utils.ts +111 -0
  47. package/src/core/standard-schema.ts +71 -0
  48. package/src/core/types.ts +8 -10
  49. package/src/exports/codec-types.ts +34 -1
  50. package/src/exports/column-types.ts +223 -27
  51. package/src/exports/control.ts +19 -9
  52. package/src/exports/runtime.ts +75 -19
  53. package/dist/chunk-HD5YISNQ.js +0 -47
  54. package/dist/chunk-HD5YISNQ.js.map +0 -1
  55. package/dist/chunk-J3XSOAM2.js +0 -162
  56. package/dist/chunk-J3XSOAM2.js.map +0 -1
  57. package/dist/chunk-T6S3A6VT.js +0 -301
  58. package/dist/chunk-T6S3A6VT.js.map +0 -1
  59. package/dist/core/adapter.d.ts +0 -19
  60. package/dist/core/adapter.d.ts.map +0 -1
  61. package/dist/core/codecs.d.ts +0 -110
  62. package/dist/core/codecs.d.ts.map +0 -1
  63. package/dist/core/control-adapter.d.ts +0 -33
  64. package/dist/core/control-adapter.d.ts.map +0 -1
  65. package/dist/core/descriptor-meta.d.ts +0 -72
  66. package/dist/core/descriptor-meta.d.ts.map +0 -1
  67. package/dist/core/types.d.ts +0 -16
  68. package/dist/core/types.d.ts.map +0 -1
  69. package/dist/exports/adapter.d.ts +0 -2
  70. package/dist/exports/adapter.d.ts.map +0 -1
  71. package/dist/exports/adapter.js +0 -8
  72. package/dist/exports/adapter.js.map +0 -1
  73. package/dist/exports/codec-types.d.ts +0 -11
  74. package/dist/exports/codec-types.d.ts.map +0 -1
  75. package/dist/exports/codec-types.js +0 -7
  76. package/dist/exports/codec-types.js.map +0 -1
  77. package/dist/exports/column-types.d.ts +0 -17
  78. package/dist/exports/column-types.d.ts.map +0 -1
  79. package/dist/exports/column-types.js +0 -49
  80. package/dist/exports/column-types.js.map +0 -1
  81. package/dist/exports/control.d.ts +0 -8
  82. package/dist/exports/control.d.ts.map +0 -1
  83. package/dist/exports/control.js +0 -279
  84. package/dist/exports/control.js.map +0 -1
  85. package/dist/exports/runtime.d.ts +0 -15
  86. package/dist/exports/runtime.d.ts.map +0 -1
  87. package/dist/exports/runtime.js +0 -20
  88. package/dist/exports/runtime.js.map +0 -1
  89. package/dist/exports/types.d.ts +0 -2
  90. package/dist/exports/types.d.ts.map +0 -1
  91. package/dist/exports/types.js +0 -1
  92. package/dist/exports/types.js.map +0 -1
@@ -1,3 +1,132 @@
1
+ import type { CodecControlHooks, ExpandNativeTypeInput } from '@prisma-next/family-sql/control';
2
+ import {
3
+ PG_BIT_CODEC_ID,
4
+ PG_BOOL_CODEC_ID,
5
+ PG_CHAR_CODEC_ID,
6
+ PG_ENUM_CODEC_ID,
7
+ PG_FLOAT_CODEC_ID,
8
+ PG_FLOAT4_CODEC_ID,
9
+ PG_FLOAT8_CODEC_ID,
10
+ PG_INT_CODEC_ID,
11
+ PG_INT2_CODEC_ID,
12
+ PG_INT4_CODEC_ID,
13
+ PG_INT8_CODEC_ID,
14
+ PG_INTERVAL_CODEC_ID,
15
+ PG_JSON_CODEC_ID,
16
+ PG_JSONB_CODEC_ID,
17
+ PG_NUMERIC_CODEC_ID,
18
+ PG_TEXT_CODEC_ID,
19
+ PG_TIME_CODEC_ID,
20
+ PG_TIMESTAMP_CODEC_ID,
21
+ PG_TIMESTAMPTZ_CODEC_ID,
22
+ PG_TIMETZ_CODEC_ID,
23
+ PG_VARBIT_CODEC_ID,
24
+ PG_VARCHAR_CODEC_ID,
25
+ SQL_CHAR_CODEC_ID,
26
+ SQL_FLOAT_CODEC_ID,
27
+ SQL_INT_CODEC_ID,
28
+ SQL_TEXT_CODEC_ID,
29
+ SQL_TIMESTAMP_CODEC_ID,
30
+ SQL_VARCHAR_CODEC_ID,
31
+ } from './codec-ids';
32
+ import { codecDefinitions } from './codecs';
33
+ import { pgEnumControlHooks } from './enum-control-hooks';
34
+
35
+ // ============================================================================
36
+ // Helper functions for reducing boilerplate
37
+ // ============================================================================
38
+
39
+ /** Creates a type import spec for codec types */
40
+ const codecTypeImport = (named: string) =>
41
+ ({
42
+ package: '@prisma-next/adapter-postgres/codec-types',
43
+ named,
44
+ alias: named,
45
+ }) as const;
46
+
47
+ function isPositiveInteger(value: unknown): value is number {
48
+ return (
49
+ typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value > 0
50
+ );
51
+ }
52
+
53
+ function isNonNegativeInteger(value: unknown): value is number {
54
+ return (
55
+ typeof value === 'number' && Number.isFinite(value) && Number.isInteger(value) && value >= 0
56
+ );
57
+ }
58
+
59
+ function expandLength({ nativeType, typeParams }: ExpandNativeTypeInput): string {
60
+ if (!typeParams || !('length' in typeParams)) {
61
+ return nativeType;
62
+ }
63
+ const length = typeParams['length'];
64
+ if (!isPositiveInteger(length)) {
65
+ throw new Error(
66
+ `Invalid "length" type parameter for "${nativeType}": expected a positive integer, got ${JSON.stringify(length)}`,
67
+ );
68
+ }
69
+ return `${nativeType}(${length})`;
70
+ }
71
+
72
+ function expandPrecision({ nativeType, typeParams }: ExpandNativeTypeInput): string {
73
+ if (!typeParams || !('precision' in typeParams)) {
74
+ return nativeType;
75
+ }
76
+ const precision = typeParams['precision'];
77
+ if (!isPositiveInteger(precision)) {
78
+ throw new Error(
79
+ `Invalid "precision" type parameter for "${nativeType}": expected a positive integer, got ${JSON.stringify(precision)}`,
80
+ );
81
+ }
82
+ return `${nativeType}(${precision})`;
83
+ }
84
+
85
+ function expandNumeric({ nativeType, typeParams }: ExpandNativeTypeInput): string {
86
+ const hasPrecision = typeParams && 'precision' in typeParams;
87
+ const hasScale = typeParams && 'scale' in typeParams;
88
+
89
+ if (!hasPrecision && !hasScale) {
90
+ return nativeType;
91
+ }
92
+
93
+ if (!hasPrecision && hasScale) {
94
+ throw new Error(
95
+ `Invalid type parameters for "${nativeType}": "scale" requires "precision" to be specified`,
96
+ );
97
+ }
98
+
99
+ if (hasPrecision) {
100
+ const precision = typeParams['precision'];
101
+ if (!isPositiveInteger(precision)) {
102
+ throw new Error(
103
+ `Invalid "precision" type parameter for "${nativeType}": expected a positive integer, got ${JSON.stringify(precision)}`,
104
+ );
105
+ }
106
+ if (hasScale) {
107
+ const scale = typeParams['scale'];
108
+ if (!isNonNegativeInteger(scale)) {
109
+ throw new Error(
110
+ `Invalid "scale" type parameter for "${nativeType}": expected a non-negative integer, got ${JSON.stringify(scale)}`,
111
+ );
112
+ }
113
+ return `${nativeType}(${precision},${scale})`;
114
+ }
115
+ return `${nativeType}(${precision})`;
116
+ }
117
+
118
+ return nativeType;
119
+ }
120
+
121
+ const lengthHooks: CodecControlHooks = { expandNativeType: expandLength };
122
+ const precisionHooks: CodecControlHooks = { expandNativeType: expandPrecision };
123
+ const numericHooks: CodecControlHooks = { expandNativeType: expandNumeric };
124
+ const identityHooks: CodecControlHooks = { expandNativeType: ({ nativeType }) => nativeType };
125
+
126
+ // ============================================================================
127
+ // Descriptor metadata
128
+ // ============================================================================
129
+
1
130
  export const postgresAdapterDescriptorMeta = {
2
131
  kind: 'adapter',
3
132
  familyId: 'sql',
@@ -12,30 +141,119 @@ export const postgresAdapterDescriptorMeta = {
12
141
  jsonAgg: true,
13
142
  returning: true,
14
143
  },
144
+ sql: {
145
+ enums: true,
146
+ returning: true,
147
+ defaultInInsert: true,
148
+ },
15
149
  },
16
150
  types: {
17
151
  codecTypes: {
152
+ codecInstances: Object.values(codecDefinitions).map((def) => def.codec),
18
153
  import: {
19
154
  package: '@prisma-next/adapter-postgres/codec-types',
20
155
  named: 'CodecTypes',
21
156
  alias: 'PgTypes',
22
157
  },
158
+ typeImports: [
159
+ {
160
+ package: '@prisma-next/adapter-postgres/codec-types',
161
+ named: 'JsonValue',
162
+ alias: 'JsonValue',
163
+ },
164
+ codecTypeImport('Char'),
165
+ codecTypeImport('Varchar'),
166
+ codecTypeImport('Numeric'),
167
+ codecTypeImport('Bit'),
168
+ codecTypeImport('VarBit'),
169
+ codecTypeImport('Timestamp'),
170
+ codecTypeImport('Timestamptz'),
171
+ codecTypeImport('Time'),
172
+ codecTypeImport('Timetz'),
173
+ codecTypeImport('Interval'),
174
+ ],
175
+ controlPlaneHooks: {
176
+ [SQL_CHAR_CODEC_ID]: lengthHooks,
177
+ [SQL_VARCHAR_CODEC_ID]: lengthHooks,
178
+ [SQL_TIMESTAMP_CODEC_ID]: precisionHooks,
179
+ [PG_CHAR_CODEC_ID]: lengthHooks,
180
+ [PG_VARCHAR_CODEC_ID]: lengthHooks,
181
+ [PG_NUMERIC_CODEC_ID]: numericHooks,
182
+ [PG_BIT_CODEC_ID]: lengthHooks,
183
+ [PG_VARBIT_CODEC_ID]: lengthHooks,
184
+ [PG_TIMESTAMP_CODEC_ID]: precisionHooks,
185
+ [PG_TIMESTAMPTZ_CODEC_ID]: precisionHooks,
186
+ [PG_TIME_CODEC_ID]: precisionHooks,
187
+ [PG_TIMETZ_CODEC_ID]: precisionHooks,
188
+ [PG_INTERVAL_CODEC_ID]: precisionHooks,
189
+ [PG_ENUM_CODEC_ID]: pgEnumControlHooks,
190
+ [PG_JSON_CODEC_ID]: identityHooks,
191
+ [PG_JSONB_CODEC_ID]: identityHooks,
192
+ },
23
193
  },
24
194
  storage: [
25
- { typeId: 'pg/text@1', familyId: 'sql', targetId: 'postgres', nativeType: 'text' },
26
- { typeId: 'pg/int4@1', familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },
27
- { typeId: 'pg/int2@1', familyId: 'sql', targetId: 'postgres', nativeType: 'int2' },
28
- { typeId: 'pg/int8@1', familyId: 'sql', targetId: 'postgres', nativeType: 'int8' },
29
- { typeId: 'pg/float4@1', familyId: 'sql', targetId: 'postgres', nativeType: 'float4' },
30
- { typeId: 'pg/float8@1', familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },
31
- { typeId: 'pg/timestamp@1', familyId: 'sql', targetId: 'postgres', nativeType: 'timestamp' },
195
+ { typeId: PG_TEXT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'text' },
196
+ { typeId: SQL_TEXT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'text' },
197
+ { typeId: SQL_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },
198
+ {
199
+ typeId: SQL_VARCHAR_CODEC_ID,
200
+ familyId: 'sql',
201
+ targetId: 'postgres',
202
+ nativeType: 'character varying',
203
+ },
204
+ { typeId: SQL_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },
205
+ { typeId: SQL_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },
32
206
  {
33
- typeId: 'pg/timestamptz@1',
207
+ typeId: SQL_TIMESTAMP_CODEC_ID,
208
+ familyId: 'sql',
209
+ targetId: 'postgres',
210
+ nativeType: 'timestamp',
211
+ },
212
+ { typeId: PG_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },
213
+ {
214
+ typeId: PG_VARCHAR_CODEC_ID,
215
+ familyId: 'sql',
216
+ targetId: 'postgres',
217
+ nativeType: 'character varying',
218
+ },
219
+ { typeId: PG_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },
220
+ { typeId: PG_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },
221
+ { typeId: PG_INT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },
222
+ { typeId: PG_INT2_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int2' },
223
+ { typeId: PG_INT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int8' },
224
+ { typeId: PG_FLOAT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float4' },
225
+ { typeId: PG_FLOAT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },
226
+ { typeId: PG_NUMERIC_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'numeric' },
227
+ {
228
+ typeId: PG_TIMESTAMP_CODEC_ID,
229
+ familyId: 'sql',
230
+ targetId: 'postgres',
231
+ nativeType: 'timestamp',
232
+ },
233
+ {
234
+ typeId: PG_TIMESTAMPTZ_CODEC_ID,
34
235
  familyId: 'sql',
35
236
  targetId: 'postgres',
36
237
  nativeType: 'timestamptz',
37
238
  },
38
- { typeId: 'pg/bool@1', familyId: 'sql', targetId: 'postgres', nativeType: 'bool' },
239
+ { typeId: PG_TIME_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'time' },
240
+ { typeId: PG_TIMETZ_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'timetz' },
241
+ { typeId: PG_BOOL_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bool' },
242
+ { typeId: PG_BIT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bit' },
243
+ {
244
+ typeId: PG_VARBIT_CODEC_ID,
245
+ familyId: 'sql',
246
+ targetId: 'postgres',
247
+ nativeType: 'bit varying',
248
+ },
249
+ {
250
+ typeId: PG_INTERVAL_CODEC_ID,
251
+ familyId: 'sql',
252
+ targetId: 'postgres',
253
+ nativeType: 'interval',
254
+ },
255
+ { typeId: PG_JSON_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'json' },
256
+ { typeId: PG_JSONB_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'jsonb' },
39
257
  ],
40
258
  },
41
259
  } as const;