intelicoreact 1.3.74 → 1.3.76

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.
@@ -79,13 +79,16 @@ class RESTAPI extends _ApiBase.default {
79
79
 
80
80
  //? Это НЕ асинхронная ф-я, которая возвращает асинхронный колбэк
81
81
  function getCallback(item, mesageOptions) {
82
+ const {
83
+ getBodyAs
84
+ } = item;
82
85
  const finalIsGetBodyFirst = (() => {
83
86
  if (item.isGetBody) return item.isGetBody && item.isGetBody === "first";
84
87
  return isGetBodyFirst;
85
88
  })();
86
- const checkResponseCallback = finalIsGetBodyFirst ? async (res, mesageOptions) => API_CONTEXT.getResponseBody(await API_CONTEXT.checkResponseCode(res, mesageOptions)) : async (res, mesageOptions) => API_CONTEXT.checkResponseCode(res, mesageOptions);
89
+ const checkResponseCallback = finalIsGetBodyFirst ? async (res, mesageOptions) => API_CONTEXT.getResponseBody(await API_CONTEXT.checkResponseCode(res, mesageOptions), getBodyAs) : async (res, mesageOptions) => API_CONTEXT.checkResponseCode(res, mesageOptions);
87
90
  const callback = item.callback ? async res => item.callback(await checkResponseCallback(res, mesageOptions)) : async res => checkResponseCallback(res, mesageOptions);
88
- return isGetBody && !isGetBodyFirst ? async res => API_CONTEXT.getResponseBody(await callback(res)) : callback;
91
+ return isGetBody && !isGetBodyFirst ? async res => API_CONTEXT.getResponseBody(await callback(res), getBodyAs) : callback;
89
92
  }
90
93
  async function getRequestItem(item, idx) {
91
94
  const {
@@ -17,20 +17,28 @@ class ApiRequestCreators extends _ApiUtils.default {
17
17
  } = settings || {};
18
18
  if ((0, _utils.getIsOnlyAnObject)(requestsCreators)) _utils.addCustomMethods.call(this, requestsCreators, PREFIX_OF_CLASS_UTILS);
19
19
  }
20
+
21
+ //? При типе toJson пользовательский callback на вход получит тело ответа реализованное методом Response.json()
22
+ //? независимо от насторойки isGetBody
20
23
  async createRequest_toJson(props, variant) {
21
24
  return this.splitProperties({
22
25
  ...props,
23
- isGetBody: true,
26
+ isGetBody: false,
24
27
  callback: async res => {
25
28
  var _props$callback, _props$callback2;
26
- const output = await this.getResponseBody(res);
29
+ const output = await this.getResponseBody(res, 'json');
27
30
  return await ((_props$callback = (_props$callback2 = props.callback) === null || _props$callback2 === void 0 ? void 0 : _props$callback2.call(props, output)) !== null && _props$callback !== void 0 ? _props$callback : output);
28
31
  }
29
32
  }, variant);
30
33
  }
34
+
35
+ //? При типе toJsonAdvanced пользовательский callback на вход получит структуру { response, result },
36
+ //? где response - объект Response, result - тело ответа реализованное методом Response.json()
37
+ //? независимо от насторойки isGetBody
31
38
  async createRequest_toJsonAdvanced(props, variant) {
32
39
  return this.splitProperties({
33
40
  ...props,
41
+ isGetBody: false,
34
42
  callback: async res => {
35
43
  var _props$callback3, _props$callback4;
36
44
  const output = {
@@ -41,6 +49,23 @@ class ApiRequestCreators extends _ApiUtils.default {
41
49
  }
42
50
  }, variant);
43
51
  }
52
+
53
+ //? При типе blob пользовательский callback на вход получит тело ответа реализованное методом Response.blob(),
54
+ //? независимо от насторойки isGetBody
55
+ async createRequest_blob(props, variant) {
56
+ return this.splitProperties({
57
+ ...props,
58
+ isGetBody: false,
59
+ callback: async res => {
60
+ var _props$callback5, _props$callback6;
61
+ const output = await this.getResponseBody(await (0, _utils.getResponseClone)(res), 'blob');
62
+ return await ((_props$callback5 = (_props$callback6 = props.callback) === null || _props$callback6 === void 0 ? void 0 : _props$callback6.call(props, output)) !== null && _props$callback5 !== void 0 ? _props$callback5 : output);
63
+ }
64
+ }, variant);
65
+ }
66
+
67
+ //? При типе testBadResponse пользовательский callback на вход получит объект Response в 401-м статусе
68
+ //? независимо независимо вообще ни от чего
44
69
  async createRequest_testBadResponse(props, variant) {
45
70
  return this.splitProperties({
46
71
  ...props,
@@ -57,11 +82,15 @@ class ApiRequestCreators extends _ApiUtils.default {
57
82
  return headers;
58
83
  })()
59
84
  })).then(res => {
60
- var _props$callback5, _props$callback6;
61
- return (_props$callback5 = (_props$callback6 = props.callback) === null || _props$callback6 === void 0 ? void 0 : _props$callback6.call(props, res)) !== null && _props$callback5 !== void 0 ? _props$callback5 : res;
85
+ var _props$callback7, _props$callback8;
86
+ return (_props$callback7 = (_props$callback8 = props.callback) === null || _props$callback8 === void 0 ? void 0 : _props$callback8.call(props, res)) !== null && _props$callback7 !== void 0 ? _props$callback7 : res;
62
87
  })
63
88
  }, variant);
64
89
  }
