feat(repositories): healthchecks and doctor command

This commit is contained in:
Nicolas Meienberger
2025-11-08 10:11:07 +01:00
parent f5339d3708
commit 4dc239139f
14 changed files with 554 additions and 61 deletions

View File

@@ -27,6 +27,7 @@ import {
getSnapshotDetails,
listSnapshotFiles,
restoreSnapshot,
doctorRepository,
listBackupSchedules,
createBackupSchedule,
deleteBackupSchedule,
@@ -76,6 +77,8 @@ import type {
ListSnapshotFilesData,
RestoreSnapshotData,
RestoreSnapshotResponse,
DoctorRepositoryData,
DoctorRepositoryResponse,
ListBackupSchedulesData,
CreateBackupScheduleData,
CreateBackupScheduleResponse,
@@ -844,6 +847,46 @@ export const restoreSnapshotMutation = (
return mutationOptions;
};
export const doctorRepositoryQueryKey = (options: Options<DoctorRepositoryData>) =>
createQueryKey("doctorRepository", options);
/**
* Run doctor operations on a repository to fix common issues (unlock, check, repair index). Use this when the repository is locked or has errors.
*/
export const doctorRepositoryOptions = (options: Options<DoctorRepositoryData>) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await doctorRepository({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: doctorRepositoryQueryKey(options),
});
};
/**
* Run doctor operations on a repository to fix common issues (unlock, check, repair index). Use this when the repository is locked or has errors.
*/
export const doctorRepositoryMutation = (
options?: Partial<Options<DoctorRepositoryData>>,
): UseMutationOptions<DoctorRepositoryResponse, DefaultError, Options<DoctorRepositoryData>> => {
const mutationOptions: UseMutationOptions<DoctorRepositoryResponse, DefaultError, Options<DoctorRepositoryData>> = {
mutationFn: async (localOptions) => {
const { data } = await doctorRepository({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};
export const listBackupSchedulesQueryKey = (options?: Options<ListBackupSchedulesData>) =>
createQueryKey("listBackupSchedules", options);