zod 3.25.0-canary.20250211T214501 → 4.0.0-beta.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.
Files changed (97) hide show
  1. package/dist/commonjs/checks.d.ts +1 -0
  2. package/dist/commonjs/checks.js +32 -0
  3. package/dist/commonjs/coerce.d.ts +17 -0
  4. package/dist/commonjs/coerce.js +57 -0
  5. package/dist/commonjs/compat.d.ts +47 -0
  6. package/dist/commonjs/compat.js +73 -0
  7. package/dist/commonjs/errors.d.ts +23 -0
  8. package/dist/commonjs/errors.js +57 -0
  9. package/dist/commonjs/external.d.ts +8 -0
  10. package/dist/commonjs/external.js +67 -0
  11. package/dist/commonjs/index.d.ts +4 -0
  12. package/{lib → dist/commonjs}/index.js +19 -9
  13. package/dist/commonjs/iso.d.ts +22 -0
  14. package/dist/commonjs/iso.js +70 -0
  15. package/dist/commonjs/package.json +3 -0
  16. package/dist/commonjs/parse.d.ts +17 -0
  17. package/dist/commonjs/parse.js +44 -0
  18. package/dist/commonjs/schemas.d.ts +738 -0
  19. package/dist/commonjs/schemas.js +1171 -0
  20. package/dist/esm/checks.d.ts +1 -0
  21. package/dist/esm/checks.js +1 -0
  22. package/dist/esm/coerce.d.ts +17 -0
  23. package/dist/esm/coerce.js +17 -0
  24. package/dist/esm/compat.d.ts +47 -0
  25. package/dist/esm/compat.js +33 -0
  26. package/dist/esm/errors.d.ts +23 -0
  27. package/dist/esm/errors.js +20 -0
  28. package/dist/esm/external.d.ts +8 -0
  29. package/dist/esm/external.js +11 -0
  30. package/dist/esm/index.d.ts +4 -0
  31. package/dist/esm/index.js +4 -0
  32. package/dist/esm/iso.d.ts +22 -0
  33. package/dist/esm/iso.js +30 -0
  34. package/dist/esm/package.json +3 -0
  35. package/dist/esm/parse.d.ts +17 -0
  36. package/dist/esm/parse.js +8 -0
  37. package/dist/esm/schemas.d.ts +738 -0
  38. package/dist/esm/schemas.js +1057 -0
  39. package/package.json +59 -99
  40. package/src/checks.ts +30 -0
  41. package/src/coerce.ts +27 -0
  42. package/src/compat.ts +74 -0
  43. package/src/errors.ts +47 -0
  44. package/src/external.ts +29 -0
  45. package/src/index.ts +5 -0
  46. package/src/iso.ts +90 -0
  47. package/src/parse.ts +32 -0
  48. package/src/schemas.ts +2324 -0
  49. package/README.md +0 -3074
  50. package/index.d.ts +0 -2
  51. package/lib/ZodError.d.ts +0 -164
  52. package/lib/ZodError.js +0 -137
  53. package/lib/__tests__/Mocker.d.ts +0 -17
  54. package/lib/__tests__/Mocker.js +0 -57
  55. package/lib/benchmarks/datetime.d.ts +0 -5
  56. package/lib/benchmarks/datetime.js +0 -54
  57. package/lib/benchmarks/discriminatedUnion.d.ts +0 -5
  58. package/lib/benchmarks/discriminatedUnion.js +0 -79
  59. package/lib/benchmarks/index.d.ts +0 -1
  60. package/lib/benchmarks/index.js +0 -59
  61. package/lib/benchmarks/ipv4.d.ts +0 -5
  62. package/lib/benchmarks/ipv4.js +0 -54
  63. package/lib/benchmarks/object.d.ts +0 -5
  64. package/lib/benchmarks/object.js +0 -70
  65. package/lib/benchmarks/primitives.d.ts +0 -5
  66. package/lib/benchmarks/primitives.js +0 -170
  67. package/lib/benchmarks/realworld.d.ts +0 -5
  68. package/lib/benchmarks/realworld.js +0 -56
  69. package/lib/benchmarks/string.d.ts +0 -5
  70. package/lib/benchmarks/string.js +0 -55
  71. package/lib/benchmarks/union.d.ts +0 -5
  72. package/lib/benchmarks/union.js +0 -79
  73. package/lib/errors.d.ts +0 -5
  74. package/lib/errors.js +0 -17
  75. package/lib/external.d.ts +0 -6
  76. package/lib/external.js +0 -22
  77. package/lib/helpers/enumUtil.d.ts +0 -8
  78. package/lib/helpers/enumUtil.js +0 -2
  79. package/lib/helpers/errorUtil.d.ts +0 -9
  80. package/lib/helpers/errorUtil.js +0 -8
  81. package/lib/helpers/parseUtil.d.ts +0 -78
  82. package/lib/helpers/parseUtil.js +0 -125
  83. package/lib/helpers/partialUtil.d.ts +0 -8
  84. package/lib/helpers/partialUtil.js +0 -2
  85. package/lib/helpers/typeAliases.d.ts +0 -2
  86. package/lib/helpers/typeAliases.js +0 -2
  87. package/lib/helpers/util.d.ts +0 -82
  88. package/lib/helpers/util.js +0 -142
  89. package/lib/index.d.ts +0 -4
  90. package/lib/index.mjs +0 -4405
  91. package/lib/index.umd.js +0 -4520
  92. package/lib/locales/en.d.ts +0 -3
  93. package/lib/locales/en.js +0 -129
  94. package/lib/standard-schema.d.ts +0 -102
  95. package/lib/standard-schema.js +0 -2
  96. package/lib/types.d.ts +0 -1062
  97. package/lib/types.js +0 -3846
