@serwist/cacheable-response 8.0.0 → 8.0.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/CacheableResponse.d.ts +0 -1
- package/dist/CacheableResponsePlugin.d.ts +0 -1
- package/dist/index.d.ts +0 -1
- package/package.json +12 -8
- package/.turbo/turbo-build.log +0 -10
- package/.turbo/turbo-lint.log +0 -4
- package/.turbo/turbo-typecheck.log +0 -4
- package/CHANGELOG.md +0 -33
- package/dist/CacheableResponse.d.ts.map +0 -1
- package/dist/CacheableResponsePlugin.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/rollup.config.js +0 -27
- package/src/CacheableResponse.ts +0 -140
- package/src/CacheableResponsePlugin.ts +0 -48
- package/src/index.ts +0 -15
- package/tsconfig.json +0 -7
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/cacheable-response",
|
|
3
|
-
"version": "8.0.
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"license": "MIT",
|
|
6
|
-
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
7
5
|
"description": "This library takes a Response object and determines whether it's cacheable based on a specific configuration.",
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
"files": [
|
|
7
|
+
"dist",
|
|
8
|
+
"!dist/**/dts"
|
|
9
|
+
],
|
|
11
10
|
"keywords": [
|
|
12
11
|
"serwist",
|
|
13
12
|
"serwistjs",
|
|
@@ -15,6 +14,11 @@
|
|
|
15
14
|
"sw",
|
|
16
15
|
"serwist-plugin"
|
|
17
16
|
],
|
|
17
|
+
"author": "Google's Web DevRel Team, Serwist's Team",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": "serwist/serwist",
|
|
20
|
+
"bugs": "https://github.com/serwist/serwist/issues",
|
|
21
|
+
"homepage": "https://ducanh-next-pwa.vercel.app",
|
|
18
22
|
"module": "./dist/index.js",
|
|
19
23
|
"main": "./dist/index.old.cjs",
|
|
20
24
|
"types": "./dist/index.d.ts",
|
|
@@ -27,11 +31,11 @@
|
|
|
27
31
|
"./package.json": "./package.json"
|
|
28
32
|
},
|
|
29
33
|
"dependencies": {
|
|
30
|
-
"@serwist/core": "8.0.
|
|
34
|
+
"@serwist/core": "8.0.1"
|
|
31
35
|
},
|
|
32
36
|
"devDependencies": {
|
|
33
37
|
"rollup": "3.28.1",
|
|
34
|
-
"@serwist/constants": "8.0.
|
|
38
|
+
"@serwist/constants": "8.0.1"
|
|
35
39
|
},
|
|
36
40
|
"scripts": {
|
|
37
41
|
"build": "cross-env NODE_ENV=production rollup --waitForBundleInput --config rollup.config.js",
|
package/.turbo/turbo-build.log
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
> @serwist/cacheable-response@8.0.0 build /home/runner/work/serwist/serwist/packages/cacheable-response
|
|
3
|
-
> cross-env NODE_ENV=production rollup --waitForBundleInput --config rollup.config.js
|
|
4
|
-
|
|
5
|
-
(node:2290) ExperimentalWarning: Import assertions are not a stable feature of the JavaScript language. Avoid relying on their current behavior and syntax as those might change in a future version of Node.js.
|
|
6
|
-
(Use `node --trace-warnings ...` to show where the warning was created)
|
|
7
|
-
(node:2290) ExperimentalWarning: Importing JSON modules is an experimental feature and might change at any time
|
|
8
|
-
[36m
|
|
9
|
-
[1msrc/index.ts[22m → [1mdist/index.old.cjs, dist/index.js[22m...[39m
|
|
10
|
-
[32mcreated [1mdist/index.old.cjs, dist/index.js[22m in [1m7.6s[22m[39m
|
package/.turbo/turbo-lint.log
DELETED
package/CHANGELOG.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# @serwist/cacheable-response
|
|
2
|
-
|
|
3
|
-
## 8.0.0
|
|
4
|
-
|
|
5
|
-
### Major Changes
|
|
6
|
-
|
|
7
|
-
- [`e0313f0`](https://github.com/serwist/serwist/commit/e0313f02f661a07ccbe9edc64e44e1af6136c73e) Thanks [@DuCanhGH](https://github.com/DuCanhGH)! - chore: initial release
|
|
8
|
-
|
|
9
|
-
- Reimagined `@serwist/next`.
|
|
10
|
-
- Removed various options.
|
|
11
|
-
- Removed `aggressiveFrontEndNavCaching` to reassess its usefulness.
|
|
12
|
-
- Removed `browserslist`. Use `swcEnvTargets` instead (TODO: add this option).
|
|
13
|
-
- Custom workers have been removed. You should use `swSrc`.
|
|
14
|
-
- Removed `extendDefaultRuntimeCaching`. Use the spread syntax instead (use `import { defaultCache } from "@serwist/next/browser"` to import the default runtimeCaching array).
|
|
15
|
-
- Temporarily removed `fallbacks` to investigate module-friendly alternatives.
|
|
16
|
-
- Removed `swcMinify`.
|
|
17
|
-
- Removed `watchWorkersInDev`.
|
|
18
|
-
- Removed `cacheStartUrl`, `dynamicStartUrl`, and `dynamicStartUrl`. These shall be re-added only when their use cases are made more clear to me.
|
|
19
|
-
- Merged `workboxOptions` with the plugin's options.
|
|
20
|
-
- Removed `swc-loader`, `terser-minify`, `webpack-builders`,... (we now leverage `ChildCompilationPlugin` to compile workers - this change will be backported to `@ducanh2912/next-pwa@10`)
|
|
21
|
-
- Removed the ability to use GenerateSW. `@serwist/sw.installSerwist` is provided as a replacement.
|
|
22
|
-
- `swSrc` is now a required property.
|
|
23
|
-
- Moved minimum support Next.js version from `11.0.0` to `14.0.0`.
|
|
24
|
-
- Removed GenerateSW (replaced by `@serwist/sw.installSerwist`).
|
|
25
|
-
- See `examples/next-basic/app/sw.ts` to see how `installSerwist` should be used.
|
|
26
|
-
- Repurposed `@serwist/sw`.
|
|
27
|
-
- The old package might be reintroduced if there's demand.
|
|
28
|
-
- **Note:** This is just the initial release, and there is still a lot of ground to cover (a lot of legacy code to be removed, a lot of features to be reintroduced,...). Here's to a bright future for the project :\_)
|
|
29
|
-
|
|
30
|
-
### Patch Changes
|
|
31
|
-
|
|
32
|
-
- Updated dependencies [[`e0313f0`](https://github.com/serwist/serwist/commit/e0313f02f661a07ccbe9edc64e44e1af6136c73e)]:
|
|
33
|
-
- @serwist/core@8.0.0
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CacheableResponse.d.ts","sourceRoot":"","sources":["../src/CacheableResponse.ts"],"names":[],"mappings":"AAUA,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB;;;OAGG;IACH,OAAO,CAAC,EAAE;QAAE,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CAC5C;AAED;;;;;GAKG;AACH,cAAM,iBAAiB;IACrB,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAuC;IAClE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAsC;IAEhE;;;;;;;;OAQG;gBACS,MAAM,GAAE,wBAA6B;IAiCjD;;;;;;;;OAQG;IACH,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;CAsDjD;AAED,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CacheableResponsePlugin.d.ts","sourceRoot":"","sources":["../src/CacheableResponsePlugin.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAGvE;;;;GAIG;AACH,cAAM,uBAAwB,YAAW,aAAa;IACpD,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAoB;IAEvD;;;;;;;;OAQG;gBACS,MAAM,EAAE,wBAAwB;IAI5C;;;;OAIG;IACH,eAAe,EAAE,aAAa,CAAC,iBAAiB,CAAC,CAK/C;CACH;AAED,OAAO,EAAE,uBAAuB,EAAE,CAAC"}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,CAAC;AAEtD,YAAY,EAAE,wBAAwB,EAAE,CAAC"}
|
package/rollup.config.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import { getRollupOptions } from "@serwist/constants/rollup";
|
|
3
|
-
|
|
4
|
-
import packageJson from "./package.json" assert { type: "json" };
|
|
5
|
-
|
|
6
|
-
const isDev = process.env.NODE_ENV === "development";
|
|
7
|
-
|
|
8
|
-
export default getRollupOptions({
|
|
9
|
-
packageJson,
|
|
10
|
-
jsFiles: [
|
|
11
|
-
{
|
|
12
|
-
input: "src/index.ts",
|
|
13
|
-
output: [
|
|
14
|
-
{
|
|
15
|
-
file: "dist/index.old.cjs",
|
|
16
|
-
format: "cjs",
|
|
17
|
-
exports: "named",
|
|
18
|
-
},
|
|
19
|
-
{
|
|
20
|
-
file: "dist/index.js",
|
|
21
|
-
format: "esm",
|
|
22
|
-
},
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
shouldEmitDeclaration: !isDev,
|
|
27
|
-
});
|
package/src/CacheableResponse.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
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 { assert, getFriendlyURL, logger, SerwistError } from "@serwist/core/internal";
|
|
10
|
-
|
|
11
|
-
export interface CacheableResponseOptions {
|
|
12
|
-
/**
|
|
13
|
-
* One or more status codes that a `Response` can have to be considered cacheable.
|
|
14
|
-
*/
|
|
15
|
-
statuses?: number[];
|
|
16
|
-
/**
|
|
17
|
-
* A mapping of header names and expected values that a `Response` can have and be
|
|
18
|
-
* considered cacheable. If multiple headers are provided, only one needs to be present.
|
|
19
|
-
*/
|
|
20
|
-
headers?: { [headerName: string]: string };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* This class allows you to set up rules determining what
|
|
25
|
-
* status codes and/or headers need to be present in order for a
|
|
26
|
-
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
27
|
-
* to be considered cacheable.
|
|
28
|
-
*/
|
|
29
|
-
class CacheableResponse {
|
|
30
|
-
private readonly _statuses?: CacheableResponseOptions["statuses"];
|
|
31
|
-
private readonly _headers?: CacheableResponseOptions["headers"];
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* To construct a new CacheableResponse instance you must provide at least
|
|
35
|
-
* one of the `config` properties.
|
|
36
|
-
*
|
|
37
|
-
* If both `statuses` and `headers` are specified, then both conditions must
|
|
38
|
-
* be met for the `Response` to be considered cacheable.
|
|
39
|
-
*
|
|
40
|
-
* @param config
|
|
41
|
-
*/
|
|
42
|
-
constructor(config: CacheableResponseOptions = {}) {
|
|
43
|
-
if (process.env.NODE_ENV !== "production") {
|
|
44
|
-
if (!(config.statuses || config.headers)) {
|
|
45
|
-
throw new SerwistError("statuses-or-headers-required", {
|
|
46
|
-
moduleName: "@serwist/cacheable-response",
|
|
47
|
-
className: "CacheableResponse",
|
|
48
|
-
funcName: "constructor",
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
if (config.statuses) {
|
|
53
|
-
assert!.isArray(config.statuses, {
|
|
54
|
-
moduleName: "@serwist/cacheable-response",
|
|
55
|
-
className: "CacheableResponse",
|
|
56
|
-
funcName: "constructor",
|
|
57
|
-
paramName: "config.statuses",
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (config.headers) {
|
|
62
|
-
assert!.isType(config.headers, "object", {
|
|
63
|
-
moduleName: "@serwist/cacheable-response",
|
|
64
|
-
className: "CacheableResponse",
|
|
65
|
-
funcName: "constructor",
|
|
66
|
-
paramName: "config.headers",
|
|
67
|
-
});
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
this._statuses = config.statuses;
|
|
72
|
-
this._headers = config.headers;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* Checks a response to see whether it's cacheable or not, based on this
|
|
77
|
-
* object's configuration.
|
|
78
|
-
*
|
|
79
|
-
* @param response The response whose cacheability is being
|
|
80
|
-
* checked.
|
|
81
|
-
* @returns `true` if the `Response` is cacheable, and `false`
|
|
82
|
-
* otherwise.
|
|
83
|
-
*/
|
|
84
|
-
isResponseCacheable(response: Response): boolean {
|
|
85
|
-
if (process.env.NODE_ENV !== "production") {
|
|
86
|
-
assert!.isInstance(response, Response, {
|
|
87
|
-
moduleName: "@serwist/cacheable-response",
|
|
88
|
-
className: "CacheableResponse",
|
|
89
|
-
funcName: "isResponseCacheable",
|
|
90
|
-
paramName: "response",
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
let cacheable = true;
|
|
95
|
-
|
|
96
|
-
if (this._statuses) {
|
|
97
|
-
cacheable = this._statuses.includes(response.status);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if (this._headers && cacheable) {
|
|
101
|
-
cacheable = Object.keys(this._headers).some((headerName) => {
|
|
102
|
-
return response.headers.get(headerName) === this._headers![headerName];
|
|
103
|
-
});
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (process.env.NODE_ENV !== "production") {
|
|
107
|
-
if (!cacheable) {
|
|
108
|
-
logger.groupCollapsed(
|
|
109
|
-
`The request for ` + `'${getFriendlyURL(response.url)}' returned a response that does ` + `not meet the criteria for being cached.`
|
|
110
|
-
);
|
|
111
|
-
|
|
112
|
-
logger.groupCollapsed(`View cacheability criteria here.`);
|
|
113
|
-
logger.log(`Cacheable statuses: ` + JSON.stringify(this._statuses));
|
|
114
|
-
logger.log(`Cacheable headers: ` + JSON.stringify(this._headers, null, 2));
|
|
115
|
-
logger.groupEnd();
|
|
116
|
-
|
|
117
|
-
const logFriendlyHeaders: { [key: string]: string } = {};
|
|
118
|
-
response.headers.forEach((value, key) => {
|
|
119
|
-
logFriendlyHeaders[key] = value;
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
logger.groupCollapsed(`View response status and headers here.`);
|
|
123
|
-
logger.log(`Response status: ${response.status}`);
|
|
124
|
-
logger.log(`Response headers: ` + JSON.stringify(logFriendlyHeaders, null, 2));
|
|
125
|
-
logger.groupEnd();
|
|
126
|
-
|
|
127
|
-
logger.groupCollapsed(`View full response details here.`);
|
|
128
|
-
logger.log(response.headers);
|
|
129
|
-
logger.log(response);
|
|
130
|
-
logger.groupEnd();
|
|
131
|
-
|
|
132
|
-
logger.groupEnd();
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
return cacheable;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export { CacheableResponse };
|
|
@@ -1,48 +0,0 @@
|
|
|
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 type { SerwistPlugin } from "@serwist/core";
|
|
10
|
-
|
|
11
|
-
import type { CacheableResponseOptions } from "./CacheableResponse.js";
|
|
12
|
-
import { CacheableResponse } from "./CacheableResponse.js";
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
|
|
16
|
-
* easier to add in cacheability checks to requests made via Serwist's built-in
|
|
17
|
-
* strategies.
|
|
18
|
-
*/
|
|
19
|
-
class CacheableResponsePlugin implements SerwistPlugin {
|
|
20
|
-
private readonly _cacheableResponse: CacheableResponse;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* To construct a new CacheableResponsePlugin instance you must provide at
|
|
24
|
-
* least one of the `config` properties.
|
|
25
|
-
*
|
|
26
|
-
* If both `statuses` and `headers` are specified, then both conditions must
|
|
27
|
-
* be met for the `Response` to be considered cacheable.
|
|
28
|
-
*
|
|
29
|
-
* @param config
|
|
30
|
-
*/
|
|
31
|
-
constructor(config: CacheableResponseOptions) {
|
|
32
|
-
this._cacheableResponse = new CacheableResponse(config);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* @param options
|
|
37
|
-
* @returns
|
|
38
|
-
* @private
|
|
39
|
-
*/
|
|
40
|
-
cacheWillUpdate: SerwistPlugin["cacheWillUpdate"] = async ({ response }) => {
|
|
41
|
-
if (this._cacheableResponse.isResponseCacheable(response)) {
|
|
42
|
-
return response;
|
|
43
|
-
}
|
|
44
|
-
return null;
|
|
45
|
-
};
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export { CacheableResponsePlugin };
|
package/src/index.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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 type { CacheableResponseOptions } from "./CacheableResponse.js";
|
|
10
|
-
import { CacheableResponse } from "./CacheableResponse.js";
|
|
11
|
-
import { CacheableResponsePlugin } from "./CacheableResponsePlugin.js";
|
|
12
|
-
|
|
13
|
-
export { CacheableResponse, CacheableResponsePlugin };
|
|
14
|
-
|
|
15
|
-
export type { CacheableResponseOptions };
|