@orpc/react 0.0.0-next.e9dc36e → 0.0.0-next.eaf61c7

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 (79) hide show
  1. package/README.md +151 -0
  2. package/dist/hooks/index.d.mts +69 -0
  3. package/dist/hooks/index.d.ts +69 -0
  4. package/dist/hooks/index.mjs +77 -0
  5. package/dist/index.d.mts +19 -0
  6. package/dist/index.d.ts +19 -0
  7. package/dist/index.mjs +28 -0
  8. package/package.json +24 -24
  9. package/dist/index.js +0 -674
  10. package/dist/index.js.map +0 -1
  11. package/dist/src/general-hooks.d.ts +0 -24
  12. package/dist/src/general-hooks.d.ts.map +0 -1
  13. package/dist/src/general-utils.d.ts +0 -41
  14. package/dist/src/general-utils.d.ts.map +0 -1
  15. package/dist/src/index.d.ts +0 -9
  16. package/dist/src/index.d.ts.map +0 -1
  17. package/dist/src/orpc-path.d.ts +0 -5
  18. package/dist/src/orpc-path.d.ts.map +0 -1
  19. package/dist/src/procedure-hooks.d.ts +0 -31
  20. package/dist/src/procedure-hooks.d.ts.map +0 -1
  21. package/dist/src/procedure-utils.d.ts +0 -35
  22. package/dist/src/procedure-utils.d.ts.map +0 -1
  23. package/dist/src/react-context.d.ts +0 -13
  24. package/dist/src/react-context.d.ts.map +0 -1
  25. package/dist/src/react-hooks.d.ts +0 -22
  26. package/dist/src/react-hooks.d.ts.map +0 -1
  27. package/dist/src/react-utils.d.ts +0 -22
  28. package/dist/src/react-utils.d.ts.map +0 -1
  29. package/dist/src/react.d.ts +0 -21
  30. package/dist/src/react.d.ts.map +0 -1
  31. package/dist/src/tanstack-key.d.ts +0 -15
  32. package/dist/src/tanstack-key.d.ts.map +0 -1
  33. package/dist/src/tanstack-query.d.ts +0 -19
  34. package/dist/src/tanstack-query.d.ts.map +0 -1
  35. package/dist/src/types.d.ts +0 -5
  36. package/dist/src/types.d.ts.map +0 -1
  37. package/dist/src/use-queries/builder.d.ts +0 -20
  38. package/dist/src/use-queries/builder.d.ts.map +0 -1
  39. package/dist/src/use-queries/builders.d.ts +0 -19
  40. package/dist/src/use-queries/builders.d.ts.map +0 -1
  41. package/dist/src/use-queries/hook.d.ts +0 -16
  42. package/dist/src/use-queries/hook.d.ts.map +0 -1
  43. package/dist/tsconfig.tsbuildinfo +0 -1
  44. package/src/general-hooks.test-d.ts +0 -151
  45. package/src/general-hooks.test.tsx +0 -232
  46. package/src/general-hooks.ts +0 -101
  47. package/src/general-utils.test-d.ts +0 -454
  48. package/src/general-utils.test.tsx +0 -818
  49. package/src/general-utils.ts +0 -393
  50. package/src/index.ts +0 -8
  51. package/src/orpc-path.test-d.ts +0 -13
  52. package/src/orpc-path.test.ts +0 -12
  53. package/src/orpc-path.ts +0 -24
  54. package/src/procedure-hooks.test-d.ts +0 -321
  55. package/src/procedure-hooks.test.tsx +0 -388
  56. package/src/procedure-hooks.ts +0 -271
  57. package/src/procedure-utils.test-d.ts +0 -476
  58. package/src/procedure-utils.test.tsx +0 -330
  59. package/src/procedure-utils.ts +0 -312
  60. package/src/react-context.ts +0 -43
  61. package/src/react-hooks.ts +0 -94
  62. package/src/react-utils.ts +0 -98
  63. package/src/react.test-d.ts +0 -89
  64. package/src/react.test.tsx +0 -102
  65. package/src/react.tsx +0 -81
  66. package/src/tanstack-key.test-d.ts +0 -35
  67. package/src/tanstack-key.test.ts +0 -62
  68. package/src/tanstack-key.ts +0 -64
  69. package/src/tanstack-query.ts +0 -27
  70. package/src/types.ts +0 -7
  71. package/src/use-queries/builder.test-d.ts +0 -29
  72. package/src/use-queries/builder.test.ts +0 -25
  73. package/src/use-queries/builder.ts +0 -71
  74. package/src/use-queries/builders.test-d.ts +0 -30
  75. package/src/use-queries/builders.test.tsx +0 -29
  76. package/src/use-queries/builders.ts +0 -101
  77. package/src/use-queries/hook.test-d.ts +0 -64
  78. package/src/use-queries/hook.test.tsx +0 -89
  79. package/src/use-queries/hook.ts +0 -57
