Add automatic project snapshots

This commit is contained in:
2026-07-25 23:27:51 +02:00
parent 59d442593f
commit 1a77eedaa8
23 changed files with 2232 additions and 26 deletions
@@ -0,0 +1,37 @@
export const projectSnapshotKinds = ["named", "automatic"] as const;
export type ProjectSnapshotKind =
(typeof projectSnapshotKinds)[number];
export const automaticProjectSnapshotIntervalRevisions = 25;
export const automaticProjectSnapshotRetentionCount = 12;
export function shouldCaptureAutomaticProjectSnapshot(
currentRevision: number,
latestAutomaticRevision: number | null
) {
assertRevision(currentRevision, "Current");
if (latestAutomaticRevision !== null) {
assertRevision(latestAutomaticRevision, "Latest automatic");
if (latestAutomaticRevision > currentRevision) {
throw new Error(
"Latest automatic snapshot revision exceeds current revision."
);
}
}
if (currentRevision < automaticProjectSnapshotIntervalRevisions) {
return false;
}
return (
latestAutomaticRevision === null ||
currentRevision - latestAutomaticRevision >=
automaticProjectSnapshotIntervalRevisions
);
}
function assertRevision(value: number, label: string) {
if (!Number.isSafeInteger(value) || value < 0) {
throw new Error(
`${label} snapshot revision must be a non-negative integer.`
);
}
}
+4 -1
View File
@@ -1,8 +1,12 @@
import type { ProjectSnapshotKind } from "../models/project-snapshot-policy.model.js";
import type { ProjectStateRestoreCommand } from "../models/project-state-restore-command.model.js";
export interface ProjectSnapshotMetadata {
id: string;
projectId: string;
sourceRevision: number;
schemaVersion: number;
kind: ProjectSnapshotKind;
name: string;
description: string | null;
payloadSha256: string;
@@ -33,4 +37,3 @@ export interface ProjectSnapshotStore {
snapshotId: string
): PreparedProjectSnapshotRestore | null;
}
import type { ProjectStateRestoreCommand } from "../models/project-state-restore-command.model.js";