@orpc/react 0.0.0-next.b15d206 → 0.0.0-next.db1f26d

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 (57) hide show
  1. package/dist/src/react-hooks.d.ts +2 -2
  2. package/dist/src/react-utils.d.ts +2 -2
  3. package/package.json +12 -15
  4. package/dist/index.js.map +0 -1
  5. package/dist/src/general-hooks.d.ts.map +0 -1
  6. package/dist/src/general-utils.d.ts.map +0 -1
  7. package/dist/src/index.d.ts.map +0 -1
  8. package/dist/src/orpc-path.d.ts.map +0 -1
  9. package/dist/src/procedure-hooks.d.ts.map +0 -1
  10. package/dist/src/procedure-utils.d.ts.map +0 -1
  11. package/dist/src/react-context.d.ts.map +0 -1
  12. package/dist/src/react-hooks.d.ts.map +0 -1
  13. package/dist/src/react-utils.d.ts.map +0 -1
  14. package/dist/src/react.d.ts.map +0 -1
  15. package/dist/src/tanstack-key.d.ts.map +0 -1
  16. package/dist/src/tanstack-query.d.ts.map +0 -1
  17. package/dist/src/types.d.ts.map +0 -1
  18. package/dist/src/use-queries/builder.d.ts.map +0 -1
  19. package/dist/src/use-queries/builders.d.ts.map +0 -1
  20. package/dist/src/use-queries/hook.d.ts.map +0 -1
  21. package/dist/tsconfig.tsbuildinfo +0 -1
  22. package/src/general-hooks.test-d.ts +0 -151
  23. package/src/general-hooks.test.tsx +0 -232
  24. package/src/general-hooks.ts +0 -101
  25. package/src/general-utils.test-d.ts +0 -454
  26. package/src/general-utils.test.tsx +0 -818
  27. package/src/general-utils.ts +0 -393
  28. package/src/index.ts +0 -8
  29. package/src/orpc-path.test-d.ts +0 -13
  30. package/src/orpc-path.test.ts +0 -12
  31. package/src/orpc-path.ts +0 -24
  32. package/src/procedure-hooks.test-d.ts +0 -321
  33. package/src/procedure-hooks.test.tsx +0 -388
  34. package/src/procedure-hooks.ts +0 -271
  35. package/src/procedure-utils.test-d.ts +0 -476
  36. package/src/procedure-utils.test.tsx +0 -330
  37. package/src/procedure-utils.ts +0 -312
  38. package/src/react-context.ts +0 -43
  39. package/src/react-hooks.ts +0 -94
  40. package/src/react-utils.ts +0 -98
  41. package/src/react.test-d.ts +0 -89
  42. package/src/react.test.tsx +0 -102
  43. package/src/react.tsx +0 -81
  44. package/src/tanstack-key.test-d.ts +0 -35
  45. package/src/tanstack-key.test.ts +0 -62
  46. package/src/tanstack-key.ts +0 -64
  47. package/src/tanstack-query.ts +0 -27
  48. package/src/types.ts +0 -7
  49. package/src/use-queries/builder.test-d.ts +0 -29
  50. package/src/use-queries/builder.test.ts +0 -25
  51. package/src/use-queries/builder.ts +0 -71
  52. package/src/use-queries/builders.test-d.ts +0 -30
  53. package/src/use-queries/builders.test.tsx +0 -29
  54. package/src/use-queries/builders.ts +0 -101
  55. package/src/use-queries/hook.test-d.ts +0 -64
  56. package/src/use-queries/hook.test.tsx +0 -89
  57. package/src/use-queries/hook.ts +0 -57