90
+
91
+ //? По умолчанию пользовательский callback на вход получит
92
+ //? - либо объект Response
93
+ //? - либо тело ответа (в случае isGetBody: 'first') полученное методом getResponseBody (смотри класс ApiUtils)
65
94
  async createRequest_default(props, variant) {
66
95
  return this.splitProperties(props, variant);
67
96
  }
@@ -89,14 +89,22 @@ class ApiUtils extends _Utils.default {
89
89
 
90
90
  //? Планируется, что метод будет использоваться неизменно, однако технически его можно перегрузить на экземпляре
91
91
  //? Метод планировался как асинхронный
92
- async getResponseBody(response) {
93
- var _response$headers$get;
92
+ async getResponseBody(response, getBodyAs) {
94
93
  if (!(response instanceof Response)) return response;
95
- const executor = (_response$headers$get = response.headers.get("content-type")) !== null && _response$headers$get !== void 0 && _response$headers$get.includes("json") ? response.json : response.text;
94
+ const contentType = response.headers.get("content-type");
95
+ const executor = (() => {
96
+ if (typeof getBodyAs === 'string' && getBodyAs in response && typeof response[getBodyAs] === 'function') {
97
+ return response[getBodyAs];
98
+ }
99
+ if (contentType.includes('text/csv')) {
100
+ return response.blob;
101
+ }
102
+ return contentType.includes('json') ? response.json : response.text;
103
+ })();
96
104
 
97
105
  // обработка случаев краша метода json при отсутствии тела ответа
98
106
  try {
99
- return executor.call(response);
107
+ return await executor.call(response);
100
108
  } catch {
101
109
  //? думаю стоит знать места, где ожидалось тело, а бэк его не положил
102
110
  // eslint-disable-next-line no-console
@@ -314,11 +314,26 @@ const downloadFile = async _ref => {
314
314
  downloadEmulation(response.data, name, response.type);
315
315
  };
316
316
  exports.downloadFile = downloadFile;
317
- const compare = function (a, b) {
318
- var _a$sort, _b$sort, _Object$entries$sort, _Object$entries, _Object$entries$sort2, _Object$entries2;
317
+ const compare = function (first, second) {
318
+ var _Object$entries$sort, _Object$entries, _Object$entries$sort2, _Object$entries2;
319
319
  let keys = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
320
- if (Array.isArray(a), Array.isArray(b)) return JSON.stringify(a === null || a === void 0 || (_a$sort = a.sort) === null || _a$sort === void 0 ? void 0 : _a$sort.call(a)) === JSON.stringify(b === null || b === void 0 || (_b$sort = b.sort) === null || _b$sort === void 0 ? void 0 : _b$sort.call(b));else if (Array.isArray(a) || Array.isArray(b)) throw new Error("Different types detected!");
321
- return JSON.stringify((_Object$entries$sort = (_Object$entries = Object.entries(omitKeys(a, keys))).sort) === null || _Object$entries$sort === void 0 ? void 0 : _Object$entries$sort.call(_Object$entries)) === JSON.stringify((_Object$entries$sort2 = (_Object$entries2 = Object.entries(omitKeys(b, keys))).sort) === null || _Object$entries$sort2 === void 0 ? void 0 : _Object$entries$sort2.call(_Object$entries2));
320
+ //? Если типы НЕ равны - не равны априори
321
+ if (typeof first !== typeof second) return false;
322
+ //? Если ответы на вопрос "массив ли?" не равны, то не равны и типы, значит тоже не равны априори
323
+ if (Array.isArray(first) !== Array.isArray(second)) return false;
324
+ //? Если прошли if-ку - типы условно равны, можем оценивать тип лишь одного параметра, это будет справедливо и для второго
325
+
326
+ //? Если примитивы - просто сравниваем. Кейс с null обработан тут.
327
+ if (!(first instanceof Object)) return first === second;
328
+
329
+ //? Исключение для ф-й.
330
+ if (typeof first === 'function') return first.name === second.name;
331
+
332
+ //? Если НЕ приметивы - не важно массив или нет, методы объекта для массива тоже доступны
333
+ //? Получаем структуры для сравнения - массивы массивов, сортируем по ключам
334
+ const structureForComparingOfFirst = (_Object$entries$sort = (_Object$entries = Object.entries(omitKeys(first, keys))).sort) === null || _Object$entries$sort === void 0 ? void 0 : _Object$entries$sort.call(_Object$entries, (a, b) => a[0] > b[0]);
335
+ const structureForComparingOfSecond = (_Object$entries$sort2 = (_Object$entries2 = Object.entries(omitKeys(second, keys))).sort) === null || _Object$entries$sort2 === void 0 ? void 0 : _Object$entries$sort2.call(_Object$entries2, (a, b) => a[0] > b[0]);
336
+ return JSON.stringify(structureForComparingOfFirst) === JSON.stringify(structureForComparingOfSecond);
322
337
  };
323
338
 
324
339
  // Set Carret to the End of Input
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "intelicoreact",
3
- "version": "1.3.74",
3
+ "version": "1.3.76",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "files": [