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