Socket
Socket
Sign inDemoInstall

cacheable-request

Package Overview
Dependencies
Maintainers
3
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cacheable-request - npm Package Compare versions

Comparing version 10.0.2 to 10.1.2

6

dist/index.d.ts

@@ -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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc