@serwist/background-sync 9.0.0-preview.1 → 9.0.0-preview.11
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 +1 -1
- package/dist/BackgroundSyncPlugin.d.ts +3 -4
- package/dist/BackgroundSyncPlugin.d.ts.map +1 -1
- package/dist/Queue.d.ts +4 -6
- package/dist/Queue.d.ts.map +1 -1
- package/dist/StorableRequest.d.ts +1 -2
- package/dist/StorableRequest.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/package.json +5 -5
- package/src/BackgroundSyncPlugin.ts +4 -6
- package/src/Queue.ts +3 -7
- package/src/StorableRequest.ts +1 -3
package/README.md
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
This module's documentation can be found at https://
|
|
1
|
+
This module's documentation can be found at https://serwist.pages.dev/docs/background-sync
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { SerwistPlugin } from "@serwist/core";
|
|
1
|
+
import type { FetchDidFailCallbackParam, SerwistPlugin } from "@serwist/core";
|
|
2
2
|
import type { QueueOptions } from "./Queue.js";
|
|
3
3
|
/**
|
|
4
4
|
* A class implementing the `fetchDidFail` lifecycle callback. This makes it
|
|
5
5
|
* easier to add failed requests to a background sync Queue.
|
|
6
6
|
*/
|
|
7
|
-
declare class BackgroundSyncPlugin implements SerwistPlugin {
|
|
7
|
+
export declare class BackgroundSyncPlugin implements SerwistPlugin {
|
|
8
8
|
private readonly _queue;
|
|
9
9
|
/**
|
|
10
10
|
* @param name See the `@serwist/background-sync.Queue`
|
|
@@ -17,7 +17,6 @@ declare class BackgroundSyncPlugin implements SerwistPlugin {
|
|
|
17
17
|
* @param options
|
|
18
18
|
* @private
|
|
19
19
|
*/
|
|
20
|
-
fetchDidFail:
|
|
20
|
+
fetchDidFail({ request }: FetchDidFailCallbackParam): Promise<void>;
|
|
21
21
|
}
|
|
22
|
-
export { BackgroundSyncPlugin };
|
|
23
22
|
//# sourceMappingURL=BackgroundSyncPlugin.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BackgroundSyncPlugin.d.ts","sourceRoot":"","sources":["../src/BackgroundSyncPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"BackgroundSyncPlugin.d.ts","sourceRoot":"","sources":["../src/BackgroundSyncPlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAG/C;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,aAAa;IACxD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAE/B;;;;;OAKG;gBACS,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,YAAY;IAIhD;;;OAGG;IACG,YAAY,CAAC,EAAE,OAAO,EAAE,EAAE,yBAAyB;CAG1D"}
|
package/dist/Queue.d.ts
CHANGED
|
@@ -56,7 +56,7 @@ export interface QueueEntry {
|
|
|
56
56
|
* later. All parts of the storing and replaying process are observable via
|
|
57
57
|
* callbacks.
|
|
58
58
|
*/
|
|
59
|
-
declare class Queue {
|
|
59
|
+
export declare class Queue {
|
|
60
60
|
private readonly _name;
|
|
61
61
|
private readonly _onSync;
|
|
62
62
|
private readonly _maxRetentionTime;
|
|
@@ -94,16 +94,14 @@ declare class Queue {
|
|
|
94
94
|
unshiftRequest(entry: QueueEntry): Promise<void>;
|
|
95
95
|
/**
|
|
96
96
|
* Removes and returns the last request in the queue (along with its
|
|
97
|
-
* timestamp and any metadata).
|
|
98
|
-
* `{request, timestamp, metadata}`.
|
|
97
|
+
* timestamp and any metadata).
|
|
99
98
|
*
|
|
100
99
|
* @returns
|
|
101
100
|
*/
|
|
102
101
|
popRequest(): Promise<QueueEntry | undefined>;
|
|
103
102
|
/**
|
|
104
103
|
* Removes and returns the first request in the queue (along with its
|
|
105
|
-
* timestamp and any metadata).
|
|
106
|
-
* `{request, timestamp, metadata}`.
|
|
104
|
+
* timestamp and any metadata).
|
|
107
105
|
*
|
|
108
106
|
* @returns
|
|
109
107
|
*/
|
|
@@ -166,5 +164,5 @@ declare class Queue {
|
|
|
166
164
|
*/
|
|
167
165
|
static get _queueNames(): Set<string>;
|
|
168
166
|
}
|
|
169
|
-
export {
|
|
167
|
+
export {};
|
|
170
168
|
//# sourceMappingURL=Queue.d.ts.map
|
package/dist/Queue.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":"AAgBA,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,UAAU,cAAc;IACtB,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACxD;AAED,MAAM,WAAW,YAAY;IAC3B;;;;;;;OAOG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B;;;;;;;OAOG;IACH,MAAM,CAAC,EAAE,cAAc,CAAC;CACzB;AAED,MAAM,WAAW,UAAU;IACzB;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;;;;;OAMG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AA2BD;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../src/Queue.ts"],"names":[],"mappings":"AAgBA,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,UAAU,cAAc;IACtB,CAAC,OAAO,EAAE,qBAA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AAU,GAAG,SAAS,CAAC;IAIrD;;;;;OAKG;IACG,MAAM,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAmBrC;;;;;OAKG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B;;;;;;OAMG;IACG,WAAW,CAAC,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAsB,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC1H;;;;;;;OAOG;IACG,cAAc,CAAC,SAAS,EAAE,KAAK,GAAG,OAAO,GAAG,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IA0BjF;;;;OAIG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAuBrC;;OAEG;IACG,YAAY,IAAI,OAAO,CAAC,IAAI,CAAC;IAenC;;;;;;OAMG;IACH,OAAO,CAAC,gBAAgB;IAmDxB;;;;;;OAMG;IACH,MAAM,KAAK,WAAW,IAAI,GAAG,CAAC,MAAM,CAAC,CAEpC;CACF"}
|
|
@@ -11,7 +11,7 @@ export interface RequestData extends MapLikeObject {
|
|
|
11
11
|
* Most developers will not need to access this class directly;
|
|
12
12
|
* it is exposed for advanced use cases.
|
|
13
13
|
*/
|
|
14
|
-
declare class StorableRequest {
|
|
14
|
+
export declare class StorableRequest {
|
|
15
15
|
private readonly _requestData;
|
|
16
16
|
/**
|
|
17
17
|
* Converts a Request object to a plain object that can be structured
|
|
@@ -48,5 +48,4 @@ declare class StorableRequest {
|
|
|
48
48
|
*/
|
|
49
49
|
clone(): StorableRequest;
|
|
50
50
|
}
|
|
51
|
-
export { StorableRequest };
|
|
52
51
|
//# sourceMappingURL=StorableRequest.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StorableRequest.d.ts","sourceRoot":"","sources":["../src/StorableRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAiBnD,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;GAMG;AACH,
|
|
1
|
+
{"version":3,"file":"StorableRequest.d.ts","sourceRoot":"","sources":["../src/StorableRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAiBnD,MAAM,WAAW,WAAY,SAAQ,aAAa;IAChD,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,aAAa,CAAC;IACvB,IAAI,CAAC,EAAE,WAAW,CAAC;CACpB;AAED;;;;;;GAMG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAc;IAE3C;;;;;;OAMG;WACU,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC;IA6BpE;;;;;;OAMG;gBACS,WAAW,EAAE,WAAW;IAyBpC;;;;OAIG;IACH,QAAQ,IAAI,WAAW;IAUvB;;;;OAIG;IACH,SAAS,IAAI,OAAO;IAIpB;;;;OAIG;IACH,KAAK,IAAI,eAAe;CAGzB"}
|
package/dist/index.js
CHANGED
|
@@ -431,11 +431,11 @@ class BackgroundSyncPlugin {
|
|
|
431
431
|
constructor(name, options){
|
|
432
432
|
this._queue = new Queue(name, options);
|
|
433
433
|
}
|
|
434
|
-
|
|
434
|
+
async fetchDidFail({ request }) {
|
|
435
435
|
await this._queue.pushRequest({
|
|
436
436
|
request
|
|
437
437
|
});
|
|
438
|
-
}
|
|
438
|
+
}
|
|
439
439
|
}
|
|
440
440
|
|
|
441
441
|
export { BackgroundSyncPlugin, Queue, QueueStore, StorableRequest };
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/background-sync",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.11",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "
|
|
5
|
+
"description": "A module that queues failed requests and uses the Background Synchronization API to replay them when the network is available",
|
|
6
6
|
"files": [
|
|
7
7
|
"src",
|
|
8
8
|
"dist"
|
|
@@ -31,13 +31,13 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"idb": "8.0.0",
|
|
34
|
-
"@serwist/core": "9.0.0-preview.
|
|
34
|
+
"@serwist/core": "9.0.0-preview.11"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"cross-env": "7.0.3",
|
|
38
38
|
"rollup": "4.9.6",
|
|
39
|
-
"typescript": "5.4.0-dev.
|
|
40
|
-
"@serwist/constants": "9.0.0-preview.
|
|
39
|
+
"typescript": "5.4.0-dev.20240206",
|
|
40
|
+
"@serwist/constants": "9.0.0-preview.11"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"typescript": ">=5.0.0"
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
https://opensource.org/licenses/MIT.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import type { SerwistPlugin } from "@serwist/core";
|
|
9
|
+
import type { FetchDidFailCallbackParam, SerwistPlugin } from "@serwist/core";
|
|
10
10
|
|
|
11
11
|
import type { QueueOptions } from "./Queue.js";
|
|
12
12
|
import { Queue } from "./Queue.js";
|
|
@@ -15,7 +15,7 @@ import { Queue } from "./Queue.js";
|
|
|
15
15
|
* A class implementing the `fetchDidFail` lifecycle callback. This makes it
|
|
16
16
|
* easier to add failed requests to a background sync Queue.
|
|
17
17
|
*/
|
|
18
|
-
class BackgroundSyncPlugin implements SerwistPlugin {
|
|
18
|
+
export class BackgroundSyncPlugin implements SerwistPlugin {
|
|
19
19
|
private readonly _queue: Queue;
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -32,9 +32,7 @@ class BackgroundSyncPlugin implements SerwistPlugin {
|
|
|
32
32
|
* @param options
|
|
33
33
|
* @private
|
|
34
34
|
*/
|
|
35
|
-
|
|
35
|
+
async fetchDidFail({ request }: FetchDidFailCallbackParam) {
|
|
36
36
|
await this._queue.pushRequest({ request });
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
|
-
|
|
40
|
-
export { BackgroundSyncPlugin };
|
package/src/Queue.ts
CHANGED
|
@@ -101,7 +101,7 @@ const convertEntry = (queueStoreEntry: UnidentifiedQueueStoreEntry): QueueEntry
|
|
|
101
101
|
* later. All parts of the storing and replaying process are observable via
|
|
102
102
|
* callbacks.
|
|
103
103
|
*/
|
|
104
|
-
class Queue {
|
|
104
|
+
export class Queue {
|
|
105
105
|
private readonly _name: string;
|
|
106
106
|
private readonly _onSync: OnSyncCallback;
|
|
107
107
|
private readonly _maxRetentionTime: number;
|
|
@@ -194,8 +194,7 @@ class Queue {
|
|
|
194
194
|
|
|
195
195
|
/**
|
|
196
196
|
* Removes and returns the last request in the queue (along with its
|
|
197
|
-
* timestamp and any metadata).
|
|
198
|
-
* `{request, timestamp, metadata}`.
|
|
197
|
+
* timestamp and any metadata).
|
|
199
198
|
*
|
|
200
199
|
* @returns
|
|
201
200
|
*/
|
|
@@ -205,8 +204,7 @@ class Queue {
|
|
|
205
204
|
|
|
206
205
|
/**
|
|
207
206
|
* Removes and returns the first request in the queue (along with its
|
|
208
|
-
* timestamp and any metadata).
|
|
209
|
-
* `{request, timestamp, metadata}`.
|
|
207
|
+
* timestamp and any metadata).
|
|
210
208
|
*
|
|
211
209
|
* @returns
|
|
212
210
|
*/
|
|
@@ -440,5 +438,3 @@ class Queue {
|
|
|
440
438
|
return queueNames;
|
|
441
439
|
}
|
|
442
440
|
}
|
|
443
|
-
|
|
444
|
-
export { Queue };
|
package/src/StorableRequest.ts
CHANGED
|
@@ -36,7 +36,7 @@ export interface RequestData extends MapLikeObject {
|
|
|
36
36
|
* Most developers will not need to access this class directly;
|
|
37
37
|
* it is exposed for advanced use cases.
|
|
38
38
|
*/
|
|
39
|
-
class StorableRequest {
|
|
39
|
+
export class StorableRequest {
|
|
40
40
|
private readonly _requestData: RequestData;
|
|
41
41
|
|
|
42
42
|
/**
|
|
@@ -140,5 +140,3 @@ class StorableRequest {
|
|
|
140
140
|
return new StorableRequest(this.toObject());
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
|
-
|
|
144
|
-
export { StorableRequest };
|