orchid-orm-valibot 0.3.126 → 0.3.128

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/dist/index.mjs CHANGED
@@ -1,470 +1,361 @@
1
- import { ArrayColumn, SmallIntColumn, IntegerColumn, RealColumn, SmallSerialColumn, SerialColumn, BigIntColumn, DecimalColumn, DoublePrecisionColumn, BigSerialColumn, MoneyColumn, VarCharColumn, TextColumn, StringColumn, CitextColumn, DateColumn, TimestampColumn, TimestampTZColumn, makeColumnNullable, EnumColumn, setColumnEncode, setColumnParseNull, setColumnParse, setDataValue, JSONColumn } from 'pqb/internal';
2
- import { array, minValue, object, number, optional, required, pick, partial, string, uuid, maxLength, regex, coerce, date, integer, minLength, never, unknown, instance, boolean, nullable, union, picklist, length, actionOutput, actionIssue, stringify, maxValue, finite, toUpperCase, toLowerCase, toTrimmed, ipv6, ipv4, isoDateTime, endsWith, startsWith, includes, ulid, cuid2, emoji, url, email } from 'valibot';
3
-
4
- class ValibotJSONColumn extends JSONColumn {
5
- constructor(schema) {
6
- super(valibotSchemaConfig, schema);
7
- }
8
- }
1
+ import { ArrayColumn, BigIntColumn, BigSerialColumn, CitextColumn, DateColumn, DecimalColumn, DoublePrecisionColumn, EnumColumn, IntegerColumn, JSONColumn, MoneyColumn, RealColumn, SerialColumn, SmallIntColumn, SmallSerialColumn, StringColumn, TextColumn, TimestampColumn, TimestampTZColumn, VarCharColumn, makeColumnNullable, setColumnEncode, setColumnParse, setColumnParseNull, setDataValue } from "pqb/internal";
2
+ import { actionIssue, actionOutput, array, boolean, coerce, cuid2, date, email, emoji, endsWith, finite, includes, instance, integer, ipv4, ipv6, isoDateTime, length, maxLength, maxValue, minLength, minValue, never, nullable, number, object, optional, partial, pick, picklist, regex, required, startsWith, string, stringify, toLowerCase, toTrimmed, toUpperCase, ulid, union, unknown, url, uuid } from "valibot";
3
+ var ValibotJSONColumn = class extends JSONColumn {
4
+ constructor(schema) {
5
+ super(valibotSchemaConfig, schema);
6
+ }
7
+ };
9
8
  function applyMethod(column, key, value, validation, params) {
10
- const cloned = setDataValue(
11
- column,
12
- key,
13
- value,
14
- params
15
- );
16
- const v = validation(
17
- value,
18
- typeof params === "object" ? params.message : params
19
- );
20
- cloned.inputSchema.pipe.push(v);
21
- cloned.outputSchema.pipe.push(v);
22
- cloned.querySchema.pipe.push(v);
23
- return cloned;
9
+ const cloned = setDataValue(column, key, value, params);
10
+ const v = validation(value, typeof params === "object" ? params.message : params);
11
+ cloned.inputSchema.pipe.push(v);
12
+ cloned.outputSchema.pipe.push(v);
13
+ cloned.querySchema.pipe.push(v);
14
+ return cloned;
24
15
  }
25
16
  function applySimpleMethod(column, key, validation, params, ...args) {
26
- const cloned = setDataValue(
27
- column,
28
- key,
29
- true,
30
- params
31
- );
32
- const v = validation(
33
- ...args,
34
- typeof params === "object" ? params.message : params
35
- );
36
- cloned.inputSchema.pipe.push(v);
37
- cloned.outputSchema.pipe.push(v);
38
- cloned.querySchema.pipe.push(v);
39
- return cloned;
17
+ const cloned = setDataValue(column, key, true, params);
18
+ const v = validation(...args, typeof params === "object" ? params.message : params);
19
+ cloned.inputSchema.pipe.push(v);
20
+ cloned.outputSchema.pipe.push(v);
21
+ cloned.querySchema.pipe.push(v);
22
+ return cloned;
40
23
  }