@@ -1,3 +0,0 @@
1
- import { ZodErrorMap } from "../ZodError";
2
- declare const errorMap: ZodErrorMap;
3
- export default errorMap;
package/lib/locales/en.js DELETED
@@ -1,129 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const util_1 = require("../helpers/util");
4
- const ZodError_1 = require("../ZodError");
5
- const errorMap = (issue, _ctx) => {
6
- let message;
7
- switch (issue.code) {
8
- case ZodError_1.ZodIssueCode.invalid_type:
9
- if (issue.received === util_1.ZodParsedType.undefined) {
10
- message = "Required";
11
- }
12
- else {
13
- message = `Expected ${issue.expected}, received ${issue.received}`;
14
- }
15
- break;
16
- case ZodError_1.ZodIssueCode.invalid_literal:
17
- message = `Invalid literal value, expected ${JSON.stringify(issue.expected, util_1.util.jsonStringifyReplacer)}`;
18
- break;
19
- case ZodError_1.ZodIssueCode.unrecognized_keys:
20
- message = `Unrecognized key(s) in object: ${util_1.util.joinValues(issue.keys, ", ")}`;
21
- break;
22
- case ZodError_1.ZodIssueCode.invalid_union:
23
- message = `Invalid input`;
24
- break;
25
- case ZodError_1.ZodIssueCode.invalid_union_discriminator:
26
- message = `Invalid discriminator value. Expected ${util_1.util.joinValues(issue.options)}`;
27
- break;
28
- case ZodError_1.ZodIssueCode.invalid_enum_value:
29
- message = `Invalid enum value. Expected ${util_1.util.joinValues(issue.options)}, received '${issue.received}'`;
30
- break;
31
- case ZodError_1.ZodIssueCode.invalid_arguments:
32
- message = `Invalid function arguments`;
33
- break;
34
- case ZodError_1.ZodIssueCode.invalid_return_type:
35
- message = `Invalid function return type`;
36
- break;
37
- case ZodError_1.ZodIssueCode.invalid_date:
38
- message = `Invalid date`;
39
- break;
40
- case ZodError_1.ZodIssueCode.invalid_string:
41
- if (typeof issue.validation === "object") {
42
- if ("includes" in issue.validation) {
43
- message = `Invalid input: must include "${issue.validation.includes}"`;
44
- if (typeof issue.validation.position === "number") {
45
- message = `${message} at one or more positions greater than or equal to ${issue.validation.position}`;
46
- }
47
- }
48
- else if ("startsWith" in issue.validation) {
49
- message = `Invalid input: must start with "${issue.validation.startsWith}"`;
50
- }
51
- else if ("endsWith" in issue.validation) {
52
- message = `Invalid input: must end with "${issue.validation.endsWith}"`;
53
- }
54
- else {
55
- util_1.util.assertNever(issue.validation);
56
- }
57
- }
58
- else if (issue.validation !== "regex") {
59
- message = `Invalid ${issue.validation}`;
60
- }
61
- else {
62
- message = "Invalid";
63
- }
64
- break;
65
- case ZodError_1.ZodIssueCode.too_small:
66
- if (issue.type === "array")
67
- message = `Array must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `more than`} ${issue.minimum} element(s)`;
68
- else if (issue.type === "string")
69
- message = `String must contain ${issue.exact ? "exactly" : issue.inclusive ? `at least` : `over`} ${issue.minimum} character(s)`;
70
- else if (issue.type === "number")
71
- message = `Number must be ${issue.exact
72
- ? `exactly equal to `
73
- : issue.inclusive
74
- ? `greater than or equal to `
75
- : `greater than `}${issue.minimum}`;
76
- else if (issue.type === "date")
77
- message = `Date must be ${issue.exact
78
- ? `exactly equal to `
79
- : issue.inclusive
80
- ? `greater than or equal to `
81
- : `greater than `}${new Date(Number(issue.minimum))}`;
82
- else
83
- message = "Invalid input";
84
- break;
85
- case ZodError_1.ZodIssueCode.too_big:
86
- if (issue.type === "array")
87
- message = `Array must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `less than`} ${issue.maximum} element(s)`;
88
- else if (issue.type === "string")
89
- message = `String must contain ${issue.exact ? `exactly` : issue.inclusive ? `at most` : `under`} ${issue.maximum} character(s)`;
90
- else if (issue.type === "number")
91
- message = `Number must be ${issue.exact
92
- ? `exactly`
93
- : issue.inclusive
94
- ? `less than or equal to`
95
- : `less than`} ${issue.maximum}`;
96
- else if (issue.type === "bigint")
97
- message = `BigInt must be ${issue.exact
98
- ? `exactly`
99
- : issue.inclusive
100
- ? `less than or equal to`
101
- : `less than`} ${issue.maximum}`;
102
- else if (issue.type === "date")
103
- message = `Date must be ${issue.exact
104
- ? `exactly`
105
- : issue.inclusive
106
- ? `smaller than or equal to`
107
- : `smaller than`} ${new Date(Number(issue.maximum))}`;
108
- else
109
- message = "Invalid input";
110
- break;
111
- case ZodError_1.ZodIssueCode.custom:
112
- message = `Invalid input`;
113
- break;
114
- case ZodError_1.ZodIssueCode.invalid_intersection_types:
115
- message = `Intersection results could not be merged`;
116
- break;
117
- case ZodError_1.ZodIssueCode.not_multiple_of:
118
- message = `Number must be a multiple of ${issue.multipleOf}`;
119
- break;
120
- case ZodError_1.ZodIssueCode.not_finite:
121
- message = "Number must be finite";
122
- break;
123
- default:
124
- message = _ctx.defaultError;
125
- util_1.util.assertNever(issue);
126
- }
127
- return { message };
128
- };
129
- exports.default = errorMap;
@@ -1,102 +0,0 @@
1
- /**
2
- * The Standard Schema interface.
3
- */
4
- export type StandardSchemaV1<Input = unknown, Output = Input> = {
5
- /**
6
- * The Standard Schema properties.
7
- */
8
- readonly "~standard": StandardSchemaV1.Props<Input, Output>;
9
- };
10
- export declare namespace StandardSchemaV1 {
11
- /**
12
- * The Standard Schema properties interface.
13
- */
14
- export interface Props<Input = unknown, Output = Input> {
15
- /**
16
- * The version number of the standard.
17
- */
18
- readonly version: 1;
19
- /**
20
- * The vendor name of the schema library.
21
- */
22
- readonly vendor: string;
23
- /**
24
- * Validates unknown input values.
25
- */
26
- readonly validate: (value: unknown) => Result<Output> | Promise<Result<Output>>;
27
- /**
28
- * Inferred types associated with the schema.
29
- */
30
- readonly types?: Types<Input, Output> | undefined;
31
- }
32
- /**
33
- * The result interface of the validate function.
34
- */
35
- export type Result<Output> = SuccessResult<Output> | FailureResult;
36
- /**
37
- * The result interface if validation succeeds.
38
- */
39
- export interface SuccessResult<Output> {
40
- /**
41
- * The typed output value.
42
- */
43
- readonly value: Output;
44
- /**
45
- * The non-existent issues.
46
- */
47
- readonly issues?: undefined;
48
- }
49
- /**
50
- * The result interface if validation fails.
51
- */
52
- export interface FailureResult {
53
- /**
54
- * The issues of failed validation.
55
- */
56
- readonly issues: ReadonlyArray<Issue>;
57
- }
58
- /**
59
- * The issue interface of the failure output.
60
- */
61
- export interface Issue {
62
- /**
63
- * The error message of the issue.
64
- */
65
- readonly message: string;
66
- /**
67
- * The path of the issue, if any.
68
- */
69
- readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
70
- }
71
- /**
72
- * The path segment interface of the issue.
73
- */
74
- export interface PathSegment {
75
- /**
76
- * The key representing a path segment.
77
- */
78
- readonly key: PropertyKey;
79
- }
80
- /**
81
- * The Standard Schema types interface.
82
- */
83
- export interface Types<Input = unknown, Output = Input> {
84
- /**
85
- * The input type of the schema.
86
- */
87
- readonly input: Input;
88
- /**
89
- * The output type of the schema.
90
- */
91
- readonly output: Output;
92
- }
93
- /**
94
- * Infers the input type of a Standard Schema.
95
- */
96
- export type InferInput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["input"];
97
- /**
98
- * Infers the output type of a Standard Schema.
99
- */
100
- export type InferOutput<Schema extends StandardSchemaV1> = NonNullable<Schema["~standard"]["types"]>["output"];
101
- export {};
102
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });