| 1 | import * as Context from "effect/Context"; |
| 2 | import type * as Effect from "effect/Effect"; |
| 3 | |
| 4 | import type { |
| 5 | VcsDriverCapabilities, |
| 6 | VcsError, |
| 7 | VcsInitInput, |
| 8 | VcsListRemotesResult, |
| 9 | VcsListWorkspaceFilesResult, |
| 10 | ReviewDiffPreviewInput, |
| 11 | ReviewDiffPreviewResult, |
| 12 | VcsRepositoryIdentity, |
| 13 | } from "@t3tools/contracts"; |
| 14 | import { CheckpointRef } from "@t3tools/contracts"; |
| 15 | import * as VcsProcess from "./VcsProcess.ts"; |
| 16 | |
| 17 | export interface VcsCaptureCheckpointInput { |
| 18 | readonly cwd: string; |
| 19 | readonly checkpointRef: CheckpointRef; |
| 20 | } |
| 21 | |
| 22 | export interface VcsRestoreCheckpointInput { |
| 23 | readonly cwd: string; |
| 24 | readonly checkpointRef: CheckpointRef; |
| 25 | readonly fallbackToHead?: boolean; |
| 26 | } |
| 27 | |
| 28 | export interface VcsDiffCheckpointsInput { |
| 29 | readonly cwd: string; |
| 30 | readonly fromCheckpointRef: CheckpointRef; |
| 31 | readonly toCheckpointRef: CheckpointRef; |
| 32 | readonly fallbackFromToHead?: boolean; |
| 33 | readonly ignoreWhitespace: boolean; |
| 34 | readonly format?: "patch" | "numstat"; |
| 35 | /** Limits the diff to these exact paths. An empty list yields an empty diff. */ |
| 36 | readonly filePaths?: ReadonlyArray<string>; |
| 37 | } |
| 38 | |
| 39 | export interface VcsListAuthoredPathsInput { |
| 40 | readonly cwd: string; |
| 41 | readonly fromCheckpointRef: CheckpointRef; |
| 42 | readonly toCheckpointRef: CheckpointRef; |
| 43 | } |
| 44 | |
| 45 | export interface VcsDeleteCheckpointRefsInput { |
| 46 | readonly cwd: string; |
| 47 | readonly checkpointRefs: ReadonlyArray<CheckpointRef>; |
| 48 | } |
| 49 | |
| 50 | export interface VcsCheckpointOps { |
| 51 | readonly captureCheckpoint: (input: VcsCaptureCheckpointInput) => Effect.Effect<void, VcsError>; |
| 52 | readonly hasCheckpointRef: ( |
| 53 | input: Omit<VcsRestoreCheckpointInput, "fallbackToHead">, |
| 54 | ) => Effect.Effect<boolean, VcsError>; |
| 55 | readonly restoreCheckpoint: ( |
| 56 | input: VcsRestoreCheckpointInput, |
| 57 | ) => Effect.Effect<boolean, VcsError>; |
| 58 | readonly diffCheckpoints: (input: VcsDiffCheckpointsInput) => Effect.Effect<string, VcsError>; |
| 59 | readonly listAuthoredPaths: ( |
| 60 | input: VcsListAuthoredPathsInput, |
| 61 | ) => Effect.Effect<ReadonlySet<string> | null, VcsError>; |
| 62 | readonly deleteCheckpointRefs: ( |
| 63 | input: VcsDeleteCheckpointRefsInput, |
| 64 | ) => Effect.Effect<void, VcsError>; |
| 65 | } |
| 66 | |
| 67 | export class VcsDriver extends Context.Service< |
| 68 | VcsDriver, |
| 69 | { |
| 70 | readonly capabilities: VcsDriverCapabilities; |
| 71 | readonly execute: ( |
| 72 | input: Omit<VcsProcess.VcsProcessInput, "command">, |
| 73 | ) => Effect.Effect<VcsProcess.VcsProcessOutput, VcsError>; |
| 74 | readonly checkpoints?: VcsCheckpointOps; |
| 75 | readonly detectRepository: ( |
| 76 | cwd: string, |
| 77 | ) => Effect.Effect<VcsRepositoryIdentity | null, VcsError>; |
| 78 | readonly isInsideWorkTree: (cwd: string) => Effect.Effect<boolean, VcsError>; |
| 79 | readonly listWorkspaceFiles: ( |
| 80 | cwd: string, |
| 81 | ) => Effect.Effect<VcsListWorkspaceFilesResult, VcsError>; |
| 82 | readonly listRemotes: (cwd: string) => Effect.Effect<VcsListRemotesResult, VcsError>; |
| 83 | readonly filterIgnoredPaths: ( |
| 84 | cwd: string, |
| 85 | relativePaths: ReadonlyArray<string>, |
| 86 | ) => Effect.Effect<ReadonlyArray<string>, VcsError>; |
| 87 | readonly initRepository: (input: VcsInitInput) => Effect.Effect<void, VcsError>; |
| 88 | readonly getDiffPreview?: ( |
| 89 | input: ReviewDiffPreviewInput, |
| 90 | ) => Effect.Effect<ReviewDiffPreviewResult, VcsError>; |
| 91 | } |
| 92 | >()("t3/vcs/VcsDriver") {} |