| 1170 | } |
| 1171 | |
| 1172 | function renderClient(groups: ReadonlyArray<Group>) { |
| 1173 | const imports = groups |
| 1174 | .map((group, index) => `import { adaptGroup${index}, Group${index} } from ${JSON.stringify(`./${group.module}`)}`) |
| 1175 | .join("\n") |
| 1176 | const api = `HttpApi.make("generated")${groups.map((_, index) => `.add(Group${index})`).join("")}` |
| 1177 | const fields = groups.flatMap((group, index) => { |
| 1178 | if (!group.endpoints[0]?.topLevel) { |
| 1179 | return [`${JSON.stringify(group.identifier)}: adaptGroup${index}(raw[${JSON.stringify(group.identifier)}])`] |
| 1180 | } |
| 1181 | const raw = `{ ${group.endpoints.map((item) => `${JSON.stringify(item.endpoint.name)}: raw[${JSON.stringify(item.endpoint.name)}]`).join(", ")} }` |
| 1182 | return [`...adaptGroup${index}(${raw})`] |
| 1183 | }) |
| 1184 | return `// Generated by @opencode-ai/httpapi-codegen. Do not edit.\nimport { Effect } from "effect"\nimport { HttpApi, HttpApiClient } from "effect/unstable/httpapi"\n${imports}\n\nconst Api = ${api}\nconst adaptClient = (raw: HttpApiClient.ForApi<typeof Api>) => ({ ${fields.join(", ")} })\n\nexport const make = (options?: { readonly baseUrl?: URL | string }) =>\n HttpApiClient.make(Api, options).pipe(Effect.map(adaptClient))\n` |
| 1185 | } |