@express-zod-api/zod-plugin 3.0.0-beta.2 → 4.0.0-beta.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## Version 4
4
+
5
+ ### v4.0.0
6
+
7
+ - Supported `zod` versions: `^4.3.4`;
8
+ - Zod made metadata inheritable, so that `pack()` and `unpack()` are removed;
9
+ - Use the `.meta()` method of a schema instead of both helpers;
10
+ - Runtime distinguishable brand is now stored along with other metadata.
11
+
3
12
  ## Version 3
4
13
 
5
14
  ### v3.0.0
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2025 Anna Bocharova
3
+ Copyright (c) 2026 Anna Bocharova
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -13,12 +13,12 @@ This module extends Zod functionality when it's imported:
13
13
  - Adds `.remap()` method to `ZodObject` for renaming object properties:
14
14
  - Supports a mapping object or an object transforming function as an argument;
15
15
  - Relies on `R.renameKeys()` from the `ramda` library;
16
- - Alters the `.brand()` method on all Zod schemas by making the assigned brand available in runtime:
17
- - The brand set this way will withstand refinements, unlike the metadata set by `.meta()`.
16
+ - Alters the `.brand()` method on all Zod schemas:
17
+ - shorthand for `.meta({ "x-brand": ... })` making the brand available in runtime via `getBrand()` helper;
18
18
 
19
19
  ## Requirements
20
20
 
21
- - Zod `^4.1.13`
21
+ - Zod `^4.3.4`
22
22
 
23
23
  ## Basic usage
24
24
 
@@ -29,11 +29,9 @@ import { getBrand } from "@express-zod-api/zod-plugin";
29
29
  const schema = z.string().example("test").example("another").brand("custom");
30
30
 
31
31
  getBrand(schema); // "custom"
