@layerzerolabs/zod-utils 0.2.101 → 0.2.102

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.
@@ -2,7 +2,7 @@ import { z } from 'zod';
2
2
 
3
3
  var __defProp = Object.defineProperty;
4
4
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
- var functionSchemaTag = Symbol("__FUNCTION_SCHEMA_TAG");
5
+ var functionSchemaTag = "__FUNCTION_SCHEMA_TAG";
6
6
  var functionSchema = /* @__PURE__ */ __name(({ input, output }) => {
7
7
  const obj = z.object({
8
8
  input,
@@ -12,6 +12,8 @@ var functionSchema = /* @__PURE__ */ __name(({ input, output }) => {
12
12
  value: true,
13
13
  writable: false
14
14
  });
15
+ obj.input = input;
16
+ obj.output = output;
15
17
  obj.parse = (i) => {
16
18
  if (typeof i !== "function") {
17
19
  throw new Error(`${i} is not a function`);
@@ -45,6 +47,6 @@ var isBrandedWith = /* @__PURE__ */ __name((expected, schema) => {
45
47
  return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];
46
48
  }, "isBrandedWith");
47
49
 
48
- export { __name, brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema };
49
- //# sourceMappingURL=D6RGXBQP.js.map
50
- //# sourceMappingURL=D6RGXBQP.js.map
50
+ export { __name, brandSchema, createFunctionPointerSchema, customSchema, functionSchema, functionSchemaTag, isBrandedWith, schemaIsFunctionSchema };
51
+ //# sourceMappingURL=VJ2U3WDZ.js.map
52
+ //# sourceMappingURL=VJ2U3WDZ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema","brandedSchemaPropertyKey","brandSchema","name","enumerable","configurable","isBrandedWith","expected"],"mappings":";;;;AAUO,IAA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EAA0B;EACpDG,UAAAA,EAAY,KAAA;EACZC,YAAAA,EAAc,KAAA;EACdf,QAAAA,EAAU,KAAA;EACVD,KAAAA,EAAOc;AACX,CAAA,CAAA,EANuB,aAAA;AAQpB,IAAMG,aAAAA,mBAAgB,MAAA,CAAA,CACzBC,QAAAA,EACAZ,MAAAA,KAAAA;AAEA,EAAA,IAAI,EAAEM,4BAA4BM,QAAAA,CAAAA,EAAW;AACzC,IAAA,MAAM,IAAId,MAAM,qCAAA,CAAA;AACpB,EAAA;AAEA,EAAA,IAAI,EAAEQ,4BAA4BN,MAAAA,CAAAA,EAAS;AACvC,IAAA,OAAO,KAAA;AACX,EAAA;AAEA,EAAA,OAAOA,MAAAA,CAAOM,wBAAAA,CAAAA,KAA8BM,QAAAA,CAASN,wBAAAA,CAAAA;AACzD,CAAA,EAb6B,eAAA","file":"VJ2U3WDZ.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\nexport const functionSchemaTag = '__FUNCTION_SCHEMA_TAG';\n\n// type assert that the z.ZodType type doesn't have a property `input` or `output` as it would conflict with our function schema type injection\nconst _check: true = null as any as keyof z.ZodType<string> extends infer U\n ? 'input' extends U\n ? false\n : 'output' extends U\n ? false\n : true\n : false;\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 (obj as any).input = input;\n (obj as any).output = output;\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\n // we have to decide here whether the args should be typed as the input or the output of the schema--\n // neither answer is correct and this is probably why zod dropped the function schema in v4\n // use infer for now because many of our schemata don't have a defined input and will silently produce `unknown`\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>> & {\n // inject these fields so that the original input and output schemata can be recovered pre-inference\n input: Input;\n output: Output;\n __FUNCTION_SCHEMA_TAG: true;\n };\n};\n\n// takes the z.infer of the schema, except for any top-level function schemata,\n// which are introspected to extract their input's output type\nexport type InferSchemaOutputWithInvertedFunctionSchemata<T extends z.ZodType> =\n T extends z.ZodObject\n ? z.infer<\n z.ZodObject<{\n [K in keyof T['shape']]: T['shape'][K] extends {\n input: z.ZodTuple;\n output: z.ZodType;\n }\n ? z.ZodType<\n (\n ...args: z.infer<T['shape'][K]['input']>\n ) => z.infer<T['shape'][K]['output']>\n >\n : T['shape'][K] extends z.ZodType\n ? T['shape'][K]\n : never;\n }>\n >\n : z.infer<T>;\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T, T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // TODO: replace with a concrete zod schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n\n// utils for branding schemata with names\nconst brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;\n\n/** Unavoidably, this mutates the underlying schema. Use with caution. */\nexport const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>\n Object.defineProperty(schema, brandedSchemaPropertyKey, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: name,\n });\n\nexport const isBrandedWith = <Branded extends z.ZodType>(\n expected: Branded,\n schema: z.ZodType,\n): schema is Branded => {\n if (!(brandedSchemaPropertyKey in expected)) {\n throw new Error('Branded model is not itself branded');\n }\n\n if (!(brandedSchemaPropertyKey in schema)) {\n return false;\n }\n\n return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];\n};\n"]}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { __name } from './D6RGXBQP.js';
2
- export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './D6RGXBQP.js';
1
+ import { __name } from './VJ2U3WDZ.js';
2
+ export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, functionSchemaTag, isBrandedWith, schemaIsFunctionSchema } from './VJ2U3WDZ.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var RESOLVING = Symbol("mapOnSchema/resolving");
package/dist/schema.d.ts CHANGED
@@ -1,10 +1,21 @@
1
1
  import { z } from 'zod';
2
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
+ export declare const functionSchemaTag = "__FUNCTION_SCHEMA_TAG";
4
5
  export declare const functionSchema: <Input extends z.ZodTuple, Output extends z.ZodType>({ input, output, }: {
5
6
  input: Input;
6
7
  output: Output;
7
- }) => z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;
8
+ }) => z.ZodType<(...args: z.infer<Input>) => z.infer<Output>> & {
9
+ input: Input;
10
+ output: Output;
11
+ __FUNCTION_SCHEMA_TAG: true;
12
+ };
13
+ export type InferSchemaOutputWithInvertedFunctionSchemata<T extends z.ZodType> = T extends z.ZodObject ? z.infer<z.ZodObject<{
14
+ [K in keyof T['shape']]: T['shape'][K] extends {
15
+ input: z.ZodTuple;
16
+ output: z.ZodType;
17
+ } ? z.ZodType<(...args: z.infer<T['shape'][K]['input']>) => z.infer<T['shape'][K]['output']>> : T['shape'][K] extends z.ZodType ? T['shape'][K] : never;
18
+ }>> : z.infer<T>;
8
19
  export declare const schemaIsFunctionSchema: (schema: z.ZodType) => schema is ReturnType<typeof functionSchema>;
9
20
  export declare const customSchema: <T>(validate?: (data: any) => T) => z.ZodType<T, T>;
10
21
  export declare const createFunctionPointerSchema: <T extends FunctionPointer>() => z.ZodType<T, T, z.core.$ZodTypeInternals<T, T>>;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iCAAiC,CAAC;AAEvE,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,EAAE,MAAM,SAAS,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,SAAS,EAAE,GACpF,MAAM,GACN,CAAC,SAAS,CAAC,MAAM,IAAI,EAAE,GAAG,MAAM,IAAI,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,GACvD,aAAa,CAAC,IAAI,EAAE,CAAC,GAAG,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,GAC/C,KAAK,CAAC;AAKd,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,CAAC,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,CAClF,CAAC;AAEF,eAAO,MAAM,sB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GAC7B,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GACb,KAAK;CAChB,CAAC,CACL,GACD,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;AAErB,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,EAAE,CAAC,CAAC,CAAC;AAE7C,eAAO,MAAM,2BAA2B,GAAI,CAAC,SAAS,eAAe,sDAEhD,CAAC;AAEtB,MAAM,MAAM,cAAc,CAAC,CAAC,SAAS,MAAM,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;AAKF,yEAAyE;AACzE,eAAO,MAAM,WAAW,GAAI,MAAM,SAAS,CAAC,CAAC,OAAO,EAAE,QAAQ,MAAM,EAAE,MAAM,MAAM,KAAG,MAM/E,CAAC;AAEP,eAAO,MAAM,aAAa,GAAI,OAAO,SAAS,CAAC,CAAC,OAAO,EACnD,UAAU,OAAO,EACjB,QAAQ,CAAC,CAAC,OAAO,KAClB,MAAM,IAAI,OAUZ,CAAC"}
package/dist/schema.js CHANGED
@@ -1,3 +1,3 @@
1
- export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './D6RGXBQP.js';
1
+ export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, functionSchemaTag, isBrandedWith, schemaIsFunctionSchema } from './VJ2U3WDZ.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.101",
3
+ "version": "0.2.102",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -17,12 +17,12 @@
17
17
  ],
