main
/** LFS domain: lock list/create/unlock and the ours/theirs verify split. */
import { unwrapApi } from '@app/lib'
import type { EnvelopeLfsLockListResponse, EnvelopeLfsVerifyLocksResponse } from '@app/services/api'
import Apis from '@app/services/api'
export type LfsLockRow = NonNullable<NonNullable<EnvelopeLfsLockListResponse['data']>['locks']>[number]
export type LfsLockPage = NonNullable<EnvelopeLfsLockListResponse['data']>
export type LfsVerifyPage = NonNullable<EnvelopeLfsVerifyLocksResponse['data']>
export const listLfsLocks = (space: string, repo: string, cursor?: string, limit = 50) =>
unwrapApi<LfsLockPage>(
Apis.lfs.list_locks({
pathParams: { space_name: space, repo_name: repo },
params: { cursor: cursor || undefined, limit },
}),
)
export const createLfsLock = (space: string, repo: string, path: string, oid?: string) =>
unwrapApi<unknown>(
Apis.lfs.lock({
pathParams: { space_name: space, repo_name: repo },
data: { path, oid: oid || null },
}),
)
export const unlockLfsPath = (space: string, repo: string, path: string, force = false) =>
unwrapApi<null>(
Apis.lfs.unlock({
pathParams: { space_name: space, repo_name: repo },
params: { path, force },
}),
)
export const unlockLfsById = (space: string, repo: string, lockId: string, force = false) =>
unwrapApi<null>(
Apis.lfs.unlock_by_id({
pathParams: { space_name: space, repo_name: repo, lock_id: lockId },
params: { force },
}),
)
/** Splits locks into ours / theirs, which is what `force` unlocks are for. */
export const verifyLfsLocks = (space: string, repo: string, limit = 50) =>
unwrapApi<LfsVerifyPage>(
Apis.lfs.verify_locks({
pathParams: { space_name: space, repo_name: repo },
params: { limit },
}),
)