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