refactor: split server utils

This commit is contained in:
Nicolas Meienberger 2026-03-11 18:02:05 +01:00
parent a458252742
commit 9be16a2172
71 changed files with 147 additions and 172 deletions

View file

@ -1,4 +1,4 @@
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { shutdown } from "./server/modules/lifecycle/shutdown"; import { shutdown } from "./server/modules/lifecycle/shutdown";
import { runCLI } from "./server/cli"; import { runCLI } from "./server/cli";
import { createStartHandler, defaultStreamHandler, defineHandlerCallback } from "@tanstack/react-start/server"; import { createStartHandler, defaultStreamHandler, defineHandlerCallback } from "@tanstack/react-start/server";

View file

@ -16,7 +16,7 @@ import { backupScheduleController } from "./modules/backups/backups.controller";
import { eventsController } from "./modules/events/events.controller"; import { eventsController } from "./modules/events/events.controller";
import { notificationsController } from "./modules/notifications/notifications.controller"; import { notificationsController } from "./modules/notifications/notifications.controller";
import { handleServiceError } from "./utils/errors"; import { handleServiceError } from "./utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { config } from "./core/config"; import { config } from "./core/config";
import { auth } from "~/server/lib/auth"; import { auth } from "~/server/lib/auth";
import { db } from "./db/db"; import { db } from "./db/db";

View file

@ -1,5 +1,5 @@
import { afterEach, describe, expect, mock, spyOn, test, vi } from "bun:test"; import { afterEach, describe, expect, mock, spyOn, test, vi } from "bun:test";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { Job, Scheduler } from "../scheduler"; import { Job, Scheduler } from "../scheduler";
const flushMicrotasks = async () => { const flushMicrotasks = async () => {

View file

@ -1,6 +1,6 @@
import * as fs from "node:fs/promises"; import * as fs from "node:fs/promises";
import { RCLONE_CONFIG_DIR } from "./constants"; import { RCLONE_CONFIG_DIR } from "./constants";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
export type SystemCapabilities = { export type SystemCapabilities = {
rclone: boolean; rclone: boolean;

View file

@ -1,4 +1,4 @@
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
export type LockType = "shared" | "exclusive"; export type LockType = "shared" | "exclusive";

View file

@ -1,5 +1,7 @@
import { createRestic, type ResticDeps } from "@zerobyte/core/restic"; import { createRestic } from "@zerobyte/core/restic/server";
import type { ResticDeps } from "@zerobyte/core/restic";
import { DEFAULT_EXCLUDES, RESTIC_CACHE_DIR, RESTIC_PASS_FILE } from "./constants"; import { DEFAULT_EXCLUDES, RESTIC_CACHE_DIR, RESTIC_PASS_FILE } from "./constants";
import { config } from "./config";
import { cryptoUtils } from "../utils/crypto"; import { cryptoUtils } from "../utils/crypto";
import { db } from "../db/db"; import { db } from "../db/db";
@ -24,6 +26,7 @@ export const resticDeps: ResticDeps = {
resticCacheDir: RESTIC_CACHE_DIR, resticCacheDir: RESTIC_CACHE_DIR,
resticPassFile: RESTIC_PASS_FILE, resticPassFile: RESTIC_PASS_FILE,
defaultExcludes: DEFAULT_EXCLUDES, defaultExcludes: DEFAULT_EXCLUDES,
hostname: config.resticHostname,
}; };
export const restic = createRestic(resticDeps); export const restic = createRestic(resticDeps);

View file

@ -1,5 +1,5 @@
import CronExpressionParser from "cron-parser"; import CronExpressionParser from "cron-parser";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
export abstract class Job { export abstract class Job {
abstract run(): Promise<unknown>; abstract run(): Promise<unknown>;

View file

@ -1,6 +1,6 @@
import { Job } from "../core/scheduler"; import { Job } from "../core/scheduler";
import { volumeService } from "../modules/volumes/volume.service"; import { volumeService } from "../modules/volumes/volume.service";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { db } from "../db/db"; import { db } from "../db/db";
import { withContext } from "../core/request-context"; import { withContext } from "../core/request-context";

View file

@ -1,6 +1,6 @@
import { Job } from "../core/scheduler"; import { Job } from "../core/scheduler";
import { backupsExecutionService } from "../modules/backups/backups.execution"; import { backupsExecutionService } from "../modules/backups/backups.execution";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { db } from "../db/db"; import { db } from "../db/db";
import { withContext } from "../core/request-context"; import { withContext } from "../core/request-context";

View file

@ -4,7 +4,7 @@ import fs from "node:fs/promises";
import { volumeService } from "../modules/volumes/volume.service"; import { volumeService } from "../modules/volumes/volume.service";
import { readMountInfo } from "../utils/mountinfo"; import { readMountInfo } from "../utils/mountinfo";
import { getVolumePath } from "../modules/volumes/helpers"; import { getVolumePath } from "../modules/volumes/helpers";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { executeUnmount } from "../modules/backends/utils/backend-utils"; import { executeUnmount } from "../modules/backends/utils/backend-utils";
import { toMessage } from "../utils/errors"; import { toMessage } from "../utils/errors";
import { VOLUME_MOUNT_BASE } from "../core/constants"; import { VOLUME_MOUNT_BASE } from "../core/constants";

View file

@ -1,6 +1,6 @@
import { Job } from "../core/scheduler"; import { Job } from "../core/scheduler";
import { volumeService } from "../modules/volumes/volume.service"; import { volumeService } from "../modules/volumes/volume.service";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { db } from "../db/db"; import { db } from "../db/db";
import { withContext } from "../core/request-context"; import { withContext } from "../core/request-context";

View file

@ -1,6 +1,6 @@
import { Job } from "../core/scheduler"; import { Job } from "../core/scheduler";
import { repositoriesService } from "../modules/repositories/repositories.service"; import { repositoriesService } from "../modules/repositories/repositories.service";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { db } from "../db/db"; import { db } from "../db/db";
import { withContext } from "../core/request-context"; import { withContext } from "../core/request-context";

View file

@ -12,7 +12,7 @@ import { createAuthMiddleware } from "better-auth/api";
import { config } from "../core/config"; import { config } from "../core/config";
import { db } from "../db/db"; import { db } from "../db/db";
import { cryptoUtils } from "../utils/crypto"; import { cryptoUtils } from "../utils/crypto";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { authService } from "../modules/auth/auth.service"; import { authService } from "../modules/auth/auth.service";
import { tanstackStartCookies } from "better-auth/tanstack-start"; import { tanstackStartCookies } from "better-auth/tanstack-start";
import { isValidUsername, normalizeUsername } from "~/lib/username"; import { isValidUsername, normalizeUsername } from "~/lib/username";

View file

@ -2,7 +2,7 @@ import { UnauthorizedError } from "http-errors-enhanced";
import { db } from "~/server/db/db"; import { db } from "~/server/db/db";
import { member, organization, type User } from "~/server/db/schema"; import { member, organization, type User } from "~/server/db/schema";
import { cryptoUtils } from "~/server/utils/crypto"; import { cryptoUtils } from "~/server/utils/crypto";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
export async function findMembershipWithOrganization(userId: string, organizationId?: string) { export async function findMembershipWithOrganization(userId: string, organizationId?: string) {
const membership = await db.query.member.findFirst({ const membership = await db.query.member.findFirst({

View file

@ -1,6 +1,6 @@
import { db } from "~/server/db/db"; import { db } from "~/server/db/db";
import type { AuthMiddlewareContext } from "~/server/lib/auth"; import type { AuthMiddlewareContext } from "~/server/lib/auth";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { ForbiddenError } from "http-errors-enhanced"; import { ForbiddenError } from "http-errors-enhanced";
import { REGISTRATION_ENABLED_KEY } from "~/server/core/constants"; import { REGISTRATION_ENABLED_KEY } from "~/server/core/constants";

View file

@ -1,6 +1,6 @@
import * as fs from "node:fs/promises"; import * as fs from "node:fs/promises";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import type { VolumeBackend } from "../backend"; import type { VolumeBackend } from "../backend";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes"; import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";

View file

@ -3,7 +3,7 @@ import * as os from "node:os";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes"; import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT } from "../../../core/constants";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
import { withTimeout } from "../../../utils/timeout"; import { withTimeout } from "../../../utils/timeout";
import type { VolumeBackend } from "../backend"; import type { VolumeBackend } from "../backend";

View file

@ -2,13 +2,13 @@ import * as fs from "node:fs/promises";
import * as os from "node:os"; import * as os from "node:os";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT } from "../../../core/constants";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
import { withTimeout } from "../../../utils/timeout"; import { withTimeout } from "../../../utils/timeout";
import type { VolumeBackend } from "../backend"; import type { VolumeBackend } from "../backend";
import { executeUnmount } from "../utils/backend-utils"; import { executeUnmount } from "../utils/backend-utils";
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes"; import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
import { safeExec } from "@zerobyte/core/utils"; import { safeExec } from "@zerobyte/core/node";
import { config as zbConfig } from "~/server/core/config"; import { config as zbConfig } from "~/server/core/config";
const mount = async (config: BackendConfig, path: string) => { const mount = async (config: BackendConfig, path: string) => {

View file

@ -5,7 +5,7 @@ import { spawn } from "node:child_process";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT } from "../../../core/constants";
import { cryptoUtils } from "../../../utils/crypto"; import { cryptoUtils } from "../../../utils/crypto";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
import { withTimeout } from "../../../utils/timeout"; import { withTimeout } from "../../../utils/timeout";
import type { VolumeBackend } from "../backend"; import type { VolumeBackend } from "../backend";

View file

@ -3,7 +3,7 @@ import * as os from "node:os";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT } from "../../../core/constants";
import { cryptoUtils } from "../../../utils/crypto"; import { cryptoUtils } from "../../../utils/crypto";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
import { withTimeout } from "../../../utils/timeout"; import { withTimeout } from "../../../utils/timeout";
import type { VolumeBackend } from "../backend"; import type { VolumeBackend } from "../backend";

View file

@ -1,8 +1,8 @@
import * as fs from "node:fs/promises"; import * as fs from "node:fs/promises";
import * as npath from "node:path"; import * as npath from "node:path";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { safeExec } from "@zerobyte/core/utils"; import { safeExec } from "@zerobyte/core/node";
export const executeMount = async (args: string[]): Promise<void> => { export const executeMount = async (args: string[]): Promise<void> => {
const shouldBeVerbose = process.env.LOG_LEVEL === "debug" || process.env.NODE_ENV !== "production"; const shouldBeVerbose = process.env.LOG_LEVEL === "debug" || process.env.NODE_ENV !== "production";

View file

@ -3,7 +3,7 @@ import * as os from "node:os";
import { OPERATION_TIMEOUT } from "../../../core/constants"; import { OPERATION_TIMEOUT } from "../../../core/constants";
import { cryptoUtils } from "../../../utils/crypto"; import { cryptoUtils } from "../../../utils/crypto";
import { toMessage } from "../../../utils/errors"; import { toMessage } from "../../../utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { getMountForPath } from "../../../utils/mountinfo"; import { getMountForPath } from "../../../utils/mountinfo";
import { withTimeout } from "../../../utils/timeout"; import { withTimeout } from "../../../utils/timeout";
import type { VolumeBackend } from "../backend"; import type { VolumeBackend } from "../backend";

View file

@ -9,7 +9,7 @@ import { createTestBackupScheduleMirror } from "~/test/helpers/backup-mirror";
import { generateBackupOutput } from "~/test/helpers/restic"; import { generateBackupOutput } from "~/test/helpers/restic";
import { TEST_ORG_ID } from "~/test/helpers/organization"; import { TEST_ORG_ID } from "~/test/helpers/organization";
import * as context from "~/server/core/request-context"; import * as context from "~/server/core/request-context";
import * as spawnModule from "@zerobyte/core/utils"; import * as spawnModule from "@zerobyte/core/node";
import { restic } from "~/server/core/restic"; import { restic } from "~/server/core/restic";
import { NotFoundError, BadRequestError } from "http-errors-enhanced"; import { NotFoundError, BadRequestError } from "http-errors-enhanced";
import { scheduleQueries } from "../backups.queries"; import { scheduleQueries } from "../backups.queries";

View file

@ -7,7 +7,7 @@ import { createTestBackupSchedule } from "~/test/helpers/backup";
import { createTestRepository } from "~/test/helpers/repository"; import { createTestRepository } from "~/test/helpers/repository";
import { generateBackupOutput } from "~/test/helpers/restic"; import { generateBackupOutput } from "~/test/helpers/restic";
import { faker } from "@faker-js/faker"; import { faker } from "@faker-js/faker";
import * as spawnModule from "@zerobyte/core/utils"; import * as spawnModule from "@zerobyte/core/node";
import { db } from "~/server/db/db"; import { db } from "~/server/db/db";
import { backupScheduleMirrorsTable, repositoriesTable, volumesTable } from "~/server/db/schema"; import { backupScheduleMirrorsTable, repositoriesTable, volumesTable } from "~/server/db/schema";
import { TEST_ORG_ID } from "~/test/helpers/organization"; import { TEST_ORG_ID } from "~/test/helpers/organization";

View file

@ -2,7 +2,7 @@ import CronExpressionParser from "cron-parser";
import path from "node:path"; import path from "node:path";
import type { BackupSchedule } from "~/server/db/schema"; import type { BackupSchedule } from "~/server/db/schema";
import { toMessage } from "~/server/utils/errors"; import { toMessage } from "~/server/utils/errors";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
export const calculateNextRun = (cronExpression: string) => { export const calculateNextRun = (cronExpression: string) => {
try { try {

View file

@ -45,7 +45,7 @@ import {
import { notificationsService } from "../notifications/notifications.service"; import { notificationsService } from "../notifications/notifications.service";
import { requireAuth } from "../auth/auth.middleware"; import { requireAuth } from "../auth/auth.middleware";
import { backupsExecutionService } from "./backups.execution"; import { backupsExecutionService } from "./backups.execution";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { asShortId } from "~/server/utils/branded"; import { asShortId } from "~/server/utils/branded";
export const backupScheduleController = new Hono() export const backupScheduleController = new Hono()

View file

@ -1,7 +1,7 @@
import { NotFoundError, BadRequestError, ConflictError } from "http-errors-enhanced"; import { NotFoundError, BadRequestError, ConflictError } from "http-errors-enhanced";
import type { BackupSchedule, Volume, Repository } from "../../db/schema"; import type { BackupSchedule, Volume, Repository } from "../../db/schema";
import { restic } from "../../core/restic"; import { restic } from "../../core/restic";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { cache, cacheKeys } from "../../utils/cache"; import { cache, cacheKeys } from "../../utils/cache";
import { getVolumePath } from "../volumes/helpers"; import { getVolumePath } from "../volumes/helpers";
import { toMessage } from "../../utils/errors"; import { toMessage } from "../../utils/errors";

View file

@ -19,7 +19,7 @@ import { generateShortId } from "~/server/utils/id";
import { getOrganizationId } from "~/server/core/request-context"; import { getOrganizationId } from "~/server/core/request-context";
import { calculateNextRun } from "./backup.helpers"; import { calculateNextRun } from "./backup.helpers";
import { asShortId, type ShortId } from "~/server/utils/branded"; import { asShortId, type ShortId } from "~/server/utils/branded";
import { validateCustomResticParams } from "@zerobyte/core/restic"; import { validateCustomResticParams } from "@zerobyte/core/restic/server";
const listSchedules = async () => { const listSchedules = async () => {
const organizationId = getOrganizationId(); const organizationId = getOrganizationId();

View file

@ -1,7 +1,7 @@
import { Hono } from "hono"; import { Hono } from "hono";
import { streamSSE } from "hono/streaming"; import { streamSSE } from "hono/streaming";
import { serverEvents } from "../../core/events"; import { serverEvents } from "../../core/events";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { requireAuth } from "../auth/auth.middleware"; import { requireAuth } from "../auth/auth.middleware";
import type { ServerEventPayloadMap } from "~/schemas/server-events"; import type { ServerEventPayloadMap } from "~/schemas/server-events";

View file

@ -1,4 +1,4 @@
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { v00001 } from "./migrations/00001-retag-snapshots"; import { v00001 } from "./migrations/00001-retag-snapshots";
import { v00002 } from "./migrations/00002-isolate-restic-passwords"; import { v00002 } from "./migrations/00002-isolate-restic-passwords";
import { v00003 } from "./migrations/00003-assign-organization"; import { v00003 } from "./migrations/00003-assign-organization";

View file

@ -1,10 +1,10 @@
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { db } from "../../../db/db"; import { db } from "../../../db/db";
import { backupScheduleMirrorsTable, type Repository } from "../../../db/schema"; import { backupScheduleMirrorsTable, type Repository } from "../../../db/schema";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "~/server/utils/errors"; import { toMessage } from "~/server/utils/errors";
import { safeExec } from "@zerobyte/core/utils"; import { safeExec } from "@zerobyte/core/node";
import { addCommonArgs, buildEnv, buildRepoUrl, cleanupTemporaryKeys } from "@zerobyte/core/restic"; import { addCommonArgs, buildEnv, buildRepoUrl, cleanupTemporaryKeys } from "@zerobyte/core/restic/server";
import { resticDeps } from "~/server/core/restic"; import { resticDeps } from "~/server/core/restic";
const migrateTag = async ( const migrateTag = async (

View file

@ -9,7 +9,7 @@ import {
notificationDestinationsTable, notificationDestinationsTable,
twoFactor, twoFactor,
} from "../../../db/schema"; } from "../../../db/schema";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "~/server/utils/errors"; import { toMessage } from "~/server/utils/errors";
import { cryptoUtils } from "~/server/utils/crypto"; import { cryptoUtils } from "~/server/utils/crypto";
import type { RepositoryConfig } from "@zerobyte/core/restic"; import type { RepositoryConfig } from "@zerobyte/core/restic";

View file

@ -1,6 +1,6 @@
import { db } from "../../../db/db"; import { db } from "../../../db/db";
import { member } from "../../../db/schema"; import { member } from "../../../db/schema";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "~/server/utils/errors"; import { toMessage } from "~/server/utils/errors";
const execute = async () => { const execute = async () => {

View file

@ -1,7 +1,7 @@
import { and, eq } from "drizzle-orm"; import { and, eq } from "drizzle-orm";
import { db } from "../../../db/db"; import { db } from "../../../db/db";
import { repositoriesTable } from "../../../db/schema"; import { repositoriesTable } from "../../../db/schema";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "~/server/utils/errors"; import { toMessage } from "~/server/utils/errors";
import { REPOSITORY_BASE } from "~/server/core/constants"; import { REPOSITORY_BASE } from "~/server/core/constants";
import { repositoryConfigSchema } from "@zerobyte/core/restic"; import { repositoryConfigSchema } from "@zerobyte/core/restic";

View file

@ -1,6 +1,6 @@
import { Scheduler } from "../../core/scheduler"; import { Scheduler } from "../../core/scheduler";
import { db } from "../../db/db"; import { db } from "../../db/db";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { createVolumeBackend } from "../backends/backend"; import { createVolumeBackend } from "../backends/backend";
export const shutdown = async () => { export const shutdown = async () => {

View file

@ -2,7 +2,7 @@ import { Scheduler } from "../../core/scheduler";
import { eq } from "drizzle-orm"; import { eq } from "drizzle-orm";
import { db } from "../../db/db"; import { db } from "../../db/db";
import { backupSchedulesTable } from "../../db/schema"; import { backupSchedulesTable } from "../../db/schema";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { volumeService } from "../volumes/volume.service"; import { volumeService } from "../volumes/volume.service";
import { CleanupDanglingMountsJob } from "../../jobs/cleanup-dangling"; import { CleanupDanglingMountsJob } from "../../jobs/cleanup-dangling";
import { VolumeHealthCheckJob } from "../../jobs/healthchecks"; import { VolumeHealthCheckJob } from "../../jobs/healthchecks";

View file

@ -7,7 +7,7 @@ import {
type NotificationDestination, type NotificationDestination,
} from "../../db/schema"; } from "../../db/schema";
import { cryptoUtils } from "../../utils/crypto"; import { cryptoUtils } from "../../utils/crypto";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { sendNotification } from "../../utils/shoutrrr"; import { sendNotification } from "../../utils/shoutrrr";
import { formatDuration } from "~/utils/utils"; import { formatDuration } from "~/utils/utils";
import { buildShoutrrrUrl } from "./builders"; import { buildShoutrrrUrl } from "./builders";

View file

@ -12,7 +12,7 @@ import { restic } from "~/server/core/restic";
import { createTestSession } from "~/test/helpers/auth"; import { createTestSession } from "~/test/helpers/auth";
import { createTestBackupSchedule } from "~/test/helpers/backup"; import { createTestBackupSchedule } from "~/test/helpers/backup";
import { cache, cacheKeys } from "~/server/utils/cache"; import { cache, cacheKeys } from "~/server/utils/cache";
import { ResticError } from "@zerobyte/core/restic"; import { ResticError } from "@zerobyte/core/restic/server";
import { repositoriesService } from "../repositories.service"; import { repositoriesService } from "../repositories.service";
const createTestRepository = async (organizationId: string) => { const createTestRepository = async (organizationId: string) => {

View file

@ -5,7 +5,7 @@ import { getOrganizationId } from "~/server/core/request-context";
import { restic } from "~/server/core/restic"; import { restic } from "~/server/core/restic";
import { toMessage } from "~/server/utils/errors"; import { toMessage } from "~/server/utils/errors";
import { safeJsonParse } from "@zerobyte/core/utils"; import { safeJsonParse } from "@zerobyte/core/utils";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { db } from "~/server/db/db"; import { db } from "~/server/db/db";
import { repositoriesTable } from "~/server/db/schema"; import { repositoriesTable } from "~/server/db/schema";
import { repoMutex } from "~/server/core/repository-mutex"; import { repoMutex } from "~/server/core/repository-mutex";

View file

@ -12,7 +12,7 @@ import {
import { config as appConfig } from "~/server/core/config"; import { config as appConfig } from "~/server/core/config";
import { serverEvents } from "~/server/core/events"; import { serverEvents } from "~/server/core/events";
import { getOrganizationId } from "~/server/core/request-context"; import { getOrganizationId } from "~/server/core/request-context";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { parseRetentionCategories, type RetentionCategory } from "~/server/utils/retention-categories"; import { parseRetentionCategories, type RetentionCategory } from "~/server/utils/retention-categories";
import { repoMutex } from "../../core/repository-mutex"; import { repoMutex } from "../../core/repository-mutex";
import { db } from "../../db/db"; import { db } from "../../db/db";
@ -21,9 +21,9 @@ import { cache, cacheKeys } from "../../utils/cache";
import { cryptoUtils } from "../../utils/crypto"; import { cryptoUtils } from "../../utils/crypto";
import { toMessage } from "../../utils/errors"; import { toMessage } from "../../utils/errors";
import { generateShortId } from "../../utils/id"; import { generateShortId } from "../../utils/id";
import { addCommonArgs, buildEnv, buildRepoUrl, cleanupTemporaryKeys } from "@zerobyte/core/restic"; import { addCommonArgs, buildEnv, buildRepoUrl, cleanupTemporaryKeys } from "@zerobyte/core/restic/server";
import { restic, resticDeps } from "../../core/restic"; import { restic, resticDeps } from "../../core/restic";
import { safeSpawn } from "@zerobyte/core/utils"; import { safeSpawn } from "@zerobyte/core/node";
import { backupsService } from "../backups/backups.service"; import { backupsService } from "../backups/backups.service";
import type { DumpPathKind, UpdateRepositoryBody } from "./repositories.dto"; import type { DumpPathKind, UpdateRepositoryBody } from "./repositories.dto";
import { findCommonAncestor } from "@zerobyte/core/utils"; import { findCommonAncestor } from "@zerobyte/core/utils";

View file

@ -1,6 +1,6 @@
import { APIError } from "better-auth/api"; import { APIError } from "better-auth/api";
import type { GenericEndpointContext } from "better-auth"; import type { GenericEndpointContext } from "better-auth";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { extractProviderIdFromContext } from "~/server/modules/sso/utils/sso-context"; import { extractProviderIdFromContext } from "~/server/modules/sso/utils/sso-context";
import { ssoService } from "~/server/modules/sso/sso.service"; import { ssoService } from "~/server/modules/sso/sso.service";

View file

@ -13,7 +13,7 @@ import { requireSsoInvitation } from "./middlewares/require-invitation";
import { resolveTrustedProvidersForRequest } from "./middlewares/trust-provider-for-linking"; import { resolveTrustedProvidersForRequest } from "./middlewares/trust-provider-for-linking";
import { isSsoCallbackRequest, extractProviderIdFromContext, normalizeEmail } from "./utils/sso-context"; import { isSsoCallbackRequest, extractProviderIdFromContext, normalizeEmail } from "./utils/sso-context";
import { findMembershipWithOrganization } from "~/server/lib/auth/helpers/create-default-org"; import { findMembershipWithOrganization } from "~/server/lib/auth/helpers/create-default-org";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
async function resolveOrgMembership(userId: string, ctx: GenericEndpointContext | null) { async function resolveOrgMembership(userId: string, ctx: GenericEndpointContext | null) {
const user = await db.query.usersTable.findFirst({ where: { id: userId } }); const user = await db.query.usersTable.findFirst({ where: { id: userId } });

View file

@ -3,7 +3,7 @@ import { config } from "../../core/config";
import type { UpdateInfoDto } from "./system.dto"; import type { UpdateInfoDto } from "./system.dto";
import semver from "semver"; import semver from "semver";
import { cache, cacheKeys } from "../../utils/cache"; import { cache, cacheKeys } from "../../utils/cache";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { db } from "../../db/db"; import { db } from "../../db/db";
import { appMetadataTable } from "../../db/schema"; import { appMetadataTable } from "../../db/schema";
import { REGISTRATION_ENABLED_KEY } from "~/server/core/constants"; import { REGISTRATION_ENABLED_KEY } from "~/server/core/constants";

View file

@ -13,7 +13,7 @@ import { withTimeout } from "../../utils/timeout";
import { createVolumeBackend } from "../backends/backend"; import { createVolumeBackend } from "../backends/backend";
import type { UpdateVolumeBody } from "./volume.dto"; import type { UpdateVolumeBody } from "./volume.dto";
import { getVolumePath } from "./helpers"; import { getVolumePath } from "./helpers";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { serverEvents } from "../../core/events"; import { serverEvents } from "../../core/events";
import { volumeConfigSchema, type BackendConfig } from "~/schemas/volumes"; import { volumeConfigSchema, type BackendConfig } from "~/schemas/volumes";
import { getOrganizationId } from "~/server/core/request-context"; import { getOrganizationId } from "~/server/core/request-context";

View file

@ -1,6 +1,6 @@
import { definePlugin } from "nitro"; import { definePlugin } from "nitro";
import { bootstrapApplication } from "../modules/lifecycle/bootstrap"; import { bootstrapApplication } from "../modules/lifecycle/bootstrap";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "../utils/errors"; import { toMessage } from "../utils/errors";
export default definePlugin(async () => { export default definePlugin(async () => {

View file

@ -1,5 +1,5 @@
import { describe, expect, test } from "bun:test"; import { describe, expect, test } from "bun:test";
import { safeExec, safeSpawn } from "@zerobyte/core/utils"; import { safeExec, safeSpawn } from "@zerobyte/core/node";
describe("safeExec", () => { describe("safeExec", () => {
describe("successful commands", () => { describe("successful commands", () => {

View file

@ -1,5 +1,5 @@
import { HttpError } from "http-errors-enhanced"; import { HttpError } from "http-errors-enhanced";
import { sanitizeSensitiveData } from "@zerobyte/core/utils"; import { sanitizeSensitiveData } from "@zerobyte/core/node";
export const handleServiceError = (error: unknown) => { export const handleServiceError = (error: unknown) => {
if (error instanceof HttpError) { if (error instanceof HttpError) {

View file

@ -1,6 +1,6 @@
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "./errors"; import { toMessage } from "./errors";
import { safeExec } from "@zerobyte/core/utils"; import { safeExec } from "@zerobyte/core/node";
/** /**
* List all configured rclone remotes * List all configured rclone remotes

View file

@ -1,5 +1,5 @@
import { safeExec } from "@zerobyte/core/utils"; import { safeExec } from "@zerobyte/core/node";
import { logger } from "@zerobyte/core/utils"; import { logger } from "@zerobyte/core/node";
import { toMessage } from "./errors"; import { toMessage } from "./errors";
export interface SendNotificationParams { export interface SendNotificationParams {

View file

@ -4,9 +4,9 @@ import path from "node:path";
import { cwd } from "node:process"; import { cwd } from "node:process";
import { db } from "~/server/db/db"; import { db } from "~/server/db/db";
import * as utils from "@zerobyte/core/utils"; import * as utils from "@zerobyte/core/node";
void mock.module("@zerobyte/core/utils", () => { void mock.module("@zerobyte/core/node", () => {
return { return {
...utils, ...utils,
logger: { logger: {

View file

@ -8,10 +8,20 @@
"import": "./src/restic/index.ts", "import": "./src/restic/index.ts",
"default": "./src/restic/index.ts" "default": "./src/restic/index.ts"
}, },
"./restic/server": {
"types": "./src/restic/server.ts",
"import": "./src/restic/server.ts",
"default": "./src/restic/server.ts"
},
"./utils": { "./utils": {
"types": "./src/utils/index.ts", "types": "./src/utils/index.ts",
"import": "./src/utils/index.ts", "import": "./src/utils/index.ts",
"default": "./src/utils/index.ts" "default": "./src/utils/index.ts"
},
"./node": {
"types": "./src/node/index.ts",
"import": "./src/node/index.ts",
"default": "./src/node/index.ts"
} }
}, },
"scripts": { "scripts": {

View file

@ -0,0 +1,4 @@
export { safeSpawn, safeExec } from "../utils/spawn.js";
export type { SafeSpawnParams, SafeSpawnParamsLines, SafeSpawnParamsRaw, SpawnResult } from "../utils/spawn.js";
export { logger } from "../utils/logger.js";
export { sanitizeSensitiveData } from "../utils/sanitize.js";

View file

@ -10,7 +10,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import { validateCustomResticParams } from "../helpers/validate-custom-params"; import { validateCustomResticParams } from "../helpers/validate-custom-params";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { logger, safeSpawn } from "../../utils"; import { logger, safeSpawn } from "../../node";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";
export const backup = async ( export const backup = async (

View file

@ -1,4 +1,4 @@
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { addCommonArgs } from "../helpers/add-common-args"; import { addCommonArgs } from "../helpers/add-common-args";
import { buildEnv } from "../helpers/build-env"; import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";

View file

@ -5,7 +5,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";
export const copy = async ( export const copy = async (

View file

@ -1,4 +1,4 @@
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { addCommonArgs } from "../helpers/add-common-args"; import { addCommonArgs } from "../helpers/add-common-args";
import { buildEnv } from "../helpers/build-env"; import { buildEnv } from "../helpers/build-env";

View file

@ -6,7 +6,7 @@ import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger, safeSpawn } from "../../utils"; import { logger, safeSpawn } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
const normalizeDumpPath = (pathToDump?: string): string => { const normalizeDumpPath = (pathToDump?: string): string => {

View file

@ -5,7 +5,7 @@ import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
export const forget = async ( export const forget = async (

View file

@ -4,7 +4,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import { keyAdd } from "./key-add"; import { keyAdd } from "./key-add";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";
const addDefaultKey = async ( const addDefaultKey = async (

View file

@ -1,4 +1,4 @@
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { addCommonArgs } from "../helpers/add-common-args"; import { addCommonArgs } from "../helpers/add-common-args";
import { buildEnv } from "../helpers/build-env"; import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";

View file

@ -4,7 +4,7 @@ import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger, safeSpawn } from "../../utils"; import { logger, safeSpawn } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";

View file

@ -1,4 +1,4 @@
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { addCommonArgs } from "../helpers/add-common-args"; import { addCommonArgs } from "../helpers/add-common-args";
import { buildEnv } from "../helpers/build-env"; import { buildEnv } from "../helpers/build-env";

View file

@ -7,7 +7,7 @@ import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import { type RepositoryConfig, type OverwriteMode } from "../schemas"; import { type RepositoryConfig, type OverwriteMode } from "../schemas";
import { logger, safeSpawn } from "../../utils"; import { logger, safeSpawn } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { resticRestoreOutputSchema, type ResticRestoreOutputDto } from "../restic-dto"; import { resticRestoreOutputSchema, type ResticRestoreOutputDto } from "../restic-dto";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";

View file

@ -5,7 +5,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import { resticSnapshotSummarySchema } from "../restic-dto"; import { resticSnapshotSummarySchema } from "../restic-dto";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";
const snapshotInfoSchema = z.object({ const snapshotInfoSchema = z.object({

View file

@ -4,7 +4,7 @@ import { buildEnv } from "../helpers/build-env";
import { buildRepoUrl } from "../helpers/build-repo-url"; import { buildRepoUrl } from "../helpers/build-repo-url";
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys"; import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { resticStatsSchema } from "../restic-dto"; import { resticStatsSchema } from "../restic-dto";
import type { ResticDeps } from "../types"; import type { ResticDeps } from "../types";

View file

@ -1,4 +1,4 @@
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { addCommonArgs } from "../helpers/add-common-args"; import { addCommonArgs } from "../helpers/add-common-args";
import { buildEnv } from "../helpers/build-env"; import { buildEnv } from "../helpers/build-env";

View file

@ -1,4 +1,4 @@
import { logger, safeExec } from "../../utils"; import { logger, safeExec } from "../../node";
import { ResticError } from "../error"; import { ResticError } from "../error";
import { addCommonArgs } from "../helpers/add-common-args"; import { addCommonArgs } from "../helpers/add-common-args";
import { buildEnv } from "../helpers/build-env"; import { buildEnv } from "../helpers/build-env";

View file

@ -3,7 +3,7 @@ import fs from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import type { ResticDeps, ResticEnv } from "../types"; import type { ResticDeps, ResticEnv } from "../types";
import type { RepositoryConfig } from "../schemas"; import type { RepositoryConfig } from "../schemas";
import { logger } from "../../utils"; import { logger } from "../../node";
export const buildEnv = async ( export const buildEnv = async (
config: RepositoryConfig, config: RepositoryConfig,

View file

@ -1,29 +1,6 @@
import { backup } from "./commands/backup";
import { check } from "./commands/check";
import { copy } from "./commands/copy";
import { deleteSnapshot, deleteSnapshots } from "./commands/delete-snapshots";
import { dump } from "./commands/dump";
import { forget } from "./commands/forget";
import { init } from "./commands/init";
import { keyAdd } from "./commands/key-add";
import { ls } from "./commands/ls";
import { repairIndex } from "./commands/repair-index";
import { restore } from "./commands/restore";
import { snapshots } from "./commands/snapshots";
import { stats } from "./commands/stats";
import { tagSnapshots } from "./commands/tag-snapshots";
import { unlock } from "./commands/unlock";
import type { ResticDeps } from "./types";
export { addCommonArgs } from "./helpers/add-common-args";
export { buildEnv } from "./helpers/build-env";
export { buildRepoUrl } from "./helpers/build-repo-url";
export { cleanupTemporaryKeys } from "./helpers/cleanup-temporary-keys";
export { validateCustomResticParams } from "./helpers/validate-custom-params";
export { ResticError } from "./error";
export * from "./schemas"; export * from "./schemas";
export * from "./restic-dto"; export * from "./restic-dto";
export { ResticError } from "./error";
export type { RestoreProgress } from "./commands/restore"; export type { RestoreProgress } from "./commands/restore";
export type { export type {
@ -36,73 +13,3 @@ export type {
ResticForgetResponse, ResticForgetResponse,
Snapshot, Snapshot,
} from "./types"; } from "./types";
export const createRestic = (deps: ResticDeps) => ({
init: (
config: Parameters<typeof init>[0],
organizationId: Parameters<typeof init>[1],
options?: { timeoutMs?: number },
) => init(config, organizationId, options, deps),
keyAdd: (
config: Parameters<typeof keyAdd>[0],
organizationId: Parameters<typeof keyAdd>[1],
options: Parameters<typeof keyAdd>[2],
) => keyAdd(config, organizationId, options, deps),
backup: (
config: Parameters<typeof backup>[0],
source: Parameters<typeof backup>[1],
options: Parameters<typeof backup>[2],
) => backup(config, source, options, deps),
restore: (
config: Parameters<typeof restore>[0],
snapshotId: Parameters<typeof restore>[1],
target: Parameters<typeof restore>[2],
options: Parameters<typeof restore>[3],
) => restore(config, snapshotId, target, options, deps),
dump: (
config: Parameters<typeof dump>[0],
snapshotRef: Parameters<typeof dump>[1],
options: Parameters<typeof dump>[2],
) => dump(config, snapshotRef, options, deps),
snapshots: (config: Parameters<typeof snapshots>[0], options: Parameters<typeof snapshots>[1]) =>
snapshots(config, options, deps),
stats: (config: Parameters<typeof stats>[0], options: Parameters<typeof stats>[1]) => stats(config, options, deps),
forget: (
config: Parameters<typeof forget>[0],
options: Parameters<typeof forget>[1],
extra: Parameters<typeof forget>[2],
) => forget(config, options, extra, deps),
deleteSnapshot: (
config: Parameters<typeof deleteSnapshot>[0],
snapshotId: Parameters<typeof deleteSnapshot>[1],
organizationId: Parameters<typeof deleteSnapshot>[2],
) => deleteSnapshot(config, snapshotId, organizationId, deps),
deleteSnapshots: (
config: Parameters<typeof deleteSnapshots>[0],
snapshotIds: Parameters<typeof deleteSnapshots>[1],
organizationId: Parameters<typeof deleteSnapshots>[2],
) => deleteSnapshots(config, snapshotIds, organizationId, deps),
tagSnapshots: (
config: Parameters<typeof tagSnapshots>[0],
snapshotIds: Parameters<typeof tagSnapshots>[1],
tags: Parameters<typeof tagSnapshots>[2],
organizationId: Parameters<typeof tagSnapshots>[3],
) => tagSnapshots(config, snapshotIds, tags, organizationId, deps),
unlock: (config: Parameters<typeof unlock>[0], options: Parameters<typeof unlock>[1]) =>
unlock(config, options, deps),
ls: (
config: Parameters<typeof ls>[0],
snapshotId: Parameters<typeof ls>[1],
organizationId: Parameters<typeof ls>[2],
path?: Parameters<typeof ls>[3],
options?: Parameters<typeof ls>[4],
) => ls(config, snapshotId, organizationId, path, options, deps),
check: (config: Parameters<typeof check>[0], options: Parameters<typeof check>[1]) => check(config, options, deps),
repairIndex: (config: Parameters<typeof repairIndex>[0], options: Parameters<typeof repairIndex>[1]) =>
repairIndex(config, options, deps),
copy: (
sourceConfig: Parameters<typeof copy>[0],
destConfig: Parameters<typeof copy>[1],
options: Parameters<typeof copy>[2],
) => copy(sourceConfig, destConfig, options, deps),
});

View file

@ -0,0 +1,54 @@
import { backup } from "./commands/backup";
import { check } from "./commands/check";
import { copy } from "./commands/copy";
import { deleteSnapshot, deleteSnapshots } from "./commands/delete-snapshots";
import { dump } from "./commands/dump";
import { forget } from "./commands/forget";
import { init } from "./commands/init";
import { keyAdd } from "./commands/key-add";
import { ls } from "./commands/ls";
import { repairIndex } from "./commands/repair-index";
import { restore } from "./commands/restore";
import { snapshots } from "./commands/snapshots";
import { stats } from "./commands/stats";
import { tagSnapshots } from "./commands/tag-snapshots";
import { unlock } from "./commands/unlock";
import type { ResticDeps } from "./types";
export { addCommonArgs } from "./helpers/add-common-args";
export { buildEnv } from "./helpers/build-env";
export { buildRepoUrl } from "./helpers/build-repo-url";
export { cleanupTemporaryKeys } from "./helpers/cleanup-temporary-keys";
export { validateCustomResticParams } from "./helpers/validate-custom-params";
export { ResticError } from "./error";
function withDeps<Args extends unknown[], Result>(
command: (...args: [...Args, ResticDeps]) => Result,
deps: ResticDeps,
): (...args: Args) => Result;
function withDeps<Args extends unknown[], Result>(
command: (...args: [...Args, ResticDeps?]) => Result,
deps: ResticDeps,
): (...args: Args) => Result;
function withDeps(command: (...args: any[]) => any, deps: ResticDeps) {
return (...args: any[]) => command(...args, deps);
}
export const createRestic = (deps: ResticDeps) => ({
init: withDeps(init, deps),
keyAdd: withDeps(keyAdd, deps),
backup: withDeps(backup, deps),
restore: withDeps(restore, deps),
dump: withDeps(dump, deps),
snapshots: withDeps(snapshots, deps),
stats: withDeps(stats, deps),
forget: withDeps(forget, deps),
deleteSnapshot: withDeps(deleteSnapshot, deps),
deleteSnapshots: withDeps(deleteSnapshots, deps),
tagSnapshots: withDeps(tagSnapshots, deps),
unlock: withDeps(unlock, deps),
ls: withDeps(ls, deps),
check: withDeps(check, deps),
repairIndex: withDeps(repairIndex, deps),
copy: withDeps(copy, deps),
});

View file

@ -1,6 +1,3 @@
export { safeSpawn, safeExec } from "./spawn.js";
export { logger } from "./logger.js";
export { sanitizeSensitiveData } from "./sanitize.js";
export { safeJsonParse } from "./json.js"; export { safeJsonParse } from "./json.js";
export { normalizeAbsolutePath } from "./path.js"; export { normalizeAbsolutePath } from "./path.js";
export { findCommonAncestor } from "./common-ancestor.js"; export { findCommonAncestor } from "./common-ancestor.js";