@ptolemy2002/zod-utils 1.4.0 → 1.5.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.js +1 -1
- package/dist/interpret.d.ts +7 -3
- package/dist/interpret.js +20 -37
- package/dist/prefixIssuePath.d.ts +2 -2
- package/dist/prefixIssuePath.js +2 -1
- package/dist/types.d.ts +7 -0
- package/package.json +1 -1
package/dist/function.js
CHANGED
|
@@ -101,7 +101,7 @@ function zodFunctionSchema({ trials = [], inputPath = "args", outputPath = "retu
|
|
|
101
101
|
const id = (_a = trial.id) !== null && _a !== void 0 ? _a : `trial_${i}`;
|
|
102
102
|
const { outputSchema = zod_1.default.unknown(), error, errorStringify = (e) => {
|
|
103
103
|
if ((0, typeGuards_1.isZodError)(e))
|
|
104
|
-
return (0, interpret_1.interpretZodError)(e);
|
|
104
|
+
return (0, interpret_1.interpretZodError)(e, { multiline: false });
|
|
105
105
|
if (e instanceof Error)
|
|
106
106
|
return e.message;
|
|
107
107
|
return String(e);
|
package/dist/interpret.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import { InterpretableZodError, InterpretableZodIssue } from './types';
|
|
2
|
+
export type InterpretZodErrorOptions = {
|
|
3
|
+
prefix?: PropertyKey | PropertyKey[];
|
|
4
|
+
multiline?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function interpretZodError(err: InterpretableZodError, options?: PropertyKey | PropertyKey[] | InterpretZodErrorOptions): string;
|
|
7
|
+
export declare function interpretZodIssue(issue: InterpretableZodIssue, options?: PropertyKey | PropertyKey[] | InterpretZodErrorOptions): string;
|
package/dist/interpret.js
CHANGED
|
@@ -1,42 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
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);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
35
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
6
|
exports.interpretZodError = interpretZodError;
|
|
37
|
-
|
|
7
|
+
exports.interpretZodIssue = interpretZodIssue;
|
|
8
|
+
const zod_1 = __importDefault(require("zod"));
|
|
38
9
|
const prefixIssuePath_1 = require("./prefixIssuePath");
|
|
39
|
-
function interpretZodError(err,
|
|
40
|
-
|
|
41
|
-
|
|
10
|
+
function interpretZodError(err, options = "") {
|
|
11
|
+
if (typeof options !== "object" || Array.isArray(options))
|
|
12
|
+
options = { prefix: options };
|
|
13
|
+
const { multiline = true, prefix = "" } = options;
|
|
14
|
+
const modifiedErr = {
|
|
15
|
+
issues: err.issues.map(issue => (0, prefixIssuePath_1.prefixZodIssuePath)(issue, prefix))
|
|
16
|
+
};
|
|
17
|
+
let result = zod_1.default.prettifyError(modifiedErr);
|
|
18
|
+
if (!multiline) {
|
|
19
|
+
result = result.replace(/\n\s*→/g, " →");
|
|
20
|
+
}
|
|
21
|
+
return result;
|
|
22
|
+
}
|
|
23
|
+
function interpretZodIssue(issue, options = "") {
|
|
24
|
+
return interpretZodError({ issues: [issue] }, options);
|
|
42
25
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare function prefixZodIssuePath(issue:
|
|
1
|
+
import { InterpretableZodIssue } from "./types";
|
|
2
|
+
export declare function prefixZodIssuePath<I extends InterpretableZodIssue>(issue: I, prefix: PropertyKey | PropertyKey[]): I;
|
package/dist/prefixIssuePath.js
CHANGED
|
@@ -2,9 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.prefixZodIssuePath = prefixZodIssuePath;
|
|
4
4
|
function prefixZodIssuePath(issue, prefix) {
|
|
5
|
+
var _a;
|
|
5
6
|
if (!Array.isArray(prefix))
|
|
6
7
|
prefix = [prefix];
|
|
7
|
-
const newPath = [...prefix, ...issue.path]
|
|
8
|
+
const newPath = [...prefix, ...((_a = issue.path) !== null && _a !== void 0 ? _a : [])]
|
|
8
9
|
.filter(p => typeof p !== "string" || p.length > 0);
|
|
9
10
|
if (newPath.length === 0)
|
|
10
11
|
newPath.push("(root)");
|
package/dist/types.d.ts
CHANGED
|
@@ -18,3 +18,10 @@ export type ZodValidateWithErrorsOptions = {
|
|
|
18
18
|
prefix?: string | string[];
|
|
19
19
|
};
|
|
20
20
|
export type MaybeZodOptional<ZT extends ZodType> = ZT | ZodOptional<ZT>;
|
|
21
|
+
export type InterpretableZodIssue = Readonly<{
|
|
22
|
+
message: string;
|
|
23
|
+
path?: PropertyKey[];
|
|
24
|
+
}>;
|
|
25
|
+
export type InterpretableZodError = Readonly<{
|
|
26
|
+
issues: InterpretableZodIssue[];
|
|
27
|
+
}>;
|