drizzle-arktype 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,434 +1,334 @@
1
- 'use strict';
2
-
3
- var arktype = require('arktype');
4
- var drizzleOrm = require('drizzle-orm');
1
+ let arktype = require("arktype");
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
 
26
+ //#endregion
27
+ //#region src/column.ts
27
28
  const literalSchema = arktype.type.string.or(arktype.type.number).or(arktype.type.boolean).or(arktype.type.null);
28
29
  const jsonSchema = literalSchema.or(arktype.type.unknown.as().array()).or(arktype.type.object.as());
29
- const bufferSchema = arktype.type.unknown.narrow((value) => value instanceof Buffer).as().describe('a Buffer instance');
30
+ const bufferSchema = arktype.type.unknown.narrow((value) => value instanceof Buffer).as().describe("a Buffer instance");
30
31
  function columnToSchema(column) {
31
- let schema;
32
- // Check for PG array columns (have dimensions property instead of changing dataType)
33
- const dimensions = column.dimensions;
34
- if (typeof dimensions === 'number' && dimensions > 0) {
35
- return pgArrayColumnToSchema(column, dimensions);
36
- }
37
- const { type: columnType, constraint } = drizzleOrm.extractExtendedColumnType(column);
38
- switch (columnType) {
39
- case 'array': {
40
- schema = arrayColumnToSchema(column, constraint);
41
- break;
42
- }
43
- case 'object': {
44
- schema = objectColumnToSchema(column, constraint);
45
- break;
46
- }
47
- case 'number': {
48
- schema = numberColumnToSchema(column, constraint);
49
- break;
50
- }
51
- case 'bigint': {
52
- schema = bigintColumnToSchema(column, constraint);
53
- break;
54
- }
55
- case 'boolean': {
56
- schema = arktype.type.boolean;
57
- break;
58
- }
59
- case 'string': {
60
- schema = stringColumnToSchema(column, constraint);
61
- break;
62
- }
63
- case 'custom': {
64
- schema = arktype.type.unknown;
65
- break;
66
- }
67
- default: {
68
- schema = arktype.type.unknown;
69
- }
70
- }
71
- return schema;
32
+ let schema;
33
+ const dimensions = column.dimensions;
34
+ if (typeof dimensions === "number" && dimensions > 0) return pgArrayColumnToSchema(column, dimensions);
35
+ const { type: columnType, constraint } = (0, drizzle_orm.extractExtendedColumnType)(column);
36
+ switch (columnType) {
37
+ case "array":
38
+ schema = arrayColumnToSchema(column, constraint);
39
+ break;
40
+ case "object":
41
+ schema = objectColumnToSchema(column, constraint);
42
+ break;
43
+ case "number":
44
+ schema = numberColumnToSchema(column, constraint);
45
+ break;
46
+ case "bigint":
47
+ schema = bigintColumnToSchema(column, constraint);
48
+ break;
49
+ case "boolean":
50
+ schema = arktype.type.boolean;
51
+ break;
52
+ case "string":
53
+ schema = stringColumnToSchema(column, constraint);
54
+ break;
55
+ case "custom":
56
+ schema = arktype.type.unknown;
57
+ break;
58
+ default: schema = arktype.type.unknown;
59
+ }
60
+ return schema;
72
61
  }
