@orpc/react 0.10.0 → 0.11.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
package/src/procedure-hooks.ts
DELETED
@@ -1,271 +0,0 @@
|
|
1
|
-
import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
|
2
|
-
import type { SchemaInputForInfiniteQuery } from './types'
|
3
|
-
import {
|
4
|
-
get,
|
5
|
-
type PartialOnUndefinedDeep,
|
6
|
-
type SetOptional,
|
7
|
-
} from '@orpc/shared'
|
8
|
-
import {
|
9
|
-
type DefaultError,
|
10
|
-
type FetchInfiniteQueryOptions,
|
11
|
-
type FetchQueryOptions,
|
12
|
-
type InfiniteData,
|
13
|
-
type QueryKey,
|
14
|
-
useInfiniteQuery,
|
15
|
-
type UseInfiniteQueryOptions,
|
16
|
-
type UseInfiniteQueryResult,
|
17
|
-
useMutation,
|
18
|
-
type UseMutationOptions,
|
19
|
-
type UseMutationResult,
|
20
|
-
usePrefetchInfiniteQuery,
|
21
|
-
usePrefetchQuery,
|
22
|
-
useQuery,
|
23
|
-
type UseQueryOptions,
|
24
|
-
type UseQueryResult,
|
25
|
-
useSuspenseInfiniteQuery,
|
26
|
-
type UseSuspenseInfiniteQueryOptions,
|
27
|
-
type UseSuspenseInfiniteQueryResult,
|
28
|
-
useSuspenseQuery,
|
29
|
-
type UseSuspenseQueryOptions,
|
30
|
-
type UseSuspenseQueryResult,
|
31
|
-
} from '@tanstack/react-query'
|
32
|
-
import { orpcPathSymbol } from './orpc-path'
|
33
|
-
import { type ORPCContext, useORPCContext } from './react-context'
|
34
|
-
import { getMutationKeyFromPath, getQueryKeyFromPath } from './tanstack-key'
|
35
|
-
|
36
|
-
export interface ProcedureHooks<
|
37
|
-
TInputSchema extends Schema,
|
38
|
-
TOutputSchema extends Schema,
|
39
|
-
TFuncOutput extends SchemaOutput<TOutputSchema>,
|
40
|
-
> {
|
41
|
-
useQuery: <USelectData = SchemaOutput<TOutputSchema, TFuncOutput>>(
|
42
|
-
input: SchemaInput<TInputSchema>,
|
43
|
-
options?: SetOptional<
|
44
|
-
UseQueryOptions<
|
45
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
46
|
-
DefaultError,
|
47
|
-
USelectData
|
48
|
-
>,
|
49
|
-
'queryFn' | 'queryKey'
|
50
|
-
>,
|
51
|
-
) => UseQueryResult<USelectData>
|
52
|
-
useInfiniteQuery: <
|
53
|
-
USelectData = InfiniteData<
|
54
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
55
|
-
SchemaInput<TInputSchema>['cursor']
|
56
|
-
>,
|
57
|
-
>(
|
58
|
-
options: PartialOnUndefinedDeep<
|
59
|
-
SetOptional<
|
60
|
-
UseInfiniteQueryOptions<
|
61
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
62
|
-
DefaultError,
|
63
|
-
USelectData,
|
64
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
65
|
-
QueryKey,
|
66
|
-
SchemaInput<TInputSchema>['cursor']
|
67
|
-
>,
|
68
|
-
'queryFn' | 'queryKey'
|
69
|
-
> & {
|
70
|
-
input: SchemaInputForInfiniteQuery<TInputSchema>
|
71
|
-
}
|
72
|
-
>,
|
73
|
-
) => UseInfiniteQueryResult<USelectData>
|
74
|
-
|
75
|
-
useSuspenseQuery: <USelectData = SchemaOutput<TOutputSchema, TFuncOutput>>(
|
76
|
-
input: SchemaInput<TInputSchema>,
|
77
|
-
options?: SetOptional<
|
78
|
-
UseSuspenseQueryOptions<
|
79
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
80
|
-
DefaultError,
|
81
|
-
USelectData
|
82
|
-
>,
|
83
|
-
'queryFn' | 'queryKey'
|
84
|
-
>,
|
85
|
-
) => UseSuspenseQueryResult<USelectData>
|
86
|
-
useSuspenseInfiniteQuery: <
|
87
|
-
USelectData = InfiniteData<
|
88
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
89
|
-
SchemaInput<TInputSchema>['cursor']
|
90
|
-
>,
|
91
|
-
>(
|
92
|
-
options: PartialOnUndefinedDeep<
|
93
|
-
SetOptional<
|
94
|
-
UseSuspenseInfiniteQueryOptions<
|
95
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
96
|
-
DefaultError,
|
97
|
-
USelectData,
|
98
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
99
|
-
QueryKey,
|
100
|
-
SchemaInput<TInputSchema>['cursor']
|
101
|
-
>,
|
102
|
-
'queryFn' | 'queryKey'
|
103
|
-
> & {
|
104
|
-
input: SchemaInputForInfiniteQuery<TInputSchema>
|
105
|
-
}
|
106
|
-
>,
|
107
|
-
) => UseSuspenseInfiniteQueryResult<USelectData>
|
108
|
-
|
109
|
-
usePrefetchQuery: (
|
110
|
-
input: SchemaInput<TInputSchema>,
|
111
|
-
options?: FetchQueryOptions<SchemaOutput<TOutputSchema, TFuncOutput>>,
|
112
|
-
) => void
|
113
|
-
usePrefetchInfiniteQuery: (
|
114
|
-
options: PartialOnUndefinedDeep<
|
115
|
-
SetOptional<
|
116
|
-
FetchInfiniteQueryOptions<
|
117
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
118
|
-
DefaultError,
|
119
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
120
|
-
QueryKey,
|
121
|
-
SchemaInput<TInputSchema>['cursor']
|
122
|
-
>,
|
123
|
-
'queryKey' | 'queryFn'
|
124
|
-
> & {
|
125
|
-
input: SchemaInputForInfiniteQuery<TInputSchema>
|
126
|
-
}
|
127
|
-
>,
|
128
|
-
) => void
|
129
|
-
|
130
|
-
useMutation: (
|
131
|
-
options?: SetOptional<
|
132
|
-
UseMutationOptions<
|
133
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
134
|
-
DefaultError,
|
135
|
-
SchemaInput<TInputSchema>
|
136
|
-
>,
|
137
|
-
'mutationFn' | 'mutationKey'
|
138
|
-
>,
|
139
|
-
) => UseMutationResult<
|
140
|
-
SchemaOutput<TOutputSchema, TFuncOutput>,
|
141
|
-
DefaultError,
|
142
|
-
SchemaInput<TInputSchema>
|
143
|
-
>
|
144
|
-
}
|
145
|
-
|
146
|
-
export interface CreateProcedureHooksOptions {
|
147
|
-
context: ORPCContext<any>
|
148
|
-
|
149
|
-
/**
|
150
|
-
* The path of the procedure on server.
|
151
|
-
*
|
152
|
-
* @internal
|
153
|
-
*/
|
154
|
-
path: string[]
|
155
|
-
}
|
156
|
-
|
157
|
-
export function createProcedureHooks<
|
158
|
-
TInputSchema extends Schema = undefined,
|
159
|
-
TOutputSchema extends Schema = undefined,
|
160
|
-
TFuncOutput extends
|
161
|
-
SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
|
162
|
-
>(
|
163
|
-
options: CreateProcedureHooksOptions,
|
164
|
-
): ProcedureHooks<TInputSchema, TOutputSchema, TFuncOutput> {
|
165
|
-
return {
|
166
|
-
[orpcPathSymbol as any]: options.path,
|
167
|
-
|
168
|
-
useQuery(input, options_) {
|
169
|
-
const context = useORPCContext(options.context)
|
170
|
-
const client = get(context.client, options.path) as any
|
171
|
-
return useQuery(
|
172
|
-
{
|
173
|
-
queryKey: getQueryKeyFromPath(options.path, { input, type: 'query' }),
|
174
|
-
queryFn: () => client(input),
|
175
|
-
...options_,
|
176
|
-
},
|
177
|
-
context.queryClient,
|
178
|
-
)
|
179
|
-
},
|
180
|
-
useInfiniteQuery(options_) {
|
181
|
-
const { input, ...rest } = options_
|
182
|
-
const context = useORPCContext(options.context)
|
183
|
-
const client = get(context.client, options.path) as any
|
184
|
-
return useInfiniteQuery(
|
185
|
-
{
|
186
|
-
queryKey: getQueryKeyFromPath(options.path, {
|
187
|
-
input,
|
188
|
-
type: 'infinite',
|
189
|
-
}),
|
190
|
-
queryFn: ({ pageParam }) =>
|
191
|
-
client({ ...(input as any), cursor: pageParam }),
|
192
|
-
...(rest as any),
|
193
|
-
},
|
194
|
-
context.queryClient,
|
195
|
-
)
|
196
|
-
},
|
197
|
-
|
198
|
-
useSuspenseQuery(input, options_) {
|
199
|
-
const context = useORPCContext(options.context)
|
200
|
-
const client = get(context.client, options.path) as any
|
201
|
-
return useSuspenseQuery(
|
202
|
-
{
|
203
|
-
queryKey: getQueryKeyFromPath(options.path, { input, type: 'query' }),
|
204
|
-
queryFn: () => client(input),
|
205
|
-
...options_,
|
206
|
-
},
|
207
|
-
context.queryClient,
|
208
|
-
)
|
209
|
-
},
|
210
|
-
useSuspenseInfiniteQuery(options_) {
|
211
|
-
const { input, ...rest } = options_
|
212
|
-
const context = useORPCContext(options.context)
|
213
|
-
const client = get(context.client, options.path) as any
|
214
|
-
return useSuspenseInfiniteQuery(
|
215
|
-
{
|
216
|
-
queryKey: getQueryKeyFromPath(options.path, {
|
217
|
-
input,
|
218
|
-
type: 'infinite',
|
219
|
-
}),
|
220
|
-
queryFn: ({ pageParam }) =>
|
221
|
-
client({ ...(input as any), cursor: pageParam }),
|
222
|
-
...(rest as any),
|
223
|
-
},
|
224
|
-
context.queryClient,
|
225
|
-
)
|
226
|
-
},
|
227
|
-
|
228
|
-
usePrefetchQuery(input, options_) {
|
229
|
-
const context = useORPCContext(options.context)
|
230
|
-
const client = get(context.client, options.path) as any
|
231
|
-
return usePrefetchQuery(
|
232
|
-
{
|
233
|
-
queryKey: getQueryKeyFromPath(options.path, { input, type: 'query' }),
|
234
|
-
queryFn: () => client(input),
|
235
|
-
...options_,
|
236
|
-
},
|
237
|
-
context.queryClient,
|
238
|
-
)
|
239
|
-
},
|
240
|
-
usePrefetchInfiniteQuery(options_) {
|
241
|
-
const { input, ...rest } = options_
|
242
|
-
const context = useORPCContext(options.context)
|
243
|
-
const client = get(context.client, options.path) as any
|
244
|
-
return usePrefetchInfiniteQuery(
|
245
|
-
{
|
246
|
-
queryKey: getQueryKeyFromPath(options.path, {
|
247
|
-
input,
|
248
|
-
type: 'infinite',
|
249
|
-
}),
|
250
|
-
queryFn: ({ pageParam }) =>
|
251
|
-
client({ ...(input as any), cursor: pageParam }),
|
252
|
-
...(rest as any),
|
253
|
-
},
|
254
|
-
context.queryClient,
|
255
|
-
)
|
256
|
-
},
|
257
|
-
|
258
|
-
useMutation(options_) {
|
259
|
-
const context = useORPCContext(options.context)
|
260
|
-
const client = get(context.client, options.path) as any
|
261
|
-
return useMutation(
|
262
|
-
{
|
263
|
-
mutationKey: getMutationKeyFromPath(options.path),
|
264
|
-
mutationFn: input => client(input),
|
265
|
-
...options_,
|
266
|
-
},
|
267
|
-
context.queryClient,
|
268
|
-
)
|
269
|
-
},
|
270
|
-
}
|
271
|
-
}
|