react-query-kit 3.0.0 → 3.1.1

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.
@@ -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 [uses, opts]: [Middleware[], any] = [\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 const composed = uses.reduceRight((next, use) => use(next), hook)\n\n return composed(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","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","reduceRight","next","composed","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,EAAMC,GAA6B,CACxCnB,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,KAIH,OAFiBT,EAAKU,aAAY,CAACC,EAAMJ,IAAQA,EAAII,IAAOhB,EAErDiB,CAASX,EAAMF,IAIbc,EAAS,CAACC,EAAoBC,SACpBxB,IAAdwB,EAA0B,IAAID,GAAY,IAAIA,EAAUC,GCrBpDC,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"}
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 typeof 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 [uses, opts]: [Middleware[], any] = [\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 const composedHook = uses.reduceRight((next, use) => use(next), hook)\n\n return composedHook(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return typeof 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 CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterInfiniteQueryOptions,\n RouterMutation,\n RouterMutationOptions,\n RouterQuery,\n RouterQueryOptions,\n} from './types'\n\nconst buildRouter = (keys: string[], config: RouterConfig) => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n if (!opts._type) {\n acc[key] = buildRouter([...keys, key], opts)\n } else {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [...keys, 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\n return acc\n },\n {\n getKey: () => keys,\n } as any\n )\n}\n\nexport const router = <TConfig extends RouterConfig>(\n key: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return buildRouter([key], config)\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: RouterQueryOptions<TFnData, TVariables, TError>\n) => {\n return {\n ...options,\n _type: 'q',\n } as RouterQuery<TFnData, TVariables, TError>\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: RouterInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n) => {\n return { ...options, _type: 'inf' } as RouterInfiniteQuery<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: RouterMutationOptions<TFnData, TVariables, TError, TContext>\n) => {\n return { ...options, _type: 'm' } as RouterMutation<\n TFnData,\n TVariables,\n TError,\n TContext\n >\n}\n"],"names":["ReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","withMiddleware","hook","defaultOptions","type","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","reduceRight","next","composedHook","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","buildRouter","keys","config","entries","acc","key","_type","router","infiniteQuery","mutation"],"mappings":"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"}
@@ -1 +1 @@
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,i){const[a,y]=[t.useQueryClient(u?i:s).getDefaultOptions()[r],n,s].reduce((([e,t],{use:u=[],...n}={})=>[[...e,...u],{...t,...n}]),[[]]);return a.reduceRight(((e,t)=>t(e)),e)(y,i)},s=(e,t)=>void 0===t?[...e]:[...e,t],i=(e,t,u)=>{const{queryKey:n,fetcher:i,queryKeyHashFn:a,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:i,getKey:e=>s(n,e),getOptions:t=>({...e,...p(i,t)}),getFetchOptions:e=>({queryKeyHashFn:a,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g,...p(i,e)})})},a=e=>i(e,t.useQuery),y=e=>u?i(e,t.useSuspenseQuery):i(e,t.useQuery,n),o=e=>i(e,t.useInfiniteQuery),g=e=>u?i(e,t.useSuspenseInfiniteQuery):i(e,t.useInfiniteQuery,n),p=e=>Object.assign(r(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,getOptions:()=>e,mutationFn:e.mutationFn}),c=(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:a(r),useSuspenseQuery:y(r),...a(r)}:{useInfiniteQuery:o(r),useSuspenseInfiniteQuery:g(r),...o(r)},t}),{getKey:()=>[e]});c.query=e=>({...e,_type:"q"}),c.infiniteQuery=e=>({...e,_type:"inf"}),c.mutation=e=>({...e,_type:"m"});export{o as createInfiniteQuery,p as createMutation,a as createQuery,g as createSuspenseInfiniteQuery,y as createSuspenseQuery,s as getKey,c as router};
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},s=(e,n,s)=>function(r,i){const[a,y]=[t.useQueryClient(u?i:r).getDefaultOptions()[s],n,r].reduce((([e,t],{use:u=[],...n}={})=>[[...e,...u],{...t,...n}]),[[]]);return a.reduceRight(((e,t)=>t(e)),e)(y,i)},r=(e,t)=>void 0===t?e:[...e,t],i=(e,t,u)=>{const{queryKey:n,fetcher:i,queryKeyHashFn:a,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g}=e,p=(e,t)=>({queryFn:u=>e(t,u),queryKey:r(n,t)});return Object.assign(s(((e,n)=>t({...e,...u,...p(e.fetcher,e.variables)},n)),e,"queries"),{fetcher:i,getKey:e=>r(n,e),getOptions:t=>({...e,...p(i,t)}),getFetchOptions:e=>({queryKeyHashFn:a,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g,...p(i,e)})})},a=e=>i(e,t.useQuery),y=e=>u?i(e,t.useSuspenseQuery):i(e,t.useQuery,n),o=e=>i(e,t.useInfiniteQuery),g=e=>u?i(e,t.useSuspenseInfiniteQuery):i(e,t.useInfiniteQuery,n),p=e=>Object.assign(s(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,getOptions:()=>e,mutationFn:e.mutationFn}),c=(e,t)=>Object.entries(t).reduce(((t,[u,n])=>{if(n._type){const s={...n,["m"===n._type?"mutationKey":"queryKey"]:[...e,u]};t[u]="m"===n._type?{useMutation:p(s),...p(s)}:"q"===n._type?{useQuery:a(s),useSuspenseQuery:y(s),...a(s)}:{useInfiniteQuery:o(s),useSuspenseInfiniteQuery:g(s),...o(s)}}else t[u]=c([...e,u],n);return t}),{getKey:()=>e}),m=(e,t)=>c([e],t);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,a as createQuery,g as createSuspenseInfiniteQuery,y as createSuspenseQuery,r as getKey,m as router};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-kit",
3
- "version": "3.0.0",
3
+ "version": "3.1.1",
4
4
  "description": "🕊️ A toolkit for ReactQuery that make ReactQuery hooks more reusable and typesafe",
