drizzle-arktype 0.1.3 → 1.0.0-beta.10-b5fdd85

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,300 +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
 
27
- function isColumnType(column, columnTypes) {
28
- return columnTypes.includes(column.columnType);
29
- }
30
- function isWithEnum(column) {
31
- return 'enumValues' in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
32
- }
33
- const isPgEnum = isWithEnum;
34
-
26
+ //#endregion
27
+ //#region src/column.ts
35
28
  const literalSchema = arktype.type.string.or(arktype.type.number).or(arktype.type.boolean).or(arktype.type.null);
36
29
  const jsonSchema = literalSchema.or(arktype.type.unknown.as().array()).or(arktype.type.object.as());
37
- const bufferSchema = arktype.type.unknown.narrow((value) => value instanceof Buffer).as().describe(// eslint-disable-line no-instanceof/no-instanceof
38
- 'a Buffer instance');
30
+ const bufferSchema = arktype.type.unknown.narrow((value) => value instanceof Buffer).as().describe("a Buffer instance");
39
31
  function columnToSchema(column) {
40
- let schema;
41
- if (isWithEnum(column)) {
42
- schema = column.enumValues.length ? arktype.type.enumerated(...column.enumValues) : arktype.type.string;
43
- }
44
- if (!schema) {
45
- // Handle specific types
46
- if (isColumnType(column, ['PgGeometry', 'PgPointTuple'])) {
47
- schema = arktype.type([arktype.type.number, arktype.type.number]);
48
- }
49
- else if (isColumnType(column, ['PgGeometryObject', 'PgPointObject'])) {
50
- schema = arktype.type({
51
- x: arktype.type.number,
52
- y: arktype.type.number,
53
- });
54
- }
55
- else if (isColumnType(column, ['PgHalfVector', 'PgVector'])) {
56
- schema = column.dimensions
57
- ? arktype.type.number.array().exactlyLength(column.dimensions)
58
- : arktype.type.number.array();
59
- }
60
- else if (isColumnType(column, ['PgLine'])) {
61
- schema = arktype.type([arktype.type.number, arktype.type.number, arktype.type.number]);
62
- }
63
- else if (isColumnType(column, ['PgLineABC'])) {
64
- schema = arktype.type({
65
- a: arktype.type.number,
66
- b: arktype.type.number,
67
- c: arktype.type.number,
68
- });
69
- } // Handle other types
70
- else if (isColumnType(column, ['PgArray'])) {
71
- const arraySchema = columnToSchema(column.baseColumn).array();
72
- schema = column.size ? arraySchema.exactlyLength(column.size) : arraySchema;
73
- }
74
- else if (column.dataType === 'array') {
75
- schema = arktype.type.unknown.array();
76
- }
77
- else if (column.dataType === 'number') {
78
- schema = numberColumnToSchema(column);
79
- }
80
- else if (column.dataType === 'bigint') {
81
- schema = bigintColumnToSchema(column);
82
- }
83
- else if (column.dataType === 'boolean') {
84
- schema = arktype.type.boolean;
85
- }
86
- else if (column.dataType === 'date') {
87
- schema = arktype.type.Date;
88
- }
89
- else if (column.dataType === 'string') {
90
- schema = stringColumnToSchema(column);
91
- }
92
- else if (column.dataType === 'json') {
93
- schema = jsonSchema;
94
- }
95
- else if (column.dataType === 'custom') {
96
- schema = arktype.type.unknown;
97
- }
98
- else if (column.dataType === 'buffer') {
99
- schema = bufferSchema;
100
- }
101
- }
102
- if (!schema) {
103
- schema = arktype.type.unknown;
104
- }
105
- 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;
61
+ }
62
+ function numberColumnToSchema(column, constraint) {
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);
148
+ }
149
+ function pgArrayColumnToSchema(column, dimensions) {
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;
176
+ }
177
+ function arrayColumnToSchema(column, constraint) {
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
+ }
106
207
  }
