MCPcopy
hub / github.com/anomalyco/opencode / emitPromise

Function emitPromise

packages/httpapi-codegen/src/index.ts:238–267  ·  view source on GitHub ↗
(
  contract: Contract,
  options?: {
    readonly outputTypes?: Readonly<Record<string, { readonly name: string; readonly import: string }>>
  },
)

Source from the content-addressed store, hash-verified

236}
237
238export function emitPromise(
239 contract: Contract,
240 options?: {
241 readonly outputTypes?: Readonly<Record<string, { readonly name: string; readonly import: string }>>
242 },
243): Output {
244 const groups = contract.groups
245 for (const group of groups) {
246 for (const endpoint of group.endpoints) assertPromiseEndpoint(endpoint)
247 }
248 return {
249 operations: operations(groups),
250 files: [
251 { path: "types.ts", content: renderPromiseTypes(groups, options?.outputTypes) },
252 {
253 path: "client-error.ts",
254 content: `export type ClientErrorReason = "Transport" | "UnexpectedStatus" | "UnsupportedContentType" | "MalformedResponse"\n\nexport class ClientError extends Error {\n override readonly name = "ClientError"\n constructor(readonly reason: ClientErrorReason, options?: ErrorOptions) {\n super(reason, options)\n }\n}\n`,
255 },
256 {
257 path: "client.ts",
258 content: renderPromiseClient(groups).replace("let next: ReadableStreamReadResult<Uint8Array>", "let next"),
259 },
260 {
261 path: "index.ts",
262 content:
263 'export { ClientError, type ClientErrorReason } from "./client-error"\nexport * as OpenCode from "./client"\nexport * from "./types"\n',
264 },
265 ],
266 }
267}
268
269function assertPromiseEndpoint(endpoint: Endpoint) {
270 const name = `${endpoint.group}.${endpoint.endpoint.name}`

Callers 3

build.tsFile · 0.90
generate.test.tsFile · 0.90

Calls 4

assertPromiseEndpointFunction · 0.85
operationsFunction · 0.85
renderPromiseTypesFunction · 0.85
renderPromiseClientFunction · 0.85

Tested by

no test coverage detected