5
5
  "author": "liaoliao666",
6
6
  "repository": "liaoliao666/react-query-kit",
@@ -27,7 +27,7 @@
27
27
  "@rollup/plugin-commonjs": "^22.0.2",
28
28
  "@rollup/plugin-node-resolve": "^13.2.1",
29
29
  "@rollup/plugin-replace": "^4.0.0",
30
- "@tanstack/react-query": "^5.0.0",
30
+ "@tanstack/react-query": "^5.18.0",
31
31
  "@testing-library/jest-dom": "^5.16.5",
32
32
  "@testing-library/react": "^14.0.0",
33
33
  "@trivago/prettier-plugin-sort-imports": "^4.2.0",
package/src/router.ts CHANGED
@@ -5,60 +5,68 @@ import { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'
5
5
  import { createSuspenseQuery } from './createSuspenseQuery'
6
6
  import type {
7
7
  CompatibleError,
8
- CreateInfiniteQueryOptions,
9
- CreateMutationOptions,
10
- CreateQueryOptions,
11
8
  CreateRouter,
12
9
  RouterConfig,
13
10
  RouterInfiniteQuery,
11
+ RouterInfiniteQueryOptions,
14
12
  RouterMutation,
13
+ RouterMutationOptions,
15
14
  RouterQuery,
15
+ RouterQueryOptions,
16
16
  } from './types'
17
17
 
18
- export const router = <TConfig extends RouterConfig>(
19
- scope: string,
20
- config: TConfig
21
- ): CreateRouter<TConfig> => {
18
+ const buildRouter = (keys: string[], config: RouterConfig) => {
22
19
  return Object.entries(config).reduce(
23
20
  (acc, [key, opts]) => {
24
- const options: any = {
25
- ...opts,
26
- [opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],
27
- }
21
+ if (!opts._type) {
22
+ acc[key] = buildRouter([...keys, key], opts)
23
+ } else {
24
+ const options: any = {
25
+ ...opts,
26
+ [opts._type === `m` ? `mutationKey` : `queryKey`]: [...keys, key],
27
+ }
28
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
- }
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
+ }
46
47
 
47
48
  return acc
48
49
  },
49
50
  {
50
- getKey: () => [scope],
51
+ getKey: () => keys,
51
52
  } as any
52
53
  )
53
54
  }
54
55
 
56
+ export const router = <TConfig extends RouterConfig>(
57
+ key: string,
58
+ config: TConfig
59
+ ): CreateRouter<TConfig> => {
60
+ return buildRouter([key], config)
61
+ }
62
+
55
63
  router.query = <TFnData, TVariables = void, TError = CompatibleError>(
56
- options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>
57
- ): RouterQuery<TFnData, TVariables, TError> => {
64
+ options: RouterQueryOptions<TFnData, TVariables, TError>
65
+ ) => {
58
66
  return {
59
67
  ...options,
60
68
  _type: 'q',
61
- }
69
+ } as RouterQuery<TFnData, TVariables, TError>
62
70
  }
63
71
 
64
72
  router.infiniteQuery = <
