Add automatic project snapshots
This commit is contained in:
@@ -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.`
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user