@layerzerolabs/zod-utils 0.0.52 → 0.0.53
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/.turbo/turbo-build.log +11 -11
- package/dist/{PWMOVI4D.js → GEP2SFVM.js} +5 -3
- package/dist/GEP2SFVM.js.map +1 -0
- package/dist/{65W4HDUY.cjs → JMPXWGC7.cjs} +6 -2
- package/dist/JMPXWGC7.cjs.map +1 -0
- package/dist/index.cjs +21 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/schema.cjs +15 -7
- package/dist/schema.d.ts +14 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -1
- package/package.json +4 -4
- package/src/schema.ts +10 -0
- package/dist/65W4HDUY.cjs.map +0 -1
- package/dist/PWMOVI4D.js.map +0 -1
package/.turbo/turbo-build.log
CHANGED
|
@@ -10,17 +10,17 @@
|
|
|
10
10
|
[34mCLI[39m Cleaning output folder
|
|
11
11
|
[34mCJS[39m Build start
|
|
12
12
|
[34mESM[39m Build start
|
|
13
|
-
[32mCJS[39m [1mdist/schema.cjs [22m[32m1.
|
|
14
|
-
[32mCJS[39m [1mdist/
|
|
15
|
-
[32mCJS[39m [1mdist/
|
|
13
|
+
[32mCJS[39m [1mdist/schema.cjs [22m[32m1.38 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m5.45 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/JMPXWGC7.cjs [22m[32m2.29 KB[39m
|
|
16
16
|
[32mCJS[39m [1mdist/schema.cjs.map [22m[32m71.00 B[39m
|
|
17
|
-
[32mCJS[39m [1mdist/65W4HDUY.cjs.map [22m[32m5.08 KB[39m
|
|
18
17
|
[32mCJS[39m [1mdist/index.cjs.map [22m[32m11.04 KB[39m
|
|
19
|
-
[32mCJS[39m
|
|
20
|
-
[
|
|
21
|
-
[32mESM[39m [1mdist/schema.js [22m[
|
|
22
|
-
[32mESM[39m [1mdist/
|
|
23
|
-
[32mESM[39m [1mdist/
|
|
18
|
+
[32mCJS[39m [1mdist/JMPXWGC7.cjs.map [22m[32m5.64 KB[39m
|
|
19
|
+
[32mCJS[39m ⚡️ Build success in 119ms
|
|
20
|
+
[32mESM[39m [1mdist/schema.js [22m[32m332.00 B[39m
|
|
21
|
+
[32mESM[39m [1mdist/index.js [22m[32m4.21 KB[39m
|
|
22
|
+
[32mESM[39m [1mdist/GEP2SFVM.js [22m[32m1.95 KB[39m
|
|
24
23
|
[32mESM[39m [1mdist/schema.js.map [22m[32m70.00 B[39m
|
|
25
|
-
[32mESM[39m [1mdist/
|
|
26
|
-
[32mESM[39m
|
|
24
|
+
[32mESM[39m [1mdist/index.js.map [22m[32m11.03 KB[39m
|
|
25
|
+
[32mESM[39m [1mdist/GEP2SFVM.js.map [22m[32m5.64 KB[39m
|
|
26
|
+
[32mESM[39m ⚡️ Build success in 119ms
|
|
@@ -36,7 +36,9 @@ var createExtendableFunctionPointerWithCurriedArgsSchema = /* @__PURE__ */ __nam
|
|
|
36
36
|
pointer: createFunctionPointerSchema().shape.pointer,
|
|
37
37
|
args: z.array(z.any())
|
|
38
38
|
}), "createExtendableFunctionPointerWithCurriedArgsSchema");
|
|
39
|
+
var bindFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindFunctionPointerArgs");
|
|
40
|
+
var bindPartialFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindPartialFunctionPointerArgs");
|
|
39
41
|
|
|
40
|
-
export { __name, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema };
|
|
41
|
-
//# sourceMappingURL=
|
|
42
|
-
//# sourceMappingURL=
|
|
42
|
+
export { __name, bindFunctionPointerArgs, bindPartialFunctionPointerArgs, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema };
|
|
43
|
+
//# sourceMappingURL=GEP2SFVM.js.map
|
|
44
|
+
//# sourceMappingURL=GEP2SFVM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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","pointer","createFunctionPointerWithArgsSchema","shape","args","createExtendableFunctionPointerWithCurriedArgsSchema","array","any","bindFunctionPointerArgs","params","bindPartialFunctionPointerArgs"],"mappings":";;;;AAwBA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,EAAEC,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;AAMX,CAAA,EA7B8B,gBAAA;AA+BvB,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,CAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA,MACvCf,CAAAA,CAAEC,MAAAA,CAAO;;AAELe,EAAAA,OAAAA,EAASJ,YAAAA;AACb,CAAA,CAAA,EAJuC,6BAAA;AAMpC,IAAMK,mCAAAA,mBAAsC,MAAA,CAAA,MAG/CjB,CAAAA,CAAEC,MAAAA,CAAO;EACLe,OAAAA,EAASD,2BAAAA,GAAiCG,KAAAA,CAAMF,OAAAA;AAChDG,EAAAA,IAAAA,EAAMP,YAAAA;AACV,CAAA,CAAA,EAN+C,qCAAA;AAa5C,IAAMQ,oDAAAA,mBAAuD,MAAA,CAAA,MAIhEpB,CAAAA,CAAEC,MAAAA,CAAO;EACLe,OAAAA,EAASD,2BAAAA,GAGLG,KAAAA,CAAMF,OAAAA;AACVG,EAAAA,IAAAA,EAAMnB,CAAAA,CAAEqB,KAAAA,CAAMrB,CAAAA,CAAEsB,GAAAA,EAAG;AACvB,CAAA,CAAA,EAVgE,sDAAA;AAY7D,IAAMC,uBAAAA,mBAA0B,MAAA,CAAA,CAA4BC,MAAAA,KAG7DA,MAAAA,EAHiC,yBAAA;AAKhC,IAAMC,8BAAAA,mBAAiC,MAAA,CAAA,CAA4BD,MAAAA,KAGpEA,MAAAA,EAHwC,gCAAA","file":"GEP2SFVM.js","sourcesContent":["import { z } from 'zod/v4';\n\nimport type {\n FunctionPointer,\n UnderlyingMethodOfFunctionPointer,\n} from '@layerzerolabs/common-utils';\n\ntype IsPromise<T> =\n T extends z.ZodOptional<infer I>\n ? IsPromise<I>\n : T extends z.ZodDefault<infer I>\n ? IsPromise<I>\n : T extends z.ZodNullable<infer I>\n ? IsPromise<I>\n : T extends z.ZodPromise<any>\n ? true\n : false;\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<\n (\n ...args: z.infer<Input>\n //z.ZodPromise<T> infers as T, not Promise<T>\n ) => IsPromise<Output> extends true ? Promise<z.infer<Output>> : z.infer<Output>\n >;\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>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer = FunctionPointer>() =>\n z.object({\n // FIXME this can be a real schema\n pointer: customSchema<T>(),\n });\n\nexport const createFunctionPointerWithArgsSchema = <\n T extends FunctionPointer = FunctionPointer,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<T>().shape.pointer,\n args: customSchema<Parameters<UnderlyingMethodOfFunctionPointer<T>>>(),\n });\n\nexport type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<\n ReturnType<<T extends (...args: any[]) => _ReturnType>() => T>\n>;\n\n// This type doesn't work correctly\nexport const createExtendableFunctionPointerWithCurriedArgsSchema = <\n _BaseArgs extends any[],\n _ReturnType extends Promise<any>,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<\n // FIXME type args correctly\n ConstrainedGenericFunctionPointer<_ReturnType>\n >().shape.pointer,\n args: z.array(z.any()),\n });\n\nexport const bindFunctionPointerArgs = <T extends FunctionPointer>(params: {\n pointer: T;\n args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;\n}) => params;\n\nexport const bindPartialFunctionPointerArgs = <T extends FunctionPointer>(params: {\n pointer: T;\n args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;\n}) => params;\n"]}
|
|
@@ -38,13 +38,17 @@ var createExtendableFunctionPointerWithCurriedArgsSchema = /* @__PURE__ */ __nam
|
|
|
38
38
|
pointer: createFunctionPointerSchema().shape.pointer,
|
|
39
39
|
args: v4.z.array(v4.z.any())
|
|
40
40
|
}), "createExtendableFunctionPointerWithCurriedArgsSchema");
|
|
41
|
+
var bindFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindFunctionPointerArgs");
|
|
42
|
+
var bindPartialFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindPartialFunctionPointerArgs");
|
|
41
43
|
|
|
42
44
|
exports.__name = __name;
|
|
45
|
+
exports.bindFunctionPointerArgs = bindFunctionPointerArgs;
|
|
46
|
+
exports.bindPartialFunctionPointerArgs = bindPartialFunctionPointerArgs;
|
|
43
47
|
exports.createExtendableFunctionPointerWithCurriedArgsSchema = createExtendableFunctionPointerWithCurriedArgsSchema;
|
|
44
48
|
exports.createFunctionPointerSchema = createFunctionPointerSchema;
|
|
45
49
|
exports.createFunctionPointerWithArgsSchema = createFunctionPointerWithArgsSchema;
|
|
46
50
|
exports.customSchema = customSchema;
|
|
47
51
|
exports.functionSchema = functionSchema;
|
|
48
52
|
exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
|
|
49
|
-
//# sourceMappingURL=
|
|
50
|
-
//# sourceMappingURL=
|
|
53
|
+
//# sourceMappingURL=JMPXWGC7.cjs.map
|
|
54
|
+
//# sourceMappingURL=JMPXWGC7.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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","pointer","createFunctionPointerWithArgsSchema","shape","args","createExtendableFunctionPointerWithCurriedArgsSchema","array","any","bindFunctionPointerArgs","params","bindPartialFunctionPointerArgs"],"mappings":";;;;;;AAwBA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,KAAEC,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;AAMX,CAAA,EA7B8B,gBAAA;AA+BvB,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,IAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA,MACvCf,IAAAA,CAAEC,MAAAA,CAAO;;AAELe,EAAAA,OAAAA,EAASJ,YAAAA;AACb,CAAA,CAAA,EAJuC,6BAAA;AAMpC,IAAMK,mCAAAA,mBAAsC,MAAA,CAAA,MAG/CjB,IAAAA,CAAEC,MAAAA,CAAO;EACLe,OAAAA,EAASD,2BAAAA,GAAiCG,KAAAA,CAAMF,OAAAA;AAChDG,EAAAA,IAAAA,EAAMP,YAAAA;AACV,CAAA,CAAA,EAN+C,qCAAA;AAa5C,IAAMQ,oDAAAA,mBAAuD,MAAA,CAAA,MAIhEpB,IAAAA,CAAEC,MAAAA,CAAO;EACLe,OAAAA,EAASD,2BAAAA,GAGLG,KAAAA,CAAMF,OAAAA;AACVG,EAAAA,IAAAA,EAAMnB,IAAAA,CAAEqB,KAAAA,CAAMrB,IAAAA,CAAEsB,GAAAA,EAAG;AACvB,CAAA,CAAA,EAVgE,sDAAA;AAY7D,IAAMC,uBAAAA,mBAA0B,MAAA,CAAA,CAA4BC,MAAAA,KAG7DA,MAAAA,EAHiC,yBAAA;AAKhC,IAAMC,8BAAAA,mBAAiC,MAAA,CAAA,CAA4BD,MAAAA,KAGpEA,MAAAA,EAHwC,gCAAA","file":"JMPXWGC7.cjs","sourcesContent":["import { z } from 'zod/v4';\n\nimport type {\n FunctionPointer,\n UnderlyingMethodOfFunctionPointer,\n} from '@layerzerolabs/common-utils';\n\ntype IsPromise<T> =\n T extends z.ZodOptional<infer I>\n ? IsPromise<I>\n : T extends z.ZodDefault<infer I>\n ? IsPromise<I>\n : T extends z.ZodNullable<infer I>\n ? IsPromise<I>\n : T extends z.ZodPromise<any>\n ? true\n : false;\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<\n (\n ...args: z.infer<Input>\n //z.ZodPromise<T> infers as T, not Promise<T>\n ) => IsPromise<Output> extends true ? Promise<z.infer<Output>> : z.infer<Output>\n >;\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>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer = FunctionPointer>() =>\n z.object({\n // FIXME this can be a real schema\n pointer: customSchema<T>(),\n });\n\nexport const createFunctionPointerWithArgsSchema = <\n T extends FunctionPointer = FunctionPointer,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<T>().shape.pointer,\n args: customSchema<Parameters<UnderlyingMethodOfFunctionPointer<T>>>(),\n });\n\nexport type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<\n ReturnType<<T extends (...args: any[]) => _ReturnType>() => T>\n>;\n\n// This type doesn't work correctly\nexport const createExtendableFunctionPointerWithCurriedArgsSchema = <\n _BaseArgs extends any[],\n _ReturnType extends Promise<any>,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<\n // FIXME type args correctly\n ConstrainedGenericFunctionPointer<_ReturnType>\n >().shape.pointer,\n args: z.array(z.any()),\n });\n\nexport const bindFunctionPointerArgs = <T extends FunctionPointer>(params: {\n pointer: T;\n args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;\n}) => params;\n\nexport const bindPartialFunctionPointerArgs = <T extends FunctionPointer>(params: {\n pointer: T;\n args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;\n}) => params;\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var JMPXWGC7_cjs = require('./JMPXWGC7.cjs');
|
|
4
4
|
var v4 = require('zod/v4');
|
|
5
5
|
|
|
6
6
|
var RESOLVING = Symbol("mapOnSchema/resolving");
|
|
@@ -18,7 +18,7 @@ function mapOnSchema(schema, fn) {
|
|
|
18
18
|
results.set(s, result);
|
|
19
19
|
return result;
|
|
20
20
|
}
|
|
21
|
-
|
|
21
|
+
JMPXWGC7_cjs.__name(mapElement, "mapElement");
|
|
22
22
|
function mapInner() {
|
|
23
23
|
if (schema instanceof v4.z.ZodObject) {
|
|
24
24
|
const newShape = {};
|
|
@@ -69,7 +69,7 @@ function mapOnSchema(schema, fn) {
|
|
|
69
69
|
return new v4.z.ZodLazy({
|
|
70
70
|
...schema.def,
|
|
71
71
|
// NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
|
|
72
|
-
getter: /* @__PURE__ */
|
|
72
|
+
getter: /* @__PURE__ */ JMPXWGC7_cjs.__name(() => mapElement(schema.def.getter()), "getter")
|
|
73
73
|
});
|
|
74
74
|
} else if (schema instanceof v4.z.ZodPromise) {
|
|
75
75
|
return new v4.z.ZodPromise({
|
|
@@ -108,42 +108,50 @@ function mapOnSchema(schema, fn) {
|
|
|
108
108
|
return schema;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
JMPXWGC7_cjs.__name(mapInner, "mapInner");
|
|
112
112
|
return fn(mapInner());
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
JMPXWGC7_cjs.__name(mapOnSchema, "mapOnSchema");
|
|
115
115
|
function zodDeepPartial(schema) {
|
|
116
116
|
return mapOnSchema(schema, (s) => s?.optional?.());
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
JMPXWGC7_cjs.__name(zodDeepPartial, "zodDeepPartial");
|
|
119
119
|
function zodDeepRequired(schema) {
|
|
120
120
|
return mapOnSchema(schema, (s) => s?.nonoptional?.());
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
JMPXWGC7_cjs.__name(zodDeepRequired, "zodDeepRequired");
|
|
123
123
|
|
|
124
|
+
Object.defineProperty(exports, "bindFunctionPointerArgs", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function () { return JMPXWGC7_cjs.bindFunctionPointerArgs; }
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, "bindPartialFunctionPointerArgs", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () { return JMPXWGC7_cjs.bindPartialFunctionPointerArgs; }
|
|
131
|
+
});
|
|
124
132
|
Object.defineProperty(exports, "createExtendableFunctionPointerWithCurriedArgsSchema", {
|
|
125
133
|
enumerable: true,
|
|
126
|
-
get: function () { return
|
|
134
|
+
get: function () { return JMPXWGC7_cjs.createExtendableFunctionPointerWithCurriedArgsSchema; }
|
|
127
135
|
});
|
|
128
136
|
Object.defineProperty(exports, "createFunctionPointerSchema", {
|
|
129
137
|
enumerable: true,
|
|
130
|
-
get: function () { return
|
|
138
|
+
get: function () { return JMPXWGC7_cjs.createFunctionPointerSchema; }
|
|
131
139
|
});
|
|
132
140
|
Object.defineProperty(exports, "createFunctionPointerWithArgsSchema", {
|
|
133
141
|
enumerable: true,
|
|
134
|
-
get: function () { return
|
|
142
|
+
get: function () { return JMPXWGC7_cjs.createFunctionPointerWithArgsSchema; }
|
|
135
143
|
});
|
|
136
144
|
Object.defineProperty(exports, "customSchema", {
|
|
137
145
|
enumerable: true,
|
|
138
|
-
get: function () { return
|
|
146
|
+
get: function () { return JMPXWGC7_cjs.customSchema; }
|
|
139
147
|
});
|
|
140
148
|
Object.defineProperty(exports, "functionSchema", {
|
|
141
149
|
enumerable: true,
|
|
142
|
-
get: function () { return
|
|
150
|
+
get: function () { return JMPXWGC7_cjs.functionSchema; }
|
|
143
151
|
});
|
|
144
152
|
Object.defineProperty(exports, "schemaIsFunctionSchema", {
|
|
145
153
|
enumerable: true,
|
|
146
|
-
get: function () { return
|
|
154
|
+
get: function () { return JMPXWGC7_cjs.schemaIsFunctionSchema; }
|
|
147
155
|
});
|
|
148
156
|
exports.mapOnSchema = mapOnSchema;
|
|
149
157
|
exports.zodDeepPartial = zodDeepPartial;
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,M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A,EAAS;AAC5D,EAAA,OAAOD,YAAYC,MAAAA,EAAQ,CAACK,CAAAA,KAAOA,CAAAA,EAAW4C,YAAAA,CAAAA;AAClD;AAFgBD,oBAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA;AAIT,SAASE,gBAAwClD,MAAAA,EAAS;AAC7D,EAAA,OAAOD,YAAYC,MAAAA,EAAQ,CAACK,CAAAA,KAAOA,CAAAA,EAAW8C,eAAAA,CAAAA;AAClD;AAFgBD,oBAAAA,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/v4';\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"]}
|
|
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,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AOD,YAAYC,MAAAA,EAAQ,CAACK,CAAAA,KAAOA,CAAAA,EAAW4C,YAAAA,CAAAA;AAClD;AAFgBD,mBAAAA,CAAAA,cAAAA,EAAAA,gBAAAA,CAAAA;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/v4';\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/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { __name } from './
|
|
2
|
-
export { createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './
|
|
1
|
+
import { __name } from './GEP2SFVM.js';
|
|
2
|
+
export { bindFunctionPointerArgs, bindPartialFunctionPointerArgs, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './GEP2SFVM.js';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
|
|
5
5
|
var RESOLVING = Symbol("mapOnSchema/resolving");
|
package/dist/schema.cjs
CHANGED
|
@@ -1,32 +1,40 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var JMPXWGC7_cjs = require('./JMPXWGC7.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
Object.defineProperty(exports, "bindFunctionPointerArgs", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return JMPXWGC7_cjs.bindFunctionPointerArgs; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "bindPartialFunctionPointerArgs", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return JMPXWGC7_cjs.bindPartialFunctionPointerArgs; }
|
|
14
|
+
});
|
|
7
15
|
Object.defineProperty(exports, "createExtendableFunctionPointerWithCurriedArgsSchema", {
|
|
8
16
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
17
|
+
get: function () { return JMPXWGC7_cjs.createExtendableFunctionPointerWithCurriedArgsSchema; }
|
|
10
18
|
});
|
|
11
19
|
Object.defineProperty(exports, "createFunctionPointerSchema", {
|
|
12
20
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
21
|
+
get: function () { return JMPXWGC7_cjs.createFunctionPointerSchema; }
|
|
14
22
|
});
|
|
15
23
|
Object.defineProperty(exports, "createFunctionPointerWithArgsSchema", {
|
|
16
24
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
25
|
+
get: function () { return JMPXWGC7_cjs.createFunctionPointerWithArgsSchema; }
|
|
18
26
|
});
|
|
19
27
|
Object.defineProperty(exports, "customSchema", {
|
|
20
28
|
enumerable: true,
|
|
21
|
-
get: function () { return
|
|
29
|
+
get: function () { return JMPXWGC7_cjs.customSchema; }
|
|
22
30
|
});
|
|
23
31
|
Object.defineProperty(exports, "functionSchema", {
|
|
24
32
|
enumerable: true,
|
|
25
|
-
get: function () { return
|
|
33
|
+
get: function () { return JMPXWGC7_cjs.functionSchema; }
|
|
26
34
|
});
|
|
27
35
|
Object.defineProperty(exports, "schemaIsFunctionSchema", {
|
|
28
36
|
enumerable: true,
|
|
29
|
-
get: function () { return
|
|
37
|
+
get: function () { return JMPXWGC7_cjs.schemaIsFunctionSchema; }
|
|
30
38
|
});
|
|
31
39
|
//# sourceMappingURL=schema.cjs.map
|
|
32
40
|
//# sourceMappingURL=schema.cjs.map
|
package/dist/schema.d.ts
CHANGED
|
@@ -20,5 +20,19 @@ export declare const createExtendableFunctionPointerWithCurriedArgsSchema: <_Bas
|
|
|
20
20
|
pointer: z.ZodType<ConstrainedGenericFunctionPointer<_ReturnType>, unknown, z.core.$ZodTypeInternals<ConstrainedGenericFunctionPointer<_ReturnType>, unknown>>;
|
|
21
21
|
args: z.ZodArray<z.ZodAny>;
|
|
22
22
|
}, z.core.$strip>;
|
|
23
|
+
export declare const bindFunctionPointerArgs: <T extends FunctionPointer>(params: {
|
|
24
|
+
pointer: T;
|
|
25
|
+
args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
|
|
26
|
+
}) => {
|
|
27
|
+
pointer: T;
|
|
28
|
+
args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
|
|
29
|
+
};
|
|
30
|
+
export declare const bindPartialFunctionPointerArgs: <T extends FunctionPointer>(params: {
|
|
31
|
+
pointer: T;
|
|
32
|
+
args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;
|
|
33
|
+
}) => {
|
|
34
|
+
pointer: T;
|
|
35
|
+
args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;
|
|
36
|
+
};
|
|
23
37
|
export {};
|
|
24
38
|
//# sourceMappingURL=schema.d.ts.map
|
package/dist/schema.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,QAAQ,CAAC;AAE3B,OAAO,KAAK,EACR,eAAe,EACf,iCAAiC,EACpC,MAAM,6BAA6B,CAAC;AAErC,KAAK,SAAS,CAAC,CAAC,IACZ,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAC1B,SAAS,CAAC,CAAC,CAAC,GACZ,CAAC,SAAS,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,GAC7B,SAAS,CAAC,CAAC,CAAC,GACZ,CAAC,SAAS,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,GAC9B,SAAS,CAAC,CAAC,CAAC,GACZ,CAAC,SAAS,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uB,GAAI,CAAC,SAAS,eAAe,EAAE,QAAQ;IACvE,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,UAAU,CAAC,iCAAiC,CAAC,CAAC,CAAC,CAAC,CAAC;CAC1D;aAFY,CAAC;UACJ,UAAU,CAAC,iCAAiC,CAAC,CAAC,CAAC,CAAC;CAC9C,CAAC;AAEb,eAAO,MAAM,8BAA8B,GAAI,CAAC,SAAS,eAAe,EAAE,QAAQ;IAC9E,OAAO,EAAE,CAAC,CAAC;IACX,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,iCAAiC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACnE;aAFY,CAAC;UACJ,OAAO,CAAC,UAAU,CAAC,iCAAiC,CAAC,CAAC,CAAC,CAAC,CAAC;CACvD,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './
|
|
1
|
+
export { bindFunctionPointerArgs, bindPartialFunctionPointerArgs, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './GEP2SFVM.js';
|
|
2
2
|
//# sourceMappingURL=schema.js.map
|
|
3
3
|
//# sourceMappingURL=schema.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/zod-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"zod": "^3.23.8",
|
|
18
|
-
"@layerzerolabs/common-utils": "0.0.
|
|
18
|
+
"@layerzerolabs/common-utils": "0.0.53"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"tsup": "^8.4.0",
|
|
22
|
-
"@layerzerolabs/typescript-configuration": "0.0.
|
|
23
|
-
"@layerzerolabs/tsup-configuration": "0.0.
|
|
22
|
+
"@layerzerolabs/typescript-configuration": "0.0.53",
|
|
23
|
+
"@layerzerolabs/tsup-configuration": "0.0.53"
|
|
24
24
|
},
|
|
25
25
|
"publishConfig": {
|
|
26
26
|
"access": "restricted",
|
package/src/schema.ts
CHANGED
|
@@ -95,3 +95,13 @@ export const createExtendableFunctionPointerWithCurriedArgsSchema = <
|
|
|
95
95
|
>().shape.pointer,
|
|
96
96
|
args: z.array(z.any()),
|
|
97
97
|
});
|
|
98
|
+
|
|
99
|
+
export const bindFunctionPointerArgs = <T extends FunctionPointer>(params: {
|
|
100
|
+
pointer: T;
|
|
101
|
+
args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
|
|
102
|
+
}) => params;
|
|
103
|
+
|
|
104
|
+
export const bindPartialFunctionPointerArgs = <T extends FunctionPointer>(params: {
|
|
105
|
+
pointer: T;
|
|
106
|
+
args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;
|
|
107
|
+
}) => params;
|
package/dist/65W4HDUY.cjs.map
DELETED
|
@@ -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","pointer","createFunctionPointerWithArgsSchema","shape","args","createExtendableFunctionPointerWithCurriedArgsSchema","array","any"],"mappings":";;;;;;AAwBA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA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AASD,2BAAAA,GAGLG,KAAAA,CAAMF,OAAAA;AACVG,EAAAA,IAAAA,EAAMnB,IAAAA,CAAEqB,KAAAA,CAAMrB,IAAAA,CAAEsB,GAAAA,EAAG;AACvB,CAAA,CAAA,EAVgE,sDAAA","file":"65W4HDUY.cjs","sourcesContent":["import { z } from 'zod/v4';\n\nimport type {\n FunctionPointer,\n UnderlyingMethodOfFunctionPointer,\n} from '@layerzerolabs/common-utils';\n\ntype IsPromise<T> =\n T extends z.ZodOptional<infer I>\n ? IsPromise<I>\n : T extends z.ZodDefault<infer I>\n ? IsPromise<I>\n : T extends z.ZodNullable<infer I>\n ? IsPromise<I>\n : T extends z.ZodPromise<any>\n ? true\n : false;\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<\n (\n ...args: z.infer<Input>\n //z.ZodPromise<T> infers as T, not Promise<T>\n ) => IsPromise<Output> extends true ? Promise<z.infer<Output>> : z.infer<Output>\n >;\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>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer = FunctionPointer>() =>\n z.object({\n // FIXME this can be a real schema\n pointer: customSchema<T>(),\n });\n\nexport const createFunctionPointerWithArgsSchema = <\n T extends FunctionPointer = FunctionPointer,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<T>().shape.pointer,\n args: customSchema<Parameters<UnderlyingMethodOfFunctionPointer<T>>>(),\n });\n\nexport type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<\n ReturnType<<T extends (...args: any[]) => _ReturnType>() => T>\n>;\n\n// This type doesn't work correctly\nexport const createExtendableFunctionPointerWithCurriedArgsSchema = <\n _BaseArgs extends any[],\n _ReturnType extends Promise<any>,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<\n // FIXME type args correctly\n ConstrainedGenericFunctionPointer<_ReturnType>\n >().shape.pointer,\n args: z.array(z.any()),\n });\n"]}
|
package/dist/PWMOVI4D.js.map
DELETED
|
@@ -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","pointer","createFunctionPointerWithArgsSchema","shape","args","createExtendableFunctionPointerWithCurriedArgsSchema","array","any"],"mappings":";;;;AAwBA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,EAAEC,MAAAA,CAAO;AACjBJ,IAAAA,KAAAA;AACAC,IAAAA;GACJ,CAAA;AACAI,EAAAA,MAAAA,CAAOC,cAAAA,CAAeJ,KAAKL,iBAAAA,EAAmB;IAAEU,KA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PWMOVI4D.js","sourcesContent":["import { z } from 'zod/v4';\n\nimport type {\n FunctionPointer,\n UnderlyingMethodOfFunctionPointer,\n} from '@layerzerolabs/common-utils';\n\ntype IsPromise<T> =\n T extends z.ZodOptional<infer I>\n ? IsPromise<I>\n : T extends z.ZodDefault<infer I>\n ? IsPromise<I>\n : T extends z.ZodNullable<infer I>\n ? IsPromise<I>\n : T extends z.ZodPromise<any>\n ? true\n : false;\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<\n (\n ...args: z.infer<Input>\n //z.ZodPromise<T> infers as T, not Promise<T>\n ) => IsPromise<Output> extends true ? Promise<z.infer<Output>> : z.infer<Output>\n >;\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>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer = FunctionPointer>() =>\n z.object({\n // FIXME this can be a real schema\n pointer: customSchema<T>(),\n });\n\nexport const createFunctionPointerWithArgsSchema = <\n T extends FunctionPointer = FunctionPointer,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<T>().shape.pointer,\n args: customSchema<Parameters<UnderlyingMethodOfFunctionPointer<T>>>(),\n });\n\nexport type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<\n ReturnType<<T extends (...args: any[]) => _ReturnType>() => T>\n>;\n\n// This type doesn't work correctly\nexport const createExtendableFunctionPointerWithCurriedArgsSchema = <\n _BaseArgs extends any[],\n _ReturnType extends Promise<any>,\n>() =>\n z.object({\n pointer: createFunctionPointerSchema<\n // FIXME type args correctly\n ConstrainedGenericFunctionPointer<_ReturnType>\n >().shape.pointer,\n args: z.array(z.any()),\n });\n"]}
|