41
24
  const arrayMethods = {
42
- min(value, params) {
43
- return applyMethod(this, "min", value, minLength, params);
44
- },
45
- max(value, params) {
46
- return applyMethod(this, "max", value, maxLength, params);
47
- },
48
- length(value, params) {
49
- return applyMethod(this, "length", value, length, params);
50
- },
51
- nonEmpty(params) {
52
- return applyMethod(this, "min", 1, minLength, params);
53
- }
25
+ min(value, params) {
26
+ return applyMethod(this, "min", value, minLength, params);
27
+ },
28
+ max(value, params) {
29
+ return applyMethod(this, "max", value, maxLength, params);
30
+ },
31
+ length(value, params) {
32
+ return applyMethod(this, "length", value, length, params);
33
+ },
34
+ nonEmpty(params) {
35
+ return applyMethod(this, "min", 1, minLength, params);
36
+ }
37
+ };
38
+ var ValibotArrayColumn = class extends ArrayColumn {
39
+ constructor(item) {
40
+ super(valibotSchemaConfig, item, array(item.inputSchema, []));
41
+ }
54
42
  };
55
- class ValibotArrayColumn extends ArrayColumn {
56
- constructor(item) {
57
- super(valibotSchemaConfig, item, array(item.inputSchema, []));
58
- }
59
- }
60
43
  Object.assign(ValibotArrayColumn.prototype, arrayMethods);
61
44
  function gt(requirement, message) {
62
- return {
63
- type: "gt",
64
- expects: `>${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`,
65
- async: false,
66
- message,
67
- requirement,
68
- _parse(input) {
69
- if (input > this.requirement) {
70
- return actionOutput(input);
71
- }
72
- return actionIssue(
73
- this,
74
- gt,
75
- input,
76
- "value",
77
- input instanceof Date ? input.toJSON() : stringify(input)
78
- );
79
- }
80
- };
45
+ return {
46
+ type: "gt",
47
+ expects: `>${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`,
48
+ async: false,
49
+ message,
50
+ requirement,
51
+ _parse(input) {
52
+ if (input > this.requirement) return actionOutput(input);
53
+ return actionIssue(this, gt, input, "value", input instanceof Date ? input.toJSON() : stringify(input));
54
+ }
55
+ };
81
56
  }
82
57
  function lt(requirement, message) {
83
- return {
84
- type: "lt",
85
- expects: `<${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`,
86
- async: false,
87
- message,
88
- requirement,
89
- _parse(input) {
90
- if (input < this.requirement) {
91
- return actionOutput(input);
92
- }
93
- return actionIssue(
94
- this,
95
- lt,
96
- input,
97
- "value",
98
- input instanceof Date ? input.toJSON() : stringify(input)
99
- );
100
- }
101
- };
58
+ return {
59
+ type: "lt",
60
+ expects: `<${requirement instanceof Date ? requirement.toJSON() : stringify(requirement)}`,
61
+ async: false,
62
+ message,
63
+ requirement,
64
+ _parse(input) {
65
+ if (input < this.requirement) return actionOutput(input);
66
+ return actionIssue(this, lt, input, "value", input instanceof Date ? input.toJSON() : stringify(input));
67
+ }
68
+ };
102
69
  }
103
70
  function step(requirement, message) {
104
- return {
105
- type: "step",
106
- expects: `a multiple of ${stringify(requirement)}`,
107
- async: false,
108
- message,
109
- requirement,
110
- _parse(input) {
111
- if (input % this.requirement === 0) {
112
- return actionOutput(input);
113
- }
114
- return actionIssue(this, step, input, "value", stringify(input));
115
- }
116
- };
71
+ return {
72
+ type: "step",
73
+ expects: `a multiple of ${stringify(requirement)}`,
74
+ async: false,
75
+ message,
76
+ requirement,
77
+ _parse(input) {
78
+ if (input % this.requirement === 0) return actionOutput(input);
79
+ return actionIssue(this, step, input, "value", stringify(input));
80
+ }
81
+ };
117
82
  }
