@orpc/react 0.0.0-unsafe-pr-2-20241118033608 → 0.0.0-unsafe-pr-9-20241121090958

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.
Files changed (53) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +66 -27
  3. package/dist/index.js.map +1 -0
  4. package/dist/src/general-hooks.d.ts +5 -5
  5. package/dist/src/general-hooks.d.ts.map +1 -1
  6. package/dist/src/general-utils.d.ts +17 -17
  7. package/dist/src/general-utils.d.ts.map +1 -1
  8. package/dist/src/index.d.ts +1 -1
  9. package/dist/src/index.d.ts.map +1 -1
  10. package/dist/src/procedure-hooks.d.ts +11 -11
  11. package/dist/src/procedure-hooks.d.ts.map +1 -1
  12. package/dist/src/procedure-utils.d.ts +15 -15
  13. package/dist/src/procedure-utils.d.ts.map +1 -1
  14. package/dist/src/react-hooks.d.ts +1 -1
  15. package/dist/src/react-hooks.d.ts.map +1 -1
  16. package/dist/src/react-utils.d.ts +1 -1
  17. package/dist/src/react-utils.d.ts.map +1 -1
  18. package/dist/src/react.d.ts +1 -1
  19. package/dist/src/react.d.ts.map +1 -1
  20. package/dist/src/tanstack-key.d.ts.map +1 -1
  21. package/dist/src/tanstack-query.d.ts.map +1 -1
  22. package/dist/src/types.d.ts.map +1 -1
  23. package/dist/src/use-queries/builder.d.ts.map +1 -1
  24. package/dist/src/use-queries/builders.d.ts.map +1 -1
  25. package/dist/src/use-queries/hook.d.ts.map +1 -1
  26. package/dist/tsconfig.tsbuildinfo +1 -1
  27. package/package.json +9 -8
  28. package/src/general-hooks.test.tsx +8 -8
  29. package/src/general-hooks.ts +8 -7
  30. package/src/general-utils.test-d.ts +7 -7
  31. package/src/general-utils.test.tsx +25 -25
  32. package/src/general-utils.ts +67 -71
  33. package/src/index.ts +1 -1
  34. package/src/orpc-path.ts +1 -1
  35. package/src/procedure-hooks.test-d.ts +6 -6
  36. package/src/procedure-hooks.test.tsx +1 -1
  37. package/src/procedure-hooks.ts +25 -25
  38. package/src/procedure-utils.test-d.ts +9 -9
  39. package/src/procedure-utils.test.tsx +13 -13
  40. package/src/procedure-utils.ts +46 -49
  41. package/src/react-hooks.ts +13 -21
  42. package/src/react-utils.ts +14 -25
  43. package/src/react.test-d.ts +6 -6
  44. package/src/react.test.tsx +8 -8
  45. package/src/react.tsx +6 -5
  46. package/src/tanstack-key.ts +9 -9
  47. package/src/tanstack-query.ts +2 -2
  48. package/src/types.ts +1 -1
  49. package/src/use-queries/builder.ts +1 -1
  50. package/src/use-queries/builders.ts +9 -9
  51. package/src/use-queries/hook.test-d.ts +1 -1
  52. package/src/use-queries/hook.test.tsx +2 -2
  53. package/src/use-queries/hook.ts +8 -8
@@ -1,8 +1,9 @@
1
1
  import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
2
+ import type { SchemaInputForInfiniteQuery } from './types'
2
3
  import {
4
+ get,
3
5
  type PartialOnUndefinedDeep,
4
6
  type SetOptional,
5
- get,
6
7
  } from '@orpc/shared'
