| 1 | import * as Schema from "effect/Schema"; |
| 2 | import { TrimmedNonEmptyString } from "./baseSchemas.ts"; |
| 3 | import { GitCommandError } from "./git.ts"; |
| 4 | import { VcsError } from "./vcs.ts"; |
| 5 | |
| 6 | export const ReviewDiffPreviewInput = Schema.Struct({ |
| 7 | cwd: TrimmedNonEmptyString, |
| 8 | baseRef: Schema.optional(TrimmedNonEmptyString), |
| 9 | ignoreWhitespace: Schema.optionalKey(Schema.Boolean), |
| 10 | file: Schema.optionalKey( |
| 11 | Schema.Struct({ |
| 12 | path: Schema.NonEmptyString, |
| 13 | previousPath: Schema.NullOr(Schema.NonEmptyString), |
| 14 | sourceKind: Schema.Literals(["working-tree", "branch-range"]), |
| 15 | }), |
| 16 | ), |
| 17 | }); |
| 18 | export type ReviewDiffPreviewInput = typeof ReviewDiffPreviewInput.Type; |
| 19 | |
| 20 | export const ReviewDiffPreviewSourceKind = Schema.Literals(["working-tree", "branch-range"]); |
| 21 | export type ReviewDiffPreviewSourceKind = typeof ReviewDiffPreviewSourceKind.Type; |
| 22 | |
| 23 | export const ReviewDiffFileStat = Schema.Struct({ |
| 24 | path: Schema.String, |
| 25 | previousPath: Schema.NullOr(Schema.String), |
| 26 | additions: Schema.Number, |
| 27 | deletions: Schema.Number, |
| 28 | }); |
| 29 | export type ReviewDiffFileStat = typeof ReviewDiffFileStat.Type; |
| 30 | |
| 31 | export const ReviewDiffPreviewSource = Schema.Struct({ |
| 32 | id: TrimmedNonEmptyString, |
| 33 | kind: ReviewDiffPreviewSourceKind, |
| 34 | title: TrimmedNonEmptyString, |
| 35 | baseRef: Schema.NullOr(TrimmedNonEmptyString), |
| 36 | headRef: Schema.NullOr(TrimmedNonEmptyString), |
| 37 | diff: Schema.String, |
| 38 | diffHash: TrimmedNonEmptyString, |
| 39 | truncated: Schema.Boolean, |
| 40 | /** Complete statistics, independent of patch limits. Absent on older servers. */ |
| 41 | files: Schema.optionalKey(Schema.Array(ReviewDiffFileStat)), |
| 42 | }); |
| 43 | export type ReviewDiffPreviewSource = typeof ReviewDiffPreviewSource.Type; |
| 44 | |
| 45 | export const ReviewDiffFileContentsInput = Schema.Struct({ |
| 46 | cwd: TrimmedNonEmptyString, |
| 47 | sourceKind: ReviewDiffPreviewSourceKind, |
| 48 | changeType: Schema.Literals(["change", "rename-pure", "rename-changed", "new", "deleted"]), |
| 49 | baseRef: Schema.NullOr(TrimmedNonEmptyString), |
| 50 | headRef: Schema.NullOr(TrimmedNonEmptyString), |
| 51 | oldPath: TrimmedNonEmptyString, |
| 52 | newPath: TrimmedNonEmptyString, |
| 53 | }); |
| 54 | export type ReviewDiffFileContentsInput = typeof ReviewDiffFileContentsInput.Type; |
| 55 | |
| 56 | export const ReviewDiffFileContentsResult = Schema.Struct({ |
| 57 | oldContents: Schema.String, |
| 58 | newContents: Schema.String, |
| 59 | }); |
| 60 | export type ReviewDiffFileContentsResult = typeof ReviewDiffFileContentsResult.Type; |
| 61 | |
| 62 | export const ReviewDiffPreviewResult = Schema.Struct({ |
| 63 | cwd: TrimmedNonEmptyString, |
| 64 | generatedAt: Schema.DateTimeUtc, |
| 65 | sources: Schema.Array(ReviewDiffPreviewSource), |
| 66 | }); |
| 67 | export type ReviewDiffPreviewResult = typeof ReviewDiffPreviewResult.Type; |
| 68 | |
| 69 | export const ReviewDiffPreviewError = Schema.Union([VcsError, GitCommandError]); |
| 70 | export type ReviewDiffPreviewError = typeof ReviewDiffPreviewError.Type; |