orchid-orm-valibot 0.3.126 → 0.3.127
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.js
CHANGED
|
@@ -1,475 +1,365 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
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
|
-
|
|
162
|
-
|
|
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
|
-
|
|
191
|
-
}
|
|
128
|
+
var SmallIntColumnValibot = class extends pqb_internal.SmallIntColumn {};
|
|
192
129
|
Object.assign(SmallIntColumnValibot.prototype, numberMethods);
|
|
193
|
-
|
|
194
|
-
}
|
|
130
|
+
var IntegerColumnValibot = class extends pqb_internal.IntegerColumn {};
|
|
195
131
|
Object.assign(IntegerColumnValibot.prototype, numberMethods);
|
|
196
|
-
|
|
197
|
-
}
|
|
132
|
+
var RealColumnValibot = class extends pqb_internal.RealColumn {};
|
|
198
133
|
Object.assign(RealColumnValibot.prototype, numberMethods);
|
|
199
|
-
|
|
200
|
-
}
|
|
134
|
+
var SmallSerialColumnValibot = class extends pqb_internal.SmallSerialColumn {};
|
|
201
135
|
Object.assign(SmallSerialColumnValibot.prototype, numberMethods);
|
|
202
|
-
|
|
203
|
-
}
|
|
136
|
+
var SerialColumnValibot = class extends pqb_internal.SerialColumn {};
|
|
204
137
|
Object.assign(SerialColumnValibot.prototype, numberMethods);
|
|
205
138
|
const stringMethods = {
|
|
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
|
-
|
|
253
|
-
|
|
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
|
-
|
|
257
|
-
}
|
|
189
|
+
var BigIntColumnValibot = class extends pqb_internal.BigIntColumn {};
|
|
258
190
|
Object.assign(BigIntColumnValibot.prototype, stringMethods);
|
|
259
|
-
|
|
260
|
-
}
|
|
191
|
+
var DecimalColumnValibot = class extends pqb_internal.DecimalColumn {};
|
|
261
192
|
Object.assign(DecimalColumnValibot.prototype, stringMethods);
|
|
262
|
-
|
|
263
|
-
}
|
|
193
|
+
var DoublePrecisionColumnValibot = class extends pqb_internal.DoublePrecisionColumn {};
|
|
264
194
|
Object.assign(DoublePrecisionColumnValibot.prototype, stringMethods);
|
|
265
|
-
|
|
266
|
-
}
|
|
195
|
+
var BigSerialColumnValibot = class extends pqb_internal.BigSerialColumn {};
|
|
267
196
|
Object.assign(BigSerialColumnValibot.prototype, stringMethods);
|
|
268
|
-
|
|
269
|
-
}
|
|
197
|
+
var MoneyColumnValibot = class extends pqb_internal.MoneyColumn {};
|
|
270
198
|
Object.assign(MoneyColumnValibot.prototype, numberMethods);
|
|
271
|
-
|
|
272
|
-
}
|
|
199
|
+
var VarCharColumnValibot = class extends pqb_internal.VarCharColumn {};
|
|
273
200
|
Object.assign(VarCharColumnValibot.prototype, stringMethods);
|
|
274
|
-
|
|
275
|
-
}
|
|
201
|
+
var TextColumnValibot = class extends pqb_internal.TextColumn {};
|
|
276
202
|
Object.assign(TextColumnValibot.prototype, stringMethods);
|
|
277
|
-
|
|
278
|
-
}
|
|
203
|
+
var StringColumnValibot = class extends pqb_internal.StringColumn {};
|
|
279
204
|
Object.assign(StringColumnValibot.prototype, stringMethods);
|
|
280
|
-
|
|
281
|
-
}
|
|
205
|
+
var CitextColumnValibot = class extends pqb_internal.CitextColumn {};
|
|
282
206
|
Object.assign(CitextColumnValibot.prototype, stringMethods);
|
|
283
207
|
const dateMethods = {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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
|
-
|
|
292
|
-
}
|
|
215
|
+
var DateColumnValibot = class extends pqb_internal.DateColumn {};
|
|
293
216
|
Object.assign(DateColumnValibot.prototype, dateMethods);
|
|
294
|
-
|
|
295
|
-
}
|
|
217
|
+
var TimestampNoTzColumnValibot = class extends pqb_internal.TimestampColumn {};
|
|
296
218
|
Object.assign(TimestampNoTzColumnValibot.prototype, dateMethods);
|
|
297
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
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
|
-
|
|
364
|
+
|
|
365
|
+
//# sourceMappingURL=index.js.map
|