drizzle-valibot 1.0.0-beta.9-5a93194 → 1.0.0-beta.9-40889e5
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 +332 -366
- 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 +304 -345
- 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,408 +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
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
default: {
|
|
89
|
-
schema = v__namespace.any();
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
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;
|
|
93
101
|
}
|
|
94
102
|
function numberColumnToSchema(column, constraint) {
|
|
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
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
integer = true;
|
|
183
|
-
break;
|
|
184
|
-
}
|
|
185
|
-
case 'unsigned': {
|
|
186
|
-
min = 0;
|
|
187
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
188
|
-
break;
|
|
189
|
-
}
|
|
190
|
-
default: {
|
|
191
|
-
min = Number.MIN_SAFE_INTEGER;
|
|
192
|
-
max = Number.MAX_SAFE_INTEGER;
|
|
193
|
-
break;
|
|
194
|
-
}
|
|
195
|
-
}
|
|
196
|
-
const actions = [v__namespace.minValue(min), v__namespace.maxValue(max)];
|
|
197
|
-
if (integer) {
|
|
198
|
-
actions.push(v__namespace.integer());
|
|
199
|
-
}
|
|
200
|
-
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);
|
|
201
190
|
}
|
|
202
191
|
/** @internal */
|
|
203
|
-
const bigintStringModeSchema =
|
|
204
|
-
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
|
205
|
-
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()));
|
|
206
193
|
/** @internal */
|
|
207
|
-
const unsignedBigintStringModeSchema =
|
|
208
|
-
// eslint-disable-next-line unicorn/prefer-native-coercion-functions
|
|
209
|
-
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()));
|
|
210
195
|
function bigintColumnToSchema(column, constraint) {
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
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();
|
|
212
|
+
}
|
|
213
|
+
function pgArrayColumnToSchema(column, dimensions) {
|
|
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;
|
|
231
240
|
}
|
|
232
241
|
function arrayColumnToSchema(column, constraint) {
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
default: {
|
|
264
|
-
return v__namespace.array(v__namespace.any());
|
|
265
|
-
}
|
|
266
|
-
}
|
|
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
|
+
}
|
|
267
271
|
}
|
|
268
272
|
function objectColumnToSchema(column, constraint) {
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
case 'line': {
|
|
287
|
-
return v__namespace.object({
|
|
288
|
-
a: v__namespace.number(),
|
|
289
|
-
b: v__namespace.number(),
|
|
290
|
-
c: v__namespace.number(),
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
default: {
|
|
294
|
-
return v__namespace.looseObject({});
|
|
295
|
-
}
|
|
296
|
-
}
|
|
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
|
+
}
|
|
297
289
|
}
|
|
298
290
|
function stringColumnToSchema(column, constraint) {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
}
|
|
316
|
-
if (constraint === 'uint64') {
|
|
317
|
-
return unsignedBigintStringModeSchema;
|
|
318
|
-
}
|
|
319
|
-
const actions = [];
|
|
320
|
-
if (regex) {
|
|
321
|
-
actions.push(v__namespace.regex(regex));
|
|
322
|
-
}
|
|
323
|
-
if (length && isLengthExact) {
|
|
324
|
-
actions.push(v__namespace.length(length));
|
|
325
|
-
}
|
|
326
|
-
else if (length) {
|
|
327
|
-
actions.push(v__namespace.maxLength(length));
|
|
328
|
-
}
|
|
329
|
-
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();
|
|
330
307
|
}
|
|
331
308
|
|
|
309
|
+
//#endregion
|
|
310
|
+
//#region src/utils.ts
|
|
332
311
|
function isColumnType(column, columnTypes) {
|
|
333
|
-
|
|
312
|
+
return columnTypes.includes(column.columnType);
|
|
334
313
|
}
|
|
335
314
|
function isWithEnum(column) {
|
|
336
|
-
|
|
315
|
+
return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
|
|
337
316
|
}
|
|
338
317
|
const isPgEnum = isWithEnum;
|
|
339
318
|
|
|
319
|
+
//#endregion
|
|
320
|
+
//#region src/schema.ts
|
|
340
321
|
function getColumns(tableLike) {
|
|
341
|
-
|
|
322
|
+
return (0, drizzle_orm.isTable)(tableLike) ? (0, drizzle_orm.getTableColumns)(tableLike) : (0, drizzle_orm.getViewSelectedFields)(tableLike);
|
|
342
323
|
}
|
|
343
324
|
function handleColumns(columns, refinements, conditions) {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (conditions.nullable(column)) {
|
|
367
|
-
columnSchemas[key] = v__namespace.nullable(columnSchemas[key]);
|
|
368
|
-
}
|
|
369
|
-
if (conditions.optional(column)) {
|
|
370
|
-
columnSchemas[key] = v__namespace.optional(columnSchemas[key]);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
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);
|
|
375
347
|
}
|
|
376
348
|
const createSelectSchema = (entity, refine) => {
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
optional: () => false,
|
|
384
|
-
nullable: (column) => !column.notNull,
|
|
385
|
-
});
|
|
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
|
+
});
|
|
386
355
|
};
|
|
387
356
|
const createInsertSchema = (entity, refine) => {
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
nullable: (column) => !column.notNull,
|
|
394
|
-
});
|
|
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
|
+
});
|
|
395
362
|
};
|
|
396
363
|
const createUpdateSchema = (entity, refine) => {
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
nullable: (column) => !column.notNull,
|
|
403
|
-
});
|
|
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
|
+
});
|
|
404
369
|
};
|
|
405
370
|
|
|
371
|
+
//#endregion
|
|
406
372
|
exports.bufferSchema = bufferSchema;
|
|
407
373
|
exports.createInsertSchema = createInsertSchema;
|
|
408
374
|
exports.createSelectSchema = createSelectSchema;
|
|
@@ -412,4 +378,4 @@ exports.isPgEnum = isPgEnum;
|
|
|
412
378
|
exports.isWithEnum = isWithEnum;
|
|
413
379
|
exports.jsonSchema = jsonSchema;
|
|
414
380
|
exports.literalSchema = literalSchema;
|
|
415
|
-
//# sourceMappingURL=index.cjs.map
|
|
381
|
+
//# sourceMappingURL=index.cjs.map
|