address.ts
This file
Path
apps/web/src/features/code/address.ts
38 lines · 1.4 KiB · TypeScript
Last changed by
Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
History of this fileTake it
Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229
lines 1–38why, one step back1/**2 * A code page's address, decoded where it arrives (AGENTS.md principle 2):3 * the project's name, the revision's segment (`rev.ts`) and the repo path4 * after it. Each is none when the address cannot name one, which a page5 * answers with a 404 before it asks the platform anything.6 */7import { NoneOrMore } from "@repo/protocol/domain/common";8import { CommitSha, ProjectName, RepoPath } from "@repo/protocol/ids";9import { Option, Schema } from "effect";1011import { revOf } from "./rev.ts";1213const decodeProject = Schema.decodeUnknownOption(ProjectName);1415const decodePath = Schema.decodeUnknownOption(RepoPath);1617const decodeSha = Schema.decodeUnknownOption(CommitSha);1819export const projectOf = (segment: string) => decodeProject(segment);2021/** A revision's segment, decoded; none for one that names no revision. */22export const revisionOf = (segment: string) => revOf(segment);2324/** A repo path from the address's rest (a trailing slash dropped); none for the root. */25export const repoPathOf = (rest: string | undefined) =>26 rest === undefined || rest === ""27 ? Option.none()28 : decodePath(rest.replace(/\/+$/u, ""));2930/** A commit's id from the address. */31export const commitOf = (segment: string) => decodeSha(segment);3233/**34 * Where a page of a list starts, from its search parameter: the router35 * reads `?from=30` as the number 30; anything but a whole number from 0 is36 * none.37 */38export const offsetOf = Schema.decodeUnknownOption(NoneOrMore);