@tanstack/solid-query 5.0.0-alpha.51 → 5.0.0-alpha.52

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 (50) hide show
  1. package/build/lib/QueryClient.cjs +12 -0
  2. package/build/lib/QueryClient.cjs.map +1 -0
  3. package/build/lib/QueryClient.js +10 -0
  4. package/build/lib/QueryClient.js.map +1 -0
  5. package/build/lib/QueryClientProvider.cjs +35 -0
  6. package/build/lib/QueryClientProvider.cjs.map +1 -0
  7. package/build/lib/QueryClientProvider.js +31 -0
  8. package/build/lib/QueryClientProvider.js.map +1 -0
  9. package/build/lib/createBaseQuery.cjs +192 -0
  10. package/build/lib/createBaseQuery.cjs.map +1 -0
  11. package/build/lib/createBaseQuery.js +190 -0
  12. package/build/lib/createBaseQuery.js.map +1 -0
  13. package/build/lib/createInfiniteQuery.cjs +14 -0
  14. package/build/lib/createInfiniteQuery.cjs.map +1 -0
  15. package/build/lib/createInfiniteQuery.js +12 -0
  16. package/build/lib/createInfiniteQuery.js.map +1 -0
  17. package/build/lib/createMutation.cjs +44 -0
  18. package/build/lib/createMutation.cjs.map +1 -0
  19. package/build/lib/createMutation.js +42 -0
  20. package/build/lib/createMutation.js.map +1 -0
  21. package/build/lib/createQueries.cjs +52 -0
  22. package/build/lib/createQueries.cjs.map +1 -0
  23. package/build/lib/createQueries.js +50 -0
  24. package/build/lib/createQueries.js.map +1 -0
  25. package/build/lib/createQuery.cjs +16 -0
  26. package/build/lib/createQuery.cjs.map +1 -0
  27. package/build/lib/createQuery.js +13 -0
  28. package/build/lib/createQuery.js.map +1 -0
  29. package/build/lib/index.cjs.map +1 -0
  30. package/build/lib/index.js +11 -0
  31. package/build/lib/index.js.map +1 -0
  32. package/build/lib/setBatchUpdatesFn.cjs +7 -0
  33. package/build/lib/setBatchUpdatesFn.cjs.map +1 -0
  34. package/build/lib/setBatchUpdatesFn.js +5 -0
  35. package/build/lib/setBatchUpdatesFn.js.map +1 -0
  36. package/build/lib/useIsFetching.cjs +18 -0
  37. package/build/lib/useIsFetching.cjs.map +1 -0
  38. package/build/lib/useIsFetching.js +16 -0
  39. package/build/lib/useIsFetching.js.map +1 -0
  40. package/build/lib/useIsMutating.cjs +18 -0
  41. package/build/lib/useIsMutating.cjs.map +1 -0
  42. package/build/lib/useIsMutating.js +16 -0
  43. package/build/lib/useIsMutating.js.map +1 -0
  44. package/build/lib/utils.cjs +12 -0
  45. package/build/lib/utils.cjs.map +1 -0
  46. package/build/lib/utils.js +10 -0
  47. package/build/lib/utils.js.map +1 -0
  48. package/build/stats-html.html +6177 -0
  49. package/build/stats.json +605 -0
  50. package/package.json +2 -5
