@signe/schema-to-zod 2.9.0 → 2.9.2
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/CHANGELOG.md +7 -0
- package/dist/index.js +96 -264
- package/dist/index.js.map +1 -1
- package/package.json +8 -3
package/dist/index.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// ../../node_modules/.pnpm/zod@3.23.8/node_modules/zod/lib/index.mjs
|
|
5
2
|
var util;
|
|
6
3
|
(function(util2) {
|
|
7
4
|
util2.assertEqual = (val) => val;
|
|
8
5
|
function assertIs(_arg) {
|
|
9
6
|
}
|
|
10
|
-
__name(assertIs, "assertIs");
|
|
11
7
|
util2.assertIs = assertIs;
|
|
12
8
|
function assertNever(_x) {
|
|
13
9
|
throw new Error();
|
|
14
10
|
}
|
|
15
|
-
__name(assertNever, "assertNever");
|
|
16
11
|
util2.assertNever = assertNever;
|
|
17
12
|
util2.arrayToEnum = (items) => {
|
|
18
13
|
const obj = {};
|
|
@@ -54,7 +49,6 @@ var util;
|
|
|
54
49
|
function joinValues(array, separator = " | ") {
|
|
55
50
|
return array.map((val) => typeof val === "string" ? `'${val}'` : val).join(separator);
|
|
56
51
|
}
|
|
57
|
-
__name(joinValues, "joinValues");
|
|
58
52
|
util2.joinValues = joinValues;
|
|
59
53
|
util2.jsonStringifyReplacer = (_, value) => {
|
|
60
54
|
if (typeof value === "bigint") {
|
|
@@ -95,7 +89,7 @@ var ZodParsedType = util.arrayToEnum([
|
|
|
95
89
|
"map",
|
|
96
90
|
"set"
|
|
97
91
|
]);
|
|
98
|
-
var getParsedType =
|
|
92
|
+
var getParsedType = (data) => {
|
|
99
93
|
const t = typeof data;
|
|
100
94
|
switch (t) {
|
|
101
95
|
case "undefined":
|
|
@@ -135,7 +129,7 @@ var getParsedType = /* @__PURE__ */ __name((data) => {
|
|
|
135
129
|
default:
|
|
136
130
|
return ZodParsedType.unknown;
|
|
137
131
|
}
|
|
138
|
-
}
|
|
132
|
+
};
|
|
139
133
|
var ZodIssueCode = util.arrayToEnum([
|
|
140
134
|
"invalid_type",
|
|
141
135
|
"invalid_literal",
|
|
@@ -154,14 +148,11 @@ var ZodIssueCode = util.arrayToEnum([
|
|
|
154
148
|
"not_multiple_of",
|
|
155
149
|
"not_finite"
|
|
156
150
|
]);
|
|
157
|
-
var quotelessJson =
|
|
151
|
+
var quotelessJson = (obj) => {
|
|
158
152
|
const json = JSON.stringify(obj, null, 2);
|
|
159
153
|
return json.replace(/"([^"]+)":/g, "$1:");
|
|
160
|
-
}
|
|
154
|
+
};
|
|
161
155
|
var ZodError = class _ZodError extends Error {
|
|
162
|
-
static {
|
|
163
|
-
__name(this, "ZodError");
|
|
164
|
-
}
|
|
165
156
|
constructor(issues) {
|
|
166
157
|
super();
|
|
167
158
|
this.issues = [];
|
|
@@ -188,7 +179,7 @@ var ZodError = class _ZodError extends Error {
|
|
|
188
179
|
return issue.message;
|
|
189
180
|
};
|
|
190
181
|
const fieldErrors = { _errors: [] };
|
|
191
|
-
const processError =
|
|
182
|
+
const processError = (error) => {
|
|
192
183
|
for (const issue of error.issues) {
|
|
193
184
|
if (issue.code === "invalid_union") {
|
|
194
185
|
issue.unionErrors.map(processError);
|
|
@@ -215,7 +206,7 @@ var ZodError = class _ZodError extends Error {
|
|
|
215
206
|
}
|
|
216
207
|
}
|
|
217
208
|
}
|
|
218
|
-
}
|
|
209
|
+
};
|
|
219
210
|
processError(this);
|
|
220
211
|
return fieldErrors;
|
|
221
212
|
}
|
|
@@ -254,7 +245,7 @@ ZodError.create = (issues) => {
|
|
|
254
245
|
const error = new ZodError(issues);
|
|
255
246
|
return error;
|
|
256
247
|
};
|
|
257
|
-
var errorMap =
|
|
248
|
+
var errorMap = (issue, _ctx) => {
|
|
258
249
|
let message;
|
|
259
250
|
switch (issue.code) {
|
|
260
251
|
case ZodIssueCode.invalid_type:
|
|
@@ -351,17 +342,15 @@ var errorMap = /* @__PURE__ */ __name((issue, _ctx) => {
|
|
|
351
342
|
util.assertNever(issue);
|
|
352
343
|
}
|
|
353
344
|
return { message };
|
|
354
|
-
}
|
|
345
|
+
};
|
|
355
346
|
var overrideErrorMap = errorMap;
|
|
356
347
|
function setErrorMap(map) {
|
|
357
348
|
overrideErrorMap = map;
|
|
358
349
|
}
|
|
359
|
-
__name(setErrorMap, "setErrorMap");
|
|
360
350
|
function getErrorMap() {
|
|
361
351
|
return overrideErrorMap;
|
|
362
352
|
}
|
|
363
|
-
|
|
364
|
-
var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
353
|
+
var makeIssue = (params) => {
|
|
365
354
|
const { data, path, errorMaps, issueData } = params;
|
|
366
355
|
const fullPath = [...path, ...issueData.path || []];
|
|
367
356
|
const fullIssue = {
|
|
@@ -385,7 +374,7 @@ var makeIssue = /* @__PURE__ */ __name((params) => {
|
|
|
385
374
|
path: fullPath,
|
|
386
375
|
message: errorMessage
|
|
387
376
|
};
|
|
388
|
-
}
|
|
377
|
+
};
|
|
389
378
|
var EMPTY_PATH = [];
|
|
390
379
|
function addIssueToContext(ctx, issueData) {
|
|
391
380
|
const overrideMap = getErrorMap();
|
|
@@ -403,11 +392,7 @@ function addIssueToContext(ctx, issueData) {
|
|
|
403
392
|
});
|
|
404
393
|
ctx.common.issues.push(issue);
|
|
405
394
|
}
|
|
406
|
-
__name(addIssueToContext, "addIssueToContext");
|
|
407
395
|
var ParseStatus = class _ParseStatus {
|
|
408
|
-
static {
|
|
409
|
-
__name(this, "ParseStatus");
|
|
410
|
-
}
|
|
411
396
|
constructor() {
|
|
412
397
|
this.value = "valid";
|
|
413
398
|
}
|
|
@@ -464,25 +449,23 @@ var ParseStatus = class _ParseStatus {
|
|
|
464
449
|
var INVALID = Object.freeze({
|
|
465
450
|
status: "aborted"
|
|
466
451
|
});
|
|
467
|
-
var DIRTY =
|
|
468
|
-
var OK =
|
|
469
|
-
var isAborted =
|
|
470
|
-
var isDirty =
|
|
471
|
-
var isValid =
|
|
472
|
-
var isAsync =
|
|
452
|
+
var DIRTY = (value) => ({ status: "dirty", value });
|
|
453
|
+
var OK = (value) => ({ status: "valid", value });
|
|
454
|
+
var isAborted = (x) => x.status === "aborted";
|
|
455
|
+
var isDirty = (x) => x.status === "dirty";
|
|
456
|
+
var isValid = (x) => x.status === "valid";
|
|
457
|
+
var isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
|
|
473
458
|
function __classPrivateFieldGet(receiver, state, kind, f) {
|
|
474
459
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
475
460
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
476
461
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
477
462
|
}
|
|
478
|
-
__name(__classPrivateFieldGet, "__classPrivateFieldGet");
|
|
479
463
|
function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
480
464
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
481
465
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
482
466
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
483
467
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
484
468
|
}
|
|
485
|
-
__name(__classPrivateFieldSet, "__classPrivateFieldSet");
|
|
486
469
|
var errorUtil;
|
|
487
470
|
(function(errorUtil2) {
|
|
488
471
|
errorUtil2.errToObj = (message) => typeof message === "string" ? { message } : message || {};
|
|
@@ -491,9 +474,6 @@ var errorUtil;
|
|
|
491
474
|
var _ZodEnum_cache;
|
|
492
475
|
var _ZodNativeEnum_cache;
|
|
493
476
|
var ParseInputLazyPath = class {
|
|
494
|
-
static {
|
|
495
|
-
__name(this, "ParseInputLazyPath");
|
|
496
|
-
}
|
|
497
477
|
constructor(parent, value, path, key) {
|
|
498
478
|
this._cachedPath = [];
|
|
499
479
|
this.parent = parent;
|
|
@@ -512,7 +492,7 @@ var ParseInputLazyPath = class {
|
|
|
512
492
|
return this._cachedPath;
|
|
513
493
|
}
|
|
514
494
|
};
|
|
515
|
-
var handleResult =
|
|
495
|
+
var handleResult = (ctx, result) => {
|
|
516
496
|
if (isValid(result)) {
|
|
517
497
|
return { success: true, data: result.value };
|
|
518
498
|
} else {
|
|
@@ -530,7 +510,7 @@ var handleResult = /* @__PURE__ */ __name((ctx, result) => {
|
|
|
530
510
|
}
|
|
531
511
|
};
|
|
532
512
|
}
|
|
533
|
-
}
|
|
513
|
+
};
|
|
534
514
|
function processCreateParams(params) {
|
|
535
515
|
if (!params)
|
|
536
516
|
return {};
|
|
@@ -540,7 +520,7 @@ function processCreateParams(params) {
|
|
|
540
520
|
}
|
|
541
521
|
if (errorMap2)
|
|
542
522
|
return { errorMap: errorMap2, description };
|
|
543
|
-
const customMap =
|
|
523
|
+
const customMap = (iss, ctx) => {
|
|
544
524
|
var _a, _b;
|
|
545
525
|
const { message } = params;
|
|
546
526
|
if (iss.code === "invalid_enum_value") {
|
|
@@ -552,14 +532,10 @@ function processCreateParams(params) {
|
|
|
552
532
|
if (iss.code !== "invalid_type")
|
|
553
533
|
return { message: ctx.defaultError };
|
|
554
534
|
return { message: (_b = message !== null && message !== void 0 ? message : invalid_type_error) !== null && _b !== void 0 ? _b : ctx.defaultError };
|
|
555
|
-
}
|
|
535
|
+
};
|
|
556
536
|
return { errorMap: customMap, description };
|
|
557
537
|
}
|
|
558
|
-
__name(processCreateParams, "processCreateParams");
|
|
559
538
|
var ZodType = class {
|
|
560
|
-
static {
|
|
561
|
-
__name(this, "ZodType");
|
|
562
|
-
}
|
|
563
539
|
constructor(def) {
|
|
564
540
|
this.spa = this.safeParseAsync;
|
|
565
541
|
this._def = def;
|
|
@@ -675,7 +651,7 @@ var ZodType = class {
|
|
|
675
651
|
return handleResult(ctx, result);
|
|
676
652
|
}
|
|
677
653
|
refine(check, message) {
|
|
678
|
-
const getIssueProperties =
|
|
654
|
+
const getIssueProperties = (val) => {
|
|
679
655
|
if (typeof message === "string" || typeof message === "undefined") {
|
|
680
656
|
return { message };
|
|
681
657
|
} else if (typeof message === "function") {
|
|
@@ -683,13 +659,13 @@ var ZodType = class {
|
|
|
683
659
|
} else {
|
|
684
660
|
return message;
|
|
685
661
|
}
|
|
686
|
-
}
|
|
662
|
+
};
|
|
687
663
|
return this._refinement((val, ctx) => {
|
|
688
664
|
const result = check(val);
|
|
689
|
-
const setError =
|
|
665
|
+
const setError = () => ctx.addIssue({
|
|
690
666
|
code: ZodIssueCode.custom,
|
|
691
667
|
...getIssueProperties(val)
|
|
692
|
-
})
|
|
668
|
+
});
|
|
693
669
|
if (typeof Promise !== "undefined" && result instanceof Promise) {
|
|
694
670
|
return result.then((data) => {
|
|
695
671
|
if (!data) {
|
|
@@ -825,11 +801,9 @@ function timeRegexSource(args) {
|
|
|
825
801
|
}
|
|
826
802
|
return regex;
|
|
827
803
|
}
|
|
828
|
-
__name(timeRegexSource, "timeRegexSource");
|
|
829
804
|
function timeRegex(args) {
|
|
830
805
|
return new RegExp(`^${timeRegexSource(args)}$`);
|
|
831
806
|
}
|
|
832
|
-
__name(timeRegex, "timeRegex");
|
|
833
807
|
function datetimeRegex(args) {
|
|
834
808
|
let regex = `${dateRegexSource}T${timeRegexSource(args)}`;
|
|
835
809
|
const opts = [];
|
|
@@ -839,7 +813,6 @@ function datetimeRegex(args) {
|
|
|
839
813
|
regex = `${regex}(${opts.join("|")})`;
|
|
840
814
|
return new RegExp(`^${regex}$`);
|
|
841
815
|
}
|
|
842
|
-
__name(datetimeRegex, "datetimeRegex");
|
|
843
816
|
function isValidIP(ip, version) {
|
|
844
817
|
if ((version === "v4" || !version) && ipv4Regex.test(ip)) {
|
|
845
818
|
return true;
|
|
@@ -849,11 +822,7 @@ function isValidIP(ip, version) {
|
|
|
849
822
|
}
|
|
850
823
|
return false;
|
|
851
824
|
}
|
|
852
|
-
__name(isValidIP, "isValidIP");
|
|
853
825
|
var ZodString = class _ZodString extends ZodType {
|
|
854
|
-
static {
|
|
855
|
-
__name(this, "ZodString");
|
|
856
|
-
}
|
|
857
826
|
_parse(input) {
|
|
858
827
|
if (this._def.coerce) {
|
|
859
828
|
input.data = String(input.data);
|
|
@@ -1362,11 +1331,7 @@ function floatSafeRemainder(val, step) {
|
|
|
1362
1331
|
const stepInt = parseInt(step.toFixed(decCount).replace(".", ""));
|
|
1363
1332
|
return valInt % stepInt / Math.pow(10, decCount);
|
|
1364
1333
|
}
|
|
1365
|
-
__name(floatSafeRemainder, "floatSafeRemainder");
|
|
1366
1334
|
var ZodNumber = class _ZodNumber extends ZodType {
|
|
1367
|
-
static {
|
|
1368
|
-
__name(this, "ZodNumber");
|
|
1369
|
-
}
|
|
1370
1335
|
constructor() {
|
|
1371
1336
|
super(...arguments);
|
|
1372
1337
|
this.min = this.gte;
|
|
@@ -1598,9 +1563,6 @@ ZodNumber.create = (params) => {
|
|
|
1598
1563
|
});
|
|
1599
1564
|
};
|
|
1600
1565
|
var ZodBigInt = class _ZodBigInt extends ZodType {
|
|
1601
|
-
static {
|
|
1602
|
-
__name(this, "ZodBigInt");
|
|
1603
|
-
}
|
|
1604
1566
|
constructor() {
|
|
1605
1567
|
super(...arguments);
|
|
1606
1568
|
this.min = this.gte;
|
|
@@ -1767,9 +1729,6 @@ ZodBigInt.create = (params) => {
|
|
|
1767
1729
|
});
|
|
1768
1730
|
};
|
|
1769
1731
|
var ZodBoolean = class extends ZodType {
|
|
1770
|
-
static {
|
|
1771
|
-
__name(this, "ZodBoolean");
|
|
1772
|
-
}
|
|
1773
1732
|
_parse(input) {
|
|
1774
1733
|
if (this._def.coerce) {
|
|
1775
1734
|
input.data = Boolean(input.data);
|
|
@@ -1795,9 +1754,6 @@ ZodBoolean.create = (params) => {
|
|
|
1795
1754
|
});
|
|
1796
1755
|
};
|
|
1797
1756
|
var ZodDate = class _ZodDate extends ZodType {
|
|
1798
|
-
static {
|
|
1799
|
-
__name(this, "ZodDate");
|
|
1800
|
-
}
|
|
1801
1757
|
_parse(input) {
|
|
1802
1758
|
if (this._def.coerce) {
|
|
1803
1759
|
input.data = new Date(input.data);
|
|
@@ -1907,9 +1863,6 @@ ZodDate.create = (params) => {
|
|
|
1907
1863
|
});
|
|
1908
1864
|
};
|
|
1909
1865
|
var ZodSymbol = class extends ZodType {
|
|
1910
|
-
static {
|
|
1911
|
-
__name(this, "ZodSymbol");
|
|
1912
|
-
}
|
|
1913
1866
|
_parse(input) {
|
|
1914
1867
|
const parsedType = this._getType(input);
|
|
1915
1868
|
if (parsedType !== ZodParsedType.symbol) {
|
|
@@ -1931,9 +1884,6 @@ ZodSymbol.create = (params) => {
|
|
|
1931
1884
|
});
|
|
1932
1885
|
};
|
|
1933
1886
|
var ZodUndefined = class extends ZodType {
|
|
1934
|
-
static {
|
|
1935
|
-
__name(this, "ZodUndefined");
|
|
1936
|
-
}
|
|
1937
1887
|
_parse(input) {
|
|
1938
1888
|
const parsedType = this._getType(input);
|
|
1939
1889
|
if (parsedType !== ZodParsedType.undefined) {
|
|
@@ -1955,9 +1905,6 @@ ZodUndefined.create = (params) => {
|
|
|
1955
1905
|
});
|
|
1956
1906
|
};
|
|
1957
1907
|
var ZodNull = class extends ZodType {
|
|
1958
|
-
static {
|
|
1959
|
-
__name(this, "ZodNull");
|
|
1960
|
-
}
|
|
1961
1908
|
_parse(input) {
|
|
1962
1909
|
const parsedType = this._getType(input);
|
|
1963
1910
|
if (parsedType !== ZodParsedType.null) {
|
|
@@ -1979,9 +1926,6 @@ ZodNull.create = (params) => {
|
|
|
1979
1926
|
});
|
|
1980
1927
|
};
|
|
1981
1928
|
var ZodAny = class extends ZodType {
|
|
1982
|
-
static {
|
|
1983
|
-
__name(this, "ZodAny");
|
|
1984
|
-
}
|
|
1985
1929
|
constructor() {
|
|
1986
1930
|
super(...arguments);
|
|
1987
1931
|
this._any = true;
|
|
@@ -1997,9 +1941,6 @@ ZodAny.create = (params) => {
|
|
|
1997
1941
|
});
|
|
1998
1942
|
};
|
|
1999
1943
|
var ZodUnknown = class extends ZodType {
|
|
2000
|
-
static {
|
|
2001
|
-
__name(this, "ZodUnknown");
|
|
2002
|
-
}
|
|
2003
1944
|
constructor() {
|
|
2004
1945
|
super(...arguments);
|
|
2005
1946
|
this._unknown = true;
|
|
@@ -2015,9 +1956,6 @@ ZodUnknown.create = (params) => {
|
|
|
2015
1956
|
});
|
|
2016
1957
|
};
|
|
2017
1958
|
var ZodNever = class extends ZodType {
|
|
2018
|
-
static {
|
|
2019
|
-
__name(this, "ZodNever");
|
|
2020
|
-
}
|
|
2021
1959
|
_parse(input) {
|
|
2022
1960
|
const ctx = this._getOrReturnCtx(input);
|
|
2023
1961
|
addIssueToContext(ctx, {
|
|
@@ -2035,9 +1973,6 @@ ZodNever.create = (params) => {
|
|
|
2035
1973
|
});
|
|
2036
1974
|
};
|
|
2037
1975
|
var ZodVoid = class extends ZodType {
|
|
2038
|
-
static {
|
|
2039
|
-
__name(this, "ZodVoid");
|
|
2040
|
-
}
|
|
2041
1976
|
_parse(input) {
|
|
2042
1977
|
const parsedType = this._getType(input);
|
|
2043
1978
|
if (parsedType !== ZodParsedType.undefined) {
|
|
@@ -2059,9 +1994,6 @@ ZodVoid.create = (params) => {
|
|
|
2059
1994
|
});
|
|
2060
1995
|
};
|
|
2061
1996
|
var ZodArray = class _ZodArray extends ZodType {
|
|
2062
|
-
static {
|
|
2063
|
-
__name(this, "ZodArray");
|
|
2064
|
-
}
|
|
2065
1997
|
_parse(input) {
|
|
2066
1998
|
const { ctx, status } = this._processInputParams(input);
|
|
2067
1999
|
const def = this._def;
|
|
@@ -2171,7 +2103,7 @@ function deepPartialify(schema) {
|
|
|
2171
2103
|
}
|
|
2172
2104
|
return new ZodObject({
|
|
2173
2105
|
...schema._def,
|
|
2174
|
-
shape:
|
|
2106
|
+
shape: () => newShape
|
|
2175
2107
|
});
|
|
2176
2108
|
} else if (schema instanceof ZodArray) {
|
|
2177
2109
|
return new ZodArray({
|
|
@@ -2188,11 +2120,7 @@ function deepPartialify(schema) {
|
|
|
2188
2120
|
return schema;
|
|
2189
2121
|
}
|
|
2190
2122
|
}
|
|
2191
|
-
__name(deepPartialify, "deepPartialify");
|
|
2192
2123
|
var ZodObject = class _ZodObject extends ZodType {
|
|
2193
|
-
static {
|
|
2194
|
-
__name(this, "ZodObject");
|
|
2195
|
-
}
|
|
2196
2124
|
constructor() {
|
|
2197
2125
|
super(...arguments);
|
|
2198
2126
|
this._cached = null;
|
|
@@ -2301,7 +2229,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2301
2229
|
...this._def,
|
|
2302
2230
|
unknownKeys: "strict",
|
|
2303
2231
|
...message !== void 0 ? {
|
|
2304
|
-
errorMap:
|
|
2232
|
+
errorMap: (issue, ctx) => {
|
|
2305
2233
|
var _a, _b, _c, _d;
|
|
2306
2234
|
const defaultError = (_c = (_b = (_a = this._def).errorMap) === null || _b === void 0 ? void 0 : _b.call(_a, issue, ctx).message) !== null && _c !== void 0 ? _c : ctx.defaultError;
|
|
2307
2235
|
if (issue.code === "unrecognized_keys")
|
|
@@ -2311,7 +2239,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2311
2239
|
return {
|
|
2312
2240
|
message: defaultError
|
|
2313
2241
|
};
|
|
2314
|
-
}
|
|
2242
|
+
}
|
|
2315
2243
|
} : {}
|
|
2316
2244
|
});
|
|
2317
2245
|
}
|
|
@@ -2347,10 +2275,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2347
2275
|
extend(augmentation) {
|
|
2348
2276
|
return new _ZodObject({
|
|
2349
2277
|
...this._def,
|
|
2350
|
-
shape:
|
|
2278
|
+
shape: () => ({
|
|
2351
2279
|
...this._def.shape(),
|
|
2352
2280
|
...augmentation
|
|
2353
|
-
})
|
|
2281
|
+
})
|
|
2354
2282
|
});
|
|
2355
2283
|
}
|
|
2356
2284
|
/**
|
|
@@ -2362,10 +2290,10 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2362
2290
|
const merged = new _ZodObject({
|
|
2363
2291
|
unknownKeys: merging._def.unknownKeys,
|
|
2364
2292
|
catchall: merging._def.catchall,
|
|
2365
|
-
shape:
|
|
2293
|
+
shape: () => ({
|
|
2366
2294
|
...this._def.shape(),
|
|
2367
2295
|
...merging._def.shape()
|
|
2368
|
-
}),
|
|
2296
|
+
}),
|
|
2369
2297
|
typeName: ZodFirstPartyTypeKind.ZodObject
|
|
2370
2298
|
});
|
|
2371
2299
|
return merged;
|
|
@@ -2444,7 +2372,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2444
2372
|
});
|
|
2445
2373
|
return new _ZodObject({
|
|
2446
2374
|
...this._def,
|
|
2447
|
-
shape:
|
|
2375
|
+
shape: () => shape
|
|
2448
2376
|
});
|
|
2449
2377
|
}
|
|
2450
2378
|
omit(mask) {
|
|
@@ -2456,7 +2384,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2456
2384
|
});
|
|
2457
2385
|
return new _ZodObject({
|
|
2458
2386
|
...this._def,
|
|
2459
|
-
shape:
|
|
2387
|
+
shape: () => shape
|
|
2460
2388
|
});
|
|
2461
2389
|
}
|
|
2462
2390
|
/**
|
|
@@ -2477,7 +2405,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2477
2405
|
});
|
|
2478
2406
|
return new _ZodObject({
|
|
2479
2407
|
...this._def,
|
|
2480
|
-
shape:
|
|
2408
|
+
shape: () => newShape
|
|
2481
2409
|
});
|
|
2482
2410
|
}
|
|
2483
2411
|
required(mask) {
|
|
@@ -2496,7 +2424,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2496
2424
|
});
|
|
2497
2425
|
return new _ZodObject({
|
|
2498
2426
|
...this._def,
|
|
2499
|
-
shape:
|
|
2427
|
+
shape: () => newShape
|
|
2500
2428
|
});
|
|
2501
2429
|
}
|
|
2502
2430
|
keyof() {
|
|
@@ -2505,7 +2433,7 @@ var ZodObject = class _ZodObject extends ZodType {
|
|
|
2505
2433
|
};
|
|
2506
2434
|
ZodObject.create = (shape, params) => {
|
|
2507
2435
|
return new ZodObject({
|
|
2508
|
-
shape:
|
|
2436
|
+
shape: () => shape,
|
|
2509
2437
|
unknownKeys: "strip",
|
|
2510
2438
|
catchall: ZodNever.create(),
|
|
2511
2439
|
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
@@ -2514,7 +2442,7 @@ ZodObject.create = (shape, params) => {
|
|
|
2514
2442
|
};
|
|
2515
2443
|
ZodObject.strictCreate = (shape, params) => {
|
|
2516
2444
|
return new ZodObject({
|
|
2517
|
-
shape:
|
|
2445
|
+
shape: () => shape,
|
|
2518
2446
|
unknownKeys: "strict",
|
|
2519
2447
|
catchall: ZodNever.create(),
|
|
2520
2448
|
typeName: ZodFirstPartyTypeKind.ZodObject,
|
|
@@ -2531,9 +2459,6 @@ ZodObject.lazycreate = (shape, params) => {
|
|
|
2531
2459
|
});
|
|
2532
2460
|
};
|
|
2533
2461
|
var ZodUnion = class extends ZodType {
|
|
2534
|
-
static {
|
|
2535
|
-
__name(this, "ZodUnion");
|
|
2536
|
-
}
|
|
2537
2462
|
_parse(input) {
|
|
2538
2463
|
const { ctx } = this._processInputParams(input);
|
|
2539
2464
|
const options = this._def.options;
|
|
@@ -2556,7 +2481,6 @@ var ZodUnion = class extends ZodType {
|
|
|
2556
2481
|
});
|
|
2557
2482
|
return INVALID;
|
|
2558
2483
|
}
|
|
2559
|
-
__name(handleResults, "handleResults");
|
|
2560
2484
|
if (ctx.common.async) {
|
|
2561
2485
|
return Promise.all(options.map(async (option) => {
|
|
2562
2486
|
const childCtx = {
|
|
@@ -2625,7 +2549,7 @@ ZodUnion.create = (types, params) => {
|
|
|
2625
2549
|
...processCreateParams(params)
|
|
2626
2550
|
});
|
|
2627
2551
|
};
|
|
2628
|
-
var getDiscriminator =
|
|
2552
|
+
var getDiscriminator = (type) => {
|
|
2629
2553
|
if (type instanceof ZodLazy) {
|
|
2630
2554
|
return getDiscriminator(type.schema);
|
|
2631
2555
|
} else if (type instanceof ZodEffects) {
|
|
@@ -2655,11 +2579,8 @@ var getDiscriminator = /* @__PURE__ */ __name((type) => {
|
|
|
2655
2579
|
} else {
|
|
2656
2580
|
return [];
|
|
2657
2581
|
}
|
|
2658
|
-
}
|
|
2582
|
+
};
|
|
2659
2583
|
var ZodDiscriminatedUnion = class _ZodDiscriminatedUnion extends ZodType {
|
|
2660
|
-
static {
|
|
2661
|
-
__name(this, "ZodDiscriminatedUnion");
|
|
2662
|
-
}
|
|
2663
2584
|
_parse(input) {
|
|
2664
2585
|
const { ctx } = this._processInputParams(input);
|
|
2665
2586
|
if (ctx.parsedType !== ZodParsedType.object) {
|
|
@@ -2773,14 +2694,10 @@ function mergeValues(a, b) {
|
|
|
2773
2694
|
return { valid: false };
|
|
2774
2695
|
}
|
|
2775
2696
|
}
|
|
2776
|
-
__name(mergeValues, "mergeValues");
|
|
2777
2697
|
var ZodIntersection = class extends ZodType {
|
|
2778
|
-
static {
|
|
2779
|
-
__name(this, "ZodIntersection");
|
|
2780
|
-
}
|
|
2781
2698
|
_parse(input) {
|
|
2782
2699
|
const { status, ctx } = this._processInputParams(input);
|
|
2783
|
-
const handleParsed =
|
|
2700
|
+
const handleParsed = (parsedLeft, parsedRight) => {
|
|
2784
2701
|
if (isAborted(parsedLeft) || isAborted(parsedRight)) {
|
|
2785
2702
|
return INVALID;
|
|
2786
2703
|
}
|
|
@@ -2795,7 +2712,7 @@ var ZodIntersection = class extends ZodType {
|
|
|
2795
2712
|
status.dirty();
|
|
2796
2713
|
}
|
|
2797
2714
|
return { status: status.value, value: merged.data };
|
|
2798
|
-
}
|
|
2715
|
+
};
|
|
2799
2716
|
if (ctx.common.async) {
|
|
2800
2717
|
return Promise.all([
|
|
2801
2718
|
this._def.left._parseAsync({
|
|
@@ -2831,9 +2748,6 @@ ZodIntersection.create = (left, right, params) => {
|
|
|
2831
2748
|
});
|
|
2832
2749
|
};
|
|
2833
2750
|
var ZodTuple = class _ZodTuple extends ZodType {
|
|
2834
|
-
static {
|
|
2835
|
-
__name(this, "ZodTuple");
|
|
2836
|
-
}
|
|
2837
2751
|
_parse(input) {
|
|
2838
2752
|
const { status, ctx } = this._processInputParams(input);
|
|
2839
2753
|
if (ctx.parsedType !== ZodParsedType.array) {
|
|
@@ -2901,9 +2815,6 @@ ZodTuple.create = (schemas, params) => {
|
|
|
2901
2815
|
});
|
|
2902
2816
|
};
|
|
2903
2817
|
var ZodRecord = class _ZodRecord extends ZodType {
|
|
2904
|
-
static {
|
|
2905
|
-
__name(this, "ZodRecord");
|
|
2906
|
-
}
|
|
2907
2818
|
get keySchema() {
|
|
2908
2819
|
return this._def.keyType;
|
|
2909
2820
|
}
|
|
@@ -2957,9 +2868,6 @@ var ZodRecord = class _ZodRecord extends ZodType {
|
|
|
2957
2868
|
}
|
|
2958
2869
|
};
|
|
2959
2870
|
var ZodMap = class extends ZodType {
|
|
2960
|
-
static {
|
|
2961
|
-
__name(this, "ZodMap");
|
|
2962
|
-
}
|
|
2963
2871
|
get keySchema() {
|
|
2964
2872
|
return this._def.keyType;
|
|
2965
2873
|
}
|
|
@@ -3026,9 +2934,6 @@ ZodMap.create = (keyType, valueType, params) => {
|
|
|
3026
2934
|
});
|
|
3027
2935
|
};
|
|
3028
2936
|
var ZodSet = class _ZodSet extends ZodType {
|
|
3029
|
-
static {
|
|
3030
|
-
__name(this, "ZodSet");
|
|
3031
|
-
}
|
|
3032
2937
|
_parse(input) {
|
|
3033
2938
|
const { status, ctx } = this._processInputParams(input);
|
|
3034
2939
|
if (ctx.parsedType !== ZodParsedType.set) {
|
|
@@ -3078,7 +2983,6 @@ var ZodSet = class _ZodSet extends ZodType {
|
|
|
3078
2983
|
}
|
|
3079
2984
|
return { status: status.value, value: parsedSet };
|
|
3080
2985
|
}
|
|
3081
|
-
__name(finalizeSet, "finalizeSet");
|
|
3082
2986
|
const elements = [...ctx.data.values()].map((item, i) => valueType._parse(new ParseInputLazyPath(ctx, item, ctx.path, i)));
|
|
3083
2987
|
if (ctx.common.async) {
|
|
3084
2988
|
return Promise.all(elements).then((elements2) => finalizeSet(elements2));
|
|
@@ -3115,9 +3019,6 @@ ZodSet.create = (valueType, params) => {
|
|
|
3115
3019
|
});
|
|
3116
3020
|
};
|
|
3117
3021
|
var ZodFunction = class _ZodFunction extends ZodType {
|
|
3118
|
-
static {
|
|
3119
|
-
__name(this, "ZodFunction");
|
|
3120
|
-
}
|
|
3121
3022
|
constructor() {
|
|
3122
3023
|
super(...arguments);
|
|
3123
3024
|
this.validate = this.implement;
|
|
@@ -3148,7 +3049,6 @@ var ZodFunction = class _ZodFunction extends ZodType {
|
|
|
3148
3049
|
}
|
|
3149
3050
|
});
|
|
3150
3051
|
}
|
|
3151
|
-
__name(makeArgsIssue, "makeArgsIssue");
|
|
3152
3052
|
function makeReturnsIssue(returns, error) {
|
|
3153
3053
|
return makeIssue({
|
|
3154
3054
|
data: returns,
|
|
@@ -3165,7 +3065,6 @@ var ZodFunction = class _ZodFunction extends ZodType {
|
|
|
3165
3065
|
}
|
|
3166
3066
|
});
|
|
3167
3067
|
}
|
|
3168
|
-
__name(makeReturnsIssue, "makeReturnsIssue");
|
|
3169
3068
|
const params = { errorMap: ctx.common.contextualErrorMap };
|
|
3170
3069
|
const fn = ctx.data;
|
|
3171
3070
|
if (this._def.returns instanceof ZodPromise) {
|
|
@@ -3235,9 +3134,6 @@ var ZodFunction = class _ZodFunction extends ZodType {
|
|
|
3235
3134
|
}
|
|
3236
3135
|
};
|
|
3237
3136
|
var ZodLazy = class extends ZodType {
|
|
3238
|
-
static {
|
|
3239
|
-
__name(this, "ZodLazy");
|
|
3240
|
-
}
|
|
3241
3137
|
get schema() {
|
|
3242
3138
|
return this._def.getter();
|
|
3243
3139
|
}
|
|
@@ -3255,9 +3151,6 @@ ZodLazy.create = (getter, params) => {
|
|
|
3255
3151
|
});
|
|
3256
3152
|
};
|
|
3257
3153
|
var ZodLiteral = class extends ZodType {
|
|
3258
|
-
static {
|
|
3259
|
-
__name(this, "ZodLiteral");
|
|
3260
|
-
}
|
|
3261
3154
|
_parse(input) {
|
|
3262
3155
|
if (input.data !== this._def.value) {
|
|
3263
3156
|
const ctx = this._getOrReturnCtx(input);
|
|
@@ -3288,11 +3181,7 @@ function createZodEnum(values, params) {
|
|
|
3288
3181
|
...processCreateParams(params)
|
|
3289
3182
|
});
|
|
3290
3183
|
}
|
|
3291
|
-
__name(createZodEnum, "createZodEnum");
|
|
3292
3184
|
var ZodEnum = class _ZodEnum extends ZodType {
|
|
3293
|
-
static {
|
|
3294
|
-
__name(this, "ZodEnum");
|
|
3295
|
-
}
|
|
3296
3185
|
constructor() {
|
|
3297
3186
|
super(...arguments);
|
|
3298
3187
|
_ZodEnum_cache.set(this, void 0);
|
|
@@ -3363,9 +3252,6 @@ var ZodEnum = class _ZodEnum extends ZodType {
|
|
|
3363
3252
|
_ZodEnum_cache = /* @__PURE__ */ new WeakMap();
|
|
3364
3253
|
ZodEnum.create = createZodEnum;
|
|
3365
3254
|
var ZodNativeEnum = class extends ZodType {
|
|
3366
|
-
static {
|
|
3367
|
-
__name(this, "ZodNativeEnum");
|
|
3368
|
-
}
|
|
3369
3255
|
constructor() {
|
|
3370
3256
|
super(...arguments);
|
|
3371
3257
|
_ZodNativeEnum_cache.set(this, void 0);
|
|
@@ -3409,9 +3295,6 @@ ZodNativeEnum.create = (values, params) => {
|
|
|
3409
3295
|
});
|
|
3410
3296
|
};
|
|
3411
3297
|
var ZodPromise = class extends ZodType {
|
|
3412
|
-
static {
|
|
3413
|
-
__name(this, "ZodPromise");
|
|
3414
|
-
}
|
|
3415
3298
|
unwrap() {
|
|
3416
3299
|
return this._def.type;
|
|
3417
3300
|
}
|
|
@@ -3442,9 +3325,6 @@ ZodPromise.create = (schema, params) => {
|
|
|
3442
3325
|
});
|
|
3443
3326
|
};
|
|
3444
3327
|
var ZodEffects = class extends ZodType {
|
|
3445
|
-
static {
|
|
3446
|
-
__name(this, "ZodEffects");
|
|
3447
|
-
}
|
|
3448
3328
|
innerType() {
|
|
3449
3329
|
return this._def.schema;
|
|
3450
3330
|
}
|
|
@@ -3455,14 +3335,14 @@ var ZodEffects = class extends ZodType {
|
|
|
3455
3335
|
const { status, ctx } = this._processInputParams(input);
|
|
3456
3336
|
const effect = this._def.effect || null;
|
|
3457
3337
|
const checkCtx = {
|
|
3458
|
-
addIssue:
|
|
3338
|
+
addIssue: (arg) => {
|
|
3459
3339
|
addIssueToContext(ctx, arg);
|
|
3460
3340
|
if (arg.fatal) {
|
|
3461
3341
|
status.abort();
|
|
3462
3342
|
} else {
|
|
3463
3343
|
status.dirty();
|
|
3464
3344
|
}
|
|
3465
|
-
},
|
|
3345
|
+
},
|
|
3466
3346
|
get path() {
|
|
3467
3347
|
return ctx.path;
|
|
3468
3348
|
}
|
|
@@ -3505,7 +3385,7 @@ var ZodEffects = class extends ZodType {
|
|
|
3505
3385
|
}
|
|
3506
3386
|
}
|
|
3507
3387
|
if (effect.type === "refinement") {
|
|
3508
|
-
const executeRefinement =
|
|
3388
|
+
const executeRefinement = (acc) => {
|
|
3509
3389
|
const result = effect.refinement(acc, checkCtx);
|
|
3510
3390
|
if (ctx.common.async) {
|
|
3511
3391
|
return Promise.resolve(result);
|
|
@@ -3514,7 +3394,7 @@ var ZodEffects = class extends ZodType {
|
|
|
3514
3394
|
throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");
|
|
3515
3395
|
}
|
|
3516
3396
|
return acc;
|
|
3517
|
-
}
|
|
3397
|
+
};
|
|
3518
3398
|
if (ctx.common.async === false) {
|
|
3519
3399
|
const inner = this._def.schema._parseSync({
|
|
3520
3400
|
data: ctx.data,
|
|
@@ -3581,9 +3461,6 @@ ZodEffects.createWithPreprocess = (preprocess, schema, params) => {
|
|
|
3581
3461
|
});
|
|
3582
3462
|
};
|
|
3583
3463
|
var ZodOptional = class extends ZodType {
|
|
3584
|
-
static {
|
|
3585
|
-
__name(this, "ZodOptional");
|
|
3586
|
-
}
|
|
3587
3464
|
_parse(input) {
|
|
3588
3465
|
const parsedType = this._getType(input);
|
|
3589
3466
|
if (parsedType === ZodParsedType.undefined) {
|
|
@@ -3603,9 +3480,6 @@ ZodOptional.create = (type, params) => {
|
|
|
3603
3480
|
});
|
|
3604
3481
|
};
|
|
3605
3482
|
var ZodNullable = class extends ZodType {
|
|
3606
|
-
static {
|
|
3607
|
-
__name(this, "ZodNullable");
|
|
3608
|
-
}
|
|
3609
3483
|
_parse(input) {
|
|
3610
3484
|
const parsedType = this._getType(input);
|
|
3611
3485
|
if (parsedType === ZodParsedType.null) {
|
|
@@ -3625,9 +3499,6 @@ ZodNullable.create = (type, params) => {
|
|
|
3625
3499
|
});
|
|
3626
3500
|
};
|
|
3627
3501
|
var ZodDefault = class extends ZodType {
|
|
3628
|
-
static {
|
|
3629
|
-
__name(this, "ZodDefault");
|
|
3630
|
-
}
|
|
3631
3502
|
_parse(input) {
|
|
3632
3503
|
const { ctx } = this._processInputParams(input);
|
|
3633
3504
|
let data = ctx.data;
|
|
@@ -3653,9 +3524,6 @@ ZodDefault.create = (type, params) => {
|
|
|
3653
3524
|
});
|
|
3654
3525
|
};
|
|
3655
3526
|
var ZodCatch = class extends ZodType {
|
|
3656
|
-
static {
|
|
3657
|
-
__name(this, "ZodCatch");
|
|
3658
|
-
}
|
|
3659
3527
|
_parse(input) {
|
|
3660
3528
|
const { ctx } = this._processInputParams(input);
|
|
3661
3529
|
const newCtx = {
|
|
@@ -3709,9 +3577,6 @@ ZodCatch.create = (type, params) => {
|
|
|
3709
3577
|
});
|
|
3710
3578
|
};
|
|
3711
3579
|
var ZodNaN = class extends ZodType {
|
|
3712
|
-
static {
|
|
3713
|
-
__name(this, "ZodNaN");
|
|
3714
|
-
}
|
|
3715
3580
|
_parse(input) {
|
|
3716
3581
|
const parsedType = this._getType(input);
|
|
3717
3582
|
if (parsedType !== ZodParsedType.nan) {
|
|
@@ -3734,9 +3599,6 @@ ZodNaN.create = (params) => {
|
|
|
3734
3599
|
};
|
|
3735
3600
|
var BRAND = Symbol("zod_brand");
|
|
3736
3601
|
var ZodBranded = class extends ZodType {
|
|
3737
|
-
static {
|
|
3738
|
-
__name(this, "ZodBranded");
|
|
3739
|
-
}
|
|
3740
3602
|
_parse(input) {
|
|
3741
3603
|
const { ctx } = this._processInputParams(input);
|
|
3742
3604
|
const data = ctx.data;
|
|
@@ -3751,13 +3613,10 @@ var ZodBranded = class extends ZodType {
|
|
|
3751
3613
|
}
|
|
3752
3614
|
};
|
|
3753
3615
|
var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
3754
|
-
static {
|
|
3755
|
-
__name(this, "ZodPipeline");
|
|
3756
|
-
}
|
|
3757
3616
|
_parse(input) {
|
|
3758
3617
|
const { status, ctx } = this._processInputParams(input);
|
|
3759
3618
|
if (ctx.common.async) {
|
|
3760
|
-
const handleAsync =
|
|
3619
|
+
const handleAsync = async () => {
|
|
3761
3620
|
const inResult = await this._def.in._parseAsync({
|
|
3762
3621
|
data: ctx.data,
|
|
3763
3622
|
path: ctx.path,
|
|
@@ -3775,7 +3634,7 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
|
3775
3634
|
parent: ctx
|
|
3776
3635
|
});
|
|
3777
3636
|
}
|
|
3778
|
-
}
|
|
3637
|
+
};
|
|
3779
3638
|
return handleAsync();
|
|
3780
3639
|
} else {
|
|
3781
3640
|
const inResult = this._def.in._parseSync({
|
|
@@ -3809,17 +3668,14 @@ var ZodPipeline = class _ZodPipeline extends ZodType {
|
|
|
3809
3668
|
}
|
|
3810
3669
|
};
|
|
3811
3670
|
var ZodReadonly = class extends ZodType {
|
|
3812
|
-
static {
|
|
3813
|
-
__name(this, "ZodReadonly");
|
|
3814
|
-
}
|
|
3815
3671
|
_parse(input) {
|
|
3816
3672
|
const result = this._def.innerType._parse(input);
|
|
3817
|
-
const freeze =
|
|
3673
|
+
const freeze = (data) => {
|
|
3818
3674
|
if (isValid(data)) {
|
|
3819
3675
|
data.value = Object.freeze(data.value);
|
|
3820
3676
|
}
|
|
3821
3677
|
return data;
|
|
3822
|
-
}
|
|
3678
|
+
};
|
|
3823
3679
|
return isAsync(result) ? result.then((data) => freeze(data)) : freeze(result);
|
|
3824
3680
|
}
|
|
3825
3681
|
unwrap() {
|
|
@@ -3846,7 +3702,6 @@ function custom(check, params = {}, fatal) {
|
|
|
3846
3702
|
});
|
|
3847
3703
|
return ZodAny.create();
|
|
3848
3704
|
}
|
|
3849
|
-
__name(custom, "custom");
|
|
3850
3705
|
var late = {
|
|
3851
3706
|
object: ZodObject.lazycreate
|
|
3852
3707
|
};
|
|
@@ -3889,9 +3744,9 @@ var ZodFirstPartyTypeKind;
|
|
|
3889
3744
|
ZodFirstPartyTypeKind2["ZodPipeline"] = "ZodPipeline";
|
|
3890
3745
|
ZodFirstPartyTypeKind2["ZodReadonly"] = "ZodReadonly";
|
|
3891
3746
|
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
3892
|
-
var instanceOfType =
|
|
3747
|
+
var instanceOfType = (cls, params = {
|
|
3893
3748
|
message: `Input not instance of ${cls.name}`
|
|
3894
|
-
}) => custom((data) => data instanceof cls, params)
|
|
3749
|
+
}) => custom((data) => data instanceof cls, params);
|
|
3895
3750
|
var stringType = ZodString.create;
|
|
3896
3751
|
var numberType = ZodNumber.create;
|
|
3897
3752
|
var nanType = ZodNaN.create;
|
|
@@ -3926,18 +3781,18 @@ var optionalType = ZodOptional.create;
|
|
|
3926
3781
|
var nullableType = ZodNullable.create;
|
|
3927
3782
|
var preprocessType = ZodEffects.createWithPreprocess;
|
|
3928
3783
|
var pipelineType = ZodPipeline.create;
|
|
3929
|
-
var ostring =
|
|
3930
|
-
var onumber =
|
|
3931
|
-
var oboolean =
|
|
3784
|
+
var ostring = () => stringType().optional();
|
|
3785
|
+
var onumber = () => numberType().optional();
|
|
3786
|
+
var oboolean = () => booleanType().optional();
|
|
3932
3787
|
var coerce = {
|
|
3933
|
-
string:
|
|
3934
|
-
number:
|
|
3935
|
-
boolean:
|
|
3788
|
+
string: (arg) => ZodString.create({ ...arg, coerce: true }),
|
|
3789
|
+
number: (arg) => ZodNumber.create({ ...arg, coerce: true }),
|
|
3790
|
+
boolean: (arg) => ZodBoolean.create({
|
|
3936
3791
|
...arg,
|
|
3937
3792
|
coerce: true
|
|
3938
|
-
}),
|
|
3939
|
-
bigint:
|
|
3940
|
-
date:
|
|
3793
|
+
}),
|
|
3794
|
+
bigint: (arg) => ZodBigInt.create({ ...arg, coerce: true }),
|
|
3795
|
+
date: (arg) => ZodDate.create({ ...arg, coerce: true })
|
|
3941
3796
|
};
|
|
3942
3797
|
var NEVER = INVALID;
|
|
3943
3798
|
var z = /* @__PURE__ */ Object.freeze({
|
|
@@ -4060,25 +3915,14 @@ var z = /* @__PURE__ */ Object.freeze({
|
|
|
4060
3915
|
// src/index.ts
|
|
4061
3916
|
function isValidSchemaType(type) {
|
|
4062
3917
|
if (typeof type !== "string") return false;
|
|
4063
|
-
return [
|
|
4064
|
-
"string",
|
|
4065
|
-
"number",
|
|
4066
|
-
"boolean",
|
|
4067
|
-
"integer",
|
|
4068
|
-
"array",
|
|
4069
|
-
"object",
|
|
4070
|
-
"null"
|
|
4071
|
-
].includes(type);
|
|
3918
|
+
return ["string", "number", "boolean", "integer", "array", "object", "null"].includes(type);
|
|
4072
3919
|
}
|
|
4073
|
-
__name(isValidSchemaType, "isValidSchemaType");
|
|
4074
3920
|
function isJSONSchema7(schema) {
|
|
4075
3921
|
return typeof schema !== "boolean";
|
|
4076
3922
|
}
|
|
4077
|
-
__name(isJSONSchema7, "isJSONSchema7");
|
|
4078
3923
|
function asExtendedJSONSchema7(schema) {
|
|
4079
3924
|
return schema;
|
|
4080
3925
|
}
|
|
4081
|
-
__name(asExtendedJSONSchema7, "asExtendedJSONSchema7");
|
|
4082
3926
|
function unwrapSchemaDefinition(schema) {
|
|
4083
3927
|
if (typeof schema === "boolean") {
|
|
4084
3928
|
return schema;
|
|
@@ -4091,11 +3935,9 @@ function unwrapSchemaDefinition(schema) {
|
|
|
4091
3935
|
}
|
|
4092
3936
|
return schema;
|
|
4093
3937
|
}
|
|
4094
|
-
__name(unwrapSchemaDefinition, "unwrapSchemaDefinition");
|
|
4095
3938
|
function isPlainObject(value) {
|
|
4096
3939
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4097
3940
|
}
|
|
4098
|
-
__name(isPlainObject, "isPlainObject");
|
|
4099
3941
|
function areValuesEqual(left, right) {
|
|
4100
3942
|
if (Object.is(left, right)) {
|
|
4101
3943
|
return true;
|
|
@@ -4116,30 +3958,24 @@ function areValuesEqual(left, right) {
|
|
|
4116
3958
|
}
|
|
4117
3959
|
return false;
|
|
4118
3960
|
}
|
|
4119
|
-
__name(areValuesEqual, "areValuesEqual");
|
|
4120
3961
|
var percent = z.number().min(0).max(100);
|
|
4121
3962
|
var formatMap = {
|
|
4122
|
-
"date":
|
|
4123
|
-
"date-time":
|
|
4124
|
-
"email":
|
|
4125
|
-
"hostname":
|
|
4126
|
-
"ipv4":
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
"
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
"
|
|
4133
|
-
"
|
|
4134
|
-
"color": /* @__PURE__ */ __name(() => z.string().regex(/^#(?:[0-9a-fA-F]{3}){1,2}$/), "color"),
|
|
4135
|
-
"password": /* @__PURE__ */ __name(() => z.string(), "password"),
|
|
4136
|
-
"code": /* @__PURE__ */ __name(() => z.string(), "code"),
|
|
4137
|
-
"percent": /* @__PURE__ */ __name(() => percent, "percent")
|
|
3963
|
+
"date": () => z.string().regex(/^\d{4}-\d{2}-\d{2}$/),
|
|
3964
|
+
"date-time": () => z.string().datetime(),
|
|
3965
|
+
"email": () => z.string().email(),
|
|
3966
|
+
"hostname": () => z.string(),
|
|
3967
|
+
"ipv4": () => z.string().ip({ version: "v4" }),
|
|
3968
|
+
"ipv6": () => z.string().ip({ version: "v6" }),
|
|
3969
|
+
"uri": () => z.string().url(),
|
|
3970
|
+
"uuid": () => z.string().uuid(),
|
|
3971
|
+
"color": () => z.string().regex(/^#(?:[0-9a-fA-F]{3}){1,2}$/),
|
|
3972
|
+
"password": () => z.string(),
|
|
3973
|
+
"code": () => z.string(),
|
|
3974
|
+
"percent": () => percent
|
|
4138
3975
|
};
|
|
4139
3976
|
function createRequiredUnknownSchema() {
|
|
4140
3977
|
return z.custom((value) => value !== void 0);
|
|
4141
3978
|
}
|
|
4142
|
-
__name(createRequiredUnknownSchema, "createRequiredUnknownSchema");
|
|
4143
3979
|
function inferSchemaType(schema) {
|
|
4144
3980
|
if (schema.type !== void 0 && !isValidSchemaType(schema.type)) {
|
|
4145
3981
|
throw new Error(`Unsupported type: ${schema.type}`);
|
|
@@ -4161,7 +3997,6 @@ function inferSchemaType(schema) {
|
|
|
4161
3997
|
}
|
|
4162
3998
|
return null;
|
|
4163
3999
|
}
|
|
4164
|
-
__name(inferSchemaType, "inferSchemaType");
|
|
4165
4000
|
function applyValidators(zodType, schema, required) {
|
|
4166
4001
|
let zodTypeWithValidators = zodType;
|
|
4167
4002
|
if (schema.type === "string" && required) {
|
|
@@ -4193,18 +4028,23 @@ function applyValidators(zodType, schema, required) {
|
|
|
4193
4028
|
zodTypeWithValidators = zodTypeWithValidators.regex(new RegExp(schema.pattern));
|
|
4194
4029
|
}
|
|
4195
4030
|
if (schema.const !== void 0) {
|
|
4196
|
-
zodTypeWithValidators = zodTypeWithValidators.refine(
|
|
4197
|
-
|
|
4198
|
-
|
|
4031
|
+
zodTypeWithValidators = zodTypeWithValidators.refine(
|
|
4032
|
+
(value) => areValuesEqual(value, schema.const),
|
|
4033
|
+
{
|
|
4034
|
+
message: `Must be equal to: ${JSON.stringify(schema.const)}`
|
|
4035
|
+
}
|
|
4036
|
+
);
|
|
4199
4037
|
}
|
|
4200
4038
|
if (schema.enum) {
|
|
4201
|
-
zodTypeWithValidators = zodTypeWithValidators.refine(
|
|
4202
|
-
|
|
4203
|
-
|
|
4039
|
+
zodTypeWithValidators = zodTypeWithValidators.refine(
|
|
4040
|
+
(value) => schema.enum.some((enumValue) => areValuesEqual(value, enumValue)),
|
|
4041
|
+
{
|
|
4042
|
+
message: `Must be one of: ${schema.enum.map((value) => JSON.stringify(value)).join(", ")}`
|
|
4043
|
+
}
|
|
4044
|
+
);
|
|
4204
4045
|
}
|
|
4205
4046
|
return zodTypeWithValidators;
|
|
4206
4047
|
}
|
|
4207
|
-
__name(applyValidators, "applyValidators");
|
|
4208
4048
|
function applyLogicalCompositionValidators(zodType, schema) {
|
|
4209
4049
|
let composedType = zodType;
|
|
4210
4050
|
if (schema.anyOf && schema.anyOf.length > 0) {
|
|
@@ -4230,14 +4070,12 @@ function applyLogicalCompositionValidators(zodType, schema) {
|
|
|
4230
4070
|
}
|
|
4231
4071
|
return composedType;
|
|
4232
4072
|
}
|
|
4233
|
-
__name(applyLogicalCompositionValidators, "applyLogicalCompositionValidators");
|
|
4234
4073
|
function matchesSchemaDefinition(schema, value) {
|
|
4235
4074
|
if (!isJSONSchema7(schema)) {
|
|
4236
4075
|
return schema;
|
|
4237
4076
|
}
|
|
4238
4077
|
return jsonSchemaDefinitionToZod(schema).safeParse(value).success;
|
|
4239
4078
|
}
|
|
4240
|
-
__name(matchesSchemaDefinition, "matchesSchemaDefinition");
|
|
4241
4079
|
function addSchemaIssues(schema, value, context) {
|
|
4242
4080
|
if (!isJSONSchema7(schema)) {
|
|
4243
4081
|
if (!schema) {
|
|
@@ -4256,11 +4094,10 @@ function addSchemaIssues(schema, value, context) {
|
|
|
4256
4094
|
context.addIssue(issue);
|
|
4257
4095
|
}
|
|
4258
4096
|
}
|
|
4259
|
-
__name(addSchemaIssues, "addSchemaIssues");
|
|
4260
4097
|
function collectComposablePropertyKeys(schema) {
|
|
4261
4098
|
const extendedSchema = asExtendedJSONSchema7(schema);
|
|
4262
4099
|
const keys = /* @__PURE__ */ new Set();
|
|
4263
|
-
const visit =
|
|
4100
|
+
const visit = (definition) => {
|
|
4264
4101
|
if (!definition || !isJSONSchema7(definition)) {
|
|
4265
4102
|
return;
|
|
4266
4103
|
}
|
|
@@ -4303,16 +4140,16 @@ function collectComposablePropertyKeys(schema) {
|
|
|
4303
4140
|
visit(extendedDefinition.if);
|
|
4304
4141
|
visit(extendedDefinition.then);
|
|
4305
4142
|
visit(extendedDefinition.else);
|
|
4306
|
-
}
|
|
4143
|
+
};
|
|
4307
4144
|
visit(extendedSchema);
|
|
4308
4145
|
return keys;
|
|
4309
4146
|
}
|
|
4310
|
-
__name(collectComposablePropertyKeys, "collectComposablePropertyKeys");
|
|
4311
4147
|
function hasComposableValidation(schema) {
|
|
4312
4148
|
const extendedSchema = asExtendedJSONSchema7(schema);
|
|
4313
|
-
return Boolean(
|
|
4149
|
+
return Boolean(
|
|
4150
|
+
extendedSchema.dependentRequired || extendedSchema.dependentSchemas || extendedSchema.if || extendedSchema.then || extendedSchema.else || Array.isArray(extendedSchema.allOf) && extendedSchema.allOf.length > 0
|
|
4151
|
+
);
|
|
4314
4152
|
}
|
|
4315
|
-
__name(hasComposableValidation, "hasComposableValidation");
|
|
4316
4153
|
function createPrimitiveType(schema, type) {
|
|
4317
4154
|
switch (type) {
|
|
4318
4155
|
case "string":
|
|
@@ -4333,7 +4170,6 @@ function createPrimitiveType(schema, type) {
|
|
|
4333
4170
|
return z.null();
|
|
4334
4171
|
}
|
|
4335
4172
|
}
|
|
4336
|
-
__name(createPrimitiveType, "createPrimitiveType");
|
|
4337
4173
|
function buildObjectSchema(schema) {
|
|
4338
4174
|
const extendedSchema = asExtendedJSONSchema7(schema);
|
|
4339
4175
|
const shape = {};
|
|
@@ -4372,9 +4208,7 @@ function buildObjectSchema(schema) {
|
|
|
4372
4208
|
context.addIssue({
|
|
4373
4209
|
code: z.ZodIssueCode.custom,
|
|
4374
4210
|
message: `Property "${requiredKey}" is required when "${triggerKey}" is present`,
|
|
4375
|
-
path: [
|
|
4376
|
-
requiredKey
|
|
4377
|
-
]
|
|
4211
|
+
path: [requiredKey]
|
|
4378
4212
|
});
|
|
4379
4213
|
}
|
|
4380
4214
|
}
|
|
@@ -4404,14 +4238,12 @@ function buildObjectSchema(schema) {
|
|
|
4404
4238
|
}
|
|
4405
4239
|
});
|
|
4406
4240
|
}
|
|
4407
|
-
__name(buildObjectSchema, "buildObjectSchema");
|
|
4408
4241
|
function buildArraySchema(schema) {
|
|
4409
4242
|
if (!schema.items || Array.isArray(schema.items)) {
|
|
4410
4243
|
throw new Error("Invalid array items");
|
|
4411
4244
|
}
|
|
4412
4245
|
return applyValidators(z.array(jsonSchemaDefinitionToZod(schema.items, true)), schema, true);
|
|
4413
4246
|
}
|
|
4414
|
-
__name(buildArraySchema, "buildArraySchema");
|
|
4415
4247
|
function jsonSchemaDefinitionToZod(schema, required = true) {
|
|
4416
4248
|
if (!isJSONSchema7(schema)) {
|
|
4417
4249
|
return schema ? z.any() : z.never();
|
|
@@ -4427,19 +4259,21 @@ function jsonSchemaDefinitionToZod(schema, required = true) {
|
|
|
4427
4259
|
return applyLogicalCompositionValidators(zodType, schema);
|
|
4428
4260
|
}
|
|
4429
4261
|
if (inferredType) {
|
|
4430
|
-
zodType = applyValidators(
|
|
4262
|
+
zodType = applyValidators(
|
|
4263
|
+
createPrimitiveType(schema, inferredType),
|
|
4264
|
+
schema,
|
|
4265
|
+
required
|
|
4266
|
+
);
|
|
4431
4267
|
return applyLogicalCompositionValidators(zodType, schema);
|
|
4432
4268
|
}
|
|
4433
4269
|
zodType = applyValidators(z.any(), schema, required);
|
|
4434
4270
|
return applyLogicalCompositionValidators(zodType, schema);
|
|
4435
4271
|
}
|
|
4436
|
-
__name(jsonSchemaDefinitionToZod, "jsonSchemaDefinitionToZod");
|
|
4437
4272
|
function convertPropertyToZod(schema, key, parentSchema) {
|
|
4438
4273
|
const required = Array.isArray(parentSchema.required) && parentSchema.required.includes(key);
|
|
4439
4274
|
const propertySchema = jsonSchemaDefinitionToZod(schema, required);
|
|
4440
4275
|
return required ? propertySchema : propertySchema.optional();
|
|
4441
4276
|
}
|
|
4442
|
-
__name(convertPropertyToZod, "convertPropertyToZod");
|
|
4443
4277
|
function jsonSchemaToZodSchema(schema) {
|
|
4444
4278
|
if (Array.isArray(schema)) {
|
|
4445
4279
|
const definitions = schema.map(unwrapSchemaDefinition).filter((definition) => definition !== null);
|
|
@@ -4450,7 +4284,6 @@ function jsonSchemaToZodSchema(schema) {
|
|
|
4450
4284
|
}
|
|
4451
4285
|
return jsonSchemaDefinitionToZod(schema);
|
|
4452
4286
|
}
|
|
4453
|
-
__name(jsonSchemaToZodSchema, "jsonSchemaToZodSchema");
|
|
4454
4287
|
function jsonSchemaToZod(schema) {
|
|
4455
4288
|
const zodSchema = {};
|
|
4456
4289
|
if (Array.isArray(schema)) {
|
|
@@ -4469,7 +4302,6 @@ function jsonSchemaToZod(schema) {
|
|
|
4469
4302
|
}
|
|
4470
4303
|
return zodSchema;
|
|
4471
4304
|
}
|
|
4472
|
-
__name(jsonSchemaToZod, "jsonSchemaToZod");
|
|
4473
4305
|
export {
|
|
4474
4306
|
jsonSchemaToZod,
|
|
4475
4307
|
jsonSchemaToZodSchema
|