118
83
  const numberMethods = {
119
- // Require a value to be lower than a given number
120
- lt(value, params) {
121
- return applyMethod(this, "lt", value, lt, params);
122
- },
123
- // Require a value to be lower than or equal to a given number (the same as `max`)
124
- lte(value, params) {
125
- return applyMethod(this, "lte", value, maxValue, params);
126
- },
127
- // Require a value to be lower than or equal to a given number
128
- max(value, params) {
129
- return applyMethod(this, "lte", value, maxValue, params);
130
- },
131
- // Require a value to be greater than a given number
132
- gt(value, params) {
133
- return applyMethod(this, "gt", value, gt, params);
134
- },
135
- // Require a value to be greater than or equal to a given number (the same as `min`)
136
- gte(value, params) {
137
- return applyMethod(this, "gte", value, minValue, params);
138
- },
139
- // Require a value to be greater than or equal to a given number
140
- min(value, params) {
141
- return applyMethod(this, "gte", value, minValue, params);
142
- },
143
- // Require a value to be greater than 0
144
- positive(params) {
145
- return applyMethod(this, "gt", 0, gt, params);
146
- },
147
- // Require a value to be greater than or equal to 0
148
- nonNegative(params) {
149
- return applyMethod(this, "gte", 0, minValue, params);
150
- },
151
- // Require a value to be lower than 0
152
- negative(params) {
153
- return applyMethod(this, "lt", 0, lt, params);
154
- },
155
- // Require a value to be lower than or equal to 0
156
- nonPositive(params) {
157
- return applyMethod(this, "lte", 0, maxValue, params);
158
- },
159
- // Require a value to be a multiple of a given number
160
- step(value, params) {
161
- return applyMethod(this, "step", value, step, params);
162
- },
163
- // Require a value to be an integer
164
- int(params) {
165
- return applySimpleMethod(this, "int", integer, params);
166
- },
167
- // Exclude `Infinity` from being a valid value
168
- finite(params) {
169
- return applySimpleMethod(this, "finite", finite, params);
170
- },
171
- // Require the value to be less than or equal to Number.MAX_SAFE_INTEGER
172
- safe(params) {
173
- return applySimpleMethod(
174
- applySimpleMethod(
175
- this,
176
- "safe",
177
- minValue,
178
- params,
179
- Number.MIN_SAFE_INTEGER
180
- ),
181
- "safe",
182
- maxValue,
183
- params,
184
- Number.MAX_SAFE_INTEGER
185
- );
186
- }
84
+ lt(value, params) {
85
+ return applyMethod(this, "lt", value, lt, params);
86
+ },
87
+ lte(value, params) {
88
+ return applyMethod(this, "lte", value, maxValue, params);
89
+ },
90
+ max(value, params) {
91
+ return applyMethod(this, "lte", value, maxValue, params);
92
+ },
93
+ gt(value, params) {
94
+ return applyMethod(this, "gt", value, gt, params);
95
+ },
96
+ gte(value, params) {
97
+ return applyMethod(this, "gte", value, minValue, params);
98
+ },
99
+ min(value, params) {
100
+ return applyMethod(this, "gte", value, minValue, params);
101
+ },
102
+ positive(params) {
103
+ return applyMethod(this, "gt", 0, gt, params);
104
+ },
105
+ nonNegative(params) {
106
+ return applyMethod(this, "gte", 0, minValue, params);
107
+ },
108
+ negative(params) {
109
+ return applyMethod(this, "lt", 0, lt, params);
110
+ },
111
+ nonPositive(params) {
112
+ return applyMethod(this, "lte", 0, maxValue, params);
113
+ },
114
+ step(value, params) {
115
+ return applyMethod(this, "step", value, step, params);
116
+ },
117
+ int(params) {
118
+ return applySimpleMethod(this, "int", integer, params);
119
+ },
120
+ finite(params) {
121
+ return applySimpleMethod(this, "finite", finite, params);
122
+ },
123
+ safe(params) {
124
+ return applySimpleMethod(applySimpleMethod(this, "safe", minValue, params, Number.MIN_SAFE_INTEGER), "safe", maxValue, params, Number.MAX_SAFE_INTEGER);
125
+ }
187
126
  };
188
- class SmallIntColumnValibot extends SmallIntColumn {
189
- }
127
+ var SmallIntColumnValibot = class extends SmallIntColumn {};
190
128
  Object.assign(SmallIntColumnValibot.prototype, numberMethods);
