42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { WS_METHODS } from "@t3tools/contracts";
|
|
import { Atom } from "effect/unstable/reactivity";
|
|
|
|
import {
|
|
createAtomCommandScheduler,
|
|
createEnvironmentRpcCommand,
|
|
createEnvironmentRpcQueryAtomFamily,
|
|
} from "./runtime.ts";
|
|
import type { EnvironmentRegistry } from "../connection/registry.ts";
|
|
|
|
export function createReviewEnvironmentAtoms<R, E>(
|
|
runtime: Atom.AtomRuntime<EnvironmentRegistry | R, E>,
|
|
) {
|
|
const diffFileScheduler = createAtomCommandScheduler();
|
|
return {
|
|
diffPreview: createEnvironmentRpcQueryAtomFamily(runtime, {
|
|
label: "environment-data:review:diff-preview",
|
|
tag: WS_METHODS.reviewGetDiffPreview,
|
|
staleTimeMs: 5_000,
|
|
}),
|
|
diffFileContents: createEnvironmentRpcCommand(runtime, {
|
|
label: "environment-data:review:diff-file-contents",
|
|
tag: WS_METHODS.reviewGetDiffFileContents,
|
|
scheduler: diffFileScheduler,
|
|
concurrency: {
|
|
mode: "singleFlight",
|
|
key: ({ environmentId, input }) =>
|
|
JSON.stringify([
|
|
environmentId,
|
|
input.cwd,
|
|
input.sourceKind,
|
|
input.baseRef,
|
|
input.headRef,
|
|
input.oldPath,
|
|
input.newPath,
|
|
input.changeType,
|
|
]),
|
|
},
|
|
}),
|
|
};
|
|
}
|