@tanstack/solid-query 4.24.10 → 5.0.0-alpha.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.
Files changed (158) hide show
  1. package/build/cjs/index.js +298 -0
  2. package/build/cjs/index.js.map +1 -0
  3. package/build/esm/index.js +283 -0
  4. package/build/esm/index.js.map +1 -0
  5. package/build/source/QueryClientProvider.jsx +21 -0
  6. package/build/source/__tests__/QueryClientProvider.test.jsx +120 -0
  7. package/build/{solid → source}/__tests__/createInfiniteQuery.test.jsx +228 -372
  8. package/build/{solid → source}/__tests__/createMutation.test.jsx +174 -165
  9. package/build/{solid → source}/__tests__/createQueries.test.jsx +86 -367
  10. package/build/{solid → source}/__tests__/createQuery.test.jsx +991 -943
  11. package/build/{solid → source}/__tests__/createQuery.types.test.jsx +35 -24
  12. package/build/{solid → source}/__tests__/suspense.test.jsx +177 -148
  13. package/build/{solid → source}/__tests__/transition.test.jsx +7 -4
  14. package/build/{solid → source}/__tests__/useIsFetching.test.jsx +68 -85
  15. package/build/{solid → source}/__tests__/useIsMutating.test.jsx +78 -93
  16. package/build/{solid → source}/__tests__/utils.jsx +3 -9
  17. package/build/source/createBaseQuery.js +147 -0
  18. package/build/source/createInfiniteQuery.js +6 -0
  19. package/build/{solid → source}/createMutation.js +7 -9
  20. package/build/source/createQueries.js +32 -0
  21. package/build/source/createQuery.js +6 -0
  22. package/build/{solid → source}/index.js +5 -3
  23. package/build/source/setBatchUpdatesFn.js +3 -0
  24. package/build/source/useIsFetching.js +12 -0
  25. package/build/source/useIsMutating.js +12 -0
  26. package/build/source/utils.js +7 -0
  27. package/build/types/QueryClientProvider.d.ts +9 -0
  28. package/build/{lib → types}/__tests__/utils.d.ts +3 -8
  29. package/build/types/createBaseQuery.d.ts +4 -0
  30. package/build/types/createInfiniteQuery.d.ts +3 -0
  31. package/build/types/createMutation.d.ts +3 -0
  32. package/build/{lib → types}/createQueries.d.ts +10 -8
  33. package/build/types/createQuery.d.ts +11 -0
  34. package/build/{lib → types}/index.d.ts +4 -3
  35. package/build/types/setBatchUpdatesFn.d.ts +1 -0
  36. package/build/types/types.d.ts +33 -0
  37. package/build/types/useIsFetching.d.ts +8 -0
  38. package/build/types/useIsMutating.d.ts +8 -0
  39. package/build/types/utils.d.ts +1 -0
  40. package/build/umd/index.js +2 -0
  41. package/build/umd/index.js.map +1 -0
  42. package/package.json +25 -17
  43. package/src/QueryClientProvider.tsx +17 -86
  44. package/src/__tests__/QueryClientProvider.test.tsx +37 -140
  45. package/src/__tests__/createInfiniteQuery.test.tsx +277 -508
  46. package/src/__tests__/createMutation.test.tsx +177 -225
  47. package/src/__tests__/createQueries.test.tsx +180 -528
  48. package/src/__tests__/createQuery.test.tsx +970 -1200
  49. package/src/__tests__/createQuery.types.test.tsx +30 -25
  50. package/src/__tests__/suspense.test.tsx +141 -178
  51. package/src/__tests__/transition.test.tsx +7 -4
  52. package/src/__tests__/useIsFetching.test.tsx +77 -122
  53. package/src/__tests__/useIsMutating.test.tsx +83 -128
  54. package/src/__tests__/utils.tsx +4 -11
  55. package/src/createBaseQuery.ts +148 -60
  56. package/src/createInfiniteQuery.ts +15 -94
  57. package/src/createMutation.ts +9 -63
  58. package/src/createQueries.ts +44 -55
  59. package/src/createQuery.ts +42 -127
  60. package/src/index.ts +6 -3
  61. package/src/setBatchUpdatesFn.ts +4 -0
  62. package/src/types.ts +81 -75
  63. package/src/useIsFetching.ts +12 -44
  64. package/src/useIsMutating.ts +13 -29
  65. package/src/utils.ts +5 -79
  66. package/build/lib/QueryClientProvider.d.ts +0 -24
  67. package/build/lib/QueryClientProvider.esm.js +0 -74
  68. package/build/lib/QueryClientProvider.esm.js.map +0 -1
  69. package/build/lib/QueryClientProvider.js +0 -80
  70. package/build/lib/QueryClientProvider.js.map +0 -1
  71. package/build/lib/QueryClientProvider.mjs +0 -74
  72. package/build/lib/QueryClientProvider.mjs.map +0 -1
  73. package/build/lib/createBaseQuery.d.ts +0 -4
  74. package/build/lib/createBaseQuery.esm.js +0 -93
  75. package/build/lib/createBaseQuery.esm.js.map +0 -1
  76. package/build/lib/createBaseQuery.js +0 -97
  77. package/build/lib/createBaseQuery.js.map +0 -1
  78. package/build/lib/createBaseQuery.mjs +0 -93
  79. package/build/lib/createBaseQuery.mjs.map +0 -1
  80. package/build/lib/createInfiniteQuery.d.ts +0 -5
  81. package/build/lib/createInfiniteQuery.esm.js +0 -20
  82. package/build/lib/createInfiniteQuery.esm.js.map +0 -1
  83. package/build/lib/createInfiniteQuery.js +0 -24
  84. package/build/lib/createInfiniteQuery.js.map +0 -1
  85. package/build/lib/createInfiniteQuery.mjs +0 -20
  86. package/build/lib/createInfiniteQuery.mjs.map +0 -1
  87. package/build/lib/createMutation.d.ts +0 -6
  88. package/build/lib/createMutation.esm.js +0 -45
  89. package/build/lib/createMutation.esm.js.map +0 -1
  90. package/build/lib/createMutation.js +0 -49
  91. package/build/lib/createMutation.js.map +0 -1
  92. package/build/lib/createMutation.mjs +0 -45
  93. package/build/lib/createMutation.mjs.map +0 -1
  94. package/build/lib/createQueries.esm.js +0 -54
  95. package/build/lib/createQueries.esm.js.map +0 -1
  96. package/build/lib/createQueries.js +0 -58
  97. package/build/lib/createQueries.js.map +0 -1
  98. package/build/lib/createQueries.mjs +0 -54
  99. package/build/lib/createQueries.mjs.map +0 -1
  100. package/build/lib/createQuery.d.ts +0 -23
  101. package/build/lib/createQuery.esm.js +0 -25
  102. package/build/lib/createQuery.esm.js.map +0 -1
  103. package/build/lib/createQuery.js +0 -29
  104. package/build/lib/createQuery.js.map +0 -1
  105. package/build/lib/createQuery.mjs +0 -25
  106. package/build/lib/createQuery.mjs.map +0 -1
  107. package/build/lib/index.esm.js +0 -9
  108. package/build/lib/index.esm.js.map +0 -1
  109. package/build/lib/index.js +0 -31
  110. package/build/lib/index.js.map +0 -1
  111. package/build/lib/index.mjs +0 -9
  112. package/build/lib/index.mjs.map +0 -1
  113. package/build/lib/types.d.ts +0 -47
  114. package/build/lib/useIsFetching.d.ts +0 -7
  115. package/build/lib/useIsFetching.esm.js +0 -29
  116. package/build/lib/useIsFetching.esm.js.map +0 -1
  117. package/build/lib/useIsFetching.js +0 -33
  118. package/build/lib/useIsFetching.js.map +0 -1
  119. package/build/lib/useIsFetching.mjs +0 -29
  120. package/build/lib/useIsFetching.mjs.map +0 -1
  121. package/build/lib/useIsMutating.d.ts +0 -8
  122. package/build/lib/useIsMutating.esm.js +0 -22
  123. package/build/lib/useIsMutating.esm.js.map +0 -1
  124. package/build/lib/useIsMutating.js +0 -26
  125. package/build/lib/useIsMutating.js.map +0 -1
  126. package/build/lib/useIsMutating.mjs +0 -22
  127. package/build/lib/useIsMutating.mjs.map +0 -1
  128. package/build/lib/utils.d.ts +0 -14
  129. package/build/lib/utils.esm.js +0 -63
  130. package/build/lib/utils.esm.js.map +0 -1
  131. package/build/lib/utils.js +0 -72
  132. package/build/lib/utils.js.map +0 -1
  133. package/build/lib/utils.mjs +0 -63
  134. package/build/lib/utils.mjs.map +0 -1
  135. package/build/solid/QueryClientProvider.jsx +0 -49
  136. package/build/solid/__tests__/QueryClientProvider.test.jsx +0 -185
  137. package/build/solid/createBaseQuery.js +0 -81
  138. package/build/solid/createInfiniteQuery.js +0 -16
  139. package/build/solid/createQueries.js +0 -39
  140. package/build/solid/createQuery.js +0 -16
  141. package/build/solid/useIsFetching.js +0 -23
  142. package/build/solid/useIsMutating.js +0 -16
  143. package/build/solid/utils.js +0 -45
  144. package/build/umd/index.development.js +0 -3577
  145. package/build/umd/index.development.js.map +0 -1
  146. package/build/umd/index.production.js +0 -2
  147. package/build/umd/index.production.js.map +0 -1
  148. /package/build/{solid → source}/types.js +0 -0
  149. /package/build/{lib → types}/__tests__/QueryClientProvider.test.d.ts +0 -0
  150. /package/build/{lib → types}/__tests__/createInfiniteQuery.test.d.ts +0 -0
  151. /package/build/{lib → types}/__tests__/createMutation.test.d.ts +0 -0
  152. /package/build/{lib → types}/__tests__/createQueries.test.d.ts +0 -0
  153. /package/build/{lib → types}/__tests__/createQuery.test.d.ts +0 -0
  154. /package/build/{lib → types}/__tests__/createQuery.types.test.d.ts +0 -0
  155. /package/build/{lib → types}/__tests__/suspense.test.d.ts +0 -0
  156. /package/build/{lib → types}/__tests__/transition.test.d.ts +0 -0
  157. /package/build/{lib → types}/__tests__/useIsFetching.test.d.ts +0 -0
  158. /package/build/{lib → types}/__tests__/useIsMutating.test.d.ts +0 -0
