ng2-rest 13.0.18 → 13.0.21
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/esm2020/lib/content-type.mjs +12 -0
- package/browser/esm2020/lib/index.mjs +2 -1
- package/browser/esm2020/lib/models.mjs +1 -1
- package/browser/esm2020/lib/resource.service.mjs +6 -11
- package/browser/esm2020/lib/rest-request.mjs +4 -2
- package/browser/esm2020/lib/rest.class.mjs +19 -8
- package/browser/fesm2015/ng2-rest.mjs +37 -21
- package/browser/fesm2015/ng2-rest.mjs.map +1 -1
- package/browser/fesm2020/ng2-rest.mjs +37 -21
- package/browser/fesm2020/ng2-rest.mjs.map +1 -1
- package/browser/lib/content-type.d.ts +5 -0
- package/browser/lib/index.d.ts +1 -0
- package/browser/lib/resource.service.d.ts +1 -2
- package/browser/lib/rest.class.d.ts +2 -5
- package/client/esm2020/lib/content-type.mjs +12 -0
- package/client/esm2020/lib/index.mjs +2 -1
- package/client/esm2020/lib/models.mjs +1 -1
- package/client/esm2020/lib/resource.service.mjs +6 -11
- package/client/esm2020/lib/rest-request.mjs +4 -2
- package/client/esm2020/lib/rest.class.mjs +19 -8
- package/client/fesm2015/ng2-rest.mjs +37 -21
- package/client/fesm2015/ng2-rest.mjs.map +1 -1
- package/client/fesm2020/ng2-rest.mjs +37 -21
- package/client/fesm2020/ng2-rest.mjs.map +1 -1
- package/client/lib/content-type.d.ts +5 -0
- package/client/lib/index.d.ts +1 -0
- package/client/lib/resource.service.d.ts +1 -2
- package/client/lib/rest.class.d.ts +2 -5
- package/lib/content-type.d.ts +5 -0
- package/lib/content-type.js +15 -0
- package/lib/content-type.js.map +1 -0
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/models.js.map +1 -1
- package/lib/resource.service.d.ts +1 -2
- package/lib/resource.service.js +5 -10
- package/lib/resource.service.js.map +1 -1
- package/lib/rest-request.js +3 -1
- package/lib/rest-request.js.map +1 -1
- package/lib/rest.class.d.ts +2 -5
- package/lib/rest.class.js +20 -8
- package/lib/rest.class.js.map +1 -1
- package/package.json +4 -4
- package/tmp-environment.json +38 -35
|
@@ -722,18 +722,26 @@ class RestHeaders {
|
|
|
722
722
|
}
|
|
723
723
|
}
|
|
724
724
|
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
725
|
+
const CONTENT_TYPE = {
|
|
726
|
+
APPLICATION_JSON: RestHeaders.from({
|
|
727
|
+
'Content-Type': 'application/json',
|
|
728
|
+
'Accept': 'application/json'
|
|
729
|
+
}),
|
|
730
|
+
APPLICATINO_VND_API_JSON: RestHeaders.from({
|
|
731
|
+
'Content-Type': 'application/vnd.api+json',
|
|
732
|
+
'Accept': 'application/vnd.api+json'
|
|
733
|
+
}),
|
|
729
734
|
};
|
|
735
|
+
|
|
736
|
+
//#endregion
|
|
730
737
|
class Rest {
|
|
731
|
-
constructor(endpoint, request, meta) {
|
|
738
|
+
constructor(endpoint, request, meta, customContentType) {
|
|
732
739
|
this.request = request;
|
|
733
740
|
this.meta = meta;
|
|
741
|
+
this.customContentType = customContentType;
|
|
734
742
|
//#endregion
|
|
735
743
|
//#region constructor
|
|
736
|
-
this._headers = RestHeaders.from(
|
|
744
|
+
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
737
745
|
//#endregion
|
|
738
746
|
this.array = {
|
|
739
747
|
get: (params = void 0, doNotSerializeParams) => {
|
|
@@ -800,8 +808,21 @@ class Rest {
|
|
|
800
808
|
req(method, item, params, doNotSerializeParams = false, isArray = false) {
|
|
801
809
|
const modelUrl = this.creatUrl(params, doNotSerializeParams);
|
|
802
810
|
const body = item ? JSON.stringify(item) : void 0;
|
|
811
|
+
// console.log('this.customContentType', this.customContentType)
|
|
812
|
+
if (this.customContentType) {
|
|
813
|
+
const customHeaderKeys = this.customContentType.keys();
|
|
814
|
+
const currentHeaderKeys = this._headers.keys();
|
|
815
|
+
currentHeaderKeys
|
|
816
|
+
.filter(key => !customHeaderKeys.includes(key))
|
|
817
|
+
.forEach(key => {
|
|
818
|
+
this.customContentType.set(key, this._headers.get(key));
|
|
819
|
+
});
|
|
820
|
+
this._headers = this.customContentType;
|
|
821
|
+
}
|
|
822
|
+
else {
|
|
823
|
+
this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
|
|
824
|
+
}
|
|
803
825
|
const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
|
|
804
|
-
this._headers = RestHeaders.from(DEFAULT_HEADERS);
|
|
805
826
|
this.mockHttp = void 0;
|
|
806
827
|
return result;
|
|
807
828
|
}
|
|
@@ -1177,7 +1198,8 @@ class RestRequest {
|
|
|
1177
1198
|
}
|
|
1178
1199
|
try {
|
|
1179
1200
|
if (!response) {
|
|
1180
|
-
log
|
|
1201
|
+
// console.log(`[${method}] (jobid=${jobid}) request to: ${url}`);
|
|
1202
|
+
// console.log(headers.toJSON())
|
|
1181
1203
|
response = await axios({
|
|
1182
1204
|
url,
|
|
1183
1205
|
method,
|
|
@@ -1185,6 +1207,7 @@ class RestRequest {
|
|
|
1185
1207
|
responseType: 'text',
|
|
1186
1208
|
headers: headers.toJSON(),
|
|
1187
1209
|
cancelToken: source.token,
|
|
1210
|
+
// withCredentials: true, // this can be done manually
|
|
1188
1211
|
});
|
|
1189
1212
|
// log.d(`after response of jobid: ${jobid}`);
|
|
1190
1213
|
}
|
|
@@ -1297,9 +1320,6 @@ class RestRequest {
|
|
|
1297
1320
|
this.subjectInuUse[jobid][cancelFn]('[ng2-rest] on purpose canceled http request');
|
|
1298
1321
|
}
|
|
1299
1322
|
}
|
|
1300
|
-
else {
|
|
1301
|
-
// console.log(`somehow second time cancel ${jobid}`)
|
|
1302
|
-
}
|
|
1303
1323
|
});
|
|
1304
1324
|
const sub = subject.subscribe({
|
|
1305
1325
|
next: a => observer.next(a),
|
|
@@ -1515,7 +1535,7 @@ class Resource {
|
|
|
1515
1535
|
}
|
|
1516
1536
|
//#endregion
|
|
1517
1537
|
//#region create
|
|
1518
|
-
static create(e, model, entityMapping, circular) {
|
|
1538
|
+
static create(e, model, entityMapping, circular, customContentType) {
|
|
1519
1539
|
const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
|
|
1520
1540
|
const matchArr = model.match(badRestRegEX) || [];
|
|
1521
1541
|
const badModelsNextToEachOther = matchArr.join();
|
|
@@ -1531,7 +1551,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1531
1551
|
}
|
|
1532
1552
|
;
|
|
1533
1553
|
Resource.map(e, e);
|
|
1534
|
-
Resource.instance.add(e, model ? model : '', entityMapping, circular);
|
|
1554
|
+
Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
|
|
1535
1555
|
// if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
|
|
1536
1556
|
return {
|
|
1537
1557
|
model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
|
|
@@ -1588,7 +1608,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1588
1608
|
* @param {string} model
|
|
1589
1609
|
* @returns {boolean}
|
|
1590
1610
|
*/
|
|
1591
|
-
add(endpoint, model, entity, circular) {
|
|
1611
|
+
add(endpoint, model, entity, circular, customContentType) {
|
|
1592
1612
|
log.i(`I am maping ${model} on ${endpoint}`);
|
|
1593
1613
|
model = Resource.prepareModel(model);
|
|
1594
1614
|
let e;
|
|
@@ -1609,8 +1629,8 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1609
1629
|
endpoint: e,
|
|
1610
1630
|
path: model,
|
|
1611
1631
|
entity,
|
|
1612
|
-
circular
|
|
1613
|
-
});
|
|
1632
|
+
circular,
|
|
1633
|
+
}, customContentType); // TODO put custom content type in meta ?
|
|
1614
1634
|
return;
|
|
1615
1635
|
}
|
|
1616
1636
|
//#endregion
|
|
@@ -1660,10 +1680,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1660
1680
|
return res;
|
|
1661
1681
|
}
|
|
1662
1682
|
}
|
|
1663
|
-
Resource.DEFAULT_HEADERS = RestHeaders.from({
|
|
1664
|
-
'Content-Type': 'application/json',
|
|
1665
|
-
'Accept': 'application/json'
|
|
1666
|
-
});
|
|
1667
1683
|
Resource._listenErrors = new Subject();
|
|
1668
1684
|
Resource._listenSuccess = new Subject();
|
|
1669
1685
|
Resource.enableWarnings = true;
|
|
@@ -1800,5 +1816,5 @@ SimpleResource._isSetQueryParamsSerialization = false;
|
|
|
1800
1816
|
* Generated bundle index. Do not edit.
|
|
1801
1817
|
*/
|
|
1802
1818
|
|
|
1803
|
-
export {
|
|
1819
|
+
export { CONTENT_TYPE, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
|
|
1804
1820
|
//# sourceMappingURL=ng2-rest.mjs.map
|