@ptolemy2002/zod-utils 1.5.0 → 1.6.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.
- package/dist/function.d.ts +3 -2
- package/dist/interpret.d.ts +5 -4
- package/dist/interpret.js +11 -2
- package/dist/issuePathStartsWith.d.ts +2 -1
- package/dist/prefixIssuePath.d.ts +2 -2
- package/dist/types.d.ts +2 -0
- package/package.json +1 -1
package/dist/function.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import z, { ZodArray, ZodType, ZodUnknown } from "zod";
|
|
2
2
|
import { $ZodFunctionArgs, $ZodFunctionOut } from "zod/v4/core";
|
|
3
|
+
import { ZodPath } from "./types";
|
|
3
4
|
export type TrialErrorMode = "allow" | "forbid" | "require" | ((e: unknown) => boolean) | {
|
|
4
5
|
require: (e: unknown) => boolean;
|
|
5
6
|
};
|
|
@@ -13,8 +14,8 @@ export type FunctionTrial<Input extends unknown[]> = {
|
|
|
13
14
|
export type ZodFunctionParseOptions<In extends $ZodFunctionArgs, Out extends $ZodFunctionOut> = {
|
|
14
15
|
input?: In;
|
|
15
16
|
output?: Out;
|
|
16
|
-
inputPath?:
|
|
17
|
-
outputPath?:
|
|
17
|
+
inputPath?: ZodPath;
|
|
18
|
+
outputPath?: ZodPath;
|
|
18
19
|
};
|
|
19
20
|
export type ZodFunctionSchemaOptions<In extends $ZodFunctionArgs, Out extends $ZodFunctionOut> = {
|
|
20
21
|
trials?: FunctionTrial<z.infer<In>>[];
|
package/dist/interpret.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { InterpretableZodError, InterpretableZodIssue } from './types';
|
|
1
|
+
import { InterpretableZodError, InterpretableZodIssue, ZodPath } from './types';
|
|
2
2
|
export type InterpretZodErrorOptions = {
|
|
3
|
-
prefix?:
|
|
3
|
+
prefix?: ZodPath;
|
|
4
4
|
multiline?: boolean;
|
|
5
|
+
includeCode?: boolean;
|
|
5
6
|
};
|
|
6
|
-
export declare function interpretZodError(err: InterpretableZodError, options?:
|
|
7
|
-
export declare function interpretZodIssue(issue: InterpretableZodIssue, options?:
|
|
7
|
+
export declare function interpretZodError(err: InterpretableZodError, options?: ZodPath | InterpretZodErrorOptions): string;
|
|
8
|
+
export declare function interpretZodIssue(issue: InterpretableZodIssue, options?: ZodPath | InterpretZodErrorOptions): string;
|
package/dist/interpret.js
CHANGED
|
@@ -10,9 +10,18 @@ const prefixIssuePath_1 = require("./prefixIssuePath");
|
|
|
10
10
|
function interpretZodError(err, options = "") {
|
|
11
11
|
if (typeof options !== "object" || Array.isArray(options))
|
|
12
12
|
options = { prefix: options };
|
|
13
|
-
const { multiline = true, prefix = "" } = options;
|
|
13
|
+
const { multiline = true, includeCode = false, prefix = "" } = options;
|
|
14
14
|
const modifiedErr = {
|
|
15
|
-
issues: err.issues.map(issue =>
|
|
15
|
+
issues: err.issues.map(issue => {
|
|
16
|
+
const modifiedIssue = (0, prefixIssuePath_1.prefixZodIssuePath)(issue, prefix);
|
|
17
|
+
if (includeCode && modifiedIssue.code) {
|
|
18
|
+
return {
|
|
19
|
+
...modifiedIssue,
|
|
20
|
+
message: `[${modifiedIssue.code}] ${modifiedIssue.message}`
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
return modifiedIssue;
|
|
24
|
+
})
|
|
16
25
|
};
|
|
17
26
|
let result = zod_1.default.prettifyError(modifiedErr);
|
|
18
27
|
if (!multiline) {
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { ZodPath } from "./types";
|
|
2
|
+
export declare function issuePathStartsWith(issuePath: PropertyKey[], prefix: ZodPath): boolean;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { InterpretableZodIssue } from "./types";
|
|
2
|
-
export declare function prefixZodIssuePath<I extends InterpretableZodIssue>(issue: I, prefix:
|
|
1
|
+
import { InterpretableZodIssue, ZodPath } from "./types";
|
|
2
|
+
export declare function prefixZodIssuePath<I extends InterpretableZodIssue>(issue: I, prefix: ZodPath): I;
|
package/dist/types.d.ts
CHANGED
|
@@ -18,7 +18,9 @@ export type ZodValidateWithErrorsOptions = {
|
|
|
18
18
|
prefix?: string | string[];
|
|
19
19
|
};
|
|
20
20
|
export type MaybeZodOptional<ZT extends ZodType> = ZT | ZodOptional<ZT>;
|
|
21
|
+
export type ZodPath = PropertyKey | PropertyKey[];
|
|
21
22
|
export type InterpretableZodIssue = Readonly<{
|
|
23
|
+
code?: string;
|
|
22
24
|
message: string;
|
|
23
25
|
path?: PropertyKey[];
|
|
24
26
|
}>;
|