@exodus/zod 3.24.2 → 3.24.4
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.d.ts +1 -1
- package/lib/ZodError.d.ts +3 -3
- package/lib/errors.d.ts +2 -2
- package/lib/external.d.ts +6 -6
- package/lib/helpers/parseUtil.d.ts +2 -2
- package/lib/helpers/partialUtil.d.ts +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.mjs +137 -110
- package/lib/locales/en.d.ts +1 -1
- package/lib/types.d.ts +8 -8
- package/package.json +2 -1
package/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from "./lib";
|
|
1
|
+
export * from "./lib/index.js";
|
|
2
2
|
export as namespace Zod;
|
package/lib/ZodError.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Primitive } from "./helpers/typeAliases.js";
|
|
2
|
+
import { util, ZodParsedType } from "./helpers/util.js";
|
|
3
|
+
import type { TypeOf, ZodType } from "./index.js";
|
|
4
4
|
type allKeys<T> = T extends any ? keyof T : never;
|
|
5
5
|
export type inferFlattenedErrors<T extends ZodType<any, any, any>, U = string> = typeToFlattenedError<TypeOf<T>, U>;
|
|
6
6
|
export type typeToFlattenedError<T, U = string> = {
|
package/lib/errors.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import defaultErrorMap from "./locales/en";
|
|
2
|
-
import type { ZodErrorMap } from "./ZodError";
|
|
1
|
+
import defaultErrorMap from "./locales/en.js";
|
|
2
|
+
import type { ZodErrorMap } from "./ZodError.js";
|
|
3
3
|
export { defaultErrorMap };
|
|
4
4
|
export declare function setErrorMap(map: ZodErrorMap): void;
|
|
5
5
|
export declare function getErrorMap(): ZodErrorMap;
|
package/lib/external.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./errors";
|
|
2
|
-
export * from "./helpers/parseUtil";
|
|
3
|
-
export * from "./helpers/typeAliases";
|
|
4
|
-
export * from "./helpers/util";
|
|
5
|
-
export * from "./types";
|
|
6
|
-
export * from "./ZodError";
|
|
1
|
+
export * from "./errors.js";
|
|
2
|
+
export * from "./helpers/parseUtil.js";
|
|
3
|
+
export * from "./helpers/typeAliases.js";
|
|
4
|
+
export * from "./helpers/util.js";
|
|
5
|
+
export * from "./types.js";
|
|
6
|
+
export * from "./ZodError.js";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError";
|
|
2
|
-
import type { ZodParsedType } from "./util";
|
|
1
|
+
import type { IssueData, ZodErrorMap, ZodIssue } from "../ZodError.js";
|
|
2
|
+
import type { ZodParsedType } from "./util.js";
|
|
3
3
|
export declare const makeIssue: (params: {
|
|
4
4
|
data: any;
|
|
5
5
|
path: (string | number)[];
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index";
|
|
1
|
+
import type { ZodArray, ZodNullable, ZodObject, ZodOptional, ZodRawShape, ZodTuple, ZodTupleItems, ZodTypeAny } from "../index.js";
|
|
2
2
|
export declare namespace partialUtil {
|
|
3
3
|
type DeepPartial<T extends ZodTypeAny> = T extends ZodObject<ZodRawShape> ? ZodObject<{
|
|
4
4
|
[k in keyof T["shape"]]: ZodOptional<DeepPartial<T["shape"][k]>>;
|
package/lib/index.d.ts
CHANGED
package/lib/index.mjs
CHANGED
|
@@ -166,36 +166,42 @@ class ZodError extends Error {
|
|
|
166
166
|
function (issue) {
|
|
167
167
|
return issue.message;
|
|
168
168
|
};
|
|
169
|
-
const fieldErrors = { _errors: [] };
|
|
170
|
-
const processError = (
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
else if (issue.code === "invalid_arguments") {
|
|
179
|
-
processError(issue.argumentsError);
|
|
180
|
-
}
|
|
181
|
-
else if (issue.path.length === 0) {
|
|
182
|
-
fieldErrors._errors.push(mapper(issue));
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
let curr = fieldErrors;
|
|
186
|
-
let i = 0;
|
|
187
|
-
while (i < issue.path.length) {
|
|
188
|
-
const el = issue.path[i];
|
|
189
|
-
const terminal = i === issue.path.length - 1;
|
|
190
|
-
if (!terminal) {
|
|
191
|
-
curr[el] = curr[el] || { _errors: [] };
|
|
169
|
+
const fieldErrors = { __proto__: null, _errors: [] };
|
|
170
|
+
const processError = (rootError) => {
|
|
171
|
+
const stack = [rootError];
|
|
172
|
+
while (stack.length > 0) {
|
|
173
|
+
const error = stack.pop();
|
|
174
|
+
for (const issue of error.issues) {
|
|
175
|
+
if (issue.code === "invalid_union") {
|
|
176
|
+
for (const unionError of issue.unionErrors) {
|
|
177
|
+
stack.push(unionError);
|
|
192
178
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
179
|
+
}
|
|
180
|
+
else if (issue.code === "invalid_return_type") {
|
|
181
|
+
stack.push(issue.returnTypeError);
|
|
182
|
+
}
|
|
183
|
+
else if (issue.code === "invalid_arguments") {
|
|
184
|
+
stack.push(issue.argumentsError);
|
|
185
|
+
}
|
|
186
|
+
else if (issue.path.length === 0) {
|
|
187
|
+
fieldErrors._errors.push(mapper(issue));
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
let curr = fieldErrors;
|
|
191
|
+
let i = 0;
|
|
192
|
+
while (i < issue.path.length) {
|
|
193
|
+
const el = issue.path[i];
|
|
194
|
+
const terminal = i === issue.path.length - 1;
|
|
195
|
+
if (!terminal) {
|
|
196
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
curr[el] = curr[el] || { _errors: [] };
|
|
200
|
+
curr[el]._errors.push(mapper(issue));
|
|
201
|
+
}
|
|
202
|
+
curr = curr[el];
|
|
203
|
+
i++;
|
|
196
204
|
}
|
|
197
|
-
curr = curr[el];
|
|
198
|
-
i++;
|
|
199
205
|
}
|
|
200
206
|
}
|
|
201
207
|
}
|
|
@@ -2677,48 +2683,53 @@ class ZodUnion extends ZodType {
|
|
|
2677
2683
|
};
|
|
2678
2684
|
}
|
|
2679
2685
|
const getDiscriminator = (type) => {
|
|
2680
|
-
|
|
2681
|
-
|
|
2682
|
-
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2687
|
-
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2686
|
+
const result = [];
|
|
2687
|
+
const stack = [type];
|
|
2688
|
+
while (stack.length > 0) {
|
|
2689
|
+
const current = stack.pop();
|
|
2690
|
+
if (current instanceof ZodLazy) {
|
|
2691
|
+
stack.push(current.schema);
|
|
2692
|
+
}
|
|
2693
|
+
else if (current instanceof ZodEffects) {
|
|
2694
|
+
stack.push(current.innerType());
|
|
2695
|
+
}
|
|
2696
|
+
else if (current instanceof ZodLiteral) {
|
|
2697
|
+
result.push(current.value);
|
|
2698
|
+
}
|
|
2699
|
+
else if (current instanceof ZodEnum) {
|
|
2700
|
+
result.push(...current.options);
|
|
2701
|
+
}
|
|
2702
|
+
else if (current instanceof ZodNativeEnum) {
|
|
2703
|
+
result.push(...util.objectValues(current.enum));
|
|
2704
|
+
}
|
|
2705
|
+
else if (current instanceof ZodDefault) {
|
|
2706
|
+
stack.push(current._def.innerType);
|
|
2707
|
+
}
|
|
2708
|
+
else if (current instanceof ZodUndefined) {
|
|
2709
|
+
result.push(undefined);
|
|
2710
|
+
}
|
|
2711
|
+
else if (current instanceof ZodNull) {
|
|
2712
|
+
result.push(null);
|
|
2713
|
+
}
|
|
2714
|
+
else if (current instanceof ZodOptional) {
|
|
2715
|
+
result.push(undefined);
|
|
2716
|
+
stack.push(current.unwrap());
|
|
2717
|
+
}
|
|
2718
|
+
else if (current instanceof ZodNullable) {
|
|
2719
|
+
result.push(null);
|
|
2720
|
+
stack.push(current.unwrap());
|
|
2721
|
+
}
|
|
2722
|
+
else if (current instanceof ZodBranded) {
|
|
2723
|
+
stack.push(current.unwrap());
|
|
2724
|
+
}
|
|
2725
|
+
else if (current instanceof ZodReadonly) {
|
|
2726
|
+
stack.push(current.unwrap());
|
|
2727
|
+
}
|
|
2728
|
+
else if (current instanceof ZodCatch) {
|
|
2729
|
+
stack.push(current._def.innerType);
|
|
2730
|
+
}
|
|
2721
2731
|
}
|
|
2732
|
+
return result;
|
|
2722
2733
|
};
|
|
2723
2734
|
class ZodDiscriminatedUnion extends ZodType {
|
|
2724
2735
|
_parse(input) {
|
|
@@ -2790,50 +2801,66 @@ class ZodDiscriminatedUnion extends ZodType {
|
|
|
2790
2801
|
}
|
|
2791
2802
|
}
|
|
2792
2803
|
function mergeValues(a, b) {
|
|
2793
|
-
const
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
const
|
|
2800
|
-
const
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
|
|
2822
|
-
|
|
2823
|
-
|
|
2824
|
-
|
|
2825
|
-
|
|
2826
|
-
|
|
2827
|
-
|
|
2828
|
-
|
|
2829
|
-
|
|
2830
|
-
|
|
2831
|
-
|
|
2832
|
-
|
|
2804
|
+
const root = { _data: undefined };
|
|
2805
|
+
let valid = true;
|
|
2806
|
+
const stack = [
|
|
2807
|
+
{ a, b, parent: root, key: "_data" },
|
|
2808
|
+
];
|
|
2809
|
+
while (stack.length > 0 && valid) {
|
|
2810
|
+
const { a, b, parent, key } = stack.pop();
|
|
2811
|
+
const aType = getParsedType(a);
|
|
2812
|
+
const bType = getParsedType(b);
|
|
2813
|
+
if (a === b) {
|
|
2814
|
+
parent[key] = a;
|
|
2815
|
+
continue;
|
|
2816
|
+
}
|
|
2817
|
+
if (aType === ZodParsedType.object && bType === ZodParsedType.object) {
|
|
2818
|
+
const bKeys = util.objectKeys(b);
|
|
2819
|
+
const sharedKeys = util
|
|
2820
|
+
.objectKeys(a)
|
|
2821
|
+
.filter((k) => bKeys.indexOf(k) !== -1);
|
|
2822
|
+
const newObj = { __proto__: null, ...a, ...b };
|
|
2823
|
+
parent[key] = newObj;
|
|
2824
|
+
for (const sharedKey of sharedKeys) {
|
|
2825
|
+
stack.push({
|
|
2826
|
+
a: a[sharedKey],
|
|
2827
|
+
b: b[sharedKey],
|
|
2828
|
+
parent: newObj,
|
|
2829
|
+
key: sharedKey,
|
|
2830
|
+
});
|
|
2831
|
+
}
|
|
2832
|
+
continue;
|
|
2833
|
+
}
|
|
2834
|
+
if (aType === ZodParsedType.array && bType === ZodParsedType.array) {
|
|
2835
|
+
if (a.length !== b.length) {
|
|
2836
|
+
valid = false;
|
|
2837
|
+
break;
|
|
2838
|
+
}
|
|
2839
|
+
const newArray = [];
|
|
2840
|
+
parent[key] = newArray;
|
|
2841
|
+
for (let i = 0; i < a.length; i++) {
|
|
2842
|
+
newArray[i] = undefined;
|
|
2843
|
+
stack.push({
|
|
2844
|
+
a: a[i],
|
|
2845
|
+
b: b[i],
|
|
2846
|
+
parent: newArray,
|
|
2847
|
+
key: i,
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
continue;
|
|
2851
|
+
}
|
|
2852
|
+
if (aType === ZodParsedType.date &&
|
|
2853
|
+
bType === ZodParsedType.date &&
|
|
2854
|
+
+a === +b) {
|
|
2855
|
+
parent[key] = a;
|
|
2856
|
+
continue;
|
|
2857
|
+
}
|
|
2858
|
+
valid = false;
|
|
2833
2859
|
}
|
|
2834
|
-
|
|
2860
|
+
if (!valid) {
|
|
2835
2861
|
return { valid: false };
|
|
2836
2862
|
}
|
|
2863
|
+
return { valid: true, data: root._data };
|
|
2837
2864
|
}
|
|
2838
2865
|
class ZodIntersection extends ZodType {
|
|
2839
2866
|
_parse(input) {
|
package/lib/locales/en.d.ts
CHANGED
package/lib/types.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { enumUtil } from "./helpers/enumUtil";
|
|
2
|
-
import { errorUtil } from "./helpers/errorUtil";
|
|
3
|
-
import { AsyncParseReturnType, INVALID, ParseContext, ParseInput, ParseParams, ParseReturnType, ParseStatus, SyncParseReturnType } from "./helpers/parseUtil";
|
|
4
|
-
import { partialUtil } from "./helpers/partialUtil";
|
|
5
|
-
import { Primitive } from "./helpers/typeAliases";
|
|
6
|
-
import { objectUtil, util } from "./helpers/util";
|
|
7
|
-
import type { StandardSchemaV1 } from "./standard-schema";
|
|
8
|
-
import { IssueData, StringValidation, ZodCustomIssue, ZodError, ZodErrorMap } from "./ZodError";
|
|
1
|
+
import { enumUtil } from "./helpers/enumUtil.js";
|
|
2
|
+
import { errorUtil } from "./helpers/errorUtil.js";
|
|
3
|
+
import { AsyncParseReturnType, INVALID, ParseContext, ParseInput, ParseParams, ParseReturnType, ParseStatus, SyncParseReturnType } from "./helpers/parseUtil.js";
|
|
4
|
+
import { partialUtil } from "./helpers/partialUtil.js";
|
|
5
|
+
import { Primitive } from "./helpers/typeAliases.js";
|
|
6
|
+
import { objectUtil, util } from "./helpers/util.js";
|
|
7
|
+
import type { StandardSchemaV1 } from "./standard-schema.js";
|
|
8
|
+
import { IssueData, StringValidation, ZodCustomIssue, ZodError, ZodErrorMap } from "./ZodError.js";
|
|
9
9
|
export interface RefinementCtx {
|
|
10
10
|
addIssue: (arg: IssueData) => void;
|
|
11
11
|
path: (string | number)[];
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/zod",
|
|
3
|
-
"version": "3.24.
|
|
3
|
+
"version": "3.24.4",
|
|
4
4
|
"author": "Exodus Movement, Inc.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/ExodusMovement/zod.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
+
"main": "./lib/index.mjs",
|
|
10
11
|
"module": "./lib/index.mjs",
|
|
11
12
|
"devDependencies": {
|
|
12
13
|
"@babel/core": "^7.22.5",
|