@koine/api 1.0.17 → 1.0.18
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/package.json +2 -2
- package/typings.d.ts +92 -0
package/package.json
CHANGED
|
@@ -4,13 +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.18",
|
|
8
8
|
"next": "^12.1.6",
|
|
9
9
|
"swr": "^2.0.0-beta.3",
|
|
10
10
|
"tslib": "^2.4.0"
|
|
11
11
|
},
|
|
12
12
|
"peerDependencies": {},
|
|
13
|
-
"version": "1.0.
|
|
13
|
+
"version": "1.0.18",
|
|
14
14
|
"module": "./index.js",
|
|
15
15
|
"types": "./index.d.ts"
|
|
16
16
|
}
|
package/typings.d.ts
CHANGED
|
@@ -293,4 +293,96 @@ declare namespace Koine.Api {
|
|
|
293
293
|
};
|
|
294
294
|
|
|
295
295
|
type HooksMapsByName = { [K in keyof HooksMaps as HooksMaps[K]]: K };
|
|
296
|
+
|
|
297
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
298
|
+
//
|
|
299
|
+
// Generate shortcuts
|
|
300
|
+
//
|
|
301
|
+
//////////////////////////////////////////////////////////////////////////////
|
|
302
|
+
|
|
303
|
+
/**
|
|
304
|
+
* To generate all available helpers use in your `API` types:
|
|
305
|
+
*
|
|
306
|
+
* ```ts
|
|
307
|
+
* type Response = Koine.Api.GenerateResponseHelpers<Endpoints>;
|
|
308
|
+
* type Request = Koine.Api.GenerateRequestHelpers<Endpoints>;
|
|
309
|
+
* type Get = Koine.Api.GenerateGetHelpers<Endpoints>;
|
|
310
|
+
* type Post = Koine.Api.GeneratePostHelpers<Endpoints>;
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
type Generate = "here just to read the example usage";
|
|
314
|
+
|
|
315
|
+
type _ShortcutsMaps = {
|
|
316
|
+
[TMethod in RequestMethod]: Capitalize<TMethod>;
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
type _ShortcutsMapsByMethod = {
|
|
320
|
+
[K in keyof _ShortcutsMaps as _ShortcutsMaps[K]]: K;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* @example
|
|
325
|
+
* ```ts
|
|
326
|
+
* // define the type on your `API` types:
|
|
327
|
+
* type Response = Koine.Api.GenerateResponseShortcuts<Endpoints>;
|
|
328
|
+
*
|
|
329
|
+
* // consume the type wherever in your app:
|
|
330
|
+
* type MyData = API.Response["get"]["my/endpoint"];
|
|
331
|
+
* ```
|
|
332
|
+
*/
|
|
333
|
+
type GenerateResponseShortcuts<TEndpoints extends Endpoints> = {
|
|
334
|
+
[TMethod in RequestMethod]: {
|
|
335
|
+
[TEndpointUrl in keyof TEndpoints]: TEndpoints[TEndpointUrl][Uppercase<TMethod>]["response"];
|
|
336
|
+
};
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* @example
|
|
341
|
+
* ```ts
|
|
342
|
+
* // define the type on your `API` types:
|
|
343
|
+
* type Get = Koine.Api.GenerateResponseShortcuts<Endpoints>;
|
|
344
|
+
*
|
|
345
|
+
* // consume the type wherever in your app:
|
|
346
|
+
* type MyData = API.Get["my/endpoint"];
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
type GenerateGetShortcuts<TEndpoints extends Endpoints> = {
|
|
350
|
+
[TEndpointUrl in keyof TEndpoints]: TEndpoints[TEndpointUrl]["GET"]["response"];
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* @example
|
|
355
|
+
* ```ts
|
|
356
|
+
* // define the type on your `API` types:
|
|
357
|
+
* type Post = Koine.Api.GenerateResponseShortcuts<Endpoints>;
|
|
358
|
+
*
|
|
359
|
+
* // consume the type wherever in your app:
|
|
360
|
+
* type MyData = API.Post["my/endpoint"];
|
|
361
|
+
* ```
|
|
362
|
+
*/
|
|
363
|
+
type GeneratePostShortcuts<TEndpoints extends Endpoints> = {
|
|
364
|
+
[TEndpointUrl in keyof TEndpoints]: TEndpoints[TEndpointUrl]["POST"]["response"];
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
/**
|
|
368
|
+
* This is not useful as it is the same as doing
|
|
369
|
+
* `API.Endpoints["my/endpoint"]["GET"]["response"];`
|
|
370
|
+
*
|
|
371
|
+
* @example
|
|
372
|
+
* ```ts
|
|
373
|
+
* // define the type on your `API` types:
|
|
374
|
+
* type Response = Koine.Api.GenerateResponseShortcuts<Endpoints>;
|
|
375
|
+
*
|
|
376
|
+
* // consume the type wherever in your app:
|
|
377
|
+
* type MyData = API.$["my/endpoint"]["get"]["response"];
|
|
378
|
+
* ```
|
|
379
|
+
* @deprecated
|
|
380
|
+
*/
|
|
381
|
+
// type GenerateAllShortcuts<TEndpoints extends Endpoints> = {
|
|
382
|
+
// [TEndpointUrl in keyof TEndpoints]: {
|
|
383
|
+
// [TMethod in RequestMethod]: {
|
|
384
|
+
// [DataType in EndpointDataType]: TEndpoints[TEndpointUrl][Uppercase<TMethod>][DataType];
|
|
385
|
+
// }
|
|
386
|
+
// }
|
|
387
|
+
// }
|
|
296
388
|
}
|