UNPKG

@mongez/gnz

Version:

Generator Z, the next generation of scaffolding tools.

45 lines (41 loc) 1.57 kB
'use strict';var reinforcements=require('@mongez/reinforcements');require('os');var prettifier=require('../../../utils/prettifier.js');async function gnWarlockHandler(options) { const { name, withValidation } = options; const handlerDescription = options?.description ?? reinforcements.capitalize(reinforcements.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 prettifier.format.typescript(content); }exports.gnWarlockHandler=gnWarlockHandler;//# sourceMappingURL=template.js.map