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.
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 +4 -2
  6. package/browser/esm2020/lib/rest.class.mjs +19 -8
  7. package/browser/fesm2015/ng2-rest.mjs +37 -21
  8. package/browser/fesm2015/ng2-rest.mjs.map +1 -1
  9. package/browser/fesm2020/ng2-rest.mjs +37 -21
  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 +4 -2
  20. package/client/esm2020/lib/rest.class.mjs +19 -8
  21. package/client/fesm2015/ng2-rest.mjs +37 -21
  22. package/client/fesm2015/ng2-rest.mjs.map +1 -1
  23. package/client/fesm2020/ng2-rest.mjs +37 -21
  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 +3 -1
  40. package/lib/rest-request.js.map +1 -1
  41. package/lib/rest.class.d.ts +2 -5
  42. package/lib/rest.class.js +20 -8
  43. package/lib/rest.class.js.map +1 -1
  44. package/package.json +4 -4
  45. package/tmp-environment.json +38 -35
@@ -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,21 @@ 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
+ // console.log('this.customContentType', this.customContentType)
813
+ if (this.customContentType) {
814
+ const customHeaderKeys = this.customContentType.keys();
815
+ const currentHeaderKeys = this._headers.keys();
816
+ currentHeaderKeys
817
+ .filter(key => !customHeaderKeys.includes(key))
818
+ .forEach(key => {
819
+ this.customContentType.set(key, this._headers.get(key));
820
+ });
821
+ this._headers = this.customContentType;
822
+ }
823
+ else {
824
+ this._headers = RestHeaders.from(CONTENT_TYPE.APPLICATION_JSON);
825
+ }
804
826
  const result = this.request[method.toLowerCase()](modelUrl, body, this.headers, this.meta, isArray, this.mockHttp);
805
- this._headers = RestHeaders.from(DEFAULT_HEADERS);
806
827
  this.mockHttp = void 0;
807
828
  return result;
808
829
  }
@@ -1179,7 +1200,8 @@ class RestRequest {
1179
1200
  }
1180
1201
  try {
1181
1202
  if (!response) {
1182
- log$1.d(`[${method}] (jobid=${jobid}) request to: ${url}`);
1203
+ // console.log(`[${method}] (jobid=${jobid}) request to: ${url}`);
1204
+ // console.log(headers.toJSON())
1183
1205
  response = yield axios({
1184
1206
  url,
1185
1207
  method,
@@ -1187,6 +1209,7 @@ class RestRequest {
1187
1209
  responseType: 'text',
1188
1210
  headers: headers.toJSON(),
1189
1211
  cancelToken: source.token,
1212
+ // withCredentials: true, // this can be done manually
1190
1213
  });
1191
1214
  // log.d(`after response of jobid: ${jobid}`);
1192
1215
  }
@@ -1300,9 +1323,6 @@ class RestRequest {
1300
1323
  this.subjectInuUse[jobid][cancelFn]('[ng2-rest] on purpose canceled http request');
1301
1324
  }
1302
1325
  }
1303
- else {
1304
- // console.log(`somehow second time cancel ${jobid}`)
1305
- }
1306
1326
  });
1307
1327
  const sub = subject.subscribe({
1308
1328
  next: a => observer.next(a),
@@ -1518,7 +1538,7 @@ class Resource {
1518
1538
  }
1519
1539
  //#endregion
1520
1540
  //#region create
1521
- static create(e, model, entityMapping, circular) {
1541
+ static create(e, model, entityMapping, circular, customContentType) {
1522
1542
  const badRestRegEX = new RegExp('((\/:)[a-z]+)+', 'g');
1523
1543
  const matchArr = model.match(badRestRegEX) || [];
1524
1544
  const badModelsNextToEachOther = matchArr.join();
@@ -1534,7 +1554,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1534
1554
  }
1535
1555
  ;
1536
1556
  Resource.map(e, e);
1537
- Resource.instance.add(e, model ? model : '', entityMapping, circular);
1557
+ Resource.instance.add(e, model ? model : '', entityMapping, circular, customContentType);
1538
1558
  // if (model.charAt(model.length - 1) !== '/') model = `${model}/`;
1539
1559
  return {
1540
1560
  model: (params) => Resource.instance.api(e, interpolateParamsToUrl(params, model)),
@@ -1591,7 +1611,7 @@ Instead use nested approach: /book/:bookid/author/:authorid
1591
1611
  * @param {string} model
1592
1612
  * @returns {boolean}
1593
1613
  */
1594
- add(endpoint, model, entity, circular) {
1614
+ add(endpoint, model, entity, circular, customContentType) {
1595
1615
  log.i(`I am maping ${model} on ${endpoint}`);
1596
1616
  model = Resource.prepareModel(model);
1597
1617
  let e;
@@ -1612,8 +1632,8 @@ Instead use nested approach: /book/:bookid/author/:authorid
1612
1632
  endpoint: e,
1613
1633
  path: model,
1614
1634
  entity,
1615
- circular
1616
- });
1635
+ circular,
1636
+ }, customContentType); // TODO put custom content type in meta ?
1617
1637
  return;
1618
1638
  }
1619
1639
  //#endregion
@@ -1663,10 +1683,6 @@ Instead use nested approach: /book/:bookid/author/:authorid
1663
1683
  return res;
1664
1684
  }
1665
1685
  }
1666
- Resource.DEFAULT_HEADERS = RestHeaders.from({
1667
- 'Content-Type': 'application/json',
1668
- 'Accept': 'application/json'
1669
- });
1670
1686
  Resource._listenErrors = new Subject();
1671
1687
  Resource._listenSuccess = new Subject();
1672
1688
  Resource.enableWarnings = true;
@@ -1803,5 +1819,5 @@ SimpleResource._isSetQueryParamsSerialization = false;
1803
1819
  * Generated bundle index. Do not edit.
1804
1820
  */
1805
1821
 
1806
- export { DEFAULT_HEADERS, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
1822
+ export { CONTENT_TYPE, Helpers, Mapping, Models, RequestCache, Resource, Rest, RestHeaders, SimpleResource, interpolateParamsToUrl };
1807
1823
  //# sourceMappingURL=ng2-rest.mjs.map