Skip to content
Myr

rev.ts

This file

Path

apps/web/src/features/code/rev.ts

55 lines · 1.9 KiB · TypeScript

Last changed by

Merge redesign into mainoscabrielbefore adoptioncaedd21

History of this file

Take it

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 1–8why, one step back
1import {
2 forkAddressOf,3 ForkPoint,4 forkRev,5 Rev,6} from "@repo/protocol/domain/code";7import { sameHandle } from "@repo/protocol/ids";8import type { AskId, Handle } from "@repo/protocol/ids";

Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a

lines 9–10why, one step back
9import { Option, Schema } from "effect";
10

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 11–12why, one step back
11import { isCommitId } from "./headers.ts";
12

Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72

line 13why, one step back
13/** A tag name may hold `/` and `@`, so it is encoded into one segment. */

Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a

lines 14–19why, one step back
14export const revSegment = (rev: string): string => encodeURIComponent(rev);
1516const decodeSegment = Option.liftThrowable(decodeURIComponent);1718const asRev = Schema.decodeUnknownOption(Rev);19

Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72

line 20why, one step back
20/** A segment the router already decoded reads as itself. */

Give the web its W9 dependencies, components, project nav, line and revision helpers, and a stub for every new pageoscabrielbefore adoption254268a

lines 21–22why, one step back
21export const revOf = (segment: string): Option.Option<string> =>
22 Option.flatMap(decodeSegment(segment), asRev);

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

line 23why, one step back
23

Merge redesign into mainoscabrielbefore adoptioncaedd21

line 24why, one step back
24/** A fork's address reads as its claimant and ask, then a branch or a short commit when it names one. */

Fold every page's project events once, keep Markdown off the first load, and cache what never changesoscabrielbefore adoption38e5215

line 25why, one step back
25export const revLabel = (rev: string) =>

Merge redesign into mainoscabrielbefore adoptioncaedd21

lines 26–55why, one step back
26 Option.match(forkAddressOf(rev), {
27 onNone: () => (isCommitId(rev) ? rev.slice(0, 7) : rev),28 onSome: ({ ask, handle, point }) =>29 `${handle}/${ask}${ForkPoint.$match(point, {30 Branch: ({ name }) => (name === "main" ? "" : `:${name}`),31 Commit: ({ sha }) => `:${sha.slice(0, 7)}`,32 })}`,33 });3435export const isForkRev = (rev: string) => Option.isSome(forkAddressOf(rev));3637/** Whether `rev` reads the fork a claimant holds for an ask, at any branch or commit of it. */38export const readsFork = (39 rev: string,40 fork: { readonly ask: AskId; readonly handle: Handle }41) =>42 Option.exists(43 forkAddressOf(rev),44 ({ ask, handle }) => ask === fork.ask && sameHandle(handle, fork.handle)45 );4647/**48 * The revision that pins a commit read at `rev`: the bare commit id, or the49 * same id inside the fork `rev` names, since a fork's commits are read there.50 */51export const pinnedRev = (rev: string, sha: string): string =>52 Option.match(forkAddressOf(rev), {53 onNone: () => sha,54 onSome: (fork) => forkRev(fork, sha),55 });