107
- function numberColumnToSchema(column) {
108
- let unsigned = column.getSQLType().includes('unsigned');
109
- let min;
110
- let max;
111
- let integer = false;
112
- if (isColumnType(column, ['MySqlTinyInt', 'SingleStoreTinyInt'])) {
113
- min = unsigned ? 0 : CONSTANTS.INT8_MIN;
114
- max = unsigned ? CONSTANTS.INT8_UNSIGNED_MAX : CONSTANTS.INT8_MAX;
115
- integer = true;
116
- }
117
- else if (isColumnType(column, [
118
- 'PgSmallInt',
119
- 'PgSmallSerial',
120
- 'MySqlSmallInt',
121
- 'SingleStoreSmallInt',
122
- ])) {
123
- min = unsigned ? 0 : CONSTANTS.INT16_MIN;
124
- max = unsigned ? CONSTANTS.INT16_UNSIGNED_MAX : CONSTANTS.INT16_MAX;
125
- integer = true;
126
- }
127
- else if (isColumnType(column, [
128
- 'PgReal',
129
- 'MySqlFloat',
130
- 'MySqlMediumInt',
131
- 'SingleStoreFloat',
132
- 'SingleStoreMediumInt',
133
- ])) {
134
- min = unsigned ? 0 : CONSTANTS.INT24_MIN;
135
- max = unsigned ? CONSTANTS.INT24_UNSIGNED_MAX : CONSTANTS.INT24_MAX;
136
- integer = isColumnType(column, ['MySqlMediumInt', 'SingleStoreMediumInt']);
137
- }
138
- else if (isColumnType(column, [
139
- 'PgInteger',
140
- 'PgSerial',
141
- 'MySqlInt',
142
- 'SingleStoreInt',
143
- ])) {
144
- min = unsigned ? 0 : CONSTANTS.INT32_MIN;
145
- max = unsigned ? CONSTANTS.INT32_UNSIGNED_MAX : CONSTANTS.INT32_MAX;
146
- integer = true;
147
- }
148
- else if (isColumnType(column, [
149
- 'PgDoublePrecision',
150
- 'MySqlReal',
151
- 'MySqlDouble',
152
- 'SingleStoreReal',
153
- 'SingleStoreDouble',
154
- 'SQLiteReal',
155
- ])) {
156
- min = unsigned ? 0 : CONSTANTS.INT48_MIN;
157
- max = unsigned ? CONSTANTS.INT48_UNSIGNED_MAX : CONSTANTS.INT48_MAX;
158
- }
159
- else if (isColumnType(column, [
160
- 'PgBigInt53',
161
- 'PgBigSerial53',
162
- 'MySqlBigInt53',
163
- 'MySqlSerial',
164
- 'SingleStoreBigInt53',
165
- 'SingleStoreSerial',
166
- 'SQLiteInteger',
167
- ])) {
168
- unsigned = unsigned || isColumnType(column, ['MySqlSerial', 'SingleStoreSerial']);
169
- min = unsigned ? 0 : Number.MIN_SAFE_INTEGER;
170
- max = Number.MAX_SAFE_INTEGER;
171
- integer = true;
172
- }
173
- else if (isColumnType(column, ['MySqlYear', 'SingleStoreYear'])) {
174
- min = 1901;
175
- max = 2155;
176
- integer = true;
177
- }
178
- else {
179
- min = Number.MIN_SAFE_INTEGER;
180
- max = Number.MAX_SAFE_INTEGER;
181
- }
182
- return (integer ? arktype.type.keywords.number.integer : arktype.type.number).atLeast(min).atMost(max);
208
+ function objectColumnToSchema(column, constraint) {
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
+ }
183
225
  }
184
226
  /** @internal */
185
- 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;
186
228
  /** @internal */
