ng2-rest 13.1.12 → 13.2.1

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 (52) hide show
  1. package/app.js +3 -3
  2. package/browser/esm2020/lib/models.mjs +43 -20
  3. package/browser/esm2020/lib/request-cache.mjs +5 -1
  4. package/browser/esm2020/lib/resource.service.mjs +1 -1
  5. package/browser/esm2020/lib/rest-headers.mjs +1 -1
  6. package/browser/esm2020/lib/rest-request.mjs +6 -5
  7. package/browser/esm2020/lib/rest.class.mjs +6 -3
  8. package/browser/fesm2015/ng2-rest.mjs +55 -25
  9. package/browser/fesm2015/ng2-rest.mjs.map +1 -1
  10. package/browser/fesm2020/ng2-rest.mjs +55 -25
  11. package/browser/fesm2020/ng2-rest.mjs.map +1 -1
  12. package/browser/lib/models.d.ts +8 -6
  13. package/browser/lib/request-cache.d.ts +4 -0
  14. package/client/esm2020/lib/models.mjs +43 -20
  15. package/client/esm2020/lib/request-cache.mjs +5 -1
  16. package/client/esm2020/lib/resource.service.mjs +1 -1
  17. package/client/esm2020/lib/rest-headers.mjs +1 -1
  18. package/client/esm2020/lib/rest-request.mjs +6 -5
  19. package/client/esm2020/lib/rest.class.mjs +6 -3
  20. package/client/fesm2015/ng2-rest.mjs +55 -25
  21. package/client/fesm2015/ng2-rest.mjs.map +1 -1
  22. package/client/fesm2020/ng2-rest.mjs +55 -25
  23. package/client/fesm2020/ng2-rest.mjs.map +1 -1
  24. package/client/lib/models.d.ts +8 -6
  25. package/client/lib/request-cache.d.ts +4 -0
  26. package/lib/models.d.ts +8 -6
  27. package/lib/models.js +49 -23
  28. package/lib/models.js.map +1 -1
  29. package/lib/request-cache.d.ts +4 -0
  30. package/lib/request-cache.js +4 -0
  31. package/lib/request-cache.js.map +1 -1
  32. package/lib/resource.service.js.map +1 -1
  33. package/lib/rest-headers.js +8 -0
  34. package/lib/rest-headers.js.map +1 -1
  35. package/lib/rest-request.js +10 -6
  36. package/lib/rest-request.js.map +1 -1
  37. package/lib/rest.class.js +6 -2
  38. package/lib/rest.class.js.map +1 -1
  39. package/package.json +5 -5
  40. package/tmp-environment.json +39 -34
  41. package/websql/esm2020/lib/models.mjs +43 -20
  42. package/websql/esm2020/lib/request-cache.mjs +5 -1
  43. package/websql/esm2020/lib/resource.service.mjs +1 -1
  44. package/websql/esm2020/lib/rest-headers.mjs +1 -1
  45. package/websql/esm2020/lib/rest-request.mjs +6 -5
  46. package/websql/esm2020/lib/rest.class.mjs +6 -3
  47. package/websql/fesm2015/ng2-rest.mjs +55 -25
  48. package/websql/fesm2015/ng2-rest.mjs.map +1 -1
  49. package/websql/fesm2020/ng2-rest.mjs +55 -25
  50. package/websql/fesm2020/ng2-rest.mjs.map +1 -1
  51. package/websql/lib/models.d.ts +8 -6
  52. package/websql/lib/request-cache.d.ts +4 -0
