ng2-rest 19.0.31 → 19.0.33
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 +135 -135
- package/browser/README.md +24 -24
- package/browser/fesm2022/ng2-rest.mjs +282 -279
- package/browser/fesm2022/ng2-rest.mjs.map +1 -1
- package/browser/lib/resource-service.d.ts +3 -4
- package/browser/package.json +1 -1
- package/index.js.map +1 -1
- package/lib/build-info._auto-generated_.d.ts +1 -1
- package/lib/build-info._auto-generated_.js +1 -1
- package/lib/build-info._auto-generated_.js.map +1 -1
- package/lib/content-type.js.map +1 -1
- package/lib/cookie.js.map +1 -1
- package/lib/env/env.angular-node-app.d.ts +6 -0
- package/lib/env/env.angular-node-app.js +8 -2
- package/lib/env/env.angular-node-app.js.map +1 -1
- package/lib/env/env.docs-webapp.d.ts +6 -0
- package/lib/env/env.docs-webapp.js +8 -2
- package/lib/env/env.docs-webapp.js.map +1 -1
- package/lib/env/env.electron-app.d.ts +6 -0
- package/lib/env/env.electron-app.js +8 -2
- package/lib/env/env.electron-app.js.map +1 -1
- package/lib/env/env.mobile-app.d.ts +6 -0
- package/lib/env/env.mobile-app.js +8 -2
- package/lib/env/env.mobile-app.js.map +1 -1
- package/lib/env/env.npm-lib-and-cli-tool.d.ts +6 -0
- package/lib/env/env.npm-lib-and-cli-tool.js +8 -2
- package/lib/env/env.npm-lib-and-cli-tool.js.map +1 -1
- package/lib/env/env.vscode-plugin.d.ts +6 -0
- package/lib/env/env.vscode-plugin.js +8 -2
- package/lib/env/env.vscode-plugin.js.map +1 -1
- package/lib/env/index.js.map +1 -1
- package/lib/helpers.js.map +1 -1
- package/lib/index._auto-generated_.js.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mapping.js.map +1 -1
- package/lib/models.js.map +1 -1
- package/lib/other/simple-resource.js.map +1 -1
- package/lib/params.js.map +1 -1
- package/lib/request-cache.js +23 -9
- package/lib/request-cache.js.map +1 -1
- package/lib/resource-service.d.ts +3 -4
- package/lib/resource-service.js +32 -76
- package/lib/resource-service.js.map +1 -1
- package/lib/rest-headers.js.map +1 -1
- package/lib/rest-request.js +67 -38
- package/lib/rest-request.js.map +1 -1
- package/lib/rest.class.js.map +1 -1
- package/migrations/index.js.map +1 -1
- package/migrations/migrations_index._auto-generated_.js.map +1 -1
- package/package.json +1 -1
- package/websql/README.md +24 -24
- package/websql/fesm2022/ng2-rest.mjs +282 -279
- package/websql/fesm2022/ng2-rest.mjs.map +1 -1
- package/websql/lib/resource-service.d.ts +3 -4
- package/websql/package.json +1 -1
- package/tmp-environment.json +0 -39
|
@@ -1,12 +1,39 @@
|
|
|
1
1
|
import { Subject, Observable, firstValueFrom } from 'rxjs';
|
|
2
|
-
import {
|
|
2
|
+
import { _, Helpers as Helpers$1, CoreHelpers, UtilsOs } from 'tnp-core/browser';
|
|
3
3
|
import { diffChars } from 'diff';
|
|
4
|
-
import {
|
|
4
|
+
import { Log, Level } from 'ng2-logger/browser';
|
|
5
5
|
import { walk } from 'lodash-walk-object/browser';
|
|
6
6
|
import { CLASS, SYMBOL, Models as Models$1 } from 'typescript-class-helpers/browser';
|
|
7
7
|
import { JSON10 } from 'json10/browser';
|
|
8
8
|
import axios from 'axios';
|
|
9
9
|
|
|
10
|
+
class Cookie {
|
|
11
|
+
static get Instance() {
|
|
12
|
+
if (!Cookie.__instance) {
|
|
13
|
+
Cookie.__instance = new Cookie();
|
|
14
|
+
}
|
|
15
|
+
return Cookie.__instance;
|
|
16
|
+
}
|
|
17
|
+
constructor() {
|
|
18
|
+
}
|
|
19
|
+
read(name) {
|
|
20
|
+
var result = new RegExp('(?:^|; )' + encodeURIComponent(name) + '=([^;]*)').exec(document.cookie);
|
|
21
|
+
return result ? result[1] : null;
|
|
22
|
+
}
|
|
23
|
+
write(name, value, days) {
|
|
24
|
+
if (!days) {
|
|
25
|
+
days = 365 * 20;
|
|
26
|
+
}
|
|
27
|
+
var date = new Date();
|
|
28
|
+
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
29
|
+
var expires = "; expires=" + date.toUTCString();
|
|
30
|
+
document.cookie = name + "=" + value + expires + "; path=/";
|
|
31
|
+
}
|
|
32
|
+
remove(name) {
|
|
33
|
+
this.write(name, "", -1);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
10
37
|
var Mapping;
|
|
11
38
|
(function (Mapping) {
|
|
12
39
|
function decode(json, autodetect = false) {
|
|
@@ -290,14 +317,14 @@ class Helpers extends CoreHelpers {
|
|
|
290
317
|
}
|
|
291
318
|
}
|
|
292
319
|
|
|
293
|
-
const log
|
|
320
|
+
const log = Log.create('[ng2-rest] params', Level.__NOTHING);
|
|
294
321
|
/** check if string is a valid pattern */
|
|
295
322
|
function isValid(pattern) {
|
|
296
323
|
return (new RegExp('\/:[a-zA-Z]*', 'g')).test(pattern.replace('://', ''));
|
|
297
324
|
}
|
|
298
325
|
function check(url, pattern) {
|
|
299
326
|
if (!Helpers.checkValidUrl(url)) {
|
|
300
|
-
log
|
|
327
|
+
log.error(`Incorrect url: ${url}`);
|
|
301
328
|
return false;
|
|
302
329
|
}
|
|
303
330
|
if (url.charAt(url.length - 1) === '/')
|
|
@@ -728,170 +755,7 @@ class RestHeaders {
|
|
|
728
755
|
}
|
|
729
756
|
}
|
|
730
757
|
|
|
731
|
-
const
|
|
732
|
-
APPLICATION_JSON: RestHeaders.from({
|
|
733
|
-
'Content-Type': 'application/json',
|
|
734
|
-
'Accept': 'application/json'
|
|
735
|
-
}),
|
|
736
|
-
APPLICATINO_VND_API_JSON: RestHeaders.from({
|
|
737
|
-
'Content-Type': 'application/vnd.api+json',
|
|
738
|
-
'Accept': 'application/vnd.api+json'
|
|
739
|
-
}),
|
|
740
|
-
};
|
|
741
|
-
|
|
742
|
-
//#endregion
|
|
743
|
-
class Rest {
|
|
744
|
-
mock(mock) {
|
|
745
|
-
if ((typeof mock === 'function') || (typeof mock === 'object')) {
|
|
746
|
-
this.mockHttp = mock;
|
|
747
|
-
}
|
|
748
|
-
else {
|
|
749
|
-
throw `[ng2-rest]
|
|
750
|
-
.model(...)
|
|
751
|
-
.mock( < BAD MOCK DATA > )
|
|
752
|
-
...
|
|
753
|
-
`;
|
|
754
|
-
}
|
|
755
|
-
return this;
|
|
756
|
-
}
|
|
757
|
-
get endpoint() {
|
|
758
|
-
let e = this.__meta_endpoint;
|
|
759
|
-
if (this.restQueryParams !== void 0 && this._endpointRest !== void 0
|
|
760
|
-
&& typeof this._endpointRest === 'string' && this._endpointRest.trim() !== '')
|
|
761
|
-
e = this._endpointRest;
|
|
762
|
-
return e;
|
|
763
|
-
}
|
|
764
|
-
set __rest_endpoint(endpoint) {
|
|
765
|
-
this._endpointRest = endpoint;
|
|
766
|
-
if (endpoint === void 0) {
|
|
767
|
-
this.restQueryParams = void 0;
|
|
768
|
-
}
|
|
769
|
-
else {
|
|
770
|
-
this.restQueryParams = getRestParams(endpoint, this.__meta_endpoint);
|
|
771
|
-
}
|
|
772
|
-
}
|
|
773
|
-
creatUrl(params, doNotSerializeParams = false) {
|
|
774
|
-
return `${this.endpoint}${getParamsUrl(params, doNotSerializeParams)}`;
|
|
775
|
-
}
|
|
776
|
-
get headers() {
|
|
777
|
-
return this._headers;
|
|
778
|
-
}
|
|
779
|
-
constructor(endpoint, request, meta, customContentType) {
|
|
780
|
-
this.request = request;
|
|
781
|
-
this.meta = meta;
|
|
782
|
-
this.customContentType = customContentType;
|
|
783
|
-
//#endregion
|
|
784
|
-
//#region constructor
|
|
785
|
-
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
786
|
-
//#endregion
|
|
787
|
-
this.array = {
|
|
788
|
-
get: (params = void 0, doNotSerializeParams) => {
|
|
789
|
-
return this.req('get', void 0, params, doNotSerializeParams, true);
|
|
790
|
-
},
|
|
791
|
-
head: (params = void 0, doNotSerializeParams) => {
|
|
792
|
-
return this.req('head', void 0, params, doNotSerializeParams, true);
|
|
793
|
-
},
|
|
794
|
-
post: (item, params, doNotSerializeParams) => {
|
|
795
|
-
return this.req('post', item, params, doNotSerializeParams, true);
|
|
796
|
-
},
|
|
797
|
-
put: (item, params, doNotSerializeParams) => {
|
|
798
|
-
return this.req('put', item, params, doNotSerializeParams, true);
|
|
799
|
-
},
|
|
800
|
-
patch: (item, params, doNotSerializeParams) => {
|
|
801
|
-
return this.req('patch', item, params, doNotSerializeParams, true);
|
|
802
|
-
},
|
|
803
|
-
delete: (params, doNotSerializeParams) => {
|
|
804
|
-
return this.req('delete', void 0, params, doNotSerializeParams, true);
|
|
805
|
-
},
|
|
806
|
-
jsonp: (params, doNotSerializeParams) => {
|
|
807
|
-
return this.req('jsonp', void 0, params, doNotSerializeParams, true);
|
|
808
|
-
}
|
|
809
|
-
};
|
|
810
|
-
this.__meta_endpoint = endpoint;
|
|
811
|
-
}
|
|
812
|
-
//#endregion
|
|
813
|
-
//#region req
|
|
814
|
-
req(method, requestBody, params, doNotSerializeParams = false, isArray = false) {
|
|
815
|
-
const modelUrl = this.creatUrl(params, doNotSerializeParams);
|
|
816
|
-
const body = (CLASS.getNameFromObject(requestBody) === 'FormData')
|
|
817
|
-
? requestBody
|
|
818
|
-
: (requestBody ? JSON.stringify(requestBody) : void 0);
|
|
819
|
-
// console.log('this.customContentType', this.customContentType)
|
|
820
|
-
if (this.customContentType) {
|
|
821
|
-
const customHeaderKeys = this.customContentType.keys();
|
|
822
|
-
const currentHeaderKeys = this._headers.keys();
|
|
823
|
-
currentHeaderKeys
|
|
824
|
-
.filter(key => !customHeaderKeys.includes(key))
|
|
825
|
-
.forEach(key => {
|
|
826
|
-
this.customContentType.set(key, this._headers.get(key));
|
|
827
|
-
});
|
|
828
|
-
this._headers = this.customContentType;
|
|
829
|
-
}
|
|
830
|
-
else {
|
|
831
|
-
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
832
|
-
}
|
|
833
|
-
// console.log("_headers", this.headers)
|
|
834
|
-
const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
|
|
835
|
-
this.mockHttp = void 0;
|
|
836
|
-
return result;
|
|
837
|
-
}
|
|
838
|
-
//#endregion
|
|
839
|
-
//#region http methods
|
|
840
|
-
//#region replay
|
|
841
|
-
replay(method) {
|
|
842
|
-
this.request.replay(method, this.meta);
|
|
843
|
-
}
|
|
844
|
-
get(params, doNotSerializeParams = false) {
|
|
845
|
-
return this.req('get', void 0, params, doNotSerializeParams);
|
|
846
|
-
}
|
|
847
|
-
head(params, doNotSerializeParams = false) {
|
|
848
|
-
return this.req('head', void 0, params, doNotSerializeParams);
|
|
849
|
-
}
|
|
850
|
-
post(item, params, doNotSerializeParams = false) {
|
|
851
|
-
return this.req('post', item, params, doNotSerializeParams);
|
|
852
|
-
}
|
|
853
|
-
put(item, params, doNotSerializeParams = false) {
|
|
854
|
-
return this.req('put', item, params, doNotSerializeParams);
|
|
855
|
-
}
|
|
856
|
-
patch(item, params, doNotSerializeParams = false) {
|
|
857
|
-
return this.req('patch', item, params, doNotSerializeParams);
|
|
858
|
-
}
|
|
859
|
-
delete(params, doNotSerializeParams = false) {
|
|
860
|
-
return this.req('delete', void 0, params, doNotSerializeParams);
|
|
861
|
-
}
|
|
862
|
-
jsonp(params, doNotSerializeParams = false) {
|
|
863
|
-
return this.req('jsonp', void 0, params, doNotSerializeParams);
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
class Cookie {
|
|
868
|
-
static get Instance() {
|
|
869
|
-
if (!Cookie.__instance) {
|
|
870
|
-
Cookie.__instance = new Cookie();
|
|
871
|
-
}
|
|
872
|
-
return Cookie.__instance;
|
|
873
|
-
}
|
|
874
|
-
constructor() {
|
|
875
|
-
}
|
|
876
|
-
read(name) {
|
|
877
|
-
var result = new RegExp('(?:^|; )' + encodeURIComponent(name) + '=([^;]*)').exec(document.cookie);
|
|
878
|
-
return result ? result[1] : null;
|
|
879
|
-
}
|
|
880
|
-
write(name, value, days) {
|
|
881
|
-
if (!days) {
|
|
882
|
-
days = 365 * 20;
|
|
883
|
-
}
|
|
884
|
-
var date = new Date();
|
|
885
|
-
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
|
886
|
-
var expires = "; expires=" + date.toUTCString();
|
|
887
|
-
document.cookie = name + "=" + value + expires + "; path=/";
|
|
888
|
-
}
|
|
889
|
-
remove(name) {
|
|
890
|
-
this.write(name, "", -1);
|
|
891
|
-
}
|
|
892
|
-
}
|
|
893
|
-
|
|
894
|
-
const log$2 = Log.create('request-cache', Level.__NOTHING);
|
|
758
|
+
// const log = Log.create('request-cache', Level.__NOTHING);
|
|
895
759
|
/**
|
|
896
760
|
* @deprecated
|
|
897
761
|
* there is Cache API for that
|
|
@@ -901,6 +765,9 @@ class RequestCache {
|
|
|
901
765
|
static { this.cached = []; }
|
|
902
766
|
static { this.isRestoredFromLocalStorage = false; }
|
|
903
767
|
static restoreFromLocalStorage() {
|
|
768
|
+
if (UtilsOs.isSSRMode) {
|
|
769
|
+
return;
|
|
770
|
+
}
|
|
904
771
|
if (Helpers$1.isNode) {
|
|
905
772
|
return;
|
|
906
773
|
}
|
|
@@ -912,24 +779,26 @@ class RequestCache {
|
|
|
912
779
|
try {
|
|
913
780
|
requests = JSON.parse(data);
|
|
914
781
|
}
|
|
915
|
-
catch (error) {
|
|
916
|
-
}
|
|
782
|
+
catch (error) { }
|
|
917
783
|
const restored = requests.map(r => {
|
|
918
|
-
let { sourceRequest, responseText, body, headers, circular, entity, isArray, cookies, statusCode } = r.response;
|
|
784
|
+
let { sourceRequest, responseText, body, headers, circular, entity, isArray, cookies, statusCode, } = r.response;
|
|
919
785
|
r.response = new Models.HttpResponse(sourceRequest, responseText, RestHeaders.from(headers), statusCode, entity, circular, -1, // jobid from local storage TODO
|
|
920
786
|
isArray);
|
|
921
787
|
r = new RequestCache(r.response);
|
|
922
788
|
r.response.rq = r;
|
|
923
789
|
return r;
|
|
924
790
|
});
|
|
925
|
-
log
|
|
791
|
+
// log.i('RESTORED FROM LOCAL STORAGE', restored);
|
|
926
792
|
RequestCache.cached = restored;
|
|
927
793
|
}
|
|
928
794
|
}
|
|
929
795
|
}
|
|
930
796
|
static findBy(sourceRequest) {
|
|
931
|
-
|
|
932
|
-
|
|
797
|
+
if (UtilsOs.isSSRMode) {
|
|
798
|
+
return;
|
|
799
|
+
}
|
|
800
|
+
// log.i('findby', sourceRequest);
|
|
801
|
+
// log.i('RequestCache.cached', RequestCache.cached);
|
|
933
802
|
RequestCache.restoreFromLocalStorage();
|
|
934
803
|
return RequestCache.cached.find(c => {
|
|
935
804
|
const a = c.response.sourceRequest;
|
|
@@ -948,6 +817,9 @@ class RequestCache {
|
|
|
948
817
|
return RequestCache.cached.includes(this);
|
|
949
818
|
}
|
|
950
819
|
persistsInLocalStorage() {
|
|
820
|
+
if (UtilsOs.isSSRMode) {
|
|
821
|
+
return;
|
|
822
|
+
}
|
|
951
823
|
localStorage.setItem(RequestCache.LOCAL_STORAGE_KEY, JSON.stringify(RequestCache.cached.map(r => {
|
|
952
824
|
return {
|
|
953
825
|
response: {
|
|
@@ -958,11 +830,14 @@ class RequestCache {
|
|
|
958
830
|
entity: r.response.entity,
|
|
959
831
|
circular: r.response.circular,
|
|
960
832
|
isArray: r.response.isArray,
|
|
961
|
-
}
|
|
833
|
+
},
|
|
962
834
|
};
|
|
963
835
|
})));
|
|
964
836
|
}
|
|
965
837
|
store() {
|
|
838
|
+
if (UtilsOs.isSSRMode) {
|
|
839
|
+
return;
|
|
840
|
+
}
|
|
966
841
|
RequestCache.restoreFromLocalStorage();
|
|
967
842
|
if (!this.containsCache) {
|
|
968
843
|
RequestCache.cached.push(this);
|
|
@@ -974,6 +849,9 @@ class RequestCache {
|
|
|
974
849
|
return this;
|
|
975
850
|
}
|
|
976
851
|
remove() {
|
|
852
|
+
if (UtilsOs.isSSRMode) {
|
|
853
|
+
return;
|
|
854
|
+
}
|
|
977
855
|
RequestCache.restoreFromLocalStorage();
|
|
978
856
|
const index = RequestCache.cached.indexOf(this);
|
|
979
857
|
if (index !== -1) {
|
|
@@ -1157,7 +1035,9 @@ var Models;
|
|
|
1157
1035
|
/* */
|
|
1158
1036
|
})(Models || (Models = {}));
|
|
1159
1037
|
|
|
1160
|
-
|
|
1038
|
+
//#region imports
|
|
1039
|
+
//#endregion
|
|
1040
|
+
// const log = Log.create('[ng2-rest] rest-request', Level.__NOTHING);
|
|
1161
1041
|
/**
|
|
1162
1042
|
* TODO refactor this (remove jobid)
|
|
1163
1043
|
*/
|
|
@@ -1219,7 +1099,7 @@ class RestRequest {
|
|
|
1219
1099
|
url,
|
|
1220
1100
|
body,
|
|
1221
1101
|
isArray,
|
|
1222
|
-
method
|
|
1102
|
+
method,
|
|
1223
1103
|
}, jobid)) {
|
|
1224
1104
|
return;
|
|
1225
1105
|
}
|
|
@@ -1234,7 +1114,7 @@ class RestRequest {
|
|
|
1234
1114
|
status: mockHttp.code,
|
|
1235
1115
|
headers: mockHttp.headers,
|
|
1236
1116
|
statusText: mockHttp.error,
|
|
1237
|
-
config: {}
|
|
1117
|
+
config: {},
|
|
1238
1118
|
};
|
|
1239
1119
|
}
|
|
1240
1120
|
else if (typeof mockHttp === 'function') {
|
|
@@ -1244,15 +1124,20 @@ class RestRequest {
|
|
|
1244
1124
|
status: r.code,
|
|
1245
1125
|
headers: r.headers,
|
|
1246
1126
|
statusText: r.error,
|
|
1247
|
-
config: {}
|
|
1127
|
+
config: {},
|
|
1248
1128
|
};
|
|
1249
1129
|
}
|
|
1250
1130
|
}
|
|
1251
1131
|
const headersJson = headers.toJSON();
|
|
1252
|
-
const responseType = headersJson.responsetypeaxios
|
|
1132
|
+
const responseType = headersJson.responsetypeaxios
|
|
1133
|
+
? headersJson.responsetypeaxios
|
|
1134
|
+
: 'text';
|
|
1253
1135
|
try {
|
|
1254
1136
|
if (!response) {
|
|
1255
|
-
|
|
1137
|
+
/* */
|
|
1138
|
+
/* */
|
|
1139
|
+
/* */
|
|
1140
|
+
/* */
|
|
1256
1141
|
// console.log('headers axios:', headers.toJSON())
|
|
1257
1142
|
// console.log({ responseType, headersJson, body, method, url })
|
|
1258
1143
|
response = await axios({
|
|
@@ -1276,11 +1161,11 @@ class RestRequest {
|
|
|
1276
1161
|
data: response.data,
|
|
1277
1162
|
isArray,
|
|
1278
1163
|
jobid,
|
|
1279
|
-
headers: RestHeaders.from(response.headers)
|
|
1164
|
+
headers: RestHeaders.from(response.headers),
|
|
1280
1165
|
},
|
|
1281
1166
|
method,
|
|
1282
1167
|
jobid,
|
|
1283
|
-
isArray
|
|
1168
|
+
isArray,
|
|
1284
1169
|
}, {
|
|
1285
1170
|
url,
|
|
1286
1171
|
body,
|
|
@@ -1294,7 +1179,9 @@ class RestRequest {
|
|
|
1294
1179
|
}
|
|
1295
1180
|
// console.log('ERROR RESPONESE catchedError typeof ', typeof catchedError)
|
|
1296
1181
|
// console.log('ERROR RESPONESE catchedError', catchedError)
|
|
1297
|
-
if (typeof catchedError === 'object' &&
|
|
1182
|
+
if (typeof catchedError === 'object' &&
|
|
1183
|
+
catchedError.response &&
|
|
1184
|
+
catchedError.response.data) {
|
|
1298
1185
|
const err = catchedError.response.data;
|
|
1299
1186
|
const msg = catchedError.response.data.message || '';
|
|
1300
1187
|
// console.log({
|
|
@@ -1305,27 +1192,35 @@ class RestRequest {
|
|
|
1305
1192
|
errObs.next({
|
|
1306
1193
|
msg,
|
|
1307
1194
|
stack,
|
|
1308
|
-
data: catchedError.response.data
|
|
1195
|
+
data: catchedError.response.data,
|
|
1309
1196
|
});
|
|
1310
1197
|
}
|
|
1311
|
-
const error =
|
|
1198
|
+
const error = catchedError && catchedError.response
|
|
1199
|
+
? `[${catchedError.response.statusText}]: `
|
|
1200
|
+
: '';
|
|
1312
1201
|
this.handlerResult({
|
|
1313
1202
|
res: {
|
|
1314
|
-
code:
|
|
1203
|
+
code: catchedError && catchedError.response
|
|
1204
|
+
? catchedError.response.status
|
|
1205
|
+
: void 0,
|
|
1315
1206
|
error: `${error}${catchedError.message}`,
|
|
1316
|
-
data:
|
|
1207
|
+
data: catchedError && catchedError.response
|
|
1208
|
+
? JSON.stringify(catchedError.response.data)
|
|
1209
|
+
: void 0,
|
|
1317
1210
|
isArray,
|
|
1318
1211
|
jobid,
|
|
1319
|
-
headers: RestHeaders.from(catchedError &&
|
|
1212
|
+
headers: RestHeaders.from(catchedError &&
|
|
1213
|
+
catchedError.response &&
|
|
1214
|
+
catchedError.response.headers),
|
|
1320
1215
|
},
|
|
1321
1216
|
method,
|
|
1322
1217
|
jobid,
|
|
1323
|
-
isArray
|
|
1218
|
+
isArray,
|
|
1324
1219
|
}, {
|
|
1325
1220
|
url,
|
|
1326
1221
|
body,
|
|
1327
1222
|
isArray,
|
|
1328
|
-
method
|
|
1223
|
+
method,
|
|
1329
1224
|
});
|
|
1330
1225
|
}
|
|
1331
1226
|
}
|
|
@@ -1345,9 +1240,8 @@ class RestRequest {
|
|
|
1345
1240
|
this.replaySubjects[meta.endpoint][meta.path][method] = {};
|
|
1346
1241
|
}
|
|
1347
1242
|
//#endregion
|
|
1348
|
-
const objectIDToCreateOrLast =
|
|
1349
|
-
|
|
1350
|
-
if (onlyGetLastReplayForMethod && (objectIDToCreateOrLast === 0)) {
|
|
1243
|
+
const objectIDToCreateOrLast = Object.keys(this.replaySubjects[meta.endpoint][meta.path][method]).length + (onlyGetLastReplayForMethod ? 0 : 1);
|
|
1244
|
+
if (onlyGetLastReplayForMethod && objectIDToCreateOrLast === 0) {
|
|
1351
1245
|
return replay;
|
|
1352
1246
|
}
|
|
1353
1247
|
if (_.isUndefined(this.replaySubjects[meta.endpoint][meta.path][method][objectIDToCreateOrLast])) {
|
|
@@ -1357,7 +1251,8 @@ class RestRequest {
|
|
|
1357
1251
|
data: void 0,
|
|
1358
1252
|
};
|
|
1359
1253
|
}
|
|
1360
|
-
replay =
|
|
1254
|
+
replay =
|
|
1255
|
+
this.replaySubjects[meta.endpoint][meta.path][method][objectIDToCreateOrLast];
|
|
1361
1256
|
if (!_.isNumber(replay.id)) {
|
|
1362
1257
|
if (RestRequest.jobId === Number.MAX_SAFE_INTEGER) {
|
|
1363
1258
|
RestRequest.jobId = 0;
|
|
@@ -1368,7 +1263,7 @@ class RestRequest {
|
|
|
1368
1263
|
subject[jobIDkey] = jobid; // modify internal rxjs subject obj
|
|
1369
1264
|
this.meta[jobid] = meta;
|
|
1370
1265
|
this.subjectInuUse[jobid] = subject;
|
|
1371
|
-
this.subjectInuUse[jobid][customObs] = new Observable(
|
|
1266
|
+
this.subjectInuUse[jobid][customObs] = new Observable(observer => {
|
|
1372
1267
|
// observer.remove(() => {
|
|
1373
1268
|
// });
|
|
1374
1269
|
observer.add(() => {
|
|
@@ -1420,7 +1315,7 @@ class RestRequest {
|
|
|
1420
1315
|
body,
|
|
1421
1316
|
isArray,
|
|
1422
1317
|
method,
|
|
1423
|
-
url
|
|
1318
|
+
url,
|
|
1424
1319
|
});
|
|
1425
1320
|
return resp;
|
|
1426
1321
|
}
|
|
@@ -1443,30 +1338,44 @@ class RestRequest {
|
|
|
1443
1338
|
return this.generalReq('patch', url, body, headers, meta, isArray, mockHttp);
|
|
1444
1339
|
}
|
|
1445
1340
|
jsonp(url, body, headers, meta, isArray, mockHttp) {
|
|
1341
|
+
const method = 'jsonp';
|
|
1342
|
+
if (UtilsOs.isSSRMode) {
|
|
1343
|
+
const emptyStuff = Promise.resolve();
|
|
1344
|
+
emptyStuff.observable = new Observable();
|
|
1345
|
+
emptyStuff.cache = RequestCache.findBy({
|
|
1346
|
+
body,
|
|
1347
|
+
isArray,
|
|
1348
|
+
method,
|
|
1349
|
+
url,
|
|
1350
|
+
});
|
|
1351
|
+
console.warn(`Cannot perform jsonp request in SSR mode`);
|
|
1352
|
+
return emptyStuff;
|
|
1353
|
+
}
|
|
1446
1354
|
const replay = this.getReplay('jsonp', meta, false);
|
|
1447
1355
|
const jobid = replay.id;
|
|
1448
|
-
const method = 'jsonp';
|
|
1449
1356
|
setTimeout(() => {
|
|
1450
1357
|
if (url.endsWith('/'))
|
|
1451
1358
|
url = url.slice(0, url.length - 1);
|
|
1452
1359
|
let num = Math.round(10000 * Math.random());
|
|
1453
|
-
let callbackMethodName =
|
|
1454
|
-
|
|
1360
|
+
let callbackMethodName = 'cb_' + num;
|
|
1361
|
+
let win = globalThis; // TODO not a good idea! @LAST
|
|
1362
|
+
win[callbackMethodName] = data => {
|
|
1455
1363
|
if (this.checkCache({
|
|
1456
1364
|
url,
|
|
1457
1365
|
body,
|
|
1458
1366
|
isArray,
|
|
1459
|
-
method
|
|
1367
|
+
method,
|
|
1460
1368
|
}, jobid)) {
|
|
1461
1369
|
return;
|
|
1462
1370
|
}
|
|
1463
1371
|
this.handlerResult({
|
|
1464
1372
|
res: {
|
|
1465
|
-
data,
|
|
1373
|
+
data,
|
|
1374
|
+
isArray,
|
|
1466
1375
|
},
|
|
1467
1376
|
method,
|
|
1468
1377
|
jobid,
|
|
1469
|
-
isArray
|
|
1378
|
+
isArray,
|
|
1470
1379
|
}, {
|
|
1471
1380
|
url,
|
|
1472
1381
|
body,
|
|
@@ -1481,12 +1390,12 @@ class RestRequest {
|
|
|
1481
1390
|
});
|
|
1482
1391
|
const resp = firstValueFrom(replay.subject[customObs]);
|
|
1483
1392
|
resp.observable = replay.subject[customObs];
|
|
1484
|
-
console.log('assiging custom observable');
|
|
1393
|
+
// console.log('assiging custom observable');
|
|
1485
1394
|
resp.cache = RequestCache.findBy({
|
|
1486
1395
|
body,
|
|
1487
1396
|
isArray,
|
|
1488
1397
|
method,
|
|
1489
|
-
url
|
|
1398
|
+
url,
|
|
1490
1399
|
});
|
|
1491
1400
|
return resp;
|
|
1492
1401
|
}
|
|
@@ -1496,8 +1405,9 @@ class RestRequest {
|
|
|
1496
1405
|
console.warn(`Canno replay first ${method} request from ${meta.endpoint}/${meta.path}`);
|
|
1497
1406
|
return;
|
|
1498
1407
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1408
|
+
if (replay &&
|
|
1409
|
+
replay.subject &&
|
|
1410
|
+
Array.isArray(replay.subject.observers) &&
|
|
1501
1411
|
replay.subject.observers.length === 0) {
|
|
1502
1412
|
console.warn(`No observators for ${method} request from ${meta.endpoint}/${meta.path}`);
|
|
1503
1413
|
return;
|
|
@@ -1510,7 +1420,144 @@ class RestRequest {
|
|
|
1510
1420
|
}
|
|
1511
1421
|
}
|
|
1512
1422
|
|
|
1513
|
-
const
|
|
1423
|
+
const CONTENT_TYPE = {
|
|
1424
|
+
APPLICATION_JSON: RestHeaders.from({
|
|
1425
|
+
'Content-Type': 'application/json',
|
|
1426
|
+
'Accept': 'application/json'
|
|
1427
|
+
}),
|
|
1428
|
+
APPLICATINO_VND_API_JSON: RestHeaders.from({
|
|
1429
|
+
'Content-Type': 'application/vnd.api+json',
|
|
1430
|
+
'Accept': 'application/vnd.api+json'
|
|
1431
|
+
}),
|
|
1432
|
+
};
|
|
1433
|
+
|
|
1434
|
+
//#endregion
|
|
1435
|
+
class Rest {
|
|
1436
|
+
mock(mock) {
|
|
1437
|
+
if ((typeof mock === 'function') || (typeof mock === 'object')) {
|
|
1438
|
+
this.mockHttp = mock;
|
|
1439
|
+
}
|
|
1440
|
+
else {
|
|
1441
|
+
throw `[ng2-rest]
|
|
1442
|
+
.model(...)
|
|
1443
|
+
.mock( < BAD MOCK DATA > )
|
|
1444
|
+
...
|
|
1445
|
+
`;
|
|
1446
|
+
}
|
|
1447
|
+
return this;
|
|
1448
|
+
}
|
|
1449
|
+
get endpoint() {
|
|
1450
|
+
let e = this.__meta_endpoint;
|
|
1451
|
+
if (this.restQueryParams !== void 0 && this._endpointRest !== void 0
|
|
1452
|
+
&& typeof this._endpointRest === 'string' && this._endpointRest.trim() !== '')
|
|
1453
|
+
e = this._endpointRest;
|
|
1454
|
+
return e;
|
|
1455
|
+
}
|
|
1456
|
+
set __rest_endpoint(endpoint) {
|
|
1457
|
+
this._endpointRest = endpoint;
|
|
1458
|
+
if (endpoint === void 0) {
|
|
1459
|
+
this.restQueryParams = void 0;
|
|
1460
|
+
}
|
|
1461
|
+
else {
|
|
1462
|
+
this.restQueryParams = getRestParams(endpoint, this.__meta_endpoint);
|
|
1463
|
+
}
|
|
1464
|
+
}
|
|
1465
|
+
creatUrl(params, doNotSerializeParams = false) {
|
|
1466
|
+
return `${this.endpoint}${getParamsUrl(params, doNotSerializeParams)}`;
|
|
1467
|
+
}
|
|
1468
|
+
get headers() {
|
|
1469
|
+
return this._headers;
|
|
1470
|
+
}
|
|
1471
|
+
constructor(endpoint, request, meta, customContentType) {
|
|
1472
|
+
this.request = request;
|
|
1473
|
+
this.meta = meta;
|
|
1474
|
+
this.customContentType = customContentType;
|
|
1475
|
+
//#endregion
|
|
1476
|
+
//#region constructor
|
|
1477
|
+
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
1478
|
+
//#endregion
|
|
1479
|
+
this.array = {
|
|
1480
|
+
get: (params = void 0, doNotSerializeParams) => {
|
|
1481
|
+
return this.req('get', void 0, params, doNotSerializeParams, true);
|
|
1482
|
+
},
|
|
1483
|
+
head: (params = void 0, doNotSerializeParams) => {
|
|
1484
|
+
return this.req('head', void 0, params, doNotSerializeParams, true);
|
|
1485
|
+
},
|
|
1486
|
+
post: (item, params, doNotSerializeParams) => {
|
|
1487
|
+
return this.req('post', item, params, doNotSerializeParams, true);
|
|
1488
|
+
},
|
|
1489
|
+
put: (item, params, doNotSerializeParams) => {
|
|
1490
|
+
return this.req('put', item, params, doNotSerializeParams, true);
|
|
1491
|
+
},
|
|
1492
|
+
patch: (item, params, doNotSerializeParams) => {
|
|
1493
|
+
return this.req('patch', item, params, doNotSerializeParams, true);
|
|
1494
|
+
},
|
|
1495
|
+
delete: (params, doNotSerializeParams) => {
|
|
1496
|
+
return this.req('delete', void 0, params, doNotSerializeParams, true);
|
|
1497
|
+
},
|
|
1498
|
+
jsonp: (params, doNotSerializeParams) => {
|
|
1499
|
+
return this.req('jsonp', void 0, params, doNotSerializeParams, true);
|
|
1500
|
+
}
|
|
1501
|
+
};
|
|
1502
|
+
this.__meta_endpoint = endpoint;
|
|
1503
|
+
}
|
|
1504
|
+
//#endregion
|
|
1505
|
+
//#region req
|
|
1506
|
+
req(method, requestBody, params, doNotSerializeParams = false, isArray = false) {
|
|
1507
|
+
const modelUrl = this.creatUrl(params, doNotSerializeParams);
|
|
1508
|
+
const body = (CLASS.getNameFromObject(requestBody) === 'FormData')
|
|
1509
|
+
? requestBody
|
|
1510
|
+
: (requestBody ? JSON.stringify(requestBody) : void 0);
|
|
1511
|
+
// console.log('this.customContentType', this.customContentType)
|
|
1512
|
+
if (this.customContentType) {
|
|
1513
|
+
const customHeaderKeys = this.customContentType.keys();
|
|
1514
|
+
const currentHeaderKeys = this._headers.keys();
|
|
1515
|
+
currentHeaderKeys
|
|
1516
|
+
.filter(key => !customHeaderKeys.includes(key))
|
|
1517
|
+
.forEach(key => {
|
|
1518
|
+
this.customContentType.set(key, this._headers.get(key));
|
|
1519
|
+
});
|
|
1520
|
+
this._headers = this.customContentType;
|
|
1521
|
+
}
|
|
1522
|
+
else {
|
|
1523
|
+
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
1524
|
+
}
|
|
1525
|
+
// console.log("_headers", this.headers)
|
|
1526
|
+
const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
|
|
1527
|
+
this.mockHttp = void 0;
|
|
1528
|
+
return result;
|
|
1529
|
+
}
|
|
1530
|
+
//#endregion
|
|
1531
|
+
//#region http methods
|
|
1532
|
+
//#region replay
|
|
1533
|
+
replay(method) {
|
|
1534
|
+
this.request.replay(method, this.meta);
|
|
1535
|
+
}
|
|
1536
|
+
get(params, doNotSerializeParams = false) {
|
|
1537
|
+
return this.req('get', void 0, params, doNotSerializeParams);
|
|
1538
|
+
}
|
|
1539
|
+
head(params, doNotSerializeParams = false) {
|
|
1540
|
+
return this.req('head', void 0, params, doNotSerializeParams);
|
|
1541
|
+
}
|
|
1542
|
+
post(item, params, doNotSerializeParams = false) {
|
|
1543
|
+
return this.req('post', item, params, doNotSerializeParams);
|
|
1544
|
+
}
|
|
1545
|
+
put(item, params, doNotSerializeParams = false) {
|
|
1546
|
+
return this.req('put', item, params, doNotSerializeParams);
|
|
1547
|
+
}
|
|
1548
|
+
patch(item, params, doNotSerializeParams = false) {
|
|
1549
|
+
return this.req('patch', item, params, doNotSerializeParams);
|
|
1550
|
+
}
|
|
1551
|
+
delete(params, doNotSerializeParams = false) {
|
|
1552
|
+
return this.req('delete', void 0, params, doNotSerializeParams);
|
|
1553
|
+
}
|
|
1554
|
+
jsonp(params, doNotSerializeParams = false) {
|
|
1555
|
+
return this.req('jsonp', void 0, params, doNotSerializeParams);
|
|
1556
|
+
}
|
|
1557
|
+
}
|
|
1558
|
+
|
|
1559
|
+
//#endregion
|
|
1560
|
+
// const log = Log.create('resouce-service', Level.__NOTHING);
|
|
1514
1561
|
class Resource {
|
|
1515
1562
|
static { this._listenErrors = new Subject(); }
|
|
1516
1563
|
static { this._listenSuccess = new Subject(); }
|
|
@@ -1522,41 +1569,6 @@ class Resource {
|
|
|
1522
1569
|
}
|
|
1523
1570
|
static { this.enableWarnings = true; }
|
|
1524
1571
|
//#region private mthods and fields
|
|
1525
|
-
getZone() {
|
|
1526
|
-
const isNode = (typeof window === 'undefined');
|
|
1527
|
-
if (isNode) {
|
|
1528
|
-
return;
|
|
1529
|
-
}
|
|
1530
|
-
;
|
|
1531
|
-
const ng = window['ng'];
|
|
1532
|
-
const getAllAngularRootElements = window['getAllAngularRootElements'];
|
|
1533
|
-
if (!ng || !getAllAngularRootElements) {
|
|
1534
|
-
return;
|
|
1535
|
-
}
|
|
1536
|
-
const probe = ng.probe;
|
|
1537
|
-
const coreTokens = ng.coreTokens;
|
|
1538
|
-
if (!coreTokens || !coreTokens.NgZone) {
|
|
1539
|
-
return;
|
|
1540
|
-
}
|
|
1541
|
-
const zoneClass = coreTokens.NgZone;
|
|
1542
|
-
if (!probe || typeof probe !== 'function' || !getAllAngularRootElements) {
|
|
1543
|
-
return;
|
|
1544
|
-
}
|
|
1545
|
-
const angularElements = getAllAngularRootElements();
|
|
1546
|
-
if (!Array.isArray(angularElements) || angularElements.length === 0) {
|
|
1547
|
-
return;
|
|
1548
|
-
}
|
|
1549
|
-
const rootElement = ng.probe(angularElements[0]);
|
|
1550
|
-
if (!rootElement) {
|
|
1551
|
-
return;
|
|
1552
|
-
}
|
|
1553
|
-
const injector = rootElement.injector;
|
|
1554
|
-
if (!injector || !injector.get || typeof injector.get !== 'function') {
|
|
1555
|
-
return;
|
|
1556
|
-
}
|
|
1557
|
-
const zone = injector.get(zoneClass);
|
|
1558
|
-
return zone;
|
|
1559
|
-
}
|
|
1560
1572
|
static initAngularNgZone(zone) {
|
|
1561
1573
|
RestRequest.zone = zone;
|
|
1562
1574
|
}
|
|
@@ -1595,7 +1607,7 @@ class Resource {
|
|
|
1595
1607
|
const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
|
|
1596
1608
|
const matchArr = model.match(badRestRegEX) || [];
|
|
1597
1609
|
const badModelsNextToEachOther = matchArr.join();
|
|
1598
|
-
const atleas2DoubleDots = (
|
|
1610
|
+
const atleas2DoubleDots = (badModelsNextToEachOther.match(new RegExp(':', 'g')) || []).length >= 2;
|
|
1599
1611
|
if (atleas2DoubleDots && model.search(badModelsNextToEachOther) !== -1) {
|
|
1600
1612
|
throw new Error(`
|
|
1601
1613
|
|
|
@@ -1605,7 +1617,6 @@ Do not create rest models like this: /book/author/:bookid/:authorid
|
|
|
1605
1617
|
Instead use nested approach: /book/:bookid/author/:authorid
|
|
1606
1618
|
`);
|
|
1607
1619
|
}
|
|
1608
|
-
;
|
|
1609
1620
|
Resource.map(e, e);
|
|
1610
1621
|
Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
|
|
1611
1622
|
// if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
|
|
@@ -1616,7 +1627,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1616
1627
|
},
|
|
1617
1628
|
get headers() {
|
|
1618
1629
|
return Resource.getModel(e, model).headers;
|
|
1619
|
-
}
|
|
1630
|
+
},
|
|
1620
1631
|
};
|
|
1621
1632
|
}
|
|
1622
1633
|
//#endregion
|
|
@@ -1626,20 +1637,12 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1626
1637
|
}
|
|
1627
1638
|
//#endregion
|
|
1628
1639
|
//#region constructor
|
|
1629
|
-
constructor() {
|
|
1630
|
-
setTimeout(() => {
|
|
1631
|
-
const zone = this.getZone();
|
|
1632
|
-
if (!RestRequest.zone) {
|
|
1633
|
-
RestRequest.zone = zone;
|
|
1634
|
-
}
|
|
1635
|
-
;
|
|
1636
|
-
});
|
|
1637
|
-
}
|
|
1640
|
+
constructor() { }
|
|
1638
1641
|
//#endregion
|
|
1639
1642
|
static { this.Cookies = Cookie.Instance; }
|
|
1640
1643
|
//#region map
|
|
1641
1644
|
static map(endpoint, url) {
|
|
1642
|
-
log.i('url', url);
|
|
1645
|
+
// log.i('url', url);
|
|
1643
1646
|
let regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
|
|
1644
1647
|
let e = endpoint;
|
|
1645
1648
|
if (!regex.test(url)) {
|
|
@@ -1647,26 +1650,29 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1647
1650
|
}
|
|
1648
1651
|
if (url.charAt(url.length - 1) === '/')
|
|
1649
1652
|
url = url.slice(0, url.length - 1);
|
|
1650
|
-
log.i('url after', url);
|
|
1653
|
+
// log.i('url after', url);
|
|
1651
1654
|
if (Resource.endpoints[e] !== void 0) {
|
|
1652
|
-
Helpers$1.log('Cannot use map function at the same API endpoint again ('
|
|
1653
|
-
|
|
1655
|
+
Helpers$1.log('Cannot use map function at the same API endpoint again (' +
|
|
1656
|
+
Resource.endpoints[e].url +
|
|
1657
|
+
')');
|
|
1654
1658
|
return false;
|
|
1655
1659
|
}
|
|
1656
1660
|
Resource.endpoints[e] = {
|
|
1657
1661
|
url: url,
|
|
1658
1662
|
models: {},
|
|
1659
|
-
entity: null
|
|
1663
|
+
entity: null,
|
|
1660
1664
|
};
|
|
1661
|
-
log.i('enpoints', Resource.endpoints);
|
|
1665
|
+
// log.i('enpoints', Resource.endpoints);
|
|
1662
1666
|
return true;
|
|
1663
1667
|
}
|
|
1664
1668
|
//#endregion
|
|
1665
1669
|
static prepareModel(model) {
|
|
1666
|
-
if (model.charAt(model.length - 1) === '/')
|
|
1670
|
+
if (model.charAt(model.length - 1) === '/') {
|
|
1667
1671
|
model = model.slice(0, model.length - 1);
|
|
1668
|
-
|
|
1672
|
+
}
|
|
1673
|
+
if (model.charAt(0) === '/') {
|
|
1669
1674
|
model = model.slice(1, model.length);
|
|
1675
|
+
}
|
|
1670
1676
|
return model;
|
|
1671
1677
|
}
|
|
1672
1678
|
//#region add
|
|
@@ -1678,28 +1684,26 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1678
1684
|
* @returns {boolean}
|
|
1679
1685
|
*/
|
|
1680
1686
|
add(endpoint, model, entity, circular, customContentType) {
|
|
1681
|
-
log.i(`I am maping ${model} on ${endpoint}`);
|
|
1687
|
+
// log.i(`I am maping ${model} on ${<any>endpoint}`);
|
|
1682
1688
|
model = Resource.prepareModel(model);
|
|
1683
1689
|
let e;
|
|
1684
|
-
e =
|
|
1690
|
+
e = endpoint.toString();
|
|
1685
1691
|
if (Resource.endpoints[e] === void 0) {
|
|
1686
1692
|
console.error('Endpoint is not mapped ! Cannot add model ' + model);
|
|
1687
1693
|
return;
|
|
1688
1694
|
}
|
|
1689
1695
|
if (Resource.endpoints[e].models[model] !== void 0) {
|
|
1690
1696
|
if (Resource.enableWarnings)
|
|
1691
|
-
console.warn(`Model '${model}' is already defined in endpoint: `
|
|
1692
|
-
|
|
1697
|
+
console.warn(`Model '${model}' is already defined in endpoint: ` +
|
|
1698
|
+
Resource.endpoints[e].url);
|
|
1693
1699
|
return;
|
|
1694
1700
|
}
|
|
1695
|
-
Resource.endpoints[e].models[model] =
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
circular,
|
|
1702
|
-
}, customContentType); // TODO put custom content type in meta ?
|
|
1701
|
+
Resource.endpoints[e].models[model] = new Rest(Resource.endpoints[e].url + '/' + model, Resource.request, {
|
|
1702
|
+
endpoint: e,
|
|
1703
|
+
path: model,
|
|
1704
|
+
entity,
|
|
1705
|
+
circular,
|
|
1706
|
+
}, customContentType); // TODO put custom content type in meta ?
|
|
1703
1707
|
return;
|
|
1704
1708
|
}
|
|
1705
1709
|
//#endregion
|
|
@@ -1718,7 +1722,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1718
1722
|
// `)
|
|
1719
1723
|
if (model.charAt(0) === '/')
|
|
1720
1724
|
model = model.slice(1, model.length);
|
|
1721
|
-
let e =
|
|
1725
|
+
let e = endpoint.toString();
|
|
1722
1726
|
if (Resource.endpoints[e] === void 0) {
|
|
1723
1727
|
throw `Endpoint: ${endpoint} is not mapped ! Cannot add model: ${model}`;
|
|
1724
1728
|
}
|
|
@@ -1729,13 +1733,13 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1729
1733
|
// log.d('Resource.endpoints', Resource.endpoints);
|
|
1730
1734
|
throw `Model '${model}' is undefined in endpoint: ${Resource.endpoints[e].url} `;
|
|
1731
1735
|
}
|
|
1732
|
-
let res = Resource.endpoints[
|
|
1736
|
+
let res = Resource.endpoints[endpoint.toString()].models[model];
|
|
1733
1737
|
// log.d(`
|
|
1734
1738
|
// orgModel: ${orgModel}
|
|
1735
1739
|
// model: ${model}
|
|
1736
1740
|
// `)
|
|
1737
1741
|
if (orgModel !== model) {
|
|
1738
|
-
let baseUrl = Resource.endpoints[
|
|
1742
|
+
let baseUrl = Resource.endpoints[endpoint.toString()].url;
|
|
1739
1743
|
// log.d('base', Resource.endpoints[<string>(endpoint).toString()])
|
|
1740
1744
|
// log.d('baseUrl', baseUrl)
|
|
1741
1745
|
// log.d('orgModel', orgModel)
|
|
@@ -1744,7 +1748,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1744
1748
|
else {
|
|
1745
1749
|
res.__rest_endpoint = void 0;
|
|
1746
1750
|
}
|
|
1747
|
-
;
|
|
1748
1751
|
// log.i(`Resource.endpoints`, Resource.endpoints)
|
|
1749
1752
|
return res;
|
|
1750
1753
|
}
|