address.ts
This file
Path
apps/web/src/features/code/address.ts
48 lines · 1.5 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Merge redesign into mainoscabrielbefore adoptioncaedd21
line 1why, one step back1import { forkAddressOf, ForkPoint, forkRev } from "@repo/protocol/domain/code";Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
lines 2–22why, one step back2import { NoneOrMore } from "@repo/protocol/domain/common";3import { CommitSha, ProjectName, RepoPath } from "@repo/protocol/ids";4import { Option, Schema } from "effect";56import { revOf } from "./rev.ts";78const decodeProject = Schema.decodeUnknownOption(ProjectName);910const decodePath = Schema.decodeUnknownOption(RepoPath);1112const decodeSha = Schema.decodeUnknownOption(CommitSha);1314export const projectOf = (segment: string) => decodeProject(segment);1516export const revisionOf = (segment: string) => revOf(segment);1718export const repoPathOf = (rest: string | undefined) =>19 rest === undefined || rest === ""20 ? Option.none()21 : decodePath(rest.replace(/\/+$/u, ""));22Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 23–45why, one step back23/**24 * A commit's page names its id, or its id inside a fork25 * (`@<handle>/<ask>:<sha>`): the fork's address comes back as `at`.26 */27export const commitOf = (28 segment: string29): Option.Option<{30 readonly sha: CommitSha;31 readonly at: Option.Option<string>;32}> =>33 Option.orElse(34 Option.map(decodeSha(segment), (sha) => ({ at: Option.none(), sha })),35 () =>36 Option.flatMap(revOf(segment), (rev) =>37 Option.flatMap(forkAddressOf(rev), (fork) =>38 ForkPoint.$match(fork.point, {39 Branch: () => Option.none(),40 Commit: ({ sha }) =>41 Option.some({ at: Option.some(forkRev(fork)), sha }),42 })43 )44 )45 );Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
line 46why, one step back46Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72
line 47why, one step back47/** The router reads `?from=30` as the number 30. */Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
line 48why, one step back48export const offsetOf = Schema.decodeUnknownOption(NoneOrMore);