@cacheable/net 1.0.2 → 2.0.1

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 CHANGED
@@ -1,570 +1 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.ts
31
- var index_exports = {};
32
- __export(index_exports, {
33
- CacheableNet: () => CacheableNet,
34
- Net: () => Net,
35
- del: () => del,
36
- fetch: () => fetch,
37
- get: () => get,
38
- head: () => head,
39
- patch: () => patch,
40
- post: () => post
41
- });
42
- module.exports = __toCommonJS(index_exports);
43
- var import_cacheable = require("cacheable");
44
- var import_hookified = require("hookified");
45
-
46
- // src/fetch.ts
47
- var import_http_cache_semantics = __toESM(require("http-cache-semantics"), 1);
48
- var import_undici = require("undici");
49
- async function fetch(url, options) {
50
- if (!options.cache) {
51
- throw new Error("Fetch options must include a cache instance or options.");
52
- }
53
- const fetchOptions = {
54
- ...options,
55
- cache: "no-cache"
56
- };
57
- if (options.method === "POST" || options.method === "PATCH" || options.method === "DELETE" || options.method === "HEAD") {
58
- const response2 = await (0, import_undici.fetch)(url, fetchOptions);
59
- if (!response2.ok) {
60
- throw new Error(`Fetch failed with status ${response2.status}`);
61
- }
62
- return response2;
63
- }
64
- const useHttpCache = options.useHttpCache !== false;
65
- const method = options.method || "GET";
66
- const cacheKey = `${method}:${url}`;
67
- if (!useHttpCache) {
68
- const cachedData = await options.cache.getOrSet(cacheKey, async () => {
69
- const response2 = await (0, import_undici.fetch)(url, fetchOptions);
70
- if (!response2.ok) {
71
- throw new Error(`Fetch failed with status ${response2.status}`);
72
- }
73
- const body2 = await response2.text();
74
- return {
75
- body: body2,
76
- status: response2.status,
77
- statusText: response2.statusText,
78
- headers: Object.fromEntries(response2.headers.entries())
79
- };
80
- });
81
- if (!cachedData) {
82
- throw new Error("Failed to get or set cache data");
83
- }
84
- return new Response(cachedData.body, {
85
- status: cachedData.status,
86
- statusText: cachedData.statusText,
87
- headers: cachedData.headers
88
- });
89
- }
90
- const policyKey = `${cacheKey}:policy`;
91
- const [cachedResponse, cachedPolicyData] = await Promise.all([
92
- options.cache.get(cacheKey),
93
- options.cache.get(policyKey)
94
- ]);
95
- let policy;
96
- let cachedBody;
97
- let cachedStatus;
98
- let cachedStatusText;
99
- let cachedHeaders;
100
- if (cachedPolicyData && cachedResponse) {
101
- policy = import_http_cache_semantics.default.fromObject(
102
- cachedPolicyData
103
- );
104
- cachedBody = cachedResponse.body;
105
- cachedStatus = cachedResponse.status;
106
- cachedStatusText = cachedResponse.statusText;
107
- cachedHeaders = cachedResponse.headers;
108
- }
109
- const requestHeaders = fetchOptions.headers || {};
110
- const request = {
111
- url,
112
- method,
113
- headers: requestHeaders
114
- };
115
- if (policy?.satisfiesWithoutRevalidation(request)) {
116
- const headers = policy.responseHeaders();
117
- return new Response(cachedBody, {
118
- status: cachedStatus,
119
- statusText: cachedStatusText,
120
- headers
121
- });
122
- }
123
- let revalidationHeaders = {};
124
- if (policy?.revalidationHeaders(request)) {
125
- revalidationHeaders = policy.revalidationHeaders(request);
126
- }
127
- const response = await (0, import_undici.fetch)(url, {
128
- ...fetchOptions,
129
- headers: {
130
- ...fetchOptions.headers,
131
- ...revalidationHeaders
132
- }
133
- });
134
- if (response.status === 304 && policy) {
135
- const { policy: updatedPolicy, modified } = policy.revalidatedPolicy(
136
- request,
137
- {
138
- status: response.status,
139
- headers: Object.fromEntries(response.headers.entries())
140
- }
141
- );
142
- if (!modified) {
143
- const ttl = updatedPolicy.timeToLive();
144
- await options.cache.set(policyKey, updatedPolicy.toObject(), ttl);
145
- await options.cache.set(
146
- cacheKey,
147
- {
148
- body: cachedBody,
149
- status: cachedStatus,
150
- statusText: cachedStatusText,
151
- headers: cachedHeaders
152
- },
153
- ttl
154
- );
155
- const headers = updatedPolicy.responseHeaders();
156
- return new Response(cachedBody, {
157
- status: cachedStatus,
158
- statusText: cachedStatusText,
159
- headers
160
- });
161
- }
162
- }
163
- if (!response.ok && response.status !== 304) {
164
- throw new Error(`Fetch failed with status ${response.status}`);
165
- }
166
- const body = await response.text();
167
- const responseForPolicy = {
168
- status: response.status,
169
- statusText: response.statusText,
170
- headers: Object.fromEntries(response.headers.entries())
171
- };
172
- const newPolicy = new import_http_cache_semantics.default(request, responseForPolicy);
173
- if (newPolicy.storable()) {
174
- const ttl = newPolicy.timeToLive();
175
- await Promise.all([
176
- options.cache.set(
177
- cacheKey,
178
- {
179
- body,
180
- status: response.status,
181
- statusText: response.statusText,
182
- headers: responseForPolicy.headers
183
- },
184
- ttl
185
- ),
186
- options.cache.set(policyKey, newPolicy.toObject(), ttl)
187
- ]);
188
- }
189
- return new Response(body, {
190
- status: response.status,
191
- statusText: response.statusText,
192
- headers: response.headers
193
- });
194
- }
195
- async function get(url, options) {
196
- const response = await fetch(url, { ...options, method: "GET" });
197
- const text = await response.text();
198
- let data;
199
- try {
200
- data = JSON.parse(text);
201
- } catch {
202
- data = text;
203
- }
204
- const newResponse = new Response(text, {
205
- status: response.status,
206
- statusText: response.statusText,
207
- headers: response.headers
208
- });
209
- return {
210
- data,
211
- response: newResponse
212
- };
213
- }
214
- async function post(url, data, options) {
215
- let body;
216
- const headers = { ...options.headers };
217
- if (typeof data === "string") {
218
- body = data;
219
- } else if (data instanceof FormData || data instanceof URLSearchParams || data instanceof Blob) {
220
- body = data;
221
- } else {
222
- body = JSON.stringify(data);
223
- if (!headers["Content-Type"] && !headers["content-type"]) {
224
- headers["Content-Type"] = "application/json";
225
- }
226
- }
227
- const response = await fetch(url, {
228
- ...options,
229
- headers,
230
- body,
231
- method: "POST"
232
- });
233
- const text = await response.text();
234
- let responseData;
235
- try {
236
- responseData = JSON.parse(text);
237
- } catch {
238
- responseData = text;
239
- }
240
- const newResponse = new Response(text, {
241
- status: response.status,
242
- statusText: response.statusText,
243
- headers: response.headers
244
- });
245
- return {
246
- data: responseData,
247
- response: newResponse
248
- };
249
- }
250
- async function patch(url, data, options) {
251
- let body;
252
- const headers = { ...options.headers };
253
- if (typeof data === "string") {
254
- body = data;
255
- } else if (data instanceof FormData || data instanceof URLSearchParams || data instanceof Blob) {
256
- body = data;
257
- } else {
258
- body = JSON.stringify(data);
259
- if (!headers["Content-Type"] && !headers["content-type"]) {
260
- headers["Content-Type"] = "application/json";
261
- }
262
- }
263
- const response = await fetch(url, {
264
- ...options,
265
- headers,
266
- body,
267
- method: "PATCH"
268
- });
269
- const text = await response.text();
270
- let responseData;
271
- try {
272
- responseData = JSON.parse(text);
273
- } catch {
274
- responseData = text;
275
- }
276
- const newResponse = new Response(text, {
277
- status: response.status,
278
- statusText: response.statusText,
279
- headers: response.headers
280
- });
281
- return {
282
- data: responseData,
283
- response: newResponse
284
- };
285
- }
286
- async function del(url, data, options) {
287
- let actualData;
288
- let actualOptions;
289
- if (data !== void 0 && typeof data === "object" && data !== null && "cache" in data) {
290
- actualData = void 0;
291
- actualOptions = data;
292
- } else if (options) {
293
- actualData = data;
294
- actualOptions = options;
295
- } else {
296
- throw new Error("Fetch options must include a cache instance or options.");
297
- }
298
- let body;
299
- const headers = { ...actualOptions.headers };
300
- if (actualData !== void 0) {
301
- if (typeof actualData === "string") {
302
- body = actualData;
303
- } else if (actualData instanceof FormData || actualData instanceof URLSearchParams || actualData instanceof Blob) {
304
- body = actualData;
305
- } else {
306
- body = JSON.stringify(actualData);
307
- if (!headers["Content-Type"] && !headers["content-type"]) {
308
- headers["Content-Type"] = "application/json";
309
- }
310
- }
311
- }
312
- const response = await fetch(url, {
313
- ...actualOptions,
314
- headers,
315
- body,
316
- method: "DELETE"
317
- });
318
- const text = await response.text();
319
- let responseData;
320
- try {
321
- responseData = JSON.parse(text);
322
- } catch {
323
- responseData = text;
324
- }
325
- const newResponse = new Response(text, {
326
- status: response.status,
327
- statusText: response.statusText,
328
- headers: response.headers
329
- });
330
- return {
331
- data: responseData,
332
- response: newResponse
333
- };
334
- }
335
- async function head(url, options) {
336
- const response = await fetch(url, { ...options, method: "HEAD" });
337
- return response;
338
- }
339
-
340
- // src/index.ts
341
- var CacheableNet = class extends import_hookified.Hookified {
342
- _cache = new import_cacheable.Cacheable();
343
- _useHttpCache = true;
344
- constructor(options) {
345
- super(options);
346
- if (options?.cache) {
347
- this._cache = options.cache instanceof import_cacheable.Cacheable ? options.cache : new import_cacheable.Cacheable(options.cache);
348
- }
349
- if (options?.useHttpCache !== void 0) {
350
- this._useHttpCache = options.useHttpCache;
351
- }
352
- }
353
- get cache() {
354
- return this._cache;
355
- }
356
- set cache(value) {
357
- this._cache = value;
358
- }
359
- /**
360
- * Get the current HTTP cache setting.
361
- * @returns {boolean} Whether HTTP cache semantics are enabled
362
- */
363
- get useHttpCache() {
364
- return this._useHttpCache;
365
- }
366
- /**
367
- * Set whether to use HTTP cache semantics.
368
- * @param {boolean} value - Enable or disable HTTP cache semantics
369
- */
370
- set useHttpCache(value) {
371
- this._useHttpCache = value;
372
- }
373
- /**
374
- * Fetch data from a URL with optional request options. Will use the cache that is already set in the instance.
375
- *
376
- * When `useHttpCache` is enabled (default), cache entries will have their TTL
377
- * set based on HTTP cache headers (e.g., Cache-Control: max-age). When disabled,
378
- * the default TTL from the Cacheable instance is used.
379
- *
380
- * @param {string} url The URL to fetch.
381
- * @param {FetchRequestInit} options Optional request options.
382
- * @returns {Promise<FetchResponse>} The response from the fetch.
383
- */
384
- async fetch(url, options) {
385
- const fetchOptions = {
386
- ...options,
387
- cache: this._cache,
388
- useHttpCache: this._useHttpCache
389
- };
390
- return fetch(url, fetchOptions);
391
- }
392
- /**
393
- * Perform a GET request to a URL with optional request options. Will use the cache that is already set in the instance.
394
- * @param {string} url The URL to fetch.
395
- * @param {Omit<FetchRequestInit, 'method'>} options Optional request options (method will be set to GET).
396
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
397
- */
398
- async get(url, options) {
399
- const response = await this.fetch(url, { ...options, method: "GET" });
400
- const text = await response.text();
401
- let data;
402
- try {
403
- data = JSON.parse(text);
404
- } catch {
405
- data = text;
406
- }
407
- const newResponse = new Response(text, {
408
- status: response.status,
409
- statusText: response.statusText,
410
- headers: response.headers
411
- });
412
- return {
413
- data,
414
- response: newResponse
415
- };
416
- }
417
- /**
418
- * Perform a POST request to a URL with data and optional request options. Will use the cache that is already set in the instance.
419
- * @param {string} url The URL to fetch.
420
- * @param {unknown} data The data to send in the request body.
421
- * @param {Omit<FetchRequestInit, 'method' | 'body'>} options Optional request options (method and body will be set).
422
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
423
- */
424
- async post(url, data, options) {
425
- let body;
426
- const headers = { ...options?.headers };
427
- if (typeof data === "string") {
428
- body = data;
429
- } else if (data instanceof FormData || data instanceof URLSearchParams || data instanceof Blob) {
430
- body = data;
431
- } else {
432
- body = JSON.stringify(data);
433
- if (!headers["Content-Type"] && !headers["content-type"]) {
434
- headers["Content-Type"] = "application/json";
435
- }
436
- }
437
- const response = await this.fetch(url, {
438
- ...options,
439
- headers,
440
- body,
441
- method: "POST"
442
- });
443
- const text = await response.text();
444
- let responseData;
445
- try {
446
- responseData = JSON.parse(text);
447
- } catch {
448
- responseData = text;
449
- }
450
- const newResponse = new Response(text, {
451
- status: response.status,
452
- statusText: response.statusText,
453
- headers: response.headers
454
- });
455
- return {
456
- data: responseData,
457
- response: newResponse
458
- };
459
- }
460
- /**
461
- * Perform a HEAD request to a URL with optional request options. Will use the cache that is already set in the instance.
462
- * @param {string} url The URL to fetch.
463
- * @param {Omit<FetchRequestInit, 'method'>} options Optional request options (method will be set to HEAD).
464
- * @returns {Promise<FetchResponse>} The response from the fetch (no body).
465
- */
466
- async head(url, options) {
467
- const response = await this.fetch(url, { ...options, method: "HEAD" });
468
- return response;
469
- }
470
- /**
471
- * Perform a PATCH request to a URL with data and optional request options. Will use the cache that is already set in the instance.
472
- * @param {string} url The URL to fetch.
473
- * @param {unknown} data The data to send in the request body.
474
- * @param {Omit<FetchRequestInit, 'method' | 'body'>} options Optional request options (method and body will be set).
475
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
476
- */
477
- async patch(url, data, options) {
478
- let body;
479
- const headers = { ...options?.headers };
480
- if (typeof data === "string") {
481
- body = data;
482
- } else if (data instanceof FormData || data instanceof URLSearchParams || data instanceof Blob) {
483
- body = data;
484
- } else {
485
- body = JSON.stringify(data);
486
- if (!headers["Content-Type"] && !headers["content-type"]) {
487
- headers["Content-Type"] = "application/json";
488
- }
489
- }
490
- const response = await this.fetch(url, {
491
- ...options,
492
- headers,
493
- body,
494
- method: "PATCH"
495
- });
496
- const text = await response.text();
497
- let responseData;
498
- try {
499
- responseData = JSON.parse(text);
500
- } catch {
501
- responseData = text;
502
- }
503
- const newResponse = new Response(text, {
504
- status: response.status,
505
- statusText: response.statusText,
506
- headers: response.headers
507
- });
508
- return {
509
- data: responseData,
510
- response: newResponse
511
- };
512
- }
513
- /**
514
- * Perform a DELETE request to a URL with optional data and request options. Will use the cache that is already set in the instance.
515
- * @param {string} url The URL to fetch.
516
- * @param {unknown} data Optional data to send in the request body.
517
- * @param {Omit<FetchRequestInit, 'method' | 'body'>} options Optional request options (method and body will be set).
518
- * @returns {Promise<DataResponse<T>>} The typed data and response from the fetch.
519
- */
520
- async delete(url, data, options) {
521
- let body;
522
- const headers = { ...options?.headers };
523
- if (data !== void 0) {
524
- if (typeof data === "string") {
525
- body = data;
526
- } else if (data instanceof FormData || data instanceof URLSearchParams || data instanceof Blob) {
527
- body = data;
528
- } else {
529
- body = JSON.stringify(data);
530
- if (!headers["Content-Type"] && !headers["content-type"]) {
531
- headers["Content-Type"] = "application/json";
532
- }
533
- }
534
- }
535
- const response = await this.fetch(url, {
536
- ...options,
537
- headers,
538
- body,
539
- method: "DELETE"
540
- });
541
- const text = await response.text();
542
- let responseData;
543
- try {
544
- responseData = JSON.parse(text);
545
- } catch {
546
- responseData = text;
547
- }
548
- const newResponse = new Response(text, {
549
- status: response.status,
550
- statusText: response.statusText,
551
- headers: response.headers
552
- });
553
- return {
554
- data: responseData,
555
- response: newResponse
556
- };
557
- }
558
- };
559
- var Net = CacheableNet;
560
- // Annotate the CommonJS export names for ESM import in node:
561
- 0 && (module.exports = {
562
- CacheableNet,
563
- Net,
564
- del,
565
- fetch,
566
- get,
567
- head,
568
- patch,
569
- post
570
- });
1
+ "use strict";var v=Object.create;var w=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var q=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,$=Object.prototype.hasOwnProperty;var A=(c,e)=>{for(var t in e)w(c,t,{get:e[t],enumerable:!0})},I=(c,e,t,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of q(e))!$.call(c,n)&&n!==t&&w(c,n,{get:()=>e[n],enumerable:!(s=L(e,n))||s.enumerable});return c};var G=(c,e,t)=>(t=c!=null?v(J(c)):{},I(e||!c||!c.__esModule?w(t,"default",{value:c,enumerable:!0}):t,c)),K=c=>I(w({},"__esModule",{value:!0}),c);var z={};A(z,{CacheableNet:()=>b,Net:()=>W,del:()=>E,fetch:()=>y,get:()=>k,head:()=>B,patch:()=>S,post:()=>H});module.exports=K(z);var R=require("cacheable"),U=require("hookified");var F=G(require("http-cache-semantics"),1),m=require("undici");async function y(c,e){let t={...e,cache:"no-cache"};if(!e.cache){let p=await(0,m.fetch)(c,t);if(!p.ok)throw new Error(`Fetch failed with status ${p.status}`);return p}if(e.method==="POST"||e.method==="PATCH"||e.method==="DELETE"||e.method==="HEAD"){let p=await(0,m.fetch)(c,t);if(!p.ok)throw new Error(`Fetch failed with status ${p.status}`);return p}let s=e.httpCachePolicy!==!1,n=e.method||"GET",a=`${n}:${c}`;if(!s){let p=await e.cache.getOrSet(a,async()=>{let T=await(0,m.fetch)(c,t);if(!T.ok)throw new Error(`Fetch failed with status ${T.status}`);return{body:await T.text(),status:T.status,statusText:T.statusText,headers:Object.fromEntries(T.headers.entries())}});if(!p)throw new Error("Failed to get or set cache data");return new Response(p.body,{status:p.status,statusText:p.statusText,headers:p.headers})}let o=`${a}:policy`,[i,r]=await Promise.all([e.cache.get(a),e.cache.get(o)]),h,u,f,l,P;r&&i&&(h=F.default.fromObject(r),u=i.body,f=i.status,l=i.statusText,P=i.headers);let N=t.headers||{},g={url:c,method:n,headers:N};if(h?.satisfiesWithoutRevalidation(g)){let p=h.responseHeaders();return new Response(u,{status:f,statusText:l,headers:p})}let C={};h?.revalidationHeaders(g)&&(C=h.revalidationHeaders(g));let d=await(0,m.fetch)(c,{...t,headers:{...t.headers,...C}});if(d.status===304&&h){let{policy:p,modified:T}=h.revalidatedPolicy(g,{status:d.status,headers:Object.fromEntries(d.headers.entries())});if(!T){let x=p.timeToLive();await e.cache.set(o,p.toObject(),x),await e.cache.set(a,{body:u,status:f,statusText:l,headers:P},x);let j=p.responseHeaders();return new Response(u,{status:f,statusText:l,headers:j})}}if(!d.ok&&d.status!==304)throw new Error(`Fetch failed with status ${d.status}`);let _=await d.text(),D={status:d.status,statusText:d.statusText,headers:Object.fromEntries(d.headers.entries())},O=new F.default(g,D);if(O.storable()){let p=O.timeToLive();await Promise.all([e.cache.set(a,{body:_,status:d.status,statusText:d.statusText,headers:D.headers},p),e.cache.set(o,O.toObject(),p)])}return new Response(_,{status:d.status,statusText:d.statusText,headers:d.headers})}async function k(c,e){let t=await y(c,{...e,method:"GET"}),s=await t.text(),n;try{n=JSON.parse(s)}catch{n=s}let a=new Response(s,{status:t.status,statusText:t.statusText,headers:t.headers});return{data:n,response:a}}async function H(c,e,t){let s,n={...t.headers};typeof e=="string"||e instanceof FormData||e instanceof URLSearchParams||e instanceof Blob?s=e:(s=JSON.stringify(e),!n["Content-Type"]&&!n["content-type"]&&(n["Content-Type"]="application/json"));let a=await y(c,{...t,headers:n,body:s,method:"POST"}),o=await a.text(),i;try{i=JSON.parse(o)}catch{i=o}let r=new Response(o,{status:a.status,statusText:a.statusText,headers:a.headers});return{data:i,response:r}}async function S(c,e,t){let s,n={...t.headers};typeof e=="string"||e instanceof FormData||e instanceof URLSearchParams||e instanceof Blob?s=e:(s=JSON.stringify(e),!n["Content-Type"]&&!n["content-type"]&&(n["Content-Type"]="application/json"));let a=await y(c,{...t,headers:n,body:s,method:"PATCH"}),o=await a.text(),i;try{i=JSON.parse(o)}catch{i=o}let r=new Response(o,{status:a.status,statusText:a.statusText,headers:a.headers});return{data:i,response:r}}async function E(c,e,t){let s,n;if(e!==void 0&&typeof e=="object"&&e!==null&&"cache"in e)s=void 0,n=e;else if(t)s=e,n=t;else throw new Error("Fetch options must include a cache instance or options.");let a,o={...n.headers};s!==void 0&&(typeof s=="string"||s instanceof FormData||s instanceof URLSearchParams||s instanceof Blob?a=s:(a=JSON.stringify(s),!o["Content-Type"]&&!o["content-type"]&&(o["Content-Type"]="application/json")));let i=await y(c,{...n,headers:o,body:a,method:"DELETE"}),r=await i.text(),h;try{h=JSON.parse(r)}catch{h=r}let u=new Response(r,{status:i.status,statusText:i.statusText,headers:i.headers});return{data:h,response:u}}async function B(c,e){return await y(c,{...e,method:"HEAD"})}var b=class extends U.Hookified{_cache=new R.Cacheable;_httpCachePolicy=!0;_stringify=JSON.stringify;_parse=JSON.parse;constructor(e){super(e),e?.cache&&(this._cache=e.cache instanceof R.Cacheable?e.cache:new R.Cacheable(e.cache)),e?.httpCachePolicy!==void 0&&(this._httpCachePolicy=e.httpCachePolicy),e?.stringify&&(this._stringify=e?.stringify),e?.parse&&(this._parse=e?.parse)}get stringify(){return this._stringify}set stringify(e){this._stringify=e}get parse(){return this._parse}set parse(e){this._parse=e}get cache(){return this._cache}set cache(e){this._cache=e}get httpCachePolicy(){return this._httpCachePolicy}set httpCachePolicy(e){this._httpCachePolicy=e}async fetch(e,t){let s={...t,cache:this._cache,httpCachePolicy:this._httpCachePolicy};return y(e,s)}async get(e,t){let s={...t,cache:this._cache,httpCachePolicy:this._httpCachePolicy,method:"GET"};t?.caching!==void 0&&delete s.cache;let n=await y(e,s),a=await n.text(),o,i=t?.parse||this._parse;try{o=i(a)}catch{o=a}let r=new Response(a,{status:n.status,statusText:n.statusText,headers:n.headers});return{data:o,response:r}}async post(e,t,s){let n,a={...s?.headers};typeof t=="string"||t instanceof FormData||t instanceof URLSearchParams||t instanceof Blob?n=t:(n=(s?.stringify||this._stringify)(t),!a["Content-Type"]&&!a["content-type"]&&(a["Content-Type"]="application/json"));let o={...s,headers:a,body:n,httpCachePolicy:this._httpCachePolicy,method:"POST"};s?.caching===!0&&(o.cache=this._cache);let i=await y(e,o),r=await i.text(),h,u=s?.parse||this._parse;try{h=u(r)}catch{h=r}let f=new Response(r,{status:i.status,statusText:i.statusText,headers:i.headers});return{data:h,response:f}}async head(e,t){let s={...t,cache:this._cache,httpCachePolicy:this._httpCachePolicy,method:"HEAD"};return t?.caching!==void 0&&!t.caching&&delete s.cache,await y(e,s)}async put(e,t,s){let n,a={...s?.headers};typeof t=="string"||t instanceof FormData||t instanceof URLSearchParams||t instanceof Blob?n=t:(n=(s?.stringify||this._stringify)(t),!a["Content-Type"]&&!a["content-type"]&&(a["Content-Type"]="application/json"));let o={...s,headers:a,body:n,httpCachePolicy:this._httpCachePolicy,method:"PUT"};s?.caching===!0&&(o.cache=this._cache);let i=await y(e,o),r=await i.text(),h,u=s?.parse||this._parse;try{h=u(r)}catch{h=r}let f=new Response(r,{status:i.status,statusText:i.statusText,headers:i.headers});return{data:h,response:f}}async patch(e,t,s){let n,a={...s?.headers};typeof t=="string"||t instanceof FormData||t instanceof URLSearchParams||t instanceof Blob?n=t:(n=(s?.stringify||this._stringify)(t),!a["Content-Type"]&&!a["content-type"]&&(a["Content-Type"]="application/json"));let o={...s,headers:a,body:n,httpCachePolicy:this._httpCachePolicy,method:"PATCH"};s?.caching===!0&&(o.cache=this._cache);let i=await y(e,o),r=await i.text(),h,u=s?.parse||this._parse;try{h=u(r)}catch{h=r}let f=new Response(r,{status:i.status,statusText:i.statusText,headers:i.headers});return{data:h,response:f}}async delete(e,t,s){let n,a={...s?.headers};t!==void 0&&(typeof t=="string"||t instanceof FormData||t instanceof URLSearchParams||t instanceof Blob?n=t:(n=(s?.stringify||this._stringify)(t),!a["Content-Type"]&&!a["content-type"]&&(a["Content-Type"]="application/json")));let o={...s,headers:a,body:n,httpCachePolicy:this._httpCachePolicy,method:"DELETE"};s?.caching===!0&&(o.cache=this._cache);let i=await y(e,o),r=await i.text(),h,u=s?.parse||this._parse;try{h=u(r)}catch{h=r}let f=new Response(r,{status:i.status,statusText:i.statusText,headers:i.headers});return{data:h,response:f}}},W=b;0&&(module.exports={CacheableNet,Net,del,fetch,get,head,patch,post});