react-query-kit 1.5.0 → 1.5.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.
package/README.md CHANGED
@@ -42,8 +42,8 @@ English | [简体中文](./README-zh_CN.md)
42
42
  - [createSuspenseQuery](#createsuspensequery)
43
43
  - [createSuspenseInfiniteQuery](#createsuspenseinfinitequery)
44
44
  - [createMutation](#createmutation)
45
+ - [Middleware](#middleware)
45
46
  - [Type inference](#type-inference)
46
- - [Caution](#caution)
47
47
  - [Issues](#issues)
48
48
  - [🐛 Bugs](#-bugs)
49
49
  - [💡 Feature Requests](#-feature-requests)
@@ -415,7 +415,9 @@ Returns
415
415
 
416
416
  ## Middleware
417
417
 
418
- The middleware feature is a new addition in SWR 1.0 that enables you to execute logic before and after SWR hooks.
418
+ This feature is inspired by the [Middleware feature from SWR](https://swr.vercel.app/docs/middleware). The middleware feature is a new addition in ReactQueryKit 1.5.0 that enables you to execute logic before and after hooks.
419
+
420
+ Middleware receive the hook and can execute logic before and after running it. If there are multiple middleware, each middleware wraps the next middleware. The last middleware in the list will receive the original hook.
419
421
 
420
422
  ### Usage
421
423
 
@@ -465,8 +467,6 @@ const queryClient = createQueryClient({
465
467
 
466
468
  ### Multiple Middleware
467
469
 
468
- This feature is inspired by the [Middleware feature from SWR](https://swr.vercel.app/docs/middleware).
469
-
470
470
  Each middleware wraps the next middleware, and the last one just wraps the useQuery. For example:
471
471
 
472
472
  ```jsx
@@ -19,10 +19,6 @@ const withMiddlewares = (hook, defaultOptions, type) => {
19
19
  const middleware = configUse.concat(use);
20
20
 
21
21
  for (let i = middleware.length; i--;) {
22
- if (middleware[i] === undefined) {
23
- console.log(middleware[i], middleware);
24
- }
25
-
26
22
  next = middleware[i](next);
27
23
  }
28
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n if (middleware[i] === undefined) {\n console.log(middleware[i], middleware)\n }\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","undefined","console","log","getQueryKey","primaryKey","variables"],"mappings":";;MAIaA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,cAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;EAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,CAAnB,GAAkDF,WAAnD,EALT;AAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;EACH,MAAM;AAAEC,IAAAA,GAAG,GAAG,EAAR;IAAY,GAAGC,WAAAA;AAAf,GAAA,GAA+BH,cAArC,CAAA;AAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,OAAD,EAAUC,WAAV,CAAtC,CAAA;IAEA,IAAIW,IAAI,GAAGP,IAAX,CAAA;IAEA,MAAM;MAAEG,GAAG,EAAEK,SAAS,GAAG,EAAnB;MAAuB,GAAGC,aAAAA;AAA1B,KAAA,GACHH,MAAM,CAACI,iBAAP,GAA2BR,IAA3B,CAAD,IAA6C,EAD/C,CAAA;AAGA,IAAA,MAAMS,UAAwB,GAAGH,SAAS,CAACI,MAAV,CAAiBT,GAAjB,CAAjC,CAAA;;IAEA,KAAK,IAAIU,CAAC,GAAGF,UAAU,CAACG,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrC,MAAA,IAAIF,UAAU,CAACE,CAAD,CAAV,KAAkBE,SAAtB,EAAiC;QAC/BC,OAAO,CAACC,GAAR,CAAYN,UAAU,CAACE,CAAD,CAAtB,EAA2BF,UAA3B,CAAA,CAAA;AACD,OAAA;;AACDJ,MAAAA,IAAI,GAAGI,UAAU,CAACE,CAAD,CAAV,CAAeN,IAAf,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAAC,EAAE,GAAGE,aAAL;AAAoB,MAAA,GAAGL,WAAvB;MAAoC,GAAGT,OAAAA;KAAxC,EAAmDC,WAAnD,CAAX,CAAA;GApBF,CAAA;AAsBD,EA7BM;MA+BMsB,WAAW,GAAG,CACzBC,UADyB,EAEzBC,SAFyB,KAGtB;AACH,EAAA,OAAOA,SAAS,KAAKL,SAAd,GAA0B,CAACI,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAAhD,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","getQueryKey","primaryKey","variables","undefined"],"mappings":";;MAIaA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,cAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;EAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,CAAnB,GAAkDF,WAAnD,EALT;AAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;EACH,MAAM;AAAEC,IAAAA,GAAG,GAAG,EAAR;IAAY,GAAGC,WAAAA;AAAf,GAAA,GAA+BH,cAArC,CAAA;AAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,OAAD,EAAUC,WAAV,CAAtC,CAAA;IAEA,IAAIW,IAAI,GAAGP,IAAX,CAAA;IAEA,MAAM;MAAEG,GAAG,EAAEK,SAAS,GAAG,EAAnB;MAAuB,GAAGC,aAAAA;AAA1B,KAAA,GACHH,MAAM,CAACI,iBAAP,GAA2BR,IAA3B,CAAD,IAA6C,EAD/C,CAAA;AAGA,IAAA,MAAMS,UAAwB,GAAGH,SAAS,CAACI,MAAV,CAAiBT,GAAjB,CAAjC,CAAA;;IAEA,KAAK,IAAIU,CAAC,GAAGF,UAAU,CAACG,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrCN,MAAAA,IAAI,GAAGI,UAAU,CAACE,CAAD,CAAV,CAAeN,IAAf,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAAC,EAAE,GAAGE,aAAL;AAAoB,MAAA,GAAGL,WAAvB;MAAoC,GAAGT,OAAAA;KAAxC,EAAmDC,WAAnD,CAAX,CAAA;GAjBF,CAAA;AAmBD,EA1BM;MA4BMmB,WAAW,GAAG,CACzBC,UADyB,EAEzBC,SAFyB,KAGtB;AACH,EAAA,OAAOA,SAAS,KAAKC,SAAd,GAA0B,CAACF,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAAhD,CAAA;AACD;;;;"}
@@ -23,10 +23,6 @@ const withMiddlewares = (hook, defaultOptions, type) => {
23
23
  const middleware = configUse.concat(use);
24
24
 
25
25
  for (let i = middleware.length; i--;) {
26
- if (middleware[i] === undefined) {
27
- console.log(middleware[i], middleware);
28
- }
29
-
30
26
  next = middleware[i](next);
31
27
  }
32
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n if (middleware[i] === undefined) {\n console.log(middleware[i], middleware)\n }\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","undefined","console","log","getQueryKey","primaryKey","variables"],"mappings":";;;;;;MAIaA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,yBAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;EAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,CAAnB,GAAkDF,WAAnD,EALT;AAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;EACH,MAAM;AAAEC,IAAAA,GAAG,GAAG,EAAR;IAAY,GAAGC,WAAAA;AAAf,GAAA,GAA+BH,cAArC,CAAA;AAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,OAAD,EAAUC,WAAV,CAAtC,CAAA;IAEA,IAAIW,IAAI,GAAGP,IAAX,CAAA;IAEA,MAAM;MAAEG,GAAG,EAAEK,SAAS,GAAG,EAAnB;MAAuB,GAAGC,aAAAA;AAA1B,KAAA,GACHH,MAAM,CAACI,iBAAP,GAA2BR,IAA3B,CAAD,IAA6C,EAD/C,CAAA;AAGA,IAAA,MAAMS,UAAwB,GAAGH,SAAS,CAACI,MAAV,CAAiBT,GAAjB,CAAjC,CAAA;;IAEA,KAAK,IAAIU,CAAC,GAAGF,UAAU,CAACG,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrC,MAAA,IAAIF,UAAU,CAACE,CAAD,CAAV,KAAkBE,SAAtB,EAAiC;QAC/BC,OAAO,CAACC,GAAR,CAAYN,UAAU,CAACE,CAAD,CAAtB,EAA2BF,UAA3B,CAAA,CAAA;AACD,OAAA;;AACDJ,MAAAA,IAAI,GAAGI,UAAU,CAACE,CAAD,CAAV,CAAeN,IAAf,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAAC,EAAE,GAAGE,aAAL;AAAoB,MAAA,GAAGL,WAAvB;MAAoC,GAAGT,OAAAA;KAAxC,EAAmDC,WAAnD,CAAX,CAAA;GApBF,CAAA;AAsBD,EA7BM;MA+BMsB,WAAW,GAAG,CACzBC,UADyB,EAEzBC,SAFyB,KAGtB;AACH,EAAA,OAAOA,SAAS,KAAKL,SAAd,GAA0B,CAACI,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAAhD,CAAA;AACD;;;;;;"}
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","getQueryKey","primaryKey","variables","undefined"],"mappings":";;;;;;MAIaA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,yBAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;EAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,CAAnB,GAAkDF,WAAnD,EALT;AAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;EACH,MAAM;AAAEC,IAAAA,GAAG,GAAG,EAAR;IAAY,GAAGC,WAAAA;AAAf,GAAA,GAA+BH,cAArC,CAAA;AAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,OAAD,EAAUC,WAAV,CAAtC,CAAA;IAEA,IAAIW,IAAI,GAAGP,IAAX,CAAA;IAEA,MAAM;MAAEG,GAAG,EAAEK,SAAS,GAAG,EAAnB;MAAuB,GAAGC,aAAAA;AAA1B,KAAA,GACHH,MAAM,CAACI,iBAAP,GAA2BR,IAA3B,CAAD,IAA6C,EAD/C,CAAA;AAGA,IAAA,MAAMS,UAAwB,GAAGH,SAAS,CAACI,MAAV,CAAiBT,GAAjB,CAAjC,CAAA;;IAEA,KAAK,IAAIU,CAAC,GAAGF,UAAU,CAACG,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrCN,MAAAA,IAAI,GAAGI,UAAU,CAACE,CAAD,CAAV,CAAeN,IAAf,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAAC,EAAE,GAAGE,aAAL;AAAoB,MAAA,GAAGL,WAAvB;MAAoC,GAAGT,OAAAA;KAAxC,EAAmDC,WAAnD,CAAX,CAAA;GAjBF,CAAA;AAmBD,EA1BM;MA4BMmB,WAAW,GAAG,CACzBC,UADyB,EAEzBC,SAFyB,KAGtB;AACH,EAAA,OAAOA,SAAS,KAAKC,SAAd,GAA0B,CAACF,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAAhD,CAAA;AACD;;;;;;"}
@@ -19,10 +19,6 @@ const withMiddlewares = (hook, defaultOptions, type) => {
19
19
  const middleware = configUse.concat(use);
20
20
 
21
21
  for (let i = middleware.length; i--;) {
22
- if (middleware[i] === undefined) {
23
- console.log(middleware[i], middleware);
24
- }
25
-
26
22
  next = middleware[i](next);
27
23
  }
28
24
 
@@ -1 +1 @@
1
- {"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n if (middleware[i] === undefined) {\n console.log(middleware[i], middleware)\n }\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","undefined","console","log","getQueryKey","primaryKey","variables"],"mappings":";;MAIaA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,cAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;EAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,CAAnB,GAAkDF,WAAnD,EALT;AAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;EACH,MAAM;AAAEC,IAAAA,GAAG,GAAG,EAAR;IAAY,GAAGC,WAAAA;AAAf,GAAA,GAA+BH,cAArC,CAAA;AAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,OAAD,EAAUC,WAAV,CAAtC,CAAA;IAEA,IAAIW,IAAI,GAAGP,IAAX,CAAA;IAEA,MAAM;MAAEG,GAAG,EAAEK,SAAS,GAAG,EAAnB;MAAuB,GAAGC,aAAAA;AAA1B,KAAA,GACHH,MAAM,CAACI,iBAAP,GAA2BR,IAA3B,CAAD,IAA6C,EAD/C,CAAA;AAGA,IAAA,MAAMS,UAAwB,GAAGH,SAAS,CAACI,MAAV,CAAiBT,GAAjB,CAAjC,CAAA;;IAEA,KAAK,IAAIU,CAAC,GAAGF,UAAU,CAACG,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrC,MAAA,IAAIF,UAAU,CAACE,CAAD,CAAV,KAAkBE,SAAtB,EAAiC;QAC/BC,OAAO,CAACC,GAAR,CAAYN,UAAU,CAACE,CAAD,CAAtB,EAA2BF,UAA3B,CAAA,CAAA;AACD,OAAA;;AACDJ,MAAAA,IAAI,GAAGI,UAAU,CAACE,CAAD,CAAV,CAAeN,IAAf,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAAC,EAAE,GAAGE,aAAL;AAAoB,MAAA,GAAGL,WAAvB;MAAoC,GAAGT,OAAAA;KAAxC,EAAmDC,WAAnD,CAAX,CAAA;GApBF,CAAA;AAsBD,EA7BM;MA+BMsB,WAAW,GAAG,CACzBC,UADyB,EAEzBC,SAFyB,KAGtB;AACH,EAAA,OAAOA,SAAS,KAAKL,SAAd,GAA0B,CAACI,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAAhD,CAAA;AACD;;;;"}
1
+ {"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","getQueryKey","primaryKey","variables","undefined"],"mappings":";;MAIaA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,cAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;EAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;AAAnB,CAAnB,GAAkDF,WAAnD,EALT;AAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;EACH,MAAM;AAAEC,IAAAA,GAAG,GAAG,EAAR;IAAY,GAAGC,WAAAA;AAAf,GAAA,GAA+BH,cAArC,CAAA;AAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,OAAD,EAAUC,WAAV,CAAtC,CAAA;IAEA,IAAIW,IAAI,GAAGP,IAAX,CAAA;IAEA,MAAM;MAAEG,GAAG,EAAEK,SAAS,GAAG,EAAnB;MAAuB,GAAGC,aAAAA;AAA1B,KAAA,GACHH,MAAM,CAACI,iBAAP,GAA2BR,IAA3B,CAAD,IAA6C,EAD/C,CAAA;AAGA,IAAA,MAAMS,UAAwB,GAAGH,SAAS,CAACI,MAAV,CAAiBT,GAAjB,CAAjC,CAAA;;IAEA,KAAK,IAAIU,CAAC,GAAGF,UAAU,CAACG,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrCN,MAAAA,IAAI,GAAGI,UAAU,CAACE,CAAD,CAAV,CAAeN,IAAf,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAAC,EAAE,GAAGE,aAAL;AAAoB,MAAA,GAAGL,WAAvB;MAAoC,GAAGT,OAAAA;KAAxC,EAAmDC,WAAnD,CAAX,CAAA;GAjBF,CAAA;AAmBD,EA1BM;MA4BMmB,WAAW,GAAG,CACzBC,UADyB,EAEzBC,SAFyB,KAGtB;AACH,EAAA,OAAOA,SAAS,KAAKC,SAAd,GAA0B,CAACF,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAAhD,CAAA;AACD;;;;"}
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
4014
4014
  </script>
4015
4015
  <script>
4016
4016
  /*<!--*/
4017
- const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"src","children":[{"uid":"349d-1","name":"utils.ts"},{"uid":"349d-3","name":"createBaseQuery.ts"},{"uid":"349d-5","name":"createQuery.tsx"},{"uid":"349d-7","name":"createImmutableQuery.tsx"},{"uid":"349d-9","name":"createSuspenseQuery.ts"},{"uid":"349d-11","name":"createInfiniteQuery.ts"},{"uid":"349d-13","name":"createSuspenseInfiniteQuery.ts"},{"uid":"349d-15","name":"createMutation.ts"},{"uid":"349d-17","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"349d-1":{"renderedLength":1082,"gzipLength":441,"brotliLength":0,"mainUid":"349d-0"},"349d-3":{"renderedLength":1585,"gzipLength":512,"brotliLength":0,"mainUid":"349d-2"},"349d-5":{"renderedLength":95,"gzipLength":83,"brotliLength":0,"mainUid":"349d-4"},"349d-7":{"renderedLength":376,"gzipLength":204,"brotliLength":0,"mainUid":"349d-6"},"349d-9":{"renderedLength":269,"gzipLength":174,"brotliLength":0,"mainUid":"349d-8"},"349d-11":{"renderedLength":111,"gzipLength":92,"brotliLength":0,"mainUid":"349d-10"},"349d-13":{"renderedLength":285,"gzipLength":181,"brotliLength":0,"mainUid":"349d-12"},"349d-15":{"renderedLength":264,"gzipLength":174,"brotliLength":0,"mainUid":"349d-14"},"349d-17":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"349d-16"}},"nodeMetas":{"349d-0":{"id":"/src/utils.ts","moduleParts":{"index.production.js":"349d-1"},"imported":[{"uid":"349d-18"}],"importedBy":[{"uid":"349d-16"},{"uid":"349d-14"},{"uid":"349d-2"}]},"349d-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"index.production.js":"349d-3"},"imported":[{"uid":"349d-0"}],"importedBy":[{"uid":"349d-4"},{"uid":"349d-6"},{"uid":"349d-8"},{"uid":"349d-10"},{"uid":"349d-12"}]},"349d-4":{"id":"/src/createQuery.tsx","moduleParts":{"index.production.js":"349d-5"},"imported":[{"uid":"349d-18"},{"uid":"349d-2"}],"importedBy":[{"uid":"349d-16"}]},"349d-6":{"id":"/src/createImmutableQuery.tsx","moduleParts":{"index.production.js":"349d-7"},"imported":[{"uid":"349d-18"},{"uid":"349d-2"}],"importedBy":[{"uid":"349d-16"}]},"349d-8":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"index.production.js":"349d-9"},"imported":[{"uid":"349d-18"},{"uid":"349d-2"}],"importedBy":[{"uid":"349d-16"}]},"349d-10":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"index.production.js":"349d-11"},"imported":[{"uid":"349d-18"},{"uid":"349d-2"}],"importedBy":[{"uid":"349d-16"}]},"349d-12":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"index.production.js":"349d-13"},"imported":[{"uid":"349d-18"},{"uid":"349d-2"}],"importedBy":[{"uid":"349d-16"}]},"349d-14":{"id":"/src/createMutation.ts","moduleParts":{"index.production.js":"349d-15"},"imported":[{"uid":"349d-18"},{"uid":"349d-0"}],"importedBy":[{"uid":"349d-16"}]},"349d-16":{"id":"/src/index.ts","moduleParts":{"index.production.js":"349d-17"},"imported":[{"uid":"349d-4"},{"uid":"349d-6"},{"uid":"349d-8"},{"uid":"349d-10"},{"uid":"349d-12"},{"uid":"349d-14"},{"uid":"349d-0"}],"importedBy":[],"isEntry":true},"349d-18":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"349d-4"},{"uid":"349d-6"},{"uid":"349d-8"},{"uid":"349d-10"},{"uid":"349d-12"},{"uid":"349d-14"},{"uid":"349d-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4017
+ const data = {"version":2,"tree":{"name":"root","children":[{"name":"index.production.js","children":[{"name":"src","children":[{"uid":"d114-1","name":"utils.ts"},{"uid":"d114-3","name":"createBaseQuery.ts"},{"uid":"d114-5","name":"createQuery.tsx"},{"uid":"d114-7","name":"createImmutableQuery.tsx"},{"uid":"d114-9","name":"createSuspenseQuery.ts"},{"uid":"d114-11","name":"createInfiniteQuery.ts"},{"uid":"d114-13","name":"createSuspenseInfiniteQuery.ts"},{"uid":"d114-15","name":"createMutation.ts"},{"uid":"d114-17","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"d114-1":{"renderedLength":978,"gzipLength":414,"brotliLength":0,"mainUid":"d114-0"},"d114-3":{"renderedLength":1585,"gzipLength":512,"brotliLength":0,"mainUid":"d114-2"},"d114-5":{"renderedLength":95,"gzipLength":83,"brotliLength":0,"mainUid":"d114-4"},"d114-7":{"renderedLength":376,"gzipLength":204,"brotliLength":0,"mainUid":"d114-6"},"d114-9":{"renderedLength":269,"gzipLength":174,"brotliLength":0,"mainUid":"d114-8"},"d114-11":{"renderedLength":111,"gzipLength":92,"brotliLength":0,"mainUid":"d114-10"},"d114-13":{"renderedLength":285,"gzipLength":181,"brotliLength":0,"mainUid":"d114-12"},"d114-15":{"renderedLength":264,"gzipLength":174,"brotliLength":0,"mainUid":"d114-14"},"d114-17":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"d114-16"}},"nodeMetas":{"d114-0":{"id":"/src/utils.ts","moduleParts":{"index.production.js":"d114-1"},"imported":[{"uid":"d114-18"}],"importedBy":[{"uid":"d114-16"},{"uid":"d114-14"},{"uid":"d114-2"}]},"d114-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"index.production.js":"d114-3"},"imported":[{"uid":"d114-0"}],"importedBy":[{"uid":"d114-4"},{"uid":"d114-6"},{"uid":"d114-8"},{"uid":"d114-10"},{"uid":"d114-12"}]},"d114-4":{"id":"/src/createQuery.tsx","moduleParts":{"index.production.js":"d114-5"},"imported":[{"uid":"d114-18"},{"uid":"d114-2"}],"importedBy":[{"uid":"d114-16"}]},"d114-6":{"id":"/src/createImmutableQuery.tsx","moduleParts":{"index.production.js":"d114-7"},"imported":[{"uid":"d114-18"},{"uid":"d114-2"}],"importedBy":[{"uid":"d114-16"}]},"d114-8":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"index.production.js":"d114-9"},"imported":[{"uid":"d114-18"},{"uid":"d114-2"}],"importedBy":[{"uid":"d114-16"}]},"d114-10":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"index.production.js":"d114-11"},"imported":[{"uid":"d114-18"},{"uid":"d114-2"}],"importedBy":[{"uid":"d114-16"}]},"d114-12":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"index.production.js":"d114-13"},"imported":[{"uid":"d114-18"},{"uid":"d114-2"}],"importedBy":[{"uid":"d114-16"}]},"d114-14":{"id":"/src/createMutation.ts","moduleParts":{"index.production.js":"d114-15"},"imported":[{"uid":"d114-18"},{"uid":"d114-0"}],"importedBy":[{"uid":"d114-16"}]},"d114-16":{"id":"/src/index.ts","moduleParts":{"index.production.js":"d114-17"},"imported":[{"uid":"d114-4"},{"uid":"d114-6"},{"uid":"d114-8"},{"uid":"d114-10"},{"uid":"d114-12"},{"uid":"d114-14"},{"uid":"d114-0"}],"importedBy":[],"isEntry":true},"d114-18":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"d114-4"},{"uid":"d114-6"},{"uid":"d114-8"},{"uid":"d114-10"},{"uid":"d114-12"},{"uid":"d114-14"},{"uid":"d114-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
4018
4018
 
4019
4019
  const run = () => {
4020
4020
  const width = window.innerWidth;
package/build/stats.json CHANGED
@@ -10,39 +10,39 @@
10
10
  "name": "src",
11
11
  "children": [
12
12
  {
13
- "uid": "349d-20",
13
+ "uid": "d114-20",
14
14
  "name": "utils.ts"
15
15
  },
16
16
  {
17
- "uid": "349d-22",
17
+ "uid": "d114-22",
18
18
  "name": "createBaseQuery.ts"
19
19
  },
20
20
  {
21
- "uid": "349d-24",
21
+ "uid": "d114-24",
22
22
  "name": "createQuery.tsx"
23
23
  },
24
24
  {
25
- "uid": "349d-26",
25
+ "uid": "d114-26",
26
26
  "name": "createImmutableQuery.tsx"
27
27
  },
28
28
  {
29
- "uid": "349d-28",
29
+ "uid": "d114-28",
30
30
  "name": "createSuspenseQuery.ts"
31
31
  },
32
32
  {
33
- "uid": "349d-30",
33
+ "uid": "d114-30",
34
34
  "name": "createInfiniteQuery.ts"
35
35
  },
36
36
  {
37
- "uid": "349d-32",
37
+ "uid": "d114-32",
38
38
  "name": "createSuspenseInfiniteQuery.ts"
39
39
  },
40
40
  {
41
- "uid": "349d-34",
41
+ "uid": "d114-34",
42
42
  "name": "createMutation.ts"
43
43
  },
44
44
  {
45
- "uid": "349d-36",
45
+ "uid": "d114-36",
46
46
  "name": "index.ts"
47
47
  }
48
48
  ]
@@ -53,282 +53,282 @@
53
53
  "isRoot": true
54
54
  },
55
55
  "nodeParts": {
56
- "349d-20": {
57
- "renderedLength": 1082,
58
- "gzipLength": 441,
56
+ "d114-20": {
57
+ "renderedLength": 978,
58
+ "gzipLength": 414,
59
59
  "brotliLength": 0,
60
- "mainUid": "349d-19"
60
+ "mainUid": "d114-19"
61
61
  },
62
- "349d-22": {
62
+ "d114-22": {
63
63
  "renderedLength": 1585,
64
64
  "gzipLength": 512,
65
65
  "brotliLength": 0,
66
- "mainUid": "349d-21"
66
+ "mainUid": "d114-21"
67
67
  },
68
- "349d-24": {
68
+ "d114-24": {
69
69
  "renderedLength": 95,
70
70
  "gzipLength": 83,
71
71
  "brotliLength": 0,
72
- "mainUid": "349d-23"
72
+ "mainUid": "d114-23"
73
73
  },
74
- "349d-26": {
74
+ "d114-26": {
75
75
  "renderedLength": 376,
76
76
  "gzipLength": 204,
77
77
  "brotliLength": 0,
78
- "mainUid": "349d-25"
78
+ "mainUid": "d114-25"
79
79
  },
80
- "349d-28": {
80
+ "d114-28": {
81
81
  "renderedLength": 269,
82
82
  "gzipLength": 174,
83
83
  "brotliLength": 0,
84
- "mainUid": "349d-27"
84
+ "mainUid": "d114-27"
85
85
  },
86
- "349d-30": {
86
+ "d114-30": {
87
87
  "renderedLength": 111,
88
88
  "gzipLength": 92,
89
89
  "brotliLength": 0,
90
- "mainUid": "349d-29"
90
+ "mainUid": "d114-29"
91
91
  },
92
- "349d-32": {
92
+ "d114-32": {
93
93
  "renderedLength": 285,
94
94
  "gzipLength": 181,
95
95
  "brotliLength": 0,
96
- "mainUid": "349d-31"
96
+ "mainUid": "d114-31"
97
97
  },
98
- "349d-34": {
98
+ "d114-34": {
99
99
  "renderedLength": 264,
100
100
  "gzipLength": 174,
101
101
  "brotliLength": 0,
102
- "mainUid": "349d-33"
102
+ "mainUid": "d114-33"
103
103
  },
104
- "349d-36": {
104
+ "d114-36": {
105
105
  "renderedLength": 0,
106
106
  "gzipLength": 0,
107
107
  "brotliLength": 0,
108
- "mainUid": "349d-35"
108
+ "mainUid": "d114-35"
109
109
  }
110
110
  },
111
111
  "nodeMetas": {
112
- "349d-19": {
112
+ "d114-19": {
113
113
  "id": "/src/utils.ts",
114
114
  "moduleParts": {
115
- "index.production.js": "349d-20"
115
+ "index.production.js": "d114-20"
116
116
  },
117
117
  "imported": [
118
118
  {
119
- "uid": "349d-37"
119
+ "uid": "d114-37"
120
120
  }
121
121
  ],
122
122
  "importedBy": [
123
123
  {
124
- "uid": "349d-35"
124
+ "uid": "d114-35"
125
125
  },
126
126
  {
127
- "uid": "349d-33"
127
+ "uid": "d114-33"
128
128
  },
129
129
  {
130
- "uid": "349d-21"
130
+ "uid": "d114-21"
131
131
  }
132
132
  ]
133
133
  },
134
- "349d-21": {
134
+ "d114-21": {
135
135
  "id": "/src/createBaseQuery.ts",
136
136
  "moduleParts": {
137
- "index.production.js": "349d-22"
137
+ "index.production.js": "d114-22"
138
138
  },
139
139
  "imported": [
140
140
  {
141
- "uid": "349d-19"
141
+ "uid": "d114-19"
142
142
  }
143
143
  ],
144
144
  "importedBy": [
145
145
  {
146
- "uid": "349d-23"
146
+ "uid": "d114-23"
147
147
  },
148
148
  {
149
- "uid": "349d-25"
149
+ "uid": "d114-25"
150
150
  },
151
151
  {
152
- "uid": "349d-27"
152
+ "uid": "d114-27"
153
153
  },
154
154
  {
155
- "uid": "349d-29"
155
+ "uid": "d114-29"
156
156
  },
157
157
  {
158
- "uid": "349d-31"
158
+ "uid": "d114-31"
159
159
  }
160
160
  ]
161
161
  },
162
- "349d-23": {
162
+ "d114-23": {
163
163
  "id": "/src/createQuery.tsx",
164
164
  "moduleParts": {
165
- "index.production.js": "349d-24"
165
+ "index.production.js": "d114-24"
166
166
  },
167
167
  "imported": [
168
168
  {
169
- "uid": "349d-37"
169
+ "uid": "d114-37"
170
170
  },
171
171
  {
172
- "uid": "349d-21"
172
+ "uid": "d114-21"
173
173
  }
174
174
  ],
175
175
  "importedBy": [
176
176
  {
177
- "uid": "349d-35"
177
+ "uid": "d114-35"
178
178
  }
179
179
  ]
180
180
  },
181
- "349d-25": {
181
+ "d114-25": {
182
182
  "id": "/src/createImmutableQuery.tsx",
183
183
  "moduleParts": {
184
- "index.production.js": "349d-26"
184
+ "index.production.js": "d114-26"
185
185
  },
186
186
  "imported": [
187
187
  {
188
- "uid": "349d-37"
188
+ "uid": "d114-37"
189
189
  },
190
190
  {
191
- "uid": "349d-21"
191
+ "uid": "d114-21"
192
192
  }
193
193
  ],
194
194
  "importedBy": [
195
195
  {
196
- "uid": "349d-35"
196
+ "uid": "d114-35"
197
197
  }
198
198
  ]
199
199
  },
200
- "349d-27": {
200
+ "d114-27": {
201
201
  "id": "/src/createSuspenseQuery.ts",
202
202
  "moduleParts": {
203
- "index.production.js": "349d-28"
203
+ "index.production.js": "d114-28"
204
204
  },
205
205
  "imported": [
206
206
  {
207
- "uid": "349d-37"
207
+ "uid": "d114-37"
208
208
  },
209
209
  {
210
- "uid": "349d-21"
210
+ "uid": "d114-21"
211
211
  }
212
212
  ],
213
213
  "importedBy": [
214
214
  {
215
- "uid": "349d-35"
215
+ "uid": "d114-35"
216
216
  }
217
217
  ]
218
218
  },
219
- "349d-29": {
219
+ "d114-29": {
220
220
  "id": "/src/createInfiniteQuery.ts",
221
221
  "moduleParts": {
222
- "index.production.js": "349d-30"
222
+ "index.production.js": "d114-30"
223
223
  },
224
224
  "imported": [
225
225
  {
226
- "uid": "349d-37"
226
+ "uid": "d114-37"
227
227
  },
228
228
  {
229
- "uid": "349d-21"
229
+ "uid": "d114-21"
230
230
  }
231
231
  ],
232
232
  "importedBy": [
233
233
  {
234
- "uid": "349d-35"
234
+ "uid": "d114-35"
235
235
  }
236
236
  ]
237
237
  },
238
- "349d-31": {
238
+ "d114-31": {
239
239
  "id": "/src/createSuspenseInfiniteQuery.ts",
240
240
  "moduleParts": {
241
- "index.production.js": "349d-32"
241
+ "index.production.js": "d114-32"
242
242
  },
243
243
  "imported": [
244
244
  {
245
- "uid": "349d-37"
245
+ "uid": "d114-37"
246
246
  },
247
247
  {
248
- "uid": "349d-21"
248
+ "uid": "d114-21"
249
249
  }
250
250
  ],
251
251
  "importedBy": [
252
252
  {
253
- "uid": "349d-35"
253
+ "uid": "d114-35"
254
254
  }
255
255
  ]
256
256
  },
257
- "349d-33": {
257
+ "d114-33": {
258
258
  "id": "/src/createMutation.ts",
259
259
  "moduleParts": {
260
- "index.production.js": "349d-34"
260
+ "index.production.js": "d114-34"
261
261
  },
262
262
  "imported": [
263
263
  {
264
- "uid": "349d-37"
264
+ "uid": "d114-37"
265
265
  },
266
266
  {
267
- "uid": "349d-19"
267
+ "uid": "d114-19"
268
268
  }
269
269
  ],
270
270
  "importedBy": [
271
271
  {
272
- "uid": "349d-35"
272
+ "uid": "d114-35"
273
273
  }
274
274
  ]
275
275
  },
276
- "349d-35": {
276
+ "d114-35": {
277
277
  "id": "/src/index.ts",
278
278
  "moduleParts": {
279
- "index.production.js": "349d-36"
279
+ "index.production.js": "d114-36"
280
280
  },
281
281
  "imported": [
282
282
  {
283
- "uid": "349d-23"
283
+ "uid": "d114-23"
284
284
  },
285
285
  {
286
- "uid": "349d-25"
286
+ "uid": "d114-25"
287
287
  },
288
288
  {
289
- "uid": "349d-27"
289
+ "uid": "d114-27"
290
290
  },
291
291
  {
292
- "uid": "349d-29"
292
+ "uid": "d114-29"
293
293
  },
294
294
  {
295
- "uid": "349d-31"
295
+ "uid": "d114-31"
296
296
  },
297
297
  {
298
- "uid": "349d-33"
298
+ "uid": "d114-33"
299
299
  },
300
300
  {
301
- "uid": "349d-19"
301
+ "uid": "d114-19"
302
302
  }
303
303
  ],
304
304
  "importedBy": [],
305
305
  "isEntry": true
306
306
  },
307
- "349d-37": {
307
+ "d114-37": {
308
308
  "id": "@tanstack/react-query",
309
309
  "moduleParts": {},
310
310
  "imported": [],
311
311
  "importedBy": [
312
312
  {
313
- "uid": "349d-23"
313
+ "uid": "d114-23"
314
314
  },
315
315
  {
316
- "uid": "349d-25"
316
+ "uid": "d114-25"
317
317
  },
318
318
  {
319
- "uid": "349d-27"
319
+ "uid": "d114-27"
320
320
  },
321
321
  {
322
- "uid": "349d-29"
322
+ "uid": "d114-29"
323
323
  },
324
324
  {
325
- "uid": "349d-31"
325
+ "uid": "d114-31"
326
326
  },
327
327
  {
328
- "uid": "349d-33"
328
+ "uid": "d114-33"
329
329
  },
330
330
  {
331
- "uid": "349d-19"
331
+ "uid": "d114-19"
332
332
  }
333
333
  ],
334
334
  "isExternal": true
@@ -23,10 +23,6 @@
23
23
  const middleware = configUse.concat(use);
24
24
 
25
25
  for (let i = middleware.length; i--;) {
26
- if (middleware[i] === undefined) {
27
- console.log(middleware[i], middleware);
28
- }
29
-
30
26
  next = middleware[i](next);
31
27
  }
32
28
 
@@ -1 +1 @@
1
- {"version":3,"file":"index.development.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.tsx","../../src/createImmutableQuery.tsx","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n if (middleware[i] === undefined) {\n console.log(middleware[i], middleware)\n }\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n","import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n Middleware,\n QueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {\n use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createQuery<TFnData, TVariables = any, TError = DefaultError>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery)\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n ImmutableQueryHook,\n Middleware,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<ImmutableQueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, TError>\n): ImmutableQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n","import type { DefaultError, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n Middleware,\n SuspenseQueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateSuspenseQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n Middleware,\n} from './types'\n\nexport interface CreateInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables, TPageParam> {\n use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]\n}\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery)\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n Middleware,\n SuspenseInfiniteQueryHook,\n} from './types'\n\nexport interface CreateSuspenseInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables, TPageParam>, 'enabled'> {\n use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n","import { useMutation } from '@tanstack/react-query'\nimport type { UseMutationOptions } from '@tanstack/react-query'\n\nimport type { DefaultError, Middleware, MutationHook } from './types'\nimport { withMiddlewares } from './utils'\n\nexport interface CreateMutationOptions<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n> extends UseMutationOptions<TData, TError, TVariables, TContext> {\n use?: Middleware<MutationHook<TData, TError, TVariables>>[]\n}\n\nexport function createMutation<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddlewares(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","undefined","console","log","getQueryKey","primaryKey","variables","createBaseQuery","useRQHook","overrideOptions","useDefaultOptions","Error","getPrimaryKey","getKey","getFetchOptions","queryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","useGeneratedQuery","enabled","mergedOptions","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData","createQuery","useQuery","createImmutableQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime","createSuspenseQuery","suspense","throwOnError","useErrorBoundary","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","createMutation","mutationKey","useMutation","mutationFn"],"mappings":";;;;;;EAIO,MAAMA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,2BAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,O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C,IAAAA,MAAM,EAAED,QANgC;EAOxC;EACA;EACAE,IAAAA,SAAS,EAAEF,QAAAA;EAT6B,GAApB,CAAtB,CAAA;EAWD;;ECtBM,SAASG,mBAAT,CAKL9D,OALK,EAM2C;EAChD,EAAA,OAAO0B,eAAe,CAAC1B,OAAD,EAAUoD,mBAAV,EAAoB;EACxCX,IAAAA,OAAO,EAAE,IAD+B;EAExCsB,IAAAA,QAAQ,EAAE,IAF8B;EAGxCC,IAAAA,YAAY,EAAE,IAH0B;EAIxC;EACA;EACAC,IAAAA,gBAAgB,EAAE,IAAA;EANsB,GAApB,CAAtB,CAAA;EAQD;;EChBM,SAASC,mBAAT,CAMLlE,OANK,EAOuD;EAC5D,EAAA,OAAO0B,eAAe,CAAC1B,OAAD,EAAUmE,2BAAV,CAAtB,CAAA;EACD;;ECDM,SAASC,2BAAT,CAMLpE,OANK,EAY+D;EACpE,EAAA,OAAO0B,eAAe,CAAC1B,OAAD,EAAUmE,2BAAV,EAA4B;EAChD1B,IAAAA,OAAO,EAAE,IADuC;EAEhDsB,IAAAA,QAAQ,EAAE,IAFsC;EAGhDC,IAAAA,YAAY,EAAE,IAHkC;EAIhD;EACA;EACAC,IAAAA,gBAAgB,EAAE,IAAA;EAN8B,GAA5B,CAAtB,CAAA;EAQD;;EC5CM,SAASI,cAAT,CAML/D,cANK,EAOoC;EACzC,EAAA,MAAM0B,MAAM,GAAG,MAAM1B,cAAc,CAACgE,WAApC,CAAA;;EAEA,EAAA,OAAOzB,MAAM,CAACC,MAAP,CACL1C,eAAe,CAACmE,sBAAD,EAAcjE,cAAd,EAA8B,WAA9B,CADV,EAEL;MACE0B,MADF;MAEEwC,UAAU,EAAElE,cAAc,CAACkE,UAAAA;EAF7B,GAFK,CAAP,CAAA;EAOD;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.development.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.tsx","../../src/createImmutableQuery.tsx","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n","import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n Middleware,\n QueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {\n use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createQuery<TFnData, TVariables = any, TError = DefaultError>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery)\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n ImmutableQueryHook,\n Middleware,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<ImmutableQueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, TError>\n): ImmutableQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n","import type { DefaultError, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n Middleware,\n SuspenseQueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateSuspenseQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n Middleware,\n} from './types'\n\nexport interface CreateInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables, TPageParam> {\n use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]\n}\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery)\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n Middleware,\n SuspenseInfiniteQueryHook,\n} from './types'\n\nexport interface CreateSuspenseInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables, TPageParam>, 'enabled'> {\n use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n","import { useMutation } from '@tanstack/react-query'\nimport type { UseMutationOptions } from '@tanstack/react-query'\n\nimport type { DefaultError, Middleware, MutationHook } from './types'\nimport { withMiddlewares } from './utils'\n\nexport interface CreateMutationOptions<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n> extends UseMutationOptions<TData, TError, TVariables, TContext> {\n use?: Middleware<MutationHook<TData, TError, TVariables>>[]\n}\n\nexport function createMutation<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddlewares(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","useMiddleware","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","getQueryKey","primaryKey","variables","undefined","createBaseQuery","useRQHook","overrideOptions","useDefaultOptions","Error","getPrimaryKey","getKey","getFetchOptions","queryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","useGeneratedQuery","enabled","mergedOptions","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData","createQuery","useQuery","createImmutableQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime","createSuspenseQuery","suspense","throwOnError","useErrorBoundary","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","createMutation","mutationKey","useMutation","mutationFn"],"mappings":";;;;;;EAIO,MAAMA,uBAAuB,GAAG,CACrCC,OADqC,EAErCC,WAFqC;AAKrCC,2BAAc,CAACF,OAAO,IAAA,IAAP,IAAAA,OAAO,CAAEG,OAAT,GAAmB;IAAEA,OAAO,EAAEH,OAAO,CAACG,OAAAA;EAAnB,CAAnB,GAAkDF,WAAnD,CALT,CAAA;EAOA,MAAMG,eAAe,GAAG,CAC7BC,IAD6B,EAE7BC,cAF6B,EAG7BC,IAH6B,KAI1B;IACH,MAAM;EAAEC,IAAAA,GAAG,GAAG,EAAR;MAAY,GAAGC,WAAAA;EAAf,GAAA,GAA+BH,cAArC,CAAA;EAEA,EAAA,OAAO,SAASI,aAAT,CACLV,OADK,EAELC,WAFK,EAGL;EACA,IAAA,MAAMU,MAAM,GAAGZ,uBAAuB,CAACC,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Y+D;EACpE,EAAA,OAAOwB,eAAe,CAACxB,OAAD,EAAUiE,2BAAV,EAA4B;EAChD1B,IAAAA,OAAO,EAAE,IADuC;EAEhDsB,IAAAA,QAAQ,EAAE,IAFsC;EAGhDC,IAAAA,YAAY,EAAE,IAHkC;EAIhD;EACA;EACAC,IAAAA,gBAAgB,EAAE,IAAA;EAN8B,GAA5B,CAAtB,CAAA;EAQD;;EC5CM,SAASI,cAAT,CAML7D,cANK,EAOoC;EACzC,EAAA,MAAMwB,MAAM,GAAG,MAAMxB,cAAc,CAAC8D,WAApC,CAAA;;EAEA,EAAA,OAAOzB,MAAM,CAACC,MAAP,CACLxC,eAAe,CAACiE,sBAAD,EAAc/D,cAAd,EAA8B,WAA9B,CADV,EAEL;MACEwB,MADF;MAEEwC,UAAU,EAAEhE,cAAc,CAACgE,UAAAA;EAF7B,GAFK,CAAP,CAAA;EAOD;;;;;;;;;;;;;;;;"}
@@ -1,2 +1,2 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryKit={},e.ReactQuery)}(this,(function(e,t){"use strict";const n=(e,n)=>t.useQueryClient(null!=e&&e.context?{context:e.context}:n),r=(e,t,r)=>{const{use:u=[],...a}=t;return function(t,o){const i=n(t,o);let s=e;const{use:c=[],...y}=i.getDefaultOptions()[r]||{},f=c.concat(u);for(let e=f.length;e--;)void 0===f[e]&&console.log(f[e],f),s=f[e](s);return s({...y,...a,...t},o)}},u=(e,t)=>void 0===t?[e]:[e,t];function a(e,t,a){const{primaryKey:o}=e,i=e=>u(o,e);return Object.assign(r(((e,r)=>{const u=n(e,r),{enabled:o,variables:s,...c}={...e,...a},y=i(s),f=t({...c,enabled:"function"==typeof o?o(u.getQueryData(y),s):o,queryKey:y},u);return Object.assign(f,{queryKey:y,variables:s,setData:(e,t)=>u.setQueryData(y,e,t)})}),e,"queries"),{getPrimaryKey:()=>o,getKey:i,queryFn:e.queryFn,queryKeyHashFn:e.queryKeyHashFn,getFetchOptions:t=>({queryKey:i(t),queryFn:e.queryFn,queryKeyHashFn:e.queryKeyHashFn,getPreviousPageParam:e.getPreviousPageParam,getNextPageParam:e.getNextPageParam,initialPageParam:e.initialPageParam})})}e.createImmutableQuery=function(e){return a(e,t.useQuery,{refetchInterval:!1,refetchOnMount:!1,refetchOnReconnect:!1,refetchOnWindowFocus:!1,staleTime:1/0,gcTime:1/0,cacheTime:1/0})},e.createInfiniteQuery=function(e){return a(e,t.useInfiniteQuery)},e.createMutation=function(e){return Object.assign(r(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,mutationFn:e.mutationFn})},e.createQuery=function(e){return a(e,t.useQuery)},e.createSuspenseInfiniteQuery=function(e){return a(e,t.useInfiniteQuery,{enabled:!0,suspense:!0,throwOnError:!0,useErrorBoundary:!0})},e.createSuspenseQuery=function(e){return a(e,t.useQuery,{enabled:!0,suspense:!0,throwOnError:!0,useErrorBoundary:!0})},e.getQueryKey=u,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryKit={},e.ReactQuery)}(this,(function(e,t){"use strict";const n=(e,n)=>t.useQueryClient(null!=e&&e.context?{context:e.context}:n),r=(e,t,r)=>{const{use:u=[],...a}=t;return function(t,i){const s=n(t,i);let o=e;const{use:c=[],...y}=s.getDefaultOptions()[r]||{},f=c.concat(u);for(let e=f.length;e--;)o=f[e](o);return o({...y,...a,...t},i)}},u=(e,t)=>void 0===t?[e]:[e,t];function a(e,t,a){const{primaryKey:i}=e,s=e=>u(i,e);return Object.assign(r(((e,r)=>{const u=n(e,r),{enabled:i,variables:o,...c}={...e,...a},y=s(o),f=t({...c,enabled:"function"==typeof i?i(u.getQueryData(y),o):i,queryKey:y},u);return Object.assign(f,{queryKey:y,variables:o,setData:(e,t)=>u.setQueryData(y,e,t)})}),e,"queries"),{getPrimaryKey:()=>i,getKey:s,queryFn:e.queryFn,queryKeyHashFn:e.queryKeyHashFn,getFetchOptions:t=>({queryKey:s(t),queryFn:e.queryFn,queryKeyHashFn:e.queryKeyHashFn,getPreviousPageParam:e.getPreviousPageParam,getNextPageParam:e.getNextPageParam,initialPageParam:e.initialPageParam})})}e.createImmutableQuery=function(e){return a(e,t.useQuery,{refetchInterval:!1,refetchOnMount:!1,refetchOnReconnect:!1,refetchOnWindowFocus:!1,staleTime:1/0,gcTime:1/0,cacheTime:1/0})},e.createInfiniteQuery=function(e){return a(e,t.useInfiniteQuery)},e.createMutation=function(e){return Object.assign(r(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,mutationFn:e.mutationFn})},e.createQuery=function(e){return a(e,t.useQuery)},e.createSuspenseInfiniteQuery=function(e){return a(e,t.useInfiniteQuery,{enabled:!0,suspense:!0,throwOnError:!0,useErrorBoundary:!0})},e.createSuspenseQuery=function(e){return a(e,t.useQuery,{enabled:!0,suspense:!0,throwOnError:!0,useErrorBoundary:!0})},e.getQueryKey=u,Object.defineProperty(e,"__esModule",{value:!0})}));
2
2
  //# sourceMappingURL=index.production.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createImmutableQuery.tsx","../../src/createInfiniteQuery.ts","../../src/createMutation.ts","../../src/createQuery.tsx","../../src/createSuspenseInfiniteQuery.ts","../../src/createSuspenseQuery.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n if (middleware[i] === undefined) {\n console.log(middleware[i], middleware)\n }\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n","import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n ImmutableQueryHook,\n Middleware,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<ImmutableQueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, TError>\n): ImmutableQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n Middleware,\n} from './types'\n\nexport interface CreateInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables, TPageParam> {\n use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]\n}\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery)\n}\n","import { useMutation } from '@tanstack/react-query'\nimport type { UseMutationOptions } from '@tanstack/react-query'\n\nimport type { DefaultError, Middleware, MutationHook } from './types'\nimport { withMiddlewares } from './utils'\n\nexport interface CreateMutationOptions<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n> extends UseMutationOptions<TData, TError, TVariables, TContext> {\n use?: Middleware<MutationHook<TData, TError, TVariables>>[]\n}\n\nexport function createMutation<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddlewares(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n Middleware,\n QueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {\n use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createQuery<TFnData, TVariables = any, TError = DefaultError>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery)\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n Middleware,\n SuspenseInfiniteQueryHook,\n} from './types'\n\nexport interface CreateSuspenseInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables, TPageParam>, 'enabled'> {\n use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n","import type { DefaultError, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n Middleware,\n SuspenseQueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateSuspenseQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","reactQuery","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","undefined","console","log","getQueryKey","primaryKey","variables","createBaseQuery","useRQHook","overrideOptions","getKey","Object","assign","enabled","mergedOptions","queryKey","result","getQueryData","setData","updater","setDataOptions","setQueryData","getPrimaryKey","queryFn","queryKeyHashFn","getFetchOptions","getPreviousPageParam","getNextPageParam","initialPageParam","useQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime","useInfiniteQuery","useMutation","mutationKey","mutationFn","suspense","throwOnError","useErrorBoundary"],"mappings":"6TAIO,MAAMA,EAA0B,CACrCC,EACAC,IAGcC,EAAAC,eAAQ,MAAPH,GAAAA,EAASI,QAAU,CAAEA,QAASJ,EAAQI,SAAYH,GAEtDI,EAAkB,CAC7BC,EACAC,EACAC,KAEA,MAAMC,IAAEA,EAAM,MAAOC,GAAgBH,EAErC,OAAO,SACLP,EACAC,GAEA,MAAMU,EAASZ,EAAwBC,EAASC,GAEhD,IAAIW,EAAON,EAEX,MAAQG,IAAKI,EAAY,MAAOC,GAC7BH,EAAOI,oBAAoBP,IAAiB,CAAA,EAEzCQ,EAA2BH,EAAUI,OAAOR,GAElD,IAAK,IAAIS,EAAIF,EAAWG,OAAQD,UACRE,IAAlBJ,EAAWE,IACbG,QAAQC,IAAIN,EAAWE,GAAIF,GAE7BJ,EAAOI,EAAWE,GAAIN,GAGxB,OAAOA,EAAK,IAAKE,KAAkBJ,KAAgBV,GAAWC,GApBhE,EAwBWsB,EAAc,CACzBC,EACAC,SAEqBL,IAAdK,EAA0B,CAACD,GAAc,CAACA,EAAYC,GCnBxD,SAASC,EACdnB,EACAoB,EACAC,GAEA,MAAMJ,WAAEA,GAAejB,EAajBsB,EAAUJ,GAAoBF,EAAYC,EAAYC,GA8C5D,OAAOK,OAAOC,OACZ1B,GAlCwB,CACxBL,EACAC,KAEA,MAAMU,EAASZ,EAAwBC,EAAS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,EACT6B,UAAU,EACVC,cAAc,EAGdC,kBAAkB,GAErB"}
1
+ {"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createImmutableQuery.tsx","../../src/createInfiniteQuery.ts","../../src/createMutation.ts","../../src/createQuery.tsx","../../src/createSuspenseInfiniteQuery.ts","../../src/createSuspenseQuery.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { CompatibleWithV4, Middleware } from './types'\n\nexport const useCompatibeQueryClient = (\n options?: any,\n queryClient?: CompatibleWithV4<QueryClient, void>\n) =>\n // @ts-ignore\n useQueryClient(options?.context ? { context: options.context } : queryClient)\n\nexport const withMiddlewares = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n const { use = [], ...restOptions } = defaultOptions\n\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) {\n const client = useCompatibeQueryClient(options, queryClient)\n\n let next = hook\n\n const { use: configUse = [], ...configOptions } =\n (client.getDefaultOptions()[type] as any) || {}\n\n const middleware: Middleware[] = configUse.concat(use)\n\n for (let i = middleware.length; i--; ) {\n next = middleware[i]!(next)\n }\n\n return next({ ...configOptions, ...restOptions, ...options }, queryClient)\n }\n}\n\nexport const getQueryKey = <TVariables>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return variables === undefined ? [primaryKey] : [primaryKey, variables]\n}\n","import type {\n QueryClient,\n SetDataOptions,\n Updater,\n UseBaseQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getQueryKey, useCompatibeQueryClient, withMiddlewares } from './utils'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any>\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const { primaryKey } = defaultOptions as CreateQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,\n getNextPageParam: (defaultOptions as any).getNextPageParam,\n initialPageParam: (defaultOptions as any).initialPageParam,\n }\n }\n\n const useGeneratedQuery = (\n options: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n const client = useCompatibeQueryClient(options, queryClient)\n\n const { enabled, variables, ...mergedOptions } = {\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey: queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(\n withMiddlewares(useGeneratedQuery, defaultOptions, 'queries'),\n {\n getPrimaryKey,\n getKey,\n queryFn: defaultOptions.queryFn,\n queryKeyHashFn: defaultOptions.queryKeyHashFn,\n getFetchOptions,\n }\n )\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n ImmutableQueryHook,\n Middleware,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<ImmutableQueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, TError>\n): ImmutableQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n Middleware,\n} from './types'\n\nexport interface CreateInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables, TPageParam> {\n use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]\n}\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery)\n}\n","import { useMutation } from '@tanstack/react-query'\nimport type { UseMutationOptions } from '@tanstack/react-query'\n\nimport type { DefaultError, Middleware, MutationHook } from './types'\nimport { withMiddlewares } from './utils'\n\nexport interface CreateMutationOptions<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n> extends UseMutationOptions<TData, TError, TVariables, TContext> {\n use?: Middleware<MutationHook<TData, TError, TVariables>>[]\n}\n\nexport function createMutation<\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddlewares(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n","import type { UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n DefaultError,\n Middleware,\n QueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {\n use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]\n}\n\nexport function createQuery<TFnData, TVariables = any, TError = DefaultError>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery)\n}\n","import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n DefaultError,\n Middleware,\n SuspenseInfiniteQueryHook,\n} from './types'\n\nexport interface CreateSuspenseInfiniteQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TFnData,\n TError,\n TPageParam\n >,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables, TPageParam>, 'enabled'> {\n use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseInfiniteQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> {\n return createBaseQuery(options, useInfiniteQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n","import type { DefaultError, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n Middleware,\n SuspenseQueryHook,\n inferQueryKey,\n} from './types'\n\nexport interface CreateSuspenseQueryOptions<\n TFnData = unknown,\n TVariables = any,\n TError = DefaultError\n> extends Omit<\n UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'suspense'\n | 'throwOnError'\n | 'placeholderData'\n | 'keepPreviousData'\n | 'useErrorBoundary'\n >,\n Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {\n use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]\n}\n\nexport function createSuspenseQuery<\n TFnData,\n TVariables = any,\n TError = DefaultError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> {\n return createBaseQuery(options, useQuery, {\n enabled: true,\n suspense: true,\n throwOnError: true,\n // compatible with ReactQuery v4\n // @ts-ignore\n useErrorBoundary: true,\n })\n}\n"],"names":["useCompatibeQueryClient","options","queryClient","reactQuery","useQueryClient","context","withMiddlewares","hook","defaultOptions","type","use","restOptions","client","next","configUse","configOptions","getDefaultOptions","middleware","concat","i","length","getQueryKey","primaryKey","variables","undefined","createBaseQuery","useRQHook","overrideOptions","getKey","Object","assign","enabled","mergedOptions","queryKey","result","getQueryData","setData","updater","setDataOptions","setQueryData","getPrimaryKey","queryFn","queryKeyHashFn","getFetchOptions","getPreviousPageParam","getNextPageParam","initialPageParam","useQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime","useInfiniteQuery","useMutation","mutationKey","mutationFn","suspense","throwOnError","useErrorBoundary"],"mappings":"6TAIO,MAAMA,EAA0B,CACrCC,EACAC,IAGcC,EAAAC,eAAQ,MAAPH,GAAAA,EAASI,QAAU,CAAEA,QAASJ,EAAQI,SAAYH,GAEtDI,EAAkB,CAC7BC,EACAC,EACAC,KAEA,MAAMC,IAAEA,EAAM,MAAOC,GAAgBH,EAErC,OAAO,SACLP,EACAC,GAEA,MAAMU,EAASZ,EAAwBC,EAASC,GAEhD,IAAIW,EAAON,EAEX,MAAQG,IAAKI,EAAY,MAAOC,GAC7BH,EAAOI,oBAAoBP,IAAiB,CAAA,EAEzCQ,EAA2BH,EAAUI,OAAOR,GAElD,IAAK,IAAIS,EAAIF,EAAWG,OAAQD,KAC9BN,EAA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BmD,EAAAA,YAAajD,EAAgB,aAC7C,CACEoB,OALW,IAAMpB,EAAekD,YAMhCC,WAAYnD,EAAemD,YAGhC,gBCRM,SACL1D,GAEA,OAAOwB,EAAgBxB,EAAS8C,EAAAA,SACjC,gCCUM,SAML9C,GAOA,OAAOwB,EAAgBxB,EAASuD,mBAAkB,CAChDzB,SAAS,EACT6B,UAAU,EACVC,cAAc,EAGdC,kBAAkB,GAErB,wBC5BM,SAKL7D,GAEA,OAAOwB,EAAgBxB,EAAS8C,WAAU,CACxChB,SAAS,EACT6B,UAAU,EACVC,cAAc,EAGdC,kBAAkB,GAErB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-query-kit",
3
- "version": "1.5.0",
3
+ "version": "1.5.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",
package/src/utils.ts CHANGED
@@ -30,9 +30,6 @@ export const withMiddlewares = (
30
30
  const middleware: Middleware[] = configUse.concat(use)
31
31
 
32
32
  for (let i = middleware.length; i--; ) {
33
- if (middleware[i] === undefined) {
34
- console.log(middleware[i], middleware)
35
- }
36
33
  next = middleware[i]!(next)
37
34
  }
38
35