refactor: split server utils
This commit is contained in:
parent
a458252742
commit
9be16a2172
71 changed files with 147 additions and 172 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { shutdown } from "./server/modules/lifecycle/shutdown";
|
||||
import { runCLI } from "./server/cli";
|
||||
import { createStartHandler, defaultStreamHandler, defineHandlerCallback } from "@tanstack/react-start/server";
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import { backupScheduleController } from "./modules/backups/backups.controller";
|
|||
import { eventsController } from "./modules/events/events.controller";
|
||||
import { notificationsController } from "./modules/notifications/notifications.controller";
|
||||
import { handleServiceError } from "./utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { config } from "./core/config";
|
||||
import { auth } from "~/server/lib/auth";
|
||||
import { db } from "./db/db";
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
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";
|
||||
|
||||
const flushMicrotasks = async () => {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as fs from "node:fs/promises";
|
||||
import { RCLONE_CONFIG_DIR } from "./constants";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
|
||||
export type SystemCapabilities = {
|
||||
rclone: boolean;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
|
||||
export type LockType = "shared" | "exclusive";
|
||||
|
||||
|
|
|
|||
|
|
@ -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 { config } from "./config";
|
||||
import { cryptoUtils } from "../utils/crypto";
|
||||
import { db } from "../db/db";
|
||||
|
||||
|
|
@ -24,6 +26,7 @@ export const resticDeps: ResticDeps = {
|
|||
resticCacheDir: RESTIC_CACHE_DIR,
|
||||
resticPassFile: RESTIC_PASS_FILE,
|
||||
defaultExcludes: DEFAULT_EXCLUDES,
|
||||
hostname: config.resticHostname,
|
||||
};
|
||||
|
||||
export const restic = createRestic(resticDeps);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import CronExpressionParser from "cron-parser";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
|
||||
export abstract class Job {
|
||||
abstract run(): Promise<unknown>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Job } from "../core/scheduler";
|
||||
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 { withContext } from "../core/request-context";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Job } from "../core/scheduler";
|
||||
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 { withContext } from "../core/request-context";
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import fs from "node:fs/promises";
|
|||
import { volumeService } from "../modules/volumes/volume.service";
|
||||
import { readMountInfo } from "../utils/mountinfo";
|
||||
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 { toMessage } from "../utils/errors";
|
||||
import { VOLUME_MOUNT_BASE } from "../core/constants";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Job } from "../core/scheduler";
|
||||
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 { withContext } from "../core/request-context";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Job } from "../core/scheduler";
|
||||
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 { withContext } from "../core/request-context";
|
||||
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import { createAuthMiddleware } from "better-auth/api";
|
|||
import { config } from "../core/config";
|
||||
import { db } from "../db/db";
|
||||
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 { tanstackStartCookies } from "better-auth/tanstack-start";
|
||||
import { isValidUsername, normalizeUsername } from "~/lib/username";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { UnauthorizedError } from "http-errors-enhanced";
|
|||
import { db } from "~/server/db/db";
|
||||
import { member, organization, type User } from "~/server/db/schema";
|
||||
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) {
|
||||
const membership = await db.query.member.findFirst({
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { db } from "~/server/db/db";
|
||||
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 { REGISTRATION_ENABLED_KEY } from "~/server/core/constants";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import * as fs from "node:fs/promises";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import type { VolumeBackend } from "../backend";
|
||||
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
|
||||
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as os from "node:os";
|
|||
import { BACKEND_STATUS, type BackendConfig } from "~/schemas/volumes";
|
||||
import { OPERATION_TIMEOUT } from "../../../core/constants";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { getMountForPath } from "../../../utils/mountinfo";
|
||||
import { withTimeout } from "../../../utils/timeout";
|
||||
import type { VolumeBackend } from "../backend";
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ import * as fs from "node:fs/promises";
|
|||
import * as os from "node:os";
|
||||
import { OPERATION_TIMEOUT } from "../../../core/constants";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { getMountForPath } from "../../../utils/mountinfo";
|
||||
import { withTimeout } from "../../../utils/timeout";
|
||||
import type { VolumeBackend } from "../backend";
|
||||
import { executeUnmount } from "../utils/backend-utils";
|
||||
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";
|
||||
|
||||
const mount = async (config: BackendConfig, path: string) => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { spawn } from "node:child_process";
|
|||
import { OPERATION_TIMEOUT } from "../../../core/constants";
|
||||
import { cryptoUtils } from "../../../utils/crypto";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { getMountForPath } from "../../../utils/mountinfo";
|
||||
import { withTimeout } from "../../../utils/timeout";
|
||||
import type { VolumeBackend } from "../backend";
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as os from "node:os";
|
|||
import { OPERATION_TIMEOUT } from "../../../core/constants";
|
||||
import { cryptoUtils } from "../../../utils/crypto";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { getMountForPath } from "../../../utils/mountinfo";
|
||||
import { withTimeout } from "../../../utils/timeout";
|
||||
import type { VolumeBackend } from "../backend";
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import * as fs from "node:fs/promises";
|
||||
import * as npath from "node:path";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { safeExec } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { safeExec } from "@zerobyte/core/node";
|
||||
|
||||
export const executeMount = async (args: string[]): Promise<void> => {
|
||||
const shouldBeVerbose = process.env.LOG_LEVEL === "debug" || process.env.NODE_ENV !== "production";
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import * as os from "node:os";
|
|||
import { OPERATION_TIMEOUT } from "../../../core/constants";
|
||||
import { cryptoUtils } from "../../../utils/crypto";
|
||||
import { toMessage } from "../../../utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { getMountForPath } from "../../../utils/mountinfo";
|
||||
import { withTimeout } from "../../../utils/timeout";
|
||||
import type { VolumeBackend } from "../backend";
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import { createTestBackupScheduleMirror } from "~/test/helpers/backup-mirror";
|
|||
import { generateBackupOutput } from "~/test/helpers/restic";
|
||||
import { TEST_ORG_ID } from "~/test/helpers/organization";
|
||||
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 { NotFoundError, BadRequestError } from "http-errors-enhanced";
|
||||
import { scheduleQueries } from "../backups.queries";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { createTestBackupSchedule } from "~/test/helpers/backup";
|
|||
import { createTestRepository } from "~/test/helpers/repository";
|
||||
import { generateBackupOutput } from "~/test/helpers/restic";
|
||||
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 { backupScheduleMirrorsTable, repositoriesTable, volumesTable } from "~/server/db/schema";
|
||||
import { TEST_ORG_ID } from "~/test/helpers/organization";
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import CronExpressionParser from "cron-parser";
|
|||
import path from "node:path";
|
||||
import type { BackupSchedule } from "~/server/db/schema";
|
||||
import { toMessage } from "~/server/utils/errors";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
|
||||
export const calculateNextRun = (cronExpression: string) => {
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ import {
|
|||
import { notificationsService } from "../notifications/notifications.service";
|
||||
import { requireAuth } from "../auth/auth.middleware";
|
||||
import { backupsExecutionService } from "./backups.execution";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { asShortId } from "~/server/utils/branded";
|
||||
|
||||
export const backupScheduleController = new Hono()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { NotFoundError, BadRequestError, ConflictError } from "http-errors-enhanced";
|
||||
import type { BackupSchedule, Volume, Repository } from "../../db/schema";
|
||||
import { restic } from "../../core/restic";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { cache, cacheKeys } from "../../utils/cache";
|
||||
import { getVolumePath } from "../volumes/helpers";
|
||||
import { toMessage } from "../../utils/errors";
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ import { generateShortId } from "~/server/utils/id";
|
|||
import { getOrganizationId } from "~/server/core/request-context";
|
||||
import { calculateNextRun } from "./backup.helpers";
|
||||
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 organizationId = getOrganizationId();
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Hono } from "hono";
|
||||
import { streamSSE } from "hono/streaming";
|
||||
import { serverEvents } from "../../core/events";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { requireAuth } from "../auth/auth.middleware";
|
||||
import type { ServerEventPayloadMap } from "~/schemas/server-events";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { v00001 } from "./migrations/00001-retag-snapshots";
|
||||
import { v00002 } from "./migrations/00002-isolate-restic-passwords";
|
||||
import { v00003 } from "./migrations/00003-assign-organization";
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../../db/db";
|
||||
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 { safeExec } from "@zerobyte/core/utils";
|
||||
import { addCommonArgs, buildEnv, buildRepoUrl, cleanupTemporaryKeys } from "@zerobyte/core/restic";
|
||||
import { safeExec } from "@zerobyte/core/node";
|
||||
import { addCommonArgs, buildEnv, buildRepoUrl, cleanupTemporaryKeys } from "@zerobyte/core/restic/server";
|
||||
import { resticDeps } from "~/server/core/restic";
|
||||
|
||||
const migrateTag = async (
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ import {
|
|||
notificationDestinationsTable,
|
||||
twoFactor,
|
||||
} from "../../../db/schema";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { toMessage } from "~/server/utils/errors";
|
||||
import { cryptoUtils } from "~/server/utils/crypto";
|
||||
import type { RepositoryConfig } from "@zerobyte/core/restic";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { db } from "../../../db/db";
|
||||
import { member } from "../../../db/schema";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { toMessage } from "~/server/utils/errors";
|
||||
|
||||
const execute = async () => {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { and, eq } from "drizzle-orm";
|
||||
import { db } from "../../../db/db";
|
||||
import { repositoriesTable } from "../../../db/schema";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { toMessage } from "~/server/utils/errors";
|
||||
import { REPOSITORY_BASE } from "~/server/core/constants";
|
||||
import { repositoryConfigSchema } from "@zerobyte/core/restic";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { Scheduler } from "../../core/scheduler";
|
||||
import { db } from "../../db/db";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { createVolumeBackend } from "../backends/backend";
|
||||
|
||||
export const shutdown = async () => {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { Scheduler } from "../../core/scheduler";
|
|||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../../db/db";
|
||||
import { backupSchedulesTable } from "../../db/schema";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { volumeService } from "../volumes/volume.service";
|
||||
import { CleanupDanglingMountsJob } from "../../jobs/cleanup-dangling";
|
||||
import { VolumeHealthCheckJob } from "../../jobs/healthchecks";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import {
|
|||
type NotificationDestination,
|
||||
} from "../../db/schema";
|
||||
import { cryptoUtils } from "../../utils/crypto";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { sendNotification } from "../../utils/shoutrrr";
|
||||
import { formatDuration } from "~/utils/utils";
|
||||
import { buildShoutrrrUrl } from "./builders";
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import { restic } from "~/server/core/restic";
|
|||
import { createTestSession } from "~/test/helpers/auth";
|
||||
import { createTestBackupSchedule } from "~/test/helpers/backup";
|
||||
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";
|
||||
|
||||
const createTestRepository = async (organizationId: string) => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { getOrganizationId } from "~/server/core/request-context";
|
|||
import { restic } from "~/server/core/restic";
|
||||
import { toMessage } from "~/server/utils/errors";
|
||||
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 { repositoriesTable } from "~/server/db/schema";
|
||||
import { repoMutex } from "~/server/core/repository-mutex";
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ import {
|
|||
import { config as appConfig } from "~/server/core/config";
|
||||
import { serverEvents } from "~/server/core/events";
|
||||
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 { repoMutex } from "../../core/repository-mutex";
|
||||
import { db } from "../../db/db";
|
||||
|
|
@ -21,9 +21,9 @@ import { cache, cacheKeys } from "../../utils/cache";
|
|||
import { cryptoUtils } from "../../utils/crypto";
|
||||
import { toMessage } from "../../utils/errors";
|
||||
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 { safeSpawn } from "@zerobyte/core/utils";
|
||||
import { safeSpawn } from "@zerobyte/core/node";
|
||||
import { backupsService } from "../backups/backups.service";
|
||||
import type { DumpPathKind, UpdateRepositoryBody } from "./repositories.dto";
|
||||
import { findCommonAncestor } from "@zerobyte/core/utils";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { APIError } from "better-auth/api";
|
||||
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 { ssoService } from "~/server/modules/sso/sso.service";
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { requireSsoInvitation } from "./middlewares/require-invitation";
|
|||
import { resolveTrustedProvidersForRequest } from "./middlewares/trust-provider-for-linking";
|
||||
import { isSsoCallbackRequest, extractProviderIdFromContext, normalizeEmail } from "./utils/sso-context";
|
||||
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) {
|
||||
const user = await db.query.usersTable.findFirst({ where: { id: userId } });
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import { config } from "../../core/config";
|
|||
import type { UpdateInfoDto } from "./system.dto";
|
||||
import semver from "semver";
|
||||
import { cache, cacheKeys } from "../../utils/cache";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { db } from "../../db/db";
|
||||
import { appMetadataTable } from "../../db/schema";
|
||||
import { REGISTRATION_ENABLED_KEY } from "~/server/core/constants";
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import { withTimeout } from "../../utils/timeout";
|
|||
import { createVolumeBackend } from "../backends/backend";
|
||||
import type { UpdateVolumeBody } from "./volume.dto";
|
||||
import { getVolumePath } from "./helpers";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { serverEvents } from "../../core/events";
|
||||
import { volumeConfigSchema, type BackendConfig } from "~/schemas/volumes";
|
||||
import { getOrganizationId } from "~/server/core/request-context";
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { definePlugin } from "nitro";
|
||||
import { bootstrapApplication } from "../modules/lifecycle/bootstrap";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { toMessage } from "../utils/errors";
|
||||
|
||||
export default definePlugin(async () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { describe, expect, test } from "bun:test";
|
||||
import { safeExec, safeSpawn } from "@zerobyte/core/utils";
|
||||
import { safeExec, safeSpawn } from "@zerobyte/core/node";
|
||||
|
||||
describe("safeExec", () => {
|
||||
describe("successful commands", () => {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { HttpError } from "http-errors-enhanced";
|
||||
import { sanitizeSensitiveData } from "@zerobyte/core/utils";
|
||||
import { sanitizeSensitiveData } from "@zerobyte/core/node";
|
||||
|
||||
export const handleServiceError = (error: unknown) => {
|
||||
if (error instanceof HttpError) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { logger } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { toMessage } from "./errors";
|
||||
import { safeExec } from "@zerobyte/core/utils";
|
||||
import { safeExec } from "@zerobyte/core/node";
|
||||
|
||||
/**
|
||||
* List all configured rclone remotes
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { safeExec } from "@zerobyte/core/utils";
|
||||
import { logger } from "@zerobyte/core/utils";
|
||||
import { safeExec } from "@zerobyte/core/node";
|
||||
import { logger } from "@zerobyte/core/node";
|
||||
import { toMessage } from "./errors";
|
||||
|
||||
export interface SendNotificationParams {
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ import path from "node:path";
|
|||
import { cwd } from "node:process";
|
||||
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 {
|
||||
...utils,
|
||||
logger: {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,20 @@
|
|||
"import": "./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": {
|
||||
"types": "./src/utils/index.ts",
|
||||
"import": "./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": {
|
||||
|
|
|
|||
4
packages/core/src/node/index.ts
Normal file
4
packages/core/src/node/index.ts
Normal 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";
|
||||
|
|
@ -10,7 +10,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
|
|||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import { validateCustomResticParams } from "../helpers/validate-custom-params";
|
||||
import { ResticError } from "../error";
|
||||
import { logger, safeSpawn } from "../../utils";
|
||||
import { logger, safeSpawn } from "../../node";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
||||
export const backup = async (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { addCommonArgs } from "../helpers/add-common-args";
|
||||
import { buildEnv } from "../helpers/build-env";
|
||||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
|
|||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { ResticError } from "../error";
|
||||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
||||
export const copy = async (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import { addCommonArgs } from "../helpers/add-common-args";
|
||||
import { buildEnv } from "../helpers/build-env";
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ import { buildEnv } from "../helpers/build-env";
|
|||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger, safeSpawn } from "../../utils";
|
||||
import { logger, safeSpawn } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
|
||||
const normalizeDumpPath = (pathToDump?: string): string => {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { buildEnv } from "../helpers/build-env";
|
|||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
|
||||
export const forget = async (
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
|
|||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import { keyAdd } from "./key-add";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
||||
const addDefaultKey = async (
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { addCommonArgs } from "../helpers/add-common-args";
|
||||
import { buildEnv } from "../helpers/build-env";
|
||||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { buildEnv } from "../helpers/build-env";
|
|||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger, safeSpawn } from "../../utils";
|
||||
import { logger, safeSpawn } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import { addCommonArgs } from "../helpers/add-common-args";
|
||||
import { buildEnv } from "../helpers/build-env";
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import { buildEnv } from "../helpers/build-env";
|
|||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import { type RepositoryConfig, type OverwriteMode } from "../schemas";
|
||||
import { logger, safeSpawn } from "../../utils";
|
||||
import { logger, safeSpawn } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import { resticRestoreOutputSchema, type ResticRestoreOutputDto } from "../restic-dto";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { buildRepoUrl } from "../helpers/build-repo-url";
|
|||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import { resticSnapshotSummarySchema } from "../restic-dto";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
||||
const snapshotInfoSchema = z.object({
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import { buildEnv } from "../helpers/build-env";
|
|||
import { buildRepoUrl } from "../helpers/build-repo-url";
|
||||
import { cleanupTemporaryKeys } from "../helpers/cleanup-temporary-keys";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import { resticStatsSchema } from "../restic-dto";
|
||||
import type { ResticDeps } from "../types";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import { addCommonArgs } from "../helpers/add-common-args";
|
||||
import { buildEnv } from "../helpers/build-env";
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { logger, safeExec } from "../../utils";
|
||||
import { logger, safeExec } from "../../node";
|
||||
import { ResticError } from "../error";
|
||||
import { addCommonArgs } from "../helpers/add-common-args";
|
||||
import { buildEnv } from "../helpers/build-env";
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ import fs from "node:fs/promises";
|
|||
import path from "node:path";
|
||||
import type { ResticDeps, ResticEnv } from "../types";
|
||||
import type { RepositoryConfig } from "../schemas";
|
||||
import { logger } from "../../utils";
|
||||
import { logger } from "../../node";
|
||||
|
||||
export const buildEnv = async (
|
||||
config: RepositoryConfig,
|
||||
|
|
|
|||
|
|
@ -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 "./restic-dto";
|
||||
export { ResticError } from "./error";
|
||||
|
||||
export type { RestoreProgress } from "./commands/restore";
|
||||
export type {
|
||||
|
|
@ -36,73 +13,3 @@ export type {
|
|||
ResticForgetResponse,
|
||||
Snapshot,
|
||||
} 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),
|
||||
});
|
||||
|
|
|
|||
54
packages/core/src/restic/server.ts
Normal file
54
packages/core/src/restic/server.ts
Normal 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),
|
||||
});
|
||||
|
|
@ -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 { normalizeAbsolutePath } from "./path.js";
|
||||
export { findCommonAncestor } from "./common-ancestor.js";
|
||||
|
|
|
|||
Loading…
Reference in a new issue