bantr-api-client 1.0.0 → 1.0.2
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/api-type/src/trpcRouter/oauth.router.d.ts +177 -0
- package/api-type/src/trpcRouter/oauth.router.test.d.ts +1 -0
- package/{src/api-type → api-type/src/trpcRouter}/router.d.ts +176 -8
- package/dist/index.d.ts +268 -12
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/provider.d.ts +178 -10
- package/dist/provider.js +32 -24
- package/dist/provider.js.map +1 -1
- package/dist/query.d.ts +93 -5
- package/dist/query.js +26 -18
- package/dist/query.js.map +1 -1
- package/package.json +9 -6
- package/tsconfig.json +1 -1
- package/src/index.ts +0 -10
- package/src/provider.tsx +0 -89
- package/src/query.ts +0 -40
package/dist/provider.js
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
2
|
-
import { QueryClient } from
|
3
|
-
import { createTRPCReact,
|
4
|
-
import React, {
|
2
|
+
import { QueryClient } from '@tanstack/react-query';
|
3
|
+
import { createTRPCReact, httpBatchLink, } from '@trpc/react-query';
|
4
|
+
import React, { useState } from 'react';
|
5
5
|
export const QueryClientContext = React.createContext(undefined);
|
6
6
|
export const reactQuery = createTRPCReact({
|
7
7
|
context: QueryClientContext,
|
8
8
|
});
|
9
9
|
export const TRPCProvider = ({ children, useLocalUrl, customUrl, queryClientConfig, queryClient, }) => {
|
10
|
-
const queryClient2 =
|
10
|
+
const [queryClient2] = useState(queryClient ||
|
11
11
|
new QueryClient({
|
12
12
|
defaultOptions: {
|
13
13
|
queries: {
|
@@ -18,29 +18,37 @@ export const TRPCProvider = ({ children, useLocalUrl, customUrl, queryClientConf
|
|
18
18
|
},
|
19
19
|
},
|
20
20
|
...queryClientConfig,
|
21
|
-
})
|
22
|
-
const trpcClientContext =
|
21
|
+
}));
|
22
|
+
const [trpcClientContext] = useState(reactQuery.createClient({
|
23
23
|
links: [
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
? "http://localhost:4242/trpc"
|
30
|
-
: "https://api.bantr.club/trpc"),
|
31
|
-
}),
|
32
|
-
true: wsLink({
|
33
|
-
client: createWSClient({
|
34
|
-
url: customUrl ||
|
35
|
-
(useLocalUrl
|
36
|
-
? "http://localhost:4242/trpc"
|
37
|
-
: "https://api.bantr.club/trpc"),
|
38
|
-
retryDelayMs: () => 5000,
|
39
|
-
}),
|
40
|
-
}),
|
24
|
+
httpBatchLink({
|
25
|
+
url: customUrl ||
|
26
|
+
(useLocalUrl
|
27
|
+
? 'http://localhost:4242/trpc'
|
28
|
+
: 'https://api.bantr.club/trpc'),
|
41
29
|
}),
|
30
|
+
// splitLink({
|
31
|
+
// condition: (op) => op.type === 'subscription',
|
32
|
+
// false: httpBatchLink({
|
33
|
+
// url:
|
34
|
+
// customUrl ||
|
35
|
+
// (useLocalUrl
|
36
|
+
// ? 'http://localhost:4242/trpc'
|
37
|
+
// : 'https://api.bantr.club/trpc'),
|
38
|
+
// }),
|
39
|
+
// true: wsLink({
|
40
|
+
// client: createWSClient({
|
41
|
+
// url:
|
42
|
+
// customUrl ||
|
43
|
+
// (useLocalUrl
|
44
|
+
// ? 'http://localhost:4242/trpc'
|
45
|
+
// : 'https://api.bantr.club/trpc'),
|
46
|
+
// retryDelayMs: () => 5000,
|
47
|
+
// }),
|
48
|
+
// }),
|
49
|
+
// }),
|
42
50
|
],
|
43
|
-
})
|
51
|
+
}));
|
44
52
|
return (_jsx(QueryClientContext.Provider, { value: queryClient, children: _jsx(reactQuery.Provider, { client: trpcClientContext, queryClient: queryClient2, children: children }) }));
|
45
53
|
};
|
46
54
|
//# sourceMappingURL=provider.js.map
|
package/dist/provider.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAqB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EACL,eAAe,EACf,
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAqB,MAAM,uBAAuB,CAAC;AACvE,OAAO,EACL,eAAe,EACf,aAAa,GACd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,EAAa,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGnD,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,CAAC,aAAa,CACnD,SAAS,CACV,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,eAAe,CAAY;IACnD,OAAO,EAAE,kBAAkB;CAC5B,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,EAC3B,QAAQ,EACR,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,WAAW,GAOZ,EAAE,EAAE;IACH,MAAM,CAAC,YAAY,CAAC,GAAG,QAAQ,CAC7B,WAAW;QACX,IAAI,WAAW,CAAC;YACd,cAAc,EAAE;gBACd,OAAO,EAAE;oBACP,oBAAoB,EAAE,KAAK;oBAC3B,kBAAkB,EAAE,KAAK;oBACzB,KAAK,EAAE,KAAK;oBACZ,SAAS,EAAE,CAAC,GAAG,EAAE,GAAG,IAAI;iBACzB;aACF;YACD,GAAG,iBAAiB;SACrB,CAAC,CACH,CAAC;IAEF,MAAM,CAAC,iBAAiB,CAAC,GAAG,QAAQ,CAClC,UAAU,CAAC,YAAY,CAAC;QACtB,KAAK,EAAE;YACL,aAAa,CAAC;gBACZ,GAAG,EACD,SAAS;oBACT,CAAC,WAAW;wBACV,CAAC,CAAC,4BAA4B;wBAC9B,CAAC,CAAC,6BAA6B,CAAC;aACrC,CAAC;YACF,cAAc;YACd,mDAAmD;YACnD,2BAA2B;YAC3B,WAAW;YACX,qBAAqB;YACrB,qBAAqB;YACrB,yCAAyC;YACzC,4CAA4C;YAC5C,QAAQ;YACR,mBAAmB;YACnB,+BAA+B;YAC/B,aAAa;YACb,uBAAuB;YACvB,uBAAuB;YACvB,2CAA2C;YAC3C,8CAA8C;YAC9C,kCAAkC;YAClC,UAAU;YACV,QAAQ;YACR,MAAM;SACP;KACF,CAAC,CACH,CAAC;IAEF,OAAO,CACL,KAAC,kBAAkB,CAAC,QAAQ,IAAC,KAAK,EAAE,WAAW,YAC7C,KAAC,UAAU,CAAC,QAAQ,IAClB,MAAM,EAAE,iBAAiB,EACzB,WAAW,EAAE,YAAY,YAExB,QAAQ,GACW,GACM,CAC/B,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/query.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
type InstanceOptions = {
|
1
|
+
declare type InstanceOptions = {
|
2
2
|
useLocalUrl?: boolean;
|
3
3
|
customUrl?: string;
|
4
4
|
};
|
@@ -36,6 +36,48 @@ export declare const createTRPCClientQuery: (options?: InstanceOptions) => {
|
|
36
36
|
_meta: object;
|
37
37
|
}, void>>;
|
38
38
|
};
|
39
|
+
googleMobileCallback: {
|
40
|
+
mutate: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"mutation", {
|
41
|
+
_config: import("@trpc/server").RootConfig<{
|
42
|
+
ctx: import("trpc-koa-adapter").CreateTrpcKoaContextOptions;
|
43
|
+
meta: object;
|
44
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
45
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
46
|
+
}>;
|
47
|
+
_meta: object;
|
48
|
+
_ctx_out: import("trpc-koa-adapter").CreateTrpcKoaContextOptions;
|
49
|
+
_input_in: {
|
50
|
+
code: string;
|
51
|
+
};
|
52
|
+
_input_out: {
|
53
|
+
code: string;
|
54
|
+
};
|
55
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
56
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
57
|
+
}, {
|
58
|
+
accessToken: string;
|
59
|
+
refreshToken: string;
|
60
|
+
accountStatus: string;
|
61
|
+
redirectTeamId?: number | null | undefined;
|
62
|
+
authSchemas: import("../api-type/src/types/member").TAuthSchemas;
|
63
|
+
memberId: number;
|
64
|
+
bio: string | null;
|
65
|
+
city?: string | undefined;
|
66
|
+
street?: string | undefined;
|
67
|
+
state?: string | undefined;
|
68
|
+
avatar: string | null;
|
69
|
+
teams: import("../api-type/src/models/team").Team[];
|
70
|
+
favoriteTeam: number | null | undefined;
|
71
|
+
zip: string | undefined;
|
72
|
+
phoneNumber: string | null;
|
73
|
+
gender?: string | undefined;
|
74
|
+
birthday: string | null;
|
75
|
+
location: string | null;
|
76
|
+
email: string;
|
77
|
+
firstName: string | null;
|
78
|
+
lastName: string | null;
|
79
|
+
}>>;
|
80
|
+
};
|
39
81
|
facebookAuth: {
|
40
82
|
mutate: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"mutation", {
|
41
83
|
_config: import("@trpc/server").RootConfig<{
|
@@ -85,21 +127,67 @@ export declare const createTRPCClientQuery: (options?: InstanceOptions) => {
|
|
85
127
|
}, string>>;
|
86
128
|
};
|
87
129
|
appleCallback: {
|
88
|
-
|
130
|
+
mutate: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"mutation", {
|
89
131
|
_config: import("@trpc/server").RootConfig<{
|
90
132
|
ctx: import("trpc-koa-adapter").CreateTrpcKoaContextOptions;
|
91
133
|
meta: object;
|
92
134
|
errorShape: import("@trpc/server").DefaultErrorShape;
|
93
135
|
transformer: import("@trpc/server").DefaultDataTransformer;
|
94
136
|
}>;
|
137
|
+
_meta: object;
|
95
138
|
_ctx_out: import("trpc-koa-adapter").CreateTrpcKoaContextOptions;
|
96
|
-
_input_in:
|
97
|
-
|
139
|
+
_input_in: {
|
140
|
+
code: string;
|
141
|
+
};
|
142
|
+
_input_out: {
|
143
|
+
code: string;
|
144
|
+
};
|
98
145
|
_output_in: typeof import("@trpc/server").unsetMarker;
|
99
146
|
_output_out: typeof import("@trpc/server").unsetMarker;
|
100
|
-
_meta: object;
|
101
147
|
}, void>>;
|
102
148
|
};
|
149
|
+
appleMobileCallback: {
|
150
|
+
mutate: import("@trpc/client").Resolver<import("@trpc/server").BuildProcedure<"mutation", {
|
151
|
+
_config: import("@trpc/server").RootConfig<{
|
152
|
+
ctx: import("trpc-koa-adapter").CreateTrpcKoaContextOptions;
|
153
|
+
meta: object;
|
154
|
+
errorShape: import("@trpc/server").DefaultErrorShape;
|
155
|
+
transformer: import("@trpc/server").DefaultDataTransformer;
|
156
|
+
}>;
|
157
|
+
_meta: object;
|
158
|
+
_ctx_out: import("trpc-koa-adapter").CreateTrpcKoaContextOptions;
|
159
|
+
_input_in: {
|
160
|
+
idToken: string;
|
161
|
+
};
|
162
|
+
_input_out: {
|
163
|
+
idToken: string;
|
164
|
+
};
|
165
|
+
_output_in: typeof import("@trpc/server").unsetMarker;
|
166
|
+
_output_out: typeof import("@trpc/server").unsetMarker;
|
167
|
+
}, {
|
168
|
+
accessToken: string;
|
169
|
+
refreshToken: string;
|
170
|
+
accountStatus: string;
|
171
|
+
redirectTeamId?: number | null | undefined;
|
172
|
+
authSchemas: import("../api-type/src/types/member").TAuthSchemas;
|
173
|
+
memberId: number;
|
174
|
+
bio: string | null;
|
175
|
+
city?: string | undefined;
|
176
|
+
street?: string | undefined;
|
177
|
+
state?: string | undefined;
|
178
|
+
avatar: string | null;
|
179
|
+
teams: import("../api-type/src/models/team").Team[];
|
180
|
+
favoriteTeam: number | null | undefined;
|
181
|
+
zip: string | undefined;
|
182
|
+
phoneNumber: string | null;
|
183
|
+
gender?: string | undefined;
|
184
|
+
birthday: string | null;
|
185
|
+
location: string | null;
|
186
|
+
email: string;
|
187
|
+
firstName: string | null;
|
188
|
+
lastName: string | null;
|
189
|
+
}>>;
|
190
|
+
};
|
103
191
|
};
|
104
192
|
};
|
105
193
|
export {};
|
package/dist/query.js
CHANGED
@@ -1,27 +1,35 @@
|
|
1
|
-
import { createTRPCProxyClient,
|
1
|
+
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
|
2
2
|
let instance = null;
|
3
3
|
export const createTRPCClientQuery = (options = {}) => {
|
4
4
|
if (!instance) {
|
5
5
|
instance = createTRPCProxyClient({
|
6
6
|
links: [
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
? "http://localhost:4242/trpc"
|
13
|
-
: "https://api.bantr.club/trpc"),
|
14
|
-
}),
|
15
|
-
true: wsLink({
|
16
|
-
client: createWSClient({
|
17
|
-
url: options?.customUrl ||
|
18
|
-
(options?.useLocalUrl
|
19
|
-
? "http://localhost:4242/trpc"
|
20
|
-
: "https://api.bantr.club/trpc"),
|
21
|
-
retryDelayMs: () => 5000,
|
22
|
-
}),
|
23
|
-
}),
|
7
|
+
httpBatchLink({
|
8
|
+
url: options?.customUrl ||
|
9
|
+
(options?.useLocalUrl
|
10
|
+
? 'http://localhost:4242/trpc'
|
11
|
+
: 'https://api.bantr.club/trpc'),
|
24
12
|
}),
|
13
|
+
// splitLink({
|
14
|
+
// condition: (op) => op.type === 'subscription',
|
15
|
+
// false: httpBatchLink({
|
16
|
+
// url:
|
17
|
+
// options?.customUrl ||
|
18
|
+
// (options?.useLocalUrl
|
19
|
+
// ? 'http://localhost:4242/trpc'
|
20
|
+
// : 'https://api.bantr.club/trpc'),
|
21
|
+
// }),
|
22
|
+
// true: wsLink({
|
23
|
+
// client: createWSClient({
|
24
|
+
// url:
|
25
|
+
// options?.customUrl ||
|
26
|
+
// (options?.useLocalUrl
|
27
|
+
// ? 'http://localhost:4242/trpc'
|
28
|
+
// : 'https://api.bantr.club/trpc'),
|
29
|
+
// retryDelayMs: () => 5000,
|
30
|
+
// }),
|
31
|
+
// }),
|
32
|
+
// }),
|
25
33
|
],
|
26
34
|
});
|
27
35
|
}
|
package/dist/query.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAGpE,IAAI,QAAQ,GAA+D,IAAI,CAAC;AAOhF,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,UAA2B,EAAE,EAAE,EAAE;IACrE,IAAI,CAAC,QAAQ,EAAE;QACb,QAAQ,GAAG,qBAAqB,CAAY;YAC1C,KAAK,EAAE;gBACL,aAAa,CAAC;oBACZ,GAAG,EACD,OAAO,EAAE,SAAS;wBAClB,CAAC,OAAO,EAAE,WAAW;4BACnB,CAAC,CAAC,4BAA4B;4BAC9B,CAAC,CAAC,6BAA6B,CAAC;iBACrC,CAAC;gBACF,cAAc;gBACd,mDAAmD;gBACnD,2BAA2B;gBAC3B,WAAW;gBACX,8BAA8B;gBAC9B,8BAA8B;gBAC9B,yCAAyC;gBACzC,4CAA4C;gBAC5C,QAAQ;gBACR,mBAAmB;gBACnB,+BAA+B;gBAC/B,aAAa;gBACb,gCAAgC;gBAChC,gCAAgC;gBAChC,2CAA2C;gBAC3C,8CAA8C;gBAC9C,kCAAkC;gBAClC,UAAU;gBACV,QAAQ;gBACR,MAAM;aACP;SACF,CAAC,CAAC;KACJ;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC,CAAC"}
|
package/package.json
CHANGED
@@ -1,9 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "bantr-api-client",
|
3
|
-
"version": "1.0.
|
3
|
+
"version": "1.0.2",
|
4
4
|
"description": "SDK for Bantr API integration using tRPC and react-query",
|
5
5
|
"main": "dist/index.js",
|
6
6
|
"types": "dist/index.d.ts",
|
7
|
+
"publishConfig": {
|
8
|
+
"access": "public"
|
9
|
+
},
|
7
10
|
"scripts": {
|
8
11
|
"build": "tsc"
|
9
12
|
},
|
@@ -11,17 +14,17 @@
|
|
11
14
|
"author": "",
|
12
15
|
"license": "Apache-2.0",
|
13
16
|
"devDependencies": {
|
14
|
-
"@types/react": "18",
|
15
|
-
"@types/react-dom": "18",
|
16
|
-
"typescript": "4"
|
17
|
+
"@types/react": "^18.2.0",
|
18
|
+
"@types/react-dom": "^18.2.0",
|
19
|
+
"typescript": "4.8.4"
|
17
20
|
},
|
18
21
|
"dependencies": {
|
19
22
|
"@tanstack/react-query": "^4.20.4",
|
20
23
|
"@trpc/client": "^10.45.2",
|
21
24
|
"@trpc/react-query": "^10.45.2",
|
22
25
|
"@trpc/server": "^10.45.2",
|
23
|
-
"react": "18",
|
24
|
-
"react-dom": "18",
|
26
|
+
"react": "^18.2.0",
|
27
|
+
"react-dom": "^18.2.0",
|
25
28
|
"trpc-koa-adapter": "^1.2.2",
|
26
29
|
"zod": "^3.23.8"
|
27
30
|
}
|
package/tsconfig.json
CHANGED
package/src/index.ts
DELETED
package/src/provider.tsx
DELETED
@@ -1,89 +0,0 @@
|
|
1
|
-
import { QueryClient, QueryClientConfig } from "@tanstack/react-query";
|
2
|
-
import {
|
3
|
-
createTRPCReact,
|
4
|
-
createWSClient,
|
5
|
-
httpBatchLink,
|
6
|
-
splitLink,
|
7
|
-
wsLink,
|
8
|
-
} from "@trpc/react-query";
|
9
|
-
import React, { ReactNode, useMemo } from "react";
|
10
|
-
import type { AppRouter } from "./api-type/router";
|
11
|
-
|
12
|
-
export const QueryClientContext = React.createContext<QueryClient | undefined>(
|
13
|
-
undefined
|
14
|
-
);
|
15
|
-
|
16
|
-
export const reactQuery = createTRPCReact<AppRouter>({
|
17
|
-
context: QueryClientContext,
|
18
|
-
});
|
19
|
-
|
20
|
-
export const TRPCProvider = ({
|
21
|
-
children,
|
22
|
-
useLocalUrl,
|
23
|
-
customUrl,
|
24
|
-
queryClientConfig,
|
25
|
-
queryClient,
|
26
|
-
}: {
|
27
|
-
children: ReactNode;
|
28
|
-
useLocalUrl?: boolean;
|
29
|
-
customUrl?: string;
|
30
|
-
queryClientConfig?: QueryClientConfig;
|
31
|
-
queryClient?: QueryClient;
|
32
|
-
}) => {
|
33
|
-
const queryClient2 = useMemo(
|
34
|
-
() =>
|
35
|
-
queryClient ||
|
36
|
-
new QueryClient({
|
37
|
-
defaultOptions: {
|
38
|
-
queries: {
|
39
|
-
refetchOnWindowFocus: false,
|
40
|
-
refetchOnReconnect: false,
|
41
|
-
retry: false,
|
42
|
-
staleTime: 5 * 60 * 1000,
|
43
|
-
},
|
44
|
-
},
|
45
|
-
...queryClientConfig,
|
46
|
-
}),
|
47
|
-
[queryClient, queryClientConfig]
|
48
|
-
);
|
49
|
-
|
50
|
-
const trpcClientContext = useMemo(
|
51
|
-
() =>
|
52
|
-
reactQuery.createClient({
|
53
|
-
links: [
|
54
|
-
splitLink({
|
55
|
-
condition: (op) => op.type === "subscription",
|
56
|
-
false: httpBatchLink({
|
57
|
-
url:
|
58
|
-
customUrl ||
|
59
|
-
(useLocalUrl
|
60
|
-
? "http://localhost:4242/trpc"
|
61
|
-
: "https://api.bantr.club/trpc"),
|
62
|
-
}),
|
63
|
-
true: wsLink({
|
64
|
-
client: createWSClient({
|
65
|
-
url:
|
66
|
-
customUrl ||
|
67
|
-
(useLocalUrl
|
68
|
-
? "http://localhost:4242/trpc"
|
69
|
-
: "https://api.bantr.club/trpc"),
|
70
|
-
retryDelayMs: () => 5000,
|
71
|
-
}),
|
72
|
-
}),
|
73
|
-
}),
|
74
|
-
],
|
75
|
-
}),
|
76
|
-
[useLocalUrl, customUrl]
|
77
|
-
);
|
78
|
-
|
79
|
-
return (
|
80
|
-
<QueryClientContext.Provider value={queryClient}>
|
81
|
-
<reactQuery.Provider
|
82
|
-
client={trpcClientContext}
|
83
|
-
queryClient={queryClient2}
|
84
|
-
>
|
85
|
-
{children}
|
86
|
-
</reactQuery.Provider>
|
87
|
-
</QueryClientContext.Provider>
|
88
|
-
);
|
89
|
-
};
|
package/src/query.ts
DELETED
@@ -1,40 +0,0 @@
|
|
1
|
-
import { createTRPCProxyClient, createWSClient, httpBatchLink, splitLink, wsLink } from "@trpc/client";
|
2
|
-
import type { AppRouter } from "./api-type/router";
|
3
|
-
|
4
|
-
let instance: ReturnType<typeof createTRPCProxyClient<AppRouter>> | null = null;
|
5
|
-
|
6
|
-
type InstanceOptions = {
|
7
|
-
useLocalUrl?: boolean;
|
8
|
-
customUrl?: string;
|
9
|
-
}
|
10
|
-
|
11
|
-
export const createTRPCClientQuery = (options: InstanceOptions = {}) => {
|
12
|
-
if (!instance) {
|
13
|
-
instance = createTRPCProxyClient<AppRouter>({
|
14
|
-
links: [
|
15
|
-
splitLink({
|
16
|
-
condition: (op) => op.type === "subscription",
|
17
|
-
false: httpBatchLink({
|
18
|
-
url:
|
19
|
-
options?.customUrl ||
|
20
|
-
(options?.useLocalUrl
|
21
|
-
? "http://localhost:4242/trpc"
|
22
|
-
: "https://api.bantr.club/trpc"),
|
23
|
-
}),
|
24
|
-
true: wsLink({
|
25
|
-
client: createWSClient({
|
26
|
-
url:
|
27
|
-
options?.customUrl ||
|
28
|
-
(options?.useLocalUrl
|
29
|
-
? "http://localhost:4242/trpc"
|
30
|
-
: "https://api.bantr.club/trpc"),
|
31
|
-
retryDelayMs: () => 5000,
|
32
|
-
}),
|
33
|
-
}),
|
34
|
-
}),
|
35
|
-
],
|
36
|
-
});
|
37
|
-
}
|
38
|
-
|
39
|
-
return instance;
|
40
|
-
};
|