@@ -1,476 +0,0 @@
1
- import type { SchemaInput, SchemaOutput } from '@orpc/contract'
2
- import type { InfiniteData, QueryState } from '@tanstack/react-query'
3
- import type {
4
- UserFindInputSchema,
5
- UserListInputSchema,
6
- UserListOutputSchema,
7
- UserSchema,
8
- } from '../tests/orpc'
9
- import { createProcedureUtils } from './procedure-utils'
10
-
11
- describe('fetchQuery', () => {
12
- const utils = createProcedureUtils<
13
- typeof UserFindInputSchema,
14
- typeof UserSchema,
15
- SchemaOutput<typeof UserSchema>
16
- >({} as any)
17
-
18
- it('simple', async () => {
19
- expectTypeOf<Parameters<typeof utils.fetchQuery>[0]>().toEqualTypeOf<
20
- SchemaInput<typeof UserFindInputSchema>
21
- >()
22
-
23
- const data = await utils.fetchQuery({ id: '1' })
24
-
25
- expectTypeOf(data).toEqualTypeOf<SchemaOutput<typeof UserSchema>>()
26
- })
27
-
28
- it('with options', async () => {
29
- await utils.fetchQuery(
30
- { id: '1' },
31
- {
32
- initialData: { id: '1', name: 'name-1' },
33
- },
34
- )
35
-
36
- await utils.fetchQuery(
37
- { id: '1' },
38
- {
39
- // @ts-expect-error invalid initialData
40
- initialData: { id: '1' },
41
- },
42
- )
43
- })
44
- })
45
-
46
- describe('fetchInfiniteQuery', () => {
47
- const utils = createProcedureUtils<
48
- typeof UserListInputSchema,
49
- typeof UserListOutputSchema,
50
- SchemaOutput<typeof UserListOutputSchema>
51
- >({} as any)
52
-
53
- it('simple', async () => {
54
- expectTypeOf<
55
- Parameters<typeof utils.fetchInfiniteQuery>[0]['input']
56
- >().toMatchTypeOf<{
57
- keyword?: string
58
- cursor?: never /** prevent user to set cursor */
59
- }>()
60
-
61
- const data = await utils.fetchInfiniteQuery({ input: {} })
62
-
63
- expectTypeOf(data).toEqualTypeOf<
64
- InfiniteData<
65
- SchemaOutput<typeof UserListOutputSchema>,
66
- number | undefined
67
- >
68
- >()
69
- })
70
-
71
- it('with options', async () => {
72
- await utils.fetchInfiniteQuery({
73
- input: { keyword: '1' },
74
- initialPageParam: 4,
75
- pages: 5,
76
- getNextPageParam(lastPage) {
77
- expectTypeOf(lastPage).toEqualTypeOf<
78
- SchemaOutput<typeof UserListOutputSchema>
79
- >()
80
-
81
- return lastPage.nextCursor
82
- },
83
- })
84
-
85
- await utils.fetchInfiniteQuery(
86
- { keyword: '1' },
87
- // @ts-expect-error missing getNextPageParam when pages is set
88
- {
89
- pages: 4,
90
- },
91
- )
92
-
93
- await utils.fetchInfiniteQuery({
94
- input: {},
95
- initialData: { pageParams: [], pages: [] },
96
- })
97
-
98
- await utils.fetchInfiniteQuery({
99
- input: {},
100
- // @ts-expect-error invalid initialData
101
- initialData: { pageParams: [] },
102
- })
103
- })
104
- })
105
-
106
- describe('prefetchQuery', () => {
107
- const utils = createProcedureUtils<
108
- typeof UserFindInputSchema,
109
- typeof UserSchema,
110
- SchemaOutput<typeof UserSchema>
111
- >({} as any)
112
-
113
- it('simple', async () => {
114
- expectTypeOf<Parameters<typeof utils.prefetchQuery>[0]>().toEqualTypeOf<
115
- SchemaInput<typeof UserFindInputSchema>
116
- >()
117
-
118
- const result = utils.prefetchQuery({ id: '1' })
119
-
120
- expectTypeOf(result).toEqualTypeOf<Promise<void>>()
121
- })
122
-
123
- it('with options', async () => {
124
- await utils.prefetchQuery(
125
- { id: '1' },
126
- {
127
- initialData: { id: '1', name: 'name-1' },
128
- },
129
- )
130
-
131
- await utils.prefetchQuery(
132
- { id: '1' },
133
- {
134
- // @ts-expect-error invalid initialData
135
- initialData: { id: '1' },
136
- },
137
- )
138
- })
139
- })
140
-
141
- describe('prefetchInfiniteQuery', () => {
142
- const utils = createProcedureUtils<
143
- typeof UserListInputSchema,
144
- typeof UserListOutputSchema,
145
- SchemaOutput<typeof UserListOutputSchema>
146
- >({} as any)
147
-
148
- it('simple', () => {
149
- expectTypeOf<
150
- Parameters<typeof utils.prefetchInfiniteQuery>[0]['input']
151
- >().toMatchTypeOf<{
152
- keyword?: string
153
- cursor?: never /** prevent user to set cursor */
154
- }>()
155
-
156
- const result = utils.prefetchInfiniteQuery({ input: {} })
157
-
158
- expectTypeOf(result).toEqualTypeOf<Promise<void>>()
159
- })
160
-
161
- it('with options', async () => {
162
- await utils.prefetchInfiniteQuery({
163
- input: { keyword: '1' },
164
- initialPageParam: 4,
165
- pages: 5,
166
- getNextPageParam(lastPage) {
167
- expectTypeOf(lastPage).toEqualTypeOf<
168
- SchemaOutput<typeof UserListOutputSchema>
169
- >()
170
-
171
- return lastPage.nextCursor
172
- },
173
- })
174
-
175
- await utils.prefetchInfiniteQuery(
176
- { keyword: '1' },
177
- // @ts-expect-error missing getNextPageParam when pages is set
178
- {
179
- pages: 4,
180
- },
181
- )
182
-
183
- await utils.prefetchInfiniteQuery({
184
- input: {},
185
- initialData: { pageParams: [], pages: [] },
186
- })
187
-
188
- await utils.prefetchInfiniteQuery({
189
- input: {},
190
- // @ts-expect-error invalid initialData
191
- initialData: { pageParams: [] },
192
- })
193
- })
194
- })
195
-
196
- describe('getQueryData', () => {
197
- const utils = createProcedureUtils<
198
- typeof UserFindInputSchema,
199
- typeof UserSchema,
200
- SchemaOutput<typeof UserSchema>
201
- >({} as any)
202
-
203
- it('simple', () => {
204
- expectTypeOf<Parameters<typeof utils.getQueryData>[0]>().toEqualTypeOf<
205
- SchemaInput<typeof UserFindInputSchema>
206
- >()
207
-
208
- const data = utils.getQueryData({ id: '1' })
209
-
210
- expectTypeOf(data).toEqualTypeOf<
211
- SchemaOutput<typeof UserSchema> | undefined
212
- >()
213
- })
214
- })
215
-
216
- describe('getInfiniteQueryData', () => {
217
- const utils = createProcedureUtils<
218
- typeof UserListInputSchema,
219
- typeof UserListOutputSchema,
220
- SchemaOutput<typeof UserListOutputSchema>
221
- >({} as any)
222
-
223
- it('simple', () => {
224
- expectTypeOf<
225
- Parameters<typeof utils.getInfiniteQueryData>[0]
226
- >().toMatchTypeOf<{
227
- keyword?: string
228
- cursor?: never /** prevent user to set cursor */
229
- }>()
230
-
231
- const data = utils.getInfiniteQueryData({})
232
-
233
- expectTypeOf(data).toEqualTypeOf<
234
- | undefined
235
- | InfiniteData<
236
- SchemaOutput<typeof UserListOutputSchema>,
237
- number | undefined
238
- >
239
- >()
240
- })
241
- })
242
-
243
- describe('ensureQueryData', () => {
244
- const utils = createProcedureUtils<
245
- typeof UserFindInputSchema,
246
- typeof UserSchema,
247
- SchemaOutput<typeof UserSchema>
248
- >({} as any)
249
-
250
- it('simple', async () => {
251
- expectTypeOf<Parameters<typeof utils.ensureQueryData>[0]>().toEqualTypeOf<
252
- SchemaInput<typeof UserFindInputSchema>
253
- >()
254
-
255
- const data = await utils.ensureQueryData({ id: '1' })
256
-
257
- expectTypeOf(data).toEqualTypeOf<SchemaOutput<typeof UserSchema>>()
258
- })
259
-
260
- it('with options', async () => {
261
- await utils.ensureQueryData(
262
- { id: '1' },
263
- {
264
- initialData: { id: '1', name: 'name-1' },
265
- },
266
- )
267
-
268
- await utils.ensureQueryData(
269
- { id: '1' },
270
- {
271
- // @ts-expect-error invalid initialData
272
- initialData: { id: '1' },
273
- },
274
- )
275
- })
276
- })
277
-
278
- describe('ensureInfiniteQuery', () => {
279
- const utils = createProcedureUtils<
280
- typeof UserListInputSchema,
281
- typeof UserListOutputSchema,
282
- SchemaOutput<typeof UserListOutputSchema>
283
- >({} as any)
284
-
285
- it('simple', async () => {
286
- expectTypeOf<
287
- Parameters<typeof utils.ensureInfiniteQueryData>[0]['input']
288
- >().toMatchTypeOf<{
289
- keyword?: string
290
- cursor?: never /** prevent user to set cursor */
291
- }>()
292
-
293
- const data = await utils.ensureInfiniteQueryData({
294
- input: {},
295
- })
296
-
297
- expectTypeOf(data).toEqualTypeOf<
298
- InfiniteData<
299
- SchemaOutput<typeof UserListOutputSchema>,
300
- number | undefined
301
- >
302
- >()
303
- })
304
-
305
- it('with options', async () => {
306
- await utils.ensureInfiniteQueryData({
307
- input: { keyword: '1' },
308
- initialPageParam: 4,
309
- pages: 5,
310
- getNextPageParam(lastPage) {
311
- expectTypeOf(lastPage).toEqualTypeOf<
312
- SchemaOutput<typeof UserListOutputSchema>
313
- >()
314
-
315
- return lastPage.nextCursor
316
- },
317
- })
318
-
319
- await utils.ensureInfiniteQueryData(
320
- { keyword: '1' },
321
- // @ts-expect-error missing getNextPageParam when pages is set
322
- {
323
- pages: 4,
324
- },
325
- )
326
-
327
- await utils.ensureInfiniteQueryData({
328
- input: {},
329
- initialData: { pageParams: [], pages: [] },
330
- })
331
-
332
- await utils.ensureInfiniteQueryData({
333
- input: {},
334
- // @ts-expect-error invalid initialData
335
- initialData: { pageParams: [] },
336
- })
337
- })
338
- })
339
-
340
- describe('getQueryState', () => {
341
- const utils = createProcedureUtils<
342
- typeof UserFindInputSchema,
343
- typeof UserSchema,
344
- SchemaOutput<typeof UserSchema>
345
- >({} as any)
346
-
347
- it('simple', () => {
348
- expectTypeOf<Parameters<typeof utils.getQueryState>[0]>().toEqualTypeOf<
349
- SchemaInput<typeof UserFindInputSchema>
350
- >()
351
-
352
- const data = utils.getQueryState({ id: '1' })
353
-
354
- expectTypeOf(data).toEqualTypeOf<
355
- undefined | QueryState<SchemaOutput<typeof UserSchema>>
356
- >()
357
- })
358
- })
359
-
360
- describe('getInfiniteQueryState', () => {
361
- const utils = createProcedureUtils<
362
- typeof UserListInputSchema,
363
- typeof UserListOutputSchema,
364
- SchemaOutput<typeof UserListOutputSchema>
365
- >({} as any)
366
-
367
- it('simple', () => {
368
- expectTypeOf<
369
- Parameters<typeof utils.getInfiniteQueryState>[0]
370
- >().toMatchTypeOf<{
371
- keyword?: string
372
- cursor?: never /** prevent user to set cursor */
373
- }>()
374
-
375
- const data = utils.getInfiniteQueryState({})
376
-
377
- expectTypeOf(data).toEqualTypeOf<
378
- | undefined
379
- | QueryState<
380
- InfiniteData<
381
- SchemaOutput<typeof UserListOutputSchema>,
382
- number | undefined
383
- >
384
- >
385
- >()
386
- })
387
- })
388
-
389
- describe('setQueryData', () => {
390
- const utils = createProcedureUtils<
391
- typeof UserFindInputSchema,
392
- typeof UserSchema,
393
- SchemaOutput<typeof UserSchema>
394
- >({} as any)
395
-
396
- it('simple', () => {
397
- expectTypeOf<Parameters<typeof utils.setQueryData>[0]>().toEqualTypeOf<
398
- SchemaInput<typeof UserFindInputSchema>
399
- >()
400
-
401
- const data = utils.setQueryData({ id: '1' }, (data) => {
402
- expectTypeOf(data).toEqualTypeOf<
403
- SchemaOutput<typeof UserSchema> | undefined
404
- >()
405
-
406
- return {
407
- id: '1',
408
- name: 'name-1',
409
- }
410
- })
411
-
412
- expectTypeOf(data).toEqualTypeOf<
413
- SchemaOutput<typeof UserSchema> | undefined
414
- >()
415
- })
416
-
417
- it('with options', () => {
418
- utils.setQueryData(
419
- { id: '1' },
420
- { id: '1', name: '5' },
421
- {
422
- updatedAt: 1233,
423
- },
424
- )
425
- })
426
- })
427
-
428
- describe('setInfiniteQueryData', () => {
429
- const utils = createProcedureUtils<
430
- typeof UserListInputSchema,
431
- typeof UserListOutputSchema,
432
- SchemaOutput<typeof UserListOutputSchema>
433
- >({} as any)
434
-
435
- it('simple', () => {
436
- expectTypeOf<
437
- Parameters<typeof utils.setInfiniteQueryData>[0]
438
- >().toMatchTypeOf<{
439
- keyword?: string
440
- cursor?: never /** prevent user to set cursor */
441
- }>()
442
-
443
- const data = utils.setInfiniteQueryData({}, (data) => {
444
- expectTypeOf(data).toEqualTypeOf<
445
- | undefined
446
- | InfiniteData<
447
- SchemaOutput<typeof UserListOutputSchema>,
448
- number | undefined
449
- >
450
- >()
451
-
452
- return {
453
- pageParams: [],
454
- pages: [],
455
- }
456
- })
457
-
458
- expectTypeOf(data).toEqualTypeOf<
459
- | undefined
460
- | InfiniteData<
461
- SchemaOutput<typeof UserListOutputSchema>,
462
- number | undefined
463
- >
464
- >()
465
- })
466
-
467
- it('with options', () => {
468
- utils.setInfiniteQueryData(
469
- { keyword: '1' },
470
- { pages: [], pageParams: [] },
471
- {
472
- updatedAt: 1244,
473
- },
474
- )
475
- })
476
- })