@@ -756,9 +756,11 @@ class Rest {
756
756
  get headers() {
757
757
  return this._headers;
758
758
  }
759
- req(method, item, params, doNotSerializeParams = false, isArray = false) {
759
+ req(method, requestBody, params, doNotSerializeParams = false, isArray = false) {
760
760
  const modelUrl = this.creatUrl(params, doNotSerializeParams);
761
- const body = item ? JSON.stringify(item) : void 0;
761
+ const body = (CLASS.getNameFromObject(requestBody) === 'FormData')
762
+ ? requestBody
763
+ : (requestBody ? JSON.stringify(requestBody) : void 0);
762
764
  if (this.customContentType) {
763
765
  const customHeaderKeys = this.customContentType.keys();
764
766
  const currentHeaderKeys = this._headers.keys();
@@ -834,6 +836,10 @@ class Cookie {
834
836
  ({}); // @--end-of-file-for-module=ng2-rest lib/cookie.ts
835
837
 
836
838
  const log$2 = Log.create('request-cache', Level.__NOTHING);
839
+ /**
840
+ * @deprecated
841
+ * there is Cache API for that
842
+ */
837
843
  class RequestCache {
838
844
  constructor(response) {
839
845
  this.response = response;
@@ -951,39 +957,50 @@ var Models;
951
957
  }
952
958
  Models.BaseBody = BaseBody;
953
959
  class HttpBody extends BaseBody {
954
- constructor(body, isArray = false, entity, circular) {
960
+ constructor(responseText, isArray = false, entity, circular) {
955
961
  super();
956
- this.body = body;
962
+ this.responseText = responseText;
957
963
  this.isArray = isArray;
958
964
  this.entity = entity;
959
965
  this.circular = circular;
960
966
  }
967
+ get blob() {
968
+ return this.responseText;
969
+ }
961
970
  get booleanValue() {
962
- return ['ok', 'true'].includes(this.body.trim());
971
+ if (!isBlob(this.responseText)) {
972
+ return ['ok', 'true'].includes(this.responseText.trim());
973
+ }
963
974
  }
964
975
  get rawJson() {
965
- let res = this.toJSON(this.body, this.isArray);
966
- if (this.circular && Array.isArray(this.circular)) {
967
- res = JSON10.parse(JSON.stringify(res), this.circular);
976
+ if (!isBlob(this.responseText)) {
977
+ let res = this.toJSON(this.responseText, this.isArray);
978
+ if (this.circular && Array.isArray(this.circular)) {
979
+ res = JSON10.parse(JSON.stringify(res), this.circular);
980
+ }
981
+ return res;
968
982
  }
969
- return res;
970
983
  }
971
984
  get json() {
972
- if (this.entity && typeof this.entity === 'function') {
973
- return this.entity(); // @LAST
974
- }
975
- if (this.entity && typeof this.entity === 'object') {
976
- const json = this.toJSON(this.body, this.isArray);
977
- return Mapping.encode(json, this.entity, this.circular);
978
- }
979
- let res = this.toJSON(this.body, this.isArray);
980
- if (this.circular && Array.isArray(this.circular)) {
981
- res = JSON10.parse(JSON.stringify(res), this.circular);
985
+ if (!isBlob(this.responseText)) {
986
+ if (this.entity && typeof this.entity === 'function') {
987
+ return this.entity(); // @LAST
988
+ }
989
+ if (this.entity && typeof this.entity === 'object') {
990
+ const json = this.toJSON(this.responseText, this.isArray);
991
+ return Mapping.encode(json, this.entity, this.circular);
992
+ }
993
+ let res = this.toJSON(this.responseText, this.isArray);
994
+ if (this.circular && Array.isArray(this.circular)) {
995
+ res = JSON10.parse(JSON.stringify(res), this.circular);
996
+ }
997
+ return res;
982
998
  }
983
- return res;
984
999
  }
985
1000
  get text() {
986
- return this.body.replace(/^\"/, '').replace(/\"$/, '');
1001
+ if (!isBlob(this.responseText)) {
1002
+ return this.responseText.replace(/^\"/, '').replace(/\"$/, '');
1003
+ }
987
1004
  }
988
1005
  }
989
1006
  Models.HttpBody = HttpBody;
@@ -1058,7 +1075,19 @@ var Models;
1058
1075
  }
1059
1076
  }
1060
1077
  Models.HttpResponseError = HttpResponseError;
1078
+ /* */
1079
+ /* */
1080
+ /* */
1081
+ /* */
1082
+ /* */
1083
+ /* */
1061
1084
  })(Models || (Models = {}));
1085
+ function isBlob(maybeBlob) {
1086
+ if (typeof Blob === 'undefined') { // OK because there is no Blob in node
1087
+ return false;
1088
+ }
1089
+ return maybeBlob instanceof Blob; // || toString.call(maybeBlob) === '[object Blob]';
1090
+ }
1062
1091
  ;
1063
1092
  ({}); // @--end-of-file-for-module=ng2-rest lib/models.ts
1064
1093
 
@@ -1100,7 +1129,6 @@ class RestRequest {
1100
1129
  checkCache(sourceRequest, jobid) {
1101
1130
  const existedInCache = RequestCache.findBy(sourceRequest);
1102
1131
  if (existedInCache) {
1103
- log$1.i('cache exists', existedInCache);
1104
1132
  const success = Resource['_listenSuccess'];
1105
1133
  success.next(existedInCache.response);
1106
1134
  this.subjectInuUse[jobid].next(existedInCache);
@@ -1143,14 +1171,16 @@ class RestRequest {
1143
1171
  };
1144
1172
  }
1145
1173
  }
1174
+ const headersJson = headers.toJSON();
1175
+ const responseType = headersJson.responsetypeaxios ? headersJson.responsetypeaxios : 'text';
1146
1176
  try {
1147
1177
  if (!response) {
1148
1178
  response = await axios({
1149
1179
  url,
1150
1180
  method,
1151
1181
  data: body,
1152
- responseType: 'text',
1153
- headers: headers.toJSON(),
1182
+ responseType,
1183
+ headers: headersJson,
1154
1184
  cancelToken: source.token,
1155
1185
  });
1156
1186
  }
@@ -1160,7 +1190,7 @@ class RestRequest {
1160
1190
  this.handlerResult({
1161
1191
  res: {
1162
1192
  code: response.status,
1163
- data: JSON.stringify(response.data),
1193
+ data: response.data,
1164
1194
  isArray,
1165
1195
  jobid,
1166
1196
  headers: RestHeaders.from(response.headers)