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.d.ts +188 -242
- package/dist/index.js +319 -429
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +318 -427
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -6
package/dist/index.mjs
CHANGED
|
@@ -1,470 +1,361 @@
|
|
|
1
|
-
import { ArrayColumn,
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
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
|
-
|
|
189
|
-
}
|
|
127
|
+
var SmallIntColumnValibot = class extends SmallIntColumn {};
|
|
190
128
|
Object.assign(SmallIntColumnValibot.prototype, numberMethods);
|
|
191
|
-
|
|
192
|
-
}
|
|
129
|
+
var IntegerColumnValibot = class extends IntegerColumn {};
|
|
193
130
|
Object.assign(IntegerColumnValibot.prototype, numberMethods);
|
|
194
|
-
|
|
195
|
-
}
|
|
131
|
+
var RealColumnValibot = class extends RealColumn {};
|
|
196
132
|
Object.assign(RealColumnValibot.prototype, numberMethods);
|
|
197
|
-
|
|
198
|
-
}
|
|
133
|
+
var SmallSerialColumnValibot = class extends SmallSerialColumn {};
|
|
199
134
|
Object.assign(SmallSerialColumnValibot.prototype, numberMethods);
|
|
200
|
-
|
|
201
|
-
}
|
|
135
|
+
var SerialColumnValibot = class extends SerialColumn {};
|
|
202
136
|
Object.assign(SerialColumnValibot.prototype, numberMethods);
|
|
203
137
|
const stringMethods = {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
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
|
-
|
|
255
|
-
}
|
|
188
|
+
var BigIntColumnValibot = class extends BigIntColumn {};
|
|
256
189
|
Object.assign(BigIntColumnValibot.prototype, stringMethods);
|
|
257
|
-
|
|
258
|
-
}
|
|
190
|
+
var DecimalColumnValibot = class extends DecimalColumn {};
|
|
259
191
|
Object.assign(DecimalColumnValibot.prototype, stringMethods);
|
|
260
|
-
|
|
261
|
-
}
|
|
192
|
+
var DoublePrecisionColumnValibot = class extends DoublePrecisionColumn {};
|
|
262
193
|
Object.assign(DoublePrecisionColumnValibot.prototype, stringMethods);
|
|
263
|
-
|
|
264
|
-
}
|
|
194
|
+
var BigSerialColumnValibot = class extends BigSerialColumn {};
|
|
265
195
|
Object.assign(BigSerialColumnValibot.prototype, stringMethods);
|
|
266
|
-
|
|
267
|
-
}
|
|
196
|
+
var MoneyColumnValibot = class extends MoneyColumn {};
|
|
268
197
|
Object.assign(MoneyColumnValibot.prototype, numberMethods);
|
|
269
|
-
|
|
270
|
-
}
|
|
198
|
+
var VarCharColumnValibot = class extends VarCharColumn {};
|
|
271
199
|
Object.assign(VarCharColumnValibot.prototype, stringMethods);
|
|
272
|
-
|
|
273
|
-
}
|
|
200
|
+
var TextColumnValibot = class extends TextColumn {};
|
|
274
201
|
Object.assign(TextColumnValibot.prototype, stringMethods);
|
|
275
|
-
|
|
276
|
-
}
|
|
202
|
+
var StringColumnValibot = class extends StringColumn {};
|
|
277
203
|
Object.assign(StringColumnValibot.prototype, stringMethods);
|
|
278
|
-
|
|
279
|
-
}
|
|
204
|
+
var CitextColumnValibot = class extends CitextColumn {};
|
|
280
205
|
Object.assign(CitextColumnValibot.prototype, stringMethods);
|
|
281
206
|
const dateMethods = {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
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
|
-
|
|
290
|
-
}
|
|
214
|
+
var DateColumnValibot = class extends DateColumn {};
|
|
291
215
|
Object.assign(DateColumnValibot.prototype, dateMethods);
|
|
292
|
-
|
|
293
|
-
}
|
|
216
|
+
var TimestampNoTzColumnValibot = class extends TimestampColumn {};
|
|
294
217
|
Object.assign(TimestampNoTzColumnValibot.prototype, dateMethods);
|
|
295
|
-
|
|
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
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
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
|
-
|
|
360
|
+
|
|
361
|
+
//# sourceMappingURL=index.mjs.map
|