73
62
  function numberColumnToSchema(column, constraint) {
74
- let min;
75
- let max;
76
- let integer = false;
77
- switch (constraint) {
78
- case 'int8': {
79
- min = CONSTANTS.INT8_MIN;
80
- max = CONSTANTS.INT8_MAX;
81
- integer = true;
82
- break;
83
- }
84
- case 'uint8': {
85
- min = 0;
86
- max = CONSTANTS.INT8_UNSIGNED_MAX;
87
- integer = true;
88
- break;
89
- }
90
- case 'int16': {
91
- min = CONSTANTS.INT16_MIN;
92
- max = CONSTANTS.INT16_MAX;
93
- integer = true;
94
- break;
95
- }
96
- case 'uint16': {
97
- min = 0;
98
- max = CONSTANTS.INT16_UNSIGNED_MAX;
99
- integer = true;
100
- break;
101
- }
102
- case 'int24': {
103
- min = CONSTANTS.INT24_MIN;
104
- max = CONSTANTS.INT24_MAX;
105
- integer = true;
106
- break;
107
- }
108
- case 'uint24': {
109
- min = 0;
110
- max = CONSTANTS.INT24_UNSIGNED_MAX;
111
- integer = true;
112
- break;
113
- }
114
- case 'int32': {
115
- min = CONSTANTS.INT32_MIN;
116
- max = CONSTANTS.INT32_MAX;
117
- integer = true;
118
- break;
119
- }
120
- case 'uint32': {
121
- min = 0;
122
- max = CONSTANTS.INT32_UNSIGNED_MAX;
123
- integer = true;
124
- break;
125
- }
126
- case 'int53': {
127
- min = Number.MIN_SAFE_INTEGER;
128
- max = Number.MAX_SAFE_INTEGER;
129
- integer = true;
130
- break;
131
- }
132
- case 'uint53': {
133
- min = 0;
134
- max = Number.MAX_SAFE_INTEGER;
135
- integer = true;
136
- break;
137
- }
138
- case 'float': {
139
- min = CONSTANTS.INT24_MIN;
140
- max = CONSTANTS.INT24_MAX;
141
- break;
142
- }
143
- case 'ufloat': {
144
- min = 0;
145
- max = CONSTANTS.INT24_UNSIGNED_MAX;
146
- break;
147
- }
148
- case 'double': {
149
- min = CONSTANTS.INT48_MIN;
150
- max = CONSTANTS.INT48_MAX;
151
- break;
152
- }
153
- case 'udouble': {
154
- min = 0;
155
- max = CONSTANTS.INT48_UNSIGNED_MAX;
156
- break;
157
- }
158
- case 'year': {
159
- min = 1901;
160
- max = 2155;
161
- integer = true;
162
- break;
163
- }
164
- case 'unsigned': {
165
- min = 0;
166
- max = Number.MAX_SAFE_INTEGER;
167
- break;
168
- }
169
- default: {
170
- min = Number.MIN_SAFE_INTEGER;
171
- max = Number.MAX_SAFE_INTEGER;
172
- break;
173
- }
174
- }
175
- return (integer ? arktype.type.keywords.number.integer : arktype.type.number).atLeast(min).atMost(max);
63
+ let min;
64
+ let max;
65
+ let integer = false;
66
+ switch (constraint) {
67
+ case "int8":
68
+ min = CONSTANTS.INT8_MIN;
69
+ max = CONSTANTS.INT8_MAX;
70
+ integer = true;
71
+ break;
72
+ case "uint8":
73
+ min = 0;
74
+ max = CONSTANTS.INT8_UNSIGNED_MAX;
75
+ integer = true;
76
+ break;
77
+ case "int16":
78
+ min = CONSTANTS.INT16_MIN;
79
+ max = CONSTANTS.INT16_MAX;
80
+ integer = true;
81
+ break;
82
+ case "uint16":
83
+ min = 0;
84
+ max = CONSTANTS.INT16_UNSIGNED_MAX;
85
+ integer = true;
86
+ break;
87
+ case "int24":
88
+ min = CONSTANTS.INT24_MIN;
89
+ max = CONSTANTS.INT24_MAX;
90
+ integer = true;
91
+ break;
92
+ case "uint24":
93
+ min = 0;
94
+ max = CONSTANTS.INT24_UNSIGNED_MAX;
95
+ integer = true;
96
+ break;
97
+ case "int32":
98
+ min = CONSTANTS.INT32_MIN;
99
+ max = CONSTANTS.INT32_MAX;
100
+ integer = true;
101
+ break;
102
+ case "uint32":
103
+ min = 0;
104
+ max = CONSTANTS.INT32_UNSIGNED_MAX;
105
+ integer = true;
106
+ break;
107
+ case "int53":
108
+ min = Number.MIN_SAFE_INTEGER;
109
+ max = Number.MAX_SAFE_INTEGER;
110
+ integer = true;
111
+ break;
112
+ case "uint53":
113
+ min = 0;
114
+ max = Number.MAX_SAFE_INTEGER;
115
+ integer = true;
116
+ break;
117
+ case "float":
118
+ min = CONSTANTS.INT24_MIN;
119
+ max = CONSTANTS.INT24_MAX;
120
+ break;
121
+ case "ufloat":
122
+ min = 0;
123
+ max = CONSTANTS.INT24_UNSIGNED_MAX;
124
+ break;
125
+ case "double":
126
+ min = CONSTANTS.INT48_MIN;
127
+ max = CONSTANTS.INT48_MAX;
128
+ break;
129
+ case "udouble":
130
+ min = 0;
131
+ max = CONSTANTS.INT48_UNSIGNED_MAX;
132
+ break;
133
+ case "year":
134
+ min = 1901;
135
+ max = 2155;
136
+ integer = true;
137
+ break;
138
+ case "unsigned":
139
+ min = 0;
140
+ max = Number.MAX_SAFE_INTEGER;
141
+ break;
142
+ default:
143
+ min = Number.MIN_SAFE_INTEGER;
144
+ max = Number.MAX_SAFE_INTEGER;
145
+ break;
146
+ }
147
+ return (integer ? arktype.type.keywords.number.integer : arktype.type.number).atLeast(min).atMost(max);
176
148
  }