7
8
  import {
8
9
  type DefaultError,
@@ -10,35 +11,34 @@ import {
10
11
  type FetchQueryOptions,
11
12
  type InfiniteData,
12
13
  type QueryKey,
14
+ useInfiniteQuery,
13
15
  type UseInfiniteQueryOptions,
14
16
  type UseInfiniteQueryResult,
17
+ useMutation,
15
18
  type UseMutationOptions,
16
19
  type UseMutationResult,
20
+ usePrefetchInfiniteQuery,
21
+ usePrefetchQuery,
22
+ useQuery,
17
23
  type UseQueryOptions,
18
24
  type UseQueryResult,
25
+ useSuspenseInfiniteQuery,
19
26
  type UseSuspenseInfiniteQueryOptions,
20
27
  type UseSuspenseInfiniteQueryResult,
28
+ useSuspenseQuery,
21
29
  type UseSuspenseQueryOptions,
22
30
  type UseSuspenseQueryResult,
23
- useInfiniteQuery,
24
- useMutation,
25
- usePrefetchInfiniteQuery,
26
- usePrefetchQuery,
27
- useQuery,
28
- useSuspenseInfiniteQuery,
29
- useSuspenseQuery,
30
31
  } from '@tanstack/react-query'
31
32
  import { orpcPathSymbol } from './orpc-path'
32
33
  import { type ORPCContext, useORPCContext } from './react-context'
33
34
  import { getMutationKeyFromPath, getQueryKeyFromPath } from './tanstack-key'
34
- import type { SchemaInputForInfiniteQuery } from './types'
35
35
 
36
36
  export interface ProcedureHooks<
37
37
  TInputSchema extends Schema,
38
38
  TOutputSchema extends Schema,
39
39
  THandlerOutput extends SchemaOutput<TOutputSchema>,
40
40
  > {
41
- useQuery<USelectData = SchemaOutput<TOutputSchema, THandlerOutput>>(
41
+ useQuery: <USelectData = SchemaOutput<TOutputSchema, THandlerOutput>>(
42
42
  input: SchemaInput<TInputSchema>,
43
43
  options?: SetOptional<
44
44
  UseQueryOptions<
@@ -48,8 +48,8 @@ export interface ProcedureHooks<
48
48
  >,
49
49
  'queryFn' | 'queryKey'
50
50
  >,
51
- ): UseQueryResult<USelectData>
52
- useInfiniteQuery<
51
+ ) => UseQueryResult<USelectData>
52
+ useInfiniteQuery: <
53
53
  USelectData = InfiniteData<
54
54
  SchemaOutput<TOutputSchema, THandlerOutput>,
55
55
  SchemaInput<TInputSchema>['cursor']
@@ -70,9 +70,9 @@ export interface ProcedureHooks<
70
70
  input: SchemaInputForInfiniteQuery<TInputSchema>
71
71
  }
72
72
  >,
73
- ): UseInfiniteQueryResult<USelectData>
73
+ ) => UseInfiniteQueryResult<USelectData>
74
74
 
75
- useSuspenseQuery<USelectData = SchemaOutput<TOutputSchema, THandlerOutput>>(
75
+ useSuspenseQuery: <USelectData = SchemaOutput<TOutputSchema, THandlerOutput>>(
76
76
  input: SchemaInput<TInputSchema>,
77
77
  options?: SetOptional<
78
78
  UseSuspenseQueryOptions<
@@ -82,8 +82,8 @@ export interface ProcedureHooks<
82
82
  >,
83
83
  'queryFn' | 'queryKey'
84
84
  >,
85
- ): UseSuspenseQueryResult<USelectData>
86
- useSuspenseInfiniteQuery<
85
+ ) => UseSuspenseQueryResult<USelectData>
86
+ useSuspenseInfiniteQuery: <
87
87
  USelectData = InfiniteData<
88
88
  SchemaOutput<TOutputSchema, THandlerOutput>,
89
89
  SchemaInput<TInputSchema>['cursor']
@@ -104,13 +104,13 @@ export interface ProcedureHooks<
104
104
  input: SchemaInputForInfiniteQuery<TInputSchema>
105
105
  }
106
106
  >,
107
- ): UseSuspenseInfiniteQueryResult<USelectData>
107
+ ) => UseSuspenseInfiniteQueryResult<USelectData>
108
108
 
109
- usePrefetchQuery(
109
+ usePrefetchQuery: (
110
110
  input: SchemaInput<TInputSchema>,
111
111
  options?: FetchQueryOptions<SchemaOutput<TOutputSchema, THandlerOutput>>,
112
- ): void
113
- usePrefetchInfiniteQuery(
112
+ ) => void
113
+ usePrefetchInfiniteQuery: (
114
114
  options: PartialOnUndefinedDeep<
115
115
  SetOptional<
116
116
  FetchInfiniteQueryOptions<
@@ -125,9 +125,9 @@ export interface ProcedureHooks<
125
125
  input: SchemaInputForInfiniteQuery<TInputSchema>
126
126
  }
127
127
  >,
128
- ): void
128
+ ) => void
129
129
 
130
- useMutation(
130
+ useMutation: (
131
131
  options?: SetOptional<
132
132
  UseMutationOptions<
133
133
  SchemaOutput<TOutputSchema, THandlerOutput>,
@@ -136,7 +136,7 @@ export interface ProcedureHooks<
136
136
  >,
137
137
  'mutationFn' | 'mutationKey'
138
138
  >,
139
- ): UseMutationResult<
139
+ ) => UseMutationResult<
140
140
  SchemaOutput<TOutputSchema, THandlerOutput>,
141
141
  DefaultError,
142
142
  SchemaInput<TInputSchema>
@@ -158,7 +158,7 @@ export function createProcedureHooks<
158
158
  TInputSchema extends Schema = undefined,
159
159
  TOutputSchema extends Schema = undefined,
160
160
  THandlerOutput extends
161
- SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
161
+ SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
162
162
  >(
163
163
  options: CreateProcedureHooksOptions,
164
164
  ): ProcedureHooks<TInputSchema, TOutputSchema, THandlerOutput> {
@@ -261,7 +261,7 @@ export function createProcedureHooks<
261
261
  return useMutation(
262
262
  {
263
263
  mutationKey: getMutationKeyFromPath(options.path),
264
- mutationFn: (input) => client(input),
264
+ mutationFn: input => client(input),
265
265
  ...options_,
266
266
  },
267
267
  context.queryClient,
@@ -233,9 +233,9 @@ describe('getInfiniteQueryData', () => {
233
233
  expectTypeOf(data).toEqualTypeOf<
234
234
  | undefined
235
235
  | InfiniteData<
236
- SchemaOutput<typeof UserListOutputSchema>,
236
+ SchemaOutput<typeof UserListOutputSchema>,
237
237
  number | undefined
238
- >
238
+ >
239
239
  >()
240
240
  })
241
241
  })
@@ -377,11 +377,11 @@ describe('getInfiniteQueryState', () => {
377
377
  expectTypeOf(data).toEqualTypeOf<
378
378
  | undefined
379
379
  | QueryState<
380
- InfiniteData<
381
- SchemaOutput<typeof UserListOutputSchema>,
380
+ InfiniteData<
381
+ SchemaOutput<typeof UserListOutputSchema>,
382
382
  number | undefined
383
- >
384
383
  >
384
+ >
385
385
  >()
386
386
  })
387
387
  })
