🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

cacheable-request

Package Overview
Dependencies
Maintainers
3
Versions
81
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
13.0.9
to
13.0.10
+3
-3
dist/index.d.ts

@@ -1,3 +0,3 @@

import { Keyv } from 'keyv';
import { RequestFn, CacheResponse, CacheValue, CacheableOptions, Emitter } from './types.js';
import { Keyv } from "keyv";
import { type CacheableOptions, type CacheResponse, type CacheValue, type Emitter, type RequestFn } from "./types.js";
type Function_ = (...arguments_: any[]) => any;

@@ -32,4 +32,4 @@ declare class CacheableRequest {

export default CacheableRequest;
export * from './types.js';
export * from "./types.js";
export declare const onResponse = "onResponse";
//# sourceMappingURL=index.d.ts.map

@@ -1,1 +0,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,MAAM,MAAM,aAA6B;IAEvD,O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F,eAAe,gBAAgB,CAAC;AAChC,cAAc,YAAY,CAAC;AAC3B,eAAO,MAAM,UAAU,eAAe,CAAC"}

@@ -1,19 +0,21 @@

import EventEmitter from 'node:events';
import urlLib, { URL } from 'node:url';
import crypto from 'node:crypto';
import stream, { PassThrough as PassThroughStream } from 'node:stream';
import normalizeUrl from 'normalize-url';
import { getStreamAsBuffer } from 'get-stream';
import CachePolicy from 'http-cache-semantics';
import Response from 'responselike';
import { Keyv } from 'keyv';
import mimicResponse from 'mimic-response';
import { CacheError, RequestError, } from './types.js';
// biome-ignore-all lint/suspicious/noImplicitAnyLet: legacy format
// biome-ignore-all lint/suspicious/noExplicitAny: legacy format
import crypto from "node:crypto";
import EventEmitter from "node:events";
import stream, { PassThrough as PassThroughStream } from "node:stream";
import urlLib, { URL } from "node:url";
import { getStreamAsBuffer } from "get-stream";
import CachePolicy from "http-cache-semantics";
import { Keyv } from "keyv";
import mimicResponse from "mimic-response";
import normalizeUrl from "normalize-url";
import Response from "responselike";
import { CacheError, RequestError, } from "./types.js";
class CacheableRequest {
constructor(cacheRequest, cacheAdapter) {
this.cache = new Keyv({ namespace: 'cacheable-request' });
this.cache = new Keyv({ namespace: "cacheable-request" });
this.hooks = new Map();
this.request = () => (options, callback) => {
let url;
if (typeof options === 'string') {
if (typeof options === "string") {
url = normalizeUrlObject(parseWithWhatwg(options));

@@ -27,6 +29,4 @@ options = {};

else {
const [pathname, ...searchParts] = (options.path ?? '').split('?');
const search = searchParts.length > 0
? `?${searchParts.join('?')}`
: '';
const [pathname, ...searchParts] = (options.path ?? "").split("?");
const search = searchParts.length > 0 ? `?${searchParts.join("?")}` : "";
url = normalizeUrlObject({ ...options, pathname, search });

@@ -36,3 +36,3 @@ }

headers: {},
method: 'GET',
method: "GET",
cache: true,

@@ -44,6 +44,9 @@ strictTtl: false,

};
options.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [key.toLowerCase(), value]));
options.headers = Object.fromEntries(entries(options.headers).map(([key, value]) => [
key.toLowerCase(),
value,
]));
const ee = new EventEmitter();
const normalizedUrlString = normalizeUrl(urlLib.format(url), {
stripWWW: false, // eslint-disable-line @typescript-eslint/naming-convention
stripWWW: false,
removeTrailingSlash: false,

@@ -56,3 +59,5 @@ stripAuthentication: false,

// added to the cache key in order to avoid collisions.
if (options.body && options.method !== undefined && ['POST', 'PATCH', 'PUT'].includes(options.method)) {
if (options.body &&
options.method !== undefined &&
["POST", "PATCH", "PUT"].includes(options.method)) {
if (options.body instanceof stream.Readable) {

@@ -65,3 +70,3 @@ // Streamed bodies should completely skip the cache because they may

else {
key += `:${crypto.createHash('md5').update(options.body).digest('hex')}`;
key += `:${crypto.createHash("md5").update(options.body).digest("hex")}`;
}

@@ -74,4 +79,7 @@ }

let requestErrored = false;
let requestErrorCallback = () => { };
const requestErrorPromise = new Promise(resolve => {
/* c8 ignore next 4 */
let requestErrorCallback = () => {
/* do nothing */
};
const requestErrorPromise = new Promise((resolve) => {
requestErrorCallback = () => {

@@ -90,10 +98,12 @@ if (!requestErrored) {

response.resume();
await new Promise(resolve => {
await new Promise((resolve) => {
// Skipping 'error' handler cause 'error' event should't be emitted for 304 response
response
.once('end', resolve);
response.once("end", resolve);
});
const headers = convertHeaders(revalidatedPolicy.policy.responseHeaders());
response = new Response({
statusCode: revalidate.statusCode, headers, body: revalidate.body, url: revalidate.url,
statusCode: revalidate.statusCode,
headers,
body: revalidate.body,
url: revalidate.url,
});

@@ -116,4 +126,4 @@ response.cachePolicy = revalidatedPolicy.policy;

requestErrorPromise,
new Promise(resolve => response.once('end', resolve)), // eslint-disable-line no-promise-executor-return
new Promise(resolve => response.once('close', resolve)), // eslint-disable-line no-promise-executor-return
new Promise((resolve) => response.once("end", resolve)),
new Promise((resolve) => response.once("close", resolve)),
]);

@@ -123,7 +133,11 @@ const body = await bodyPromise;

url: response.url,
statusCode: response.fromCache ? revalidate.statusCode : response.statusCode,
statusCode: response.fromCache
? revalidate.statusCode
: response.statusCode,
body,
cachePolicy: response.cachePolicy.toObject(),
};
let ttl = options_.strictTtl ? response.cachePolicy.timeToLive() : undefined;
let ttl = options_.strictTtl
? response.cachePolicy.timeToLive()
: undefined;
if (options_.maxTtl) {

@@ -133,7 +147,5 @@ ttl = ttl ? Math.min(ttl, options_.maxTtl) : options_.maxTtl;

if (this.hooks.size > 0) {
/* eslint-disable no-await-in-loop */
for (const key_ of this.hooks.keys()) {
value = await this.runHook(key_, value, response);
}
/* eslint-enable no-await-in-loop */
}

@@ -144,3 +156,3 @@ await this.cache.set(key, value, ttl);

/* c8 ignore next 2 */
ee.emit('error', new CacheError(error));
ee.emit("error", new CacheError(error));
}

@@ -156,8 +168,8 @@ })();

/* c8 ignore next 2 */
ee.emit('error', new CacheError(error));
ee.emit("error", new CacheError(error));
}
})();
}
ee.emit('response', clonedResponse ?? response);
if (typeof callback === 'function') {
ee.emit("response", clonedResponse ?? response);
if (typeof callback === "function") {
callback(clonedResponse ?? response);

@@ -168,10 +180,9 @@ }

const request_ = this.cacheRequest(options_, handler);
request_.once('error', requestErrorCallback);
// eslint-disable-next-line @typescript-eslint/no-deprecated
request_.once('abort', requestErrorCallback);
request_.once('destroy', requestErrorCallback);
ee.emit('request', request_);
request_.once("error", requestErrorCallback);
request_.once("abort", requestErrorCallback);
request_.once("destroy", requestErrorCallback);
ee.emit("request", request_);
}
catch (error) {
ee.emit('error', new RequestError(error));
ee.emit("error", new RequestError(error));
}

@@ -182,3 +193,5 @@ };

await Promise.resolve();
const cacheEntry = options_.cache ? await this.cache.get(key) : undefined;
const cacheEntry = options_.cache
? await this.cache.get(key)
: undefined;
if (cacheEntry === undefined && !options_.forceRefresh) {

@@ -189,6 +202,6 @@ makeRequest(options_);

const policy = CachePolicy.fromObject(cacheEntry.cachePolicy);
if (policy.satisfiesWithoutRevalidation(options_) && !options_.forceRefresh) {
if (policy.satisfiesWithoutRevalidation(options_) &&
!options_.forceRefresh) {
const headers = convertHeaders(policy.responseHeaders());
const bodyBuffer = cacheEntry.body;
// eslint-disable-next-line n/prefer-global/buffer
const body = Buffer.from(bodyBuffer);

@@ -203,8 +216,10 @@ const response = new Response({

response.fromCache = true;
ee.emit('response', response);
if (typeof callback === 'function') {
ee.emit("response", response);
if (typeof callback === "function") {
callback(response);
}
}
else if (policy.satisfiesWithoutRevalidation(options_) && Date.now() >= policy.timeToLive() && options_.forceRefresh) {
else if (policy.satisfiesWithoutRevalidation(options_) &&
Date.now() >= policy.timeToLive() &&
options_.forceRefresh) {
await this.cache.delete(key);

@@ -220,11 +235,11 @@ options_.headers = policy.revalidationHeaders(options_);

};
const errorHandler = (error) => ee.emit('error', new CacheError(error));
const errorHandler = (error) => ee.emit("error", new CacheError(error));
if (this.cache instanceof Keyv) {
const cachek = this.cache;
cachek.once('error', errorHandler);
ee.on('error', () => {
cachek.removeListener('error', errorHandler);
cachek.once("error", errorHandler);
ee.on("error", () => {
cachek.removeListener("error", errorHandler);
});
ee.on('response', () => {
cachek.removeListener('error', errorHandler);
ee.on("response", () => {
cachek.removeListener("error", errorHandler);
});

@@ -240,3 +255,3 @@ }

}
ee.emit('error', new CacheError(error));
ee.emit("error", new CacheError(error));
}

@@ -261,3 +276,3 @@ })();

store: cacheAdapter,
namespace: 'cacheable-request',
namespace: "cacheable-request",
});

@@ -278,3 +293,3 @@ }

const options = { ...url };
options.path = `${url.pathname || '/'}${url.search || ''}`;
options.path = `${url.pathname || "/"}${url.search || ""}`;
delete options.pathname;

@@ -295,3 +310,3 @@ delete options.search;

auth: url.auth,
hostname: url.hostname || url.host || 'localhost',
hostname: url.hostname || url.host || "localhost",
port: url.port,

@@ -315,5 +330,3 @@ pathname: url.pathname,

/* c8 ignore next 3 */
auth: u.username || u.password
? `${u.username}:${u.password}`
: undefined,
auth: u.username || u.password ? `${u.username}:${u.password}` : undefined,
host: u.host, // E.g. 'example.com:8080'

@@ -331,4 +344,4 @@ port: u.port, // E.g. '8080'

export default CacheableRequest;
export * from './types.js';
export const onResponse = 'onResponse';
export * from "./types.js";
export const onResponse = "onResponse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AQ,EAAE,cAAc;QACpC,IAAI,EAAE,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,MAAM,EAAE,iBAAiB;QAC9C,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"]}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[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AC,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":["// 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"]}

@@ -1,7 +0,7 @@

import { request, RequestOptions, ClientRequest, ServerResponse } from 'node:http';
import { URL } from 'node:url';
import { EventEmitter } from 'node:events';
import { Buffer } from 'node:buffer';
import ResponseLike from 'responselike';
import { CachePolicyObject } from 'http-cache-semantics';
import type { Buffer } from "node:buffer";
import type { EventEmitter } from "node:events";
import type { ClientRequest, RequestOptions, request, ServerResponse } from "node:http";
import type { URL } from "node:url";
import type { CachePolicyObject } from "http-cache-semantics";
import type ResponseLike from "responselike";
export type RequestFn = typeof request;

@@ -11,33 +11,33 @@ export type RequestFunction = typeof request;

export type CacheableRequestFunction = (options: CacheableOptions, callback?: (response: CacheResponse) => void) => Emitter;
export type CacheableOptions = Options & RequestOptions | string | URL;
export type CacheableOptions = (Options & RequestOptions) | string | URL;
export interface Options {
/**
* If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.
* @default true
*/
* If the cache should be used. Setting this to `false` will completely bypass the cache for the current request.
* @default true
*/
cache?: boolean | undefined;
/**
* If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
*
* If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated
* on the next request with `If-None-Match`/`If-Modified-Since` headers.
* @default false
*/
* If set to `true` once a cached resource has expired it is deleted and will have to be re-requested.
*
* If set to `false`, after a cached resource's TTL expires it is kept in the cache and will be revalidated
* on the next request with `If-None-Match`/`If-Modified-Since` headers.
* @default false
*/
strictTtl?: boolean | undefined;
/**
* Limits TTL. The `number` represents milliseconds.
* @default undefined
*/
* Limits TTL. The `number` represents milliseconds.
* @default undefined
*/
maxTtl?: number | undefined;
/**
* When set to `true`, if the DB connection fails we will automatically fallback to a network request.
* DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
* @default false
*/
* When set to `true`, if the DB connection fails we will automatically fallback to a network request.
* DB errors will still be emitted to notify you of the problem even though the request callback may succeed.
* @default false
*/
automaticFailover?: boolean | undefined;
/**
* Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a
* new request and override the cache instead.
* @default false
*/
* Forces refreshing the cache. If the response could be retrieved from the cache, it will perform a
* new request and override the cache instead.
* @default false
*/
forceRefresh?: boolean | undefined;

@@ -56,35 +56,35 @@ remoteAddress?: boolean | undefined;

export interface Emitter extends EventEmitter {
addListener(event: 'request', listener: (request: ClientRequest) => void): this;
addListener(event: 'response', listener: (response: CacheResponse) => void): this;
addListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
on(event: 'request', listener: (request: ClientRequest) => void): this;
on(event: 'response', listener: (response: CacheResponse) => void): this;
on(event: 'error', listener: (error: RequestError | CacheError) => void): this;
once(event: 'request', listener: (request: ClientRequest) => void): this;
once(event: 'response', listener: (response: CacheResponse) => void): this;
once(event: 'error', listener: (error: RequestError | CacheError) => void): this;
prependListener(event: 'request', listener: (request: ClientRequest) => void): this;
prependListener(event: 'response', listener: (response: CacheResponse) => void): this;
prependListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
prependOnceListener(event: 'request', listener: (request: ClientRequest) => void): this;
prependOnceListener(event: 'response', listener: (response: CacheResponse) => void): this;
prependOnceListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
removeListener(event: 'request', listener: (request: ClientRequest) => void): this;
removeListener(event: 'response', listener: (response: CacheResponse) => void): this;
removeListener(event: 'error', listener: (error: RequestError | CacheError) => void): this;
off(event: 'request', listener: (request: ClientRequest) => void): this;
off(event: 'response', listener: (response: CacheResponse) => void): this;
off(event: 'error', listener: (error: RequestError | CacheError) => void): this;
removeAllListeners(event?: 'request' | 'response' | 'error'): this;
listeners(event: 'request'): Array<(request: ClientRequest) => void>;
listeners(event: 'response'): Array<(response: CacheResponse) => void>;
listeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;
rawListeners(event: 'request'): Array<(request: ClientRequest) => void>;
rawListeners(event: 'response'): Array<(response: CacheResponse) => void>;
rawListeners(event: 'error'): Array<(error: RequestError | CacheError) => void>;
emit(event: 'request', request: ClientRequest): boolean;
emit(event: 'response', response: CacheResponse): boolean;
emit(event: 'error', error: RequestError | CacheError): boolean;
eventNames(): Array<'request' | 'response' | 'error'>;
listenerCount(type: 'request' | 'response' | 'error'): number;
addListener(event: "request", listener: (request: ClientRequest) => void): this;
addListener(event: "response", listener: (response: CacheResponse) => void): this;
addListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
on(event: "request", listener: (request: ClientRequest) => void): this;
on(event: "response", listener: (response: CacheResponse) => void): this;
on(event: "error", listener: (error: RequestError | CacheError) => void): this;
once(event: "request", listener: (request: ClientRequest) => void): this;
once(event: "response", listener: (response: CacheResponse) => void): this;
once(event: "error", listener: (error: RequestError | CacheError) => void): this;
prependListener(event: "request", listener: (request: ClientRequest) => void): this;
prependListener(event: "response", listener: (response: CacheResponse) => void): this;
prependListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
prependOnceListener(event: "request", listener: (request: ClientRequest) => void): this;
prependOnceListener(event: "response", listener: (response: CacheResponse) => void): this;
prependOnceListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
removeListener(event: "request", listener: (request: ClientRequest) => void): this;
removeListener(event: "response", listener: (response: CacheResponse) => void): this;
removeListener(event: "error", listener: (error: RequestError | CacheError) => void): this;
off(event: "request", listener: (request: ClientRequest) => void): this;
off(event: "response", listener: (response: CacheResponse) => void): this;
off(event: "error", listener: (error: RequestError | CacheError) => void): this;
removeAllListeners(event?: "request" | "response" | "error"): this;
listeners(event: "request"): Array<(request: ClientRequest) => void>;
listeners(event: "response"): Array<(response: CacheResponse) => void>;
listeners(event: "error"): Array<(error: RequestError | CacheError) => void>;
rawListeners(event: "request"): Array<(request: ClientRequest) => void>;
rawListeners(event: "response"): Array<(response: CacheResponse) => void>;
rawListeners(event: "error"): Array<(error: RequestError | CacheError) => void>;
emit(event: "request", request: ClientRequest): boolean;
emit(event: "response", response: CacheResponse): boolean;
emit(event: "error", error: RequestError | CacheError): boolean;
eventNames(): Array<"request" | "response" | "error">;
listenerCount(type: "request" | "response" | "error"): number;
}

@@ -91,0 +91,0 @@ export declare class RequestError extends Error {

@@ -1,1 +0,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,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,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"]}
{"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"]}
{
"name": "cacheable-request",
"version": "13.0.9",
"version": "13.0.10",
"description": "Wrap native HTTP requests with RFC compliant cache support",

@@ -41,3 +41,3 @@ "license": "MIT",

"http-cache-semantics": "^4.2.0",
"keyv": "^5.5.0",
"keyv": "^5.5.1",
"mimic-response": "^4.0.0",

@@ -48,5 +48,6 @@ "normalize-url": "^8.0.2",

"devDependencies": {
"@biomejs/biome": "^2.2.3",
"@keyv/sqlite": "^4.0.5",
"@types/express": "^5.0.3",
"@types/node": "^24.2.0",
"@types/node": "^24.3.1",
"@types/responselike": "^1.0.3",

@@ -62,33 +63,8 @@ "@vitest/coverage-v8": "^3.2.4",

"typescript": "^5.9.2",
"vitest": "^3.2.4",
"xo": "^1.2.1"
"vitest": "^3.2.4"
},
"xo": {
"rules": {
"@typescript-eslint/triple-slash-reference": 0,
"@typescript-eslint/no-namespace": 0,
"@typescript-eslint/no-unsafe-assignment": 0,
"@typescript-eslint/no-unsafe-call": 0,
"@typescript-eslint/ban-types": 0,
"@typescript-eslint/restrict-template-expressions": 0,
"@typescript-eslint/no-unsafe-return": 0,
"@typescript-eslint/no-unsafe-argument": 0,
"new-cap": 0,
"unicorn/no-abusive-eslint-disable": 0,
"@typescript-eslint/restrict-plus-operands": 0,
"@typescript-eslint/no-implicit-any-catch": 0,
"@typescript-eslint/consistent-type-imports": 0,
"@typescript-eslint/consistent-type-definitions": 0,
"@typescript-eslint/prefer-nullish-coalescing": 0,
"n/prefer-global/url": 0,
"n/no-deprecated-api": 0,
"unicorn/prefer-event-target": 0,
"@typescript-eslint/no-unnecessary-type-assertion": 0,
"promise/prefer-await-to-then": 0,
"@typescript-eslint/no-unnecessary-boolean-literal-compare": 0
}
},
"scripts": {
"test": "xo --fix && vitest run --coverage",
"test:ci": "xo && vitest run --coverage",
"lint": "biome check --write --error-on-warnings",
"test": "pnpm lint && vitest run --coverage",
"test:ci": "biome check --error-on-warnings && vitest run --coverage",
"prepublish": "pnpm run build",

@@ -95,0 +71,0 @@ "build": "rimraf ./dist && tsc --project tsconfig.build.json",