ng2-rest 13.0.19 → 13.0.22
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 -18
- package/browser/fesm2015/ng2-rest.mjs.map +1 -1
- package/browser/fesm2020/ng2-rest.mjs +37 -18
- 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 -18
- package/client/fesm2015/ng2-rest.mjs.map +1 -1
- package/client/fesm2020/ng2-rest.mjs +37 -18
- 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 +27 -26
|
@@ -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
|
}
|
|
@@ -1515,7 +1538,7 @@ class Resource {
|
|
|
1515
1538
|
}
|
|
1516
1539
|
//#endregion
|
|
1517
1540
|
//#region create
|
|
1518
|
-
static create(e, model, entityMapping, circular) {
|
|
1541
|
+
static create(e, model, entityMapping, circular, customContentType) {
|
|
1519
1542
|
const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
|
|
1520
1543
|
const matchArr = model.match(badRestRegEX) || [];
|
|
1521
1544
|
const badModelsNextToEachOther = matchArr.join();
|
|
@@ -1531,7 +1554,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1531
1554
|
}
|
|
1532
1555
|
;
|
|
1533
1556
|
Resource.map(e, e);
|
|
1534
|
-
Resource.instance.add(e, model ? model : '', entityMapping, circular);
|
|
1557
|
+
Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
|
|
1535
1558
|
// if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
|
|
1536
1559
|
return {
|
|
1537
1560
|
model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
|
|
@@ -1588,7 +1611,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1588
1611
|
* @param {string} model
|
|
1589
1612
|
* @returns {boolean}
|
|
1590
1613
|
*/
|
|
1591
|
-
add(endpoint, model, entity, circular) {
|
|
1614
|
+
add(endpoint, model, entity, circular, customContentType) {
|
|
1592
1615
|
log.i(`I am maping ${model} on ${endpoint}`);
|
|
1593
1616
|
model = Resource.prepareModel(model);
|
|
1594
1617
|
let e;
|
|
@@ -1609,8 +1632,8 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1609
1632
|
endpoint: e,
|
|
1610
1633
|
path: model,
|
|
1611
1634
|
entity,
|
|
1612
|
-
circular
|
|
1613
|
-
});
|
|
1635
|
+
circular,
|
|
1636
|
+
}, customContentType); // TODO put custom content type in meta ?
|
|
1614
1637
|
return;
|
|
1615
1638
|
}
|
|
1616
1639
|
//#endregion
|
|
@@ -1660,10 +1683,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
|
|
|
1660
1683
|
return res;
|
|
1661
1684
|
}
|
|
1662
1685
|
}
|
|
1663
|
-
Resource.DEFAULT_HEADERS = RestHeaders.from({
|
|
1664
|
-
'Content-Type': 'application/json',
|
|
1665
|
-
'Accept': 'application/json'
|
|
1666
|
-
});
|
|
1667
1686
|
Resource._listenErrors = new Subject();
|
|
1668
1687
|
Resource._listenSuccess = new Subject();
|
|
1669
1688
|
Resource.enableWarnings = true;
|
|
@@ -1800,5 +1819,5 @@ SimpleResource._isSetQueryParamsSerialization = false;
|
|
|
1800
1819
|
* Generated bundle index. Do not edit.
|
|
1801
1820
|
*/
|
|
1802
1821
|
|
|
1803
|
-
export {
|
|
1822
|
+
export { CONTENT_TYPE, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
|
|
1804
1823
|
//# sourceMappingURL=ng2-rest.mjs.map
|