@mongez/gnz
Version:
Generator Z, the next generation of scaffolding tools.
45 lines (41 loc) • 1.5 kB
JavaScript
import {capitalize,toKebabCase}from'@mongez/reinforcements';import'os';import {format}from'../../../utils/prettifier.js';async function gnWarlockHandler(options) {
const { name, withValidation } = options;
const handlerDescription = options?.description ?? capitalize(toKebabCase(name).replaceAll("-", " "));
let validation = "";
const warlockImports = [
"type RequestHandler",
"type Request",
"type Response",
"v",
];
if (withValidation) {
let content = "";
if (withValidation) {
content += `validate: async (request: Request, response: Response) => {
// your code here
// if any value is returned from this function, the handler won't be executed.
// as it will interrupt the request and return the value as a response.
},
schema: v.object({
// your schema here
}),
`;
}
validation = `${name}.validation = {
${content}
}`;
}
const imports = [
`import { ${warlockImports.join(", ")} } from "@warlock.js/core";`,
...(options.imports ?? []),
];
const content = `
${imports.join("\n")}
export const ${name}: RequestHandler = async (request: Request, response: Response) => {
${options.content}
}
${validation}
${name}.description = "${handlerDescription}";
`;
return await format.typescript(content);
}export{gnWarlockHandler};//# sourceMappingURL=template.js.map