drizzle-typebox 1.0.0-beta.6-9514357 → 1.0.0-beta.6-051f3cd

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