9 lines
607 B
TypeScript
9 lines
607 B
TypeScript
export class BackupPruneError extends Error {
|
|
constructor(public readonly pruned: number, cause: unknown) { super("Очистка резервных копий прервана после " + pruned + " удалений: " + (cause instanceof Error ? cause.message : String(cause)), { cause }); this.name = "BackupPruneError" }
|
|
}
|
|
export async function pruneBackupRecords(ids: string[], remove: (id: string) => Promise<unknown>): Promise<number> {
|
|
let pruned = 0
|
|
for (const id of ids) { try { if (await remove(id)) pruned++ } catch (cause) { throw new BackupPruneError(pruned, cause) } }
|
|
return pruned
|
|
}
|