zod#AnyZodObject TypeScript Examples
The following examples show how to use
zod#AnyZodObject.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: util.ts From linear-discord-serverless with MIT License | 7 votes |
createAllStates = <T extends AnyZodObject, R extends AnyZodObject>(
commons: T,
removeState: R,
) => {
return z
.object({
action: z.enum([Action.UPDATE, Action.CREATE]),
data: commons,
})
.or(
z.object({
action: z.literal(Action.REMOVE),
data: removeState.merge(commons),
}),
);
}
Example #2
Source File: middleware.ts From your_spotify with GNU General Public License v3.0 | 6 votes |
validating =
(schema: AnyZodObject, location: Location = 'body') =>
(req: Request, res: Response, next: NextFunction) => {
try {
const value = schema.merge(z.object({ token: z.string().optional() })).parse(req[location]);
req[location] = value;
return next();
} catch (e) {
logger.error(e);
return res.status(400).end();
}
}