From 4f09420c25c06989d14d5b4f4b099d2cf8cedfd2 Mon Sep 17 00:00:00 2001 From: Nicolas Meienberger Date: Sun, 31 May 2026 19:26:51 +0200 Subject: [PATCH] refactor: export restore progress from dto file --- packages/core/src/restic/commands/restore.ts | 20 ++++++-------------- packages/core/src/restic/index.ts | 1 - packages/core/src/restic/restic-dto.ts | 11 +++++++++++ 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/packages/core/src/restic/commands/restore.ts b/packages/core/src/restic/commands/restore.ts index 996fbef8..9b6b8f7e 100644 --- a/packages/core/src/restic/commands/restore.ts +++ b/packages/core/src/restic/commands/restore.ts @@ -1,5 +1,4 @@ import path from "node:path"; -import { z } from "zod"; import { throttle } from "es-toolkit"; import { findCommonAncestor } from "../../utils/common-ancestor"; import { addCommonArgs } from "../helpers/add-common-args"; @@ -9,7 +8,12 @@ import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { type RepositoryConfig, type OverwriteMode } from "../schemas"; import { logger, safeSpawn } from "../../node"; import { createResticError, isResticError, type AnyResticError } from "../error"; -import { resticRestoreOutputSchema, type ResticRestoreOutputDto } from "../restic-dto"; +import { + restoreProgressSchema, + resticRestoreOutputSchema, + type RestoreProgress, + type ResticRestoreOutputDto, +} from "../restic-dto"; import type { ResticDeps } from "../types"; import { Data, Effect } from "effect"; import { toMessage } from "../../utils"; @@ -19,18 +23,6 @@ class ResticRestoreCommandError extends Data.TaggedError("ResticRestoreCommandEr message: string; }> {} -export const restoreProgressSchema = z.object({ - message_type: z.enum(["status", "summary"]), - seconds_elapsed: z.number().default(0), - percent_done: z.number().default(0), - total_files: z.number().default(0), - files_restored: z.number().default(0), - total_bytes: z.number().default(0), - bytes_restored: z.number().default(0), -}); - -export type RestoreProgress = z.infer; - export const restore = ( config: RepositoryConfig, snapshotId: string, diff --git a/packages/core/src/restic/index.ts b/packages/core/src/restic/index.ts index 4624ed86..2f975a25 100644 --- a/packages/core/src/restic/index.ts +++ b/packages/core/src/restic/index.ts @@ -1,7 +1,6 @@ export * from "./schemas"; export * from "./restic-dto"; export { isResticError, ResticError, ResticLockError } from "./error"; -export { restoreProgressSchema, type RestoreProgress } from "./commands/restore"; export type { ResticDeps, ResticEnv, diff --git a/packages/core/src/restic/restic-dto.ts b/packages/core/src/restic/restic-dto.ts index 2d3b36bf..344cb53f 100644 --- a/packages/core/src/restic/restic-dto.ts +++ b/packages/core/src/restic/restic-dto.ts @@ -54,6 +54,16 @@ export const resticRestoreOutputSchema = z.object({ bytes_skipped: z.number().optional(), }); +export const restoreProgressSchema = z.object({ + message_type: z.enum(["status", "summary"]), + seconds_elapsed: z.number().default(0), + percent_done: z.number().default(0), + total_files: z.number().default(0), + files_restored: z.number().default(0), + total_bytes: z.number().default(0), + bytes_restored: z.number().default(0), +}); + export const resticStatsSchema = z.object({ total_size: z.number().default(0), total_uncompressed_size: z.number().default(0), @@ -70,4 +80,5 @@ export type ResticBackupProgressMetricsDto = z.infer; export type ResticRestoreOutputDto = z.infer; +export type RestoreProgress = z.infer; export type ResticStatsDto = z.infer;