cacheable-request 8.3.1 → 10.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -11,6 +11,69 @@
11
11
 
12
12
  **Note:** This is a low level wrapper around the core HTTP modules, it's not a high level request library.
13
13
 
14
+ # Table of Contents
15
+ * [Latest Changes](#latest-changes)
16
+ * [Features](#features)
17
+ * [Install and Usage](#install-and-usage)
18
+ * [Storage Adapters](#storage-adapters)
19
+ * [API](#api)
20
+ * [Using Hooks](#using-hooks)
21
+ * [Contributing](#contributing)
22
+ * [Ask a Question](#ask-a-question)
23
+ * [License](#license) (MIT)
24
+
25
+ # Latest Changes
26
+
27
+ ## Breaking Changes with v10.0.0
28
+ This release contains breaking changes. This is the new way to use this package.
29
+
30
+ ### Usage Before v10
31
+ ```js
32
+ import http from 'http';
33
+ import CacheableRequest from 'cacheable-request';
34
+
35
+ // Then instead of
36
+ const req = http.request('http://example.com', cb);
37
+ req.end();
38
+
39
+ // You can do
40
+ const cacheableRequest = new CacheableRequest(http.request);
41
+ const cacheReq = cacheableRequest('http://example.com', cb);
42
+ cacheReq.on('request', req => req.end());
43
+ // Future requests to 'example.com' will be returned from cache if still valid
44
+
45
+ // You pass in any other http.request API compatible method to be wrapped with cache support:
46
+ const cacheableRequest = new CacheableRequest(https.request);
47
+ const cacheableRequest = new CacheableRequest(electron.net);
48
+ ```
49
+
50
+ ### Usage After v10
51
+
52
+ ```js
53
+ import CacheableRequest from 'cacheable-request';
54
+
55
+ // Now You can do
56
+ const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
57
+ const cacheReq = cacheableRequest('http://example.com', cb);
58
+ cacheReq.on('request', req => req.end());
59
+ // Future requests to 'example.com' will be returned from cache if still valid
60
+
61
+ // You pass in any other http.request API compatible method to be wrapped with cache support:
62
+ const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
63
+ const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();
64
+ ```
65
+
66
+ The biggest change is that when you do a `new` CacheableRequest you now want to call `createCacheableRequest` method will give you the instance to use.
67
+
68
+ ```diff
69
+ - const cacheableRequest = new CacheableRequest(http.request);
70
+ + const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
71
+ ```
72
+
73
+ ### ESM Support in version 9 and higher.
74
+
75
+ We are now using pure esm support in our package. If you need to use commonjs you can use v8 or lower. To learn more about using ESM please read this from `sindresorhus`: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c
76
+
14
77
  ## Features
15
78
 
16
79
  - Only stores cacheable responses as defined by RFC 7234
@@ -26,14 +89,12 @@
26
89
  - Adds cache support to any existing HTTP code with minimal changes
27
90
  - Uses [http-cache-semantics](https://github.com/pornel/http-cache-semantics) internally for HTTP RFC 7234 compliance
28
91
 
29
- ## Install
92
+ ## Install and Usage
30
93
 
31
94
  ```shell
32
95
  npm install cacheable-request
33
96
  ```
34
97
 
35
- ## Usage
36
-
37
98
  ```js
38
99
  import http from 'http';
39
100
  import CacheableRequest from 'cacheable-request';
@@ -43,14 +104,14 @@ const req = http.request('http://example.com', cb);
43
104
  req.end();
44
105
 
45
106
  // You can do
46
- const cacheableRequest = new CacheableRequest(http.request);
107
+ const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest();
47
108
  const cacheReq = cacheableRequest('http://example.com', cb);
48
109
  cacheReq.on('request', req => req.end());
49
110
  // Future requests to 'example.com' will be returned from cache if still valid
50
111
 
51
112
  // You pass in any other http.request API compatible method to be wrapped with cache support:
52
- const cacheableRequest = new CacheableRequest(https.request);
53
- const cacheableRequest = new CacheableRequest(electron.net);
113
+ const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest();
114
+ const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest();
54
115
  ```
55
116
 
56
117
  ## Storage Adapters
@@ -66,7 +127,7 @@ npm install @keyv/redis
66
127
  And then you can pass `CacheableRequest` your connection string:
67
128
 
68
129
  ```js
69
- const cacheableRequest = new CacheableRequest(http.request, 'redis://user:pass@localhost:6379');
130
+ const cacheableRequest = new CacheableRequest(http.request, 'redis://user:pass@localhost:6379').createCacheableRequest();
70
131
  ```
71
132
 
72
133
  [View all official Keyv storage adapters.](https://github.com/jaredwray/keyv#official-storage-adapters)
@@ -83,7 +144,7 @@ const storageAdapter = require('./my-storage-adapter');
83
144
  const QuickLRU = require('quick-lru');
84
145
  const storageAdapter = new QuickLRU({ maxSize: 1000 });
85
146
 
86
- const cacheableRequest = new CacheableRequest(http.request, storageAdapter);
147
+ const cacheableRequest = new CacheableRequest(http.request, storageAdapter).createCacheableRequest();
87
148
  ```
88
149
 
89
150
  View the [Keyv docs](https://github.com/jaredwray/keyv) for more information on how to use storage adapters.
@@ -198,9 +259,55 @@ cacheableRequest('example.com', cb)
198
259
  req.end();
199
260
  });
200
261
  ```
201
-
202
262
  **Note:** Database connection errors are emitted here, however `cacheable-request` will attempt to re-request the resource and bypass the cache on a connection error. Therefore a database connection error doesn't necessarily mean the request won't be fulfilled.
203
263
 
264
+
265
+ ## Using Hooks
266
+ Hooks have been implemented since version `v9` and are very useful to modify response before saving it in cache. You can use hooks to modify response before saving it in cache. You can also use hooks to modify response before returning it to user.
267
+
268
+ ### Add Hooks
269
+
270
+ The hook will pre compute response right before saving it in cache. You can include many hooks and it will run in order you add hook on response object.
271
+
272
+ ```js
273
+ import http from 'http';
274
+ import CacheableRequest from 'cacheable-request';
275
+
276
+ const cacheableRequest = new CacheableRequest(request, cache).createCacheableRequest();
277
+ cacheableRequest.addHook('response', async (response: any) => {
278
+ const buffer = await pm(gunzip)(response);
279
+ return buffer.toString();
280
+ });
281
+
282
+ ```
283
+ ### Remove Hooks
284
+
285
+ You can also remove hook by using below
286
+
287
+ ```js
288
+ CacheableRequest.removeHook('response');
289
+ ```
290
+
291
+ ## How to Contribute
292
+
293
+ Cacheable-Request is an open source package and community driven that is maintained regularly. In addtion we have a couple of other guidelines for review:
294
+
295
+ * [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) - Our code of conduct
296
+ * [CONTRIBUTING.md](CONTRIBUTING.md) - How to contribute to this project
297
+ * [SECURITY.md](SECURITY.md) - Security guidelines and supported versions
298
+
299
+ ## Post an Issue
300
+
301
+ To post an issue, navigate to the "Issues" tab in the main repository, and then select "New Issue." Enter a clear title describing the issue, as well as a description containing additional relevant information. Also select the label that best describes your issue type. For a bug report, for example, create an issue with the label "bug." In the description field, Be sure to include replication steps, as well as any relevant error messages.
302
+
303
+ If you're reporting a security violation, be sure to check out the project's [security policy](SECURITY.md).
304
+
305
+ Please also refer to our [Code of Conduct](CODE_OF_CONDUCT.md) for more information on how to report issues.
306
+
307
+ ## Ask a Question
308
+
309
+ To ask a question, create an issue with the label "question." In the issue description, include the related code and any context that can help us answer your question.
310
+
204
311
  ## License
205
312
 
206
313
  MIT © Luke Childs 2017-2021
package/dist/index.d.ts CHANGED
@@ -1,28 +1,19 @@
1
- /// <reference types="node" />
2
- /// <reference types="node" />
3
1
  import EventEmitter from 'node:events';
4
- declare const CacheableRequest: {
5
- (request: Function, cacheAdapter?: any): (options: any, cb?: ((response: {}) => void) | undefined) => EventEmitter;
6
- RequestError: {
7
- new (error: any): {
8
- name: string;
9
- message: string;
10
- stack?: string | undefined;
11
- };
12
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
13
- prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
14
- stackTraceLimit: number;
15
- };
16
- CacheError: {
17
- new (error: any): {
18
- name: string;
19
- message: string;
20
- stack?: string | undefined;
21
- };
22
- captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
23
- prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
24
- stackTraceLimit: number;
25
- };
26
- };
2
+ import { RequestOptions, ServerResponse } from 'node:http';
3
+ import { Options as CacheSemanticsOptions } from 'http-cache-semantics';
4
+ import Response from 'responselike';
5
+ import { RequestFn, StorageAdapter, Options } from './types.js';
6
+ declare type Func = (...args: any[]) => any;
7
+ declare class CacheableRequest {
8
+ cache: StorageAdapter;
9
+ request: RequestFn;
10
+ hooks: Map<string, Func>;
11
+ constructor(request: RequestFn, cacheAdapter?: StorageAdapter | string);
12
+ createCacheableRequest: () => (options: (Options & RequestOptions & CacheSemanticsOptions) | string | URL, cb?: ((response: ServerResponse | Response) => void) | undefined) => EventEmitter;
13
+ addHook: (name: string, fn: Func) => void;
14
+ removeHook: (name: string) => boolean;
15
+ getHook: (name: string) => Func | undefined;
16
+ runHook: (name: string, response: any) => Promise<any>;
17
+ }
27
18
  export default CacheableRequest;
28
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAYvC,QAAA,MAAM,gBAAgB;cAAsB,QAAQ,iBAAiB,GAAG,aAgBtD,GAAG,mBAAkB,EAAE,KAAK,IAAI;;oBAsN9B,GAAG;;;;;;;;;;oBAOH,GAAG;;;;;;;;;CAhOtB,CAAC;AAuOF,eAAe,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,aAAa,CAAC;AAIvC,OAAO,EAAC,cAAc,EAAE,cAAc,EAAkB,MAAM,WAAW,CAAC;AAG1E,OAAoB,EAAC,OAAO,IAAI,qBAAqB,EAAC,MAAM,sBAAsB,CAAC;AACnF,OAAO,QAAQ,MAAM,cAAc,CAAC;AAGpC,OAAO,EAAC,SAAS,EAAE,cAAc,EAAE,OAAO,EAAsC,MAAM,YAAY,CAAC;AAEnG,aAAK,IAAI,GAAG,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC;AAEpC,cAAM,gBAAgB;IACrB,KAAK,EAAE,cAAc,CAAC;IACtB,OAAO,EAAE,SAAS,CAAC;IACnB,KAAK,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAA2B;gBACvC,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,EAAE,cAAc,GAAG,MAAM;IAmBtE,sBAAsB,kBAAmB,CAAC,OAAO,GAAG,cAAc,GAAG,qBAAqB,CAAC,GAAG,MAAM,GAAG,GAAG,mBACzF,cAAc,GAAG,QAAQ,KAAK,IAAI,kBAAG,YAAY,CA8LhE;IAEF,OAAO,SAAU,MAAM,MAAM,IAAI,UAI/B;IAEF,UAAU,SAAU,MAAM,aAA6B;IAEvD,OAAO,SAAU,MAAM,sBAA0B;IAEjD,OAAO,SAAgB,MAAM,YAAY,GAAG,kBAM1C;CACF;AA6CD,eAAe,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,270 +1,269 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const node_events_1 = __importDefault(require("node:events"));
30
- const node_url_1 = __importDefault(require("node:url"));
31
- const node_crypto_1 = __importDefault(require("node:crypto"));
32
- const node_stream_1 = __importStar(require("node:stream"));
33
- const normalize_url_1 = __importDefault(require("normalize-url"));
34
- const get_stream_1 = __importDefault(require("get-stream"));
35
- const http_cache_semantics_1 = __importDefault(require("http-cache-semantics"));
36
- const responselike_1 = __importDefault(require("responselike"));
37
- const keyv_1 = __importDefault(require("keyv"));
38
- const mimic_response_1 = __importDefault(require("mimic-response"));
39
- const { Readable } = node_stream_1.default;
40
- const CacheableRequest = function (request, cacheAdapter) {
41
- let cache = {};
42
- if (cacheAdapter instanceof keyv_1.default) {
43
- cache = cacheAdapter;
44
- }
45
- else {
46
- cache = new keyv_1.default({
47
- uri: (typeof cacheAdapter === 'string' && cacheAdapter) || '',
48
- store: typeof cacheAdapter !== 'string' && cacheAdapter,
49
- namespace: 'cacheable-request',
50
- });
51
- }
52
- return createCacheableRequest(request, cache);
53
- };
54
- function createCacheableRequest(request, cache) {
55
- return (options, cb) => {
56
- let url;
57
- if (typeof options === 'string') {
58
- url = normalizeUrlObject(node_url_1.default.parse(options));
59
- options = {};
60
- }
61
- else if (options instanceof node_url_1.default.URL) {
62
- url = normalizeUrlObject(node_url_1.default.parse(options.toString()));
63
- options = {};
64
- }
65
- else {
66
- const [pathname, ...searchParts] = (options.path || '').split('?');
67
- const search = searchParts.length > 0
68
- ? `?${searchParts.join('?')}`
69
- : '';
70
- url = normalizeUrlObject({ ...options, pathname, search });
71
- }
72
- options = {
73
- headers: {},
74
- method: 'GET',
75
- cache: true,
76
- strictTtl: false,
77
- automaticFailover: false,
78
- ...options,
79
- ...urlObjectToRequestOptions(url),
80
- };
81
- options.headers = Object.fromEntries(Object.entries(options.headers).map(([key, value]) => [key.toLowerCase(), value]));
82
- const ee = new node_events_1.default();
83
- const normalizedUrlString = (0, normalize_url_1.default)(node_url_1.default.format(url), {
84
- stripWWW: false,
85
- removeTrailingSlash: false,
86
- stripAuthentication: false,
87
- });
88
- let key = `${options.method}:${normalizedUrlString}`;
89
- // POST, PATCH, and PUT requests may be cached, depending on the response
90
- // cache-control headers. As a result, the body of the request should be
91
- // added to the cache key in order to avoid collisions.
92
- if (options.body && ['POST', 'PATCH', 'PUT'].includes(options.method)) {
93
- if (options.body instanceof Readable) {
94
- // Streamed bodies should completely skip the cache because they may
95
- // or may not be hashable and in either case the stream would need to
96
- // close before the cache key could be generated.
97
- options.cache = false;
1
+ import EventEmitter from 'node:events';
2
+ import urlLib 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 getStream 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';
12
+ class CacheableRequest {
13
+ constructor(request, cacheAdapter) {
14
+ this.hooks = new Map();
15
+ this.createCacheableRequest = () => (options, cb) => {
16
+ let url;
17
+ if (typeof options === 'string') {
18
+ url = normalizeUrlObject(urlLib.parse(options));
19
+ options = {};
20
+ }
21
+ else if (options instanceof urlLib.URL) {
22
+ url = normalizeUrlObject(urlLib.parse(options.toString()));
23
+ options = {};
98
24
  }
99
25
  else {
100
- key += `:${node_crypto_1.default.createHash('md5').update(options.body).digest('hex')}`;
26
+ const [pathname, ...searchParts] = (options.path ?? '').split('?');
27
+ const search = searchParts.length > 0
28
+ ? `?${searchParts.join('?')}`
29
+ : '';
30
+ url = normalizeUrlObject({ ...options, pathname, search });
101
31
  }
102
- }
103
- let revalidate = false;
104
- let madeRequest = false;
105
- const makeRequest = (options_) => {
106
- madeRequest = true;
107
- let requestErrored = false;
108
- let requestErrorCallback;
109
- const requestErrorPromise = new Promise(resolve => {
110
- requestErrorCallback = () => {
111
- if (!requestErrored) {
112
- requestErrored = true;
113
- resolve();
114
- }
115
- };
32
+ options = {
33
+ headers: {},
34
+ method: 'GET',
35
+ cache: true,
36
+ strictTtl: false,
37
+ automaticFailover: false,
38
+ ...options,
39
+ ...urlObjectToRequestOptions(url),
40
+ };
41
+ options.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [key.toLowerCase(), value]));
42
+ const ee = new EventEmitter();
43
+ const normalizedUrlString = normalizeUrl(urlLib.format(url), {
44
+ stripWWW: false,
45
+ removeTrailingSlash: false,
46
+ stripAuthentication: false,
116
47
  });
117
- const handler = (response) => {
118
- if (revalidate && !options_.forceRefresh) {
119
- response.status = response.statusCode;
120
- const revalidatedPolicy = http_cache_semantics_1.default.fromObject(revalidate.cachePolicy).revalidatedPolicy(options_, response);
121
- if (!revalidatedPolicy.modified) {
122
- const headers = revalidatedPolicy.policy.responseHeaders();
123
- response = new responselike_1.default(revalidate.statusCode, headers, revalidate.body, revalidate.url);
124
- response.cachePolicy = revalidatedPolicy.policy;
125
- response.fromCache = true;
126
- }
127
- }
128
- if (!response.fromCache) {
129
- response.cachePolicy = new http_cache_semantics_1.default(options_, response, options_);
130
- response.fromCache = false;
48
+ let key = `${options.method}:${normalizedUrlString}`;
49
+ // POST, PATCH, and PUT requests may be cached, depending on the response
50
+ // cache-control headers. As a result, the body of the request should be
51
+ // added to the cache key in order to avoid collisions.
52
+ if (options.body && options.method !== undefined && ['POST', 'PATCH', 'PUT'].includes(options.method)) {
53
+ if (options.body instanceof stream.Readable) {
54
+ // Streamed bodies should completely skip the cache because they may
55
+ // or may not be hashable and in either case the stream would need to
56
+ // close before the cache key could be generated.
57
+ options.cache = false;
131
58
  }
132
- let clonedResponse;
133
- if (options_.cache && response.cachePolicy.storable()) {
134
- clonedResponse = cloneResponse(response);
135
- (async () => {
136
- try {
137
- const bodyPromise = get_stream_1.default.buffer(response);
138
- await Promise.race([
139
- requestErrorPromise,
140
- new Promise(resolve => response.once('end', resolve)), // eslint-disable-line no-promise-executor-return
141
- ]);
142
- const body = await bodyPromise;
143
- const value = {
144
- cachePolicy: response.cachePolicy.toObject(),
145
- url: response.url,
146
- statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
147
- body,
148
- };
149
- let ttl = options_.strictTtl ? response.cachePolicy.timeToLive() : undefined;
150
- if (options_.maxTtl) {
151
- ttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;
152
- }
153
- await cache.set(key, value, ttl);
154
- }
155
- catch (error) {
156
- ee.emit('error', new CacheableRequest.CacheError(error));
157
- }
158
- })();
59
+ else {
60
+ key += `:${crypto.createHash('md5').update(options.body).digest('hex')}`;
159
61
  }
160
- else if (options_.cache && revalidate) {
161
- (async () => {
162
- try {
163
- await cache.delete(key);
62
+ }
63
+ let revalidate = false;
64
+ let madeRequest = false;
65
+ const makeRequest = (options_) => {
66
+ madeRequest = true;
67
+ let requestErrored = false;
68
+ let requestErrorCallback = () => { };
69
+ const requestErrorPromise = new Promise(resolve => {
70
+ requestErrorCallback = () => {
71
+ if (!requestErrored) {
72
+ requestErrored = true;
73
+ resolve();
164
74
  }
165
- catch (error) {
166
- ee.emit('error', new CacheableRequest.CacheError(error));
75
+ };
76
+ });
77
+ const handler = (response) => {
78
+ if (revalidate) {
79
+ response.status = response.statusCode;
80
+ const revalidatedPolicy = CachePolicy.fromObject(revalidate.cachePolicy).revalidatedPolicy(options_, response);
81
+ if (!revalidatedPolicy.modified) {
82
+ const headers = convertHeaders(revalidatedPolicy.policy.responseHeaders());
83
+ response = new Response({ statusCode: revalidate.statusCode, headers, body: revalidate.body, url: revalidate.url });
84
+ response.cachePolicy = revalidatedPolicy.policy;
85
+ response.fromCache = true;
167
86
  }
168
- })();
87
+ }
88
+ if (!response.fromCache) {
89
+ response.cachePolicy = new CachePolicy(options_, response, options_);
90
+ response.fromCache = false;
91
+ }
92
+ let clonedResponse;
93
+ if (options_.cache && response.cachePolicy.storable()) {
94
+ clonedResponse = cloneResponse(response);
95
+ (async () => {
96
+ try {
97
+ const bodyPromise = getStream.buffer(response);
98
+ await Promise.race([
99
+ requestErrorPromise,
100
+ new Promise(resolve => response.once('end', resolve)), // eslint-disable-line no-promise-executor-return
101
+ ]);
102
+ const body = await bodyPromise;
103
+ const value = {
104
+ cachePolicy: response.cachePolicy.toObject(),
105
+ url: response.url,
106
+ statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
107
+ body,
108
+ };
109
+ let ttl = options_.strictTtl ? response.cachePolicy.timeToLive() : undefined;
110
+ if (options_.maxTtl) {
111
+ ttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;
112
+ }
113
+ if (this.hooks.size > 0) {
114
+ /* eslint-disable no-await-in-loop */
115
+ for (const key_ of this.hooks.keys()) {
116
+ value.body = await this.runHook(key_, value.body);
117
+ }
118
+ /* eslint-enable no-await-in-loop */
119
+ }
120
+ await this.cache.set(key, value, ttl);
121
+ }
122
+ catch (error) {
123
+ ee.emit('error', new CacheError(error));
124
+ }
125
+ })();
126
+ }
127
+ else if (options_.cache && revalidate) {
128
+ (async () => {
129
+ try {
130
+ await this.cache.delete(key);
131
+ }
132
+ catch (error) {
133
+ ee.emit('error', new CacheError(error));
134
+ }
135
+ })();
136
+ }
137
+ ee.emit('response', clonedResponse ?? response);
138
+ if (typeof cb === 'function') {
139
+ cb(clonedResponse ?? response);
140
+ }
141
+ };
142
+ try {
143
+ const request_ = this.request(options_, handler);
144
+ request_.once('error', requestErrorCallback);
145
+ request_.once('abort', requestErrorCallback);
146
+ ee.emit('request', request_);
169
147
  }
170
- ee.emit('response', clonedResponse || response);
171
- if (typeof cb === 'function') {
172
- cb(clonedResponse || response);
148
+ catch (error) {
149
+ ee.emit('error', new RequestError(error));
173
150
  }
174
151
  };
175
- try {
176
- const request_ = request(options_, handler);
177
- request_.once('error', requestErrorCallback);
178
- request_.once('abort', requestErrorCallback);
179
- ee.emit('request', request_);
180
- }
181
- catch (error) {
182
- ee.emit('error', new CacheableRequest.RequestError(error));
183
- }
184
- };
185
- (async () => {
186
- const get = async (options_) => {
187
- await Promise.resolve();
188
- const cacheEntry = options_.cache ? await cache.get(key) : undefined;
189
- if (typeof cacheEntry === 'undefined') {
190
- makeRequest(options_);
191
- return;
192
- }
193
- const policy = http_cache_semantics_1.default.fromObject(cacheEntry.cachePolicy);
194
- if (policy.satisfiesWithoutRevalidation(options_) && !options_.forceRefresh) {
195
- const headers = policy.responseHeaders();
196
- const response = new responselike_1.default(cacheEntry.statusCode, headers, cacheEntry.body, cacheEntry.url);
197
- response.cachePolicy = policy;
198
- response.fromCache = true;
199
- ee.emit('response', response);
200
- if (typeof cb === 'function') {
201
- cb(response);
152
+ (async () => {
153
+ const get = async (options_) => {
154
+ await Promise.resolve();
155
+ const cacheEntry = options_.cache ? await this.cache.get(key) : undefined;
156
+ if (typeof cacheEntry === 'undefined' && !options_.forceRefresh) {
157
+ makeRequest(options_);
158
+ return;
159
+ }
160
+ const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
161
+ if (policy.satisfiesWithoutRevalidation(options_) && !options_.forceRefresh) {
162
+ const headers = convertHeaders(policy.responseHeaders());
163
+ const response = new Response({ statusCode: cacheEntry.statusCode, headers, body: cacheEntry.body, url: cacheEntry.url });
164
+ response.cachePolicy = policy;
165
+ response.fromCache = true;
166
+ ee.emit('response', response);
167
+ if (typeof cb === 'function') {
168
+ cb(response);
169
+ }
170
+ }
171
+ else if (policy.satisfiesWithoutRevalidation(options_) && Date.now() >= policy.timeToLive() && options_.forceRefresh) {
172
+ await this.cache.delete(key);
173
+ options_.headers = policy.revalidationHeaders(options_);
174
+ makeRequest(options_);
175
+ }
176
+ else {
177
+ revalidate = cacheEntry;
178
+ options_.headers = policy.revalidationHeaders(options_);
179
+ makeRequest(options_);
202
180
  }
181
+ };
182
+ const errorHandler = (error) => ee.emit('error', new CacheError(error));
183
+ if (this.cache instanceof Keyv) {
184
+ const cachek = this.cache;
185
+ cachek.once('error', errorHandler);
186
+ ee.on('error', () => cachek.removeListener('error', errorHandler));
203
187
  }
204
- else {
205
- revalidate = cacheEntry;
206
- options_.headers = policy.revalidationHeaders(options_);
207
- makeRequest(options_);
188
+ try {
189
+ await get(options);
208
190
  }
209
- };
210
- const errorHandler = (error) => ee.emit('error', new CacheableRequest.CacheError(error));
211
- cache.once('error', errorHandler);
212
- ee.on('response', () => cache.removeListener('error', errorHandler));
213
- try {
214
- await get(options);
215
- }
216
- catch (error) {
217
- if (options.automaticFailover && !madeRequest) {
218
- makeRequest(options);
191
+ catch (error) {
192
+ if (options.automaticFailover && !madeRequest) {
193
+ makeRequest(options);
194
+ }
195
+ ee.emit('error', new CacheError(error));
219
196
  }
220
- ee.emit('error', new CacheableRequest.CacheError(error));
197
+ })();
198
+ return ee;
199
+ };
200
+ this.addHook = (name, fn) => {
201
+ if (!this.hooks.has(name)) {
202
+ this.hooks.set(name, fn);
221
203
  }
222
- })();
223
- return ee;
224
- };
204
+ };
205
+ this.removeHook = (name) => this.hooks.delete(name);
206
+ this.getHook = (name) => this.hooks.get(name);
207
+ this.runHook = async (name, response) => {
208
+ if (!response) {
209
+ return new CacheError(new Error('runHooks requires response argument'));
210
+ }
211
+ return this.hooks.get(name)?.(response);
212
+ };
213
+ if (cacheAdapter instanceof Keyv) {
214
+ this.cache = cacheAdapter;
215
+ }
216
+ else if (typeof cacheAdapter === 'string') {
217
+ this.cache = new Keyv({
218
+ uri: cacheAdapter,
219
+ namespace: 'cacheable-request',
220
+ });
221
+ }
222
+ else {
223
+ this.cache = new Keyv({
224
+ store: cacheAdapter,
225
+ namespace: 'cacheable-request',
226
+ });
227
+ }
228
+ this.createCacheableRequest = this.createCacheableRequest.bind(this);
229
+ this.request = request;
230
+ }
225
231
  }
226
- function cloneResponse(response) {
227
- const clone = new node_stream_1.PassThrough({ autoDestroy: false });
228
- (0, mimic_response_1.default)(response, clone);
232
+ const entries = Object.entries;
233
+ const cloneResponse = (response) => {
234
+ const clone = new PassThroughStream({ autoDestroy: false });
235
+ mimicResponse(response, clone);
229
236
  return response.pipe(clone);
230
- }
231
- function urlObjectToRequestOptions(url) {
237
+ };
238
+ const urlObjectToRequestOptions = (url) => {
232
239
  const options = { ...url };
233
240
  options.path = `${url.pathname || '/'}${url.search || ''}`;
234
241
  delete options.pathname;
235
242
  delete options.search;
236
243
  return options;
237
- }
238
- function normalizeUrlObject(url) {
239
- // If url was parsed by url.parse or new URL:
240
- // - hostname will be set
241
- // - host will be hostname[:port]
242
- // - port will be set if it was explicit in the parsed string
243
- // Otherwise, url was from request options:
244
- // - hostname or host may be set
245
- // - host shall not have port encoded
246
- return {
247
- protocol: url.protocol,
248
- auth: url.auth,
249
- hostname: url.hostname || url.host || 'localhost',
250
- port: url.port,
251
- pathname: url.pathname,
252
- search: url.search,
253
- };
254
- }
255
- CacheableRequest.RequestError = class extends Error {
256
- constructor(error) {
257
- super(error.message);
258
- this.name = 'RequestError';
259
- Object.assign(this, error);
260
- }
261
244
  };
262
- CacheableRequest.CacheError = class extends Error {
263
- constructor(error) {
264
- super(error.message);
265
- this.name = 'CacheError';
266
- Object.assign(this, error);
245
+ const normalizeUrlObject = (url) =>
246
+ // If url was parsed by url.parse or new URL:
247
+ // - hostname will be set
248
+ // - host will be hostname[:port]
249
+ // - port will be set if it was explicit in the parsed string
250
+ // Otherwise, url was from request options:
251
+ // - hostname or host may be set
252
+ // - host shall not have port encoded
253
+ ({
254
+ protocol: url.protocol,
255
+ auth: url.auth,
256
+ hostname: url.hostname || url.host || 'localhost',
257
+ port: url.port,
258
+ pathname: url.pathname,
259
+ search: url.search,
260
+ });
261
+ const convertHeaders = (headers) => {
262
+ const result = [];
263
+ for (const name of Object.keys(headers)) {
264
+ result[name.toLowerCase()] = headers[name];
267
265
  }
266
+ return result;
268
267
  };
269
- exports.default = CacheableRequest;
268
+ export default CacheableRequest;
270
269
  //# 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,8DAAuC;AACvC,wDAA8B;AA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,GAAG,CAAC,IAAI,IAAI,WAAW;IACjD,IAAI,EAAE,GAAG,CAAC,IAAI;IACd,QAAQ,EAAE,GAAG,CAAC,QAAQ;IACtB,MAAM,EAAE,GAAG,CAAC,MAAM;CAClB,CAAC,CAAC;AAEJ,MAAM,cAAc,GAAG,CAAC,OAA4B,EAAE,EAAE;IACvD,MAAM,MAAM,GAAQ,EAAE,CAAC;IACvB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE;QACxC,MAAM,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;KAC3C;IAED,OAAO,MAAM,CAAC;AACf,CAAC,CAAC;AAEF,eAAe,gBAAgB,CAAC"}
@@ -0,0 +1,97 @@
1
+ /// <reference types="node" resolution-mode="require"/>
2
+ /// <reference types="node" resolution-mode="require"/>
3
+ /// <reference types="node" resolution-mode="require"/>
4
+ /// <reference types="node" resolution-mode="require"/>
5
+ import { request, RequestOptions, ClientRequest, ServerResponse } from 'node:http';
6
+ import { URL } from 'node:url';
7
+ import { EventEmitter } from 'node:events';
8
+ import { Buffer } from 'node:buffer';
9
+ import { Store } from 'keyv';
10
+ import { Options as CacheSemanticsOptions } from 'http-cache-semantics';
11
+ import ResponseLike from 'responselike';
12
+ export declare type RequestFn = typeof request;
13
+ export declare type RequestFunction = typeof request;
14
+ export declare type CacheableRequestFunction = (options: (Options & RequestOptions & CacheSemanticsOptions) | string | URL, cb?: (response: ServerResponse | typeof ResponseLike) => void) => EventEmitter;
15
+ export declare type StorageAdapter = Store<any>;
16
+ export interface Options {
17
+ /**
18
+ * If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.
19
+ * @default true
20
+ */
21
+ cache?: boolean | undefined;
22
+ /**
23
+ * If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
24
+ *
25
+ * If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated
26
+ * on the next request with `If-None-Match`/`If-Modified-Since` headers.
27
+ * @default false
28
+ */
29
+ strictTtl?: boolean | undefined;
30
+ /**
31
+ * Limits TTL. The `number` represents milliseconds.
32
+ * @default undefined
33
+ */
34
+ maxTtl?: number | undefined;
35
+ /**
36
+ * When set to `true`, if the DB connection fails we will automatically fallback to a network request.
37
+ * DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
38
+ * @default false
39
+ */
40
+ automaticFailover?: boolean | undefined;
41
+ /**
42
+ * Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a
43
+ * new request and override the cache instead.
44
+ * @default false
45
+ */
46
+ forceRefresh?: boolean | undefined;
47
+ url?: string | undefined;
48
+ headers?: Record<string, string | string[] | undefined>;
49
+ body?: Buffer;
50
+ }
51
+ export interface Emitter extends EventEmitter {
52
+ addListener(event: 'request', listener: (request: ClientRequest) => void): this;
53
+ addListener(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
54
+ addListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
55
+ on(event: 'request', listener: (request: ClientRequest) => void): this;
56
+ on(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
57
+ on(event: 'error', listener: (error: RequestError | CacheError) => void): this;
58
+ once(event: 'request', listener: (request: ClientRequest) => void): this;
59
+ once(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
60
+ once(event: 'error', listener: (error: RequestError | CacheError) => void): this;
61
+ prependListener(event: 'request', listener: (request: ClientRequest) => void): this;
62
+ prependListener(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
63
+ prependListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
64
+ prependOnceListener(event: 'request', listener: (request: ClientRequest) => void): this;
65
+ prependOnceListener(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
66
+ prependOnceListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
67
+ removeListener(event: 'request', listener: (request: ClientRequest) => void): this;
68
+ removeListener(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
69
+ removeListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
70
+ off(event: 'request', listener: (request: ClientRequest) => void): this;
71
+ off(event: 'response', listener: (response: ServerResponse | typeof ResponseLike) => void): this;
72
+ off(event: 'error', listener: (error: RequestError | CacheError) => void): this;
73
+ removeAllListeners(event?: 'request' | 'response' | 'error'): this;
74
+ listeners(event: 'request'): Array<(request: ClientRequest) => void>;
75
+ listeners(event: 'response'): Array<(response: ServerResponse | typeof ResponseLike) => void>;
76
+ listeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;
77
+ rawListeners(event: 'request'): Array<(request: ClientRequest) => void>;
78
+ rawListeners(event: 'response'): Array<(response: ServerResponse | typeof ResponseLike) => void>;
79
+ rawListeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;
80
+ emit(event: 'request', request: ClientRequest): boolean;
81
+ emit(event: 'response', response: ServerResponse | typeof ResponseLike): boolean;
82
+ emit(event: 'error', error: RequestError | CacheError): boolean;
83
+ eventNames(): Array<'request' | 'response' | 'error'>;
84
+ listenerCount(type: 'request' | 'response' | 'error'): number;
85
+ }
86
+ export declare class RequestError extends Error {
87
+ constructor(error: Error);
88
+ }
89
+ export declare class CacheError extends Error {
90
+ constructor(error: Error);
91
+ }
92
+ export interface UrlOption {
93
+ path: string;
94
+ pathname?: string;
95
+ search?: string;
96
+ }
97
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;;AASA,OAAO,EAAC,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,cAAc,EAAC,MAAM,WAAW,CAAC;AACjF,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,EAAC,KAAK,EAAC,MA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AAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB"}
package/dist/types.js ADDED
@@ -0,0 +1,19 @@
1
+ // Type definitions for cacheable-request 6.0
2
+ // Project: https://github.com/lukechilds/cacheable-request#readme
3
+ // Definitions by: BendingBender <https://github.com/BendingBender>
4
+ // Paul Melnikow <https://github.com/paulmelnikow>
5
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
6
+ // TypeScript Version: 2.3
7
+ export class RequestError extends Error {
8
+ constructor(error) {
9
+ super(error.message);
10
+ Object.assign(this, error);
11
+ }
12
+ }
13
+ export class CacheError extends Error {
14
+ constructor(error) {
15
+ super(error.message);
16
+ Object.assign(this, error);
17
+ }
18
+ }
19
+ //# sourceMappingURL=types.js.map
@@ -0,0 +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;AAoH1B,MAAM,OAAO,YAAa,SAAQ,KAAK;IACtC,YAAY,KAAY;QACvB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACD;AACD,MAAM,OAAO,UAAW,SAAQ,KAAK;IACpC,YAAY,KAAY;QACvB,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAC5B,CAAC;CACD"}
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "cacheable-request",
3
- "version": "8.3.1",
3
+ "version": "10.0.1",
4
4
  "description": "Wrap native HTTP requests with RFC compliant cache support",
5
5
  "license": "MIT",
6
6
  "repository": "jaredwray/cacheable-request",
7
7
  "author": "Jared Wray <me@jaredwray.com> (http://jaredwray.com)",
8
- "main": "./dist/index.js",
8
+ "type": "module",
9
+ "exports": "./dist/index.js",
9
10
  "types": "./dist/index.d.ts",
10
11
  "engines": {
11
12
  "node": ">=14.16"
12
13
  },
13
14
  "scripts": {
14
- "test": "xo && jest --coverage",
15
+ "test": "xo && NODE_OPTIONS=--experimental-vm-modules jest --coverage ",
16
+ "prepare": "npm run build",
15
17
  "build": "tsc --project tsconfig.build.json",
16
18
  "clean": "rm -rf node_modules && rm -rf ./coverage && rm -rf ./package-lock.json && rm -rf ./test/testdb.sqlite && rm -rf ./dist"
17
19
  },
@@ -33,50 +35,49 @@
33
35
  "dependencies": {
34
36
  "get-stream": "^6.0.1",
35
37
  "http-cache-semantics": "^4.1.0",
36
- "keyv": "^4.3.2",
37
- "mimic-response": "^3.1.0",
38
- "normalize-url": "^6.0.3",
39
- "responselike": "^2.0.0"
38
+ "keyv": "^4.5.0",
39
+ "mimic-response": "^4.0.0",
40
+ "normalize-url": "^7.1.0",
41
+ "responselike": "^3.0.0"
40
42
  },
41
43
  "devDependencies": {
42
- "@babel/core": "^7.18.5",
43
- "@babel/preset-env": "^7.18.2",
44
- "@keyv/sqlite": "^3.5.2",
44
+ "@keyv/sqlite": "^3.5.3",
45
45
  "@types/create-test-server": "^3.0.1",
46
46
  "@types/delay": "^3.1.0",
47
47
  "@types/get-stream": "^3.0.2",
48
48
  "@types/http-cache-semantics": "^4.0.1",
49
- "@types/jest": "^28.1.3",
50
- "@types/node": "^18.0.0",
51
- "@types/pify": "^5.0.1",
49
+ "@types/jest": "^29.0.0",
50
+ "@types/node": "^18.7.16",
52
51
  "@types/responselike": "^1.0.0",
53
52
  "@types/sqlite3": "^3.1.8",
54
53
  "create-test-server": "3.0.1",
55
- "eslint-plugin-jest": "^26.5.3",
56
54
  "delay": "^5.0.0",
57
- "jest": "^28.1.1",
58
- "pify": "^5.0.0",
59
- "sqlite3": "^5.0.8",
60
- "ts-jest": "^28.0.5",
61
- "ts-node": "^10.8.1",
62
- "typescript": "^4.7.4",
63
- "xo": "^0.50.0"
55
+ "eslint-plugin-jest": "^27.0.4",
56
+ "jest": "^29.0.3",
57
+ "sqlite3": "^5.0.11",
58
+ "ts-jest": "^29.0.0",
59
+ "ts-jest-resolver": "^2.0.0",
60
+ "ts-node": "^10.9.1",
61
+ "typescript": "^4.8.3",
62
+ "xo": "^0.51.0"
64
63
  },
65
64
  "jest": {
66
- "globals": {
67
- "ts-jest": {
68
- "tsconfig": "./tsconfig.json"
69
- }
70
- },
65
+ "extensionsToTreatAsEsm": [
66
+ ".ts"
67
+ ],
68
+ "resolver": "ts-jest-resolver",
71
69
  "moduleFileExtensions": [
72
70
  "ts",
73
71
  "js"
74
72
  ],
75
73
  "transform": {
76
- "^.+\\.(ts|tsx)$": "ts-jest"
74
+ "^.+\\.(ts|tsx)$": ["ts-jest", {
75
+ "tsconfig": "./tsconfig.build.json",
76
+ "useESM": true
77
+ }]
77
78
  },
78
79
  "testMatch": [
79
- "**/test/*.test.(ts)"
80
+ "**/test/*.test.(ts|js)"
80
81
  ],
81
82
  "testEnvironment": "node"
82
83
  },
@@ -88,18 +89,16 @@
88
89
  "plugin:jest/recommended"
89
90
  ],
90
91
  "rules": {
91
- "@typescript-eslint/object-curly-spacing": 0,
92
- "@typescript-eslint/naming-convention": 0,
92
+ "@typescript-eslint/triple-slash-reference": 0,
93
+ "@typescript-eslint/no-namespace": 0,
93
94
  "@typescript-eslint/no-unsafe-assignment": 0,
94
95
  "@typescript-eslint/no-unsafe-call": 0,
95
96
  "@typescript-eslint/ban-types": 0,
96
97
  "@typescript-eslint/restrict-template-expressions": 0,
97
98
  "@typescript-eslint/no-unsafe-return": 0,
98
99
  "new-cap": 0,
99
- "@typescript-eslint/no-empty-function": 0,
100
100
  "@typescript-eslint/restrict-plus-operands": 0,
101
- "@typescript-eslint/no-floating-promises": 0,
102
- "@typescript-eslint/await-thenable": 0
101
+ "@typescript-eslint/no-implicit-any-catch": 0
103
102
  }
104
103
  }
105
104
  }