@prisma-next/adapter-postgres 0.3.0-dev.11 → 0.3.0-dev.114
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/LICENSE +201 -0
- package/README.md +64 -2
- package/dist/adapter-CWmWEFe1.mjs +361 -0
- package/dist/adapter-CWmWEFe1.mjs.map +1 -0
- package/dist/adapter.d.mts +23 -0
- package/dist/adapter.d.mts.map +1 -0
- package/dist/adapter.mjs +3 -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 +3 -0
- package/dist/codecs-DgJcyEBR.mjs +254 -0
- package/dist/codecs-DgJcyEBR.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 +77 -0
- package/dist/control.d.mts.map +1 -0
- package/dist/control.mjs +773 -0
- package/dist/control.mjs.map +1 -0
- package/dist/descriptor-meta-l_dv8Nnn.mjs +884 -0
- package/dist/descriptor-meta-l_dv8Nnn.mjs.map +1 -0
- package/dist/runtime.d.mts +19 -0
- package/dist/runtime.d.mts.map +1 -0
- package/dist/runtime.mjs +99 -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-aQLL6QVb.d.mts +19 -0
- package/dist/types-aQLL6QVb.d.mts.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +1 -0
- package/package.json +39 -46
- package/src/core/adapter.ts +529 -256
- package/src/core/codec-ids.ts +28 -0
- package/src/core/codecs.ts +385 -36
- package/src/core/control-adapter.ts +404 -179
- package/src/core/control-mutation-defaults.ts +335 -0
- package/src/core/default-normalizer.ts +138 -0
- package/src/core/descriptor-meta.ts +296 -9
- package/src/core/enum-control-hooks.ts +733 -0
- package/src/core/json-schema-type-expression.ts +131 -0
- package/src/core/json-schema-validator.ts +53 -0
- package/src/core/sql-utils.ts +111 -0
- package/src/core/standard-schema.ts +71 -0
- package/src/core/types.ts +5 -3
- package/src/exports/codec-types.ts +73 -1
- package/src/exports/column-types.ts +233 -9
- package/src/exports/control.ts +20 -9
- package/src/exports/runtime.ts +76 -19
- package/dist/chunk-HD5YISNQ.js +0 -47
- package/dist/chunk-HD5YISNQ.js.map +0 -1
- package/dist/chunk-J3XSOAM2.js +0 -162
- package/dist/chunk-J3XSOAM2.js.map +0 -1
- package/dist/chunk-T6S3A6VT.js +0 -301
- package/dist/chunk-T6S3A6VT.js.map +0 -1
- package/dist/core/adapter.d.ts +0 -19
- package/dist/core/adapter.d.ts.map +0 -1
- package/dist/core/codecs.d.ts +0 -110
- package/dist/core/codecs.d.ts.map +0 -1
- package/dist/core/control-adapter.d.ts +0 -33
- package/dist/core/control-adapter.d.ts.map +0 -1
- package/dist/core/descriptor-meta.d.ts +0 -72
- package/dist/core/descriptor-meta.d.ts.map +0 -1
- package/dist/core/types.d.ts +0 -16
- package/dist/core/types.d.ts.map +0 -1
- package/dist/exports/adapter.d.ts +0 -2
- package/dist/exports/adapter.d.ts.map +0 -1
- package/dist/exports/adapter.js +0 -8
- package/dist/exports/adapter.js.map +0 -1
- package/dist/exports/codec-types.d.ts +0 -11
- package/dist/exports/codec-types.d.ts.map +0 -1
- 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 -17
- package/dist/exports/column-types.d.ts.map +0 -1
- package/dist/exports/column-types.js +0 -49
- package/dist/exports/column-types.js.map +0 -1
- package/dist/exports/control.d.ts +0 -8
- package/dist/exports/control.d.ts.map +0 -1
- package/dist/exports/control.js +0 -279
- package/dist/exports/control.js.map +0 -1
- package/dist/exports/runtime.d.ts +0 -15
- package/dist/exports/runtime.d.ts.map +0 -1
- package/dist/exports/runtime.js +0 -20
- package/dist/exports/runtime.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
export {
|
|
2
|
+
SQL_CHAR_CODEC_ID,
|
|
3
|
+
SQL_FLOAT_CODEC_ID,
|
|
4
|
+
SQL_INT_CODEC_ID,
|
|
5
|
+
SQL_VARCHAR_CODEC_ID,
|
|
6
|
+
} from '@prisma-next/sql-relational-core/ast';
|
|
7
|
+
export const PG_TEXT_CODEC_ID = 'pg/text@1' as const;
|
|
8
|
+
export const PG_ENUM_CODEC_ID = 'pg/enum@1' as const;
|
|
9
|
+
export const PG_CHAR_CODEC_ID = 'pg/char@1' as const;
|
|
10
|
+
export const PG_VARCHAR_CODEC_ID = 'pg/varchar@1' as const;
|
|
11
|
+
export const PG_INT_CODEC_ID = 'pg/int@1' as const;
|
|
12
|
+
export const PG_INT2_CODEC_ID = 'pg/int2@1' as const;
|
|
13
|
+
export const PG_INT4_CODEC_ID = 'pg/int4@1' as const;
|
|
14
|
+
export const PG_INT8_CODEC_ID = 'pg/int8@1' as const;
|
|
15
|
+
export const PG_FLOAT_CODEC_ID = 'pg/float@1' as const;
|
|
16
|
+
export const PG_FLOAT4_CODEC_ID = 'pg/float4@1' as const;
|
|
17
|
+
export const PG_FLOAT8_CODEC_ID = 'pg/float8@1' as const;
|
|
18
|
+
export const PG_NUMERIC_CODEC_ID = 'pg/numeric@1' as const;
|
|
19
|
+
export const PG_BOOL_CODEC_ID = 'pg/bool@1' as const;
|
|
20
|
+
export const PG_BIT_CODEC_ID = 'pg/bit@1' as const;
|
|
21
|
+
export const PG_VARBIT_CODEC_ID = 'pg/varbit@1' as const;
|
|
22
|
+
export const PG_TIMESTAMP_CODEC_ID = 'pg/timestamp@1' as const;
|
|
23
|
+
export const PG_TIMESTAMPTZ_CODEC_ID = 'pg/timestamptz@1' as const;
|
|
24
|
+
export const PG_TIME_CODEC_ID = 'pg/time@1' as const;
|
|
25
|
+
export const PG_TIMETZ_CODEC_ID = 'pg/timetz@1' as const;
|
|
26
|
+
export const PG_INTERVAL_CODEC_ID = 'pg/interval@1' as const;
|
|
27
|
+
export const PG_JSON_CODEC_ID = 'pg/json@1' as const;
|
|
28
|
+
export const PG_JSONB_CODEC_ID = 'pg/jsonb@1' as const;
|
package/src/core/codecs.ts
CHANGED
|
@@ -11,12 +11,93 @@
|
|
|
11
11
|
* at compile time (to derive CodecTypes).
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
|
-
import {
|
|
14
|
+
import type { Codec, CodecMeta, CodecTrait } 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
|
+
TTraits extends readonly CodecTrait[],
|
|
59
|
+
TWire,
|
|
60
|
+
TJs,
|
|
61
|
+
TParams,
|
|
62
|
+
THelper,
|
|
63
|
+
>(
|
|
64
|
+
base: Codec<string, TTraits, TWire, TJs, TParams, THelper>,
|
|
65
|
+
options: {
|
|
66
|
+
readonly typeId: Id;
|
|
67
|
+
readonly targetTypes: readonly string[];
|
|
68
|
+
readonly meta?: CodecMeta;
|
|
69
|
+
},
|
|
70
|
+
): Codec<Id, TTraits, TWire, TJs, TParams, THelper> {
|
|
71
|
+
return {
|
|
72
|
+
id: options.typeId,
|
|
73
|
+
targetTypes: options.targetTypes,
|
|
74
|
+
...ifDefined('meta', options.meta),
|
|
75
|
+
...ifDefined('paramsSchema', base.paramsSchema),
|
|
76
|
+
...ifDefined('init', base.init),
|
|
77
|
+
...ifDefined('encode', base.encode),
|
|
78
|
+
...ifDefined('traits', base.traits),
|
|
79
|
+
decode: base.decode,
|
|
80
|
+
} as Codec<Id, TTraits, TWire, TJs, TParams, THelper>;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const sqlCharCodec = sqlCodecDefinitions.char.codec;
|
|
84
|
+
const sqlVarcharCodec = sqlCodecDefinitions.varchar.codec;
|
|
85
|
+
const sqlIntCodec = sqlCodecDefinitions.int.codec;
|
|
86
|
+
const sqlFloatCodec = sqlCodecDefinitions.float.codec;
|
|
87
|
+
|
|
88
|
+
export type JsonValue =
|
|
89
|
+
| string
|
|
90
|
+
| number
|
|
91
|
+
| boolean
|
|
92
|
+
| null
|
|
93
|
+
| { readonly [key: string]: JsonValue }
|
|
94
|
+
| readonly JsonValue[];
|
|
15
95
|
|
|
16
96
|
// Create individual codec instances
|
|
17
97
|
const pgTextCodec = codec({
|
|
18
|
-
typeId:
|
|
98
|
+
typeId: PG_TEXT_CODEC_ID,
|
|
19
99
|
targetTypes: ['text'],
|
|
100
|
+
traits: ['equality', 'order', 'textual'],
|
|
20
101
|
encode: (value: string): string => value,
|
|
21
102
|
decode: (wire: string): string => wire,
|
|
22
103
|
meta: {
|
|
@@ -30,11 +111,37 @@ const pgTextCodec = codec({
|
|
|
30
111
|
},
|
|
31
112
|
});
|
|
32
113
|
|
|
33
|
-
const
|
|
34
|
-
typeId:
|
|
114
|
+
const pgCharCodec = aliasCodec(sqlCharCodec, {
|
|
115
|
+
typeId: PG_CHAR_CODEC_ID,
|
|
116
|
+
targetTypes: ['character'],
|
|
117
|
+
meta: {
|
|
118
|
+
db: {
|
|
119
|
+
sql: {
|
|
120
|
+
postgres: {
|
|
121
|
+
nativeType: 'character',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
const pgVarcharCodec = aliasCodec(sqlVarcharCodec, {
|
|
129
|
+
typeId: PG_VARCHAR_CODEC_ID,
|
|
130
|
+
targetTypes: ['character varying'],
|
|
131
|
+
meta: {
|
|
132
|
+
db: {
|
|
133
|
+
sql: {
|
|
134
|
+
postgres: {
|
|
135
|
+
nativeType: 'character varying',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
const pgIntCodec = aliasCodec(sqlIntCodec, {
|
|
143
|
+
typeId: PG_INT_CODEC_ID,
|
|
35
144
|
targetTypes: ['int4'],
|
|
36
|
-
encode: (value) => value,
|
|
37
|
-
decode: (wire) => wire,
|
|
38
145
|
meta: {
|
|
39
146
|
db: {
|
|
40
147
|
sql: {
|
|
@@ -46,11 +153,69 @@ const pgInt4Codec = codec<'pg/int4@1', number, number>({
|
|
|
46
153
|
},
|
|
47
154
|
});
|
|
48
155
|
|
|
49
|
-
const
|
|
50
|
-
typeId:
|
|
156
|
+
const pgFloatCodec = aliasCodec(sqlFloatCodec, {
|
|
157
|
+
typeId: PG_FLOAT_CODEC_ID,
|
|
158
|
+
targetTypes: ['float8'],
|
|
159
|
+
meta: {
|
|
160
|
+
db: {
|
|
161
|
+
sql: {
|
|
162
|
+
postgres: {
|
|
163
|
+
nativeType: 'double precision',
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const pgInt4Codec = codec({
|
|
171
|
+
typeId: PG_INT4_CODEC_ID,
|
|
172
|
+
targetTypes: ['int4'],
|
|
173
|
+
traits: ['equality', 'order', 'numeric'],
|
|
174
|
+
encode: (value: number): number => value,
|
|
175
|
+
decode: (wire: number): number => wire,
|
|
176
|
+
meta: {
|
|
177
|
+
db: {
|
|
178
|
+
sql: {
|
|
179
|
+
postgres: {
|
|
180
|
+
nativeType: 'integer',
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
},
|
|
184
|
+
},
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const pgNumericCodec = codec<
|
|
188
|
+
typeof PG_NUMERIC_CODEC_ID,
|
|
189
|
+
readonly ['equality', 'order', 'numeric'],
|
|
190
|
+
string,
|
|
191
|
+
string
|
|
192
|
+
>({
|
|
193
|
+
typeId: PG_NUMERIC_CODEC_ID,
|
|
194
|
+
targetTypes: ['numeric', 'decimal'],
|
|
195
|
+
traits: ['equality', 'order', 'numeric'],
|
|
196
|
+
encode: (value: string): string => value,
|
|
197
|
+
decode: (wire: string | number): string => {
|
|
198
|
+
if (typeof wire === 'number') return String(wire);
|
|
199
|
+
return wire;
|
|
200
|
+
},
|
|
201
|
+
paramsSchema: numericParamsSchema,
|
|
202
|
+
meta: {
|
|
203
|
+
db: {
|
|
204
|
+
sql: {
|
|
205
|
+
postgres: {
|
|
206
|
+
nativeType: 'numeric',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const pgInt2Codec = codec({
|
|
214
|
+
typeId: PG_INT2_CODEC_ID,
|
|
51
215
|
targetTypes: ['int2'],
|
|
52
|
-
|
|
53
|
-
|
|
216
|
+
traits: ['equality', 'order', 'numeric'],
|
|
217
|
+
encode: (value: number): number => value,
|
|
218
|
+
decode: (wire: number): number => wire,
|
|
54
219
|
meta: {
|
|
55
220
|
db: {
|
|
56
221
|
sql: {
|
|
@@ -62,11 +227,12 @@ const pgInt2Codec = codec<'pg/int2@1', number, number>({
|
|
|
62
227
|
},
|
|
63
228
|
});
|
|
64
229
|
|
|
65
|
-
const pgInt8Codec = codec
|
|
66
|
-
typeId:
|
|
230
|
+
const pgInt8Codec = codec({
|
|
231
|
+
typeId: PG_INT8_CODEC_ID,
|
|
67
232
|
targetTypes: ['int8'],
|
|
68
|
-
|
|
69
|
-
|
|
233
|
+
traits: ['equality', 'order', 'numeric'],
|
|
234
|
+
encode: (value: number): number => value,
|
|
235
|
+
decode: (wire: number): number => wire,
|
|
70
236
|
meta: {
|
|
71
237
|
db: {
|
|
72
238
|
sql: {
|
|
@@ -78,11 +244,12 @@ const pgInt8Codec = codec<'pg/int8@1', number, number>({
|
|
|
78
244
|
},
|
|
79
245
|
});
|
|
80
246
|
|
|
81
|
-
const pgFloat4Codec = codec
|
|
82
|
-
typeId:
|
|
247
|
+
const pgFloat4Codec = codec({
|
|
248
|
+
typeId: PG_FLOAT4_CODEC_ID,
|
|
83
249
|
targetTypes: ['float4'],
|
|
84
|
-
|
|
85
|
-
|
|
250
|
+
traits: ['equality', 'order', 'numeric'],
|
|
251
|
+
encode: (value: number): number => value,
|
|
252
|
+
decode: (wire: number): number => wire,
|
|
86
253
|
meta: {
|
|
87
254
|
db: {
|
|
88
255
|
sql: {
|
|
@@ -94,11 +261,12 @@ const pgFloat4Codec = codec<'pg/float4@1', number, number>({
|
|
|
94
261
|
},
|
|
95
262
|
});
|
|
96
263
|
|
|
97
|
-
const pgFloat8Codec = codec
|
|
98
|
-
typeId:
|
|
264
|
+
const pgFloat8Codec = codec({
|
|
265
|
+
typeId: PG_FLOAT8_CODEC_ID,
|
|
99
266
|
targetTypes: ['float8'],
|
|
100
|
-
|
|
101
|
-
|
|
267
|
+
traits: ['equality', 'order', 'numeric'],
|
|
268
|
+
encode: (value: number): number => value,
|
|
269
|
+
decode: (wire: number): number => wire,
|
|
102
270
|
meta: {
|
|
103
271
|
db: {
|
|
104
272
|
sql: {
|
|
@@ -110,19 +278,25 @@ const pgFloat8Codec = codec<'pg/float8@1', number, number>({
|
|
|
110
278
|
},
|
|
111
279
|
});
|
|
112
280
|
|
|
113
|
-
const pgTimestampCodec = codec<
|
|
114
|
-
|
|
281
|
+
const pgTimestampCodec = codec<
|
|
282
|
+
typeof PG_TIMESTAMP_CODEC_ID,
|
|
283
|
+
readonly ['equality', 'order'],
|
|
284
|
+
string | Date,
|
|
285
|
+
string
|
|
286
|
+
>({
|
|
287
|
+
typeId: PG_TIMESTAMP_CODEC_ID,
|
|
115
288
|
targetTypes: ['timestamp'],
|
|
289
|
+
traits: ['equality', 'order'],
|
|
116
290
|
encode: (value: string | Date): string => {
|
|
117
291
|
if (value instanceof Date) return value.toISOString();
|
|
118
292
|
if (typeof value === 'string') return value;
|
|
119
293
|
return String(value);
|
|
120
294
|
},
|
|
121
295
|
decode: (wire: string | Date): string => {
|
|
122
|
-
if (typeof wire === 'string') return wire;
|
|
123
296
|
if (wire instanceof Date) return wire.toISOString();
|
|
124
|
-
return
|
|
297
|
+
return wire;
|
|
125
298
|
},
|
|
299
|
+
paramsSchema: precisionParamsSchema,
|
|
126
300
|
meta: {
|
|
127
301
|
db: {
|
|
128
302
|
sql: {
|
|
@@ -134,19 +308,25 @@ const pgTimestampCodec = codec<'pg/timestamp@1', string | Date, string>({
|
|
|
134
308
|
},
|
|
135
309
|
});
|
|
136
310
|
|
|
137
|
-
const pgTimestamptzCodec = codec<
|
|
138
|
-
|
|
311
|
+
const pgTimestamptzCodec = codec<
|
|
312
|
+
typeof PG_TIMESTAMPTZ_CODEC_ID,
|
|
313
|
+
readonly ['equality', 'order'],
|
|
314
|
+
string | Date,
|
|
315
|
+
string
|
|
316
|
+
>({
|
|
317
|
+
typeId: PG_TIMESTAMPTZ_CODEC_ID,
|
|
139
318
|
targetTypes: ['timestamptz'],
|
|
319
|
+
traits: ['equality', 'order'],
|
|
140
320
|
encode: (value: string | Date): string => {
|
|
141
321
|
if (value instanceof Date) return value.toISOString();
|
|
142
322
|
if (typeof value === 'string') return value;
|
|
143
323
|
return String(value);
|
|
144
324
|
},
|
|
145
325
|
decode: (wire: string | Date): string => {
|
|
146
|
-
if (typeof wire === 'string') return wire;
|
|
147
326
|
if (wire instanceof Date) return wire.toISOString();
|
|
148
|
-
return
|
|
327
|
+
return wire;
|
|
149
328
|
},
|
|
329
|
+
paramsSchema: precisionParamsSchema,
|
|
150
330
|
meta: {
|
|
151
331
|
db: {
|
|
152
332
|
sql: {
|
|
@@ -158,11 +338,53 @@ const pgTimestamptzCodec = codec<'pg/timestamptz@1', string | Date, string>({
|
|
|
158
338
|
},
|
|
159
339
|
});
|
|
160
340
|
|
|
161
|
-
const
|
|
162
|
-
typeId:
|
|
341
|
+
const pgTimeCodec = codec<typeof PG_TIME_CODEC_ID, readonly ['equality', 'order'], string, string>({
|
|
342
|
+
typeId: PG_TIME_CODEC_ID,
|
|
343
|
+
targetTypes: ['time'],
|
|
344
|
+
traits: ['equality', 'order'],
|
|
345
|
+
encode: (value: string): string => value,
|
|
346
|
+
decode: (wire: string): string => wire,
|
|
347
|
+
paramsSchema: precisionParamsSchema,
|
|
348
|
+
meta: {
|
|
349
|
+
db: {
|
|
350
|
+
sql: {
|
|
351
|
+
postgres: {
|
|
352
|
+
nativeType: 'time',
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
const pgTimetzCodec = codec<
|
|
360
|
+
typeof PG_TIMETZ_CODEC_ID,
|
|
361
|
+
readonly ['equality', 'order'],
|
|
362
|
+
string,
|
|
363
|
+
string
|
|
364
|
+
>({
|
|
365
|
+
typeId: PG_TIMETZ_CODEC_ID,
|
|
366
|
+
targetTypes: ['timetz'],
|
|
367
|
+
traits: ['equality', 'order'],
|
|
368
|
+
encode: (value: string): string => value,
|
|
369
|
+
decode: (wire: string): string => wire,
|
|
370
|
+
paramsSchema: precisionParamsSchema,
|
|
371
|
+
meta: {
|
|
372
|
+
db: {
|
|
373
|
+
sql: {
|
|
374
|
+
postgres: {
|
|
375
|
+
nativeType: 'timetz',
|
|
376
|
+
},
|
|
377
|
+
},
|
|
378
|
+
},
|
|
379
|
+
},
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
const pgBoolCodec = codec({
|
|
383
|
+
typeId: PG_BOOL_CODEC_ID,
|
|
163
384
|
targetTypes: ['bool'],
|
|
164
|
-
|
|
165
|
-
|
|
385
|
+
traits: ['equality', 'boolean'],
|
|
386
|
+
encode: (value: boolean): boolean => value,
|
|
387
|
+
decode: (wire: boolean): boolean => wire,
|
|
166
388
|
meta: {
|
|
167
389
|
db: {
|
|
168
390
|
sql: {
|
|
@@ -174,21 +396,148 @@ const pgBoolCodec = codec<'pg/bool@1', boolean, boolean>({
|
|
|
174
396
|
},
|
|
175
397
|
});
|
|
176
398
|
|
|
399
|
+
const pgBitCodec = codec<typeof PG_BIT_CODEC_ID, readonly ['equality', 'order'], string, string>({
|
|
400
|
+
typeId: PG_BIT_CODEC_ID,
|
|
401
|
+
targetTypes: ['bit'],
|
|
402
|
+
traits: ['equality', 'order'],
|
|
403
|
+
encode: (value: string): string => value,
|
|
404
|
+
decode: (wire: string): string => wire,
|
|
405
|
+
paramsSchema: lengthParamsSchema,
|
|
406
|
+
meta: {
|
|
407
|
+
db: {
|
|
408
|
+
sql: {
|
|
409
|
+
postgres: {
|
|
410
|
+
nativeType: 'bit',
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
},
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
const pgVarbitCodec = codec<
|
|
418
|
+
typeof PG_VARBIT_CODEC_ID,
|
|
419
|
+
readonly ['equality', 'order'],
|
|
420
|
+
string,
|
|
421
|
+
string
|
|
422
|
+
>({
|
|
423
|
+
typeId: PG_VARBIT_CODEC_ID,
|
|
424
|
+
targetTypes: ['bit varying'],
|
|
425
|
+
traits: ['equality', 'order'],
|
|
426
|
+
encode: (value: string): string => value,
|
|
427
|
+
decode: (wire: string): string => wire,
|
|
428
|
+
paramsSchema: lengthParamsSchema,
|
|
429
|
+
meta: {
|
|
430
|
+
db: {
|
|
431
|
+
sql: {
|
|
432
|
+
postgres: {
|
|
433
|
+
nativeType: 'bit varying',
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
const pgEnumCodec = codec({
|
|
441
|
+
typeId: PG_ENUM_CODEC_ID,
|
|
442
|
+
targetTypes: ['enum'],
|
|
443
|
+
traits: ['equality', 'order'],
|
|
444
|
+
encode: (value: string): string => value,
|
|
445
|
+
decode: (wire: string): string => wire,
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
const pgIntervalCodec = codec<
|
|
449
|
+
typeof PG_INTERVAL_CODEC_ID,
|
|
450
|
+
readonly ['equality', 'order'],
|
|
451
|
+
string | Record<string, unknown>,
|
|
452
|
+
string
|
|
453
|
+
>({
|
|
454
|
+
typeId: PG_INTERVAL_CODEC_ID,
|
|
455
|
+
targetTypes: ['interval'],
|
|
456
|
+
traits: ['equality', 'order'],
|
|
457
|
+
encode: (value: string): string => value,
|
|
458
|
+
decode: (wire: string | Record<string, unknown>): string => {
|
|
459
|
+
if (typeof wire === 'string') return wire;
|
|
460
|
+
return JSON.stringify(wire);
|
|
461
|
+
},
|
|
462
|
+
paramsSchema: precisionParamsSchema,
|
|
463
|
+
meta: {
|
|
464
|
+
db: {
|
|
465
|
+
sql: {
|
|
466
|
+
postgres: {
|
|
467
|
+
nativeType: 'interval',
|
|
468
|
+
},
|
|
469
|
+
},
|
|
470
|
+
},
|
|
471
|
+
},
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
const pgJsonCodec = codec({
|
|
475
|
+
typeId: PG_JSON_CODEC_ID,
|
|
476
|
+
targetTypes: ['json'],
|
|
477
|
+
traits: [],
|
|
478
|
+
encode: (value: string | JsonValue): string => JSON.stringify(value),
|
|
479
|
+
decode: (wire: string | JsonValue): JsonValue =>
|
|
480
|
+
typeof wire === 'string' ? JSON.parse(wire) : wire,
|
|
481
|
+
meta: {
|
|
482
|
+
db: {
|
|
483
|
+
sql: {
|
|
484
|
+
postgres: {
|
|
485
|
+
nativeType: 'json',
|
|
486
|
+
},
|
|
487
|
+
},
|
|
488
|
+
},
|
|
489
|
+
},
|
|
490
|
+
});
|
|
491
|
+
|
|
492
|
+
const pgJsonbCodec = codec({
|
|
493
|
+
typeId: PG_JSONB_CODEC_ID,
|
|
494
|
+
targetTypes: ['jsonb'],
|
|
495
|
+
traits: ['equality'],
|
|
496
|
+
encode: (value: string | JsonValue): string => JSON.stringify(value),
|
|
497
|
+
decode: (wire: string | JsonValue): JsonValue =>
|
|
498
|
+
typeof wire === 'string' ? JSON.parse(wire) : wire,
|
|
499
|
+
meta: {
|
|
500
|
+
db: {
|
|
501
|
+
sql: {
|
|
502
|
+
postgres: {
|
|
503
|
+
nativeType: 'jsonb',
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
},
|
|
508
|
+
});
|
|
509
|
+
|
|
177
510
|
// Build codec definitions using the builder DSL
|
|
178
511
|
const codecs = defineCodecs()
|
|
512
|
+
.add('char', sqlCharCodec)
|
|
513
|
+
.add('varchar', sqlVarcharCodec)
|
|
514
|
+
.add('int', sqlIntCodec)
|
|
515
|
+
.add('float', sqlFloatCodec)
|
|
179
516
|
.add('text', pgTextCodec)
|
|
517
|
+
.add('character', pgCharCodec)
|
|
518
|
+
.add('character varying', pgVarcharCodec)
|
|
519
|
+
.add('integer', pgIntCodec)
|
|
520
|
+
.add('double precision', pgFloatCodec)
|
|
180
521
|
.add('int4', pgInt4Codec)
|
|
181
522
|
.add('int2', pgInt2Codec)
|
|
182
523
|
.add('int8', pgInt8Codec)
|
|
183
524
|
.add('float4', pgFloat4Codec)
|
|
184
525
|
.add('float8', pgFloat8Codec)
|
|
526
|
+
.add('numeric', pgNumericCodec)
|
|
185
527
|
.add('timestamp', pgTimestampCodec)
|
|
186
528
|
.add('timestamptz', pgTimestamptzCodec)
|
|
187
|
-
.add('
|
|
529
|
+
.add('time', pgTimeCodec)
|
|
530
|
+
.add('timetz', pgTimetzCodec)
|
|
531
|
+
.add('bool', pgBoolCodec)
|
|
532
|
+
.add('bit', pgBitCodec)
|
|
533
|
+
.add('bit varying', pgVarbitCodec)
|
|
534
|
+
.add('interval', pgIntervalCodec)
|
|
535
|
+
.add('enum', pgEnumCodec)
|
|
536
|
+
.add('json', pgJsonCodec)
|
|
537
|
+
.add('jsonb', pgJsonbCodec);
|
|
188
538
|
|
|
189
539
|
// Export derived structures directly from codecs builder
|
|
190
540
|
export const codecDefinitions = codecs.codecDefinitions;
|
|
191
541
|
export const dataTypes = codecs.dataTypes;
|
|
192
542
|
|
|
193
|
-
// Export types derived from codecs builder
|
|
194
543
|
export type CodecTypes = typeof codecs.CodecTypes;
|