@orpc/react 0.0.0-unsafe-pr-2-20241118033608

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 (71) hide show
  1. package/dist/index.js +635 -0
  2. package/dist/src/general-hooks.d.ts +24 -0
  3. package/dist/src/general-hooks.d.ts.map +1 -0
  4. package/dist/src/general-utils.d.ts +41 -0
  5. package/dist/src/general-utils.d.ts.map +1 -0
  6. package/dist/src/index.d.ts +9 -0
  7. package/dist/src/index.d.ts.map +1 -0
  8. package/dist/src/orpc-path.d.ts +5 -0
  9. package/dist/src/orpc-path.d.ts.map +1 -0
  10. package/dist/src/procedure-hooks.d.ts +31 -0
  11. package/dist/src/procedure-hooks.d.ts.map +1 -0
  12. package/dist/src/procedure-utils.d.ts +35 -0
  13. package/dist/src/procedure-utils.d.ts.map +1 -0
  14. package/dist/src/react-context.d.ts +13 -0
  15. package/dist/src/react-context.d.ts.map +1 -0
  16. package/dist/src/react-hooks.d.ts +22 -0
  17. package/dist/src/react-hooks.d.ts.map +1 -0
  18. package/dist/src/react-utils.d.ts +22 -0
  19. package/dist/src/react-utils.d.ts.map +1 -0
  20. package/dist/src/react.d.ts +21 -0
  21. package/dist/src/react.d.ts.map +1 -0
  22. package/dist/src/tanstack-key.d.ts +15 -0
  23. package/dist/src/tanstack-key.d.ts.map +1 -0
  24. package/dist/src/tanstack-query.d.ts +19 -0
  25. package/dist/src/tanstack-query.d.ts.map +1 -0
  26. package/dist/src/types.d.ts +5 -0
  27. package/dist/src/types.d.ts.map +1 -0
  28. package/dist/src/use-queries/builder.d.ts +20 -0
  29. package/dist/src/use-queries/builder.d.ts.map +1 -0
  30. package/dist/src/use-queries/builders.d.ts +19 -0
  31. package/dist/src/use-queries/builders.d.ts.map +1 -0
  32. package/dist/src/use-queries/hook.d.ts +16 -0
  33. package/dist/src/use-queries/hook.d.ts.map +1 -0
  34. package/dist/tsconfig.tsbuildinfo +1 -0
  35. package/package.json +56 -0
  36. package/src/general-hooks.test-d.ts +151 -0
  37. package/src/general-hooks.test.tsx +232 -0
  38. package/src/general-hooks.ts +100 -0
  39. package/src/general-utils.test-d.ts +454 -0
  40. package/src/general-utils.test.tsx +818 -0
  41. package/src/general-utils.ts +397 -0
  42. package/src/index.ts +8 -0
  43. package/src/orpc-path.test-d.ts +13 -0
  44. package/src/orpc-path.test.ts +12 -0
  45. package/src/orpc-path.ts +24 -0
  46. package/src/procedure-hooks.test-d.ts +321 -0
  47. package/src/procedure-hooks.test.tsx +388 -0
  48. package/src/procedure-hooks.ts +271 -0
  49. package/src/procedure-utils.test-d.ts +476 -0
  50. package/src/procedure-utils.test.tsx +330 -0
  51. package/src/procedure-utils.ts +315 -0
  52. package/src/react-context.ts +43 -0
  53. package/src/react-hooks.ts +102 -0
  54. package/src/react-utils.ts +110 -0
  55. package/src/react.test-d.ts +89 -0
  56. package/src/react.test.tsx +102 -0
  57. package/src/react.tsx +80 -0
  58. package/src/tanstack-key.test-d.ts +35 -0
  59. package/src/tanstack-key.test.ts +62 -0
  60. package/src/tanstack-key.ts +64 -0
  61. package/src/tanstack-query.ts +27 -0
  62. package/src/types.ts +7 -0
  63. package/src/use-queries/builder.test-d.ts +29 -0
  64. package/src/use-queries/builder.test.ts +25 -0
  65. package/src/use-queries/builder.ts +72 -0
  66. package/src/use-queries/builders.test-d.ts +30 -0
  67. package/src/use-queries/builders.test.tsx +29 -0
  68. package/src/use-queries/builders.ts +101 -0
  69. package/src/use-queries/hook.test-d.ts +64 -0
  70. package/src/use-queries/hook.test.tsx +89 -0
  71. package/src/use-queries/hook.ts +57 -0
