diff --git a/src/server/mod.ts b/src/server/mod.ts index 80bf5f4..fb3e15a 100644 --- a/src/server/mod.ts +++ b/src/server/mod.ts @@ -40,7 +40,7 @@ export const lesanServer = (schemasObj: TSchemas, actsObj: Services) => { typeGeneration: false, staticPath: [], }) => { - typeGeneration && (await generateSchemTypes(schemasObj)); + typeGeneration && (await generateSchemTypes(schemasObj, actsObj)); const handler = async (request: Request): Promise => { try { if (request.method === "OPTIONS") { diff --git a/src/types/mod.ts b/src/types/mod.ts index d9e5833..267453d 100644 --- a/src/types/mod.ts +++ b/src/types/mod.ts @@ -1,9 +1,12 @@ -import { ensureDir } from "../mod.ts"; +import { Acts, ensureDir, Services } from "../mod.ts"; import { createStruct } from "../models/mod.ts"; import { schemas as schemaFns, TSchemas } from "../models/mod.ts"; import { generateTypesFromStruct } from "./generateTypesFromStruct.ts"; -export const generateSchemTypes = async (schemasObj: TSchemas) => { +export const generateSchemTypes = async ( + schemasObj: TSchemas, + actsObj: Services, +) => { const schemas = schemaFns(schemasObj).getSchemas(); let str = ""; @@ -37,6 +40,40 @@ export const generateSchemTypes = async (schemasObj: TSchemas) => { `; } + str = str + ` + export type ReqType = {\n + `; + for (const service in actsObj) { + if (typeof actsObj[service] === "object") { + str = str + ` + ${service}: {\n + `; + for (const model in actsObj[service] as Acts) { + str = str + ` + ${model}: {\n + `; + for (const fn in (actsObj[service] as Acts)[model]) { + str = str + ` + ${fn}: ${ + generateTypesFromStruct({ + schemaStruct: (actsObj[service] as Acts)[model][fn].validator, + }) + } + `; + } + str = str + ` + }\n + `; + } + str = str + ` + }\n + `; + } + } + str = str + ` + }\n + `; + await ensureDir("./declarations"); await Deno.writeTextFile("./declarations/selectInp.ts", str); };