@serwist/cacheable-response 9.0.0-preview.0 → 9.0.0-preview.10
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/index.js +6 -43
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,22 +1,9 @@
|
|
|
1
1
|
import { SerwistError, assert, logger, getFriendlyURL } from '@serwist/core/internal';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* This class allows you to set up rules determining what
|
|
5
|
-
* status codes and/or headers need to be present in order for a
|
|
6
|
-
* [`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response)
|
|
7
|
-
* to be considered cacheable.
|
|
8
|
-
*/ class CacheableResponse {
|
|
3
|
+
class CacheableResponse {
|
|
9
4
|
_statuses;
|
|
10
5
|
_headers;
|
|
11
|
-
|
|
12
|
-
* To construct a new CacheableResponse instance you must provide at least
|
|
13
|
-
* one of the `config` properties.
|
|
14
|
-
*
|
|
15
|
-
* If both `statuses` and `headers` are specified, then both conditions must
|
|
16
|
-
* be met for the `Response` to be considered cacheable.
|
|
17
|
-
*
|
|
18
|
-
* @param config
|
|
19
|
-
*/ constructor(config = {}){
|
|
6
|
+
constructor(config = {}){
|
|
20
7
|
if (process.env.NODE_ENV !== "production") {
|
|
21
8
|
if (!(config.statuses || config.headers)) {
|
|
22
9
|
throw new SerwistError("statuses-or-headers-required", {
|
|
@@ -45,15 +32,7 @@ import { SerwistError, assert, logger, getFriendlyURL } from '@serwist/core/inte
|
|
|
45
32
|
this._statuses = config.statuses;
|
|
46
33
|
this._headers = config.headers;
|
|
47
34
|
}
|
|
48
|
-
|
|
49
|
-
* Checks a response to see whether it's cacheable or not, based on this
|
|
50
|
-
* object's configuration.
|
|
51
|
-
*
|
|
52
|
-
* @param response The response whose cacheability is being
|
|
53
|
-
* checked.
|
|
54
|
-
* @returns `true` if the `Response` is cacheable, and `false`
|
|
55
|
-
* otherwise.
|
|
56
|
-
*/ isResponseCacheable(response) {
|
|
35
|
+
isResponseCacheable(response) {
|
|
57
36
|
if (process.env.NODE_ENV !== "production") {
|
|
58
37
|
assert.isInstance(response, Response, {
|
|
59
38
|
moduleName: "@serwist/cacheable-response",
|
|
@@ -97,28 +76,12 @@ import { SerwistError, assert, logger, getFriendlyURL } from '@serwist/core/inte
|
|
|
97
76
|
}
|
|
98
77
|
}
|
|
99
78
|
|
|
100
|
-
|
|
101
|
-
* A class implementing the `cacheWillUpdate` lifecycle callback. This makes it
|
|
102
|
-
* easier to add in cacheability checks to requests made via Serwist's built-in
|
|
103
|
-
* strategies.
|
|
104
|
-
*/ class CacheableResponsePlugin {
|
|
79
|
+
class CacheableResponsePlugin {
|
|
105
80
|
_cacheableResponse;
|
|
106
|
-
|
|
107
|
-
* To construct a new CacheableResponsePlugin instance you must provide at
|
|
108
|
-
* least one of the `config` properties.
|
|
109
|
-
*
|
|
110
|
-
* If both `statuses` and `headers` are specified, then both conditions must
|
|
111
|
-
* be met for the `Response` to be considered cacheable.
|
|
112
|
-
*
|
|
113
|
-
* @param config
|
|
114
|
-
*/ constructor(config){
|
|
81
|
+
constructor(config){
|
|
115
82
|
this._cacheableResponse = new CacheableResponse(config);
|
|
116
83
|
}
|
|
117
|
-
|
|
118
|
-
* @param options
|
|
119
|
-
* @returns
|
|
120
|
-
* @private
|
|
121
|
-
*/ cacheWillUpdate = async ({ response })=>{
|
|
84
|
+
cacheWillUpdate = async ({ response })=>{
|
|
122
85
|
if (this._cacheableResponse.isResponseCacheable(response)) {
|
|
123
86
|
return response;
|
|
124
87
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@serwist/cacheable-response",
|
|
3
|
-
"version": "9.0.0-preview.
|
|
3
|
+
"version": "9.0.0-preview.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "This library takes a Response object and determines whether it's cacheable based on a specific configuration.",
|
|
6
6
|
"files": [
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"./package.json": "./package.json"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@serwist/core": "9.0.0-preview.
|
|
32
|
+
"@serwist/core": "9.0.0-preview.10"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"rollup": "4.9.6",
|
|
36
|
-
"typescript": "5.4.0-dev.
|
|
37
|
-
"@serwist/constants": "9.0.0-preview.
|
|
36
|
+
"typescript": "5.4.0-dev.20240206",
|
|
37
|
+
"@serwist/constants": "9.0.0-preview.10"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
40
|
"typescript": ">=5.0.0"
|