;
62 | }
63 |
64 | return withInitialQueriesWrapper;
65 | }
66 |
--------------------------------------------------------------------------------
/src/query-client.ts:
--------------------------------------------------------------------------------
1 | import { QueryClient } from 'react-query';
2 |
3 | export const queryClient = new QueryClient({
4 | defaultOptions: {
5 | queries: {
6 | cacheTime: 1000 * 60 * 60 * 12, // 12 hours
7 | notifyOnChangeProps: ['data', 'error'],
8 | },
9 | },
10 | });
11 |
--------------------------------------------------------------------------------
/src/utils.ts:
--------------------------------------------------------------------------------
1 | import { makeWeakCache } from './cache';
2 | import type { QueryKey } from 'react-query';
3 |
4 | const spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
5 |
6 | function getTag(value: any) {
7 | if (value == null) {
8 | return value === undefined ? '[object Undefined]' : '[object Null]';
9 | }
10 | return toString.call(value);
11 | }
12 |
13 | function isObjectLike(value: any) {
14 | return typeof value === 'object' && value !== null;
15 | }
16 |
17 | function isArguments(value: any) {
18 | return isObjectLike(value) && getTag(value) == '[object Arguments]';
19 | }
20 |
21 | function isFlattenable(value: any) {
22 | return (
23 | Array.isArray(value) ||
24 | isArguments(value) ||
25 | !!(spreadableSymbol && value && value[spreadableSymbol])
26 | );
27 | }
28 |
29 | export function makeQueryKey(key: QueryKey, param?: P): [QueryKey, P] | QueryKey {
30 | const flattenedKey = isFlattenable(key) ? (key as any).flat() : key;
31 | const flattenedParam = param ? (isFlattenable(param) ? (param as any).flat(100) : param) : null;
32 | return flattenedParam ? [flattenedKey, flattenedParam].flat(100) : flattenedKey;
33 | }
34 |
35 | export const queryKeyCache = makeWeakCache();
36 |
37 | export function makeMessage(message: string) {
38 | return `[jotai-query-toolkit] ${message}`;
39 | }
40 |
41 | export function makeError(message: string) {
42 | return new Error(makeMessage(message));
43 | }
44 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "target": "esnext",
4 | "strict": true,
5 | "jsx": "preserve",
6 | "allowSyntheticDefaultImports": true,
7 | "esModuleInterop": true,
8 | "skipLibCheck": true,
9 | "moduleResolution": "node",
10 | "baseUrl": ".",
11 | "paths": {
12 | "jotai-query-toolkit": ["./src"]
13 | }
14 | },
15 | "include": ["src/**/*", "tests/**/*"],
16 | "exclude": ["node_modules", "dist"]
17 | }
18 |
--------------------------------------------------------------------------------