@express-zod-api/zod-plugin 3.0.0-beta.2 → 3.0.1
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 +4 -0
- package/LICENSE +1 -1
- package/dist/augmentation.d.ts +26 -12
- package/dist/index.d.ts +7 -6
- package/dist/index.js +1 -0
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
package/LICENSE
CHANGED
package/dist/augmentation.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
|
|
3
2
|
//#region src/remap.d.ts
|
|
4
3
|
type TuplesFromObject<T> = { [P in keyof T]: [P, T[P]] }[keyof T];
|
|
5
|
-
type GetKeyByValue<T, V> = TuplesFromObject<T> extends infer TT ? TT extends [infer P, V] ? P : never : never;
|
|
4
|
+
type GetKeyByValue<T, V> = TuplesFromObject<T> extends infer TT ? (TT extends [infer P, V] ? P : never) : never;
|
|
6
5
|
/**
|
|
7
6
|
* @fileoverview Mapping utils for Zod Runtime Plugin (remap)
|
|
8
7
|
* @link https://stackoverflow.com/questions/55454125/typescript-remapping-object-properties-in-typesafe
|
|
9
|
-
* @todo try to reuse R.Remap from Ramda (requires to move its types to prod dependencies)
|
|
10
8
|
*/
|
|
11
|
-
type Remap<T, U extends { [P in keyof T]?: V }, V extends string> = {
|
|
9
|
+
type Remap<T, U extends { [P in keyof T]?: V }, V extends string> = {
|
|
10
|
+
[P in NonNullable<U[keyof U]>]: T[GetKeyByValue<U, P>];
|
|
11
|
+
};
|
|
12
12
|
type Intact<T, U> = { [K in Exclude<keyof T, keyof U>]: T[K] };
|
|
13
13
|
//#endregion
|
|
14
14
|
//#region src/augmentation.d.ts
|
|
@@ -28,19 +28,33 @@ declare module "zod/v4/core" {
|
|
|
28
28
|
* @desc Stores the argument supplied to .brand() on all schemas (runtime distinguishable branded types)
|
|
29
29
|
* */
|
|
30
30
|
declare module "zod" {
|
|
31
|
-
interface ZodType<
|
|
31
|
+
interface ZodType<
|
|
32
|
+
out Output = unknown,
|
|
33
|
+
out Input = unknown,
|
|
34
|
+
out Internals extends z.core.$ZodTypeInternals<Output, Input> = z.core.$ZodTypeInternals<Output, Input>,
|
|
35
|
+
> extends z.core.$ZodType<Output, Input, Internals> {
|
|
32
36
|
/** @desc Shorthand for .meta({ examples }) */
|
|
33
37
|
example(example: z.output<this>): this;
|
|
34
38
|
deprecated(): this;
|
|
35
39
|
}
|
|
36
|
-
interface ZodDefault<T extends z.core.SomeType = z.core.$ZodType>
|
|
40
|
+
interface ZodDefault<T extends z.core.SomeType = z.core.$ZodType>
|
|
41
|
+
extends z._ZodType<z.core.$ZodDefaultInternals<T>>, z.core.$ZodDefault<T> {
|
|
37
42
|
/** @desc Shorthand for .meta({ default }) */
|
|
38
43
|
label(label: string): this;
|
|
39
44
|
}
|
|
40
|
-
interface ZodObject<
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
interface ZodObject<
|
|
46
|
+
out Shape extends z.core.$ZodShape = z.core.$ZodLooseShape,
|
|
47
|
+
out Config extends z.core.$ZodObjectConfig = z.core.$strip,
|
|
48
|
+
>
|
|
49
|
+
extends z._ZodType<z.core.$ZodObjectInternals<Shape, Config>>, z.core.$ZodObject<Shape, Config> {
|
|
50
|
+
remap<V extends string, U extends { [P in keyof Shape]?: V }>(
|
|
51
|
+
mapping: U,
|
|
52
|
+
): z.ZodPipe<
|
|
53
|
+
z.ZodPipe<this, z.ZodTransform>, // internal type simplified
|
|
54
|
+
z.ZodObject<Remap<Shape, U, V> & Intact<Shape, U>, Config>
|
|
55
|
+
>;
|
|
56
|
+
remap<U extends z.core.$ZodShape>(
|
|
57
|
+
mapper: (subject: Shape) => U,
|
|
58
|
+
): z.ZodPipe<z.ZodPipe<this, z.ZodTransform>, z.ZodObject<U>>;
|
|
45
59
|
}
|
|
46
|
-
}
|
|
60
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import "./augmentation.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
|
|
4
3
|
//#region src/packer.d.ts
|
|
5
|
-
|
|
6
4
|
/**
|
|
7
5
|
* @public
|
|
8
|
-
* @desc Attaches
|
|
6
|
+
* @desc Attaches inheritable attributes to the schema (withstand refinements).
|
|
9
7
|
*/
|
|
10
|
-
declare const pack: <T extends z.ZodType, B extends object>(
|
|
8
|
+
declare const pack: <T extends z.ZodType, B extends object>(
|
|
9
|
+
subject: T,
|
|
10
|
+
bag: B,
|
|
11
|
+
) => T & {
|
|
11
12
|
_zod: {
|
|
12
13
|
bag: T["_zod"]["bag"] & B;
|
|
13
14
|
};
|
|
@@ -25,4 +26,4 @@ declare const unpack: <T extends z.core.$ZodType>(subject: T) => T["_zod"]["bag"
|
|
|
25
26
|
* */
|
|
26
27
|
declare const getBrand: (subject: z.core.$ZodType) => string | number | symbol | undefined;
|
|
27
28
|
//#endregion
|
|
28
|
-
export { getBrand, pack, unpack };
|
|
29
|
+
export { getBrand, pack, unpack };
|
package/dist/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
+
|
|
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,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};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@express-zod-api/zod-plugin",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Zod plugin for express-zod-api",
|
|
6
6
|
"sideEffects": true,
|
|
@@ -39,10 +39,11 @@
|
|
|
39
39
|
"zod": "^4.1.13"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
|
-
"@types/ramda": "^0.31.
|
|
42
|
+
"@types/ramda": "^0.31.1",
|
|
43
43
|
"camelize-ts": "^3.0.0",
|
|
44
|
-
"typescript": "^5.9.
|
|
45
|
-
"zod": "^4.
|
|
44
|
+
"typescript": "^5.9.3",
|
|
45
|
+
"zod": "^4.3.4",
|
|
46
|
+
"dts-plugin": "^0.1.0"
|
|
46
47
|
},
|
|
47
48
|
"keywords": [
|
|
48
49
|
"zod",
|