ng2-rest 13.0.17 → 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 +38 -35
@@ -722,18 +722,26 @@ class RestHeaders {
722
722
  }
723
723
  }
724
724
 
725
- //#endregion
726
- const DEFAULT_HEADERS = {
727
- 'Content-Type': 'application/json',
728
- 'Accept': 'application/json'
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(DEFAULT_HEADERS);
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,13 @@ 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
+ if (this.customContentType) {
812
+ this._headers = this.customContentType;
813
+ }
814
+ else {
815
+ this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
816
+ }
803
817
  const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
804
- this._headers = RestHeaders.from(DEFAULT_HEADERS);
805
818
  this.mockHttp = void 0;
806
819
  return result;
807
820
  }
@@ -1185,6 +1198,7 @@ class RestRequest {
1185
1198
  responseType: 'text',
1186
1199
  headers: headers.toJSON(),
1187
1200
  cancelToken: source.token,
1201
+ // withCredentials: true, // this can be done manually
1188
1202
  });
1189
1203
  // log.d(`after response of jobid: ${jobid}`);
1190
1204
  }
@@ -1515,7 +1529,7 @@ class Resource {
1515
1529
  }
1516
1530
  //#endregion
1517
1531
  //#region create
1518
- static create(e, model, entityMapping, circular) {
1532
+ static create(e, model, entityMapping, circular, customContentType) {
1519
1533
  const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
1520
1534
  const matchArr = model.match(badRestRegEX) || [];
1521
1535
  const badModelsNextToEachOther = matchArr.join();
@@ -1531,7 +1545,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1531
1545
  }
1532
1546
  ;
1533
1547
  Resource.map(e, e);
1534
- Resource.instance.add(e, model ? model : '', entityMapping, circular);
1548
+ Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
1535
1549
  // if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
1536
1550
  return {
1537
1551
  model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
@@ -1588,7 +1602,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1588
1602
  * @param {string} model
1589
1603
  * @returns {boolean}
1590
1604
  */
1591
- add(endpoint, model, entity, circular) {
1605
+ add(endpoint, model, entity, circular, customContentType) {
1592
1606
  log.i(`I am maping ${model} on ${endpoint}`);
1593
1607
  model = Resource.prepareModel(model);
1594
1608
  let e;
@@ -1609,8 +1623,8 @@ Instead use nested approach: /book/:bookid/author/:authorid
1609
1623
  endpoint: e,
1610
1624
  path: model,
1611
1625
  entity,
1612
- circular
1613
- });
1626
+ circular,
1627
+ }, customContentType); // TODO put custom content type in meta ?
1614
1628
  return;
1615
1629
  }
1616
1630
  //#endregion
@@ -1660,10 +1674,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
1660
1674
  return res;
1661
1675
  }
1662
1676
  }
1663
- Resource.DEFAULT_HEADERS = RestHeaders.from({
1664
- 'Content-Type': 'application/json',
1665
- 'Accept': 'application/json'
1666
- });
1667
1677
  Resource._listenErrors = new Subject();
1668
1678
  Resource._listenSuccess = new Subject();
1669
1679
  Resource.enableWarnings = true;
@@ -1800,5 +1810,5 @@ SimpleResource._isSetQueryParamsSerialization = false;
1800
1810
  * Generated bundle index. Do not edit.
1801
1811
  */
1802
1812
 
1803
- export { DEFAULT_HEADERS, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
1813
+ export { CONTENT_TYPE, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
1804
1814
  //# sourceMappingURL=ng2-rest.mjs.map