@netlify/cache 1.5.0 → 1.6.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/bootstrap/main.cjs +28 -10
- package/dist/bootstrap/main.d.cts +2 -2
- package/dist/bootstrap/main.d.ts +2 -2
- package/dist/bootstrap/main.js +26 -9
- package/dist/{cache-854474ad.d.ts → cache-fc378069.d.ts} +9 -2
- package/dist/main.d.cts +1 -1
- package/dist/main.d.ts +1 -1
- package/package.json +1 -1
package/dist/bootstrap/main.cjs
CHANGED
|
@@ -39,10 +39,19 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
39
39
|
var main_exports = {};
|
|
40
40
|
__export(main_exports, {
|
|
41
41
|
NetlifyCache: () => NetlifyCache,
|
|
42
|
-
NetlifyCacheStorage: () => NetlifyCacheStorage
|
|
42
|
+
NetlifyCacheStorage: () => NetlifyCacheStorage,
|
|
43
|
+
Operation: () => Operation
|
|
43
44
|
});
|
|
44
45
|
module.exports = __toCommonJS(main_exports);
|
|
45
46
|
|
|
47
|
+
// src/bootstrap/environment.ts
|
|
48
|
+
var Operation = /* @__PURE__ */ ((Operation2) => {
|
|
49
|
+
Operation2["Delete"] = "delete";
|
|
50
|
+
Operation2["Read"] = "read";
|
|
51
|
+
Operation2["Write"] = "write";
|
|
52
|
+
return Operation2;
|
|
53
|
+
})(Operation || {});
|
|
54
|
+
|
|
46
55
|
// src/bootstrap/errors.ts
|
|
47
56
|
var ERROR_CODES = {
|
|
48
57
|
invalid_vary: "Responses must not use unsupported directives of the `Netlify-Vary` header (https://ntl.fyi/cache_api_invalid_vary).",
|
|
@@ -118,12 +127,14 @@ var NetlifyCache = class {
|
|
|
118
127
|
}
|
|
119
128
|
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
120
129
|
async delete(request) {
|
|
121
|
-
const context = __privateGet(this, _getContext).call(this);
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
130
|
+
const context = __privateGet(this, _getContext).call(this, { operation: "delete" /* Delete */ });
|
|
131
|
+
if (context) {
|
|
132
|
+
const resourceURL = extractAndValidateURL(request);
|
|
133
|
+
await fetch(`${context.url}/${toCacheKey(resourceURL)}`, {
|
|
134
|
+
headers: this[getInternalHeaders](context),
|
|
135
|
+
method: "DELETE"
|
|
136
|
+
});
|
|
137
|
+
}
|
|
127
138
|
return true;
|
|
128
139
|
}
|
|
129
140
|
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
@@ -132,7 +143,10 @@ var NetlifyCache = class {
|
|
|
132
143
|
}
|
|
133
144
|
async match(request) {
|
|
134
145
|
try {
|
|
135
|
-
const context = __privateGet(this, _getContext).call(this);
|
|
146
|
+
const context = __privateGet(this, _getContext).call(this, { operation: "read" /* Read */ });
|
|
147
|
+
if (!context) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
136
150
|
const resourceURL = extractAndValidateURL(request);
|
|
137
151
|
const cacheURL = `${context.url}/${toCacheKey(resourceURL)}`;
|
|
138
152
|
const response = await fetch(cacheURL, {
|
|
@@ -167,7 +181,10 @@ var NetlifyCache = class {
|
|
|
167
181
|
if (response.headers.get("vary")?.includes("*")) {
|
|
168
182
|
throw new TypeError("Cannot cache response with 'Vary: *' header.");
|
|
169
183
|
}
|
|
170
|
-
const context = __privateGet(this, _getContext).call(this);
|
|
184
|
+
const context = __privateGet(this, _getContext).call(this, { operation: "write" /* Write */ });
|
|
185
|
+
if (!context) {
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
171
188
|
const resourceURL = extractAndValidateURL(request);
|
|
172
189
|
const cacheResponse = await fetch(`${context.url}/${toCacheKey(resourceURL)}`, {
|
|
173
190
|
body: response.body,
|
|
@@ -259,5 +276,6 @@ _stores = new WeakMap();
|
|
|
259
276
|
// Annotate the CommonJS export names for ESM import in node:
|
|
260
277
|
0 && (module.exports = {
|
|
261
278
|
NetlifyCache,
|
|
262
|
-
NetlifyCacheStorage
|
|
279
|
+
NetlifyCacheStorage,
|
|
280
|
+
Operation
|
|
263
281
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EnvironmentOptions } from '../cache-
|
|
2
|
-
export { B as Base64Encoder, N as NetlifyCache, R as RequestContextFactory } from '../cache-
|
|
1
|
+
import { E as EnvironmentOptions } from '../cache-fc378069.js';
|
|
2
|
+
export { B as Base64Encoder, N as NetlifyCache, O as Operation, R as RequestContextFactory } from '../cache-fc378069.js';
|
|
3
3
|
|
|
4
4
|
declare class NetlifyCacheStorage {
|
|
5
5
|
#private;
|
package/dist/bootstrap/main.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { E as EnvironmentOptions } from '../cache-
|
|
2
|
-
export { B as Base64Encoder, N as NetlifyCache, R as RequestContextFactory } from '../cache-
|
|
1
|
+
import { E as EnvironmentOptions } from '../cache-fc378069.js';
|
|
2
|
+
export { B as Base64Encoder, N as NetlifyCache, O as Operation, R as RequestContextFactory } from '../cache-fc378069.js';
|
|
3
3
|
|
|
4
4
|
declare class NetlifyCacheStorage {
|
|
5
5
|
#private;
|
package/dist/bootstrap/main.js
CHANGED
|
@@ -17,6 +17,14 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
17
17
|
return value;
|
|
18
18
|
};
|
|
19
19
|
|
|
20
|
+
// src/bootstrap/environment.ts
|
|
21
|
+
var Operation = /* @__PURE__ */ ((Operation2) => {
|
|
22
|
+
Operation2["Delete"] = "delete";
|
|
23
|
+
Operation2["Read"] = "read";
|
|
24
|
+
Operation2["Write"] = "write";
|
|
25
|
+
return Operation2;
|
|
26
|
+
})(Operation || {});
|
|
27
|
+
|
|
20
28
|
// src/bootstrap/errors.ts
|
|
21
29
|
var ERROR_CODES = {
|
|
22
30
|
invalid_vary: "Responses must not use unsupported directives of the `Netlify-Vary` header (https://ntl.fyi/cache_api_invalid_vary).",
|
|
@@ -92,12 +100,14 @@ var NetlifyCache = class {
|
|
|
92
100
|
}
|
|
93
101
|
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
94
102
|
async delete(request) {
|
|
95
|
-
const context = __privateGet(this, _getContext).call(this);
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
103
|
+
const context = __privateGet(this, _getContext).call(this, { operation: "delete" /* Delete */ });
|
|
104
|
+
if (context) {
|
|
105
|
+
const resourceURL = extractAndValidateURL(request);
|
|
106
|
+
await fetch(`${context.url}/${toCacheKey(resourceURL)}`, {
|
|
107
|
+
headers: this[getInternalHeaders](context),
|
|
108
|
+
method: "DELETE"
|
|
109
|
+
});
|
|
110
|
+
}
|
|
101
111
|
return true;
|
|
102
112
|
}
|
|
103
113
|
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
@@ -106,7 +116,10 @@ var NetlifyCache = class {
|
|
|
106
116
|
}
|
|
107
117
|
async match(request) {
|
|
108
118
|
try {
|
|
109
|
-
const context = __privateGet(this, _getContext).call(this);
|
|
119
|
+
const context = __privateGet(this, _getContext).call(this, { operation: "read" /* Read */ });
|
|
120
|
+
if (!context) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
110
123
|
const resourceURL = extractAndValidateURL(request);
|
|
111
124
|
const cacheURL = `${context.url}/${toCacheKey(resourceURL)}`;
|
|
112
125
|
const response = await fetch(cacheURL, {
|
|
@@ -141,7 +154,10 @@ var NetlifyCache = class {
|
|
|
141
154
|
if (response.headers.get("vary")?.includes("*")) {
|
|
142
155
|
throw new TypeError("Cannot cache response with 'Vary: *' header.");
|
|
143
156
|
}
|
|
144
|
-
const context = __privateGet(this, _getContext).call(this);
|
|
157
|
+
const context = __privateGet(this, _getContext).call(this, { operation: "write" /* Write */ });
|
|
158
|
+
if (!context) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
145
161
|
const resourceURL = extractAndValidateURL(request);
|
|
146
162
|
const cacheResponse = await fetch(`${context.url}/${toCacheKey(resourceURL)}`, {
|
|
147
163
|
body: response.body,
|
|
@@ -232,5 +248,6 @@ _environmentOptions = new WeakMap();
|
|
|
232
248
|
_stores = new WeakMap();
|
|
233
249
|
export {
|
|
234
250
|
NetlifyCache,
|
|
235
|
-
NetlifyCacheStorage
|
|
251
|
+
NetlifyCacheStorage,
|
|
252
|
+
Operation
|
|
236
253
|
};
|
|
@@ -4,7 +4,14 @@ interface EnvironmentOptions {
|
|
|
4
4
|
getContext: RequestContextFactory;
|
|
5
5
|
userAgent?: string;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
declare enum Operation {
|
|
8
|
+
Delete = "delete",
|
|
9
|
+
Read = "read",
|
|
10
|
+
Write = "write"
|
|
11
|
+
}
|
|
12
|
+
type RequestContextFactory = (options: {
|
|
13
|
+
operation: Operation;
|
|
14
|
+
}) => RequestContext | null;
|
|
8
15
|
interface RequestContext {
|
|
9
16
|
host: string;
|
|
10
17
|
token: string;
|
|
@@ -30,4 +37,4 @@ declare class NetlifyCache implements Cache {
|
|
|
30
37
|
put(request: RequestInfo | URL | string, response: Response): Promise<void>;
|
|
31
38
|
}
|
|
32
39
|
|
|
33
|
-
export { Base64Encoder as B, EnvironmentOptions as E, NetlifyCache as N, RequestContextFactory as R };
|
|
40
|
+
export { Base64Encoder as B, EnvironmentOptions as E, NetlifyCache as N, Operation as O, RequestContextFactory as R };
|
package/dist/main.d.cts
CHANGED
package/dist/main.d.ts
CHANGED