feat(web-sync): add background sync worker and retry strategy

This commit is contained in:
2026-04-06 01:15:50 +08:00
parent 661788ae75
commit c48e16a977
6 changed files with 953 additions and 162 deletions
+33
View File
@@ -47,10 +47,33 @@ export type LocalTaskDraftRecord = {
updatedAt: number;
};
export type LocalSyncStateRecord = {
userId: string;
cursor: string | null;
lastSyncedAt: number | null;
updatedAt: number;
};
export type LocalSyncInboxRecord = {
opId: string;
userId: string;
entityId: string;
entityType: SyncEntityType;
action: SyncActionType;
payload: string | null;
clientTs: number;
deviceId: string;
serverTs: number;
receivedAt: number;
appliedAt: number | null;
};
class TodoLocalDb extends Dexie {
declare tasks: Table<LocalTaskRecord, string>;
declare opLogs: Table<LocalOpLogRecord, string>;
declare taskDrafts: Table<LocalTaskDraftRecord, string>;
declare syncStates: Table<LocalSyncStateRecord, string>;
declare syncInbox: Table<LocalSyncInboxRecord, string>;
constructor() {
super("todolist-web-db");
@@ -66,9 +89,19 @@ class TodoLocalDb extends Dexie {
task_drafts: "&taskId,userId,updatedAt"
});
this.version(3).stores({
tasks: "&id,userId,status,priority,ddlAt,updatedAt,deletedAt",
op_logs: "&opId,entityId,entityType,action,clientTs,syncedAt",
task_drafts: "&taskId,userId,updatedAt",
sync_states: "&userId,updatedAt,lastSyncedAt",
sync_inbox: "&opId,userId,entityId,serverTs,appliedAt"
});
this.tasks = this.table("tasks");
this.opLogs = this.table("op_logs");
this.taskDrafts = this.table("task_drafts");
this.syncStates = this.table("sync_states");
this.syncInbox = this.table("sync_inbox");
}
}