@ztimson/utils 0.23.11 → 0.23.13

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.mjs CHANGED
@@ -417,11 +417,11 @@ class Cache {
417
417
  return new Proxy(this, {
418
418
  get: (target, prop2) => {
419
419
  if (prop2 in target) return target[prop2];
420
- return target.store[prop2];
420
+ return deepCopy(target.store[prop2]);
421
421
  },
422
422
  set: (target, prop2, value2) => {
423
423
  if (prop2 in target) target[prop2] = value2;
424
- else target.store[prop2] = value2;
424
+ else this.set(prop2, value2);
425
425
  return true;
426
426
  }
427
427
  });
@@ -436,7 +436,7 @@ class Cache {
436
436
  * @return {T[]} Array of items
437
437
  */
438
438
  all() {
439
- return Object.values(this.store);
439
+ return deepCopy(Object.values(this.store));
440
440
  }
441
441
  /**
442
442
  * Add a new item to the cache. Like set, but finds key automatically
@@ -491,7 +491,7 @@ class Cache {
491
491
  * @return {T} Cached item
492
492
  */
493
493
  get(key) {
494
- return this.store[key];
494
+ return deepCopy(this.store[key]);
495
495
  }
496
496
  /**
497
497
  * Get a list of cached keys
@@ -507,7 +507,7 @@ class Cache {
507
507
  * @return {Record<K, T>}
508
508
  */
509
509
  map() {
510
- return structuredClone(this.store);
510
+ return deepCopy(this.store);
511
511
  }
512
512
  /**
513
513
  * Add an item to the cache manually specifying the key
@@ -1036,6 +1036,20 @@ function errorFromCode(code, message) {
1036
1036
  return new CustomError(message, code);
1037
1037
  }
1038
1038
  }
1039
+ class HttpResponse extends Response {
1040
+ constructor(resp, stream) {
1041
+ super(stream, { headers: resp.headers, status: resp.status, statusText: resp.statusText });
1042
+ __publicField(this, "data");
1043
+ __publicField(this, "ok");
1044
+ __publicField(this, "redirected");
1045
+ __publicField(this, "type");
1046
+ __publicField(this, "url");
1047
+ this.ok = resp.ok;
1048
+ this.redirected = resp.redirected;
1049
+ this.type = resp.type;
1050
+ this.url = resp.url;
1051
+ }
1052
+ }
1039
1053
  const _Http = class _Http {
1040
1054
  constructor(defaults = {}) {
1041
1055
  __publicField(this, "interceptors", {});
@@ -1107,13 +1121,13 @@ const _Http = class _Http {
1107
1121
  push();
1108
1122
  }
1109
1123
  });
1110
- resp.data = new Response(stream);
1111
- if (opts.decode == null || opts.decode) {
1124
+ resp = new HttpResponse(resp, stream);
1125
+ if (opts.decode !== false) {
1112
1126
  const content = (_b = resp.headers.get("Content-Type")) == null ? void 0 : _b.toLowerCase();
1113
- if (content == null ? void 0 : content.includes("form")) resp.data = await resp.data.formData();
1114
- else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.data.json();
1115
- else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.data.text();
1116
- else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.data.blob();
1127
+ if (content == null ? void 0 : content.includes("form")) resp.data = await resp.formData();
1128
+ else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.json();
1129
+ else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.text();
1130
+ else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.blob();
1117
1131
  }
1118
1132
  if (resp.ok) res(resp);
1119
1133
  else rej(resp);