@layerzerolabs/zod-utils 0.2.46 → 0.2.48

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/index.cjs 4.79 KB
15
- CJS dist/schema.cjs 709.00 B
16
- CJS dist/EK3R2JUO.cjs 1.29 KB
17
- CJS dist/index.cjs.map 11.04 KB
18
- CJS dist/schema.cjs.map 71.00 B
19
- CJS dist/EK3R2JUO.cjs.map 3.22 KB
20
- CJS ⚡️ Build success in 214ms
21
14
  ESM dist/schema.js 184.00 B
15
+ ESM dist/R6AQXXPU.js 1.14 KB
22
16
  ESM dist/index.js 4.06 KB
23
- ESM dist/DWFVFIJK.js 1.14 KB
17
+ ESM dist/R6AQXXPU.js.map 3.22 KB
24
18
  ESM dist/schema.js.map 70.00 B
25
- ESM dist/DWFVFIJK.js.map 3.22 KB
26
19
  ESM dist/index.js.map 11.03 KB
27
- ESM ⚡️ Build success in 214ms
20
+ ESM ⚡️ Build success in 120ms
21
+ CJS dist/schema.cjs 709.00 B
22
+ CJS dist/GR4ZG7N6.cjs 1.29 KB
23
+ CJS dist/index.cjs 4.79 KB
24
+ CJS dist/GR4ZG7N6.cjs.map 3.23 KB
25
+ CJS dist/schema.cjs.map 71.00 B
26
+ CJS dist/index.cjs.map 11.04 KB
27
+ CJS ⚡️ Build success in 120ms
@@ -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:69959) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1772682049785 is not specified and it doesn't parse as CommonJS.
5
+ (node:48391) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1772907261065 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)
@@ -36,5 +36,5 @@ exports.createFunctionPointerSchema = createFunctionPointerSchema;
36
36
  exports.customSchema = customSchema;
37
37
  exports.functionSchema = functionSchema;
38
38
  exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
39
- //# sourceMappingURL=EK3R2JUO.cjs.map
40
- //# sourceMappingURL=EK3R2JUO.cjs.map
39
+ //# sourceMappingURL=GR4ZG7N6.cjs.map
40
+ //# sourceMappingURL=GR4ZG7N6.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":"GR4ZG7N6.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"]}
@@ -30,5 +30,5 @@ var createFunctionPointerSchema = /* @__PURE__ */ __name(() => (
30
30
  ), "createFunctionPointerSchema");
31
31
 
32
32
  export { __name, createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema };
33
- //# sourceMappingURL=DWFVFIJK.js.map
34
- //# sourceMappingURL=DWFVFIJK.js.map
33
+ //# sourceMappingURL=R6AQXXPU.js.map
34
+ //# sourceMappingURL=R6AQXXPU.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":"R6AQXXPU.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"]}
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var EK3R2JUO_cjs = require('./EK3R2JUO.cjs');
3
+ var GR4ZG7N6_cjs = require('./GR4ZG7N6.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
- EK3R2JUO_cjs.__name(mapElement, "mapElement");
21
+ GR4ZG7N6_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__ */ EK3R2JUO_cjs.__name(() => mapElement(schema.def.getter()), "getter")
72
+ getter: /* @__PURE__ */ GR4ZG7N6_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,34 +108,34 @@ function mapOnSchema(schema, fn) {
108
108
  return schema;
109
109
  }
110
110
  }
111
- EK3R2JUO_cjs.__name(mapInner, "mapInner");
111
+ GR4ZG7N6_cjs.__name(mapInner, "mapInner");
112
112
  return fn(mapInner());
113
113
  }
114
- EK3R2JUO_cjs.__name(mapOnSchema, "mapOnSchema");
114
+ GR4ZG7N6_cjs.__name(mapOnSchema, "mapOnSchema");
115
115
  function zodDeepPartial(schema) {
116
116
  return mapOnSchema(schema, (s) => s?.optional?.());
117
117
  }
118
- EK3R2JUO_cjs.__name(zodDeepPartial, "zodDeepPartial");
118
+ GR4ZG7N6_cjs.__name(zodDeepPartial, "zodDeepPartial");
119
119
  function zodDeepRequired(schema) {
120
120
  return mapOnSchema(schema, (s) => s?.nonoptional?.());
121
121
  }
122
- EK3R2JUO_cjs.__name(zodDeepRequired, "zodDeepRequired");
122
+ GR4ZG7N6_cjs.__name(zodDeepRequired, "zodDeepRequired");
123
123
 
124
124
  Object.defineProperty(exports, "createFunctionPointerSchema", {
125
125
  enumerable: true,
126
- get: function () { return EK3R2JUO_cjs.createFunctionPointerSchema; }
126
+ get: function () { return GR4ZG7N6_cjs.createFunctionPointerSchema; }
127
127
  });
