zod 4.1.12 → 4.1.13
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/package.json +1 -1
- package/src/v4/classic/checks.ts +1 -0
- package/src/v4/classic/schemas.ts +20 -0
- package/src/v4/classic/tests/continuability.test.ts +22 -0
- package/src/v4/classic/tests/describe-meta-checks.test.ts +27 -0
- package/src/v4/classic/tests/index.test.ts +55 -1
- package/src/v4/classic/tests/promise.test.ts +1 -1
- package/src/v4/classic/tests/readonly.test.ts +1 -1
- package/src/v4/classic/tests/record.test.ts +141 -9
- package/src/v4/classic/tests/registries.test.ts +5 -1
- package/src/v4/classic/tests/string.test.ts +72 -0
- package/src/v4/classic/tests/template-literal.test.ts +8 -0
- package/src/v4/classic/tests/to-json-schema.test.ts +97 -0
- package/src/v4/classic/tests/tuple.test.ts +18 -0
- package/src/v4/classic/tests/url.test.ts +13 -0
- package/src/v4/core/api.ts +45 -0
- package/src/v4/core/core.ts +22 -9
- package/src/v4/core/regexes.ts +6 -1
- package/src/v4/core/registries.ts +12 -1
- package/src/v4/core/schemas.ts +50 -33
- package/src/v4/core/tests/extend.test.ts +42 -1
- package/src/v4/core/tests/locales/he.test.ts +379 -0
- package/src/v4/core/tests/locales/nl.test.ts +46 -0
- package/src/v4/core/tests/record-constructor.test.ts +67 -0
- package/src/v4/core/tests/recursive-tuples.test.ts +45 -0
- package/src/v4/core/to-json-schema.ts +55 -91
- package/src/v4/core/util.ts +11 -0
- package/src/v4/core/versions.ts +1 -1
- package/src/v4/locales/en.ts +1 -0
- package/src/v4/locales/he.ts +202 -71
- package/src/v4/locales/nl.ts +10 -10
- package/src/v4/mini/iso.ts +4 -4
- package/src/v4/mini/schemas.ts +17 -0
- package/src/v4/mini/tests/functions.test.ts +0 -38
- package/src/v4/mini/tests/index.test.ts +24 -1
- package/src/v4/mini/tests/string.test.ts +32 -0
- package/v3/ZodError.d.cts +1 -1
- package/v3/ZodError.d.ts +1 -1
- package/v4/classic/checks.cjs +2 -1
- package/v4/classic/checks.d.cts +1 -1
- package/v4/classic/checks.d.ts +1 -1
- package/v4/classic/checks.js +1 -1
- package/v4/classic/schemas.cjs +15 -2
- package/v4/classic/schemas.d.cts +8 -0
- package/v4/classic/schemas.d.ts +8 -0
- package/v4/classic/schemas.js +12 -0
- package/v4/core/api.cjs +40 -0
- package/v4/core/api.d.cts +7 -0
- package/v4/core/api.d.ts +7 -0
- package/v4/core/api.js +36 -0
- package/v4/core/core.cjs +20 -11
- package/v4/core/core.js +20 -11
- package/v4/core/regexes.cjs +31 -2
- package/v4/core/regexes.d.cts +1 -0
- package/v4/core/regexes.d.ts +1 -0
- package/v4/core/regexes.js +5 -0
- package/v4/core/registries.cjs +3 -1
- package/v4/core/registries.js +3 -1
- package/v4/core/schemas.cjs +32 -33
- package/v4/core/schemas.d.cts +12 -2
- package/v4/core/schemas.d.ts +12 -2
- package/v4/core/schemas.js +30 -31
- package/v4/core/to-json-schema.cjs +55 -92
- package/v4/core/to-json-schema.js +55 -92
- package/v4/core/util.cjs +11 -0
- package/v4/core/util.d.cts +1 -0
- package/v4/core/util.d.ts +1 -0
- package/v4/core/util.js +10 -0
- package/v4/core/versions.cjs +1 -1
- package/v4/core/versions.js +1 -1
- package/v4/locales/en.cjs +1 -0
- package/v4/locales/en.js +1 -0
- package/v4/locales/he.cjs +177 -66
- package/v4/locales/he.js +177 -66
- package/v4/locales/nl.cjs +8 -8
- package/v4/locales/nl.js +8 -8
- package/v4/mini/iso.cjs +4 -4
- package/v4/mini/iso.js +4 -4
- package/v4/mini/schemas.cjs +13 -2
- package/v4/mini/schemas.d.cts +6 -0
- package/v4/mini/schemas.d.ts +6 -0
- package/v4/mini/schemas.js +10 -0
|
@@ -1,43 +1,5 @@
|
|
|
1
1
|
import { expect, test } from "vitest";
|
|
2
|
-
// import * as z from "zod/v4/core";
|
|
3
2
|
|
|
4
3
|
test("z.function", () => {
|
|
5
4
|
expect(true).toEqual(true);
|
|
6
5
|
});
|
|
7
|
-
|
|
8
|
-
// test("z.function", () => {
|
|
9
|
-
// const a = z.function({
|
|
10
|
-
// args: z.tuple([z.string()]),
|
|
11
|
-
// returns: z.string(),
|
|
12
|
-
// });
|
|
13
|
-
|
|
14
|
-
// const myFunc = a.implement((name: string | number) => `Hello, ${name}!`);
|
|
15
|
-
|
|
16
|
-
// expect(myFunc("world")).toEqual("Hello, world!");
|
|
17
|
-
// expect(() => myFunc(123 as any)).toThrow();
|
|
18
|
-
|
|
19
|
-
// // this won't run
|
|
20
|
-
// () => {
|
|
21
|
-
// // @ts-expect-error
|
|
22
|
-
// const r = myFunc(123);
|
|
23
|
-
// expectTypeOf(r).toEqualTypeOf<string>();
|
|
24
|
-
// };
|
|
25
|
-
// });
|
|
26
|
-
|
|
27
|
-
// test("z.function async", async () => {
|
|
28
|
-
// const b = z.function({
|
|
29
|
-
// args: z.tuple([z.string()]).$check(async (_) => {}),
|
|
30
|
-
// returns: z.string().$check(async (_) => {}),
|
|
31
|
-
// });
|
|
32
|
-
// const myFuncAsync = b.implementAsync(async (name) => `Hello, ${name}!`);
|
|
33
|
-
|
|
34
|
-
// expect(await myFuncAsync("world")).toEqual("Hello, world!");
|
|
35
|
-
// expect(myFuncAsync(123 as any)).rejects.toThrow();
|
|
36
|
-
|
|
37
|
-
// // this won't run
|
|
38
|
-
// () => {
|
|
39
|
-
// // @ts-expect-error
|
|
40
|
-
// const r = myFuncAsync(123);
|
|
41
|
-
// expectTypeOf(r).toEqualTypeOf<Promise<string>>();
|
|
42
|
-
// };
|
|
43
|
-
// });
|
|
@@ -296,6 +296,29 @@ test("z.record", () => {
|
|
|
296
296
|
expect(() => z.parse(c, { a: "hello", b: "world" })).toThrow();
|
|
297
297
|
// extra keys
|
|
298
298
|
expect(() => z.parse(c, { a: "hello", b: "world", c: "world", d: "world" })).toThrow();
|
|
299
|
+
|
|
300
|
+
// literal union keys
|
|
301
|
+
const d = z.record(z.union([z.literal("a"), z.literal(0)]), z.string());
|
|
302
|
+
type d = z.output<typeof d>;
|
|
303
|
+
expectTypeOf<d>().toEqualTypeOf<Record<"a" | 0, string>>();
|
|
304
|
+
expect(z.parse(d, { a: "hello", 0: "world" })).toEqual({
|
|
305
|
+
a: "hello",
|
|
306
|
+
0: "world",
|
|
307
|
+
});
|
|
308
|
+
|
|
309
|
+
// TypeScript enum keys
|
|
310
|
+
enum Enum {
|
|
311
|
+
A = 0,
|
|
312
|
+
B = "hi",
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const e = z.record(z.enum(Enum), z.string());
|
|
316
|
+
type e = z.output<typeof e>;
|
|
317
|
+
expectTypeOf<e>().toEqualTypeOf<Record<Enum, string>>();
|
|
318
|
+
expect(z.parse(e, { [Enum.A]: "hello", [Enum.B]: "world" })).toEqual({
|
|
319
|
+
[Enum.A]: "hello",
|
|
320
|
+
[Enum.B]: "world",
|
|
321
|
+
});
|
|
299
322
|
});
|
|
300
323
|
|
|
301
324
|
test("z.map", () => {
|
|
@@ -789,7 +812,7 @@ test("z.stringbool", () => {
|
|
|
789
812
|
test("z.promise", async () => {
|
|
790
813
|
const a = z.promise(z.string());
|
|
791
814
|
type a = z.output<typeof a>;
|
|
792
|
-
expectTypeOf<a>().toEqualTypeOf<string
|
|
815
|
+
expectTypeOf<a>().toEqualTypeOf<Promise<string>>();
|
|
793
816
|
|
|
794
817
|
expect(await z.safeParseAsync(a, Promise.resolve("hello"))).toMatchObject({
|
|
795
818
|
success: true,
|
|
@@ -241,6 +241,38 @@ test("z.ipv6", () => {
|
|
|
241
241
|
expect(() => z.parse(a, 123)).toThrow();
|
|
242
242
|
});
|
|
243
243
|
|
|
244
|
+
test("z.mac", () => {
|
|
245
|
+
const a = z.mac();
|
|
246
|
+
// valid mac
|
|
247
|
+
expect(z.parse(a, "00:1A:2B:3C:4D:5E")).toEqual("00:1A:2B:3C:4D:5E");
|
|
248
|
+
// invalid mac (dash delimiter not accepted by default)
|
|
249
|
+
expect(() => z.parse(a, "01-23-45-67-89-AB")).toThrow();
|
|
250
|
+
expect(() => z.parse(a, "00:1A:2B::4D:5E")).toThrow();
|
|
251
|
+
expect(() => z.parse(a, "00:1a-2B:3c-4D:5e")).toThrow();
|
|
252
|
+
expect(() => z.parse(a, "hello")).toThrow();
|
|
253
|
+
// wrong type
|
|
254
|
+
expect(() => z.parse(a, 123)).toThrow();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
test("z.mac with custom delimiter", () => {
|
|
258
|
+
const a = z.mac({ delimiter: ":" });
|
|
259
|
+
// valid mac with colon
|
|
260
|
+
expect(z.parse(a, "00:1A:2B:3C:4D:5E")).toEqual("00:1A:2B:3C:4D:5E");
|
|
261
|
+
// invalid mac with dash
|
|
262
|
+
expect(() => z.parse(a, "00-1A-2B-3C-4D-5E")).toThrow();
|
|
263
|
+
|
|
264
|
+
const b = z.mac({ delimiter: "-" });
|
|
265
|
+
// valid mac with dash
|
|
266
|
+
expect(z.parse(b, "00-1A-2B-3C-4D-5E")).toEqual("00-1A-2B-3C-4D-5E");
|
|
267
|
+
// invalid mac with colon
|
|
268
|
+
expect(() => z.parse(b, "00:1A:2B:3C:4D:5E")).toThrow();
|
|
269
|
+
|
|
270
|
+
const c = z.mac({ delimiter: ":" });
|
|
271
|
+
// colon-only mac
|
|
272
|
+
expect(z.parse(c, "00:1A:2B:3C:4D:5E")).toEqual("00:1A:2B:3C:4D:5E");
|
|
273
|
+
expect(() => z.parse(c, "00-1A-2B-3C-4D-5E")).toThrow();
|
|
274
|
+
});
|
|
275
|
+
|
|
244
276
|
test("z.base64", () => {
|
|
245
277
|
const a = z.base64();
|
|
246
278
|
// valid base64
|
package/v3/ZodError.d.cts
CHANGED
|
@@ -12,10 +12,10 @@ export type typeToFlattenedError<T, U = string> = {
|
|
|
12
12
|
export declare const ZodIssueCode: {
|
|
13
13
|
custom: "custom";
|
|
14
14
|
invalid_type: "invalid_type";
|
|
15
|
-
unrecognized_keys: "unrecognized_keys";
|
|
16
15
|
too_big: "too_big";
|
|
17
16
|
too_small: "too_small";
|
|
18
17
|
not_multiple_of: "not_multiple_of";
|
|
18
|
+
unrecognized_keys: "unrecognized_keys";
|
|
19
19
|
invalid_union: "invalid_union";
|
|
20
20
|
invalid_literal: "invalid_literal";
|
|
21
21
|
invalid_union_discriminator: "invalid_union_discriminator";
|
package/v3/ZodError.d.ts
CHANGED
|
@@ -12,10 +12,10 @@ export type typeToFlattenedError<T, U = string> = {
|
|
|
12
12
|
export declare const ZodIssueCode: {
|
|
13
13
|
custom: "custom";
|
|
14
14
|
invalid_type: "invalid_type";
|
|
15
|
-
unrecognized_keys: "unrecognized_keys";
|
|
16
15
|
too_big: "too_big";
|
|
17
16
|
too_small: "too_small";
|
|
18
17
|
not_multiple_of: "not_multiple_of";
|
|
18
|
+
unrecognized_keys: "unrecognized_keys";
|
|
19
19
|
invalid_union: "invalid_union";
|
|
20
20
|
invalid_literal: "invalid_literal";
|
|
21
21
|
invalid_union_discriminator: "invalid_union_discriminator";
|
package/v4/classic/checks.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
|
|
3
|
+
exports.slugify = exports.toUpperCase = exports.toLowerCase = exports.trim = exports.normalize = exports.overwrite = exports.mime = exports.property = exports.endsWith = exports.startsWith = exports.includes = exports.uppercase = exports.lowercase = exports.regex = exports.length = exports.minLength = exports.maxLength = exports.size = exports.minSize = exports.maxSize = exports.multipleOf = exports.nonnegative = exports.nonpositive = exports.negative = exports.positive = exports.gte = exports.gt = exports.lte = exports.lt = void 0;
|
|
4
4
|
var index_js_1 = require("../core/index.cjs");
|
|
5
5
|
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return index_js_1._lt; } });
|
|
6
6
|
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return index_js_1._lte; } });
|
|
@@ -30,3 +30,4 @@ Object.defineProperty(exports, "normalize", { enumerable: true, get: function ()
|
|
|
30
30
|
Object.defineProperty(exports, "trim", { enumerable: true, get: function () { return index_js_1._trim; } });
|
|
31
31
|
Object.defineProperty(exports, "toLowerCase", { enumerable: true, get: function () { return index_js_1._toLowerCase; } });
|
|
32
32
|
Object.defineProperty(exports, "toUpperCase", { enumerable: true, get: function () { return index_js_1._toUpperCase; } });
|
|
33
|
+
Object.defineProperty(exports, "slugify", { enumerable: true, get: function () { return index_js_1._slugify; } });
|
package/v4/classic/checks.d.cts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.cjs";
|
package/v4/classic/checks.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, type $RefinementCtx as RefinementCtx, } from "../core/index.js";
|
package/v4/classic/checks.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, } from "../core/index.js";
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, } from "../core/index.js";
|
package/v4/classic/schemas.cjs
CHANGED
|
@@ -23,8 +23,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
exports.stringbool = exports.ZodCustom = exports.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = void 0;
|
|
26
|
+
exports.ZodFile = exports.ZodLiteral = exports.ZodEnum = exports.ZodSet = exports.ZodMap = exports.ZodRecord = exports.ZodTuple = exports.ZodIntersection = exports.ZodDiscriminatedUnion = exports.ZodUnion = exports.ZodObject = exports.ZodArray = exports.ZodDate = exports.ZodVoid = exports.ZodNever = exports.ZodUnknown = exports.ZodAny = exports.ZodNull = exports.ZodUndefined = exports.ZodSymbol = exports.ZodBigIntFormat = exports.ZodBigInt = exports.ZodBoolean = exports.ZodNumberFormat = exports.ZodNumber = exports.ZodCustomStringFormat = exports.ZodJWT = exports.ZodE164 = exports.ZodBase64URL = exports.ZodBase64 = exports.ZodCIDRv6 = exports.ZodCIDRv4 = exports.ZodIPv6 = exports.ZodMAC = exports.ZodIPv4 = exports.ZodKSUID = exports.ZodXID = exports.ZodULID = exports.ZodCUID2 = exports.ZodCUID = exports.ZodNanoID = exports.ZodEmoji = exports.ZodURL = exports.ZodUUID = exports.ZodGUID = exports.ZodEmail = exports.ZodStringFormat = exports.ZodString = exports._ZodString = exports.ZodType = void 0;
|
|
27
|
+
exports.stringbool = exports.meta = exports.describe = exports.ZodCustom = exports.ZodFunction = exports.ZodPromise = exports.ZodLazy = exports.ZodTemplateLiteral = exports.ZodReadonly = exports.ZodCodec = exports.ZodPipe = exports.ZodNaN = exports.ZodCatch = exports.ZodSuccess = exports.ZodNonOptional = exports.ZodPrefault = exports.ZodDefault = exports.ZodNullable = exports.ZodOptional = exports.ZodTransform = void 0;
|
|
28
28
|
exports.string = string;
|
|
29
29
|
exports.email = email;
|
|
30
30
|
exports.guid = guid;
|
|
@@ -42,6 +42,7 @@ exports.ulid = ulid;
|
|
|
42
42
|
exports.xid = xid;
|
|
43
43
|
exports.ksuid = ksuid;
|
|
44
44
|
exports.ipv4 = ipv4;
|
|
45
|
+
exports.mac = mac;
|
|
45
46
|
exports.ipv6 = ipv6;
|
|
46
47
|
exports.cidrv4 = cidrv4;
|
|
47
48
|
exports.cidrv6 = cidrv6;
|
|
@@ -223,6 +224,7 @@ exports._ZodString = core.$constructor("_ZodString", (inst, def) => {
|
|
|
223
224
|
inst.normalize = (...args) => inst.check(checks.normalize(...args));
|
|
224
225
|
inst.toLowerCase = () => inst.check(checks.toLowerCase());
|
|
225
226
|
inst.toUpperCase = () => inst.check(checks.toUpperCase());
|
|
227
|
+
inst.slugify = () => inst.check(checks.slugify());
|
|
226
228
|
});
|
|
227
229
|
exports.ZodString = core.$constructor("ZodString", (inst, def) => {
|
|
228
230
|
core.$ZodString.init(inst, def);
|
|
@@ -377,6 +379,14 @@ exports.ZodIPv4 = core.$constructor("ZodIPv4", (inst, def) => {
|
|
|
377
379
|
function ipv4(params) {
|
|
378
380
|
return core._ipv4(exports.ZodIPv4, params);
|
|
379
381
|
}
|
|
382
|
+
exports.ZodMAC = core.$constructor("ZodMAC", (inst, def) => {
|
|
383
|
+
// ZodStringFormat.init(inst, def);
|
|
384
|
+
core.$ZodMAC.init(inst, def);
|
|
385
|
+
exports.ZodStringFormat.init(inst, def);
|
|
386
|
+
});
|
|
387
|
+
function mac(params) {
|
|
388
|
+
return core._mac(exports.ZodMAC, params);
|
|
389
|
+
}
|
|
380
390
|
exports.ZodIPv6 = core.$constructor("ZodIPv6", (inst, def) => {
|
|
381
391
|
// ZodStringFormat.init(inst, def);
|
|
382
392
|
core.$ZodIPv6.init(inst, def);
|
|
@@ -1118,6 +1128,9 @@ function refine(fn, _params = {}) {
|
|
|
1118
1128
|
function superRefine(fn) {
|
|
1119
1129
|
return core._superRefine(fn);
|
|
1120
1130
|
}
|
|
1131
|
+
// Re-export describe and meta from core
|
|
1132
|
+
exports.describe = core.describe;
|
|
1133
|
+
exports.meta = core.meta;
|
|
1121
1134
|
function _instanceof(cls, params = {
|
|
1122
1135
|
error: `Input not instance of ${cls.name}`,
|
|
1123
1136
|
}) {
|
package/v4/classic/schemas.d.cts
CHANGED
|
@@ -94,6 +94,7 @@ export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$
|
|
|
94
94
|
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
|
|
95
95
|
toLowerCase(): this;
|
|
96
96
|
toUpperCase(): this;
|
|
97
|
+
slugify(): this;
|
|
97
98
|
}
|
|
98
99
|
/** @internal */
|
|
99
100
|
export declare const _ZodString: core.$constructor<_ZodString>;
|
|
@@ -223,6 +224,11 @@ export interface ZodIPv4 extends ZodStringFormat<"ipv4"> {
|
|
|
223
224
|
}
|
|
224
225
|
export declare const ZodIPv4: core.$constructor<ZodIPv4>;
|
|
225
226
|
export declare function ipv4(params?: string | core.$ZodIPv4Params): ZodIPv4;
|
|
227
|
+
export interface ZodMAC extends ZodStringFormat<"mac"> {
|
|
228
|
+
_zod: core.$ZodMACInternals;
|
|
229
|
+
}
|
|
230
|
+
export declare const ZodMAC: core.$constructor<ZodMAC>;
|
|
231
|
+
export declare function mac(params?: string | core.$ZodMACParams): ZodMAC;
|
|
226
232
|
export interface ZodIPv6 extends ZodStringFormat<"ipv6"> {
|
|
227
233
|
_zod: core.$ZodIPv6Internals;
|
|
228
234
|
}
|
|
@@ -649,6 +655,8 @@ export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<
|
|
|
649
655
|
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
650
656
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
651
657
|
export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
|
|
658
|
+
export declare const describe: typeof core.describe;
|
|
659
|
+
export declare const meta: typeof core.meta;
|
|
652
660
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
653
661
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
|
|
654
662
|
export { _instanceof as instanceof };
|
package/v4/classic/schemas.d.ts
CHANGED
|
@@ -94,6 +94,7 @@ export interface _ZodString<T extends core.$ZodStringInternals<unknown> = core.$
|
|
|
94
94
|
normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (string & {})): this;
|
|
95
95
|
toLowerCase(): this;
|
|
96
96
|
toUpperCase(): this;
|
|
97
|
+
slugify(): this;
|
|
97
98
|
}
|
|
98
99
|
/** @internal */
|
|
99
100
|
export declare const _ZodString: core.$constructor<_ZodString>;
|
|
@@ -223,6 +224,11 @@ export interface ZodIPv4 extends ZodStringFormat<"ipv4"> {
|
|
|
223
224
|
}
|
|
224
225
|
export declare const ZodIPv4: core.$constructor<ZodIPv4>;
|
|
225
226
|
export declare function ipv4(params?: string | core.$ZodIPv4Params): ZodIPv4;
|
|
227
|
+
export interface ZodMAC extends ZodStringFormat<"mac"> {
|
|
228
|
+
_zod: core.$ZodMACInternals;
|
|
229
|
+
}
|
|
230
|
+
export declare const ZodMAC: core.$constructor<ZodMAC>;
|
|
231
|
+
export declare function mac(params?: string | core.$ZodMACParams): ZodMAC;
|
|
226
232
|
export interface ZodIPv6 extends ZodStringFormat<"ipv6"> {
|
|
227
233
|
_zod: core.$ZodIPv6Internals;
|
|
228
234
|
}
|
|
@@ -649,6 +655,8 @@ export declare function check<O = unknown>(fn: core.CheckFn<O>): core.$ZodCheck<
|
|
|
649
655
|
export declare function custom<O>(fn?: (data: unknown) => unknown, _params?: string | core.$ZodCustomParams | undefined): ZodCustom<O, O>;
|
|
650
656
|
export declare function refine<T>(fn: (arg: NoInfer<T>) => util.MaybeAsync<unknown>, _params?: string | core.$ZodCustomParams): core.$ZodCheck<T>;
|
|
651
657
|
export declare function superRefine<T>(fn: (arg: T, payload: core.$RefinementCtx<T>) => void | Promise<void>): core.$ZodCheck<T>;
|
|
658
|
+
export declare const describe: typeof core.describe;
|
|
659
|
+
export declare const meta: typeof core.meta;
|
|
652
660
|
type ZodInstanceOfParams = core.Params<ZodCustom, core.$ZodIssueCustom, "type" | "check" | "checks" | "fn" | "abort" | "error" | "params" | "path">;
|
|
653
661
|
declare function _instanceof<T extends typeof util.Class>(cls: T, params?: ZodInstanceOfParams): ZodCustom<InstanceType<T>, InstanceType<T>>;
|
|
654
662
|
export { _instanceof as instanceof };
|
package/v4/classic/schemas.js
CHANGED
|
@@ -106,6 +106,7 @@ export const _ZodString = /*@__PURE__*/ core.$constructor("_ZodString", (inst, d
|
|
|
106
106
|
inst.normalize = (...args) => inst.check(checks.normalize(...args));
|
|
107
107
|
inst.toLowerCase = () => inst.check(checks.toLowerCase());
|
|
108
108
|
inst.toUpperCase = () => inst.check(checks.toUpperCase());
|
|
109
|
+
inst.slugify = () => inst.check(checks.slugify());
|
|
109
110
|
});
|
|
110
111
|
export const ZodString = /*@__PURE__*/ core.$constructor("ZodString", (inst, def) => {
|
|
111
112
|
core.$ZodString.init(inst, def);
|
|
@@ -260,6 +261,14 @@ export const ZodIPv4 = /*@__PURE__*/ core.$constructor("ZodIPv4", (inst, def) =>
|
|
|
260
261
|
export function ipv4(params) {
|
|
261
262
|
return core._ipv4(ZodIPv4, params);
|
|
262
263
|
}
|
|
264
|
+
export const ZodMAC = /*@__PURE__*/ core.$constructor("ZodMAC", (inst, def) => {
|
|
265
|
+
// ZodStringFormat.init(inst, def);
|
|
266
|
+
core.$ZodMAC.init(inst, def);
|
|
267
|
+
ZodStringFormat.init(inst, def);
|
|
268
|
+
});
|
|
269
|
+
export function mac(params) {
|
|
270
|
+
return core._mac(ZodMAC, params);
|
|
271
|
+
}
|
|
263
272
|
export const ZodIPv6 = /*@__PURE__*/ core.$constructor("ZodIPv6", (inst, def) => {
|
|
264
273
|
// ZodStringFormat.init(inst, def);
|
|
265
274
|
core.$ZodIPv6.init(inst, def);
|
|
@@ -1007,6 +1016,9 @@ export function refine(fn, _params = {}) {
|
|
|
1007
1016
|
export function superRefine(fn) {
|
|
1008
1017
|
return core._superRefine(fn);
|
|
1009
1018
|
}
|
|
1019
|
+
// Re-export describe and meta from core
|
|
1020
|
+
export const describe = core.describe;
|
|
1021
|
+
export const meta = core.meta;
|
|
1010
1022
|
function _instanceof(cls, params = {
|
|
1011
1023
|
error: `Input not instance of ${cls.name}`,
|
|
1012
1024
|
}) {
|
package/v4/core/api.cjs
CHANGED
|
@@ -42,6 +42,7 @@ exports._xid = _xid;
|
|
|
42
42
|
exports._ksuid = _ksuid;
|
|
43
43
|
exports._ipv4 = _ipv4;
|
|
44
44
|
exports._ipv6 = _ipv6;
|
|
45
|
+
exports._mac = _mac;
|
|
45
46
|
exports._cidrv4 = _cidrv4;
|
|
46
47
|
exports._cidrv6 = _cidrv6;
|
|
47
48
|
exports._base64 = _base64;
|
|
@@ -109,6 +110,7 @@ exports._normalize = _normalize;
|
|
|
109
110
|
exports._trim = _trim;
|
|
110
111
|
exports._toLowerCase = _toLowerCase;
|
|
111
112
|
exports._toUpperCase = _toUpperCase;
|
|
113
|
+
exports._slugify = _slugify;
|
|
112
114
|
exports._array = _array;
|
|
113
115
|
exports._union = _union;
|
|
114
116
|
exports._discriminatedUnion = _discriminatedUnion;
|
|
@@ -137,9 +139,12 @@ exports._custom = _custom;
|
|
|
137
139
|
exports._refine = _refine;
|
|
138
140
|
exports._superRefine = _superRefine;
|
|
139
141
|
exports._check = _check;
|
|
142
|
+
exports.describe = describe;
|
|
143
|
+
exports.meta = meta;
|
|
140
144
|
exports._stringbool = _stringbool;
|
|
141
145
|
exports._stringFormat = _stringFormat;
|
|
142
146
|
const checks = __importStar(require("./checks.cjs"));
|
|
147
|
+
const registries = __importStar(require("./registries.cjs"));
|
|
143
148
|
const schemas = __importStar(require("./schemas.cjs"));
|
|
144
149
|
const util = __importStar(require("./util.cjs"));
|
|
145
150
|
function _string(Class, params) {
|
|
@@ -302,6 +307,15 @@ function _ipv6(Class, params) {
|
|
|
302
307
|
...util.normalizeParams(params),
|
|
303
308
|
});
|
|
304
309
|
}
|
|
310
|
+
function _mac(Class, params) {
|
|
311
|
+
return new Class({
|
|
312
|
+
type: "string",
|
|
313
|
+
format: "mac",
|
|
314
|
+
check: "string_format",
|
|
315
|
+
abort: false,
|
|
316
|
+
...util.normalizeParams(params),
|
|
317
|
+
});
|
|
318
|
+
}
|
|
305
319
|
function _cidrv4(Class, params) {
|
|
306
320
|
return new Class({
|
|
307
321
|
type: "string",
|
|
@@ -742,6 +756,10 @@ function _toLowerCase() {
|
|
|
742
756
|
function _toUpperCase() {
|
|
743
757
|
return _overwrite((input) => input.toUpperCase());
|
|
744
758
|
}
|
|
759
|
+
// slugify
|
|
760
|
+
function _slugify() {
|
|
761
|
+
return _overwrite((input) => util.slugify(input));
|
|
762
|
+
}
|
|
745
763
|
function _array(Class, element, params) {
|
|
746
764
|
return new Class({
|
|
747
765
|
type: "array",
|
|
@@ -989,6 +1007,28 @@ function _check(fn, params) {
|
|
|
989
1007
|
ch._zod.check = fn;
|
|
990
1008
|
return ch;
|
|
991
1009
|
}
|
|
1010
|
+
function describe(description) {
|
|
1011
|
+
const ch = new checks.$ZodCheck({ check: "describe" });
|
|
1012
|
+
ch._zod.onattach = [
|
|
1013
|
+
(inst) => {
|
|
1014
|
+
const existing = registries.globalRegistry.get(inst) ?? {};
|
|
1015
|
+
registries.globalRegistry.add(inst, { ...existing, description });
|
|
1016
|
+
},
|
|
1017
|
+
];
|
|
1018
|
+
ch._zod.check = () => { }; // no-op check
|
|
1019
|
+
return ch;
|
|
1020
|
+
}
|
|
1021
|
+
function meta(metadata) {
|
|
1022
|
+
const ch = new checks.$ZodCheck({ check: "meta" });
|
|
1023
|
+
ch._zod.onattach = [
|
|
1024
|
+
(inst) => {
|
|
1025
|
+
const existing = registries.globalRegistry.get(inst) ?? {};
|
|
1026
|
+
registries.globalRegistry.add(inst, { ...existing, ...metadata });
|
|
1027
|
+
},
|
|
1028
|
+
];
|
|
1029
|
+
ch._zod.check = () => { }; // no-op check
|
|
1030
|
+
return ch;
|
|
1031
|
+
}
|
|
992
1032
|
function _stringbool(Classes, _params) {
|
|
993
1033
|
const params = util.normalizeParams(_params);
|
|
994
1034
|
let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
|
package/v4/core/api.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as checks from "./checks.cjs";
|
|
2
2
|
import type * as core from "./core.cjs";
|
|
3
3
|
import type * as errors from "./errors.cjs";
|
|
4
|
+
import * as registries from "./registries.cjs";
|
|
4
5
|
import * as schemas from "./schemas.cjs";
|
|
5
6
|
import * as util from "./util.cjs";
|
|
6
7
|
export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
|
|
@@ -69,6 +70,9 @@ export declare function _ipv4<T extends schemas.$ZodIPv4>(Class: util.SchemaClas
|
|
|
69
70
|
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
|
70
71
|
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
|
71
72
|
export declare function _ipv6<T extends schemas.$ZodIPv6>(Class: util.SchemaClass<T>, params?: string | $ZodIPv6Params | $ZodCheckIPv6Params): T;
|
|
73
|
+
export type $ZodMACParams = StringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
|
74
|
+
export type $ZodCheckMACParams = CheckStringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
|
75
|
+
export declare function _mac<T extends schemas.$ZodMAC>(Class: util.SchemaClass<T>, params?: string | $ZodMACParams | $ZodCheckMACParams): T;
|
|
72
76
|
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
|
73
77
|
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
|
74
78
|
export declare function _cidrv4<T extends schemas.$ZodCIDRv4>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv4Params | $ZodCheckCIDRv4Params): T;
|
|
@@ -198,6 +202,7 @@ export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (str
|
|
|
198
202
|
export declare function _trim(): checks.$ZodCheckOverwrite<string>;
|
|
199
203
|
export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
|
|
200
204
|
export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
|
|
205
|
+
export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
|
|
201
206
|
export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
|
|
202
207
|
export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
|
|
203
208
|
export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
|
|
@@ -277,6 +282,8 @@ export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
|
|
277
282
|
}
|
|
278
283
|
export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>): checks.$ZodCheck<T>;
|
|
279
284
|
export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
|
|
285
|
+
export declare function describe<T>(description: string): checks.$ZodCheck<T>;
|
|
286
|
+
export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
|
|
280
287
|
export interface $ZodStringBoolParams extends TypeParams {
|
|
281
288
|
truthy?: string[];
|
|
282
289
|
falsy?: string[];
|
package/v4/core/api.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as checks from "./checks.js";
|
|
2
2
|
import type * as core from "./core.js";
|
|
3
3
|
import type * as errors from "./errors.js";
|
|
4
|
+
import * as registries from "./registries.js";
|
|
4
5
|
import * as schemas from "./schemas.js";
|
|
5
6
|
import * as util from "./util.js";
|
|
6
7
|
export type Params<T extends schemas.$ZodType | checks.$ZodCheck, IssueTypes extends errors.$ZodIssueBase, OmitKeys extends keyof T["_zod"]["def"] = never> = util.Flatten<Partial<util.EmptyToNever<Omit<T["_zod"]["def"], OmitKeys> & ([IssueTypes] extends [never] ? {} : {
|
|
@@ -69,6 +70,9 @@ export declare function _ipv4<T extends schemas.$ZodIPv4>(Class: util.SchemaClas
|
|
|
69
70
|
export type $ZodIPv6Params = StringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
|
70
71
|
export type $ZodCheckIPv6Params = CheckStringFormatParams<schemas.$ZodIPv6, "pattern" | "when" | "version">;
|
|
71
72
|
export declare function _ipv6<T extends schemas.$ZodIPv6>(Class: util.SchemaClass<T>, params?: string | $ZodIPv6Params | $ZodCheckIPv6Params): T;
|
|
73
|
+
export type $ZodMACParams = StringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
|
74
|
+
export type $ZodCheckMACParams = CheckStringFormatParams<schemas.$ZodMAC, "pattern" | "when">;
|
|
75
|
+
export declare function _mac<T extends schemas.$ZodMAC>(Class: util.SchemaClass<T>, params?: string | $ZodMACParams | $ZodCheckMACParams): T;
|
|
72
76
|
export type $ZodCIDRv4Params = StringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
|
73
77
|
export type $ZodCheckCIDRv4Params = CheckStringFormatParams<schemas.$ZodCIDRv4, "pattern" | "when">;
|
|
74
78
|
export declare function _cidrv4<T extends schemas.$ZodCIDRv4>(Class: util.SchemaClass<T>, params?: string | $ZodCIDRv4Params | $ZodCheckCIDRv4Params): T;
|
|
@@ -198,6 +202,7 @@ export declare function _normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD" | (str
|
|
|
198
202
|
export declare function _trim(): checks.$ZodCheckOverwrite<string>;
|
|
199
203
|
export declare function _toLowerCase(): checks.$ZodCheckOverwrite<string>;
|
|
200
204
|
export declare function _toUpperCase(): checks.$ZodCheckOverwrite<string>;
|
|
205
|
+
export declare function _slugify(): checks.$ZodCheckOverwrite<string>;
|
|
201
206
|
export type $ZodArrayParams = TypeParams<schemas.$ZodArray, "element">;
|
|
202
207
|
export declare function _array<T extends schemas.$ZodType>(Class: util.SchemaClass<schemas.$ZodArray>, element: T, params?: string | $ZodArrayParams): schemas.$ZodArray<T>;
|
|
203
208
|
export type $ZodObjectParams = TypeParams<schemas.$ZodObject, "shape" | "catchall">;
|
|
@@ -277,6 +282,8 @@ export interface $RefinementCtx<T = unknown> extends schemas.ParsePayload<T> {
|
|
|
277
282
|
}
|
|
278
283
|
export declare function _superRefine<T>(fn: (arg: T, payload: $RefinementCtx<T>) => void | Promise<void>): checks.$ZodCheck<T>;
|
|
279
284
|
export declare function _check<O = unknown>(fn: schemas.CheckFn<O>, params?: string | $ZodCustomParams): checks.$ZodCheck<O>;
|
|
285
|
+
export declare function describe<T>(description: string): checks.$ZodCheck<T>;
|
|
286
|
+
export declare function meta<T>(metadata: registries.GlobalMeta): checks.$ZodCheck<T>;
|
|
280
287
|
export interface $ZodStringBoolParams extends TypeParams {
|
|
281
288
|
truthy?: string[];
|
|
282
289
|
falsy?: string[];
|
package/v4/core/api.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as checks from "./checks.js";
|
|
2
|
+
import * as registries from "./registries.js";
|
|
2
3
|
import * as schemas from "./schemas.js";
|
|
3
4
|
import * as util from "./util.js";
|
|
4
5
|
export function _string(Class, params) {
|
|
@@ -161,6 +162,15 @@ export function _ipv6(Class, params) {
|
|
|
161
162
|
...util.normalizeParams(params),
|
|
162
163
|
});
|
|
163
164
|
}
|
|
165
|
+
export function _mac(Class, params) {
|
|
166
|
+
return new Class({
|
|
167
|
+
type: "string",
|
|
168
|
+
format: "mac",
|
|
169
|
+
check: "string_format",
|
|
170
|
+
abort: false,
|
|
171
|
+
...util.normalizeParams(params),
|
|
172
|
+
});
|
|
173
|
+
}
|
|
164
174
|
export function _cidrv4(Class, params) {
|
|
165
175
|
return new Class({
|
|
166
176
|
type: "string",
|
|
@@ -607,6 +617,10 @@ export function _toLowerCase() {
|
|
|
607
617
|
export function _toUpperCase() {
|
|
608
618
|
return _overwrite((input) => input.toUpperCase());
|
|
609
619
|
}
|
|
620
|
+
// slugify
|
|
621
|
+
export function _slugify() {
|
|
622
|
+
return _overwrite((input) => util.slugify(input));
|
|
623
|
+
}
|
|
610
624
|
export function _array(Class, element, params) {
|
|
611
625
|
return new Class({
|
|
612
626
|
type: "array",
|
|
@@ -854,6 +868,28 @@ export function _check(fn, params) {
|
|
|
854
868
|
ch._zod.check = fn;
|
|
855
869
|
return ch;
|
|
856
870
|
}
|
|
871
|
+
export function describe(description) {
|
|
872
|
+
const ch = new checks.$ZodCheck({ check: "describe" });
|
|
873
|
+
ch._zod.onattach = [
|
|
874
|
+
(inst) => {
|
|
875
|
+
const existing = registries.globalRegistry.get(inst) ?? {};
|
|
876
|
+
registries.globalRegistry.add(inst, { ...existing, description });
|
|
877
|
+
},
|
|
878
|
+
];
|
|
879
|
+
ch._zod.check = () => { }; // no-op check
|
|
880
|
+
return ch;
|
|
881
|
+
}
|
|
882
|
+
export function meta(metadata) {
|
|
883
|
+
const ch = new checks.$ZodCheck({ check: "meta" });
|
|
884
|
+
ch._zod.onattach = [
|
|
885
|
+
(inst) => {
|
|
886
|
+
const existing = registries.globalRegistry.get(inst) ?? {};
|
|
887
|
+
registries.globalRegistry.add(inst, { ...existing, ...metadata });
|
|
888
|
+
},
|
|
889
|
+
];
|
|
890
|
+
ch._zod.check = () => { }; // no-op check
|
|
891
|
+
return ch;
|
|
892
|
+
}
|
|
857
893
|
export function _stringbool(Classes, _params) {
|
|
858
894
|
const params = util.normalizeParams(_params);
|
|
859
895
|
let truthyArray = params.truthy ?? ["true", "1", "yes", "on", "y", "enabled"];
|
package/v4/core/core.cjs
CHANGED
|
@@ -9,21 +9,30 @@ exports.NEVER = Object.freeze({
|
|
|
9
9
|
});
|
|
10
10
|
function $constructor(name, initializer, params) {
|
|
11
11
|
function init(inst, def) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
12
|
+
if (!inst._zod) {
|
|
13
|
+
Object.defineProperty(inst, "_zod", {
|
|
14
|
+
value: {
|
|
15
|
+
def,
|
|
16
|
+
constr: _,
|
|
17
|
+
traits: new Set(),
|
|
18
|
+
},
|
|
19
|
+
enumerable: false,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
if (inst._zod.traits.has(name)) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
18
25
|
inst._zod.traits.add(name);
|
|
19
26
|
initializer(inst, def);
|
|
20
27
|
// support prototype modifications
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
28
|
+
const proto = _.prototype;
|
|
29
|
+
const keys = Object.keys(proto);
|
|
30
|
+
for (let i = 0; i < keys.length; i++) {
|
|
31
|
+
const k = keys[i];
|
|
32
|
+
if (!(k in inst)) {
|
|
33
|
+
inst[k] = proto[k].bind(inst);
|
|
34
|
+
}
|
|
24
35
|
}
|
|
25
|
-
inst._zod.constr = _;
|
|
26
|
-
inst._zod.def = def;
|
|
27
36
|
}
|
|
28
37
|
// doesn't work if Parent has a constructor with arguments
|
|
29
38
|
const Parent = params?.Parent ?? Object;
|
package/v4/core/core.js
CHANGED
|
@@ -4,21 +4,30 @@ export const NEVER = Object.freeze({
|
|
|
4
4
|
});
|
|
5
5
|
export /*@__NO_SIDE_EFFECTS__*/ function $constructor(name, initializer, params) {
|
|
6
6
|
function init(inst, def) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
if (!inst._zod) {
|
|
8
|
+
Object.defineProperty(inst, "_zod", {
|
|
9
|
+
value: {
|
|
10
|
+
def,
|
|
11
|
+
constr: _,
|
|
12
|
+
traits: new Set(),
|
|
13
|
+
},
|
|
14
|
+
enumerable: false,
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
if (inst._zod.traits.has(name)) {
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
13
20
|
inst._zod.traits.add(name);
|
|
14
21
|
initializer(inst, def);
|
|
15
22
|
// support prototype modifications
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
23
|
+
const proto = _.prototype;
|
|
24
|
+
const keys = Object.keys(proto);
|
|
25
|
+
for (let i = 0; i < keys.length; i++) {
|
|
26
|
+
const k = keys[i];
|
|
27
|
+
if (!(k in inst)) {
|
|
28
|
+
inst[k] = proto[k].bind(inst);
|
|
29
|
+
}
|
|
19
30
|
}
|
|
20
|
-
inst._zod.constr = _;
|
|
21
|
-
inst._zod.def = def;
|
|
22
31
|
}
|
|
23
32
|
// doesn't work if Parent has a constructor with arguments
|
|
24
33
|
const Parent = params?.Parent ?? Object;
|