18
18
  "dependencies": {
19
19
  "zod": "4.3.5",
20
- "@layerzerolabs/function-pointer": "0.2.101"
20
+ "@layerzerolabs/function-pointer": "0.2.102"
21
21
  },
22
22
  "devDependencies": {
23
23
  "tsup": "^8.4.0",
24
- "@layerzerolabs/tsup-configuration": "0.2.101",
25
- "@layerzerolabs/typescript-configuration": "0.2.101"
24
+ "@layerzerolabs/typescript-configuration": "0.2.102",
25
+ "@layerzerolabs/tsup-configuration": "0.2.102"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/schema.ts"],"names":["functionSchemaTag","Symbol","functionSchema","input","output","obj","z","object","Object","defineProperty","value","writable","parse","i","Error","schemaIsFunctionSchema","schema","hasOwn","customSchema","validate","custom","createFunctionPointerSchema","brandedSchemaPropertyKey","brandSchema","name","enumerable","configurable","isBrandedWith","expected"],"mappings":";;;;AAUA,IAAMA,iBAAAA,GAAoBC,OAAO,uBAAA,CAAA;AAG1B,IAAMC,cAAAA,mBAAiB,MAAA,CAAA,CAAqD,EAC/EC,KAAAA,EACAC,QAAM,KAIT;AACG,EAAA,MAAMC,GAAAA,GAAMC,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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FunctionPointer } from '@layerzerolabs/function-pointer';\n\nexport type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []\n ? Output\n : T extends [infer Head, ...infer Tail extends z.ZodType[]]\n ? InferredArray<Tail, [...Output, z.infer<Head>]>\n : never;\n\nconst functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');\n\n// This essentially replicates the functionality of z.function in zod v3\nexport const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({\n input,\n output,\n}: {\n input: Input;\n output: Output;\n}) => {\n const obj = z.object({\n input,\n output,\n });\n Object.defineProperty(obj, functionSchemaTag, { value: true, writable: false });\n // We don't expect the function to actually be an object with an input field and an output field\n // so we override the parse function. We can't actually parse functions since input and output\n // types are lost at runtime, but we can check the runtime type of the object\n obj.parse = (i) => {\n if (typeof i !== 'function') {\n throw new Error(`${i} is not a function`);\n }\n // The return type here just has to match the inference of z.object,\n // the actual inference of the schema will be the z.ZodType custom\n return i as any;\n };\n return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;\n};\n\nexport const schemaIsFunctionSchema = (\n schema: z.ZodType,\n): schema is ReturnType<typeof functionSchema> => {\n return Object.hasOwn(schema, functionSchemaTag);\n};\n\nexport const customSchema = <T>(validate?: (data: any) => T) =>\n z.custom<T>(validate) as z.ZodType<T, T>;\n\nexport const createFunctionPointerSchema = <T extends FunctionPointer>() =>\n // TODO: replace with a concrete zod schema\n customSchema<T>();\n\nexport type BuildZodObject<T extends object> = z.ZodObject<\n {\n [K in keyof T]: z.ZodType<T[K]>;\n },\n z.core.$strip\n>;\n\n// utils for branding schemata with names\nconst brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;\n\n/** Unavoidably, this mutates the underlying schema. Use with caution. */\nexport const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>\n Object.defineProperty(schema, brandedSchemaPropertyKey, {\n enumerable: false,\n configurable: false,\n writable: false,\n value: name,\n });\n\nexport const isBrandedWith = <Branded extends z.ZodType>(\n expected: Branded,\n schema: z.ZodType,\n): schema is Branded => {\n if (!(brandedSchemaPropertyKey in expected)) {\n throw new Error('Branded model is not itself branded');\n }\n\n if (!(brandedSchemaPropertyKey in schema)) {\n return false;\n }\n\n return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];\n};\n"]}