package/dist/index.js ADDED
@@ -0,0 +1,635 @@
1
+ import { useIsFetching, useIsMutating, useMutationState, useQuery, useInfiniteQuery, useSuspenseQuery, useSuspenseInfiniteQuery, usePrefetchQuery, usePrefetchInfiniteQuery, useMutation, useQueries } from "@tanstack/react-query";
2
+ import { createContext, useContext } from "react";
3
+ function createORPCContext() {
4
+ return createContext(void 0);
5
+ }
6
+ function useORPCContext(context) {
7
+ const value = useContext(context);
8
+ if (!value) {
9
+ throw new Error(
10
+ "useORPCContext must be used within a <ORPCContext.Provider>, please see the docs"
11
+ );
12
+ }
13
+ return value;
14
+ }
15
+ const orpcPathSymbol = Symbol("orpcPathSymbol");
16
+ function getQueryKeyFromPath(path, options) {
17
+ const withInput = (options == null ? void 0 : options.input) !== void 0 ? { input: options == null ? void 0 : options.input } : {};
18
+ const withType = (options == null ? void 0 : options.type) !== void 0 ? { type: options == null ? void 0 : options.type } : {};
19
+ return [
20
+ path,
21
+ {
22
+ ...withInput,
23
+ ...withType
24
+ }
25
+ ];
26
+ }
27
+ function getMutationKeyFromPath(path) {
28
+ return [path];
29
+ }
30
+ function createGeneralHooks(options) {
31
+ return {
32
+ useIsFetching(filters) {
33
+ const { queryType, input, ...rest } = filters ?? {};
34
+ const context = useORPCContext(options.context);
35
+ return useIsFetching(
36
+ {
37
+ queryKey: getQueryKeyFromPath(options.path, {
38
+ input,
39
+ type: queryType
40
+ }),
41
+ ...rest
42
+ },
43
+ context.queryClient
44
+ );
45
+ },
46
+ useIsMutating(filters) {
47
+ const context = useORPCContext(options.context);
48
+ return useIsMutating(
49
+ { mutationKey: getMutationKeyFromPath(options.path), ...filters },
50
+ context.queryClient
51
+ );
52
+ },
53
+ useMutationState(options_) {
54
+ const context = useORPCContext(options.context);
55
+ return useMutationState(
56
+ {
57
+ ...options_,
58
+ filters: {
59
+ mutationKey: getMutationKeyFromPath(options.path),
60
+ ...options_ == null ? void 0 : options_.filters
61
+ }
62
+ },
63
+ context.queryClient
64
+ );
65
+ }
66
+ };
67
+ }
68
+ function createGeneralUtils(options) {
69
+ return {
70
+ getQueriesData(filters) {
71
+ const { input, ...rest } = filters ?? {};
72
+ return options.queryClient.getQueriesData({
73
+ queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
74
+ ...rest
75
+ });
76
+ },
77
+ getInfiniteQueriesData(filters) {
78
+ const { input, ...rest } = filters ?? {};
79
+ return options.queryClient.getQueriesData({
80
+ queryKey: getQueryKeyFromPath(options.path, {
81
+ input,
82
+ type: "infinite"
83
+ }),
84
+ ...rest
85
+ });
86
+ },
87
+ setQueriesData(filters, updater, options_) {
88
+ const { input, ...rest } = filters;
89
+ return options.queryClient.setQueriesData(
90
+ {
91
+ queryKey: getQueryKeyFromPath(options.path, {
92
+ input,
93
+ type: "query"
94
+ }),
95
+ ...rest
96
+ },
97
+ updater,
98
+ options_
99
+ );
100
+ },
101
+ setInfiniteQueriesData(filters, updater, options_) {
102
+ const { input, ...rest } = filters;
103
+ return options.queryClient.setQueriesData(
104
+ {
105
+ queryKey: getQueryKeyFromPath(options.path, {
106
+ input,
107
+ type: "infinite"
108
+ }),
109
+ ...rest
110
+ },
111
+ updater,
112
+ options_
113
+ );
114
+ },
115
+ invalidate(filters, options_) {
116
+ const { input, queryType, ...rest } = filters ?? {};
117
+ return options.queryClient.invalidateQueries(
118
+ {
119
+ queryKey: getQueryKeyFromPath(options.path, {
120
+ input,
121
+ type: queryType
122
+ }),
123
+ ...rest
124
+ },
125
+ options_
126
+ );
127
+ },
128
+ refetch(filters, options_) {
129
+ const { input, queryType, ...rest } = filters ?? {};
130
+ return options.queryClient.refetchQueries(
131
+ {
132
+ queryKey: getQueryKeyFromPath(options.path, {
133
+ input,
134
+ type: queryType
135
+ }),
136
+ ...rest
137
+ },
138
+ options_
139
+ );
140
+ },
141
+ cancel(filters, options_) {
142
+ const { input, queryType, ...rest } = filters ?? {};
143
+ return options.queryClient.cancelQueries(
144
+ {
145
+ queryKey: getQueryKeyFromPath(options.path, {
146
+ input,
147
+ type: queryType
148
+ }),
149
+ ...rest
150
+ },
151
+ options_
152
+ );
153
+ },
154
+ remove(filters) {
155
+ const { input, queryType, ...rest } = filters ?? {};
156
+ return options.queryClient.removeQueries({
157
+ queryKey: getQueryKeyFromPath(options.path, {
158
+ input,
159
+ type: queryType
160
+ }),
161
+ ...rest
162
+ });
163
+ },
164
+ reset(filters, options_) {
165
+ const { input, queryType, ...rest } = filters ?? {};
166
+ return options.queryClient.resetQueries(
167
+ {
168
+ queryKey: getQueryKeyFromPath(options.path, {
169
+ input,
170
+ type: queryType
171
+ }),
172
+ ...rest
173
+ },
174
+ options_
175
+ );
176
+ },
177
+ isFetching(filters) {
178
+ const { input, queryType, ...rest } = filters ?? {};
179
+ return options.queryClient.isFetching({
180
+ queryKey: getQueryKeyFromPath(options.path, {
181
+ input,
182
+ type: queryType
183
+ }),
184
+ ...rest
185
+ });
186
+ },
187
+ isMutating(filters) {
188
+ return options.queryClient.isMutating({
189
+ mutationKey: getMutationKeyFromPath(options.path),
190
+ ...filters
191
+ });
192
+ },
193
+ getQueryDefaults(filters) {
194
+ return options.queryClient.getQueryDefaults(
195
+ (filters == null ? void 0 : filters.queryKey) ?? getQueryKeyFromPath(options.path, {
196
+ input: filters == null ? void 0 : filters.input,
197
+ type: "query"
198
+ })
199
+ );
200
+ },
201
+ getInfiniteQueryDefaults(filters) {
202
+ return options.queryClient.getQueryDefaults(
203
+ (filters == null ? void 0 : filters.queryKey) ?? getQueryKeyFromPath(options.path, {
204
+ input: filters == null ? void 0 : filters.input,
205
+ type: "infinite"
206
+ })
207
+ );
208
+ },
209
+ setQueryDefaults(options_, filters) {
210
+ return options.queryClient.setQueryDefaults(
211
+ (filters == null ? void 0 : filters.queryKey) ?? getQueryKeyFromPath(options.path, {
212
+ input: filters == null ? void 0 : filters.input,
213
+ type: "query"
214
+ }),
215
+ options_
216
+ );
217
+ },
218
+ setInfiniteQueryDefaults(options_, filters) {
219
+ return options.queryClient.setQueryDefaults(
220
+ (filters == null ? void 0 : filters.queryKey) ?? getQueryKeyFromPath(options.path, {
221
+ input: filters == null ? void 0 : filters.input,
222
+ type: "infinite"
223
+ }),
224
+ options_
225
+ );
226
+ },
227
+ getMutationDefaults(filters) {
228
+ return options.queryClient.getMutationDefaults(
229
+ (filters == null ? void 0 : filters.mutationKey) ?? getMutationKeyFromPath(options.path)
230
+ );
231
+ },
232
+ setMutationDefaults(options_, filters) {
233
+ return options.queryClient.setMutationDefaults(
234
+ (filters == null ? void 0 : filters.mutationKey) ?? getMutationKeyFromPath(options.path),
235
+ options_
236
+ );
237
+ }
238
+ };
239
+ }
240
+ function get(root, segments) {
241
+ const ref = { root };
242
+ let currentRef = ref;
243
+ let preSegment = "root";
244
+ for (const segment of segments) {
245
+ currentRef = currentRef[preSegment];
246
+ preSegment = segment;
247
+ }
248
+ return currentRef[preSegment];
249
+ }
250
+ function createProcedureHooks(options) {
251
+ return {
252
+ [orpcPathSymbol]: options.path,
253
+ useQuery(input, options_) {
254
+ const context = useORPCContext(options.context);
255
+ const client = get(context.client, options.path);
256
+ return useQuery(
257
+ {
258
+ queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
259
+ queryFn: () => client(input),
260
+ ...options_
261
+ },
262
+ context.queryClient
263
+ );
264
+ },
265
+ useInfiniteQuery(options_) {
266
+ const { input, ...rest } = options_;
267
+ const context = useORPCContext(options.context);
268
+ const client = get(context.client, options.path);
269
+ return useInfiniteQuery(
270
+ {
271
+ queryKey: getQueryKeyFromPath(options.path, {
272
+ input,
273
+ type: "infinite"
274
+ }),
275
+ queryFn: ({ pageParam }) => client({ ...input, cursor: pageParam }),
276
+ ...rest
277
+ },
278
+ context.queryClient
279
+ );
280
+ },
281
+ useSuspenseQuery(input, options_) {
282
+ const context = useORPCContext(options.context);
283
+ const client = get(context.client, options.path);
284
+ return useSuspenseQuery(
285
+ {
286
+ queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
287
+ queryFn: () => client(input),
288
+ ...options_
289
+ },
290
+ context.queryClient
291
+ );
292
+ },
293
+ useSuspenseInfiniteQuery(options_) {
294
+ const { input, ...rest } = options_;
295
+ const context = useORPCContext(options.context);
296
+ const client = get(context.client, options.path);
297
+ return useSuspenseInfiniteQuery(
298
+ {
299
+ queryKey: getQueryKeyFromPath(options.path, {
300
+ input,
301
+ type: "infinite"
302
+ }),
303
+ queryFn: ({ pageParam }) => client({ ...input, cursor: pageParam }),
304
+ ...rest
305
+ },
306
+ context.queryClient
307
+ );
308
+ },
309
+ usePrefetchQuery(input, options_) {
310
+ const context = useORPCContext(options.context);
311
+ const client = get(context.client, options.path);
312
+ return usePrefetchQuery(
313
+ {
314
+ queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
315
+ queryFn: () => client(input),
316
+ ...options_
317
+ },
318
+ context.queryClient
319
+ );
320
+ },
321
+ usePrefetchInfiniteQuery(options_) {
322
+ const { input, ...rest } = options_;
323
+ const context = useORPCContext(options.context);
324
+ const client = get(context.client, options.path);
325
+ return usePrefetchInfiniteQuery(
326
+ {
327
+ queryKey: getQueryKeyFromPath(options.path, {
328
+ input,
329
+ type: "infinite"
330
+ }),
331
+ queryFn: ({ pageParam }) => client({ ...input, cursor: pageParam }),
332
+ ...rest
333
+ },
334
+ context.queryClient
335
+ );
336
+ },
337
+ useMutation(options_) {
338
+ const context = useORPCContext(options.context);
339
+ const client = get(context.client, options.path);
340
+ return useMutation(
341
+ {
342
+ mutationKey: getMutationKeyFromPath(options.path),
343
+ mutationFn: (input) => client(input),
344
+ ...options_
345
+ },
346
+ context.queryClient
347
+ );
348
+ }
349
+ };
350
+ }
351
+ function createProcedureUtils(options) {
352
+ return {
353
+ fetchQuery(input, options_) {
354
+ return options.queryClient.fetchQuery({
355
+ queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
356
+ queryFn: () => options.client(input),
357
+ ...options_
358
+ });
359
+ },
360
+ fetchInfiniteQuery(options_) {
361
+ const { input, ...rest } = options_;
362
+ return options.queryClient.fetchInfiniteQuery({
363
+ queryKey: getQueryKeyFromPath(options.path, {
364
+ input,
365
+ type: "infinite"
366
+ }),
367
+ queryFn: ({ pageParam }) => {
368
+ return options.client({ ...input, pageParam });
369
+ },
370
+ ...rest
371
+ });
372
+ },
373
+ prefetchQuery(input, options_) {
374
+ return options.queryClient.prefetchQuery({
375
+ queryKey: getQueryKeyFromPath(options.path, {
376
+ input,
377
+ type: "query"
378
+ }),
379
+ queryFn: () => options.client(input),
380
+ ...options_
381
+ });
382
+ },
383
+ prefetchInfiniteQuery(options_) {
384
+ const { input, ...rest } = options_;
385
+ return options.queryClient.prefetchInfiniteQuery({
386
+ queryKey: getQueryKeyFromPath(options.path, {
387
+ input,
388
+ type: "infinite"
389
+ }),
390
+ queryFn: ({ pageParam }) => {
391
+ return options.client({ ...input, cursor: pageParam });
392
+ },
393
+ ...rest
394
+ });
395
+ },
396
+ getQueryData(input) {
397
+ return options.queryClient.getQueryData(
398
+ getQueryKeyFromPath(options.path, {
399
+ input,
400
+ type: "query"
401
+ })
402
+ );
403
+ },
404
+ getInfiniteQueryData(input) {
405
+ return options.queryClient.getQueryData(
406
+ getQueryKeyFromPath(options.path, {
407
+ input,
408
+ type: "infinite"
409
+ })
410
+ );
411
+ },
412
+ ensureQueryData(input, options_) {
413
+ return options.queryClient.ensureQueryData({
414
+ queryKey: getQueryKeyFromPath(options.path, {
415
+ input,
416
+ type: "query"
417
+ }),
418
+ queryFn: () => options.client(input),
419
+ ...options_
420
+ });
421
+ },
422
+ ensureInfiniteQueryData(options_) {
423
+ const { input, ...rest } = options_;
424
+ return options.queryClient.ensureInfiniteQueryData({
425
+ queryKey: getQueryKeyFromPath(options.path, {
426
+ input,
427
+ type: "infinite"
428
+ }),
429
+ queryFn: ({ pageParam }) => {
430
+ return options.client({ ...input, pageParam });
431
+ },
432
+ ...rest
433
+ });
434
+ },
435
+ getQueryState(input) {
436
+ return options.queryClient.getQueryState(
437
+ getQueryKeyFromPath(options.path, {
438
+ input,
439
+ type: "query"
440
+ })
441
+ );
442
+ },
443
+ getInfiniteQueryState(input) {
444
+ return options.queryClient.getQueryState(
445
+ getQueryKeyFromPath(options.path, {
446
+ input,
447
+ type: "infinite"
448
+ })
449
+ );
450
+ },
451
+ setQueryData(input, updater, options_) {
452
+ return options.queryClient.setQueryData(
453
+ getQueryKeyFromPath(options.path, {
454
+ input,
455
+ type: "query"
456
+ }),
457
+ updater,
458
+ options_
459
+ );
460
+ },
461
+ setInfiniteQueryData(input, updater, options_) {
462
+ return options.queryClient.setQueryData(
463
+ getQueryKeyFromPath(options.path, {
464
+ input,
465
+ type: "infinite"
466
+ }),
467
+ updater,
468
+ options_
469
+ );
470
+ }
471
+ };
472
+ }
473
+ function createORPCHooks(options) {
474
+ const path = options.path ?? [];
475
+ const generalHooks = createGeneralHooks({ context: options.context, path });
476
+ const procedureHooks = path.length ? createProcedureHooks({
477
+ context: options.context,
478
+ path
479
+ }) : {};
480
+ return new Proxy(
481
+ {
482
+ [orpcPathSymbol]: path,
483
+ ...generalHooks,
484
+ ...procedureHooks
485
+ },
486
+ {
487
+ get(target, key) {
488
+ const value = Reflect.get(target, key);
489
+ if (typeof key !== "string") {
490
+ return value;
491
+ }
492
+ const nextHooks = createORPCHooks({
493
+ context: options.context,
494
+ path: [...path, key]
495
+ });
496
+ if (typeof value !== "function") {
497
+ return nextHooks;
498
+ }
499
+ return new Proxy(value, {
500
+ get(_, key2) {
501
+ return Reflect.get(nextHooks, key2);
502
+ }
503
+ });
504
+ }
505
+ }
506
+ );
507
+ }
508
+ function createORPCUtils(options) {
509
+ const path = options.path ?? [];
510
+ const client = options.contextValue.client;
511
+ const generalUtils = createGeneralUtils({
512
+ queryClient: options.contextValue.queryClient,
513
+ path
514
+ });
515
+ const procedureUtils = path.length ? createProcedureUtils({
516
+ client,
517
+ queryClient: options.contextValue.queryClient,
518
+ path
519
+ }) : {};
520
+ return new Proxy(
521
+ {
522
+ ...generalUtils,
523
+ ...procedureUtils
524
+ },
525
+ {
526
+ get(target, key) {
527
+ const value = Reflect.get(target, key);
528
+ if (typeof key !== "string") {
529
+ return value;
530
+ }
531
+ const nextUtils = createORPCUtils({
532
+ ...options,
533
+ contextValue: {
534
+ ...options.contextValue,
535
+ client: client[key]
536
+ },
537
+ path: [...path, key]
538
+ });
539
+ if (typeof value !== "function") {
540
+ return nextUtils;
541
+ }
542
+ return new Proxy(value, {
543
+ get(_, key2) {
544
+ return Reflect.get(nextUtils, key2);
545
+ }
546
+ });
547
+ }
548
+ }
549
+ );
550
+ }
551
+ function createUseQueriesBuilder(options) {
552
+ return (input, options_) => {
553
+ return {
554
+ queryKey: getQueryKeyFromPath(options.path, { input, type: "query" }),
555
+ queryFn: () => options.client(input),
556
+ ...options_
557
+ };
558
+ };
559
+ }
560
+ function createUseQueriesBuilders(options) {
561
+ const path = options.path ?? [];
562
+ const client = options.client;
563
+ const builder = path.length ? createUseQueriesBuilder({ client, path }) : {};
564
+ return new Proxy(builder, {
565
+ get(target, key) {
566
+ const value = Reflect.get(target, key);
567
+ if (typeof key !== "string") {
568
+ return value;
569
+ }
570
+ const nextBuilders = createUseQueriesBuilders({
571
+ client: client[key],
572
+ path: [...path, key]
573
+ });
574
+ if (typeof value !== "function") {
575
+ return nextBuilders;
576
+ }
577
+ return new Proxy(value, {
578
+ get(_, key2) {
579
+ return Reflect.get(nextBuilders, key2);
580
+ }
581
+ });
582
+ }
583
+ });
584
+ }
585
+ function useQueriesFactory(options) {
586
+ const hook = (build, combine) => {
587
+ const orpc = useORPCContext(options.context);
588
+ const builders = createUseQueriesBuilders({ client: orpc.client });
589
+ return useQueries({
590
+ queries: build(builders),
591
+ combine
592
+ });
593
+ };
594
+ return hook;
595
+ }
596
+ function createORPCReact() {
597
+ const Context = createORPCContext();
598
+ const useContext2 = () => useORPCContext(Context);
599
+ const useUtils = () => createORPCUtils({ contextValue: useContext2() });
600
+ const useQueries2 = useQueriesFactory({ context: Context });
601
+ const hooks = createORPCHooks({ context: Context });
602
+ const orpc = new Proxy(
603
+ {
604
+ useContext: useContext2,
605
+ useUtils,
606
+ useQueries: useQueries2
607
+ },
608
+ {
609
+ get(target, key) {
610
+ const value = Reflect.get(target, key);
611
+ const nextHooks = Reflect.get(hooks, key);
612
+ if (typeof value !== "function") {
613
+ return nextHooks;
614
+ }
615
+ return new Proxy(value, {
616
+ get(_, key2) {
617
+ return Reflect.get(nextHooks, key2);
618
+ }
619
+ });
620
+ }
621
+ }
622
+ );
623
+ return { orpc, ORPCContext: Context };
624
+ }
625
+ export {
626
+ createGeneralHooks,
627
+ createGeneralUtils,
628
+ createORPCContext,
629
+ createORPCHooks,
630
+ createORPCReact,
631
+ createORPCUtils,
632
+ createProcedureHooks,
633
+ createProcedureUtils,
634
+ useORPCContext
635
+ };
@@ -0,0 +1,24 @@
1
+ import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { PartialDeep, SetOptional } from '@orpc/shared';
3
+ import { type DefaultError, type Mutation, type MutationFilters, type MutationState } from '@tanstack/react-query';
4
+ import { type ORPCContext } from './react-context';
5
+ import type { ORPCQueryFilters } from './tanstack-query';
6
+ export interface GeneralHooks<TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaOutput<TOutputSchema>> {
7
+ useIsFetching(filers?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>): number;
8
+ useIsMutating(filters?: SetOptional<MutationFilters, 'mutationKey'>): number;
9
+ useMutationState<UResult = MutationState<SchemaOutput<TOutputSchema, THandlerOutput>, DefaultError, SchemaInput<TInputSchema>>>(options?: {
10
+ filters?: SetOptional<MutationFilters, 'mutationKey'>;
11
+ select?: (mutation: Mutation<SchemaOutput<TOutputSchema, THandlerOutput>, DefaultError, SchemaInput<TInputSchema>>) => UResult;
12
+ }): UResult[];
13
+ }
14
+ export interface CreateGeneralHooksOptions {
15
+ context: ORPCContext<any>;
16
+ /**
17
+ * The path of the router or procedure on server.
18
+ *
19
+ * @internal
20
+ */
21
+ path: string[];
22
+ }
23
+ export declare function createGeneralHooks<TInputSchema extends Schema = undefined, TOutputSchema extends Schema = undefined, THandlerOutput extends SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>>(options: CreateGeneralHooksOptions): GeneralHooks<TInputSchema, TOutputSchema, THandlerOutput>;
24
+ //# sourceMappingURL=general-hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"general-hooks.d.ts","sourceRoot":"","sources":["../../src/general-hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACvE,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAC5D,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,QAAQ,EACb,KAAK,eAAe,EACpB,KAAK,aAAa,EAInB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,iBAAiB,CAAA;AAElE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAExD,MAAM,WAAW,YAAY,CAC3B,YAAY,SAAS,MAAM,EAC3B,aAAa,SAAS,MAAM,EAC5B,cAAc,SAAS,YAAY,CAAC,aAAa,CAAC;IAElD,aAAa,CACX,MAAM,CAAC,EAAE,gBAAgB,CAAC,WAAW,CAAC,WAAW,CAAC,YAAY,CAAC,CAAC,CAAC,GAChE,MAAM,CAAA;IACT,aAAa,CAAC,OAAO,CAAC,EAAE,WAAW,CAAC,eAAe,EAAE,aAAa,CAAC,GAAG,MAAM,CAAA;IAE5E,gBAAgB,CACd,OAAO,GAAG,aAAa,CACrB,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,EAC3C,YAAY,EACZ,WAAW,CAAC,YAAY,CAAC,CAC1B,EACD,OAAO,CAAC,EAAE;QACV,OAAO,CAAC,EAAE,WAAW,CAAC,eAAe,EAAE,aAAa,CAAC,CAAA;QACrD,MAAM,CAAC,EAAE,CACP,QAAQ,EAAE,QAAQ,CAChB,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,EAC3C,YAAY,EACZ,WAAW,CAAC,YAAY,CAAC,CAC1B,KACE,OAAO,CAAA;KACb,GAAG,OAAO,EAAE,CAAA;CACd;AAED,MAAM,WAAW,yBAAyB;IACxC,OAAO,EAAE,WAAW,CAAC,GAAG,CAAC,CAAA;IAEzB;;;;OAIG;IACH,IAAI,EAAE,MAAM,EAAE,CAAA;CACf;AAED,wBAAgB,kBAAkB,CAChC,YAAY,SAAS,MAAM,GAAG,SAAS,EACvC,aAAa,SAAS,MAAM,GAAG,SAAS,EACxC,cAAc,SACZ,YAAY,CAAC,aAAa,CAAC,GAAG,YAAY,CAAC,aAAa,CAAC,EAE3D,OAAO,EAAE,yBAAyB,GACjC,YAAY,CAAC,YAAY,EAAE,aAAa,EAAE,cAAc,CAAC,CAsC3D"}
@@ -0,0 +1,41 @@
1
+ import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract';
2
+ import type { PartialDeep, SetOptional } from '@orpc/shared';
3
+ import type { CancelOptions, DefaultError, InfiniteData, InvalidateOptions, MutationFilters, MutationObserverOptions, OmitKeyof, QueryClient, QueryKey, QueryObserverOptions, RefetchOptions, ResetOptions, SetDataOptions, Updater } from '@tanstack/react-query';
4
+ import type { ORPCInvalidateQueryFilters, ORPCQueryFilters } from './tanstack-query';
5
+ import type { SchemaInputForInfiniteQuery } from './types';
6
+ export interface GeneralUtils<TInputSchema extends Schema, TOutputSchema extends Schema, THandlerOutput extends SchemaOutput<TOutputSchema>> {
7
+ getQueriesData(filters?: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, 'queryType'>): [QueryKey, SchemaOutput<TOutputSchema, THandlerOutput> | undefined][];
8
+ getInfiniteQueriesData(filters?: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>, 'queryType'>): [
9
+ QueryKey,
10
+ (InfiniteData<SchemaOutput<TOutputSchema, THandlerOutput>, SchemaInput<TInputSchema>['cursor']> | undefined)
11
+ ][];
12
+ setQueriesData(filters: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, 'queryType'>, updater: Updater<SchemaOutput<TOutputSchema, THandlerOutput> | undefined, SchemaOutput<TOutputSchema, THandlerOutput> | undefined>, options?: SetDataOptions): [QueryKey, SchemaOutput<TOutputSchema, THandlerOutput> | undefined][];
13
+ setInfiniteQueriesData(filters: OmitKeyof<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>, 'queryType'>, updater: Updater<InfiniteData<SchemaOutput<TOutputSchema, THandlerOutput>, SchemaInput<TInputSchema>['cursor']> | undefined, InfiniteData<SchemaOutput<TOutputSchema, THandlerOutput>, SchemaInput<TInputSchema>['cursor']> | undefined>, options?: SetDataOptions): [
14
+ QueryKey,
15
+ (InfiniteData<SchemaOutput<TOutputSchema, THandlerOutput>, SchemaInput<TInputSchema>['cursor']> | undefined)
16
+ ][];
17
+ invalidate(filters?: ORPCInvalidateQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, options?: InvalidateOptions): Promise<void>;
18
+ refetch(filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, options?: RefetchOptions): Promise<void>;
19
+ cancel(filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, options?: CancelOptions): Promise<void>;
20
+ remove(filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>): void;
21
+ reset(filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, options?: ResetOptions): Promise<void>;
22
+ isFetching(filters?: ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>): number;
23
+ isMutating(filters?: SetOptional<MutationFilters, 'mutationKey'>): number;
24
+ getQueryDefaults(filters?: Pick<ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, 'input' | 'queryKey'>): OmitKeyof<QueryObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>>, 'queryKey'>;
25
+ getInfiniteQueryDefaults(filters?: Pick<ORPCQueryFilters<PartialDeep<SchemaInputForInfiniteQuery<TInputSchema>>>, 'input' | 'queryKey'>): OmitKeyof<QueryObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>, DefaultError, SchemaOutput<TOutputSchema, THandlerOutput>, InfiniteData<SchemaOutput<TOutputSchema, THandlerOutput>>, QueryKey, SchemaInput<TInputSchema>['cursor']>, 'queryKey'>;
26
+ setQueryDefaults(options: Partial<OmitKeyof<QueryObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>>, 'queryKey'>>, filters?: Pick<ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, 'input' | 'queryKey'>): void;
27
+ setInfiniteQueryDefaults(options: Partial<OmitKeyof<QueryObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>, DefaultError, SchemaOutput<TOutputSchema, THandlerOutput>, InfiniteData<SchemaOutput<TOutputSchema, THandlerOutput>>, QueryKey, SchemaInput<TInputSchema>['cursor']>, 'queryKey'>>, filters?: Pick<ORPCQueryFilters<PartialDeep<SchemaInput<TInputSchema>>>, 'input' | 'queryKey'>): void;
28
+ getMutationDefaults: (filters?: Pick<MutationFilters, 'mutationKey'>) => MutationObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>, DefaultError, SchemaInput<TInputSchema>>;
29
+ setMutationDefaults: (options: OmitKeyof<MutationObserverOptions<SchemaOutput<TOutputSchema, THandlerOutput>, DefaultError, SchemaInput<TInputSchema>>, 'mutationKey'>, filters?: Pick<MutationFilters, 'mutationKey'>) => void;
30
+ }
31
+ export interface CreateGeneralUtilsOptions {
32
+ queryClient: QueryClient;
33
+ /**
34
+ * The path of the router or procedure on server.
35
+ *
36
+ * @internal
37
+ */
38
+ path: string[];
39
+ }
40
+ export declare function createGeneralUtils<TInputSchema extends Schema = undefined, TOutputSchema extends Schema = undefined, THandlerOutput extends SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>>(options: CreateGeneralUtilsOptions): GeneralUtils<TInputSchema, TOutputSchema, THandlerOutput>;
41
+ //# sourceMappingURL=general-utils.d.ts.map