@layerzerolabs/zod-utils 0.2.67 → 0.2.69

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.
@@ -46,5 +46,5 @@ var isBrandedWith = /* @__PURE__ */ __name((expected, schema) => {
46
46
  }, "isBrandedWith");
47
47
 
48
48
  export { __name, brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema };
49
- //# sourceMappingURL=3NS47XY3.js.map
50
- //# sourceMappingURL=3NS47XY3.js.map
49
+ //# sourceMappingURL=D6RGXBQP.js.map
50
+ //# sourceMappingURL=D6RGXBQP.js.map
@@ -1 +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","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,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;AAY3C,IAAMI,wBAAAA,GAA2B,uBAAA;AAG1B,IAAMC,8BAAc,MAAA,CAAA,CAA2BP,MAAAA,EAAgBQ,SAClEhB,MAAAA,CAAOC,cAAAA,CAAeO,QAAQM,wBAAAA,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":"3NS47XY3.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 // 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"]}
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,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;AAY3C,IAAMI,wBAAAA,GAA2B,uBAAA;AAG1B,IAAMC,8BAAc,MAAA,CAAA,CAA2BP,MAAAA,EAAgBQ,SAClEhB,MAAAA,CAAOC,cAAAA,CAAeO,QAAQM,wBAAAA,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":"D6RGXBQP.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, 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"]}
@@ -54,5 +54,5 @@ exports.customSchema = customSchema;
54
54
  exports.functionSchema = functionSchema;
55
55
  exports.isBrandedWith = isBrandedWith;
56
56
  exports.schemaIsFunctionSchema = schemaIsFunctionSchema;
57
- //# sourceMappingURL=KWZL3T47.cjs.map
58
- //# sourceMappingURL=KWZL3T47.cjs.map
57
+ //# sourceMappingURL=RHF5FXGP.cjs.map
58
+ //# sourceMappingURL=RHF5FXGP.cjs.map
@@ -1 +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","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,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;AAY3C,IAAMI,wBAAAA,GAA2B,uBAAA;AAG1B,IAAMC,8BAAc,MAAA,CAAA,CAA2BP,MAAAA,EAAgBQ,SAClEhB,MAAAA,CAAOC,cAAAA,CAAeO,QAAQM,wBAAAA,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":"KWZL3T47.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 // 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"]}
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,IAA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AA;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":"RHF5FXGP.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, 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.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var KWZL3T47_cjs = require('./KWZL3T47.cjs');
3
+ var RHF5FXGP_cjs = require('./RHF5FXGP.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
- KWZL3T47_cjs.__name(mapElement, "mapElement");
21
+ RHF5FXGP_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__ */ KWZL3T47_cjs.__name(() => mapElement(schema.def.getter()), "getter")
72
+ getter: /* @__PURE__ */ RHF5FXGP_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,42 +108,42 @@ function mapOnSchema(schema, fn) {
108
108
  return schema;
109
109
  }
110
110
  }
111
- KWZL3T47_cjs.__name(mapInner, "mapInner");
111
+ RHF5FXGP_cjs.__name(mapInner, "mapInner");
112
112
  return fn(mapInner());
113
113
  }
114
- KWZL3T47_cjs.__name(mapOnSchema, "mapOnSchema");
114
+ RHF5FXGP_cjs.__name(mapOnSchema, "mapOnSchema");
115
115
  function zodDeepPartial(schema) {
116
116
  return mapOnSchema(schema, (s) => s?.optional?.());
117
117
  }
118
- KWZL3T47_cjs.__name(zodDeepPartial, "zodDeepPartial");
118
+ RHF5FXGP_cjs.__name(zodDeepPartial, "zodDeepPartial");
119
119
  function zodDeepRequired(schema) {
120
120
  return mapOnSchema(schema, (s) => s?.nonoptional?.());
121
121
  }
122
- KWZL3T47_cjs.__name(zodDeepRequired, "zodDeepRequired");
122
+ RHF5FXGP_cjs.__name(zodDeepRequired, "zodDeepRequired");
123
123
 
124
124
  Object.defineProperty(exports, "brandSchema", {
125
125
  enumerable: true,
126
- get: function () { return KWZL3T47_cjs.brandSchema; }
126
+ get: function () { return RHF5FXGP_cjs.brandSchema; }
127
127
  });
128
128
  Object.defineProperty(exports, "createFunctionPointerSchema", {
129
129
  enumerable: true,
130
- get: function () { return KWZL3T47_cjs.createFunctionPointerSchema; }
130
+ get: function () { return RHF5FXGP_cjs.createFunctionPointerSchema; }
131
131
  });
