react-query-kit 3.0.0-rc.1 → 3.0.0-rc.2
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.
- package/README.md +18 -28
- package/build/lib/router.d.ts +1 -24
- package/build/lib/router.esm.js +15 -37
- package/build/lib/router.esm.js.map +1 -1
- package/build/lib/router.js +15 -37
- package/build/lib/router.js.map +1 -1
- package/build/lib/router.mjs +15 -37
- package/build/lib/router.mjs.map +1 -1
- package/build/lib/types.d.ts +43 -10
- package/build/stats-html.html +1 -1
- package/build/stats.json +97 -97
- package/build/umd/index.development.js +15 -37
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/build/zip/zip.esm.js +1 -1
- package/package.json +1 -1
- package/src/router.ts +26 -129
- package/src/types.ts +153 -49
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.ts","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts","../../src/router.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n","import type {\n QueryClient,\n QueryFunctionContext,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getFullKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n fetcher?: any\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: Partial<UseInfiniteQueryOptions>\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n\n // @ts-ignore\n if (defaultOptions.queryFn) {\n console.error(\n '[Bug] queryFn is not supported, please use fetcher instead.'\n )\n }\n }\n\n const {\n queryKey,\n fetcher,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n const getQueryOptions = (fetcherFn: any, variables: any) => {\n return {\n queryFn: (context: QueryFunctionContext) => fetcherFn(variables, context),\n queryKey: getFullKey(queryKey, variables),\n }\n }\n\n const getKey = (variables?: any) => getFullKey(queryKey, variables)\n\n const getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n ...getQueryOptions(options.fetcher, options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n fetcher,\n getKey,\n getOptions,\n getFetchOptions,\n })\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type { CompatibleError, CreateQueryOptions, QueryHook } from './types'\nimport { ReactQuery } from './utils'\n\nexport const createQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, ReactQuery.useQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseQuery)\n : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n InfiniteQueryHook,\n} from './types'\nimport { ReactQuery } from './utils'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, ReactQuery.useInfiniteQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)\n : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)\n}\n","import type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { ReactQuery, withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError, TContext> => {\n return Object.assign(\n withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'),\n {\n getKey: () => defaultOptions.mutationKey,\n getOptions: () => defaultOptions,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError, TContext>\n}\n","import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n ExposeMethods,\n ExposeMutationMethods,\n InfiniteQueryHook,\n MutationHook,\n QueryHook,\n SuspenseQueryHook,\n} from './types'\n\nexport type RouterQuery<\n TFnData,\n TVariables = void,\n TError = CompatibleError\n> = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'> & {\n _type: `q`\n}\n\nexport type RouterInfiniteQuery<\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n> = Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n> & {\n _type: `inf`\n}\n\nexport type RouterMutation<\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n> = Omit<\n CreateMutationOptions<TData, TVariables, TError, TContext>,\n 'mutationKey'\n> & {\n _type: `m`\n}\n\nexport type RouterConfig = Record<\n string,\n | RouterQuery<any, any, any>\n | RouterInfiniteQuery<any, any, any>\n | RouterMutation<any, any, any>\n>\n\nexport type CreateRouter<TConfig extends RouterConfig> = {\n [K in keyof TConfig]: TConfig[K] extends RouterMutation<\n infer TFnData,\n infer TVariables,\n infer TError,\n infer TContext\n >\n ? {\n useMutation: MutationHook<TFnData, TVariables, TError, TContext>\n } & ExposeMutationMethods<TFnData, TVariables, TError, TContext>\n : TConfig[K] extends RouterInfiniteQuery<\n infer TFnData,\n infer TVariables,\n infer TError,\n infer TPageParam\n >\n ? {\n useInfiniteQuery: InfiniteQueryHook<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n useSuspenseInfiniteQuery: InfiniteQueryHook<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n } & ExposeMethods<TFnData, TVariables, TError, TPageParam>\n : TConfig[K] extends Omit<\n RouterQuery<infer TFnData, infer TVariables, infer TError>,\n 'queryKey'\n >\n ? {\n useQuery: QueryHook<TFnData, TVariables, TError>\n useSuspenseQuery: SuspenseQueryHook<TFnData, TVariables, TError>\n } & ExposeMethods<TFnData, TVariables, TError>\n : never\n} & { getKey: () => [string] }\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n const keys = [scope, key]\n\n if (opts._type === `m`) {\n acc[key] = {\n useMutation: createMutation({\n ...opts,\n mutationKey: keys,\n }),\n ...createMutation({\n ...opts,\n mutationKey: keys,\n }),\n }\n } else if (opts._type === `q`) {\n acc[key] = {\n useQuery: createQuery({\n ...(opts as any),\n queryKey: keys,\n }),\n useSuspenseQuery: createSuspenseQuery({\n ...(opts as any),\n queryKey: keys,\n }),\n ...createQuery({\n ...(opts as any),\n queryKey: keys,\n }),\n }\n } else {\n acc[key] = {\n useInfiniteQuery: createInfiniteQuery({\n ...opts,\n queryKey: keys,\n }),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery({\n ...(opts as any),\n queryKey: keys,\n }),\n ...createInfiniteQuery({\n ...opts,\n queryKey: keys,\n }),\n }\n }\n\n return acc\n },\n {\n getKey: () => [scope],\n } as any\n )\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["ReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","undefined","state","data","withMiddleware","hook","defaultOptions","type","options","queryClient","middleware","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","getKey","queryKey","variables","createBaseQuery","useRQHook","overrideOptions","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","queryFn","context","getFullKey","Object","assign","getOptions","getFetchOptions","createQuery","useQuery","createSuspenseQuery","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","useSuspenseInfiniteQuery","createMutation","useMutation","mutationKey","mutationFn","router","scope","config","entries","acc","key","keys","_type","infiniteQuery","mutation"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.ts","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts","../../src/router.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n","import type {\n QueryClient,\n QueryFunctionContext,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getFullKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n fetcher?: any\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: Partial<UseInfiniteQueryOptions>\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n\n // @ts-ignore\n if (defaultOptions.queryFn) {\n console.error(\n '[Bug] queryFn is not supported, please use fetcher instead.'\n )\n }\n }\n\n const {\n queryKey,\n fetcher,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n const getQueryOptions = (fetcherFn: any, variables: any) => {\n return {\n queryFn: (context: QueryFunctionContext) => fetcherFn(variables, context),\n queryKey: getFullKey(queryKey, variables),\n }\n }\n\n const getKey = (variables?: any) => getFullKey(queryKey, variables)\n\n const getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n ...getQueryOptions(options.fetcher, options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n fetcher,\n getKey,\n getOptions,\n getFetchOptions,\n })\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type { CompatibleError, CreateQueryOptions, QueryHook } from './types'\nimport { ReactQuery } from './utils'\n\nexport const createQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, ReactQuery.useQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseQuery)\n : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n InfiniteQueryHook,\n} from './types'\nimport { ReactQuery } from './utils'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, ReactQuery.useInfiniteQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)\n : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)\n}\n","import type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { ReactQuery, withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError, TContext> => {\n return Object.assign(\n withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'),\n {\n getKey: () => defaultOptions.mutationKey,\n getOptions: () => defaultOptions,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError, TContext>\n}\n","import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n\n return acc\n },\n {\n getKey: () => [scope],\n } as any\n )\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["ReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","undefined","state","data","withMiddleware","hook","defaultOptions","type","options","queryClient","middleware","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","getKey","queryKey","variables","createBaseQuery","useRQHook","overrideOptions","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","queryFn","context","getFullKey","Object","assign","getOptions","getFetchOptions","createQuery","useQuery","createSuspenseQuery","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","useSuspenseInfiniteQuery","createMutation","useMutation","mutationKey","mutationFn","router","scope","config","entries","acc","key","_type","infiniteQuery","mutation"],"mappings":"4lBAKO,MAAMA,OAEAC,IAASD,EAAWE,iBAEpBC,EAAkB,CAC7BC,SAAS,EACTC,UAAU,EACVC,iBAAkB,CAACC,EAAiBC,SACbC,IAArBD,EAAME,MAAMC,MAGHC,EAAiB,CAC5BC,EACAC,EACAC,IAEO,SACLC,EACAC,GAEA,MAAOC,EAAYC,GAAQ,CACzBnB,EAAWoB,eAETnB,EAAOgB,EAAcD,GACrBK,oBAAoBN,GACtBD,EACAE,GACAM,QACA,EAAEC,EAAIC,IAAOC,IAAKC,EAAK,MAAOC,GAAO,CAAA,IAAO,CAC1C,IAAIJ,KAAOG,GACX,IAAKF,KAAOG,KAEd,CAAC,KAGH,IAAIC,EAAOf,EACX,IAAK,IAAIgB,EAAIX,EAAWY,OAAQD,KAC9BD,EAAOV,EAAWW,GAAGD,GAGvB,OAAOA,EAAKT,EAAMF,IAITc,EAAS,CAACC,EAAoBC,SACpBxB,IAAdwB,EAA0B,IAAID,GAAY,IAAIA,EAAUC,GCzBpDC,EAAkB,CAC7BpB,EACAqB,EACAC,KAkBA,MAAMJ,SACJA,EADIK,QAEJA,EAFIC,eAGJA,EAHIC,qBAIJA,EAJIC,iBAKJA,EALIC,iBAMJA,GACE3B,EAEE4B,EAAkB,CAACC,EAAgBV,KAChC,CACLW,QAAUC,GAAkCF,EAAUV,EAAWY,GACjEb,SAAUc,EAAWd,EAAUC,KAqCnC,OAAOc,OAAOC,OAAOpC,GAdD,CAClBI,EACAC,IAEOkB,EACL,IACKnB,KACAoB,KACAM,EAAgB1B,EAAQqB,QAASrB,EAAQiB,YAE9ChB,IAI6CH,EAAgB,WAAY,CAC3EuB,iBAlCcJ,GAAoBa,EAAWd,EAAUC,GAoCvDgB,WAlCkBhB,IACX,IACFnB,KACA4B,EAAgBL,EAASJ,KAgC9BiB,gBA5BuBjB,IAChB,CACLK,iBACAC,uBACAC,mBACAC,sBACGC,EAAgBL,EAASJ,MAkBhC,EC3FWkB,EAKXnC,GAEOkB,EAAgBlB,EAAShB,EAAWoD,UCHhCC,EAKXrC,GAEOf,EACHiC,EAAgBlB,EAAShB,EAAWE,kBACpCgC,EAAgBlB,EAAShB,EAAWoD,SAAUjD,GCTvCmD,EAMXtC,GAEOkB,EAAgBlB,EAAShB,EAAWuD,kBCRhCC,EAMXxC,GAOOf,EACHiC,EAAgBlB,EAAShB,EAAWyD,0BACpCvB,EAAgBlB,EAAShB,EAAWuD,iBAAkBpD,GChB/CuD,EAMX5C,GAEOiC,OAAOC,OACZpC,EAAeZ,EAAW2D,YAAa7C,EAAgB,aACvD,CACEiB,OAAQ,IAAMjB,EAAe8C,YAC7BX,WAAY,IAAMnC,EAClB+C,WAAY/C,EAAe+C,aCHpBC,EAAS,CACpBC,EACAC,IAEOjB,OAAOkB,QAAQD,GAAQ1C,QAC5B,CAAC4C,GAAMC,EAAKhD,MACV,MAAMH,EAAe,IAChBG,EACH,CAAC,MAAAA,EAAKiD,MAAL,cAAA,YAAkD,CAACL,EAAOI,IAqB7D,OAlBAD,EAAIC,GAEE,MADJhD,EAAKiD,MACD,CACET,YAAaD,EAAe1C,MACzB0C,EAAe1C,IAGpB,MADAG,EAAKiD,MACL,CACEhB,SAAUD,EAAYnC,GACtBd,iBAAkBmD,EAAoBrC,MACnCmC,EAAYnC,IAEjB,CACEuC,iBAAkBD,EAAoBtC,GACtCyC,yBAA0BD,EAA4BxC,MACnDsC,EAAoBtC,IAGxBkD,CAAP,GAEF,CACEnC,OAAQ,IAAM,CAACgC,KAKrBD,EAAOtD,MACLQ,IAEO,IACFA,EACHoD,MAAO,MAIXN,EAAOO,cAMLrD,IAKO,IAAKA,EAASoD,MAAO,QAG9BN,EAAOQ,SAMLtD,IAKO,IAAKA,EAASoD,MAAO"}
|
package/build/zip/zip.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"@tanstack/react-query";const t=e,u=!!t.useSuspenseQuery,
|
|
1
|
+
import*as e from"@tanstack/react-query";const t=e,u=!!t.useSuspenseQuery,n={enabled:!0,suspense:!0,useErrorBoundary:(e,t)=>void 0===t.state.data},r=(e,n,r)=>function(s,a){const[i,y]=[t.useQueryClient(u?a:s).getDefaultOptions()[r],n,s].reduce((([e,t],{use:u=[],...n}={})=>[[...e,...u],{...t,...n}]),[[]]);let o=e;for(let e=i.length;e--;)o=i[e](o);return o(y,a)},s=(e,t)=>void 0===t?[...e]:[...e,t],a=(e,t,u)=>{const{queryKey:n,fetcher:a,queryKeyHashFn:i,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g}=e,p=(e,t)=>({queryFn:u=>e(t,u),queryKey:s(n,t)});return Object.assign(r(((e,n)=>t({...e,...u,...p(e.fetcher,e.variables)},n)),e,"queries"),{fetcher:a,getKey:e=>s(n,e),getOptions:t=>({...e,...p(a,t)}),getFetchOptions:e=>({queryKeyHashFn:i,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g,...p(a,e)})})},i=e=>a(e,t.useQuery),y=e=>u?a(e,t.useSuspenseQuery):a(e,t.useQuery,n),o=e=>a(e,t.useInfiniteQuery),g=e=>u?a(e,t.useSuspenseInfiniteQuery):a(e,t.useInfiniteQuery,n),p=e=>Object.assign(r(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,getOptions:()=>e,mutationFn:e.mutationFn}),m=(e,t)=>Object.entries(t).reduce(((t,[u,n])=>{const r={...n,["m"===n._type?"mutationKey":"queryKey"]:[e,u]};return t[u]="m"===n._type?{useMutation:p(r),...p(r)}:"q"===n._type?{useQuery:i(r),useSuspenseQuery:y(r),...i(r)}:{useInfiniteQuery:o(r),useSuspenseInfiniteQuery:g(r),...o(r)},t}),{getKey:()=>[e]});m.query=e=>({...e,_type:"q"}),m.infiniteQuery=e=>({...e,_type:"inf"}),m.mutation=e=>({...e,_type:"m"});export{o as createInfiniteQuery,p as createMutation,i as createQuery,g as createSuspenseInfiniteQuery,y as createSuspenseQuery,s as getKey,m as router};
|
package/package.json
CHANGED
package/src/router.ts
CHANGED
|
@@ -8,145 +8,42 @@ import type {
|
|
|
8
8
|
CreateInfiniteQueryOptions,
|
|
9
9
|
CreateMutationOptions,
|
|
10
10
|
CreateQueryOptions,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
SuspenseQueryHook,
|
|
11
|
+
CreateRouter,
|
|
12
|
+
RouterConfig,
|
|
13
|
+
RouterInfiniteQuery,
|
|
14
|
+
RouterMutation,
|
|
15
|
+
RouterQuery,
|
|
17
16
|
} from './types'
|
|
18
17
|
|
|
19
|
-
export type RouterQuery<
|
|
20
|
-
TFnData,
|
|
21
|
-
TVariables = void,
|
|
22
|
-
TError = CompatibleError
|
|
23
|
-
> = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'> & {
|
|
24
|
-
_type: `q`
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export type RouterInfiniteQuery<
|
|
28
|
-
TFnData,
|
|
29
|
-
TVariables = void,
|
|
30
|
-
TError = CompatibleError,
|
|
31
|
-
TPageParam = number
|
|
32
|
-
> = Omit<
|
|
33
|
-
CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,
|
|
34
|
-
'queryKey'
|
|
35
|
-
> & {
|
|
36
|
-
_type: `inf`
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export type RouterMutation<
|
|
40
|
-
TData = unknown,
|
|
41
|
-
TVariables = void,
|
|
42
|
-
TError = CompatibleError,
|
|
43
|
-
TContext = unknown
|
|
44
|
-
> = Omit<
|
|
45
|
-
CreateMutationOptions<TData, TVariables, TError, TContext>,
|
|
46
|
-
'mutationKey'
|
|
47
|
-
> & {
|
|
48
|
-
_type: `m`
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export type RouterConfig = Record<
|
|
52
|
-
string,
|
|
53
|
-
| RouterQuery<any, any, any>
|
|
54
|
-
| RouterInfiniteQuery<any, any, any>
|
|
55
|
-
| RouterMutation<any, any, any>
|
|
56
|
-
>
|
|
57
|
-
|
|
58
|
-
export type CreateRouter<TConfig extends RouterConfig> = {
|
|
59
|
-
[K in keyof TConfig]: TConfig[K] extends RouterMutation<
|
|
60
|
-
infer TFnData,
|
|
61
|
-
infer TVariables,
|
|
62
|
-
infer TError,
|
|
63
|
-
infer TContext
|
|
64
|
-
>
|
|
65
|
-
? {
|
|
66
|
-
useMutation: MutationHook<TFnData, TVariables, TError, TContext>
|
|
67
|
-
} & ExposeMutationMethods<TFnData, TVariables, TError, TContext>
|
|
68
|
-
: TConfig[K] extends RouterInfiniteQuery<
|
|
69
|
-
infer TFnData,
|
|
70
|
-
infer TVariables,
|
|
71
|
-
infer TError,
|
|
72
|
-
infer TPageParam
|
|
73
|
-
>
|
|
74
|
-
? {
|
|
75
|
-
useInfiniteQuery: InfiniteQueryHook<
|
|
76
|
-
TFnData,
|
|
77
|
-
TVariables,
|
|
78
|
-
TError,
|
|
79
|
-
TPageParam
|
|
80
|
-
>
|
|
81
|
-
useSuspenseInfiniteQuery: InfiniteQueryHook<
|
|
82
|
-
TFnData,
|
|
83
|
-
TVariables,
|
|
84
|
-
TError,
|
|
85
|
-
TPageParam
|
|
86
|
-
>
|
|
87
|
-
} & ExposeMethods<TFnData, TVariables, TError, TPageParam>
|
|
88
|
-
: TConfig[K] extends Omit<
|
|
89
|
-
RouterQuery<infer TFnData, infer TVariables, infer TError>,
|
|
90
|
-
'queryKey'
|
|
91
|
-
>
|
|
92
|
-
? {
|
|
93
|
-
useQuery: QueryHook<TFnData, TVariables, TError>
|
|
94
|
-
useSuspenseQuery: SuspenseQueryHook<TFnData, TVariables, TError>
|
|
95
|
-
} & ExposeMethods<TFnData, TVariables, TError>
|
|
96
|
-
: never
|
|
97
|
-
} & { getKey: () => [string] }
|
|
98
|
-
|
|
99
18
|
export const router = <TConfig extends RouterConfig>(
|
|
100
19
|
scope: string,
|
|
101
20
|
config: TConfig
|
|
102
21
|
): CreateRouter<TConfig> => {
|
|
103
22
|
return Object.entries(config).reduce(
|
|
104
23
|
(acc, [key, opts]) => {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
acc[key] = {
|
|
109
|
-
useMutation: createMutation({
|
|
110
|
-
...opts,
|
|
111
|
-
mutationKey: keys,
|
|
112
|
-
}),
|
|
113
|
-
...createMutation({
|
|
114
|
-
...opts,
|
|
115
|
-
mutationKey: keys,
|
|
116
|
-
}),
|
|
117
|
-
}
|
|
118
|
-
} else if (opts._type === `q`) {
|
|
119
|
-
acc[key] = {
|
|
120
|
-
useQuery: createQuery({
|
|
121
|
-
...(opts as any),
|
|
122
|
-
queryKey: keys,
|
|
123
|
-
}),
|
|
124
|
-
useSuspenseQuery: createSuspenseQuery({
|
|
125
|
-
...(opts as any),
|
|
126
|
-
queryKey: keys,
|
|
127
|
-
}),
|
|
128
|
-
...createQuery({
|
|
129
|
-
...(opts as any),
|
|
130
|
-
queryKey: keys,
|
|
131
|
-
}),
|
|
132
|
-
}
|
|
133
|
-
} else {
|
|
134
|
-
acc[key] = {
|
|
135
|
-
useInfiniteQuery: createInfiniteQuery({
|
|
136
|
-
...opts,
|
|
137
|
-
queryKey: keys,
|
|
138
|
-
}),
|
|
139
|
-
useSuspenseInfiniteQuery: createSuspenseInfiniteQuery({
|
|
140
|
-
...(opts as any),
|
|
141
|
-
queryKey: keys,
|
|
142
|
-
}),
|
|
143
|
-
...createInfiniteQuery({
|
|
144
|
-
...opts,
|
|
145
|
-
queryKey: keys,
|
|
146
|
-
}),
|
|
147
|
-
}
|
|
24
|
+
const options: any = {
|
|
25
|
+
...opts,
|
|
26
|
+
[opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],
|
|
148
27
|
}
|
|
149
28
|
|
|
29
|
+
acc[key] =
|
|
30
|
+
opts._type === `m`
|
|
31
|
+
? {
|
|
32
|
+
useMutation: createMutation(options),
|
|
33
|
+
...createMutation(options),
|
|
34
|
+
}
|
|
35
|
+
: opts._type === `q`
|
|
36
|
+
? {
|
|
37
|
+
useQuery: createQuery(options),
|
|
38
|
+
useSuspenseQuery: createSuspenseQuery(options),
|
|
39
|
+
...createQuery(options),
|
|
40
|
+
}
|
|
41
|
+
: {
|
|
42
|
+
useInfiniteQuery: createInfiniteQuery(options),
|
|
43
|
+
useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),
|
|
44
|
+
...createInfiniteQuery(options),
|
|
45
|
+
}
|
|
46
|
+
|
|
150
47
|
return acc
|
|
151
48
|
},
|
|
152
49
|
{
|
package/src/types.ts
CHANGED
|
@@ -54,6 +54,12 @@ type WithRequired<T, K extends keyof T> = T & {
|
|
|
54
54
|
[_ in K]: {}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
type DeepPartial<T> = T extends object
|
|
58
|
+
? {
|
|
59
|
+
[P in keyof T]?: DeepPartial<T[P]>
|
|
60
|
+
}
|
|
61
|
+
: T
|
|
62
|
+
|
|
57
63
|
export type CompatibleError = CompatibleWithV4<DefaultError, Error>
|
|
58
64
|
|
|
59
65
|
export type Fetcher<TFnData, TVariables = void, TPageParam = never> = (
|
|
@@ -75,19 +81,15 @@ export type Middleware<
|
|
|
75
81
|
T extends (...args: any) => any = QueryHook<any, any, any>
|
|
76
82
|
> = (hook: inferMiddlewareHook<T>) => inferMiddlewareHook<T>
|
|
77
83
|
|
|
78
|
-
type
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
: T
|
|
84
|
+
export type ExposeFetcher<TFnData, TVariables = void, TPageParam = never> = (
|
|
85
|
+
variables: TVariables,
|
|
86
|
+
context?: Partial<QueryFunctionContext<QueryKey, TPageParam>>
|
|
87
|
+
) => TFnData | Promise<TFnData>
|
|
83
88
|
|
|
84
89
|
export type ExposeMethods<TFnData, TVariables, TError, TPageParam = never> = {
|
|
85
|
-
fetcher:
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
) => TFnData | Promise<TFnData>
|
|
89
|
-
getKey: <V extends DeepPartial<TVariables> | void = void>(
|
|
90
|
-
variables?: V
|
|
90
|
+
fetcher: ExposeFetcher<TFnData, TVariables, TPageParam>
|
|
91
|
+
getKey: (
|
|
92
|
+
variables?: DeepPartial<TVariables>
|
|
91
93
|
) => CompatibleWithV4<
|
|
92
94
|
DataTag<
|
|
93
95
|
QueryKey,
|
|
@@ -489,51 +491,37 @@ export interface MutationHook<
|
|
|
489
491
|
|
|
490
492
|
// infer types
|
|
491
493
|
|
|
492
|
-
export type inferVariables<T> = T extends
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
? TVariables
|
|
496
|
-
: T extends InfiniteQueryHook<any, infer TVariables, any>
|
|
497
|
-
? TVariables
|
|
498
|
-
: T extends SuspenseInfiniteQueryHook<any, infer TVariables, any>
|
|
494
|
+
export type inferVariables<T> = T extends {
|
|
495
|
+
fetcher: ExposeFetcher<any, infer TVariables, any>
|
|
496
|
+
}
|
|
499
497
|
? TVariables
|
|
500
|
-
: T extends
|
|
498
|
+
: T extends ExposeMutationMethods<any, infer TVariables, any, any>
|
|
501
499
|
? TVariables
|
|
502
500
|
: never
|
|
503
501
|
|
|
504
|
-
export type inferData<T> = T extends
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
?
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
: T extends
|
|
511
|
-
?
|
|
512
|
-
: T extends MutationHook<infer TData, any, any>
|
|
513
|
-
? TData
|
|
502
|
+
export type inferData<T> = T extends {
|
|
503
|
+
fetcher: ExposeFetcher<infer TFnData, any, infer TPageParam>
|
|
504
|
+
}
|
|
505
|
+
? [TPageParam] extends [never]
|
|
506
|
+
? TFnData
|
|
507
|
+
: CompatibleInfiniteData<TFnData, TPageParam>
|
|
508
|
+
: T extends ExposeMutationMethods<infer TFnData, any, any, any>
|
|
509
|
+
? TFnData
|
|
514
510
|
: never
|
|
515
511
|
|
|
516
|
-
export type inferFnData<T> = T extends
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
?
|
|
520
|
-
: T extends
|
|
521
|
-
?
|
|
522
|
-
: T extends SuspenseInfiniteQueryHook<infer TData, any, any>
|
|
523
|
-
? TData
|
|
524
|
-
: T extends MutationHook<infer TData, any, any>
|
|
525
|
-
? TData
|
|
512
|
+
export type inferFnData<T> = T extends {
|
|
513
|
+
fetcher: ExposeFetcher<infer TFnData, any, any>
|
|
514
|
+
}
|
|
515
|
+
? TFnData
|
|
516
|
+
: T extends ExposeMutationMethods<infer TFnData, any, any, any>
|
|
517
|
+
? TFnData
|
|
526
518
|
: never
|
|
527
519
|
|
|
528
|
-
export type inferError<T> = T extends
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
? TError
|
|
532
|
-
: T extends InfiniteQueryHook<any, any, infer TError>
|
|
533
|
-
? TError
|
|
534
|
-
: T extends SuspenseInfiniteQueryHook<any, any, infer TError>
|
|
520
|
+
export type inferError<T> = T extends {
|
|
521
|
+
fetcher: ExposeFetcher<any, infer TError, any>
|
|
522
|
+
}
|
|
535
523
|
? TError
|
|
536
|
-
: T extends
|
|
524
|
+
: T extends ExposeMutationMethods<any, any, infer TError, any>
|
|
537
525
|
? TError
|
|
538
526
|
: never
|
|
539
527
|
|
|
@@ -597,6 +585,122 @@ export type inferCreateOptions<T> = T extends QueryHook<
|
|
|
597
585
|
infer TPageParam
|
|
598
586
|
>
|
|
599
587
|
? CreateSuspenseInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>
|
|
600
|
-
: T extends MutationHook<
|
|
601
|
-
|
|
588
|
+
: T extends MutationHook<
|
|
589
|
+
infer TFnData,
|
|
590
|
+
infer TVariables,
|
|
591
|
+
infer TError,
|
|
592
|
+
infer TContext
|
|
593
|
+
>
|
|
594
|
+
? CreateMutationOptions<TFnData, TError, TVariables, TContext>
|
|
602
595
|
: never
|
|
596
|
+
|
|
597
|
+
// router
|
|
598
|
+
|
|
599
|
+
export type RouterQuery<
|
|
600
|
+
TFnData,
|
|
601
|
+
TVariables = void,
|
|
602
|
+
TError = CompatibleError
|
|
603
|
+
> = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'> & {
|
|
604
|
+
_type: `q`
|
|
605
|
+
}
|
|
606
|
+
|
|
607
|
+
export type RouterInfiniteQuery<
|
|
608
|
+
TFnData,
|
|
609
|
+
TVariables = void,
|
|
610
|
+
TError = CompatibleError,
|
|
611
|
+
TPageParam = number
|
|
612
|
+
> = Omit<
|
|
613
|
+
CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,
|
|
614
|
+
'queryKey'
|
|
615
|
+
> & {
|
|
616
|
+
_type: `inf`
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
export type RouterMutation<
|
|
620
|
+
TData = unknown,
|
|
621
|
+
TVariables = void,
|
|
622
|
+
TError = CompatibleError,
|
|
623
|
+
TContext = unknown
|
|
624
|
+
> = Omit<
|
|
625
|
+
CreateMutationOptions<TData, TVariables, TError, TContext>,
|
|
626
|
+
'mutationKey'
|
|
627
|
+
> & {
|
|
628
|
+
_type: `m`
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
type DefaultTo<T, D> = unknown extends T ? D : T
|
|
632
|
+
|
|
633
|
+
export type RouterConfig = Record<
|
|
634
|
+
string,
|
|
635
|
+
| RouterQuery<any, any, any>
|
|
636
|
+
| RouterInfiniteQuery<any, any, any, any>
|
|
637
|
+
| RouterMutation<any, any, any, any>
|
|
638
|
+
>
|
|
639
|
+
|
|
640
|
+
export type CreateRouter<TConfig extends RouterConfig> = {
|
|
641
|
+
[K in keyof TConfig]: TConfig[K] extends RouterMutation<
|
|
642
|
+
infer TFnData,
|
|
643
|
+
infer TVariables,
|
|
644
|
+
infer TError,
|
|
645
|
+
infer TContext
|
|
646
|
+
>
|
|
647
|
+
? {
|
|
648
|
+
useMutation: MutationHook<
|
|
649
|
+
TFnData,
|
|
650
|
+
DefaultTo<TVariables, void>,
|
|
651
|
+
DefaultTo<TError, CompatibleError>,
|
|
652
|
+
TContext
|
|
653
|
+
>
|
|
654
|
+
} & ExposeMutationMethods<
|
|
655
|
+
TFnData,
|
|
656
|
+
DefaultTo<TVariables, void>,
|
|
657
|
+
DefaultTo<TError, CompatibleError>,
|
|
658
|
+
TContext
|
|
659
|
+
>
|
|
660
|
+
: TConfig[K] extends RouterInfiniteQuery<
|
|
661
|
+
infer TFnData,
|
|
662
|
+
infer TVariables,
|
|
663
|
+
infer TError,
|
|
664
|
+
infer TPageParam
|
|
665
|
+
>
|
|
666
|
+
? {
|
|
667
|
+
useInfiniteQuery: InfiniteQueryHook<
|
|
668
|
+
TFnData,
|
|
669
|
+
DefaultTo<TVariables, void>,
|
|
670
|
+
DefaultTo<TError, CompatibleError>,
|
|
671
|
+
TPageParam
|
|
672
|
+
>
|
|
673
|
+
useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<
|
|
674
|
+
TFnData,
|
|
675
|
+
DefaultTo<TVariables, void>,
|
|
676
|
+
DefaultTo<TError, CompatibleError>,
|
|
677
|
+
TPageParam
|
|
678
|
+
>
|
|
679
|
+
} & ExposeMethods<
|
|
680
|
+
TFnData,
|
|
681
|
+
DefaultTo<TVariables, void>,
|
|
682
|
+
DefaultTo<TError, CompatibleError>,
|
|
683
|
+
TPageParam
|
|
684
|
+
>
|
|
685
|
+
: TConfig[K] extends Omit<
|
|
686
|
+
RouterQuery<infer TFnData, infer TVariables, infer TError>,
|
|
687
|
+
'queryKey'
|
|
688
|
+
>
|
|
689
|
+
? {
|
|
690
|
+
useQuery: QueryHook<
|
|
691
|
+
TFnData,
|
|
692
|
+
DefaultTo<TVariables, void>,
|
|
693
|
+
DefaultTo<TError, CompatibleError>
|
|
694
|
+
>
|
|
695
|
+
useSuspenseQuery: SuspenseQueryHook<
|
|
696
|
+
TFnData,
|
|
697
|
+
DefaultTo<TVariables, void>,
|
|
698
|
+
DefaultTo<TError, CompatibleError>
|
|
699
|
+
>
|
|
700
|
+
} & ExposeMethods<
|
|
701
|
+
TFnData,
|
|
702
|
+
DefaultTo<TVariables, void>,
|
|
703
|
+
DefaultTo<TError, CompatibleError>
|
|
704
|
+
>
|
|
705
|
+
: never
|
|
706
|
+
} & { getKey: () => [string] }
|