@layerzerolabs/zod-utils 0.2.29 → 0.2.31

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.
@@ -11,17 +11,17 @@
11
11
  CLI Cleaning output folder
12
12
  CJS Build start
13
13
  ESM Build start
14
- CJS dist/schema.cjs 1.38 KB
15
- CJS dist/index.cjs 5.47 KB
16
- CJS dist/E7II22PB.cjs 2.29 KB
14
+ ESM dist/index.js 4.06 KB
15
+ ESM dist/DWFVFIJK.js 1.14 KB
16
+ ESM dist/schema.js 184.00 B
17
+ ESM dist/index.js.map 11.03 KB
18
+ ESM dist/DWFVFIJK.js.map 3.22 KB
19
+ ESM dist/schema.js.map 70.00 B
20
+ ESM ⚡️ Build success in 138ms
21
+ CJS dist/schema.cjs 709.00 B
22
+ CJS dist/EK3R2JUO.cjs 1.29 KB
23
+ CJS dist/index.cjs 4.79 KB
17
24
  CJS dist/schema.cjs.map 71.00 B
25
+ CJS dist/EK3R2JUO.cjs.map 3.22 KB
18
26
  CJS dist/index.cjs.map 11.04 KB
19
- CJS dist/E7II22PB.cjs.map 5.46 KB
20
- CJS ⚡️ Build success in 194ms
21
- ESM dist/schema.js 332.00 B
22
- ESM dist/CQE5KQHY.js 1.95 KB
23
- ESM dist/index.js 4.21 KB
24
- ESM dist/schema.js.map 70.00 B
25
- ESM dist/CQE5KQHY.js.map 5.46 KB
26
- ESM dist/index.js.map 11.03 KB
27
- ESM ⚡️ Build success in 195ms
27
+ CJS ⚡️ Build success in 138ms
@@ -2,7 +2,7 @@
2
2
  > @layerzerolabs/zod-utils@0.0.0 lint /home/runner/work/monorepo-internal/monorepo-internal/packages/zod-utils
3
3
  > eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)
4
4
 
5
- (node:58715) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1771045407926 is not specified and it doesn't parse as CommonJS.
5
+ (node:55864) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1771449390046 is not specified and it doesn't parse as CommonJS.
6
6
  Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
7
7
  To eliminate this warning, add "type": "module" to /home/runner/work/monorepo-internal/monorepo-internal/package.json.
8
8
  (Use `node --trace-warnings ...` to show where the warning was created)
