@tankpkg/mcp-server 0.16.5 → 0.16.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/index.js +2572 -957
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -371,79 +371,33 @@ z.object({
|
|
|
371
371
|
skills: z.record(z.string(), lockedSkillSchema$1)
|
|
372
372
|
});
|
|
373
373
|
var __commonJSMin = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
374
|
-
Object.freeze({ status: "aborted" });
|
|
375
|
-
function $constructor(name, initializer, params) {
|
|
376
|
-
function init(inst, def) {
|
|
377
|
-
if (!inst._zod) Object.defineProperty(inst, "_zod", {
|
|
378
|
-
value: {
|
|
379
|
-
def,
|
|
380
|
-
constr: _,
|
|
381
|
-
traits: /* @__PURE__ */ new Set()
|
|
382
|
-
},
|
|
383
|
-
enumerable: false
|
|
384
|
-
});
|
|
385
|
-
if (inst._zod.traits.has(name)) return;
|
|
386
|
-
inst._zod.traits.add(name);
|
|
387
|
-
initializer(inst, def);
|
|
388
|
-
const proto = _.prototype;
|
|
389
|
-
const keys = Object.keys(proto);
|
|
390
|
-
for (let i = 0; i < keys.length; i++) {
|
|
391
|
-
const k = keys[i];
|
|
392
|
-
if (!(k in inst)) inst[k] = proto[k].bind(inst);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
const Parent = params?.Parent ?? Object;
|
|
396
|
-
class Definition extends Parent {}
|
|
397
|
-
Object.defineProperty(Definition, "name", { value: name });
|
|
398
|
-
function _(def) {
|
|
399
|
-
var _a;
|
|
400
|
-
const inst = params?.Parent ? new Definition() : this;
|
|
401
|
-
init(inst, def);
|
|
402
|
-
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
403
|
-
for (const fn of inst._zod.deferred) fn();
|
|
404
|
-
return inst;
|
|
405
|
-
}
|
|
406
|
-
Object.defineProperty(_, "init", { value: init });
|
|
407
|
-
Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
|
|
408
|
-
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
409
|
-
return inst?._zod?.traits?.has(name);
|
|
410
|
-
} });
|
|
411
|
-
Object.defineProperty(_, "name", { value: name });
|
|
412
|
-
return _;
|
|
413
|
-
}
|
|
414
|
-
var $ZodAsyncError = class extends Error {
|
|
415
|
-
constructor() {
|
|
416
|
-
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
417
|
-
}
|
|
418
|
-
};
|
|
419
|
-
var $ZodEncodeError = class extends Error {
|
|
420
|
-
constructor(name) {
|
|
421
|
-
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
422
|
-
this.name = "ZodEncodeError";
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
const globalConfig = {};
|
|
426
|
-
function config(newConfig) {
|
|
427
|
-
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
428
|
-
return globalConfig;
|
|
429
|
-
}
|
|
430
374
|
function getEnumValues(entries) {
|
|
431
375
|
const numericValues = Object.values(entries).filter((v) => typeof v === "number");
|
|
432
376
|
return Object.entries(entries).filter(([k, _]) => numericValues.indexOf(+k) === -1).map(([_, v]) => v);
|
|
433
377
|
}
|
|
378
|
+
function joinValues(array, separator = "|") {
|
|
379
|
+
return array.map((val) => stringifyPrimitive(val)).join(separator);
|
|
380
|
+
}
|
|
434
381
|
function jsonStringifyReplacer(_, value) {
|
|
435
382
|
if (typeof value === "bigint") return value.toString();
|
|
436
383
|
return value;
|
|
437
384
|
}
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
385
|
+
var Cached = class {
|
|
386
|
+
constructor(getter) {
|
|
387
|
+
this._getter = getter;
|
|
388
|
+
this._value = void 0;
|
|
389
|
+
}
|
|
390
|
+
get value() {
|
|
391
|
+
const getter = this._getter;
|
|
392
|
+
if (getter !== void 0) {
|
|
393
|
+
this._value = getter();
|
|
394
|
+
this._getter = void 0;
|
|
444
395
|
}
|
|
445
|
-
|
|
446
|
-
}
|
|
396
|
+
return this._value;
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
function cached(getter) {
|
|
400
|
+
return new Cached(getter);
|
|
447
401
|
}
|
|
448
402
|
function nullish(input) {
|
|
449
403
|
return input === null || input === void 0;
|
|
@@ -454,33 +408,11 @@ function cleanRegex(source) {
|
|
|
454
408
|
return source.slice(start, end);
|
|
455
409
|
}
|
|
456
410
|
function floatSafeRemainder(val, step) {
|
|
457
|
-
const
|
|
458
|
-
const
|
|
459
|
-
|
|
460
|
-
if (
|
|
461
|
-
|
|
462
|
-
if (match?.[1]) stepDecCount = Number.parseInt(match[1]);
|
|
463
|
-
}
|
|
464
|
-
const decCount = valDecCount > stepDecCount ? valDecCount : stepDecCount;
|
|
465
|
-
return Number.parseInt(val.toFixed(decCount).replace(".", "")) % Number.parseInt(step.toFixed(decCount).replace(".", "")) / 10 ** decCount;
|
|
466
|
-
}
|
|
467
|
-
const EVALUATING = Symbol("evaluating");
|
|
468
|
-
function defineLazy(object, key, getter) {
|
|
469
|
-
let value = void 0;
|
|
470
|
-
Object.defineProperty(object, key, {
|
|
471
|
-
get() {
|
|
472
|
-
if (value === EVALUATING) return;
|
|
473
|
-
if (value === void 0) {
|
|
474
|
-
value = EVALUATING;
|
|
475
|
-
value = getter();
|
|
476
|
-
}
|
|
477
|
-
return value;
|
|
478
|
-
},
|
|
479
|
-
set(v) {
|
|
480
|
-
Object.defineProperty(object, key, { value: v });
|
|
481
|
-
},
|
|
482
|
-
configurable: true
|
|
483
|
-
});
|
|
411
|
+
const ratio = val / step;
|
|
412
|
+
const roundedRatio = Math.round(ratio);
|
|
413
|
+
const tolerance = 4 * Number.EPSILON * Math.max(Math.abs(ratio), 1);
|
|
414
|
+
if (Math.abs(ratio - roundedRatio) < tolerance) return 0;
|
|
415
|
+
return ratio - roundedRatio;
|
|
484
416
|
}
|
|
485
417
|
function assignProp(target, prop, value) {
|
|
486
418
|
Object.defineProperty(target, prop, {
|
|
@@ -490,6 +422,58 @@ function assignProp(target, prop, value) {
|
|
|
490
422
|
configurable: true
|
|
491
423
|
});
|
|
492
424
|
}
|
|
425
|
+
/**
|
|
426
|
+
* Whichever object a def's `shape` currently answers from: the one the caller passed until the first read, the frozen copy after it.
|
|
427
|
+
*
|
|
428
|
+
* Its keys and descriptors read without invoking anything, which is what lets a discriminated union check its discriminator, and the cycle walk read a shape, without resolving a getter that references the schema being constructed. A def that answers `shape` from an accessor of its own has none.
|
|
429
|
+
*/
|
|
430
|
+
function rawShape(def) {
|
|
431
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
432
|
+
return desc?.get ? desc.get.raw : desc?.value;
|
|
433
|
+
}
|
|
434
|
+
function sourceShape(schema) {
|
|
435
|
+
return rawShape(schema._zod.def) ?? schema._zod.def.shape;
|
|
436
|
+
}
|
|
437
|
+
function deferProp(target, key, getter) {
|
|
438
|
+
Object.defineProperty(target, key, {
|
|
439
|
+
get() {
|
|
440
|
+
const value = getter();
|
|
441
|
+
assignProp(this, key, value);
|
|
442
|
+
return value;
|
|
443
|
+
},
|
|
444
|
+
enumerable: true,
|
|
445
|
+
configurable: true
|
|
446
|
+
});
|
|
447
|
+
}
|
|
448
|
+
function putProp(target, key, value) {
|
|
449
|
+
if (key in target) assignProp(target, key, value);
|
|
450
|
+
else target[key] = value;
|
|
451
|
+
}
|
|
452
|
+
/**
|
|
453
|
+
* Copies `keys` of `source`'s shape onto `target`, each value passed through `wrap`.
|
|
454
|
+
*
|
|
455
|
+
* A key the source has resolved is copied through now, so the derived shape states it outright and nothing has to resolve it to learn what it holds. A key the source still defers stays deferred, and reads back through the source's own `shape`, so it resolves once and both shapes get that one schema.
|
|
456
|
+
*/
|
|
457
|
+
function mirrorShape(target, source, keys, wrap) {
|
|
458
|
+
const raw = sourceShape(source);
|
|
459
|
+
for (const key of keys) {
|
|
460
|
+
const desc = Object.getOwnPropertyDescriptor(raw, key);
|
|
461
|
+
if (!desc.enumerable) continue;
|
|
462
|
+
if (desc.get) deferProp(target, key, () => {
|
|
463
|
+
const value = source._zod.def.shape[key];
|
|
464
|
+
return wrap ? wrap(value, key) : value;
|
|
465
|
+
});
|
|
466
|
+
else putProp(target, key, wrap ? wrap(desc.value, key) : desc.value);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function mirrorProps(target, source) {
|
|
470
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
471
|
+
const desc = Object.getOwnPropertyDescriptor(source, key);
|
|
472
|
+
if (!desc.enumerable) continue;
|
|
473
|
+
if (desc.get) deferProp(target, key, () => source[key]);
|
|
474
|
+
else putProp(target, key, desc.value);
|
|
475
|
+
}
|
|
476
|
+
}
|
|
493
477
|
function mergeDefs(...defs) {
|
|
494
478
|
const mergedDescriptors = {};
|
|
495
479
|
for (const def of defs) Object.assign(mergedDescriptors, Object.getOwnPropertyDescriptors(def));
|
|
@@ -505,7 +489,8 @@ const captureStackTrace = "captureStackTrace" in Error ? Error.captureStackTrace
|
|
|
505
489
|
function isObject(data) {
|
|
506
490
|
return typeof data === "object" && data !== null && !Array.isArray(data);
|
|
507
491
|
}
|
|
508
|
-
const allowsEval = cached(() => {
|
|
492
|
+
const allowsEval = /* @__PURE__ */ cached(() => {
|
|
493
|
+
if (globalConfig.jitless) return false;
|
|
509
494
|
if (typeof navigator !== "undefined" && navigator?.userAgent?.includes("Cloudflare")) return false;
|
|
510
495
|
try {
|
|
511
496
|
new Function("");
|
|
@@ -527,9 +512,11 @@ function isPlainObject(o) {
|
|
|
527
512
|
function shallowClone(o) {
|
|
528
513
|
if (isPlainObject(o)) return { ...o };
|
|
529
514
|
if (Array.isArray(o)) return [...o];
|
|
515
|
+
if (o instanceof Map) return new Map(o);
|
|
516
|
+
if (o instanceof Set) return new Set(o);
|
|
530
517
|
return o;
|
|
531
518
|
}
|
|
532
|
-
const propertyKeyTypes = new Set([
|
|
519
|
+
const propertyKeyTypes = /* @__PURE__ */ new Set([
|
|
533
520
|
"string",
|
|
534
521
|
"number",
|
|
535
522
|
"symbol"
|
|
@@ -557,9 +544,14 @@ function normalizeParams(_params) {
|
|
|
557
544
|
};
|
|
558
545
|
return params;
|
|
559
546
|
}
|
|
547
|
+
function stringifyPrimitive(value) {
|
|
548
|
+
if (typeof value === "bigint") return value.toString() + "n";
|
|
549
|
+
if (typeof value === "string") return `"${value}"`;
|
|
550
|
+
return `${value}`;
|
|
551
|
+
}
|
|
560
552
|
function optionalKeys(shape) {
|
|
561
553
|
return Object.keys(shape).filter((k) => {
|
|
562
|
-
return shape[k]._zod.optin
|
|
554
|
+
return shape[k]._zod.optin !== void 0 && shape[k]._zod.optout === "optional";
|
|
563
555
|
});
|
|
564
556
|
}
|
|
565
557
|
const NUMBER_FORMAT_RANGES = {
|
|
@@ -569,39 +561,39 @@ const NUMBER_FORMAT_RANGES = {
|
|
|
569
561
|
float32: [-34028234663852886e22, 34028234663852886e22],
|
|
570
562
|
float64: [-Number.MAX_VALUE, Number.MAX_VALUE]
|
|
571
563
|
};
|
|
564
|
+
const BIGINT_FORMAT_RANGES = {
|
|
565
|
+
int64: [/* @__PURE__ */ BigInt("-9223372036854775808"), /* @__PURE__ */ BigInt("9223372036854775807")],
|
|
566
|
+
uint64: [/* @__PURE__ */ BigInt(0), /* @__PURE__ */ BigInt("18446744073709551615")]
|
|
567
|
+
};
|
|
572
568
|
function pick(schema, mask) {
|
|
573
569
|
const currDef = schema._zod.def;
|
|
574
570
|
const checks = currDef.checks;
|
|
575
571
|
if (checks && checks.length > 0) throw new Error(".pick() cannot be used on object schemas containing refinements");
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
if (!(key in currDef.shape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
581
|
-
if (!mask[key]) continue;
|
|
582
|
-
newShape[key] = currDef.shape[key];
|
|
583
|
-
}
|
|
584
|
-
assignProp(this, "shape", newShape);
|
|
585
|
-
return newShape;
|
|
586
|
-
},
|
|
572
|
+
const newShape = {};
|
|
573
|
+
mirrorShape(newShape, schema, maskedKeys(schema, mask));
|
|
574
|
+
return clone(schema, mergeDefs(currDef, {
|
|
575
|
+
shape: newShape,
|
|
587
576
|
checks: []
|
|
588
577
|
}));
|
|
589
578
|
}
|
|
579
|
+
function maskedKeys(schema, mask) {
|
|
580
|
+
const raw = sourceShape(schema);
|
|
581
|
+
const keys = [];
|
|
582
|
+
for (const key of Reflect.ownKeys(mask)) {
|
|
583
|
+
if (!Object.getOwnPropertyDescriptor(raw, key)?.enumerable) throw new Error(`Unrecognized key: "${String(key)}"`);
|
|
584
|
+
if (mask[key]) keys.push(key);
|
|
585
|
+
}
|
|
586
|
+
return keys;
|
|
587
|
+
}
|
|
590
588
|
function omit(schema, mask) {
|
|
591
589
|
const currDef = schema._zod.def;
|
|
592
590
|
const checks = currDef.checks;
|
|
593
591
|
if (checks && checks.length > 0) throw new Error(".omit() cannot be used on object schemas containing refinements");
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
if (!mask[key]) continue;
|
|
600
|
-
delete newShape[key];
|
|
601
|
-
}
|
|
602
|
-
assignProp(this, "shape", newShape);
|
|
603
|
-
return newShape;
|
|
604
|
-
},
|
|
592
|
+
const omitted = new Set(maskedKeys(schema, mask));
|
|
593
|
+
const newShape = {};
|
|
594
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)).filter((key) => !omitted.has(key)));
|
|
595
|
+
return clone(schema, mergeDefs(currDef, {
|
|
596
|
+
shape: newShape,
|
|
605
597
|
checks: []
|
|
606
598
|
}));
|
|
607
599
|
}
|
|
@@ -609,95 +601,68 @@ function extend(schema, shape) {
|
|
|
609
601
|
if (!isPlainObject(shape)) throw new Error("Invalid input to extend: expected a plain object");
|
|
610
602
|
const checks = schema._zod.def.checks;
|
|
611
603
|
if (checks && checks.length > 0) {
|
|
612
|
-
const existingShape = schema
|
|
613
|
-
for (const key
|
|
604
|
+
const existingShape = sourceShape(schema);
|
|
605
|
+
for (const key of Reflect.ownKeys(shape)) if (Object.getOwnPropertyDescriptor(existingShape, key) !== void 0) throw new Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.");
|
|
614
606
|
}
|
|
615
|
-
return clone(schema, mergeDefs(schema._zod.def, {
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
} }));
|
|
607
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
|
|
608
|
+
}
|
|
609
|
+
function extended(schema, shape) {
|
|
610
|
+
const newShape = {};
|
|
611
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)));
|
|
612
|
+
mirrorProps(newShape, shape);
|
|
613
|
+
return newShape;
|
|
623
614
|
}
|
|
624
615
|
function safeExtend(schema, shape) {
|
|
625
616
|
if (!isPlainObject(shape)) throw new Error("Invalid input to safeExtend: expected a plain object");
|
|
626
|
-
return clone(schema, mergeDefs(schema._zod.def, {
|
|
627
|
-
const _shape = {
|
|
628
|
-
...schema._zod.def.shape,
|
|
629
|
-
...shape
|
|
630
|
-
};
|
|
631
|
-
assignProp(this, "shape", _shape);
|
|
632
|
-
return _shape;
|
|
633
|
-
} }));
|
|
617
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: extended(schema, shape) }));
|
|
634
618
|
}
|
|
635
619
|
function merge(a, b) {
|
|
620
|
+
if (!b?._zod?.def) throw new Error("Invalid input to merge: expected an object schema. To merge a plain shape, use `.extend()`.");
|
|
621
|
+
if (a._zod.def.checks?.length) throw new Error(".merge() cannot be used on object schemas containing refinements. Use .safeExtend() instead.");
|
|
622
|
+
const newShape = {};
|
|
623
|
+
mirrorShape(newShape, a, Reflect.ownKeys(sourceShape(a)));
|
|
624
|
+
mirrorShape(newShape, b, Reflect.ownKeys(sourceShape(b)));
|
|
636
625
|
return clone(a, mergeDefs(a._zod.def, {
|
|
637
|
-
|
|
638
|
-
const _shape = {
|
|
639
|
-
...a._zod.def.shape,
|
|
640
|
-
...b._zod.def.shape
|
|
641
|
-
};
|
|
642
|
-
assignProp(this, "shape", _shape);
|
|
643
|
-
return _shape;
|
|
644
|
-
},
|
|
626
|
+
shape: newShape,
|
|
645
627
|
get catchall() {
|
|
646
628
|
return b._zod.def.catchall;
|
|
647
629
|
},
|
|
648
|
-
checks: []
|
|
630
|
+
checks: b._zod.def.checks ?? []
|
|
649
631
|
}));
|
|
650
632
|
}
|
|
651
|
-
function partial(Class, schema, mask) {
|
|
633
|
+
function partial(Class, schema, mask, name = "partial") {
|
|
652
634
|
const checks = schema._zod.def.checks;
|
|
653
|
-
if (checks && checks.length > 0) throw new Error(
|
|
635
|
+
if (checks && checks.length > 0) throw new Error(`.${name}() cannot be used on object schemas containing refinements`);
|
|
636
|
+
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
|
|
637
|
+
const newShape = {};
|
|
638
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), Class && ((value, key) => selected && !selected.has(key) ? value : new Class({
|
|
639
|
+
type: "optional",
|
|
640
|
+
innerType: value
|
|
641
|
+
})));
|
|
654
642
|
return clone(schema, mergeDefs(schema._zod.def, {
|
|
655
|
-
|
|
656
|
-
const oldShape = schema._zod.def.shape;
|
|
657
|
-
const shape = { ...oldShape };
|
|
658
|
-
if (mask) for (const key in mask) {
|
|
659
|
-
if (!(key in oldShape)) throw new Error(`Unrecognized key: "${key}"`);
|
|
660
|
-
if (!mask[key]) continue;
|
|
661
|
-
shape[key] = Class ? new Class({
|
|
662
|
-
type: "optional",
|
|
663
|
-
innerType: oldShape[key]
|
|
664
|
-
}) : oldShape[key];
|
|
665
|
-
}
|
|
666
|
-
else for (const key in oldShape) shape[key] = Class ? new Class({
|
|
667
|
-
type: "optional",
|
|
668
|
-
innerType: oldShape[key]
|
|
669
|
-
}) : oldShape[key];
|
|
670
|
-
assignProp(this, "shape", shape);
|
|
671
|
-
return shape;
|
|
672
|
-
},
|
|
643
|
+
shape: newShape,
|
|
673
644
|
checks: []
|
|
674
645
|
}));
|
|
675
646
|
}
|
|
676
647
|
function required(Class, schema, mask) {
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
type: "nonoptional",
|
|
685
|
-
innerType: oldShape[key]
|
|
686
|
-
});
|
|
687
|
-
}
|
|
688
|
-
else for (const key in oldShape) shape[key] = new Class({
|
|
689
|
-
type: "nonoptional",
|
|
690
|
-
innerType: oldShape[key]
|
|
691
|
-
});
|
|
692
|
-
assignProp(this, "shape", shape);
|
|
693
|
-
return shape;
|
|
694
|
-
} }));
|
|
648
|
+
const selected = mask ? new Set(maskedKeys(schema, mask)) : void 0;
|
|
649
|
+
const newShape = {};
|
|
650
|
+
mirrorShape(newShape, schema, Reflect.ownKeys(sourceShape(schema)), (value, key) => selected && !selected.has(key) ? value : new Class({
|
|
651
|
+
type: "nonoptional",
|
|
652
|
+
innerType: value
|
|
653
|
+
}));
|
|
654
|
+
return clone(schema, mergeDefs(schema._zod.def, { shape: newShape }));
|
|
695
655
|
}
|
|
696
656
|
function aborted(x, startIndex = 0) {
|
|
697
657
|
if (x.aborted === true) return true;
|
|
698
658
|
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue !== true) return true;
|
|
699
659
|
return false;
|
|
700
660
|
}
|
|
661
|
+
function explicitlyAborted(x, startIndex = 0) {
|
|
662
|
+
if (x.aborted === true) return true;
|
|
663
|
+
for (let i = startIndex; i < x.issues.length; i++) if (x.issues[i]?.continue === false) return true;
|
|
664
|
+
return false;
|
|
665
|
+
}
|
|
701
666
|
function prefixIssues(path, issues) {
|
|
702
667
|
return issues.map((iss) => {
|
|
703
668
|
var _a;
|
|
@@ -709,22 +674,67 @@ function prefixIssues(path, issues) {
|
|
|
709
674
|
function unwrapMessage(message) {
|
|
710
675
|
return typeof message === "string" ? message : message?.message;
|
|
711
676
|
}
|
|
677
|
+
/** The leading size checks of `defChecks` that set an upper bound, each paired with it. */
|
|
678
|
+
function sizeCaps(defChecks) {
|
|
679
|
+
const caps = [];
|
|
680
|
+
for (const ch of defChecks ?? []) {
|
|
681
|
+
const d = ch._zod.def;
|
|
682
|
+
if (!/_(length|size)$|_equals$/.test(d.check)) break;
|
|
683
|
+
const max = d.maximum ?? d.length ?? d.size;
|
|
684
|
+
if (max >= 0) caps.push([max, ch]);
|
|
685
|
+
}
|
|
686
|
+
return caps;
|
|
687
|
+
}
|
|
688
|
+
function attachSchema(issues, start, inst) {
|
|
689
|
+
var _a;
|
|
690
|
+
for (let i = start; i < issues.length; i++) (_a = issues[i]).schema ?? (_a.schema = inst);
|
|
691
|
+
}
|
|
712
692
|
function finalizeIssue(iss, ctx, config) {
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
693
|
+
var _a;
|
|
694
|
+
const traits = iss.inst?._zod?.traits;
|
|
695
|
+
if (traits?.has("$ZodType")) if (traits.has("$ZodCheck")) (_a = iss).schema ?? (_a.schema = iss.inst);
|
|
696
|
+
else iss.schema = iss.inst;
|
|
697
|
+
const schemaError = iss.schema !== iss.inst ? iss.schema?._zod.def?.error : void 0;
|
|
698
|
+
const message = iss.message ? iss.message : unwrapMessage(iss.inst?._zod.def?.error?.(iss)) ?? unwrapMessage(schemaError?.(iss)) ?? unwrapMessage(ctx?.error?.(iss)) ?? unwrapMessage(config.customError?.(iss)) ?? unwrapMessage(config.localeError?.(iss)) ?? "Invalid input";
|
|
699
|
+
const full = {};
|
|
700
|
+
for (const k of Object.keys(iss)) {
|
|
701
|
+
if (k === "inst" || k === "schema" || k === "continue" || k === "input" || k === "__proto__") continue;
|
|
702
|
+
full[k] = iss[k];
|
|
703
|
+
}
|
|
704
|
+
full.path ?? (full.path = []);
|
|
705
|
+
full.message = message;
|
|
706
|
+
if (ctx?.reportInput) full.input = iss.input;
|
|
721
707
|
return full;
|
|
722
708
|
}
|
|
709
|
+
const highSurrogate = /[\uD800-\uDBFF]/;
|
|
710
|
+
function codePointLength(str) {
|
|
711
|
+
const units = str.length;
|
|
712
|
+
if (!highSurrogate.test(str)) return units;
|
|
713
|
+
let count = units;
|
|
714
|
+
for (let i = 0; i < units - 1; i++) if ((str.charCodeAt(i) & 64512) === 55296 && (str.charCodeAt(i + 1) & 64512) === 56320) {
|
|
715
|
+
count--;
|
|
716
|
+
i++;
|
|
717
|
+
}
|
|
718
|
+
return count;
|
|
719
|
+
}
|
|
723
720
|
function getLengthableOrigin(input) {
|
|
724
721
|
if (Array.isArray(input)) return "array";
|
|
725
722
|
if (typeof input === "string") return "string";
|
|
726
723
|
return "unknown";
|
|
727
724
|
}
|
|
725
|
+
function parsedType(data) {
|
|
726
|
+
const t = typeof data;
|
|
727
|
+
switch (t) {
|
|
728
|
+
case "number": return Number.isNaN(data) ? "nan" : "number";
|
|
729
|
+
case "object": {
|
|
730
|
+
if (data === null) return "null";
|
|
731
|
+
if (Array.isArray(data)) return "array";
|
|
732
|
+
const obj = data;
|
|
733
|
+
if (obj && Object.getPrototypeOf(obj) !== Object.prototype && "constructor" in obj && obj.constructor) return obj.constructor.name;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return t;
|
|
737
|
+
}
|
|
728
738
|
function issue(...args) {
|
|
729
739
|
const [iss, input, inst] = args;
|
|
730
740
|
if (typeof iss === "string") return {
|
|
@@ -735,31 +745,333 @@ function issue(...args) {
|
|
|
735
745
|
};
|
|
736
746
|
return { ...iss };
|
|
737
747
|
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
748
|
+
/**
|
|
749
|
+
* Installs a trait's members on its prototype. Each value builds that member for the instance on first read; the built value shadows the accessor as an own property, so a detached `const { parse } = schema` keeps working.
|
|
750
|
+
*
|
|
751
|
+
* Call this from a `proto` initializer, which runs once per prototype — never per instance.
|
|
752
|
+
*/
|
|
753
|
+
function members(proto, table) {
|
|
754
|
+
for (const key in table) {
|
|
755
|
+
const desc = Object.getOwnPropertyDescriptor(table, key);
|
|
756
|
+
if (desc.get) Object.defineProperty(proto, key, {
|
|
757
|
+
...desc,
|
|
758
|
+
enumerable: false
|
|
759
|
+
});
|
|
760
|
+
else defineBound(proto, key, desc.value);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/** Shadows a prototype member with an own value, so a getter that builds from the instance runs once. */
|
|
764
|
+
function own(inst, key, value, enumerable = true) {
|
|
765
|
+
Object.defineProperty(inst, key, {
|
|
766
|
+
configurable: true,
|
|
767
|
+
writable: true,
|
|
768
|
+
enumerable,
|
|
769
|
+
value
|
|
743
770
|
});
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
771
|
+
return value;
|
|
772
|
+
}
|
|
773
|
+
/** Like {@link own}, for a member that was never an own data property and has to stay out of `Object.keys`. */
|
|
774
|
+
function hide(inst, key, value) {
|
|
775
|
+
return own(inst, key, value, false);
|
|
776
|
+
}
|
|
777
|
+
/** Adds members a table derives from the instance: each builds on first read and shadows as own data, and assignment shadows the same way, as when these were own properties. */
|
|
778
|
+
function derived(computes, table) {
|
|
779
|
+
for (const key in computes) {
|
|
780
|
+
const compute = computes[key];
|
|
781
|
+
Object.defineProperty(table, key, {
|
|
782
|
+
configurable: true,
|
|
783
|
+
enumerable: true,
|
|
784
|
+
get() {
|
|
785
|
+
return own(this, key, compute(this));
|
|
786
|
+
},
|
|
787
|
+
set(value) {
|
|
788
|
+
own(this, key, value);
|
|
789
|
+
}
|
|
790
|
+
});
|
|
791
|
+
}
|
|
792
|
+
return table;
|
|
793
|
+
}
|
|
794
|
+
function defineBound(proto, key, fn) {
|
|
795
|
+
Object.defineProperty(proto, key, {
|
|
796
|
+
configurable: true,
|
|
797
|
+
get() {
|
|
798
|
+
return this == null ? fn : own(this, key, fn.bind(this));
|
|
799
|
+
},
|
|
800
|
+
set(value) {
|
|
801
|
+
own(this, key, value);
|
|
802
|
+
}
|
|
747
803
|
});
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
804
|
+
}
|
|
805
|
+
/** Returns the prototype to install on, or `undefined` if this group is already installed on it. */
|
|
806
|
+
function claim(inst, sentinel) {
|
|
807
|
+
const proto = Object.getPrototypeOf(inst);
|
|
808
|
+
return sentinel in proto ? void 0 : proto;
|
|
809
|
+
}
|
|
810
|
+
let installing;
|
|
811
|
+
let broke = false;
|
|
812
|
+
const breaker = {
|
|
813
|
+
configurable: true,
|
|
814
|
+
get() {
|
|
815
|
+
broke = true;
|
|
816
|
+
}
|
|
817
|
+
};
|
|
818
|
+
/**
|
|
819
|
+
* Installs a lazily-derived internal on the `_zod` prototype of `inst`'s
|
|
820
|
+
* constructor, computed from the internals object itself and cached there on
|
|
821
|
+
* first read. One accessor per constructor rather than one per instance.
|
|
822
|
+
*/
|
|
823
|
+
function defineLazyInternal(inst, key, compute) {
|
|
824
|
+
const proto = Object.getPrototypeOf(inst._zod);
|
|
825
|
+
if (key in proto && installing !== inst._zod) {
|
|
826
|
+
installing = void 0;
|
|
827
|
+
return;
|
|
828
|
+
}
|
|
829
|
+
installing = inst._zod;
|
|
830
|
+
Object.defineProperty(proto, key, {
|
|
831
|
+
configurable: true,
|
|
832
|
+
get() {
|
|
833
|
+
Object.defineProperty(this, key, breaker);
|
|
834
|
+
const outer = broke;
|
|
835
|
+
broke = false;
|
|
836
|
+
try {
|
|
837
|
+
const value = compute(this);
|
|
838
|
+
if (broke) delete this[key];
|
|
839
|
+
else Object.defineProperty(this, key, {
|
|
840
|
+
configurable: true,
|
|
841
|
+
writable: true,
|
|
842
|
+
value
|
|
843
|
+
});
|
|
844
|
+
broke = broke || outer;
|
|
845
|
+
return value;
|
|
846
|
+
} catch (err) {
|
|
847
|
+
delete this[key];
|
|
848
|
+
broke = broke || outer;
|
|
849
|
+
throw err;
|
|
850
|
+
}
|
|
851
|
+
},
|
|
852
|
+
set(value) {
|
|
853
|
+
Object.defineProperty(this, key, {
|
|
854
|
+
configurable: true,
|
|
855
|
+
writable: true,
|
|
856
|
+
value
|
|
857
|
+
});
|
|
858
|
+
}
|
|
752
859
|
});
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Installs `key` on `inst`'s prototype, computed by `make` on first read and cached there as an own
|
|
863
|
+
* data property. One accessor per constructor rather than one per instance, because an own accessor
|
|
864
|
+
* puts every instance after the first into v8 dictionary mode. The key doubles as the sentinel.
|
|
865
|
+
*/
|
|
866
|
+
function installLazyProp(inst, key, make, enumerable) {
|
|
867
|
+
const proto = claim(inst, key);
|
|
868
|
+
if (!proto) return;
|
|
869
|
+
Object.defineProperty(proto, key, {
|
|
870
|
+
configurable: true,
|
|
871
|
+
get() {
|
|
872
|
+
const desc = {
|
|
873
|
+
configurable: true,
|
|
874
|
+
writable: true,
|
|
875
|
+
enumerable,
|
|
876
|
+
value: void 0
|
|
877
|
+
};
|
|
878
|
+
Object.defineProperty(this, key, desc);
|
|
879
|
+
desc.value = make(this);
|
|
880
|
+
Object.defineProperty(this, key, desc);
|
|
881
|
+
return desc.value;
|
|
882
|
+
},
|
|
883
|
+
set(value) {
|
|
884
|
+
Object.defineProperty(this, key, {
|
|
885
|
+
configurable: true,
|
|
886
|
+
writable: true,
|
|
887
|
+
enumerable,
|
|
888
|
+
value
|
|
889
|
+
});
|
|
890
|
+
}
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
/** Marks the thunk `_catch` synthesises for a constant catch value. `Function.length` cannot tell that thunk from a user callback — rest and defaulted parameters both report arity 0 — and a user callback reads `ctx.error`, whose issues only finalize correctly against the caller's per-parse error map. Provenance can say what arity cannot. A plain string key rather than `Symbol.for`, whose call at module scope no bundler can prove pure — the same shape that anchored `urlCanParse` into every build. */
|
|
894
|
+
const CONSTANT_CATCH = "~constantCatch";
|
|
895
|
+
/** Wraps a constant catch value in a thunk tagged with {@link CONSTANT_CATCH}. */
|
|
896
|
+
function constantCatch(value) {
|
|
897
|
+
const fn = () => value;
|
|
898
|
+
fn[CONSTANT_CATCH] = true;
|
|
899
|
+
return fn;
|
|
900
|
+
}
|
|
901
|
+
var _a$1;
|
|
902
|
+
const _zodDesc = {
|
|
903
|
+
value: void 0,
|
|
904
|
+
enumerable: false
|
|
905
|
+
};
|
|
906
|
+
let _E = "captureStackTrace" in Error ? Error : null;
|
|
907
|
+
function newError(Definition) {
|
|
908
|
+
const E = _E;
|
|
909
|
+
if (E) {
|
|
910
|
+
const saved = E.stackTraceLimit;
|
|
911
|
+
if (typeof saved === "number") {
|
|
912
|
+
try {
|
|
913
|
+
E.stackTraceLimit = 0;
|
|
914
|
+
} catch {
|
|
915
|
+
_E = null;
|
|
916
|
+
return new Definition();
|
|
917
|
+
}
|
|
918
|
+
try {
|
|
919
|
+
return new Definition();
|
|
920
|
+
} finally {
|
|
921
|
+
E.stackTraceLimit = saved;
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
return new Definition();
|
|
926
|
+
}
|
|
927
|
+
function $constructor(name, initializer, proto, params) {
|
|
928
|
+
const zodProto = {};
|
|
929
|
+
function Internals(def) {
|
|
930
|
+
this.def = def;
|
|
931
|
+
this.constr = _;
|
|
932
|
+
this.traits = /* @__PURE__ */ new Set();
|
|
933
|
+
}
|
|
934
|
+
Internals.prototype = zodProto;
|
|
935
|
+
const protoMembers = proto;
|
|
936
|
+
const initialized = protoMembers && /* @__PURE__ */ new WeakSet();
|
|
937
|
+
function init(inst, def) {
|
|
938
|
+
if (!inst._zod) {
|
|
939
|
+
_zodDesc.value = new Internals(def);
|
|
940
|
+
try {
|
|
941
|
+
Object.defineProperty(inst, "_zod", _zodDesc);
|
|
942
|
+
} finally {
|
|
943
|
+
_zodDesc.value = void 0;
|
|
944
|
+
}
|
|
945
|
+
} else if (inst._zod.traits.has(name)) return;
|
|
946
|
+
inst._zod.traits.add(name);
|
|
947
|
+
initializer(inst, def);
|
|
948
|
+
if (initialized) {
|
|
949
|
+
const own = Object.getPrototypeOf(inst);
|
|
950
|
+
const ctorProto = inst._zod.constr.prototype;
|
|
951
|
+
let up = own;
|
|
952
|
+
while (up && up !== ctorProto) up = Object.getPrototypeOf(up);
|
|
953
|
+
const target = up ?? own;
|
|
954
|
+
if (!initialized.has(target)) {
|
|
955
|
+
initialized.add(target);
|
|
956
|
+
members(target, protoMembers);
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
const proto = _.prototype;
|
|
960
|
+
for (const k in proto) {
|
|
961
|
+
if (!Object.prototype.hasOwnProperty.call(proto, k)) continue;
|
|
962
|
+
if (!(k in inst)) inst[k] = proto[k].bind(inst);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
const Parent = params?.Parent ?? Object;
|
|
966
|
+
class Definition extends Parent {}
|
|
967
|
+
Object.defineProperty(Definition, "name", { value: name });
|
|
968
|
+
function _(def) {
|
|
969
|
+
const inst = params?.Parent ? newError(Definition) : this;
|
|
970
|
+
init(inst, def);
|
|
971
|
+
const deferred = inst._zod.deferred;
|
|
972
|
+
if (deferred) {
|
|
973
|
+
for (const fn of deferred) fn();
|
|
974
|
+
inst._zod.deferred = void 0;
|
|
975
|
+
}
|
|
976
|
+
const pp = globalThis.__zod_globalConfig?.postProcessor;
|
|
977
|
+
if (pp) pp(inst);
|
|
978
|
+
return inst;
|
|
979
|
+
}
|
|
980
|
+
Object.defineProperty(_, "init", { value: init });
|
|
981
|
+
Object.defineProperty(_, Symbol.hasInstance, { value: (inst) => {
|
|
982
|
+
if (params?.Parent && inst instanceof params.Parent) return true;
|
|
983
|
+
return inst?._zod?.traits?.has(name);
|
|
984
|
+
} });
|
|
985
|
+
Object.defineProperty(_, "name", { value: name });
|
|
986
|
+
return _;
|
|
987
|
+
}
|
|
988
|
+
var $ZodAsyncError = class extends Error {
|
|
989
|
+
constructor() {
|
|
990
|
+
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
991
|
+
}
|
|
992
|
+
};
|
|
993
|
+
var $ZodEncodeError = class extends Error {
|
|
994
|
+
constructor(name) {
|
|
995
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
996
|
+
this.name = "ZodEncodeError";
|
|
997
|
+
}
|
|
998
|
+
};
|
|
999
|
+
(_a$1 = globalThis).__zod_globalConfig ?? (_a$1.__zod_globalConfig = {});
|
|
1000
|
+
const globalConfig = globalThis.__zod_globalConfig;
|
|
1001
|
+
function config(newConfig) {
|
|
1002
|
+
if (newConfig) Object.assign(globalConfig, newConfig);
|
|
1003
|
+
return globalConfig;
|
|
1004
|
+
}
|
|
1005
|
+
function _getMessage() {
|
|
1006
|
+
const internals = this._zod;
|
|
1007
|
+
internals.message ?? (internals.message = JSON.stringify(internals.def, jsonStringifyReplacer, 2));
|
|
1008
|
+
return internals.message;
|
|
1009
|
+
}
|
|
1010
|
+
function _setMessage(value) {
|
|
1011
|
+
this._zod.message = value;
|
|
1012
|
+
}
|
|
1013
|
+
const _messageDesc = {
|
|
1014
|
+
get: _getMessage,
|
|
1015
|
+
set: _setMessage,
|
|
1016
|
+
enumerable: true,
|
|
1017
|
+
configurable: true
|
|
1018
|
+
};
|
|
1019
|
+
const _issuesDesc = {
|
|
1020
|
+
value: void 0,
|
|
1021
|
+
enumerable: false
|
|
1022
|
+
};
|
|
1023
|
+
const _installedToString = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
|
|
1024
|
+
const initializer$1 = (inst, def) => {
|
|
1025
|
+
inst.name = "$ZodError";
|
|
1026
|
+
_issuesDesc.value = def;
|
|
1027
|
+
Object.defineProperty(inst, "issues", _issuesDesc);
|
|
1028
|
+
_issuesDesc.value = void 0;
|
|
1029
|
+
Object.defineProperty(inst, "message", _messageDesc);
|
|
1030
|
+
const proto = Object.getPrototypeOf(inst);
|
|
1031
|
+
if (!_installedToString.has(proto)) {
|
|
1032
|
+
_installedToString.add(proto);
|
|
1033
|
+
Object.defineProperty(proto, "toString", {
|
|
1034
|
+
configurable: true,
|
|
1035
|
+
enumerable: false,
|
|
1036
|
+
get() {
|
|
1037
|
+
const value = () => this.message;
|
|
1038
|
+
Object.defineProperty(this, "toString", {
|
|
1039
|
+
value,
|
|
1040
|
+
configurable: true,
|
|
1041
|
+
writable: true
|
|
1042
|
+
});
|
|
1043
|
+
return value;
|
|
1044
|
+
},
|
|
1045
|
+
set(value) {
|
|
1046
|
+
Object.defineProperty(this, "toString", {
|
|
1047
|
+
value,
|
|
1048
|
+
configurable: true,
|
|
1049
|
+
writable: true
|
|
1050
|
+
});
|
|
1051
|
+
}
|
|
1052
|
+
});
|
|
1053
|
+
}
|
|
753
1054
|
};
|
|
754
1055
|
const $ZodError = $constructor("$ZodError", initializer$1);
|
|
755
|
-
|
|
1056
|
+
$constructor("$ZodError", initializer$1, void 0, { Parent: Error });
|
|
1057
|
+
/** Get-or-create `obj[key]` as an own data property. A path segment naming an inherited member
|
|
1058
|
+
* ("toString", "constructor") would otherwise read through to the prototype, and assigning
|
|
1059
|
+
* "__proto__" would hit the setter instead of creating a key. */
|
|
1060
|
+
function node(obj, key, make) {
|
|
1061
|
+
if (!Object.prototype.hasOwnProperty.call(obj, key)) if (key === "__proto__") Object.defineProperty(obj, key, {
|
|
1062
|
+
value: make(),
|
|
1063
|
+
writable: true,
|
|
1064
|
+
enumerable: true,
|
|
1065
|
+
configurable: true
|
|
1066
|
+
});
|
|
1067
|
+
else obj[key] = make();
|
|
1068
|
+
return obj[key];
|
|
1069
|
+
}
|
|
756
1070
|
function flattenError(error, mapper = (issue) => issue.message) {
|
|
757
1071
|
const fieldErrors = {};
|
|
758
1072
|
const formErrors = [];
|
|
759
|
-
for (const sub of error.issues) if (sub.path.length > 0)
|
|
760
|
-
|
|
761
|
-
fieldErrors[sub.path[0]].push(mapper(sub));
|
|
762
|
-
} else formErrors.push(mapper(sub));
|
|
1073
|
+
for (const sub of error.issues) if (sub.path.length > 0) node(fieldErrors, sub.path[0], () => []).push(mapper(sub));
|
|
1074
|
+
else formErrors.push(mapper(sub));
|
|
763
1075
|
return {
|
|
764
1076
|
formErrors,
|
|
765
1077
|
fieldErrors
|
|
@@ -767,56 +1079,86 @@ function flattenError(error, mapper = (issue) => issue.message) {
|
|
|
767
1079
|
}
|
|
768
1080
|
function formatError(error, mapper = (issue) => issue.message) {
|
|
769
1081
|
const fieldErrors = { _errors: [] };
|
|
770
|
-
const processError = (error) => {
|
|
771
|
-
for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }));
|
|
772
|
-
else if (issue.code === "invalid_key") processError({ issues: issue.issues });
|
|
773
|
-
else if (issue.code === "invalid_element") processError({ issues: issue.issues });
|
|
774
|
-
else if (issue.path.length === 0) fieldErrors._errors.push(mapper(issue));
|
|
1082
|
+
const processError = (error, path = []) => {
|
|
1083
|
+
for (const issue of error.issues) if (issue.code === "invalid_union" && issue.errors.length) issue.errors.map((issues) => processError({ issues }, [...path, ...issue.path]));
|
|
1084
|
+
else if (issue.code === "invalid_key") processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
1085
|
+
else if (issue.code === "invalid_element") processError({ issues: issue.issues }, [...path, ...issue.path]);
|
|
775
1086
|
else {
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
1087
|
+
const fullpath = [...path, ...issue.path];
|
|
1088
|
+
if (fullpath.length === 0) fieldErrors._errors.push(mapper(issue));
|
|
1089
|
+
else {
|
|
1090
|
+
let curr = fieldErrors;
|
|
1091
|
+
let i = 0;
|
|
1092
|
+
while (i < fullpath.length) {
|
|
1093
|
+
const el = fullpath[i];
|
|
1094
|
+
const terminal = i === fullpath.length - 1;
|
|
1095
|
+
if (el === "_errors") {
|
|
1096
|
+
if (terminal) curr._errors.push(mapper(issue));
|
|
1097
|
+
i++;
|
|
1098
|
+
continue;
|
|
1099
|
+
}
|
|
1100
|
+
if (!Object.prototype.hasOwnProperty.call(curr, el)) Object.defineProperty(curr, el, {
|
|
1101
|
+
value: { _errors: [] },
|
|
1102
|
+
enumerable: true,
|
|
1103
|
+
writable: true,
|
|
1104
|
+
configurable: true
|
|
1105
|
+
});
|
|
1106
|
+
const node = curr[el];
|
|
1107
|
+
if (terminal) node._errors.push(mapper(issue));
|
|
1108
|
+
curr = node;
|
|
1109
|
+
i++;
|
|
784
1110
|
}
|
|
785
|
-
curr = curr[el];
|
|
786
|
-
i++;
|
|
787
1111
|
}
|
|
788
1112
|
}
|
|
789
1113
|
};
|
|
790
1114
|
processError(error);
|
|
791
1115
|
return fieldErrors;
|
|
792
1116
|
}
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
const
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
1117
|
+
function finalizeParams(callee, params) {
|
|
1118
|
+
return {
|
|
1119
|
+
callee: params?.callee ?? callee,
|
|
1120
|
+
Err: params?.Err
|
|
1121
|
+
};
|
|
1122
|
+
}
|
|
1123
|
+
const _parse = (_Err) => {
|
|
1124
|
+
const fn = (schema, value, _ctx, _params) => {
|
|
1125
|
+
const ctx = _ctx ? {
|
|
1126
|
+
..._ctx,
|
|
1127
|
+
async: false
|
|
1128
|
+
} : { async: false };
|
|
1129
|
+
const result = schema._zod.run({
|
|
1130
|
+
value,
|
|
1131
|
+
issues: []
|
|
1132
|
+
}, ctx);
|
|
1133
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
1134
|
+
if (result.issues.length) {
|
|
1135
|
+
const e = new (_params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
1136
|
+
captureStackTrace(e, _params?.callee ?? fn);
|
|
1137
|
+
throw e;
|
|
1138
|
+
}
|
|
1139
|
+
return result.value;
|
|
1140
|
+
};
|
|
1141
|
+
return fn;
|
|
806
1142
|
};
|
|
807
|
-
const _parseAsync = (_Err) =>
|
|
808
|
-
const
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
1143
|
+
const _parseAsync = (_Err) => {
|
|
1144
|
+
const fn = async (schema, value, _ctx, params) => {
|
|
1145
|
+
const ctx = _ctx ? {
|
|
1146
|
+
..._ctx,
|
|
1147
|
+
async: true
|
|
1148
|
+
} : { async: true };
|
|
1149
|
+
let result = schema._zod.run({
|
|
1150
|
+
value,
|
|
1151
|
+
issues: []
|
|
1152
|
+
}, ctx);
|
|
1153
|
+
if (result instanceof Promise) result = await result;
|
|
1154
|
+
if (result.issues.length) {
|
|
1155
|
+
const e = new (params?.Err ?? _Err)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
1156
|
+
captureStackTrace(e, params?.callee ?? fn);
|
|
1157
|
+
throw e;
|
|
1158
|
+
}
|
|
1159
|
+
return result.value;
|
|
1160
|
+
};
|
|
1161
|
+
return fn;
|
|
820
1162
|
};
|
|
821
1163
|
const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
822
1164
|
const ctx = _ctx ? {
|
|
@@ -828,67 +1170,165 @@ const _safeParse = (_Err) => (schema, value, _ctx) => {
|
|
|
828
1170
|
issues: []
|
|
829
1171
|
}, ctx);
|
|
830
1172
|
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
831
|
-
return result.issues.length ? {
|
|
832
|
-
success: false,
|
|
833
|
-
error: new (_Err ?? $ZodError)(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
834
|
-
} : {
|
|
1173
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : {
|
|
835
1174
|
success: true,
|
|
836
1175
|
data: result.value
|
|
837
1176
|
};
|
|
838
1177
|
};
|
|
839
|
-
|
|
1178
|
+
function failure(Err, issues, ctx) {
|
|
1179
|
+
let error;
|
|
1180
|
+
return {
|
|
1181
|
+
success: false,
|
|
1182
|
+
get error() {
|
|
1183
|
+
if (!error) {
|
|
1184
|
+
error = new Err(issues.map((iss) => finalizeIssue(iss, ctx, config())));
|
|
1185
|
+
issues = void 0;
|
|
1186
|
+
ctx = void 0;
|
|
1187
|
+
}
|
|
1188
|
+
return error;
|
|
1189
|
+
},
|
|
1190
|
+
set error(e) {
|
|
1191
|
+
error = e;
|
|
1192
|
+
issues = void 0;
|
|
1193
|
+
ctx = void 0;
|
|
1194
|
+
}
|
|
1195
|
+
};
|
|
1196
|
+
}
|
|
840
1197
|
const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
841
|
-
const ctx = _ctx ?
|
|
1198
|
+
const ctx = _ctx ? {
|
|
1199
|
+
..._ctx,
|
|
1200
|
+
async: true
|
|
1201
|
+
} : { async: true };
|
|
842
1202
|
let result = schema._zod.run({
|
|
843
1203
|
value,
|
|
844
1204
|
issues: []
|
|
845
1205
|
}, ctx);
|
|
846
1206
|
if (result instanceof Promise) result = await result;
|
|
847
|
-
return result.issues.length ? {
|
|
848
|
-
success: false,
|
|
849
|
-
error: new _Err(result.issues.map((iss) => finalizeIssue(iss, ctx, config())))
|
|
850
|
-
} : {
|
|
1207
|
+
return result.issues.length ? failure(_Err, result.issues, ctx) : {
|
|
851
1208
|
success: true,
|
|
852
1209
|
data: result.value
|
|
853
1210
|
};
|
|
854
1211
|
};
|
|
855
|
-
const
|
|
856
|
-
const
|
|
857
|
-
|
|
858
|
-
|
|
1212
|
+
const COMPILE_INVALID = /* @__PURE__ */ Symbol.for("zod.compile.invalid");
|
|
1213
|
+
const COMPILE_FALLBACK = /* @__PURE__ */ Symbol.for("zod.compile.fallback");
|
|
1214
|
+
const validate = ((schema, value, _ctx) => {
|
|
1215
|
+
const validator = schema._zod.bag.validator;
|
|
1216
|
+
if (validator !== void 0) {
|
|
1217
|
+
if (validator(value) !== COMPILE_INVALID) return true;
|
|
1218
|
+
if (validator.definite === true && _ctx === void 0) return false;
|
|
1219
|
+
}
|
|
1220
|
+
return validateFallback(schema, value, _ctx);
|
|
1221
|
+
});
|
|
1222
|
+
function validateFallback(schema, value, _ctx) {
|
|
1223
|
+
const ctx = _ctx ? {
|
|
1224
|
+
..._ctx,
|
|
1225
|
+
async: false,
|
|
1226
|
+
abortEarly: true
|
|
1227
|
+
} : {
|
|
1228
|
+
async: false,
|
|
1229
|
+
abortEarly: true
|
|
1230
|
+
};
|
|
1231
|
+
const fallbackRun = schema._zod.bag.fallbackRun;
|
|
1232
|
+
let result;
|
|
1233
|
+
if (fallbackRun) {
|
|
1234
|
+
ctx[COMPILE_FALLBACK] = true;
|
|
1235
|
+
result = fallbackRun({
|
|
1236
|
+
value,
|
|
1237
|
+
issues: []
|
|
1238
|
+
}, ctx);
|
|
1239
|
+
} else result = schema._zod.run({
|
|
1240
|
+
value,
|
|
1241
|
+
issues: []
|
|
1242
|
+
}, ctx);
|
|
1243
|
+
if (result instanceof Promise) throw new $ZodAsyncError();
|
|
1244
|
+
return result.issues.length === 0;
|
|
1245
|
+
}
|
|
1246
|
+
const validateAsync$1 = async (schema, value, _ctx) => {
|
|
1247
|
+
const ctx = _ctx ? {
|
|
1248
|
+
..._ctx,
|
|
1249
|
+
async: true,
|
|
1250
|
+
abortEarly: true
|
|
1251
|
+
} : {
|
|
1252
|
+
async: true,
|
|
1253
|
+
abortEarly: true
|
|
1254
|
+
};
|
|
1255
|
+
let result = schema._zod.run({
|
|
1256
|
+
value,
|
|
1257
|
+
issues: []
|
|
1258
|
+
}, ctx);
|
|
1259
|
+
if (result instanceof Promise) result = await result;
|
|
1260
|
+
return result.issues.length === 0;
|
|
859
1261
|
};
|
|
860
|
-
const
|
|
861
|
-
|
|
1262
|
+
const _encode = (_Err) => {
|
|
1263
|
+
const parse = _parse(_Err);
|
|
1264
|
+
const fn = (schema, value, _ctx, _params) => {
|
|
1265
|
+
return parse(schema, value, _ctx ? {
|
|
1266
|
+
..._ctx,
|
|
1267
|
+
direction: "backward"
|
|
1268
|
+
} : { direction: "backward" }, finalizeParams(fn, _params));
|
|
1269
|
+
};
|
|
1270
|
+
return fn;
|
|
862
1271
|
};
|
|
863
|
-
const
|
|
864
|
-
const
|
|
865
|
-
|
|
1272
|
+
const _decode = (_Err) => {
|
|
1273
|
+
const parse = _parse(_Err);
|
|
1274
|
+
const fn = (schema, value, _ctx, _params) => {
|
|
1275
|
+
return parse(schema, value, _ctx, finalizeParams(fn, _params));
|
|
1276
|
+
};
|
|
1277
|
+
return fn;
|
|
866
1278
|
};
|
|
867
|
-
const
|
|
868
|
-
|
|
1279
|
+
const _encodeAsync = (_Err) => {
|
|
1280
|
+
const parseAsync = _parseAsync(_Err);
|
|
1281
|
+
const fn = async (schema, value, _ctx, _params) => {
|
|
1282
|
+
return await parseAsync(schema, value, _ctx ? {
|
|
1283
|
+
..._ctx,
|
|
1284
|
+
direction: "backward"
|
|
1285
|
+
} : { direction: "backward" }, finalizeParams(fn, _params));
|
|
1286
|
+
};
|
|
1287
|
+
return fn;
|
|
1288
|
+
};
|
|
1289
|
+
const _decodeAsync = (_Err) => {
|
|
1290
|
+
const parseAsync = _parseAsync(_Err);
|
|
1291
|
+
const fn = async (schema, value, _ctx, _params) => {
|
|
1292
|
+
return await parseAsync(schema, value, _ctx, finalizeParams(fn, _params));
|
|
1293
|
+
};
|
|
1294
|
+
return fn;
|
|
869
1295
|
};
|
|
870
1296
|
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
|
871
|
-
const ctx = _ctx ?
|
|
1297
|
+
const ctx = _ctx ? {
|
|
1298
|
+
..._ctx,
|
|
1299
|
+
direction: "backward"
|
|
1300
|
+
} : { direction: "backward" };
|
|
872
1301
|
return _safeParse(_Err)(schema, value, ctx);
|
|
873
1302
|
};
|
|
874
1303
|
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
|
875
1304
|
return _safeParse(_Err)(schema, value, _ctx);
|
|
876
1305
|
};
|
|
877
1306
|
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
878
|
-
const ctx = _ctx ?
|
|
1307
|
+
const ctx = _ctx ? {
|
|
1308
|
+
..._ctx,
|
|
1309
|
+
direction: "backward"
|
|
1310
|
+
} : { direction: "backward" };
|
|
879
1311
|
return _safeParseAsync(_Err)(schema, value, ctx);
|
|
880
1312
|
};
|
|
881
1313
|
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
882
1314
|
return _safeParseAsync(_Err)(schema, value, _ctx);
|
|
883
1315
|
};
|
|
884
|
-
|
|
1316
|
+
/**
|
|
1317
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
1318
|
+
* (timestamps embedded in the id). Use {@link cuid2} instead.
|
|
1319
|
+
* See https://github.com/paralleldrive/cuid.
|
|
1320
|
+
*/
|
|
1321
|
+
const cuid = /^[cC][0-9a-z]{6,}$/;
|
|
885
1322
|
const cuid2 = /^[0-9a-z]+$/;
|
|
886
|
-
const ulid = /^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{
|
|
1323
|
+
const ulid = /^[0-7][0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{25}$/;
|
|
887
1324
|
const xid = /^[0-9a-vA-V]{20}$/;
|
|
888
1325
|
const ksuid = /^[A-Za-z0-9]{27}$/;
|
|
889
1326
|
const nanoid = /^[a-zA-Z0-9_-]{21}$/;
|
|
1327
|
+
function nanoidOfLength(length) {
|
|
1328
|
+
return new RegExp(`^[a-zA-Z0-9_-]{${length}}$`);
|
|
1329
|
+
}
|
|
890
1330
|
/** ISO 8601-1 duration regex. Does not support the 8601-2 extensions like negative durations or fractional/negative components. */
|
|
891
|
-
const duration
|
|
1331
|
+
const duration = /^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/;
|
|
892
1332
|
/** A regex for any UUID-like identifier: 8-4-4-4-12 hex pattern */
|
|
893
1333
|
const guid = /^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/;
|
|
894
1334
|
/** Returns a regex for validating an RFC 9562/4122 UUID.
|
|
@@ -899,39 +1339,45 @@ const uuid = (version) => {
|
|
|
899
1339
|
return new RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${version}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`);
|
|
900
1340
|
};
|
|
901
1341
|
/** Practical email validation */
|
|
902
|
-
const email = /^(
|
|
903
|
-
const _emoji$1 = `^(\\p{Extended_Pictographic}
|
|
1342
|
+
const email = /^(?:[A-Za-z0-9_'+\-]+\.)*[A-Za-z0-9_'+\-]*[A-Za-z0-9_+-]@(?:[A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/;
|
|
1343
|
+
const _emoji$1 = `^(?=[\\s\\S]*[\\p{Extended_Pictographic}\\p{Regional_Indicator}\\u20E3])[\\p{Extended_Pictographic}\\p{Emoji_Component}]+$`;
|
|
904
1344
|
function emoji() {
|
|
905
1345
|
return new RegExp(_emoji$1, "u");
|
|
906
1346
|
}
|
|
907
1347
|
const ipv4 = /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/;
|
|
908
1348
|
const ipv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/;
|
|
909
1349
|
const cidrv4 = /^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/;
|
|
910
|
-
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}
|
|
1350
|
+
const cidrv6 = /^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/;
|
|
911
1351
|
const base64 = /^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/;
|
|
912
|
-
const base64url = /^[A-Za-z0-9_-]
|
|
1352
|
+
const base64url = /^(?:[A-Za-z0-9_-]{4})*(?:[A-Za-z0-9_-]{2,3})?$/;
|
|
1353
|
+
const httpProtocol = /^https?$/;
|
|
913
1354
|
const e164 = /^\+[1-9]\d{6,14}$/;
|
|
914
1355
|
const dateSource = `(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`;
|
|
915
|
-
|
|
1356
|
+
/** Anchors a pattern source. The interpolation lives here rather than at the call site because
|
|
1357
|
+
* esbuild will not drop a `@__PURE__` call whose own argument interpolates a variable, but it
|
|
1358
|
+
* will drop `anchor(dateSource)`. Keeping it inline pinned `date` into every bundle. */
|
|
1359
|
+
function anchor(source) {
|
|
1360
|
+
return new RegExp(`^${source}$`);
|
|
1361
|
+
}
|
|
1362
|
+
const date = /* @__PURE__ */ anchor(dateSource);
|
|
916
1363
|
function timeSource(args) {
|
|
917
1364
|
const hhmm = `(?:[01]\\d|2[0-3]):[0-5]\\d`;
|
|
918
|
-
return typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
1365
|
+
return typeof args.precision === "number" ? args.precision === -1 ? `${hhmm}` : args.precision === 0 ? `${hhmm}:[0-5]\\d` : `${hhmm}:[0-5]\\d\\.\\d{${args.precision}}` : args.seconds ? `${hhmm}:[0-5]\\d(?:\\.\\d+)?` : `${hhmm}(?::[0-5]\\d(?:\\.\\d+)?)?`;
|
|
919
1366
|
}
|
|
920
|
-
function time
|
|
1367
|
+
function time(args) {
|
|
921
1368
|
return new RegExp(`^${timeSource(args)}$`);
|
|
922
1369
|
}
|
|
923
|
-
function datetime
|
|
924
|
-
const time = timeSource({ precision: args.precision });
|
|
1370
|
+
function datetime(args) {
|
|
925
1371
|
const opts = ["Z"];
|
|
926
|
-
if (args.local) opts.push("");
|
|
927
1372
|
if (args.offset) opts.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);
|
|
928
|
-
const
|
|
1373
|
+
const qualified = `${timeSource({
|
|
1374
|
+
precision: args.precision,
|
|
1375
|
+
seconds: true
|
|
1376
|
+
})}(?:${opts.join("|")})`;
|
|
1377
|
+
const timeRegex = args.local ? `${qualified}|${timeSource({ precision: args.precision })}` : qualified;
|
|
929
1378
|
return new RegExp(`^${dateSource}T(?:${timeRegex})$`);
|
|
930
1379
|
}
|
|
931
|
-
const
|
|
932
|
-
const regex = params ? `[\\s\\S]{${params?.minimum ?? 0},${params?.maximum ?? ""}}` : `[\\s\\S]*`;
|
|
933
|
-
return new RegExp(`^${regex}$`);
|
|
934
|
-
};
|
|
1380
|
+
const anyString = /^[\s\S]{0,}$/;
|
|
935
1381
|
const integer = /^-?\d+$/;
|
|
936
1382
|
const number$1 = /^-?\d+(?:\.\d+)?$/;
|
|
937
1383
|
const boolean$1 = /^(?:true|false)$/i;
|
|
@@ -943,6 +1389,11 @@ const $ZodCheck = /* @__PURE__ */ $constructor("$ZodCheck", (inst, def) => {
|
|
|
943
1389
|
inst._zod.def = def;
|
|
944
1390
|
(_a = inst._zod).onattach ?? (_a.onattach = []);
|
|
945
1391
|
});
|
|
1392
|
+
/** Default `when` for length-based checks: run only on non-nullish values with a `length`. */
|
|
1393
|
+
const _whenHasLength = (payload) => {
|
|
1394
|
+
const val = payload.value;
|
|
1395
|
+
return !nullish(val) && val.length !== void 0;
|
|
1396
|
+
};
|
|
946
1397
|
const numericOriginMap = {
|
|
947
1398
|
number: "number",
|
|
948
1399
|
bigint: "bigint",
|
|
@@ -951,16 +1402,10 @@ const numericOriginMap = {
|
|
|
951
1402
|
const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (inst, def) => {
|
|
952
1403
|
$ZodCheck.init(inst, def);
|
|
953
1404
|
const origin = numericOriginMap[typeof def.value];
|
|
954
|
-
inst._zod.onattach.push((inst) => {
|
|
955
|
-
const bag = inst._zod.bag;
|
|
956
|
-
const curr = (def.inclusive ? bag.maximum : bag.exclusiveMaximum) ?? Number.POSITIVE_INFINITY;
|
|
957
|
-
if (def.value < curr) if (def.inclusive) bag.maximum = def.value;
|
|
958
|
-
else bag.exclusiveMaximum = def.value;
|
|
959
|
-
});
|
|
960
1405
|
inst._zod.check = (payload) => {
|
|
961
1406
|
if (def.inclusive ? payload.value <= def.value : payload.value < def.value) return;
|
|
962
1407
|
payload.issues.push({
|
|
963
|
-
origin,
|
|
1408
|
+
origin: numericOriginMap[typeof payload.value] ?? origin,
|
|
964
1409
|
code: "too_big",
|
|
965
1410
|
maximum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
966
1411
|
input: payload.value,
|
|
@@ -973,16 +1418,10 @@ const $ZodCheckLessThan = /* @__PURE__ */ $constructor("$ZodCheckLessThan", (ins
|
|
|
973
1418
|
const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan", (inst, def) => {
|
|
974
1419
|
$ZodCheck.init(inst, def);
|
|
975
1420
|
const origin = numericOriginMap[typeof def.value];
|
|
976
|
-
inst._zod.onattach.push((inst) => {
|
|
977
|
-
const bag = inst._zod.bag;
|
|
978
|
-
const curr = (def.inclusive ? bag.minimum : bag.exclusiveMinimum) ?? Number.NEGATIVE_INFINITY;
|
|
979
|
-
if (def.value > curr) if (def.inclusive) bag.minimum = def.value;
|
|
980
|
-
else bag.exclusiveMinimum = def.value;
|
|
981
|
-
});
|
|
982
1421
|
inst._zod.check = (payload) => {
|
|
983
1422
|
if (def.inclusive ? payload.value >= def.value : payload.value > def.value) return;
|
|
984
1423
|
payload.issues.push({
|
|
985
|
-
origin,
|
|
1424
|
+
origin: numericOriginMap[typeof payload.value] ?? origin,
|
|
986
1425
|
code: "too_small",
|
|
987
1426
|
minimum: typeof def.value === "object" ? def.value.getTime() : def.value,
|
|
988
1427
|
input: payload.value,
|
|
@@ -994,13 +1433,9 @@ const $ZodCheckGreaterThan = /* @__PURE__ */ $constructor("$ZodCheckGreaterThan"
|
|
|
994
1433
|
});
|
|
995
1434
|
const $ZodCheckMultipleOf = /* @__PURE__ */ $constructor("$ZodCheckMultipleOf", (inst, def) => {
|
|
996
1435
|
$ZodCheck.init(inst, def);
|
|
997
|
-
inst._zod.onattach.push((inst) => {
|
|
998
|
-
var _a;
|
|
999
|
-
(_a = inst._zod.bag).multipleOf ?? (_a.multipleOf = def.value);
|
|
1000
|
-
});
|
|
1001
1436
|
inst._zod.check = (payload) => {
|
|
1002
1437
|
if (typeof payload.value !== typeof def.value) throw new Error("Cannot mix number and bigint in multiple_of check.");
|
|
1003
|
-
if (typeof payload.value === "bigint" ? payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0) return;
|
|
1438
|
+
if (typeof payload.value === "bigint" ? def.value !== BigInt(0) && payload.value % def.value === BigInt(0) : floatSafeRemainder(payload.value, def.value) === 0) return;
|
|
1004
1439
|
payload.issues.push({
|
|
1005
1440
|
origin: typeof payload.value,
|
|
1006
1441
|
code: "not_multiple_of",
|
|
@@ -1017,13 +1452,6 @@ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberForma
|
|
|
1017
1452
|
const isInt = def.format?.includes("int");
|
|
1018
1453
|
const origin = isInt ? "int" : "number";
|
|
1019
1454
|
const [minimum, maximum] = NUMBER_FORMAT_RANGES[def.format];
|
|
1020
|
-
inst._zod.onattach.push((inst) => {
|
|
1021
|
-
const bag = inst._zod.bag;
|
|
1022
|
-
bag.format = def.format;
|
|
1023
|
-
bag.minimum = minimum;
|
|
1024
|
-
bag.maximum = maximum;
|
|
1025
|
-
if (isInt) bag.pattern = integer;
|
|
1026
|
-
});
|
|
1027
1455
|
inst._zod.check = (payload) => {
|
|
1028
1456
|
const input = payload.value;
|
|
1029
1457
|
if (isInt) {
|
|
@@ -1085,17 +1513,11 @@ const $ZodCheckNumberFormat = /* @__PURE__ */ $constructor("$ZodCheckNumberForma
|
|
|
1085
1513
|
const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (inst, def) => {
|
|
1086
1514
|
var _a;
|
|
1087
1515
|
$ZodCheck.init(inst, def);
|
|
1088
|
-
(_a = inst._zod.def).when ?? (_a.when =
|
|
1089
|
-
const val = payload.value;
|
|
1090
|
-
return !nullish(val) && val.length !== void 0;
|
|
1091
|
-
});
|
|
1092
|
-
inst._zod.onattach.push((inst) => {
|
|
1093
|
-
const curr = inst._zod.bag.maximum ?? Number.POSITIVE_INFINITY;
|
|
1094
|
-
if (def.maximum < curr) inst._zod.bag.maximum = def.maximum;
|
|
1095
|
-
});
|
|
1516
|
+
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
|
|
1096
1517
|
inst._zod.check = (payload) => {
|
|
1097
1518
|
const input = payload.value;
|
|
1098
|
-
|
|
1519
|
+
const units = input.length;
|
|
1520
|
+
if ((typeof input === "string" && units > def.maximum ? codePointLength(input) : units) <= def.maximum) return;
|
|
1099
1521
|
const origin = getLengthableOrigin(input);
|
|
1100
1522
|
payload.issues.push({
|
|
1101
1523
|
origin,
|
|
@@ -1111,17 +1533,11 @@ const $ZodCheckMaxLength = /* @__PURE__ */ $constructor("$ZodCheckMaxLength", (i
|
|
|
1111
1533
|
const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (inst, def) => {
|
|
1112
1534
|
var _a;
|
|
1113
1535
|
$ZodCheck.init(inst, def);
|
|
1114
|
-
(_a = inst._zod.def).when ?? (_a.when =
|
|
1115
|
-
const val = payload.value;
|
|
1116
|
-
return !nullish(val) && val.length !== void 0;
|
|
1117
|
-
});
|
|
1118
|
-
inst._zod.onattach.push((inst) => {
|
|
1119
|
-
const curr = inst._zod.bag.minimum ?? Number.NEGATIVE_INFINITY;
|
|
1120
|
-
if (def.minimum > curr) inst._zod.bag.minimum = def.minimum;
|
|
1121
|
-
});
|
|
1536
|
+
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
|
|
1122
1537
|
inst._zod.check = (payload) => {
|
|
1123
1538
|
const input = payload.value;
|
|
1124
|
-
|
|
1539
|
+
const units = input.length;
|
|
1540
|
+
if ((typeof input === "string" && units >= def.minimum && units < def.minimum * 2 ? codePointLength(input) : units) >= def.minimum) return;
|
|
1125
1541
|
const origin = getLengthableOrigin(input);
|
|
1126
1542
|
payload.issues.push({
|
|
1127
1543
|
origin,
|
|
@@ -1137,19 +1553,11 @@ const $ZodCheckMinLength = /* @__PURE__ */ $constructor("$ZodCheckMinLength", (i
|
|
|
1137
1553
|
const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEquals", (inst, def) => {
|
|
1138
1554
|
var _a;
|
|
1139
1555
|
$ZodCheck.init(inst, def);
|
|
1140
|
-
(_a = inst._zod.def).when ?? (_a.when =
|
|
1141
|
-
const val = payload.value;
|
|
1142
|
-
return !nullish(val) && val.length !== void 0;
|
|
1143
|
-
});
|
|
1144
|
-
inst._zod.onattach.push((inst) => {
|
|
1145
|
-
const bag = inst._zod.bag;
|
|
1146
|
-
bag.minimum = def.length;
|
|
1147
|
-
bag.maximum = def.length;
|
|
1148
|
-
bag.length = def.length;
|
|
1149
|
-
});
|
|
1556
|
+
(_a = inst._zod.def).when ?? (_a.when = _whenHasLength);
|
|
1150
1557
|
inst._zod.check = (payload) => {
|
|
1151
1558
|
const input = payload.value;
|
|
1152
|
-
const
|
|
1559
|
+
const units = input.length;
|
|
1560
|
+
const length = typeof input === "string" && units >= def.length && units <= def.length * 2 ? codePointLength(input) : units;
|
|
1153
1561
|
if (length === def.length) return;
|
|
1154
1562
|
const origin = getLengthableOrigin(input);
|
|
1155
1563
|
const tooBig = length > def.length;
|
|
@@ -1173,14 +1581,6 @@ const $ZodCheckLengthEquals = /* @__PURE__ */ $constructor("$ZodCheckLengthEqual
|
|
|
1173
1581
|
const $ZodCheckStringFormat = /* @__PURE__ */ $constructor("$ZodCheckStringFormat", (inst, def) => {
|
|
1174
1582
|
var _a, _b;
|
|
1175
1583
|
$ZodCheck.init(inst, def);
|
|
1176
|
-
inst._zod.onattach.push((inst) => {
|
|
1177
|
-
const bag = inst._zod.bag;
|
|
1178
|
-
bag.format = def.format;
|
|
1179
|
-
if (def.pattern) {
|
|
1180
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1181
|
-
bag.patterns.add(def.pattern);
|
|
1182
|
-
}
|
|
1183
|
-
});
|
|
1184
1584
|
if (def.pattern) (_a = inst._zod).check ?? (_a.check = (payload) => {
|
|
1185
1585
|
def.pattern.lastIndex = 0;
|
|
1186
1586
|
if (def.pattern.test(payload.value)) return;
|
|
@@ -1223,13 +1623,7 @@ const $ZodCheckUpperCase = /* @__PURE__ */ $constructor("$ZodCheckUpperCase", (i
|
|
|
1223
1623
|
const $ZodCheckIncludes = /* @__PURE__ */ $constructor("$ZodCheckIncludes", (inst, def) => {
|
|
1224
1624
|
$ZodCheck.init(inst, def);
|
|
1225
1625
|
const escapedRegex = escapeRegex(def.includes);
|
|
1226
|
-
|
|
1227
|
-
def.pattern = pattern;
|
|
1228
|
-
inst._zod.onattach.push((inst) => {
|
|
1229
|
-
const bag = inst._zod.bag;
|
|
1230
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1231
|
-
bag.patterns.add(pattern);
|
|
1232
|
-
});
|
|
1626
|
+
def.pattern = new RegExp(typeof def.position === "number" ? `^.{${def.position},}${escapedRegex}` : escapedRegex);
|
|
1233
1627
|
inst._zod.check = (payload) => {
|
|
1234
1628
|
if (payload.value.includes(def.includes, def.position)) return;
|
|
1235
1629
|
payload.issues.push({
|
|
@@ -1247,11 +1641,6 @@ const $ZodCheckStartsWith = /* @__PURE__ */ $constructor("$ZodCheckStartsWith",
|
|
|
1247
1641
|
$ZodCheck.init(inst, def);
|
|
1248
1642
|
const pattern = new RegExp(`^${escapeRegex(def.prefix)}.*`);
|
|
1249
1643
|
def.pattern ?? (def.pattern = pattern);
|
|
1250
|
-
inst._zod.onattach.push((inst) => {
|
|
1251
|
-
const bag = inst._zod.bag;
|
|
1252
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1253
|
-
bag.patterns.add(pattern);
|
|
1254
|
-
});
|
|
1255
1644
|
inst._zod.check = (payload) => {
|
|
1256
1645
|
if (payload.value.startsWith(def.prefix)) return;
|
|
1257
1646
|
payload.issues.push({
|
|
@@ -1269,11 +1658,6 @@ const $ZodCheckEndsWith = /* @__PURE__ */ $constructor("$ZodCheckEndsWith", (ins
|
|
|
1269
1658
|
$ZodCheck.init(inst, def);
|
|
1270
1659
|
const pattern = new RegExp(`.*${escapeRegex(def.suffix)}$`);
|
|
1271
1660
|
def.pattern ?? (def.pattern = pattern);
|
|
1272
|
-
inst._zod.onattach.push((inst) => {
|
|
1273
|
-
const bag = inst._zod.bag;
|
|
1274
|
-
bag.patterns ?? (bag.patterns = /* @__PURE__ */ new Set());
|
|
1275
|
-
bag.patterns.add(pattern);
|
|
1276
|
-
});
|
|
1277
1661
|
inst._zod.check = (payload) => {
|
|
1278
1662
|
if (payload.value.endsWith(def.suffix)) return;
|
|
1279
1663
|
payload.issues.push({
|
|
@@ -1294,15 +1678,19 @@ const $ZodCheckOverwrite = /* @__PURE__ */ $constructor("$ZodCheckOverwrite", (i
|
|
|
1294
1678
|
};
|
|
1295
1679
|
});
|
|
1296
1680
|
var Doc = class {
|
|
1297
|
-
constructor(args = []) {
|
|
1681
|
+
constructor(args = [], closed = {}) {
|
|
1298
1682
|
this.content = [];
|
|
1299
1683
|
this.indent = 0;
|
|
1300
|
-
|
|
1684
|
+
this.args = args;
|
|
1685
|
+
this.closed = closed;
|
|
1301
1686
|
}
|
|
1302
1687
|
indented(fn) {
|
|
1303
1688
|
this.indent += 1;
|
|
1304
|
-
|
|
1305
|
-
|
|
1689
|
+
try {
|
|
1690
|
+
fn(this);
|
|
1691
|
+
} finally {
|
|
1692
|
+
this.indent -= 1;
|
|
1693
|
+
}
|
|
1306
1694
|
}
|
|
1307
1695
|
write(arg) {
|
|
1308
1696
|
if (typeof arg === "function") {
|
|
@@ -1317,15 +1705,14 @@ var Doc = class {
|
|
|
1317
1705
|
}
|
|
1318
1706
|
compile() {
|
|
1319
1707
|
const F = Function;
|
|
1320
|
-
const
|
|
1321
|
-
|
|
1322
|
-
return new F(...args, lines.join("\n"));
|
|
1708
|
+
const content = this?.content ?? [``];
|
|
1709
|
+
return new F(...Object.keys(this.closed), `return function (${this.args.join(", ")}) {\n${content.join("\n")}\n};`)(...Object.values(this.closed));
|
|
1323
1710
|
}
|
|
1324
1711
|
};
|
|
1325
1712
|
const version = {
|
|
1326
1713
|
major: 4,
|
|
1327
|
-
minor:
|
|
1328
|
-
patch:
|
|
1714
|
+
minor: 6,
|
|
1715
|
+
patch: 7
|
|
1329
1716
|
};
|
|
1330
1717
|
const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
1331
1718
|
var _a;
|
|
@@ -1333,8 +1720,8 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1333
1720
|
inst._zod.def = def;
|
|
1334
1721
|
inst._zod.bag = inst._zod.bag || {};
|
|
1335
1722
|
inst._zod.version = version;
|
|
1336
|
-
const
|
|
1337
|
-
|
|
1723
|
+
const defChecks = inst._zod.def.checks;
|
|
1724
|
+
const checks = inst._zod.traits.has("$ZodCheck") ? [inst, ...defChecks ?? []] : defChecks?.length ? [...defChecks] : [];
|
|
1338
1725
|
for (const ch of checks) for (const fn of ch._zod.onattach) fn(inst);
|
|
1339
1726
|
if (checks.length === 0) {
|
|
1340
1727
|
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
@@ -1343,10 +1730,12 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1343
1730
|
});
|
|
1344
1731
|
} else {
|
|
1345
1732
|
const runChecks = (payload, checks, ctx) => {
|
|
1733
|
+
if (payload.memo) return payload;
|
|
1346
1734
|
let isAborted = aborted(payload);
|
|
1347
1735
|
let asyncResult;
|
|
1348
1736
|
for (const ch of checks) {
|
|
1349
1737
|
if (ch._zod.def.when) {
|
|
1738
|
+
if (explicitlyAborted(payload)) continue;
|
|
1350
1739
|
if (!ch._zod.def.when(payload)) continue;
|
|
1351
1740
|
} else if (isAborted) continue;
|
|
1352
1741
|
const currLen = payload.issues.length;
|
|
@@ -1355,10 +1744,12 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1355
1744
|
if (asyncResult || _ instanceof Promise) asyncResult = (asyncResult ?? Promise.resolve()).then(async () => {
|
|
1356
1745
|
await _;
|
|
1357
1746
|
if (payload.issues.length === currLen) return;
|
|
1747
|
+
attachSchema(payload.issues, currLen, inst);
|
|
1358
1748
|
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
1359
1749
|
});
|
|
1360
1750
|
else {
|
|
1361
1751
|
if (payload.issues.length === currLen) continue;
|
|
1752
|
+
attachSchema(payload.issues, currLen, inst);
|
|
1362
1753
|
if (!isAborted) isAborted = aborted(payload, currLen);
|
|
1363
1754
|
}
|
|
1364
1755
|
}
|
|
@@ -1402,22 +1793,43 @@ const $ZodType = /* @__PURE__ */ $constructor("$ZodType", (inst, def) => {
|
|
|
1402
1793
|
return runChecks(result, checks, ctx);
|
|
1403
1794
|
};
|
|
1404
1795
|
}
|
|
1405
|
-
|
|
1796
|
+
}, {
|
|
1797
|
+
get "~standard"() {
|
|
1798
|
+
return hide(this, "~standard", standardProps(this));
|
|
1799
|
+
},
|
|
1800
|
+
set "~standard"(value) {
|
|
1801
|
+
own(this, "~standard", value);
|
|
1802
|
+
}
|
|
1803
|
+
});
|
|
1804
|
+
/** The Standard Schema surface for `inst`. Shared so wrappers can extend it without forcing it. */
|
|
1805
|
+
const toStandardResult = (r, ctx) => r.issues.length ? { issues: r.issues.map((iss) => finalizeIssue(iss, ctx, config())) } : { value: r.value };
|
|
1806
|
+
async function validateAsync(inst, value) {
|
|
1807
|
+
const ctx = { async: true };
|
|
1808
|
+
return toStandardResult(await inst._zod.run({
|
|
1809
|
+
value,
|
|
1810
|
+
issues: []
|
|
1811
|
+
}, ctx), ctx);
|
|
1812
|
+
}
|
|
1813
|
+
function standardProps(inst) {
|
|
1814
|
+
return {
|
|
1406
1815
|
validate: (value) => {
|
|
1816
|
+
const ctx = { async: false };
|
|
1407
1817
|
try {
|
|
1408
|
-
const r =
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1818
|
+
const r = inst._zod.run({
|
|
1819
|
+
value,
|
|
1820
|
+
issues: []
|
|
1821
|
+
}, ctx);
|
|
1822
|
+
if (!(r instanceof Promise)) return toStandardResult(r, ctx);
|
|
1823
|
+
} catch (_) {}
|
|
1824
|
+
return validateAsync(inst, value);
|
|
1413
1825
|
},
|
|
1414
1826
|
vendor: "zod",
|
|
1415
1827
|
version: 1
|
|
1416
|
-
}
|
|
1417
|
-
}
|
|
1828
|
+
};
|
|
1829
|
+
}
|
|
1418
1830
|
const $ZodString = /* @__PURE__ */ $constructor("$ZodString", (inst, def) => {
|
|
1419
1831
|
$ZodType.init(inst, def);
|
|
1420
|
-
inst._zod.pattern =
|
|
1832
|
+
inst._zod.pattern = def.pattern ?? anyString;
|
|
1421
1833
|
inst._zod.parse = (payload, _) => {
|
|
1422
1834
|
if (def.coerce) try {
|
|
1423
1835
|
payload.value = String(payload.value);
|
|
@@ -1461,38 +1873,95 @@ const $ZodEmail = /* @__PURE__ */ $constructor("$ZodEmail", (inst, def) => {
|
|
|
1461
1873
|
def.pattern ?? (def.pattern = email);
|
|
1462
1874
|
$ZodStringFormat.init(inst, def);
|
|
1463
1875
|
});
|
|
1876
|
+
function canParseURL(input) {
|
|
1877
|
+
try {
|
|
1878
|
+
if (typeof URL !== "undefined" && typeof URL.canParse === "function") return URL.canParse(input);
|
|
1879
|
+
new URL(input);
|
|
1880
|
+
return true;
|
|
1881
|
+
} catch {
|
|
1882
|
+
return false;
|
|
1883
|
+
}
|
|
1884
|
+
}
|
|
1885
|
+
function validateURL(trimmed, def) {
|
|
1886
|
+
if (!("normalize" in def) && !("hostname" in def) && !("protocol" in def)) return canParseURL(trimmed) || 2;
|
|
1887
|
+
return parseURLObject(trimmed, def);
|
|
1888
|
+
}
|
|
1889
|
+
/** Parses a URL while preserving the non-normalizing HTTP guard. */
|
|
1890
|
+
function parseURLObject(trimmed, def) {
|
|
1891
|
+
if (!def.normalize && def.protocol?.source === httpProtocol.source && !/^https?:\/\//i.test(trimmed)) return 1;
|
|
1892
|
+
try {
|
|
1893
|
+
if (typeof URL !== "undefined") {
|
|
1894
|
+
const URLStatic = URL;
|
|
1895
|
+
if (typeof URLStatic.parse === "function") return URLStatic.parse(trimmed) ?? 2;
|
|
1896
|
+
}
|
|
1897
|
+
return new URL(trimmed);
|
|
1898
|
+
} catch {
|
|
1899
|
+
return 2;
|
|
1900
|
+
}
|
|
1901
|
+
}
|
|
1902
|
+
const asciiTabOrNewline = /[\t\n\r]/g;
|
|
1903
|
+
/** The URL parser deletes every ASCII tab, LF and CR from its input before it parses, so `new URL("https://exa\nmple.com")` reports on `example.com`. Applying the same deletion to the returned value closes the half of that divergence which can move the host; the parser's other rewrite, stripping C0 controls at the edges, cannot. */
|
|
1904
|
+
function stripTabAndNewline(value) {
|
|
1905
|
+
return value.replace(asciiTabOrNewline, "");
|
|
1906
|
+
}
|
|
1907
|
+
function urlHostnameOk(url, hostname) {
|
|
1908
|
+
hostname.lastIndex = 0;
|
|
1909
|
+
return hostname.test(url.hostname);
|
|
1910
|
+
}
|
|
1911
|
+
function urlProtocolOk(url, protocol) {
|
|
1912
|
+
protocol.lastIndex = 0;
|
|
1913
|
+
return protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol);
|
|
1914
|
+
}
|
|
1464
1915
|
const $ZodURL = /* @__PURE__ */ $constructor("$ZodURL", (inst, def) => {
|
|
1465
1916
|
$ZodStringFormat.init(inst, def);
|
|
1466
1917
|
inst._zod.check = (payload) => {
|
|
1467
1918
|
try {
|
|
1468
1919
|
const trimmed = payload.value.trim();
|
|
1469
|
-
const url =
|
|
1470
|
-
if (
|
|
1471
|
-
|
|
1472
|
-
if (!def.hostname.test(url.hostname)) payload.issues.push({
|
|
1920
|
+
const url = validateURL(trimmed, def);
|
|
1921
|
+
if (url === 1) {
|
|
1922
|
+
payload.issues.push({
|
|
1473
1923
|
code: "invalid_format",
|
|
1474
1924
|
format: "url",
|
|
1475
|
-
note: "Invalid
|
|
1476
|
-
pattern: def.hostname.source,
|
|
1925
|
+
note: "Invalid URL format",
|
|
1477
1926
|
input: payload.value,
|
|
1478
1927
|
inst,
|
|
1479
1928
|
continue: !def.abort
|
|
1480
1929
|
});
|
|
1930
|
+
return;
|
|
1481
1931
|
}
|
|
1482
|
-
if (
|
|
1483
|
-
|
|
1484
|
-
if (!def.protocol.test(url.protocol.endsWith(":") ? url.protocol.slice(0, -1) : url.protocol)) payload.issues.push({
|
|
1932
|
+
if (url === 2) {
|
|
1933
|
+
payload.issues.push({
|
|
1485
1934
|
code: "invalid_format",
|
|
1486
1935
|
format: "url",
|
|
1487
|
-
note: "Invalid protocol",
|
|
1488
|
-
pattern: def.protocol.source,
|
|
1489
1936
|
input: payload.value,
|
|
1490
1937
|
inst,
|
|
1491
1938
|
continue: !def.abort
|
|
1492
1939
|
});
|
|
1940
|
+
return;
|
|
1493
1941
|
}
|
|
1494
|
-
if (
|
|
1495
|
-
|
|
1942
|
+
if (url === true) {
|
|
1943
|
+
payload.value = stripTabAndNewline(trimmed);
|
|
1944
|
+
return;
|
|
1945
|
+
}
|
|
1946
|
+
if (def.hostname && !urlHostnameOk(url, def.hostname)) payload.issues.push({
|
|
1947
|
+
code: "invalid_format",
|
|
1948
|
+
format: "url",
|
|
1949
|
+
note: "Invalid hostname",
|
|
1950
|
+
pattern: def.hostname.source,
|
|
1951
|
+
input: payload.value,
|
|
1952
|
+
inst,
|
|
1953
|
+
continue: !def.abort
|
|
1954
|
+
});
|
|
1955
|
+
if (def.protocol && !urlProtocolOk(url, def.protocol)) payload.issues.push({
|
|
1956
|
+
code: "invalid_format",
|
|
1957
|
+
format: "url",
|
|
1958
|
+
note: "Invalid protocol",
|
|
1959
|
+
pattern: def.protocol.source,
|
|
1960
|
+
input: payload.value,
|
|
1961
|
+
inst,
|
|
1962
|
+
continue: !def.abort
|
|
1963
|
+
});
|
|
1964
|
+
payload.value = def.normalize ? url.href : stripTabAndNewline(trimmed);
|
|
1496
1965
|
return;
|
|
1497
1966
|
} catch (_) {
|
|
1498
1967
|
payload.issues.push({
|
|
@@ -1510,9 +1979,15 @@ const $ZodEmoji = /* @__PURE__ */ $constructor("$ZodEmoji", (inst, def) => {
|
|
|
1510
1979
|
$ZodStringFormat.init(inst, def);
|
|
1511
1980
|
});
|
|
1512
1981
|
const $ZodNanoID = /* @__PURE__ */ $constructor("$ZodNanoID", (inst, def) => {
|
|
1513
|
-
def.
|
|
1982
|
+
if (def.length !== void 0 && (!Number.isInteger(def.length) || def.length < 1)) throw new Error(`Invalid nanoid length: ${def.length}`);
|
|
1983
|
+
def.pattern ?? (def.pattern = def.length === void 0 ? nanoid : nanoidOfLength(def.length));
|
|
1514
1984
|
$ZodStringFormat.init(inst, def);
|
|
1515
1985
|
});
|
|
1986
|
+
/**
|
|
1987
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
1988
|
+
* (timestamps embedded in the id). Use {@link $ZodCUID2} instead.
|
|
1989
|
+
* See https://github.com/paralleldrive/cuid.
|
|
1990
|
+
*/
|
|
1516
1991
|
const $ZodCUID = /* @__PURE__ */ $constructor("$ZodCUID", (inst, def) => {
|
|
1517
1992
|
def.pattern ?? (def.pattern = cuid);
|
|
1518
1993
|
$ZodStringFormat.init(inst, def);
|
|
@@ -1534,74 +2009,74 @@ const $ZodKSUID = /* @__PURE__ */ $constructor("$ZodKSUID", (inst, def) => {
|
|
|
1534
2009
|
$ZodStringFormat.init(inst, def);
|
|
1535
2010
|
});
|
|
1536
2011
|
const $ZodISODateTime = /* @__PURE__ */ $constructor("$ZodISODateTime", (inst, def) => {
|
|
1537
|
-
def.pattern ?? (def.pattern = datetime
|
|
2012
|
+
def.pattern ?? (def.pattern = datetime(def));
|
|
1538
2013
|
$ZodStringFormat.init(inst, def);
|
|
1539
2014
|
});
|
|
1540
2015
|
const $ZodISODate = /* @__PURE__ */ $constructor("$ZodISODate", (inst, def) => {
|
|
1541
|
-
def.pattern ?? (def.pattern = date
|
|
2016
|
+
def.pattern ?? (def.pattern = date);
|
|
1542
2017
|
$ZodStringFormat.init(inst, def);
|
|
1543
2018
|
});
|
|
1544
2019
|
const $ZodISOTime = /* @__PURE__ */ $constructor("$ZodISOTime", (inst, def) => {
|
|
1545
|
-
def.pattern ?? (def.pattern = time
|
|
2020
|
+
def.pattern ?? (def.pattern = time(def));
|
|
1546
2021
|
$ZodStringFormat.init(inst, def);
|
|
1547
2022
|
});
|
|
1548
2023
|
const $ZodISODuration = /* @__PURE__ */ $constructor("$ZodISODuration", (inst, def) => {
|
|
1549
|
-
def.pattern ?? (def.pattern = duration
|
|
2024
|
+
def.pattern ?? (def.pattern = duration);
|
|
1550
2025
|
$ZodStringFormat.init(inst, def);
|
|
1551
2026
|
});
|
|
1552
2027
|
const $ZodIPv4 = /* @__PURE__ */ $constructor("$ZodIPv4", (inst, def) => {
|
|
1553
2028
|
def.pattern ?? (def.pattern = ipv4);
|
|
1554
2029
|
$ZodStringFormat.init(inst, def);
|
|
1555
|
-
inst._zod.bag.format = `ipv4`;
|
|
1556
2030
|
});
|
|
2031
|
+
/** An IPv6 address is written with hex digits, colons and dots, and nothing else. The guard is what makes the check below an IPv6 check: `new URL("http://[...]")` parses an authority, not an address, so `@` and `\` re-delimit it and `"::@1\\"` validates against the host `0.0.0.1`. The URL parser also deletes ASCII tab, LF and CR rather than failing, which is how `"::1\n"` validated as `::1`. */
|
|
2032
|
+
const ipv6Alphabet = /^[0-9a-fA-F:.]+$/;
|
|
2033
|
+
function isValidIPv6(value) {
|
|
2034
|
+
if (!ipv6Alphabet.test(value)) return false;
|
|
2035
|
+
return canParseURL(`http://[${value}]`);
|
|
2036
|
+
}
|
|
1557
2037
|
const $ZodIPv6 = /* @__PURE__ */ $constructor("$ZodIPv6", (inst, def) => {
|
|
1558
2038
|
def.pattern ?? (def.pattern = ipv6);
|
|
1559
2039
|
$ZodStringFormat.init(inst, def);
|
|
1560
|
-
inst._zod.bag.format = `ipv6`;
|
|
1561
2040
|
inst._zod.check = (payload) => {
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
payload.
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
inst,
|
|
1570
|
-
continue: !def.abort
|
|
1571
|
-
});
|
|
1572
|
-
}
|
|
2041
|
+
if (!isValidIPv6(payload.value)) payload.issues.push({
|
|
2042
|
+
code: "invalid_format",
|
|
2043
|
+
format: "ipv6",
|
|
2044
|
+
input: payload.value,
|
|
2045
|
+
inst,
|
|
2046
|
+
continue: !def.abort
|
|
2047
|
+
});
|
|
1573
2048
|
};
|
|
1574
2049
|
});
|
|
1575
2050
|
const $ZodCIDRv4 = /* @__PURE__ */ $constructor("$ZodCIDRv4", (inst, def) => {
|
|
1576
2051
|
def.pattern ?? (def.pattern = cidrv4);
|
|
1577
2052
|
$ZodStringFormat.init(inst, def);
|
|
1578
2053
|
});
|
|
2054
|
+
function isValidCIDRv6(value) {
|
|
2055
|
+
const parts = value.split("/");
|
|
2056
|
+
if (parts.length !== 2) return false;
|
|
2057
|
+
const [address, prefix] = parts;
|
|
2058
|
+
if (!prefix) return false;
|
|
2059
|
+
const prefixNum = Number(prefix);
|
|
2060
|
+
if (`${prefixNum}` !== prefix) return false;
|
|
2061
|
+
if (prefixNum < 0 || prefixNum > 128) return false;
|
|
2062
|
+
return isValidIPv6(address);
|
|
2063
|
+
}
|
|
1579
2064
|
const $ZodCIDRv6 = /* @__PURE__ */ $constructor("$ZodCIDRv6", (inst, def) => {
|
|
1580
2065
|
def.pattern ?? (def.pattern = cidrv6);
|
|
1581
2066
|
$ZodStringFormat.init(inst, def);
|
|
1582
2067
|
inst._zod.check = (payload) => {
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
if (prefixNum < 0 || prefixNum > 128) throw new Error();
|
|
1591
|
-
new URL(`http://[${address}]`);
|
|
1592
|
-
} catch {
|
|
1593
|
-
payload.issues.push({
|
|
1594
|
-
code: "invalid_format",
|
|
1595
|
-
format: "cidrv6",
|
|
1596
|
-
input: payload.value,
|
|
1597
|
-
inst,
|
|
1598
|
-
continue: !def.abort
|
|
1599
|
-
});
|
|
1600
|
-
}
|
|
2068
|
+
if (!isValidCIDRv6(payload.value)) payload.issues.push({
|
|
2069
|
+
code: "invalid_format",
|
|
2070
|
+
format: "cidrv6",
|
|
2071
|
+
input: payload.value,
|
|
2072
|
+
inst,
|
|
2073
|
+
continue: !def.abort
|
|
2074
|
+
});
|
|
1601
2075
|
};
|
|
1602
2076
|
});
|
|
1603
2077
|
function isValidBase64(data) {
|
|
1604
2078
|
if (data === "") return true;
|
|
2079
|
+
if (/\s/.test(data)) return false;
|
|
1605
2080
|
if (data.length % 4 !== 0) return false;
|
|
1606
2081
|
try {
|
|
1607
2082
|
atob(data);
|
|
@@ -1610,10 +2085,10 @@ function isValidBase64(data) {
|
|
|
1610
2085
|
return false;
|
|
1611
2086
|
}
|
|
1612
2087
|
}
|
|
2088
|
+
const base64Charset = /^[0-9a-zA-Z+/]*={0,2}$/;
|
|
1613
2089
|
const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
|
|
1614
|
-
def.pattern ?? (def.pattern =
|
|
2090
|
+
def.pattern ?? (def.pattern = base64Charset);
|
|
1615
2091
|
$ZodStringFormat.init(inst, def);
|
|
1616
|
-
inst._zod.bag.contentEncoding = "base64";
|
|
1617
2092
|
inst._zod.check = (payload) => {
|
|
1618
2093
|
if (isValidBase64(payload.value)) return;
|
|
1619
2094
|
payload.issues.push({
|
|
@@ -1625,15 +2100,15 @@ const $ZodBase64 = /* @__PURE__ */ $constructor("$ZodBase64", (inst, def) => {
|
|
|
1625
2100
|
});
|
|
1626
2101
|
};
|
|
1627
2102
|
});
|
|
2103
|
+
const base64urlCharset = /^[A-Za-z0-9_-]*$/;
|
|
1628
2104
|
function isValidBase64URL(data) {
|
|
1629
|
-
if (!
|
|
2105
|
+
if (!base64urlCharset.test(data)) return false;
|
|
1630
2106
|
const base64 = data.replace(/[-_]/g, (c) => c === "-" ? "+" : "/");
|
|
1631
2107
|
return isValidBase64(base64.padEnd(Math.ceil(base64.length / 4) * 4, "="));
|
|
1632
2108
|
}
|
|
1633
2109
|
const $ZodBase64URL = /* @__PURE__ */ $constructor("$ZodBase64URL", (inst, def) => {
|
|
1634
|
-
def.pattern ?? (def.pattern =
|
|
2110
|
+
def.pattern ?? (def.pattern = base64urlCharset);
|
|
1635
2111
|
$ZodStringFormat.init(inst, def);
|
|
1636
|
-
inst._zod.bag.contentEncoding = "base64url";
|
|
1637
2112
|
inst._zod.check = (payload) => {
|
|
1638
2113
|
if (isValidBase64URL(payload.value)) return;
|
|
1639
2114
|
payload.issues.push({
|
|
@@ -1679,14 +2154,14 @@ const $ZodJWT = /* @__PURE__ */ $constructor("$ZodJWT", (inst, def) => {
|
|
|
1679
2154
|
});
|
|
1680
2155
|
const $ZodNumber = /* @__PURE__ */ $constructor("$ZodNumber", (inst, def) => {
|
|
1681
2156
|
$ZodType.init(inst, def);
|
|
1682
|
-
inst._zod.pattern =
|
|
2157
|
+
inst._zod.pattern = number$1;
|
|
1683
2158
|
inst._zod.parse = (payload, _ctx) => {
|
|
1684
2159
|
if (def.coerce) try {
|
|
1685
2160
|
payload.value = Number(payload.value);
|
|
1686
2161
|
} catch (_) {}
|
|
1687
2162
|
const input = payload.value;
|
|
1688
2163
|
if (typeof input === "number" && !Number.isNaN(input) && Number.isFinite(input)) return payload;
|
|
1689
|
-
const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ?
|
|
2164
|
+
const received = typeof input === "number" ? Number.isNaN(input) ? "NaN" : !Number.isFinite(input) ? String(input) : void 0 : void 0;
|
|
1690
2165
|
payload.issues.push({
|
|
1691
2166
|
expected: "number",
|
|
1692
2167
|
code: "invalid_type",
|
|
@@ -1735,12 +2210,34 @@ const $ZodNever = /* @__PURE__ */ $constructor("$ZodNever", (inst, def) => {
|
|
|
1735
2210
|
return payload;
|
|
1736
2211
|
};
|
|
1737
2212
|
});
|
|
2213
|
+
function capSize(inst, size) {
|
|
2214
|
+
const caps = sizeCaps(inst._zod.def.checks);
|
|
2215
|
+
if (!caps.length) return;
|
|
2216
|
+
const cap = Math.min(...caps.map((c) => c[0]));
|
|
2217
|
+
const parse = inst._zod.parse;
|
|
2218
|
+
inst._zod.parse = (payload, ctx) => {
|
|
2219
|
+
const n = size(payload.value);
|
|
2220
|
+
if (n > cap && !ctx?.skipChecks && ctx?.direction !== "backward") {
|
|
2221
|
+
for (const [max, ch] of sizeCaps(inst._zod.def.checks)) if (n > max && ch._zod.def.when(payload)) {
|
|
2222
|
+
const start = payload.issues.length;
|
|
2223
|
+
ch._zod.check(payload);
|
|
2224
|
+
payload.issues[start].continue = false;
|
|
2225
|
+
attachSchema(payload.issues, start, inst);
|
|
2226
|
+
return payload;
|
|
2227
|
+
}
|
|
2228
|
+
}
|
|
2229
|
+
return parse(payload, ctx);
|
|
2230
|
+
};
|
|
2231
|
+
}
|
|
2232
|
+
const arraySize = (input) => Array.isArray(input) ? input.length : -1;
|
|
1738
2233
|
function handleArrayResult(result, final, index) {
|
|
1739
2234
|
if (result.issues.length) final.issues.push(...prefixIssues(index, result.issues));
|
|
1740
2235
|
final.value[index] = result.value;
|
|
1741
2236
|
}
|
|
1742
2237
|
const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
1743
2238
|
$ZodType.init(inst, def);
|
|
2239
|
+
const memo = globalConfig.memoizer;
|
|
2240
|
+
memo?.attach(inst);
|
|
1744
2241
|
inst._zod.parse = (payload, ctx) => {
|
|
1745
2242
|
const input = payload.value;
|
|
1746
2243
|
if (!Array.isArray(input)) {
|
|
@@ -1752,8 +2249,9 @@ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
|
1752
2249
|
});
|
|
1753
2250
|
return payload;
|
|
1754
2251
|
}
|
|
1755
|
-
payload.value = Array(input.length);
|
|
2252
|
+
payload.value = memo ? memo.alloc(inst, payload, Array(input.length), ctx) : Array(input.length);
|
|
1756
2253
|
const proms = [];
|
|
2254
|
+
const abortEarly = ctx?.abortEarly;
|
|
1757
2255
|
for (let i = 0; i < input.length; i++) {
|
|
1758
2256
|
const item = input[i];
|
|
1759
2257
|
const result = def.element._zod.run({
|
|
@@ -1761,41 +2259,72 @@ const $ZodArray = /* @__PURE__ */ $constructor("$ZodArray", (inst, def) => {
|
|
|
1761
2259
|
issues: []
|
|
1762
2260
|
}, ctx);
|
|
1763
2261
|
if (result instanceof Promise) proms.push(result.then((result) => handleArrayResult(result, payload, i)));
|
|
1764
|
-
else
|
|
2262
|
+
else {
|
|
2263
|
+
handleArrayResult(result, payload, i);
|
|
2264
|
+
if (abortEarly && result.issues.length !== 0 && aborted(result)) break;
|
|
2265
|
+
}
|
|
1765
2266
|
}
|
|
1766
2267
|
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
1767
2268
|
return payload;
|
|
1768
2269
|
};
|
|
2270
|
+
capSize(inst, arraySize);
|
|
1769
2271
|
});
|
|
1770
|
-
function handlePropertyResult(result, final, key, input,
|
|
2272
|
+
function handlePropertyResult(result, final, key, input, optin, optout) {
|
|
2273
|
+
const isPresent = key in input;
|
|
2274
|
+
const isOptionalOut = optout === "optional";
|
|
2275
|
+
if (!isPresent && isOptionalOut && optin === "optional") return;
|
|
1771
2276
|
if (result.issues.length) {
|
|
1772
|
-
if (isOptionalOut && !
|
|
2277
|
+
if (optin !== void 0 && isOptionalOut && !isPresent) return;
|
|
1773
2278
|
final.issues.push(...prefixIssues(key, result.issues));
|
|
1774
2279
|
}
|
|
2280
|
+
if (!isPresent && optin === void 0) {
|
|
2281
|
+
if (!result.issues.length) final.issues.push({
|
|
2282
|
+
code: "invalid_type",
|
|
2283
|
+
expected: "nonoptional",
|
|
2284
|
+
input: void 0,
|
|
2285
|
+
path: [key]
|
|
2286
|
+
});
|
|
2287
|
+
return;
|
|
2288
|
+
}
|
|
1775
2289
|
if (result.value === void 0) {
|
|
1776
|
-
if (
|
|
2290
|
+
if (isPresent || optin === "defaulted" && !isOptionalOut) final.value[key] = void 0;
|
|
1777
2291
|
} else final.value[key] = result.value;
|
|
1778
2292
|
}
|
|
2293
|
+
const NO_SYMBOL_KEYS = [];
|
|
1779
2294
|
function normalizeDef(def) {
|
|
1780
2295
|
const keys = Object.keys(def.shape);
|
|
1781
|
-
|
|
2296
|
+
const ownSymbols = Object.getOwnPropertySymbols(def.shape);
|
|
2297
|
+
const symbolKeys = ownSymbols.length ? ownSymbols : NO_SYMBOL_KEYS;
|
|
2298
|
+
const allKeys = symbolKeys.length ? [...keys, ...symbolKeys] : keys;
|
|
2299
|
+
for (const k of allKeys) if (!def.shape?.[k]?._zod?.traits?.has("$ZodType")) throw new Error(`Invalid element at key "${String(k)}": expected a Zod schema`);
|
|
1782
2300
|
const okeys = optionalKeys(def.shape);
|
|
1783
2301
|
return {
|
|
1784
2302
|
...def,
|
|
1785
|
-
|
|
2303
|
+
allKeys,
|
|
2304
|
+
symbolKeys,
|
|
1786
2305
|
keySet: new Set(keys),
|
|
1787
2306
|
numKeys: keys.length,
|
|
1788
2307
|
optionalKeys: new Set(okeys)
|
|
1789
2308
|
};
|
|
1790
2309
|
}
|
|
1791
|
-
function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
2310
|
+
function handleCatchall(proms, input, payload, ctx, def, inst, abortEarly) {
|
|
1792
2311
|
const unrecognized = [];
|
|
1793
2312
|
const keySet = def.keySet;
|
|
1794
2313
|
const _catchall = def.catchall._zod;
|
|
1795
2314
|
const t = _catchall.def.type;
|
|
1796
|
-
const
|
|
2315
|
+
const optin = _catchall.optin;
|
|
2316
|
+
const optout = _catchall.optout;
|
|
2317
|
+
let seen = 0;
|
|
1797
2318
|
for (const key in input) {
|
|
2319
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2320
|
+
if (aborted(payload, seen)) break;
|
|
2321
|
+
seen = payload.issues.length;
|
|
2322
|
+
}
|
|
1798
2323
|
if (keySet.has(key)) continue;
|
|
2324
|
+
if (key === "__proto__") {
|
|
2325
|
+
if (t === "never") unrecognized.push(key);
|
|
2326
|
+
continue;
|
|
2327
|
+
}
|
|
1799
2328
|
if (t === "never") {
|
|
1800
2329
|
unrecognized.push(key);
|
|
1801
2330
|
continue;
|
|
@@ -1804,14 +2333,15 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1804
2333
|
value: input[key],
|
|
1805
2334
|
issues: []
|
|
1806
2335
|
}, ctx);
|
|
1807
|
-
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input,
|
|
1808
|
-
else handlePropertyResult(r, payload, key, input,
|
|
2336
|
+
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
2337
|
+
else handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1809
2338
|
}
|
|
1810
2339
|
if (unrecognized.length) payload.issues.push({
|
|
1811
2340
|
code: "unrecognized_keys",
|
|
1812
2341
|
keys: unrecognized,
|
|
1813
2342
|
input,
|
|
1814
|
-
inst
|
|
2343
|
+
inst,
|
|
2344
|
+
continue: true
|
|
1815
2345
|
});
|
|
1816
2346
|
if (!proms.length) return payload;
|
|
1817
2347
|
return Promise.all(proms).then(() => {
|
|
@@ -1820,34 +2350,41 @@ function handleCatchall(proms, input, payload, ctx, def, inst) {
|
|
|
1820
2350
|
}
|
|
1821
2351
|
const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
1822
2352
|
$ZodType.init(inst, def);
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
2353
|
+
const desc = Object.getOwnPropertyDescriptor(def, "shape");
|
|
2354
|
+
const sh = desc?.get ? desc.get.raw : def.shape ?? {};
|
|
2355
|
+
if (sh) {
|
|
2356
|
+
const get = () => {
|
|
1826
2357
|
const newSh = { ...sh };
|
|
1827
2358
|
Object.defineProperty(def, "shape", { value: newSh });
|
|
2359
|
+
get.raw = newSh;
|
|
1828
2360
|
return newSh;
|
|
1829
|
-
}
|
|
2361
|
+
};
|
|
2362
|
+
get.raw = sh;
|
|
2363
|
+
Object.defineProperty(def, "shape", { get });
|
|
1830
2364
|
}
|
|
1831
2365
|
const _normalized = cached(() => normalizeDef(def));
|
|
1832
|
-
|
|
1833
|
-
const shape = def.shape;
|
|
2366
|
+
defineLazyInternal(inst, "propValues", (zod) => {
|
|
2367
|
+
const shape = zod.def.shape;
|
|
1834
2368
|
const propValues = {};
|
|
1835
2369
|
for (const key in shape) {
|
|
1836
2370
|
const field = shape[key]._zod;
|
|
1837
2371
|
if (field.values) {
|
|
1838
|
-
propValues
|
|
2372
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, key)) assignProp(propValues, key, /* @__PURE__ */ new Set());
|
|
1839
2373
|
for (const v of field.values) propValues[key].add(v);
|
|
2374
|
+
if (field.optin !== void 0) propValues[key].add(void 0);
|
|
1840
2375
|
}
|
|
1841
2376
|
}
|
|
1842
2377
|
return propValues;
|
|
1843
2378
|
});
|
|
1844
|
-
const isObject$
|
|
2379
|
+
const isObject$1 = isObject;
|
|
1845
2380
|
const catchall = def.catchall;
|
|
1846
2381
|
let value;
|
|
2382
|
+
const memo = globalConfig.memoizer;
|
|
2383
|
+
memo?.attach(inst);
|
|
1847
2384
|
inst._zod.parse = (payload, ctx) => {
|
|
1848
2385
|
value ?? (value = _normalized.value);
|
|
1849
2386
|
const input = payload.value;
|
|
1850
|
-
if (!isObject$
|
|
2387
|
+
if (!isObject$1(input)) {
|
|
1851
2388
|
payload.issues.push({
|
|
1852
2389
|
expected: "object",
|
|
1853
2390
|
code: "invalid_type",
|
|
@@ -1856,92 +2393,128 @@ const $ZodObject = /* @__PURE__ */ $constructor("$ZodObject", (inst, def) => {
|
|
|
1856
2393
|
});
|
|
1857
2394
|
return payload;
|
|
1858
2395
|
}
|
|
1859
|
-
payload.value = {};
|
|
2396
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
1860
2397
|
const proms = [];
|
|
1861
2398
|
const shape = value.shape;
|
|
1862
|
-
|
|
2399
|
+
const abortEarly = ctx?.abortEarly;
|
|
2400
|
+
let seen = payload.issues.length;
|
|
2401
|
+
for (const key of value.allKeys) {
|
|
2402
|
+
if (abortEarly && payload.issues.length !== seen) {
|
|
2403
|
+
if (aborted(payload, seen)) break;
|
|
2404
|
+
seen = payload.issues.length;
|
|
2405
|
+
}
|
|
2406
|
+
if (key === "__proto__") continue;
|
|
1863
2407
|
const el = shape[key];
|
|
1864
|
-
const
|
|
2408
|
+
const optin = el._zod.optin;
|
|
2409
|
+
const optout = el._zod.optout;
|
|
1865
2410
|
const r = el._zod.run({
|
|
1866
2411
|
value: input[key],
|
|
1867
2412
|
issues: []
|
|
1868
2413
|
}, ctx);
|
|
1869
|
-
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input,
|
|
1870
|
-
else handlePropertyResult(r, payload, key, input,
|
|
2414
|
+
if (r instanceof Promise) proms.push(r.then((r) => handlePropertyResult(r, payload, key, input, optin, optout)));
|
|
2415
|
+
else handlePropertyResult(r, payload, key, input, optin, optout);
|
|
1871
2416
|
}
|
|
1872
2417
|
if (!catchall) return proms.length ? Promise.all(proms).then(() => payload) : payload;
|
|
1873
|
-
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst);
|
|
2418
|
+
return handleCatchall(proms, input, payload, ctx, _normalized.value, inst, abortEarly === true);
|
|
1874
2419
|
};
|
|
1875
2420
|
});
|
|
1876
2421
|
const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def) => {
|
|
1877
2422
|
$ZodObject.init(inst, def);
|
|
1878
2423
|
const superParse = inst._zod.parse;
|
|
1879
2424
|
const _normalized = cached(() => normalizeDef(def));
|
|
2425
|
+
const memo = globalConfig.memoizer;
|
|
1880
2426
|
const generateFastpass = (shape) => {
|
|
1881
|
-
const doc = new Doc([
|
|
1882
|
-
"shape",
|
|
1883
|
-
"payload",
|
|
1884
|
-
"ctx"
|
|
1885
|
-
]);
|
|
1886
2427
|
const normalized = _normalized.value;
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
2428
|
+
const syms = normalized.symbolKeys;
|
|
2429
|
+
const doc = new Doc(["payload", "ctx"], {
|
|
2430
|
+
shape,
|
|
2431
|
+
inst,
|
|
2432
|
+
memo,
|
|
2433
|
+
syms
|
|
2434
|
+
});
|
|
2435
|
+
const parseStr = (k) => `shape[${k}]._zod.run({ value: input[${k}], issues: [] }, ctx)`;
|
|
2436
|
+
const prefixStr = (id, k) => `
|
|
2437
|
+
let ${id}_ab = false;
|
|
2438
|
+
for (let i = 0; i < ${id}.issues.length; i++) {
|
|
2439
|
+
const iss = ${id}.issues[i];
|
|
2440
|
+
iss.path = iss.path ? [${k}, ...iss.path] : [${k}];
|
|
2441
|
+
payload.issues.push(iss);
|
|
2442
|
+
if (iss.continue !== true) ${id}_ab = true;
|
|
2443
|
+
}
|
|
2444
|
+
if (${id}_ab && ctx && ctx.abortEarly) {
|
|
2445
|
+
payload.value = newResult;
|
|
2446
|
+
return payload;
|
|
2447
|
+
}`;
|
|
1891
2448
|
doc.write(`const input = payload.value;`);
|
|
1892
2449
|
const ids = Object.create(null);
|
|
1893
2450
|
let counter = 0;
|
|
1894
|
-
for (const key of normalized.
|
|
1895
|
-
doc.write(`const newResult = {};`);
|
|
1896
|
-
for (const key of normalized.
|
|
2451
|
+
for (const key of normalized.allKeys) ids[key] = `key_${counter++}`;
|
|
2452
|
+
doc.write(memo ? `const newResult = memo.alloc(inst, payload, {}, ctx);` : `const newResult = {};`);
|
|
2453
|
+
for (const key of normalized.allKeys) {
|
|
2454
|
+
if (key === "__proto__") continue;
|
|
1897
2455
|
const id = ids[key];
|
|
1898
|
-
const k = esc(key);
|
|
1899
|
-
const
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
2456
|
+
const k = typeof key === "symbol" ? `syms[${syms.indexOf(key)}]` : esc(key);
|
|
2457
|
+
const isPresent = `${k} in input`;
|
|
2458
|
+
const schema = shape[key];
|
|
2459
|
+
const optin = schema?._zod?.optin;
|
|
2460
|
+
const isOptionalIn = optin !== void 0;
|
|
2461
|
+
const isOptionalOut = schema?._zod?.optout === "optional";
|
|
2462
|
+
doc.write(`const ${id} = ${parseStr(k)};`);
|
|
2463
|
+
if (isOptionalIn && isOptionalOut) {
|
|
2464
|
+
const assign = optin === "optional" ? `${id}_present` : `${id}.value !== undefined || ${id}_present`;
|
|
2465
|
+
doc.write(`
|
|
2466
|
+
const ${id}_present = ${isPresent};
|
|
2467
|
+
if (!${id}.issues.length || ${id}_present) {
|
|
2468
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1908
2469
|
}
|
|
2470
|
+
|
|
2471
|
+
if (${assign}) {
|
|
2472
|
+
newResult[${k}] = ${id}.value;
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
|
|
2476
|
+
`);
|
|
2477
|
+
} else if (!isOptionalIn) doc.write(`
|
|
2478
|
+
const ${id}_present = ${isPresent};
|
|
2479
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1909
2480
|
}
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
2481
|
+
if (!${id}_present && !${id}.issues.length) {
|
|
2482
|
+
payload.issues.push({
|
|
2483
|
+
code: "invalid_type",
|
|
2484
|
+
expected: "nonoptional",
|
|
2485
|
+
input: undefined,
|
|
2486
|
+
path: [${k}]
|
|
2487
|
+
});
|
|
2488
|
+
if (ctx && ctx.abortEarly) {
|
|
2489
|
+
payload.value = newResult;
|
|
2490
|
+
return payload;
|
|
1914
2491
|
}
|
|
1915
|
-
}
|
|
2492
|
+
}
|
|
2493
|
+
|
|
2494
|
+
if (${id}_present) {
|
|
1916
2495
|
newResult[${k}] = ${id}.value;
|
|
1917
2496
|
}
|
|
1918
|
-
|
|
2497
|
+
|
|
1919
2498
|
`);
|
|
1920
|
-
else
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
...iss,
|
|
1924
|
-
path: iss.path ? [${k}, ...iss.path] : [${k}]
|
|
1925
|
-
})));
|
|
2499
|
+
else {
|
|
2500
|
+
doc.write(`
|
|
2501
|
+
if (${id}.issues.length) {${prefixStr(id, k)}
|
|
1926
2502
|
}
|
|
1927
|
-
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
}
|
|
1932
|
-
} else {
|
|
2503
|
+
`);
|
|
2504
|
+
if (optin === "defaulted") doc.write(`newResult[${k}] = ${id}.value;`);
|
|
2505
|
+
else doc.write(`
|
|
2506
|
+
if (${id}.value !== undefined || ${isPresent}) {
|
|
1933
2507
|
newResult[${k}] = ${id}.value;
|
|
1934
2508
|
}
|
|
1935
|
-
|
|
1936
2509
|
`);
|
|
2510
|
+
}
|
|
1937
2511
|
}
|
|
1938
2512
|
doc.write(`payload.value = newResult;`);
|
|
1939
2513
|
doc.write(`return payload;`);
|
|
1940
|
-
|
|
1941
|
-
return (payload, ctx) => fn(shape, payload, ctx);
|
|
2514
|
+
return doc.compile();
|
|
1942
2515
|
};
|
|
1943
2516
|
let fastpass;
|
|
1944
|
-
const isObject$
|
|
2517
|
+
const isObject$2 = isObject;
|
|
1945
2518
|
const jit = !globalConfig.jitless;
|
|
1946
2519
|
const fastEnabled = jit && allowsEval.value;
|
|
1947
2520
|
const catchall = def.catchall;
|
|
@@ -1949,7 +2522,7 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
|
|
|
1949
2522
|
inst._zod.parse = (payload, ctx) => {
|
|
1950
2523
|
value ?? (value = _normalized.value);
|
|
1951
2524
|
const input = payload.value;
|
|
1952
|
-
if (!isObject$
|
|
2525
|
+
if (!isObject$2(input)) {
|
|
1953
2526
|
payload.issues.push({
|
|
1954
2527
|
expected: "object",
|
|
1955
2528
|
code: "invalid_type",
|
|
@@ -1962,7 +2535,7 @@ const $ZodObjectJIT = /* @__PURE__ */ $constructor("$ZodObjectJIT", (inst, def)
|
|
|
1962
2535
|
if (!fastpass) fastpass = generateFastpass(def.shape);
|
|
1963
2536
|
payload = fastpass(payload, ctx);
|
|
1964
2537
|
if (!catchall) return payload;
|
|
1965
|
-
return handleCatchall([], input, payload, ctx, value, inst);
|
|
2538
|
+
return handleCatchall([], input, payload, ctx, value, inst, ctx?.abortEarly === true);
|
|
1966
2539
|
}
|
|
1967
2540
|
return superParse(payload, ctx);
|
|
1968
2541
|
};
|
|
@@ -1987,21 +2560,20 @@ function handleUnionResults(results, final, inst, ctx) {
|
|
|
1987
2560
|
}
|
|
1988
2561
|
const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
1989
2562
|
$ZodType.init(inst, def);
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
if (def.options.every((o) => o._zod.values)) return new Set(def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
1994
|
-
});
|
|
1995
|
-
|
|
1996
|
-
if (def.options.every((o) => o._zod.pattern)) {
|
|
1997
|
-
const patterns = def.options.map((o) => o._zod.pattern);
|
|
2563
|
+
defineLazyInternal(inst, "optin", (zod) => zod.def.options.some((o) => o._zod.optin === "defaulted") ? "defaulted" : zod.def.options.some((o) => o._zod.optin !== void 0) ? "optional" : void 0);
|
|
2564
|
+
defineLazyInternal(inst, "optout", (zod) => zod.def.options.some((o) => o._zod.optout === "optional") ? "optional" : void 0);
|
|
2565
|
+
defineLazyInternal(inst, "values", (zod) => {
|
|
2566
|
+
if (zod.def.options.every((o) => o._zod.values)) return new Set(zod.def.options.flatMap((option) => Array.from(option._zod.values)));
|
|
2567
|
+
});
|
|
2568
|
+
defineLazyInternal(inst, "pattern", (zod) => {
|
|
2569
|
+
if (zod.def.options.every((o) => o._zod.pattern)) {
|
|
2570
|
+
const patterns = zod.def.options.map((o) => o._zod.pattern);
|
|
1998
2571
|
return new RegExp(`^(${patterns.map((p) => cleanRegex(p.source)).join("|")})$`);
|
|
1999
2572
|
}
|
|
2000
2573
|
});
|
|
2001
|
-
const
|
|
2002
|
-
const first = def.options[0]._zod.run;
|
|
2574
|
+
const first = def.options.length === 1 ? def.options[0]._zod.run : null;
|
|
2003
2575
|
inst._zod.parse = (payload, ctx) => {
|
|
2004
|
-
if (
|
|
2576
|
+
if (first) return first(payload, ctx);
|
|
2005
2577
|
let async = false;
|
|
2006
2578
|
const results = [];
|
|
2007
2579
|
for (const option of def.options) {
|
|
@@ -2023,35 +2595,42 @@ const $ZodUnion = /* @__PURE__ */ $constructor("$ZodUnion", (inst, def) => {
|
|
|
2023
2595
|
});
|
|
2024
2596
|
};
|
|
2025
2597
|
});
|
|
2598
|
+
function discriminatorMap(def) {
|
|
2599
|
+
const map = /* @__PURE__ */ new Map();
|
|
2600
|
+
for (const option of def.options) {
|
|
2601
|
+
const values = option._zod.propValues?.[def.discriminator];
|
|
2602
|
+
if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2603
|
+
for (const value of values) if (map.has(value)) {
|
|
2604
|
+
if (value !== void 0) throw new Error(`Duplicate discriminator value "${String(value)}"`);
|
|
2605
|
+
map.set(value, null);
|
|
2606
|
+
} else map.set(value, option);
|
|
2607
|
+
}
|
|
2608
|
+
return map;
|
|
2609
|
+
}
|
|
2026
2610
|
const $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUnion", (inst, def) => {
|
|
2027
2611
|
def.inclusive = false;
|
|
2028
2612
|
$ZodUnion.init(inst, def);
|
|
2029
2613
|
const _super = inst._zod.parse;
|
|
2030
|
-
|
|
2614
|
+
defineLazyInternal(inst, "propValues", (zod) => {
|
|
2031
2615
|
const propValues = {};
|
|
2032
|
-
|
|
2616
|
+
let undefinedCount = 0;
|
|
2617
|
+
for (const option of zod.def.options) {
|
|
2033
2618
|
const pv = option._zod.propValues;
|
|
2034
|
-
if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(option)}"`);
|
|
2619
|
+
if (!pv || Object.keys(pv).length === 0) throw new Error(`Invalid discriminated union option at index "${zod.def.options.indexOf(option)}"`);
|
|
2620
|
+
if (pv[zod.def.discriminator]?.has(void 0)) undefinedCount++;
|
|
2035
2621
|
for (const [k, v] of Object.entries(pv)) {
|
|
2036
|
-
if (!propValues
|
|
2622
|
+
if (!Object.prototype.hasOwnProperty.call(propValues, k)) assignProp(propValues, k, /* @__PURE__ */ new Set());
|
|
2037
2623
|
for (const val of v) propValues[k].add(val);
|
|
2038
2624
|
}
|
|
2039
2625
|
}
|
|
2626
|
+
if (!zod.def.unionFallback && undefinedCount > 1) propValues[zod.def.discriminator]?.delete(void 0);
|
|
2040
2627
|
return propValues;
|
|
2041
2628
|
});
|
|
2042
|
-
|
|
2043
|
-
const
|
|
2044
|
-
|
|
2045
|
-
for (const o of opts) {
|
|
2046
|
-
const values = o._zod.propValues?.[def.discriminator];
|
|
2047
|
-
if (!values || values.size === 0) throw new Error(`Invalid discriminated union option at index "${def.options.indexOf(o)}"`);
|
|
2048
|
-
for (const v of values) {
|
|
2049
|
-
if (map.has(v)) throw new Error(`Duplicate discriminator value "${String(v)}"`);
|
|
2050
|
-
map.set(v, o);
|
|
2051
|
-
}
|
|
2052
|
-
}
|
|
2053
|
-
return map;
|
|
2629
|
+
def.options.forEach((option, i) => {
|
|
2630
|
+
const propShape = rawShape(option._zod.def);
|
|
2631
|
+
if (propShape && !Object.prototype.hasOwnProperty.call(propShape, def.discriminator)) throw new Error(`Invalid discriminated union option at index "${i}"`);
|
|
2054
2632
|
});
|
|
2633
|
+
const disc = cached(() => discriminatorMap(def));
|
|
2055
2634
|
inst._zod.parse = (payload, ctx) => {
|
|
2056
2635
|
const input = payload.value;
|
|
2057
2636
|
if (!isObject(input)) {
|
|
@@ -2063,14 +2642,16 @@ const $ZodDiscriminatedUnion = /* @__PURE__ */ $constructor("$ZodDiscriminatedUn
|
|
|
2063
2642
|
});
|
|
2064
2643
|
return payload;
|
|
2065
2644
|
}
|
|
2066
|
-
const
|
|
2067
|
-
|
|
2068
|
-
if (
|
|
2645
|
+
const value = input?.[def.discriminator];
|
|
2646
|
+
const opt = disc.value.get(value);
|
|
2647
|
+
if (opt && (value !== void 0 || ctx.direction !== "backward")) return opt._zod.run(payload, ctx);
|
|
2648
|
+
if (def.unionFallback || ctx.direction === "backward") return _super(payload, ctx);
|
|
2069
2649
|
payload.issues.push({
|
|
2070
2650
|
code: "invalid_union",
|
|
2071
2651
|
errors: [],
|
|
2072
2652
|
note: "No matching discriminator",
|
|
2073
2653
|
discriminator: def.discriminator,
|
|
2654
|
+
options: Array.from(disc.value.keys()).filter((value) => disc.value.get(value) !== null),
|
|
2074
2655
|
input,
|
|
2075
2656
|
path: [def.discriminator],
|
|
2076
2657
|
inst
|
|
@@ -2112,7 +2693,9 @@ function mergeValues(a, b) {
|
|
|
2112
2693
|
...a,
|
|
2113
2694
|
...b
|
|
2114
2695
|
};
|
|
2696
|
+
if (Object.prototype.hasOwnProperty.call(newObj, "__proto__")) delete newObj.__proto__;
|
|
2115
2697
|
for (const key of sharedKeys) {
|
|
2698
|
+
if (key === "__proto__") continue;
|
|
2116
2699
|
const sharedValue = mergeValues(a[key], b[key]);
|
|
2117
2700
|
if (!sharedValue.valid) return {
|
|
2118
2701
|
valid: false,
|
|
@@ -2154,31 +2737,46 @@ function mergeValues(a, b) {
|
|
|
2154
2737
|
function handleIntersectionResults(result, left, right) {
|
|
2155
2738
|
const unrecKeys = /* @__PURE__ */ new Map();
|
|
2156
2739
|
let unrecIssue;
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2740
|
+
const keyIssues = /* @__PURE__ */ new Map();
|
|
2741
|
+
const collect = (iss, side) => {
|
|
2742
|
+
let keys;
|
|
2743
|
+
if (iss.code === "unrecognized_keys" && !iss.path?.length) {
|
|
2744
|
+
unrecIssue ?? (unrecIssue = iss);
|
|
2745
|
+
keys = iss.keys;
|
|
2746
|
+
} else if (iss.code === "invalid_key" && iss.origin === "record" && iss.path?.length === 1) {
|
|
2747
|
+
const k = String(iss.path[0]);
|
|
2748
|
+
if (!keyIssues.has(k)) keyIssues.set(k, iss);
|
|
2749
|
+
keys = [k];
|
|
2750
|
+
} else return false;
|
|
2751
|
+
for (const k of keys) {
|
|
2160
2752
|
if (!unrecKeys.has(k)) unrecKeys.set(k, {});
|
|
2161
|
-
unrecKeys.get(k)
|
|
2753
|
+
unrecKeys.get(k)[side] = true;
|
|
2162
2754
|
}
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
}
|
|
2168
|
-
else result.issues.push(iss);
|
|
2755
|
+
return true;
|
|
2756
|
+
};
|
|
2757
|
+
for (const iss of left.issues) if (!collect(iss, "l")) result.issues.push(iss);
|
|
2758
|
+
for (const iss of right.issues) if (!collect(iss, "r")) result.issues.push(iss);
|
|
2169
2759
|
const bothKeys = [...unrecKeys].filter(([, f]) => f.l && f.r).map(([k]) => k);
|
|
2170
|
-
if (bothKeys.length
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2760
|
+
if (bothKeys.length) {
|
|
2761
|
+
const aggregated = unrecIssue ? bothKeys.filter((k) => unrecIssue.keys.includes(k)) : [];
|
|
2762
|
+
if (aggregated.length) result.issues.push({
|
|
2763
|
+
...unrecIssue,
|
|
2764
|
+
keys: aggregated
|
|
2765
|
+
});
|
|
2766
|
+
for (const k of bothKeys) if (!aggregated.includes(k) && keyIssues.has(k)) result.issues.push(keyIssues.get(k));
|
|
2767
|
+
}
|
|
2175
2768
|
const merged = mergeValues(left.value, right.value);
|
|
2176
|
-
if (!merged.valid)
|
|
2769
|
+
if (!merged.valid) {
|
|
2770
|
+
if (aborted(result)) return result;
|
|
2771
|
+
throw new Error(`Unmergable intersection. Error path: ${JSON.stringify(merged.mergeErrorPath)}`);
|
|
2772
|
+
}
|
|
2177
2773
|
result.value = merged.data;
|
|
2178
2774
|
return result;
|
|
2179
2775
|
}
|
|
2180
2776
|
const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
2181
2777
|
$ZodType.init(inst, def);
|
|
2778
|
+
const memo = globalConfig.memoizer;
|
|
2779
|
+
memo?.attach(inst);
|
|
2182
2780
|
inst._zod.parse = (payload, ctx) => {
|
|
2183
2781
|
const input = payload.value;
|
|
2184
2782
|
if (!isPlainObject(input)) {
|
|
@@ -2192,26 +2790,48 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
2192
2790
|
}
|
|
2193
2791
|
const proms = [];
|
|
2194
2792
|
const values = def.keyType._zod.values;
|
|
2195
|
-
if (values) {
|
|
2196
|
-
payload.value = {};
|
|
2793
|
+
if (values && !def.partial) {
|
|
2794
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
2197
2795
|
const recordKeys = /* @__PURE__ */ new Set();
|
|
2198
2796
|
for (const key of values) if (typeof key === "string" || typeof key === "number" || typeof key === "symbol") {
|
|
2199
2797
|
recordKeys.add(typeof key === "number" ? key.toString() : key);
|
|
2798
|
+
if (key === "__proto__") continue;
|
|
2799
|
+
const keyResult = def.keyType._zod.run({
|
|
2800
|
+
value: key,
|
|
2801
|
+
issues: []
|
|
2802
|
+
}, ctx);
|
|
2803
|
+
if (keyResult instanceof Promise) throw new Error("Async schemas not supported in object keys currently");
|
|
2804
|
+
if (keyResult.issues.length) {
|
|
2805
|
+
payload.issues.push({
|
|
2806
|
+
code: "invalid_key",
|
|
2807
|
+
origin: "record",
|
|
2808
|
+
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
2809
|
+
input: key,
|
|
2810
|
+
path: [key],
|
|
2811
|
+
inst
|
|
2812
|
+
});
|
|
2813
|
+
continue;
|
|
2814
|
+
}
|
|
2815
|
+
const outKey = keyResult.value;
|
|
2816
|
+
if (outKey === "__proto__") continue;
|
|
2200
2817
|
const result = def.valueType._zod.run({
|
|
2201
2818
|
value: input[key],
|
|
2202
2819
|
issues: []
|
|
2203
2820
|
}, ctx);
|
|
2204
2821
|
if (result instanceof Promise) proms.push(result.then((result) => {
|
|
2205
2822
|
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
2206
|
-
payload.value[
|
|
2823
|
+
payload.value[outKey] = result.value;
|
|
2207
2824
|
}));
|
|
2208
2825
|
else {
|
|
2209
2826
|
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
2210
|
-
payload.value[
|
|
2827
|
+
payload.value[outKey] = result.value;
|
|
2211
2828
|
}
|
|
2212
2829
|
}
|
|
2213
2830
|
let unrecognized;
|
|
2214
|
-
for (const key in input) if (!recordKeys.has(key)) {
|
|
2831
|
+
for (const key in input) if (!recordKeys.has(key)) if (def.mode === "loose") {
|
|
2832
|
+
if (key === "__proto__") continue;
|
|
2833
|
+
payload.value[key] = input[key];
|
|
2834
|
+
} else {
|
|
2215
2835
|
unrecognized = unrecognized ?? [];
|
|
2216
2836
|
unrecognized.push(key);
|
|
2217
2837
|
}
|
|
@@ -2219,12 +2839,15 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
2219
2839
|
code: "unrecognized_keys",
|
|
2220
2840
|
input,
|
|
2221
2841
|
inst,
|
|
2222
|
-
keys: unrecognized
|
|
2842
|
+
keys: unrecognized,
|
|
2843
|
+
continue: true
|
|
2223
2844
|
});
|
|
2224
2845
|
} else {
|
|
2225
|
-
payload.value = {};
|
|
2846
|
+
payload.value = memo ? memo.alloc(inst, payload, {}, ctx) : {};
|
|
2847
|
+
let unrecognized;
|
|
2226
2848
|
for (const key of Reflect.ownKeys(input)) {
|
|
2227
2849
|
if (key === "__proto__") continue;
|
|
2850
|
+
if (!Object.prototype.propertyIsEnumerable.call(input, key)) continue;
|
|
2228
2851
|
let keyResult = def.keyType._zod.run({
|
|
2229
2852
|
value: key,
|
|
2230
2853
|
issues: []
|
|
@@ -2240,7 +2863,10 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
2240
2863
|
}
|
|
2241
2864
|
if (keyResult.issues.length) {
|
|
2242
2865
|
if (def.mode === "loose") payload.value[key] = input[key];
|
|
2243
|
-
else
|
|
2866
|
+
else if (values) {
|
|
2867
|
+
unrecognized = unrecognized ?? [];
|
|
2868
|
+
unrecognized.push(key);
|
|
2869
|
+
} else payload.issues.push({
|
|
2244
2870
|
code: "invalid_key",
|
|
2245
2871
|
origin: "record",
|
|
2246
2872
|
issues: keyResult.issues.map((iss) => finalizeIssue(iss, ctx, config())),
|
|
@@ -2250,19 +2876,28 @@ const $ZodRecord = /* @__PURE__ */ $constructor("$ZodRecord", (inst, def) => {
|
|
|
2250
2876
|
});
|
|
2251
2877
|
continue;
|
|
2252
2878
|
}
|
|
2879
|
+
const outKey = keyResult.value;
|
|
2880
|
+
if (outKey === "__proto__") continue;
|
|
2253
2881
|
const result = def.valueType._zod.run({
|
|
2254
2882
|
value: input[key],
|
|
2255
2883
|
issues: []
|
|
2256
2884
|
}, ctx);
|
|
2257
2885
|
if (result instanceof Promise) proms.push(result.then((result) => {
|
|
2258
2886
|
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
2259
|
-
payload.value[
|
|
2887
|
+
payload.value[outKey] = result.value;
|
|
2260
2888
|
}));
|
|
2261
2889
|
else {
|
|
2262
2890
|
if (result.issues.length) payload.issues.push(...prefixIssues(key, result.issues));
|
|
2263
|
-
payload.value[
|
|
2891
|
+
payload.value[outKey] = result.value;
|
|
2264
2892
|
}
|
|
2265
2893
|
}
|
|
2894
|
+
if (unrecognized && unrecognized.length > 0) payload.issues.push({
|
|
2895
|
+
code: "unrecognized_keys",
|
|
2896
|
+
input,
|
|
2897
|
+
inst,
|
|
2898
|
+
keys: unrecognized,
|
|
2899
|
+
continue: true
|
|
2900
|
+
});
|
|
2266
2901
|
}
|
|
2267
2902
|
if (proms.length) return Promise.all(proms).then(() => payload);
|
|
2268
2903
|
return payload;
|
|
@@ -2273,7 +2908,10 @@ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
|
2273
2908
|
const values = getEnumValues(def.entries);
|
|
2274
2909
|
const valuesSet = new Set(values);
|
|
2275
2910
|
inst._zod.values = valuesSet;
|
|
2276
|
-
inst
|
|
2911
|
+
defineLazyInternal(inst, "pattern", (zod) => {
|
|
2912
|
+
const patternValues = getEnumValues(zod.def.entries).filter((k) => propertyKeyTypes.has(typeof k));
|
|
2913
|
+
return new RegExp(patternValues.length ? `^(${patternValues.map((o) => escapeRegex(o.toString())).join("|")})$` : "^[^\\s\\S]$");
|
|
2914
|
+
});
|
|
2277
2915
|
inst._zod.parse = (payload, _ctx) => {
|
|
2278
2916
|
const input = payload.value;
|
|
2279
2917
|
if (valuesSet.has(input)) return payload;
|
|
@@ -2288,10 +2926,12 @@ const $ZodEnum = /* @__PURE__ */ $constructor("$ZodEnum", (inst, def) => {
|
|
|
2288
2926
|
});
|
|
2289
2927
|
const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
2290
2928
|
$ZodType.init(inst, def);
|
|
2291
|
-
if (def.values.length === 0) throw new Error("Cannot create literal schema with no valid values");
|
|
2292
2929
|
const values = new Set(def.values);
|
|
2293
2930
|
inst._zod.values = values;
|
|
2294
|
-
inst
|
|
2931
|
+
defineLazyInternal(inst, "pattern", (zod) => {
|
|
2932
|
+
const vals = zod.def.values;
|
|
2933
|
+
return new RegExp(vals.length ? `^(${vals.map((o) => typeof o === "string" ? escapeRegex(o) : o ? escapeRegex(o.toString()) : String(o)).join("|")})$` : "^[^\\s\\S]$");
|
|
2934
|
+
});
|
|
2295
2935
|
inst._zod.parse = (payload, _ctx) => {
|
|
2296
2936
|
const input = payload.value;
|
|
2297
2937
|
if (values.has(input)) return payload;
|
|
@@ -2306,6 +2946,8 @@ const $ZodLiteral = /* @__PURE__ */ $constructor("$ZodLiteral", (inst, def) => {
|
|
|
2306
2946
|
});
|
|
2307
2947
|
const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def) => {
|
|
2308
2948
|
$ZodType.init(inst, def);
|
|
2949
|
+
inst._zod.optin = "optional";
|
|
2950
|
+
globalConfig.memoizer?.guard(inst);
|
|
2309
2951
|
inst._zod.parse = (payload, ctx) => {
|
|
2310
2952
|
if (ctx.direction === "backward") throw new $ZodEncodeError(inst.constructor.name);
|
|
2311
2953
|
const _out = def.transform(payload.value, payload);
|
|
@@ -2318,52 +2960,53 @@ const $ZodTransform = /* @__PURE__ */ $constructor("$ZodTransform", (inst, def)
|
|
|
2318
2960
|
return payload;
|
|
2319
2961
|
};
|
|
2320
2962
|
});
|
|
2321
|
-
function handleOptionalResult(
|
|
2322
|
-
|
|
2323
|
-
|
|
2324
|
-
value: void 0
|
|
2325
|
-
};
|
|
2326
|
-
return result;
|
|
2963
|
+
function handleOptionalResult(payload, result) {
|
|
2964
|
+
payload.value = result.issues.length ? void 0 : result.value;
|
|
2965
|
+
return payload;
|
|
2327
2966
|
}
|
|
2328
2967
|
const $ZodOptional = /* @__PURE__ */ $constructor("$ZodOptional", (inst, def) => {
|
|
2329
2968
|
$ZodType.init(inst, def);
|
|
2330
|
-
inst._zod.optin
|
|
2969
|
+
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
|
|
2331
2970
|
inst._zod.optout = "optional";
|
|
2332
|
-
|
|
2333
|
-
|
|
2971
|
+
defineLazyInternal(inst, "values", (zod) => {
|
|
2972
|
+
const values = zod.def.innerType._zod.values;
|
|
2973
|
+
return values ? new Set([...values, void 0]) : void 0;
|
|
2334
2974
|
});
|
|
2335
|
-
|
|
2336
|
-
const pattern = def.innerType._zod.pattern;
|
|
2975
|
+
defineLazyInternal(inst, "pattern", (zod) => {
|
|
2976
|
+
const pattern = zod.def.innerType._zod.pattern;
|
|
2337
2977
|
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)})?$`) : void 0;
|
|
2338
2978
|
});
|
|
2339
2979
|
inst._zod.parse = (payload, ctx) => {
|
|
2340
|
-
if (
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2980
|
+
if (payload.value === void 0) {
|
|
2981
|
+
if (def.innerType._zod.optin !== "defaulted") return payload;
|
|
2982
|
+
const result = def.innerType._zod.run({
|
|
2983
|
+
value: payload.value,
|
|
2984
|
+
issues: []
|
|
2985
|
+
}, ctx);
|
|
2986
|
+
if (result instanceof Promise) return result.then((result) => handleOptionalResult(payload, result));
|
|
2987
|
+
return handleOptionalResult(payload, result);
|
|
2344
2988
|
}
|
|
2345
|
-
if (payload.value === void 0) return payload;
|
|
2346
2989
|
return def.innerType._zod.run(payload, ctx);
|
|
2347
2990
|
};
|
|
2348
2991
|
});
|
|
2349
2992
|
const $ZodExactOptional = /* @__PURE__ */ $constructor("$ZodExactOptional", (inst, def) => {
|
|
2350
2993
|
$ZodOptional.init(inst, def);
|
|
2351
|
-
|
|
2352
|
-
|
|
2994
|
+
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
2995
|
+
defineLazyInternal(inst, "pattern", (zod) => zod.def.innerType._zod.pattern);
|
|
2353
2996
|
inst._zod.parse = (payload, ctx) => {
|
|
2354
2997
|
return def.innerType._zod.run(payload, ctx);
|
|
2355
2998
|
};
|
|
2356
2999
|
});
|
|
2357
3000
|
const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) => {
|
|
2358
3001
|
$ZodType.init(inst, def);
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
|
|
2362
|
-
const pattern = def.innerType._zod.pattern;
|
|
3002
|
+
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin);
|
|
3003
|
+
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
|
|
3004
|
+
defineLazyInternal(inst, "pattern", (zod) => {
|
|
3005
|
+
const pattern = zod.def.innerType._zod.pattern;
|
|
2363
3006
|
return pattern ? new RegExp(`^(${cleanRegex(pattern.source)}|null)$`) : void 0;
|
|
2364
3007
|
});
|
|
2365
|
-
|
|
2366
|
-
return def.innerType._zod.values ? new Set([...def.innerType._zod.values, null]) : void 0;
|
|
3008
|
+
defineLazyInternal(inst, "values", (zod) => {
|
|
3009
|
+
return zod.def.innerType._zod.values ? new Set([...zod.def.innerType._zod.values, null]) : void 0;
|
|
2367
3010
|
});
|
|
2368
3011
|
inst._zod.parse = (payload, ctx) => {
|
|
2369
3012
|
if (payload.value === null) return payload;
|
|
@@ -2372,8 +3015,8 @@ const $ZodNullable = /* @__PURE__ */ $constructor("$ZodNullable", (inst, def) =>
|
|
|
2372
3015
|
});
|
|
2373
3016
|
const $ZodDefault = /* @__PURE__ */ $constructor("$ZodDefault", (inst, def) => {
|
|
2374
3017
|
$ZodType.init(inst, def);
|
|
2375
|
-
inst._zod.optin = "
|
|
2376
|
-
|
|
3018
|
+
inst._zod.optin = "defaulted";
|
|
3019
|
+
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
2377
3020
|
inst._zod.parse = (payload, ctx) => {
|
|
2378
3021
|
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
|
|
2379
3022
|
if (payload.value === void 0) {
|
|
@@ -2394,8 +3037,8 @@ function handleDefaultResult(payload, def) {
|
|
|
2394
3037
|
}
|
|
2395
3038
|
const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) => {
|
|
2396
3039
|
$ZodType.init(inst, def);
|
|
2397
|
-
inst._zod.optin = "
|
|
2398
|
-
|
|
3040
|
+
inst._zod.optin = "defaulted";
|
|
3041
|
+
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
2399
3042
|
inst._zod.parse = (payload, ctx) => {
|
|
2400
3043
|
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
|
|
2401
3044
|
if (payload.value === void 0) payload.value = def.defaultValue;
|
|
@@ -2404,8 +3047,8 @@ const $ZodPrefault = /* @__PURE__ */ $constructor("$ZodPrefault", (inst, def) =>
|
|
|
2404
3047
|
});
|
|
2405
3048
|
const $ZodNonOptional = /* @__PURE__ */ $constructor("$ZodNonOptional", (inst, def) => {
|
|
2406
3049
|
$ZodType.init(inst, def);
|
|
2407
|
-
|
|
2408
|
-
const v = def.innerType._zod.values;
|
|
3050
|
+
defineLazyInternal(inst, "values", (zod) => {
|
|
3051
|
+
const v = zod.def.innerType._zod.values;
|
|
2409
3052
|
return v ? new Set([...v].filter((x) => x !== void 0)) : void 0;
|
|
2410
3053
|
});
|
|
2411
3054
|
inst._zod.parse = (payload, ctx) => {
|
|
@@ -2423,44 +3066,41 @@ function handleNonOptionalResult(payload, inst) {
|
|
|
2423
3066
|
});
|
|
2424
3067
|
return payload;
|
|
2425
3068
|
}
|
|
3069
|
+
function handleCatchResult(payload, result, def, ctx) {
|
|
3070
|
+
if (!result.issues.length) {
|
|
3071
|
+
payload.value = result.value;
|
|
3072
|
+
if (result.memo) payload.memo = true;
|
|
3073
|
+
return payload;
|
|
3074
|
+
}
|
|
3075
|
+
payload.value = def.catchValue({
|
|
3076
|
+
...result,
|
|
3077
|
+
value: payload.value,
|
|
3078
|
+
error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
|
|
3079
|
+
input: payload.value
|
|
3080
|
+
});
|
|
3081
|
+
return payload;
|
|
3082
|
+
}
|
|
2426
3083
|
const $ZodCatch = /* @__PURE__ */ $constructor("$ZodCatch", (inst, def) => {
|
|
2427
3084
|
$ZodType.init(inst, def);
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
3085
|
+
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType._zod.optin === "defaulted" ? "defaulted" : "optional");
|
|
3086
|
+
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType._zod.optout);
|
|
3087
|
+
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
2431
3088
|
inst._zod.parse = (payload, ctx) => {
|
|
2432
3089
|
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
|
|
2433
|
-
const result = def.innerType._zod.run(
|
|
2434
|
-
|
|
2435
|
-
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
|
|
2440
|
-
input: payload.value
|
|
2441
|
-
});
|
|
2442
|
-
payload.issues = [];
|
|
2443
|
-
}
|
|
2444
|
-
return payload;
|
|
2445
|
-
});
|
|
2446
|
-
payload.value = result.value;
|
|
2447
|
-
if (result.issues.length) {
|
|
2448
|
-
payload.value = def.catchValue({
|
|
2449
|
-
...payload,
|
|
2450
|
-
error: { issues: result.issues.map((iss) => finalizeIssue(iss, ctx, config())) },
|
|
2451
|
-
input: payload.value
|
|
2452
|
-
});
|
|
2453
|
-
payload.issues = [];
|
|
2454
|
-
}
|
|
2455
|
-
return payload;
|
|
3090
|
+
const result = def.innerType._zod.run({
|
|
3091
|
+
value: payload.value,
|
|
3092
|
+
issues: []
|
|
3093
|
+
}, ctx);
|
|
3094
|
+
if (result instanceof Promise) return result.then((result) => handleCatchResult(payload, result, def, ctx));
|
|
3095
|
+
return handleCatchResult(payload, result, def, ctx);
|
|
2456
3096
|
};
|
|
2457
3097
|
});
|
|
2458
3098
|
const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
|
|
2459
3099
|
$ZodType.init(inst, def);
|
|
2460
|
-
|
|
2461
|
-
|
|
2462
|
-
|
|
2463
|
-
|
|
3100
|
+
defineLazyInternal(inst, "values", (zod) => zod.def.in._zod.values);
|
|
3101
|
+
defineLazyInternal(inst, "optin", (zod) => zod.def.in._zod.optin);
|
|
3102
|
+
defineLazyInternal(inst, "optout", (zod) => zod.def.out._zod.optout);
|
|
3103
|
+
defineLazyInternal(inst, "propValues", (zod) => zod.def.in._zod.propValues);
|
|
2464
3104
|
inst._zod.parse = (payload, ctx) => {
|
|
2465
3105
|
if (ctx.direction === "backward") {
|
|
2466
3106
|
const right = def.out._zod.run(payload, ctx);
|
|
@@ -2473,7 +3113,7 @@ const $ZodPipe = /* @__PURE__ */ $constructor("$ZodPipe", (inst, def) => {
|
|
|
2473
3113
|
};
|
|
2474
3114
|
});
|
|
2475
3115
|
function handlePipeResult(left, next, ctx) {
|
|
2476
|
-
if (left.issues.
|
|
3116
|
+
if (left.issues.some((iss) => iss.code !== "unrecognized_keys")) {
|
|
2477
3117
|
left.aborted = true;
|
|
2478
3118
|
return left;
|
|
2479
3119
|
}
|
|
@@ -2484,10 +3124,10 @@ function handlePipeResult(left, next, ctx) {
|
|
|
2484
3124
|
}
|
|
2485
3125
|
const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) => {
|
|
2486
3126
|
$ZodType.init(inst, def);
|
|
2487
|
-
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
3127
|
+
defineLazyInternal(inst, "propValues", (zod) => zod.def.innerType._zod.propValues);
|
|
3128
|
+
defineLazyInternal(inst, "values", (zod) => zod.def.innerType._zod.values);
|
|
3129
|
+
defineLazyInternal(inst, "optin", (zod) => zod.def.innerType?._zod?.optin);
|
|
3130
|
+
defineLazyInternal(inst, "optout", (zod) => zod.def.innerType?._zod?.optout);
|
|
2491
3131
|
inst._zod.parse = (payload, ctx) => {
|
|
2492
3132
|
if (ctx.direction === "backward") return def.innerType._zod.run(payload, ctx);
|
|
2493
3133
|
const result = def.innerType._zod.run(payload, ctx);
|
|
@@ -2496,7 +3136,7 @@ const $ZodReadonly = /* @__PURE__ */ $constructor("$ZodReadonly", (inst, def) =>
|
|
|
2496
3136
|
};
|
|
2497
3137
|
});
|
|
2498
3138
|
function handleReadonlyResult(payload) {
|
|
2499
|
-
payload.value = Object.freeze(payload.value);
|
|
3139
|
+
if (!payload.memo) payload.value = Object.freeze(payload.value);
|
|
2500
3140
|
return payload;
|
|
2501
3141
|
}
|
|
2502
3142
|
const $ZodCustom = /* @__PURE__ */ $constructor("$ZodCustom", (inst, def) => {
|
|
@@ -2525,6 +3165,363 @@ function handleRefineResult(result, payload, input, inst) {
|
|
|
2525
3165
|
payload.issues.push(issue(_iss));
|
|
2526
3166
|
}
|
|
2527
3167
|
}
|
|
3168
|
+
var $ZodCyclicError = class extends Error {
|
|
3169
|
+
constructor() {
|
|
3170
|
+
super(`Cannot parse a reference cycle that closes through a transform`);
|
|
3171
|
+
this.name = "ZodCyclicError";
|
|
3172
|
+
}
|
|
3173
|
+
};
|
|
3174
|
+
/** Keyed off the context object every schema in one parse call already shares. */
|
|
3175
|
+
const STATE = "~memo";
|
|
3176
|
+
const NO_ISSUES = [];
|
|
3177
|
+
function isRef(value) {
|
|
3178
|
+
return value !== null && typeof value === "object";
|
|
3179
|
+
}
|
|
3180
|
+
function cloneIssues(issues) {
|
|
3181
|
+
return issues.map((iss) => iss.path ? {
|
|
3182
|
+
...iss,
|
|
3183
|
+
path: iss.path.slice()
|
|
3184
|
+
} : { ...iss });
|
|
3185
|
+
}
|
|
3186
|
+
const recursive = /* @__PURE__ */ new WeakMap();
|
|
3187
|
+
/** What the walk established, in order of certainty: ordered so the strongest answer among children wins. */
|
|
3188
|
+
const NONE = 0;
|
|
3189
|
+
const ASSUMED = 1;
|
|
3190
|
+
const PROVEN = 2;
|
|
3191
|
+
/** Whether this schema's subtree contains a cycle, so one parse can re-enter it. */
|
|
3192
|
+
function isRecursive(inst, stack, resolve) {
|
|
3193
|
+
const cached = recursive.get(inst);
|
|
3194
|
+
if (cached !== void 0) return cached ? PROVEN : NONE;
|
|
3195
|
+
if (stack.has(inst)) return PROVEN;
|
|
3196
|
+
stack.add(inst);
|
|
3197
|
+
let result = NONE;
|
|
3198
|
+
const check = (child) => {
|
|
3199
|
+
if (result !== PROVEN && child?._zod) {
|
|
3200
|
+
const answer = isRecursive(child, stack, resolve);
|
|
3201
|
+
if (answer > result) result = answer;
|
|
3202
|
+
}
|
|
3203
|
+
};
|
|
3204
|
+
const shape = (sh, spread) => {
|
|
3205
|
+
let answer = NONE;
|
|
3206
|
+
for (const key of Reflect.ownKeys(sh)) {
|
|
3207
|
+
const desc = Object.getOwnPropertyDescriptor(sh, key);
|
|
3208
|
+
if (spread && !desc.enumerable) continue;
|
|
3209
|
+
const child = desc.get ? ASSUMED : desc.value?._zod ? isRecursive(desc.value, stack, resolve) : NONE;
|
|
3210
|
+
if (child > answer) answer = child;
|
|
3211
|
+
}
|
|
3212
|
+
return answer;
|
|
3213
|
+
};
|
|
3214
|
+
const merge = (answer) => {
|
|
3215
|
+
if (answer > result) result = answer;
|
|
3216
|
+
};
|
|
3217
|
+
const def = inst._zod.def;
|
|
3218
|
+
switch (def.type) {
|
|
3219
|
+
case "object": {
|
|
3220
|
+
const raw = rawShape(def);
|
|
3221
|
+
merge(raw ? shape(raw, true) : ASSUMED);
|
|
3222
|
+
check(def.catchall);
|
|
3223
|
+
break;
|
|
3224
|
+
}
|
|
3225
|
+
case "array":
|
|
3226
|
+
check(def.element);
|
|
3227
|
+
break;
|
|
3228
|
+
case "tuple":
|
|
3229
|
+
for (const el of def.items) check(el);
|
|
3230
|
+
check(def.rest);
|
|
3231
|
+
break;
|
|
3232
|
+
case "record":
|
|
3233
|
+
case "map":
|
|
3234
|
+
check(def.keyType);
|
|
3235
|
+
check(def.valueType);
|
|
3236
|
+
break;
|
|
3237
|
+
case "set":
|
|
3238
|
+
check(def.valueType);
|
|
3239
|
+
break;
|
|
3240
|
+
case "union":
|
|
3241
|
+
for (const el of def.options) check(el);
|
|
3242
|
+
break;
|
|
3243
|
+
case "intersection":
|
|
3244
|
+
check(def.left);
|
|
3245
|
+
check(def.right);
|
|
3246
|
+
break;
|
|
3247
|
+
case "optional":
|
|
3248
|
+
case "nullable":
|
|
3249
|
+
case "default":
|
|
3250
|
+
case "prefault":
|
|
3251
|
+
case "catch":
|
|
3252
|
+
case "readonly":
|
|
3253
|
+
case "nonoptional":
|
|
3254
|
+
case "promise":
|
|
3255
|
+
case "success":
|
|
3256
|
+
check(def.innerType);
|
|
3257
|
+
break;
|
|
3258
|
+
case "pipe":
|
|
3259
|
+
check(def.in);
|
|
3260
|
+
check(def.out);
|
|
3261
|
+
break;
|
|
3262
|
+
case "function":
|
|
3263
|
+
check(def.input);
|
|
3264
|
+
check(def.output);
|
|
3265
|
+
break;
|
|
3266
|
+
case "lazy": {
|
|
3267
|
+
const inner = def._cachedInner ?? (resolve ? inst._zod.innerType : void 0);
|
|
3268
|
+
merge(inner ? isRecursive(inner, stack, false) : ASSUMED);
|
|
3269
|
+
break;
|
|
3270
|
+
}
|
|
3271
|
+
case "template_literal":
|
|
3272
|
+
case "string":
|
|
3273
|
+
case "number":
|
|
3274
|
+
case "int":
|
|
3275
|
+
case "boolean":
|
|
3276
|
+
case "bigint":
|
|
3277
|
+
case "symbol":
|
|
3278
|
+
case "undefined":
|
|
3279
|
+
case "null":
|
|
3280
|
+
case "void":
|
|
3281
|
+
case "never":
|
|
3282
|
+
case "any":
|
|
3283
|
+
case "unknown":
|
|
3284
|
+
case "date":
|
|
3285
|
+
case "nan":
|
|
3286
|
+
case "enum":
|
|
3287
|
+
case "literal":
|
|
3288
|
+
case "file":
|
|
3289
|
+
case "transform":
|
|
3290
|
+
case "custom": break;
|
|
3291
|
+
default: for (const key in def) {
|
|
3292
|
+
const desc = Object.getOwnPropertyDescriptor(def, key);
|
|
3293
|
+
if (!desc || desc.get) continue;
|
|
3294
|
+
const value = desc.value;
|
|
3295
|
+
if (!value || typeof value !== "object") continue;
|
|
3296
|
+
if (value._zod) check(value);
|
|
3297
|
+
else if (Array.isArray(value)) for (const el of value) check(el);
|
|
3298
|
+
}
|
|
3299
|
+
}
|
|
3300
|
+
stack.delete(inst);
|
|
3301
|
+
return settle(inst, result);
|
|
3302
|
+
}
|
|
3303
|
+
/** An assumed answer must not outlive the resolution that settles it, so only a certain one is cached. */
|
|
3304
|
+
function settle(inst, answer) {
|
|
3305
|
+
if (answer !== ASSUMED) recursive.set(inst, answer === PROVEN);
|
|
3306
|
+
return answer;
|
|
3307
|
+
}
|
|
3308
|
+
function bucketFor(state, inst) {
|
|
3309
|
+
let bucket = state.buckets.get(inst);
|
|
3310
|
+
if (!bucket) {
|
|
3311
|
+
bucket = /* @__PURE__ */ new WeakMap();
|
|
3312
|
+
state.buckets.set(inst, bucket);
|
|
3313
|
+
}
|
|
3314
|
+
return bucket;
|
|
3315
|
+
}
|
|
3316
|
+
let handoff;
|
|
3317
|
+
const open = [];
|
|
3318
|
+
const memo = {
|
|
3319
|
+
alloc(_inst, payload, empty) {
|
|
3320
|
+
const bucket = handoff;
|
|
3321
|
+
if (!bucket) return empty;
|
|
3322
|
+
handoff = void 0;
|
|
3323
|
+
const entry = {
|
|
3324
|
+
value: empty,
|
|
3325
|
+
issues: null
|
|
3326
|
+
};
|
|
3327
|
+
bucket.set(payload.value, entry);
|
|
3328
|
+
open.push(entry);
|
|
3329
|
+
return empty;
|
|
3330
|
+
},
|
|
3331
|
+
guard(inst) {
|
|
3332
|
+
var _a;
|
|
3333
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
3334
|
+
inst._zod.deferred.push(() => {
|
|
3335
|
+
const base = inst._zod.parse;
|
|
3336
|
+
const wrapped = (payload, ctx) => {
|
|
3337
|
+
if (ctx.direction !== "backward" && isBackEdge(ctx, payload.value)) throw new $ZodCyclicError();
|
|
3338
|
+
return base(payload, ctx);
|
|
3339
|
+
};
|
|
3340
|
+
inst._zod.parse = wrapped;
|
|
3341
|
+
if (inst._zod.run === base) inst._zod.run = wrapped;
|
|
3342
|
+
});
|
|
3343
|
+
},
|
|
3344
|
+
attach(inst) {
|
|
3345
|
+
var _a;
|
|
3346
|
+
let isRecursiveInst;
|
|
3347
|
+
let rechecked = false;
|
|
3348
|
+
let lastCtx;
|
|
3349
|
+
let lastBucket;
|
|
3350
|
+
(_a = inst._zod).deferred ?? (_a.deferred = []);
|
|
3351
|
+
inst._zod.deferred.push(() => {
|
|
3352
|
+
const base = inst._zod.parse;
|
|
3353
|
+
const wrapped = (payload, ctx) => {
|
|
3354
|
+
if (isRecursiveInst === void 0) {
|
|
3355
|
+
const walked = isRecursive(inst, /* @__PURE__ */ new Set(), false);
|
|
3356
|
+
if (walked === NONE) {
|
|
3357
|
+
inst._zod.parse = base;
|
|
3358
|
+
if (inst._zod.run === wrapped) inst._zod.run = base;
|
|
3359
|
+
return base(payload, ctx);
|
|
3360
|
+
}
|
|
3361
|
+
if (walked === PROVEN || rechecked) isRecursiveInst = true;
|
|
3362
|
+
else rechecked = true;
|
|
3363
|
+
}
|
|
3364
|
+
const input = payload.value;
|
|
3365
|
+
if (!isRef(input)) return base(payload, ctx);
|
|
3366
|
+
let state = ctx[STATE];
|
|
3367
|
+
if (!state) {
|
|
3368
|
+
state = {
|
|
3369
|
+
buckets: /* @__PURE__ */ new WeakMap(),
|
|
3370
|
+
backEdges: void 0
|
|
3371
|
+
};
|
|
3372
|
+
ctx[STATE] = state;
|
|
3373
|
+
}
|
|
3374
|
+
let bucket;
|
|
3375
|
+
if (lastCtx === ctx) bucket = lastBucket;
|
|
3376
|
+
else {
|
|
3377
|
+
bucket = bucketFor(state, inst);
|
|
3378
|
+
lastCtx = ctx;
|
|
3379
|
+
lastBucket = bucket;
|
|
3380
|
+
}
|
|
3381
|
+
const hit = bucket.get(input);
|
|
3382
|
+
if (hit) {
|
|
3383
|
+
payload.value = hit.value;
|
|
3384
|
+
if (hit.issues) {
|
|
3385
|
+
if (hit.issues.length) payload.issues.push(...cloneIssues(hit.issues));
|
|
3386
|
+
} else {
|
|
3387
|
+
payload.memo = true;
|
|
3388
|
+
state.backEdges ?? (state.backEdges = /* @__PURE__ */ new WeakSet());
|
|
3389
|
+
state.backEdges.add(hit.value);
|
|
3390
|
+
}
|
|
3391
|
+
return payload;
|
|
3392
|
+
}
|
|
3393
|
+
handoff = bucket;
|
|
3394
|
+
const depth = open.length;
|
|
3395
|
+
const result = base(payload, ctx);
|
|
3396
|
+
handoff = void 0;
|
|
3397
|
+
const entry = open.length > depth ? open.pop() : void 0;
|
|
3398
|
+
if (result instanceof Promise) return result.then((r) => {
|
|
3399
|
+
if (entry) entry.issues = r.issues.length ? cloneIssues(r.issues) : NO_ISSUES;
|
|
3400
|
+
return r;
|
|
3401
|
+
});
|
|
3402
|
+
if (entry) entry.issues = result.issues.length ? cloneIssues(result.issues) : NO_ISSUES;
|
|
3403
|
+
return result;
|
|
3404
|
+
};
|
|
3405
|
+
inst._zod.parse = wrapped;
|
|
3406
|
+
if (inst._zod.run === base) inst._zod.run = wrapped;
|
|
3407
|
+
});
|
|
3408
|
+
}
|
|
3409
|
+
};
|
|
3410
|
+
/** The memoizer that gives containers cycle support. `zod` installs it by default; `zod/mini` opts in with `config({ memoizer: memoizer() })`. */
|
|
3411
|
+
function memoizer() {
|
|
3412
|
+
return memo;
|
|
3413
|
+
}
|
|
3414
|
+
/** Whether this value is a node a back-edge resolved to before it finished. */
|
|
3415
|
+
function isBackEdge(ctx, value) {
|
|
3416
|
+
const backEdges = ctx[STATE]?.backEdges;
|
|
3417
|
+
return backEdges !== void 0 && isRef(value) && backEdges.has(value);
|
|
3418
|
+
}
|
|
3419
|
+
const error = () => {
|
|
3420
|
+
const Sizable = {
|
|
3421
|
+
string: {
|
|
3422
|
+
unit: "characters",
|
|
3423
|
+
verb: "to have"
|
|
3424
|
+
},
|
|
3425
|
+
file: {
|
|
3426
|
+
unit: "bytes",
|
|
3427
|
+
verb: "to have"
|
|
3428
|
+
},
|
|
3429
|
+
array: {
|
|
3430
|
+
unit: "items",
|
|
3431
|
+
verb: "to have"
|
|
3432
|
+
},
|
|
3433
|
+
set: {
|
|
3434
|
+
unit: "items",
|
|
3435
|
+
verb: "to have"
|
|
3436
|
+
},
|
|
3437
|
+
map: {
|
|
3438
|
+
unit: "entries",
|
|
3439
|
+
verb: "to have"
|
|
3440
|
+
}
|
|
3441
|
+
};
|
|
3442
|
+
function getSizing(origin) {
|
|
3443
|
+
return Sizable[origin] ?? null;
|
|
3444
|
+
}
|
|
3445
|
+
const FormatDictionary = {
|
|
3446
|
+
regex: "input",
|
|
3447
|
+
email: "email address",
|
|
3448
|
+
url: "URL",
|
|
3449
|
+
emoji: "emoji",
|
|
3450
|
+
uuid: "UUID",
|
|
3451
|
+
uuidv4: "UUIDv4",
|
|
3452
|
+
uuidv6: "UUIDv6",
|
|
3453
|
+
nanoid: "nanoid",
|
|
3454
|
+
guid: "GUID",
|
|
3455
|
+
cuid: "cuid",
|
|
3456
|
+
cuid2: "cuid2",
|
|
3457
|
+
ulid: "ULID",
|
|
3458
|
+
xid: "XID",
|
|
3459
|
+
ksuid: "KSUID",
|
|
3460
|
+
datetime: "ISO datetime",
|
|
3461
|
+
date: "ISO date",
|
|
3462
|
+
time: "ISO time",
|
|
3463
|
+
duration: "ISO duration",
|
|
3464
|
+
ipv4: "IPv4 address",
|
|
3465
|
+
ipv6: "IPv6 address",
|
|
3466
|
+
mac: "MAC address",
|
|
3467
|
+
cidrv4: "IPv4 range",
|
|
3468
|
+
cidrv6: "IPv6 range",
|
|
3469
|
+
base64: "base64-encoded string",
|
|
3470
|
+
base64url: "base64url-encoded string",
|
|
3471
|
+
json_string: "JSON string",
|
|
3472
|
+
e164: "E.164 number",
|
|
3473
|
+
currency_code: "currency code",
|
|
3474
|
+
credit_card: "credit card number",
|
|
3475
|
+
iban: "IBAN",
|
|
3476
|
+
jwt: "JWT",
|
|
3477
|
+
template_literal: "input"
|
|
3478
|
+
};
|
|
3479
|
+
const TypeDictionary = { nan: "NaN" };
|
|
3480
|
+
function getTypeName(type, input) {
|
|
3481
|
+
if (type === "number" && typeof input === "number" && !Number.isFinite(input)) return String(input);
|
|
3482
|
+
return TypeDictionary[type] ?? type;
|
|
3483
|
+
}
|
|
3484
|
+
return (issue) => {
|
|
3485
|
+
switch (issue.code) {
|
|
3486
|
+
case "invalid_type": return `Invalid input: expected ${getTypeName(issue.expected)}, received ${getTypeName(parsedType(issue.input), issue.input)}`;
|
|
3487
|
+
case "invalid_value":
|
|
3488
|
+
if (issue.values.length === 1) return `Invalid input: expected ${stringifyPrimitive(issue.values[0])}`;
|
|
3489
|
+
return `Invalid option: expected one of ${joinValues(issue.values, "|")}`;
|
|
3490
|
+
case "too_big": {
|
|
3491
|
+
const adj = issue.exact ? "exactly " : issue.inclusive ? "<=" : "<";
|
|
3492
|
+
const sizing = getSizing(issue.origin);
|
|
3493
|
+
if (sizing) return `Too big: expected ${issue.origin ?? "value"} to have ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
|
|
3494
|
+
return `Too big: expected ${issue.origin ?? "value"} to be ${adj}${issue.maximum.toString()}`;
|
|
3495
|
+
}
|
|
3496
|
+
case "too_small": {
|
|
3497
|
+
const adj = issue.exact ? "exactly " : issue.inclusive ? ">=" : ">";
|
|
3498
|
+
const sizing = getSizing(issue.origin);
|
|
3499
|
+
if (sizing) return `Too small: expected ${issue.origin} to have ${adj}${issue.minimum.toString()} ${sizing.unit}`;
|
|
3500
|
+
return `Too small: expected ${issue.origin} to be ${adj}${issue.minimum.toString()}`;
|
|
3501
|
+
}
|
|
3502
|
+
case "invalid_format": {
|
|
3503
|
+
const _issue = issue;
|
|
3504
|
+
if (_issue.format === "starts_with") return `Invalid string: must start with "${_issue.prefix}"`;
|
|
3505
|
+
if (_issue.format === "ends_with") return `Invalid string: must end with "${_issue.suffix}"`;
|
|
3506
|
+
if (_issue.format === "includes") return `Invalid string: must include "${_issue.includes}"`;
|
|
3507
|
+
if (_issue.format === "regex") return `Invalid string: must match pattern ${_issue.pattern}`;
|
|
3508
|
+
return `Invalid ${FormatDictionary[_issue.format] ?? issue.format}`;
|
|
3509
|
+
}
|
|
3510
|
+
case "not_multiple_of": return `Invalid number: must be a multiple of ${issue.divisor}`;
|
|
3511
|
+
case "unrecognized_keys": return `Unrecognized key${issue.keys.length > 1 ? "s" : ""}: ${joinValues(issue.keys, ", ")}`;
|
|
3512
|
+
case "invalid_key": return `Invalid key in ${issue.origin}`;
|
|
3513
|
+
case "invalid_union":
|
|
3514
|
+
if (issue.options && Array.isArray(issue.options) && issue.options.length > 0) return `Invalid discriminator value. Expected ${issue.options.map((o) => `'${o}'`).join(" | ")}`;
|
|
3515
|
+
if (issue.inclusive === false) return "Invalid input: more than one option matched";
|
|
3516
|
+
return "Invalid input";
|
|
3517
|
+
case "invalid_element": return `Invalid value in ${issue.origin}`;
|
|
3518
|
+
default: return `Invalid input`;
|
|
3519
|
+
}
|
|
3520
|
+
};
|
|
3521
|
+
};
|
|
3522
|
+
function en_default() {
|
|
3523
|
+
return { localeError: error() };
|
|
3524
|
+
}
|
|
2528
3525
|
var _a;
|
|
2529
3526
|
var $ZodRegistry = class {
|
|
2530
3527
|
constructor() {
|
|
@@ -2570,12 +3567,16 @@ function registry() {
|
|
|
2570
3567
|
}
|
|
2571
3568
|
(_a = globalThis).__zod_globalRegistry ?? (_a.__zod_globalRegistry = registry());
|
|
2572
3569
|
const globalRegistry = globalThis.__zod_globalRegistry;
|
|
3570
|
+
function snapshotChecks(def) {
|
|
3571
|
+
if (def.checks) def.checks = [...def.checks];
|
|
3572
|
+
return def;
|
|
3573
|
+
}
|
|
2573
3574
|
/* @__NO_SIDE_EFFECTS__ */
|
|
2574
3575
|
function _string(Class, params) {
|
|
2575
|
-
return new Class({
|
|
3576
|
+
return new Class(snapshotChecks({
|
|
2576
3577
|
type: "string",
|
|
2577
3578
|
...normalizeParams(params)
|
|
2578
|
-
});
|
|
3579
|
+
}));
|
|
2579
3580
|
}
|
|
2580
3581
|
/* @__NO_SIDE_EFFECTS__ */
|
|
2581
3582
|
function _email(Class, params) {
|
|
@@ -2670,6 +3671,11 @@ function _nanoid(Class, params) {
|
|
|
2670
3671
|
...normalizeParams(params)
|
|
2671
3672
|
});
|
|
2672
3673
|
}
|
|
3674
|
+
/**
|
|
3675
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
3676
|
+
* (timestamps embedded in the id). Use {@link _cuid2} instead.
|
|
3677
|
+
* See https://github.com/paralleldrive/cuid.
|
|
3678
|
+
*/
|
|
2673
3679
|
/* @__NO_SIDE_EFFECTS__ */
|
|
2674
3680
|
function _cuid(Class, params) {
|
|
2675
3681
|
return new Class({
|
|
@@ -2842,11 +3848,11 @@ function _isoDuration(Class, params) {
|
|
|
2842
3848
|
}
|
|
2843
3849
|
/* @__NO_SIDE_EFFECTS__ */
|
|
2844
3850
|
function _number(Class, params) {
|
|
2845
|
-
return new Class({
|
|
3851
|
+
return new Class(snapshotChecks({
|
|
2846
3852
|
type: "number",
|
|
2847
3853
|
checks: [],
|
|
2848
3854
|
...normalizeParams(params)
|
|
2849
|
-
});
|
|
3855
|
+
}));
|
|
2850
3856
|
}
|
|
2851
3857
|
/* @__NO_SIDE_EFFECTS__ */
|
|
2852
3858
|
function _int(Class, params) {
|
|
@@ -3041,7 +4047,7 @@ function _refine(Class, fn, _params) {
|
|
|
3041
4047
|
});
|
|
3042
4048
|
}
|
|
3043
4049
|
/* @__NO_SIDE_EFFECTS__ */
|
|
3044
|
-
function _superRefine(fn) {
|
|
4050
|
+
function _superRefine(fn, params) {
|
|
3045
4051
|
const ch = /* @__PURE__ */ _check((payload) => {
|
|
3046
4052
|
payload.addIssue = (issue$2) => {
|
|
3047
4053
|
if (typeof issue$2 === "string") payload.issues.push(issue(issue$2, payload.value, ch._zod.def));
|
|
@@ -3049,14 +4055,14 @@ function _superRefine(fn) {
|
|
|
3049
4055
|
const _issue = issue$2;
|
|
3050
4056
|
if (_issue.fatal) _issue.continue = false;
|
|
3051
4057
|
_issue.code ?? (_issue.code = "custom");
|
|
3052
|
-
|
|
4058
|
+
if (!("input" in _issue)) _issue.input = payload.value;
|
|
3053
4059
|
_issue.inst ?? (_issue.inst = ch);
|
|
3054
4060
|
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
3055
4061
|
payload.issues.push(issue(_issue));
|
|
3056
4062
|
}
|
|
3057
4063
|
};
|
|
3058
4064
|
return fn(payload.value, payload);
|
|
3059
|
-
});
|
|
4065
|
+
}, params);
|
|
3060
4066
|
return ch;
|
|
3061
4067
|
}
|
|
3062
4068
|
/* @__NO_SIDE_EFFECTS__ */
|
|
@@ -3068,6 +4074,10 @@ function _check(fn, params) {
|
|
|
3068
4074
|
ch._zod.check = fn;
|
|
3069
4075
|
return ch;
|
|
3070
4076
|
}
|
|
4077
|
+
function assignProps(target, ...sources) {
|
|
4078
|
+
for (const source of sources) for (const key of Reflect.ownKeys(source)) if (Object.prototype.propertyIsEnumerable.call(source, key)) assignProp(target, key, source[key]);
|
|
4079
|
+
return target;
|
|
4080
|
+
}
|
|
3071
4081
|
function initializeContext(params) {
|
|
3072
4082
|
let target = params?.target ?? "draft-2020-12";
|
|
3073
4083
|
if (target === "draft-4") target = "draft-04";
|
|
@@ -3081,12 +4091,32 @@ function initializeContext(params) {
|
|
|
3081
4091
|
io: params?.io ?? "output",
|
|
3082
4092
|
counter: 0,
|
|
3083
4093
|
seen: /* @__PURE__ */ new Map(),
|
|
4094
|
+
sharedDefsExtractedFor: void 0,
|
|
4095
|
+
sharedEmitDoneFor: void 0,
|
|
3084
4096
|
cycles: params?.cycles ?? "ref",
|
|
3085
4097
|
reused: params?.reused ?? "inline",
|
|
4098
|
+
intersections: [],
|
|
4099
|
+
deferred: [],
|
|
3086
4100
|
external: params?.external ?? void 0
|
|
3087
4101
|
};
|
|
3088
4102
|
}
|
|
3089
|
-
|
|
4103
|
+
/**
|
|
4104
|
+
* Applies the `unrepresentable` setting at a site that has no JSON Schema equivalent. Throws
|
|
4105
|
+
* `message` unless the setting (or the handler's return value) says otherwise. Returns `true` if a
|
|
4106
|
+
* custom JSON Schema was written into `json`, in which case the caller must not write its own.
|
|
4107
|
+
*/
|
|
4108
|
+
function handleUnrepresentable(schema, ctx, json, params, message) {
|
|
4109
|
+
const result = typeof ctx.unrepresentable === "function" ? ctx.unrepresentable({
|
|
4110
|
+
zodSchema: schema,
|
|
4111
|
+
path: params.path,
|
|
4112
|
+
message
|
|
4113
|
+
}) : ctx.unrepresentable;
|
|
4114
|
+
if (result === "any") return false;
|
|
4115
|
+
if (result === void 0 || result === "throw") throw new Error(message);
|
|
4116
|
+
Object.assign(json, result);
|
|
4117
|
+
return true;
|
|
4118
|
+
}
|
|
4119
|
+
function processSchema(schema, ctx, _params = {
|
|
3090
4120
|
path: [],
|
|
3091
4121
|
schemaPath: []
|
|
3092
4122
|
}) {
|
|
@@ -3105,6 +4135,8 @@ function process$1(schema, ctx, _params = {
|
|
|
3105
4135
|
path: _params.path
|
|
3106
4136
|
};
|
|
3107
4137
|
ctx.seen.set(schema, result);
|
|
4138
|
+
ctx.sharedDefsExtractedFor = void 0;
|
|
4139
|
+
ctx.sharedEmitDoneFor = void 0;
|
|
3108
4140
|
const overrideSchema = schema._zod.toJSONSchema?.();
|
|
3109
4141
|
if (overrideSchema) result.schema = overrideSchema;
|
|
3110
4142
|
else {
|
|
@@ -3123,23 +4155,27 @@ function process$1(schema, ctx, _params = {
|
|
|
3123
4155
|
const parent = schema._zod.parent;
|
|
3124
4156
|
if (parent) {
|
|
3125
4157
|
if (!result.ref) result.ref = parent;
|
|
3126
|
-
|
|
4158
|
+
processSchema(parent, ctx, params);
|
|
3127
4159
|
ctx.seen.get(parent).isParent = true;
|
|
3128
4160
|
}
|
|
3129
4161
|
}
|
|
3130
4162
|
const meta = ctx.metadataRegistry.get(schema);
|
|
3131
|
-
if (meta)
|
|
4163
|
+
if (meta) assignProps(result.schema, meta);
|
|
3132
4164
|
if (ctx.io === "input" && isTransforming(schema)) {
|
|
3133
4165
|
delete result.schema.examples;
|
|
3134
4166
|
delete result.schema.default;
|
|
3135
4167
|
}
|
|
3136
|
-
if (ctx.io === "input" && result.schema
|
|
4168
|
+
if (ctx.io === "input" && "_prefault" in result.schema) (_a = result.schema).default ?? (_a.default = result.schema._prefault);
|
|
3137
4169
|
delete result.schema._prefault;
|
|
3138
4170
|
return ctx.seen.get(schema).schema;
|
|
3139
4171
|
}
|
|
4172
|
+
function encodeJSONPointerSegment(segment) {
|
|
4173
|
+
return segment.replace(/~/g, "~0").replace(/\//g, "~1");
|
|
4174
|
+
}
|
|
3140
4175
|
function extractDefs(ctx, schema) {
|
|
3141
4176
|
const root = ctx.seen.get(schema);
|
|
3142
4177
|
if (!root) throw new Error("Unprocessed schema. This is a bug in Zod.");
|
|
4178
|
+
if (ctx.external && ctx.sharedDefsExtractedFor === ctx.external) return;
|
|
3143
4179
|
const idToSchema = /* @__PURE__ */ new Map();
|
|
3144
4180
|
for (const entry of ctx.seen.entries()) {
|
|
3145
4181
|
const id = ctx.metadataRegistry.get(entry[0])?.id;
|
|
@@ -3159,15 +4195,16 @@ function extractDefs(ctx, schema) {
|
|
|
3159
4195
|
entry[1].defId = id;
|
|
3160
4196
|
return {
|
|
3161
4197
|
defId: id,
|
|
3162
|
-
ref: `${uriGenerator("__shared")}#/${defsSegment}/${id}`
|
|
4198
|
+
ref: `${uriGenerator("__shared")}#/${defsSegment}/${encodeJSONPointerSegment(id)}`
|
|
3163
4199
|
};
|
|
3164
4200
|
}
|
|
3165
|
-
|
|
3166
|
-
const defUriPrefix =
|
|
4201
|
+
const uriPrefix = `#`;
|
|
4202
|
+
const defUriPrefix = `${uriPrefix}/${defsSegment}/`;
|
|
4203
|
+
if (entry[1] === root && !entry[1].schema.id) return { ref: uriPrefix };
|
|
3167
4204
|
const defId = entry[1].schema.id ?? `__schema${ctx.counter++}`;
|
|
3168
4205
|
return {
|
|
3169
4206
|
defId,
|
|
3170
|
-
ref: defUriPrefix + defId
|
|
4207
|
+
ref: defUriPrefix + encodeJSONPointerSegment(defId)
|
|
3171
4208
|
};
|
|
3172
4209
|
};
|
|
3173
4210
|
const extractToDef = (entry) => {
|
|
@@ -3208,12 +4245,114 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
|
|
|
3208
4245
|
continue;
|
|
3209
4246
|
}
|
|
3210
4247
|
if (seen.count > 1) {
|
|
3211
|
-
if (ctx.reused === "ref")
|
|
3212
|
-
|
|
3213
|
-
|
|
4248
|
+
if (ctx.reused === "ref") extractToDef(entry);
|
|
4249
|
+
}
|
|
4250
|
+
}
|
|
4251
|
+
if (ctx.external) ctx.sharedDefsExtractedFor = ctx.external;
|
|
4252
|
+
}
|
|
4253
|
+
/** Rewrites `anyOf: [{type: "a"}, {type: "b"}]` to `type: ["a", "b"]`, which every JSON Schema draft treats as equivalent and most consumers render far better for the nullable case. Only branches that are a bare type assertion qualify — anything carrying a constraint, `$ref`, `const` or metadata is left alone. Runs after `flattenRef`, so a branch an override decorated or `$defs` extraction turned into a `$ref` is no longer bare and correctly stays in `anyOf`. `oneOf` is excluded: `integer` and `number` overlap, so "exactly one" and "at least one" are not the same there. OpenAPI 3.0 is excluded: its `type` must be a single string. */
|
|
4254
|
+
function compactTypeUnion(schema) {
|
|
4255
|
+
const options = schema.anyOf;
|
|
4256
|
+
if (!Array.isArray(options) || options.length === 0 || schema.type !== void 0) return;
|
|
4257
|
+
const types = [];
|
|
4258
|
+
for (const option of options) {
|
|
4259
|
+
if (!option || typeof option !== "object") return;
|
|
4260
|
+
compactTypeUnion(option);
|
|
4261
|
+
const keys = Object.keys(option);
|
|
4262
|
+
if (keys.length !== 1 || keys[0] !== "type") return;
|
|
4263
|
+
const type = option.type;
|
|
4264
|
+
for (const member of Array.isArray(type) ? type : [type]) {
|
|
4265
|
+
if (typeof member !== "string") return;
|
|
4266
|
+
if (!types.includes(member)) types.push(member);
|
|
4267
|
+
}
|
|
4268
|
+
}
|
|
4269
|
+
delete schema.anyOf;
|
|
4270
|
+
schema.type = types.length === 1 ? types[0] : types;
|
|
4271
|
+
}
|
|
4272
|
+
/** Keywords `foldIntersection` knows how to combine. Anything else — `$ref`, `patternProperties`,
|
|
4273
|
+
* an annotation like `description` — makes a member unfoldable, so a constraint this does not
|
|
4274
|
+
* understand leaves the `allOf` alone instead of being silently dropped or misattributed. */
|
|
4275
|
+
const FOLDABLE_KEYS = new Set([
|
|
4276
|
+
"type",
|
|
4277
|
+
"properties",
|
|
4278
|
+
"required",
|
|
4279
|
+
"additionalProperties"
|
|
4280
|
+
]);
|
|
4281
|
+
const UNION_KEYS = ["oneOf", "anyOf"];
|
|
4282
|
+
/** A member's constraint on a key it does not declare itself. A `catchall` states one; `false`, an absent `additionalProperties`, and the empty schema a loose object emits state nothing. */
|
|
4283
|
+
function undeclaredConstraint(member) {
|
|
4284
|
+
const extra = member.additionalProperties;
|
|
4285
|
+
if (extra === void 0 || extra === false || typeof extra !== "object" || extra === null) return null;
|
|
4286
|
+
return Object.keys(extra).length ? extra : null;
|
|
4287
|
+
}
|
|
4288
|
+
/** Combines object members into the single object they describe together, or returns `null` if any of them carries a keyword outside {@link FOLDABLE_KEYS}. */
|
|
4289
|
+
function foldObjects(members) {
|
|
4290
|
+
const objects = [];
|
|
4291
|
+
for (const member of members) {
|
|
4292
|
+
if (typeof member !== "object" || member.type !== "object") return null;
|
|
4293
|
+
for (const key in member) if (!FOLDABLE_KEYS.has(key)) return null;
|
|
4294
|
+
objects.push(member);
|
|
4295
|
+
}
|
|
4296
|
+
const properties = {};
|
|
4297
|
+
const required = /* @__PURE__ */ new Set();
|
|
4298
|
+
for (const object of objects) {
|
|
4299
|
+
for (const key in object.properties) {
|
|
4300
|
+
if (Object.prototype.hasOwnProperty.call(properties, key)) continue;
|
|
4301
|
+
const parts = [];
|
|
4302
|
+
for (const other of objects) {
|
|
4303
|
+
const part = other.properties?.[key] ?? undeclaredConstraint(other);
|
|
4304
|
+
if (part === null || part === void 0) continue;
|
|
4305
|
+
if (!parts.some((seen) => JSON.stringify(seen) === JSON.stringify(part))) parts.push(part);
|
|
3214
4306
|
}
|
|
4307
|
+
assignProp(properties, key, parts.length === 1 ? parts[0] : foldObjects(parts) ?? { allOf: parts });
|
|
3215
4308
|
}
|
|
4309
|
+
for (const key of object.required ?? []) required.add(key);
|
|
4310
|
+
}
|
|
4311
|
+
const folded = {
|
|
4312
|
+
type: "object",
|
|
4313
|
+
properties
|
|
4314
|
+
};
|
|
4315
|
+
if (required.size) folded.required = [...required];
|
|
4316
|
+
if (objects.every((object) => object.additionalProperties === false)) folded.additionalProperties = false;
|
|
4317
|
+
else {
|
|
4318
|
+
const constraints = [];
|
|
4319
|
+
for (const object of objects) {
|
|
4320
|
+
const constraint = undeclaredConstraint(object);
|
|
4321
|
+
if (constraint && !constraints.some((seen) => JSON.stringify(seen) === JSON.stringify(constraint))) constraints.push(constraint);
|
|
4322
|
+
}
|
|
4323
|
+
if (constraints.length === 1) folded.additionalProperties = constraints[0];
|
|
4324
|
+
else if (constraints.length > 1) folded.additionalProperties = { allOf: constraints };
|
|
4325
|
+
}
|
|
4326
|
+
return folded;
|
|
4327
|
+
}
|
|
4328
|
+
/** `additionalProperties` in an `allOf` member sees only that member's own `properties`, so two
|
|
4329
|
+
* closed object members reject each other's keys and the schema validates nothing. Zod's parser
|
|
4330
|
+
* pools the key sets instead — `handleIntersectionResults` reports a key as unrecognized only when
|
|
4331
|
+
* *every* side rejects it — so the emitted schema has to pool them too, and folding the members
|
|
4332
|
+
* into one object is the encoding that says so on every target.
|
|
4333
|
+
*
|
|
4334
|
+
* This runs from `finalize`, after `extractDefs`, which is what keeps it clear of the `$ref`
|
|
4335
|
+
* machinery: a member extracted into `$defs` is already a `$ref` by now and declines to fold, so it
|
|
4336
|
+
* keeps its reference and its own closedness rather than being inlined as a stale copy. */
|
|
4337
|
+
function foldIntersection(json) {
|
|
4338
|
+
const allOf = json.allOf;
|
|
4339
|
+
if (!Array.isArray(allOf) || allOf.length < 2) return;
|
|
4340
|
+
for (const key of FOLDABLE_KEYS) if (key in json) return;
|
|
4341
|
+
const unions = allOf.filter((m) => UNION_KEYS.some((k) => Array.isArray(m[k])));
|
|
4342
|
+
let folded = null;
|
|
4343
|
+
if (!unions.length) folded = foldObjects(allOf);
|
|
4344
|
+
else {
|
|
4345
|
+
const union = unions[0];
|
|
4346
|
+
const keyword = UNION_KEYS.find((k) => Array.isArray(union[k]));
|
|
4347
|
+
if (Object.keys(union).length !== 1) return;
|
|
4348
|
+
const rest = allOf.filter((m) => m !== union);
|
|
4349
|
+
const branches = union[keyword].map((branch) => foldObjects([...rest, branch]));
|
|
4350
|
+
if (branches.some((b) => !b)) return;
|
|
4351
|
+
folded = { [keyword]: branches };
|
|
3216
4352
|
}
|
|
4353
|
+
if (!folded) return;
|
|
4354
|
+
delete json.allOf;
|
|
4355
|
+
assignProps(json, folded);
|
|
3217
4356
|
}
|
|
3218
4357
|
function finalize(ctx, schema) {
|
|
3219
4358
|
const root = ctx.seen.get(schema);
|
|
@@ -3232,8 +4371,8 @@ function finalize(ctx, schema) {
|
|
|
3232
4371
|
if (refSchema.$ref && (ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0")) {
|
|
3233
4372
|
schema.allOf = schema.allOf ?? [];
|
|
3234
4373
|
schema.allOf.push(refSchema);
|
|
3235
|
-
} else
|
|
3236
|
-
|
|
4374
|
+
} else assignProps(schema, refSchema);
|
|
4375
|
+
assignProps(schema, _cached);
|
|
3237
4376
|
if (zodSchema._zod.parent === ref) for (const key in schema) {
|
|
3238
4377
|
if (key === "$ref" || key === "allOf") continue;
|
|
3239
4378
|
if (!(key in _cached)) delete schema[key];
|
|
@@ -3261,7 +4400,22 @@ function finalize(ctx, schema) {
|
|
|
3261
4400
|
path: seen.path ?? []
|
|
3262
4401
|
});
|
|
3263
4402
|
};
|
|
3264
|
-
|
|
4403
|
+
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) {
|
|
4404
|
+
for (const entry of [...ctx.seen.entries()].reverse()) flattenRef(entry[0]);
|
|
4405
|
+
if (ctx.target !== "openapi-3.0") for (const entry of ctx.seen.entries()) compactTypeUnion(entry[1].def ?? entry[1].schema);
|
|
4406
|
+
for (const rewrite of ctx.deferred) rewrite();
|
|
4407
|
+
if (ctx.intersections.length) {
|
|
4408
|
+
const carriers = /* @__PURE__ */ new Map();
|
|
4409
|
+
for (const seen of ctx.seen.values()) for (const json of [seen.schema, seen.def]) {
|
|
4410
|
+
const allOf = json?.allOf;
|
|
4411
|
+
if (!Array.isArray(allOf)) continue;
|
|
4412
|
+
const existing = carriers.get(allOf);
|
|
4413
|
+
if (existing) existing.push(json);
|
|
4414
|
+
else carriers.set(allOf, [json]);
|
|
4415
|
+
}
|
|
4416
|
+
for (const allOf of ctx.intersections) for (const json of carriers.get(allOf) ?? []) foldIntersection(json);
|
|
4417
|
+
}
|
|
4418
|
+
}
|
|
3265
4419
|
const result = {};
|
|
3266
4420
|
if (ctx.target === "draft-2020-12") result.$schema = "https://json-schema.org/draft/2020-12/schema";
|
|
3267
4421
|
else if (ctx.target === "draft-07") result.$schema = "http://json-schema.org/draft-07/schema#";
|
|
@@ -3272,12 +4426,18 @@ function finalize(ctx, schema) {
|
|
|
3272
4426
|
if (!id) throw new Error("Schema is missing an `id` property");
|
|
3273
4427
|
result.$id = ctx.external.uri(id);
|
|
3274
4428
|
}
|
|
3275
|
-
|
|
4429
|
+
assignProps(result, root.defId ? root.schema : root.def ?? root.schema);
|
|
4430
|
+
const rootMetaId = ctx.metadataRegistry.get(schema)?.id;
|
|
4431
|
+
if (rootMetaId !== void 0 && result.id === rootMetaId) delete result.id;
|
|
3276
4432
|
const defs = ctx.external?.defs ?? {};
|
|
3277
|
-
for (const entry of ctx.seen.entries()) {
|
|
4433
|
+
if (!ctx.external || ctx.sharedEmitDoneFor !== ctx.external) for (const entry of ctx.seen.entries()) {
|
|
3278
4434
|
const seen = entry[1];
|
|
3279
|
-
if (seen.def && seen.defId)
|
|
4435
|
+
if (seen.def && seen.defId) {
|
|
4436
|
+
if (seen.def.id === seen.defId) delete seen.def.id;
|
|
4437
|
+
assignProp(defs, seen.defId, seen.def);
|
|
4438
|
+
}
|
|
3280
4439
|
}
|
|
4440
|
+
if (ctx.external) ctx.sharedEmitDoneFor = ctx.external;
|
|
3281
4441
|
if (ctx.external) {} else if (Object.keys(defs).length > 0) if (ctx.target === "draft-2020-12") result.$defs = defs;
|
|
3282
4442
|
else result.definitions = defs;
|
|
3283
4443
|
try {
|
|
@@ -3307,10 +4467,13 @@ function isTransforming(_schema, _ctx) {
|
|
|
3307
4467
|
if (def.type === "array") return isTransforming(def.element, ctx);
|
|
3308
4468
|
if (def.type === "set") return isTransforming(def.valueType, ctx);
|
|
3309
4469
|
if (def.type === "lazy") return isTransforming(def.getter(), ctx);
|
|
3310
|
-
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault") return isTransforming(def.innerType, ctx);
|
|
4470
|
+
if (def.type === "promise" || def.type === "optional" || def.type === "nonoptional" || def.type === "nullable" || def.type === "readonly" || def.type === "default" || def.type === "prefault" || def.type === "catch") return isTransforming(def.innerType, ctx);
|
|
3311
4471
|
if (def.type === "intersection") return isTransforming(def.left, ctx) || isTransforming(def.right, ctx);
|
|
3312
4472
|
if (def.type === "record" || def.type === "map") return isTransforming(def.keyType, ctx) || isTransforming(def.valueType, ctx);
|
|
3313
|
-
if (def.type === "pipe")
|
|
4473
|
+
if (def.type === "pipe") {
|
|
4474
|
+
if (_schema._zod.traits.has("$ZodCodec")) return true;
|
|
4475
|
+
return isTransforming(def.in, ctx) || isTransforming(def.out, ctx);
|
|
4476
|
+
}
|
|
3314
4477
|
if (def.type === "object") {
|
|
3315
4478
|
for (const key in def.shape) if (isTransforming(def.shape[key], ctx)) return true;
|
|
3316
4479
|
return false;
|
|
@@ -3335,7 +4498,7 @@ const createToJSONSchemaMethod = (schema, processors = {}) => (params) => {
|
|
|
3335
4498
|
...params,
|
|
3336
4499
|
processors
|
|
3337
4500
|
});
|
|
3338
|
-
|
|
4501
|
+
processSchema(schema, ctx);
|
|
3339
4502
|
extractDefs(ctx, schema);
|
|
3340
4503
|
return finalize(ctx, schema);
|
|
3341
4504
|
};
|
|
@@ -3347,10 +4510,82 @@ const createStandardJSONSchemaMethod = (schema, io, processors = {}) => (params)
|
|
|
3347
4510
|
io,
|
|
3348
4511
|
processors
|
|
3349
4512
|
});
|
|
3350
|
-
|
|
4513
|
+
processSchema(schema, ctx);
|
|
3351
4514
|
extractDefs(ctx, schema);
|
|
3352
4515
|
return finalize(ctx, schema);
|
|
3353
4516
|
};
|
|
4517
|
+
const narrowMin = (agg, key, value) => {
|
|
4518
|
+
if (agg[key] === void 0 || value > agg[key]) agg[key] = value;
|
|
4519
|
+
};
|
|
4520
|
+
const narrowMax = (agg, key, value) => {
|
|
4521
|
+
if (agg[key] === void 0 || value < agg[key]) agg[key] = value;
|
|
4522
|
+
};
|
|
4523
|
+
const narrowBoth = (agg, value) => {
|
|
4524
|
+
narrowMin(agg, "minimum", value);
|
|
4525
|
+
narrowMax(agg, "maximum", value);
|
|
4526
|
+
};
|
|
4527
|
+
const addDivisor = (agg, value) => {
|
|
4528
|
+
agg.multipleOf ?? (agg.multipleOf = []);
|
|
4529
|
+
if (!agg.multipleOf.includes(value)) agg.multipleOf.push(value);
|
|
4530
|
+
};
|
|
4531
|
+
const addPattern = (agg, pattern) => {
|
|
4532
|
+
agg.patterns ?? (agg.patterns = /* @__PURE__ */ new Set());
|
|
4533
|
+
agg.patterns.add(pattern);
|
|
4534
|
+
};
|
|
4535
|
+
const intersectMime = (agg, mime) => {
|
|
4536
|
+
agg.mime = agg.mime ? agg.mime.filter((m) => mime.includes(m)) : [...mime];
|
|
4537
|
+
};
|
|
4538
|
+
const setFormat = (agg, format) => {
|
|
4539
|
+
agg.format = format;
|
|
4540
|
+
if (format.includes("int")) agg.isInt = true;
|
|
4541
|
+
};
|
|
4542
|
+
const minContributor = (agg, def) => narrowMin(agg, "minimum", def.minimum);
|
|
4543
|
+
const maxContributor = (agg, def) => narrowMax(agg, "maximum", def.maximum);
|
|
4544
|
+
const formatContributor = (ranges) => (agg, def) => {
|
|
4545
|
+
setFormat(agg, def.format);
|
|
4546
|
+
const [minimum, maximum] = ranges[def.format];
|
|
4547
|
+
narrowMin(agg, "minimum", minimum);
|
|
4548
|
+
narrowMax(agg, "maximum", maximum);
|
|
4549
|
+
};
|
|
4550
|
+
const contributors = {
|
|
4551
|
+
greater_than: (agg, def) => narrowMin(agg, def.inclusive ? "minimum" : "exclusiveMinimum", def.value),
|
|
4552
|
+
less_than: (agg, def) => narrowMax(agg, def.inclusive ? "maximum" : "exclusiveMaximum", def.value),
|
|
4553
|
+
multiple_of: (agg, def) => addDivisor(agg, def.value),
|
|
4554
|
+
number_format: formatContributor(NUMBER_FORMAT_RANGES),
|
|
4555
|
+
bigint_format: formatContributor(BIGINT_FORMAT_RANGES),
|
|
4556
|
+
min_length: minContributor,
|
|
4557
|
+
max_length: maxContributor,
|
|
4558
|
+
length_equals: (agg, def) => narrowBoth(agg, def.length),
|
|
4559
|
+
min_size: minContributor,
|
|
4560
|
+
max_size: maxContributor,
|
|
4561
|
+
size_equals: (agg, def) => narrowBoth(agg, def.size),
|
|
4562
|
+
string_format: (agg, def) => {
|
|
4563
|
+
setFormat(agg, def.format);
|
|
4564
|
+
if (def.pattern) addPattern(agg, def.pattern);
|
|
4565
|
+
if (def.format === "base64" || def.format === "base64url") agg.contentEncoding = def.format;
|
|
4566
|
+
if (def.local || def.precision === -1) agg.laxFormat = true;
|
|
4567
|
+
},
|
|
4568
|
+
mime_type: (agg, def) => intersectMime(agg, def.mime)
|
|
4569
|
+
};
|
|
4570
|
+
function aggregateChecks(schema) {
|
|
4571
|
+
const agg = {};
|
|
4572
|
+
const def = schema._zod.def;
|
|
4573
|
+
const list = schema._zod.traits.has("$ZodCheck") ? [schema, ...def.checks ?? []] : def.checks ?? [];
|
|
4574
|
+
for (const ch of list) contributors[ch._zod.def.check]?.(agg, ch._zod.def);
|
|
4575
|
+
const bag = schema._zod.bag;
|
|
4576
|
+
if (bag.minimum !== void 0) narrowMin(agg, "minimum", bag.minimum);
|
|
4577
|
+
if (bag.exclusiveMinimum !== void 0) narrowMin(agg, "exclusiveMinimum", bag.exclusiveMinimum);
|
|
4578
|
+
if (bag.maximum !== void 0) narrowMax(agg, "maximum", bag.maximum);
|
|
4579
|
+
if (bag.exclusiveMaximum !== void 0) narrowMax(agg, "exclusiveMaximum", bag.exclusiveMaximum);
|
|
4580
|
+
if (bag.multipleOf !== void 0) addDivisor(agg, bag.multipleOf);
|
|
4581
|
+
if (bag.format !== void 0) {
|
|
4582
|
+
agg.format ?? (agg.format = bag.format);
|
|
4583
|
+
if (bag.format.includes("int")) agg.isInt = true;
|
|
4584
|
+
}
|
|
4585
|
+
if (bag.mime) intersectMime(agg, bag.mime);
|
|
4586
|
+
for (const pattern of bag.patterns ?? []) addPattern(agg, pattern);
|
|
4587
|
+
return agg;
|
|
4588
|
+
}
|
|
3354
4589
|
const formatMap = {
|
|
3355
4590
|
guid: "uuid",
|
|
3356
4591
|
url: "uri",
|
|
@@ -3358,51 +4593,54 @@ const formatMap = {
|
|
|
3358
4593
|
json_string: "json-string",
|
|
3359
4594
|
regex: ""
|
|
3360
4595
|
};
|
|
4596
|
+
const exactPatterns = new Map([[base64Charset, base64], [base64urlCharset, base64url]]);
|
|
4597
|
+
const exactPattern = (p) => exactPatterns.get(p) ?? p;
|
|
3361
4598
|
const stringProcessor = (schema, ctx, _json, _params) => {
|
|
3362
4599
|
const json = _json;
|
|
3363
4600
|
json.type = "string";
|
|
3364
|
-
const { minimum, maximum, format, patterns, contentEncoding } = schema
|
|
4601
|
+
const { minimum, maximum, format, patterns, contentEncoding, laxFormat } = aggregateChecks(schema);
|
|
3365
4602
|
if (typeof minimum === "number") json.minLength = minimum;
|
|
3366
4603
|
if (typeof maximum === "number") json.maxLength = maximum;
|
|
3367
4604
|
if (format) {
|
|
3368
4605
|
json.format = formatMap[format] ?? format;
|
|
3369
4606
|
if (json.format === "") delete json.format;
|
|
3370
|
-
if (format === "time") delete json.format;
|
|
4607
|
+
if (format === "time" || laxFormat) delete json.format;
|
|
3371
4608
|
}
|
|
3372
4609
|
if (contentEncoding) json.contentEncoding = contentEncoding;
|
|
3373
4610
|
if (patterns && patterns.size > 0) {
|
|
3374
|
-
const
|
|
3375
|
-
if (
|
|
3376
|
-
else if (
|
|
4611
|
+
const patternList = [...patterns].map(exactPattern);
|
|
4612
|
+
if (patternList.length === 1) json.pattern = patternList[0].source;
|
|
4613
|
+
else if (patternList.length > 1) json.allOf = [...patternList.map((regex) => ({
|
|
3377
4614
|
...ctx.target === "draft-07" || ctx.target === "draft-04" || ctx.target === "openapi-3.0" ? { type: "string" } : {},
|
|
3378
4615
|
pattern: regex.source
|
|
3379
4616
|
}))];
|
|
3380
4617
|
}
|
|
3381
4618
|
};
|
|
3382
|
-
const numberProcessor = (schema, ctx, _json,
|
|
4619
|
+
const numberProcessor = (schema, ctx, _json, params) => {
|
|
3383
4620
|
const json = _json;
|
|
3384
|
-
const { minimum, maximum,
|
|
3385
|
-
|
|
3386
|
-
|
|
3387
|
-
|
|
4621
|
+
const { minimum, maximum, multipleOf, exclusiveMaximum, exclusiveMinimum, isInt } = aggregateChecks(schema);
|
|
4622
|
+
json.type = isInt ? "integer" : "number";
|
|
4623
|
+
const exMin = typeof exclusiveMinimum === "number" && exclusiveMinimum >= (minimum ?? Number.NEGATIVE_INFINITY);
|
|
4624
|
+
const exMax = typeof exclusiveMaximum === "number" && exclusiveMaximum <= (maximum ?? Number.POSITIVE_INFINITY);
|
|
4625
|
+
const legacy = ctx.target === "draft-04" || ctx.target === "openapi-3.0";
|
|
4626
|
+
if (exMin) if (legacy) {
|
|
3388
4627
|
json.minimum = exclusiveMinimum;
|
|
3389
4628
|
json.exclusiveMinimum = true;
|
|
3390
4629
|
} else json.exclusiveMinimum = exclusiveMinimum;
|
|
3391
|
-
if (typeof minimum === "number")
|
|
3392
|
-
|
|
3393
|
-
if (typeof exclusiveMinimum === "number" && ctx.target !== "draft-04") if (exclusiveMinimum >= minimum) delete json.minimum;
|
|
3394
|
-
else delete json.exclusiveMinimum;
|
|
3395
|
-
}
|
|
3396
|
-
if (typeof exclusiveMaximum === "number") if (ctx.target === "draft-04" || ctx.target === "openapi-3.0") {
|
|
4630
|
+
else if (typeof minimum === "number") json.minimum = minimum;
|
|
4631
|
+
if (exMax) if (legacy) {
|
|
3397
4632
|
json.maximum = exclusiveMaximum;
|
|
3398
4633
|
json.exclusiveMaximum = true;
|
|
3399
4634
|
} else json.exclusiveMaximum = exclusiveMaximum;
|
|
3400
|
-
if (typeof maximum === "number")
|
|
3401
|
-
|
|
3402
|
-
|
|
3403
|
-
|
|
4635
|
+
else if (typeof maximum === "number") json.maximum = maximum;
|
|
4636
|
+
if (multipleOf) {
|
|
4637
|
+
const divisors = /* @__PURE__ */ new Set();
|
|
4638
|
+
for (const divisor of multipleOf) if (Number.isFinite(divisor) && divisor !== 0) divisors.add(Math.abs(divisor));
|
|
4639
|
+
else handleUnrepresentable(schema, ctx, json, params, `A multipleOf divisor of ${divisor} cannot be represented in JSON Schema`);
|
|
4640
|
+
const [first, ...rest] = divisors;
|
|
4641
|
+
if (first !== void 0) json.multipleOf = first;
|
|
4642
|
+
if (rest.length) json.allOf = [...json.allOf ?? [], ...rest.map((m) => ({ multipleOf: m }))];
|
|
3404
4643
|
}
|
|
3405
|
-
if (typeof multipleOf === "number") json.multipleOf = multipleOf;
|
|
3406
4644
|
};
|
|
3407
4645
|
const booleanProcessor = (_schema, _ctx, json, _params) => {
|
|
3408
4646
|
json.type = "boolean";
|
|
@@ -3414,18 +4652,27 @@ const unknownProcessor = (_schema, _ctx, _json, _params) => {};
|
|
|
3414
4652
|
const enumProcessor = (schema, _ctx, json, _params) => {
|
|
3415
4653
|
const def = schema._zod.def;
|
|
3416
4654
|
const values = getEnumValues(def.entries);
|
|
4655
|
+
if (values.length === 0) {
|
|
4656
|
+
json.not = {};
|
|
4657
|
+
return;
|
|
4658
|
+
}
|
|
3417
4659
|
if (values.every((v) => typeof v === "number")) json.type = "number";
|
|
3418
4660
|
if (values.every((v) => typeof v === "string")) json.type = "string";
|
|
3419
4661
|
json.enum = values;
|
|
3420
4662
|
};
|
|
3421
|
-
const literalProcessor = (schema, ctx, json,
|
|
4663
|
+
const literalProcessor = (schema, ctx, json, params) => {
|
|
3422
4664
|
const def = schema._zod.def;
|
|
4665
|
+
if (def.values.length === 0) {
|
|
4666
|
+
json.not = {};
|
|
4667
|
+
return;
|
|
4668
|
+
}
|
|
3423
4669
|
const vals = [];
|
|
3424
4670
|
for (const val of def.values) if (val === void 0) {
|
|
3425
|
-
if (ctx
|
|
3426
|
-
} else if (typeof val === "bigint")
|
|
3427
|
-
|
|
3428
|
-
|
|
4671
|
+
if (handleUnrepresentable(schema, ctx, json, params, "Literal `undefined` cannot be represented in JSON Schema")) return;
|
|
4672
|
+
} else if (typeof val === "bigint") {
|
|
4673
|
+
if (handleUnrepresentable(schema, ctx, json, params, "BigInt literals cannot be represented in JSON Schema")) return;
|
|
4674
|
+
vals.push(Number(val));
|
|
4675
|
+
} else vals.push(val);
|
|
3429
4676
|
if (vals.length === 0) {} else if (vals.length === 1) {
|
|
3430
4677
|
const val = vals[0];
|
|
3431
4678
|
json.type = val === null ? "null" : typeof val;
|
|
@@ -3439,49 +4686,55 @@ const literalProcessor = (schema, ctx, json, _params) => {
|
|
|
3439
4686
|
json.enum = vals;
|
|
3440
4687
|
}
|
|
3441
4688
|
};
|
|
3442
|
-
const customProcessor = (
|
|
3443
|
-
|
|
4689
|
+
const customProcessor = (schema, ctx, json, params) => {
|
|
4690
|
+
handleUnrepresentable(schema, ctx, json, params, "Custom types cannot be represented in JSON Schema");
|
|
3444
4691
|
};
|
|
3445
|
-
const transformProcessor = (
|
|
3446
|
-
|
|
4692
|
+
const transformProcessor = (schema, ctx, json, params) => {
|
|
4693
|
+
handleUnrepresentable(schema, ctx, json, params, "Transforms cannot be represented in JSON Schema");
|
|
3447
4694
|
};
|
|
3448
4695
|
const arrayProcessor = (schema, ctx, _json, params) => {
|
|
3449
4696
|
const json = _json;
|
|
3450
4697
|
const def = schema._zod.def;
|
|
3451
|
-
const { minimum, maximum } = schema
|
|
4698
|
+
const { minimum, maximum } = aggregateChecks(schema);
|
|
3452
4699
|
if (typeof minimum === "number") json.minItems = minimum;
|
|
3453
4700
|
if (typeof maximum === "number") json.maxItems = maximum;
|
|
3454
4701
|
json.type = "array";
|
|
3455
|
-
json.items =
|
|
4702
|
+
json.items = processSchema(def.element, ctx, {
|
|
3456
4703
|
...params,
|
|
3457
4704
|
path: [...params.path, "items"]
|
|
3458
4705
|
});
|
|
3459
4706
|
};
|
|
4707
|
+
function inputOptin(schema) {
|
|
4708
|
+
const def = schema._zod.def;
|
|
4709
|
+
if (def.type === "pipe" && def.in._zod.traits.has("$ZodTransform")) return inputOptin(def.out);
|
|
4710
|
+
if (def.type === "catch") return inputOptin(def.innerType);
|
|
4711
|
+
return schema._zod.optin;
|
|
4712
|
+
}
|
|
3460
4713
|
const objectProcessor = (schema, ctx, _json, params) => {
|
|
3461
4714
|
const json = _json;
|
|
3462
4715
|
const def = schema._zod.def;
|
|
4716
|
+
const shape = def.shape;
|
|
4717
|
+
if (Object.getOwnPropertySymbols(shape).length && handleUnrepresentable(schema, ctx, json, params, "Symbol keys cannot be represented in JSON Schema")) return;
|
|
3463
4718
|
json.type = "object";
|
|
3464
4719
|
json.properties = {};
|
|
3465
|
-
const shape
|
|
3466
|
-
for (const key in shape) json.properties[key] = process$1(shape[key], ctx, {
|
|
4720
|
+
for (const key in shape) assignProp(json.properties, key, processSchema(shape[key], ctx, {
|
|
3467
4721
|
...params,
|
|
3468
4722
|
path: [
|
|
3469
4723
|
...params.path,
|
|
3470
4724
|
"properties",
|
|
3471
4725
|
key
|
|
3472
4726
|
]
|
|
3473
|
-
});
|
|
3474
|
-
const allKeys = new Set(Object.keys(shape));
|
|
3475
|
-
const requiredKeys = new Set([...allKeys].filter((key) => {
|
|
3476
|
-
const v = def.shape[key]._zod;
|
|
3477
|
-
if (ctx.io === "input") return v.optin === void 0;
|
|
3478
|
-
else return v.optout === void 0;
|
|
3479
4727
|
}));
|
|
3480
|
-
|
|
4728
|
+
const requiredKeys = [];
|
|
4729
|
+
for (const key of Object.keys(shape)) {
|
|
4730
|
+
const field = def.shape[key];
|
|
4731
|
+
if (ctx.io === "input" ? inputOptin(field) === void 0 : field._zod.optout === void 0) requiredKeys.push(key);
|
|
4732
|
+
}
|
|
4733
|
+
if (requiredKeys.length > 0) json.required = requiredKeys;
|
|
3481
4734
|
if (def.catchall?._zod.def.type === "never") json.additionalProperties = false;
|
|
3482
4735
|
else if (!def.catchall) {
|
|
3483
4736
|
if (ctx.io === "output") json.additionalProperties = false;
|
|
3484
|
-
} else if (def.catchall) json.additionalProperties =
|
|
4737
|
+
} else if (def.catchall) json.additionalProperties = processSchema(def.catchall, ctx, {
|
|
3485
4738
|
...params,
|
|
3486
4739
|
path: [...params.path, "additionalProperties"]
|
|
3487
4740
|
});
|
|
@@ -3489,7 +4742,7 @@ const objectProcessor = (schema, ctx, _json, params) => {
|
|
|
3489
4742
|
const unionProcessor = (schema, ctx, json, params) => {
|
|
3490
4743
|
const def = schema._zod.def;
|
|
3491
4744
|
const isExclusive = def.inclusive === false;
|
|
3492
|
-
const options = def.options.map((x, i) =>
|
|
4745
|
+
const options = def.options.map((x, i) => processSchema(x, ctx, {
|
|
3493
4746
|
...params,
|
|
3494
4747
|
path: [
|
|
3495
4748
|
...params.path,
|
|
@@ -3502,7 +4755,7 @@ const unionProcessor = (schema, ctx, json, params) => {
|
|
|
3502
4755
|
};
|
|
3503
4756
|
const intersectionProcessor = (schema, ctx, json, params) => {
|
|
3504
4757
|
const def = schema._zod.def;
|
|
3505
|
-
const a =
|
|
4758
|
+
const a = processSchema(def.left, ctx, {
|
|
3506
4759
|
...params,
|
|
3507
4760
|
path: [
|
|
3508
4761
|
...params.path,
|
|
@@ -3510,7 +4763,7 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
3510
4763
|
0
|
|
3511
4764
|
]
|
|
3512
4765
|
});
|
|
3513
|
-
const b =
|
|
4766
|
+
const b = processSchema(def.right, ctx, {
|
|
3514
4767
|
...params,
|
|
3515
4768
|
path: [
|
|
3516
4769
|
...params.path,
|
|
@@ -3519,16 +4772,76 @@ const intersectionProcessor = (schema, ctx, json, params) => {
|
|
|
3519
4772
|
]
|
|
3520
4773
|
});
|
|
3521
4774
|
const isSimpleIntersection = (val) => "allOf" in val && Object.keys(val).length === 1;
|
|
3522
|
-
|
|
4775
|
+
const allOf = [...isSimpleIntersection(a) ? a.allOf : [a], ...isSimpleIntersection(b) ? b.allOf : [b]];
|
|
4776
|
+
json.allOf = allOf;
|
|
4777
|
+
ctx.intersections.push(allOf);
|
|
3523
4778
|
};
|
|
4779
|
+
/** JSON object keys are always strings, so a numeric record key schema is re-expressed over the
|
|
4780
|
+
* numeric-string form the record parser matches. Deferred to `finalize`, after the flatten: a key
|
|
4781
|
+
* behind a wrapper only carries its own `type` before then, and a union key only has its branches.
|
|
4782
|
+
*
|
|
4783
|
+
* A numeric bound cannot apply to a property name, so `minimum` and its siblings are dropped rather
|
|
4784
|
+
* than carried over: keeping them beside `type: "string"` reproduces the match-nothing schema this
|
|
4785
|
+
* exists to fix. A key that carries one therefore emits wider than the record parses — `z.record(z.number().min(5), V)`
|
|
4786
|
+
* accepts `"3"` — which is the deliberate trade, since throwing on it would reject an ordinary schema
|
|
4787
|
+
* outright. */
|
|
4788
|
+
function stringifyKeyNames(bySchema, json, visited) {
|
|
4789
|
+
if (json.$ref) {
|
|
4790
|
+
if (visited.has(json)) return json;
|
|
4791
|
+
visited.add(json);
|
|
4792
|
+
const def = bySchema.get(json)?.def;
|
|
4793
|
+
if (!def) return json;
|
|
4794
|
+
const inlined = stringifyKeyNames(bySchema, def, visited);
|
|
4795
|
+
return inlined === def ? json : inlined;
|
|
4796
|
+
}
|
|
4797
|
+
for (const keyword of ["anyOf", "oneOf"]) {
|
|
4798
|
+
const branches = json[keyword];
|
|
4799
|
+
if (!Array.isArray(branches)) continue;
|
|
4800
|
+
const mapped = branches.map((branch) => stringifyKeyNames(bySchema, branch, visited));
|
|
4801
|
+
if (mapped.some((branch, i) => branch !== branches[i])) json = {
|
|
4802
|
+
...json,
|
|
4803
|
+
[keyword]: mapped
|
|
4804
|
+
};
|
|
4805
|
+
}
|
|
4806
|
+
const types = Array.isArray(json.type) ? json.type : [json.type];
|
|
4807
|
+
const numericType = !types.includes("string") && types.some((t) => t === "number" || t === "integer");
|
|
4808
|
+
const values = json.enum ?? (json.const !== void 0 ? [json.const] : void 0);
|
|
4809
|
+
if (!numericType && !values?.some((v) => typeof v === "number")) return json;
|
|
4810
|
+
const { minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf, format, id, ...rest } = json;
|
|
4811
|
+
if (rest.enum) rest.enum = rest.enum.map((v) => typeof v === "number" ? String(v) : v);
|
|
4812
|
+
else if (typeof rest.const === "number") rest.const = String(rest.const);
|
|
4813
|
+
if (!numericType) return rest;
|
|
4814
|
+
rest.type = "string";
|
|
4815
|
+
if (!values) rest.pattern = (types.includes("number") ? number$1 : integer).source;
|
|
4816
|
+
return rest;
|
|
4817
|
+
}
|
|
4818
|
+
/** Every record of one conversion, so the carriers are found in a single pass rather than once per record. */
|
|
4819
|
+
const pendingRecords = /* @__PURE__ */ new WeakMap();
|
|
4820
|
+
function rewriteKeyNames(ctx) {
|
|
4821
|
+
const bySchema = /* @__PURE__ */ new Map();
|
|
4822
|
+
for (const entry of ctx.seen.values()) if (entry.def && !bySchema.has(entry.schema)) bySchema.set(entry.schema, entry);
|
|
4823
|
+
const rewrites = /* @__PURE__ */ new Map();
|
|
4824
|
+
for (const record of pendingRecords.get(ctx) ?? []) {
|
|
4825
|
+
const seen = ctx.seen.get(record);
|
|
4826
|
+
const names = (seen?.def ?? seen?.schema)?.propertyNames;
|
|
4827
|
+
if (!names || names === true || rewrites.has(names)) continue;
|
|
4828
|
+
const rewritten = stringifyKeyNames(bySchema, names, /* @__PURE__ */ new Set());
|
|
4829
|
+
if (rewritten !== names) rewrites.set(names, rewritten);
|
|
4830
|
+
}
|
|
4831
|
+
if (!rewrites.size) return;
|
|
4832
|
+
for (const entry of ctx.seen.values()) for (const carrier of [entry.schema, entry.def]) {
|
|
4833
|
+
const rewritten = carrier && rewrites.get(carrier.propertyNames);
|
|
4834
|
+
if (rewritten) carrier.propertyNames = rewritten;
|
|
4835
|
+
}
|
|
4836
|
+
}
|
|
3524
4837
|
const recordProcessor = (schema, ctx, _json, params) => {
|
|
3525
4838
|
const json = _json;
|
|
3526
4839
|
const def = schema._zod.def;
|
|
3527
4840
|
json.type = "object";
|
|
3528
4841
|
const keyType = def.keyType;
|
|
3529
|
-
const patterns = keyType.
|
|
4842
|
+
const patterns = aggregateChecks(keyType).patterns;
|
|
3530
4843
|
if (def.mode === "loose" && patterns && patterns.size > 0) {
|
|
3531
|
-
const valueSchema =
|
|
4844
|
+
const valueSchema = processSchema(def.valueType, ctx, {
|
|
3532
4845
|
...params,
|
|
3533
4846
|
path: [
|
|
3534
4847
|
...params.path,
|
|
@@ -3537,26 +4850,36 @@ const recordProcessor = (schema, ctx, _json, params) => {
|
|
|
3537
4850
|
]
|
|
3538
4851
|
});
|
|
3539
4852
|
json.patternProperties = {};
|
|
3540
|
-
for (const pattern of patterns) json.patternProperties
|
|
4853
|
+
for (const pattern of patterns) assignProp(json.patternProperties, exactPattern(pattern).source, valueSchema);
|
|
3541
4854
|
} else {
|
|
3542
|
-
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12")
|
|
3543
|
-
|
|
3544
|
-
|
|
3545
|
-
|
|
3546
|
-
|
|
4855
|
+
if (ctx.target === "draft-07" || ctx.target === "draft-2020-12") {
|
|
4856
|
+
json.propertyNames = processSchema(def.keyType, ctx, {
|
|
4857
|
+
...params,
|
|
4858
|
+
path: [...params.path, "propertyNames"]
|
|
4859
|
+
});
|
|
4860
|
+
let pending = pendingRecords.get(ctx);
|
|
4861
|
+
if (!pending) {
|
|
4862
|
+
pending = [];
|
|
4863
|
+
pendingRecords.set(ctx, pending);
|
|
4864
|
+
ctx.deferred.push(() => rewriteKeyNames(ctx));
|
|
4865
|
+
}
|
|
4866
|
+
pending.push(schema);
|
|
4867
|
+
}
|
|
4868
|
+
json.additionalProperties = processSchema(def.valueType, ctx, {
|
|
3547
4869
|
...params,
|
|
3548
4870
|
path: [...params.path, "additionalProperties"]
|
|
3549
4871
|
});
|
|
3550
4872
|
}
|
|
3551
4873
|
const keyValues = keyType._zod.values;
|
|
3552
|
-
|
|
4874
|
+
const omittableOnInput = ctx.io === "input" && inputOptin(def.valueType) !== void 0;
|
|
4875
|
+
if (keyValues && !def.partial && !omittableOnInput) {
|
|
3553
4876
|
const validKeyValues = [...keyValues].filter((v) => typeof v === "string" || typeof v === "number");
|
|
3554
|
-
if (validKeyValues.length > 0) json.required = validKeyValues;
|
|
4877
|
+
if (validKeyValues.length > 0) json.required = validKeyValues.map(String);
|
|
3555
4878
|
}
|
|
3556
4879
|
};
|
|
3557
4880
|
const nullableProcessor = (schema, ctx, json, params) => {
|
|
3558
4881
|
const def = schema._zod.def;
|
|
3559
|
-
const inner =
|
|
4882
|
+
const inner = processSchema(def.innerType, ctx, params);
|
|
3560
4883
|
const seen = ctx.seen.get(schema);
|
|
3561
4884
|
if (ctx.target === "openapi-3.0") {
|
|
3562
4885
|
seen.ref = def.innerType;
|
|
@@ -3565,106 +4888,125 @@ const nullableProcessor = (schema, ctx, json, params) => {
|
|
|
3565
4888
|
};
|
|
3566
4889
|
const nonoptionalProcessor = (schema, ctx, _json, params) => {
|
|
3567
4890
|
const def = schema._zod.def;
|
|
3568
|
-
|
|
4891
|
+
processSchema(def.innerType, ctx, params);
|
|
3569
4892
|
const seen = ctx.seen.get(schema);
|
|
3570
4893
|
seen.ref = def.innerType;
|
|
3571
4894
|
};
|
|
4895
|
+
/** Round-trips a default value through JSON so the emitted schema is guaranteed to be valid JSON.
|
|
4896
|
+
* A BigInt has no reliable encoding, so it goes through `unrepresentable` like any other
|
|
4897
|
+
* unrepresentable value. Returns a sentinel when the caller must not write a default of its own. */
|
|
4898
|
+
const UNREPRESENTABLE_DEFAULT = Symbol();
|
|
4899
|
+
function serializeDefaultValue(value, schema, ctx, json, params) {
|
|
4900
|
+
let unrepresentable = false;
|
|
4901
|
+
const serialized = JSON.stringify(value, (_, val) => {
|
|
4902
|
+
if (typeof val !== "bigint") return val;
|
|
4903
|
+
unrepresentable = true;
|
|
4904
|
+
return null;
|
|
4905
|
+
});
|
|
4906
|
+
if (!unrepresentable) return JSON.parse(serialized);
|
|
4907
|
+
handleUnrepresentable(schema, ctx, json, params, "BigInt defaults cannot be represented in JSON Schema");
|
|
4908
|
+
return UNREPRESENTABLE_DEFAULT;
|
|
4909
|
+
}
|
|
3572
4910
|
const defaultProcessor = (schema, ctx, json, params) => {
|
|
3573
4911
|
const def = schema._zod.def;
|
|
3574
|
-
|
|
4912
|
+
processSchema(def.innerType, ctx, params);
|
|
3575
4913
|
const seen = ctx.seen.get(schema);
|
|
3576
4914
|
seen.ref = def.innerType;
|
|
3577
|
-
|
|
4915
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
|
|
4916
|
+
if (value !== UNREPRESENTABLE_DEFAULT) json.default = value;
|
|
3578
4917
|
};
|
|
3579
4918
|
const prefaultProcessor = (schema, ctx, json, params) => {
|
|
3580
4919
|
const def = schema._zod.def;
|
|
3581
|
-
|
|
4920
|
+
processSchema(def.innerType, ctx, params);
|
|
3582
4921
|
const seen = ctx.seen.get(schema);
|
|
3583
4922
|
seen.ref = def.innerType;
|
|
3584
|
-
if (ctx.io
|
|
4923
|
+
if (ctx.io !== "input") return;
|
|
4924
|
+
const value = serializeDefaultValue(def.defaultValue, schema, ctx, json, params);
|
|
4925
|
+
if (value !== UNREPRESENTABLE_DEFAULT) json._prefault = value;
|
|
3585
4926
|
};
|
|
3586
4927
|
const catchProcessor = (schema, ctx, json, params) => {
|
|
3587
4928
|
const def = schema._zod.def;
|
|
3588
|
-
|
|
4929
|
+
processSchema(def.innerType, ctx, params);
|
|
3589
4930
|
const seen = ctx.seen.get(schema);
|
|
3590
4931
|
seen.ref = def.innerType;
|
|
3591
4932
|
let catchValue;
|
|
3592
4933
|
try {
|
|
3593
4934
|
catchValue = def.catchValue(void 0);
|
|
3594
4935
|
} catch {
|
|
3595
|
-
|
|
4936
|
+
handleUnrepresentable(schema, ctx, json, params, "Dynamic catch values are not supported in JSON Schema");
|
|
4937
|
+
return;
|
|
3596
4938
|
}
|
|
3597
4939
|
json.default = catchValue;
|
|
3598
4940
|
};
|
|
3599
4941
|
const pipeProcessor = (schema, ctx, _json, params) => {
|
|
3600
4942
|
const def = schema._zod.def;
|
|
3601
|
-
const
|
|
3602
|
-
|
|
4943
|
+
const inIsTransform = def.in._zod.traits.has("$ZodTransform");
|
|
4944
|
+
const innerType = ctx.io === "input" ? inIsTransform ? def.out : def.in : def.out;
|
|
4945
|
+
processSchema(innerType, ctx, params);
|
|
3603
4946
|
const seen = ctx.seen.get(schema);
|
|
3604
4947
|
seen.ref = innerType;
|
|
3605
4948
|
};
|
|
3606
4949
|
const readonlyProcessor = (schema, ctx, json, params) => {
|
|
3607
4950
|
const def = schema._zod.def;
|
|
3608
|
-
|
|
4951
|
+
processSchema(def.innerType, ctx, params);
|
|
3609
4952
|
const seen = ctx.seen.get(schema);
|
|
3610
4953
|
seen.ref = def.innerType;
|
|
3611
4954
|
json.readOnly = true;
|
|
3612
4955
|
};
|
|
3613
4956
|
const optionalProcessor = (schema, ctx, _json, params) => {
|
|
3614
4957
|
const def = schema._zod.def;
|
|
3615
|
-
|
|
4958
|
+
processSchema(def.innerType, ctx, params);
|
|
3616
4959
|
const seen = ctx.seen.get(schema);
|
|
3617
4960
|
seen.ref = def.innerType;
|
|
3618
4961
|
};
|
|
3619
|
-
const
|
|
3620
|
-
|
|
3621
|
-
|
|
3622
|
-
|
|
3623
|
-
|
|
3624
|
-
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
|
|
3628
|
-
|
|
3629
|
-
|
|
3630
|
-
|
|
3631
|
-
|
|
3632
|
-
}
|
|
3633
|
-
|
|
3634
|
-
|
|
3635
|
-
|
|
3636
|
-
|
|
3637
|
-
|
|
3638
|
-
|
|
3639
|
-
}
|
|
3640
|
-
|
|
3641
|
-
$ZodISODuration.init(inst, def);
|
|
3642
|
-
ZodStringFormat.init(inst, def);
|
|
3643
|
-
});
|
|
3644
|
-
function duration(params) {
|
|
3645
|
-
return /* @__PURE__ */ _isoDuration(ZodISODuration, params);
|
|
4962
|
+
const _installedErrorProtos = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
|
|
4963
|
+
function _lazyMethod(proto, key, make) {
|
|
4964
|
+
Object.defineProperty(proto, key, {
|
|
4965
|
+
configurable: true,
|
|
4966
|
+
enumerable: false,
|
|
4967
|
+
get() {
|
|
4968
|
+
const value = make(this);
|
|
4969
|
+
Object.defineProperty(this, key, {
|
|
4970
|
+
value,
|
|
4971
|
+
configurable: true,
|
|
4972
|
+
writable: true
|
|
4973
|
+
});
|
|
4974
|
+
return value;
|
|
4975
|
+
},
|
|
4976
|
+
set(value) {
|
|
4977
|
+
Object.defineProperty(this, key, {
|
|
4978
|
+
value,
|
|
4979
|
+
configurable: true,
|
|
4980
|
+
writable: true
|
|
4981
|
+
});
|
|
4982
|
+
}
|
|
4983
|
+
});
|
|
3646
4984
|
}
|
|
3647
4985
|
const initializer = (inst, issues) => {
|
|
3648
4986
|
$ZodError.init(inst, issues);
|
|
3649
4987
|
inst.name = "ZodError";
|
|
3650
|
-
Object.
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3654
|
-
|
|
3655
|
-
|
|
3656
|
-
|
|
3657
|
-
|
|
3658
|
-
|
|
3659
|
-
|
|
3660
|
-
|
|
3661
|
-
|
|
3662
|
-
|
|
3663
|
-
|
|
4988
|
+
const proto = Object.getPrototypeOf(inst);
|
|
4989
|
+
if (_installedErrorProtos.has(proto)) return;
|
|
4990
|
+
_installedErrorProtos.add(proto);
|
|
4991
|
+
_lazyMethod(proto, "format", (self) => (mapper) => formatError(self, mapper));
|
|
4992
|
+
_lazyMethod(proto, "flatten", (self) => (mapper) => flattenError(self, mapper));
|
|
4993
|
+
_lazyMethod(proto, "addIssue", (self) => (issue) => {
|
|
4994
|
+
self.issues.push(issue);
|
|
4995
|
+
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
|
|
4996
|
+
});
|
|
4997
|
+
_lazyMethod(proto, "addIssues", (self) => (issues) => {
|
|
4998
|
+
self.issues.push(...issues);
|
|
4999
|
+
self.message = JSON.stringify(self.issues, jsonStringifyReplacer, 2);
|
|
5000
|
+
});
|
|
5001
|
+
Object.defineProperty(proto, "isEmpty", {
|
|
5002
|
+
configurable: true,
|
|
5003
|
+
enumerable: false,
|
|
5004
|
+
get() {
|
|
5005
|
+
return this.issues.length === 0;
|
|
5006
|
+
}
|
|
3664
5007
|
});
|
|
3665
5008
|
};
|
|
3666
|
-
$constructor("ZodError", initializer);
|
|
3667
|
-
const ZodRealError = $constructor("ZodError", initializer, { Parent: Error });
|
|
5009
|
+
const ZodRealError = /* @__PURE__ */ $constructor("ZodError", initializer, void 0, { Parent: Error });
|
|
3668
5010
|
const parse = /* @__PURE__ */ _parse(ZodRealError);
|
|
3669
5011
|
const parseAsync = /* @__PURE__ */ _parseAsync(ZodRealError);
|
|
3670
5012
|
const safeParse = /* @__PURE__ */ _safeParse(ZodRealError);
|
|
@@ -3677,137 +5019,319 @@ const safeEncode = /* @__PURE__ */ _safeEncode(ZodRealError);
|
|
|
3677
5019
|
const safeDecode = /* @__PURE__ */ _safeDecode(ZodRealError);
|
|
3678
5020
|
const safeEncodeAsync = /* @__PURE__ */ _safeEncodeAsync(ZodRealError);
|
|
3679
5021
|
const safeDecodeAsync = /* @__PURE__ */ _safeDecodeAsync(ZodRealError);
|
|
5022
|
+
function _ensureDefaultLocale() {
|
|
5023
|
+
if (!globalConfig.localeError) config(en_default());
|
|
5024
|
+
}
|
|
5025
|
+
function _ensureDefaultMemoizer() {
|
|
5026
|
+
if (!globalConfig.memoizer) config({ memoizer: memoizer() });
|
|
5027
|
+
}
|
|
3680
5028
|
const ZodType = /* @__PURE__ */ $constructor("ZodType", (inst, def) => {
|
|
5029
|
+
_ensureDefaultLocale();
|
|
3681
5030
|
$ZodType.init(inst, def);
|
|
3682
|
-
Object.assign(inst["~standard"], { jsonSchema: {
|
|
3683
|
-
input: createStandardJSONSchemaMethod(inst, "input"),
|
|
3684
|
-
output: createStandardJSONSchemaMethod(inst, "output")
|
|
3685
|
-
} });
|
|
3686
|
-
inst.toJSONSchema = createToJSONSchemaMethod(inst, {});
|
|
3687
5031
|
inst.def = def;
|
|
3688
5032
|
inst.type = def.type;
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
5033
|
+
return inst;
|
|
5034
|
+
}, {
|
|
5035
|
+
check(...chks) {
|
|
5036
|
+
const def = this.def;
|
|
5037
|
+
return this.clone(mergeDefs(def, { checks: [...def.checks ?? [], ...chks.map((ch) => typeof ch === "function" ? { _zod: {
|
|
3692
5038
|
check: ch,
|
|
3693
5039
|
def: { check: "custom" },
|
|
3694
5040
|
onattach: []
|
|
3695
5041
|
} } : ch)] }), { parent: true });
|
|
3696
|
-
}
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
3703
|
-
|
|
3704
|
-
|
|
3705
|
-
|
|
3706
|
-
|
|
3707
|
-
|
|
3708
|
-
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
5042
|
+
},
|
|
5043
|
+
with(...chks) {
|
|
5044
|
+
return this.check(...chks);
|
|
5045
|
+
},
|
|
5046
|
+
clone(def, params) {
|
|
5047
|
+
return clone(this, def, params);
|
|
5048
|
+
},
|
|
5049
|
+
brand() {
|
|
5050
|
+
return this;
|
|
5051
|
+
},
|
|
5052
|
+
register(reg, meta) {
|
|
5053
|
+
reg.add(this, meta);
|
|
5054
|
+
return this;
|
|
5055
|
+
},
|
|
5056
|
+
refine(check, params) {
|
|
5057
|
+
return this.check(refine(check, params));
|
|
5058
|
+
},
|
|
5059
|
+
superRefine(refinement, params) {
|
|
5060
|
+
return this.check(superRefine(refinement, params));
|
|
5061
|
+
},
|
|
5062
|
+
overwrite(fn) {
|
|
5063
|
+
return this.check(/* @__PURE__ */ _overwrite(fn));
|
|
5064
|
+
},
|
|
5065
|
+
optional() {
|
|
5066
|
+
return optional(this);
|
|
5067
|
+
},
|
|
5068
|
+
exactOptional() {
|
|
5069
|
+
return exactOptional(this);
|
|
5070
|
+
},
|
|
5071
|
+
nullable() {
|
|
5072
|
+
return nullable(this);
|
|
5073
|
+
},
|
|
5074
|
+
nullish() {
|
|
5075
|
+
return optional(nullable(this));
|
|
5076
|
+
},
|
|
5077
|
+
nonoptional(params) {
|
|
5078
|
+
return nonoptional(this, params);
|
|
5079
|
+
},
|
|
5080
|
+
array() {
|
|
5081
|
+
return array(this);
|
|
5082
|
+
},
|
|
5083
|
+
or(arg) {
|
|
5084
|
+
return union([this, arg]);
|
|
5085
|
+
},
|
|
5086
|
+
and(arg) {
|
|
5087
|
+
return intersection(this, arg);
|
|
5088
|
+
},
|
|
5089
|
+
transform(tx) {
|
|
5090
|
+
return pipe(this, transform(tx));
|
|
5091
|
+
},
|
|
5092
|
+
default(d) {
|
|
5093
|
+
return _default(this, d);
|
|
5094
|
+
},
|
|
5095
|
+
prefault(d) {
|
|
5096
|
+
return prefault(this, d);
|
|
5097
|
+
},
|
|
5098
|
+
catch(params) {
|
|
5099
|
+
return _catch(this, params);
|
|
5100
|
+
},
|
|
5101
|
+
pipe(target) {
|
|
5102
|
+
return pipe(this, target);
|
|
5103
|
+
},
|
|
5104
|
+
readonly() {
|
|
5105
|
+
return readonly(this);
|
|
5106
|
+
},
|
|
5107
|
+
describe(description) {
|
|
5108
|
+
const cl = this.clone();
|
|
3736
5109
|
globalRegistry.add(cl, { description });
|
|
3737
5110
|
return cl;
|
|
3738
|
-
}
|
|
3739
|
-
|
|
3740
|
-
get()
|
|
3741
|
-
|
|
3742
|
-
},
|
|
3743
|
-
configurable: true
|
|
3744
|
-
});
|
|
3745
|
-
inst.meta = (...args) => {
|
|
3746
|
-
if (args.length === 0) return globalRegistry.get(inst);
|
|
3747
|
-
const cl = inst.clone();
|
|
5111
|
+
},
|
|
5112
|
+
meta(...args) {
|
|
5113
|
+
if (args.length === 0) return globalRegistry.get(this);
|
|
5114
|
+
const cl = this.clone();
|
|
3748
5115
|
globalRegistry.add(cl, args[0]);
|
|
3749
5116
|
return cl;
|
|
3750
|
-
}
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
5117
|
+
},
|
|
5118
|
+
isOptional() {
|
|
5119
|
+
return this.safeParse(void 0).success;
|
|
5120
|
+
},
|
|
5121
|
+
isNullable() {
|
|
5122
|
+
return this.safeParse(null).success;
|
|
5123
|
+
},
|
|
5124
|
+
apply(fn, ...args) {
|
|
5125
|
+
return args.length === 0 ? fn(this) : fn(this, ...args);
|
|
5126
|
+
},
|
|
5127
|
+
get "~standard"() {
|
|
5128
|
+
return hide(this, "~standard", {
|
|
5129
|
+
...standardProps(this),
|
|
5130
|
+
jsonSchema: {
|
|
5131
|
+
input: createStandardJSONSchemaMethod(this, "input"),
|
|
5132
|
+
output: createStandardJSONSchemaMethod(this, "output")
|
|
5133
|
+
}
|
|
5134
|
+
});
|
|
5135
|
+
},
|
|
5136
|
+
set "~standard"(value) {
|
|
5137
|
+
own(this, "~standard", value);
|
|
5138
|
+
},
|
|
5139
|
+
parse: function _parse(data, params) {
|
|
5140
|
+
return parse(this, data, params, { callee: _parse });
|
|
5141
|
+
},
|
|
5142
|
+
parseAsync: async function _parseAsync(data, params) {
|
|
5143
|
+
return await parseAsync(this, data, params, { callee: _parseAsync });
|
|
5144
|
+
},
|
|
5145
|
+
safeParse(data, params) {
|
|
5146
|
+
return safeParse(this, data, params);
|
|
5147
|
+
},
|
|
5148
|
+
async safeParseAsync(data, params) {
|
|
5149
|
+
return safeParseAsync(this, data, params);
|
|
5150
|
+
},
|
|
5151
|
+
get spa() {
|
|
5152
|
+
return this?.safeParseAsync;
|
|
5153
|
+
},
|
|
5154
|
+
set spa(value) {
|
|
5155
|
+
own(this, "spa", value);
|
|
5156
|
+
},
|
|
5157
|
+
validate(data, params) {
|
|
5158
|
+
return validate(this, data, params);
|
|
5159
|
+
},
|
|
5160
|
+
validateAsync(data, params) {
|
|
5161
|
+
return validateAsync$1(this, data, params);
|
|
5162
|
+
},
|
|
5163
|
+
encode: function _encode(data, params) {
|
|
5164
|
+
return encode(this, data, params, { callee: _encode });
|
|
5165
|
+
},
|
|
5166
|
+
decode: function _decode(data, params) {
|
|
5167
|
+
return decode(this, data, params, { callee: _decode });
|
|
5168
|
+
},
|
|
5169
|
+
encodeAsync: async function _encodeAsync(data, params) {
|
|
5170
|
+
return await encodeAsync(this, data, params, { callee: _encodeAsync });
|
|
5171
|
+
},
|
|
5172
|
+
decodeAsync: async function _decodeAsync(data, params) {
|
|
5173
|
+
return await decodeAsync(this, data, params, { callee: _decodeAsync });
|
|
5174
|
+
},
|
|
5175
|
+
safeEncode(data, params) {
|
|
5176
|
+
return safeEncode(this, data, params);
|
|
5177
|
+
},
|
|
5178
|
+
safeDecode(data, params) {
|
|
5179
|
+
return safeDecode(this, data, params);
|
|
5180
|
+
},
|
|
5181
|
+
async safeEncodeAsync(data, params) {
|
|
5182
|
+
return safeEncodeAsync(this, data, params);
|
|
5183
|
+
},
|
|
5184
|
+
async safeDecodeAsync(data, params) {
|
|
5185
|
+
return safeDecodeAsync(this, data, params);
|
|
5186
|
+
},
|
|
5187
|
+
toJSONSchema(params) {
|
|
5188
|
+
return createToJSONSchemaMethod(this, {})(params);
|
|
5189
|
+
},
|
|
5190
|
+
get description() {
|
|
5191
|
+
return globalRegistry.get(this)?.description;
|
|
5192
|
+
},
|
|
5193
|
+
get _def() {
|
|
5194
|
+
return this._zod.def;
|
|
5195
|
+
}
|
|
3755
5196
|
});
|
|
3756
5197
|
/** @internal */
|
|
3757
5198
|
const _ZodString = /* @__PURE__ */ $constructor("_ZodString", (inst, def) => {
|
|
3758
5199
|
$ZodString.init(inst, def);
|
|
3759
5200
|
ZodType.init(inst, def);
|
|
3760
5201
|
inst._zod.processJSONSchema = (ctx, json, params) => stringProcessor(inst, ctx, json, params);
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
|
|
3772
|
-
|
|
3773
|
-
|
|
3774
|
-
|
|
3775
|
-
|
|
3776
|
-
|
|
3777
|
-
|
|
3778
|
-
|
|
3779
|
-
|
|
3780
|
-
}
|
|
5202
|
+
}, /* @__PURE__ */ derived({
|
|
5203
|
+
format: (inst) => aggregateChecks(inst).format ?? null,
|
|
5204
|
+
minLength: (inst) => aggregateChecks(inst).minimum ?? null,
|
|
5205
|
+
maxLength: (inst) => aggregateChecks(inst).maximum ?? null
|
|
5206
|
+
}, {
|
|
5207
|
+
regex(...args) {
|
|
5208
|
+
return this.check(/* @__PURE__ */ _regex(...args));
|
|
5209
|
+
},
|
|
5210
|
+
includes(...args) {
|
|
5211
|
+
return this.check(/* @__PURE__ */ _includes(...args));
|
|
5212
|
+
},
|
|
5213
|
+
startsWith(...args) {
|
|
5214
|
+
return this.check(/* @__PURE__ */ _startsWith(...args));
|
|
5215
|
+
},
|
|
5216
|
+
endsWith(...args) {
|
|
5217
|
+
return this.check(/* @__PURE__ */ _endsWith(...args));
|
|
5218
|
+
},
|
|
5219
|
+
min(...args) {
|
|
5220
|
+
return this.check(/* @__PURE__ */ _minLength(...args));
|
|
5221
|
+
},
|
|
5222
|
+
max(...args) {
|
|
5223
|
+
return this.check(/* @__PURE__ */ _maxLength(...args));
|
|
5224
|
+
},
|
|
5225
|
+
length(...args) {
|
|
5226
|
+
return this.check(/* @__PURE__ */ _length(...args));
|
|
5227
|
+
},
|
|
5228
|
+
nonempty(...args) {
|
|
5229
|
+
return this.check(/* @__PURE__ */ _minLength(1, ...args));
|
|
5230
|
+
},
|
|
5231
|
+
lowercase(params) {
|
|
5232
|
+
return this.check(/* @__PURE__ */ _lowercase(params));
|
|
5233
|
+
},
|
|
5234
|
+
uppercase(params) {
|
|
5235
|
+
return this.check(/* @__PURE__ */ _uppercase(params));
|
|
5236
|
+
},
|
|
5237
|
+
trim() {
|
|
5238
|
+
return this.check(/* @__PURE__ */ _trim());
|
|
5239
|
+
},
|
|
5240
|
+
normalize(...args) {
|
|
5241
|
+
return this.check(/* @__PURE__ */ _normalize(...args));
|
|
5242
|
+
},
|
|
5243
|
+
toLowerCase() {
|
|
5244
|
+
return this.check(/* @__PURE__ */ _toLowerCase());
|
|
5245
|
+
},
|
|
5246
|
+
toUpperCase() {
|
|
5247
|
+
return this.check(/* @__PURE__ */ _toUpperCase());
|
|
5248
|
+
},
|
|
5249
|
+
slugify() {
|
|
5250
|
+
return this.check(/* @__PURE__ */ _slugify());
|
|
5251
|
+
}
|
|
5252
|
+
}));
|
|
3781
5253
|
const ZodString = /* @__PURE__ */ $constructor("ZodString", (inst, def) => {
|
|
3782
5254
|
$ZodString.init(inst, def);
|
|
3783
5255
|
_ZodString.init(inst, def);
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
5256
|
+
}, {
|
|
5257
|
+
email(params) {
|
|
5258
|
+
return this.check(/* @__PURE__ */ _email(ZodEmail, params));
|
|
5259
|
+
},
|
|
5260
|
+
url(params) {
|
|
5261
|
+
return this.check(/* @__PURE__ */ _url(ZodURL, params));
|
|
5262
|
+
},
|
|
5263
|
+
jwt(params) {
|
|
5264
|
+
return this.check(/* @__PURE__ */ _jwt(ZodJWT, params));
|
|
5265
|
+
},
|
|
5266
|
+
emoji(params) {
|
|
5267
|
+
return this.check(/* @__PURE__ */ _emoji(ZodEmoji, params));
|
|
5268
|
+
},
|
|
5269
|
+
guid(params) {
|
|
5270
|
+
return this.check(/* @__PURE__ */ _guid(ZodGUID, params));
|
|
5271
|
+
},
|
|
5272
|
+
uuid(params) {
|
|
5273
|
+
return this.check(/* @__PURE__ */ _uuid(ZodUUID, params));
|
|
5274
|
+
},
|
|
5275
|
+
uuidv4(params) {
|
|
5276
|
+
return this.check(/* @__PURE__ */ _uuidv4(ZodUUID, params));
|
|
5277
|
+
},
|
|
5278
|
+
uuidv6(params) {
|
|
5279
|
+
return this.check(/* @__PURE__ */ _uuidv6(ZodUUID, params));
|
|
5280
|
+
},
|
|
5281
|
+
uuidv7(params) {
|
|
5282
|
+
return this.check(/* @__PURE__ */ _uuidv7(ZodUUID, params));
|
|
5283
|
+
},
|
|
5284
|
+
nanoid(params) {
|
|
5285
|
+
return this.check(/* @__PURE__ */ _nanoid(ZodNanoID, params));
|
|
5286
|
+
},
|
|
5287
|
+
cuid(params) {
|
|
5288
|
+
return this.check(/* @__PURE__ */ _cuid(ZodCUID, params));
|
|
5289
|
+
},
|
|
5290
|
+
cuid2(params) {
|
|
5291
|
+
return this.check(/* @__PURE__ */ _cuid2(ZodCUID2, params));
|
|
5292
|
+
},
|
|
5293
|
+
ulid(params) {
|
|
5294
|
+
return this.check(/* @__PURE__ */ _ulid(ZodULID, params));
|
|
5295
|
+
},
|
|
5296
|
+
base64(params) {
|
|
5297
|
+
return this.check(/* @__PURE__ */ _base64(ZodBase64, params));
|
|
5298
|
+
},
|
|
5299
|
+
base64url(params) {
|
|
5300
|
+
return this.check(/* @__PURE__ */ _base64url(ZodBase64URL, params));
|
|
5301
|
+
},
|
|
5302
|
+
xid(params) {
|
|
5303
|
+
return this.check(/* @__PURE__ */ _xid(ZodXID, params));
|
|
5304
|
+
},
|
|
5305
|
+
ksuid(params) {
|
|
5306
|
+
return this.check(/* @__PURE__ */ _ksuid(ZodKSUID, params));
|
|
5307
|
+
},
|
|
5308
|
+
ipv4(params) {
|
|
5309
|
+
return this.check(/* @__PURE__ */ _ipv4(ZodIPv4, params));
|
|
5310
|
+
},
|
|
5311
|
+
ipv6(params) {
|
|
5312
|
+
return this.check(/* @__PURE__ */ _ipv6(ZodIPv6, params));
|
|
5313
|
+
},
|
|
5314
|
+
cidrv4(params) {
|
|
5315
|
+
return this.check(/* @__PURE__ */ _cidrv4(ZodCIDRv4, params));
|
|
5316
|
+
},
|
|
5317
|
+
cidrv6(params) {
|
|
5318
|
+
return this.check(/* @__PURE__ */ _cidrv6(ZodCIDRv6, params));
|
|
5319
|
+
},
|
|
5320
|
+
e164(params) {
|
|
5321
|
+
return this.check(/* @__PURE__ */ _e164(ZodE164, params));
|
|
5322
|
+
},
|
|
5323
|
+
datetime(params) {
|
|
5324
|
+
return this.check(/* @__PURE__ */ _isoDateTime(ZodISODateTime, params));
|
|
5325
|
+
},
|
|
5326
|
+
date(params) {
|
|
5327
|
+
return this.check(/* @__PURE__ */ _isoDate(ZodISODate, params));
|
|
5328
|
+
},
|
|
5329
|
+
time(params) {
|
|
5330
|
+
return this.check(/* @__PURE__ */ _isoTime(ZodISOTime, params));
|
|
5331
|
+
},
|
|
5332
|
+
duration(params) {
|
|
5333
|
+
return this.check(/* @__PURE__ */ _isoDuration(ZodISODuration, params));
|
|
5334
|
+
}
|
|
3811
5335
|
});
|
|
3812
5336
|
function string(params) {
|
|
3813
5337
|
return /* @__PURE__ */ _string(ZodString, params);
|
|
@@ -3816,6 +5340,22 @@ const ZodStringFormat = /* @__PURE__ */ $constructor("ZodStringFormat", (inst, d
|
|
|
3816
5340
|
$ZodStringFormat.init(inst, def);
|
|
3817
5341
|
_ZodString.init(inst, def);
|
|
3818
5342
|
});
|
|
5343
|
+
const ZodISODateTime = /* @__PURE__ */ $constructor("ZodISODateTime", (inst, def) => {
|
|
5344
|
+
$ZodISODateTime.init(inst, def);
|
|
5345
|
+
ZodStringFormat.init(inst, def);
|
|
5346
|
+
});
|
|
5347
|
+
const ZodISODate = /* @__PURE__ */ $constructor("ZodISODate", (inst, def) => {
|
|
5348
|
+
$ZodISODate.init(inst, def);
|
|
5349
|
+
ZodStringFormat.init(inst, def);
|
|
5350
|
+
});
|
|
5351
|
+
const ZodISOTime = /* @__PURE__ */ $constructor("ZodISOTime", (inst, def) => {
|
|
5352
|
+
$ZodISOTime.init(inst, def);
|
|
5353
|
+
ZodStringFormat.init(inst, def);
|
|
5354
|
+
});
|
|
5355
|
+
const ZodISODuration = /* @__PURE__ */ $constructor("ZodISODuration", (inst, def) => {
|
|
5356
|
+
$ZodISODuration.init(inst, def);
|
|
5357
|
+
ZodStringFormat.init(inst, def);
|
|
5358
|
+
});
|
|
3819
5359
|
const ZodEmail = /* @__PURE__ */ $constructor("ZodEmail", (inst, def) => {
|
|
3820
5360
|
$ZodEmail.init(inst, def);
|
|
3821
5361
|
ZodStringFormat.init(inst, def);
|
|
@@ -3840,6 +5380,11 @@ const ZodNanoID = /* @__PURE__ */ $constructor("ZodNanoID", (inst, def) => {
|
|
|
3840
5380
|
$ZodNanoID.init(inst, def);
|
|
3841
5381
|
ZodStringFormat.init(inst, def);
|
|
3842
5382
|
});
|
|
5383
|
+
/**
|
|
5384
|
+
* @deprecated CUID v1 is deprecated by its authors due to information leakage
|
|
5385
|
+
* (timestamps embedded in the id). Use {@link ZodCUID2} instead.
|
|
5386
|
+
* See https://github.com/paralleldrive/cuid.
|
|
5387
|
+
*/
|
|
3843
5388
|
const ZodCUID = /* @__PURE__ */ $constructor("ZodCUID", (inst, def) => {
|
|
3844
5389
|
$ZodCUID.init(inst, def);
|
|
3845
5390
|
ZodStringFormat.init(inst, def);
|
|
@@ -3896,28 +5441,68 @@ const ZodNumber = /* @__PURE__ */ $constructor("ZodNumber", (inst, def) => {
|
|
|
3896
5441
|
$ZodNumber.init(inst, def);
|
|
3897
5442
|
ZodType.init(inst, def);
|
|
3898
5443
|
inst._zod.processJSONSchema = (ctx, json, params) => numberProcessor(inst, ctx, json, params);
|
|
3899
|
-
inst.gt = (value, params) => inst.check(/* @__PURE__ */ _gt(value, params));
|
|
3900
|
-
inst.gte = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
|
|
3901
|
-
inst.min = (value, params) => inst.check(/* @__PURE__ */ _gte(value, params));
|
|
3902
|
-
inst.lt = (value, params) => inst.check(/* @__PURE__ */ _lt(value, params));
|
|
3903
|
-
inst.lte = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
|
|
3904
|
-
inst.max = (value, params) => inst.check(/* @__PURE__ */ _lte(value, params));
|
|
3905
|
-
inst.int = (params) => inst.check(int(params));
|
|
3906
|
-
inst.safe = (params) => inst.check(int(params));
|
|
3907
|
-
inst.positive = (params) => inst.check(/* @__PURE__ */ _gt(0, params));
|
|
3908
|
-
inst.nonnegative = (params) => inst.check(/* @__PURE__ */ _gte(0, params));
|
|
3909
|
-
inst.negative = (params) => inst.check(/* @__PURE__ */ _lt(0, params));
|
|
3910
|
-
inst.nonpositive = (params) => inst.check(/* @__PURE__ */ _lte(0, params));
|
|
3911
|
-
inst.multipleOf = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
3912
|
-
inst.step = (value, params) => inst.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
3913
|
-
inst.finite = () => inst;
|
|
3914
|
-
const bag = inst._zod.bag;
|
|
3915
|
-
inst.minValue = Math.max(bag.minimum ?? Number.NEGATIVE_INFINITY, bag.exclusiveMinimum ?? Number.NEGATIVE_INFINITY) ?? null;
|
|
3916
|
-
inst.maxValue = Math.min(bag.maximum ?? Number.POSITIVE_INFINITY, bag.exclusiveMaximum ?? Number.POSITIVE_INFINITY) ?? null;
|
|
3917
|
-
inst.isInt = (bag.format ?? "").includes("int") || Number.isSafeInteger(bag.multipleOf ?? .5);
|
|
3918
5444
|
inst.isFinite = true;
|
|
3919
|
-
|
|
3920
|
-
|
|
5445
|
+
}, /* @__PURE__ */ derived({
|
|
5446
|
+
minValue: (inst) => {
|
|
5447
|
+
const { minimum, exclusiveMinimum } = aggregateChecks(inst);
|
|
5448
|
+
return Math.max(minimum ?? Number.NEGATIVE_INFINITY, exclusiveMinimum ?? Number.NEGATIVE_INFINITY);
|
|
5449
|
+
},
|
|
5450
|
+
maxValue: (inst) => {
|
|
5451
|
+
const { maximum, exclusiveMaximum } = aggregateChecks(inst);
|
|
5452
|
+
return Math.min(maximum ?? Number.POSITIVE_INFINITY, exclusiveMaximum ?? Number.POSITIVE_INFINITY);
|
|
5453
|
+
},
|
|
5454
|
+
isInt: (inst) => {
|
|
5455
|
+
const { isInt, multipleOf } = aggregateChecks(inst);
|
|
5456
|
+
return !!isInt || !!multipleOf?.some(Number.isSafeInteger);
|
|
5457
|
+
},
|
|
5458
|
+
format: (inst) => aggregateChecks(inst).format ?? null
|
|
5459
|
+
}, {
|
|
5460
|
+
gt(value, params) {
|
|
5461
|
+
return this.check(/* @__PURE__ */ _gt(value, params));
|
|
5462
|
+
},
|
|
5463
|
+
gte(value, params) {
|
|
5464
|
+
return this.check(/* @__PURE__ */ _gte(value, params));
|
|
5465
|
+
},
|
|
5466
|
+
min(value, params) {
|
|
5467
|
+
return this.check(/* @__PURE__ */ _gte(value, params));
|
|
5468
|
+
},
|
|
5469
|
+
lt(value, params) {
|
|
5470
|
+
return this.check(/* @__PURE__ */ _lt(value, params));
|
|
5471
|
+
},
|
|
5472
|
+
lte(value, params) {
|
|
5473
|
+
return this.check(/* @__PURE__ */ _lte(value, params));
|
|
5474
|
+
},
|
|
5475
|
+
max(value, params) {
|
|
5476
|
+
return this.check(/* @__PURE__ */ _lte(value, params));
|
|
5477
|
+
},
|
|
5478
|
+
int(params) {
|
|
5479
|
+
return this.check(int(params));
|
|
5480
|
+
},
|
|
5481
|
+
safe(params) {
|
|
5482
|
+
return this.check(int(params));
|
|
5483
|
+
},
|
|
5484
|
+
positive(params) {
|
|
5485
|
+
return this.check(/* @__PURE__ */ _gt(0, params));
|
|
5486
|
+
},
|
|
5487
|
+
nonnegative(params) {
|
|
5488
|
+
return this.check(/* @__PURE__ */ _gte(0, params));
|
|
5489
|
+
},
|
|
5490
|
+
negative(params) {
|
|
5491
|
+
return this.check(/* @__PURE__ */ _lt(0, params));
|
|
5492
|
+
},
|
|
5493
|
+
nonpositive(params) {
|
|
5494
|
+
return this.check(/* @__PURE__ */ _lte(0, params));
|
|
5495
|
+
},
|
|
5496
|
+
multipleOf(value, params) {
|
|
5497
|
+
return this.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
5498
|
+
},
|
|
5499
|
+
step(value, params) {
|
|
5500
|
+
return this.check(/* @__PURE__ */ _multipleOf(value, params));
|
|
5501
|
+
},
|
|
5502
|
+
finite() {
|
|
5503
|
+
return this;
|
|
5504
|
+
}
|
|
5505
|
+
}));
|
|
3921
5506
|
function number(params) {
|
|
3922
5507
|
return /* @__PURE__ */ _number(ZodNumber, params);
|
|
3923
5508
|
}
|
|
@@ -3953,58 +5538,80 @@ function never(params) {
|
|
|
3953
5538
|
return /* @__PURE__ */ _never(ZodNever, params);
|
|
3954
5539
|
}
|
|
3955
5540
|
const ZodArray = /* @__PURE__ */ $constructor("ZodArray", (inst, def) => {
|
|
5541
|
+
_ensureDefaultMemoizer();
|
|
3956
5542
|
$ZodArray.init(inst, def);
|
|
3957
5543
|
ZodType.init(inst, def);
|
|
3958
5544
|
inst._zod.processJSONSchema = (ctx, json, params) => arrayProcessor(inst, ctx, json, params);
|
|
3959
5545
|
inst.element = def.element;
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
5546
|
+
}, {
|
|
5547
|
+
min(n, params) {
|
|
5548
|
+
return this.check(/* @__PURE__ */ _minLength(n, params));
|
|
5549
|
+
},
|
|
5550
|
+
nonempty(params) {
|
|
5551
|
+
return this.check(/* @__PURE__ */ _minLength(1, params));
|
|
5552
|
+
},
|
|
5553
|
+
max(n, params) {
|
|
5554
|
+
return this.check(/* @__PURE__ */ _maxLength(n, params));
|
|
5555
|
+
},
|
|
5556
|
+
length(n, params) {
|
|
5557
|
+
return this.check(/* @__PURE__ */ _length(n, params));
|
|
5558
|
+
},
|
|
5559
|
+
unwrap() {
|
|
5560
|
+
return this.element;
|
|
5561
|
+
}
|
|
3965
5562
|
});
|
|
3966
5563
|
function array(element, params) {
|
|
3967
5564
|
return /* @__PURE__ */ _array(ZodArray, element, params);
|
|
3968
5565
|
}
|
|
3969
5566
|
const ZodObject = /* @__PURE__ */ $constructor("ZodObject", (inst, def) => {
|
|
5567
|
+
_ensureDefaultMemoizer();
|
|
3970
5568
|
$ZodObjectJIT.init(inst, def);
|
|
3971
5569
|
ZodType.init(inst, def);
|
|
3972
5570
|
inst._zod.processJSONSchema = (ctx, json, params) => objectProcessor(inst, ctx, json, params);
|
|
3973
|
-
|
|
3974
|
-
|
|
3975
|
-
|
|
3976
|
-
|
|
3977
|
-
|
|
3978
|
-
|
|
3979
|
-
catchall
|
|
3980
|
-
}
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
catchall:
|
|
3992
|
-
}
|
|
3993
|
-
|
|
3994
|
-
|
|
3995
|
-
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
5571
|
+
installLazyProp(inst, "shape", (self) => self._zod.def.shape, false);
|
|
5572
|
+
}, {
|
|
5573
|
+
keyof() {
|
|
5574
|
+
return _enum(Object.keys(this._zod.def.shape));
|
|
5575
|
+
},
|
|
5576
|
+
catchall(catchall) {
|
|
5577
|
+
return this.clone(mergeDefs(this._zod.def, { catchall }));
|
|
5578
|
+
},
|
|
5579
|
+
passthrough() {
|
|
5580
|
+
return this.clone(mergeDefs(this._zod.def, { catchall: unknown() }));
|
|
5581
|
+
},
|
|
5582
|
+
loose() {
|
|
5583
|
+
return this.clone(mergeDefs(this._zod.def, { catchall: unknown() }));
|
|
5584
|
+
},
|
|
5585
|
+
strict() {
|
|
5586
|
+
return this.clone(mergeDefs(this._zod.def, { catchall: never() }));
|
|
5587
|
+
},
|
|
5588
|
+
strip() {
|
|
5589
|
+
return this.clone(mergeDefs(this._zod.def, { catchall: void 0 }));
|
|
5590
|
+
},
|
|
5591
|
+
extend(incoming) {
|
|
5592
|
+
return extend(this, incoming);
|
|
5593
|
+
},
|
|
5594
|
+
safeExtend(incoming) {
|
|
5595
|
+
return safeExtend(this, incoming);
|
|
5596
|
+
},
|
|
5597
|
+
merge(other) {
|
|
5598
|
+
return merge(this, other);
|
|
5599
|
+
},
|
|
5600
|
+
pick(mask) {
|
|
5601
|
+
return pick(this, mask);
|
|
5602
|
+
},
|
|
5603
|
+
omit(mask) {
|
|
5604
|
+
return omit(this, mask);
|
|
5605
|
+
},
|
|
5606
|
+
partial(...args) {
|
|
5607
|
+
return partial(ZodOptional, this, args[0]);
|
|
5608
|
+
},
|
|
5609
|
+
exactPartial(...args) {
|
|
5610
|
+
return partial(ZodExactOptional, this, args[0], "exactPartial");
|
|
5611
|
+
},
|
|
5612
|
+
required(...args) {
|
|
5613
|
+
return required(ZodNonOptional, this, args[0]);
|
|
5614
|
+
}
|
|
4008
5615
|
});
|
|
4009
5616
|
function object(shape, params) {
|
|
4010
5617
|
return new ZodObject({
|
|
@@ -4051,6 +5658,7 @@ function intersection(left, right) {
|
|
|
4051
5658
|
});
|
|
4052
5659
|
}
|
|
4053
5660
|
const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
5661
|
+
_ensureDefaultMemoizer();
|
|
4054
5662
|
$ZodRecord.init(inst, def);
|
|
4055
5663
|
ZodType.init(inst, def);
|
|
4056
5664
|
inst._zod.processJSONSchema = (ctx, json, params) => recordProcessor(inst, ctx, json, params);
|
|
@@ -4058,6 +5666,12 @@ const ZodRecord = /* @__PURE__ */ $constructor("ZodRecord", (inst, def) => {
|
|
|
4058
5666
|
inst.valueType = def.valueType;
|
|
4059
5667
|
});
|
|
4060
5668
|
function record(keyType, valueType, params) {
|
|
5669
|
+
if (!valueType || !valueType._zod) return new ZodRecord({
|
|
5670
|
+
type: "record",
|
|
5671
|
+
keyType: string(),
|
|
5672
|
+
valueType: keyType,
|
|
5673
|
+
...normalizeParams(valueType)
|
|
5674
|
+
});
|
|
4061
5675
|
return new ZodRecord({
|
|
4062
5676
|
type: "record",
|
|
4063
5677
|
keyType,
|
|
@@ -4070,7 +5684,7 @@ const ZodEnum = /* @__PURE__ */ $constructor("ZodEnum", (inst, def) => {
|
|
|
4070
5684
|
ZodType.init(inst, def);
|
|
4071
5685
|
inst._zod.processJSONSchema = (ctx, json, params) => enumProcessor(inst, ctx, json, params);
|
|
4072
5686
|
inst.enum = def.entries;
|
|
4073
|
-
inst.options =
|
|
5687
|
+
inst.options = [...inst._zod.values];
|
|
4074
5688
|
const keys = new Set(Object.keys(def.entries));
|
|
4075
5689
|
inst.extract = (values, params) => {
|
|
4076
5690
|
const newEntries = {};
|
|
@@ -4120,6 +5734,7 @@ function literal(value, params) {
|
|
|
4120
5734
|
});
|
|
4121
5735
|
}
|
|
4122
5736
|
const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) => {
|
|
5737
|
+
_ensureDefaultMemoizer();
|
|
4123
5738
|
$ZodTransform.init(inst, def);
|
|
4124
5739
|
ZodType.init(inst, def);
|
|
4125
5740
|
inst._zod.processJSONSchema = (ctx, json, params) => transformProcessor(inst, ctx, json, params);
|
|
@@ -4131,7 +5746,7 @@ const ZodTransform = /* @__PURE__ */ $constructor("ZodTransform", (inst, def) =>
|
|
|
4131
5746
|
const _issue = issue$1;
|
|
4132
5747
|
if (_issue.fatal) _issue.continue = false;
|
|
4133
5748
|
_issue.code ?? (_issue.code = "custom");
|
|
4134
|
-
|
|
5749
|
+
if (!("input" in _issue)) _issue.input = payload.value;
|
|
4135
5750
|
_issue.inst ?? (_issue.inst = inst);
|
|
4136
5751
|
payload.issues.push(issue(_issue));
|
|
4137
5752
|
}
|
|
@@ -4242,7 +5857,7 @@ function _catch(innerType, catchValue) {
|
|
|
4242
5857
|
return new ZodCatch({
|
|
4243
5858
|
type: "catch",
|
|
4244
5859
|
innerType,
|
|
4245
|
-
catchValue: typeof catchValue === "function" ? catchValue : ()
|
|
5860
|
+
catchValue: typeof catchValue === "function" ? catchValue : constantCatch(catchValue)
|
|
4246
5861
|
});
|
|
4247
5862
|
}
|
|
4248
5863
|
const ZodPipe = /* @__PURE__ */ $constructor("ZodPipe", (inst, def) => {
|
|
@@ -4279,8 +5894,8 @@ const ZodCustom = /* @__PURE__ */ $constructor("ZodCustom", (inst, def) => {
|
|
|
4279
5894
|
function refine(fn, _params = {}) {
|
|
4280
5895
|
return /* @__PURE__ */ _refine(ZodCustom, fn, _params);
|
|
4281
5896
|
}
|
|
4282
|
-
function superRefine(fn) {
|
|
4283
|
-
return /* @__PURE__ */ _superRefine(fn);
|
|
5897
|
+
function superRefine(fn, params) {
|
|
5898
|
+
return /* @__PURE__ */ _superRefine(fn, params);
|
|
4284
5899
|
}
|
|
4285
5900
|
const REGISTRY_URL = process.env.TANK_REGISTRY_URL || "https://www.tankpkg.dev";
|
|
4286
5901
|
const supportLevelSchema = _enum([
|