(keys: QueryKey, config: RouterConfig)
| 27 | } |
| 28 | |
| 29 | const buildRouter = (keys: QueryKey, config: RouterConfig) => { |
| 30 | return Object.entries(config).reduce( |
| 31 | (acc, [key, opts]) => { |
| 32 | if (!isRouterLeaf(opts)) { |
| 33 | acc[key] = buildRouter([...keys, key], opts) |
| 34 | } else { |
| 35 | const type = opts._routerType |
| 36 | const options: any = { |
| 37 | ...opts, |
| 38 | [type === `m` ? `mutationKey` : `queryKey`]: [...keys, key], |
| 39 | } |
| 40 | |
| 41 | if (type === `m`) { |
| 42 | acc[key] = { |
| 43 | useMutation: createMutation(options), |
| 44 | ...createMutation(options), |
| 45 | } |
| 46 | return acc |
| 47 | } |
| 48 | |
| 49 | acc[key] = |
| 50 | type === `q` |
| 51 | ? { |
| 52 | useQuery: createQuery(options), |
| 53 | useSuspenseQuery: createSuspenseQuery(options), |
| 54 | ...createQuery(options), |
| 55 | } |
| 56 | : { |
| 57 | useInfiniteQuery: createInfiniteQuery(options), |
| 58 | useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options), |
| 59 | ...createInfiniteQuery(options), |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | return acc |
| 64 | }, |
| 65 | { |
| 66 | getKey: () => keys, |
| 67 | } as any |
| 68 | ) |
| 69 | } |
| 70 | |
| 71 | export const router = <TConfig extends RouterConfig>( |
| 72 | key: string | QueryKey, |
no test coverage detected