MCPcopy Index your code
hub / github.com/anomalyco/opencode / renderClient

Function renderClient

packages/httpapi-codegen/src/index.ts:1172–1185  ·  view source on GitHub ↗
(groups: ReadonlyArray<Group>)

Source from the content-addressed store, hash-verified

1170}
1171
1172function 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}

Callers 1

renderEffectFilesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected