Skip to content

Commit e6ba35b

Browse files
committed
Make queryClient required
1 parent ac881ed commit e6ba35b

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/coreSDK.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
import type { QueryClient } from "react-query";
12
import {
2-
Opts,
33
DeepAsyncFnRecord,
44
DoFetch,
55
getTypedSDKInstance,
@@ -8,7 +8,12 @@ import {
88
} from "./internal";
99

1010
export function createTypedSDK<T extends DeepAsyncFnRecord<any>>(
11-
opts: Opts
11+
opts:
12+
| { url: string; queryClient?: QueryClient }
13+
| {
14+
queryClient?: QueryClient;
15+
doFetch: DoFetch;
16+
}
1217
): TypedSDK<T> {
1318
let doFetch: DoFetch;
1419
if ("doFetch" in opts) {

src/internal.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ export type DoFetch = <TPageParam = any>(
1919
} & Partial<QueryFunctionContext<readonly string[], TPageParam>>
2020
) => Promise<any>;
2121

22-
export type Opts =
23-
| { url: string; queryClient?: QueryClient }
24-
| {
25-
queryClient?: QueryClient;
26-
doFetch: DoFetch;
27-
};
28-
2922
export type AsyncFn = (...args: any[]) => Promise<any>;
3023

3124
export type DeepAsyncFnRecord<T extends {}> = {

src/reactSDK.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {
22
DeepAsyncFnRecord,
33
TypedGetSDKQueryKey,
4-
Opts,
54
TypedSDK as TypedSDK,
65
TypedUseInfiniteQuery as TypedUseInfiniteSDK,
76
TypedUseQuery as TypedUseSDK,
@@ -28,15 +27,29 @@ export { QueryClient } from "react-query";
2827

2928
export function createTypedReactSDK<
3029
Endpoints extends DeepAsyncFnRecord<Endpoints>
31-
>(opts: Opts): SDK<Endpoints> {
30+
>(
31+
opts:
32+
| { url: string; queryClient: QueryClient }
33+
| {
34+
queryClient: QueryClient;
35+
doFetch: DoFetch;
36+
}
37+
): SDK<Endpoints> {
3238
return new SDK(opts);
3339
}
3440

3541
class SDK<Endpoints extends DeepAsyncFnRecord<Endpoints>> {
3642
private queryClient?: QueryClient;
3743
private doFetch: DoFetch;
3844

39-
constructor(opts: Opts) {
45+
constructor(
46+
opts:
47+
| { url: string; queryClient: QueryClient }
48+
| {
49+
queryClient: QueryClient;
50+
doFetch: DoFetch;
51+
}
52+
) {
4053
this.queryClient = opts.queryClient;
4154
if ("doFetch" in opts) {
4255
this.doFetch = getFetchFn({ userSuppliedDoFetch: opts.doFetch });

0 commit comments

Comments
 (0)