Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

vcs.ts

85 lines3.1 KB

1import { type VcsStatusResult, WS_METHODS } from "@t3tools/contracts";
2import { applyGitStatusStreamEvent } from "@t3tools/shared/git";
3import * as Stream from "effect/Stream";
4import { Atom } from "effect/unstable/reactivity";
5​
6import {
7 createEnvironmentRpcCommand,
8 createEnvironmentRpcQueryAtomFamily,
9 createEnvironmentSubscriptionAtomFamily,
10} from "./runtime.ts";
11import type { EnvironmentRegistry } from "../connection/registry.ts";
12import { subscribe, type EnvironmentRpcInput } from "../rpc/client.ts";
13import { vcsCommandConcurrency, vcsCommandScheduler } from "./vcsCommandScheduler.ts";
14​
15export function createVcsEnvironmentAtoms<R, E>(
16 runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
17) {
18 return {
19 listRefs: createEnvironmentRpcQueryAtomFamily(runtime, {
20 label: "environment-data:vcs:list-refs",
21 tag: WS_METHODS.vcsListRefs,
22 staleTimeMs: 5_000,
23 }),
24 status: createEnvironmentSubscriptionAtomFamily(runtime, {
25 label: "environment-data:vcs:status",
26 subscribe: (input: EnvironmentRpcInput<typeof WS_METHODS.subscribeVcsStatus>) =>
27 subscribe(WS_METHODS.subscribeVcsStatus, input).pipe(
28 Stream.mapAccum(
29 () => null as VcsStatusResult | null,
30 (current, event) => {
31 const next = applyGitStatusStreamEvent(current, event);
32 return [next, [next]] as const;
33 },
34 ),
35 ),
36 }),
37 pull: createEnvironmentRpcCommand(runtime, {
38 label: "environment-data:vcs:pull",
39 tag: WS_METHODS.vcsPull,
40 scheduler: vcsCommandScheduler,
41 concurrency: vcsCommandConcurrency,
42 }),
43 refreshStatus: createEnvironmentRpcCommand(runtime, {
44 label: "environment-data:vcs:refresh-status",
45 tag: WS_METHODS.vcsRefreshStatus,
46 scheduler: vcsCommandScheduler,
47 concurrency: vcsCommandConcurrency,
48 }),
49 createWorktree: createEnvironmentRpcCommand(runtime, {
50 label: "environment-data:vcs:create-worktree",
51 tag: WS_METHODS.vcsCreateWorktree,
52 scheduler: vcsCommandScheduler,
53 concurrency: vcsCommandConcurrency,
54 }),
55 removeWorktree: createEnvironmentRpcCommand(runtime, {
56 label: "environment-data:vcs:remove-worktree",
57 tag: WS_METHODS.vcsRemoveWorktree,
58 scheduler: vcsCommandScheduler,
59 concurrency: vcsCommandConcurrency,
60 }),
61 createRef: createEnvironmentRpcCommand(runtime, {
62 label: "environment-data:vcs:create-ref",
63 tag: WS_METHODS.vcsCreateRef,
64 scheduler: vcsCommandScheduler,
65 concurrency: vcsCommandConcurrency,
66 }),
67 switchRef: createEnvironmentRpcCommand(runtime, {
68 label: "environment-data:vcs:switch-ref",
69 tag: WS_METHODS.vcsSwitchRef,
70 scheduler: vcsCommandScheduler,
71 concurrency: vcsCommandConcurrency,
72 }),
73 init: createEnvironmentRpcCommand(runtime, {
74 label: "environment-data:vcs:init",
75 tag: WS_METHODS.vcsInit,
76 scheduler: vcsCommandScheduler,
77 concurrency: vcsCommandConcurrency,
78 }),
79 };
81​
82export * from "./gitActions.ts";
83export * from "./vcsAction.ts";
84export * from "./vcsRef.ts";
85export * from "./vcsStatus.ts";