@@ -0,0 +1,34 @@
1
+ import { z } from 'zod';
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(() => (
28
+ // FIXME this can be a real schema
29
+ customSchema()
30
+ ), "createFunctionPointerSchema");
31
+
32
+ export { __name, createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema };
33
+ //# sourceMappingURL=DWFVFIJK.js.map
34
+ //# sourceMappingURL=DWFVFIJK.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"],"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,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;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,CAAAA,CAAEc,MAAAA,CAAUD,QAAAA,CAAAA,EADY,cAAA;AAGrB,IAAME,2BAAAA,mBAA8B,MAAA,CAAA;;EAEvCH,YAAAA;AAFuC,CAAA,EAAA,6BAAA","file":"DWFVFIJK.js","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>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // FIXME this can be a real 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"]}
@@ -0,0 +1,40 @@
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
+ // FIXME this can be a real schema
31
+ customSchema()
32
+ ), "createFunctionPointerSchema");
33
+
34
+ exports.__name = __name;
35
+ exports.createFunctionPointerSchema = createFunctionPointerSchema;
36
+ exports.customSchema = customSchema;
37
+ exports.functionSchema = functionSchema;
38
+ exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
39
+ //# sourceMappingURL=EK3R2JUO.cjs.map
40
+ //# sourceMappingURL=EK3R2JUO.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"],"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","file":"EK3R2JUO.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>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // FIXME this can be a real 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"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var E7II22PB_cjs = require('./E7II22PB.cjs');
3
+ var EK3R2JUO_cjs = require('./EK3R2JUO.cjs');
4
4
  var zod = require('zod');
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
- E7II22PB_cjs.__name(mapElement, "mapElement");
21
+ EK3R2JUO_cjs.__name(mapElement, "mapElement");
22
22
  function mapInner() {
23
23
  if (schema instanceof zod.z.ZodObject) {
24
24
  const newShape = {};
@@ -69,7 +69,7 @@ function mapOnSchema(schema, fn) {
69
69
  return new zod.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__ */ E7II22PB_cjs.__name(() => mapElement(schema.def.getter()), "getter")
72
+ getter: /* @__PURE__ */ EK3R2JUO_cjs.__name(() => mapElement(schema.def.getter()), "getter")
73
73
  });
74
74
  } else if (schema instanceof zod.z.ZodPromise) {
75
75
  return new zod.z.ZodPromise({
@@ -108,50 +108,34 @@ function mapOnSchema(schema, fn) {
108
108
  return schema;
109
109
  }
110
110
  }
111
- E7II22PB_cjs.__name(mapInner, "mapInner");
111
+ EK3R2JUO_cjs.__name(mapInner, "mapInner");
112
112
  return fn(mapInner());
113
113
  }
114
- E7II22PB_cjs.__name(mapOnSchema, "mapOnSchema");
114
+ EK3R2JUO_cjs.__name(mapOnSchema, "mapOnSchema");
115
115
  function zodDeepPartial(schema) {
116
116
  return mapOnSchema(schema, (s) => s?.optional?.());
117
117
  }
118
- E7II22PB_cjs.__name(zodDeepPartial, "zodDeepPartial");
118
+ EK3R2JUO_cjs.__name(zodDeepPartial, "zodDeepPartial");
119
119
  function zodDeepRequired(schema) {
120
120
  return mapOnSchema(schema, (s) => s?.nonoptional?.());
121
121
  }
122
- E7II22PB_cjs.__name(zodDeepRequired, "zodDeepRequired");
122
+ EK3R2JUO_cjs.__name(zodDeepRequired, "zodDeepRequired");
123
123
 
124
- Object.defineProperty(exports, "bindFunctionPointerArgs", {
125
- enumerable: true,
126
- get: function () { return E7II22PB_cjs.bindFunctionPointerArgs; }
127
- });
128
- Object.defineProperty(exports, "bindPartialFunctionPointerArgs", {
129
- enumerable: true,
130
- get: function () { return E7II22PB_cjs.bindPartialFunctionPointerArgs; }
131
- });
132
- Object.defineProperty(exports, "createExtendableFunctionPointerWithCurriedArgsSchema", {
133
- enumerable: true,
134
- get: function () { return E7II22PB_cjs.createExtendableFunctionPointerWithCurriedArgsSchema; }
135
- });
136
124
  Object.defineProperty(exports, "createFunctionPointerSchema", {
137
125
  enumerable: true,
138
- get: function () { return E7II22PB_cjs.createFunctionPointerSchema; }
139
- });
140
- Object.defineProperty(exports, "createFunctionPointerWithArgsSchema", {
141
- enumerable: true,
142
- get: function () { return E7II22PB_cjs.createFunctionPointerWithArgsSchema; }
126
+ get: function () { return EK3R2JUO_cjs.createFunctionPointerSchema; }
143
127
  });
144
128
  Object.defineProperty(exports, "customSchema", {
145
129
  enumerable: true,
146
- get: function () { return E7II22PB_cjs.customSchema; }
130
+ get: function () { return EK3R2JUO_cjs.customSchema; }
147
131
  });
148
132
  Object.defineProperty(exports, "functionSchema", {
149
133
  enumerable: true,
150
- get: function () { return E7II22PB_cjs.functionSchema; }
134
+ get: function () { return EK3R2JUO_cjs.functionSchema; }
151
135
  });
152
136
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
153
137
  enumerable: true,
154
- get: function () { return E7II22PB_cjs.schemaIsFunctionSchema; }
138
+ get: function () { return EK3R2JUO_cjs.schemaIsFunctionSchema; }
155
139
  });
156
140
  exports.mapOnSchema = mapOnSchema;