191
- class IntegerColumnValibot extends IntegerColumn {
192
- }
129
+ var IntegerColumnValibot = class extends IntegerColumn {};
193
130
  Object.assign(IntegerColumnValibot.prototype, numberMethods);
194
- class RealColumnValibot extends RealColumn {
195
- }
131
+ var RealColumnValibot = class extends RealColumn {};
196
132
  Object.assign(RealColumnValibot.prototype, numberMethods);
197
- class SmallSerialColumnValibot extends SmallSerialColumn {
198
- }
133
+ var SmallSerialColumnValibot = class extends SmallSerialColumn {};
199
134
  Object.assign(SmallSerialColumnValibot.prototype, numberMethods);
200
- class SerialColumnValibot extends SerialColumn {
201
- }
135
+ var SerialColumnValibot = class extends SerialColumn {};
202
136
  Object.assign(SerialColumnValibot.prototype, numberMethods);
203
137
  const stringMethods = {
204
- ...arrayMethods,
205
- email(params) {
206
- return applySimpleMethod(this, "email", email, params);
207
- },
208
- url(params) {
209
- return applySimpleMethod(this, "url", url, params);
210
- },
211
- emoji(params) {
212
- return applySimpleMethod(this, "emoji", emoji, params);
213
- },
214
- uuid(params) {
215
- return applySimpleMethod(this, "uuid", uuid, params);
216
- },
217
- cuid2(params) {
218
- return applySimpleMethod(this, "cuid2", cuid2, params);
219
- },
220
- ulid(params) {
221
- return applySimpleMethod(this, "ulid", ulid, params);
222
- },
223
- regex(value, params) {
224
- return applyMethod(this, "regex", value, regex, params);
225
- },
226
- includes(value, params) {
227
- return applyMethod(this, "includes", value, includes, params);
228
- },
229
- startsWith(value, params) {
230
- return applyMethod(this, "startsWith", value, startsWith, params);
231
- },
232
- endsWith(value, params) {
233
- return applyMethod(this, "endsWith", value, endsWith, params);
234
- },
235
- datetime(params) {
236
- return applySimpleMethod(this, "datetime", isoDateTime, params);
237
- },
238
- ipv4(params = {}) {
239
- return applySimpleMethod(this, "ipv4", ipv4, params);
240
- },
241
- ipv6(params = {}) {
242
- return applySimpleMethod(this, "ipv6", ipv6, params);
243
- },
244
- trim(params) {
245
- return applySimpleMethod(this, "trim", toTrimmed, params);
246
- },
247
- toLowerCase(params) {
248
- return applySimpleMethod(this, "toLowerCase", toLowerCase, params);
249
- },
250
- toUpperCase(params) {
251
- return applySimpleMethod(this, "toUpperCase", toUpperCase, params);
252
- }
138
+ ...arrayMethods,
139
+ email(params) {
140
+ return applySimpleMethod(this, "email", email, params);
141
+ },
142
+ url(params) {
143
+ return applySimpleMethod(this, "url", url, params);
144
+ },
145
+ emoji(params) {
146
+ return applySimpleMethod(this, "emoji", emoji, params);
147
+ },
148
+ uuid(params) {
149
+ return applySimpleMethod(this, "uuid", uuid, params);
150
+ },
151
+ cuid2(params) {
152
+ return applySimpleMethod(this, "cuid2", cuid2, params);
153
+ },
154
+ ulid(params) {
155
+ return applySimpleMethod(this, "ulid", ulid, params);
156
+ },
157
+ regex(value, params) {
158
+ return applyMethod(this, "regex", value, regex, params);
159
+ },
160
+ includes(value, params) {
161
+ return applyMethod(this, "includes", value, includes, params);
162
+ },
163
+ startsWith(value, params) {
164
+ return applyMethod(this, "startsWith", value, startsWith, params);
165
+ },
166
+ endsWith(value, params) {
167
+ return applyMethod(this, "endsWith", value, endsWith, params);
168
+ },
169
+ datetime(params) {
170
+ return applySimpleMethod(this, "datetime", isoDateTime, params);
171
+ },
172
+ ipv4(params = {}) {
173
+ return applySimpleMethod(this, "ipv4", ipv4, params);
174
+ },
175
+ ipv6(params = {}) {
176
+ return applySimpleMethod(this, "ipv6", ipv6, params);
177
+ },
178
+ trim(params) {
179
+ return applySimpleMethod(this, "trim", toTrimmed, params);
180
+ },
181
+ toLowerCase(params) {
182
+ return applySimpleMethod(this, "toLowerCase", toLowerCase, params);
183
+ },
184
+ toUpperCase(params) {
185
+ return applySimpleMethod(this, "toUpperCase", toUpperCase, params);
186
+ }
253
187
  };
