drizzle-valibot 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 CHANGED
@@ -1,408 +1,374 @@
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
- }
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
- var v__namespace = /*#__PURE__*/_interopNamespaceDefault(v);
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
- 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,
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
- 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()),
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 = v__namespace.custom((v) => v instanceof Buffer);
67
+ const bufferSchema = valibot.custom((v) => v instanceof Buffer);
53
68
  function mapEnumValues(values) {
54
- return Object.fromEntries(values.map((value) => [value, value]));
69
+ return Object.fromEntries(values.map((value) => [value, value]));
55
70
  }
56
71
  function columnToSchema(column) {
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;
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
- 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);
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 = 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()));
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 = 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()));
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
- 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();
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
- 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
- }
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
- 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
- }
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
- 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();
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
- return columnTypes.includes(column.columnType);
312
+ return columnTypes.includes(column.columnType);
334
313
  }
335
314
  function isWithEnum(column) {
336
- return 'enumValues' in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
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
- return drizzleOrm.isTable(tableLike) ? drizzleOrm.getTableColumns(tableLike) : drizzleOrm.getViewSelectedFields(tableLike);
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
- 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);
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
- 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
- });
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
- 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
- });
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
- 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
- });
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