fixture.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import { Schema } from "effect"
  2. import { HttpApi, HttpApiEndpoint, HttpApiGroup, HttpApiSchema } from "effect/unstable/httpapi"
  3. export class Missing extends Schema.TaggedErrorClass<Missing>()("Missing", {
  4. message: Schema.String,
  5. }) {}
  6. export const Api = HttpApi.make("fixture")
  7. .add(
  8. HttpApiGroup.make("session")
  9. .add(HttpApiEndpoint.get("health", "/session/health", { success: Schema.String }))
  10. .add(
  11. HttpApiEndpoint.get("list", "/session", {
  12. query: { archived: Schema.optional(Schema.Boolean) },
  13. success: Schema.Array(Schema.String),
  14. }),
  15. )
  16. .add(
  17. HttpApiEndpoint.get("get", "/session/:sessionID", {
  18. params: { sessionID: Schema.String },
  19. success: Schema.Struct({ data: Schema.String }),
  20. error: Missing.pipe(HttpApiSchema.status(404)),
  21. }),
  22. )
  23. .add(
  24. HttpApiEndpoint.post("interrupt", "/session/:sessionID/interrupt", {
  25. params: { sessionID: Schema.String },
  26. success: HttpApiSchema.NoContent,
  27. }),
  28. ),
  29. )
  30. .add(
  31. HttpApiGroup.make("event").add(
  32. HttpApiEndpoint.get("subscribe", "/event", {
  33. success: HttpApiSchema.StreamSse({ data: Schema.Struct({ type: Schema.String }) }).pipe(
  34. HttpApiSchema.status(202),
  35. ),
  36. }),
  37. ),
  38. )
  39. .add(
  40. HttpApiGroup.make("system", { topLevel: true }).add(
  41. HttpApiEndpoint.get("status", "/status", { success: Schema.String }),
  42. ),
  43. )