Files
anomalyco_opencode/packages/httpapi-codegen/test/generated/event.ts
T

40 lines
1.6 KiB
TypeScript

// Generated by @opencode-ai/httpapi-codegen. Do not edit.
import { Effect, Schema, Stream } from "effect"
import { Sse } from "effect/unstable/encoding"
import { HttpClientError } from "effect/unstable/http"
import { HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/unstable/httpapi"
import { ClientError } from "./client-error.js"
const EndpointSubscribeSuccessData = Schema.Struct({ type: Schema.String })
const EndpointSubscribeSuccessError = Schema.Never
export const GroupEvent = HttpApiGroup.make("event", { topLevel: false }).add(
HttpApiEndpoint.make("GET")("subscribe", "/event", {
success: HttpApiSchema.StreamSse({
data: EndpointSubscribeSuccessData,
error: EndpointSubscribeSuccessError,
contentType: "text/event-stream",
}).pipe(HttpApiSchema.status(202)),
}),
)
type RawGroup = HttpApiClient.Client.Group<typeof GroupEvent, never, never>
const EndpointSubscribeDeclaredError = Schema.Union([EndpointSubscribeSuccessError])
const mapEndpointSubscribeError = (error: unknown) =>
HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
? new ClientError({ cause: error })
: Schema.is(EndpointSubscribeDeclaredError)(error)
? error
: new ClientError({ cause: error })
const EndpointSubscribe = (raw: RawGroup) => () =>
Stream.unwrap(
raw["subscribe"]({}).pipe(
Effect.mapError(mapEndpointSubscribeError),
Effect.map((stream) => stream.pipe(Stream.mapError(mapEndpointSubscribeError))),
),
)
export const adaptGroupEvent = (raw: RawGroup) => ({ subscribe: EndpointSubscribe(raw) })