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,125 +0,0 @@
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
- exports.isAsync = exports.isValid = exports.isDirty = exports.isAborted = exports.OK = exports.DIRTY = exports.INVALID = exports.ParseStatus = exports.addIssueToContext = exports.EMPTY_PATH = exports.makeIssue = void 0;
7
- const errors_1 = require("../errors");
8
- const en_1 = __importDefault(require("../locales/en"));
9
- const makeIssue = (params) => {
10
- const { data, path, errorMaps, issueData } = params;
11
- const fullPath = [...path, ...(issueData.path || [])];
12
- const fullIssue = {
13
- ...issueData,
14
- path: fullPath,
15
- };
16
- if (issueData.message !== undefined) {
17
- return {
18
- ...issueData,
19
- path: fullPath,
20
- message: issueData.message,
21
- };
22
- }
23
- let errorMessage = "";
24
- const maps = errorMaps
25
- .filter((m) => !!m)
26
- .slice()
27
- .reverse();
28
- for (const map of maps) {
29
- errorMessage = map(fullIssue, { data, defaultError: errorMessage }).message;
30
- }
31
- return {
32
- ...issueData,
33
- path: fullPath,
34
- message: errorMessage,
35
- };
36
- };
37
- exports.makeIssue = makeIssue;
38
- exports.EMPTY_PATH = [];
39
- function addIssueToContext(ctx, issueData) {
40
- const overrideMap = (0, errors_1.getErrorMap)();
41
- const issue = (0, exports.makeIssue)({
42
- issueData: issueData,
43
- data: ctx.data,
44
- path: ctx.path,
45
- errorMaps: [
46
- ctx.common.contextualErrorMap, // contextual error map is first priority
47
- ctx.schemaErrorMap, // then schema-bound map if available
48
- overrideMap, // then global override map
49
- overrideMap === en_1.default ? undefined : en_1.default, // then global default map
50
- ].filter((x) => !!x),
51
- });
52
- ctx.common.issues.push(issue);
53
- }
54
- exports.addIssueToContext = addIssueToContext;
55
- class ParseStatus {
56
- constructor() {
57
- this.value = "valid";
58
- }
59
- dirty() {
60
- if (this.value === "valid")
61
- this.value = "dirty";
62
- }
63
- abort() {
64
- if (this.value !== "aborted")
65
- this.value = "aborted";
66
- }
67
- static mergeArray(status, results) {
68
- const arrayValue = [];
69
- for (const s of results) {
70
- if (s.status === "aborted")
71
- return exports.INVALID;
72
- if (s.status === "dirty")
73
- status.dirty();
74
- arrayValue.push(s.value);
75
- }
76
- return { status: status.value, value: arrayValue };
77
- }
78
- static async mergeObjectAsync(status, pairs) {
79
- const syncPairs = [];
80
- for (const pair of pairs) {
81
- const key = await pair.key;
82
- const value = await pair.value;
83
- syncPairs.push({
84
- key,
85
- value,
86
- });
87
- }
88
- return ParseStatus.mergeObjectSync(status, syncPairs);
89
- }
90
- static mergeObjectSync(status, pairs) {
91
- const finalObject = {};
92
- for (const pair of pairs) {
93
- const { key, value } = pair;
94
- if (key.status === "aborted")
95
- return exports.INVALID;
96
- if (value.status === "aborted")
97
- return exports.INVALID;
98
- if (key.status === "dirty")
99
- status.dirty();
100
- if (value.status === "dirty")
101
- status.dirty();
102
- if (key.value !== "__proto__" &&
103
- (typeof value.value !== "undefined" || pair.alwaysSet)) {
104
- finalObject[key.value] = value.value;
105
- }
106
- }
107
- return { status: status.value, value: finalObject };
108
- }
109
- }
110
- exports.ParseStatus = ParseStatus;
111
- exports.INVALID = Object.freeze({
112
- status: "aborted",
113
- });
114
- const DIRTY = (value) => ({ status: "dirty", value });
115
- exports.DIRTY = DIRTY;
116
- const OK = (value) => ({ status: "valid", value });
117
- exports.OK = OK;
118
- const isAborted = (x) => x.status === "aborted";
119
- exports.isAborted = isAborted;
120
- const isDirty = (x) => x.status === "dirty";
121
- exports.isDirty = isDirty;
122
- const isValid = (x) => x.status === "valid";
123
- exports.isValid = isValid;
124
- const isAsync = (x) => typeof Promise !== "undefined" && x instanceof Promise;
125
- exports.isAsync = isAsync;
@@ -1,8 +0,0 @@
1
- import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index";
2
- export declare namespace partialUtil {
3
- type DeepPartial<T extends ZodTypeAny> = T extends ZodObject<ZodRawShape> ? ZodObject<{
4
- [k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>>;
5
- }, T["_def"]["unknownKeys"], T["_def"]["catchall"]> : T extends ZodArray<infer Type, infer Card> ? ZodArray<DeepPartial<Type>, Card> : T extends ZodOptional<infer Type> ? ZodOptional<DeepPartial<Type>> : T extends ZodNullable<infer Type> ? ZodNullable<DeepPartial<Type>> : T extends ZodTuple<infer Items> ? {
6
- [k in keyof Items]: Items[k] extends ZodTypeAny ? DeepPartial<Items[k]> : never;
7
- } extends infer PI ? PI extends ZodTupleItems ? ZodTuple<PI> : never : never : T;
8
- }
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,2 +0,0 @@
1
- export type Primitive = string | number | symbol | bigint | boolean | null | undefined;
2
- export type Scalars = Primitive | Primitive[];
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,82 +0,0 @@
1
- export declare namespace util {
2
- type AssertEqual<T, U> = (<V>() => V extends T ? 1 : 2) extends <V>() => V extends U ? 1 : 2 ? true : false;
3
- export type isAny<T> = 0 extends 1 & T ? true : false;
4
- export const assertEqual: <A, B>(val: AssertEqual<A, B>) => AssertEqual<A, B>;
5
- export function assertIs<T>(_arg: T): void;
6
- export function assertNever(_x: never): never;
7
- export type Omit<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
8
- export type OmitKeys<T, K extends string> = Pick<T, Exclude<keyof T, K>>;
9
- export type MakePartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
10
- export type Exactly<T, X> = T & Record<Exclude<keyof X, keyof T>, never>;
11
- export const arrayToEnum: <T extends string, U extends [T, ...T[]]>(items: U) => { [k in U[number]]: k; };
12
- export const getValidEnumValues: (obj: any) => any[];
13
- export const objectValues: (obj: any) => any[];
14
- export const objectKeys: ObjectConstructor["keys"];
15
- export const find: <T>(arr: T[], checker: (arg: T) => any) => T | undefined;
16
- export type identity<T> = objectUtil.identity<T>;
17
- export type flatten<T> = objectUtil.flatten<T>;
18
- export type noUndefined<T> = T extends undefined ? never : T;
19
- export const isInteger: NumberConstructor["isInteger"];
20
- export function joinValues<T extends any[]>(array: T, separator?: string): string;
21
- export const jsonStringifyReplacer: (_: string, value: any) => any;
22
- export {};
23
- }
24
- export declare namespace objectUtil {
25
- export type MergeShapes<U, V> = {
26
- [k in Exclude<keyof U, keyof V>]: U[k];
27
- } & V;
28
- type optionalKeys<T extends object> = {
29
- [k in keyof T]: undefined extends T[k] ? k : never;
30
- }[keyof T];
31
- type requiredKeys<T extends object> = {
32
- [k in keyof T]: undefined extends T[k] ? never : k;
33
- }[keyof T];
34
- export type addQuestionMarks<T extends object, _O = any> = {
35
- [K in requiredKeys<T>]: T[K];
36
- } & {
37
- [K in optionalKeys<T>]?: T[K];
38
- } & {
39
- [k in keyof T]?: unknown;
40
- };
41
- export type identity<T> = T;
42
- export type flatten<T> = identity<{
43
- [k in keyof T]: T[k];
44
- }>;
45
- export type noNeverKeys<T> = {
46
- [k in keyof T]: [T[k]] extends [never] ? never : k;
47
- }[keyof T];
48
- export type noNever<T> = identity<{
49
- [k in noNeverKeys<T>]: k extends keyof T ? T[k] : never;
50
- }>;
51
- export const mergeShapes: <U, T>(first: U, second: T) => T & U;
52
- export type extendShape<A extends object, B extends object> = {
53
- [K in keyof A as K extends keyof B ? never : K]: A[K];
54
- } & {
55
- [K in keyof B]: B[K];
56
- };
57
- export {};
58
- }
59
- export declare const ZodParsedType: {
60
- string: "string";
61
- number: "number";
62
- bigint: "bigint";
63
- boolean: "boolean";
64
- symbol: "symbol";
65
- undefined: "undefined";
66
- object: "object";
67
- function: "function";
68
- map: "map";
69
- nan: "nan";
70
- integer: "integer";
71
- float: "float";
72
- date: "date";
73
- null: "null";
74
- array: "array";
75
- unknown: "unknown";
76
- promise: "promise";
77
- void: "void";
78
- never: "never";
79
- set: "set";
80
- };
81
- export type ZodParsedType = keyof typeof ZodParsedType;
82
- export declare const getParsedType: (data: any) => ZodParsedType;
@@ -1,142 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getParsedType = exports.ZodParsedType = exports.objectUtil = exports.util = void 0;
4
- var util;
5
- (function (util) {
6
- util.assertEqual = (val) => val;
7
- function assertIs(_arg) { }
8
- util.assertIs = assertIs;
9
- function assertNever(_x) {
10
- throw new Error();
11
- }
12
- util.assertNever = assertNever;
13
- util.arrayToEnum = (items) => {
14
- const obj = {};
15
- for (const item of items) {
16
- obj[item] = item;
17
- }
18
- return obj;
19
- };
20
- util.getValidEnumValues = (obj) => {
21
- const validKeys = util.objectKeys(obj).filter((k) => typeof obj[obj[k]] !== "number");
22
- const filtered = {};
23
- for (const k of validKeys) {
24
- filtered[k] = obj[k];
25
- }
26
- return util.objectValues(filtered);
27
- };
28
- util.objectValues = (obj) => {
29
- return util.objectKeys(obj).map(function (e) {
30
- return obj[e];
31
- });
32
- };
33
- util.objectKeys = typeof Object.keys === "function" // eslint-disable-line ban/ban
34
- ? (obj) => Object.keys(obj) // eslint-disable-line ban/ban
35
- : (object) => {
36
- const keys = [];
37
- for (const key in object) {
38
- if (Object.prototype.hasOwnProperty.call(object, key)) {
39
- keys.push(key);
40
- }
41
- }
42
- return keys;
43
- };
44
- util.find = (arr, checker) => {
45
- for (const item of arr) {
46
- if (checker(item))
47
- return item;
48
- }
49
- return undefined;
50
- };
51
- util.isInteger = typeof Number.isInteger === "function"
52
- ? (val) => Number.isInteger(val) // eslint-disable-line ban/ban
53
- : (val) => typeof val === "number" && isFinite(val) && Math.floor(val) === val;
54
- function joinValues(array, separator = " | ") {
55
- return array
56
- .map((val) => (typeof val === "string" ? `'${val}'` : val))
57
- .join(separator);
58
- }
59
- util.joinValues = joinValues;
60
- util.jsonStringifyReplacer = (_, value) => {
61
- if (typeof value === "bigint") {
62
- return value.toString();
63
- }
64
- return value;
65
- };
66
- })(util || (exports.util = util = {}));
67
- var objectUtil;
68
- (function (objectUtil) {
69
- objectUtil.mergeShapes = (first, second) => {
70
- return {
71
- ...first,
72
- ...second, // second overwrites first
73
- };
74
- };
75
- })(objectUtil || (exports.objectUtil = objectUtil = {}));
76
- exports.ZodParsedType = util.arrayToEnum([
77
- "string",
78
- "nan",
79
- "number",
80
- "integer",
81
- "float",
82
- "boolean",
83
- "date",
84
- "bigint",
85
- "symbol",
86
- "function",
87
- "undefined",
88
- "null",
89
- "array",
90
- "object",
91
- "unknown",
92
- "promise",
93
- "void",
94
- "never",
95
- "map",
96
- "set",
97
- ]);
98
- const getParsedType = (data) => {
99
- const t = typeof data;
100
- switch (t) {
101
- case "undefined":
102
- return exports.ZodParsedType.undefined;
103
- case "string":
104
- return exports.ZodParsedType.string;
105
- case "number":
106
- return isNaN(data) ? exports.ZodParsedType.nan : exports.ZodParsedType.number;
107
- case "boolean":
108
- return exports.ZodParsedType.boolean;
109
- case "function":
110
- return exports.ZodParsedType.function;
111
- case "bigint":
112
- return exports.ZodParsedType.bigint;
113
- case "symbol":
114
- return exports.ZodParsedType.symbol;
115
- case "object":
116
- if (Array.isArray(data)) {
117
- return exports.ZodParsedType.array;
118
- }
119
- if (data === null) {
120
- return exports.ZodParsedType.null;
121
- }
122
- if (data.then &&
123
- typeof data.then === "function" &&
124
- data.catch &&
125
- typeof data.catch === "function") {
126
- return exports.ZodParsedType.promise;
127
- }
128
- if (typeof Map !== "undefined" && data instanceof Map) {
129
- return exports.ZodParsedType.map;
130
- }
131
- if (typeof Set !== "undefined" && data instanceof Set) {
132
- return exports.ZodParsedType.set;
133
- }
134
- if (typeof Date !== "undefined" && data instanceof Date) {
135
- return exports.ZodParsedType.date;
136
- }
137
- return exports.ZodParsedType.object;
138
- default:
139
- return exports.ZodParsedType.unknown;
140
- }
141
- };
142
- exports.getParsedType = getParsedType;
package/lib/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import * as z from "./external";
2
- export * from "./external";
3
- export { z };
4
- export default z;