react-query-kit 3.0.0 → 3.1.0
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 +29 -7
- package/build/lib/router.esm.js +26 -17
- package/build/lib/router.esm.js.map +1 -1
- package/build/lib/router.js +26 -17
- package/build/lib/router.js.map +1 -1
- package/build/lib/router.mjs +26 -17
- package/build/lib/router.mjs.map +1 -1
- package/build/lib/types.d.ts +2 -2
- package/build/lib/utils.esm.js +4 -4
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +4 -4
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +4 -4
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +99 -99
- package/build/umd/index.development.js +30 -21
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/build/zip/zip.esm.js +1 -1
- package/package.json +1 -1
- package/src/router.ts +34 -26
- package/src/types.ts +32 -0
- package/src/utils.ts +4 -4
package/README.md
CHANGED
|
@@ -64,7 +64,7 @@ This module is distributed via [npm][npm] which is bundled with [node][node] and
|
|
|
64
64
|
should be installed as one of your project's `dependencies`:
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
|
-
$ npm i react-query-
|
|
67
|
+
$ npm i react-query-kit
|
|
68
68
|
# or
|
|
69
69
|
$ yarn add react-query-kit
|
|
70
70
|
```
|
|
@@ -367,7 +367,7 @@ Options
|
|
|
367
367
|
- Optional
|
|
368
368
|
- array of middleware functions [(details)](#middleware)
|
|
369
369
|
|
|
370
|
-
|
|
370
|
+
Expose Methods
|
|
371
371
|
|
|
372
372
|
- `getKey: () => MutationKey`
|
|
373
373
|
- `getOptions: () => UseMutationOptions`
|
|
@@ -403,6 +403,13 @@ const post = router(`post`, {
|
|
|
403
403
|
body: JSON.stringify(variables),
|
|
404
404
|
}).then(res => res.json()),
|
|
405
405
|
}),
|
|
406
|
+
|
|
407
|
+
// nest router
|
|
408
|
+
command: {
|
|
409
|
+
report: router.mutation({ mutationFn }),
|
|
410
|
+
|
|
411
|
+
promote: router.mutation({ mutationFn }),
|
|
412
|
+
},
|
|
406
413
|
})
|
|
407
414
|
|
|
408
415
|
// get root key
|
|
@@ -414,6 +421,7 @@ post.byId.useSuspenseQuery({ variables: { id: 1 } })
|
|
|
414
421
|
post.list.useInfiniteQuery()
|
|
415
422
|
post.list.useSuspenseInfiniteQuery()
|
|
416
423
|
post.add.useMutation()
|
|
424
|
+
post.command.report.useMutation()
|
|
417
425
|
|
|
418
426
|
// expose methods
|
|
419
427
|
post.byId.getKey({ id: 1 }) // ['post', 'byId', { id: 1 }]
|
|
@@ -425,13 +433,27 @@ post.add.getOptions()
|
|
|
425
433
|
post.add.mutationFn({ title: 'title', content: 'content' })
|
|
426
434
|
|
|
427
435
|
// infer types
|
|
428
|
-
type Data = inferData<typeof
|
|
429
|
-
type FnData = inferFnData<typeof
|
|
430
|
-
type Variables = inferVariables<typeof
|
|
431
|
-
type Error = inferError<typeof
|
|
436
|
+
type Data = inferData<typeof post.list>
|
|
437
|
+
type FnData = inferFnData<typeof post.list>
|
|
438
|
+
type Variables = inferVariables<typeof post.list>
|
|
439
|
+
type Error = inferError<typeof post.list>
|
|
440
|
+
```
|
|
441
|
+
|
|
442
|
+
### Merging Routers
|
|
443
|
+
|
|
444
|
+
```ts
|
|
445
|
+
import { router } from 'react-query-kit'
|
|
446
|
+
|
|
447
|
+
const user = router(`user`, {})
|
|
448
|
+
const post = router(`post`, {})
|
|
449
|
+
|
|
450
|
+
const k = {
|
|
451
|
+
user,
|
|
452
|
+
post,
|
|
453
|
+
}
|
|
432
454
|
```
|
|
433
455
|
|
|
434
|
-
|
|
456
|
+
### API Reference
|
|
435
457
|
|
|
436
458
|
`type Router = (key: string, config: TConfig) => TRouter`
|
|
437
459
|
|
package/build/lib/router.esm.js
CHANGED
|
@@ -4,29 +4,38 @@ import { createQuery } from './createQuery.esm.js';
|
|
|
4
4
|
import { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery.esm.js';
|
|
5
5
|
import { createSuspenseQuery } from './createSuspenseQuery.esm.js';
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const buildRouter = (keys, config) => {
|
|
8
8
|
return Object.entries(config).reduce((acc, [key, opts]) => {
|
|
9
|
-
|
|
10
|
-
[
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
if (!opts._type) {
|
|
10
|
+
acc[key] = buildRouter([...keys, key], opts);
|
|
11
|
+
} else {
|
|
12
|
+
const options = { ...opts,
|
|
13
|
+
[opts._type === "m" ? "mutationKey" : "queryKey"]: [...keys, key]
|
|
14
|
+
};
|
|
15
|
+
acc[key] = opts._type === "m" ? {
|
|
16
|
+
useMutation: createMutation(options),
|
|
17
|
+
...createMutation(options)
|
|
18
|
+
} : opts._type === "q" ? {
|
|
19
|
+
useQuery: createQuery(options),
|
|
20
|
+
useSuspenseQuery: createSuspenseQuery(options),
|
|
21
|
+
...createQuery(options)
|
|
22
|
+
} : {
|
|
23
|
+
useInfiniteQuery: createInfiniteQuery(options),
|
|
24
|
+
useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),
|
|
25
|
+
...createInfiniteQuery(options)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
return acc;
|
|
25
30
|
}, {
|
|
26
|
-
getKey: () =>
|
|
31
|
+
getKey: () => keys
|
|
27
32
|
});
|
|
28
33
|
};
|
|
29
34
|
|
|
35
|
+
const router = (scope, config) => {
|
|
36
|
+
return buildRouter([scope], config);
|
|
37
|
+
};
|
|
38
|
+
|
|
30
39
|
router.query = options => {
|
|
31
40
|
return { ...options,
|
|
32
41
|
_type: 'q'
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.esm.js","sources":["../../src/router.ts"],"sourcesContent":["import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\
|
|
1
|
+
{"version":3,"file":"router.esm.js","sources":["../../src/router.ts"],"sourcesContent":["import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nconst buildRouter = (keys: string[], config: RouterConfig) => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n if (!opts._type) {\n acc[key] = buildRouter([...keys, key], opts)\n } else {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [...keys, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n }\n\n return acc\n },\n {\n getKey: () => keys,\n } as any\n )\n}\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return buildRouter([scope], config)\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["buildRouter","keys","config","Object","entries","reduce","acc","key","opts","_type","options","useMutation","createMutation","useQuery","createQuery","useSuspenseQuery","createSuspenseQuery","useInfiniteQuery","createInfiniteQuery","useSuspenseInfiniteQuery","createSuspenseInfiniteQuery","getKey","router","scope","query","infiniteQuery","mutation"],"mappings":";;;;;;AAiBA,MAAMA,WAAW,GAAG,CAACC,IAAD,EAAiBC,MAAjB,KAA0C;AAC5D,EAAA,OAAOC,MAAM,CAACC,OAAP,CAAeF,MAAf,EAAuBG,MAAvB,CACL,CAACC,GAAD,EAAM,CAACC,GAAD,EAAMC,IAAN,CAAN,KAAsB;AACpB,IAAA,IAAI,CAACA,IAAI,CAACC,KAAV,EAAiB;AACfH,MAAAA,GAAG,CAACC,GAAD,CAAH,GAAWP,WAAW,CAAC,CAAC,GAAGC,IAAJ,EAAUM,GAAV,CAAD,EAAiBC,IAAjB,CAAtB,CAAA;AACD,KAFD,MAEO;AACL,MAAA,MAAME,OAAY,GAAG,EACnB,GAAGF,IADgB;QAEnB,CAACA,IAAI,CAACC,K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;AAcAa,MAAM,CAACI,QAAP,GAMEhB,OANgB,IAU0C;EAC1D,OAAO,EAAE,GAAGA,OAAL;AAAcD,IAAAA,KAAK,EAAE,GAAA;GAA5B,CAAA;AACD,CAZD;;;;"}
|
package/build/lib/router.js
CHANGED
|
@@ -8,29 +8,38 @@ var createQuery = require('./createQuery.js');
|
|
|
8
8
|
var createSuspenseInfiniteQuery = require('./createSuspenseInfiniteQuery.js');
|
|
9
9
|
var createSuspenseQuery = require('./createSuspenseQuery.js');
|
|
10
10
|
|
|
11
|
-
const
|
|
11
|
+
const buildRouter = (keys, config) => {
|
|
12
12
|
return Object.entries(config).reduce((acc, [key, opts]) => {
|
|
13
|
-
|
|
14
|
-
[
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
if (!opts._type) {
|
|
14
|
+
acc[key] = buildRouter([...keys, key], opts);
|
|
15
|
+
} else {
|
|
16
|
+
const options = { ...opts,
|
|
17
|
+
[opts._type === "m" ? "mutationKey" : "queryKey"]: [...keys, key]
|
|
18
|
+
};
|
|
19
|
+
acc[key] = opts._type === "m" ? {
|
|
20
|
+
useMutation: createMutation.createMutation(options),
|
|
21
|
+
...createMutation.createMutation(options)
|
|
22
|
+
} : opts._type === "q" ? {
|
|
23
|
+
useQuery: createQuery.createQuery(options),
|
|
24
|
+
useSuspenseQuery: createSuspenseQuery.createSuspenseQuery(options),
|
|
25
|
+
...createQuery.createQuery(options)
|
|
26
|
+
} : {
|
|
27
|
+
useInfiniteQuery: createInfiniteQuery.createInfiniteQuery(options),
|
|
28
|
+
useSuspenseInfiniteQuery: createSuspenseInfiniteQuery.createSuspenseInfiniteQuery(options),
|
|
29
|
+
...createInfiniteQuery.createInfiniteQuery(options)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
28
33
|
return acc;
|
|
29
34
|
}, {
|
|
30
|
-
getKey: () =>
|
|
35
|
+
getKey: () => keys
|
|
31
36
|
});
|
|
32
37
|
};
|
|
33
38
|
|
|
39
|
+
const router = (scope, config) => {
|
|
40
|
+
return buildRouter([scope], config);
|
|
41
|
+
};
|
|
42
|
+
|
|
34
43
|
router.query = options => {
|
|
35
44
|
return { ...options,
|
|
36
45
|
_type: 'q'
|
package/build/lib/router.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.js","sources":["../../src/router.ts"],"sourcesContent":["import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\
|
|
1
|
+
{"version":3,"file":"router.js","sources":["../../src/router.ts"],"sourcesContent":["import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nconst buildRouter = (keys: string[], config: RouterConfig) => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n if (!opts._type) {\n acc[key] = buildRouter([...keys, key], opts)\n } else {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [...keys, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n }\n\n return acc\n },\n {\n getKey: () => keys,\n } as any\n )\n}\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return buildRouter([scope], config)\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["buildRouter","keys","config","Object","entries","reduce","acc","key","opts","_type","options","useMutation","createMutation","useQuery","createQuery","useSuspenseQuery","createSuspenseQuery","useInfiniteQuery","createInfiniteQuery","useSuspenseInfiniteQuery","createSuspenseInfiniteQuery","getKey","router","scope","query","infiniteQuery","mutation"],"mappings":";;;;;;;;;;AAiBA,MAAMA,WAAW,GAAG,CAACC,IAAD,EAAiBC,MAAjB,KAA0C;AAC5D,EAAA,OAAOC,MAAM,CAACC,OAAP,CAAeF,MAAf,EAAuBG,MAAvB,CACL,CAACC,GAAD,EAAM,CAACC,GAAD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CAAlB,CAAA;AACD,EALM;;AAOPoB,MAAM,CAACE,KAAP,GACEd,OADa,IAEgC;EAC7C,OAAO,EACL,GAAGA,OADE;AAELD,IAAAA,KAAK,EAAE,GAAA;GAFT,CAAA;AAID,CAPD,CAAA;;AASAa,MAAM,CAACG,aAAP,GAMEf,OANqB,IAU4C;EACjE,OAAO,EAAE,GAAGA,OAAL;AAAcD,IAAAA,KAAK,EAAE,KAAA;GAA5B,CAAA;AACD,CAZD,CAAA;;AAcAa,MAAM,CAACI,QAAP,GAMEhB,OANgB,IAU0C;EAC1D,OAAO,EAAE,GAAGA,OAAL;AAAcD,IAAAA,KAAK,EAAE,GAAA;GAA5B,CAAA;AACD,CAZD;;;;"}
|
package/build/lib/router.mjs
CHANGED
|
@@ -4,29 +4,38 @@ import { createQuery } from './createQuery.mjs';
|
|
|
4
4
|
import { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery.mjs';
|
|
5
5
|
import { createSuspenseQuery } from './createSuspenseQuery.mjs';
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const buildRouter = (keys, config) => {
|
|
8
8
|
return Object.entries(config).reduce((acc, [key, opts]) => {
|
|
9
|
-
|
|
10
|
-
[
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
9
|
+
if (!opts._type) {
|
|
10
|
+
acc[key] = buildRouter([...keys, key], opts);
|
|
11
|
+
} else {
|
|
12
|
+
const options = { ...opts,
|
|
13
|
+
[opts._type === "m" ? "mutationKey" : "queryKey"]: [...keys, key]
|
|
14
|
+
};
|
|
15
|
+
acc[key] = opts._type === "m" ? {
|
|
16
|
+
useMutation: createMutation(options),
|
|
17
|
+
...createMutation(options)
|
|
18
|
+
} : opts._type === "q" ? {
|
|
19
|
+
useQuery: createQuery(options),
|
|
20
|
+
useSuspenseQuery: createSuspenseQuery(options),
|
|
21
|
+
...createQuery(options)
|
|
22
|
+
} : {
|
|
23
|
+
useInfiniteQuery: createInfiniteQuery(options),
|
|
24
|
+
useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),
|
|
25
|
+
...createInfiniteQuery(options)
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
24
29
|
return acc;
|
|
25
30
|
}, {
|
|
26
|
-
getKey: () =>
|
|
31
|
+
getKey: () => keys
|
|
27
32
|
});
|
|
28
33
|
};
|
|
29
34
|
|
|
35
|
+
const router = (scope, config) => {
|
|
36
|
+
return buildRouter([scope], config);
|
|
37
|
+
};
|
|
38
|
+
|
|
30
39
|
router.query = options => {
|
|
31
40
|
return { ...options,
|
|
32
41
|
_type: 'q'
|
package/build/lib/router.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router.mjs","sources":["../../src/router.ts"],"sourcesContent":["import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\
|
|
1
|
+
{"version":3,"file":"router.mjs","sources":["../../src/router.ts"],"sourcesContent":["import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nconst buildRouter = (keys: string[], config: RouterConfig) => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n if (!opts._type) {\n acc[key] = buildRouter([...keys, key], opts)\n } else {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [...keys, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n }\n\n return acc\n },\n {\n getKey: () => keys,\n } as any\n )\n}\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return buildRouter([scope], config)\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["buildRouter","keys","config","Object","entries","reduce","acc","key","opts","_type","options","useMutation","createMutation","useQuery","createQuery","useSuspenseQuery","createSuspenseQuery","useInfiniteQuery","createInfiniteQuery","useSuspenseIn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D,GA9BI,EA+BL;AACEe,IAAAA,MAAM,EAAE,MAAMpB,IAAAA;AADhB,GA/BK,CAAP,CAAA;AAmCD,CApCD,CAAA;;MAsCaqB,MAAM,GAAG,CACpBC,KADoB,EAEpBrB,MAFoB,KAGM;AAC1B,EAAA,OAAOF,WAAW,CAAC,CAACuB,KAAD,CAAD,EAAUrB,MAAV,CAAlB,CAAA;AACD,EALM;;AAOPoB,MAAM,CAACE,KAAP,GACEd,OADa,IAEgC;EAC7C,OAAO,EACL,GAAGA,OADE;AAELD,IAAAA,KAAK,EAAE,GAAA;GAFT,CAAA;AAID,CAPD,CAAA;;AASAa,MAAM,CAACG,aAAP,GAMEf,OANqB,IAU4C;EACjE,OAAO,EAAE,GAAGA,OAAL;AAAcD,IAAAA,KAAK,EAAE,KAAA;GAA5B,CAAA;AACD,CAZD,CAAA;;AAcAa,MAAM,CAACI,QAAP,GAMEhB,OANgB,IAU0C;EAC1D,OAAO,EAAE,GAAGA,OAAL;AAAcD,IAAAA,KAAK,EAAE,GAAA;GAA5B,CAAA;AACD,CAZD;;;;"}
|
package/build/lib/types.d.ts
CHANGED
|
@@ -136,7 +136,7 @@ export type RouterMutation<TData = unknown, TVariables = void, TError = Compatib
|
|
|
136
136
|
_type: `m`;
|
|
137
137
|
};
|
|
138
138
|
type DefaultTo<T, D> = unknown extends T ? D : T;
|
|
139
|
-
export type RouterConfig = Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any
|
|
139
|
+
export type RouterConfig = Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any> | Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any> | Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any> | Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any> | Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any> | Record<string, RouterQuery<any, any, any> | RouterInfiniteQuery<any, any, any, any> | RouterMutation<any, any, any, any>>>>>>>;
|
|
140
140
|
export type CreateRouter<TConfig extends RouterConfig> = {
|
|
141
141
|
[K in keyof TConfig]: TConfig[K] extends RouterMutation<infer TFnData, infer TVariables, infer TError, infer TContext> ? {
|
|
142
142
|
useMutation: MutationHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TContext>;
|
|
@@ -146,7 +146,7 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
146
146
|
} & ExposeMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, DefaultTo<TPageParam, number>> : TConfig[K] extends Omit<RouterQuery<infer TFnData, infer TVariables, infer TError>, 'queryKey'> ? {
|
|
147
147
|
useQuery: QueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>>;
|
|
148
148
|
useSuspenseQuery: SuspenseQueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>>;
|
|
149
|
-
} & ExposeMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>> : never;
|
|
149
|
+
} & ExposeMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>> : TConfig[K] extends RouterConfig ? CreateRouter<TConfig[K]> : never;
|
|
150
150
|
} & {
|
|
151
151
|
getKey: () => [string];
|
|
152
152
|
};
|
package/build/lib/utils.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ const isV5 = !!ReactQuery.useSuspenseQuery;
|
|
|
5
5
|
const suspenseOptions = {
|
|
6
6
|
enabled: true,
|
|
7
7
|
suspense: true,
|
|
8
|
-
useErrorBoundary: (_error, query) => query.state.data === undefined
|
|
8
|
+
useErrorBoundary: (_error, query) => typeof query.state.data === 'undefined'
|
|
9
9
|
};
|
|
10
10
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
11
11
|
return function useMiddleware(options, queryClient) {
|
|
@@ -16,12 +16,12 @@ const withMiddleware = (hook, defaultOptions, type) => {
|
|
|
16
16
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
17
17
|
...o2
|
|
18
18
|
}], [[]]);
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
const composedHook = uses.reduceRight((next, use) => use(next), hook);
|
|
20
|
+
return composedHook(opts, queryClient);
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
const getKey = (queryKey, variables) => {
|
|
24
|
-
return variables === undefined ?
|
|
24
|
+
return typeof variables === 'undefined' ? queryKey : [...queryKey, variables];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export { ReactQuery, getKey, isV5, suspenseOptions, withMiddleware };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n typeof query.state.data === 'undefined',\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composedHook = uses.reduceRight((next, use) => use(next), hook)\n\n return composedHook(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return typeof variables === 'undefined' ? queryKey : [...queryKey, variables]\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composedHook","reduceRight","next","getKey","queryKey","variables"],"mappings":";;AAKO,MAAMA,UAAU,GAAGC,mBAAnB;MAEMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,iBAA1B;AAEA,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;AAG7BC,EAAAA,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChB,OAAOA,KAAK,CAACC,KA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abled: true,
|
|
31
31
|
suspense: true,
|
|
32
|
-
useErrorBoundary: (_error, query) => query.state.data === undefined
|
|
32
|
+
useErrorBoundary: (_error, query) => typeof query.state.data === 'undefined'
|
|
33
33
|
};
|
|
34
34
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
35
35
|
return function useMiddleware(options, queryClient) {
|
|
@@ -40,12 +40,12 @@ const withMiddleware = (hook, defaultOptions, type) => {
|
|
|
40
40
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
41
41
|
...o2
|
|
42
42
|
}], [[]]);
|
|
43
|
-
const
|
|
44
|
-
return
|
|
43
|
+
const composedHook = uses.reduceRight((next, use) => use(next), hook);
|
|
44
|
+
return composedHook(opts, queryClient);
|
|
45
45
|
};
|
|
46
46
|
};
|
|
47
47
|
const getKey = (queryKey, variables) => {
|
|
48
|
-
return variables === undefined ?
|
|
48
|
+
return typeof variables === 'undefined' ? queryKey : [...queryKey, variables];
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
exports.ReactQuery = ReactQuery;
|
package/build/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n typeof query.state.data === 'undefined',\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composedHook = uses.reduceRight((next, use) => use(next), hook)\n\n return composedHook(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return typeof variables === 'undefined' ? queryKey : [...queryKey, variables]\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composedHook","reduceRight","next","getKey","queryKey","variables"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAMA,UAAU,GAAGC,8BAAnB;MAEMC,IAAI,GAAG,CAAC,CAACF,UAAU,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mCD,QAAnC,GAA8C,CAAC,GAAGA,QAAJ,EAAcC,SAAd,CAArD,CAAA;AACD;;;;;;;;"}
|
package/build/lib/utils.mjs
CHANGED
|
@@ -5,7 +5,7 @@ const isV5 = !!ReactQuery.useSuspenseQuery;
|
|
|
5
5
|
const suspenseOptions = {
|
|
6
6
|
enabled: true,
|
|
7
7
|
suspense: true,
|
|
8
|
-
useErrorBoundary: (_error, query) => query.state.data === undefined
|
|
8
|
+
useErrorBoundary: (_error, query) => typeof query.state.data === 'undefined'
|
|
9
9
|
};
|
|
10
10
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
11
11
|
return function useMiddleware(options, queryClient) {
|
|
@@ -16,12 +16,12 @@ const withMiddleware = (hook, defaultOptions, type) => {
|
|
|
16
16
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
17
17
|
...o2
|
|
18
18
|
}], [[]]);
|
|
19
|
-
const
|
|
20
|
-
return
|
|
19
|
+
const composedHook = uses.reduceRight((next, use) => use(next), hook);
|
|
20
|
+
return composedHook(opts, queryClient);
|
|
21
21
|
};
|
|
22
22
|
};
|
|
23
23
|
const getKey = (queryKey, variables) => {
|
|
24
|
-
return variables === undefined ?
|
|
24
|
+
return typeof variables === 'undefined' ? queryKey : [...queryKey, variables];
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
export { ReactQuery, getKey, isV5, suspenseOptions, withMiddleware };
|
package/build/lib/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n typeof query.state.data === 'undefined',\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composedHook = uses.reduceRight((next, use) => use(next), hook)\n\n return composedHook(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return typeof variables === 'undefined' ? queryKey : [...queryKey, variables]\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composedHook","reduceRight","next","getKey","queryKey","variables"],"mappings":";;AAKO,MAAMA,UAAU,GAAGC,mBAAnB;MAEMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,iBAA1B;AAEA,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;AAG7BC,EAAAA,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChB,OAAOA,KAAK,CAACC,KAAN,CAAYC,IAAnB,KAA4B,WAAA;AAJD,EAAxB;AAOA,MAAMC,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;IACA,MAAM,CAACC,IAAD,EAAOC,IAAP,IAAoC,CACxCpB,UAAU,CAACqB,cAAX;IAEEnB,IAAI,GAAGgB,WAAH,GAAiBD,OAFvB,EAGEK,iBAHF,EAAA,CAGsBP,IAHtB,CADwC,EAKxCD,cALwC,EAMxCG,OANwC,CAAA,CAOxCM,MAPwC,CAQxC,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,CARJ,EAYxC,CAAC,EAAD,CAZwC,CAA1C,CAAA;AAcA,IAAA,MAAMC,YAAY,GAAGV,IAAI,CAACW,WAAL,CAAiB,CAACC,IAAD,EAAOL,GAAP,KAAeA,GAAG,CAACK,IAAD,CAAnC,EAA2ClB,IAA3C,CAArB,CAAA;AAEA,IAAA,OAAOgB,YAAY,CAACT,IAAD,EAAOF,WAAP,CAAnB,CAAA;GApBF,CAAA;AAsBD,EA3BM;MA6BMc,MAAM,GAAG,CAACC,QAAD,EAAqBC,SAArB,KAAmD;AACvE,EAAA,OAAO,OAAOA,SAAP,KAAqB,WAArB,GAAmCD,QAAnC,GAA8C,CAAC,GAAGA,QAAJ,EAAcC,SAAd,CAArD,CAAA;AACD;;;;"}
|
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":"4094-1","name":"utils.ts"},{"uid":"4094-3","name":"createBaseQuery.ts"},{"uid":"4094-5","name":"createQuery.ts"},{"uid":"4094-7","name":"createSuspenseQuery.ts"},{"uid":"4094-9","name":"createInfiniteQuery.ts"},{"uid":"4094-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"4094-13","name":"createMutation.ts"},{"uid":"4094-15","name":"router.ts"},{"uid":"4094-17","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"4094-1":{"renderedLength":894,"gzipLength":449,"brotliLength":0,"mainUid":"4094-0"},"4094-3":{"renderedLength":1162,"gzipLength":397,"brotliLength":0,"mainUid":"4094-2"},"4094-5":{"renderedLength":91,"gzipLength":87,"brotliLength":0,"mainUid":"4094-4"},"4094-7":{"renderedLength":179,"gzipLength":118,"brotliLength":0,"mainUid":"4094-6"},"4094-9":{"renderedLength":107,"gzipLength":97,"brotliLength":0,"mainUid":"4094-8"},"4094-11":{"renderedLength":203,"gzipLength":128,"brotliLength":0,"mainUid":"4094-10"},"4094-13":{"renderedLength":271,"gzipLength":168,"brotliLength":0,"mainUid":"4094-12"},"4094-15":{"renderedLength":1156,"gzipLength":389,"brotliLength":0,"mainUid":"4094-14"},"4094-17":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"4094-16"}},"nodeMetas":{"4094-0":{"id":"/src/utils.ts","moduleParts":{"zip.esm.js":"4094-1"},"imported":[{"uid":"4094-19"}],"importedBy":[{"uid":"4094-16"},{"uid":"4094-4"},{"uid":"4094-6"},{"uid":"4094-8"},{"uid":"4094-10"},{"uid":"4094-12"},{"uid":"4094-2"}]},"4094-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"zip.esm.js":"4094-3"},"imported":[{"uid":"4094-0"}],"importedBy":[{"uid":"4094-4"},{"uid":"4094-6"},{"uid":"4094-8"},{"uid":"4094-10"}]},"4094-4":{"id":"/src/createQuery.ts","moduleParts":{"zip.esm.js":"4094-5"},"imported":[{"uid":"4094-2"},{"uid":"4094-0"}],"importedBy":[{"uid":"4094-16"},{"uid":"4094-14"}]},"4094-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"zip.esm.js":"4094-7"},"imported":[{"uid":"4094-2"},{"uid":"4094-0"}],"importedBy":[{"uid":"4094-16"},{"uid":"4094-14"}]},"4094-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"zip.esm.js":"4094-9"},"imported":[{"uid":"4094-2"},{"uid":"4094-0"}],"importedBy":[{"uid":"4094-16"},{"uid":"4094-14"}]},"4094-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"zip.esm.js":"4094-11"},"imported":[{"uid":"4094-2"},{"uid":"4094-0"}],"importedBy":[{"uid":"4094-16"},{"uid":"4094-14"}]},"4094-12":{"id":"/src/createMutation.ts","moduleParts":{"zip.esm.js":"4094-13"},"imported":[{"uid":"4094-0"}],"importedBy":[{"uid":"4094-16"},{"uid":"4094-14"}]},"4094-14":{"id":"/src/router.ts","moduleParts":{"zip.esm.js":"4094-15"},"imported":[{"uid":"4094-8"},{"uid":"4094-12"},{"uid":"4094-4"},{"uid":"4094-10"},{"uid":"4094-6"}],"importedBy":[{"uid":"4094-16"}]},"4094-16":{"id":"/src/index.ts","moduleParts":{"zip.esm.js":"4094-17"},"imported":[{"uid":"4094-4"},{"uid":"4094-6"},{"uid":"4094-8"},{"uid":"4094-10"},{"uid":"4094-12"},{"uid":"4094-18"},{"uid":"4094-14"},{"uid":"4094-0"}],"importedBy":[],"isEntry":true},"4094-18":{"id":"/src/types.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"4094-16"}]},"4094-19":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"4094-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;
|