@cacheable/net 2.0.0 → 2.0.2
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 +17 -12
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +17 -12
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -491,9 +491,7 @@ var CacheableNet = class extends import_hookified.Hookified {
|
|
|
491
491
|
} else {
|
|
492
492
|
const stringifyFn = options?.stringify || this._stringify;
|
|
493
493
|
body = stringifyFn(data);
|
|
494
|
-
|
|
495
|
-
headers["Content-Type"] = "application/json";
|
|
496
|
-
}
|
|
494
|
+
this.setContentType(headers);
|
|
497
495
|
}
|
|
498
496
|
const fetchOptions = {
|
|
499
497
|
...options,
|
|
@@ -562,9 +560,7 @@ var CacheableNet = class extends import_hookified.Hookified {
|
|
|
562
560
|
} else {
|
|
563
561
|
const stringifyFn = options?.stringify || this._stringify;
|
|
564
562
|
body = stringifyFn(data);
|
|
565
|
-
|
|
566
|
-
headers["Content-Type"] = "application/json";
|
|
567
|
-
}
|
|
563
|
+
this.setContentType(headers);
|
|
568
564
|
}
|
|
569
565
|
const fetchOptions = {
|
|
570
566
|
...options,
|
|
@@ -613,9 +609,7 @@ var CacheableNet = class extends import_hookified.Hookified {
|
|
|
613
609
|
} else {
|
|
614
610
|
const stringifyFn = options?.stringify || this._stringify;
|
|
615
611
|
body = stringifyFn(data);
|
|
616
|
-
|
|
617
|
-
headers["Content-Type"] = "application/json";
|
|
618
|
-
}
|
|
612
|
+
this.setContentType(headers);
|
|
619
613
|
}
|
|
620
614
|
const fetchOptions = {
|
|
621
615
|
...options,
|
|
@@ -665,9 +659,7 @@ var CacheableNet = class extends import_hookified.Hookified {
|
|
|
665
659
|
} else {
|
|
666
660
|
const stringifyFn = options?.stringify || this._stringify;
|
|
667
661
|
body = stringifyFn(data);
|
|
668
|
-
|
|
669
|
-
headers["Content-Type"] = "application/json";
|
|
670
|
-
}
|
|
662
|
+
this.setContentType(headers);
|
|
671
663
|
}
|
|
672
664
|
}
|
|
673
665
|
const fetchOptions = {
|
|
@@ -699,6 +691,18 @@ var CacheableNet = class extends import_hookified.Hookified {
|
|
|
699
691
|
response: newResponse
|
|
700
692
|
};
|
|
701
693
|
}
|
|
694
|
+
/**
|
|
695
|
+
* Sets the Content-Type header if not already set.
|
|
696
|
+
* Checks both "Content-Type" and "content-type" to handle case variations.
|
|
697
|
+
* @param headers - The headers object to modify
|
|
698
|
+
* @param contentType - The content type to set (defaults to "application/json")
|
|
699
|
+
* @private
|
|
700
|
+
*/
|
|
701
|
+
setContentType(headers, contentType = "application/json") {
|
|
702
|
+
if (!headers["Content-Type"] && !headers["content-type"]) {
|
|
703
|
+
headers["Content-Type"] = contentType;
|
|
704
|
+
}
|
|
705
|
+
}
|
|
702
706
|
};
|
|
703
707
|
var Net = CacheableNet;
|
|
704
708
|
// Annotate the CommonJS export names for ESM import in node:
|
|
@@ -712,3 +716,4 @@ var Net = CacheableNet;
|
|
|
712
716
|
patch,
|
|
713
717
|
post
|
|
714
718
|
});
|
|
719
|
+
/* v8 ignore next -- @preserve */
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cacheable, CacheableOptions } from 'cacheable';
|
|
2
2
|
import { HookifiedOptions, Hookified } from 'hookified';
|
|
3
3
|
import { RequestInit, Response as Response$1 } from 'undici';
|
|
4
|
+
export { RequestInit as FetchRequestInit } from 'undici';
|
|
4
5
|
|
|
5
6
|
type FetchOptions = Omit<RequestInit, "cache"> & {
|
|
6
7
|
cache?: Cacheable;
|
|
@@ -289,6 +290,14 @@ declare class CacheableNet extends Hookified {
|
|
|
289
290
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
290
291
|
*/
|
|
291
292
|
delete<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
293
|
+
/**
|
|
294
|
+
* Sets the Content-Type header if not already set.
|
|
295
|
+
* Checks both "Content-Type" and "content-type" to handle case variations.
|
|
296
|
+
* @param headers - The headers object to modify
|
|
297
|
+
* @param contentType - The content type to set (defaults to "application/json")
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
private setContentType;
|
|
292
301
|
}
|
|
293
302
|
declare const Net: typeof CacheableNet;
|
|
294
303
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Cacheable, CacheableOptions } from 'cacheable';
|
|
2
2
|
import { HookifiedOptions, Hookified } from 'hookified';
|
|
3
3
|
import { RequestInit, Response as Response$1 } from 'undici';
|
|
4
|
+
export { RequestInit as FetchRequestInit } from 'undici';
|
|
4
5
|
|
|
5
6
|
type FetchOptions = Omit<RequestInit, "cache"> & {
|
|
6
7
|
cache?: Cacheable;
|
|
@@ -289,6 +290,14 @@ declare class CacheableNet extends Hookified {
|
|
|
289
290
|
* @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
|
|
290
291
|
*/
|
|
291
292
|
delete<T = unknown>(url: string, data?: unknown, options?: Omit<NetFetchOptions, "method" | "body">): Promise<DataResponse<T>>;
|
|
293
|
+
/**
|
|
294
|
+
* Sets the Content-Type header if not already set.
|
|
295
|
+
* Checks both "Content-Type" and "content-type" to handle case variations.
|
|
296
|
+
* @param headers - The headers object to modify
|
|
297
|
+
* @param contentType - The content type to set (defaults to "application/json")
|
|
298
|
+
* @private
|
|
299
|
+
*/
|
|
300
|
+
private setContentType;
|
|
292
301
|
}
|
|
293
302
|
declare const Net: typeof CacheableNet;
|
|
294
303
|
|
package/dist/index.js
CHANGED
|
@@ -452,9 +452,7 @@ var CacheableNet = class extends Hookified {
|
|
|
452
452
|
} else {
|
|
453
453
|
const stringifyFn = options?.stringify || this._stringify;
|
|
454
454
|
body = stringifyFn(data);
|
|
455
|
-
|
|
456
|
-
headers["Content-Type"] = "application/json";
|
|
457
|
-
}
|
|
455
|
+
this.setContentType(headers);
|
|
458
456
|
}
|
|
459
457
|
const fetchOptions = {
|
|
460
458
|
...options,
|
|
@@ -523,9 +521,7 @@ var CacheableNet = class extends Hookified {
|
|
|
523
521
|
} else {
|
|
524
522
|
const stringifyFn = options?.stringify || this._stringify;
|
|
525
523
|
body = stringifyFn(data);
|
|
526
|
-
|
|
527
|
-
headers["Content-Type"] = "application/json";
|
|
528
|
-
}
|
|
524
|
+
this.setContentType(headers);
|
|
529
525
|
}
|
|
530
526
|
const fetchOptions = {
|
|
531
527
|
...options,
|
|
@@ -574,9 +570,7 @@ var CacheableNet = class extends Hookified {
|
|
|
574
570
|
} else {
|
|
575
571
|
const stringifyFn = options?.stringify || this._stringify;
|
|
576
572
|
body = stringifyFn(data);
|
|
577
|
-
|
|
578
|
-
headers["Content-Type"] = "application/json";
|
|
579
|
-
}
|
|
573
|
+
this.setContentType(headers);
|
|
580
574
|
}
|
|
581
575
|
const fetchOptions = {
|
|
582
576
|
...options,
|
|
@@ -626,9 +620,7 @@ var CacheableNet = class extends Hookified {
|
|
|
626
620
|
} else {
|
|
627
621
|
const stringifyFn = options?.stringify || this._stringify;
|
|
628
622
|
body = stringifyFn(data);
|
|
629
|
-
|
|
630
|
-
headers["Content-Type"] = "application/json";
|
|
631
|
-
}
|
|
623
|
+
this.setContentType(headers);
|
|
632
624
|
}
|
|
633
625
|
}
|
|
634
626
|
const fetchOptions = {
|
|
@@ -660,6 +652,18 @@ var CacheableNet = class extends Hookified {
|
|
|
660
652
|
response: newResponse
|
|
661
653
|
};
|
|
662
654
|
}
|
|
655
|
+
/**
|
|
656
|
+
* Sets the Content-Type header if not already set.
|
|
657
|
+
* Checks both "Content-Type" and "content-type" to handle case variations.
|
|
658
|
+
* @param headers - The headers object to modify
|
|
659
|
+
* @param contentType - The content type to set (defaults to "application/json")
|
|
660
|
+
* @private
|
|
661
|
+
*/
|
|
662
|
+
setContentType(headers, contentType = "application/json") {
|
|
663
|
+
if (!headers["Content-Type"] && !headers["content-type"]) {
|
|
664
|
+
headers["Content-Type"] = contentType;
|
|
665
|
+
}
|
|
666
|
+
}
|
|
663
667
|
};
|
|
664
668
|
var Net = CacheableNet;
|
|
665
669
|
export {
|
|
@@ -672,3 +676,4 @@ export {
|
|
|
672
676
|
patch,
|
|
673
677
|
post
|
|
674
678
|
};
|
|
679
|
+
/* v8 ignore next -- @preserve */
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cacheable/net",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
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.cjs",
|
|
@@ -21,21 +21,21 @@
|
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"private": false,
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@biomejs/biome": "^2.
|
|
25
|
-
"@faker-js/faker": "^10.
|
|
24
|
+
"@biomejs/biome": "^2.3.1",
|
|
25
|
+
"@faker-js/faker": "^10.1.0",
|
|
26
26
|
"@types/http-cache-semantics": "^4.0.4",
|
|
27
|
-
"@types/node": "^24.
|
|
28
|
-
"@vitest/coverage-v8": "^
|
|
27
|
+
"@types/node": "^24.9.1",
|
|
28
|
+
"@vitest/coverage-v8": "^4.0.4",
|
|
29
29
|
"rimraf": "^6.0.1",
|
|
30
30
|
"tsup": "^8.5.0",
|
|
31
|
-
"typescript": "^5.9.
|
|
32
|
-
"vitest": "^
|
|
31
|
+
"typescript": "^5.9.3",
|
|
32
|
+
"vitest": "^4.0.4"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"hookified": "^1.12.
|
|
35
|
+
"hookified": "^1.12.2",
|
|
36
36
|
"http-cache-semantics": "^4.2.0",
|
|
37
37
|
"undici": "^7.16.0",
|
|
38
|
-
"cacheable": "^2.
|
|
38
|
+
"cacheable": "^2.1.1"
|
|
39
39
|
},
|
|
40
40
|
"keywords": [
|
|
41
41
|
"cacheable",
|