event.ts 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. // Generated by @opencode-ai/httpapi-codegen. Do not edit.
  2. import { Effect, Schema, Stream } from "effect"
  3. import { Sse } from "effect/unstable/encoding"
  4. import { HttpClientError } from "effect/unstable/http"
  5. import { HttpApiClient, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/unstable/httpapi"
  6. import { ClientError } from "./client-error"
  7. const Endpoint0SuccessData = Schema.Struct({ type: Schema.String })
  8. const Endpoint0SuccessError = Schema.Never
  9. export const Group1 = HttpApiGroup.make("event", { topLevel: false }).add(
  10. HttpApiEndpoint.make("GET")("subscribe", "/event", {
  11. success: HttpApiSchema.StreamSse({
  12. data: Endpoint0SuccessData,
  13. error: Endpoint0SuccessError,
  14. contentType: "text/event-stream",
  15. }).pipe(HttpApiSchema.status(202)),
  16. }),
  17. )
  18. type RawGroup = HttpApiClient.Client.Group<typeof Group1, "event", never, never>
  19. const Endpoint0DeclaredError = Schema.Union([Endpoint0SuccessError])
  20. const mapEndpoint0Error = (error: unknown) =>
  21. HttpClientError.isHttpClientError(error) || Schema.isSchemaError(error) || Sse.Retry.is(error)
  22. ? new ClientError({ cause: error })
  23. : Schema.is(Endpoint0DeclaredError)(error)
  24. ? error
  25. : new ClientError({ cause: error })
  26. const Endpoint0 = (raw: RawGroup) => () =>
  27. Stream.unwrap(
  28. raw["subscribe"]({}).pipe(
  29. Effect.mapError(mapEndpoint0Error),
  30. Effect.map((stream) => stream.pipe(Stream.mapError(mapEndpoint0Error))),
  31. ),
  32. )
  33. export const adaptGroup1 = (raw: RawGroup) => ({ subscribe: Endpoint0(raw) })