ng2-rest 13.0.19 → 13.0.20

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.
Files changed (45) hide show
  1. package/browser/esm2020/lib/content-type.mjs +12 -0
  2. package/browser/esm2020/lib/index.mjs +2 -1
  3. package/browser/esm2020/lib/models.mjs +1 -1
  4. package/browser/esm2020/lib/resource.service.mjs +6 -11
  5. package/browser/esm2020/lib/rest-request.mjs +2 -1
  6. package/browser/esm2020/lib/rest.class.mjs +11 -8
  7. package/browser/fesm2015/ng2-rest.mjs +27 -17
  8. package/browser/fesm2015/ng2-rest.mjs.map +1 -1
  9. package/browser/fesm2020/ng2-rest.mjs +27 -17
  10. package/browser/fesm2020/ng2-rest.mjs.map +1 -1
  11. package/browser/lib/content-type.d.ts +5 -0
  12. package/browser/lib/index.d.ts +1 -0
  13. package/browser/lib/resource.service.d.ts +1 -2
  14. package/browser/lib/rest.class.d.ts +2 -5
  15. package/client/esm2020/lib/content-type.mjs +12 -0
  16. package/client/esm2020/lib/index.mjs +2 -1
  17. package/client/esm2020/lib/models.mjs +1 -1
  18. package/client/esm2020/lib/resource.service.mjs +6 -11
  19. package/client/esm2020/lib/rest-request.mjs +2 -1
  20. package/client/esm2020/lib/rest.class.mjs +11 -8
  21. package/client/fesm2015/ng2-rest.mjs +27 -17
  22. package/client/fesm2015/ng2-rest.mjs.map +1 -1
  23. package/client/fesm2020/ng2-rest.mjs +27 -17
  24. package/client/fesm2020/ng2-rest.mjs.map +1 -1
  25. package/client/lib/content-type.d.ts +5 -0
  26. package/client/lib/index.d.ts +1 -0
  27. package/client/lib/resource.service.d.ts +1 -2
  28. package/client/lib/rest.class.d.ts +2 -5
  29. package/lib/content-type.d.ts +5 -0
  30. package/lib/content-type.js +15 -0
  31. package/lib/content-type.js.map +1 -0
  32. package/lib/index.d.ts +1 -0
  33. package/lib/index.js +1 -0
  34. package/lib/index.js.map +1 -1
  35. package/lib/models.js.map +1 -1
  36. package/lib/resource.service.d.ts +1 -2
  37. package/lib/resource.service.js +5 -10
  38. package/lib/resource.service.js.map +1 -1
  39. package/lib/rest-request.js +1 -0
  40. package/lib/rest-request.js.map +1 -1
  41. package/lib/rest.class.d.ts +2 -5
  42. package/lib/rest.class.js +11 -8
  43. package/lib/rest.class.js.map +1 -1
  44. package/package.json +4 -4
  45. package/tmp-environment.json +27 -26
@@ -723,18 +723,26 @@ class RestHeaders {
723
723
  }
724
724
  }
725
725
 
726
- //#endregion
727
- const DEFAULT_HEADERS = {
728
- 'Content-Type': 'application/json',
729
- 'Accept': 'application/json'
726
+ const CONTENT_TYPE = {
727
+ APPLICATION_JSON: RestHeaders.from({
728
+ 'Content-Type': 'application/json',
729
+ 'Accept': 'application/json'
730
+ }),
731
+ APPLICATINO_VND_API_JSON: RestHeaders.from({
732
+ 'Content-Type': 'application/vnd.api+json',
733
+ 'Accept': 'application/vnd.api+json'
734
+ }),
730
735
  };
736
+
737
+ //#endregion
731
738
  class Rest {
732
- constructor(endpoint, request, meta) {
739
+ constructor(endpoint, request, meta, customContentType) {
733
740
  this.request = request;
734
741
  this.meta = meta;
742
+ this.customContentType = customContentType;
735
743
  //#endregion
736
744
  //#region constructor
737
- this._headers = RestHeaders.from(DEFAULT_HEADERS);
745
+ this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
738
746
  //#endregion
739
747
  this.array = {
740
748
  get: (params = void 0, doNotSerializeParams) => {
@@ -801,8 +809,13 @@ class Rest {
801
809
  req(method, item, params, doNotSerializeParams = false, isArray = false) {
802
810
  const modelUrl = this.creatUrl(params, doNotSerializeParams);
803
811
  const body = item ? JSON.stringify(item) : void 0;
812
+ if (this.customContentType) {
813
+ this._headers = this.customContentType;
814
+ }
815
+ else {
816
+ this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
817
+ }
804
818
  const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
805
- this._headers = RestHeaders.from(DEFAULT_HEADERS);
806
819
  this.mockHttp = void 0;
807
820
  return result;
808
821
  }
@@ -1187,6 +1200,7 @@ class RestRequest {
1187
1200
  responseType: 'text',
1188
1201
  headers: headers.toJSON(),
1189
1202
  cancelToken: source.token,
1203
+ // withCredentials: true, // this can be done manually
1190
1204
  });
1191
1205
  // log.d(`after response of jobid: ${jobid}`);
1192
1206
  }
@@ -1518,7 +1532,7 @@ class Resource {
1518
1532
  }
1519
1533
  //#endregion
1520
1534
  //#region create
1521
- static create(e, model, entityMapping, circular) {
1535
+ static create(e, model, entityMapping, circular, customContentType) {
1522
1536
  const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
1523
1537
  const matchArr = model.match(badRestRegEX) || [];
1524
1538
  const badModelsNextToEachOther = matchArr.join();
@@ -1534,7 +1548,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1534
1548
  }
1535
1549
  ;
1536
1550
  Resource.map(e, e);
1537
- Resource.instance.add(e, model ? model : '', entityMapping, circular);
1551
+ Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
1538
1552
  // if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
1539
1553
  return {
1540
1554
  model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
@@ -1591,7 +1605,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1591
1605
  * @param {string} model
1592
1606
  * @returns {boolean}
1593
1607
  */
1594
- add(endpoint, model, entity, circular) {
1608
+ add(endpoint, model, entity, circular, customContentType) {
1595
1609
  log.i(`I am maping ${model} on ${endpoint}`);
1596
1610
  model = Resource.prepareModel(model);
1597
1611
  let e;
@@ -1612,8 +1626,8 @@ Instead use nested approach: /book/:bookid/author/:authorid
1612
1626
  endpoint: e,
1613
1627
  path: model,
1614
1628
  entity,
1615
- circular
1616
- });
1629
+ circular,
1630
+ }, customContentType); // TODO put custom content type in meta ?
1617
1631
  return;
1618
1632
  }
1619
1633
  //#endregion
@@ -1663,10 +1677,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
1663
1677
  return res;
1664
1678
  }
1665
1679
  }
1666
- Resource.DEFAULT_HEADERS = RestHeaders.from({
1667
- 'Content-Type': 'application/json',
1668
- 'Accept': 'application/json'
1669
- });
1670
1680
  Resource._listenErrors = new Subject();
1671
1681
  Resource._listenSuccess = new Subject();
1672
1682
  Resource.enableWarnings = true;
@@ -1803,5 +1813,5 @@ SimpleResource._isSetQueryParamsSerialization = false;
1803
1813
  * Generated bundle index. Do not edit.
1804
1814
  */
1805
1815
 
1806
- export { DEFAULT_HEADERS, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
1816
+ export { CONTENT_TYPE, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
1807
1817
  //# sourceMappingURL=ng2-rest.mjs.map