@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
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { QueryKey, QueryObserver, QueryObserverResult } from '@tanstack/query-core';
|
|
2
|
+
import { CreateBaseQueryOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Base implementation for `injectQuery` and `injectInfiniteQuery`.
|
|
5
|
+
* @param optionsFn
|
|
6
|
+
* @param Observer
|
|
7
|
+
*/
|
|
8
|
+
export declare function createBaseQuery<TQueryFnData, TError, TData, TQueryData, TQueryKey extends QueryKey>(optionsFn: () => CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, Observer: typeof QueryObserver): import('./signal-proxy.js').MapToSignals<QueryObserverResult<TData, TError>>;
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { inject, NgZone, computed, signal, effect, untracked, VERSION } from "@angular/core";
|
|
2
|
+
import { QueryClient, notifyManager, shouldThrowError } from "@tanstack/query-core";
|
|
3
|
+
import { signalProxy } from "./signal-proxy.mjs";
|
|
4
|
+
import { injectIsRestoring } from "./inject-is-restoring.mjs";
|
|
5
|
+
function createBaseQuery(optionsFn, Observer) {
|
|
6
|
+
const ngZone = inject(NgZone);
|
|
7
|
+
const queryClient = inject(QueryClient);
|
|
8
|
+
const isRestoring = injectIsRestoring();
|
|
9
|
+
const defaultedOptionsSignal = computed(() => {
|
|
10
|
+
const defaultedOptions = queryClient.defaultQueryOptions(optionsFn());
|
|
11
|
+
defaultedOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
12
|
+
return defaultedOptions;
|
|
13
|
+
});
|
|
14
|
+
const observerSignal = (() => {
|
|
15
|
+
let instance = null;
|
|
16
|
+
return computed(() => {
|
|
17
|
+
return instance || (instance = new Observer(queryClient, defaultedOptionsSignal()));
|
|
18
|
+
});
|
|
19
|
+
})();
|
|
20
|
+
const optimisticResultSignal = computed(
|
|
21
|
+
() => observerSignal().getOptimisticResult(defaultedOptionsSignal())
|
|
22
|
+
);
|
|
23
|
+
const resultFromSubscriberSignal = signal(null);
|
|
24
|
+
effect(
|
|
25
|
+
(onCleanup) => {
|
|
26
|
+
const observer = observerSignal();
|
|
27
|
+
const defaultedOptions = defaultedOptionsSignal();
|
|
28
|
+
untracked(() => {
|
|
29
|
+
observer.setOptions(defaultedOptions);
|
|
30
|
+
});
|
|
31
|
+
onCleanup(() => {
|
|
32
|
+
ngZone.run(() => resultFromSubscriberSignal.set(null));
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
// Set allowSignalWrites to support Angular < v19
|
|
37
|
+
// Set to undefined to avoid warning on newer versions
|
|
38
|
+
allowSignalWrites: VERSION.major < "19" || void 0
|
|
39
|
+
}
|
|
40
|
+
);
|
|
41
|
+
effect((onCleanup) => {
|
|
42
|
+
const observer = observerSignal();
|
|
43
|
+
const unsubscribe = isRestoring() ? () => void 0 : untracked(
|
|
44
|
+
() => ngZone.runOutsideAngular(
|
|
45
|
+
() => observer.subscribe(
|
|
46
|
+
notifyManager.batchCalls((state) => {
|
|
47
|
+
ngZone.run(() => {
|
|
48
|
+
if (state.isError && !state.isFetching && shouldThrowError(observer.options.throwOnError, [
|
|
49
|
+
state.error,
|
|
50
|
+
observer.getCurrentQuery()
|
|
51
|
+
])) {
|
|
52
|
+
ngZone.onError.emit(state.error);
|
|
53
|
+
throw state.error;
|
|
54
|
+
}
|
|
55
|
+
resultFromSubscriberSignal.set(state);
|
|
56
|
+
});
|
|
57
|
+
})
|
|
58
|
+
)
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
onCleanup(unsubscribe);
|
|
62
|
+
});
|
|
63
|
+
return signalProxy(
|
|
64
|
+
computed(() => {
|
|
65
|
+
const subscriberResult = resultFromSubscriberSignal();
|
|
66
|
+
const optimisticResult = optimisticResultSignal();
|
|
67
|
+
return subscriberResult ?? optimisticResult;
|
|
68
|
+
})
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
export {
|
|
72
|
+
createBaseQuery
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=create-base-query.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-base-query.mjs","sources":["../src/create-base-query.ts"],"sourcesContent":["import {\n NgZone,\n VERSION,\n computed,\n effect,\n inject,\n signal,\n untracked,\n} from '@angular/core'\nimport {\n QueryClient,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { signalProxy } from './signal-proxy'\nimport { injectIsRestoring } from './inject-is-restoring'\nimport type {\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { CreateBaseQueryOptions } from './types'\n\n/**\n * Base implementation for `injectQuery` and `injectInfiniteQuery`.\n * @param optionsFn\n * @param Observer\n */\nexport function createBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n optionsFn: () => CreateBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n) {\n const ngZone = inject(NgZone)\n const queryClient = inject(QueryClient)\n const isRestoring = injectIsRestoring()\n\n /**\n * Signal that has the default options from query client applied\n * computed() is used so signals can be inserted into the options\n * making it reactive. Wrapping options in a function ensures embedded expressions\n * are preserved and can keep being applied after signal changes\n */\n const defaultedOptionsSignal = computed(() => {\n const defaultedOptions = queryClient.defaultQueryOptions(optionsFn())\n defaultedOptions._optimisticResults = isRestoring()\n ? 'isRestoring'\n : 'optimistic'\n return defaultedOptions\n })\n\n const observerSignal = (() => {\n let instance: QueryObserver<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > | null = null\n\n return computed(() => {\n return (instance ||= new Observer(queryClient, defaultedOptionsSignal()))\n })\n })()\n\n const optimisticResultSignal = computed(() =>\n observerSignal().getOptimisticResult(defaultedOptionsSignal()),\n )\n\n const resultFromSubscriberSignal = signal<QueryObserverResult<\n TData,\n TError\n > | null>(null)\n\n effect(\n (onCleanup) => {\n const observer = observerSignal()\n const defaultedOptions = defaultedOptionsSignal()\n\n untracked(() => {\n observer.setOptions(defaultedOptions)\n })\n onCleanup(() => {\n ngZone.run(() => resultFromSubscriberSignal.set(null))\n })\n },\n {\n // Set allowSignalWrites to support Angular < v19\n // Set to undefined to avoid warning on newer versions\n allowSignalWrites: VERSION.major < '19' || undefined,\n },\n )\n\n effect((onCleanup) => {\n // observer.trackResult is not used as this optimization is not needed for Angular\n const observer = observerSignal()\n const unsubscribe = isRestoring()\n ? () => undefined\n : untracked(() =>\n ngZone.runOutsideAngular(() =>\n observer.subscribe(\n notifyManager.batchCalls((state) => {\n ngZone.run(() => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(observer.options.throwOnError, [\n state.error,\n observer.getCurrentQuery(),\n ])\n ) {\n ngZone.onError.emit(state.error)\n throw state.error\n }\n resultFromSubscriberSignal.set(state)\n })\n }),\n ),\n ),\n )\n onCleanup(unsubscribe)\n })\n\n return signalProxy(\n computed(() => {\n const subscriberResult = resultFromSubscriberSignal()\n const optimisticResult = optimisticResultSignal()\n return subscriberResult ?? optimisticResult\n }),\n )\n}\n"],"names":[],"mappings":";;;;AA4BgB,SAAA,gBAOd,WAOA,UACA;AACM,QAAA,SAAS,OAAO,MAAM;AACtB,QAAA,cAAc,OAAO,WAAW;AACtC,QAAM,cAAc,kBAAkB;AAQhC,QAAA,yBAAyB,SAAS,MAAM;AAC5C,UAAM,mBAAmB,YAAY,oBAAoB,UAAA,CAAW;AACnD,qBAAA,qBAAqB,YAAY,IAC9C,gBACA;AACG,WAAA;AAAA,EAAA,CACR;AAED,QAAM,kBAAkB,MAAM;AAC5B,QAAI,WAMO;AAEX,WAAO,SAAS,MAAM;AACpB,aAAQ,wBAAa,IAAI,SAAS,aAAa,wBAAwB;AAAA,IAAA,CACxE;AAAA,EAAA,GACA;AAEH,QAAM,yBAAyB;AAAA,IAAS,MACtC,eAAA,EAAiB,oBAAoB,uBAAwB,CAAA;AAAA,EAC/D;AAEM,QAAA,6BAA6B,OAGzB,IAAI;AAEd;AAAA,IACE,CAAC,cAAc;AACb,YAAM,WAAW,eAAe;AAChC,YAAM,mBAAmB,uBAAuB;AAEhD,gBAAU,MAAM;AACd,iBAAS,WAAW,gBAAgB;AAAA,MAAA,CACrC;AACD,gBAAU,MAAM;AACd,eAAO,IAAI,MAAM,2BAA2B,IAAI,IAAI,CAAC;AAAA,MAAA,CACtD;AAAA,IACH;AAAA,IACA;AAAA;AAAA;AAAA,MAGE,mBAAmB,QAAQ,QAAQ,QAAQ;AAAA,IAAA;AAAA,EAE/C;AAEA,SAAO,CAAC,cAAc;AAEpB,UAAM,WAAW,eAAe;AAChC,UAAM,cAAc,gBAChB,MAAM,SACN;AAAA,MAAU,MACR,OAAO;AAAA,QAAkB,MACvB,SAAS;AAAA,UACP,cAAc,WAAW,CAAC,UAAU;AAClC,mBAAO,IAAI,MAAM;AAEb,kBAAA,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,SAAS,QAAQ,cAAc;AAAA,gBAC9C,MAAM;AAAA,gBACN,SAAS,gBAAgB;AAAA,cAAA,CAC1B,GACD;AACO,uBAAA,QAAQ,KAAK,MAAM,KAAK;AAC/B,sBAAM,MAAM;AAAA,cAAA;AAEd,yCAA2B,IAAI,KAAK;AAAA,YAAA,CACrC;AAAA,UACF,CAAA;AAAA,QAAA;AAAA,MACH;AAAA,IAEJ;AACJ,cAAU,WAAW;AAAA,EAAA,CACtB;AAEM,SAAA;AAAA,IACL,SAAS,MAAM;AACb,YAAM,mBAAmB,2BAA2B;AACpD,YAAM,mBAAmB,uBAAuB;AAChD,aAAO,oBAAoB;AAAA,IAC5B,CAAA;AAAA,EACH;AACF;"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export * from '@tanstack/query-core';
|
|
2
|
+
export * from './types.js';
|
|
3
|
+
export type { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, } from './query-options.js';
|
|
4
|
+
export { queryOptions } from './query-options.js';
|
|
5
|
+
export type { CreateMutationOptions } from './mutation-options.js';
|
|
6
|
+
export { mutationOptions } from './mutation-options.js';
|
|
7
|
+
export type { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, UnusedSkipTokenInfiniteOptions, } from './infinite-query-options.js';
|
|
8
|
+
export { infiniteQueryOptions } from './infinite-query-options.js';
|
|
9
|
+
export type { InjectInfiniteQueryOptions } from './inject-infinite-query.js';
|
|
10
|
+
export { injectInfiniteQuery } from './inject-infinite-query.js';
|
|
11
|
+
export type { InjectIsFetchingOptions } from './inject-is-fetching.js';
|
|
12
|
+
export { injectIsFetching } from './inject-is-fetching.js';
|
|
13
|
+
export type { InjectIsMutatingOptions } from './inject-is-mutating.js';
|
|
14
|
+
export { injectIsMutating } from './inject-is-mutating.js';
|
|
15
|
+
export { injectIsRestoring, provideIsRestoring } from './inject-is-restoring.js';
|
|
16
|
+
export type { InjectMutationOptions } from './inject-mutation.js';
|
|
17
|
+
export { injectMutation } from './inject-mutation.js';
|
|
18
|
+
export type { InjectMutationStateOptions } from './inject-mutation-state.js';
|
|
19
|
+
export { injectMutationState } from './inject-mutation-state.js';
|
|
20
|
+
export type { QueriesOptions, QueriesResults } from './inject-queries.js';
|
|
21
|
+
export { injectQueries } from './inject-queries.js';
|
|
22
|
+
export type { InjectQueryOptions } from './inject-query.js';
|
|
23
|
+
export { injectQuery } from './inject-query.js';
|
|
24
|
+
export { injectQueryClient } from './inject-query-client.js';
|
|
25
|
+
export type { DeveloperToolsFeature, DevtoolsOptions, PersistQueryClientFeature, QueryFeature, QueryFeatureKind, QueryFeatures, } from './providers.js';
|
|
26
|
+
export { provideQueryClient, provideTanStackQuery, queryFeature, queryFeatures, withDevtools, } from './providers.js';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export * from "@tanstack/query-core";
|
|
2
|
+
import { queryOptions } from "./query-options.mjs";
|
|
3
|
+
import { mutationOptions } from "./mutation-options.mjs";
|
|
4
|
+
import { infiniteQueryOptions } from "./infinite-query-options.mjs";
|
|
5
|
+
import { injectInfiniteQuery } from "./inject-infinite-query.mjs";
|
|
6
|
+
import { injectIsFetching } from "./inject-is-fetching.mjs";
|
|
7
|
+
import { injectIsMutating } from "./inject-is-mutating.mjs";
|
|
8
|
+
import { injectIsRestoring, provideIsRestoring } from "./inject-is-restoring.mjs";
|
|
9
|
+
import { injectMutation } from "./inject-mutation.mjs";
|
|
10
|
+
import { injectMutationState } from "./inject-mutation-state.mjs";
|
|
11
|
+
import { injectQueries } from "./inject-queries.mjs";
|
|
12
|
+
import { injectQuery } from "./inject-query.mjs";
|
|
13
|
+
import { injectQueryClient } from "./inject-query-client.mjs";
|
|
14
|
+
import { provideQueryClient, provideTanStackQuery, queryFeature, queryFeatures, withDevtools } from "./providers.mjs";
|
|
15
|
+
export {
|
|
16
|
+
infiniteQueryOptions,
|
|
17
|
+
injectInfiniteQuery,
|
|
18
|
+
injectIsFetching,
|
|
19
|
+
injectIsMutating,
|
|
20
|
+
injectIsRestoring,
|
|
21
|
+
injectMutation,
|
|
22
|
+
injectMutationState,
|
|
23
|
+
injectQueries,
|
|
24
|
+
injectQuery,
|
|
25
|
+
injectQueryClient,
|
|
26
|
+
mutationOptions,
|
|
27
|
+
provideIsRestoring,
|
|
28
|
+
provideQueryClient,
|
|
29
|
+
provideTanStackQuery,
|
|
30
|
+
queryFeature,
|
|
31
|
+
queryFeatures,
|
|
32
|
+
queryOptions,
|
|
33
|
+
withDevtools
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { DataTag, DefaultError, InfiniteData, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryKey, SkipToken } from '@tanstack/query-core';
|
|
2
|
+
import { CreateInfiniteQueryOptions } from './types.js';
|
|
3
|
+
export type UndefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
4
|
+
initialData?: undefined | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | InitialDataFunction<NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>>;
|
|
5
|
+
};
|
|
6
|
+
export type UnusedSkipTokenInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = OmitKeyof<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'queryFn'> & {
|
|
7
|
+
queryFn?: Exclude<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>['queryFn'], SkipToken | undefined>;
|
|
8
|
+
};
|
|
9
|
+
export type DefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
10
|
+
initialData: NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>) | undefined;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Allows to share and re-use infinite query options in a type-safe way.
|
|
14
|
+
*
|
|
15
|
+
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
16
|
+
* @param options - The infinite query options to tag with the type from `queryFn`.
|
|
17
|
+
* @returns The tagged infinite query options.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
21
|
+
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Allows to share and re-use infinite query options in a type-safe way.
|
|
25
|
+
*
|
|
26
|
+
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
27
|
+
* @param options - The infinite query options to tag with the type from `queryFn`.
|
|
28
|
+
* @returns The tagged infinite query options.
|
|
29
|
+
* @public
|
|
30
|
+
*/
|
|
31
|
+
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
32
|
+
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Allows to share and re-use infinite query options in a type-safe way.
|
|
36
|
+
*
|
|
37
|
+
* The `queryKey` will be tagged with the type from `queryFn`.
|
|
38
|
+
* @param options - The infinite query options to tag with the type from `queryFn`.
|
|
39
|
+
* @returns The tagged infinite query options.
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
43
|
+
queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
44
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"infinite-query-options.mjs","sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n DataTag,\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n | undefined\n}\n\n/**\n * Allows to share and re-use infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n * @public\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n}\n\n/**\n * Allows to share and re-use infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n * @public\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n}\n\n/**\n * Allows to share and re-use infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n * @public\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n}\n\n/**\n * Allows to share and re-use infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n * @public\n */\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AAwLO,SAAS,qBAAqB,SAAkB;AAC9C,SAAA;AACT;"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { Injector } from '@angular/core';
|
|
2
|
+
import { DefaultError, InfiniteData, QueryKey } from '@tanstack/query-core';
|
|
3
|
+
import { CreateInfiniteQueryOptions, CreateInfiniteQueryResult, DefinedCreateInfiniteQueryResult } from './types.js';
|
|
4
|
+
import { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions } from './infinite-query-options.js';
|
|
5
|
+
export interface InjectInfiniteQueryOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The `Injector` in which to create the infinite query.
|
|
8
|
+
*
|
|
9
|
+
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
10
|
+
*/
|
|
11
|
+
injector?: Injector;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
15
|
+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
16
|
+
* @param injectInfiniteQueryFn - A function that returns infinite query options.
|
|
17
|
+
* @param options - Additional configuration.
|
|
18
|
+
* @returns The infinite query result.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): DefinedCreateInfiniteQueryResult<TData, TError>;
|
|
22
|
+
/**
|
|
23
|
+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
24
|
+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
25
|
+
* @param injectInfiniteQueryFn - A function that returns infinite query options.
|
|
26
|
+
* @param options - Additional configuration.
|
|
27
|
+
* @returns The infinite query result.
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
|
|
31
|
+
/**
|
|
32
|
+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
|
|
33
|
+
* Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
|
|
34
|
+
* @param injectInfiniteQueryFn - A function that returns infinite query options.
|
|
35
|
+
* @param options - Additional configuration.
|
|
36
|
+
* @returns The infinite query result.
|
|
37
|
+
* @public
|
|
38
|
+
*/
|
|
39
|
+
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { InfiniteQueryObserver } from "@tanstack/query-core";
|
|
2
|
+
import { assertInInjectionContext, inject, Injector, runInInjectionContext } from "@angular/core";
|
|
3
|
+
import { createBaseQuery } from "./create-base-query.mjs";
|
|
4
|
+
function injectInfiniteQuery(injectInfiniteQueryFn, options) {
|
|
5
|
+
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectInfiniteQuery);
|
|
6
|
+
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
7
|
+
return runInInjectionContext(
|
|
8
|
+
injector,
|
|
9
|
+
() => createBaseQuery(
|
|
10
|
+
injectInfiniteQueryFn,
|
|
11
|
+
InfiniteQueryObserver
|
|
12
|
+
)
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
export {
|
|
16
|
+
injectInfiniteQuery
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=inject-infinite-query.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-infinite-query.mjs","sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport {\n Injector,\n assertInInjectionContext,\n inject,\n runInInjectionContext,\n} from '@angular/core'\nimport { createBaseQuery } from './create-base-query'\nimport type {\n DefaultError,\n InfiniteData,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\n\nexport interface InjectInfiniteQueryOptions {\n /**\n * The `Injector` in which to create the infinite query.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n * @public\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): DefinedCreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n * @public\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n * @public\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n * @public\n */\nexport function injectInfiniteQuery(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions,\n options?: InjectInfiniteQueryOptions,\n) {\n !options?.injector && assertInInjectionContext(injectInfiniteQuery)\n const injector = options?.injector ?? inject(Injector)\n return runInInjectionContext(injector, () =>\n createBaseQuery(\n injectInfiniteQueryFn,\n InfiniteQueryObserver as typeof QueryObserver,\n ),\n )\n}\n"],"names":[],"mappings":";;;AAoHgB,SAAA,oBACd,uBACA,SACA;AACC,IAAA,mCAAS,aAAY,yBAAyB,mBAAmB;AAClE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AAC9C,SAAA;AAAA,IAAsB;AAAA,IAAU,MACrC;AAAA,MACE;AAAA,MACA;AAAA,IAAA;AAAA,EAEJ;AACF;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Injector, Signal } from '@angular/core';
|
|
2
|
+
import { QueryFilters } from '@tanstack/query-core';
|
|
3
|
+
export interface InjectIsFetchingOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The `Injector` in which to create the isFetching signal.
|
|
6
|
+
*
|
|
7
|
+
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
8
|
+
*/
|
|
9
|
+
injector?: Injector;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Injects a signal that tracks the number of queries that your application is loading or
|
|
13
|
+
* fetching in the background.
|
|
14
|
+
*
|
|
15
|
+
* Can be used for app-wide loading indicators
|
|
16
|
+
* @param filters - The filters to apply to the query.
|
|
17
|
+
* @param options - Additional configuration
|
|
18
|
+
* @returns signal with number of loading or fetching queries.
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
export declare function injectIsFetching(filters?: QueryFilters, options?: InjectIsFetchingOptions): Signal<number>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertInInjectionContext, inject, Injector, DestroyRef, NgZone, signal } from "@angular/core";
|
|
2
|
+
import { QueryClient, notifyManager } from "@tanstack/query-core";
|
|
3
|
+
function injectIsFetching(filters, options) {
|
|
4
|
+
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectIsFetching);
|
|
5
|
+
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
6
|
+
const destroyRef = injector.get(DestroyRef);
|
|
7
|
+
const ngZone = injector.get(NgZone);
|
|
8
|
+
const queryClient = injector.get(QueryClient);
|
|
9
|
+
const cache = queryClient.getQueryCache();
|
|
10
|
+
let isFetching = queryClient.isFetching(filters);
|
|
11
|
+
const result = signal(isFetching);
|
|
12
|
+
const unsubscribe = ngZone.runOutsideAngular(
|
|
13
|
+
() => cache.subscribe(
|
|
14
|
+
notifyManager.batchCalls(() => {
|
|
15
|
+
const newIsFetching = queryClient.isFetching(filters);
|
|
16
|
+
if (isFetching !== newIsFetching) {
|
|
17
|
+
isFetching = newIsFetching;
|
|
18
|
+
ngZone.run(() => {
|
|
19
|
+
result.set(isFetching);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
destroyRef.onDestroy(unsubscribe);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
injectIsFetching
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=inject-is-fetching.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-is-fetching.mjs","sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport { QueryClient, notifyManager } from '@tanstack/query-core'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\nexport interface InjectIsFetchingOptions {\n /**\n * The `Injector` in which to create the isFetching signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks the number of queries that your application is loading or\n * fetching in the background.\n *\n * Can be used for app-wide loading indicators\n * @param filters - The filters to apply to the query.\n * @param options - Additional configuration\n * @returns signal with number of loading or fetching queries.\n * @public\n */\nexport function injectIsFetching(\n filters?: QueryFilters,\n options?: InjectIsFetchingOptions,\n): Signal<number> {\n !options?.injector && assertInInjectionContext(injectIsFetching)\n const injector = options?.injector ?? inject(Injector)\n const destroyRef = injector.get(DestroyRef)\n const ngZone = injector.get(NgZone)\n const queryClient = injector.get(QueryClient)\n\n const cache = queryClient.getQueryCache()\n // isFetching is the prev value initialized on mount *\n let isFetching = queryClient.isFetching(filters)\n\n const result = signal(isFetching)\n\n const unsubscribe = ngZone.runOutsideAngular(() =>\n cache.subscribe(\n notifyManager.batchCalls(() => {\n const newIsFetching = queryClient.isFetching(filters)\n if (isFetching !== newIsFetching) {\n // * and update with each change\n isFetching = newIsFetching\n ngZone.run(() => {\n result.set(isFetching)\n })\n }\n }),\n ),\n )\n\n destroyRef.onDestroy(unsubscribe)\n\n return result\n}\n"],"names":[],"mappings":";;AA+BgB,SAAA,iBACd,SACA,SACgB;AACf,IAAA,mCAAS,aAAY,yBAAyB,gBAAgB;AAC/D,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AAC/C,QAAA,aAAa,SAAS,IAAI,UAAU;AACpC,QAAA,SAAS,SAAS,IAAI,MAAM;AAC5B,QAAA,cAAc,SAAS,IAAI,WAAW;AAEtC,QAAA,QAAQ,YAAY,cAAc;AAEpC,MAAA,aAAa,YAAY,WAAW,OAAO;AAEzC,QAAA,SAAS,OAAO,UAAU;AAEhC,QAAM,cAAc,OAAO;AAAA,IAAkB,MAC3C,MAAM;AAAA,MACJ,cAAc,WAAW,MAAM;AACvB,cAAA,gBAAgB,YAAY,WAAW,OAAO;AACpD,YAAI,eAAe,eAAe;AAEnB,uBAAA;AACb,iBAAO,IAAI,MAAM;AACf,mBAAO,IAAI,UAAU;AAAA,UAAA,CACtB;AAAA,QAAA;AAAA,MAEJ,CAAA;AAAA,IAAA;AAAA,EAEL;AAEA,aAAW,UAAU,WAAW;AAEzB,SAAA;AACT;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Injector, Signal } from '@angular/core';
|
|
2
|
+
import { MutationFilters } from '@tanstack/query-core';
|
|
3
|
+
export interface InjectIsMutatingOptions {
|
|
4
|
+
/**
|
|
5
|
+
* The `Injector` in which to create the isMutating signal.
|
|
6
|
+
*
|
|
7
|
+
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
8
|
+
*/
|
|
9
|
+
injector?: Injector;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Injects a signal that tracks the number of mutations that your application is fetching.
|
|
13
|
+
*
|
|
14
|
+
* Can be used for app-wide loading indicators
|
|
15
|
+
* @param filters - The filters to apply to the query.
|
|
16
|
+
* @param options - Additional configuration
|
|
17
|
+
* @returns signal with number of fetching mutations.
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
export declare function injectIsMutating(filters?: MutationFilters, options?: InjectIsMutatingOptions): Signal<number>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { assertInInjectionContext, inject, Injector, DestroyRef, NgZone, signal } from "@angular/core";
|
|
2
|
+
import { QueryClient, notifyManager } from "@tanstack/query-core";
|
|
3
|
+
function injectIsMutating(filters, options) {
|
|
4
|
+
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectIsMutating);
|
|
5
|
+
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
6
|
+
const destroyRef = injector.get(DestroyRef);
|
|
7
|
+
const ngZone = injector.get(NgZone);
|
|
8
|
+
const queryClient = injector.get(QueryClient);
|
|
9
|
+
const cache = queryClient.getMutationCache();
|
|
10
|
+
let isMutating = queryClient.isMutating(filters);
|
|
11
|
+
const result = signal(isMutating);
|
|
12
|
+
const unsubscribe = ngZone.runOutsideAngular(
|
|
13
|
+
() => cache.subscribe(
|
|
14
|
+
notifyManager.batchCalls(() => {
|
|
15
|
+
const newIsMutating = queryClient.isMutating(filters);
|
|
16
|
+
if (isMutating !== newIsMutating) {
|
|
17
|
+
isMutating = newIsMutating;
|
|
18
|
+
ngZone.run(() => {
|
|
19
|
+
result.set(isMutating);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
)
|
|
24
|
+
);
|
|
25
|
+
destroyRef.onDestroy(unsubscribe);
|
|
26
|
+
return result;
|
|
27
|
+
}
|
|
28
|
+
export {
|
|
29
|
+
injectIsMutating
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=inject-is-mutating.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-is-mutating.mjs","sources":["../src/inject-is-mutating.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport { QueryClient, notifyManager } from '@tanstack/query-core'\nimport type { MutationFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\nexport interface InjectIsMutatingOptions {\n /**\n * The `Injector` in which to create the isMutating signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks the number of mutations that your application is fetching.\n *\n * Can be used for app-wide loading indicators\n * @param filters - The filters to apply to the query.\n * @param options - Additional configuration\n * @returns signal with number of fetching mutations.\n * @public\n */\nexport function injectIsMutating(\n filters?: MutationFilters,\n options?: InjectIsMutatingOptions,\n): Signal<number> {\n !options?.injector && assertInInjectionContext(injectIsMutating)\n const injector = options?.injector ?? inject(Injector)\n const destroyRef = injector.get(DestroyRef)\n const ngZone = injector.get(NgZone)\n const queryClient = injector.get(QueryClient)\n\n const cache = queryClient.getMutationCache()\n // isMutating is the prev value initialized on mount *\n let isMutating = queryClient.isMutating(filters)\n\n const result = signal(isMutating)\n\n const unsubscribe = ngZone.runOutsideAngular(() =>\n cache.subscribe(\n notifyManager.batchCalls(() => {\n const newIsMutating = queryClient.isMutating(filters)\n if (isMutating !== newIsMutating) {\n // * and update with each change\n isMutating = newIsMutating\n ngZone.run(() => {\n result.set(isMutating)\n })\n }\n }),\n ),\n )\n\n destroyRef.onDestroy(unsubscribe)\n\n return result\n}\n"],"names":[],"mappings":";;AA8BgB,SAAA,iBACd,SACA,SACgB;AACf,IAAA,mCAAS,aAAY,yBAAyB,gBAAgB;AAC/D,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AAC/C,QAAA,aAAa,SAAS,IAAI,UAAU;AACpC,QAAA,SAAS,SAAS,IAAI,MAAM;AAC5B,QAAA,cAAc,SAAS,IAAI,WAAW;AAEtC,QAAA,QAAQ,YAAY,iBAAiB;AAEvC,MAAA,aAAa,YAAY,WAAW,OAAO;AAEzC,QAAA,SAAS,OAAO,UAAU;AAEhC,QAAM,cAAc,OAAO;AAAA,IAAkB,MAC3C,MAAM;AAAA,MACJ,cAAc,WAAW,MAAM;AACvB,cAAA,gBAAgB,YAAY,WAAW,OAAO;AACpD,YAAI,eAAe,eAAe;AAEnB,uBAAA;AACb,iBAAO,IAAI,MAAM;AACf,mBAAO,IAAI,UAAU;AAAA,UAAA,CACtB;AAAA,QAAA;AAAA,MAEJ,CAAA;AAAA,IAAA;AAAA,EAEL;AAEA,aAAW,UAAU,WAAW;AAEzB,SAAA;AACT;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Injector, Provider, Signal } from '@angular/core';
|
|
2
|
+
/**
|
|
3
|
+
* The `Injector` in which to create the isRestoring signal.
|
|
4
|
+
*
|
|
5
|
+
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
6
|
+
*/
|
|
7
|
+
interface InjectIsRestoringOptions {
|
|
8
|
+
injector?: Injector;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Injects a signal that tracks whether a restore is currently in progress. {@link injectQuery} and friends also check this internally to avoid race conditions between the restore and initializing queries.
|
|
12
|
+
* @param options - Options for injectIsRestoring.
|
|
13
|
+
* @returns signal with boolean that indicates whether a restore is in progress.
|
|
14
|
+
* @public
|
|
15
|
+
*/
|
|
16
|
+
export declare function injectIsRestoring(options?: InjectIsRestoringOptions): Signal<boolean>;
|
|
17
|
+
/**
|
|
18
|
+
* Used by TanStack Query Angular persist client plugin to provide the signal that tracks the restore state
|
|
19
|
+
* @param isRestoring - a readonly signal that returns a boolean
|
|
20
|
+
* @returns Provider for the `isRestoring` signal
|
|
21
|
+
* @public
|
|
22
|
+
*/
|
|
23
|
+
export declare function provideIsRestoring(isRestoring: Signal<boolean>): Provider;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { assertInInjectionContext, inject, Injector, InjectionToken, signal } from "@angular/core";
|
|
2
|
+
const IS_RESTORING = new InjectionToken(
|
|
3
|
+
typeof ngDevMode === "undefined" || ngDevMode ? "TANSTACK_QUERY_IS_RESTORING" : "",
|
|
4
|
+
{
|
|
5
|
+
// Default value when not provided
|
|
6
|
+
factory: () => signal(false).asReadonly()
|
|
7
|
+
}
|
|
8
|
+
);
|
|
9
|
+
function injectIsRestoring(options) {
|
|
10
|
+
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectIsRestoring);
|
|
11
|
+
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
12
|
+
return injector.get(IS_RESTORING);
|
|
13
|
+
}
|
|
14
|
+
function provideIsRestoring(isRestoring) {
|
|
15
|
+
return {
|
|
16
|
+
provide: IS_RESTORING,
|
|
17
|
+
useValue: isRestoring
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
injectIsRestoring,
|
|
22
|
+
provideIsRestoring
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=inject-is-restoring.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-is-restoring.mjs","sources":["../src/inject-is-restoring.ts"],"sourcesContent":["import {\n InjectionToken,\n Injector,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport type { Provider, Signal } from '@angular/core'\n\nconst IS_RESTORING = new InjectionToken(\n typeof ngDevMode === 'undefined' || ngDevMode\n ? 'TANSTACK_QUERY_IS_RESTORING'\n : '',\n {\n // Default value when not provided\n factory: () => signal(false).asReadonly(),\n },\n)\n\n/**\n * The `Injector` in which to create the isRestoring signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\ninterface InjectIsRestoringOptions {\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks whether a restore is currently in progress. {@link injectQuery} and friends also check this internally to avoid race conditions between the restore and initializing queries.\n * @param options - Options for injectIsRestoring.\n * @returns signal with boolean that indicates whether a restore is in progress.\n * @public\n */\nexport function injectIsRestoring(options?: InjectIsRestoringOptions) {\n !options?.injector && assertInInjectionContext(injectIsRestoring)\n const injector = options?.injector ?? inject(Injector)\n return injector.get(IS_RESTORING)\n}\n\n/**\n * Used by TanStack Query Angular persist client plugin to provide the signal that tracks the restore state\n * @param isRestoring - a readonly signal that returns a boolean\n * @returns Provider for the `isRestoring` signal\n * @public\n */\nexport function provideIsRestoring(isRestoring: Signal<boolean>): Provider {\n return {\n provide: IS_RESTORING,\n useValue: isRestoring,\n }\n}\n"],"names":[],"mappings":";AASA,MAAM,eAAe,IAAI;AAAA,EACvB,OAAO,cAAc,eAAe,YAChC,gCACA;AAAA,EACJ;AAAA;AAAA,IAEE,SAAS,MAAM,OAAO,KAAK,EAAE,WAAW;AAAA,EAAA;AAE5C;AAiBO,SAAS,kBAAkB,SAAoC;AACnE,IAAA,mCAAS,aAAY,yBAAyB,iBAAiB;AAChE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AAC9C,SAAA,SAAS,IAAI,YAAY;AAClC;AAQO,SAAS,mBAAmB,aAAwC;AAClE,SAAA;AAAA,IACL,SAAS;AAAA,IACT,UAAU;AAAA,EACZ;AACF;"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Injector, Signal } from '@angular/core';
|
|
2
|
+
import { Mutation, MutationFilters, MutationState } from '@tanstack/query-core';
|
|
3
|
+
type MutationStateOptions<TResult = MutationState> = {
|
|
4
|
+
filters?: MutationFilters;
|
|
5
|
+
select?: (mutation: Mutation) => TResult;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export interface InjectMutationStateOptions {
|
|
11
|
+
/**
|
|
12
|
+
* The `Injector` in which to create the mutation state signal.
|
|
13
|
+
*
|
|
14
|
+
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
15
|
+
*/
|
|
16
|
+
injector?: Injector;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Injects a signal that tracks the state of all mutations.
|
|
20
|
+
* @param injectMutationStateFn - A function that returns mutation state options.
|
|
21
|
+
* @param options - The Angular injector to use.
|
|
22
|
+
* @returns The signal that tracks the state of all mutations.
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
export declare function injectMutationState<TResult = MutationState>(injectMutationStateFn?: () => MutationStateOptions<TResult>, options?: InjectMutationStateOptions): Signal<Array<TResult>>;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { assertInInjectionContext, inject, Injector, DestroyRef, NgZone, computed, signal } from "@angular/core";
|
|
2
|
+
import { QueryClient, notifyManager, replaceEqualDeep } from "@tanstack/query-core";
|
|
3
|
+
function getResult(mutationCache, options) {
|
|
4
|
+
return mutationCache.findAll(options.filters).map(
|
|
5
|
+
(mutation) => options.select ? options.select(mutation) : mutation.state
|
|
6
|
+
);
|
|
7
|
+
}
|
|
8
|
+
function injectMutationState(injectMutationStateFn = () => ({}), options) {
|
|
9
|
+
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectMutationState);
|
|
10
|
+
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
11
|
+
const destroyRef = injector.get(DestroyRef);
|
|
12
|
+
const ngZone = injector.get(NgZone);
|
|
13
|
+
const queryClient = injector.get(QueryClient);
|
|
14
|
+
const mutationCache = queryClient.getMutationCache();
|
|
15
|
+
const resultFromOptionsSignal = computed(() => {
|
|
16
|
+
return [
|
|
17
|
+
getResult(mutationCache, injectMutationStateFn()),
|
|
18
|
+
performance.now()
|
|
19
|
+
];
|
|
20
|
+
});
|
|
21
|
+
const resultFromSubscriberSignal = signal(
|
|
22
|
+
null
|
|
23
|
+
);
|
|
24
|
+
const effectiveResultSignal = computed(() => {
|
|
25
|
+
const optionsResult = resultFromOptionsSignal();
|
|
26
|
+
const subscriberResult = resultFromSubscriberSignal();
|
|
27
|
+
return subscriberResult && subscriberResult[1] > optionsResult[1] ? subscriberResult[0] : optionsResult[0];
|
|
28
|
+
});
|
|
29
|
+
const unsubscribe = ngZone.runOutsideAngular(
|
|
30
|
+
() => mutationCache.subscribe(
|
|
31
|
+
notifyManager.batchCalls(() => {
|
|
32
|
+
const [lastResult] = effectiveResultSignal();
|
|
33
|
+
const nextResult = replaceEqualDeep(
|
|
34
|
+
lastResult,
|
|
35
|
+
getResult(mutationCache, injectMutationStateFn())
|
|
36
|
+
);
|
|
37
|
+
if (lastResult !== nextResult) {
|
|
38
|
+
ngZone.run(() => {
|
|
39
|
+
resultFromSubscriberSignal.set([nextResult, performance.now()]);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
)
|
|
44
|
+
);
|
|
45
|
+
destroyRef.onDestroy(unsubscribe);
|
|
46
|
+
return effectiveResultSignal;
|
|
47
|
+
}
|
|
48
|
+
export {
|
|
49
|
+
injectMutationState
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=inject-mutation-state.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject-mutation-state.mjs","sources":["../src/inject-mutation-state.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n computed,\n inject,\n signal,\n} from '@angular/core'\nimport {\n QueryClient,\n notifyManager,\n replaceEqualDeep,\n} from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\nimport type {\n Mutation,\n MutationCache,\n MutationFilters,\n MutationState,\n} from '@tanstack/query-core'\n\ntype MutationStateOptions<TResult = MutationState> = {\n filters?: MutationFilters\n select?: (mutation: Mutation) => TResult\n}\n\n/**\n *\n * @param mutationCache\n * @param options\n */\nfunction getResult<TResult = MutationState>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select ? options.select(mutation) : mutation.state) as TResult,\n )\n}\n\n/**\n * @public\n */\nexport interface InjectMutationStateOptions {\n /**\n * The `Injector` in which to create the mutation state signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks the state of all mutations.\n * @param injectMutationStateFn - A function that returns mutation state options.\n * @param options - The Angular injector to use.\n * @returns The signal that tracks the state of all mutations.\n * @public\n */\nexport function injectMutationState<TResult = MutationState>(\n injectMutationStateFn: () => MutationStateOptions<TResult> = () => ({}),\n options?: InjectMutationStateOptions,\n): Signal<Array<TResult>> {\n !options?.injector && assertInInjectionContext(injectMutationState)\n const injector = options?.injector ?? inject(Injector)\n const destroyRef = injector.get(DestroyRef)\n const ngZone = injector.get(NgZone)\n const queryClient = injector.get(QueryClient)\n const mutationCache = queryClient.getMutationCache()\n\n /**\n * Computed signal that gets result from mutation cache based on passed options\n * First element is the result, second element is the time when the result was set\n */\n const resultFromOptionsSignal = computed(() => {\n return [\n getResult(mutationCache, injectMutationStateFn()),\n performance.now(),\n ] as const\n })\n\n /**\n * Signal that contains result set by subscriber\n * First element is the result, second element is the time when the result was set\n */\n const resultFromSubscriberSignal = signal<[Array<TResult>, number] | null>(\n null,\n )\n\n /**\n * Returns the last result by either subscriber or options\n */\n const effectiveResultSignal = computed(() => {\n const optionsResult = resultFromOptionsSignal()\n const subscriberResult = resultFromSubscriberSignal()\n return subscriberResult && subscriberResult[1] > optionsResult[1]\n ? subscriberResult[0]\n : optionsResult[0]\n })\n\n const unsubscribe = ngZone.runOutsideAngular(() =>\n mutationCache.subscribe(\n notifyManager.batchCalls(() => {\n const [lastResult] = effectiveResultSignal()\n const nextResult = replaceEqualDeep(\n lastResult,\n getResult(mutationCache, injectMutationStateFn()),\n )\n if (lastResult !== nextResult) {\n ngZone.run(() => {\n resultFromSubscriberSignal.set([nextResult, performance.now()])\n })\n }\n }),\n ),\n )\n\n destroyRef.onDestroy(unsubscribe)\n\n return effectiveResultSignal\n}\n"],"names":[],"mappings":";;AAgCA,SAAS,UACP,eACA,SACgB;AAChB,SAAO,cACJ,QAAQ,QAAQ,OAAO,EACvB;AAAA,IACC,CAAC,aACE,QAAQ,SAAS,QAAQ,OAAO,QAAQ,IAAI,SAAS;AAAA,EAC1D;AACJ;AAqBO,SAAS,oBACd,wBAA6D,OAAO,KACpE,SACwB;AACvB,IAAA,mCAAS,aAAY,yBAAyB,mBAAmB;AAClE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AAC/C,QAAA,aAAa,SAAS,IAAI,UAAU;AACpC,QAAA,SAAS,SAAS,IAAI,MAAM;AAC5B,QAAA,cAAc,SAAS,IAAI,WAAW;AACtC,QAAA,gBAAgB,YAAY,iBAAiB;AAM7C,QAAA,0BAA0B,SAAS,MAAM;AACtC,WAAA;AAAA,MACL,UAAU,eAAe,uBAAuB;AAAA,MAChD,YAAY,IAAI;AAAA,IAClB;AAAA,EAAA,CACD;AAMD,QAAM,6BAA6B;AAAA,IACjC;AAAA,EACF;AAKM,QAAA,wBAAwB,SAAS,MAAM;AAC3C,UAAM,gBAAgB,wBAAwB;AAC9C,UAAM,mBAAmB,2BAA2B;AAC7C,WAAA,oBAAoB,iBAAiB,CAAC,IAAI,cAAc,CAAC,IAC5D,iBAAiB,CAAC,IAClB,cAAc,CAAC;AAAA,EAAA,CACpB;AAED,QAAM,cAAc,OAAO;AAAA,IAAkB,MAC3C,cAAc;AAAA,MACZ,cAAc,WAAW,MAAM;AACvB,cAAA,CAAC,UAAU,IAAI,sBAAsB;AAC3C,cAAM,aAAa;AAAA,UACjB;AAAA,UACA,UAAU,eAAe,sBAAuB,CAAA;AAAA,QAClD;AACA,YAAI,eAAe,YAAY;AAC7B,iBAAO,IAAI,MAAM;AACf,uCAA2B,IAAI,CAAC,YAAY,YAAY,IAAK,CAAA,CAAC;AAAA,UAAA,CAC/D;AAAA,QAAA;AAAA,MAEJ,CAAA;AAAA,IAAA;AAAA,EAEL;AAEA,aAAW,UAAU,WAAW;AAEzB,SAAA;AACT;"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Injector } from '@angular/core';
|
|
2
|
+
import { DefaultError } from '@tanstack/query-core';
|
|
3
|
+
import { CreateMutationResult } from './types.js';
|
|
4
|
+
import { CreateMutationOptions } from './mutation-options.js';
|
|
5
|
+
export interface InjectMutationOptions {
|
|
6
|
+
/**
|
|
7
|
+
* The `Injector` in which to create the mutation.
|
|
8
|
+
*
|
|
9
|
+
* If this is not provided, the current injection context will be used instead (via `inject`).
|
|
10
|
+
*/
|
|
11
|
+
injector?: Injector;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
|
|
15
|
+
*
|
|
16
|
+
* Unlike queries, mutations are not run automatically.
|
|
17
|
+
* @param injectMutationFn - A function that returns mutation options.
|
|
18
|
+
* @param options - Additional configuration
|
|
19
|
+
* @returns The mutation.
|
|
20
|
+
* @public
|
|
21
|
+
*/
|
|
22
|
+
export declare function injectMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(injectMutationFn: () => CreateMutationOptions<TData, TError, TVariables, TContext>, options?: InjectMutationOptions): CreateMutationResult<TData, TError, TVariables, TContext>;
|