kobp
Version:
Koa Boilerplate with MikroORM
19 lines • 767 B
JavaScript
// interface SchemaParser {
// <T>(parsable: Parsable<T>): T
// }
// const query = <T>(schema: Parsable<T>) => tinyParser('query', schema)
// const body = <T>(schema: Parsable<T>) => tinyParser('body', schema)
// const params = <T>(schema: Parsable<T>) => tinyParser('params', schema)
//
// const tinyParser = <L extends 'query' | 'body' | 'params', LT>(location: L, schema: Parsable<any>) => {}
export const withValidation = (schemaSpec) => {
// TODO: build up a parser for this route
return async (context, next) => {
const query = context.query;
const params = context.params;
const body = context.body;
schemaSpec.parse({ query, params, body });
await next();
};
};
//# sourceMappingURL=withValidations.js.map