mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-06 00:15:32 +00:00
The IndexedDB cache, its crypto, the responder and the page-side sync go. lib/offline keeps its structure, policy, wipes, sign-out gates and notices; answers, the outbox and sync now live in lib/store, in a worker behind lib/store/client/api.ts. What users get besides that: - every folder is kept, not just the Inbox and opened ones - delete for good and empty trash work offline - a change the server refuses, or that meets a message changed on another device, is shown instead of dropped - a send whose response got lost is looked up by a Message-ID fixed when it was queued, then finished, submitted or sent again - with the store on, a start paints from the local copy, then connects An account the app drops by itself no longer wipes its data: only a sign-out or an explicit removal does. The outbox of the old database moves over once, in lib/offline/migrate-legacy.ts, and the old database goes only after the store committed. `isNetworkFailure` now counts timeouts and proxy 5xx. Sends and outbox requests are never answered from the device. Tests moved with the code: cache.test.ts and responder.test.ts are replaced by lib/store/__tests__/, and review-fixes.test.ts, outbox.test.ts and client-fallback.test.ts now run the real engine on node:sqlite. Changed assertions: an uncertain send is looked up rather than left alone forever, destroy and empty trash are queued rather than refused, and #9 (opened folders) became "a folder the server deleted goes", since all folders are kept.
65 lines
2.0 KiB
TypeScript
65 lines
2.0 KiB
TypeScript
import type { Migration } from '../storage';
|
|
|
|
export const OUTBOX_MIGRATIONS: readonly Migration[] = [
|
|
{
|
|
id: 200,
|
|
name: 'outbox',
|
|
sql: `
|
|
-- Finished messages waiting for the server. seq is shared with
|
|
-- outbox_patch, so changes and sends go out in the order they were made.
|
|
CREATE TABLE outbox (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
seq INTEGER NOT NULL,
|
|
kind TEXT NOT NULL,
|
|
created_at INTEGER NOT NULL,
|
|
status TEXT NOT NULL,
|
|
sending_since INTEGER,
|
|
-- When it was first handed to the server: where a retry's lookup starts.
|
|
first_attempt_at INTEGER,
|
|
payload TEXT NOT NULL,
|
|
summary TEXT NOT NULL,
|
|
message_id TEXT,
|
|
-- The copy already on the server that only needs submitting.
|
|
copy_id TEXT,
|
|
error TEXT
|
|
);
|
|
-- One row per record, later changes merged in. base is the record's state
|
|
-- when first queued, to tell whether the server changed it since; server
|
|
-- is the newest state the server sent, for the folder counts.
|
|
CREATE TABLE outbox_patch (
|
|
jmap TEXT NOT NULL,
|
|
type TEXT NOT NULL,
|
|
record_id TEXT NOT NULL,
|
|
op TEXT NOT NULL,
|
|
patch TEXT NOT NULL,
|
|
base TEXT,
|
|
server TEXT,
|
|
subject TEXT,
|
|
seq INTEGER NOT NULL,
|
|
queued_at INTEGER NOT NULL,
|
|
PRIMARY KEY (jmap, type, record_id)
|
|
) WITHOUT ROWID;
|
|
CREATE INDEX outbox_patch_seq ON outbox_patch (seq);
|
|
CREATE TABLE conflict (
|
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
jmap TEXT NOT NULL,
|
|
type TEXT NOT NULL,
|
|
record_id TEXT NOT NULL,
|
|
summary TEXT NOT NULL,
|
|
local TEXT NOT NULL,
|
|
created_at INTEGER NOT NULL
|
|
);
|
|
-- Files attached offline, under a stand-in blob id.
|
|
CREATE TABLE upload (
|
|
local_id TEXT PRIMARY KEY,
|
|
jmap TEXT,
|
|
type TEXT,
|
|
name TEXT,
|
|
size INTEGER NOT NULL,
|
|
data BLOB NOT NULL,
|
|
created_at INTEGER NOT NULL
|
|
) WITHOUT ROWID;
|
|
`,
|
|
},
|
|
];
|