| 1 | /** |
| 2 | * The `protocol` group: git smart HTTP v0 at the repository's root path. |
| 3 | * The routes are streaming binary (pkt-lines in, sideband packs out), |
| 4 | * decode repository path parameters and return the binary response they build. |
| 5 | * Use handleRaw to keep request bodies streaming through API middleware. |
| 6 | * |
| 7 | * `:repo` may carry a `.git` suffix; the handlers strip it. |
| 8 | */ |
| 9 | import { RepoPath, RepoNotFound, PushDenied } from "./Schema.ts"; |
| 10 | import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint"; |
| 11 | import * as HttpApiGroup from "effect/http-api/HttpApiGroup"; |
| 12 | |
| 13 | /** `GET /:owner/:repo/info/refs?service=…`: the ref advertisement. */ |
| 14 | export const InfoRefs = HttpApiEndpoint.get( |
| 15 | "infoRefs", |
| 16 | "/:owner/:repo/info/refs", |
| 17 | { params: RepoPath, error: [RepoNotFound, PushDenied] }, |
| 18 | ); |
| 19 | |
| 20 | /** `POST /:owner/:repo/git-upload-pack`: clone and fetch. */ |
| 21 | export const UploadPack = HttpApiEndpoint.post( |
| 22 | "uploadPack", |
| 23 | "/:owner/:repo/git-upload-pack", |
| 24 | { params: RepoPath, error: [RepoNotFound, PushDenied] }, |
| 25 | ); |
| 26 | |
| 27 | /** `POST /:owner/:repo/git-receive-pack`: push. */ |
| 28 | export const ReceivePack = HttpApiEndpoint.post( |
| 29 | "receivePack", |
| 30 | "/:owner/:repo/git-receive-pack", |
| 31 | { params: RepoPath, error: [RepoNotFound, PushDenied] }, |
| 32 | ); |
| 33 | |
| 34 | /** The git wire protocol, mounted at the root. */ |
| 35 | export class Protocol extends HttpApiGroup.make("protocol", { |
| 36 | topLevel: true, |
| 37 | }).add(InfoRefs, UploadPack, ReceivePack) {} |