@@ -444,9 +444,9 @@ describe('setInfiniteQueryData', () => {
444
444
  expectTypeOf(data).toEqualTypeOf<
445
445
  | undefined
446
446
  | InfiniteData<
447
- SchemaOutput<typeof UserListOutputSchema>,
447
+ SchemaOutput<typeof UserListOutputSchema>,
448
448
  number | undefined
449
- >
449
+ >
450
450
  >()
451
451
 
452
452
  return {
@@ -458,9 +458,9 @@ describe('setInfiniteQueryData', () => {
458
458
  expectTypeOf(data).toEqualTypeOf<
459
459
  | undefined
460
460
  | InfiniteData<
461
- SchemaOutput<typeof UserListOutputSchema>,
461
+ SchemaOutput<typeof UserListOutputSchema>,
462
462
  number | undefined
463
- >
463
+ >
464
464
  >()
465
465
  })
466
466
 
@@ -9,7 +9,7 @@ describe('fetchQuery', () => {
9
9
  const utils = createProcedureUtils({
10
10
  client: orpcClient.user.find,
11
11
  path: ['user', 'find'],
12
- queryClient: queryClient,
12
+ queryClient,
13
13
  })
14
14
 
15
15
  it('on success', async () => {
@@ -40,7 +40,7 @@ describe('fetchInfiniteQuery', () => {
40
40
  const utils = createProcedureUtils({
41
41
  client: orpcClient.user.list,
42
42
  path: ['user', 'list'],
43
- queryClient: queryClient,
43
+ queryClient,
44
44
  })
45
45
 
46
46
  it('on success', async () => {
@@ -76,7 +76,7 @@ describe('prefetchQuery', () => {
76
76
  const utils = createProcedureUtils({
77
77
  client: orpcClient.user.find,
78
78
  path: ['user', 'find'],
79
- queryClient: queryClient,
79
+ queryClient,
80
80
  })
81
81
 
82
82
  it('on success', async () => {
@@ -109,7 +109,7 @@ describe('prefetchInfiniteQuery', () => {
109
109
  const utils = createProcedureUtils({
110
110
  client: orpcClient.user.list,
111
111
  path: ['user', 'list'],
112
- queryClient: queryClient,
112
+ queryClient,
113
113
  })
114
114
 
115
115
  it('on success', async () => {
@@ -144,7 +144,7 @@ describe('ensureQueryData', () => {
144
144
  const utils = createProcedureUtils({
145
145
  client: orpcClient.user.find,
146
146
  path: ['user', 'find'],
147
- queryClient: queryClient,
147
+ queryClient,
148
148
  })
149
149
 
150
150
  it('on success', async () => {
@@ -175,7 +175,7 @@ describe('ensureInfiniteQuery', () => {
175
175
  const utils = createProcedureUtils({
176
176
  client: orpcClient.user.list,
177
177
  path: ['user', 'list'],
178
- queryClient: queryClient,
178
+ queryClient,
179
179
  })
180
180
 
181
181
  it('on success', async () => {
@@ -211,7 +211,7 @@ describe('getQueryData', () => {
211
211
  const utils = createProcedureUtils({
212
212
  client: orpcClient.user.find,
213
213
  path: ['user', 'find'],
214
- queryClient: queryClient,
214
+ queryClient,
215
215
  })
216
216
 
217
217
  it('on success', async () => {
@@ -225,7 +225,7 @@ describe('getInfiniteQueryData', () => {
225
225
  const utils = createProcedureUtils({
226
226
  client: orpcClient.user.list,
227
227
  path: ['user', 'list'],
228
- queryClient: queryClient,
228
+ queryClient,
229
229
  })
230
230
 
231
231
  it('on success', async () => {
@@ -239,7 +239,7 @@ describe('getQueryState', () => {
239
239
  const utils = createProcedureUtils({
240
240
  client: orpcClient.user.find,
241
241
  path: ['user', 'find'],
242
- queryClient: queryClient,
242
+ queryClient,
243
243
  })
244
244
 
245
245
  it('on success', async () => {
@@ -256,7 +256,7 @@ describe('getInfiniteQueryState', () => {
256
256
  const utils = createProcedureUtils({
257
257
  client: orpcClient.user.list,
258
258
  path: ['user', 'list'],
259
- queryClient: queryClient,
259
+ queryClient,
260
260
  })
261
261
 
262
262
  it('on success', async () => {
@@ -273,7 +273,7 @@ describe('setQueryData', () => {
273
273
  const utils = createProcedureUtils({
274
274
  client: orpcClient.user.find,
275
275
  path: ['user', 'find'],
276
- queryClient: queryClient,
276
+ queryClient,
277
277
  })
278
278
 
279
279
  it('on success', async () => {
@@ -299,11 +299,11 @@ describe('setQueryData', () => {
299
299
  })
300
300
  })
301
301
 
302
- describe('getInfiniteQueryData', () => {
302
+ describe('getInfiniteQueryData 2', () => {
303
303
  const utils = createProcedureUtils({
304
304
  client: orpcClient.user.list,
305
305
  path: ['user', 'list'],
306
- queryClient: queryClient,
306
+ queryClient,
307
307
  })
308
308
 
309
309
  it('on success', async () => {
@@ -14,22 +14,22 @@ import type {
14
14
  SetDataOptions,
15
15
  Updater,
16
16
  } from '@tanstack/react-query'
17
- import { getQueryKeyFromPath } from './tanstack-key'
18
17
  import type { SchemaInputForInfiniteQuery } from './types'
18
+ import { getQueryKeyFromPath } from './tanstack-key'
19
19
 
20
20
  export interface ProcedureUtils<
21
21
  TInputSchema extends Schema,
22
22
  TOutputSchema extends Schema,
23
23
  THandlerOutput extends SchemaOutput<TOutputSchema>,
24
24
  > {
25
- fetchQuery(
25
+ fetchQuery: (
26
26
  input: SchemaInput<TInputSchema>,
27
27
  options?: SetOptional<
28
28
  FetchQueryOptions<SchemaOutput<TOutputSchema, THandlerOutput>>,
29
29
  'queryKey' | 'queryFn'
30
30
  >,
31
- ): Promise<SchemaOutput<TOutputSchema, THandlerOutput>>
32
- fetchInfiniteQuery(
31
+ ) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>
32
+ fetchInfiniteQuery: (
33
33
  options: PartialOnUndefinedDeep<
34
34
  SetOptional<
35
35
  FetchInfiniteQueryOptions<
@@ -44,21 +44,21 @@ export interface ProcedureUtils<
44
44
  input: SchemaInputForInfiniteQuery<TInputSchema>
45
45
  }
46
46
  >,
47
- ): Promise<
47
+ ) => Promise<
48
48
  InfiniteData<
49
49
  SchemaOutput<TOutputSchema, THandlerOutput>,
50
50
  SchemaInput<TInputSchema>['cursor']
51
51
  >
52
52
  >
53
53
 
54
- prefetchQuery(
54
+ prefetchQuery: (
55
55
  input: SchemaInput<TInputSchema>,
56
56
  options?: SetOptional<
57
57
  FetchQueryOptions<SchemaOutput<TOutputSchema, THandlerOutput>>,
58
58
  'queryKey' | 'queryFn'
59
59
  >,
60
- ): Promise<void>
61
- prefetchInfiniteQuery(
60
+ ) => Promise<void>
61
+ prefetchInfiniteQuery: (
62
62
  options: PartialOnUndefinedDeep<
63
63
  SetOptional<
64
64
  FetchInfiniteQueryOptions<
@@ -73,28 +73,27 @@ export interface ProcedureUtils<
73
73
  input: SchemaInputForInfiniteQuery<TInputSchema>
74
74
  }
75
75
  >,
76
- ): Promise<void>
76
+ ) => Promise<void>
77
77
 
78
- getQueryData(
78
+ getQueryData: (
79
79
  input: SchemaInput<TInputSchema>,
80
- ): SchemaOutput<TOutputSchema, THandlerOutput> | undefined
81
- getInfiniteQueryData(
80
+ ) => SchemaOutput<TOutputSchema, THandlerOutput> | undefined
81
+ getInfiniteQueryData: (
82
82
  input: SchemaInputForInfiniteQuery<TInputSchema>,
83
- ):
84
- | InfiniteData<
85
- SchemaOutput<TOutputSchema, THandlerOutput>,
86
- SchemaInput<TInputSchema>['cursor']
87
- >
88
- | undefined
83
+ ) => | InfiniteData<
84
+ SchemaOutput<TOutputSchema, THandlerOutput>,
85
+ SchemaInput<TInputSchema>['cursor']
86
+ >
87
+ | undefined
89
88
 
90
- ensureQueryData(
89
+ ensureQueryData: (
91
90
  input: SchemaInput<TInputSchema>,
92
91
  options?: SetOptional<
93
92
  EnsureQueryDataOptions<SchemaOutput<TOutputSchema, THandlerOutput>>,
94
93
  'queryFn' | 'queryKey'
95
94
  >,
96
- ): Promise<SchemaOutput<TOutputSchema, THandlerOutput>>
97
- ensureInfiniteQueryData(
95
+ ) => Promise<SchemaOutput<TOutputSchema, THandlerOutput>>
96
+ ensureInfiniteQueryData: (
98
97
  options: PartialOnUndefinedDeep<
99
98
  SetOptional<
100
99
  EnsureInfiniteQueryDataOptions<
@@ -109,63 +108,61 @@ export interface ProcedureUtils<
109
108
  input: SchemaInputForInfiniteQuery<TInputSchema>
110
109
  }
111
110
  >,
112
- ): Promise<
111
+ ) => Promise<
113
112
  InfiniteData<
114
113
  SchemaOutput<TOutputSchema, THandlerOutput>,
115
114
  SchemaInput<TInputSchema>['cursor']
116
115
  >
117
116
  >
118
117
 
119
- getQueryState(
118
+ getQueryState: (
120
119
  input: SchemaInput<TInputSchema>,
121
- ): QueryState<SchemaOutput<TOutputSchema, THandlerOutput>> | undefined
122
- getInfiniteQueryState(
120
+ ) => QueryState<SchemaOutput<TOutputSchema, THandlerOutput>> | undefined
121
+ getInfiniteQueryState: (
123
122
  input: SchemaInputForInfiniteQuery<TInputSchema>,
124
- ):
125
- | QueryState<
126
- InfiniteData<
127
- SchemaOutput<TOutputSchema, THandlerOutput>,
128
- SchemaInput<TInputSchema>['cursor']
129
- >
130
- >
131
- | undefined
123
+ ) => | QueryState<
124
+ InfiniteData<
125
+ SchemaOutput<TOutputSchema, THandlerOutput>,
126
+ SchemaInput<TInputSchema>['cursor']
127
+ >
128
+ >
129
+ | undefined
132
130
 
133
- setQueryData(
131
+ setQueryData: (
134
132
  input: SchemaInput<TInputSchema>,
135
133
  updater: Updater<
136
134
  SchemaOutput<TOutputSchema, THandlerOutput> | undefined,
137
135
  SchemaOutput<TOutputSchema, THandlerOutput> | undefined
138
136
  >,
139
137
  options?: SetDataOptions,
140
- ): SchemaOutput<TOutputSchema, THandlerOutput> | undefined
141
- setInfiniteQueryData(
138
+ ) => SchemaOutput<TOutputSchema, THandlerOutput> | undefined
139
+ setInfiniteQueryData: (
142
140
  input: SchemaInputForInfiniteQuery<TInputSchema>,
143
141
  updater: Updater<
144
142
  | InfiniteData<
145
- SchemaOutput<TOutputSchema, THandlerOutput>,
146
- SchemaInput<TInputSchema>['cursor']
147
- >
143
+ SchemaOutput<TOutputSchema, THandlerOutput>,
144
+ SchemaInput<TInputSchema>['cursor']
145
+ >
148
146
  | undefined,
149
147
  | InfiniteData<
150
- SchemaOutput<TOutputSchema, THandlerOutput>,
151
- SchemaInput<TInputSchema>['cursor']
152
- >
153
- | undefined
154
- >,
155
- options?: SetDataOptions,
156
- ):
157
- | InfiniteData<
158
148
  SchemaOutput<TOutputSchema, THandlerOutput>,
159
149
  SchemaInput<TInputSchema>['cursor']
160
150
  >
161
- | undefined
151
+ | undefined
152
+ >,
153
+ options?: SetDataOptions,
154
+ ) => | InfiniteData<
155
+ SchemaOutput<TOutputSchema, THandlerOutput>,
156
+ SchemaInput<TInputSchema>['cursor']
157
+ >
158
+ | undefined
162
159
  }
163
160
 
164
161
  export interface CreateProcedureUtilsOptions<
165
162
  TInputSchema extends Schema = undefined,
166
163
  TOutputSchema extends Schema = undefined,
167
164
  THandlerOutput extends
168
- SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
165
+ SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
169
166
  > {
170
167
  client: ProcedureClient<TInputSchema, TOutputSchema, THandlerOutput>
171
168
  queryClient: QueryClient
@@ -4,33 +4,25 @@ import type {
4
4
  SchemaOutput,
5
5
  } from '@orpc/contract'
6
6
  import type { Procedure, Router } from '@orpc/server'
7
- import { type GeneralHooks, createGeneralHooks } from './general-hooks'
8
- import { orpcPathSymbol } from './orpc-path'
9
- import { type ProcedureHooks, createProcedureHooks } from './procedure-hooks'
10
7
  import type { ORPCContext } from './react-context'
8
+ import { createGeneralHooks, type GeneralHooks } from './general-hooks'
9
+ import { orpcPathSymbol } from './orpc-path'
10
+ import { createProcedureHooks, type ProcedureHooks } from './procedure-hooks'
11
11
 
12
12
  export type ORPCHooksWithContractRouter<TRouter extends ContractRouter> = {
13
13
  [K in keyof TRouter]: TRouter[K] extends ContractProcedure<
14
14
  infer UInputSchema,
15
15
  infer UOutputSchema
16
16
  >
17
- ? ProcedureHooks<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> &
18
- GeneralHooks<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>
17
+ ? ProcedureHooks<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>> & GeneralHooks<UInputSchema, UOutputSchema, SchemaOutput<UOutputSchema>>
19
18
  : TRouter[K] extends ContractRouter
20
19
  ? ORPCHooksWithContractRouter<TRouter[K]>
21
20
  : never
22
21
  } & GeneralHooks<undefined, undefined, unknown>
23
22
 
24
23
  export type ORPCHooksWithRouter<TRouter extends Router<any>> = {
25
- [K in keyof TRouter]: TRouter[K] extends Procedure<
26
- any,
27
- any,
28
- infer UInputSchema,
29
- infer UOutputSchema,
30
- infer UHandlerOutput
31
- >
32
- ? ProcedureHooks<UInputSchema, UOutputSchema, UHandlerOutput> &
33
- GeneralHooks<UInputSchema, UOutputSchema, UHandlerOutput>
24
+ [K in keyof TRouter]: TRouter[K] extends Procedure<any, any, infer UInputSchema, infer UOutputSchema, infer UHandlerOutput>
25
+ ? ProcedureHooks<UInputSchema, UOutputSchema, UHandlerOutput> & GeneralHooks<UInputSchema, UOutputSchema, UHandlerOutput>
34
26
  : TRouter[K] extends Router<any>
35
27
  ? ORPCHooksWithRouter<TRouter[K]>
36
28
  : never
@@ -52,19 +44,19 @@ export interface CreateORPCHooksOptions<
52
44
  export function createORPCHooks<TRouter extends ContractRouter | Router<any>>(
53
45
  options: CreateORPCHooksOptions<TRouter>,
54
46
  ): TRouter extends Router<any>
55
- ? ORPCHooksWithRouter<TRouter>
56
- : TRouter extends ContractRouter
57
- ? ORPCHooksWithContractRouter<TRouter>
58
- : never {
47
+ ? ORPCHooksWithRouter<TRouter>
48
+ : TRouter extends ContractRouter
49
+ ? ORPCHooksWithContractRouter<TRouter>
50
+ : never {
59
51
  const path = options.path ?? []
60
52
  const generalHooks = createGeneralHooks({ context: options.context, path })
61
53
 
62
54
  // for sure root is not procedure, so do not it procedure hooks on root
63
55
  const procedureHooks = path.length
64
56
  ? createProcedureHooks({
65
- context: options.context,
66
- path,
67
- })
57
+ context: options.context,
58
+ path,
59
+ })
68
60
  : {}
69
61
 
70
62
  return new Proxy(
@@ -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
- infer UInputSchema,
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
- any,
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 UHandlerOutput>
22
+ ? ProcedureUtils<UInputSchema, UOutputSchema, UHandlerOutput> & GeneralUtils<UInputSchema, UOutputSchema, UHandlerOutput>
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
- ? ORPCUtilsWithRouter<TRouter>
56
- : TRouter extends ContractRouter
57
- ? ORPCUtilsWithContractRouter<TRouter>
58
- : never {
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
- client,
71
- queryClient: options.contextValue.queryClient,
72
- path,
73
- })
59
+ client,
60
+ queryClient: options.contextValue.queryClient,
61
+ path,
62
+ })
74
63
  : {}
75
64
 
76
65
  return new Proxy(
@@ -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', () => {