cacheable-request
Advanced tools
Comparing version 10.0.2 to 10.1.2
@@ -7,6 +7,6 @@ import { ServerResponse } from 'node:http'; | ||
cache: StorageAdapter; | ||
request: RequestFn; | ||
cacheRequest: RequestFn; | ||
hooks: Map<string, Func>; | ||
constructor(request: RequestFn, cacheAdapter?: StorageAdapter | string); | ||
createCacheableRequest: () => (options: CacheableOptions, cb?: ((response: ServerResponse | typeof Response) => void) | undefined) => Emitter; | ||
constructor(cacheRequest: RequestFn, cacheAdapter?: StorageAdapter | string); | ||
request: () => (options: CacheableOptions, cb?: ((response: ServerResponse | typeof Response) => void) | undefined) => Emitter; | ||
addHook: (name: string, fn: Func) => void; | ||
@@ -13,0 +13,0 @@ removeHook: (name: string) => boolean; |
@@ -13,5 +13,5 @@ import EventEmitter from 'node:events'; | ||
class CacheableRequest { | ||
constructor(request, cacheAdapter) { | ||
constructor(cacheRequest, cacheAdapter) { | ||
this.hooks = new Map(); | ||
this.createCacheableRequest = () => (options, cb) => { | ||
this.request = () => (options, cb) => { | ||
let url; | ||
@@ -144,3 +144,3 @@ if (typeof options === 'string') { | ||
try { | ||
const request_ = this.request(options_, handler); | ||
const request_ = this.cacheRequest(options_, handler); | ||
request_.once('error', requestErrorCallback); | ||
@@ -230,4 +230,4 @@ request_.once('abort', requestErrorCallback); | ||
} | ||
this.createCacheableRequest = this.createCacheableRequest.bind(this); | ||
this.request = request; | ||
this.request = this.request.bind(this); | ||
this.cacheRequest = cacheRequest; | ||
} | ||
@@ -234,0 +234,0 @@ } |
{ | ||
"name": "cacheable-request", | ||
"version": "10.0.2", | ||
"version": "10.1.2", | ||
"description": "Wrap native HTTP requests with RFC compliant cache support", | ||
@@ -74,6 +74,9 @@ "license": "MIT", | ||
"transform": { | ||
"^.+\\.(ts|tsx)$": ["ts-jest", { | ||
"tsconfig": "./tsconfig.build.json", | ||
"useESM": true | ||
}] | ||
"^.+\\.(ts|tsx)$": [ | ||
"ts-jest", | ||
{ | ||
"tsconfig": "./tsconfig.build.json", | ||
"useESM": true | ||
} | ||
] | ||
}, | ||
@@ -80,0 +83,0 @@ "testMatch": [ |
@@ -56,3 +56,3 @@ # cacheable-request | ||
// Now You can do | ||
const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest(); | ||
const cacheableRequest = new CacheableRequest(http.request).request(); | ||
const cacheReq = cacheableRequest('http://example.com', cb); | ||
@@ -63,11 +63,11 @@ cacheReq.on('request', req => req.end()); | ||
// You pass in any other http.request API compatible method to be wrapped with cache support: | ||
const cacheableRequest = new CacheableRequest(https.request).createCacheableRequest(); | ||
const cacheableRequest = new CacheableRequest(electron.net).createCacheableRequest(); | ||
const cacheableRequest = new CacheableRequest(https.request).request(); | ||
const cacheableRequest = new CacheableRequest(electron.net).request(); | ||
``` | ||
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. | ||
The biggest change is that when you do a `new` CacheableRequest you now want to call `request` method will give you the instance to use. | ||
```diff | ||
- const cacheableRequest = new CacheableRequest(http.request); | ||
+ const cacheableRequest = new CacheableRequest(http.request).createCacheableRequest(); | ||
+ const cacheableRequest = new CacheableRequest(http.request).request(); | ||
``` | ||
@@ -74,0 +74,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
50903