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.`
);
}
}