@layerzerolabs/zod-utils 0.0.32 → 0.0.33
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/6OCBD2DH.js +42 -0
- package/dist/6OCBD2DH.js.map +1 -0
- package/dist/{CAXEKYBD.cjs → O5ID4FPX.cjs} +17 -2
- package/dist/O5ID4FPX.cjs.map +1 -0
- package/dist/index.cjs +22 -10
- package/dist/index.js +2 -2
- package/dist/schema.cjs +16 -4
- package/dist/schema.d.ts +13 -0
- package/dist/schema.d.ts.map +1 -1
- package/dist/schema.js +1 -1
- package/package.json +5 -4
- package/src/schema.ts +36 -0
- package/dist/CAXEKYBD.cjs.map +0 -1
- package/dist/NIWFGLF4.js +0 -30
- package/dist/NIWFGLF4.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/
|
|
14
|
-
[32mCJS[39m [1mdist/
|
|
15
|
-
[32mCJS[39m [1mdist/
|
|
16
|
-
[32mCJS[39m [1mdist/index.cjs.map [22m[32m11.04 KB[39m
|
|
17
|
-
[32mCJS[39m [1mdist/CAXEKYBD.cjs.map [22m[32m3.00 KB[39m
|
|
13
|
+
[32mCJS[39m [1mdist/schema.cjs [22m[32m1.07 KB[39m
|
|
14
|
+
[32mCJS[39m [1mdist/index.cjs [22m[32m5.14 KB[39m
|
|
15
|
+
[32mCJS[39m [1mdist/O5ID4FPX.cjs [22m[32m1.95 KB[39m
|
|
18
16
|
[32mCJS[39m [1mdist/schema.cjs.map [22m[32m71.00 B[39m
|
|
19
|
-
[32mCJS[39m
|
|
20
|
-
[
|
|
21
|
-
[
|
|
22
|
-
[32mESM[39m [1mdist/
|
|
17
|
+
[32mCJS[39m [1mdist/index.cjs.map [22m[32m11.04 KB[39m
|
|
18
|
+
[32mCJS[39m [1mdist/O5ID4FPX.cjs.map [22m[32m4.83 KB[39m
|
|
19
|
+
[32mCJS[39m ⚡️ Build success in 169ms
|
|
20
|
+
[32mESM[39m [1mdist/schema.js [22m[32m275.00 B[39m
|
|
21
|
+
[32mESM[39m [1mdist/index.js [22m[32m4.15 KB[39m
|
|
22
|
+
[32mESM[39m [1mdist/6OCBD2DH.js [22m[32m1.68 KB[39m
|
|
23
23
|
[32mESM[39m [1mdist/schema.js.map [22m[32m70.00 B[39m
|
|
24
24
|
[32mESM[39m [1mdist/index.js.map [22m[32m11.03 KB[39m
|
|
25
|
-
[32mESM[39m [1mdist/
|
|
26
|
-
[32mESM[39m ⚡️ Build success in
|
|
25
|
+
[32mESM[39m [1mdist/6OCBD2DH.js.map [22m[32m4.83 KB[39m
|
|
26
|
+
[32mESM[39m ⚡️ Build success in 169ms
|
package/dist/6OCBD2DH.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { z } from 'zod/v4';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
+
var functionSchemaTag = Symbol("__FUNCTION_SCHEMA_TAG");
|
|
6
|
+
var functionSchema = /* @__PURE__ */ __name(({ input, output }) => {
|
|
7
|
+
const obj = z.object({
|
|
8
|
+
input,
|
|
9
|
+
output
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(obj, functionSchemaTag, {
|
|
12
|
+
value: true,
|
|
13
|
+
writable: false
|
|
14
|
+
});
|
|
15
|
+
obj.parse = (i) => {
|
|
16
|
+
if (typeof i !== "function") {
|
|
17
|
+
throw new Error(`${i} is not a function`);
|
|
18
|
+
}
|
|
19
|
+
return i;
|
|
20
|
+
};
|
|
21
|
+
return obj;
|
|
22
|
+
}, "functionSchema");
|
|
23
|
+
var schemaIsFunctionSchema = /* @__PURE__ */ __name((schema) => {
|
|
24
|
+
return Object.hasOwn(schema, functionSchemaTag);
|
|
25
|
+
}, "schemaIsFunctionSchema");
|
|
26
|
+
var customSchema = /* @__PURE__ */ __name((validate) => z.custom(validate), "customSchema");
|
|
27
|
+
var createFunctionPointerSchema = /* @__PURE__ */ __name(() => z.object({
|
|
28
|
+
// FIXME this can be a real schema
|
|
29
|
+
pointer: customSchema()
|
|
30
|
+
}), "createFunctionPointerSchema");
|
|
31
|
+
var createFunctionPointerWithArgsSchema = /* @__PURE__ */ __name(() => z.object({
|
|
32
|
+
pointer: createFunctionPointerSchema().shape.pointer,
|
|
33
|
+
args: customSchema()
|
|
34
|
+
}), "createFunctionPointerWithArgsSchema");
|
|
35
|
+
var createExtendableFunctionPointerWithCurriedArgsSchema = /* @__PURE__ */ __name(() => z.object({
|
|
36
|
+
pointer: createFunctionPointerSchema().shape.pointer,
|
|
37
|
+
args: z.array(z.any())
|
|
38
|
+
}), "createExtendableFunctionPointerWithCurriedArgsSchema");
|
|
39
|
+
|
|
40
|
+
export { __name, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema };
|
|
41
|
+
//# sourceMappingURL=6OCBD2DH.js.map
|
|
42
|
+
//# sourceMappingURL=6OCBD2DH.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"],"mappings":";;;;AAkBA,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","file":"6OCBD2DH.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\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"]}
|
|
@@ -26,10 +26,25 @@ var schemaIsFunctionSchema = /* @__PURE__ */ __name((schema) => {
|
|
|
26
26
|
return Object.hasOwn(schema, functionSchemaTag);
|
|
27
27
|
}, "schemaIsFunctionSchema");
|
|
28
28
|
var customSchema = /* @__PURE__ */ __name((validate) => v4.z.custom(validate), "customSchema");
|
|
29
|
+
var createFunctionPointerSchema = /* @__PURE__ */ __name(() => v4.z.object({
|
|
30
|
+
// FIXME this can be a real schema
|
|
31
|
+
pointer: customSchema()
|
|
32
|
+
}), "createFunctionPointerSchema");
|
|
33
|
+
var createFunctionPointerWithArgsSchema = /* @__PURE__ */ __name(() => v4.z.object({
|
|
34
|
+
pointer: createFunctionPointerSchema().shape.pointer,
|
|
35
|
+
args: customSchema()
|
|
36
|
+
}), "createFunctionPointerWithArgsSchema");
|
|
37
|
+
var createExtendableFunctionPointerWithCurriedArgsSchema = /* @__PURE__ */ __name(() => v4.z.object({
|
|
38
|
+
pointer: createFunctionPointerSchema().shape.pointer,
|
|
39
|
+
args: v4.z.array(v4.z.any())
|
|
40
|
+
}), "createExtendableFunctionPointerWithCurriedArgsSchema");
|
|
29
41
|
|
|
30
42
|
exports.__name = __name;
|
|
43
|
+
exports.createExtendableFunctionPointerWithCurriedArgsSchema = createExtendableFunctionPointerWithCurriedArgsSchema;
|
|
44
|
+
exports.createFunctionPointerSchema = createFunctionPointerSchema;
|
|
45
|
+
exports.createFunctionPointerWithArgsSchema = createFunctionPointerWithArgsSchema;
|
|
31
46
|
exports.customSchema = customSchema;
|
|
32
47
|
exports.functionSchema = functionSchema;
|
|
33
48
|
exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
|
|
34
|
-
//# sourceMappingURL=
|
|
35
|
-
//# sourceMappingURL=
|
|
49
|
+
//# sourceMappingURL=O5ID4FPX.cjs.map
|
|
50
|
+
//# sourceMappingURL=O5ID4FPX.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"],"mappings":";;;;;;AAkBA,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","file":"O5ID4FPX.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\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/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var O5ID4FPX_cjs = require('./O5ID4FPX.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
|
+
O5ID4FPX_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__ */ O5ID4FPX_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,30 +108,42 @@ function mapOnSchema(schema, fn) {
|
|
|
108
108
|
return schema;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
O5ID4FPX_cjs.__name(mapInner, "mapInner");
|
|
112
112
|
return fn(mapInner());
|
|
113
113
|
}
|
|
114
|
-
|
|
114
|
+
O5ID4FPX_cjs.__name(mapOnSchema, "mapOnSchema");
|
|
115
115
|
function zodDeepPartial(schema) {
|
|
116
116
|
return mapOnSchema(schema, (s) => s?.optional?.());
|
|
117
117
|
}
|
|
118
|
-
|
|
118
|
+
O5ID4FPX_cjs.__name(zodDeepPartial, "zodDeepPartial");
|
|
119
119
|
function zodDeepRequired(schema) {
|
|
120
120
|
return mapOnSchema(schema, (s) => s?.nonoptional?.());
|
|
121
121
|
}
|
|
122
|
-
|
|
122
|
+
O5ID4FPX_cjs.__name(zodDeepRequired, "zodDeepRequired");
|
|
123
123
|
|
|
124
|
+
Object.defineProperty(exports, "createExtendableFunctionPointerWithCurriedArgsSchema", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function () { return O5ID4FPX_cjs.createExtendableFunctionPointerWithCurriedArgsSchema; }
|
|
127
|
+
});
|
|
128
|
+
Object.defineProperty(exports, "createFunctionPointerSchema", {
|
|
129
|
+
enumerable: true,
|
|
130
|
+
get: function () { return O5ID4FPX_cjs.createFunctionPointerSchema; }
|
|
131
|
+
});
|
|
132
|
+
Object.defineProperty(exports, "createFunctionPointerWithArgsSchema", {
|
|
133
|
+
enumerable: true,
|
|
134
|
+
get: function () { return O5ID4FPX_cjs.createFunctionPointerWithArgsSchema; }
|
|
135
|
+
});
|
|
124
136
|
Object.defineProperty(exports, "customSchema", {
|
|
125
137
|
enumerable: true,
|
|
126
|
-
get: function () { return
|
|
138
|
+
get: function () { return O5ID4FPX_cjs.customSchema; }
|
|
127
139
|
});
|
|
128
140
|
Object.defineProperty(exports, "functionSchema", {
|
|
129
141
|
enumerable: true,
|
|
130
|
-
get: function () { return
|
|
142
|
+
get: function () { return O5ID4FPX_cjs.functionSchema; }
|
|
131
143
|
});
|
|
132
144
|
Object.defineProperty(exports, "schemaIsFunctionSchema", {
|
|
133
145
|
enumerable: true,
|
|
134
|
-
get: function () { return
|
|
146
|
+
get: function () { return O5ID4FPX_cjs.schemaIsFunctionSchema; }
|
|
135
147
|
});
|
|
136
148
|
exports.mapOnSchema = mapOnSchema;
|
|
137
149
|
exports.zodDeepPartial = zodDeepPartial;
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { __name } from './
|
|
2
|
-
export { customSchema, functionSchema, schemaIsFunctionSchema } from './
|
|
1
|
+
import { __name } from './6OCBD2DH.js';
|
|
2
|
+
export { createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './6OCBD2DH.js';
|
|
3
3
|
import { z } from 'zod/v4';
|
|
4
4
|
|
|
5
5
|
var RESOLVING = Symbol("mapOnSchema/resolving");
|
package/dist/schema.cjs
CHANGED
|
@@ -1,20 +1,32 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var O5ID4FPX_cjs = require('./O5ID4FPX.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
Object.defineProperty(exports, "createExtendableFunctionPointerWithCurriedArgsSchema", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return O5ID4FPX_cjs.createExtendableFunctionPointerWithCurriedArgsSchema; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "createFunctionPointerSchema", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return O5ID4FPX_cjs.createFunctionPointerSchema; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "createFunctionPointerWithArgsSchema", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return O5ID4FPX_cjs.createFunctionPointerWithArgsSchema; }
|
|
18
|
+
});
|
|
7
19
|
Object.defineProperty(exports, "customSchema", {
|
|
8
20
|
enumerable: true,
|
|
9
|
-
get: function () { return
|
|
21
|
+
get: function () { return O5ID4FPX_cjs.customSchema; }
|
|
10
22
|
});
|
|
11
23
|
Object.defineProperty(exports, "functionSchema", {
|
|
12
24
|
enumerable: true,
|
|
13
|
-
get: function () { return
|
|
25
|
+
get: function () { return O5ID4FPX_cjs.functionSchema; }
|
|
14
26
|
});
|
|
15
27
|
Object.defineProperty(exports, "schemaIsFunctionSchema", {
|
|
16
28
|
enumerable: true,
|
|
17
|
-
get: function () { return
|
|
29
|
+
get: function () { return O5ID4FPX_cjs.schemaIsFunctionSchema; }
|
|
18
30
|
});
|
|
19
31
|
//# sourceMappingURL=schema.cjs.map
|
|
20
32
|
//# sourceMappingURL=schema.cjs.map
|
package/dist/schema.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
|
+
import type { FunctionPointer, UnderlyingMethodOfFunctionPointer } from '@layerzerolabs/common-utils';
|
|
2
3
|
type IsPromise<T> = T extends z.ZodOptional<infer I> ? IsPromise<I> : T extends z.ZodDefault<infer I> ? IsPromise<I> : T extends z.ZodNullable<infer I> ? IsPromise<I> : T extends z.ZodPromise<any> ? true : false;
|
|
3
4
|
export declare const functionSchema: <Input extends z.ZodTuple, Output extends z.ZodType>({ input, output, }: {
|
|
4
5
|
input: Input;
|
|
@@ -6,5 +7,17 @@ export declare const functionSchema: <Input extends z.ZodTuple, Output extends z
|
|
|
6
7
|
}) => z.ZodType<(...args: z.infer<Input>) => IsPromise<Output> extends true ? Promise<z.infer<Output>> : z.infer<Output>>;
|
|
7
8
|
export declare const schemaIsFunctionSchema: (schema: z.ZodType) => schema is ReturnType<typeof functionSchema>;
|
|
8
9
|
export declare const customSchema: <T>(validate?: (data: any) => T) => z.ZodType<T>;
|
|
10
|
+
export declare const createFunctionPointerSchema: <T extends FunctionPointer = FunctionPointer>() => z.ZodObject<{
|
|
11
|
+
pointer: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>;
|
|
12
|
+
}, z.core.$strip>;
|
|
13
|
+
export declare const createFunctionPointerWithArgsSchema: <T extends FunctionPointer = FunctionPointer>() => z.ZodObject<{
|
|
14
|
+
pointer: z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>;
|
|
15
|
+
args: z.ZodType<Parameters<UnderlyingMethodOfFunctionPointer<T>>, unknown, z.core.$ZodTypeInternals<Parameters<UnderlyingMethodOfFunctionPointer<T>>, unknown>>;
|
|
16
|
+
}, z.core.$strip>;
|
|
17
|
+
export type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<ReturnType<(<T extends (...args: any[]) => _ReturnType>() => T)>>;
|
|
18
|
+
export declare const createExtendableFunctionPointerWithCurriedArgsSchema: <_BaseArgs extends any[], _ReturnType extends Promise<any>>() => z.ZodObject<{
|
|
19
|
+
pointer: z.ZodType<ConstrainedGenericFunctionPointer<_ReturnType>, unknown, z.core.$ZodTypeInternals<ConstrainedGenericFunctionPointer<_ReturnType>, unknown>>;
|
|
20
|
+
args: z.ZodArray<z.ZodAny>;
|
|
21
|
+
}, z.core.$strip>;
|
|
9
22
|
export {};
|
|
10
23
|
//# 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,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,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GACzB,IAAI,GACJ,KAAK,CAAC;AAKtB,eAAO,MAAM,cAAc,GAAI,KAAK,SAAS,CAAC,CAAC,QAAQ,EAAE,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,oBAGhF;IACC,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB,KAiB4B,CAAC,CAAC,OAAO,CAC9B,CACI,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAEtB,SAAS,CAAC,MAAM,CAAC,SAAS,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAEvF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAC/B,QAAQ,CAAC,CAAC,OAAO,KAClB,MAAM,IAAI,UAAU,CAAC,OAAO,cAAc,CAE5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,KAC9B,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
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,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,GACzB,IAAI,GACJ,KAAK,CAAC;AAKtB,eAAO,MAAM,cAAc,GAAI,KAAK,SAAS,CAAC,CAAC,QAAQ,EAAE,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,oBAGhF;IACC,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;CAClB,KAiB4B,CAAC,CAAC,OAAO,CAC9B,CACI,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAEtB,SAAS,CAAC,MAAM,CAAC,SAAS,IAAI,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAEvF,CAAC;AAEF,eAAO,MAAM,sBAAsB,GAC/B,QAAQ,CAAC,CAAC,OAAO,KAClB,MAAM,IAAI,UAAU,CAAC,OAAO,cAAc,CAE5C,CAAC;AAEF,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,WAAW,CAAC,IAAI,EAAE,GAAG,KAAK,CAAC,KAC9B,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AAE1C,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,eAAe,GAAG,eAAe;;iBAIjF,CAAC;AAEP,eAAO,MAAM,mCAAmC,GAC5C,CAAC,SAAS,eAAe,GAAG,eAAe;;;iBAKzC,CAAC;AAEP,MAAM,MAAM,iCAAiC,CAAC,WAAW,SAAS,OAAO,CAAC,GAAG,CAAC,IAAI,eAAe,CAC7F,UAAU,EAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,WAAW,OAAO,CAAC,EAAC,CACjE,CAAC;AAGF,eAAO,MAAM,oDAAoD,GAC7D,SAAS,SAAS,GAAG,EAAE,EACvB,WAAW,SAAS,OAAO,CAAC,GAAG,CAAC;;;iBAQ9B,CAAC"}
|
package/dist/schema.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { customSchema, functionSchema, schemaIsFunctionSchema } from './
|
|
1
|
+
export { createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './6OCBD2DH.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.33",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -14,12 +14,13 @@
|
|
|
14
14
|
"module": "./dist/index.js",
|
|
15
15
|
"types": "./dist/index.d.ts",
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"zod": "^3.23.8"
|
|
17
|
+
"zod": "^3.23.8",
|
|
18
|
+
"@layerzerolabs/common-utils": "0.0.33"
|
|
18
19
|
},
|
|
19
20
|
"devDependencies": {
|
|
20
21
|
"tsup": "^8.4.0",
|
|
21
|
-
"@layerzerolabs/typescript-configuration": "0.0.
|
|
22
|
-
"@layerzerolabs/tsup-configuration": "0.0.
|
|
22
|
+
"@layerzerolabs/typescript-configuration": "0.0.33",
|
|
23
|
+
"@layerzerolabs/tsup-configuration": "0.0.33"
|
|
23
24
|
},
|
|
24
25
|
"publishConfig": {
|
|
25
26
|
"access": "restricted",
|
package/src/schema.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import { z } from 'zod/v4';
|
|
2
2
|
|
|
3
|
+
import type {
|
|
4
|
+
FunctionPointer,
|
|
5
|
+
UnderlyingMethodOfFunctionPointer,
|
|
6
|
+
} from '@layerzerolabs/common-utils';
|
|
7
|
+
|
|
3
8
|
type IsPromise<T> =
|
|
4
9
|
T extends z.ZodOptional<infer I>
|
|
5
10
|
? IsPromise<I>
|
|
@@ -53,3 +58,34 @@ export const schemaIsFunctionSchema = (
|
|
|
53
58
|
|
|
54
59
|
export const customSchema = <T>(validate?: (data: any) => T) =>
|
|
55
60
|
z.custom<T>(validate) as z.ZodType<T>;
|
|
61
|
+
|
|
62
|
+
export const createFunctionPointerSchema = <T extends FunctionPointer = FunctionPointer>() =>
|
|
63
|
+
z.object({
|
|
64
|
+
// FIXME this can be a real schema
|
|
65
|
+
pointer: customSchema<T>(),
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
export const createFunctionPointerWithArgsSchema = <
|
|
69
|
+
T extends FunctionPointer = FunctionPointer,
|
|
70
|
+
>() =>
|
|
71
|
+
z.object({
|
|
72
|
+
pointer: createFunctionPointerSchema<T>().shape.pointer,
|
|
73
|
+
args: customSchema<Parameters<UnderlyingMethodOfFunctionPointer<T>>>(),
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
export type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<
|
|
77
|
+
ReturnType<<T extends (...args: any[]) => _ReturnType>() => T>
|
|
78
|
+
>;
|
|
79
|
+
|
|
80
|
+
// This type doesn't work correctly
|
|
81
|
+
export const createExtendableFunctionPointerWithCurriedArgsSchema = <
|
|
82
|
+
_BaseArgs extends any[],
|
|
83
|
+
_ReturnType extends Promise<any>,
|
|
84
|
+
>() =>
|
|
85
|
+
z.object({
|
|
86
|
+
pointer: createFunctionPointerSchema<
|
|
87
|
+
// FIXME type args correctly
|
|
88
|
+
ConstrainedGenericFunctionPointer<_ReturnType>
|
|
89
|
+
>().shape.pointer,
|
|
90
|
+
args: z.array(z.any()),
|
|
91
|
+
});
|
package/dist/CAXEKYBD.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"],"mappings":";;;;;;AAaA,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","file":"CAXEKYBD.cjs","sourcesContent":["import { z } from 'zod/v4';\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\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"]}
|
package/dist/NIWFGLF4.js
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { z } from 'zod/v4';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
var functionSchemaTag = Symbol("__FUNCTION_SCHEMA_TAG");
|
|
6
|
-
var functionSchema = /* @__PURE__ */ __name(({ input, output }) => {
|
|
7
|
-
const obj = z.object({
|
|
8
|
-
input,
|
|
9
|
-
output
|
|
10
|
-
});
|
|
11
|
-
Object.defineProperty(obj, functionSchemaTag, {
|
|
12
|
-
value: true,
|
|
13
|
-
writable: false
|
|
14
|
-
});
|
|
15
|
-
obj.parse = (i) => {
|
|
16
|
-
if (typeof i !== "function") {
|
|
17
|
-
throw new Error(`${i} is not a function`);
|
|
18
|
-
}
|
|
19
|
-
return i;
|
|
20
|
-
};
|
|
21
|
-
return obj;
|
|
22
|
-
}, "functionSchema");
|
|
23
|
-
var schemaIsFunctionSchema = /* @__PURE__ */ __name((schema) => {
|
|
24
|
-
return Object.hasOwn(schema, functionSchemaTag);
|
|
25
|
-
}, "schemaIsFunctionSchema");
|
|
26
|
-
var customSchema = /* @__PURE__ */ __name((validate) => z.custom(validate), "customSchema");
|
|
27
|
-
|
|
28
|
-
export { __name, customSchema, functionSchema, schemaIsFunctionSchema };
|
|
29
|
-
//# sourceMappingURL=NIWFGLF4.js.map
|
|
30
|
-
//# sourceMappingURL=NIWFGLF4.js.map
|
package/dist/NIWFGLF4.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"],"mappings":";;;;AAaA,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","file":"NIWFGLF4.js","sourcesContent":["import { z } from 'zod/v4';\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\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"]}
|