react-query-kit 2.0.3 → 2.0.4
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 +28 -22
- package/build/lib/createBaseQuery.esm.js +24 -13
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +24 -13
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +24 -13
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/lib/types.d.ts +1 -0
- package/build/lib/utils.d.ts +3 -3
- package/build/lib/utils.esm.js +7 -10
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +7 -10
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +7 -10
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +88 -88
- package/build/umd/index.development.js +31 -23
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/build/zip/zip.esm.js +1 -1
- package/package.json +1 -1
- package/src/createBaseQuery.ts +28 -12
- package/src/types.ts +3 -0
- package/src/utils.ts +9 -10
package/README.md
CHANGED
|
@@ -135,8 +135,8 @@ const data = await queryClient.fetchQuery(usePost.getFetchOptions(variables))
|
|
|
135
135
|
// useQueries example
|
|
136
136
|
const queries = useQueries({
|
|
137
137
|
queries: [
|
|
138
|
-
usePost.
|
|
139
|
-
useUser.
|
|
138
|
+
usePost.getOptions(variables),
|
|
139
|
+
useUser.getOptions(),
|
|
140
140
|
],
|
|
141
141
|
})
|
|
142
142
|
|
|
@@ -161,6 +161,7 @@ Expose Methods
|
|
|
161
161
|
- `getKey: (variables: TVariables) => [primaryKey, variables]`
|
|
162
162
|
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
163
163
|
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
164
|
+
- `getOptions: (variables: TVariables) => UseQueryOptions`
|
|
164
165
|
- `getFetchOptions: (variables: TVariables) => ({ queryKey, queryFn, queryKeyHashFn })`
|
|
165
166
|
|
|
166
167
|
## createInfiniteQuery
|
|
@@ -257,6 +258,7 @@ Expose Methods
|
|
|
257
258
|
- `getKey: (variables: TVariables) => [primaryKey, variables]`
|
|
258
259
|
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
259
260
|
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
261
|
+
- `getOptions: (variables: TVariables) => UseInfiniteQueryOptions`
|
|
260
262
|
- `getFetchOptions: (variables: TVariables) => ({ queryKey, queryFn, queryKeyHashFn, getNextPageParam, getPreviousPageParam, initialPageParam })`
|
|
261
263
|
|
|
262
264
|
## createSuspenseQuery
|
|
@@ -399,7 +401,16 @@ const myMiddleware: Middleware<
|
|
|
399
401
|
|
|
400
402
|
const useUser = createQuery<Response, Variables>({
|
|
401
403
|
// ...
|
|
402
|
-
use: [
|
|
404
|
+
use: [
|
|
405
|
+
myMiddleware,
|
|
406
|
+
// or just defined inside of `use`
|
|
407
|
+
function myMiddleware2(useQueryNext) {
|
|
408
|
+
return options => {
|
|
409
|
+
// ...
|
|
410
|
+
return useQueryNext(options)
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
],
|
|
403
414
|
})
|
|
404
415
|
|
|
405
416
|
// global middlewares
|
|
@@ -481,26 +492,21 @@ exit a
|
|
|
481
492
|
In ReactQuery v5, the `QueryClient` will be the second argument to `useQuery` and `useMutation`. If u have multiple `QueryClient` in global, u should receive `QueryClient` in middleware hook.
|
|
482
493
|
|
|
483
494
|
```ts
|
|
484
|
-
const
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
const useSomething = createQuery({ use: [m1, m2] })
|
|
495
|
+
const useSomething = createQuery({
|
|
496
|
+
use: [
|
|
497
|
+
function myMiddleware(useQueryNext) {
|
|
498
|
+
// u should receive queryClient as the second argument here
|
|
499
|
+
return (options, queryClient) => {
|
|
500
|
+
const client = useQueryClient(queryClient)
|
|
501
|
+
// ...
|
|
502
|
+
return useQueryNext(options, queryClient)
|
|
503
|
+
}
|
|
504
|
+
},
|
|
505
|
+
],
|
|
506
|
+
})
|
|
499
507
|
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
useSomething({...}, anotherQueryClient)
|
|
503
|
-
}
|
|
508
|
+
// if u need to pass an another QueryClient
|
|
509
|
+
useSomething({...}, anotherQueryClient)
|
|
504
510
|
```
|
|
505
511
|
|
|
506
512
|
## Type inference
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { withMiddleware, getKey } from './utils.esm.js';
|
|
2
2
|
|
|
3
|
+
const existedPrimaryKeys = new Set();
|
|
3
4
|
const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
4
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
if (defaultOptions.useDefaultOptions) {
|
|
7
|
-
throw new Error('useDefaultOptions is not supported, please use middleware instead.');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
const {
|
|
12
6
|
primaryKey,
|
|
13
7
|
queryFn,
|
|
@@ -17,10 +11,29 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
17
11
|
initialPageParam
|
|
18
12
|
} = defaultOptions;
|
|
19
13
|
|
|
14
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
15
|
+
if (existedPrimaryKeys.has(primaryKey)) {
|
|
16
|
+
console.error("[Bug] Duplicated primaryKey: " + primaryKey);
|
|
17
|
+
} else {
|
|
18
|
+
existedPrimaryKeys.add(primaryKey);
|
|
19
|
+
} // @ts-ignore
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (defaultOptions.useDefaultOptions) {
|
|
23
|
+
console.error('[Bug] useDefaultOptions is not supported, please use middleware instead.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
const getPrimaryKey = () => primaryKey;
|
|
21
28
|
|
|
22
29
|
const getKey$1 = variables => getKey(primaryKey, variables);
|
|
23
30
|
|
|
31
|
+
const getOptions = variables => {
|
|
32
|
+
return { ...defaultOptions,
|
|
33
|
+
queryKey: getKey$1(variables)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
24
37
|
const getFetchOptions = variables => {
|
|
25
38
|
return {
|
|
26
39
|
queryKey: getKey$1(variables),
|
|
@@ -32,13 +45,10 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
32
45
|
};
|
|
33
46
|
};
|
|
34
47
|
|
|
35
|
-
const useBaseHook = ({
|
|
36
|
-
|
|
37
|
-
...restOptions
|
|
38
|
-
}, queryClient) => {
|
|
39
|
-
return useRQHook({ ...restOptions,
|
|
48
|
+
const useBaseHook = (options, queryClient) => {
|
|
49
|
+
return useRQHook({ ...options,
|
|
40
50
|
...overrideOptions,
|
|
41
|
-
queryKey: getKey$1(variables)
|
|
51
|
+
queryKey: getKey$1(options.variables)
|
|
42
52
|
}, queryClient);
|
|
43
53
|
};
|
|
44
54
|
|
|
@@ -47,6 +57,7 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
47
57
|
getKey: getKey$1,
|
|
48
58
|
queryFn,
|
|
49
59
|
queryKeyHashFn,
|
|
60
|
+
getOptions,
|
|
50
61
|
getFetchOptions
|
|
51
62
|
});
|
|
52
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n
|
|
1
|
+
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nconst existedPrimaryKeys = new Set<string>()\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any => {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n if (existedPrimaryKeys.has(primaryKey)) {\n console.error(`[Bug] Duplicated primaryKey: ${primaryKey}`)\n } else {\n existedPrimaryKeys.add(primaryKey)\n }\n\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] 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 getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n queryKey: getKey(variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n queryKey: getKey(options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getOptions,\n getFetchOptions,\n })\n}\n"],"names":["existedPrimaryKeys","Set","createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","process","env","NODE_ENV","has","console","error","add","useDefaultOptions","getPrimaryKey","getKey","variables","getQueryKey","getOptions","queryKey","getFetchOptions","useBaseHook","options","queryClient","Object","assign","withMiddleware"],"mappings":";;AAuBA,MAAMA,kBAAkB,GAAG,IAAIC,GAAJ,EAA3B,CAAA;AAEO,MAAMC,eAAe,GAAG,CAC7BC,cAD6B,EAE7BC,SAF6B,EAG7BC,eAH6B,KAIrB;EACR,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFR,cAPJ,CAAA;;AASA,EAAA,IAAIS,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,IAAA,IAAId,kBAAkB,CAACe,GAAnB,CAAuBT,UAAvB,CAAJ,EAAwC;MACtCU,OAAO,CAACC,KAAR,CAAA,+BAAA,GAA8CX,UAA9C,CAAA,C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esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var utils = require('./utils.js');
|
|
6
6
|
|
|
7
|
+
const existedPrimaryKeys = new Set();
|
|
7
8
|
const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
8
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
-
// @ts-ignore
|
|
10
|
-
if (defaultOptions.useDefaultOptions) {
|
|
11
|
-
throw new Error('useDefaultOptions is not supported, please use middleware instead.');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
9
|
const {
|
|
16
10
|
primaryKey,
|
|
17
11
|
queryFn,
|
|
@@ -21,10 +15,29 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
21
15
|
initialPageParam
|
|
22
16
|
} = defaultOptions;
|
|
23
17
|
|
|
18
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
19
|
+
if (existedPrimaryKeys.has(primaryKey)) {
|
|
20
|
+
console.error("[Bug] Duplicated primaryKey: " + primaryKey);
|
|
21
|
+
} else {
|
|
22
|
+
existedPrimaryKeys.add(primaryKey);
|
|
23
|
+
} // @ts-ignore
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
if (defaultOptions.useDefaultOptions) {
|
|
27
|
+
console.error('[Bug] useDefaultOptions is not supported, please use middleware instead.');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
24
31
|
const getPrimaryKey = () => primaryKey;
|
|
25
32
|
|
|
26
33
|
const getKey = variables => utils.getKey(primaryKey, variables);
|
|
27
34
|
|
|
35
|
+
const getOptions = variables => {
|
|
36
|
+
return { ...defaultOptions,
|
|
37
|
+
queryKey: getKey(variables)
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
|
|
28
41
|
const getFetchOptions = variables => {
|
|
29
42
|
return {
|
|
30
43
|
queryKey: getKey(variables),
|
|
@@ -36,13 +49,10 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
36
49
|
};
|
|
37
50
|
};
|
|
38
51
|
|
|
39
|
-
const useBaseHook = ({
|
|
40
|
-
|
|
41
|
-
...restOptions
|
|
42
|
-
}, queryClient) => {
|
|
43
|
-
return useRQHook({ ...restOptions,
|
|
52
|
+
const useBaseHook = (options, queryClient) => {
|
|
53
|
+
return useRQHook({ ...options,
|
|
44
54
|
...overrideOptions,
|
|
45
|
-
queryKey: getKey(variables)
|
|
55
|
+
queryKey: getKey(options.variables)
|
|
46
56
|
}, queryClient);
|
|
47
57
|
};
|
|
48
58
|
|
|
@@ -51,6 +61,7 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
51
61
|
getKey,
|
|
52
62
|
queryFn,
|
|
53
63
|
queryKeyHashFn,
|
|
64
|
+
getOptions,
|
|
54
65
|
getFetchOptions
|
|
55
66
|
});
|
|
56
67
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n
|
|
1
|
+
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nconst existedPrimaryKeys = new Set<string>()\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any => {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n if (existedPrimaryKeys.has(primaryKey)) {\n console.error(`[Bug] Duplicated primaryKey: ${primaryKey}`)\n } else {\n existedPrimaryKeys.add(primaryKey)\n }\n\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] 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 getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n queryKey: getKey(variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n queryKey: getKey(options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getOptions,\n getFetchOptions,\n })\n}\n"],"names":["existedPrimaryKeys","Set","createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","process","env","NODE_ENV","has","console","error","add","useDefaultOptions","getPrimaryKey","getKey","variables","getQueryKey","getOptions","queryKey","getFetchOptions","useBaseHook","options","queryClient","Object","assign","withMiddleware"],"mappings":";;;;;;AAuBA,MAAMA,kBAAkB,GAAG,IAAIC,GAAJ,EAA3B,CAAA;AAEO,MAAMC,eAAe,GAAG,CAC7BC,cAD6B,EAE7BC,SAF6B,EAG7BC,eAH6B,KAIrB;EACR,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFR,cAPJ,CAAA;;AASA,EAAA,IAAIS,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC,IAAA,IAAId,kBAAkB,CAACe,GAAnB,CAAuBT,UAAvB,CAAJ,EAAwC;MACtCU,OAAO,CAACC,KAAR,CAAA,+BAAA,GAA8CX,UAA9C,CAAA,CAAA;AACD,KAFD,MAEO;MACLN,kBAAkB,CAACkB,GAAnB,CAAuBZ,UAAvB,CAAA,CAAA;AACD,KALwC;;;IAQzC,IAAIH,cAAc,CAACgB,iBAAnB,EAAsC;MACpCH,OAAO,CAACC,KAAR,CACE,0EADF,CAAA,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMG,aAAa,GAAG,MAAMd,UAA5B,CAAA;;EAEA,MAAMe,MAAM,GAAIC,SAAD,IAAqBC,YAAW,CAACjB,UAAD,EAAagB,SAAb,CAA/C,CAAA;;EAEA,MAAME,UAAU,GAAIF,SAAD,IAAoB;IACrC,OAAO,EACL,GAAGnB,cADE;MAELsB,QAAQ,EAAEJ,MAAM,CAACC,SAAD,CAAA;KAFlB,CAAA;GADF,CAAA;;EAOA,MAAMI,eAAe,GAAIJ,SAAD,IAAoB;IAC1C,OAAO;AACLG,MAAAA,QAAQ,EAAEJ,MAAM,CAACC,SAAD,CADX;MAELf,OAFK;MAGLC,cAHK;MAILC,oBAJK;MAKLC,gBALK;AAMLC,MAAAA,gBAAAA;KANF,CAAA;GADF,CAAA;;AAWA,EAAA,MAAMgB,WAAW,GAAG,CAClBC,OADkB,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOzB,SAAS,CACd,EACE,GAAGwB,OADL;AAEE,MAAA,GAAGvB,eAFL;AAGEoB,MAAAA,QAAQ,EAAEJ,MAAM,CAACO,OAAO,CAACN,SAAT,CAAA;KAJJ,EAMdO,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,oBAAc,CAACL,WAAD,EAAcxB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3EiB,aAD2E;IAE3EC,MAF2E;IAG3Ed,OAH2E;IAI3EC,cAJ2E;IAK3EgB,UAL2E;AAM3EE,IAAAA,eAAAA;AAN2E,GAAtE,CAAP,CAAA;AAQD;;;;"}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { withMiddleware, getKey } from './utils.mjs';
|
|
2
2
|
|
|
3
|
+
const existedPrimaryKeys = new Set();
|
|
3
4
|
const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
4
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
5
|
-
// @ts-ignore
|
|
6
|
-
if (defaultOptions.useDefaultOptions) {
|
|
7
|
-
throw new Error('useDefaultOptions is not supported, please use middleware instead.');
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
|
|
11
5
|
const {
|
|
12
6
|
primaryKey,
|
|
13
7
|
queryFn,
|
|
@@ -17,10 +11,29 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
17
11
|
initialPageParam
|
|
18
12
|
} = defaultOptions;
|
|
19
13
|
|
|
14
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
15
|
+
if (existedPrimaryKeys.has(primaryKey)) {
|
|
16
|
+
console.error("[Bug] Duplicated primaryKey: " + primaryKey);
|
|
17
|
+
} else {
|
|
18
|
+
existedPrimaryKeys.add(primaryKey);
|
|
19
|
+
} // @ts-ignore
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if (defaultOptions.useDefaultOptions) {
|
|
23
|
+
console.error('[Bug] useDefaultOptions is not supported, please use middleware instead.');
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
20
27
|
const getPrimaryKey = () => primaryKey;
|
|
21
28
|
|
|
22
29
|
const getKey$1 = variables => getKey(primaryKey, variables);
|
|
23
30
|
|
|
31
|
+
const getOptions = variables => {
|
|
32
|
+
return { ...defaultOptions,
|
|
33
|
+
queryKey: getKey$1(variables)
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
|
|
24
37
|
const getFetchOptions = variables => {
|
|
25
38
|
return {
|
|
26
39
|
queryKey: getKey$1(variables),
|
|
@@ -32,13 +45,10 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
32
45
|
};
|
|
33
46
|
};
|
|
34
47
|
|
|
35
|
-
const useBaseHook = ({
|
|
36
|
-
|
|
37
|
-
...restOptions
|
|
38
|
-
}, queryClient) => {
|
|
39
|
-
return useRQHook({ ...restOptions,
|
|
48
|
+
const useBaseHook = (options, queryClient) => {
|
|
49
|
+
return useRQHook({ ...options,
|
|
40
50
|
...overrideOptions,
|
|
41
|
-
queryKey: getKey$1(variables)
|
|
51
|
+
queryKey: getKey$1(options.variables)
|
|
42
52
|
}, queryClient);
|
|
43
53
|
};
|
|
44
54
|
|
|
@@ -47,6 +57,7 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
47
57
|
getKey: getKey$1,
|
|
48
58
|
queryFn,
|
|
49
59
|
queryKeyHashFn,
|
|
60
|
+
getOptions,
|
|
50
61
|
getFetchOptions
|
|
51
62
|
});
|
|
52
63
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n
|
|
1
|
+
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nconst existedPrimaryKeys = new Set<string>()\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any => {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n if (existedPrimaryKeys.has(primaryKey)) {\n console.error(`[Bug] Duplicated primaryKey: ${primaryKey}`)\n } else {\n existedPrimaryKeys.add(primaryKey)\n }\n\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] 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 getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n queryKey: getKey(variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n queryKey: getKey(options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getOptions,\n getFetchOptions,\n })\n}\n"],"names":["existedPrimaryKeys","Set","createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","process","env","NODE_ENV","has","console","error","add","useDefaultOptions","getPrimaryKey","getKey","variables","getQueryKey","getOptions","queryKey","getFetchOptions","useBaseHook","options","queryClient","Object","assign","withMiddleware"],"mappings":";;AAuBA,MAAMA,kBAAkB,GAAG,IAAIC,GAAJ,EAA3B,CAAA;AAEO,MAAMC,eAAe,GAAG,CAC7BC,cAD6B,EAE7BC,SAF6B,EAG7BC,eAH6B,KAIrB;EACR,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFR,cA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EAA8B,SAA9B,CAA5B,EAAsE;IAC3EiB,aAD2E;YAE3EC,QAF2E;IAG3Ed,OAH2E;IAI3EC,cAJ2E;IAK3EgB,UAL2E;AAM3EE,IAAAA,eAAAA;AAN2E,GAAtE,CAAP,CAAA;AAQD;;;;"}
|
package/build/lib/types.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export type ExposeMethods<TFnData, TVariables, TPageParam = never> = {
|
|
|
35
35
|
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TVariables>, TPageParam>;
|
|
36
36
|
queryKeyHashFn?: QueryKeyHashFunction<inferQueryKey<TVariables>>;
|
|
37
37
|
} & CompatibleInfiniteQueryPageParamsOptions<TFnData, TPageParam>;
|
|
38
|
+
getOptions: ExposeMethods<TFnData, TVariables, TPageParam>['getFetchOptions'];
|
|
38
39
|
};
|
|
39
40
|
export interface CreateQueryOptions<TFnData = unknown, TVariables = any, TError = Error> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'select'>, AdditionalQueryOptions<TFnData, TVariables> {
|
|
40
41
|
use?: Middleware<QueryHook<TFnData, TVariables, TError>>[];
|
package/build/lib/utils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { Middleware, inferQueryKey } from './types';
|
|
1
|
+
import { type QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import type { Middleware, inferQueryKey } from './types';
|
|
3
3
|
export declare const withMiddleware: (hook: any, defaultOptions: any, type: 'queries' | 'mutations') => (options?: {
|
|
4
4
|
client?: QueryClient;
|
|
5
5
|
use?: Middleware[];
|
|
@@ -10,4 +10,4 @@ export declare const suspenseOptions: {
|
|
|
10
10
|
throwOnError: boolean;
|
|
11
11
|
useErrorBoundary: boolean;
|
|
12
12
|
};
|
|
13
|
-
export declare const getKey: <TVariables>(primaryKey: string, variables?: TVariables | undefined) => inferQueryKey<TVariables>;
|
|
13
|
+
export declare const getKey: <TVariables = void>(primaryKey: string, variables?: TVariables | undefined) => inferQueryKey<TVariables>;
|
package/build/lib/utils.esm.js
CHANGED
|
@@ -2,16 +2,13 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
|
|
3
3
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
4
4
|
return function useMiddleware(options, queryClient) {
|
|
5
|
-
const [middleware, opts] = [useQueryClient( //
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = {}) => [[..._middleware, ...use], { ..._opts,
|
|
13
|
-
...rest
|
|
14
|
-
}], [[], {}]);
|
|
5
|
+
const [middleware, opts] = [useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
6
|
+
options != null && options.context ? options : queryClient).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
7
|
+
use: u2 = [],
|
|
8
|
+
...o2
|
|
9
|
+
} = {}) => [[...u1, ...u2], { ...o1,
|
|
10
|
+
...o2
|
|
11
|
+
}], [[]]);
|
|
15
12
|
let next = hook;
|
|
16
13
|
|
|
17
14
|
for (let i = middleware.length; i--;) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n //
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import { type QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n options?.context ? options : queryClient\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n throwOnError: true,\n useErrorBoundary: true,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<TVariables>\n}\n"],"names":["withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","context","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","throwOnError","useErrorBoundary","getKey","primaryKey","variables","undefined"],"mappings":";;AAIO,MAAMA,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAM,CAACC,UAAD,EAAaC,IAAb,CAAqB,GAAA,CACzBC,cAAc;AAEZJ,IAAAA,OAAO,IAAP,IAAA,IAAAA,OAAO,CAAEK,OAAT,GAAmBL,OAAnB,GAA6BC,WAFjB,CAAd,CAGEK,iBAHF,EAGsBR,CAAAA,IAHtB,CADyB,EAKzBD,cALyB,EAMzBG,OANyB,CAAA,CAOzBO,MAPyB,CAQzB,CAAC,CAACC,EAAD,EAAKC,EAAL,CAAD,EAAW;MAAEC,GAAG,EAAEC,EAAE,GAAG,EAAZ;MAAgB,GAAGC,EAAAA;AAAnB,KAAA,GAA0B,EAArC,KAA4C,CAC1C,CAAC,GAAGJ,EAAJ,EAAQ,GAAGG,EAAX,CAD0C,EAE1C,EAAE,GAAGF,EAAL;MAAS,GAAGG,EAAAA;AAAZ,KAF0C,CARnB,EAYzB,CAAC,EAAD,CAZyB,CAA3B,CAAA;IAeA,IAAIC,IAAI,GAAGjB,IAAX,CAAA;;IACA,KAAK,IAAIkB,CAAC,GAAGZ,UAAU,CAACa,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrCD,MAAAA,IAAI,GAAGX,UAAU,CAACY,CAAD,CAAV,CAAcD,IAAd,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAACV,IAAD,EAAOF,WAAP,CAAX,CAAA;GAxBF,CAAA;AA0BD,EA/BM;AAiCA,MAAMe,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;AAG7BC,EAAAA,YAAY,EAAE,IAHe;AAI7BC,EAAAA,gBAAgB,EAAE,IAAA;AAJW,EAAxB;MAOMC,MAAM,GAAG,CACpBC,UADoB,EAEpBC,SAFoB,KAGjB;AACH,EAAA,OACEA,SAAS,KAAKC,SAAd,GAA0B,CAACF,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAD3C,CAAA;AAGD;;;;"}
|
package/build/lib/utils.js
CHANGED
|
@@ -6,16 +6,13 @@ var reactQuery = require('@tanstack/react-query');
|
|
|
6
6
|
|
|
7
7
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
8
8
|
return function useMiddleware(options, queryClient) {
|
|
9
|
-
const [middleware, opts] = [reactQuery.useQueryClient( //
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
} = {}) => [[..._middleware, ...use], { ..._opts,
|
|
17
|
-
...rest
|
|
18
|
-
}], [[], {}]);
|
|
9
|
+
const [middleware, opts] = [reactQuery.useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
10
|
+
options != null && options.context ? options : queryClient).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
11
|
+
use: u2 = [],
|
|
12
|
+
...o2
|
|
13
|
+
} = {}) => [[...u1, ...u2], { ...o1,
|
|
14
|
+
...o2
|
|
15
|
+
}], [[]]);
|
|
19
16
|
let next = hook;
|
|
20
17
|
|
|
21
18
|
for (let i = middleware.length; i--;) {
|
package/build/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n //
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import { type QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n options?.context ? options : queryClient\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n throwOnError: true,\n useErrorBoundary: true,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<TVariables>\n}\n"],"names":["withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","context","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","throwOnError","useErrorBoundary","getKey","primaryKey","variables","undefined"],"mappings":";;;;;;AAIO,MAAMA,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAM,CAACC,UAAD,EAAaC,IAAb,CAAqB,GAAA,CACzBC,yBAAc;AAEZJ,IAAAA,OAAO,IAAP,IAAA,IAAAA,OAAO,CAAEK,OAAT,GAAmBL,OAAnB,GAA6BC,WAFjB,CAAd,CAGEK,iBAHF,EAGsBR,CAAAA,IAHtB,CADyB,EAKzBD,cALyB,EAMzBG,OANyB,CAAA,CAOzBO,MAPyB,CAQzB,CAAC,CAACC,EAAD,EAAKC,EAAL,CAAD,EAAW;MAAEC,GAAG,EAAEC,EAAE,GAAG,EAAZ;MAAgB,GAAGC,EAAAA;AAAnB,KAAA,GAA0B,EAArC,KAA4C,CAC1C,CAAC,GAAGJ,EAAJ,EAAQ,GAAGG,EAAX,CAD0C,EAE1C,EAAE,GAAGF,EAAL;MAAS,GAAGG,EAAAA;AAAZ,KAF0C,CARnB,EAYzB,CAAC,EAAD,CAZyB,CAA3B,CAAA;IAeA,IAAIC,IAAI,GAAGjB,IAAX,CAAA;;IACA,KAAK,IAAIkB,CAAC,GAAGZ,UAAU,CAACa,MAAxB,EAAgCD,CAAC,EAAjC,GAAuC;AACrCD,MAAAA,IAAI,GAAGX,UAAU,CAACY,CAAD,CAAV,CAAcD,IAAd,CAAP,CAAA;AACD,KAAA;;AAED,IAAA,OAAOA,IAAI,CAACV,IAAD,EAAOF,WAAP,CAAX,CAAA;GAxBF,CAAA;AA0BD,EA/BM;AAiCA,MAAMe,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;AAG7BC,EAAAA,YAAY,EAAE,IAHe;AAI7BC,EAAAA,gBAAgB,EAAE,IAAA;AAJW,EAAxB;MAOMC,MAAM,GAAG,CACpBC,UADoB,EAEpBC,SAFoB,KAGjB;AACH,EAAA,OACEA,SAAS,KAAKC,SAAd,GAA0B,CAACF,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaC,SAAb,CAD3C,CAAA;AAGD;;;;;;"}
|
package/build/lib/utils.mjs
CHANGED
|
@@ -2,16 +2,13 @@ import { useQueryClient } from '@tanstack/react-query';
|
|
|
2
2
|
|
|
3
3
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
4
4
|
return function useMiddleware(options, queryClient) {
|
|
5
|
-
const [middleware, opts] = [useQueryClient( //
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
} = {}) => [[..._middleware, ...use], { ..._opts,
|
|
13
|
-
...rest
|
|
14
|
-
}], [[], {}]);
|
|
5
|
+
const [middleware, opts] = [useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
6
|
+
options != null && options.context ? options : queryClient).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
7
|
+
use: u2 = [],
|
|
8
|
+
...o2
|
|
9
|
+
} = {}) => [[...u1, ...u2], { ...o1,
|
|
10
|
+
...o2
|
|
11
|
+
}], [[]]);
|
|
15
12
|
let next = hook;
|
|
16
13
|
|
|
17
14
|
for (let i = middleware.length; i--;) {
|
package/build/lib/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import { QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n //
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import { type QueryClient, useQueryClient } from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n options?.context ? options : queryClient\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n throwOnError: true,\n useErrorBoundary: true,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<TVariables>\n}\n"],"names":["withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","context","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","throwOnError","useErrorBoundary","getKey","primaryKey","variables","undefined"],"mappings":";;AAIO,MAAMA,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,W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;"}
|
package/build/stats-html.html
CHANGED
|
@@ -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":"zip.esm.js","children":[{"name":"src","children":[{"uid":"
|
|
4017
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"a4ee-1","name":"utils.ts"},{"uid":"a4ee-3","name":"createBaseQuery.ts"},{"uid":"a4ee-5","name":"createQuery.tsx"},{"uid":"a4ee-7","name":"createSuspenseQuery.ts"},{"uid":"a4ee-9","name":"createInfiniteQuery.ts"},{"uid":"a4ee-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"a4ee-13","name":"createMutation.ts"},{"uid":"a4ee-15","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"a4ee-1":{"renderedLength":824,"gzipLength":428,"brotliLength":0,"mainUid":"a4ee-0"},"a4ee-3":{"renderedLength":1046,"gzipLength":367,"brotliLength":0,"mainUid":"a4ee-2"},"a4ee-5":{"renderedLength":80,"gzipLength":79,"brotliLength":0,"mainUid":"a4ee-4"},"a4ee-7":{"renderedLength":105,"gzipLength":94,"brotliLength":0,"mainUid":"a4ee-6"},"a4ee-9":{"renderedLength":96,"gzipLength":89,"brotliLength":0,"mainUid":"a4ee-8"},"a4ee-11":{"renderedLength":121,"gzipLength":104,"brotliLength":0,"mainUid":"a4ee-10"},"a4ee-13":{"renderedLength":240,"gzipLength":163,"brotliLength":0,"mainUid":"a4ee-12"},"a4ee-15":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"a4ee-14"}},"nodeMetas":{"a4ee-0":{"id":"/src/utils.ts","moduleParts":{"zip.esm.js":"a4ee-1"},"imported":[{"uid":"a4ee-17"}],"importedBy":[{"uid":"a4ee-14"},{"uid":"a4ee-6"},{"uid":"a4ee-10"},{"uid":"a4ee-12"},{"uid":"a4ee-2"}]},"a4ee-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"zip.esm.js":"a4ee-3"},"imported":[{"uid":"a4ee-0"}],"importedBy":[{"uid":"a4ee-4"},{"uid":"a4ee-6"},{"uid":"a4ee-8"},{"uid":"a4ee-10"}]},"a4ee-4":{"id":"/src/createQuery.tsx","moduleParts":{"zip.esm.js":"a4ee-5"},"imported":[{"uid":"a4ee-17"},{"uid":"a4ee-2"}],"importedBy":[{"uid":"a4ee-14"}]},"a4ee-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"zip.esm.js":"a4ee-7"},"imported":[{"uid":"a4ee-17"},{"uid":"a4ee-2"},{"uid":"a4ee-0"}],"importedBy":[{"uid":"a4ee-14"}]},"a4ee-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"zip.esm.js":"a4ee-9"},"imported":[{"uid":"a4ee-17"},{"uid":"a4ee-2"}],"importedBy":[{"uid":"a4ee-14"}]},"a4ee-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"zip.esm.js":"a4ee-11"},"imported":[{"uid":"a4ee-17"},{"uid":"a4ee-2"},{"uid":"a4ee-0"}],"importedBy":[{"uid":"a4ee-14"}]},"a4ee-12":{"id":"/src/createMutation.ts","moduleParts":{"zip.esm.js":"a4ee-13"},"imported":[{"uid":"a4ee-17"},{"uid":"a4ee-0"}],"importedBy":[{"uid":"a4ee-14"}]},"a4ee-14":{"id":"/src/index.ts","moduleParts":{"zip.esm.js":"a4ee-15"},"imported":[{"uid":"a4ee-4"},{"uid":"a4ee-6"},{"uid":"a4ee-8"},{"uid":"a4ee-10"},{"uid":"a4ee-12"},{"uid":"a4ee-16"},{"uid":"a4ee-0"}],"importedBy":[],"isEntry":true},"a4ee-16":{"id":"/src/types.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"a4ee-14"}]},"a4ee-17":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"a4ee-4"},{"uid":"a4ee-6"},{"uid":"a4ee-8"},{"uid":"a4ee-10"},{"uid":"a4ee-12"},{"uid":"a4ee-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;
|