157
141
  exports.zodDeepPartial = zodDeepPartial;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { __name } from './CQE5KQHY.js';
2
- export { bindFunctionPointerArgs, bindPartialFunctionPointerArgs, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './CQE5KQHY.js';
1
+ import { __name } from './DWFVFIJK.js';
2
+ export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './DWFVFIJK.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var RESOLVING = Symbol("mapOnSchema/resolving");
package/dist/schema.cjs CHANGED
@@ -1,40 +1,24 @@
1
1
  'use strict';
2
2
 
3
- var E7II22PB_cjs = require('./E7II22PB.cjs');
3
+ var EK3R2JUO_cjs = require('./EK3R2JUO.cjs');
4
4
 
5
5
 
6
6
 
7
- Object.defineProperty(exports, "bindFunctionPointerArgs", {
8
- enumerable: true,
9
- get: function () { return E7II22PB_cjs.bindFunctionPointerArgs; }
10
- });
11
- Object.defineProperty(exports, "bindPartialFunctionPointerArgs", {
12
- enumerable: true,
13
- get: function () { return E7II22PB_cjs.bindPartialFunctionPointerArgs; }
14
- });
15
- Object.defineProperty(exports, "createExtendableFunctionPointerWithCurriedArgsSchema", {
16
- enumerable: true,
17
- get: function () { return E7II22PB_cjs.createExtendableFunctionPointerWithCurriedArgsSchema; }
18
- });
19
7
  Object.defineProperty(exports, "createFunctionPointerSchema", {
20
8
  enumerable: true,
21
- get: function () { return E7II22PB_cjs.createFunctionPointerSchema; }
22
- });
23
- Object.defineProperty(exports, "createFunctionPointerWithArgsSchema", {
24
- enumerable: true,
25
- get: function () { return E7II22PB_cjs.createFunctionPointerWithArgsSchema; }
9
+ get: function () { return EK3R2JUO_cjs.createFunctionPointerSchema; }
26
10
  });
27
11
  Object.defineProperty(exports, "customSchema", {
28
12
  enumerable: true,
29
- get: function () { return E7II22PB_cjs.customSchema; }
13
+ get: function () { return EK3R2JUO_cjs.customSchema; }
30
14
  });
31
15
  Object.defineProperty(exports, "functionSchema", {
32
16
  enumerable: true,
33
- get: function () { return E7II22PB_cjs.functionSchema; }
17
+ get: function () { return EK3R2JUO_cjs.functionSchema; }
34
18
  });
35
19
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
36
20
  enumerable: true,
37
- get: function () { return E7II22PB_cjs.schemaIsFunctionSchema; }
21
+ get: function () { return EK3R2JUO_cjs.schemaIsFunctionSchema; }
38
22
  });
39
23
  //# sourceMappingURL=schema.cjs.map
40
24
  //# sourceMappingURL=schema.cjs.map
package/dist/schema.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { z } from 'zod';
2
- import type { FunctionPointer, UnderlyingMethodOfFunctionPointer } from '@layerzerolabs/function-pointer';
2
+ import type { FunctionPointer } from '@layerzerolabs/function-pointer';
3
3
  export type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends [] ? Output : T extends [infer Head, ...infer Tail extends z.ZodType[]] ? InferredArray<Tail, [...Output, z.infer<Head>]> : never;
4
4
  export declare const functionSchema: <Input extends z.ZodTuple, Output extends z.ZodType>({ input, output, }: {
5
5
  input: Input;
@@ -7,36 +7,7 @@ export declare const functionSchema: <Input extends z.ZodTuple, Output extends z
7
7
  }) => z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;
8
8
  export declare const schemaIsFunctionSchema: (schema: z.ZodType) => schema is ReturnType<typeof functionSchema>;
