Comparing version 0.0.0-canary.20231011T214946 to 0.0.0-canary.20231012T184154
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.version = void 0; | ||
exports.version = '0.0.0-canary.20231011T214946'; | ||
exports.version = '0.0.0-canary.20231012T184154'; | ||
//# sourceMappingURL=version.js.map |
@@ -136,3 +136,4 @@ "use strict"; | ||
]); | ||
exports.Abi = zod_1.z.array(zod_1.z.union([ | ||
exports.Abi = zod_1.z | ||
.array(zod_1.z.union([ | ||
exports.AbiError, | ||
@@ -149,4 +150,3 @@ exports.AbiEvent, | ||
abiItem.stateMutability = 'view'; | ||
else if (abiItem | ||
.payable) | ||
else if (abiItem.payable) | ||
abiItem.stateMutability = 'payable'; | ||
@@ -190,3 +190,4 @@ else | ||
]))), | ||
])); | ||
])) | ||
.readonly(); | ||
exports.TypedDataDomain = zod_1.z.object({ | ||
@@ -193,0 +194,0 @@ chainId: zod_1.z.number().optional(), |
@@ -1,2 +0,2 @@ | ||
export const version = '0.0.0-canary.20231011T214946'; | ||
export const version = '0.0.0-canary.20231012T184154'; | ||
//# sourceMappingURL=version.js.map |
@@ -172,3 +172,4 @@ import { z } from 'zod'; | ||
*/ | ||
export const Abi = z.array(z.union([ | ||
export const Abi = z | ||
.array(z.union([ | ||
AbiError, | ||
@@ -189,4 +190,3 @@ AbiEvent, | ||
abiItem.stateMutability = 'view'; | ||
else if (abiItem | ||
.payable) | ||
else if (abiItem.payable) | ||
abiItem.stateMutability = 'payable'; | ||
@@ -242,3 +242,4 @@ else | ||
]))), | ||
])); | ||
])) | ||
.readonly(); | ||
//////////////////////////////////////////////////////////////////////////////////////////////////// | ||
@@ -245,0 +246,0 @@ // Typed Data Types |
@@ -1,2 +0,2 @@ | ||
export declare const version = "0.0.0-canary.20231011T214946"; | ||
export declare const version = "0.0.0-canary.20231012T184154"; | ||
//# sourceMappingURL=version.d.ts.map |
@@ -170,3 +170,3 @@ import { z } from 'zod'; | ||
*/ | ||
export declare const Abi: z.ZodArray<z.ZodUnion<[z.ZodObject<{ | ||
export declare const Abi: z.ZodReadonly<z.ZodArray<z.ZodUnion<[z.ZodObject<{ | ||
type: z.ZodLiteral<"error">; | ||
@@ -294,3 +294,3 @@ inputs: z.ZodReadonly<z.ZodArray<z.ZodType<AbiParameterType, z.ZodTypeDef, AbiParameterType>, "many">>; | ||
stateMutability: "payable"; | ||
}), unknown>]>, "many">; | ||
}), unknown>]>, "many">>; | ||
export declare const TypedDataDomain: z.ZodObject<{ | ||
@@ -297,0 +297,0 @@ chainId: z.ZodOptional<z.ZodNumber>; |
{ | ||
"name": "abitype", | ||
"description": "Strict TypeScript types for Ethereum ABIs", | ||
"version": "0.0.0-canary.20231011T214946", | ||
"version": "0.0.0-canary.20231012T184154", | ||
"license": "MIT", | ||
@@ -6,0 +6,0 @@ "repository": "wagmi-dev/abitype", |
@@ -1,1 +0,1 @@ | ||
export const version = '0.0.0-canary.20231011T214946' | ||
export const version = '0.0.0-canary.20231012T184154' |
168
src/zod.ts
@@ -210,88 +210,94 @@ import { z } from 'zod' | ||
*/ | ||
export const Abi = z.array( | ||
z.union([ | ||
AbiError, | ||
AbiEvent, | ||
// TODO: Replace code below to `z.switch` (https://github.com/colinhacks/zod/issues/2106) | ||
// Need to redefine `AbiFunction | AbiConstructor | AbiFallback | AbiReceive` since `z.discriminate` doesn't support `z.preprocess` on `options` | ||
// https://github.com/colinhacks/zod/issues/1490 | ||
z.preprocess( | ||
(val) => { | ||
const abiItem = val as | ||
| AbiConstructorType | ||
| AbiFallbackType | ||
| AbiFunctionType | ||
| AbiReceiveType | ||
if (abiItem.type === 'receive') return abiItem | ||
// Calculate `stateMutability` for deprecated fields: `constant` and `payable` | ||
if ( | ||
(val as { stateMutability: AbiFunctionType['stateMutability'] }) | ||
.stateMutability === undefined | ||
) { | ||
export const Abi = z | ||
.array( | ||
z.union([ | ||
AbiError, | ||
AbiEvent, | ||
// TODO: Replace code below to `z.switch` (https://github.com/colinhacks/zod/issues/2106) | ||
// Need to redefine `AbiFunction | AbiConstructor | AbiFallback | AbiReceive` since `z.discriminate` doesn't support `z.preprocess` on `options` | ||
// https://github.com/colinhacks/zod/issues/1490 | ||
z.preprocess( | ||
(val) => { | ||
const abiItem = val as | ||
| AbiConstructorType | ||
| AbiFallbackType | ||
| AbiFunctionType | ||
| AbiReceiveType | ||
if (abiItem.type === 'receive') return abiItem | ||
// Calculate `stateMutability` for deprecated fields: `constant` and `payable` | ||
if ( | ||
abiItem.type === 'function' && | ||
(abiItem as AbiFunctionType).constant | ||
) | ||
abiItem.stateMutability = 'view' | ||
else if ( | ||
(abiItem as AbiConstructorType | AbiFallbackType | AbiFunctionType) | ||
.payable | ||
) | ||
abiItem.stateMutability = 'payable' | ||
else abiItem.stateMutability = 'nonpayable' | ||
} | ||
(val as { stateMutability: AbiFunctionType['stateMutability'] }) | ||
.stateMutability === undefined | ||
) { | ||
if ( | ||
abiItem.type === 'function' && | ||
(abiItem as AbiFunctionType).constant | ||
) | ||
abiItem.stateMutability = 'view' | ||
else if ( | ||
( | ||
abiItem as | ||
| AbiConstructorType | ||
| AbiFallbackType | ||
| AbiFunctionType | ||
).payable | ||
) | ||
abiItem.stateMutability = 'payable' | ||
else abiItem.stateMutability = 'nonpayable' | ||
} | ||
return val | ||
}, | ||
z.intersection( | ||
z.object({ | ||
/** | ||
* @deprecated use `pure` or `view` from {@link AbiStateMutability} instead | ||
* https://github.com/ethereum/solidity/issues/992 | ||
*/ | ||
constant: z.boolean().optional(), | ||
/** | ||
* @deprecated Vyper used to provide gas estimates | ||
* https://github.com/vyperlang/vyper/issues/2151 | ||
*/ | ||
gas: z.number().optional(), | ||
/** | ||
* @deprecated use `payable` or `nonpayable` from {@link AbiStateMutability} instead | ||
* https://github.com/ethereum/solidity/issues/992 | ||
*/ | ||
payable: z.boolean().optional(), | ||
}), | ||
z.discriminatedUnion('type', [ | ||
return val | ||
}, | ||
z.intersection( | ||
z.object({ | ||
type: z.literal('function'), | ||
inputs: z.array(AbiParameter).readonly(), | ||
name: z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/), | ||
outputs: z.array(AbiParameter).readonly(), | ||
stateMutability: AbiStateMutability, | ||
/** | ||
* @deprecated use `pure` or `view` from {@link AbiStateMutability} instead | ||
* https://github.com/ethereum/solidity/issues/992 | ||
*/ | ||
constant: z.boolean().optional(), | ||
/** | ||
* @deprecated Vyper used to provide gas estimates | ||
* https://github.com/vyperlang/vyper/issues/2151 | ||
*/ | ||
gas: z.number().optional(), | ||
/** | ||
* @deprecated use `payable` or `nonpayable` from {@link AbiStateMutability} instead | ||
* https://github.com/ethereum/solidity/issues/992 | ||
*/ | ||
payable: z.boolean().optional(), | ||
}), | ||
z.object({ | ||
type: z.literal('constructor'), | ||
inputs: z.array(AbiParameter).readonly(), | ||
stateMutability: z.union([ | ||
z.literal('payable'), | ||
z.literal('nonpayable'), | ||
]), | ||
}), | ||
z.object({ | ||
type: z.literal('fallback'), | ||
inputs: z.tuple([]).optional(), | ||
stateMutability: z.union([ | ||
z.literal('payable'), | ||
z.literal('nonpayable'), | ||
]), | ||
}), | ||
z.object({ | ||
type: z.literal('receive'), | ||
stateMutability: z.literal('payable'), | ||
}), | ||
]), | ||
z.discriminatedUnion('type', [ | ||
z.object({ | ||
type: z.literal('function'), | ||
inputs: z.array(AbiParameter).readonly(), | ||
name: z.string().regex(/[a-zA-Z$_][a-zA-Z0-9$_]*/), | ||
outputs: z.array(AbiParameter).readonly(), | ||
stateMutability: AbiStateMutability, | ||
}), | ||
z.object({ | ||
type: z.literal('constructor'), | ||
inputs: z.array(AbiParameter).readonly(), | ||
stateMutability: z.union([ | ||
z.literal('payable'), | ||
z.literal('nonpayable'), | ||
]), | ||
}), | ||
z.object({ | ||
type: z.literal('fallback'), | ||
inputs: z.tuple([]).optional(), | ||
stateMutability: z.union([ | ||
z.literal('payable'), | ||
z.literal('nonpayable'), | ||
]), | ||
}), | ||
z.object({ | ||
type: z.literal('receive'), | ||
stateMutability: z.literal('payable'), | ||
}), | ||
]), | ||
), | ||
), | ||
), | ||
]), | ||
) | ||
]), | ||
) | ||
.readonly() | ||
@@ -298,0 +304,0 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1155991
23909