254
- class BigIntColumnValibot extends BigIntColumn {
255
- }
188
+ var BigIntColumnValibot = class extends BigIntColumn {};
256
189
  Object.assign(BigIntColumnValibot.prototype, stringMethods);
257
- class DecimalColumnValibot extends DecimalColumn {
258
- }
190
+ var DecimalColumnValibot = class extends DecimalColumn {};
259
191
  Object.assign(DecimalColumnValibot.prototype, stringMethods);
260
- class DoublePrecisionColumnValibot extends DoublePrecisionColumn {
261
- }
192
+ var DoublePrecisionColumnValibot = class extends DoublePrecisionColumn {};
262
193
  Object.assign(DoublePrecisionColumnValibot.prototype, stringMethods);
263
- class BigSerialColumnValibot extends BigSerialColumn {
264
- }
194
+ var BigSerialColumnValibot = class extends BigSerialColumn {};
265
195
  Object.assign(BigSerialColumnValibot.prototype, stringMethods);
266
- class MoneyColumnValibot extends MoneyColumn {
267
- }
196
+ var MoneyColumnValibot = class extends MoneyColumn {};
268
197
  Object.assign(MoneyColumnValibot.prototype, numberMethods);
269
- class VarCharColumnValibot extends VarCharColumn {
270
- }
198
+ var VarCharColumnValibot = class extends VarCharColumn {};
271
199
  Object.assign(VarCharColumnValibot.prototype, stringMethods);
272
- class TextColumnValibot extends TextColumn {
273
- }
200
+ var TextColumnValibot = class extends TextColumn {};
274
201
  Object.assign(TextColumnValibot.prototype, stringMethods);
275
- class StringColumnValibot extends StringColumn {
276
- }
202
+ var StringColumnValibot = class extends StringColumn {};
277
203
  Object.assign(StringColumnValibot.prototype, stringMethods);
278
- class CitextColumnValibot extends CitextColumn {
279
- }
204
+ var CitextColumnValibot = class extends CitextColumn {};
280
205
  Object.assign(CitextColumnValibot.prototype, stringMethods);
281
206
  const dateMethods = {
282
- min(value, params) {
283
- return applyMethod(this, "min", value, minValue, params);
284
- },
285
- max(value, params) {
286
- return applyMethod(this, "max", value, maxValue, params);
287
- }
207
+ min(value, params) {
208
+ return applyMethod(this, "min", value, minValue, params);
209
+ },
210
+ max(value, params) {
211
+ return applyMethod(this, "max", value, maxValue, params);
212
+ }
288
213
  };
289
- class DateColumnValibot extends DateColumn {
290
- }
214
+ var DateColumnValibot = class extends DateColumn {};
291
215
  Object.assign(DateColumnValibot.prototype, dateMethods);
292
- class TimestampNoTzColumnValibot extends TimestampColumn {
293
- }
216
+ var TimestampNoTzColumnValibot = class extends TimestampColumn {};
294
217
  Object.assign(TimestampNoTzColumnValibot.prototype, dateMethods);
295
- class TimestampColumnValibot extends TimestampTZColumn {
296
- }
218
+ var TimestampColumnValibot = class extends TimestampTZColumn {};
297
219
  Object.assign(TimestampColumnValibot.prototype, dateMethods);
298
220
  let pointSchema;
299
221
  const parseDateToDate = (value) => new Date(value);
