@tanstack/solid-query 4.24.10 → 5.0.0-alpha.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/build/cjs/index.js +300 -0
- package/build/cjs/index.js.map +1 -0
- package/build/esm/index.js +285 -0
- package/build/esm/index.js.map +1 -0
- package/build/source/QueryClientProvider.jsx +21 -0
- package/build/source/__tests__/QueryClientProvider.test.jsx +120 -0
- package/build/{solid → source}/__tests__/createInfiniteQuery.test.jsx +228 -372
- package/build/{solid → source}/__tests__/createMutation.test.jsx +174 -165
- package/build/{solid → source}/__tests__/createQueries.test.jsx +86 -367
- package/build/{solid → source}/__tests__/createQuery.test.jsx +991 -943
- package/build/{solid → source}/__tests__/createQuery.types.test.jsx +35 -24
- package/build/{solid → source}/__tests__/suspense.test.jsx +177 -148
- package/build/{solid → source}/__tests__/transition.test.jsx +7 -4
- package/build/{solid → source}/__tests__/useIsFetching.test.jsx +68 -85
- package/build/{solid → source}/__tests__/useIsMutating.test.jsx +78 -93
- package/build/{solid → source}/__tests__/utils.jsx +3 -9
- package/build/source/createBaseQuery.js +147 -0
- package/build/source/createInfiniteQuery.js +8 -0
- package/build/{solid → source}/createMutation.js +7 -9
- package/build/source/createQueries.js +32 -0
- package/build/source/createQuery.js +6 -0
- package/build/{solid → source}/index.js +5 -3
- package/build/source/setBatchUpdatesFn.js +3 -0
- package/build/source/useIsFetching.js +12 -0
- package/build/source/useIsMutating.js +12 -0
- package/build/source/utils.js +7 -0
- package/build/types/QueryClientProvider.d.ts +9 -0
- package/build/{lib → types}/__tests__/utils.d.ts +3 -8
- package/build/types/createBaseQuery.d.ts +4 -0
- package/build/types/createInfiniteQuery.d.ts +3 -0
- package/build/types/createMutation.d.ts +3 -0
- package/build/{lib → types}/createQueries.d.ts +10 -8
- package/build/types/createQuery.d.ts +11 -0
- package/build/{lib → types}/index.d.ts +4 -3
- package/build/types/setBatchUpdatesFn.d.ts +1 -0
- package/build/types/types.d.ts +33 -0
- package/build/types/useIsFetching.d.ts +8 -0
- package/build/types/useIsMutating.d.ts +8 -0
- package/build/types/utils.d.ts +1 -0
- package/build/umd/index.js +2 -0
- package/build/umd/index.js.map +1 -0
- package/package.json +25 -17
- package/src/QueryClientProvider.tsx +17 -86
- package/src/__tests__/QueryClientProvider.test.tsx +37 -140
- package/src/__tests__/createInfiniteQuery.test.tsx +277 -508
- package/src/__tests__/createMutation.test.tsx +177 -225
- package/src/__tests__/createQueries.test.tsx +180 -528
- package/src/__tests__/createQuery.test.tsx +970 -1200
- package/src/__tests__/createQuery.types.test.tsx +30 -25
- package/src/__tests__/suspense.test.tsx +141 -178
- package/src/__tests__/transition.test.tsx +7 -4
- package/src/__tests__/useIsFetching.test.tsx +77 -122
- package/src/__tests__/useIsMutating.test.tsx +83 -128
- package/src/__tests__/utils.tsx +4 -11
- package/src/createBaseQuery.ts +148 -60
- package/src/createInfiniteQuery.ts +16 -94
- package/src/createMutation.ts +9 -63
- package/src/createQueries.ts +44 -55
- package/src/createQuery.ts +42 -127
- package/src/index.ts +6 -3
- package/src/setBatchUpdatesFn.ts +4 -0
- package/src/types.ts +81 -75
- package/src/useIsFetching.ts +12 -44
- package/src/useIsMutating.ts +13 -29
- package/src/utils.ts +5 -79
- package/build/lib/QueryClientProvider.d.ts +0 -24
- package/build/lib/QueryClientProvider.esm.js +0 -74
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.js +0 -80
- package/build/lib/QueryClientProvider.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -74
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/createBaseQuery.d.ts +0 -4
- package/build/lib/createBaseQuery.esm.js +0 -93
- package/build/lib/createBaseQuery.esm.js.map +0 -1
- package/build/lib/createBaseQuery.js +0 -97
- package/build/lib/createBaseQuery.js.map +0 -1
- package/build/lib/createBaseQuery.mjs +0 -93
- package/build/lib/createBaseQuery.mjs.map +0 -1
- package/build/lib/createInfiniteQuery.d.ts +0 -5
- package/build/lib/createInfiniteQuery.esm.js +0 -20
- package/build/lib/createInfiniteQuery.esm.js.map +0 -1
- package/build/lib/createInfiniteQuery.js +0 -24
- package/build/lib/createInfiniteQuery.js.map +0 -1
- package/build/lib/createInfiniteQuery.mjs +0 -20
- package/build/lib/createInfiniteQuery.mjs.map +0 -1
- package/build/lib/createMutation.d.ts +0 -6
- package/build/lib/createMutation.esm.js +0 -45
- package/build/lib/createMutation.esm.js.map +0 -1
- package/build/lib/createMutation.js +0 -49
- package/build/lib/createMutation.js.map +0 -1
- package/build/lib/createMutation.mjs +0 -45
- package/build/lib/createMutation.mjs.map +0 -1
- package/build/lib/createQueries.esm.js +0 -54
- package/build/lib/createQueries.esm.js.map +0 -1
- package/build/lib/createQueries.js +0 -58
- package/build/lib/createQueries.js.map +0 -1
- package/build/lib/createQueries.mjs +0 -54
- package/build/lib/createQueries.mjs.map +0 -1
- package/build/lib/createQuery.d.ts +0 -23
- package/build/lib/createQuery.esm.js +0 -25
- package/build/lib/createQuery.esm.js.map +0 -1
- package/build/lib/createQuery.js +0 -29
- package/build/lib/createQuery.js.map +0 -1
- package/build/lib/createQuery.mjs +0 -25
- package/build/lib/createQuery.mjs.map +0 -1
- package/build/lib/index.esm.js +0 -9
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.js +0 -31
- package/build/lib/index.js.map +0 -1
- package/build/lib/index.mjs +0 -9
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/types.d.ts +0 -47
- package/build/lib/useIsFetching.d.ts +0 -7
- package/build/lib/useIsFetching.esm.js +0 -29
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.js +0 -33
- package/build/lib/useIsFetching.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -29
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useIsMutating.d.ts +0 -8
- package/build/lib/useIsMutating.esm.js +0 -22
- package/build/lib/useIsMutating.esm.js.map +0 -1
- package/build/lib/useIsMutating.js +0 -26
- package/build/lib/useIsMutating.js.map +0 -1
- package/build/lib/useIsMutating.mjs +0 -22
- package/build/lib/useIsMutating.mjs.map +0 -1
- package/build/lib/utils.d.ts +0 -14
- package/build/lib/utils.esm.js +0 -63
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.js +0 -72
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.mjs +0 -63
- package/build/lib/utils.mjs.map +0 -1
- package/build/solid/QueryClientProvider.jsx +0 -49
- package/build/solid/__tests__/QueryClientProvider.test.jsx +0 -185
- package/build/solid/createBaseQuery.js +0 -81
- package/build/solid/createInfiniteQuery.js +0 -16
- package/build/solid/createQueries.js +0 -39
- package/build/solid/createQuery.js +0 -16
- package/build/solid/useIsFetching.js +0 -23
- package/build/solid/useIsMutating.js +0 -16
- package/build/solid/utils.js +0 -45
- package/build/umd/index.development.js +0 -3577
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
- /package/build/{solid → source}/types.js +0 -0
- /package/build/{lib → types}/__tests__/QueryClientProvider.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/createInfiniteQuery.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/createMutation.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/createQueries.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/createQuery.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/createQuery.types.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/suspense.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/transition.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/useIsFetching.test.d.ts +0 -0
- /package/build/{lib → types}/__tests__/useIsMutating.test.d.ts +0 -0
package/build/lib/utils.d.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { SolidQueryKey, SolidQueryFilters, ParseFilterArgs, ParseQueryArgs } from './types';
|
|
2
|
-
import type { QueryFunction, QueryOptions } from '@tanstack/query-core';
|
|
3
|
-
export declare function isQueryKey(value: unknown): value is SolidQueryKey;
|
|
4
|
-
export declare function parseQueryArgs<TOptions extends Omit<QueryOptions<any, any, any, ReturnType<TQueryKey>>, 'queryKey'> & {
|
|
5
|
-
queryKey?: TQueryKey;
|
|
6
|
-
}, TQueryKey extends () => readonly unknown[] = SolidQueryKey>(arg1: TQueryKey | TOptions, arg2?: QueryFunction<any, ReturnType<TQueryKey>> | TOptions, arg3?: TOptions): ParseQueryArgs<TOptions, TQueryKey>;
|
|
7
|
-
export declare function parseFilterArgs<TFilters extends SolidQueryFilters, TOptions = unknown>(arg1?: SolidQueryKey | TFilters, arg2?: TFilters | TOptions, arg3?: TOptions): [ParseFilterArgs<TFilters>, TOptions | undefined];
|
|
8
|
-
export declare function shouldThrowError<T extends (...args: any[]) => boolean>(_useErrorBoundary: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
9
|
-
export declare function sleep(timeout: number): Promise<void>;
|
|
10
|
-
/**
|
|
11
|
-
* Schedules a microtask.
|
|
12
|
-
* This can be useful to schedule state updates after rendering.
|
|
13
|
-
*/
|
|
14
|
-
export declare function scheduleMicrotask(callback: () => void): void;
|
package/build/lib/utils.esm.js
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
function isQueryKey(value) {
|
|
2
|
-
return typeof value === 'function';
|
|
3
|
-
} // The parseQuery Args functions helps normalize the arguments into the correct form.
|
|
4
|
-
// Whatever the parameters are, they are normalized into the correct form.
|
|
5
|
-
|
|
6
|
-
function parseQueryArgs(arg1, arg2, arg3) {
|
|
7
|
-
if (!isQueryKey(arg1)) {
|
|
8
|
-
const {
|
|
9
|
-
queryKey: solidKey,
|
|
10
|
-
...opts
|
|
11
|
-
} = arg1;
|
|
12
|
-
|
|
13
|
-
if (solidKey) {
|
|
14
|
-
return { ...opts,
|
|
15
|
-
queryKey: solidKey()
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return arg1;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof arg2 === 'function') {
|
|
23
|
-
return { ...arg3,
|
|
24
|
-
queryKey: arg1(),
|
|
25
|
-
queryFn: arg2
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return { ...arg2,
|
|
30
|
-
queryKey: arg1()
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function parseFilterArgs(arg1, arg2, arg3) {
|
|
34
|
-
return isQueryKey(arg1) ? [{ ...arg2,
|
|
35
|
-
queryKey: arg1()
|
|
36
|
-
}, arg3] : [{ ...arg1,
|
|
37
|
-
queryKey: arg1 == null ? void 0 : arg1.queryKey == null ? void 0 : arg1.queryKey()
|
|
38
|
-
}, arg2];
|
|
39
|
-
}
|
|
40
|
-
function shouldThrowError(_useErrorBoundary, params) {
|
|
41
|
-
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
42
|
-
if (typeof _useErrorBoundary === 'function') {
|
|
43
|
-
return _useErrorBoundary(...params);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return !!_useErrorBoundary;
|
|
47
|
-
}
|
|
48
|
-
function sleep(timeout) {
|
|
49
|
-
return new Promise(resolve => {
|
|
50
|
-
setTimeout(resolve, timeout);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Schedules a microtask.
|
|
55
|
-
* This can be useful to schedule state updates after rendering.
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
function scheduleMicrotask(callback) {
|
|
59
|
-
sleep(0).then(callback);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { isQueryKey, parseFilterArgs, parseQueryArgs, scheduleMicrotask, shouldThrowError, sleep };
|
|
63
|
-
//# sourceMappingURL=utils.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import type {\n SolidQueryKey,\n SolidQueryFilters,\n ParseFilterArgs,\n ParseQueryArgs,\n} from './types'\nimport type { QueryFunction, QueryOptions } from '@tanstack/query-core'\n\nexport function isQueryKey(value: unknown): value is SolidQueryKey {\n return typeof value === 'function'\n}\n\n// The parseQuery Args functions helps normalize the arguments into the correct form.\n// Whatever the parameters are, they are normalized into the correct form.\nexport function parseQueryArgs<\n TOptions extends Omit<\n QueryOptions<any, any, any, ReturnType<TQueryKey>>,\n 'queryKey'\n > & {\n queryKey?: TQueryKey\n },\n TQueryKey extends () => readonly unknown[] = SolidQueryKey,\n>(\n arg1: TQueryKey | TOptions,\n arg2?: QueryFunction<any, ReturnType<TQueryKey>> | TOptions,\n arg3?: TOptions,\n): ParseQueryArgs<TOptions, TQueryKey> {\n if (!isQueryKey(arg1)) {\n const { queryKey: solidKey, ...opts } = arg1 as any\n if (solidKey) {\n return {\n ...opts,\n queryKey: solidKey(),\n }\n }\n return arg1 as any\n }\n\n if (typeof arg2 === 'function') {\n return { ...arg3, queryKey: arg1(), queryFn: arg2 } as any\n }\n\n return { ...arg2, queryKey: arg1() } as any\n}\n\nexport function parseFilterArgs<\n TFilters extends SolidQueryFilters,\n TOptions = unknown,\n>(\n arg1?: SolidQueryKey | TFilters,\n arg2?: TFilters | TOptions,\n arg3?: TOptions,\n): [ParseFilterArgs<TFilters>, TOptions | undefined] {\n return (\n isQueryKey(arg1)\n ? [{ ...arg2, queryKey: arg1() }, arg3]\n : [{ ...arg1, queryKey: arg1?.queryKey?.() }, arg2]\n ) as [ParseFilterArgs<TFilters>, TOptions]\n}\n\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n _useErrorBoundary: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow useErrorBoundary function to override throwing behavior on a per-error basis\n if (typeof _useErrorBoundary === 'function') {\n return _useErrorBoundary(...params)\n }\n\n return !!_useErrorBoundary\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n"],"names":["isQueryKey","value","parseQueryArgs","arg1","arg2","arg3","queryKey","solidKey","opts","queryFn","parseFilterArgs","shouldThrowError","_useErrorBoundary","params","sleep","timeout","Promise","resolve","setTimeout","scheduleMicrotask","callback","then"],"mappings":"AAQO,SAASA,UAAT,CAAoBC,KAApB,EAA4D;EACjE,OAAO,OAAOA,KAAP,KAAiB,UAAxB,CAAA;AACD;AAGD;;AACO,SAASC,cAAT,CASLC,IATK,EAULC,IAVK,EAWLC,IAXK,EAYgC;AACrC,EAAA,IAAI,CAACL,UAAU,CAACG,IAAD,CAAf,EAAuB;IACrB,MAAM;AAAEG,MAAAA,QAAQ,EAAEC,QAAZ;MAAsB,GAAGC,IAAAA;AAAzB,KAAA,GAAkCL,IAAxC,CAAA;;AACA,IAAA,IAAII,QAAJ,EAAc;MACZ,OAAO,EACL,GAAGC,IADE;AAELF,QAAAA,QAAQ,EAAEC,QAAQ,EAAA;OAFpB,CAAA;AAID,KAAA;;AACD,IAAA,OAAOJ,IAAP,CAAA;AACD,GAAA;;AAED,EAAA,IAAI,OAAOC,IAAP,KAAgB,UAApB,EAAgC;IAC9B,OAAO,EAAE,GAAGC,IAAL;MAAWC,QAAQ,EAAEH,IAAI,EAAzB;AAA6BM,MAAAA,OAAO,EAAEL,IAAAA;KAA7C,CAAA;AACD,GAAA;;EAED,OAAO,EAAE,GAAGA,IAAL;AAAWE,IAAAA,QAAQ,EAAEH,IAAI,EAAA;GAAhC,CAAA;AACD,CAAA;AAEM,SAASO,eAAT,CAILP,IAJK,EAKLC,IALK,EAMLC,IANK,EAO8C;EACnD,OACEL,UAAU,CAACG,IAAD,CAAV,GACI,CAAC,EAAE,GAAGC,IAAL;AAAWE,IAAAA,QAAQ,EAAEH,IAAI,EAAA;AAAzB,GAAD,EAAgCE,IAAhC,CADJ,GAEI,CAAC,EAAE,GAAGF,IAAL;IAAWG,QAAQ,EAAEH,IAAF,IAAEA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,IAAI,CAAEG,QAAR,IAAA,IAAA,GAAA,KAAA,CAAA,GAAEH,IAAI,CAAEG,QAAN,EAAA;GAAtB,EAA4CF,IAA5C,CAHN,CAAA;AAKD,CAAA;AAEM,SAASO,gBAAT,CACLC,iBADK,EAELC,MAFK,EAGI;AACT;AACA,EAAA,IAAI,OAAOD,iBAAP,KAA6B,UAAjC,EAA6C;AAC3C,IAAA,OAAOA,iBAAiB,CAAC,GAAGC,MAAJ,CAAxB,CAAA;AACD,GAAA;;EAED,OAAO,CAAC,CAACD,iBAAT,CAAA;AACD,CAAA;AAEM,SAASE,KAAT,CAAeC,OAAf,EAA+C;AACpD,EAAA,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;AAC9BC,IAAAA,UAAU,CAACD,OAAD,EAAUF,OAAV,CAAV,CAAA;AACD,GAFM,CAAP,CAAA;AAGD,CAAA;AAED;AACA;AACA;AACA;;AACO,SAASI,iBAAT,CAA2BC,QAA3B,EAAiD;AACtDN,EAAAA,KAAK,CAAC,CAAD,CAAL,CAASO,IAAT,CAAcD,QAAd,CAAA,CAAA;AACD;;;;"}
|
package/build/lib/utils.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
function isQueryKey(value) {
|
|
6
|
-
return typeof value === 'function';
|
|
7
|
-
} // The parseQuery Args functions helps normalize the arguments into the correct form.
|
|
8
|
-
// Whatever the parameters are, they are normalized into the correct form.
|
|
9
|
-
|
|
10
|
-
function parseQueryArgs(arg1, arg2, arg3) {
|
|
11
|
-
if (!isQueryKey(arg1)) {
|
|
12
|
-
const {
|
|
13
|
-
queryKey: solidKey,
|
|
14
|
-
...opts
|
|
15
|
-
} = arg1;
|
|
16
|
-
|
|
17
|
-
if (solidKey) {
|
|
18
|
-
return { ...opts,
|
|
19
|
-
queryKey: solidKey()
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return arg1;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (typeof arg2 === 'function') {
|
|
27
|
-
return { ...arg3,
|
|
28
|
-
queryKey: arg1(),
|
|
29
|
-
queryFn: arg2
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return { ...arg2,
|
|
34
|
-
queryKey: arg1()
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
function parseFilterArgs(arg1, arg2, arg3) {
|
|
38
|
-
return isQueryKey(arg1) ? [{ ...arg2,
|
|
39
|
-
queryKey: arg1()
|
|
40
|
-
}, arg3] : [{ ...arg1,
|
|
41
|
-
queryKey: arg1 == null ? void 0 : arg1.queryKey == null ? void 0 : arg1.queryKey()
|
|
42
|
-
}, arg2];
|
|
43
|
-
}
|
|
44
|
-
function shouldThrowError(_useErrorBoundary, params) {
|
|
45
|
-
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
46
|
-
if (typeof _useErrorBoundary === 'function') {
|
|
47
|
-
return _useErrorBoundary(...params);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return !!_useErrorBoundary;
|
|
51
|
-
}
|
|
52
|
-
function sleep(timeout) {
|
|
53
|
-
return new Promise(resolve => {
|
|
54
|
-
setTimeout(resolve, timeout);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Schedules a microtask.
|
|
59
|
-
* This can be useful to schedule state updates after rendering.
|
|
60
|
-
*/
|
|
61
|
-
|
|
62
|
-
function scheduleMicrotask(callback) {
|
|
63
|
-
sleep(0).then(callback);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
exports.isQueryKey = isQueryKey;
|
|
67
|
-
exports.parseFilterArgs = parseFilterArgs;
|
|
68
|
-
exports.parseQueryArgs = parseQueryArgs;
|
|
69
|
-
exports.scheduleMicrotask = scheduleMicrotask;
|
|
70
|
-
exports.shouldThrowError = shouldThrowError;
|
|
71
|
-
exports.sleep = sleep;
|
|
72
|
-
//# sourceMappingURL=utils.js.map
|
package/build/lib/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import type {\n SolidQueryKey,\n SolidQueryFilters,\n ParseFilterArgs,\n ParseQueryArgs,\n} from './types'\nimport type { QueryFunction, QueryOptions } from '@tanstack/query-core'\n\nexport function isQueryKey(value: unknown): value is SolidQueryKey {\n return typeof value === 'function'\n}\n\n// The parseQuery Args functions helps normalize the arguments into the correct form.\n// Whatever the parameters are, they are normalized into the correct form.\nexport function parseQueryArgs<\n TOptions extends Omit<\n QueryOptions<any, any, any, ReturnType<TQueryKey>>,\n 'queryKey'\n > & {\n queryKey?: TQueryKey\n },\n TQueryKey extends () => readonly unknown[] = SolidQueryKey,\n>(\n arg1: TQueryKey | TOptions,\n arg2?: QueryFunction<any, ReturnType<TQueryKey>> | TOptions,\n arg3?: TOptions,\n): ParseQueryArgs<TOptions, TQueryKey> {\n if (!isQueryKey(arg1)) {\n const { queryKey: solidKey, ...opts } = arg1 as any\n if (solidKey) {\n return {\n ...opts,\n queryKey: solidKey(),\n }\n }\n return arg1 as any\n }\n\n if (typeof arg2 === 'function') {\n return { ...arg3, queryKey: arg1(), queryFn: arg2 } as any\n }\n\n return { ...arg2, queryKey: arg1() } as any\n}\n\nexport function parseFilterArgs<\n TFilters extends SolidQueryFilters,\n TOptions = unknown,\n>(\n arg1?: SolidQueryKey | TFilters,\n arg2?: TFilters | TOptions,\n arg3?: TOptions,\n): [ParseFilterArgs<TFilters>, TOptions | undefined] {\n return (\n isQueryKey(arg1)\n ? [{ ...arg2, queryKey: arg1() }, arg3]\n : [{ ...arg1, queryKey: arg1?.queryKey?.() }, arg2]\n ) as [ParseFilterArgs<TFilters>, TOptions]\n}\n\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n _useErrorBoundary: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow useErrorBoundary function to override throwing behavior on a per-error basis\n if (typeof _useErrorBoundary === 'function') {\n return _useErrorBoundary(...params)\n }\n\n return !!_useErrorBoundary\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n"],"names":["isQueryKey","value","parseQueryArgs","arg1","arg2","arg3","queryKey","solidKey","opts","queryFn","parseFilterArgs","shouldThrowError","_useErrorBoundary","params","sleep","timeout","Promise","resolve","setTimeout","scheduleMicrotask","callback","then"],"mappings":";;;;AAQO,SAASA,UAAT,CAAoBC,KAApB,EAA4D;EACjE,OAAO,OAAOA,KAAP,KAAiB,UAAxB,CAAA;AACD;AAGD;;AACO,SAASC,cAAT,CASLC,IATK,EAULC,IAVK,EAWLC,IAXK,EAYgC;AACrC,EAAA,IAAI,CAACL,UAAU,CAACG,IAAD,CAAf,EAAuB;IACrB,MAAM;AAAEG,MAAAA,QAAQ,EAAEC,QAAZ;MAAsB,GAAGC,IAAAA;AAAzB,KAAA,GAAkCL,IAAxC,CAAA;;AACA,IAAA,IAAII,QAAJ,EAAc;MACZ,OAAO,EACL,GAAGC,IADE;AAELF,QAAAA,QAAQ,EAAEC,QAAQ,EAAA;OAFpB,CAAA;AAID,KAAA;;AACD,IAAA,OAAOJ,IAAP,CAAA;AACD,GAAA;;AAED,EAAA,IAAI,OAAOC,IAAP,KAAgB,UAApB,EAAgC;IAC9B,OAAO,EAAE,GAAGC,IAAL;MAAWC,QAAQ,EAAEH,IAAI,EAAzB;AAA6BM,MAAAA,OAAO,EAAEL,IAAAA;KAA7C,CAAA;AACD,GAAA;;EAED,OAAO,EAAE,GAAGA,IAAL;AAAWE,IAAAA,QAAQ,EAAEH,IAAI,EAAA;GAAhC,CAAA;AACD,CAAA;AAEM,SAASO,eAAT,CAILP,IAJK,EAKLC,IALK,EAMLC,IANK,EAO8C;EACnD,OACEL,UAAU,CAACG,IAAD,CAAV,GACI,CAAC,EAAE,GAAGC,IAAL;AAAWE,IAAAA,QAAQ,EAAEH,IAAI,EAAA;AAAzB,GAAD,EAAgCE,IAAhC,CADJ,GAEI,CAAC,EAAE,GAAGF,IAAL;IAAWG,QAAQ,EAAEH,IAAF,IAAEA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,IAAI,CAAEG,QAAR,IAAA,IAAA,GAAA,KAAA,CAAA,GAAEH,IAAI,CAAEG,QAAN,EAAA;GAAtB,EAA4CF,IAA5C,CAHN,CAAA;AAKD,CAAA;AAEM,SAASO,gBAAT,CACLC,iBADK,EAELC,MAFK,EAGI;AACT;AACA,EAAA,IAAI,OAAOD,iBAAP,KAA6B,UAAjC,EAA6C;AAC3C,IAAA,OAAOA,iBAAiB,CAAC,GAAGC,MAAJ,CAAxB,CAAA;AACD,GAAA;;EAED,OAAO,CAAC,CAACD,iBAAT,CAAA;AACD,CAAA;AAEM,SAASE,KAAT,CAAeC,OAAf,EAA+C;AACpD,EAAA,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;AAC9BC,IAAAA,UAAU,CAACD,OAAD,EAAUF,OAAV,CAAV,CAAA;AACD,GAFM,CAAP,CAAA;AAGD,CAAA;AAED;AACA;AACA;AACA;;AACO,SAASI,iBAAT,CAA2BC,QAA3B,EAAiD;AACtDN,EAAAA,KAAK,CAAC,CAAD,CAAL,CAASO,IAAT,CAAcD,QAAd,CAAA,CAAA;AACD;;;;;;;;;"}
|
package/build/lib/utils.mjs
DELETED
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
function isQueryKey(value) {
|
|
2
|
-
return typeof value === 'function';
|
|
3
|
-
} // The parseQuery Args functions helps normalize the arguments into the correct form.
|
|
4
|
-
// Whatever the parameters are, they are normalized into the correct form.
|
|
5
|
-
|
|
6
|
-
function parseQueryArgs(arg1, arg2, arg3) {
|
|
7
|
-
if (!isQueryKey(arg1)) {
|
|
8
|
-
const {
|
|
9
|
-
queryKey: solidKey,
|
|
10
|
-
...opts
|
|
11
|
-
} = arg1;
|
|
12
|
-
|
|
13
|
-
if (solidKey) {
|
|
14
|
-
return { ...opts,
|
|
15
|
-
queryKey: solidKey()
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return arg1;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
if (typeof arg2 === 'function') {
|
|
23
|
-
return { ...arg3,
|
|
24
|
-
queryKey: arg1(),
|
|
25
|
-
queryFn: arg2
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return { ...arg2,
|
|
30
|
-
queryKey: arg1()
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
function parseFilterArgs(arg1, arg2, arg3) {
|
|
34
|
-
return isQueryKey(arg1) ? [{ ...arg2,
|
|
35
|
-
queryKey: arg1()
|
|
36
|
-
}, arg3] : [{ ...arg1,
|
|
37
|
-
queryKey: arg1 == null ? void 0 : arg1.queryKey == null ? void 0 : arg1.queryKey()
|
|
38
|
-
}, arg2];
|
|
39
|
-
}
|
|
40
|
-
function shouldThrowError(_useErrorBoundary, params) {
|
|
41
|
-
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
42
|
-
if (typeof _useErrorBoundary === 'function') {
|
|
43
|
-
return _useErrorBoundary(...params);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return !!_useErrorBoundary;
|
|
47
|
-
}
|
|
48
|
-
function sleep(timeout) {
|
|
49
|
-
return new Promise(resolve => {
|
|
50
|
-
setTimeout(resolve, timeout);
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Schedules a microtask.
|
|
55
|
-
* This can be useful to schedule state updates after rendering.
|
|
56
|
-
*/
|
|
57
|
-
|
|
58
|
-
function scheduleMicrotask(callback) {
|
|
59
|
-
sleep(0).then(callback);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export { isQueryKey, parseFilterArgs, parseQueryArgs, scheduleMicrotask, shouldThrowError, sleep };
|
|
63
|
-
//# sourceMappingURL=utils.mjs.map
|
package/build/lib/utils.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import type {\n SolidQueryKey,\n SolidQueryFilters,\n ParseFilterArgs,\n ParseQueryArgs,\n} from './types'\nimport type { QueryFunction, QueryOptions } from '@tanstack/query-core'\n\nexport function isQueryKey(value: unknown): value is SolidQueryKey {\n return typeof value === 'function'\n}\n\n// The parseQuery Args functions helps normalize the arguments into the correct form.\n// Whatever the parameters are, they are normalized into the correct form.\nexport function parseQueryArgs<\n TOptions extends Omit<\n QueryOptions<any, any, any, ReturnType<TQueryKey>>,\n 'queryKey'\n > & {\n queryKey?: TQueryKey\n },\n TQueryKey extends () => readonly unknown[] = SolidQueryKey,\n>(\n arg1: TQueryKey | TOptions,\n arg2?: QueryFunction<any, ReturnType<TQueryKey>> | TOptions,\n arg3?: TOptions,\n): ParseQueryArgs<TOptions, TQueryKey> {\n if (!isQueryKey(arg1)) {\n const { queryKey: solidKey, ...opts } = arg1 as any\n if (solidKey) {\n return {\n ...opts,\n queryKey: solidKey(),\n }\n }\n return arg1 as any\n }\n\n if (typeof arg2 === 'function') {\n return { ...arg3, queryKey: arg1(), queryFn: arg2 } as any\n }\n\n return { ...arg2, queryKey: arg1() } as any\n}\n\nexport function parseFilterArgs<\n TFilters extends SolidQueryFilters,\n TOptions = unknown,\n>(\n arg1?: SolidQueryKey | TFilters,\n arg2?: TFilters | TOptions,\n arg3?: TOptions,\n): [ParseFilterArgs<TFilters>, TOptions | undefined] {\n return (\n isQueryKey(arg1)\n ? [{ ...arg2, queryKey: arg1() }, arg3]\n : [{ ...arg1, queryKey: arg1?.queryKey?.() }, arg2]\n ) as [ParseFilterArgs<TFilters>, TOptions]\n}\n\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n _useErrorBoundary: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow useErrorBoundary function to override throwing behavior on a per-error basis\n if (typeof _useErrorBoundary === 'function') {\n return _useErrorBoundary(...params)\n }\n\n return !!_useErrorBoundary\n}\n\nexport function sleep(timeout: number): Promise<void> {\n return new Promise((resolve) => {\n setTimeout(resolve, timeout)\n })\n}\n\n/**\n * Schedules a microtask.\n * This can be useful to schedule state updates after rendering.\n */\nexport function scheduleMicrotask(callback: () => void) {\n sleep(0).then(callback)\n}\n"],"names":["isQueryKey","value","parseQueryArgs","arg1","arg2","arg3","queryKey","solidKey","opts","queryFn","parseFilterArgs","shouldThrowError","_useErrorBoundary","params","sleep","timeout","Promise","resolve","setTimeout","scheduleMicrotask","callback","then"],"mappings":"AAQO,SAASA,UAAT,CAAoBC,KAApB,EAA4D;EACjE,OAAO,OAAOA,KAAP,KAAiB,UAAxB,CAAA;AACD;AAGD;;AACO,SAASC,cAAT,CASLC,IATK,EAULC,IAVK,EAWLC,IAXK,EAYgC;AACrC,EAAA,IAAI,CAACL,UAAU,CAACG,IAAD,CAAf,EAAuB;IACrB,MAAM;AAAEG,MAAAA,QAAQ,EAAEC,QAAZ;MAAsB,GAAGC,IAAAA;AAAzB,KAAA,GAAkCL,IAAxC,CAAA;;AACA,IAAA,IAAII,QAAJ,EAAc;MACZ,OAAO,EACL,GAAGC,IADE;AAELF,QAAAA,QAAQ,EAAEC,QAAQ,EAAA;OAFpB,CAAA;AAID,KAAA;;AACD,IAAA,OAAOJ,IAAP,CAAA;AACD,GAAA;;AAED,EAAA,IAAI,OAAOC,IAAP,KAAgB,UAApB,EAAgC;IAC9B,OAAO,EAAE,GAAGC,IAAL;MAAWC,QAAQ,EAAEH,IAAI,EAAzB;AAA6BM,MAAAA,OAAO,EAAEL,IAAAA;KAA7C,CAAA;AACD,GAAA;;EAED,OAAO,EAAE,GAAGA,IAAL;AAAWE,IAAAA,QAAQ,EAAEH,IAAI,EAAA;GAAhC,CAAA;AACD,CAAA;AAEM,SAASO,eAAT,CAILP,IAJK,EAKLC,IALK,EAMLC,IANK,EAO8C;EACnD,OACEL,UAAU,CAACG,IAAD,CAAV,GACI,CAAC,EAAE,GAAGC,IAAL;AAAWE,IAAAA,QAAQ,EAAEH,IAAI,EAAA;AAAzB,GAAD,EAAgCE,IAAhC,CADJ,GAEI,CAAC,EAAE,GAAGF,IAAL;IAAWG,QAAQ,EAAEH,IAAF,IAAEA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,IAAI,CAAEG,QAAR,IAAA,IAAA,GAAA,KAAA,CAAA,GAAEH,IAAI,CAAEG,QAAN,EAAA;GAAtB,EAA4CF,IAA5C,CAHN,CAAA;AAKD,CAAA;AAEM,SAASO,gBAAT,CACLC,iBADK,EAELC,MAFK,EAGI;AACT;AACA,EAAA,IAAI,OAAOD,iBAAP,KAA6B,UAAjC,EAA6C;AAC3C,IAAA,OAAOA,iBAAiB,CAAC,GAAGC,MAAJ,CAAxB,CAAA;AACD,GAAA;;EAED,OAAO,CAAC,CAACD,iBAAT,CAAA;AACD,CAAA;AAEM,SAASE,KAAT,CAAeC,OAAf,EAA+C;AACpD,EAAA,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;AAC9BC,IAAAA,UAAU,CAACD,OAAD,EAAUF,OAAV,CAAV,CAAA;AACD,GAFM,CAAP,CAAA;AAGD,CAAA;AAED;AACA;AACA;AACA;;AACO,SAASI,iBAAT,CAA2BC,QAA3B,EAAiD;AACtDN,EAAAA,KAAK,CAAC,CAAD,CAAL,CAASO,IAAT,CAAcD,QAAd,CAAA,CAAA;AACD;;;;"}
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { createContext, useContext, onMount, onCleanup, mergeProps, } from 'solid-js';
|
|
2
|
-
export const defaultContext = createContext(undefined);
|
|
3
|
-
const QueryClientSharingContext = createContext(false);
|
|
4
|
-
// If we are given a context, we will use it.
|
|
5
|
-
// Otherwise, if contextSharing is on, we share the first and at least one
|
|
6
|
-
// instance of the context across the window
|
|
7
|
-
// to ensure that if Solid Query is used across
|
|
8
|
-
// different bundles or microfrontends they will
|
|
9
|
-
// all use the same **instance** of context, regardless
|
|
10
|
-
// of module scoping.
|
|
11
|
-
function getQueryClientContext(context, contextSharing) {
|
|
12
|
-
if (context) {
|
|
13
|
-
return context;
|
|
14
|
-
}
|
|
15
|
-
if (contextSharing && typeof window !== 'undefined') {
|
|
16
|
-
if (!window.SolidQueryClientContext) {
|
|
17
|
-
window.SolidQueryClientContext = defaultContext;
|
|
18
|
-
}
|
|
19
|
-
return window.SolidQueryClientContext;
|
|
20
|
-
}
|
|
21
|
-
return defaultContext;
|
|
22
|
-
}
|
|
23
|
-
export const useQueryClient = ({ context } = {}) => {
|
|
24
|
-
const queryClient = useContext(getQueryClientContext(context, useContext(QueryClientSharingContext)));
|
|
25
|
-
if (!queryClient) {
|
|
26
|
-
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
|
27
|
-
}
|
|
28
|
-
return queryClient;
|
|
29
|
-
};
|
|
30
|
-
export const QueryClientProvider = (props) => {
|
|
31
|
-
const mergedProps = mergeProps({
|
|
32
|
-
contextSharing: false,
|
|
33
|
-
}, props);
|
|
34
|
-
onMount(() => {
|
|
35
|
-
mergedProps.client.mount();
|
|
36
|
-
if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {
|
|
37
|
-
mergedProps.client
|
|
38
|
-
.getLogger()
|
|
39
|
-
.error(`The contextSharing option has been deprecated and will be removed in the next major version`);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
onCleanup(() => mergedProps.client.unmount());
|
|
43
|
-
const QueryClientContext = getQueryClientContext(mergedProps.context, mergedProps.contextSharing);
|
|
44
|
-
return (<QueryClientSharingContext.Provider value={!mergedProps.context && mergedProps.contextSharing}>
|
|
45
|
-
<QueryClientContext.Provider value={mergedProps.client}>
|
|
46
|
-
{mergedProps.children}
|
|
47
|
-
</QueryClientContext.Provider>
|
|
48
|
-
</QueryClientSharingContext.Provider>);
|
|
49
|
-
};
|
|
@@ -1,185 +0,0 @@
|
|
|
1
|
-
import { render, screen, waitFor } from 'solid-testing-library';
|
|
2
|
-
import { queryKey } from './utils';
|
|
3
|
-
import { QueryCache, QueryClient } from '@tanstack/query-core';
|
|
4
|
-
import { createContext, useContext } from 'solid-js';
|
|
5
|
-
import { renderToString } from 'solid-js/web';
|
|
6
|
-
import { createQuery, QueryClientProvider, useQueryClient } from '..';
|
|
7
|
-
import { createQueryClient, sleep } from './utils';
|
|
8
|
-
describe('QueryClientProvider', () => {
|
|
9
|
-
it('sets a specific cache for all queries to use', async () => {
|
|
10
|
-
const key = queryKey();
|
|
11
|
-
const queryCache = new QueryCache();
|
|
12
|
-
const queryClient = createQueryClient({ queryCache });
|
|
13
|
-
function Page() {
|
|
14
|
-
const query = createQuery(key, async () => {
|
|
15
|
-
await sleep(10);
|
|
16
|
-
return 'test';
|
|
17
|
-
});
|
|
18
|
-
return (<div>
|
|
19
|
-
<h1>{query.data}</h1>
|
|
20
|
-
</div>);
|
|
21
|
-
}
|
|
22
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
23
|
-
<Page />
|
|
24
|
-
</QueryClientProvider>));
|
|
25
|
-
await waitFor(() => {
|
|
26
|
-
return screen.getByText('test');
|
|
27
|
-
});
|
|
28
|
-
expect(queryCache.find(key())).toBeDefined();
|
|
29
|
-
});
|
|
30
|
-
it('allows multiple caches to be partitioned', async () => {
|
|
31
|
-
const key1 = queryKey();
|
|
32
|
-
const key2 = queryKey();
|
|
33
|
-
const queryCache1 = new QueryCache();
|
|
34
|
-
const queryCache2 = new QueryCache();
|
|
35
|
-
const queryClient1 = createQueryClient({ queryCache: queryCache1 });
|
|
36
|
-
const queryClient2 = createQueryClient({ queryCache: queryCache2 });
|
|
37
|
-
function Page1() {
|
|
38
|
-
const query = createQuery(key1, async () => {
|
|
39
|
-
await sleep(10);
|
|
40
|
-
return 'test1';
|
|
41
|
-
});
|
|
42
|
-
return (<div>
|
|
43
|
-
<h1>{query.data}</h1>
|
|
44
|
-
</div>);
|
|
45
|
-
}
|
|
46
|
-
function Page2() {
|
|
47
|
-
const query = createQuery(key2, async () => {
|
|
48
|
-
await sleep(10);
|
|
49
|
-
return 'test2';
|
|
50
|
-
});
|
|
51
|
-
return (<div>
|
|
52
|
-
<h1>{query.data}</h1>
|
|
53
|
-
</div>);
|
|
54
|
-
}
|
|
55
|
-
render(() => (<>
|
|
56
|
-
<QueryClientProvider client={queryClient1}>
|
|
57
|
-
<Page1 />
|
|
58
|
-
</QueryClientProvider>
|
|
59
|
-
<QueryClientProvider client={queryClient2}>
|
|
60
|
-
<Page2 />
|
|
61
|
-
</QueryClientProvider>
|
|
62
|
-
</>));
|
|
63
|
-
await waitFor(() => screen.getByText('test1'));
|
|
64
|
-
await waitFor(() => screen.getByText('test2'));
|
|
65
|
-
expect(queryCache1.find(key1())).toBeDefined();
|
|
66
|
-
expect(queryCache1.find(key2())).not.toBeDefined();
|
|
67
|
-
expect(queryCache2.find(key1())).not.toBeDefined();
|
|
68
|
-
expect(queryCache2.find(key2())).toBeDefined();
|
|
69
|
-
});
|
|
70
|
-
it("uses defaultOptions for queries when they don't provide their own config", async () => {
|
|
71
|
-
const key = queryKey();
|
|
72
|
-
const queryCache = new QueryCache();
|
|
73
|
-
const queryClient = createQueryClient({
|
|
74
|
-
queryCache,
|
|
75
|
-
defaultOptions: {
|
|
76
|
-
queries: {
|
|
77
|
-
cacheTime: Infinity,
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
function Page() {
|
|
82
|
-
const query = createQuery(key, async () => {
|
|
83
|
-
await sleep(10);
|
|
84
|
-
return 'test';
|
|
85
|
-
});
|
|
86
|
-
return (<div>
|
|
87
|
-
<h1>{query.data}</h1>
|
|
88
|
-
</div>);
|
|
89
|
-
}
|
|
90
|
-
render(() => (<QueryClientProvider client={queryClient}>
|
|
91
|
-
<Page />
|
|
92
|
-
</QueryClientProvider>));
|
|
93
|
-
await waitFor(() => screen.getByText('test'));
|
|
94
|
-
expect(queryCache.find(key())).toBeDefined();
|
|
95
|
-
expect(queryCache.find(key())?.options.cacheTime).toBe(Infinity);
|
|
96
|
-
});
|
|
97
|
-
describe('with custom context', () => {
|
|
98
|
-
it('uses the correct context', async () => {
|
|
99
|
-
const key = queryKey();
|
|
100
|
-
const contextOuter = createContext(undefined);
|
|
101
|
-
const contextInner = createContext(undefined);
|
|
102
|
-
const queryCacheOuter = new QueryCache();
|
|
103
|
-
const queryClientOuter = new QueryClient({ queryCache: queryCacheOuter });
|
|
104
|
-
const queryCacheInner = new QueryCache();
|
|
105
|
-
const queryClientInner = new QueryClient({ queryCache: queryCacheInner });
|
|
106
|
-
const queryCacheInnerInner = new QueryCache();
|
|
107
|
-
const queryClientInnerInner = new QueryClient({
|
|
108
|
-
queryCache: queryCacheInnerInner,
|
|
109
|
-
});
|
|
110
|
-
function Page() {
|
|
111
|
-
const queryOuter = createQuery(key, async () => 'testOuter', {
|
|
112
|
-
context: contextOuter,
|
|
113
|
-
});
|
|
114
|
-
const queryInner = createQuery(key, async () => 'testInner', {
|
|
115
|
-
context: contextInner,
|
|
116
|
-
});
|
|
117
|
-
const queryInnerInner = createQuery(key, async () => 'testInnerInner');
|
|
118
|
-
return (<div>
|
|
119
|
-
<h1>
|
|
120
|
-
{queryOuter.data} {queryInner.data} {queryInnerInner.data}
|
|
121
|
-
</h1>
|
|
122
|
-
</div>);
|
|
123
|
-
}
|
|
124
|
-
// contextSharing should be ignored when passing a custom context.
|
|
125
|
-
const contextSharing = true;
|
|
126
|
-
render(() => (<QueryClientProvider client={queryClientOuter} context={contextOuter}>
|
|
127
|
-
<QueryClientProvider client={queryClientInner} context={contextInner}>
|
|
128
|
-
<QueryClientProvider client={queryClientInnerInner} contextSharing={contextSharing}>
|
|
129
|
-
<Page />
|
|
130
|
-
</QueryClientProvider>
|
|
131
|
-
</QueryClientProvider>
|
|
132
|
-
</QueryClientProvider>));
|
|
133
|
-
await waitFor(() => screen.getByText('testOuter testInner testInnerInner'));
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
describe('useQueryClient', () => {
|
|
137
|
-
it('should throw an error if no query client has been set', () => {
|
|
138
|
-
const consoleMock = jest
|
|
139
|
-
.spyOn(console, 'error')
|
|
140
|
-
.mockImplementation(() => undefined);
|
|
141
|
-
function Page() {
|
|
142
|
-
useQueryClient();
|
|
143
|
-
return null;
|
|
144
|
-
}
|
|
145
|
-
expect(() => render(() => <Page />)).toThrow('No QueryClient set, use QueryClientProvider to set one');
|
|
146
|
-
consoleMock.mockRestore();
|
|
147
|
-
});
|
|
148
|
-
it('should use window to get the context when contextSharing is true', () => {
|
|
149
|
-
const queryCache = new QueryCache();
|
|
150
|
-
const queryClient = createQueryClient({ queryCache });
|
|
151
|
-
let queryClientFromHook;
|
|
152
|
-
let queryClientFromWindow;
|
|
153
|
-
function Page() {
|
|
154
|
-
queryClientFromHook = useQueryClient();
|
|
155
|
-
queryClientFromWindow = useContext(window.SolidQueryClientContext);
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
render(() => (<QueryClientProvider client={queryClient} contextSharing={true}>
|
|
159
|
-
<Page />
|
|
160
|
-
</QueryClientProvider>));
|
|
161
|
-
expect(queryClientFromHook).toEqual(queryClient);
|
|
162
|
-
expect(queryClientFromWindow).toEqual(queryClient);
|
|
163
|
-
});
|
|
164
|
-
it.skip('should not use window to get the context when contextSharing is true and window does not exist', () => {
|
|
165
|
-
const queryCache = new QueryCache();
|
|
166
|
-
const queryClient = createQueryClient({ queryCache });
|
|
167
|
-
// Mock a non web browser environment
|
|
168
|
-
const windowSpy = jest
|
|
169
|
-
.spyOn(window, 'window', 'get')
|
|
170
|
-
.mockImplementation(undefined);
|
|
171
|
-
let queryClientFromHook;
|
|
172
|
-
function Page() {
|
|
173
|
-
queryClientFromHook = useQueryClient();
|
|
174
|
-
return null;
|
|
175
|
-
}
|
|
176
|
-
// TODO(lukemurray): fails because renderToString never calls Page
|
|
177
|
-
// probably an SSR-testing issue we need to fix.
|
|
178
|
-
renderToString(() => (<QueryClientProvider client={queryClient} contextSharing={true}>
|
|
179
|
-
<Page />
|
|
180
|
-
</QueryClientProvider>));
|
|
181
|
-
expect(queryClientFromHook).toEqual(queryClient);
|
|
182
|
-
windowSpy.mockRestore();
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
});
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { useQueryClient } from './QueryClientProvider';
|
|
2
|
-
import { onMount, onCleanup, createComputed, createResource, on, batch, } from 'solid-js';
|
|
3
|
-
import { createStore, unwrap } from 'solid-js/store';
|
|
4
|
-
import { shouldThrowError } from './utils';
|
|
5
|
-
// Base Query Function that is used to create the query.
|
|
6
|
-
export function createBaseQuery(options, Observer) {
|
|
7
|
-
const queryClient = useQueryClient({ context: options.context });
|
|
8
|
-
const emptyData = Symbol('empty');
|
|
9
|
-
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
10
|
-
defaultedOptions._optimisticResults = 'optimistic';
|
|
11
|
-
const observer = new Observer(queryClient, defaultedOptions);
|
|
12
|
-
const [state, setState] = createStore(
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
observer.getOptimisticResult(defaultedOptions));
|
|
15
|
-
const [dataResource, { refetch, mutate }] = createResource(() => {
|
|
16
|
-
return new Promise((resolve) => {
|
|
17
|
-
if (!(state.isFetching && state.isLoading)) {
|
|
18
|
-
if (unwrap(state.data) === emptyData) {
|
|
19
|
-
resolve(undefined);
|
|
20
|
-
}
|
|
21
|
-
resolve(unwrap(state.data));
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
});
|
|
25
|
-
batch(() => {
|
|
26
|
-
mutate(() => unwrap(state.data));
|
|
27
|
-
refetch();
|
|
28
|
-
});
|
|
29
|
-
let taskQueue = [];
|
|
30
|
-
const unsubscribe = observer.subscribe((result) => {
|
|
31
|
-
taskQueue.push(() => {
|
|
32
|
-
batch(() => {
|
|
33
|
-
const unwrappedResult = { ...unwrap(result) };
|
|
34
|
-
if (unwrappedResult.data === undefined) {
|
|
35
|
-
// This is a hack to prevent Solid
|
|
36
|
-
// from deleting the data property when it is `undefined`
|
|
37
|
-
// ref: https://www.solidjs.com/docs/latest/api#updating-stores
|
|
38
|
-
// @ts-ignore
|
|
39
|
-
unwrappedResult.data = emptyData;
|
|
40
|
-
}
|
|
41
|
-
setState(unwrap(unwrappedResult));
|
|
42
|
-
mutate(() => unwrap(result.data));
|
|
43
|
-
refetch();
|
|
44
|
-
});
|
|
45
|
-
});
|
|
46
|
-
queueMicrotask(() => {
|
|
47
|
-
const taskToRun = taskQueue.pop();
|
|
48
|
-
if (taskToRun) {
|
|
49
|
-
taskToRun();
|
|
50
|
-
}
|
|
51
|
-
taskQueue = [];
|
|
52
|
-
});
|
|
53
|
-
});
|
|
54
|
-
onCleanup(() => unsubscribe());
|
|
55
|
-
onMount(() => {
|
|
56
|
-
observer.setOptions(defaultedOptions, { listeners: false });
|
|
57
|
-
});
|
|
58
|
-
createComputed(() => {
|
|
59
|
-
const newDefaultedOptions = queryClient.defaultQueryOptions(options);
|
|
60
|
-
observer.setOptions(newDefaultedOptions);
|
|
61
|
-
});
|
|
62
|
-
createComputed(on(() => state.status, () => {
|
|
63
|
-
if (state.isError &&
|
|
64
|
-
!state.isFetching &&
|
|
65
|
-
shouldThrowError(observer.options.useErrorBoundary, [
|
|
66
|
-
state.error,
|
|
67
|
-
observer.getCurrentQuery(),
|
|
68
|
-
])) {
|
|
69
|
-
throw state.error;
|
|
70
|
-
}
|
|
71
|
-
}));
|
|
72
|
-
const handler = {
|
|
73
|
-
get(target, prop) {
|
|
74
|
-
if (prop === 'data') {
|
|
75
|
-
return dataResource();
|
|
76
|
-
}
|
|
77
|
-
return Reflect.get(target, prop);
|
|
78
|
-
},
|
|
79
|
-
};
|
|
80
|
-
return new Proxy(state, handler);
|
|
81
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import { createBaseQuery } from './createBaseQuery';
|
|
3
|
-
import { createComputed } from 'solid-js';
|
|
4
|
-
import { createStore } from 'solid-js/store';
|
|
5
|
-
import { parseQueryArgs } from './utils';
|
|
6
|
-
export function createInfiniteQuery(arg1, arg2, arg3) {
|
|
7
|
-
// The parseQuery Args functions helps normalize the arguments into the correct form.
|
|
8
|
-
// Whatever the parameters are, they are normalized into the correct form.
|
|
9
|
-
const [parsedOptions, setParsedOptions] = createStore(parseQueryArgs(arg1, arg2, arg3));
|
|
10
|
-
// Watch for changes in the options and update the parsed options.
|
|
11
|
-
createComputed(() => {
|
|
12
|
-
const newParsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
|
13
|
-
setParsedOptions(newParsedOptions);
|
|
14
|
-
});
|
|
15
|
-
return createBaseQuery(parsedOptions, InfiniteQueryObserver);
|
|
16
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { createComputed, onCleanup, onMount } from 'solid-js';
|
|
2
|
-
import { QueriesObserver } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider';
|
|
4
|
-
import { createStore, unwrap } from 'solid-js/store';
|
|
5
|
-
import { scheduleMicrotask } from './utils';
|
|
6
|
-
export function createQueries(queriesOptions) {
|
|
7
|
-
const queryClient = useQueryClient({ context: queriesOptions.context });
|
|
8
|
-
const normalizeOptions = (options) => {
|
|
9
|
-
const normalizedOptions = { ...options, queryKey: options.queryKey?.() };
|
|
10
|
-
const defaultedOptions = queryClient.defaultQueryOptions(normalizedOptions);
|
|
11
|
-
defaultedOptions._optimisticResults = 'optimistic';
|
|
12
|
-
return defaultedOptions;
|
|
13
|
-
};
|
|
14
|
-
const defaultedQueries = queriesOptions.queries.map((options) => normalizeOptions(options));
|
|
15
|
-
const observer = new QueriesObserver(queryClient, defaultedQueries);
|
|
16
|
-
const [state, setState] = createStore(observer.getOptimisticResult(defaultedQueries));
|
|
17
|
-
const taskQueue = [];
|
|
18
|
-
const unsubscribe = observer.subscribe((result) => {
|
|
19
|
-
taskQueue.push(() => {
|
|
20
|
-
setState(unwrap(result));
|
|
21
|
-
});
|
|
22
|
-
scheduleMicrotask(() => {
|
|
23
|
-
const taskToRun = taskQueue.pop();
|
|
24
|
-
if (taskToRun) {
|
|
25
|
-
taskToRun();
|
|
26
|
-
taskQueue.splice(0, taskQueue.length);
|
|
27
|
-
}
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
onCleanup(unsubscribe);
|
|
31
|
-
onMount(() => {
|
|
32
|
-
observer.setQueries(defaultedQueries, { listeners: false });
|
|
33
|
-
});
|
|
34
|
-
createComputed(() => {
|
|
35
|
-
const updateDefaultedQueries = queriesOptions.queries.map((options) => normalizeOptions(options));
|
|
36
|
-
observer.setQueries(updateDefaultedQueries);
|
|
37
|
-
});
|
|
38
|
-
return state;
|
|
39
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { QueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import { createComputed } from 'solid-js';
|
|
3
|
-
import { createStore } from 'solid-js/store';
|
|
4
|
-
import { parseQueryArgs } from './utils';
|
|
5
|
-
import { createBaseQuery } from './createBaseQuery';
|
|
6
|
-
export function createQuery(arg1, arg2, arg3) {
|
|
7
|
-
// The parseQuery Args functions helps normalize the arguments into the correct form.
|
|
8
|
-
// Whatever the parameters are, they are normalized into the correct form.
|
|
9
|
-
const [parsedOptions, setParsedOptions] = createStore(parseQueryArgs(arg1, arg2, arg3));
|
|
10
|
-
// Watch for changes in the options and update the parsed options.
|
|
11
|
-
createComputed(() => {
|
|
12
|
-
const newParsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
|
13
|
-
setParsedOptions(newParsedOptions);
|
|
14
|
-
});
|
|
15
|
-
return createBaseQuery(parsedOptions, QueryObserver);
|
|
16
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import { useQueryClient } from './QueryClientProvider';
|
|
2
|
-
import { createSignal, onCleanup, createComputed, createMemo } from 'solid-js';
|
|
3
|
-
import { parseFilterArgs } from './utils';
|
|
4
|
-
export function useIsFetching(arg1, arg2, arg3) {
|
|
5
|
-
const [filtersObj, optionsObj = {}] = parseFilterArgs(arg1, arg2, arg3);
|
|
6
|
-
const [filters, setFilters] = createSignal(filtersObj);
|
|
7
|
-
const [options, setOptions] = createSignal(optionsObj);
|
|
8
|
-
const queryClient = createMemo(() => useQueryClient({ context: options().context }));
|
|
9
|
-
const queryCache = createMemo(() => queryClient().getQueryCache());
|
|
10
|
-
const [fetches, setFetches] = createSignal(queryClient().isFetching(filters));
|
|
11
|
-
createComputed(() => {
|
|
12
|
-
const [newFiltersObj, newOptionsObj = {}] = parseFilterArgs(arg1, arg2, arg3);
|
|
13
|
-
setFilters(newFiltersObj);
|
|
14
|
-
setOptions(newOptionsObj);
|
|
15
|
-
});
|
|
16
|
-
const unsubscribe = queryCache().subscribe(() => {
|
|
17
|
-
setFetches(queryClient().isFetching(filters()));
|
|
18
|
-
});
|
|
19
|
-
onCleanup(() => {
|
|
20
|
-
unsubscribe();
|
|
21
|
-
});
|
|
22
|
-
return fetches;
|
|
23
|
-
}
|