code-head.ts
This file
Path
apps/web/src/server/code-head.ts
32 lines · 1.0 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 1–32why, one step back1import { Client } from "@repo/protocol/contracts";2import type { CommitView, Rev } from "@repo/protocol/domain/code";3import type { ProjectName } from "@repo/protocol/ids";4import { Effect, Option } from "effect";56/**7 * The commit a revision points at, for the Code tab's bar: one read beside8 * the page's own, never per row. It is only a fact over the page, so a page9 * goes without it when it cannot be read.10 */11export const readHead = (12 project: ProjectName,13 rev: Rev14): Effect.Effect<Option.Option<CommitView>, never, Client> =>15 Effect.gen(function* () {16 const client = yield* Client;1718 const page = yield* client19 .log({ at: rev, limit: 1, project })20 .pipe(Effect.option);2122 return Option.flatMap(page, ({ commits }) =>23 Option.fromUndefinedOr(commits[0])24 );25 });2627/** The head as a page's data carries it: present, or no key at all. */28export const headField = (head: Option.Option<CommitView>) =>29 Option.match(head, {30 onNone: () => ({}),31 onSome: (commit) => ({ head: commit }),32 });