mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-30 00:20:07 +00:00
feat(atlas): read and write the Atlas offline
The Atlas reads go network first and fall back to a snapshot kept in a new Dexie table (v17, append-only). Marks, unmarks and wishlist deletes made offline wait in their own account-level queue, replayed in order with an idempotency key, and every read lays them over the kept answer.
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* The replay rules both write queues follow: the trip queue (mutationQueue)
|
||||
* and the account's own writes (userMutationQueue). One place, so a retry or
|
||||
* backoff change cannot reach one queue and miss the other.
|
||||
*/
|
||||
|
||||
// A row sits on 'syncing' only while its request is in flight, and the shared
|
||||
// axios instance times out at 8s. Anything still 'syncing' a minute later
|
||||
// belongs to a flush that never reached its catch — the tab was killed, the PWA
|
||||
// was evicted, the device slept mid-request. flush() only ever selects
|
||||
// 'pending', so without recovery that row is stranded: counted in the badge,
|
||||
// never replayed, and blocking every dependent behind it.
|
||||
export const STUCK_SYNCING_MS = 60_000;
|
||||
|
||||
/**
|
||||
* A write the server answers with a 5xx this many times is parked as failed.
|
||||
* The gaps double from 30 s, so the last try comes about two hours after the
|
||||
* first: long enough for a restart or an outage, short of blocking forever.
|
||||
*/
|
||||
export const MAX_SERVER_ERROR_ATTEMPTS = 8;
|
||||
export const SERVER_ERROR_BACKOFF_MS = 30_000;
|
||||
|
||||
/** HTTP statuses that should be retried later rather than treated as terminal. */
|
||||
export function isRetryableStatus(status: number | undefined): boolean {
|
||||
// 401: token expired mid-flush (offline window) — retry after re-auth.
|
||||
// 408/425/429: timeout / too-early / rate-limited — transient.
|
||||
return status === 401 || status === 408 || status === 425 || status === 429;
|
||||
}
|
||||
|
||||
// The UI build stamped onto each queued write, for diagnosis. Empty where the
|
||||
// bundler defined none.
|
||||
export const BUILD_VERSION: string = typeof __TREK_UI_VERSION__ === 'string' ? __TREK_UI_VERSION__ : '';
|
||||
Reference in New Issue
Block a user