1- import * as R from "ramda" ;
21import { globalRegistry , z } from "zod" ;
32import { name } from "./package.json" ;
43import { setBrand } from "./brand" ;
4+ import { remap } from "./remap" ;
55
66const exampleSetter = function ( this : z . ZodType , value : z . output < typeof this > ) {
77 const examples = globalRegistry . get ( this ) ?. examples ?. slice ( ) || [ ] ;
@@ -17,24 +17,6 @@ const labelSetter = function (this: z.ZodDefault, defaultLabel: string) {
1717 return this . meta ( { default : defaultLabel } ) ;
1818} ;
1919
20- type _Mapper = < T extends Record < string , unknown > > (
21- subject : T ,
22- ) => { [ P in string | keyof T ] : T [ keyof T ] } ;
23-
24- const objectMapper = function (
25- this : z . ZodObject ,
26- tool : Record < string , string > | _Mapper ,
27- ) {
28- const transformer =
29- typeof tool === "function" ? tool : R . renameKeys ( R . reject ( R . isNil , tool ) ) ; // rejecting undefined
30- const nextShape = transformer (
31- R . map ( R . invoker ( 0 , "clone" ) , this . _zod . def . shape ) , // immutable, changed from R.clone due to failure
32- ) ;
33- const hasPassThrough = this . _zod . def . catchall instanceof z . ZodUnknown ;
34- const output = ( hasPassThrough ? z . looseObject : z . object ) ( nextShape ) ; // proxies unknown keys when set to "passthrough"
35- return this . transform ( transformer ) . pipe ( output ) ;
36- } ;
37-
3820const pluginFlag = Symbol . for ( name ) ;
3921
4022if ( ! ( pluginFlag in globalThis ) ) {
@@ -70,6 +52,6 @@ if (!(pluginFlag in globalThis)) {
7052 Object . defineProperty (
7153 z . ZodObject . prototype ,
7254 "remap" satisfies keyof z . ZodObject ,
73- { value : objectMapper , writable : false } ,
55+ { value : remap , writable : false } ,
7456 ) ;
7557}
0 commit comments