@tanstack/angular-query 5.0.0-rc.4 → 5.0.0-rc.5

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.
Files changed (69) hide show
  1. package/hydration-state-key.mjs +10 -13
  2. package/hydration-state-key.mjs.map +1 -1
  3. package/index.mjs +8 -20
  4. package/index.mjs.map +1 -1
  5. package/infinite-query-options.d.ts +7 -18
  6. package/infinite-query-options.mjs +6 -5
  7. package/infinite-query-options.mjs.map +1 -1
  8. package/inject-base-query.d.ts +3 -0
  9. package/inject-base-query.mjs +62 -58
  10. package/inject-base-query.mjs.map +1 -1
  11. package/inject-infinite-query.d.ts +7 -11
  12. package/inject-infinite-query.mjs +16 -32
  13. package/inject-infinite-query.mjs.map +1 -1
  14. package/inject-is-fetching.d.ts +1 -1
  15. package/inject-is-fetching.mjs +22 -15
  16. package/inject-is-fetching.mjs.map +1 -1
  17. package/inject-is-mutating.d.ts +1 -1
  18. package/inject-is-mutating.mjs +22 -15
  19. package/inject-is-mutating.mjs.map +1 -1
  20. package/inject-is-restoring.d.ts +2 -0
  21. package/inject-is-restoring.mjs +28 -17
  22. package/inject-is-restoring.mjs.map +1 -1
  23. package/inject-mutation-state.d.ts +9 -0
  24. package/inject-mutation-state.mjs +25 -23
  25. package/inject-mutation-state.mjs.map +1 -1
  26. package/inject-mutation.d.ts +2 -4
  27. package/inject-mutation.mjs +87 -67
  28. package/inject-mutation.mjs.map +1 -1
  29. package/inject-queries.d.ts +1 -3
  30. package/inject-queries.mjs +122 -114
  31. package/inject-queries.mjs.map +1 -1
  32. package/inject-queries.types.d.ts +15 -0
  33. package/inject-query.d.ts +7 -13
  34. package/inject-query.mjs +11 -14
  35. package/inject-query.mjs.map +1 -1
  36. package/internal.mjs +2 -7
  37. package/mutation-options.d.ts +2 -6
  38. package/mutation-options.mjs +6 -5
  39. package/mutation-options.mjs.map +1 -1
  40. package/package.json +2 -2
  41. package/providers.d.ts +16 -14
  42. package/providers.mjs +138 -75
  43. package/providers.mjs.map +1 -1
  44. package/query-options.d.ts +6 -16
  45. package/query-options.mjs +6 -5
  46. package/query-options.mjs.map +1 -1
  47. package/query-resource.d.ts +4 -3
  48. package/query-resource.mjs +72 -63
  49. package/query-resource.mjs.map +1 -1
  50. package/schematics/migrate-from-experimental/index.js +2 -2
  51. package/schematics/ng-add/index.js +1 -1
  52. package/types.d.ts +70 -10
  53. package/utils/inject-external-store.d.ts +3 -0
  54. package/utils/inject-external-store.mjs +54 -38
  55. package/utils/inject-external-store.mjs.map +1 -1
  56. package/utils/inject-pending-tasks-lifecycle.d.ts +13 -1
  57. package/utils/inject-pending-tasks-lifecycle.mjs +32 -29
  58. package/utils/inject-pending-tasks-lifecycle.mjs.map +1 -1
  59. package/utils/inject-query-zone.d.ts +4 -1
  60. package/utils/inject-query-zone.mjs +12 -7
  61. package/utils/inject-query-zone.mjs.map +1 -1
  62. package/utils/resource-types.d.ts +3 -0
  63. package/utils/result-fields.d.ts +9 -0
  64. package/utils/result-fields.mjs +55 -62
  65. package/utils/result-fields.mjs.map +1 -1
  66. package/utils/signal-proxy.d.ts +6 -0
  67. package/utils/signal-proxy.mjs +16 -9
  68. package/utils/signal-proxy.mjs.map +1 -1
  69. package/internal.mjs.map +0 -1
package/providers.d.ts CHANGED
@@ -4,9 +4,12 @@ import { EnvironmentProviders } from '@angular/core';
4
4
  * Provides a `QueryClient` and optional TanStack Query features.
5
5
  * The factory runs once per injector in Angular's injection context, so it can
6
6
  * call `inject()` and each SSR request can receive an independent cache.
7
- *
8
- * **Example - standalone**
9
- *
7
+ * @param queryClientFactory - Creates or resolves a `QueryClient` in the injection context.
8
+ * @param features - Optional features to configure additional Query functionality.
9
+ * @returns A single {@link EnvironmentProviders} value (do not spread into `providers`).
10
+ * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
11
+ * @see https://tanstack.com/query/v5/docs/framework/angular/devtools
12
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/ssr
10
13
  * @example
11
14
  * ```ts
12
15
  * import {
@@ -32,13 +35,6 @@ import { EnvironmentProviders } from '@angular/core';
32
35
  * ],
33
36
  * })
34
37
  * ```
35
- *
36
- * @param queryClientFactory - Creates or resolves a `QueryClient` in the injection context.
37
- * @param features - Optional features to configure additional Query functionality.
38
- * @returns A single {@link EnvironmentProviders} value (do not spread into `providers`).
39
- * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
40
- * @see https://tanstack.com/query/v5/docs/framework/angular/devtools
41
- * @see https://tanstack.com/query/latest/docs/framework/angular/guides/ssr
42
38
  */
