mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-29 03:24:54 +00:00
47 lines
1.6 KiB
TypeScript
47 lines
1.6 KiB
TypeScript
import { Project } from "@opencode/schema/project"
|
|
import { Schema, SchemaGetter, Struct } from "effect"
|
|
import { HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/http-api"
|
|
import { ProjectNotFoundError } from "../errors.js"
|
|
|
|
const root = "/api/project"
|
|
const UpdatePayload = Schema.Struct(Struct.omit(Project.UpdateInput.fields, ["projectID"]))
|
|
const BooleanFromString = Schema.Literals(["true", "false"]).pipe(
|
|
Schema.decodeTo(Schema.Boolean, {
|
|
decode: SchemaGetter.transform((value) => value === "true"),
|
|
encode: SchemaGetter.transform((value): "true" | "false" => (value ? "true" : "false")),
|
|
}),
|
|
)
|
|
|
|
export const ProjectGroup = HttpApiGroup.make("server.project")
|
|
.add(
|
|
HttpApiEndpoint.get("project.list", root, {
|
|
query: Schema.Struct({ archived: BooleanFromString.pipe(Schema.optional) }),
|
|
success: Schema.Array(Project.Info),
|
|
}).annotateMerge(
|
|
OpenApi.annotations({
|
|
identifier: "project.list",
|
|
summary: "List projects",
|
|
description: "List known projects. Archived projects are excluded unless archived=true.",
|
|
}),
|
|
),
|
|
)
|
|
.add(
|
|
HttpApiEndpoint.patch("project.update", `${root}/:projectID`, {
|
|
params: { projectID: Project.ID },
|
|
payload: UpdatePayload,
|
|
success: Project.Info,
|
|
error: ProjectNotFoundError,
|
|
}).annotateMerge(
|
|
OpenApi.annotations({
|
|
identifier: "project.update",
|
|
summary: "Update project",
|
|
description: "Update the project canonical directory, display metadata, and workspace commands.",
|
|
}),
|
|
),
|
|
)
|
|
.annotateMerge(
|
|
OpenApi.annotations({
|
|
title: "project",
|
|
description: "Project routes.",
|
|
}),
|
|
)
|