@@ -67,12 +75,14 @@ router.infiniteQuery = <
67
75
  TError = CompatibleError,
68
76
  TPageParam = number
69
77
  >(
70
- options: Omit<
71
- CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,
72
- 'queryKey'
78
+ options: RouterInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>
79
+ ) => {
80
+ return { ...options, _type: 'inf' } as RouterInfiniteQuery<
81
+ TFnData,
82
+ TVariables,
83
+ TError,
84
+ TPageParam
73
85
  >
74
- ): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {
75
- return { ...options, _type: 'inf' }
76
86
  }
77
87
 
78
88
  router.mutation = <
@@ -81,10 +91,12 @@ router.mutation = <
81
91
  TError = CompatibleError,
82
92
  TContext = unknown
83
93
  >(
84
- options: Omit<
85
- CreateMutationOptions<TFnData, TVariables, TError, TContext>,
86
- 'mutationKey'
94
+ options: RouterMutationOptions<TFnData, TVariables, TError, TContext>
95
+ ) => {
96
+ return { ...options, _type: 'm' } as RouterMutation<
97
+ TFnData,
98
+ TVariables,
99
+ TError,
100
+ TContext
87
101
  >
88
- ): RouterMutation<TFnData, TVariables, TError, TContext> => {
89
- return { ...options, _type: 'm' }
90
102
  }
package/src/types.ts CHANGED
@@ -60,6 +60,8 @@ type DeepPartial<T> = T extends object
60
60
  }
61
61
  : T
62
62
 
63
+ type DefaultTo<T, D> = unknown extends T ? D : T
64
+
63
65
  export type CompatibleError = CompatibleWithV4<DefaultError, Error>
64
66
 