32
- schema.meta(); // { examples: ["test", "another"] }
32
+ schema.meta(); // { examples: ["test", "another"], "x-brand": "custom" }
33
33
  ```
34
34
 
35
35
  ## Helpers
36
36
 
37
- - `getBrand()` — retrieves the brand from the schema that was set by its `.brand()` method;
38
- - `pack()` — returns a cloned schema having inheritable attributes assigned (such as brand);
39
- - `unpack()` — retrieves the attributes from the schema that was set by `pack()` helper.
37
+ - `getBrand()` — retrieves the brand from the schema that was set by its `.brand()` method.
package/dist/index.d.ts CHANGED
@@ -1,28 +1,12 @@
1
1
  import './augmentation.js';
2
2
  import { z } from "zod";
3
3
 
4
- //#region src/packer.d.ts
5
-
6
- /**
7
- * @public
8
- * @desc Attaches an inheritable attributes to the schema (withstands refinements).
9
- */
10
- declare const pack: <T extends z.ZodType, B extends object>(subject: T, bag: B) => T & {
11
- _zod: {
12
- bag: T["_zod"]["bag"] & B;
13
- };
14
- };
15
- /**
16
- * @public
17
- * @desc Retrieves the attributes attached to the schema by pack() method.
18
- */
19
- declare const unpack: <T extends z.core.$ZodType>(subject: T) => T["_zod"]["bag"];
20
- //#endregion
21
4
  //#region src/brand.d.ts
5
+
22
6
  /**
23
7
  * @public
24
8
  * @desc Retrieves the brand from the schema set by its .brand() method.
25
9
  * */
26
10
  declare const getBrand: (subject: z.core.$ZodType) => string | number | symbol | undefined;
27
11
  //#endregion
28
- export { getBrand, pack, unpack };
12
+ export { getBrand };
package/dist/index.js CHANGED
@@ -1 +1,2 @@
1
- import{createRequire as e}from"node:module";import{globalRegistry as t,z as n}from"zod";import*as r from"ramda";const i=(e,t)=>{let r=n.core.$constructor(`$Packer`,(e,t)=>{n.core.$ZodCheck.init(e,t),e._zod.onattach.push(e=>{Object.assign(e._zod.bag,t.bag)}),e._zod.check=()=>{}});return e.check(new r({check:`$Packer`,bag:t}))},a=e=>e._zod.bag,o=`brand`,s=function(e){return i(this,{[o]:e})},c=e=>{let{[o]:t}=a(e)||{};if(typeof t==`symbol`||typeof t==`string`||typeof t==`number`)return t},l=e=>{let t=r.reject(r.isNil,e),n=Object.values(t);if(new Set(n).size!==n.length)throw Error(`remap(): duplicate target keys`,{cause:e});return r.renameKeys(t)},u=function(e){let t=typeof e==`function`?e:l(e),i=t(r.map(r.invoker(0,`clone`),this._zod.def.shape)),a=(this._zod.def.catchall instanceof n.ZodUnknown?n.looseObject:n.object)(i);return this.transform(t).pipe(a)},d=function(e){let n=t.get(this)?.examples?.slice()||[];return n.push(e),this.meta({examples:n})},f=function(){return this.meta({deprecated:!0})},p=function(e){return this.meta({default:e})},m=()=>{let t=[n],{z:r}=e(import.meta.url)(`zod`);return n!==r&&t.push(r),t},h=e=>Object.keys(e).filter(e=>e.startsWith(`Zod`)&&!/(Success|Error|Function)$/.test(e)).map(t=>e[t]).filter(e=>typeof e==`function`),g=Symbol.for(`@express-zod-api/zod-plugin`);if(!(g in globalThis)){globalThis[g]=!0;for(let e of m()){for(let t of h(e))Object.defineProperties(t.prototype,{example:{value:d,writable:!1},deprecated:{value:f,writable:!1},brand:{set(){},get(){return s.bind(this)}}});Object.defineProperty(e.ZodDefault.prototype,`label`,{value:p,writable:!1}),Object.defineProperty(e.ZodObject.prototype,`remap`,{value:u,writable:!1})}}export{c as getBrand,i as pack,a as unpack};
1
+
2
+ import{createRequire as e}from"node:module";import{globalRegistry as t,z as n}from"zod";import*as r from"ramda";const i=e=>{let t=r.reject(r.isNil,e),n=Object.values(t);if(new Set(n).size!==n.length)throw Error(`remap(): duplicate target keys`,{cause:e});return r.renameKeys(t)},a=function(e){let t=typeof e==`function`?e:i(e),a=t(r.map(r.invoker(0,`clone`),this._zod.def.shape)),o=(this._zod.def.catchall instanceof n.ZodUnknown?n.looseObject:n.object)(a);return this.transform(t).pipe(o)},o=`x-brand`,s=e=>{let{[o]:n}=t.get(e)||{};if(typeof n==`symbol`||typeof n==`string`||typeof n==`number`)return n},c=function(e){let n=t.get(this)?.examples?.slice()||[];return n.push(e),this.meta({examples:n})},l=function(){return this.meta({deprecated:!0})},u=function(e){return this.meta({default:e})},d=function(e){return this.meta({[o]:e})},f=()=>{let t=[n],{z:r}=e(import.meta.url)(`zod`);return n!==r&&t.push(r),t},p=e=>Object.keys(e).filter(e=>e.startsWith(`Zod`)&&!/(Success|Error|Function)$/.test(e)).map(t=>e[t]).filter(e=>typeof e==`function`),m=Symbol.for(`@express-zod-api/zod-plugin`);if(!(m in globalThis)){globalThis[m]=!0;for(let e of f()){for(let t of p(e))Object.defineProperties(t.prototype,{example:{value:c,writable:!1},deprecated:{value:l,writable:!1},brand:{set(){},get(){return d.bind(this)}}});Object.defineProperty(e.ZodDefault.prototype,`label`,{value:u,writable:!1}),Object.defineProperty(e.ZodObject.prototype,`remap`,{value:a,writable:!1})}}export{s as getBrand};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@express-zod-api/zod-plugin",
3
- "version": "3.0.0-beta.2",
3
+ "version": "4.0.0-beta.2",
4
4
  "license": "MIT",
5
5
  "description": "Zod plugin for express-zod-api",
6
6
  "sideEffects": true,
@@ -36,13 +36,13 @@
36
36
  "ramda": "^0.32.0"
37
37
  },
38
38
  "peerDependencies": {
39
- "zod": "^4.1.13"
39
+ "zod": "^4.3.4"
40
40
  },
41
41
  "devDependencies": {
42
- "@types/ramda": "^0.31.0",
42
+ "@types/ramda": "^0.31.1",
43
43
  "camelize-ts": "^3.0.0",
44
- "typescript": "^5.9.2",
45
- "zod": "^4.1.13"
44
+ "typescript": "^5.9.3",
45
+ "zod": "^4.3.4"
46
46
  },
47
47
  "keywords": [
48
48
  "zod",