177
149
  function pgArrayColumnToSchema(column, dimensions) {
178
- // PG style: the column IS the base type, with dimensions indicating array depth
179
- // Get the base schema from the column's own dataType
180
- const [baseType, baseConstraint] = column.dataType.split(' ');
181
- let baseSchema;
182
- switch (baseType) {
183
- case 'number':
184
- baseSchema = numberColumnToSchema(column, baseConstraint);
185
- break;
186
- case 'bigint':
187
- baseSchema = bigintColumnToSchema(column, baseConstraint);
188
- break;
189
- case 'boolean':
190
- baseSchema = arktype.type.boolean;
191
- break;
192
- case 'string':
193
- baseSchema = stringColumnToSchema(column, baseConstraint);
194
- break;
195
- case 'object':
196
- baseSchema = objectColumnToSchema(column, baseConstraint);
197
- break;
198
- case 'array':
199
- // Handle array types like point, line, etc.
200
- baseSchema = arrayColumnToSchema(column, baseConstraint);
201
- break;
202
- default:
203
- baseSchema = arktype.type.unknown;
204
- }
205
- // Wrap in arrays based on dimensions
206
- // Note: For PG arrays, column.length is the base type's length (e.g., varchar(10)), not array size
207
- let schema = baseSchema.array();
208
- for (let i = 1; i < dimensions; i++) {
209
- schema = schema.array();
210
- }
211
- return schema;
150
+ const [baseType, baseConstraint] = column.dataType.split(" ");
151
+ let baseSchema;
152
+ switch (baseType) {
153
+ case "number":
154
+ baseSchema = numberColumnToSchema(column, baseConstraint);
155
+ break;
156
+ case "bigint":
157
+ baseSchema = bigintColumnToSchema(column, baseConstraint);
158
+ break;
159
+ case "boolean":
160
+ baseSchema = arktype.type.boolean;
161
+ break;
162
+ case "string":
163
+ baseSchema = stringColumnToSchema(column, baseConstraint);
164
+ break;
165
+ case "object":
166
+ baseSchema = objectColumnToSchema(column, baseConstraint);
167
+ break;
168
+ case "array":
169
+ baseSchema = arrayColumnToSchema(column, baseConstraint);
170
+ break;
171
+ default: baseSchema = arktype.type.unknown;
172
+ }
173
+ let schema = baseSchema.array();
174
+ for (let i = 1; i < dimensions; i++) schema = schema.array();
175
+ return schema;
212
176
  }
