@layerzerolabs/zod-utils 0.2.90 → 0.2.91

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/package.json CHANGED
@@ -1,16 +1,15 @@
1
1
  {
2
2
  "name": "@layerzerolabs/zod-utils",
3
- "version": "0.2.90",
3
+ "version": "0.2.91",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "exports": {
8
8
  "types": "./dist/index.d.ts",
9
- "require": "./dist/index.cjs",
10
9
  "import": "./dist/index.js",
11
- "default": "./dist/index.cjs"
10
+ "default": "./dist/index.js"
12
11
  },
13
- "main": "./dist/index.cjs",
12
+ "main": "./dist/index.js",
14
13
  "module": "./dist/index.js",
15
14
  "types": "./dist/index.d.ts",
16
15
  "files": [
@@ -18,12 +17,12 @@
18
17
  ],
19
18
  "dependencies": {
20
19
  "zod": "4.3.5",
21
- "@layerzerolabs/function-pointer": "0.2.90"
20
+ "@layerzerolabs/function-pointer": "0.2.91"
22
21
  },
23
22
  "devDependencies": {
24
23
  "tsup": "^8.4.0",
25
- "@layerzerolabs/tsup-configuration": "0.2.90",
26
- "@layerzerolabs/typescript-configuration": "0.2.90"
24
+ "@layerzerolabs/typescript-configuration": "0.2.91",
25
+ "@layerzerolabs/tsup-configuration": "0.2.91"
27
26
  },
28
27
  "publishConfig": {
29
28
  "access": "public",
@@ -32,6 +31,7 @@
32
31
  "externalRepoConfig": {
33
32
  "targets": [
34
33
  "audit-external",
34
+ "console-pen-test",
35
35
  "onesig-client"
36
36
  ]
37
37
  },
package/dist/RHF5FXGP.cjs DELETED
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- var zod = require('zod');
4
-
5
- var __defProp = Object.defineProperty;
6
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
- var functionSchemaTag = Symbol("__FUNCTION_SCHEMA_TAG");
8
- var functionSchema = /* @__PURE__ */ __name(({ input, output }) => {
9
- const obj = zod.z.object({
10
- input,
11
- output
12
- });
13
- Object.defineProperty(obj, functionSchemaTag, {
14
- value: true,
15
- writable: false
16
- });
17
- obj.parse = (i) => {
18
- if (typeof i !== "function") {
19
- throw new Error(`${i} is not a function`);
20
- }
21
- return i;
22
- };
23
- return obj;
24
- }, "functionSchema");
25
- var schemaIsFunctionSchema = /* @__PURE__ */ __name((schema) => {
26
- return Object.hasOwn(schema, functionSchemaTag);
27
- }, "schemaIsFunctionSchema");
28
- var customSchema = /* @__PURE__ */ __name((validate) => zod.z.custom(validate), "customSchema");
29
- var createFunctionPointerSchema = /* @__PURE__ */ __name(() => (
30
- // TODO: replace with a concrete zod schema
31
- customSchema()
32
- ), "createFunctionPointerSchema");
33
- var brandedSchemaPropertyKey = "__BRANDED_SCHEMA_NAME";
34
- var brandSchema = /* @__PURE__ */ __name((schema, name) => Object.defineProperty(schema, brandedSchemaPropertyKey, {
35
- enumerable: false,
36
- configurable: false,
37
- writable: false,
38
- value: name
39
- }), "brandSchema");
40
- var isBrandedWith = /* @__PURE__ */ __name((expected, schema) => {
41
- if (!(brandedSchemaPropertyKey in expected)) {
42
- throw new Error("Branded model is not itself branded");
43
- }
44
- if (!(brandedSchemaPropertyKey in schema)) {
45
- return false;
46
- }
47
- return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];
48
- }, "isBrandedWith");
49
-
50
- exports.__name = __name;
51
- exports.brandSchema = brandSchema;
52
- exports.createFunctionPointerSchema = createFunctionPointerSchema;
53
- exports.customSchema = customSchema;
54
- exports.functionSchema = functionSchema;
55
- exports.isBrandedWith = isBrandedWith;
56
- exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
57
- //# sourceMappingURL=RHF5FXGP.cjs.map
58
- //# sourceMappingURL=RHF5FXGP.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","Symbol","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema","brandedSchemaPropertyKey","brandSchema","name","enumerable","configurable","isBrandedWith","expected"],"mappings":";;;;;;AAUA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,MAAEC,MAAAA,CAAO;AACjBJ,IAAAA,KAAAA;AACAC,IAAAA;GACJ,CAAA;AACAI,EAAAA,MAAAA,CAAOC,cAAAA,CAAeJ,KAAKL,iBAAAA,EAAmB;IAAEU,KAAAA,EAAO,IAAA;IAAMC,QAAAA,EAAU;GAAM,CAAA;AAI7EN,EAAAA,GAAAA,CAAIO,KAAAA,GAAQ,CAACC,CAAAA,KAAAA;AACT,IAAA,IAAI,OAAOA,MAAM,UAAA,EAAY;AACzB,MAAA,MAAM,IAAIC,KAAAA,CAAM,CAAA,EAAGD,CAAAA,CAAAA,kBAAAA,CAAqB,CAAA;AAC5C,IAAA;AAGA,IAAA,OAAOA,CAAAA;AACX,EAAA,CAAA;AACA,EAAA,OAAOR,GAAAA;AACX,CAAA,EAxB8B,gBAAA;AA0BvB,IAAMU,sBAAAA,2BACTC,MAAAA,KAAAA;AAEA,EAAA,OAAOR,MAAAA,CAAOS,MAAAA,CAAOD,MAAAA,EAAQhB,iBAAAA,CAAAA;AACjC,CAAA,EAJsC,wBAAA;AAM/B,IAAMkB,+BAAe,MAAA,CAAA,CAAIC,QAAAA,KAC5Bb,KAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA;;EAEvCH,YAAAA;AAFuC,CAAA,EAAA,6BAAA;AAY3C,IAAMI,wBAAAA,GAA2B,uBAAA;AAG1B,IAAMC,8BAAc,MAAA,CAAA,CAA2BP,MAAAA,EAAgBQ,SAClEhB,MAAAA,CAAOC,cAAAA,CAAeO,QAAQM,wBAAAA,EAA0B;EACpDG,UAAAA,EAAY,KAAA;EACZC,YAAAA,EAAc,KAAA;EACdf,QAAAA,EAAU,KAAA;EACVD,KAAAA,EAAOc;AACX,CAAA,CAAA,EANuB,aAAA;AAQpB,IAAMG,aAAAA,mBAAgB,MAAA,CAAA,CACzBC,QAAAA,EACAZ,MAAAA,KAAAA;AAEA,EAAA,IAAI,EAAEM,4BAA4BM,QAAAA,CAAAA,EAAW;AACzC,IAAA,MAAM,IAAId,MAAM,qCAAA,CAAA;AACpB,EAAA;AAEA,EAAA,IAAI,EAAEQ,4BAA4BN,MAAAA,CAAAA,EAAS;AACvC,IAAA,OAAO,KAAA;AACX,EAAA;AAEA,EAAA,OAAOA,MAAAA,CAAOM,wBAAAA,CAAAA,KAA8BM,QAAAA,CAASN,wBAAAA,CAAAA;AACzD,CAAA,EAb6B,eAAA","file":"RHF5FXGP.cjs","sourcesContent":["import { z } from 'zod';\n\nimport type { FunctionPointer } from '@layerzerolabs/function-pointer';\n\nexport type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []\n ? Output\n : T extends [infer Head, ...infer Tail extends z.ZodType[]]\n ? InferredArray<Tail, [...Output, z.infer<Head>]>\n : never;\n\nconst functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');\n\n// This essentially replicates the functionality of z.function in zod v3\nexport const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({\n input,\n output,\n}: {\n input: Input;\n output: Output;\n}) => {\n const obj = z.object({\n input,\n output,\n });\n Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });\n // We don't expect the function to actually be an object with an input field and an output field\n // so we override the parse function. We can't actually parse functions since input and output\n // types are lost at runtime, but we can check the runtime type of the object\n obj.parse = (i) => {\n if (typeof i !== 'function') {\n throw new Error(`${i} is not a function`);\n }\n // The return type here just has to match the inference of z.object,\n // the actual inference of the schema will be the z.ZodType custom\n return i as any;\n };\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;\n};\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T, T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // TODO: replace with a concrete zod schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n\n// utils for branding schemata with names\nconst brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;\n\n/** Unavoidably, this mutates the underlying schema. Use with caution. */\nexport const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>\n Object.defineProperty(schema, brandedSchemaPropertyKey, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: name,\n });\n\nexport const isBrandedWith = <Branded extends z.ZodType>(\n expected: Branded,\n schema: z.ZodType,\n): schema is Branded => {\n if (!(brandedSchemaPropertyKey in expected)) {\n throw new Error('Branded model is not itself branded');\n }\n\n if (!(brandedSchemaPropertyKey in schema)) {\n return false;\n }\n\n return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];\n};\n"]}
package/dist/index.cjs DELETED
@@ -1,152 +0,0 @@
1
- 'use strict';
2
-
3
- var RHF5FXGP_cjs = require('./RHF5FXGP.cjs');
4
- var zod = require('zod');
5
-
6
- var RESOLVING = Symbol("mapOnSchema/resolving");
7
- function mapOnSchema(schema, fn) {
8
- const results = /* @__PURE__ */ new Map();
9
- function mapElement(s) {
10
- const value = results.get(s);
11
- if (value === RESOLVING) {
12
- throw new Error("Recursive schema access detected");
13
- } else if (value !== void 0) {
14
- return value;
15
- }
16
- results.set(s, RESOLVING);
17
- const result = mapOnSchema(s, fn);
18
- results.set(s, result);
19
- return result;
20
- }
21
- RHF5FXGP_cjs.__name(mapElement, "mapElement");
22
- function mapInner() {
23
- if (schema instanceof zod.z.ZodObject) {
24
- const newShape = {};
25
- for (const [key, value] of Object.entries(schema.shape)) {
26
- newShape[key] = mapElement(value);
27
- }
28
- return new zod.z.ZodObject({
29
- ...schema.def,
30
- shape: newShape
31
- });
32
- } else if (schema instanceof zod.z.ZodArray) {
33
- return new zod.z.ZodArray({
34
- ...schema.def,
35
- element: mapElement(schema.def.element)
36
- });
37
- } else if (schema instanceof zod.z.ZodMap) {
38
- return new zod.z.ZodMap({
39
- ...schema.def,
40
- keyType: mapElement(schema.def.keyType),
41
- valueType: mapElement(schema.def.valueType)
42
- });
43
- } else if (schema instanceof zod.z.ZodSet) {
44
- return new zod.z.ZodSet({
45
- ...schema.def,
46
- valueType: mapElement(schema.def.valueType)
47
- });
48
- } else if (schema instanceof zod.z.ZodOptional) {
49
- return new zod.z.ZodOptional({
50
- ...schema.def,
51
- innerType: mapElement(schema.def.innerType)
52
- });
53
- } else if (schema instanceof zod.z.ZodNullable) {
54
- return new zod.z.ZodNullable({
55
- ...schema.def,
56
- innerType: mapElement(schema.def.innerType)
57
- });
58
- } else if (schema instanceof zod.z.ZodDefault) {
59
- return new zod.z.ZodDefault({
60
- ...schema.def,
61
- innerType: mapElement(schema.def.innerType)
62
- });
63
- } else if (schema instanceof zod.z.ZodReadonly) {
64
- return new zod.z.ZodReadonly({
65
- ...schema.def,
66
- innerType: mapElement(schema.def.innerType)
67
- });
68
- } else if (schema instanceof zod.z.ZodLazy) {
69
- return new zod.z.ZodLazy({
70
- ...schema.def,
71
- // NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
72
- getter: /* @__PURE__ */ RHF5FXGP_cjs.__name(() => mapElement(schema.def.getter()), "getter")
73
- });
74
- } else if (schema instanceof zod.z.ZodPromise) {
75
- return new zod.z.ZodPromise({
76
- ...schema.def,
77
- innerType: mapElement(schema.def.innerType)
78
- });
79
- } else if (schema instanceof zod.z.ZodCatch) {
80
- return new zod.z.ZodCatch({
81
- ...schema.def,
82
- innerType: mapElement(schema.def.innerType)
83
- });
84
- } else if (schema instanceof zod.z.ZodTuple) {
85
- return new zod.z.ZodTuple({
86
- ...schema.def,
87
- items: schema.def.items.map((item) => mapElement(item)),
88
- rest: schema.def.rest && mapElement(schema.def.rest)
89
- });
90
- } else if (schema instanceof zod.z.ZodUnion) {
91
- return new zod.z.ZodUnion({
92
- ...schema.def,
93
- options: schema.def.options.map((option) => mapElement(option))
94
- });
95
- } else if (schema instanceof zod.z.ZodIntersection) {
96
- return new zod.z.ZodIntersection({
97
- ...schema.def,
98
- right: mapElement(schema.def.right),
99
- left: mapElement(schema.def.left)
100
- });
101
- } else if (schema instanceof zod.z.ZodRecord) {
102
- return new zod.z.ZodRecord({
103
- ...schema.def,
104
- keyType: schema.def.keyType,
105
- valueType: mapElement(schema.def.valueType)
106
- });
107
- } else {
108
- return schema;
109
- }
110
- }
111
- RHF5FXGP_cjs.__name(mapInner, "mapInner");
112
- return fn(mapInner());
113
- }
114
- RHF5FXGP_cjs.__name(mapOnSchema, "mapOnSchema");
115
- function zodDeepPartial(schema) {
116
- return mapOnSchema(schema, (s) => s?.optional?.());
117
- }
118
- RHF5FXGP_cjs.__name(zodDeepPartial, "zodDeepPartial");
119
- function zodDeepRequired(schema) {
120
- return mapOnSchema(schema, (s) => s?.nonoptional?.());
121
- }
122
- RHF5FXGP_cjs.__name(zodDeepRequired, "zodDeepRequired");
123
-
124
- Object.defineProperty(exports, "brandSchema", {
125
- enumerable: true,
126
- get: function () { return RHF5FXGP_cjs.brandSchema; }
127
- });
128
- Object.defineProperty(exports, "createFunctionPointerSchema", {
129
- enumerable: true,
130
- get: function () { return RHF5FXGP_cjs.createFunctionPointerSchema; }
131
- });
132
- Object.defineProperty(exports, "customSchema", {
133
- enumerable: true,
134
- get: function () { return RHF5FXGP_cjs.customSchema; }
135
- });
136
- Object.defineProperty(exports, "functionSchema", {
137
- enumerable: true,
138
- get: function () { return RHF5FXGP_cjs.functionSchema; }
139
- });
140
- Object.defineProperty(exports, "isBrandedWith", {
141
- enumerable: true,
142
- get: function () { return RHF5FXGP_cjs.isBrandedWith; }
143
- });
144
- Object.defineProperty(exports, "schemaIsFunctionSchema", {
145
- enumerable: true,
146
- get: function () { return RHF5FXGP_cjs.schemaIsFunctionSchema; }
147
- });
148
- exports.mapOnSchema = mapOnSchema;
149
- exports.zodDeepPartial = zodDeepPartial;
150
- exports.zodDeepRequired = zodDeepRequired;
151
- //# sourceMappingURL=index.cjs.map
152
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.ts"],"names":["RESOLVING","Symbol","mapOnSchema","schema","fn","results","Map","mapElement","s","value","get","Error","undefined","set","result","mapInner","z","ZodObject","newShape","key","Object","entries","shape","def","ZodArray","element","ZodMap","keyType","valueType","ZodSet","ZodOptional","innerType","ZodNullable","ZodDefault","ZodReadonly","ZodLazy","getter","ZodPromise","ZodCatch","ZodTuple","items","map","item","rest","ZodUnion","options","option","ZodIntersection","right","left","ZodRecord","zodDeepPartial","optional","zodDeepRequired","nonoptional"],"mappings":";;;;;AAoBA,IAAMA,SAAAA,GAAYC,OAAO,uBAAA,CAAA;AAWlB,SAASC,WAAAA,CAAYC,QAAkBC,EAAAA,EAAkC;AAE5E,EAAA,MAAMC,OAAAA,uBAAcC,GAAAA,EAAAA;AAEpB,EAAA,SAASC,WAAWC,CAAAA,EAAW;AAC3B,IAAA,MAAMC,KAAAA,GAAQJ,OAAAA,CAAQK,GAAAA,CAAIF,CAAAA,CAAAA;AAC1B,IAAA,IAAIC,UAAUT,SAAAA,EAAW;AACrB,MAAA,MAAM,IAAIW,MAAM,kCAAA,CAAA;AACpB,IAAA,CAAA,MAAA,IAAWF,UAAUG,MAAAA,EAAW;AAC5B,MAAA,OAAOH,KAAAA;AACX,IAAA;AAEAJ,IAAAA,OAAAA,CAAQQ,GAAAA,CAAIL,GAAGR,SAAAA,CAAAA;AACf,IAAA,MAAMc,MAAAA,GAASZ,WAAAA,CAAYM,CAAAA,EAAGJ,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;AAIT,SAASE,gBAAwClD,MAAAA,EAAS;AAC7D,EAAA,OAAOD,YAAYC,MAAAA,EAAQ,CAACK,CAAAA,KAAOA,CAAAA,EAAW8C,eAAAA,CAAAA;AAClD;AAFgBD,mBAAAA,CAAAA,eAAAA,EAAAA,iBAAAA,CAAAA","file":"index.cjs","sourcesContent":["export * from './schema';\n\n/*\n Copyright 2024, Jaen - https://github.com/jaens\n Licensed under the Apache License, Version 2.0 (the \"License\");\n you may not use this file except in compliance with the License.\n You may obtain a copy of the License at\n http://www.apache.org/licenses/LICENSE-2.0\n Unless required by applicable law or agreed to in writing, software\n distributed under the License is distributed on an \"AS IS\" BASIS,\n WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n See the License for the specific language governing permissions and\n limitations under the License.\n\n https://gist.github.com/jaens/7e15ae1984bb338c86eb5e452dee3010\n*/\n\nimport { z } from 'zod';\nimport type { $ZodType } from 'zod/v4/core';\n\nconst RESOLVING = Symbol('mapOnSchema/resolving');\n\nexport function mapOnSchema<T extends $ZodType, TResult extends $ZodType>(\n schema: T,\n fn: (schema: $ZodType) => TResult,\n): TResult;\n\n/**\n * Applies {@link fn} to each element of the schema recursively, replacing every schema with its return value.\n * The rewriting is applied bottom-up (ie. {@link fn} will get called on \"children\" first).\n */\nexport function mapOnSchema(schema: $ZodType, fn: (schema: $ZodType) => $ZodType): $ZodType {\n // Cache results to support recursive schemas\n const results = new Map<$ZodType, $ZodType | typeof RESOLVING>();\n\n function mapElement(s: $ZodType) {\n const value = results.get(s);\n if (value === RESOLVING) {\n throw new Error('Recursive schema access detected');\n } else if (value !== undefined) {\n return value;\n }\n\n results.set(s, RESOLVING);\n const result = mapOnSchema(s, fn);\n results.set(s, result);\n return result;\n }\n\n function mapInner() {\n if (schema instanceof z.ZodObject) {\n const newShape: Record<string, $ZodType> = {};\n for (const [key, value] of Object.entries(schema.shape)) {\n newShape[key] = mapElement(value as $ZodType);\n }\n\n return new z.ZodObject({\n ...schema.def,\n shape: newShape,\n });\n } else if (schema instanceof z.ZodArray) {\n return new z.ZodArray({\n ...schema.def,\n element: mapElement(schema.def.element),\n });\n } else if (schema instanceof z.ZodMap) {\n return new z.ZodMap({\n ...schema.def,\n keyType: mapElement(schema.def.keyType),\n valueType: mapElement(schema.def.valueType),\n });\n } else if (schema instanceof z.ZodSet) {\n return new z.ZodSet({\n ...schema.def,\n valueType: mapElement(schema.def.valueType),\n });\n } else if (schema instanceof z.ZodOptional) {\n return new z.ZodOptional({\n ...schema.def,\n innerType: mapElement(schema.def.innerType),\n });\n } else if (schema instanceof z.ZodNullable) {\n return new z.ZodNullable({\n ...schema.def,\n innerType: mapElement(schema.def.innerType),\n });\n } else if (schema instanceof z.ZodDefault) {\n return new z.ZodDefault({\n ...schema.def,\n innerType: mapElement(schema.def.innerType),\n });\n } else if (schema instanceof z.ZodReadonly) {\n return new z.ZodReadonly({\n ...schema.def,\n innerType: mapElement(schema.def.innerType),\n });\n } else if (schema instanceof z.ZodLazy) {\n return new z.ZodLazy({\n ...schema.def,\n // NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas\n getter: () => mapElement(schema.def.getter()),\n });\n } else if (schema instanceof z.ZodPromise) {\n return new z.ZodPromise({\n ...schema.def,\n innerType: mapElement(schema.def.innerType),\n });\n } else if (schema instanceof z.ZodCatch) {\n return new z.ZodCatch({\n ...schema.def,\n innerType: mapElement(schema.def.innerType),\n });\n } else if (schema instanceof z.ZodTuple) {\n return new z.ZodTuple({\n ...schema.def,\n items: schema.def.items.map((item: $ZodType) => mapElement(item)),\n rest: schema.def.rest && mapElement(schema.def.rest),\n });\n } else if (schema instanceof z.ZodUnion) {\n return new z.ZodUnion({\n ...schema.def,\n options: schema.def.options.map((option: $ZodType) => mapElement(option)),\n });\n } else if (schema instanceof z.ZodIntersection) {\n return new z.ZodIntersection({\n ...schema.def,\n right: mapElement(schema.def.right),\n left: mapElement(schema.def.left),\n });\n } else if (schema instanceof z.ZodRecord) {\n return new z.ZodRecord({\n ...schema.def,\n keyType: schema.def.keyType as any,\n valueType: mapElement(schema.def.valueType),\n });\n } else {\n return schema;\n }\n }\n\n return fn(mapInner());\n}\n\nexport function zodDeepPartial<T extends z.ZodTypeAny>(schema: T): T {\n return mapOnSchema(schema, (s) => (s as any)?.optional?.()) as T;\n}\n\nexport function zodDeepRequired<T extends z.ZodTypeAny>(schema: T): T {\n return mapOnSchema(schema, (s) => (s as any)?.nonoptional?.()) as T;\n}\n"]}
package/dist/schema.cjs DELETED
@@ -1,32 +0,0 @@
1
- 'use strict';
2
-
3
- var RHF5FXGP_cjs = require('./RHF5FXGP.cjs');
4
-
5
-
6
-
7
- Object.defineProperty(exports, "brandSchema", {
8
- enumerable: true,
9
- get: function () { return RHF5FXGP_cjs.brandSchema; }
10
- });
11
- Object.defineProperty(exports, "createFunctionPointerSchema", {
12
- enumerable: true,
13
- get: function () { return RHF5FXGP_cjs.createFunctionPointerSchema; }
14
- });
15
- Object.defineProperty(exports, "customSchema", {
16
- enumerable: true,
17
- get: function () { return RHF5FXGP_cjs.customSchema; }
18
- });
19
- Object.defineProperty(exports, "functionSchema", {
20
- enumerable: true,
21
- get: function () { return RHF5FXGP_cjs.functionSchema; }
22
- });
23
- Object.defineProperty(exports, "isBrandedWith", {
24
- enumerable: true,
25
- get: function () { return RHF5FXGP_cjs.isBrandedWith; }
26
- });
27
- Object.defineProperty(exports, "schemaIsFunctionSchema", {
28
- enumerable: true,
29
- get: function () { return RHF5FXGP_cjs.schemaIsFunctionSchema; }
30
- });
31
- //# sourceMappingURL=schema.cjs.map
32
- //# sourceMappingURL=schema.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"schema.cjs"}