@classic-homes/offline-core 0.1.5 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cache/index.d.ts +17 -1
- package/dist/cache/index.js +6 -6
- package/dist/{chunk-DIXYWY34.js → chunk-34PR6T4B.js} +216 -60
- package/dist/{chunk-J2ZYJDJX.js → chunk-4KL3GDYP.js} +94 -44
- package/dist/{chunk-PEQVHD6Q.js → chunk-JPXEFKZO.js} +97 -23
- package/dist/{chunk-WWKATW37.js → chunk-MA4ZHPQS.js} +95 -18
- package/dist/{chunk-ZC7F2HDV.js → chunk-QS7N4PTV.js} +5 -2
- package/dist/{chunk-U27TKOYZ.js → chunk-R2IP2AA5.js} +2 -2
- package/dist/{chunk-EWMN3Y7N.js → chunk-UL7MZBSF.js} +2 -2
- package/dist/drafts/index.d.ts +46 -9
- package/dist/drafts/index.js +3 -3
- package/dist/files/index.js +2 -2
- package/dist/index.d.ts +7 -4
- package/dist/index.js +7 -7
- package/dist/storage/index.d.ts +7 -1
- package/dist/storage/index.js +2 -2
- package/dist/sync/index.d.ts +64 -7
- package/dist/sync/index.js +3 -3
- package/dist/{types-Ho1JiLQR.d.ts → types-CRMTQnjY.d.ts} +6 -1
- package/package.json +1 -1
package/dist/drafts/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { S as SaveDraftOptions, d as LoadDraftOptions, e as LoadDraftResult, C as CreateDraftOptions, b as DraftMetadata, g as StoredDraftV2, L as ListDraftsOptions, c as DraftSyncStatus } from '../types-
|
|
2
|
-
export { j as CURRENT_DRAFT_PREFIX, D as DRAFT_PREFIX, a as DRAFT_V2_PREFIX, f as StoredDraft, h as generateDraftId, k as getCurrentDraftKey, l as getDraftKey, m as getDraftV2Key, n as getFormKeyFromDraftKey, i as getOrCreateDeviceId, o as isDraftV2Key, p as isLegacyDraftKey, q as parseDraftV2Key } from '../types-
|
|
1
|
+
import { S as SaveDraftOptions, d as LoadDraftOptions, e as LoadDraftResult, C as CreateDraftOptions, b as DraftMetadata, g as StoredDraftV2, L as ListDraftsOptions, c as DraftSyncStatus } from '../types-CRMTQnjY.js';
|
|
2
|
+
export { j as CURRENT_DRAFT_PREFIX, D as DRAFT_PREFIX, a as DRAFT_V2_PREFIX, f as StoredDraft, h as generateDraftId, k as getCurrentDraftKey, l as getDraftKey, m as getDraftV2Key, n as getFormKeyFromDraftKey, i as getOrCreateDeviceId, o as isDraftV2Key, p as isLegacyDraftKey, q as parseDraftV2Key } from '../types-CRMTQnjY.js';
|
|
3
3
|
import { S as StorageAdapter } from '../types-DDhQm0hc.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
@@ -91,6 +91,20 @@ declare function createDraftStorageService(adapter: StorageAdapter): DraftStorag
|
|
|
91
91
|
* Supports legacy draft migration and backward compatibility.
|
|
92
92
|
*/
|
|
93
93
|
|
|
94
|
+
/**
|
|
95
|
+
* Options for a compare-and-set write
|
|
96
|
+
*/
|
|
97
|
+
interface DraftWriteOptions {
|
|
98
|
+
/** Only write if the stored draft still has this `version` */
|
|
99
|
+
expectedVersion?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Options for updating draft data
|
|
103
|
+
*/
|
|
104
|
+
interface UpdateDraftOptions extends DraftWriteOptions {
|
|
105
|
+
/** Replace the stored data instead of merging into it (default: false) */
|
|
106
|
+
replace?: boolean;
|
|
107
|
+
}
|
|
94
108
|
/**
|
|
95
109
|
* Draft manager service for multi-draft support
|
|
96
110
|
*/
|
|
@@ -127,17 +141,40 @@ declare class DraftManagerService {
|
|
|
127
141
|
*/
|
|
128
142
|
getDraftCount(formKey?: string): Promise<number>;
|
|
129
143
|
/**
|
|
130
|
-
* Update draft data
|
|
144
|
+
* Update draft data. This is a local edit: it bumps `version` and
|
|
145
|
+
* `updatedAt` and extends the draft's expiry by its original lifetime.
|
|
146
|
+
*
|
|
147
|
+
* Returns false if the draft does not exist (or has expired), or if
|
|
148
|
+
* `options.expectedVersion` no longer matches.
|
|
149
|
+
*/
|
|
150
|
+
updateDraft<T = Record<string, unknown>>(draftId: string, data: Partial<T>, fileRefs?: Record<string, string[]>, options?: UpdateDraftOptions): Promise<boolean>;
|
|
151
|
+
private writeDraftData;
|
|
152
|
+
/**
|
|
153
|
+
* Update draft metadata only.
|
|
154
|
+
*
|
|
155
|
+
* Sync bookkeeping (`syncStatus`, `remoteId`, `lastSyncedAt`, `syncedVersion`)
|
|
156
|
+
* is not a local edit and leaves `version` and `updatedAt` alone. Renaming
|
|
157
|
+
* is: it bumps `version` and marks a synced draft `pending-upload`, unless
|
|
158
|
+
* the same update sets `syncStatus`. Setting `syncStatus: 'synced'` without
|
|
159
|
+
* a `syncedVersion` records the resulting version as synced.
|
|
160
|
+
*
|
|
161
|
+
* Returns false if the draft does not exist, or if
|
|
162
|
+
* `options.expectedVersion` no longer matches.
|
|
131
163
|
*/
|
|
132
|
-
|
|
164
|
+
updateDraftMetadata(draftId: string, updates: Partial<Pick<DraftMetadata, 'name' | 'syncStatus' | 'remoteId' | 'lastSyncedAt' | 'syncedVersion'>>, options?: DraftWriteOptions): Promise<boolean>;
|
|
165
|
+
private writeDraftMetadata;
|
|
133
166
|
/**
|
|
134
|
-
*
|
|
167
|
+
* Delete a draft.
|
|
168
|
+
*
|
|
169
|
+
* Returns false if the draft does not exist, or if
|
|
170
|
+
* `options.expectedVersion` no longer matches (it was edited meanwhile).
|
|
135
171
|
*/
|
|
136
|
-
|
|
172
|
+
deleteDraft(draftId: string, deleteFiles?: boolean, options?: DraftWriteOptions): Promise<boolean>;
|
|
173
|
+
private removeDraft;
|
|
137
174
|
/**
|
|
138
|
-
*
|
|
175
|
+
* File IDs referenced by any stored draft (multi-draft and legacy)
|
|
139
176
|
*/
|
|
140
|
-
|
|
177
|
+
private referencedFileIds;
|
|
141
178
|
/**
|
|
142
179
|
* Delete all drafts for a form key
|
|
143
180
|
*/
|
|
@@ -200,4 +237,4 @@ declare class DraftManagerService {
|
|
|
200
237
|
*/
|
|
201
238
|
declare function createDraftManagerService(adapter: StorageAdapter): DraftManagerService;
|
|
202
239
|
|
|
203
|
-
export { CreateDraftOptions, DraftManagerService, DraftMetadata, DraftStorageService, DraftSyncStatus, type FileExistsValidator, ListDraftsOptions, LoadDraftOptions, LoadDraftResult, SaveDraftOptions, StoredDraftV2, createDraftManagerService, createDraftStorageService };
|
|
240
|
+
export { CreateDraftOptions, DraftManagerService, DraftMetadata, DraftStorageService, DraftSyncStatus, type DraftWriteOptions, type FileExistsValidator, ListDraftsOptions, LoadDraftOptions, LoadDraftResult, SaveDraftOptions, StoredDraftV2, type UpdateDraftOptions, createDraftManagerService, createDraftStorageService };
|
package/dist/drafts/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { DraftStorageService, createDraftStorageService } from '../chunk-
|
|
2
|
-
export { CURRENT_DRAFT_PREFIX, DRAFT_PREFIX, DRAFT_V2_PREFIX, DraftManagerService, createDraftManagerService, generateDraftId, getCurrentDraftKey, getDraftKey, getDraftV2Key, getFormKeyFromDraftKey, getOrCreateDeviceId, isDraftV2Key, isLegacyDraftKey, parseDraftV2Key } from '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { DraftStorageService, createDraftStorageService } from '../chunk-UL7MZBSF.js';
|
|
2
|
+
export { CURRENT_DRAFT_PREFIX, DRAFT_PREFIX, DRAFT_V2_PREFIX, DraftManagerService, createDraftManagerService, generateDraftId, getCurrentDraftKey, getDraftKey, getDraftV2Key, getFormKeyFromDraftKey, getOrCreateDeviceId, isDraftV2Key, isLegacyDraftKey, parseDraftV2Key } from '../chunk-MA4ZHPQS.js';
|
|
3
|
+
import '../chunk-QS7N4PTV.js';
|
package/dist/files/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { FileStorageService, blobMetadataToStoredFile, createFileStorageService, storedFileToBlobMetadata } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { FileStorageService, blobMetadataToStoredFile, createFileStorageService, storedFileToBlobMetadata } from '../chunk-R2IP2AA5.js';
|
|
2
|
+
import '../chunk-QS7N4PTV.js';
|
package/dist/index.d.ts
CHANGED
|
@@ -3,12 +3,12 @@ export { B as BlobMetadata, c as BlobWithMetadata, C as CleanupResult, J as JSON
|
|
|
3
3
|
import { FileStorageService } from './files/index.js';
|
|
4
4
|
export { DeleteFilesResult, FileConstraints, FileValidationError, GetFilesOptions, PersistedFile, StoreFileOptions, StoredFile, createFileStorageService } from './files/index.js';
|
|
5
5
|
import { DraftStorageService, DraftManagerService } from './drafts/index.js';
|
|
6
|
-
export { createDraftManagerService, createDraftStorageService } from './drafts/index.js';
|
|
6
|
+
export { DraftWriteOptions, UpdateDraftOptions, createDraftManagerService, createDraftStorageService } from './drafts/index.js';
|
|
7
7
|
import { CacheService } from './cache/index.js';
|
|
8
8
|
export { CACHE_PREFIX, CacheEntry, CacheGetResult, CacheOptions, CacheStats, GetOrSetOptions, createCacheService, invalidateAllCache, invalidateCacheByTag } from './cache/index.js';
|
|
9
9
|
export { CreateAdapterOptions, CreateAdapterResult, createAdapter, detectAvailableAdapters } from './storage/index.js';
|
|
10
|
-
export { C as CreateDraftOptions, D as DRAFT_PREFIX, a as DRAFT_V2_PREFIX, b as DraftMetadata, c as DraftSyncStatus, L as ListDraftsOptions, d as LoadDraftOptions, e as LoadDraftResult, S as SaveDraftOptions, f as StoredDraft, g as StoredDraftV2, h as generateDraftId, i as getOrCreateDeviceId } from './types-
|
|
11
|
-
export { ConflictResolution, ConnectivityMonitor, ConnectivityState, DraftConflict, DraftPayload, PendingSyncOperation, RemoteDraft, SyncAdapter, SyncConfig, SyncEvent, SyncEventListener, SyncEventType, SyncQueue, SyncQueueState, SyncRequest, SyncResponse, SyncResult, SyncService, applyResolution, compareDrafts, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict } from './sync/index.js';
|
|
10
|
+
export { C as CreateDraftOptions, D as DRAFT_PREFIX, a as DRAFT_V2_PREFIX, b as DraftMetadata, c as DraftSyncStatus, L as ListDraftsOptions, d as LoadDraftOptions, e as LoadDraftResult, S as SaveDraftOptions, f as StoredDraft, g as StoredDraftV2, h as generateDraftId, i as getOrCreateDeviceId } from './types-CRMTQnjY.js';
|
|
11
|
+
export { ConflictResolution, ConnectivityMonitor, ConnectivityState, DraftConflict, DraftPayload, PendingSyncOperation, RemoteDraft, SyncAdapter, SyncConfig, SyncEvent, SyncEventListener, SyncEventType, SyncFailure, SyncQueue, SyncQueueState, SyncRequest, SyncResponse, SyncResult, SyncService, applyResolution, compareDrafts, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict } from './sync/index.js';
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Error types for the offline storage package
|
|
@@ -121,7 +121,10 @@ declare function isExpired(expiresAt: number | null | undefined): boolean;
|
|
|
121
121
|
declare const DEFAULT_EXPIRATIONS: {
|
|
122
122
|
/** Form draft expiration: 7 days */
|
|
123
123
|
readonly DRAFT: number;
|
|
124
|
-
/**
|
|
124
|
+
/**
|
|
125
|
+
* File attachment expiration: 7 days, the same as drafts, so a restored
|
|
126
|
+
* draft still has its attachments
|
|
127
|
+
*/
|
|
125
128
|
readonly FILE: number;
|
|
126
129
|
/** Cache entry expiration: 1 hour */
|
|
127
130
|
readonly CACHE: number;
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
export { CACHE_PREFIX, CacheService, createCacheService, detectStorageAdapter, getOfflineStorage, getOfflineStorageOrNull, initOfflineStorage, invalidateAllCache, invalidateCacheByTag, isOfflineStorageInitialized, resetOfflineStorage } from './chunk-
|
|
2
|
-
export { OfflineStorageError, createAdapter, detectAvailableAdapters, detectBrowser, isBrowser, isSSR, isWorker, supportsIndexedDB, supportsLocalStorage, supportsOPFS } from './chunk-
|
|
3
|
-
export { FileStorageService, createFileStorageService } from './chunk-
|
|
4
|
-
export { DraftStorageService, createDraftStorageService } from './chunk-
|
|
5
|
-
export { ConnectivityMonitor, SyncQueue, SyncService, applyResolution, compareDrafts, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict } from './chunk-
|
|
6
|
-
export { DRAFT_PREFIX, DRAFT_V2_PREFIX, DraftManagerService, createDraftManagerService, generateDraftId, getOrCreateDeviceId } from './chunk-
|
|
7
|
-
export { CleanupScheduler, DEFAULT_EXPIRATIONS, calculateExpiration, isExpired } from './chunk-
|
|
1
|
+
export { CACHE_PREFIX, CacheService, createCacheService, detectStorageAdapter, getOfflineStorage, getOfflineStorageOrNull, initOfflineStorage, invalidateAllCache, invalidateCacheByTag, isOfflineStorageInitialized, resetOfflineStorage } from './chunk-JPXEFKZO.js';
|
|
2
|
+
export { OfflineStorageError, createAdapter, detectAvailableAdapters, detectBrowser, isBrowser, isSSR, isWorker, supportsIndexedDB, supportsLocalStorage, supportsOPFS } from './chunk-4KL3GDYP.js';
|
|
3
|
+
export { FileStorageService, createFileStorageService } from './chunk-R2IP2AA5.js';
|
|
4
|
+
export { DraftStorageService, createDraftStorageService } from './chunk-UL7MZBSF.js';
|
|
5
|
+
export { ConnectivityMonitor, SyncQueue, SyncService, applyResolution, compareDrafts, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict } from './chunk-34PR6T4B.js';
|
|
6
|
+
export { DRAFT_PREFIX, DRAFT_V2_PREFIX, DraftManagerService, createDraftManagerService, generateDraftId, getOrCreateDeviceId } from './chunk-MA4ZHPQS.js';
|
|
7
|
+
export { CleanupScheduler, DEFAULT_EXPIRATIONS, calculateExpiration, isExpired } from './chunk-QS7N4PTV.js';
|
package/dist/storage/index.d.ts
CHANGED
|
@@ -53,12 +53,18 @@ declare function createMemoryAdapter(options?: StorageAdapterOptions): MemoryAda
|
|
|
53
53
|
declare class IndexedDBAdapter implements StorageAdapter {
|
|
54
54
|
readonly name: "indexeddb";
|
|
55
55
|
private db;
|
|
56
|
+
private reopening;
|
|
57
|
+
private initialized;
|
|
56
58
|
private readonly dbName;
|
|
57
59
|
constructor(options?: StorageAdapterOptions);
|
|
58
60
|
/**
|
|
59
|
-
* Get the database,
|
|
61
|
+
* Get the database, reopening it if the connection was closed
|
|
60
62
|
*/
|
|
61
63
|
private getDB;
|
|
64
|
+
/**
|
|
65
|
+
* Open the database and keep the connection only while it is usable
|
|
66
|
+
*/
|
|
67
|
+
private open;
|
|
62
68
|
storeBlob(key: string, blob: Blob, metadata?: BlobMetadata): Promise<void>;
|
|
63
69
|
getBlob(key: string): Promise<BlobWithMetadata | null>;
|
|
64
70
|
deleteBlob(key: string): Promise<void>;
|
package/dist/storage/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { IndexedDBAdapter, MemoryAdapter, OPFSAdapter, createAdapter, createIndexedDBAdapter, createMemoryAdapter, createOPFSAdapter, detectAvailableAdapters } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
1
|
+
export { IndexedDBAdapter, MemoryAdapter, OPFSAdapter, createAdapter, createIndexedDBAdapter, createMemoryAdapter, createOPFSAdapter, detectAvailableAdapters } from '../chunk-4KL3GDYP.js';
|
|
2
|
+
import '../chunk-QS7N4PTV.js';
|
package/dist/sync/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as StoredDraftV2 } from '../types-
|
|
1
|
+
import { g as StoredDraftV2 } from '../types-CRMTQnjY.js';
|
|
2
2
|
import { S as StorageAdapter } from '../types-DDhQm0hc.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -48,6 +48,12 @@ interface DraftPayload {
|
|
|
48
48
|
updatedAt: number;
|
|
49
49
|
/** Device ID */
|
|
50
50
|
deviceId: string;
|
|
51
|
+
/**
|
|
52
|
+
* Local draft ID. Stable across retries of the same draft, so a server can
|
|
53
|
+
* use it as an idempotency key on create: a retried create whose first
|
|
54
|
+
* response was lost should return the existing draft, not a duplicate.
|
|
55
|
+
*/
|
|
56
|
+
localId?: string;
|
|
51
57
|
}
|
|
52
58
|
/**
|
|
53
59
|
* Draft data returned from the server
|
|
@@ -118,7 +124,12 @@ interface SyncResponse {
|
|
|
118
124
|
*/
|
|
119
125
|
interface SyncAdapter {
|
|
120
126
|
/**
|
|
121
|
-
* Fetch all drafts for the current user
|
|
127
|
+
* Fetch all drafts for the current user.
|
|
128
|
+
*
|
|
129
|
+
* Must return the **complete** list, not a page or a partial result: the
|
|
130
|
+
* sync service treats a previously synced draft missing from this list as
|
|
131
|
+
* deleted on the server and deletes the local copy (unless it was edited
|
|
132
|
+
* since the sync started). Throw instead of returning a partial list.
|
|
122
133
|
*/
|
|
123
134
|
fetchDrafts(): Promise<RemoteDraft[]>;
|
|
124
135
|
/**
|
|
@@ -163,11 +174,24 @@ interface SyncConfig {
|
|
|
163
174
|
/** Callback for sync errors */
|
|
164
175
|
onSyncError?: (error: Error) => void;
|
|
165
176
|
}
|
|
177
|
+
/**
|
|
178
|
+
* A single draft that failed to sync. The rest of the sync still runs.
|
|
179
|
+
*/
|
|
180
|
+
interface SyncFailure {
|
|
181
|
+
/** What was being done */
|
|
182
|
+
operation: 'upload' | 'download' | 'delete';
|
|
183
|
+
/** Local draft ID (absent for a failed download of a new remote draft) */
|
|
184
|
+
draftId?: string;
|
|
185
|
+
/** Remote draft ID, if known */
|
|
186
|
+
remoteId?: string;
|
|
187
|
+
/** Error message */
|
|
188
|
+
error: string;
|
|
189
|
+
}
|
|
166
190
|
/**
|
|
167
191
|
* Result of a sync operation
|
|
168
192
|
*/
|
|
169
193
|
interface SyncResult {
|
|
170
|
-
/** Whether sync was successful */
|
|
194
|
+
/** Whether sync was successful (false if any draft failed; see `failures`) */
|
|
171
195
|
success: boolean;
|
|
172
196
|
/** Number of drafts uploaded */
|
|
173
197
|
uploaded: number;
|
|
@@ -181,6 +205,11 @@ interface SyncResult {
|
|
|
181
205
|
conflicts: DraftConflict[];
|
|
182
206
|
/** Error message if failed */
|
|
183
207
|
error?: string;
|
|
208
|
+
/**
|
|
209
|
+
* Drafts that failed while the rest synced. A failed upload is retried on
|
|
210
|
+
* later syncs with exponential backoff.
|
|
211
|
+
*/
|
|
212
|
+
failures?: SyncFailure[];
|
|
184
213
|
/** Timestamp of sync */
|
|
185
214
|
timestamp: number;
|
|
186
215
|
/** Duration in milliseconds */
|
|
@@ -503,6 +532,9 @@ declare class SyncService {
|
|
|
503
532
|
private conflicts;
|
|
504
533
|
private eventListeners;
|
|
505
534
|
private connectivityUnsubscribe;
|
|
535
|
+
private pendingDraftCount;
|
|
536
|
+
/** Upload backoff per local draft ID */
|
|
537
|
+
private uploadFailures;
|
|
506
538
|
private onSyncComplete?;
|
|
507
539
|
private onConflictDetected?;
|
|
508
540
|
private onOnlineStatusChange?;
|
|
@@ -525,9 +557,15 @@ declare class SyncService {
|
|
|
525
557
|
*/
|
|
526
558
|
get lastSyncAt(): number | null;
|
|
527
559
|
/**
|
|
528
|
-
*
|
|
560
|
+
* Number of local drafts waiting to be uploaded ('local-only' or
|
|
561
|
+
* 'pending-upload'), as of the last sync, `initialize()` or
|
|
562
|
+
* `refreshPendingCount()`
|
|
529
563
|
*/
|
|
530
564
|
get pendingCount(): number;
|
|
565
|
+
/**
|
|
566
|
+
* Recount the local drafts waiting to be uploaded
|
|
567
|
+
*/
|
|
568
|
+
refreshPendingCount(): Promise<number>;
|
|
531
569
|
/**
|
|
532
570
|
* Get current conflicts
|
|
533
571
|
*/
|
|
@@ -540,10 +578,12 @@ declare class SyncService {
|
|
|
540
578
|
* Sync all drafts
|
|
541
579
|
*/
|
|
542
580
|
syncAll(): Promise<SyncResult>;
|
|
581
|
+
private runSyncAll;
|
|
543
582
|
/**
|
|
544
583
|
* Sync a specific draft
|
|
545
584
|
*/
|
|
546
585
|
syncDraft(draftId: string): Promise<SyncResult>;
|
|
586
|
+
private runSyncDraft;
|
|
547
587
|
/**
|
|
548
588
|
* Force push a draft (overwrite remote)
|
|
549
589
|
*/
|
|
@@ -581,15 +621,32 @@ declare class SyncService {
|
|
|
581
621
|
*/
|
|
582
622
|
dispose(): void;
|
|
583
623
|
/**
|
|
584
|
-
* Perform the actual sync
|
|
624
|
+
* Perform the actual sync. One draft failing does not stop the rest: each
|
|
625
|
+
* failure is recorded in `failures` and the sync carries on.
|
|
585
626
|
*/
|
|
586
627
|
private performSync;
|
|
628
|
+
/**
|
|
629
|
+
* Whether a failing draft is still waiting out its retry delay
|
|
630
|
+
*/
|
|
631
|
+
private isBackedOff;
|
|
632
|
+
/**
|
|
633
|
+
* Record a failed upload and schedule its next attempt (exponential backoff)
|
|
634
|
+
*/
|
|
635
|
+
private recordUploadFailure;
|
|
587
636
|
/**
|
|
588
637
|
* Sync a single draft
|
|
589
638
|
*/
|
|
590
639
|
private syncSingleDraft;
|
|
591
640
|
/**
|
|
592
|
-
*
|
|
641
|
+
* Mark an uploaded draft as synced, but only if it was not edited while the
|
|
642
|
+
* upload was in flight (compare-and-set on `version`). An edited draft stays
|
|
643
|
+
* pending so the edit is uploaded next time; its remote ID is still
|
|
644
|
+
* recorded so that upload updates the remote copy instead of creating another.
|
|
645
|
+
*/
|
|
646
|
+
private markUploaded;
|
|
647
|
+
/**
|
|
648
|
+
* Download a remote draft. Into an existing local draft only if that draft
|
|
649
|
+
* is unchanged since it was read; returns false when a local edit won.
|
|
593
650
|
*/
|
|
594
651
|
private downloadRemoteDraft;
|
|
595
652
|
/**
|
|
@@ -618,4 +675,4 @@ declare class SyncService {
|
|
|
618
675
|
*/
|
|
619
676
|
declare function createSyncService(adapter: StorageAdapter, config: SyncConfig): SyncService;
|
|
620
677
|
|
|
621
|
-
export { type ConflictResolution, ConnectivityMonitor, type ConnectivityState, type DraftConflict, type DraftPayload, type PendingSyncOperation, type RemoteDraft, type SyncAdapter, type SyncConfig, SyncConflictError, type SyncEvent, type SyncEventListener, type SyncEventType, SyncQueue, type SyncQueueState, type SyncRequest, type SyncResponse, type SyncResult, SyncService, applyResolution, compareDrafts, createConflict, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict, isSyncConflictError, resolveKeepLocal, resolveKeepRemote, resolveMerge };
|
|
678
|
+
export { type ConflictResolution, ConnectivityMonitor, type ConnectivityState, type DraftConflict, type DraftPayload, type PendingSyncOperation, type RemoteDraft, type SyncAdapter, type SyncConfig, SyncConflictError, type SyncEvent, type SyncEventListener, type SyncEventType, type SyncFailure, SyncQueue, type SyncQueueState, type SyncRequest, type SyncResponse, type SyncResult, SyncService, applyResolution, compareDrafts, createConflict, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict, isSyncConflictError, resolveKeepLocal, resolveKeepRemote, resolveMerge };
|
package/dist/sync/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { ConnectivityMonitor, SyncConflictError, SyncQueue, SyncService, applyResolution, compareDrafts, createConflict, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict, isSyncConflictError, resolveKeepLocal, resolveKeepRemote, resolveMerge } from '../chunk-
|
|
2
|
-
import '../chunk-
|
|
3
|
-
import '../chunk-
|
|
1
|
+
export { ConnectivityMonitor, SyncConflictError, SyncQueue, SyncService, applyResolution, compareDrafts, createConflict, createConnectivityMonitor, createSyncQueue, createSyncService, detectConflict, isSyncConflictError, resolveKeepLocal, resolveKeepRemote, resolveMerge } from '../chunk-34PR6T4B.js';
|
|
2
|
+
import '../chunk-MA4ZHPQS.js';
|
|
3
|
+
import '../chunk-QS7N4PTV.js';
|
|
@@ -40,8 +40,13 @@ interface DraftMetadata {
|
|
|
40
40
|
syncStatus: DraftSyncStatus;
|
|
41
41
|
/** Server-side ID (null if never synced) */
|
|
42
42
|
remoteId: string | null;
|
|
43
|
-
/** Version number for conflict detection */
|
|
43
|
+
/** Version number for conflict detection. Bumped by local edits only, not by metadata-only updates */
|
|
44
44
|
version: number;
|
|
45
|
+
/**
|
|
46
|
+
* The `version` last confirmed in sync with the server. A draft whose
|
|
47
|
+
* `version` differs has local edits that have not been uploaded.
|
|
48
|
+
*/
|
|
49
|
+
syncedVersion?: number;
|
|
45
50
|
/** Timestamp of last successful sync */
|
|
46
51
|
lastSyncedAt: number | null;
|
|
47
52
|
/** Device ID where draft was created/modified */
|