@serwist/background-sync 8.4.0 → 8.4.1
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/dist/Queue.d.ts +1 -1
- package/dist/index.cjs +11 -13
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +11 -13
- package/package.json +4 -4
package/dist/Queue.d.ts
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -161,7 +161,7 @@ const QUEUE_NAME_INDEX = "queueName";
|
|
|
161
161
|
paramName: "entry.requestData"
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
|
-
// Don't specify an ID since one is automatically generated.
|
|
164
|
+
// biome-ignore lint/performance/noDelete: Don't specify an ID since one is automatically generated.
|
|
165
165
|
delete entry.id;
|
|
166
166
|
entry.queueName = this._queueName;
|
|
167
167
|
await this._queueDb.addEntry(entry);
|
|
@@ -190,7 +190,7 @@ const QUEUE_NAME_INDEX = "queueName";
|
|
|
190
190
|
// Pick an ID one less than the lowest ID in the object store.
|
|
191
191
|
entry.id = firstId - 1;
|
|
192
192
|
} else {
|
|
193
|
-
//
|
|
193
|
+
// biome-ignore lint/performance/noDelete: Let the auto-incrementor assign the ID.
|
|
194
194
|
delete entry.id;
|
|
195
195
|
}
|
|
196
196
|
entry.queueName = this._queueName;
|
|
@@ -322,8 +322,8 @@ const serializableProperties = [
|
|
|
322
322
|
}
|
|
323
323
|
// If the request's mode is `navigate`, convert it to `same-origin` since
|
|
324
324
|
// navigation requests can't be constructed via script.
|
|
325
|
-
if (requestData
|
|
326
|
-
requestData
|
|
325
|
+
if (requestData.mode === "navigate") {
|
|
326
|
+
requestData.mode = "same-origin";
|
|
327
327
|
}
|
|
328
328
|
this._requestData = requestData;
|
|
329
329
|
}
|
|
@@ -402,9 +402,8 @@ const queueNames = new Set();
|
|
|
402
402
|
throw new internal.SerwistError("duplicate-queue-name", {
|
|
403
403
|
name
|
|
404
404
|
});
|
|
405
|
-
} else {
|
|
406
|
-
queueNames.add(name);
|
|
407
405
|
}
|
|
406
|
+
queueNames.add(name);
|
|
408
407
|
this._name = name;
|
|
409
408
|
this._onSync = onSync || this.replayRequests;
|
|
410
409
|
this._maxRetentionTime = maxRetentionTime || MAX_RETENTION_TIME;
|
|
@@ -570,16 +569,15 @@ const queueNames = new Set();
|
|
|
570
569
|
return this._removeRequest(operation);
|
|
571
570
|
}
|
|
572
571
|
return convertEntry(entry);
|
|
573
|
-
} else {
|
|
574
|
-
return undefined;
|
|
575
572
|
}
|
|
573
|
+
return undefined;
|
|
576
574
|
}
|
|
577
575
|
/**
|
|
578
576
|
* Loops through each request in the queue and attempts to re-fetch it.
|
|
579
577
|
* If any request fails to re-fetch, it's put back in the same position in
|
|
580
578
|
* the queue (which registers a retry for the next sync event).
|
|
581
579
|
*/ async replayRequests() {
|
|
582
|
-
let entry;
|
|
580
|
+
let entry = undefined;
|
|
583
581
|
while(entry = await this.shiftRequest()){
|
|
584
582
|
try {
|
|
585
583
|
await fetch(entry.request.clone());
|
|
@@ -597,7 +595,7 @@ const queueNames = new Set();
|
|
|
597
595
|
}
|
|
598
596
|
}
|
|
599
597
|
if (process.env.NODE_ENV !== "production") {
|
|
600
|
-
internal.logger.log(`All requests in queue '${this.name}' have successfully
|
|
598
|
+
internal.logger.log(`All requests in queue '${this.name}' have successfully replayed; the queue is now empty!`);
|
|
601
599
|
}
|
|
602
600
|
}
|
|
603
601
|
/**
|
|
@@ -628,11 +626,11 @@ const queueNames = new Set();
|
|
|
628
626
|
self.addEventListener("sync", (event)=>{
|
|
629
627
|
if (event.tag === `${TAG_PREFIX}:${this._name}`) {
|
|
630
628
|
if (process.env.NODE_ENV !== "production") {
|
|
631
|
-
internal.logger.log(`Background sync for tag '${event.tag}'
|
|
629
|
+
internal.logger.log(`Background sync for tag '${event.tag}' has been received`);
|
|
632
630
|
}
|
|
633
631
|
const syncComplete = async ()=>{
|
|
634
632
|
this._syncInProgress = true;
|
|
635
|
-
let syncError;
|
|
633
|
+
let syncError = undefined;
|
|
636
634
|
try {
|
|
637
635
|
await this._onSync({
|
|
638
636
|
queue: this
|
|
@@ -662,7 +660,7 @@ const queueNames = new Set();
|
|
|
662
660
|
});
|
|
663
661
|
} else {
|
|
664
662
|
if (process.env.NODE_ENV !== "production") {
|
|
665
|
-
internal.logger.log(
|
|
663
|
+
internal.logger.log("Background sync replaying without background sync event");
|
|
666
664
|
}
|
|
667
665
|
// If the browser doesn't support background sync, or the developer has
|
|
668
666
|
// opted-in to not using it, retry every time the service worker starts up
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BackgroundSyncPlugin } from "./BackgroundSyncPlugin.js";
|
|
2
|
-
import type { QueueOptions } from "./Queue.js";
|
|
2
|
+
import type { QueueEntry, QueueOptions } from "./Queue.js";
|
|
3
3
|
import { Queue } from "./Queue.js";
|
|
4
4
|
import { QueueStore } from "./QueueStore.js";
|
|
5
5
|
import { StorableRequest } from "./StorableRequest.js";
|
|
@@ -20,4 +20,4 @@ declare global {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export { BackgroundSyncPlugin, Queue, QueueStore, StorableRequest };
|
|
23
|
-
export type { QueueOptions };
|
|
23
|
+
export type { QueueOptions, QueueEntry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BackgroundSyncPlugin } from "./BackgroundSyncPlugin.js";
|
|
2
|
-
import type { QueueOptions } from "./Queue.js";
|
|
2
|
+
import type { QueueEntry, QueueOptions } from "./Queue.js";
|
|
3
3
|
import { Queue } from "./Queue.js";
|
|
4
4
|
import { QueueStore } from "./QueueStore.js";
|
|
5
5
|
import { StorableRequest } from "./StorableRequest.js";
|
|
@@ -20,4 +20,4 @@ declare global {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
export { BackgroundSyncPlugin, Queue, QueueStore, StorableRequest };
|
|
23
|
-
export type { QueueOptions };
|
|
23
|
+
export type { QueueOptions, QueueEntry };
|
package/dist/index.js
CHANGED
|
@@ -159,7 +159,7 @@ const QUEUE_NAME_INDEX = "queueName";
|
|
|
159
159
|
paramName: "entry.requestData"
|
|
160
160
|
});
|
|
161
161
|
}
|
|
162
|
-
// Don't specify an ID since one is automatically generated.
|
|
162
|
+
// biome-ignore lint/performance/noDelete: Don't specify an ID since one is automatically generated.
|
|
163
163
|
delete entry.id;
|
|
164
164
|
entry.queueName = this._queueName;
|
|
165
165
|
await this._queueDb.addEntry(entry);
|
|
@@ -188,7 +188,7 @@ const QUEUE_NAME_INDEX = "queueName";
|
|
|
188
188
|
// Pick an ID one less than the lowest ID in the object store.
|
|
189
189
|
entry.id = firstId - 1;
|
|
190
190
|
} else {
|
|
191
|
-
//
|
|
191
|
+
// biome-ignore lint/performance/noDelete: Let the auto-incrementor assign the ID.
|
|
192
192
|
delete entry.id;
|
|
193
193
|
}
|
|
194
194
|
entry.queueName = this._queueName;
|
|
@@ -320,8 +320,8 @@ const serializableProperties = [
|
|
|
320
320
|
}
|
|
321
321
|
// If the request's mode is `navigate`, convert it to `same-origin` since
|
|
322
322
|
// navigation requests can't be constructed via script.
|
|
323
|
-
if (requestData
|
|
324
|
-
requestData
|
|
323
|
+
if (requestData.mode === "navigate") {
|
|
324
|
+
requestData.mode = "same-origin";
|
|
325
325
|
}
|
|
326
326
|
this._requestData = requestData;
|
|
327
327
|
}
|
|
@@ -400,9 +400,8 @@ const queueNames = new Set();
|
|
|
400
400
|
throw new SerwistError("duplicate-queue-name", {
|
|
401
401
|
name
|
|
402
402
|
});
|
|
403
|
-
} else {
|
|
404
|
-
queueNames.add(name);
|
|
405
403
|
}
|
|
404
|
+
queueNames.add(name);
|
|
406
405
|
this._name = name;
|
|
407
406
|
this._onSync = onSync || this.replayRequests;
|
|
408
407
|
this._maxRetentionTime = maxRetentionTime || MAX_RETENTION_TIME;
|
|
@@ -568,16 +567,15 @@ const queueNames = new Set();
|
|
|
568
567
|
return this._removeRequest(operation);
|
|
569
568
|
}
|
|
570
569
|
return convertEntry(entry);
|
|
571
|
-
} else {
|
|
572
|
-
return undefined;
|
|
573
570
|
}
|
|
571
|
+
return undefined;
|
|
574
572
|
}
|
|
575
573
|
/**
|
|
576
574
|
* Loops through each request in the queue and attempts to re-fetch it.
|
|
577
575
|
* If any request fails to re-fetch, it's put back in the same position in
|
|
578
576
|
* the queue (which registers a retry for the next sync event).
|
|
579
577
|
*/ async replayRequests() {
|
|
580
|
-
let entry;
|
|
578
|
+
let entry = undefined;
|
|
581
579
|
while(entry = await this.shiftRequest()){
|
|
582
580
|
try {
|
|
583
581
|
await fetch(entry.request.clone());
|
|
@@ -595,7 +593,7 @@ const queueNames = new Set();
|
|
|
595
593
|
}
|
|
596
594
|
}
|
|
597
595
|
if (process.env.NODE_ENV !== "production") {
|
|
598
|
-
logger.log(`All requests in queue '${this.name}' have successfully
|
|
596
|
+
logger.log(`All requests in queue '${this.name}' have successfully replayed; the queue is now empty!`);
|
|
599
597
|
}
|
|
600
598
|
}
|
|
601
599
|
/**
|
|
@@ -626,11 +624,11 @@ const queueNames = new Set();
|
|
|
626
624
|
self.addEventListener("sync", (event)=>{
|
|
627
625
|
if (event.tag === `${TAG_PREFIX}:${this._name}`) {
|
|
628
626
|
if (process.env.NODE_ENV !== "production") {
|
|
629
|
-
logger.log(`Background sync for tag '${event.tag}'
|
|
627
|
+
logger.log(`Background sync for tag '${event.tag}' has been received`);
|
|
630
628
|
}
|
|
631
629
|
const syncComplete = async ()=>{
|
|
632
630
|
this._syncInProgress = true;
|
|
633
|
-
let syncError;
|
|
631
|
+
let syncError = undefined;
|
|
634
632
|
try {
|
|
635
633
|
await this._onSync({
|
|
636
634
|
queue: this
|
|
@@ -660,7 +658,7 @@ const queueNames = new Set();
|
|
|
660
658
|
});
|
|
661
659
|
} else {
|
|
662
660
|
if (process.env.NODE_ENV !== "production") {
|
|
663
|
-
logger.log(
|
|
661
|
+
logger.log("Background sync replaying without background sync event");
|
|
664
662
|
}
|
|
665
663
|
// If the browser doesn't support background sync, or the developer has
|
|
666
664
|
// opted-in to not using it, retry every time the service worker starts up
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/background-sync",
|
|
3
|
-
"version": "8.4.
|
|
3
|
+
"version": "8.4.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Queues failed requests and uses the Background Sync API to replay them when the network is available",
|
|
6
6
|
"files": [
|
|
@@ -38,18 +38,18 @@
|
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"idb": "8.0.0",
|
|
41
|
-
"@serwist/core": "8.4.
|
|
41
|
+
"@serwist/core": "8.4.1"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"cross-env": "7.0.3",
|
|
45
45
|
"rollup": "4.9.1",
|
|
46
46
|
"typescript": "5.4.0-dev.20231226",
|
|
47
|
-
"@serwist/constants": "8.4.
|
|
47
|
+
"@serwist/constants": "8.4.1"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
|
|
51
51
|
"dev": "rollup --config rollup.config.js --watch",
|
|
52
|
-
"lint": "
|
|
52
|
+
"lint": "biome lint ./src",
|
|
53
53
|
"typecheck": "tsc"
|
|
54
54
|
}
|
|
55
55
|
}
|