@@ -1,393 +0,0 @@
1
- import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
2
- import type { PartialDeep, SetOptional } from '@orpc/shared'
3
- import type {
4
- CancelOptions,
5
- DefaultError,
6
- InfiniteData,
7
- InvalidateOptions,
8
- MutationFilters,
9
- MutationObserverOptions,
10
- OmitKeyof,
11
- QueryClient,
12
- QueryKey,
13
- QueryObserverOptions,
14
- RefetchOptions,
15
- ResetOptions,
16
- SetDataOptions,
17
- Updater,
18
- } from '@tanstack/react-query'
19
- import type {
20
- ORPCInvalidateQueryFilters,
21
- ORPCQueryFilters,
22
- } from './tanstack-query'
23
- import type { SchemaInputForInfiniteQuery } from './types'
24
- import { getMutationKeyFromPath, getQueryKeyFromPath } from './tanstack-key'
25
-
26
- export interface GeneralUtils<
27
- TInputSchema extends Schema,
28
- TOutputSchema extends Schema,
29
- TFuncOutput extends SchemaOutput<TOutputSchema>,
30
- > {
31
- getQueriesData: (
32
- filters?: OmitKeyof<
33
- ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
34
- 'queryType'
35
- >,
36
- ) => [QueryKey, SchemaOutput<TOutputSchema, TFuncOutput> | undefined][]
37
- getInfiniteQueriesData: (
38
- filters?: OmitKeyof<
39
- ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>,
40
- 'queryType'
41
- >,
42
- ) => [
43
- QueryKey,
44
- | undefined
45
- | InfiniteData<
46
- SchemaOutput<TOutputSchema, TFuncOutput>,
47
- SchemaInput<TInputSchema>['cursor']
48
- >,
49
- ][]
50
-
51
- setQueriesData: (
52
- filters: OmitKeyof<
53
- ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
54
- 'queryType'
55
- >,
56
- updater: Updater<
57
- SchemaOutput<TOutputSchema, TFuncOutput> | undefined,
58
- SchemaOutput<TOutputSchema, TFuncOutput> | undefined
59
- >,
60
- options?: SetDataOptions,
61
- ) => [QueryKey, SchemaOutput<TOutputSchema, TFuncOutput> | undefined][]
62
- setInfiniteQueriesData: (
63
- filters: OmitKeyof<
64
- ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>,
65
- 'queryType'
66
- >,
67
- updater: Updater<
68
- | InfiniteData<
69
- SchemaOutput<TOutputSchema, TFuncOutput>,
70
- SchemaInput<TInputSchema>['cursor']
71
- >
72
- | undefined,
73
- | InfiniteData<
74
- SchemaOutput<TOutputSchema, TFuncOutput>,
75
- SchemaInput<TInputSchema>['cursor']
76
- >
77
- | undefined
78
- >,
79
- options?: SetDataOptions,
80
- ) => [
81
- QueryKey,
82
- | undefined
83
- | InfiniteData<
84
- SchemaOutput<TOutputSchema, TFuncOutput>,
85
- SchemaInput<TInputSchema>['cursor']
86
- >,
87
- ][]
88
-
89
- invalidate: (
90
- filters?: ORPCInvalidateQueryFilters<
91
- PartialDeep<SchemaInput<TInputSchema>>
92
- >,
93
- options?: InvalidateOptions,
94
- ) => Promise<void>
95
- refetch: (
96
- filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
97
- options?: RefetchOptions,
98
- ) => Promise<void>
99
- cancel: (
100
- filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
101
- options?: CancelOptions,
102
- ) => Promise<void>
103
- remove: (
104
- filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
105
- ) => void
106
- reset: (
107
- filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
108
- options?: ResetOptions,
109
- ) => Promise<void>
110
-
111
- isFetching: (
112
- filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
113
- ) => number
114
- isMutating: (filters?: SetOptional<MutationFilters, 'mutationKey'>) => number
115
-
116
- getQueryDefaults: (
117
- filters?: Pick<
118
- ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
119
- 'input' | 'queryKey'
120
- >,
121
- ) => OmitKeyof<
122
- QueryObserverOptions<SchemaOutput<TOutputSchema, TFuncOutput>>,
123
- 'queryKey'
124
- >
125
- getInfiniteQueryDefaults: (
126
- filters?: Pick<
127
- ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>,
128
- 'input' | 'queryKey'
129
- >,
130
- ) => OmitKeyof<
131
- QueryObserverOptions<
132
- SchemaOutput<TOutputSchema, TFuncOutput>,
133
- DefaultError,
134
- SchemaOutput<TOutputSchema, TFuncOutput>,
135
- InfiniteData<SchemaOutput<TOutputSchema, TFuncOutput>>,
136
- QueryKey,
137
- SchemaInput<TInputSchema>['cursor']
138
- >,
139
- 'queryKey'
140
- >
141
-
142
- setQueryDefaults: (
143
- options: Partial<
144
- OmitKeyof<
145
- QueryObserverOptions<SchemaOutput<TOutputSchema, TFuncOutput>>,
146
- 'queryKey'
147
- >
148
- >,
149
- filters?: Pick<
150
- ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
151
- 'input' | 'queryKey'
152
- >,
153
- ) => void
154
- setInfiniteQueryDefaults: (
155
- options: Partial<
156
- OmitKeyof<
157
- QueryObserverOptions<
158
- SchemaOutput<TOutputSchema, TFuncOutput>,
159
- DefaultError,
160
- SchemaOutput<TOutputSchema, TFuncOutput>,
161
- InfiniteData<SchemaOutput<TOutputSchema, TFuncOutput>>,
162
- QueryKey,
163
- SchemaInput<TInputSchema>['cursor']
164
- >,
165
- 'queryKey'
166
- >
167
- >,
168
- filters?: Pick<
169
- ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>,
170
- 'input' | 'queryKey'
171
- >,
172
- ) => void
173
-
174
- getMutationDefaults: (
175
- filters?: Pick<MutationFilters, 'mutationKey'>,
176
- ) => MutationObserverOptions<
177
- SchemaOutput<TOutputSchema, TFuncOutput>,
178
- DefaultError,
179
- SchemaInput<TInputSchema>
180
- >
181
- setMutationDefaults: (
182
- options: OmitKeyof<
183
- MutationObserverOptions<
184
- SchemaOutput<TOutputSchema, TFuncOutput>,
185
- DefaultError,
186
- SchemaInput<TInputSchema>
187
- >,
188
- 'mutationKey'
189
- >,
190
- filters?: Pick<MutationFilters, 'mutationKey'>,
191
- ) => void
192
- }
193
-
194
- export interface CreateGeneralUtilsOptions {
195
- queryClient: QueryClient
196
-
197
- /**
198
- * The path of the router or procedure on server.
199
- *
200
- * @internal
201
- */
202
- path: string[]
203
- }
204
-
205
- export function createGeneralUtils<
206
- TInputSchema extends Schema = undefined,
207
- TOutputSchema extends Schema = undefined,
208
- TFuncOutput extends
209
- SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
210
- >(
211
- options: CreateGeneralUtilsOptions,
212
- ): GeneralUtils<TInputSchema, TOutputSchema, TFuncOutput> {
213
- return {
214
- getQueriesData(filters) {
215
- const { input, ...rest } = filters ?? {}
216
- return options.queryClient.getQueriesData({
217
- queryKey: getQueryKeyFromPath(options.path, { input, type: 'query' }),
218
- ...rest,
219
- }) as any
220
- },
221
- getInfiniteQueriesData(filters) {
222
- const { input, ...rest } = filters ?? {}
223
- return options.queryClient.getQueriesData({
224
- queryKey: getQueryKeyFromPath(options.path, {
225
- input,
226
- type: 'infinite',
227
- }),
228
- ...rest,
229
- }) as any
230
- },
231
-
232
- setQueriesData(filters, updater, options_) {
233
- const { input, ...rest } = filters
234
- return options.queryClient.setQueriesData(
235
- {
236
- queryKey: getQueryKeyFromPath(options.path, {
237
- input,
238
- type: 'query',
239
- }),
240
- ...rest,
241
- },
242
- updater,
243
- options_,
244
- ) as any
245
- },
246
- setInfiniteQueriesData(filters, updater, options_) {
247
- const { input, ...rest } = filters
248
- return options.queryClient.setQueriesData(
249
- {
250
- queryKey: getQueryKeyFromPath(options.path, {
251
- input,
252
- type: 'infinite',
253
- }),
254
- ...rest,
255
- },
256
- updater,
257
- options_,
258
- ) as any
259
- },
260
-
261
- invalidate(filters, options_) {
262
- const { input, queryType, ...rest } = filters ?? {}
263
- return options.queryClient.invalidateQueries(
264
- {
265
- queryKey: getQueryKeyFromPath(options.path, {
266
- input,
267
- type: queryType,
268
- }),
269
- ...rest,
270
- },
271
- options_,
272
- )
273
- },
274
- refetch(filters, options_) {
275
- const { input, queryType, ...rest } = filters ?? {}
276
- return options.queryClient.refetchQueries(
277
- {
278
- queryKey: getQueryKeyFromPath(options.path, {
279
- input,
280
- type: queryType,
281
- }),
282
- ...rest,
283
- },
284
- options_,
285
- )
286
- },
287
- cancel(filters, options_) {
288
- const { input, queryType, ...rest } = filters ?? {}
289
- return options.queryClient.cancelQueries(
290
- {
291
- queryKey: getQueryKeyFromPath(options.path, {
292
- input,
293
- type: queryType,
294
- }),
295
- ...rest,
296
- },
297
- options_,
298
- )
299
- },
300
- remove(filters) {
301
- const { input, queryType, ...rest } = filters ?? {}
302
- return options.queryClient.removeQueries({
303
- queryKey: getQueryKeyFromPath(options.path, {
304
- input,
305
- type: queryType,
306
- }),
307
- ...rest,
308
- })
309
- },
310
- reset(filters, options_) {
311
- const { input, queryType, ...rest } = filters ?? {}
312
- return options.queryClient.resetQueries(
313
- {
314
- queryKey: getQueryKeyFromPath(options.path, {
315
- input,
316
- type: queryType,
317
- }),
318
- ...rest,
319
- },
320
- options_,
321
- )
322
- },
323
-
324
- isFetching(filters) {
325
- const { input, queryType, ...rest } = filters ?? {}
326
- return options.queryClient.isFetching({
327
- queryKey: getQueryKeyFromPath(options.path, {
328
- input,
329
- type: queryType,
330
- }),
331
- ...rest,
332
- })
333
- },
334
- isMutating(filters) {
335
- return options.queryClient.isMutating({
336
- mutationKey: getMutationKeyFromPath(options.path),
337
- ...filters,
338
- })
339
- },
340
-
341
- getQueryDefaults(filters) {
342
- return options.queryClient.getQueryDefaults(
343
- filters?.queryKey
344
- ?? getQueryKeyFromPath(options.path, {
345
- input: filters?.input,
346
- type: 'query',
347
- }),
348
- )
349
- },
350
- getInfiniteQueryDefaults(filters) {
351
- return options.queryClient.getQueryDefaults(
352
- filters?.queryKey
353
- ?? getQueryKeyFromPath(options.path, {
354
- input: filters?.input,
355
- type: 'infinite',
356
- }),
357
- ) as any
358
- },
359
-
360
- setQueryDefaults(options_, filters) {
361
- return options.queryClient.setQueryDefaults(
362
- filters?.queryKey
363
- ?? getQueryKeyFromPath(options.path, {
364
- input: filters?.input,
365
- type: 'query',
366
- }),
367
- options_ as any,
368
- )
369
- },
370
- setInfiniteQueryDefaults(options_, filters) {
371
- return options.queryClient.setQueryDefaults(
372
- filters?.queryKey
373
- ?? getQueryKeyFromPath(options.path, {
374
- input: filters?.input,
375
- type: 'infinite',
376
- }),
377
- options_ as any,
378
- )
379
- },
380
-
381
- getMutationDefaults(filters) {
382
- return options.queryClient.getMutationDefaults(
383
- filters?.mutationKey ?? getMutationKeyFromPath(options.path),
384
- )
385
- },
386
- setMutationDefaults(options_, filters) {
387
- return options.queryClient.setMutationDefaults(
388
- filters?.mutationKey ?? getMutationKeyFromPath(options.path),
389
- options_,
390
- )
391
- },
392
- }
393
- }
package/src/index.ts DELETED
@@ -1,8 +0,0 @@
1
- export * from './general-hooks'
2
- export * from './general-utils'
3
- export * from './procedure-hooks'
4
- export * from './procedure-utils'
5
- export * from './react'
6
- export * from './react-context'
7
- export * from './react-hooks'
8
- export * from './react-utils'
@@ -1,13 +0,0 @@
1
- import { orpc } from '../tests/orpc'
2
- import { getORPCPath } from './orpc-path'
3
-
4
- it('required valid orpc', () => {
5
- getORPCPath(orpc.ping)
6
- getORPCPath(orpc.user.find)
7
-
8
- // @ts-expect-error invalid orpc
9
- getORPCPath({})
10
-
11
- // @ts-expect-error cannot use in root
12
- getORPCPath(orpc)
13
- })
@@ -1,12 +0,0 @@
1
- import { orpc } from '../tests/orpc'
2
- import { getORPCPath } from './orpc-path'
3
-
4
- it('can get path', () => {
5
- expect(getORPCPath(orpc.ping)).toEqual(['ping'])
6
- expect(getORPCPath(orpc.user.find)).toEqual(['user', 'find'])
7
- })
8
-
9
- it('throw on invalid orpc', () => {
10
- // @ts-expect-error invalid orpc
11
- expect(() => getORPCPath({})).toThrow()
12
- })
package/src/orpc-path.ts DELETED
@@ -1,24 +0,0 @@
1
- import type { ProcedureHooks } from './procedure-hooks'
2
- import type {
3
- ORPCHooksWithContractRouter,
4
- ORPCHooksWithRouter,
5
- } from './react-hooks'
6
-
7
- export const orpcPathSymbol = Symbol('orpcPathSymbol')
8
-
9
- export function getORPCPath(
10
- orpc:
11
- | ORPCHooksWithContractRouter<any>
12
- | ORPCHooksWithRouter<any>
13
- | ProcedureHooks<any, any, any>,
14
- ): string[] {
15
- const val = Reflect.get(orpc, orpcPathSymbol)
16
-
17
- if (!Array.isArray(val)) {
18
- throw new TypeError(
19
- 'orpcPathSymbol is not implemented, please use getORPCPath with correct instance.',
20
- )
21
- }
22
-
23
- return val
24
- }