@koine/api 2.0.0-beta.160 → 2.0.0-beta.161
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.d.ts +1 -1
- package/package.json +2 -2
- package/swr/createSwrApi.d.ts +30 -21
- package/swr.d.ts +1 -1
package/createApi.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { Api } from "./types";
|
|
|
3
3
|
* Create api client
|
|
4
4
|
*
|
|
5
5
|
* @param apiName Short name to use in debug logs
|
|
6
|
-
* @param baseUrl Either
|
|
6
|
+
* @param baseUrl Either relative or absolute, it must end without trailing slash
|
|
7
7
|
*/
|
|
8
8
|
export declare let createApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, defaultOptions?: Api.ClientOptions) => Api.Client<TEndpoints>;
|
|
9
9
|
export default createApi;
|
package/package.json
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
}
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@koine/utils": "2.0.0-beta.
|
|
77
|
+
"@koine/utils": "2.0.0-beta.161"
|
|
78
78
|
},
|
|
79
79
|
"peerDependencies": {
|
|
80
80
|
"next": "^14.0.4",
|
|
@@ -91,5 +91,5 @@
|
|
|
91
91
|
"module": "./index.esm.js",
|
|
92
92
|
"main": "./index.cjs.js",
|
|
93
93
|
"types": "./index.esm.d.ts",
|
|
94
|
-
"version": "2.0.0-beta.
|
|
94
|
+
"version": "2.0.0-beta.161"
|
|
95
95
|
}
|
package/swr/createSwrApi.d.ts
CHANGED
|
@@ -1,32 +1,41 @@
|
|
|
1
1
|
import { type BareFetcher, type SWRConfiguration, type SWRResponse } from "swr";
|
|
2
2
|
import type { Api } from "../types";
|
|
3
|
-
|
|
3
|
+
export declare namespace ApiSWR {
|
|
4
|
+
type ConfigurationExtended<Data = any, Error = any, Fn extends BareFetcher<any> = BareFetcher<any>> = SWRConfiguration<Data, Error, Fn> & {
|
|
5
|
+
/**
|
|
6
|
+
* Conditional fetching as option
|
|
7
|
+
*
|
|
8
|
+
* Moving this to an option allows us to keep the endpoints typed dictionary,
|
|
9
|
+
* e.g. we can write:
|
|
10
|
+
*
|
|
11
|
+
* ```js
|
|
12
|
+
* const { data, mutate } = myApi.use("User/{id}",
|
|
13
|
+
* { params: { id: aVariableMaybeContainingAnId || "" }, },
|
|
14
|
+
* { when: !!aVariableMaybeContainingAnId }
|
|
15
|
+
* );
|
|
16
|
+
*
|
|
17
|
+
* // we still have typed `data`, `mutate`
|
|
18
|
+
* ```
|
|
19
|
+
* @see https://swr.vercel.app/docs/conditional-fetching
|
|
20
|
+
*/
|
|
21
|
+
when?: boolean | (() => boolean);
|
|
22
|
+
};
|
|
4
23
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* Moving this to an option allows us to keep the endpoints typed dictionary,
|
|
8
|
-
* e.g. we can write:
|
|
9
|
-
*
|
|
10
|
-
* ```js
|
|
11
|
-
* const { data, mutate } = myApi.use("User/{id}",
|
|
12
|
-
* { params: { id: aVariableMaybeContainingAnId || "" }, },
|
|
13
|
-
* { when: !!aVariableMaybeContainingAnId }
|
|
14
|
-
* );
|
|
15
|
-
*
|
|
16
|
-
* // we still have typed `data`, `mutate`
|
|
17
|
-
* ```
|
|
18
|
-
* @see https://swr.vercel.app/docs/conditional-fetching
|
|
24
|
+
* The `api` interface generated by `createApi`
|
|
19
25
|
*/
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
type Client<TEndpoints extends Api.Endpoints> = Api.Client<TEndpoints> & {
|
|
27
|
+
use: ReturnType<typeof createUseApi<TEndpoints>>;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
22
30
|
/**
|
|
23
31
|
* @private
|
|
24
32
|
*/
|
|
25
|
-
export declare let createUseApi: <TEndpoints extends Api.Endpoints>(api: Api.Client<TEndpoints>, defaultSwrConfig?:
|
|
33
|
+
export declare let createUseApi: <TEndpoints extends Api.Endpoints>(api: Api.Client<TEndpoints>, defaultSwrConfig?: ApiSWR.ConfigurationExtended) => <TEndpoint extends Api.EndpointUrl<TEndpoints>>(endpoint: TEndpoint, options?: Api.EndpointOptions<TEndpoints, TEndpoint, "get">, swrConfig?: ApiSWR.ConfigurationExtended<Api.EndpointResponseOk<TEndpoints, TEndpoint, "get">, Api.EndpointResponseFail<TEndpoints, TEndpoint, "get">>) => SWRResponse<Api.EndpointResponseOk<TEndpoints, TEndpoint, "get">, Api.EndpointResponseFail<TEndpoints, TEndpoint, "get">>;
|
|
26
34
|
/**
|
|
27
35
|
* It creates an api client extended with auto-generated SWR wrapper hooks
|
|
36
|
+
*
|
|
37
|
+
* @param apiName Short name to use in debug logs
|
|
38
|
+
* @param baseUrl Either relative or absolute, it must end without trailing slash
|
|
28
39
|
*/
|
|
29
|
-
export declare let createSwrApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, defaultOptions?: Api.ClientOptions, defaultSwrConfig?:
|
|
30
|
-
use: ReturnType<typeof createUseApi<TEndpoints>>;
|
|
31
|
-
};
|
|
40
|
+
export declare let createSwrApi: <TEndpoints extends Api.Endpoints>(apiName: string, baseUrl: string, defaultOptions?: Api.ClientOptions, defaultSwrConfig?: ApiSWR.ConfigurationExtended) => ApiSWR.Client<TEndpoints>;
|
|
32
41
|
export default createSwrApi;
|
package/swr.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { createSwrApi } from "./swr/createSwrApi";
|
|
1
|
+
export { createSwrApi, type ApiSWR } from "./swr/createSwrApi";
|