@cacheable/net 2.0.6 → 2.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +5 -5
- package/dist/index.js +5 -7
- package/package.json +5 -9
package/dist/index.cjs
CHANGED
|
@@ -45,21 +45,21 @@ var import_hookified = require("hookified");
|
|
|
45
45
|
|
|
46
46
|
// src/fetch.ts
|
|
47
47
|
var import_http_cache_semantics = __toESM(require("http-cache-semantics"), 1);
|
|
48
|
-
var
|
|
48
|
+
var runtimeFetch = globalThis.fetch.bind(globalThis);
|
|
49
49
|
async function fetch(url, options) {
|
|
50
50
|
const fetchOptions = {
|
|
51
51
|
...options,
|
|
52
52
|
cache: "no-cache"
|
|
53
53
|
};
|
|
54
54
|
if (!options.cache) {
|
|
55
|
-
const response2 = await (
|
|
55
|
+
const response2 = await runtimeFetch(url, fetchOptions);
|
|
56
56
|
if (!response2.ok) {
|
|
57
57
|
throw new Error(`Fetch failed with status ${response2.status}`);
|
|
58
58
|
}
|
|
59
59
|
return response2;
|
|
60
60
|
}
|
|
61
61
|
if (options.method === "POST" || options.method === "PATCH" || options.method === "DELETE" || options.method === "HEAD") {
|
|
62
|
-
const response2 = await (
|
|
62
|
+
const response2 = await runtimeFetch(url, fetchOptions);
|
|
63
63
|
if (!response2.ok) {
|
|
64
64
|
throw new Error(`Fetch failed with status ${response2.status}`);
|
|
65
65
|
}
|
|
@@ -70,7 +70,7 @@ async function fetch(url, options) {
|
|
|
70
70
|
const cacheKey = `${method}:${url}`;
|
|
71
71
|
if (!httpCachePolicy) {
|
|
72
72
|
const cachedData = await options.cache.getOrSet(cacheKey, async () => {
|
|
73
|
-
const response2 = await (
|
|
73
|
+
const response2 = await runtimeFetch(url, fetchOptions);
|
|
74
74
|
if (!response2.ok) {
|
|
75
75
|
throw new Error(`Fetch failed with status ${response2.status}`);
|
|
76
76
|
}
|
|
@@ -128,7 +128,7 @@ async function fetch(url, options) {
|
|
|
128
128
|
if (policy?.revalidationHeaders(request)) {
|
|
129
129
|
revalidationHeaders = policy.revalidationHeaders(request);
|
|
130
130
|
}
|
|
131
|
-
const response = await (
|
|
131
|
+
const response = await runtimeFetch(url, {
|
|
132
132
|
...fetchOptions,
|
|
133
133
|
headers: {
|
|
134
134
|
...fetchOptions.headers,
|
package/dist/index.js
CHANGED
|
@@ -4,23 +4,21 @@ import { Hookified } from "hookified";
|
|
|
4
4
|
|
|
5
5
|
// src/fetch.ts
|
|
6
6
|
import CachePolicy from "http-cache-semantics";
|
|
7
|
-
|
|
8
|
-
fetch as undiciFetch
|
|
9
|
-
} from "undici";
|
|
7
|
+
var runtimeFetch = globalThis.fetch.bind(globalThis);
|
|
10
8
|
async function fetch(url, options) {
|
|
11
9
|
const fetchOptions = {
|
|
12
10
|
...options,
|
|
13
11
|
cache: "no-cache"
|
|
14
12
|
};
|
|
15
13
|
if (!options.cache) {
|
|
16
|
-
const response2 = await
|
|
14
|
+
const response2 = await runtimeFetch(url, fetchOptions);
|
|
17
15
|
if (!response2.ok) {
|
|
18
16
|
throw new Error(`Fetch failed with status ${response2.status}`);
|
|
19
17
|
}
|
|
20
18
|
return response2;
|
|
21
19
|
}
|
|
22
20
|
if (options.method === "POST" || options.method === "PATCH" || options.method === "DELETE" || options.method === "HEAD") {
|
|
23
|
-
const response2 = await
|
|
21
|
+
const response2 = await runtimeFetch(url, fetchOptions);
|
|
24
22
|
if (!response2.ok) {
|
|
25
23
|
throw new Error(`Fetch failed with status ${response2.status}`);
|
|
26
24
|
}
|
|
@@ -31,7 +29,7 @@ async function fetch(url, options) {
|
|
|
31
29
|
const cacheKey = `${method}:${url}`;
|
|
32
30
|
if (!httpCachePolicy) {
|
|
33
31
|
const cachedData = await options.cache.getOrSet(cacheKey, async () => {
|
|
34
|
-
const response2 = await
|
|
32
|
+
const response2 = await runtimeFetch(url, fetchOptions);
|
|
35
33
|
if (!response2.ok) {
|
|
36
34
|
throw new Error(`Fetch failed with status ${response2.status}`);
|
|
37
35
|
}
|
|
@@ -89,7 +87,7 @@ async function fetch(url, options) {
|
|
|
89
87
|
if (policy?.revalidationHeaders(request)) {
|
|
90
88
|
revalidationHeaders = policy.revalidationHeaders(request);
|
|
91
89
|
}
|
|
92
|
-
const response = await
|
|
90
|
+
const response = await runtimeFetch(url, {
|
|
93
91
|
...fetchOptions,
|
|
94
92
|
headers: {
|
|
95
93
|
...fetchOptions.headers,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cacheable/net",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.8",
|
|
4
4
|
"description": "High Performance Network Caching for Node.js with fetch, request, http 1.1, and http 2 support",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -27,18 +27,15 @@
|
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"private": false,
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@faker-js/faker": "^10.3.0",
|
|
31
30
|
"@types/http-cache-semantics": "^4.2.0",
|
|
32
|
-
"@types/node": "^25.3.0",
|
|
33
|
-
"rimraf": "^6.1.3",
|
|
34
31
|
"tsup": "^8.5.1",
|
|
35
32
|
"typescript": "^5.9.3"
|
|
36
33
|
},
|
|
37
34
|
"dependencies": {
|
|
38
35
|
"hookified": "^1.15.1",
|
|
39
36
|
"http-cache-semantics": "^4.2.0",
|
|
40
|
-
"undici": "^7.
|
|
41
|
-
"cacheable": "^2.3.
|
|
37
|
+
"undici": "^7.24.5",
|
|
38
|
+
"cacheable": "^2.3.5"
|
|
42
39
|
},
|
|
43
40
|
"keywords": [
|
|
44
41
|
"cacheable",
|
|
@@ -73,10 +70,9 @@
|
|
|
73
70
|
],
|
|
74
71
|
"scripts": {
|
|
75
72
|
"build": "rimraf ./dist && tsup src/index.ts --format cjs,esm --dts --clean",
|
|
76
|
-
"prepublish": "pnpm build",
|
|
77
73
|
"lint": "biome check --write --error-on-warnings",
|
|
78
|
-
"test": "pnpm lint && TEST_URL=http://localhost:
|
|
79
|
-
"test:ci": "biome check --error-on-warnings && TEST_URL=http://localhost:
|
|
74
|
+
"test": "pnpm lint && TEST_URL=http://localhost:3737 vitest run --coverage",
|
|
75
|
+
"test:ci": "biome check --error-on-warnings && TEST_URL=http://localhost:3737 vitest run --coverage",
|
|
80
76
|
"clean": "rimraf ./dist ./coverage ./node_modules"
|
|
81
77
|
}
|
|
82
78
|
}
|