@oriun/next-api
Version:
Next.js API routes with Zod validation
23 lines (22 loc) • 759 B
JavaScript
import { api, createAPI } from './wrapper';
export function API(schemas = {}, errorHandlers = []) {
return function (_target, _propertyKey, descriptor) {
return {
get() {
return api(descriptor.value, schemas, errorHandlers);
},
};
};
}
export function createAPIDecorator({ middlewares = [], errorHandlers = [] } = {}) {
const composition = createAPI({ middlewares, errorHandlers });
return function (schema = {}, localErrorHandlers = []) {
return function (_target, _propertyKey, descriptor) {
return {
get() {
return composition(descriptor.value, schema, localErrorHandlers);
},
};
};
};
}