ng2-rest 19.0.46 → 19.0.47
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/README.md +136 -136
- package/browser/README.md +24 -24
- package/browser/fesm2022/ng2-rest.mjs +40 -21
- package/browser/fesm2022/ng2-rest.mjs.map +1 -1
- package/browser/lib/models.d.ts +37 -11
- package/browser/package.json +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/models.d.ts +37 -11
- package/lib/models.js +53 -31
- package/lib/models.js.map +1 -1
- package/lib/rest-request.js +4 -1
- package/lib/rest-request.js.map +1 -1
- package/package.json +1 -1
- package/websql/README.md +24 -24
- package/websql/fesm2022/ng2-rest.mjs +40 -21
- package/websql/fesm2022/ng2-rest.mjs.map +1 -1
- package/websql/lib/models.d.ts +37 -11
- package/websql/package.json +1 -1
- package/lib/request-cache.d.ts +0 -18
- package/lib/request-cache.js +0 -118
- package/lib/request-cache.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { from, firstValueFrom, Subject, Observable } from 'rxjs';
|
|
2
|
-
import { _, UtilsOs, CoreHelpers, Helpers as Helpers$1 } from 'tnp-core/websql';
|
|
2
|
+
import { _, UtilsOs, CoreHelpers, CoreModels, Helpers as Helpers$1 } from 'tnp-core/websql';
|
|
3
3
|
import { diffChars } from 'diff';
|
|
4
4
|
import { Log, Level } from 'ng2-logger/websql';
|
|
5
5
|
import { walk } from 'lodash-walk-object/websql';
|
|
@@ -643,6 +643,12 @@ const buildInterceptorChain = (interceptors, backend) => {
|
|
|
643
643
|
};
|
|
644
644
|
|
|
645
645
|
/* */
|
|
646
|
+
class RestCommonHttpResponseWrapper {
|
|
647
|
+
}
|
|
648
|
+
class RestResponseWrapper extends RestCommonHttpResponseWrapper {
|
|
649
|
+
}
|
|
650
|
+
class RestErrorResponseWrapper extends RestCommonHttpResponseWrapper {
|
|
651
|
+
}
|
|
646
652
|
// const log = Log.create('rest namespace', Level.__NOTHING)
|
|
647
653
|
var Models;
|
|
648
654
|
(function (Models) {
|
|
@@ -651,11 +657,19 @@ var Models;
|
|
|
651
657
|
Models.ParamConfig = Models$1.ParamConfig;
|
|
652
658
|
[];
|
|
653
659
|
class BaseBody {
|
|
654
|
-
toJSON(data,
|
|
655
|
-
|
|
660
|
+
toJSON(data, opt) {
|
|
661
|
+
opt = opt || { isJSONArray: false };
|
|
662
|
+
let r = opt.isJSONArray ? [] : {};
|
|
656
663
|
if (typeof data === 'string') {
|
|
657
664
|
try {
|
|
658
|
-
|
|
665
|
+
let parsed = JSON.parse(data);
|
|
666
|
+
if (typeof parsed === 'string' && parsed.trim().startsWith('{')) {
|
|
667
|
+
parsed = JSON.parse(parsed);
|
|
668
|
+
}
|
|
669
|
+
if (opt.parsingError && parsed[CoreModels.TaonHttpErrorCustomProp]) {
|
|
670
|
+
return _.merge(new RestErrorResponseWrapper(), parsed);
|
|
671
|
+
}
|
|
672
|
+
return parsed;
|
|
659
673
|
}
|
|
660
674
|
catch (e) { }
|
|
661
675
|
}
|
|
@@ -689,7 +703,7 @@ var Models;
|
|
|
689
703
|
}
|
|
690
704
|
get rawJson() {
|
|
691
705
|
if (!Helpers$1.isBlob(this.responseText)) {
|
|
692
|
-
let res = this.toJSON(this.responseText, this.isArray);
|
|
706
|
+
let res = this.toJSON(this.responseText, { isJSONArray: this.isArray });
|
|
693
707
|
if (this.circular && Array.isArray(this.circular)) {
|
|
694
708
|
res = JSON10.parse(JSON.stringify(res), this.circular);
|
|
695
709
|
}
|
|
@@ -705,10 +719,12 @@ var Models;
|
|
|
705
719
|
return this.entity(); // @LAST
|
|
706
720
|
}
|
|
707
721
|
if (this.entity && typeof this.entity === 'object') {
|
|
708
|
-
const json = this.toJSON(this.responseText,
|
|
722
|
+
const json = this.toJSON(this.responseText, {
|
|
723
|
+
isJSONArray: this.isArray,
|
|
724
|
+
});
|
|
709
725
|
return Mapping.encode(json, this.entity, this.circular);
|
|
710
726
|
}
|
|
711
|
-
let res = this.toJSON(this.responseText, this.isArray);
|
|
727
|
+
let res = this.toJSON(this.responseText, { isJSONArray: this.isArray });
|
|
712
728
|
if (this.circular && Array.isArray(this.circular)) {
|
|
713
729
|
res = JSON10.parse(JSON.stringify(res), this.circular);
|
|
714
730
|
}
|
|
@@ -732,7 +748,7 @@ var Models;
|
|
|
732
748
|
this.data = data;
|
|
733
749
|
}
|
|
734
750
|
get json() {
|
|
735
|
-
return this.toJSON(this.data);
|
|
751
|
+
return this.toJSON(this.data, { parsingError: true });
|
|
736
752
|
}
|
|
737
753
|
get text() {
|
|
738
754
|
return this.data;
|
|
@@ -791,17 +807,6 @@ var Models;
|
|
|
791
807
|
}
|
|
792
808
|
}
|
|
793
809
|
Models.HttpResponse = HttpResponse;
|
|
794
|
-
class HttpResponseError extends BaseResponse {
|
|
795
|
-
// public tryRecconect() {
|
|
796
|
-
// }
|
|
797
|
-
constructor(message, responseText, headers, statusCode, jobid) {
|
|
798
|
-
super(responseText, headers, statusCode);
|
|
799
|
-
this.message = message;
|
|
800
|
-
this.jobid = jobid;
|
|
801
|
-
this.body = new ErrorBody(responseText);
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
Models.HttpResponseError = HttpResponseError;
|
|
805
810
|
/* */
|
|
806
811
|
/* */
|
|
807
812
|
/* */
|
|
@@ -809,6 +814,17 @@ var Models;
|
|
|
809
814
|
/* */
|
|
810
815
|
/* */
|
|
811
816
|
})(Models || (Models = {}));
|
|
817
|
+
class HttpResponseError extends Models.BaseResponse {
|
|
818
|
+
// public tryRecconect() {
|
|
819
|
+
// }
|
|
820
|
+
constructor(message, responseText, headers, statusCode, jobid, sourceRequest) {
|
|
821
|
+
super(responseText, headers, statusCode);
|
|
822
|
+
this.message = message;
|
|
823
|
+
this.jobid = jobid;
|
|
824
|
+
this.sourceRequest = sourceRequest;
|
|
825
|
+
this.body = new Models.ErrorBody(responseText);
|
|
826
|
+
}
|
|
827
|
+
}
|
|
812
828
|
|
|
813
829
|
class RestHeaders {
|
|
814
830
|
static from(headers) {
|
|
@@ -991,7 +1007,7 @@ class RestRequest {
|
|
|
991
1007
|
}
|
|
992
1008
|
// error no internet
|
|
993
1009
|
if (res.error) {
|
|
994
|
-
this.subjectInuUse[jobid].error(new
|
|
1010
|
+
this.subjectInuUse[jobid].error(new HttpResponseError(res.error, res.data, res.headers, res.code, jobid, sourceRequest));
|
|
995
1011
|
return;
|
|
996
1012
|
}
|
|
997
1013
|
const entity = this.meta[jobid].entity;
|
|
@@ -1086,6 +1102,7 @@ class RestRequest {
|
|
|
1086
1102
|
if (this.subjectInuUse[jobid][isCanceled]) {
|
|
1087
1103
|
return;
|
|
1088
1104
|
}
|
|
1105
|
+
// handle normal request
|
|
1089
1106
|
this.handlerResult({
|
|
1090
1107
|
res: {
|
|
1091
1108
|
code: response.status,
|
|
@@ -1129,6 +1146,7 @@ class RestRequest {
|
|
|
1129
1146
|
const error = catchedError && catchedError.response
|
|
1130
1147
|
? `[${catchedError.response.statusText}]: `
|
|
1131
1148
|
: '';
|
|
1149
|
+
// handle error request
|
|
1132
1150
|
this.handlerResult({
|
|
1133
1151
|
res: {
|
|
1134
1152
|
code: catchedError && catchedError.response
|
|
@@ -1279,6 +1297,7 @@ class RestRequest {
|
|
|
1279
1297
|
let callbackMethodName = 'cb_' + num;
|
|
1280
1298
|
let win = globalThis; // TODO not a good idea! @LAST
|
|
1281
1299
|
win[callbackMethodName] = data => {
|
|
1300
|
+
// handle jsonp result data
|
|
1282
1301
|
this.handlerResult({
|
|
1283
1302
|
res: {
|
|
1284
1303
|
data,
|
|
@@ -1779,5 +1798,5 @@ class SimpleResource {
|
|
|
1779
1798
|
* Generated bundle index. Do not edit.
|
|
1780
1799
|
*/
|
|
1781
1800
|
|
|
1782
|
-
export { AxiosBackendHandler, CONTENT_TYPE, Helpers, Mapping, Models, Resource, Rest, RestHeaders, SimpleResource, buildInterceptorChain, interpolateParamsToUrl };
|
|
1801
|
+
export { AxiosBackendHandler, CONTENT_TYPE, Helpers, HttpResponseError, Mapping, Models, Resource, Rest, RestErrorResponseWrapper, RestHeaders, RestResponseWrapper, SimpleResource, buildInterceptorChain, interpolateParamsToUrl };
|
|
1783
1802
|
//# sourceMappingURL=ng2-rest.mjs.map
|