43
39
  export declare function provideTanStackQuery(queryClientFactory: () => QueryClient, ...features: ReadonlyArray<QueryFeature>): EnvironmentProviders;
44
40
  declare const queryFeatureBrand: unique symbol;
@@ -53,11 +49,16 @@ export interface QueryFeature {
53
49
  /**
54
50
  * Creates a feature shared by Angular Query integration packages.
55
51
  * @internal
56
- * @param providers -
57
- * @returns A Query feature.
52
+ * @param providers - Providers owned by this Query feature.
53
+ * @returns An opaque feature that installs the supplied environment providers.
58
54
  */
59
55
  export declare function queryFeature(providers: EnvironmentProviders): QueryFeature;
60
- /** @internal */
56
+ /**
57
+ * Gets the environment providers owned by an opaque Query feature.
58
+ * @internal
59
+ * @param feature - The feature to unwrap.
60
+ * @returns The environment providers to install.
61
+ */
61
62
  export declare function getQueryFeatureProviders(feature: QueryFeature): EnvironmentProviders;
62
63
  /**
63
64
  * Sets a non-default serialization key for this injector's `QueryClient` cache (server dehydrate /
@@ -72,12 +73,13 @@ export declare function getQueryFeatureProviders(feature: QueryFeature): Environ
72
73
  * ),
73
74
  * ]
74
75
  * ```
75
- *
76
76
  * @param key - A unique string for this client's `TransferState` entry.
77
+ * @returns A feature that stores this client's cache under the supplied key.
77
78
  */
78
79
  export declare function withHydrationKey(key: string): QueryFeature;
79
80
  /**
80
81
  * Disables `TransferState` hydration and dehydration for the current environment injector.
82
+ * @returns A feature that prevents automatic cache transfer for this injector.
81
83
  */
82
84
  export declare function withNoQueryHydration(): QueryFeature;
83
85
  export {};
package/providers.mjs CHANGED
@@ -1,89 +1,152 @@
1
- import { isPlatformServer, isPlatformBrowser } from "@angular/common";
2
- import { makeEnvironmentProviders, provideEnvironmentInitializer, makeStateKey, InjectionToken, inject, DestroyRef, PLATFORM_ID, DOCUMENT, TransferState } from "@angular/core";
3
- import { QueryClient, dehydrate, hydrate } from "@tanstack/query-core";
4
- import { INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY } from "./hydration-state-key.mjs";
5
1
  import { injectQueryZone } from "./utils/inject-query-zone.mjs";
6
- const INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE = new InjectionToken("", {
7
- providedIn: "root",
8
- factory: () => true
2
+ import { INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY } from "./hydration-state-key.mjs";
3
+ import { QueryClient, dehydrate, hydrate } from "@tanstack/query-core";
4
+ import { DOCUMENT, DestroyRef, InjectionToken, PLATFORM_ID, TransferState, inject, makeEnvironmentProviders, makeStateKey, provideEnvironmentInitializer } from "@angular/core";
5
+ import { isPlatformBrowser, isPlatformServer } from "@angular/common";
6
+ //#region src/providers.ts
7
+ var INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE = new InjectionToken("", {
8
+ providedIn: "root",
9
+ factory: () => true
9
10
  });
11
+ /**
12
+ * Mounts the injected client, configures server defaults, and connects TransferState hydration.
13
+ */
10
14
  function configureQueryClient() {
11
- const queryClient = inject(QueryClient);
12
- const destroyRef = inject(DestroyRef);
13
- const platformId = inject(PLATFORM_ID);
14
- if (isPlatformServer(platformId)) {
15
- const defaults = queryClient.getDefaultOptions();
16
- queryClient.setDefaultOptions({
17
- ...defaults,
18
- queries: { gcTime: Infinity, retry: false, ...defaults.queries },
19
- mutations: { gcTime: Infinity, ...defaults.mutations }
20
- });
21
- }
22
- const shouldHydrate = inject(INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE);
23
- const hydrationStateKey = inject(
24
- INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY
25
- );
26
- if (inject(DOCUMENT, { optional: true })) {
27
- const transferState = inject(TransferState);
28
- if (shouldHydrate && isPlatformServer(platformId)) {
29
- transferState.onSerialize(hydrationStateKey, () => dehydrate(queryClient));
30
- } else if (shouldHydrate && isPlatformBrowser(platformId)) {
31
- const dehydratedState = transferState.get(hydrationStateKey, null);
32
- if (dehydratedState) {
33
- hydrate(queryClient, dehydratedState);
34
- transferState.remove(hydrationStateKey);
35
- }
36
- }
37
- }
38
- queryClient.mount();
39
- destroyRef.onDestroy(() => queryClient.unmount());
15
+ const queryClient = inject(QueryClient);
16
+ const destroyRef = inject(DestroyRef);
17
+ const platformId = inject(PLATFORM_ID);
18
+ if (isPlatformServer(platformId)) {
19
+ const defaults = queryClient.getDefaultOptions();
20
+ queryClient.setDefaultOptions({
21
+ ...defaults,
22
+ queries: {
23
+ gcTime: Infinity,
24
+ retry: false,
25
+ ...defaults.queries
26
+ },
27
+ mutations: {
28
+ gcTime: Infinity,
29
+ ...defaults.mutations
30
+ }
31
+ });
32
+ }
33
+ const shouldHydrate = inject(INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE);
34
+ const hydrationStateKey = inject(INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY);
35
+ if (inject(DOCUMENT, { optional: true })) {
36
+ const transferState = inject(TransferState);
37
+ if (shouldHydrate && isPlatformServer(platformId)) transferState.onSerialize(hydrationStateKey, () => dehydrate(queryClient));
38
+ else if (shouldHydrate && isPlatformBrowser(platformId)) {
39
+ const dehydratedState = transferState.get(hydrationStateKey, null);
40
+ if (dehydratedState) {
41
+ hydrate(queryClient, dehydratedState);
42
+ transferState.remove(hydrationStateKey);
43
+ }
44
+ }
45
+ }
46
+ queryClient.mount();
47
+ destroyRef.onDestroy(() => queryClient.unmount());
40
48
  }
49
+ /**
50
+ * Provides a `QueryClient` and optional TanStack Query features.
51
+ * The factory runs once per injector in Angular's injection context, so it can
52
+ * call `inject()` and each SSR request can receive an independent cache.
53
+ * @param queryClientFactory - Creates or resolves a `QueryClient` in the injection context.
54
+ * @param features - Optional features to configure additional Query functionality.
55
+ * @returns A single {@link EnvironmentProviders} value (do not spread into `providers`).
56
+ * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
57
+ * @see https://tanstack.com/query/v5/docs/framework/angular/devtools
58
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/ssr
59
+ * @example
60
+ * ```ts
61
+ * import {
62
+ * provideTanStackQuery,
63
+ * QueryClient,
64
+ * } from '@tanstack/angular-query'
65
+ *
66
+ * bootstrapApplication(AppComponent, {
67
+ * providers: [provideTanStackQuery(() => new QueryClient())],
68
+ * })
69
+ * ```
70
+ *
71
+ * You can also enable optional developer tools by adding `withDevtools`. By
72
+ * default the tools will then be loaded when your app is in development mode.
73
+ *
74
+ * ```ts
75
+ * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query'
76
+ * import { withDevtools } from '@tanstack/angular-query-devtools'
77
+ *
78
+ * bootstrapApplication(AppComponent, {
79
+ * providers: [
80
+ * provideTanStackQuery(() => new QueryClient(), withDevtools()),
81
+ * ],
82
+ * })
83
+ * ```
84
+ */
41
85
  function provideTanStackQuery(queryClientFactory, ...features) {
42
- return makeEnvironmentProviders([
43
- {
44
- provide: QueryClient,
45
- useFactory: () => injectQueryZone()(queryClientFactory)
46
- },
47
- ...features.map(getQueryFeatureProviders),
48
- provideEnvironmentInitializer(configureQueryClient)
49
- ]);
86
+ return makeEnvironmentProviders([
87
+ {
88
+ provide: QueryClient,
89
+ useFactory: () => injectQueryZone()(queryClientFactory)
90
+ },
91
+ ...features.map(getQueryFeatureProviders),
92
+ provideEnvironmentInitializer(configureQueryClient)
93
+ ]);
50
94
  }
51
- const queryFeatureBrand = /* @__PURE__ */ Symbol("QueryFeature");
95
+ var queryFeatureBrand = Symbol("QueryFeature");
96
+ /**
97
+ * Creates a feature shared by Angular Query integration packages.
98
+ * @internal
99
+ * @param providers - Providers owned by this Query feature.
100
+ * @returns An opaque feature that installs the supplied environment providers.
101
+ */
52
102
  function queryFeature(providers) {
53
- const feature = {
54
- [queryFeatureBrand]: true,
55
- ɵproviders: providers
56
- };
57
- return feature;
103
+ return {
104
+ [queryFeatureBrand]: true,
105
+ ɵproviders: providers
106
+ };
58
107
  }
108
+ /**
109
+ * Gets the environment providers owned by an opaque Query feature.
110
+ * @internal
111
+ * @param feature - The feature to unwrap.
112
+ * @returns The environment providers to install.
113
+ */
59
114
  function getQueryFeatureProviders(feature) {
60
- return feature.ɵproviders;
115
+ return feature.ɵproviders;
61
116
  }
117
+ /**
118
+ * Sets a non-default serialization key for this injector's `QueryClient` cache (server dehydrate /
119
+ * browser hydrate via `TransferState`). Use this when you have multiple `QueryClient` instances
120
+ * so each has its own key. The default key applies when you do not add this feature.
121
+ *
122
+ * ```ts
123
+ * providers: [
124
+ * provideTanStackQuery(
125
+ * () => new QueryClient(),
126
+ * withHydrationKey('my-secondary-query-cache'),
127
+ * ),
128
+ * ]
129
+ * ```
130
+ * @param key - A unique string for this client's `TransferState` entry.
131
+ * @returns A feature that stores this client's cache under the supplied key.
132
+ */
62
133
  function withHydrationKey(key) {
63
- return queryFeature(
64
- makeEnvironmentProviders([
65
- {
66
- provide: INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY,
67
- useValue: makeStateKey(key)
68
- }
69
- ])
70
- );
134
+ return queryFeature(makeEnvironmentProviders([{
135
+ provide: INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY,
136
+ useValue: makeStateKey(key)
137
+ }]));
71
138
  }
139
+ /**
140
+ * Disables `TransferState` hydration and dehydration for the current environment injector.
141
+ * @returns A feature that prevents automatic cache transfer for this injector.
142
+ */
72
143
  function withNoQueryHydration() {
73
- return queryFeature(
74
- makeEnvironmentProviders([
75
- {
76
- provide: INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE,
77
- useValue: false
78
- }
79
- ])
80
- );
144
+ return queryFeature(makeEnvironmentProviders([{
145
+ provide: INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE,
146
+ useValue: false
147
+ }]));
81
148
  }
82
- export {
83
- getQueryFeatureProviders,
84
- provideTanStackQuery,
85
- queryFeature,
86
- withHydrationKey,
87
- withNoQueryHydration
88
- };
89
- //# sourceMappingURL=providers.mjs.map
149
+ //#endregion
150
+ export { getQueryFeatureProviders, provideTanStackQuery, queryFeature, withHydrationKey, withNoQueryHydration };
151
+
152
+ //# sourceMappingURL=providers.mjs.map
package/providers.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"providers.mjs","sources":["../src/providers.ts"],"sourcesContent":["import { isPlatformBrowser, isPlatformServer } from '@angular/common'\nimport {\n DOCUMENT,\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n TransferState,\n inject,\n makeEnvironmentProviders,\n makeStateKey,\n provideEnvironmentInitializer,\n} from '@angular/core'\nimport { QueryClient, dehydrate, hydrate } from '@tanstack/query-core'\nimport { INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY } from './hydration-state-key'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport type { DehydratedState } from '@tanstack/query-core'\nimport type { EnvironmentProviders } from '@angular/core'\n\nconst INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE = new InjectionToken<boolean>('', {\n providedIn: 'root',\n factory: () => true,\n})\n\nfunction configureQueryClient() {\n const queryClient = inject(QueryClient)\n const destroyRef = inject(DestroyRef)\n const platformId = inject(PLATFORM_ID)\n\n if (isPlatformServer(platformId)) {\n // DOM emulation can fool core's runtime detection. Apply server defaults to\n // this client without changing other clients or global scheduling providers.\n const defaults = queryClient.getDefaultOptions()\n queryClient.setDefaultOptions({\n ...defaults,\n queries: { gcTime: Infinity, retry: false, ...defaults.queries },\n mutations: { gcTime: Infinity, ...defaults.mutations },\n })\n }\n const shouldHydrate = inject(INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE)\n const hydrationStateKey = inject(\n INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY,\n )\n\n if (inject(DOCUMENT, { optional: true })) {\n const transferState = inject(TransferState)\n\n if (shouldHydrate && isPlatformServer(platformId)) {\n transferState.onSerialize(hydrationStateKey, () => dehydrate(queryClient))\n } else if (shouldHydrate && isPlatformBrowser(platformId)) {\n const dehydratedState = transferState.get(hydrationStateKey, null)\n if (dehydratedState) {\n hydrate(queryClient, dehydratedState)\n transferState.remove(hydrationStateKey)\n }\n }\n }\n\n queryClient.mount()\n destroyRef.onDestroy(() => queryClient.unmount())\n}\n\n/**\n * Provides a `QueryClient` and optional TanStack Query features.\n * The factory runs once per injector in Angular's injection context, so it can\n * call `inject()` and each SSR request can receive an independent cache.\n *\n * **Example - standalone**\n *\n * @example\n * ```ts\n * import {\n * provideTanStackQuery,\n * QueryClient,\n * } from '@tanstack/angular-query'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(() => new QueryClient())],\n * })\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 *\n * ```ts\n * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query'\n * import { withDevtools } from '@tanstack/angular-query-devtools'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideTanStackQuery(() => new QueryClient(), withDevtools()),\n * ],\n * })\n * ```\n *\n * @param queryClientFactory - Creates or resolves a `QueryClient` in the injection context.\n * @param features - Optional features to configure additional Query functionality.\n * @returns A single {@link EnvironmentProviders} value (do not spread into `providers`).\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @see https://tanstack.com/query/v5/docs/framework/angular/devtools\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/ssr\n */\nexport function provideTanStackQuery(\n queryClientFactory: () => QueryClient,\n ...features: ReadonlyArray<QueryFeature>\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: QueryClient,\n useFactory: () => injectQueryZone()(queryClientFactory),\n },\n ...features.map(getQueryFeatureProviders),\n provideEnvironmentInitializer(configureQueryClient),\n ])\n}\n\nconst queryFeatureBrand: unique symbol = Symbol('QueryFeature')\n\n/**\n * Opaque configuration returned by Query feature functions such as `withHydrationKey`.\n * Pass features to `provideTanStackQuery`; applications do not construct them directly.\n */\nexport interface QueryFeature {\n /** @internal */\n readonly [queryFeatureBrand]: true\n}\n\ninterface InternalQueryFeature extends QueryFeature {\n readonly ɵproviders: EnvironmentProviders\n}\n\n/**\n * Creates a feature shared by Angular Query integration packages.\n * @internal\n * @param providers -\n * @returns A Query feature.\n */\nexport function queryFeature(providers: EnvironmentProviders): QueryFeature {\n const feature: InternalQueryFeature = {\n [queryFeatureBrand]: true,\n ɵproviders: providers,\n }\n\n return feature\n}\n\n/** @internal */\nexport function getQueryFeatureProviders(\n feature: QueryFeature,\n): EnvironmentProviders {\n return (feature as InternalQueryFeature).ɵproviders\n}\n\n/**\n * Sets a non-default serialization key for this injector's `QueryClient` cache (server dehydrate /\n * browser hydrate via `TransferState`). Use this when you have multiple `QueryClient` instances\n * so each has its own key. The default key applies when you do not add this feature.\n *\n * ```ts\n * providers: [\n * provideTanStackQuery(\n * () => new QueryClient(),\n * withHydrationKey('my-secondary-query-cache'),\n * ),\n * ]\n * ```\n *\n * @param key - A unique string for this client's `TransferState` entry.\n */\nexport function withHydrationKey(key: string): QueryFeature {\n return queryFeature(\n makeEnvironmentProviders([\n {\n provide: INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY,\n useValue: makeStateKey<DehydratedState>(key),\n },\n ]),\n )\n}\n\n/**\n * Disables `TransferState` hydration and dehydration for the current environment injector.\n */\nexport function withNoQueryHydration(): QueryFeature {\n return queryFeature(\n makeEnvironmentProviders([\n {\n provide: INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE,\n useValue: false,\n },\n ]),\n )\n}\n"],"names":[],"mappings":";;;;;AAkBA,MAAM,uCAAuC,IAAI,eAAwB,IAAI;AAAA,EAC3E,YAAY;AAAA,EACZ,SAAS,MAAM;AACjB,CAAC;AAED,SAAS,uBAAuB;AAC9B,QAAM,cAAc,OAAO,WAAW;AACtC,QAAM,aAAa,OAAO,UAAU;AACpC,QAAM,aAAa,OAAO,WAAW;AAErC,MAAI,iBAAiB,UAAU,GAAG;AAGhC,UAAM,WAAW,YAAY,kBAAA;AAC7B,gBAAY,kBAAkB;AAAA,MAC5B,GAAG;AAAA,MACH,SAAS,EAAE,QAAQ,UAAU,OAAO,OAAO,GAAG,SAAS,QAAA;AAAA,MACvD,WAAW,EAAE,QAAQ,UAAU,GAAG,SAAS,UAAA;AAAA,IAAU,CACtD;AAAA,EACH;AACA,QAAM,gBAAgB,OAAO,oCAAoC;AACjE,QAAM,oBAAoB;AAAA,IACxB;AAAA,EAAA;AAGF,MAAI,OAAO,UAAU,EAAE,UAAU,KAAA,CAAM,GAAG;AACxC,UAAM,gBAAgB,OAAO,aAAa;AAE1C,QAAI,iBAAiB,iBAAiB,UAAU,GAAG;AACjD,oBAAc,YAAY,mBAAmB,MAAM,UAAU,WAAW,CAAC;AAAA,IAC3E,WAAW,iBAAiB,kBAAkB,UAAU,GAAG;AACzD,YAAM,kBAAkB,cAAc,IAAI,mBAAmB,IAAI;AACjE,UAAI,iBAAiB;AACnB,gBAAQ,aAAa,eAAe;AACpC,sBAAc,OAAO,iBAAiB;AAAA,MACxC;AAAA,IACF;AAAA,EACF;AAEA,cAAY,MAAA;AACZ,aAAW,UAAU,MAAM,YAAY,QAAA,CAAS;AAClD;AA0CO,SAAS,qBACd,uBACG,UACmB;AACtB,SAAO,yBAAyB;AAAA,IAC9B;AAAA,MACE,SAAS;AAAA,MACT,YAAY,MAAM,gBAAA,EAAkB,kBAAkB;AAAA,IAAA;AAAA,IAExD,GAAG,SAAS,IAAI,wBAAwB;AAAA,IACxC,8BAA8B,oBAAoB;AAAA,EAAA,CACnD;AACH;AAEA,MAAM,2CAA0C,cAAc;AAqBvD,SAAS,aAAa,WAA+C;AAC1E,QAAM,UAAgC;AAAA,IACpC,CAAC,iBAAiB,GAAG;AAAA,IACrB,YAAY;AAAA,EAAA;AAGd,SAAO;AACT;AAGO,SAAS,yBACd,SACsB;AACtB,SAAQ,QAAiC;AAC3C;AAkBO,SAAS,iBAAiB,KAA2B;AAC1D,SAAO;AAAA,IACL,yBAAyB;AAAA,MACvB;AAAA,QACE,SAAS;AAAA,QACT,UAAU,aAA8B,GAAG;AAAA,MAAA;AAAA,IAC7C,CACD;AAAA,EAAA;AAEL;AAKO,SAAS,uBAAqC;AACnD,SAAO;AAAA,IACL,yBAAyB;AAAA,MACvB;AAAA,QACE,SAAS;AAAA,QACT,UAAU;AAAA,MAAA;AAAA,IACZ,CACD;AAAA,EAAA;AAEL;"}
1
+ {"version":3,"file":"providers.mjs","names":[],"sources":["../src/providers.ts"],"sourcesContent":["import { isPlatformBrowser, isPlatformServer } from '@angular/common'\nimport {\n DOCUMENT,\n DestroyRef,\n InjectionToken,\n PLATFORM_ID,\n TransferState,\n inject,\n makeEnvironmentProviders,\n makeStateKey,\n provideEnvironmentInitializer,\n} from '@angular/core'\nimport { QueryClient, dehydrate, hydrate } from '@tanstack/query-core'\nimport { INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY } from './hydration-state-key'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport type { DehydratedState } from '@tanstack/query-core'\nimport type { EnvironmentProviders } from '@angular/core'\n\nconst INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE = new InjectionToken<boolean>('', {\n providedIn: 'root',\n factory: () => true,\n})\n\n/**\n * Mounts the injected client, configures server defaults, and connects TransferState hydration.\n */\nfunction configureQueryClient() {\n const queryClient = inject(QueryClient)\n const destroyRef = inject(DestroyRef)\n const platformId = inject(PLATFORM_ID)\n\n if (isPlatformServer(platformId)) {\n // DOM emulation can fool core's runtime detection. Apply server defaults to\n // this client without changing other clients or global scheduling providers.\n const defaults = queryClient.getDefaultOptions()\n queryClient.setDefaultOptions({\n ...defaults,\n queries: { gcTime: Infinity, retry: false, ...defaults.queries },\n mutations: { gcTime: Infinity, ...defaults.mutations },\n })\n }\n const shouldHydrate = inject(INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE)\n const hydrationStateKey = inject(\n INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY,\n )\n\n if (inject(DOCUMENT, { optional: true })) {\n const transferState = inject(TransferState)\n\n if (shouldHydrate && isPlatformServer(platformId)) {\n transferState.onSerialize(hydrationStateKey, () => dehydrate(queryClient))\n } else if (shouldHydrate && isPlatformBrowser(platformId)) {\n const dehydratedState = transferState.get(hydrationStateKey, null)\n if (dehydratedState) {\n hydrate(queryClient, dehydratedState)\n transferState.remove(hydrationStateKey)\n }\n }\n }\n\n queryClient.mount()\n destroyRef.onDestroy(() => queryClient.unmount())\n}\n\n/**\n * Provides a `QueryClient` and optional TanStack Query features.\n * The factory runs once per injector in Angular's injection context, so it can\n * call `inject()` and each SSR request can receive an independent cache.\n * @param queryClientFactory - Creates or resolves a `QueryClient` in the injection context.\n * @param features - Optional features to configure additional Query functionality.\n * @returns A single {@link EnvironmentProviders} value (do not spread into `providers`).\n * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start\n * @see https://tanstack.com/query/v5/docs/framework/angular/devtools\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/ssr\n * @example\n * ```ts\n * import {\n * provideTanStackQuery,\n * QueryClient,\n * } from '@tanstack/angular-query'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [provideTanStackQuery(() => new QueryClient())],\n * })\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 *\n * ```ts\n * import { provideTanStackQuery, QueryClient } from '@tanstack/angular-query'\n * import { withDevtools } from '@tanstack/angular-query-devtools'\n *\n * bootstrapApplication(AppComponent, {\n * providers: [\n * provideTanStackQuery(() => new QueryClient(), withDevtools()),\n * ],\n * })\n * ```\n */\nexport function provideTanStackQuery(\n queryClientFactory: () => QueryClient,\n ...features: ReadonlyArray<QueryFeature>\n): EnvironmentProviders {\n return makeEnvironmentProviders([\n {\n provide: QueryClient,\n useFactory: () => injectQueryZone()(queryClientFactory),\n },\n ...features.map(getQueryFeatureProviders),\n provideEnvironmentInitializer(configureQueryClient),\n ])\n}\n\nconst queryFeatureBrand: unique symbol = Symbol('QueryFeature')\n\n/**\n * Opaque configuration returned by Query feature functions such as `withHydrationKey`.\n * Pass features to `provideTanStackQuery`; applications do not construct them directly.\n */\nexport interface QueryFeature {\n /** @internal */\n readonly [queryFeatureBrand]: true\n}\n\ninterface InternalQueryFeature extends QueryFeature {\n readonly ɵproviders: EnvironmentProviders\n}\n\n/**\n * Creates a feature shared by Angular Query integration packages.\n * @internal\n * @param providers - Providers owned by this Query feature.\n * @returns An opaque feature that installs the supplied environment providers.\n */\nexport function queryFeature(providers: EnvironmentProviders): QueryFeature {\n const feature: InternalQueryFeature = {\n [queryFeatureBrand]: true,\n ɵproviders: providers,\n }\n\n return feature\n}\n\n/**\n * Gets the environment providers owned by an opaque Query feature.\n * @internal\n * @param feature - The feature to unwrap.\n * @returns The environment providers to install.\n */\nexport function getQueryFeatureProviders(\n feature: QueryFeature,\n): EnvironmentProviders {\n return (feature as InternalQueryFeature).ɵproviders\n}\n\n/**\n * Sets a non-default serialization key for this injector's `QueryClient` cache (server dehydrate /\n * browser hydrate via `TransferState`). Use this when you have multiple `QueryClient` instances\n * so each has its own key. The default key applies when you do not add this feature.\n *\n * ```ts\n * providers: [\n * provideTanStackQuery(\n * () => new QueryClient(),\n * withHydrationKey('my-secondary-query-cache'),\n * ),\n * ]\n * ```\n * @param key - A unique string for this client's `TransferState` entry.\n * @returns A feature that stores this client's cache under the supplied key.\n */\nexport function withHydrationKey(key: string): QueryFeature {\n return queryFeature(\n makeEnvironmentProviders([\n {\n provide: INTERNAL_TANSTACK_QUERY_HYDRATION_TRANSFER_KEY,\n useValue: makeStateKey<DehydratedState>(key),\n },\n ]),\n )\n}\n\n/**\n * Disables `TransferState` hydration and dehydration for the current environment injector.\n * @returns A feature that prevents automatic cache transfer for this injector.\n */\nexport function withNoQueryHydration(): QueryFeature {\n return queryFeature(\n makeEnvironmentProviders([\n {\n provide: INTERNAL_QUERY_CLIENT_SHOULD_HYDRATE,\n useValue: false,\n },\n ]),\n )\n}\n"],"mappings":";;;;;;AAkBA,IAAM,uCAAuC,IAAI,eAAwB,IAAI;CAC3E,YAAY;CACZ,eAAe;AACjB,CAAC;;;;AAKD,SAAS,uBAAuB;CAC9B,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,aAAa,OAAO,UAAU;CACpC,MAAM,aAAa,OAAO,WAAW;CAErC,IAAI,iBAAiB,UAAU,GAAG;EAGhC,MAAM,WAAW,YAAY,kBAAkB;EAC/C,YAAY,kBAAkB;GAC5B,GAAG;GACH,SAAS;IAAE,QAAQ;IAAU,OAAO;IAAO,GAAG,SAAS;GAAQ;GAC/D,WAAW;IAAE,QAAQ;IAAU,GAAG,SAAS;GAAU;EACvD,CAAC;CACH;CACA,MAAM,gBAAgB,OAAO,oCAAoC;CACjE,MAAM,oBAAoB,OACxB,8CACF;CAEA,IAAI,OAAO,UAAU,EAAE,UAAU,KAAK,CAAC,GAAG;EACxC,MAAM,gBAAgB,OAAO,aAAa;EAE1C,IAAI,iBAAiB,iBAAiB,UAAU,GAC9C,cAAc,YAAY,yBAAyB,UAAU,WAAW,CAAC;OACpE,IAAI,iBAAiB,kBAAkB,UAAU,GAAG;GACzD,MAAM,kBAAkB,cAAc,IAAI,mBAAmB,IAAI;GACjE,IAAI,iBAAiB;IACnB,QAAQ,aAAa,eAAe;IACpC,cAAc,OAAO,iBAAiB;GACxC;EACF;CACF;CAEA,YAAY,MAAM;CAClB,WAAW,gBAAgB,YAAY,QAAQ,CAAC;AAClD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsCA,SAAgB,qBACd,oBACA,GAAG,UACmB;CACtB,OAAO,yBAAyB;EAC9B;GACE,SAAS;GACT,kBAAkB,gBAAgB,CAAC,CAAC,kBAAkB;EACxD;EACA,GAAG,SAAS,IAAI,wBAAwB;EACxC,8BAA8B,oBAAoB;CACpD,CAAC;AACH;AAEA,IAAM,oBAAmC,OAAO,cAAc;;;;;;;AAqB9D,SAAgB,aAAa,WAA+C;CAM1E,OAAO;GAJJ,oBAAoB;EACrB,YAAY;CAGP;AACT;;;;;;;AAQA,SAAgB,yBACd,SACsB;CACtB,OAAQ,QAAiC;AAC3C;;;;;;;;;;;;;;;;;AAkBA,SAAgB,iBAAiB,KAA2B;CAC1D,OAAO,aACL,yBAAyB,CACvB;EACE,SAAS;EACT,UAAU,aAA8B,GAAG;CAC7C,CACF,CAAC,CACH;AACF;;;;;AAMA,SAAgB,uBAAqC;CACnD,OAAO,aACL,yBAAyB,CACvB;EACE,SAAS;EACT,UAAU;CACZ,CACF,CAAC,CACH;AACF"}
@@ -3,7 +3,6 @@ import { CreateQueryOptions } from './types.js';
3
3
  /**
4
4
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set — `data` may be
5
5
  * `undefined` while the query is `pending`.
6
- *
7
6
  * @template TQueryFnData - The type your `queryFn` resolves to.
8
7
  * @template TError - The type of errors your `queryFn` may throw.
9
8
  * @template TData - The type `data` ends up as after `select` runs.
@@ -22,7 +21,6 @@ export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = Default
22
21
  /**
23
22
  * The options accepted by the `queryOptions` overload selected when no `initialData` is set and `queryFn` is
24
23
  * not `skipToken` — same as {@link UndefinedInitialDataOptions}, but `queryFn` may not be `skipToken`.
25
- *
26
24
  * @template TQueryFnData - The type your `queryFn` resolves to.
27
25
  * @template TError - The type of errors your `queryFn` may throw.
28
26
  * @template TData - The type `data` ends up as after `select` runs.
@@ -40,7 +38,6 @@ export type UnusedSkipTokenOptions<TQueryFnData = unknown, TError = DefaultError
40
38
  /**
41
39
  * The options accepted by the `queryOptions` overload selected when `initialData` is set — `data` is never
42
40
  * `undefined` (unless a `select` changes `TData` to include `undefined`).
43
- *
44
41
  * @template TQueryFnData - The type your `queryFn` resolves to.
45
42
  * @template TError - The type of errors your `queryFn` may throw.
46
43
  * @template TData - The type `data` ends up as after `select` runs.
@@ -56,13 +53,11 @@ export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultEr
56
53
  *
57
54
  * This overload is selected when `initialData` is set, so the resulting `data` is never `undefined` (unless
58
55
  * a `select` changes `TData` to include `undefined`).
59
- *
60
- * @see {@link injectQuery} to run a query with these options.
61
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
62
56
  * @param options - The {@link DefinedInitialDataOptions} to use — everything you can pass to `injectQuery`,
63
57
  * with `initialData` set.
64
58
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
65
- *
59
+ * @see {@link injectQuery} to run a query with these options.
60
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
66
61
  * @example
67
62
  * ```angular-ts
68
63
  * import { queryOptions, injectQuery } from '@tanstack/angular-query'
@@ -98,12 +93,10 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
98
93
  * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
99
94
  * can be shared across functions and imperative APIs such as `queryClient.query`. `options.queryKey` is
100
95
  * required and is the query key to generate options for.
101
- *
102
- * @see {@link injectQuery} to run a query with these options.
103
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
104
96
  * @param options - The {@link UnusedSkipTokenOptions} to use — everything you can pass to `injectQuery`.
105
97
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
106
- *
98
+ * @see {@link injectQuery} to run a query with these options.
99
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
107
100
  * @example
108
101
  * A parameterized factory, so the same options object can be reused per `id`:
109
102
  * ```angular-ts
@@ -138,13 +131,11 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
138
131
  * You can generally pass everything to `queryOptions` that you can also pass to `injectQuery`. These options
139
132
  * can be shared across functions and imperative APIs such as `queryClient.query`. `options.queryKey` is
140
133
  * required and is the query key to generate options for.
141
- *
142
- * @see {@link injectQuery} to run a query with these options.
143
- * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
144
134
  * @param options - The {@link UndefinedInitialDataOptions} to use — everything you can pass to `injectQuery`.
145
135
  * @returns The same options object, typed so that `queryKey` carries the inferred data type.
146
136
  * @remarks This is the only overload that accepts `queryFn: skipToken`, shown below.
147
- *
137
+ * @see {@link injectQuery} to run a query with these options.
138
+ * @see [The Query Options API](https://tkdodo.eu/blog/the-query-options-api) for more on this pattern.
148
139
  * @example
149
140
  * A parameterized factory, so the same options object can be reused per `id`:
150
141
  * ```angular-ts
@@ -173,7 +164,6 @@ export declare function queryOptions<TQueryFnData = unknown, TError = DefaultErr
173
164
  * readonly postQuery = injectQuery(() => postOptions(this.id()))
174
165
  * }
175
166
  * ```
176
- *
177
167
  * @example
178
168
  * A factory that disables the query, type safe, until `postId` is set:
179
169
  * ```angular-ts
package/query-options.mjs CHANGED
@@ -1,7 +1,8 @@
1
+ //#region src/query-options.ts
1
2
  function queryOptions(options) {
2
- return options;
3
+ return options;
3
4
  }
4
- export {
5
- queryOptions
6
- };
7
- //# sourceMappingURL=query-options.mjs.map
5
+ //#endregion
6
+ export { queryOptions };
7
+
8
+ //# sourceMappingURL=query-options.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"query-options.mjs","sources":["../src/query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\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> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\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.query`. `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'\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.query`. `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'\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.query`. `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'\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'\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"],"names":[],"mappings":"AAiRO,SAAS,aAAa,SAAkB;AAC7C,SAAO;AACT;"}
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 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 * @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 * @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 * @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> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData:\n | NonUndefinedGuard<TQueryFnData>\n | (() => NonUndefinedGuard<TQueryFnData>)\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.query`. `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 * @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 * @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 * @example\n * ```angular-ts\n * import { queryOptions, injectQuery } from '@tanstack/angular-query'\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.query`. `options.queryKey` is\n * required and is the query key to generate options for.\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 * @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 * @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'\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.query`. `options.queryKey` is\n * required and is the query key to generate options for.\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 * @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 * @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'\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 * @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'\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":";AAuQA,SAAgB,aAAa,SAAkB;CAC7C,OAAO;AACT"}
@@ -1,6 +1,9 @@
1
1
  import { QueryObserverResult } from '@tanstack/query-core';
2
2
  import { ResourceSnapshot } from './utils/resource-types.js';
3
3
  import { Resource, Signal } from '@angular/core';
4
+ /**
5
+ * A query-backed Angular Resource that also exposes an atomic state snapshot.
6
+ */
4
7
  export interface QueryResource<TValue> extends Resource<TValue> {
5
8
  /**
6
9
  * The current query state as a single snapshot.
@@ -11,7 +14,6 @@ export interface QueryResource<TValue> extends Resource<TValue> {
11
14
  *
12
15
  * Used for compatibility with Angular APIs that might want to reload a resource,
13
16
  * like Signal Forms' validateAsync resource interface.
14
- *
15
17
  * @returns `true` if a reload was initiated, `false` if a reload was unnecessary or unsupported.
16
18
  */
17
19
  reload: () => boolean;
@@ -28,8 +30,7 @@ type QueryResourceSource<TValue> = {
28
30
  * Converts an Angular Query result into Angular's Resource interface.
29
31
  *
30
32
  * Call this function once and reuse the returned resource.
31
- *
32
- * @param query An Angular Query or infinite-query result.
33
+ * @param query - An Angular Query or infinite-query result.
33
34
  * @returns A Resource-compatible view of the query result.
34
35
  */
35
36
  export declare function toResource<TValue>(query: QueryResourceSource<TValue>): QueryResource<TValue>;