@serwist/core 8.4.4 → 9.0.0-preview.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/_private/Deferred.d.ts +1 -0
- package/dist/_private/Deferred.d.ts.map +1 -0
- package/dist/_private/SerwistError.d.ts +1 -0
- package/dist/_private/SerwistError.d.ts.map +1 -0
- package/dist/_private/assert.d.ts +1 -0
- package/dist/_private/assert.d.ts.map +1 -0
- package/dist/_private/cacheMatchIgnoreParams.d.ts +1 -0
- package/dist/_private/cacheMatchIgnoreParams.d.ts.map +1 -0
- package/dist/_private/cacheNames.d.ts +1 -0
- package/dist/_private/cacheNames.d.ts.map +1 -0
- package/dist/_private/canConstructReadableStream.d.ts +1 -0
- package/dist/_private/canConstructReadableStream.d.ts.map +1 -0
- package/dist/_private/canConstructResponseFromBodyStream.d.ts +1 -0
- package/dist/_private/canConstructResponseFromBodyStream.d.ts.map +1 -0
- package/dist/_private/dontWaitFor.d.ts +1 -0
- package/dist/_private/dontWaitFor.d.ts.map +1 -0
- package/dist/_private/executeQuotaErrorCallbacks.d.ts +1 -0
- package/dist/_private/executeQuotaErrorCallbacks.d.ts.map +1 -0
- package/dist/_private/getFriendlyURL.d.ts +1 -0
- package/dist/_private/getFriendlyURL.d.ts.map +1 -0
- package/dist/_private/logger.d.ts +1 -0
- package/dist/_private/logger.d.ts.map +1 -0
- package/dist/_private/resultingClientExists.d.ts +1 -0
- package/dist/_private/resultingClientExists.d.ts.map +1 -0
- package/dist/_private/timeout.d.ts +1 -0
- package/dist/_private/timeout.d.ts.map +1 -0
- package/dist/_private/waitUntil.d.ts +1 -0
- package/dist/_private/waitUntil.d.ts.map +1 -0
- package/dist/cacheNames.d.ts +1 -0
- package/dist/cacheNames.d.ts.map +1 -0
- package/dist/{quotaErrorCallbacks.js → chunks/quotaErrorCallbacks.js} +9 -77
- package/dist/clientsClaim.d.ts +1 -0
- package/dist/clientsClaim.d.ts.map +1 -0
- package/dist/copyResponse.d.ts +1 -0
- package/dist/copyResponse.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.internal.d.ts +1 -0
- package/dist/index.internal.d.ts.map +1 -0
- package/dist/index.internal.js +14 -123
- package/dist/index.js +5 -60
- package/dist/models/messages/messageGenerator.d.ts +1 -0
- package/dist/models/messages/messageGenerator.d.ts.map +1 -0
- package/dist/models/messages/messages.d.ts +1 -0
- package/dist/models/messages/messages.d.ts.map +1 -0
- package/dist/models/pluginEvents.d.ts +1 -0
- package/dist/models/pluginEvents.d.ts.map +1 -0
- package/dist/models/quotaErrorCallbacks.d.ts +1 -0
- package/dist/models/quotaErrorCallbacks.d.ts.map +1 -0
- package/dist/registerQuotaErrorCallback.d.ts +1 -0
- package/dist/registerQuotaErrorCallback.d.ts.map +1 -0
- package/dist/setCacheNameDetails.d.ts +1 -0
- package/dist/setCacheNameDetails.d.ts.map +1 -0
- package/dist/types.d.ts +1 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/utils/pluginUtils.d.ts +1 -0
- package/dist/utils/pluginUtils.d.ts.map +1 -0
- package/dist/utils/welcome.d.ts +1 -0
- package/dist/utils/welcome.d.ts.map +1 -0
- package/package.json +18 -22
- package/src/_private/Deferred.ts +33 -0
- package/src/_private/SerwistError.ts +42 -0
- package/src/_private/assert.ts +89 -0
- package/src/_private/cacheMatchIgnoreParams.ts +54 -0
- package/src/_private/cacheNames.ts +87 -0
- package/src/_private/canConstructReadableStream.ts +34 -0
- package/src/_private/canConstructResponseFromBodyStream.ts +37 -0
- package/src/_private/dontWaitFor.ts +16 -0
- package/src/_private/executeQuotaErrorCallbacks.ts +35 -0
- package/src/_private/getFriendlyURL.ts +16 -0
- package/src/_private/logger.ts +92 -0
- package/src/_private/resultingClientExists.ts +58 -0
- package/src/_private/timeout.ts +19 -0
- package/src/_private/waitUntil.ts +23 -0
- package/src/cacheNames.ts +41 -0
- package/src/clientsClaim.ts +20 -0
- package/src/copyResponse.ts +62 -0
- package/{dist/index.internal.d.cts → src/index.internal.ts} +19 -1
- package/{dist/index.d.cts → src/index.ts} +9 -0
- package/src/models/messages/messageGenerator.ts +28 -0
- package/src/models/messages/messages.ts +231 -0
- package/src/models/pluginEvents.ts +17 -0
- package/src/models/quotaErrorCallbacks.ts +13 -0
- package/src/registerQuotaErrorCallback.ts +36 -0
- package/src/setCacheNameDetails.ts +55 -0
- package/src/types.ts +315 -0
- package/src/utils/pluginUtils.ts +15 -0
- package/src/utils/welcome.ts +25 -0
- package/dist/_private/Deferred.d.cts +0 -18
- package/dist/_private/SerwistError.d.cts +0 -23
- package/dist/_private/assert.d.cts +0 -10
- package/dist/_private/cacheMatchIgnoreParams.d.cts +0 -14
- package/dist/_private/cacheNames.d.cts +0 -39
- package/dist/_private/canConstructReadableStream.d.cts +0 -11
- package/dist/_private/canConstructResponseFromBodyStream.d.cts +0 -10
- package/dist/_private/dontWaitFor.d.cts +0 -6
- package/dist/_private/executeQuotaErrorCallbacks.d.cts +0 -8
- package/dist/_private/getFriendlyURL.d.cts +0 -2
- package/dist/_private/logger.d.cts +0 -10
- package/dist/_private/resultingClientExists.d.cts +0 -11
- package/dist/_private/timeout.d.cts +0 -9
- package/dist/_private/waitUntil.d.cts +0 -11
- package/dist/cacheNames.d.cts +0 -20
- package/dist/clientsClaim.d.cts +0 -6
- package/dist/copyResponse.d.cts +0 -20
- package/dist/index.cjs +0 -153
- package/dist/index.internal.cjs +0 -243
- package/dist/models/messages/messageGenerator.d.cts +0 -1
- package/dist/models/messages/messages.d.cts +0 -8
- package/dist/models/pluginEvents.d.cts +0 -9
- package/dist/models/quotaErrorCallbacks.d.cts +0 -2
- package/dist/quotaErrorCallbacks.cjs +0 -432
- package/dist/registerQuotaErrorCallback.d.cts +0 -8
- package/dist/setCacheNameDetails.d.cts +0 -9
- package/dist/types.d.cts +0 -272
- package/dist/utils/pluginUtils.d.cts +0 -4
- package/dist/utils/welcome.d.cts +0 -1
package/dist/index.js
CHANGED
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBodyStream, f as finalAssertExports, q as quotaErrorCallbacks, l as logger } from './quotaErrorCallbacks.js';
|
|
1
|
+
import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBodyStream, f as finalAssertExports, q as quotaErrorCallbacks, l as logger } from './chunks/quotaErrorCallbacks.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* Get the current cache names and prefix/suffix used by Workbox.
|
|
5
|
-
*
|
|
6
|
-
* `cacheNames.precache` is used for precached assets,
|
|
7
|
-
* `cacheNames.googleAnalytics` is used by `@serwist/google-analytics` to
|
|
8
|
-
* store `analytics.js`, and `cacheNames.runtime` is used for everything else.
|
|
9
|
-
*
|
|
10
|
-
* `cacheNames.prefix` can be used to retrieve just the current prefix value.
|
|
11
|
-
* `cacheNames.suffix` can be used to retrieve just the current suffix value.
|
|
12
|
-
*
|
|
13
|
-
* @returns An object with `precache`, `runtime`, `prefix`, and `googleAnalytics` properties.
|
|
14
|
-
*/ const cacheNames = {
|
|
3
|
+
const cacheNames = {
|
|
15
4
|
get googleAnalytics () {
|
|
16
5
|
return cacheNames$1.getGoogleAnalyticsName();
|
|
17
6
|
},
|
|
@@ -29,40 +18,12 @@ import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBody
|
|
|
29
18
|
}
|
|
30
19
|
};
|
|
31
20
|
|
|
32
|
-
|
|
33
|
-
Copyright 2019 Google LLC
|
|
34
|
-
|
|
35
|
-
Use of this source code is governed by an MIT-style
|
|
36
|
-
license that can be found in the LICENSE file or at
|
|
37
|
-
https://opensource.org/licenses/MIT.
|
|
38
|
-
*/ // Give TypeScript the correct global.
|
|
39
|
-
/**
|
|
40
|
-
* Claim any currently available clients once the service worker
|
|
41
|
-
* becomes active. This is normally used in conjunction with `skipWaiting()`.
|
|
42
|
-
*/ function clientsClaim() {
|
|
21
|
+
function clientsClaim() {
|
|
43
22
|
self.addEventListener("activate", ()=>self.clients.claim());
|
|
44
23
|
}
|
|
45
24
|
|
|
46
|
-
|
|
47
|
-
* Allows developers to copy a response and modify its `headers`, `status`,
|
|
48
|
-
* or `statusText` values (the values settable via a
|
|
49
|
-
* [`ResponseInit`](https://developer.mozilla.org/en-US/docs/Web/API/Response/Response#Syntax)
|
|
50
|
-
* object in the constructor).
|
|
51
|
-
* To modify these values, pass a function as the second argument. That
|
|
52
|
-
* function will be invoked with a single object with the response properties
|
|
53
|
-
* `{headers, status, statusText}`. The return value of this function will
|
|
54
|
-
* be used as the `ResponseInit` for the new `Response`. To change the values
|
|
55
|
-
* either modify the passed parameter(s) and return it, or return a totally
|
|
56
|
-
* new object.
|
|
57
|
-
*
|
|
58
|
-
* This method is intentionally limited to same-origin responses, regardless of
|
|
59
|
-
* whether CORS was used or not.
|
|
60
|
-
*
|
|
61
|
-
* @param response
|
|
62
|
-
* @param modifier
|
|
63
|
-
*/ async function copyResponse(response, modifier) {
|
|
25
|
+
async function copyResponse(response, modifier) {
|
|
64
26
|
let origin = null;
|
|
65
|
-
// If response.url isn't set, assume it's cross-origin and keep origin null.
|
|
66
27
|
if (response.url) {
|
|
67
28
|
const responseURL = new URL(response.url);
|
|
68
29
|
origin = responseURL.origin;
|
|
@@ -73,27 +34,16 @@ import { c as cacheNames$1, S as SerwistError, a as canConstructResponseFromBody
|
|
|
73
34
|
});
|
|
74
35
|
}
|
|
75
36
|
const clonedResponse = response.clone();
|
|
76
|
-
// Create a fresh `ResponseInit` object by cloning the headers.
|
|
77
37
|
const responseInit = {
|
|
78
38
|
headers: new Headers(clonedResponse.headers),
|
|
79
39
|
status: clonedResponse.status,
|
|
80
40
|
statusText: clonedResponse.statusText
|
|
81
41
|
};
|
|
82
|
-
// Apply any user modifications.
|
|
83
42
|
const modifiedResponseInit = modifier ? modifier(responseInit) : responseInit;
|
|
84
|
-
// Create the new response from the body stream and `ResponseInit`
|
|
85
|
-
// modifications. Note: not all browsers support the Response.body stream,
|
|
86
|
-
// so fall back to reading the entire body into memory as a blob.
|
|
87
43
|
const body = canConstructResponseFromBodyStream() ? clonedResponse.body : await clonedResponse.blob();
|
|
88
44
|
return new Response(body, modifiedResponseInit);
|
|
89
45
|
}
|
|
90
46
|
|
|
91
|
-
/**
|
|
92
|
-
* Adds a function to the set of quotaErrorCallbacks that will be executed if
|
|
93
|
-
* there's a quota error.
|
|
94
|
-
*
|
|
95
|
-
* @param callback
|
|
96
|
-
*/ // biome-ignore lint/complexity/noBannedTypes: Can't change Function type
|
|
97
47
|
function registerQuotaErrorCallback(callback) {
|
|
98
48
|
if (process.env.NODE_ENV !== "production") {
|
|
99
49
|
finalAssertExports.isType(callback, "function", {
|
|
@@ -108,12 +58,7 @@ function registerQuotaErrorCallback(callback) {
|
|
|
108
58
|
}
|
|
109
59
|
}
|
|
110
60
|
|
|
111
|
-
|
|
112
|
-
* Modifies the default cache names used by the Serwist packages.
|
|
113
|
-
* Cache names are generated as `<prefix>-<Cache Name>-<suffix>`.
|
|
114
|
-
*
|
|
115
|
-
* @param details
|
|
116
|
-
*/ function setCacheNameDetails(details) {
|
|
61
|
+
function setCacheNameDetails(details) {
|
|
117
62
|
if (process.env.NODE_ENV !== "production") {
|
|
118
63
|
for (const key of Object.keys(details)){
|
|
119
64
|
finalAssertExports.isType(details[key], "string", {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageGenerator.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messageGenerator.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,gBAAgB,UAjBL,MAAM,WAAW,GAAG,EAAE,uBAQb,MAAM,0BAS6D,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/models/messages/messages.ts"],"names":[],"mappings":"AAQA,UAAU,cAAc;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;CAChC;AACD,UAAU,UAAU;IAClB,CAAC,SAAS,EAAE,MAAM,GAAG,CAAC,KAAK,EAAE,cAAc,KAAK,MAAM,CAAC;CACxD;AAED,eAAO,MAAM,QAAQ,EAAE,UAuNtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginEvents.d.ts","sourceRoot":"","sources":["../../src/models/pluginEvents.ts"],"names":[],"mappings":"AAQA,oBAAY,YAAY;IACtB,gBAAgB,mBAAmB;IACnC,sBAAsB,uBAAuB;IAC7C,iBAAiB,oBAAoB;IACrC,4BAA4B,6BAA6B;IACzD,cAAc,iBAAiB;IAC/B,iBAAiB,oBAAoB;IACrC,kBAAkB,qBAAqB;CACxC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"quotaErrorCallbacks.d.ts","sourceRoot":"","sources":["../../src/models/quotaErrorCallbacks.ts"],"names":[],"mappings":"AAUA,QAAA,MAAM,mBAAmB,EAAE,GAAG,CAAC,QAAQ,CAAa,CAAC;AAErD,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registerQuotaErrorCallback.d.ts","sourceRoot":"","sources":["../src/registerQuotaErrorCallback.ts"],"names":[],"mappings":"AAYA;;;;;GAKG;AAEH,iBAAS,0BAA0B,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI,CAc5D;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setCacheNameDetails.d.ts","sourceRoot":"","sources":["../src/setCacheNameDetails.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAGxE;;;;;GAKG;AACH,iBAAS,mBAAmB,CAAC,OAAO,EAAE,uBAAuB,GAAG,IAAI,CAiCnE;AAED,OAAO,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@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,EAAE,0BAA0B,CAAC;IAChD,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC1C,YAAY,CAAC,EAAE,oBAAoB,CAAC;IACpC,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC1C,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;IAChD,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC1C,iBAAiB,CAAC,EAAE,yBAAyB,CAAC;IAC9C,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;IAChD,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;IAC5C,gBAAgB,CAAC,EAAE,wBAAwB,CAAC;CAC7C;AAED,MAAM,WAAW,0BAA0B;IACzC,cAAc,EAAE,2BAA2B,CAAC;IAC5C,wBAAwB,EAAE,qCAAqC,CAAC;IAChE,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,EAAE,4BAA4B,CAAC;IAC9C,YAAY,EAAE,yBAAyB,CAAC;IACxC,eAAe,EAAE,4BAA4B,CAAC;IAC9C,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,eAAe,EAAE,4BAA4B,CAAC;IAC9C,iBAAiB,EAAE,8BAA8B,CAAC;IAClD,kBAAkB,EAAE,+BAA+B,CAAC;IACpD,gBAAgB,EAAE,6BAA6B,CAAC;IAChD,gBAAgB,EAAE,6BAA6B,CAAC;CACjD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pluginUtils.d.ts","sourceRoot":"","sources":["../../src/utils/pluginUtils.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD,eAAO,MAAM,WAAW;sBACJ,aAAa,EAAE,gBAAgB,MAAM,KAAG,aAAa,EAAE;CAG1E,CAAC"}
|
package/dist/utils/welcome.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"welcome.d.ts","sourceRoot":"","sources":["../../src/utils/welcome.ts"],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0-preview.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "This module is used by a number of the other Serwist modules to share common code.",
|
|
6
6
|
"files": [
|
|
7
|
-
"
|
|
8
|
-
"
|
|
7
|
+
"src",
|
|
8
|
+
"dist"
|
|
9
9
|
],
|
|
10
10
|
"keywords": [
|
|
11
11
|
"serwist",
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"bugs": "https://github.com/serwist/serwist/issues",
|
|
20
20
|
"homepage": "https://serwist.pages.dev",
|
|
21
21
|
"main": "./dist/index.js",
|
|
22
|
-
"module": "./dist/index.js",
|
|
23
22
|
"types": "./dist/index.d.ts",
|
|
24
23
|
"typesVersions": {
|
|
25
24
|
"*": {
|
|
@@ -30,29 +29,26 @@
|
|
|
30
29
|
},
|
|
31
30
|
"exports": {
|
|
32
31
|
".": {
|
|
33
|
-
"
|
|
34
|
-
|
|
35
|
-
"default": "./dist/index.js"
|
|
36
|
-
},
|
|
37
|
-
"require": {
|
|
38
|
-
"types": "./dist/index.d.cts",
|
|
39
|
-
"default": "./dist/index.cjs"
|
|
40
|
-
}
|
|
32
|
+
"types": "./dist/index.d.ts",
|
|
33
|
+
"default": "./dist/index.js"
|
|
41
34
|
},
|
|
42
35
|
"./internal": {
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
"default": "./dist/index.internal.js"
|
|
46
|
-
},
|
|
47
|
-
"require": {
|
|
48
|
-
"types": "./dist/index.internal.d.cts",
|
|
49
|
-
"default": "./dist/index.internal.cjs"
|
|
50
|
-
}
|
|
36
|
+
"types": "./dist/index.internal.d.ts",
|
|
37
|
+
"default": "./dist/index.internal.js"
|
|
51
38
|
}
|
|
52
39
|
},
|
|
53
40
|
"devDependencies": {
|
|
54
|
-
"rollup": "4.9.
|
|
55
|
-
"
|
|
41
|
+
"rollup": "4.9.6",
|
|
42
|
+
"typescript": "5.4.0-dev.20240203",
|
|
43
|
+
"@serwist/constants": "9.0.0-preview.1"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"typescript": ">=5.0.0"
|
|
47
|
+
},
|
|
48
|
+
"peerDependenciesMeta": {
|
|
49
|
+
"typescript": {
|
|
50
|
+
"optional": true
|
|
51
|
+
}
|
|
56
52
|
},
|
|
57
53
|
"scripts": {
|
|
58
54
|
"build": "rimraf dist && cross-env NODE_ENV=production rollup --config rollup.config.js",
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The Deferred class composes Promises in a way that allows for them to be
|
|
11
|
+
* resolved or rejected from outside the constructor. In most cases promises
|
|
12
|
+
* should be used directly, but Deferreds can be necessary when the logic to
|
|
13
|
+
* resolve a promise must be separate.
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
class Deferred<T> {
|
|
18
|
+
promise: Promise<T>;
|
|
19
|
+
resolve!: (value: T) => void;
|
|
20
|
+
reject!: (reason?: any) => void;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Creates a promise and exposes its resolve and reject functions as methods.
|
|
24
|
+
*/
|
|
25
|
+
constructor() {
|
|
26
|
+
this.promise = new Promise((resolve, reject) => {
|
|
27
|
+
this.resolve = resolve;
|
|
28
|
+
this.reject = reject;
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export { Deferred };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { messageGenerator } from "../models/messages/messageGenerator.js";
|
|
10
|
+
import type { MapLikeObject } from "../types.js";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Serwist errors should be thrown with this class.
|
|
14
|
+
* This allows use to ensure the type easily in tests,
|
|
15
|
+
* helps developers identify errors from Serwist
|
|
16
|
+
* easily and allows use to optimise error
|
|
17
|
+
* messages correctly.
|
|
18
|
+
*
|
|
19
|
+
* @private
|
|
20
|
+
*/
|
|
21
|
+
class SerwistError extends Error {
|
|
22
|
+
details?: MapLikeObject;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
*
|
|
26
|
+
* @param errorCode The error code that
|
|
27
|
+
* identifies this particular error.
|
|
28
|
+
* @param details Any relevant arguments
|
|
29
|
+
* that will help developers identify issues should
|
|
30
|
+
* be added as a key on the context object.
|
|
31
|
+
*/
|
|
32
|
+
constructor(errorCode: string, details?: MapLikeObject) {
|
|
33
|
+
const message = messageGenerator(errorCode, details);
|
|
34
|
+
|
|
35
|
+
super(message);
|
|
36
|
+
|
|
37
|
+
this.name = errorCode;
|
|
38
|
+
this.details = details;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { SerwistError };
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { SerwistError } from "../_private/SerwistError.js";
|
|
10
|
+
import type { MapLikeObject } from "../types.js";
|
|
11
|
+
|
|
12
|
+
/*
|
|
13
|
+
* This method throws if the supplied value is not an array.
|
|
14
|
+
* The destructed values are required to produce a meaningful error for users.
|
|
15
|
+
* The destructed and restructured object is so it's clear what is
|
|
16
|
+
* needed.
|
|
17
|
+
*/
|
|
18
|
+
const isArray = (value: any[], details: MapLikeObject) => {
|
|
19
|
+
if (!Array.isArray(value)) {
|
|
20
|
+
throw new SerwistError("not-an-array", details);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const hasMethod = (object: MapLikeObject, expectedMethod: string, details: MapLikeObject) => {
|
|
25
|
+
const type = typeof object[expectedMethod];
|
|
26
|
+
if (type !== "function") {
|
|
27
|
+
details.expectedMethod = expectedMethod;
|
|
28
|
+
throw new SerwistError("missing-a-method", details);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const isType = (object: unknown, expectedType: string, details: MapLikeObject) => {
|
|
33
|
+
// biome-ignore lint/suspicious/useValidTypeof: Know to not make a mistake...
|
|
34
|
+
if (typeof object !== expectedType) {
|
|
35
|
+
details.expectedType = expectedType;
|
|
36
|
+
throw new SerwistError("incorrect-type", details);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const isInstance = (
|
|
41
|
+
object: unknown,
|
|
42
|
+
// biome-ignore lint/complexity/noBannedTypes: Need the general type to do the check later.
|
|
43
|
+
expectedClass: Function,
|
|
44
|
+
details: MapLikeObject,
|
|
45
|
+
) => {
|
|
46
|
+
if (!(object instanceof expectedClass)) {
|
|
47
|
+
details.expectedClassName = expectedClass.name;
|
|
48
|
+
throw new SerwistError("incorrect-class", details);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const isOneOf = (value: any, validValues: any[], details: MapLikeObject) => {
|
|
53
|
+
if (!validValues.includes(value)) {
|
|
54
|
+
details.validValueDescription = `Valid values are ${JSON.stringify(validValues)}.`;
|
|
55
|
+
throw new SerwistError("invalid-value", details);
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const isArrayOfClass = (
|
|
60
|
+
value: any,
|
|
61
|
+
// biome-ignore lint/complexity/noBannedTypes: Need general type to do check later.
|
|
62
|
+
expectedClass: Function,
|
|
63
|
+
details: MapLikeObject,
|
|
64
|
+
) => {
|
|
65
|
+
const error = new SerwistError("not-array-of-class", details);
|
|
66
|
+
if (!Array.isArray(value)) {
|
|
67
|
+
throw error;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
for (const item of value) {
|
|
71
|
+
if (!(item instanceof expectedClass)) {
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const finalAssertExports =
|
|
78
|
+
process.env.NODE_ENV === "production"
|
|
79
|
+
? null
|
|
80
|
+
: {
|
|
81
|
+
hasMethod,
|
|
82
|
+
isArray,
|
|
83
|
+
isInstance,
|
|
84
|
+
isOneOf,
|
|
85
|
+
isType,
|
|
86
|
+
isArrayOfClass,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
export { finalAssertExports as assert };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020 Google LLC
|
|
3
|
+
Use of this source code is governed by an MIT-style
|
|
4
|
+
license that can be found in the LICENSE file or at
|
|
5
|
+
https://opensource.org/licenses/MIT.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
function stripParams(fullURL: string, ignoreParams: string[]) {
|
|
9
|
+
const strippedURL = new URL(fullURL);
|
|
10
|
+
for (const param of ignoreParams) {
|
|
11
|
+
strippedURL.searchParams.delete(param);
|
|
12
|
+
}
|
|
13
|
+
return strippedURL.href;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Matches an item in the cache, ignoring specific URL params. This is similar
|
|
18
|
+
* to the `ignoreSearch` option, but it allows you to ignore just specific
|
|
19
|
+
* params (while continuing to match on the others).
|
|
20
|
+
*
|
|
21
|
+
* @private
|
|
22
|
+
* @param cache
|
|
23
|
+
* @param request
|
|
24
|
+
* @param matchOptions
|
|
25
|
+
* @param ignoreParams
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
async function cacheMatchIgnoreParams(
|
|
29
|
+
cache: Cache,
|
|
30
|
+
request: Request,
|
|
31
|
+
ignoreParams: string[],
|
|
32
|
+
matchOptions?: CacheQueryOptions,
|
|
33
|
+
): Promise<Response | undefined> {
|
|
34
|
+
const strippedRequestURL = stripParams(request.url, ignoreParams);
|
|
35
|
+
|
|
36
|
+
// If the request doesn't include any ignored params, match as normal.
|
|
37
|
+
if (request.url === strippedRequestURL) {
|
|
38
|
+
return cache.match(request, matchOptions);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Otherwise, match by comparing keys
|
|
42
|
+
const keysOptions = { ...matchOptions, ignoreSearch: true };
|
|
43
|
+
const cacheKeys = await cache.keys(request, keysOptions);
|
|
44
|
+
|
|
45
|
+
for (const cacheKey of cacheKeys) {
|
|
46
|
+
const strippedCacheKeyURL = stripParams(cacheKey.url, ignoreParams);
|
|
47
|
+
if (strippedRequestURL === strippedCacheKeyURL) {
|
|
48
|
+
return cache.match(cacheKey, matchOptions);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export { cacheMatchIgnoreParams };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2018 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
declare let registration: ServiceWorkerRegistration | undefined;
|
|
10
|
+
|
|
11
|
+
export interface CacheNameDetails {
|
|
12
|
+
googleAnalytics: string;
|
|
13
|
+
precache: string;
|
|
14
|
+
prefix: string;
|
|
15
|
+
runtime: string;
|
|
16
|
+
suffix: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface PartialCacheNameDetails {
|
|
20
|
+
/**
|
|
21
|
+
* The string to add to the beginning of the precache and runtime cache names.
|
|
22
|
+
*/
|
|
23
|
+
prefix?: string;
|
|
24
|
+
/**
|
|
25
|
+
* The string to add to the end of the precache and runtime cache names.
|
|
26
|
+
*/
|
|
27
|
+
suffix?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The cache name to use for precache caching.
|
|
30
|
+
*/
|
|
31
|
+
precache?: string;
|
|
32
|
+
/**
|
|
33
|
+
* The cache name to use for runtime caching.
|
|
34
|
+
*/
|
|
35
|
+
runtime?: string;
|
|
36
|
+
/**
|
|
37
|
+
* The cache name to use for `@serwist/google-analytics` caching.
|
|
38
|
+
*/
|
|
39
|
+
googleAnalytics?: string;
|
|
40
|
+
[propName: string]: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export type CacheNameDetailsProp = "googleAnalytics" | "precache" | "prefix" | "runtime" | "suffix";
|
|
44
|
+
|
|
45
|
+
const _cacheNameDetails: CacheNameDetails = {
|
|
46
|
+
googleAnalytics: "googleAnalytics",
|
|
47
|
+
precache: "precache-v2",
|
|
48
|
+
prefix: "serwist",
|
|
49
|
+
runtime: "runtime",
|
|
50
|
+
suffix: typeof registration !== "undefined" ? registration.scope : "",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const _createCacheName = (cacheName: string): string => {
|
|
54
|
+
return [_cacheNameDetails.prefix, cacheName, _cacheNameDetails.suffix].filter((value) => value && value.length > 0).join("-");
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
const eachCacheNameDetail = (fn: (key: CacheNameDetailsProp) => void): void => {
|
|
58
|
+
for (const key of Object.keys(_cacheNameDetails)) {
|
|
59
|
+
fn(key as CacheNameDetailsProp);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const cacheNames = {
|
|
64
|
+
updateDetails: (details: PartialCacheNameDetails): void => {
|
|
65
|
+
eachCacheNameDetail((key: CacheNameDetailsProp): void => {
|
|
66
|
+
const detail = details[key];
|
|
67
|
+
if (typeof detail === "string") {
|
|
68
|
+
_cacheNameDetails[key] = detail;
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
},
|
|
72
|
+
getGoogleAnalyticsName: (userCacheName?: string): string => {
|
|
73
|
+
return userCacheName || _createCacheName(_cacheNameDetails.googleAnalytics);
|
|
74
|
+
},
|
|
75
|
+
getPrecacheName: (userCacheName?: string): string => {
|
|
76
|
+
return userCacheName || _createCacheName(_cacheNameDetails.precache);
|
|
77
|
+
},
|
|
78
|
+
getPrefix: (): string => {
|
|
79
|
+
return _cacheNameDetails.prefix;
|
|
80
|
+
},
|
|
81
|
+
getRuntimeName: (userCacheName?: string): string => {
|
|
82
|
+
return userCacheName || _createCacheName(_cacheNameDetails.runtime);
|
|
83
|
+
},
|
|
84
|
+
getSuffix: (): string => {
|
|
85
|
+
return _cacheNameDetails.suffix;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2019 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
let supportStatus: boolean | undefined;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A utility function that determines whether the current browser supports
|
|
13
|
+
* constructing a [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream)
|
|
14
|
+
* object.
|
|
15
|
+
*
|
|
16
|
+
* @returns `true`, if the current browser can successfully construct a `ReadableStream`, `false` otherwise.
|
|
17
|
+
*
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
function canConstructReadableStream(): boolean {
|
|
21
|
+
if (supportStatus === undefined) {
|
|
22
|
+
// See https://github.com/GoogleChrome/workbox/issues/1473
|
|
23
|
+
try {
|
|
24
|
+
new ReadableStream({ start() {} });
|
|
25
|
+
supportStatus = true;
|
|
26
|
+
} catch (error) {
|
|
27
|
+
supportStatus = false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return supportStatus;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { canConstructReadableStream };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2019 Google LLC
|
|
3
|
+
|
|
4
|
+
Use of this source code is governed by an MIT-style
|
|
5
|
+
license that can be found in the LICENSE file or at
|
|
6
|
+
https://opensource.org/licenses/MIT.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
let supportStatus: boolean | undefined;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* A utility function that determines whether the current browser supports
|
|
13
|
+
* constructing a new `Response` from a `response.body` stream.
|
|
14
|
+
*
|
|
15
|
+
* @returns `true`, if the current browser can successfully construct
|
|
16
|
+
* a `Response` from a `response.body` stream, `false` otherwise.
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
function canConstructResponseFromBodyStream(): boolean {
|
|
20
|
+
if (supportStatus === undefined) {
|
|
21
|
+
const testResponse = new Response("");
|
|
22
|
+
|
|
23
|
+
if ("body" in testResponse) {
|
|
24
|
+
try {
|
|
25
|
+
new Response(testResponse.body);
|
|
26
|
+
supportStatus = true;
|
|
27
|
+
} catch (error) {
|
|
28
|
+
supportStatus = false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
supportStatus = false;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return supportStatus;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { canConstructResponseFromBodyStream };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2019 Google LLC
|
|
3
|
+
Use of this source code is governed by an MIT-style
|
|
4
|
+
license that can be found in the LICENSE file or at
|
|
5
|
+
https://opensource.org/licenses/MIT.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A helper function that prevents a promise from being flagged as unused.
|
|
10
|
+
*
|
|
11
|
+
* @private
|
|
12
|
+
**/
|
|
13
|
+
export function dontWaitFor(promise: Promise<any>): void {
|
|
14
|
+
// Effective no-op.
|
|
15
|
+
void promise.then(() => {});
|
|
16
|
+
}
|