187
- const bigintNarrow = (v, ctx) => v < CONSTANTS.INT64_MIN ? ctx.mustBe('greater than') : v > CONSTANTS.INT64_MAX ? ctx.mustBe('less than') : true;
188
- function bigintColumnToSchema(column) {
189
- const unsigned = column.getSQLType().includes('unsigned');
190
- return arktype.type.bigint.narrow(unsigned ? unsignedBigintNarrow : bigintNarrow);
229
+ const bigintNarrow = (v, ctx) => v < CONSTANTS.INT64_MIN ? ctx.mustBe("greater than") : v > CONSTANTS.INT64_MAX ? ctx.mustBe("less than") : true;
230
+ /** @internal */
231
+ const bigintStringModeSchema = arktype.type.string.narrow((v, ctx) => {
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;
238
+ });
239
+ /** @internal */
240
+ const unsignedBigintStringModeSchema = arktype.type.string.narrow((v, ctx) => {
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;
247
+ });
248
+ function bigintColumnToSchema(column, constraint) {
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;
254
+ }
255
+ function stringColumnToSchema(column, constraint) {
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;
191
267
  }
192
- function stringColumnToSchema(column) {
193
- if (isColumnType(column, ['PgUUID'])) {
194
- return arktype.type(/^[\da-f]{8}(?:-[\da-f]{4}){3}-[\da-f]{12}$/iu).describe('a RFC-4122-compliant UUID');
195
- }
196
- if (isColumnType(column, ['PgBinaryVector'])) {
197
- return arktype.type(`/^[01]{${column.dimensions}}$/`)
198
- .describe(`a string containing ones or zeros while being ${column.dimensions} characters long`);
199
- }
200
- let max;
201
- let fixed = false;
202
- if (isColumnType(column, ['PgVarchar', 'SQLiteText'])) {
203
- max = column.length;
204
- }
205
- else if (isColumnType(column, ['MySqlVarChar', 'SingleStoreVarChar'])) {
206
- max = column.length ?? CONSTANTS.INT16_UNSIGNED_MAX;
207
- }
208
- else if (isColumnType(column, ['MySqlText', 'SingleStoreText'])) {
209
- if (column.textType === 'longtext') {
210
- max = CONSTANTS.INT32_UNSIGNED_MAX;
211
- }
212
- else if (column.textType === 'mediumtext') {
213
- max = CONSTANTS.INT24_UNSIGNED_MAX;
214
- }
215
- else if (column.textType === 'text') {
216
- max = CONSTANTS.INT16_UNSIGNED_MAX;
217
- }
218
- else {
219
- max = CONSTANTS.INT8_UNSIGNED_MAX;
220
- }
221
- }
222
- if (isColumnType(column, [
223
- 'PgChar',
224
- 'MySqlChar',
225
- 'SingleStoreChar',
226
- ])) {
227
- max = column.length;
228
- fixed = true;
229
- }
230
- return max && fixed ? arktype.type.string.exactlyLength(max) : max ? arktype.type.string.atMostLength(max) : arktype.type.string;
268
+
269
+ //#endregion
270
+ //#region src/utils.ts
271
+ function isColumnType(column, columnTypes) {
272
+ return columnTypes.includes(column.columnType);
231
273
  }
274
+ function isWithEnum(column) {
275
+ return "enumValues" in column && Array.isArray(column.enumValues) && column.enumValues.length > 0;
276
+ }
277
+ const isPgEnum = isWithEnum;
232
278
 
279
+ //#endregion
280
+ //#region src/schema.ts
233
281
  function getColumns(tableLike) {
234
- 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);
235
283
  }
236
284
  function handleColumns(columns, refinements, conditions) {
237
- const columnSchemas = {};
238
- for (const [key, selected] of Object.entries(columns)) {
239
- if (!drizzleOrm.is(selected, drizzleOrm.Column) && !drizzleOrm.is(selected, drizzleOrm.SQL) && !drizzleOrm.is(selected, drizzleOrm.SQL.Aliased) && typeof selected === 'object') {
240
- const columns = drizzleOrm.isTable(selected) || drizzleOrm.isView(selected) ? getColumns(selected) : selected;
241
- columnSchemas[key] = handleColumns(columns, refinements[key] ?? {}, conditions);
242
- continue;
243
- }
244
- const refinement = refinements[key];
245
- if (refinement !== undefined
246
- && (typeof refinement !== 'function' || (typeof refinement === 'function' && refinement.expression !== undefined))) {
247
- columnSchemas[key] = refinement;
248
- continue;
249
- }
250
- const column = drizzleOrm.is(selected, drizzleOrm.Column) ? selected : undefined;
251
- const schema = column ? columnToSchema(column) : arktype.type.unknown;
252
- const refined = typeof refinement === 'function' ? refinement(schema) : schema;
253
- if (conditions.never(column)) {
254
- continue;
255
- }
256
- else {
257
- columnSchemas[key] = refined;
258
- }
259
- if (column) {
260
- if (conditions.nullable(column)) {
261
- columnSchemas[key] = columnSchemas[key].or(arktype.type.null);
262
- }
263
- if (conditions.optional(column)) {
264
- columnSchemas[key] = columnSchemas[key].optional();
265
- }
266
- }
267
- }
268
- 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);
269
307
  }
270
308
  const createSelectSchema = ((entity, refine) => {
271
- if (isPgEnum(entity)) {
272
- return arktype.type.enumerated(...entity.enumValues);
273
- }
274
- const columns = getColumns(entity);
275
- return handleColumns(columns, refine ?? {}, {
276
- never: () => false,
277
- optional: () => false,
278
- nullable: (column) => !column.notNull,
279
- });
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
+ });
280
315
  });
281
316
  const createInsertSchema = ((entity, refine) => {
282
- const columns = getColumns(entity);
283
- return handleColumns(columns, refine ?? {}, {
284
- never: (column) => column?.generated?.type === 'always' || column?.generatedIdentity?.type === 'always',
285
- optional: (column) => !column.notNull || (column.notNull && column.hasDefault),
286
- nullable: (column) => !column.notNull,
287
- });
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
+ });
288
322
  });
289
323
  const createUpdateSchema = ((entity, refine) => {
290
- const columns = getColumns(entity);
291
- return handleColumns(columns, refine ?? {}, {
292
- never: (column) => column?.generated?.type === 'always' || column?.generatedIdentity?.type === 'always',
293
- optional: () => true,
294
- nullable: (column) => !column.notNull,
295
- });
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
+ });
296
329
  });
297
330
 
331
+ //#endregion
298
332
  exports.bufferSchema = bufferSchema;
299
333
  exports.createInsertSchema = createInsertSchema;
300
334
  exports.createSelectSchema = createSelectSchema;
@@ -304,4 +338,4 @@ exports.isPgEnum = isPgEnum;
304
338
  exports.isWithEnum = isWithEnum;
305
339
  exports.jsonSchema = jsonSchema;
306
340
  exports.literalSchema = literalSchema;
307
- //# sourceMappingURL=index.cjs.map
341
+ //# sourceMappingURL=index.cjs.map