65
67
  export type Fetcher<TFnData, TVariables = void, TPageParam = never> = (
@@ -596,15 +598,30 @@ export type inferCreateOptions<T> = T extends QueryHook<
596
598
 
597
599
  // router
598
600
 
601
+ export type RouterQueryOptions<
602
+ TFnData,
603
+ TVariables = void,
604
+ TError = CompatibleError
605
+ > = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>
606
+
599
607
  export type RouterQuery<
600
608
  TFnData,
601
609
  TVariables = void,
602
610
  TError = CompatibleError
603
- > = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'> & {
611
+ > = RouterQueryOptions<TFnData, TVariables, TError> & {
604
612
  _type: `q`
605
613
  }
606
614
 
607
- export type RouterInfiniteQuery<
615
+ export type ResolvedRouterQuery<
616
+ TFnData,
617
+ TVariables = void,
618
+ TError = CompatibleError
619
+ > = {
620
+ useQuery: QueryHook<TFnData, TVariables, TError>
621
+ useSuspenseQuery: SuspenseQueryHook<TFnData, TVariables, TError>
622
+ } & ExposeMethods<TFnData, TVariables, TError>
623
+
624
+ export type RouterInfiniteQueryOptions<
608
625
  TFnData,
609
626
  TVariables = void,
610
627
  TError = CompatibleError,
@@ -612,11 +629,38 @@ export type RouterInfiniteQuery<
612
629
  > = Omit<
613
630
  CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,
614
631
  'queryKey'
632
+ >
633
+
634
+ export type RouterInfiniteQuery<
635
+ TFnData,
636
+ TVariables = void,
637
+ TError = CompatibleError,
638
+ TPageParam = number
639
+ > = RouterInfiniteQueryOptions<
640
+ TFnData,
641
+ TVariables,
642
+ TError,
643
+ Clone<TPageParam>
615
644
  > & {
616
645
  _type: `inf`
617
646
  }
618
647
 
619
- export type RouterMutation<
648
+ export type ResolvedRouterInfiniteQuery<
649
+ TFnData,
650
+ TVariables = void,
651
+ TError = CompatibleError,
652
+ TPageParam = number
653
+ > = {
654
+ useInfiniteQuery: InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>
655
+ useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<
656
+ TFnData,
657
+ TVariables,
658
+ TError,
659
+ TPageParam
660
+ >
661
+ } & ExposeMethods<TFnData, TVariables, TError, TPageParam>
662
+
663
+ export type RouterMutationOptions<
620
664
  TData = unknown,
621
665
  TVariables = void,
622
666
  TError = CompatibleError,
@@ -624,19 +668,44 @@ export type RouterMutation<
624
668
  > = Omit<
625
669
  CreateMutationOptions<TData, TVariables, TError, TContext>,
626
670
  'mutationKey'
627
- > & {
671
+ >
672
+
673
+ export type RouterMutation<
674
+ TData = unknown,
675
+ TVariables = void,
676
+ TError = CompatibleError,
677
+ TContext = unknown
678
+ > = RouterMutationOptions<TData, TVariables, TError, TContext> & {
628
679
  _type: `m`
629
680
  }
630
681
 
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>
682
+ export type ResolvedRouterMutation<
683
+ TData = unknown,
684
+ TVariables = void,
685
+ TError = CompatibleError,
686
+ TContext = unknown
687
+ > = {
688
+ useMutation: MutationHook<
689
+ TData,
690
+ DefaultTo<TVariables, void>,
691
+ DefaultTo<TError, CompatibleError>,
692
+ TContext
693
+ >
694
+ } & ExposeMutationMethods<
695
+ TData,
696
+ DefaultTo<TVariables, void>,
697
+ DefaultTo<TError, CompatibleError>,
698
+ TContext
638
699
  >
639
700
 
701
+ export interface RouterConfig {
702
+ [k: string]:
703
+ | RouterQuery<any, any, any>
704
+ | RouterInfiniteQuery<any, any, any, any>
705
+ | RouterMutation<any, any, any, any>
706
+ | RouterConfig
707
+ }
708
+
640
709
  export type CreateRouter<TConfig extends RouterConfig> = {
641
710
  [K in keyof TConfig]: TConfig[K] extends RouterMutation<
642
711
  infer TFnData,
@@ -644,14 +713,7 @@ export type CreateRouter<TConfig extends RouterConfig> = {
644
713
  infer TError,
645
714
  infer TContext
646
715
  >
647
- ? {
648
- useMutation: MutationHook<
649
- TFnData,
650
- DefaultTo<TVariables, void>,
651
- DefaultTo<TError, CompatibleError>,
652
- TContext
653
- >
654
- } & ExposeMutationMethods<
716
+ ? ResolvedRouterMutation<
655
717
  TFnData,
656
718
  DefaultTo<TVariables, void>,
657
719
  DefaultTo<TError, CompatibleError>,
@@ -663,20 +725,7 @@ export type CreateRouter<TConfig extends RouterConfig> = {
663
725
  infer TError,
664
726
  infer TPageParam
665
727
  >
666
- ? {
667
- useInfiniteQuery: InfiniteQueryHook<
668
- TFnData,
669
- DefaultTo<TVariables, void>,
670
- DefaultTo<TError, CompatibleError>,
671
- DefaultTo<TPageParam, number>
672
- >
673
- useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<
674
- TFnData,
675
- DefaultTo<TVariables, void>,
676
- DefaultTo<TError, CompatibleError>,
677
- DefaultTo<TPageParam, number>
678
- >
679
- } & ExposeMethods<
728
+ ? ResolvedRouterInfiniteQuery<
680
729
  TFnData,
681
730
  DefaultTo<TVariables, void>,
682
731
  DefaultTo<TError, CompatibleError>,
@@ -686,21 +735,12 @@ export type CreateRouter<TConfig extends RouterConfig> = {
686
735
  RouterQuery<infer TFnData, infer TVariables, infer TError>,
687
736
  'queryKey'
688
737
  >
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<
738
+ ? ResolvedRouterQuery<
701
739
  TFnData,
702
740
  DefaultTo<TVariables, void>,
703
741
  DefaultTo<TError, CompatibleError>
704
742
  >
743
+ : TConfig[K] extends RouterConfig
744
+ ? CreateRouter<TConfig[K]>
705
745
  : never
706
- } & { getKey: () => [string] }
746
+ } & { getKey: () => string[] }
package/src/utils.ts CHANGED
@@ -11,7 +11,7 @@ export const suspenseOptions = {
11
11
  enabled: true,
12
12
  suspense: true,
13
13
  useErrorBoundary: (_error: unknown, query: Query) =>
14
- query.state.data === undefined,
14
+ typeof query.state.data === 'undefined',
15
15
  }
16
16
 
17
17
  export const withMiddleware = (
@@ -37,12 +37,12 @@ export const withMiddleware = (
37
37
  ],
38
38
  [[]]
39
39
  )
40
- const composed = uses.reduceRight((next, use) => use(next), hook)
40
+ const composedHook = uses.reduceRight((next, use) => use(next), hook)
41
41
 
42
- return composed(opts, queryClient)
42
+ return composedHook(opts, queryClient)
43
43
  }
44
44
  }
45
45
 
46
46
  export const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {
47
- return variables === undefined ? [...queryKey] : [...queryKey, variables]
47
+ return typeof variables === 'undefined' ? queryKey : [...queryKey, variables]
48
48
  }