histoire
Version:
A fast story book powered by Vite
36 lines (35 loc) • 1.49 kB
JavaScript
/** Returns an empty detached snapshot for one new owner. */
export function initialSetupSnapshot() {
return { revision: 0, state: 'unverified', attempts: [], repairs: [] };
}
/** Copies public nested values so observers cannot mutate cached state. */
export function detachSetupSnapshot(value) {
return {
...value,
attempts: copySetupAttempts(value.attempts),
repairs: value.repairs.map(repair => ({
...repair,
...(repair.command ? { command: { executable: repair.command.executable, args: [...repair.command.args] } } : {}),
})),
};
}
/** Copies a bounded attempt list without repeating a renderer. */
export function copySetupAttempts(attempts) {
return attempts.slice(0, 4).map(copySetupAttempt);
}
/** Adds one deterministic source result while retaining the four-candidate bound. */
export function addSetupAttempt(attempts, attempt) {
const existing = attempts.findIndex(value => value.source === attempt.source);
if (existing >= 0)
attempts[existing] = copySetupAttempt(attempt);
else if (attempts.length < 4)
attempts.push(copySetupAttempt(attempt));
}
/** Copies nested private-safe diagnostic fields so later mutation cannot alter observations. */
function copySetupAttempt(attempt) {
return {
...attempt,
...(attempt.driver ? { driver: { ...attempt.driver } } : {}),
...(attempt.diagnostic ? { diagnostic: { ...attempt.diagnostic } } : {}),
};
}