zod 4.1.0-canary.20250821T014930 → 4.1.0-canary.20250823T071040
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/index.cjs +17 -7
- package/package.json +1 -1
- package/src/v4/classic/external.ts +0 -1
- package/src/v4/classic/parse.ts +49 -0
- package/src/v4/classic/schemas.ts +145 -7
- package/src/v4/classic/tests/catch.test.ts +25 -0
- package/src/v4/classic/tests/codec-examples.test.ts +538 -0
- package/src/v4/classic/tests/codec.test.ts +532 -0
- package/src/v4/classic/tests/continuability.test.ts +1 -1
- package/src/v4/classic/tests/default.test.ts +32 -0
- package/src/v4/classic/tests/firstparty.test.ts +4 -0
- package/src/v4/classic/tests/function.test.ts +31 -31
- package/src/v4/classic/tests/hash.test.ts +68 -0
- package/src/v4/classic/tests/nonoptional.test.ts +15 -0
- package/src/v4/classic/tests/object.test.ts +31 -0
- package/src/v4/classic/tests/pipe.test.ts +25 -5
- package/src/v4/classic/tests/prefault.test.ts +25 -0
- package/src/v4/classic/tests/preprocess.test.ts +1 -6
- package/src/v4/classic/tests/refine.test.ts +76 -3
- package/src/v4/classic/tests/string-formats.test.ts +16 -0
- package/src/v4/classic/tests/string.test.ts +82 -1
- package/src/v4/classic/tests/stringbool.test.ts +40 -0
- package/src/v4/classic/tests/template-literal.test.ts +1 -1
- package/src/v4/classic/tests/to-json-schema.test.ts +21 -2
- package/src/v4/classic/tests/transform.test.ts +7 -0
- package/src/v4/classic/tests/union.test.ts +1 -1
- package/src/v4/core/api.ts +25 -35
- package/src/v4/core/core.ts +7 -26
- package/src/v4/core/index.ts +0 -1
- package/src/v4/core/json-schema.ts +1 -0
- package/src/v4/core/parse.ts +101 -0
- package/src/v4/core/regexes.ts +40 -1
- package/src/v4/core/schemas.ts +521 -129
- package/src/v4/core/to-json-schema.ts +43 -8
- package/src/v4/core/util.ts +73 -0
- package/src/v4/mini/external.ts +0 -1
- package/src/v4/mini/parse.ts +14 -1
- package/src/v4/mini/schemas.ts +153 -12
- package/src/v4/mini/tests/codec.test.ts +499 -0
- package/src/v4/mini/tests/object.test.ts +9 -0
- package/src/v4/mini/tests/string.test.ts +16 -0
- package/v3/index.cjs +17 -7
- package/v4/classic/coerce.cjs +17 -7
- package/v4/classic/compat.cjs +17 -7
- package/v4/classic/errors.cjs +17 -7
- package/v4/classic/external.cjs +18 -9
- package/v4/classic/external.d.cts +1 -1
- package/v4/classic/external.d.ts +1 -1
- package/v4/classic/external.js +1 -1
- package/v4/classic/index.cjs +17 -7
- package/v4/classic/iso.cjs +17 -7
- package/v4/classic/parse.cjs +27 -8
- package/v4/classic/parse.d.cts +8 -0
- package/v4/classic/parse.d.ts +8 -0
- package/v4/classic/parse.js +9 -0
- package/v4/classic/schemas.cjs +76 -11
- package/v4/classic/schemas.d.cts +48 -2
- package/v4/classic/schemas.d.ts +48 -2
- package/v4/classic/schemas.js +51 -3
- package/v4/core/api.cjs +36 -35
- package/v4/core/api.d.cts +3 -4
- package/v4/core/api.d.ts +3 -4
- package/v4/core/api.js +19 -24
- package/v4/core/checks.cjs +17 -7
- package/v4/core/core.cjs +8 -1
- package/v4/core/core.d.cts +3 -0
- package/v4/core/core.d.ts +3 -0
- package/v4/core/core.js +6 -0
- package/v4/core/errors.cjs +17 -7
- package/v4/core/index.cjs +17 -8
- package/v4/core/index.d.cts +0 -1
- package/v4/core/index.d.ts +0 -1
- package/v4/core/index.js +0 -1
- package/v4/core/json-schema.d.cts +1 -0
- package/v4/core/json-schema.d.ts +1 -0
- package/v4/core/parse.cjs +62 -8
- package/v4/core/parse.d.cts +24 -0
- package/v4/core/parse.d.ts +24 -0
- package/v4/core/parse.js +36 -0
- package/v4/core/regexes.cjs +34 -2
- package/v4/core/regexes.d.cts +16 -0
- package/v4/core/regexes.d.ts +16 -0
- package/v4/core/regexes.js +32 -1
- package/v4/core/schemas.cjs +326 -84
- package/v4/core/schemas.d.cts +61 -3
- package/v4/core/schemas.d.ts +61 -3
- package/v4/core/schemas.js +308 -76
- package/v4/core/to-json-schema.cjs +42 -5
- package/v4/core/to-json-schema.d.cts +4 -3
- package/v4/core/to-json-schema.d.ts +4 -3
- package/v4/core/to-json-schema.js +42 -5
- package/v4/core/util.cjs +69 -0
- package/v4/core/util.d.cts +10 -0
- package/v4/core/util.d.ts +10 -0
- package/v4/core/util.js +62 -0
- package/v4/locales/ar.cjs +17 -7
- package/v4/locales/az.cjs +17 -7
- package/v4/locales/be.cjs +17 -7
- package/v4/locales/bg.cjs +17 -7
- package/v4/locales/ca.cjs +17 -7
- package/v4/locales/cs.cjs +17 -7
- package/v4/locales/da.cjs +17 -7
- package/v4/locales/de.cjs +17 -7
- package/v4/locales/en.cjs +17 -7
- package/v4/locales/eo.cjs +17 -7
- package/v4/locales/es.cjs +17 -7
- package/v4/locales/fa.cjs +17 -7
- package/v4/locales/fi.cjs +17 -7
- package/v4/locales/fr-CA.cjs +17 -7
- package/v4/locales/fr.cjs +17 -7
- package/v4/locales/he.cjs +17 -7
- package/v4/locales/hu.cjs +17 -7
- package/v4/locales/id.cjs +17 -7
- package/v4/locales/is.cjs +17 -7
- package/v4/locales/it.cjs +17 -7
- package/v4/locales/ja.cjs +17 -7
- package/v4/locales/kh.cjs +17 -7
- package/v4/locales/ko.cjs +17 -7
- package/v4/locales/mk.cjs +17 -7
- package/v4/locales/ms.cjs +17 -7
- package/v4/locales/nl.cjs +17 -7
- package/v4/locales/no.cjs +17 -7
- package/v4/locales/ota.cjs +17 -7
- package/v4/locales/pl.cjs +17 -7
- package/v4/locales/ps.cjs +17 -7
- package/v4/locales/pt.cjs +17 -7
- package/v4/locales/ru.cjs +17 -7
- package/v4/locales/sl.cjs +17 -7
- package/v4/locales/sv.cjs +17 -7
- package/v4/locales/ta.cjs +17 -7
- package/v4/locales/th.cjs +17 -7
- package/v4/locales/tr.cjs +17 -7
- package/v4/locales/ua.cjs +17 -7
- package/v4/locales/ur.cjs +17 -7
- package/v4/locales/vi.cjs +17 -7
- package/v4/locales/yo.cjs +17 -7
- package/v4/locales/zh-CN.cjs +17 -7
- package/v4/locales/zh-TW.cjs +17 -7
- package/v4/mini/coerce.cjs +17 -7
- package/v4/mini/external.cjs +18 -9
- package/v4/mini/external.d.cts +1 -1
- package/v4/mini/external.d.ts +1 -1
- package/v4/mini/external.js +1 -1
- package/v4/mini/index.cjs +17 -7
- package/v4/mini/iso.cjs +17 -7
- package/v4/mini/parse.cjs +9 -1
- package/v4/mini/parse.d.cts +1 -1
- package/v4/mini/parse.d.ts +1 -1
- package/v4/mini/parse.js +1 -1
- package/v4/mini/schemas.cjs +75 -10
- package/v4/mini/schemas.d.cts +49 -1
- package/v4/mini/schemas.d.ts +49 -1
- package/v4/mini/schemas.js +49 -2
- package/src/v4/core/function.ts +0 -176
- package/v4/core/function.cjs +0 -102
- package/v4/core/function.d.cts +0 -52
- package/v4/core/function.d.ts +0 -52
- package/v4/core/function.js +0 -75
package/v4/classic/schemas.js
CHANGED
|
@@ -183,6 +183,13 @@ export const ZodURL = /*@__PURE__*/ core.$constructor("ZodURL", (inst, def) => {
|
|
|
183
183
|
export function url(params) {
|
|
184
184
|
return core._url(ZodURL, params);
|
|
185
185
|
}
|
|
186
|
+
export function httpUrl(params) {
|
|
187
|
+
return core._url(ZodURL, {
|
|
188
|
+
protocol: /^https?$/,
|
|
189
|
+
hostname: core.regexes.domain,
|
|
190
|
+
...util.normalizeParams(params),
|
|
191
|
+
});
|
|
192
|
+
}
|
|
186
193
|
export const ZodEmoji = /*@__PURE__*/ core.$constructor("ZodEmoji", (inst, def) => {
|
|
187
194
|
// ZodStringFormat.init(inst, def);
|
|
188
195
|
core.$ZodEmoji.init(inst, def);
|
|
@@ -312,6 +319,17 @@ export function stringFormat(format, fnOrRegex, _params = {}) {
|
|
|
312
319
|
export function hostname(_params) {
|
|
313
320
|
return core._stringFormat(ZodCustomStringFormat, "hostname", core.regexes.hostname, _params);
|
|
314
321
|
}
|
|
322
|
+
export function hex(_params) {
|
|
323
|
+
return core._stringFormat(ZodCustomStringFormat, "hex", core.regexes.hex, _params);
|
|
324
|
+
}
|
|
325
|
+
export function hash(alg, params) {
|
|
326
|
+
const enc = params?.enc ?? "hex";
|
|
327
|
+
const format = `${alg}_${enc}`;
|
|
328
|
+
const regex = core.regexes[format];
|
|
329
|
+
if (!regex)
|
|
330
|
+
throw new Error(`Unrecognized hash format: ${format}`);
|
|
331
|
+
return core._stringFormat(ZodCustomStringFormat, format, regex, params);
|
|
332
|
+
}
|
|
315
333
|
export const ZodNumber = /*@__PURE__*/ core.$constructor("ZodNumber", (inst, def) => {
|
|
316
334
|
core.$ZodNumber.init(inst, def);
|
|
317
335
|
ZodType.init(inst, def);
|
|
@@ -488,7 +506,7 @@ export function keyof(schema) {
|
|
|
488
506
|
return _enum(Object.keys(shape));
|
|
489
507
|
}
|
|
490
508
|
export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def) => {
|
|
491
|
-
core.$
|
|
509
|
+
core.$ZodObjectJIT.init(inst, def);
|
|
492
510
|
ZodType.init(inst, def);
|
|
493
511
|
util.defineLazy(inst, "shape", () => def.shape);
|
|
494
512
|
inst.keyof = () => _enum(Object.keys(inst._zod.def.shape));
|
|
@@ -500,6 +518,9 @@ export const ZodObject = /*@__PURE__*/ core.$constructor("ZodObject", (inst, def
|
|
|
500
518
|
inst.extend = (incoming) => {
|
|
501
519
|
return util.extend(inst, incoming);
|
|
502
520
|
};
|
|
521
|
+
inst.safeExtend = (incoming) => {
|
|
522
|
+
return util.safeExtend(inst, incoming);
|
|
523
|
+
};
|
|
503
524
|
inst.merge = (other) => util.merge(inst, other);
|
|
504
525
|
inst.pick = (mask) => util.pick(inst, mask);
|
|
505
526
|
inst.omit = (mask) => util.omit(inst, mask);
|
|
@@ -746,6 +767,9 @@ export const ZodTransform = /*@__PURE__*/ core.$constructor("ZodTransform", (ins
|
|
|
746
767
|
core.$ZodTransform.init(inst, def);
|
|
747
768
|
ZodType.init(inst, def);
|
|
748
769
|
inst._zod.parse = (payload, _ctx) => {
|
|
770
|
+
if (_ctx.direction === "backward") {
|
|
771
|
+
throw new core.$ZodEncodeError(inst.constructor.name);
|
|
772
|
+
}
|
|
749
773
|
payload.addIssue = (issue) => {
|
|
750
774
|
if (typeof issue === "string") {
|
|
751
775
|
payload.issues.push(util.issue(issue, payload.value, def));
|
|
@@ -892,6 +916,19 @@ export function pipe(in_, out) {
|
|
|
892
916
|
// ...util.normalizeParams(params),
|
|
893
917
|
});
|
|
894
918
|
}
|
|
919
|
+
export const ZodCodec = /*@__PURE__*/ core.$constructor("ZodCodec", (inst, def) => {
|
|
920
|
+
ZodPipe.init(inst, def);
|
|
921
|
+
core.$ZodCodec.init(inst, def);
|
|
922
|
+
});
|
|
923
|
+
export function codec(in_, out, params) {
|
|
924
|
+
return new ZodCodec({
|
|
925
|
+
type: "pipe",
|
|
926
|
+
in: in_,
|
|
927
|
+
out: out,
|
|
928
|
+
transform: params.decode,
|
|
929
|
+
reverseTransform: params.encode,
|
|
930
|
+
});
|
|
931
|
+
}
|
|
895
932
|
export const ZodReadonly = /*@__PURE__*/ core.$constructor("ZodReadonly", (inst, def) => {
|
|
896
933
|
core.$ZodReadonly.init(inst, def);
|
|
897
934
|
ZodType.init(inst, def);
|
|
@@ -936,6 +973,18 @@ export function promise(innerType) {
|
|
|
936
973
|
innerType: innerType,
|
|
937
974
|
});
|
|
938
975
|
}
|
|
976
|
+
export const ZodFunction = /*@__PURE__*/ core.$constructor("ZodFunction", (inst, def) => {
|
|
977
|
+
core.$ZodFunction.init(inst, def);
|
|
978
|
+
ZodType.init(inst, def);
|
|
979
|
+
});
|
|
980
|
+
export function _function(params) {
|
|
981
|
+
return new ZodFunction({
|
|
982
|
+
type: "function",
|
|
983
|
+
input: Array.isArray(params?.input) ? tuple(params?.input) : (params?.input ?? array(unknown())),
|
|
984
|
+
output: params?.output ?? unknown(),
|
|
985
|
+
});
|
|
986
|
+
}
|
|
987
|
+
export { _function as function };
|
|
939
988
|
export const ZodCustom = /*@__PURE__*/ core.$constructor("ZodCustom", (inst, def) => {
|
|
940
989
|
core.$ZodCustom.init(inst, def);
|
|
941
990
|
ZodType.init(inst, def);
|
|
@@ -975,10 +1024,9 @@ function _instanceof(cls, params = {
|
|
|
975
1024
|
export { _instanceof as instanceof };
|
|
976
1025
|
// stringbool
|
|
977
1026
|
export const stringbool = (...args) => core._stringbool({
|
|
978
|
-
|
|
1027
|
+
Codec: ZodCodec,
|
|
979
1028
|
Boolean: ZodBoolean,
|
|
980
1029
|
String: ZodString,
|
|
981
|
-
Transform: ZodTransform,
|
|
982
1030
|
}, ...args);
|
|
983
1031
|
export function json(params) {
|
|
984
1032
|
const jsonSchema = lazy(() => {
|
package/v4/core/api.cjs
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.TimePrecision = void 0;
|
|
27
37
|
exports._string = _string;
|
|
@@ -78,13 +88,9 @@ exports._nan = _nan;
|
|
|
78
88
|
exports._lt = _lt;
|
|
79
89
|
exports._lte = _lte;
|
|
80
90
|
exports._max = _lte;
|
|
81
|
-
exports._lte = _lte;
|
|
82
|
-
exports._max = _lte;
|
|
83
91
|
exports._gt = _gt;
|
|
84
92
|
exports._gte = _gte;
|
|
85
93
|
exports._min = _gte;
|
|
86
|
-
exports._gte = _gte;
|
|
87
|
-
exports._min = _gte;
|
|
88
94
|
exports._positive = _positive;
|
|
89
95
|
exports._negative = _negative;
|
|
90
96
|
exports._nonpositive = _nonpositive;
|
|
@@ -973,7 +979,7 @@ function _superRefine(fn) {
|
|
|
973
979
|
_issue.code ?? (_issue.code = "custom");
|
|
974
980
|
_issue.input ?? (_issue.input = payload.value);
|
|
975
981
|
_issue.inst ?? (_issue.inst = ch);
|
|
976
|
-
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
982
|
+
_issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
|
|
977
983
|
payload.issues.push(util.issue(_issue));
|
|
978
984
|
}
|
|
979
985
|
};
|
|
@@ -999,13 +1005,16 @@ function _stringbool(Classes, _params) {
|
|
|
999
1005
|
}
|
|
1000
1006
|
const truthySet = new Set(truthyArray);
|
|
1001
1007
|
const falsySet = new Set(falsyArray);
|
|
1002
|
-
const
|
|
1008
|
+
const _Codec = Classes.Codec ?? schemas.$ZodCodec;
|
|
1003
1009
|
const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
|
|
1004
1010
|
const _String = Classes.String ?? schemas.$ZodString;
|
|
1005
|
-
const
|
|
1006
|
-
const
|
|
1007
|
-
|
|
1008
|
-
|
|
1011
|
+
const stringSchema = new _String({ type: "string", error: params.error });
|
|
1012
|
+
const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
|
|
1013
|
+
const codec = new _Codec({
|
|
1014
|
+
type: "pipe",
|
|
1015
|
+
in: stringSchema,
|
|
1016
|
+
out: booleanSchema,
|
|
1017
|
+
transform: ((input, payload) => {
|
|
1009
1018
|
let data = input;
|
|
1010
1019
|
if (params.case !== "sensitive")
|
|
1011
1020
|
data = data.toLowerCase();
|
|
@@ -1021,31 +1030,23 @@ function _stringbool(Classes, _params) {
|
|
|
1021
1030
|
expected: "stringbool",
|
|
1022
1031
|
values: [...truthySet, ...falsySet],
|
|
1023
1032
|
input: payload.value,
|
|
1024
|
-
inst:
|
|
1033
|
+
inst: codec,
|
|
1025
1034
|
continue: false,
|
|
1026
1035
|
});
|
|
1027
1036
|
return {};
|
|
1028
1037
|
}
|
|
1029
|
-
},
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
error: params.error,
|
|
1038
|
-
});
|
|
1039
|
-
const outerPipe = new _Pipe({
|
|
1040
|
-
type: "pipe",
|
|
1041
|
-
in: innerPipe,
|
|
1042
|
-
out: new _Boolean({
|
|
1043
|
-
type: "boolean",
|
|
1044
|
-
error: params.error,
|
|
1038
|
+
}),
|
|
1039
|
+
reverseTransform: ((input, _payload) => {
|
|
1040
|
+
if (input === true) {
|
|
1041
|
+
return truthyArray[0] || "true";
|
|
1042
|
+
}
|
|
1043
|
+
else {
|
|
1044
|
+
return falsyArray[0] || "false";
|
|
1045
|
+
}
|
|
1045
1046
|
}),
|
|
1046
1047
|
error: params.error,
|
|
1047
1048
|
});
|
|
1048
|
-
return
|
|
1049
|
+
return codec;
|
|
1049
1050
|
}
|
|
1050
1051
|
function _stringFormat(Class, format, fnOrRegex, _params = {}) {
|
|
1051
1052
|
const params = util.normalizeParams(_params);
|
package/v4/core/api.d.cts
CHANGED
|
@@ -269,7 +269,7 @@ export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIss
|
|
|
269
269
|
type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
|
270
270
|
/** The schema or check that originated this issue. */
|
|
271
271
|
readonly inst?: schemas.$ZodType | checks.$ZodCheck;
|
|
272
|
-
/** If `true`, Zod will
|
|
272
|
+
/** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
|
|
273
273
|
readonly continue?: boolean | undefined;
|
|
274
274
|
} & Record<string, unknown>> : never;
|
|
275
275
|
export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
|
@@ -288,9 +288,8 @@ export interface $ZodStringBoolParams extends TypeParams {
|
|
|
288
288
|
case?: "sensitive" | "insensitive" | undefined;
|
|
289
289
|
}
|
|
290
290
|
export declare function _stringbool(Classes: {
|
|
291
|
-
|
|
291
|
+
Codec?: typeof schemas.$ZodCodec;
|
|
292
292
|
Boolean?: typeof schemas.$ZodBoolean;
|
|
293
|
-
Transform?: typeof schemas.$ZodTransform;
|
|
294
293
|
String?: typeof schemas.$ZodString;
|
|
295
|
-
}, _params?: string | $ZodStringBoolParams): schemas.$
|
|
294
|
+
}, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
|
|
296
295
|
export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
|
package/v4/core/api.d.ts
CHANGED
|
@@ -269,7 +269,7 @@ export type $ZodSuperRefineIssue<T extends errors.$ZodIssueBase = errors.$ZodIss
|
|
|
269
269
|
type RawIssue<T extends errors.$ZodIssueBase> = T extends any ? util.Flatten<util.MakePartial<T, "message" | "path"> & {
|
|
270
270
|
/** The schema or check that originated this issue. */
|
|
271
271
|
readonly inst?: schemas.$ZodType | checks.$ZodCheck;
|
|
272
|
-
/** If `true`, Zod will
|
|
272
|
+
/** If `true`, Zod will execute subsequent checks/refinements instead of immediately aborting */
|
|
273
273
|
readonly continue?: boolean | undefined;
|
|
274
274
|
} & Record<string, unknown>> : never;
|
|
275
275
|
export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
|
@@ -288,9 +288,8 @@ export interface $ZodStringBoolParams extends TypeParams {
|
|
|
288
288
|
case?: "sensitive" | "insensitive" | undefined;
|
|
289
289
|
}
|
|
290
290
|
export declare function _stringbool(Classes: {
|
|
291
|
-
|
|
291
|
+
Codec?: typeof schemas.$ZodCodec;
|
|
292
292
|
Boolean?: typeof schemas.$ZodBoolean;
|
|
293
|
-
Transform?: typeof schemas.$ZodTransform;
|
|
294
293
|
String?: typeof schemas.$ZodString;
|
|
295
|
-
}, _params?: string | $ZodStringBoolParams): schemas.$
|
|
294
|
+
}, _params?: string | $ZodStringBoolParams): schemas.$ZodCodec<schemas.$ZodString, schemas.$ZodBoolean>;
|
|
296
295
|
export declare function _stringFormat<Format extends string>(Class: typeof schemas.$ZodCustomStringFormat, format: Format, fnOrRegex: ((arg: string) => util.MaybeAsync<unknown>) | RegExp, _params?: string | $ZodStringFormatParams): schemas.$ZodCustomStringFormat<Format>;
|
package/v4/core/api.js
CHANGED
|
@@ -838,7 +838,7 @@ export function _superRefine(fn) {
|
|
|
838
838
|
_issue.code ?? (_issue.code = "custom");
|
|
839
839
|
_issue.input ?? (_issue.input = payload.value);
|
|
840
840
|
_issue.inst ?? (_issue.inst = ch);
|
|
841
|
-
_issue.continue ?? (_issue.continue = !ch._zod.def.abort);
|
|
841
|
+
_issue.continue ?? (_issue.continue = !ch._zod.def.abort); // abort is always undefined, so this is always true...
|
|
842
842
|
payload.issues.push(util.issue(_issue));
|
|
843
843
|
}
|
|
844
844
|
};
|
|
@@ -864,13 +864,16 @@ export function _stringbool(Classes, _params) {
|
|
|
864
864
|
}
|
|
865
865
|
const truthySet = new Set(truthyArray);
|
|
866
866
|
const falsySet = new Set(falsyArray);
|
|
867
|
-
const
|
|
867
|
+
const _Codec = Classes.Codec ?? schemas.$ZodCodec;
|
|
868
868
|
const _Boolean = Classes.Boolean ?? schemas.$ZodBoolean;
|
|
869
869
|
const _String = Classes.String ?? schemas.$ZodString;
|
|
870
|
-
const
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
870
|
+
const stringSchema = new _String({ type: "string", error: params.error });
|
|
871
|
+
const booleanSchema = new _Boolean({ type: "boolean", error: params.error });
|
|
872
|
+
const codec = new _Codec({
|
|
873
|
+
type: "pipe",
|
|
874
|
+
in: stringSchema,
|
|
875
|
+
out: booleanSchema,
|
|
876
|
+
transform: ((input, payload) => {
|
|
874
877
|
let data = input;
|
|
875
878
|
if (params.case !== "sensitive")
|
|
876
879
|
data = data.toLowerCase();
|
|
@@ -886,31 +889,23 @@ export function _stringbool(Classes, _params) {
|
|
|
886
889
|
expected: "stringbool",
|
|
887
890
|
values: [...truthySet, ...falsySet],
|
|
888
891
|
input: payload.value,
|
|
889
|
-
inst:
|
|
892
|
+
inst: codec,
|
|
890
893
|
continue: false,
|
|
891
894
|
});
|
|
892
895
|
return {};
|
|
893
896
|
}
|
|
894
|
-
},
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
error: params.error,
|
|
903
|
-
});
|
|
904
|
-
const outerPipe = new _Pipe({
|
|
905
|
-
type: "pipe",
|
|
906
|
-
in: innerPipe,
|
|
907
|
-
out: new _Boolean({
|
|
908
|
-
type: "boolean",
|
|
909
|
-
error: params.error,
|
|
897
|
+
}),
|
|
898
|
+
reverseTransform: ((input, _payload) => {
|
|
899
|
+
if (input === true) {
|
|
900
|
+
return truthyArray[0] || "true";
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
return falsyArray[0] || "false";
|
|
904
|
+
}
|
|
910
905
|
}),
|
|
911
906
|
error: params.error,
|
|
912
907
|
});
|
|
913
|
-
return
|
|
908
|
+
return codec;
|
|
914
909
|
}
|
|
915
910
|
export function _stringFormat(Class, format, fnOrRegex, _params = {}) {
|
|
916
911
|
const params = util.normalizeParams(_params);
|
package/v4/core/checks.cjs
CHANGED
|
@@ -16,13 +16,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
16
16
|
}) : function(o, v) {
|
|
17
17
|
o["default"] = v;
|
|
18
18
|
});
|
|
19
|
-
var __importStar = (this && this.__importStar) || function (
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
26
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
37
|
exports.$ZodCheckOverwrite = exports.$ZodCheckMimeType = exports.$ZodCheckProperty = exports.$ZodCheckEndsWith = exports.$ZodCheckStartsWith = exports.$ZodCheckIncludes = exports.$ZodCheckUpperCase = exports.$ZodCheckLowerCase = exports.$ZodCheckRegex = exports.$ZodCheckStringFormat = exports.$ZodCheckLengthEquals = exports.$ZodCheckMinLength = exports.$ZodCheckMaxLength = exports.$ZodCheckSizeEquals = exports.$ZodCheckMinSize = exports.$ZodCheckMaxSize = exports.$ZodCheckBigIntFormat = exports.$ZodCheckNumberFormat = exports.$ZodCheckMultipleOf = exports.$ZodCheckGreaterThan = exports.$ZodCheckLessThan = exports.$ZodCheck = void 0;
|
|
28
38
|
const core = __importStar(require("./core.cjs"));
|
package/v4/core/core.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.globalConfig = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0;
|
|
3
|
+
exports.globalConfig = exports.$ZodEncodeError = exports.$ZodAsyncError = exports.$brand = exports.NEVER = void 0;
|
|
4
4
|
exports.$constructor = $constructor;
|
|
5
5
|
exports.config = config;
|
|
6
6
|
/** A special constant with type `never` */
|
|
@@ -59,6 +59,13 @@ class $ZodAsyncError extends Error {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
exports.$ZodAsyncError = $ZodAsyncError;
|
|
62
|
+
class $ZodEncodeError extends Error {
|
|
63
|
+
constructor(name) {
|
|
64
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
65
|
+
this.name = "ZodEncodeError";
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
exports.$ZodEncodeError = $ZodEncodeError;
|
|
62
69
|
exports.globalConfig = {};
|
|
63
70
|
function config(newConfig) {
|
|
64
71
|
if (newConfig)
|
package/v4/core/core.d.cts
CHANGED
|
@@ -26,6 +26,9 @@ export type $ZodBranded<T extends schemas.SomeType, Brand extends string | numbe
|
|
|
26
26
|
export declare class $ZodAsyncError extends Error {
|
|
27
27
|
constructor();
|
|
28
28
|
}
|
|
29
|
+
export declare class $ZodEncodeError extends Error {
|
|
30
|
+
constructor(name: string);
|
|
31
|
+
}
|
|
29
32
|
export type input<T> = T extends {
|
|
30
33
|
_zod: {
|
|
31
34
|
input: any;
|
package/v4/core/core.d.ts
CHANGED
|
@@ -26,6 +26,9 @@ export type $ZodBranded<T extends schemas.SomeType, Brand extends string | numbe
|
|
|
26
26
|
export declare class $ZodAsyncError extends Error {
|
|
27
27
|
constructor();
|
|
28
28
|
}
|
|
29
|
+
export declare class $ZodEncodeError extends Error {
|
|
30
|
+
constructor(name: string);
|
|
31
|
+
}
|
|
29
32
|
export type input<T> = T extends {
|
|
30
33
|
_zod: {
|
|
31
34
|
input: any;
|
package/v4/core/core.js
CHANGED
|
@@ -53,6 +53,12 @@ export class $ZodAsyncError extends Error {
|
|
|
53
53
|
super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
|
+
export class $ZodEncodeError extends Error {
|
|
57
|
+
constructor(name) {
|
|
58
|
+
super(`Encountered unidirectional transform during encode: ${name}`);
|
|
59
|
+
this.name = "ZodEncodeError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
56
62
|
export const globalConfig = {};
|
|
57
63
|
export function config(newConfig) {
|
|
58
64
|
if (newConfig)
|
package/v4/core/errors.cjs
CHANGED
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.$ZodRealError = exports.$ZodError = void 0;
|
|
27
37
|
exports.flattenError = flattenError;
|
package/v4/core/index.cjs
CHANGED
|
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
18
18
|
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
19
19
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
20
20
|
};
|
|
21
|
-
var __importStar = (this && this.__importStar) || function (
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
21
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
22
|
+
var ownKeys = function(o) {
|
|
23
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
24
|
+
var ar = [];
|
|
25
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
26
|
+
return ar;
|
|
27
|
+
};
|
|
28
|
+
return ownKeys(o);
|
|
29
|
+
};
|
|
30
|
+
return function (mod) {
|
|
31
|
+
if (mod && mod.__esModule) return mod;
|
|
32
|
+
var result = {};
|
|
33
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
34
|
+
__setModuleDefault(result, mod);
|
|
35
|
+
return result;
|
|
36
|
+
};
|
|
37
|
+
})();
|
|
28
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
39
|
exports.JSONSchema = exports.locales = exports.regexes = exports.util = void 0;
|
|
30
40
|
__exportStar(require("./core.cjs"), exports);
|
|
@@ -38,7 +48,6 @@ exports.regexes = __importStar(require("./regexes.cjs"));
|
|
|
38
48
|
exports.locales = __importStar(require("../locales/index.cjs"));
|
|
39
49
|
__exportStar(require("./registries.cjs"), exports);
|
|
40
50
|
__exportStar(require("./doc.cjs"), exports);
|
|
41
|
-
__exportStar(require("./function.cjs"), exports);
|
|
42
51
|
__exportStar(require("./api.cjs"), exports);
|
|
43
52
|
__exportStar(require("./to-json-schema.cjs"), exports);
|
|
44
53
|
exports.JSONSchema = __importStar(require("./json-schema.cjs"));
|
package/v4/core/index.d.cts
CHANGED
|
@@ -9,7 +9,6 @@ export * as regexes from "./regexes.cjs";
|
|
|
9
9
|
export * as locales from "../locales/index.cjs";
|
|
10
10
|
export * from "./registries.cjs";
|
|
11
11
|
export * from "./doc.cjs";
|
|
12
|
-
export * from "./function.cjs";
|
|
13
12
|
export * from "./api.cjs";
|
|
14
13
|
export * from "./to-json-schema.cjs";
|
|
15
14
|
export * as JSONSchema from "./json-schema.cjs";
|
package/v4/core/index.d.ts
CHANGED
|
@@ -9,7 +9,6 @@ export * as regexes from "./regexes.js";
|
|
|
9
9
|
export * as locales from "../locales/index.js";
|
|
10
10
|
export * from "./registries.js";
|
|
11
11
|
export * from "./doc.js";
|
|
12
|
-
export * from "./function.js";
|
|
13
12
|
export * from "./api.js";
|
|
14
13
|
export * from "./to-json-schema.js";
|
|
15
14
|
export * as JSONSchema from "./json-schema.js";
|
package/v4/core/index.js
CHANGED
|
@@ -9,7 +9,6 @@ export * as regexes from "./regexes.js";
|
|
|
9
9
|
export * as locales from "../locales/index.js";
|
|
10
10
|
export * from "./registries.js";
|
|
11
11
|
export * from "./doc.js";
|
|
12
|
-
export * from "./function.js";
|
|
13
12
|
export * from "./api.js";
|
|
14
13
|
export * from "./to-json-schema.js";
|
|
15
14
|
export * as JSONSchema from "./json-schema.js";
|
package/v4/core/json-schema.d.ts
CHANGED
package/v4/core/parse.cjs
CHANGED
|
@@ -15,15 +15,25 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.safeParseAsync = exports._safeParseAsync = exports.safeParse = exports._safeParse = exports.parseAsync = exports._parseAsync = exports.parse = exports._parse = void 0;
|
|
36
|
+
exports.safeDecodeAsync = exports._safeDecodeAsync = exports.safeEncodeAsync = exports._safeEncodeAsync = exports.safeDecode = exports._safeDecode = exports.safeEncode = exports._safeEncode = exports.decodeAsync = exports._decodeAsync = exports.encodeAsync = exports._encodeAsync = exports.decode = exports._decode = exports.encode = exports._encode = exports.safeParseAsync = exports._safeParseAsync = exports.safeParse = exports._safeParse = exports.parseAsync = exports._parseAsync = exports.parse = exports._parse = void 0;
|
|
27
37
|
const core = __importStar(require("./core.cjs"));
|
|
28
38
|
const errors = __importStar(require("./errors.cjs"));
|
|
29
39
|
const util = __importStar(require("./util.cjs"));
|
|
@@ -85,3 +95,47 @@ const _safeParseAsync = (_Err) => async (schema, value, _ctx) => {
|
|
|
85
95
|
};
|
|
86
96
|
exports._safeParseAsync = _safeParseAsync;
|
|
87
97
|
exports.safeParseAsync = (0, exports._safeParseAsync)(errors.$ZodRealError);
|
|
98
|
+
const _encode = (_Err) => (schema, value, _ctx) => {
|
|
99
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
100
|
+
return (0, exports._parse)(_Err)(schema, value, ctx);
|
|
101
|
+
};
|
|
102
|
+
exports._encode = _encode;
|
|
103
|
+
exports.encode = (0, exports._encode)(errors.$ZodRealError);
|
|
104
|
+
const _decode = (_Err) => (schema, value, _ctx) => {
|
|
105
|
+
return (0, exports._parse)(_Err)(schema, value, _ctx);
|
|
106
|
+
};
|
|
107
|
+
exports._decode = _decode;
|
|
108
|
+
exports.decode = (0, exports._decode)(errors.$ZodRealError);
|
|
109
|
+
const _encodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
110
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
111
|
+
return (0, exports._parseAsync)(_Err)(schema, value, ctx);
|
|
112
|
+
};
|
|
113
|
+
exports._encodeAsync = _encodeAsync;
|
|
114
|
+
exports.encodeAsync = (0, exports._encodeAsync)(errors.$ZodRealError);
|
|
115
|
+
const _decodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
116
|
+
return (0, exports._parseAsync)(_Err)(schema, value, _ctx);
|
|
117
|
+
};
|
|
118
|
+
exports._decodeAsync = _decodeAsync;
|
|
119
|
+
exports.decodeAsync = (0, exports._decodeAsync)(errors.$ZodRealError);
|
|
120
|
+
const _safeEncode = (_Err) => (schema, value, _ctx) => {
|
|
121
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
122
|
+
return (0, exports._safeParse)(_Err)(schema, value, ctx);
|
|
123
|
+
};
|
|
124
|
+
exports._safeEncode = _safeEncode;
|
|
125
|
+
exports.safeEncode = (0, exports._safeEncode)(errors.$ZodRealError);
|
|
126
|
+
const _safeDecode = (_Err) => (schema, value, _ctx) => {
|
|
127
|
+
return (0, exports._safeParse)(_Err)(schema, value, _ctx);
|
|
128
|
+
};
|
|
129
|
+
exports._safeDecode = _safeDecode;
|
|
130
|
+
exports.safeDecode = (0, exports._safeDecode)(errors.$ZodRealError);
|
|
131
|
+
const _safeEncodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
132
|
+
const ctx = _ctx ? Object.assign(_ctx, { direction: "backward" }) : { direction: "backward" };
|
|
133
|
+
return (0, exports._safeParseAsync)(_Err)(schema, value, ctx);
|
|
134
|
+
};
|
|
135
|
+
exports._safeEncodeAsync = _safeEncodeAsync;
|
|
136
|
+
exports.safeEncodeAsync = (0, exports._safeEncodeAsync)(errors.$ZodRealError);
|
|
137
|
+
const _safeDecodeAsync = (_Err) => async (schema, value, _ctx) => {
|
|
138
|
+
return (0, exports._safeParseAsync)(_Err)(schema, value, _ctx);
|
|
139
|
+
};
|
|
140
|
+
exports._safeDecodeAsync = _safeDecodeAsync;
|
|
141
|
+
exports.safeDecodeAsync = (0, exports._safeDecodeAsync)(errors.$ZodRealError);
|