9
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>;
22
- export declare const bindFunctionPointerArgs: <T extends FunctionPointer>(params: {
23
- pointer: T;
24
- args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
25
- }) => {
26
- pointer: T;
27
- args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
28
- };
29
- export declare const bindPartialFunctionPointerArgs: <T extends FunctionPointer>(params: {
30
- pointer: T;
31
- args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;
32
- }) => {
33
- pointer: T;
34
- args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;
35
- };
36
- export type FunctionPointerWithArgs<T extends FunctionPointer> = {
37
- pointer: T;
38
- args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
39
- };
10
+ export declare const createFunctionPointerSchema: <T extends FunctionPointer>() => z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>;
40
11
  export type BuildZodObject<T extends object> = z.ZodObject<{
41
12
  [K in keyof T]: z.ZodType<T[K]>;
42
13
  }, z.core.$strip>;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts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AM,IAAI,CAAC,CAAC,SAAS,CACtD;KACK,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,EACD,CAAC,CAAC,IAAI,CAAC,MAAM,CAChB,CAAC"}
package/dist/schema.js CHANGED
@@ -1,3 +1,3 @@
1
- export { bindFunctionPointerArgs, bindPartialFunctionPointerArgs, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './CQE5KQHY.js';
1
+ export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './DWFVFIJK.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.2.29",
3
+ "version": "0.2.31",
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": "4.3.5",
18
- "@layerzerolabs/function-pointer": "0.2.29"
18
+ "@layerzerolabs/function-pointer": "0.2.31"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsup": "^8.4.0",
22
- "@layerzerolabs/typescript-configuration": "0.2.29",
23
- "@layerzerolabs/tsup-configuration": "0.2.29"
22
+ "@layerzerolabs/tsup-configuration": "0.2.31",
23
+ "@layerzerolabs/typescript-configuration": "0.2.31"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "restricted",
package/src/schema.ts CHANGED
@@ -1,9 +1,6 @@
1
1
  import { z } from 'zod';
2
2
 
3
- import type {
4
- FunctionPointer,
5
- UnderlyingMethodOfFunctionPointer,
6
- } from '@layerzerolabs/function-pointer';
3
+ import type { FunctionPointer } from '@layerzerolabs/function-pointer';
7
4
 
8
5
  export type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []
9
6
  ? Output
@@ -49,51 +46,9 @@ export const schemaIsFunctionSchema = (
49
46
  export const customSchema = <T>(validate?: (data: any) => T) =>
50
47
  z.custom<T>(validate) as z.ZodType<T>;
51
48
 
52
- export const createFunctionPointerSchema = <T extends FunctionPointer = FunctionPointer>() =>
53
- z.object({
54
- // FIXME this can be a real schema
55
- pointer: customSchema<T>(),
56
- });
57
-
58
- export const createFunctionPointerWithArgsSchema = <
59
- T extends FunctionPointer = FunctionPointer,
60
- >() =>
61
- z.object({
62
- pointer: createFunctionPointerSchema<T>().shape.pointer,
63
- args: customSchema<Parameters<UnderlyingMethodOfFunctionPointer<T>>>(),
64
- });
65
-
66
- export type ConstrainedGenericFunctionPointer<_ReturnType extends Promise<any>> = FunctionPointer<
67
- ReturnType<<T extends (...args: any[]) => _ReturnType>() => T>
68
- >;
69
-
70
- // This type doesn't work correctly
71
- export const createExtendableFunctionPointerWithCurriedArgsSchema = <
72
- _BaseArgs extends any[],
73
- _ReturnType extends Promise<any>,
74
- >() =>
75
- z.object({
76
- pointer: createFunctionPointerSchema<
77
- // FIXME type args correctly
78
- ConstrainedGenericFunctionPointer<_ReturnType>
79
- >().shape.pointer,
80
- args: z.array(z.any()),
81
- });
82
-
83
- export const bindFunctionPointerArgs = <T extends FunctionPointer>(params: {
84
- pointer: T;
85
- args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
86
- }) => params;
87
-
88
- export const bindPartialFunctionPointerArgs = <T extends FunctionPointer>(params: {
89
- pointer: T;
90
- args: Partial<Parameters<UnderlyingMethodOfFunctionPointer<T>>>;
91
- }) => params;
92
-
93
- export type FunctionPointerWithArgs<T extends FunctionPointer> = {
94
- pointer: T;
95
- args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;
96
- };
49
+ export const createFunctionPointerSchema = <T extends FunctionPointer>() =>
50
+ // FIXME this can be a real schema
51
+ customSchema<T>();
97
52
 
98
53
  export type BuildZodObject<T extends object> = z.ZodObject<
99
54
  {
package/dist/CQE5KQHY.js DELETED
@@ -1,44 +0,0 @@
1
- import { z } from 'zod';
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
- var bindFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindFunctionPointerArgs");
40
- var bindPartialFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindPartialFunctionPointerArgs");
41
-
42
- export { __name, bindFunctionPointerArgs, bindPartialFunctionPointerArgs, createExtendableFunctionPointerWithCurriedArgsSchema, createFunctionPointerSchema, createFunctionPointerWithArgsSchema, customSchema, functionSchema, schemaIsFunctionSchema };
43
- //# sourceMappingURL=CQE5KQHY.js.map
44
- //# sourceMappingURL=CQE5KQHY.js.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","pointer","createFunctionPointerWithArgsSchema","shape","args","createExtendableFunctionPointerWithCurriedArgsSchema","array","any","bindFunctionPointerArgs","params","bindPartialFunctionPointerArgs"],"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;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,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":"CQE5KQHY.js","sourcesContent":["import { z } from 'zod';\n\nimport type {\n FunctionPointer,\n UnderlyingMethodOfFunctionPointer,\n} 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>;\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\nexport type FunctionPointerWithArgs<T extends FunctionPointer> = {\n pointer: T;\n args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;\n};\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"]}
package/dist/E7II22PB.cjs DELETED
@@ -1,54 +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(() => zod.z.object({
30
- // FIXME this can be a real schema
31
- pointer: customSchema()
32
- }), "createFunctionPointerSchema");
33
- var createFunctionPointerWithArgsSchema = /* @__PURE__ */ __name(() => zod.z.object({
34
- pointer: createFunctionPointerSchema().shape.pointer,
35
- args: customSchema()
36
- }), "createFunctionPointerWithArgsSchema");
37
- var createExtendableFunctionPointerWithCurriedArgsSchema = /* @__PURE__ */ __name(() => zod.z.object({
38
- pointer: createFunctionPointerSchema().shape.pointer,
39
- args: zod.z.array(zod.z.any())
40
- }), "createExtendableFunctionPointerWithCurriedArgsSchema");
41
- var bindFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindFunctionPointerArgs");
42
- var bindPartialFunctionPointerArgs = /* @__PURE__ */ __name((params) => params, "bindPartialFunctionPointerArgs");
43
-
44
- exports.__name = __name;
45
- exports.bindFunctionPointerArgs = bindFunctionPointerArgs;
46
- exports.bindPartialFunctionPointerArgs = bindPartialFunctionPointerArgs;
47
- exports.createExtendableFunctionPointerWithCurriedArgsSchema = createExtendableFunctionPointerWithCurriedArgsSchema;
48
- exports.createFunctionPointerSchema = createFunctionPointerSchema;
49
- exports.createFunctionPointerWithArgsSchema = createFunctionPointerWithArgsSchema;
50
- exports.customSchema = customSchema;
51
- exports.functionSchema = functionSchema;
52
- exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
53
- //# sourceMappingURL=E7II22PB.cjs.map
54
- //# sourceMappingURL=E7II22PB.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","pointer","createFunctionPointerWithArgsSchema","shape","args","createExtendableFunctionPointerWithCurriedArgsSchema","array","any","bindFunctionPointerArgs","params","bindPartialFunctionPointerArgs"],"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,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,E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MAAAA,EAHwC,gCAAA","file":"E7II22PB.cjs","sourcesContent":["import { z } from 'zod';\n\nimport type {\n FunctionPointer,\n UnderlyingMethodOfFunctionPointer,\n} 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>;\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\nexport type FunctionPointerWithArgs<T extends FunctionPointer> = {\n pointer: T;\n args: Parameters<UnderlyingMethodOfFunctionPointer<T>>;\n};\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"]}