forked from farhoodlabs/paperclip
fcbae62baf
Replace single retentionDays with a three-tier BackupRetentionPolicy: - Daily: keep all backups (presets: 3, 7, 14 days; default 7) - Weekly: keep one per calendar week (presets: 1, 2, 4 weeks; default 4) - Monthly: keep one per calendar month (presets: 1, 3, 6 months; default 1) Pruning sorts backups newest-first and applies each tier's cutoff, keeping only the newest entry per ISO week/month bucket. The Instance Settings General page now shows three preset selectors (no icon, matches existing page design). Remove Database icon import.
46 lines
2.1 KiB
TypeScript
46 lines
2.1 KiB
TypeScript
import { z } from "zod";
|
|
import { DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE } from "../types/feedback.js";
|
|
import {
|
|
DAILY_RETENTION_PRESETS,
|
|
WEEKLY_RETENTION_PRESETS,
|
|
MONTHLY_RETENTION_PRESETS,
|
|
DEFAULT_BACKUP_RETENTION,
|
|
} from "../types/instance.js";
|
|
import { feedbackDataSharingPreferenceSchema } from "./feedback.js";
|
|
|
|
function presetSchema<T extends readonly number[]>(presets: T, label: string) {
|
|
return z.number().refine(
|
|
(v): v is T[number] => (presets as readonly number[]).includes(v),
|
|
{ message: `${label} must be one of: ${presets.join(", ")}` },
|
|
);
|
|
}
|
|
|
|
export const backupRetentionPolicySchema = z.object({
|
|
dailyDays: presetSchema(DAILY_RETENTION_PRESETS, "dailyDays").default(DEFAULT_BACKUP_RETENTION.dailyDays),
|
|
weeklyWeeks: presetSchema(WEEKLY_RETENTION_PRESETS, "weeklyWeeks").default(DEFAULT_BACKUP_RETENTION.weeklyWeeks),
|
|
monthlyMonths: presetSchema(MONTHLY_RETENTION_PRESETS, "monthlyMonths").default(DEFAULT_BACKUP_RETENTION.monthlyMonths),
|
|
});
|
|
|
|
export const instanceGeneralSettingsSchema = z.object({
|
|
censorUsernameInLogs: z.boolean().default(false),
|
|
keyboardShortcuts: z.boolean().default(false),
|
|
feedbackDataSharingPreference: feedbackDataSharingPreferenceSchema.default(
|
|
DEFAULT_FEEDBACK_DATA_SHARING_PREFERENCE,
|
|
),
|
|
backupRetention: backupRetentionPolicySchema.default(DEFAULT_BACKUP_RETENTION),
|
|
}).strict();
|
|
|
|
export const patchInstanceGeneralSettingsSchema = instanceGeneralSettingsSchema.partial();
|
|
|
|
export const instanceExperimentalSettingsSchema = z.object({
|
|
enableIsolatedWorkspaces: z.boolean().default(false),
|
|
autoRestartDevServerWhenIdle: z.boolean().default(false),
|
|
}).strict();
|
|
|
|
export const patchInstanceExperimentalSettingsSchema = instanceExperimentalSettingsSchema.partial();
|
|
|
|
export type InstanceGeneralSettings = z.infer<typeof instanceGeneralSettingsSchema>;
|
|
export type PatchInstanceGeneralSettings = z.infer<typeof patchInstanceGeneralSettingsSchema>;
|
|
export type InstanceExperimentalSettings = z.infer<typeof instanceExperimentalSettingsSchema>;
|
|
export type PatchInstanceExperimentalSettings = z.infer<typeof patchInstanceExperimentalSettingsSchema>;
|