128
128
  Object.defineProperty(exports, "customSchema", {
129
129
  enumerable: true,
130
- get: function () { return EK3R2JUO_cjs.customSchema; }
130
+ get: function () { return GR4ZG7N6_cjs.customSchema; }
131
131
  });
132
132
  Object.defineProperty(exports, "functionSchema", {
133
133
  enumerable: true,
134
- get: function () { return EK3R2JUO_cjs.functionSchema; }
134
+ get: function () { return GR4ZG7N6_cjs.functionSchema; }
135
135
  });
136
136
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
137
137
  enumerable: true,
138
- get: function () { return EK3R2JUO_cjs.schemaIsFunctionSchema; }
138
+ get: function () { return GR4ZG7N6_cjs.schemaIsFunctionSchema; }
139
139
  });
140
140
  exports.mapOnSchema = mapOnSchema;
141
141
  exports.zodDeepPartial = zodDeepPartial;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { __name } from './DWFVFIJK.js';
2
- export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './DWFVFIJK.js';
1
+ import { __name } from './R6AQXXPU.js';
2
+ export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './R6AQXXPU.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var RESOLVING = Symbol("mapOnSchema/resolving");
package/dist/schema.cjs CHANGED
@@ -1,24 +1,24 @@
1
1
  'use strict';
2
2
 
3
- var EK3R2JUO_cjs = require('./EK3R2JUO.cjs');
3
+ var GR4ZG7N6_cjs = require('./GR4ZG7N6.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "createFunctionPointerSchema", {
8
8
  enumerable: true,
9
- get: function () { return EK3R2JUO_cjs.createFunctionPointerSchema; }
9
+ get: function () { return GR4ZG7N6_cjs.createFunctionPointerSchema; }
10
10
  });
11
11
  Object.defineProperty(exports, "customSchema", {
12
12
  enumerable: true,
13
- get: function () { return EK3R2JUO_cjs.customSchema; }
13
+ get: function () { return GR4ZG7N6_cjs.customSchema; }
14
14
  });
15
15
  Object.defineProperty(exports, "functionSchema", {
16
16
  enumerable: true,
17
- get: function () { return EK3R2JUO_cjs.functionSchema; }
17
+ get: function () { return GR4ZG7N6_cjs.functionSchema; }
18
18
  });
19
19
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
20
20
  enumerable: true,
21
- get: function () { return EK3R2JUO_cjs.schemaIsFunctionSchema; }
21
+ get: function () { return GR4ZG7N6_cjs.schemaIsFunctionSchema; }
22
22
  });
23
23
  //# sourceMappingURL=schema.cjs.map
24
24
  //# sourceMappingURL=schema.cjs.map
package/dist/schema.js CHANGED
@@ -1,3 +1,3 @@
1
- export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './DWFVFIJK.js';
1
+ export { createFunctionPointerSchema, customSchema, functionSchema, schemaIsFunctionSchema } from './R6AQXXPU.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.46",
3
+ "version": "0.2.48",
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.46"
18
+ "@layerzerolabs/function-pointer": "0.2.48"
19
19
  },
20
20
  "devDependencies": {
21
21
  "tsup": "^8.4.0",
22
- "@layerzerolabs/typescript-configuration": "0.2.46",
23
- "@layerzerolabs/tsup-configuration": "0.2.46"
22
+ "@layerzerolabs/tsup-configuration": "0.2.48",
23
+ "@layerzerolabs/typescript-configuration": "0.2.48"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "restricted",
package/src/schema.ts CHANGED
@@ -10,7 +10,7 @@ export type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T
10
10
 
11
11
  const functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');
12
12
 
13
- //this essentially replicates the functionality of z.function in zod v3
13
+ // This essentially replicates the functionality of z.function in zod v3
14
14
  export const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({
15
15
  input,
16
16
  output,
@@ -23,15 +23,15 @@ export const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodTyp
23
23
  output,
24
24
  });
25
25
  Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });
26
- //we don't expect the function to actually be an object with an input field and an output field
27
- //so we override the parse function. we can't actually parse functions since input and output
28
- //types are lost at runtime, but we can check the runtime type of the object
26
+ // We don't expect the function to actually be an object with an input field and an output field
27
+ // so we override the parse function. We can't actually parse functions since input and output
28
+ // types are lost at runtime, but we can check the runtime type of the object
29
29
  obj.parse = (i) => {
30
30
  if (typeof i !== 'function') {
31
31
  throw new Error(`${i} is not a function`);
32
32
  }
33
- //the return type here just has to match the inference of z.object,
34
- //the actual inference of the schema will be the z.ZodType custom
33
+ // The return type here just has to match the inference of z.object,
34
+ // the actual inference of the schema will be the z.ZodType custom
35
35
  return i as any;
36
36
  };
37
37
  return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;
@@ -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"],"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"]}
@@ -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"],"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"]}