132
132
  Object.defineProperty(exports, "customSchema", {
133
133
  enumerable: true,
134
- get: function () { return KWZL3T47_cjs.customSchema; }
134
+ get: function () { return RHF5FXGP_cjs.customSchema; }
135
135
  });
136
136
  Object.defineProperty(exports, "functionSchema", {
137
137
  enumerable: true,
138
- get: function () { return KWZL3T47_cjs.functionSchema; }
138
+ get: function () { return RHF5FXGP_cjs.functionSchema; }
139
139
  });
140
140
  Object.defineProperty(exports, "isBrandedWith", {
141
141
  enumerable: true,
142
- get: function () { return KWZL3T47_cjs.isBrandedWith; }
142
+ get: function () { return RHF5FXGP_cjs.isBrandedWith; }
143
143
  });
144
144
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
145
145
  enumerable: true,
146
- get: function () { return KWZL3T47_cjs.schemaIsFunctionSchema; }
146
+ get: function () { return RHF5FXGP_cjs.schemaIsFunctionSchema; }
147
147
  });
148
148
  exports.mapOnSchema = mapOnSchema;
149
149
  exports.zodDeepPartial = zodDeepPartial;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { __name } from './3NS47XY3.js';
2
- export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './3NS47XY3.js';
1
+ import { __name } from './D6RGXBQP.js';
2
+ export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './D6RGXBQP.js';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var RESOLVING = Symbol("mapOnSchema/resolving");
package/dist/schema.cjs CHANGED
@@ -1,32 +1,32 @@
1
1
  'use strict';
2
2
 
3
- var KWZL3T47_cjs = require('./KWZL3T47.cjs');
3
+ var RHF5FXGP_cjs = require('./RHF5FXGP.cjs');
4
4
 
5
5
 
6
6
 
7
7
  Object.defineProperty(exports, "brandSchema", {
8
8
  enumerable: true,
9
- get: function () { return KWZL3T47_cjs.brandSchema; }
9
+ get: function () { return RHF5FXGP_cjs.brandSchema; }
10
10
  });
11
11
  Object.defineProperty(exports, "createFunctionPointerSchema", {
12
12
  enumerable: true,
13
- get: function () { return KWZL3T47_cjs.createFunctionPointerSchema; }
13
+ get: function () { return RHF5FXGP_cjs.createFunctionPointerSchema; }
14
14
  });
15
15
  Object.defineProperty(exports, "customSchema", {
16
16
  enumerable: true,
17
- get: function () { return KWZL3T47_cjs.customSchema; }
17
+ get: function () { return RHF5FXGP_cjs.customSchema; }
18
18
  });
19
19
  Object.defineProperty(exports, "functionSchema", {
20
20
  enumerable: true,
21
- get: function () { return KWZL3T47_cjs.functionSchema; }
21
+ get: function () { return RHF5FXGP_cjs.functionSchema; }
22
22
  });
23
23
  Object.defineProperty(exports, "isBrandedWith", {
24
24
  enumerable: true,
25
- get: function () { return KWZL3T47_cjs.isBrandedWith; }
25
+ get: function () { return RHF5FXGP_cjs.isBrandedWith; }
26
26
  });
27
27
  Object.defineProperty(exports, "schemaIsFunctionSchema", {
28
28
  enumerable: true,
29
- get: function () { return KWZL3T47_cjs.schemaIsFunctionSchema; }
29
+ get: function () { return RHF5FXGP_cjs.schemaIsFunctionSchema; }
30
30
  });
31
31
  //# sourceMappingURL=schema.cjs.map
32
32
  //# sourceMappingURL=schema.cjs.map
package/dist/schema.d.ts CHANGED
@@ -6,8 +6,8 @@ export declare const functionSchema: <Input extends z.ZodTuple, Output extends z
6
6
  output: Output;
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
- export declare const customSchema: <T>(validate?: (data: any) => T) => z.ZodType<T>;
10
- export declare const createFunctionPointerSchema: <T extends FunctionPointer>() => z.ZodType<T, unknown, z.core.$ZodTypeInternals<T, unknown>>;
9
+ export declare const customSchema: <T>(validate?: (data: any) => T) => z.ZodType<T, T>;
10
+ export declare const createFunctionPointerSchema: <T extends FunctionPointer>() => z.ZodType<T, T, z.core.$ZodTypeInternals<T, T>>;
11
11
  export type BuildZodObject<T extends object> = z.ZodObject<{
12
12
  [K in keyof T]: z.ZodType<T[K]>;
13
13
  }, z.core.$strip>;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../src/schema.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC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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 './3NS47XY3.js';