213
177
  function arrayColumnToSchema(column, constraint) {
214
- switch (constraint) {
215
- case 'geometry':
216
- case 'point': {
217
- return arktype.type([arktype.type.number, arktype.type.number]);
218
- }
219
- case 'line': {
220
- return arktype.type([arktype.type.number, arktype.type.number, arktype.type.number]);
221
- }
222
- case 'vector':
223
- case 'halfvector': {
224
- const length = column.length;
225
- return length ? arktype.type.number.array().exactlyLength(length) : arktype.type.number.array();
226
- }
227
- case 'int64vector': {
228
- const length = column.length;
229
- // TODO - INT64 number range
230
- return length ? arktype.type.bigint.array().exactlyLength(length) : arktype.type.bigint.array();
231
- }
232
- case 'basecolumn': {
233
- // CockroachDB/GEL style: has a separate baseColumn
234
- const baseColumn = column.baseColumn;
235
- if (baseColumn) {
236
- const length = column.length;
237
- const schema = columnToSchema(baseColumn).array();
238
- if (length)
239
- return schema.exactlyLength(length);
240
- return schema;
241
- }
242
- return arktype.type.unknown.array();
243
- }
244
- default: {
245
- return arktype.type.unknown.array();
246
- }
247
- }
178
+ switch (constraint) {
179
+ case "geometry":
180
+ case "point": return (0, arktype.type)([arktype.type.number, arktype.type.number]);
181
+ case "line": return (0, arktype.type)([
182
+ arktype.type.number,
183
+ arktype.type.number,
184
+ arktype.type.number
185
+ ]);
186
+ case "vector":
187
+ case "halfvector": {
188
+ const length = column.length;
189
+ return length ? arktype.type.number.array().exactlyLength(length) : arktype.type.number.array();
190
+ }
191
+ case "int64vector": {
192
+ const length = column.length;
193
+ return length ? arktype.type.bigint.array().exactlyLength(length) : arktype.type.bigint.array();
194
+ }
195
+ case "basecolumn": {
196
+ const baseColumn = column.baseColumn;
197
+ if (baseColumn) {
198
+ const length = column.length;
199
+ const schema = columnToSchema(baseColumn).array();
200
+ if (length) return schema.exactlyLength(length);
201
+ return schema;
202
+ }
203
+ return arktype.type.unknown.array();
204
+ }
205
+ default: return arktype.type.unknown.array();
206
+ }
248
207
  }
249
208
  function objectColumnToSchema(column, constraint) {
250
- switch (constraint) {
251
- case 'buffer': {
252
- return bufferSchema;
253
- }
254
- case 'date': {
255
- return arktype.type.Date;
256
- }
257
- case 'geometry':
258
- case 'point': {
259
- return arktype.type({
260
- x: arktype.type.number,
261
- y: arktype.type.number,
262
- });
263
- }
264
- case 'json': {
265
- return jsonSchema;
266
- }
267
- case 'line': {
268
- return arktype.type({
269
- a: arktype.type.number,
270
- b: arktype.type.number,
271
- c: arktype.type.number,
272
- });
273
- }
274
- default: {
275
- return arktype.type({});
276
- }
277
- }
209
+ switch (constraint) {
210
+ case "buffer": return bufferSchema;
211
+ case "date": return arktype.type.Date;
212
+ case "geometry":
213
+ case "point": return (0, arktype.type)({
214
+ x: arktype.type.number,
215
+ y: arktype.type.number
216
+ });
217
+ case "json": return jsonSchema;
218
+ case "line": return (0, arktype.type)({
219
+ a: arktype.type.number,
220
+ b: arktype.type.number,
221
+ c: arktype.type.number
222
+ });
223
+ default: return (0, arktype.type)({});
224
+ }
278
225
  }
279
226
  /** @internal */
280
- const unsignedBigintNarrow = (v, ctx) => v < 0n ? ctx.mustBe('greater than') : v > CONSTANTS.INT64_UNSIGNED_MAX ? ctx.mustBe('less than') : true;
227
+ const unsignedBigintNarrow = (v, ctx) => v < 0n ? ctx.mustBe("greater than") : v > CONSTANTS.INT64_UNSIGNED_MAX ? ctx.mustBe("less than") : true;
281
228
  /** @internal */
282
- const bigintNarrow = (v, ctx) => v < CONSTANTS.INT64_MIN ? ctx.mustBe('greater than') : v > CONSTANTS.INT64_MAX ? ctx.mustBe('less than') : true;
229
+ const bigintNarrow = (v, ctx) => v < CONSTANTS.INT64_MIN ? ctx.mustBe("greater than") : v > CONSTANTS.INT64_MAX ? ctx.mustBe("less than") : true;
283
230
  /** @internal */
