1import { WS_METHODS } from "@t3tools/contracts";
2import { Atom } from "effect/reactivity";
3
4import { createEnvironmentRpcCommand, createEnvironmentRpcQueryAtomFamily } from "./runtime.ts";
5import type { EnvironmentRegistry } from "../connection/registry.ts";
6import * as Persistence from "../platform/persistence.ts";
7import { vcsCommandConcurrency, vcsCommandScheduler } from "./vcsCommandScheduler.ts";
8import { invalidateCachedVcsRefs } from "./vcsRefInvalidation.ts";
9
10export function createGitEnvironmentAtoms<R, E>(
11 runtime: Atom.AtomRuntime<EnvironmentRegistry | Persistence.EnvironmentCacheStore | R, E>,
12) {
13 return {
14 pullRequestResolution: createEnvironmentRpcQueryAtomFamily(runtime, {
15 label: "environment-data:git:resolve-pull-request",
16 tag: WS_METHODS.gitResolvePullRequest,
17 }),
18 preparePullRequestThread: createEnvironmentRpcCommand(runtime, {
19 label: "environment-data:git:prepare-pull-request-thread",
20 tag: WS_METHODS.gitPreparePullRequestThread,
21 scheduler: vcsCommandScheduler,
22 concurrency: vcsCommandConcurrency,
23 onSettled: ({ environmentId, input }, registry) =>
24 invalidateCachedVcsRefs(registry, { environmentId, cwd: input.cwd }),
25 }),
26 };
27}