Julius Marmingedelegate trimming to schemae5542b78 months agoHistory
163 lines · 5.2 KB · TypeScript
RawDownload
import { Schema } from "effect";import { NonNegativeInt, PositiveInt, TrimmedNonEmptyString } from "./baseSchemas"; const TrimmedNonEmptyStringSchema = TrimmedNonEmptyString; // Domain Types export const GitStackedAction = Schema.Literals(["commit", "commit_push", "commit_push_pr"]);export type GitStackedAction = typeof GitStackedAction.Type;export const GitCommitStepStatus = Schema.Literals(["created", "skipped_no_changes"]);export const GitPushStepStatus = Schema.Literals([  "pushed",  "skipped_not_requested",  "skipped_up_to_date",]);export const GitPrStepStatus = Schema.Literals([  "created",  "opened_existing",  "skipped_not_requested",]); export const GitBranch = Schema.Struct({  name: TrimmedNonEmptyStringSchema,  current: Schema.Boolean,  isDefault: Schema.Boolean,  worktreePath: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),});export type GitBranch = typeof GitBranch.Type; export const GitWorktree = Schema.Struct({  path: TrimmedNonEmptyStringSchema,  branch: TrimmedNonEmptyStringSchema,});export type GitWorktree = typeof GitWorktree.Type; // RPC Inputs export const GitStatusInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,});export type GitStatusInput = typeof GitStatusInput.Type; export const GitPullInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,});export type GitPullInput = typeof GitPullInput.Type; export const GitRunStackedActionInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,  action: GitStackedAction,  commitMessage: Schema.optional(TrimmedNonEmptyStringSchema.check(Schema.isMaxLength(10_000))),});export type GitRunStackedActionInput = typeof GitRunStackedActionInput.Type; export const GitListBranchesInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,});export type GitListBranchesInput = typeof GitListBranchesInput.Type; export const GitCreateWorktreeInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,  branch: TrimmedNonEmptyStringSchema,  newBranch: TrimmedNonEmptyStringSchema,  path: Schema.NullOr(TrimmedNonEmptyStringSchema),});export type GitCreateWorktreeInput = typeof GitCreateWorktreeInput.Type; export const GitRemoveWorktreeInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,  path: TrimmedNonEmptyStringSchema,  force: Schema.optional(Schema.Boolean),});export type GitRemoveWorktreeInput = typeof GitRemoveWorktreeInput.Type; export const GitCreateBranchInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,  branch: TrimmedNonEmptyStringSchema,});export type GitCreateBranchInput = typeof GitCreateBranchInput.Type; export const GitCheckoutInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,  branch: TrimmedNonEmptyStringSchema,});export type GitCheckoutInput = typeof GitCheckoutInput.Type; export const GitInitInput = Schema.Struct({  cwd: TrimmedNonEmptyStringSchema,});export type GitInitInput = typeof GitInitInput.Type; // RPC Results export const GitStatusResult = Schema.Struct({  branch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),  hasWorkingTreeChanges: Schema.Boolean,  workingTree: Schema.Struct({    files: Schema.Array(      Schema.Struct({        path: TrimmedNonEmptyStringSchema,        insertions: NonNegativeInt,        deletions: NonNegativeInt,      }),    ),    insertions: NonNegativeInt,    deletions: NonNegativeInt,  }),  hasUpstream: Schema.Boolean,  aheadCount: NonNegativeInt,  behindCount: NonNegativeInt,  openPr: Schema.NullOr(    Schema.Struct({      number: PositiveInt,      title: TrimmedNonEmptyStringSchema,      url: Schema.String,      baseBranch: TrimmedNonEmptyStringSchema,      headBranch: TrimmedNonEmptyStringSchema,    }),  ),});export type GitStatusResult = typeof GitStatusResult.Type; export const GitListBranchesResult = Schema.Struct({  branches: Schema.Array(GitBranch),  isRepo: Schema.Boolean,});export type GitListBranchesResult = typeof GitListBranchesResult.Type; export const GitCreateWorktreeResult = Schema.Struct({  worktree: GitWorktree,});export type GitCreateWorktreeResult = typeof GitCreateWorktreeResult.Type; export const GitRunStackedActionResult = Schema.Struct({  action: GitStackedAction,  commit: Schema.Struct({    status: GitCommitStepStatus,    commitSha: Schema.optional(TrimmedNonEmptyStringSchema),    subject: Schema.optional(TrimmedNonEmptyStringSchema),  }),  push: Schema.Struct({    status: GitPushStepStatus,    branch: Schema.optional(TrimmedNonEmptyStringSchema),    upstreamBranch: Schema.optional(TrimmedNonEmptyStringSchema),    setUpstream: Schema.optional(Schema.Boolean),  }),  pr: Schema.Struct({    status: GitPrStepStatus,    url: Schema.optional(Schema.String),    number: Schema.optional(PositiveInt),    baseBranch: Schema.optional(TrimmedNonEmptyStringSchema),    headBranch: Schema.optional(TrimmedNonEmptyStringSchema),    title: Schema.optional(TrimmedNonEmptyStringSchema),  }),});export type GitRunStackedActionResult = typeof GitRunStackedActionResult.Type; export const GitPullResult = Schema.Struct({  status: Schema.Literals(["pulled", "skipped_up_to_date"]),  branch: TrimmedNonEmptyStringSchema,  upstreamBranch: TrimmedNonEmptyStringSchema.pipe(Schema.NullOr),});export type GitPullResult = typeof GitPullResult.Type;