284
231
  const bigintStringModeSchema = arktype.type.string.narrow((v, ctx) => {
285
- if (typeof v !== 'string') {
286
- return ctx.mustBe('a string');
287
- }
288
- if (!(/^-?\d+$/.test(v))) {
289
- return ctx.mustBe('a string representing a number');
290
- }
291
- const bigint = BigInt(v);
292
- if (bigint < CONSTANTS.INT64_MIN) {
293
- return ctx.mustBe('greater than');
294
- }
295
- if (bigint > CONSTANTS.INT64_MAX) {
296
- return ctx.mustBe('less than');
297
- }
298
- return true;
232
+ if (typeof v !== "string") return ctx.mustBe("a string");
233
+ if (!/^-?\d+$/.test(v)) return ctx.mustBe("a string representing a number");
234
+ const bigint = BigInt(v);
235
+ if (bigint < CONSTANTS.INT64_MIN) return ctx.mustBe("greater than");
236
+ if (bigint > CONSTANTS.INT64_MAX) return ctx.mustBe("less than");
237
+ return true;
299
238
  });
300
239
  /** @internal */
301
240
  const unsignedBigintStringModeSchema = arktype.type.string.narrow((v, ctx) => {
302
- if (typeof v !== 'string') {
303
- return ctx.mustBe('a string');
304
- }
305
- if (!(/^\d+$/.test(v))) {
306
- return ctx.mustBe('a string representing a number');
307
- }
308
- const bigint = BigInt(v);
309
- if (bigint < 0) {
310
- return ctx.mustBe('greater than');
311
- }
312
- if (bigint > CONSTANTS.INT64_MAX) {
313
- return ctx.mustBe('less than');
314
- }
315
- return true;
241
+ if (typeof v !== "string") return ctx.mustBe("a string");
242
+ if (!/^\d+$/.test(v)) return ctx.mustBe("a string representing a number");
243
+ const bigint = BigInt(v);
244
+ if (bigint < 0) return ctx.mustBe("greater than");
245
+ if (bigint > CONSTANTS.INT64_MAX) return ctx.mustBe("less than");
246
+ return true;
316
247
  });
317
248
  function bigintColumnToSchema(column, constraint) {
318
- switch (constraint) {
319
- case 'int64': {
320
- return arktype.type.bigint.narrow(bigintNarrow);
321
- }
322
- case 'uint64': {
323
- return arktype.type.bigint.narrow(unsignedBigintNarrow);
324
- }
325
- }
326
- return arktype.type.bigint;
249
+ switch (constraint) {
250
+ case "int64": return arktype.type.bigint.narrow(bigintNarrow);
251
+ case "uint64": return arktype.type.bigint.narrow(unsignedBigintNarrow);
252
+ }
253
+ return arktype.type.bigint;
327
254
  }
