Complete TASK-017 simplified EMOM and per-side entry

This commit is contained in:
rob
2026-11-07 15:29:12 +00:00
parent 9c0e82037f
commit 922d1f6bd7
30 changed files with 646 additions and 236 deletions
+3 -3
View File
@@ -15,7 +15,7 @@ export function parseBackup(input) {
let backup
try { backup = typeof input === 'string' ? JSON.parse(input) : structuredClone(input) }
catch { throw new Error('Invalid backup JSON.') }
if (backup?.format !== 'workout-tracker' || ![1, 2].includes(backup.version) || !backup.stores || typeof backup.stores !== 'object' || Array.isArray(backup.stores)) throw new Error('Unsupported backup schema.')
if (backup?.format !== 'workout-tracker' || ![1, 2, 3].includes(backup.version) || !backup.stores || typeof backup.stores !== 'object' || Array.isArray(backup.stores)) throw new Error('Unsupported backup schema.')
if (Object.keys(backup.stores).some((store) => !stores.includes(store))) throw new Error('Unsupported backup store.')
// Version 1 is the legacy adapter envelope with the two original stores.
for (const store of stores) {
@@ -26,7 +26,7 @@ export function parseBackup(input) {
if (!entry || typeof entry.key !== 'string' || keys.has(entry.key) || !validJSON(entry.value)) throw new Error('Invalid or duplicate backup entry.')
keys.add(entry.key)
if (store === 'strengthEntries' && (!/^\d{4}-\d{2}-\d{2}:.+/.test(entry.key) || !validEntry(entry.value))) throw new Error('Invalid legacy strength entry.')
if (store === 'performanceEntries' && (performanceError(entry.value) || entry.key !== performanceKey(entry.value.date, entry.value.period, entry.value.exerciseId))) throw new Error('Invalid detailed performance entry.')
if (store === 'performanceEntries' && (performanceError(entry.value) || entry.key !== performanceKey(entry.value.date, entry.value.period, entry.value.exerciseId, entry.value.format))) throw new Error('Invalid detailed performance entry.')
if (store === 'routineOverrides' && entry.key === 'dailyHangGoalSec' && (!Number.isSafeInteger(entry.value) || entry.value <= 0)) throw new Error('Invalid hanging goal.')
}
}
@@ -43,7 +43,7 @@ export async function exportBackup() {
if (cursor.result) { data[name].push({ key: cursor.result.key, value: cursor.result.value }); cursor.result.continue() }
}
}
tx.oncomplete = () => { db.close(); resolve(JSON.stringify({ format: 'workout-tracker', version: 2, reference: { exerciseDefinitions, initialRoutine }, stores: data })) }
tx.oncomplete = () => { db.close(); resolve(JSON.stringify({ format: 'workout-tracker', version: 3, reference: { exerciseDefinitions, initialRoutine }, stores: data })) }
tx.onerror = tx.onabort = () => { db.close(); reject(new Error('Could not export local data.')) }
})
}