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