@koine/api 1.0.105 → 1.1.0

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/createSwrApi.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { type SWRConfiguration, type SWRResponse, type BareFetcher } from "swr";
2
2
  import { type SWRMutationConfiguration, type SWRMutationResponse } from "swr/mutation";
3
- declare type SWRConfigurationExtended<Data = any, Error = any, Fn extends BareFetcher<any> = BareFetcher<any>> = SWRConfiguration<Data, Error, Fn> & {
3
+ type SWRConfigurationExtended<Data = any, Error = any, Fn extends BareFetcher<any> = BareFetcher<any>> = SWRConfiguration<Data, Error, Fn> & {
4
4
  /**
5
5
  * Conditional fetching as option
6
6
  *
@@ -19,7 +19,7 @@ declare type SWRConfigurationExtended<Data = any, Error = any, Fn extends BareFe
19
19
  */
20
20
  when?: boolean | (() => boolean);
21
21
  };
22
- declare type KoineApiMethodHookSWR<THookName extends keyof Koine.Api.HooksMapsByName, TEndpoints extends Koine.Api.Endpoints> = <TEndpoint extends Koine.Api.EndpointUrl<TEndpoints>, TMethod extends Koine.Api.RequestMethod = Koine.Api.HooksMapsByName[THookName]>(endpoint: TEndpoint, options?: Koine.Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, config?: THookName extends "useGet" ? SWRConfigurationExtended<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>> : SWRMutationConfiguration<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, TEndpoint>) => THookName extends "useGet" ? SWRResponse<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>> : SWRMutationResponse<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, TEndpoint>;
22
+ type KoineApiMethodHookSWR<THookName extends keyof Koine.Api.HooksMapsByName, TEndpoints extends Koine.Api.Endpoints> = <TEndpoint extends Koine.Api.EndpointUrl<TEndpoints>, TMethod extends Koine.Api.RequestMethod = Koine.Api.HooksMapsByName[THookName]>(endpoint: TEndpoint, options?: Koine.Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, config?: THookName extends "useGet" ? SWRConfigurationExtended<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>> : SWRMutationConfiguration<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, TEndpoint>) => THookName extends "useGet" ? SWRResponse<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>> : SWRMutationResponse<Koine.Api.EndpointResponseOk<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointResponseFail<TEndpoints, TEndpoint, TMethod>, Koine.Api.EndpointOptions<TEndpoints, TEndpoint, TMethod>, TEndpoint>;
23
23
  /**
24
24
  * It creates an api client extended with auto-generated SWR wrapper hooks
25
25
  */
package/package.json CHANGED
@@ -2,16 +2,14 @@
2
2
  "name": "@koine/api",
3
3
  "sideEffects": false,
4
4
  "main": "./node/index.js",
5
- "typings": "./index.d.ts",
6
- "dependencies": {
7
- "@koine/utils": "1.0.105",
8
- "ts-debounce": "^4.0.0",
9
- "swr": "^2.0.0-beta.6",
10
- "next": "^12.3.1",
11
- "tslib": "^2.4.0"
5
+ "types": "./index.d.ts",
6
+ "dependencies": {},
7
+ "peerDependencies": {
8
+ "ts-debounce": "4.0.0",
9
+ "type-fest": "3.5.3",
10
+ "next": "13.1.6",
11
+ "tslib": "2.5.0"
12
12
  },
13
- "peerDependencies": {},
14
- "version": "1.0.105",
15
- "module": "./index.js",
16
- "types": "./index.d.ts"
13
+ "version": "1.1.0",
14
+ "module": "./index.js"
17
15
  }
package/typings.d.ts CHANGED
@@ -440,6 +440,22 @@ declare namespace Koine.Api {
440
440
  };
441
441
  };
442
442
 
443
+ /**
444
+ * @example
445
+ * ```ts
446
+ * // define the type on your `API` types:
447
+ * type Request = Koine.Api.GenerateRequestShortcuts<Endpoints>;
448
+ *
449
+ * // consume the type wherever in your app:
450
+ * type MyData = API.Request["get"]["my/endpoint"];
451
+ * ```
452
+ */
453
+ type GenerateRequestShortcuts<TEndpoints extends Endpoints> = {
454
+ [TMethod in RequestMethod]: {
455
+ [TEndpointUrl in keyof TEndpoints]: TMethod extends "get" ? TEndpoints[TEndpointUrl][Uppercase<TMethod>]["query"] : TEndpoints[TEndpointUrl][Uppercase<TMethod>]["json"];
456
+ };
457
+ };
458
+
443
459
  /**
444
460
  * @example
445
461
  * ```ts