@tanstack/solid-query 6.0.0-rc.0 → 6.0.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -1
- package/build/_tsup-dts-rollup.d.cts +203 -152
- package/build/_tsup-dts-rollup.d.ts +203 -152
- package/build/dev.cjs +755 -559
- package/build/dev.d.cts +2 -22
- package/build/dev.d.ts +2 -22
- package/build/dev.js +757 -559
- package/build/index.cjs +755 -550
- package/build/index.d.cts +2 -22
- package/build/index.d.ts +2 -22
- package/build/index.js +757 -550
- package/package.json +7 -6
- package/src/QueryClient.ts +24 -45
- package/src/QueryClientProvider.tsx +136 -58
- package/src/cacheAggregate.ts +90 -0
- package/src/dehydrateSettled.ts +42 -0
- package/src/index.ts +3 -29
- package/src/types.ts +62 -44
- package/src/useBaseQuery.ts +674 -412
- package/src/useInfiniteQuery.ts +156 -4
- package/src/useIsFetching.ts +6 -16
- package/src/useIsMutating.ts +6 -16
- package/src/useMutation.ts +317 -56
- package/src/useMutationState.ts +9 -22
- package/src/useQueries.ts +61 -110
- package/src/hydrationChannel.ts +0 -260
package/build/index.cjs
CHANGED
|
@@ -3,160 +3,17 @@
|
|
|
3
3
|
var queryCore = require('@tanstack/query-core');
|
|
4
4
|
var solidJs = require('solid-js');
|
|
5
5
|
var web = require('@solidjs/web');
|
|
6
|
+
var serverFunctions = require('@solidjs/web/server-functions');
|
|
6
7
|
|
|
7
|
-
// src/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
for (const query of cache.getAll()) {
|
|
14
|
-
if (query.state.status !== "success") continue;
|
|
15
|
-
let cached = entryCache.get(query.queryHash);
|
|
16
|
-
if (!cached || cached.state !== query.state) {
|
|
17
|
-
cached = {
|
|
18
|
-
state: query.state,
|
|
19
|
-
entry: {
|
|
20
|
-
dehydratedAt: Date.now(),
|
|
21
|
-
state: query.state,
|
|
22
|
-
queryKey: query.queryKey,
|
|
23
|
-
queryHash: query.queryHash,
|
|
24
|
-
...query.meta && { meta: query.meta },
|
|
25
|
-
...query.queryType && { queryType: query.queryType }
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
entryCache.set(query.queryHash, cached);
|
|
29
|
-
}
|
|
30
|
-
entries.push(cached.entry);
|
|
31
|
-
}
|
|
32
|
-
return entries;
|
|
33
|
-
};
|
|
34
|
-
let closed = false;
|
|
35
|
-
let pull = null;
|
|
36
|
-
const buffered = [];
|
|
37
|
-
const emit = (value) => {
|
|
38
|
-
if (closed) return;
|
|
39
|
-
if (value.done) closed = true;
|
|
40
|
-
if (pull) {
|
|
41
|
-
const resolve = pull;
|
|
42
|
-
pull = null;
|
|
43
|
-
resolve({ done: false, value });
|
|
44
|
-
} else {
|
|
45
|
-
buffered.push(value);
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
let closeTimer = null;
|
|
49
|
-
const scheduleCloseCheck = () => {
|
|
50
|
-
if (closed || closeTimer !== null) return;
|
|
51
|
-
closeTimer = setTimeout(() => {
|
|
52
|
-
closeTimer = null;
|
|
53
|
-
if (closed) return;
|
|
54
|
-
if (client.isFetching() === 0) {
|
|
55
|
-
unsubscribe();
|
|
56
|
-
emit({ entries: snapshot2(), done: true });
|
|
57
|
-
}
|
|
58
|
-
}, 0);
|
|
59
|
-
};
|
|
60
|
-
const unsubscribe = cache.subscribe((event) => {
|
|
61
|
-
if (closed) return;
|
|
62
|
-
if (event.type === "updated" && event.action.type === "success") {
|
|
63
|
-
emit({ entries: snapshot2(), done: false });
|
|
64
|
-
}
|
|
65
|
-
scheduleCloseCheck();
|
|
66
|
-
});
|
|
67
|
-
scheduleCloseCheck();
|
|
68
|
-
return {
|
|
69
|
-
[Symbol.asyncIterator]() {
|
|
70
|
-
return {
|
|
71
|
-
next() {
|
|
72
|
-
if (buffered.length > 0) {
|
|
73
|
-
return Promise.resolve({ done: false, value: buffered.shift() });
|
|
74
|
-
}
|
|
75
|
-
if (closed) {
|
|
76
|
-
return Promise.resolve({
|
|
77
|
-
done: true,
|
|
78
|
-
value: void 0
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
return new Promise(
|
|
82
|
-
(resolve) => {
|
|
83
|
-
pull = resolve;
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
},
|
|
87
|
-
return(value) {
|
|
88
|
-
if (!closed) {
|
|
89
|
-
closed = true;
|
|
90
|
-
unsubscribe();
|
|
91
|
-
if (closeTimer !== null) {
|
|
92
|
-
clearTimeout(closeTimer);
|
|
93
|
-
closeTimer = null;
|
|
94
|
-
}
|
|
95
|
-
const resolve = pull;
|
|
96
|
-
pull = null;
|
|
97
|
-
resolve?.({ done: true, value: void 0 });
|
|
98
|
-
}
|
|
99
|
-
return Promise.resolve({
|
|
100
|
-
done: true,
|
|
101
|
-
value
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
function createHydrationCoordinator(client) {
|
|
109
|
-
const applied = /* @__PURE__ */ new Map();
|
|
110
|
-
const waiters = /* @__PURE__ */ new Map();
|
|
111
|
-
let channelDone = false;
|
|
112
|
-
const fireWaiters = (queryHash) => {
|
|
113
|
-
const callbacks = waiters.get(queryHash);
|
|
114
|
-
if (!callbacks) return;
|
|
115
|
-
waiters.delete(queryHash);
|
|
116
|
-
for (const callback of callbacks) queueMicrotask(callback);
|
|
117
|
-
};
|
|
118
|
-
return {
|
|
119
|
-
applyYield(value) {
|
|
120
|
-
const fresh = value.entries.filter(
|
|
121
|
-
(entry) => applied.get(entry.queryHash) !== entry.state.dataUpdatedAt
|
|
122
|
-
);
|
|
123
|
-
if (fresh.length > 0) {
|
|
124
|
-
solidJs.runWithOwner(
|
|
125
|
-
null,
|
|
126
|
-
() => queryCore.hydrate(client(), { queries: fresh, mutations: [] })
|
|
127
|
-
);
|
|
128
|
-
for (const entry of fresh) {
|
|
129
|
-
applied.set(entry.queryHash, entry.state.dataUpdatedAt);
|
|
130
|
-
fireWaiters(entry.queryHash);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (value.done && !channelDone) {
|
|
134
|
-
channelDone = true;
|
|
135
|
-
const remaining = [...waiters.values()];
|
|
136
|
-
waiters.clear();
|
|
137
|
-
for (const callbacks of remaining) {
|
|
138
|
-
for (const callback of callbacks) queueMicrotask(callback);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
},
|
|
142
|
-
whenQueryPrimed(queryHash, callback) {
|
|
143
|
-
if (channelDone || applied.has(queryHash)) {
|
|
144
|
-
queueMicrotask(callback);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
let list = waiters.get(queryHash);
|
|
148
|
-
if (!list) {
|
|
149
|
-
list = [];
|
|
150
|
-
waiters.set(queryHash, list);
|
|
151
|
-
}
|
|
152
|
-
list.push(callback);
|
|
153
|
-
}
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
var HydrationCoordinatorContext = solidJs.createContext(null);
|
|
157
|
-
|
|
158
|
-
// src/QueryClientProvider.tsx
|
|
8
|
+
// src/index.ts
|
|
9
|
+
exports.QueryClient = class QueryClient extends queryCore.QueryClient {
|
|
10
|
+
constructor(config = {}) {
|
|
11
|
+
super(config);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
159
14
|
var isServer = typeof window === "undefined";
|
|
15
|
+
var HYDRATION_KEY_PREFIX = "sq:";
|
|
16
|
+
exports.FLIGHT_DATA_SOURCE = "sq";
|
|
160
17
|
exports.QueryClientContext = solidJs.createContext(null);
|
|
161
18
|
exports.useQueryClient = (queryClient) => {
|
|
162
19
|
if (queryClient) {
|
|
@@ -168,25 +25,53 @@ exports.useQueryClient = (queryClient) => {
|
|
|
168
25
|
}
|
|
169
26
|
return client();
|
|
170
27
|
};
|
|
28
|
+
function serializeCacheOnServer(client) {
|
|
29
|
+
const ctx = solidJs.sharedConfig.context;
|
|
30
|
+
if (!ctx || !ctx.async || ctx.noHydrate) return;
|
|
31
|
+
const cache = client.getQueryCache();
|
|
32
|
+
const shouldDehydrateQuery = client.getDefaultOptions().dehydrate?.shouldDehydrateQuery;
|
|
33
|
+
const seen = /* @__PURE__ */ new Set();
|
|
34
|
+
const serializeQuery = (query) => {
|
|
35
|
+
if (seen.has(query.queryHash)) return;
|
|
36
|
+
if (shouldDehydrateQuery && !shouldDehydrateQuery(query)) return;
|
|
37
|
+
const state = query.state;
|
|
38
|
+
if (state.status === "success") {
|
|
39
|
+
seen.add(query.queryHash);
|
|
40
|
+
ctx.serialize(HYDRATION_KEY_PREFIX + query.queryHash, {
|
|
41
|
+
data: state.data,
|
|
42
|
+
t: state.dataUpdatedAt
|
|
43
|
+
});
|
|
44
|
+
} else if (state.fetchStatus !== "idle") {
|
|
45
|
+
const promise = query.promise;
|
|
46
|
+
if (!promise) return;
|
|
47
|
+
seen.add(query.queryHash);
|
|
48
|
+
ctx.serialize(HYDRATION_KEY_PREFIX + query.queryHash, promise.then(() => ({
|
|
49
|
+
data: query.state.data,
|
|
50
|
+
t: query.state.dataUpdatedAt
|
|
51
|
+
})));
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
for (const query of cache.getAll()) serializeQuery(query);
|
|
55
|
+
solidJs.onCleanup(cache.subscribe((event) => serializeQuery(event.query)));
|
|
56
|
+
}
|
|
171
57
|
exports.QueryClientProvider = (props) => {
|
|
172
58
|
props.client.mount();
|
|
173
59
|
solidJs.onCleanup(() => props.client.unmount());
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
}
|
|
60
|
+
if (isServer) {
|
|
61
|
+
serializeCacheOnServer(props.client);
|
|
62
|
+
solidJs.onCleanup(() => {
|
|
63
|
+
props.client.cancelQueries().catch(() => void 0);
|
|
64
|
+
props.client.clear();
|
|
65
|
+
});
|
|
66
|
+
} else {
|
|
67
|
+
solidJs.onCleanup(serverFunctions.subscribeFlightData(exports.FLIGHT_DATA_SOURCE, (data) => {
|
|
68
|
+
queryCore.hydrate(props.client, data);
|
|
69
|
+
}));
|
|
70
|
+
}
|
|
181
71
|
return web.createComponent(exports.QueryClientContext, {
|
|
182
72
|
value: () => props.client,
|
|
183
73
|
get children() {
|
|
184
|
-
return
|
|
185
|
-
value: coordinator,
|
|
186
|
-
get children() {
|
|
187
|
-
return props.children;
|
|
188
|
-
}
|
|
189
|
-
});
|
|
74
|
+
return props.children;
|
|
190
75
|
}
|
|
191
76
|
});
|
|
192
77
|
};
|
|
@@ -195,251 +80,357 @@ exports.useIsRestoring = () => solidJs.useContext(exports.IsRestoringContext);
|
|
|
195
80
|
|
|
196
81
|
// src/useBaseQuery.ts
|
|
197
82
|
var isServer2 = typeof window === "undefined";
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
if (typeof reconcileOption === "function") {
|
|
212
|
-
const newData = reconcileOption(store.data, result.data);
|
|
213
|
-
return { ...result, data: newData };
|
|
214
|
-
}
|
|
215
|
-
if (reconcileOption === false) return result;
|
|
216
|
-
const key = reconcileOption;
|
|
217
|
-
let data = result.data;
|
|
218
|
-
if (store.data === void 0) {
|
|
219
|
-
try {
|
|
220
|
-
data = structuredClone(data);
|
|
221
|
-
} catch (error) {
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
if (store.data !== void 0 && data !== void 0) {
|
|
225
|
-
solidJs.reconcile(data, key)(store.data);
|
|
226
|
-
return { ...result, data: store.data };
|
|
227
|
-
}
|
|
228
|
-
return { ...result, data };
|
|
229
|
-
}
|
|
230
|
-
var hydratableObserverResult = (_query, result) => {
|
|
231
|
-
if (!isServer2) return result;
|
|
232
|
-
const obj = {
|
|
233
|
-
...solidJs.snapshot(result),
|
|
234
|
-
// During SSR, functions cannot be serialized, so we need to remove them
|
|
235
|
-
// This is safe because we will add these functions back when the query is hydrated
|
|
236
|
-
refetch: void 0
|
|
83
|
+
var NEVER = new Promise(queryCore.noop);
|
|
84
|
+
function metaFrom(state) {
|
|
85
|
+
return {
|
|
86
|
+
dataUpdateCount: state.dataUpdateCount,
|
|
87
|
+
dataUpdatedAt: state.dataUpdatedAt,
|
|
88
|
+
error: state.error,
|
|
89
|
+
errorUpdateCount: state.errorUpdateCount,
|
|
90
|
+
errorUpdatedAt: state.errorUpdatedAt,
|
|
91
|
+
fetchFailureCount: state.fetchFailureCount,
|
|
92
|
+
fetchFailureReason: state.fetchFailureReason,
|
|
93
|
+
fetchStatus: state.fetchStatus,
|
|
94
|
+
isInvalidated: state.isInvalidated,
|
|
95
|
+
status: state.status
|
|
237
96
|
};
|
|
238
|
-
|
|
239
|
-
obj.fetchNextPage = void 0;
|
|
240
|
-
obj.fetchPreviousPage = void 0;
|
|
241
|
-
}
|
|
242
|
-
return obj;
|
|
243
|
-
};
|
|
97
|
+
}
|
|
244
98
|
function useBaseQuery(options, Observer, queryClient) {
|
|
245
|
-
|
|
99
|
+
return useBaseQueryLayer(options, Observer, queryClient).result;
|
|
100
|
+
}
|
|
101
|
+
function useBaseQueryLayer(options, Observer, queryClient) {
|
|
102
|
+
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
246
103
|
const isRestoring = exports.useIsRestoring();
|
|
247
|
-
let
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
104
|
+
let latestHash;
|
|
105
|
+
let latestOptions;
|
|
106
|
+
const defaultedOptions = solidJs.createMemo(() => {
|
|
107
|
+
const defaulted = client().defaultQueryOptions(options());
|
|
108
|
+
defaulted._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
252
109
|
if (isServer2) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
defaultOptions.experimental_prefetchInRender = true;
|
|
110
|
+
defaulted.retry = false;
|
|
111
|
+
defaulted.throwOnError = true;
|
|
256
112
|
}
|
|
257
|
-
|
|
113
|
+
latestHash = defaulted.queryHash;
|
|
114
|
+
latestOptions = defaulted;
|
|
115
|
+
return defaulted;
|
|
258
116
|
});
|
|
259
|
-
|
|
260
|
-
const [trackedDefaultedOptions] = solidJs.createSignal(() => defaultedOptions());
|
|
117
|
+
let observer = solidJs.untrack(() => new Observer(client(), defaultedOptions()));
|
|
261
118
|
solidJs.createRenderEffect(
|
|
262
|
-
() =>
|
|
263
|
-
(opts) =>
|
|
264
|
-
solidJs.runWithOwner(null, () => observer.setOptions(opts));
|
|
265
|
-
}
|
|
119
|
+
() => defaultedOptions(),
|
|
120
|
+
(opts) => observer.setOptions(opts)
|
|
266
121
|
);
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
)
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
queryCore.notifyManager.batchCalls(() => {
|
|
276
|
-
const query = observer.getCurrentQuery();
|
|
277
|
-
const unwrappedResult = hydratableObserverResult(query, result);
|
|
278
|
-
if (result.data !== void 0 && unwrappedResult.isError) {
|
|
279
|
-
reject(unwrappedResult.error);
|
|
280
|
-
unsubscribeIfQueued();
|
|
281
|
-
} else {
|
|
282
|
-
resolve(unwrappedResult);
|
|
283
|
-
unsubscribeIfQueued();
|
|
284
|
-
}
|
|
285
|
-
})();
|
|
286
|
-
});
|
|
287
|
-
};
|
|
288
|
-
const unsubscribeIfQueued = () => {
|
|
289
|
-
if (unsubscribeQueued) {
|
|
290
|
-
unsubscribe?.();
|
|
291
|
-
unsubscribeQueued = false;
|
|
122
|
+
const hydratedMount = !isServer2 && solidJs.sharedConfig.hydrating === true;
|
|
123
|
+
const [version, setVersion] = solidJs.createSignal(0, { ownedWrite: true });
|
|
124
|
+
const [primed, setPrimed] = solidJs.createSignal(!hydratedMount, {
|
|
125
|
+
ownedWrite: true
|
|
126
|
+
});
|
|
127
|
+
const onCacheEvent = (event) => {
|
|
128
|
+
if (event.query.queryHash === solidJs.untrack(defaultedOptions).queryHash || event.query.queryHash === latestHash) {
|
|
129
|
+
setVersion((v) => v + 1);
|
|
292
130
|
}
|
|
293
131
|
};
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const previousResult = observerResult;
|
|
297
|
-
observerResult = result;
|
|
298
|
-
solidJs.runWithOwner(null, () => {
|
|
299
|
-
setStateWithReconciliation(result);
|
|
300
|
-
if (unsubscribe && !disposed && (previousResult.isLoading !== result.isLoading || previousResult.isError !== result.isError)) {
|
|
301
|
-
try {
|
|
302
|
-
solidJs.refresh(queryResource);
|
|
303
|
-
} catch {
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
});
|
|
308
|
-
};
|
|
309
|
-
function setStateWithReconciliation(res) {
|
|
310
|
-
const opts = observer.options;
|
|
311
|
-
const reconcileOptions = opts.reconcile;
|
|
312
|
-
const sanitized = _stripFnsForSSR(res);
|
|
313
|
-
setState((store) => {
|
|
314
|
-
return reconcileFn(
|
|
315
|
-
store,
|
|
316
|
-
sanitized,
|
|
317
|
-
reconcileOptions === void 0 ? false : reconcileOptions,
|
|
318
|
-
opts.queryHash
|
|
319
|
-
);
|
|
320
|
-
});
|
|
321
|
-
}
|
|
322
|
-
let unsubscribe = null;
|
|
132
|
+
let observerSub = null;
|
|
133
|
+
let cacheSub = null;
|
|
323
134
|
let disposed = false;
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
135
|
+
let shouldAttach = false;
|
|
136
|
+
let activeClient = solidJs.untrack(client);
|
|
137
|
+
const attach = () => {
|
|
138
|
+
if (!disposed && !observerSub && !solidJs.untrack(isRestoring)) {
|
|
139
|
+
shouldAttach = true;
|
|
140
|
+
observerSub = observer.subscribe(queryCore.noop);
|
|
328
141
|
}
|
|
329
142
|
};
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
143
|
+
const syncClient = (c) => {
|
|
144
|
+
if (isServer2 || c === activeClient) return;
|
|
145
|
+
activeClient = c;
|
|
146
|
+
cacheSub?.();
|
|
147
|
+
cacheSub = c.getQueryCache().subscribe(onCacheEvent);
|
|
148
|
+
observerSub?.();
|
|
149
|
+
observerSub = null;
|
|
150
|
+
observer = new Observer(c, solidJs.untrack(defaultedOptions));
|
|
151
|
+
if (shouldAttach && !disposed && !solidJs.untrack(isRestoring)) {
|
|
152
|
+
observerSub = observer.subscribe(queryCore.noop);
|
|
336
153
|
}
|
|
337
154
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
155
|
+
const prime = (entry) => {
|
|
156
|
+
if (entry != null && typeof entry === "object" && (entry.t ?? 0) > 0) {
|
|
157
|
+
const c = solidJs.untrack(client);
|
|
158
|
+
const opts = solidJs.untrack(defaultedOptions);
|
|
159
|
+
solidJs.runWithOwner(
|
|
160
|
+
null,
|
|
161
|
+
() => queryCore.hydrate(c, {
|
|
162
|
+
mutations: [],
|
|
163
|
+
queries: [
|
|
164
|
+
{
|
|
165
|
+
queryKey: opts.queryKey,
|
|
166
|
+
queryHash: opts.queryHash,
|
|
167
|
+
dehydratedAt: entry.t,
|
|
168
|
+
...opts.meta && { meta: opts.meta },
|
|
169
|
+
...opts._type && {
|
|
170
|
+
queryType: opts._type
|
|
171
|
+
},
|
|
172
|
+
state: {
|
|
173
|
+
data: entry.data,
|
|
174
|
+
dataUpdatedAt: entry.t,
|
|
175
|
+
dataUpdateCount: 1,
|
|
176
|
+
error: null,
|
|
177
|
+
errorUpdateCount: 0,
|
|
178
|
+
errorUpdatedAt: 0,
|
|
179
|
+
fetchFailureCount: 0,
|
|
180
|
+
fetchFailureReason: null,
|
|
181
|
+
fetchMeta: null,
|
|
182
|
+
isInvalidated: false,
|
|
183
|
+
status: "success",
|
|
184
|
+
fetchStatus: "idle"
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
})
|
|
189
|
+
);
|
|
354
190
|
}
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
setStateWithReconciliation(currentResult);
|
|
378
|
-
});
|
|
379
|
-
if (currentResult.isError && !currentResult.isFetching && !restoring && queryCore.shouldThrowError(opts.throwOnError, [
|
|
380
|
-
currentResult.error,
|
|
381
|
-
observer.getCurrentQuery()
|
|
382
|
-
])) {
|
|
383
|
-
return;
|
|
384
|
-
}
|
|
385
|
-
if (!currentResult.isLoading) {
|
|
386
|
-
resolver = null;
|
|
387
|
-
return resolve(
|
|
388
|
-
hydratableObserverResult(observer.getCurrentQuery(), currentResult)
|
|
389
|
-
);
|
|
191
|
+
};
|
|
192
|
+
if (!isServer2) {
|
|
193
|
+
cacheSub = activeClient.getQueryCache().subscribe(onCacheEvent);
|
|
194
|
+
const sc = solidJs.sharedConfig;
|
|
195
|
+
const registryKey = HYDRATION_KEY_PREFIX + solidJs.untrack(defaultedOptions).queryHash;
|
|
196
|
+
const primeAndAttach = (entry) => {
|
|
197
|
+
prime(entry);
|
|
198
|
+
setPrimed(true);
|
|
199
|
+
attach();
|
|
200
|
+
};
|
|
201
|
+
const settle = hydratedMount ? primeAndAttach : prime;
|
|
202
|
+
if (sc.has?.(registryKey)) {
|
|
203
|
+
const entry = sc.load(registryKey);
|
|
204
|
+
delete globalThis._$HY.r[registryKey];
|
|
205
|
+
if (entry != null && typeof entry === "object") {
|
|
206
|
+
if (entry.s === 1) settle(entry.v);
|
|
207
|
+
else if (entry.s === 2) settle();
|
|
208
|
+
else if (typeof entry.then === "function")
|
|
209
|
+
entry.then(settle, () => settle());
|
|
210
|
+
else settle(entry);
|
|
211
|
+
} else {
|
|
212
|
+
settle(entry);
|
|
390
213
|
}
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
scheduleHydratedAttach();
|
|
214
|
+
} else if (hydratedMount) {
|
|
215
|
+
primeAndAttach();
|
|
394
216
|
}
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
217
|
+
if (!hydratedMount) {
|
|
218
|
+
solidJs.createRenderEffect(
|
|
219
|
+
() => isRestoring(),
|
|
220
|
+
(restoring) => {
|
|
221
|
+
if (!restoring) attach();
|
|
222
|
+
}
|
|
223
|
+
);
|
|
402
224
|
}
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
225
|
+
solidJs.onCleanup(() => {
|
|
226
|
+
disposed = true;
|
|
227
|
+
observerSub?.();
|
|
228
|
+
observerSub = null;
|
|
229
|
+
cacheSub?.();
|
|
230
|
+
cacheSub = null;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
const query = () => {
|
|
234
|
+
version();
|
|
235
|
+
const c = client();
|
|
236
|
+
syncClient(c);
|
|
237
|
+
return c.getQueryCache().build(c, defaultedOptions());
|
|
238
|
+
};
|
|
239
|
+
const isEnabled = () => {
|
|
240
|
+
const opts = defaultedOptions();
|
|
241
|
+
const enabled = typeof opts.enabled === "function" ? opts.enabled(solidJs.untrack(query)) : opts.enabled;
|
|
242
|
+
return enabled !== false;
|
|
243
|
+
};
|
|
244
|
+
const resolvePlaceholder = (opts) => {
|
|
245
|
+
const placeholder = opts.placeholderData;
|
|
246
|
+
if (placeholder === void 0) return void 0;
|
|
247
|
+
return typeof placeholder === "function" ? placeholder() : placeholder;
|
|
248
|
+
};
|
|
249
|
+
let chained = null;
|
|
250
|
+
const chainOnce = (base, select, wrap) => {
|
|
251
|
+
if (chained?.base !== base || chained.select !== select) {
|
|
252
|
+
chained = { base, select, value: base.then(wrap) };
|
|
406
253
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
254
|
+
return chained.value;
|
|
255
|
+
};
|
|
256
|
+
const computeData = (prev) => {
|
|
257
|
+
const opts = defaultedOptions();
|
|
258
|
+
const q = query();
|
|
259
|
+
const state = q.state;
|
|
260
|
+
const select = opts.select;
|
|
261
|
+
const wrap = (d) => ({
|
|
262
|
+
value: select ? select(d) : d
|
|
263
|
+
});
|
|
264
|
+
if (state.data === void 0 && state.status === "pending") {
|
|
265
|
+
const placeholder = resolvePlaceholder(opts);
|
|
266
|
+
if (placeholder !== void 0) return wrap(placeholder);
|
|
410
267
|
}
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
"failureCount",
|
|
416
|
-
"failureReason",
|
|
417
|
-
"errorUpdateCount",
|
|
418
|
-
"errorUpdatedAt"
|
|
419
|
-
]);
|
|
420
|
-
return new Proxy(state, {
|
|
421
|
-
get(target, prop, receiver) {
|
|
422
|
-
if (typeof prop === "symbol") {
|
|
423
|
-
return Reflect.get(target, prop, receiver);
|
|
424
|
-
}
|
|
425
|
-
if (isServer2) {
|
|
426
|
-
const resolved = queryResource();
|
|
427
|
-
if (prop in resolved) {
|
|
428
|
-
return Reflect.get(resolved, prop);
|
|
429
|
-
}
|
|
268
|
+
if (state.fetchStatus !== "idle") {
|
|
269
|
+
if (state.data === void 0 || prev !== void 0) {
|
|
270
|
+
const promise = q.promise;
|
|
271
|
+
if (promise) return chainOnce(promise, select, wrap);
|
|
430
272
|
}
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
if (state.isError && !state.isFetching && queryCore.shouldThrowError(observer.options.throwOnError, [
|
|
273
|
+
}
|
|
274
|
+
if (state.status === "error") {
|
|
275
|
+
if (state.data === void 0 || queryCore.shouldThrowError(opts.throwOnError, [
|
|
435
276
|
state.error,
|
|
436
|
-
|
|
277
|
+
q
|
|
437
278
|
])) {
|
|
438
279
|
throw state.error;
|
|
439
280
|
}
|
|
440
|
-
return Reflect.get(target, prop, receiver);
|
|
441
281
|
}
|
|
282
|
+
if (state.data !== void 0) return wrap(state.data);
|
|
283
|
+
if (isEnabled()) {
|
|
284
|
+
if (!isServer2 && solidJs.sharedConfig.hydrating) {
|
|
285
|
+
return NEVER;
|
|
286
|
+
}
|
|
287
|
+
if (!primed()) {
|
|
288
|
+
return NEVER;
|
|
289
|
+
}
|
|
290
|
+
if (isRestoring()) {
|
|
291
|
+
return NEVER;
|
|
292
|
+
}
|
|
293
|
+
if (!isServer2) observer.setOptions(opts);
|
|
294
|
+
return chainOnce(q.fetch(opts), select, wrap);
|
|
295
|
+
}
|
|
296
|
+
return NEVER;
|
|
297
|
+
};
|
|
298
|
+
const dataStore = solidJs.createProjection(
|
|
299
|
+
(draft) => computeData(draft.value),
|
|
300
|
+
{},
|
|
301
|
+
{
|
|
302
|
+
key: solidJs.untrack(() => options().reconcile),
|
|
303
|
+
deferStream: solidJs.untrack(() => options().deferStream)
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
const data = () => dataStore.value;
|
|
307
|
+
const serverMeta = () => {
|
|
308
|
+
if (query().state.status === "pending" && isEnabled()) data();
|
|
309
|
+
return metaFrom(query().state);
|
|
310
|
+
};
|
|
311
|
+
const metaProjection = solidJs.createProjection(
|
|
312
|
+
(draft) => {
|
|
313
|
+
Object.assign(draft, metaFrom(query().state));
|
|
314
|
+
},
|
|
315
|
+
solidJs.untrack(() => metaFrom(query().state))
|
|
316
|
+
);
|
|
317
|
+
const meta = isServer2 ? new Proxy({}, {
|
|
318
|
+
get: (_, key) => serverMeta()[key]
|
|
319
|
+
}) : metaProjection;
|
|
320
|
+
const mountedAt = isServer2 ? {
|
|
321
|
+
get dataUpdateCount() {
|
|
322
|
+
return solidJs.untrack(query).state.dataUpdateCount;
|
|
323
|
+
},
|
|
324
|
+
get errorUpdateCount() {
|
|
325
|
+
return solidJs.untrack(query).state.errorUpdateCount;
|
|
326
|
+
}
|
|
327
|
+
} : solidJs.untrack(() => {
|
|
328
|
+
const state = query().state;
|
|
329
|
+
return {
|
|
330
|
+
dataUpdateCount: state.dataUpdateCount,
|
|
331
|
+
errorUpdateCount: state.errorUpdateCount
|
|
332
|
+
};
|
|
442
333
|
});
|
|
334
|
+
const hasPlaceholder = () => meta.status === "pending" && solidJs.untrack(() => resolvePlaceholder(defaultedOptions())) !== void 0;
|
|
335
|
+
const status = () => hasPlaceholder() ? "success" : meta.status;
|
|
336
|
+
const isPending = () => status() === "pending";
|
|
337
|
+
const isFetching = () => meta.fetchStatus === "fetching" || solidJs.isPending(() => data());
|
|
338
|
+
const isError = () => status() === "error";
|
|
339
|
+
const isStale = () => {
|
|
340
|
+
const opts = defaultedOptions();
|
|
341
|
+
const q = solidJs.untrack(query);
|
|
342
|
+
const staleTime = typeof opts.staleTime === "function" ? opts.staleTime(q) : opts.staleTime;
|
|
343
|
+
version();
|
|
344
|
+
return q.isStaleByTime(staleTime);
|
|
345
|
+
};
|
|
346
|
+
const result = {
|
|
347
|
+
get data() {
|
|
348
|
+
return data();
|
|
349
|
+
},
|
|
350
|
+
get error() {
|
|
351
|
+
return meta.error;
|
|
352
|
+
},
|
|
353
|
+
get status() {
|
|
354
|
+
return status();
|
|
355
|
+
},
|
|
356
|
+
get fetchStatus() {
|
|
357
|
+
return meta.fetchStatus;
|
|
358
|
+
},
|
|
359
|
+
get isPending() {
|
|
360
|
+
return isPending();
|
|
361
|
+
},
|
|
362
|
+
get isSuccess() {
|
|
363
|
+
return status() === "success";
|
|
364
|
+
},
|
|
365
|
+
get isError() {
|
|
366
|
+
return isError();
|
|
367
|
+
},
|
|
368
|
+
get isLoading() {
|
|
369
|
+
return isPending() && isFetching();
|
|
370
|
+
},
|
|
371
|
+
get isFetching() {
|
|
372
|
+
return isFetching();
|
|
373
|
+
},
|
|
374
|
+
get isRefetching() {
|
|
375
|
+
return isFetching() && !isPending();
|
|
376
|
+
},
|
|
377
|
+
get isPaused() {
|
|
378
|
+
return meta.fetchStatus === "paused";
|
|
379
|
+
},
|
|
380
|
+
get isEnabled() {
|
|
381
|
+
return isEnabled();
|
|
382
|
+
},
|
|
383
|
+
get isLoadingError() {
|
|
384
|
+
return isError() && meta.dataUpdatedAt === 0;
|
|
385
|
+
},
|
|
386
|
+
get isRefetchError() {
|
|
387
|
+
return isError() && meta.dataUpdatedAt !== 0;
|
|
388
|
+
},
|
|
389
|
+
get isPlaceholderData() {
|
|
390
|
+
return hasPlaceholder();
|
|
391
|
+
},
|
|
392
|
+
get isStale() {
|
|
393
|
+
return isStale();
|
|
394
|
+
},
|
|
395
|
+
get isFetched() {
|
|
396
|
+
return meta.dataUpdateCount > 0 || meta.errorUpdateCount > 0;
|
|
397
|
+
},
|
|
398
|
+
get isFetchedAfterMount() {
|
|
399
|
+
return meta.dataUpdateCount > mountedAt.dataUpdateCount || meta.errorUpdateCount > mountedAt.errorUpdateCount;
|
|
400
|
+
},
|
|
401
|
+
get dataUpdatedAt() {
|
|
402
|
+
return meta.dataUpdatedAt;
|
|
403
|
+
},
|
|
404
|
+
get errorUpdatedAt() {
|
|
405
|
+
return meta.errorUpdatedAt;
|
|
406
|
+
},
|
|
407
|
+
get failureCount() {
|
|
408
|
+
return meta.fetchFailureCount;
|
|
409
|
+
},
|
|
410
|
+
get failureReason() {
|
|
411
|
+
return meta.fetchFailureReason;
|
|
412
|
+
},
|
|
413
|
+
get errorUpdateCount() {
|
|
414
|
+
return meta.errorUpdateCount;
|
|
415
|
+
},
|
|
416
|
+
get promise() {
|
|
417
|
+
return solidJs.resolve(() => data());
|
|
418
|
+
},
|
|
419
|
+
refetch: ((refetchOptions) => {
|
|
420
|
+
if (!isServer2 && latestOptions) {
|
|
421
|
+
observer.setOptions(latestOptions);
|
|
422
|
+
}
|
|
423
|
+
return observer.refetch(refetchOptions);
|
|
424
|
+
})
|
|
425
|
+
};
|
|
426
|
+
return {
|
|
427
|
+
result,
|
|
428
|
+
observer,
|
|
429
|
+
query,
|
|
430
|
+
defaultedOptions,
|
|
431
|
+
isFetching,
|
|
432
|
+
status
|
|
433
|
+
};
|
|
443
434
|
}
|
|
444
435
|
|
|
445
436
|
// src/useQuery.ts
|
|
@@ -450,157 +441,356 @@ function useQuery(options, queryClient) {
|
|
|
450
441
|
queryClient
|
|
451
442
|
);
|
|
452
443
|
}
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
queryClient
|
|
458
|
-
);
|
|
444
|
+
|
|
445
|
+
// src/queryOptions.ts
|
|
446
|
+
function queryOptions(options) {
|
|
447
|
+
return options;
|
|
459
448
|
}
|
|
460
|
-
function
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
() =>
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
);
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
449
|
+
async function dehydrateSettled(client, options) {
|
|
450
|
+
const cache = client.getQueryCache();
|
|
451
|
+
for (; ; ) {
|
|
452
|
+
const pending = cache.getAll().filter((query) => query.state.fetchStatus !== "idle").map((query) => query.promise);
|
|
453
|
+
if (pending.length === 0) break;
|
|
454
|
+
await Promise.allSettled(pending);
|
|
455
|
+
}
|
|
456
|
+
return queryCore.dehydrate(client, options);
|
|
457
|
+
}
|
|
458
|
+
var isServer3 = typeof window === "undefined";
|
|
459
|
+
function createCacheAggregate(subscribe, read, empty) {
|
|
460
|
+
const hydratedMount = !isServer3 && solidJs.sharedConfig.hydrating === true;
|
|
461
|
+
const [durable, setDurable] = solidJs.createSignal(
|
|
462
|
+
hydratedMount || isServer3 ? empty : solidJs.untrack(() => read(empty)),
|
|
463
|
+
{ ownedWrite: true }
|
|
473
464
|
);
|
|
474
|
-
const
|
|
475
|
-
|
|
476
|
-
};
|
|
477
|
-
const initialResult = solidJs.untrack(() => observer.getCurrentResult());
|
|
478
|
-
const [state, setState] = solidJs.createStore({
|
|
479
|
-
...initialResult,
|
|
480
|
-
mutate,
|
|
481
|
-
mutateAsync: initialResult.mutate
|
|
465
|
+
const [value, setValue] = solidJs.createOptimistic(() => durable(), {
|
|
466
|
+
ownedWrite: true
|
|
482
467
|
});
|
|
483
|
-
const
|
|
484
|
-
solidJs.
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
}
|
|
492
|
-
solidJs.onCleanup(unsubscribe);
|
|
493
|
-
solidJs.
|
|
468
|
+
const sync = () => {
|
|
469
|
+
const next = solidJs.untrack(() => read(solidJs.untrack(durable)));
|
|
470
|
+
setDurable(() => next);
|
|
471
|
+
setValue(() => next);
|
|
472
|
+
};
|
|
473
|
+
let unsubscribe = null;
|
|
474
|
+
const attach = () => {
|
|
475
|
+
unsubscribe ??= solidJs.untrack(() => subscribe(sync));
|
|
476
|
+
};
|
|
477
|
+
solidJs.onCleanup(() => unsubscribe?.());
|
|
478
|
+
solidJs.createEffect(
|
|
479
|
+
() => void 0,
|
|
494
480
|
() => {
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
throw error;
|
|
481
|
+
if (hydratedMount) {
|
|
482
|
+
attach();
|
|
483
|
+
sync();
|
|
499
484
|
}
|
|
500
|
-
},
|
|
501
|
-
() => {
|
|
502
485
|
}
|
|
503
486
|
);
|
|
504
|
-
return
|
|
487
|
+
if (isServer3) return () => empty;
|
|
488
|
+
if (!hydratedMount) attach();
|
|
489
|
+
return value;
|
|
505
490
|
}
|
|
506
|
-
|
|
491
|
+
|
|
492
|
+
// src/useIsFetching.ts
|
|
493
|
+
function useIsFetching(filters, queryClient) {
|
|
507
494
|
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
() =>
|
|
511
|
-
|
|
512
|
-
get _optimisticResults() {
|
|
513
|
-
return isRestoring() ? "isRestoring" : "optimistic";
|
|
514
|
-
}
|
|
515
|
-
})
|
|
516
|
-
)
|
|
495
|
+
return createCacheAggregate(
|
|
496
|
+
(onEvent) => client().getQueryCache().subscribe(onEvent),
|
|
497
|
+
() => client().isFetching(filters?.()),
|
|
498
|
+
0
|
|
517
499
|
);
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
500
|
+
}
|
|
501
|
+
function hasNextPage(options, data) {
|
|
502
|
+
if (!data || data.pages.length === 0) return false;
|
|
503
|
+
const lastIndex = data.pages.length - 1;
|
|
504
|
+
return options.getNextPageParam(
|
|
505
|
+
data.pages[lastIndex],
|
|
506
|
+
data.pages,
|
|
507
|
+
data.pageParams[lastIndex],
|
|
508
|
+
data.pageParams
|
|
509
|
+
) != null;
|
|
510
|
+
}
|
|
511
|
+
function hasPreviousPage(options, data) {
|
|
512
|
+
if (!data || data.pages.length === 0 || !options.getPreviousPageParam)
|
|
513
|
+
return false;
|
|
514
|
+
return options.getPreviousPageParam(
|
|
515
|
+
data.pages[0],
|
|
516
|
+
data.pages,
|
|
517
|
+
data.pageParams[0],
|
|
518
|
+
data.pageParams
|
|
519
|
+
) != null;
|
|
520
|
+
}
|
|
521
|
+
function useInfiniteQuery(options, queryClient) {
|
|
522
|
+
const layer = useBaseQueryLayer(
|
|
523
|
+
// `_type` is how query-core stamps a cache entry as infinite
|
|
524
|
+
// (`Query.setOptions` → `#queryType`), which makes every fetch attach
|
|
525
|
+
// `infiniteQueryBehavior`. Core only sets it inside
|
|
526
|
+
// `InfiniteQueryObserver.setOptions`, but the adapter's pull path can
|
|
527
|
+
// build and fetch the entry first (reactive key change recomputes the
|
|
528
|
+
// data memo before the deferred observer effect runs) — without the
|
|
529
|
+
// stamp that fetch would run as a plain query and corrupt the entry.
|
|
530
|
+
solidJs.createMemo(() => ({ ...options(), _type: "infinite" })),
|
|
531
|
+
queryCore.InfiniteQueryObserver,
|
|
532
|
+
queryClient
|
|
536
533
|
);
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
534
|
+
const observer = layer.observer;
|
|
535
|
+
const direction = () => layer.query().state.fetchMeta?.fetchMore?.direction;
|
|
536
|
+
const pageOptions = () => layer.defaultedOptions();
|
|
537
|
+
const infiniteData = () => layer.query().state.data;
|
|
538
|
+
const isFetchingNextPage = () => layer.isFetching() && direction() === "forward";
|
|
539
|
+
const isFetchingPreviousPage = () => layer.isFetching() && direction() === "backward";
|
|
540
|
+
const isError = () => layer.status() === "error";
|
|
541
|
+
const result = Object.defineProperties(
|
|
542
|
+
{},
|
|
543
|
+
{
|
|
544
|
+
...Object.getOwnPropertyDescriptors(layer.result),
|
|
545
|
+
fetchNextPage: {
|
|
546
|
+
value: (fetchOptions) => observer.fetchNextPage(fetchOptions),
|
|
547
|
+
enumerable: true
|
|
548
|
+
},
|
|
549
|
+
fetchPreviousPage: {
|
|
550
|
+
value: (fetchOptions) => observer.fetchPreviousPage(fetchOptions),
|
|
551
|
+
enumerable: true
|
|
552
|
+
},
|
|
553
|
+
hasNextPage: {
|
|
554
|
+
get: () => hasNextPage(pageOptions(), infiniteData()),
|
|
555
|
+
enumerable: true
|
|
556
|
+
},
|
|
557
|
+
hasPreviousPage: {
|
|
558
|
+
get: () => hasPreviousPage(pageOptions(), infiniteData()),
|
|
559
|
+
enumerable: true
|
|
560
|
+
},
|
|
561
|
+
isFetchingNextPage: {
|
|
562
|
+
get: isFetchingNextPage,
|
|
563
|
+
enumerable: true
|
|
564
|
+
},
|
|
565
|
+
isFetchingPreviousPage: {
|
|
566
|
+
get: isFetchingPreviousPage,
|
|
567
|
+
enumerable: true
|
|
568
|
+
},
|
|
569
|
+
isFetchNextPageError: {
|
|
570
|
+
get: () => isError() && direction() === "forward",
|
|
571
|
+
enumerable: true
|
|
572
|
+
},
|
|
573
|
+
isFetchPreviousPageError: {
|
|
574
|
+
get: () => isError() && direction() === "backward",
|
|
575
|
+
enumerable: true
|
|
576
|
+
},
|
|
577
|
+
isRefetching: {
|
|
578
|
+
get: () => layer.isFetching() && layer.status() !== "pending" && !isFetchingNextPage() && !isFetchingPreviousPage(),
|
|
579
|
+
enumerable: true
|
|
580
|
+
},
|
|
581
|
+
isRefetchError: {
|
|
582
|
+
get: () => {
|
|
583
|
+
const errored = isError() && layer.query().state.dataUpdatedAt !== 0;
|
|
584
|
+
return errored && direction() === void 0;
|
|
585
|
+
},
|
|
586
|
+
enumerable: true
|
|
553
587
|
}
|
|
554
|
-
},
|
|
555
|
-
() => {
|
|
556
588
|
}
|
|
557
589
|
);
|
|
558
|
-
|
|
559
|
-
unsubscribe();
|
|
560
|
-
});
|
|
561
|
-
solidJs.createMemo(() => {
|
|
562
|
-
const queries = defaultedQueries();
|
|
563
|
-
solidJs.runWithOwner(null, () => {
|
|
564
|
-
observer.setQueries(
|
|
565
|
-
queries,
|
|
566
|
-
queriesOptions().combine ? {
|
|
567
|
-
combine: queriesOptions().combine
|
|
568
|
-
} : void 0
|
|
569
|
-
);
|
|
570
|
-
});
|
|
571
|
-
return queries;
|
|
572
|
-
});
|
|
573
|
-
return state;
|
|
590
|
+
return result;
|
|
574
591
|
}
|
|
575
|
-
exports.QueryClient = class QueryClient extends queryCore.QueryClient {
|
|
576
|
-
constructor(config = {}) {
|
|
577
|
-
super(config);
|
|
578
|
-
}
|
|
579
|
-
};
|
|
580
592
|
|
|
581
|
-
// src/
|
|
582
|
-
function
|
|
593
|
+
// src/infiniteQueryOptions.ts
|
|
594
|
+
function infiniteQueryOptions(options) {
|
|
583
595
|
return options;
|
|
584
596
|
}
|
|
585
|
-
|
|
597
|
+
var isServer4 = typeof window === "undefined";
|
|
598
|
+
var IDLE = {
|
|
599
|
+
status: "idle",
|
|
600
|
+
data: void 0,
|
|
601
|
+
error: null,
|
|
602
|
+
variables: void 0,
|
|
603
|
+
submittedAt: 0
|
|
604
|
+
};
|
|
605
|
+
async function drain(iterator) {
|
|
606
|
+
let input;
|
|
607
|
+
for (; ; ) {
|
|
608
|
+
const result = await iterator.next(input);
|
|
609
|
+
if (result.done) return result.value;
|
|
610
|
+
input = result.value != null ? await result.value : void 0;
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function useMutation(options, queryClient) {
|
|
586
614
|
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
587
|
-
const
|
|
588
|
-
const [
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
);
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
615
|
+
const [flight, setFlight] = solidJs.createOptimistic(null);
|
|
616
|
+
const [settled, setSettled] = solidJs.createSignal(IDLE);
|
|
617
|
+
let activeMutation = null;
|
|
618
|
+
let unsubscribeFlight = null;
|
|
619
|
+
const [flightVersion, setFlightVersion] = solidJs.createSignal(0);
|
|
620
|
+
if (!isServer4)
|
|
621
|
+
solidJs.onCleanup(() => {
|
|
622
|
+
unsubscribeFlight?.();
|
|
623
|
+
unsubscribeFlight = null;
|
|
624
|
+
});
|
|
625
|
+
async function* run(variables) {
|
|
626
|
+
const opts = solidJs.untrack(options);
|
|
627
|
+
const callbackContext = {
|
|
628
|
+
client: solidJs.untrack(client),
|
|
629
|
+
meta: opts.meta,
|
|
630
|
+
mutationKey: opts.mutationKey
|
|
631
|
+
};
|
|
632
|
+
if (!isServer4) setFlight({ variables });
|
|
633
|
+
opts.onMutate?.(variables, callbackContext);
|
|
634
|
+
const c = solidJs.untrack(client);
|
|
635
|
+
const mutation = c.getMutationCache().build(c, {
|
|
636
|
+
...opts,
|
|
637
|
+
// Options-level callbacks re-run below, inside the transaction —
|
|
638
|
+
// executing them here (inside the await gap) would let their
|
|
639
|
+
// cache writes and invalidations escape the atomic settle.
|
|
640
|
+
onMutate: void 0,
|
|
641
|
+
onSuccess: void 0,
|
|
642
|
+
onError: void 0,
|
|
643
|
+
onSettled: void 0
|
|
644
|
+
});
|
|
645
|
+
activeMutation = mutation;
|
|
646
|
+
if (!isServer4) {
|
|
647
|
+
unsubscribeFlight?.();
|
|
648
|
+
unsubscribeFlight = c.getMutationCache().subscribe((event) => {
|
|
649
|
+
if ("mutation" in event && event.mutation === activeMutation) {
|
|
650
|
+
setFlightVersion((v) => v + 1);
|
|
651
|
+
}
|
|
652
|
+
});
|
|
653
|
+
}
|
|
654
|
+
const settleFlight = () => {
|
|
655
|
+
if (activeMutation !== mutation) return;
|
|
656
|
+
activeMutation = null;
|
|
657
|
+
unsubscribeFlight?.();
|
|
658
|
+
unsubscribeFlight = null;
|
|
659
|
+
};
|
|
660
|
+
async function* settleFailure(error) {
|
|
661
|
+
try {
|
|
662
|
+
if (opts.onError)
|
|
663
|
+
yield opts.onError(error, variables, void 0, callbackContext);
|
|
664
|
+
} catch (callbackError) {
|
|
665
|
+
void Promise.reject(callbackError);
|
|
666
|
+
}
|
|
667
|
+
try {
|
|
668
|
+
if (opts.onSettled)
|
|
669
|
+
yield opts.onSettled(
|
|
670
|
+
void 0,
|
|
671
|
+
error,
|
|
672
|
+
variables,
|
|
673
|
+
void 0,
|
|
674
|
+
callbackContext
|
|
675
|
+
);
|
|
676
|
+
} catch (callbackError) {
|
|
677
|
+
void Promise.reject(callbackError);
|
|
678
|
+
}
|
|
679
|
+
if (!isServer4)
|
|
680
|
+
setSettled({
|
|
681
|
+
status: "error",
|
|
682
|
+
data: void 0,
|
|
683
|
+
error,
|
|
684
|
+
variables,
|
|
685
|
+
submittedAt: mutation.state.submittedAt
|
|
686
|
+
});
|
|
687
|
+
settleFlight();
|
|
688
|
+
throw error;
|
|
689
|
+
}
|
|
690
|
+
let result2;
|
|
691
|
+
try {
|
|
692
|
+
result2 = await mutation.execute(variables);
|
|
693
|
+
} catch (error) {
|
|
694
|
+
yield;
|
|
695
|
+
yield* settleFailure(error);
|
|
696
|
+
throw error;
|
|
697
|
+
}
|
|
698
|
+
yield;
|
|
699
|
+
try {
|
|
700
|
+
if (opts.onSuccess)
|
|
701
|
+
yield opts.onSuccess(
|
|
702
|
+
result2,
|
|
703
|
+
variables,
|
|
704
|
+
void 0,
|
|
705
|
+
callbackContext
|
|
706
|
+
);
|
|
707
|
+
if (opts.onSettled)
|
|
708
|
+
yield opts.onSettled(
|
|
709
|
+
result2,
|
|
710
|
+
null,
|
|
711
|
+
variables,
|
|
712
|
+
void 0,
|
|
713
|
+
callbackContext
|
|
714
|
+
);
|
|
715
|
+
} catch (callbackError) {
|
|
716
|
+
yield* settleFailure(callbackError);
|
|
717
|
+
throw callbackError;
|
|
718
|
+
}
|
|
719
|
+
if (!isServer4)
|
|
720
|
+
setSettled({
|
|
721
|
+
status: "success",
|
|
722
|
+
data: result2,
|
|
723
|
+
error: null,
|
|
724
|
+
variables,
|
|
725
|
+
submittedAt: mutation.state.submittedAt
|
|
726
|
+
});
|
|
727
|
+
settleFlight();
|
|
728
|
+
return result2;
|
|
729
|
+
}
|
|
730
|
+
const invoke = isServer4 ? (variables) => drain(run(variables)) : solidJs.action(run);
|
|
731
|
+
const mutate = (variables) => {
|
|
732
|
+
const promise = invoke(variables);
|
|
733
|
+
promise.catch(queryCore.noop);
|
|
734
|
+
return promise;
|
|
735
|
+
};
|
|
736
|
+
const status = () => flight() !== null ? "pending" : settled().status;
|
|
737
|
+
const isPending = () => flight() !== null;
|
|
738
|
+
solidJs.createRenderEffect(
|
|
739
|
+
() => {
|
|
740
|
+
const state = settled();
|
|
741
|
+
if (state.status === "error" && queryCore.shouldThrowError(solidJs.untrack(options).throwOnError, [state.error])) {
|
|
742
|
+
throw state.error;
|
|
743
|
+
}
|
|
744
|
+
},
|
|
745
|
+
() => {
|
|
746
|
+
}
|
|
596
747
|
);
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
748
|
+
const result = {
|
|
749
|
+
mutate,
|
|
750
|
+
get data() {
|
|
751
|
+
return settled().data;
|
|
752
|
+
},
|
|
753
|
+
get error() {
|
|
754
|
+
return flight() !== null ? null : settled().error;
|
|
755
|
+
},
|
|
756
|
+
get variables() {
|
|
757
|
+
return flight()?.variables ?? settled().variables;
|
|
758
|
+
},
|
|
759
|
+
get status() {
|
|
760
|
+
return status();
|
|
761
|
+
},
|
|
762
|
+
get isPending() {
|
|
763
|
+
return isPending();
|
|
764
|
+
},
|
|
765
|
+
get isIdle() {
|
|
766
|
+
return status() === "idle";
|
|
767
|
+
},
|
|
768
|
+
get isSuccess() {
|
|
769
|
+
return status() === "success";
|
|
770
|
+
},
|
|
771
|
+
get isError() {
|
|
772
|
+
return status() === "error";
|
|
773
|
+
},
|
|
774
|
+
get submittedAt() {
|
|
775
|
+
return flight() !== null ? (flightVersion(), activeMutation?.state.submittedAt ?? 0) : settled().submittedAt;
|
|
776
|
+
},
|
|
777
|
+
get failureCount() {
|
|
778
|
+
flightVersion();
|
|
779
|
+
return activeMutation?.state.failureCount ?? 0;
|
|
780
|
+
},
|
|
781
|
+
get failureReason() {
|
|
782
|
+
flightVersion();
|
|
783
|
+
return activeMutation?.state.failureReason ?? null;
|
|
784
|
+
},
|
|
785
|
+
get isPaused() {
|
|
786
|
+
flightVersion();
|
|
787
|
+
return activeMutation?.state.isPaused ?? false;
|
|
788
|
+
},
|
|
789
|
+
reset: () => {
|
|
790
|
+
setSettled(IDLE);
|
|
791
|
+
}
|
|
792
|
+
};
|
|
793
|
+
return result;
|
|
604
794
|
}
|
|
605
795
|
|
|
606
796
|
// src/mutationOptions.ts
|
|
@@ -609,18 +799,11 @@ function mutationOptions(options) {
|
|
|
609
799
|
}
|
|
610
800
|
function useIsMutating(filters, queryClient) {
|
|
611
801
|
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
);
|
|
617
|
-
const unsubscribe = solidJs.untrack(
|
|
618
|
-
() => mutationCache().subscribe((_result) => {
|
|
619
|
-
setMutations(client().isMutating(filters?.()));
|
|
620
|
-
})
|
|
802
|
+
return createCacheAggregate(
|
|
803
|
+
(onEvent) => client().getMutationCache().subscribe(onEvent),
|
|
804
|
+
() => client().isMutating(filters?.()),
|
|
805
|
+
0
|
|
621
806
|
);
|
|
622
|
-
solidJs.onCleanup(unsubscribe);
|
|
623
|
-
return mutations;
|
|
624
807
|
}
|
|
625
808
|
function getResult(mutationCache, options) {
|
|
626
809
|
return mutationCache.findAll(options.filters).map(
|
|
@@ -629,35 +812,57 @@ function getResult(mutationCache, options) {
|
|
|
629
812
|
}
|
|
630
813
|
function useMutationState(options = () => ({}), queryClient) {
|
|
631
814
|
const client = solidJs.createMemo(() => exports.useQueryClient(queryClient?.()));
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
() => mutationCache().subscribe(() => {
|
|
639
|
-
setResult((prev) => {
|
|
640
|
-
const nextResult = queryCore.replaceEqualDeep(
|
|
641
|
-
prev,
|
|
642
|
-
getResult(mutationCache(), options())
|
|
643
|
-
);
|
|
644
|
-
return prev === nextResult ? prev : nextResult;
|
|
645
|
-
});
|
|
646
|
-
})
|
|
815
|
+
return createCacheAggregate(
|
|
816
|
+
(onEvent) => client().getMutationCache().subscribe(onEvent),
|
|
817
|
+
// Structural sharing against the previous committed value keeps
|
|
818
|
+
// unchanged mutation states referentially stable across syncs.
|
|
819
|
+
(prev) => queryCore.replaceEqualDeep(prev, getResult(client().getMutationCache(), options())),
|
|
820
|
+
[]
|
|
647
821
|
);
|
|
648
|
-
|
|
649
|
-
|
|
822
|
+
}
|
|
823
|
+
function useQueries(queriesOptions, queryClient) {
|
|
824
|
+
const length = solidJs.createMemo(() => queriesOptions().queries.length);
|
|
825
|
+
const results = solidJs.repeat(length, (index) => {
|
|
826
|
+
let lastOptions;
|
|
827
|
+
return useBaseQuery(
|
|
828
|
+
() => {
|
|
829
|
+
const next = queriesOptions().queries[index];
|
|
830
|
+
if (next !== void 0) lastOptions = next;
|
|
831
|
+
return lastOptions;
|
|
832
|
+
},
|
|
833
|
+
queryCore.QueryObserver,
|
|
834
|
+
queryClient
|
|
835
|
+
);
|
|
836
|
+
});
|
|
837
|
+
const combined = solidJs.createMemo(() => {
|
|
838
|
+
const combine = queriesOptions().combine;
|
|
839
|
+
const list = results();
|
|
840
|
+
return combine ? combine(list) : list;
|
|
841
|
+
});
|
|
842
|
+
return new Proxy([], {
|
|
843
|
+
get(_, prop) {
|
|
844
|
+
if (prop === solidJs.$TRACK) return combined();
|
|
845
|
+
return Reflect.get(combined(), prop);
|
|
846
|
+
},
|
|
847
|
+
has(_, prop) {
|
|
848
|
+
if (prop === solidJs.$TRACK) return true;
|
|
849
|
+
return Reflect.has(combined(), prop);
|
|
850
|
+
},
|
|
851
|
+
ownKeys() {
|
|
852
|
+
return Reflect.ownKeys(combined());
|
|
853
|
+
},
|
|
854
|
+
getOwnPropertyDescriptor(_, prop) {
|
|
855
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(
|
|
856
|
+
combined(),
|
|
857
|
+
prop
|
|
858
|
+
);
|
|
859
|
+
if (descriptor) descriptor.configurable = true;
|
|
860
|
+
return descriptor;
|
|
861
|
+
}
|
|
862
|
+
});
|
|
650
863
|
}
|
|
651
864
|
|
|
652
|
-
|
|
653
|
-
exports.createQuery = useQuery;
|
|
654
|
-
exports.createInfiniteQuery = useInfiniteQuery;
|
|
655
|
-
exports.createMutation = useMutation;
|
|
656
|
-
exports.createQueries = useQueries;
|
|
657
|
-
|
|
658
|
-
exports.createIsFetching = useIsFetching;
|
|
659
|
-
exports.createIsMutating = useIsMutating;
|
|
660
|
-
exports.createMutationState = useMutationState;
|
|
865
|
+
exports.dehydrateSettled = dehydrateSettled;
|
|
661
866
|
exports.infiniteQueryOptions = infiniteQueryOptions;
|
|
662
867
|
exports.mutationOptions = mutationOptions;
|
|
663
868
|
exports.queryOptions = queryOptions;
|