@tanstack/angular-query-experimental 5.80.8 → 5.80.9
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 +2 -0
- package/build/index.d.ts +821 -0
- package/build/index.mjs +622 -0
- package/build/index.mjs.map +1 -0
- package/package.json +9 -11
- package/src/create-base-query.ts +142 -0
- package/src/index.ts +64 -0
- package/src/infinite-query-options.ts +187 -0
- package/src/inject-infinite-query.ts +129 -0
- package/src/inject-is-fetching.ts +66 -0
- package/src/inject-is-mutating.ts +65 -0
- package/{dist-ts/src/inject-is-restoring.d.ts → src/inject-is-restoring.ts} +33 -7
- package/src/inject-mutation-state.ts +125 -0
- package/src/inject-mutation.ts +169 -0
- package/src/inject-queries.ts +271 -0
- package/{dist-ts/src/inject-query-client.d.ts → src/inject-query-client.ts} +9 -7
- package/{dist-ts/src/inject-query.d.ts → src/inject-query.ts} +117 -14
- package/{dist-ts/src/mutation-options.d.ts → src/mutation-options.ts} +26 -5
- package/src/providers.ts +368 -0
- package/src/query-options.ts +178 -0
- package/src/signal-proxy.ts +46 -0
- package/src/test-setup.ts +10 -0
- package/src/types.ts +309 -0
- package/src/util/is-dev-mode/is-dev-mode.ts +3 -0
- package/dist/create-base-query.mjs +0 -74
- package/dist/create-base-query.mjs.map +0 -1
- package/dist/index.mjs +0 -35
- package/dist/index.mjs.map +0 -1
- package/dist/infinite-query-options.mjs +0 -7
- package/dist/infinite-query-options.mjs.map +0 -1
- package/dist/inject-infinite-query.mjs +0 -18
- package/dist/inject-infinite-query.mjs.map +0 -1
- package/dist/inject-is-fetching.mjs +0 -31
- package/dist/inject-is-fetching.mjs.map +0 -1
- package/dist/inject-is-mutating.mjs +0 -31
- package/dist/inject-is-mutating.mjs.map +0 -1
- package/dist/inject-is-restoring.mjs +0 -24
- package/dist/inject-is-restoring.mjs.map +0 -1
- package/dist/inject-mutation-state.mjs +0 -51
- package/dist/inject-mutation-state.mjs.map +0 -1
- package/dist/inject-mutation.mjs +0 -79
- package/dist/inject-mutation.mjs.map +0 -1
- package/dist/inject-queries.mjs +0 -49
- package/dist/inject-queries.mjs.map +0 -1
- package/dist/inject-query-client.mjs +0 -9
- package/dist/inject-query-client.mjs.map +0 -1
- package/dist/inject-query.mjs +0 -14
- package/dist/inject-query.mjs.map +0 -1
- package/dist/mutation-options.mjs +0 -7
- package/dist/mutation-options.mjs.map +0 -1
- package/dist/providers.mjs +0 -109
- package/dist/providers.mjs.map +0 -1
- package/dist/query-options.mjs +0 -7
- package/dist/query-options.mjs.map +0 -1
- package/dist/signal-proxy.mjs +0 -29
- package/dist/signal-proxy.mjs.map +0 -1
- package/dist-ts/eslint.config.d.ts +0 -3
- package/dist-ts/root.eslint.config.d.ts +0 -3
- package/dist-ts/src/__tests__/inject-infinite-query.test-d.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-infinite-query.test.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-is-fetching.test.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-is-mutating.test.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-mutation-state.test-d.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-mutation-state.test.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-mutation.test-d.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-mutation.test.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-query.test-d.d.ts +0 -2
- package/dist-ts/src/__tests__/inject-query.test.d.ts +0 -2
- package/dist-ts/src/__tests__/mutation-options.test-d.d.ts +0 -2
- package/dist-ts/src/__tests__/provide-query-client.test.d.ts +0 -2
- package/dist-ts/src/__tests__/provide-tanstack-query.test.d.ts +0 -2
- package/dist-ts/src/__tests__/providers.test.d.ts +0 -2
- package/dist-ts/src/__tests__/query-options.test-d.d.ts +0 -2
- package/dist-ts/src/__tests__/signal-proxy.test.d.ts +0 -2
- package/dist-ts/src/__tests__/test-utils.d.ts +0 -16
- package/dist-ts/src/create-base-query.d.ts +0 -9
- package/dist-ts/src/index.d.ts +0 -27
- package/dist-ts/src/infinite-query-options.d.ts +0 -45
- package/dist-ts/src/inject-infinite-query.d.ts +0 -40
- package/dist-ts/src/inject-is-fetching.d.ts +0 -23
- package/dist-ts/src/inject-is-mutating.d.ts +0 -22
- package/dist-ts/src/inject-mutation-state.d.ts +0 -28
- package/dist-ts/src/inject-mutation.d.ts +0 -23
- package/dist-ts/src/inject-queries.d.ts +0 -78
- package/dist-ts/src/providers.d.ts +0 -217
- package/dist-ts/src/query-options.d.ts +0 -88
- package/dist-ts/src/signal-proxy.d.ts +0 -12
- package/dist-ts/src/test-setup.d.ts +0 -2
- package/dist-ts/src/types.d.ts +0 -90
- package/dist-ts/src/util/is-dev-mode/is-dev-mode.d.ts +0 -2
- package/dist-ts/vite.config.d.ts +0 -5
package/dist/inject-mutation.mjs
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { assertInInjectionContext, inject, Injector, DestroyRef, NgZone, computed, signal, effect, untracked } from "@angular/core";
|
|
2
|
-
import { QueryClient, MutationObserver, noop, notifyManager, shouldThrowError } from "@tanstack/query-core";
|
|
3
|
-
import { signalProxy } from "./signal-proxy.mjs";
|
|
4
|
-
function injectMutation(injectMutationFn, options) {
|
|
5
|
-
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectMutation);
|
|
6
|
-
const injector = (options == null ? void 0 : options.injector) ?? inject(Injector);
|
|
7
|
-
const destroyRef = injector.get(DestroyRef);
|
|
8
|
-
const ngZone = injector.get(NgZone);
|
|
9
|
-
const queryClient = injector.get(QueryClient);
|
|
10
|
-
const optionsSignal = computed(injectMutationFn);
|
|
11
|
-
const observerSignal = (() => {
|
|
12
|
-
let instance = null;
|
|
13
|
-
return computed(() => {
|
|
14
|
-
return instance || (instance = new MutationObserver(queryClient, optionsSignal()));
|
|
15
|
-
});
|
|
16
|
-
})();
|
|
17
|
-
const mutateFnSignal = computed(() => {
|
|
18
|
-
const observer = observerSignal();
|
|
19
|
-
return (variables, mutateOptions) => {
|
|
20
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
const resultFromInitialOptionsSignal = computed(() => {
|
|
24
|
-
const observer = observerSignal();
|
|
25
|
-
return observer.getCurrentResult();
|
|
26
|
-
});
|
|
27
|
-
const resultFromSubscriberSignal = signal(null);
|
|
28
|
-
effect(
|
|
29
|
-
() => {
|
|
30
|
-
const observer = observerSignal();
|
|
31
|
-
const observerOptions = optionsSignal();
|
|
32
|
-
untracked(() => {
|
|
33
|
-
observer.setOptions(observerOptions);
|
|
34
|
-
});
|
|
35
|
-
},
|
|
36
|
-
{
|
|
37
|
-
injector
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
effect(
|
|
41
|
-
() => {
|
|
42
|
-
const observer = observerSignal();
|
|
43
|
-
untracked(() => {
|
|
44
|
-
const unsubscribe = ngZone.runOutsideAngular(
|
|
45
|
-
() => observer.subscribe(
|
|
46
|
-
notifyManager.batchCalls((state) => {
|
|
47
|
-
ngZone.run(() => {
|
|
48
|
-
if (state.isError && shouldThrowError(observer.options.throwOnError, [state.error])) {
|
|
49
|
-
ngZone.onError.emit(state.error);
|
|
50
|
-
throw state.error;
|
|
51
|
-
}
|
|
52
|
-
resultFromSubscriberSignal.set(state);
|
|
53
|
-
});
|
|
54
|
-
})
|
|
55
|
-
)
|
|
56
|
-
);
|
|
57
|
-
destroyRef.onDestroy(unsubscribe);
|
|
58
|
-
});
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
injector
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
|
-
const resultSignal = computed(() => {
|
|
65
|
-
const resultFromSubscriber = resultFromSubscriberSignal();
|
|
66
|
-
const resultFromInitialOptions = resultFromInitialOptionsSignal();
|
|
67
|
-
const result = resultFromSubscriber ?? resultFromInitialOptions;
|
|
68
|
-
return {
|
|
69
|
-
...result,
|
|
70
|
-
mutate: mutateFnSignal(),
|
|
71
|
-
mutateAsync: result.mutate
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
return signalProxy(resultSignal);
|
|
75
|
-
}
|
|
76
|
-
export {
|
|
77
|
-
injectMutation
|
|
78
|
-
};
|
|
79
|
-
//# sourceMappingURL=inject-mutation.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-mutation.mjs","sources":["../src/inject-mutation.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n signal,\n untracked,\n} from '@angular/core'\nimport {\n MutationObserver,\n QueryClient,\n noop,\n notifyManager,\n shouldThrowError,\n} from '@tanstack/query-core'\nimport { signalProxy } from './signal-proxy'\nimport type { DefaultError, MutationObserverResult } from '@tanstack/query-core'\nimport type { CreateMutateFunction, CreateMutationResult } from './types'\nimport type { CreateMutationOptions } from './mutation-options'\n\nexport interface InjectMutationOptions {\n /**\n * The `Injector` in which to create the mutation.\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 mutation: an imperative function that can be invoked which typically performs server side effects.\n *\n * Unlike queries, mutations are not run automatically.\n * @param injectMutationFn - A function that returns mutation options.\n * @param options - Additional configuration\n * @returns The mutation.\n * @public\n */\nexport function injectMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n injectMutationFn: () => CreateMutationOptions<\n TData,\n TError,\n TVariables,\n TContext\n >,\n options?: InjectMutationOptions,\n): CreateMutationResult<TData, TError, TVariables, TContext> {\n !options?.injector && assertInInjectionContext(injectMutation)\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 /**\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 optionsSignal = computed(injectMutationFn)\n\n const observerSignal = (() => {\n let instance: MutationObserver<TData, TError, TVariables, TContext> | null =\n null\n\n return computed(() => {\n return (instance ||= new MutationObserver(queryClient, optionsSignal()))\n })\n })()\n\n const mutateFnSignal = computed<\n CreateMutateFunction<TData, TError, TVariables, TContext>\n >(() => {\n const observer = observerSignal()\n return (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n }\n })\n\n /**\n * Computed signal that gets result from mutation cache based on passed options\n */\n const resultFromInitialOptionsSignal = computed(() => {\n const observer = observerSignal()\n return observer.getCurrentResult()\n })\n\n /**\n * Signal that contains result set by subscriber\n */\n const resultFromSubscriberSignal = signal<MutationObserverResult<\n TData,\n TError,\n TVariables,\n TContext\n > | null>(null)\n\n effect(\n () => {\n const observer = observerSignal()\n const observerOptions = optionsSignal()\n\n untracked(() => {\n observer.setOptions(observerOptions)\n })\n },\n {\n injector,\n },\n )\n\n effect(\n () => {\n // observer.trackResult is not used as this optimization is not needed for Angular\n const observer = observerSignal()\n\n untracked(() => {\n const unsubscribe = ngZone.runOutsideAngular(() =>\n observer.subscribe(\n notifyManager.batchCalls((state) => {\n ngZone.run(() => {\n if (\n state.isError &&\n shouldThrowError(observer.options.throwOnError, [state.error])\n ) {\n ngZone.onError.emit(state.error)\n throw state.error\n }\n\n resultFromSubscriberSignal.set(state)\n })\n }),\n ),\n )\n destroyRef.onDestroy(unsubscribe)\n })\n },\n {\n injector,\n },\n )\n\n const resultSignal = computed(() => {\n const resultFromSubscriber = resultFromSubscriberSignal()\n const resultFromInitialOptions = resultFromInitialOptionsSignal()\n\n const result = resultFromSubscriber ?? resultFromInitialOptions\n\n return {\n ...result,\n mutate: mutateFnSignal(),\n mutateAsync: result.mutate,\n }\n })\n\n return signalProxy(resultSignal) as CreateMutationResult<\n TData,\n TError,\n TVariables,\n TContext\n >\n}\n"],"names":[],"mappings":";;;AAyCgB,SAAA,eAMd,kBAMA,SAC2D;AAC1D,IAAA,mCAAS,aAAY,yBAAyB,cAAc;AAC7D,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;AAOtC,QAAA,gBAAgB,SAAS,gBAAgB;AAE/C,QAAM,kBAAkB,MAAM;AAC5B,QAAI,WACF;AAEF,WAAO,SAAS,MAAM;AACpB,aAAQ,wBAAa,IAAI,iBAAiB,aAAa,eAAe;AAAA,IAAA,CACvE;AAAA,EAAA,GACA;AAEG,QAAA,iBAAiB,SAErB,MAAM;AACN,UAAM,WAAW,eAAe;AACzB,WAAA,CAAC,WAAW,kBAAkB;AACnC,eAAS,OAAO,WAAW,aAAa,EAAE,MAAM,IAAI;AAAA,IACtD;AAAA,EAAA,CACD;AAKK,QAAA,iCAAiC,SAAS,MAAM;AACpD,UAAM,WAAW,eAAe;AAChC,WAAO,SAAS,iBAAiB;AAAA,EAAA,CAClC;AAKK,QAAA,6BAA6B,OAKzB,IAAI;AAEd;AAAA,IACE,MAAM;AACJ,YAAM,WAAW,eAAe;AAChC,YAAM,kBAAkB,cAAc;AAEtC,gBAAU,MAAM;AACd,iBAAS,WAAW,eAAe;AAAA,MAAA,CACpC;AAAA,IACH;AAAA,IACA;AAAA,MACE;AAAA,IAAA;AAAA,EAEJ;AAEA;AAAA,IACE,MAAM;AAEJ,YAAM,WAAW,eAAe;AAEhC,gBAAU,MAAM;AACd,cAAM,cAAc,OAAO;AAAA,UAAkB,MAC3C,SAAS;AAAA,YACP,cAAc,WAAW,CAAC,UAAU;AAClC,qBAAO,IAAI,MAAM;AAEb,oBAAA,MAAM,WACN,iBAAiB,SAAS,QAAQ,cAAc,CAAC,MAAM,KAAK,CAAC,GAC7D;AACO,yBAAA,QAAQ,KAAK,MAAM,KAAK;AAC/B,wBAAM,MAAM;AAAA,gBAAA;AAGd,2CAA2B,IAAI,KAAK;AAAA,cAAA,CACrC;AAAA,YACF,CAAA;AAAA,UAAA;AAAA,QAEL;AACA,mBAAW,UAAU,WAAW;AAAA,MAAA,CACjC;AAAA,IACH;AAAA,IACA;AAAA,MACE;AAAA,IAAA;AAAA,EAEJ;AAEM,QAAA,eAAe,SAAS,MAAM;AAClC,UAAM,uBAAuB,2BAA2B;AACxD,UAAM,2BAA2B,+BAA+B;AAEhE,UAAM,SAAS,wBAAwB;AAEhC,WAAA;AAAA,MACL,GAAG;AAAA,MACH,QAAQ,eAAe;AAAA,MACvB,aAAa,OAAO;AAAA,IACtB;AAAA,EAAA,CACD;AAED,SAAO,YAAY,YAAY;AAMjC;"}
|
package/dist/inject-queries.mjs
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import { QueryClient, QueriesObserver, notifyManager } from "@tanstack/query-core";
|
|
2
|
-
import { assertInInjectionContext, runInInjectionContext, inject, Injector, DestroyRef, NgZone, computed, effect, signal } from "@angular/core";
|
|
3
|
-
import { injectIsRestoring } from "./inject-is-restoring.mjs";
|
|
4
|
-
function injectQueries({
|
|
5
|
-
queries,
|
|
6
|
-
...options
|
|
7
|
-
}, injector) {
|
|
8
|
-
!injector && assertInInjectionContext(injectQueries);
|
|
9
|
-
return runInInjectionContext(injector ?? inject(Injector), () => {
|
|
10
|
-
const destroyRef = inject(DestroyRef);
|
|
11
|
-
const ngZone = inject(NgZone);
|
|
12
|
-
const queryClient = inject(QueryClient);
|
|
13
|
-
const isRestoring = injectIsRestoring();
|
|
14
|
-
const defaultedQueries = computed(() => {
|
|
15
|
-
return queries().map((opts) => {
|
|
16
|
-
const defaultedOptions = queryClient.defaultQueryOptions(opts);
|
|
17
|
-
defaultedOptions._optimisticResults = isRestoring() ? "isRestoring" : "optimistic";
|
|
18
|
-
return defaultedOptions;
|
|
19
|
-
});
|
|
20
|
-
});
|
|
21
|
-
const observer = new QueriesObserver(
|
|
22
|
-
queryClient,
|
|
23
|
-
defaultedQueries(),
|
|
24
|
-
options
|
|
25
|
-
);
|
|
26
|
-
effect(() => {
|
|
27
|
-
observer.setQueries(
|
|
28
|
-
defaultedQueries(),
|
|
29
|
-
options
|
|
30
|
-
);
|
|
31
|
-
});
|
|
32
|
-
const [, getCombinedResult] = observer.getOptimisticResult(
|
|
33
|
-
defaultedQueries(),
|
|
34
|
-
options.combine
|
|
35
|
-
);
|
|
36
|
-
const result = signal(getCombinedResult());
|
|
37
|
-
effect(() => {
|
|
38
|
-
const unsubscribe = isRestoring() ? () => void 0 : ngZone.runOutsideAngular(
|
|
39
|
-
() => observer.subscribe(notifyManager.batchCalls(result.set))
|
|
40
|
-
);
|
|
41
|
-
destroyRef.onDestroy(unsubscribe);
|
|
42
|
-
});
|
|
43
|
-
return result;
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
export {
|
|
47
|
-
injectQueries
|
|
48
|
-
};
|
|
49
|
-
//# sourceMappingURL=inject-queries.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-queries.mjs","sources":["../src/inject-queries.ts"],"sourcesContent":["import {\n QueriesObserver,\n QueryClient,\n notifyManager,\n} from '@tanstack/query-core'\nimport {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n computed,\n effect,\n inject,\n runInInjectionContext,\n signal,\n} from '@angular/core'\nimport { injectIsRestoring } from './inject-is-restoring'\nimport type { Signal } from '@angular/core'\nimport type {\n DefaultError,\n OmitKeyof,\n QueriesObserverOptions,\n QueriesPlaceholderDataFunction,\n QueryFunction,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n ThrowOnError,\n} from '@tanstack/query-core'\n\n// This defines the `CreateQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// `placeholderData` function does not have a parameter\ntype QueryObserverOptionsForCreateQueries<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>,\n 'placeholderData'\n> & {\n placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>\n}\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\n// Widen the type of the symbol to enable type inference even if skipToken is not immutable.\ntype SkipTokenForUseQueries = symbol\n\ntype GetOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? QueryObserverOptionsForCreateQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? QueryObserverOptionsForCreateQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, infer TQueryKey>\n | SkipTokenForUseQueries\n select: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? QueryObserverOptionsForCreateQueries<\n TQueryFnData,\n unknown extends TError ? DefaultError : TError,\n unknown extends TData ? TQueryFnData : TData,\n TQueryKey\n >\n : // Fallback\n QueryObserverOptionsForCreateQueries\n\ntype GetResults<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? QueryObserverResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? QueryObserverResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? QueryObserverResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? QueryObserverResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?:\n | QueryFunction<infer TQueryFnData, any>\n | SkipTokenForUseQueries\n select: (data: any) => infer TData\n throwOnError?: ThrowOnError<any, infer TError, any, any>\n }\n ? QueryObserverResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n : // Fallback\n QueryObserverResult\n\n/**\n * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n * @public\n */\nexport type QueriesOptions<\n T extends Array<any>,\n TResult extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<QueryObserverOptionsForCreateQueries>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResult, GetOptions<Head>]\n : T extends [infer Head, ...infer Tail]\n ? QueriesOptions<\n [...Tail],\n [...TResult, GetOptions<Head>],\n [...TDepth, 1]\n >\n : ReadonlyArray<unknown> extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends Array<\n QueryObserverOptionsForCreateQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >\n >\n ? Array<\n QueryObserverOptionsForCreateQueries<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >\n >\n : // Fallback\n Array<QueryObserverOptionsForCreateQueries>\n\n/**\n * QueriesResults reducer recursively maps type param to results\n * @public\n */\nexport type QueriesResults<\n T extends Array<any>,\n TResult extends Array<any> = [],\n TDepth extends ReadonlyArray<number> = [],\n> = TDepth['length'] extends MAXIMUM_DEPTH\n ? Array<QueryObserverResult>\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...TResult, GetResults<Head>]\n : T extends [infer Head, ...infer Tail]\n ? QueriesResults<\n [...Tail],\n [...TResult, GetResults<Head>],\n [...TDepth, 1]\n >\n : T extends Array<\n QueryObserverOptionsForCreateQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n any\n >\n >\n ? // Dynamic-size (homogenous) CreateQueryOptions array: map directly to array of results\n Array<\n QueryObserverResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >\n >\n : // Fallback\n Array<QueryObserverResult>\n\n/**\n * @param root0\n * @param root0.queries\n * @param root0.combine\n * @param injector\n * @param injector\n * @public\n */\nexport function injectQueries<\n T extends Array<any>,\n TCombinedResult = QueriesResults<T>,\n>(\n {\n queries,\n ...options\n }: {\n queries: Signal<[...QueriesOptions<T>]>\n combine?: (result: QueriesResults<T>) => TCombinedResult\n },\n injector?: Injector,\n): Signal<TCombinedResult> {\n !injector && assertInInjectionContext(injectQueries)\n return runInInjectionContext(injector ?? inject(Injector), () => {\n const destroyRef = inject(DestroyRef)\n const ngZone = inject(NgZone)\n const queryClient = inject(QueryClient)\n const isRestoring = injectIsRestoring()\n\n const defaultedQueries = computed(() => {\n return queries().map((opts) => {\n const defaultedOptions = queryClient.defaultQueryOptions(opts)\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring()\n ? 'isRestoring'\n : 'optimistic'\n\n return defaultedOptions as QueryObserverOptions\n })\n })\n\n const observer = new QueriesObserver<TCombinedResult>(\n queryClient,\n defaultedQueries(),\n options as QueriesObserverOptions<TCombinedResult>,\n )\n\n // Do not notify on updates because of changes in the options because\n // these changes should already be reflected in the optimistic result.\n effect(() => {\n observer.setQueries(\n defaultedQueries(),\n options as QueriesObserverOptions<TCombinedResult>,\n )\n })\n\n const [, getCombinedResult] = observer.getOptimisticResult(\n defaultedQueries(),\n (options as QueriesObserverOptions<TCombinedResult>).combine,\n )\n\n const result = signal(getCombinedResult() as any)\n\n effect(() => {\n const unsubscribe = isRestoring()\n ? () => undefined\n : ngZone.runOutsideAngular(() =>\n observer.subscribe(notifyManager.batchCalls(result.set)),\n )\n destroyRef.onDestroy(unsubscribe)\n })\n\n return result\n })\n}\n"],"names":[],"mappings":";;;AA6MO,SAAS,cAId;AAAA,EACE;AAAA,EACA,GAAG;AACL,GAIA,UACyB;AACxB,GAAA,YAAY,yBAAyB,aAAa;AACnD,SAAO,sBAAsB,YAAY,OAAO,QAAQ,GAAG,MAAM;AACzD,UAAA,aAAa,OAAO,UAAU;AAC9B,UAAA,SAAS,OAAO,MAAM;AACtB,UAAA,cAAc,OAAO,WAAW;AACtC,UAAM,cAAc,kBAAkB;AAEhC,UAAA,mBAAmB,SAAS,MAAM;AACtC,aAAO,QAAQ,EAAE,IAAI,CAAC,SAAS;AACvB,cAAA,mBAAmB,YAAY,oBAAoB,IAAI;AAE5C,yBAAA,qBAAqB,YAAY,IAC9C,gBACA;AAEG,eAAA;AAAA,MAAA,CACR;AAAA,IAAA,CACF;AAED,UAAM,WAAW,IAAI;AAAA,MACnB;AAAA,MACA,iBAAiB;AAAA,MACjB;AAAA,IACF;AAIA,WAAO,MAAM;AACF,eAAA;AAAA,QACP,iBAAiB;AAAA,QACjB;AAAA,MACF;AAAA,IAAA,CACD;AAED,UAAM,CAAG,EAAA,iBAAiB,IAAI,SAAS;AAAA,MACrC,iBAAiB;AAAA,MAChB,QAAoD;AAAA,IACvD;AAEM,UAAA,SAAS,OAAO,mBAA0B;AAEhD,WAAO,MAAM;AACX,YAAM,cAAc,YAAA,IAChB,MAAM,SACN,OAAO;AAAA,QAAkB,MACvB,SAAS,UAAU,cAAc,WAAW,OAAO,GAAG,CAAC;AAAA,MACzD;AACJ,iBAAW,UAAU,WAAW;AAAA,IAAA,CACjC;AAEM,WAAA;AAAA,EAAA,CACR;AACH;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { inject, Injector } from "@angular/core";
|
|
2
|
-
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
-
function injectQueryClient(injectOptions = {}) {
|
|
4
|
-
return (injectOptions.injector ?? inject(Injector)).get(QueryClient);
|
|
5
|
-
}
|
|
6
|
-
export {
|
|
7
|
-
injectQueryClient
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=inject-query-client.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-query-client.mjs","sources":["../src/inject-query-client.ts"],"sourcesContent":["import { Injector, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport type { InjectOptions } from '@angular/core'\n\n/**\n * Injects a `QueryClient` instance and allows passing a custom injector.\n * @param injectOptions - Type of the options argument to inject and optionally a custom injector.\n * @returns The `QueryClient` instance.\n * @public\n * @deprecated Use `inject(QueryClient)` instead.\n * If you need to get a `QueryClient` from a custom injector, use `injector.get(QueryClient)`.\n *\n *\n * **Example**\n * ```ts\n * const queryClient = injectQueryClient();\n * ```\n */\nexport function injectQueryClient(\n injectOptions: InjectOptions & { injector?: Injector } = {},\n) {\n return (injectOptions.injector ?? inject(Injector)).get(QueryClient)\n}\n"],"names":[],"mappings":";;AAkBgB,SAAA,kBACd,gBAAyD,IACzD;AACA,UAAQ,cAAc,YAAY,OAAO,QAAQ,GAAG,IAAI,WAAW;AACrE;"}
|
package/dist/inject-query.mjs
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { QueryObserver } from "@tanstack/query-core";
|
|
2
|
-
import { assertInInjectionContext, runInInjectionContext, inject, Injector } from "@angular/core";
|
|
3
|
-
import { createBaseQuery } from "./create-base-query.mjs";
|
|
4
|
-
function injectQuery(injectQueryFn, options) {
|
|
5
|
-
!(options == null ? void 0 : options.injector) && assertInInjectionContext(injectQuery);
|
|
6
|
-
return runInInjectionContext(
|
|
7
|
-
(options == null ? void 0 : options.injector) ?? inject(Injector),
|
|
8
|
-
() => createBaseQuery(injectQueryFn, QueryObserver)
|
|
9
|
-
);
|
|
10
|
-
}
|
|
11
|
-
export {
|
|
12
|
-
injectQuery
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=inject-query.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"inject-query.mjs","sources":["../src/inject-query.ts"],"sourcesContent":["import { QueryObserver } 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 { DefaultError, QueryKey } from '@tanstack/query-core'\nimport type {\n CreateQueryOptions,\n CreateQueryResult,\n DefinedCreateQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataOptions,\n UndefinedInitialDataOptions,\n} from './query-options'\n\nexport interface InjectQueryOptions {\n /**\n * The `Injector` in which to create the 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 a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n *\n * **Basic example**\n * ```ts\n * class ServiceOrComponent {\n * query = injectQuery(() => ({\n * queryKey: ['repoData'],\n * queryFn: () =>\n * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),\n * }))\n * }\n * ```\n *\n * Similar to `computed` from Angular, the function passed to `injectQuery` will be run in the reactive context.\n * In the example below, the query will be automatically enabled and executed when the filter signal changes\n * to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.\n *\n * **Reactive example**\n * ```ts\n * class ServiceOrComponent {\n * filter = signal('')\n *\n * todosQuery = injectQuery(() => ({\n * queryKey: ['todos', this.filter()],\n * queryFn: () => fetchTodos(this.filter()),\n * // Signals can be combined with expressions\n * enabled: !!this.filter(),\n * }))\n * }\n * ```\n * @param injectQueryFn - A function that returns query options.\n * @param options - Additional configuration\n * @returns The query result.\n * @public\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries\n */\nexport function injectQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n injectQueryFn: () => DefinedInitialDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n options?: InjectQueryOptions,\n): DefinedCreateQueryResult<TData, TError>\n\n/**\n * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n *\n * **Basic example**\n * ```ts\n * class ServiceOrComponent {\n * query = injectQuery(() => ({\n * queryKey: ['repoData'],\n * queryFn: () =>\n * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),\n * }))\n * }\n * ```\n *\n * Similar to `computed` from Angular, the function passed to `injectQuery` will be run in the reactive context.\n * In the example below, the query will be automatically enabled and executed when the filter signal changes\n * to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.\n *\n * **Reactive example**\n * ```ts\n * class ServiceOrComponent {\n * filter = signal('')\n *\n * todosQuery = injectQuery(() => ({\n * queryKey: ['todos', this.filter()],\n * queryFn: () => fetchTodos(this.filter()),\n * // Signals can be combined with expressions\n * enabled: !!this.filter(),\n * }))\n * }\n * ```\n * @param injectQueryFn - A function that returns query options.\n * @param options - Additional configuration\n * @returns The query result.\n * @public\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries\n */\nexport function injectQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n injectQueryFn: () => UndefinedInitialDataOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n options?: InjectQueryOptions,\n): CreateQueryResult<TData, TError>\n\n/**\n * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n *\n * **Basic example**\n * ```ts\n * class ServiceOrComponent {\n * query = injectQuery(() => ({\n * queryKey: ['repoData'],\n * queryFn: () =>\n * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),\n * }))\n * }\n * ```\n *\n * Similar to `computed` from Angular, the function passed to `injectQuery` will be run in the reactive context.\n * In the example below, the query will be automatically enabled and executed when the filter signal changes\n * to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.\n *\n * **Reactive example**\n * ```ts\n * class ServiceOrComponent {\n * filter = signal('')\n *\n * todosQuery = injectQuery(() => ({\n * queryKey: ['todos', this.filter()],\n * queryFn: () => fetchTodos(this.filter()),\n * // Signals can be combined with expressions\n * enabled: !!this.filter(),\n * }))\n * }\n * ```\n * @param injectQueryFn - A function that returns query options.\n * @param options - Additional configuration\n * @returns The query result.\n * @public\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries\n */\nexport function injectQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n injectQueryFn: () => CreateQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey\n >,\n options?: InjectQueryOptions,\n): CreateQueryResult<TData, TError>\n\n/**\n * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n *\n * **Basic example**\n * ```ts\n * class ServiceOrComponent {\n * query = injectQuery(() => ({\n * queryKey: ['repoData'],\n * queryFn: () =>\n * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),\n * }))\n * }\n * ```\n *\n * Similar to `computed` from Angular, the function passed to `injectQuery` will be run in the reactive context.\n * In the example below, the query will be automatically enabled and executed when the filter signal changes\n * to a truthy value. When the filter signal changes back to a falsy value, the query will be disabled.\n *\n * **Reactive example**\n * ```ts\n * class ServiceOrComponent {\n * filter = signal('')\n *\n * todosQuery = injectQuery(() => ({\n * queryKey: ['todos', this.filter()],\n * queryFn: () => fetchTodos(this.filter()),\n * // Signals can be combined with expressions\n * enabled: !!this.filter(),\n * }))\n * }\n * ```\n * @param injectQueryFn - A function that returns query options.\n * @param options - Additional configuration\n * @returns The query result.\n * @public\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries\n */\nexport function injectQuery(\n injectQueryFn: () => CreateQueryOptions,\n options?: InjectQueryOptions,\n) {\n !options?.injector && assertInInjectionContext(injectQuery)\n return runInInjectionContext(options?.injector ?? inject(Injector), () =>\n createBaseQuery(injectQueryFn, QueryObserver),\n ) as unknown as CreateQueryResult\n}\n"],"names":[],"mappings":";;;AA6NgB,SAAA,YACd,eACA,SACA;AACC,IAAA,mCAAS,aAAY,yBAAyB,WAAW;AACnD,SAAA;AAAA,KAAsB,mCAAS,aAAY,OAAO,QAAQ;AAAA,IAAG,MAClE,gBAAgB,eAAe,aAAa;AAAA,EAC9C;AACF;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mutation-options.mjs","sources":["../src/mutation-options.ts"],"sourcesContent":["import type {\n DefaultError,\n MutationObserverOptions,\n OmitKeyof,\n} from '@tanstack/query-core'\n\n/**\n * Allows to share and re-use mutation options in a type-safe way.\n *\n * **Example**\n *\n * ```ts\n * export class QueriesService {\n * private http = inject(HttpClient);\n *\n * updatePost(id: number) {\n * return mutationOptions({\n * mutationFn: (post: Post) => Promise.resolve(post),\n * mutationKey: [\"updatePost\", id],\n * onSuccess: (newPost) => {\n * // ^? newPost: Post\n * this.queryClient.setQueryData([\"posts\", id], newPost);\n * },\n * });\n * }\n * }\n *\n * queries = inject(QueriesService)\n * idSignal = new Signal(0);\n * mutation = injectMutation(() => this.queries.updatePost(this.idSignal()))\n *\n * mutation.mutate({ title: 'New Title' })\n * ```\n * @param options - The mutation options.\n * @returns Mutation options.\n * @public\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: MutationObserverOptions<TData, TError, TVariables, TContext>,\n): CreateMutationOptions<TData, TError, TVariables, TContext> {\n return options\n}\n\n/**\n * @public\n */\nexport interface CreateMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> extends OmitKeyof<\n MutationObserverOptions<TData, TError, TVariables, TContext>,\n '_defaulted'\n > {}\n"],"names":[],"mappings":"AAqCO,SAAS,gBAMd,SAC4D;AACrD,SAAA;AACT;"}
|
package/dist/providers.mjs
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { InjectionToken, inject, DestroyRef, isDevMode, ENVIRONMENT_INITIALIZER, PLATFORM_ID, computed, effect } from "@angular/core";
|
|
2
|
-
import { QueryClient, noop, onlineManager } from "@tanstack/query-core";
|
|
3
|
-
import { isPlatformBrowser } from "@angular/common";
|
|
4
|
-
function provideQueryClient(queryClient) {
|
|
5
|
-
return {
|
|
6
|
-
provide: QueryClient,
|
|
7
|
-
useFactory: () => {
|
|
8
|
-
const client = queryClient instanceof InjectionToken ? inject(queryClient) : queryClient;
|
|
9
|
-
inject(DestroyRef).onDestroy(() => client.unmount());
|
|
10
|
-
client.mount();
|
|
11
|
-
return client;
|
|
12
|
-
}
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
function provideTanStackQuery(queryClient, ...features) {
|
|
16
|
-
return [
|
|
17
|
-
provideQueryClient(queryClient),
|
|
18
|
-
features.map((feature) => feature.ɵproviders)
|
|
19
|
-
];
|
|
20
|
-
}
|
|
21
|
-
function queryFeature(kind, providers) {
|
|
22
|
-
return { ɵkind: kind, ɵproviders: providers };
|
|
23
|
-
}
|
|
24
|
-
function withDevtools(withDevtoolsFn) {
|
|
25
|
-
let providers = [];
|
|
26
|
-
if (!isDevMode() && !withDevtoolsFn) {
|
|
27
|
-
providers = [];
|
|
28
|
-
} else {
|
|
29
|
-
providers = [
|
|
30
|
-
{
|
|
31
|
-
// Do not use provideEnvironmentInitializer while Angular < v19 is supported
|
|
32
|
-
provide: ENVIRONMENT_INITIALIZER,
|
|
33
|
-
multi: true,
|
|
34
|
-
useFactory: () => {
|
|
35
|
-
if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop;
|
|
36
|
-
const injectedClient = inject(QueryClient, {
|
|
37
|
-
optional: true
|
|
38
|
-
});
|
|
39
|
-
const destroyRef = inject(DestroyRef);
|
|
40
|
-
const options = computed(() => (withDevtoolsFn == null ? void 0 : withDevtoolsFn()) ?? {});
|
|
41
|
-
let devtools = null;
|
|
42
|
-
let el = null;
|
|
43
|
-
const shouldLoadToolsSignal = computed(() => {
|
|
44
|
-
const { loadDevtools } = options();
|
|
45
|
-
return typeof loadDevtools === "boolean" ? loadDevtools : isDevMode();
|
|
46
|
-
});
|
|
47
|
-
const getResolvedQueryClient = () => {
|
|
48
|
-
const client = options().client ?? injectedClient;
|
|
49
|
-
if (!client) {
|
|
50
|
-
throw new Error("No QueryClient found");
|
|
51
|
-
}
|
|
52
|
-
return client;
|
|
53
|
-
};
|
|
54
|
-
const destroyDevtools = () => {
|
|
55
|
-
devtools == null ? void 0 : devtools.unmount();
|
|
56
|
-
el == null ? void 0 : el.remove();
|
|
57
|
-
devtools = null;
|
|
58
|
-
};
|
|
59
|
-
return () => effect(() => {
|
|
60
|
-
const shouldLoadTools = shouldLoadToolsSignal();
|
|
61
|
-
const {
|
|
62
|
-
client,
|
|
63
|
-
position,
|
|
64
|
-
errorTypes,
|
|
65
|
-
buttonPosition,
|
|
66
|
-
initialIsOpen
|
|
67
|
-
} = options();
|
|
68
|
-
if (devtools && !shouldLoadTools) {
|
|
69
|
-
destroyDevtools();
|
|
70
|
-
return;
|
|
71
|
-
} else if (devtools && shouldLoadTools) {
|
|
72
|
-
client && devtools.setClient(client);
|
|
73
|
-
position && devtools.setPosition(position);
|
|
74
|
-
errorTypes && devtools.setErrorTypes(errorTypes);
|
|
75
|
-
buttonPosition && devtools.setButtonPosition(buttonPosition);
|
|
76
|
-
initialIsOpen && devtools.setInitialIsOpen(initialIsOpen);
|
|
77
|
-
return;
|
|
78
|
-
} else if (!shouldLoadTools) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
el = document.body.appendChild(document.createElement("div"));
|
|
82
|
-
el.classList.add("tsqd-parent-container");
|
|
83
|
-
import("@tanstack/query-devtools").then((queryDevtools) => {
|
|
84
|
-
devtools = new queryDevtools.TanstackQueryDevtools({
|
|
85
|
-
...options(),
|
|
86
|
-
client: getResolvedQueryClient(),
|
|
87
|
-
queryFlavor: "Angular Query",
|
|
88
|
-
version: "5",
|
|
89
|
-
onlineManager
|
|
90
|
-
});
|
|
91
|
-
el && devtools.mount(el);
|
|
92
|
-
destroyRef.onDestroy(destroyDevtools);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
];
|
|
98
|
-
}
|
|
99
|
-
return queryFeature("DeveloperTools", providers);
|
|
100
|
-
}
|
|
101
|
-
const queryFeatures = ["DeveloperTools", "PersistQueryClient"];
|
|
102
|
-
export {
|
|
103
|
-
provideQueryClient,
|
|
104
|
-
provideTanStackQuery,
|
|
105
|
-
queryFeature,
|
|
106
|
-
queryFeatures,
|
|
107
|
-
withDevtools
|
|
108
|
-
};
|
|
109
|
-
//# sourceMappingURL=providers.mjs.map
|
package/dist/providers.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"providers.mjs","sources":["../src/providers.ts"],"sourcesContent":["import {\n DestroyRef,\n ENVIRONMENT_INITIALIZER,\n InjectionToken,\n PLATFORM_ID,\n computed,\n effect,\n inject,\n} from '@angular/core'\nimport { QueryClient, noop, onlineManager } from '@tanstack/query-core'\nimport { isPlatformBrowser } from '@angular/common'\nimport { isDevMode } from './util/is-dev-mode/is-dev-mode'\nimport type { Provider } from '@angular/core'\nimport type {\n DevtoolsButtonPosition,\n DevtoolsErrorType,\n DevtoolsPosition,\n TanstackQueryDevtools,\n} from '@tanstack/query-devtools'\n\n/**\n * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the\n * {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient}\n * for the entire application. Internally it calls `provideQueryClient`.\n * You can use `provideQueryClient` to provide a different `QueryClient` instance for a part\n * of the application or for unit testing purposes.\n * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.\n * @returns a provider object that can be used to provide the `QueryClient` instance.\n */\nexport function provideQueryClient(\n queryClient: QueryClient | InjectionToken<QueryClient>,\n): Provider {\n return {\n provide: QueryClient,\n useFactory: () => {\n const client =\n queryClient instanceof InjectionToken\n ? inject(queryClient)\n : queryClient\n // Unmount the query client on injector destroy\n inject(DestroyRef).onDestroy(() => client.unmount())\n client.mount()\n return client\n },\n }\n}\n\n/**\n * Sets up providers necessary to enable TanStack Query functionality for Angular applications.\n *\n * Allows to configure a `QueryClient` and optional features such as developer tools.\n *\n * **Example - standalone**\n *\n * ```ts\n * import {\n * provideTanStackQuery,\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(new QueryClient())],\n * })\n * ```\n *\n * **Example - NgModule-based**\n *\n * ```ts\n * import {\n * provideTanStackQuery,\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * @NgModule({\n * declarations: [AppComponent],\n * imports: [BrowserModule],\n * providers: [provideTanStackQuery(new QueryClient())],\n * bootstrap: [AppComponent],\n * })\n * export class AppModule {}\n * ```\n *\n * You can also enable optional developer tools by adding `withDevtools`. By\n * default the tools will then be loaded when your app is in development mode.\n * ```ts\n * import {\n * provideTanStackQuery,\n * withDevtools\n * QueryClient,\n * } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent,\n * {\n * providers: [\n * provideTanStackQuery(new QueryClient(), withDevtools())\n * ]\n * }\n * )\n * ```\n *\n * **Example: using an InjectionToken**\n *\n * ```ts\n * export const MY_QUERY_CLIENT = new InjectionToken('', {\n * factory: () => new QueryClient(),\n * })\n *\n * // In a lazy loaded route or lazy loaded component's providers array:\n * providers: [provideTanStackQuery(MY_QUERY_CLIENT)]\n * ```\n * @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.\n * @param features - Optional features to configure additional Query functionality.\n * @returns A set of providers to set up TanStack Query.\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @see withDevtools\n */\nexport function provideTanStackQuery(\n queryClient: QueryClient | InjectionToken<QueryClient>,\n ...features: Array<QueryFeatures>\n): Array<Provider> {\n return [\n provideQueryClient(queryClient),\n features.map((feature) => feature.ɵproviders),\n ]\n}\n\n/**\n * Sets up providers necessary to enable TanStack Query functionality for Angular applications.\n *\n * Allows to configure a `QueryClient`.\n * @param queryClient - A `QueryClient` instance.\n * @returns A set of providers to set up TanStack Query.\n * @public\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @deprecated Use `provideTanStackQuery` instead.\n */\nexport function provideAngularQuery(queryClient: QueryClient): Array<Provider> {\n return provideTanStackQuery(queryClient)\n}\n\n/**\n * Helper type to represent a Query feature.\n */\nexport interface QueryFeature<TFeatureKind extends QueryFeatureKind> {\n ɵkind: TFeatureKind\n ɵproviders: Array<Provider>\n}\n\n/**\n * Helper function to create an object that represents a Query feature.\n * @param kind -\n * @param providers -\n * @returns A Query feature.\n */\nexport function queryFeature<TFeatureKind extends QueryFeatureKind>(\n kind: TFeatureKind,\n providers: Array<Provider>,\n): QueryFeature<TFeatureKind> {\n return { ɵkind: kind, ɵproviders: providers }\n}\n\n/**\n * A type alias that represents a feature which enables developer tools.\n * The type is used to describe the return value of the `withDevtools` function.\n * @public\n * @see {@link withDevtools}\n */\nexport type DeveloperToolsFeature = QueryFeature<'DeveloperTools'>\n\n/**\n * A type alias that represents a feature which enables persistence.\n * The type is used to describe the return value of the `withPersistQueryClient` function.\n * @public\n */\nexport type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>\n\n/**\n * Options for configuring the TanStack Query devtools.\n * @public\n */\nexport interface DevtoolsOptions {\n /**\n * Set this true if you want the devtools to default to being open\n */\n initialIsOpen?: boolean\n /**\n * The position of the TanStack logo to open and close the devtools panel.\n * `top-left` | `top-right` | `bottom-left` | `bottom-right` | `relative`\n * Defaults to `bottom-right`.\n */\n buttonPosition?: DevtoolsButtonPosition\n /**\n * The position of the TanStack Query devtools panel.\n * `top` | `bottom` | `left` | `right`\n * Defaults to `bottom`.\n */\n position?: DevtoolsPosition\n /**\n * Custom instance of QueryClient\n */\n client?: QueryClient\n /**\n * Use this so you can define custom errors that can be shown in the devtools.\n */\n errorTypes?: Array<DevtoolsErrorType>\n /**\n * Use this to pass a nonce to the style tag that is added to the document head. This is useful if you are using a Content Security Policy (CSP) nonce to allow inline styles.\n */\n styleNonce?: string\n /**\n * Use this so you can attach the devtool's styles to a specific element in the DOM.\n */\n shadowDOMTarget?: ShadowRoot\n\n /**\n * Whether the developer tools should load.\n * - `auto`- (Default) Lazily loads devtools when in development mode. Skips loading in production mode.\n * - `true`- Always load the devtools, regardless of the environment.\n * - `false`- Never load the devtools, regardless of the environment.\n *\n * You can use `true` and `false` to override loading developer tools from an environment file.\n * For example, a test environment might run in production mode but you may want to load developer tools.\n *\n * Additionally, you can use a signal in the callback to dynamically load the devtools based on a condition. For example,\n * a signal created from a RxJS observable that listens for a keyboard shortcut.\n *\n * **Example**\n * ```ts\n * withDevtools(() => ({\n * initialIsOpen: true,\n * loadDevtools: inject(ExampleService).loadDevtools()\n * }))\n * ```\n */\n loadDevtools?: 'auto' | boolean\n}\n\n/**\n * Enables developer tools.\n *\n * **Example**\n *\n * ```ts\n * export const appConfig: ApplicationConfig = {\n * providers: [\n * provideTanStackQuery(new QueryClient(), withDevtools())\n * ]\n * }\n * ```\n * By default the devtools will be loaded when Angular runs in development mode and rendered in `<body>`.\n *\n * If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available.\n *\n * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.\n * @param withDevtoolsFn - A function that returns `DevtoolsOptions`.\n * @returns A set of providers for use with `provideTanStackQuery`.\n * @public\n * @see {@link provideTanStackQuery}\n * @see {@link DevtoolsOptions}\n */\nexport function withDevtools(\n withDevtoolsFn?: () => DevtoolsOptions,\n): DeveloperToolsFeature {\n let providers: Array<Provider> = []\n if (!isDevMode() && !withDevtoolsFn) {\n providers = []\n } else {\n providers = [\n {\n // Do not use provideEnvironmentInitializer while Angular < v19 is supported\n provide: ENVIRONMENT_INITIALIZER,\n multi: true,\n useFactory: () => {\n if (!isPlatformBrowser(inject(PLATFORM_ID))) return noop\n const injectedClient = inject(QueryClient, {\n optional: true,\n })\n const destroyRef = inject(DestroyRef)\n\n const options = computed(() => withDevtoolsFn?.() ?? {})\n\n let devtools: TanstackQueryDevtools | null = null\n let el: HTMLElement | null = null\n\n const shouldLoadToolsSignal = computed(() => {\n const { loadDevtools } = options()\n return typeof loadDevtools === 'boolean'\n ? loadDevtools\n : isDevMode()\n })\n\n const getResolvedQueryClient = () => {\n const client = options().client ?? injectedClient\n if (!client) {\n throw new Error('No QueryClient found')\n }\n return client\n }\n\n const destroyDevtools = () => {\n devtools?.unmount()\n el?.remove()\n devtools = null\n }\n\n return () =>\n effect(() => {\n const shouldLoadTools = shouldLoadToolsSignal()\n const {\n client,\n position,\n errorTypes,\n buttonPosition,\n initialIsOpen,\n } = options()\n\n if (devtools && !shouldLoadTools) {\n destroyDevtools()\n return\n } else if (devtools && shouldLoadTools) {\n client && devtools.setClient(client)\n position && devtools.setPosition(position)\n errorTypes && devtools.setErrorTypes(errorTypes)\n buttonPosition && devtools.setButtonPosition(buttonPosition)\n initialIsOpen && devtools.setInitialIsOpen(initialIsOpen)\n return\n } else if (!shouldLoadTools) {\n return\n }\n\n el = document.body.appendChild(document.createElement('div'))\n el.classList.add('tsqd-parent-container')\n\n import('@tanstack/query-devtools').then((queryDevtools) => {\n devtools = new queryDevtools.TanstackQueryDevtools({\n ...options(),\n client: getResolvedQueryClient(),\n queryFlavor: 'Angular Query',\n version: '5',\n onlineManager,\n })\n\n el && devtools.mount(el)\n\n // Unmount the devtools on application destroy\n destroyRef.onDestroy(destroyDevtools)\n })\n })\n },\n },\n ]\n }\n return queryFeature('DeveloperTools', providers)\n}\n\n/**\n * A type alias that represents all Query features available for use with `provideTanStackQuery`.\n * Features can be enabled by adding special functions to the `provideTanStackQuery` call.\n * See documentation for each symbol to find corresponding function name. See also `provideTanStackQuery`\n * documentation on how to use those functions.\n * @public\n * @see {@link provideTanStackQuery}\n */\nexport type QueryFeatures = DeveloperToolsFeature | PersistQueryClientFeature\n\nexport const queryFeatures = ['DeveloperTools', 'PersistQueryClient'] as const\n\nexport type QueryFeatureKind = (typeof queryFeatures)[number]\n"],"names":[],"mappings":";;;AA6BO,SAAS,mBACd,aACU;AACH,SAAA;AAAA,IACL,SAAS;AAAA,IACT,YAAY,MAAM;AAChB,YAAM,SACJ,uBAAuB,iBACnB,OAAO,WAAW,IAClB;AAEN,aAAO,UAAU,EAAE,UAAU,MAAM,OAAO,SAAS;AACnD,aAAO,MAAM;AACN,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;AAuEgB,SAAA,qBACd,gBACG,UACc;AACV,SAAA;AAAA,IACL,mBAAmB,WAAW;AAAA,IAC9B,SAAS,IAAI,CAAC,YAAY,QAAQ,UAAU;AAAA,EAC9C;AACF;AA8BgB,SAAA,aACd,MACA,WAC4B;AAC5B,SAAO,EAAE,OAAO,MAAM,YAAY,UAAU;AAC9C;AAqGO,SAAS,aACd,gBACuB;AACvB,MAAI,YAA6B,CAAC;AAClC,MAAI,CAAC,eAAe,CAAC,gBAAgB;AACnC,gBAAY,CAAC;AAAA,EAAA,OACR;AACO,gBAAA;AAAA,MACV;AAAA;AAAA,QAEE,SAAS;AAAA,QACT,OAAO;AAAA,QACP,YAAY,MAAM;AAChB,cAAI,CAAC,kBAAkB,OAAO,WAAW,CAAC,EAAU,QAAA;AAC9C,gBAAA,iBAAiB,OAAO,aAAa;AAAA,YACzC,UAAU;AAAA,UAAA,CACX;AACK,gBAAA,aAAa,OAAO,UAAU;AAEpC,gBAAM,UAAU,SAAS,OAAM,uDAAsB,CAAA,CAAE;AAEvD,cAAI,WAAyC;AAC7C,cAAI,KAAyB;AAEvB,gBAAA,wBAAwB,SAAS,MAAM;AACrC,kBAAA,EAAE,aAAa,IAAI,QAAQ;AACjC,mBAAO,OAAO,iBAAiB,YAC3B,eACA,UAAU;AAAA,UAAA,CACf;AAED,gBAAM,yBAAyB,MAAM;AAC7B,kBAAA,SAAS,UAAU,UAAU;AACnC,gBAAI,CAAC,QAAQ;AACL,oBAAA,IAAI,MAAM,sBAAsB;AAAA,YAAA;AAEjC,mBAAA;AAAA,UACT;AAEA,gBAAM,kBAAkB,MAAM;AAC5B,iDAAU;AACV,qCAAI;AACO,uBAAA;AAAA,UACb;AAEO,iBAAA,MACL,OAAO,MAAM;AACX,kBAAM,kBAAkB,sBAAsB;AACxC,kBAAA;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,cACA;AAAA,gBACE,QAAQ;AAER,gBAAA,YAAY,CAAC,iBAAiB;AAChB,8BAAA;AAChB;AAAA,YAAA,WACS,YAAY,iBAAiB;AAC5B,wBAAA,SAAS,UAAU,MAAM;AACvB,0BAAA,SAAS,YAAY,QAAQ;AAC3B,4BAAA,SAAS,cAAc,UAAU;AAC7B,gCAAA,SAAS,kBAAkB,cAAc;AAC1C,+BAAA,SAAS,iBAAiB,aAAa;AACxD;AAAA,YAAA,WACS,CAAC,iBAAiB;AAC3B;AAAA,YAAA;AAGF,iBAAK,SAAS,KAAK,YAAY,SAAS,cAAc,KAAK,CAAC;AACzD,eAAA,UAAU,IAAI,uBAAuB;AAExC,mBAAO,0BAA0B,EAAE,KAAK,CAAC,kBAAkB;AAC9C,yBAAA,IAAI,cAAc,sBAAsB;AAAA,gBACjD,GAAG,QAAQ;AAAA,gBACX,QAAQ,uBAAuB;AAAA,gBAC/B,aAAa;AAAA,gBACb,SAAS;AAAA,gBACT;AAAA,cAAA,CACD;AAEK,oBAAA,SAAS,MAAM,EAAE;AAGvB,yBAAW,UAAU,eAAe;AAAA,YAAA,CACrC;AAAA,UAAA,CACF;AAAA,QAAA;AAAA,MACL;AAAA,IAEJ;AAAA,EAAA;AAEK,SAAA,aAAa,kBAAkB,SAAS;AACjD;AAYa,MAAA,gBAAgB,CAAC,kBAAkB,oBAAoB;"}
|
package/dist/query-options.mjs
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-options.mjs","sources":["../src/query-options.ts"],"sourcesContent":["import type {\n DataTag,\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateQueryOptions } from './types'\n\nexport type UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\nexport type UnusedSkipTokenOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = OmitKeyof<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryFn'\n> & {\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n * @public\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {\n queryKey: DataTag<TQueryKey, TQueryFnData, TError>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n * @public\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & {\n queryKey: DataTag<TQueryKey, TQueryFnData, TError>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n * @public\n */\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {\n queryKey: DataTag<TQueryKey, TQueryFnData, TError>\n}\n\n/**\n * Allows to share and re-use query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n *\n * **Example**\n *\n * ```ts\n * const { queryKey } = queryOptions({\n * queryKey: ['key'],\n * queryFn: () => Promise.resolve(5),\n * // ^? Promise<number>\n * })\n *\n * const queryClient = new QueryClient()\n * const data = queryClient.getQueryData(queryKey)\n * // ^? number | undefined\n * ```\n * @param options - The query options to tag with the type from `queryFn`.\n * @returns The tagged query options.\n * @public\n */\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AA+KO,SAAS,aAAa,SAAkB;AACtC,SAAA;AACT;"}
|
package/dist/signal-proxy.mjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { untracked, computed } from "@angular/core";
|
|
2
|
-
function signalProxy(inputSignal) {
|
|
3
|
-
const internalState = {};
|
|
4
|
-
return new Proxy(internalState, {
|
|
5
|
-
get(target, prop) {
|
|
6
|
-
const computedField = target[prop];
|
|
7
|
-
if (computedField) return computedField;
|
|
8
|
-
const targetField = untracked(inputSignal)[prop];
|
|
9
|
-
if (typeof targetField === "function") return targetField;
|
|
10
|
-
return target[prop] = computed(() => inputSignal()[prop]);
|
|
11
|
-
},
|
|
12
|
-
has(_, prop) {
|
|
13
|
-
return !!untracked(inputSignal)[prop];
|
|
14
|
-
},
|
|
15
|
-
ownKeys() {
|
|
16
|
-
return Reflect.ownKeys(untracked(inputSignal));
|
|
17
|
-
},
|
|
18
|
-
getOwnPropertyDescriptor() {
|
|
19
|
-
return {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
configurable: true
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export {
|
|
27
|
-
signalProxy
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=signal-proxy.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signal-proxy.mjs","sources":["../src/signal-proxy.ts"],"sourcesContent":["import { computed, untracked } from '@angular/core'\nimport type { Signal } from '@angular/core'\n\nexport type MapToSignals<T> = {\n [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>\n}\n\n/**\n * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.\n * Functions on the object are passed through as-is.\n * @param inputSignal - `Signal` that must return an object.\n * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.\n */\nexport function signalProxy<TInput extends Record<string | symbol, any>>(\n inputSignal: Signal<TInput>,\n) {\n const internalState = {} as MapToSignals<TInput>\n\n return new Proxy<MapToSignals<TInput>>(internalState, {\n get(target, prop) {\n // first check if we have it in our internal state and return it\n const computedField = target[prop]\n if (computedField) return computedField\n\n // then, check if it's a function on the resultState and return it\n const targetField = untracked(inputSignal)[prop]\n if (typeof targetField === 'function') return targetField\n\n // finally, create a computed field, store it and return it\n // @ts-expect-error\n return (target[prop] = computed(() => inputSignal()[prop]))\n },\n has(_, prop) {\n return !!untracked(inputSignal)[prop]\n },\n ownKeys() {\n return Reflect.ownKeys(untracked(inputSignal))\n },\n getOwnPropertyDescriptor() {\n return {\n enumerable: true,\n configurable: true,\n }\n },\n })\n}\n"],"names":[],"mappings":";AAaO,SAAS,YACd,aACA;AACA,QAAM,gBAAgB,CAAC;AAEhB,SAAA,IAAI,MAA4B,eAAe;AAAA,IACpD,IAAI,QAAQ,MAAM;AAEV,YAAA,gBAAgB,OAAO,IAAI;AACjC,UAAI,cAAsB,QAAA;AAG1B,YAAM,cAAc,UAAU,WAAW,EAAE,IAAI;AAC3C,UAAA,OAAO,gBAAgB,WAAmB,QAAA;AAItC,aAAA,OAAO,IAAI,IAAI,SAAS,MAAM,YAAY,EAAE,IAAI,CAAC;AAAA,IAC3D;AAAA,IACA,IAAI,GAAG,MAAM;AACX,aAAO,CAAC,CAAC,UAAU,WAAW,EAAE,IAAI;AAAA,IACtC;AAAA,IACA,UAAU;AACR,aAAO,QAAQ,QAAQ,UAAU,WAAW,CAAC;AAAA,IAC/C;AAAA,IACA,2BAA2B;AAClB,aAAA;AAAA,QACL,YAAY;AAAA,QACZ,cAAc;AAAA,MAChB;AAAA,IAAA;AAAA,EACF,CACD;AACH;"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import type { InputSignal, Signal } from '@angular/core';
|
|
2
|
-
import type { ComponentFixture } from '@angular/core/testing';
|
|
3
|
-
export declare const expectSignals: <T extends Record<string, any>>(obj: T, expected: Partial<{ [K in keyof T]: T[K] extends Signal<any> ? ReturnType<T[K]> : never; }>) => void;
|
|
4
|
-
type ToSignalInputUpdatableMap<T> = {
|
|
5
|
-
[K in keyof T as T[K] extends InputSignal<any> ? K : never]: T[K] extends InputSignal<infer Value> ? Value : never;
|
|
6
|
-
};
|
|
7
|
-
/**
|
|
8
|
-
* Set required signal input value to component fixture
|
|
9
|
-
* @see https://github.com/angular/angular/issues/54013
|
|
10
|
-
*/
|
|
11
|
-
export declare function setSignalInputs<T extends NonNullable<unknown>>(component: T, inputs: ToSignalInputUpdatableMap<T>): void;
|
|
12
|
-
export declare function setFixtureSignalInputs<T extends NonNullable<unknown>>(componentFixture: ComponentFixture<T>, inputs: ToSignalInputUpdatableMap<T>, options?: {
|
|
13
|
-
detectChanges: boolean;
|
|
14
|
-
}): void;
|
|
15
|
-
export {};
|
|
16
|
-
//# sourceMappingURL=test-utils.d.ts.map
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { QueryKey, QueryObserver, QueryObserverResult } from '@tanstack/query-core';
|
|
2
|
-
import type { CreateBaseQueryOptions } from './types';
|
|
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").MapToSignals<QueryObserverResult<TData, TError>>;
|
|
9
|
-
//# sourceMappingURL=create-base-query.d.ts.map
|
package/dist-ts/src/index.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export * from './types';
|
|
3
|
-
export type { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, } from './query-options';
|
|
4
|
-
export { queryOptions } from './query-options';
|
|
5
|
-
export type { CreateMutationOptions } from './mutation-options';
|
|
6
|
-
export { mutationOptions } from './mutation-options';
|
|
7
|
-
export type { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions, UnusedSkipTokenInfiniteOptions, } from './infinite-query-options';
|
|
8
|
-
export { infiniteQueryOptions } from './infinite-query-options';
|
|
9
|
-
export type { InjectInfiniteQueryOptions } from './inject-infinite-query';
|
|
10
|
-
export { injectInfiniteQuery } from './inject-infinite-query';
|
|
11
|
-
export type { InjectIsFetchingOptions } from './inject-is-fetching';
|
|
12
|
-
export { injectIsFetching } from './inject-is-fetching';
|
|
13
|
-
export type { InjectIsMutatingOptions } from './inject-is-mutating';
|
|
14
|
-
export { injectIsMutating } from './inject-is-mutating';
|
|
15
|
-
export { injectIsRestoring, provideIsRestoring } from './inject-is-restoring';
|
|
16
|
-
export type { InjectMutationOptions } from './inject-mutation';
|
|
17
|
-
export { injectMutation } from './inject-mutation';
|
|
18
|
-
export type { InjectMutationStateOptions } from './inject-mutation-state';
|
|
19
|
-
export { injectMutationState } from './inject-mutation-state';
|
|
20
|
-
export type { QueriesOptions, QueriesResults } from './inject-queries';
|
|
21
|
-
export { injectQueries } from './inject-queries';
|
|
22
|
-
export type { InjectQueryOptions } from './inject-query';
|
|
23
|
-
export { injectQuery } from './inject-query';
|
|
24
|
-
export { injectQueryClient } from './inject-query-client';
|
|
25
|
-
export type { DeveloperToolsFeature, DevtoolsOptions, PersistQueryClientFeature, QueryFeature, QueryFeatureKind, QueryFeatures, } from './providers';
|
|
26
|
-
export { provideQueryClient, provideTanStackQuery, queryFeature, queryFeatures, withDevtools, } from './providers';
|
|
27
|
-
//# sourceMappingURL=index.d.ts.map
|