@orpc/react 0.0.3 → 0.0.5

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 (54) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +4970 -39
  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 +11 -14
  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.test-d.ts +2 -2
  50. package/src/use-queries/builder.ts +1 -2
  51. package/src/use-queries/builders.ts +9 -9
  52. package/src/use-queries/hook.test-d.ts +1 -1
  53. package/src/use-queries/hook.test.tsx +2 -2
  54. package/src/use-queries/hook.ts +8 -8
@@ -6,7 +6,7 @@ beforeEach(() => {
6
6
  })
7
7
 
8
8
  it('useUtils', async () => {
9
- const { result } = renderHook(() => orpc.useUtils(), { wrapper: wrapper })
9
+ const { result } = renderHook(() => orpc.useUtils(), { wrapper })
10
10
 
11
11
  const promise = result.current.user.find.ensureQueryData({ id: '1' })
12
12
  expect(result.current.user.isFetching()).toBe(1)
@@ -26,7 +26,7 @@ it('useUtils', async () => {
26
26
  })
27
27
 
28
28
  it('useContext', async () => {
29
- const { result } = renderHook(() => orpc.useContext(), { wrapper: wrapper })
29
+ const { result } = renderHook(() => orpc.useContext(), { wrapper })
30
30
 
31
31
  expect(result.current.client).toBe(orpcClient)
32
32
  expect(result.current.queryClient).toBe(queryClient)
@@ -38,8 +38,8 @@ it('useContext', async () => {
38
38
 
39
39
  it('useQueries', async () => {
40
40
  const queries = renderHook(
41
- () => orpc.useQueries((o) => [o.user.find({ id: '123' })]),
42
- { wrapper: wrapper },
41
+ () => orpc.useQueries(o => [o.user.find({ id: '123' })]),
42
+ { wrapper },
43
43
  )
44
44
 
45
45
  await waitFor(() =>
@@ -52,20 +52,20 @@ it('useQueries', async () => {
52
52
 
53
53
  it('hooks', async () => {
54
54
  const isFetching = renderHook(() => orpc.user.useIsFetching(), {
55
- wrapper: wrapper,
55
+ wrapper,
56
56
  })
57
57
  const isMutating = renderHook(() => orpc.user.useIsMutating(), {
58
- wrapper: wrapper,
58
+ wrapper,
59
59
  })
60
60
 
61
61
  expect(isFetching.result.current).toBe(0)
62
62
  expect(isMutating.result.current).toBe(0)
63
63
 
64
64
  const query = renderHook(() => orpc.user.find.useQuery({ id: '1' }), {
65
- wrapper: wrapper,
65
+ wrapper,
66
66
  })
67
67
  const mutation = renderHook(() => orpc.user.create.useMutation(), {
68
- wrapper: wrapper,
68
+ wrapper,
69
69
  })
70
70
 
71
71
  await waitFor(() => expect(query.result.current.status).toEqual('pending'))
package/src/react.tsx CHANGED
@@ -1,32 +1,32 @@
1
1
  import type { ContractRouter } from '@orpc/contract'
2
2
  import type { Router } from '@orpc/server'
3
3
  import {
4
+ createORPCContext,
4
5
  type ORPCContext,
5
6
  type ORPCContextValue,
6
- createORPCContext,
7
7
  useORPCContext,
8
8
  } from './react-context'
9
9
  import {
10
+ createORPCHooks,
10
11
  type ORPCHooksWithContractRouter,
11
12
  type ORPCHooksWithRouter,
12
- createORPCHooks,
13
13
  } from './react-hooks'
14
14
  import {
15
+ createORPCUtils,
15
16
  type ORPCUtilsWithContractRouter,
16
17
  type ORPCUtilsWithRouter,
17
- createORPCUtils,
18
18
  } from './react-utils'
19
19
  import {
20
+ useQueriesFactory,
20
21
  type UseQueriesWithContractRouter,
21
22
  type UseQueriesWithRouter,
22
- useQueriesFactory,
23
23
  } from './use-queries/hook'
24
24
 
25
25
  export type ORPCReactWithContractRouter<TRouter extends ContractRouter> =
26
26
  ORPCHooksWithContractRouter<TRouter> & {
27
27
  useContext: () => ORPCContextValue<TRouter>
28
28
  useUtils: () => ORPCUtilsWithContractRouter<TRouter>
29
- useQueries: () => UseQueriesWithContractRouter<TRouter>
29
+ useQueries: UseQueriesWithContractRouter<TRouter>
30
30
  }
31
31
 
32
32
  export type ORPCReactWithRouter<TRouter extends Router<any>> =
@@ -49,6 +49,7 @@ export function createORPCReact<
49
49
  const Context = createORPCContext<TRouter>()
50
50
  const useContext = () => useORPCContext(Context)
51
51
  const useUtils = () => createORPCUtils({ contextValue: useContext() })
52
+ // eslint-disable-next-line react-hooks/rules-of-hooks
52
53
  const useQueries = useQueriesFactory({ context: Context })
53
54
  const hooks = createORPCHooks({ context: Context })
54
55
 
@@ -1,12 +1,12 @@
1
1
  import type { SchemaInput } from '@orpc/contract'
2
2
  import type { PartialDeep } from '@orpc/shared'
3
3
  import type { MutationKey, QueryKey } from '@tanstack/react-query'
4
- import { getORPCPath } from './orpc-path'
5
4
  import type { ProcedureHooks } from './procedure-hooks'
6
5
  import type {
7
6
  ORPCHooksWithContractRouter,
8
7
  ORPCHooksWithRouter,
9
8
  } from './react-hooks'
9
+ import { getORPCPath } from './orpc-path'
10
10
 
11
11
  export type QueryType = 'query' | 'infinite' | undefined
12
12
 
@@ -17,9 +17,9 @@ export interface GetQueryKeyOptions<TInput> {
17
17
 
18
18
  export function getQueryKey<
19
19
  T extends
20
- | ORPCHooksWithContractRouter<any>
21
- | ORPCHooksWithRouter<any>
22
- | ProcedureHooks<any, any, any>,
20
+ | ORPCHooksWithContractRouter<any>
21
+ | ORPCHooksWithRouter<any>
22
+ | ProcedureHooks<any, any, any>,
23
23
  >(
24
24
  orpc: T,
25
25
  options?: GetQueryKeyOptions<
@@ -36,8 +36,8 @@ export function getQueryKeyFromPath(
36
36
  path: string[],
37
37
  options?: GetQueryKeyOptions<unknown>,
38
38
  ): QueryKey {
39
- const withInput =
40
- options?.input !== undefined ? { input: options?.input } : {}
39
+ const withInput
40
+ = options?.input !== undefined ? { input: options?.input } : {}
41
41
  const withType = options?.type !== undefined ? { type: options?.type } : {}
42
42
 
43
43
  return [
@@ -51,9 +51,9 @@ export function getQueryKeyFromPath(
51
51
 
52
52
  export function getMutationKey<
53
53
  T extends
54
- | ORPCHooksWithContractRouter<any>
55
- | ORPCHooksWithRouter<any>
56
- | ProcedureHooks<any, any, any>,
54
+ | ORPCHooksWithContractRouter<any>
55
+ | ORPCHooksWithRouter<any>
56
+ | ProcedureHooks<any, any, any>,
57
57
  >(orpc: T): MutationKey {
58
58
  const path = getORPCPath(orpc)
59
59
  return getMutationKeyFromPath(path)
@@ -20,8 +20,8 @@ export interface ORPCAdditionalQueryFilters<TFilterInput> {
20
20
 
21
21
  export interface ORPCQueryFilters<TFilterInput>
22
22
  extends SetOptional<QueryFilters, 'queryKey'>,
23
- ORPCAdditionalQueryFilters<TFilterInput> {}
23
+ ORPCAdditionalQueryFilters<TFilterInput> {}
24
24
 
25
25
  export interface ORPCInvalidateQueryFilters<TFilterInput>
26
26
  extends SetOptional<InvalidateQueryFilters, 'queryKey'>,
27
- ORPCAdditionalQueryFilters<TFilterInput> {}
27
+ ORPCAdditionalQueryFilters<TFilterInput> {}
package/src/types.ts CHANGED
@@ -4,4 +4,4 @@ export type SchemaInputForInfiniteQuery<TInputSchema extends Schema> = Omit<
4
4
  SchemaInput<TInputSchema>,
5
5
  'cursor'
6
6
  > &
7
- (Record<string | number, any> & { cursor?: never })
7
+ (Record<string | number, any> & { cursor?: never })
@@ -1,4 +1,4 @@
1
- import type { Promisable } from '@orpc/server'
1
+ import type { Promisable } from '@orpc/shared'
2
2
  import { orpcClient } from '../../tests/orpc'
3
3
  import { createUseQueriesBuilder } from './builder'
4
4
 
@@ -19,7 +19,7 @@ it('createUseQueriesBuilder', () => {
19
19
  builder({ id: 123 })
20
20
 
21
21
  if (typeof result.queryFn === 'function') {
22
- expectTypeOf(result.queryFn({} as any)).toEqualTypeOf<
22
+ expectTypeOf(result.queryFn({} as any)).toMatchTypeOf<
23
23
  Promisable<{
24
24
  id: string
25
25
  name: string
@@ -1,6 +1,5 @@
1
1
  import type { ProcedureClient } from '@orpc/client'
2
2
  import type { Schema, SchemaInput, SchemaOutput } from '@orpc/contract'
3
- import type {} from '@orpc/server'
4
3
  import type { SetOptional } from '@orpc/shared'
5
4
  import type {
6
5
  DefaultError,
@@ -54,7 +53,7 @@ export function createUseQueriesBuilder<
54
53
  TInputSchema extends Schema = undefined,
55
54
  TOutputSchema extends Schema = undefined,
56
55
  THandlerOutput extends
57
- SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
56
+ SchemaOutput<TOutputSchema> = SchemaOutput<TOutputSchema>,
58
57
  >(
59
58
  options: CreateUseQueriesBuilderOptions<
60
59
  TInputSchema,
@@ -9,7 +9,7 @@ import type {
9
9
  } from '@orpc/contract'
10
10
  import type { Procedure, Router } from '@orpc/server'
11
11
  import type {} from '@tanstack/react-query'
12
- import { type UseQueriesBuilder, createUseQueriesBuilder } from './builder'
12
+ import { createUseQueriesBuilder, type UseQueriesBuilder } from './builder'
13
13
 
14
14
  export type UseQueriesBuildersWithContractRouter<
15
15
  TRouter extends ContractRouter,
@@ -19,10 +19,10 @@ export type UseQueriesBuildersWithContractRouter<
19
19
  infer UOutputSchema
20
20
  >
21
21
  ? UseQueriesBuilder<
22
- UInputSchema,
23
- UOutputSchema,
24
- SchemaOutput<UOutputSchema>
25
- >
22
+ UInputSchema,
23
+ UOutputSchema,
24
+ SchemaOutput<UOutputSchema>
25
+ >
26
26
  : TRouter[K] extends ContractRouter
27
27
  ? UseQueriesBuildersWithContractRouter<TRouter[K]>
28
28
  : never
@@ -62,10 +62,10 @@ export function createUseQueriesBuilders<
62
62
  >(
63
63
  options: CreateUseQueriesBuildersOptions<TRouter>,
64
64
  ): TRouter extends Router<any>
65
- ? UseQueriesBuildersWithRouter<TRouter>
66
- : TRouter extends ContractRouter
67
- ? UseQueriesBuildersWithContractRouter<TRouter>
68
- : never {
65
+ ? UseQueriesBuildersWithRouter<TRouter>
66
+ : TRouter extends ContractRouter
67
+ ? UseQueriesBuildersWithContractRouter<TRouter>
68
+ : never {
69
69
  const path = options.path ?? []
70
70
  const client = options.client as any
71
71
 
@@ -1,9 +1,9 @@
1
1
  import type { SchemaOutput } from '@orpc/contract'
2
2
  import {
3
+ orpcClient,
3
4
  ORPCContext,
4
5
  type UserListOutputSchema,
5
6
  type UserSchema,
6
- orpcClient,
7
7
  } from '../../tests/orpc'
8
8
  import { createUseQueriesBuilders } from './builders'
9
9
  import { useQueriesFactory } from './hook'
@@ -1,5 +1,5 @@
1
1
  import { renderHook, waitFor } from '@testing-library/react'
2
- import { ORPCContext, orpcClient, wrapper } from '../../tests/orpc'
2
+ import { orpcClient, ORPCContext, wrapper } from '../../tests/orpc'
3
3
  import { createUseQueriesBuilders } from './builders'
4
4
  import { useQueriesFactory } from './hook'
5
5
 
@@ -18,7 +18,7 @@ describe('useQueriesFactory', () => {
18
18
 
19
19
  return [o.user.find({ id: '123' }), o.user.list({})]
20
20
  }),
21
- { wrapper: wrapper },
21
+ { wrapper },
22
22
  )
23
23
 
24
24
  await waitFor(() =>
@@ -7,9 +7,9 @@ import {
7
7
  } from '@tanstack/react-query'
8
8
  import { type ORPCContext, useORPCContext } from '../react-context'
9
9
  import {
10
+ createUseQueriesBuilders,
10
11
  type UseQueriesBuildersWithContractRouter,
11
12
  type UseQueriesBuildersWithRouter,
12
- createUseQueriesBuilders,
13
13
  } from './builders'
14
14
 
15
15
  export interface UseQueriesWithContractRouter<TRouter extends ContractRouter> {
@@ -39,19 +39,19 @@ export interface UseQueriesFactoryOptions<
39
39
  export function useQueriesFactory<TRouter extends Router<any> | ContractRouter>(
40
40
  options: UseQueriesFactoryOptions<TRouter>,
41
41
  ): TRouter extends Router<any>
42
- ? UseQueriesWithRouter<TRouter>
43
- : TRouter extends ContractRouter
44
- ? UseQueriesWithContractRouter<TRouter>
45
- : never {
46
- const hook = (build: any, combine?: any) => {
42
+ ? UseQueriesWithRouter<TRouter>
43
+ : TRouter extends ContractRouter
44
+ ? UseQueriesWithContractRouter<TRouter>
45
+ : never {
46
+ const Hook = (build: any, combine?: any): any => {
47
47
  const orpc = useORPCContext(options.context)
48
48
  const builders = createUseQueriesBuilders({ client: orpc.client as any })
49
49
 
50
50
  return useQueries({
51
51
  queries: build(builders),
52
- combine: combine,
52
+ combine,
53
53
  })
54
54
  }
55
55
 
56
- return hook as any
56
+ return Hook as any
57
57
  }