@scout9/app 1.0.0-alpha.0.2.4 → 1.0.0-alpha.0.2.6
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/{dev-73ac7343.cjs → dev-170fa3f5.cjs} +18 -4683
- package/dist/{index-6fd2c8cd.cjs → index-44e73470.cjs} +16 -15
- package/dist/index.cjs +3 -52
- package/dist/macros-eff64992.cjs +4588 -0
- package/dist/{multipart-parser-a55dfbdc.cjs → multipart-parser-bd1fae8a.cjs} +3 -2
- package/dist/schemas.cjs +55 -0
- package/dist/testing-tools.cjs +2 -1
- package/package.json +6 -1
- package/src/core/templates/app.js +17 -6
- package/src/exports.js +0 -1
- package/src/public.d.ts +2 -2
- package/src/runtime/client/api.js +1 -1
- package/src/runtime/schemas/api.js +0 -8
- package/src/runtime/schemas/platform.js +2 -46
- package/src/runtime/schemas/users.js +0 -16
- package/src/schemas.js +1 -0
- package/types/index.d.ts +14708 -2
- package/types/index.d.ts.map +64 -3
|
@@ -23,6 +23,7 @@ var Stream = require('node:stream');
|
|
|
23
23
|
var node_string_decoder = require('node:string_decoder');
|
|
24
24
|
var readline = require('node:readline');
|
|
25
25
|
var process$2 = require('node:process');
|
|
26
|
+
var macros = require("./macros-eff64992.cjs");
|
|
26
27
|
var node_os = require('node:os');
|
|
27
28
|
var promises = require('fs/promises');
|
|
28
29
|
|
|
@@ -176,4009 +177,6 @@ function init$1(open, close) {
|
|
|
176
177
|
};
|
|
177
178
|
}
|
|
178
179
|
|
|
179
|
-
var util$5;
|
|
180
|
-
(function (util) {
|
|
181
|
-
util.assertEqual = val => val;
|
|
182
|
-
function assertIs(_arg) {}
|
|
183
|
-
util.assertIs = assertIs;
|
|
184
|
-
function assertNever(_x) {
|
|
185
|
-
throw new Error();
|
|
186
|
-
}
|
|
187
|
-
util.assertNever = assertNever;
|
|
188
|
-
util.arrayToEnum = items => {
|
|
189
|
-
const obj = {};
|
|
190
|
-
for (const item of items) {
|
|
191
|
-
obj[item] = item;
|
|
192
|
-
}
|
|
193
|
-
return obj;
|
|
194
|
-
};
|
|
195
|
-
util.getValidEnumValues = obj => {
|
|
196
|
-
const validKeys = util.objectKeys(obj).filter(k => typeof obj[obj[k]] !== "number");
|
|
197
|
-
const filtered = {};
|
|
198
|
-
for (const k of validKeys) {
|
|
199
|
-
filtered[k] = obj[k];
|
|
200
|
-
}
|
|
201
|
-
return util.objectValues(filtered);
|
|
202
|
-
};
|
|
203
|
-
util.objectValues = obj => {
|
|
204
|
-
return util.objectKeys(obj).map(function (e) {
|
|
205
|
-
return obj[e];
|
|
206
|
-
});
|
|
207
|
-
};
|
|
208
|
-
util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
|
|
209
|
-
? obj => Object.keys(obj) // eslint-disable-line ban/ban
|
|
210
|
-
: object => {
|
|
211
|
-
const keys = [];
|
|
212
|
-
for (const key in object) {
|
|
213
|
-
if (Object.prototype.hasOwnProperty.call(object, key)) {
|
|
214
|
-
keys.push(key);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
return keys;
|
|
218
|
-
};
|
|
219
|
-
util.find = (arr, checker) => {
|
|
220
|
-
for (const item of arr) {
|
|
221
|
-
if (checker(item)) return item;
|
|
222
|
-
}
|
|
223
|
-
return undefined;
|
|
224
|
-
};
|
|
225
|
-
util.isInteger = typeof Number.isInteger === "function" ? val => Number.isInteger(val) // eslint-disable-line ban/ban
|
|
226
|
-
: val => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
|
|
227
|
-
function joinValues(array, separator = " | ") {
|
|
228
|
-
return array.map(val => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
229
|
-
}
|
|
230
|
-
util.joinValues = joinValues;
|
|
231
|
-
util.jsonStringifyReplacer = (_, value) => {
|
|
232
|
-
if (typeof value === "bigint") {
|
|
233
|
-
return value.toString();
|
|
234
|
-
}
|
|
235
|
-
return value;
|
|
236
|
-
};
|
|
237
|
-
})(util$5 || (util$5 = {}));
|
|
238
|
-
var objectUtil;
|
|
239
|
-
(function (objectUtil) {
|
|
240
|
-
objectUtil.mergeShapes = (first, second) => {
|
|
241
|
-
return {
|
|
242
|
-
...first,
|
|
243
|
-
...second // second overwrites first
|
|
244
|
-
};
|
|
245
|
-
};
|
|
246
|
-
})(objectUtil || (objectUtil = {}));
|
|
247
|
-
const ZodParsedType = util$5.arrayToEnum(["string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set"]);
|
|
248
|
-
const getParsedType = data => {
|
|
249
|
-
const t = typeof data;
|
|
250
|
-
switch (t) {
|
|
251
|
-
case "undefined":
|
|
252
|
-
return ZodParsedType.undefined;
|
|
253
|
-
case "string":
|
|
254
|
-
return ZodParsedType.string;
|
|
255
|
-
case "number":
|
|
256
|
-
return isNaN(data) ? ZodParsedType.nan : ZodParsedType.number;
|
|
257
|
-
case "boolean":
|
|
258
|
-
return ZodParsedType.boolean;
|
|
259
|
-
case "function":
|
|
260
|
-
return ZodParsedType.function;
|
|
261
|
-
case "bigint":
|
|
262
|
-
return ZodParsedType.bigint;
|
|
263
|
-
case "symbol":
|
|
264
|
-
return ZodParsedType.symbol;
|
|
265
|
-
case "object":
|
|
266
|
-
if (Array.isArray(data)) {
|
|
267
|
-
return ZodParsedType.array;
|
|
268
|
-
}
|
|
269
|
-
if (data === null) {
|
|
270
|
-
return ZodParsedType.null;
|
|
271
|
-
}
|
|
272
|
-
if (data.then && typeof data.then === "function" && data.catch && typeof data.catch === "function") {
|
|
273
|
-
return ZodParsedType.promise;
|
|
274
|
-
}
|
|
275
|
-
if (typeof Map !== "undefined" && data instanceof Map) {
|
|
276
|
-
return ZodParsedType.map;
|
|
277
|
-
}
|
|
278
|
-
if (typeof Set !== "undefined" && data instanceof Set) {
|
|
279
|
-
return ZodParsedType.set;
|
|
280
|
-
}
|
|
281
|
-
if (typeof Date !== "undefined" && data instanceof Date) {
|
|
282
|
-
return ZodParsedType.date;
|
|
283
|
-
}
|
|
284
|
-
return ZodParsedType.object;
|
|
285
|
-
default:
|
|
286
|
-
return ZodParsedType.unknown;
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
const ZodIssueCode = util$5.arrayToEnum(["invalid_type", "invalid_literal", "custom", "invalid_union", "invalid_union_discriminator", "invalid_enum_value", "unrecognized_keys", "invalid_arguments", "invalid_return_type", "invalid_date", "invalid_string", "too_small", "too_big", "invalid_intersection_types", "not_multiple_of", "not_finite"]);
|
|
290
|
-
const quotelessJson = obj => {
|
|
291
|
-
const json = JSON.stringify(obj, null, 2);
|
|
292
|
-
return json.replace(/"([^"]+)":/g, "$1:");
|
|
293
|
-
};
|
|
294
|
-
class ZodError extends Error {
|
|
295
|
-
constructor(issues) {
|
|
296
|
-
super();
|
|
297
|
-
this.issues = [];
|
|
298
|
-
this.addIssue = sub => {
|
|
299
|
-
this.issues = [...this.issues, sub];
|
|
300
|
-
};
|
|
301
|
-
this.addIssues = (subs = []) => {
|
|
302
|
-
this.issues = [...this.issues, ...subs];
|
|
303
|
-
};
|
|
304
|
-
const actualProto = new.target.prototype;
|
|
305
|
-
if (Object.setPrototypeOf) {
|
|
306
|
-
// eslint-disable-next-line ban/ban
|
|
307
|
-
Object.setPrototypeOf(this, actualProto);
|
|
308
|
-
} else {
|
|
309
|
-
this.__proto__ = actualProto;
|
|
310
|
-
}
|
|
311
|
-
this.name = "ZodError";
|
|
312
|
-
this.issues = issues;
|
|
313
|
-
}
|
|
314
|
-
get errors() {
|
|
315
|
-
return this.issues;
|
|
316
|
-
}
|
|
317
|
-
format(_mapper) {
|
|
318
|
-
const mapper = _mapper || function (issue) {
|
|
319
|
-
return issue.message;
|
|
320
|
-
};
|
|
321
|
-
const fieldErrors = {
|
|
322
|
-
_errors: []
|
|
323
|
-
};
|
|
324
|
-
const processError = error => {
|
|
325
|
-
for (const issue of error.issues) {
|
|
326
|
-
if (issue.code === "invalid_union") {
|
|
327
|
-
issue.unionErrors.map(processError);
|
|
328
|
-
} else if (issue.code === "invalid_return_type") {
|
|
329
|
-
processError(issue.returnTypeError);
|
|
330
|
-
} else if (issue.code === "invalid_arguments") {
|
|
331
|
-
processError(issue.argumentsError);
|
|
332
|
-
} else if (issue.path.length === 0) {
|
|
333
|
-
fieldErrors._errors.push(mapper(issue));
|
|
334
|
-
} else {
|
|
335
|
-
let curr = fieldErrors;
|
|
336
|
-
let i = 0;
|
|
337
|
-
while (i < issue.path.length) {
|
|
338
|
-
const el = issue.path[i];
|
|
339
|
-
const terminal = i === issue.path.length - 1;
|
|
340
|
-
if (!terminal) {
|
|
341
|
-
curr[el] = curr[el] || {
|
|
342
|
-
_errors: []
|
|
343
|
-
};
|
|
344
|
-
// if (typeof el === "string") {
|
|
345
|
-
// curr[el] = curr[el] || { _errors: [] };
|
|
346
|
-
// } else if (typeof el === "number") {
|
|
347
|
-
// const errorArray: any = [];
|
|
348
|
-
// errorArray._errors = [];
|
|
349
|
-
// curr[el] = curr[el] || errorArray;
|
|
350
|
-
// }
|
|
351
|
-
} else {
|
|
352
|
-
curr[el] = curr[el] || {
|
|
353
|
-
_errors: []
|
|
354
|
-
};
|
|
355
|
-
curr[el]._errors.push(mapper(issue));
|
|
356
|
-
}
|
|
357
|
-
curr = curr[el];
|
|
358
|
-
i++;
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
};
|
|
363
|
-
processError(this);
|
|
364
|
-
return fieldErrors;
|
|
365
|
-
}
|
|
366
|
-
toString() {
|
|
367
|
-
return this.message;
|
|
368
|
-
}
|
|
369
|
-
get message() {
|
|
370
|
-
return JSON.stringify(this.issues, util$5.jsonStringifyReplacer, 2);
|
|
371
|
-
}
|
|
372
|
-
get isEmpty() {
|
|
373
|
-
return this.issues.length === 0;
|
|
374
|
-
}
|
|
375
|
-
flatten(mapper = issue => issue.message) {
|
|
376
|
-
const fieldErrors = {};
|
|
377
|
-
const formErrors = [];
|
|
378
|
-
for (const sub of this.issues) {
|
|
379
|
-
if (sub.path.length > 0) {
|
|
380
|
-
fieldErrors[sub.path[0]] = fieldErrors[sub.path[0]] || [];
|
|
381
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
382
|
-
} else {
|
|
383
|
-
formErrors.push(mapper(sub));
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
return {
|
|
387
|
-
formErrors,
|
|
388
|
-
fieldErrors
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
get formErrors() {
|
|
392
|
-
return this.flatten();
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
ZodError.create = issues => {
|
|
396
|
-
const error = new ZodError(issues);
|
|
397
|
-
return error;
|
|
398
|
-
};
|
|
399
|
-
const errorMap = (issue, _ctx) => {
|
|
400
|
-
let message;
|
|
401
|
-
switch (issue.code) {
|
|
402
|
-
case ZodIssueCode.invalid_type:
|
|
403
|
-
if (issue.received === ZodParsedType.undefined) {
|
|
404
|
-
message = "Required";
|
|
405
|
-
} else {
|
|
406
|
-
message = `Expected ${issue.expected}, received ${issue.received}`;
|
|
407
|
-
}
|
|
408
|
-
break;
|
|
409
|
-
case ZodIssueCode.invalid_literal:
|
|
410
|
-
message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util$5.jsonStringifyReplacer)}`;
|
|
411
|
-
break;
|
|
412
|
-
case ZodIssueCode.unrecognized_keys:
|
|
413
|
-
message = `Unrecognized key(s) in object: ${util$5.joinValues(issue.keys, ", ")}`;
|
|
414
|
-
break;
|
|
415
|
-
case ZodIssueCode.invalid_union:
|
|
416
|
-
message = `Invalid input`;
|
|
417
|
-
break;
|
|
418
|
-
case ZodIssueCode.invalid_union_discriminator:
|
|
419
|
-
message = `Invalid discriminator value. Expected ${util$5.joinValues(issue.options)}`;
|
|
420
|
-
break;
|
|
421
|
-
case ZodIssueCode.invalid_enum_value:
|
|
422
|
-
message = `Invalid enum value. Expected ${util$5.joinValues(issue.options)}, received '${issue.received}'`;
|
|
423
|
-
break;
|
|
424
|
-
case ZodIssueCode.invalid_arguments:
|
|
425
|
-
message = `Invalid function arguments`;
|
|
426
|
-
break;
|
|
427
|
-
case ZodIssueCode.invalid_return_type:
|
|
428
|
-
message = `Invalid function return type`;
|
|
429
|
-
break;
|
|
430
|
-
case ZodIssueCode.invalid_date:
|
|
431
|
-
message = `Invalid date`;
|
|
432
|
-
break;
|
|
433
|
-
case ZodIssueCode.invalid_string:
|
|
434
|
-
if (typeof issue.validation === "object") {
|
|
435
|
-
if ("includes" in issue.validation) {
|
|
436
|
-
message = `Invalid input: must include "${issue.validation.includes}"`;
|
|
437
|
-
if (typeof issue.validation.position === "number") {
|
|
438
|
-
message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
|
|
439
|
-
}
|
|
440
|
-
} else if ("startsWith" in issue.validation) {
|
|
441
|
-
message = `Invalid input: must start with "${issue.validation.startsWith}"`;
|
|
442
|
-
} else if ("endsWith" in issue.validation) {
|
|
443
|
-
message = `Invalid input: must end with "${issue.validation.endsWith}"`;
|
|
444
|
-
} else {
|
|
445
|
-
util$5.assertNever(issue.validation);
|
|
446
|
-
}
|
|
447
|
-
} else if (issue.validation !== "regex") {
|
|
448
|
-
message = `Invalid ${issue.validation}`;
|
|
449
|
-
} else {
|
|
450
|
-
message = "Invalid";
|
|
451
|
-
}
|
|
452
|
-
break;
|
|
453
|
-
case ZodIssueCode.too_small:
|
|
454
|
-
if (issue.type === "array") message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;else if (issue.type === "string") message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${issue.minimum}`;else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly equal to ` : issue.inclusive ? `greater than or equal to ` : `greater than `}${new Date(Number(issue.minimum))}`;else message = "Invalid input";
|
|
455
|
-
break;
|
|
456
|
-
case ZodIssueCode.too_big:
|
|
457
|
-
if (issue.type === "array") message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;else if (issue.type === "string") message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;else if (issue.type === "number") message = `Number must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;else if (issue.type === "bigint") message = `BigInt must be ${issue.exact ? `exactly` : issue.inclusive ? `less than or equal to` : `less than`} ${issue.maximum}`;else if (issue.type === "date") message = `Date must be ${issue.exact ? `exactly` : issue.inclusive ? `smaller than or equal to` : `smaller than`} ${new Date(Number(issue.maximum))}`;else message = "Invalid input";
|
|
458
|
-
break;
|
|
459
|
-
case ZodIssueCode.custom:
|
|
460
|
-
message = `Invalid input`;
|
|
461
|
-
break;
|
|
462
|
-
case ZodIssueCode.invalid_intersection_types:
|
|
463
|
-
message = `Intersection results could not be merged`;
|
|
464
|
-
break;
|
|
465
|
-
case ZodIssueCode.not_multiple_of:
|
|
466
|
-
message = `Number must be a multiple of ${issue.multipleOf}`;
|
|
467
|
-
break;
|
|
468
|
-
case ZodIssueCode.not_finite:
|
|
469
|
-
message = "Number must be finite";
|
|
470
|
-
break;
|
|
471
|
-
default:
|
|
472
|
-
message = _ctx.defaultError;
|
|
473
|
-
util$5.assertNever(issue);
|
|
474
|
-
}
|
|
475
|
-
return {
|
|
476
|
-
message
|
|
477
|
-
};
|
|
478
|
-
};
|
|
479
|
-
let overrideErrorMap = errorMap;
|
|
480
|
-
function setErrorMap(map) {
|
|
481
|
-
overrideErrorMap = map;
|
|
482
|
-
}
|
|
483
|
-
function getErrorMap() {
|
|
484
|
-
return overrideErrorMap;
|
|
485
|
-
}
|
|
486
|
-
const makeIssue = params => {
|
|
487
|
-
const {
|
|
488
|
-
data,
|
|
489
|
-
path,
|
|
490
|
-
errorMaps,
|
|
491
|
-
issueData
|
|
492
|
-
} = params;
|
|
493
|
-
const fullPath = [...path, ...(issueData.path || [])];
|
|
494
|
-
const fullIssue = {
|
|
495
|
-
...issueData,
|
|
496
|
-
path: fullPath
|
|
497
|
-
};
|
|
498
|
-
let errorMessage = "";
|
|
499
|
-
const maps = errorMaps.filter(m => !!m).slice().reverse();
|
|
500
|
-
for (const map of maps) {
|
|
501
|
-
errorMessage = map(fullIssue, {
|
|
502
|
-
data,
|
|
503
|
-
defaultError: errorMessage
|
|
504
|
-
}).message;
|
|
505
|
-
}
|
|
506
|
-
return {
|
|
507
|
-
...issueData,
|
|
508
|
-
path: fullPath,
|
|
509
|
-
message: issueData.message || errorMessage
|
|
510
|
-
};
|
|
511
|
-
};
|
|
512
|
-
const EMPTY_PATH = [];
|
|
513
|
-
function addIssueToContext(ctx, issueData) {
|
|
514
|
-
const issue = makeIssue({
|
|
515
|
-
issueData: issueData,
|
|
516
|
-
data: ctx.data,
|
|
517
|
-
path: ctx.path,
|
|
518
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap // then global default map
|
|
519
|
-
].filter(x => !!x)
|
|
520
|
-
});
|
|
521
|
-
ctx.common.issues.push(issue);
|
|
522
|
-
}
|
|
523
|
-
class ParseStatus {
|
|
524
|
-
constructor() {
|
|
525
|
-
this.value = "valid";
|
|
526
|
-
}
|
|
527
|
-
dirty() {
|
|
528
|
-
if (this.value === "valid") this.value = "dirty";
|
|
529
|
-
}
|
|
530
|
-
abort() {
|
|
531
|
-
if (this.value !== "aborted") this.value = "aborted";
|
|
532
|
-
}
|
|
533
|
-
static mergeArray(status, results) {
|
|
534
|
-
const arrayValue = [];
|
|
535
|
-
for (const s of results) {
|
|
536
|
-
if (s.status === "aborted") return INVALID;
|
|
537
|
-
if (s.status === "dirty") status.dirty();
|
|
538
|
-
arrayValue.push(s.value);
|
|
539
|
-
}
|
|
540
|
-
return {
|
|
541
|
-
status: status.value,
|
|
542
|
-
value: arrayValue
|
|
543
|
-
};
|
|
544
|
-
}
|
|
545
|
-
static async mergeObjectAsync(status, pairs) {
|
|
546
|
-
const syncPairs = [];
|
|
547
|
-
for (const pair of pairs) {
|
|
548
|
-
syncPairs.push({
|
|
549
|
-
key: await pair.key,
|
|
550
|
-
value: await pair.value
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
554
|
-
}
|
|
555
|
-
static mergeObjectSync(status, pairs) {
|
|
556
|
-
const finalObject = {};
|
|
557
|
-
for (const pair of pairs) {
|
|
558
|
-
const {
|
|
559
|
-
key,
|
|
560
|
-
value
|
|
561
|
-
} = pair;
|
|
562
|
-
if (key.status === "aborted") return INVALID;
|
|
563
|
-
if (value.status === "aborted") return INVALID;
|
|
564
|
-
if (key.status === "dirty") status.dirty();
|
|
565
|
-
if (value.status === "dirty") status.dirty();
|
|
566
|
-
if (key.value !== "__proto__" && (typeof value.value !== "undefined" || pair.alwaysSet)) {
|
|
567
|
-
finalObject[key.value] = value.value;
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
return {
|
|
571
|
-
status: status.value,
|
|
572
|
-
value: finalObject
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
const INVALID = Object.freeze({
|
|
577
|
-
status: "aborted"
|
|
578
|
-
});
|
|
579
|
-
const DIRTY = value => ({
|
|
580
|
-
status: "dirty",
|
|
581
|
-
value
|
|
582
|
-
});
|
|
583
|
-
const OK = value => ({
|
|
584
|
-
status: "valid",
|
|
585
|
-
value
|
|
586
|
-
});
|
|
587
|
-
const isAborted = x => x.status === "aborted";
|
|
588
|
-
const isDirty = x => x.status === "dirty";
|
|
589
|
-
const isValid = x => x.status === "valid";
|
|
590
|
-
const isAsync = x => typeof Promise !== "undefined" && x instanceof Promise;
|
|
591
|
-
var errorUtil;
|
|
592
|
-
(function (errorUtil) {
|
|
593
|
-
errorUtil.errToObj = message => typeof message === "string" ? {
|
|
594
|
-
message
|
|
595
|
-
} : message || {};
|
|
596
|
-
errorUtil.toString = message => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
|
|
597
|
-
})(errorUtil || (errorUtil = {}));
|
|
598
|
-
class ParseInputLazyPath {
|
|
599
|
-
constructor(parent, value, path, key) {
|
|
600
|
-
this._cachedPath = [];
|
|
601
|
-
this.parent = parent;
|
|
602
|
-
this.data = value;
|
|
603
|
-
this._path = path;
|
|
604
|
-
this._key = key;
|
|
605
|
-
}
|
|
606
|
-
get path() {
|
|
607
|
-
if (!this._cachedPath.length) {
|
|
608
|
-
if (this._key instanceof Array) {
|
|
609
|
-
this._cachedPath.push(...this._path, ...this._key);
|
|
610
|
-
} else {
|
|
611
|
-
this._cachedPath.push(...this._path, this._key);
|
|
612
|
-
}
|
|
613
|
-
}
|
|
614
|
-
return this._cachedPath;
|
|
615
|
-
}
|
|
616
|
-
}
|
|
617
|
-
const handleResult = (ctx, result) => {
|
|
618
|
-
if (isValid(result)) {
|
|
619
|
-
return {
|
|
620
|
-
success: true,
|
|
621
|
-
data: result.value
|
|
622
|
-
};
|
|
623
|
-
} else {
|
|
624
|
-
if (!ctx.common.issues.length) {
|
|
625
|
-
throw new Error("Validation failed but no issues detected.");
|
|
626
|
-
}
|
|
627
|
-
return {
|
|
628
|
-
success: false,
|
|
629
|
-
get error() {
|
|
630
|
-
if (this._error) return this._error;
|
|
631
|
-
const error = new ZodError(ctx.common.issues);
|
|
632
|
-
this._error = error;
|
|
633
|
-
return this._error;
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
};
|
|
638
|
-
function processCreateParams(params) {
|
|
639
|
-
if (!params) return {};
|
|
640
|
-
const {
|
|
641
|
-
errorMap,
|
|
642
|
-
invalid_type_error,
|
|
643
|
-
required_error,
|
|
644
|
-
description
|
|
645
|
-
} = params;
|
|
646
|
-
if (errorMap && (invalid_type_error || required_error)) {
|
|
647
|
-
throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);
|
|
648
|
-
}
|
|
649
|
-
if (errorMap) return {
|
|
650
|
-
errorMap: errorMap,
|
|
651
|
-
description
|
|
652
|
-
};
|
|
653
|
-
const customMap = (iss, ctx) => {
|
|
654
|
-
if (iss.code !== "invalid_type") return {
|
|
655
|
-
message: ctx.defaultError
|
|
656
|
-
};
|
|
657
|
-
if (typeof ctx.data === "undefined") {
|
|
658
|
-
return {
|
|
659
|
-
message: required_error !== null && required_error !== void 0 ? required_error : ctx.defaultError
|
|
660
|
-
};
|
|
661
|
-
}
|
|
662
|
-
return {
|
|
663
|
-
message: invalid_type_error !== null && invalid_type_error !== void 0 ? invalid_type_error : ctx.defaultError
|
|
664
|
-
};
|
|
665
|
-
};
|
|
666
|
-
return {
|
|
667
|
-
errorMap: customMap,
|
|
668
|
-
description
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
class ZodType {
|
|
672
|
-
constructor(def) {
|
|
673
|
-
/** Alias of safeParseAsync */
|
|
674
|
-
this.spa = this.safeParseAsync;
|
|
675
|
-
this._def = def;
|
|
676
|
-
this.parse = this.parse.bind(this);
|
|
677
|
-
this.safeParse = this.safeParse.bind(this);
|
|
678
|
-
this.parseAsync = this.parseAsync.bind(this);
|
|
679
|
-
this.safeParseAsync = this.safeParseAsync.bind(this);
|
|
680
|
-
this.spa = this.spa.bind(this);
|
|
681
|
-
this.refine = this.refine.bind(this);
|
|
682
|
-
this.refinement = this.refinement.bind(this);
|
|
683
|
-
this.superRefine = this.superRefine.bind(this);
|
|
684
|
-
this.optional = this.optional.bind(this);
|
|
685
|
-
this.nullable = this.nullable.bind(this);
|
|
686
|
-
this.nullish = this.nullish.bind(this);
|
|
687
|
-
this.array = this.array.bind(this);
|
|
688
|
-
this.promise = this.promise.bind(this);
|
|
689
|
-
this.or = this.or.bind(this);
|
|
690
|
-
this.and = this.and.bind(this);
|
|
691
|
-
this.transform = this.transform.bind(this);
|
|
692
|
-
this.brand = this.brand.bind(this);
|
|
693
|
-
this.default = this.default.bind(this);
|
|
694
|
-
this.catch = this.catch.bind(this);
|
|
695
|
-
this.describe = this.describe.bind(this);
|
|
696
|
-
this.pipe = this.pipe.bind(this);
|
|
697
|
-
this.readonly = this.readonly.bind(this);
|
|
698
|
-
this.isNullable = this.isNullable.bind(this);
|
|
699
|
-
this.isOptional = this.isOptional.bind(this);
|
|
700
|
-
}
|
|
701
|
-
get description() {
|
|
702
|
-
return this._def.description;
|
|
703
|
-
}
|
|
704
|
-
_getType(input) {
|
|
705
|
-
return getParsedType(input.data);
|
|
706
|
-
}
|
|
707
|
-
_getOrReturnCtx(input, ctx) {
|
|
708
|
-
return ctx || {
|
|
709
|
-
common: input.parent.common,
|
|
710
|
-
data: input.data,
|
|
711
|
-
parsedType: getParsedType(input.data),
|
|
712
|
-
schemaErrorMap: this._def.errorMap,
|
|
713
|
-
path: input.path,
|
|
714
|
-
parent: input.parent
|
|
715
|
-
};
|
|
716
|
-
}
|
|
717
|
-
_processInputParams(input) {
|
|
718
|
-
return {
|
|
719
|
-
status: new ParseStatus(),
|
|
720
|
-
ctx: {
|
|
721
|
-
common: input.parent.common,
|
|
722
|
-
data: input.data,
|
|
723
|
-
parsedType: getParsedType(input.data),
|
|
724
|
-
schemaErrorMap: this._def.errorMap,
|
|
725
|
-
path: input.path,
|
|
726
|
-
parent: input.parent
|
|
727
|
-
}
|
|
728
|
-
};
|
|
729
|
-
}
|
|
730
|
-
_parseSync(input) {
|
|
731
|
-
const result = this._parse(input);
|
|
732
|
-
if (isAsync(result)) {
|
|
733
|
-
throw new Error("Synchronous parse encountered promise.");
|
|
734
|
-
}
|
|
735
|
-
return result;
|
|
736
|
-
}
|
|
737
|
-
_parseAsync(input) {
|
|
738
|
-
const result = this._parse(input);
|
|
739
|
-
return Promise.resolve(result);
|
|
740
|
-
}
|
|
741
|
-
parse(data, params) {
|
|
742
|
-
const result = this.safeParse(data, params);
|
|
743
|
-
if (result.success) return result.data;
|
|
744
|
-
throw result.error;
|
|
745
|
-
}
|
|
746
|
-
safeParse(data, params) {
|
|
747
|
-
var _a;
|
|
748
|
-
const ctx = {
|
|
749
|
-
common: {
|
|
750
|
-
issues: [],
|
|
751
|
-
async: (_a = params === null || params === void 0 ? void 0 : params.async) !== null && _a !== void 0 ? _a : false,
|
|
752
|
-
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap
|
|
753
|
-
},
|
|
754
|
-
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
755
|
-
schemaErrorMap: this._def.errorMap,
|
|
756
|
-
parent: null,
|
|
757
|
-
data,
|
|
758
|
-
parsedType: getParsedType(data)
|
|
759
|
-
};
|
|
760
|
-
const result = this._parseSync({
|
|
761
|
-
data,
|
|
762
|
-
path: ctx.path,
|
|
763
|
-
parent: ctx
|
|
764
|
-
});
|
|
765
|
-
return handleResult(ctx, result);
|
|
766
|
-
}
|
|
767
|
-
async parseAsync(data, params) {
|
|
768
|
-
const result = await this.safeParseAsync(data, params);
|
|
769
|
-
if (result.success) return result.data;
|
|
770
|
-
throw result.error;
|
|
771
|
-
}
|
|
772
|
-
async safeParseAsync(data, params) {
|
|
773
|
-
const ctx = {
|
|
774
|
-
common: {
|
|
775
|
-
issues: [],
|
|
776
|
-
contextualErrorMap: params === null || params === void 0 ? void 0 : params.errorMap,
|
|
777
|
-
async: true
|
|
778
|
-
},
|
|
779
|
-
path: (params === null || params === void 0 ? void 0 : params.path) || [],
|
|
780
|
-
schemaErrorMap: this._def.errorMap,
|
|
781
|
-
parent: null,
|
|
782
|
-
data,
|
|
783
|
-
parsedType: getParsedType(data)
|
|
784
|
-
};
|
|
785
|
-
const maybeAsyncResult = this._parse({
|
|
786
|
-
data,
|
|
787
|
-
path: ctx.path,
|
|
788
|
-
parent: ctx
|
|
789
|
-
});
|
|
790
|
-
const result = await (isAsync(maybeAsyncResult) ? maybeAsyncResult : Promise.resolve(maybeAsyncResult));
|
|
791
|
-
return handleResult(ctx, result);
|
|
792
|
-
}
|
|
793
|
-
refine(check, message) {
|
|
794
|
-
const getIssueProperties = val => {
|
|
795
|
-
if (typeof message === "string" || typeof message === "undefined") {
|
|
796
|
-
return {
|
|
797
|
-
message
|
|
798
|
-
};
|
|
799
|
-
} else if (typeof message === "function") {
|
|
800
|
-
return message(val);
|
|
801
|
-
} else {
|
|
802
|
-
return message;
|
|
803
|
-
}
|
|
804
|
-
};
|
|
805
|
-
return this._refinement((val, ctx) => {
|
|
806
|
-
const result = check(val);
|
|
807
|
-
const setError = () => ctx.addIssue({
|
|
808
|
-
code: ZodIssueCode.custom,
|
|
809
|
-
...getIssueProperties(val)
|
|
810
|
-
});
|
|
811
|
-
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
812
|
-
return result.then(data => {
|
|
813
|
-
if (!data) {
|
|
814
|
-
setError();
|
|
815
|
-
return false;
|
|
816
|
-
} else {
|
|
817
|
-
return true;
|
|
818
|
-
}
|
|
819
|
-
});
|
|
820
|
-
}
|
|
821
|
-
if (!result) {
|
|
822
|
-
setError();
|
|
823
|
-
return false;
|
|
824
|
-
} else {
|
|
825
|
-
return true;
|
|
826
|
-
}
|
|
827
|
-
});
|
|
828
|
-
}
|
|
829
|
-
refinement(check, refinementData) {
|
|
830
|
-
return this._refinement((val, ctx) => {
|
|
831
|
-
if (!check(val)) {
|
|
832
|
-
ctx.addIssue(typeof refinementData === "function" ? refinementData(val, ctx) : refinementData);
|
|
833
|
-
return false;
|
|
834
|
-
} else {
|
|
835
|
-
return true;
|
|
836
|
-
}
|
|
837
|
-
});
|
|
838
|
-
}
|
|
839
|
-
_refinement(refinement) {
|
|
840
|
-
return new ZodEffects({
|
|
841
|
-
schema: this,
|
|
842
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
843
|
-
effect: {
|
|
844
|
-
type: "refinement",
|
|
845
|
-
refinement
|
|
846
|
-
}
|
|
847
|
-
});
|
|
848
|
-
}
|
|
849
|
-
superRefine(refinement) {
|
|
850
|
-
return this._refinement(refinement);
|
|
851
|
-
}
|
|
852
|
-
optional() {
|
|
853
|
-
return ZodOptional.create(this, this._def);
|
|
854
|
-
}
|
|
855
|
-
nullable() {
|
|
856
|
-
return ZodNullable.create(this, this._def);
|
|
857
|
-
}
|
|
858
|
-
nullish() {
|
|
859
|
-
return this.nullable().optional();
|
|
860
|
-
}
|
|
861
|
-
array() {
|
|
862
|
-
return ZodArray.create(this, this._def);
|
|
863
|
-
}
|
|
864
|
-
promise() {
|
|
865
|
-
return ZodPromise.create(this, this._def);
|
|
866
|
-
}
|
|
867
|
-
or(option) {
|
|
868
|
-
return ZodUnion.create([this, option], this._def);
|
|
869
|
-
}
|
|
870
|
-
and(incoming) {
|
|
871
|
-
return ZodIntersection.create(this, incoming, this._def);
|
|
872
|
-
}
|
|
873
|
-
transform(transform) {
|
|
874
|
-
return new ZodEffects({
|
|
875
|
-
...processCreateParams(this._def),
|
|
876
|
-
schema: this,
|
|
877
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
878
|
-
effect: {
|
|
879
|
-
type: "transform",
|
|
880
|
-
transform
|
|
881
|
-
}
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
default(def) {
|
|
885
|
-
const defaultValueFunc = typeof def === "function" ? def : () => def;
|
|
886
|
-
return new ZodDefault({
|
|
887
|
-
...processCreateParams(this._def),
|
|
888
|
-
innerType: this,
|
|
889
|
-
defaultValue: defaultValueFunc,
|
|
890
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault
|
|
891
|
-
});
|
|
892
|
-
}
|
|
893
|
-
brand() {
|
|
894
|
-
return new ZodBranded({
|
|
895
|
-
typeName: ZodFirstPartyTypeKind.ZodBranded,
|
|
896
|
-
type: this,
|
|
897
|
-
...processCreateParams(this._def)
|
|
898
|
-
});
|
|
899
|
-
}
|
|
900
|
-
catch(def) {
|
|
901
|
-
const catchValueFunc = typeof def === "function" ? def : () => def;
|
|
902
|
-
return new ZodCatch({
|
|
903
|
-
...processCreateParams(this._def),
|
|
904
|
-
innerType: this,
|
|
905
|
-
catchValue: catchValueFunc,
|
|
906
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch
|
|
907
|
-
});
|
|
908
|
-
}
|
|
909
|
-
describe(description) {
|
|
910
|
-
const This = this.constructor;
|
|
911
|
-
return new This({
|
|
912
|
-
...this._def,
|
|
913
|
-
description
|
|
914
|
-
});
|
|
915
|
-
}
|
|
916
|
-
pipe(target) {
|
|
917
|
-
return ZodPipeline.create(this, target);
|
|
918
|
-
}
|
|
919
|
-
readonly() {
|
|
920
|
-
return ZodReadonly.create(this);
|
|
921
|
-
}
|
|
922
|
-
isOptional() {
|
|
923
|
-
return this.safeParse(undefined).success;
|
|
924
|
-
}
|
|
925
|
-
isNullable() {
|
|
926
|
-
return this.safeParse(null).success;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
const cuidRegex = /^c[^\s-]{8,}$/i;
|
|
930
|
-
const cuid2Regex = /^[a-z][a-z0-9]*$/;
|
|
931
|
-
const ulidRegex = /^[0-9A-HJKMNP-TV-Z]{26}$/;
|
|
932
|
-
// const uuidRegex =
|
|
933
|
-
// /^([a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[a-f0-9]{4}-[a-f0-9]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
934
|
-
const 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;
|
|
935
|
-
// from https://stackoverflow.com/a/46181/1550155
|
|
936
|
-
// old version: too slow, didn't support unicode
|
|
937
|
-
// const emailRegex = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
|
|
938
|
-
//old email regex
|
|
939
|
-
// const emailRegex = /^(([^<>()[\].,;:\s@"]+(\.[^<>()[\].,;:\s@"]+)*)|(".+"))@((?!-)([^<>()[\].,;:\s@"]+\.)+[^<>()[\].,;:\s@"]{1,})[^-<>()[\].,;:\s@"]$/i;
|
|
940
|
-
// eslint-disable-next-line
|
|
941
|
-
// const emailRegex =
|
|
942
|
-
// /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\])|(\[IPv6:(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))\])|([A-Za-z0-9]([A-Za-z0-9-]*[A-Za-z0-9])*(\.[A-Za-z]{2,})+))$/;
|
|
943
|
-
// const emailRegex =
|
|
944
|
-
// /^[a-zA-Z0-9\.\!\#\$\%\&\'\*\+\/\=\?\^\_\`\{\|\}\~\-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/;
|
|
945
|
-
// const emailRegex =
|
|
946
|
-
// /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])$/i;
|
|
947
|
-
const emailRegex = /^(?!\.)(?!.*\.\.)([A-Z0-9_+-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i;
|
|
948
|
-
// const emailRegex =
|
|
949
|
-
// /^[a-z0-9.!#$%&’*+/=?^_`{|}~-]+@[a-z0-9-]+(?:\.[a-z0-9\-]+)*$/i;
|
|
950
|
-
// from https://thekevinscott.com/emojis-in-javascript/#writing-a-regular-expression
|
|
951
|
-
const _emojiRegex = `^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`;
|
|
952
|
-
let emojiRegex$1;
|
|
953
|
-
const ipv4Regex = /^(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))$/;
|
|
954
|
-
const ipv6Regex = /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/;
|
|
955
|
-
// Adapted from https://stackoverflow.com/a/3143231
|
|
956
|
-
const datetimeRegex = args => {
|
|
957
|
-
if (args.precision) {
|
|
958
|
-
if (args.offset) {
|
|
959
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
960
|
-
} else {
|
|
961
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}\\.\\d{${args.precision}}Z$`);
|
|
962
|
-
}
|
|
963
|
-
} else if (args.precision === 0) {
|
|
964
|
-
if (args.offset) {
|
|
965
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
966
|
-
} else {
|
|
967
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z$`);
|
|
968
|
-
}
|
|
969
|
-
} else {
|
|
970
|
-
if (args.offset) {
|
|
971
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?(([+-]\\d{2}(:?\\d{2})?)|Z)$`);
|
|
972
|
-
} else {
|
|
973
|
-
return new RegExp(`^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}(\\.\\d+)?Z$`);
|
|
974
|
-
}
|
|
975
|
-
}
|
|
976
|
-
};
|
|
977
|
-
function isValidIP(ip, version) {
|
|
978
|
-
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
979
|
-
return true;
|
|
980
|
-
}
|
|
981
|
-
if ((version === "v6" || !version) && ipv6Regex.test(ip)) {
|
|
982
|
-
return true;
|
|
983
|
-
}
|
|
984
|
-
return false;
|
|
985
|
-
}
|
|
986
|
-
class ZodString extends ZodType {
|
|
987
|
-
_parse(input) {
|
|
988
|
-
if (this._def.coerce) {
|
|
989
|
-
input.data = String(input.data);
|
|
990
|
-
}
|
|
991
|
-
const parsedType = this._getType(input);
|
|
992
|
-
if (parsedType !== ZodParsedType.string) {
|
|
993
|
-
const ctx = this._getOrReturnCtx(input);
|
|
994
|
-
addIssueToContext(ctx, {
|
|
995
|
-
code: ZodIssueCode.invalid_type,
|
|
996
|
-
expected: ZodParsedType.string,
|
|
997
|
-
received: ctx.parsedType
|
|
998
|
-
}
|
|
999
|
-
//
|
|
1000
|
-
);
|
|
1001
|
-
return INVALID;
|
|
1002
|
-
}
|
|
1003
|
-
const status = new ParseStatus();
|
|
1004
|
-
let ctx = undefined;
|
|
1005
|
-
for (const check of this._def.checks) {
|
|
1006
|
-
if (check.kind === "min") {
|
|
1007
|
-
if (input.data.length < check.value) {
|
|
1008
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1009
|
-
addIssueToContext(ctx, {
|
|
1010
|
-
code: ZodIssueCode.too_small,
|
|
1011
|
-
minimum: check.value,
|
|
1012
|
-
type: "string",
|
|
1013
|
-
inclusive: true,
|
|
1014
|
-
exact: false,
|
|
1015
|
-
message: check.message
|
|
1016
|
-
});
|
|
1017
|
-
status.dirty();
|
|
1018
|
-
}
|
|
1019
|
-
} else if (check.kind === "max") {
|
|
1020
|
-
if (input.data.length > check.value) {
|
|
1021
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1022
|
-
addIssueToContext(ctx, {
|
|
1023
|
-
code: ZodIssueCode.too_big,
|
|
1024
|
-
maximum: check.value,
|
|
1025
|
-
type: "string",
|
|
1026
|
-
inclusive: true,
|
|
1027
|
-
exact: false,
|
|
1028
|
-
message: check.message
|
|
1029
|
-
});
|
|
1030
|
-
status.dirty();
|
|
1031
|
-
}
|
|
1032
|
-
} else if (check.kind === "length") {
|
|
1033
|
-
const tooBig = input.data.length > check.value;
|
|
1034
|
-
const tooSmall = input.data.length < check.value;
|
|
1035
|
-
if (tooBig || tooSmall) {
|
|
1036
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1037
|
-
if (tooBig) {
|
|
1038
|
-
addIssueToContext(ctx, {
|
|
1039
|
-
code: ZodIssueCode.too_big,
|
|
1040
|
-
maximum: check.value,
|
|
1041
|
-
type: "string",
|
|
1042
|
-
inclusive: true,
|
|
1043
|
-
exact: true,
|
|
1044
|
-
message: check.message
|
|
1045
|
-
});
|
|
1046
|
-
} else if (tooSmall) {
|
|
1047
|
-
addIssueToContext(ctx, {
|
|
1048
|
-
code: ZodIssueCode.too_small,
|
|
1049
|
-
minimum: check.value,
|
|
1050
|
-
type: "string",
|
|
1051
|
-
inclusive: true,
|
|
1052
|
-
exact: true,
|
|
1053
|
-
message: check.message
|
|
1054
|
-
});
|
|
1055
|
-
}
|
|
1056
|
-
status.dirty();
|
|
1057
|
-
}
|
|
1058
|
-
} else if (check.kind === "email") {
|
|
1059
|
-
if (!emailRegex.test(input.data)) {
|
|
1060
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1061
|
-
addIssueToContext(ctx, {
|
|
1062
|
-
validation: "email",
|
|
1063
|
-
code: ZodIssueCode.invalid_string,
|
|
1064
|
-
message: check.message
|
|
1065
|
-
});
|
|
1066
|
-
status.dirty();
|
|
1067
|
-
}
|
|
1068
|
-
} else if (check.kind === "emoji") {
|
|
1069
|
-
if (!emojiRegex$1) {
|
|
1070
|
-
emojiRegex$1 = new RegExp(_emojiRegex, "u");
|
|
1071
|
-
}
|
|
1072
|
-
if (!emojiRegex$1.test(input.data)) {
|
|
1073
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1074
|
-
addIssueToContext(ctx, {
|
|
1075
|
-
validation: "emoji",
|
|
1076
|
-
code: ZodIssueCode.invalid_string,
|
|
1077
|
-
message: check.message
|
|
1078
|
-
});
|
|
1079
|
-
status.dirty();
|
|
1080
|
-
}
|
|
1081
|
-
} else if (check.kind === "uuid") {
|
|
1082
|
-
if (!uuidRegex.test(input.data)) {
|
|
1083
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1084
|
-
addIssueToContext(ctx, {
|
|
1085
|
-
validation: "uuid",
|
|
1086
|
-
code: ZodIssueCode.invalid_string,
|
|
1087
|
-
message: check.message
|
|
1088
|
-
});
|
|
1089
|
-
status.dirty();
|
|
1090
|
-
}
|
|
1091
|
-
} else if (check.kind === "cuid") {
|
|
1092
|
-
if (!cuidRegex.test(input.data)) {
|
|
1093
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1094
|
-
addIssueToContext(ctx, {
|
|
1095
|
-
validation: "cuid",
|
|
1096
|
-
code: ZodIssueCode.invalid_string,
|
|
1097
|
-
message: check.message
|
|
1098
|
-
});
|
|
1099
|
-
status.dirty();
|
|
1100
|
-
}
|
|
1101
|
-
} else if (check.kind === "cuid2") {
|
|
1102
|
-
if (!cuid2Regex.test(input.data)) {
|
|
1103
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1104
|
-
addIssueToContext(ctx, {
|
|
1105
|
-
validation: "cuid2",
|
|
1106
|
-
code: ZodIssueCode.invalid_string,
|
|
1107
|
-
message: check.message
|
|
1108
|
-
});
|
|
1109
|
-
status.dirty();
|
|
1110
|
-
}
|
|
1111
|
-
} else if (check.kind === "ulid") {
|
|
1112
|
-
if (!ulidRegex.test(input.data)) {
|
|
1113
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1114
|
-
addIssueToContext(ctx, {
|
|
1115
|
-
validation: "ulid",
|
|
1116
|
-
code: ZodIssueCode.invalid_string,
|
|
1117
|
-
message: check.message
|
|
1118
|
-
});
|
|
1119
|
-
status.dirty();
|
|
1120
|
-
}
|
|
1121
|
-
} else if (check.kind === "url") {
|
|
1122
|
-
try {
|
|
1123
|
-
new URL(input.data);
|
|
1124
|
-
} catch (_a) {
|
|
1125
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1126
|
-
addIssueToContext(ctx, {
|
|
1127
|
-
validation: "url",
|
|
1128
|
-
code: ZodIssueCode.invalid_string,
|
|
1129
|
-
message: check.message
|
|
1130
|
-
});
|
|
1131
|
-
status.dirty();
|
|
1132
|
-
}
|
|
1133
|
-
} else if (check.kind === "regex") {
|
|
1134
|
-
check.regex.lastIndex = 0;
|
|
1135
|
-
const testResult = check.regex.test(input.data);
|
|
1136
|
-
if (!testResult) {
|
|
1137
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1138
|
-
addIssueToContext(ctx, {
|
|
1139
|
-
validation: "regex",
|
|
1140
|
-
code: ZodIssueCode.invalid_string,
|
|
1141
|
-
message: check.message
|
|
1142
|
-
});
|
|
1143
|
-
status.dirty();
|
|
1144
|
-
}
|
|
1145
|
-
} else if (check.kind === "trim") {
|
|
1146
|
-
input.data = input.data.trim();
|
|
1147
|
-
} else if (check.kind === "includes") {
|
|
1148
|
-
if (!input.data.includes(check.value, check.position)) {
|
|
1149
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1150
|
-
addIssueToContext(ctx, {
|
|
1151
|
-
code: ZodIssueCode.invalid_string,
|
|
1152
|
-
validation: {
|
|
1153
|
-
includes: check.value,
|
|
1154
|
-
position: check.position
|
|
1155
|
-
},
|
|
1156
|
-
message: check.message
|
|
1157
|
-
});
|
|
1158
|
-
status.dirty();
|
|
1159
|
-
}
|
|
1160
|
-
} else if (check.kind === "toLowerCase") {
|
|
1161
|
-
input.data = input.data.toLowerCase();
|
|
1162
|
-
} else if (check.kind === "toUpperCase") {
|
|
1163
|
-
input.data = input.data.toUpperCase();
|
|
1164
|
-
} else if (check.kind === "startsWith") {
|
|
1165
|
-
if (!input.data.startsWith(check.value)) {
|
|
1166
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1167
|
-
addIssueToContext(ctx, {
|
|
1168
|
-
code: ZodIssueCode.invalid_string,
|
|
1169
|
-
validation: {
|
|
1170
|
-
startsWith: check.value
|
|
1171
|
-
},
|
|
1172
|
-
message: check.message
|
|
1173
|
-
});
|
|
1174
|
-
status.dirty();
|
|
1175
|
-
}
|
|
1176
|
-
} else if (check.kind === "endsWith") {
|
|
1177
|
-
if (!input.data.endsWith(check.value)) {
|
|
1178
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1179
|
-
addIssueToContext(ctx, {
|
|
1180
|
-
code: ZodIssueCode.invalid_string,
|
|
1181
|
-
validation: {
|
|
1182
|
-
endsWith: check.value
|
|
1183
|
-
},
|
|
1184
|
-
message: check.message
|
|
1185
|
-
});
|
|
1186
|
-
status.dirty();
|
|
1187
|
-
}
|
|
1188
|
-
} else if (check.kind === "datetime") {
|
|
1189
|
-
const regex = datetimeRegex(check);
|
|
1190
|
-
if (!regex.test(input.data)) {
|
|
1191
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1192
|
-
addIssueToContext(ctx, {
|
|
1193
|
-
code: ZodIssueCode.invalid_string,
|
|
1194
|
-
validation: "datetime",
|
|
1195
|
-
message: check.message
|
|
1196
|
-
});
|
|
1197
|
-
status.dirty();
|
|
1198
|
-
}
|
|
1199
|
-
} else if (check.kind === "ip") {
|
|
1200
|
-
if (!isValidIP(input.data, check.version)) {
|
|
1201
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1202
|
-
addIssueToContext(ctx, {
|
|
1203
|
-
validation: "ip",
|
|
1204
|
-
code: ZodIssueCode.invalid_string,
|
|
1205
|
-
message: check.message
|
|
1206
|
-
});
|
|
1207
|
-
status.dirty();
|
|
1208
|
-
}
|
|
1209
|
-
} else {
|
|
1210
|
-
util$5.assertNever(check);
|
|
1211
|
-
}
|
|
1212
|
-
}
|
|
1213
|
-
return {
|
|
1214
|
-
status: status.value,
|
|
1215
|
-
value: input.data
|
|
1216
|
-
};
|
|
1217
|
-
}
|
|
1218
|
-
_regex(regex, validation, message) {
|
|
1219
|
-
return this.refinement(data => regex.test(data), {
|
|
1220
|
-
validation,
|
|
1221
|
-
code: ZodIssueCode.invalid_string,
|
|
1222
|
-
...errorUtil.errToObj(message)
|
|
1223
|
-
});
|
|
1224
|
-
}
|
|
1225
|
-
_addCheck(check) {
|
|
1226
|
-
return new ZodString({
|
|
1227
|
-
...this._def,
|
|
1228
|
-
checks: [...this._def.checks, check]
|
|
1229
|
-
});
|
|
1230
|
-
}
|
|
1231
|
-
email(message) {
|
|
1232
|
-
return this._addCheck({
|
|
1233
|
-
kind: "email",
|
|
1234
|
-
...errorUtil.errToObj(message)
|
|
1235
|
-
});
|
|
1236
|
-
}
|
|
1237
|
-
url(message) {
|
|
1238
|
-
return this._addCheck({
|
|
1239
|
-
kind: "url",
|
|
1240
|
-
...errorUtil.errToObj(message)
|
|
1241
|
-
});
|
|
1242
|
-
}
|
|
1243
|
-
emoji(message) {
|
|
1244
|
-
return this._addCheck({
|
|
1245
|
-
kind: "emoji",
|
|
1246
|
-
...errorUtil.errToObj(message)
|
|
1247
|
-
});
|
|
1248
|
-
}
|
|
1249
|
-
uuid(message) {
|
|
1250
|
-
return this._addCheck({
|
|
1251
|
-
kind: "uuid",
|
|
1252
|
-
...errorUtil.errToObj(message)
|
|
1253
|
-
});
|
|
1254
|
-
}
|
|
1255
|
-
cuid(message) {
|
|
1256
|
-
return this._addCheck({
|
|
1257
|
-
kind: "cuid",
|
|
1258
|
-
...errorUtil.errToObj(message)
|
|
1259
|
-
});
|
|
1260
|
-
}
|
|
1261
|
-
cuid2(message) {
|
|
1262
|
-
return this._addCheck({
|
|
1263
|
-
kind: "cuid2",
|
|
1264
|
-
...errorUtil.errToObj(message)
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
ulid(message) {
|
|
1268
|
-
return this._addCheck({
|
|
1269
|
-
kind: "ulid",
|
|
1270
|
-
...errorUtil.errToObj(message)
|
|
1271
|
-
});
|
|
1272
|
-
}
|
|
1273
|
-
ip(options) {
|
|
1274
|
-
return this._addCheck({
|
|
1275
|
-
kind: "ip",
|
|
1276
|
-
...errorUtil.errToObj(options)
|
|
1277
|
-
});
|
|
1278
|
-
}
|
|
1279
|
-
datetime(options) {
|
|
1280
|
-
var _a;
|
|
1281
|
-
if (typeof options === "string") {
|
|
1282
|
-
return this._addCheck({
|
|
1283
|
-
kind: "datetime",
|
|
1284
|
-
precision: null,
|
|
1285
|
-
offset: false,
|
|
1286
|
-
message: options
|
|
1287
|
-
});
|
|
1288
|
-
}
|
|
1289
|
-
return this._addCheck({
|
|
1290
|
-
kind: "datetime",
|
|
1291
|
-
precision: typeof (options === null || options === void 0 ? void 0 : options.precision) === "undefined" ? null : options === null || options === void 0 ? void 0 : options.precision,
|
|
1292
|
-
offset: (_a = options === null || options === void 0 ? void 0 : options.offset) !== null && _a !== void 0 ? _a : false,
|
|
1293
|
-
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
1294
|
-
});
|
|
1295
|
-
}
|
|
1296
|
-
regex(regex, message) {
|
|
1297
|
-
return this._addCheck({
|
|
1298
|
-
kind: "regex",
|
|
1299
|
-
regex: regex,
|
|
1300
|
-
...errorUtil.errToObj(message)
|
|
1301
|
-
});
|
|
1302
|
-
}
|
|
1303
|
-
includes(value, options) {
|
|
1304
|
-
return this._addCheck({
|
|
1305
|
-
kind: "includes",
|
|
1306
|
-
value: value,
|
|
1307
|
-
position: options === null || options === void 0 ? void 0 : options.position,
|
|
1308
|
-
...errorUtil.errToObj(options === null || options === void 0 ? void 0 : options.message)
|
|
1309
|
-
});
|
|
1310
|
-
}
|
|
1311
|
-
startsWith(value, message) {
|
|
1312
|
-
return this._addCheck({
|
|
1313
|
-
kind: "startsWith",
|
|
1314
|
-
value: value,
|
|
1315
|
-
...errorUtil.errToObj(message)
|
|
1316
|
-
});
|
|
1317
|
-
}
|
|
1318
|
-
endsWith(value, message) {
|
|
1319
|
-
return this._addCheck({
|
|
1320
|
-
kind: "endsWith",
|
|
1321
|
-
value: value,
|
|
1322
|
-
...errorUtil.errToObj(message)
|
|
1323
|
-
});
|
|
1324
|
-
}
|
|
1325
|
-
min(minLength, message) {
|
|
1326
|
-
return this._addCheck({
|
|
1327
|
-
kind: "min",
|
|
1328
|
-
value: minLength,
|
|
1329
|
-
...errorUtil.errToObj(message)
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1332
|
-
max(maxLength, message) {
|
|
1333
|
-
return this._addCheck({
|
|
1334
|
-
kind: "max",
|
|
1335
|
-
value: maxLength,
|
|
1336
|
-
...errorUtil.errToObj(message)
|
|
1337
|
-
});
|
|
1338
|
-
}
|
|
1339
|
-
length(len, message) {
|
|
1340
|
-
return this._addCheck({
|
|
1341
|
-
kind: "length",
|
|
1342
|
-
value: len,
|
|
1343
|
-
...errorUtil.errToObj(message)
|
|
1344
|
-
});
|
|
1345
|
-
}
|
|
1346
|
-
/**
|
|
1347
|
-
* @deprecated Use z.string().min(1) instead.
|
|
1348
|
-
* @see {@link ZodString.min}
|
|
1349
|
-
*/
|
|
1350
|
-
nonempty(message) {
|
|
1351
|
-
return this.min(1, errorUtil.errToObj(message));
|
|
1352
|
-
}
|
|
1353
|
-
trim() {
|
|
1354
|
-
return new ZodString({
|
|
1355
|
-
...this._def,
|
|
1356
|
-
checks: [...this._def.checks, {
|
|
1357
|
-
kind: "trim"
|
|
1358
|
-
}]
|
|
1359
|
-
});
|
|
1360
|
-
}
|
|
1361
|
-
toLowerCase() {
|
|
1362
|
-
return new ZodString({
|
|
1363
|
-
...this._def,
|
|
1364
|
-
checks: [...this._def.checks, {
|
|
1365
|
-
kind: "toLowerCase"
|
|
1366
|
-
}]
|
|
1367
|
-
});
|
|
1368
|
-
}
|
|
1369
|
-
toUpperCase() {
|
|
1370
|
-
return new ZodString({
|
|
1371
|
-
...this._def,
|
|
1372
|
-
checks: [...this._def.checks, {
|
|
1373
|
-
kind: "toUpperCase"
|
|
1374
|
-
}]
|
|
1375
|
-
});
|
|
1376
|
-
}
|
|
1377
|
-
get isDatetime() {
|
|
1378
|
-
return !!this._def.checks.find(ch => ch.kind === "datetime");
|
|
1379
|
-
}
|
|
1380
|
-
get isEmail() {
|
|
1381
|
-
return !!this._def.checks.find(ch => ch.kind === "email");
|
|
1382
|
-
}
|
|
1383
|
-
get isURL() {
|
|
1384
|
-
return !!this._def.checks.find(ch => ch.kind === "url");
|
|
1385
|
-
}
|
|
1386
|
-
get isEmoji() {
|
|
1387
|
-
return !!this._def.checks.find(ch => ch.kind === "emoji");
|
|
1388
|
-
}
|
|
1389
|
-
get isUUID() {
|
|
1390
|
-
return !!this._def.checks.find(ch => ch.kind === "uuid");
|
|
1391
|
-
}
|
|
1392
|
-
get isCUID() {
|
|
1393
|
-
return !!this._def.checks.find(ch => ch.kind === "cuid");
|
|
1394
|
-
}
|
|
1395
|
-
get isCUID2() {
|
|
1396
|
-
return !!this._def.checks.find(ch => ch.kind === "cuid2");
|
|
1397
|
-
}
|
|
1398
|
-
get isULID() {
|
|
1399
|
-
return !!this._def.checks.find(ch => ch.kind === "ulid");
|
|
1400
|
-
}
|
|
1401
|
-
get isIP() {
|
|
1402
|
-
return !!this._def.checks.find(ch => ch.kind === "ip");
|
|
1403
|
-
}
|
|
1404
|
-
get minLength() {
|
|
1405
|
-
let min = null;
|
|
1406
|
-
for (const ch of this._def.checks) {
|
|
1407
|
-
if (ch.kind === "min") {
|
|
1408
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1409
|
-
}
|
|
1410
|
-
}
|
|
1411
|
-
return min;
|
|
1412
|
-
}
|
|
1413
|
-
get maxLength() {
|
|
1414
|
-
let max = null;
|
|
1415
|
-
for (const ch of this._def.checks) {
|
|
1416
|
-
if (ch.kind === "max") {
|
|
1417
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1418
|
-
}
|
|
1419
|
-
}
|
|
1420
|
-
return max;
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
ZodString.create = params => {
|
|
1424
|
-
var _a;
|
|
1425
|
-
return new ZodString({
|
|
1426
|
-
checks: [],
|
|
1427
|
-
typeName: ZodFirstPartyTypeKind.ZodString,
|
|
1428
|
-
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1429
|
-
...processCreateParams(params)
|
|
1430
|
-
});
|
|
1431
|
-
};
|
|
1432
|
-
// https://stackoverflow.com/questions/3966484/why-does-modulus-operator-return-fractional-number-in-javascript/31711034#31711034
|
|
1433
|
-
function floatSafeRemainder(val, step) {
|
|
1434
|
-
const valDecCount = (val.toString().split(".")[1] || "").length;
|
|
1435
|
-
const stepDecCount = (step.toString().split(".")[1] || "").length;
|
|
1436
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
1437
|
-
const valInt = parseInt(val.toFixed(decCount).replace(".", ""));
|
|
1438
|
-
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1439
|
-
return valInt % stepInt / Math.pow(10, decCount);
|
|
1440
|
-
}
|
|
1441
|
-
class ZodNumber extends ZodType {
|
|
1442
|
-
constructor() {
|
|
1443
|
-
super(...arguments);
|
|
1444
|
-
this.min = this.gte;
|
|
1445
|
-
this.max = this.lte;
|
|
1446
|
-
this.step = this.multipleOf;
|
|
1447
|
-
}
|
|
1448
|
-
_parse(input) {
|
|
1449
|
-
if (this._def.coerce) {
|
|
1450
|
-
input.data = Number(input.data);
|
|
1451
|
-
}
|
|
1452
|
-
const parsedType = this._getType(input);
|
|
1453
|
-
if (parsedType !== ZodParsedType.number) {
|
|
1454
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1455
|
-
addIssueToContext(ctx, {
|
|
1456
|
-
code: ZodIssueCode.invalid_type,
|
|
1457
|
-
expected: ZodParsedType.number,
|
|
1458
|
-
received: ctx.parsedType
|
|
1459
|
-
});
|
|
1460
|
-
return INVALID;
|
|
1461
|
-
}
|
|
1462
|
-
let ctx = undefined;
|
|
1463
|
-
const status = new ParseStatus();
|
|
1464
|
-
for (const check of this._def.checks) {
|
|
1465
|
-
if (check.kind === "int") {
|
|
1466
|
-
if (!util$5.isInteger(input.data)) {
|
|
1467
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1468
|
-
addIssueToContext(ctx, {
|
|
1469
|
-
code: ZodIssueCode.invalid_type,
|
|
1470
|
-
expected: "integer",
|
|
1471
|
-
received: "float",
|
|
1472
|
-
message: check.message
|
|
1473
|
-
});
|
|
1474
|
-
status.dirty();
|
|
1475
|
-
}
|
|
1476
|
-
} else if (check.kind === "min") {
|
|
1477
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1478
|
-
if (tooSmall) {
|
|
1479
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1480
|
-
addIssueToContext(ctx, {
|
|
1481
|
-
code: ZodIssueCode.too_small,
|
|
1482
|
-
minimum: check.value,
|
|
1483
|
-
type: "number",
|
|
1484
|
-
inclusive: check.inclusive,
|
|
1485
|
-
exact: false,
|
|
1486
|
-
message: check.message
|
|
1487
|
-
});
|
|
1488
|
-
status.dirty();
|
|
1489
|
-
}
|
|
1490
|
-
} else if (check.kind === "max") {
|
|
1491
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1492
|
-
if (tooBig) {
|
|
1493
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1494
|
-
addIssueToContext(ctx, {
|
|
1495
|
-
code: ZodIssueCode.too_big,
|
|
1496
|
-
maximum: check.value,
|
|
1497
|
-
type: "number",
|
|
1498
|
-
inclusive: check.inclusive,
|
|
1499
|
-
exact: false,
|
|
1500
|
-
message: check.message
|
|
1501
|
-
});
|
|
1502
|
-
status.dirty();
|
|
1503
|
-
}
|
|
1504
|
-
} else if (check.kind === "multipleOf") {
|
|
1505
|
-
if (floatSafeRemainder(input.data, check.value) !== 0) {
|
|
1506
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1507
|
-
addIssueToContext(ctx, {
|
|
1508
|
-
code: ZodIssueCode.not_multiple_of,
|
|
1509
|
-
multipleOf: check.value,
|
|
1510
|
-
message: check.message
|
|
1511
|
-
});
|
|
1512
|
-
status.dirty();
|
|
1513
|
-
}
|
|
1514
|
-
} else if (check.kind === "finite") {
|
|
1515
|
-
if (!Number.isFinite(input.data)) {
|
|
1516
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1517
|
-
addIssueToContext(ctx, {
|
|
1518
|
-
code: ZodIssueCode.not_finite,
|
|
1519
|
-
message: check.message
|
|
1520
|
-
});
|
|
1521
|
-
status.dirty();
|
|
1522
|
-
}
|
|
1523
|
-
} else {
|
|
1524
|
-
util$5.assertNever(check);
|
|
1525
|
-
}
|
|
1526
|
-
}
|
|
1527
|
-
return {
|
|
1528
|
-
status: status.value,
|
|
1529
|
-
value: input.data
|
|
1530
|
-
};
|
|
1531
|
-
}
|
|
1532
|
-
gte(value, message) {
|
|
1533
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1534
|
-
}
|
|
1535
|
-
gt(value, message) {
|
|
1536
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1537
|
-
}
|
|
1538
|
-
lte(value, message) {
|
|
1539
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1540
|
-
}
|
|
1541
|
-
lt(value, message) {
|
|
1542
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1543
|
-
}
|
|
1544
|
-
setLimit(kind, value, inclusive, message) {
|
|
1545
|
-
return new ZodNumber({
|
|
1546
|
-
...this._def,
|
|
1547
|
-
checks: [...this._def.checks, {
|
|
1548
|
-
kind,
|
|
1549
|
-
value,
|
|
1550
|
-
inclusive,
|
|
1551
|
-
message: errorUtil.toString(message)
|
|
1552
|
-
}]
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
_addCheck(check) {
|
|
1556
|
-
return new ZodNumber({
|
|
1557
|
-
...this._def,
|
|
1558
|
-
checks: [...this._def.checks, check]
|
|
1559
|
-
});
|
|
1560
|
-
}
|
|
1561
|
-
int(message) {
|
|
1562
|
-
return this._addCheck({
|
|
1563
|
-
kind: "int",
|
|
1564
|
-
message: errorUtil.toString(message)
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
positive(message) {
|
|
1568
|
-
return this._addCheck({
|
|
1569
|
-
kind: "min",
|
|
1570
|
-
value: 0,
|
|
1571
|
-
inclusive: false,
|
|
1572
|
-
message: errorUtil.toString(message)
|
|
1573
|
-
});
|
|
1574
|
-
}
|
|
1575
|
-
negative(message) {
|
|
1576
|
-
return this._addCheck({
|
|
1577
|
-
kind: "max",
|
|
1578
|
-
value: 0,
|
|
1579
|
-
inclusive: false,
|
|
1580
|
-
message: errorUtil.toString(message)
|
|
1581
|
-
});
|
|
1582
|
-
}
|
|
1583
|
-
nonpositive(message) {
|
|
1584
|
-
return this._addCheck({
|
|
1585
|
-
kind: "max",
|
|
1586
|
-
value: 0,
|
|
1587
|
-
inclusive: true,
|
|
1588
|
-
message: errorUtil.toString(message)
|
|
1589
|
-
});
|
|
1590
|
-
}
|
|
1591
|
-
nonnegative(message) {
|
|
1592
|
-
return this._addCheck({
|
|
1593
|
-
kind: "min",
|
|
1594
|
-
value: 0,
|
|
1595
|
-
inclusive: true,
|
|
1596
|
-
message: errorUtil.toString(message)
|
|
1597
|
-
});
|
|
1598
|
-
}
|
|
1599
|
-
multipleOf(value, message) {
|
|
1600
|
-
return this._addCheck({
|
|
1601
|
-
kind: "multipleOf",
|
|
1602
|
-
value: value,
|
|
1603
|
-
message: errorUtil.toString(message)
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
finite(message) {
|
|
1607
|
-
return this._addCheck({
|
|
1608
|
-
kind: "finite",
|
|
1609
|
-
message: errorUtil.toString(message)
|
|
1610
|
-
});
|
|
1611
|
-
}
|
|
1612
|
-
safe(message) {
|
|
1613
|
-
return this._addCheck({
|
|
1614
|
-
kind: "min",
|
|
1615
|
-
inclusive: true,
|
|
1616
|
-
value: Number.MIN_SAFE_INTEGER,
|
|
1617
|
-
message: errorUtil.toString(message)
|
|
1618
|
-
})._addCheck({
|
|
1619
|
-
kind: "max",
|
|
1620
|
-
inclusive: true,
|
|
1621
|
-
value: Number.MAX_SAFE_INTEGER,
|
|
1622
|
-
message: errorUtil.toString(message)
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
get minValue() {
|
|
1626
|
-
let min = null;
|
|
1627
|
-
for (const ch of this._def.checks) {
|
|
1628
|
-
if (ch.kind === "min") {
|
|
1629
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1630
|
-
}
|
|
1631
|
-
}
|
|
1632
|
-
return min;
|
|
1633
|
-
}
|
|
1634
|
-
get maxValue() {
|
|
1635
|
-
let max = null;
|
|
1636
|
-
for (const ch of this._def.checks) {
|
|
1637
|
-
if (ch.kind === "max") {
|
|
1638
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1639
|
-
}
|
|
1640
|
-
}
|
|
1641
|
-
return max;
|
|
1642
|
-
}
|
|
1643
|
-
get isInt() {
|
|
1644
|
-
return !!this._def.checks.find(ch => ch.kind === "int" || ch.kind === "multipleOf" && util$5.isInteger(ch.value));
|
|
1645
|
-
}
|
|
1646
|
-
get isFinite() {
|
|
1647
|
-
let max = null,
|
|
1648
|
-
min = null;
|
|
1649
|
-
for (const ch of this._def.checks) {
|
|
1650
|
-
if (ch.kind === "finite" || ch.kind === "int" || ch.kind === "multipleOf") {
|
|
1651
|
-
return true;
|
|
1652
|
-
} else if (ch.kind === "min") {
|
|
1653
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1654
|
-
} else if (ch.kind === "max") {
|
|
1655
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1656
|
-
}
|
|
1657
|
-
}
|
|
1658
|
-
return Number.isFinite(min) && Number.isFinite(max);
|
|
1659
|
-
}
|
|
1660
|
-
}
|
|
1661
|
-
ZodNumber.create = params => {
|
|
1662
|
-
return new ZodNumber({
|
|
1663
|
-
checks: [],
|
|
1664
|
-
typeName: ZodFirstPartyTypeKind.ZodNumber,
|
|
1665
|
-
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1666
|
-
...processCreateParams(params)
|
|
1667
|
-
});
|
|
1668
|
-
};
|
|
1669
|
-
class ZodBigInt extends ZodType {
|
|
1670
|
-
constructor() {
|
|
1671
|
-
super(...arguments);
|
|
1672
|
-
this.min = this.gte;
|
|
1673
|
-
this.max = this.lte;
|
|
1674
|
-
}
|
|
1675
|
-
_parse(input) {
|
|
1676
|
-
if (this._def.coerce) {
|
|
1677
|
-
input.data = BigInt(input.data);
|
|
1678
|
-
}
|
|
1679
|
-
const parsedType = this._getType(input);
|
|
1680
|
-
if (parsedType !== ZodParsedType.bigint) {
|
|
1681
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1682
|
-
addIssueToContext(ctx, {
|
|
1683
|
-
code: ZodIssueCode.invalid_type,
|
|
1684
|
-
expected: ZodParsedType.bigint,
|
|
1685
|
-
received: ctx.parsedType
|
|
1686
|
-
});
|
|
1687
|
-
return INVALID;
|
|
1688
|
-
}
|
|
1689
|
-
let ctx = undefined;
|
|
1690
|
-
const status = new ParseStatus();
|
|
1691
|
-
for (const check of this._def.checks) {
|
|
1692
|
-
if (check.kind === "min") {
|
|
1693
|
-
const tooSmall = check.inclusive ? input.data < check.value : input.data <= check.value;
|
|
1694
|
-
if (tooSmall) {
|
|
1695
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1696
|
-
addIssueToContext(ctx, {
|
|
1697
|
-
code: ZodIssueCode.too_small,
|
|
1698
|
-
type: "bigint",
|
|
1699
|
-
minimum: check.value,
|
|
1700
|
-
inclusive: check.inclusive,
|
|
1701
|
-
message: check.message
|
|
1702
|
-
});
|
|
1703
|
-
status.dirty();
|
|
1704
|
-
}
|
|
1705
|
-
} else if (check.kind === "max") {
|
|
1706
|
-
const tooBig = check.inclusive ? input.data > check.value : input.data >= check.value;
|
|
1707
|
-
if (tooBig) {
|
|
1708
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1709
|
-
addIssueToContext(ctx, {
|
|
1710
|
-
code: ZodIssueCode.too_big,
|
|
1711
|
-
type: "bigint",
|
|
1712
|
-
maximum: check.value,
|
|
1713
|
-
inclusive: check.inclusive,
|
|
1714
|
-
message: check.message
|
|
1715
|
-
});
|
|
1716
|
-
status.dirty();
|
|
1717
|
-
}
|
|
1718
|
-
} else if (check.kind === "multipleOf") {
|
|
1719
|
-
if (input.data % check.value !== BigInt(0)) {
|
|
1720
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1721
|
-
addIssueToContext(ctx, {
|
|
1722
|
-
code: ZodIssueCode.not_multiple_of,
|
|
1723
|
-
multipleOf: check.value,
|
|
1724
|
-
message: check.message
|
|
1725
|
-
});
|
|
1726
|
-
status.dirty();
|
|
1727
|
-
}
|
|
1728
|
-
} else {
|
|
1729
|
-
util$5.assertNever(check);
|
|
1730
|
-
}
|
|
1731
|
-
}
|
|
1732
|
-
return {
|
|
1733
|
-
status: status.value,
|
|
1734
|
-
value: input.data
|
|
1735
|
-
};
|
|
1736
|
-
}
|
|
1737
|
-
gte(value, message) {
|
|
1738
|
-
return this.setLimit("min", value, true, errorUtil.toString(message));
|
|
1739
|
-
}
|
|
1740
|
-
gt(value, message) {
|
|
1741
|
-
return this.setLimit("min", value, false, errorUtil.toString(message));
|
|
1742
|
-
}
|
|
1743
|
-
lte(value, message) {
|
|
1744
|
-
return this.setLimit("max", value, true, errorUtil.toString(message));
|
|
1745
|
-
}
|
|
1746
|
-
lt(value, message) {
|
|
1747
|
-
return this.setLimit("max", value, false, errorUtil.toString(message));
|
|
1748
|
-
}
|
|
1749
|
-
setLimit(kind, value, inclusive, message) {
|
|
1750
|
-
return new ZodBigInt({
|
|
1751
|
-
...this._def,
|
|
1752
|
-
checks: [...this._def.checks, {
|
|
1753
|
-
kind,
|
|
1754
|
-
value,
|
|
1755
|
-
inclusive,
|
|
1756
|
-
message: errorUtil.toString(message)
|
|
1757
|
-
}]
|
|
1758
|
-
});
|
|
1759
|
-
}
|
|
1760
|
-
_addCheck(check) {
|
|
1761
|
-
return new ZodBigInt({
|
|
1762
|
-
...this._def,
|
|
1763
|
-
checks: [...this._def.checks, check]
|
|
1764
|
-
});
|
|
1765
|
-
}
|
|
1766
|
-
positive(message) {
|
|
1767
|
-
return this._addCheck({
|
|
1768
|
-
kind: "min",
|
|
1769
|
-
value: BigInt(0),
|
|
1770
|
-
inclusive: false,
|
|
1771
|
-
message: errorUtil.toString(message)
|
|
1772
|
-
});
|
|
1773
|
-
}
|
|
1774
|
-
negative(message) {
|
|
1775
|
-
return this._addCheck({
|
|
1776
|
-
kind: "max",
|
|
1777
|
-
value: BigInt(0),
|
|
1778
|
-
inclusive: false,
|
|
1779
|
-
message: errorUtil.toString(message)
|
|
1780
|
-
});
|
|
1781
|
-
}
|
|
1782
|
-
nonpositive(message) {
|
|
1783
|
-
return this._addCheck({
|
|
1784
|
-
kind: "max",
|
|
1785
|
-
value: BigInt(0),
|
|
1786
|
-
inclusive: true,
|
|
1787
|
-
message: errorUtil.toString(message)
|
|
1788
|
-
});
|
|
1789
|
-
}
|
|
1790
|
-
nonnegative(message) {
|
|
1791
|
-
return this._addCheck({
|
|
1792
|
-
kind: "min",
|
|
1793
|
-
value: BigInt(0),
|
|
1794
|
-
inclusive: true,
|
|
1795
|
-
message: errorUtil.toString(message)
|
|
1796
|
-
});
|
|
1797
|
-
}
|
|
1798
|
-
multipleOf(value, message) {
|
|
1799
|
-
return this._addCheck({
|
|
1800
|
-
kind: "multipleOf",
|
|
1801
|
-
value,
|
|
1802
|
-
message: errorUtil.toString(message)
|
|
1803
|
-
});
|
|
1804
|
-
}
|
|
1805
|
-
get minValue() {
|
|
1806
|
-
let min = null;
|
|
1807
|
-
for (const ch of this._def.checks) {
|
|
1808
|
-
if (ch.kind === "min") {
|
|
1809
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1810
|
-
}
|
|
1811
|
-
}
|
|
1812
|
-
return min;
|
|
1813
|
-
}
|
|
1814
|
-
get maxValue() {
|
|
1815
|
-
let max = null;
|
|
1816
|
-
for (const ch of this._def.checks) {
|
|
1817
|
-
if (ch.kind === "max") {
|
|
1818
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1819
|
-
}
|
|
1820
|
-
}
|
|
1821
|
-
return max;
|
|
1822
|
-
}
|
|
1823
|
-
}
|
|
1824
|
-
ZodBigInt.create = params => {
|
|
1825
|
-
var _a;
|
|
1826
|
-
return new ZodBigInt({
|
|
1827
|
-
checks: [],
|
|
1828
|
-
typeName: ZodFirstPartyTypeKind.ZodBigInt,
|
|
1829
|
-
coerce: (_a = params === null || params === void 0 ? void 0 : params.coerce) !== null && _a !== void 0 ? _a : false,
|
|
1830
|
-
...processCreateParams(params)
|
|
1831
|
-
});
|
|
1832
|
-
};
|
|
1833
|
-
class ZodBoolean extends ZodType {
|
|
1834
|
-
_parse(input) {
|
|
1835
|
-
if (this._def.coerce) {
|
|
1836
|
-
input.data = Boolean(input.data);
|
|
1837
|
-
}
|
|
1838
|
-
const parsedType = this._getType(input);
|
|
1839
|
-
if (parsedType !== ZodParsedType.boolean) {
|
|
1840
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1841
|
-
addIssueToContext(ctx, {
|
|
1842
|
-
code: ZodIssueCode.invalid_type,
|
|
1843
|
-
expected: ZodParsedType.boolean,
|
|
1844
|
-
received: ctx.parsedType
|
|
1845
|
-
});
|
|
1846
|
-
return INVALID;
|
|
1847
|
-
}
|
|
1848
|
-
return OK(input.data);
|
|
1849
|
-
}
|
|
1850
|
-
}
|
|
1851
|
-
ZodBoolean.create = params => {
|
|
1852
|
-
return new ZodBoolean({
|
|
1853
|
-
typeName: ZodFirstPartyTypeKind.ZodBoolean,
|
|
1854
|
-
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1855
|
-
...processCreateParams(params)
|
|
1856
|
-
});
|
|
1857
|
-
};
|
|
1858
|
-
class ZodDate extends ZodType {
|
|
1859
|
-
_parse(input) {
|
|
1860
|
-
if (this._def.coerce) {
|
|
1861
|
-
input.data = new Date(input.data);
|
|
1862
|
-
}
|
|
1863
|
-
const parsedType = this._getType(input);
|
|
1864
|
-
if (parsedType !== ZodParsedType.date) {
|
|
1865
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1866
|
-
addIssueToContext(ctx, {
|
|
1867
|
-
code: ZodIssueCode.invalid_type,
|
|
1868
|
-
expected: ZodParsedType.date,
|
|
1869
|
-
received: ctx.parsedType
|
|
1870
|
-
});
|
|
1871
|
-
return INVALID;
|
|
1872
|
-
}
|
|
1873
|
-
if (isNaN(input.data.getTime())) {
|
|
1874
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1875
|
-
addIssueToContext(ctx, {
|
|
1876
|
-
code: ZodIssueCode.invalid_date
|
|
1877
|
-
});
|
|
1878
|
-
return INVALID;
|
|
1879
|
-
}
|
|
1880
|
-
const status = new ParseStatus();
|
|
1881
|
-
let ctx = undefined;
|
|
1882
|
-
for (const check of this._def.checks) {
|
|
1883
|
-
if (check.kind === "min") {
|
|
1884
|
-
if (input.data.getTime() < check.value) {
|
|
1885
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1886
|
-
addIssueToContext(ctx, {
|
|
1887
|
-
code: ZodIssueCode.too_small,
|
|
1888
|
-
message: check.message,
|
|
1889
|
-
inclusive: true,
|
|
1890
|
-
exact: false,
|
|
1891
|
-
minimum: check.value,
|
|
1892
|
-
type: "date"
|
|
1893
|
-
});
|
|
1894
|
-
status.dirty();
|
|
1895
|
-
}
|
|
1896
|
-
} else if (check.kind === "max") {
|
|
1897
|
-
if (input.data.getTime() > check.value) {
|
|
1898
|
-
ctx = this._getOrReturnCtx(input, ctx);
|
|
1899
|
-
addIssueToContext(ctx, {
|
|
1900
|
-
code: ZodIssueCode.too_big,
|
|
1901
|
-
message: check.message,
|
|
1902
|
-
inclusive: true,
|
|
1903
|
-
exact: false,
|
|
1904
|
-
maximum: check.value,
|
|
1905
|
-
type: "date"
|
|
1906
|
-
});
|
|
1907
|
-
status.dirty();
|
|
1908
|
-
}
|
|
1909
|
-
} else {
|
|
1910
|
-
util$5.assertNever(check);
|
|
1911
|
-
}
|
|
1912
|
-
}
|
|
1913
|
-
return {
|
|
1914
|
-
status: status.value,
|
|
1915
|
-
value: new Date(input.data.getTime())
|
|
1916
|
-
};
|
|
1917
|
-
}
|
|
1918
|
-
_addCheck(check) {
|
|
1919
|
-
return new ZodDate({
|
|
1920
|
-
...this._def,
|
|
1921
|
-
checks: [...this._def.checks, check]
|
|
1922
|
-
});
|
|
1923
|
-
}
|
|
1924
|
-
min(minDate, message) {
|
|
1925
|
-
return this._addCheck({
|
|
1926
|
-
kind: "min",
|
|
1927
|
-
value: minDate.getTime(),
|
|
1928
|
-
message: errorUtil.toString(message)
|
|
1929
|
-
});
|
|
1930
|
-
}
|
|
1931
|
-
max(maxDate, message) {
|
|
1932
|
-
return this._addCheck({
|
|
1933
|
-
kind: "max",
|
|
1934
|
-
value: maxDate.getTime(),
|
|
1935
|
-
message: errorUtil.toString(message)
|
|
1936
|
-
});
|
|
1937
|
-
}
|
|
1938
|
-
get minDate() {
|
|
1939
|
-
let min = null;
|
|
1940
|
-
for (const ch of this._def.checks) {
|
|
1941
|
-
if (ch.kind === "min") {
|
|
1942
|
-
if (min === null || ch.value > min) min = ch.value;
|
|
1943
|
-
}
|
|
1944
|
-
}
|
|
1945
|
-
return min != null ? new Date(min) : null;
|
|
1946
|
-
}
|
|
1947
|
-
get maxDate() {
|
|
1948
|
-
let max = null;
|
|
1949
|
-
for (const ch of this._def.checks) {
|
|
1950
|
-
if (ch.kind === "max") {
|
|
1951
|
-
if (max === null || ch.value < max) max = ch.value;
|
|
1952
|
-
}
|
|
1953
|
-
}
|
|
1954
|
-
return max != null ? new Date(max) : null;
|
|
1955
|
-
}
|
|
1956
|
-
}
|
|
1957
|
-
ZodDate.create = params => {
|
|
1958
|
-
return new ZodDate({
|
|
1959
|
-
checks: [],
|
|
1960
|
-
coerce: (params === null || params === void 0 ? void 0 : params.coerce) || false,
|
|
1961
|
-
typeName: ZodFirstPartyTypeKind.ZodDate,
|
|
1962
|
-
...processCreateParams(params)
|
|
1963
|
-
});
|
|
1964
|
-
};
|
|
1965
|
-
class ZodSymbol extends ZodType {
|
|
1966
|
-
_parse(input) {
|
|
1967
|
-
const parsedType = this._getType(input);
|
|
1968
|
-
if (parsedType !== ZodParsedType.symbol) {
|
|
1969
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1970
|
-
addIssueToContext(ctx, {
|
|
1971
|
-
code: ZodIssueCode.invalid_type,
|
|
1972
|
-
expected: ZodParsedType.symbol,
|
|
1973
|
-
received: ctx.parsedType
|
|
1974
|
-
});
|
|
1975
|
-
return INVALID;
|
|
1976
|
-
}
|
|
1977
|
-
return OK(input.data);
|
|
1978
|
-
}
|
|
1979
|
-
}
|
|
1980
|
-
ZodSymbol.create = params => {
|
|
1981
|
-
return new ZodSymbol({
|
|
1982
|
-
typeName: ZodFirstPartyTypeKind.ZodSymbol,
|
|
1983
|
-
...processCreateParams(params)
|
|
1984
|
-
});
|
|
1985
|
-
};
|
|
1986
|
-
class ZodUndefined extends ZodType {
|
|
1987
|
-
_parse(input) {
|
|
1988
|
-
const parsedType = this._getType(input);
|
|
1989
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
1990
|
-
const ctx = this._getOrReturnCtx(input);
|
|
1991
|
-
addIssueToContext(ctx, {
|
|
1992
|
-
code: ZodIssueCode.invalid_type,
|
|
1993
|
-
expected: ZodParsedType.undefined,
|
|
1994
|
-
received: ctx.parsedType
|
|
1995
|
-
});
|
|
1996
|
-
return INVALID;
|
|
1997
|
-
}
|
|
1998
|
-
return OK(input.data);
|
|
1999
|
-
}
|
|
2000
|
-
}
|
|
2001
|
-
ZodUndefined.create = params => {
|
|
2002
|
-
return new ZodUndefined({
|
|
2003
|
-
typeName: ZodFirstPartyTypeKind.ZodUndefined,
|
|
2004
|
-
...processCreateParams(params)
|
|
2005
|
-
});
|
|
2006
|
-
};
|
|
2007
|
-
class ZodNull extends ZodType {
|
|
2008
|
-
_parse(input) {
|
|
2009
|
-
const parsedType = this._getType(input);
|
|
2010
|
-
if (parsedType !== ZodParsedType.null) {
|
|
2011
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2012
|
-
addIssueToContext(ctx, {
|
|
2013
|
-
code: ZodIssueCode.invalid_type,
|
|
2014
|
-
expected: ZodParsedType.null,
|
|
2015
|
-
received: ctx.parsedType
|
|
2016
|
-
});
|
|
2017
|
-
return INVALID;
|
|
2018
|
-
}
|
|
2019
|
-
return OK(input.data);
|
|
2020
|
-
}
|
|
2021
|
-
}
|
|
2022
|
-
ZodNull.create = params => {
|
|
2023
|
-
return new ZodNull({
|
|
2024
|
-
typeName: ZodFirstPartyTypeKind.ZodNull,
|
|
2025
|
-
...processCreateParams(params)
|
|
2026
|
-
});
|
|
2027
|
-
};
|
|
2028
|
-
class ZodAny extends ZodType {
|
|
2029
|
-
constructor() {
|
|
2030
|
-
super(...arguments);
|
|
2031
|
-
// to prevent instances of other classes from extending ZodAny. this causes issues with catchall in ZodObject.
|
|
2032
|
-
this._any = true;
|
|
2033
|
-
}
|
|
2034
|
-
_parse(input) {
|
|
2035
|
-
return OK(input.data);
|
|
2036
|
-
}
|
|
2037
|
-
}
|
|
2038
|
-
ZodAny.create = params => {
|
|
2039
|
-
return new ZodAny({
|
|
2040
|
-
typeName: ZodFirstPartyTypeKind.ZodAny,
|
|
2041
|
-
...processCreateParams(params)
|
|
2042
|
-
});
|
|
2043
|
-
};
|
|
2044
|
-
class ZodUnknown extends ZodType {
|
|
2045
|
-
constructor() {
|
|
2046
|
-
super(...arguments);
|
|
2047
|
-
// required
|
|
2048
|
-
this._unknown = true;
|
|
2049
|
-
}
|
|
2050
|
-
_parse(input) {
|
|
2051
|
-
return OK(input.data);
|
|
2052
|
-
}
|
|
2053
|
-
}
|
|
2054
|
-
ZodUnknown.create = params => {
|
|
2055
|
-
return new ZodUnknown({
|
|
2056
|
-
typeName: ZodFirstPartyTypeKind.ZodUnknown,
|
|
2057
|
-
...processCreateParams(params)
|
|
2058
|
-
});
|
|
2059
|
-
};
|
|
2060
|
-
class ZodNever extends ZodType {
|
|
2061
|
-
_parse(input) {
|
|
2062
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2063
|
-
addIssueToContext(ctx, {
|
|
2064
|
-
code: ZodIssueCode.invalid_type,
|
|
2065
|
-
expected: ZodParsedType.never,
|
|
2066
|
-
received: ctx.parsedType
|
|
2067
|
-
});
|
|
2068
|
-
return INVALID;
|
|
2069
|
-
}
|
|
2070
|
-
}
|
|
2071
|
-
ZodNever.create = params => {
|
|
2072
|
-
return new ZodNever({
|
|
2073
|
-
typeName: ZodFirstPartyTypeKind.ZodNever,
|
|
2074
|
-
...processCreateParams(params)
|
|
2075
|
-
});
|
|
2076
|
-
};
|
|
2077
|
-
class ZodVoid extends ZodType {
|
|
2078
|
-
_parse(input) {
|
|
2079
|
-
const parsedType = this._getType(input);
|
|
2080
|
-
if (parsedType !== ZodParsedType.undefined) {
|
|
2081
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2082
|
-
addIssueToContext(ctx, {
|
|
2083
|
-
code: ZodIssueCode.invalid_type,
|
|
2084
|
-
expected: ZodParsedType.void,
|
|
2085
|
-
received: ctx.parsedType
|
|
2086
|
-
});
|
|
2087
|
-
return INVALID;
|
|
2088
|
-
}
|
|
2089
|
-
return OK(input.data);
|
|
2090
|
-
}
|
|
2091
|
-
}
|
|
2092
|
-
ZodVoid.create = params => {
|
|
2093
|
-
return new ZodVoid({
|
|
2094
|
-
typeName: ZodFirstPartyTypeKind.ZodVoid,
|
|
2095
|
-
...processCreateParams(params)
|
|
2096
|
-
});
|
|
2097
|
-
};
|
|
2098
|
-
class ZodArray extends ZodType {
|
|
2099
|
-
_parse(input) {
|
|
2100
|
-
const {
|
|
2101
|
-
ctx,
|
|
2102
|
-
status
|
|
2103
|
-
} = this._processInputParams(input);
|
|
2104
|
-
const def = this._def;
|
|
2105
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2106
|
-
addIssueToContext(ctx, {
|
|
2107
|
-
code: ZodIssueCode.invalid_type,
|
|
2108
|
-
expected: ZodParsedType.array,
|
|
2109
|
-
received: ctx.parsedType
|
|
2110
|
-
});
|
|
2111
|
-
return INVALID;
|
|
2112
|
-
}
|
|
2113
|
-
if (def.exactLength !== null) {
|
|
2114
|
-
const tooBig = ctx.data.length > def.exactLength.value;
|
|
2115
|
-
const tooSmall = ctx.data.length < def.exactLength.value;
|
|
2116
|
-
if (tooBig || tooSmall) {
|
|
2117
|
-
addIssueToContext(ctx, {
|
|
2118
|
-
code: tooBig ? ZodIssueCode.too_big : ZodIssueCode.too_small,
|
|
2119
|
-
minimum: tooSmall ? def.exactLength.value : undefined,
|
|
2120
|
-
maximum: tooBig ? def.exactLength.value : undefined,
|
|
2121
|
-
type: "array",
|
|
2122
|
-
inclusive: true,
|
|
2123
|
-
exact: true,
|
|
2124
|
-
message: def.exactLength.message
|
|
2125
|
-
});
|
|
2126
|
-
status.dirty();
|
|
2127
|
-
}
|
|
2128
|
-
}
|
|
2129
|
-
if (def.minLength !== null) {
|
|
2130
|
-
if (ctx.data.length < def.minLength.value) {
|
|
2131
|
-
addIssueToContext(ctx, {
|
|
2132
|
-
code: ZodIssueCode.too_small,
|
|
2133
|
-
minimum: def.minLength.value,
|
|
2134
|
-
type: "array",
|
|
2135
|
-
inclusive: true,
|
|
2136
|
-
exact: false,
|
|
2137
|
-
message: def.minLength.message
|
|
2138
|
-
});
|
|
2139
|
-
status.dirty();
|
|
2140
|
-
}
|
|
2141
|
-
}
|
|
2142
|
-
if (def.maxLength !== null) {
|
|
2143
|
-
if (ctx.data.length > def.maxLength.value) {
|
|
2144
|
-
addIssueToContext(ctx, {
|
|
2145
|
-
code: ZodIssueCode.too_big,
|
|
2146
|
-
maximum: def.maxLength.value,
|
|
2147
|
-
type: "array",
|
|
2148
|
-
inclusive: true,
|
|
2149
|
-
exact: false,
|
|
2150
|
-
message: def.maxLength.message
|
|
2151
|
-
});
|
|
2152
|
-
status.dirty();
|
|
2153
|
-
}
|
|
2154
|
-
}
|
|
2155
|
-
if (ctx.common.async) {
|
|
2156
|
-
return Promise.all([...ctx.data].map((item, i) => {
|
|
2157
|
-
return def.type._parseAsync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2158
|
-
})).then(result => {
|
|
2159
|
-
return ParseStatus.mergeArray(status, result);
|
|
2160
|
-
});
|
|
2161
|
-
}
|
|
2162
|
-
const result = [...ctx.data].map((item, i) => {
|
|
2163
|
-
return def.type._parseSync(new ParseInputLazyPath(ctx, item, ctx.path, i));
|
|
2164
|
-
});
|
|
2165
|
-
return ParseStatus.mergeArray(status, result);
|
|
2166
|
-
}
|
|
2167
|
-
get element() {
|
|
2168
|
-
return this._def.type;
|
|
2169
|
-
}
|
|
2170
|
-
min(minLength, message) {
|
|
2171
|
-
return new ZodArray({
|
|
2172
|
-
...this._def,
|
|
2173
|
-
minLength: {
|
|
2174
|
-
value: minLength,
|
|
2175
|
-
message: errorUtil.toString(message)
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
}
|
|
2179
|
-
max(maxLength, message) {
|
|
2180
|
-
return new ZodArray({
|
|
2181
|
-
...this._def,
|
|
2182
|
-
maxLength: {
|
|
2183
|
-
value: maxLength,
|
|
2184
|
-
message: errorUtil.toString(message)
|
|
2185
|
-
}
|
|
2186
|
-
});
|
|
2187
|
-
}
|
|
2188
|
-
length(len, message) {
|
|
2189
|
-
return new ZodArray({
|
|
2190
|
-
...this._def,
|
|
2191
|
-
exactLength: {
|
|
2192
|
-
value: len,
|
|
2193
|
-
message: errorUtil.toString(message)
|
|
2194
|
-
}
|
|
2195
|
-
});
|
|
2196
|
-
}
|
|
2197
|
-
nonempty(message) {
|
|
2198
|
-
return this.min(1, message);
|
|
2199
|
-
}
|
|
2200
|
-
}
|
|
2201
|
-
ZodArray.create = (schema, params) => {
|
|
2202
|
-
return new ZodArray({
|
|
2203
|
-
type: schema,
|
|
2204
|
-
minLength: null,
|
|
2205
|
-
maxLength: null,
|
|
2206
|
-
exactLength: null,
|
|
2207
|
-
typeName: ZodFirstPartyTypeKind.ZodArray,
|
|
2208
|
-
...processCreateParams(params)
|
|
2209
|
-
});
|
|
2210
|
-
};
|
|
2211
|
-
function deepPartialify(schema) {
|
|
2212
|
-
if (schema instanceof ZodObject) {
|
|
2213
|
-
const newShape = {};
|
|
2214
|
-
for (const key in schema.shape) {
|
|
2215
|
-
const fieldSchema = schema.shape[key];
|
|
2216
|
-
newShape[key] = ZodOptional.create(deepPartialify(fieldSchema));
|
|
2217
|
-
}
|
|
2218
|
-
return new ZodObject({
|
|
2219
|
-
...schema._def,
|
|
2220
|
-
shape: () => newShape
|
|
2221
|
-
});
|
|
2222
|
-
} else if (schema instanceof ZodArray) {
|
|
2223
|
-
return new ZodArray({
|
|
2224
|
-
...schema._def,
|
|
2225
|
-
type: deepPartialify(schema.element)
|
|
2226
|
-
});
|
|
2227
|
-
} else if (schema instanceof ZodOptional) {
|
|
2228
|
-
return ZodOptional.create(deepPartialify(schema.unwrap()));
|
|
2229
|
-
} else if (schema instanceof ZodNullable) {
|
|
2230
|
-
return ZodNullable.create(deepPartialify(schema.unwrap()));
|
|
2231
|
-
} else if (schema instanceof ZodTuple) {
|
|
2232
|
-
return ZodTuple.create(schema.items.map(item => deepPartialify(item)));
|
|
2233
|
-
} else {
|
|
2234
|
-
return schema;
|
|
2235
|
-
}
|
|
2236
|
-
}
|
|
2237
|
-
class ZodObject extends ZodType {
|
|
2238
|
-
constructor() {
|
|
2239
|
-
super(...arguments);
|
|
2240
|
-
this._cached = null;
|
|
2241
|
-
/**
|
|
2242
|
-
* @deprecated In most cases, this is no longer needed - unknown properties are now silently stripped.
|
|
2243
|
-
* If you want to pass through unknown properties, use `.passthrough()` instead.
|
|
2244
|
-
*/
|
|
2245
|
-
this.nonstrict = this.passthrough;
|
|
2246
|
-
// extend<
|
|
2247
|
-
// Augmentation extends ZodRawShape,
|
|
2248
|
-
// NewOutput extends util.flatten<{
|
|
2249
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2250
|
-
// ? Augmentation[k]["_output"]
|
|
2251
|
-
// : k extends keyof Output
|
|
2252
|
-
// ? Output[k]
|
|
2253
|
-
// : never;
|
|
2254
|
-
// }>,
|
|
2255
|
-
// NewInput extends util.flatten<{
|
|
2256
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2257
|
-
// ? Augmentation[k]["_input"]
|
|
2258
|
-
// : k extends keyof Input
|
|
2259
|
-
// ? Input[k]
|
|
2260
|
-
// : never;
|
|
2261
|
-
// }>
|
|
2262
|
-
// >(
|
|
2263
|
-
// augmentation: Augmentation
|
|
2264
|
-
// ): ZodObject<
|
|
2265
|
-
// extendShape<T, Augmentation>,
|
|
2266
|
-
// UnknownKeys,
|
|
2267
|
-
// Catchall,
|
|
2268
|
-
// NewOutput,
|
|
2269
|
-
// NewInput
|
|
2270
|
-
// > {
|
|
2271
|
-
// return new ZodObject({
|
|
2272
|
-
// ...this._def,
|
|
2273
|
-
// shape: () => ({
|
|
2274
|
-
// ...this._def.shape(),
|
|
2275
|
-
// ...augmentation,
|
|
2276
|
-
// }),
|
|
2277
|
-
// }) as any;
|
|
2278
|
-
// }
|
|
2279
|
-
/**
|
|
2280
|
-
* @deprecated Use `.extend` instead
|
|
2281
|
-
* */
|
|
2282
|
-
this.augment = this.extend;
|
|
2283
|
-
}
|
|
2284
|
-
_getCached() {
|
|
2285
|
-
if (this._cached !== null) return this._cached;
|
|
2286
|
-
const shape = this._def.shape();
|
|
2287
|
-
const keys = util$5.objectKeys(shape);
|
|
2288
|
-
return this._cached = {
|
|
2289
|
-
shape,
|
|
2290
|
-
keys
|
|
2291
|
-
};
|
|
2292
|
-
}
|
|
2293
|
-
_parse(input) {
|
|
2294
|
-
const parsedType = this._getType(input);
|
|
2295
|
-
if (parsedType !== ZodParsedType.object) {
|
|
2296
|
-
const ctx = this._getOrReturnCtx(input);
|
|
2297
|
-
addIssueToContext(ctx, {
|
|
2298
|
-
code: ZodIssueCode.invalid_type,
|
|
2299
|
-
expected: ZodParsedType.object,
|
|
2300
|
-
received: ctx.parsedType
|
|
2301
|
-
});
|
|
2302
|
-
return INVALID;
|
|
2303
|
-
}
|
|
2304
|
-
const {
|
|
2305
|
-
status,
|
|
2306
|
-
ctx
|
|
2307
|
-
} = this._processInputParams(input);
|
|
2308
|
-
const {
|
|
2309
|
-
shape,
|
|
2310
|
-
keys: shapeKeys
|
|
2311
|
-
} = this._getCached();
|
|
2312
|
-
const extraKeys = [];
|
|
2313
|
-
if (!(this._def.catchall instanceof ZodNever && this._def.unknownKeys === "strip")) {
|
|
2314
|
-
for (const key in ctx.data) {
|
|
2315
|
-
if (!shapeKeys.includes(key)) {
|
|
2316
|
-
extraKeys.push(key);
|
|
2317
|
-
}
|
|
2318
|
-
}
|
|
2319
|
-
}
|
|
2320
|
-
const pairs = [];
|
|
2321
|
-
for (const key of shapeKeys) {
|
|
2322
|
-
const keyValidator = shape[key];
|
|
2323
|
-
const value = ctx.data[key];
|
|
2324
|
-
pairs.push({
|
|
2325
|
-
key: {
|
|
2326
|
-
status: "valid",
|
|
2327
|
-
value: key
|
|
2328
|
-
},
|
|
2329
|
-
value: keyValidator._parse(new ParseInputLazyPath(ctx, value, ctx.path, key)),
|
|
2330
|
-
alwaysSet: key in ctx.data
|
|
2331
|
-
});
|
|
2332
|
-
}
|
|
2333
|
-
if (this._def.catchall instanceof ZodNever) {
|
|
2334
|
-
const unknownKeys = this._def.unknownKeys;
|
|
2335
|
-
if (unknownKeys === "passthrough") {
|
|
2336
|
-
for (const key of extraKeys) {
|
|
2337
|
-
pairs.push({
|
|
2338
|
-
key: {
|
|
2339
|
-
status: "valid",
|
|
2340
|
-
value: key
|
|
2341
|
-
},
|
|
2342
|
-
value: {
|
|
2343
|
-
status: "valid",
|
|
2344
|
-
value: ctx.data[key]
|
|
2345
|
-
}
|
|
2346
|
-
});
|
|
2347
|
-
}
|
|
2348
|
-
} else if (unknownKeys === "strict") {
|
|
2349
|
-
if (extraKeys.length > 0) {
|
|
2350
|
-
addIssueToContext(ctx, {
|
|
2351
|
-
code: ZodIssueCode.unrecognized_keys,
|
|
2352
|
-
keys: extraKeys
|
|
2353
|
-
});
|
|
2354
|
-
status.dirty();
|
|
2355
|
-
}
|
|
2356
|
-
} else if (unknownKeys === "strip") ;else {
|
|
2357
|
-
throw new Error(`Internal ZodObject error: invalid unknownKeys value.`);
|
|
2358
|
-
}
|
|
2359
|
-
} else {
|
|
2360
|
-
// run catchall validation
|
|
2361
|
-
const catchall = this._def.catchall;
|
|
2362
|
-
for (const key of extraKeys) {
|
|
2363
|
-
const value = ctx.data[key];
|
|
2364
|
-
pairs.push({
|
|
2365
|
-
key: {
|
|
2366
|
-
status: "valid",
|
|
2367
|
-
value: key
|
|
2368
|
-
},
|
|
2369
|
-
value: catchall._parse(new ParseInputLazyPath(ctx, value, ctx.path, key) //, ctx.child(key), value, getParsedType(value)
|
|
2370
|
-
),
|
|
2371
|
-
alwaysSet: key in ctx.data
|
|
2372
|
-
});
|
|
2373
|
-
}
|
|
2374
|
-
}
|
|
2375
|
-
if (ctx.common.async) {
|
|
2376
|
-
return Promise.resolve().then(async () => {
|
|
2377
|
-
const syncPairs = [];
|
|
2378
|
-
for (const pair of pairs) {
|
|
2379
|
-
const key = await pair.key;
|
|
2380
|
-
syncPairs.push({
|
|
2381
|
-
key,
|
|
2382
|
-
value: await pair.value,
|
|
2383
|
-
alwaysSet: pair.alwaysSet
|
|
2384
|
-
});
|
|
2385
|
-
}
|
|
2386
|
-
return syncPairs;
|
|
2387
|
-
}).then(syncPairs => {
|
|
2388
|
-
return ParseStatus.mergeObjectSync(status, syncPairs);
|
|
2389
|
-
});
|
|
2390
|
-
} else {
|
|
2391
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
2392
|
-
}
|
|
2393
|
-
}
|
|
2394
|
-
get shape() {
|
|
2395
|
-
return this._def.shape();
|
|
2396
|
-
}
|
|
2397
|
-
strict(message) {
|
|
2398
|
-
errorUtil.errToObj;
|
|
2399
|
-
return new ZodObject({
|
|
2400
|
-
...this._def,
|
|
2401
|
-
unknownKeys: "strict",
|
|
2402
|
-
...(message !== undefined ? {
|
|
2403
|
-
errorMap: (issue, ctx) => {
|
|
2404
|
-
var _a, _b, _c, _d;
|
|
2405
|
-
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
2406
|
-
if (issue.code === "unrecognized_keys") return {
|
|
2407
|
-
message: (_d = errorUtil.errToObj(message).message) !== null && _d !== void 0 ? _d : defaultError
|
|
2408
|
-
};
|
|
2409
|
-
return {
|
|
2410
|
-
message: defaultError
|
|
2411
|
-
};
|
|
2412
|
-
}
|
|
2413
|
-
} : {})
|
|
2414
|
-
});
|
|
2415
|
-
}
|
|
2416
|
-
strip() {
|
|
2417
|
-
return new ZodObject({
|
|
2418
|
-
...this._def,
|
|
2419
|
-
unknownKeys: "strip"
|
|
2420
|
-
});
|
|
2421
|
-
}
|
|
2422
|
-
passthrough() {
|
|
2423
|
-
return new ZodObject({
|
|
2424
|
-
...this._def,
|
|
2425
|
-
unknownKeys: "passthrough"
|
|
2426
|
-
});
|
|
2427
|
-
}
|
|
2428
|
-
// const AugmentFactory =
|
|
2429
|
-
// <Def extends ZodObjectDef>(def: Def) =>
|
|
2430
|
-
// <Augmentation extends ZodRawShape>(
|
|
2431
|
-
// augmentation: Augmentation
|
|
2432
|
-
// ): ZodObject<
|
|
2433
|
-
// extendShape<ReturnType<Def["shape"]>, Augmentation>,
|
|
2434
|
-
// Def["unknownKeys"],
|
|
2435
|
-
// Def["catchall"]
|
|
2436
|
-
// > => {
|
|
2437
|
-
// return new ZodObject({
|
|
2438
|
-
// ...def,
|
|
2439
|
-
// shape: () => ({
|
|
2440
|
-
// ...def.shape(),
|
|
2441
|
-
// ...augmentation,
|
|
2442
|
-
// }),
|
|
2443
|
-
// }) as any;
|
|
2444
|
-
// };
|
|
2445
|
-
extend(augmentation) {
|
|
2446
|
-
return new ZodObject({
|
|
2447
|
-
...this._def,
|
|
2448
|
-
shape: () => ({
|
|
2449
|
-
...this._def.shape(),
|
|
2450
|
-
...augmentation
|
|
2451
|
-
})
|
|
2452
|
-
});
|
|
2453
|
-
}
|
|
2454
|
-
/**
|
|
2455
|
-
* Prior to zod@1.0.12 there was a bug in the
|
|
2456
|
-
* inferred type of merged objects. Please
|
|
2457
|
-
* upgrade if you are experiencing issues.
|
|
2458
|
-
*/
|
|
2459
|
-
merge(merging) {
|
|
2460
|
-
const merged = new ZodObject({
|
|
2461
|
-
unknownKeys: merging._def.unknownKeys,
|
|
2462
|
-
catchall: merging._def.catchall,
|
|
2463
|
-
shape: () => ({
|
|
2464
|
-
...this._def.shape(),
|
|
2465
|
-
...merging._def.shape()
|
|
2466
|
-
}),
|
|
2467
|
-
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2468
|
-
});
|
|
2469
|
-
return merged;
|
|
2470
|
-
}
|
|
2471
|
-
// merge<
|
|
2472
|
-
// Incoming extends AnyZodObject,
|
|
2473
|
-
// Augmentation extends Incoming["shape"],
|
|
2474
|
-
// NewOutput extends {
|
|
2475
|
-
// [k in keyof Augmentation | keyof Output]: k extends keyof Augmentation
|
|
2476
|
-
// ? Augmentation[k]["_output"]
|
|
2477
|
-
// : k extends keyof Output
|
|
2478
|
-
// ? Output[k]
|
|
2479
|
-
// : never;
|
|
2480
|
-
// },
|
|
2481
|
-
// NewInput extends {
|
|
2482
|
-
// [k in keyof Augmentation | keyof Input]: k extends keyof Augmentation
|
|
2483
|
-
// ? Augmentation[k]["_input"]
|
|
2484
|
-
// : k extends keyof Input
|
|
2485
|
-
// ? Input[k]
|
|
2486
|
-
// : never;
|
|
2487
|
-
// }
|
|
2488
|
-
// >(
|
|
2489
|
-
// merging: Incoming
|
|
2490
|
-
// ): ZodObject<
|
|
2491
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2492
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2493
|
-
// Incoming["_def"]["catchall"],
|
|
2494
|
-
// NewOutput,
|
|
2495
|
-
// NewInput
|
|
2496
|
-
// > {
|
|
2497
|
-
// const merged: any = new ZodObject({
|
|
2498
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2499
|
-
// catchall: merging._def.catchall,
|
|
2500
|
-
// shape: () =>
|
|
2501
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2502
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2503
|
-
// }) as any;
|
|
2504
|
-
// return merged;
|
|
2505
|
-
// }
|
|
2506
|
-
setKey(key, schema) {
|
|
2507
|
-
return this.augment({
|
|
2508
|
-
[key]: schema
|
|
2509
|
-
});
|
|
2510
|
-
}
|
|
2511
|
-
// merge<Incoming extends AnyZodObject>(
|
|
2512
|
-
// merging: Incoming
|
|
2513
|
-
// ): //ZodObject<T & Incoming["_shape"], UnknownKeys, Catchall> = (merging) => {
|
|
2514
|
-
// ZodObject<
|
|
2515
|
-
// extendShape<T, ReturnType<Incoming["_def"]["shape"]>>,
|
|
2516
|
-
// Incoming["_def"]["unknownKeys"],
|
|
2517
|
-
// Incoming["_def"]["catchall"]
|
|
2518
|
-
// > {
|
|
2519
|
-
// // const mergedShape = objectUtil.mergeShapes(
|
|
2520
|
-
// // this._def.shape(),
|
|
2521
|
-
// // merging._def.shape()
|
|
2522
|
-
// // );
|
|
2523
|
-
// const merged: any = new ZodObject({
|
|
2524
|
-
// unknownKeys: merging._def.unknownKeys,
|
|
2525
|
-
// catchall: merging._def.catchall,
|
|
2526
|
-
// shape: () =>
|
|
2527
|
-
// objectUtil.mergeShapes(this._def.shape(), merging._def.shape()),
|
|
2528
|
-
// typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2529
|
-
// }) as any;
|
|
2530
|
-
// return merged;
|
|
2531
|
-
// }
|
|
2532
|
-
catchall(index) {
|
|
2533
|
-
return new ZodObject({
|
|
2534
|
-
...this._def,
|
|
2535
|
-
catchall: index
|
|
2536
|
-
});
|
|
2537
|
-
}
|
|
2538
|
-
pick(mask) {
|
|
2539
|
-
const shape = {};
|
|
2540
|
-
util$5.objectKeys(mask).forEach(key => {
|
|
2541
|
-
if (mask[key] && this.shape[key]) {
|
|
2542
|
-
shape[key] = this.shape[key];
|
|
2543
|
-
}
|
|
2544
|
-
});
|
|
2545
|
-
return new ZodObject({
|
|
2546
|
-
...this._def,
|
|
2547
|
-
shape: () => shape
|
|
2548
|
-
});
|
|
2549
|
-
}
|
|
2550
|
-
omit(mask) {
|
|
2551
|
-
const shape = {};
|
|
2552
|
-
util$5.objectKeys(this.shape).forEach(key => {
|
|
2553
|
-
if (!mask[key]) {
|
|
2554
|
-
shape[key] = this.shape[key];
|
|
2555
|
-
}
|
|
2556
|
-
});
|
|
2557
|
-
return new ZodObject({
|
|
2558
|
-
...this._def,
|
|
2559
|
-
shape: () => shape
|
|
2560
|
-
});
|
|
2561
|
-
}
|
|
2562
|
-
/**
|
|
2563
|
-
* @deprecated
|
|
2564
|
-
*/
|
|
2565
|
-
deepPartial() {
|
|
2566
|
-
return deepPartialify(this);
|
|
2567
|
-
}
|
|
2568
|
-
partial(mask) {
|
|
2569
|
-
const newShape = {};
|
|
2570
|
-
util$5.objectKeys(this.shape).forEach(key => {
|
|
2571
|
-
const fieldSchema = this.shape[key];
|
|
2572
|
-
if (mask && !mask[key]) {
|
|
2573
|
-
newShape[key] = fieldSchema;
|
|
2574
|
-
} else {
|
|
2575
|
-
newShape[key] = fieldSchema.optional();
|
|
2576
|
-
}
|
|
2577
|
-
});
|
|
2578
|
-
return new ZodObject({
|
|
2579
|
-
...this._def,
|
|
2580
|
-
shape: () => newShape
|
|
2581
|
-
});
|
|
2582
|
-
}
|
|
2583
|
-
required(mask) {
|
|
2584
|
-
const newShape = {};
|
|
2585
|
-
util$5.objectKeys(this.shape).forEach(key => {
|
|
2586
|
-
if (mask && !mask[key]) {
|
|
2587
|
-
newShape[key] = this.shape[key];
|
|
2588
|
-
} else {
|
|
2589
|
-
const fieldSchema = this.shape[key];
|
|
2590
|
-
let newField = fieldSchema;
|
|
2591
|
-
while (newField instanceof ZodOptional) {
|
|
2592
|
-
newField = newField._def.innerType;
|
|
2593
|
-
}
|
|
2594
|
-
newShape[key] = newField;
|
|
2595
|
-
}
|
|
2596
|
-
});
|
|
2597
|
-
return new ZodObject({
|
|
2598
|
-
...this._def,
|
|
2599
|
-
shape: () => newShape
|
|
2600
|
-
});
|
|
2601
|
-
}
|
|
2602
|
-
keyof() {
|
|
2603
|
-
return createZodEnum(util$5.objectKeys(this.shape));
|
|
2604
|
-
}
|
|
2605
|
-
}
|
|
2606
|
-
ZodObject.create = (shape, params) => {
|
|
2607
|
-
return new ZodObject({
|
|
2608
|
-
shape: () => shape,
|
|
2609
|
-
unknownKeys: "strip",
|
|
2610
|
-
catchall: ZodNever.create(),
|
|
2611
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2612
|
-
...processCreateParams(params)
|
|
2613
|
-
});
|
|
2614
|
-
};
|
|
2615
|
-
ZodObject.strictCreate = (shape, params) => {
|
|
2616
|
-
return new ZodObject({
|
|
2617
|
-
shape: () => shape,
|
|
2618
|
-
unknownKeys: "strict",
|
|
2619
|
-
catchall: ZodNever.create(),
|
|
2620
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2621
|
-
...processCreateParams(params)
|
|
2622
|
-
});
|
|
2623
|
-
};
|
|
2624
|
-
ZodObject.lazycreate = (shape, params) => {
|
|
2625
|
-
return new ZodObject({
|
|
2626
|
-
shape,
|
|
2627
|
-
unknownKeys: "strip",
|
|
2628
|
-
catchall: ZodNever.create(),
|
|
2629
|
-
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
2630
|
-
...processCreateParams(params)
|
|
2631
|
-
});
|
|
2632
|
-
};
|
|
2633
|
-
class ZodUnion extends ZodType {
|
|
2634
|
-
_parse(input) {
|
|
2635
|
-
const {
|
|
2636
|
-
ctx
|
|
2637
|
-
} = this._processInputParams(input);
|
|
2638
|
-
const options = this._def.options;
|
|
2639
|
-
function handleResults(results) {
|
|
2640
|
-
// return first issue-free validation if it exists
|
|
2641
|
-
for (const result of results) {
|
|
2642
|
-
if (result.result.status === "valid") {
|
|
2643
|
-
return result.result;
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
for (const result of results) {
|
|
2647
|
-
if (result.result.status === "dirty") {
|
|
2648
|
-
// add issues from dirty option
|
|
2649
|
-
ctx.common.issues.push(...result.ctx.common.issues);
|
|
2650
|
-
return result.result;
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
// return invalid
|
|
2654
|
-
const unionErrors = results.map(result => new ZodError(result.ctx.common.issues));
|
|
2655
|
-
addIssueToContext(ctx, {
|
|
2656
|
-
code: ZodIssueCode.invalid_union,
|
|
2657
|
-
unionErrors
|
|
2658
|
-
});
|
|
2659
|
-
return INVALID;
|
|
2660
|
-
}
|
|
2661
|
-
if (ctx.common.async) {
|
|
2662
|
-
return Promise.all(options.map(async option => {
|
|
2663
|
-
const childCtx = {
|
|
2664
|
-
...ctx,
|
|
2665
|
-
common: {
|
|
2666
|
-
...ctx.common,
|
|
2667
|
-
issues: []
|
|
2668
|
-
},
|
|
2669
|
-
parent: null
|
|
2670
|
-
};
|
|
2671
|
-
return {
|
|
2672
|
-
result: await option._parseAsync({
|
|
2673
|
-
data: ctx.data,
|
|
2674
|
-
path: ctx.path,
|
|
2675
|
-
parent: childCtx
|
|
2676
|
-
}),
|
|
2677
|
-
ctx: childCtx
|
|
2678
|
-
};
|
|
2679
|
-
})).then(handleResults);
|
|
2680
|
-
} else {
|
|
2681
|
-
let dirty = undefined;
|
|
2682
|
-
const issues = [];
|
|
2683
|
-
for (const option of options) {
|
|
2684
|
-
const childCtx = {
|
|
2685
|
-
...ctx,
|
|
2686
|
-
common: {
|
|
2687
|
-
...ctx.common,
|
|
2688
|
-
issues: []
|
|
2689
|
-
},
|
|
2690
|
-
parent: null
|
|
2691
|
-
};
|
|
2692
|
-
const result = option._parseSync({
|
|
2693
|
-
data: ctx.data,
|
|
2694
|
-
path: ctx.path,
|
|
2695
|
-
parent: childCtx
|
|
2696
|
-
});
|
|
2697
|
-
if (result.status === "valid") {
|
|
2698
|
-
return result;
|
|
2699
|
-
} else if (result.status === "dirty" && !dirty) {
|
|
2700
|
-
dirty = {
|
|
2701
|
-
result,
|
|
2702
|
-
ctx: childCtx
|
|
2703
|
-
};
|
|
2704
|
-
}
|
|
2705
|
-
if (childCtx.common.issues.length) {
|
|
2706
|
-
issues.push(childCtx.common.issues);
|
|
2707
|
-
}
|
|
2708
|
-
}
|
|
2709
|
-
if (dirty) {
|
|
2710
|
-
ctx.common.issues.push(...dirty.ctx.common.issues);
|
|
2711
|
-
return dirty.result;
|
|
2712
|
-
}
|
|
2713
|
-
const unionErrors = issues.map(issues => new ZodError(issues));
|
|
2714
|
-
addIssueToContext(ctx, {
|
|
2715
|
-
code: ZodIssueCode.invalid_union,
|
|
2716
|
-
unionErrors
|
|
2717
|
-
});
|
|
2718
|
-
return INVALID;
|
|
2719
|
-
}
|
|
2720
|
-
}
|
|
2721
|
-
get options() {
|
|
2722
|
-
return this._def.options;
|
|
2723
|
-
}
|
|
2724
|
-
}
|
|
2725
|
-
ZodUnion.create = (types, params) => {
|
|
2726
|
-
return new ZodUnion({
|
|
2727
|
-
options: types,
|
|
2728
|
-
typeName: ZodFirstPartyTypeKind.ZodUnion,
|
|
2729
|
-
...processCreateParams(params)
|
|
2730
|
-
});
|
|
2731
|
-
};
|
|
2732
|
-
/////////////////////////////////////////////////////
|
|
2733
|
-
/////////////////////////////////////////////////////
|
|
2734
|
-
////////// //////////
|
|
2735
|
-
////////// ZodDiscriminatedUnion //////////
|
|
2736
|
-
////////// //////////
|
|
2737
|
-
/////////////////////////////////////////////////////
|
|
2738
|
-
/////////////////////////////////////////////////////
|
|
2739
|
-
const getDiscriminator = type => {
|
|
2740
|
-
if (type instanceof ZodLazy) {
|
|
2741
|
-
return getDiscriminator(type.schema);
|
|
2742
|
-
} else if (type instanceof ZodEffects) {
|
|
2743
|
-
return getDiscriminator(type.innerType());
|
|
2744
|
-
} else if (type instanceof ZodLiteral) {
|
|
2745
|
-
return [type.value];
|
|
2746
|
-
} else if (type instanceof ZodEnum) {
|
|
2747
|
-
return type.options;
|
|
2748
|
-
} else if (type instanceof ZodNativeEnum) {
|
|
2749
|
-
// eslint-disable-next-line ban/ban
|
|
2750
|
-
return Object.keys(type.enum);
|
|
2751
|
-
} else if (type instanceof ZodDefault) {
|
|
2752
|
-
return getDiscriminator(type._def.innerType);
|
|
2753
|
-
} else if (type instanceof ZodUndefined) {
|
|
2754
|
-
return [undefined];
|
|
2755
|
-
} else if (type instanceof ZodNull) {
|
|
2756
|
-
return [null];
|
|
2757
|
-
} else {
|
|
2758
|
-
return null;
|
|
2759
|
-
}
|
|
2760
|
-
};
|
|
2761
|
-
class ZodDiscriminatedUnion extends ZodType {
|
|
2762
|
-
_parse(input) {
|
|
2763
|
-
const {
|
|
2764
|
-
ctx
|
|
2765
|
-
} = this._processInputParams(input);
|
|
2766
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
2767
|
-
addIssueToContext(ctx, {
|
|
2768
|
-
code: ZodIssueCode.invalid_type,
|
|
2769
|
-
expected: ZodParsedType.object,
|
|
2770
|
-
received: ctx.parsedType
|
|
2771
|
-
});
|
|
2772
|
-
return INVALID;
|
|
2773
|
-
}
|
|
2774
|
-
const discriminator = this.discriminator;
|
|
2775
|
-
const discriminatorValue = ctx.data[discriminator];
|
|
2776
|
-
const option = this.optionsMap.get(discriminatorValue);
|
|
2777
|
-
if (!option) {
|
|
2778
|
-
addIssueToContext(ctx, {
|
|
2779
|
-
code: ZodIssueCode.invalid_union_discriminator,
|
|
2780
|
-
options: Array.from(this.optionsMap.keys()),
|
|
2781
|
-
path: [discriminator]
|
|
2782
|
-
});
|
|
2783
|
-
return INVALID;
|
|
2784
|
-
}
|
|
2785
|
-
if (ctx.common.async) {
|
|
2786
|
-
return option._parseAsync({
|
|
2787
|
-
data: ctx.data,
|
|
2788
|
-
path: ctx.path,
|
|
2789
|
-
parent: ctx
|
|
2790
|
-
});
|
|
2791
|
-
} else {
|
|
2792
|
-
return option._parseSync({
|
|
2793
|
-
data: ctx.data,
|
|
2794
|
-
path: ctx.path,
|
|
2795
|
-
parent: ctx
|
|
2796
|
-
});
|
|
2797
|
-
}
|
|
2798
|
-
}
|
|
2799
|
-
get discriminator() {
|
|
2800
|
-
return this._def.discriminator;
|
|
2801
|
-
}
|
|
2802
|
-
get options() {
|
|
2803
|
-
return this._def.options;
|
|
2804
|
-
}
|
|
2805
|
-
get optionsMap() {
|
|
2806
|
-
return this._def.optionsMap;
|
|
2807
|
-
}
|
|
2808
|
-
/**
|
|
2809
|
-
* The constructor of the discriminated union schema. Its behaviour is very similar to that of the normal z.union() constructor.
|
|
2810
|
-
* However, it only allows a union of objects, all of which need to share a discriminator property. This property must
|
|
2811
|
-
* have a different value for each object in the union.
|
|
2812
|
-
* @param discriminator the name of the discriminator property
|
|
2813
|
-
* @param types an array of object schemas
|
|
2814
|
-
* @param params
|
|
2815
|
-
*/
|
|
2816
|
-
static create(discriminator, options, params) {
|
|
2817
|
-
// Get all the valid discriminator values
|
|
2818
|
-
const optionsMap = new Map();
|
|
2819
|
-
// try {
|
|
2820
|
-
for (const type of options) {
|
|
2821
|
-
const discriminatorValues = getDiscriminator(type.shape[discriminator]);
|
|
2822
|
-
if (!discriminatorValues) {
|
|
2823
|
-
throw new Error(`A discriminator value for key \`${discriminator}\` could not be extracted from all schema options`);
|
|
2824
|
-
}
|
|
2825
|
-
for (const value of discriminatorValues) {
|
|
2826
|
-
if (optionsMap.has(value)) {
|
|
2827
|
-
throw new Error(`Discriminator property ${String(discriminator)} has duplicate value ${String(value)}`);
|
|
2828
|
-
}
|
|
2829
|
-
optionsMap.set(value, type);
|
|
2830
|
-
}
|
|
2831
|
-
}
|
|
2832
|
-
return new ZodDiscriminatedUnion({
|
|
2833
|
-
typeName: ZodFirstPartyTypeKind.ZodDiscriminatedUnion,
|
|
2834
|
-
discriminator,
|
|
2835
|
-
options,
|
|
2836
|
-
optionsMap,
|
|
2837
|
-
...processCreateParams(params)
|
|
2838
|
-
});
|
|
2839
|
-
}
|
|
2840
|
-
}
|
|
2841
|
-
function mergeValues(a, b) {
|
|
2842
|
-
const aType = getParsedType(a);
|
|
2843
|
-
const bType = getParsedType(b);
|
|
2844
|
-
if (a === b) {
|
|
2845
|
-
return {
|
|
2846
|
-
valid: true,
|
|
2847
|
-
data: a
|
|
2848
|
-
};
|
|
2849
|
-
} else if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2850
|
-
const bKeys = util$5.objectKeys(b);
|
|
2851
|
-
const sharedKeys = util$5.objectKeys(a).filter(key => bKeys.indexOf(key) !== -1);
|
|
2852
|
-
const newObj = {
|
|
2853
|
-
...a,
|
|
2854
|
-
...b
|
|
2855
|
-
};
|
|
2856
|
-
for (const key of sharedKeys) {
|
|
2857
|
-
const sharedValue = mergeValues(a[key], b[key]);
|
|
2858
|
-
if (!sharedValue.valid) {
|
|
2859
|
-
return {
|
|
2860
|
-
valid: false
|
|
2861
|
-
};
|
|
2862
|
-
}
|
|
2863
|
-
newObj[key] = sharedValue.data;
|
|
2864
|
-
}
|
|
2865
|
-
return {
|
|
2866
|
-
valid: true,
|
|
2867
|
-
data: newObj
|
|
2868
|
-
};
|
|
2869
|
-
} else if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2870
|
-
if (a.length !== b.length) {
|
|
2871
|
-
return {
|
|
2872
|
-
valid: false
|
|
2873
|
-
};
|
|
2874
|
-
}
|
|
2875
|
-
const newArray = [];
|
|
2876
|
-
for (let index = 0; index < a.length; index++) {
|
|
2877
|
-
const itemA = a[index];
|
|
2878
|
-
const itemB = b[index];
|
|
2879
|
-
const sharedValue = mergeValues(itemA, itemB);
|
|
2880
|
-
if (!sharedValue.valid) {
|
|
2881
|
-
return {
|
|
2882
|
-
valid: false
|
|
2883
|
-
};
|
|
2884
|
-
}
|
|
2885
|
-
newArray.push(sharedValue.data);
|
|
2886
|
-
}
|
|
2887
|
-
return {
|
|
2888
|
-
valid: true,
|
|
2889
|
-
data: newArray
|
|
2890
|
-
};
|
|
2891
|
-
} else if (aType === ZodParsedType.date && bType === ZodParsedType.date && +a === +b) {
|
|
2892
|
-
return {
|
|
2893
|
-
valid: true,
|
|
2894
|
-
data: a
|
|
2895
|
-
};
|
|
2896
|
-
} else {
|
|
2897
|
-
return {
|
|
2898
|
-
valid: false
|
|
2899
|
-
};
|
|
2900
|
-
}
|
|
2901
|
-
}
|
|
2902
|
-
class ZodIntersection extends ZodType {
|
|
2903
|
-
_parse(input) {
|
|
2904
|
-
const {
|
|
2905
|
-
status,
|
|
2906
|
-
ctx
|
|
2907
|
-
} = this._processInputParams(input);
|
|
2908
|
-
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2909
|
-
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2910
|
-
return INVALID;
|
|
2911
|
-
}
|
|
2912
|
-
const merged = mergeValues(parsedLeft.value, parsedRight.value);
|
|
2913
|
-
if (!merged.valid) {
|
|
2914
|
-
addIssueToContext(ctx, {
|
|
2915
|
-
code: ZodIssueCode.invalid_intersection_types
|
|
2916
|
-
});
|
|
2917
|
-
return INVALID;
|
|
2918
|
-
}
|
|
2919
|
-
if (isDirty(parsedLeft) || isDirty(parsedRight)) {
|
|
2920
|
-
status.dirty();
|
|
2921
|
-
}
|
|
2922
|
-
return {
|
|
2923
|
-
status: status.value,
|
|
2924
|
-
value: merged.data
|
|
2925
|
-
};
|
|
2926
|
-
};
|
|
2927
|
-
if (ctx.common.async) {
|
|
2928
|
-
return Promise.all([this._def.left._parseAsync({
|
|
2929
|
-
data: ctx.data,
|
|
2930
|
-
path: ctx.path,
|
|
2931
|
-
parent: ctx
|
|
2932
|
-
}), this._def.right._parseAsync({
|
|
2933
|
-
data: ctx.data,
|
|
2934
|
-
path: ctx.path,
|
|
2935
|
-
parent: ctx
|
|
2936
|
-
})]).then(([left, right]) => handleParsed(left, right));
|
|
2937
|
-
} else {
|
|
2938
|
-
return handleParsed(this._def.left._parseSync({
|
|
2939
|
-
data: ctx.data,
|
|
2940
|
-
path: ctx.path,
|
|
2941
|
-
parent: ctx
|
|
2942
|
-
}), this._def.right._parseSync({
|
|
2943
|
-
data: ctx.data,
|
|
2944
|
-
path: ctx.path,
|
|
2945
|
-
parent: ctx
|
|
2946
|
-
}));
|
|
2947
|
-
}
|
|
2948
|
-
}
|
|
2949
|
-
}
|
|
2950
|
-
ZodIntersection.create = (left, right, params) => {
|
|
2951
|
-
return new ZodIntersection({
|
|
2952
|
-
left: left,
|
|
2953
|
-
right: right,
|
|
2954
|
-
typeName: ZodFirstPartyTypeKind.ZodIntersection,
|
|
2955
|
-
...processCreateParams(params)
|
|
2956
|
-
});
|
|
2957
|
-
};
|
|
2958
|
-
class ZodTuple extends ZodType {
|
|
2959
|
-
_parse(input) {
|
|
2960
|
-
const {
|
|
2961
|
-
status,
|
|
2962
|
-
ctx
|
|
2963
|
-
} = this._processInputParams(input);
|
|
2964
|
-
if (ctx.parsedType !== ZodParsedType.array) {
|
|
2965
|
-
addIssueToContext(ctx, {
|
|
2966
|
-
code: ZodIssueCode.invalid_type,
|
|
2967
|
-
expected: ZodParsedType.array,
|
|
2968
|
-
received: ctx.parsedType
|
|
2969
|
-
});
|
|
2970
|
-
return INVALID;
|
|
2971
|
-
}
|
|
2972
|
-
if (ctx.data.length < this._def.items.length) {
|
|
2973
|
-
addIssueToContext(ctx, {
|
|
2974
|
-
code: ZodIssueCode.too_small,
|
|
2975
|
-
minimum: this._def.items.length,
|
|
2976
|
-
inclusive: true,
|
|
2977
|
-
exact: false,
|
|
2978
|
-
type: "array"
|
|
2979
|
-
});
|
|
2980
|
-
return INVALID;
|
|
2981
|
-
}
|
|
2982
|
-
const rest = this._def.rest;
|
|
2983
|
-
if (!rest && ctx.data.length > this._def.items.length) {
|
|
2984
|
-
addIssueToContext(ctx, {
|
|
2985
|
-
code: ZodIssueCode.too_big,
|
|
2986
|
-
maximum: this._def.items.length,
|
|
2987
|
-
inclusive: true,
|
|
2988
|
-
exact: false,
|
|
2989
|
-
type: "array"
|
|
2990
|
-
});
|
|
2991
|
-
status.dirty();
|
|
2992
|
-
}
|
|
2993
|
-
const items = [...ctx.data].map((item, itemIndex) => {
|
|
2994
|
-
const schema = this._def.items[itemIndex] || this._def.rest;
|
|
2995
|
-
if (!schema) return null;
|
|
2996
|
-
return schema._parse(new ParseInputLazyPath(ctx, item, ctx.path, itemIndex));
|
|
2997
|
-
}).filter(x => !!x); // filter nulls
|
|
2998
|
-
if (ctx.common.async) {
|
|
2999
|
-
return Promise.all(items).then(results => {
|
|
3000
|
-
return ParseStatus.mergeArray(status, results);
|
|
3001
|
-
});
|
|
3002
|
-
} else {
|
|
3003
|
-
return ParseStatus.mergeArray(status, items);
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
get items() {
|
|
3007
|
-
return this._def.items;
|
|
3008
|
-
}
|
|
3009
|
-
rest(rest) {
|
|
3010
|
-
return new ZodTuple({
|
|
3011
|
-
...this._def,
|
|
3012
|
-
rest
|
|
3013
|
-
});
|
|
3014
|
-
}
|
|
3015
|
-
}
|
|
3016
|
-
ZodTuple.create = (schemas, params) => {
|
|
3017
|
-
if (!Array.isArray(schemas)) {
|
|
3018
|
-
throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
|
|
3019
|
-
}
|
|
3020
|
-
return new ZodTuple({
|
|
3021
|
-
items: schemas,
|
|
3022
|
-
typeName: ZodFirstPartyTypeKind.ZodTuple,
|
|
3023
|
-
rest: null,
|
|
3024
|
-
...processCreateParams(params)
|
|
3025
|
-
});
|
|
3026
|
-
};
|
|
3027
|
-
class ZodRecord extends ZodType {
|
|
3028
|
-
get keySchema() {
|
|
3029
|
-
return this._def.keyType;
|
|
3030
|
-
}
|
|
3031
|
-
get valueSchema() {
|
|
3032
|
-
return this._def.valueType;
|
|
3033
|
-
}
|
|
3034
|
-
_parse(input) {
|
|
3035
|
-
const {
|
|
3036
|
-
status,
|
|
3037
|
-
ctx
|
|
3038
|
-
} = this._processInputParams(input);
|
|
3039
|
-
if (ctx.parsedType !== ZodParsedType.object) {
|
|
3040
|
-
addIssueToContext(ctx, {
|
|
3041
|
-
code: ZodIssueCode.invalid_type,
|
|
3042
|
-
expected: ZodParsedType.object,
|
|
3043
|
-
received: ctx.parsedType
|
|
3044
|
-
});
|
|
3045
|
-
return INVALID;
|
|
3046
|
-
}
|
|
3047
|
-
const pairs = [];
|
|
3048
|
-
const keyType = this._def.keyType;
|
|
3049
|
-
const valueType = this._def.valueType;
|
|
3050
|
-
for (const key in ctx.data) {
|
|
3051
|
-
pairs.push({
|
|
3052
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, key)),
|
|
3053
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, ctx.data[key], ctx.path, key))
|
|
3054
|
-
});
|
|
3055
|
-
}
|
|
3056
|
-
if (ctx.common.async) {
|
|
3057
|
-
return ParseStatus.mergeObjectAsync(status, pairs);
|
|
3058
|
-
} else {
|
|
3059
|
-
return ParseStatus.mergeObjectSync(status, pairs);
|
|
3060
|
-
}
|
|
3061
|
-
}
|
|
3062
|
-
get element() {
|
|
3063
|
-
return this._def.valueType;
|
|
3064
|
-
}
|
|
3065
|
-
static create(first, second, third) {
|
|
3066
|
-
if (second instanceof ZodType) {
|
|
3067
|
-
return new ZodRecord({
|
|
3068
|
-
keyType: first,
|
|
3069
|
-
valueType: second,
|
|
3070
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3071
|
-
...processCreateParams(third)
|
|
3072
|
-
});
|
|
3073
|
-
}
|
|
3074
|
-
return new ZodRecord({
|
|
3075
|
-
keyType: ZodString.create(),
|
|
3076
|
-
valueType: first,
|
|
3077
|
-
typeName: ZodFirstPartyTypeKind.ZodRecord,
|
|
3078
|
-
...processCreateParams(second)
|
|
3079
|
-
});
|
|
3080
|
-
}
|
|
3081
|
-
}
|
|
3082
|
-
class ZodMap extends ZodType {
|
|
3083
|
-
get keySchema() {
|
|
3084
|
-
return this._def.keyType;
|
|
3085
|
-
}
|
|
3086
|
-
get valueSchema() {
|
|
3087
|
-
return this._def.valueType;
|
|
3088
|
-
}
|
|
3089
|
-
_parse(input) {
|
|
3090
|
-
const {
|
|
3091
|
-
status,
|
|
3092
|
-
ctx
|
|
3093
|
-
} = this._processInputParams(input);
|
|
3094
|
-
if (ctx.parsedType !== ZodParsedType.map) {
|
|
3095
|
-
addIssueToContext(ctx, {
|
|
3096
|
-
code: ZodIssueCode.invalid_type,
|
|
3097
|
-
expected: ZodParsedType.map,
|
|
3098
|
-
received: ctx.parsedType
|
|
3099
|
-
});
|
|
3100
|
-
return INVALID;
|
|
3101
|
-
}
|
|
3102
|
-
const keyType = this._def.keyType;
|
|
3103
|
-
const valueType = this._def.valueType;
|
|
3104
|
-
const pairs = [...ctx.data.entries()].map(([key, value], index) => {
|
|
3105
|
-
return {
|
|
3106
|
-
key: keyType._parse(new ParseInputLazyPath(ctx, key, ctx.path, [index, "key"])),
|
|
3107
|
-
value: valueType._parse(new ParseInputLazyPath(ctx, value, ctx.path, [index, "value"]))
|
|
3108
|
-
};
|
|
3109
|
-
});
|
|
3110
|
-
if (ctx.common.async) {
|
|
3111
|
-
const finalMap = new Map();
|
|
3112
|
-
return Promise.resolve().then(async () => {
|
|
3113
|
-
for (const pair of pairs) {
|
|
3114
|
-
const key = await pair.key;
|
|
3115
|
-
const value = await pair.value;
|
|
3116
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3117
|
-
return INVALID;
|
|
3118
|
-
}
|
|
3119
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3120
|
-
status.dirty();
|
|
3121
|
-
}
|
|
3122
|
-
finalMap.set(key.value, value.value);
|
|
3123
|
-
}
|
|
3124
|
-
return {
|
|
3125
|
-
status: status.value,
|
|
3126
|
-
value: finalMap
|
|
3127
|
-
};
|
|
3128
|
-
});
|
|
3129
|
-
} else {
|
|
3130
|
-
const finalMap = new Map();
|
|
3131
|
-
for (const pair of pairs) {
|
|
3132
|
-
const key = pair.key;
|
|
3133
|
-
const value = pair.value;
|
|
3134
|
-
if (key.status === "aborted" || value.status === "aborted") {
|
|
3135
|
-
return INVALID;
|
|
3136
|
-
}
|
|
3137
|
-
if (key.status === "dirty" || value.status === "dirty") {
|
|
3138
|
-
status.dirty();
|
|
3139
|
-
}
|
|
3140
|
-
finalMap.set(key.value, value.value);
|
|
3141
|
-
}
|
|
3142
|
-
return {
|
|
3143
|
-
status: status.value,
|
|
3144
|
-
value: finalMap
|
|
3145
|
-
};
|
|
3146
|
-
}
|
|
3147
|
-
}
|
|
3148
|
-
}
|
|
3149
|
-
ZodMap.create = (keyType, valueType, params) => {
|
|
3150
|
-
return new ZodMap({
|
|
3151
|
-
valueType,
|
|
3152
|
-
keyType,
|
|
3153
|
-
typeName: ZodFirstPartyTypeKind.ZodMap,
|
|
3154
|
-
...processCreateParams(params)
|
|
3155
|
-
});
|
|
3156
|
-
};
|
|
3157
|
-
class ZodSet extends ZodType {
|
|
3158
|
-
_parse(input) {
|
|
3159
|
-
const {
|
|
3160
|
-
status,
|
|
3161
|
-
ctx
|
|
3162
|
-
} = this._processInputParams(input);
|
|
3163
|
-
if (ctx.parsedType !== ZodParsedType.set) {
|
|
3164
|
-
addIssueToContext(ctx, {
|
|
3165
|
-
code: ZodIssueCode.invalid_type,
|
|
3166
|
-
expected: ZodParsedType.set,
|
|
3167
|
-
received: ctx.parsedType
|
|
3168
|
-
});
|
|
3169
|
-
return INVALID;
|
|
3170
|
-
}
|
|
3171
|
-
const def = this._def;
|
|
3172
|
-
if (def.minSize !== null) {
|
|
3173
|
-
if (ctx.data.size < def.minSize.value) {
|
|
3174
|
-
addIssueToContext(ctx, {
|
|
3175
|
-
code: ZodIssueCode.too_small,
|
|
3176
|
-
minimum: def.minSize.value,
|
|
3177
|
-
type: "set",
|
|
3178
|
-
inclusive: true,
|
|
3179
|
-
exact: false,
|
|
3180
|
-
message: def.minSize.message
|
|
3181
|
-
});
|
|
3182
|
-
status.dirty();
|
|
3183
|
-
}
|
|
3184
|
-
}
|
|
3185
|
-
if (def.maxSize !== null) {
|
|
3186
|
-
if (ctx.data.size > def.maxSize.value) {
|
|
3187
|
-
addIssueToContext(ctx, {
|
|
3188
|
-
code: ZodIssueCode.too_big,
|
|
3189
|
-
maximum: def.maxSize.value,
|
|
3190
|
-
type: "set",
|
|
3191
|
-
inclusive: true,
|
|
3192
|
-
exact: false,
|
|
3193
|
-
message: def.maxSize.message
|
|
3194
|
-
});
|
|
3195
|
-
status.dirty();
|
|
3196
|
-
}
|
|
3197
|
-
}
|
|
3198
|
-
const valueType = this._def.valueType;
|
|
3199
|
-
function finalizeSet(elements) {
|
|
3200
|
-
const parsedSet = new Set();
|
|
3201
|
-
for (const element of elements) {
|
|
3202
|
-
if (element.status === "aborted") return INVALID;
|
|
3203
|
-
if (element.status === "dirty") status.dirty();
|
|
3204
|
-
parsedSet.add(element.value);
|
|
3205
|
-
}
|
|
3206
|
-
return {
|
|
3207
|
-
status: status.value,
|
|
3208
|
-
value: parsedSet
|
|
3209
|
-
};
|
|
3210
|
-
}
|
|
3211
|
-
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3212
|
-
if (ctx.common.async) {
|
|
3213
|
-
return Promise.all(elements).then(elements => finalizeSet(elements));
|
|
3214
|
-
} else {
|
|
3215
|
-
return finalizeSet(elements);
|
|
3216
|
-
}
|
|
3217
|
-
}
|
|
3218
|
-
min(minSize, message) {
|
|
3219
|
-
return new ZodSet({
|
|
3220
|
-
...this._def,
|
|
3221
|
-
minSize: {
|
|
3222
|
-
value: minSize,
|
|
3223
|
-
message: errorUtil.toString(message)
|
|
3224
|
-
}
|
|
3225
|
-
});
|
|
3226
|
-
}
|
|
3227
|
-
max(maxSize, message) {
|
|
3228
|
-
return new ZodSet({
|
|
3229
|
-
...this._def,
|
|
3230
|
-
maxSize: {
|
|
3231
|
-
value: maxSize,
|
|
3232
|
-
message: errorUtil.toString(message)
|
|
3233
|
-
}
|
|
3234
|
-
});
|
|
3235
|
-
}
|
|
3236
|
-
size(size, message) {
|
|
3237
|
-
return this.min(size, message).max(size, message);
|
|
3238
|
-
}
|
|
3239
|
-
nonempty(message) {
|
|
3240
|
-
return this.min(1, message);
|
|
3241
|
-
}
|
|
3242
|
-
}
|
|
3243
|
-
ZodSet.create = (valueType, params) => {
|
|
3244
|
-
return new ZodSet({
|
|
3245
|
-
valueType,
|
|
3246
|
-
minSize: null,
|
|
3247
|
-
maxSize: null,
|
|
3248
|
-
typeName: ZodFirstPartyTypeKind.ZodSet,
|
|
3249
|
-
...processCreateParams(params)
|
|
3250
|
-
});
|
|
3251
|
-
};
|
|
3252
|
-
class ZodFunction extends ZodType {
|
|
3253
|
-
constructor() {
|
|
3254
|
-
super(...arguments);
|
|
3255
|
-
this.validate = this.implement;
|
|
3256
|
-
}
|
|
3257
|
-
_parse(input) {
|
|
3258
|
-
const {
|
|
3259
|
-
ctx
|
|
3260
|
-
} = this._processInputParams(input);
|
|
3261
|
-
if (ctx.parsedType !== ZodParsedType.function) {
|
|
3262
|
-
addIssueToContext(ctx, {
|
|
3263
|
-
code: ZodIssueCode.invalid_type,
|
|
3264
|
-
expected: ZodParsedType.function,
|
|
3265
|
-
received: ctx.parsedType
|
|
3266
|
-
});
|
|
3267
|
-
return INVALID;
|
|
3268
|
-
}
|
|
3269
|
-
function makeArgsIssue(args, error) {
|
|
3270
|
-
return makeIssue({
|
|
3271
|
-
data: args,
|
|
3272
|
-
path: ctx.path,
|
|
3273
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap].filter(x => !!x),
|
|
3274
|
-
issueData: {
|
|
3275
|
-
code: ZodIssueCode.invalid_arguments,
|
|
3276
|
-
argumentsError: error
|
|
3277
|
-
}
|
|
3278
|
-
});
|
|
3279
|
-
}
|
|
3280
|
-
function makeReturnsIssue(returns, error) {
|
|
3281
|
-
return makeIssue({
|
|
3282
|
-
data: returns,
|
|
3283
|
-
path: ctx.path,
|
|
3284
|
-
errorMaps: [ctx.common.contextualErrorMap, ctx.schemaErrorMap, getErrorMap(), errorMap].filter(x => !!x),
|
|
3285
|
-
issueData: {
|
|
3286
|
-
code: ZodIssueCode.invalid_return_type,
|
|
3287
|
-
returnTypeError: error
|
|
3288
|
-
}
|
|
3289
|
-
});
|
|
3290
|
-
}
|
|
3291
|
-
const params = {
|
|
3292
|
-
errorMap: ctx.common.contextualErrorMap
|
|
3293
|
-
};
|
|
3294
|
-
const fn = ctx.data;
|
|
3295
|
-
if (this._def.returns instanceof ZodPromise) {
|
|
3296
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3297
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3298
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3299
|
-
const me = this;
|
|
3300
|
-
return OK(async function (...args) {
|
|
3301
|
-
const error = new ZodError([]);
|
|
3302
|
-
const parsedArgs = await me._def.args.parseAsync(args, params).catch(e => {
|
|
3303
|
-
error.addIssue(makeArgsIssue(args, e));
|
|
3304
|
-
throw error;
|
|
3305
|
-
});
|
|
3306
|
-
const result = await Reflect.apply(fn, this, parsedArgs);
|
|
3307
|
-
const parsedReturns = await me._def.returns._def.type.parseAsync(result, params).catch(e => {
|
|
3308
|
-
error.addIssue(makeReturnsIssue(result, e));
|
|
3309
|
-
throw error;
|
|
3310
|
-
});
|
|
3311
|
-
return parsedReturns;
|
|
3312
|
-
});
|
|
3313
|
-
} else {
|
|
3314
|
-
// Would love a way to avoid disabling this rule, but we need
|
|
3315
|
-
// an alias (using an arrow function was what caused 2651).
|
|
3316
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
3317
|
-
const me = this;
|
|
3318
|
-
return OK(function (...args) {
|
|
3319
|
-
const parsedArgs = me._def.args.safeParse(args, params);
|
|
3320
|
-
if (!parsedArgs.success) {
|
|
3321
|
-
throw new ZodError([makeArgsIssue(args, parsedArgs.error)]);
|
|
3322
|
-
}
|
|
3323
|
-
const result = Reflect.apply(fn, this, parsedArgs.data);
|
|
3324
|
-
const parsedReturns = me._def.returns.safeParse(result, params);
|
|
3325
|
-
if (!parsedReturns.success) {
|
|
3326
|
-
throw new ZodError([makeReturnsIssue(result, parsedReturns.error)]);
|
|
3327
|
-
}
|
|
3328
|
-
return parsedReturns.data;
|
|
3329
|
-
});
|
|
3330
|
-
}
|
|
3331
|
-
}
|
|
3332
|
-
parameters() {
|
|
3333
|
-
return this._def.args;
|
|
3334
|
-
}
|
|
3335
|
-
returnType() {
|
|
3336
|
-
return this._def.returns;
|
|
3337
|
-
}
|
|
3338
|
-
args(...items) {
|
|
3339
|
-
return new ZodFunction({
|
|
3340
|
-
...this._def,
|
|
3341
|
-
args: ZodTuple.create(items).rest(ZodUnknown.create())
|
|
3342
|
-
});
|
|
3343
|
-
}
|
|
3344
|
-
returns(returnType) {
|
|
3345
|
-
return new ZodFunction({
|
|
3346
|
-
...this._def,
|
|
3347
|
-
returns: returnType
|
|
3348
|
-
});
|
|
3349
|
-
}
|
|
3350
|
-
implement(func) {
|
|
3351
|
-
const validatedFunc = this.parse(func);
|
|
3352
|
-
return validatedFunc;
|
|
3353
|
-
}
|
|
3354
|
-
strictImplement(func) {
|
|
3355
|
-
const validatedFunc = this.parse(func);
|
|
3356
|
-
return validatedFunc;
|
|
3357
|
-
}
|
|
3358
|
-
static create(args, returns, params) {
|
|
3359
|
-
return new ZodFunction({
|
|
3360
|
-
args: args ? args : ZodTuple.create([]).rest(ZodUnknown.create()),
|
|
3361
|
-
returns: returns || ZodUnknown.create(),
|
|
3362
|
-
typeName: ZodFirstPartyTypeKind.ZodFunction,
|
|
3363
|
-
...processCreateParams(params)
|
|
3364
|
-
});
|
|
3365
|
-
}
|
|
3366
|
-
}
|
|
3367
|
-
class ZodLazy extends ZodType {
|
|
3368
|
-
get schema() {
|
|
3369
|
-
return this._def.getter();
|
|
3370
|
-
}
|
|
3371
|
-
_parse(input) {
|
|
3372
|
-
const {
|
|
3373
|
-
ctx
|
|
3374
|
-
} = this._processInputParams(input);
|
|
3375
|
-
const lazySchema = this._def.getter();
|
|
3376
|
-
return lazySchema._parse({
|
|
3377
|
-
data: ctx.data,
|
|
3378
|
-
path: ctx.path,
|
|
3379
|
-
parent: ctx
|
|
3380
|
-
});
|
|
3381
|
-
}
|
|
3382
|
-
}
|
|
3383
|
-
ZodLazy.create = (getter, params) => {
|
|
3384
|
-
return new ZodLazy({
|
|
3385
|
-
getter: getter,
|
|
3386
|
-
typeName: ZodFirstPartyTypeKind.ZodLazy,
|
|
3387
|
-
...processCreateParams(params)
|
|
3388
|
-
});
|
|
3389
|
-
};
|
|
3390
|
-
class ZodLiteral extends ZodType {
|
|
3391
|
-
_parse(input) {
|
|
3392
|
-
if (input.data !== this._def.value) {
|
|
3393
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3394
|
-
addIssueToContext(ctx, {
|
|
3395
|
-
received: ctx.data,
|
|
3396
|
-
code: ZodIssueCode.invalid_literal,
|
|
3397
|
-
expected: this._def.value
|
|
3398
|
-
});
|
|
3399
|
-
return INVALID;
|
|
3400
|
-
}
|
|
3401
|
-
return {
|
|
3402
|
-
status: "valid",
|
|
3403
|
-
value: input.data
|
|
3404
|
-
};
|
|
3405
|
-
}
|
|
3406
|
-
get value() {
|
|
3407
|
-
return this._def.value;
|
|
3408
|
-
}
|
|
3409
|
-
}
|
|
3410
|
-
ZodLiteral.create = (value, params) => {
|
|
3411
|
-
return new ZodLiteral({
|
|
3412
|
-
value: value,
|
|
3413
|
-
typeName: ZodFirstPartyTypeKind.ZodLiteral,
|
|
3414
|
-
...processCreateParams(params)
|
|
3415
|
-
});
|
|
3416
|
-
};
|
|
3417
|
-
function createZodEnum(values, params) {
|
|
3418
|
-
return new ZodEnum({
|
|
3419
|
-
values,
|
|
3420
|
-
typeName: ZodFirstPartyTypeKind.ZodEnum,
|
|
3421
|
-
...processCreateParams(params)
|
|
3422
|
-
});
|
|
3423
|
-
}
|
|
3424
|
-
class ZodEnum extends ZodType {
|
|
3425
|
-
_parse(input) {
|
|
3426
|
-
if (typeof input.data !== "string") {
|
|
3427
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3428
|
-
const expectedValues = this._def.values;
|
|
3429
|
-
addIssueToContext(ctx, {
|
|
3430
|
-
expected: util$5.joinValues(expectedValues),
|
|
3431
|
-
received: ctx.parsedType,
|
|
3432
|
-
code: ZodIssueCode.invalid_type
|
|
3433
|
-
});
|
|
3434
|
-
return INVALID;
|
|
3435
|
-
}
|
|
3436
|
-
if (this._def.values.indexOf(input.data) === -1) {
|
|
3437
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3438
|
-
const expectedValues = this._def.values;
|
|
3439
|
-
addIssueToContext(ctx, {
|
|
3440
|
-
received: ctx.data,
|
|
3441
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
3442
|
-
options: expectedValues
|
|
3443
|
-
});
|
|
3444
|
-
return INVALID;
|
|
3445
|
-
}
|
|
3446
|
-
return OK(input.data);
|
|
3447
|
-
}
|
|
3448
|
-
get options() {
|
|
3449
|
-
return this._def.values;
|
|
3450
|
-
}
|
|
3451
|
-
get enum() {
|
|
3452
|
-
const enumValues = {};
|
|
3453
|
-
for (const val of this._def.values) {
|
|
3454
|
-
enumValues[val] = val;
|
|
3455
|
-
}
|
|
3456
|
-
return enumValues;
|
|
3457
|
-
}
|
|
3458
|
-
get Values() {
|
|
3459
|
-
const enumValues = {};
|
|
3460
|
-
for (const val of this._def.values) {
|
|
3461
|
-
enumValues[val] = val;
|
|
3462
|
-
}
|
|
3463
|
-
return enumValues;
|
|
3464
|
-
}
|
|
3465
|
-
get Enum() {
|
|
3466
|
-
const enumValues = {};
|
|
3467
|
-
for (const val of this._def.values) {
|
|
3468
|
-
enumValues[val] = val;
|
|
3469
|
-
}
|
|
3470
|
-
return enumValues;
|
|
3471
|
-
}
|
|
3472
|
-
extract(values) {
|
|
3473
|
-
return ZodEnum.create(values);
|
|
3474
|
-
}
|
|
3475
|
-
exclude(values) {
|
|
3476
|
-
return ZodEnum.create(this.options.filter(opt => !values.includes(opt)));
|
|
3477
|
-
}
|
|
3478
|
-
}
|
|
3479
|
-
ZodEnum.create = createZodEnum;
|
|
3480
|
-
class ZodNativeEnum extends ZodType {
|
|
3481
|
-
_parse(input) {
|
|
3482
|
-
const nativeEnumValues = util$5.getValidEnumValues(this._def.values);
|
|
3483
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3484
|
-
if (ctx.parsedType !== ZodParsedType.string && ctx.parsedType !== ZodParsedType.number) {
|
|
3485
|
-
const expectedValues = util$5.objectValues(nativeEnumValues);
|
|
3486
|
-
addIssueToContext(ctx, {
|
|
3487
|
-
expected: util$5.joinValues(expectedValues),
|
|
3488
|
-
received: ctx.parsedType,
|
|
3489
|
-
code: ZodIssueCode.invalid_type
|
|
3490
|
-
});
|
|
3491
|
-
return INVALID;
|
|
3492
|
-
}
|
|
3493
|
-
if (nativeEnumValues.indexOf(input.data) === -1) {
|
|
3494
|
-
const expectedValues = util$5.objectValues(nativeEnumValues);
|
|
3495
|
-
addIssueToContext(ctx, {
|
|
3496
|
-
received: ctx.data,
|
|
3497
|
-
code: ZodIssueCode.invalid_enum_value,
|
|
3498
|
-
options: expectedValues
|
|
3499
|
-
});
|
|
3500
|
-
return INVALID;
|
|
3501
|
-
}
|
|
3502
|
-
return OK(input.data);
|
|
3503
|
-
}
|
|
3504
|
-
get enum() {
|
|
3505
|
-
return this._def.values;
|
|
3506
|
-
}
|
|
3507
|
-
}
|
|
3508
|
-
ZodNativeEnum.create = (values, params) => {
|
|
3509
|
-
return new ZodNativeEnum({
|
|
3510
|
-
values: values,
|
|
3511
|
-
typeName: ZodFirstPartyTypeKind.ZodNativeEnum,
|
|
3512
|
-
...processCreateParams(params)
|
|
3513
|
-
});
|
|
3514
|
-
};
|
|
3515
|
-
class ZodPromise extends ZodType {
|
|
3516
|
-
unwrap() {
|
|
3517
|
-
return this._def.type;
|
|
3518
|
-
}
|
|
3519
|
-
_parse(input) {
|
|
3520
|
-
const {
|
|
3521
|
-
ctx
|
|
3522
|
-
} = this._processInputParams(input);
|
|
3523
|
-
if (ctx.parsedType !== ZodParsedType.promise && ctx.common.async === false) {
|
|
3524
|
-
addIssueToContext(ctx, {
|
|
3525
|
-
code: ZodIssueCode.invalid_type,
|
|
3526
|
-
expected: ZodParsedType.promise,
|
|
3527
|
-
received: ctx.parsedType
|
|
3528
|
-
});
|
|
3529
|
-
return INVALID;
|
|
3530
|
-
}
|
|
3531
|
-
const promisified = ctx.parsedType === ZodParsedType.promise ? ctx.data : Promise.resolve(ctx.data);
|
|
3532
|
-
return OK(promisified.then(data => {
|
|
3533
|
-
return this._def.type.parseAsync(data, {
|
|
3534
|
-
path: ctx.path,
|
|
3535
|
-
errorMap: ctx.common.contextualErrorMap
|
|
3536
|
-
});
|
|
3537
|
-
}));
|
|
3538
|
-
}
|
|
3539
|
-
}
|
|
3540
|
-
ZodPromise.create = (schema, params) => {
|
|
3541
|
-
return new ZodPromise({
|
|
3542
|
-
type: schema,
|
|
3543
|
-
typeName: ZodFirstPartyTypeKind.ZodPromise,
|
|
3544
|
-
...processCreateParams(params)
|
|
3545
|
-
});
|
|
3546
|
-
};
|
|
3547
|
-
class ZodEffects extends ZodType {
|
|
3548
|
-
innerType() {
|
|
3549
|
-
return this._def.schema;
|
|
3550
|
-
}
|
|
3551
|
-
sourceType() {
|
|
3552
|
-
return this._def.schema._def.typeName === ZodFirstPartyTypeKind.ZodEffects ? this._def.schema.sourceType() : this._def.schema;
|
|
3553
|
-
}
|
|
3554
|
-
_parse(input) {
|
|
3555
|
-
const {
|
|
3556
|
-
status,
|
|
3557
|
-
ctx
|
|
3558
|
-
} = this._processInputParams(input);
|
|
3559
|
-
const effect = this._def.effect || null;
|
|
3560
|
-
const checkCtx = {
|
|
3561
|
-
addIssue: arg => {
|
|
3562
|
-
addIssueToContext(ctx, arg);
|
|
3563
|
-
if (arg.fatal) {
|
|
3564
|
-
status.abort();
|
|
3565
|
-
} else {
|
|
3566
|
-
status.dirty();
|
|
3567
|
-
}
|
|
3568
|
-
},
|
|
3569
|
-
get path() {
|
|
3570
|
-
return ctx.path;
|
|
3571
|
-
}
|
|
3572
|
-
};
|
|
3573
|
-
checkCtx.addIssue = checkCtx.addIssue.bind(checkCtx);
|
|
3574
|
-
if (effect.type === "preprocess") {
|
|
3575
|
-
const processed = effect.transform(ctx.data, checkCtx);
|
|
3576
|
-
if (ctx.common.issues.length) {
|
|
3577
|
-
return {
|
|
3578
|
-
status: "dirty",
|
|
3579
|
-
value: ctx.data
|
|
3580
|
-
};
|
|
3581
|
-
}
|
|
3582
|
-
if (ctx.common.async) {
|
|
3583
|
-
return Promise.resolve(processed).then(processed => {
|
|
3584
|
-
return this._def.schema._parseAsync({
|
|
3585
|
-
data: processed,
|
|
3586
|
-
path: ctx.path,
|
|
3587
|
-
parent: ctx
|
|
3588
|
-
});
|
|
3589
|
-
});
|
|
3590
|
-
} else {
|
|
3591
|
-
return this._def.schema._parseSync({
|
|
3592
|
-
data: processed,
|
|
3593
|
-
path: ctx.path,
|
|
3594
|
-
parent: ctx
|
|
3595
|
-
});
|
|
3596
|
-
}
|
|
3597
|
-
}
|
|
3598
|
-
if (effect.type === "refinement") {
|
|
3599
|
-
const executeRefinement = (acc
|
|
3600
|
-
// effect: RefinementEffect<any>
|
|
3601
|
-
) => {
|
|
3602
|
-
const result = effect.refinement(acc, checkCtx);
|
|
3603
|
-
if (ctx.common.async) {
|
|
3604
|
-
return Promise.resolve(result);
|
|
3605
|
-
}
|
|
3606
|
-
if (result instanceof Promise) {
|
|
3607
|
-
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3608
|
-
}
|
|
3609
|
-
return acc;
|
|
3610
|
-
};
|
|
3611
|
-
if (ctx.common.async === false) {
|
|
3612
|
-
const inner = this._def.schema._parseSync({
|
|
3613
|
-
data: ctx.data,
|
|
3614
|
-
path: ctx.path,
|
|
3615
|
-
parent: ctx
|
|
3616
|
-
});
|
|
3617
|
-
if (inner.status === "aborted") return INVALID;
|
|
3618
|
-
if (inner.status === "dirty") status.dirty();
|
|
3619
|
-
// return value is ignored
|
|
3620
|
-
executeRefinement(inner.value);
|
|
3621
|
-
return {
|
|
3622
|
-
status: status.value,
|
|
3623
|
-
value: inner.value
|
|
3624
|
-
};
|
|
3625
|
-
} else {
|
|
3626
|
-
return this._def.schema._parseAsync({
|
|
3627
|
-
data: ctx.data,
|
|
3628
|
-
path: ctx.path,
|
|
3629
|
-
parent: ctx
|
|
3630
|
-
}).then(inner => {
|
|
3631
|
-
if (inner.status === "aborted") return INVALID;
|
|
3632
|
-
if (inner.status === "dirty") status.dirty();
|
|
3633
|
-
return executeRefinement(inner.value).then(() => {
|
|
3634
|
-
return {
|
|
3635
|
-
status: status.value,
|
|
3636
|
-
value: inner.value
|
|
3637
|
-
};
|
|
3638
|
-
});
|
|
3639
|
-
});
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
if (effect.type === "transform") {
|
|
3643
|
-
if (ctx.common.async === false) {
|
|
3644
|
-
const base = this._def.schema._parseSync({
|
|
3645
|
-
data: ctx.data,
|
|
3646
|
-
path: ctx.path,
|
|
3647
|
-
parent: ctx
|
|
3648
|
-
});
|
|
3649
|
-
if (!isValid(base)) return base;
|
|
3650
|
-
const result = effect.transform(base.value, checkCtx);
|
|
3651
|
-
if (result instanceof Promise) {
|
|
3652
|
-
throw new Error(`Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.`);
|
|
3653
|
-
}
|
|
3654
|
-
return {
|
|
3655
|
-
status: status.value,
|
|
3656
|
-
value: result
|
|
3657
|
-
};
|
|
3658
|
-
} else {
|
|
3659
|
-
return this._def.schema._parseAsync({
|
|
3660
|
-
data: ctx.data,
|
|
3661
|
-
path: ctx.path,
|
|
3662
|
-
parent: ctx
|
|
3663
|
-
}).then(base => {
|
|
3664
|
-
if (!isValid(base)) return base;
|
|
3665
|
-
return Promise.resolve(effect.transform(base.value, checkCtx)).then(result => ({
|
|
3666
|
-
status: status.value,
|
|
3667
|
-
value: result
|
|
3668
|
-
}));
|
|
3669
|
-
});
|
|
3670
|
-
}
|
|
3671
|
-
}
|
|
3672
|
-
util$5.assertNever(effect);
|
|
3673
|
-
}
|
|
3674
|
-
}
|
|
3675
|
-
ZodEffects.create = (schema, effect, params) => {
|
|
3676
|
-
return new ZodEffects({
|
|
3677
|
-
schema,
|
|
3678
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3679
|
-
effect,
|
|
3680
|
-
...processCreateParams(params)
|
|
3681
|
-
});
|
|
3682
|
-
};
|
|
3683
|
-
ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
3684
|
-
return new ZodEffects({
|
|
3685
|
-
schema,
|
|
3686
|
-
effect: {
|
|
3687
|
-
type: "preprocess",
|
|
3688
|
-
transform: preprocess
|
|
3689
|
-
},
|
|
3690
|
-
typeName: ZodFirstPartyTypeKind.ZodEffects,
|
|
3691
|
-
...processCreateParams(params)
|
|
3692
|
-
});
|
|
3693
|
-
};
|
|
3694
|
-
class ZodOptional extends ZodType {
|
|
3695
|
-
_parse(input) {
|
|
3696
|
-
const parsedType = this._getType(input);
|
|
3697
|
-
if (parsedType === ZodParsedType.undefined) {
|
|
3698
|
-
return OK(undefined);
|
|
3699
|
-
}
|
|
3700
|
-
return this._def.innerType._parse(input);
|
|
3701
|
-
}
|
|
3702
|
-
unwrap() {
|
|
3703
|
-
return this._def.innerType;
|
|
3704
|
-
}
|
|
3705
|
-
}
|
|
3706
|
-
ZodOptional.create = (type, params) => {
|
|
3707
|
-
return new ZodOptional({
|
|
3708
|
-
innerType: type,
|
|
3709
|
-
typeName: ZodFirstPartyTypeKind.ZodOptional,
|
|
3710
|
-
...processCreateParams(params)
|
|
3711
|
-
});
|
|
3712
|
-
};
|
|
3713
|
-
class ZodNullable extends ZodType {
|
|
3714
|
-
_parse(input) {
|
|
3715
|
-
const parsedType = this._getType(input);
|
|
3716
|
-
if (parsedType === ZodParsedType.null) {
|
|
3717
|
-
return OK(null);
|
|
3718
|
-
}
|
|
3719
|
-
return this._def.innerType._parse(input);
|
|
3720
|
-
}
|
|
3721
|
-
unwrap() {
|
|
3722
|
-
return this._def.innerType;
|
|
3723
|
-
}
|
|
3724
|
-
}
|
|
3725
|
-
ZodNullable.create = (type, params) => {
|
|
3726
|
-
return new ZodNullable({
|
|
3727
|
-
innerType: type,
|
|
3728
|
-
typeName: ZodFirstPartyTypeKind.ZodNullable,
|
|
3729
|
-
...processCreateParams(params)
|
|
3730
|
-
});
|
|
3731
|
-
};
|
|
3732
|
-
class ZodDefault extends ZodType {
|
|
3733
|
-
_parse(input) {
|
|
3734
|
-
const {
|
|
3735
|
-
ctx
|
|
3736
|
-
} = this._processInputParams(input);
|
|
3737
|
-
let data = ctx.data;
|
|
3738
|
-
if (ctx.parsedType === ZodParsedType.undefined) {
|
|
3739
|
-
data = this._def.defaultValue();
|
|
3740
|
-
}
|
|
3741
|
-
return this._def.innerType._parse({
|
|
3742
|
-
data,
|
|
3743
|
-
path: ctx.path,
|
|
3744
|
-
parent: ctx
|
|
3745
|
-
});
|
|
3746
|
-
}
|
|
3747
|
-
removeDefault() {
|
|
3748
|
-
return this._def.innerType;
|
|
3749
|
-
}
|
|
3750
|
-
}
|
|
3751
|
-
ZodDefault.create = (type, params) => {
|
|
3752
|
-
return new ZodDefault({
|
|
3753
|
-
innerType: type,
|
|
3754
|
-
typeName: ZodFirstPartyTypeKind.ZodDefault,
|
|
3755
|
-
defaultValue: typeof params.default === "function" ? params.default : () => params.default,
|
|
3756
|
-
...processCreateParams(params)
|
|
3757
|
-
});
|
|
3758
|
-
};
|
|
3759
|
-
class ZodCatch extends ZodType {
|
|
3760
|
-
_parse(input) {
|
|
3761
|
-
const {
|
|
3762
|
-
ctx
|
|
3763
|
-
} = this._processInputParams(input);
|
|
3764
|
-
// newCtx is used to not collect issues from inner types in ctx
|
|
3765
|
-
const newCtx = {
|
|
3766
|
-
...ctx,
|
|
3767
|
-
common: {
|
|
3768
|
-
...ctx.common,
|
|
3769
|
-
issues: []
|
|
3770
|
-
}
|
|
3771
|
-
};
|
|
3772
|
-
const result = this._def.innerType._parse({
|
|
3773
|
-
data: newCtx.data,
|
|
3774
|
-
path: newCtx.path,
|
|
3775
|
-
parent: {
|
|
3776
|
-
...newCtx
|
|
3777
|
-
}
|
|
3778
|
-
});
|
|
3779
|
-
if (isAsync(result)) {
|
|
3780
|
-
return result.then(result => {
|
|
3781
|
-
return {
|
|
3782
|
-
status: "valid",
|
|
3783
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3784
|
-
get error() {
|
|
3785
|
-
return new ZodError(newCtx.common.issues);
|
|
3786
|
-
},
|
|
3787
|
-
input: newCtx.data
|
|
3788
|
-
})
|
|
3789
|
-
};
|
|
3790
|
-
});
|
|
3791
|
-
} else {
|
|
3792
|
-
return {
|
|
3793
|
-
status: "valid",
|
|
3794
|
-
value: result.status === "valid" ? result.value : this._def.catchValue({
|
|
3795
|
-
get error() {
|
|
3796
|
-
return new ZodError(newCtx.common.issues);
|
|
3797
|
-
},
|
|
3798
|
-
input: newCtx.data
|
|
3799
|
-
})
|
|
3800
|
-
};
|
|
3801
|
-
}
|
|
3802
|
-
}
|
|
3803
|
-
removeCatch() {
|
|
3804
|
-
return this._def.innerType;
|
|
3805
|
-
}
|
|
3806
|
-
}
|
|
3807
|
-
ZodCatch.create = (type, params) => {
|
|
3808
|
-
return new ZodCatch({
|
|
3809
|
-
innerType: type,
|
|
3810
|
-
typeName: ZodFirstPartyTypeKind.ZodCatch,
|
|
3811
|
-
catchValue: typeof params.catch === "function" ? params.catch : () => params.catch,
|
|
3812
|
-
...processCreateParams(params)
|
|
3813
|
-
});
|
|
3814
|
-
};
|
|
3815
|
-
class ZodNaN extends ZodType {
|
|
3816
|
-
_parse(input) {
|
|
3817
|
-
const parsedType = this._getType(input);
|
|
3818
|
-
if (parsedType !== ZodParsedType.nan) {
|
|
3819
|
-
const ctx = this._getOrReturnCtx(input);
|
|
3820
|
-
addIssueToContext(ctx, {
|
|
3821
|
-
code: ZodIssueCode.invalid_type,
|
|
3822
|
-
expected: ZodParsedType.nan,
|
|
3823
|
-
received: ctx.parsedType
|
|
3824
|
-
});
|
|
3825
|
-
return INVALID;
|
|
3826
|
-
}
|
|
3827
|
-
return {
|
|
3828
|
-
status: "valid",
|
|
3829
|
-
value: input.data
|
|
3830
|
-
};
|
|
3831
|
-
}
|
|
3832
|
-
}
|
|
3833
|
-
ZodNaN.create = params => {
|
|
3834
|
-
return new ZodNaN({
|
|
3835
|
-
typeName: ZodFirstPartyTypeKind.ZodNaN,
|
|
3836
|
-
...processCreateParams(params)
|
|
3837
|
-
});
|
|
3838
|
-
};
|
|
3839
|
-
const BRAND = Symbol("zod_brand");
|
|
3840
|
-
class ZodBranded extends ZodType {
|
|
3841
|
-
_parse(input) {
|
|
3842
|
-
const {
|
|
3843
|
-
ctx
|
|
3844
|
-
} = this._processInputParams(input);
|
|
3845
|
-
const data = ctx.data;
|
|
3846
|
-
return this._def.type._parse({
|
|
3847
|
-
data,
|
|
3848
|
-
path: ctx.path,
|
|
3849
|
-
parent: ctx
|
|
3850
|
-
});
|
|
3851
|
-
}
|
|
3852
|
-
unwrap() {
|
|
3853
|
-
return this._def.type;
|
|
3854
|
-
}
|
|
3855
|
-
}
|
|
3856
|
-
class ZodPipeline extends ZodType {
|
|
3857
|
-
_parse(input) {
|
|
3858
|
-
const {
|
|
3859
|
-
status,
|
|
3860
|
-
ctx
|
|
3861
|
-
} = this._processInputParams(input);
|
|
3862
|
-
if (ctx.common.async) {
|
|
3863
|
-
const handleAsync = async () => {
|
|
3864
|
-
const inResult = await this._def.in._parseAsync({
|
|
3865
|
-
data: ctx.data,
|
|
3866
|
-
path: ctx.path,
|
|
3867
|
-
parent: ctx
|
|
3868
|
-
});
|
|
3869
|
-
if (inResult.status === "aborted") return INVALID;
|
|
3870
|
-
if (inResult.status === "dirty") {
|
|
3871
|
-
status.dirty();
|
|
3872
|
-
return DIRTY(inResult.value);
|
|
3873
|
-
} else {
|
|
3874
|
-
return this._def.out._parseAsync({
|
|
3875
|
-
data: inResult.value,
|
|
3876
|
-
path: ctx.path,
|
|
3877
|
-
parent: ctx
|
|
3878
|
-
});
|
|
3879
|
-
}
|
|
3880
|
-
};
|
|
3881
|
-
return handleAsync();
|
|
3882
|
-
} else {
|
|
3883
|
-
const inResult = this._def.in._parseSync({
|
|
3884
|
-
data: ctx.data,
|
|
3885
|
-
path: ctx.path,
|
|
3886
|
-
parent: ctx
|
|
3887
|
-
});
|
|
3888
|
-
if (inResult.status === "aborted") return INVALID;
|
|
3889
|
-
if (inResult.status === "dirty") {
|
|
3890
|
-
status.dirty();
|
|
3891
|
-
return {
|
|
3892
|
-
status: "dirty",
|
|
3893
|
-
value: inResult.value
|
|
3894
|
-
};
|
|
3895
|
-
} else {
|
|
3896
|
-
return this._def.out._parseSync({
|
|
3897
|
-
data: inResult.value,
|
|
3898
|
-
path: ctx.path,
|
|
3899
|
-
parent: ctx
|
|
3900
|
-
});
|
|
3901
|
-
}
|
|
3902
|
-
}
|
|
3903
|
-
}
|
|
3904
|
-
static create(a, b) {
|
|
3905
|
-
return new ZodPipeline({
|
|
3906
|
-
in: a,
|
|
3907
|
-
out: b,
|
|
3908
|
-
typeName: ZodFirstPartyTypeKind.ZodPipeline
|
|
3909
|
-
});
|
|
3910
|
-
}
|
|
3911
|
-
}
|
|
3912
|
-
class ZodReadonly extends ZodType {
|
|
3913
|
-
_parse(input) {
|
|
3914
|
-
const result = this._def.innerType._parse(input);
|
|
3915
|
-
if (isValid(result)) {
|
|
3916
|
-
result.value = Object.freeze(result.value);
|
|
3917
|
-
}
|
|
3918
|
-
return result;
|
|
3919
|
-
}
|
|
3920
|
-
}
|
|
3921
|
-
ZodReadonly.create = (type, params) => {
|
|
3922
|
-
return new ZodReadonly({
|
|
3923
|
-
innerType: type,
|
|
3924
|
-
typeName: ZodFirstPartyTypeKind.ZodReadonly,
|
|
3925
|
-
...processCreateParams(params)
|
|
3926
|
-
});
|
|
3927
|
-
};
|
|
3928
|
-
const custom = (check, params = {},
|
|
3929
|
-
/**
|
|
3930
|
-
* @deprecated
|
|
3931
|
-
*
|
|
3932
|
-
* Pass `fatal` into the params object instead:
|
|
3933
|
-
*
|
|
3934
|
-
* ```ts
|
|
3935
|
-
* z.string().custom((val) => val.length > 5, { fatal: false })
|
|
3936
|
-
* ```
|
|
3937
|
-
*
|
|
3938
|
-
*/
|
|
3939
|
-
fatal) => {
|
|
3940
|
-
if (check) return ZodAny.create().superRefine((data, ctx) => {
|
|
3941
|
-
var _a, _b;
|
|
3942
|
-
if (!check(data)) {
|
|
3943
|
-
const p = typeof params === "function" ? params(data) : typeof params === "string" ? {
|
|
3944
|
-
message: params
|
|
3945
|
-
} : params;
|
|
3946
|
-
const _fatal = (_b = (_a = p.fatal) !== null && _a !== void 0 ? _a : fatal) !== null && _b !== void 0 ? _b : true;
|
|
3947
|
-
const p2 = typeof p === "string" ? {
|
|
3948
|
-
message: p
|
|
3949
|
-
} : p;
|
|
3950
|
-
ctx.addIssue({
|
|
3951
|
-
code: "custom",
|
|
3952
|
-
...p2,
|
|
3953
|
-
fatal: _fatal
|
|
3954
|
-
});
|
|
3955
|
-
}
|
|
3956
|
-
});
|
|
3957
|
-
return ZodAny.create();
|
|
3958
|
-
};
|
|
3959
|
-
const late = {
|
|
3960
|
-
object: ZodObject.lazycreate
|
|
3961
|
-
};
|
|
3962
|
-
var ZodFirstPartyTypeKind;
|
|
3963
|
-
(function (ZodFirstPartyTypeKind) {
|
|
3964
|
-
ZodFirstPartyTypeKind["ZodString"] = "ZodString";
|
|
3965
|
-
ZodFirstPartyTypeKind["ZodNumber"] = "ZodNumber";
|
|
3966
|
-
ZodFirstPartyTypeKind["ZodNaN"] = "ZodNaN";
|
|
3967
|
-
ZodFirstPartyTypeKind["ZodBigInt"] = "ZodBigInt";
|
|
3968
|
-
ZodFirstPartyTypeKind["ZodBoolean"] = "ZodBoolean";
|
|
3969
|
-
ZodFirstPartyTypeKind["ZodDate"] = "ZodDate";
|
|
3970
|
-
ZodFirstPartyTypeKind["ZodSymbol"] = "ZodSymbol";
|
|
3971
|
-
ZodFirstPartyTypeKind["ZodUndefined"] = "ZodUndefined";
|
|
3972
|
-
ZodFirstPartyTypeKind["ZodNull"] = "ZodNull";
|
|
3973
|
-
ZodFirstPartyTypeKind["ZodAny"] = "ZodAny";
|
|
3974
|
-
ZodFirstPartyTypeKind["ZodUnknown"] = "ZodUnknown";
|
|
3975
|
-
ZodFirstPartyTypeKind["ZodNever"] = "ZodNever";
|
|
3976
|
-
ZodFirstPartyTypeKind["ZodVoid"] = "ZodVoid";
|
|
3977
|
-
ZodFirstPartyTypeKind["ZodArray"] = "ZodArray";
|
|
3978
|
-
ZodFirstPartyTypeKind["ZodObject"] = "ZodObject";
|
|
3979
|
-
ZodFirstPartyTypeKind["ZodUnion"] = "ZodUnion";
|
|
3980
|
-
ZodFirstPartyTypeKind["ZodDiscriminatedUnion"] = "ZodDiscriminatedUnion";
|
|
3981
|
-
ZodFirstPartyTypeKind["ZodIntersection"] = "ZodIntersection";
|
|
3982
|
-
ZodFirstPartyTypeKind["ZodTuple"] = "ZodTuple";
|
|
3983
|
-
ZodFirstPartyTypeKind["ZodRecord"] = "ZodRecord";
|
|
3984
|
-
ZodFirstPartyTypeKind["ZodMap"] = "ZodMap";
|
|
3985
|
-
ZodFirstPartyTypeKind["ZodSet"] = "ZodSet";
|
|
3986
|
-
ZodFirstPartyTypeKind["ZodFunction"] = "ZodFunction";
|
|
3987
|
-
ZodFirstPartyTypeKind["ZodLazy"] = "ZodLazy";
|
|
3988
|
-
ZodFirstPartyTypeKind["ZodLiteral"] = "ZodLiteral";
|
|
3989
|
-
ZodFirstPartyTypeKind["ZodEnum"] = "ZodEnum";
|
|
3990
|
-
ZodFirstPartyTypeKind["ZodEffects"] = "ZodEffects";
|
|
3991
|
-
ZodFirstPartyTypeKind["ZodNativeEnum"] = "ZodNativeEnum";
|
|
3992
|
-
ZodFirstPartyTypeKind["ZodOptional"] = "ZodOptional";
|
|
3993
|
-
ZodFirstPartyTypeKind["ZodNullable"] = "ZodNullable";
|
|
3994
|
-
ZodFirstPartyTypeKind["ZodDefault"] = "ZodDefault";
|
|
3995
|
-
ZodFirstPartyTypeKind["ZodCatch"] = "ZodCatch";
|
|
3996
|
-
ZodFirstPartyTypeKind["ZodPromise"] = "ZodPromise";
|
|
3997
|
-
ZodFirstPartyTypeKind["ZodBranded"] = "ZodBranded";
|
|
3998
|
-
ZodFirstPartyTypeKind["ZodPipeline"] = "ZodPipeline";
|
|
3999
|
-
ZodFirstPartyTypeKind["ZodReadonly"] = "ZodReadonly";
|
|
4000
|
-
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
4001
|
-
const instanceOfType = (
|
|
4002
|
-
// const instanceOfType = <T extends new (...args: any[]) => any>(
|
|
4003
|
-
cls, params = {
|
|
4004
|
-
message: `Input not instance of ${cls.name}`
|
|
4005
|
-
}) => custom(data => data instanceof cls, params);
|
|
4006
|
-
const stringType = ZodString.create;
|
|
4007
|
-
const numberType = ZodNumber.create;
|
|
4008
|
-
const nanType = ZodNaN.create;
|
|
4009
|
-
const bigIntType = ZodBigInt.create;
|
|
4010
|
-
const booleanType = ZodBoolean.create;
|
|
4011
|
-
const dateType = ZodDate.create;
|
|
4012
|
-
const symbolType = ZodSymbol.create;
|
|
4013
|
-
const undefinedType = ZodUndefined.create;
|
|
4014
|
-
const nullType = ZodNull.create;
|
|
4015
|
-
const anyType = ZodAny.create;
|
|
4016
|
-
const unknownType = ZodUnknown.create;
|
|
4017
|
-
const neverType = ZodNever.create;
|
|
4018
|
-
const voidType = ZodVoid.create;
|
|
4019
|
-
const arrayType = ZodArray.create;
|
|
4020
|
-
const objectType = ZodObject.create;
|
|
4021
|
-
const strictObjectType = ZodObject.strictCreate;
|
|
4022
|
-
const unionType = ZodUnion.create;
|
|
4023
|
-
const discriminatedUnionType = ZodDiscriminatedUnion.create;
|
|
4024
|
-
const intersectionType = ZodIntersection.create;
|
|
4025
|
-
const tupleType = ZodTuple.create;
|
|
4026
|
-
const recordType = ZodRecord.create;
|
|
4027
|
-
const mapType = ZodMap.create;
|
|
4028
|
-
const setType = ZodSet.create;
|
|
4029
|
-
const functionType = ZodFunction.create;
|
|
4030
|
-
const lazyType = ZodLazy.create;
|
|
4031
|
-
const literalType = ZodLiteral.create;
|
|
4032
|
-
const enumType = ZodEnum.create;
|
|
4033
|
-
const nativeEnumType = ZodNativeEnum.create;
|
|
4034
|
-
const promiseType = ZodPromise.create;
|
|
4035
|
-
const effectsType = ZodEffects.create;
|
|
4036
|
-
const optionalType = ZodOptional.create;
|
|
4037
|
-
const nullableType = ZodNullable.create;
|
|
4038
|
-
const preprocessType = ZodEffects.createWithPreprocess;
|
|
4039
|
-
const pipelineType = ZodPipeline.create;
|
|
4040
|
-
const ostring = () => stringType().optional();
|
|
4041
|
-
const onumber = () => numberType().optional();
|
|
4042
|
-
const oboolean = () => booleanType().optional();
|
|
4043
|
-
const coerce = {
|
|
4044
|
-
string: arg => ZodString.create({
|
|
4045
|
-
...arg,
|
|
4046
|
-
coerce: true
|
|
4047
|
-
}),
|
|
4048
|
-
number: arg => ZodNumber.create({
|
|
4049
|
-
...arg,
|
|
4050
|
-
coerce: true
|
|
4051
|
-
}),
|
|
4052
|
-
boolean: arg => ZodBoolean.create({
|
|
4053
|
-
...arg,
|
|
4054
|
-
coerce: true
|
|
4055
|
-
}),
|
|
4056
|
-
bigint: arg => ZodBigInt.create({
|
|
4057
|
-
...arg,
|
|
4058
|
-
coerce: true
|
|
4059
|
-
}),
|
|
4060
|
-
date: arg => ZodDate.create({
|
|
4061
|
-
...arg,
|
|
4062
|
-
coerce: true
|
|
4063
|
-
})
|
|
4064
|
-
};
|
|
4065
|
-
const NEVER = INVALID;
|
|
4066
|
-
var z = /*#__PURE__*/Object.freeze({
|
|
4067
|
-
__proto__: null,
|
|
4068
|
-
defaultErrorMap: errorMap,
|
|
4069
|
-
setErrorMap: setErrorMap,
|
|
4070
|
-
getErrorMap: getErrorMap,
|
|
4071
|
-
makeIssue: makeIssue,
|
|
4072
|
-
EMPTY_PATH: EMPTY_PATH,
|
|
4073
|
-
addIssueToContext: addIssueToContext,
|
|
4074
|
-
ParseStatus: ParseStatus,
|
|
4075
|
-
INVALID: INVALID,
|
|
4076
|
-
DIRTY: DIRTY,
|
|
4077
|
-
OK: OK,
|
|
4078
|
-
isAborted: isAborted,
|
|
4079
|
-
isDirty: isDirty,
|
|
4080
|
-
isValid: isValid,
|
|
4081
|
-
isAsync: isAsync,
|
|
4082
|
-
get util() {
|
|
4083
|
-
return util$5;
|
|
4084
|
-
},
|
|
4085
|
-
get objectUtil() {
|
|
4086
|
-
return objectUtil;
|
|
4087
|
-
},
|
|
4088
|
-
ZodParsedType: ZodParsedType,
|
|
4089
|
-
getParsedType: getParsedType,
|
|
4090
|
-
ZodType: ZodType,
|
|
4091
|
-
ZodString: ZodString,
|
|
4092
|
-
ZodNumber: ZodNumber,
|
|
4093
|
-
ZodBigInt: ZodBigInt,
|
|
4094
|
-
ZodBoolean: ZodBoolean,
|
|
4095
|
-
ZodDate: ZodDate,
|
|
4096
|
-
ZodSymbol: ZodSymbol,
|
|
4097
|
-
ZodUndefined: ZodUndefined,
|
|
4098
|
-
ZodNull: ZodNull,
|
|
4099
|
-
ZodAny: ZodAny,
|
|
4100
|
-
ZodUnknown: ZodUnknown,
|
|
4101
|
-
ZodNever: ZodNever,
|
|
4102
|
-
ZodVoid: ZodVoid,
|
|
4103
|
-
ZodArray: ZodArray,
|
|
4104
|
-
ZodObject: ZodObject,
|
|
4105
|
-
ZodUnion: ZodUnion,
|
|
4106
|
-
ZodDiscriminatedUnion: ZodDiscriminatedUnion,
|
|
4107
|
-
ZodIntersection: ZodIntersection,
|
|
4108
|
-
ZodTuple: ZodTuple,
|
|
4109
|
-
ZodRecord: ZodRecord,
|
|
4110
|
-
ZodMap: ZodMap,
|
|
4111
|
-
ZodSet: ZodSet,
|
|
4112
|
-
ZodFunction: ZodFunction,
|
|
4113
|
-
ZodLazy: ZodLazy,
|
|
4114
|
-
ZodLiteral: ZodLiteral,
|
|
4115
|
-
ZodEnum: ZodEnum,
|
|
4116
|
-
ZodNativeEnum: ZodNativeEnum,
|
|
4117
|
-
ZodPromise: ZodPromise,
|
|
4118
|
-
ZodEffects: ZodEffects,
|
|
4119
|
-
ZodTransformer: ZodEffects,
|
|
4120
|
-
ZodOptional: ZodOptional,
|
|
4121
|
-
ZodNullable: ZodNullable,
|
|
4122
|
-
ZodDefault: ZodDefault,
|
|
4123
|
-
ZodCatch: ZodCatch,
|
|
4124
|
-
ZodNaN: ZodNaN,
|
|
4125
|
-
BRAND: BRAND,
|
|
4126
|
-
ZodBranded: ZodBranded,
|
|
4127
|
-
ZodPipeline: ZodPipeline,
|
|
4128
|
-
ZodReadonly: ZodReadonly,
|
|
4129
|
-
custom: custom,
|
|
4130
|
-
Schema: ZodType,
|
|
4131
|
-
ZodSchema: ZodType,
|
|
4132
|
-
late: late,
|
|
4133
|
-
get ZodFirstPartyTypeKind() {
|
|
4134
|
-
return ZodFirstPartyTypeKind;
|
|
4135
|
-
},
|
|
4136
|
-
coerce: coerce,
|
|
4137
|
-
any: anyType,
|
|
4138
|
-
array: arrayType,
|
|
4139
|
-
bigint: bigIntType,
|
|
4140
|
-
boolean: booleanType,
|
|
4141
|
-
date: dateType,
|
|
4142
|
-
discriminatedUnion: discriminatedUnionType,
|
|
4143
|
-
effect: effectsType,
|
|
4144
|
-
'enum': enumType,
|
|
4145
|
-
'function': functionType,
|
|
4146
|
-
'instanceof': instanceOfType,
|
|
4147
|
-
intersection: intersectionType,
|
|
4148
|
-
lazy: lazyType,
|
|
4149
|
-
literal: literalType,
|
|
4150
|
-
map: mapType,
|
|
4151
|
-
nan: nanType,
|
|
4152
|
-
nativeEnum: nativeEnumType,
|
|
4153
|
-
never: neverType,
|
|
4154
|
-
'null': nullType,
|
|
4155
|
-
nullable: nullableType,
|
|
4156
|
-
number: numberType,
|
|
4157
|
-
object: objectType,
|
|
4158
|
-
oboolean: oboolean,
|
|
4159
|
-
onumber: onumber,
|
|
4160
|
-
optional: optionalType,
|
|
4161
|
-
ostring: ostring,
|
|
4162
|
-
pipeline: pipelineType,
|
|
4163
|
-
preprocess: preprocessType,
|
|
4164
|
-
promise: promiseType,
|
|
4165
|
-
record: recordType,
|
|
4166
|
-
set: setType,
|
|
4167
|
-
strictObject: strictObjectType,
|
|
4168
|
-
string: stringType,
|
|
4169
|
-
symbol: symbolType,
|
|
4170
|
-
transformer: effectsType,
|
|
4171
|
-
tuple: tupleType,
|
|
4172
|
-
'undefined': undefinedType,
|
|
4173
|
-
union: unionType,
|
|
4174
|
-
unknown: unknownType,
|
|
4175
|
-
'void': voidType,
|
|
4176
|
-
NEVER: NEVER,
|
|
4177
|
-
ZodIssueCode: ZodIssueCode,
|
|
4178
|
-
quotelessJson: quotelessJson,
|
|
4179
|
-
ZodError: ZodError
|
|
4180
|
-
});
|
|
4181
|
-
|
|
4182
180
|
var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
|
|
4183
181
|
|
|
4184
182
|
function getDefaultExportFromCjs (x) {
|
|
@@ -39939,7 +35937,7 @@ function _loadUserPackageJson() {
|
|
|
39939
35937
|
targetPkgUrl = isTest ? packageTestJsonUrl : packageJsonUrl;
|
|
39940
35938
|
_context2.t0 = JSON;
|
|
39941
35939
|
_context2.next = 10;
|
|
39942
|
-
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('dev-
|
|
35940
|
+
return fs__default["default"].readFile(new URL(targetPkgUrl, (typeof document === 'undefined' ? new (require('u' + 'rl').URL)('file:' + __filename).href : (document.currentScript && document.currentScript.src || new URL('dev-170fa3f5.js', document.baseURI).href))), 'utf-8');
|
|
39943
35941
|
case 10:
|
|
39944
35942
|
_context2.t1 = _context2.sent;
|
|
39945
35943
|
pkg = _context2.t0.parse.call(_context2.t0, _context2.t1);
|
|
@@ -40625,354 +36623,6 @@ main$1.exports.parse = DotenvModule.parse;
|
|
|
40625
36623
|
main$1.exports.populate = DotenvModule.populate;
|
|
40626
36624
|
main$1.exports = DotenvModule;
|
|
40627
36625
|
|
|
40628
|
-
/**
|
|
40629
|
-
* @param {string} name
|
|
40630
|
-
* @param {Object} [props]
|
|
40631
|
-
* @returns {import('zod').ZodString}
|
|
40632
|
-
*/
|
|
40633
|
-
function zId(name) {
|
|
40634
|
-
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
40635
|
-
return z.string(props).regex(/^[A-Za-z0-9\-_\[\]]+$/, {
|
|
40636
|
-
message: "Invalid ".concat(name, " ID: ID must not contain spaces and should only contain alphanumeric characters, dashes, or underscores.")
|
|
40637
|
-
});
|
|
40638
|
-
}
|
|
40639
|
-
|
|
40640
|
-
var MessageSchema = z.object({
|
|
40641
|
-
id: zId('Message ID', {
|
|
40642
|
-
description: 'Unique ID for the message'
|
|
40643
|
-
}),
|
|
40644
|
-
role: z["enum"](['agent', 'customer', 'system']),
|
|
40645
|
-
content: z.string(),
|
|
40646
|
-
time: z.string({
|
|
40647
|
-
description: 'Datetime ISO 8601 timestamp'
|
|
40648
|
-
}),
|
|
40649
|
-
name: z.string().optional(),
|
|
40650
|
-
scheduled: z.string({
|
|
40651
|
-
description: 'Datetime ISO 8601 timestamp'
|
|
40652
|
-
}).optional(),
|
|
40653
|
-
context: z.any({
|
|
40654
|
-
description: 'The context generated from the message'
|
|
40655
|
-
}).optional(),
|
|
40656
|
-
intent: z.string({
|
|
40657
|
-
description: 'Detected intent'
|
|
40658
|
-
}).optional().nullable(),
|
|
40659
|
-
intentScore: z.number({
|
|
40660
|
-
description: 'Confidence score of the assigned intent'
|
|
40661
|
-
}).nullable().optional(),
|
|
40662
|
-
delayInSeconds: z.number({
|
|
40663
|
-
description: 'How long to delay the message manually in seconds'
|
|
40664
|
-
}).nullable().optional()
|
|
40665
|
-
});
|
|
40666
|
-
|
|
40667
|
-
var CustomerValueSchema = z.union([z["boolean"](), z.number(), z.string()]);
|
|
40668
|
-
var CustomerSchema = z.object({
|
|
40669
|
-
firstName: z.string().optional(),
|
|
40670
|
-
lastName: z.string().optional(),
|
|
40671
|
-
name: z.string(),
|
|
40672
|
-
email: z.string().nullable().optional(),
|
|
40673
|
-
phone: z.string().nullable().optional(),
|
|
40674
|
-
img: z.string().nullable().optional(),
|
|
40675
|
-
neighborhood: z.string().nullable().optional(),
|
|
40676
|
-
city: z.string().nullable().optional(),
|
|
40677
|
-
country: z.string().nullable().optional(),
|
|
40678
|
-
line1: z.string().nullable().optional(),
|
|
40679
|
-
line2: z.string().nullable().optional(),
|
|
40680
|
-
postal_code: z.string().nullable().optional(),
|
|
40681
|
-
state: z.string().nullable().optional(),
|
|
40682
|
-
town: z.string().nullable().optional(),
|
|
40683
|
-
joined: z.string().nullable().optional(),
|
|
40684
|
-
stripe: z.string().nullable().optional(),
|
|
40685
|
-
stripeDev: z.string().nullable().optional()
|
|
40686
|
-
}).catchall(CustomerValueSchema);
|
|
40687
|
-
var AgentSchema = z.object({
|
|
40688
|
-
deployed: z.object({
|
|
40689
|
-
web: z.string({
|
|
40690
|
-
description: 'Web URL for agent'
|
|
40691
|
-
}).optional(),
|
|
40692
|
-
phone: z.string({
|
|
40693
|
-
description: 'Phone number for agent'
|
|
40694
|
-
}).optional(),
|
|
40695
|
-
email: z.string({
|
|
40696
|
-
description: 'Email address for agent'
|
|
40697
|
-
}).optional()
|
|
40698
|
-
}).optional(),
|
|
40699
|
-
img: z.string().nullable().optional(),
|
|
40700
|
-
firstName: z.string({
|
|
40701
|
-
description: 'Agent first name'
|
|
40702
|
-
}).optional(),
|
|
40703
|
-
lastName: z.string({
|
|
40704
|
-
description: 'Agent last name'
|
|
40705
|
-
}).optional(),
|
|
40706
|
-
inactive: z["boolean"]({
|
|
40707
|
-
description: 'Agent is inactive'
|
|
40708
|
-
}).optional(),
|
|
40709
|
-
programmablePhoneNumber: z.string({
|
|
40710
|
-
description: 'Programmable phone number'
|
|
40711
|
-
}).optional(),
|
|
40712
|
-
programmablePhoneNumberSid: z.string({
|
|
40713
|
-
description: 'Programmable phone number SID'
|
|
40714
|
-
}).optional(),
|
|
40715
|
-
programmableEmail: z.string({
|
|
40716
|
-
description: 'Email address from Scout9 gmail subdomain'
|
|
40717
|
-
}).optional(),
|
|
40718
|
-
forwardEmail: z.string({
|
|
40719
|
-
description: 'Email address to forward to'
|
|
40720
|
-
}).optional(),
|
|
40721
|
-
forwardPhone: z.string({
|
|
40722
|
-
description: 'Phone number to forward to'
|
|
40723
|
-
}).optional(),
|
|
40724
|
-
title: z.string({
|
|
40725
|
-
description: 'Agent title '
|
|
40726
|
-
}).optional()["default"]('Agent'),
|
|
40727
|
-
context: z.string({
|
|
40728
|
-
description: 'Context of the agent'
|
|
40729
|
-
}).optional()["default"]('You represent the agent when they are away'),
|
|
40730
|
-
includedLocations: z.array(z.string({
|
|
40731
|
-
description: 'Locations the agent is included in'
|
|
40732
|
-
})).optional(),
|
|
40733
|
-
excludedLocations: z.array(z.string({
|
|
40734
|
-
description: 'Locations the agent is excluded from'
|
|
40735
|
-
})).optional(),
|
|
40736
|
-
model: z["enum"](['Scout9', 'bard', 'openai']).optional()["default"]('openai'),
|
|
40737
|
-
transcripts: z.array(z.array(MessageSchema)).optional(),
|
|
40738
|
-
audios: z.array(z.any()).optional()
|
|
40739
|
-
});
|
|
40740
|
-
var PersonaSchema = AgentSchema;
|
|
40741
|
-
var AgentConfigurationSchema = AgentSchema.extend({
|
|
40742
|
-
id: zId('Agent ID', {
|
|
40743
|
-
description: 'Unique ID for agent'
|
|
40744
|
-
})
|
|
40745
|
-
});
|
|
40746
|
-
var PersonaConfigurationSchema = AgentConfigurationSchema.extend({
|
|
40747
|
-
id: zId('Agent ID', {
|
|
40748
|
-
description: 'Unique ID for agent'
|
|
40749
|
-
})
|
|
40750
|
-
});
|
|
40751
|
-
var AgentsConfigurationSchema = z.array(AgentConfigurationSchema);
|
|
40752
|
-
var PersonasConfigurationSchema = z.array(PersonaConfigurationSchema);
|
|
40753
|
-
var AgentsSchema = z.array(AgentSchema);
|
|
40754
|
-
var PersonasSchema = z.array(PersonaSchema);
|
|
40755
|
-
var Bus = z.object({
|
|
40756
|
-
foo: z.string(),
|
|
40757
|
-
bar: z["boolean"]().optional()
|
|
40758
|
-
});
|
|
40759
|
-
var Baz = z.object({
|
|
40760
|
-
boo: z.object({
|
|
40761
|
-
one: z.number(),
|
|
40762
|
-
two: z.number().optional()
|
|
40763
|
-
})
|
|
40764
|
-
});
|
|
40765
|
-
var TestSchema = z.object({
|
|
40766
|
-
baz: Baz,
|
|
40767
|
-
bus: Bus
|
|
40768
|
-
});
|
|
40769
|
-
|
|
40770
|
-
var ConversationContext = z.record(z.string(), z.any());
|
|
40771
|
-
var ConversationAnticipateSchema = z.object({
|
|
40772
|
-
type: z["enum"](['did', 'literal', 'context'], {
|
|
40773
|
-
description: "Determines the runtime to address the next response"
|
|
40774
|
-
}),
|
|
40775
|
-
slots: z.record(z.string(), z.array(z.any())),
|
|
40776
|
-
did: z.string({
|
|
40777
|
-
description: 'For type \'did\''
|
|
40778
|
-
}).optional(),
|
|
40779
|
-
map: z.array(z.object({
|
|
40780
|
-
slot: z.string(),
|
|
40781
|
-
keywords: z.array(z.string())
|
|
40782
|
-
}), {
|
|
40783
|
-
description: 'For literal keywords, this map helps point which slot the keyword matches to'
|
|
40784
|
-
}).optional()
|
|
40785
|
-
});
|
|
40786
|
-
var ConversationSchema = z.object({
|
|
40787
|
-
$agent: zId('Conversation Agent ID', z.string({
|
|
40788
|
-
description: 'Default agent assigned to the conversation(s)'
|
|
40789
|
-
})),
|
|
40790
|
-
$customer: zId('Conversation Customer ID', z.string({
|
|
40791
|
-
description: 'Customer this conversation is with'
|
|
40792
|
-
})),
|
|
40793
|
-
initialContexts: z.array(z.string(), {
|
|
40794
|
-
description: 'Initial contexts to load when starting the conversation'
|
|
40795
|
-
}).optional(),
|
|
40796
|
-
environment: z["enum"](['phone', 'email', 'web']),
|
|
40797
|
-
environmentProps: z.object({
|
|
40798
|
-
subject: z.string({
|
|
40799
|
-
description: 'HTML Subject of the conversation'
|
|
40800
|
-
}).optional(),
|
|
40801
|
-
platformEmailThreadId: z.string({
|
|
40802
|
-
description: 'Used to sync email messages with the conversation'
|
|
40803
|
-
}).optional()
|
|
40804
|
-
}).optional(),
|
|
40805
|
-
locked: z["boolean"]({
|
|
40806
|
-
description: 'Whether the conversation is locked or not'
|
|
40807
|
-
}).optional().nullable(),
|
|
40808
|
-
lockedReason: z.string({
|
|
40809
|
-
description: 'Why this conversation was locked'
|
|
40810
|
-
}).optional().nullable(),
|
|
40811
|
-
lockAttempts: z.number({
|
|
40812
|
-
description: 'Number attempts made until conversation is locked'
|
|
40813
|
-
}).optional().nullable(),
|
|
40814
|
-
forwardedTo: z.string({
|
|
40815
|
-
description: 'What personaId/phone/email was forwarded'
|
|
40816
|
-
}).optional().nullable(),
|
|
40817
|
-
forwarded: z.string({
|
|
40818
|
-
description: 'Datetime ISO 8601 timestamp when persona was forwarded'
|
|
40819
|
-
}).optional().nullable(),
|
|
40820
|
-
forwardNote: z.string().optional().nullable(),
|
|
40821
|
-
intent: z.string({
|
|
40822
|
-
description: 'Detected intent of conversation'
|
|
40823
|
-
}).optional().nullable(),
|
|
40824
|
-
intentScore: z.number({
|
|
40825
|
-
description: 'Confidence score of the assigned intent'
|
|
40826
|
-
}).optional().nullable(),
|
|
40827
|
-
anticipate: ConversationAnticipateSchema.optional()
|
|
40828
|
-
});
|
|
40829
|
-
|
|
40830
|
-
var ForwardSchema = z.union([z["boolean"](), z.string(), z.object({
|
|
40831
|
-
to: z.string().optional(),
|
|
40832
|
-
mode: z["enum"](['after-reply', 'immediately']).optional(),
|
|
40833
|
-
note: z.string({
|
|
40834
|
-
description: 'Note to provide to the agent'
|
|
40835
|
-
}).optional()
|
|
40836
|
-
})], {
|
|
40837
|
-
description: 'Forward input information of a conversation'
|
|
40838
|
-
});
|
|
40839
|
-
var InstructionObjectSchema = z.object({
|
|
40840
|
-
id: zId('Instruction ID').describe('Unique ID for the instruction, this is used to remove the instruction later').optional(),
|
|
40841
|
-
persist: z["boolean"]().describe('if true, the instruction persists the conversation, if false the instruction will only last for 1 auto reply')["default"](true).optional(),
|
|
40842
|
-
content: z.string()
|
|
40843
|
-
});
|
|
40844
|
-
var WorkflowResponseMessageApiRequest = z.object({
|
|
40845
|
-
uri: z.string(),
|
|
40846
|
-
data: z.any().optional(),
|
|
40847
|
-
headers: z.record(z.string(), z.string()).optional(),
|
|
40848
|
-
method: z["enum"](['GET', 'POST', 'PUT']).optional()
|
|
40849
|
-
});
|
|
40850
|
-
|
|
40851
|
-
/**
|
|
40852
|
-
* If its a string, it will be sent as a static string.
|
|
40853
|
-
* If it's a object or WorkflowResponseMessageAPI - it will use
|
|
40854
|
-
*/
|
|
40855
|
-
var WorkflowResponseMessage = z.union([z.string(),
|
|
40856
|
-
/**
|
|
40857
|
-
* An api call that should be called later, must return a string or {message: string}
|
|
40858
|
-
*/
|
|
40859
|
-
WorkflowResponseMessageApiRequest]);
|
|
40860
|
-
|
|
40861
|
-
/**
|
|
40862
|
-
* The intended response provided by the WorkflowResponseMessageApiRequest
|
|
40863
|
-
*/
|
|
40864
|
-
var WorkflowResponseMessageApiResponse = z.union([z.string(), z.object({
|
|
40865
|
-
message: z.string()
|
|
40866
|
-
}), z.object({
|
|
40867
|
-
text: z.string()
|
|
40868
|
-
}), z.object({
|
|
40869
|
-
data: z.object({
|
|
40870
|
-
message: z.string()
|
|
40871
|
-
})
|
|
40872
|
-
}), z.object({
|
|
40873
|
-
data: z.object({
|
|
40874
|
-
text: z.string()
|
|
40875
|
-
})
|
|
40876
|
-
})]);
|
|
40877
|
-
|
|
40878
|
-
/**
|
|
40879
|
-
* The workflow response object slot
|
|
40880
|
-
*/
|
|
40881
|
-
var InstructionSchema = z.union([z.string(), InstructionObjectSchema, z.array(z.string()), z.array(InstructionObjectSchema)]);
|
|
40882
|
-
|
|
40883
|
-
/**
|
|
40884
|
-
* Base follow up schema to follow up with the client
|
|
40885
|
-
*/
|
|
40886
|
-
var FollowupBaseSchema = z.object({
|
|
40887
|
-
scheduled: z.number(),
|
|
40888
|
-
cancelIf: ConversationContext.optional(),
|
|
40889
|
-
overrideLock: z["boolean"]({
|
|
40890
|
-
description: 'This will still run even if the conversation is locked, defaults to false'
|
|
40891
|
-
}).optional()
|
|
40892
|
-
});
|
|
40893
|
-
|
|
40894
|
-
/**
|
|
40895
|
-
* Data used to automatically follow up with the client in the future
|
|
40896
|
-
*/
|
|
40897
|
-
var FollowupSchema = z.union([FollowupBaseSchema.extend({
|
|
40898
|
-
message: z.string({
|
|
40899
|
-
description: 'Manual message sent to client'
|
|
40900
|
-
})
|
|
40901
|
-
}), FollowupBaseSchema.extend({
|
|
40902
|
-
instructions: InstructionSchema
|
|
40903
|
-
})]);
|
|
40904
|
-
var WorkflowConfigurationSchema = z.object({
|
|
40905
|
-
entities: z.array(zId('Workflow Folder', z.string()), {
|
|
40906
|
-
description: 'Workflow id association, used to handle route params'
|
|
40907
|
-
}).min(1, 'Must have at least 1 entity').max(15, 'Cannot have more than 15 entity paths'),
|
|
40908
|
-
entity: zId('Workflow Folder', z.string())
|
|
40909
|
-
});
|
|
40910
|
-
var WorkflowsConfigurationSchema = z.array(WorkflowConfigurationSchema);
|
|
40911
|
-
var IntentWorkflowEventSchema = z.object({
|
|
40912
|
-
current: z.string().nullable(),
|
|
40913
|
-
flow: z.array(z.string()),
|
|
40914
|
-
initial: z.string().nullable()
|
|
40915
|
-
});
|
|
40916
|
-
var WorkflowEventSchema = z.object({
|
|
40917
|
-
messages: z.array(MessageSchema),
|
|
40918
|
-
conversation: ConversationSchema,
|
|
40919
|
-
context: z.any(),
|
|
40920
|
-
message: MessageSchema,
|
|
40921
|
-
agent: AgentConfigurationSchema.omit({
|
|
40922
|
-
transcripts: true,
|
|
40923
|
-
audios: true,
|
|
40924
|
-
includedLocations: true,
|
|
40925
|
-
excludedLocations: true,
|
|
40926
|
-
model: true,
|
|
40927
|
-
context: true
|
|
40928
|
-
}),
|
|
40929
|
-
customer: CustomerSchema,
|
|
40930
|
-
intent: IntentWorkflowEventSchema,
|
|
40931
|
-
stagnationCount: z.number(),
|
|
40932
|
-
note: z.string({
|
|
40933
|
-
description: 'Any developer notes to provide'
|
|
40934
|
-
}).optional()
|
|
40935
|
-
});
|
|
40936
|
-
|
|
40937
|
-
/**
|
|
40938
|
-
* The workflow response object slot
|
|
40939
|
-
*/
|
|
40940
|
-
var WorkflowResponseSlotBaseSchema = z.object({
|
|
40941
|
-
forward: ForwardSchema.optional(),
|
|
40942
|
-
forwardNote: z.string({
|
|
40943
|
-
description: 'Note to provide to the agent, recommend using forward object api instead'
|
|
40944
|
-
}).optional(),
|
|
40945
|
-
instructions: InstructionSchema.optional(),
|
|
40946
|
-
removeInstructions: z.array(z.string()).optional(),
|
|
40947
|
-
message: z.string().optional(),
|
|
40948
|
-
secondsDelay: z.number().optional(),
|
|
40949
|
-
scheduled: z.number().optional(),
|
|
40950
|
-
contextUpsert: ConversationContext.optional(),
|
|
40951
|
-
resetIntent: z["boolean"]().optional(),
|
|
40952
|
-
followup: FollowupSchema.optional()
|
|
40953
|
-
});
|
|
40954
|
-
|
|
40955
|
-
/**
|
|
40956
|
-
* The workflow response object slot
|
|
40957
|
-
*/
|
|
40958
|
-
var WorkflowResponseSlotSchema = WorkflowResponseSlotBaseSchema.extend({
|
|
40959
|
-
anticipate: z.union([z.object({
|
|
40960
|
-
did: z.string({
|
|
40961
|
-
definition: 'The prompt to check if true or false'
|
|
40962
|
-
}),
|
|
40963
|
-
yes: WorkflowResponseSlotBaseSchema,
|
|
40964
|
-
no: WorkflowResponseSlotBaseSchema
|
|
40965
|
-
}), z.array(WorkflowResponseSlotBaseSchema.extend({
|
|
40966
|
-
keywords: z.array(z.string()).min(1).max(20)
|
|
40967
|
-
}))]).optional()
|
|
40968
|
-
});
|
|
40969
|
-
|
|
40970
|
-
/**
|
|
40971
|
-
* The workflow response to send in any given workflow
|
|
40972
|
-
*/
|
|
40973
|
-
var WorkflowResponseSchema = z.union([WorkflowResponseSlotSchema, z.array(WorkflowResponseSlotSchema)]);
|
|
40974
|
-
var WorkflowFunctionSchema = z["function"]().args(WorkflowEventSchema).returns(z.union([z.promise(WorkflowResponseSchema), WorkflowResponseSchema]));
|
|
40975
|
-
|
|
40976
36626
|
var _excluded$2 = ["success"];
|
|
40977
36627
|
function MacroUtilsFactory() {
|
|
40978
36628
|
return {
|
|
@@ -41102,7 +36752,7 @@ function EventMacrosFactory() {
|
|
|
41102
36752
|
var slot = {
|
|
41103
36753
|
contextUpsert: updates
|
|
41104
36754
|
};
|
|
41105
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
36755
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
41106
36756
|
return this;
|
|
41107
36757
|
},
|
|
41108
36758
|
/**
|
|
@@ -41156,7 +36806,7 @@ function EventMacrosFactory() {
|
|
|
41156
36806
|
}
|
|
41157
36807
|
};
|
|
41158
36808
|
}
|
|
41159
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
36809
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
41160
36810
|
return this;
|
|
41161
36811
|
},
|
|
41162
36812
|
/**
|
|
@@ -41200,13 +36850,13 @@ function EventMacrosFactory() {
|
|
|
41200
36850
|
}
|
|
41201
36851
|
slot.anticipate = {
|
|
41202
36852
|
did: instruction,
|
|
41203
|
-
yes: WorkflowResponseSlotBaseSchema.parse(yes),
|
|
41204
|
-
no: WorkflowResponseSlotBaseSchema.parse(no)
|
|
36853
|
+
yes: macros.WorkflowResponseSlotBaseSchema.parse(yes),
|
|
36854
|
+
no: macros.WorkflowResponseSlotBaseSchema.parse(no)
|
|
41205
36855
|
};
|
|
41206
36856
|
} else {
|
|
41207
36857
|
throw new Error("Instruction is not of type \"string\" or \"array\"");
|
|
41208
36858
|
}
|
|
41209
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
36859
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
41210
36860
|
return this;
|
|
41211
36861
|
},
|
|
41212
36862
|
/**
|
|
@@ -41232,7 +36882,7 @@ function EventMacrosFactory() {
|
|
|
41232
36882
|
} else {
|
|
41233
36883
|
slot.instructions = instruction;
|
|
41234
36884
|
}
|
|
41235
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
36885
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
41236
36886
|
return this;
|
|
41237
36887
|
},
|
|
41238
36888
|
/**
|
|
@@ -41258,7 +36908,7 @@ function EventMacrosFactory() {
|
|
|
41258
36908
|
slot.secondsDelay = delay;
|
|
41259
36909
|
}
|
|
41260
36910
|
}
|
|
41261
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
36911
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
41262
36912
|
return this;
|
|
41263
36913
|
},
|
|
41264
36914
|
/**
|
|
@@ -41290,7 +36940,7 @@ function EventMacrosFactory() {
|
|
|
41290
36940
|
forwardNote: message !== null && message !== void 0 ? message : defaultForward
|
|
41291
36941
|
};
|
|
41292
36942
|
}
|
|
41293
|
-
slots.push(WorkflowResponseSlotSchema.parse(slot));
|
|
36943
|
+
slots.push(macros.WorkflowResponseSlotSchema.parse(slot));
|
|
41294
36944
|
return this;
|
|
41295
36945
|
},
|
|
41296
36946
|
/**
|
|
@@ -41364,270 +37014,6 @@ var forward = eventMacros.forward.bind(eventMacros);
|
|
|
41364
37014
|
*/
|
|
41365
37015
|
var reply = eventMacros.reply.bind(eventMacros);
|
|
41366
37016
|
|
|
41367
|
-
var responseInitSchema = z.object({
|
|
41368
|
-
status: z.number().optional(),
|
|
41369
|
-
statusText: z.string().optional(),
|
|
41370
|
-
headers: z.any().optional() // Headers can be complex; adjust as needed
|
|
41371
|
-
});
|
|
41372
|
-
|
|
41373
|
-
/**
|
|
41374
|
-
* @template T
|
|
41375
|
-
* @typedef {object} IEventResponse
|
|
41376
|
-
* @property {T} body - The body of the response.
|
|
41377
|
-
* @property {ResponseInit} [init] - Additional options for the response.
|
|
41378
|
-
* @property {Response} response - The response object.
|
|
41379
|
-
* @property {T} data - The body of the response.
|
|
41380
|
-
*/
|
|
41381
|
-
var eventResponseSchema = z.object({
|
|
41382
|
-
body: z.any(),
|
|
41383
|
-
// Adjust as per your actual body structure
|
|
41384
|
-
init: responseInitSchema.optional()
|
|
41385
|
-
});
|
|
41386
|
-
|
|
41387
|
-
var EntityApiConfigurationSchema = z.object({
|
|
41388
|
-
// path: z.string(),
|
|
41389
|
-
GET: z["boolean"]().optional(),
|
|
41390
|
-
UPDATE: z["boolean"]().optional(),
|
|
41391
|
-
QUERY: z["boolean"]().optional(),
|
|
41392
|
-
PUT: z["boolean"]().optional(),
|
|
41393
|
-
PATCH: z["boolean"]().optional(),
|
|
41394
|
-
DELETE: z["boolean"]().optional()
|
|
41395
|
-
}).nullable();
|
|
41396
|
-
var EntityConfigurationDefinitionSchema = z.object({
|
|
41397
|
-
utterance: zId('Utterance', z.string({
|
|
41398
|
-
description: 'What entity utterance this represents, if not provided, it will default to the entity id'
|
|
41399
|
-
})).optional(),
|
|
41400
|
-
value: z.string({
|
|
41401
|
-
description: 'The value of this entity variance'
|
|
41402
|
-
}),
|
|
41403
|
-
text: z.array(z.string(), {
|
|
41404
|
-
description: 'Text representing the entity variance'
|
|
41405
|
-
})
|
|
41406
|
-
});
|
|
41407
|
-
var EntityConfigurationTrainingSchema = z.object({
|
|
41408
|
-
intent: zId('Intent', z.string({
|
|
41409
|
-
description: 'The assigned intent id of the given text, e.g. "I love %pizza%" could have an intent id "feedback" and "Can I purchase a %pizza%?" could have an intent id "purchase"'
|
|
41410
|
-
})),
|
|
41411
|
-
text: z.string({
|
|
41412
|
-
description: 'Text to train the intent field and entities in or entity variances in example sentences or phrase. Ex: "I love %pizza%" and "Can I purchase a %pizza%?"'
|
|
41413
|
-
})
|
|
41414
|
-
});
|
|
41415
|
-
var EntityConfigurationTestSchema = z.object({
|
|
41416
|
-
text: z.string({
|
|
41417
|
-
description: 'Text to test the entity detection'
|
|
41418
|
-
}),
|
|
41419
|
-
expected: z.object({
|
|
41420
|
-
intent: zId('Intent', z.string({
|
|
41421
|
-
description: 'The expected intent id'
|
|
41422
|
-
})),
|
|
41423
|
-
// context: ConversationContext
|
|
41424
|
-
context: z.any()
|
|
41425
|
-
})
|
|
41426
|
-
});
|
|
41427
|
-
var _EntityConfigurationSchema = z.object({
|
|
41428
|
-
id: zId('Id', z.string({
|
|
41429
|
-
description: 'If not provided, the id will default to the route (folder) name'
|
|
41430
|
-
})).optional(),
|
|
41431
|
-
definitions: z.array(EntityConfigurationDefinitionSchema).optional(),
|
|
41432
|
-
training: z.array(EntityConfigurationTrainingSchema).optional(),
|
|
41433
|
-
tests: z.array(EntityConfigurationTestSchema).optional()
|
|
41434
|
-
}).strict();
|
|
41435
|
-
var EntityConfigurationSchema = _EntityConfigurationSchema.refine(function (data) {
|
|
41436
|
-
// If 'definitions' is provided, then 'training' must also be provided
|
|
41437
|
-
if (data.definitions !== undefined) {
|
|
41438
|
-
return data.training !== undefined;
|
|
41439
|
-
}
|
|
41440
|
-
// If 'definitions' is not provided, no additional validation is needed
|
|
41441
|
-
return true;
|
|
41442
|
-
}, {
|
|
41443
|
-
// Custom error message
|
|
41444
|
-
message: "If 'definitions' is provided, then 'training' must also be provided"
|
|
41445
|
-
});
|
|
41446
|
-
var EntitiesRootConfigurationSchema = z.array(EntityConfigurationSchema);
|
|
41447
|
-
var EntityExtendedProjectConfigurationSchema = z.object({
|
|
41448
|
-
entities: z.array(zId('Entity Folder', z.string()), {
|
|
41449
|
-
description: 'Entity id association, used to handle route params'
|
|
41450
|
-
}).min(1, 'Must have at least 1 entity').max(15, 'Cannot have more than 15 entity paths'),
|
|
41451
|
-
entity: zId('Entity Folder', z.string()),
|
|
41452
|
-
api: EntityApiConfigurationSchema
|
|
41453
|
-
});
|
|
41454
|
-
var _EntityRootProjectConfigurationSchema = _EntityConfigurationSchema.extend(EntityExtendedProjectConfigurationSchema.shape);
|
|
41455
|
-
z.array(_EntityRootProjectConfigurationSchema);
|
|
41456
|
-
|
|
41457
|
-
/**
|
|
41458
|
-
* @TODO why type extend not valid?
|
|
41459
|
-
*/
|
|
41460
|
-
var EntityRootProjectConfigurationSchema = _EntityConfigurationSchema.extend(EntityExtendedProjectConfigurationSchema.shape).refine(function (data) {
|
|
41461
|
-
// If 'definitions' is provided, then 'training' must also be provided
|
|
41462
|
-
if (data.definitions !== undefined) {
|
|
41463
|
-
return data.training !== undefined;
|
|
41464
|
-
}
|
|
41465
|
-
// If 'definitions' is not provided, no additional validation is needed
|
|
41466
|
-
return true;
|
|
41467
|
-
}, {
|
|
41468
|
-
// Custom error message
|
|
41469
|
-
message: "If 'definitions' is provided, then 'training' must also be provided"
|
|
41470
|
-
});
|
|
41471
|
-
var EntitiesRootProjectConfigurationSchema = z.array(EntityRootProjectConfigurationSchema);
|
|
41472
|
-
|
|
41473
|
-
var LlmModelOptions = z.union([z.literal('gpt-4-1106-preview'), z.literal('gpt-4-vision-preview'), z.literal('gpt-4'), z.literal('gpt-4-0314'), z.literal('gpt-4-0613'), z.literal('gpt-4-32k'), z.literal('gpt-4-32k-0314'), z.literal('gpt-4-32k-0613'), z.literal('gpt-3.5-turbo'), z.literal('gpt-3.5-turbo-16k'), z.literal('gpt-3.5-turbo-0301'), z.literal('gpt-3.5-turbo-0613'), z.literal('gpt-3.5-turbo-16k-0613'), z.string() // for the (string & {}) part
|
|
41474
|
-
]);
|
|
41475
|
-
z.union([z.literal('orin-1.0'), z.literal('orin-2.0-preview')]);
|
|
41476
|
-
var LlmSchema = z.object({
|
|
41477
|
-
engine: z.literal('openai'),
|
|
41478
|
-
model: LlmModelOptions
|
|
41479
|
-
});
|
|
41480
|
-
var LlamaSchema = z.object({
|
|
41481
|
-
engine: z.literal('llama'),
|
|
41482
|
-
model: z.string()
|
|
41483
|
-
});
|
|
41484
|
-
var BardSchema = z.object({
|
|
41485
|
-
engine: z.literal('bard'),
|
|
41486
|
-
model: z.string()
|
|
41487
|
-
});
|
|
41488
|
-
|
|
41489
|
-
/**
|
|
41490
|
-
* Configure personal model transformer (PMT) settings to align auto replies the agent's tone
|
|
41491
|
-
*/
|
|
41492
|
-
var PmtSchema = z.object({
|
|
41493
|
-
engine: z.literal('scout9'),
|
|
41494
|
-
// model: pmtModelOptions
|
|
41495
|
-
model: z.string()
|
|
41496
|
-
}, {
|
|
41497
|
-
description: 'Configure personal model transformer (PMT) settings to align auto replies the agent\'s tone'
|
|
41498
|
-
});
|
|
41499
|
-
|
|
41500
|
-
/**
|
|
41501
|
-
* Represents the configuration provided in src/index.{js | ts} in a project
|
|
41502
|
-
*/
|
|
41503
|
-
var Scout9ProjectConfigSchema = z.object({
|
|
41504
|
-
/**
|
|
41505
|
-
* Tag to reference this application
|
|
41506
|
-
* @defaut your local package.json name + version, or scout9-app-v1.0.0
|
|
41507
|
-
*/
|
|
41508
|
-
tag: z.string().optional(),
|
|
41509
|
-
// Defaults to scout9-app-v1.0.0
|
|
41510
|
-
llm: z.union([LlmSchema, LlamaSchema, BardSchema]),
|
|
41511
|
-
/**
|
|
41512
|
-
* Configure personal model transformer (PMT) settings to align auto replies the agent's tone
|
|
41513
|
-
*/
|
|
41514
|
-
pmt: PmtSchema,
|
|
41515
|
-
/**
|
|
41516
|
-
* Determines the max auto replies without further conversation progression (defined by new context data gathered)
|
|
41517
|
-
* before the conversation is locked and requires manual intervention
|
|
41518
|
-
* @default 3
|
|
41519
|
-
*/
|
|
41520
|
-
maxLockAttempts: z.number({
|
|
41521
|
-
description: 'Determines the max auto replies without further conversation progression (defined by new context data gathered), before the conversation is locked and requires manual intervention'
|
|
41522
|
-
}).min(0).max(20)["default"](3).optional(),
|
|
41523
|
-
initialContext: z.array(z.string(), {
|
|
41524
|
-
description: 'Configure the initial contexts for every conversation'
|
|
41525
|
-
}),
|
|
41526
|
-
organization: z.object({
|
|
41527
|
-
name: z.string(),
|
|
41528
|
-
description: z.string(),
|
|
41529
|
-
dashboard: z.string().optional(),
|
|
41530
|
-
logo: z.string().optional(),
|
|
41531
|
-
icon: z.string().optional(),
|
|
41532
|
-
logos: z.string().optional(),
|
|
41533
|
-
website: z.string().optional(),
|
|
41534
|
-
email: z.string().email().optional(),
|
|
41535
|
-
phone: z.string().optional()
|
|
41536
|
-
}).optional()
|
|
41537
|
-
});
|
|
41538
|
-
var Scout9ProjectBuildConfigSchema = Scout9ProjectConfigSchema.extend({
|
|
41539
|
-
agents: AgentsSchema,
|
|
41540
|
-
entities: EntitiesRootProjectConfigurationSchema,
|
|
41541
|
-
workflows: WorkflowsConfigurationSchema
|
|
41542
|
-
});
|
|
41543
|
-
|
|
41544
|
-
/**
|
|
41545
|
-
* @typedef {object} IApiFunctionParams
|
|
41546
|
-
* @property {Object.<string, string|string[]>} searchParams
|
|
41547
|
-
* @property {Record<string, string>} params
|
|
41548
|
-
*/
|
|
41549
|
-
var apiFunctionParamsSchema = z.object({
|
|
41550
|
-
searchParams: z.record(z.string(), z.union([z.string(), z.array(z.string())])),
|
|
41551
|
-
params: z.record(z.string(), z.string())
|
|
41552
|
-
});
|
|
41553
|
-
|
|
41554
|
-
/**
|
|
41555
|
-
* @typedef {IApiFunctionParams & { id: string }} IApiEntityFunctionParams
|
|
41556
|
-
*/
|
|
41557
|
-
apiFunctionParamsSchema.extend({
|
|
41558
|
-
id: z.string()
|
|
41559
|
-
});
|
|
41560
|
-
|
|
41561
|
-
/**
|
|
41562
|
-
* @template Params
|
|
41563
|
-
* @template Response
|
|
41564
|
-
* @typedef {function(IApiFunctionParams): Promise<EventResponse>} IApiFunction
|
|
41565
|
-
*/
|
|
41566
|
-
var apiFunctionSchema = z["function"]().args(apiFunctionParamsSchema).returns(z.promise(eventResponseSchema));
|
|
41567
|
-
|
|
41568
|
-
/**
|
|
41569
|
-
* @template Params
|
|
41570
|
-
* @template Response
|
|
41571
|
-
* @typedef {IApiFunction<Params, Response>} IQueryApiFunction
|
|
41572
|
-
*/
|
|
41573
|
-
var queryApiFunctionSchema = apiFunctionSchema;
|
|
41574
|
-
|
|
41575
|
-
/**
|
|
41576
|
-
* @template Params
|
|
41577
|
-
* @template Response
|
|
41578
|
-
* @typedef {IApiFunction<Params, Response>} GetApiFunction
|
|
41579
|
-
*/
|
|
41580
|
-
var getApiFunctionSchema = apiFunctionSchema;
|
|
41581
|
-
|
|
41582
|
-
/**
|
|
41583
|
-
* @template Params
|
|
41584
|
-
* @template RequestBody
|
|
41585
|
-
* @template Response
|
|
41586
|
-
* @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPostApiFunction
|
|
41587
|
-
*/
|
|
41588
|
-
var postApiFunctionSchema = function postApiFunctionSchema(requestBodySchema) {
|
|
41589
|
-
return z["function"]().args(apiFunctionParamsSchema.extend({
|
|
41590
|
-
body: requestBodySchema.partial()
|
|
41591
|
-
})).returns(z.promise(eventResponseSchema));
|
|
41592
|
-
};
|
|
41593
|
-
|
|
41594
|
-
/**
|
|
41595
|
-
* @template Params
|
|
41596
|
-
* @template RequestBody
|
|
41597
|
-
* @template Response
|
|
41598
|
-
* @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPutApiFunction
|
|
41599
|
-
*/
|
|
41600
|
-
var putApiFunctionSchema = function putApiFunctionSchema(requestBodySchema) {
|
|
41601
|
-
return z["function"]().args(apiFunctionParamsSchema.extend({
|
|
41602
|
-
body: requestBodySchema.partial()
|
|
41603
|
-
})).returns(z.promise(eventResponseSchema));
|
|
41604
|
-
};
|
|
41605
|
-
|
|
41606
|
-
/**
|
|
41607
|
-
* @template Params
|
|
41608
|
-
* @template RequestBody
|
|
41609
|
-
* @template Response
|
|
41610
|
-
* @typedef {function(IApiFunctionParams & {body: Partial<RequestBody>}): Promise<EventResponse<Response>>} IPatchApiFunction
|
|
41611
|
-
*/
|
|
41612
|
-
var patchApiFunctionSchema = function patchApiFunctionSchema(requestBodySchema) {
|
|
41613
|
-
return z["function"]().args(apiFunctionParamsSchema.extend({
|
|
41614
|
-
body: requestBodySchema.partial()
|
|
41615
|
-
})).returns(z.promise(eventResponseSchema));
|
|
41616
|
-
};
|
|
41617
|
-
|
|
41618
|
-
/**
|
|
41619
|
-
* @template Params
|
|
41620
|
-
* @template Response
|
|
41621
|
-
* @typedef {IApiFunction<Params, Response>} IDeleteApiFunction
|
|
41622
|
-
*/
|
|
41623
|
-
var deleteApiFunctionSchema = apiFunctionSchema;
|
|
41624
|
-
|
|
41625
|
-
var ContextExampleWithTrainingDataSchema = z.object({
|
|
41626
|
-
input: z.string(),
|
|
41627
|
-
output: z.array(z.record(z.string(), z.any()))
|
|
41628
|
-
});
|
|
41629
|
-
var ContextExampleSchema = z.union([z.array(ContextExampleWithTrainingDataSchema), z.array(z.record(z.string(), z.any()))]);
|
|
41630
|
-
|
|
41631
37017
|
let FORCE_COLOR,
|
|
41632
37018
|
NODE_DISABLE_COLORS,
|
|
41633
37019
|
NO_COLOR,
|
|
@@ -42570,7 +37956,7 @@ function _loadAgentConfig() {
|
|
|
42570
37956
|
_iterator.f();
|
|
42571
37957
|
return _context6.finish(36);
|
|
42572
37958
|
case 39:
|
|
42573
|
-
result = (deploying ? AgentsConfigurationSchema : AgentsSchema).safeParse(agents);
|
|
37959
|
+
result = (deploying ? macros.AgentsConfigurationSchema : macros.AgentsSchema).safeParse(agents);
|
|
42574
37960
|
if (result.success) {
|
|
42575
37961
|
_context6.next = 43;
|
|
42576
37962
|
break;
|
|
@@ -42626,7 +38012,7 @@ function _loadEntityApiConfig() {
|
|
|
42626
38012
|
config[key] = true;
|
|
42627
38013
|
}
|
|
42628
38014
|
}
|
|
42629
|
-
EntityApiConfigurationSchema.parse(config);
|
|
38015
|
+
macros.EntityApiConfigurationSchema.parse(config);
|
|
42630
38016
|
return _context.abrupt("return", config);
|
|
42631
38017
|
case 14:
|
|
42632
38018
|
return _context.abrupt("return", null);
|
|
@@ -42775,7 +38161,7 @@ function _loadEntitiesConfig() {
|
|
|
42775
38161
|
throw new Error("Invalid entity type (".concat(entityType, ") returned at \"").concat(filePath, "\""));
|
|
42776
38162
|
case 21:
|
|
42777
38163
|
// Validate entity configuration
|
|
42778
|
-
result = EntityConfigurationSchema.safeParse(entityConfig, {
|
|
38164
|
+
result = macros.EntityConfigurationSchema.safeParse(entityConfig, {
|
|
42779
38165
|
path: ['entities', config.length]
|
|
42780
38166
|
});
|
|
42781
38167
|
if (result.success) {
|
|
@@ -42800,7 +38186,7 @@ function _loadEntitiesConfig() {
|
|
|
42800
38186
|
entities: parents.reverse(),
|
|
42801
38187
|
api: api
|
|
42802
38188
|
});
|
|
42803
|
-
EntityRootProjectConfigurationSchema.parse(entityProjectConfig);
|
|
38189
|
+
macros.EntityRootProjectConfigurationSchema.parse(entityProjectConfig);
|
|
42804
38190
|
existingIndex = config.findIndex(function (c) {
|
|
42805
38191
|
return c.entity === entityProjectConfig.entity;
|
|
42806
38192
|
});
|
|
@@ -42865,7 +38251,7 @@ function _loadEntitiesConfig() {
|
|
|
42865
38251
|
throw new Error("Missing required entity: \"entities/customers/[customer]\"");
|
|
42866
38252
|
case 34:
|
|
42867
38253
|
// Validate the config
|
|
42868
|
-
EntitiesRootProjectConfigurationSchema.parse(config);
|
|
38254
|
+
macros.EntitiesRootProjectConfigurationSchema.parse(config);
|
|
42869
38255
|
return _context4.abrupt("return", config);
|
|
42870
38256
|
case 36:
|
|
42871
38257
|
case "end":
|
|
@@ -42924,10 +38310,10 @@ function _loadWorkflowsConfig() {
|
|
|
42924
38310
|
entity: parents[0],
|
|
42925
38311
|
entities: parents.reverse()
|
|
42926
38312
|
};
|
|
42927
|
-
WorkflowConfigurationSchema.parse(workflowConfig);
|
|
38313
|
+
macros.WorkflowConfigurationSchema.parse(workflowConfig);
|
|
42928
38314
|
return workflowConfig;
|
|
42929
38315
|
}); // Validate the config
|
|
42930
|
-
WorkflowsConfigurationSchema.parse(config);
|
|
38316
|
+
macros.WorkflowsConfigurationSchema.parse(config);
|
|
42931
38317
|
return _context.abrupt("return", config);
|
|
42932
38318
|
case 4:
|
|
42933
38319
|
case "end":
|
|
@@ -43053,7 +38439,7 @@ function _loadConfig() {
|
|
|
43053
38439
|
agents: agentsConfig,
|
|
43054
38440
|
workflows: workflowsConfig
|
|
43055
38441
|
}); // Validate the config
|
|
43056
|
-
result = Scout9ProjectBuildConfigSchema.safeParse(projectConfig);
|
|
38442
|
+
result = macros.Scout9ProjectBuildConfigSchema.safeParse(projectConfig);
|
|
43057
38443
|
if (result.success) {
|
|
43058
38444
|
_context.next = 19;
|
|
43059
38445
|
break;
|
|
@@ -48261,51 +43647,8 @@ var Scout9Test = /*#__PURE__*/function () {
|
|
|
48261
43647
|
}();
|
|
48262
43648
|
|
|
48263
43649
|
exports.$ = $$1;
|
|
48264
|
-
exports.AgentConfigurationSchema = AgentConfigurationSchema;
|
|
48265
|
-
exports.AgentSchema = AgentSchema;
|
|
48266
|
-
exports.AgentsConfigurationSchema = AgentsConfigurationSchema;
|
|
48267
|
-
exports.AgentsSchema = AgentsSchema;
|
|
48268
|
-
exports.Baz = Baz;
|
|
48269
|
-
exports.Bus = Bus;
|
|
48270
|
-
exports.ContextExampleSchema = ContextExampleSchema;
|
|
48271
|
-
exports.ContextExampleWithTrainingDataSchema = ContextExampleWithTrainingDataSchema;
|
|
48272
|
-
exports.ConversationAnticipateSchema = ConversationAnticipateSchema;
|
|
48273
|
-
exports.ConversationContext = ConversationContext;
|
|
48274
|
-
exports.ConversationSchema = ConversationSchema;
|
|
48275
|
-
exports.CustomerSchema = CustomerSchema;
|
|
48276
|
-
exports.CustomerValueSchema = CustomerValueSchema;
|
|
48277
|
-
exports.EntitiesRootConfigurationSchema = EntitiesRootConfigurationSchema;
|
|
48278
|
-
exports.EntitiesRootProjectConfigurationSchema = EntitiesRootProjectConfigurationSchema;
|
|
48279
|
-
exports.EntityApiConfigurationSchema = EntityApiConfigurationSchema;
|
|
48280
|
-
exports.EntityConfigurationSchema = EntityConfigurationSchema;
|
|
48281
|
-
exports.EntityRootProjectConfigurationSchema = EntityRootProjectConfigurationSchema;
|
|
48282
|
-
exports.FollowupBaseSchema = FollowupBaseSchema;
|
|
48283
|
-
exports.FollowupSchema = FollowupSchema;
|
|
48284
|
-
exports.ForwardSchema = ForwardSchema;
|
|
48285
|
-
exports.InstructionObjectSchema = InstructionObjectSchema;
|
|
48286
|
-
exports.InstructionSchema = InstructionSchema;
|
|
48287
|
-
exports.IntentWorkflowEventSchema = IntentWorkflowEventSchema;
|
|
48288
|
-
exports.MessageSchema = MessageSchema;
|
|
48289
|
-
exports.PersonaConfigurationSchema = PersonaConfigurationSchema;
|
|
48290
|
-
exports.PersonaSchema = PersonaSchema;
|
|
48291
|
-
exports.PersonasConfigurationSchema = PersonasConfigurationSchema;
|
|
48292
|
-
exports.PersonasSchema = PersonasSchema;
|
|
48293
43650
|
exports.ProgressLogger = ProgressLogger;
|
|
48294
|
-
exports.Scout9ProjectBuildConfigSchema = Scout9ProjectBuildConfigSchema;
|
|
48295
|
-
exports.Scout9ProjectConfigSchema = Scout9ProjectConfigSchema;
|
|
48296
43651
|
exports.Scout9Test = Scout9Test;
|
|
48297
|
-
exports.TestSchema = TestSchema;
|
|
48298
|
-
exports.WorkflowConfigurationSchema = WorkflowConfigurationSchema;
|
|
48299
|
-
exports.WorkflowEventSchema = WorkflowEventSchema;
|
|
48300
|
-
exports.WorkflowFunctionSchema = WorkflowFunctionSchema;
|
|
48301
|
-
exports.WorkflowResponseMessage = WorkflowResponseMessage;
|
|
48302
|
-
exports.WorkflowResponseMessageApiRequest = WorkflowResponseMessageApiRequest;
|
|
48303
|
-
exports.WorkflowResponseMessageApiResponse = WorkflowResponseMessageApiResponse;
|
|
48304
|
-
exports.WorkflowResponseSchema = WorkflowResponseSchema;
|
|
48305
|
-
exports.WorkflowResponseSlotBaseSchema = WorkflowResponseSlotBaseSchema;
|
|
48306
|
-
exports.WorkflowResponseSlotSchema = WorkflowResponseSlotSchema;
|
|
48307
|
-
exports.WorkflowsConfigurationSchema = WorkflowsConfigurationSchema;
|
|
48308
|
-
exports.apiFunctionSchema = apiFunctionSchema;
|
|
48309
43652
|
exports.balancedMatch = balancedMatch;
|
|
48310
43653
|
exports.build = build;
|
|
48311
43654
|
exports.checkVariableType = checkVariableType;
|
|
@@ -48316,10 +43659,7 @@ exports.createMockConversation = createMockConversation;
|
|
|
48316
43659
|
exports.createMockCustomer = createMockCustomer;
|
|
48317
43660
|
exports.createMockMessage = createMockMessage;
|
|
48318
43661
|
exports.createMockWorkflowEvent = createMockWorkflowEvent;
|
|
48319
|
-
exports.deleteApiFunctionSchema = deleteApiFunctionSchema;
|
|
48320
|
-
exports.eventResponseSchema = eventResponseSchema;
|
|
48321
43662
|
exports.forward = forward;
|
|
48322
|
-
exports.getApiFunctionSchema = getApiFunctionSchema;
|
|
48323
43663
|
exports.getAugmentedNamespace = getAugmentedNamespace;
|
|
48324
43664
|
exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
|
|
48325
43665
|
exports.globSync = globSync;
|
|
@@ -48328,13 +43668,8 @@ exports.loadConfig = loadConfig;
|
|
|
48328
43668
|
exports.loadEnvConfig = loadEnvConfig;
|
|
48329
43669
|
exports.loadUserPackageJson = loadUserPackageJson;
|
|
48330
43670
|
exports.logUserValidationError = logUserValidationError;
|
|
48331
|
-
exports.patchApiFunctionSchema = patchApiFunctionSchema;
|
|
48332
|
-
exports.postApiFunctionSchema = postApiFunctionSchema;
|
|
48333
43671
|
exports.projectTemplates = projectTemplates;
|
|
48334
|
-
exports.putApiFunctionSchema = putApiFunctionSchema;
|
|
48335
|
-
exports.queryApiFunctionSchema = queryApiFunctionSchema;
|
|
48336
43672
|
exports.reply = reply;
|
|
48337
43673
|
exports.report = report;
|
|
48338
43674
|
exports.requireOptionalProjectFile = requireOptionalProjectFile;
|
|
48339
43675
|
exports.requireProjectFile = requireProjectFile;
|
|
48340
|
-
exports.z = z;
|