diff options
| author | Shoubhit Dash <[email protected]> | 2026-04-15 04:57:18 +0530 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2026-04-14 20:55:41 -0400 |
| commit | 467e5689ec6187f811afacc337d411863dc9e9ca (patch) | |
| tree | 21fcf828a805b52859abd65c2744fe92d01fdf54 /packages/server/src/api/question.ts | |
| parent | fba752a5016a93ad7ea54890cf444de02a89a0f8 (diff) | |
| download | opencode-467e5689ec6187f811afacc337d411863dc9e9ca.tar.gz opencode-467e5689ec6187f811afacc337d411863dc9e9ca.zip | |
feat(server): extract question handler factory
Diffstat (limited to 'packages/server/src/api/question.ts')
| -rw-r--r-- | packages/server/src/api/question.ts | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/packages/server/src/api/question.ts b/packages/server/src/api/question.ts new file mode 100644 index 000000000..f72c37aa1 --- /dev/null +++ b/packages/server/src/api/question.ts @@ -0,0 +1,37 @@ +import { Effect, Schema } from "effect" +import { HttpApiBuilder } from "effect/unstable/httpapi" +import { QuestionReply, QuestionRequest, questionApi } from "../definition/question.js" + +export interface QuestionOps<R = never> { + readonly list: () => Effect.Effect<ReadonlyArray<unknown>, never, R> + readonly reply: (input: { + requestID: string + answers: Schema.Schema.Type<typeof QuestionReply>["answers"] + }) => Effect.Effect<void, never, R> +} + +export const makeQuestionHandler = <R>(ops: QuestionOps<R>) => + HttpApiBuilder.group( + questionApi, + "question", + Effect.fn("QuestionHttpApi.handlers")(function* (handlers) { + const decode = Schema.decodeUnknownSync(Schema.Array(QuestionRequest)) + + const list = Effect.fn("QuestionHttpApi.list")(function* () { + return decode(yield* ops.list()) + }) + + const reply = Effect.fn("QuestionHttpApi.reply")(function* (ctx: { + params: { requestID: string } + payload: Schema.Schema.Type<typeof QuestionReply> + }) { + yield* ops.reply({ + requestID: ctx.params.requestID, + answers: ctx.payload.answers, + }) + return true + }) + + return handlers.handle("list", list).handle("reply", reply) + }), + ) |
