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