ng2-rest 19.0.29 → 19.0.32
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 +278 -278
- 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 +64 -37
- 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/fesm2022/ng2-rest.mjs +278 -278
- 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,12 +1124,14 @@ 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
|
// console.log(`[${method}] (jobid=${jobid}) request to: ${url}`);
|
|
@@ -1276,11 +1158,11 @@ class RestRequest {
|
|
|
1276
1158
|
data: response.data,
|
|
1277
1159
|
isArray,
|
|
1278
1160
|
jobid,
|
|
1279
|
-
headers: RestHeaders.from(response.headers)
|
|
1161
|
+
headers: RestHeaders.from(response.headers),
|
|
1280
1162
|
},
|
|
1281
1163
|
method,
|
|
1282
1164
|
jobid,
|
|
1283
|
-
isArray
|
|
1165
|
+
isArray,
|
|
1284
1166
|
}, {
|
|
1285
1167
|
url,
|
|
1286
1168
|
body,
|
|
@@ -1294,7 +1176,9 @@ class RestRequest {
|
|
|
1294
1176
|
}
|
|
1295
1177
|
// console.log('ERROR RESPONESE catchedError typeof ', typeof catchedError)
|
|
1296
1178
|
// console.log('ERROR RESPONESE catchedError', catchedError)
|
|
1297
|
-
if (typeof catchedError === 'object' &&
|
|
1179
|
+
if (typeof catchedError === 'object' &&
|
|
1180
|
+
catchedError.response &&
|
|
1181
|
+
catchedError.response.data) {
|
|
1298
1182
|
const err = catchedError.response.data;
|
|
1299
1183
|
const msg = catchedError.response.data.message || '';
|
|
1300
1184
|
// console.log({
|
|
@@ -1305,27 +1189,35 @@ class RestRequest {
|
|
|
1305
1189
|
errObs.next({
|
|
1306
1190
|
msg,
|
|
1307
1191
|
stack,
|
|
1308
|
-
data: catchedError.response.data
|
|
1192
|
+
data: catchedError.response.data,
|
|
1309
1193
|
});
|
|
1310
1194
|
}
|
|
1311
|
-
const error =
|
|
1195
|
+
const error = catchedError && catchedError.response
|
|
1196
|
+
? `[${catchedError.response.statusText}]: `
|
|
1197
|
+
: '';
|
|
1312
1198
|
this.handlerResult({
|
|
1313
1199
|
res: {
|
|
1314
|
-
code:
|
|
1200
|
+
code: catchedError && catchedError.response
|
|
1201
|
+
? catchedError.response.status
|
|
1202
|
+
: void 0,
|
|
1315
1203
|
error: `${error}${catchedError.message}`,
|
|
1316
|
-
data:
|
|
1204
|
+
data: catchedError && catchedError.response
|
|
1205
|
+
? JSON.stringify(catchedError.response.data)
|
|
1206
|
+
: void 0,
|
|
1317
1207
|
isArray,
|
|
1318
1208
|
jobid,
|
|
1319
|
-
headers: RestHeaders.from(catchedError &&
|
|
1209
|
+
headers: RestHeaders.from(catchedError &&
|
|
1210
|
+
catchedError.response &&
|
|
1211
|
+
catchedError.response.headers),
|
|
1320
1212
|
},
|
|
1321
1213
|
method,
|
|
1322
1214
|
jobid,
|
|
1323
|
-
isArray
|
|
1215
|
+
isArray,
|
|
1324
1216
|
}, {
|
|
1325
1217
|
url,
|
|
1326
1218
|
body,
|
|
1327
1219
|
isArray,
|
|
1328
|
-
method
|
|
1220
|
+
method,
|
|
1329
1221
|
});
|
|
1330
1222
|
}
|
|
1331
1223
|
}
|
|
@@ -1345,9 +1237,8 @@ class RestRequest {
|
|
|
1345
1237
|
this.replaySubjects[meta.endpoint][meta.path][method] = {};
|
|
1346
1238
|
}
|
|
1347
1239
|
//#endregion
|
|
1348
|
-
const objectIDToCreateOrLast =
|
|
1349
|
-
|
|
1350
|
-
if (onlyGetLastReplayForMethod && (objectIDToCreateOrLast === 0)) {
|
|
1240
|
+
const objectIDToCreateOrLast = Object.keys(this.replaySubjects[meta.endpoint][meta.path][method]).length + (onlyGetLastReplayForMethod ? 0 : 1);
|
|
1241
|
+
if (onlyGetLastReplayForMethod && objectIDToCreateOrLast === 0) {
|
|
1351
1242
|
return replay;
|
|
1352
1243
|
}
|
|
1353
1244
|
if (_.isUndefined(this.replaySubjects[meta.endpoint][meta.path][method][objectIDToCreateOrLast])) {
|
|
@@ -1357,7 +1248,8 @@ class RestRequest {
|
|
|
1357
1248
|
data: void 0,
|
|
1358
1249
|
};
|
|
1359
1250
|
}
|
|
1360
|
-
replay =
|
|
1251
|
+
replay =
|
|
1252
|
+
this.replaySubjects[meta.endpoint][meta.path][method][objectIDToCreateOrLast];
|
|
1361
1253
|
if (!_.isNumber(replay.id)) {
|
|
1362
1254
|
if (RestRequest.jobId === Number.MAX_SAFE_INTEGER) {
|
|
1363
1255
|
RestRequest.jobId = 0;
|
|
@@ -1368,7 +1260,7 @@ class RestRequest {
|
|
|
1368
1260
|
subject[jobIDkey] = jobid; // modify internal rxjs subject obj
|
|
1369
1261
|
this.meta[jobid] = meta;
|
|
1370
1262
|
this.subjectInuUse[jobid] = subject;
|
|
1371
|
-
this.subjectInuUse[jobid][customObs] = new Observable(
|
|
1263
|
+
this.subjectInuUse[jobid][customObs] = new Observable(observer => {
|
|
1372
1264
|
// observer.remove(() => {
|
|
1373
1265
|
// });
|
|
1374
1266
|
observer.add(() => {
|
|
@@ -1420,7 +1312,7 @@ class RestRequest {
|
|
|
1420
1312
|
body,
|
|
1421
1313
|
isArray,
|
|
1422
1314
|
method,
|
|
1423
|
-
url
|
|
1315
|
+
url,
|
|
1424
1316
|
});
|
|
1425
1317
|
return resp;
|
|
1426
1318
|
}
|
|
@@ -1443,30 +1335,44 @@ class RestRequest {
|
|
|
1443
1335
|
return this.generalReq('patch', url, body, headers, meta, isArray, mockHttp);
|
|
1444
1336
|
}
|
|
1445
1337
|
jsonp(url, body, headers, meta, isArray, mockHttp) {
|
|
1338
|
+
const method = 'jsonp';
|
|
1339
|
+
if (UtilsOs.isSSRMode) {
|
|
1340
|
+
const emptyStuff = Promise.resolve();
|
|
1341
|
+
emptyStuff.observable = new Observable();
|
|
1342
|
+
emptyStuff.cache = RequestCache.findBy({
|
|
1343
|
+
body,
|
|
1344
|
+
isArray,
|
|
1345
|
+
method,
|
|
1346
|
+
url,
|
|
1347
|
+
});
|
|
1348
|
+
console.warn(`Cannot perform jsonp request in SSR mode`);
|
|
1349
|
+
return emptyStuff;
|
|
1350
|
+
}
|
|
1446
1351
|
const replay = this.getReplay('jsonp', meta, false);
|
|
1447
1352
|
const jobid = replay.id;
|
|
1448
|
-
const method = 'jsonp';
|
|
1449
1353
|
setTimeout(() => {
|
|
1450
1354
|
if (url.endsWith('/'))
|
|
1451
1355
|
url = url.slice(0, url.length - 1);
|
|
1452
1356
|
let num = Math.round(10000 * Math.random());
|
|
1453
|
-
let callbackMethodName =
|
|
1454
|
-
|
|
1357
|
+
let callbackMethodName = 'cb_' + num;
|
|
1358
|
+
let win = globalThis; // TODO not a good idea! @LAST
|
|
1359
|
+
win[callbackMethodName] = data => {
|
|
1455
1360
|
if (this.checkCache({
|
|
1456
1361
|
url,
|
|
1457
1362
|
body,
|
|
1458
1363
|
isArray,
|
|
1459
|
-
method
|
|
1364
|
+
method,
|
|
1460
1365
|
}, jobid)) {
|
|
1461
1366
|
return;
|
|
1462
1367
|
}
|
|
1463
1368
|
this.handlerResult({
|
|
1464
1369
|
res: {
|
|
1465
|
-
data,
|
|
1370
|
+
data,
|
|
1371
|
+
isArray,
|
|
1466
1372
|
},
|
|
1467
1373
|
method,
|
|
1468
1374
|
jobid,
|
|
1469
|
-
isArray
|
|
1375
|
+
isArray,
|
|
1470
1376
|
}, {
|
|
1471
1377
|
url,
|
|
1472
1378
|
body,
|
|
@@ -1481,12 +1387,12 @@ class RestRequest {
|
|
|
1481
1387
|
});
|
|
1482
1388
|
const resp = firstValueFrom(replay.subject[customObs]);
|
|
1483
1389
|
resp.observable = replay.subject[customObs];
|
|
1484
|
-
console.log('assiging custom observable');
|
|
1390
|
+
// console.log('assiging custom observable');
|
|
1485
1391
|
resp.cache = RequestCache.findBy({
|
|
1486
1392
|
body,
|
|
1487
1393
|
isArray,
|
|
1488
1394
|
method,
|
|
1489
|
-
url
|
|
1395
|
+
url,
|
|
1490
1396
|
});
|
|
1491
1397
|
return resp;
|
|
1492
1398
|
}
|
|
@@ -1496,8 +1402,9 @@ class RestRequest {
|
|
|
1496
1402
|
console.warn(`Canno replay first ${method} request from ${meta.endpoint}/${meta.path}`);
|
|
1497
1403
|
return;
|
|
1498
1404
|
}
|
|
1499
|
-
|
|
1500
|
-
|
|
1405
|
+
if (replay &&
|
|
1406
|
+
replay.subject &&
|
|
1407
|
+
Array.isArray(replay.subject.observers) &&
|
|
1501
1408
|
replay.subject.observers.length === 0) {
|
|
1502
1409
|
console.warn(`No observators for ${method} request from ${meta.endpoint}/${meta.path}`);
|
|
1503
1410
|
return;
|
|
@@ -1510,7 +1417,144 @@ class RestRequest {
|
|
|
1510
1417
|
}
|
|
1511
1418
|
}
|
|
1512
1419
|
|
|
1513
|
-
const
|
|
1420
|
+
const CONTENT_TYPE = {
|
|
1421
|
+
APPLICATION_JSON: RestHeaders.from({
|
|
1422
|
+
'Content-Type': 'application/json',
|
|
1423
|
+
'Accept': 'application/json'
|
|
1424
|
+
}),
|
|
1425
|
+
APPLICATINO_VND_API_JSON: RestHeaders.from({
|
|
1426
|
+
'Content-Type': 'application/vnd.api+json',
|
|
1427
|
+
'Accept': 'application/vnd.api+json'
|
|
1428
|
+
}),
|
|
1429
|
+
};
|
|
1430
|
+
|
|
1431
|
+
//#endregion
|
|
1432
|
+
class Rest {
|
|
1433
|
+
mock(mock) {
|
|
1434
|
+
if ((typeof mock === 'function') || (typeof mock === 'object')) {
|
|
1435
|
+
this.mockHttp = mock;
|
|
1436
|
+
}
|
|
1437
|
+
else {
|
|
1438
|
+
throw `[ng2-rest]
|
|
1439
|
+
.model(...)
|
|
1440
|
+
.mock( < BAD MOCK DATA > )
|
|
1441
|
+
...
|
|
1442
|
+
`;
|
|
1443
|
+
}
|
|
1444
|
+
return this;
|
|
1445
|
+
}
|
|
1446
|
+
get endpoint() {
|
|
1447
|
+
let e = this.__meta_endpoint;
|
|
1448
|
+
if (this.restQueryParams !== void 0 && this._endpointRest !== void 0
|
|
1449
|
+
&& typeof this._endpointRest === 'string' && this._endpointRest.trim() !== '')
|
|
1450
|
+
e = this._endpointRest;
|
|
1451
|
+
return e;
|
|
1452
|
+
}
|
|
1453
|
+
set __rest_endpoint(endpoint) {
|
|
1454
|
+
this._endpointRest = endpoint;
|
|
1455
|
+
if (endpoint === void 0) {
|
|
1456
|
+
this.restQueryParams = void 0;
|
|
1457
|
+
}
|
|
1458
|
+
else {
|
|
1459
|
+
this.restQueryParams = getRestParams(endpoint, this.__meta_endpoint);
|
|
1460
|
+
}
|
|
1461
|
+
}
|
|
1462
|
+
creatUrl(params, doNotSerializeParams = false) {
|
|
1463
|
+
return `${this.endpoint}${getParamsUrl(params, doNotSerializeParams)}`;
|
|
1464
|
+
}
|
|
1465
|
+
get headers() {
|
|
1466
|
+
return this._headers;
|
|
1467
|
+
}
|
|
1468
|
+
constructor(endpoint, request, meta, customContentType) {
|
|
1469
|
+
this.request = request;
|
|
1470
|
+
this.meta = meta;
|
|
1471
|
+
this.customContentType = customContentType;
|
|
1472
|
+
//#endregion
|
|
1473
|
+
//#region constructor
|
|
1474
|
+
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
1475
|
+
//#endregion
|
|
1476
|
+
this.array = {
|
|
1477
|
+
get: (params = void 0, doNotSerializeParams) => {
|
|
1478
|
+
return this.req('get', void 0, params, doNotSerializeParams, true);
|
|
1479
|
+
},
|
|
1480
|
+
head: (params = void 0, doNotSerializeParams) => {
|
|
1481
|
+
return this.req('head', void 0, params, doNotSerializeParams, true);
|
|
1482
|
+
},
|
|
1483
|
+
post: (item, params, doNotSerializeParams) => {
|
|
1484
|
+
return this.req('post', item, params, doNotSerializeParams, true);
|
|
1485
|
+
},
|
|
1486
|
+
put: (item, params, doNotSerializeParams) => {
|
|
1487
|
+
return this.req('put', item, params, doNotSerializeParams, true);
|
|
1488
|
+
},
|
|
1489
|
+
patch: (item, params, doNotSerializeParams) => {
|
|
1490
|
+
return this.req('patch', item, params, doNotSerializeParams, true);
|
|
1491
|
+
},
|
|
1492
|
+
delete: (params, doNotSerializeParams) => {
|
|
1493
|
+
return this.req('delete', void 0, params, doNotSerializeParams, true);
|
|
1494
|
+
},
|
|
1495
|
+
jsonp: (params, doNotSerializeParams) => {
|
|
1496
|
+
return this.req('jsonp', void 0, params, doNotSerializeParams, true);
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
this.__meta_endpoint = endpoint;
|
|
1500
|
+
}
|
|
1501
|
+
//#endregion
|
|
1502
|
+
//#region req
|
|
1503
|
+
req(method, requestBody, params, doNotSerializeParams = false, isArray = false) {
|
|
1504
|
+
const modelUrl = this.creatUrl(params, doNotSerializeParams);
|
|
1505
|
+
const body = (CLASS.getNameFromObject(requestBody) === 'FormData')
|
|
1506
|
+
? requestBody
|
|
1507
|
+
: (requestBody ? JSON.stringify(requestBody) : void 0);
|
|
1508
|
+
// console.log('this.customContentType', this.customContentType)
|
|
1509
|
+
if (this.customContentType) {
|
|
1510
|
+
const customHeaderKeys = this.customContentType.keys();
|
|
1511
|
+
const currentHeaderKeys = this._headers.keys();
|
|
1512
|
+
currentHeaderKeys
|
|
1513
|
+
.filter(key => !customHeaderKeys.includes(key))
|
|
1514
|
+
.forEach(key => {
|
|
1515
|
+
this.customContentType.set(key, this._headers.get(key));
|
|
1516
|
+
});
|
|
1517
|
+
this._headers = this.customContentType;
|
|
1518
|
+
}
|
|
1519
|
+
else {
|
|
1520
|
+
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
1521
|
+
}
|
|
1522
|
+
// console.log("_headers", this.headers)
|
|
1523
|
+
const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
|
|
1524
|
+
this.mockHttp = void 0;
|
|
1525
|
+
return result;
|
|
1526
|
+
}
|
|
1527
|
+
//#endregion
|
|
1528
|
+
//#region http methods
|
|
1529
|
+
//#region replay
|
|
1530
|
+
replay(method) {
|
|
1531
|
+
this.request.replay(method, this.meta);
|
|
1532
|
+
}
|
|
1533
|
+
get(params, doNotSerializeParams = false) {
|
|
1534
|
+
return this.req('get', void 0, params, doNotSerializeParams);
|
|
1535
|
+
}
|
|
1536
|
+
head(params, doNotSerializeParams = false) {
|
|
1537
|
+
return this.req('head', void 0, params, doNotSerializeParams);
|
|
1538
|
+
}
|
|
1539
|
+
post(item, params, doNotSerializeParams = false) {
|
|
1540
|
+
return this.req('post', item, params, doNotSerializeParams);
|
|
1541
|
+
}
|
|
1542
|
+
put(item, params, doNotSerializeParams = false) {
|
|
1543
|
+
return this.req('put', item, params, doNotSerializeParams);
|
|
1544
|
+
}
|
|
1545
|
+
patch(item, params, doNotSerializeParams = false) {
|
|
1546
|
+
return this.req('patch', item, params, doNotSerializeParams);
|
|
1547
|
+
}
|
|
1548
|
+
delete(params, doNotSerializeParams = false) {
|
|
1549
|
+
return this.req('delete', void 0, params, doNotSerializeParams);
|
|
1550
|
+
}
|
|
1551
|
+
jsonp(params, doNotSerializeParams = false) {
|
|
1552
|
+
return this.req('jsonp', void 0, params, doNotSerializeParams);
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
//#endregion
|
|
1557
|
+
// const log = Log.create('resouce-service', Level.__NOTHING);
|
|
1514
1558
|
class Resource {
|
|
1515
1559
|
static { this._listenErrors = new Subject(); }
|
|
1516
1560
|
static { this._listenSuccess = new Subject(); }
|
|
@@ -1522,41 +1566,6 @@ class Resource {
|
|
|
1522
1566
|
}
|
|
1523
1567
|
static { this.enableWarnings = true; }
|
|
1524
1568
|
//#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
1569
|
static initAngularNgZone(zone) {
|
|
1561
1570
|
RestRequest.zone = zone;
|
|
1562
1571
|
}
|
|
@@ -1595,7 +1604,7 @@ class Resource {
|
|
|
1595
1604
|
const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
|
|
1596
1605
|
const matchArr = model.match(badRestRegEX) || [];
|
|
1597
1606
|
const badModelsNextToEachOther = matchArr.join();
|
|
1598
|
-
const atleas2DoubleDots = (
|
|
1607
|
+
const atleas2DoubleDots = (badModelsNextToEachOther.match(new RegExp(':', 'g')) || []).length >= 2;
|
|
1599
1608
|
if (atleas2DoubleDots && model.search(badModelsNextToEachOther) !== -1) {
|
|
1600
1609
|
throw new Error(`
|
|
1601
1610
|
|
|
@@ -1605,7 +1614,6 @@ Do not create rest models like this: /book/author/:bookid/:authorid
|
|
|
1605
1614
|
Instead use nested approach: /book/:bookid/author/:authorid
|
|
1606
1615
|
`);
|
|
1607
1616
|
}
|
|
1608
|
-
;
|
|
1609
1617
|
Resource.map(e, e);
|
|
1610
1618
|
Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
|
|
1611
1619
|
// if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
|
|
@@ -1616,7 +1624,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1616
1624
|
},
|
|
1617
1625
|
get headers() {
|
|
1618
1626
|
return Resource.getModel(e, model).headers;
|
|
1619
|
-
}
|
|
1627
|
+
},
|
|
1620
1628
|
};
|
|
1621
1629
|
}
|
|
1622
1630
|
//#endregion
|
|
@@ -1626,20 +1634,12 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1626
1634
|
}
|
|
1627
1635
|
//#endregion
|
|
1628
1636
|
//#region constructor
|
|
1629
|
-
constructor() {
|
|
1630
|
-
setTimeout(() => {
|
|
1631
|
-
const zone = this.getZone();
|
|
1632
|
-
if (!RestRequest.zone) {
|
|
1633
|
-
RestRequest.zone = zone;
|
|
1634
|
-
}
|
|
1635
|
-
;
|
|
1636
|
-
});
|
|
1637
|
-
}
|
|
1637
|
+
constructor() { }
|
|
1638
1638
|
//#endregion
|
|
1639
1639
|
static { this.Cookies = Cookie.Instance; }
|
|
1640
1640
|
//#region map
|
|
1641
1641
|
static map(endpoint, url) {
|
|
1642
|
-
log.i('url', url);
|
|
1642
|
+
// log.i('url', url);
|
|
1643
1643
|
let regex = /(http|https):\/\/(\w+:{0,1}\w*)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%!\-\/]))?/;
|
|
1644
1644
|
let e = endpoint;
|
|
1645
1645
|
if (!regex.test(url)) {
|
|
@@ -1647,26 +1647,29 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1647
1647
|
}
|
|
1648
1648
|
if (url.charAt(url.length - 1) === '/')
|
|
1649
1649
|
url = url.slice(0, url.length - 1);
|
|
1650
|
-
log.i('url after', url);
|
|
1650
|
+
// log.i('url after', url);
|
|
1651
1651
|
if (Resource.endpoints[e] !== void 0) {
|
|
1652
|
-
Helpers$1.log('Cannot use map function at the same API endpoint again ('
|
|
1653
|
-
|
|
1652
|
+
Helpers$1.log('Cannot use map function at the same API endpoint again (' +
|
|
1653
|
+
Resource.endpoints[e].url +
|
|
1654
|
+
')');
|
|
1654
1655
|
return false;
|
|
1655
1656
|
}
|
|
1656
1657
|
Resource.endpoints[e] = {
|
|
1657
1658
|
url: url,
|
|
1658
1659
|
models: {},
|
|
1659
|
-
entity: null
|
|
1660
|
+
entity: null,
|
|
1660
1661
|
};
|
|
1661
|
-
log.i('enpoints', Resource.endpoints);
|
|
1662
|
+
// log.i('enpoints', Resource.endpoints);
|
|
1662
1663
|
return true;
|
|
1663
1664
|
}
|
|
1664
1665
|
//#endregion
|
|
1665
1666
|
static prepareModel(model) {
|
|
1666
|
-
if (model.charAt(model.length - 1) === '/')
|
|
1667
|
+
if (model.charAt(model.length - 1) === '/') {
|
|
1667
1668
|
model = model.slice(0, model.length - 1);
|
|
1668
|
-
|
|
1669
|
+
}
|
|
1670
|
+
if (model.charAt(0) === '/') {
|
|
1669
1671
|
model = model.slice(1, model.length);
|
|
1672
|
+
}
|
|
1670
1673
|
return model;
|
|
1671
1674
|
}
|
|
1672
1675
|
//#region add
|
|
@@ -1678,28 +1681,26 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1678
1681
|
* @returns {boolean}
|
|
1679
1682
|
*/
|
|
1680
1683
|
add(endpoint, model, entity, circular, customContentType) {
|
|
1681
|
-
log.i(`I am maping ${model} on ${endpoint}`);
|
|
1684
|
+
// log.i(`I am maping ${model} on ${<any>endpoint}`);
|
|
1682
1685
|
model = Resource.prepareModel(model);
|
|
1683
1686
|
let e;
|
|
1684
|
-
e =
|
|
1687
|
+
e = endpoint.toString();
|
|
1685
1688
|
if (Resource.endpoints[e] === void 0) {
|
|
1686
1689
|
console.error('Endpoint is not mapped ! Cannot add model ' + model);
|
|
1687
1690
|
return;
|
|
1688
1691
|
}
|
|
1689
1692
|
if (Resource.endpoints[e].models[model] !== void 0) {
|
|
1690
1693
|
if (Resource.enableWarnings)
|
|
1691
|
-
console.warn(`Model '${model}' is already defined in endpoint: `
|
|
1692
|
-
|
|
1694
|
+
console.warn(`Model '${model}' is already defined in endpoint: ` +
|
|
1695
|
+
Resource.endpoints[e].url);
|
|
1693
1696
|
return;
|
|
1694
1697
|
}
|
|
1695
|
-
Resource.endpoints[e].models[model] =
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
circular,
|
|
1702
|
-
}, customContentType); // TODO put custom content type in meta ?
|
|
1698
|
+
Resource.endpoints[e].models[model] = new Rest(Resource.endpoints[e].url + '/' + model, Resource.request, {
|
|
1699
|
+
endpoint: e,
|
|
1700
|
+
path: model,
|
|
1701
|
+
entity,
|
|
1702
|
+
circular,
|
|
1703
|
+
}, customContentType); // TODO put custom content type in meta ?
|
|
1703
1704
|
return;
|
|
1704
1705
|
}
|
|
1705
1706
|
//#endregion
|
|
@@ -1718,7 +1719,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1718
1719
|
// `)
|
|
1719
1720
|
if (model.charAt(0) === '/')
|
|
1720
1721
|
model = model.slice(1, model.length);
|
|
1721
|
-
let e =
|
|
1722
|
+
let e = endpoint.toString();
|
|
1722
1723
|
if (Resource.endpoints[e] === void 0) {
|
|
1723
1724
|
throw `Endpoint: ${endpoint} is not mapped ! Cannot add model: ${model}`;
|
|
1724
1725
|
}
|
|
@@ -1729,13 +1730,13 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1729
1730
|
// log.d('Resource.endpoints', Resource.endpoints);
|
|
1730
1731
|
throw `Model '${model}' is undefined in endpoint: ${Resource.endpoints[e].url} `;
|
|
1731
1732
|
}
|
|
1732
|
-
let res = Resource.endpoints[
|
|
1733
|
+
let res = Resource.endpoints[endpoint.toString()].models[model];
|
|
1733
1734
|
// log.d(`
|
|
1734
1735
|
// orgModel: ${orgModel}
|
|
1735
1736
|
// model: ${model}
|
|
1736
1737
|
// `)
|
|
1737
1738
|
if (orgModel !== model) {
|
|
1738
|
-
let baseUrl = Resource.endpoints[
|
|
1739
|
+
let baseUrl = Resource.endpoints[endpoint.toString()].url;
|
|
1739
1740
|
// log.d('base', Resource.endpoints[<string>(endpoint).toString()])
|
|
1740
1741
|
// log.d('baseUrl', baseUrl)
|
|
1741
1742
|
// log.d('orgModel', orgModel)
|
|
@@ -1744,7 +1745,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1744
1745
|
else {
|
|
1745
1746
|
res.__rest_endpoint = void 0;
|
|
1746
1747
|
}
|
|
1747
|
-
;
|
|
1748
1748
|
// log.i(`Resource.endpoints`, Resource.endpoints)
|
|
1749
1749
|
return res;
|
|
1750
1750
|
}
|