300
222
  const valibotSchemaConfig = {
301
- type: void 0,
302
- parse(schema, fn) {
303
- return setColumnParse(this, fn, schema);
304
- },
305
- parseNull(schema, fn) {
306
- return setColumnParseNull(this, fn, schema);
307
- },
308
- encode(schema, fn) {
309
- return setColumnEncode(this, fn, schema);
310
- },
311
- asType(_types) {
312
- return this;
313
- },
314
- narrowType(type) {
315
- const c = Object.create(this);
316
- if (c.data.generated) {
317
- c.outputSchema = c.querySchema = type;
318
- } else {
319
- c.inputSchema = c.outputSchema = c.querySchema = type;
320
- }
321
- return c;
322
- },
323
- narrowAllTypes(types) {
324
- const c = Object.create(this);
325
- if (types.input) {
326
- c.inputSchema = types.input;
327
- }
328
- if (types.output) {
329
- c.outputSchema = types.output;
330
- }
331
- if (types.query) {
332
- c.querySchema = types.query;
333
- }
334
- return c;
335
- },
336
- dateAsNumber() {
337
- return this.parse(number([]), Date.parse);
338
- },
339
- dateAsDate() {
340
- return this.parse(date([]), parseDateToDate);
341
- },
342
- enum(dataType, type) {
343
- return new EnumColumn(valibotSchemaConfig, dataType, type, picklist(type));
344
- },
345
- array(item) {
346
- return new ValibotArrayColumn(item);
347
- },
348
- nullable() {
349
- return makeColumnNullable(
350
- this,
351
- nullable(this.inputSchema),
352
- this.nullSchema ? union([this.outputSchema, this.nullSchema]) : nullable(this.outputSchema),
353
- nullable(this.querySchema)
354
- );
355
- },
356
- json(schema) {
357
- return new ValibotJSONColumn(schema ?? unknown([]));
358
- },
359
- boolean: () => boolean([]),
360
- buffer: () => instance(Buffer, []),
361
- unknown: () => unknown([]),
362
- never: () => never(),
363
- stringSchema: () => string([]),
364
- stringMin(min) {
365
- return string([minLength(min)]);
366
- },
367
- stringMax(max) {
368
- return string([maxLength(max)]);
369
- },
370
- stringMinMax(min, max) {
371
- return string([minLength(min), maxLength(max)]);
372
- },
373
- number: () => number([]),
374
- int: () => number([integer()]),
375
- stringNumberDate: () => coerce(date([]), (input) => new Date(input)),
376
- timeInterval: () => object(
377
- {
378
- years: optional(number()),
379
- months: optional(number()),
380
- days: optional(number()),
381
- hours: optional(number()),
382
- minutes: optional(number()),
383
- seconds: optional(number())
384
- },
385
- []
386
- ),
387
- bit: (max) => max ? string([maxLength(max), regex(/[10]/g)]) : string([regex(/[10]/g)]),
388
- uuid: () => string([uuid()]),
389
- inputSchema() {
390
- return mapSchema(this, "inputSchema");
391
- },
392
- outputSchema() {
393
- return mapSchema(this, "outputSchema");
394
- },
395
- querySchema() {
396
- return partial(mapSchema(this, "querySchema"));
397
- },
398
- createSchema() {
399
- const input = this.inputSchema();
400
- const shape = {};
401
- const { shape: columns } = this.prototype.columns;
402
- for (const key in columns) {
403
- const column = columns[key];
404
- if (column.dataType && !column.data.primaryKey) {
405
- shape[key] = input.entries[key];
406
- if (column.data.isNullable || column.data.default !== void 0) {
407
- shape[key] = optional(shape[key]);
408
- }
409
- }
410
- }
411
- return object(shape);
412
- },
413
- updateSchema() {
414
- return partial(this.createSchema());
415
- },
416
- pkeySchema() {
417
- const keys = [];
418
- const {
419
- columns: { shape }
420
- } = this.prototype;
421
- for (const key in shape) {
422
- if (shape[key].data.primaryKey) {
423
- keys.push(key);
424
- }
425
- }
426
- return required(
427
- pick(this.querySchema(), keys)
428
- );
429
- },
430
- error(message) {
431
- const c = this;
432
- c.inputSchema.message = c.outputSchema.message = c.querySchema.message = message;
433
- return c;
434
- },
435
- smallint: () => new SmallIntColumnValibot(valibotSchemaConfig),
436
- integer: () => new IntegerColumnValibot(valibotSchemaConfig),
437
- real: () => new RealColumnValibot(valibotSchemaConfig),
438
- smallSerial: () => new SmallSerialColumnValibot(valibotSchemaConfig),
439
- serial: () => new SerialColumnValibot(valibotSchemaConfig),
440
- bigint: () => new BigIntColumnValibot(valibotSchemaConfig),
441
- decimal: (precision, scale) => new DecimalColumnValibot(valibotSchemaConfig, precision, scale),
442
- doublePrecision: () => new DoublePrecisionColumnValibot(valibotSchemaConfig),
443
- bigSerial: () => new BigSerialColumnValibot(valibotSchemaConfig),
444
- money: () => new MoneyColumnValibot(valibotSchemaConfig),
445
- varchar: (limit) => new VarCharColumnValibot(valibotSchemaConfig, limit),
446
- text: () => new TextColumnValibot(valibotSchemaConfig),
447
- string: (limit) => new StringColumnValibot(valibotSchemaConfig, limit),
448
- citext: () => new CitextColumnValibot(valibotSchemaConfig),
449
- date: () => new DateColumnValibot(valibotSchemaConfig),
450
- timestampNoTZ: (precision) => new TimestampNoTzColumnValibot(valibotSchemaConfig, precision),
451
- timestamp: (precision) => new TimestampColumnValibot(valibotSchemaConfig, precision),
452
- geographyPointSchema: () => pointSchema ?? (pointSchema = object({
453
- srid: optional(number()),
454
- lon: number(),
455
- lat: number()
456
- }))
223
+ type: void 0,
224
+ parse(schema, fn) {
225
+ return setColumnParse(this, fn, schema);
226
+ },
227
+ parseNull(schema, fn) {
228
+ return setColumnParseNull(this, fn, schema);
229
+ },
230
+ encode(schema, fn) {
231
+ return setColumnEncode(this, fn, schema);
232
+ },
233
+ asType(_types) {
234
+ return this;
235
+ },
236
+ narrowType(type) {
237
+ const c = Object.create(this);
238
+ if (c.data.generated) c.outputSchema = c.querySchema = type;
239
+ else c.inputSchema = c.outputSchema = c.querySchema = type;
240
+ return c;
241
+ },
242
+ narrowAllTypes(types) {
243
+ const c = Object.create(this);
244
+ if (types.input) c.inputSchema = types.input;
245
+ if (types.output) c.outputSchema = types.output;
246
+ if (types.query) c.querySchema = types.query;
247
+ return c;
248
+ },
249
+ dateAsNumber() {
250
+ return this.parse(number([]), Date.parse);
251
+ },
252
+ dateAsDate() {
253
+ return this.parse(date([]), parseDateToDate);
254
+ },
255
+ enum(dataType, type) {
256
+ return new EnumColumn(valibotSchemaConfig, dataType, type, picklist(type));
257
+ },
258
+ array(item) {
259
+ return new ValibotArrayColumn(item);
260
+ },
261
+ nullable() {
262
+ return makeColumnNullable(this, nullable(this.inputSchema), this.nullSchema ? union([this.outputSchema, this.nullSchema]) : nullable(this.outputSchema), nullable(this.querySchema));
263
+ },
264
+ json(schema) {
265
+ return new ValibotJSONColumn(schema ?? unknown([]));
266
+ },
267
+ boolean: () => boolean([]),
268
+ buffer: () => instance(Buffer, []),
269
+ unknown: () => unknown([]),
270
+ never: () => never(),
271
+ stringSchema: () => string([]),
272
+ stringMin(min) {
273
+ return string([minLength(min)]);
274
+ },
275
+ stringMax(max) {
276
+ return string([maxLength(max)]);
277
+ },
278
+ stringMinMax(min, max) {
279
+ return string([minLength(min), maxLength(max)]);
280
+ },
281
+ number: () => number([]),
282
+ int: () => number([integer()]),
283
+ stringNumberDate: () => coerce(date([]), (input) => new Date(input)),
284
+ timeInterval: () => object({
285
+ years: optional(number()),
286
+ months: optional(number()),
287
+ days: optional(number()),
288
+ hours: optional(number()),
289
+ minutes: optional(number()),
290
+ seconds: optional(number())
291
+ }, []),
292
+ bit: (max) => max ? string([maxLength(max), regex(/[10]/g)]) : string([regex(/[10]/g)]),
293
+ uuid: () => string([uuid()]),
294
+ inputSchema() {
295
+ return mapSchema(this, "inputSchema");
296
+ },
297
+ outputSchema() {
298
+ return mapSchema(this, "outputSchema");
299
+ },
300
+ querySchema() {
301
+ return partial(mapSchema(this, "querySchema"));
302
+ },
303
+ createSchema() {
304
+ const input = this.inputSchema();
305
+ const shape = {};
306
+ const { shape: columns } = this.prototype.columns;
307
+ for (const key in columns) {
308
+ const column = columns[key];
309
+ if (column.dataType && !column.data.primaryKey) {
310
+ shape[key] = input.entries[key];
311
+ if (column.data.isNullable || column.data.default !== void 0) shape[key] = optional(shape[key]);
312
+ }
313
+ }
314
+ return object(shape);
315
+ },
316
+ updateSchema() {
317
+ return partial(this.createSchema());
318
+ },
319
+ pkeySchema() {
320
+ const keys = [];
321
+ const { columns: { shape } } = this.prototype;
322
+ for (const key in shape) if (shape[key].data.primaryKey) keys.push(key);
323
+ return required(pick(this.querySchema(), keys));
324
+ },
325
+ error(message) {
326
+ const c = this;
327
+ c.inputSchema.message = c.outputSchema.message = c.querySchema.message = message;
328
+ return c;
329
+ },
330
+ smallint: () => new SmallIntColumnValibot(valibotSchemaConfig),
331
+ integer: () => new IntegerColumnValibot(valibotSchemaConfig),
332
+ real: () => new RealColumnValibot(valibotSchemaConfig),
333
+ smallSerial: () => new SmallSerialColumnValibot(valibotSchemaConfig),
334
+ serial: () => new SerialColumnValibot(valibotSchemaConfig),
335
+ bigint: () => new BigIntColumnValibot(valibotSchemaConfig),
336
+ decimal: (precision, scale) => new DecimalColumnValibot(valibotSchemaConfig, precision, scale),
337
+ doublePrecision: () => new DoublePrecisionColumnValibot(valibotSchemaConfig),
338
+ bigSerial: () => new BigSerialColumnValibot(valibotSchemaConfig),
339
+ money: () => new MoneyColumnValibot(valibotSchemaConfig),
340
+ varchar: (limit) => new VarCharColumnValibot(valibotSchemaConfig, limit),
341
+ text: () => new TextColumnValibot(valibotSchemaConfig),
342
+ string: (limit) => new StringColumnValibot(valibotSchemaConfig, limit),
343
+ citext: () => new CitextColumnValibot(valibotSchemaConfig),
344
+ date: () => new DateColumnValibot(valibotSchemaConfig),
345
+ timestampNoTZ: (precision) => new TimestampNoTzColumnValibot(valibotSchemaConfig, precision),
346
+ timestamp: (precision) => new TimestampColumnValibot(valibotSchemaConfig, precision),
347
+ geographyPointSchema: () => pointSchema ??= object({
348
+ srid: optional(number()),
349
+ lon: number(),
350
+ lat: number()
351
+ })
457
352
  };
458
353
  function mapSchema(klass, schemaKey) {
459
- const shape = {};
460
- const { shape: columns } = klass.prototype.columns;
461
- for (const key in columns) {
462
- if (columns[key].dataType) {
463
- shape[key] = columns[key][schemaKey];
464
- }
465
- }
466
- return object(shape);
354
+ const shape = {};
355
+ const { shape: columns } = klass.prototype.columns;
356
+ for (const key in columns) if (columns[key].dataType) shape[key] = columns[key][schemaKey];
357
+ return object(shape);
467
358
  }
468
-
469
359
  export { gt, lt, step, valibotSchemaConfig };
470
- //# sourceMappingURL=index.mjs.map
360
+
361
+ //# sourceMappingURL=index.mjs.map