-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e5b0976
commit fcc83eb
Showing
7 changed files
with
94 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { z } from 'zod'; | ||
|
||
import { ETH_ADDRESS_REGEXP, USER_ADDRESS_PARAM } from '../const'; | ||
|
||
export const returnValueTestSchema = z.object({ | ||
index: z.number().optional(), | ||
comparator: z.enum(['==', '>', '<', '>=', '<=', '!=']), | ||
value: z.unknown(), | ||
}); | ||
|
||
export type ReturnValueTestProps = z.infer<typeof returnValueTestSchema>; | ||
|
||
const EthAddressSchema = z.string().regex(ETH_ADDRESS_REGEXP); | ||
const UserAddressSchema = z.literal(USER_ADDRESS_PARAM); | ||
export const EthAddressOrUserAddressSchema = z.union([ | ||
EthAddressSchema, | ||
UserAddressSchema, | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Primitive, z, ZodLiteral } from 'zod'; | ||
|
||
// Source: https://github.com/colinhacks/zod/issues/831#issuecomment-1063481764 | ||
const createUnion = < | ||
T extends Readonly<[Primitive, Primitive, ...Primitive[]]> | ||
>( | ||
values: T | ||
) => { | ||
const zodLiterals = values.map((value) => z.literal(value)) as unknown as [ | ||
ZodLiteral<Primitive>, | ||
ZodLiteral<Primitive>, | ||
...ZodLiteral<Primitive>[] | ||
]; | ||
return z.union(zodLiterals); | ||
}; | ||
|
||
function createUnionSchema<T extends readonly Primitive[]>(values: T) { | ||
if (values.length === 0) { | ||
return z.never(); | ||
} | ||
|
||
if (values.length === 1) { | ||
return z.literal(values[0]); | ||
} | ||
|
||
return createUnion( | ||
values as unknown as Readonly<[Primitive, Primitive, ...Primitive[]]> | ||
); | ||
} | ||
|
||
export default createUnionSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fcc83eb
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bundled size for the package is listed below:
build/main/src/characters: 74.22 KB
build/main/src/kits: 19.53 KB
build/main/src/conditions/context: 42.97 KB
build/main/src/conditions/predefined: 19.53 KB
build/main/src/conditions/base: 54.69 KB
build/main/src/conditions: 164.06 KB
build/main/src/agents: 39.06 KB
build/main/src/sdk/strategy: 35.16 KB
build/main/src/sdk: 46.88 KB
build/main/src/policies: 19.53 KB
build/main/src: 449.22 KB
build/main/types/ethers-contracts/factories: 82.03 KB
build/main/types/ethers-contracts: 152.34 KB
build/main/types: 156.25 KB
build/main: 664.06 KB
build/module/src/characters: 74.22 KB
build/module/src/kits: 19.53 KB
build/module/src/conditions/context: 42.97 KB
build/module/src/conditions/predefined: 19.53 KB
build/module/src/conditions/base: 54.69 KB
build/module/src/conditions: 164.06 KB
build/module/src/agents: 39.06 KB
build/module/src/sdk/strategy: 31.25 KB
build/module/src/sdk: 42.97 KB
build/module/src/policies: 19.53 KB
build/module/src: 441.41 KB
build/module/types/ethers-contracts/factories: 82.03 KB
build/module/types/ethers-contracts: 152.34 KB
build/module/types: 156.25 KB
build/module: 656.25 KB
build: 1.29 MB