@netlify/cache 1.1.0 → 1.2.0
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 +90 -67
- package/dist/bootstrap/main.d.cts +5 -24
- package/dist/bootstrap/main.d.ts +5 -24
- package/dist/bootstrap/main.js +93 -85
- package/dist/cache-7ef2f22d.d.ts +30 -0
- package/dist/chunk-I5FZDZ6V.js +46 -0
- package/dist/main.cjs +280 -0
- package/dist/main.d.cts +155 -1
- package/dist/main.d.ts +155 -1
- package/dist/main.js +270 -0
- package/package.json +7 -5
package/dist/bootstrap/main.cjs
CHANGED
|
@@ -43,22 +43,63 @@ __export(main_exports, {
|
|
|
43
43
|
});
|
|
44
44
|
module.exports = __toCommonJS(main_exports);
|
|
45
45
|
|
|
46
|
+
// src/headers.ts
|
|
47
|
+
var ResourceHeaders = "netlify-programmable-headers";
|
|
48
|
+
var ResourceStatus = "netlify-programmable-status";
|
|
49
|
+
var ResourceStore = "netlify-programmable-store";
|
|
50
|
+
var NetlifyForwardedHost = "netlify-forwarded-host";
|
|
51
|
+
var UserAgent = "user-agent";
|
|
52
|
+
|
|
46
53
|
// src/bootstrap/cache.ts
|
|
47
|
-
var import_node_buffer = require("buffer");
|
|
48
|
-
var HEADERS_HEADER = "Netlify-Programmable-Headers";
|
|
49
|
-
var STATUS_HEADER = "Netlify-Programmable-Status";
|
|
50
|
-
var STORE_HEADER = "Netlify-Programmable-Store";
|
|
51
54
|
var allowedProtocols = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
52
55
|
var discardedHeaders = /* @__PURE__ */ new Set(["cookie", "content-encoding", "content-length"]);
|
|
53
|
-
var
|
|
56
|
+
var getInternalHeaders = Symbol("getInternalHeaders");
|
|
57
|
+
var serializeResourceHeaders = Symbol("serializeResourceHeaders");
|
|
58
|
+
var _base64Encode, _getHost, _getToken, _getURL, _name, _userAgent;
|
|
54
59
|
var NetlifyCache = class {
|
|
55
|
-
constructor({ getToken, getURL, name }) {
|
|
60
|
+
constructor({ base64Encode, getHost, getToken, getURL, name, userAgent }) {
|
|
61
|
+
__privateAdd(this, _base64Encode, void 0);
|
|
62
|
+
__privateAdd(this, _getHost, void 0);
|
|
56
63
|
__privateAdd(this, _getToken, void 0);
|
|
57
64
|
__privateAdd(this, _getURL, void 0);
|
|
58
65
|
__privateAdd(this, _name, void 0);
|
|
66
|
+
__privateAdd(this, _userAgent, void 0);
|
|
67
|
+
__privateSet(this, _base64Encode, base64Encode);
|
|
68
|
+
__privateSet(this, _getHost, getHost);
|
|
59
69
|
__privateSet(this, _getToken, getToken);
|
|
60
70
|
__privateSet(this, _getURL, getURL);
|
|
61
71
|
__privateSet(this, _name, name);
|
|
72
|
+
__privateSet(this, _userAgent, userAgent);
|
|
73
|
+
}
|
|
74
|
+
[getInternalHeaders]() {
|
|
75
|
+
var _a;
|
|
76
|
+
const headers = {
|
|
77
|
+
Authorization: `Bearer ${__privateGet(this, _getToken).call(this)}`,
|
|
78
|
+
[ResourceStore]: __privateGet(this, _name)
|
|
79
|
+
};
|
|
80
|
+
const host = (_a = __privateGet(this, _getHost)) == null ? void 0 : _a.call(this);
|
|
81
|
+
if (host) {
|
|
82
|
+
headers[NetlifyForwardedHost] = host;
|
|
83
|
+
}
|
|
84
|
+
if (__privateGet(this, _userAgent)) {
|
|
85
|
+
headers[UserAgent] = __privateGet(this, _userAgent);
|
|
86
|
+
}
|
|
87
|
+
return headers;
|
|
88
|
+
}
|
|
89
|
+
[serializeResourceHeaders](headers) {
|
|
90
|
+
const headersMap = {};
|
|
91
|
+
headers.forEach((value, key) => {
|
|
92
|
+
if (discardedHeaders.has(key)) {
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
if (key === "set-cookie") {
|
|
96
|
+
headersMap[key] = headersMap[key] || [];
|
|
97
|
+
headersMap[key].push(value);
|
|
98
|
+
} else {
|
|
99
|
+
headersMap[key] = value.split(",");
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return __privateGet(this, _base64Encode).call(this, JSON.stringify(headersMap));
|
|
62
103
|
}
|
|
63
104
|
async add(request) {
|
|
64
105
|
await this.put(new Request(request), await fetch(request));
|
|
@@ -66,6 +107,34 @@ var NetlifyCache = class {
|
|
|
66
107
|
async addAll(requests) {
|
|
67
108
|
await Promise.allSettled(requests.map((request) => this.add(request)));
|
|
68
109
|
}
|
|
110
|
+
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
111
|
+
async delete(request) {
|
|
112
|
+
const resourceURL = extractAndValidateURL(request);
|
|
113
|
+
await fetch(`${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`, {
|
|
114
|
+
headers: this[getInternalHeaders](),
|
|
115
|
+
method: "DELETE"
|
|
116
|
+
});
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
120
|
+
async keys(_request) {
|
|
121
|
+
return [];
|
|
122
|
+
}
|
|
123
|
+
async match(request) {
|
|
124
|
+
try {
|
|
125
|
+
const resourceURL = extractAndValidateURL(request);
|
|
126
|
+
const cacheURL = `${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`;
|
|
127
|
+
const response = await fetch(cacheURL, {
|
|
128
|
+
headers: this[getInternalHeaders](),
|
|
129
|
+
method: "GET"
|
|
130
|
+
});
|
|
131
|
+
if (!response.ok) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
return response;
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
}
|
|
69
138
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
70
139
|
async matchAll(request, _options) {
|
|
71
140
|
if (!request) {
|
|
@@ -91,68 +160,22 @@ var NetlifyCache = class {
|
|
|
91
160
|
await fetch(`${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`, {
|
|
92
161
|
body: response.body,
|
|
93
162
|
headers: {
|
|
94
|
-
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
[STORE_HEADER]: __privateGet(this, _name)
|
|
163
|
+
...this[getInternalHeaders](),
|
|
164
|
+
[ResourceHeaders]: this[serializeResourceHeaders](response.headers),
|
|
165
|
+
[ResourceStatus]: response.status.toString()
|
|
98
166
|
},
|
|
99
167
|
// @ts-expect-error https://github.com/whatwg/fetch/pull/1457
|
|
100
168
|
duplex: "half",
|
|
101
169
|
method: "POST"
|
|
102
170
|
});
|
|
103
171
|
}
|
|
104
|
-
async match(request) {
|
|
105
|
-
try {
|
|
106
|
-
const resourceURL = extractAndValidateURL(request);
|
|
107
|
-
const cacheURL = `${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`;
|
|
108
|
-
const response = await fetch(cacheURL, {
|
|
109
|
-
headers: {
|
|
110
|
-
Authorization: `Bearer ${__privateGet(this, _getToken).call(this)}`
|
|
111
|
-
},
|
|
112
|
-
method: "GET"
|
|
113
|
-
});
|
|
114
|
-
if (!response.ok) {
|
|
115
|
-
return;
|
|
116
|
-
}
|
|
117
|
-
return response;
|
|
118
|
-
} catch {
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
122
|
-
async delete(request) {
|
|
123
|
-
const resourceURL = extractAndValidateURL(request);
|
|
124
|
-
await fetch(`${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`, {
|
|
125
|
-
headers: {
|
|
126
|
-
Authorization: `Bearer ${__privateGet(this, _getToken).call(this)}`,
|
|
127
|
-
[STORE_HEADER]: __privateGet(this, _name)
|
|
128
|
-
},
|
|
129
|
-
method: "DELETE"
|
|
130
|
-
});
|
|
131
|
-
return true;
|
|
132
|
-
}
|
|
133
|
-
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
134
|
-
async keys(_request) {
|
|
135
|
-
return [];
|
|
136
|
-
}
|
|
137
172
|
};
|
|
173
|
+
_base64Encode = new WeakMap();
|
|
174
|
+
_getHost = new WeakMap();
|
|
138
175
|
_getToken = new WeakMap();
|
|
139
176
|
_getURL = new WeakMap();
|
|
140
177
|
_name = new WeakMap();
|
|
141
|
-
|
|
142
|
-
const headersMap = {};
|
|
143
|
-
headers.forEach((value, key) => {
|
|
144
|
-
if (discardedHeaders.has(key)) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
if (key === "set-cookie") {
|
|
148
|
-
headersMap[key] = headersMap[key] || [];
|
|
149
|
-
headersMap[key].push(value);
|
|
150
|
-
} else {
|
|
151
|
-
headersMap[key] = value.split(",");
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
return import_node_buffer.Buffer.from(JSON.stringify(headersMap), "utf8").toString("base64");
|
|
155
|
-
};
|
|
178
|
+
_userAgent = new WeakMap();
|
|
156
179
|
var extractAndValidateURL = (input) => {
|
|
157
180
|
let url;
|
|
158
181
|
if (input instanceof Request) {
|
|
@@ -176,20 +199,21 @@ var extractAndValidateURL = (input) => {
|
|
|
176
199
|
var toCacheKey = (url) => encodeURIComponent(url.toString());
|
|
177
200
|
|
|
178
201
|
// src/bootstrap/cachestorage.ts
|
|
179
|
-
var
|
|
202
|
+
var _environmentOptions, _stores;
|
|
180
203
|
var NetlifyCacheStorage = class {
|
|
181
|
-
constructor(
|
|
182
|
-
__privateAdd(this,
|
|
183
|
-
__privateAdd(this, _getURL2, void 0);
|
|
204
|
+
constructor(environmentOptions) {
|
|
205
|
+
__privateAdd(this, _environmentOptions, void 0);
|
|
184
206
|
__privateAdd(this, _stores, void 0);
|
|
185
|
-
__privateSet(this,
|
|
186
|
-
__privateSet(this, _getURL2, getURL);
|
|
207
|
+
__privateSet(this, _environmentOptions, environmentOptions);
|
|
187
208
|
__privateSet(this, _stores, /* @__PURE__ */ new Map());
|
|
188
209
|
}
|
|
189
210
|
open(name) {
|
|
190
211
|
let store = __privateGet(this, _stores).get(name);
|
|
191
212
|
if (!store) {
|
|
192
|
-
store = new NetlifyCache({
|
|
213
|
+
store = new NetlifyCache({
|
|
214
|
+
...__privateGet(this, _environmentOptions),
|
|
215
|
+
name
|
|
216
|
+
});
|
|
193
217
|
__privateGet(this, _stores).set(name, store);
|
|
194
218
|
}
|
|
195
219
|
return Promise.resolve(store);
|
|
@@ -215,8 +239,7 @@ var NetlifyCacheStorage = class {
|
|
|
215
239
|
}
|
|
216
240
|
}
|
|
217
241
|
};
|
|
218
|
-
|
|
219
|
-
_getURL2 = new WeakMap();
|
|
242
|
+
_environmentOptions = new WeakMap();
|
|
220
243
|
_stores = new WeakMap();
|
|
221
244
|
// Annotate the CommonJS export names for ESM import in node:
|
|
222
245
|
0 && (module.exports = {
|
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { E as EnvironmentOptions, F as Factory } from '../cache-7ef2f22d.js';
|
|
2
|
+
export { B as Base64Encoder, N as NetlifyCache } from '../cache-7ef2f22d.js';
|
|
2
3
|
|
|
3
|
-
interface NetlifyCacheOptions {
|
|
4
|
-
getToken: Factory<string>;
|
|
5
|
-
getURL: Factory<string>;
|
|
6
|
-
name: string;
|
|
7
|
-
}
|
|
8
|
-
declare class NetlifyCache implements Cache {
|
|
9
|
-
#private;
|
|
10
|
-
constructor({ getToken, getURL, name }: NetlifyCacheOptions);
|
|
11
|
-
add(request: RequestInfo): Promise<void>;
|
|
12
|
-
addAll(requests: RequestInfo[]): Promise<void>;
|
|
13
|
-
matchAll(request?: RequestInfo, _options?: CacheQueryOptions): Promise<readonly Response[]>;
|
|
14
|
-
put(request: RequestInfo | URL | string, response: Response): Promise<void>;
|
|
15
|
-
match(request: RequestInfo): Promise<Response | undefined>;
|
|
16
|
-
delete(request: RequestInfo): Promise<boolean>;
|
|
17
|
-
keys(_request?: Request): Promise<never[]>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface NetlifyCacheStorageOptions {
|
|
21
|
-
getToken: Factory<string>;
|
|
22
|
-
getURL: Factory<string>;
|
|
23
|
-
}
|
|
24
4
|
declare class NetlifyCacheStorage {
|
|
25
5
|
#private;
|
|
26
|
-
constructor(
|
|
6
|
+
constructor(environmentOptions: EnvironmentOptions);
|
|
27
7
|
open(name: string): Promise<Cache>;
|
|
28
8
|
has(name: string): Promise<boolean>;
|
|
29
9
|
delete(name: string): Promise<boolean>;
|
|
@@ -31,7 +11,8 @@ declare class NetlifyCacheStorage {
|
|
|
31
11
|
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
|
|
32
12
|
}
|
|
33
13
|
|
|
14
|
+
type HostFactory = Factory<string>;
|
|
34
15
|
type TokenFactory = Factory<string>;
|
|
35
16
|
type URLFactory = Factory<string>;
|
|
36
17
|
|
|
37
|
-
export {
|
|
18
|
+
export { HostFactory, NetlifyCacheStorage, TokenFactory, URLFactory };
|
package/dist/bootstrap/main.d.ts
CHANGED
|
@@ -1,29 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import { E as EnvironmentOptions, F as Factory } from '../cache-7ef2f22d.js';
|
|
2
|
+
export { B as Base64Encoder, N as NetlifyCache } from '../cache-7ef2f22d.js';
|
|
2
3
|
|
|
3
|
-
interface NetlifyCacheOptions {
|
|
4
|
-
getToken: Factory<string>;
|
|
5
|
-
getURL: Factory<string>;
|
|
6
|
-
name: string;
|
|
7
|
-
}
|
|
8
|
-
declare class NetlifyCache implements Cache {
|
|
9
|
-
#private;
|
|
10
|
-
constructor({ getToken, getURL, name }: NetlifyCacheOptions);
|
|
11
|
-
add(request: RequestInfo): Promise<void>;
|
|
12
|
-
addAll(requests: RequestInfo[]): Promise<void>;
|
|
13
|
-
matchAll(request?: RequestInfo, _options?: CacheQueryOptions): Promise<readonly Response[]>;
|
|
14
|
-
put(request: RequestInfo | URL | string, response: Response): Promise<void>;
|
|
15
|
-
match(request: RequestInfo): Promise<Response | undefined>;
|
|
16
|
-
delete(request: RequestInfo): Promise<boolean>;
|
|
17
|
-
keys(_request?: Request): Promise<never[]>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface NetlifyCacheStorageOptions {
|
|
21
|
-
getToken: Factory<string>;
|
|
22
|
-
getURL: Factory<string>;
|
|
23
|
-
}
|
|
24
4
|
declare class NetlifyCacheStorage {
|
|
25
5
|
#private;
|
|
26
|
-
constructor(
|
|
6
|
+
constructor(environmentOptions: EnvironmentOptions);
|
|
27
7
|
open(name: string): Promise<Cache>;
|
|
28
8
|
has(name: string): Promise<boolean>;
|
|
29
9
|
delete(name: string): Promise<boolean>;
|
|
@@ -31,7 +11,8 @@ declare class NetlifyCacheStorage {
|
|
|
31
11
|
match(request: RequestInfo, options?: MultiCacheQueryOptions): Promise<Response | undefined>;
|
|
32
12
|
}
|
|
33
13
|
|
|
14
|
+
type HostFactory = Factory<string>;
|
|
34
15
|
type TokenFactory = Factory<string>;
|
|
35
16
|
type URLFactory = Factory<string>;
|
|
36
17
|
|
|
37
|
-
export {
|
|
18
|
+
export { HostFactory, NetlifyCacheStorage, TokenFactory, URLFactory };
|
package/dist/bootstrap/main.js
CHANGED
|
@@ -1,38 +1,64 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
-
};
|
|
14
|
-
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
-
__accessCheck(obj, member, "write to private field");
|
|
16
|
-
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
-
return value;
|
|
18
|
-
};
|
|
1
|
+
import {
|
|
2
|
+
NetlifyForwardedHost,
|
|
3
|
+
ResourceHeaders,
|
|
4
|
+
ResourceStatus,
|
|
5
|
+
ResourceStore,
|
|
6
|
+
UserAgent,
|
|
7
|
+
__privateAdd,
|
|
8
|
+
__privateGet,
|
|
9
|
+
__privateSet
|
|
10
|
+
} from "../chunk-I5FZDZ6V.js";
|
|
19
11
|
|
|
20
12
|
// src/bootstrap/cache.ts
|
|
21
|
-
import { Buffer as Buffer2 } from "buffer";
|
|
22
|
-
var HEADERS_HEADER = "Netlify-Programmable-Headers";
|
|
23
|
-
var STATUS_HEADER = "Netlify-Programmable-Status";
|
|
24
|
-
var STORE_HEADER = "Netlify-Programmable-Store";
|
|
25
13
|
var allowedProtocols = /* @__PURE__ */ new Set(["http:", "https:"]);
|
|
26
14
|
var discardedHeaders = /* @__PURE__ */ new Set(["cookie", "content-encoding", "content-length"]);
|
|
27
|
-
var
|
|
15
|
+
var getInternalHeaders = Symbol("getInternalHeaders");
|
|
16
|
+
var serializeResourceHeaders = Symbol("serializeResourceHeaders");
|
|
17
|
+
var _base64Encode, _getHost, _getToken, _getURL, _name, _userAgent;
|
|
28
18
|
var NetlifyCache = class {
|
|
29
|
-
constructor({ getToken, getURL, name }) {
|
|
19
|
+
constructor({ base64Encode, getHost, getToken, getURL, name, userAgent }) {
|
|
20
|
+
__privateAdd(this, _base64Encode, void 0);
|
|
21
|
+
__privateAdd(this, _getHost, void 0);
|
|
30
22
|
__privateAdd(this, _getToken, void 0);
|
|
31
23
|
__privateAdd(this, _getURL, void 0);
|
|
32
24
|
__privateAdd(this, _name, void 0);
|
|
25
|
+
__privateAdd(this, _userAgent, void 0);
|
|
26
|
+
__privateSet(this, _base64Encode, base64Encode);
|
|
27
|
+
__privateSet(this, _getHost, getHost);
|
|
33
28
|
__privateSet(this, _getToken, getToken);
|
|
34
29
|
__privateSet(this, _getURL, getURL);
|
|
35
30
|
__privateSet(this, _name, name);
|
|
31
|
+
__privateSet(this, _userAgent, userAgent);
|
|
32
|
+
}
|
|
33
|
+
[getInternalHeaders]() {
|
|
34
|
+
var _a;
|
|
35
|
+
const headers = {
|
|
36
|
+
Authorization: `Bearer ${__privateGet(this, _getToken).call(this)}`,
|
|
37
|
+
[ResourceStore]: __privateGet(this, _name)
|
|
38
|
+
};
|
|
39
|
+
const host = (_a = __privateGet(this, _getHost)) == null ? void 0 : _a.call(this);
|
|
40
|
+
if (host) {
|
|
41
|
+
headers[NetlifyForwardedHost] = host;
|
|
42
|
+
}
|
|
43
|
+
if (__privateGet(this, _userAgent)) {
|
|
44
|
+
headers[UserAgent] = __privateGet(this, _userAgent);
|
|
45
|
+
}
|
|
46
|
+
return headers;
|
|
47
|
+
}
|
|
48
|
+
[serializeResourceHeaders](headers) {
|
|
49
|
+
const headersMap = {};
|
|
50
|
+
headers.forEach((value, key) => {
|
|
51
|
+
if (discardedHeaders.has(key)) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (key === "set-cookie") {
|
|
55
|
+
headersMap[key] = headersMap[key] || [];
|
|
56
|
+
headersMap[key].push(value);
|
|
57
|
+
} else {
|
|
58
|
+
headersMap[key] = value.split(",");
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
return __privateGet(this, _base64Encode).call(this, JSON.stringify(headersMap));
|
|
36
62
|
}
|
|
37
63
|
async add(request) {
|
|
38
64
|
await this.put(new Request(request), await fetch(request));
|
|
@@ -40,6 +66,34 @@ var NetlifyCache = class {
|
|
|
40
66
|
async addAll(requests) {
|
|
41
67
|
await Promise.allSettled(requests.map((request) => this.add(request)));
|
|
42
68
|
}
|
|
69
|
+
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
70
|
+
async delete(request) {
|
|
71
|
+
const resourceURL = extractAndValidateURL(request);
|
|
72
|
+
await fetch(`${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`, {
|
|
73
|
+
headers: this[getInternalHeaders](),
|
|
74
|
+
method: "DELETE"
|
|
75
|
+
});
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
79
|
+
async keys(_request) {
|
|
80
|
+
return [];
|
|
81
|
+
}
|
|
82
|
+
async match(request) {
|
|
83
|
+
try {
|
|
84
|
+
const resourceURL = extractAndValidateURL(request);
|
|
85
|
+
const cacheURL = `${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`;
|
|
86
|
+
const response = await fetch(cacheURL, {
|
|
87
|
+
headers: this[getInternalHeaders](),
|
|
88
|
+
method: "GET"
|
|
89
|
+
});
|
|
90
|
+
if (!response.ok) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
return response;
|
|
94
|
+
} catch {
|
|
95
|
+
}
|
|
96
|
+
}
|
|
43
97
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
44
98
|
async matchAll(request, _options) {
|
|
45
99
|
if (!request) {
|
|
@@ -65,68 +119,22 @@ var NetlifyCache = class {
|
|
|
65
119
|
await fetch(`${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`, {
|
|
66
120
|
body: response.body,
|
|
67
121
|
headers: {
|
|
68
|
-
|
|
69
|
-
[
|
|
70
|
-
[
|
|
71
|
-
[STORE_HEADER]: __privateGet(this, _name)
|
|
122
|
+
...this[getInternalHeaders](),
|
|
123
|
+
[ResourceHeaders]: this[serializeResourceHeaders](response.headers),
|
|
124
|
+
[ResourceStatus]: response.status.toString()
|
|
72
125
|
},
|
|
73
126
|
// @ts-expect-error https://github.com/whatwg/fetch/pull/1457
|
|
74
127
|
duplex: "half",
|
|
75
128
|
method: "POST"
|
|
76
129
|
});
|
|
77
130
|
}
|
|
78
|
-
async match(request) {
|
|
79
|
-
try {
|
|
80
|
-
const resourceURL = extractAndValidateURL(request);
|
|
81
|
-
const cacheURL = `${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`;
|
|
82
|
-
const response = await fetch(cacheURL, {
|
|
83
|
-
headers: {
|
|
84
|
-
Authorization: `Bearer ${__privateGet(this, _getToken).call(this)}`
|
|
85
|
-
},
|
|
86
|
-
method: "GET"
|
|
87
|
-
});
|
|
88
|
-
if (!response.ok) {
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
return response;
|
|
92
|
-
} catch {
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
96
|
-
async delete(request) {
|
|
97
|
-
const resourceURL = extractAndValidateURL(request);
|
|
98
|
-
await fetch(`${__privateGet(this, _getURL).call(this)}/${toCacheKey(resourceURL)}`, {
|
|
99
|
-
headers: {
|
|
100
|
-
Authorization: `Bearer ${__privateGet(this, _getToken).call(this)}`,
|
|
101
|
-
[STORE_HEADER]: __privateGet(this, _name)
|
|
102
|
-
},
|
|
103
|
-
method: "DELETE"
|
|
104
|
-
});
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
// eslint-disable-next-line class-methods-use-this, require-await, @typescript-eslint/no-unused-vars
|
|
108
|
-
async keys(_request) {
|
|
109
|
-
return [];
|
|
110
|
-
}
|
|
111
131
|
};
|
|
132
|
+
_base64Encode = new WeakMap();
|
|
133
|
+
_getHost = new WeakMap();
|
|
112
134
|
_getToken = new WeakMap();
|
|
113
135
|
_getURL = new WeakMap();
|
|
114
136
|
_name = new WeakMap();
|
|
115
|
-
|
|
116
|
-
const headersMap = {};
|
|
117
|
-
headers.forEach((value, key) => {
|
|
118
|
-
if (discardedHeaders.has(key)) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
if (key === "set-cookie") {
|
|
122
|
-
headersMap[key] = headersMap[key] || [];
|
|
123
|
-
headersMap[key].push(value);
|
|
124
|
-
} else {
|
|
125
|
-
headersMap[key] = value.split(",");
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
|
-
return Buffer2.from(JSON.stringify(headersMap), "utf8").toString("base64");
|
|
129
|
-
};
|
|
137
|
+
_userAgent = new WeakMap();
|
|
130
138
|
var extractAndValidateURL = (input) => {
|
|
131
139
|
let url;
|
|
132
140
|
if (input instanceof Request) {
|
|
@@ -150,20 +158,21 @@ var extractAndValidateURL = (input) => {
|
|
|
150
158
|
var toCacheKey = (url) => encodeURIComponent(url.toString());
|
|
151
159
|
|
|
152
160
|
// src/bootstrap/cachestorage.ts
|
|
153
|
-
var
|
|
161
|
+
var _environmentOptions, _stores;
|
|
154
162
|
var NetlifyCacheStorage = class {
|
|
155
|
-
constructor(
|
|
156
|
-
__privateAdd(this,
|
|
157
|
-
__privateAdd(this, _getURL2, void 0);
|
|
163
|
+
constructor(environmentOptions) {
|
|
164
|
+
__privateAdd(this, _environmentOptions, void 0);
|
|
158
165
|
__privateAdd(this, _stores, void 0);
|
|
159
|
-
__privateSet(this,
|
|
160
|
-
__privateSet(this, _getURL2, getURL);
|
|
166
|
+
__privateSet(this, _environmentOptions, environmentOptions);
|
|
161
167
|
__privateSet(this, _stores, /* @__PURE__ */ new Map());
|
|
162
168
|
}
|
|
163
169
|
open(name) {
|
|
164
170
|
let store = __privateGet(this, _stores).get(name);
|
|
165
171
|
if (!store) {
|
|
166
|
-
store = new NetlifyCache({
|
|
172
|
+
store = new NetlifyCache({
|
|
173
|
+
...__privateGet(this, _environmentOptions),
|
|
174
|
+
name
|
|
175
|
+
});
|
|
167
176
|
__privateGet(this, _stores).set(name, store);
|
|
168
177
|
}
|
|
169
178
|
return Promise.resolve(store);
|
|
@@ -189,8 +198,7 @@ var NetlifyCacheStorage = class {
|
|
|
189
198
|
}
|
|
190
199
|
}
|
|
191
200
|
};
|
|
192
|
-
|
|
193
|
-
_getURL2 = new WeakMap();
|
|
201
|
+
_environmentOptions = new WeakMap();
|
|
194
202
|
_stores = new WeakMap();
|
|
195
203
|
export {
|
|
196
204
|
NetlifyCache,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
type Base64Encoder = (input: string) => string;
|
|
2
|
+
type Factory<T> = () => T;
|
|
3
|
+
interface EnvironmentOptions {
|
|
4
|
+
base64Encode: Base64Encoder;
|
|
5
|
+
getHost: Factory<string>;
|
|
6
|
+
getToken: Factory<string>;
|
|
7
|
+
getURL: Factory<string>;
|
|
8
|
+
userAgent?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
type NetlifyCacheOptions = EnvironmentOptions & {
|
|
12
|
+
name: string;
|
|
13
|
+
};
|
|
14
|
+
declare const getInternalHeaders: unique symbol;
|
|
15
|
+
declare const serializeResourceHeaders: unique symbol;
|
|
16
|
+
declare class NetlifyCache implements Cache {
|
|
17
|
+
#private;
|
|
18
|
+
constructor({ base64Encode, getHost, getToken, getURL, name, userAgent }: NetlifyCacheOptions);
|
|
19
|
+
private [getInternalHeaders];
|
|
20
|
+
private [serializeResourceHeaders];
|
|
21
|
+
add(request: RequestInfo): Promise<void>;
|
|
22
|
+
addAll(requests: RequestInfo[]): Promise<void>;
|
|
23
|
+
delete(request: RequestInfo): Promise<boolean>;
|
|
24
|
+
keys(_request?: Request): Promise<never[]>;
|
|
25
|
+
match(request: RequestInfo): Promise<Response | undefined>;
|
|
26
|
+
matchAll(request?: RequestInfo, _options?: CacheQueryOptions): Promise<readonly Response[]>;
|
|
27
|
+
put(request: RequestInfo | URL | string, response: Response): Promise<void>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export { Base64Encoder as B, EnvironmentOptions as E, Factory as F, NetlifyCache as N };
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2
|
+
if (!member.has(obj))
|
|
3
|
+
throw TypeError("Cannot " + msg);
|
|
4
|
+
};
|
|
5
|
+
var __privateGet = (obj, member, getter) => {
|
|
6
|
+
__accessCheck(obj, member, "read from private field");
|
|
7
|
+
return getter ? getter.call(obj) : member.get(obj);
|
|
8
|
+
};
|
|
9
|
+
var __privateAdd = (obj, member, value) => {
|
|
10
|
+
if (member.has(obj))
|
|
11
|
+
throw TypeError("Cannot add the same private member more than once");
|
|
12
|
+
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
13
|
+
};
|
|
14
|
+
var __privateSet = (obj, member, value, setter) => {
|
|
15
|
+
__accessCheck(obj, member, "write to private field");
|
|
16
|
+
setter ? setter.call(obj, value) : member.set(obj, value);
|
|
17
|
+
return value;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
// src/headers.ts
|
|
21
|
+
var CacheStatus = "cache-status";
|
|
22
|
+
var NetlifyCacheId = "netlify-cache-id";
|
|
23
|
+
var NetlifyCacheTag = "netlify-cache-tag";
|
|
24
|
+
var NetlifyCdnCacheControl = "netlify-cdn-cache-control";
|
|
25
|
+
var NetlifyVary = "netlify-vary";
|
|
26
|
+
var ResourceHeaders = "netlify-programmable-headers";
|
|
27
|
+
var ResourceStatus = "netlify-programmable-status";
|
|
28
|
+
var ResourceStore = "netlify-programmable-store";
|
|
29
|
+
var NetlifyForwardedHost = "netlify-forwarded-host";
|
|
30
|
+
var UserAgent = "user-agent";
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
__privateGet,
|
|
34
|
+
__privateAdd,
|
|
35
|
+
__privateSet,
|
|
36
|
+
CacheStatus,
|
|
37
|
+
NetlifyCacheId,
|
|
38
|
+
NetlifyCacheTag,
|
|
39
|
+
NetlifyCdnCacheControl,
|
|
40
|
+
NetlifyVary,
|
|
41
|
+
ResourceHeaders,
|
|
42
|
+
ResourceStatus,
|
|
43
|
+
ResourceStore,
|
|
44
|
+
NetlifyForwardedHost,
|
|
45
|
+
UserAgent
|
|
46
|
+
};
|