@tanstack/angular-query-experimental 5.59.20 → 5.60.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 +6 -6
- package/build/index.d.ts +680 -0
- package/build/index.js +616 -0
- package/build/index.js.map +1 -0
- package/package.json +13 -14
- package/src/create-base-query.ts +119 -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 +50 -0
- package/src/inject-is-mutating.ts +49 -0
- package/src/inject-mutation-state.ts +99 -0
- package/src/inject-mutation.ts +122 -0
- package/src/inject-queries.ts +243 -0
- package/src/inject-query-client.ts +27 -0
- package/src/inject-query.ts +207 -0
- package/src/providers.ts +344 -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/create-injection-token/create-injection-token.test.ts +32 -0
- package/src/util/create-injection-token/create-injection-token.ts +183 -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 -22
- package/build/esm2022/inject-query.mjs +0 -44
- package/build/esm2022/providers.mjs +0 -56
- 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/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 -587
- package/build/fesm2022/tanstack-angular-query-experimental.mjs.map +0 -1
- package/build/rollup.d.ts +0 -605
package/build/index.js
ADDED
|
@@ -0,0 +1,616 @@
|
|
|
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 as Injector2,
|
|
21
|
+
NgZone,
|
|
22
|
+
computed as computed2,
|
|
23
|
+
effect,
|
|
24
|
+
inject as inject3,
|
|
25
|
+
runInInjectionContext as runInInjectionContext3,
|
|
26
|
+
signal,
|
|
27
|
+
untracked as untracked3
|
|
28
|
+
} from "@angular/core";
|
|
29
|
+
import { 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/util/create-injection-token/create-injection-token.ts
|
|
103
|
+
import { InjectionToken, inject as inject2, runInInjectionContext as runInInjectionContext2 } from "@angular/core";
|
|
104
|
+
|
|
105
|
+
// src/util/assert-injector/assert-injector.ts
|
|
106
|
+
import {
|
|
107
|
+
Injector,
|
|
108
|
+
assertInInjectionContext,
|
|
109
|
+
inject,
|
|
110
|
+
runInInjectionContext
|
|
111
|
+
} from "@angular/core";
|
|
112
|
+
function assertInjector(fn, injector, runner) {
|
|
113
|
+
!injector && assertInInjectionContext(fn);
|
|
114
|
+
const assertedInjector = injector ?? inject(Injector);
|
|
115
|
+
if (!runner)
|
|
116
|
+
return assertedInjector;
|
|
117
|
+
return runInInjectionContext(assertedInjector, runner);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/util/create-injection-token/create-injection-token.ts
|
|
121
|
+
function createInjectFn(token) {
|
|
122
|
+
return function({
|
|
123
|
+
injector,
|
|
124
|
+
...injectOptions
|
|
125
|
+
} = {}) {
|
|
126
|
+
injector = assertInjector(this, injector);
|
|
127
|
+
return runInInjectionContext2(
|
|
128
|
+
injector,
|
|
129
|
+
() => inject2(token, injectOptions)
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function createProvideFn(token, factory, opts = {}) {
|
|
134
|
+
const { deps = [], multi = false, extraProviders = [] } = opts;
|
|
135
|
+
return (value, isFunctionValue = false) => {
|
|
136
|
+
let provider;
|
|
137
|
+
if (value !== void 0) {
|
|
138
|
+
const factory2 = typeof value === "function" ? isFunctionValue ? () => value : value : () => value;
|
|
139
|
+
provider = {
|
|
140
|
+
provide: token,
|
|
141
|
+
useFactory: factory2,
|
|
142
|
+
multi
|
|
143
|
+
};
|
|
144
|
+
} else {
|
|
145
|
+
provider = {
|
|
146
|
+
provide: token,
|
|
147
|
+
useFactory: factory,
|
|
148
|
+
deps,
|
|
149
|
+
multi
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
return [extraProviders, provider];
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
function createNoopInjectionToken(description, options) {
|
|
156
|
+
const token = (
|
|
157
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
158
|
+
options?.token || new InjectionToken(description)
|
|
159
|
+
);
|
|
160
|
+
return [
|
|
161
|
+
createInjectFn(token),
|
|
162
|
+
createProvideFn(
|
|
163
|
+
token,
|
|
164
|
+
() => null,
|
|
165
|
+
options || {}
|
|
166
|
+
),
|
|
167
|
+
token,
|
|
168
|
+
() => {
|
|
169
|
+
}
|
|
170
|
+
];
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/inject-query-client.ts
|
|
174
|
+
var tokens = createNoopInjectionToken("QueryClientToken");
|
|
175
|
+
var injectQueryClient = tokens[0];
|
|
176
|
+
var provideQueryClient = tokens[1];
|
|
177
|
+
var QUERY_CLIENT = tokens[2];
|
|
178
|
+
|
|
179
|
+
// src/create-base-query.ts
|
|
180
|
+
function createBaseQuery(optionsFn, Observer) {
|
|
181
|
+
const injector = inject3(Injector2);
|
|
182
|
+
return lazyInit(() => {
|
|
183
|
+
const ngZone = injector.get(NgZone);
|
|
184
|
+
const destroyRef = injector.get(DestroyRef);
|
|
185
|
+
const queryClient = injectQueryClient({ injector });
|
|
186
|
+
const defaultedOptionsSignal = computed2(() => {
|
|
187
|
+
const options = runInInjectionContext3(
|
|
188
|
+
injector,
|
|
189
|
+
() => optionsFn(queryClient)
|
|
190
|
+
);
|
|
191
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
192
|
+
defaultedOptions._optimisticResults = "optimistic";
|
|
193
|
+
return defaultedOptions;
|
|
194
|
+
});
|
|
195
|
+
const observer = new Observer(queryClient, defaultedOptionsSignal());
|
|
196
|
+
const resultSignal = signal(
|
|
197
|
+
observer.getOptimisticResult(defaultedOptionsSignal())
|
|
198
|
+
);
|
|
199
|
+
effect(
|
|
200
|
+
() => {
|
|
201
|
+
const defaultedOptions = defaultedOptionsSignal();
|
|
202
|
+
observer.setOptions(defaultedOptions, {
|
|
203
|
+
// Do not notify on updates because of changes in the options because
|
|
204
|
+
// these changes should already be reflected in the optimistic result.
|
|
205
|
+
listeners: false
|
|
206
|
+
});
|
|
207
|
+
untracked3(() => {
|
|
208
|
+
resultSignal.set(observer.getOptimisticResult(defaultedOptions));
|
|
209
|
+
});
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
injector
|
|
213
|
+
}
|
|
214
|
+
);
|
|
215
|
+
const unsubscribe = observer.subscribe(
|
|
216
|
+
notifyManager.batchCalls((state) => {
|
|
217
|
+
ngZone.run(() => {
|
|
218
|
+
if (state.isError && !state.isFetching && // !isRestoring() && // todo: enable when client persistence is implemented
|
|
219
|
+
shouldThrowError(observer.options.throwOnError, [
|
|
220
|
+
state.error,
|
|
221
|
+
observer.getCurrentQuery()
|
|
222
|
+
])) {
|
|
223
|
+
throw state.error;
|
|
224
|
+
}
|
|
225
|
+
resultSignal.set(state);
|
|
226
|
+
});
|
|
227
|
+
})
|
|
228
|
+
);
|
|
229
|
+
destroyRef.onDestroy(unsubscribe);
|
|
230
|
+
return signalProxy(resultSignal);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
// src/inject-infinite-query.ts
|
|
235
|
+
function injectInfiniteQuery(optionsFn, injector) {
|
|
236
|
+
return assertInjector(
|
|
237
|
+
injectInfiniteQuery,
|
|
238
|
+
injector,
|
|
239
|
+
() => createBaseQuery(optionsFn, InfiniteQueryObserver)
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// src/inject-is-fetching.ts
|
|
244
|
+
import { DestroyRef as DestroyRef2, NgZone as NgZone2, inject as inject4, signal as signal2 } from "@angular/core";
|
|
245
|
+
import { notifyManager as notifyManager2 } from "@tanstack/query-core";
|
|
246
|
+
function injectIsFetching(filters, injector) {
|
|
247
|
+
return assertInjector(injectIsFetching, injector, () => {
|
|
248
|
+
const queryClient = injectQueryClient();
|
|
249
|
+
const destroyRef = inject4(DestroyRef2);
|
|
250
|
+
const ngZone = inject4(NgZone2);
|
|
251
|
+
const cache = queryClient.getQueryCache();
|
|
252
|
+
let isFetching = queryClient.isFetching(filters);
|
|
253
|
+
const result = signal2(isFetching);
|
|
254
|
+
const unsubscribe = cache.subscribe(
|
|
255
|
+
notifyManager2.batchCalls(() => {
|
|
256
|
+
const newIsFetching = queryClient.isFetching(filters);
|
|
257
|
+
if (isFetching !== newIsFetching) {
|
|
258
|
+
isFetching = newIsFetching;
|
|
259
|
+
ngZone.run(() => {
|
|
260
|
+
result.set(isFetching);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
})
|
|
264
|
+
);
|
|
265
|
+
destroyRef.onDestroy(unsubscribe);
|
|
266
|
+
return result;
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/inject-is-mutating.ts
|
|
271
|
+
import { DestroyRef as DestroyRef3, NgZone as NgZone3, inject as inject5, signal as signal3 } from "@angular/core";
|
|
272
|
+
import { notifyManager as notifyManager3 } from "@tanstack/query-core";
|
|
273
|
+
function injectIsMutating(filters, injector) {
|
|
274
|
+
return assertInjector(injectIsMutating, injector, () => {
|
|
275
|
+
const queryClient = injectQueryClient();
|
|
276
|
+
const destroyRef = inject5(DestroyRef3);
|
|
277
|
+
const ngZone = inject5(NgZone3);
|
|
278
|
+
const cache = queryClient.getMutationCache();
|
|
279
|
+
let isMutating = queryClient.isMutating(filters);
|
|
280
|
+
const result = signal3(isMutating);
|
|
281
|
+
const unsubscribe = cache.subscribe(
|
|
282
|
+
notifyManager3.batchCalls(() => {
|
|
283
|
+
const newIsMutating = queryClient.isMutating(filters);
|
|
284
|
+
if (isMutating !== newIsMutating) {
|
|
285
|
+
isMutating = newIsMutating;
|
|
286
|
+
ngZone.run(() => {
|
|
287
|
+
result.set(isMutating);
|
|
288
|
+
});
|
|
289
|
+
}
|
|
290
|
+
})
|
|
291
|
+
);
|
|
292
|
+
destroyRef.onDestroy(unsubscribe);
|
|
293
|
+
return result;
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// src/inject-mutation.ts
|
|
298
|
+
import {
|
|
299
|
+
DestroyRef as DestroyRef4,
|
|
300
|
+
Injector as Injector3,
|
|
301
|
+
NgZone as NgZone4,
|
|
302
|
+
computed as computed3,
|
|
303
|
+
effect as effect2,
|
|
304
|
+
inject as inject6,
|
|
305
|
+
runInInjectionContext as runInInjectionContext4,
|
|
306
|
+
signal as signal4
|
|
307
|
+
} from "@angular/core";
|
|
308
|
+
import { MutationObserver, notifyManager as notifyManager4 } from "@tanstack/query-core";
|
|
309
|
+
function injectMutation(optionsFn, injector) {
|
|
310
|
+
return assertInjector(injectMutation, injector, () => {
|
|
311
|
+
const queryClient = injectQueryClient();
|
|
312
|
+
const currentInjector = inject6(Injector3);
|
|
313
|
+
const destroyRef = inject6(DestroyRef4);
|
|
314
|
+
const ngZone = inject6(NgZone4);
|
|
315
|
+
return lazyInit(
|
|
316
|
+
() => runInInjectionContext4(currentInjector, () => {
|
|
317
|
+
const observer = new MutationObserver(queryClient, optionsFn(queryClient));
|
|
318
|
+
const mutate = (variables, mutateOptions) => {
|
|
319
|
+
observer.mutate(variables, mutateOptions).catch(noop);
|
|
320
|
+
};
|
|
321
|
+
effect2(() => {
|
|
322
|
+
observer.setOptions(
|
|
323
|
+
runInInjectionContext4(
|
|
324
|
+
currentInjector,
|
|
325
|
+
() => optionsFn(queryClient)
|
|
326
|
+
)
|
|
327
|
+
);
|
|
328
|
+
});
|
|
329
|
+
const result = signal4(observer.getCurrentResult());
|
|
330
|
+
const unsubscribe = observer.subscribe(
|
|
331
|
+
notifyManager4.batchCalls(
|
|
332
|
+
(state) => {
|
|
333
|
+
ngZone.run(() => {
|
|
334
|
+
if (state.isError && shouldThrowError(observer.options.throwOnError, [state.error])) {
|
|
335
|
+
throw state.error;
|
|
336
|
+
}
|
|
337
|
+
result.set(state);
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
)
|
|
341
|
+
);
|
|
342
|
+
destroyRef.onDestroy(unsubscribe);
|
|
343
|
+
const resultSignal = computed3(() => ({
|
|
344
|
+
...result(),
|
|
345
|
+
mutate,
|
|
346
|
+
mutateAsync: result().mutate
|
|
347
|
+
}));
|
|
348
|
+
return signalProxy(resultSignal);
|
|
349
|
+
})
|
|
350
|
+
);
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
// src/inject-mutation-state.ts
|
|
355
|
+
import {
|
|
356
|
+
DestroyRef as DestroyRef5,
|
|
357
|
+
NgZone as NgZone5,
|
|
358
|
+
effect as effect3,
|
|
359
|
+
inject as inject8,
|
|
360
|
+
signal as signal5,
|
|
361
|
+
untracked as untracked5
|
|
362
|
+
} from "@angular/core";
|
|
363
|
+
import { notifyManager as notifyManager5, replaceEqualDeep } from "@tanstack/query-core";
|
|
364
|
+
|
|
365
|
+
// src/util/lazy-signal-initializer/lazy-signal-initializer.ts
|
|
366
|
+
import { Injector as Injector4, computed as computed4, inject as inject7, untracked as untracked4 } from "@angular/core";
|
|
367
|
+
function lazySignalInitializer(initializerFn) {
|
|
368
|
+
const injector = inject7(Injector4);
|
|
369
|
+
let source = null;
|
|
370
|
+
const unwrapSignal = () => {
|
|
371
|
+
if (!source) {
|
|
372
|
+
source = untracked4(() => initializerFn(injector));
|
|
373
|
+
}
|
|
374
|
+
return source();
|
|
375
|
+
};
|
|
376
|
+
queueMicrotask(() => unwrapSignal());
|
|
377
|
+
return computed4(unwrapSignal);
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
// src/inject-mutation-state.ts
|
|
381
|
+
function getResult(mutationCache, options) {
|
|
382
|
+
return mutationCache.findAll(options.filters).map(
|
|
383
|
+
(mutation) => options.select ? options.select(mutation) : mutation.state
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
function injectMutationState(mutationStateOptionsFn = () => ({}), options) {
|
|
387
|
+
return assertInjector(injectMutationState, options?.injector, () => {
|
|
388
|
+
const destroyRef = inject8(DestroyRef5);
|
|
389
|
+
const queryClient = injectQueryClient();
|
|
390
|
+
const ngZone = inject8(NgZone5);
|
|
391
|
+
const mutationCache = queryClient.getMutationCache();
|
|
392
|
+
return lazySignalInitializer((injector) => {
|
|
393
|
+
const result = signal5(
|
|
394
|
+
getResult(mutationCache, mutationStateOptionsFn())
|
|
395
|
+
);
|
|
396
|
+
effect3(
|
|
397
|
+
() => {
|
|
398
|
+
const mutationStateOptions = mutationStateOptionsFn();
|
|
399
|
+
untracked5(() => {
|
|
400
|
+
result.set(getResult(mutationCache, mutationStateOptions));
|
|
401
|
+
});
|
|
402
|
+
},
|
|
403
|
+
{ injector }
|
|
404
|
+
);
|
|
405
|
+
const unsubscribe = mutationCache.subscribe(
|
|
406
|
+
notifyManager5.batchCalls(() => {
|
|
407
|
+
const nextResult = replaceEqualDeep(
|
|
408
|
+
result(),
|
|
409
|
+
getResult(mutationCache, mutationStateOptionsFn())
|
|
410
|
+
);
|
|
411
|
+
if (result() !== nextResult) {
|
|
412
|
+
ngZone.run(() => {
|
|
413
|
+
result.set(nextResult);
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
})
|
|
417
|
+
);
|
|
418
|
+
destroyRef.onDestroy(unsubscribe);
|
|
419
|
+
return result;
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
// src/inject-queries.ts
|
|
425
|
+
import { QueriesObserver, notifyManager as notifyManager6 } from "@tanstack/query-core";
|
|
426
|
+
import { DestroyRef as DestroyRef6, computed as computed5, effect as effect4, inject as inject9, signal as signal6 } from "@angular/core";
|
|
427
|
+
function injectQueries({
|
|
428
|
+
queries,
|
|
429
|
+
...options
|
|
430
|
+
}, injector) {
|
|
431
|
+
return assertInjector(injectQueries, injector, () => {
|
|
432
|
+
const queryClient = injectQueryClient();
|
|
433
|
+
const destroyRef = inject9(DestroyRef6);
|
|
434
|
+
const defaultedQueries = computed5(() => {
|
|
435
|
+
return queries().map((opts) => {
|
|
436
|
+
const defaultedOptions = queryClient.defaultQueryOptions(opts);
|
|
437
|
+
defaultedOptions._optimisticResults = "optimistic";
|
|
438
|
+
return defaultedOptions;
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
const observer = new QueriesObserver(
|
|
442
|
+
queryClient,
|
|
443
|
+
defaultedQueries(),
|
|
444
|
+
options
|
|
445
|
+
);
|
|
446
|
+
effect4(() => {
|
|
447
|
+
observer.setQueries(
|
|
448
|
+
defaultedQueries(),
|
|
449
|
+
options,
|
|
450
|
+
{ listeners: false }
|
|
451
|
+
);
|
|
452
|
+
});
|
|
453
|
+
const [, getCombinedResult] = observer.getOptimisticResult(
|
|
454
|
+
defaultedQueries(),
|
|
455
|
+
options.combine
|
|
456
|
+
);
|
|
457
|
+
const result = signal6(getCombinedResult());
|
|
458
|
+
const unsubscribe = observer.subscribe(notifyManager6.batchCalls(result.set));
|
|
459
|
+
destroyRef.onDestroy(unsubscribe);
|
|
460
|
+
return result;
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
// src/inject-query.ts
|
|
465
|
+
import { QueryObserver } from "@tanstack/query-core";
|
|
466
|
+
function injectQuery(optionsFn, injector) {
|
|
467
|
+
return assertInjector(
|
|
468
|
+
injectQuery,
|
|
469
|
+
injector,
|
|
470
|
+
() => createBaseQuery(optionsFn, QueryObserver)
|
|
471
|
+
);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// src/providers.ts
|
|
475
|
+
import {
|
|
476
|
+
DestroyRef as DestroyRef7,
|
|
477
|
+
ENVIRONMENT_INITIALIZER,
|
|
478
|
+
Injector as Injector5,
|
|
479
|
+
PLATFORM_ID,
|
|
480
|
+
computed as computed6,
|
|
481
|
+
effect as effect5,
|
|
482
|
+
inject as inject10,
|
|
483
|
+
makeEnvironmentProviders,
|
|
484
|
+
runInInjectionContext as runInInjectionContext5
|
|
485
|
+
} from "@angular/core";
|
|
486
|
+
import { onlineManager } from "@tanstack/query-core";
|
|
487
|
+
import { isPlatformBrowser } from "@angular/common";
|
|
488
|
+
|
|
489
|
+
// src/util/is-dev-mode/is-dev-mode.ts
|
|
490
|
+
import { isDevMode } from "@angular/core";
|
|
491
|
+
|
|
492
|
+
// src/providers.ts
|
|
493
|
+
function provideTanStackQuery(queryClient, ...features) {
|
|
494
|
+
return makeEnvironmentProviders([
|
|
495
|
+
provideQueryClient(queryClient),
|
|
496
|
+
{
|
|
497
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
498
|
+
multi: true,
|
|
499
|
+
useValue: () => {
|
|
500
|
+
queryClient.mount();
|
|
501
|
+
inject10(DestroyRef7).onDestroy(() => queryClient.unmount());
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
features.map((feature) => feature.\u0275providers)
|
|
505
|
+
]);
|
|
506
|
+
}
|
|
507
|
+
function provideAngularQuery(queryClient) {
|
|
508
|
+
return provideTanStackQuery(queryClient);
|
|
509
|
+
}
|
|
510
|
+
function queryFeature(kind, providers) {
|
|
511
|
+
return { \u0275kind: kind, \u0275providers: providers };
|
|
512
|
+
}
|
|
513
|
+
function withDevtools(optionsFn) {
|
|
514
|
+
let providers = [];
|
|
515
|
+
if (!isDevMode() && !optionsFn) {
|
|
516
|
+
providers = [];
|
|
517
|
+
} else {
|
|
518
|
+
providers = [
|
|
519
|
+
{
|
|
520
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
521
|
+
multi: true,
|
|
522
|
+
useFactory: () => {
|
|
523
|
+
if (!isPlatformBrowser(inject10(PLATFORM_ID)))
|
|
524
|
+
return () => {
|
|
525
|
+
};
|
|
526
|
+
const injector = inject10(Injector5);
|
|
527
|
+
const options = computed6(
|
|
528
|
+
() => runInInjectionContext5(injector, () => optionsFn?.() ?? {})
|
|
529
|
+
);
|
|
530
|
+
let devtools = null;
|
|
531
|
+
let el = null;
|
|
532
|
+
const shouldLoadToolsSignal = computed6(() => {
|
|
533
|
+
const { loadDevtools } = options();
|
|
534
|
+
return typeof loadDevtools === "boolean" ? loadDevtools : isDevMode();
|
|
535
|
+
});
|
|
536
|
+
const destroyRef = inject10(DestroyRef7);
|
|
537
|
+
const getResolvedQueryClient = () => {
|
|
538
|
+
const injectedClient = injectQueryClient({
|
|
539
|
+
optional: true,
|
|
540
|
+
injector
|
|
541
|
+
});
|
|
542
|
+
const client = options().client ?? injectedClient;
|
|
543
|
+
if (!client) {
|
|
544
|
+
throw new Error("No QueryClient found");
|
|
545
|
+
}
|
|
546
|
+
return client;
|
|
547
|
+
};
|
|
548
|
+
const destroyDevtools = () => {
|
|
549
|
+
devtools?.unmount();
|
|
550
|
+
el?.remove();
|
|
551
|
+
devtools = null;
|
|
552
|
+
};
|
|
553
|
+
return () => effect5(() => {
|
|
554
|
+
const shouldLoadTools = shouldLoadToolsSignal();
|
|
555
|
+
const {
|
|
556
|
+
client,
|
|
557
|
+
position,
|
|
558
|
+
errorTypes,
|
|
559
|
+
buttonPosition,
|
|
560
|
+
initialIsOpen
|
|
561
|
+
} = options();
|
|
562
|
+
if (devtools && !shouldLoadTools) {
|
|
563
|
+
destroyDevtools();
|
|
564
|
+
return;
|
|
565
|
+
} else if (devtools && shouldLoadTools) {
|
|
566
|
+
client && devtools.setClient(client);
|
|
567
|
+
position && devtools.setPosition(position);
|
|
568
|
+
errorTypes && devtools.setErrorTypes(errorTypes);
|
|
569
|
+
buttonPosition && devtools.setButtonPosition(buttonPosition);
|
|
570
|
+
initialIsOpen && devtools.setInitialIsOpen(initialIsOpen);
|
|
571
|
+
return;
|
|
572
|
+
} else if (!shouldLoadTools) {
|
|
573
|
+
return;
|
|
574
|
+
}
|
|
575
|
+
el = document.body.appendChild(document.createElement("div"));
|
|
576
|
+
el.classList.add("tsqd-parent-container");
|
|
577
|
+
import("@tanstack/query-devtools").then(
|
|
578
|
+
(queryDevtools) => runInInjectionContext5(injector, () => {
|
|
579
|
+
devtools = new queryDevtools.TanstackQueryDevtools({
|
|
580
|
+
...options(),
|
|
581
|
+
client: getResolvedQueryClient(),
|
|
582
|
+
queryFlavor: "Angular Query",
|
|
583
|
+
version: "5",
|
|
584
|
+
onlineManager
|
|
585
|
+
});
|
|
586
|
+
el && devtools.mount(el);
|
|
587
|
+
destroyRef.onDestroy(destroyDevtools);
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
});
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
];
|
|
594
|
+
}
|
|
595
|
+
return queryFeature("DeveloperTools", providers);
|
|
596
|
+
}
|
|
597
|
+
var queryFeatures = ["DeveloperTools"];
|
|
598
|
+
export {
|
|
599
|
+
QUERY_CLIENT,
|
|
600
|
+
infiniteQueryOptions,
|
|
601
|
+
injectInfiniteQuery,
|
|
602
|
+
injectIsFetching,
|
|
603
|
+
injectIsMutating,
|
|
604
|
+
injectMutation,
|
|
605
|
+
injectMutationState,
|
|
606
|
+
injectQueries,
|
|
607
|
+
injectQuery,
|
|
608
|
+
injectQueryClient,
|
|
609
|
+
provideAngularQuery,
|
|
610
|
+
provideQueryClient,
|
|
611
|
+
provideTanStackQuery,
|
|
612
|
+
queryFeatures,
|
|
613
|
+
queryOptions,
|
|
614
|
+
withDevtools
|
|
615
|
+
};
|
|
616
|
+
//# sourceMappingURL=index.js.map
|