@orpc/react 0.0.4 → 0.0.6
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/LICENSE +21 -0
- package/dist/index.js +4970 -39
- package/dist/index.js.map +1 -0
- package/dist/src/general-hooks.d.ts +8 -8
- package/dist/src/general-hooks.d.ts.map +1 -1
- package/dist/src/general-utils.d.ts +21 -21
- package/dist/src/general-utils.d.ts.map +1 -1
- package/dist/src/index.d.ts +1 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/procedure-hooks.d.ts +13 -13
- package/dist/src/procedure-hooks.d.ts.map +1 -1
- package/dist/src/procedure-utils.d.ts +19 -19
- package/dist/src/procedure-utils.d.ts.map +1 -1
- package/dist/src/react-hooks.d.ts +2 -2
- package/dist/src/react-hooks.d.ts.map +1 -1
- package/dist/src/react-utils.d.ts +2 -2
- package/dist/src/react-utils.d.ts.map +1 -1
- package/dist/src/react.d.ts.map +1 -1
- package/dist/src/tanstack-key.d.ts.map +1 -1
- package/dist/src/tanstack-query.d.ts.map +1 -1
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/use-queries/builder.d.ts +5 -5
- package/dist/src/use-queries/builder.d.ts.map +1 -1
- package/dist/src/use-queries/builders.d.ts +1 -1
- package/dist/src/use-queries/builders.d.ts.map +1 -1
- package/dist/src/use-queries/hook.d.ts.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +11 -14
- package/src/general-hooks.test.tsx +8 -8
- package/src/general-hooks.ts +13 -12
- package/src/general-utils.test-d.ts +7 -7
- package/src/general-utils.test.tsx +25 -25
- package/src/general-utils.ts +82 -86
- package/src/index.ts +1 -1
- package/src/orpc-path.ts +1 -1
- package/src/procedure-hooks.test-d.ts +6 -6
- package/src/procedure-hooks.test.tsx +1 -1
- package/src/procedure-hooks.ts +41 -41
- package/src/procedure-utils.test-d.ts +9 -9
- package/src/procedure-utils.test.tsx +13 -13
- package/src/procedure-utils.ts +65 -68
- package/src/react-hooks.ts +13 -21
- package/src/react-utils.ts +14 -25
- package/src/react.test-d.ts +6 -6
- package/src/react.test.tsx +8 -8
- package/src/react.tsx +5 -4
- package/src/tanstack-key.ts +9 -9
- package/src/tanstack-query.ts +2 -2
- package/src/types.ts +1 -1
- package/src/use-queries/builder.test-d.ts +2 -2
- package/src/use-queries/builder.ts +9 -10
- package/src/use-queries/builders.ts +11 -11
- package/src/use-queries/hook.test-d.ts +1 -1
- package/src/use-queries/hook.test.tsx +2 -2
- package/src/use-queries/hook.ts +8 -8
package/src/react-utils.ts
CHANGED
@@ -5,32 +5,21 @@ import type {
|
|
5
5
|
SchemaOutput,
|
6
6
|
} from '@orpc/contract'
|
7
7
|
import type { Procedure, Router } from '@orpc/server'
|
8
|
-
import { type GeneralUtils, createGeneralUtils } from './general-utils'
|
9
|
-
import { type ProcedureUtils, createProcedureUtils } from './procedure-utils'
|
10
8
|
import type { ORPCContextValue } from './react-context'
|
9
|
+
import { createGeneralUtils, type GeneralUtils } from './general-utils'
|
10
|
+
import { createProcedureUtils, type ProcedureUtils } from './procedure-utils'
|
11
11
|
|
12
12
|
export type ORPCUtilsWithContractRouter<TRouter extends ContractRouter> = {
|
13
|
-
[K in keyof TRouter]: TRouter[K] extends ContractProcedure<
|
14
|
-
|
15
|
-
infer UOutputSchema
|
16
|
-
>
|
17
|
-
? ProcedureUtils<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> &
|
18
|
-
GeneralUtils<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>
|
13
|
+
[K in keyof TRouter]: TRouter[K] extends ContractProcedure<infer UInputSchema, infer UOutputSchema>
|
14
|
+
? ProcedureUtils<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> & GeneralUtils<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>
|
19
15
|
: TRouter[K] extends ContractRouter
|
20
16
|
? ORPCUtilsWithContractRouter<TRouter[K]>
|
21
17
|
: never
|
22
18
|
} & GeneralUtils<undefined, undefined, unknown>
|
23
19
|
|
24
20
|
export type ORPCUtilsWithRouter<TRouter extends Router<any>> = {
|
25
|
-
[K in keyof TRouter]: TRouter[K] extends Procedure<
|
26
|
-
|
27
|
-
any,
|
28
|
-
infer UInputSchema,
|
29
|
-
infer UOutputSchema,
|
30
|
-
infer UHandlerOutput
|
31
|
-
>
|
32
|
-
? ProcedureUtils<UInputSchema, UOutputSchema, UHandlerOutput> &
|
33
|
-
GeneralUtils<UInputSchema, UOutputSchema, UHandlerOutput>
|
21
|
+
[K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UFuncOutput>
|
22
|
+
? ProcedureUtils<UInputSchema, UOutputSchema, UFuncOutput> & GeneralUtils<UInputSchema, UOutputSchema, UFuncOutput>
|
34
23
|
: TRouter[K] extends Router<any>
|
35
24
|
? ORPCUtilsWithRouter<TRouter[K]>
|
36
25
|
: never
|
@@ -52,10 +41,10 @@ export interface CreateORPCUtilsOptions<
|
|
52
41
|
export function createORPCUtils<TRouter extends ContractRouter | Router<any>>(
|
53
42
|
options: CreateORPCUtilsOptions<TRouter>,
|
54
43
|
): TRouter extends Router<any>
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
44
|
+
? ORPCUtilsWithRouter<TRouter>
|
45
|
+
: TRouter extends ContractRouter
|
46
|
+
? ORPCUtilsWithContractRouter<TRouter>
|
47
|
+
: never {
|
59
48
|
const path = options.path ?? []
|
60
49
|
const client = options.contextValue.client as any
|
61
50
|
|
@@ -67,10 +56,10 @@ export function createORPCUtils<TRouter extends ContractRouter | Router<any>>(
|
|
67
56
|
// for sure root is not procedure, so do not it procedure utils on root
|
68
57
|
const procedureUtils = path.length
|
69
58
|
? createProcedureUtils({
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
59
|
+
client,
|
60
|
+
queryClient: options.contextValue.queryClient,
|
61
|
+
path,
|
62
|
+
})
|
74
63
|
: {}
|
75
64
|
|
76
65
|
return new Proxy(
|
package/src/react.test-d.ts
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
import type { SchemaOutput } from '@orpc/contract'
|
2
2
|
import type { QueryClient } from '@tanstack/react-query'
|
3
|
+
import type { GeneralHooks } from './general-hooks'
|
4
|
+
import type { GeneralUtils } from './general-utils'
|
5
|
+
import type { ProcedureHooks } from './procedure-hooks'
|
6
|
+
import type { ProcedureUtils } from './procedure-utils'
|
3
7
|
import {
|
8
|
+
orpc,
|
9
|
+
orpcClient,
|
4
10
|
ORPCContext,
|
5
11
|
type UserFindInputSchema,
|
6
12
|
type UserSchema,
|
7
|
-
orpc,
|
8
|
-
orpcClient,
|
9
13
|
} from '../tests/orpc'
|
10
|
-
import type { GeneralHooks } from './general-hooks'
|
11
|
-
import type { GeneralUtils } from './general-utils'
|
12
|
-
import type { ProcedureHooks } from './procedure-hooks'
|
13
|
-
import type { ProcedureUtils } from './procedure-utils'
|
14
14
|
import { useQueriesFactory } from './use-queries/hook'
|
15
15
|
|
16
16
|
describe('useUtils', () => {
|
package/src/react.test.tsx
CHANGED
@@ -6,7 +6,7 @@ beforeEach(() => {
|
|
6
6
|
})
|
7
7
|
|
8
8
|
it('useUtils', async () => {
|
9
|
-
const { result } = renderHook(() => orpc.useUtils(), { wrapper
|
9
|
+
const { result } = renderHook(() => orpc.useUtils(), { wrapper })
|
10
10
|
|
11
11
|
const promise = result.current.user.find.ensureQueryData({ id: '1' })
|
12
12
|
expect(result.current.user.isFetching()).toBe(1)
|
@@ -26,7 +26,7 @@ it('useUtils', async () => {
|
|
26
26
|
})
|
27
27
|
|
28
28
|
it('useContext', async () => {
|
29
|
-
const { result } = renderHook(() => orpc.useContext(), { wrapper
|
29
|
+
const { result } = renderHook(() => orpc.useContext(), { wrapper })
|
30
30
|
|
31
31
|
expect(result.current.client).toBe(orpcClient)
|
32
32
|
expect(result.current.queryClient).toBe(queryClient)
|
@@ -38,8 +38,8 @@ it('useContext', async () => {
|
|
38
38
|
|
39
39
|
it('useQueries', async () => {
|
40
40
|
const queries = renderHook(
|
41
|
-
() => orpc.useQueries(
|
42
|
-
{ wrapper
|
41
|
+
() => orpc.useQueries(o => [o.user.find({ id: '123' })]),
|
42
|
+
{ wrapper },
|
43
43
|
)
|
44
44
|
|
45
45
|
await waitFor(() =>
|
@@ -52,20 +52,20 @@ it('useQueries', async () => {
|
|
52
52
|
|
53
53
|
it('hooks', async () => {
|
54
54
|
const isFetching = renderHook(() => orpc.user.useIsFetching(), {
|
55
|
-
wrapper
|
55
|
+
wrapper,
|
56
56
|
})
|
57
57
|
const isMutating = renderHook(() => orpc.user.useIsMutating(), {
|
58
|
-
wrapper
|
58
|
+
wrapper,
|
59
59
|
})
|
60
60
|
|
61
61
|
expect(isFetching.result.current).toBe(0)
|
62
62
|
expect(isMutating.result.current).toBe(0)
|
63
63
|
|
64
64
|
const query = renderHook(() => orpc.user.find.useQuery({ id: '1' }), {
|
65
|
-
wrapper
|
65
|
+
wrapper,
|
66
66
|
})
|
67
67
|
const mutation = renderHook(() => orpc.user.create.useMutation(), {
|
68
|
-
wrapper
|
68
|
+
wrapper,
|
69
69
|
})
|
70
70
|
|
71
71
|
await waitFor(() => expect(query.result.current.status).toEqual('pending'))
|
package/src/react.tsx
CHANGED
@@ -1,25 +1,25 @@
|
|
1
1
|
import type { ContractRouter } from '@orpc/contract'
|
2
2
|
import type { Router } from '@orpc/server'
|
3
3
|
import {
|
4
|
+
createORPCContext,
|
4
5
|
type ORPCContext,
|
5
6
|
type ORPCContextValue,
|
6
|
-
createORPCContext,
|
7
7
|
useORPCContext,
|
8
8
|
} from './react-context'
|
9
9
|
import {
|
10
|
+
createORPCHooks,
|
10
11
|
type ORPCHooksWithContractRouter,
|
11
12
|
type ORPCHooksWithRouter,
|
12
|
-
createORPCHooks,
|
13
13
|
} from './react-hooks'
|
14
14
|
import {
|
15
|
+
createORPCUtils,
|
15
16
|
type ORPCUtilsWithContractRouter,
|
16
17
|
type ORPCUtilsWithRouter,
|
17
|
-
createORPCUtils,
|
18
18
|
} from './react-utils'
|
19
19
|
import {
|
20
|
+
useQueriesFactory,
|
20
21
|
type UseQueriesWithContractRouter,
|
21
22
|
type UseQueriesWithRouter,
|
22
|
-
useQueriesFactory,
|
23
23
|
} from './use-queries/hook'
|
24
24
|
|
25
25
|
export type ORPCReactWithContractRouter<TRouter extends ContractRouter> =
|
@@ -49,6 +49,7 @@ export function createORPCReact<
|
|
49
49
|
const Context = createORPCContext<TRouter>()
|
50
50
|
const useContext = () => useORPCContext(Context)
|
51
51
|
const useUtils = () => createORPCUtils({ contextValue: useContext() })
|
52
|
+
// eslint-disable-next-line react-hooks/rules-of-hooks
|
52
53
|
const useQueries = useQueriesFactory({ context: Context })
|
53
54
|
const hooks = createORPCHooks({ context: Context })
|
54
55
|
|
package/src/tanstack-key.ts
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
import type { SchemaInput } from '@orpc/contract'
|
2
2
|
import type { PartialDeep } from '@orpc/shared'
|
3
3
|
import type { MutationKey, QueryKey } from '@tanstack/react-query'
|
4
|
-
import { getORPCPath } from './orpc-path'
|
5
4
|
import type { ProcedureHooks } from './procedure-hooks'
|
6
5
|
import type {
|
7
6
|
ORPCHooksWithContractRouter,
|
8
7
|
ORPCHooksWithRouter,
|
9
8
|
} from './react-hooks'
|
9
|
+
import { getORPCPath } from './orpc-path'
|
10
10
|
|
11
11
|
export type QueryType = 'query' | 'infinite' | undefined
|
12
12
|
|
@@ -17,9 +17,9 @@ export interface GetQueryKeyOptions<TInput> {
|
|
17
17
|
|
18
18
|
export function getQueryKey<
|
19
19
|
T extends
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
| ORPCHooksWithContractRouter<any>
|
21
|
+
| ORPCHooksWithRouter<any>
|
22
|
+
| ProcedureHooks<any, any, any>,
|
23
23
|
>(
|
24
24
|
orpc: T,
|
25
25
|
options?: GetQueryKeyOptions<
|
@@ -36,8 +36,8 @@ export function getQueryKeyFromPath(
|
|
36
36
|
path: string[],
|
37
37
|
options?: GetQueryKeyOptions<unknown>,
|
38
38
|
): QueryKey {
|
39
|
-
const withInput
|
40
|
-
options?.input !== undefined ? { input: options?.input } : {}
|
39
|
+
const withInput
|
40
|
+
= options?.input !== undefined ? { input: options?.input } : {}
|
41
41
|
const withType = options?.type !== undefined ? { type: options?.type } : {}
|
42
42
|
|
43
43
|
return [
|
@@ -51,9 +51,9 @@ export function getQueryKeyFromPath(
|
|
51
51
|
|
52
52
|
export function getMutationKey<
|
53
53
|
T extends
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
| ORPCHooksWithContractRouter<any>
|
55
|
+
| ORPCHooksWithRouter<any>
|
56
|
+
| ProcedureHooks<any, any, any>,
|
57
57
|
>(orpc: T): MutationKey {
|
58
58
|
const path = getORPCPath(orpc)
|
59
59
|
return getMutationKeyFromPath(path)
|
package/src/tanstack-query.ts
CHANGED
@@ -20,8 +20,8 @@ export interface ORPCAdditionalQueryFilters<TFilterInput> {
|
|
20
20
|
|
21
21
|
export interface ORPCQueryFilters<TFilterInput>
|
22
22
|
extends SetOptional<QueryFilters, 'queryKey'>,
|
23
|
-
|
23
|
+
ORPCAdditionalQueryFilters<TFilterInput> {}
|
24
24
|
|
25
25
|
export interface ORPCInvalidateQueryFilters<TFilterInput>
|
26
26
|
extends SetOptional<InvalidateQueryFilters, 'queryKey'>,
|
27
|
-
|
27
|
+
ORPCAdditionalQueryFilters<TFilterInput> {}
|
package/src/types.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import type { Promisable } from '@orpc/
|
1
|
+
import type { Promisable } from '@orpc/shared'
|
2
2
|
import { orpcClient } from '../../tests/orpc'
|
3
3
|
import { createUseQueriesBuilder } from './builder'
|
4
4
|
|
@@ -19,7 +19,7 @@ it('createUseQueriesBuilder', () => {
|
|
19
19
|
builder({ id: 123 })
|
20
20
|
|
21
21
|
if (typeof result.queryFn === 'function') {
|
22
|
-
expectTypeOf(result.queryFn({} as any)).
|
22
|
+
expectTypeOf(result.queryFn({} as any)).toMatchTypeOf<
|
23
23
|
Promisable<{
|
24
24
|
id: string
|
25
25
|
name: string
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import type { ProcedureClient } from '@orpc/client'
|
2
2
|
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
|
3
|
-
import type {} from '@orpc/server'
|
4
3
|
import type { SetOptional } from '@orpc/shared'
|
5
4
|
import type {
|
6
5
|
DefaultError,
|
@@ -26,23 +25,23 @@ type UseQueryOptionsForUseQueries<
|
|
26
25
|
export interface UseQueriesBuilder<
|
27
26
|
TInputSchema extends Schema,
|
28
27
|
TOutputSchema extends Schema,
|
29
|
-
|
28
|
+
TFuncOutput extends SchemaOutput<TOutputSchema>,
|
30
29
|
> {
|
31
30
|
(
|
32
31
|
input: SchemaInput<TInputSchema>,
|
33
32
|
options?: SetOptional<
|
34
|
-
UseQueryOptionsForUseQueries<SchemaOutput<TOutputSchema,
|
33
|
+
UseQueryOptionsForUseQueries<SchemaOutput<TOutputSchema, TFuncOutput>>,
|
35
34
|
'queryFn' | 'queryKey'
|
36
35
|
>,
|
37
|
-
): UseQueryOptionsForUseQueries<SchemaOutput<TOutputSchema,
|
36
|
+
): UseQueryOptionsForUseQueries<SchemaOutput<TOutputSchema, TFuncOutput>>
|
38
37
|
}
|
39
38
|
|
40
39
|
export interface CreateUseQueriesBuilderOptions<
|
41
40
|
TInputSchema extends Schema,
|
42
41
|
TOutputSchema extends Schema,
|
43
|
-
|
42
|
+
TFuncOutput extends SchemaOutput<TOutputSchema>,
|
44
43
|
> {
|
45
|
-
client: ProcedureClient<TInputSchema, TOutputSchema,
|
44
|
+
client: ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput>
|
46
45
|
|
47
46
|
/**
|
48
47
|
* The path of procedure on server
|
@@ -53,15 +52,15 @@ export interface CreateUseQueriesBuilderOptions<
|
|
53
52
|
export function createUseQueriesBuilder<
|
54
53
|
TInputSchema extends Schema = undefined,
|
55
54
|
TOutputSchema extends Schema = undefined,
|
56
|
-
|
57
|
-
|
55
|
+
TFuncOutput extends
|
56
|
+
SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
|
58
57
|
>(
|
59
58
|
options: CreateUseQueriesBuilderOptions<
|
60
59
|
TInputSchema,
|
61
60
|
TOutputSchema,
|
62
|
-
|
61
|
+
TFuncOutput
|
63
62
|
>,
|
64
|
-
): UseQueriesBuilder<TInputSchema, TOutputSchema,
|
63
|
+
): UseQueriesBuilder<TInputSchema, TOutputSchema, TFuncOutput> {
|
65
64
|
return (input, options_) => {
|
66
65
|
return {
|
67
66
|
queryKey: getQueryKeyFromPath(options.path, { input, type: 'query' }),
|
@@ -9,7 +9,7 @@ import type {
|
|
9
9
|
} from '@orpc/contract'
|
10
10
|
import type { Procedure, Router } from '@orpc/server'
|
11
11
|
import type {} from '@tanstack/react-query'
|
12
|
-
import { type UseQueriesBuilder
|
12
|
+
import { createUseQueriesBuilder, type UseQueriesBuilder } from './builder'
|
13
13
|
|
14
14
|
export type UseQueriesBuildersWithContractRouter<
|
15
15
|
TRouter extends ContractRouter,
|
@@ -19,10 +19,10 @@ export type UseQueriesBuildersWithContractRouter<
|
|
19
19
|
infer UOutputSchema
|
20
20
|
>
|
21
21
|
? UseQueriesBuilder<
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
UInputSchema,
|
23
|
+
UOutputSchema,
|
24
|
+
SchemaOutput<UOutputSchema>
|
25
|
+
>
|
26
26
|
: TRouter[K] extends ContractRouter
|
27
27
|
? UseQueriesBuildersWithContractRouter<TRouter[K]>
|
28
28
|
: never
|
@@ -34,9 +34,9 @@ export type UseQueriesBuildersWithRouter<TRouter extends Router<any>> = {
|
|
34
34
|
any,
|
35
35
|
infer UInputSchema,
|
36
36
|
infer UOutputSchema,
|
37
|
-
infer
|
37
|
+
infer UFuncOutput
|
38
38
|
>
|
39
|
-
? UseQueriesBuilder<UInputSchema, UOutputSchema,
|
39
|
+
? UseQueriesBuilder<UInputSchema, UOutputSchema, UFuncOutput>
|
40
40
|
: TRouter[K] extends Router<any>
|
41
41
|
? UseQueriesBuildersWithRouter<TRouter[K]>
|
42
42
|
: never
|
@@ -62,10 +62,10 @@ export function createUseQueriesBuilders<
|
|
62
62
|
>(
|
63
63
|
options: CreateUseQueriesBuildersOptions<TRouter>,
|
64
64
|
): TRouter extends Router<any>
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
65
|
+
? UseQueriesBuildersWithRouter<TRouter>
|
66
|
+
: TRouter extends ContractRouter
|
67
|
+
? UseQueriesBuildersWithContractRouter<TRouter>
|
68
|
+
: never {
|
69
69
|
const path = options.path ?? []
|
70
70
|
const client = options.client as any
|
71
71
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import type { SchemaOutput } from '@orpc/contract'
|
2
2
|
import {
|
3
|
+
orpcClient,
|
3
4
|
ORPCContext,
|
4
5
|
type UserListOutputSchema,
|
5
6
|
type UserSchema,
|
6
|
-
orpcClient,
|
7
7
|
} from '../../tests/orpc'
|
8
8
|
import { createUseQueriesBuilders } from './builders'
|
9
9
|
import { useQueriesFactory } from './hook'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
import { renderHook, waitFor } from '@testing-library/react'
|
2
|
-
import {
|
2
|
+
import { orpcClient, ORPCContext, wrapper } from '../../tests/orpc'
|
3
3
|
import { createUseQueriesBuilders } from './builders'
|
4
4
|
import { useQueriesFactory } from './hook'
|
5
5
|
|
@@ -18,7 +18,7 @@ describe('useQueriesFactory', () => {
|
|
18
18
|
|
19
19
|
return [o.user.find({ id: '123' }), o.user.list({})]
|
20
20
|
}),
|
21
|
-
{ wrapper
|
21
|
+
{ wrapper },
|
22
22
|
)
|
23
23
|
|
24
24
|
await waitFor(() =>
|
package/src/use-queries/hook.ts
CHANGED
@@ -7,9 +7,9 @@ import {
|
|
7
7
|
} from '@tanstack/react-query'
|
8
8
|
import { type ORPCContext, useORPCContext } from '../react-context'
|
9
9
|
import {
|
10
|
+
createUseQueriesBuilders,
|
10
11
|
type UseQueriesBuildersWithContractRouter,
|
11
12
|
type UseQueriesBuildersWithRouter,
|
12
|
-
createUseQueriesBuilders,
|
13
13
|
} from './builders'
|
14
14
|
|
15
15
|
export interface UseQueriesWithContractRouter<TRouter extends ContractRouter> {
|
@@ -39,19 +39,19 @@ export interface UseQueriesFactoryOptions<
|
|
39
39
|
export function useQueriesFactory<TRouter extends Router<any> | ContractRouter>(
|
40
40
|
options: UseQueriesFactoryOptions<TRouter>,
|
41
41
|
): TRouter extends Router<any>
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
const
|
42
|
+
? UseQueriesWithRouter<TRouter>
|
43
|
+
: TRouter extends ContractRouter
|
44
|
+
? UseQueriesWithContractRouter<TRouter>
|
45
|
+
: never {
|
46
|
+
const Hook = (build: any, combine?: any): any => {
|
47
47
|
const orpc = useORPCContext(options.context)
|
48
48
|
const builders = createUseQueriesBuilders({ client: orpc.client as any })
|
49
49
|
|
50
50
|
return useQueries({
|
51
51
|
queries: build(builders),
|
52
|
-
combine
|
52
|
+
combine,
|
53
53
|
})
|
54
54
|
}
|
55
55
|
|
56
|
-
return
|
56
|
+
return Hook as any
|
57
57
|
}
|