@@ -0,0 +1,12 @@
1
+ 'use strict';
2
+
3
+ var queryCore = require('@tanstack/query-core');
4
+
5
+ class QueryClient extends queryCore.QueryClient {
6
+ constructor(config = {}) {
7
+ super(config);
8
+ }
9
+ }
10
+
11
+ exports.QueryClient = QueryClient;
12
+ //# sourceMappingURL=QueryClient.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClient.cjs","sources":["../../src/QueryClient.ts"],"sourcesContent":["import type {\n QueryClientConfig as QueryCoreClientConfig,\n DefaultOptions as CoreDefaultOptions,\n QueryObserverOptions as QueryCoreObserverOptions,\n InfiniteQueryObserverOptions as QueryCoreInfiniteQueryObserverOptions,\n DefaultError,\n QueryKey,\n} from '@tanstack/query-core'\nimport { QueryClient as QueryCoreClient } from '@tanstack/query-core'\n\nexport interface QueryObserverOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> extends Omit<\n QueryCoreObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n 'structuralSharing'\n > {\n /**\n * Set this to a reconciliation key to enable reconciliation between query results.\n * Set this to `false` to disable reconciliation between query results.\n * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.\n * Defaults reconciliation key to `id`.\n */\n reconcile?:\n | string\n | false\n | ((oldData: TData | undefined, newData: TData) => TData)\n}\n\nexport interface InfiniteQueryObserverOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends Omit<\n QueryCoreInfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n 'structuralSharing'\n > {\n /**\n * Set this to a reconciliation key to enable reconciliation between query results.\n * Set this to `false` to disable reconciliation between query results.\n * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.\n * Defaults reconciliation key to `id`.\n */\n reconcile?:\n | string\n | false\n | ((oldData: TData | undefined, newData: TData) => TData)\n}\n\nexport interface DefaultOptions<TError = DefaultError>\n extends CoreDefaultOptions<TError> {\n queries?: QueryObserverOptions<unknown, TError>\n}\n\nexport interface QueryClientConfig extends QueryCoreClientConfig {\n defaultOptions?: DefaultOptions\n}\n\nexport class QueryClient extends QueryCoreClient {\n constructor(config: QueryClientConfig = {}) {\n super(config)\n }\n}\n"],"names":["QueryClient","QueryCoreClient","constructor","config"],"mappings":";;;;AA+EO,MAAMA,WAAW,SAASC,qBAAe,CAAC;AAC/CC,EAAAA,WAAWA,CAACC,MAAyB,GAAG,EAAE,EAAE;IAC1C,KAAK,CAACA,MAAM,CAAC,CAAA;AACf,GAAA;AACF;;;;"}
@@ -0,0 +1,10 @@
1
+ import { QueryClient as QueryClient$1 } from '@tanstack/query-core';
2
+
3
+ class QueryClient extends QueryClient$1 {
4
+ constructor(config = {}) {
5
+ super(config);
6
+ }
7
+ }
8
+
9
+ export { QueryClient };
10
+ //# sourceMappingURL=QueryClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClient.js","sources":["../../src/QueryClient.ts"],"sourcesContent":["import type {\n QueryClientConfig as QueryCoreClientConfig,\n DefaultOptions as CoreDefaultOptions,\n QueryObserverOptions as QueryCoreObserverOptions,\n InfiniteQueryObserverOptions as QueryCoreInfiniteQueryObserverOptions,\n DefaultError,\n QueryKey,\n} from '@tanstack/query-core'\nimport { QueryClient as QueryCoreClient } from '@tanstack/query-core'\n\nexport interface QueryObserverOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = never,\n> extends Omit<\n QueryCoreObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n 'structuralSharing'\n > {\n /**\n * Set this to a reconciliation key to enable reconciliation between query results.\n * Set this to `false` to disable reconciliation between query results.\n * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.\n * Defaults reconciliation key to `id`.\n */\n reconcile?:\n | string\n | false\n | ((oldData: TData | undefined, newData: TData) => TData)\n}\n\nexport interface InfiniteQueryObserverOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> extends Omit<\n QueryCoreInfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n 'structuralSharing'\n > {\n /**\n * Set this to a reconciliation key to enable reconciliation between query results.\n * Set this to `false` to disable reconciliation between query results.\n * Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom reconciliation logic.\n * Defaults reconciliation key to `id`.\n */\n reconcile?:\n | string\n | false\n | ((oldData: TData | undefined, newData: TData) => TData)\n}\n\nexport interface DefaultOptions<TError = DefaultError>\n extends CoreDefaultOptions<TError> {\n queries?: QueryObserverOptions<unknown, TError>\n}\n\nexport interface QueryClientConfig extends QueryCoreClientConfig {\n defaultOptions?: DefaultOptions\n}\n\nexport class QueryClient extends QueryCoreClient {\n constructor(config: QueryClientConfig = {}) {\n super(config)\n }\n}\n"],"names":["QueryClient","QueryCoreClient","constructor","config"],"mappings":";;AA+EO,MAAMA,WAAW,SAASC,aAAe,CAAC;AAC/CC,EAAAA,WAAWA,CAACC,MAAyB,GAAG,EAAE,EAAE;IAC1C,KAAK,CAACA,MAAM,CAAC,CAAA;AACf,GAAA;AACF;;;;"}
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ var web = require('solid-js/web');
4
+ var solidJs = require('solid-js');
5
+
6
+ const QueryClientContext = solidJs.createContext(undefined);
7
+ const useQueryClient = queryClient => {
8
+ const client = solidJs.useContext(QueryClientContext);
9
+ if (queryClient) {
10
+ return queryClient;
11
+ }
12
+ if (!client) {
13
+ throw new Error('No QueryClient set, use QueryClientProvider to set one');
14
+ }
15
+ return client;
16
+ };
17
+ const QueryClientProvider = props => {
18
+ solidJs.onMount(() => {
19
+ props.client.mount();
20
+ });
21
+ solidJs.onCleanup(() => props.client.unmount());
22
+ return web.createComponent(QueryClientContext.Provider, {
23
+ get value() {
24
+ return props.client;
25
+ },
26
+ get children() {
27
+ return props.children;
28
+ }
29
+ });
30
+ };
31
+
32
+ exports.QueryClientContext = QueryClientContext;
33
+ exports.QueryClientProvider = QueryClientProvider;
34
+ exports.useQueryClient = useQueryClient;
35
+ //# sourceMappingURL=QueryClientProvider.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.cjs","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from './QueryClient'\nimport type { JSX } from 'solid-js'\nimport { createContext, useContext, onMount, onCleanup } from 'solid-js'\n\nexport const QueryClientContext = createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: JSX.Element\n}\n\nexport const QueryClientProvider = (\n props: QueryClientProviderProps,\n): JSX.Element => {\n onMount(() => {\n props.client.mount()\n })\n onCleanup(() => props.client.unmount())\n\n return (\n <QueryClientContext.Provider value={props.client}>\n {props.children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["QueryClientContext","createContext","undefined","useQueryClient","queryClient","client","useContext","Error","QueryClientProvider","props","onMount","mount","onCleanup","unmount","_$createComponent","Provider","value","children"],"mappings":";;;;;MAIaA,kBAAkB,GAAGC,qBAAa,CAC7CC,SACF,EAAC;AAEYC,MAAAA,cAAc,GAAIC,WAAyB,IAAK;AAC3D,EAAA,MAAMC,MAAM,GAAGC,kBAAU,CAACN,kBAAkB,CAAC,CAAA;AAE7C,EAAA,IAAII,WAAW,EAAE;AACf,IAAA,OAAOA,WAAW,CAAA;AACpB,GAAA;EAEA,IAAI,CAACC,MAAM,EAAE;AACX,IAAA,MAAM,IAAIE,KAAK,CAAC,wDAAwD,CAAC,CAAA;AAC3E,GAAA;AAEA,EAAA,OAAOF,MAAM,CAAA;AACf,EAAC;AAOYG,MAAAA,mBAAmB,GAC9BC,KAA+B,IACf;AAChBC,EAAAA,eAAO,CAAC,MAAM;AACZD,IAAAA,KAAK,CAACJ,MAAM,CAACM,KAAK,EAAE,CAAA;AACtB,GAAC,CAAC,CAAA;EACFC,iBAAS,CAAC,MAAMH,KAAK,CAACJ,MAAM,CAACQ,OAAO,EAAE,CAAC,CAAA;AAEvC,EAAA,OAAAC,mBAAA,CACGd,kBAAkB,CAACe,QAAQ,EAAA;AAAA,IAAA,IAACC,KAAKA,GAAA;MAAA,OAAEP,KAAK,CAACJ,MAAM,CAAA;AAAA,KAAA;AAAA,IAAA,IAAAY,QAAA,GAAA;MAAA,OAC7CR,KAAK,CAACQ,QAAQ,CAAA;AAAA,KAAA;AAAA,GAAA,CAAA,CAAA;AAGrB;;;;;;"}
@@ -0,0 +1,31 @@
1
+ import { createComponent } from 'solid-js/web';
2
+ import { createContext, useContext, onMount, onCleanup } from 'solid-js';
3
+
4
+ const QueryClientContext = createContext(undefined);
5
+ const useQueryClient = queryClient => {
6
+ const client = useContext(QueryClientContext);
7
+ if (queryClient) {
8
+ return queryClient;
9
+ }
10
+ if (!client) {
11
+ throw new Error('No QueryClient set, use QueryClientProvider to set one');
12
+ }
13
+ return client;
14
+ };
15
+ const QueryClientProvider = props => {
16
+ onMount(() => {
17
+ props.client.mount();
18
+ });
19
+ onCleanup(() => props.client.unmount());
20
+ return createComponent(QueryClientContext.Provider, {
21
+ get value() {
22
+ return props.client;
23
+ },
24
+ get children() {
25
+ return props.children;
26
+ }
27
+ });
28
+ };
29
+
30
+ export { QueryClientContext, QueryClientProvider, useQueryClient };
31
+ //# sourceMappingURL=QueryClientProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"QueryClientProvider.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["import type { QueryClient } from './QueryClient'\nimport type { JSX } from 'solid-js'\nimport { createContext, useContext, onMount, onCleanup } from 'solid-js'\n\nexport const QueryClientContext = createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: JSX.Element\n}\n\nexport const QueryClientProvider = (\n props: QueryClientProviderProps,\n): JSX.Element => {\n onMount(() => {\n props.client.mount()\n })\n onCleanup(() => props.client.unmount())\n\n return (\n <QueryClientContext.Provider value={props.client}>\n {props.children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["QueryClientContext","createContext","undefined","useQueryClient","queryClient","client","useContext","Error","QueryClientProvider","props","onMount","mount","onCleanup","unmount","_$createComponent","Provider","value","children"],"mappings":";;;MAIaA,kBAAkB,GAAGC,aAAa,CAC7CC,SACF,EAAC;AAEYC,MAAAA,cAAc,GAAIC,WAAyB,IAAK;AAC3D,EAAA,MAAMC,MAAM,GAAGC,UAAU,CAACN,kBAAkB,CAAC,CAAA;AAE7C,EAAA,IAAII,WAAW,EAAE;AACf,IAAA,OAAOA,WAAW,CAAA;AACpB,GAAA;EAEA,IAAI,CAACC,MAAM,EAAE;AACX,IAAA,MAAM,IAAIE,KAAK,CAAC,wDAAwD,CAAC,CAAA;AAC3E,GAAA;AAEA,EAAA,OAAOF,MAAM,CAAA;AACf,EAAC;AAOYG,MAAAA,mBAAmB,GAC9BC,KAA+B,IACf;AAChBC,EAAAA,OAAO,CAAC,MAAM;AACZD,IAAAA,KAAK,CAACJ,MAAM,CAACM,KAAK,EAAE,CAAA;AACtB,GAAC,CAAC,CAAA;EACFC,SAAS,CAAC,MAAMH,KAAK,CAACJ,MAAM,CAACQ,OAAO,EAAE,CAAC,CAAA;AAEvC,EAAA,OAAAC,eAAA,CACGd,kBAAkB,CAACe,QAAQ,EAAA;AAAA,IAAA,IAACC,KAAKA,GAAA;MAAA,OAAEP,KAAK,CAACJ,MAAM,CAAA;AAAA,KAAA;AAAA,IAAA,IAAAY,QAAA,GAAA;MAAA,OAC7CR,KAAK,CAACQ,QAAQ,CAAA;AAAA,KAAA;AAAA,GAAA,CAAA,CAAA;AAGrB;;;;"}
@@ -0,0 +1,192 @@
1
+ 'use strict';
2
+
3
+ var queryCore = require('@tanstack/query-core');
4
+ var web = require('solid-js/web');
5
+ var solidJs = require('solid-js');
6
+ var store = require('solid-js/store');
7
+ var QueryClientProvider = require('./QueryClientProvider.cjs');
8
+ var utils = require('./utils.cjs');
9
+
10
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
11
+ // Had to disable the lint rule because isServer type is defined as false
12
+ // in solid-js/web package. I'll create a GitHub issue with them to see
13
+ // why that happens.
14
+
15
+ function reconcileFn(store$1, result, reconcileOption) {
16
+ if (reconcileOption === false) return result;
17
+ if (typeof reconcileOption === 'function') {
18
+ const newData = reconcileOption(store$1.data, result.data);
19
+ return {
20
+ ...result,
21
+ data: newData
22
+ };
23
+ }
24
+ const newData = store.reconcile(result.data, {
25
+ key: reconcileOption
26
+ })(store$1.data);
27
+ return {
28
+ ...result,
29
+ data: newData
30
+ };
31
+ }
32
+
33
+ // Base Query Function that is used to create the query.
34
+ function createBaseQuery(options, Observer, queryClient) {
35
+ const client = solidJs.createMemo(() => QueryClientProvider.useQueryClient(queryClient?.()));
36
+ const defaultedOptions = client().defaultQueryOptions(options());
37
+ defaultedOptions._optimisticResults = 'optimistic';
38
+ defaultedOptions.structuralSharing = false;
39
+ if (web.isServer) {
40
+ defaultedOptions.retry = false;
41
+ defaultedOptions.throwOnError = true;
42
+ }
43
+ const observer = new Observer(client(), defaultedOptions);
44
+ const [state, setState] = store.createStore(observer.getOptimisticResult(defaultedOptions));
45
+ const createServerSubscriber = (resolve, reject) => {
46
+ return observer.subscribe(result => {
47
+ queryCore.notifyManager.batchCalls(() => {
48
+ const query = observer.getCurrentQuery();
49
+ const {
50
+ refetch,
51
+ ...rest
52
+ } = store.unwrap(result);
53
+ const unwrappedResult = {
54
+ ...rest,
55
+ // hydrate() expects a QueryState object, which is similar but not
56
+ // quite the same as a QueryObserverResult object. Thus, for now, we're
57
+ // copying over the missing properties from state in order to support hydration
58
+ dataUpdateCount: query.state.dataUpdateCount,
59
+ fetchFailureCount: query.state.fetchFailureCount,
60
+ // Removing these properties since they might not be serializable
61
+ // fetchFailureReason: query.state.fetchFailureReason,
62
+ // fetchMeta: query.state.fetchMeta,
63
+ isInvalidated: query.state.isInvalidated
64
+ };
65
+ if (unwrappedResult.isError) {
66
+ if (process.env['NODE_ENV'] === 'development') {
67
+ console.error(unwrappedResult.error);
68
+ }
69
+ reject(unwrappedResult.error);
70
+ }
71
+ if (unwrappedResult.isSuccess) {
72
+ // Use of any here is fine
73
+ // We cannot include refetch since it is not serializable
74
+ resolve(unwrappedResult);
75
+ }
76
+ })();
77
+ });
78
+ };
79
+ const createClientSubscriber = () => {
80
+ return observer.subscribe(result => {
81
+ queryCore.notifyManager.batchCalls(() => {
82
+ // @ts-expect-error - This will error because the reconcile option does not
83
+ // exist on the query-core QueryObserverResult type
84
+ const reconcileOptions = observer.options.reconcile;
85
+ // If the query has data we dont suspend but instead mutate the resource
86
+ // This could happen when placeholderData/initialData is defined
87
+ if (queryResource()?.data && result.data && !queryResource.loading) {
88
+ setState(store => {
89
+ return reconcileFn(store, result, reconcileOptions === undefined ? 'id' : reconcileOptions);
90
+ });
91
+ mutate(state);
92
+ } else {
93
+ setState(store => {
94
+ return reconcileFn(store, result, reconcileOptions === undefined ? 'id' : reconcileOptions);
95
+ });
96
+ refetch();
97
+ }
98
+ })();
99
+ });
100
+ };
101
+
102
+ /**
103
+ * Unsubscribe is set lazily, so that we can subscribe after hydration when needed.
104
+ */
105
+ let unsubscribe = null;
106
+ const [queryResource, {
107
+ refetch,
108
+ mutate
109
+ }] = solidJs.createResource(() => {
110
+ return new Promise((resolve, reject) => {
111
+ if (web.isServer) {
112
+ unsubscribe = createServerSubscriber(resolve, reject);
113
+ } else {
114
+ if (!unsubscribe) {
115
+ unsubscribe = createClientSubscriber();
116
+ }
117
+ }
118
+ if (!state.isLoading) {
119
+ resolve(state);
120
+ }
121
+ });
122
+ }, {
123
+ initialValue: state,
124
+ // If initialData is provided, we resolve the resource immediately
125
+ ssrLoadFrom: options().initialData ? 'initial' : 'server',
126
+ get deferStream() {
127
+ return options().deferStream;
128
+ },
129
+ /**
130
+ * If this resource was populated on the server (either sync render, or streamed in over time), onHydrated
131
+ * will be called. This is the point at which we can hydrate the query cache state, and setup the query subscriber.
132
+ *
133
+ * Leveraging onHydrated allows us to plug into the async and streaming support that solidjs resources already support.
134
+ *
135
+ * Note that this is only invoked on the client, for queries that were originally run on the server.
136
+ */
137
+ onHydrated(_k, info) {
138
+ if (info.value) {
139
+ queryCore.hydrate(client(), {
140
+ queries: [{
141
+ queryKey: defaultedOptions.queryKey,
142
+ queryHash: defaultedOptions.queryHash,
143
+ state: info.value
144
+ }]
145
+ });
146
+ }
147
+ if (!unsubscribe) {
148
+ /**
149
+ * Do not refetch query on mount if query was fetched on server,
150
+ * even if `staleTime` is not set.
151
+ */
152
+ const newOptions = {
153
+ ...defaultedOptions
154
+ };
155
+ if (defaultedOptions.staleTime || !defaultedOptions.initialData) {
156
+ newOptions.refetchOnMount = false;
157
+ }
158
+ // Setting the options as an immutable object to prevent
159
+ // wonky behavior with observer subscriptions
160
+ observer.setOptions(newOptions);
161
+ setState(observer.getOptimisticResult(newOptions));
162
+ unsubscribe = createClientSubscriber();
163
+ }
164
+ }
165
+ });
166
+ solidJs.onCleanup(() => {
167
+ if (unsubscribe) {
168
+ unsubscribe();
169
+ unsubscribe = null;
170
+ }
171
+ });
172
+ solidJs.createComputed(solidJs.on(() => client().defaultQueryOptions(options()), () => observer.setOptions(client().defaultQueryOptions(options())), {
173
+ // Defer because we don't need to trigger on first render
174
+ // This only cares about changes to options after the observer is created
175
+ defer: true
176
+ }));
177
+ solidJs.createComputed(solidJs.on(() => state.status, () => {
178
+ if (state.isError && !state.isFetching && utils.shouldThrowError(observer.options.throwOnError, [state.error, observer.getCurrentQuery()])) {
179
+ throw state.error;
180
+ }
181
+ }));
182
+ const handler = {
183
+ get(target, prop) {
184
+ const val = queryResource()?.[prop];
185
+ return val !== undefined ? val : Reflect.get(target, prop);
186
+ }
187
+ };
188
+ return new Proxy(state, handler);
189
+ }
190
+
191
+ exports.createBaseQuery = createBaseQuery;
192
+ //# sourceMappingURL=createBaseQuery.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBaseQuery.cjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unnecessary-condition */\n// Had to disable the lint rule because isServer type is defined as false\n// in solid-js/web package. I'll create a GitHub issue with them to see\n// why that happens.\nimport type {\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './QueryClient'\nimport { hydrate, notifyManager } from '@tanstack/query-core'\nimport type { Accessor } from 'solid-js'\nimport { isServer } from 'solid-js/web'\nimport {\n createComputed,\n createMemo,\n createResource,\n on,\n onCleanup,\n} from 'solid-js'\nimport { createStore, reconcile, unwrap } from 'solid-js/store'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { CreateBaseQueryOptions } from './types'\nimport { shouldThrowError } from './utils'\n\nfunction reconcileFn<TData, TError>(\n store: QueryObserverResult<TData, TError>,\n result: QueryObserverResult<TData, TError>,\n reconcileOption:\n | string\n | false\n | ((oldData: TData | undefined, newData: TData) => TData),\n): QueryObserverResult<TData, TError> {\n if (reconcileOption === false) return result\n if (typeof reconcileOption === 'function') {\n const newData = reconcileOption(store.data, result.data as TData)\n return { ...result, data: newData } as typeof result\n }\n const newData = reconcile(result.data, { key: reconcileOption })(store.data)\n return { ...result, data: newData } as typeof result\n}\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: Accessor<\n CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n >,\n Observer: typeof QueryObserver,\n queryClient?: Accessor<QueryClient>,\n) {\n const client = createMemo(() => useQueryClient(queryClient?.()))\n\n const defaultedOptions = client().defaultQueryOptions(options())\n defaultedOptions._optimisticResults = 'optimistic'\n defaultedOptions.structuralSharing = false\n if (isServer) {\n defaultedOptions.retry = false\n defaultedOptions.throwOnError = true\n }\n const observer = new Observer(client(), defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const createServerSubscriber = (\n resolve: (\n data:\n | QueryObserverResult<TData, TError>\n | PromiseLike<QueryObserverResult<TData, TError> | undefined>\n | undefined,\n ) => void,\n reject: (reason?: any) => void,\n ) => {\n return observer.subscribe((result) => {\n notifyManager.batchCalls(() => {\n const query = observer.getCurrentQuery()\n const { refetch, ...rest } = unwrap(result)\n const unwrappedResult = {\n ...rest,\n\n // hydrate() expects a QueryState object, which is similar but not\n // quite the same as a QueryObserverResult object. Thus, for now, we're\n // copying over the missing properties from state in order to support hydration\n dataUpdateCount: query.state.dataUpdateCount,\n fetchFailureCount: query.state.fetchFailureCount,\n // Removing these properties since they might not be serializable\n // fetchFailureReason: query.state.fetchFailureReason,\n // fetchMeta: query.state.fetchMeta,\n isInvalidated: query.state.isInvalidated,\n }\n\n if (unwrappedResult.isError) {\n if (process.env['NODE_ENV'] === 'development') {\n console.error(unwrappedResult.error)\n }\n reject(unwrappedResult.error)\n }\n if (unwrappedResult.isSuccess) {\n // Use of any here is fine\n // We cannot include refetch since it is not serializable\n resolve(unwrappedResult as any)\n }\n })()\n })\n }\n\n const createClientSubscriber = () => {\n return observer.subscribe((result) => {\n notifyManager.batchCalls(() => {\n // @ts-expect-error - This will error because the reconcile option does not\n // exist on the query-core QueryObserverResult type\n const reconcileOptions = observer.options.reconcile\n // If the query has data we dont suspend but instead mutate the resource\n // This could happen when placeholderData/initialData is defined\n if (queryResource()?.data && result.data && !queryResource.loading) {\n setState((store) => {\n return reconcileFn(\n store,\n result,\n reconcileOptions === undefined ? 'id' : reconcileOptions,\n )\n })\n mutate(state)\n } else {\n setState((store) => {\n return reconcileFn(\n store,\n result,\n reconcileOptions === undefined ? 'id' : reconcileOptions,\n )\n })\n refetch()\n }\n })()\n })\n }\n\n /**\n * Unsubscribe is set lazily, so that we can subscribe after hydration when needed.\n */\n let unsubscribe: (() => void) | null = null\n\n const [queryResource, { refetch, mutate }] = createResource<\n QueryObserverResult<TData, TError> | undefined\n >(\n () => {\n return new Promise((resolve, reject) => {\n if (isServer) {\n unsubscribe = createServerSubscriber(resolve, reject)\n } else {\n if (!unsubscribe) {\n unsubscribe = createClientSubscriber()\n }\n }\n if (!state.isLoading) {\n resolve(state)\n }\n })\n },\n {\n initialValue: state,\n\n // If initialData is provided, we resolve the resource immediately\n ssrLoadFrom: options().initialData ? 'initial' : 'server',\n\n get deferStream() {\n return options().deferStream\n },\n\n /**\n * If this resource was populated on the server (either sync render, or streamed in over time), onHydrated\n * will be called. This is the point at which we can hydrate the query cache state, and setup the query subscriber.\n *\n * Leveraging onHydrated allows us to plug into the async and streaming support that solidjs resources already support.\n *\n * Note that this is only invoked on the client, for queries that were originally run on the server.\n */\n onHydrated(_k, info) {\n if (info.value) {\n hydrate(client(), {\n queries: [\n {\n queryKey: defaultedOptions.queryKey,\n queryHash: defaultedOptions.queryHash,\n state: info.value,\n },\n ],\n })\n }\n\n if (!unsubscribe) {\n /**\n * Do not refetch query on mount if query was fetched on server,\n * even if `staleTime` is not set.\n */\n const newOptions = { ...defaultedOptions }\n if (defaultedOptions.staleTime || !defaultedOptions.initialData) {\n newOptions.refetchOnMount = false\n }\n // Setting the options as an immutable object to prevent\n // wonky behavior with observer subscriptions\n observer.setOptions(newOptions)\n setState(observer.getOptimisticResult(newOptions))\n unsubscribe = createClientSubscriber()\n }\n },\n },\n )\n\n onCleanup(() => {\n if (unsubscribe) {\n unsubscribe()\n unsubscribe = null\n }\n })\n\n createComputed(\n on(\n () => client().defaultQueryOptions(options()),\n () => observer.setOptions(client().defaultQueryOptions(options())),\n {\n // Defer because we don't need to trigger on first render\n // This only cares about changes to options after the observer is created\n defer: true,\n },\n ),\n )\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.throwOnError, [\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 const val = queryResource()?.[prop]\n return val !== undefined ? val : Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler)\n}\n"],"names":["reconcileFn","store","result","reconcileOption","newData","data","reconcile","key","createBaseQuery","options","Observer","queryClient","client","createMemo","useQueryClient","defaultedOptions","defaultQueryOptions","_optimisticResults","structuralSharing","isServer","retry","throwOnError","observer","state","setState","createStore","getOptimisticResult","createServerSubscriber","resolve","reject","subscribe","notifyManager","batchCalls","query","getCurrentQuery","refetch","rest","unwrap","unwrappedResult","dataUpdateCount","fetchFailureCount","isInvalidated","isError","process","env","console","error","isSuccess","createClientSubscriber","reconcileOptions","queryResource","loading","undefined","mutate","unsubscribe","createResource","Promise","isLoading","initialValue","ssrLoadFrom","initialData","deferStream","onHydrated","_k","info","value","hydrate","queries","queryKey","queryHash","newOptions","staleTime","refetchOnMount","setOptions","onCleanup","createComputed","on","defer","status","isFetching","shouldThrowError","handler","get","target","prop","val","Reflect","Proxy"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;;AAsBA,SAASA,WAAWA,CAClBC,OAAyC,EACzCC,MAA0C,EAC1CC,eAG2D,EACvB;AACpC,EAAA,IAAIA,eAAe,KAAK,KAAK,EAAE,OAAOD,MAAM,CAAA;AAC5C,EAAA,IAAI,OAAOC,eAAe,KAAK,UAAU,EAAE;IACzC,MAAMC,OAAO,GAAGD,eAAe,CAACF,OAAK,CAACI,IAAI,EAAEH,MAAM,CAACG,IAAa,CAAC,CAAA;IACjE,OAAO;AAAE,MAAA,GAAGH,MAAM;AAAEG,MAAAA,IAAI,EAAED,OAAAA;KAAS,CAAA;AACrC,GAAA;AACA,EAAA,MAAMA,OAAO,GAAGE,eAAS,CAACJ,MAAM,CAACG,IAAI,EAAE;AAAEE,IAAAA,GAAG,EAAEJ,eAAAA;AAAgB,GAAC,CAAC,CAACF,OAAK,CAACI,IAAI,CAAC,CAAA;EAC5E,OAAO;AAAE,IAAA,GAAGH,MAAM;AAAEG,IAAAA,IAAI,EAAED,OAAAA;GAAS,CAAA;AACrC,CAAA;;AAEA;AACO,SAASI,eAAeA,CAO7BC,OAEC,EACDC,QAA8B,EAC9BC,WAAmC,EACnC;EACA,MAAMC,MAAM,GAAGC,kBAAU,CAAC,MAAMC,kCAAc,CAACH,WAAW,IAAI,CAAC,CAAC,CAAA;EAEhE,MAAMI,gBAAgB,GAAGH,M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,EACzC;AACL,MAAA,MAAMC,GAAG,GAAGnC,aAAa,EAAE,GAAGkC,IAAI,CAAC,CAAA;AACnC,MAAA,OAAOC,GAAG,KAAKjC,SAAS,GAAGiC,GAAG,GAAGC,OAAO,CAACJ,GAAG,CAACC,MAAM,EAAEC,IAAI,CAAC,CAAA;AAC5D,KAAA;GACD,CAAA;AAED,EAAA,OAAO,IAAIG,KAAK,CAAChE,KAAK,EAAE0D,OAAO,CAAC,CAAA;AAClC;;;;"}
@@ -0,0 +1,190 @@
1
+ import { hydrate, notifyManager } from '@tanstack/query-core';
2
+ import { isServer } from 'solid-js/web';
3
+ import { createMemo, createResource, onCleanup, createComputed, on } from 'solid-js';
4
+ import { createStore, unwrap, reconcile } from 'solid-js/store';
5
+ import { useQueryClient } from './QueryClientProvider.js';
6
+ import { shouldThrowError } from './utils.js';
7
+
8
+ /* eslint-disable @typescript-eslint/no-unnecessary-condition */
9
+ // Had to disable the lint rule because isServer type is defined as false
10
+ // in solid-js/web package. I'll create a GitHub issue with them to see
11
+ // why that happens.
12
+
13
+ function reconcileFn(store, result, reconcileOption) {
14
+ if (reconcileOption === false) return result;
15
+ if (typeof reconcileOption === 'function') {
16
+ const newData = reconcileOption(store.data, result.data);
17
+ return {
18
+ ...result,
19
+ data: newData
20
+ };
21
+ }
22
+ const newData = reconcile(result.data, {
23
+ key: reconcileOption
24
+ })(store.data);
25
+ return {
26
+ ...result,
27
+ data: newData
28
+ };
29
+ }
30
+
31
+ // Base Query Function that is used to create the query.
32
+ function createBaseQuery(options, Observer, queryClient) {
33
+ const client = createMemo(() => useQueryClient(queryClient?.()));
34
+ const defaultedOptions = client().defaultQueryOptions(options());
35
+ defaultedOptions._optimisticResults = 'optimistic';
36
+ defaultedOptions.structuralSharing = false;
37
+ if (isServer) {
38
+ defaultedOptions.retry = false;
39
+ defaultedOptions.throwOnError = true;
40
+ }
41
+ const observer = new Observer(client(), defaultedOptions);
42
+ const [state, setState] = createStore(observer.getOptimisticResult(defaultedOptions));
43
+ const createServerSubscriber = (resolve, reject) => {
44
+ return observer.subscribe(result => {
45
+ notifyManager.batchCalls(() => {
46
+ const query = observer.getCurrentQuery();
47
+ const {
48
+ refetch,
49
+ ...rest
50
+ } = unwrap(result);
51
+ const unwrappedResult = {
52
+ ...rest,
53
+ // hydrate() expects a QueryState object, which is similar but not
54
+ // quite the same as a QueryObserverResult object. Thus, for now, we're
55
+ // copying over the missing properties from state in order to support hydration
56
+ dataUpdateCount: query.state.dataUpdateCount,
57
+ fetchFailureCount: query.state.fetchFailureCount,
58
+ // Removing these properties since they might not be serializable
59
+ // fetchFailureReason: query.state.fetchFailureReason,
60
+ // fetchMeta: query.state.fetchMeta,
61
+ isInvalidated: query.state.isInvalidated
62
+ };
63
+ if (unwrappedResult.isError) {
64
+ if (process.env['NODE_ENV'] === 'development') {
65
+ console.error(unwrappedResult.error);
66
+ }
67
+ reject(unwrappedResult.error);
68
+ }
69
+ if (unwrappedResult.isSuccess) {
70
+ // Use of any here is fine
71
+ // We cannot include refetch since it is not serializable
72
+ resolve(unwrappedResult);
73
+ }
74
+ })();
75
+ });
76
+ };
77
+ const createClientSubscriber = () => {
78
+ return observer.subscribe(result => {
79
+ notifyManager.batchCalls(() => {
80
+ // @ts-expect-error - This will error because the reconcile option does not
81
+ // exist on the query-core QueryObserverResult type
82
+ const reconcileOptions = observer.options.reconcile;
83
+ // If the query has data we dont suspend but instead mutate the resource
84
+ // This could happen when placeholderData/initialData is defined
85
+ if (queryResource()?.data && result.data && !queryResource.loading) {
86
+ setState(store => {
87
+ return reconcileFn(store, result, reconcileOptions === undefined ? 'id' : reconcileOptions);
88
+ });
89
+ mutate(state);
90
+ } else {
91
+ setState(store => {
92
+ return reconcileFn(store, result, reconcileOptions === undefined ? 'id' : reconcileOptions);
93
+ });
94
+ refetch();
95
+ }
96
+ })();
97
+ });
98
+ };
99
+
100
+ /**
101
+ * Unsubscribe is set lazily, so that we can subscribe after hydration when needed.
102
+ */
103
+ let unsubscribe = null;
104
+ const [queryResource, {
105
+ refetch,
106
+ mutate
107
+ }] = createResource(() => {
108
+ return new Promise((resolve, reject) => {
109
+ if (isServer) {
110
+ unsubscribe = createServerSubscriber(resolve, reject);
111
+ } else {
112
+ if (!unsubscribe) {
113
+ unsubscribe = createClientSubscriber();
114
+ }
115
+ }
116
+ if (!state.isLoading) {
117
+ resolve(state);
118
+ }
119
+ });
120
+ }, {
121
+ initialValue: state,
122
+ // If initialData is provided, we resolve the resource immediately
123
+ ssrLoadFrom: options().initialData ? 'initial' : 'server',
124
+ get deferStream() {
125
+ return options().deferStream;
126
+ },
127
+ /**
128
+ * If this resource was populated on the server (either sync render, or streamed in over time), onHydrated
129
+ * will be called. This is the point at which we can hydrate the query cache state, and setup the query subscriber.
130
+ *
131
+ * Leveraging onHydrated allows us to plug into the async and streaming support that solidjs resources already support.
132
+ *
133
+ * Note that this is only invoked on the client, for queries that were originally run on the server.
134
+ */
135
+ onHydrated(_k, info) {
136
+ if (info.value) {
137
+ hydrate(client(), {
138
+ queries: [{
139
+ queryKey: defaultedOptions.queryKey,
140
+ queryHash: defaultedOptions.queryHash,
141
+ state: info.value
142
+ }]
143
+ });
144
+ }
145
+ if (!unsubscribe) {
146
+ /**
147
+ * Do not refetch query on mount if query was fetched on server,
148
+ * even if `staleTime` is not set.
149
+ */
150
+ const newOptions = {
151
+ ...defaultedOptions
152
+ };
153
+ if (defaultedOptions.staleTime || !defaultedOptions.initialData) {
154
+ newOptions.refetchOnMount = false;
155
+ }
156
+ // Setting the options as an immutable object to prevent
157
+ // wonky behavior with observer subscriptions
158
+ observer.setOptions(newOptions);
159
+ setState(observer.getOptimisticResult(newOptions));
160
+ unsubscribe = createClientSubscriber();
161
+ }
162
+ }
163
+ });
164
+ onCleanup(() => {
165
+ if (unsubscribe) {
166
+ unsubscribe();
167
+ unsubscribe = null;
168
+ }
169
+ });
170
+ createComputed(on(() => client().defaultQueryOptions(options()), () => observer.setOptions(client().defaultQueryOptions(options())), {
171
+ // Defer because we don't need to trigger on first render
172
+ // This only cares about changes to options after the observer is created
173
+ defer: true
174
+ }));
175
+ createComputed(on(() => state.status, () => {
176
+ if (state.isError && !state.isFetching && shouldThrowError(observer.options.throwOnError, [state.error, observer.getCurrentQuery()])) {
177
+ throw state.error;
178
+ }
179
+ }));
180
+ const handler = {
181
+ get(target, prop) {
182
+ const val = queryResource()?.[prop];
183
+ return val !== undefined ? val : Reflect.get(target, prop);
184
+ }
185
+ };
186
+ return new Proxy(state, handler);
187
+ }
188
+
189
+ export { createBaseQuery };
190
+ //# sourceMappingURL=createBaseQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-unnecessary-condition */\n// Had to disable the lint rule because isServer type is defined as false\n// in solid-js/web package. I'll create a GitHub issue with them to see\n// why that happens.\nimport type {\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './QueryClient'\nimport { hydrate, notifyManager } from '@tanstack/query-core'\nimport type { Accessor } from 'solid-js'\nimport { isServer } from 'solid-js/web'\nimport {\n createComputed,\n createMemo,\n createResource,\n on,\n onCleanup,\n} from 'solid-js'\nimport { createStore, reconcile, unwrap } from 'solid-js/store'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { CreateBaseQueryOptions } from './types'\nimport { shouldThrowError } from './utils'\n\nfunction reconcileFn<TData, TError>(\n store: QueryObserverResult<TData, TError>,\n result: QueryObserverResult<TData, TError>,\n reconcileOption:\n | string\n | false\n | ((oldData: TData | undefined, newData: TData) => TData),\n): QueryObserverResult<TData, TError> {\n if (reconcileOption === false) return result\n if (typeof reconcileOption === 'function') {\n const newData = reconcileOption(store.data, result.data as TData)\n return { ...result, data: newData } as typeof result\n }\n const newData = reconcile(result.data, { key: reconcileOption })(store.data)\n return { ...result, data: newData } as typeof result\n}\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: Accessor<\n CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n >,\n Observer: typeof QueryObserver,\n queryClient?: Accessor<QueryClient>,\n) {\n const client = createMemo(() => useQueryClient(queryClient?.()))\n\n const defaultedOptions = client().defaultQueryOptions(options())\n defaultedOptions._optimisticResults = 'optimistic'\n defaultedOptions.structuralSharing = false\n if (isServer) {\n defaultedOptions.retry = false\n defaultedOptions.throwOnError = true\n }\n const observer = new Observer(client(), defaultedOptions)\n\n const [state, setState] = createStore<QueryObserverResult<TData, TError>>(\n observer.getOptimisticResult(defaultedOptions),\n )\n\n const createServerSubscriber = (\n resolve: (\n data:\n | QueryObserverResult<TData, TError>\n | PromiseLike<QueryObserverResult<TData, TError> | undefined>\n | undefined,\n ) => void,\n reject: (reason?: any) => void,\n ) => {\n return observer.subscribe((result) => {\n notifyManager.batchCalls(() => {\n const query = observer.getCurrentQuery()\n const { refetch, ...rest } = unwrap(result)\n const unwrappedResult = {\n ...rest,\n\n // hydrate() expects a QueryState object, which is similar but not\n // quite the same as a QueryObserverResult object. Thus, for now, we're\n // copying over the missing properties from state in order to support hydration\n dataUpdateCount: query.state.dataUpdateCount,\n fetchFailureCount: query.state.fetchFailureCount,\n // Removing these properties since they might not be serializable\n // fetchFailureReason: query.state.fetchFailureReason,\n // fetchMeta: query.state.fetchMeta,\n isInvalidated: query.state.isInvalidated,\n }\n\n if (unwrappedResult.isError) {\n if (process.env['NODE_ENV'] === 'development') {\n console.error(unwrappedResult.error)\n }\n reject(unwrappedResult.error)\n }\n if (unwrappedResult.isSuccess) {\n // Use of any here is fine\n // We cannot include refetch since it is not serializable\n resolve(unwrappedResult as any)\n }\n })()\n })\n }\n\n const createClientSubscriber = () => {\n return observer.subscribe((result) => {\n notifyManager.batchCalls(() => {\n // @ts-expect-error - This will error because the reconcile option does not\n // exist on the query-core QueryObserverResult type\n const reconcileOptions = observer.options.reconcile\n // If the query has data we dont suspend but instead mutate the resource\n // This could happen when placeholderData/initialData is defined\n if (queryResource()?.data && result.data && !queryResource.loading) {\n setState((store) => {\n return reconcileFn(\n store,\n result,\n reconcileOptions === undefined ? 'id' : reconcileOptions,\n )\n })\n mutate(state)\n } else {\n setState((store) => {\n return reconcileFn(\n store,\n result,\n reconcileOptions === undefined ? 'id' : reconcileOptions,\n )\n })\n refetch()\n }\n })()\n })\n }\n\n /**\n * Unsubscribe is set lazily, so that we can subscribe after hydration when needed.\n */\n let unsubscribe: (() => void) | null = null\n\n const [queryResource, { refetch, mutate }] = createResource<\n QueryObserverResult<TData, TError> | undefined\n >(\n () => {\n return new Promise((resolve, reject) => {\n if (isServer) {\n unsubscribe = createServerSubscriber(resolve, reject)\n } else {\n if (!unsubscribe) {\n unsubscribe = createClientSubscriber()\n }\n }\n if (!state.isLoading) {\n resolve(state)\n }\n })\n },\n {\n initialValue: state,\n\n // If initialData is provided, we resolve the resource immediately\n ssrLoadFrom: options().initialData ? 'initial' : 'server',\n\n get deferStream() {\n return options().deferStream\n },\n\n /**\n * If this resource was populated on the server (either sync render, or streamed in over time), onHydrated\n * will be called. This is the point at which we can hydrate the query cache state, and setup the query subscriber.\n *\n * Leveraging onHydrated allows us to plug into the async and streaming support that solidjs resources already support.\n *\n * Note that this is only invoked on the client, for queries that were originally run on the server.\n */\n onHydrated(_k, info) {\n if (info.value) {\n hydrate(client(), {\n queries: [\n {\n queryKey: defaultedOptions.queryKey,\n queryHash: defaultedOptions.queryHash,\n state: info.value,\n },\n ],\n })\n }\n\n if (!unsubscribe) {\n /**\n * Do not refetch query on mount if query was fetched on server,\n * even if `staleTime` is not set.\n */\n const newOptions = { ...defaultedOptions }\n if (defaultedOptions.staleTime || !defaultedOptions.initialData) {\n newOptions.refetchOnMount = false\n }\n // Setting the options as an immutable object to prevent\n // wonky behavior with observer subscriptions\n observer.setOptions(newOptions)\n setState(observer.getOptimisticResult(newOptions))\n unsubscribe = createClientSubscriber()\n }\n },\n },\n )\n\n onCleanup(() => {\n if (unsubscribe) {\n unsubscribe()\n unsubscribe = null\n }\n })\n\n createComputed(\n on(\n () => client().defaultQueryOptions(options()),\n () => observer.setOptions(client().defaultQueryOptions(options())),\n {\n // Defer because we don't need to trigger on first render\n // This only cares about changes to options after the observer is created\n defer: true,\n },\n ),\n )\n\n createComputed(\n on(\n () => state.status,\n () => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.throwOnError, [\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 const val = queryResource()?.[prop]\n return val !== undefined ? val : Reflect.get(target, prop)\n },\n }\n\n return new Proxy(state, handler)\n}\n"],"names":["reconcileFn","store","result","reconcileOption","newData","data","reconcile","key","createBaseQuery","options","Observer","queryClient","client","createMemo","useQueryClient","defaultedOptions","defaultQueryOptions","_optimisticResults","structuralSharing","isServer","retry","throwOnError","observer","state","setState","createStore","getOptimisticResult","createServerSubscriber","resolve","reject","subscribe","notifyManager","batchCalls","query","getCurrentQuery","refetch","rest","unwrap","unwrappedResult","dataUpdateCount","fetchFailureCount","isInvalidated","isError","process","env","console","error","isSuccess","createClientSubscriber","reconcileOptions","queryResource","loading","undefined","mutate","unsubscribe","createResource","Promise","isLoading","initialValue","ssrLoadFrom","initialData","deferStream","onHydrated","_k","info","value","hydrate","queries","queryKey","queryHash","newOptions","staleTime","refetchOnMount","setOptions","onCleanup","createComputed","on","defer","status","isFetching","shouldThrowError","handler","get","target","prop","val","Reflect","Proxy"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;;AAsBA,SAASA,WAAWA,CAClBC,KAAyC,EACzCC,MAA0C,EAC1CC,eAG2D,EACvB;AACpC,EAAA,IAAIA,eAAe,KAAK,KAAK,EAAE,OAAOD,MAAM,CAAA;AAC5C,EAAA,IAAI,OAAOC,eAAe,KAA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,mBAAmB,CAACP,OAAO,EAAE,CAAC,EAC7C,MAAMa,QAAQ,CAACmD,UAAU,CAAC7D,MAAM,EAAE,CAACI,mBAAmB,CAACP,OAAO,EAAE,CAAC,CAAC,EAClE;AACE;AACA;AACAoE,IAAAA,KAAK,EAAE,IAAA;AACT,GACF,CACF,CAAC,CAAA;EAEDF,cAAc,CACZC,EAAE,CACA,MAAMrD,KAAK,CAACuD,MAAM,EAClB,MAAM;AACJ,IAAA,IACEvD,KAAK,CAACmB,OAAO,IACb,CAACnB,KAAK,CAACwD,UAAU,IACjBC,gBAAgB,CAAC1D,QAAQ,CAACb,OAAO,CAACY,YAAY,EAAE,CAC9CE,KAAK,CAACuB,KAAK,EACXxB,QAAQ,CAACY,eAAe,EAAE,CAC3B,CAAC,EACF;MACA,MAAMX,KAAK,CAACuB,KAAK,CAAA;AACnB,KAAA;AACF,GACF,CACF,CAAC,CAAA;AAED,EAAA,MAAMmC,OAAO,GAAG;AACdC,IAAAA,GAAGA,CACDC,MAA0C,EAC1CC,IAA8C,EACzC;AACL,MAAA,MAAMC,GAAG,GAAGnC,aAAa,EAAE,GAAGkC,IAAI,CAAC,CAAA;AACnC,MAAA,OAAOC,GAAG,KAAKjC,SAAS,GAAGiC,GAAG,GAAGC,OAAO,CAACJ,GAAG,CAACC,MAAM,EAAEC,IAAI,CAAC,CAAA;AAC5D,KAAA;GACD,CAAA;AAED,EAAA,OAAO,IAAIG,KAAK,CAAChE,KAAK,EAAE0D,OAAO,CAAC,CAAA;AAClC;;;;"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var queryCore = require('@tanstack/query-core');
4
+ var createBaseQuery = require('./createBaseQuery.cjs');
5
+ var solidJs = require('solid-js');
6
+
7
+ function createInfiniteQuery(options, queryClient) {
8
+ return createBaseQuery.createBaseQuery(solidJs.createMemo(() => options()),
9
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
10
+ queryCore.InfiniteQueryObserver, queryClient);
11
+ }
12
+
13
+ exports.createInfiniteQuery = createInfiniteQuery;
14
+ //# sourceMappingURL=createInfiniteQuery.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInfiniteQuery.cjs","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import type {\n QueryObserver,\n QueryKey,\n DefaultError,\n InfiniteData,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './QueryClient'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n} from './types'\nimport { createBaseQuery } from './createBaseQuery'\nimport { createMemo } from 'solid-js'\nimport type { Accessor } from 'solid-js'\n\nexport function createInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: Accessor<QueryClient>,\n): CreateInfiniteQueryResult<TData, TError> {\n return createBaseQuery(\n createMemo(() => options()),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n ) as CreateInfiniteQueryResult<TData, TError>\n}\n"],"names":["createInfiniteQuery","options","queryClient","createBaseQuery","createMemo","InfiniteQueryObserver"],"mappings":";;;;;;AAgBO,SAASA,mBAAmBA,CAOjCC,OAMC,EACDC,WAAmC,EACO;EAC1C,OAAOC,+BAAe,CACpBC,kBAAU,CAAC,MAAMH,OAAO,EAAE,CAAC;AAC3B;EACAI,+BAAqB,EACrBH,WACF,CAAC,CAAA;AACH;;;;"}
@@ -0,0 +1,12 @@
1
+ import { InfiniteQueryObserver } from '@tanstack/query-core';
2
+ import { createBaseQuery } from './createBaseQuery.js';
3
+ import { createMemo } from 'solid-js';
4
+
5
+ function createInfiniteQuery(options, queryClient) {
6
+ return createBaseQuery(createMemo(() => options()),
7
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
8
+ InfiniteQueryObserver, queryClient);
9
+ }
10
+
11
+ export { createInfiniteQuery };
12
+ //# sourceMappingURL=createInfiniteQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createInfiniteQuery.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import type {\n QueryObserver,\n QueryKey,\n DefaultError,\n InfiniteData,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './QueryClient'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n} from './types'\nimport { createBaseQuery } from './createBaseQuery'\nimport { createMemo } from 'solid-js'\nimport type { Accessor } from 'solid-js'\n\nexport function createInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: Accessor<QueryClient>,\n): CreateInfiniteQueryResult<TData, TError> {\n return createBaseQuery(\n createMemo(() => options()),\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n ) as CreateInfiniteQueryResult<TData, TError>\n}\n"],"names":["createInfiniteQuery","options","queryClient","createBaseQuery","createMemo","InfiniteQueryObserver"],"mappings":";;;;AAgBO,SAASA,mBAAmBA,CAOjCC,OAMC,EACDC,WAAmC,EACO;EAC1C,OAAOC,eAAe,CACpBC,UAAU,CAAC,MAAMH,OAAO,EAAE,CAAC;AAC3B;EACAI,qBAAqB,EACrBH,WACF,CAAC,CAAA;AACH;;;;"}