@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.cjs +25 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +25 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -421,11 +421,11 @@ ${opts.message || this.desc}`;
|
|
|
421
421
|
return new Proxy(this, {
|
|
422
422
|
get: (target, prop2) => {
|
|
423
423
|
if (prop2 in target) return target[prop2];
|
|
424
|
-
return target.store[prop2];
|
|
424
|
+
return deepCopy(target.store[prop2]);
|
|
425
425
|
},
|
|
426
426
|
set: (target, prop2, value2) => {
|
|
427
427
|
if (prop2 in target) target[prop2] = value2;
|
|
428
|
-
else
|
|
428
|
+
else this.set(prop2, value2);
|
|
429
429
|
return true;
|
|
430
430
|
}
|
|
431
431
|
});
|
|
@@ -440,7 +440,7 @@ ${opts.message || this.desc}`;
|
|
|
440
440
|
* @return {T[]} Array of items
|
|
441
441
|
*/
|
|
442
442
|
all() {
|
|
443
|
-
return Object.values(this.store);
|
|
443
|
+
return deepCopy(Object.values(this.store));
|
|
444
444
|
}
|
|
445
445
|
/**
|
|
446
446
|
* Add a new item to the cache. Like set, but finds key automatically
|
|
@@ -495,7 +495,7 @@ ${opts.message || this.desc}`;
|
|
|
495
495
|
* @return {T} Cached item
|
|
496
496
|
*/
|
|
497
497
|
get(key) {
|
|
498
|
-
return this.store[key];
|
|
498
|
+
return deepCopy(this.store[key]);
|
|
499
499
|
}
|
|
500
500
|
/**
|
|
501
501
|
* Get a list of cached keys
|
|
@@ -511,7 +511,7 @@ ${opts.message || this.desc}`;
|
|
|
511
511
|
* @return {Record<K, T>}
|
|
512
512
|
*/
|
|
513
513
|
map() {
|
|
514
|
-
return
|
|
514
|
+
return deepCopy(this.store);
|
|
515
515
|
}
|
|
516
516
|
/**
|
|
517
517
|
* Add an item to the cache manually specifying the key
|
|
@@ -1040,6 +1040,20 @@ ${opts.message || this.desc}`;
|
|
|
1040
1040
|
return new CustomError(message, code);
|
|
1041
1041
|
}
|
|
1042
1042
|
}
|
|
1043
|
+
class HttpResponse extends Response {
|
|
1044
|
+
constructor(resp, stream) {
|
|
1045
|
+
super(stream, { headers: resp.headers, status: resp.status, statusText: resp.statusText });
|
|
1046
|
+
__publicField(this, "data");
|
|
1047
|
+
__publicField(this, "ok");
|
|
1048
|
+
__publicField(this, "redirected");
|
|
1049
|
+
__publicField(this, "type");
|
|
1050
|
+
__publicField(this, "url");
|
|
1051
|
+
this.ok = resp.ok;
|
|
1052
|
+
this.redirected = resp.redirected;
|
|
1053
|
+
this.type = resp.type;
|
|
1054
|
+
this.url = resp.url;
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1043
1057
|
const _Http = class _Http {
|
|
1044
1058
|
constructor(defaults = {}) {
|
|
1045
1059
|
__publicField(this, "interceptors", {});
|
|
@@ -1111,13 +1125,13 @@ ${opts.message || this.desc}`;
|
|
|
1111
1125
|
push();
|
|
1112
1126
|
}
|
|
1113
1127
|
});
|
|
1114
|
-
resp
|
|
1115
|
-
if (opts.decode
|
|
1128
|
+
resp = new HttpResponse(resp, stream);
|
|
1129
|
+
if (opts.decode !== false) {
|
|
1116
1130
|
const content = (_b = resp.headers.get("Content-Type")) == null ? void 0 : _b.toLowerCase();
|
|
1117
|
-
if (content == null ? void 0 : content.includes("form")) resp.data = await resp.
|
|
1118
|
-
else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.
|
|
1119
|
-
else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.
|
|
1120
|
-
else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.
|
|
1131
|
+
if (content == null ? void 0 : content.includes("form")) resp.data = await resp.formData();
|
|
1132
|
+
else if (content == null ? void 0 : content.includes("json")) resp.data = await resp.json();
|
|
1133
|
+
else if (content == null ? void 0 : content.includes("text")) resp.data = await resp.text();
|
|
1134
|
+
else if (content == null ? void 0 : content.includes("application")) resp.data = await resp.blob();
|
|
1121
1135
|
}
|
|
1122
1136
|
if (resp.ok) res(resp);
|
|
1123
1137
|
else rej(resp);
|