drizzle-zod 1.0.0-beta.9-42ad8bb → 1.0.0-beta.9-c26fd2f
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/index.cjs +325 -361
- package/index.cjs.map +1 -1
- package/index.d.cts +99 -6
- package/index.d.mts +99 -6
- package/index.d.ts +99 -6
- package/index.mjs +321 -355
- package/index.mjs.map +1 -1
- package/package.json +2 -3
- package/column.d.cts +0 -8
- package/column.d.mts +0 -8
- package/column.d.ts +0 -8
- package/column.types.d.cts +0 -24
- package/column.types.d.mts +0 -24
- package/column.types.d.ts +0 -24
- package/constants.d.cts +0 -20
- package/constants.d.mts +0 -20
- package/constants.d.ts +0 -20
- package/schema.d.cts +0 -9
- package/schema.d.mts +0 -9
- package/schema.d.ts +0 -9
- package/schema.types.d.cts +0 -28
- package/schema.types.d.mts +0 -28
- package/schema.types.d.ts +0 -28
- package/schema.types.internal.d.cts +0 -26
- package/schema.types.internal.d.mts +0 -26
- package/schema.types.internal.d.ts +0 -26
- package/utils.d.cts +0 -19
- package/utils.d.mts +0 -19
- package/utils.d.ts +0 -19
package/index.cjs
CHANGED
|
@@ -1,403 +1,367 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var drizzleOrm = require('drizzle-orm');
|
|
4
|
-
var v4 = require('zod/v4');
|
|
1
|
+
let drizzle_orm = require("drizzle-orm");
|
|
2
|
+
let zod_v4 = require("zod/v4");
|
|
5
3
|
|
|
4
|
+
//#region src/constants.ts
|
|
6
5
|
const CONSTANTS = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
6
|
+
INT8_MIN: -128,
|
|
7
|
+
INT8_MAX: 127,
|
|
8
|
+
INT8_UNSIGNED_MAX: 255,
|
|
9
|
+
INT16_MIN: -32768,
|
|
10
|
+
INT16_MAX: 32767,
|
|
11
|
+
INT16_UNSIGNED_MAX: 65535,
|
|
12
|
+
INT24_MIN: -8388608,
|
|
13
|
+
INT24_MAX: 8388607,
|
|
14
|
+
INT24_UNSIGNED_MAX: 16777215,
|
|
15
|
+
INT32_MIN: -2147483648,
|
|
16
|
+
INT32_MAX: 2147483647,
|
|
17
|
+
INT32_UNSIGNED_MAX: 4294967295,
|
|
18
|
+
INT48_MIN: -0x800000000000,
|
|
19
|
+
INT48_MAX: 0x7fffffffffff,
|
|
20
|
+
INT48_UNSIGNED_MAX: 0xffffffffffff,
|
|
21
|
+
INT64_MIN: -9223372036854775808n,
|
|
22
|
+
INT64_MAX: 9223372036854775807n,
|
|
23
|
+
INT64_UNSIGNED_MAX: 18446744073709551615n
|
|
25
24
|
};
|
|
26
25
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/column.ts
|
|
28
|
+
const literalSchema = zod_v4.z.union([
|
|
29
|
+
zod_v4.z.string(),
|
|
30
|
+
zod_v4.z.number(),
|
|
31
|
+
zod_v4.z.boolean(),
|
|
32
|
+
zod_v4.z.null()
|
|
33
|
+
]);
|
|
34
|
+
const jsonSchema = zod_v4.z.union([
|
|
35
|
+
literalSchema,
|
|
36
|
+
zod_v4.z.record(zod_v4.z.string(), zod_v4.z.any()),
|
|
37
|
+
zod_v4.z.array(zod_v4.z.any())
|
|
32
38
|
]);
|
|
33
|
-
const bufferSchema =
|
|
39
|
+
const bufferSchema = zod_v4.z.custom((v) => v instanceof Buffer);
|
|
34
40
|
function columnToSchema(column, factory) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
break;
|
|
67
|
-
}
|
|
68
|
-
default: {
|
|
69
|
-
schema = z.any();
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return schema;
|
|
41
|
+
const z$1 = factory?.zodInstance ?? zod_v4.z;
|
|
42
|
+
const coerce = factory?.coerce ?? {};
|
|
43
|
+
let schema;
|
|
44
|
+
const dimensions = column.dimensions;
|
|
45
|
+
if (typeof dimensions === "number" && dimensions > 0) return pgArrayColumnToSchema(column, dimensions, z$1, coerce);
|
|
46
|
+
const { type, constraint } = (0, drizzle_orm.extractExtendedColumnType)(column);
|
|
47
|
+
switch (type) {
|
|
48
|
+
case "array":
|
|
49
|
+
schema = arrayColumnToSchema(column, constraint, z$1, coerce);
|
|
50
|
+
break;
|
|
51
|
+
case "object":
|
|
52
|
+
schema = objectColumnToSchema(column, constraint, z$1, coerce);
|
|
53
|
+
break;
|
|
54
|
+
case "number":
|
|
55
|
+
schema = numberColumnToSchema(column, constraint, z$1, coerce);
|
|
56
|
+
break;
|
|
57
|
+
case "bigint":
|
|
58
|
+
schema = bigintColumnToSchema(column, constraint, z$1, coerce);
|
|
59
|
+
break;
|
|
60
|
+
case "boolean":
|
|
61
|
+
schema = coerce === true || coerce.boolean ? z$1.coerce.boolean() : z$1.boolean();
|
|
62
|
+
break;
|
|
63
|
+
case "string":
|
|
64
|
+
schema = stringColumnToSchema(column, constraint, z$1, coerce);
|
|
65
|
+
break;
|
|
66
|
+
case "custom":
|
|
67
|
+
schema = z$1.any();
|
|
68
|
+
break;
|
|
69
|
+
default: schema = z$1.any();
|
|
70
|
+
}
|
|
71
|
+
return schema;
|
|
73
72
|
}
|
|
74
|
-
function numberColumnToSchema(column, constraint, z, coerce) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
integer = true;
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
case 'unsigned': {
|
|
166
|
-
min = 0;
|
|
167
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
168
|
-
break;
|
|
169
|
-
}
|
|
170
|
-
default: {
|
|
171
|
-
min = Number.MIN_SAFE_INTEGER;
|
|
172
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
let schema = coerce === true || coerce?.number
|
|
177
|
-
? integer ? z.coerce.number().int() : z.coerce.number()
|
|
178
|
-
: integer
|
|
179
|
-
? z.int()
|
|
180
|
-
: z.number();
|
|
181
|
-
schema = schema.gte(min).lte(max);
|
|
182
|
-
return schema;
|
|
73
|
+
function numberColumnToSchema(column, constraint, z$1, coerce) {
|
|
74
|
+
let min;
|
|
75
|
+
let max;
|
|
76
|
+
let integer = false;
|
|
77
|
+
switch (constraint) {
|
|
78
|
+
case "int8":
|
|
79
|
+
min = CONSTANTS.INT8_MIN;
|
|
80
|
+
max = CONSTANTS.INT8_MAX;
|
|
81
|
+
integer = true;
|
|
82
|
+
break;
|
|
83
|
+
case "uint8":
|
|
84
|
+
min = 0;
|
|
85
|
+
max = CONSTANTS.INT8_UNSIGNED_MAX;
|
|
86
|
+
integer = true;
|
|
87
|
+
break;
|
|
88
|
+
case "int16":
|
|
89
|
+
min = CONSTANTS.INT16_MIN;
|
|
90
|
+
max = CONSTANTS.INT16_MAX;
|
|
91
|
+
integer = true;
|
|
92
|
+
break;
|
|
93
|
+
case "uint16":
|
|
94
|
+
min = 0;
|
|
95
|
+
max = CONSTANTS.INT16_UNSIGNED_MAX;
|
|
96
|
+
integer = true;
|
|
97
|
+
break;
|
|
98
|
+
case "int24":
|
|
99
|
+
min = CONSTANTS.INT24_MIN;
|
|
100
|
+
max = CONSTANTS.INT24_MAX;
|
|
101
|
+
integer = true;
|
|
102
|
+
break;
|
|
103
|
+
case "uint24":
|
|
104
|
+
min = 0;
|
|
105
|
+
max = CONSTANTS.INT24_UNSIGNED_MAX;
|
|
106
|
+
integer = true;
|
|
107
|
+
break;
|
|
108
|
+
case "int32":
|
|
109
|
+
min = CONSTANTS.INT32_MIN;
|
|
110
|
+
max = CONSTANTS.INT32_MAX;
|
|
111
|
+
integer = true;
|
|
112
|
+
break;
|
|
113
|
+
case "uint32":
|
|
114
|
+
min = 0;
|
|
115
|
+
max = CONSTANTS.INT32_UNSIGNED_MAX;
|
|
116
|
+
integer = true;
|
|
117
|
+
break;
|
|
118
|
+
case "int53":
|
|
119
|
+
min = Number.MIN_SAFE_INTEGER;
|
|
120
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
121
|
+
integer = true;
|
|
122
|
+
break;
|
|
123
|
+
case "uint53":
|
|
124
|
+
min = 0;
|
|
125
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
126
|
+
integer = true;
|
|
127
|
+
break;
|
|
128
|
+
case "float":
|
|
129
|
+
min = CONSTANTS.INT24_MIN;
|
|
130
|
+
max = CONSTANTS.INT24_MAX;
|
|
131
|
+
break;
|
|
132
|
+
case "ufloat":
|
|
133
|
+
min = 0;
|
|
134
|
+
max = CONSTANTS.INT24_UNSIGNED_MAX;
|
|
135
|
+
break;
|
|
136
|
+
case "double":
|
|
137
|
+
min = CONSTANTS.INT48_MIN;
|
|
138
|
+
max = CONSTANTS.INT48_MAX;
|
|
139
|
+
break;
|
|
140
|
+
case "udouble":
|
|
141
|
+
min = 0;
|
|
142
|
+
max = CONSTANTS.INT48_UNSIGNED_MAX;
|
|
143
|
+
break;
|
|
144
|
+
case "year":
|
|
145
|
+
min = 1901;
|
|
146
|
+
max = 2155;
|
|
147
|
+
integer = true;
|
|
148
|
+
break;
|
|
149
|
+
case "unsigned":
|
|
150
|
+
min = 0;
|
|
151
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
min = Number.MIN_SAFE_INTEGER;
|
|
155
|
+
max = Number.MAX_SAFE_INTEGER;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
let schema = coerce === true || coerce?.number ? integer ? z$1.coerce.number().int() : z$1.coerce.number() : integer ? z$1.int() : z$1.number();
|
|
159
|
+
schema = schema.gte(min).lte(max);
|
|
160
|
+
return schema;
|
|
183
161
|
}
|
|
184
162
|
/** @internal */
|
|
185
|
-
const bigintStringModeSchema =
|
|
163
|
+
const bigintStringModeSchema = zod_v4.z.string().regex(/^-?\d+$/).transform(BigInt).pipe(zod_v4.z.bigint().gte(CONSTANTS.INT64_MIN).lte(CONSTANTS.INT64_MAX)).transform(String);
|
|
186
164
|
/** @internal */
|
|
187
|
-
const unsignedBigintStringModeSchema =
|
|
188
|
-
function bigintColumnToSchema(column, constraint, z, coerce) {
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
165
|
+
const unsignedBigintStringModeSchema = zod_v4.z.string().regex(/^\d+$/).transform(BigInt).pipe(zod_v4.z.bigint().gte(0n).lte(CONSTANTS.INT64_MAX)).transform(String);
|
|
166
|
+
function bigintColumnToSchema(column, constraint, z$1, coerce) {
|
|
167
|
+
let min;
|
|
168
|
+
let max;
|
|
169
|
+
switch (constraint) {
|
|
170
|
+
case "int64":
|
|
171
|
+
min = CONSTANTS.INT64_MIN;
|
|
172
|
+
max = CONSTANTS.INT64_MAX;
|
|
173
|
+
break;
|
|
174
|
+
case "uint64":
|
|
175
|
+
min = 0n;
|
|
176
|
+
max = CONSTANTS.INT64_UNSIGNED_MAX;
|
|
177
|
+
break;
|
|
178
|
+
}
|
|
179
|
+
let schema = coerce === true || coerce?.bigint ? z$1.coerce.bigint() : z$1.bigint();
|
|
180
|
+
if (min !== void 0) schema = schema.min(min);
|
|
181
|
+
if (max !== void 0) schema = schema.max(max);
|
|
182
|
+
return schema;
|
|
183
|
+
}
|
|
184
|
+
function pgArrayColumnToSchema(column, dimensions, z$1, coerce) {
|
|
185
|
+
const [baseType, baseConstraint] = column.dataType.split(" ");
|
|
186
|
+
let baseSchema;
|
|
187
|
+
switch (baseType) {
|
|
188
|
+
case "number":
|
|
189
|
+
baseSchema = numberColumnToSchema(column, baseConstraint, z$1, coerce);
|
|
190
|
+
break;
|
|
191
|
+
case "bigint":
|
|
192
|
+
baseSchema = bigintColumnToSchema(column, baseConstraint, z$1, coerce);
|
|
193
|
+
break;
|
|
194
|
+
case "boolean":
|
|
195
|
+
baseSchema = coerce === true || coerce?.boolean ? z$1.coerce.boolean() : z$1.boolean();
|
|
196
|
+
break;
|
|
197
|
+
case "string":
|
|
198
|
+
baseSchema = stringColumnToSchema(column, baseConstraint, z$1, coerce);
|
|
199
|
+
break;
|
|
200
|
+
case "object":
|
|
201
|
+
baseSchema = objectColumnToSchema(column, baseConstraint, z$1, coerce);
|
|
202
|
+
break;
|
|
203
|
+
case "array":
|
|
204
|
+
baseSchema = arrayColumnToSchema(column, baseConstraint, z$1, coerce);
|
|
205
|
+
break;
|
|
206
|
+
default: baseSchema = z$1.any();
|
|
207
|
+
}
|
|
208
|
+
let schema = z$1.array(baseSchema);
|
|
209
|
+
for (let i = 1; i < dimensions; i++) schema = z$1.array(schema);
|
|
210
|
+
return schema;
|
|
209
211
|
}
|
|
210
|
-
function arrayColumnToSchema(column, constraint, z, coerce) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
default: {
|
|
245
|
-
return z.array(z.any());
|
|
246
|
-
}
|
|
247
|
-
}
|
|
212
|
+
function arrayColumnToSchema(column, constraint, z$1, coerce) {
|
|
213
|
+
switch (constraint) {
|
|
214
|
+
case "geometry":
|
|
215
|
+
case "point": return z$1.tuple([z$1.number(), z$1.number()]);
|
|
216
|
+
case "line": return z$1.tuple([
|
|
217
|
+
z$1.number(),
|
|
218
|
+
z$1.number(),
|
|
219
|
+
z$1.number()
|
|
220
|
+
]);
|
|
221
|
+
case "vector":
|
|
222
|
+
case "halfvector": {
|
|
223
|
+
const length = column.length;
|
|
224
|
+
return length ? z$1.array(z$1.number()).length(length) : z$1.array(z$1.number());
|
|
225
|
+
}
|
|
226
|
+
case "int64vector": {
|
|
227
|
+
const length = column.length;
|
|
228
|
+
return length ? z$1.array(z$1.bigint().min(CONSTANTS.INT64_MIN).max(CONSTANTS.INT64_MAX)).length(length) : z$1.array(z$1.bigint().min(CONSTANTS.INT64_MIN).max(CONSTANTS.INT64_MAX));
|
|
229
|
+
}
|
|
230
|
+
case "basecolumn": {
|
|
231
|
+
const baseColumn = column.baseColumn;
|
|
232
|
+
if (baseColumn) {
|
|
233
|
+
const baseSchema = columnToSchema(baseColumn, {
|
|
234
|
+
zodInstance: z$1,
|
|
235
|
+
coerce
|
|
236
|
+
});
|
|
237
|
+
const length = column.length;
|
|
238
|
+
const schema = z$1.array(baseSchema);
|
|
239
|
+
if (length) return schema.length(length);
|
|
240
|
+
return schema;
|
|
241
|
+
}
|
|
242
|
+
return z$1.array(z$1.any());
|
|
243
|
+
}
|
|
244
|
+
default: return z$1.array(z$1.any());
|
|
245
|
+
}
|
|
248
246
|
}
|
|
249
|
-
function objectColumnToSchema(column, constraint, z, coerce) {
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
}
|
|
267
|
-
case 'line': {
|
|
268
|
-
return z.object({
|
|
269
|
-
a: z.number(),
|
|
270
|
-
b: z.number(),
|
|
271
|
-
c: z.number(),
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
default: {
|
|
275
|
-
return z.looseObject({});
|
|
276
|
-
}
|
|
277
|
-
}
|
|
247
|
+
function objectColumnToSchema(column, constraint, z$1, coerce) {
|
|
248
|
+
switch (constraint) {
|
|
249
|
+
case "buffer": return bufferSchema;
|
|
250
|
+
case "date": return coerce === true || coerce?.date ? z$1.coerce.date() : z$1.date();
|
|
251
|
+
case "geometry":
|
|
252
|
+
case "point": return z$1.object({
|
|
253
|
+
x: z$1.number(),
|
|
254
|
+
y: z$1.number()
|
|
255
|
+
});
|
|
256
|
+
case "json": return jsonSchema;
|
|
257
|
+
case "line": return z$1.object({
|
|
258
|
+
a: z$1.number(),
|
|
259
|
+
b: z$1.number(),
|
|
260
|
+
c: z$1.number()
|
|
261
|
+
});
|
|
262
|
+
default: return z$1.looseObject({});
|
|
263
|
+
}
|
|
278
264
|
}
|
|
279
|
-
function stringColumnToSchema(column, constraint, z, coerce) {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
if (constraint === 'int64') {
|
|
295
|
-
return bigintStringModeSchema;
|
|
296
|
-
}
|
|
297
|
-
if (constraint === 'uint64') {
|
|
298
|
-
return unsignedBigintStringModeSchema;
|
|
299
|
-
}
|
|
300
|
-
let schema = coerce === true || coerce?.string ? z.coerce.string() : z.string();
|
|
301
|
-
schema = regex ? schema.regex(regex) : schema;
|
|
302
|
-
return length && isLengthExact ? schema.length(length) : length ? schema.max(length) : schema;
|
|
265
|
+
function stringColumnToSchema(column, constraint, z$1, coerce) {
|
|
266
|
+
const { name: columnName, length, isLengthExact } = column;
|
|
267
|
+
let regex;
|
|
268
|
+
if (constraint === "binary") regex = /^[01]*$/;
|
|
269
|
+
if (constraint === "uuid") return z$1.uuid();
|
|
270
|
+
if (constraint === "enum") {
|
|
271
|
+
const enumValues = column.enumValues;
|
|
272
|
+
if (!enumValues) throw new Error(`Column "${(0, drizzle_orm.getTableName)((0, drizzle_orm.getColumnTable)(column))}"."${columnName}" is of 'enum' type, but lacks enum values`);
|
|
273
|
+
return z$1.enum(enumValues);
|
|
274
|
+
}
|
|
275
|
+
if (constraint === "int64") return bigintStringModeSchema;
|
|
276
|
+
if (constraint === "uint64") return unsignedBigintStringModeSchema;
|
|
277
|
+
let schema = coerce === true || coerce?.string ? z$1.coerce.string() : z$1.string();
|
|
278
|
+
schema = regex ? schema.regex(regex) : schema;
|
|
279
|
+
return length && isLengthExact ? schema.length(length) : length ? schema.max(length) : schema;
|
|
303
280
|
}
|
|
304
281
|
|
|
282
|
+
//#endregion
|
|
283
|
+
//#region src/utils.ts
|
|
305
284
|
function isWithEnum(column) {
|
|
306
|
-
|
|
285
|
+
return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
|
|
307
286
|
}
|
|
308
287
|
const isPgEnum = isWithEnum;
|
|
309
288
|
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/schema.ts
|
|
310
291
|
function getColumns(tableLike) {
|
|
311
|
-
|
|
292
|
+
return (0, drizzle_orm.isTable)(tableLike) ? (0, drizzle_orm.getTableColumns)(tableLike) : (0, drizzle_orm.getViewSelectedFields)(tableLike);
|
|
312
293
|
}
|
|
313
294
|
function handleColumns(columns, refinements, conditions, factory) {
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
if (conditions.nullable(column)) {
|
|
337
|
-
columnSchemas[key] = columnSchemas[key].nullable();
|
|
338
|
-
}
|
|
339
|
-
if (conditions.optional(column)) {
|
|
340
|
-
columnSchemas[key] = columnSchemas[key].optional();
|
|
341
|
-
}
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
return v4.z.object(columnSchemas);
|
|
295
|
+
const columnSchemas = {};
|
|
296
|
+
for (const [key, selected] of Object.entries(columns)) {
|
|
297
|
+
if (!(0, drizzle_orm.is)(selected, drizzle_orm.Column) && !(0, drizzle_orm.is)(selected, drizzle_orm.SQL) && !(0, drizzle_orm.is)(selected, drizzle_orm.SQL.Aliased) && typeof selected === "object") {
|
|
298
|
+
columnSchemas[key] = handleColumns((0, drizzle_orm.isTable)(selected) || (0, drizzle_orm.isView)(selected) ? getColumns(selected) : selected, refinements[key] ?? {}, conditions, factory);
|
|
299
|
+
continue;
|
|
300
|
+
}
|
|
301
|
+
const refinement = refinements[key];
|
|
302
|
+
if (refinement !== void 0 && typeof refinement !== "function") {
|
|
303
|
+
columnSchemas[key] = refinement;
|
|
304
|
+
continue;
|
|
305
|
+
}
|
|
306
|
+
const column = (0, drizzle_orm.is)(selected, drizzle_orm.Column) ? selected : void 0;
|
|
307
|
+
const schema = column ? columnToSchema(column, factory) : zod_v4.z.any();
|
|
308
|
+
const refined = typeof refinement === "function" ? refinement(schema) : schema;
|
|
309
|
+
if (conditions.never(column)) continue;
|
|
310
|
+
else columnSchemas[key] = refined;
|
|
311
|
+
if (column) {
|
|
312
|
+
if (conditions.nullable(column)) columnSchemas[key] = columnSchemas[key].nullable();
|
|
313
|
+
if (conditions.optional(column)) columnSchemas[key] = columnSchemas[key].optional();
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
return zod_v4.z.object(columnSchemas);
|
|
345
317
|
}
|
|
346
318
|
function handleEnum(enum_, factory) {
|
|
347
|
-
|
|
348
|
-
return zod.enum(enum_.enumValues);
|
|
319
|
+
return (factory?.zodInstance ?? zod_v4.z).enum(enum_.enumValues);
|
|
349
320
|
}
|
|
350
321
|
const selectConditions = {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
322
|
+
never: () => false,
|
|
323
|
+
optional: () => false,
|
|
324
|
+
nullable: (column) => !column.notNull
|
|
354
325
|
};
|
|
355
326
|
const insertConditions = {
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
nullable: (column) => !column.notNull,
|
|
327
|
+
never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always" || "identity" in (column ?? {}) && typeof column?.identity !== "undefined",
|
|
328
|
+
optional: (column) => !column.notNull || column.notNull && column.hasDefault,
|
|
329
|
+
nullable: (column) => !column.notNull
|
|
360
330
|
};
|
|
361
331
|
const updateConditions = {
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
nullable: (column) => !column.notNull,
|
|
332
|
+
never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always" || "identity" in (column ?? {}) && typeof column?.identity !== "undefined",
|
|
333
|
+
optional: () => true,
|
|
334
|
+
nullable: (column) => !column.notNull
|
|
366
335
|
};
|
|
367
336
|
const createSelectSchema = (entity, refine) => {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
const columns = getColumns(entity);
|
|
372
|
-
return handleColumns(columns, refine ?? {}, selectConditions);
|
|
337
|
+
if (isPgEnum(entity)) return handleEnum(entity);
|
|
338
|
+
return handleColumns(getColumns(entity), refine ?? {}, selectConditions);
|
|
373
339
|
};
|
|
374
340
|
const createInsertSchema = (entity, refine) => {
|
|
375
|
-
|
|
376
|
-
return handleColumns(columns, refine ?? {}, insertConditions);
|
|
341
|
+
return handleColumns(getColumns(entity), refine ?? {}, insertConditions);
|
|
377
342
|
};
|
|
378
343
|
const createUpdateSchema = (entity, refine) => {
|
|
379
|
-
|
|
380
|
-
return handleColumns(columns, refine ?? {}, updateConditions);
|
|
344
|
+
return handleColumns(getColumns(entity), refine ?? {}, updateConditions);
|
|
381
345
|
};
|
|
382
346
|
function createSchemaFactory(options) {
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
return { createSelectSchema, createInsertSchema, createUpdateSchema };
|
|
347
|
+
const createSelectSchema$1 = (entity, refine) => {
|
|
348
|
+
if (isPgEnum(entity)) return handleEnum(entity, options);
|
|
349
|
+
return handleColumns(getColumns(entity), refine ?? {}, selectConditions, options);
|
|
350
|
+
};
|
|
351
|
+
const createInsertSchema$1 = (entity, refine) => {
|
|
352
|
+
return handleColumns(getColumns(entity), refine ?? {}, insertConditions, options);
|
|
353
|
+
};
|
|
354
|
+
const createUpdateSchema$1 = (entity, refine) => {
|
|
355
|
+
return handleColumns(getColumns(entity), refine ?? {}, updateConditions, options);
|
|
356
|
+
};
|
|
357
|
+
return {
|
|
358
|
+
createSelectSchema: createSelectSchema$1,
|
|
359
|
+
createInsertSchema: createInsertSchema$1,
|
|
360
|
+
createUpdateSchema: createUpdateSchema$1
|
|
361
|
+
};
|
|
399
362
|
}
|
|
400
363
|
|
|
364
|
+
//#endregion
|
|
401
365
|
exports.bufferSchema = bufferSchema;
|
|
402
366
|
exports.createInsertSchema = createInsertSchema;
|
|
403
367
|
exports.createSchemaFactory = createSchemaFactory;
|
|
@@ -407,4 +371,4 @@ exports.isPgEnum = isPgEnum;
|
|
|
407
371
|
exports.isWithEnum = isWithEnum;
|
|
408
372
|
exports.jsonSchema = jsonSchema;
|
|
409
373
|
exports.literalSchema = literalSchema;
|
|
410
|
-
//# sourceMappingURL=index.cjs.map
|
|
374
|
+
//# sourceMappingURL=index.cjs.map
|