(
contract: Contract,
options?: {
readonly outputTypes?: Readonly<Record<string, { readonly name: string; readonly import: string }>>
},
)
| 236 | } |
| 237 | |
| 238 | export 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 | |
| 269 | function assertPromiseEndpoint(endpoint: Endpoint) { |
| 270 | const name = `${endpoint.group}.${endpoint.endpoint.name}` |
no test coverage detected