@ptolemy2002/zod-utils 1.0.0 → 1.2.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/README.md CHANGED
@@ -4,7 +4,9 @@ Various utilities for working with Zod schemas.
4
4
  ## Table of Contents
5
5
  - [Type Reference](docs/type-reference.md) - Complete type definitions for all exported types
6
6
  - `util` - Utilities for working with Zod schemas and errors
7
+ - [clone](docs/util/clone.md) - Utility for cloning Zod schemas without affecting the original
7
8
  - [interpret](docs/util/interpret.md) - Utilities for formatting Zod errors as strings
9
+ - [prefixIssuePath](docs/util/prefixIssuePath.md) - Utility for prepending a path prefix to a Zod issue
8
10
  - [typeGuards](docs/util/typeGuards.md) - Type guards for Zod-related values
9
11
  - [validate](docs/util/validate.md) - Schema-wrapping factories for creating validators
10
12
 
@@ -0,0 +1,2 @@
1
+ import { ZodType } from "zod";
2
+ export declare function zodClone<T extends ZodType>(schema: T): T;
package/dist/clone.js ADDED
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.zodClone = zodClone;
4
+ function zodClone(schema) {
5
+ // This `refine` pattern allows us to copy the schema so that
6
+ // the original metadata is not overwritten
7
+ return schema.refine(() => true);
8
+ }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,5 @@ export * from './types';
2
2
  export * from './typeGuards';
3
3
  export * from './interpret';
4
4
  export * from './validate';
5
+ export * from './clone';
6
+ export * from './prefixIssuePath';
package/dist/index.js CHANGED
@@ -18,3 +18,5 @@ __exportStar(require("./types"), exports);
18
18
  __exportStar(require("./typeGuards"), exports);
19
19
  __exportStar(require("./interpret"), exports);
20
20
  __exportStar(require("./validate"), exports);
21
+ __exportStar(require("./clone"), exports);
22
+ __exportStar(require("./prefixIssuePath"), exports);
package/dist/interpret.js CHANGED
@@ -35,15 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
36
  exports.interpretZodError = interpretZodError;
37
37
  const zod_1 = __importStar(require("zod"));
38
+ const prefixIssuePath_1 = require("./prefixIssuePath");
38
39
  function interpretZodError(err, prefix = "") {
39
- if (!Array.isArray(prefix))
40
- prefix = [prefix];
41
- const modifiedErr = new zod_1.ZodError(err.issues.map(issue => {
42
- const newPath = [...prefix, ...issue.path]
43
- .filter(p => typeof p !== "string" || p.length > 0);
44
- if (newPath.length === 0)
45
- newPath.push("(root)");
46
- return { ...issue, path: newPath };
47
- }));
40
+ const modifiedErr = new zod_1.ZodError(err.issues.map(issue => (0, prefixIssuePath_1.prefixZodIssuePath)(issue, prefix)));
48
41
  return zod_1.default.prettifyError(modifiedErr);
49
42
  }
@@ -0,0 +1,2 @@
1
+ import z from "zod";
2
+ export declare function prefixZodIssuePath(issue: z.core.$ZodIssue, prefix: PropertyKey | PropertyKey[]): z.core.$ZodIssue;
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prefixZodIssuePath = prefixZodIssuePath;
4
+ function prefixZodIssuePath(issue, prefix) {
5
+ if (!Array.isArray(prefix))
6
+ prefix = [prefix];
7
+ const newPath = [...prefix, ...issue.path]
8
+ .filter(p => typeof p !== "string" || p.length > 0);
9
+ if (newPath.length === 0)
10
+ newPath.push("(root)");
11
+ return { ...issue, path: newPath };
12
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ptolemy2002/zod-utils",
3
- "version": "1.0.0",
3
+ "version": "1.2.0",
4
4
  "private": false,
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,11 +28,9 @@
28
28
  "release-minor": "bash ./scripts/release.sh minor",
29
29
  "release-major": "bash ./scripts/release.sh major"
30
30
  },
31
-
32
31
  "peerDependencies": {
33
32
  "zod": "^4.3.6"
34
33
  },
35
-
36
34
  "devDependencies": {
37
35
  "@types/jest": "^29.5.0",
38
36
  "@types/node": "^25.3.5",
@@ -43,4 +41,4 @@
43
41
  "typescript-transform-paths": "^3.5.3",
44
42
  "zod": "^4.3.6"
45
43
  }
46
- }
44
+ }