package/src/utils.ts CHANGED
@@ -1,85 +1,11 @@
1
- import type {
2
- SolidQueryKey,
3
- SolidQueryFilters,
4
- ParseFilterArgs,
5
- ParseQueryArgs,
6
- } from './types'
7
- import type { QueryFunction, QueryOptions } from '@tanstack/query-core'
8
-
9
- export function isQueryKey(value: unknown): value is SolidQueryKey {
10
- return typeof value === 'function'
11
- }
12
-
13
- // The parseQuery Args functions helps normalize the arguments into the correct form.
14
- // Whatever the parameters are, they are normalized into the correct form.
15
- export function parseQueryArgs<
16
- TOptions extends Omit<
17
- QueryOptions<any, any, any, ReturnType<TQueryKey>>,
18
- 'queryKey'
19
- > & {
20
- queryKey?: TQueryKey
21
- },
22
- TQueryKey extends () => readonly unknown[] = SolidQueryKey,
23
- >(
24
- arg1: TQueryKey | TOptions,
25
- arg2?: QueryFunction<any, ReturnType<TQueryKey>> | TOptions,
26
- arg3?: TOptions,
27
- ): ParseQueryArgs<TOptions, TQueryKey> {
28
- if (!isQueryKey(arg1)) {
29
- const { queryKey: solidKey, ...opts } = arg1 as any
30
- if (solidKey) {
31
- return {
32
- ...opts,
33
- queryKey: solidKey(),
34
- }
35
- }
36
- return arg1 as any
37
- }
38
-
39
- if (typeof arg2 === 'function') {
40
- return { ...arg3, queryKey: arg1(), queryFn: arg2 } as any
41
- }
42
-
43
- return { ...arg2, queryKey: arg1() } as any
44
- }
45
-
46
- export function parseFilterArgs<
47
- TFilters extends SolidQueryFilters,
48
- TOptions = unknown,
49
- >(
50
- arg1?: SolidQueryKey | TFilters,
51
- arg2?: TFilters | TOptions,
52
- arg3?: TOptions,
53
- ): [ParseFilterArgs<TFilters>, TOptions | undefined] {
54
- return (
55
- isQueryKey(arg1)
56
- ? [{ ...arg2, queryKey: arg1() }, arg3]
57
- : [{ ...arg1, queryKey: arg1?.queryKey?.() }, arg2]
58
- ) as [ParseFilterArgs<TFilters>, TOptions]
59
- }
60
-
61
1
  export function shouldThrowError<T extends (...args: any[]) => boolean>(
62
- _useErrorBoundary: boolean | T | undefined,
2
+ throwError: boolean | T | undefined,
63
3
  params: Parameters<T>,
64
4
  ): boolean {
65
- // Allow useErrorBoundary function to override throwing behavior on a per-error basis
66
- if (typeof _useErrorBoundary === 'function') {
67
- return _useErrorBoundary(...params)
5
+ // Allow throwError function to override throwing behavior on a per-error basis
6
+ if (typeof throwError === 'function') {
7
+ return throwError(...params)
68
8
  }
69
9
 
70
- return !!_useErrorBoundary
71
- }
72
-
73
- export function sleep(timeout: number): Promise<void> {
74
- return new Promise((resolve) => {
75
- setTimeout(resolve, timeout)
76
- })
77
- }
78
-
79
- /**
80
- * Schedules a microtask.
81
- * This can be useful to schedule state updates after rendering.
82
- */
83
- export function scheduleMicrotask(callback: () => void) {
84
- sleep(0).then(callback)
10
+ return !!throwError
85
11
  }
@@ -1,24 +0,0 @@
1
- import type { QueryClient } from '@tanstack/query-core';
2
- import type { Context, JSX } from 'solid-js';
3
- import type { ContextOptions } from './types';
4
- declare global {
5
- interface Window {
6
- SolidQueryClientContext?: Context<QueryClient | undefined>;
7
- }
8
- }
9
- export declare const defaultContext: Context<QueryClient | undefined>;
10
- export declare const useQueryClient: ({ context }?: ContextOptions) => QueryClient;
11
- declare type QueryClientProviderPropsBase = {
12
- client: QueryClient;
13
- children?: JSX.Element;
14
- };
15
- declare type QueryClientProviderPropsWithContext = ContextOptions & {
16
- contextSharing?: never;
17
- } & QueryClientProviderPropsBase;
18
- declare type QueryClientProviderPropsWithContextSharing = {
19
- context?: never;
20
- contextSharing?: boolean;
21
- } & QueryClientProviderPropsBase;
22
- export declare type QueryClientProviderProps = QueryClientProviderPropsWithContext | QueryClientProviderPropsWithContextSharing;
23
- export declare const QueryClientProvider: (props: QueryClientProviderProps) => JSX.Element;
24
- export {};
@@ -1,74 +0,0 @@
1
- import { createContext, useContext, mergeProps, onMount, onCleanup, createComponent } from 'solid-js';
2
-
3
- const defaultContext = createContext(undefined);
4
- const QueryClientSharingContext = createContext(false); // 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
-
12
- function getQueryClientContext(context, contextSharing) {
13
- if (context) {
14
- return context;
15
- }
16
-
17
- if (contextSharing && typeof window !== 'undefined') {
18
- if (!window.SolidQueryClientContext) {
19
- window.SolidQueryClientContext = defaultContext;
20
- }
21
-
22
- return window.SolidQueryClientContext;
23
- }
24
-
25
- return defaultContext;
26
- }
27
-
28
- const useQueryClient = ({
29
- context
30
- } = {}) => {
31
- const queryClient = useContext(getQueryClientContext(context, useContext(QueryClientSharingContext)));
32
-
33
- if (!queryClient) {
34
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
35
- }
36
-
37
- return queryClient;
38
- };
39
- const QueryClientProvider = props => {
40
- const mergedProps = mergeProps({
41
- contextSharing: false
42
- }, props);
43
- onMount(() => {
44
- mergedProps.client.mount();
45
-
46
- if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {
47
- mergedProps.client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
48
- }
49
- });
50
- onCleanup(() => mergedProps.client.unmount());
51
- const QueryClientContext = getQueryClientContext(mergedProps.context, mergedProps.contextSharing);
52
- return createComponent(QueryClientSharingContext.Provider, {
53
- get value() {
54
- return !mergedProps.context && mergedProps.contextSharing;
55
- },
56
-
57
- get children() {
58
- return createComponent(QueryClientContext.Provider, {
59
- get value() {
60
- return mergedProps.client;
61
- },
62
-
63
- get children() {
64
- return mergedProps.children;
65
- }
66
-
67
- });
68
- }
69
-
70
- });
71
- };
72
-
73
- export { QueryClientProvider, defaultContext, useQueryClient };
74
- //# sourceMappingURL=QueryClientProvider.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryClientProvider.esm.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core'\nimport type { Context, JSX } from 'solid-js'\nimport {\n createContext,\n useContext,\n onMount,\n onCleanup,\n mergeProps,\n} from 'solid-js'\nimport type { ContextOptions } from './types'\n\ndeclare global {\n interface Window {\n SolidQueryClientContext?: Context<QueryClient | undefined>\n }\n}\n\nexport const defaultContext = createContext<QueryClient | undefined>(undefined)\nconst QueryClientSharingContext = createContext<boolean>(false)\n\n// If we are given a context, we will use it.\n// Otherwise, if contextSharing is on, we share the first and at least one\n// instance of the context across the window\n// to ensure that if Solid Query is used across\n// different bundles or microfrontends they will\n// all use the same **instance** of context, regardless\n// of module scoping.\nfunction getQueryClientContext(\n context: Context<QueryClient | undefined> | undefined,\n contextSharing: boolean,\n) {\n if (context) {\n return context\n }\n if (contextSharing && typeof window !== 'undefined') {\n if (!window.SolidQueryClientContext) {\n window.SolidQueryClientContext = defaultContext\n }\n\n return window.SolidQueryClientContext\n }\n\n return defaultContext\n}\n\nexport const useQueryClient = ({ context }: ContextOptions = {}) => {\n const queryClient = useContext(\n getQueryClientContext(context, useContext(QueryClientSharingContext)),\n )\n\n if (!queryClient) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return queryClient\n}\n\ntype QueryClientProviderPropsBase = {\n client: QueryClient\n children?: JSX.Element\n}\ntype QueryClientProviderPropsWithContext = ContextOptions & {\n contextSharing?: never\n} & QueryClientProviderPropsBase\ntype QueryClientProviderPropsWithContextSharing = {\n context?: never\n contextSharing?: boolean\n} & QueryClientProviderPropsBase\n\nexport type QueryClientProviderProps =\n | QueryClientProviderPropsWithContext\n | QueryClientProviderPropsWithContextSharing\n\nexport const QueryClientProvider = (\n props: QueryClientProviderProps,\n): JSX.Element => {\n const mergedProps = mergeProps(\n {\n contextSharing: false,\n },\n props,\n )\n onMount(() => {\n mergedProps.client.mount()\n\n if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {\n mergedProps.client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n })\n onCleanup(() => mergedProps.client.unmount())\n\n const QueryClientContext = getQueryClientContext(\n mergedProps.context,\n mergedProps.contextSharing,\n )\n\n return (\n <QueryClientSharingContext.Provider\n value={!mergedProps.context && mergedProps.contextSharing}\n >\n <QueryClientContext.Provider value={mergedProps.client}>\n {mergedProps.children}\n </QueryClientContext.Provider>\n </QueryClientSharingContext.Provider>\n )\n}\n"],"names":["defaultContext","createContext","undefined","QueryClientSharingContext","getQueryClientContext","context","contextSharing","window","SolidQueryClientContext","useQueryClient","queryClient","useContext","Error","QueryClientProvider","props","mergedProps","mergeProps","onMount","client","mount","process","env","NODE_ENV","getLogger","error","onCleanup","unmount","QueryClientContext","_$createComponent","children"],"mappings":";;MAiBaA,cAAc,GAAGC,aAAa,CAA0BC,SAA1B,EAApC;AACP,MAAMC,yBAAyB,GAAGF,aAAa,CAAU,KAAV,CAA/C;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASG,qBAAT,CACEC,OADF,EAEEC,cAFF,EAGE;AACA,EAAA,IAAID,OAAJ,EAAa;AACX,IAAA,OAAOA,OAAP,CAAA;AACD,GAAA;;AACD,EAAA,IAAIC,cAAc,IAAI,OAAOC,MAAP,KAAkB,WAAxC,EAAqD;AACnD,IAAA,IAAI,CAACA,MAAM,CAACC,uBAAZ,EAAqC;MACnCD,MAAM,CAACC,uBAAP,GAAiCR,cAAjC,CAAA;AACD,KAAA;;IAED,OAAOO,MAAM,CAACC,uBAAd,CAAA;AACD,GAAA;;AAED,EAAA,OAAOR,cAAP,CAAA;AACD,CAAA;;AAEM,MAAMS,cAAc,GAAG,CAAC;AAAEJ,EAAAA,OAAAA;A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Cb,WAAW,CAACG,MAJpD,CAAA;AAAA,SAAA;;AAAA,QAAA,IAAA,QAAA,GAAA;UAAA,OAKOH,WAAW,CAACc,QALnB,CAAA;AAAA,SAAA;;AAAA,OAAA,CAAA,CAAA;AAAA,KAAA;;AAAA,GAAA,CAAA,CAAA;AASD;;;;"}
@@ -1,80 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var solidJs = require('solid-js');
6
-
7
- const defaultContext = solidJs.createContext(undefined);
8
- const QueryClientSharingContext = solidJs.createContext(false); // If we are given a context, we will use it.
9
- // Otherwise, if contextSharing is on, we share the first and at least one
10
- // instance of the context across the window
11
- // to ensure that if Solid Query is used across
12
- // different bundles or microfrontends they will
13
- // all use the same **instance** of context, regardless
14
- // of module scoping.
15
-
16
- function getQueryClientContext(context, contextSharing) {
17
- if (context) {
18
- return context;
19
- }
20
-
21
- if (contextSharing && typeof window !== 'undefined') {
22
- if (!window.SolidQueryClientContext) {
23
- window.SolidQueryClientContext = defaultContext;
24
- }
25
-
26
- return window.SolidQueryClientContext;
27
- }
28
-
29
- return defaultContext;
30
- }
31
-
32
- const useQueryClient = ({
33
- context
34
- } = {}) => {
35
- const queryClient = solidJs.useContext(getQueryClientContext(context, solidJs.useContext(QueryClientSharingContext)));
36
-
37
- if (!queryClient) {
38
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
39
- }
40
-
41
- return queryClient;
42
- };
43
- const QueryClientProvider = props => {
44
- const mergedProps = solidJs.mergeProps({
45
- contextSharing: false
46
- }, props);
47
- solidJs.onMount(() => {
48
- mergedProps.client.mount();
49
-
50
- if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {
51
- mergedProps.client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
52
- }
53
- });
54
- solidJs.onCleanup(() => mergedProps.client.unmount());
55
- const QueryClientContext = getQueryClientContext(mergedProps.context, mergedProps.contextSharing);
56
- return solidJs.createComponent(QueryClientSharingContext.Provider, {
57
- get value() {
58
- return !mergedProps.context && mergedProps.contextSharing;
59
- },
60
-
61
- get children() {
62
- return solidJs.createComponent(QueryClientContext.Provider, {
63
- get value() {
64
- return mergedProps.client;
65
- },
66
-
67
- get children() {
68
- return mergedProps.children;
69
- }
70
-
71
- });
72
- }
73
-
74
- });
75
- };
76
-
77
- exports.QueryClientProvider = QueryClientProvider;
78
- exports.defaultContext = defaultContext;
79
- exports.useQueryClient = useQueryClient;
80
- //# sourceMappingURL=QueryClientProvider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryClientProvider.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core'\nimport type { Context, JSX } from 'solid-js'\nimport {\n createContext,\n useContext,\n onMount,\n onCleanup,\n mergeProps,\n} from 'solid-js'\nimport type { ContextOptions } from './types'\n\ndeclare global {\n interface Window {\n SolidQueryClientContext?: Context<QueryClient | undefined>\n }\n}\n\nexport const defaultContext = createContext<QueryClient | undefined>(undefined)\nconst QueryClientSharingContext = createContext<boolean>(false)\n\n// If we are given a context, we will use it.\n// Otherwise, if contextSharing is on, we share the first and at least one\n// instance of the context across the window\n// to ensure that if Solid Query is used across\n// different bundles or microfrontends they will\n// all use the same **instance** of context, regardless\n// of module scoping.\nfunction getQueryClientContext(\n context: Context<QueryClient | undefined> | undefined,\n contextSharing: boolean,\n) {\n if (context) {\n return context\n }\n if (contextSharing && typeof window !== 'undefined') {\n if (!window.SolidQueryClientContext) {\n window.SolidQueryClientContext = defaultContext\n }\n\n return window.SolidQueryClientContext\n }\n\n return defaultContext\n}\n\nexport const useQueryClient = ({ context }: ContextOptions = {}) => {\n const queryClient = useContext(\n getQueryClientContext(context, useContext(QueryClientSharingContext)),\n )\n\n if (!queryClient) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return queryClient\n}\n\ntype QueryClientProviderPropsBase = {\n client: QueryClient\n children?: JSX.Element\n}\ntype QueryClientProviderPropsWithContext = ContextOptions & {\n contextSharing?: never\n} & QueryClientProviderPropsBase\ntype QueryClientProviderPropsWithContextSharing = {\n context?: never\n contextSharing?: boolean\n} & QueryClientProviderPropsBase\n\nexport type QueryClientProviderProps =\n | QueryClientProviderPropsWithContext\n | QueryClientProviderPropsWithContextSharing\n\nexport const QueryClientProvider = (\n props: QueryClientProviderProps,\n): JSX.Element => {\n const mergedProps = mergeProps(\n {\n contextSharing: false,\n },\n props,\n )\n onMount(() => {\n mergedProps.client.mount()\n\n if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {\n mergedProps.client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n })\n onCleanup(() => mergedProps.client.unmount())\n\n const QueryClientContext = getQueryClientContext(\n mergedProps.context,\n mergedProps.contextSharing,\n )\n\n return (\n <QueryClientSharingContext.Provider\n value={!mergedProps.context && mergedProps.contextSharing}\n >\n <QueryClientContext.Provider value={mergedProps.client}>\n {mergedProps.children}\n </QueryClientContext.Provider>\n </QueryClientSharingContext.Provider>\n )\n}\n"],"names":["defaultContext","createContext","undefined","QueryClientSharingContext","getQueryClientContext","context","contextSharing","window","SolidQueryClientContext","useQueryClient","queryClient","useContext","Error","QueryClientProvider","props","mergedProps","mergeProps","onMount","client","mount","process","env","NODE_ENV","getLogger","error","onCleanup","unmount","QueryClientContext","_$createComponent","children"],"mappings":";;;;;;MAiBaA,cAAc,GAAGC,qBAAa,CAA0BC,SAA1B,EAApC;AACP,MAAMC,yBAAyB,GAAGF,qBAAa,CAAU,KAAV,CAA/C;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASG,qBAAT,CACEC,OADF,EAEEC,cAFF,EAGE;AACA,EAAA,IAAID,OAAJ,EAAa;AACX,IAAA,OAAOA,OAAP,CAAA;AACD,GAAA;;AACD,EAAA,IAAIC,cAAc,IAAI,OAAOC,MAAP,KAAkB,WAAxC,EAAqD;AACnD,IAAA,IAAI,CAACA,MAAM,CAACC,uBAAZ,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AA;AAAA,MAAA,OAEW,CAACb,WAAW,CAACV,OAAb,IAAwBU,WAAW,CAACT,cAF/C,CAAA;AAAA,KAAA;;AAAA,IAAA,IAAA,QAAA,GAAA;MAAA,OAIKsB,uBAAA,CAAA,kBAJL,CAIwB,QAJxB,EAAA;AAAA,QAAA,IAIiC,KAJjC,GAAA;UAAA,OAIwCb,WAAW,CAACG,MAJpD,CAAA;AAAA,SAAA;;AAAA,QAAA,IAAA,QAAA,GAAA;UAAA,OAKOH,WAAW,CAACc,QALnB,CAAA;AAAA,SAAA;;AAAA,OAAA,CAAA,CAAA;AAAA,KAAA;;AAAA,GAAA,CAAA,CAAA;AASD;;;;;;"}
@@ -1,74 +0,0 @@
1
- import { createContext, useContext, mergeProps, onMount, onCleanup, createComponent } from 'solid-js';
2
-
3
- const defaultContext = createContext(undefined);
4
- const QueryClientSharingContext = createContext(false); // 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
-
12
- function getQueryClientContext(context, contextSharing) {
13
- if (context) {
14
- return context;
15
- }
16
-
17
- if (contextSharing && typeof window !== 'undefined') {
18
- if (!window.SolidQueryClientContext) {
19
- window.SolidQueryClientContext = defaultContext;
20
- }
21
-
22
- return window.SolidQueryClientContext;
23
- }
24
-
25
- return defaultContext;
26
- }
27
-
28
- const useQueryClient = ({
29
- context
30
- } = {}) => {
31
- const queryClient = useContext(getQueryClientContext(context, useContext(QueryClientSharingContext)));
32
-
33
- if (!queryClient) {
34
- throw new Error('No QueryClient set, use QueryClientProvider to set one');
35
- }
36
-
37
- return queryClient;
38
- };
39
- const QueryClientProvider = props => {
40
- const mergedProps = mergeProps({
41
- contextSharing: false
42
- }, props);
43
- onMount(() => {
44
- mergedProps.client.mount();
45
-
46
- if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {
47
- mergedProps.client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
48
- }
49
- });
50
- onCleanup(() => mergedProps.client.unmount());
51
- const QueryClientContext = getQueryClientContext(mergedProps.context, mergedProps.contextSharing);
52
- return createComponent(QueryClientSharingContext.Provider, {
53
- get value() {
54
- return !mergedProps.context && mergedProps.contextSharing;
55
- },
56
-
57
- get children() {
58
- return createComponent(QueryClientContext.Provider, {
59
- get value() {
60
- return mergedProps.client;
61
- },
62
-
63
- get children() {
64
- return mergedProps.children;
65
- }
66
-
67
- });
68
- }
69
-
70
- });
71
- };
72
-
73
- export { QueryClientProvider, defaultContext, useQueryClient };
74
- //# sourceMappingURL=QueryClientProvider.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"QueryClientProvider.mjs","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from '@tanstack/query-core'\nimport type { Context, JSX } from 'solid-js'\nimport {\n createContext,\n useContext,\n onMount,\n onCleanup,\n mergeProps,\n} from 'solid-js'\nimport type { ContextOptions } from './types'\n\ndeclare global {\n interface Window {\n SolidQueryClientContext?: Context<QueryClient | undefined>\n }\n}\n\nexport const defaultContext = createContext<QueryClient | undefined>(undefined)\nconst QueryClientSharingContext = createContext<boolean>(false)\n\n// If we are given a context, we will use it.\n// Otherwise, if contextSharing is on, we share the first and at least one\n// instance of the context across the window\n// to ensure that if Solid Query is used across\n// different bundles or microfrontends they will\n// all use the same **instance** of context, regardless\n// of module scoping.\nfunction getQueryClientContext(\n context: Context<QueryClient | undefined> | undefined,\n contextSharing: boolean,\n) {\n if (context) {\n return context\n }\n if (contextSharing && typeof window !== 'undefined') {\n if (!window.SolidQueryClientContext) {\n window.SolidQueryClientContext = defaultContext\n }\n\n return window.SolidQueryClientContext\n }\n\n return defaultContext\n}\n\nexport const useQueryClient = ({ context }: ContextOptions = {}) => {\n const queryClient = useContext(\n getQueryClientContext(context, useContext(QueryClientSharingContext)),\n )\n\n if (!queryClient) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return queryClient\n}\n\ntype QueryClientProviderPropsBase = {\n client: QueryClient\n children?: JSX.Element\n}\ntype QueryClientProviderPropsWithContext = ContextOptions & {\n contextSharing?: never\n} & QueryClientProviderPropsBase\ntype QueryClientProviderPropsWithContextSharing = {\n context?: never\n contextSharing?: boolean\n} & QueryClientProviderPropsBase\n\nexport type QueryClientProviderProps =\n | QueryClientProviderPropsWithContext\n | QueryClientProviderPropsWithContextSharing\n\nexport const QueryClientProvider = (\n props: QueryClientProviderProps,\n): JSX.Element => {\n const mergedProps = mergeProps(\n {\n contextSharing: false,\n },\n props,\n )\n onMount(() => {\n mergedProps.client.mount()\n\n if (process.env.NODE_ENV !== 'production' && mergedProps.contextSharing) {\n mergedProps.client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n })\n onCleanup(() => mergedProps.client.unmount())\n\n const QueryClientContext = getQueryClientContext(\n mergedProps.context,\n mergedProps.contextSharing,\n )\n\n return (\n <QueryClientSharingContext.Provider\n value={!mergedProps.context && mergedProps.contextSharing}\n >\n <QueryClientContext.Provider value={mergedProps.client}>\n {mergedProps.children}\n </QueryClientContext.Provider>\n </QueryClientSharingContext.Provider>\n )\n}\n"],"names":["defaultContext","createContext","undefined","QueryClientSharingContext","getQueryClientContext","context","contextSharing","window","SolidQueryClientContext","useQueryClient","queryClient","useContext","Error","QueryClientProvider","props","mergedProps","mergeProps","onMount","client","mount","process","env","NODE_ENV","getLogger","error","onCleanup","unmount","QueryClientContext","_$createComponent","children"],"mappings":";;MAiBaA,cAAc,GAAGC,aAAa,CAA0BC,SAA1B,EAApC;AACP,MAAMC,yBAAyB,GAAGF,aAAa,CAAU,KAAV,CAA/C;AAGA;AACA;AACA;AACA;AACA;AACA;;AACA,SAASG,qBAAT,CACEC,OADF,EAEEC,cAFF,EAGE;AACA,EAAA,IAAID,OAAJ,EAAa;AACX,IAAA,OAAOA,OAAP,CAAA;AACD,GAAA;;AACD,EAAA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,CAAhD,CAAA;EAKA,OACGsB,eAAA,CAAA,yBADH,CAC6B,QAD7B,EAAA;AAAA,IAAA,IAEI,KAFJ,GAAA;AAAA,MAAA,OAEW,CAACb,WAAW,CAACV,OAAb,IAAwBU,WAAW,CAACT,cAF/C,CAAA;AAAA,KAAA;;AAAA,IAAA,IAAA,QAAA,GAAA;MAAA,OAIKsB,eAAA,CAAA,kBAJL,CAIwB,QAJxB,EAAA;AAAA,QAAA,IAIiC,KAJjC,GAAA;UAAA,OAIwCb,WAAW,CAACG,MAJpD,CAAA;AAAA,SAAA;;AAAA,QAAA,IAAA,QAAA,GAAA;UAAA,OAKOH,WAAW,CAACc,QALnB,CAAA;AAAA,SAAA;;AAAA,OAAA,CAAA,CAAA;AAAA,KAAA;;AAAA,GAAA,CAAA,CAAA;AASD;;;;"}
@@ -1,4 +0,0 @@
1
- import type { QueryObserver } from '@tanstack/query-core';
2
- import type { QueryKey, QueryObserverResult } from '@tanstack/query-core';
3
- import type { CreateBaseQueryOptions } from './types';
4
- export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(options: CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver): QueryObserverResult<TData, TError>;
@@ -1,93 +0,0 @@
1
- import { useQueryClient } from './QueryClientProvider.esm.js';
2
- import { createResource, batch, onCleanup, onMount, createComputed, on } from 'solid-js';
3
- import { createStore, unwrap } from 'solid-js/store';
4
- import { shouldThrowError } from './utils.esm.js';
5
-
6
- function createBaseQuery(options, Observer) {
7
- const queryClient = useQueryClient({
8
- context: options.context
9
- });
10
- const emptyData = Symbol('empty');
11
- const defaultedOptions = queryClient.defaultQueryOptions(options);
12
- defaultedOptions._optimisticResults = 'optimistic';
13
- const observer = new Observer(queryClient, defaultedOptions);
14
- const [state, setState] = createStore( // @ts-ignore
15
- observer.getOptimisticResult(defaultedOptions));
16
- const [dataResource, {
17
- refetch,
18
- mutate
19
- }] = createResource(() => {
20
- return new Promise(resolve => {
21
- if (!(state.isFetching && state.isLoading)) {
22
- if (unwrap(state.data) === emptyData) {
23
- resolve(undefined);
24
- }
25
-
26
- resolve(unwrap(state.data));
27
- }
28
- });
29
- });
30
- batch(() => {
31
- mutate(() => unwrap(state.data));
32
- refetch();
33
- });
34
- let taskQueue = [];
35
- const unsubscribe = observer.subscribe(result => {
36
- taskQueue.push(() => {
37
- batch(() => {
38
- const unwrappedResult = { ...unwrap(result)
39
- };
40
-
41
- if (unwrappedResult.data === undefined) {
42
- // This is a hack to prevent Solid
43
- // from deleting the data property when it is `undefined`
44
- // ref: https://www.solidjs.com/docs/latest/api#updating-stores
45
- // @ts-ignore
46
- unwrappedResult.data = emptyData;
47
- }
48
-
49
- setState(unwrap(unwrappedResult));
50
- mutate(() => unwrap(result.data));
51
- refetch();
52
- });
53
- });
54
- queueMicrotask(() => {
55
- const taskToRun = taskQueue.pop();
56
-
57
- if (taskToRun) {
58
- taskToRun();
59
- }
60
-
61
- taskQueue = [];
62
- });
63
- });
64
- onCleanup(() => unsubscribe());
65
- onMount(() => {
66
- observer.setOptions(defaultedOptions, {
67
- listeners: false
68
- });
69
- });
70
- createComputed(() => {
71
- const newDefaultedOptions = queryClient.defaultQueryOptions(options);
72
- observer.setOptions(newDefaultedOptions);
73
- });
74
- createComputed(on(() => state.status, () => {
75
- if (state.isError && !state.isFetching && shouldThrowError(observer.options.useErrorBoundary, [state.error, observer.getCurrentQuery()])) {
76
- throw state.error;
77
- }
78
- }));
79
- const handler = {
80
- get(target, prop) {
81
- if (prop === 'data') {
82
- return dataResource();
83
- }
84
-
85
- return Reflect.get(target, prop);
86
- }
87
-
88
- };
89
- return new Proxy(state, handler);
90
- }
91
-
92
- export { createBaseQuery };
93
- //# sourceMappingURL=createBaseQuery.esm.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n const emptyData = Symbol('empty')\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n if (unwrap(state.data) === emptyData) {\n resolve(undefined)\n }\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n const unwrappedResult = { ...unwrap(result) }\n if (unwrappedResult.data === undefined) {\n // This is a hack to prevent Solid\n // from deleting the data property when it is `undefined`\n // ref: https://www.solidjs.com/docs/latest/api#updating-stores\n // @ts-ignore\n unwrappedResult.data = emptyData\n }\n setState(unwrap(unwrappedResult))\n mutate(() => unwrap(result.data))\n refetch()\n })\n })\n\n queueMicrotask(() => {\n const taskToRun = taskQueue.pop()\n if (taskToRun) {\n taskToRun()\n }\n taskQueue = []\n })\n })\n\n onCleanup(() => unsubscribe())\n\n onMount(() => {\n observer.setOptions(defaultedOptions, { listeners: false })\n })\n\n createComputed(() => {\n const newDefaultedOptions = queryClient.defaultQueryOptions(options)\n observer.setOptions(newDefaultedOptions)\n })\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.useErrorBoundary, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n throw state.error\n }\n },\n ),\n )\n\n const handler = {\n get(\n target: QueryObserverResult<TData, TError>,\n prop: keyof QueryObserverResult<TData, TError>,\n ): any {\n if (prop === 'data') {\n return dataResource()\n }\n return Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler) as QueryObserverResult<TData, TError>\n}\n"],"names":["createBaseQuery","options","Observer","queryClient","useQueryClient","context","emptyData","Symbol","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","state","setState","createStore","getOptimisticResult","dataResource","refetch","mutate","createResource","Promise","resolve","isFetching","isLoading","unwrap","data","undefined","batch","taskQueue","unsubscribe","subscribe","result","push","unwrappedResult","queueMicrotask","taskToRun","pop","onCleanup","onMount","setOptions","listeners","createComputed","newDefaultedOptions","on","status","isError","shouldThrowError","useErrorBoundary","error","getCurrentQuery","handler","get","target","prop","Reflect","Proxy"],"mappings":";;;;;AAgBO,SAASA,eAAT,CAOLC,OAPK,EAcLC,QAdK,EAe+B;EACpC,MAAMC,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,SAAS,GAAGC,MAAM,CAAC,OAAD,CAAxB,CAAA;AACA,EAAA,MAAMC,gBAAgB,GAAGL,WAAW,CAACM,mBAAZ,CAAgCR,OAAhC,CAAzB,CAAA;EACAO,gBAAgB,CAACE,kBAAjB,GAAsC,YAAtC,CAAA;EACA,MAAMC,QAAQ,GAAG,IAAIT,QAAJ,CAAaC,WAAb,EAA0BK,gBAA1B,CAAjB,CAAA;AA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GAAG;AACdC,IAAAA,GAAG,CACDC,MADC,EAEDC,IAFC,EAGI;MACL,IAAIA,IAAI,KAAK,MAAb,EAAqB;AACnB,QAAA,OAAOrC,YAAY,EAAnB,CAAA;AACD,OAAA;;AACD,MAAA,OAAOsC,OAAO,CAACH,GAAR,CAAYC,MAAZ,EAAoBC,IAApB,CAAP,CAAA;AACD,KAAA;;GATH,CAAA;AAYA,EAAA,OAAO,IAAIE,KAAJ,CAAU3C,KAAV,EAAiBsC,OAAjB,CAAP,CAAA;AACD;;;;"}
@@ -1,97 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var QueryClientProvider = require('./QueryClientProvider.js');
6
- var solidJs = require('solid-js');
7
- var store = require('solid-js/store');
8
- var utils = require('./utils.js');
9
-
10
- function createBaseQuery(options, Observer) {
11
- const queryClient = QueryClientProvider.useQueryClient({
12
- context: options.context
13
- });
14
- const emptyData = Symbol('empty');
15
- const defaultedOptions = queryClient.defaultQueryOptions(options);
16
- defaultedOptions._optimisticResults = 'optimistic';
17
- const observer = new Observer(queryClient, defaultedOptions);
18
- const [state, setState] = store.createStore( // @ts-ignore
19
- observer.getOptimisticResult(defaultedOptions));
20
- const [dataResource, {
21
- refetch,
22
- mutate
23
- }] = solidJs.createResource(() => {
24
- return new Promise(resolve => {
25
- if (!(state.isFetching && state.isLoading)) {
26
- if (store.unwrap(state.data) === emptyData) {
27
- resolve(undefined);
28
- }
29
-
30
- resolve(store.unwrap(state.data));
31
- }
32
- });
33
- });
34
- solidJs.batch(() => {
35
- mutate(() => store.unwrap(state.data));
36
- refetch();
37
- });
38
- let taskQueue = [];
39
- const unsubscribe = observer.subscribe(result => {
40
- taskQueue.push(() => {
41
- solidJs.batch(() => {
42
- const unwrappedResult = { ...store.unwrap(result)
43
- };
44
-
45
- if (unwrappedResult.data === undefined) {
46
- // This is a hack to prevent Solid
47
- // from deleting the data property when it is `undefined`
48
- // ref: https://www.solidjs.com/docs/latest/api#updating-stores
49
- // @ts-ignore
50
- unwrappedResult.data = emptyData;
51
- }
52
-
53
- setState(store.unwrap(unwrappedResult));
54
- mutate(() => store.unwrap(result.data));
55
- refetch();
56
- });
57
- });
58
- queueMicrotask(() => {
59
- const taskToRun = taskQueue.pop();
60
-
61
- if (taskToRun) {
62
- taskToRun();
63
- }
64
-
65
- taskQueue = [];
66
- });
67
- });
68
- solidJs.onCleanup(() => unsubscribe());
69
- solidJs.onMount(() => {
70
- observer.setOptions(defaultedOptions, {
71
- listeners: false
72
- });
73
- });
74
- solidJs.createComputed(() => {
75
- const newDefaultedOptions = queryClient.defaultQueryOptions(options);
76
- observer.setOptions(newDefaultedOptions);
77
- });
78
- solidJs.createComputed(solidJs.on(() => state.status, () => {
79
- if (state.isError && !state.isFetching && utils.shouldThrowError(observer.options.useErrorBoundary, [state.error, observer.getCurrentQuery()])) {
80
- throw state.error;
81
- }
82
- }));
83
- const handler = {
84
- get(target, prop) {
85
- if (prop === 'data') {
86
- return dataResource();
87
- }
88
-
89
- return Reflect.get(target, prop);
90
- }
91
-
92
- };
93
- return new Proxy(state, handler);
94
- }
95
-
96
- exports.createBaseQuery = createBaseQuery;
97
- //# sourceMappingURL=createBaseQuery.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryKey, QueryObserverResult } from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\n onMount,\n onCleanup,\n createComputed,\n createResource,\n on,\n batch,\n} from 'solid-js'\nimport { createStore, unwrap } from 'solid-js/store'\nimport { shouldThrowError } from './utils'\n\n// Base Query Function that is used to create the query.\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n): QueryObserverResult<TData, TError> {\n const queryClient = useQueryClient({ context: options.context })\n const emptyData = Symbol('empty')\n const defaultedOptions = queryClient.defaultQueryOptions(options)\n defaultedOptions._optimisticResults = 'optimistic'\n const observer = new Observer(queryClient, defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n // @ts-ignore\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const [dataResource, { refetch, mutate }] = createResource<TData | undefined>(\n () => {\n return new Promise((resolve) => {\n if (!(state.isFetching && state.isLoading)) {\n if (unwrap(state.data) === emptyData) {\n resolve(undefined)\n }\n resolve(unwrap(state.data))\n }\n })\n },\n )\n\n batch(() => {\n mutate(() => unwrap(state.data))\n refetch()\n })\n\n let taskQueue: Array<() => void> = []\n\n const unsubscribe = observer.subscribe((result) => {\n taskQueue.push(() => {\n batch(() => {\n const unwrappedResult = { ...unwrap(result) }\n if (unwrappedResult.data === undefined) {\n // This is a hack to prevent Solid\n // from deleting the data property when it is `undefined`\n // ref: https://www.solidjs.com/docs/latest/api#updating-stores\n // @ts-ignore\n unwrappedResult.data = emptyData\n }\n setState(unwrap(unwrappedResult))\n mutate(() => unwrap(result.data))\n refetch()\n })\n })\n\n queueMicrotask(() => {\n const taskToRun = taskQueue.pop()\n if (taskToRun) {\n taskToRun()\n }\n taskQueue = []\n })\n })\n\n onCleanup(() => unsubscribe())\n\n onMount(() => {\n observer.setOptions(defaultedOptions, { listeners: false })\n })\n\n createComputed(() => {\n const newDefaultedOptions = queryClient.defaultQueryOptions(options)\n observer.setOptions(newDefaultedOptions)\n })\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.useErrorBoundary, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n throw state.error\n }\n },\n ),\n )\n\n const handler = {\n get(\n target: QueryObserverResult<TData, TError>,\n prop: keyof QueryObserverResult<TData, TError>,\n ): any {\n if (prop === 'data') {\n return dataResource()\n }\n return Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler) as QueryObserverResult<TData, TError>\n}\n"],"names":["createBaseQuery","options","Observer","queryClient","useQueryClient","context","emptyData","Symbol","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","state","setState","createStore","getOptimisticResult","dataResource","refetch","mutate","createResource","Promise","resolve","isFetching","isLoading","unwrap","data","undefined","batch","taskQueue","unsubscribe","subscribe","result","push","unwrappedResult","queueMicrotask","taskToRun","pop","onCleanup","onMount","setOptions","listeners","createComputed","newDefaultedOptions","on","status","isError","shouldThrowError","useErrorBoundary","error","getCurrentQuery","handler","get","target","prop","Reflect","Proxy"],"mappings":";;;;;;;;;AAgBO,SAASA,eAAT,CAOLC,OAPK,EAcLC,QAdK,EAe+B;EACpC,MAAMC,WAAW,GAAGC,kCAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,SAAS,GAAGC,MAAM,CAAC,OAAD,CAAxB,CAAA;AACA,EAAA,MAAMC,gBAAgB,GAAGL,WAAW,CAACM,mBAAZ,CAAgCR,OAAhC,CAAzB,CAAA;EACAO,gBAAgB,CAACE,kBAAjB,GAAsC,YAAtC,CAAA;EACA,MAAMC,QAAQ,GAAG,IAAIT,QAAJ,CAAaC,WAAb,EAA0BK,gBAA1B,CAAjB,CAAA;AAEA,EAAA,MAAM,CAACI,KAAD,EAAQC,QAAR,CAAA,GAAoBC,iBAAW;AAEnCH,EAAAA,QAAQ,CAACI,mBAAT,CAA6BP,gBAA7B,CAFmC,CAArC,CAAA;EAKA,MAAM,CAACQ,YAAD,EAAe;IAAEC,OAAF;AAAWC,IAAAA,MAAAA;GAA1B,CAAA,GAAsCC,sBAAc,CACxD,MAAM;AACJ,IAAA,OAAO,IAAIC,OAAJ,CAAaC,OAAD,IAAa;MAC9B,IAAI,EAAET,KAAK,CAACU,UAAN,IAAoBV,KAAK,CAACW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