Skip to content
Myr

code.ts

This file

Path

apps/web/src/client/code.ts

102 lines · 3.2 KiB · TypeScript

Last changed by

Merge build/comments-web-rest into mainoscabrielbefore adoption0eb1248

History of this file

Take it

Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229

line 1why, one step back
1import type { Contract } from "@repo/protocol/contracts";

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 2–4why, one step back
2import type { CommitView } from "@repo/protocol/domain/code";
3import type { ProjectName, RepoPath } from "@repo/protocol/ids";4import { Array, Effect, Option } from "effect";

Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229

lines 5–60why, one step back
5import { Atom } from "effect/reactivity";
6import type { Rpc } from "effect/rpc";78import { ContractsClient } from "../surfaces.ts";9import { keys } from "./keys.ts";1011type PayloadOf<Tag extends string> = Rpc.Payload<Rpc.ExtractTag<Contract, Tag>>;1213const options = (project: ProjectName) => ({14 reactivityKeys: keys.code(project),15});1617export const refsAtom = Atom.family((project: ProjectName) =>18 Atom.withServerValueInitial(19 ContractsClient.query("listRefs", { project }, options(project))20 )21);2223export const treeAtom = (payload: PayloadOf<"readTree">) =>24 ContractsClient.query("readTree", payload, options(payload.project));2526export const pathsAtom = (payload: PayloadOf<"listPaths">) =>27 ContractsClient.query("listPaths", payload, options(payload.project));2829export const fileAtom = (payload: PayloadOf<"readFile">) =>30 ContractsClient.query("readFile", payload, options(payload.project));3132export const logAtom = (payload: PayloadOf<"log">) =>33 ContractsClient.query("log", payload, options(payload.project));3435export const commitAtom = (payload: PayloadOf<"showCommit">) =>36 ContractsClient.query("showCommit", payload, options(payload.project));3738export const projectCodeAtom = Atom.family((project: ProjectName) =>39 Atom.withServerValueInitial(40 ContractsClient.runtime.factory.withReactivity(keys.code(project))(41 ContractsClient.runtime.atom(42 Effect.gen(function* () {43 const client = yield* ContractsClient;44 const root = yield* client("readTree", { at: "main", project });4546 if (root.readme === undefined) {47 return { root };48 }4950 const readme = yield* client("readFile", {51 at: root.at,52 path: root.readme.path,53 project,54 });5556 return { readme, root };57 })58 )59 )60 )

Merge build/1211-code-browseroscabrielbefore adoptiona6808d3

lines 61–101why, one step back
61);
6263export const LAST_CHANGES_CAP = 30;6465export const lastChangesAtom = Atom.family(66 (key: {67 readonly at: string;68 readonly paths: readonly RepoPath[];69 readonly project: ProjectName;70 }) =>71 Atom.withServerValueInitial(72 ContractsClient.runtime.atom(73 Effect.gen(function* () {74 const client = yield* ContractsClient;7576 if (key.paths.length > LAST_CHANGES_CAP) {77 return new Map<string, CommitView>();78 }7980 const found = yield* Effect.forEach(81 key.paths,82 (path) =>83 client("log", {84 at: key.at,85 limit: 1,86 path,87 project: key.project,88 }).pipe(89 Effect.map(({ commits }) => Option.fromUndefinedOr(commits[0])),90 Effect.orElseSucceed(() => Option.none<CommitView>()),91 Effect.map((commit) =>92 Option.map(commit, (last) => [path, last] as const)93 )94 ),95 { concurrency: 3 }96 );9798 return new Map<string, CommitView>(Array.getSomes(found));99 })100 )101 )

Merge branch 'build/904-web-code-browser'oscabrielbefore adoption06e2229

line 102why, one step back
102);