cacheable-request 13.0.9 → 13.0.11

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.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Keyv } from 'keyv';
2
- import { RequestFn, CacheResponse, CacheValue, CacheableOptions, Emitter } from './types.js';
1
+ import { Keyv } from "keyv";
2
+ import { type CacheableOptions, type CacheResponse, type CacheValue, type Emitter, type RequestFn } from "./types.js";
3
3
  type Function_ = (...arguments_: any[]) => any;
4
4
  declare class CacheableRequest {
5
5
  cache: Keyv;
@@ -29,6 +29,6 @@ export declare const parseWithWhatwg: (raw: string) => {
29
29
  href: string;
30
30
  };
31
31
  export default CacheableRequest;
32
- export * from './types.js';
32
+ export * from "./types.js";
33
33
  export declare const onResponse = "onResponse";
34
34
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAC,IAAI,EAAC,MAAM,MAAM,CAAC;AAE1B,OAAO,EACN,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EAAuC,OAAO,EACpG,MAAM,YAAY,CAAC;AAGpB,KAAK,SAAS,GAAG,CAAC,GAAG,UAAU,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAE/C,cAAM,gBAAgB;IACrB,KAAK,EAAE,IAAI,CAAmD;IAC9D,YAAY,EAAE,SAAS,CAAC;IACxB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,CAAC,CAAgC;gBACjD,YAAY,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,GAAG;IAgBvD,OAAO,SACN,SAAS,gBAAgB,EACzB,WAAW,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,KAC1C,OAAO,CAyNR;IAEF,OAAO,GAAI,MAAM,MAAM,EAAE,WAAW,SAAS,UAI3C;IAEF,UAAU,GAAI,M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;;;;;;;;;;;CAmB1C,CAAC;AAEF,eAAe,gBAAgB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,eAAO,MAAM,UAAU,eAAe,CAAC"}
package/dist/index.js CHANGED
@@ -1,21 +1,23 @@
1
- import EventEmitter from 'node:events';
2
- import urlLib, { URL } from 'node:url';
3
- import crypto from 'node:crypto';
4
- import stream, { PassThrough as PassThroughStream } from 'node:stream';
5
- import normalizeUrl from 'normalize-url';
6
- import { getStreamAsBuffer } from 'get-stream';
7
- import CachePolicy from 'http-cache-semantics';
8
- import Response from 'responselike';
9
- import { Keyv } from 'keyv';
10
- import mimicResponse from 'mimic-response';
11
- import { CacheError, RequestError, } from './types.js';
1
+ // biome-ignore-all lint/suspicious/noImplicitAnyLet: legacy format
2
+ // biome-ignore-all lint/suspicious/noExplicitAny: legacy format
3
+ import crypto from "node:crypto";
4
+ import EventEmitter from "node:events";
5
+ import stream, { PassThrough as PassThroughStream } from "node:stream";
6
+ import urlLib, { URL } from "node:url";
7
+ import { getStreamAsBuffer } from "get-stream";
8
+ import CachePolicy from "http-cache-semantics";
9
+ import { Keyv } from "keyv";
10
+ import mimicResponse from "mimic-response";
11
+ import normalizeUrl from "normalize-url";
12
+ import Response from "responselike";
13
+ import { CacheError, RequestError, } from "./types.js";
12
14
  class CacheableRequest {
13
15
  constructor(cacheRequest, cacheAdapter) {
14
- this.cache = new Keyv({ namespace: 'cacheable-request' });
16
+ this.cache = new Keyv({ namespace: "cacheable-request" });
15
17
  this.hooks = new Map();
16
18
  this.request = () => (options, callback) => {
17
19
  let url;
18
- if (typeof options === 'string') {
20
+ if (typeof options === "string") {
19
21
  url = normalizeUrlObject(parseWithWhatwg(options));
20
22
  options = {};
21
23
  }
@@ -24,25 +26,26 @@ class CacheableRequest {
24
26
  options = {};
25
27
  }
26
28
  else {
27
- const [pathname, ...searchParts] = (options.path ?? '').split('?');
28
- const search = searchParts.length > 0
29
- ? `?${searchParts.join('?')}`
30
- : '';
29
+ const [pathname, ...searchParts] = (options.path ?? "").split("?");
30
+ const search = searchParts.length > 0 ? `?${searchParts.join("?")}` : "";
31
31
  url = normalizeUrlObject({ ...options, pathname, search });
32
32
  }
33
33
  options = {
34
34
  headers: {},
35
- method: 'GET',
35
+ method: "GET",
36
36
  cache: true,
37
37
  strictTtl: false,
38
38
  automaticFailover: false,
39
39
  ...options,
40
40
  ...urlObjectToRequestOptions(url),
41
41
  };
42
- options.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [key.toLowerCase(), value]));
42
+ options.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [
43
+ key.toLowerCase(),
44
+ value,
45
+ ]));
43
46
  const ee = new EventEmitter();
44
47
  const normalizedUrlString = normalizeUrl(urlLib.format(url), {
45
- stripWWW: false, // eslint-disable-line @typescript-eslint/naming-convention
48
+ stripWWW: false,
46
49
  removeTrailingSlash: false,
47
50
  stripAuthentication: false,
48
51
  });
@@ -50,7 +53,9 @@ class CacheableRequest {
50
53
  // POST, PATCH, and PUT requests may be cached, depending on the response
51
54
  // cache-control headers. As a result, the body of the request should be
52
55
  // added to the cache key in order to avoid collisions.
53
- if (options.body && options.method !== undefined && ['POST', 'PATCH', 'PUT'].includes(options.method)) {
56
+ if (options.body &&
57
+ options.method !== undefined &&
58
+ ["POST", "PATCH", "PUT"].includes(options.method)) {
54
59
  if (options.body instanceof stream.Readable) {
55
60
  // Streamed bodies should completely skip the cache because they may
56
61
  // or may not be hashable and in either case the stream would need to
@@ -58,7 +63,7 @@ class CacheableRequest {
58
63
  options.cache = false;
59
64
  }
60
65
  else {
61
- key += `:${crypto.createHash('md5').update(options.body).digest('hex')}`;
66
+ key += `:${crypto.createHash("md5").update(options.body).digest("hex")}`;
62
67
  }
63
68
  }
64
69
  let revalidate = false;
@@ -66,8 +71,11 @@ class CacheableRequest {
66
71
  const makeRequest = (options_) => {
67
72
  madeRequest = true;
68
73
  let requestErrored = false;
69
- let requestErrorCallback = () => { };
70
- const requestErrorPromise = new Promise(resolve => {
74
+ /* c8 ignore next 4 */
75
+ let requestErrorCallback = () => {
76
+ /* do nothing */
77
+ };
78
+ const requestErrorPromise = new Promise((resolve) => {
71
79
  requestErrorCallback = () => {
72
80
  if (!requestErrored) {
73
81
  requestErrored = true;
@@ -81,14 +89,16 @@ class CacheableRequest {
81
89
  const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(options_, response);
82
90
  if (!revalidatedPolicy.modified) {
83
91
  response.resume();
84
- await new Promise(resolve => {
92
+ await new Promise((resolve) => {
85
93
  // Skipping 'error' handler cause 'error' event should't be emitted for 304 response
86
- response
87
- .once('end', resolve);
94
+ response.once("end", resolve);
88
95
  });
89
96
  const headers = convertHeaders(revalidatedPolicy.policy.responseHeaders());
90
97
  response = new Response({
91
- statusCode: revalidate.statusCode, headers, body: revalidate.body, url: revalidate.url,
98
+ statusCode: revalidate.statusCode,
99
+ headers,
100
+ body: revalidate.body,
101
+ url: revalidate.url,
92
102
  });
93
103
  response.cachePolicy = revalidatedPolicy.policy;
94
104
  response.fromCache = true;
@@ -106,32 +116,34 @@ class CacheableRequest {
106
116
  const bodyPromise = getStreamAsBuffer(response);
107
117
  await Promise.race([
108
118
  requestErrorPromise,
109
- new Promise(resolve => response.once('end', resolve)), // eslint-disable-line no-promise-executor-return
110
- new Promise(resolve => response.once('close', resolve)), // eslint-disable-line no-promise-executor-return
119
+ new Promise((resolve) => response.once("end", resolve)),
120
+ new Promise((resolve) => response.once("close", resolve)),
111
121
  ]);
112
122
  const body = await bodyPromise;
113
123
  let value = {
114
124
  url: response.url,
115
- statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
125
+ statusCode: response.fromCache
126
+ ? revalidate.statusCode
127
+ : response.statusCode,
116
128
  body,
117
129
  cachePolicy: response.cachePolicy.toObject(),
118
130
  };
119
- let ttl = options_.strictTtl ? response.cachePolicy.timeToLive() : undefined;
131
+ let ttl = options_.strictTtl
132
+ ? response.cachePolicy.timeToLive()
133
+ : undefined;
120
134
  if (options_.maxTtl) {
121
135
  ttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;
122
136
  }
123
137
  if (this.hooks.size > 0) {
124
- /* eslint-disable no-await-in-loop */
125
138
  for (const key_ of this.hooks.keys()) {
126
139
  value = await this.runHook(key_, value, response);
127
140
  }
128
- /* eslint-enable no-await-in-loop */
129
141
  }
130
142
  await this.cache.set(key, value, ttl);
131
143
  }
132
144
  catch (error) {
133
145
  /* c8 ignore next 2 */
134
- ee.emit('error', new CacheError(error));
146
+ ee.emit("error", new CacheError(error));
135
147
  }
136
148
  })();
137
149
  }
@@ -142,40 +154,41 @@ class CacheableRequest {
142
154
  }
143
155
  catch (error) {
144
156
  /* c8 ignore next 2 */
145
- ee.emit('error', new CacheError(error));
157
+ ee.emit("error", new CacheError(error));
146
158
  }
147
159
  })();
148
160
  }
149
- ee.emit('response', clonedResponse ?? response);
150
- if (typeof callback === 'function') {
161
+ ee.emit("response", clonedResponse ?? response);
162
+ if (typeof callback === "function") {
151
163
  callback(clonedResponse ?? response);
152
164
  }
153
165
  };
154
166
  try {
155
167
  const request_ = this.cacheRequest(options_, handler);
156
- request_.once('error', requestErrorCallback);
157
- // eslint-disable-next-line @typescript-eslint/no-deprecated
158
- request_.once('abort', requestErrorCallback);
159
- request_.once('destroy', requestErrorCallback);
160
- ee.emit('request', request_);
168
+ request_.once("error", requestErrorCallback);
169
+ request_.once("abort", requestErrorCallback);
170
+ request_.once("destroy", requestErrorCallback);
171
+ ee.emit("request", request_);
161
172
  }
162
173
  catch (error) {
163
- ee.emit('error', new RequestError(error));
174
+ ee.emit("error", new RequestError(error));
164
175
  }
165
176
  };
166
177
  (async () => {
167
178
  const get = async (options_) => {
168
179
  await Promise.resolve();
169
- const cacheEntry = options_.cache ? await this.cache.get(key) : undefined;
180
+ const cacheEntry = options_.cache
181
+ ? await this.cache.get(key)
182
+ : undefined;
170
183
  if (cacheEntry === undefined && !options_.forceRefresh) {
171
184
  makeRequest(options_);
172
185
  return;
173
186
  }
174
187
  const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
175
- if (policy.satisfiesWithoutRevalidation(options_) && !options_.forceRefresh) {
188
+ if (policy.satisfiesWithoutRevalidation(options_) &&
189
+ !options_.forceRefresh) {
176
190
  const headers = convertHeaders(policy.responseHeaders());
177
191
  const bodyBuffer = cacheEntry.body;
178
- // eslint-disable-next-line n/prefer-global/buffer
179
192
  const body = Buffer.from(bodyBuffer);
180
193
  const response = new Response({
181
194
  statusCode: cacheEntry.statusCode,
@@ -185,12 +198,14 @@ class CacheableRequest {
185
198
  });
186
199
  response.cachePolicy = policy;
187
200
  response.fromCache = true;
188
- ee.emit('response', response);
189
- if (typeof callback === 'function') {
201
+ ee.emit("response", response);
202
+ if (typeof callback === "function") {
190
203
  callback(response);
191
204
  }
192
205
  }
193
- else if (policy.satisfiesWithoutRevalidation(options_) && Date.now() >= policy.timeToLive() && options_.forceRefresh) {
206
+ else if (policy.satisfiesWithoutRevalidation(options_) &&
207
+ Date.now() >= policy.timeToLive() &&
208
+ options_.forceRefresh) {
194
209
  await this.cache.delete(key);
195
210
  options_.headers = policy.revalidationHeaders(options_);
196
211
  makeRequest(options_);
@@ -201,15 +216,15 @@ class CacheableRequest {
201
216
  makeRequest(options_);
202
217
  }
203
218
  };
204
- const errorHandler = (error) => ee.emit('error', new CacheError(error));
219
+ const errorHandler = (error) => ee.emit("error", new CacheError(error));
205
220
  if (this.cache instanceof Keyv) {
206
221
  const cachek = this.cache;
207
- cachek.once('error', errorHandler);
208
- ee.on('error', () => {
209
- cachek.removeListener('error', errorHandler);
222
+ cachek.once("error", errorHandler);
223
+ ee.on("error", () => {
224
+ cachek.removeListener("error", errorHandler);
210
225
  });
211
- ee.on('response', () => {
212
- cachek.removeListener('error', errorHandler);
226
+ ee.on("response", () => {
227
+ cachek.removeListener("error", errorHandler);
213
228
  });
214
229
  }
215
230
  try {
@@ -220,7 +235,7 @@ class CacheableRequest {
220
235
  if (options.automaticFailover && !madeRequest) {
221
236
  makeRequest(options);
222
237
  }
223
- ee.emit('error', new CacheError(error));
238
+ ee.emit("error", new CacheError(error));
224
239
  }
225
240
  })();
226
241
  return ee;
@@ -240,7 +255,7 @@ class CacheableRequest {
240
255
  else {
241
256
  this.cache = new Keyv({
242
257
  store: cacheAdapter,
243
- namespace: 'cacheable-request',
258
+ namespace: "cacheable-request",
244
259
  });
245
260
  }
246
261
  }
@@ -256,7 +271,7 @@ const cloneResponse = (response) => {
256
271
  };
257
272
  const urlObjectToRequestOptions = (url) => {
258
273
  const options = { ...url };
259
- options.path = `${url.pathname || '/'}${url.search || ''}`;
274
+ options.path = `${url.pathname || "/"}${url.search || ""}`;
260
275
  delete options.pathname;
261
276
  delete options.search;
262
277
  return options;
@@ -272,7 +287,7 @@ const normalizeUrlObject = (url) =>
272
287
  ({
273
288
  protocol: url.protocol,
274
289
  auth: url.auth,
275
- hostname: url.hostname || url.host || 'localhost',
290
+ hostname: url.hostname || url.host || "localhost",
276
291
  port: url.port,
277
292
  pathname: url.pathname,
278
293
  search: url.search,
@@ -291,9 +306,7 @@ export const parseWithWhatwg = (raw) => {
291
306
  protocol: u.protocol, // E.g. 'https:'
292
307
  slashes: true, // Always true for WHATWG URLs
293
308
  /* c8 ignore next 3 */
294
- auth: u.username || u.password
295
- ? `${u.username}:${u.password}`
296
- : undefined,
309
+ auth: u.username || u.password ? `${u.username}:${u.password}` : undefined,
297
310
  host: u.host, // E.g. 'example.com:8080'
298
311
  port: u.port, // E.g. '8080'
299
312
  hostname: u.hostname, // E.g. 'example.com'
@@ -306,6 +319,6 @@ export const parseWithWhatwg = (raw) => {
306
319
  };
307
320
  };
308
321
  export default CacheableRequest;
309
- export * from './types.js';
310
- export const onResponse = 'onResponse';
322
+ export * from "./types.js";
323
+ export const onResponse = "onResponse";
311
324
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,sBAAsB;KACpC,CAAC;AACH,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC","sourcesContent":["\nimport EventEmitter from 'node:events';\nimport urlLib, {URL} from 'node:url';\nimport crypto from 'node:crypto';\nimport stream, {PassThrough as PassThroughStream} from 'node:stream';\nimport {IncomingMessage} from 'node:http';\nimport normalizeUrl from 'normalize-url';\nimport {getStreamAsBuffer} from 'get-stream';\nimport CachePolicy from 'http-cache-semantics';\nimport Response from 'responselike';\nimport {Keyv} from 'keyv';\nimport mimicResponse from 'mimic-response';\nimport {\n\tRequestFn, CacheResponse, CacheValue, CacheableOptions, UrlOption, CacheError, RequestError, Emitter, CacheableRequestFunction,\n} from './types.js';\n\n// eslint-disable-next-line @typescript-eslint/naming-convention\ntype Function_ = (...arguments_: any[]) => any;\n\nclass CacheableRequest {\n\tcache: Keyv = new Keyv<any>({namespace: 'cacheable-request'});\n\tcacheRequest: RequestFn;\n\thooks: Map<string, Function_> = new Map<string, Function_>();\n\tconstructor(cacheRequest: RequestFn, cacheAdapter?: any) {\n\t\tif (cacheAdapter) {\n\t\t\tif (cacheAdapter instanceof Keyv) {\n\t\t\t\tthis.cache = cacheAdapter;\n\t\t\t} else {\n\t\t\t\tthis.cache = new Keyv({\n\t\t\t\t\tstore: cacheAdapter,\n\t\t\t\t\tnamespace: 'cacheable-request',\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tthis.request = this.request.bind(this);\n\t\tthis.cacheRequest = cacheRequest;\n\t}\n\n\trequest = () => (\n\t\toptions: CacheableOptions,\n\t\tcallback?: (response: CacheResponse) => void,\n\t): Emitter => {\n\t\tlet url;\n\t\tif (typeof options === 'string') {\n\t\t\turl = normalizeUrlObject(parseWithWhatwg(options));\n\t\t\toptions = {};\n\t\t} else if (options instanceof urlLib.URL) {\n\t\t\turl = normalizeUrlObject(parseWithWhatwg(options.toString()));\n\t\t\toptions = {};\n\t\t} else {\n\t\t\tconst [pathname, ...searchParts] = (options.path ?? '').split('?');\n\t\t\tconst search = searchParts.length > 0\n\t\t\t\t? `?${searchParts.join('?')}`\n\t\t\t\t: '';\n\t\t\turl = normalizeUrlObject({...options, pathname, search});\n\t\t}\n\n\t\toptions = {\n\t\t\theaders: {},\n\t\t\tmethod: 'GET',\n\t\t\tcache: true,\n\t\t\tstrictTtl: false,\n\t\t\tautomaticFailover: false,\n\t\t\t...options,\n\t\t\t...urlObjectToRequestOptions(url),\n\t\t};\n\t\toptions.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [(key as string).toLowerCase(), value]));\n\t\tconst ee: Emitter = new EventEmitter() as Emitter;\n\t\tconst normalizedUrlString = normalizeUrl(urlLib.format(url), {\n\t\t\tstripWWW: false, // eslint-disable-line @typescript-eslint/naming-convention\n\t\t\tremoveTrailingSlash: false,\n\t\t\tstripAuthentication: false,\n\t\t});\n\t\tlet key = `${options.method}:${normalizedUrlString}`;\n\t\t// POST, PATCH, and PUT requests may be cached, depending on the response\n\t\t// cache-control headers. As a result, the body of the request should be\n\t\t// added to the cache key in order to avoid collisions.\n\t\tif (options.body && options.method !== undefined && ['POST', 'PATCH', 'PUT'].includes(options.method)) {\n\t\t\tif (options.body instanceof stream.Readable) {\n\t\t\t\t// Streamed bodies should completely skip the cache because they may\n\t\t\t\t// or may not be hashable and in either case the stream would need to\n\t\t\t\t// close before the cache key could be generated.\n\t\t\t\toptions.cache = false;\n\t\t\t} else {\n\t\t\t\tkey += `:${crypto.createHash('md5').update(options.body).digest('hex')}`;\n\t\t\t}\n\t\t}\n\n\t\tlet revalidate: any = false;\n\t\tlet madeRequest = false;\n\t\tconst makeRequest = (options_: any) => {\n\t\t\tmadeRequest = true;\n\t\t\tlet requestErrored = false;\n\t\t\tlet requestErrorCallback: (...arguments_: any[]) => void = () => {/* do nothing */};\n\n\t\t\tconst requestErrorPromise = new Promise<void>(resolve => {\n\t\t\t\trequestErrorCallback = () => {\n\t\t\t\t\tif (!requestErrored) {\n\t\t\t\t\t\trequestErrored = true;\n\t\t\t\t\t\tresolve();\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t});\n\t\t\tconst handler = async (response: any) => {\n\t\t\t\tif (revalidate) {\n\t\t\t\t\tresponse.status = response.statusCode;\n\t\t\t\t\tconst revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(options_, response);\n\t\t\t\t\tif (!revalidatedPolicy.modified) {\n\t\t\t\t\t\tresponse.resume();\n\t\t\t\t\t\tawait new Promise(resolve => {\n\t\t\t\t\t\t\t// Skipping 'error' handler cause 'error' event should't be emitted for 304 response\n\t\t\t\t\t\t\tresponse\n\t\t\t\t\t\t\t\t.once('end', resolve);\n\t\t\t\t\t\t});\n\t\t\t\t\t\tconst headers = convertHeaders(revalidatedPolicy.policy.responseHeaders());\n\t\t\t\t\t\tresponse = new Response({\n\t\t\t\t\t\t\tstatusCode: revalidate.statusCode, headers, body: revalidate.body, url: revalidate.url,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tresponse.cachePolicy = revalidatedPolicy.policy;\n\t\t\t\t\t\tresponse.fromCache = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (!response.fromCache) {\n\t\t\t\t\tresponse.cachePolicy = new CachePolicy(options_, response, options_);\n\t\t\t\t\tresponse.fromCache = false;\n\t\t\t\t}\n\n\t\t\t\tlet clonedResponse;\n\t\t\t\tif (options_.cache && response.cachePolicy.storable()) {\n\t\t\t\t\tclonedResponse = cloneResponse(response);\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tconst bodyPromise = getStreamAsBuffer(response);\n\t\t\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\t\t\trequestErrorPromise,\n\t\t\t\t\t\t\t\tnew Promise(resolve => response.once('end', resolve)), // eslint-disable-line no-promise-executor-return\n\t\t\t\t\t\t\t\tnew Promise(resolve => response.once('close', resolve)), // eslint-disable-line no-promise-executor-return\n\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\tconst body = await bodyPromise;\n\t\t\t\t\t\t\tlet value: CacheValue = {\n\t\t\t\t\t\t\t\turl: response.url,\n\t\t\t\t\t\t\t\tstatusCode: response.fromCache ? revalidate.statusCode : response.statusCode,\n\t\t\t\t\t\t\t\tbody,\n\t\t\t\t\t\t\t\tcachePolicy: response.cachePolicy.toObject(),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\tlet ttl = options_.strictTtl ? response.cachePolicy.timeToLive() : undefined;\n\t\t\t\t\t\t\tif (options_.maxTtl) {\n\t\t\t\t\t\t\t\tttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif (this.hooks.size > 0) {\n\t\t\t\t\t\t\t\t/* eslint-disable no-await-in-loop */\n\t\t\t\t\t\t\t\tfor (const key_ of this.hooks.keys()) {\n\t\t\t\t\t\t\t\t\tvalue = await this.runHook(key_, value, response);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t/* eslint-enable no-await-in-loop */\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tawait this.cache.set(key, value, ttl);\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\t/* c8 ignore next 2 */\n\t\t\t\t\t\t\tee.emit('error', new CacheError(error));\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t} else if (options_.cache && revalidate) {\n\t\t\t\t\t(async () => {\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tawait this.cache.delete(key);\n\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\t/* c8 ignore next 2 */\n\t\t\t\t\t\t\tee.emit('error', new CacheError(error));\n\t\t\t\t\t\t}\n\t\t\t\t\t})();\n\t\t\t\t}\n\n\t\t\t\tee.emit('response', clonedResponse ?? response);\n\t\t\t\tif (typeof callback === 'function') {\n\t\t\t\t\tcallback(clonedResponse ?? response);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\ttry {\n\t\t\t\tconst request_ = this.cacheRequest(options_, handler);\n\t\t\t\trequest_.once('error', requestErrorCallback);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-deprecated\n\t\t\t\trequest_.once('abort', requestErrorCallback);\n\t\t\t\trequest_.once('destroy', requestErrorCallback);\n\t\t\t\tee.emit('request', request_);\n\t\t\t} catch (error: any) {\n\t\t\t\tee.emit('error', new RequestError(error));\n\t\t\t}\n\t\t};\n\n\t\t(async () => {\n\t\t\tconst get = async (options_: any) => {\n\t\t\t\tawait Promise.resolve();\n\t\t\t\tconst cacheEntry = options_.cache ? await this.cache.get(key) : undefined;\n\n\t\t\t\tif (cacheEntry === undefined && !options_.forceRefresh) {\n\t\t\t\t\tmakeRequest(options_);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tconst policy = CachePolicy.fromObject((cacheEntry as CacheValue).cachePolicy);\n\t\t\t\tif (policy.satisfiesWithoutRevalidation(options_) && !options_.forceRefresh) {\n\t\t\t\t\tconst headers = convertHeaders(policy.responseHeaders());\n\t\t\t\t\tconst bodyBuffer = (cacheEntry as CacheValue).body;\n\t\t\t\t\t// eslint-disable-next-line n/prefer-global/buffer\n\t\t\t\t\tconst body = Buffer.from(bodyBuffer as string);\n\t\t\t\t\tconst response: any = new Response({\n\t\t\t\t\t\tstatusCode: (cacheEntry as CacheValue).statusCode,\n\t\t\t\t\t\theaders,\n\t\t\t\t\t\tbody,\n\t\t\t\t\t\turl: (cacheEntry as CacheValue).url,\n\t\t\t\t\t});\n\t\t\t\t\tresponse.cachePolicy = policy;\n\t\t\t\t\tresponse.fromCache = true;\n\t\t\t\t\tee.emit('response', response);\n\t\t\t\t\tif (typeof callback === 'function') {\n\t\t\t\t\t\tcallback(response);\n\t\t\t\t\t}\n\t\t\t\t} else if (policy.satisfiesWithoutRevalidation(options_) && Date.now() >= policy.timeToLive() && options_.forceRefresh) {\n\t\t\t\t\tawait this.cache.delete(key);\n\t\t\t\t\toptions_.headers = policy.revalidationHeaders(options_);\n\t\t\t\t\tmakeRequest(options_);\n\t\t\t\t} else {\n\t\t\t\t\trevalidate = cacheEntry;\n\t\t\t\t\toptions_.headers = policy.revalidationHeaders(options_);\n\t\t\t\t\tmakeRequest(options_);\n\t\t\t\t}\n\t\t\t};\n\n\t\t\tconst errorHandler = (error: Error) => ee.emit('error', new CacheError(error));\n\t\t\tif (this.cache instanceof Keyv) {\n\t\t\t\tconst cachek = this.cache;\n\t\t\t\tcachek.once('error', errorHandler);\n\t\t\t\tee.on('error', () => {\n\t\t\t\t\tcachek.removeListener('error', errorHandler);\n\t\t\t\t});\n\t\t\t\tee.on('response', () => {\n\t\t\t\t\tcachek.removeListener('error', errorHandler);\n\t\t\t\t});\n\t\t\t}\n\n\t\t\ttry {\n\t\t\t\tawait get(options);\n\t\t\t} catch (error: any) {\n\t\t\t\t/* c8 ignore next 3 */\n\t\t\t\tif (options.automaticFailover && !madeRequest) {\n\t\t\t\t\tmakeRequest(options);\n\t\t\t\t}\n\n\t\t\t\tee.emit('error', new CacheError(error));\n\t\t\t}\n\t\t})();\n\n\t\treturn ee;\n\t};\n\n\taddHook = (name: string, function_: Function_) => {\n\t\tif (!this.hooks.has(name)) {\n\t\t\tthis.hooks.set(name, function_);\n\t\t}\n\t};\n\n\tremoveHook = (name: string) => this.hooks.delete(name);\n\n\tgetHook = (name: string) => this.hooks.get(name);\n\n\trunHook = async (name: string, ...arguments_: any[]): Promise<CacheValue> => this.hooks.get(name)?.(...arguments_);\n}\n\nconst entries = Object.entries as <T>(object: T) => Array<[keyof T, T[keyof T]]>;\n\nconst cloneResponse = (response: IncomingMessage) => {\n\tconst clone = new PassThroughStream({autoDestroy: false});\n\tmimicResponse(response, clone);\n\n\treturn response.pipe(clone);\n};\n\nconst urlObjectToRequestOptions = (url: any) => {\n\tconst options: UrlOption = {...url};\n\toptions.path = `${url.pathname || '/'}${url.search || ''}`;\n\tdelete options.pathname;\n\tdelete options.search;\n\treturn options;\n};\n\nconst normalizeUrlObject = (url: any) =>\n// If url was parsed by url.parse or new URL:\n// - hostname will be set\n// - host will be hostname[:port]\n// - port will be set if it was explicit in the parsed string\n// Otherwise, url was from request options:\n// - hostname or host may be set\n// - host shall not have port encoded\n\t({\n\t\tprotocol: url.protocol,\n\t\tauth: url.auth,\n\t\thostname: url.hostname || url.host || 'localhost',\n\t\tport: url.port,\n\t\tpathname: url.pathname,\n\t\tsearch: url.search,\n\t});\n\nconst convertHeaders = (headers: CachePolicy.Headers) => {\n\tconst result: any = [];\n\tfor (const name of Object.keys(headers)) {\n\t\tresult[name.toLowerCase()] = headers[name];\n\t}\n\n\treturn result;\n};\n\nexport const parseWithWhatwg = (raw: string) => {\n\tconst u = new URL(raw);\n\n\t// If normalizeUrlObject expects the same fields as url.parse()\n\treturn {\n\t\tprotocol: u.protocol, // E.g. 'https:'\n\t\tslashes: true, // Always true for WHATWG URLs\n\t\t/* c8 ignore next 3 */\n\t\tauth: u.username || u.password\n\t\t\t? `${u.username}:${u.password}`\n\t\t\t: undefined,\n\t\thost: u.host, // E.g. 'example.com:8080'\n\t\tport: u.port, // E.g. '8080'\n\t\thostname: u.hostname, // E.g. 'example.com'\n\t\thash: u.hash, // E.g. '#quux'\n\t\tsearch: u.search, // E.g. '?bar=baz'\n\t\tquery: Object.fromEntries(u.searchParams), // { bar: 'baz' }\n\t\tpathname: u.pathname, // E.g. '/foo'\n\t\tpath: u.pathname + u.search, // '/foo?bar=baz'\n\t\thref: u.href, // Full serialized URL\n\t};\n};\n\nexport default CacheableRequest;\nexport * from './types.js';\nexport const onResponse = 'onResponse';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,gEAAgE;AAChE,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,YAAY,MA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AY,CAAC;AAC3B,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC","sourcesContent":["// biome-ignore-all lint/suspicious/noImplicitAnyLet: legacy format\n// biome-ignore-all lint/suspicious/noExplicitAny: legacy format\nimport crypto from \"node:crypto\";\nimport EventEmitter from \"node:events\";\nimport type { IncomingMessage } from \"node:http\";\nimport stream, { PassThrough as PassThroughStream } from \"node:stream\";\nimport urlLib, { URL } from \"node:url\";\nimport { getStreamAsBuffer } from \"get-stream\";\nimport CachePolicy from \"http-cache-semantics\";\nimport { Keyv } from \"keyv\";\nimport mimicResponse from \"mimic-response\";\nimport normalizeUrl from \"normalize-url\";\nimport Response from \"responselike\";\nimport {\n\ttype CacheableOptions,\n\tCacheError,\n\ttype CacheResponse,\n\ttype CacheValue,\n\ttype Emitter,\n\tRequestError,\n\ttype RequestFn,\n\ttype UrlOption,\n} from \"./types.js\";\n\ntype Function_ = (...arguments_: any[]) => any;\n\nclass CacheableRequest {\n\tcache: Keyv = new Keyv<any>({ namespace: \"cacheable-request\" });\n\tcacheRequest: RequestFn;\n\thooks: Map<string, Function_> = new Map<string, Function_>();\n\tconstructor(cacheRequest: RequestFn, cacheAdapter?: any) {\n\t\tif (cacheAdapter) {\n\t\t\tif (cacheAdapter instanceof Keyv) {\n\t\t\t\tthis.cache = cacheAdapter;\n\t\t\t} else {\n\t\t\t\tthis.cache = new Keyv({\n\t\t\t\t\tstore: cacheAdapter,\n\t\t\t\t\tnamespace: \"cacheable-request\",\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tthis.request = this.request.bind(this);\n\t\tthis.cacheRequest = cacheRequest;\n\t}\n\n\trequest =\n\t\t() =>\n\t\t(\n\t\t\toptions: CacheableOptions,\n\t\t\tcallback?: (response: CacheResponse) => void,\n\t\t): Emitter => {\n\t\t\tlet url;\n\t\t\tif (typeof options === \"string\") {\n\t\t\t\turl = normalizeUrlObject(parseWithWhatwg(options));\n\t\t\t\toptions = {};\n\t\t\t} else if (options instanceof urlLib.URL) {\n\t\t\t\turl = normalizeUrlObject(parseWithWhatwg(options.toString()));\n\t\t\t\toptions = {};\n\t\t\t} else {\n\t\t\t\tconst [pathname, ...searchParts] = (options.path ?? \"\").split(\"?\");\n\t\t\t\tconst search =\n\t\t\t\t\tsearchParts.length > 0 ? `?${searchParts.join(\"?\")}` : \"\";\n\t\t\t\turl = normalizeUrlObject({ ...options, pathname, search });\n\t\t\t}\n\n\t\t\toptions = {\n\t\t\t\theaders: {},\n\t\t\t\tmethod: \"GET\",\n\t\t\t\tcache: true,\n\t\t\t\tstrictTtl: false,\n\t\t\t\tautomaticFailover: false,\n\t\t\t\t...options,\n\t\t\t\t...urlObjectToRequestOptions(url),\n\t\t\t};\n\t\t\toptions.headers = Object.fromEntries(\n\t\t\t\tentries(options.headers).map(([key, value]) => [\n\t\t\t\t\t(key as string).toLowerCase(),\n\t\t\t\t\tvalue,\n\t\t\t\t]),\n\t\t\t);\n\t\t\tconst ee: Emitter = new EventEmitter() as Emitter;\n\t\t\tconst normalizedUrlString = normalizeUrl(urlLib.format(url), {\n\t\t\t\tstripWWW: false,\n\t\t\t\tremoveTrailingSlash: false,\n\t\t\t\tstripAuthentication: false,\n\t\t\t});\n\t\t\tlet key = `${options.method}:${normalizedUrlString}`;\n\t\t\t// POST, PATCH, and PUT requests may be cached, depending on the response\n\t\t\t// cache-control headers. As a result, the body of the request should be\n\t\t\t// added to the cache key in order to avoid collisions.\n\t\t\tif (\n\t\t\t\toptions.body &&\n\t\t\t\toptions.method !== undefined &&\n\t\t\t\t[\"POST\", \"PATCH\", \"PUT\"].includes(options.method)\n\t\t\t) {\n\t\t\t\tif (options.body instanceof stream.Readable) {\n\t\t\t\t\t// Streamed bodies should completely skip the cache because they may\n\t\t\t\t\t// or may not be hashable and in either case the stream would need to\n\t\t\t\t\t// close before the cache key could be generated.\n\t\t\t\t\toptions.cache = false;\n\t\t\t\t} else {\n\t\t\t\t\tkey += `:${crypto.createHash(\"md5\").update(options.body).digest(\"hex\")}`;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tlet revalidate: any = false;\n\t\t\tlet madeRequest = false;\n\t\t\tconst makeRequest = (options_: any) => {\n\t\t\t\tmadeRequest = true;\n\t\t\t\tlet requestErrored = false;\n\t\t\t\t/* c8 ignore next 4 */\n\t\t\t\tlet requestErrorCallback: (...arguments_: any[]) => void = () => {\n\t\t\t\t\t/* do nothing */\n\t\t\t\t};\n\n\t\t\t\tconst requestErrorPromise = new Promise<void>((resolve) => {\n\t\t\t\t\trequestErrorCallback = () => {\n\t\t\t\t\t\tif (!requestErrored) {\n\t\t\t\t\t\t\trequestErrored = true;\n\t\t\t\t\t\t\tresolve();\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t\tconst handler = async (response: any) => {\n\t\t\t\t\tif (revalidate) {\n\t\t\t\t\t\tresponse.status = response.statusCode;\n\t\t\t\t\t\tconst revalidatedPolicy = CachePolicy.fromObject(\n\t\t\t\t\t\t\trevalidate.cachePolicy,\n\t\t\t\t\t\t).revalidatedPolicy(options_, response);\n\t\t\t\t\t\tif (!revalidatedPolicy.modified) {\n\t\t\t\t\t\t\tresponse.resume();\n\t\t\t\t\t\t\tawait new Promise((resolve) => {\n\t\t\t\t\t\t\t\t// Skipping 'error' handler cause 'error' event should't be emitted for 304 response\n\t\t\t\t\t\t\t\tresponse.once(\"end\", resolve);\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tconst headers = convertHeaders(\n\t\t\t\t\t\t\t\trevalidatedPolicy.policy.responseHeaders(),\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tresponse = new Response({\n\t\t\t\t\t\t\t\tstatusCode: revalidate.statusCode,\n\t\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\t\tbody: revalidate.body,\n\t\t\t\t\t\t\t\turl: revalidate.url,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tresponse.cachePolicy = revalidatedPolicy.policy;\n\t\t\t\t\t\t\tresponse.fromCache = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tif (!response.fromCache) {\n\t\t\t\t\t\tresponse.cachePolicy = new CachePolicy(\n\t\t\t\t\t\t\toptions_,\n\t\t\t\t\t\t\tresponse,\n\t\t\t\t\t\t\toptions_,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tresponse.fromCache = false;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet clonedResponse;\n\t\t\t\t\tif (options_.cache && response.cachePolicy.storable()) {\n\t\t\t\t\t\tclonedResponse = cloneResponse(response);\n\t\t\t\t\t\t(async () => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tconst bodyPromise = getStreamAsBuffer(response);\n\t\t\t\t\t\t\t\tawait Promise.race([\n\t\t\t\t\t\t\t\t\trequestErrorPromise,\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => response.once(\"end\", resolve)),\n\t\t\t\t\t\t\t\t\tnew Promise((resolve) => response.once(\"close\", resolve)),\n\t\t\t\t\t\t\t\t]);\n\t\t\t\t\t\t\t\tconst body = await bodyPromise;\n\t\t\t\t\t\t\t\tlet value: CacheValue = {\n\t\t\t\t\t\t\t\t\turl: response.url,\n\t\t\t\t\t\t\t\t\tstatusCode: response.fromCache\n\t\t\t\t\t\t\t\t\t\t? revalidate.statusCode\n\t\t\t\t\t\t\t\t\t\t: response.statusCode,\n\t\t\t\t\t\t\t\t\tbody,\n\t\t\t\t\t\t\t\t\tcachePolicy: response.cachePolicy.toObject(),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tlet ttl = options_.strictTtl\n\t\t\t\t\t\t\t\t\t? response.cachePolicy.timeToLive()\n\t\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\t\tif (options_.maxTtl) {\n\t\t\t\t\t\t\t\t\tttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif (this.hooks.size > 0) {\n\t\t\t\t\t\t\t\t\tfor (const key_ of this.hooks.keys()) {\n\t\t\t\t\t\t\t\t\t\tvalue = await this.runHook(key_, value, response);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tawait this.cache.set(key, value, ttl);\n\t\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\t\t/* c8 ignore next 2 */\n\t\t\t\t\t\t\t\tee.emit(\"error\", new CacheError(error));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})();\n\t\t\t\t\t} else if (options_.cache && revalidate) {\n\t\t\t\t\t\t(async () => {\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tawait this.cache.delete(key);\n\t\t\t\t\t\t\t} catch (error: any) {\n\t\t\t\t\t\t\t\t/* c8 ignore next 2 */\n\t\t\t\t\t\t\t\tee.emit(\"error\", new CacheError(error));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t})();\n\t\t\t\t\t}\n\n\t\t\t\t\tee.emit(\"response\", clonedResponse ?? response);\n\t\t\t\t\tif (typeof callback === \"function\") {\n\t\t\t\t\t\tcallback(clonedResponse ?? response);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\ttry {\n\t\t\t\t\tconst request_ = this.cacheRequest(options_, handler);\n\t\t\t\t\trequest_.once(\"error\", requestErrorCallback);\n\t\t\t\t\trequest_.once(\"abort\", requestErrorCallback);\n\t\t\t\t\trequest_.once(\"destroy\", requestErrorCallback);\n\t\t\t\t\tee.emit(\"request\", request_);\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\tee.emit(\"error\", new RequestError(error));\n\t\t\t\t}\n\t\t\t};\n\n\t\t\t(async () => {\n\t\t\t\tconst get = async (options_: any) => {\n\t\t\t\t\tawait Promise.resolve();\n\t\t\t\t\tconst cacheEntry = options_.cache\n\t\t\t\t\t\t? await this.cache.get(key)\n\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\tif (cacheEntry === undefined && !options_.forceRefresh) {\n\t\t\t\t\t\tmakeRequest(options_);\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tconst policy = CachePolicy.fromObject(\n\t\t\t\t\t\t(cacheEntry as CacheValue).cachePolicy,\n\t\t\t\t\t);\n\t\t\t\t\tif (\n\t\t\t\t\t\tpolicy.satisfiesWithoutRevalidation(options_) &&\n\t\t\t\t\t\t!options_.forceRefresh\n\t\t\t\t\t) {\n\t\t\t\t\t\tconst headers = convertHeaders(policy.responseHeaders());\n\t\t\t\t\t\tconst bodyBuffer = (cacheEntry as CacheValue).body;\n\t\t\t\t\t\tconst body = Buffer.from(bodyBuffer as string);\n\t\t\t\t\t\tconst response: any = new Response({\n\t\t\t\t\t\t\tstatusCode: (cacheEntry as CacheValue).statusCode,\n\t\t\t\t\t\t\theaders,\n\t\t\t\t\t\t\tbody,\n\t\t\t\t\t\t\turl: (cacheEntry as CacheValue).url,\n\t\t\t\t\t\t});\n\t\t\t\t\t\tresponse.cachePolicy = policy;\n\t\t\t\t\t\tresponse.fromCache = true;\n\t\t\t\t\t\tee.emit(\"response\", response);\n\t\t\t\t\t\tif (typeof callback === \"function\") {\n\t\t\t\t\t\t\tcallback(response);\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if (\n\t\t\t\t\t\tpolicy.satisfiesWithoutRevalidation(options_) &&\n\t\t\t\t\t\tDate.now() >= policy.timeToLive() &&\n\t\t\t\t\t\toptions_.forceRefresh\n\t\t\t\t\t) {\n\t\t\t\t\t\tawait this.cache.delete(key);\n\t\t\t\t\t\toptions_.headers = policy.revalidationHeaders(options_);\n\t\t\t\t\t\tmakeRequest(options_);\n\t\t\t\t\t} else {\n\t\t\t\t\t\trevalidate = cacheEntry;\n\t\t\t\t\t\toptions_.headers = policy.revalidationHeaders(options_);\n\t\t\t\t\t\tmakeRequest(options_);\n\t\t\t\t\t}\n\t\t\t\t};\n\n\t\t\t\tconst errorHandler = (error: Error) =>\n\t\t\t\t\tee.emit(\"error\", new CacheError(error));\n\t\t\t\tif (this.cache instanceof Keyv) {\n\t\t\t\t\tconst cachek = this.cache;\n\t\t\t\t\tcachek.once(\"error\", errorHandler);\n\t\t\t\t\tee.on(\"error\", () => {\n\t\t\t\t\t\tcachek.removeListener(\"error\", errorHandler);\n\t\t\t\t\t});\n\t\t\t\t\tee.on(\"response\", () => {\n\t\t\t\t\t\tcachek.removeListener(\"error\", errorHandler);\n\t\t\t\t\t});\n\t\t\t\t}\n\n\t\t\t\ttry {\n\t\t\t\t\tawait get(options);\n\t\t\t\t} catch (error: any) {\n\t\t\t\t\t/* c8 ignore next 3 */\n\t\t\t\t\tif (options.automaticFailover && !madeRequest) {\n\t\t\t\t\t\tmakeRequest(options);\n\t\t\t\t\t}\n\n\t\t\t\t\tee.emit(\"error\", new CacheError(error));\n\t\t\t\t}\n\t\t\t})();\n\n\t\t\treturn ee;\n\t\t};\n\n\taddHook = (name: string, function_: Function_) => {\n\t\tif (!this.hooks.has(name)) {\n\t\t\tthis.hooks.set(name, function_);\n\t\t}\n\t};\n\n\tremoveHook = (name: string) => this.hooks.delete(name);\n\n\tgetHook = (name: string) => this.hooks.get(name);\n\n\trunHook = async (name: string, ...arguments_: any[]): Promise<CacheValue> =>\n\t\tthis.hooks.get(name)?.(...arguments_);\n}\n\nconst entries = Object.entries as <T>(\n\tobject: T,\n) => Array<[keyof T, T[keyof T]]>;\n\nconst cloneResponse = (response: IncomingMessage) => {\n\tconst clone = new PassThroughStream({ autoDestroy: false });\n\tmimicResponse(response, clone);\n\n\treturn response.pipe(clone);\n};\n\nconst urlObjectToRequestOptions = (url: any) => {\n\tconst options: UrlOption = { ...url };\n\toptions.path = `${url.pathname || \"/\"}${url.search || \"\"}`;\n\tdelete options.pathname;\n\tdelete options.search;\n\treturn options;\n};\n\nconst normalizeUrlObject = (url: any) =>\n\t// If url was parsed by url.parse or new URL:\n\t// - hostname will be set\n\t// - host will be hostname[:port]\n\t// - port will be set if it was explicit in the parsed string\n\t// Otherwise, url was from request options:\n\t// - hostname or host may be set\n\t// - host shall not have port encoded\n\t({\n\t\tprotocol: url.protocol,\n\t\tauth: url.auth,\n\t\thostname: url.hostname || url.host || \"localhost\",\n\t\tport: url.port,\n\t\tpathname: url.pathname,\n\t\tsearch: url.search,\n\t});\n\nconst convertHeaders = (headers: CachePolicy.Headers) => {\n\tconst result: any = [];\n\tfor (const name of Object.keys(headers)) {\n\t\tresult[name.toLowerCase()] = headers[name];\n\t}\n\n\treturn result;\n};\n\nexport const parseWithWhatwg = (raw: string) => {\n\tconst u = new URL(raw);\n\n\t// If normalizeUrlObject expects the same fields as url.parse()\n\treturn {\n\t\tprotocol: u.protocol, // E.g. 'https:'\n\t\tslashes: true, // Always true for WHATWG URLs\n\t\t/* c8 ignore next 3 */\n\t\tauth: u.username || u.password ? `${u.username}:${u.password}` : undefined,\n\t\thost: u.host, // E.g. 'example.com:8080'\n\t\tport: u.port, // E.g. '8080'\n\t\thostname: u.hostname, // E.g. 'example.com'\n\t\thash: u.hash, // E.g. '#quux'\n\t\tsearch: u.search, // E.g. '?bar=baz'\n\t\tquery: Object.fromEntries(u.searchParams), // { bar: 'baz' }\n\t\tpathname: u.pathname, // E.g. '/foo'\n\t\tpath: u.pathname + u.search, // '/foo?bar=baz'\n\t\thref: u.href, // Full serialized URL\n\t};\n};\n\nexport default CacheableRequest;\nexport * from \"./types.js\";\nexport const onResponse = \"onResponse\";\n"]}
package/dist/types.d.ts CHANGED
@@ -1,44 +1,44 @@
1
- import { request, RequestOptions, ClientRequest, ServerResponse } from 'node:http';
2
- import { URL } from 'node:url';
3
- import { EventEmitter } from 'node:events';
4
- import { Buffer } from 'node:buffer';
5
- import ResponseLike from 'responselike';
6
- import { CachePolicyObject } from 'http-cache-semantics';
1
+ import type { Buffer } from "node:buffer";
2
+ import type { EventEmitter } from "node:events";
3
+ import type { ClientRequest, RequestOptions, request, ServerResponse } from "node:http";
4
+ import type { URL } from "node:url";
5
+ import type { CachePolicyObject } from "http-cache-semantics";
6
+ import type ResponseLike from "responselike";
7
7
  export type RequestFn = typeof request;
8
8
  export type RequestFunction = typeof request;
9
9
  export type CacheResponse = ServerResponse | typeof ResponseLike;
10
10
  export type CacheableRequestFunction = (options: CacheableOptions, callback?: (response: CacheResponse) => void) => Emitter;
11
- export type CacheableOptions = Options & RequestOptions | string | URL;
11
+ export type CacheableOptions = (Options & RequestOptions) | string | URL;
12
12
  export interface Options {
13
13
  /**
14
- * If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.
15
- * @default true
16
- */
14
+ * If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.
15
+ * @default true
16
+ */
17
17
  cache?: boolean | undefined;
18
18
  /**
19
- * If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
20
- *
21
- * If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated
22
- * on the next request with `If-None-Match`/`If-Modified-Since` headers.
23
- * @default false
24
- */
19
+ * If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
20
+ *
21
+ * If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated
22
+ * on the next request with `If-None-Match`/`If-Modified-Since` headers.
23
+ * @default false
24
+ */
25
25
  strictTtl?: boolean | undefined;
26
26
  /**
27
- * Limits TTL. The `number` represents milliseconds.
28
- * @default undefined
29
- */
27
+ * Limits TTL. The `number` represents milliseconds.
28
+ * @default undefined
29
+ */
30
30
  maxTtl?: number | undefined;
31
31
  /**
32
- * When set to `true`, if the DB connection fails we will automatically fallback to a network request.
33
- * DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
34
- * @default false
35
- */
32
+ * When set to `true`, if the DB connection fails we will automatically fallback to a network request.
33
+ * DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
34
+ * @default false
35
+ */
36
36
  automaticFailover?: boolean | undefined;
37
37
  /**
38
- * Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a
39
- * new request and override the cache instead.
40
- * @default false
41
- */
38
+ * Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a
39
+ * new request and override the cache instead.
40
+ * @default false
41
+ */
42
42
  forceRefresh?: boolean | undefined;
43
43
  remoteAddress?: boolean | undefined;
44
44
  url?: string | undefined;
@@ -52,39 +52,39 @@ export interface CacheValue extends Record<string, any> {
52
52
  cachePolicy: CachePolicyObject;
53
53
  }
54
54
  export interface Emitter extends EventEmitter {
55
- addListener(event: 'request', listener: (request: ClientRequest) => void): this;
56
- addListener(event: 'response', listener: (response: CacheResponse) => void): this;
57
- addListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
58
- on(event: 'request', listener: (request: ClientRequest) => void): this;
59
- on(event: 'response', listener: (response: CacheResponse) => void): this;
60
- on(event: 'error', listener: (error: RequestError | CacheError) => void): this;
61
- once(event: 'request', listener: (request: ClientRequest) => void): this;
62
- once(event: 'response', listener: (response: CacheResponse) => void): this;
63
- once(event: 'error', listener: (error: RequestError | CacheError) => void): this;
64
- prependListener(event: 'request', listener: (request: ClientRequest) => void): this;
65
- prependListener(event: 'response', listener: (response: CacheResponse) => void): this;
66
- prependListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
67
- prependOnceListener(event: 'request', listener: (request: ClientRequest) => void): this;
68
- prependOnceListener(event: 'response', listener: (response: CacheResponse) => void): this;
69
- prependOnceListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
70
- removeListener(event: 'request', listener: (request: ClientRequest) => void): this;
71
- removeListener(event: 'response', listener: (response: CacheResponse) => void): this;
72
- removeListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
73
- off(event: 'request', listener: (request: ClientRequest) => void): this;
74
- off(event: 'response', listener: (response: CacheResponse) => void): this;
75
- off(event: 'error', listener: (error: RequestError | CacheError) => void): this;
76
- removeAllListeners(event?: 'request' | 'response' | 'error'): this;
77
- listeners(event: 'request'): Array<(request: ClientRequest) => void>;
78
- listeners(event: 'response'): Array<(response: CacheResponse) => void>;
79
- listeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;
80
- rawListeners(event: 'request'): Array<(request: ClientRequest) => void>;
81
- rawListeners(event: 'response'): Array<(response: CacheResponse) => void>;
82
- rawListeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;
83
- emit(event: 'request', request: ClientRequest): boolean;
84
- emit(event: 'response', response: CacheResponse): boolean;
85
- emit(event: 'error', error: RequestError | CacheError): boolean;
86
- eventNames(): Array<'request' | 'response' | 'error'>;
87
- listenerCount(type: 'request' | 'response' | 'error'): number;
55
+ addListener(event: "request", listener: (request: ClientRequest) => void): this;
56
+ addListener(event: "response", listener: (response: CacheResponse) => void): this;
57
+ addListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
58
+ on(event: "request", listener: (request: ClientRequest) => void): this;
59
+ on(event: "response", listener: (response: CacheResponse) => void): this;
60
+ on(event: "error", listener: (error: RequestError | CacheError) => void): this;
61
+ once(event: "request", listener: (request: ClientRequest) => void): this;
62
+ once(event: "response", listener: (response: CacheResponse) => void): this;
63
+ once(event: "error", listener: (error: RequestError | CacheError) => void): this;
64
+ prependListener(event: "request", listener: (request: ClientRequest) => void): this;
65
+ prependListener(event: "response", listener: (response: CacheResponse) => void): this;
66
+ prependListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
67
+ prependOnceListener(event: "request", listener: (request: ClientRequest) => void): this;
68
+ prependOnceListener(event: "response", listener: (response: CacheResponse) => void): this;
69
+ prependOnceListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
70
+ removeListener(event: "request", listener: (request: ClientRequest) => void): this;
71
+ removeListener(event: "response", listener: (response: CacheResponse) => void): this;
72
+ removeListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
73
+ off(event: "request", listener: (request: ClientRequest) => void): this;
74
+ off(event: "response", listener: (response: CacheResponse) => void): this;
75
+ off(event: "error", listener: (error: RequestError | CacheError) => void): this;
76
+ removeAllListeners(event?: "request" | "response" | "error"): this;
77
+ listeners(event: "request"): Array<(request: ClientRequest) => void>;
78
+ listeners(event: "response"): Array<(response: CacheResponse) => void>;
79
+ listeners(event: "error"): Array<(error: RequestError | CacheError) => void>;
80
+ rawListeners(event: "request"): Array<(request: ClientRequest) => void>;
81
+ rawListeners(event: "response"): Array<(response: CacheResponse) => void>;
82
+ rawListeners(event: "error"): Array<(error: RequestError | CacheError) => void>;
83
+ emit(event: "request", request: ClientRequest): boolean;
84
+ emit(event: "response", response: CacheResponse): boolean;
85
+ emit(event: "error", error: RequestError | CacheError): boolean;
86
+ eventNames(): Array<"request" | "response" | "error">;
87
+ listenerCount(type: "request" | "response" | "error"): number;
88
88
  }
89
89
  export declare class RequestError extends Error {
90
90
  constructor(error: Error);
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AASA,OAAO,EACN,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EACtD,MAAM,WAAW,CAAC;AACnB,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAC,YAAY,EAAC,MAAM,aAAa,CAAC;AACzC,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,YAAY,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAEvD,MAAM,MAAM,SAAS,GAAG,OAAO,OAAO,CAAC;AACvC,MAAM,MAAM,eAAe,GAAG,OAAO,OAAO,CAAC;AAC7C,MAAM,MAAM,aAAa,GAAG,cAAc,GAAG,OAAO,YAAY,CAAC;AAEjE,MAAM,MAAM,wBAAwB,GAAG,CACtC,OAAO,EAAE,gBAAgB,EACzB,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,KAAK,IAAI,KACxC,OAAO,CAAC;AAEb,MAAM,MAAM,gBAAgB,GAAG,OAAO,GAAG,cAAc,GAAG,MAAM,GAAG,GAAG,CAAC;AAEvE,MAAM,WAAW,OAAO;IACvB;;;eAGK;IACL,KAAK,CAAC,EAAE,OAAO,G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CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,kEAAkE;AAClE,mEAAmE;AACnE,kEAAkE;AAClE,kEAAkE;AAClE,0BAA0B;AAgI1B,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,KAAY;QACvB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;CACD;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACpC,YAAY,KAAY;QACvB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["// Type definitions for cacheable-request 6.0\n// Project: https://github.com/lukechilds/cacheable-request#readme\n// Definitions by: BendingBender <https://github.com/BendingBender>\n// Paul Melnikow <https://github.com/paulmelnikow>\n// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped\n// TypeScript Version: 2.3\n\n/// <reference types=\"node\" />\n\nimport {\n\trequest, RequestOptions, ClientRequest, ServerResponse,\n} from 'node:http';\nimport {URL} from 'node:url';\nimport {EventEmitter} from 'node:events';\nimport {Buffer} from 'node:buffer';\nimport ResponseLike from 'responselike';\nimport {CachePolicyObject} from 'http-cache-semantics';\n\nexport type RequestFn = typeof request;\nexport type RequestFunction = typeof request;\nexport type CacheResponse = ServerResponse | typeof ResponseLike;\n\nexport type CacheableRequestFunction = (\n\toptions: CacheableOptions,\n\tcallback?: (response: CacheResponse) => void\n) => Emitter;\n\nexport type CacheableOptions = Options & RequestOptions | string | URL;\n\nexport interface Options {\n\t/**\n\t\t\t * If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.\n\t\t\t * @default true\n\t\t\t */\n\tcache?: boolean | undefined;\n\n\t/**\n\t\t\t * If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.\n\t\t\t *\n\t\t\t * If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated\n\t\t\t * on the next request with `If-None-Match`/`If-Modified-Since` headers.\n\t\t\t * @default false\n\t\t\t */\n\tstrictTtl?: boolean | undefined;\n\n\t/**\n\t\t\t * Limits TTL. The `number` represents milliseconds.\n\t\t\t * @default undefined\n\t\t\t */\n\tmaxTtl?: number | undefined;\n\n\t/**\n\t\t\t * When set to `true`, if the DB connection fails we will automatically fallback to a network request.\n\t\t\t * DB errors will still be emitted to notify you of the problem even though the request callback may succeed.\n\t\t\t * @default false\n\t\t\t */\n\tautomaticFailover?: boolean | undefined;\n\n\t/**\n * Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a\n * new request and override the cache instead.\n * @default false\n */\n\tforceRefresh?: boolean | undefined;\n\tremoteAddress?: boolean | undefined;\n\n\turl?: string | undefined;\n\n\theaders?: Record<string, string | string[] | undefined>;\n\n\t// eslint-disable-next-line @typescript-eslint/no-restricted-types\n\tbody?: Buffer;\n}\n\nexport interface CacheValue extends Record<string, any> {\n\turl: string;\n\tstatusCode: number;\n\t// eslint-disable-next-line @typescript-eslint/no-restricted-types\n\tbody: Buffer | string;\n\tcachePolicy: CachePolicyObject;\n}\n\nexport interface Emitter extends EventEmitter {\n\taddListener(event: 'request', listener: (request: ClientRequest) => void): this;\n\taddListener(\n\t\tevent: 'response',\n\t\tlistener: (response: CacheResponse) => void\n\t): this;\n\taddListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;\n\ton(event: 'request', listener: (request: ClientRequest) => void): this;\n\ton(event: 'response', listener: (response: CacheResponse) => void): this;\n\ton(event: 'error', listener: (error: RequestError | CacheError) => void): this;\n\tonce(event: 'request', listener: (request: ClientRequest) => void): this;\n\tonce(event: 'response', listener: (response: CacheResponse) => void): this;\n\tonce(event: 'error', listener: (error: RequestError | CacheError) => void): this;\n\tprependListener(event: 'request', listener: (request: ClientRequest) => void): this;\n\tprependListener(\n\t\tevent: 'response',\n\t\tlistener: (response: CacheResponse) => void\n\t): this;\n\tprependListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;\n\tprependOnceListener(event: 'request', listener: (request: ClientRequest) => void): this;\n\tprependOnceListener(\n\t\tevent: 'response',\n\t\tlistener: (response: CacheResponse) => void\n\t): this;\n\tprependOnceListener(\n\t\tevent: 'error',\n\t\tlistener: (error: RequestError | CacheError) => void\n\t): this;\n\tremoveListener(event: 'request', listener: (request: ClientRequest) => void): this;\n\tremoveListener(\n\t\tevent: 'response',\n\t\tlistener: (response: CacheResponse) => void\n\t): this;\n\tremoveListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;\n\toff(event: 'request', listener: (request: ClientRequest) => void): this;\n\toff(event: 'response', listener: (response: CacheResponse) => void): this;\n\toff(event: 'error', listener: (error: RequestError | CacheError) => void): this;\n\tremoveAllListeners(event?: 'request' | 'response' | 'error'): this;\n\tlisteners(event: 'request'): Array<(request: ClientRequest) => void>;\n\tlisteners(event: 'response'): Array<(response: CacheResponse) => void>;\n\tlisteners(event: 'error'): Array<(error: RequestError | CacheError) => void>;\n\trawListeners(event: 'request'): Array<(request: ClientRequest) => void>;\n\trawListeners(event: 'response'): Array<(response: CacheResponse) => void>;\n\trawListeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;\n\temit(event: 'request', request: ClientRequest): boolean;\n\temit(event: 'response', response: CacheResponse): boolean;\n\temit(event: 'error', error: RequestError | CacheError): boolean;\n\teventNames(): Array<'request' | 'response' | 'error'>;\n\tlistenerCount(type: 'request' | 'response' | 'error'): number;\n}\n\nexport class RequestError extends Error {\n\tconstructor(error: Error) {\n\t\tsuper(error.message);\n\t\tObject.defineProperties(this, Object.getOwnPropertyDescriptors(error));\n\t}\n}\n\nexport class CacheError extends Error {\n\tconstructor(error: Error) {\n\t\tsuper(error.message);\n\t\tObject.defineProperties(this, Object.getOwnPropertyDescriptors(error));\n\t}\n}\n\nexport interface UrlOption {\n\tpath: string;\n\tpathname?: string;\n\tsearch?: string;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,6CAA6C;AAC7C,kEAAkE;AAClE,mEAAmE;AACnE,kEAAkE;AAClE,kEAAkE;AAClE,0BAA0B;AAkK1B,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,KAAY;QACvB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;CACD;AAED,MAAM,OAAO,UAAW,SAAQ,KAAK;IACpC,YAAY,KAAY;QACvB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,yBAAyB,CAAC,KAAK,CAAC,CAAC,CAAC;IACxE,CAAC;CACD","sourcesContent":["// Type definitions for cacheable-request 6.0\n// Project: https://github.com/lukechilds/cacheable-request#readme\n// Definitions by: BendingBender <https://github.com/BendingBender>\n// Paul Melnikow <https://github.com/paulmelnikow>\n// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped\n// TypeScript Version: 2.3\n\n/// <reference types=\"node\" />\n\nimport type { Buffer } from \"node:buffer\";\nimport type { EventEmitter } from \"node:events\";\nimport type {\n\tClientRequest,\n\tRequestOptions,\n\trequest,\n\tServerResponse,\n} from \"node:http\";\nimport type { URL } from \"node:url\";\nimport type { CachePolicyObject } from \"http-cache-semantics\";\nimport type ResponseLike from \"responselike\";\n\nexport type RequestFn = typeof request;\nexport type RequestFunction = typeof request;\nexport type CacheResponse = ServerResponse | typeof ResponseLike;\n\nexport type CacheableRequestFunction = (\n\toptions: CacheableOptions,\n\tcallback?: (response: CacheResponse) => void,\n) => Emitter;\n\nexport type CacheableOptions = (Options & RequestOptions) | string | URL;\n\nexport interface Options {\n\t/**\n\t * If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.\n\t * @default true\n\t */\n\tcache?: boolean | undefined;\n\n\t/**\n\t * If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.\n\t *\n\t * If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated\n\t * on the next request with `If-None-Match`/`If-Modified-Since` headers.\n\t * @default false\n\t */\n\tstrictTtl?: boolean | undefined;\n\n\t/**\n\t * Limits TTL. The `number` represents milliseconds.\n\t * @default undefined\n\t */\n\tmaxTtl?: number | undefined;\n\n\t/**\n\t * When set to `true`, if the DB connection fails we will automatically fallback to a network request.\n\t * DB errors will still be emitted to notify you of the problem even though the request callback may succeed.\n\t * @default false\n\t */\n\tautomaticFailover?: boolean | undefined;\n\n\t/**\n\t * Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a\n\t * new request and override the cache instead.\n\t * @default false\n\t */\n\tforceRefresh?: boolean | undefined;\n\tremoteAddress?: boolean | undefined;\n\n\turl?: string | undefined;\n\n\theaders?: Record<string, string | string[] | undefined>;\n\n\tbody?: Buffer;\n}\n\n// biome-ignore lint/suspicious/noExplicitAny: type\nexport interface CacheValue extends Record<string, any> {\n\turl: string;\n\tstatusCode: number;\n\tbody: Buffer | string;\n\tcachePolicy: CachePolicyObject;\n}\n\nexport interface Emitter extends EventEmitter {\n\taddListener(\n\t\tevent: \"request\",\n\t\tlistener: (request: ClientRequest) => void,\n\t): this;\n\taddListener(\n\t\tevent: \"response\",\n\t\tlistener: (response: CacheResponse) => void,\n\t): this;\n\taddListener(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\ton(event: \"request\", listener: (request: ClientRequest) => void): this;\n\ton(event: \"response\", listener: (response: CacheResponse) => void): this;\n\ton(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\tonce(event: \"request\", listener: (request: ClientRequest) => void): this;\n\tonce(event: \"response\", listener: (response: CacheResponse) => void): this;\n\tonce(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\tprependListener(\n\t\tevent: \"request\",\n\t\tlistener: (request: ClientRequest) => void,\n\t): this;\n\tprependListener(\n\t\tevent: \"response\",\n\t\tlistener: (response: CacheResponse) => void,\n\t): this;\n\tprependListener(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\tprependOnceListener(\n\t\tevent: \"request\",\n\t\tlistener: (request: ClientRequest) => void,\n\t): this;\n\tprependOnceListener(\n\t\tevent: \"response\",\n\t\tlistener: (response: CacheResponse) => void,\n\t): this;\n\tprependOnceListener(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\tremoveListener(\n\t\tevent: \"request\",\n\t\tlistener: (request: ClientRequest) => void,\n\t): this;\n\tremoveListener(\n\t\tevent: \"response\",\n\t\tlistener: (response: CacheResponse) => void,\n\t): this;\n\tremoveListener(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\toff(event: \"request\", listener: (request: ClientRequest) => void): this;\n\toff(event: \"response\", listener: (response: CacheResponse) => void): this;\n\toff(\n\t\tevent: \"error\",\n\t\tlistener: (error: RequestError | CacheError) => void,\n\t): this;\n\tremoveAllListeners(event?: \"request\" | \"response\" | \"error\"): this;\n\tlisteners(event: \"request\"): Array<(request: ClientRequest) => void>;\n\tlisteners(event: \"response\"): Array<(response: CacheResponse) => void>;\n\tlisteners(event: \"error\"): Array<(error: RequestError | CacheError) => void>;\n\trawListeners(event: \"request\"): Array<(request: ClientRequest) => void>;\n\trawListeners(event: \"response\"): Array<(response: CacheResponse) => void>;\n\trawListeners(\n\t\tevent: \"error\",\n\t): Array<(error: RequestError | CacheError) => void>;\n\temit(event: \"request\", request: ClientRequest): boolean;\n\temit(event: \"response\", response: CacheResponse): boolean;\n\temit(event: \"error\", error: RequestError | CacheError): boolean;\n\teventNames(): Array<\"request\" | \"response\" | \"error\">;\n\tlistenerCount(type: \"request\" | \"response\" | \"error\"): number;\n}\n\nexport class RequestError extends Error {\n\tconstructor(error: Error) {\n\t\tsuper(error.message);\n\t\tObject.defineProperties(this, Object.getOwnPropertyDescriptors(error));\n\t}\n}\n\nexport class CacheError extends Error {\n\tconstructor(error: Error) {\n\t\tsuper(error.message);\n\t\tObject.defineProperties(this, Object.getOwnPropertyDescriptors(error));\n\t}\n}\n\nexport interface UrlOption {\n\tpath: string;\n\tpathname?: string;\n\tsearch?: string;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cacheable-request",
3
- "version": "13.0.9",
3
+ "version": "13.0.11",
4
4
  "description": "Wrap native HTTP requests with RFC compliant cache support",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -38,15 +38,16 @@
38
38
  "@types/http-cache-semantics": "^4.0.4",
39
39
  "get-stream": "^9.0.1",
40
40
  "http-cache-semantics": "^4.2.0",
41
- "keyv": "^5.5.0",
41
+ "keyv": "^5.5.3",
42
42
  "mimic-response": "^4.0.0",
43
43
  "normalize-url": "^8.0.2",
44
44
  "responselike": "^3.0.0"
45
45
  },
46
46
  "devDependencies": {
47
+ "@biomejs/biome": "^2.2.3",
47
48
  "@keyv/sqlite": "^4.0.5",
48
49
  "@types/express": "^5.0.3",
49
- "@types/node": "^24.2.0",
50
+ "@types/node": "^24.3.1",
50
51
  "@types/responselike": "^1.0.3",
51
52
  "@vitest/coverage-v8": "^3.2.4",
52
53
  "body-parser": "^2.2.0",
@@ -57,37 +58,12 @@
57
58
  "sqlite3": "^5.1.7",
58
59
  "tsup": "^8.5.0",
59
60
  "typescript": "^5.9.2",
60
- "vitest": "^3.2.4",
61
- "xo": "^1.2.1"
62
- },
63
- "xo": {
64
- "rules": {
65
- "@typescript-eslint/triple-slash-reference": 0,
66
- "@typescript-eslint/no-namespace": 0,
67
- "@typescript-eslint/no-unsafe-assignment": 0,
68
- "@typescript-eslint/no-unsafe-call": 0,
69
- "@typescript-eslint/ban-types": 0,
70
- "@typescript-eslint/restrict-template-expressions": 0,
71
- "@typescript-eslint/no-unsafe-return": 0,
72
- "@typescript-eslint/no-unsafe-argument": 0,
73
- "new-cap": 0,
74
- "unicorn/no-abusive-eslint-disable": 0,
75
- "@typescript-eslint/restrict-plus-operands": 0,
76
- "@typescript-eslint/no-implicit-any-catch": 0,
77
- "@typescript-eslint/consistent-type-imports": 0,
78
- "@typescript-eslint/consistent-type-definitions": 0,
79
- "@typescript-eslint/prefer-nullish-coalescing": 0,
80
- "n/prefer-global/url": 0,
81
- "n/no-deprecated-api": 0,
82
- "unicorn/prefer-event-target": 0,
83
- "@typescript-eslint/no-unnecessary-type-assertion": 0,
84
- "promise/prefer-await-to-then": 0,
85
- "@typescript-eslint/no-unnecessary-boolean-literal-compare": 0
86
- }
61
+ "vitest": "^3.2.4"
87
62
  },
88
63
  "scripts": {
89
- "test": "xo --fix && vitest run --coverage",
90
- "test:ci": "xo && vitest run --coverage",
64
+ "lint": "biome check --write --error-on-warnings",
65
+ "test": "pnpm lint && vitest run --coverage",
66
+ "test:ci": "biome check --error-on-warnings && vitest run --coverage",
91
67
  "prepublish": "pnpm run build",
92
68
  "build": "rimraf ./dist && tsc --project tsconfig.build.json",
93
69
  "clean": "rimraf node_modules ./coverage ./test/testdb.sqlite ./dist"