@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
ts 78 lines 2.49 KB
Raw
1 /**
2 * The `refs` group: ref reads and transactional (CAS) writes (DESIGN.md §5).
3 *
4 * Ref names contain `/`, so the single-ref endpoints address the ref via
5 * the `name` query parameter, not a path segment.
6 */
7 import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
8 import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
9 import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
10 import * as Schema from "effect/Schema";
11 import {
12 ObjectNotFound,
13 Oid,
14 ReadOnlyRepo,
15 Ref,
16 RefConflict,
17 RefName,
18 RefNotFound,
19 RepoNotFound,
20 RepoPath,
21 PushDenied,
22 } from "./Schema.ts";
23
24 /** Lists refs, optionally filtered by prefix (e.g. `refs/heads/`). */
25 export const ListRefs = HttpApiEndpoint.get("list", "/repos/:owner/:repo/refs", {
26 params: RepoPath,
27 query: Schema.Struct({
28 /** Filter by prefix, e.g. `refs/heads/`. */
29 prefix: Schema.optional(Schema.String),
30 }),
31 success: Schema.Struct({
32 /** The default branch's full ref name, `null` on an unborn repo. */
33 head: Schema.NullOr(Schema.String),
34 refs: Schema.Array(Ref),
35 }),
36 error: [RepoNotFound],
37 });
38
39 /** Reads one ref by full name (`?name=refs/heads/main`). */
40 export const GetRef = HttpApiEndpoint.get("get", "/repos/:owner/:repo/ref", {
41 params: RepoPath,
42 query: Schema.Struct({ name: RefName }),
43 success: Ref,
44 error: [RepoNotFound, RefNotFound],
45 });
46
47 /** Writes one ref with CAS semantics. */
48 export const UpdateRef = HttpApiEndpoint.put("update", "/repos/:owner/:repo/ref", {
49 params: RepoPath,
50 query: Schema.Struct({ name: RefName }),
51 payload: Schema.Struct({
52 newOid: Oid,
53 /**
54 * CAS token: current oid the ref must hold. `null` = the ref must
55 * not exist (create). Absent = unconditional write.
56 */
57 expectedOid: Oid.pipe(Schema.NullOr, Schema.optional),
58 }),
59 success: Ref,
60 error: [PushDenied, RepoNotFound, RefConflict, ObjectNotFound, ReadOnlyRepo],
61 });
62
63 /** Deletes one ref with CAS semantics. */
64 export const RemoveRef = HttpApiEndpoint.delete("remove", "/repos/:owner/:repo/ref", {
65 params: RepoPath,
66 query: Schema.Struct({ name: RefName }),
67 payload: Schema.Struct({
68 /** CAS token: current oid the ref must hold. Absent = unconditional. */
69 expectedOid: Schema.optional(Oid),
70 }),
71 success: HttpApiSchema.NoContent,
72 error: [PushDenied, RepoNotFound, RefNotFound, RefConflict, ReadOnlyRepo],
73 });
74
75 /** The `refs` group, mounted at `/api/v1`. */
76 export class Refs extends HttpApiGroup.make("refs")
77 .add(ListRefs, GetRef, UpdateRef, RemoveRef)
78 .prefix("/api/v1") {}