async-storage-sync 1.0.5 → 1.0.6
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -4
- package/dist/index.mjs +34 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ console.log(`${pending.length} forms waiting to sync`);
|
|
|
64
64
|
- `autoSync: false`: no automatic syncing; call sync methods manually when you choose.
|
|
65
65
|
- Manual methods:
|
|
66
66
|
- `store.flushWithResult()` → sync all pending and return summary counts
|
|
67
|
-
- `store.
|
|
67
|
+
- `store.syncWithResult(collection)` → sync one collection and return summary counts
|
|
68
68
|
- `store.syncById(collection, id)` → sync one record
|
|
69
69
|
- Sync destination is controlled by your config: `serverUrl + endpoint`.
|
|
70
70
|
|
|
@@ -88,7 +88,7 @@ console.log(`${pending.length} forms waiting to sync`);
|
|
|
88
88
|
| `store.deleteById(collection, id)` | Delete one record by internal `_id` |
|
|
89
89
|
| `store.deleteCollection(collection)` | Delete all records in one collection |
|
|
90
90
|
| `store.flushWithResult()` | Sync all pending and return detailed summary (`attempted`, `synced`, `failed`, `retried`, `remainingPending`, `items`) |
|
|
91
|
-
| `store.
|
|
91
|
+
| `store.syncWithResult(collection)` | Sync collection and return detailed summary (same format as `flushWithResult()`) |
|
|
92
92
|
| `store.syncById(collection, id)` | Sync one specific record by internal `_id` |
|
|
93
93
|
| `store.requeueFailed()` | Move `failed` records back to pending queue for retry |
|
|
94
94
|
| `store.onSynced(callback)` | Event callback for successful sync of each item |
|
package/dist/index.d.mts
CHANGED
|
@@ -80,7 +80,7 @@ declare class AsyncStorageSync {
|
|
|
80
80
|
getById<T extends Record<string, unknown>>(name: string, id: string): Promise<StoredRecord<T> | null>;
|
|
81
81
|
deleteById(name: string, id: string): Promise<void>;
|
|
82
82
|
deleteCollection(name: string): Promise<void>;
|
|
83
|
-
|
|
83
|
+
syncWithResult(name: string): Promise<FlushResult>;
|
|
84
84
|
syncById(_name: string, id: string): Promise<void>;
|
|
85
85
|
flushWithResult(): Promise<FlushResult>;
|
|
86
86
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -80,7 +80,7 @@ declare class AsyncStorageSync {
|
|
|
80
80
|
getById<T extends Record<string, unknown>>(name: string, id: string): Promise<StoredRecord<T> | null>;
|
|
81
81
|
deleteById(name: string, id: string): Promise<void>;
|
|
82
82
|
deleteCollection(name: string): Promise<void>;
|
|
83
|
-
|
|
83
|
+
syncWithResult(name: string): Promise<FlushResult>;
|
|
84
84
|
syncById(_name: string, id: string): Promise<void>;
|
|
85
85
|
flushWithResult(): Promise<FlushResult>;
|
|
86
86
|
/**
|
package/dist/index.js
CHANGED
|
@@ -281,11 +281,41 @@ var SyncEngine = class {
|
|
|
281
281
|
this.isFlushing = false;
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
|
-
async
|
|
284
|
+
async flushCollectionWithResult(collectionName) {
|
|
285
|
+
const result = {
|
|
286
|
+
attempted: 0,
|
|
287
|
+
synced: 0,
|
|
288
|
+
failed: 0,
|
|
289
|
+
retried: 0,
|
|
290
|
+
deferred: 0,
|
|
291
|
+
networkErrors: 0,
|
|
292
|
+
remainingPending: 0,
|
|
293
|
+
skippedAlreadyFlushing: false,
|
|
294
|
+
items: []
|
|
295
|
+
};
|
|
285
296
|
const pending = this.queue.getPendingForCollection(collectionName);
|
|
297
|
+
if (pending.length === 0) {
|
|
298
|
+
result.remainingPending = this.queue.getPendingForCollection(collectionName).length;
|
|
299
|
+
return result;
|
|
300
|
+
}
|
|
286
301
|
for (const item of pending) {
|
|
287
|
-
|
|
302
|
+
result.attempted += 1;
|
|
303
|
+
const itemResult = await this.syncItem(item);
|
|
304
|
+
result.items.push(itemResult);
|
|
305
|
+
if (itemResult.status === "synced") {
|
|
306
|
+
result.synced += 1;
|
|
307
|
+
} else if (itemResult.status === "failed") {
|
|
308
|
+
result.failed += 1;
|
|
309
|
+
} else if (itemResult.status === "retried") {
|
|
310
|
+
result.retried += 1;
|
|
311
|
+
} else if (itemResult.status === "deferred-backoff") {
|
|
312
|
+
result.deferred += 1;
|
|
313
|
+
} else if (itemResult.status === "network-error") {
|
|
314
|
+
result.networkErrors += 1;
|
|
315
|
+
}
|
|
288
316
|
}
|
|
317
|
+
result.remainingPending = this.queue.getPendingForCollection(collectionName).length;
|
|
318
|
+
return result;
|
|
289
319
|
}
|
|
290
320
|
async flushRecord(recordId) {
|
|
291
321
|
const item = this.queue.getPendingForRecord(recordId);
|
|
@@ -556,8 +586,8 @@ var _AsyncStorageSync = class _AsyncStorageSync {
|
|
|
556
586
|
async deleteCollection(name) {
|
|
557
587
|
await this.driver.remove(collectionKey(name));
|
|
558
588
|
}
|
|
559
|
-
async
|
|
560
|
-
|
|
589
|
+
async syncWithResult(name) {
|
|
590
|
+
return this.engine.flushCollectionWithResult(name);
|
|
561
591
|
}
|
|
562
592
|
async syncById(_name, id) {
|
|
563
593
|
await this.engine.flushRecord(id);
|
package/dist/index.mjs
CHANGED
|
@@ -259,11 +259,41 @@ var SyncEngine = class {
|
|
|
259
259
|
this.isFlushing = false;
|
|
260
260
|
}
|
|
261
261
|
}
|
|
262
|
-
async
|
|
262
|
+
async flushCollectionWithResult(collectionName) {
|
|
263
|
+
const result = {
|
|
264
|
+
attempted: 0,
|
|
265
|
+
synced: 0,
|
|
266
|
+
failed: 0,
|
|
267
|
+
retried: 0,
|
|
268
|
+
deferred: 0,
|
|
269
|
+
networkErrors: 0,
|
|
270
|
+
remainingPending: 0,
|
|
271
|
+
skippedAlreadyFlushing: false,
|
|
272
|
+
items: []
|
|
273
|
+
};
|
|
263
274
|
const pending = this.queue.getPendingForCollection(collectionName);
|
|
275
|
+
if (pending.length === 0) {
|
|
276
|
+
result.remainingPending = this.queue.getPendingForCollection(collectionName).length;
|
|
277
|
+
return result;
|
|
278
|
+
}
|
|
264
279
|
for (const item of pending) {
|
|
265
|
-
|
|
280
|
+
result.attempted += 1;
|
|
281
|
+
const itemResult = await this.syncItem(item);
|
|
282
|
+
result.items.push(itemResult);
|
|
283
|
+
if (itemResult.status === "synced") {
|
|
284
|
+
result.synced += 1;
|
|
285
|
+
} else if (itemResult.status === "failed") {
|
|
286
|
+
result.failed += 1;
|
|
287
|
+
} else if (itemResult.status === "retried") {
|
|
288
|
+
result.retried += 1;
|
|
289
|
+
} else if (itemResult.status === "deferred-backoff") {
|
|
290
|
+
result.deferred += 1;
|
|
291
|
+
} else if (itemResult.status === "network-error") {
|
|
292
|
+
result.networkErrors += 1;
|
|
293
|
+
}
|
|
266
294
|
}
|
|
295
|
+
result.remainingPending = this.queue.getPendingForCollection(collectionName).length;
|
|
296
|
+
return result;
|
|
267
297
|
}
|
|
268
298
|
async flushRecord(recordId) {
|
|
269
299
|
const item = this.queue.getPendingForRecord(recordId);
|
|
@@ -534,8 +564,8 @@ var _AsyncStorageSync = class _AsyncStorageSync {
|
|
|
534
564
|
async deleteCollection(name) {
|
|
535
565
|
await this.driver.remove(collectionKey(name));
|
|
536
566
|
}
|
|
537
|
-
async
|
|
538
|
-
|
|
567
|
+
async syncWithResult(name) {
|
|
568
|
+
return this.engine.flushCollectionWithResult(name);
|
|
539
569
|
}
|
|
540
570
|
async syncById(_name, id) {
|
|
541
571
|
await this.engine.flushRecord(id);
|
package/package.json
CHANGED