@coursebuilder/adapter-drizzle 2.0.1-canary.cd34f124e → 2.1.1
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/{chunk-WPDVDHLH.js → chunk-2AW5KYAK.js} +2 -2
- package/dist/chunk-62VSIVME.js +4714 -0
- package/dist/{chunk-6VDGZ4KA.js → chunk-7FBSP3VD.js} +2 -2
- package/dist/{chunk-QDWLBCD3.js → chunk-AP5HBIV4.js} +2 -2
- package/dist/{chunk-DHII2GRW.js → chunk-EZEQQJNH.js} +2 -2
- package/dist/{chunk-Q5NZ5UFZ.js → chunk-F56AI52P.js} +2 -2
- package/dist/{chunk-RDAVEULA.js → chunk-KIQLUFJX.js} +2 -2
- package/dist/{chunk-3XHKEHGF.js → chunk-M3WM5Q7W.js} +2 -2
- package/dist/{chunk-4SMVVOU5.js → chunk-PJORQUQP.js} +2 -2
- package/dist/{chunk-DB473RZJ.js → chunk-PNPTKVJ4.js} +4 -4
- package/dist/{chunk-ULJCXOOM.js → chunk-RVXF3JZ7.js} +627 -5096
- package/dist/chunk-WEJL5OFI.js +8732 -0
- package/dist/{chunk-52A4W4YI.js → chunk-WWBSNLRC.js} +2 -2
- package/dist/index.d.ts +5 -0
- package/dist/index.js +14 -13
- package/dist/lib/mysql/cms-resource-actions.cjs +4733 -0
- package/dist/lib/mysql/cms-resource-actions.cjs.map +1 -0
- package/dist/lib/mysql/cms-resource-actions.d.cts +155 -0
- package/dist/lib/mysql/cms-resource-actions.d.ts +155 -0
- package/dist/lib/mysql/cms-resource-actions.js +8 -0
- package/dist/lib/mysql/cms-resource-actions.js.map +1 -0
- package/dist/lib/mysql/index.cjs +420 -187
- package/dist/lib/mysql/index.cjs.map +1 -1
- package/dist/lib/mysql/index.d.cts +5 -0
- package/dist/lib/mysql/index.d.ts +5 -0
- package/dist/lib/mysql/index.js +17 -13
- package/dist/lib/mysql/schemas/auth/accounts.js +2 -2
- package/dist/lib/mysql/schemas/auth/device-access-token.js +3 -3
- package/dist/lib/mysql/schemas/auth/device-verification.js +3 -3
- package/dist/lib/mysql/schemas/auth/personal-access-token.js +3 -3
- package/dist/lib/mysql/schemas/auth/profiles.js +2 -2
- package/dist/lib/mysql/schemas/auth/role-permissions.js +3 -3
- package/dist/lib/mysql/schemas/auth/roles.js +2 -2
- package/dist/lib/mysql/schemas/auth/sessions.js +3 -3
- package/dist/lib/mysql/schemas/auth/user-permissions.js +2 -2
- package/dist/lib/mysql/schemas/auth/user-prefs.js +2 -2
- package/dist/lib/mysql/schemas/auth/user-roles.js +2 -2
- package/dist/lib/mysql/schemas/auth/users.js +2 -2
- package/dist/lib/mysql/schemas/commerce/coupon.js +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-charge.js +2 -2
- package/dist/lib/mysql/schemas/commerce/merchant-subscription.js +2 -2
- package/dist/lib/mysql/schemas/commerce/price.js +2 -2
- package/dist/lib/mysql/schemas/commerce/product.js +2 -2
- package/dist/lib/mysql/schemas/commerce/purchase-user-transfer.js +3 -3
- package/dist/lib/mysql/schemas/commerce/purchase.js +2 -2
- package/dist/lib/mysql/schemas/commerce/subscription.js +2 -2
- package/dist/lib/mysql/schemas/commerce/upgradable-products.js +3 -3
- package/dist/lib/mysql/schemas/communication/comment.js +2 -2
- package/dist/lib/mysql/schemas/communication/communication-preferences.js +2 -2
- package/dist/lib/mysql/schemas/communication/question-response.js +3 -3
- package/dist/lib/mysql/schemas/content/content-contributions.js +2 -2
- package/dist/lib/mysql/schemas/content/content-resource-product.js +2 -2
- package/dist/lib/mysql/schemas/content/content-resource-resource.js +2 -2
- package/dist/lib/mysql/schemas/content/content-resource-tag.js +2 -2
- package/dist/lib/mysql/schemas/content/content-resource-version.js +2 -2
- package/dist/lib/mysql/schemas/content/content-resource.js +2 -2
- package/dist/lib/mysql/schemas/content/tag-tag.js +2 -2
- package/dist/lib/mysql/schemas/content/tag.js +2 -2
- package/dist/lib/mysql/schemas/entitlements/entitlement.js +3 -3
- package/dist/lib/mysql/schemas/org/organization-membership-roles.js +2 -2
- package/dist/lib/mysql/schemas/org/organization-memberships.js +2 -2
- package/dist/lib/mysql/schemas/org/organizations.js +2 -2
- package/dist/lib/utils.d.cts +5 -0
- package/dist/lib/utils.d.ts +5 -0
- package/package.json +3 -3
- package/src/lib/mysql/cms-resource-actions.ts +527 -0
- package/src/lib/mysql/index.ts +3 -0
|
@@ -0,0 +1,4733 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc2) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc2 = __getOwnPropDesc(from, key)) || desc2.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/lib/mysql/cms-resource-actions.ts
|
|
22
|
+
var cms_resource_actions_exports = {};
|
|
23
|
+
__export(cms_resource_actions_exports, {
|
|
24
|
+
createCmsResourceActions: () => createCmsResourceActions
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(cms_resource_actions_exports);
|
|
27
|
+
var import_drizzle_orm = require("drizzle-orm");
|
|
28
|
+
|
|
29
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/external.js
|
|
30
|
+
var external_exports = {};
|
|
31
|
+
__export(external_exports, {
|
|
32
|
+
BRAND: () => BRAND,
|
|
33
|
+
DIRTY: () => DIRTY,
|
|
34
|
+
EMPTY_PATH: () => EMPTY_PATH,
|
|
35
|
+
INVALID: () => INVALID,
|
|
36
|
+
NEVER: () => NEVER,
|
|
37
|
+
OK: () => OK,
|
|
38
|
+
ParseStatus: () => ParseStatus,
|
|
39
|
+
Schema: () => ZodType,
|
|
40
|
+
ZodAny: () => ZodAny,
|
|
41
|
+
ZodArray: () => ZodArray,
|
|
42
|
+
ZodBigInt: () => ZodBigInt,
|
|
43
|
+
ZodBoolean: () => ZodBoolean,
|
|
44
|
+
ZodBranded: () => ZodBranded,
|
|
45
|
+
ZodCatch: () => ZodCatch,
|
|
46
|
+
ZodDate: () => ZodDate,
|
|
47
|
+
ZodDefault: () => ZodDefault,
|
|
48
|
+
ZodDiscriminatedUnion: () => ZodDiscriminatedUnion,
|
|
49
|
+
ZodEffects: () => ZodEffects,
|
|
50
|
+
ZodEnum: () => ZodEnum,
|
|
51
|
+
ZodError: () => ZodError,
|
|
52
|
+
ZodFirstPartyTypeKind: () => ZodFirstPartyTypeKind,
|
|
53
|
+
ZodFunction: () => ZodFunction,
|
|
54
|
+
ZodIntersection: () => ZodIntersection,
|
|
55
|
+
ZodIssueCode: () => ZodIssueCode,
|
|
56
|
+
ZodLazy: () => ZodLazy,
|
|
57
|
+
ZodLiteral: () => ZodLiteral,
|
|
58
|
+
ZodMap: () => ZodMap,
|
|
59
|
+
ZodNaN: () => ZodNaN,
|
|
60
|
+
ZodNativeEnum: () => ZodNativeEnum,
|
|
61
|
+
ZodNever: () => ZodNever,
|
|
62
|
+
ZodNull: () => ZodNull,
|
|
63
|
+
ZodNullable: () => ZodNullable,
|
|
64
|
+
ZodNumber: () => ZodNumber,
|
|
65
|
+
ZodObject: () => ZodObject,
|
|
66
|
+
ZodOptional: () => ZodOptional,
|
|
67
|
+
ZodParsedType: () => ZodParsedType,
|
|
68
|
+
ZodPipeline: () => ZodPipeline,
|
|
69
|
+
ZodPromise: () => ZodPromise,
|
|
70
|
+
ZodReadonly: () => ZodReadonly,
|
|
71
|
+
ZodRecord: () => ZodRecord,
|
|
72
|
+
ZodSchema: () => ZodType,
|
|
73
|
+
ZodSet: () => ZodSet,
|
|
74
|
+
ZodString: () => ZodString,
|
|
75
|
+
ZodSymbol: () => ZodSymbol,
|
|
76
|
+
ZodTransformer: () => ZodEffects,
|
|
77
|
+
ZodTuple: () => ZodTuple,
|
|
78
|
+
ZodType: () => ZodType,
|
|
79
|
+
ZodUndefined: () => ZodUndefined,
|
|
80
|
+
ZodUnion: () => ZodUnion,
|
|
81
|
+
ZodUnknown: () => ZodUnknown,
|
|
82
|
+
ZodVoid: () => ZodVoid,
|
|
83
|
+
addIssueToContext: () => addIssueToContext,
|
|
84
|
+
any: () => anyType,
|
|
85
|
+
array: () => arrayType,
|
|
86
|
+
bigint: () => bigIntType,
|
|
87
|
+
boolean: () => booleanType,
|
|
88
|
+
coerce: () => coerce,
|
|
89
|
+
custom: () => custom,
|
|
90
|
+
date: () => dateType,
|
|
91
|
+
datetimeRegex: () => datetimeRegex,
|
|
92
|
+
defaultErrorMap: () => en_default,
|
|
93
|
+
discriminatedUnion: () => discriminatedUnionType,
|
|
94
|
+
effect: () => effectsType,
|
|
95
|
+
enum: () => enumType,
|
|
96
|
+
function: () => functionType,
|
|
97
|
+
getErrorMap: () => getErrorMap,
|
|
98
|
+
getParsedType: () => getParsedType,
|
|
99
|
+
instanceof: () => instanceOfType,
|
|
100
|
+
intersection: () => intersectionType,
|
|
101
|
+
isAborted: () => isAborted,
|
|
102
|
+
isAsync: () => isAsync,
|
|
103
|
+
isDirty: () => isDirty,
|
|
104
|
+
isValid: () => isValid,
|
|
105
|
+
late: () => late,
|
|
106
|
+
lazy: () => lazyType,
|
|
107
|
+
literal: () => literalType,
|
|
108
|
+
makeIssue: () => makeIssue,
|
|
109
|
+
map: () => mapType,
|
|
110
|
+
nan: () => nanType,
|
|
111
|
+
nativeEnum: () => nativeEnumType,
|
|
112
|
+
never: () => neverType,
|
|
113
|
+
null: () => nullType,
|
|
114
|
+
nullable: () => nullableType,
|
|
115
|
+
number: () => numberType,
|
|
116
|
+
object: () => objectType,
|
|
117
|
+
objectUtil: () => objectUtil,
|
|
118
|
+
oboolean: () => oboolean,
|
|
119
|
+
onumber: () => onumber,
|
|
120
|
+
optional: () => optionalType,
|
|
121
|
+
ostring: () => ostring,
|
|
122
|
+
pipeline: () => pipelineType,
|
|
123
|
+
preprocess: () => preprocessType,
|
|
124
|
+
promise: () => promiseType,
|
|
125
|
+
quotelessJson: () => quotelessJson,
|
|
126
|
+
record: () => recordType,
|
|
127
|
+
set: () => setType,
|
|
128
|
+
setErrorMap: () => setErrorMap,
|
|
129
|
+
strictObject: () => strictObjectType,
|
|
130
|
+
string: () => stringType,
|
|
131
|
+
symbol: () => symbolType,
|
|
132
|
+
transformer: () => effectsType,
|
|
133
|
+
tuple: () => tupleType,
|
|
134
|
+
undefined: () => undefinedType,
|
|
135
|
+
union: () => unionType,
|
|
136
|
+
unknown: () => unknownType,
|
|
137
|
+
util: () => util,
|
|
138
|
+
void: () => voidType
|
|
139
|
+
});
|
|
140
|
+
|
|
141
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/util.js
|
|
142
|
+
var util;
|
|
143
|
+
(function(util2) {
|
|
144
|
+
util2.assertEqual = (_) => {
|
|
145
|
+
};
|
|
146
|
+
function assertIs(_arg) {
|
|
147
|
+
}
|
|
148
|
+
__name(assertIs, "assertIs");
|
|
149
|
+
util2.assertIs = assertIs;
|
|
150
|
+
function assertNever(_x) {
|
|
151
|
+
throw new Error();
|
|
152
|
+
}
|
|
153
|
+
__name(assertNever, "assertNever");
|
|
154
|
+
util2.assertNever = assertNever;
|
|
155
|
+
util2.arrayToEnum = (items) => {
|
|
156
|
+
const obj = {};
|
|
157
|
+
for (const item of items) {
|
|
158
|
+
obj[item] = item;
|
|
159
|
+
}
|
|
160
|
+
return obj;
|
|
161
|
+
};
|
|
162
|
+
util2.getValidEnumValues = (obj) => {
|
|
163
|
+
const validKeys = util2.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
|
|
164
|
+
const filtered = {};
|
|
165
|
+
for (const k of validKeys) {
|
|
166
|
+
filtered[k] = obj[k];
|
|
167
|
+
}
|
|
168
|
+
return util2.objectValues(filtered);
|
|
169
|
+
};
|
|
170
|
+
util2.objectValues = (obj) => {
|
|
171
|
+
return util2.objectKeys(obj).map(function(e) {
|
|
172
|
+
return obj[e];
|
|
173
|
+
});
|
|
174
|
+
};
|
|
175
|
+
util2.objectKeys = typeof Object.keys === "function" ? (obj) => Object.keys(obj) : (object) => {
|
|
176
|
+
const keys = [];
|
|
177
|
+
for (const key in object) {
|
|
178
|
+
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
179
|
+
keys.push(key);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return keys;
|
|
183
|
+
};
|
|
184
|
+
util2.find = (arr, checker) => {
|
|
185
|
+
for (const item of arr) {
|
|
186
|
+
if (checker(item))
|
|
187
|
+
return item;
|
|
188
|
+
}
|
|
189
|
+
return void 0;
|
|
190
|
+
};
|
|
191
|
+
util2.isInteger = typeof Number.isInteger === "function" ? (val) => Number.isInteger(val) : (val) => typeof val === "number" && Number.isFinite(val) && Math.floor(val) === val;
|
|
192
|
+
function joinValues(array, separator = " | ") {
|
|
193
|
+
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
194
|
+
}
|
|
195
|
+
__name(joinValues, "joinValues");
|
|
196
|
+
util2.joinValues = joinValues;
|
|
197
|
+
util2.jsonStringifyReplacer = (_, value) => {
|
|
198
|
+
if (typeof value === "bigint") {
|
|
199
|
+
return value.toString();
|
|
200
|
+
}
|
|
201
|
+
return value;
|
|
202
|
+
};
|
|
203
|
+
})(util || (util = {}));
|
|
204
|
+
var objectUtil;
|
|
205
|
+
(function(objectUtil2) {
|
|
206
|
+
objectUtil2.mergeShapes = (first, second) => {
|
|
207
|
+
return {
|
|
208
|
+
...first,
|
|
209
|
+
...second
|
|
210
|
+
};
|
|
211
|
+
};
|
|
212
|
+
})(objectUtil || (objectUtil = {}));
|
|
213
|
+
var ZodParsedType = util.arrayToEnum([
|
|
214
|
+
"string",
|
|
215
|
+
"nan",
|
|
216
|
+
"number",
|
|
217
|
+
"integer",
|
|
218
|
+
"float",
|
|
219
|
+
"boolean",
|
|
220
|
+
"date",
|
|
221
|
+
"bigint",
|
|
222
|
+
"symbol",
|
|
223
|
+
"function",
|
|
224
|
+
"undefined",
|
|
225
|
+
"null",
|
|
226
|
+
"array",
|
|
227
|
+
"object",
|
|
228
|
+
"unknown",
|
|
229
|
+
"promise",
|
|
230
|
+
"void",
|
|
231
|
+
"never",
|
|
232
|
+
"map",
|
|
233
|
+
"set"
|
|
234
|
+
]);
|
|
235
|
+
var getParsedType = /* @__PURE__ */ __name((data) => {
|
|
236
|
+
const t = typeof data;
|
|
237
|
+
switch (t) {
|
|
238
|
+
case "undefined":
|
|
239
|
+
return ZodParsedType.undefined;
|
|
240
|
+
case "string":
|
|
241
|
+
return ZodParsedType.string;
|
|
242
|
+
case "number":
|
|
243
|
+
return Number.isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
244
|
+
case "boolean":
|
|
245
|
+
return ZodParsedType.boolean;
|
|
246
|
+
case "function":
|
|
247
|
+
return ZodParsedType.function;
|
|
248
|
+
case "bigint":
|
|
249
|
+
return ZodParsedType.bigint;
|
|
250
|
+
case "symbol":
|
|
251
|
+
return ZodParsedType.symbol;
|
|
252
|
+
case "object":
|
|
253
|
+
if (Array.isArray(data)) {
|
|
254
|
+
return ZodParsedType.array;
|
|
255
|
+
}
|
|
256
|
+
if (data === null) {
|
|
257
|
+
return ZodParsedType.null;
|
|
258
|
+
}
|
|
259
|
+
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
260
|
+
return ZodParsedType.promise;
|
|
261
|
+
}
|
|
262
|
+
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
263
|
+
return ZodParsedType.map;
|
|
264
|
+
}
|
|
265
|
+
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
266
|
+
return ZodParsedType.set;
|
|
267
|
+
}
|
|
268
|
+
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
269
|
+
return ZodParsedType.date;
|
|
270
|
+
}
|
|
271
|
+
return ZodParsedType.object;
|
|
272
|
+
default:
|
|
273
|
+
return ZodParsedType.unknown;
|
|
274
|
+
}
|
|
275
|
+
}, "getParsedType");
|
|
276
|
+
|
|
277
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/ZodError.js
|
|
278
|
+
var ZodIssueCode = util.arrayToEnum([
|
|
279
|
+
"invalid_type",
|
|
280
|
+
"invalid_literal",
|
|
281
|
+
"custom",
|
|
282
|
+
"invalid_union",
|
|
283
|
+
"invalid_union_discriminator",
|
|
284
|
+
"invalid_enum_value",
|
|
285
|
+
"unrecognized_keys",
|
|
286
|
+
"invalid_arguments",
|
|
287
|
+
"invalid_return_type",
|
|
288
|
+
"invalid_date",
|
|
289
|
+
"invalid_string",
|
|
290
|
+
"too_small",
|
|
291
|
+
"too_big",
|
|
292
|
+
"invalid_intersection_types",
|
|
293
|
+
"not_multiple_of",
|
|
294
|
+
"not_finite"
|
|
295
|
+
]);
|
|
296
|
+
var quotelessJson = /* @__PURE__ */ __name((obj) => {
|
|
297
|
+
const json = JSON.stringify(obj, null, 2);
|
|
298
|
+
return json.replace(/"([^"]+)":/g, "$1:");
|
|
299
|
+
}, "quotelessJson");
|
|
300
|
+
var _ZodError = class _ZodError extends Error {
|
|
301
|
+
get errors() {
|
|
302
|
+
return this.issues;
|
|
303
|
+
}
|
|
304
|
+
constructor(issues) {
|
|
305
|
+
super();
|
|
306
|
+
this.issues = [];
|
|
307
|
+
this.addIssue = (sub) => {
|
|
308
|
+
this.issues = [
|
|
309
|
+
...this.issues,
|
|
310
|
+
sub
|
|
311
|
+
];
|
|
312
|
+
};
|
|
313
|
+
this.addIssues = (subs = []) => {
|
|
314
|
+
this.issues = [
|
|
315
|
+
...this.issues,
|
|
316
|
+
...subs
|
|
317
|
+
];
|
|
318
|
+
};
|
|
319
|
+
const actualProto = new.target.prototype;
|
|
320
|
+
if (Object.setPrototypeOf) {
|
|
321
|
+
Object.setPrototypeOf(this, actualProto);
|
|
322
|
+
} else {
|
|
323
|
+
this.__proto__ = actualProto;
|
|
324
|
+
}
|
|
325
|
+
this.name = "ZodError";
|
|
326
|
+
this.issues = issues;
|
|
327
|
+
}
|
|
328
|
+
format(_mapper) {
|
|
329
|
+
const mapper = _mapper || function(issue) {
|
|
330
|
+
return issue.message;
|
|
331
|
+
};
|
|
332
|
+
const fieldErrors = {
|
|
333
|
+
_errors: []
|
|
334
|
+
};
|
|
335
|
+
const processError = /* @__PURE__ */ __name((error) => {
|
|
336
|
+
for (const issue of error.issues) {
|
|
337
|
+
if (issue.code === "invalid_union") {
|
|
338
|
+
issue.unionErrors.map(processError);
|
|
339
|
+
} else if (issue.code === "invalid_return_type") {
|
|
340
|
+
processError(issue.returnTypeError);
|
|
341
|
+
} else if (issue.code === "invalid_arguments") {
|
|
342
|
+
processError(issue.argumentsError);
|
|
343
|
+
} else if (issue.path.length === 0) {
|
|
344
|
+
fieldErrors._errors.push(mapper(issue));
|
|
345
|
+
} else {
|
|
346
|
+
let curr = fieldErrors;
|
|
347
|
+
let i = 0;
|
|
348
|
+
while (i < issue.path.length) {
|
|
349
|
+
const el = issue.path[i];
|
|
350
|
+
const terminal = i === issue.path.length - 1;
|
|
351
|
+
if (!terminal) {
|
|
352
|
+
curr[el] = curr[el] || {
|
|
353
|
+
_errors: []
|
|
354
|
+
};
|
|
355
|
+
} else {
|
|
356
|
+
curr[el] = curr[el] || {
|
|
357
|
+
_errors: []
|
|
358
|
+
};
|
|
359
|
+
curr[el]._errors.push(mapper(issue));
|
|
360
|
+
}
|
|
361
|
+
curr = curr[el];
|
|
362
|
+
i++;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}, "processError");
|
|
367
|
+
processError(this);
|
|
368
|
+
return fieldErrors;
|
|
369
|
+
}
|
|
370
|
+
static assert(value) {
|
|
371
|
+
if (!(value instanceof _ZodError)) {
|
|
372
|
+
throw new Error(`Not a ZodError: ${value}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
toString() {
|
|
376
|
+
return this.message;
|
|
377
|
+
}
|
|
378
|
+
get message() {
|
|
379
|
+
return JSON.stringify(this.issues, util.jsonStringifyReplacer, 2);
|
|
380
|
+
}
|
|
381
|
+
get isEmpty() {
|
|
382
|
+
return this.issues.length === 0;
|
|
383
|
+
}
|
|
384
|
+
flatten(mapper = (issue) => issue.message) {
|
|
385
|
+
const fieldErrors = {};
|
|
386
|
+
const formErrors = [];
|
|
387
|
+
for (const sub of this.issues) {
|
|
388
|
+
if (sub.path.length > 0) {
|
|
389
|
+
const firstEl = sub.path[0];
|
|
390
|
+
fieldErrors[firstEl] = fieldErrors[firstEl] || [];
|
|
391
|
+
fieldErrors[firstEl].push(mapper(sub));
|
|
392
|
+
} else {
|
|
393
|
+
formErrors.push(mapper(sub));
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return {
|
|
397
|
+
formErrors,
|
|
398
|
+
fieldErrors
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
get formErrors() {
|
|
402
|
+
return this.flatten();
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
__name(_ZodError, "ZodError");
|
|
406
|
+
var ZodError = _ZodError;
|
|
407
|
+
ZodError.create = (issues) => {
|
|
408
|
+
const error = new ZodError(issues);
|
|
409
|
+
return error;
|
|
410
|
+
};
|
|
411
|
+
|
|
412
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/locales/en.js
|
|
413
|
+
var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
|
|
414
|
+
let message;
|
|
415
|
+
switch (issue.code) {
|
|
416
|
+
case ZodIssueCode.invalid_type:
|
|
417
|
+
if (issue.received === ZodParsedType.undefined) {
|
|
418
|
+
message = "Required";
|
|
419
|
+
} else {
|
|
420
|
+
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
421
|
+
}
|
|
422
|
+
break;
|
|
423
|
+
case ZodIssueCode.invalid_literal:
|
|
424
|
+
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util.jsonStringifyReplacer)}`;
|
|
425
|
+
break;
|
|
426
|
+
case ZodIssueCode.unrecognized_keys:
|
|
427
|
+
message = `Unrecognized key(s) in object: ${util.joinValues(issue.keys, ", ")}`;
|
|
428
|
+
break;
|
|
429
|
+
case ZodIssueCode.invalid_union:
|
|
430
|
+
message = `Invalid input`;
|
|
431
|
+
break;
|
|
432
|
+
case ZodIssueCode.invalid_union_discriminator:
|
|
433
|
+
message = `Invalid discriminator value. Expected ${util.joinValues(issue.options)}`;
|
|
434
|
+
break;
|
|
435
|
+
case ZodIssueCode.invalid_enum_value:
|
|
436
|
+
message = `Invalid enum value. Expected ${util.joinValues(issue.options)}, received '${issue.received}'`;
|
|
437
|
+
break;
|
|
438
|
+
case ZodIssueCode.invalid_arguments:
|
|
439
|
+
message = `Invalid function arguments`;
|
|
440
|
+
break;
|
|
441
|
+
case ZodIssueCode.invalid_return_type:
|
|
442
|
+
message = `Invalid function return type`;
|
|
443
|
+
break;
|
|
444
|
+
case ZodIssueCode.invalid_date:
|
|
445
|
+
message = `Invalid date`;
|
|
446
|
+
break;
|
|
447
|
+
case ZodIssueCode.invalid_string:
|
|
448
|
+
if (typeof issue.validation === "object") {
|
|
449
|
+
if ("includes" in issue.validation) {
|
|
450
|
+
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
451
|
+
if (typeof issue.validation.position === "number") {
|
|
452
|
+
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
453
|
+
}
|
|
454
|
+
} else if ("startsWith" in issue.validation) {
|
|
455
|
+
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
456
|
+
} else if ("endsWith" in issue.validation) {
|
|
457
|
+
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
458
|
+
} else {
|
|
459
|
+
util.assertNever(issue.validation);
|
|
460
|
+
}
|
|
461
|
+
} else if (issue.validation !== "regex") {
|
|
462
|
+
message = `Invalid ${issue.validation}`;
|
|
463
|
+
} else {
|
|
464
|
+
message = "Invalid";
|
|
465
|
+
}
|
|
466
|
+
break;
|
|
467
|
+
case ZodIssueCode.too_small:
|
|
468
|
+
if (issue.type === "array")
|
|
469
|
+
message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
|
|
470
|
+
else if (issue.type === "string")
|
|
471
|
+
message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
|
|
472
|
+
else if (issue.type === "number")
|
|
473
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
474
|
+
else if (issue.type === "bigint")
|
|
475
|
+
message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;
|
|
476
|
+
else if (issue.type === "date")
|
|
477
|
+
message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;
|
|
478
|
+
else
|
|
479
|
+
message = "Invalid input";
|
|
480
|
+
break;
|
|
481
|
+
case ZodIssueCode.too_big:
|
|
482
|
+
if (issue.type === "array")
|
|
483
|
+
message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
|
|
484
|
+
else if (issue.type === "string")
|
|
485
|
+
message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
|
|
486
|
+
else if (issue.type === "number")
|
|
487
|
+
message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
488
|
+
else if (issue.type === "bigint")
|
|
489
|
+
message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;
|
|
490
|
+
else if (issue.type === "date")
|
|
491
|
+
message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;
|
|
492
|
+
else
|
|
493
|
+
message = "Invalid input";
|
|
494
|
+
break;
|
|
495
|
+
case ZodIssueCode.custom:
|
|
496
|
+
message = `Invalid input`;
|
|
497
|
+
break;
|
|
498
|
+
case ZodIssueCode.invalid_intersection_types:
|
|
499
|
+
message = `Intersection results could not be merged`;
|
|
500
|
+
break;
|
|
501
|
+
case ZodIssueCode.not_multiple_of:
|
|
502
|
+
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
503
|
+
break;
|
|
504
|
+
case ZodIssueCode.not_finite:
|
|
505
|
+
message = "Number must be finite";
|
|
506
|
+
break;
|
|
507
|
+
default:
|
|
508
|
+
message = _ctx.defaultError;
|
|
509
|
+
util.assertNever(issue);
|
|
510
|
+
}
|
|
511
|
+
return {
|
|
512
|
+
message
|
|
513
|
+
};
|
|
514
|
+
}, "errorMap");
|
|
515
|
+
var en_default = errorMap;
|
|
516
|
+
|
|
517
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/errors.js
|
|
518
|
+
var overrideErrorMap = en_default;
|
|
519
|
+
function setErrorMap(map) {
|
|
520
|
+
overrideErrorMap = map;
|
|
521
|
+
}
|
|
522
|
+
__name(setErrorMap, "setErrorMap");
|
|
523
|
+
function getErrorMap() {
|
|
524
|
+
return overrideErrorMap;
|
|
525
|
+
}
|
|
526
|
+
__name(getErrorMap, "getErrorMap");
|
|
527
|
+
|
|
528
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/parseUtil.js
|
|
529
|
+
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
530
|
+
const { data, path, errorMaps, issueData } = params;
|
|
531
|
+
const fullPath = [
|
|
532
|
+
...path,
|
|
533
|
+
...issueData.path || []
|
|
534
|
+
];
|
|
535
|
+
const fullIssue = {
|
|
536
|
+
...issueData,
|
|
537
|
+
path: fullPath
|
|
538
|
+
};
|
|
539
|
+
if (issueData.message !== void 0) {
|
|
540
|
+
return {
|
|
541
|
+
...issueData,
|
|
542
|
+
path: fullPath,
|
|
543
|
+
message: issueData.message
|
|
544
|
+
};
|
|
545
|
+
}
|
|
546
|
+
let errorMessage = "";
|
|
547
|
+
const maps = errorMaps.filter((m) => !!m).slice().reverse();
|
|
548
|
+
for (const map of maps) {
|
|
549
|
+
errorMessage = map(fullIssue, {
|
|
550
|
+
data,
|
|
551
|
+
defaultError: errorMessage
|
|
552
|
+
}).message;
|
|
553
|
+
}
|
|
554
|
+
return {
|
|
555
|
+
...issueData,
|
|
556
|
+
path: fullPath,
|
|
557
|
+
message: errorMessage
|
|
558
|
+
};
|
|
559
|
+
}, "makeIssue");
|
|
560
|
+
var EMPTY_PATH = [];
|
|
561
|
+
function addIssueToContext(ctx, issueData) {
|
|
562
|
+
const overrideMap = getErrorMap();
|
|
563
|
+
const issue = makeIssue({
|
|
564
|
+
issueData,
|
|
565
|
+
data: ctx.data,
|
|
566
|
+
path: ctx.path,
|
|
567
|
+
errorMaps: [
|
|
568
|
+
ctx.common.contextualErrorMap,
|
|
569
|
+
ctx.schemaErrorMap,
|
|
570
|
+
overrideMap,
|
|
571
|
+
overrideMap === en_default ? void 0 : en_default
|
|
572
|
+
].filter((x) => !!x)
|
|
573
|
+
});
|
|
574
|
+
ctx.common.issues.push(issue);
|
|
575
|
+
}
|
|
576
|
+
__name(addIssueToContext, "addIssueToContext");
|
|
577
|
+
var _ParseStatus = class _ParseStatus {
|
|
578
|
+
constructor() {
|
|
579
|
+
this.value = "valid";
|
|
580
|
+
}
|
|
581
|
+
dirty() {
|
|
582
|
+
if (this.value === "valid")
|
|
583
|
+
this.value = "dirty";
|
|
584
|
+
}
|
|
585
|
+
abort() {
|
|
586
|
+
if (this.value !== "aborted")
|
|
587
|
+
this.value = "aborted";
|
|
588
|
+
}
|
|
589
|
+
static mergeArray(status, results) {
|
|
590
|
+
const arrayValue = [];
|
|
591
|
+
for (const s of results) {
|
|
592
|
+
if (s.status === "aborted")
|
|
593
|
+
return INVALID;
|
|
594
|
+
if (s.status === "dirty")
|
|
595
|
+
status.dirty();
|
|
596
|
+
arrayValue.push(s.value);
|
|
597
|
+
}
|
|
598
|
+
return {
|
|
599
|
+
status: status.value,
|
|
600
|
+
value: arrayValue
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
static async mergeObjectAsync(status, pairs) {
|
|
604
|
+
const syncPairs = [];
|
|
605
|
+
for (const pair of pairs) {
|
|
606
|
+
const key = await pair.key;
|
|
607
|
+
const value = await pair.value;
|
|
608
|
+
syncPairs.push({
|
|
609
|
+
key,
|
|
610
|
+
value
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
return _ParseStatus.mergeObjectSync(status, syncPairs);
|
|
614
|
+
}
|
|
615
|
+
static mergeObjectSync(status, pairs) {
|
|
616
|
+
const finalObject = {};
|
|
617
|
+
for (const pair of pairs) {
|
|
618
|
+
const { key, value } = pair;
|
|
619
|
+
if (key.status === "aborted")
|
|
620
|
+
return INVALID;
|
|
621
|
+
if (value.status === "aborted")
|
|
622
|
+
return INVALID;
|
|
623
|
+
if (key.status === "dirty")
|
|
624
|
+
status.dirty();
|
|
625
|
+
if (value.status === "dirty")
|
|
626
|
+
status.dirty();
|
|
627
|
+
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
628
|
+
finalObject[key.value] = value.value;
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
return {
|
|
632
|
+
status: status.value,
|
|
633
|
+
value: finalObject
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
};
|
|
637
|
+
__name(_ParseStatus, "ParseStatus");
|
|
638
|
+
var ParseStatus = _ParseStatus;
|
|
639
|
+
var INVALID = Object.freeze({
|
|
640
|
+
status: "aborted"
|
|
641
|
+
});
|
|
642
|
+
var DIRTY = /* @__PURE__ */ __name((value) => ({
|
|
643
|
+
status: "dirty",
|
|
644
|
+
value
|
|
645
|
+
}), "DIRTY");
|
|
646
|
+
var OK = /* @__PURE__ */ __name((value) => ({
|
|
647
|
+
status: "valid",
|
|
648
|
+
value
|
|
649
|
+
}), "OK");
|
|
650
|
+
var isAborted = /* @__PURE__ */ __name((x) => x.status === "aborted", "isAborted");
|
|
651
|
+
var isDirty = /* @__PURE__ */ __name((x) => x.status === "dirty", "isDirty");
|
|
652
|
+
var isValid = /* @__PURE__ */ __name((x) => x.status === "valid", "isValid");
|
|
653
|
+
var isAsync = /* @__PURE__ */ __name((x) => typeof Promise !== "undefined" && x instanceof Promise, "isAsync");
|
|
654
|
+
|
|
655
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/helpers/errorUtil.js
|
|
656
|
+
var errorUtil;
|
|
657
|
+
(function(errorUtil2) {
|
|
658
|
+
errorUtil2.errToObj = (message) => typeof message === "string" ? {
|
|
659
|
+
message
|
|
660
|
+
} : message || {};
|
|
661
|
+
errorUtil2.toString = (message) => typeof message === "string" ? message : message?.message;
|
|
662
|
+
})(errorUtil || (errorUtil = {}));
|
|
663
|
+
|
|
664
|
+
// ../../node_modules/.pnpm/zod@3.25.76/node_modules/zod/v3/types.js
|
|
665
|
+
var _a;
|
|
666
|
+
var ParseInputLazyPath = (_a = class {
|
|
667
|
+
constructor(parent, value, path, key) {
|
|
668
|
+
this._cachedPath = [];
|
|
669
|
+
this.parent = parent;
|
|
670
|
+
this.data = value;
|
|
671
|
+
this._path = path;
|
|
672
|
+
this._key = key;
|
|
673
|
+
}
|
|
674
|
+
get path() {
|
|
675
|
+
if (!this._cachedPath.length) {
|
|
676
|
+
if (Array.isArray(this._key)) {
|
|
677
|
+
this._cachedPath.push(...this._path, ...this._key);
|
|
678
|
+
} else {
|
|
679
|
+
this._cachedPath.push(...this._path, this._key);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
return this._cachedPath;
|
|
683
|
+
}
|
|
684
|
+
}, __name(_a, "ParseInputLazyPath"), _a);
|
|
685
|
+
var handleResult = /* @__PURE__ */ __name((ctx, result) => {
|
|
686
|
+
if (isValid(result)) {
|
|
687
|
+
return {
|
|
688
|
+
success: true,
|
|
689
|
+
data: result.value
|
|
690
|
+
};
|
|
691
|
+
} else {
|
|
692
|
+
if (!ctx.common.issues.length) {
|
|
693
|
+
throw new Error("Validation failed but no issues detected.");
|
|
694
|
+
}
|
|
695
|
+
return {
|
|
696
|
+
success: false,
|
|
697
|
+
get error() {
|
|
698
|
+
if (this._error)
|
|
699
|
+
return this._error;
|
|
700
|
+
const error = new ZodError(ctx.common.issues);
|
|
701
|
+
this._error = error;
|
|
702
|
+
return this._error;
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
}, "handleResult");
|
|
707
|
+
function processCreateParams(params) {
|
|
708
|
+
if (!params)
|
|
709
|
+
return {};
|
|
710
|
+
const { errorMap: errorMap2, invalid_type_error, required_error, description } = params;
|
|
711
|
+
if (errorMap2 && (invalid_type_error || required_error)) {
|
|
712
|
+
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
713
|
+
}
|
|
714
|
+
if (errorMap2)
|
|
715
|
+
return {
|
|
716
|
+
errorMap: errorMap2,
|
|
717
|
+
description
|
|
718
|
+
};
|
|
719
|
+
const customMap = /* @__PURE__ */ __name((iss, ctx) => {
|
|
720
|
+
const { message } = params;
|
|
721
|
+
if (iss.code === "invalid_enum_value") {
|
|
722
|
+
return {
|
|
723
|
+
message: message ?? ctx.defaultError
|
|
724
|
+
};
|
|
725
|
+
}
|
|
726
|
+
if (typeof ctx.data === "undefined") {
|
|
727
|
+
return {
|
|
728
|
+
message: message ?? required_error ?? ctx.defaultError
|
|
729
|
+
};
|
|
730
|
+
}
|
|
731
|
+
if (iss.code !== "invalid_type")
|
|
732
|
+
return {
|
|
733
|
+
message: ctx.defaultError
|
|
734
|
+
};
|
|
735
|
+
return {
|
|
736
|
+
message: message ?? invalid_type_error ?? ctx.defaultError
|
|
737
|
+
};
|
|
738
|
+
}, "customMap");
|
|
739
|
+
return {
|
|
740
|
+
errorMap: customMap,
|
|
741
|
+
description
|
|
742
|
+
};
|
|
743
|
+
}
|
|
744
|
+
__name(processCreateParams, "processCreateParams");
|
|
745
|
+
var _ZodType = class _ZodType {
|
|
746
|
+
get description() {
|
|
747
|
+
return this._def.description;
|
|
748
|
+
}
|
|
749
|
+
_getType(input) {
|
|
750
|
+
return getParsedType(input.data);
|
|
751
|
+
}
|
|
752
|
+
_getOrReturnCtx(input, ctx) {
|
|
753
|
+
return ctx || {
|
|
754
|
+
common: input.parent.common,
|
|
755
|
+
data: input.data,
|
|
756
|
+
parsedType: getParsedType(input.data),
|
|
757
|
+
schemaErrorMap: this._def.errorMap,
|
|
758
|
+
path: input.path,
|
|
759
|
+
parent: input.parent
|
|
760
|
+
};
|
|
761
|
+
}
|
|
762
|
+
_processInputParams(input) {
|
|
763
|
+
return {
|
|
764
|
+
status: new ParseStatus(),
|
|
765
|
+
ctx: {
|
|
766
|
+
common: input.parent.common,
|
|
767
|
+
data: input.data,
|
|
768
|
+
parsedType: getParsedType(input.data),
|
|
769
|
+
schemaErrorMap: this._def.errorMap,
|
|
770
|
+
path: input.path,
|
|
771
|
+
parent: input.parent
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
}
|
|
775
|
+
_parseSync(input) {
|
|
776
|
+
const result = this._parse(input);
|
|
777
|
+
if (isAsync(result)) {
|
|
778
|
+
throw new Error("Synchronous parse encountered promise.");
|
|
779
|
+
}
|
|
780
|
+
return result;
|
|
781
|
+
}
|
|
782
|
+
_parseAsync(input) {
|
|
783
|
+
const result = this._parse(input);
|
|
784
|
+
return Promise.resolve(result);
|
|
785
|
+
}
|
|
786
|
+
parse(data, params) {
|
|
787
|
+
const result = this.safeParse(data, params);
|
|
788
|
+
if (result.success)
|
|
789
|
+
return result.data;
|
|
790
|
+
throw result.error;
|
|
791
|
+
}
|
|
792
|
+
safeParse(data, params) {
|
|
793
|
+
const ctx = {
|
|
794
|
+
common: {
|
|
795
|
+
issues: [],
|
|
796
|
+
async: params?.async ?? false,
|
|
797
|
+
contextualErrorMap: params?.errorMap
|
|
798
|
+
},
|
|
799
|
+
path: params?.path || [],
|
|
800
|
+
schemaErrorMap: this._def.errorMap,
|
|
801
|
+
parent: null,
|
|
802
|
+
data,
|
|
803
|
+
parsedType: getParsedType(data)
|
|
804
|
+
};
|
|
805
|
+
const result = this._parseSync({
|
|
806
|
+
data,
|
|
807
|
+
path: ctx.path,
|
|
808
|
+
parent: ctx
|
|
809
|
+
});
|
|
810
|
+
return handleResult(ctx, result);
|
|
811
|
+
}
|
|
812
|
+
"~validate"(data) {
|
|
813
|
+
const ctx = {
|
|
814
|
+
common: {
|
|
815
|
+
issues: [],
|
|
816
|
+
async: !!this["~standard"].async
|
|
817
|
+
},
|
|
818
|
+
path: [],
|
|
819
|
+
schemaErrorMap: this._def.errorMap,
|
|
820
|
+
parent: null,
|
|
821
|
+
data,
|
|
822
|
+
parsedType: getParsedType(data)
|
|
823
|
+
};
|
|
824
|
+
if (!this["~standard"].async) {
|
|
825
|
+
try {
|
|
826
|
+
const result = this._parseSync({
|
|
827
|
+
data,
|
|
828
|
+
path: [],
|
|
829
|
+
parent: ctx
|
|
830
|
+
});
|
|
831
|
+
return isValid(result) ? {
|
|
832
|
+
value: result.value
|
|
833
|
+
} : {
|
|
834
|
+
issues: ctx.common.issues
|
|
835
|
+
};
|
|
836
|
+
} catch (err) {
|
|
837
|
+
if (err?.message?.toLowerCase()?.includes("encountered")) {
|
|
838
|
+
this["~standard"].async = true;
|
|
839
|
+
}
|
|
840
|
+
ctx.common = {
|
|
841
|
+
issues: [],
|
|
842
|
+
async: true
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
return this._parseAsync({
|
|
847
|
+
data,
|
|
848
|
+
path: [],
|
|
849
|
+
parent: ctx
|
|
850
|
+
}).then((result) => isValid(result) ? {
|
|
851
|
+
value: result.value
|
|
852
|
+
} : {
|
|
853
|
+
issues: ctx.common.issues
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
async parseAsync(data, params) {
|
|
857
|
+
const result = await this.safeParseAsync(data, params);
|
|
858
|
+
if (result.success)
|
|
859
|
+
return result.data;
|
|
860
|
+
throw result.error;
|
|
861
|
+
}
|
|
862
|
+
async safeParseAsync(data, params) {
|
|
863
|
+
const ctx = {
|
|
864
|
+
common: {
|
|
865
|
+
issues: [],
|
|
866
|
+
contextualErrorMap: params?.errorMap,
|
|
867
|
+
async: true
|
|
868
|
+
},
|
|
869
|
+
path: params?.path || [],
|
|
870
|
+
schemaErrorMap: this._def.errorMap,
|
|
871
|
+
parent: null,
|
|
872
|
+
data,
|
|
873
|
+
parsedType: getParsedType(data)
|
|
874
|
+
};
|
|
875
|
+
const maybeAsyncResult = this._parse({
|
|
876
|
+
data,
|
|
877
|
+
path: ctx.path,
|
|
878
|
+
parent: ctx
|
|
879
|
+
});
|
|
880
|
+
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
881
|
+
return handleResult(ctx, result);
|
|
882
|
+
}
|
|
883
|
+
refine(check, message) {
|
|
884
|
+
const getIssueProperties = /* @__PURE__ */ __name((val) => {
|
|
885
|
+
if (typeof message === "string" || typeof message === "undefined") {
|
|
886
|
+
return {
|
|
887
|
+
message
|
|
888
|
+
};
|
|
889
|
+
} else if (typeof message === "function") {
|
|
890
|
+
return message(val);
|
|
891
|
+
} else {
|
|
892
|
+
return message;
|
|
893
|
+
}
|
|
894
|
+
}, "getIssueProperties");
|
|
895
|
+
return this._refinement((val, ctx) => {
|
|
896
|
+
const result = check(val);
|
|
897
|
+
const setError = /* @__PURE__ */ __name(() => ctx.addIssue({
|
|
898
|
+
code: ZodIssueCode.custom,
|
|
899
|
+
...getIssueProperties(val)
|
|
900
|
+
}), "setError");
|
|
901
|
+
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
902
|
+
return result.then((data) => {
|
|
903
|
+
if (!data) {
|
|
904
|
+
setError();
|
|
905
|
+
return false;
|
|
906
|
+
} else {
|
|
907
|
+
return true;
|
|
908
|
+
}
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
if (!result) {
|
|
912
|
+
setError();
|
|
913
|
+
return false;
|
|
914
|
+
} else {
|
|
915
|
+
return true;
|
|
916
|
+
}
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
refinement(check, refinementData) {
|
|
920
|
+
return this._refinement((val, ctx) => {
|
|
921
|
+
if (!check(val)) {
|
|
922
|
+
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
923
|
+
return false;
|
|
924
|
+
} else {
|
|
925
|
+
return true;
|
|
926
|
+
}
|
|
927
|
+
});
|
|
928
|
+
}
|
|
929
|
+
_refinement(refinement) {
|
|
930
|
+
return new ZodEffects({
|
|
931
|
+
schema: this,
|
|
932
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
933
|
+
effect: {
|
|
934
|
+
type: "refinement",
|
|
935
|
+
refinement
|
|
936
|
+
}
|
|
937
|
+
});
|
|
938
|
+
}
|
|
939
|
+
superRefine(refinement) {
|
|
940
|
+
return this._refinement(refinement);
|
|
941
|
+
}
|
|
942
|
+
constructor(def) {
|
|
943
|
+
this.spa = this.safeParseAsync;
|
|
944
|
+
this._def = def;
|
|
945
|
+
this.parse = this.parse.bind(this);
|
|
946
|
+
this.safeParse = this.safeParse.bind(this);
|
|
947
|
+
this.parseAsync = this.parseAsync.bind(this);
|
|
948
|
+
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
949
|
+
this.spa = this.spa.bind(this);
|
|
950
|
+
this.refine = this.refine.bind(this);
|
|
951
|
+
this.refinement = this.refinement.bind(this);
|
|
952
|
+
this.superRefine = this.superRefine.bind(this);
|
|
953
|
+
this.optional = this.optional.bind(this);
|
|
954
|
+
this.nullable = this.nullable.bind(this);
|
|
955
|
+
this.nullish = this.nullish.bind(this);
|
|
956
|
+
this.array = this.array.bind(this);
|
|
957
|
+
this.promise = this.promise.bind(this);
|
|
958
|
+
this.or = this.or.bind(this);
|
|
959
|
+
this.and = this.and.bind(this);
|
|
960
|
+
this.transform = this.transform.bind(this);
|
|
961
|
+
this.brand = this.brand.bind(this);
|
|
962
|
+
this.default = this.default.bind(this);
|
|
963
|
+
this.catch = this.catch.bind(this);
|
|
964
|
+
this.describe = this.describe.bind(this);
|
|
965
|
+
this.pipe = this.pipe.bind(this);
|
|
966
|
+
this.readonly = this.readonly.bind(this);
|
|
967
|
+
this.isNullable = this.isNullable.bind(this);
|
|
968
|
+
this.isOptional = this.isOptional.bind(this);
|
|
969
|
+
this["~standard"] = {
|
|
970
|
+
version: 1,
|
|
971
|
+
vendor: "zod",
|
|
972
|
+
validate: (data) => this["~validate"](data)
|
|
973
|
+
};
|
|
974
|
+
}
|
|
975
|
+
optional() {
|
|
976
|
+
return ZodOptional.create(this, this._def);
|
|
977
|
+
}
|
|
978
|
+
nullable() {
|
|
979
|
+
return ZodNullable.create(this, this._def);
|
|
980
|
+
}
|
|
981
|
+
nullish() {
|
|
982
|
+
return this.nullable().optional();
|
|
983
|
+
}
|
|
984
|
+
array() {
|
|
985
|
+
return ZodArray.create(this);
|
|
986
|
+
}
|
|
987
|
+
promise() {
|
|
988
|
+
return ZodPromise.create(this, this._def);
|
|
989
|
+
}
|
|
990
|
+
or(option) {
|
|
991
|
+
return ZodUnion.create([
|
|
992
|
+
this,
|
|
993
|
+
option
|
|
994
|
+
], this._def);
|
|
995
|
+
}
|
|
996
|
+
and(incoming) {
|
|
997
|
+
return ZodIntersection.create(this, incoming, this._def);
|
|
998
|
+
}
|
|
999
|
+
transform(transform) {
|
|
1000
|
+
return new ZodEffects({
|
|
1001
|
+
...processCreateParams(this._def),
|
|
1002
|
+
schema: this,
|
|
1003
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
1004
|
+
effect: {
|
|
1005
|
+
type: "transform",
|
|
1006
|
+
transform
|
|
1007
|
+
}
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
default(def) {
|
|
1011
|
+
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
1012
|
+
return new ZodDefault({
|
|
1013
|
+
...processCreateParams(this._def),
|
|
1014
|
+
innerType: this,
|
|
1015
|
+
defaultValue: defaultValueFunc,
|
|
1016
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
brand() {
|
|
1020
|
+
return new ZodBranded({
|
|
1021
|
+
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
1022
|
+
type: this,
|
|
1023
|
+
...processCreateParams(this._def)
|
|
1024
|
+
});
|
|
1025
|
+
}
|
|
1026
|
+
catch(def) {
|
|
1027
|
+
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
1028
|
+
return new ZodCatch({
|
|
1029
|
+
...processCreateParams(this._def),
|
|
1030
|
+
innerType: this,
|
|
1031
|
+
catchValue: catchValueFunc,
|
|
1032
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
1033
|
+
});
|
|
1034
|
+
}
|
|
1035
|
+
describe(description) {
|
|
1036
|
+
const This = this.constructor;
|
|
1037
|
+
return new This({
|
|
1038
|
+
...this._def,
|
|
1039
|
+
description
|
|
1040
|
+
});
|
|
1041
|
+
}
|
|
1042
|
+
pipe(target) {
|
|
1043
|
+
return ZodPipeline.create(this, target);
|
|
1044
|
+
}
|
|
1045
|
+
readonly() {
|
|
1046
|
+
return ZodReadonly.create(this);
|
|
1047
|
+
}
|
|
1048
|
+
isOptional() {
|
|
1049
|
+
return this.safeParse(void 0).success;
|
|
1050
|
+
}
|
|
1051
|
+
isNullable() {
|
|
1052
|
+
return this.safeParse(null).success;
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
__name(_ZodType, "ZodType");
|
|
1056
|
+
var ZodType = _ZodType;
|
|
1057
|
+
var cuidRegex = /^c[^\s-]{8,}$/i;
|
|
1058
|
+
var cuid2Regex = /^[0-9a-z]+$/;
|
|
1059
|
+
var ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/i;
|
|
1060
|
+
var uuidRegex = /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i;
|
|
1061
|
+
var nanoidRegex = /^[a-z0-9_-]{21}$/i;
|
|
1062
|
+
var jwtRegex = /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/;
|
|
1063
|
+
var durationRegex = /^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/;
|
|
1064
|
+
var emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
1065
|
+
var _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
1066
|
+
var emojiRegex;
|
|
1067
|
+
var ipv4Regex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
1068
|
+
var ipv4CidrRegex = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/;
|
|
1069
|
+
var ipv6Regex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/;
|
|
1070
|
+
var ipv6CidrRegex = /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
1071
|
+
var base64Regex = /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/;
|
|
1072
|
+
var base64urlRegex = /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/;
|
|
1073
|
+
var dateRegexSource = `((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))`;
|
|
1074
|
+
var dateRegex = new RegExp(`^${dateRegexSource}$`);
|
|
1075
|
+
function timeRegexSource(args) {
|
|
1076
|
+
let secondsRegexSource = `[0-5]\\d`;
|
|
1077
|
+
if (args.precision) {
|
|
1078
|
+
secondsRegexSource = `${secondsRegexSource}\\.\\d{${args.precision}}`;
|
|
1079
|
+
} else if (args.precision == null) {
|
|
1080
|
+
secondsRegexSource = `${secondsRegexSource}(\\.\\d+)?`;
|
|
1081
|
+
}
|
|
1082
|
+
const secondsQuantifier = args.precision ? "+" : "?";
|
|
1083
|
+
return `([01]\\d|2[0-3]):[0-5]\\d(:${secondsRegexSource})${secondsQuantifier}`;
|
|
1084
|
+
}
|
|
1085
|
+
__name(timeRegexSource, "timeRegexSource");
|
|
1086
|
+
function timeRegex(args) {
|
|
1087
|
+
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
1088
|
+
}
|
|
1089
|
+
__name(timeRegex, "timeRegex");
|
|
1090
|
+
function datetimeRegex(args) {
|
|
1091
|
+
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
1092
|
+
const opts = [];
|
|
1093
|
+
opts.push(args.local ? `Z?` : `Z`);
|
|
1094
|
+
if (args.offset)
|
|
1095
|
+
opts.push(`([+-]\\d{2}:?\\d{2})`);
|
|
1096
|
+
regex = `${regex}(${opts.join("|")})`;
|
|
1097
|
+
return new RegExp(`^${regex}$`);
|
|
1098
|
+
}
|
|
1099
|
+
__name(datetimeRegex, "datetimeRegex");
|
|
1100
|
+
function isValidIP(ip, version) {
|
|
1101
|
+
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
1102
|
+
return true;
|
|
1103
|
+
}
|
|
1104
|
+
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
1105
|
+
return true;
|
|
1106
|
+
}
|
|
1107
|
+
return false;
|
|
1108
|
+
}
|
|
1109
|
+
__name(isValidIP, "isValidIP");
|
|
1110
|
+
function isValidJWT(jwt, alg) {
|
|
1111
|
+
if (!jwtRegex.test(jwt))
|
|
1112
|
+
return false;
|
|
1113
|
+
try {
|
|
1114
|
+
const [header] = jwt.split(".");
|
|
1115
|
+
if (!header)
|
|
1116
|
+
return false;
|
|
1117
|
+
const base64 = header.replace(/-/g, "+").replace(/_/g, "/").padEnd(header.length + (4 - header.length % 4) % 4, "=");
|
|
1118
|
+
const decoded = JSON.parse(atob(base64));
|
|
1119
|
+
if (typeof decoded !== "object" || decoded === null)
|
|
1120
|
+
return false;
|
|
1121
|
+
if ("typ" in decoded && decoded?.typ !== "JWT")
|
|
1122
|
+
return false;
|
|
1123
|
+
if (!decoded.alg)
|
|
1124
|
+
return false;
|
|
1125
|
+
if (alg && decoded.alg !== alg)
|
|
1126
|
+
return false;
|
|
1127
|
+
return true;
|
|
1128
|
+
} catch {
|
|
1129
|
+
return false;
|
|
1130
|
+
}
|
|
1131
|
+
}
|
|
1132
|
+
__name(isValidJWT, "isValidJWT");
|
|
1133
|
+
function isValidCidr(ip, version) {
|
|
1134
|
+
if ((version === "v4" || !version) && ipv4CidrRegex.test(ip)) {
|
|
1135
|
+
return true;
|
|
1136
|
+
}
|
|
1137
|
+
if ((version === "v6" || !version) && ipv6CidrRegex.test(ip)) {
|
|
1138
|
+
return true;
|
|
1139
|
+
}
|
|
1140
|
+
return false;
|
|
1141
|
+
}
|
|
1142
|
+
__name(isValidCidr, "isValidCidr");
|
|
1143
|
+
var _ZodString = class _ZodString extends ZodType {
|
|
1144
|
+
_parse(input) {
|
|
1145
|
+
if (this._def.coerce) {
|
|
1146
|
+
input.data = String(input.data);
|
|
1147
|
+
}
|
|
1148
|
+
const parsedType = this._getType(input);
|
|
1149
|
+
if (parsedType !== ZodParsedType.string) {
|
|
1150
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1151
|
+
addIssueToContext(ctx2, {
|
|
1152
|
+
code: ZodIssueCode.invalid_type,
|
|
1153
|
+
expected: ZodParsedType.string,
|
|
1154
|
+
received: ctx2.parsedType
|
|
1155
|
+
});
|
|
1156
|
+
return INVALID;
|
|
1157
|
+
}
|
|
1158
|
+
const status = new ParseStatus();
|
|
1159
|
+
let ctx = void 0;
|
|
1160
|
+
for (const check of this._def.checks) {
|
|
1161
|
+
if (check.kind === "min") {
|
|
1162
|
+
if (input.data.length < check.value) {
|
|
1163
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1164
|
+
addIssueToContext(ctx, {
|
|
1165
|
+
code: ZodIssueCode.too_small,
|
|
1166
|
+
minimum: check.value,
|
|
1167
|
+
type: "string",
|
|
1168
|
+
inclusive: true,
|
|
1169
|
+
exact: false,
|
|
1170
|
+
message: check.message
|
|
1171
|
+
});
|
|
1172
|
+
status.dirty();
|
|
1173
|
+
}
|
|
1174
|
+
} else if (check.kind === "max") {
|
|
1175
|
+
if (input.data.length > check.value) {
|
|
1176
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1177
|
+
addIssueToContext(ctx, {
|
|
1178
|
+
code: ZodIssueCode.too_big,
|
|
1179
|
+
maximum: check.value,
|
|
1180
|
+
type: "string",
|
|
1181
|
+
inclusive: true,
|
|
1182
|
+
exact: false,
|
|
1183
|
+
message: check.message
|
|
1184
|
+
});
|
|
1185
|
+
status.dirty();
|
|
1186
|
+
}
|
|
1187
|
+
} else if (check.kind === "length") {
|
|
1188
|
+
const tooBig = input.data.length > check.value;
|
|
1189
|
+
const tooSmall = input.data.length < check.value;
|
|
1190
|
+
if (tooBig || tooSmall) {
|
|
1191
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1192
|
+
if (tooBig) {
|
|
1193
|
+
addIssueToContext(ctx, {
|
|
1194
|
+
code: ZodIssueCode.too_big,
|
|
1195
|
+
maximum: check.value,
|
|
1196
|
+
type: "string",
|
|
1197
|
+
inclusive: true,
|
|
1198
|
+
exact: true,
|
|
1199
|
+
message: check.message
|
|
1200
|
+
});
|
|
1201
|
+
} else if (tooSmall) {
|
|
1202
|
+
addIssueToContext(ctx, {
|
|
1203
|
+
code: ZodIssueCode.too_small,
|
|
1204
|
+
minimum: check.value,
|
|
1205
|
+
type: "string",
|
|
1206
|
+
inclusive: true,
|
|
1207
|
+
exact: true,
|
|
1208
|
+
message: check.message
|
|
1209
|
+
});
|
|
1210
|
+
}
|
|
1211
|
+
status.dirty();
|
|
1212
|
+
}
|
|
1213
|
+
} else if (check.kind === "email") {
|
|
1214
|
+
if (!emailRegex.test(input.data)) {
|
|
1215
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1216
|
+
addIssueToContext(ctx, {
|
|
1217
|
+
validation: "email",
|
|
1218
|
+
code: ZodIssueCode.invalid_string,
|
|
1219
|
+
message: check.message
|
|
1220
|
+
});
|
|
1221
|
+
status.dirty();
|
|
1222
|
+
}
|
|
1223
|
+
} else if (check.kind === "emoji") {
|
|
1224
|
+
if (!emojiRegex) {
|
|
1225
|
+
emojiRegex = new RegExp(_emojiRegex, "u");
|
|
1226
|
+
}
|
|
1227
|
+
if (!emojiRegex.test(input.data)) {
|
|
1228
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1229
|
+
addIssueToContext(ctx, {
|
|
1230
|
+
validation: "emoji",
|
|
1231
|
+
code: ZodIssueCode.invalid_string,
|
|
1232
|
+
message: check.message
|
|
1233
|
+
});
|
|
1234
|
+
status.dirty();
|
|
1235
|
+
}
|
|
1236
|
+
} else if (check.kind === "uuid") {
|
|
1237
|
+
if (!uuidRegex.test(input.data)) {
|
|
1238
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1239
|
+
addIssueToContext(ctx, {
|
|
1240
|
+
validation: "uuid",
|
|
1241
|
+
code: ZodIssueCode.invalid_string,
|
|
1242
|
+
message: check.message
|
|
1243
|
+
});
|
|
1244
|
+
status.dirty();
|
|
1245
|
+
}
|
|
1246
|
+
} else if (check.kind === "nanoid") {
|
|
1247
|
+
if (!nanoidRegex.test(input.data)) {
|
|
1248
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1249
|
+
addIssueToContext(ctx, {
|
|
1250
|
+
validation: "nanoid",
|
|
1251
|
+
code: ZodIssueCode.invalid_string,
|
|
1252
|
+
message: check.message
|
|
1253
|
+
});
|
|
1254
|
+
status.dirty();
|
|
1255
|
+
}
|
|
1256
|
+
} else if (check.kind === "cuid") {
|
|
1257
|
+
if (!cuidRegex.test(input.data)) {
|
|
1258
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1259
|
+
addIssueToContext(ctx, {
|
|
1260
|
+
validation: "cuid",
|
|
1261
|
+
code: ZodIssueCode.invalid_string,
|
|
1262
|
+
message: check.message
|
|
1263
|
+
});
|
|
1264
|
+
status.dirty();
|
|
1265
|
+
}
|
|
1266
|
+
} else if (check.kind === "cuid2") {
|
|
1267
|
+
if (!cuid2Regex.test(input.data)) {
|
|
1268
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1269
|
+
addIssueToContext(ctx, {
|
|
1270
|
+
validation: "cuid2",
|
|
1271
|
+
code: ZodIssueCode.invalid_string,
|
|
1272
|
+
message: check.message
|
|
1273
|
+
});
|
|
1274
|
+
status.dirty();
|
|
1275
|
+
}
|
|
1276
|
+
} else if (check.kind === "ulid") {
|
|
1277
|
+
if (!ulidRegex.test(input.data)) {
|
|
1278
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1279
|
+
addIssueToContext(ctx, {
|
|
1280
|
+
validation: "ulid",
|
|
1281
|
+
code: ZodIssueCode.invalid_string,
|
|
1282
|
+
message: check.message
|
|
1283
|
+
});
|
|
1284
|
+
status.dirty();
|
|
1285
|
+
}
|
|
1286
|
+
} else if (check.kind === "url") {
|
|
1287
|
+
try {
|
|
1288
|
+
new URL(input.data);
|
|
1289
|
+
} catch {
|
|
1290
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1291
|
+
addIssueToContext(ctx, {
|
|
1292
|
+
validation: "url",
|
|
1293
|
+
code: ZodIssueCode.invalid_string,
|
|
1294
|
+
message: check.message
|
|
1295
|
+
});
|
|
1296
|
+
status.dirty();
|
|
1297
|
+
}
|
|
1298
|
+
} else if (check.kind === "regex") {
|
|
1299
|
+
check.regex.lastIndex = 0;
|
|
1300
|
+
const testResult = check.regex.test(input.data);
|
|
1301
|
+
if (!testResult) {
|
|
1302
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1303
|
+
addIssueToContext(ctx, {
|
|
1304
|
+
validation: "regex",
|
|
1305
|
+
code: ZodIssueCode.invalid_string,
|
|
1306
|
+
message: check.message
|
|
1307
|
+
});
|
|
1308
|
+
status.dirty();
|
|
1309
|
+
}
|
|
1310
|
+
} else if (check.kind === "trim") {
|
|
1311
|
+
input.data = input.data.trim();
|
|
1312
|
+
} else if (check.kind === "includes") {
|
|
1313
|
+
if (!input.data.includes(check.value, check.position)) {
|
|
1314
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1315
|
+
addIssueToContext(ctx, {
|
|
1316
|
+
code: ZodIssueCode.invalid_string,
|
|
1317
|
+
validation: {
|
|
1318
|
+
includes: check.value,
|
|
1319
|
+
position: check.position
|
|
1320
|
+
},
|
|
1321
|
+
message: check.message
|
|
1322
|
+
});
|
|
1323
|
+
status.dirty();
|
|
1324
|
+
}
|
|
1325
|
+
} else if (check.kind === "toLowerCase") {
|
|
1326
|
+
input.data = input.data.toLowerCase();
|
|
1327
|
+
} else if (check.kind === "toUpperCase") {
|
|
1328
|
+
input.data = input.data.toUpperCase();
|
|
1329
|
+
} else if (check.kind === "startsWith") {
|
|
1330
|
+
if (!input.data.startsWith(check.value)) {
|
|
1331
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1332
|
+
addIssueToContext(ctx, {
|
|
1333
|
+
code: ZodIssueCode.invalid_string,
|
|
1334
|
+
validation: {
|
|
1335
|
+
startsWith: check.value
|
|
1336
|
+
},
|
|
1337
|
+
message: check.message
|
|
1338
|
+
});
|
|
1339
|
+
status.dirty();
|
|
1340
|
+
}
|
|
1341
|
+
} else if (check.kind === "endsWith") {
|
|
1342
|
+
if (!input.data.endsWith(check.value)) {
|
|
1343
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1344
|
+
addIssueToContext(ctx, {
|
|
1345
|
+
code: ZodIssueCode.invalid_string,
|
|
1346
|
+
validation: {
|
|
1347
|
+
endsWith: check.value
|
|
1348
|
+
},
|
|
1349
|
+
message: check.message
|
|
1350
|
+
});
|
|
1351
|
+
status.dirty();
|
|
1352
|
+
}
|
|
1353
|
+
} else if (check.kind === "datetime") {
|
|
1354
|
+
const regex = datetimeRegex(check);
|
|
1355
|
+
if (!regex.test(input.data)) {
|
|
1356
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1357
|
+
addIssueToContext(ctx, {
|
|
1358
|
+
code: ZodIssueCode.invalid_string,
|
|
1359
|
+
validation: "datetime",
|
|
1360
|
+
message: check.message
|
|
1361
|
+
});
|
|
1362
|
+
status.dirty();
|
|
1363
|
+
}
|
|
1364
|
+
} else if (check.kind === "date") {
|
|
1365
|
+
const regex = dateRegex;
|
|
1366
|
+
if (!regex.test(input.data)) {
|
|
1367
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1368
|
+
addIssueToContext(ctx, {
|
|
1369
|
+
code: ZodIssueCode.invalid_string,
|
|
1370
|
+
validation: "date",
|
|
1371
|
+
message: check.message
|
|
1372
|
+
});
|
|
1373
|
+
status.dirty();
|
|
1374
|
+
}
|
|
1375
|
+
} else if (check.kind === "time") {
|
|
1376
|
+
const regex = timeRegex(check);
|
|
1377
|
+
if (!regex.test(input.data)) {
|
|
1378
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1379
|
+
addIssueToContext(ctx, {
|
|
1380
|
+
code: ZodIssueCode.invalid_string,
|
|
1381
|
+
validation: "time",
|
|
1382
|
+
message: check.message
|
|
1383
|
+
});
|
|
1384
|
+
status.dirty();
|
|
1385
|
+
}
|
|
1386
|
+
} else if (check.kind === "duration") {
|
|
1387
|
+
if (!durationRegex.test(input.data)) {
|
|
1388
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1389
|
+
addIssueToContext(ctx, {
|
|
1390
|
+
validation: "duration",
|
|
1391
|
+
code: ZodIssueCode.invalid_string,
|
|
1392
|
+
message: check.message
|
|
1393
|
+
});
|
|
1394
|
+
status.dirty();
|
|
1395
|
+
}
|
|
1396
|
+
} else if (check.kind === "ip") {
|
|
1397
|
+
if (!isValidIP(input.data, check.version)) {
|
|
1398
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1399
|
+
addIssueToContext(ctx, {
|
|
1400
|
+
validation: "ip",
|
|
1401
|
+
code: ZodIssueCode.invalid_string,
|
|
1402
|
+
message: check.message
|
|
1403
|
+
});
|
|
1404
|
+
status.dirty();
|
|
1405
|
+
}
|
|
1406
|
+
} else if (check.kind === "jwt") {
|
|
1407
|
+
if (!isValidJWT(input.data, check.alg)) {
|
|
1408
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1409
|
+
addIssueToContext(ctx, {
|
|
1410
|
+
validation: "jwt",
|
|
1411
|
+
code: ZodIssueCode.invalid_string,
|
|
1412
|
+
message: check.message
|
|
1413
|
+
});
|
|
1414
|
+
status.dirty();
|
|
1415
|
+
}
|
|
1416
|
+
} else if (check.kind === "cidr") {
|
|
1417
|
+
if (!isValidCidr(input.data, check.version)) {
|
|
1418
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1419
|
+
addIssueToContext(ctx, {
|
|
1420
|
+
validation: "cidr",
|
|
1421
|
+
code: ZodIssueCode.invalid_string,
|
|
1422
|
+
message: check.message
|
|
1423
|
+
});
|
|
1424
|
+
status.dirty();
|
|
1425
|
+
}
|
|
1426
|
+
} else if (check.kind === "base64") {
|
|
1427
|
+
if (!base64Regex.test(input.data)) {
|
|
1428
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1429
|
+
addIssueToContext(ctx, {
|
|
1430
|
+
validation: "base64",
|
|
1431
|
+
code: ZodIssueCode.invalid_string,
|
|
1432
|
+
message: check.message
|
|
1433
|
+
});
|
|
1434
|
+
status.dirty();
|
|
1435
|
+
}
|
|
1436
|
+
} else if (check.kind === "base64url") {
|
|
1437
|
+
if (!base64urlRegex.test(input.data)) {
|
|
1438
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1439
|
+
addIssueToContext(ctx, {
|
|
1440
|
+
validation: "base64url",
|
|
1441
|
+
code: ZodIssueCode.invalid_string,
|
|
1442
|
+
message: check.message
|
|
1443
|
+
});
|
|
1444
|
+
status.dirty();
|
|
1445
|
+
}
|
|
1446
|
+
} else {
|
|
1447
|
+
util.assertNever(check);
|
|
1448
|
+
}
|
|
1449
|
+
}
|
|
1450
|
+
return {
|
|
1451
|
+
status: status.value,
|
|
1452
|
+
value: input.data
|
|
1453
|
+
};
|
|
1454
|
+
}
|
|
1455
|
+
_regex(regex, validation, message) {
|
|
1456
|
+
return this.refinement((data) => regex.test(data), {
|
|
1457
|
+
validation,
|
|
1458
|
+
code: ZodIssueCode.invalid_string,
|
|
1459
|
+
...errorUtil.errToObj(message)
|
|
1460
|
+
});
|
|
1461
|
+
}
|
|
1462
|
+
_addCheck(check) {
|
|
1463
|
+
return new _ZodString({
|
|
1464
|
+
...this._def,
|
|
1465
|
+
checks: [
|
|
1466
|
+
...this._def.checks,
|
|
1467
|
+
check
|
|
1468
|
+
]
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
email(message) {
|
|
1472
|
+
return this._addCheck({
|
|
1473
|
+
kind: "email",
|
|
1474
|
+
...errorUtil.errToObj(message)
|
|
1475
|
+
});
|
|
1476
|
+
}
|
|
1477
|
+
url(message) {
|
|
1478
|
+
return this._addCheck({
|
|
1479
|
+
kind: "url",
|
|
1480
|
+
...errorUtil.errToObj(message)
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1483
|
+
emoji(message) {
|
|
1484
|
+
return this._addCheck({
|
|
1485
|
+
kind: "emoji",
|
|
1486
|
+
...errorUtil.errToObj(message)
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
uuid(message) {
|
|
1490
|
+
return this._addCheck({
|
|
1491
|
+
kind: "uuid",
|
|
1492
|
+
...errorUtil.errToObj(message)
|
|
1493
|
+
});
|
|
1494
|
+
}
|
|
1495
|
+
nanoid(message) {
|
|
1496
|
+
return this._addCheck({
|
|
1497
|
+
kind: "nanoid",
|
|
1498
|
+
...errorUtil.errToObj(message)
|
|
1499
|
+
});
|
|
1500
|
+
}
|
|
1501
|
+
cuid(message) {
|
|
1502
|
+
return this._addCheck({
|
|
1503
|
+
kind: "cuid",
|
|
1504
|
+
...errorUtil.errToObj(message)
|
|
1505
|
+
});
|
|
1506
|
+
}
|
|
1507
|
+
cuid2(message) {
|
|
1508
|
+
return this._addCheck({
|
|
1509
|
+
kind: "cuid2",
|
|
1510
|
+
...errorUtil.errToObj(message)
|
|
1511
|
+
});
|
|
1512
|
+
}
|
|
1513
|
+
ulid(message) {
|
|
1514
|
+
return this._addCheck({
|
|
1515
|
+
kind: "ulid",
|
|
1516
|
+
...errorUtil.errToObj(message)
|
|
1517
|
+
});
|
|
1518
|
+
}
|
|
1519
|
+
base64(message) {
|
|
1520
|
+
return this._addCheck({
|
|
1521
|
+
kind: "base64",
|
|
1522
|
+
...errorUtil.errToObj(message)
|
|
1523
|
+
});
|
|
1524
|
+
}
|
|
1525
|
+
base64url(message) {
|
|
1526
|
+
return this._addCheck({
|
|
1527
|
+
kind: "base64url",
|
|
1528
|
+
...errorUtil.errToObj(message)
|
|
1529
|
+
});
|
|
1530
|
+
}
|
|
1531
|
+
jwt(options) {
|
|
1532
|
+
return this._addCheck({
|
|
1533
|
+
kind: "jwt",
|
|
1534
|
+
...errorUtil.errToObj(options)
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
ip(options) {
|
|
1538
|
+
return this._addCheck({
|
|
1539
|
+
kind: "ip",
|
|
1540
|
+
...errorUtil.errToObj(options)
|
|
1541
|
+
});
|
|
1542
|
+
}
|
|
1543
|
+
cidr(options) {
|
|
1544
|
+
return this._addCheck({
|
|
1545
|
+
kind: "cidr",
|
|
1546
|
+
...errorUtil.errToObj(options)
|
|
1547
|
+
});
|
|
1548
|
+
}
|
|
1549
|
+
datetime(options) {
|
|
1550
|
+
if (typeof options === "string") {
|
|
1551
|
+
return this._addCheck({
|
|
1552
|
+
kind: "datetime",
|
|
1553
|
+
precision: null,
|
|
1554
|
+
offset: false,
|
|
1555
|
+
local: false,
|
|
1556
|
+
message: options
|
|
1557
|
+
});
|
|
1558
|
+
}
|
|
1559
|
+
return this._addCheck({
|
|
1560
|
+
kind: "datetime",
|
|
1561
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1562
|
+
offset: options?.offset ?? false,
|
|
1563
|
+
local: options?.local ?? false,
|
|
1564
|
+
...errorUtil.errToObj(options?.message)
|
|
1565
|
+
});
|
|
1566
|
+
}
|
|
1567
|
+
date(message) {
|
|
1568
|
+
return this._addCheck({
|
|
1569
|
+
kind: "date",
|
|
1570
|
+
message
|
|
1571
|
+
});
|
|
1572
|
+
}
|
|
1573
|
+
time(options) {
|
|
1574
|
+
if (typeof options === "string") {
|
|
1575
|
+
return this._addCheck({
|
|
1576
|
+
kind: "time",
|
|
1577
|
+
precision: null,
|
|
1578
|
+
message: options
|
|
1579
|
+
});
|
|
1580
|
+
}
|
|
1581
|
+
return this._addCheck({
|
|
1582
|
+
kind: "time",
|
|
1583
|
+
precision: typeof options?.precision === "undefined" ? null : options?.precision,
|
|
1584
|
+
...errorUtil.errToObj(options?.message)
|
|
1585
|
+
});
|
|
1586
|
+
}
|
|
1587
|
+
duration(message) {
|
|
1588
|
+
return this._addCheck({
|
|
1589
|
+
kind: "duration",
|
|
1590
|
+
...errorUtil.errToObj(message)
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
regex(regex, message) {
|
|
1594
|
+
return this._addCheck({
|
|
1595
|
+
kind: "regex",
|
|
1596
|
+
regex,
|
|
1597
|
+
...errorUtil.errToObj(message)
|
|
1598
|
+
});
|
|
1599
|
+
}
|
|
1600
|
+
includes(value, options) {
|
|
1601
|
+
return this._addCheck({
|
|
1602
|
+
kind: "includes",
|
|
1603
|
+
value,
|
|
1604
|
+
position: options?.position,
|
|
1605
|
+
...errorUtil.errToObj(options?.message)
|
|
1606
|
+
});
|
|
1607
|
+
}
|
|
1608
|
+
startsWith(value, message) {
|
|
1609
|
+
return this._addCheck({
|
|
1610
|
+
kind: "startsWith",
|
|
1611
|
+
value,
|
|
1612
|
+
...errorUtil.errToObj(message)
|
|
1613
|
+
});
|
|
1614
|
+
}
|
|
1615
|
+
endsWith(value, message) {
|
|
1616
|
+
return this._addCheck({
|
|
1617
|
+
kind: "endsWith",
|
|
1618
|
+
value,
|
|
1619
|
+
...errorUtil.errToObj(message)
|
|
1620
|
+
});
|
|
1621
|
+
}
|
|
1622
|
+
min(minLength, message) {
|
|
1623
|
+
return this._addCheck({
|
|
1624
|
+
kind: "min",
|
|
1625
|
+
value: minLength,
|
|
1626
|
+
...errorUtil.errToObj(message)
|
|
1627
|
+
});
|
|
1628
|
+
}
|
|
1629
|
+
max(maxLength, message) {
|
|
1630
|
+
return this._addCheck({
|
|
1631
|
+
kind: "max",
|
|
1632
|
+
value: maxLength,
|
|
1633
|
+
...errorUtil.errToObj(message)
|
|
1634
|
+
});
|
|
1635
|
+
}
|
|
1636
|
+
length(len, message) {
|
|
1637
|
+
return this._addCheck({
|
|
1638
|
+
kind: "length",
|
|
1639
|
+
value: len,
|
|
1640
|
+
...errorUtil.errToObj(message)
|
|
1641
|
+
});
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Equivalent to `.min(1)`
|
|
1645
|
+
*/
|
|
1646
|
+
nonempty(message) {
|
|
1647
|
+
return this.min(1, errorUtil.errToObj(message));
|
|
1648
|
+
}
|
|
1649
|
+
trim() {
|
|
1650
|
+
return new _ZodString({
|
|
1651
|
+
...this._def,
|
|
1652
|
+
checks: [
|
|
1653
|
+
...this._def.checks,
|
|
1654
|
+
{
|
|
1655
|
+
kind: "trim"
|
|
1656
|
+
}
|
|
1657
|
+
]
|
|
1658
|
+
});
|
|
1659
|
+
}
|
|
1660
|
+
toLowerCase() {
|
|
1661
|
+
return new _ZodString({
|
|
1662
|
+
...this._def,
|
|
1663
|
+
checks: [
|
|
1664
|
+
...this._def.checks,
|
|
1665
|
+
{
|
|
1666
|
+
kind: "toLowerCase"
|
|
1667
|
+
}
|
|
1668
|
+
]
|
|
1669
|
+
});
|
|
1670
|
+
}
|
|
1671
|
+
toUpperCase() {
|
|
1672
|
+
return new _ZodString({
|
|
1673
|
+
...this._def,
|
|
1674
|
+
checks: [
|
|
1675
|
+
...this._def.checks,
|
|
1676
|
+
{
|
|
1677
|
+
kind: "toUpperCase"
|
|
1678
|
+
}
|
|
1679
|
+
]
|
|
1680
|
+
});
|
|
1681
|
+
}
|
|
1682
|
+
get isDatetime() {
|
|
1683
|
+
return !!this._def.checks.find((ch) => ch.kind === "datetime");
|
|
1684
|
+
}
|
|
1685
|
+
get isDate() {
|
|
1686
|
+
return !!this._def.checks.find((ch) => ch.kind === "date");
|
|
1687
|
+
}
|
|
1688
|
+
get isTime() {
|
|
1689
|
+
return !!this._def.checks.find((ch) => ch.kind === "time");
|
|
1690
|
+
}
|
|
1691
|
+
get isDuration() {
|
|
1692
|
+
return !!this._def.checks.find((ch) => ch.kind === "duration");
|
|
1693
|
+
}
|
|
1694
|
+
get isEmail() {
|
|
1695
|
+
return !!this._def.checks.find((ch) => ch.kind === "email");
|
|
1696
|
+
}
|
|
1697
|
+
get isURL() {
|
|
1698
|
+
return !!this._def.checks.find((ch) => ch.kind === "url");
|
|
1699
|
+
}
|
|
1700
|
+
get isEmoji() {
|
|
1701
|
+
return !!this._def.checks.find((ch) => ch.kind === "emoji");
|
|
1702
|
+
}
|
|
1703
|
+
get isUUID() {
|
|
1704
|
+
return !!this._def.checks.find((ch) => ch.kind === "uuid");
|
|
1705
|
+
}
|
|
1706
|
+
get isNANOID() {
|
|
1707
|
+
return !!this._def.checks.find((ch) => ch.kind === "nanoid");
|
|
1708
|
+
}
|
|
1709
|
+
get isCUID() {
|
|
1710
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid");
|
|
1711
|
+
}
|
|
1712
|
+
get isCUID2() {
|
|
1713
|
+
return !!this._def.checks.find((ch) => ch.kind === "cuid2");
|
|
1714
|
+
}
|
|
1715
|
+
get isULID() {
|
|
1716
|
+
return !!this._def.checks.find((ch) => ch.kind === "ulid");
|
|
1717
|
+
}
|
|
1718
|
+
get isIP() {
|
|
1719
|
+
return !!this._def.checks.find((ch) => ch.kind === "ip");
|
|
1720
|
+
}
|
|
1721
|
+
get isCIDR() {
|
|
1722
|
+
return !!this._def.checks.find((ch) => ch.kind === "cidr");
|
|
1723
|
+
}
|
|
1724
|
+
get isBase64() {
|
|
1725
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64");
|
|
1726
|
+
}
|
|
1727
|
+
get isBase64url() {
|
|
1728
|
+
return !!this._def.checks.find((ch) => ch.kind === "base64url");
|
|
1729
|
+
}
|
|
1730
|
+
get minLength() {
|
|
1731
|
+
let min = null;
|
|
1732
|
+
for (const ch of this._def.checks) {
|
|
1733
|
+
if (ch.kind === "min") {
|
|
1734
|
+
if (min === null || ch.value > min)
|
|
1735
|
+
min = ch.value;
|
|
1736
|
+
}
|
|
1737
|
+
}
|
|
1738
|
+
return min;
|
|
1739
|
+
}
|
|
1740
|
+
get maxLength() {
|
|
1741
|
+
let max = null;
|
|
1742
|
+
for (const ch of this._def.checks) {
|
|
1743
|
+
if (ch.kind === "max") {
|
|
1744
|
+
if (max === null || ch.value < max)
|
|
1745
|
+
max = ch.value;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
return max;
|
|
1749
|
+
}
|
|
1750
|
+
};
|
|
1751
|
+
__name(_ZodString, "ZodString");
|
|
1752
|
+
var ZodString = _ZodString;
|
|
1753
|
+
ZodString.create = (params) => {
|
|
1754
|
+
return new ZodString({
|
|
1755
|
+
checks: [],
|
|
1756
|
+
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1757
|
+
coerce: params?.coerce ?? false,
|
|
1758
|
+
...processCreateParams(params)
|
|
1759
|
+
});
|
|
1760
|
+
};
|
|
1761
|
+
function floatSafeRemainder(val, step) {
|
|
1762
|
+
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1763
|
+
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1764
|
+
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1765
|
+
const valInt = Number.parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1766
|
+
const stepInt = Number.parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1767
|
+
return valInt % stepInt / 10 ** decCount;
|
|
1768
|
+
}
|
|
1769
|
+
__name(floatSafeRemainder, "floatSafeRemainder");
|
|
1770
|
+
var _ZodNumber = class _ZodNumber extends ZodType {
|
|
1771
|
+
constructor() {
|
|
1772
|
+
super(...arguments);
|
|
1773
|
+
this.min = this.gte;
|
|
1774
|
+
this.max = this.lte;
|
|
1775
|
+
this.step = this.multipleOf;
|
|
1776
|
+
}
|
|
1777
|
+
_parse(input) {
|
|
1778
|
+
if (this._def.coerce) {
|
|
1779
|
+
input.data = Number(input.data);
|
|
1780
|
+
}
|
|
1781
|
+
const parsedType = this._getType(input);
|
|
1782
|
+
if (parsedType !== ZodParsedType.number) {
|
|
1783
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
1784
|
+
addIssueToContext(ctx2, {
|
|
1785
|
+
code: ZodIssueCode.invalid_type,
|
|
1786
|
+
expected: ZodParsedType.number,
|
|
1787
|
+
received: ctx2.parsedType
|
|
1788
|
+
});
|
|
1789
|
+
return INVALID;
|
|
1790
|
+
}
|
|
1791
|
+
let ctx = void 0;
|
|
1792
|
+
const status = new ParseStatus();
|
|
1793
|
+
for (const check of this._def.checks) {
|
|
1794
|
+
if (check.kind === "int") {
|
|
1795
|
+
if (!util.isInteger(input.data)) {
|
|
1796
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1797
|
+
addIssueToContext(ctx, {
|
|
1798
|
+
code: ZodIssueCode.invalid_type,
|
|
1799
|
+
expected: "integer",
|
|
1800
|
+
received: "float",
|
|
1801
|
+
message: check.message
|
|
1802
|
+
});
|
|
1803
|
+
status.dirty();
|
|
1804
|
+
}
|
|
1805
|
+
} else if (check.kind === "min") {
|
|
1806
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1807
|
+
if (tooSmall) {
|
|
1808
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1809
|
+
addIssueToContext(ctx, {
|
|
1810
|
+
code: ZodIssueCode.too_small,
|
|
1811
|
+
minimum: check.value,
|
|
1812
|
+
type: "number",
|
|
1813
|
+
inclusive: check.inclusive,
|
|
1814
|
+
exact: false,
|
|
1815
|
+
message: check.message
|
|
1816
|
+
});
|
|
1817
|
+
status.dirty();
|
|
1818
|
+
}
|
|
1819
|
+
} else if (check.kind === "max") {
|
|
1820
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1821
|
+
if (tooBig) {
|
|
1822
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1823
|
+
addIssueToContext(ctx, {
|
|
1824
|
+
code: ZodIssueCode.too_big,
|
|
1825
|
+
maximum: check.value,
|
|
1826
|
+
type: "number",
|
|
1827
|
+
inclusive: check.inclusive,
|
|
1828
|
+
exact: false,
|
|
1829
|
+
message: check.message
|
|
1830
|
+
});
|
|
1831
|
+
status.dirty();
|
|
1832
|
+
}
|
|
1833
|
+
} else if (check.kind === "multipleOf") {
|
|
1834
|
+
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1835
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1836
|
+
addIssueToContext(ctx, {
|
|
1837
|
+
code: ZodIssueCode.not_multiple_of,
|
|
1838
|
+
multipleOf: check.value,
|
|
1839
|
+
message: check.message
|
|
1840
|
+
});
|
|
1841
|
+
status.dirty();
|
|
1842
|
+
}
|
|
1843
|
+
} else if (check.kind === "finite") {
|
|
1844
|
+
if (!Number.isFinite(input.data)) {
|
|
1845
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
1846
|
+
addIssueToContext(ctx, {
|
|
1847
|
+
code: ZodIssueCode.not_finite,
|
|
1848
|
+
message: check.message
|
|
1849
|
+
});
|
|
1850
|
+
status.dirty();
|
|
1851
|
+
}
|
|
1852
|
+
} else {
|
|
1853
|
+
util.assertNever(check);
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
return {
|
|
1857
|
+
status: status.value,
|
|
1858
|
+
value: input.data
|
|
1859
|
+
};
|
|
1860
|
+
}
|
|
1861
|
+
gte(value, message) {
|
|
1862
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1863
|
+
}
|
|
1864
|
+
gt(value, message) {
|
|
1865
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1866
|
+
}
|
|
1867
|
+
lte(value, message) {
|
|
1868
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1869
|
+
}
|
|
1870
|
+
lt(value, message) {
|
|
1871
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1872
|
+
}
|
|
1873
|
+
setLimit(kind, value, inclusive, message) {
|
|
1874
|
+
return new _ZodNumber({
|
|
1875
|
+
...this._def,
|
|
1876
|
+
checks: [
|
|
1877
|
+
...this._def.checks,
|
|
1878
|
+
{
|
|
1879
|
+
kind,
|
|
1880
|
+
value,
|
|
1881
|
+
inclusive,
|
|
1882
|
+
message: errorUtil.toString(message)
|
|
1883
|
+
}
|
|
1884
|
+
]
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
_addCheck(check) {
|
|
1888
|
+
return new _ZodNumber({
|
|
1889
|
+
...this._def,
|
|
1890
|
+
checks: [
|
|
1891
|
+
...this._def.checks,
|
|
1892
|
+
check
|
|
1893
|
+
]
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
int(message) {
|
|
1897
|
+
return this._addCheck({
|
|
1898
|
+
kind: "int",
|
|
1899
|
+
message: errorUtil.toString(message)
|
|
1900
|
+
});
|
|
1901
|
+
}
|
|
1902
|
+
positive(message) {
|
|
1903
|
+
return this._addCheck({
|
|
1904
|
+
kind: "min",
|
|
1905
|
+
value: 0,
|
|
1906
|
+
inclusive: false,
|
|
1907
|
+
message: errorUtil.toString(message)
|
|
1908
|
+
});
|
|
1909
|
+
}
|
|
1910
|
+
negative(message) {
|
|
1911
|
+
return this._addCheck({
|
|
1912
|
+
kind: "max",
|
|
1913
|
+
value: 0,
|
|
1914
|
+
inclusive: false,
|
|
1915
|
+
message: errorUtil.toString(message)
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
nonpositive(message) {
|
|
1919
|
+
return this._addCheck({
|
|
1920
|
+
kind: "max",
|
|
1921
|
+
value: 0,
|
|
1922
|
+
inclusive: true,
|
|
1923
|
+
message: errorUtil.toString(message)
|
|
1924
|
+
});
|
|
1925
|
+
}
|
|
1926
|
+
nonnegative(message) {
|
|
1927
|
+
return this._addCheck({
|
|
1928
|
+
kind: "min",
|
|
1929
|
+
value: 0,
|
|
1930
|
+
inclusive: true,
|
|
1931
|
+
message: errorUtil.toString(message)
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
multipleOf(value, message) {
|
|
1935
|
+
return this._addCheck({
|
|
1936
|
+
kind: "multipleOf",
|
|
1937
|
+
value,
|
|
1938
|
+
message: errorUtil.toString(message)
|
|
1939
|
+
});
|
|
1940
|
+
}
|
|
1941
|
+
finite(message) {
|
|
1942
|
+
return this._addCheck({
|
|
1943
|
+
kind: "finite",
|
|
1944
|
+
message: errorUtil.toString(message)
|
|
1945
|
+
});
|
|
1946
|
+
}
|
|
1947
|
+
safe(message) {
|
|
1948
|
+
return this._addCheck({
|
|
1949
|
+
kind: "min",
|
|
1950
|
+
inclusive: true,
|
|
1951
|
+
value: Number.MIN_SAFE_INTEGER,
|
|
1952
|
+
message: errorUtil.toString(message)
|
|
1953
|
+
})._addCheck({
|
|
1954
|
+
kind: "max",
|
|
1955
|
+
inclusive: true,
|
|
1956
|
+
value: Number.MAX_SAFE_INTEGER,
|
|
1957
|
+
message: errorUtil.toString(message)
|
|
1958
|
+
});
|
|
1959
|
+
}
|
|
1960
|
+
get minValue() {
|
|
1961
|
+
let min = null;
|
|
1962
|
+
for (const ch of this._def.checks) {
|
|
1963
|
+
if (ch.kind === "min") {
|
|
1964
|
+
if (min === null || ch.value > min)
|
|
1965
|
+
min = ch.value;
|
|
1966
|
+
}
|
|
1967
|
+
}
|
|
1968
|
+
return min;
|
|
1969
|
+
}
|
|
1970
|
+
get maxValue() {
|
|
1971
|
+
let max = null;
|
|
1972
|
+
for (const ch of this._def.checks) {
|
|
1973
|
+
if (ch.kind === "max") {
|
|
1974
|
+
if (max === null || ch.value < max)
|
|
1975
|
+
max = ch.value;
|
|
1976
|
+
}
|
|
1977
|
+
}
|
|
1978
|
+
return max;
|
|
1979
|
+
}
|
|
1980
|
+
get isInt() {
|
|
1981
|
+
return !!this._def.checks.find((ch) => ch.kind === "int" || ch.kind === "multipleOf" && util.isInteger(ch.value));
|
|
1982
|
+
}
|
|
1983
|
+
get isFinite() {
|
|
1984
|
+
let max = null;
|
|
1985
|
+
let min = null;
|
|
1986
|
+
for (const ch of this._def.checks) {
|
|
1987
|
+
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1988
|
+
return true;
|
|
1989
|
+
} else if (ch.kind === "min") {
|
|
1990
|
+
if (min === null || ch.value > min)
|
|
1991
|
+
min = ch.value;
|
|
1992
|
+
} else if (ch.kind === "max") {
|
|
1993
|
+
if (max === null || ch.value < max)
|
|
1994
|
+
max = ch.value;
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
return Number.isFinite(min) && Number.isFinite(max);
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
__name(_ZodNumber, "ZodNumber");
|
|
2001
|
+
var ZodNumber = _ZodNumber;
|
|
2002
|
+
ZodNumber.create = (params) => {
|
|
2003
|
+
return new ZodNumber({
|
|
2004
|
+
checks: [],
|
|
2005
|
+
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
2006
|
+
coerce: params?.coerce || false,
|
|
2007
|
+
...processCreateParams(params)
|
|
2008
|
+
});
|
|
2009
|
+
};
|
|
2010
|
+
var _ZodBigInt = class _ZodBigInt extends ZodType {
|
|
2011
|
+
constructor() {
|
|
2012
|
+
super(...arguments);
|
|
2013
|
+
this.min = this.gte;
|
|
2014
|
+
this.max = this.lte;
|
|
2015
|
+
}
|
|
2016
|
+
_parse(input) {
|
|
2017
|
+
if (this._def.coerce) {
|
|
2018
|
+
try {
|
|
2019
|
+
input.data = BigInt(input.data);
|
|
2020
|
+
} catch {
|
|
2021
|
+
return this._getInvalidInput(input);
|
|
2022
|
+
}
|
|
2023
|
+
}
|
|
2024
|
+
const parsedType = this._getType(input);
|
|
2025
|
+
if (parsedType !== ZodParsedType.bigint) {
|
|
2026
|
+
return this._getInvalidInput(input);
|
|
2027
|
+
}
|
|
2028
|
+
let ctx = void 0;
|
|
2029
|
+
const status = new ParseStatus();
|
|
2030
|
+
for (const check of this._def.checks) {
|
|
2031
|
+
if (check.kind === "min") {
|
|
2032
|
+
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
2033
|
+
if (tooSmall) {
|
|
2034
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2035
|
+
addIssueToContext(ctx, {
|
|
2036
|
+
code: ZodIssueCode.too_small,
|
|
2037
|
+
type: "bigint",
|
|
2038
|
+
minimum: check.value,
|
|
2039
|
+
inclusive: check.inclusive,
|
|
2040
|
+
message: check.message
|
|
2041
|
+
});
|
|
2042
|
+
status.dirty();
|
|
2043
|
+
}
|
|
2044
|
+
} else if (check.kind === "max") {
|
|
2045
|
+
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
2046
|
+
if (tooBig) {
|
|
2047
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2048
|
+
addIssueToContext(ctx, {
|
|
2049
|
+
code: ZodIssueCode.too_big,
|
|
2050
|
+
type: "bigint",
|
|
2051
|
+
maximum: check.value,
|
|
2052
|
+
inclusive: check.inclusive,
|
|
2053
|
+
message: check.message
|
|
2054
|
+
});
|
|
2055
|
+
status.dirty();
|
|
2056
|
+
}
|
|
2057
|
+
} else if (check.kind === "multipleOf") {
|
|
2058
|
+
if (input.data % check.value !== BigInt(0)) {
|
|
2059
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2060
|
+
addIssueToContext(ctx, {
|
|
2061
|
+
code: ZodIssueCode.not_multiple_of,
|
|
2062
|
+
multipleOf: check.value,
|
|
2063
|
+
message: check.message
|
|
2064
|
+
});
|
|
2065
|
+
status.dirty();
|
|
2066
|
+
}
|
|
2067
|
+
} else {
|
|
2068
|
+
util.assertNever(check);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
return {
|
|
2072
|
+
status: status.value,
|
|
2073
|
+
value: input.data
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
_getInvalidInput(input) {
|
|
2077
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2078
|
+
addIssueToContext(ctx, {
|
|
2079
|
+
code: ZodIssueCode.invalid_type,
|
|
2080
|
+
expected: ZodParsedType.bigint,
|
|
2081
|
+
received: ctx.parsedType
|
|
2082
|
+
});
|
|
2083
|
+
return INVALID;
|
|
2084
|
+
}
|
|
2085
|
+
gte(value, message) {
|
|
2086
|
+
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
2087
|
+
}
|
|
2088
|
+
gt(value, message) {
|
|
2089
|
+
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
2090
|
+
}
|
|
2091
|
+
lte(value, message) {
|
|
2092
|
+
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
2093
|
+
}
|
|
2094
|
+
lt(value, message) {
|
|
2095
|
+
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
2096
|
+
}
|
|
2097
|
+
setLimit(kind, value, inclusive, message) {
|
|
2098
|
+
return new _ZodBigInt({
|
|
2099
|
+
...this._def,
|
|
2100
|
+
checks: [
|
|
2101
|
+
...this._def.checks,
|
|
2102
|
+
{
|
|
2103
|
+
kind,
|
|
2104
|
+
value,
|
|
2105
|
+
inclusive,
|
|
2106
|
+
message: errorUtil.toString(message)
|
|
2107
|
+
}
|
|
2108
|
+
]
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
_addCheck(check) {
|
|
2112
|
+
return new _ZodBigInt({
|
|
2113
|
+
...this._def,
|
|
2114
|
+
checks: [
|
|
2115
|
+
...this._def.checks,
|
|
2116
|
+
check
|
|
2117
|
+
]
|
|
2118
|
+
});
|
|
2119
|
+
}
|
|
2120
|
+
positive(message) {
|
|
2121
|
+
return this._addCheck({
|
|
2122
|
+
kind: "min",
|
|
2123
|
+
value: BigInt(0),
|
|
2124
|
+
inclusive: false,
|
|
2125
|
+
message: errorUtil.toString(message)
|
|
2126
|
+
});
|
|
2127
|
+
}
|
|
2128
|
+
negative(message) {
|
|
2129
|
+
return this._addCheck({
|
|
2130
|
+
kind: "max",
|
|
2131
|
+
value: BigInt(0),
|
|
2132
|
+
inclusive: false,
|
|
2133
|
+
message: errorUtil.toString(message)
|
|
2134
|
+
});
|
|
2135
|
+
}
|
|
2136
|
+
nonpositive(message) {
|
|
2137
|
+
return this._addCheck({
|
|
2138
|
+
kind: "max",
|
|
2139
|
+
value: BigInt(0),
|
|
2140
|
+
inclusive: true,
|
|
2141
|
+
message: errorUtil.toString(message)
|
|
2142
|
+
});
|
|
2143
|
+
}
|
|
2144
|
+
nonnegative(message) {
|
|
2145
|
+
return this._addCheck({
|
|
2146
|
+
kind: "min",
|
|
2147
|
+
value: BigInt(0),
|
|
2148
|
+
inclusive: true,
|
|
2149
|
+
message: errorUtil.toString(message)
|
|
2150
|
+
});
|
|
2151
|
+
}
|
|
2152
|
+
multipleOf(value, message) {
|
|
2153
|
+
return this._addCheck({
|
|
2154
|
+
kind: "multipleOf",
|
|
2155
|
+
value,
|
|
2156
|
+
message: errorUtil.toString(message)
|
|
2157
|
+
});
|
|
2158
|
+
}
|
|
2159
|
+
get minValue() {
|
|
2160
|
+
let min = null;
|
|
2161
|
+
for (const ch of this._def.checks) {
|
|
2162
|
+
if (ch.kind === "min") {
|
|
2163
|
+
if (min === null || ch.value > min)
|
|
2164
|
+
min = ch.value;
|
|
2165
|
+
}
|
|
2166
|
+
}
|
|
2167
|
+
return min;
|
|
2168
|
+
}
|
|
2169
|
+
get maxValue() {
|
|
2170
|
+
let max = null;
|
|
2171
|
+
for (const ch of this._def.checks) {
|
|
2172
|
+
if (ch.kind === "max") {
|
|
2173
|
+
if (max === null || ch.value < max)
|
|
2174
|
+
max = ch.value;
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
return max;
|
|
2178
|
+
}
|
|
2179
|
+
};
|
|
2180
|
+
__name(_ZodBigInt, "ZodBigInt");
|
|
2181
|
+
var ZodBigInt = _ZodBigInt;
|
|
2182
|
+
ZodBigInt.create = (params) => {
|
|
2183
|
+
return new ZodBigInt({
|
|
2184
|
+
checks: [],
|
|
2185
|
+
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
2186
|
+
coerce: params?.coerce ?? false,
|
|
2187
|
+
...processCreateParams(params)
|
|
2188
|
+
});
|
|
2189
|
+
};
|
|
2190
|
+
var _ZodBoolean = class _ZodBoolean extends ZodType {
|
|
2191
|
+
_parse(input) {
|
|
2192
|
+
if (this._def.coerce) {
|
|
2193
|
+
input.data = Boolean(input.data);
|
|
2194
|
+
}
|
|
2195
|
+
const parsedType = this._getType(input);
|
|
2196
|
+
if (parsedType !== ZodParsedType.boolean) {
|
|
2197
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2198
|
+
addIssueToContext(ctx, {
|
|
2199
|
+
code: ZodIssueCode.invalid_type,
|
|
2200
|
+
expected: ZodParsedType.boolean,
|
|
2201
|
+
received: ctx.parsedType
|
|
2202
|
+
});
|
|
2203
|
+
return INVALID;
|
|
2204
|
+
}
|
|
2205
|
+
return OK(input.data);
|
|
2206
|
+
}
|
|
2207
|
+
};
|
|
2208
|
+
__name(_ZodBoolean, "ZodBoolean");
|
|
2209
|
+
var ZodBoolean = _ZodBoolean;
|
|
2210
|
+
ZodBoolean.create = (params) => {
|
|
2211
|
+
return new ZodBoolean({
|
|
2212
|
+
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
2213
|
+
coerce: params?.coerce || false,
|
|
2214
|
+
...processCreateParams(params)
|
|
2215
|
+
});
|
|
2216
|
+
};
|
|
2217
|
+
var _ZodDate = class _ZodDate extends ZodType {
|
|
2218
|
+
_parse(input) {
|
|
2219
|
+
if (this._def.coerce) {
|
|
2220
|
+
input.data = new Date(input.data);
|
|
2221
|
+
}
|
|
2222
|
+
const parsedType = this._getType(input);
|
|
2223
|
+
if (parsedType !== ZodParsedType.date) {
|
|
2224
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2225
|
+
addIssueToContext(ctx2, {
|
|
2226
|
+
code: ZodIssueCode.invalid_type,
|
|
2227
|
+
expected: ZodParsedType.date,
|
|
2228
|
+
received: ctx2.parsedType
|
|
2229
|
+
});
|
|
2230
|
+
return INVALID;
|
|
2231
|
+
}
|
|
2232
|
+
if (Number.isNaN(input.data.getTime())) {
|
|
2233
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2234
|
+
addIssueToContext(ctx2, {
|
|
2235
|
+
code: ZodIssueCode.invalid_date
|
|
2236
|
+
});
|
|
2237
|
+
return INVALID;
|
|
2238
|
+
}
|
|
2239
|
+
const status = new ParseStatus();
|
|
2240
|
+
let ctx = void 0;
|
|
2241
|
+
for (const check of this._def.checks) {
|
|
2242
|
+
if (check.kind === "min") {
|
|
2243
|
+
if (input.data.getTime() < check.value) {
|
|
2244
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2245
|
+
addIssueToContext(ctx, {
|
|
2246
|
+
code: ZodIssueCode.too_small,
|
|
2247
|
+
message: check.message,
|
|
2248
|
+
inclusive: true,
|
|
2249
|
+
exact: false,
|
|
2250
|
+
minimum: check.value,
|
|
2251
|
+
type: "date"
|
|
2252
|
+
});
|
|
2253
|
+
status.dirty();
|
|
2254
|
+
}
|
|
2255
|
+
} else if (check.kind === "max") {
|
|
2256
|
+
if (input.data.getTime() > check.value) {
|
|
2257
|
+
ctx = this._getOrReturnCtx(input, ctx);
|
|
2258
|
+
addIssueToContext(ctx, {
|
|
2259
|
+
code: ZodIssueCode.too_big,
|
|
2260
|
+
message: check.message,
|
|
2261
|
+
inclusive: true,
|
|
2262
|
+
exact: false,
|
|
2263
|
+
maximum: check.value,
|
|
2264
|
+
type: "date"
|
|
2265
|
+
});
|
|
2266
|
+
status.dirty();
|
|
2267
|
+
}
|
|
2268
|
+
} else {
|
|
2269
|
+
util.assertNever(check);
|
|
2270
|
+
}
|
|
2271
|
+
}
|
|
2272
|
+
return {
|
|
2273
|
+
status: status.value,
|
|
2274
|
+
value: new Date(input.data.getTime())
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
_addCheck(check) {
|
|
2278
|
+
return new _ZodDate({
|
|
2279
|
+
...this._def,
|
|
2280
|
+
checks: [
|
|
2281
|
+
...this._def.checks,
|
|
2282
|
+
check
|
|
2283
|
+
]
|
|
2284
|
+
});
|
|
2285
|
+
}
|
|
2286
|
+
min(minDate, message) {
|
|
2287
|
+
return this._addCheck({
|
|
2288
|
+
kind: "min",
|
|
2289
|
+
value: minDate.getTime(),
|
|
2290
|
+
message: errorUtil.toString(message)
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
max(maxDate, message) {
|
|
2294
|
+
return this._addCheck({
|
|
2295
|
+
kind: "max",
|
|
2296
|
+
value: maxDate.getTime(),
|
|
2297
|
+
message: errorUtil.toString(message)
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
get minDate() {
|
|
2301
|
+
let min = null;
|
|
2302
|
+
for (const ch of this._def.checks) {
|
|
2303
|
+
if (ch.kind === "min") {
|
|
2304
|
+
if (min === null || ch.value > min)
|
|
2305
|
+
min = ch.value;
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
return min != null ? new Date(min) : null;
|
|
2309
|
+
}
|
|
2310
|
+
get maxDate() {
|
|
2311
|
+
let max = null;
|
|
2312
|
+
for (const ch of this._def.checks) {
|
|
2313
|
+
if (ch.kind === "max") {
|
|
2314
|
+
if (max === null || ch.value < max)
|
|
2315
|
+
max = ch.value;
|
|
2316
|
+
}
|
|
2317
|
+
}
|
|
2318
|
+
return max != null ? new Date(max) : null;
|
|
2319
|
+
}
|
|
2320
|
+
};
|
|
2321
|
+
__name(_ZodDate, "ZodDate");
|
|
2322
|
+
var ZodDate = _ZodDate;
|
|
2323
|
+
ZodDate.create = (params) => {
|
|
2324
|
+
return new ZodDate({
|
|
2325
|
+
checks: [],
|
|
2326
|
+
coerce: params?.coerce || false,
|
|
2327
|
+
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
2328
|
+
...processCreateParams(params)
|
|
2329
|
+
});
|
|
2330
|
+
};
|
|
2331
|
+
var _ZodSymbol = class _ZodSymbol extends ZodType {
|
|
2332
|
+
_parse(input) {
|
|
2333
|
+
const parsedType = this._getType(input);
|
|
2334
|
+
if (parsedType !== ZodParsedType.symbol) {
|
|
2335
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2336
|
+
addIssueToContext(ctx, {
|
|
2337
|
+
code: ZodIssueCode.invalid_type,
|
|
2338
|
+
expected: ZodParsedType.symbol,
|
|
2339
|
+
received: ctx.parsedType
|
|
2340
|
+
});
|
|
2341
|
+
return INVALID;
|
|
2342
|
+
}
|
|
2343
|
+
return OK(input.data);
|
|
2344
|
+
}
|
|
2345
|
+
};
|
|
2346
|
+
__name(_ZodSymbol, "ZodSymbol");
|
|
2347
|
+
var ZodSymbol = _ZodSymbol;
|
|
2348
|
+
ZodSymbol.create = (params) => {
|
|
2349
|
+
return new ZodSymbol({
|
|
2350
|
+
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
2351
|
+
...processCreateParams(params)
|
|
2352
|
+
});
|
|
2353
|
+
};
|
|
2354
|
+
var _ZodUndefined = class _ZodUndefined extends ZodType {
|
|
2355
|
+
_parse(input) {
|
|
2356
|
+
const parsedType = this._getType(input);
|
|
2357
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2358
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2359
|
+
addIssueToContext(ctx, {
|
|
2360
|
+
code: ZodIssueCode.invalid_type,
|
|
2361
|
+
expected: ZodParsedType.undefined,
|
|
2362
|
+
received: ctx.parsedType
|
|
2363
|
+
});
|
|
2364
|
+
return INVALID;
|
|
2365
|
+
}
|
|
2366
|
+
return OK(input.data);
|
|
2367
|
+
}
|
|
2368
|
+
};
|
|
2369
|
+
__name(_ZodUndefined, "ZodUndefined");
|
|
2370
|
+
var ZodUndefined = _ZodUndefined;
|
|
2371
|
+
ZodUndefined.create = (params) => {
|
|
2372
|
+
return new ZodUndefined({
|
|
2373
|
+
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2374
|
+
...processCreateParams(params)
|
|
2375
|
+
});
|
|
2376
|
+
};
|
|
2377
|
+
var _ZodNull = class _ZodNull extends ZodType {
|
|
2378
|
+
_parse(input) {
|
|
2379
|
+
const parsedType = this._getType(input);
|
|
2380
|
+
if (parsedType !== ZodParsedType.null) {
|
|
2381
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2382
|
+
addIssueToContext(ctx, {
|
|
2383
|
+
code: ZodIssueCode.invalid_type,
|
|
2384
|
+
expected: ZodParsedType.null,
|
|
2385
|
+
received: ctx.parsedType
|
|
2386
|
+
});
|
|
2387
|
+
return INVALID;
|
|
2388
|
+
}
|
|
2389
|
+
return OK(input.data);
|
|
2390
|
+
}
|
|
2391
|
+
};
|
|
2392
|
+
__name(_ZodNull, "ZodNull");
|
|
2393
|
+
var ZodNull = _ZodNull;
|
|
2394
|
+
ZodNull.create = (params) => {
|
|
2395
|
+
return new ZodNull({
|
|
2396
|
+
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2397
|
+
...processCreateParams(params)
|
|
2398
|
+
});
|
|
2399
|
+
};
|
|
2400
|
+
var _ZodAny = class _ZodAny extends ZodType {
|
|
2401
|
+
constructor() {
|
|
2402
|
+
super(...arguments);
|
|
2403
|
+
this._any = true;
|
|
2404
|
+
}
|
|
2405
|
+
_parse(input) {
|
|
2406
|
+
return OK(input.data);
|
|
2407
|
+
}
|
|
2408
|
+
};
|
|
2409
|
+
__name(_ZodAny, "ZodAny");
|
|
2410
|
+
var ZodAny = _ZodAny;
|
|
2411
|
+
ZodAny.create = (params) => {
|
|
2412
|
+
return new ZodAny({
|
|
2413
|
+
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2414
|
+
...processCreateParams(params)
|
|
2415
|
+
});
|
|
2416
|
+
};
|
|
2417
|
+
var _ZodUnknown = class _ZodUnknown extends ZodType {
|
|
2418
|
+
constructor() {
|
|
2419
|
+
super(...arguments);
|
|
2420
|
+
this._unknown = true;
|
|
2421
|
+
}
|
|
2422
|
+
_parse(input) {
|
|
2423
|
+
return OK(input.data);
|
|
2424
|
+
}
|
|
2425
|
+
};
|
|
2426
|
+
__name(_ZodUnknown, "ZodUnknown");
|
|
2427
|
+
var ZodUnknown = _ZodUnknown;
|
|
2428
|
+
ZodUnknown.create = (params) => {
|
|
2429
|
+
return new ZodUnknown({
|
|
2430
|
+
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2431
|
+
...processCreateParams(params)
|
|
2432
|
+
});
|
|
2433
|
+
};
|
|
2434
|
+
var _ZodNever = class _ZodNever extends ZodType {
|
|
2435
|
+
_parse(input) {
|
|
2436
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2437
|
+
addIssueToContext(ctx, {
|
|
2438
|
+
code: ZodIssueCode.invalid_type,
|
|
2439
|
+
expected: ZodParsedType.never,
|
|
2440
|
+
received: ctx.parsedType
|
|
2441
|
+
});
|
|
2442
|
+
return INVALID;
|
|
2443
|
+
}
|
|
2444
|
+
};
|
|
2445
|
+
__name(_ZodNever, "ZodNever");
|
|
2446
|
+
var ZodNever = _ZodNever;
|
|
2447
|
+
ZodNever.create = (params) => {
|
|
2448
|
+
return new ZodNever({
|
|
2449
|
+
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2450
|
+
...processCreateParams(params)
|
|
2451
|
+
});
|
|
2452
|
+
};
|
|
2453
|
+
var _ZodVoid = class _ZodVoid extends ZodType {
|
|
2454
|
+
_parse(input) {
|
|
2455
|
+
const parsedType = this._getType(input);
|
|
2456
|
+
if (parsedType !== ZodParsedType.undefined) {
|
|
2457
|
+
const ctx = this._getOrReturnCtx(input);
|
|
2458
|
+
addIssueToContext(ctx, {
|
|
2459
|
+
code: ZodIssueCode.invalid_type,
|
|
2460
|
+
expected: ZodParsedType.void,
|
|
2461
|
+
received: ctx.parsedType
|
|
2462
|
+
});
|
|
2463
|
+
return INVALID;
|
|
2464
|
+
}
|
|
2465
|
+
return OK(input.data);
|
|
2466
|
+
}
|
|
2467
|
+
};
|
|
2468
|
+
__name(_ZodVoid, "ZodVoid");
|
|
2469
|
+
var ZodVoid = _ZodVoid;
|
|
2470
|
+
ZodVoid.create = (params) => {
|
|
2471
|
+
return new ZodVoid({
|
|
2472
|
+
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2473
|
+
...processCreateParams(params)
|
|
2474
|
+
});
|
|
2475
|
+
};
|
|
2476
|
+
var _ZodArray = class _ZodArray extends ZodType {
|
|
2477
|
+
_parse(input) {
|
|
2478
|
+
const { ctx, status } = this._processInputParams(input);
|
|
2479
|
+
const def = this._def;
|
|
2480
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2481
|
+
addIssueToContext(ctx, {
|
|
2482
|
+
code: ZodIssueCode.invalid_type,
|
|
2483
|
+
expected: ZodParsedType.array,
|
|
2484
|
+
received: ctx.parsedType
|
|
2485
|
+
});
|
|
2486
|
+
return INVALID;
|
|
2487
|
+
}
|
|
2488
|
+
if (def.exactLength !== null) {
|
|
2489
|
+
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2490
|
+
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2491
|
+
if (tooBig || tooSmall) {
|
|
2492
|
+
addIssueToContext(ctx, {
|
|
2493
|
+
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2494
|
+
minimum: tooSmall ? def.exactLength.value : void 0,
|
|
2495
|
+
maximum: tooBig ? def.exactLength.value : void 0,
|
|
2496
|
+
type: "array",
|
|
2497
|
+
inclusive: true,
|
|
2498
|
+
exact: true,
|
|
2499
|
+
message: def.exactLength.message
|
|
2500
|
+
});
|
|
2501
|
+
status.dirty();
|
|
2502
|
+
}
|
|
2503
|
+
}
|
|
2504
|
+
if (def.minLength !== null) {
|
|
2505
|
+
if (ctx.data.length < def.minLength.value) {
|
|
2506
|
+
addIssueToContext(ctx, {
|
|
2507
|
+
code: ZodIssueCode.too_small,
|
|
2508
|
+
minimum: def.minLength.value,
|
|
2509
|
+
type: "array",
|
|
2510
|
+
inclusive: true,
|
|
2511
|
+
exact: false,
|
|
2512
|
+
message: def.minLength.message
|
|
2513
|
+
});
|
|
2514
|
+
status.dirty();
|
|
2515
|
+
}
|
|
2516
|
+
}
|
|
2517
|
+
if (def.maxLength !== null) {
|
|
2518
|
+
if (ctx.data.length > def.maxLength.value) {
|
|
2519
|
+
addIssueToContext(ctx, {
|
|
2520
|
+
code: ZodIssueCode.too_big,
|
|
2521
|
+
maximum: def.maxLength.value,
|
|
2522
|
+
type: "array",
|
|
2523
|
+
inclusive: true,
|
|
2524
|
+
exact: false,
|
|
2525
|
+
message: def.maxLength.message
|
|
2526
|
+
});
|
|
2527
|
+
status.dirty();
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
if (ctx.common.async) {
|
|
2531
|
+
return Promise.all([
|
|
2532
|
+
...ctx.data
|
|
2533
|
+
].map((item, i) => {
|
|
2534
|
+
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2535
|
+
})).then((result2) => {
|
|
2536
|
+
return ParseStatus.mergeArray(status, result2);
|
|
2537
|
+
});
|
|
2538
|
+
}
|
|
2539
|
+
const result = [
|
|
2540
|
+
...ctx.data
|
|
2541
|
+
].map((item, i) => {
|
|
2542
|
+
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2543
|
+
});
|
|
2544
|
+
return ParseStatus.mergeArray(status, result);
|
|
2545
|
+
}
|
|
2546
|
+
get element() {
|
|
2547
|
+
return this._def.type;
|
|
2548
|
+
}
|
|
2549
|
+
min(minLength, message) {
|
|
2550
|
+
return new _ZodArray({
|
|
2551
|
+
...this._def,
|
|
2552
|
+
minLength: {
|
|
2553
|
+
value: minLength,
|
|
2554
|
+
message: errorUtil.toString(message)
|
|
2555
|
+
}
|
|
2556
|
+
});
|
|
2557
|
+
}
|
|
2558
|
+
max(maxLength, message) {
|
|
2559
|
+
return new _ZodArray({
|
|
2560
|
+
...this._def,
|
|
2561
|
+
maxLength: {
|
|
2562
|
+
value: maxLength,
|
|
2563
|
+
message: errorUtil.toString(message)
|
|
2564
|
+
}
|
|
2565
|
+
});
|
|
2566
|
+
}
|
|
2567
|
+
length(len, message) {
|
|
2568
|
+
return new _ZodArray({
|
|
2569
|
+
...this._def,
|
|
2570
|
+
exactLength: {
|
|
2571
|
+
value: len,
|
|
2572
|
+
message: errorUtil.toString(message)
|
|
2573
|
+
}
|
|
2574
|
+
});
|
|
2575
|
+
}
|
|
2576
|
+
nonempty(message) {
|
|
2577
|
+
return this.min(1, message);
|
|
2578
|
+
}
|
|
2579
|
+
};
|
|
2580
|
+
__name(_ZodArray, "ZodArray");
|
|
2581
|
+
var ZodArray = _ZodArray;
|
|
2582
|
+
ZodArray.create = (schema, params) => {
|
|
2583
|
+
return new ZodArray({
|
|
2584
|
+
type: schema,
|
|
2585
|
+
minLength: null,
|
|
2586
|
+
maxLength: null,
|
|
2587
|
+
exactLength: null,
|
|
2588
|
+
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2589
|
+
...processCreateParams(params)
|
|
2590
|
+
});
|
|
2591
|
+
};
|
|
2592
|
+
function deepPartialify(schema) {
|
|
2593
|
+
if (schema instanceof ZodObject) {
|
|
2594
|
+
const newShape = {};
|
|
2595
|
+
for (const key in schema.shape) {
|
|
2596
|
+
const fieldSchema = schema.shape[key];
|
|
2597
|
+
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2598
|
+
}
|
|
2599
|
+
return new ZodObject({
|
|
2600
|
+
...schema._def,
|
|
2601
|
+
shape: () => newShape
|
|
2602
|
+
});
|
|
2603
|
+
} else if (schema instanceof ZodArray) {
|
|
2604
|
+
return new ZodArray({
|
|
2605
|
+
...schema._def,
|
|
2606
|
+
type: deepPartialify(schema.element)
|
|
2607
|
+
});
|
|
2608
|
+
} else if (schema instanceof ZodOptional) {
|
|
2609
|
+
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2610
|
+
} else if (schema instanceof ZodNullable) {
|
|
2611
|
+
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2612
|
+
} else if (schema instanceof ZodTuple) {
|
|
2613
|
+
return ZodTuple.create(schema.items.map((item) => deepPartialify(item)));
|
|
2614
|
+
} else {
|
|
2615
|
+
return schema;
|
|
2616
|
+
}
|
|
2617
|
+
}
|
|
2618
|
+
__name(deepPartialify, "deepPartialify");
|
|
2619
|
+
var _ZodObject = class _ZodObject extends ZodType {
|
|
2620
|
+
constructor() {
|
|
2621
|
+
super(...arguments);
|
|
2622
|
+
this._cached = null;
|
|
2623
|
+
this.nonstrict = this.passthrough;
|
|
2624
|
+
this.augment = this.extend;
|
|
2625
|
+
}
|
|
2626
|
+
_getCached() {
|
|
2627
|
+
if (this._cached !== null)
|
|
2628
|
+
return this._cached;
|
|
2629
|
+
const shape = this._def.shape();
|
|
2630
|
+
const keys = util.objectKeys(shape);
|
|
2631
|
+
this._cached = {
|
|
2632
|
+
shape,
|
|
2633
|
+
keys
|
|
2634
|
+
};
|
|
2635
|
+
return this._cached;
|
|
2636
|
+
}
|
|
2637
|
+
_parse(input) {
|
|
2638
|
+
const parsedType = this._getType(input);
|
|
2639
|
+
if (parsedType !== ZodParsedType.object) {
|
|
2640
|
+
const ctx2 = this._getOrReturnCtx(input);
|
|
2641
|
+
addIssueToContext(ctx2, {
|
|
2642
|
+
code: ZodIssueCode.invalid_type,
|
|
2643
|
+
expected: ZodParsedType.object,
|
|
2644
|
+
received: ctx2.parsedType
|
|
2645
|
+
});
|
|
2646
|
+
return INVALID;
|
|
2647
|
+
}
|
|
2648
|
+
const { status, ctx } = this._processInputParams(input);
|
|
2649
|
+
const { shape, keys: shapeKeys } = this._getCached();
|
|
2650
|
+
const extraKeys = [];
|
|
2651
|
+
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2652
|
+
for (const key in ctx.data) {
|
|
2653
|
+
if (!shapeKeys.includes(key)) {
|
|
2654
|
+
extraKeys.push(key);
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
}
|
|
2658
|
+
const pairs = [];
|
|
2659
|
+
for (const key of shapeKeys) {
|
|
2660
|
+
const keyValidator = shape[key];
|
|
2661
|
+
const value = ctx.data[key];
|
|
2662
|
+
pairs.push({
|
|
2663
|
+
key: {
|
|
2664
|
+
status: "valid",
|
|
2665
|
+
value: key
|
|
2666
|
+
},
|
|
2667
|
+
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2668
|
+
alwaysSet: key in ctx.data
|
|
2669
|
+
});
|
|
2670
|
+
}
|
|
2671
|
+
if (this._def.catchall instanceof ZodNever) {
|
|
2672
|
+
const unknownKeys = this._def.unknownKeys;
|
|
2673
|
+
if (unknownKeys === "passthrough") {
|
|
2674
|
+
for (const key of extraKeys) {
|
|
2675
|
+
pairs.push({
|
|
2676
|
+
key: {
|
|
2677
|
+
status: "valid",
|
|
2678
|
+
value: key
|
|
2679
|
+
},
|
|
2680
|
+
value: {
|
|
2681
|
+
status: "valid",
|
|
2682
|
+
value: ctx.data[key]
|
|
2683
|
+
}
|
|
2684
|
+
});
|
|
2685
|
+
}
|
|
2686
|
+
} else if (unknownKeys === "strict") {
|
|
2687
|
+
if (extraKeys.length > 0) {
|
|
2688
|
+
addIssueToContext(ctx, {
|
|
2689
|
+
code: ZodIssueCode.unrecognized_keys,
|
|
2690
|
+
keys: extraKeys
|
|
2691
|
+
});
|
|
2692
|
+
status.dirty();
|
|
2693
|
+
}
|
|
2694
|
+
} else if (unknownKeys === "strip") {
|
|
2695
|
+
} else {
|
|
2696
|
+
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2697
|
+
}
|
|
2698
|
+
} else {
|
|
2699
|
+
const catchall = this._def.catchall;
|
|
2700
|
+
for (const key of extraKeys) {
|
|
2701
|
+
const value = ctx.data[key];
|
|
2702
|
+
pairs.push({
|
|
2703
|
+
key: {
|
|
2704
|
+
status: "valid",
|
|
2705
|
+
value: key
|
|
2706
|
+
},
|
|
2707
|
+
value: catchall._parse(
|
|
2708
|
+
new ParseInputLazyPath(ctx, value, ctx.path, key)
|
|
2709
|
+
//, ctx.child(key), value, getParsedType(value)
|
|
2710
|
+
),
|
|
2711
|
+
alwaysSet: key in ctx.data
|
|
2712
|
+
});
|
|
2713
|
+
}
|
|
2714
|
+
}
|
|
2715
|
+
if (ctx.common.async) {
|
|
2716
|
+
return Promise.resolve().then(async () => {
|
|
2717
|
+
const syncPairs = [];
|
|
2718
|
+
for (const pair of pairs) {
|
|
2719
|
+
const key = await pair.key;
|
|
2720
|
+
const value = await pair.value;
|
|
2721
|
+
syncPairs.push({
|
|
2722
|
+
key,
|
|
2723
|
+
value,
|
|
2724
|
+
alwaysSet: pair.alwaysSet
|
|
2725
|
+
});
|
|
2726
|
+
}
|
|
2727
|
+
return syncPairs;
|
|
2728
|
+
}).then((syncPairs) => {
|
|
2729
|
+
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2730
|
+
});
|
|
2731
|
+
} else {
|
|
2732
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2733
|
+
}
|
|
2734
|
+
}
|
|
2735
|
+
get shape() {
|
|
2736
|
+
return this._def.shape();
|
|
2737
|
+
}
|
|
2738
|
+
strict(message) {
|
|
2739
|
+
errorUtil.errToObj;
|
|
2740
|
+
return new _ZodObject({
|
|
2741
|
+
...this._def,
|
|
2742
|
+
unknownKeys: "strict",
|
|
2743
|
+
...message !== void 0 ? {
|
|
2744
|
+
errorMap: (issue, ctx) => {
|
|
2745
|
+
const defaultError = this._def.errorMap?.(issue, ctx).message ?? ctx.defaultError;
|
|
2746
|
+
if (issue.code === "unrecognized_keys")
|
|
2747
|
+
return {
|
|
2748
|
+
message: errorUtil.errToObj(message).message ?? defaultError
|
|
2749
|
+
};
|
|
2750
|
+
return {
|
|
2751
|
+
message: defaultError
|
|
2752
|
+
};
|
|
2753
|
+
}
|
|
2754
|
+
} : {}
|
|
2755
|
+
});
|
|
2756
|
+
}
|
|
2757
|
+
strip() {
|
|
2758
|
+
return new _ZodObject({
|
|
2759
|
+
...this._def,
|
|
2760
|
+
unknownKeys: "strip"
|
|
2761
|
+
});
|
|
2762
|
+
}
|
|
2763
|
+
passthrough() {
|
|
2764
|
+
return new _ZodObject({
|
|
2765
|
+
...this._def,
|
|
2766
|
+
unknownKeys: "passthrough"
|
|
2767
|
+
});
|
|
2768
|
+
}
|
|
2769
|
+
// const AugmentFactory =
|
|
2770
|
+
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2771
|
+
// <Augmentation extends ZodRawShape>(
|
|
2772
|
+
// augmentation: Augmentation
|
|
2773
|
+
// ): ZodObject<
|
|
2774
|
+
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2775
|
+
// Def["unknownKeys"],
|
|
2776
|
+
// Def["catchall"]
|
|
2777
|
+
// > => {
|
|
2778
|
+
// return new ZodObject({
|
|
2779
|
+
// ...def,
|
|
2780
|
+
// shape: () => ({
|
|
2781
|
+
// ...def.shape(),
|
|
2782
|
+
// ...augmentation,
|
|
2783
|
+
// }),
|
|
2784
|
+
// }) as any;
|
|
2785
|
+
// };
|
|
2786
|
+
extend(augmentation) {
|
|
2787
|
+
return new _ZodObject({
|
|
2788
|
+
...this._def,
|
|
2789
|
+
shape: () => ({
|
|
2790
|
+
...this._def.shape(),
|
|
2791
|
+
...augmentation
|
|
2792
|
+
})
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
/**
|
|
2796
|
+
* Prior to zod@1.0.12 there was a bug in the
|
|
2797
|
+
* inferred type of merged objects. Please
|
|
2798
|
+
* upgrade if you are experiencing issues.
|
|
2799
|
+
*/
|
|
2800
|
+
merge(merging) {
|
|
2801
|
+
const merged = new _ZodObject({
|
|
2802
|
+
unknownKeys: merging._def.unknownKeys,
|
|
2803
|
+
catchall: merging._def.catchall,
|
|
2804
|
+
shape: () => ({
|
|
2805
|
+
...this._def.shape(),
|
|
2806
|
+
...merging._def.shape()
|
|
2807
|
+
}),
|
|
2808
|
+
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2809
|
+
});
|
|
2810
|
+
return merged;
|
|
2811
|
+
}
|
|
2812
|
+
// merge<
|
|
2813
|
+
// Incoming extends AnyZodObject,
|
|
2814
|
+
// Augmentation extends Incoming["shape"],
|
|
2815
|
+
// NewOutput extends {
|
|
2816
|
+
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2817
|
+
// ? Augmentation[k]["_output"]
|
|
2818
|
+
// : k extends keyof Output
|
|
2819
|
+
// ? Output[k]
|
|
2820
|
+
// : never;
|
|
2821
|
+
// },
|
|
2822
|
+
// NewInput extends {
|
|
2823
|
+
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2824
|
+
// ? Augmentation[k]["_input"]
|
|
2825
|
+
// : k extends keyof Input
|
|
2826
|
+
// ? Input[k]
|
|
2827
|
+
// : never;
|
|
2828
|
+
// }
|
|
2829
|
+
// >(
|
|
2830
|
+
// merging: Incoming
|
|
2831
|
+
// ): ZodObject<
|
|
2832
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2833
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2834
|
+
// Incoming["_def"]["catchall"],
|
|
2835
|
+
// NewOutput,
|
|
2836
|
+
// NewInput
|
|
2837
|
+
// > {
|
|
2838
|
+
// const merged: any = new ZodObject({
|
|
2839
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2840
|
+
// catchall: merging._def.catchall,
|
|
2841
|
+
// shape: () =>
|
|
2842
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2843
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2844
|
+
// }) as any;
|
|
2845
|
+
// return merged;
|
|
2846
|
+
// }
|
|
2847
|
+
setKey(key, schema) {
|
|
2848
|
+
return this.augment({
|
|
2849
|
+
[key]: schema
|
|
2850
|
+
});
|
|
2851
|
+
}
|
|
2852
|
+
// merge<Incoming extends AnyZodObject>(
|
|
2853
|
+
// merging: Incoming
|
|
2854
|
+
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2855
|
+
// ZodObject<
|
|
2856
|
+
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2857
|
+
// Incoming["_def"]["unknownKeys"],
|
|
2858
|
+
// Incoming["_def"]["catchall"]
|
|
2859
|
+
// > {
|
|
2860
|
+
// // const mergedShape = objectUtil.mergeShapes(
|
|
2861
|
+
// // this._def.shape(),
|
|
2862
|
+
// // merging._def.shape()
|
|
2863
|
+
// // );
|
|
2864
|
+
// const merged: any = new ZodObject({
|
|
2865
|
+
// unknownKeys: merging._def.unknownKeys,
|
|
2866
|
+
// catchall: merging._def.catchall,
|
|
2867
|
+
// shape: () =>
|
|
2868
|
+
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2869
|
+
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2870
|
+
// }) as any;
|
|
2871
|
+
// return merged;
|
|
2872
|
+
// }
|
|
2873
|
+
catchall(index) {
|
|
2874
|
+
return new _ZodObject({
|
|
2875
|
+
...this._def,
|
|
2876
|
+
catchall: index
|
|
2877
|
+
});
|
|
2878
|
+
}
|
|
2879
|
+
pick(mask) {
|
|
2880
|
+
const shape = {};
|
|
2881
|
+
for (const key of util.objectKeys(mask)) {
|
|
2882
|
+
if (mask[key] && this.shape[key]) {
|
|
2883
|
+
shape[key] = this.shape[key];
|
|
2884
|
+
}
|
|
2885
|
+
}
|
|
2886
|
+
return new _ZodObject({
|
|
2887
|
+
...this._def,
|
|
2888
|
+
shape: () => shape
|
|
2889
|
+
});
|
|
2890
|
+
}
|
|
2891
|
+
omit(mask) {
|
|
2892
|
+
const shape = {};
|
|
2893
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2894
|
+
if (!mask[key]) {
|
|
2895
|
+
shape[key] = this.shape[key];
|
|
2896
|
+
}
|
|
2897
|
+
}
|
|
2898
|
+
return new _ZodObject({
|
|
2899
|
+
...this._def,
|
|
2900
|
+
shape: () => shape
|
|
2901
|
+
});
|
|
2902
|
+
}
|
|
2903
|
+
/**
|
|
2904
|
+
* @deprecated
|
|
2905
|
+
*/
|
|
2906
|
+
deepPartial() {
|
|
2907
|
+
return deepPartialify(this);
|
|
2908
|
+
}
|
|
2909
|
+
partial(mask) {
|
|
2910
|
+
const newShape = {};
|
|
2911
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2912
|
+
const fieldSchema = this.shape[key];
|
|
2913
|
+
if (mask && !mask[key]) {
|
|
2914
|
+
newShape[key] = fieldSchema;
|
|
2915
|
+
} else {
|
|
2916
|
+
newShape[key] = fieldSchema.optional();
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
return new _ZodObject({
|
|
2920
|
+
...this._def,
|
|
2921
|
+
shape: () => newShape
|
|
2922
|
+
});
|
|
2923
|
+
}
|
|
2924
|
+
required(mask) {
|
|
2925
|
+
const newShape = {};
|
|
2926
|
+
for (const key of util.objectKeys(this.shape)) {
|
|
2927
|
+
if (mask && !mask[key]) {
|
|
2928
|
+
newShape[key] = this.shape[key];
|
|
2929
|
+
} else {
|
|
2930
|
+
const fieldSchema = this.shape[key];
|
|
2931
|
+
let newField = fieldSchema;
|
|
2932
|
+
while (newField instanceof ZodOptional) {
|
|
2933
|
+
newField = newField._def.innerType;
|
|
2934
|
+
}
|
|
2935
|
+
newShape[key] = newField;
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
return new _ZodObject({
|
|
2939
|
+
...this._def,
|
|
2940
|
+
shape: () => newShape
|
|
2941
|
+
});
|
|
2942
|
+
}
|
|
2943
|
+
keyof() {
|
|
2944
|
+
return createZodEnum(util.objectKeys(this.shape));
|
|
2945
|
+
}
|
|
2946
|
+
};
|
|
2947
|
+
__name(_ZodObject, "ZodObject");
|
|
2948
|
+
var ZodObject = _ZodObject;
|
|
2949
|
+
ZodObject.create = (shape, params) => {
|
|
2950
|
+
return new ZodObject({
|
|
2951
|
+
shape: () => shape,
|
|
2952
|
+
unknownKeys: "strip",
|
|
2953
|
+
catchall: ZodNever.create(),
|
|
2954
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2955
|
+
...processCreateParams(params)
|
|
2956
|
+
});
|
|
2957
|
+
};
|
|
2958
|
+
ZodObject.strictCreate = (shape, params) => {
|
|
2959
|
+
return new ZodObject({
|
|
2960
|
+
shape: () => shape,
|
|
2961
|
+
unknownKeys: "strict",
|
|
2962
|
+
catchall: ZodNever.create(),
|
|
2963
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2964
|
+
...processCreateParams(params)
|
|
2965
|
+
});
|
|
2966
|
+
};
|
|
2967
|
+
ZodObject.lazycreate = (shape, params) => {
|
|
2968
|
+
return new ZodObject({
|
|
2969
|
+
shape,
|
|
2970
|
+
unknownKeys: "strip",
|
|
2971
|
+
catchall: ZodNever.create(),
|
|
2972
|
+
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2973
|
+
...processCreateParams(params)
|
|
2974
|
+
});
|
|
2975
|
+
};
|
|
2976
|
+
var _ZodUnion = class _ZodUnion extends ZodType {
|
|
2977
|
+
_parse(input) {
|
|
2978
|
+
const { ctx } = this._processInputParams(input);
|
|
2979
|
+
const options = this._def.options;
|
|
2980
|
+
function handleResults(results) {
|
|
2981
|
+
for (const result of results) {
|
|
2982
|
+
if (result.result.status === "valid") {
|
|
2983
|
+
return result.result;
|
|
2984
|
+
}
|
|
2985
|
+
}
|
|
2986
|
+
for (const result of results) {
|
|
2987
|
+
if (result.result.status === "dirty") {
|
|
2988
|
+
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2989
|
+
return result.result;
|
|
2990
|
+
}
|
|
2991
|
+
}
|
|
2992
|
+
const unionErrors = results.map((result) => new ZodError(result.ctx.common.issues));
|
|
2993
|
+
addIssueToContext(ctx, {
|
|
2994
|
+
code: ZodIssueCode.invalid_union,
|
|
2995
|
+
unionErrors
|
|
2996
|
+
});
|
|
2997
|
+
return INVALID;
|
|
2998
|
+
}
|
|
2999
|
+
__name(handleResults, "handleResults");
|
|
3000
|
+
if (ctx.common.async) {
|
|
3001
|
+
return Promise.all(options.map(async (option) => {
|
|
3002
|
+
const childCtx = {
|
|
3003
|
+
...ctx,
|
|
3004
|
+
common: {
|
|
3005
|
+
...ctx.common,
|
|
3006
|
+
issues: []
|
|
3007
|
+
},
|
|
3008
|
+
parent: null
|
|
3009
|
+
};
|
|
3010
|
+
return {
|
|
3011
|
+
result: await option._parseAsync({
|
|
3012
|
+
data: ctx.data,
|
|
3013
|
+
path: ctx.path,
|
|
3014
|
+
parent: childCtx
|
|
3015
|
+
}),
|
|
3016
|
+
ctx: childCtx
|
|
3017
|
+
};
|
|
3018
|
+
})).then(handleResults);
|
|
3019
|
+
} else {
|
|
3020
|
+
let dirty = void 0;
|
|
3021
|
+
const issues = [];
|
|
3022
|
+
for (const option of options) {
|
|
3023
|
+
const childCtx = {
|
|
3024
|
+
...ctx,
|
|
3025
|
+
common: {
|
|
3026
|
+
...ctx.common,
|
|
3027
|
+
issues: []
|
|
3028
|
+
},
|
|
3029
|
+
parent: null
|
|
3030
|
+
};
|
|
3031
|
+
const result = option._parseSync({
|
|
3032
|
+
data: ctx.data,
|
|
3033
|
+
path: ctx.path,
|
|
3034
|
+
parent: childCtx
|
|
3035
|
+
});
|
|
3036
|
+
if (result.status === "valid") {
|
|
3037
|
+
return result;
|
|
3038
|
+
} else if (result.status === "dirty" && !dirty) {
|
|
3039
|
+
dirty = {
|
|
3040
|
+
result,
|
|
3041
|
+
ctx: childCtx
|
|
3042
|
+
};
|
|
3043
|
+
}
|
|
3044
|
+
if (childCtx.common.issues.length) {
|
|
3045
|
+
issues.push(childCtx.common.issues);
|
|
3046
|
+
}
|
|
3047
|
+
}
|
|
3048
|
+
if (dirty) {
|
|
3049
|
+
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
3050
|
+
return dirty.result;
|
|
3051
|
+
}
|
|
3052
|
+
const unionErrors = issues.map((issues2) => new ZodError(issues2));
|
|
3053
|
+
addIssueToContext(ctx, {
|
|
3054
|
+
code: ZodIssueCode.invalid_union,
|
|
3055
|
+
unionErrors
|
|
3056
|
+
});
|
|
3057
|
+
return INVALID;
|
|
3058
|
+
}
|
|
3059
|
+
}
|
|
3060
|
+
get options() {
|
|
3061
|
+
return this._def.options;
|
|
3062
|
+
}
|
|
3063
|
+
};
|
|
3064
|
+
__name(_ZodUnion, "ZodUnion");
|
|
3065
|
+
var ZodUnion = _ZodUnion;
|
|
3066
|
+
ZodUnion.create = (types, params) => {
|
|
3067
|
+
return new ZodUnion({
|
|
3068
|
+
options: types,
|
|
3069
|
+
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
3070
|
+
...processCreateParams(params)
|
|
3071
|
+
});
|
|
3072
|
+
};
|
|
3073
|
+
var getDiscriminator = /* @__PURE__ */ __name((type) => {
|
|
3074
|
+
if (type instanceof ZodLazy) {
|
|
3075
|
+
return getDiscriminator(type.schema);
|
|
3076
|
+
} else if (type instanceof ZodEffects) {
|
|
3077
|
+
return getDiscriminator(type.innerType());
|
|
3078
|
+
} else if (type instanceof ZodLiteral) {
|
|
3079
|
+
return [
|
|
3080
|
+
type.value
|
|
3081
|
+
];
|
|
3082
|
+
} else if (type instanceof ZodEnum) {
|
|
3083
|
+
return type.options;
|
|
3084
|
+
} else if (type instanceof ZodNativeEnum) {
|
|
3085
|
+
return util.objectValues(type.enum);
|
|
3086
|
+
} else if (type instanceof ZodDefault) {
|
|
3087
|
+
return getDiscriminator(type._def.innerType);
|
|
3088
|
+
} else if (type instanceof ZodUndefined) {
|
|
3089
|
+
return [
|
|
3090
|
+
void 0
|
|
3091
|
+
];
|
|
3092
|
+
} else if (type instanceof ZodNull) {
|
|
3093
|
+
return [
|
|
3094
|
+
null
|
|
3095
|
+
];
|
|
3096
|
+
} else if (type instanceof ZodOptional) {
|
|
3097
|
+
return [
|
|
3098
|
+
void 0,
|
|
3099
|
+
...getDiscriminator(type.unwrap())
|
|
3100
|
+
];
|
|
3101
|
+
} else if (type instanceof ZodNullable) {
|
|
3102
|
+
return [
|
|
3103
|
+
null,
|
|
3104
|
+
...getDiscriminator(type.unwrap())
|
|
3105
|
+
];
|
|
3106
|
+
} else if (type instanceof ZodBranded) {
|
|
3107
|
+
return getDiscriminator(type.unwrap());
|
|
3108
|
+
} else if (type instanceof ZodReadonly) {
|
|
3109
|
+
return getDiscriminator(type.unwrap());
|
|
3110
|
+
} else if (type instanceof ZodCatch) {
|
|
3111
|
+
return getDiscriminator(type._def.innerType);
|
|
3112
|
+
} else {
|
|
3113
|
+
return [];
|
|
3114
|
+
}
|
|
3115
|
+
}, "getDiscriminator");
|
|
3116
|
+
var _ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
3117
|
+
_parse(input) {
|
|
3118
|
+
const { ctx } = this._processInputParams(input);
|
|
3119
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3120
|
+
addIssueToContext(ctx, {
|
|
3121
|
+
code: ZodIssueCode.invalid_type,
|
|
3122
|
+
expected: ZodParsedType.object,
|
|
3123
|
+
received: ctx.parsedType
|
|
3124
|
+
});
|
|
3125
|
+
return INVALID;
|
|
3126
|
+
}
|
|
3127
|
+
const discriminator = this.discriminator;
|
|
3128
|
+
const discriminatorValue = ctx.data[discriminator];
|
|
3129
|
+
const option = this.optionsMap.get(discriminatorValue);
|
|
3130
|
+
if (!option) {
|
|
3131
|
+
addIssueToContext(ctx, {
|
|
3132
|
+
code: ZodIssueCode.invalid_union_discriminator,
|
|
3133
|
+
options: Array.from(this.optionsMap.keys()),
|
|
3134
|
+
path: [
|
|
3135
|
+
discriminator
|
|
3136
|
+
]
|
|
3137
|
+
});
|
|
3138
|
+
return INVALID;
|
|
3139
|
+
}
|
|
3140
|
+
if (ctx.common.async) {
|
|
3141
|
+
return option._parseAsync({
|
|
3142
|
+
data: ctx.data,
|
|
3143
|
+
path: ctx.path,
|
|
3144
|
+
parent: ctx
|
|
3145
|
+
});
|
|
3146
|
+
} else {
|
|
3147
|
+
return option._parseSync({
|
|
3148
|
+
data: ctx.data,
|
|
3149
|
+
path: ctx.path,
|
|
3150
|
+
parent: ctx
|
|
3151
|
+
});
|
|
3152
|
+
}
|
|
3153
|
+
}
|
|
3154
|
+
get discriminator() {
|
|
3155
|
+
return this._def.discriminator;
|
|
3156
|
+
}
|
|
3157
|
+
get options() {
|
|
3158
|
+
return this._def.options;
|
|
3159
|
+
}
|
|
3160
|
+
get optionsMap() {
|
|
3161
|
+
return this._def.optionsMap;
|
|
3162
|
+
}
|
|
3163
|
+
/**
|
|
3164
|
+
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
3165
|
+
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
3166
|
+
* have a different value for each object in the union.
|
|
3167
|
+
* @param discriminator the name of the discriminator property
|
|
3168
|
+
* @param types an array of object schemas
|
|
3169
|
+
* @param params
|
|
3170
|
+
*/
|
|
3171
|
+
static create(discriminator, options, params) {
|
|
3172
|
+
const optionsMap = /* @__PURE__ */ new Map();
|
|
3173
|
+
for (const type of options) {
|
|
3174
|
+
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
3175
|
+
if (!discriminatorValues.length) {
|
|
3176
|
+
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
3177
|
+
}
|
|
3178
|
+
for (const value of discriminatorValues) {
|
|
3179
|
+
if (optionsMap.has(value)) {
|
|
3180
|
+
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
3181
|
+
}
|
|
3182
|
+
optionsMap.set(value, type);
|
|
3183
|
+
}
|
|
3184
|
+
}
|
|
3185
|
+
return new _ZodDiscriminatedUnion({
|
|
3186
|
+
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
3187
|
+
discriminator,
|
|
3188
|
+
options,
|
|
3189
|
+
optionsMap,
|
|
3190
|
+
...processCreateParams(params)
|
|
3191
|
+
});
|
|
3192
|
+
}
|
|
3193
|
+
};
|
|
3194
|
+
__name(_ZodDiscriminatedUnion, "ZodDiscriminatedUnion");
|
|
3195
|
+
var ZodDiscriminatedUnion = _ZodDiscriminatedUnion;
|
|
3196
|
+
function mergeValues(a, b) {
|
|
3197
|
+
const aType = getParsedType(a);
|
|
3198
|
+
const bType = getParsedType(b);
|
|
3199
|
+
if (a === b) {
|
|
3200
|
+
return {
|
|
3201
|
+
valid: true,
|
|
3202
|
+
data: a
|
|
3203
|
+
};
|
|
3204
|
+
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
3205
|
+
const bKeys = util.objectKeys(b);
|
|
3206
|
+
const sharedKeys = util.objectKeys(a).filter((key) => bKeys.indexOf(key) !== -1);
|
|
3207
|
+
const newObj = {
|
|
3208
|
+
...a,
|
|
3209
|
+
...b
|
|
3210
|
+
};
|
|
3211
|
+
for (const key of sharedKeys) {
|
|
3212
|
+
const sharedValue = mergeValues(a[key], b[key]);
|
|
3213
|
+
if (!sharedValue.valid) {
|
|
3214
|
+
return {
|
|
3215
|
+
valid: false
|
|
3216
|
+
};
|
|
3217
|
+
}
|
|
3218
|
+
newObj[key] = sharedValue.data;
|
|
3219
|
+
}
|
|
3220
|
+
return {
|
|
3221
|
+
valid: true,
|
|
3222
|
+
data: newObj
|
|
3223
|
+
};
|
|
3224
|
+
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
3225
|
+
if (a.length !== b.length) {
|
|
3226
|
+
return {
|
|
3227
|
+
valid: false
|
|
3228
|
+
};
|
|
3229
|
+
}
|
|
3230
|
+
const newArray = [];
|
|
3231
|
+
for (let index = 0; index < a.length; index++) {
|
|
3232
|
+
const itemA = a[index];
|
|
3233
|
+
const itemB = b[index];
|
|
3234
|
+
const sharedValue = mergeValues(itemA, itemB);
|
|
3235
|
+
if (!sharedValue.valid) {
|
|
3236
|
+
return {
|
|
3237
|
+
valid: false
|
|
3238
|
+
};
|
|
3239
|
+
}
|
|
3240
|
+
newArray.push(sharedValue.data);
|
|
3241
|
+
}
|
|
3242
|
+
return {
|
|
3243
|
+
valid: true,
|
|
3244
|
+
data: newArray
|
|
3245
|
+
};
|
|
3246
|
+
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
3247
|
+
return {
|
|
3248
|
+
valid: true,
|
|
3249
|
+
data: a
|
|
3250
|
+
};
|
|
3251
|
+
} else {
|
|
3252
|
+
return {
|
|
3253
|
+
valid: false
|
|
3254
|
+
};
|
|
3255
|
+
}
|
|
3256
|
+
}
|
|
3257
|
+
__name(mergeValues, "mergeValues");
|
|
3258
|
+
var _ZodIntersection = class _ZodIntersection extends ZodType {
|
|
3259
|
+
_parse(input) {
|
|
3260
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3261
|
+
const handleParsed = /* @__PURE__ */ __name((parsedLeft, parsedRight) => {
|
|
3262
|
+
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
3263
|
+
return INVALID;
|
|
3264
|
+
}
|
|
3265
|
+
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
3266
|
+
if (!merged.valid) {
|
|
3267
|
+
addIssueToContext(ctx, {
|
|
3268
|
+
code: ZodIssueCode.invalid_intersection_types
|
|
3269
|
+
});
|
|
3270
|
+
return INVALID;
|
|
3271
|
+
}
|
|
3272
|
+
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
3273
|
+
status.dirty();
|
|
3274
|
+
}
|
|
3275
|
+
return {
|
|
3276
|
+
status: status.value,
|
|
3277
|
+
value: merged.data
|
|
3278
|
+
};
|
|
3279
|
+
}, "handleParsed");
|
|
3280
|
+
if (ctx.common.async) {
|
|
3281
|
+
return Promise.all([
|
|
3282
|
+
this._def.left._parseAsync({
|
|
3283
|
+
data: ctx.data,
|
|
3284
|
+
path: ctx.path,
|
|
3285
|
+
parent: ctx
|
|
3286
|
+
}),
|
|
3287
|
+
this._def.right._parseAsync({
|
|
3288
|
+
data: ctx.data,
|
|
3289
|
+
path: ctx.path,
|
|
3290
|
+
parent: ctx
|
|
3291
|
+
})
|
|
3292
|
+
]).then(([left, right]) => handleParsed(left, right));
|
|
3293
|
+
} else {
|
|
3294
|
+
return handleParsed(this._def.left._parseSync({
|
|
3295
|
+
data: ctx.data,
|
|
3296
|
+
path: ctx.path,
|
|
3297
|
+
parent: ctx
|
|
3298
|
+
}), this._def.right._parseSync({
|
|
3299
|
+
data: ctx.data,
|
|
3300
|
+
path: ctx.path,
|
|
3301
|
+
parent: ctx
|
|
3302
|
+
}));
|
|
3303
|
+
}
|
|
3304
|
+
}
|
|
3305
|
+
};
|
|
3306
|
+
__name(_ZodIntersection, "ZodIntersection");
|
|
3307
|
+
var ZodIntersection = _ZodIntersection;
|
|
3308
|
+
ZodIntersection.create = (left, right, params) => {
|
|
3309
|
+
return new ZodIntersection({
|
|
3310
|
+
left,
|
|
3311
|
+
right,
|
|
3312
|
+
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
3313
|
+
...processCreateParams(params)
|
|
3314
|
+
});
|
|
3315
|
+
};
|
|
3316
|
+
var _ZodTuple = class _ZodTuple extends ZodType {
|
|
3317
|
+
_parse(input) {
|
|
3318
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3319
|
+
if (ctx.parsedType !== ZodParsedType.array) {
|
|
3320
|
+
addIssueToContext(ctx, {
|
|
3321
|
+
code: ZodIssueCode.invalid_type,
|
|
3322
|
+
expected: ZodParsedType.array,
|
|
3323
|
+
received: ctx.parsedType
|
|
3324
|
+
});
|
|
3325
|
+
return INVALID;
|
|
3326
|
+
}
|
|
3327
|
+
if (ctx.data.length < this._def.items.length) {
|
|
3328
|
+
addIssueToContext(ctx, {
|
|
3329
|
+
code: ZodIssueCode.too_small,
|
|
3330
|
+
minimum: this._def.items.length,
|
|
3331
|
+
inclusive: true,
|
|
3332
|
+
exact: false,
|
|
3333
|
+
type: "array"
|
|
3334
|
+
});
|
|
3335
|
+
return INVALID;
|
|
3336
|
+
}
|
|
3337
|
+
const rest = this._def.rest;
|
|
3338
|
+
if (!rest && ctx.data.length > this._def.items.length) {
|
|
3339
|
+
addIssueToContext(ctx, {
|
|
3340
|
+
code: ZodIssueCode.too_big,
|
|
3341
|
+
maximum: this._def.items.length,
|
|
3342
|
+
inclusive: true,
|
|
3343
|
+
exact: false,
|
|
3344
|
+
type: "array"
|
|
3345
|
+
});
|
|
3346
|
+
status.dirty();
|
|
3347
|
+
}
|
|
3348
|
+
const items = [
|
|
3349
|
+
...ctx.data
|
|
3350
|
+
].map((item, itemIndex) => {
|
|
3351
|
+
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
3352
|
+
if (!schema)
|
|
3353
|
+
return null;
|
|
3354
|
+
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
3355
|
+
}).filter((x) => !!x);
|
|
3356
|
+
if (ctx.common.async) {
|
|
3357
|
+
return Promise.all(items).then((results) => {
|
|
3358
|
+
return ParseStatus.mergeArray(status, results);
|
|
3359
|
+
});
|
|
3360
|
+
} else {
|
|
3361
|
+
return ParseStatus.mergeArray(status, items);
|
|
3362
|
+
}
|
|
3363
|
+
}
|
|
3364
|
+
get items() {
|
|
3365
|
+
return this._def.items;
|
|
3366
|
+
}
|
|
3367
|
+
rest(rest) {
|
|
3368
|
+
return new _ZodTuple({
|
|
3369
|
+
...this._def,
|
|
3370
|
+
rest
|
|
3371
|
+
});
|
|
3372
|
+
}
|
|
3373
|
+
};
|
|
3374
|
+
__name(_ZodTuple, "ZodTuple");
|
|
3375
|
+
var ZodTuple = _ZodTuple;
|
|
3376
|
+
ZodTuple.create = (schemas, params) => {
|
|
3377
|
+
if (!Array.isArray(schemas)) {
|
|
3378
|
+
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3379
|
+
}
|
|
3380
|
+
return new ZodTuple({
|
|
3381
|
+
items: schemas,
|
|
3382
|
+
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3383
|
+
rest: null,
|
|
3384
|
+
...processCreateParams(params)
|
|
3385
|
+
});
|
|
3386
|
+
};
|
|
3387
|
+
var _ZodRecord = class _ZodRecord extends ZodType {
|
|
3388
|
+
get keySchema() {
|
|
3389
|
+
return this._def.keyType;
|
|
3390
|
+
}
|
|
3391
|
+
get valueSchema() {
|
|
3392
|
+
return this._def.valueType;
|
|
3393
|
+
}
|
|
3394
|
+
_parse(input) {
|
|
3395
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3396
|
+
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3397
|
+
addIssueToContext(ctx, {
|
|
3398
|
+
code: ZodIssueCode.invalid_type,
|
|
3399
|
+
expected: ZodParsedType.object,
|
|
3400
|
+
received: ctx.parsedType
|
|
3401
|
+
});
|
|
3402
|
+
return INVALID;
|
|
3403
|
+
}
|
|
3404
|
+
const pairs = [];
|
|
3405
|
+
const keyType = this._def.keyType;
|
|
3406
|
+
const valueType = this._def.valueType;
|
|
3407
|
+
for (const key in ctx.data) {
|
|
3408
|
+
pairs.push({
|
|
3409
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3410
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key)),
|
|
3411
|
+
alwaysSet: key in ctx.data
|
|
3412
|
+
});
|
|
3413
|
+
}
|
|
3414
|
+
if (ctx.common.async) {
|
|
3415
|
+
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3416
|
+
} else {
|
|
3417
|
+
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3418
|
+
}
|
|
3419
|
+
}
|
|
3420
|
+
get element() {
|
|
3421
|
+
return this._def.valueType;
|
|
3422
|
+
}
|
|
3423
|
+
static create(first, second, third) {
|
|
3424
|
+
if (second instanceof ZodType) {
|
|
3425
|
+
return new _ZodRecord({
|
|
3426
|
+
keyType: first,
|
|
3427
|
+
valueType: second,
|
|
3428
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3429
|
+
...processCreateParams(third)
|
|
3430
|
+
});
|
|
3431
|
+
}
|
|
3432
|
+
return new _ZodRecord({
|
|
3433
|
+
keyType: ZodString.create(),
|
|
3434
|
+
valueType: first,
|
|
3435
|
+
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3436
|
+
...processCreateParams(second)
|
|
3437
|
+
});
|
|
3438
|
+
}
|
|
3439
|
+
};
|
|
3440
|
+
__name(_ZodRecord, "ZodRecord");
|
|
3441
|
+
var ZodRecord = _ZodRecord;
|
|
3442
|
+
var _ZodMap = class _ZodMap extends ZodType {
|
|
3443
|
+
get keySchema() {
|
|
3444
|
+
return this._def.keyType;
|
|
3445
|
+
}
|
|
3446
|
+
get valueSchema() {
|
|
3447
|
+
return this._def.valueType;
|
|
3448
|
+
}
|
|
3449
|
+
_parse(input) {
|
|
3450
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3451
|
+
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3452
|
+
addIssueToContext(ctx, {
|
|
3453
|
+
code: ZodIssueCode.invalid_type,
|
|
3454
|
+
expected: ZodParsedType.map,
|
|
3455
|
+
received: ctx.parsedType
|
|
3456
|
+
});
|
|
3457
|
+
return INVALID;
|
|
3458
|
+
}
|
|
3459
|
+
const keyType = this._def.keyType;
|
|
3460
|
+
const valueType = this._def.valueType;
|
|
3461
|
+
const pairs = [
|
|
3462
|
+
...ctx.data.entries()
|
|
3463
|
+
].map(([key, value], index) => {
|
|
3464
|
+
return {
|
|
3465
|
+
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [
|
|
3466
|
+
index,
|
|
3467
|
+
"key"
|
|
3468
|
+
])),
|
|
3469
|
+
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [
|
|
3470
|
+
index,
|
|
3471
|
+
"value"
|
|
3472
|
+
]))
|
|
3473
|
+
};
|
|
3474
|
+
});
|
|
3475
|
+
if (ctx.common.async) {
|
|
3476
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3477
|
+
return Promise.resolve().then(async () => {
|
|
3478
|
+
for (const pair of pairs) {
|
|
3479
|
+
const key = await pair.key;
|
|
3480
|
+
const value = await pair.value;
|
|
3481
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3482
|
+
return INVALID;
|
|
3483
|
+
}
|
|
3484
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3485
|
+
status.dirty();
|
|
3486
|
+
}
|
|
3487
|
+
finalMap.set(key.value, value.value);
|
|
3488
|
+
}
|
|
3489
|
+
return {
|
|
3490
|
+
status: status.value,
|
|
3491
|
+
value: finalMap
|
|
3492
|
+
};
|
|
3493
|
+
});
|
|
3494
|
+
} else {
|
|
3495
|
+
const finalMap = /* @__PURE__ */ new Map();
|
|
3496
|
+
for (const pair of pairs) {
|
|
3497
|
+
const key = pair.key;
|
|
3498
|
+
const value = pair.value;
|
|
3499
|
+
if (key.status === "aborted" || value.status === "aborted") {
|
|
3500
|
+
return INVALID;
|
|
3501
|
+
}
|
|
3502
|
+
if (key.status === "dirty" || value.status === "dirty") {
|
|
3503
|
+
status.dirty();
|
|
3504
|
+
}
|
|
3505
|
+
finalMap.set(key.value, value.value);
|
|
3506
|
+
}
|
|
3507
|
+
return {
|
|
3508
|
+
status: status.value,
|
|
3509
|
+
value: finalMap
|
|
3510
|
+
};
|
|
3511
|
+
}
|
|
3512
|
+
}
|
|
3513
|
+
};
|
|
3514
|
+
__name(_ZodMap, "ZodMap");
|
|
3515
|
+
var ZodMap = _ZodMap;
|
|
3516
|
+
ZodMap.create = (keyType, valueType, params) => {
|
|
3517
|
+
return new ZodMap({
|
|
3518
|
+
valueType,
|
|
3519
|
+
keyType,
|
|
3520
|
+
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3521
|
+
...processCreateParams(params)
|
|
3522
|
+
});
|
|
3523
|
+
};
|
|
3524
|
+
var _ZodSet = class _ZodSet extends ZodType {
|
|
3525
|
+
_parse(input) {
|
|
3526
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3527
|
+
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3528
|
+
addIssueToContext(ctx, {
|
|
3529
|
+
code: ZodIssueCode.invalid_type,
|
|
3530
|
+
expected: ZodParsedType.set,
|
|
3531
|
+
received: ctx.parsedType
|
|
3532
|
+
});
|
|
3533
|
+
return INVALID;
|
|
3534
|
+
}
|
|
3535
|
+
const def = this._def;
|
|
3536
|
+
if (def.minSize !== null) {
|
|
3537
|
+
if (ctx.data.size < def.minSize.value) {
|
|
3538
|
+
addIssueToContext(ctx, {
|
|
3539
|
+
code: ZodIssueCode.too_small,
|
|
3540
|
+
minimum: def.minSize.value,
|
|
3541
|
+
type: "set",
|
|
3542
|
+
inclusive: true,
|
|
3543
|
+
exact: false,
|
|
3544
|
+
message: def.minSize.message
|
|
3545
|
+
});
|
|
3546
|
+
status.dirty();
|
|
3547
|
+
}
|
|
3548
|
+
}
|
|
3549
|
+
if (def.maxSize !== null) {
|
|
3550
|
+
if (ctx.data.size > def.maxSize.value) {
|
|
3551
|
+
addIssueToContext(ctx, {
|
|
3552
|
+
code: ZodIssueCode.too_big,
|
|
3553
|
+
maximum: def.maxSize.value,
|
|
3554
|
+
type: "set",
|
|
3555
|
+
inclusive: true,
|
|
3556
|
+
exact: false,
|
|
3557
|
+
message: def.maxSize.message
|
|
3558
|
+
});
|
|
3559
|
+
status.dirty();
|
|
3560
|
+
}
|
|
3561
|
+
}
|
|
3562
|
+
const valueType = this._def.valueType;
|
|
3563
|
+
function finalizeSet(elements2) {
|
|
3564
|
+
const parsedSet = /* @__PURE__ */ new Set();
|
|
3565
|
+
for (const element of elements2) {
|
|
3566
|
+
if (element.status === "aborted")
|
|
3567
|
+
return INVALID;
|
|
3568
|
+
if (element.status === "dirty")
|
|
3569
|
+
status.dirty();
|
|
3570
|
+
parsedSet.add(element.value);
|
|
3571
|
+
}
|
|
3572
|
+
return {
|
|
3573
|
+
status: status.value,
|
|
3574
|
+
value: parsedSet
|
|
3575
|
+
};
|
|
3576
|
+
}
|
|
3577
|
+
__name(finalizeSet, "finalizeSet");
|
|
3578
|
+
const elements = [
|
|
3579
|
+
...ctx.data.values()
|
|
3580
|
+
].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3581
|
+
if (ctx.common.async) {
|
|
3582
|
+
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
3583
|
+
} else {
|
|
3584
|
+
return finalizeSet(elements);
|
|
3585
|
+
}
|
|
3586
|
+
}
|
|
3587
|
+
min(minSize, message) {
|
|
3588
|
+
return new _ZodSet({
|
|
3589
|
+
...this._def,
|
|
3590
|
+
minSize: {
|
|
3591
|
+
value: minSize,
|
|
3592
|
+
message: errorUtil.toString(message)
|
|
3593
|
+
}
|
|
3594
|
+
});
|
|
3595
|
+
}
|
|
3596
|
+
max(maxSize, message) {
|
|
3597
|
+
return new _ZodSet({
|
|
3598
|
+
...this._def,
|
|
3599
|
+
maxSize: {
|
|
3600
|
+
value: maxSize,
|
|
3601
|
+
message: errorUtil.toString(message)
|
|
3602
|
+
}
|
|
3603
|
+
});
|
|
3604
|
+
}
|
|
3605
|
+
size(size, message) {
|
|
3606
|
+
return this.min(size, message).max(size, message);
|
|
3607
|
+
}
|
|
3608
|
+
nonempty(message) {
|
|
3609
|
+
return this.min(1, message);
|
|
3610
|
+
}
|
|
3611
|
+
};
|
|
3612
|
+
__name(_ZodSet, "ZodSet");
|
|
3613
|
+
var ZodSet = _ZodSet;
|
|
3614
|
+
ZodSet.create = (valueType, params) => {
|
|
3615
|
+
return new ZodSet({
|
|
3616
|
+
valueType,
|
|
3617
|
+
minSize: null,
|
|
3618
|
+
maxSize: null,
|
|
3619
|
+
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3620
|
+
...processCreateParams(params)
|
|
3621
|
+
});
|
|
3622
|
+
};
|
|
3623
|
+
var _ZodFunction = class _ZodFunction extends ZodType {
|
|
3624
|
+
constructor() {
|
|
3625
|
+
super(...arguments);
|
|
3626
|
+
this.validate = this.implement;
|
|
3627
|
+
}
|
|
3628
|
+
_parse(input) {
|
|
3629
|
+
const { ctx } = this._processInputParams(input);
|
|
3630
|
+
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3631
|
+
addIssueToContext(ctx, {
|
|
3632
|
+
code: ZodIssueCode.invalid_type,
|
|
3633
|
+
expected: ZodParsedType.function,
|
|
3634
|
+
received: ctx.parsedType
|
|
3635
|
+
});
|
|
3636
|
+
return INVALID;
|
|
3637
|
+
}
|
|
3638
|
+
function makeArgsIssue(args, error) {
|
|
3639
|
+
return makeIssue({
|
|
3640
|
+
data: args,
|
|
3641
|
+
path: ctx.path,
|
|
3642
|
+
errorMaps: [
|
|
3643
|
+
ctx.common.contextualErrorMap,
|
|
3644
|
+
ctx.schemaErrorMap,
|
|
3645
|
+
getErrorMap(),
|
|
3646
|
+
en_default
|
|
3647
|
+
].filter((x) => !!x),
|
|
3648
|
+
issueData: {
|
|
3649
|
+
code: ZodIssueCode.invalid_arguments,
|
|
3650
|
+
argumentsError: error
|
|
3651
|
+
}
|
|
3652
|
+
});
|
|
3653
|
+
}
|
|
3654
|
+
__name(makeArgsIssue, "makeArgsIssue");
|
|
3655
|
+
function makeReturnsIssue(returns, error) {
|
|
3656
|
+
return makeIssue({
|
|
3657
|
+
data: returns,
|
|
3658
|
+
path: ctx.path,
|
|
3659
|
+
errorMaps: [
|
|
3660
|
+
ctx.common.contextualErrorMap,
|
|
3661
|
+
ctx.schemaErrorMap,
|
|
3662
|
+
getErrorMap(),
|
|
3663
|
+
en_default
|
|
3664
|
+
].filter((x) => !!x),
|
|
3665
|
+
issueData: {
|
|
3666
|
+
code: ZodIssueCode.invalid_return_type,
|
|
3667
|
+
returnTypeError: error
|
|
3668
|
+
}
|
|
3669
|
+
});
|
|
3670
|
+
}
|
|
3671
|
+
__name(makeReturnsIssue, "makeReturnsIssue");
|
|
3672
|
+
const params = {
|
|
3673
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3674
|
+
};
|
|
3675
|
+
const fn = ctx.data;
|
|
3676
|
+
if (this._def.returns instanceof ZodPromise) {
|
|
3677
|
+
const me = this;
|
|
3678
|
+
return OK(async function(...args) {
|
|
3679
|
+
const error = new ZodError([]);
|
|
3680
|
+
const parsedArgs = await me._def.args.parseAsync(args, params).catch((e) => {
|
|
3681
|
+
error.addIssue(makeArgsIssue(args, e));
|
|
3682
|
+
throw error;
|
|
3683
|
+
});
|
|
3684
|
+
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3685
|
+
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch((e) => {
|
|
3686
|
+
error.addIssue(makeReturnsIssue(result, e));
|
|
3687
|
+
throw error;
|
|
3688
|
+
});
|
|
3689
|
+
return parsedReturns;
|
|
3690
|
+
});
|
|
3691
|
+
} else {
|
|
3692
|
+
const me = this;
|
|
3693
|
+
return OK(function(...args) {
|
|
3694
|
+
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3695
|
+
if (!parsedArgs.success) {
|
|
3696
|
+
throw new ZodError([
|
|
3697
|
+
makeArgsIssue(args, parsedArgs.error)
|
|
3698
|
+
]);
|
|
3699
|
+
}
|
|
3700
|
+
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3701
|
+
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3702
|
+
if (!parsedReturns.success) {
|
|
3703
|
+
throw new ZodError([
|
|
3704
|
+
makeReturnsIssue(result, parsedReturns.error)
|
|
3705
|
+
]);
|
|
3706
|
+
}
|
|
3707
|
+
return parsedReturns.data;
|
|
3708
|
+
});
|
|
3709
|
+
}
|
|
3710
|
+
}
|
|
3711
|
+
parameters() {
|
|
3712
|
+
return this._def.args;
|
|
3713
|
+
}
|
|
3714
|
+
returnType() {
|
|
3715
|
+
return this._def.returns;
|
|
3716
|
+
}
|
|
3717
|
+
args(...items) {
|
|
3718
|
+
return new _ZodFunction({
|
|
3719
|
+
...this._def,
|
|
3720
|
+
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3721
|
+
});
|
|
3722
|
+
}
|
|
3723
|
+
returns(returnType) {
|
|
3724
|
+
return new _ZodFunction({
|
|
3725
|
+
...this._def,
|
|
3726
|
+
returns: returnType
|
|
3727
|
+
});
|
|
3728
|
+
}
|
|
3729
|
+
implement(func) {
|
|
3730
|
+
const validatedFunc = this.parse(func);
|
|
3731
|
+
return validatedFunc;
|
|
3732
|
+
}
|
|
3733
|
+
strictImplement(func) {
|
|
3734
|
+
const validatedFunc = this.parse(func);
|
|
3735
|
+
return validatedFunc;
|
|
3736
|
+
}
|
|
3737
|
+
static create(args, returns, params) {
|
|
3738
|
+
return new _ZodFunction({
|
|
3739
|
+
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3740
|
+
returns: returns || ZodUnknown.create(),
|
|
3741
|
+
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3742
|
+
...processCreateParams(params)
|
|
3743
|
+
});
|
|
3744
|
+
}
|
|
3745
|
+
};
|
|
3746
|
+
__name(_ZodFunction, "ZodFunction");
|
|
3747
|
+
var ZodFunction = _ZodFunction;
|
|
3748
|
+
var _ZodLazy = class _ZodLazy extends ZodType {
|
|
3749
|
+
get schema() {
|
|
3750
|
+
return this._def.getter();
|
|
3751
|
+
}
|
|
3752
|
+
_parse(input) {
|
|
3753
|
+
const { ctx } = this._processInputParams(input);
|
|
3754
|
+
const lazySchema = this._def.getter();
|
|
3755
|
+
return lazySchema._parse({
|
|
3756
|
+
data: ctx.data,
|
|
3757
|
+
path: ctx.path,
|
|
3758
|
+
parent: ctx
|
|
3759
|
+
});
|
|
3760
|
+
}
|
|
3761
|
+
};
|
|
3762
|
+
__name(_ZodLazy, "ZodLazy");
|
|
3763
|
+
var ZodLazy = _ZodLazy;
|
|
3764
|
+
ZodLazy.create = (getter, params) => {
|
|
3765
|
+
return new ZodLazy({
|
|
3766
|
+
getter,
|
|
3767
|
+
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3768
|
+
...processCreateParams(params)
|
|
3769
|
+
});
|
|
3770
|
+
};
|
|
3771
|
+
var _ZodLiteral = class _ZodLiteral extends ZodType {
|
|
3772
|
+
_parse(input) {
|
|
3773
|
+
if (input.data !== this._def.value) {
|
|
3774
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3775
|
+
addIssueToContext(ctx, {
|
|
3776
|
+
received: ctx.data,
|
|
3777
|
+
code: ZodIssueCode.invalid_literal,
|
|
3778
|
+
expected: this._def.value
|
|
3779
|
+
});
|
|
3780
|
+
return INVALID;
|
|
3781
|
+
}
|
|
3782
|
+
return {
|
|
3783
|
+
status: "valid",
|
|
3784
|
+
value: input.data
|
|
3785
|
+
};
|
|
3786
|
+
}
|
|
3787
|
+
get value() {
|
|
3788
|
+
return this._def.value;
|
|
3789
|
+
}
|
|
3790
|
+
};
|
|
3791
|
+
__name(_ZodLiteral, "ZodLiteral");
|
|
3792
|
+
var ZodLiteral = _ZodLiteral;
|
|
3793
|
+
ZodLiteral.create = (value, params) => {
|
|
3794
|
+
return new ZodLiteral({
|
|
3795
|
+
value,
|
|
3796
|
+
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3797
|
+
...processCreateParams(params)
|
|
3798
|
+
});
|
|
3799
|
+
};
|
|
3800
|
+
function createZodEnum(values, params) {
|
|
3801
|
+
return new ZodEnum({
|
|
3802
|
+
values,
|
|
3803
|
+
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3804
|
+
...processCreateParams(params)
|
|
3805
|
+
});
|
|
3806
|
+
}
|
|
3807
|
+
__name(createZodEnum, "createZodEnum");
|
|
3808
|
+
var _ZodEnum = class _ZodEnum extends ZodType {
|
|
3809
|
+
_parse(input) {
|
|
3810
|
+
if (typeof input.data !== "string") {
|
|
3811
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3812
|
+
const expectedValues = this._def.values;
|
|
3813
|
+
addIssueToContext(ctx, {
|
|
3814
|
+
expected: util.joinValues(expectedValues),
|
|
3815
|
+
received: ctx.parsedType,
|
|
3816
|
+
code: ZodIssueCode.invalid_type
|
|
3817
|
+
});
|
|
3818
|
+
return INVALID;
|
|
3819
|
+
}
|
|
3820
|
+
if (!this._cache) {
|
|
3821
|
+
this._cache = new Set(this._def.values);
|
|
3822
|
+
}
|
|
3823
|
+
if (!this._cache.has(input.data)) {
|
|
3824
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3825
|
+
const expectedValues = this._def.values;
|
|
3826
|
+
addIssueToContext(ctx, {
|
|
3827
|
+
received: ctx.data,
|
|
3828
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3829
|
+
options: expectedValues
|
|
3830
|
+
});
|
|
3831
|
+
return INVALID;
|
|
3832
|
+
}
|
|
3833
|
+
return OK(input.data);
|
|
3834
|
+
}
|
|
3835
|
+
get options() {
|
|
3836
|
+
return this._def.values;
|
|
3837
|
+
}
|
|
3838
|
+
get enum() {
|
|
3839
|
+
const enumValues = {};
|
|
3840
|
+
for (const val of this._def.values) {
|
|
3841
|
+
enumValues[val] = val;
|
|
3842
|
+
}
|
|
3843
|
+
return enumValues;
|
|
3844
|
+
}
|
|
3845
|
+
get Values() {
|
|
3846
|
+
const enumValues = {};
|
|
3847
|
+
for (const val of this._def.values) {
|
|
3848
|
+
enumValues[val] = val;
|
|
3849
|
+
}
|
|
3850
|
+
return enumValues;
|
|
3851
|
+
}
|
|
3852
|
+
get Enum() {
|
|
3853
|
+
const enumValues = {};
|
|
3854
|
+
for (const val of this._def.values) {
|
|
3855
|
+
enumValues[val] = val;
|
|
3856
|
+
}
|
|
3857
|
+
return enumValues;
|
|
3858
|
+
}
|
|
3859
|
+
extract(values, newDef = this._def) {
|
|
3860
|
+
return _ZodEnum.create(values, {
|
|
3861
|
+
...this._def,
|
|
3862
|
+
...newDef
|
|
3863
|
+
});
|
|
3864
|
+
}
|
|
3865
|
+
exclude(values, newDef = this._def) {
|
|
3866
|
+
return _ZodEnum.create(this.options.filter((opt) => !values.includes(opt)), {
|
|
3867
|
+
...this._def,
|
|
3868
|
+
...newDef
|
|
3869
|
+
});
|
|
3870
|
+
}
|
|
3871
|
+
};
|
|
3872
|
+
__name(_ZodEnum, "ZodEnum");
|
|
3873
|
+
var ZodEnum = _ZodEnum;
|
|
3874
|
+
ZodEnum.create = createZodEnum;
|
|
3875
|
+
var _ZodNativeEnum = class _ZodNativeEnum extends ZodType {
|
|
3876
|
+
_parse(input) {
|
|
3877
|
+
const nativeEnumValues = util.getValidEnumValues(this._def.values);
|
|
3878
|
+
const ctx = this._getOrReturnCtx(input);
|
|
3879
|
+
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3880
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3881
|
+
addIssueToContext(ctx, {
|
|
3882
|
+
expected: util.joinValues(expectedValues),
|
|
3883
|
+
received: ctx.parsedType,
|
|
3884
|
+
code: ZodIssueCode.invalid_type
|
|
3885
|
+
});
|
|
3886
|
+
return INVALID;
|
|
3887
|
+
}
|
|
3888
|
+
if (!this._cache) {
|
|
3889
|
+
this._cache = new Set(util.getValidEnumValues(this._def.values));
|
|
3890
|
+
}
|
|
3891
|
+
if (!this._cache.has(input.data)) {
|
|
3892
|
+
const expectedValues = util.objectValues(nativeEnumValues);
|
|
3893
|
+
addIssueToContext(ctx, {
|
|
3894
|
+
received: ctx.data,
|
|
3895
|
+
code: ZodIssueCode.invalid_enum_value,
|
|
3896
|
+
options: expectedValues
|
|
3897
|
+
});
|
|
3898
|
+
return INVALID;
|
|
3899
|
+
}
|
|
3900
|
+
return OK(input.data);
|
|
3901
|
+
}
|
|
3902
|
+
get enum() {
|
|
3903
|
+
return this._def.values;
|
|
3904
|
+
}
|
|
3905
|
+
};
|
|
3906
|
+
__name(_ZodNativeEnum, "ZodNativeEnum");
|
|
3907
|
+
var ZodNativeEnum = _ZodNativeEnum;
|
|
3908
|
+
ZodNativeEnum.create = (values, params) => {
|
|
3909
|
+
return new ZodNativeEnum({
|
|
3910
|
+
values,
|
|
3911
|
+
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3912
|
+
...processCreateParams(params)
|
|
3913
|
+
});
|
|
3914
|
+
};
|
|
3915
|
+
var _ZodPromise = class _ZodPromise extends ZodType {
|
|
3916
|
+
unwrap() {
|
|
3917
|
+
return this._def.type;
|
|
3918
|
+
}
|
|
3919
|
+
_parse(input) {
|
|
3920
|
+
const { ctx } = this._processInputParams(input);
|
|
3921
|
+
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3922
|
+
addIssueToContext(ctx, {
|
|
3923
|
+
code: ZodIssueCode.invalid_type,
|
|
3924
|
+
expected: ZodParsedType.promise,
|
|
3925
|
+
received: ctx.parsedType
|
|
3926
|
+
});
|
|
3927
|
+
return INVALID;
|
|
3928
|
+
}
|
|
3929
|
+
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3930
|
+
return OK(promisified.then((data) => {
|
|
3931
|
+
return this._def.type.parseAsync(data, {
|
|
3932
|
+
path: ctx.path,
|
|
3933
|
+
errorMap: ctx.common.contextualErrorMap
|
|
3934
|
+
});
|
|
3935
|
+
}));
|
|
3936
|
+
}
|
|
3937
|
+
};
|
|
3938
|
+
__name(_ZodPromise, "ZodPromise");
|
|
3939
|
+
var ZodPromise = _ZodPromise;
|
|
3940
|
+
ZodPromise.create = (schema, params) => {
|
|
3941
|
+
return new ZodPromise({
|
|
3942
|
+
type: schema,
|
|
3943
|
+
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3944
|
+
...processCreateParams(params)
|
|
3945
|
+
});
|
|
3946
|
+
};
|
|
3947
|
+
var _ZodEffects = class _ZodEffects extends ZodType {
|
|
3948
|
+
innerType() {
|
|
3949
|
+
return this._def.schema;
|
|
3950
|
+
}
|
|
3951
|
+
sourceType() {
|
|
3952
|
+
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3953
|
+
}
|
|
3954
|
+
_parse(input) {
|
|
3955
|
+
const { status, ctx } = this._processInputParams(input);
|
|
3956
|
+
const effect = this._def.effect || null;
|
|
3957
|
+
const checkCtx = {
|
|
3958
|
+
addIssue: (arg) => {
|
|
3959
|
+
addIssueToContext(ctx, arg);
|
|
3960
|
+
if (arg.fatal) {
|
|
3961
|
+
status.abort();
|
|
3962
|
+
} else {
|
|
3963
|
+
status.dirty();
|
|
3964
|
+
}
|
|
3965
|
+
},
|
|
3966
|
+
get path() {
|
|
3967
|
+
return ctx.path;
|
|
3968
|
+
}
|
|
3969
|
+
};
|
|
3970
|
+
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3971
|
+
if (effect.type === "preprocess") {
|
|
3972
|
+
const processed = effect.transform(ctx.data, checkCtx);
|
|
3973
|
+
if (ctx.common.async) {
|
|
3974
|
+
return Promise.resolve(processed).then(async (processed2) => {
|
|
3975
|
+
if (status.value === "aborted")
|
|
3976
|
+
return INVALID;
|
|
3977
|
+
const result = await this._def.schema._parseAsync({
|
|
3978
|
+
data: processed2,
|
|
3979
|
+
path: ctx.path,
|
|
3980
|
+
parent: ctx
|
|
3981
|
+
});
|
|
3982
|
+
if (result.status === "aborted")
|
|
3983
|
+
return INVALID;
|
|
3984
|
+
if (result.status === "dirty")
|
|
3985
|
+
return DIRTY(result.value);
|
|
3986
|
+
if (status.value === "dirty")
|
|
3987
|
+
return DIRTY(result.value);
|
|
3988
|
+
return result;
|
|
3989
|
+
});
|
|
3990
|
+
} else {
|
|
3991
|
+
if (status.value === "aborted")
|
|
3992
|
+
return INVALID;
|
|
3993
|
+
const result = this._def.schema._parseSync({
|
|
3994
|
+
data: processed,
|
|
3995
|
+
path: ctx.path,
|
|
3996
|
+
parent: ctx
|
|
3997
|
+
});
|
|
3998
|
+
if (result.status === "aborted")
|
|
3999
|
+
return INVALID;
|
|
4000
|
+
if (result.status === "dirty")
|
|
4001
|
+
return DIRTY(result.value);
|
|
4002
|
+
if (status.value === "dirty")
|
|
4003
|
+
return DIRTY(result.value);
|
|
4004
|
+
return result;
|
|
4005
|
+
}
|
|
4006
|
+
}
|
|
4007
|
+
if (effect.type === "refinement") {
|
|
4008
|
+
const executeRefinement = /* @__PURE__ */ __name((acc) => {
|
|
4009
|
+
const result = effect.refinement(acc, checkCtx);
|
|
4010
|
+
if (ctx.common.async) {
|
|
4011
|
+
return Promise.resolve(result);
|
|
4012
|
+
}
|
|
4013
|
+
if (result instanceof Promise) {
|
|
4014
|
+
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
4015
|
+
}
|
|
4016
|
+
return acc;
|
|
4017
|
+
}, "executeRefinement");
|
|
4018
|
+
if (ctx.common.async === false) {
|
|
4019
|
+
const inner = this._def.schema._parseSync({
|
|
4020
|
+
data: ctx.data,
|
|
4021
|
+
path: ctx.path,
|
|
4022
|
+
parent: ctx
|
|
4023
|
+
});
|
|
4024
|
+
if (inner.status === "aborted")
|
|
4025
|
+
return INVALID;
|
|
4026
|
+
if (inner.status === "dirty")
|
|
4027
|
+
status.dirty();
|
|
4028
|
+
executeRefinement(inner.value);
|
|
4029
|
+
return {
|
|
4030
|
+
status: status.value,
|
|
4031
|
+
value: inner.value
|
|
4032
|
+
};
|
|
4033
|
+
} else {
|
|
4034
|
+
return this._def.schema._parseAsync({
|
|
4035
|
+
data: ctx.data,
|
|
4036
|
+
path: ctx.path,
|
|
4037
|
+
parent: ctx
|
|
4038
|
+
}).then((inner) => {
|
|
4039
|
+
if (inner.status === "aborted")
|
|
4040
|
+
return INVALID;
|
|
4041
|
+
if (inner.status === "dirty")
|
|
4042
|
+
status.dirty();
|
|
4043
|
+
return executeRefinement(inner.value).then(() => {
|
|
4044
|
+
return {
|
|
4045
|
+
status: status.value,
|
|
4046
|
+
value: inner.value
|
|
4047
|
+
};
|
|
4048
|
+
});
|
|
4049
|
+
});
|
|
4050
|
+
}
|
|
4051
|
+
}
|
|
4052
|
+
if (effect.type === "transform") {
|
|
4053
|
+
if (ctx.common.async === false) {
|
|
4054
|
+
const base = this._def.schema._parseSync({
|
|
4055
|
+
data: ctx.data,
|
|
4056
|
+
path: ctx.path,
|
|
4057
|
+
parent: ctx
|
|
4058
|
+
});
|
|
4059
|
+
if (!isValid(base))
|
|
4060
|
+
return INVALID;
|
|
4061
|
+
const result = effect.transform(base.value, checkCtx);
|
|
4062
|
+
if (result instanceof Promise) {
|
|
4063
|
+
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
4064
|
+
}
|
|
4065
|
+
return {
|
|
4066
|
+
status: status.value,
|
|
4067
|
+
value: result
|
|
4068
|
+
};
|
|
4069
|
+
} else {
|
|
4070
|
+
return this._def.schema._parseAsync({
|
|
4071
|
+
data: ctx.data,
|
|
4072
|
+
path: ctx.path,
|
|
4073
|
+
parent: ctx
|
|
4074
|
+
}).then((base) => {
|
|
4075
|
+
if (!isValid(base))
|
|
4076
|
+
return INVALID;
|
|
4077
|
+
return Promise.resolve(effect.transform(base.value, checkCtx)).then((result) => ({
|
|
4078
|
+
status: status.value,
|
|
4079
|
+
value: result
|
|
4080
|
+
}));
|
|
4081
|
+
});
|
|
4082
|
+
}
|
|
4083
|
+
}
|
|
4084
|
+
util.assertNever(effect);
|
|
4085
|
+
}
|
|
4086
|
+
};
|
|
4087
|
+
__name(_ZodEffects, "ZodEffects");
|
|
4088
|
+
var ZodEffects = _ZodEffects;
|
|
4089
|
+
ZodEffects.create = (schema, effect, params) => {
|
|
4090
|
+
return new ZodEffects({
|
|
4091
|
+
schema,
|
|
4092
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4093
|
+
effect,
|
|
4094
|
+
...processCreateParams(params)
|
|
4095
|
+
});
|
|
4096
|
+
};
|
|
4097
|
+
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
4098
|
+
return new ZodEffects({
|
|
4099
|
+
schema,
|
|
4100
|
+
effect: {
|
|
4101
|
+
type: "preprocess",
|
|
4102
|
+
transform: preprocess
|
|
4103
|
+
},
|
|
4104
|
+
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
4105
|
+
...processCreateParams(params)
|
|
4106
|
+
});
|
|
4107
|
+
};
|
|
4108
|
+
var _ZodOptional = class _ZodOptional extends ZodType {
|
|
4109
|
+
_parse(input) {
|
|
4110
|
+
const parsedType = this._getType(input);
|
|
4111
|
+
if (parsedType === ZodParsedType.undefined) {
|
|
4112
|
+
return OK(void 0);
|
|
4113
|
+
}
|
|
4114
|
+
return this._def.innerType._parse(input);
|
|
4115
|
+
}
|
|
4116
|
+
unwrap() {
|
|
4117
|
+
return this._def.innerType;
|
|
4118
|
+
}
|
|
4119
|
+
};
|
|
4120
|
+
__name(_ZodOptional, "ZodOptional");
|
|
4121
|
+
var ZodOptional = _ZodOptional;
|
|
4122
|
+
ZodOptional.create = (type, params) => {
|
|
4123
|
+
return new ZodOptional({
|
|
4124
|
+
innerType: type,
|
|
4125
|
+
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
4126
|
+
...processCreateParams(params)
|
|
4127
|
+
});
|
|
4128
|
+
};
|
|
4129
|
+
var _ZodNullable = class _ZodNullable extends ZodType {
|
|
4130
|
+
_parse(input) {
|
|
4131
|
+
const parsedType = this._getType(input);
|
|
4132
|
+
if (parsedType === ZodParsedType.null) {
|
|
4133
|
+
return OK(null);
|
|
4134
|
+
}
|
|
4135
|
+
return this._def.innerType._parse(input);
|
|
4136
|
+
}
|
|
4137
|
+
unwrap() {
|
|
4138
|
+
return this._def.innerType;
|
|
4139
|
+
}
|
|
4140
|
+
};
|
|
4141
|
+
__name(_ZodNullable, "ZodNullable");
|
|
4142
|
+
var ZodNullable = _ZodNullable;
|
|
4143
|
+
ZodNullable.create = (type, params) => {
|
|
4144
|
+
return new ZodNullable({
|
|
4145
|
+
innerType: type,
|
|
4146
|
+
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
4147
|
+
...processCreateParams(params)
|
|
4148
|
+
});
|
|
4149
|
+
};
|
|
4150
|
+
var _ZodDefault = class _ZodDefault extends ZodType {
|
|
4151
|
+
_parse(input) {
|
|
4152
|
+
const { ctx } = this._processInputParams(input);
|
|
4153
|
+
let data = ctx.data;
|
|
4154
|
+
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
4155
|
+
data = this._def.defaultValue();
|
|
4156
|
+
}
|
|
4157
|
+
return this._def.innerType._parse({
|
|
4158
|
+
data,
|
|
4159
|
+
path: ctx.path,
|
|
4160
|
+
parent: ctx
|
|
4161
|
+
});
|
|
4162
|
+
}
|
|
4163
|
+
removeDefault() {
|
|
4164
|
+
return this._def.innerType;
|
|
4165
|
+
}
|
|
4166
|
+
};
|
|
4167
|
+
__name(_ZodDefault, "ZodDefault");
|
|
4168
|
+
var ZodDefault = _ZodDefault;
|
|
4169
|
+
ZodDefault.create = (type, params) => {
|
|
4170
|
+
return new ZodDefault({
|
|
4171
|
+
innerType: type,
|
|
4172
|
+
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
4173
|
+
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
4174
|
+
...processCreateParams(params)
|
|
4175
|
+
});
|
|
4176
|
+
};
|
|
4177
|
+
var _ZodCatch = class _ZodCatch extends ZodType {
|
|
4178
|
+
_parse(input) {
|
|
4179
|
+
const { ctx } = this._processInputParams(input);
|
|
4180
|
+
const newCtx = {
|
|
4181
|
+
...ctx,
|
|
4182
|
+
common: {
|
|
4183
|
+
...ctx.common,
|
|
4184
|
+
issues: []
|
|
4185
|
+
}
|
|
4186
|
+
};
|
|
4187
|
+
const result = this._def.innerType._parse({
|
|
4188
|
+
data: newCtx.data,
|
|
4189
|
+
path: newCtx.path,
|
|
4190
|
+
parent: {
|
|
4191
|
+
...newCtx
|
|
4192
|
+
}
|
|
4193
|
+
});
|
|
4194
|
+
if (isAsync(result)) {
|
|
4195
|
+
return result.then((result2) => {
|
|
4196
|
+
return {
|
|
4197
|
+
status: "valid",
|
|
4198
|
+
value: result2.status === "valid" ? result2.value : this._def.catchValue({
|
|
4199
|
+
get error() {
|
|
4200
|
+
return new ZodError(newCtx.common.issues);
|
|
4201
|
+
},
|
|
4202
|
+
input: newCtx.data
|
|
4203
|
+
})
|
|
4204
|
+
};
|
|
4205
|
+
});
|
|
4206
|
+
} else {
|
|
4207
|
+
return {
|
|
4208
|
+
status: "valid",
|
|
4209
|
+
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
4210
|
+
get error() {
|
|
4211
|
+
return new ZodError(newCtx.common.issues);
|
|
4212
|
+
},
|
|
4213
|
+
input: newCtx.data
|
|
4214
|
+
})
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4217
|
+
}
|
|
4218
|
+
removeCatch() {
|
|
4219
|
+
return this._def.innerType;
|
|
4220
|
+
}
|
|
4221
|
+
};
|
|
4222
|
+
__name(_ZodCatch, "ZodCatch");
|
|
4223
|
+
var ZodCatch = _ZodCatch;
|
|
4224
|
+
ZodCatch.create = (type, params) => {
|
|
4225
|
+
return new ZodCatch({
|
|
4226
|
+
innerType: type,
|
|
4227
|
+
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
4228
|
+
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
4229
|
+
...processCreateParams(params)
|
|
4230
|
+
});
|
|
4231
|
+
};
|
|
4232
|
+
var _ZodNaN = class _ZodNaN extends ZodType {
|
|
4233
|
+
_parse(input) {
|
|
4234
|
+
const parsedType = this._getType(input);
|
|
4235
|
+
if (parsedType !== ZodParsedType.nan) {
|
|
4236
|
+
const ctx = this._getOrReturnCtx(input);
|
|
4237
|
+
addIssueToContext(ctx, {
|
|
4238
|
+
code: ZodIssueCode.invalid_type,
|
|
4239
|
+
expected: ZodParsedType.nan,
|
|
4240
|
+
received: ctx.parsedType
|
|
4241
|
+
});
|
|
4242
|
+
return INVALID;
|
|
4243
|
+
}
|
|
4244
|
+
return {
|
|
4245
|
+
status: "valid",
|
|
4246
|
+
value: input.data
|
|
4247
|
+
};
|
|
4248
|
+
}
|
|
4249
|
+
};
|
|
4250
|
+
__name(_ZodNaN, "ZodNaN");
|
|
4251
|
+
var ZodNaN = _ZodNaN;
|
|
4252
|
+
ZodNaN.create = (params) => {
|
|
4253
|
+
return new ZodNaN({
|
|
4254
|
+
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
4255
|
+
...processCreateParams(params)
|
|
4256
|
+
});
|
|
4257
|
+
};
|
|
4258
|
+
var BRAND = Symbol("zod_brand");
|
|
4259
|
+
var _ZodBranded = class _ZodBranded extends ZodType {
|
|
4260
|
+
_parse(input) {
|
|
4261
|
+
const { ctx } = this._processInputParams(input);
|
|
4262
|
+
const data = ctx.data;
|
|
4263
|
+
return this._def.type._parse({
|
|
4264
|
+
data,
|
|
4265
|
+
path: ctx.path,
|
|
4266
|
+
parent: ctx
|
|
4267
|
+
});
|
|
4268
|
+
}
|
|
4269
|
+
unwrap() {
|
|
4270
|
+
return this._def.type;
|
|
4271
|
+
}
|
|
4272
|
+
};
|
|
4273
|
+
__name(_ZodBranded, "ZodBranded");
|
|
4274
|
+
var ZodBranded = _ZodBranded;
|
|
4275
|
+
var _ZodPipeline = class _ZodPipeline extends ZodType {
|
|
4276
|
+
_parse(input) {
|
|
4277
|
+
const { status, ctx } = this._processInputParams(input);
|
|
4278
|
+
if (ctx.common.async) {
|
|
4279
|
+
const handleAsync = /* @__PURE__ */ __name(async () => {
|
|
4280
|
+
const inResult = await this._def.in._parseAsync({
|
|
4281
|
+
data: ctx.data,
|
|
4282
|
+
path: ctx.path,
|
|
4283
|
+
parent: ctx
|
|
4284
|
+
});
|
|
4285
|
+
if (inResult.status === "aborted")
|
|
4286
|
+
return INVALID;
|
|
4287
|
+
if (inResult.status === "dirty") {
|
|
4288
|
+
status.dirty();
|
|
4289
|
+
return DIRTY(inResult.value);
|
|
4290
|
+
} else {
|
|
4291
|
+
return this._def.out._parseAsync({
|
|
4292
|
+
data: inResult.value,
|
|
4293
|
+
path: ctx.path,
|
|
4294
|
+
parent: ctx
|
|
4295
|
+
});
|
|
4296
|
+
}
|
|
4297
|
+
}, "handleAsync");
|
|
4298
|
+
return handleAsync();
|
|
4299
|
+
} else {
|
|
4300
|
+
const inResult = this._def.in._parseSync({
|
|
4301
|
+
data: ctx.data,
|
|
4302
|
+
path: ctx.path,
|
|
4303
|
+
parent: ctx
|
|
4304
|
+
});
|
|
4305
|
+
if (inResult.status === "aborted")
|
|
4306
|
+
return INVALID;
|
|
4307
|
+
if (inResult.status === "dirty") {
|
|
4308
|
+
status.dirty();
|
|
4309
|
+
return {
|
|
4310
|
+
status: "dirty",
|
|
4311
|
+
value: inResult.value
|
|
4312
|
+
};
|
|
4313
|
+
} else {
|
|
4314
|
+
return this._def.out._parseSync({
|
|
4315
|
+
data: inResult.value,
|
|
4316
|
+
path: ctx.path,
|
|
4317
|
+
parent: ctx
|
|
4318
|
+
});
|
|
4319
|
+
}
|
|
4320
|
+
}
|
|
4321
|
+
}
|
|
4322
|
+
static create(a, b) {
|
|
4323
|
+
return new _ZodPipeline({
|
|
4324
|
+
in: a,
|
|
4325
|
+
out: b,
|
|
4326
|
+
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
4327
|
+
});
|
|
4328
|
+
}
|
|
4329
|
+
};
|
|
4330
|
+
__name(_ZodPipeline, "ZodPipeline");
|
|
4331
|
+
var ZodPipeline = _ZodPipeline;
|
|
4332
|
+
var _ZodReadonly = class _ZodReadonly extends ZodType {
|
|
4333
|
+
_parse(input) {
|
|
4334
|
+
const result = this._def.innerType._parse(input);
|
|
4335
|
+
const freeze = /* @__PURE__ */ __name((data) => {
|
|
4336
|
+
if (isValid(data)) {
|
|
4337
|
+
data.value = Object.freeze(data.value);
|
|
4338
|
+
}
|
|
4339
|
+
return data;
|
|
4340
|
+
}, "freeze");
|
|
4341
|
+
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
4342
|
+
}
|
|
4343
|
+
unwrap() {
|
|
4344
|
+
return this._def.innerType;
|
|
4345
|
+
}
|
|
4346
|
+
};
|
|
4347
|
+
__name(_ZodReadonly, "ZodReadonly");
|
|
4348
|
+
var ZodReadonly = _ZodReadonly;
|
|
4349
|
+
ZodReadonly.create = (type, params) => {
|
|
4350
|
+
return new ZodReadonly({
|
|
4351
|
+
innerType: type,
|
|
4352
|
+
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
4353
|
+
...processCreateParams(params)
|
|
4354
|
+
});
|
|
4355
|
+
};
|
|
4356
|
+
function cleanParams(params, data) {
|
|
4357
|
+
const p = typeof params === "function" ? params(data) : typeof params === "string" ? {
|
|
4358
|
+
message: params
|
|
4359
|
+
} : params;
|
|
4360
|
+
const p2 = typeof p === "string" ? {
|
|
4361
|
+
message: p
|
|
4362
|
+
} : p;
|
|
4363
|
+
return p2;
|
|
4364
|
+
}
|
|
4365
|
+
__name(cleanParams, "cleanParams");
|
|
4366
|
+
function custom(check, _params = {}, fatal) {
|
|
4367
|
+
if (check)
|
|
4368
|
+
return ZodAny.create().superRefine((data, ctx) => {
|
|
4369
|
+
const r = check(data);
|
|
4370
|
+
if (r instanceof Promise) {
|
|
4371
|
+
return r.then((r2) => {
|
|
4372
|
+
if (!r2) {
|
|
4373
|
+
const params = cleanParams(_params, data);
|
|
4374
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
4375
|
+
ctx.addIssue({
|
|
4376
|
+
code: "custom",
|
|
4377
|
+
...params,
|
|
4378
|
+
fatal: _fatal
|
|
4379
|
+
});
|
|
4380
|
+
}
|
|
4381
|
+
});
|
|
4382
|
+
}
|
|
4383
|
+
if (!r) {
|
|
4384
|
+
const params = cleanParams(_params, data);
|
|
4385
|
+
const _fatal = params.fatal ?? fatal ?? true;
|
|
4386
|
+
ctx.addIssue({
|
|
4387
|
+
code: "custom",
|
|
4388
|
+
...params,
|
|
4389
|
+
fatal: _fatal
|
|
4390
|
+
});
|
|
4391
|
+
}
|
|
4392
|
+
return;
|
|
4393
|
+
});
|
|
4394
|
+
return ZodAny.create();
|
|
4395
|
+
}
|
|
4396
|
+
__name(custom, "custom");
|
|
4397
|
+
var late = {
|
|
4398
|
+
object: ZodObject.lazycreate
|
|
4399
|
+
};
|
|
4400
|
+
var ZodFirstPartyTypeKind;
|
|
4401
|
+
(function(ZodFirstPartyTypeKind2) {
|
|
4402
|
+
ZodFirstPartyTypeKind2["ZodString"] = "ZodString";
|
|
4403
|
+
ZodFirstPartyTypeKind2["ZodNumber"] = "ZodNumber";
|
|
4404
|
+
ZodFirstPartyTypeKind2["ZodNaN"] = "ZodNaN";
|
|
4405
|
+
ZodFirstPartyTypeKind2["ZodBigInt"] = "ZodBigInt";
|
|
4406
|
+
ZodFirstPartyTypeKind2["ZodBoolean"] = "ZodBoolean";
|
|
4407
|
+
ZodFirstPartyTypeKind2["ZodDate"] = "ZodDate";
|
|
4408
|
+
ZodFirstPartyTypeKind2["ZodSymbol"] = "ZodSymbol";
|
|
4409
|
+
ZodFirstPartyTypeKind2["ZodUndefined"] = "ZodUndefined";
|
|
4410
|
+
ZodFirstPartyTypeKind2["ZodNull"] = "ZodNull";
|
|
4411
|
+
ZodFirstPartyTypeKind2["ZodAny"] = "ZodAny";
|
|
4412
|
+
ZodFirstPartyTypeKind2["ZodUnknown"] = "ZodUnknown";
|
|
4413
|
+
ZodFirstPartyTypeKind2["ZodNever"] = "ZodNever";
|
|
4414
|
+
ZodFirstPartyTypeKind2["ZodVoid"] = "ZodVoid";
|
|
4415
|
+
ZodFirstPartyTypeKind2["ZodArray"] = "ZodArray";
|
|
4416
|
+
ZodFirstPartyTypeKind2["ZodObject"] = "ZodObject";
|
|
4417
|
+
ZodFirstPartyTypeKind2["ZodUnion"] = "ZodUnion";
|
|
4418
|
+
ZodFirstPartyTypeKind2["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
4419
|
+
ZodFirstPartyTypeKind2["ZodIntersection"] = "ZodIntersection";
|
|
4420
|
+
ZodFirstPartyTypeKind2["ZodTuple"] = "ZodTuple";
|
|
4421
|
+
ZodFirstPartyTypeKind2["ZodRecord"] = "ZodRecord";
|
|
4422
|
+
ZodFirstPartyTypeKind2["ZodMap"] = "ZodMap";
|
|
4423
|
+
ZodFirstPartyTypeKind2["ZodSet"] = "ZodSet";
|
|
4424
|
+
ZodFirstPartyTypeKind2["ZodFunction"] = "ZodFunction";
|
|
4425
|
+
ZodFirstPartyTypeKind2["ZodLazy"] = "ZodLazy";
|
|
4426
|
+
ZodFirstPartyTypeKind2["ZodLiteral"] = "ZodLiteral";
|
|
4427
|
+
ZodFirstPartyTypeKind2["ZodEnum"] = "ZodEnum";
|
|
4428
|
+
ZodFirstPartyTypeKind2["ZodEffects"] = "ZodEffects";
|
|
4429
|
+
ZodFirstPartyTypeKind2["ZodNativeEnum"] = "ZodNativeEnum";
|
|
4430
|
+
ZodFirstPartyTypeKind2["ZodOptional"] = "ZodOptional";
|
|
4431
|
+
ZodFirstPartyTypeKind2["ZodNullable"] = "ZodNullable";
|
|
4432
|
+
ZodFirstPartyTypeKind2["ZodDefault"] = "ZodDefault";
|
|
4433
|
+
ZodFirstPartyTypeKind2["ZodCatch"] = "ZodCatch";
|
|
4434
|
+
ZodFirstPartyTypeKind2["ZodPromise"] = "ZodPromise";
|
|
4435
|
+
ZodFirstPartyTypeKind2["ZodBranded"] = "ZodBranded";
|
|
4436
|
+
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
4437
|
+
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
4438
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4439
|
+
var instanceOfType = /* @__PURE__ */ __name((cls, params = {
|
|
4440
|
+
message: `Input not instance of ${cls.name}`
|
|
4441
|
+
}) => custom((data) => data instanceof cls, params), "instanceOfType");
|
|
4442
|
+
var stringType = ZodString.create;
|
|
4443
|
+
var numberType = ZodNumber.create;
|
|
4444
|
+
var nanType = ZodNaN.create;
|
|
4445
|
+
var bigIntType = ZodBigInt.create;
|
|
4446
|
+
var booleanType = ZodBoolean.create;
|
|
4447
|
+
var dateType = ZodDate.create;
|
|
4448
|
+
var symbolType = ZodSymbol.create;
|
|
4449
|
+
var undefinedType = ZodUndefined.create;
|
|
4450
|
+
var nullType = ZodNull.create;
|
|
4451
|
+
var anyType = ZodAny.create;
|
|
4452
|
+
var unknownType = ZodUnknown.create;
|
|
4453
|
+
var neverType = ZodNever.create;
|
|
4454
|
+
var voidType = ZodVoid.create;
|
|
4455
|
+
var arrayType = ZodArray.create;
|
|
4456
|
+
var objectType = ZodObject.create;
|
|
4457
|
+
var strictObjectType = ZodObject.strictCreate;
|
|
4458
|
+
var unionType = ZodUnion.create;
|
|
4459
|
+
var discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4460
|
+
var intersectionType = ZodIntersection.create;
|
|
4461
|
+
var tupleType = ZodTuple.create;
|
|
4462
|
+
var recordType = ZodRecord.create;
|
|
4463
|
+
var mapType = ZodMap.create;
|
|
4464
|
+
var setType = ZodSet.create;
|
|
4465
|
+
var functionType = ZodFunction.create;
|
|
4466
|
+
var lazyType = ZodLazy.create;
|
|
4467
|
+
var literalType = ZodLiteral.create;
|
|
4468
|
+
var enumType = ZodEnum.create;
|
|
4469
|
+
var nativeEnumType = ZodNativeEnum.create;
|
|
4470
|
+
var promiseType = ZodPromise.create;
|
|
4471
|
+
var effectsType = ZodEffects.create;
|
|
4472
|
+
var optionalType = ZodOptional.create;
|
|
4473
|
+
var nullableType = ZodNullable.create;
|
|
4474
|
+
var preprocessType = ZodEffects.createWithPreprocess;
|
|
4475
|
+
var pipelineType = ZodPipeline.create;
|
|
4476
|
+
var ostring = /* @__PURE__ */ __name(() => stringType().optional(), "ostring");
|
|
4477
|
+
var onumber = /* @__PURE__ */ __name(() => numberType().optional(), "onumber");
|
|
4478
|
+
var oboolean = /* @__PURE__ */ __name(() => booleanType().optional(), "oboolean");
|
|
4479
|
+
var coerce = {
|
|
4480
|
+
string: (arg) => ZodString.create({
|
|
4481
|
+
...arg,
|
|
4482
|
+
coerce: true
|
|
4483
|
+
}),
|
|
4484
|
+
number: (arg) => ZodNumber.create({
|
|
4485
|
+
...arg,
|
|
4486
|
+
coerce: true
|
|
4487
|
+
}),
|
|
4488
|
+
boolean: (arg) => ZodBoolean.create({
|
|
4489
|
+
...arg,
|
|
4490
|
+
coerce: true
|
|
4491
|
+
}),
|
|
4492
|
+
bigint: (arg) => ZodBigInt.create({
|
|
4493
|
+
...arg,
|
|
4494
|
+
coerce: true
|
|
4495
|
+
}),
|
|
4496
|
+
date: (arg) => ZodDate.create({
|
|
4497
|
+
...arg,
|
|
4498
|
+
coerce: true
|
|
4499
|
+
})
|
|
4500
|
+
};
|
|
4501
|
+
var NEVER = INVALID;
|
|
4502
|
+
|
|
4503
|
+
// src/lib/mysql/cms-resource-actions.ts
|
|
4504
|
+
var jsonNumber = external_exports.preprocess((value) => value == null ? null : Number(value), external_exports.number().nullable().optional());
|
|
4505
|
+
var CmsImageResourceRowSchema = external_exports.object({
|
|
4506
|
+
id: external_exports.string(),
|
|
4507
|
+
url: external_exports.string(),
|
|
4508
|
+
alt: external_exports.string().optional().nullable(),
|
|
4509
|
+
// Human filename (the uploaded file's name) — the media grid prefers it
|
|
4510
|
+
// over `alt` for the tile label; absent on older rows.
|
|
4511
|
+
name: external_exports.string().optional().nullable(),
|
|
4512
|
+
// Row creation time — the media tab's unified grid sorts by it.
|
|
4513
|
+
createdAt: external_exports.coerce.date().optional().nullable(),
|
|
4514
|
+
// Cloudinary metadata — optional/nullable so pre-metadata rows keep
|
|
4515
|
+
// working (JSON_EXTRACT returns NULL when the key is absent). Numeric
|
|
4516
|
+
// coercion preserves null (plain z.coerce.number() would turn it into 0);
|
|
4517
|
+
// MySQL JSON numerics can arrive as strings through some drivers.
|
|
4518
|
+
width: jsonNumber,
|
|
4519
|
+
height: jsonNumber,
|
|
4520
|
+
bytes: jsonNumber,
|
|
4521
|
+
format: external_exports.string().optional().nullable()
|
|
4522
|
+
});
|
|
4523
|
+
var ListResourcesForPickerInputSchema = external_exports.object({
|
|
4524
|
+
types: external_exports.array(external_exports.string()).min(1),
|
|
4525
|
+
search: external_exports.string().trim().max(200).optional(),
|
|
4526
|
+
excludeIds: external_exports.array(external_exports.string()).default([]),
|
|
4527
|
+
limit: external_exports.number().int().min(1).max(100).default(20)
|
|
4528
|
+
});
|
|
4529
|
+
function createCmsResourceActions(options) {
|
|
4530
|
+
const { db, contentResource, contentResourceResource, contentResourceProduct, getAuthContext, getEditHref } = options;
|
|
4531
|
+
const dbQuery = db.query;
|
|
4532
|
+
async function assertCanUpdateContent() {
|
|
4533
|
+
const { session, ability } = await getAuthContext();
|
|
4534
|
+
if (!session?.user || !ability.can("update", "Content")) {
|
|
4535
|
+
throw new Error("Unauthorized");
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
__name(assertCanUpdateContent, "assertCanUpdateContent");
|
|
4539
|
+
async function listResourcesForPicker(input) {
|
|
4540
|
+
await assertCanUpdateContent();
|
|
4541
|
+
const { types, search, excludeIds, limit } = ListResourcesForPickerInputSchema.parse(input);
|
|
4542
|
+
const conditions = [
|
|
4543
|
+
(0, import_drizzle_orm.inArray)(contentResource.type, types),
|
|
4544
|
+
(0, import_drizzle_orm.isNull)(contentResource.deletedAt)
|
|
4545
|
+
];
|
|
4546
|
+
if (excludeIds.length > 0) {
|
|
4547
|
+
conditions.push((0, import_drizzle_orm.notInArray)(contentResource.id, excludeIds));
|
|
4548
|
+
}
|
|
4549
|
+
if (search) {
|
|
4550
|
+
const escaped = search.replace(/[\\%_]/g, "\\$&");
|
|
4551
|
+
conditions.push(import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title')) LIKE ${`%${escaped}%`}`);
|
|
4552
|
+
}
|
|
4553
|
+
const rows = await db.select({
|
|
4554
|
+
id: contentResource.id,
|
|
4555
|
+
type: contentResource.type,
|
|
4556
|
+
title: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.title'))`,
|
|
4557
|
+
// Generated (indexed) column — cheaper than a JSON_EXTRACT here.
|
|
4558
|
+
slug: contentResource.slug,
|
|
4559
|
+
state: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
|
|
4560
|
+
postType: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.postType'))`,
|
|
4561
|
+
updatedAt: contentResource.updatedAt
|
|
4562
|
+
}).from(contentResource).where((0, import_drizzle_orm.and)(...conditions)).orderBy((0, import_drizzle_orm.desc)(contentResource.updatedAt)).limit(limit);
|
|
4563
|
+
return rows.map((row) => ({
|
|
4564
|
+
id: row.id,
|
|
4565
|
+
type: row.type,
|
|
4566
|
+
title: row.title ?? row.slug ?? row.id,
|
|
4567
|
+
slug: row.slug ?? "",
|
|
4568
|
+
state: row.state ?? "draft",
|
|
4569
|
+
detail: row.postType ?? void 0,
|
|
4570
|
+
updatedAt: row.updatedAt ?? void 0
|
|
4571
|
+
}));
|
|
4572
|
+
}
|
|
4573
|
+
__name(listResourcesForPicker, "listResourcesForPicker");
|
|
4574
|
+
async function listVideoResourcesForPicker(input) {
|
|
4575
|
+
await assertCanUpdateContent();
|
|
4576
|
+
const excludeIds = input.excludeIds ?? [];
|
|
4577
|
+
const limit = Math.min(Math.max(input.limit ?? 20, 1), 200);
|
|
4578
|
+
const offset = Math.max(0, Math.floor(input.offset ?? 0));
|
|
4579
|
+
const conditions = [
|
|
4580
|
+
(0, import_drizzle_orm.eq)(contentResource.type, "videoResource"),
|
|
4581
|
+
(0, import_drizzle_orm.isNull)(contentResource.deletedAt)
|
|
4582
|
+
];
|
|
4583
|
+
if (excludeIds.length > 0) {
|
|
4584
|
+
conditions.push((0, import_drizzle_orm.notInArray)(contentResource.id, excludeIds));
|
|
4585
|
+
}
|
|
4586
|
+
if (input.search) {
|
|
4587
|
+
const escaped = input.search.replace(/[\\%_]/g, "\\$&");
|
|
4588
|
+
conditions.push(import_drizzle_orm.sql`${contentResource.id} LIKE ${`%${escaped}%`}`);
|
|
4589
|
+
}
|
|
4590
|
+
const pageRows = await db.select({
|
|
4591
|
+
id: contentResource.id,
|
|
4592
|
+
createdAt: contentResource.createdAt
|
|
4593
|
+
}).from(contentResource).where((0, import_drizzle_orm.and)(...conditions)).orderBy((0, import_drizzle_orm.desc)(contentResource.createdAt)).limit(offset + limit + 50);
|
|
4594
|
+
if (pageRows.length === 0)
|
|
4595
|
+
return [];
|
|
4596
|
+
const detailRows = await db.select({
|
|
4597
|
+
id: contentResource.id,
|
|
4598
|
+
state: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.state'))`,
|
|
4599
|
+
muxPlaybackId: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.muxPlaybackId'))`,
|
|
4600
|
+
duration: import_drizzle_orm.sql`JSON_EXTRACT(${contentResource.fields}, '$.duration')`,
|
|
4601
|
+
createdAt: contentResource.createdAt
|
|
4602
|
+
}).from(contentResource).where((0, import_drizzle_orm.inArray)(contentResource.id, pageRows.map((row) => row.id)));
|
|
4603
|
+
const byId = new Map(detailRows.map((row) => [
|
|
4604
|
+
row.id,
|
|
4605
|
+
row
|
|
4606
|
+
]));
|
|
4607
|
+
const rows = pageRows.flatMap((page) => byId.get(page.id) ?? []).filter((row) => row.state !== "deleted" && row.state !== "errored").slice(offset, offset + limit);
|
|
4608
|
+
return rows.map((row) => ({
|
|
4609
|
+
id: row.id,
|
|
4610
|
+
// videoResources have no title/slug — the filename-derived id is the
|
|
4611
|
+
// human-readable handle.
|
|
4612
|
+
title: row.id,
|
|
4613
|
+
state: row.state ?? "processing",
|
|
4614
|
+
thumbnailUrl: row.muxPlaybackId ? `https://image.mux.com/${row.muxPlaybackId}/thumbnail.png?width=96&height=54&fit_mode=smartcrop` : void 0,
|
|
4615
|
+
duration: row.duration != null ? Number(row.duration) : null,
|
|
4616
|
+
createdAt: row.createdAt
|
|
4617
|
+
}));
|
|
4618
|
+
}
|
|
4619
|
+
__name(listVideoResourcesForPicker, "listVideoResourcesForPicker");
|
|
4620
|
+
async function listImageResources({ limit, offset = 0 }) {
|
|
4621
|
+
const capped = Math.min(Math.max(1, Math.floor(limit)), 200);
|
|
4622
|
+
const skip = Math.max(0, Math.floor(offset));
|
|
4623
|
+
const rows = await db.select({
|
|
4624
|
+
id: contentResource.id,
|
|
4625
|
+
url: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.url'))`,
|
|
4626
|
+
alt: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.alt'))`,
|
|
4627
|
+
name: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.name'))`,
|
|
4628
|
+
createdAt: contentResource.createdAt,
|
|
4629
|
+
// Cloudinary metadata — NULL on pre-metadata rows (backfillable).
|
|
4630
|
+
width: import_drizzle_orm.sql`JSON_EXTRACT(${contentResource.fields}, '$.width')`,
|
|
4631
|
+
height: import_drizzle_orm.sql`JSON_EXTRACT(${contentResource.fields}, '$.height')`,
|
|
4632
|
+
bytes: import_drizzle_orm.sql`JSON_EXTRACT(${contentResource.fields}, '$.bytes')`,
|
|
4633
|
+
format: import_drizzle_orm.sql`JSON_UNQUOTE(JSON_EXTRACT(${contentResource.fields}, '$.format'))`
|
|
4634
|
+
}).from(contentResource).where((0, import_drizzle_orm.eq)(contentResource.type, "imageResource")).orderBy((0, import_drizzle_orm.desc)(contentResource.createdAt)).limit(capped).offset(skip);
|
|
4635
|
+
const parsed = external_exports.array(CmsImageResourceRowSchema).safeParse(rows);
|
|
4636
|
+
return parsed.success ? parsed.data : [];
|
|
4637
|
+
}
|
|
4638
|
+
__name(listImageResources, "listImageResources");
|
|
4639
|
+
async function getPostListMemberships(postId) {
|
|
4640
|
+
await assertCanUpdateContent();
|
|
4641
|
+
const links = await dbQuery.contentResourceResource.findMany({
|
|
4642
|
+
where: (0, import_drizzle_orm.and)((0, import_drizzle_orm.eq)(contentResourceResource.resourceId, postId), (0, import_drizzle_orm.isNull)(contentResourceResource.deletedAt)),
|
|
4643
|
+
with: {
|
|
4644
|
+
resourceOf: true
|
|
4645
|
+
}
|
|
4646
|
+
});
|
|
4647
|
+
return links.filter((link) => link.resourceOf?.type === "list" && !link.resourceOf.deletedAt).map((link) => {
|
|
4648
|
+
const fields = link.resourceOf.fields ?? {};
|
|
4649
|
+
return {
|
|
4650
|
+
listId: link.resourceOf.id,
|
|
4651
|
+
title: fields.title ?? fields.slug ?? link.resourceOf.id,
|
|
4652
|
+
slug: fields.slug ?? void 0,
|
|
4653
|
+
href: fields.slug ? getEditHref("list", fields.slug) : void 0,
|
|
4654
|
+
position: link.position
|
|
4655
|
+
};
|
|
4656
|
+
});
|
|
4657
|
+
}
|
|
4658
|
+
__name(getPostListMemberships, "getPostListMemberships");
|
|
4659
|
+
async function getResourceParents(resourceId) {
|
|
4660
|
+
await assertCanUpdateContent();
|
|
4661
|
+
const [containerLinks, productLinks] = await Promise.all([
|
|
4662
|
+
dbQuery.contentResourceResource.findMany({
|
|
4663
|
+
where: (0, import_drizzle_orm.eq)(contentResourceResource.resourceId, resourceId),
|
|
4664
|
+
with: {
|
|
4665
|
+
resourceOf: {
|
|
4666
|
+
with: {
|
|
4667
|
+
// Sibling JOIN rows only (no nested resource objects) —
|
|
4668
|
+
// cheap, and enough to compute this resource's ordinal.
|
|
4669
|
+
resources: {
|
|
4670
|
+
orderBy: (0, import_drizzle_orm.asc)(contentResourceResource.position)
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4675
|
+
}),
|
|
4676
|
+
dbQuery.contentResourceProduct.findMany({
|
|
4677
|
+
where: (0, import_drizzle_orm.and)((0, import_drizzle_orm.eq)(contentResourceProduct.resourceId, resourceId), (0, import_drizzle_orm.isNull)(contentResourceProduct.deletedAt)),
|
|
4678
|
+
with: {
|
|
4679
|
+
product: true
|
|
4680
|
+
}
|
|
4681
|
+
})
|
|
4682
|
+
]);
|
|
4683
|
+
const parents = [];
|
|
4684
|
+
for (const link of containerLinks) {
|
|
4685
|
+
const parent = link.resourceOf;
|
|
4686
|
+
if (!parent || parent.deletedAt)
|
|
4687
|
+
continue;
|
|
4688
|
+
if (parent.type === "videoResource")
|
|
4689
|
+
continue;
|
|
4690
|
+
const slug = parent.fields?.slug ?? "";
|
|
4691
|
+
const siblings = parent.resources ?? [];
|
|
4692
|
+
const index = siblings.findIndex((sibling) => sibling.resourceId === resourceId);
|
|
4693
|
+
parents.push({
|
|
4694
|
+
id: parent.id,
|
|
4695
|
+
type: parent.type,
|
|
4696
|
+
title: parent.fields?.title ?? (slug || parent.id),
|
|
4697
|
+
href: getEditHref(parent.type, slug || parent.id),
|
|
4698
|
+
...index !== -1 && {
|
|
4699
|
+
detail: `#${index + 1} of ${siblings.length}`
|
|
4700
|
+
}
|
|
4701
|
+
});
|
|
4702
|
+
}
|
|
4703
|
+
for (const link of productLinks) {
|
|
4704
|
+
const product = link.product;
|
|
4705
|
+
if (!product)
|
|
4706
|
+
continue;
|
|
4707
|
+
const slug = product.fields?.slug ?? "";
|
|
4708
|
+
parents.push({
|
|
4709
|
+
id: product.id,
|
|
4710
|
+
type: "product",
|
|
4711
|
+
title: product.name,
|
|
4712
|
+
// Products aren't in the resource-paths registries; every app's
|
|
4713
|
+
// product editor lives at /products/[slug]/edit.
|
|
4714
|
+
href: `/products/${slug || product.id}/edit`
|
|
4715
|
+
});
|
|
4716
|
+
}
|
|
4717
|
+
return parents;
|
|
4718
|
+
}
|
|
4719
|
+
__name(getResourceParents, "getResourceParents");
|
|
4720
|
+
return {
|
|
4721
|
+
listResourcesForPicker,
|
|
4722
|
+
listVideoResourcesForPicker,
|
|
4723
|
+
listImageResources,
|
|
4724
|
+
getPostListMemberships,
|
|
4725
|
+
getResourceParents
|
|
4726
|
+
};
|
|
4727
|
+
}
|
|
4728
|
+
__name(createCmsResourceActions, "createCmsResourceActions");
|
|
4729
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
4730
|
+
0 && (module.exports = {
|
|
4731
|
+
createCmsResourceActions
|
|
4732
|
+
});
|
|
4733
|
+
//# sourceMappingURL=cms-resource-actions.cjs.map
|