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