@koine/api 1.0.14 → 1.0.17
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/README.md +1 -5
- package/core/index.js +2 -2
- package/node/core/index.js +2 -2
- package/package.json +3 -4
- package/typings.d.ts +30 -43
package/README.md
CHANGED
package/core/index.js
CHANGED
|
@@ -83,7 +83,7 @@ export var createApi = function (apiName, baseUrl, options) {
|
|
|
83
83
|
case 8:
|
|
84
84
|
_f.trys.push([8, 13, , 14]);
|
|
85
85
|
if (!adapter) return [3 /*break*/, 10];
|
|
86
|
-
return [4 /*yield*/, adapter(response, options)];
|
|
86
|
+
return [4 /*yield*/, adapter(response, options || {})];
|
|
87
87
|
case 9:
|
|
88
88
|
result = _f.sent();
|
|
89
89
|
return [3 /*break*/, 12];
|
|
@@ -99,7 +99,7 @@ export var createApi = function (apiName, baseUrl, options) {
|
|
|
99
99
|
case 14: return [3 /*break*/, 19];
|
|
100
100
|
case 15:
|
|
101
101
|
if (!adapter) return [3 /*break*/, 17];
|
|
102
|
-
return [4 /*yield*/, adapter(response, options)];
|
|
102
|
+
return [4 /*yield*/, adapter(response, options || {})];
|
|
103
103
|
case 16:
|
|
104
104
|
result = _f.sent();
|
|
105
105
|
return [3 /*break*/, 19];
|
package/node/core/index.js
CHANGED
|
@@ -86,7 +86,7 @@ var createApi = function (apiName, baseUrl, options) {
|
|
|
86
86
|
case 8:
|
|
87
87
|
_f.trys.push([8, 13, , 14]);
|
|
88
88
|
if (!adapter) return [3 /*break*/, 10];
|
|
89
|
-
return [4 /*yield*/, adapter(response, options)];
|
|
89
|
+
return [4 /*yield*/, adapter(response, options || {})];
|
|
90
90
|
case 9:
|
|
91
91
|
result = _f.sent();
|
|
92
92
|
return [3 /*break*/, 12];
|
|
@@ -102,7 +102,7 @@ var createApi = function (apiName, baseUrl, options) {
|
|
|
102
102
|
case 14: return [3 /*break*/, 19];
|
|
103
103
|
case 15:
|
|
104
104
|
if (!adapter) return [3 /*break*/, 17];
|
|
105
|
-
return [4 /*yield*/, adapter(response, options)];
|
|
105
|
+
return [4 /*yield*/, adapter(response, options || {})];
|
|
106
106
|
case 16:
|
|
107
107
|
result = _f.sent();
|
|
108
108
|
return [3 /*break*/, 19];
|
package/package.json
CHANGED
|
@@ -4,14 +4,13 @@
|
|
|
4
4
|
"main": "./node/index.js",
|
|
5
5
|
"typings": "./index.d.ts",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@koine/utils": "1.0.
|
|
7
|
+
"@koine/utils": "1.0.17",
|
|
8
8
|
"next": "^12.1.6",
|
|
9
9
|
"swr": "^2.0.0-beta.3",
|
|
10
|
-
"type-fest": "^2.13.0",
|
|
11
10
|
"tslib": "^2.4.0"
|
|
12
11
|
},
|
|
13
12
|
"peerDependencies": {},
|
|
13
|
+
"version": "1.0.17",
|
|
14
14
|
"module": "./index.js",
|
|
15
|
-
"types": "./index.d.ts"
|
|
16
|
-
"version": "1.0.14"
|
|
15
|
+
"types": "./index.d.ts"
|
|
17
16
|
}
|
package/typings.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ type _Response = Response;
|
|
|
4
4
|
|
|
5
5
|
declare namespace Koine.Api {
|
|
6
6
|
// @see https://stackoverflow.com/a/60702896/1938970
|
|
7
|
-
import { Exact } from "type-fest";
|
|
7
|
+
// import { Exact } from "type-fest";
|
|
8
8
|
|
|
9
9
|
//////////////////////////////////////////////////////////////////////////////
|
|
10
10
|
//
|
|
@@ -48,7 +48,7 @@ declare namespace Koine.Api {
|
|
|
48
48
|
/**
|
|
49
49
|
* The `api` interface generated by `createApi`
|
|
50
50
|
*/
|
|
51
|
-
type Client<TEndpoints> = {
|
|
51
|
+
type Client<TEndpoints extends Endpoints> = {
|
|
52
52
|
[TMethod in RequestMethod]: ClientMethod<TMethod, TEndpoints>;
|
|
53
53
|
};
|
|
54
54
|
|
|
@@ -112,9 +112,11 @@ declare namespace Koine.Api {
|
|
|
112
112
|
// T : "Endpoint must follow `Koine.Api.Endpoint` shape" : never;
|
|
113
113
|
type DefineEndpoint<T extends EndpointShape> = T;
|
|
114
114
|
type DefineEndpoints<T extends Endpoints> = {};
|
|
115
|
-
type EndpointShape = {
|
|
115
|
+
type EndpointShape = {
|
|
116
|
+
[TMethod in Uppercase<RequestMethod>]?: DataTypes<TMethod>;
|
|
117
|
+
};
|
|
116
118
|
|
|
117
|
-
type Endpoints =
|
|
119
|
+
type Endpoints = Record<string, Endpoint>;
|
|
118
120
|
type Endpoint = {
|
|
119
121
|
[TMethod in Uppercase<RequestMethod>]?: DataTypes<TMethod>;
|
|
120
122
|
};
|
|
@@ -124,42 +126,25 @@ declare namespace Koine.Api {
|
|
|
124
126
|
string
|
|
125
127
|
>;
|
|
126
128
|
|
|
127
|
-
type DataTypes<TMethod extends Uppercase<RequestMethod>> =
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
* The request body of a non-GET request
|
|
147
|
-
*/
|
|
148
|
-
request?: null | unknown;
|
|
149
|
-
/**
|
|
150
|
-
* The JSON response data returned by the request in case of success
|
|
151
|
-
*/
|
|
152
|
-
response?: null | unknown;
|
|
153
|
-
/**
|
|
154
|
-
* The parameters to encode in the URL of the request
|
|
155
|
-
*/
|
|
156
|
-
params?: RequestParams;
|
|
157
|
-
/**
|
|
158
|
-
* The shape of the error data returned by the request in case of
|
|
159
|
-
* failure
|
|
160
|
-
*/
|
|
161
|
-
error?: null | unknown;
|
|
162
|
-
};
|
|
129
|
+
type DataTypes<TMethod extends Uppercase<RequestMethod>> = {
|
|
130
|
+
/**
|
|
131
|
+
* The request body of a non-GET request
|
|
132
|
+
*/
|
|
133
|
+
request?: RequestJson;
|
|
134
|
+
/**
|
|
135
|
+
* The JSON response data returned by the request in case of success
|
|
136
|
+
*/
|
|
137
|
+
response?: null | unknown;
|
|
138
|
+
/**
|
|
139
|
+
* The parameters to encode in the URL of the request
|
|
140
|
+
*/
|
|
141
|
+
params?: RequestParams;
|
|
142
|
+
/**
|
|
143
|
+
* The shape of the error data returned by the request in case of
|
|
144
|
+
* failure
|
|
145
|
+
*/
|
|
146
|
+
error?: null | unknown;
|
|
147
|
+
};
|
|
163
148
|
|
|
164
149
|
//////////////////////////////////////////////////////////////////////////////
|
|
165
150
|
//
|
|
@@ -167,6 +152,8 @@ declare namespace Koine.Api {
|
|
|
167
152
|
//
|
|
168
153
|
//////////////////////////////////////////////////////////////////////////////
|
|
169
154
|
|
|
155
|
+
type RequestJson = undefined | null | Record<string | number, unknown>;
|
|
156
|
+
|
|
170
157
|
type RequestParams = undefined | null | Record<string | number, unknown>;
|
|
171
158
|
|
|
172
159
|
/**
|
|
@@ -285,7 +272,7 @@ declare namespace Koine.Api {
|
|
|
285
272
|
Failed extends DataFailed = DataFailed
|
|
286
273
|
>(
|
|
287
274
|
response: _Response,
|
|
288
|
-
options:
|
|
275
|
+
options: TOptions
|
|
289
276
|
) => Promise<Koine.Api.Response<Succesfull, Failed>>;
|
|
290
277
|
|
|
291
278
|
//////////////////////////////////////////////////////////////////////////////
|
|
@@ -301,9 +288,9 @@ declare namespace Koine.Api {
|
|
|
301
288
|
* These hooks are implemented with different libraries or, in the future as
|
|
302
289
|
* standalone hooks, see SWR ones to start with.
|
|
303
290
|
*/
|
|
304
|
-
type HooksMaps =
|
|
291
|
+
type HooksMaps = {
|
|
305
292
|
[TMethod in RequestMethod]: `use${Capitalize<TMethod>}`;
|
|
306
293
|
};
|
|
307
294
|
|
|
308
|
-
type HooksMapsByName =
|
|
295
|
+
type HooksMapsByName = { [K in keyof HooksMaps as HooksMaps[K]]: K };
|
|
309
296
|
}
|