serwist 9.0.0-preview.24
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/LICENSE +21 -0
- package/README.md +1 -0
- package/dist/NavigationRoute.d.ts +57 -0
- package/dist/NavigationRoute.d.ts.map +1 -0
- package/dist/PrecacheRoute.d.ts +17 -0
- package/dist/PrecacheRoute.d.ts.map +1 -0
- package/dist/PrecacheStrategy.d.ts +66 -0
- package/dist/PrecacheStrategy.d.ts.map +1 -0
- package/dist/RegExpRoute.d.ts +24 -0
- package/dist/RegExpRoute.d.ts.map +1 -0
- package/dist/Route.d.ts +33 -0
- package/dist/Route.d.ts.map +1 -0
- package/dist/Serwist.d.ts +331 -0
- package/dist/Serwist.d.ts.map +1 -0
- package/dist/cacheNames.d.ts +20 -0
- package/dist/cacheNames.d.ts.map +1 -0
- package/dist/chunks/NetworkOnly.js +599 -0
- package/dist/chunks/PrecacheFallbackPlugin.js +634 -0
- package/dist/chunks/Serwist.js +1034 -0
- package/dist/chunks/registerQuotaErrorCallback.js +17 -0
- package/dist/chunks/resultingClientExists.js +32 -0
- package/dist/chunks/timeout.js +400 -0
- package/dist/chunks/waitUntil.js +24 -0
- package/dist/cleanupOutdatedCaches.d.ts +6 -0
- package/dist/cleanupOutdatedCaches.d.ts.map +1 -0
- package/dist/clientsClaim.d.ts +6 -0
- package/dist/clientsClaim.d.ts.map +1 -0
- package/dist/constants.d.ts +15 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/copyResponse.d.ts +20 -0
- package/dist/copyResponse.d.ts.map +1 -0
- package/dist/disableDevLogs.d.ts +7 -0
- package/dist/disableDevLogs.d.ts.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.internal.d.ts +16 -0
- package/dist/index.internal.d.ts.map +1 -0
- package/dist/index.internal.js +24 -0
- package/dist/index.js +27 -0
- package/dist/index.legacy.d.ts +32 -0
- package/dist/index.legacy.d.ts.map +1 -0
- package/dist/index.legacy.js +640 -0
- package/dist/index.plugins.d.ts +41 -0
- package/dist/index.plugins.d.ts.map +1 -0
- package/dist/index.plugins.js +669 -0
- package/dist/index.strategies.d.ts +22 -0
- package/dist/index.strategies.d.ts.map +1 -0
- package/dist/index.strategies.js +144 -0
- package/dist/legacy/PrecacheController.d.ts +146 -0
- package/dist/legacy/PrecacheController.d.ts.map +1 -0
- package/dist/legacy/PrecacheFallbackPlugin.d.ts +62 -0
- package/dist/legacy/PrecacheFallbackPlugin.d.ts.map +1 -0
- package/dist/legacy/PrecacheRoute.d.ts +19 -0
- package/dist/legacy/PrecacheRoute.d.ts.map +1 -0
- package/dist/legacy/Router.d.ts +151 -0
- package/dist/legacy/Router.d.ts.map +1 -0
- package/dist/legacy/addPlugins.d.ts +9 -0
- package/dist/legacy/addPlugins.d.ts.map +1 -0
- package/dist/legacy/addRoute.d.ts +16 -0
- package/dist/legacy/addRoute.d.ts.map +1 -0
- package/dist/legacy/createHandlerBoundToURL.d.ts +18 -0
- package/dist/legacy/createHandlerBoundToURL.d.ts.map +1 -0
- package/dist/legacy/fallbacks.d.ts +59 -0
- package/dist/legacy/fallbacks.d.ts.map +1 -0
- package/dist/legacy/getCacheKeyForURL.d.ts +20 -0
- package/dist/legacy/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/legacy/handlePrecaching.d.ts +54 -0
- package/dist/legacy/handlePrecaching.d.ts.map +1 -0
- package/dist/legacy/installSerwist.d.ts +15 -0
- package/dist/legacy/installSerwist.d.ts.map +1 -0
- package/dist/legacy/matchPrecache.d.ts +15 -0
- package/dist/legacy/matchPrecache.d.ts.map +1 -0
- package/dist/legacy/precache.d.ts +20 -0
- package/dist/legacy/precache.d.ts.map +1 -0
- package/dist/legacy/precacheAndRoute.d.ts +15 -0
- package/dist/legacy/precacheAndRoute.d.ts.map +1 -0
- package/dist/legacy/registerRoute.d.ts +16 -0
- package/dist/legacy/registerRoute.d.ts.map +1 -0
- package/dist/legacy/registerRuntimeCaching.d.ts +11 -0
- package/dist/legacy/registerRuntimeCaching.d.ts.map +1 -0
- package/dist/legacy/setCatchHandler.d.ts +10 -0
- package/dist/legacy/setCatchHandler.d.ts.map +1 -0
- package/dist/legacy/setDefaultHandler.d.ts +13 -0
- package/dist/legacy/setDefaultHandler.d.ts.map +1 -0
- package/dist/legacy/singletonPrecacheController.d.ts +34 -0
- package/dist/legacy/singletonPrecacheController.d.ts.map +1 -0
- package/dist/legacy/singletonRouter.d.ts +41 -0
- package/dist/legacy/singletonRouter.d.ts.map +1 -0
- package/dist/legacy/unregisterRoute.d.ts +9 -0
- package/dist/legacy/unregisterRoute.d.ts.map +1 -0
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts +16 -0
- package/dist/legacy/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/legacy/utils/getCacheKeyForURL.d.ts +14 -0
- package/dist/legacy/utils/getCacheKeyForURL.d.ts.map +1 -0
- package/dist/models/messages/messageGenerator.d.ts +4 -0
- package/dist/models/messages/messageGenerator.d.ts.map +1 -0
- package/dist/models/messages/messages.d.ts +44 -0
- package/dist/models/messages/messages.d.ts.map +1 -0
- package/dist/models/pluginEvents.d.ts +10 -0
- package/dist/models/pluginEvents.d.ts.map +1 -0
- package/dist/models/quotaErrorCallbacks.d.ts +3 -0
- package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
- package/dist/navigationPreload.d.ts +24 -0
- package/dist/navigationPreload.d.ts.map +1 -0
- package/dist/parseRoute.d.ts +16 -0
- package/dist/parseRoute.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts +23 -0
- package/dist/plugins/backgroundSync/BackgroundSyncPlugin.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/Queue.d.ts +166 -0
- package/dist/plugins/backgroundSync/Queue.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/QueueDb.d.ts +90 -0
- package/dist/plugins/backgroundSync/QueueDb.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/QueueStore.d.ts +75 -0
- package/dist/plugins/backgroundSync/QueueStore.d.ts.map +1 -0
- package/dist/plugins/backgroundSync/StorableRequest.d.ts +51 -0
- package/dist/plugins/backgroundSync/StorableRequest.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts +45 -0
- package/dist/plugins/broadcastUpdate/BroadcastCacheUpdate.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts +27 -0
- package/dist/plugins/broadcastUpdate/BroadcastUpdatePlugin.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/constants.d.ts +5 -0
- package/dist/plugins/broadcastUpdate/constants.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts +11 -0
- package/dist/plugins/broadcastUpdate/responsesAreSame.d.ts.map +1 -0
- package/dist/plugins/broadcastUpdate/types.d.ts +34 -0
- package/dist/plugins/broadcastUpdate/types.d.ts.map +1 -0
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts +40 -0
- package/dist/plugins/cacheableResponse/CacheableResponse.d.ts.map +1 -0
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts +27 -0
- package/dist/plugins/cacheableResponse/CacheableResponsePlugin.d.ts.map +1 -0
- package/dist/plugins/expiration/CacheExpiration.d.ts +66 -0
- package/dist/plugins/expiration/CacheExpiration.d.ts.map +1 -0
- package/dist/plugins/expiration/ExpirationPlugin.d.ts +116 -0
- package/dist/plugins/expiration/ExpirationPlugin.d.ts.map +1 -0
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts +73 -0
- package/dist/plugins/expiration/models/CacheTimestampsModel.d.ts.map +1 -0
- package/dist/plugins/googleAnalytics/constants.d.ts +10 -0
- package/dist/plugins/googleAnalytics/constants.d.ts.map +1 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts +30 -0
- package/dist/plugins/googleAnalytics/initialize.d.ts.map +1 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts +53 -0
- package/dist/plugins/precaching/PrecacheFallbackPlugin.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts +19 -0
- package/dist/plugins/rangeRequests/RangeRequestsPlugin.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts +18 -0
- package/dist/plugins/rangeRequests/createPartialResponse.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts +14 -0
- package/dist/plugins/rangeRequests/utils/calculateEffectiveBoundaries.d.ts.map +1 -0
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts +12 -0
- package/dist/plugins/rangeRequests/utils/parseRangeHeader.d.ts.map +1 -0
- package/dist/registerQuotaErrorCallback.d.ts +8 -0
- package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
- package/dist/setCacheNameDetails.d.ts +9 -0
- package/dist/setCacheNameDetails.d.ts.map +1 -0
- package/dist/strategies/CacheFirst.d.ts +23 -0
- package/dist/strategies/CacheFirst.d.ts.map +1 -0
- package/dist/strategies/CacheOnly.d.ts +20 -0
- package/dist/strategies/CacheOnly.d.ts.map +1 -0
- package/dist/strategies/NetworkFirst.d.ts +61 -0
- package/dist/strategies/NetworkFirst.d.ts.map +1 -0
- package/dist/strategies/NetworkOnly.d.ts +32 -0
- package/dist/strategies/NetworkOnly.d.ts.map +1 -0
- package/dist/strategies/StaleWhileRevalidate.d.ts +35 -0
- package/dist/strategies/StaleWhileRevalidate.d.ts.map +1 -0
- package/dist/strategies/Strategy.d.ts +83 -0
- package/dist/strategies/Strategy.d.ts.map +1 -0
- package/dist/strategies/StrategyHandler.d.ts +189 -0
- package/dist/strategies/StrategyHandler.d.ts.map +1 -0
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts +3 -0
- package/dist/strategies/plugins/cacheOkAndOpaquePlugin.d.ts.map +1 -0
- package/dist/strategies/utils/messages.d.ts +5 -0
- package/dist/strategies/utils/messages.d.ts.map +1 -0
- package/dist/types.d.ts +317 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/Deferred.d.ts +19 -0
- package/dist/utils/Deferred.d.ts.map +1 -0
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts +16 -0
- package/dist/utils/PrecacheCacheKeyPlugin.d.ts.map +1 -0
- package/dist/utils/PrecacheInstallReportPlugin.d.ts +14 -0
- package/dist/utils/PrecacheInstallReportPlugin.d.ts.map +1 -0
- package/dist/utils/SerwistError.d.ts +24 -0
- package/dist/utils/SerwistError.d.ts.map +1 -0
- package/dist/utils/assert.d.ts +11 -0
- package/dist/utils/assert.d.ts.map +1 -0
- package/dist/utils/cacheMatchIgnoreParams.d.ts +15 -0
- package/dist/utils/cacheMatchIgnoreParams.d.ts.map +1 -0
- package/dist/utils/cacheNames.d.ts +40 -0
- package/dist/utils/cacheNames.d.ts.map +1 -0
- package/dist/utils/canConstructReadableStream.d.ts +12 -0
- package/dist/utils/canConstructReadableStream.d.ts.map +1 -0
- package/dist/utils/canConstructResponseFromBodyStream.d.ts +11 -0
- package/dist/utils/canConstructResponseFromBodyStream.d.ts.map +1 -0
- package/dist/utils/createCacheKey.d.ts +16 -0
- package/dist/utils/createCacheKey.d.ts.map +1 -0
- package/dist/utils/deleteOutdatedCaches.d.ts +18 -0
- package/dist/utils/deleteOutdatedCaches.d.ts.map +1 -0
- package/dist/utils/dontWaitFor.d.ts +7 -0
- package/dist/utils/dontWaitFor.d.ts.map +1 -0
- package/dist/utils/executeQuotaErrorCallbacks.d.ts +8 -0
- package/dist/utils/executeQuotaErrorCallbacks.d.ts.map +1 -0
- package/dist/utils/generateURLVariations.d.ts +12 -0
- package/dist/utils/generateURLVariations.d.ts.map +1 -0
- package/dist/utils/getFriendlyURL.d.ts +3 -0
- package/dist/utils/getFriendlyURL.d.ts.map +1 -0
- package/dist/utils/logger.d.ts +24 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/normalizeHandler.d.ts +10 -0
- package/dist/utils/normalizeHandler.d.ts.map +1 -0
- package/dist/utils/pluginUtils.d.ts +5 -0
- package/dist/utils/pluginUtils.d.ts.map +1 -0
- package/dist/utils/printCleanupDetails.d.ts +6 -0
- package/dist/utils/printCleanupDetails.d.ts.map +1 -0
- package/dist/utils/printInstallDetails.d.ts +7 -0
- package/dist/utils/printInstallDetails.d.ts.map +1 -0
- package/dist/utils/removeIgnoredSearchParams.d.ts +12 -0
- package/dist/utils/removeIgnoredSearchParams.d.ts.map +1 -0
- package/dist/utils/resultingClientExists.d.ts +12 -0
- package/dist/utils/resultingClientExists.d.ts.map +1 -0
- package/dist/utils/timeout.d.ts +10 -0
- package/dist/utils/timeout.d.ts.map +1 -0
- package/dist/utils/waitUntil.d.ts +11 -0
- package/dist/utils/waitUntil.d.ts.map +1 -0
- package/dist/utils/welcome.d.ts +2 -0
- package/dist/utils/welcome.d.ts.map +1 -0
- package/package.json +85 -0
- package/src/NavigationRoute.ts +119 -0
- package/src/PrecacheRoute.ts +46 -0
- package/src/PrecacheStrategy.ts +239 -0
- package/src/RegExpRoute.ts +74 -0
- package/src/Route.ts +67 -0
- package/src/Serwist.ts +920 -0
- package/src/cacheNames.ts +39 -0
- package/src/cleanupOutdatedCaches.ts +32 -0
- package/src/clientsClaim.ts +18 -0
- package/src/constants.ts +24 -0
- package/src/copyResponse.ts +60 -0
- package/src/disableDevLogs.ts +10 -0
- package/src/index.internal.ts +33 -0
- package/src/index.legacy.ts +66 -0
- package/src/index.plugins.ts +95 -0
- package/src/index.strategies.ts +26 -0
- package/src/index.ts +39 -0
- package/src/legacy/PrecacheController.ts +337 -0
- package/src/legacy/PrecacheFallbackPlugin.ts +93 -0
- package/src/legacy/PrecacheRoute.ts +48 -0
- package/src/legacy/Router.ts +484 -0
- package/src/legacy/addPlugins.ts +21 -0
- package/src/legacy/addRoute.ts +29 -0
- package/src/legacy/createHandlerBoundToURL.ts +30 -0
- package/src/legacy/fallbacks.ts +94 -0
- package/src/legacy/getCacheKeyForURL.ts +32 -0
- package/src/legacy/handlePrecaching.ts +86 -0
- package/src/legacy/installSerwist.ts +19 -0
- package/src/legacy/matchPrecache.ts +26 -0
- package/src/legacy/precache.ts +31 -0
- package/src/legacy/precacheAndRoute.ts +28 -0
- package/src/legacy/registerRoute.ts +27 -0
- package/src/legacy/registerRuntimeCaching.ts +17 -0
- package/src/legacy/setCatchHandler.ts +21 -0
- package/src/legacy/setDefaultHandler.ts +24 -0
- package/src/legacy/singletonPrecacheController.ts +53 -0
- package/src/legacy/singletonRouter.ts +70 -0
- package/src/legacy/unregisterRoute.ts +12 -0
- package/src/legacy/utils/PrecacheCacheKeyPlugin.ts +33 -0
- package/src/legacy/utils/getCacheKeyForURL.ts +36 -0
- package/src/models/messages/messageGenerator.ts +29 -0
- package/src/models/messages/messages.ts +233 -0
- package/src/models/pluginEvents.ts +17 -0
- package/src/models/quotaErrorCallbacks.ts +13 -0
- package/src/navigationPreload.ts +68 -0
- package/src/parseRoute.ts +78 -0
- package/src/plugins/backgroundSync/BackgroundSyncPlugin.ts +38 -0
- package/src/plugins/backgroundSync/Queue.ts +440 -0
- package/src/plugins/backgroundSync/QueueDb.ts +176 -0
- package/src/plugins/backgroundSync/QueueStore.ts +160 -0
- package/src/plugins/backgroundSync/StorableRequest.ts +142 -0
- package/src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts +161 -0
- package/src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts +42 -0
- package/src/plugins/broadcastUpdate/constants.ts +12 -0
- package/src/plugins/broadcastUpdate/responsesAreSame.ts +49 -0
- package/src/plugins/broadcastUpdate/types.ts +37 -0
- package/src/plugins/cacheableResponse/CacheableResponse.ts +144 -0
- package/src/plugins/cacheableResponse/CacheableResponsePlugin.ts +45 -0
- package/src/plugins/expiration/CacheExpiration.ts +193 -0
- package/src/plugins/expiration/ExpirationPlugin.ts +300 -0
- package/src/plugins/expiration/models/CacheTimestampsModel.ts +184 -0
- package/src/plugins/googleAnalytics/constants.ts +22 -0
- package/src/plugins/googleAnalytics/initialize.ts +209 -0
- package/src/plugins/precaching/PrecacheFallbackPlugin.ts +83 -0
- package/src/plugins/rangeRequests/RangeRequestsPlugin.ts +38 -0
- package/src/plugins/rangeRequests/createPartialResponse.ts +93 -0
- package/src/plugins/rangeRequests/utils/calculateEffectiveBoundaries.ts +59 -0
- package/src/plugins/rangeRequests/utils/parseRangeHeader.ts +55 -0
- package/src/registerQuotaErrorCallback.ts +34 -0
- package/src/setCacheNameDetails.ts +53 -0
- package/src/strategies/CacheFirst.ts +88 -0
- package/src/strategies/CacheOnly.ts +59 -0
- package/src/strategies/NetworkFirst.ts +229 -0
- package/src/strategies/NetworkOnly.ts +98 -0
- package/src/strategies/StaleWhileRevalidate.ts +110 -0
- package/src/strategies/Strategy.ts +204 -0
- package/src/strategies/StrategyHandler.ts +554 -0
- package/src/strategies/plugins/cacheOkAndOpaquePlugin.ts +26 -0
- package/src/strategies/utils/messages.ts +21 -0
- package/src/types.ts +358 -0
- package/src/utils/Deferred.ts +33 -0
- package/src/utils/PrecacheCacheKeyPlugin.ts +33 -0
- package/src/utils/PrecacheInstallReportPlugin.ts +47 -0
- package/src/utils/SerwistError.ts +41 -0
- package/src/utils/assert.ts +89 -0
- package/src/utils/cacheMatchIgnoreParams.ts +54 -0
- package/src/utils/cacheNames.ts +87 -0
- package/src/utils/canConstructReadableStream.ts +34 -0
- package/src/utils/canConstructResponseFromBodyStream.ts +37 -0
- package/src/utils/createCacheKey.ts +68 -0
- package/src/utils/deleteOutdatedCaches.ts +40 -0
- package/src/utils/dontWaitFor.ts +16 -0
- package/src/utils/executeQuotaErrorCallbacks.ts +33 -0
- package/src/utils/generateURLVariations.ts +55 -0
- package/src/utils/getFriendlyURL.ts +16 -0
- package/src/utils/logger.ts +95 -0
- package/src/utils/normalizeHandler.ts +40 -0
- package/src/utils/pluginUtils.ts +15 -0
- package/src/utils/printCleanupDetails.ts +38 -0
- package/src/utils/printInstallDetails.ts +53 -0
- package/src/utils/removeIgnoredSearchParams.ts +29 -0
- package/src/utils/resultingClientExists.ts +58 -0
- package/src/utils/timeout.ts +19 -0
- package/src/utils/waitUntil.ts +21 -0
- package/src/utils/welcome.ts +19 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
interface OnSyncCallbackOptions {
|
|
2
|
+
queue: Queue;
|
|
3
|
+
}
|
|
4
|
+
type OnSyncCallback = (options: OnSyncCallbackOptions) => void | Promise<void>;
|
|
5
|
+
export interface QueueOptions {
|
|
6
|
+
/**
|
|
7
|
+
* If `true`, instead of attempting to use background sync events, always attempt
|
|
8
|
+
* to replay queued request at service worker startup. Most folks will not need
|
|
9
|
+
* this, unless you explicitly target a runtime like Electron that exposes the
|
|
10
|
+
* interfaces for background sync, but does not have a working implementation.
|
|
11
|
+
*
|
|
12
|
+
* @default false
|
|
13
|
+
*/
|
|
14
|
+
forceSyncFallback?: boolean;
|
|
15
|
+
/**
|
|
16
|
+
* The amount of time (in minutes) a request may be retried. After this amount
|
|
17
|
+
* of time has passed, the request will be deleted from the queue.
|
|
18
|
+
*
|
|
19
|
+
* @default 60 * 24 * 7
|
|
20
|
+
*/
|
|
21
|
+
maxRetentionTime?: number;
|
|
22
|
+
/**
|
|
23
|
+
* A function that gets invoked whenever the 'sync' event fires. The function
|
|
24
|
+
* is invoked with an object containing the `queue` property (referencing this
|
|
25
|
+
* instance), and you can use the callback to customize the replay behavior of
|
|
26
|
+
* the queue. When not set the `replayRequests()` method is called. Note: if the
|
|
27
|
+
* replay fails after a sync event, make sure you throw an error, so the browser
|
|
28
|
+
* knows to retry the sync event later.
|
|
29
|
+
*/
|
|
30
|
+
onSync?: OnSyncCallback;
|
|
31
|
+
}
|
|
32
|
+
export interface QueueEntry {
|
|
33
|
+
/**
|
|
34
|
+
* The request to store in the queue.
|
|
35
|
+
*/
|
|
36
|
+
request: Request;
|
|
37
|
+
/**
|
|
38
|
+
* The timestamp (Epoch time in milliseconds) when the request was first added
|
|
39
|
+
* to the queue. This is used along with `maxRetentionTime` to remove outdated
|
|
40
|
+
* requests. In general you don't need to set this value, as it's automatically
|
|
41
|
+
* set for you (defaulting to `Date.now()`), but you can update it if you don't
|
|
42
|
+
* want particular requests to expire.
|
|
43
|
+
*/
|
|
44
|
+
timestamp?: number;
|
|
45
|
+
/**
|
|
46
|
+
* Any metadata you want associated with the stored request. When requests are
|
|
47
|
+
* replayed you'll have access to this metadata object in case you need to modify
|
|
48
|
+
* the request beforehand.
|
|
49
|
+
*/
|
|
50
|
+
metadata?: Record<string, unknown>;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* A class to manage storing failed requests in IndexedDB and retrying them
|
|
54
|
+
* later. All parts of the storing and replaying process are observable via
|
|
55
|
+
* callbacks.
|
|
56
|
+
*/
|
|
57
|
+
export declare class Queue {
|
|
58
|
+
private readonly _name;
|
|
59
|
+
private readonly _onSync;
|
|
60
|
+
private readonly _maxRetentionTime;
|
|
61
|
+
private readonly _queueStore;
|
|
62
|
+
private readonly _forceSyncFallback;
|
|
63
|
+
private _syncInProgress;
|
|
64
|
+
private _requestsAddedDuringSync;
|
|
65
|
+
/**
|
|
66
|
+
* Creates an instance of Queue with the given options
|
|
67
|
+
*
|
|
68
|
+
* @param name The unique name for this queue. This name must be
|
|
69
|
+
* unique as it's used to register sync events and store requests
|
|
70
|
+
* in IndexedDB specific to this instance. An error will be thrown if
|
|
71
|
+
* a duplicate name is detected.
|
|
72
|
+
* @param options
|
|
73
|
+
*/
|
|
74
|
+
constructor(name: string, { forceSyncFallback, onSync, maxRetentionTime }?: QueueOptions);
|
|
75
|
+
/**
|
|
76
|
+
* @returns
|
|
77
|
+
*/
|
|
78
|
+
get name(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Stores the passed request in IndexedDB (with its timestamp and any
|
|
81
|
+
* metadata) at the end of the queue.
|
|
82
|
+
*
|
|
83
|
+
* @param entry
|
|
84
|
+
*/
|
|
85
|
+
pushRequest(entry: QueueEntry): Promise<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Stores the passed request in IndexedDB (with its timestamp and any
|
|
88
|
+
* metadata) at the beginning of the queue.
|
|
89
|
+
*
|
|
90
|
+
* @param entry
|
|
91
|
+
*/
|
|
92
|
+
unshiftRequest(entry: QueueEntry): Promise<void>;
|
|
93
|
+
/**
|
|
94
|
+
* Removes and returns the last request in the queue (along with its
|
|
95
|
+
* timestamp and any metadata).
|
|
96
|
+
*
|
|
97
|
+
* @returns
|
|
98
|
+
*/
|
|
99
|
+
popRequest(): Promise<QueueEntry | undefined>;
|
|
100
|
+
/**
|
|
101
|
+
* Removes and returns the first request in the queue (along with its
|
|
102
|
+
* timestamp and any metadata).
|
|
103
|
+
*
|
|
104
|
+
* @returns
|
|
105
|
+
*/
|
|
106
|
+
shiftRequest(): Promise<QueueEntry | undefined>;
|
|
107
|
+
/**
|
|
108
|
+
* Returns all the entries that have not expired (per `maxRetentionTime`).
|
|
109
|
+
* Any expired entries are removed from the queue.
|
|
110
|
+
*
|
|
111
|
+
* @returns
|
|
112
|
+
*/
|
|
113
|
+
getAll(): Promise<QueueEntry[]>;
|
|
114
|
+
/**
|
|
115
|
+
* Returns the number of entries present in the queue.
|
|
116
|
+
* Note that expired entries (per `maxRetentionTime`) are also included in this count.
|
|
117
|
+
*
|
|
118
|
+
* @returns
|
|
119
|
+
*/
|
|
120
|
+
size(): Promise<number>;
|
|
121
|
+
/**
|
|
122
|
+
* Adds the entry to the QueueStore and registers for a sync event.
|
|
123
|
+
*
|
|
124
|
+
* @param entry
|
|
125
|
+
* @param operation
|
|
126
|
+
* @private
|
|
127
|
+
*/
|
|
128
|
+
_addRequest({ request, metadata, timestamp }: QueueEntry, operation: "push" | "unshift"): Promise<void>;
|
|
129
|
+
/**
|
|
130
|
+
* Removes and returns the first or last (depending on `operation`) entry
|
|
131
|
+
* from the QueueStore that's not older than the `maxRetentionTime`.
|
|
132
|
+
*
|
|
133
|
+
* @param operation
|
|
134
|
+
* @returns
|
|
135
|
+
* @private
|
|
136
|
+
*/
|
|
137
|
+
_removeRequest(operation: "pop" | "shift"): Promise<QueueEntry | undefined>;
|
|
138
|
+
/**
|
|
139
|
+
* Loops through each request in the queue and attempts to re-fetch it.
|
|
140
|
+
* If any request fails to re-fetch, it's put back in the same position in
|
|
141
|
+
* the queue (which registers a retry for the next sync event).
|
|
142
|
+
*/
|
|
143
|
+
replayRequests(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Registers a sync event with a tag unique to this instance.
|
|
146
|
+
*/
|
|
147
|
+
registerSync(): Promise<void>;
|
|
148
|
+
/**
|
|
149
|
+
* In sync-supporting browsers, this adds a listener for the sync event.
|
|
150
|
+
* In non-sync-supporting browsers, or if _forceSyncFallback is true, this
|
|
151
|
+
* will retry the queue on service worker startup.
|
|
152
|
+
*
|
|
153
|
+
* @private
|
|
154
|
+
*/
|
|
155
|
+
private _addSyncListener;
|
|
156
|
+
/**
|
|
157
|
+
* Returns the set of queue names. This is primarily used to reset the list
|
|
158
|
+
* of queue names in tests.
|
|
159
|
+
*
|
|
160
|
+
* @returns
|
|
161
|
+
* @private
|
|
162
|
+
*/
|
|
163
|
+
static get _queueNames(): Set<string>;
|
|
164
|
+
}
|
|
165
|
+
export {};
|
|
166
|
+
//# sourceMappingURL=Queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Queue.d.ts","sourceRoot":"","sources":["../../../src/plugins/backgroundSync/Queue.ts"],"names":[],"mappings":"AAkBA,UAAU,qBAAqB;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;AAED,KAAK,cAAc,GAAG,CAAC,OAAO,EAAE,qBAAqB,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAE/E,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,qBAAa,KAAK;IAChB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAS;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiB;IACzC,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAa;IACzC,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAU;IAC7C,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,wBAAwB,CAAS;IAEzC;;;;;;;;OAQG;gBACS,IAAI,EAAE,MAAM,EAAE,EAAE,iBAAiB,EAAE,MAAM,EAAE,gBAAgB,EAAE,GAAE,YAAiB;IAgB5F;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;;;OAKG;IACG,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBnD;;;;;OAKG;IACG,cAAc,CAAC,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAmBtD;;;;;OAKG;IACG,UAAU,IAAI,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC;IAInD;;;;;OAKG;IACG,YAAY,IAAI,OAAO,CAAC,UAAU,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"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { RequestData } from "./StorableRequest.js";
|
|
2
|
+
export interface UnidentifiedQueueStoreEntry {
|
|
3
|
+
requestData: RequestData;
|
|
4
|
+
timestamp: number;
|
|
5
|
+
id?: number;
|
|
6
|
+
queueName?: string;
|
|
7
|
+
metadata?: Record<string, unknown>;
|
|
8
|
+
}
|
|
9
|
+
export interface QueueStoreEntry extends UnidentifiedQueueStoreEntry {
|
|
10
|
+
id: number;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* A class to interact directly an IndexedDB created specifically to save and
|
|
14
|
+
* retrieve QueueStoreEntries. This class encapsulates all the schema details
|
|
15
|
+
* to store the representation of a Queue.
|
|
16
|
+
*
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
export declare class QueueDb {
|
|
20
|
+
private _db;
|
|
21
|
+
/**
|
|
22
|
+
* Add QueueStoreEntry to underlying db.
|
|
23
|
+
*
|
|
24
|
+
* @param entry
|
|
25
|
+
*/
|
|
26
|
+
addEntry(entry: UnidentifiedQueueStoreEntry): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Returns the first entry id in the ObjectStore.
|
|
29
|
+
*
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getFirstEntryId(): Promise<number | undefined>;
|
|
33
|
+
/**
|
|
34
|
+
* Get all the entries filtered by index
|
|
35
|
+
*
|
|
36
|
+
* @param queueName
|
|
37
|
+
* @returns
|
|
38
|
+
*/
|
|
39
|
+
getAllEntriesByQueueName(queueName: string): Promise<QueueStoreEntry[]>;
|
|
40
|
+
/**
|
|
41
|
+
* Returns the number of entries filtered by index
|
|
42
|
+
*
|
|
43
|
+
* @param queueName
|
|
44
|
+
* @returns
|
|
45
|
+
*/
|
|
46
|
+
getEntryCountByQueueName(queueName: string): Promise<number>;
|
|
47
|
+
/**
|
|
48
|
+
* Deletes a single entry by id.
|
|
49
|
+
*
|
|
50
|
+
* @param id the id of the entry to be deleted
|
|
51
|
+
*/
|
|
52
|
+
deleteEntry(id: number): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param queueName
|
|
56
|
+
* @returns
|
|
57
|
+
*/
|
|
58
|
+
getFirstEntryByQueueName(queueName: string): Promise<QueueStoreEntry | undefined>;
|
|
59
|
+
/**
|
|
60
|
+
*
|
|
61
|
+
* @param queueName
|
|
62
|
+
* @returns
|
|
63
|
+
*/
|
|
64
|
+
getLastEntryByQueueName(queueName: string): Promise<QueueStoreEntry | undefined>;
|
|
65
|
+
/**
|
|
66
|
+
* Returns either the first or the last entries, depending on direction.
|
|
67
|
+
* Filtered by index.
|
|
68
|
+
*
|
|
69
|
+
* @param direction
|
|
70
|
+
* @param query
|
|
71
|
+
* @returns
|
|
72
|
+
* @private
|
|
73
|
+
*/
|
|
74
|
+
getEndEntryFromIndex(query: IDBKeyRange, direction: IDBCursorDirection): Promise<QueueStoreEntry | undefined>;
|
|
75
|
+
/**
|
|
76
|
+
* Returns an open connection to the database.
|
|
77
|
+
*
|
|
78
|
+
* @private
|
|
79
|
+
*/
|
|
80
|
+
private getDb;
|
|
81
|
+
/**
|
|
82
|
+
* Upgrades QueueDB
|
|
83
|
+
*
|
|
84
|
+
* @param db
|
|
85
|
+
* @param oldVersion
|
|
86
|
+
* @private
|
|
87
|
+
*/
|
|
88
|
+
private _upgradeDb;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=QueueDb.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueueDb.d.ts","sourceRoot":"","sources":["../../../src/plugins/backgroundSync/QueueDb.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAexD,MAAM,WAAW,2BAA2B;IAC1C,WAAW,EAAE,WAAW,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,eAAgB,SAAQ,2BAA2B;IAClE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;GAMG;AAEH,qBAAa,OAAO;IAClB,OAAO,CAAC,GAAG,CAA4C;IAEvD;;;;OAIG;IACG,QAAQ,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IASjE;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IAMpD;;;;;OAKG;IACG,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;IAM7E;;;;;OAKG;IACG,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAKlE;;;;OAIG;IACG,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAK5C;;;;OAIG;IACG,wBAAwB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAIvF;;;;OAIG;IACG,uBAAuB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAItF;;;;;;;;OAQG;IACG,oBAAoB,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAOnH;;;;OAIG;YACW,KAAK;IASnB;;;;;;OAMG;IACH,OAAO,CAAC,UAAU;CAanB"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import type { QueueStoreEntry, UnidentifiedQueueStoreEntry } from "./QueueDb.js";
|
|
2
|
+
/**
|
|
3
|
+
* A class to manage storing requests from a Queue in IndexedDB,
|
|
4
|
+
* indexed by their queue name for easier access.
|
|
5
|
+
*
|
|
6
|
+
* Most developers will not need to access this class directly;
|
|
7
|
+
* it is exposed for advanced use cases.
|
|
8
|
+
*/
|
|
9
|
+
export declare class QueueStore {
|
|
10
|
+
private readonly _queueName;
|
|
11
|
+
private readonly _queueDb;
|
|
12
|
+
/**
|
|
13
|
+
* Associates this instance with a Queue instance, so entries added can be
|
|
14
|
+
* identified by their queue name.
|
|
15
|
+
*
|
|
16
|
+
* @param queueName
|
|
17
|
+
*/
|
|
18
|
+
constructor(queueName: string);
|
|
19
|
+
/**
|
|
20
|
+
* Append an entry last in the queue.
|
|
21
|
+
*
|
|
22
|
+
* @param entry
|
|
23
|
+
*/
|
|
24
|
+
pushEntry(entry: UnidentifiedQueueStoreEntry): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Prepend an entry first in the queue.
|
|
27
|
+
*
|
|
28
|
+
* @param entry
|
|
29
|
+
*/
|
|
30
|
+
unshiftEntry(entry: UnidentifiedQueueStoreEntry): Promise<void>;
|
|
31
|
+
/**
|
|
32
|
+
* Removes and returns the last entry in the queue matching the `queueName`.
|
|
33
|
+
*
|
|
34
|
+
* @returns
|
|
35
|
+
*/
|
|
36
|
+
popEntry(): Promise<QueueStoreEntry | undefined>;
|
|
37
|
+
/**
|
|
38
|
+
* Removes and returns the first entry in the queue matching the `queueName`.
|
|
39
|
+
*
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
shiftEntry(): Promise<QueueStoreEntry | undefined>;
|
|
43
|
+
/**
|
|
44
|
+
* Returns all entries in the store matching the `queueName`.
|
|
45
|
+
*
|
|
46
|
+
* @returns
|
|
47
|
+
*/
|
|
48
|
+
getAll(): Promise<QueueStoreEntry[]>;
|
|
49
|
+
/**
|
|
50
|
+
* Returns the number of entries in the store matching the `queueName`.
|
|
51
|
+
*
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
size(): Promise<number>;
|
|
55
|
+
/**
|
|
56
|
+
* Deletes the entry for the given ID.
|
|
57
|
+
*
|
|
58
|
+
* WARNING: this method does not ensure the deleted entry belongs to this
|
|
59
|
+
* queue (i.e. matches the `queueName`). But this limitation is acceptable
|
|
60
|
+
* as this class is not publicly exposed. An additional check would make
|
|
61
|
+
* this method slower than it needs to be.
|
|
62
|
+
*
|
|
63
|
+
* @param id
|
|
64
|
+
*/
|
|
65
|
+
deleteEntry(id: number): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Removes and returns the first or last entry in the queue (based on the
|
|
68
|
+
* `direction` argument) matching the `queueName`.
|
|
69
|
+
*
|
|
70
|
+
* @returns
|
|
71
|
+
* @private
|
|
72
|
+
*/
|
|
73
|
+
_removeEntry(entry?: QueueStoreEntry): Promise<QueueStoreEntry | undefined>;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=QueueStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"QueueStore.d.ts","sourceRoot":"","sources":["../../../src/plugins/backgroundSync/QueueStore.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,eAAe,EAAE,2BAA2B,EAAE,MAAM,cAAc,CAAC;AAGjF;;;;;;GAMG;AACH,qBAAa,UAAU;IACrB,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IAEnC;;;;;OAKG;gBACS,SAAS,EAAE,MAAM;IAK7B;;;;OAIG;IACG,SAAS,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IAuBlE;;;;OAIG;IACG,YAAY,CAAC,KAAK,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;IA8BrE;;;;OAIG;IACG,QAAQ,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAItD;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;IAIxD;;;;OAIG;IACG,MAAM,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;IAI1C;;;;OAIG;IACG,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAI7B;;;;;;;;;OASG;IACG,WAAW,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAI5C;;;;;;OAMG;IACG,YAAY,CAAC,KAAK,CAAC,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,GAAG,SAAS,CAAC;CAMlF"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { MapLikeObject } from "../../types.js";
|
|
2
|
+
export interface RequestData extends MapLikeObject {
|
|
3
|
+
url: string;
|
|
4
|
+
headers: MapLikeObject;
|
|
5
|
+
body?: ArrayBuffer;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* A class to make it easier to serialize and de-serialize requests so they
|
|
9
|
+
* can be stored in IndexedDB.
|
|
10
|
+
*
|
|
11
|
+
* Most developers will not need to access this class directly;
|
|
12
|
+
* it is exposed for advanced use cases.
|
|
13
|
+
*/
|
|
14
|
+
export declare class StorableRequest {
|
|
15
|
+
private readonly _requestData;
|
|
16
|
+
/**
|
|
17
|
+
* Converts a Request object to a plain object that can be structured
|
|
18
|
+
* cloned or JSON-stringified.
|
|
19
|
+
*
|
|
20
|
+
* @param request
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
static fromRequest(request: Request): Promise<StorableRequest>;
|
|
24
|
+
/**
|
|
25
|
+
* Accepts an object of request data that can be used to construct a
|
|
26
|
+
* `Request` but can also be stored in IndexedDB.
|
|
27
|
+
*
|
|
28
|
+
* @param requestData An object of request data that includes the `url` plus any relevant properties of
|
|
29
|
+
* [requestInit](https://fetch.spec.whatwg.org/#requestinit).
|
|
30
|
+
*/
|
|
31
|
+
constructor(requestData: RequestData);
|
|
32
|
+
/**
|
|
33
|
+
* Returns a deep clone of the instances `_requestData` object.
|
|
34
|
+
*
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
toObject(): RequestData;
|
|
38
|
+
/**
|
|
39
|
+
* Converts this instance to a Request.
|
|
40
|
+
*
|
|
41
|
+
* @returns
|
|
42
|
+
*/
|
|
43
|
+
toRequest(): Request;
|
|
44
|
+
/**
|
|
45
|
+
* Creates and returns a deep clone of the instance.
|
|
46
|
+
*
|
|
47
|
+
* @returns
|
|
48
|
+
*/
|
|
49
|
+
clone(): StorableRequest;
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=StorableRequest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StorableRequest.d.ts","sourceRoot":"","sources":["../../../src/plugins/backgroundSync/StorableRequest.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAiBpD,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"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam } from "../../types.js";
|
|
2
|
+
import type { BroadcastCacheUpdateOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A class that uses the `postMessage()` API to inform any open windows/tabs when
|
|
5
|
+
* a cached response has been updated.
|
|
6
|
+
*
|
|
7
|
+
* For efficiency's sake, the underlying response bodies are not compared;
|
|
8
|
+
* only specific response headers are checked.
|
|
9
|
+
*/
|
|
10
|
+
export declare class BroadcastCacheUpdate {
|
|
11
|
+
private readonly _headersToCheck;
|
|
12
|
+
private readonly _generatePayload;
|
|
13
|
+
private readonly _notifyAllClients;
|
|
14
|
+
/**
|
|
15
|
+
* Construct a BroadcastCacheUpdate instance with a specific `channelName` to
|
|
16
|
+
* broadcast messages on
|
|
17
|
+
*
|
|
18
|
+
* @param options
|
|
19
|
+
*/
|
|
20
|
+
constructor({ generatePayload, headersToCheck, notifyAllClients }?: BroadcastCacheUpdateOptions);
|
|
21
|
+
/**
|
|
22
|
+
* Compares two responses and sends a message (via `postMessage()`) to all window clients if the
|
|
23
|
+
* responses differ. Neither of the Responses can be opaque.
|
|
24
|
+
*
|
|
25
|
+
* The message that's posted has the following format (where `payload` can
|
|
26
|
+
* be customized via the `generatePayload` option the instance is created
|
|
27
|
+
* with):
|
|
28
|
+
*
|
|
29
|
+
* ```
|
|
30
|
+
* {
|
|
31
|
+
* type: 'CACHE_UPDATED',
|
|
32
|
+
* meta: 'workbox-broadcast-update',
|
|
33
|
+
* payload: {
|
|
34
|
+
* cacheName: 'the-cache-name',
|
|
35
|
+
* updatedURL: 'https://example.com/'
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @param options
|
|
41
|
+
* @returns Resolves once the update is sent.
|
|
42
|
+
*/
|
|
43
|
+
notifyIfUpdated(options: CacheDidUpdateCallbackParam): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=BroadcastCacheUpdate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BroadcastCacheUpdate.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/BroadcastCacheUpdate.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAOlE,OAAO,KAAK,EAAE,2BAA2B,EAAiE,MAAM,YAAY,CAAC;AAuB7H;;;;;;GAMG;AACH,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAW;IAC3C,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAA4B;IAC7D,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAU;IAE5C;;;;;OAKG;gBACS,EAAE,eAAe,EAAE,cAAc,EAAE,gBAAgB,EAAE,GAAE,2BAAgC;IAMnG;;;;;;;;;;;;;;;;;;;;;OAqBG;IACG,eAAe,CAAC,OAAO,EAAE,2BAA2B,GAAG,OAAO,CAAC,IAAI,CAAC;CA4E3E"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam, SerwistPlugin } from "../../types.js";
|
|
2
|
+
import type { BroadcastCacheUpdateOptions } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* A class implementing the `cacheDidUpdate` lifecycle callback. It will automatically
|
|
5
|
+
* broadcast a message whenever a cached response is updated.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BroadcastUpdatePlugin implements SerwistPlugin {
|
|
8
|
+
private readonly _broadcastUpdate;
|
|
9
|
+
/**
|
|
10
|
+
* Construct a `serwist/plugins.BroadcastCacheUpdate` instance with
|
|
11
|
+
* the passed options and calls its `notifyIfUpdated` method whenever the
|
|
12
|
+
* plugin's `cacheDidUpdate` callback is invoked.
|
|
13
|
+
*
|
|
14
|
+
* @param options
|
|
15
|
+
*/
|
|
16
|
+
constructor(options?: BroadcastCacheUpdateOptions);
|
|
17
|
+
/**
|
|
18
|
+
* A "lifecycle" callback that will be triggered automatically by
|
|
19
|
+
* `@serwist/build.RuntimeCaching` handlers when an entry is
|
|
20
|
+
* added to a cache.
|
|
21
|
+
*
|
|
22
|
+
* @private
|
|
23
|
+
* @param options The input object to this function.
|
|
24
|
+
*/
|
|
25
|
+
cacheDidUpdate(options: CacheDidUpdateCallbackParam): void;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=BroadcastUpdatePlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BroadcastUpdatePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/BroadcastUpdatePlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,2BAA2B,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEjF,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,YAAY,CAAC;AAE9D;;;GAGG;AACH,qBAAa,qBAAsB,YAAW,aAAa;IACzD,OAAO,CAAC,QAAQ,CAAC,gBAAgB,CAAuB;IAExD;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,2BAA2B;IAIjD;;;;;;;OAOG;IACH,cAAc,CAAC,OAAO,EAAE,2BAA2B;CAGpD"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const CACHE_UPDATED_MESSAGE_TYPE = "CACHE_UPDATED";
|
|
2
|
+
export declare const CACHE_UPDATED_MESSAGE_META = "serwist-broadcast-update";
|
|
3
|
+
export declare const defaultNotifyAllClients = true;
|
|
4
|
+
export declare const defaultHeadersToCheck: string[];
|
|
5
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/constants.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,0BAA0B,kBAAkB,CAAC;AAC1D,eAAO,MAAM,0BAA0B,6BAA6B,CAAC;AACrE,eAAO,MAAM,uBAAuB,OAAO,CAAC;AAC5C,eAAO,MAAM,qBAAqB,UAA8C,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given two responses, compares several header values to see if they are
|
|
3
|
+
* the same or not.
|
|
4
|
+
*
|
|
5
|
+
* @param firstResponse The first response.
|
|
6
|
+
* @param secondResponse The second response.
|
|
7
|
+
* @param headersToCheck A list of headers to check.
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
export declare const responsesAreSame: (firstResponse: Response, secondResponse: Response, headersToCheck: string[]) => boolean;
|
|
11
|
+
//# sourceMappingURL=responsesAreSame.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"responsesAreSame.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/responsesAreSame.ts"],"names":[],"mappings":"AAWA;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB,kBAAmB,QAAQ,kBAAkB,QAAQ,kBAAkB,MAAM,EAAE,KAAG,OA4B9G,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { CacheDidUpdateCallbackParam } from "../../types.js";
|
|
2
|
+
import type { CACHE_UPDATED_MESSAGE_META, CACHE_UPDATED_MESSAGE_TYPE } from "./constants.js";
|
|
3
|
+
export interface BroadcastCacheUpdateOptions {
|
|
4
|
+
/**
|
|
5
|
+
* A list of headers that will be used to determine whether the responses
|
|
6
|
+
* differ.
|
|
7
|
+
*
|
|
8
|
+
* @default ['content-length', 'etag', 'last-modified']
|
|
9
|
+
*/
|
|
10
|
+
headersToCheck?: string[];
|
|
11
|
+
/**
|
|
12
|
+
* A function whose return value
|
|
13
|
+
* will be used as the `payload` field in any cache update messages sent
|
|
14
|
+
* to the window clients.
|
|
15
|
+
* @param options
|
|
16
|
+
* @returns
|
|
17
|
+
*/
|
|
18
|
+
generatePayload?: (options: CacheDidUpdateCallbackParam) => Record<string, any>;
|
|
19
|
+
/**
|
|
20
|
+
* If `true` (the default) then all open clients will receive a message. If `false`,
|
|
21
|
+
* then only the client that make the original request will be notified of the update.
|
|
22
|
+
*
|
|
23
|
+
* @default true
|
|
24
|
+
*/
|
|
25
|
+
notifyAllClients?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export type BroadcastPayload = Record<string, any>;
|
|
28
|
+
export type BroadcastPayloadGenerator = (options: CacheDidUpdateCallbackParam) => BroadcastPayload;
|
|
29
|
+
export interface BroadcastMessage {
|
|
30
|
+
type: typeof CACHE_UPDATED_MESSAGE_TYPE;
|
|
31
|
+
meta: typeof CACHE_UPDATED_MESSAGE_META;
|
|
32
|
+
payload: BroadcastPayload;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/broadcastUpdate/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAClE,OAAO,KAAK,EAAE,0BAA0B,EAAE,0BAA0B,EAAE,MAAM,gBAAgB,CAAC;AAE7F,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;;;;;OAMG;IACH,eAAe,CAAC,EAAE,CAAC,OAAO,EAAE,2BAA2B,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAChF;;;;;OAKG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B;AAED,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEnD,MAAM,MAAM,yBAAyB,GAAG,CAAC,OAAO,EAAE,2BAA2B,KAAK,gBAAgB,CAAC;AAEnG,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,OAAO,0BAA0B,CAAC;IACxC,IAAI,EAAE,OAAO,0BAA0B,CAAC;IACxC,OAAO,EAAE,gBAAgB,CAAC;CAC3B"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export interface CacheableResponseOptions {
|
|
2
|
+
/**
|
|
3
|
+
* One or more status codes that a `Response` can have to be considered cacheable.
|
|
4
|
+
*/
|
|
5
|
+
statuses?: number[];
|
|
6
|
+
/**
|
|
7
|
+
* A mapping of header names and expected values that a `Response` can have and be
|
|
8
|
+
* considered cacheable. If multiple headers are provided, only one needs to be present.
|
|
9
|
+
*/
|
|
10
|
+
headers?: HeadersInit;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Allows you to set up rules determining what status codes and/or headers need
|
|
14
|
+
* to be present in order for a [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
15
|
+
* to be considered cacheable.
|
|
16
|
+
*/
|
|
17
|
+
export declare class CacheableResponse {
|
|
18
|
+
private readonly _statuses?;
|
|
19
|
+
private readonly _headers?;
|
|
20
|
+
/**
|
|
21
|
+
* To construct a new CacheableResponse instance you must provide at least
|
|
22
|
+
* one of the `config` properties.
|
|
23
|
+
*
|
|
24
|
+
* If both `statuses` and `headers` are specified, then both conditions must
|
|
25
|
+
* be met for the `Response` to be considered cacheable.
|
|
26
|
+
*
|
|
27
|
+
* @param config
|
|
28
|
+
*/
|
|
29
|
+
constructor(config?: CacheableResponseOptions);
|
|
30
|
+
/**
|
|
31
|
+
* Checks a response to see whether it's cacheable or not.
|
|
32
|
+
*
|
|
33
|
+
* @param response The response whose cacheability is being
|
|
34
|
+
* checked.
|
|
35
|
+
* @returns `true` if the `Response` is cacheable, and `false`
|
|
36
|
+
* otherwise.
|
|
37
|
+
*/
|
|
38
|
+
isResponseCacheable(response: Response): boolean;
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=CacheableResponse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheableResponse.d.ts","sourceRoot":"","sources":["../../../src/plugins/cacheableResponse/CacheableResponse.ts"],"names":[],"mappings":"AAaA,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE,WAAW,CAAC;CACvB;AAED;;;;GAIG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAuC;IAClE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAU;IAEpC;;;;;;;;OAQG;gBACS,MAAM,GAAE,wBAA6B;IAmCjD;;;;;;;OAOG;IACH,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;CAyDjD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SerwistPlugin } from "../../types.js";
|
|
2
|
+
import type { CacheableResponseOptions } from "./CacheableResponse.js";
|
|
3
|
+
/**
|
|
4
|
+
* A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
|
|
5
|
+
* easier to add in cacheability checks to requests made via Serwist's built-in
|
|
6
|
+
* strategies.
|
|
7
|
+
*/
|
|
8
|
+
export declare class CacheableResponsePlugin implements SerwistPlugin {
|
|
9
|
+
private readonly _cacheableResponse;
|
|
10
|
+
/**
|
|
11
|
+
* To construct a new CacheableResponsePlugin instance you must provide at
|
|
12
|
+
* least one of the `config` properties.
|
|
13
|
+
*
|
|
14
|
+
* If both `statuses` and `headers` are specified, then both conditions must
|
|
15
|
+
* be met for the `Response` to be considered cacheable.
|
|
16
|
+
*
|
|
17
|
+
* @param config
|
|
18
|
+
*/
|
|
19
|
+
constructor(config: CacheableResponseOptions);
|
|
20
|
+
/**
|
|
21
|
+
* @param options
|
|
22
|
+
* @returns
|
|
23
|
+
* @private
|
|
24
|
+
*/
|
|
25
|
+
cacheWillUpdate: SerwistPlugin["cacheWillUpdate"];
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=CacheableResponsePlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CacheableResponsePlugin.d.ts","sourceRoot":"","sources":["../../../src/plugins/cacheableResponse/CacheableResponsePlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AACpD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGvE;;;;GAIG;AACH,qBAAa,uBAAwB,YAAW,aAAa;IAC3D,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IAEvD;;;;;;;;OAQG;gBACS,MAAM,EAAE,wBAAwB;IAI5C;;;;OAIG;IACH,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAK/C;CACH"}
|