328
255
  function stringColumnToSchema(column, constraint) {
329
- const { name: columnName, length, isLengthExact } = column;
330
- if (constraint === 'binary') {
331
- return arktype.type(`/^[01]${length ? `{${isLengthExact ? length : `0,${length}`}}` : '*'}$/`)
332
- .describe(`a string containing ones or zeros${length ? ` while being ${isLengthExact ? '' : 'up to '}${length} characters long` : ''}`);
333
- }
334
- if (constraint === 'uuid') {
335
- return arktype.type(/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu).describe('a RFC-4122-compliant UUID');
336
- }
337
- if (constraint === 'enum') {
338
- const enumValues = column.enumValues;
339
- if (!enumValues) {
340
- throw new Error(`Column "${drizzleOrm.getTableName(drizzleOrm.getColumnTable(column))}"."${columnName}" is of 'enum' type, but lacks enum values`);
341
- }
342
- return arktype.type.enumerated(...enumValues);
343
- }
344
- if (constraint === 'int64') {
345
- return bigintStringModeSchema;
346
- }
347
- if (constraint === 'uint64') {
348
- return unsignedBigintStringModeSchema;
349
- }
350
- return length && isLengthExact
351
- ? arktype.type.string.exactlyLength(length)
352
- : length
353
- ? arktype.type.string.atMostLength(length)
354
- : arktype.type.string;
256
+ const { name: columnName, length, isLengthExact } = column;
257
+ if (constraint === "binary") return (0, arktype.type)(`/^[01]${length ? `{${isLengthExact ? length : `0,${length}`}}` : "*"}$/`).describe(`a string containing ones or zeros${length ? ` while being ${isLengthExact ? "" : "up to "}${length} characters long` : ""}`);
258
+ if (constraint === "uuid") return (0, arktype.type)(/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu).describe("a RFC-4122-compliant UUID");
259
+ if (constraint === "enum") {
260
+ const enumValues = column.enumValues;
261
+ if (!enumValues) throw new Error(`Column "${(0, drizzle_orm.getTableName)((0, drizzle_orm.getColumnTable)(column))}"."${columnName}" is of 'enum' type, but lacks enum values`);
262
+ return arktype.type.enumerated(...enumValues);
263
+ }
264
+ if (constraint === "int64") return bigintStringModeSchema;
265
+ if (constraint === "uint64") return unsignedBigintStringModeSchema;
266
+ return length && isLengthExact ? arktype.type.string.exactlyLength(length) : length ? arktype.type.string.atMostLength(length) : arktype.type.string;
355
267
  }
356
268
 
269
+ //#endregion
270
+ //#region src/utils.ts
357
271
  function isColumnType(column, columnTypes) {
358
- return columnTypes.includes(column.columnType);
272
+ return columnTypes.includes(column.columnType);
359
273
  }
360
274
  function isWithEnum(column) {
361
- return 'enumValues' in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
275
+ return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
362
276
  }
363
277
  const isPgEnum = isWithEnum;
364
278
 
279
+ //#endregion
280
+ //#region src/schema.ts
365
281
  function getColumns(tableLike) {
366
- return drizzleOrm.isTable(tableLike) ? drizzleOrm.getTableColumns(tableLike) : drizzleOrm.getViewSelectedFields(tableLike);
282
+ return (0, drizzle_orm.isTable)(tableLike) ? (0, drizzle_orm.getTableColumns)(tableLike) : (0, drizzle_orm.getViewSelectedFields)(tableLike);
367
283
  }
368
284
  function handleColumns(columns, refinements, conditions) {
369
- const columnSchemas = {};
370
- for (const [key, selected] of Object.entries(columns)) {
371
- if (!drizzleOrm.is(selected, drizzleOrm.Column) && !drizzleOrm.is(selected, drizzleOrm.SQL) && !drizzleOrm.is(selected, drizzleOrm.SQL.Aliased) && typeof selected === 'object') {
372
- const columns = drizzleOrm.isTable(selected) || drizzleOrm.isView(selected) ? getColumns(selected) : selected;
373
- columnSchemas[key] = handleColumns(columns, refinements[key] ?? {}, conditions);
374
- continue;
375
- }
376
- const refinement = refinements[key];
377
- if (refinement !== undefined
378
- && (typeof refinement !== 'function' || (typeof refinement === 'function' && refinement.expression !== undefined))) {
379
- columnSchemas[key] = refinement;
380
- continue;
381
- }
382
- const column = drizzleOrm.is(selected, drizzleOrm.Column) ? selected : undefined;
383
- const schema = column ? columnToSchema(column) : arktype.type.unknown;
384
- const refined = typeof refinement === 'function' ? refinement(schema) : schema;
385
- if (conditions.never(column)) {
386
- continue;
387
- }
388
- else {
389
- columnSchemas[key] = refined;
390
- }
391
- if (column) {
392
- if (conditions.nullable(column)) {
393
- columnSchemas[key] = columnSchemas[key].or(arktype.type.null);
394
- }
395
- if (conditions.optional(column)) {
396
- columnSchemas[key] = columnSchemas[key].optional();
397
- }
398
- }
399
- }
400
- return arktype.type(columnSchemas);
285
+ const columnSchemas = {};
286
+ for (const [key, selected] of Object.entries(columns)) {
287
+ 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") {
288
+ columnSchemas[key] = handleColumns((0, drizzle_orm.isTable)(selected) || (0, drizzle_orm.isView)(selected) ? getColumns(selected) : selected, refinements[key] ?? {}, conditions);
289
+ continue;
290
+ }
291
+ const refinement = refinements[key];
292
+ if (refinement !== void 0 && (typeof refinement !== "function" || typeof refinement === "function" && refinement.expression !== void 0)) {
293
+ columnSchemas[key] = refinement;
294
+ continue;
295
+ }
296
+ const column = (0, drizzle_orm.is)(selected, drizzle_orm.Column) ? selected : void 0;
297
+ const schema = column ? columnToSchema(column) : arktype.type.unknown;
298
+ const refined = typeof refinement === "function" ? refinement(schema) : schema;
299
+ if (conditions.never(column)) continue;
300
+ else columnSchemas[key] = refined;
301
+ if (column) {
302
+ if (conditions.nullable(column)) columnSchemas[key] = columnSchemas[key].or(arktype.type.null);
303
+ if (conditions.optional(column)) columnSchemas[key] = columnSchemas[key].optional();
304
+ }
305
+ }
306
+ return (0, arktype.type)(columnSchemas);
401
307
  }
