Open History to see the last commit
1import { WS_METHODS } from "@t3tools/contracts";
2import { Atom } from "effect/unstable/reactivity";
3
4import {
5 createAtomCommandScheduler,
6 createEnvironmentRpcCommand,
7 createEnvironmentRpcQueryAtomFamily,
8} from "./runtime.ts";
9import type { EnvironmentRegistry } from "../connection/registry.ts";
10import { EnvironmentCacheStore } from "../platform/persistence.ts";
11import { vcsCommandConcurrency, vcsCommandScheduler } from "./vcsCommandScheduler.ts";
12import { invalidateCachedVcsRefs } from "./vcsRefInvalidation.ts";
13
14export function createSourceControlEnvironmentAtoms<R, E>(
15 runtime: Atom.AtomRuntime<EnvironmentRegistry | EnvironmentCacheStore | R, E>,
16) {
17 const commandScheduler = createAtomCommandScheduler();
18 return {
19 discovery: createEnvironmentRpcQueryAtomFamily(runtime, {
20 label: "environment-data:server:source-control-discovery",
21 tag: WS_METHODS.serverDiscoverSourceControl,
22 }),
23 repository: createEnvironmentRpcQueryAtomFamily(runtime, {
24 label: "environment-data:source-control:repository",
25 tag: WS_METHODS.sourceControlLookupRepository,
26 }),
27 cloneRepository: createEnvironmentRpcCommand(runtime, {
28 label: "environment-data:source-control:clone-repository",
29 tag: WS_METHODS.sourceControlCloneRepository,
30 scheduler: commandScheduler,
31 concurrency: {
32 mode: "serial",
33 key: ({ environmentId }) => environmentId,
34 },
35 }),
36 publishRepository: createEnvironmentRpcCommand(runtime, {
37 label: "environment-data:source-control:publish-repository",
38 tag: WS_METHODS.sourceControlPublishRepository,
39 scheduler: vcsCommandScheduler,
40 concurrency: vcsCommandConcurrency,
41 onSettled: (target, registry) =>
42 invalidateCachedVcsRefs(registry, {
43 environmentId: target.environmentId,
44 cwd: target.input.cwd,
45 }),
46 }),
47 };
48}