Added optionnal online storage and cross-client sync
All checks were successful
Tests et déploiement / validate (push) Successful in 2m44s
Tests et déploiement / deploy (push) Successful in 51s

This commit is contained in:
2026-10-10 16:01:06 +02:00
parent 277b9c887e
commit 5686ee5072
33 changed files with 2466 additions and 25 deletions

View File

@@ -49,6 +49,11 @@ import { DAY, HOUR, localDateKey } from './time.js';
* days: import('dexie').Table<DayRecord, string>,
* entries: import('dexie').Table<EntryRecord, number>,
* settings: import('dexie').Table<SettingsRecord, string>,
* syncState: import('dexie').Table<any, string>,
* syncObjects: import('dexie').Table<any, string>,
* syncVersions: import('dexie').Table<any, string>,
* syncOutbox: import('dexie').Table<any, string>,
* syncConflicts: import('dexie').Table<any, string>,
* }} TimeLogDB
*/
@@ -67,6 +72,38 @@ db.version(2).stores({
settings: 'key',
});
db.version(3).stores({
syncState: 'key', syncObjects: 'key', syncVersions: 'id, key',
syncOutbox: 'id', syncConflicts: 'key',
});
// Journal every local mutation in its native IndexedDB transaction, including
// direct writes by editing, automation, import and purge. The durable source
// rows + last captured values are the outbox until revisions are materialised.
db.use({
stack: 'dbcore', name: 'sync-dirty-journal',
create(core) {
return {
...core,
transaction(stores, mode, options) {
const names = mode === 'readwrite' && stores.some(s => ['days', 'entries', 'settings'].includes(s))
? [...new Set([...stores, 'syncState'])] : stores;
return core.transaction(names, mode, options);
},
table(name) {
const table = core.table(name);
if (!['days', 'entries', 'settings'].includes(name)) return table;
return { ...table, async mutate(req) {
const result = await table.mutate(req);
const marker = await core.table('syncState').mutate({ type: 'put', trans: req.trans, values: [{ key: 'dirty', value: true }] });
if (marker.numFailures) throw marker.failures[0];
return result;
} };
},
};
},
});
/* ------------------------------------------------------------------ settings */
export async function readSettings() {