@tanstack/angular-query-experimental 5.82.0 → 5.83.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-base-query.d.ts +8 -0
- package/dist/create-base-query.mjs +74 -0
- package/dist/create-base-query.mjs.map +1 -0
- package/dist/index.d.ts +26 -0
- package/dist/index.mjs +35 -0
- package/dist/index.mjs.map +1 -0
- package/dist/infinite-query-options.d.ts +44 -0
- package/dist/infinite-query-options.mjs +7 -0
- package/dist/infinite-query-options.mjs.map +1 -0
- package/dist/inject-infinite-query.d.ts +39 -0
- package/dist/inject-infinite-query.mjs +18 -0
- package/dist/inject-infinite-query.mjs.map +1 -0
- package/dist/inject-is-fetching.d.ts +21 -0
- package/dist/inject-is-fetching.mjs +31 -0
- package/dist/inject-is-fetching.mjs.map +1 -0
- package/dist/inject-is-mutating.d.ts +20 -0
- package/dist/inject-is-mutating.mjs +31 -0
- package/dist/inject-is-mutating.mjs.map +1 -0
- package/dist/inject-is-restoring.d.ts +24 -0
- package/dist/inject-is-restoring.mjs +24 -0
- package/dist/inject-is-restoring.mjs.map +1 -0
- package/dist/inject-mutation-state.d.ts +26 -0
- package/dist/inject-mutation-state.mjs +51 -0
- package/dist/inject-mutation-state.mjs.map +1 -0
- package/dist/inject-mutation.d.ts +22 -0
- package/dist/inject-mutation.mjs +79 -0
- package/dist/inject-mutation.mjs.map +1 -0
- package/dist/inject-queries.d.ts +76 -0
- package/dist/inject-queries.mjs +49 -0
- package/dist/inject-queries.mjs.map +1 -0
- package/dist/inject-query-client.d.ts +19 -0
- package/dist/inject-query-client.mjs +9 -0
- package/dist/inject-query-client.mjs.map +1 -0
- package/dist/inject-query.d.ts +126 -0
- package/dist/inject-query.mjs +14 -0
- package/dist/inject-query.mjs.map +1 -0
- package/dist/mutation-options.d.ts +38 -0
- package/dist/mutation-options.mjs +7 -0
- package/dist/mutation-options.mjs.map +1 -0
- package/dist/providers.d.ts +215 -0
- package/dist/providers.mjs +109 -0
- package/dist/providers.mjs.map +1 -0
- package/dist/query-options.d.ts +87 -0
- package/dist/query-options.mjs +7 -0
- package/dist/query-options.mjs.map +1 -0
- package/dist/signal-proxy.d.ts +11 -0
- package/dist/signal-proxy.mjs +29 -0
- package/dist/signal-proxy.mjs.map +1 -0
- package/dist/types.d.ts +89 -0
- package/dist/util/is-dev-mode/is-dev-mode.d.ts +1 -0
- package/package.json +9 -10
- package/build/index.d.ts +0 -821
- package/build/index.mjs +0 -622
- package/build/index.mjs.map +0 -1
- package/src/test-setup.ts +0 -7
package/build/index.mjs
DELETED
|
@@ -1,622 +0,0 @@
|
|
|
1
|
-
// src/index.ts
|
|
2
|
-
export * from "@tanstack/query-core";
|
|
3
|
-
|
|
4
|
-
// src/query-options.ts
|
|
5
|
-
function queryOptions(options) {
|
|
6
|
-
return options;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// src/mutation-options.ts
|
|
10
|
-
function mutationOptions(options) {
|
|
11
|
-
return options;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// src/infinite-query-options.ts
|
|
15
|
-
function infiniteQueryOptions(options) {
|
|
16
|
-
return options;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// src/inject-infinite-query.ts
|
|
20
|
-
import { InfiniteQueryObserver } from "@tanstack/query-core";
|
|
21
|
-
import {
|
|
22
|
-
Injector as Injector2,
|
|
23
|
-
assertInInjectionContext as assertInInjectionContext2,
|
|
24
|
-
inject as inject3,
|
|
25
|
-
runInInjectionContext
|
|
26
|
-
} from "@angular/core";
|
|
27
|
-
|
|
28
|
-
// src/create-base-query.ts
|
|
29
|
-
import {
|
|
30
|
-
NgZone,
|
|
31
|
-
VERSION,
|
|
32
|
-
computed as computed2,
|
|
33
|
-
effect,
|
|
34
|
-
inject as inject2,
|
|
35
|
-
signal as signal2,
|
|
36
|
-
untracked as untracked2
|
|
37
|
-
} from "@angular/core";
|
|
38
|
-
import {
|
|
39
|
-
QueryClient,
|
|
40
|
-
notifyManager,
|
|
41
|
-
shouldThrowError
|
|
42
|
-
} from "@tanstack/query-core";
|
|
43
|
-
|
|
44
|
-
// src/signal-proxy.ts
|
|
45
|
-
import { computed, untracked } from "@angular/core";
|
|
46
|
-
function signalProxy(inputSignal) {
|
|
47
|
-
const internalState = {};
|
|
48
|
-
return new Proxy(internalState, {
|
|
49
|
-
get(target, prop) {
|
|
50
|
-
const computedField = target[prop];
|
|
51
|
-
if (computedField) return computedField;
|
|
52
|
-
const targetField = untracked(inputSignal)[prop];
|
|
53
|
-
if (typeof targetField === "function") return targetField;
|
|
54
|
-
return target[prop] = computed(() => inputSignal()[prop]);
|
|
55
|
-
},
|
|
56
|
-
has(_, prop) {
|
|
57
|
-
return !!untracked(inputSignal)[prop];
|
|
58
|
-
},
|
|
59
|
-
ownKeys() {
|
|
60
|
-
return Reflect.ownKeys(untracked(inputSignal));
|
|
61
|
-
},
|
|
62
|
-
getOwnPropertyDescriptor() {
|
|
63
|
-
return {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true
|
|
66
|
-
};
|
|
67
|
-
}
|
|
68
|
-
});
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// src/inject-is-restoring.ts
|
|
72
|
-
import {
|
|
73
|
-
InjectionToken,
|
|
74
|
-
Injector,
|
|
75
|
-
assertInInjectionContext,
|
|
76
|
-
inject,
|
|
77
|
-
signal
|
|
78
|
-
} from "@angular/core";
|
|
79
|
-
var IS_RESTORING = new InjectionToken(
|
|
80
|
-
typeof ngDevMode === "undefined" || ngDevMode ? "TANSTACK_QUERY_IS_RESTORING" : "",
|
|
81
|
-
{
|
|
82
|
-
// Default value when not provided
|
|
83
|
-
factory: () => signal(false).asReadonly()
|
|
84
|
-
}
|
|
85
|
-
);
|
|
86
|
-
function injectIsRestoring(options) {
|
|
87
|
-
!options?.injector && assertInInjectionContext(injectIsRestoring);
|
|
88
|
-
const injector = options?.injector ?? inject(Injector);
|
|
89
|
-
return injector.get(IS_RESTORING);
|
|
90
|
-
}
|
|
91
|
-
function provideIsRestoring(isRestoring) {
|
|
92
|
-
return {
|
|
93
|
-
provide: IS_RESTORING,
|
|
94
|
-
useValue: isRestoring
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
// src/create-base-query.ts
|
|
99
|
-
function createBaseQuery(optionsFn, Observer) {
|
|
100
|
-
const ngZone = inject2(NgZone);
|
|
101
|
-
const queryClient = inject2(QueryClient);
|
|
102
|
-
const isRestoring = injectIsRestoring();
|
|
103
|
-
const defaultedOptionsSignal = computed2(() => {
|
|
104
|
-
const defaultedOptions = queryClient.defaultQueryOptions(optionsFn());
|
|
105
|
-
defaultedOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
106
|
-
return defaultedOptions;
|
|
107
|
-
});
|
|
108
|
-
const observerSignal = (() => {
|
|
109
|
-
let instance = null;
|
|
110
|
-
return computed2(() => {
|
|
111
|
-
return instance ||= new Observer(queryClient, defaultedOptionsSignal());
|
|
112
|
-
});
|
|
113
|
-
})();
|
|
114
|
-
const optimisticResultSignal = computed2(
|
|
115
|
-
() => observerSignal().getOptimisticResult(defaultedOptionsSignal())
|
|
116
|
-
);
|
|
117
|
-
const resultFromSubscriberSignal = signal2(null);
|
|
118
|
-
effect(
|
|
119
|
-
(onCleanup) => {
|
|
120
|
-
const observer = observerSignal();
|
|
121
|
-
const defaultedOptions = defaultedOptionsSignal();
|
|
122
|
-
untracked2(() => {
|
|
123
|
-
observer.setOptions(defaultedOptions);
|
|
124
|
-
});
|
|
125
|
-
onCleanup(() => {
|
|
126
|
-
ngZone.run(() => resultFromSubscriberSignal.set(null));
|
|
127
|
-
});
|
|
128
|
-
},
|
|
129
|
-
{
|
|
130
|
-
// Set allowSignalWrites to support Angular < v19
|
|
131
|
-
// Set to undefined to avoid warning on newer versions
|
|
132
|
-
allowSignalWrites: VERSION.major < "19" || void 0
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
effect((onCleanup) => {
|
|
136
|
-
const observer = observerSignal();
|
|
137
|
-
const unsubscribe = isRestoring() ? () => void 0 : untracked2(
|
|
138
|
-
() => ngZone.runOutsideAngular(
|
|
139
|
-
() => observer.subscribe(
|
|
140
|
-
notifyManager.batchCalls((state) => {
|
|
141
|
-
ngZone.run(() => {
|
|
142
|
-
if (state.isError && !state.isFetching && shouldThrowError(observer.options.throwOnError, [
|
|
143
|
-
state.error,
|
|
144
|
-
observer.getCurrentQuery()
|
|
145
|
-
])) {
|
|
146
|
-
ngZone.onError.emit(state.error);
|
|
147
|
-
throw state.error;
|
|
148
|
-
}
|
|
149
|
-
resultFromSubscriberSignal.set(state);
|
|
150
|
-
});
|
|
151
|
-
})
|
|
152
|
-
)
|
|
153
|
-
)
|
|
154
|
-
);
|
|
155
|
-
onCleanup(unsubscribe);
|
|
156
|
-
});
|
|
157
|
-
return signalProxy(
|
|
158
|
-
computed2(() => {
|
|
159
|
-
const subscriberResult = resultFromSubscriberSignal();
|
|
160
|
-
const optimisticResult = optimisticResultSignal();
|
|
161
|
-
return subscriberResult ?? optimisticResult;
|
|
162
|
-
})
|
|
163
|
-
);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// src/inject-infinite-query.ts
|
|
167
|
-
function injectInfiniteQuery(injectInfiniteQueryFn, options) {
|
|
168
|
-
!options?.injector && assertInInjectionContext2(injectInfiniteQuery);
|
|
169
|
-
const injector = options?.injector ?? inject3(Injector2);
|
|
170
|
-
return runInInjectionContext(
|
|
171
|
-
injector,
|
|
172
|
-
() => createBaseQuery(
|
|
173
|
-
injectInfiniteQueryFn,
|
|
174
|
-
InfiniteQueryObserver
|
|
175
|
-
)
|
|
176
|
-
);
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
// src/inject-is-fetching.ts
|
|
180
|
-
import {
|
|
181
|
-
DestroyRef,
|
|
182
|
-
Injector as Injector3,
|
|
183
|
-
NgZone as NgZone2,
|
|
184
|
-
assertInInjectionContext as assertInInjectionContext3,
|
|
185
|
-
inject as inject4,
|
|
186
|
-
signal as signal3
|
|
187
|
-
} from "@angular/core";
|
|
188
|
-
import { QueryClient as QueryClient2, notifyManager as notifyManager2 } from "@tanstack/query-core";
|
|
189
|
-
function injectIsFetching(filters, options) {
|
|
190
|
-
!options?.injector && assertInInjectionContext3(injectIsFetching);
|
|
191
|
-
const injector = options?.injector ?? inject4(Injector3);
|
|
192
|
-
const destroyRef = injector.get(DestroyRef);
|
|
193
|
-
const ngZone = injector.get(NgZone2);
|
|
194
|
-
const queryClient = injector.get(QueryClient2);
|
|
195
|
-
const cache = queryClient.getQueryCache();
|
|
196
|
-
let isFetching = queryClient.isFetching(filters);
|
|
197
|
-
const result = signal3(isFetching);
|
|
198
|
-
const unsubscribe = ngZone.runOutsideAngular(
|
|
199
|
-
() => cache.subscribe(
|
|
200
|
-
notifyManager2.batchCalls(() => {
|
|
201
|
-
const newIsFetching = queryClient.isFetching(filters);
|
|
202
|
-
if (isFetching !== newIsFetching) {
|
|
203
|
-
isFetching = newIsFetching;
|
|
204
|
-
ngZone.run(() => {
|
|
205
|
-
result.set(isFetching);
|
|
206
|
-
});
|
|
207
|
-
}
|
|
208
|
-
})
|
|
209
|
-
)
|
|
210
|
-
);
|
|
211
|
-
destroyRef.onDestroy(unsubscribe);
|
|
212
|
-
return result;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
// src/inject-is-mutating.ts
|
|
216
|
-
import {
|
|
217
|
-
DestroyRef as DestroyRef2,
|
|
218
|
-
Injector as Injector4,
|
|
219
|
-
NgZone as NgZone3,
|
|
220
|
-
assertInInjectionContext as assertInInjectionContext4,
|
|
221
|
-
inject as inject5,
|
|
222
|
-
signal as signal4
|
|
223
|
-
} from "@angular/core";
|
|
224
|
-
import { QueryClient as QueryClient3, notifyManager as notifyManager3 } from "@tanstack/query-core";
|
|
225
|
-
function injectIsMutating(filters, options) {
|
|
226
|
-
!options?.injector && assertInInjectionContext4(injectIsMutating);
|
|
227
|
-
const injector = options?.injector ?? inject5(Injector4);
|
|
228
|
-
const destroyRef = injector.get(DestroyRef2);
|
|
229
|
-
const ngZone = injector.get(NgZone3);
|
|
230
|
-
const queryClient = injector.get(QueryClient3);
|
|
231
|
-
const cache = queryClient.getMutationCache();
|
|
232
|
-
let isMutating = queryClient.isMutating(filters);
|
|
233
|
-
const result = signal4(isMutating);
|
|
234
|
-
const unsubscribe = ngZone.runOutsideAngular(
|
|
235
|
-
() => cache.subscribe(
|
|
236
|
-
notifyManager3.batchCalls(() => {
|
|
237
|
-
const newIsMutating = queryClient.isMutating(filters);
|
|
238
|
-
if (isMutating !== newIsMutating) {
|
|
239
|
-
isMutating = newIsMutating;
|
|
240
|
-
ngZone.run(() => {
|
|
241
|
-
result.set(isMutating);
|
|
242
|
-
});
|
|
243
|
-
}
|
|
244
|
-
})
|
|
245
|
-
)
|
|
246
|
-
);
|
|
247
|
-
destroyRef.onDestroy(unsubscribe);
|
|
248
|
-
return result;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
// src/inject-mutation.ts
|
|
252
|
-
import {
|
|
253
|
-
DestroyRef as DestroyRef3,
|
|
254
|
-
Injector as Injector5,
|
|
255
|
-
NgZone as NgZone4,
|
|
256
|
-
assertInInjectionContext as assertInInjectionContext5,
|
|
257
|
-
computed as computed3,
|
|
258
|
-
effect as effect2,
|
|
259
|
-
inject as inject6,
|
|
260
|
-
signal as signal5,
|
|
261
|
-
untracked as untracked3
|
|
262
|
-
} from "@angular/core";
|
|
263
|
-
import {
|
|
264
|
-
MutationObserver,
|
|
265
|
-
QueryClient as QueryClient4,
|
|
266
|
-
noop,
|
|
267
|
-
notifyManager as notifyManager4,
|
|
268
|
-
shouldThrowError as shouldThrowError2
|
|
269
|
-
} from "@tanstack/query-core";
|
|
270
|
-
function injectMutation(injectMutationFn, options) {
|
|
271
|
-
!options?.injector && assertInInjectionContext5(injectMutation);
|
|
272
|
-
const injector = options?.injector ?? inject6(Injector5);
|
|
273
|
-
const destroyRef = injector.get(DestroyRef3);
|
|
274
|
-
const ngZone = injector.get(NgZone4);
|
|
275
|
-
const queryClient = injector.get(QueryClient4);
|
|
276
|
-
const optionsSignal = computed3(injectMutationFn);
|
|
277
|
-
const observerSignal = (() => {
|
|
278
|
-
let instance = null;
|
|
279
|
-
return computed3(() => {
|
|
280
|
-
return instance ||= new MutationObserver(queryClient, optionsSignal());
|
|
281
|
-
});
|
|
282
|
-
})();
|
|
283
|
-
const mutateFnSignal = computed3(() => {
|
|
284
|
-
const observer = observerSignal();
|
|
285
|
-
return (variables, mutateOptions) => {
|
|
286
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
287
|
-
};
|
|
288
|
-
});
|
|
289
|
-
const resultFromInitialOptionsSignal = computed3(() => {
|
|
290
|
-
const observer = observerSignal();
|
|
291
|
-
return observer.getCurrentResult();
|
|
292
|
-
});
|
|
293
|
-
const resultFromSubscriberSignal = signal5(null);
|
|
294
|
-
effect2(
|
|
295
|
-
() => {
|
|
296
|
-
const observer = observerSignal();
|
|
297
|
-
const observerOptions = optionsSignal();
|
|
298
|
-
untracked3(() => {
|
|
299
|
-
observer.setOptions(observerOptions);
|
|
300
|
-
});
|
|
301
|
-
},
|
|
302
|
-
{
|
|
303
|
-
injector
|
|
304
|
-
}
|
|
305
|
-
);
|
|
306
|
-
effect2(
|
|
307
|
-
() => {
|
|
308
|
-
const observer = observerSignal();
|
|
309
|
-
untracked3(() => {
|
|
310
|
-
const unsubscribe = ngZone.runOutsideAngular(
|
|
311
|
-
() => observer.subscribe(
|
|
312
|
-
notifyManager4.batchCalls((state) => {
|
|
313
|
-
ngZone.run(() => {
|
|
314
|
-
if (state.isError && shouldThrowError2(observer.options.throwOnError, [state.error])) {
|
|
315
|
-
ngZone.onError.emit(state.error);
|
|
316
|
-
throw state.error;
|
|
317
|
-
}
|
|
318
|
-
resultFromSubscriberSignal.set(state);
|
|
319
|
-
});
|
|
320
|
-
})
|
|
321
|
-
)
|
|
322
|
-
);
|
|
323
|
-
destroyRef.onDestroy(unsubscribe);
|
|
324
|
-
});
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
injector
|
|
328
|
-
}
|
|
329
|
-
);
|
|
330
|
-
const resultSignal = computed3(() => {
|
|
331
|
-
const resultFromSubscriber = resultFromSubscriberSignal();
|
|
332
|
-
const resultFromInitialOptions = resultFromInitialOptionsSignal();
|
|
333
|
-
const result = resultFromSubscriber ?? resultFromInitialOptions;
|
|
334
|
-
return {
|
|
335
|
-
...result,
|
|
336
|
-
mutate: mutateFnSignal(),
|
|
337
|
-
mutateAsync: result.mutate
|
|
338
|
-
};
|
|
339
|
-
});
|
|
340
|
-
return signalProxy(resultSignal);
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
// src/inject-mutation-state.ts
|
|
344
|
-
import {
|
|
345
|
-
DestroyRef as DestroyRef4,
|
|
346
|
-
Injector as Injector6,
|
|
347
|
-
NgZone as NgZone5,
|
|
348
|
-
assertInInjectionContext as assertInInjectionContext6,
|
|
349
|
-
computed as computed4,
|
|
350
|
-
inject as inject7,
|
|
351
|
-
signal as signal6
|
|
352
|
-
} from "@angular/core";
|
|
353
|
-
import {
|
|
354
|
-
QueryClient as QueryClient5,
|
|
355
|
-
notifyManager as notifyManager5,
|
|
356
|
-
replaceEqualDeep
|
|
357
|
-
} from "@tanstack/query-core";
|
|
358
|
-
function getResult(mutationCache, options) {
|
|
359
|
-
return mutationCache.findAll(options.filters).map(
|
|
360
|
-
(mutation) => options.select ? options.select(mutation) : mutation.state
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
function injectMutationState(injectMutationStateFn = () => ({}), options) {
|
|
364
|
-
!options?.injector && assertInInjectionContext6(injectMutationState);
|
|
365
|
-
const injector = options?.injector ?? inject7(Injector6);
|
|
366
|
-
const destroyRef = injector.get(DestroyRef4);
|
|
367
|
-
const ngZone = injector.get(NgZone5);
|
|
368
|
-
const queryClient = injector.get(QueryClient5);
|
|
369
|
-
const mutationCache = queryClient.getMutationCache();
|
|
370
|
-
const resultFromOptionsSignal = computed4(() => {
|
|
371
|
-
return [
|
|
372
|
-
getResult(mutationCache, injectMutationStateFn()),
|
|
373
|
-
performance.now()
|
|
374
|
-
];
|
|
375
|
-
});
|
|
376
|
-
const resultFromSubscriberSignal = signal6(
|
|
377
|
-
null
|
|
378
|
-
);
|
|
379
|
-
const effectiveResultSignal = computed4(() => {
|
|
380
|
-
const optionsResult = resultFromOptionsSignal();
|
|
381
|
-
const subscriberResult = resultFromSubscriberSignal();
|
|
382
|
-
return subscriberResult && subscriberResult[1] > optionsResult[1] ? subscriberResult[0] : optionsResult[0];
|
|
383
|
-
});
|
|
384
|
-
const unsubscribe = ngZone.runOutsideAngular(
|
|
385
|
-
() => mutationCache.subscribe(
|
|
386
|
-
notifyManager5.batchCalls(() => {
|
|
387
|
-
const [lastResult] = effectiveResultSignal();
|
|
388
|
-
const nextResult = replaceEqualDeep(
|
|
389
|
-
lastResult,
|
|
390
|
-
getResult(mutationCache, injectMutationStateFn())
|
|
391
|
-
);
|
|
392
|
-
if (lastResult !== nextResult) {
|
|
393
|
-
ngZone.run(() => {
|
|
394
|
-
resultFromSubscriberSignal.set([nextResult, performance.now()]);
|
|
395
|
-
});
|
|
396
|
-
}
|
|
397
|
-
})
|
|
398
|
-
)
|
|
399
|
-
);
|
|
400
|
-
destroyRef.onDestroy(unsubscribe);
|
|
401
|
-
return effectiveResultSignal;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// src/inject-queries.ts
|
|
405
|
-
import {
|
|
406
|
-
QueriesObserver,
|
|
407
|
-
QueryClient as QueryClient6,
|
|
408
|
-
notifyManager as notifyManager6
|
|
409
|
-
} from "@tanstack/query-core";
|
|
410
|
-
import {
|
|
411
|
-
DestroyRef as DestroyRef5,
|
|
412
|
-
Injector as Injector7,
|
|
413
|
-
NgZone as NgZone6,
|
|
414
|
-
assertInInjectionContext as assertInInjectionContext7,
|
|
415
|
-
computed as computed5,
|
|
416
|
-
effect as effect3,
|
|
417
|
-
inject as inject8,
|
|
418
|
-
runInInjectionContext as runInInjectionContext2,
|
|
419
|
-
signal as signal7
|
|
420
|
-
} from "@angular/core";
|
|
421
|
-
function injectQueries({
|
|
422
|
-
queries,
|
|
423
|
-
...options
|
|
424
|
-
}, injector) {
|
|
425
|
-
!injector && assertInInjectionContext7(injectQueries);
|
|
426
|
-
return runInInjectionContext2(injector ?? inject8(Injector7), () => {
|
|
427
|
-
const destroyRef = inject8(DestroyRef5);
|
|
428
|
-
const ngZone = inject8(NgZone6);
|
|
429
|
-
const queryClient = inject8(QueryClient6);
|
|
430
|
-
const isRestoring = injectIsRestoring();
|
|
431
|
-
const defaultedQueries = computed5(() => {
|
|
432
|
-
return queries().map((opts) => {
|
|
433
|
-
const defaultedOptions = queryClient.defaultQueryOptions(opts);
|
|
434
|
-
defaultedOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
435
|
-
return defaultedOptions;
|
|
436
|
-
});
|
|
437
|
-
});
|
|
438
|
-
const observer = new QueriesObserver(
|
|
439
|
-
queryClient,
|
|
440
|
-
defaultedQueries(),
|
|
441
|
-
options
|
|
442
|
-
);
|
|
443
|
-
effect3(() => {
|
|
444
|
-
observer.setQueries(
|
|
445
|
-
defaultedQueries(),
|
|
446
|
-
options
|
|
447
|
-
);
|
|
448
|
-
});
|
|
449
|
-
const [, getCombinedResult] = observer.getOptimisticResult(
|
|
450
|
-
defaultedQueries(),
|
|
451
|
-
options.combine
|
|
452
|
-
);
|
|
453
|
-
const result = signal7(getCombinedResult());
|
|
454
|
-
effect3(() => {
|
|
455
|
-
const unsubscribe = isRestoring() ? () => void 0 : ngZone.runOutsideAngular(
|
|
456
|
-
() => observer.subscribe(notifyManager6.batchCalls(result.set))
|
|
457
|
-
);
|
|
458
|
-
destroyRef.onDestroy(unsubscribe);
|
|
459
|
-
});
|
|
460
|
-
return result;
|
|
461
|
-
});
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
// src/inject-query.ts
|
|
465
|
-
import { QueryObserver } from "@tanstack/query-core";
|
|
466
|
-
import {
|
|
467
|
-
Injector as Injector8,
|
|
468
|
-
assertInInjectionContext as assertInInjectionContext8,
|
|
469
|
-
inject as inject9,
|
|
470
|
-
runInInjectionContext as runInInjectionContext3
|
|
471
|
-
} from "@angular/core";
|
|
472
|
-
function injectQuery(injectQueryFn, options) {
|
|
473
|
-
!options?.injector && assertInInjectionContext8(injectQuery);
|
|
474
|
-
return runInInjectionContext3(
|
|
475
|
-
options?.injector ?? inject9(Injector8),
|
|
476
|
-
() => createBaseQuery(injectQueryFn, QueryObserver)
|
|
477
|
-
);
|
|
478
|
-
}
|
|
479
|
-
|
|
480
|
-
// src/inject-query-client.ts
|
|
481
|
-
import { Injector as Injector9, inject as inject10 } from "@angular/core";
|
|
482
|
-
import { QueryClient as QueryClient7 } from "@tanstack/query-core";
|
|
483
|
-
function injectQueryClient(injectOptions = {}) {
|
|
484
|
-
return (injectOptions.injector ?? inject10(Injector9)).get(QueryClient7);
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
// src/providers.ts
|
|
488
|
-
import {
|
|
489
|
-
DestroyRef as DestroyRef6,
|
|
490
|
-
ENVIRONMENT_INITIALIZER,
|
|
491
|
-
InjectionToken as InjectionToken2,
|
|
492
|
-
PLATFORM_ID,
|
|
493
|
-
computed as computed6,
|
|
494
|
-
effect as effect4,
|
|
495
|
-
inject as inject11
|
|
496
|
-
} from "@angular/core";
|
|
497
|
-
import { QueryClient as QueryClient8, noop as noop2, onlineManager } from "@tanstack/query-core";
|
|
498
|
-
import { isPlatformBrowser } from "@angular/common";
|
|
499
|
-
|
|
500
|
-
// src/util/is-dev-mode/is-dev-mode.ts
|
|
501
|
-
import { isDevMode } from "@angular/core";
|
|
502
|
-
|
|
503
|
-
// src/providers.ts
|
|
504
|
-
function provideQueryClient(queryClient) {
|
|
505
|
-
return {
|
|
506
|
-
provide: QueryClient8,
|
|
507
|
-
useFactory: () => {
|
|
508
|
-
const client = queryClient instanceof InjectionToken2 ? inject11(queryClient) : queryClient;
|
|
509
|
-
inject11(DestroyRef6).onDestroy(() => client.unmount());
|
|
510
|
-
client.mount();
|
|
511
|
-
return client;
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
function provideTanStackQuery(queryClient, ...features) {
|
|
516
|
-
return [
|
|
517
|
-
provideQueryClient(queryClient),
|
|
518
|
-
features.map((feature) => feature.\u0275providers)
|
|
519
|
-
];
|
|
520
|
-
}
|
|
521
|
-
function queryFeature(kind, providers) {
|
|
522
|
-
return { \u0275kind: kind, \u0275providers: providers };
|
|
523
|
-
}
|
|
524
|
-
function withDevtools(withDevtoolsFn) {
|
|
525
|
-
let providers = [];
|
|
526
|
-
if (!isDevMode() && !withDevtoolsFn) {
|
|
527
|
-
providers = [];
|
|
528
|
-
} else {
|
|
529
|
-
providers = [
|
|
530
|
-
{
|
|
531
|
-
// Do not use provideEnvironmentInitializer while Angular < v19 is supported
|
|
532
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
533
|
-
multi: true,
|
|
534
|
-
useFactory: () => {
|
|
535
|
-
if (!isPlatformBrowser(inject11(PLATFORM_ID))) return noop2;
|
|
536
|
-
const injectedClient = inject11(QueryClient8, {
|
|
537
|
-
optional: true
|
|
538
|
-
});
|
|
539
|
-
const destroyRef = inject11(DestroyRef6);
|
|
540
|
-
const options = computed6(() => withDevtoolsFn?.() ?? {});
|
|
541
|
-
let devtools = null;
|
|
542
|
-
let el = null;
|
|
543
|
-
const shouldLoadToolsSignal = computed6(() => {
|
|
544
|
-
const { loadDevtools } = options();
|
|
545
|
-
return typeof loadDevtools === "boolean" ? loadDevtools : isDevMode();
|
|
546
|
-
});
|
|
547
|
-
const getResolvedQueryClient = () => {
|
|
548
|
-
const client = options().client ?? injectedClient;
|
|
549
|
-
if (!client) {
|
|
550
|
-
throw new Error("No QueryClient found");
|
|
551
|
-
}
|
|
552
|
-
return client;
|
|
553
|
-
};
|
|
554
|
-
const destroyDevtools = () => {
|
|
555
|
-
devtools?.unmount();
|
|
556
|
-
el?.remove();
|
|
557
|
-
devtools = null;
|
|
558
|
-
};
|
|
559
|
-
return () => effect4(() => {
|
|
560
|
-
const shouldLoadTools = shouldLoadToolsSignal();
|
|
561
|
-
const {
|
|
562
|
-
client,
|
|
563
|
-
position,
|
|
564
|
-
errorTypes,
|
|
565
|
-
buttonPosition,
|
|
566
|
-
initialIsOpen
|
|
567
|
-
} = options();
|
|
568
|
-
if (devtools && !shouldLoadTools) {
|
|
569
|
-
destroyDevtools();
|
|
570
|
-
return;
|
|
571
|
-
} else if (devtools && shouldLoadTools) {
|
|
572
|
-
client && devtools.setClient(client);
|
|
573
|
-
position && devtools.setPosition(position);
|
|
574
|
-
errorTypes && devtools.setErrorTypes(errorTypes);
|
|
575
|
-
buttonPosition && devtools.setButtonPosition(buttonPosition);
|
|
576
|
-
initialIsOpen && devtools.setInitialIsOpen(initialIsOpen);
|
|
577
|
-
return;
|
|
578
|
-
} else if (!shouldLoadTools) {
|
|
579
|
-
return;
|
|
580
|
-
}
|
|
581
|
-
el = document.body.appendChild(document.createElement("div"));
|
|
582
|
-
el.classList.add("tsqd-parent-container");
|
|
583
|
-
import("@tanstack/query-devtools").then((queryDevtools) => {
|
|
584
|
-
devtools = new queryDevtools.TanstackQueryDevtools({
|
|
585
|
-
...options(),
|
|
586
|
-
client: getResolvedQueryClient(),
|
|
587
|
-
queryFlavor: "Angular Query",
|
|
588
|
-
version: "5",
|
|
589
|
-
onlineManager
|
|
590
|
-
});
|
|
591
|
-
el && devtools.mount(el);
|
|
592
|
-
destroyRef.onDestroy(destroyDevtools);
|
|
593
|
-
});
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
];
|
|
598
|
-
}
|
|
599
|
-
return queryFeature("DeveloperTools", providers);
|
|
600
|
-
}
|
|
601
|
-
var queryFeatures = ["DeveloperTools", "PersistQueryClient"];
|
|
602
|
-
export {
|
|
603
|
-
infiniteQueryOptions,
|
|
604
|
-
injectInfiniteQuery,
|
|
605
|
-
injectIsFetching,
|
|
606
|
-
injectIsMutating,
|
|
607
|
-
injectIsRestoring,
|
|
608
|
-
injectMutation,
|
|
609
|
-
injectMutationState,
|
|
610
|
-
injectQueries,
|
|
611
|
-
injectQuery,
|
|
612
|
-
injectQueryClient,
|
|
613
|
-
mutationOptions,
|
|
614
|
-
provideIsRestoring,
|
|
615
|
-
provideQueryClient,
|
|
616
|
-
provideTanStackQuery,
|
|
617
|
-
queryFeature,
|
|
618
|
-
queryFeatures,
|
|
619
|
-
queryOptions,
|
|
620
|
-
withDevtools
|
|
621
|
-
};
|
|
622
|
-
//# sourceMappingURL=index.mjs.map
|