@koine/api 1.0.64 → 1.0.67

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.
package/createApi.js CHANGED
@@ -13,15 +13,15 @@ export var createApi = function (apiName, baseUrl, options) {
13
13
  // mode: "cors",
14
14
  // redirect: "follow",
15
15
  // cache: "no-cache",
16
- } : _c, throwErrBase = _a.throwErr, _d = _a.timeout, timeoutBase = _d === void 0 ? 10000 : _d, processReqBase = _a.processReq, processOkBase = _a.processOk, processFailBase = _a.processFail;
16
+ } : _c, throwErrBase = _a.throwErr, _d = _a.timeout, timeoutBase = _d === void 0 ? 10000 : _d, processReqBase = _a.processReq, processResBase = _a.processRes, processErrBase = _a.processErr;
17
17
  return ["get", "post", "put", "patch", "delete"].reduce(function (api, method) {
18
18
  // @ts-expect-error FIXME: type
19
19
  api[method] = function (endpoint, options) { return __awaiter(void 0, void 0, void 0, function () {
20
- var _a, _b, request, _c, headers, _d, timeout, processReq, _e, processOk, _f, processFail, _g, throwErr, _h, params, json, query, url, requestInit, transformed, transformed, key, timeoutNumber, controller, timeoutId, response, result, msg, e_1, e_2, logMsg;
20
+ var _a, _b, request, _c, headers, _d, timeout, processReq, _e, processRes, _f, processErr, _g, throwErr, _h, params, json, query, url, requestInit, transformed, transformed, key, timeoutNumber, controller, timeoutId, response, result, msg, e_1, e_2, logMsg;
21
21
  return __generator(this, function (_j) {
22
22
  switch (_j.label) {
23
23
  case 0:
24
- _a = options || {}, _b = _a.request, request = _b === void 0 ? requestBase : _b, _c = _a.headers, headers = _c === void 0 ? headersBase : _c, _d = _a.timeout, timeout = _d === void 0 ? timeoutBase : _d, processReq = _a.processReq, _e = _a.processOk, processOk = _e === void 0 ? processOkBase : _e, _f = _a.processFail, processFail = _f === void 0 ? processFailBase : _f, _g = _a.throwErr, throwErr = _g === void 0 ? throwErrBase : _g;
24
+ _a = options || {}, _b = _a.request, request = _b === void 0 ? requestBase : _b, _c = _a.headers, headers = _c === void 0 ? headersBase : _c, _d = _a.timeout, timeout = _d === void 0 ? timeoutBase : _d, processReq = _a.processReq, _e = _a.processRes, processRes = _e === void 0 ? processResBase : _e, _f = _a.processErr, processErr = _f === void 0 ? processErrBase : _f, _g = _a.throwErr, throwErr = _g === void 0 ? throwErrBase : _g;
25
25
  _h = options || {}, params = _h.params, json = _h.json, query = _h.query;
26
26
  url = "".concat(baseUrl, "/").concat(endpoint + "".replace(/^\/*/, ""));
27
27
  requestInit = __assign(__assign({ method: method.toUpperCase() }, request), { headers: __assign({ "content-type": "application/json" }, headers) });
@@ -81,8 +81,8 @@ export var createApi = function (apiName, baseUrl, options) {
81
81
  _j.label = 5;
82
82
  case 5:
83
83
  _j.trys.push([5, 10, , 11]);
84
- if (!processOk) return [3 /*break*/, 7];
85
- return [4 /*yield*/, processOk(response, options || {})];
84
+ if (!processRes) return [3 /*break*/, 7];
85
+ return [4 /*yield*/, processRes(response, options || {})];
86
86
  case 6:
87
87
  result = _j.sent();
88
88
  return [3 /*break*/, 9];
@@ -97,8 +97,8 @@ export var createApi = function (apiName, baseUrl, options) {
97
97
  return [3 /*break*/, 11];
98
98
  case 11:
99
99
  if (!(result === null)) return [3 /*break*/, 14];
100
- if (!processFail) return [3 /*break*/, 13];
101
- return [4 /*yield*/, processFail(msg, options || {})];
100
+ if (!processErr) return [3 /*break*/, 13];
101
+ return [4 /*yield*/, processErr(msg, options || {})];
102
102
  case 12:
103
103
  result = _j.sent();
104
104
  return [3 /*break*/, 14];
package/node/createApi.js CHANGED
@@ -16,15 +16,15 @@ var createApi = function (apiName, baseUrl, options) {
16
16
  // mode: "cors",
17
17
  // redirect: "follow",
18
18
  // cache: "no-cache",
19
- } : _c, throwErrBase = _a.throwErr, _d = _a.timeout, timeoutBase = _d === void 0 ? 10000 : _d, processReqBase = _a.processReq, processOkBase = _a.processOk, processFailBase = _a.processFail;
19
+ } : _c, throwErrBase = _a.throwErr, _d = _a.timeout, timeoutBase = _d === void 0 ? 10000 : _d, processReqBase = _a.processReq, processResBase = _a.processRes, processErrBase = _a.processErr;
20
20
  return ["get", "post", "put", "patch", "delete"].reduce(function (api, method) {
21
21
  // @ts-expect-error FIXME: type
22
22
  api[method] = function (endpoint, options) { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
23
- var _a, _b, request, _c, headers, _d, timeout, processReq, _e, processOk, _f, processFail, _g, throwErr, _h, params, json, query, url, requestInit, transformed, transformed, key, timeoutNumber, controller, timeoutId, response, result, msg, e_1, e_2, logMsg;
23
+ var _a, _b, request, _c, headers, _d, timeout, processReq, _e, processRes, _f, processErr, _g, throwErr, _h, params, json, query, url, requestInit, transformed, transformed, key, timeoutNumber, controller, timeoutId, response, result, msg, e_1, e_2, logMsg;
24
24
  return tslib_1.__generator(this, function (_j) {
25
25
  switch (_j.label) {
26
26
  case 0:
27
- _a = options || {}, _b = _a.request, request = _b === void 0 ? requestBase : _b, _c = _a.headers, headers = _c === void 0 ? headersBase : _c, _d = _a.timeout, timeout = _d === void 0 ? timeoutBase : _d, processReq = _a.processReq, _e = _a.processOk, processOk = _e === void 0 ? processOkBase : _e, _f = _a.processFail, processFail = _f === void 0 ? processFailBase : _f, _g = _a.throwErr, throwErr = _g === void 0 ? throwErrBase : _g;
27
+ _a = options || {}, _b = _a.request, request = _b === void 0 ? requestBase : _b, _c = _a.headers, headers = _c === void 0 ? headersBase : _c, _d = _a.timeout, timeout = _d === void 0 ? timeoutBase : _d, processReq = _a.processReq, _e = _a.processRes, processRes = _e === void 0 ? processResBase : _e, _f = _a.processErr, processErr = _f === void 0 ? processErrBase : _f, _g = _a.throwErr, throwErr = _g === void 0 ? throwErrBase : _g;
28
28
  _h = options || {}, params = _h.params, json = _h.json, query = _h.query;
29
29
  url = "".concat(baseUrl, "/").concat(endpoint + "".replace(/^\/*/, ""));
30
30
  requestInit = tslib_1.__assign(tslib_1.__assign({ method: method.toUpperCase() }, request), { headers: tslib_1.__assign({ "content-type": "application/json" }, headers) });
@@ -84,8 +84,8 @@ var createApi = function (apiName, baseUrl, options) {
84
84
  _j.label = 5;
85
85
  case 5:
86
86
  _j.trys.push([5, 10, , 11]);
87
- if (!processOk) return [3 /*break*/, 7];
88
- return [4 /*yield*/, processOk(response, options || {})];
87
+ if (!processRes) return [3 /*break*/, 7];
88
+ return [4 /*yield*/, processRes(response, options || {})];
89
89
  case 6:
90
90
  result = _j.sent();
91
91
  return [3 /*break*/, 9];
@@ -100,8 +100,8 @@ var createApi = function (apiName, baseUrl, options) {
100
100
  return [3 /*break*/, 11];
101
101
  case 11:
102
102
  if (!(result === null)) return [3 /*break*/, 14];
103
- if (!processFail) return [3 /*break*/, 13];
104
- return [4 /*yield*/, processFail(msg, options || {})];
103
+ if (!processErr) return [3 /*break*/, 13];
104
+ return [4 /*yield*/, processErr(msg, options || {})];
105
105
  case 12:
106
106
  result = _j.sent();
107
107
  return [3 /*break*/, 14];
package/package.json CHANGED
@@ -5,12 +5,12 @@
5
5
  "typings": "./index.d.ts",
6
6
  "dependencies": {},
7
7
  "peerDependencies": {
8
- "@koine/utils": "1.0.64",
8
+ "@koine/utils": "1.0.67",
9
9
  "swr": "^2.0.0-beta.6",
10
10
  "next": "^12.2.3",
11
11
  "tslib": "^2.4.0"
12
12
  },
13
- "version": "1.0.64",
13
+ "version": "1.0.67",
14
14
  "module": "./index.js",
15
15
  "types": "./index.d.ts"
16
16
  }
package/typings.d.ts CHANGED
@@ -69,17 +69,18 @@ declare namespace Koine.Api {
69
69
  */
70
70
  processReq?: RequestProcessor;
71
71
  /**
72
- * Process ok response just after http response
72
+ * Process ok/failed response just after http response
73
73
  *
74
74
  * @default undefined
75
75
  */
76
- processOk?: ResponseProcessorOk;
76
+ processRes?: ResponseProcessorRes;
77
77
  /**
78
- * Process failed response just after http response
78
+ * Process maybe-thrown error originated either from `fetch` function
79
+ * invokation or from its `response.json()` parsing
79
80
  *
80
81
  * @default undefined
81
82
  */
82
- processFail?: ResponseProcessorFail;
83
+ processErr?: ResponseProcessorErr;
83
84
  };
84
85
 
85
86
  type ClientMethod<
@@ -379,19 +380,19 @@ declare namespace Koine.Api {
379
380
  ];
380
381
 
381
382
  /**
382
- * The ok response processor at the request level, this is meant to apply
383
+ * The ok/fail response processor at the request level, this is meant to apply
383
384
  * transformations to a single or all endpoint responses
384
385
  */
385
- type ResponseProcessorOk = <TResponseOk extends ResponseOk = ResponseOk>(
386
+ type ResponseProcessorRes = <TResponseOk extends ResponseOk = ResponseOk>(
386
387
  response: _Response,
387
388
  options: TOptions
388
389
  ) => Promise<Koine.Api.Result<TResponseOk>>;
389
390
 
390
391
  /**
391
- * The fail response processor at the request level, this is meant to apply
392
+ * The error response processor at the request level, this is meant to apply
392
393
  * transformations to a single or all endpoint responses
393
394
  */
394
- type ResponseProcessorFail = <
395
+ type ResponseProcessorErr = <
395
396
  TResponseFail extends ResponseFailed = ResponseFailed
396
397
  >(
397
398
  msg: string,