Created
January 8, 2024 13:54
-
-
Save ducva/f0c08b511452ca8941e8dc3f10175773 to your computer and use it in GitHub Desktop.
zod final
This file contains hidden or 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
| export const validateChannelConfig = z.discriminatedUnion('type', [ | |
| z.object({ | |
| type: z.literal(ChannelType.LINE), | |
| config: LineChannelConfigSchema | |
| }), | |
| z.object({ | |
| type: z.literal(ChannelType.MAIL), | |
| config: MailChannelConfigSchema | |
| }) | |
| ]) | |
| export const ChannelSchema = z.object({ | |
| id: z.string(), | |
| name: z.string(), | |
| description: z.string().optional(), | |
| createdAt: z.string(), | |
| updatedAt: z.string(), | |
| config: ChannelConfigSchema | |
| }) | |
| .strict() | |
| .refine( | |
| (value) => { | |
| return validateChannelConfig.safeParse({ | |
| type: value.type, | |
| config: value.config | |
| }).success | |
| }, | |
| { | |
| message: 'Invalid channel config', | |
| path: ['config'] | |
| } | |
| ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment