@orpc/react 0.10.0 → 0.12.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/dist/index.js +0 -1
- package/dist/src/general-hooks.d.ts +0 -1
- package/dist/src/general-utils.d.ts +0 -1
- package/dist/src/index.d.ts +0 -1
- package/dist/src/orpc-path.d.ts +0 -1
- package/dist/src/procedure-hooks.d.ts +0 -1
- package/dist/src/procedure-utils.d.ts +0 -1
- package/dist/src/react-context.d.ts +0 -1
- package/dist/src/react-hooks.d.ts +0 -1
- package/dist/src/react-utils.d.ts +0 -1
- package/dist/src/react.d.ts +0 -1
- package/dist/src/tanstack-key.d.ts +0 -1
- package/dist/src/tanstack-query.d.ts +0 -1
- package/dist/src/types.d.ts +0 -1
- package/dist/src/use-queries/builder.d.ts +0 -1
- package/dist/src/use-queries/builders.d.ts +0 -1
- package/dist/src/use-queries/hook.d.ts +0 -1
- package/package.json +12 -16
- package/dist/index.js.map +0 -1
- package/dist/src/general-hooks.d.ts.map +0 -1
- package/dist/src/general-utils.d.ts.map +0 -1
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/orpc-path.d.ts.map +0 -1
- package/dist/src/procedure-hooks.d.ts.map +0 -1
- package/dist/src/procedure-utils.d.ts.map +0 -1
- package/dist/src/react-context.d.ts.map +0 -1
- package/dist/src/react-hooks.d.ts.map +0 -1
- package/dist/src/react-utils.d.ts.map +0 -1
- package/dist/src/react.d.ts.map +0 -1
- package/dist/src/tanstack-key.d.ts.map +0 -1
- package/dist/src/tanstack-query.d.ts.map +0 -1
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/use-queries/builder.d.ts.map +0 -1
- package/dist/src/use-queries/builders.d.ts.map +0 -1
- package/dist/src/use-queries/hook.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/src/general-hooks.test-d.ts +0 -151
- package/src/general-hooks.test.tsx +0 -232
- package/src/general-hooks.ts +0 -101
- package/src/general-utils.test-d.ts +0 -454
- package/src/general-utils.test.tsx +0 -818
- package/src/general-utils.ts +0 -393
- package/src/index.ts +0 -8
- package/src/orpc-path.test-d.ts +0 -13
- package/src/orpc-path.test.ts +0 -12
- package/src/orpc-path.ts +0 -24
- package/src/procedure-hooks.test-d.ts +0 -321
- package/src/procedure-hooks.test.tsx +0 -388
- package/src/procedure-hooks.ts +0 -271
- package/src/procedure-utils.test-d.ts +0 -476
- package/src/procedure-utils.test.tsx +0 -330
- package/src/procedure-utils.ts +0 -312
- package/src/react-context.ts +0 -43
- package/src/react-hooks.ts +0 -94
- package/src/react-utils.ts +0 -98
- package/src/react.test-d.ts +0 -89
- package/src/react.test.tsx +0 -102
- package/src/react.tsx +0 -81
- package/src/tanstack-key.test-d.ts +0 -35
- package/src/tanstack-key.test.ts +0 -62
- package/src/tanstack-key.ts +0 -64
- package/src/tanstack-query.ts +0 -27
- package/src/types.ts +0 -7
- package/src/use-queries/builder.test-d.ts +0 -29
- package/src/use-queries/builder.test.ts +0 -25
- package/src/use-queries/builder.ts +0 -71
- package/src/use-queries/builders.test-d.ts +0 -30
- package/src/use-queries/builders.test.tsx +0 -29
- package/src/use-queries/builders.ts +0 -101
- package/src/use-queries/hook.test-d.ts +0 -64
- package/src/use-queries/hook.test.tsx +0 -89
- package/src/use-queries/hook.ts +0 -57
@@ -1,25 +0,0 @@
|
|
1
|
-
import { orpcClient } from '../../tests/orpc'
|
2
|
-
import { createUseQueriesBuilder } from './builder'
|
3
|
-
|
4
|
-
it('createUseQueriesBuilder', async () => {
|
5
|
-
const builder = createUseQueriesBuilder({
|
6
|
-
client: orpcClient.user.find,
|
7
|
-
path: ['user', 'find'],
|
8
|
-
})
|
9
|
-
|
10
|
-
const options = builder({ id: '123' })
|
11
|
-
|
12
|
-
expect(options.queryKey).toEqual([
|
13
|
-
['user', 'find'],
|
14
|
-
{ input: { id: '123' }, type: 'query' },
|
15
|
-
])
|
16
|
-
|
17
|
-
expect(options.queryFn).toBeInstanceOf(Function)
|
18
|
-
|
19
|
-
const result = await (options as any).queryFn({} as any)
|
20
|
-
|
21
|
-
expect(result).toEqual({
|
22
|
-
id: '123',
|
23
|
-
name: 'name-123',
|
24
|
-
})
|
25
|
-
})
|
@@ -1,71 +0,0 @@
|
|
1
|
-
import type { ProcedureClient } from '@orpc/client'
|
2
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
|
3
|
-
import type { SetOptional } from '@orpc/shared'
|
4
|
-
import type {
|
5
|
-
DefaultError,
|
6
|
-
OmitKeyof,
|
7
|
-
QueriesPlaceholderDataFunction,
|
8
|
-
QueryKey,
|
9
|
-
UseQueryOptions,
|
10
|
-
} from '@tanstack/react-query'
|
11
|
-
import { getQueryKeyFromPath } from '../tanstack-key'
|
12
|
-
|
13
|
-
type UseQueryOptionsForUseQueries<
|
14
|
-
TQueryFnData,
|
15
|
-
TError = DefaultError,
|
16
|
-
TData = TQueryFnData,
|
17
|
-
TQueryKey extends QueryKey = QueryKey,
|
18
|
-
> = OmitKeyof<
|
19
|
-
UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
|
20
|
-
'placeholderData'
|
21
|
-
> & {
|
22
|
-
placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>
|
23
|
-
}
|
24
|
-
|
25
|
-
export interface UseQueriesBuilder<
|
26
|
-
TInputSchema extends Schema,
|
27
|
-
TOutputSchema extends Schema,
|
28
|
-
TFuncOutput extends SchemaOutput<TOutputSchema>,
|
29
|
-
> {
|
30
|
-
(
|
31
|
-
input: SchemaInput<TInputSchema>,
|
32
|
-
options?: SetOptional<
|
33
|
-
UseQueryOptionsForUseQueries<SchemaOutput<TOutputSchema, TFuncOutput>>,
|
34
|
-
'queryFn' | 'queryKey'
|
35
|
-
>,
|
36
|
-
): UseQueryOptionsForUseQueries<SchemaOutput<TOutputSchema, TFuncOutput>>
|
37
|
-
}
|
38
|
-
|
39
|
-
export interface CreateUseQueriesBuilderOptions<
|
40
|
-
TInputSchema extends Schema,
|
41
|
-
TOutputSchema extends Schema,
|
42
|
-
TFuncOutput extends SchemaOutput<TOutputSchema>,
|
43
|
-
> {
|
44
|
-
client: ProcedureClient<TInputSchema, TOutputSchema, TFuncOutput>
|
45
|
-
|
46
|
-
/**
|
47
|
-
* The path of procedure on server
|
48
|
-
*/
|
49
|
-
path: string[]
|
50
|
-
}
|
51
|
-
|
52
|
-
export function createUseQueriesBuilder<
|
53
|
-
TInputSchema extends Schema = undefined,
|
54
|
-
TOutputSchema extends Schema = undefined,
|
55
|
-
TFuncOutput extends
|
56
|
-
SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
|
57
|
-
>(
|
58
|
-
options: CreateUseQueriesBuilderOptions<
|
59
|
-
TInputSchema,
|
60
|
-
TOutputSchema,
|
61
|
-
TFuncOutput
|
62
|
-
>,
|
63
|
-
): UseQueriesBuilder<TInputSchema, TOutputSchema, TFuncOutput> {
|
64
|
-
return (input, options_) => {
|
65
|
-
return {
|
66
|
-
queryKey: getQueryKeyFromPath(options.path, { input, type: 'query' }),
|
67
|
-
queryFn: () => options.client(input),
|
68
|
-
...options_,
|
69
|
-
}
|
70
|
-
}
|
71
|
-
}
|
@@ -1,30 +0,0 @@
|
|
1
|
-
import { orpcClient } from '../../tests/orpc'
|
2
|
-
import { createUseQueriesBuilder } from './builder'
|
3
|
-
import { createUseQueriesBuilders } from './builders'
|
4
|
-
|
5
|
-
it('createUseQueriesBuilders', () => {
|
6
|
-
const builder = createUseQueriesBuilders({
|
7
|
-
client: orpcClient,
|
8
|
-
})
|
9
|
-
|
10
|
-
expectTypeOf(builder.user.find).toEqualTypeOf(
|
11
|
-
createUseQueriesBuilder({
|
12
|
-
client: orpcClient.user.find,
|
13
|
-
path: ['user', 'find'],
|
14
|
-
}),
|
15
|
-
)
|
16
|
-
|
17
|
-
expectTypeOf(builder.user.list).toEqualTypeOf(
|
18
|
-
createUseQueriesBuilder({
|
19
|
-
client: orpcClient.user.list,
|
20
|
-
path: ['user', 'list'],
|
21
|
-
}),
|
22
|
-
)
|
23
|
-
|
24
|
-
expectTypeOf(builder.ping).toEqualTypeOf(
|
25
|
-
createUseQueriesBuilder({
|
26
|
-
client: orpcClient.ping,
|
27
|
-
path: ['ping'],
|
28
|
-
}),
|
29
|
-
)
|
30
|
-
})
|
@@ -1,29 +0,0 @@
|
|
1
|
-
import { orpcClient } from '../../tests/orpc'
|
2
|
-
import { createUseQueriesBuilder } from './builder'
|
3
|
-
import { createUseQueriesBuilders } from './builders'
|
4
|
-
|
5
|
-
it('createUseQueriesBuilders', async () => {
|
6
|
-
const builder = createUseQueriesBuilders({
|
7
|
-
client: orpcClient,
|
8
|
-
})
|
9
|
-
|
10
|
-
const e1 = builder.user.find({ id: '123' })
|
11
|
-
const a1 = createUseQueriesBuilder({
|
12
|
-
client: orpcClient.user.find,
|
13
|
-
path: ['user', 'find'],
|
14
|
-
})({ id: '123' })
|
15
|
-
|
16
|
-
expect(e1.queryKey).toEqual(a1.queryKey)
|
17
|
-
|
18
|
-
expect(await (e1 as any).queryFn()).toEqual(await (a1 as any).queryFn())
|
19
|
-
|
20
|
-
const e2 = builder.user.list({})
|
21
|
-
const a2 = createUseQueriesBuilder({
|
22
|
-
client: orpcClient.user.list,
|
23
|
-
path: ['user', 'list'],
|
24
|
-
})({})
|
25
|
-
|
26
|
-
expect(e2.queryKey).toEqual(a2.queryKey)
|
27
|
-
|
28
|
-
expect(await (e2 as any).queryFn()).toEqual(await (a2 as any).queryFn())
|
29
|
-
})
|
@@ -1,101 +0,0 @@
|
|
1
|
-
import type {
|
2
|
-
RouterClientWithContractRouter,
|
3
|
-
RouterClientWithRouter,
|
4
|
-
} from '@orpc/client'
|
5
|
-
import type {
|
6
|
-
ContractProcedure,
|
7
|
-
ContractRouter,
|
8
|
-
SchemaOutput,
|
9
|
-
} from '@orpc/contract'
|
10
|
-
import type { Procedure, Router } from '@orpc/server'
|
11
|
-
import type {} from '@tanstack/react-query'
|
12
|
-
import { createUseQueriesBuilder, type UseQueriesBuilder } from './builder'
|
13
|
-
|
14
|
-
export type UseQueriesBuildersWithContractRouter<
|
15
|
-
TRouter extends ContractRouter,
|
16
|
-
> = {
|
17
|
-
[K in keyof TRouter]: TRouter[K] extends ContractProcedure<
|
18
|
-
infer UInputSchema,
|
19
|
-
infer UOutputSchema
|
20
|
-
>
|
21
|
-
? UseQueriesBuilder<
|
22
|
-
UInputSchema,
|
23
|
-
UOutputSchema,
|
24
|
-
SchemaOutput<UOutputSchema>
|
25
|
-
>
|
26
|
-
: TRouter[K] extends ContractRouter
|
27
|
-
? UseQueriesBuildersWithContractRouter<TRouter[K]>
|
28
|
-
: never
|
29
|
-
}
|
30
|
-
|
31
|
-
export type UseQueriesBuildersWithRouter<TRouter extends Router<any>> = {
|
32
|
-
[K in keyof TRouter]: TRouter[K] extends Procedure<
|
33
|
-
any,
|
34
|
-
any,
|
35
|
-
infer UInputSchema,
|
36
|
-
infer UOutputSchema,
|
37
|
-
infer UFuncOutput
|
38
|
-
>
|
39
|
-
? UseQueriesBuilder<UInputSchema, UOutputSchema, UFuncOutput>
|
40
|
-
: TRouter[K] extends Router<any>
|
41
|
-
? UseQueriesBuildersWithRouter<TRouter[K]>
|
42
|
-
: never
|
43
|
-
}
|
44
|
-
|
45
|
-
export interface CreateUseQueriesBuildersOptions<
|
46
|
-
TRouter extends Router<any> | ContractRouter,
|
47
|
-
> {
|
48
|
-
client: TRouter extends Router<any>
|
49
|
-
? RouterClientWithRouter<TRouter>
|
50
|
-
: TRouter extends ContractRouter
|
51
|
-
? RouterClientWithContractRouter<TRouter>
|
52
|
-
: never
|
53
|
-
|
54
|
-
/**
|
55
|
-
* The path of router on server
|
56
|
-
*/
|
57
|
-
path?: string[]
|
58
|
-
}
|
59
|
-
|
60
|
-
export function createUseQueriesBuilders<
|
61
|
-
TRouter extends Router<any> | ContractRouter,
|
62
|
-
>(
|
63
|
-
options: CreateUseQueriesBuildersOptions<TRouter>,
|
64
|
-
): TRouter extends Router<any>
|
65
|
-
? UseQueriesBuildersWithRouter<TRouter>
|
66
|
-
: TRouter extends ContractRouter
|
67
|
-
? UseQueriesBuildersWithContractRouter<TRouter>
|
68
|
-
: never {
|
69
|
-
const path = options.path ?? []
|
70
|
-
const client = options.client as any
|
71
|
-
|
72
|
-
/**
|
73
|
-
* For sure root is not procedure so do not create builder on root
|
74
|
-
*/
|
75
|
-
const builder = path.length ? createUseQueriesBuilder({ client, path }) : {}
|
76
|
-
|
77
|
-
return new Proxy(builder, {
|
78
|
-
get(target, key) {
|
79
|
-
const value = Reflect.get(target, key)
|
80
|
-
|
81
|
-
if (typeof key !== 'string') {
|
82
|
-
return value
|
83
|
-
}
|
84
|
-
|
85
|
-
const nextBuilders = createUseQueriesBuilders({
|
86
|
-
client: client[key],
|
87
|
-
path: [...path, key],
|
88
|
-
})
|
89
|
-
|
90
|
-
if (typeof value !== 'function') {
|
91
|
-
return nextBuilders
|
92
|
-
}
|
93
|
-
|
94
|
-
return new Proxy(value, {
|
95
|
-
get(_, key) {
|
96
|
-
return Reflect.get(nextBuilders, key)
|
97
|
-
},
|
98
|
-
})
|
99
|
-
},
|
100
|
-
}) as any
|
101
|
-
}
|
@@ -1,64 +0,0 @@
|
|
1
|
-
import type { SchemaOutput } from '@orpc/contract'
|
2
|
-
import {
|
3
|
-
orpcClient,
|
4
|
-
ORPCContext,
|
5
|
-
type UserListOutputSchema,
|
6
|
-
type UserSchema,
|
7
|
-
} from '../../tests/orpc'
|
8
|
-
import { createUseQueriesBuilders } from './builders'
|
9
|
-
import { useQueriesFactory } from './hook'
|
10
|
-
|
11
|
-
describe('useQueriesFactory', () => {
|
12
|
-
const useQueries = useQueriesFactory({
|
13
|
-
context: ORPCContext,
|
14
|
-
})
|
15
|
-
|
16
|
-
it('simple', () => {
|
17
|
-
const [findQuery, listQuery] = useQueries((o) => {
|
18
|
-
expectTypeOf(o).toEqualTypeOf(
|
19
|
-
createUseQueriesBuilders({ client: orpcClient }),
|
20
|
-
)
|
21
|
-
|
22
|
-
return [o.user.find({ id: '123' }), o.user.list({})]
|
23
|
-
})
|
24
|
-
|
25
|
-
expectTypeOf(findQuery.data).toEqualTypeOf<
|
26
|
-
SchemaOutput<typeof UserSchema> | undefined
|
27
|
-
>()
|
28
|
-
|
29
|
-
expectTypeOf(listQuery.data).toEqualTypeOf<
|
30
|
-
SchemaOutput<typeof UserListOutputSchema> | undefined
|
31
|
-
>()
|
32
|
-
})
|
33
|
-
|
34
|
-
it('with combine', () => {
|
35
|
-
const [findData, listData] = useQueries(
|
36
|
-
(o) => {
|
37
|
-
expectTypeOf(o).toEqualTypeOf(
|
38
|
-
createUseQueriesBuilders({ client: orpcClient }),
|
39
|
-
)
|
40
|
-
|
41
|
-
return [o.user.find({ id: '123' }), o.user.list({})]
|
42
|
-
},
|
43
|
-
([findQuery, listQuery]) => {
|
44
|
-
expectTypeOf(findQuery.data).toEqualTypeOf<
|
45
|
-
SchemaOutput<typeof UserSchema> | undefined
|
46
|
-
>()
|
47
|
-
|
48
|
-
expectTypeOf(listQuery.data).toEqualTypeOf<
|
49
|
-
SchemaOutput<typeof UserListOutputSchema> | undefined
|
50
|
-
>()
|
51
|
-
|
52
|
-
return [findQuery.data, listQuery.data] as const
|
53
|
-
},
|
54
|
-
)
|
55
|
-
|
56
|
-
expectTypeOf(findData).toEqualTypeOf<
|
57
|
-
SchemaOutput<typeof UserSchema> | undefined
|
58
|
-
>()
|
59
|
-
|
60
|
-
expectTypeOf(listData).toEqualTypeOf<
|
61
|
-
SchemaOutput<typeof UserListOutputSchema> | undefined
|
62
|
-
>()
|
63
|
-
})
|
64
|
-
})
|
@@ -1,89 +0,0 @@
|
|
1
|
-
import { renderHook, waitFor } from '@testing-library/react'
|
2
|
-
import { orpcClient, ORPCContext, wrapper } from '../../tests/orpc'
|
3
|
-
import { createUseQueriesBuilders } from './builders'
|
4
|
-
import { useQueriesFactory } from './hook'
|
5
|
-
|
6
|
-
describe('useQueriesFactory', () => {
|
7
|
-
const useQueries = useQueriesFactory({
|
8
|
-
context: ORPCContext,
|
9
|
-
})
|
10
|
-
|
11
|
-
it('simple', async () => {
|
12
|
-
const queries = renderHook(
|
13
|
-
() =>
|
14
|
-
useQueries((o) => {
|
15
|
-
expectTypeOf(o).toEqualTypeOf(
|
16
|
-
createUseQueriesBuilders({ client: orpcClient }),
|
17
|
-
)
|
18
|
-
|
19
|
-
return [o.user.find({ id: '123' }), o.user.list({})]
|
20
|
-
}),
|
21
|
-
{ wrapper },
|
22
|
-
)
|
23
|
-
|
24
|
-
await waitFor(() =>
|
25
|
-
expect(queries.result.current[0].data).toEqual({
|
26
|
-
id: '123',
|
27
|
-
name: 'name-123',
|
28
|
-
}),
|
29
|
-
)
|
30
|
-
|
31
|
-
await waitFor(() =>
|
32
|
-
expect(queries.result.current[1].data).toEqual({
|
33
|
-
nextCursor: 2,
|
34
|
-
users: [
|
35
|
-
{
|
36
|
-
id: 'id-0',
|
37
|
-
name: 'number-0',
|
38
|
-
},
|
39
|
-
{
|
40
|
-
id: 'id-1',
|
41
|
-
name: 'number-1',
|
42
|
-
},
|
43
|
-
],
|
44
|
-
}),
|
45
|
-
)
|
46
|
-
})
|
47
|
-
|
48
|
-
it('with combine', async () => {
|
49
|
-
const data = renderHook(
|
50
|
-
() =>
|
51
|
-
useQueries(
|
52
|
-
(o) => {
|
53
|
-
expectTypeOf(o).toEqualTypeOf(
|
54
|
-
createUseQueriesBuilders({ client: orpcClient }),
|
55
|
-
)
|
56
|
-
|
57
|
-
return [o.user.find({ id: '123' }), o.user.list({})]
|
58
|
-
},
|
59
|
-
([findQuery, listQuery]) => {
|
60
|
-
return [findQuery.data, listQuery.data] as const
|
61
|
-
},
|
62
|
-
),
|
63
|
-
{ wrapper },
|
64
|
-
)
|
65
|
-
|
66
|
-
await waitFor(() =>
|
67
|
-
expect(data.result.current[0]).toEqual({
|
68
|
-
id: '123',
|
69
|
-
name: 'name-123',
|
70
|
-
}),
|
71
|
-
)
|
72
|
-
|
73
|
-
await waitFor(() =>
|
74
|
-
expect(data.result.current[1]).toEqual({
|
75
|
-
nextCursor: 2,
|
76
|
-
users: [
|
77
|
-
{
|
78
|
-
id: 'id-0',
|
79
|
-
name: 'number-0',
|
80
|
-
},
|
81
|
-
{
|
82
|
-
id: 'id-1',
|
83
|
-
name: 'number-1',
|
84
|
-
},
|
85
|
-
],
|
86
|
-
}),
|
87
|
-
)
|
88
|
-
})
|
89
|
-
})
|
package/src/use-queries/hook.ts
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
import type { ContractRouter } from '@orpc/contract'
|
2
|
-
import type { Router } from '@orpc/server'
|
3
|
-
import {
|
4
|
-
type QueriesOptions,
|
5
|
-
type QueriesResults,
|
6
|
-
useQueries,
|
7
|
-
} from '@tanstack/react-query'
|
8
|
-
import { type ORPCContext, useORPCContext } from '../react-context'
|
9
|
-
import {
|
10
|
-
createUseQueriesBuilders,
|
11
|
-
type UseQueriesBuildersWithContractRouter,
|
12
|
-
type UseQueriesBuildersWithRouter,
|
13
|
-
} from './builders'
|
14
|
-
|
15
|
-
export interface UseQueriesWithContractRouter<TRouter extends ContractRouter> {
|
16
|
-
<T extends Array<any> = [], TCombinedResult = QueriesResults<T>>(
|
17
|
-
build: (
|
18
|
-
builders: UseQueriesBuildersWithContractRouter<TRouter>,
|
19
|
-
) => [...QueriesOptions<T>],
|
20
|
-
combine?: (result: QueriesResults<T>) => TCombinedResult,
|
21
|
-
): TCombinedResult
|
22
|
-
}
|
23
|
-
|
24
|
-
export interface UseQueriesWithRouter<TRouter extends Router<any>> {
|
25
|
-
<T extends Array<any> = [], TCombinedResult = QueriesResults<T>>(
|
26
|
-
build: (
|
27
|
-
builders: UseQueriesBuildersWithRouter<TRouter>,
|
28
|
-
) => [...QueriesOptions<T>],
|
29
|
-
combine?: (result: QueriesResults<T>) => TCombinedResult,
|
30
|
-
): TCombinedResult
|
31
|
-
}
|
32
|
-
|
33
|
-
export interface UseQueriesFactoryOptions<
|
34
|
-
TRouter extends Router<any> | ContractRouter,
|
35
|
-
> {
|
36
|
-
context: ORPCContext<TRouter>
|
37
|
-
}
|
38
|
-
|
39
|
-
export function useQueriesFactory<TRouter extends Router<any> | ContractRouter>(
|
40
|
-
options: UseQueriesFactoryOptions<TRouter>,
|
41
|
-
): TRouter extends Router<any>
|
42
|
-
? UseQueriesWithRouter<TRouter>
|
43
|
-
: TRouter extends ContractRouter
|
44
|
-
? UseQueriesWithContractRouter<TRouter>
|
45
|
-
: never {
|
46
|
-
const Hook = (build: any, combine?: any): any => {
|
47
|
-
const orpc = useORPCContext(options.context)
|
48
|
-
const builders = createUseQueriesBuilders({ client: orpc.client as any })
|
49
|
-
|
50
|
-
return useQueries({
|
51
|
-
queries: build(builders),
|
52
|
-
combine,
|
53
|
-
})
|
54
|
-
}
|
55
|
-
|
56
|
-
return Hook as any
|
57
|
-
}
|