Make machine configuration authoritative and restore native checkpoints exactly
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import { fnv1a64 } from "./replay.mjs";
|
||||
import { DEFAULT_MACHINE } from "../workspace/machine-definitions.mjs";
|
||||
|
||||
export const OPFS_UI_STATE_SCHEMA = "linuxcnc-ui-temp-json.v1";
|
||||
export const OPFS_UI_STATE_TTL_MS = 7 * 24 * 60 * 60 * 1000;
|
||||
@@ -77,7 +78,7 @@ async function writeFile(project, name, value) {
|
||||
return { status: "verified", bytes: bytes.byteLength };
|
||||
}
|
||||
|
||||
export async function loadUiState({ contextId, key = "xyzac-trt", storage } = {}) {
|
||||
export async function loadUiState({ contextId, key = DEFAULT_MACHINE.id, storage } = {}) {
|
||||
const resolved = await handles(key, false, storage).catch((error) => ({ status: "blocked", code: "opfs_open_failed", reason: error?.name ?? "unknown" }));
|
||||
if (resolved.status === "blocked" && resolved.reason === "NotFoundError") return emptyResult(contextId, key);
|
||||
if (resolved.status !== "verified") return { schema: OPFS_UI_STATE_SCHEMA, ...resolved, context_id: contextId, key };
|
||||
@@ -92,7 +93,7 @@ export async function loadUiState({ contextId, key = "xyzac-trt", storage } = {}
|
||||
return { schema: OPFS_UI_STATE_SCHEMA, status: "verified", storage: "opfs", context_id: contextId, key, generation: selected.generation, state: selected.state, state_hash: selected.state_hash };
|
||||
}
|
||||
|
||||
export async function saveUiState({ contextId, key = "xyzac-trt", state, storage } = {}) {
|
||||
export async function saveUiState({ contextId, key = DEFAULT_MACHINE.id, state, storage } = {}) {
|
||||
if (!validObject(state) || !finiteTree(state)) return { schema: OPFS_UI_STATE_SCHEMA, status: "blocked", code: "opfs_ui_state_invalid", context_id: contextId, key };
|
||||
const resolved = await handles(key, true, storage).catch((error) => ({ status: "blocked", code: "opfs_open_failed", reason: error?.name ?? "unknown" }));
|
||||
if (resolved.status !== "verified") return { schema: OPFS_UI_STATE_SCHEMA, ...resolved, context_id: contextId, key };
|
||||
@@ -108,23 +109,23 @@ export async function saveUiState({ contextId, key = "xyzac-trt", state, storage
|
||||
return { schema: OPFS_UI_STATE_SCHEMA, status: "verified", storage: "opfs", context_id: contextId, key, generation, slot, state_hash: next.state_hash, bytes: written.bytes };
|
||||
}
|
||||
|
||||
export async function clearUiState({ contextId, key = "xyzac-trt", storage } = {}) {
|
||||
export async function clearUiState({ contextId, key = DEFAULT_MACHINE.id, storage } = {}) {
|
||||
const resolved = await handles(key, false, storage).catch((error) => ({ status: "blocked", code: "opfs_open_failed", reason: error?.name ?? "unknown" }));
|
||||
if (resolved.status !== "verified") return { schema: OPFS_UI_STATE_SCHEMA, ...resolved, context_id: contextId, key };
|
||||
for (const name of [...SLOT_NAMES, MANIFEST_NAME]) { try { await resolved.project.removeEntry(name); } catch {} }
|
||||
return { schema: OPFS_UI_STATE_SCHEMA, status: "verified", storage: "opfs", context_id: contextId, key, cleared: true };
|
||||
}
|
||||
|
||||
export async function savePowerOffCheckpoint({ contextId, checkpoint, key = "xyzac-trt", storage } = {}) {
|
||||
export async function savePowerOffCheckpoint({ contextId, checkpoint, key = DEFAULT_MACHINE.id, storage } = {}) {
|
||||
return saveUiState({ contextId, key: `${key}-power-off`, state: { kind: "power_off_checkpoint", checkpoint }, storage });
|
||||
}
|
||||
|
||||
export async function loadPowerOffCheckpoint({ contextId, key = "xyzac-trt", storage } = {}) {
|
||||
export async function loadPowerOffCheckpoint({ contextId, key = DEFAULT_MACHINE.id, storage } = {}) {
|
||||
const result = await loadUiState({ contextId, key: `${key}-power-off`, storage });
|
||||
if (result.status !== "verified" || result.state?.kind !== "power_off_checkpoint" || !result.state.checkpoint) return { ...result, checkpoint: null };
|
||||
return { ...result, checkpoint: result.state.checkpoint };
|
||||
}
|
||||
|
||||
export async function clearPowerOffCheckpoint({ contextId, key = "xyzac-trt", storage } = {}) {
|
||||
export async function clearPowerOffCheckpoint({ contextId, key = DEFAULT_MACHINE.id, storage } = {}) {
|
||||
return clearUiState({ contextId, key: `${key}-power-off`, storage });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user