ng2-rest 19.0.36 → 19.0.38
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/browser/fesm2022/ng2-rest.mjs +156 -331
- package/browser/fesm2022/ng2-rest.mjs.map +1 -1
- package/browser/lib/index.d.ts +0 -1
- package/browser/lib/models.d.ts +0 -6
- package/browser/lib/resource-service.d.ts +2 -1
- package/browser/lib/rest-request.d.ts +2 -2
- package/browser/lib/rest.class.d.ts +0 -1
- 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/env/env.angular-node-app.d.ts +1 -0
- package/lib/env/env.angular-node-app.js +3 -2
- package/lib/env/env.angular-node-app.js.map +1 -1
- package/lib/env/env.docs-webapp.d.ts +1 -0
- package/lib/env/env.docs-webapp.js +3 -2
- package/lib/env/env.docs-webapp.js.map +1 -1
- package/lib/env/env.electron-app.d.ts +1 -0
- package/lib/env/env.electron-app.js +3 -2
- package/lib/env/env.electron-app.js.map +1 -1
- package/lib/env/env.mobile-app.d.ts +1 -0
- package/lib/env/env.mobile-app.js +3 -2
- package/lib/env/env.mobile-app.js.map +1 -1
- package/lib/env/env.npm-lib-and-cli-tool.d.ts +1 -0
- package/lib/env/env.npm-lib-and-cli-tool.js +3 -2
- package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib/env/env.vscode-plugin.d.ts +1 -0
- package/lib/env/env.vscode-plugin.js +3 -2
- package/lib/env/env.vscode-plugin.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/models.d.ts +0 -6
- package/lib/models.js +5 -14
- package/lib/models.js.map +1 -1
- package/lib/resource-service.d.ts +2 -1
- package/lib/resource-service.js +0 -3
- package/lib/resource-service.js.map +1 -1
- package/lib/rest-request.d.ts +2 -2
- package/lib/rest-request.js +13 -70
- package/lib/rest-request.js.map +1 -1
- package/lib/rest.class.d.ts +0 -1
- package/lib/rest.class.js +0 -5
- package/lib/rest.class.js.map +1 -1
- package/package.json +1 -1
- package/tmp-environment.json +4 -8
- package/websql/fesm2022/ng2-rest.mjs +156 -331
- package/websql/fesm2022/ng2-rest.mjs.map +1 -1
- package/websql/lib/index.d.ts +0 -1
- package/websql/lib/models.d.ts +0 -6
- package/websql/lib/resource-service.d.ts +2 -1
- package/websql/lib/rest-request.d.ts +2 -2
- package/websql/lib/rest.class.d.ts +0 -1
- package/websql/package.json +1 -1
- package/browser/lib/request-cache.d.ts +0 -19
- package/websql/lib/request-cache.d.ts +0 -19
|
@@ -618,252 +618,6 @@ function prepareUrlOldWay(params) {
|
|
|
618
618
|
return this.endpoint + '/' + params;
|
|
619
619
|
}
|
|
620
620
|
|
|
621
|
-
class RestHeaders {
|
|
622
|
-
static from(headers) {
|
|
623
|
-
if (!headers) {
|
|
624
|
-
return void 0;
|
|
625
|
-
}
|
|
626
|
-
return new RestHeaders(headers);
|
|
627
|
-
}
|
|
628
|
-
constructor(headers) {
|
|
629
|
-
/** @internal header names are lower case */
|
|
630
|
-
this._headers = new Map();
|
|
631
|
-
/** @internal map lower case names to actual names */
|
|
632
|
-
this._normalizedNames = new Map();
|
|
633
|
-
if (headers instanceof RestHeaders) {
|
|
634
|
-
headers.forEach((values, name) => {
|
|
635
|
-
values.forEach(value => this.set(name, value));
|
|
636
|
-
});
|
|
637
|
-
}
|
|
638
|
-
else {
|
|
639
|
-
Object.keys(headers).forEach((name) => {
|
|
640
|
-
const values = (Array.isArray(headers[name]) ? headers[name] : [headers[name]]);
|
|
641
|
-
this.delete(name);
|
|
642
|
-
values.forEach(value => this.set(name, value));
|
|
643
|
-
});
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
/**
|
|
647
|
-
* Returns a new RestHeaders instance from the given DOMString of Response RestHeaders
|
|
648
|
-
*/
|
|
649
|
-
static fromResponseHeaderString(headersString) {
|
|
650
|
-
const headers = new RestHeaders();
|
|
651
|
-
// console.log({
|
|
652
|
-
// headersString
|
|
653
|
-
// })
|
|
654
|
-
headersString.split('\n').forEach(line => {
|
|
655
|
-
const index = line.indexOf(':');
|
|
656
|
-
if (index > 0) {
|
|
657
|
-
const name = line.slice(0, index);
|
|
658
|
-
const value = line.slice(index + 1).trim();
|
|
659
|
-
headers.set(name, value);
|
|
660
|
-
}
|
|
661
|
-
});
|
|
662
|
-
return headers;
|
|
663
|
-
}
|
|
664
|
-
/**
|
|
665
|
-
* Appends a header to existing list of header values for a given header name.
|
|
666
|
-
*/
|
|
667
|
-
append(name, value) {
|
|
668
|
-
const values = this.getAll(name);
|
|
669
|
-
if (values === null) {
|
|
670
|
-
this.set(name, value);
|
|
671
|
-
}
|
|
672
|
-
else {
|
|
673
|
-
values.push(value);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
/**
|
|
677
|
-
* Deletes all header values for the given name.
|
|
678
|
-
*/
|
|
679
|
-
delete(name) {
|
|
680
|
-
const lcName = name.toLowerCase();
|
|
681
|
-
this._normalizedNames.delete(lcName);
|
|
682
|
-
this._headers.delete(lcName);
|
|
683
|
-
}
|
|
684
|
-
forEach(fn) {
|
|
685
|
-
this._headers.forEach((values, lcName) => fn(values, this._normalizedNames.get(lcName), this._headers));
|
|
686
|
-
}
|
|
687
|
-
/**
|
|
688
|
-
* Returns first header that matches given name.
|
|
689
|
-
*/
|
|
690
|
-
get(name) {
|
|
691
|
-
const values = this.getAll(name);
|
|
692
|
-
if (values === null) {
|
|
693
|
-
return null;
|
|
694
|
-
}
|
|
695
|
-
return values.length > 0 ? values[0] : null;
|
|
696
|
-
}
|
|
697
|
-
/**
|
|
698
|
-
* Checks for existence of header by given name.
|
|
699
|
-
*/
|
|
700
|
-
has(name) { return this._headers.has(name.toLowerCase()); }
|
|
701
|
-
/**
|
|
702
|
-
* Returns the names of the headers
|
|
703
|
-
*/
|
|
704
|
-
keys() { return Array.from(this._normalizedNames.values()); }
|
|
705
|
-
/**
|
|
706
|
-
* Sets or overrides header value for given name.
|
|
707
|
-
*/
|
|
708
|
-
set(name, value) {
|
|
709
|
-
if (Array.isArray(value)) {
|
|
710
|
-
if (value.length) {
|
|
711
|
-
this._headers.set(name.toLowerCase(), [value.join(',')]);
|
|
712
|
-
}
|
|
713
|
-
}
|
|
714
|
-
else {
|
|
715
|
-
this._headers.set(name.toLowerCase(), [value]);
|
|
716
|
-
}
|
|
717
|
-
this.mayBeSetNormalizedName(name);
|
|
718
|
-
}
|
|
719
|
-
/**
|
|
720
|
-
* Returns values of all headers.
|
|
721
|
-
*/
|
|
722
|
-
values() { return Array.from(this._headers.values()); }
|
|
723
|
-
/**
|
|
724
|
-
* Returns string of all headers.
|
|
725
|
-
*/
|
|
726
|
-
// TODO(vicb): returns {[name: string]: string[]}
|
|
727
|
-
toJSON() {
|
|
728
|
-
const serialized = {};
|
|
729
|
-
if (!this._headers) {
|
|
730
|
-
// debugger
|
|
731
|
-
}
|
|
732
|
-
// console.log('serializing headers',this._headers)
|
|
733
|
-
this._headers.forEach((values, name) => {
|
|
734
|
-
const split = [];
|
|
735
|
-
values.forEach(v => split.push(...v.split(',')));
|
|
736
|
-
// console.log({
|
|
737
|
-
// values
|
|
738
|
-
// })
|
|
739
|
-
// values.forEach(v => split.push(...(v ? v : '').split(',')));
|
|
740
|
-
serialized[this._normalizedNames.get(name)] = split;
|
|
741
|
-
});
|
|
742
|
-
return serialized;
|
|
743
|
-
}
|
|
744
|
-
/**
|
|
745
|
-
* Returns list of header values for a given name.
|
|
746
|
-
*/
|
|
747
|
-
getAll(name) {
|
|
748
|
-
return this.has(name) ? this._headers.get(name.toLowerCase()) : null;
|
|
749
|
-
}
|
|
750
|
-
mayBeSetNormalizedName(name) {
|
|
751
|
-
const lcName = name.toLowerCase();
|
|
752
|
-
if (!this._normalizedNames.has(lcName)) {
|
|
753
|
-
this._normalizedNames.set(lcName, name);
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
// const log = Log.create('request-cache', Level.__NOTHING);
|
|
759
|
-
/**
|
|
760
|
-
* @deprecated
|
|
761
|
-
* there is Cache API for that
|
|
762
|
-
*/
|
|
763
|
-
class RequestCache {
|
|
764
|
-
static { this.LOCAL_STORAGE_KEY = 'ng2restrequestcache'; }
|
|
765
|
-
static { this.cached = []; }
|
|
766
|
-
static { this.isRestoredFromLocalStorage = false; }
|
|
767
|
-
static restoreFromLocalStorage() {
|
|
768
|
-
if (UtilsOs.isSSRMode) {
|
|
769
|
-
return;
|
|
770
|
-
}
|
|
771
|
-
if (Helpers$1.isNode) {
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
if (!RequestCache.isRestoredFromLocalStorage) {
|
|
775
|
-
RequestCache.isRestoredFromLocalStorage = true;
|
|
776
|
-
const data = localStorage.getItem(RequestCache.LOCAL_STORAGE_KEY);
|
|
777
|
-
let requests = [];
|
|
778
|
-
if (data) {
|
|
779
|
-
try {
|
|
780
|
-
requests = JSON.parse(data);
|
|
781
|
-
}
|
|
782
|
-
catch (error) { }
|
|
783
|
-
const restored = requests.map(r => {
|
|
784
|
-
let { sourceRequest, responseText, body, headers, circular, entity, isArray, cookies, statusCode, } = r.response;
|
|
785
|
-
r.response = new Models.HttpResponse(sourceRequest, responseText, RestHeaders.from(headers), statusCode, entity, circular, -1, // jobid from local storage TODO
|
|
786
|
-
isArray);
|
|
787
|
-
r = new RequestCache(r.response);
|
|
788
|
-
r.response.rq = r;
|
|
789
|
-
return r;
|
|
790
|
-
});
|
|
791
|
-
// log.i('RESTORED FROM LOCAL STORAGE', restored);
|
|
792
|
-
RequestCache.cached = restored;
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
static findBy(sourceRequest) {
|
|
797
|
-
if (UtilsOs.isSSRMode) {
|
|
798
|
-
return;
|
|
799
|
-
}
|
|
800
|
-
// log.i('findby', sourceRequest);
|
|
801
|
-
// log.i('RequestCache.cached', RequestCache.cached);
|
|
802
|
-
RequestCache.restoreFromLocalStorage();
|
|
803
|
-
return RequestCache.cached.find(c => {
|
|
804
|
-
const a = c.response.sourceRequest;
|
|
805
|
-
const b = sourceRequest;
|
|
806
|
-
return (a.isArray === b.isArray &&
|
|
807
|
-
a.url === b.url &&
|
|
808
|
-
a.method === b.method &&
|
|
809
|
-
a.body === b.body);
|
|
810
|
-
});
|
|
811
|
-
}
|
|
812
|
-
constructor(response) {
|
|
813
|
-
this.response = response;
|
|
814
|
-
}
|
|
815
|
-
get containsCache() {
|
|
816
|
-
RequestCache.restoreFromLocalStorage();
|
|
817
|
-
return RequestCache.cached.includes(this);
|
|
818
|
-
}
|
|
819
|
-
persistsInLocalStorage() {
|
|
820
|
-
if (UtilsOs.isSSRMode) {
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
localStorage.setItem(RequestCache.LOCAL_STORAGE_KEY, JSON.stringify(RequestCache.cached.map(r => {
|
|
824
|
-
return {
|
|
825
|
-
response: {
|
|
826
|
-
sourceRequest: r.response.sourceRequest,
|
|
827
|
-
responseText: r.response.responseText,
|
|
828
|
-
headers: r.response.headers,
|
|
829
|
-
statusCode: r.response.statusCode,
|
|
830
|
-
entity: r.response.entity,
|
|
831
|
-
circular: r.response.circular,
|
|
832
|
-
isArray: r.response.isArray,
|
|
833
|
-
},
|
|
834
|
-
};
|
|
835
|
-
})));
|
|
836
|
-
}
|
|
837
|
-
store() {
|
|
838
|
-
if (UtilsOs.isSSRMode) {
|
|
839
|
-
return;
|
|
840
|
-
}
|
|
841
|
-
RequestCache.restoreFromLocalStorage();
|
|
842
|
-
if (!this.containsCache) {
|
|
843
|
-
RequestCache.cached.push(this);
|
|
844
|
-
this.persistsInLocalStorage();
|
|
845
|
-
}
|
|
846
|
-
else {
|
|
847
|
-
console.log('already stored');
|
|
848
|
-
}
|
|
849
|
-
return this;
|
|
850
|
-
}
|
|
851
|
-
remove() {
|
|
852
|
-
if (UtilsOs.isSSRMode) {
|
|
853
|
-
return;
|
|
854
|
-
}
|
|
855
|
-
RequestCache.restoreFromLocalStorage();
|
|
856
|
-
const index = RequestCache.cached.indexOf(this);
|
|
857
|
-
if (index !== -1) {
|
|
858
|
-
RequestCache.cached.splice(index, 1);
|
|
859
|
-
this.persistsInLocalStorage();
|
|
860
|
-
}
|
|
861
|
-
else {
|
|
862
|
-
console.log('already removed');
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
621
|
/* */
|
|
868
622
|
/* */
|
|
869
623
|
// const log = Log.create('rest namespace', Level.__NOTHING)
|
|
@@ -976,6 +730,10 @@ var Models;
|
|
|
976
730
|
}
|
|
977
731
|
Models.BaseResponse = BaseResponse;
|
|
978
732
|
class HttpResponse extends BaseResponse {
|
|
733
|
+
// public readonly TOTAL_COUNT_HEADER = 'X-Total-Count'.toLowerCase();
|
|
734
|
+
// public get totalElements(): number {
|
|
735
|
+
// return Number(this.headers.get(this.TOTAL_COUNT_HEADER));
|
|
736
|
+
// }
|
|
979
737
|
constructor(sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray = false) {
|
|
980
738
|
// console.log({
|
|
981
739
|
// sourceRequest, responseText, headers, statusCode, entity, circular, jobid, isArray
|
|
@@ -1008,12 +766,6 @@ var Models;
|
|
|
1008
766
|
}
|
|
1009
767
|
this.body = new HttpBody(this.responseText, this.isArray, this.entity, this.circular);
|
|
1010
768
|
}
|
|
1011
|
-
get cache() {
|
|
1012
|
-
if (_.isUndefined(this.rq)) {
|
|
1013
|
-
this.rq = new RequestCache(this);
|
|
1014
|
-
}
|
|
1015
|
-
return new RequestCache(this);
|
|
1016
|
-
}
|
|
1017
769
|
}
|
|
1018
770
|
Models.HttpResponse = HttpResponse;
|
|
1019
771
|
class HttpResponseError extends BaseResponse {
|
|
@@ -1035,6 +787,143 @@ var Models;
|
|
|
1035
787
|
/* */
|
|
1036
788
|
})(Models || (Models = {}));
|
|
1037
789
|
|
|
790
|
+
class RestHeaders {
|
|
791
|
+
static from(headers) {
|
|
792
|
+
if (!headers) {
|
|
793
|
+
return void 0;
|
|
794
|
+
}
|
|
795
|
+
return new RestHeaders(headers);
|
|
796
|
+
}
|
|
797
|
+
constructor(headers) {
|
|
798
|
+
/** @internal header names are lower case */
|
|
799
|
+
this._headers = new Map();
|
|
800
|
+
/** @internal map lower case names to actual names */
|
|
801
|
+
this._normalizedNames = new Map();
|
|
802
|
+
if (headers instanceof RestHeaders) {
|
|
803
|
+
headers.forEach((values, name) => {
|
|
804
|
+
values.forEach(value => this.set(name, value));
|
|
805
|
+
});
|
|
806
|
+
}
|
|
807
|
+
else {
|
|
808
|
+
Object.keys(headers).forEach((name) => {
|
|
809
|
+
const values = (Array.isArray(headers[name]) ? headers[name] : [headers[name]]);
|
|
810
|
+
this.delete(name);
|
|
811
|
+
values.forEach(value => this.set(name, value));
|
|
812
|
+
});
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
/**
|
|
816
|
+
* Returns a new RestHeaders instance from the given DOMString of Response RestHeaders
|
|
817
|
+
*/
|
|
818
|
+
static fromResponseHeaderString(headersString) {
|
|
819
|
+
const headers = new RestHeaders();
|
|
820
|
+
// console.log({
|
|
821
|
+
// headersString
|
|
822
|
+
// })
|
|
823
|
+
headersString.split('\n').forEach(line => {
|
|
824
|
+
const index = line.indexOf(':');
|
|
825
|
+
if (index > 0) {
|
|
826
|
+
const name = line.slice(0, index);
|
|
827
|
+
const value = line.slice(index + 1).trim();
|
|
828
|
+
headers.set(name, value);
|
|
829
|
+
}
|
|
830
|
+
});
|
|
831
|
+
return headers;
|
|
832
|
+
}
|
|
833
|
+
/**
|
|
834
|
+
* Appends a header to existing list of header values for a given header name.
|
|
835
|
+
*/
|
|
836
|
+
append(name, value) {
|
|
837
|
+
const values = this.getAll(name);
|
|
838
|
+
if (values === null) {
|
|
839
|
+
this.set(name, value);
|
|
840
|
+
}
|
|
841
|
+
else {
|
|
842
|
+
values.push(value);
|
|
843
|
+
}
|
|
844
|
+
}
|
|
845
|
+
/**
|
|
846
|
+
* Deletes all header values for the given name.
|
|
847
|
+
*/
|
|
848
|
+
delete(name) {
|
|
849
|
+
const lcName = name.toLowerCase();
|
|
850
|
+
this._normalizedNames.delete(lcName);
|
|
851
|
+
this._headers.delete(lcName);
|
|
852
|
+
}
|
|
853
|
+
forEach(fn) {
|
|
854
|
+
this._headers.forEach((values, lcName) => fn(values, this._normalizedNames.get(lcName), this._headers));
|
|
855
|
+
}
|
|
856
|
+
/**
|
|
857
|
+
* Returns first header that matches given name.
|
|
858
|
+
*/
|
|
859
|
+
get(name) {
|
|
860
|
+
const values = this.getAll(name);
|
|
861
|
+
if (values === null) {
|
|
862
|
+
return null;
|
|
863
|
+
}
|
|
864
|
+
return values.length > 0 ? values[0] : null;
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Checks for existence of header by given name.
|
|
868
|
+
*/
|
|
869
|
+
has(name) { return this._headers.has(name.toLowerCase()); }
|
|
870
|
+
/**
|
|
871
|
+
* Returns the names of the headers
|
|
872
|
+
*/
|
|
873
|
+
keys() { return Array.from(this._normalizedNames.values()); }
|
|
874
|
+
/**
|
|
875
|
+
* Sets or overrides header value for given name.
|
|
876
|
+
*/
|
|
877
|
+
set(name, value) {
|
|
878
|
+
if (Array.isArray(value)) {
|
|
879
|
+
if (value.length) {
|
|
880
|
+
this._headers.set(name.toLowerCase(), [value.join(',')]);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
else {
|
|
884
|
+
this._headers.set(name.toLowerCase(), [value]);
|
|
885
|
+
}
|
|
886
|
+
this.mayBeSetNormalizedName(name);
|
|
887
|
+
}
|
|
888
|
+
/**
|
|
889
|
+
* Returns values of all headers.
|
|
890
|
+
*/
|
|
891
|
+
values() { return Array.from(this._headers.values()); }
|
|
892
|
+
/**
|
|
893
|
+
* Returns string of all headers.
|
|
894
|
+
*/
|
|
895
|
+
// TODO(vicb): returns {[name: string]: string[]}
|
|
896
|
+
toJSON() {
|
|
897
|
+
const serialized = {};
|
|
898
|
+
if (!this._headers) {
|
|
899
|
+
// debugger
|
|
900
|
+
}
|
|
901
|
+
// console.log('serializing headers',this._headers)
|
|
902
|
+
this._headers.forEach((values, name) => {
|
|
903
|
+
const split = [];
|
|
904
|
+
values.forEach(v => split.push(...v.split(',')));
|
|
905
|
+
// console.log({
|
|
906
|
+
// values
|
|
907
|
+
// })
|
|
908
|
+
// values.forEach(v => split.push(...(v ? v : '').split(',')));
|
|
909
|
+
serialized[this._normalizedNames.get(name)] = split;
|
|
910
|
+
});
|
|
911
|
+
return serialized;
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* Returns list of header values for a given name.
|
|
915
|
+
*/
|
|
916
|
+
getAll(name) {
|
|
917
|
+
return this.has(name) ? this._headers.get(name.toLowerCase()) : null;
|
|
918
|
+
}
|
|
919
|
+
mayBeSetNormalizedName(name) {
|
|
920
|
+
const lcName = name.toLowerCase();
|
|
921
|
+
if (!this._normalizedNames.has(lcName)) {
|
|
922
|
+
this._normalizedNames.set(lcName, name);
|
|
923
|
+
}
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
|
|
1038
927
|
//#region imports
|
|
1039
928
|
//#endregion
|
|
1040
929
|
// const log = Log.create('[ng2-rest] rest-request', Level.__NOTHING);
|
|
@@ -1051,6 +940,7 @@ class RestRequest {
|
|
|
1051
940
|
constructor() {
|
|
1052
941
|
this.subjectInuUse = {};
|
|
1053
942
|
this.meta = {};
|
|
943
|
+
this.interceptors = new Map();
|
|
1054
944
|
//#endregion
|
|
1055
945
|
this.replaySubjects = {};
|
|
1056
946
|
}
|
|
@@ -1081,28 +971,7 @@ class RestRequest {
|
|
|
1081
971
|
this.meta[jobid] = void 0;
|
|
1082
972
|
this.subjectInuUse[jobid].complete();
|
|
1083
973
|
}
|
|
1084
|
-
checkCache(sourceRequest, jobid) {
|
|
1085
|
-
const existedInCache = RequestCache.findBy(sourceRequest);
|
|
1086
|
-
if (existedInCache) {
|
|
1087
|
-
// log.i('cache exists', existedInCache)
|
|
1088
|
-
const success = Resource['_listenSuccess'];
|
|
1089
|
-
success.next(existedInCache.response);
|
|
1090
|
-
this.subjectInuUse[jobid].next(existedInCache);
|
|
1091
|
-
this.subjectInuUse[jobid].complete();
|
|
1092
|
-
return true;
|
|
1093
|
-
}
|
|
1094
|
-
// log.i(`cache not exists for jobid ${jobid}`)
|
|
1095
|
-
return false;
|
|
1096
|
-
}
|
|
1097
974
|
async req(url, method, headers, body, jobid, isArray = false, mockHttp) {
|
|
1098
|
-
if (this.checkCache({
|
|
1099
|
-
url,
|
|
1100
|
-
body,
|
|
1101
|
-
isArray,
|
|
1102
|
-
method,
|
|
1103
|
-
}, jobid)) {
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
975
|
const CancelToken = axios.CancelToken;
|
|
1107
976
|
const source = CancelToken.source();
|
|
1108
977
|
this.subjectInuUse[jobid][cancelFn] = source.cancel;
|
|
@@ -1140,7 +1009,7 @@ class RestRequest {
|
|
|
1140
1009
|
/* */
|
|
1141
1010
|
// console.log('headers axios:', headers.toJSON())
|
|
1142
1011
|
// console.log({ responseType, headersJson, body, method, url })
|
|
1143
|
-
|
|
1012
|
+
let axiosConfig = {
|
|
1144
1013
|
url,
|
|
1145
1014
|
method,
|
|
1146
1015
|
data: body,
|
|
@@ -1148,7 +1017,17 @@ class RestRequest {
|
|
|
1148
1017
|
headers: headersJson,
|
|
1149
1018
|
cancelToken: source.token,
|
|
1150
1019
|
// withCredentials: true, // this can be done manually
|
|
1151
|
-
}
|
|
1020
|
+
};
|
|
1021
|
+
// console.log('AXIOS CONFIG', axiosConfig);
|
|
1022
|
+
const entries = this.interceptors.entries();
|
|
1023
|
+
// console.log('AXIOS INTERCEPTORS', entries);
|
|
1024
|
+
for (const interceptorObj of entries) {
|
|
1025
|
+
const [interceptorName, interceptor] = interceptorObj;
|
|
1026
|
+
if (typeof interceptor === 'function') {
|
|
1027
|
+
axiosConfig = await interceptor(axiosConfig, interceptorName);
|
|
1028
|
+
}
|
|
1029
|
+
}
|
|
1030
|
+
response = await axios(axiosConfig);
|
|
1152
1031
|
// log.d(`after response of jobid: ${jobid}`);
|
|
1153
1032
|
}
|
|
1154
1033
|
// console.log('AXIOS RESPONES', response)
|
|
@@ -1311,12 +1190,6 @@ class RestRequest {
|
|
|
1311
1190
|
})(this, url, method, headers, body, replay.id, isArray, mockHttp);
|
|
1312
1191
|
const resp = firstValueFrom(replay.subject[customObs]);
|
|
1313
1192
|
resp.observable = replay.subject[customObs];
|
|
1314
|
-
resp.cache = RequestCache.findBy({
|
|
1315
|
-
body,
|
|
1316
|
-
isArray,
|
|
1317
|
-
method,
|
|
1318
|
-
url,
|
|
1319
|
-
});
|
|
1320
1193
|
return resp;
|
|
1321
1194
|
}
|
|
1322
1195
|
get(url, body, headers, meta, isArray, mockHttp) {
|
|
@@ -1342,12 +1215,6 @@ class RestRequest {
|
|
|
1342
1215
|
if (UtilsOs.isSSRMode) {
|
|
1343
1216
|
const emptyStuff = Promise.resolve();
|
|
1344
1217
|
emptyStuff.observable = new Observable();
|
|
1345
|
-
emptyStuff.cache = RequestCache.findBy({
|
|
1346
|
-
body,
|
|
1347
|
-
isArray,
|
|
1348
|
-
method,
|
|
1349
|
-
url,
|
|
1350
|
-
});
|
|
1351
1218
|
console.warn(`Cannot perform jsonp request in SSR mode`);
|
|
1352
1219
|
return emptyStuff;
|
|
1353
1220
|
}
|
|
@@ -1360,14 +1227,6 @@ class RestRequest {
|
|
|
1360
1227
|
let callbackMethodName = 'cb_' + num;
|
|
1361
1228
|
let win = globalThis; // TODO not a good idea! @LAST
|
|
1362
1229
|
win[callbackMethodName] = data => {
|
|
1363
|
-
if (this.checkCache({
|
|
1364
|
-
url,
|
|
1365
|
-
body,
|
|
1366
|
-
isArray,
|
|
1367
|
-
method,
|
|
1368
|
-
}, jobid)) {
|
|
1369
|
-
return;
|
|
1370
|
-
}
|
|
1371
1230
|
this.handlerResult({
|
|
1372
1231
|
res: {
|
|
1373
1232
|
data,
|
|
@@ -1390,34 +1249,8 @@ class RestRequest {
|
|
|
1390
1249
|
});
|
|
1391
1250
|
const resp = firstValueFrom(replay.subject[customObs]);
|
|
1392
1251
|
resp.observable = replay.subject[customObs];
|
|
1393
|
-
// console.log('assiging custom observable');
|
|
1394
|
-
resp.cache = RequestCache.findBy({
|
|
1395
|
-
body,
|
|
1396
|
-
isArray,
|
|
1397
|
-
method,
|
|
1398
|
-
url,
|
|
1399
|
-
});
|
|
1400
1252
|
return resp;
|
|
1401
1253
|
}
|
|
1402
|
-
replay(method, meta) {
|
|
1403
|
-
const replay = this.getReplay(method, meta, true);
|
|
1404
|
-
if (!replay || !replay.data) {
|
|
1405
|
-
console.warn(`Canno replay first ${method} request from ${meta.endpoint}/${meta.path}`);
|
|
1406
|
-
return;
|
|
1407
|
-
}
|
|
1408
|
-
if (replay &&
|
|
1409
|
-
replay.subject &&
|
|
1410
|
-
Array.isArray(replay.subject.observers) &&
|
|
1411
|
-
replay.subject.observers.length === 0) {
|
|
1412
|
-
console.warn(`No observators for ${method} request from ${meta.endpoint}/${meta.path}`);
|
|
1413
|
-
return;
|
|
1414
|
-
}
|
|
1415
|
-
const url = replay.data.url;
|
|
1416
|
-
const headers = replay.data.headers;
|
|
1417
|
-
const body = replay.data.body;
|
|
1418
|
-
const isArray = replay.data.isArray;
|
|
1419
|
-
setTimeout(() => this.req(url, method, headers, body, replay.id, isArray));
|
|
1420
|
-
}
|
|
1421
1254
|
}
|
|
1422
1255
|
|
|
1423
1256
|
const CONTENT_TYPE = {
|
|
@@ -1476,6 +1309,7 @@ class Rest {
|
|
|
1476
1309
|
//#region constructor
|
|
1477
1310
|
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
1478
1311
|
//#endregion
|
|
1312
|
+
//#region http methods
|
|
1479
1313
|
this.array = {
|
|
1480
1314
|
get: (params = void 0, doNotSerializeParams) => {
|
|
1481
1315
|
return this.req('get', void 0, params, doNotSerializeParams, true);
|
|
@@ -1527,12 +1361,6 @@ class Rest {
|
|
|
1527
1361
|
this.mockHttp = void 0;
|
|
1528
1362
|
return result;
|
|
1529
1363
|
}
|
|
1530
|
-
//#endregion
|
|
1531
|
-
//#region http methods
|
|
1532
|
-
//#region replay
|
|
1533
|
-
replay(method) {
|
|
1534
|
-
this.request.replay(method, this.meta);
|
|
1535
|
-
}
|
|
1536
1364
|
get(params, doNotSerializeParams = false) {
|
|
1537
1365
|
return this.req('get', void 0, params, doNotSerializeParams);
|
|
1538
1366
|
}
|
|
@@ -1622,9 +1450,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1622
1450
|
// if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
|
|
1623
1451
|
return {
|
|
1624
1452
|
model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
|
|
1625
|
-
replay: (method) => {
|
|
1626
|
-
Resource.getModel(e, model).replay(method);
|
|
1627
|
-
},
|
|
1628
1453
|
get headers() {
|
|
1629
1454
|
return Resource.getModel(e, model).headers;
|
|
1630
1455
|
},
|
|
@@ -1880,5 +1705,5 @@ class SimpleResource {
|
|
|
1880
1705
|
* Generated bundle index. Do not edit.
|
|
1881
1706
|
*/
|
|
1882
1707
|
|
|
1883
|
-
export { CONTENT_TYPE, Helpers, Mapping, Models,
|
|
1708
|
+
export { CONTENT_TYPE, Helpers, Mapping, Models, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
|
|
1884
1709
|
//# sourceMappingURL=ng2-rest.mjs.map
|