@koine/api 1.0.13 → 1.0.16

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 CHANGED
@@ -1,5 +1 @@
1
- # @koine/utils
2
-
3
- ## Code
4
-
5
- - Transformative functions like `truncate` or `titleCase` should allow for nullable inputs as much as possible, acceptin both `undefined` and `null`.
1
+ # @koine/api
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];
@@ -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
@@ -1,16 +1,16 @@
1
1
  {
2
2
  "name": "@koine/api",
3
- "version": "1.0.13",
4
3
  "sideEffects": false,
5
4
  "main": "./node/index.js",
6
5
  "typings": "./index.d.ts",
7
6
  "dependencies": {
7
+ "@koine/utils": "1.0.16",
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.16",
14
14
  "module": "./index.js",
15
15
  "types": "./index.d.ts"
16
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,51 +112,39 @@ 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 = { [TMethod in Uppercase<RequestMethod>]?: DataTypes };
115
+ type EndpointShape = {
116
+ [TMethod in Uppercase<RequestMethod>]?: DataTypes<TMethod>;
117
+ };
116
118
 
117
- type Endpoints = readonly Record<string, Endpoint>;
119
+ type Endpoints = Record<string, Endpoint>;
118
120
  type Endpoint = {
119
121
  [TMethod in Uppercase<RequestMethod>]?: DataTypes<TMethod>;
120
122
  };
121
123
 
122
- type EndpointUrl<TEndpoints extends Endpoints> = Extract<keyof TEndpoints, string>;
124
+ type EndpointUrl<TEndpoints extends Endpoints> = Extract<
125
+ keyof TEndpoints,
126
+ string
127
+ >;
123
128
 
124
- type DataTypes<TMethod extends Uppercase<RequestMethod>> =
125
- TMethod extends "GET"
126
- ? {
127
- /**
128
- * The JSON response data returned by the request in case of success
129
- */
130
- response?: null | unknown;
131
- /**
132
- * The parameters to encode in the URL of the request
133
- */
134
- params?: RequestParams;
135
- /**
136
- * The shape of the error data returned by the request in case of
137
- * failure
138
- */
139
- error?: null | unknown;
140
- }
141
- : {
142
- /**
143
- * The request body of a non-GET request
144
- */
145
- request?: null | unknown;
146
- /**
147
- * The JSON response data returned by the request in case of success
148
- */
149
- response?: null | unknown;
150
- /**
151
- * The parameters to encode in the URL of the request
152
- */
153
- params?: RequestParams;
154
- /**
155
- * The shape of the error data returned by the request in case of
156
- * failure
157
- */
158
- error?: null | unknown;
159
- };
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
+ };
160
148
 
161
149
  //////////////////////////////////////////////////////////////////////////////
162
150
  //
@@ -164,6 +152,8 @@ declare namespace Koine.Api {
164
152
  //
165
153
  //////////////////////////////////////////////////////////////////////////////
166
154
 
155
+ type RequestJson = undefined | null | Record<string | number, unknown>;
156
+
167
157
  type RequestParams = undefined | null | Record<string | number, unknown>;
168
158
 
169
159
  /**
@@ -279,10 +269,10 @@ declare namespace Koine.Api {
279
269
 
280
270
  type ResponseAdapter = <
281
271
  Succesfull extends DataSuccesfull = DataSuccesfull,
282
- Failed extends DataFailed = DataFailed
272
+ Failed extends DataFailed = DataFailed,
283
273
  >(
284
274
  response: _Response,
285
- options: RequestOptions
275
+ options: TOptions
286
276
  ) => Promise<Koine.Api.Response<Succesfull, Failed>>;
287
277
 
288
278
  //////////////////////////////////////////////////////////////////////////////
@@ -298,9 +288,9 @@ declare namespace Koine.Api {
298
288
  * These hooks are implemented with different libraries or, in the future as
299
289
  * standalone hooks, see SWR ones to start with.
300
290
  */
301
- type HooksMaps = readonly {
291
+ type HooksMaps = {
302
292
  [TMethod in RequestMethod]: `use${Capitalize<TMethod>}`;
303
293
  };
304
294
 
305
- type HooksMapsByName = readonly { [K in keyof HooksMaps as HooksMaps[K]]: K };
295
+ type HooksMapsByName = { [K in keyof HooksMaps as HooksMaps[K]]: K };
306
296
  }