1
+ export { brandSchema, createFunctionPointerSchema, customSchema, functionSchema, isBrandedWith, schemaIsFunctionSchema } from './D6RGXBQP.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.67",
3
+ "version": "0.2.69",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -13,14 +13,17 @@
13
13
  "main": "./dist/index.cjs",
14
14
  "module": "./dist/index.js",
15
15
  "types": "./dist/index.d.ts",
16
+ "files": [
17
+ "dist/**/*"
18
+ ],
16
19
  "dependencies": {
17
20
  "zod": "4.3.5",
18
- "@layerzerolabs/function-pointer": "0.2.67"
21
+ "@layerzerolabs/function-pointer": "0.2.69"
19
22
  },
20
23
  "devDependencies": {
21
24
  "tsup": "^8.4.0",
22
- "@layerzerolabs/tsup-configuration": "0.2.67",
23
- "@layerzerolabs/typescript-configuration": "0.2.67"
25
+ "@layerzerolabs/tsup-configuration": "0.2.69",
26
+ "@layerzerolabs/typescript-configuration": "0.2.69"
24
27
  },
25
28
  "publishConfig": {
26
29
  "access": "public",
@@ -1,27 +0,0 @@
1
-  WARN  Issue while reading "/home/runner/work/monorepo-internal/monorepo-internal/.npmrc". Failed to replace env in config: ${NPM_TOKEN}
2
-
3
- > @layerzerolabs/zod-utils@0.0.0 build /home/runner/work/monorepo-internal/monorepo-internal/packages/zod-utils
4
- > tsup
5
-
6
- CLI Building entry: src/index.ts, src/schema.ts
7
- CLI Using tsconfig: tsconfig.json
8
- CLI tsup v8.5.1
9
- CLI Using tsup config: /home/runner/work/monorepo-internal/monorepo-internal/packages/zod-utils/tsup.config.ts
10
- CLI Target: ES2023
11
- CLI Cleaning output folder
12
- CJS Build start
13
- ESM Build start
14
- ESM dist/index.js 4.09 KB
15
- ESM dist/3NS47XY3.js 1.78 KB
16
- ESM dist/schema.js 212.00 B
17
- ESM dist/index.js.map 11.03 KB
18
- ESM dist/3NS47XY3.js.map 4.77 KB
19
- ESM dist/schema.js.map 70.00 B
20
- ESM ⚡️ Build success in 180ms
21
- CJS dist/index.cjs 5.04 KB
22
- CJS dist/KWZL3T47.cjs 1.97 KB
23
- CJS dist/schema.cjs 969.00 B
24
- CJS dist/index.cjs.map 11.04 KB
25
- CJS dist/KWZL3T47.cjs.map 4.77 KB
26
- CJS dist/schema.cjs.map 71.00 B
27
- CJS ⚡️ Build success in 182ms
@@ -1,8 +0,0 @@
1
-
2
- > @layerzerolabs/zod-utils@0.0.0 lint /home/runner/work/monorepo-internal/monorepo-internal/packages/zod-utils
3
- > eslint . --max-warnings 0 || (eslint . --fix --max-warnings 0 && false)
4
-
5
- (node:66133) [MODULE_TYPELESS_PACKAGE_JSON] Warning: Module type of file:///home/runner/work/monorepo-internal/monorepo-internal/eslint.config.js?mtime=1775770562286 is not specified and it doesn't parse as CommonJS.
6
- Reparsing as ES module because module syntax was detected. This incurs a performance overhead.
7
- To eliminate this warning, add "type": "module" to /home/runner/work/monorepo-internal/monorepo-internal/package.json.
8
- (Use `node --trace-warnings ...` to show where the warning was created)
package/src/index.ts DELETED
@@ -1,150 +0,0 @@
1
- export * from './schema';
2
-
3
- /*
4
- Copyright 2024, Jaen - https://github.com/jaens
5
- Licensed under the Apache License, Version 2.0 (the "License");
6
- you may not use this file except in compliance with the License.
7
- You may obtain a copy of the License at
8
- http://www.apache.org/licenses/LICENSE-2.0
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
14
-
15
- https://gist.github.com/jaens/7e15ae1984bb338c86eb5e452dee3010
16
- */
17
-
18
- import { z } from 'zod';
19
- import type { $ZodType } from 'zod/v4/core';
20
-
21
- const RESOLVING = Symbol('mapOnSchema/resolving');
22
-
23
- export function mapOnSchema<T extends $ZodType, TResult extends $ZodType>(
24
- schema: T,
25
- fn: (schema: $ZodType) => TResult,
26
- ): TResult;
27
-
28
- /**
29
- * Applies {@link fn} to each element of the schema recursively, replacing every schema with its return value.
30
- * The rewriting is applied bottom-up (ie. {@link fn} will get called on "children" first).
31
- */
32
- export function mapOnSchema(schema: $ZodType, fn: (schema: $ZodType) => $ZodType): $ZodType {
33
- // Cache results to support recursive schemas
34
- const results = new Map<$ZodType, $ZodType | typeof RESOLVING>();
35
-
36
- function mapElement(s: $ZodType) {
37
- const value = results.get(s);
38
- if (value === RESOLVING) {
39
- throw new Error('Recursive schema access detected');
40
- } else if (value !== undefined) {
41
- return value;
42
- }
43
-
44
- results.set(s, RESOLVING);
45
- const result = mapOnSchema(s, fn);
46
- results.set(s, result);
47
- return result;
48
- }
49
-
50
- function mapInner() {
51
- if (schema instanceof z.ZodObject) {
52
- const newShape: Record<string, $ZodType> = {};
53
- for (const [key, value] of Object.entries(schema.shape)) {
54
- newShape[key] = mapElement(value as $ZodType);
55
- }
56
-
57
- return new z.ZodObject({
58
- ...schema.def,
59
- shape: newShape,
60
- });
61
- } else if (schema instanceof z.ZodArray) {
62
- return new z.ZodArray({
63
- ...schema.def,
64
- element: mapElement(schema.def.element),
65
- });
66
- } else if (schema instanceof z.ZodMap) {
67
- return new z.ZodMap({
68
- ...schema.def,
69
- keyType: mapElement(schema.def.keyType),
70
- valueType: mapElement(schema.def.valueType),
71
- });
72
- } else if (schema instanceof z.ZodSet) {
73
- return new z.ZodSet({
74
- ...schema.def,
75
- valueType: mapElement(schema.def.valueType),
76
- });
77
- } else if (schema instanceof z.ZodOptional) {
78
- return new z.ZodOptional({
79
- ...schema.def,
80
- innerType: mapElement(schema.def.innerType),
81
- });
82
- } else if (schema instanceof z.ZodNullable) {
83
- return new z.ZodNullable({
84
- ...schema.def,
85
- innerType: mapElement(schema.def.innerType),
86
- });
87
- } else if (schema instanceof z.ZodDefault) {
88
- return new z.ZodDefault({
89
- ...schema.def,
90
- innerType: mapElement(schema.def.innerType),
91
- });
92
- } else if (schema instanceof z.ZodReadonly) {
93
- return new z.ZodReadonly({
94
- ...schema.def,
95
- innerType: mapElement(schema.def.innerType),
96
- });
97
- } else if (schema instanceof z.ZodLazy) {
98
- return new z.ZodLazy({
99
- ...schema.def,
100
- // NB: This leaks `fn` into the schema, but there is no other way to support recursive schemas
101
- getter: () => mapElement(schema.def.getter()),
102
- });
103
- } else if (schema instanceof z.ZodPromise) {
104
- return new z.ZodPromise({
105
- ...schema.def,
106
- innerType: mapElement(schema.def.innerType),
107
- });
108
- } else if (schema instanceof z.ZodCatch) {
109
- return new z.ZodCatch({
110
- ...schema.def,
111
- innerType: mapElement(schema.def.innerType),
112
- });
113
- } else if (schema instanceof z.ZodTuple) {
114
- return new z.ZodTuple({
115
- ...schema.def,
116
- items: schema.def.items.map((item: $ZodType) => mapElement(item)),
117
- rest: schema.def.rest && mapElement(schema.def.rest),
118
- });
119
- } else if (schema instanceof z.ZodUnion) {
120
- return new z.ZodUnion({
121
- ...schema.def,
122
- options: schema.def.options.map((option: $ZodType) => mapElement(option)),
123
- });
124
- } else if (schema instanceof z.ZodIntersection) {
125
- return new z.ZodIntersection({
126
- ...schema.def,
127
- right: mapElement(schema.def.right),
128
- left: mapElement(schema.def.left),
129
- });
130
- } else if (schema instanceof z.ZodRecord) {
131
- return new z.ZodRecord({
132
- ...schema.def,
133
- keyType: schema.def.keyType as any,
134
- valueType: mapElement(schema.def.valueType),
135
- });
136
- } else {
137
- return schema;
138
- }
139
- }
140
-
141
- return fn(mapInner());
142
- }
143
-
144
- export function zodDeepPartial<T extends z.ZodTypeAny>(schema: T): T {
145
- return mapOnSchema(schema, (s) => (s as any)?.optional?.()) as T;
146
- }
147
-
148
- export function zodDeepRequired<T extends z.ZodTypeAny>(schema: T): T {
149
- return mapOnSchema(schema, (s) => (s as any)?.nonoptional?.()) as T;
150
- }
package/src/schema.ts DELETED
@@ -1,85 +0,0 @@
1
- import { z } from 'zod';
2
-
3
- import type { FunctionPointer } from '@layerzerolabs/function-pointer';
4
-
5
- export type InferredArray<T extends z.ZodType[], Output extends any[] = []> = T extends []
6
- ? Output
7
- : T extends [infer Head, ...infer Tail extends z.ZodType[]]
8
- ? InferredArray<Tail, [...Output, z.infer<Head>]>
9
- : never;
10
-
11
- const functionSchemaTag = Symbol('__FUNCTION_SCHEMA_TAG');
12
-
13
- // This essentially replicates the functionality of z.function in zod v3
14
- export const functionSchema = <Input extends z.ZodTuple, Output extends z.ZodType>({
15
- input,
16
- output,
17
- }: {
18
- input: Input;
19
- output: Output;
20
- }) => {
21
- const obj = z.object({
22
- input,
23
- output,
24
- });
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
29
- obj.parse = (i) => {
30
- if (typeof i !== 'function') {
31
- throw new Error(`${i} is not a function`);
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
35
- return i as any;
36
- };
37
- return obj as unknown as z.ZodType<(...args: z.infer<Input>) => z.infer<Output>>;
38
- };
39
-
40
- export const schemaIsFunctionSchema = (
41
- schema: z.ZodType,
42
- ): schema is ReturnType<typeof functionSchema> => {
43
- return Object.hasOwn(schema, functionSchemaTag);
44
- };
45
-
46
- export const customSchema = <T>(validate?: (data: any) => T) =>
47
- z.custom<T>(validate) as z.ZodType<T>;
48
-
49
- export const createFunctionPointerSchema = <T extends FunctionPointer>() =>
50
- // TODO: replace with a concrete zod schema
51
- customSchema<T>();
52
-
53
- export type BuildZodObject<T extends object> = z.ZodObject<
54
- {
55
- [K in keyof T]: z.ZodType<T[K]>;
56
- },
57
- z.core.$strip
58
- >;
59
-
60
- // utils for branding schemata with names
61
- const brandedSchemaPropertyKey = '__BRANDED_SCHEMA_NAME' as const;
62
-
63
- /** Unavoidably, this mutates the underlying schema. Use with caution. */
64
- export const brandSchema = <Schema extends z.ZodType>(schema: Schema, name: string): Schema =>
65
- Object.defineProperty(schema, brandedSchemaPropertyKey, {
66
- enumerable: false,
67
- configurable: false,
68
- writable: false,
69
- value: name,
70
- });
71
-
72
- export const isBrandedWith = <Branded extends z.ZodType>(
73
- expected: Branded,
74
- schema: z.ZodType,
75
- ): schema is Branded => {
76
- if (!(brandedSchemaPropertyKey in expected)) {
77
- throw new Error('Branded model is not itself branded');
78
- }
79
-
80
- if (!(brandedSchemaPropertyKey in schema)) {
81
- return false;
82
- }
83
-
84
- return schema[brandedSchemaPropertyKey] === expected[brandedSchemaPropertyKey];
85
- };
package/tsconfig.json DELETED
@@ -1,20 +0,0 @@
1
- {
2
- "extends": "@layerzerolabs/typescript-configuration/tsconfig.base.json",
3
- "compilerOptions": {
4
- "rootDir": "./src",
5
- "outDir": "./dist",
6
- "strictPropertyInitialization": false,
7
- "noUnusedLocals": false,
8
- "noUnusedParameters": false,
9
- "jsx": "react-jsx"
10
- },
11
- "exclude": [
12
- "node_modules",
13
- "**/__mocks__/*",
14
- "**/__tests__/*",
15
- "**/*.spec.ts",
16
- "**/*.test.ts",
17
- "dist"
18
- ],
19
- "include": ["src/**/*"]
20
- }
package/tsup.config.ts DELETED
@@ -1,8 +0,0 @@
1
- import { defineConfig } from 'tsup';
2
-
3
- import { createPackageTsupConfig } from '@layerzerolabs/tsup-configuration';
4
-
5
- export default defineConfig(({ watch }) => ({
6
- ...createPackageTsupConfig(),
7
- clean: !watch,
8
- }));