@koine/api 1.1.9 → 1.1.10
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 +2 -1
- package/createSwrApi.js +2 -2
- package/node/createApi.js +4 -3
- package/node/createSwrApi.js +3 -3
- package/package.json +1 -4
package/createApi.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
-
import
|
|
2
|
+
import buildUrlQueryString from "@koine/utils/buildUrlQueryString";
|
|
3
|
+
import isFullObject from "@koine/utils/isFullObject";
|
|
3
4
|
/**
|
|
4
5
|
* Create api client
|
|
5
6
|
*
|
package/createSwrApi.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
-
import
|
|
2
|
+
import isFunction from "@koine/utils/isFunction";
|
|
3
3
|
import useSWR from "swr";
|
|
4
4
|
import useSWRMutation from "swr/mutation";
|
|
5
|
-
import
|
|
5
|
+
import createApi from "./createApi";
|
|
6
6
|
function createUseApi(api, method) {
|
|
7
7
|
return function useApi(endpoint, options, _config) {
|
|
8
8
|
var _this = this;
|
package/node/createApi.js
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createApi = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var
|
|
5
|
+
var buildUrlQueryString_1 = require("@koine/utils/buildUrlQueryString");
|
|
6
|
+
var isFullObject_1 = require("@koine/utils/isFullObject");
|
|
6
7
|
/**
|
|
7
8
|
* Create api client
|
|
8
9
|
*
|
|
@@ -44,7 +45,7 @@ var createApi = function (apiName, baseUrl, options) {
|
|
|
44
45
|
params = transformed[3];
|
|
45
46
|
requestInit = transformed[4];
|
|
46
47
|
}
|
|
47
|
-
if ((0,
|
|
48
|
+
if ((0, isFullObject_1.default)(params)) {
|
|
48
49
|
for (key in params) {
|
|
49
50
|
url = url.replace("{".concat(key, "}"), params[key].toString());
|
|
50
51
|
}
|
|
@@ -60,7 +61,7 @@ var createApi = function (apiName, baseUrl, options) {
|
|
|
60
61
|
}
|
|
61
62
|
if (query) {
|
|
62
63
|
// FIXME: ts-expect-error this assertion is not the best, but nevermind for now
|
|
63
|
-
url += (0,
|
|
64
|
+
url += (0, buildUrlQueryString_1.default)(query);
|
|
64
65
|
}
|
|
65
66
|
response = null;
|
|
66
67
|
result = null;
|
package/node/createSwrApi.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.createSwrApi = void 0;
|
|
4
4
|
var tslib_1 = require("tslib");
|
|
5
|
-
var
|
|
5
|
+
var isFunction_1 = require("@koine/utils/isFunction");
|
|
6
6
|
var swr_1 = require("swr");
|
|
7
7
|
var mutation_1 = require("swr/mutation");
|
|
8
8
|
var createApi_1 = require("./createApi");
|
|
@@ -38,7 +38,7 @@ function createUseApi(api, method) {
|
|
|
38
38
|
}); };
|
|
39
39
|
var config_1 = _config;
|
|
40
40
|
var shouldNotFetch = (config_1 === null || config_1 === void 0 ? void 0 : config_1.when) === false ||
|
|
41
|
-
((0,
|
|
41
|
+
((0, isFunction_1.default)(config_1 === null || config_1 === void 0 ? void 0 : config_1.when) && (config_1 === null || config_1 === void 0 ? void 0 : config_1.when()) === false);
|
|
42
42
|
// <Data = any, Error = any>(key: Key, config: SWRConfigurationExtended<Data, Error, Fetcher<Data>> | undefined): SWRResponse<Data, Error>;
|
|
43
43
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
44
44
|
return (0, swr_1.default)(shouldNotFetch ? null : options ? [endpoint, options] : [endpoint], fetcher, config_1);
|
|
@@ -79,7 +79,7 @@ var createSwrApi = function () {
|
|
|
79
79
|
for (var _i = 0; _i < arguments.length; _i++) {
|
|
80
80
|
args[_i] = arguments[_i];
|
|
81
81
|
}
|
|
82
|
-
var api = createApi_1.
|
|
82
|
+
var api = createApi_1.default.apply(void 0, args);
|
|
83
83
|
["get", "post", "put", "patch", "delete"].forEach(function (method) {
|
|
84
84
|
var hookName = "use".concat(method.charAt(0).toUpperCase() + method.slice(1));
|
|
85
85
|
api[hookName] = createUseApi(api, method);
|
package/package.json
CHANGED
|
@@ -10,13 +10,10 @@
|
|
|
10
10
|
"types": "./index.d.ts",
|
|
11
11
|
"dependencies": {},
|
|
12
12
|
"peerDependencies": {
|
|
13
|
-
"@koine/utils": "1.1.9",
|
|
14
|
-
"ts-debounce": "4.0.0",
|
|
15
|
-
"type-fest": "3.5.3",
|
|
16
13
|
"swr": "2.0.3",
|
|
17
14
|
"next": "13.1.6",
|
|
18
15
|
"tslib": "2.5.0"
|
|
19
16
|
},
|
|
20
|
-
"version": "1.1.
|
|
17
|
+
"version": "1.1.10",
|
|
21
18
|
"module": "./index.js"
|
|
22
19
|
}
|