402
308
  const createSelectSchema = ((entity, refine) => {
403
- if (isPgEnum(entity)) {
404
- return arktype.type.enumerated(...entity.enumValues);
405
- }
406
- const columns = getColumns(entity);
407
- return handleColumns(columns, refine ?? {}, {
408
- never: () => false,
409
- optional: () => false,
410
- nullable: (column) => !column.notNull,
411
- });
309
+ if (isPgEnum(entity)) return arktype.type.enumerated(...entity.enumValues);
310
+ return handleColumns(getColumns(entity), refine ?? {}, {
311
+ never: () => false,
312
+ optional: () => false,
313
+ nullable: (column) => !column.notNull
314
+ });
412
315
  });
413
316
  const createInsertSchema = ((entity, refine) => {
414
- const columns = getColumns(entity);
415
- return handleColumns(columns, refine ?? {}, {
416
- never: (column) => column?.generated?.type === 'always' || column?.generatedIdentity?.type === 'always'
417
- || ('identity' in (column ?? {}) && typeof column?.identity !== 'undefined'),
418
- optional: (column) => !column.notNull || (column.notNull && column.hasDefault),
419
- nullable: (column) => !column.notNull,
420
- });
317
+ return handleColumns(getColumns(entity), refine ?? {}, {
318
+ never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always" || "identity" in (column ?? {}) && typeof column?.identity !== "undefined",
319
+ optional: (column) => !column.notNull || column.notNull && column.hasDefault,
320
+ nullable: (column) => !column.notNull
321
+ });
421
322
  });
422
323
  const createUpdateSchema = ((entity, refine) => {
423
- const columns = getColumns(entity);
424
- return handleColumns(columns, refine ?? {}, {
425
- never: (column) => column?.generated?.type === 'always' || column?.generatedIdentity?.type === 'always'
426
- || ('identity' in (column ?? {}) && typeof column?.identity !== 'undefined'),
427
- optional: () => true,
428
- nullable: (column) => !column.notNull,
429
- });
324
+ return handleColumns(getColumns(entity), refine ?? {}, {
325
+ never: (column) => column?.generated?.type === "always" || column?.generatedIdentity?.type === "always" || "identity" in (column ?? {}) && typeof column?.identity !== "undefined",
326
+ optional: () => true,
327
+ nullable: (column) => !column.notNull
328
+ });
430
329
  });
431
330
 
331
+ //#endregion
432
332
  exports.bufferSchema = bufferSchema;
433
333
  exports.createInsertSchema = createInsertSchema;
434
334
  exports.createSelectSchema = createSelectSchema;
@@ -438,4 +338,4 @@ exports.isPgEnum = isPgEnum;
438
338
  exports.isWithEnum = isWithEnum;
439
339
  exports.jsonSchema = jsonSchema;
440
340
  exports.literalSchema = literalSchema;
441
- //# sourceMappingURL=index.cjs.map
341
+ //# sourceMappingURL=index.cjs.map