@orpc/react 0.0.4 → 0.0.5
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 +5 -5
- package/dist/src/general-hooks.d.ts.map +1 -1
- package/dist/src/general-utils.d.ts +17 -17
- 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 +11 -11
- package/dist/src/procedure-hooks.d.ts.map +1 -1
- package/dist/src/procedure-utils.d.ts +15 -15
- package/dist/src/procedure-utils.d.ts.map +1 -1
- package/dist/src/react-hooks.d.ts +1 -1
- package/dist/src/react-hooks.d.ts.map +1 -1
- package/dist/src/react-utils.d.ts +1 -1
- 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.map +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 +8 -7
- package/src/general-utils.test-d.ts +7 -7
- package/src/general-utils.test.tsx +25 -25
- package/src/general-utils.ts +67 -71
- 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 +25 -25
- package/src/procedure-utils.test-d.ts +9 -9
- package/src/procedure-utils.test.tsx +13 -13
- package/src/procedure-utils.ts +46 -49
- 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 +1 -2
- package/src/use-queries/builders.ts +9 -9
- 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/general-hooks.ts
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
|
2
2
|
import type { PartialDeep, SetOptional } from '@orpc/shared'
|
3
|
+
import type { ORPCQueryFilters } from './tanstack-query'
|
3
4
|
import {
|
4
5
|
type DefaultError,
|
5
6
|
type Mutation,
|
@@ -11,19 +12,18 @@ import {
|
|
11
12
|
} from '@tanstack/react-query'
|
12
13
|
import { type ORPCContext, useORPCContext } from './react-context'
|
13
14
|
import { getMutationKeyFromPath, getQueryKeyFromPath } from './tanstack-key'
|
14
|
-
import type { ORPCQueryFilters } from './tanstack-query'
|
15
15
|
|
16
16
|
export interface GeneralHooks<
|
17
17
|
TInputSchema extends Schema,
|
18
18
|
TOutputSchema extends Schema,
|
19
19
|
THandlerOutput extends SchemaOutput<TOutputSchema>,
|
20
20
|
> {
|
21
|
-
useIsFetching(
|
21
|
+
useIsFetching: (
|
22
22
|
filers?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
23
|
-
)
|
24
|
-
useIsMutating(filters?: SetOptional<MutationFilters, 'mutationKey'>)
|
23
|
+
) => number
|
24
|
+
useIsMutating: (filters?: SetOptional<MutationFilters, 'mutationKey'>) => number
|
25
25
|
|
26
|
-
useMutationState<
|
26
|
+
useMutationState: <
|
27
27
|
UResult = MutationState<
|
28
28
|
SchemaOutput<TOutputSchema, THandlerOutput>,
|
29
29
|
DefaultError,
|
@@ -38,7 +38,8 @@ export interface GeneralHooks<
|
|
38
38
|
SchemaInput<TInputSchema>
|
39
39
|
>,
|
40
40
|
) => UResult
|
41
|
-
}
|
41
|
+
}
|
42
|
+
) => UResult[]
|
42
43
|
}
|
43
44
|
|
44
45
|
export interface CreateGeneralHooksOptions {
|
@@ -56,7 +57,7 @@ export function createGeneralHooks<
|
|
56
57
|
TInputSchema extends Schema = undefined,
|
57
58
|
TOutputSchema extends Schema = undefined,
|
58
59
|
THandlerOutput extends
|
59
|
-
|
60
|
+
SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
|
60
61
|
>(
|
61
62
|
options: CreateGeneralHooksOptions,
|
62
63
|
): GeneralHooks<TInputSchema, TOutputSchema, THandlerOutput> {
|
@@ -2,17 +2,17 @@ import type { SchemaOutput } from '@orpc/contract'
|
|
2
2
|
import type { Promisable } from '@orpc/shared'
|
3
3
|
import type { InfiniteData } from '@tanstack/react-query'
|
4
4
|
import {
|
5
|
+
queryClient,
|
5
6
|
type UserCreateInputSchema,
|
6
7
|
type UserFindInputSchema,
|
7
8
|
type UserListInputSchema,
|
8
9
|
type UserListOutputSchema,
|
9
10
|
type UserSchema,
|
10
|
-
queryClient,
|
11
11
|
} from '../tests/orpc'
|
12
12
|
import { createGeneralUtils } from './general-utils'
|
13
13
|
|
14
14
|
const user_utils = createGeneralUtils({
|
15
|
-
queryClient
|
15
|
+
queryClient,
|
16
16
|
path: ['user'],
|
17
17
|
})
|
18
18
|
|
@@ -21,7 +21,7 @@ const user_find_utils = createGeneralUtils<
|
|
21
21
|
typeof UserSchema,
|
22
22
|
SchemaOutput<typeof UserSchema>
|
23
23
|
>({
|
24
|
-
queryClient
|
24
|
+
queryClient,
|
25
25
|
path: ['user', 'find'],
|
26
26
|
})
|
27
27
|
|
@@ -30,7 +30,7 @@ const user_list_utils = createGeneralUtils<
|
|
30
30
|
typeof UserListOutputSchema,
|
31
31
|
SchemaOutput<typeof UserListOutputSchema>
|
32
32
|
>({
|
33
|
-
queryClient
|
33
|
+
queryClient,
|
34
34
|
path: ['user', 'list'],
|
35
35
|
})
|
36
36
|
|
@@ -39,7 +39,7 @@ const user_create_utils = createGeneralUtils<
|
|
39
39
|
typeof UserSchema,
|
40
40
|
SchemaOutput<typeof UserSchema>
|
41
41
|
>({
|
42
|
-
queryClient
|
42
|
+
queryClient,
|
43
43
|
path: ['user', 'create'],
|
44
44
|
})
|
45
45
|
|
@@ -121,9 +121,9 @@ describe('setInfiniteQueriesData', () => {
|
|
121
121
|
user_list_utils.setInfiniteQueriesData({}, (old) => {
|
122
122
|
expectTypeOf(old).toEqualTypeOf<
|
123
123
|
| InfiniteData<
|
124
|
-
|
124
|
+
SchemaOutput<typeof UserListOutputSchema>,
|
125
125
|
number | undefined
|
126
|
-
|
126
|
+
>
|
127
127
|
| undefined
|
128
128
|
>()
|
129
129
|
|
@@ -1,11 +1,4 @@
|
|
1
1
|
import type { SchemaOutput } from '@orpc/contract'
|
2
|
-
import {
|
3
|
-
QueryClient,
|
4
|
-
useInfiniteQuery,
|
5
|
-
useMutation,
|
6
|
-
useQuery,
|
7
|
-
} from '@tanstack/react-query'
|
8
|
-
import { renderHook } from '@testing-library/react'
|
9
2
|
import type {
|
10
3
|
UserCreateInputSchema,
|
11
4
|
UserFindInputSchema,
|
@@ -13,6 +6,13 @@ import type {
|
|
13
6
|
UserListOutputSchema,
|
14
7
|
UserSchema,
|
15
8
|
} from '../tests/orpc'
|
9
|
+
import {
|
10
|
+
QueryClient,
|
11
|
+
useInfiniteQuery,
|
12
|
+
useMutation,
|
13
|
+
useQuery,
|
14
|
+
} from '@tanstack/react-query'
|
15
|
+
import { renderHook } from '@testing-library/react'
|
16
16
|
import { createGeneralUtils } from './general-utils'
|
17
17
|
|
18
18
|
let qc = new QueryClient()
|
@@ -299,8 +299,8 @@ describe('refetch', () => {
|
|
299
299
|
const infiniteQueryKey = [['user', 'list'], { type: 'infinite' }]
|
300
300
|
const queryKey = [['user', 'list'], { type: 'query' }]
|
301
301
|
|
302
|
-
const fn1 = vi.fn(() => new Promise(
|
303
|
-
const fn2 = vi.fn(() => new Promise(
|
302
|
+
const fn1 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 100)))
|
303
|
+
const fn2 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 100)))
|
304
304
|
|
305
305
|
beforeEach(() => {
|
306
306
|
fn1.mockClear()
|
@@ -321,7 +321,7 @@ describe('refetch', () => {
|
|
321
321
|
renderHook(() =>
|
322
322
|
useQuery(
|
323
323
|
{
|
324
|
-
queryKey
|
324
|
+
queryKey,
|
325
325
|
queryFn: fn2,
|
326
326
|
},
|
327
327
|
qc,
|
@@ -338,7 +338,7 @@ describe('refetch', () => {
|
|
338
338
|
expect(fn1).toHaveBeenCalledTimes(1)
|
339
339
|
expect(fn2).toHaveBeenCalledTimes(1)
|
340
340
|
|
341
|
-
await new Promise(
|
341
|
+
await new Promise(resolve => setTimeout(resolve, 101))
|
342
342
|
user_utils.refetch()
|
343
343
|
|
344
344
|
expect(fn1).toHaveBeenCalledTimes(2)
|
@@ -350,7 +350,7 @@ describe('refetch', () => {
|
|
350
350
|
expect(fn1).toHaveBeenCalledTimes(1)
|
351
351
|
expect(fn2).toHaveBeenCalledTimes(1)
|
352
352
|
|
353
|
-
await new Promise(
|
353
|
+
await new Promise(resolve => setTimeout(resolve, 101))
|
354
354
|
user_utils.refetch({ queryType: 'query' })
|
355
355
|
|
356
356
|
expect(fn1).toHaveBeenCalledTimes(1)
|
@@ -363,7 +363,7 @@ describe('refetch', () => {
|
|
363
363
|
expect(fn1).toHaveBeenCalledTimes(1)
|
364
364
|
expect(fn2).toHaveBeenCalledTimes(1)
|
365
365
|
|
366
|
-
await new Promise(
|
366
|
+
await new Promise(resolve => setTimeout(resolve, 101))
|
367
367
|
user_list_utils.refetch()
|
368
368
|
|
369
369
|
expect(fn1).toHaveBeenCalledTimes(2)
|
@@ -376,7 +376,7 @@ describe('refetch', () => {
|
|
376
376
|
expect(fn1).toHaveBeenCalledTimes(1)
|
377
377
|
expect(fn2).toHaveBeenCalledTimes(1)
|
378
378
|
|
379
|
-
await new Promise(
|
379
|
+
await new Promise(resolve => setTimeout(resolve, 101))
|
380
380
|
user_list_utils.refetch({ queryType: 'infinite' })
|
381
381
|
|
382
382
|
expect(fn1).toHaveBeenCalledTimes(2)
|
@@ -389,7 +389,7 @@ describe('refetch', () => {
|
|
389
389
|
expect(fn1).toHaveBeenCalledTimes(1)
|
390
390
|
expect(fn2).toHaveBeenCalledTimes(1)
|
391
391
|
|
392
|
-
await new Promise(
|
392
|
+
await new Promise(resolve => setTimeout(resolve, 101))
|
393
393
|
user_find_utils.refetch()
|
394
394
|
|
395
395
|
expect(fn1).toHaveBeenCalledTimes(1)
|
@@ -407,7 +407,7 @@ describe('cancel', () => {
|
|
407
407
|
{
|
408
408
|
queryKey: infiniteQueryKey,
|
409
409
|
queryFn: async () =>
|
410
|
-
await new Promise(
|
410
|
+
await new Promise(resolve => setTimeout(resolve, 100)),
|
411
411
|
getNextPageParam: () => 2,
|
412
412
|
initialPageParam: 1,
|
413
413
|
},
|
@@ -418,9 +418,9 @@ describe('cancel', () => {
|
|
418
418
|
renderHook(() =>
|
419
419
|
useQuery(
|
420
420
|
{
|
421
|
-
queryKey
|
421
|
+
queryKey,
|
422
422
|
queryFn: async () =>
|
423
|
-
await new Promise(
|
423
|
+
await new Promise(resolve => setTimeout(resolve, 100)),
|
424
424
|
},
|
425
425
|
qc,
|
426
426
|
),
|
@@ -516,8 +516,8 @@ describe('reset', () => {
|
|
516
516
|
const infiniteQueryKey = [['user', 'list'], { type: 'infinite' }]
|
517
517
|
const queryKey = [['user', 'list'], { type: 'query' }]
|
518
518
|
|
519
|
-
const fn1 = vi.fn(() => new Promise(
|
520
|
-
const fn2 = vi.fn(() => new Promise(
|
519
|
+
const fn1 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 100)))
|
520
|
+
const fn2 = vi.fn(() => new Promise(resolve => setTimeout(resolve, 100)))
|
521
521
|
|
522
522
|
beforeEach(() => {
|
523
523
|
fn1.mockClear()
|
@@ -538,7 +538,7 @@ describe('reset', () => {
|
|
538
538
|
renderHook(() =>
|
539
539
|
useQuery(
|
540
540
|
{
|
541
|
-
queryKey
|
541
|
+
queryKey,
|
542
542
|
queryFn: fn2,
|
543
543
|
},
|
544
544
|
qc,
|
@@ -594,7 +594,7 @@ it('isFetching', () => {
|
|
594
594
|
{
|
595
595
|
queryKey: infiniteQueryKey,
|
596
596
|
queryFn: async () =>
|
597
|
-
await new Promise(
|
597
|
+
await new Promise(resolve => setTimeout(resolve, 100)),
|
598
598
|
getNextPageParam: () => 2,
|
599
599
|
initialPageParam: 1,
|
600
600
|
},
|
@@ -605,9 +605,9 @@ it('isFetching', () => {
|
|
605
605
|
renderHook(() =>
|
606
606
|
useQuery(
|
607
607
|
{
|
608
|
-
queryKey
|
608
|
+
queryKey,
|
609
609
|
queryFn: async () =>
|
610
|
-
await new Promise(
|
610
|
+
await new Promise(resolve => setTimeout(resolve, 100)),
|
611
611
|
},
|
612
612
|
qc,
|
613
613
|
),
|
@@ -630,7 +630,7 @@ it('isMutating', async () => {
|
|
630
630
|
useMutation(
|
631
631
|
{
|
632
632
|
mutationKey: [['user', 'create']],
|
633
|
-
mutationFn: () => new Promise(
|
633
|
+
mutationFn: () => new Promise(resolve => setTimeout(resolve, 100)),
|
634
634
|
},
|
635
635
|
qc,
|
636
636
|
),
|
package/src/general-utils.ts
CHANGED
@@ -16,41 +16,39 @@ import type {
|
|
16
16
|
SetDataOptions,
|
17
17
|
Updater,
|
18
18
|
} from '@tanstack/react-query'
|
19
|
-
import { getMutationKeyFromPath, getQueryKeyFromPath } from './tanstack-key'
|
20
19
|
import type {
|
21
20
|
ORPCInvalidateQueryFilters,
|
22
21
|
ORPCQueryFilters,
|
23
22
|
} from './tanstack-query'
|
24
23
|
import type { SchemaInputForInfiniteQuery } from './types'
|
24
|
+
import { getMutationKeyFromPath, getQueryKeyFromPath } from './tanstack-key'
|
25
25
|
|
26
26
|
export interface GeneralUtils<
|
27
27
|
TInputSchema extends Schema,
|
28
28
|
TOutputSchema extends Schema,
|
29
29
|
THandlerOutput extends SchemaOutput<TOutputSchema>,
|
30
30
|
> {
|
31
|
-
getQueriesData(
|
31
|
+
getQueriesData: (
|
32
32
|
filters?: OmitKeyof<
|
33
33
|
ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
34
34
|
'queryType'
|
35
35
|
>,
|
36
|
-
)
|
37
|
-
getInfiniteQueriesData(
|
36
|
+
) => [QueryKey, SchemaOutput<TOutputSchema, THandlerOutput> | undefined][]
|
37
|
+
getInfiniteQueriesData: (
|
38
38
|
filters?: OmitKeyof<
|
39
39
|
ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>,
|
40
40
|
'queryType'
|
41
41
|
>,
|
42
|
-
)
|
42
|
+
) => [
|
43
43
|
QueryKey,
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
| undefined
|
50
|
-
),
|
44
|
+
| undefined
|
45
|
+
| InfiniteData<
|
46
|
+
SchemaOutput<TOutputSchema, THandlerOutput>,
|
47
|
+
SchemaInput<TInputSchema>['cursor']
|
48
|
+
>,
|
51
49
|
][]
|
52
50
|
|
53
|
-
setQueriesData(
|
51
|
+
setQueriesData: (
|
54
52
|
filters: OmitKeyof<
|
55
53
|
ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
56
54
|
'queryType'
|
@@ -60,78 +58,76 @@ export interface GeneralUtils<
|
|
60
58
|
SchemaOutput<TOutputSchema, THandlerOutput> | undefined
|
61
59
|
>,
|
62
60
|
options?: SetDataOptions,
|
63
|
-
)
|
64
|
-
setInfiniteQueriesData(
|
61
|
+
) => [QueryKey, SchemaOutput<TOutputSchema, THandlerOutput> | undefined][]
|
62
|
+
setInfiniteQueriesData: (
|
65
63
|
filters: OmitKeyof<
|
66
64
|
ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>,
|
67
65
|
'queryType'
|
68
66
|
>,
|
69
67
|
updater: Updater<
|
70
68
|
| InfiniteData<
|
71
|
-
|
72
|
-
|
73
|
-
|
69
|
+
SchemaOutput<TOutputSchema, THandlerOutput>,
|
70
|
+
SchemaInput<TInputSchema>['cursor']
|
71
|
+
>
|
74
72
|
| undefined,
|
75
73
|
| InfiniteData<
|
76
|
-
|
77
|
-
|
78
|
-
|
74
|
+
SchemaOutput<TOutputSchema, THandlerOutput>,
|
75
|
+
SchemaInput<TInputSchema>['cursor']
|
76
|
+
>
|
79
77
|
| undefined
|
80
78
|
>,
|
81
79
|
options?: SetDataOptions,
|
82
|
-
)
|
80
|
+
) => [
|
83
81
|
QueryKey,
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
| undefined
|
90
|
-
),
|
82
|
+
| undefined
|
83
|
+
| InfiniteData<
|
84
|
+
SchemaOutput<TOutputSchema, THandlerOutput>,
|
85
|
+
SchemaInput<TInputSchema>['cursor']
|
86
|
+
>,
|
91
87
|
][]
|
92
88
|
|
93
|
-
invalidate(
|
89
|
+
invalidate: (
|
94
90
|
filters?: ORPCInvalidateQueryFilters<
|
95
91
|
PartialDeep<SchemaInput<TInputSchema>>
|
96
92
|
>,
|
97
93
|
options?: InvalidateOptions,
|
98
|
-
)
|
99
|
-
refetch(
|
94
|
+
) => Promise<void>
|
95
|
+
refetch: (
|
100
96
|
filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
101
97
|
options?: RefetchOptions,
|
102
|
-
)
|
103
|
-
cancel(
|
98
|
+
) => Promise<void>
|
99
|
+
cancel: (
|
104
100
|
filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
105
101
|
options?: CancelOptions,
|
106
|
-
)
|
107
|
-
remove(
|
102
|
+
) => Promise<void>
|
103
|
+
remove: (
|
108
104
|
filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
109
|
-
)
|
110
|
-
reset(
|
105
|
+
) => void
|
106
|
+
reset: (
|
111
107
|
filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
112
108
|
options?: ResetOptions,
|
113
|
-
)
|
109
|
+
) => Promise<void>
|
114
110
|
|
115
|
-
isFetching(
|
111
|
+
isFetching: (
|
116
112
|
filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
117
|
-
)
|
118
|
-
isMutating(filters?: SetOptional<MutationFilters, 'mutationKey'>)
|
113
|
+
) => number
|
114
|
+
isMutating: (filters?: SetOptional<MutationFilters, 'mutationKey'>) => number
|
119
115
|
|
120
|
-
getQueryDefaults(
|
116
|
+
getQueryDefaults: (
|
121
117
|
filters?: Pick<
|
122
118
|
ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
123
119
|
'input' | 'queryKey'
|
124
120
|
>,
|
125
|
-
)
|
121
|
+
) => OmitKeyof<
|
126
122
|
QueryObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>>,
|
127
123
|
'queryKey'
|
128
124
|
>
|
129
|
-
getInfiniteQueryDefaults(
|
125
|
+
getInfiniteQueryDefaults: (
|
130
126
|
filters?: Pick<
|
131
127
|
ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>,
|
132
128
|
'input' | 'queryKey'
|
133
129
|
>,
|
134
|
-
)
|
130
|
+
) => OmitKeyof<
|
135
131
|
QueryObserverOptions<
|
136
132
|
SchemaOutput<TOutputSchema, THandlerOutput>,
|
137
133
|
DefaultError,
|
@@ -143,7 +139,7 @@ export interface GeneralUtils<
|
|
143
139
|
'queryKey'
|
144
140
|
>
|
145
141
|
|
146
|
-
setQueryDefaults(
|
142
|
+
setQueryDefaults: (
|
147
143
|
options: Partial<
|
148
144
|
OmitKeyof<
|
149
145
|
QueryObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>>,
|
@@ -154,8 +150,8 @@ export interface GeneralUtils<
|
|
154
150
|
ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
155
151
|
'input' | 'queryKey'
|
156
152
|
>,
|
157
|
-
)
|
158
|
-
setInfiniteQueryDefaults(
|
153
|
+
) => void
|
154
|
+
setInfiniteQueryDefaults: (
|
159
155
|
options: Partial<
|
160
156
|
OmitKeyof<
|
161
157
|
QueryObserverOptions<
|
@@ -173,7 +169,7 @@ export interface GeneralUtils<
|
|
173
169
|
ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
|
174
170
|
'input' | 'queryKey'
|
175
171
|
>,
|
176
|
-
)
|
172
|
+
) => void
|
177
173
|
|
178
174
|
getMutationDefaults: (
|
179
175
|
filters?: Pick<MutationFilters, 'mutationKey'>,
|
@@ -210,7 +206,7 @@ export function createGeneralUtils<
|
|
210
206
|
TInputSchema extends Schema = undefined,
|
211
207
|
TOutputSchema extends Schema = undefined,
|
212
208
|
THandlerOutput extends
|
213
|
-
|
209
|
+
SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
|
214
210
|
>(
|
215
211
|
options: CreateGeneralUtilsOptions,
|
216
212
|
): GeneralUtils<TInputSchema, TOutputSchema, THandlerOutput> {
|
@@ -344,40 +340,40 @@ export function createGeneralUtils<
|
|
344
340
|
|
345
341
|
getQueryDefaults(filters) {
|
346
342
|
return options.queryClient.getQueryDefaults(
|
347
|
-
filters?.queryKey
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
343
|
+
filters?.queryKey
|
344
|
+
?? getQueryKeyFromPath(options.path, {
|
345
|
+
input: filters?.input,
|
346
|
+
type: 'query',
|
347
|
+
}),
|
352
348
|
)
|
353
349
|
},
|
354
350
|
getInfiniteQueryDefaults(filters) {
|
355
351
|
return options.queryClient.getQueryDefaults(
|
356
|
-
filters?.queryKey
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
352
|
+
filters?.queryKey
|
353
|
+
?? getQueryKeyFromPath(options.path, {
|
354
|
+
input: filters?.input,
|
355
|
+
type: 'infinite',
|
356
|
+
}),
|
361
357
|
) as any
|
362
358
|
},
|
363
359
|
|
364
360
|
setQueryDefaults(options_, filters) {
|
365
361
|
return options.queryClient.setQueryDefaults(
|
366
|
-
filters?.queryKey
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
362
|
+
filters?.queryKey
|
363
|
+
?? getQueryKeyFromPath(options.path, {
|
364
|
+
input: filters?.input,
|
365
|
+
type: 'query',
|
366
|
+
}),
|
371
367
|
options_ as any,
|
372
368
|
)
|
373
369
|
},
|
374
370
|
setInfiniteQueryDefaults(options_, filters) {
|
375
371
|
return options.queryClient.setQueryDefaults(
|
376
|
-
filters?.queryKey
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
372
|
+
filters?.queryKey
|
373
|
+
?? getQueryKeyFromPath(options.path, {
|
374
|
+
input: filters?.input,
|
375
|
+
type: 'infinite',
|
376
|
+
}),
|
381
377
|
options_ as any,
|
382
378
|
)
|
383
379
|
},
|
package/src/index.ts
CHANGED
@@ -2,7 +2,7 @@ export * from './general-hooks'
|
|
2
2
|
export * from './general-utils'
|
3
3
|
export * from './procedure-hooks'
|
4
4
|
export * from './procedure-utils'
|
5
|
+
export * from './react'
|
5
6
|
export * from './react-context'
|
6
7
|
export * from './react-hooks'
|
7
8
|
export * from './react-utils'
|
8
|
-
export * from './react'
|
package/src/orpc-path.ts
CHANGED
@@ -81,9 +81,9 @@ describe('useInfiniteQuery', () => {
|
|
81
81
|
expectTypeOf(query.data).toEqualTypeOf<
|
82
82
|
| undefined
|
83
83
|
| InfiniteData<
|
84
|
-
|
84
|
+
SchemaOutput<typeof UserListOutputSchema>,
|
85
85
|
number | undefined
|
86
|
-
|
86
|
+
>
|
87
87
|
>()
|
88
88
|
})
|
89
89
|
|
@@ -111,11 +111,11 @@ describe('useInfiniteQuery', () => {
|
|
111
111
|
expectTypeOf(query.data).toEqualTypeOf<
|
112
112
|
| undefined
|
113
113
|
| {
|
114
|
-
|
115
|
-
|
114
|
+
select: InfiniteData<
|
115
|
+
SchemaOutput<typeof UserListOutputSchema>,
|
116
116
|
number | undefined
|
117
|
-
|
118
|
-
|
117
|
+
>
|
118
|
+
}
|
119
119
|
>()
|
120
120
|
})
|
121
121
|
})
|
@@ -2,12 +2,12 @@ import type { SchemaOutput } from '@orpc/contract'
|
|
2
2
|
import { renderHook, screen, waitFor } from '@testing-library/react'
|
3
3
|
import {
|
4
4
|
ORPCContext,
|
5
|
+
queryClient,
|
5
6
|
type UserCreateInputSchema,
|
6
7
|
type UserFindInputSchema,
|
7
8
|
type UserListInputSchema,
|
8
9
|
type UserListOutputSchema,
|
9
10
|
type UserSchema,
|
10
|
-
queryClient,
|
11
11
|
wrapper,
|
12
12
|
} from '../tests/orpc'
|
13
13
|
import { createProcedureHooks } from './procedure-hooks'
|