@tanstack/angular-query-experimental 5.103.1 → 5.103.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/create-base-query.d.mts +169 -0
- package/dist/create-base-query.d.mts.map +1 -0
- package/dist/create-base-query.mjs +91 -0
- package/dist/create-base-query.mjs.map +1 -0
- package/dist/devtools/index.d.mts +3 -0
- package/dist/devtools/index.mjs +2 -0
- package/dist/devtools/production/index.d.mts +4 -0
- package/dist/devtools/production/index.mjs +2 -0
- package/dist/devtools/stub.d.mts +6 -0
- package/dist/devtools/stub.d.mts.map +1 -0
- package/dist/devtools/stub.mjs +9 -0
- package/dist/devtools/stub.mjs.map +1 -0
- package/dist/devtools/types.d.mts +107 -0
- package/dist/devtools/types.d.mts.map +1 -0
- package/dist/devtools/types.mjs +1 -0
- package/{devtools/with-devtools.d.ts → dist/devtools/with-devtools.d.mts} +6 -2
- package/dist/devtools/with-devtools.d.mts.map +1 -0
- package/dist/devtools/with-devtools.mjs +110 -0
- package/dist/devtools/with-devtools.mjs.map +1 -0
- package/dist/devtools-panel/index.d.mts +3 -0
- package/dist/devtools-panel/index.mjs +2 -0
- package/{devtools-panel/inject-devtools-panel.d.ts → dist/devtools-panel/inject-devtools-panel.d.mts} +6 -2
- package/dist/devtools-panel/inject-devtools-panel.d.mts.map +1 -0
- package/dist/devtools-panel/inject-devtools-panel.mjs +67 -0
- package/dist/devtools-panel/inject-devtools-panel.mjs.map +1 -0
- package/dist/devtools-panel/production/index.d.mts +4 -0
- package/dist/devtools-panel/production/index.mjs +2 -0
- package/dist/devtools-panel/stub.d.mts +6 -0
- package/dist/devtools-panel/stub.d.mts.map +1 -0
- package/dist/devtools-panel/stub.mjs +7 -0
- package/dist/devtools-panel/stub.mjs.map +1 -0
- package/dist/devtools-panel/types.d.mts +52 -0
- package/dist/devtools-panel/types.d.mts.map +1 -0
- package/dist/devtools-panel/types.mjs +1 -0
- package/dist/index.d.mts +16 -0
- package/{index.mjs → dist/index.mjs} +8 -21
- package/dist/index.mjs.map +1 -0
- package/{infinite-query-options.d.ts → dist/infinite-query-options.d.mts} +35 -31
- package/dist/infinite-query-options.d.mts.map +1 -0
- package/dist/infinite-query-options.mjs +8 -0
- package/dist/infinite-query-options.mjs.map +1 -0
- package/{inject-infinite-query.d.ts → dist/inject-infinite-query.d.mts} +18 -14
- package/dist/inject-infinite-query.d.mts.map +1 -0
- package/dist/inject-infinite-query.mjs +13 -0
- package/dist/inject-infinite-query.mjs.map +1 -0
- package/{inject-is-fetching.d.ts → dist/inject-is-fetching.d.mts} +14 -10
- package/dist/inject-is-fetching.d.mts.map +1 -0
- package/dist/inject-is-fetching.mjs +69 -0
- package/dist/inject-is-fetching.mjs.map +1 -0
- package/{inject-is-mutating.d.ts → dist/inject-is-mutating.d.mts} +14 -10
- package/dist/inject-is-mutating.d.mts.map +1 -0
- package/dist/inject-is-mutating.mjs +52 -0
- package/dist/inject-is-mutating.mjs.map +1 -0
- package/{inject-is-restoring.d.ts → dist/inject-is-restoring.d.mts} +13 -10
- package/dist/inject-is-restoring.d.mts.map +1 -0
- package/dist/inject-is-restoring.mjs +35 -0
- package/dist/inject-is-restoring.mjs.map +1 -0
- package/{inject-mutation-state.d.ts → dist/inject-mutation-state.d.mts} +16 -13
- package/dist/inject-mutation-state.d.mts.map +1 -0
- package/dist/inject-mutation-state.mjs +103 -0
- package/dist/inject-mutation-state.mjs.map +1 -0
- package/{inject-mutation.d.ts → dist/inject-mutation.d.mts} +15 -11
- package/dist/inject-mutation.d.mts.map +1 -0
- package/dist/inject-mutation.mjs +226 -0
- package/dist/inject-mutation.mjs.map +1 -0
- package/dist/inject-queries-experimental/index.d.mts +2 -0
- package/dist/inject-queries-experimental/index.mjs +2 -0
- package/{inject-queries.d.ts → dist/inject-queries.d.mts} +36 -55
- package/dist/inject-queries.d.mts.map +1 -0
- package/dist/inject-queries.mjs +203 -0
- package/dist/inject-queries.mjs.map +1 -0
- package/{inject-query-client.d.ts → dist/inject-query-client.d.mts} +8 -4
- package/dist/inject-query-client.d.mts.map +1 -0
- package/dist/inject-query-client.mjs +23 -0
- package/dist/inject-query-client.mjs.map +1 -0
- package/{inject-query.d.ts → dist/inject-query.d.mts} +18 -14
- package/dist/inject-query.d.mts.map +1 -0
- package/dist/inject-query.mjs +12 -0
- package/dist/inject-query.mjs.map +1 -0
- package/{mutation-options.d.ts → dist/mutation-options.d.mts} +8 -4
- package/dist/mutation-options.d.mts.map +1 -0
- package/dist/mutation-options.mjs +8 -0
- package/dist/mutation-options.mjs.map +1 -0
- package/dist/pending-tasks-compat.d.mts +10 -0
- package/dist/pending-tasks-compat.d.mts.map +1 -0
- package/dist/pending-tasks-compat.mjs +13 -0
- package/dist/pending-tasks-compat.mjs.map +1 -0
- package/{providers.d.ts → dist/providers.d.mts} +16 -13
- package/dist/providers.d.mts.map +1 -0
- package/dist/providers.mjs +124 -0
- package/dist/providers.mjs.map +1 -0
- package/{query-options.d.ts → dist/query-options.d.mts} +41 -37
- package/dist/query-options.d.mts.map +1 -0
- package/dist/query-options.mjs +8 -0
- package/dist/query-options.mjs.map +1 -0
- package/dist/signal-proxy.d.mts +13 -0
- package/dist/signal-proxy.d.mts.map +1 -0
- package/dist/signal-proxy.mjs +35 -0
- package/dist/signal-proxy.mjs.map +1 -0
- package/{types.d.ts → dist/types.d.mts} +36 -37
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -0
- package/package.json +48 -20
- package/src/__tests__/infinite-query-options.test-d.ts +314 -0
- package/src/__tests__/infinite-query-options.test.ts +19 -0
- package/src/__tests__/inject-devtools-panel.test.ts +196 -0
- package/src/__tests__/inject-infinite-query.test-d.ts +66 -0
- package/src/__tests__/inject-infinite-query.test.ts +227 -0
- package/src/__tests__/inject-is-fetching.test.ts +108 -0
- package/src/__tests__/inject-is-mutating.test.ts +113 -0
- package/src/__tests__/inject-is-restoring.test.ts +93 -0
- package/src/__tests__/inject-mutation-state.test-d.ts +22 -0
- package/src/__tests__/inject-mutation-state.test.ts +198 -0
- package/src/__tests__/inject-mutation.test-d.ts +158 -0
- package/src/__tests__/inject-mutation.test.ts +1161 -0
- package/src/__tests__/inject-queries.test-d.ts +196 -0
- package/src/__tests__/inject-queries.test.ts +240 -0
- package/src/__tests__/inject-query.test-d.ts +357 -0
- package/src/__tests__/inject-query.test.ts +700 -0
- package/src/__tests__/mutation-options.test-d.ts +234 -0
- package/src/__tests__/mutation-options.test.ts +344 -0
- package/src/__tests__/pending-tasks.test.ts +644 -0
- package/src/__tests__/provide-query-client.test.ts +38 -0
- package/src/__tests__/provide-tanstack-query.test.ts +38 -0
- package/src/__tests__/query-options.test-d.ts +262 -0
- package/src/__tests__/query-options.test.ts +14 -0
- package/src/__tests__/signal-proxy.test.ts +27 -0
- package/src/__tests__/test-utils.ts +77 -0
- package/src/__tests__/with-devtools.test.ts +674 -0
- package/src/create-base-query.ts +175 -0
- package/src/devtools/index.ts +8 -0
- package/src/devtools/production/index.ts +1 -0
- package/src/devtools/stub.ts +7 -0
- package/src/devtools/types.ts +116 -0
- package/src/devtools/with-devtools.ts +182 -0
- package/src/devtools-panel/index.ts +8 -0
- package/src/devtools-panel/inject-devtools-panel.ts +110 -0
- package/src/devtools-panel/production/index.ts +1 -0
- package/src/devtools-panel/stub.ts +7 -0
- package/src/devtools-panel/types.ts +57 -0
- package/src/index.ts +60 -0
- package/src/infinite-query-options.ts +354 -0
- package/src/inject-infinite-query.ts +296 -0
- package/src/inject-is-fetching.ts +97 -0
- package/src/inject-is-mutating.ts +80 -0
- package/src/inject-is-restoring.ts +53 -0
- package/src/inject-mutation-state.ts +167 -0
- package/src/inject-mutation.ts +328 -0
- package/src/inject-queries-experimental/index.ts +1 -0
- package/src/inject-queries.ts +479 -0
- package/src/inject-query-client.ts +22 -0
- package/src/inject-query.ts +208 -0
- package/src/mutation-options.ts +121 -0
- package/src/pending-tasks-compat.ts +27 -0
- package/src/providers.ts +170 -0
- package/src/query-options.ts +292 -0
- package/src/signal-proxy.ts +46 -0
- package/src/types.ts +429 -0
- package/create-base-query.d.ts +0 -164
- package/create-base-query.mjs +0 -99
- package/create-base-query.mjs.map +0 -1
- package/devtools/index.d.ts +0 -2
- package/devtools/index.mjs +0 -5
- package/devtools/index.mjs.map +0 -1
- package/devtools/production/index.d.ts +0 -1
- package/devtools/stub.d.ts +0 -2
- package/devtools/stub.mjs +0 -8
- package/devtools/stub.mjs.map +0 -1
- package/devtools/types.d.ts +0 -100
- package/devtools/with-devtools.mjs +0 -106
- package/devtools/with-devtools.mjs.map +0 -1
- package/devtools-panel/index.d.ts +0 -2
- package/devtools-panel/index.mjs +0 -5
- package/devtools-panel/index.mjs.map +0 -1
- package/devtools-panel/inject-devtools-panel.mjs +0 -72
- package/devtools-panel/inject-devtools-panel.mjs.map +0 -1
- package/devtools-panel/production/index.d.ts +0 -1
- package/devtools-panel/stub.d.ts +0 -2
- package/devtools-panel/stub.mjs +0 -8
- package/devtools-panel/stub.mjs.map +0 -1
- package/devtools-panel/types.d.ts +0 -48
- package/index.d.ts +0 -25
- package/index.mjs.map +0 -1
- package/infinite-query-options.mjs +0 -7
- package/infinite-query-options.mjs.map +0 -1
- package/inject-infinite-query.mjs +0 -18
- package/inject-infinite-query.mjs.map +0 -1
- package/inject-is-fetching.mjs +0 -31
- package/inject-is-fetching.mjs.map +0 -1
- package/inject-is-mutating.mjs +0 -31
- package/inject-is-mutating.mjs.map +0 -1
- package/inject-is-restoring.mjs +0 -21
- package/inject-is-restoring.mjs.map +0 -1
- package/inject-mutation-state.mjs +0 -51
- package/inject-mutation-state.mjs.map +0 -1
- package/inject-mutation.mjs +0 -94
- package/inject-mutation.mjs.map +0 -1
- package/inject-queries-experimental/index.d.ts +0 -1
- package/inject-queries-experimental/index.mjs +0 -5
- package/inject-queries-experimental/index.mjs.map +0 -1
- package/inject-queries.mjs +0 -82
- package/inject-queries.mjs.map +0 -1
- package/inject-query-client.mjs +0 -9
- package/inject-query-client.mjs.map +0 -1
- package/inject-query.mjs +0 -14
- package/inject-query.mjs.map +0 -1
- package/mutation-options.mjs +0 -7
- package/mutation-options.mjs.map +0 -1
- package/pending-tasks-compat.d.ts +0 -7
- package/pending-tasks-compat.mjs +0 -19
- package/pending-tasks-compat.mjs.map +0 -1
- package/providers.mjs +0 -32
- package/providers.mjs.map +0 -1
- package/query-options.mjs +0 -7
- package/query-options.mjs.map +0 -1
- package/signal-proxy.d.ts +0 -11
- package/signal-proxy.mjs +0 -29
- package/signal-proxy.mjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation-options.mjs","names":[],"sources":["../src/mutation-options.ts"],"sourcesContent":["import type { DefaultError, WithRequired } from '@tanstack/query-core'\nimport type { CreateMutationOptions } from './types'\n\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `injectMutation`. A\n * `mutationKey` is required on this overload so the mutation can be looked up later, e.g. with\n * `injectMutationState`.\n *\n * @see {@link injectMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `injectMutation`, with a\n * required `mutationKey`.\n * @returns The same options object, unchanged.\n *\n * @example\n * Looking the mutation up elsewhere via its `mutationKey`, e.g. for a global \"saving…\" indicator:\n * ```angular-ts\n * import { mutationOptions, injectMutationState } from '@tanstack/angular-query-experimental'\n *\n * const createPostOptions = mutationOptions({\n * mutationKey: ['posts', 'create'],\n * mutationFn: createPost,\n * })\n *\n * @Component({\n * selector: 'saving-indicator',\n * template: `\n * @if (isCreatingPost()) {\n * <span>Saving…</span>\n * }\n * `,\n * })\n * export class SavingIndicator {\n * readonly #pendingCreates = injectMutationState(() => ({\n * filters: { mutationKey: createPostOptions.mutationKey, status: 'pending' },\n * }))\n * readonly isCreatingPost = computed(() => this.#pendingCreates().length > 0)\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: WithRequired<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): WithRequired<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\n/**\n * You can generally pass everything to `mutationOptions` that you can also pass to `injectMutation`. No\n * `mutationKey` is required on this overload — use this when you don't need to target the mutation via a\n * `mutationKey` filter later (e.g. with `injectMutationState`); it can still be observed through other\n * filters, such as `status`.\n *\n * @see {@link injectMutation} to run the mutation these options describe.\n * @param options - The mutation options to use, identical to what you'd pass to `injectMutation`, without a\n * `mutationKey`.\n * @returns The same options object, unchanged.\n * @remarks See the other overload's example for looking a mutation up via `injectMutationState`.\n *\n * @example\n * Sharing options across services, so `QueriesService` stays the single place a mutation is defined:\n * ```angular-ts\n * import { mutationOptions, injectMutation } from '@tanstack/angular-query-experimental'\n *\n * @Injectable({ providedIn: 'root' })\n * export class QueriesService {\n * readonly #queryClient = inject(QueryClient)\n *\n * updatePost(id: number) {\n * return mutationOptions({\n * mutationFn: (post: Partial<Post>) => putPost(id, post),\n * onSuccess: (newPost) => this.#queryClient.setQueryData(['posts', id], newPost),\n * })\n * }\n * }\n *\n * @Component({\n * selector: 'post',\n * template: `<button (click)=\"save()\">Save</button>`,\n * })\n * export class Post {\n * readonly queries = inject(QueriesService)\n * readonly id = signal(0)\n * readonly updatePostMutation = injectMutation(() => this.queries.updatePost(this.id()))\n *\n * save() {\n * this.updatePostMutation.mutate({ title: 'New Title' })\n * }\n * }\n * ```\n */\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: Omit<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n >,\n): Omit<\n CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n 'mutationKey'\n>\nexport function mutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TOnMutateResult = unknown,\n>(\n options: CreateMutationOptions<TData, TError, TVariables, TOnMutateResult>,\n): CreateMutationOptions<TData, TError, TVariables, TOnMutateResult> {\n return options\n}\n"],"mappings":";AA+GA,SAAgB,gBAMd,SACmE;CACnE,OAAO;AACT"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { InjectionToken } from "@angular/core";
|
|
2
|
+
//#region src/pending-tasks-compat.d.ts
|
|
3
|
+
type PendingTasksCompat = {
|
|
4
|
+
add: () => PendingTaskRef;
|
|
5
|
+
};
|
|
6
|
+
type PendingTaskRef = () => void;
|
|
7
|
+
declare const PENDING_TASKS: InjectionToken<PendingTasksCompat>;
|
|
8
|
+
//#endregion
|
|
9
|
+
export { PENDING_TASKS, PendingTaskRef };
|
|
10
|
+
//# sourceMappingURL=pending-tasks-compat.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-tasks-compat.d.mts","names":[],"sources":["../src/pending-tasks-compat.ts"],"mappings":";;KAIK;EAAuB,WAAW;;KAE3B;cAEC,eAAa,eAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import * as ng from "@angular/core";
|
|
2
|
+
import { InjectionToken, inject } from "@angular/core";
|
|
3
|
+
import { noop } from "@tanstack/query-core";
|
|
4
|
+
//#region src/pending-tasks-compat.ts
|
|
5
|
+
const PENDING_TASKS = new InjectionToken("PENDING_TASKS", { factory: () => {
|
|
6
|
+
const token = Reflect.get(ng, "PendingTasks");
|
|
7
|
+
const svc = token ? inject(token, { optional: true }) : null;
|
|
8
|
+
return { add: svc ? () => svc.add() : () => noop };
|
|
9
|
+
} });
|
|
10
|
+
//#endregion
|
|
11
|
+
export { PENDING_TASKS };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=pending-tasks-compat.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pending-tasks-compat.mjs","names":[],"sources":["../src/pending-tasks-compat.ts"],"sourcesContent":["import { InjectionToken, inject } from '@angular/core'\nimport * as ng from '@angular/core'\nimport { noop } from '@tanstack/query-core'\n\ntype PendingTasksCompat = { add: () => PendingTaskRef }\n\nexport type PendingTaskRef = () => void\n\nexport const PENDING_TASKS = new InjectionToken<PendingTasksCompat>(\n 'PENDING_TASKS',\n {\n factory: (): PendingTasksCompat => {\n // Access via Reflect so bundlers stay quiet when the token is absent (Angular < 19).\n const token = Reflect.get(ng, 'PendingTasks') as unknown as\n Parameters<typeof inject>[0] | undefined\n\n const svc: PendingTasksCompat | null = token\n ? (inject(token, { optional: true }) as PendingTasksCompat | null)\n : null\n\n // Without PendingTasks we fall back to a stable no-op shim.\n return {\n add: svc ? () => svc.add() : () => noop,\n }\n },\n },\n)\n"],"mappings":";;;;AAQA,MAAa,gBAAgB,IAAI,eAC/B,iBACA,EACE,eAAmC;CAEjC,MAAM,QAAQ,QAAQ,IAAI,IAAI,cAAc;CAG5C,MAAM,MAAiC,QAClC,OAAO,OAAO,EAAE,UAAU,KAAK,CAAC,IACjC;CAGJ,OAAO,EACL,KAAK,YAAY,IAAI,IAAI,UAAU,KACrC;AACF,EACF,CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { InjectionToken, Provider } from
|
|
2
|
-
import { QueryClient } from
|
|
1
|
+
import { InjectionToken, Provider } from "@angular/core";
|
|
2
|
+
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
+
//#region src/providers.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the
|
|
5
6
|
* [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application —
|
|
@@ -17,7 +18,7 @@ import { QueryClient } from '@tanstack/query-core';
|
|
|
17
18
|
* })
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
|
-
|
|
21
|
+
declare function provideQueryClient(queryClient: QueryClient | InjectionToken<QueryClient>): Provider;
|
|
21
22
|
/**
|
|
22
23
|
* Sets up providers necessary to enable TanStack Query functionality for Angular applications. Allows
|
|
23
24
|
* configuring a `QueryClient` and optional features such as developer tools.
|
|
@@ -80,7 +81,7 @@ export declare function provideQueryClient(queryClient: QueryClient | InjectionT
|
|
|
80
81
|
* providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
|
|
81
82
|
* ```
|
|
82
83
|
*/
|
|
83
|
-
|
|
84
|
+
declare function provideTanStackQuery(queryClient: QueryClient | InjectionToken<QueryClient>, ...features: Array<QueryFeatures>): Array<Provider>;
|
|
84
85
|
/**
|
|
85
86
|
* Sets up providers necessary to enable TanStack Query functionality for Angular applications.
|
|
86
87
|
*
|
|
@@ -90,15 +91,15 @@ export declare function provideTanStackQuery(queryClient: QueryClient | Injectio
|
|
|
90
91
|
* @returns A set of providers to set up TanStack Query.
|
|
91
92
|
* @deprecated Use `provideTanStackQuery` instead.
|
|
92
93
|
*/
|
|
93
|
-
|
|
94
|
+
declare function provideAngularQuery(queryClient: QueryClient): Array<Provider>;
|
|
94
95
|
declare const queryFeatures: readonly ["Devtools", "PersistQueryClient"];
|
|
95
96
|
type QueryFeatureKind = (typeof queryFeatures)[number];
|
|
96
97
|
/**
|
|
97
98
|
* Helper type to represent a Query feature.
|
|
98
99
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
100
|
+
interface QueryFeature<TFeatureKind extends QueryFeatureKind> {
|
|
101
|
+
ɵkind: TFeatureKind;
|
|
102
|
+
ɵproviders: Array<Provider>;
|
|
102
103
|
}
|
|
103
104
|
/**
|
|
104
105
|
* Helper function to create an object that represents a Query feature.
|
|
@@ -106,18 +107,18 @@ export interface QueryFeature<TFeatureKind extends QueryFeatureKind> {
|
|
|
106
107
|
* @param providers - The Angular providers this feature contributes to `provideTanStackQuery`.
|
|
107
108
|
* @returns A Query feature.
|
|
108
109
|
*/
|
|
109
|
-
|
|
110
|
+
declare function queryFeature<TFeatureKind extends QueryFeatureKind>(kind: TFeatureKind, providers: Array<Provider>): QueryFeature<TFeatureKind>;
|
|
110
111
|
/**
|
|
111
112
|
* A type alias that represents a feature which enables developer tools.
|
|
112
113
|
* The type is used to describe the return value of the `withDevtools` function.
|
|
113
114
|
* @see {@link withDevtools}
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
|
+
type DevtoolsFeature = QueryFeature<'Devtools'>;
|
|
116
117
|
/**
|
|
117
118
|
* A type alias that represents a feature which enables persistence.
|
|
118
119
|
* The type is used to describe the return value of the `withPersistQueryClient` function.
|
|
119
120
|
*/
|
|
120
|
-
|
|
121
|
+
type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>;
|
|
121
122
|
/**
|
|
122
123
|
* A type alias that represents all Query features available for use with `provideTanStackQuery`.
|
|
123
124
|
* Features can be enabled by adding special functions to the `provideTanStackQuery` call.
|
|
@@ -125,5 +126,7 @@ export type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>;
|
|
|
125
126
|
* documentation on how to use those functions.
|
|
126
127
|
* @see {@link provideTanStackQuery}
|
|
127
128
|
*/
|
|
128
|
-
|
|
129
|
-
|
|
129
|
+
type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { DevtoolsFeature, PersistQueryClientFeature, QueryFeature, QueryFeatures, provideAngularQuery, provideQueryClient, provideTanStackQuery, queryFeature };
|
|
132
|
+
//# sourceMappingURL=providers.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.d.mts","names":[],"sources":["../src/providers.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;iBAqBgB,mBACd,aAAa,cAAc,eAAe,eACzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA8Ea,qBACd,aAAa,cAAc,eAAe,iBACvC,UAAU,MAAM,iBAClB,MAAM;;;;;;;;;;iBAgBO,oBAAoB,aAAa,cAAc,MAAM;cAI/D;KAED,2BAA2B;;;;UAKf,aAAa,qBAAqB;EACjD,OAAO;EACP,YAAY,MAAM;;;;;;;;iBASJ,aAAa,qBAAqB,kBAChD,MAAM,cACN,WAAW,MAAM,YAChB,aAAa;;;;;;KASJ,kBAAkB;;;;;KAMlB,4BAA4B;;;;;;;;KAS5B,gBAAgB,kBAAkB"}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { DestroyRef, InjectionToken, inject } from "@angular/core";
|
|
2
|
+
import { QueryClient } from "@tanstack/query-core";
|
|
3
|
+
//#region src/providers.ts
|
|
4
|
+
/**
|
|
5
|
+
* Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the
|
|
6
|
+
* [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application —
|
|
7
|
+
* it calls `provideQueryClient` internally. Use `provideQueryClient` directly to provide a different
|
|
8
|
+
* `QueryClient` instance for part of the application, or for unit testing.
|
|
9
|
+
* @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
|
|
10
|
+
* @returns A provider object that can be used to provide the `QueryClient` instance.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* Providing a test-only `QueryClient` in a component test, without wiring up `provideTanStackQuery`'s other
|
|
14
|
+
* defaults:
|
|
15
|
+
* ```ts
|
|
16
|
+
* TestBed.configureTestingModule({
|
|
17
|
+
* providers: [provideQueryClient(new QueryClient())],
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
function provideQueryClient(queryClient) {
|
|
22
|
+
return {
|
|
23
|
+
provide: QueryClient,
|
|
24
|
+
useFactory: () => {
|
|
25
|
+
const client = queryClient instanceof InjectionToken ? inject(queryClient) : queryClient;
|
|
26
|
+
inject(DestroyRef).onDestroy(() => client.unmount());
|
|
27
|
+
client.mount();
|
|
28
|
+
return client;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets up providers necessary to enable TanStack Query functionality for Angular applications. Allows
|
|
34
|
+
* configuring a `QueryClient` and optional features such as developer tools.
|
|
35
|
+
*
|
|
36
|
+
* @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
|
|
37
|
+
* @see {@link withDevtools}
|
|
38
|
+
* @param queryClient - A `QueryClient` instance, or an `InjectionToken` which provides a `QueryClient`.
|
|
39
|
+
* @param features - Optional features to configure additional Query functionality.
|
|
40
|
+
* @returns A set of providers to set up TanStack Query.
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
|
|
45
|
+
*
|
|
46
|
+
* bootstrapApplication(AppComponent, {
|
|
47
|
+
* providers: [provideTanStackQuery(new QueryClient())],
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*
|
|
51
|
+
* @example
|
|
52
|
+
* The same, in an `NgModule`-based application:
|
|
53
|
+
* ```ts
|
|
54
|
+
* import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'
|
|
55
|
+
*
|
|
56
|
+
* @NgModule({
|
|
57
|
+
* declarations: [AppComponent],
|
|
58
|
+
* imports: [BrowserModule],
|
|
59
|
+
* providers: [provideTanStackQuery(new QueryClient())],
|
|
60
|
+
* bootstrap: [AppComponent],
|
|
61
|
+
* })
|
|
62
|
+
* export class AppModule {}
|
|
63
|
+
* ```
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* Enabling optional developer tools by adding `withDevtools` — by default, the tools are then loaded when
|
|
67
|
+
* your app is in development mode:
|
|
68
|
+
* ```ts
|
|
69
|
+
* import {
|
|
70
|
+
* provideTanStackQuery,
|
|
71
|
+
* withDevtools,
|
|
72
|
+
* QueryClient,
|
|
73
|
+
* } from '@tanstack/angular-query-experimental'
|
|
74
|
+
*
|
|
75
|
+
* bootstrapApplication(AppComponent, {
|
|
76
|
+
* providers: [provideTanStackQuery(new QueryClient(), withDevtools())],
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* Using an `InjectionToken` for the `QueryClient` — an advanced optimization that lets TanStack Query be
|
|
82
|
+
* absent from the main application bundle, useful for including it on lazy-loaded routes only while still
|
|
83
|
+
* sharing a `QueryClient`. This is a small optimization; for most applications it's preferable to provide
|
|
84
|
+
* the `QueryClient` in the main application config, as in the examples above:
|
|
85
|
+
* ```ts
|
|
86
|
+
* export const MY_QUERY_CLIENT = new InjectionToken('', {
|
|
87
|
+
* factory: () => new QueryClient(),
|
|
88
|
+
* })
|
|
89
|
+
*
|
|
90
|
+
* // In a lazy loaded route or lazy loaded component's providers array:
|
|
91
|
+
* providers: [provideTanStackQuery(MY_QUERY_CLIENT)]
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
function provideTanStackQuery(queryClient, ...features) {
|
|
95
|
+
return [provideQueryClient(queryClient), features.map((feature) => feature.ɵproviders)];
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Sets up providers necessary to enable TanStack Query functionality for Angular applications.
|
|
99
|
+
*
|
|
100
|
+
* Allows configuring a `QueryClient`.
|
|
101
|
+
* @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
|
|
102
|
+
* @param queryClient - A `QueryClient` instance.
|
|
103
|
+
* @returns A set of providers to set up TanStack Query.
|
|
104
|
+
* @deprecated Use `provideTanStackQuery` instead.
|
|
105
|
+
*/
|
|
106
|
+
function provideAngularQuery(queryClient) {
|
|
107
|
+
return provideTanStackQuery(queryClient);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Helper function to create an object that represents a Query feature.
|
|
111
|
+
* @param kind - The kind of feature, e.g. `'Devtools'`.
|
|
112
|
+
* @param providers - The Angular providers this feature contributes to `provideTanStackQuery`.
|
|
113
|
+
* @returns A Query feature.
|
|
114
|
+
*/
|
|
115
|
+
function queryFeature(kind, providers) {
|
|
116
|
+
return {
|
|
117
|
+
ɵkind: kind,
|
|
118
|
+
ɵproviders: providers
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
//#endregion
|
|
122
|
+
export { provideAngularQuery, provideQueryClient, provideTanStackQuery, queryFeature };
|
|
123
|
+
|
|
124
|
+
//# sourceMappingURL=providers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"providers.mjs","names":[],"sources":["../src/providers.ts"],"sourcesContent":["import { DestroyRef, InjectionToken, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport type { Provider } from '@angular/core'\n\n/**\n * Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the\n * [`QueryClient`](https://tanstack.com/query/latest/docs/reference/QueryClient) for the entire application —\n * it calls `provideQueryClient` internally. Use `provideQueryClient` directly to provide a different\n * `QueryClient` instance for part of the application, or for unit testing.\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 *\n * @example\n * Providing a test-only `QueryClient` in a component test, without wiring up `provideTanStackQuery`'s other\n * defaults:\n * ```ts\n * TestBed.configureTestingModule({\n * providers: [provideQueryClient(new QueryClient())],\n * })\n * ```\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. Allows\n * configuring a `QueryClient` and optional features such as developer tools.\n *\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @see {@link withDevtools}\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 *\n * @example\n * ```ts\n * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query-experimental'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(new QueryClient())],\n * })\n * ```\n *\n * @example\n * The same, in an `NgModule`-based application:\n * ```ts\n * import { provideTanStackQuery, QueryClient } 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 * @example\n * Enabling optional developer tools by adding `withDevtools` — by default, the tools are then loaded when\n * 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 * providers: [provideTanStackQuery(new QueryClient(), withDevtools())],\n * })\n * ```\n *\n * @example\n * Using an `InjectionToken` for the `QueryClient` — an advanced optimization that lets TanStack Query be\n * absent from the main application bundle, useful for including it on lazy-loaded routes only while still\n * sharing a `QueryClient`. This is a small optimization; for most applications it's preferable to provide\n * the `QueryClient` in the main application config, as in the examples above:\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 */\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 configuring a `QueryClient`.\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @param queryClient - A `QueryClient` instance.\n * @returns A set of providers to set up TanStack Query.\n * @deprecated Use `provideTanStackQuery` instead.\n */\nexport function provideAngularQuery(queryClient: QueryClient): Array<Provider> {\n return provideTanStackQuery(queryClient)\n}\n\nconst queryFeatures = ['Devtools', 'PersistQueryClient'] as const\n\ntype QueryFeatureKind = (typeof queryFeatures)[number]\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 - The kind of feature, e.g. `'Devtools'`.\n * @param providers - The Angular providers this feature contributes to `provideTanStackQuery`.\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 * @see {@link withDevtools}\n */\nexport type DevtoolsFeature = QueryFeature<'Devtools'>\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 */\nexport type PersistQueryClientFeature = QueryFeature<'PersistQueryClient'>\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 * @see {@link provideTanStackQuery}\n */\nexport type QueryFeatures = DevtoolsFeature | PersistQueryClientFeature\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAqBA,SAAgB,mBACd,aACU;CACV,OAAO;EACL,SAAS;EACT,kBAAkB;GAChB,MAAM,SACJ,uBAAuB,iBACnB,OAAO,WAAW,IAClB;GAEN,OAAO,UAAU,CAAC,CAAC,gBAAgB,OAAO,QAAQ,CAAC;GACnD,OAAO,MAAM;GACb,OAAO;EACT;CACF;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,SAAgB,qBACd,aACA,GAAG,UACc;CACjB,OAAO,CACL,mBAAmB,WAAW,GAC9B,SAAS,KAAK,YAAY,QAAQ,UAAU,CAC9C;AACF;;;;;;;;;;AAWA,SAAgB,oBAAoB,aAA2C;CAC7E,OAAO,qBAAqB,WAAW;AACzC;;;;;;;AAoBA,SAAgB,aACd,MACA,WAC4B;CAC5B,OAAO;EAAE,OAAO;EAAM,YAAY;CAAU;AAC9C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { CreateQueryOptions } from "./types.mjs";
|
|
2
|
+
import { DefaultError, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryFunction, QueryKey, QueryKeyWithDataTag, SkipToken } from "@tanstack/query-core";
|
|
3
|
+
//#region src/query-options.d.ts
|
|
3
4
|
/**
|
|
4
5
|
* The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
|
|
5
6
|
* `undefined` while the query is `pending`.
|
|
@@ -9,15 +10,15 @@ import { CreateQueryOptions } from './types.js';
|
|
|
9
10
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
10
11
|
* @template TQueryKey - The type of your `queryKey`.
|
|
11
12
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
|
|
14
|
+
/**
|
|
15
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
16
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
17
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
18
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
19
|
+
* cache.
|
|
20
|
+
*/
|
|
21
|
+
initialData?: undefined | InitialDataFunction<NonUndefinedGuard<TQueryFnData>> | NonUndefinedGuard<TQueryFnData>;
|
|
21
22
|
};
|
|
22
23
|
/**
|
|
23
24
|
* The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
|
|
@@ -28,14 +29,14 @@ export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = Default
|
|
|
28
29
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
29
30
|
* @template TQueryKey - The type of your `queryKey`.
|
|
30
31
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
32
|
+
type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
|
|
33
|
+
/**
|
|
34
|
+
* `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
|
|
35
|
+
* you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a
|
|
36
|
+
* fetch that fails with "Missing queryFn" unless `enabled` is `false` or a default query function has been
|
|
37
|
+
* defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.
|
|
38
|
+
*/
|
|
39
|
+
queryFn?: Exclude<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'], SkipToken | undefined>;
|
|
39
40
|
};
|
|
40
41
|
/**
|
|
41
42
|
* The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
|
|
@@ -46,21 +47,21 @@ export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError
|
|
|
46
47
|
* @template TData - The type `data` ends up as after `select` runs.
|
|
47
48
|
* @template TQueryKey - The type of your `queryKey`.
|
|
48
49
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
50
|
+
type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = Omit<CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'queryFn'> & {
|
|
51
|
+
/**
|
|
52
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
53
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
54
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
55
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
56
|
+
* cache.
|
|
57
|
+
*/
|
|
58
|
+
initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
|
|
59
|
+
/**
|
|
60
|
+
* Optional here, but omitting it is only safe when no fetch will be attempted — for example with
|
|
61
|
+
* `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no
|
|
62
|
+
* `queryFn` still tries to fetch and fails with a "Missing queryFn" error; `initialData` does not prevent this.
|
|
63
|
+
*/
|
|
64
|
+
queryFn?: QueryFunction<TQueryFnData, TQueryKey>;
|
|
64
65
|
};
|
|
65
66
|
/**
|
|
66
67
|
* You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
|
|
@@ -106,7 +107,7 @@ export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultEr
|
|
|
106
107
|
* }
|
|
107
108
|
* ```
|
|
108
109
|
*/
|
|
109
|
-
|
|
110
|
+
declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
|
|
110
111
|
/**
|
|
111
112
|
* You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
|
|
112
113
|
* can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is
|
|
@@ -146,7 +147,7 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
|
|
|
146
147
|
* }
|
|
147
148
|
* ```
|
|
148
149
|
*/
|
|
149
|
-
|
|
150
|
+
declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey>): UnusedSkipTokenOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
|
|
150
151
|
/**
|
|
151
152
|
* You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
|
|
152
153
|
* can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is
|
|
@@ -218,4 +219,7 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
|
|
|
218
219
|
* }
|
|
219
220
|
* ```
|
|
220
221
|
*/
|
|
221
|
-
|
|
222
|
+
declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>;
|
|
223
|
+
//#endregion
|
|
224
|
+
export { DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions, queryOptions };
|
|
225
|
+
//# sourceMappingURL=query-options.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-options.d.mts","names":[],"sources":["../src/query-options.ts"],"mappings":";;;;;;;;;;;;KAqBY,4BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,mBAAmB,cAAc,QAAQ,OAAO;;;;;;;;EAQlD,0BAEI,oBAAoB,kBAAkB,iBACtC,kBAAkB;;;;;;;;;;;KAYZ,uBACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,UACF,mBAAmB,cAAc,QAAQ,OAAO;;;;;;;EAShD,UAAU,QACR,mBAAmB,cAAc,QAAQ,OAAO,uBAChD;;;;;;;;;;;KAaQ,0BACV,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,YAC3B,KACF,mBAAmB,cAAc,QAAQ,OAAO;;;;;;;;EAUhD,aACE,kBAAkB,uBAAuB,kBAAkB;;;;;;EAM7D,UAAU,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA+CxB,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,0BAA0B,cAAc,QAAQ,OAAO,aAC/D,0BAA0B,cAAc,QAAQ,OAAO,aACxD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyC/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,uBAAuB,cAAc,QAAQ,OAAO,aAC5D,uBAAuB,cAAc,QAAQ,OAAO,aACrD,oBAAoB,WAAW,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAyE/B,aACd,wBACA,SAAS,cACT,QAAQ,cACR,kBAAkB,WAAW,UAE7B,SAAS,4BAA4B,cAAc,QAAQ,OAAO,aACjE,4BAA4B,cAAc,QAAQ,OAAO,aAC1D,oBAAoB,WAAW,cAAc"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-options.mjs","names":[],"sources":["../src/query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryFunction,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateQueryOptions } from './types'\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be\n * `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\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 /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | InitialDataFunction<NonUndefinedGuard<TQueryFnData>>\n | NonUndefinedGuard<TQueryFnData>\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is\n * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\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 /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never\n * `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type your `queryFn` resolves to.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs.\n * @template TQueryKey - The type of your `queryKey`.\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 /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>)\n /**\n * Optional here, but omitting it is only safe when no fetch will be attempted — for example with\n * `enabled: false`, or when a default query function has been defined. Otherwise, an enabled query with no\n * `queryFn` still tries to fetch and fails with a \"Missing queryFn\" error; `initialData` does not prevent this.\n */\n queryFn?: QueryFunction<TQueryFnData, TQueryKey>\n}\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options\n * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is\n * required and is the query key to generate options for.\n *\n * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless\n * a `select` changes `TData` to include `undefined`).\n *\n * @see {@link injectQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `injectQuery`,\n * with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postsOptions = queryOptions({\n * queryKey: ['posts'],\n * queryFn: fetchPosts,\n * initialData: [],\n * })\n *\n * @Component({\n * selector: 'posts',\n * template: `\n * <!-- `postsQuery.data()` is never `undefined`, thanks to `initialData` — even if a refetch\n * fails, so the list stays visible alongside the error. -->\n * @if (postsQuery.isError()) {\n * <span>Error: {{ postsQuery.error()?.message }}</span>\n * }\n * <ul>\n * @for (post of postsQuery.data(); track post.id) {\n * <li>{{ post.title }}</li>\n * }\n * </ul>\n * `,\n * })\n * export class Posts {\n * readonly postsQuery = injectQuery(() => postsOptions)\n * }\n * ```\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 QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options\n * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is\n * required and is the query key to generate options for.\n *\n * @see {@link injectQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `injectQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * @Component({\n * selector: 'post',\n * template: `\n * @if (postQuery.isPending()) {\n * Loading...\n * } @else if (postQuery.isError()) {\n * <span>Error: {{ postQuery.error()?.message }}</span>\n * } @else {\n * <h1>{{ postQuery.data().title }}</h1>\n * }\n * `,\n * })\n * export class Post {\n * readonly id = signal('1')\n * readonly postQuery = injectQuery(() => postOptions(this.id()))\n * }\n * ```\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 QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\n/**\n * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options\n * can be shared across functions and imperative APIs such as `queryClient.fetchQuery`. `options.queryKey` is\n * required and is the query key to generate options for.\n *\n * @see {@link injectQuery} to run a query with these options.\n * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.\n * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `injectQuery`.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `id`:\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postOptions = (id: string) =>\n * queryOptions({\n * queryKey: ['post', id],\n * queryFn: () => fetchPost(id),\n * })\n *\n * @Component({\n * selector: 'post',\n * template: `\n * @if (postQuery.isPending()) {\n * Loading...\n * } @else if (postQuery.isError()) {\n * <span>Error: {{ postQuery.error()?.message }}</span>\n * } @else {\n * <h1>{{ postQuery.data().title }}</h1>\n * }\n * `,\n * })\n * export class Post {\n * readonly id = signal('1')\n * readonly postQuery = injectQuery(() => postOptions(this.id()))\n * }\n * ```\n *\n * @example\n * A factory that disables the query, type safe, until `postId` is set:\n * ```angular-ts\n * import { queryOptions, skipToken, injectQuery } from '@tanstack/angular-query-experimental'\n *\n * export const postOptions = (postId: number | undefined) =>\n * queryOptions({\n * queryKey: ['post', postId],\n * queryFn: postId != null ? () => fetchPost(postId) : skipToken,\n * })\n *\n * @Component({\n * selector: 'post',\n * template: `\n * @if (postId() == null) {\n * Select a post\n * } @else if (postQuery.isPending()) {\n * Loading...\n * } @else if (postQuery.isError()) {\n * <span>Error: {{ postQuery.error()?.message }}</span>\n * } @else {\n * <h1>{{ postQuery.data().title }}</h1>\n * }\n * `,\n * })\n * export class Post {\n * readonly postId = signal<number | undefined>(undefined)\n * readonly postQuery = injectQuery(() => postOptions(this.postId()))\n * }\n * ```\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 QueryKeyWithDataTag<TQueryKey, TQueryFnData, TError>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n"],"mappings":";AAiSA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Signal } from "@angular/core";
|
|
2
|
+
//#region src/signal-proxy.d.ts
|
|
3
|
+
type MapToSignals<T> = { [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>; };
|
|
4
|
+
/**
|
|
5
|
+
* Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
|
|
6
|
+
* Functions on the object are passed through as-is.
|
|
7
|
+
* @param inputSignal - `Signal` that must return an object.
|
|
8
|
+
* @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
|
|
9
|
+
*/
|
|
10
|
+
declare function signalProxy<TInput extends Record<string | symbol, any>>(inputSignal: Signal<TInput>): MapToSignals<TInput>;
|
|
11
|
+
//#endregion
|
|
12
|
+
export { MapToSignals, signalProxy };
|
|
13
|
+
//# sourceMappingURL=signal-proxy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-proxy.d.mts","names":[],"sources":["../src/signal-proxy.ts"],"mappings":";;KAGY,aAAa,QACtB,WAAW,IAAI,EAAE,WAAW,WAAW,EAAE,KAAK,OAAO,EAAE;;;;;;;iBAS1C,YAAY,eAAe,8BACzC,aAAa,OAAO,UAAO,aAAA"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { computed, untracked } from "@angular/core";
|
|
2
|
+
//#region src/signal-proxy.ts
|
|
3
|
+
/**
|
|
4
|
+
* Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
|
|
5
|
+
* Functions on the object are passed through as-is.
|
|
6
|
+
* @param inputSignal - `Signal` that must return an object.
|
|
7
|
+
* @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
|
|
8
|
+
*/
|
|
9
|
+
function signalProxy(inputSignal) {
|
|
10
|
+
return new Proxy({}, {
|
|
11
|
+
get(target, prop) {
|
|
12
|
+
const computedField = target[prop];
|
|
13
|
+
if (computedField) return computedField;
|
|
14
|
+
const targetField = untracked(inputSignal)[prop];
|
|
15
|
+
if (typeof targetField === "function") return targetField;
|
|
16
|
+
return target[prop] = computed(() => inputSignal()[prop]);
|
|
17
|
+
},
|
|
18
|
+
has(_, prop) {
|
|
19
|
+
return !!untracked(inputSignal)[prop];
|
|
20
|
+
},
|
|
21
|
+
ownKeys() {
|
|
22
|
+
return Reflect.ownKeys(untracked(inputSignal));
|
|
23
|
+
},
|
|
24
|
+
getOwnPropertyDescriptor() {
|
|
25
|
+
return {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
//#endregion
|
|
33
|
+
export { signalProxy };
|
|
34
|
+
|
|
35
|
+
//# sourceMappingURL=signal-proxy.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"signal-proxy.mjs","names":[],"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"],"mappings":";;;;;;;;AAaA,SAAgB,YACd,aACA;CAGA,OAAO,IAAI,MAA4B,CAAY,GAAG;EACpD,IAAI,QAAQ,MAAM;GAEhB,MAAM,gBAAgB,OAAO;GAC7B,IAAI,eAAe,OAAO;GAG1B,MAAM,cAAc,UAAU,WAAW,CAAC,CAAC;GAC3C,IAAI,OAAO,gBAAgB,YAAY,OAAO;GAI9C,OAAQ,OAAO,QAAQ,eAAe,YAAY,CAAC,CAAC,KAAK;EAC3D;EACA,IAAI,GAAG,MAAM;GACX,OAAO,CAAC,CAAC,UAAU,WAAW,CAAC,CAAC;EAClC;EACA,UAAU;GACR,OAAO,QAAQ,QAAQ,UAAU,WAAW,CAAC;EAC/C;EACA,2BAA2B;GACzB,OAAO;IACL,YAAY;IACZ,cAAc;GAChB;EACF;CACF,CAAC;AACH"}
|