chore: generate
This commit is contained in:
parent
147c6c4d51
commit
0294342f77
7 changed files with 91 additions and 146 deletions
|
|
@ -186,7 +186,13 @@ export const layer = Layer.effect(
|
|||
})
|
||||
|
||||
const worktreeRemove = Effect.fn("Git.worktreeRemove")(function* (input: { repo: Repo; directory: AbsolutePath }) {
|
||||
yield* worktree("remove", input.repo, ["worktree", "remove", "--force", input.directory], input.directory, input.repo.store)
|
||||
yield* worktree(
|
||||
"remove",
|
||||
input.repo,
|
||||
["worktree", "remove", "--force", input.directory],
|
||||
input.directory,
|
||||
input.repo.store,
|
||||
)
|
||||
})
|
||||
|
||||
const worktreeList = Effect.fn("Git.worktreeList")(function* (repo: Repo) {
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ export function makeStrategies(input: {
|
|||
fs: FSUtil.Interface
|
||||
canonical: (directory: AbsolutePath) => Effect.Effect<AbsolutePath, DirectoryUnavailableError>
|
||||
}) {
|
||||
const repo = (sourceDirectory: AbsolutePath) => ({ directory: sourceDirectory, store: sourceDirectory }) satisfies Git.Repo
|
||||
const repo = (sourceDirectory: AbsolutePath) =>
|
||||
({ directory: sourceDirectory, store: sourceDirectory }) satisfies Git.Repo
|
||||
|
||||
const gitWorktree: Strategy = {
|
||||
id: "git_worktree",
|
||||
|
|
@ -26,7 +27,9 @@ export function makeStrategies(input: {
|
|||
list: Effect.fn("ProjectCopy.GitWorktree.list")(function* (directory) {
|
||||
const entries = yield* input.git.worktreeList(repo(directory))
|
||||
return yield* Effect.forEach(entries, (entry) =>
|
||||
entry === directory ? Effect.succeed(undefined) : input.canonical(entry).pipe(Effect.map((directory) => ({ directory }))),
|
||||
entry === directory
|
||||
? Effect.succeed(undefined)
|
||||
: input.canonical(entry).pipe(Effect.map((directory) => ({ directory }))),
|
||||
).pipe(Effect.map((items) => items.filter((item): item is Copy => item !== undefined)))
|
||||
}),
|
||||
detect: Effect.fn("ProjectCopy.GitWorktree.detect")(function* (inputDirectory) {
|
||||
|
|
|
|||
|
|
@ -120,7 +120,9 @@ export const layer = Layer.effect(
|
|||
const row = yield* db
|
||||
.select({ directory: ProjectDirectoryTable.directory })
|
||||
.from(ProjectDirectoryTable)
|
||||
.where(and(eq(ProjectDirectoryTable.project_id, projectID), eq(ProjectDirectoryTable.directory, sourceDirectory)))
|
||||
.where(
|
||||
and(eq(ProjectDirectoryTable.project_id, projectID), eq(ProjectDirectoryTable.directory, sourceDirectory)),
|
||||
)
|
||||
.get()
|
||||
.pipe(Effect.orDie)
|
||||
if (!row) return yield* new SourceDirectoryNotFoundError({ directory: sourceDirectory })
|
||||
|
|
@ -135,10 +137,18 @@ export const layer = Layer.effect(
|
|||
const row = yield* tx
|
||||
.select({ directory: ProjectDirectoryTable.directory })
|
||||
.from(ProjectDirectoryTable)
|
||||
.where(and(eq(ProjectDirectoryTable.project_id, projectID), eq(ProjectDirectoryTable.directory, copyDirectory)))
|
||||
.where(
|
||||
and(
|
||||
eq(ProjectDirectoryTable.project_id, projectID),
|
||||
eq(ProjectDirectoryTable.directory, copyDirectory),
|
||||
),
|
||||
)
|
||||
.get()
|
||||
if (row) return false
|
||||
yield* tx.insert(ProjectDirectoryTable).values({ project_id: projectID, directory: copyDirectory, type }).run()
|
||||
yield* tx
|
||||
.insert(ProjectDirectoryTable)
|
||||
.values({ project_id: projectID, directory: copyDirectory, type })
|
||||
.run()
|
||||
return true
|
||||
}),
|
||||
{ behavior: "immediate" },
|
||||
|
|
@ -150,7 +160,9 @@ export const layer = Layer.effect(
|
|||
return (
|
||||
(yield* db
|
||||
.delete(ProjectDirectoryTable)
|
||||
.where(and(eq(ProjectDirectoryTable.project_id, projectID), eq(ProjectDirectoryTable.directory, copyDirectory)))
|
||||
.where(
|
||||
and(eq(ProjectDirectoryTable.project_id, projectID), eq(ProjectDirectoryTable.directory, copyDirectory)),
|
||||
)
|
||||
.returning({ directory: ProjectDirectoryTable.directory })
|
||||
.get()
|
||||
.pipe(Effect.orDie)) !== undefined
|
||||
|
|
@ -171,7 +183,8 @@ export const layer = Layer.effect(
|
|||
})
|
||||
|
||||
const create = Effect.fn("ProjectCopy.create")(function* (input: CreateInput) {
|
||||
if (yield* fs.existsSafe(input.directory)) return yield* new DestinationExistsError({ directory: input.directory })
|
||||
if (yield* fs.existsSafe(input.directory))
|
||||
return yield* new DestinationExistsError({ directory: input.directory })
|
||||
const result = yield* strategy(input.strategy).create({
|
||||
directory: input.directory,
|
||||
sourceDirectory: yield* source(input.sourceDirectory, input.projectID),
|
||||
|
|
@ -192,7 +205,12 @@ export const layer = Layer.effect(
|
|||
const roots = yield* db
|
||||
.select({ directory: ProjectDirectoryTable.directory })
|
||||
.from(ProjectDirectoryTable)
|
||||
.where(and(eq(ProjectDirectoryTable.project_id, input.projectID), inArray(ProjectDirectoryTable.type, ["main", "root"])))
|
||||
.where(
|
||||
and(
|
||||
eq(ProjectDirectoryTable.project_id, input.projectID),
|
||||
inArray(ProjectDirectoryTable.type, ["main", "root"]),
|
||||
),
|
||||
)
|
||||
.all()
|
||||
.pipe(Effect.orDie)
|
||||
const sourceDirectories = yield* Effect.forEach(roots, (item) => canonical(AbsolutePath.make(item.directory)), {
|
||||
|
|
@ -207,16 +225,18 @@ export const layer = Layer.effect(
|
|||
.pipe(Effect.map((items) => items.map((item) => ({ ...item, type: strategy.id })))),
|
||||
),
|
||||
{ concurrency: "unbounded" },
|
||||
).pipe(Effect.map((sets) => new Map(sets.flat(2).map((item) => [item.directory, item] as const)).values().toArray()))
|
||||
).pipe(
|
||||
Effect.map((sets) => new Map(sets.flat(2).map((item) => [item.directory, item] as const)).values().toArray()),
|
||||
)
|
||||
const stored = yield* db
|
||||
.select({ directory: ProjectDirectoryTable.directory })
|
||||
.from(ProjectDirectoryTable)
|
||||
.where(eq(ProjectDirectoryTable.project_id, input.projectID))
|
||||
.all()
|
||||
.pipe(Effect.orDie)
|
||||
const inserted = yield* Effect.forEach(discovered, (item) => insert(input.projectID, item.directory, item.type)).pipe(
|
||||
Effect.map((items) => items.some(Boolean)),
|
||||
)
|
||||
const inserted = yield* Effect.forEach(discovered, (item) =>
|
||||
insert(input.projectID, item.directory, item.type),
|
||||
).pipe(Effect.map((items) => items.some(Boolean)))
|
||||
const removed = yield* Effect.forEach(stored, (item) =>
|
||||
fs
|
||||
.isDir(item.directory)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue