@prisma-next/adapter-postgres 0.3.0-dev.4 → 0.3.0-dev.41
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 +64 -2
- package/dist/adapter-B5uYhMy7.mjs +266 -0
- package/dist/adapter-B5uYhMy7.mjs.map +1 -0
- package/dist/adapter.d.mts +23 -0
- package/dist/adapter.d.mts.map +1 -0
- package/dist/adapter.mjs +5 -0
- package/dist/codec-ids-Bsm9c7ns.mjs +29 -0
- package/dist/codec-ids-Bsm9c7ns.mjs.map +1 -0
- package/dist/codec-types.d.mts +141 -0
- package/dist/codec-types.d.mts.map +1 -0
- package/dist/codec-types.mjs +4 -0
- package/dist/codecs-BfC_5c-4.mjs +207 -0
- package/dist/codecs-BfC_5c-4.mjs.map +1 -0
- package/dist/column-types.d.mts +110 -0
- package/dist/column-types.d.mts.map +1 -0
- package/dist/column-types.mjs +180 -0
- package/dist/column-types.mjs.map +1 -0
- package/dist/control.d.mts +111 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +427 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-ilnFI7bx.mjs +921 -0
- package/dist/descriptor-meta-ilnFI7bx.mjs.map +1 -0
- package/dist/runtime.d.mts +19 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +85 -0
- package/dist/runtime.mjs.map +1 -0
- package/dist/sql-utils-CSfAGEwF.mjs +78 -0
- package/dist/sql-utils-CSfAGEwF.mjs.map +1 -0
- package/dist/types-CXO7EB60.d.mts +19 -0
- package/dist/types-CXO7EB60.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +39 -47
- package/src/core/adapter.ts +517 -0
- package/src/core/codec-ids.ts +28 -0
- package/src/core/codecs.ts +496 -0
- package/src/core/control-adapter.ts +536 -0
- package/src/core/default-normalizer.ts +90 -0
- package/src/core/descriptor-meta.ts +253 -0
- package/src/core/enum-control-hooks.ts +735 -0
- package/src/core/json-schema-type-expression.ts +131 -0
- package/src/core/json-schema-validator.ts +53 -0
- package/src/core/parameterized-types.ts +118 -0
- package/src/core/sql-utils.ts +111 -0
- package/src/core/standard-schema.ts +71 -0
- package/src/core/types.ts +53 -0
- package/src/exports/adapter.ts +1 -0
- package/src/exports/codec-types.ts +83 -0
- package/src/exports/column-types.ts +277 -0
- package/src/exports/control.ts +27 -0
- package/src/exports/runtime.ts +75 -0
- package/src/exports/types.ts +14 -0
- package/dist/exports/adapter.d.ts +0 -21
- package/dist/exports/adapter.js +0 -8
- package/dist/exports/adapter.js.map +0 -1
- package/dist/exports/chunk-B5SU5BVC.js +0 -47
- package/dist/exports/chunk-B5SU5BVC.js.map +0 -1
- package/dist/exports/chunk-CPAKRHXM.js +0 -162
- package/dist/exports/chunk-CPAKRHXM.js.map +0 -1
- package/dist/exports/chunk-ZHJOVBWT.js +0 -301
- package/dist/exports/chunk-ZHJOVBWT.js.map +0 -1
- package/dist/exports/codec-types.d.ts +0 -38
- package/dist/exports/codec-types.js +0 -7
- package/dist/exports/codec-types.js.map +0 -1
- package/dist/exports/column-types.d.ts +0 -20
- package/dist/exports/column-types.js +0 -49
- package/dist/exports/column-types.js.map +0 -1
- package/dist/exports/control.d.ts +0 -9
- package/dist/exports/control.js +0 -279
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -17
- package/dist/exports/runtime.js +0 -20
- package/dist/exports/runtime.js.map +0 -1
- package/dist/exports/types.d.ts +0 -19
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
import type { CodecControlHooks } 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_VARCHAR_CODEC_ID,
|
|
29
|
+
} from './codec-ids';
|
|
30
|
+
import { pgEnumControlHooks } from './enum-control-hooks';
|
|
31
|
+
import { renderTypeScriptTypeFromJsonSchema } from './json-schema-type-expression';
|
|
32
|
+
import { expandParameterizedNativeType } from './parameterized-types';
|
|
33
|
+
|
|
34
|
+
// ============================================================================
|
|
35
|
+
// Helper functions for reducing boilerplate
|
|
36
|
+
// ============================================================================
|
|
37
|
+
|
|
38
|
+
/** Creates a type import spec for codec types */
|
|
39
|
+
const codecTypeImport = (named: string) =>
|
|
40
|
+
({
|
|
41
|
+
package: '@prisma-next/adapter-postgres/codec-types',
|
|
42
|
+
named,
|
|
43
|
+
alias: named,
|
|
44
|
+
}) as const;
|
|
45
|
+
|
|
46
|
+
/** Creates a precision-based TypeScript type renderer for temporal types */
|
|
47
|
+
const precisionRenderer = (typeName: string) =>
|
|
48
|
+
({
|
|
49
|
+
kind: 'function',
|
|
50
|
+
render: (params: Record<string, unknown>) => {
|
|
51
|
+
const precision = params['precision'];
|
|
52
|
+
return typeof precision === 'number' ? `${typeName}<${precision}>` : typeName;
|
|
53
|
+
},
|
|
54
|
+
}) as const;
|
|
55
|
+
|
|
56
|
+
/** Creates control hooks with just expandNativeType for parameterized types */
|
|
57
|
+
const parameterizedTypeHooks: CodecControlHooks = {
|
|
58
|
+
expandNativeType: expandParameterizedNativeType,
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Validates that a type expression string is safe to embed in generated .d.ts files.
|
|
63
|
+
* Rejects expressions containing patterns that could inject executable code.
|
|
64
|
+
*/
|
|
65
|
+
function isSafeTypeExpression(expr: string): boolean {
|
|
66
|
+
return !/import\s*\(|require\s*\(|declare\s|export\s|eval\s*\(/.test(expr);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function renderJsonTypeExpression(params: Record<string, unknown>): string {
|
|
70
|
+
const typeName = params['type'];
|
|
71
|
+
if (typeof typeName === 'string' && typeName.trim().length > 0) {
|
|
72
|
+
const trimmed = typeName.trim();
|
|
73
|
+
if (!isSafeTypeExpression(trimmed)) {
|
|
74
|
+
return 'JsonValue';
|
|
75
|
+
}
|
|
76
|
+
return trimmed;
|
|
77
|
+
}
|
|
78
|
+
const schema = params['schemaJson'];
|
|
79
|
+
if (schema && typeof schema === 'object') {
|
|
80
|
+
const rendered = renderTypeScriptTypeFromJsonSchema(schema);
|
|
81
|
+
if (!isSafeTypeExpression(rendered)) {
|
|
82
|
+
return 'JsonValue';
|
|
83
|
+
}
|
|
84
|
+
return rendered;
|
|
85
|
+
}
|
|
86
|
+
return 'JsonValue';
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ============================================================================
|
|
90
|
+
// Descriptor metadata
|
|
91
|
+
// ============================================================================
|
|
92
|
+
|
|
93
|
+
export const postgresAdapterDescriptorMeta = {
|
|
94
|
+
kind: 'adapter',
|
|
95
|
+
familyId: 'sql',
|
|
96
|
+
targetId: 'postgres',
|
|
97
|
+
id: 'postgres',
|
|
98
|
+
version: '0.0.1',
|
|
99
|
+
capabilities: {
|
|
100
|
+
postgres: {
|
|
101
|
+
orderBy: true,
|
|
102
|
+
limit: true,
|
|
103
|
+
lateral: true,
|
|
104
|
+
jsonAgg: true,
|
|
105
|
+
returning: true,
|
|
106
|
+
},
|
|
107
|
+
sql: {
|
|
108
|
+
enums: true,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
types: {
|
|
112
|
+
codecTypes: {
|
|
113
|
+
import: {
|
|
114
|
+
package: '@prisma-next/adapter-postgres/codec-types',
|
|
115
|
+
named: 'CodecTypes',
|
|
116
|
+
alias: 'PgTypes',
|
|
117
|
+
},
|
|
118
|
+
parameterized: {
|
|
119
|
+
[SQL_CHAR_CODEC_ID]: 'Char<{{length}}>',
|
|
120
|
+
[SQL_VARCHAR_CODEC_ID]: 'Varchar<{{length}}>',
|
|
121
|
+
[PG_CHAR_CODEC_ID]: 'Char<{{length}}>',
|
|
122
|
+
[PG_VARCHAR_CODEC_ID]: 'Varchar<{{length}}>',
|
|
123
|
+
[PG_NUMERIC_CODEC_ID]: {
|
|
124
|
+
kind: 'function',
|
|
125
|
+
render: (params: Record<string, unknown>) => {
|
|
126
|
+
const precision = params['precision'];
|
|
127
|
+
if (typeof precision !== 'number') {
|
|
128
|
+
throw new Error('pg/numeric@1 renderer expects precision');
|
|
129
|
+
}
|
|
130
|
+
const scale = params['scale'];
|
|
131
|
+
return typeof scale === 'number'
|
|
132
|
+
? `Numeric<${precision}, ${scale}>`
|
|
133
|
+
: `Numeric<${precision}>`;
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
[PG_BIT_CODEC_ID]: 'Bit<{{length}}>',
|
|
137
|
+
[PG_VARBIT_CODEC_ID]: 'VarBit<{{length}}>',
|
|
138
|
+
[PG_TIMESTAMP_CODEC_ID]: precisionRenderer('Timestamp'),
|
|
139
|
+
[PG_TIMESTAMPTZ_CODEC_ID]: precisionRenderer('Timestamptz'),
|
|
140
|
+
[PG_TIME_CODEC_ID]: precisionRenderer('Time'),
|
|
141
|
+
[PG_TIMETZ_CODEC_ID]: precisionRenderer('Timetz'),
|
|
142
|
+
[PG_INTERVAL_CODEC_ID]: precisionRenderer('Interval'),
|
|
143
|
+
[PG_ENUM_CODEC_ID]: {
|
|
144
|
+
kind: 'function',
|
|
145
|
+
render: (params: Record<string, unknown>) => {
|
|
146
|
+
const values = params['values'];
|
|
147
|
+
if (!Array.isArray(values)) {
|
|
148
|
+
throw new Error('pg/enum@1 renderer expects values array');
|
|
149
|
+
}
|
|
150
|
+
return values.map((value) => `'${String(value).replace(/'/g, "\\'")}'`).join(' | ');
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
[PG_JSON_CODEC_ID]: {
|
|
154
|
+
kind: 'function',
|
|
155
|
+
render: renderJsonTypeExpression,
|
|
156
|
+
},
|
|
157
|
+
[PG_JSONB_CODEC_ID]: {
|
|
158
|
+
kind: 'function',
|
|
159
|
+
render: renderJsonTypeExpression,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
typeImports: [
|
|
163
|
+
{
|
|
164
|
+
package: '@prisma-next/adapter-postgres/codec-types',
|
|
165
|
+
named: 'JsonValue',
|
|
166
|
+
alias: 'JsonValue',
|
|
167
|
+
},
|
|
168
|
+
codecTypeImport('Char'),
|
|
169
|
+
codecTypeImport('Varchar'),
|
|
170
|
+
codecTypeImport('Numeric'),
|
|
171
|
+
codecTypeImport('Bit'),
|
|
172
|
+
codecTypeImport('VarBit'),
|
|
173
|
+
codecTypeImport('Timestamp'),
|
|
174
|
+
codecTypeImport('Timestamptz'),
|
|
175
|
+
codecTypeImport('Time'),
|
|
176
|
+
codecTypeImport('Timetz'),
|
|
177
|
+
codecTypeImport('Interval'),
|
|
178
|
+
],
|
|
179
|
+
controlPlaneHooks: {
|
|
180
|
+
[SQL_CHAR_CODEC_ID]: parameterizedTypeHooks,
|
|
181
|
+
[SQL_VARCHAR_CODEC_ID]: parameterizedTypeHooks,
|
|
182
|
+
[PG_CHAR_CODEC_ID]: parameterizedTypeHooks,
|
|
183
|
+
[PG_VARCHAR_CODEC_ID]: parameterizedTypeHooks,
|
|
184
|
+
[PG_NUMERIC_CODEC_ID]: parameterizedTypeHooks,
|
|
185
|
+
[PG_BIT_CODEC_ID]: parameterizedTypeHooks,
|
|
186
|
+
[PG_VARBIT_CODEC_ID]: parameterizedTypeHooks,
|
|
187
|
+
[PG_TIMESTAMP_CODEC_ID]: parameterizedTypeHooks,
|
|
188
|
+
[PG_TIMESTAMPTZ_CODEC_ID]: parameterizedTypeHooks,
|
|
189
|
+
[PG_TIME_CODEC_ID]: parameterizedTypeHooks,
|
|
190
|
+
[PG_TIMETZ_CODEC_ID]: parameterizedTypeHooks,
|
|
191
|
+
[PG_INTERVAL_CODEC_ID]: parameterizedTypeHooks,
|
|
192
|
+
[PG_ENUM_CODEC_ID]: pgEnumControlHooks,
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
storage: [
|
|
196
|
+
{ typeId: PG_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' },
|
|
206
|
+
{ typeId: PG_CHAR_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'character' },
|
|
207
|
+
{
|
|
208
|
+
typeId: PG_VARCHAR_CODEC_ID,
|
|
209
|
+
familyId: 'sql',
|
|
210
|
+
targetId: 'postgres',
|
|
211
|
+
nativeType: 'character varying',
|
|
212
|
+
},
|
|
213
|
+
{ typeId: PG_INT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },
|
|
214
|
+
{ typeId: PG_FLOAT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },
|
|
215
|
+
{ typeId: PG_INT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int4' },
|
|
216
|
+
{ typeId: PG_INT2_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int2' },
|
|
217
|
+
{ typeId: PG_INT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'int8' },
|
|
218
|
+
{ typeId: PG_FLOAT4_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float4' },
|
|
219
|
+
{ typeId: PG_FLOAT8_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'float8' },
|
|
220
|
+
{ typeId: PG_NUMERIC_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'numeric' },
|
|
221
|
+
{
|
|
222
|
+
typeId: PG_TIMESTAMP_CODEC_ID,
|
|
223
|
+
familyId: 'sql',
|
|
224
|
+
targetId: 'postgres',
|
|
225
|
+
nativeType: 'timestamp',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
typeId: PG_TIMESTAMPTZ_CODEC_ID,
|
|
229
|
+
familyId: 'sql',
|
|
230
|
+
targetId: 'postgres',
|
|
231
|
+
nativeType: 'timestamptz',
|
|
232
|
+
},
|
|
233
|
+
{ typeId: PG_TIME_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'time' },
|
|
234
|
+
{ typeId: PG_TIMETZ_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'timetz' },
|
|
235
|
+
{ typeId: PG_BOOL_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bool' },
|
|
236
|
+
{ typeId: PG_BIT_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'bit' },
|
|
237
|
+
{
|
|
238
|
+
typeId: PG_VARBIT_CODEC_ID,
|
|
239
|
+
familyId: 'sql',
|
|
240
|
+
targetId: 'postgres',
|
|
241
|
+
nativeType: 'bit varying',
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
typeId: PG_INTERVAL_CODEC_ID,
|
|
245
|
+
familyId: 'sql',
|
|
246
|
+
targetId: 'postgres',
|
|
247
|
+
nativeType: 'interval',
|
|
248
|
+
},
|
|
249
|
+
{ typeId: PG_JSON_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'json' },
|
|
250
|
+
{ typeId: PG_JSONB_CODEC_ID, familyId: 'sql', targetId: 'postgres', nativeType: 'jsonb' },
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
} as const;
|