zod 3.13.2 → 3.14.0

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.
@@ -1,59 +1,19 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
- var __values = (this && this.__values) || function(o) {
28
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
29
- if (m) return m.call(o);
30
- if (o && typeof o.length === "number") return {
31
- next: function () {
32
- if (o && i >= o.length) o = void 0;
33
- return { value: o && o[i++], done: !o };
34
- }
35
- };
36
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
37
- };
38
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
39
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
40
4
  };
41
- var e_1, _a;
42
5
  Object.defineProperty(exports, "__esModule", { value: true });
43
- var discriminatedUnion_1 = __importDefault(require("./discriminatedUnion"));
44
- var object_1 = __importDefault(require("./object"));
45
- var string_1 = __importDefault(require("./string"));
46
- var union_1 = __importDefault(require("./union"));
47
- try {
48
- for (var _b = __values(__spreadArray(__spreadArray(__spreadArray(__spreadArray([], __read(string_1.default.suites), false), __read(object_1.default.suites), false), __read(union_1.default.suites), false), __read(discriminatedUnion_1.default.suites), false)), _c = _b.next(); !_c.done; _c = _b.next()) {
49
- var suite = _c.value;
50
- suite.run();
51
- }
52
- }
53
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
54
- finally {
55
- try {
56
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
57
- }
58
- finally { if (e_1) throw e_1.error; }
6
+ const discriminatedUnion_1 = __importDefault(require("./discriminatedUnion"));
7
+ const object_1 = __importDefault(require("./object"));
8
+ const realworld_1 = __importDefault(require("./realworld"));
9
+ const string_1 = __importDefault(require("./string"));
10
+ const union_1 = __importDefault(require("./union"));
11
+ for (const suite of [
12
+ ...realworld_1.default.suites,
13
+ ...string_1.default.suites,
14
+ ...object_1.default.suites,
15
+ ...union_1.default.suites,
16
+ ...discriminatedUnion_1.default.suites,
17
+ ]) {
18
+ suite.run();
59
19
  }
@@ -3,67 +3,67 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var benchmark_1 = __importDefault(require("benchmark"));
7
- var index_1 = require("../index");
8
- var emptySuite = new benchmark_1.default.Suite("z.object: empty");
9
- var shortSuite = new benchmark_1.default.Suite("z.object: short");
10
- var longSuite = new benchmark_1.default.Suite("z.object: long");
11
- var empty = index_1.z.object({});
12
- var short = index_1.z.object({
6
+ const benchmark_1 = __importDefault(require("benchmark"));
7
+ const index_1 = require("../index");
8
+ const emptySuite = new benchmark_1.default.Suite("z.object: empty");
9
+ const shortSuite = new benchmark_1.default.Suite("z.object: short");
10
+ const longSuite = new benchmark_1.default.Suite("z.object: long");
11
+ const empty = index_1.z.object({});
12
+ const short = index_1.z.object({
13
13
  string: index_1.z.string(),
14
14
  });
15
- var long = index_1.z.object({
15
+ const long = index_1.z.object({
16
16
  string: index_1.z.string(),
17
17
  number: index_1.z.number(),
18
18
  boolean: index_1.z.boolean(),
19
19
  });
20
20
  emptySuite
21
- .add("valid", function () {
21
+ .add("valid", () => {
22
22
  empty.parse({});
23
23
  })
24
- .add("valid: extra keys", function () {
24
+ .add("valid: extra keys", () => {
25
25
  empty.parse({ string: "string" });
26
26
  })
27
- .add("invalid: null", function () {
27
+ .add("invalid: null", () => {
28
28
  try {
29
29
  empty.parse(null);
30
30
  }
31
31
  catch (err) { }
32
32
  })
33
- .on("cycle", function (e) {
34
- console.log("".concat(emptySuite.name, ": ").concat(e.target));
33
+ .on("cycle", (e) => {
34
+ console.log(`${emptySuite.name}: ${e.target}`);
35
35
  });
36
36
  shortSuite
37
- .add("valid", function () {
37
+ .add("valid", () => {
38
38
  short.parse({ string: "string" });
39
39
  })
40
- .add("valid: extra keys", function () {
40
+ .add("valid: extra keys", () => {
41
41
  short.parse({ string: "string", number: 42 });
42
42
  })
43
- .add("invalid: null", function () {
43
+ .add("invalid: null", () => {
44
44
  try {
45
45
  short.parse(null);
46
46
  }
47
47
  catch (err) { }
48
48
  })
49
- .on("cycle", function (e) {
50
- console.log("".concat(shortSuite.name, ": ").concat(e.target));
49
+ .on("cycle", (e) => {
50
+ console.log(`${shortSuite.name}: ${e.target}`);
51
51
  });
52
52
  longSuite
53
- .add("valid", function () {
53
+ .add("valid", () => {
54
54
  long.parse({ string: "string", number: 42, boolean: true });
55
55
  })
56
- .add("valid: extra keys", function () {
56
+ .add("valid: extra keys", () => {
57
57
  long.parse({ string: "string", number: 42, boolean: true, list: [] });
58
58
  })
59
- .add("invalid: null", function () {
59
+ .add("invalid: null", () => {
60
60
  try {
61
61
  long.parse(null);
62
62
  }
63
63
  catch (err) { }
64
64
  })
65
- .on("cycle", function (e) {
66
- console.log("".concat(longSuite.name, ": ").concat(e.target));
65
+ .on("cycle", (e) => {
66
+ console.log(`${longSuite.name}: ${e.target}`);
67
67
  });
68
68
  exports.default = {
69
69
  suites: [emptySuite, shortSuite, longSuite],
@@ -0,0 +1,5 @@
1
+ import Benchmark from "benchmark";
2
+ declare const _default: {
3
+ suites: Benchmark.Suite[];
4
+ };
5
+ export default _default;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const benchmark_1 = __importDefault(require("benchmark"));
7
+ const index_1 = require("../index");
8
+ const shortSuite = new benchmark_1.default.Suite("realworld");
9
+ const People = index_1.z.array(index_1.z.object({
10
+ type: index_1.z.literal("person"),
11
+ hair: index_1.z.enum(["blue", "brown"]),
12
+ active: index_1.z.boolean(),
13
+ name: index_1.z.string(),
14
+ age: index_1.z.number().int(),
15
+ hobbies: index_1.z.array(index_1.z.string()),
16
+ address: index_1.z.object({
17
+ street: index_1.z.string(),
18
+ zip: index_1.z.string(),
19
+ country: index_1.z.string(),
20
+ }),
21
+ }));
22
+ let i = 0;
23
+ function num() {
24
+ return ++i;
25
+ }
26
+ function str() {
27
+ return (++i % 100).toString(16);
28
+ }
29
+ function array(fn) {
30
+ return Array.from({ length: ++i % 10 }, () => fn());
31
+ }
32
+ const people = Array.from({ length: 100 }, () => {
33
+ return {
34
+ type: "person",
35
+ hair: i % 2 ? "blue" : "brown",
36
+ active: !!(i % 2),
37
+ name: str(),
38
+ age: num(),
39
+ hobbies: array(str),
40
+ address: {
41
+ street: str(),
42
+ zip: str(),
43
+ country: str(),
44
+ },
45
+ };
46
+ });
47
+ shortSuite
48
+ .add("valid", () => {
49
+ People.parse(people);
50
+ })
51
+ .on("cycle", (e) => {
52
+ console.log(`${shortSuite.name}: ${e.target}`);
53
+ });
54
+ exports.default = {
55
+ suites: [shortSuite],
56
+ };
@@ -3,41 +3,41 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var benchmark_1 = __importDefault(require("benchmark"));
7
- var index_1 = require("../index");
8
- var SUITE_NAME = "z.string";
9
- var suite = new benchmark_1.default.Suite(SUITE_NAME);
10
- var empty = "";
11
- var short = "short";
12
- var long = "long".repeat(256);
13
- var manual = function (str) {
6
+ const benchmark_1 = __importDefault(require("benchmark"));
7
+ const index_1 = require("../index");
8
+ const SUITE_NAME = "z.string";
9
+ const suite = new benchmark_1.default.Suite(SUITE_NAME);
10
+ const empty = "";
11
+ const short = "short";
12
+ const long = "long".repeat(256);
13
+ const manual = (str) => {
14
14
  if (typeof str !== "string") {
15
15
  throw new Error("Not a string");
16
16
  }
17
17
  return str;
18
18
  };
19
- var stringSchema = index_1.z.string();
19
+ const stringSchema = index_1.z.string();
20
20
  suite
21
- .add("empty string", function () {
21
+ .add("empty string", () => {
22
22
  stringSchema.parse(empty);
23
23
  })
24
- .add("short string", function () {
24
+ .add("short string", () => {
25
25
  stringSchema.parse(short);
26
26
  })
27
- .add("long string", function () {
27
+ .add("long string", () => {
28
28
  stringSchema.parse(long);
29
29
  })
30
- .add("invalid: null", function () {
30
+ .add("invalid: null", () => {
31
31
  try {
32
32
  stringSchema.parse(null);
33
33
  }
34
34
  catch (err) { }
35
35
  })
36
- .add("manual parser: long", function () {
36
+ .add("manual parser: long", () => {
37
37
  manual(long);
38
38
  })
39
- .on("cycle", function (e) {
40
- console.log("".concat(SUITE_NAME, ": ").concat(e.target));
39
+ .on("cycle", (e) => {
40
+ console.log(`${SUITE_NAME}: ${e.target}`);
41
41
  });
42
42
  exports.default = {
43
43
  suites: [suite],
@@ -3,76 +3,76 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- var benchmark_1 = __importDefault(require("benchmark"));
7
- var index_1 = require("../index");
8
- var doubleSuite = new benchmark_1.default.Suite("z.union: double");
9
- var manySuite = new benchmark_1.default.Suite("z.union: many");
10
- var aSchema = index_1.z.object({
6
+ const benchmark_1 = __importDefault(require("benchmark"));
7
+ const index_1 = require("../index");
8
+ const doubleSuite = new benchmark_1.default.Suite("z.union: double");
9
+ const manySuite = new benchmark_1.default.Suite("z.union: many");
10
+ const aSchema = index_1.z.object({
11
11
  type: index_1.z.literal("a"),
12
12
  });
13
- var objA = {
13
+ const objA = {
14
14
  type: "a",
15
15
  };
16
- var bSchema = index_1.z.object({
16
+ const bSchema = index_1.z.object({
17
17
  type: index_1.z.literal("b"),
18
18
  });
19
- var objB = {
19
+ const objB = {
20
20
  type: "b",
21
21
  };
22
- var cSchema = index_1.z.object({
22
+ const cSchema = index_1.z.object({
23
23
  type: index_1.z.literal("c"),
24
24
  });
25
- var objC = {
25
+ const objC = {
26
26
  type: "c",
27
27
  };
28
- var dSchema = index_1.z.object({
28
+ const dSchema = index_1.z.object({
29
29
  type: index_1.z.literal("d"),
30
30
  });
31
- var double = index_1.z.union([aSchema, bSchema]);
32
- var many = index_1.z.union([aSchema, bSchema, cSchema, dSchema]);
31
+ const double = index_1.z.union([aSchema, bSchema]);
32
+ const many = index_1.z.union([aSchema, bSchema, cSchema, dSchema]);
33
33
  doubleSuite
34
- .add("valid: a", function () {
34
+ .add("valid: a", () => {
35
35
  double.parse(objA);
36
36
  })
37
- .add("valid: b", function () {
37
+ .add("valid: b", () => {
38
38
  double.parse(objB);
39
39
  })
40
- .add("invalid: null", function () {
40
+ .add("invalid: null", () => {
41
41
  try {
42
42
  double.parse(null);
43
43
  }
44
44
  catch (err) { }
45
45
  })
46
- .add("invalid: wrong shape", function () {
46
+ .add("invalid: wrong shape", () => {
47
47
  try {
48
48
  double.parse(objC);
49
49
  }
50
50
  catch (err) { }
51
51
  })
52
- .on("cycle", function (e) {
53
- console.log("".concat(doubleSuite.name, ": ").concat(e.target));
52
+ .on("cycle", (e) => {
53
+ console.log(`${doubleSuite.name}: ${e.target}`);
54
54
  });
55
55
  manySuite
56
- .add("valid: a", function () {
56
+ .add("valid: a", () => {
57
57
  many.parse(objA);
58
58
  })
59
- .add("valid: c", function () {
59
+ .add("valid: c", () => {
60
60
  many.parse(objC);
61
61
  })
62
- .add("invalid: null", function () {
62
+ .add("invalid: null", () => {
63
63
  try {
64
64
  many.parse(null);
65
65
  }
66
66
  catch (err) { }
67
67
  })
68
- .add("invalid: wrong shape", function () {
68
+ .add("invalid: wrong shape", () => {
69
69
  try {
70
70
  many.parse({ type: "unknown" });
71
71
  }
72
72
  catch (err) { }
73
73
  })
74
- .on("cycle", function (e) {
75
- console.log("".concat(manySuite.name, ": ").concat(e.target));
74
+ .on("cycle", (e) => {
75
+ console.log(`${manySuite.name}: ${e.target}`);
76
76
  });
77
77
  exports.default = {
78
78
  suites: [doubleSuite, manySuite],
package/lib/external.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -3,10 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.errorUtil = void 0;
4
4
  var errorUtil;
5
5
  (function (errorUtil) {
6
- errorUtil.errToObj = function (message) {
7
- return typeof message === "string" ? { message: message } : message || {};
8
- };
9
- errorUtil.toString = function (message) {
10
- return typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
11
- };
6
+ errorUtil.errToObj = (message) => typeof message === "string" ? { message } : message || {};
7
+ errorUtil.toString = (message) => typeof message === "string" ? message : message === null || message === void 0 ? void 0 : message.message;
12
8
  })(errorUtil = exports.errorUtil || (exports.errorUtil = {}));
@@ -22,7 +22,7 @@ export declare const ZodParsedType: {
22
22
  set: "set";
23
23
  };
24
24
  export declare type ZodParsedType = keyof typeof ZodParsedType;
25
- export declare const getParsedType: (data: any, cache?: Map<any, "function" | "number" | "string" | "nan" | "integer" | "float" | "boolean" | "date" | "bigint" | "symbol" | "undefined" | "null" | "array" | "object" | "unknown" | "promise" | "void" | "never" | "map" | "set"> | undefined) => ZodParsedType;
25
+ export declare const getParsedType: (data: any) => ZodParsedType;
26
26
  export declare const makeIssue: (params: {
27
27
  data: any;
28
28
  path: (string | number)[];
@@ -44,7 +44,6 @@ export interface ParseContext {
44
44
  readonly contextualErrorMap?: ZodErrorMap;
45
45
  readonly async: boolean;
46
46
  readonly parent: ParseContext | null;
47
- readonly typeCache: Map<any, ZodParsedType> | undefined;
48
47
  readonly data: any;
49
48
  readonly parsedType: ZodParsedType;
50
49
  }