@tanstack/angular-query-experimental 5.33.0 → 5.34.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/README.md +19 -2
  2. package/build/README.md +19 -2
  3. package/build/create-base-query.d.ts +1 -1
  4. package/build/esm2022/create-base-query.mjs +3 -3
  5. package/build/esm2022/index.mjs +2 -2
  6. package/build/esm2022/infinite-query-options.mjs +9 -1
  7. package/build/esm2022/inject-infinite-query.mjs +11 -3
  8. package/build/esm2022/inject-is-fetching.mjs +11 -1
  9. package/build/esm2022/inject-is-mutating.mjs +10 -1
  10. package/build/esm2022/inject-mutation-state.mjs +8 -1
  11. package/build/esm2022/inject-mutation.mjs +13 -4
  12. package/build/esm2022/inject-queries.mjs +4 -1
  13. package/build/esm2022/inject-query-client.mjs +21 -3
  14. package/build/esm2022/inject-query.mjs +36 -3
  15. package/build/esm2022/providers.mjs +40 -1
  16. package/build/esm2022/query-options.mjs +23 -1
  17. package/build/esm2022/signal-proxy.mjs +2 -4
  18. package/build/esm2022/types.mjs +1 -1
  19. package/build/fesm2022/tanstack-angular-query-experimental.mjs +179 -14
  20. package/build/fesm2022/tanstack-angular-query-experimental.mjs.map +1 -1
  21. package/build/index.d.ts +1 -1
  22. package/build/infinite-query-options.d.ts +16 -0
  23. package/build/inject-infinite-query.d.ts +27 -3
  24. package/build/inject-is-fetching.d.ts +10 -0
  25. package/build/inject-is-mutating.d.ts +9 -0
  26. package/build/inject-mutation-state.d.ts +10 -0
  27. package/build/inject-mutation.d.ts +10 -1
  28. package/build/inject-queries.d.ts +5 -0
  29. package/build/inject-query-client.d.ts +20 -3
  30. package/build/inject-query.d.ts +102 -3
  31. package/build/providers.d.ts +39 -0
  32. package/build/query-options.d.ts +50 -0
  33. package/build/signal-proxy.d.ts +1 -3
  34. package/build/types.d.ts +51 -0
  35. package/package.json +2 -2
  36. package/src/__tests__/inject-mutation-state.test.ts +0 -2
  37. package/src/create-base-query.ts +2 -2
  38. package/src/index.ts +1 -5
  39. package/src/infinite-query-options.ts +24 -0
  40. package/src/inject-infinite-query.ts +37 -5
  41. package/src/inject-is-fetching.ts +10 -0
  42. package/src/inject-is-mutating.ts +9 -0
  43. package/src/inject-mutation-state.ts +10 -0
  44. package/src/inject-mutation.ts +12 -3
  45. package/src/inject-queries.ts +5 -0
  46. package/src/inject-query-client.ts +21 -3
  47. package/src/inject-query.ts +141 -9
  48. package/src/providers.ts +39 -0
  49. package/src/query-options.ts +72 -0
  50. package/src/signal-proxy.ts +1 -3
  51. package/src/types.ts +51 -0
@@ -2,6 +2,105 @@ import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core';
2
2
  import type { Injector } from '@angular/core';
3
3
  import type { CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult } from './types';
4
4
  import type { DefinedInitialDataOptions, UndefinedInitialDataOptions } from './query-options';
5
- export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: (client: QueryClient) => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): CreateQueryResult<TData, TError>;
6
- export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: (client: QueryClient) => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): DefinedCreateQueryResult<TData, TError>;
7
- export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: (client: QueryClient) => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): CreateQueryResult<TData, TError>;
5
+ /**
6
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
7
+ *
8
+ * **Basic example**
9
+ * ```ts
10
+ * class ServiceOrComponent {
11
+ * query = injectQuery(() => ({
12
+ * queryKey: ['repoData'],
13
+ * queryFn: () =>
14
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
15
+ * }))
16
+ * }
17
+ * ```
18
+ *
19
+ * **The options function can utilize signals**
20
+ * ```ts
21
+ * class ServiceOrComponent {
22
+ * filter = signal('')
23
+ *
24
+ * todosQuery = injectQuery(() => ({
25
+ * queryKey: ['todos', this.filter()],
26
+ * queryFn: () => fetchTodos(this.filter()),
27
+ * // Signals can be combined with expressions
28
+ * enabled: !!this.filter(),
29
+ * }))
30
+ * }
31
+ * ```
32
+ * @param optionsFn - A function that returns query options.
33
+ * @param injector - The Angular injector to use.
34
+ * @returns The query result.
35
+ * @public
36
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
37
+ */
38
+ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(optionsFn: (client: QueryClient) => DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): DefinedCreateQueryResult<TData, TError>;
39
+ /**
40
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
41
+ *
42
+ * **Basic example**
43
+ * ```ts
44
+ * class ServiceOrComponent {
45
+ * query = injectQuery(() => ({
46
+ * queryKey: ['repoData'],
47
+ * queryFn: () =>
48
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
49
+ * }))
50
+ * }
51
+ * ```
52
+ *
53
+ * **The options function can utilize signals**
54
+ * ```ts
55
+ * class ServiceOrComponent {
56
+ * filter = signal('')
57
+ *
58
+ * todosQuery = injectQuery(() => ({
59
+ * queryKey: ['todos', this.filter()],
60
+ * queryFn: () => fetchTodos(this.filter()),
61
+ * // Signals can be combined with expressions
62
+ * enabled: !!this.filter(),
63
+ * }))
64
+ * }
65
+ * ```
66
+ * @param optionsFn - A function that returns query options.
67
+ * @param injector - The Angular injector to use.
68
+ * @returns The query result.
69
+ * @public
70
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
71
+ */
72
+ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(optionsFn: (client: QueryClient) => UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): CreateQueryResult<TData, TError>;
73
+ /**
74
+ * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
75
+ *
76
+ * **Basic example**
77
+ * ```ts
78
+ * class ServiceOrComponent {
79
+ * query = injectQuery(() => ({
80
+ * queryKey: ['repoData'],
81
+ * queryFn: () =>
82
+ * this.#http.get<Response>('https://api.github.com/repos/tanstack/query'),
83
+ * }))
84
+ * }
85
+ * ```
86
+ *
87
+ * **The options function can utilize signals**
88
+ * ```ts
89
+ * class ServiceOrComponent {
90
+ * filter = signal('')
91
+ *
92
+ * todosQuery = injectQuery(() => ({
93
+ * queryKey: ['todos', this.filter()],
94
+ * queryFn: () => fetchTodos(this.filter()),
95
+ * // Signals can be combined with expressions
96
+ * enabled: !!this.filter(),
97
+ * }))
98
+ * }
99
+ * ```
100
+ * @param optionsFn - A function that returns query options.
101
+ * @param injector - The Angular injector to use.
102
+ * @returns The query result.
103
+ * @public
104
+ * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
105
+ */
106
+ export declare function injectQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(optionsFn: (client: QueryClient) => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>, injector?: Injector): CreateQueryResult<TData, TError>;
@@ -1,3 +1,42 @@
1
1
  import type { EnvironmentProviders } from '@angular/core';
2
2
  import type { QueryClient } from '@tanstack/query-core';
3
+ /**
4
+ * Sets up providers necessary to enable TanStack Query functionality for Angular applications.
5
+ *
6
+ * Allows to configure a `QueryClient`.
7
+ *
8
+ * **Example - standalone**
9
+ *
10
+ * ```ts
11
+ * import {
12
+ * provideAngularQuery,
13
+ * QueryClient,
14
+ * } from '@tanstack/angular-query-experimental'
15
+ *
16
+ * bootstrapApplication(AppComponent, {
17
+ * providers: [provideAngularQuery(new QueryClient())],
18
+ * })
19
+ * ```
20
+ *
21
+ * **Example - NgModule-based**
22
+ *
23
+ * ```ts
24
+ * import {
25
+ * provideAngularQuery,
26
+ * QueryClient,
27
+ * } from '@tanstack/angular-query-experimental'
28
+ *
29
+ * @NgModule({
30
+ * declarations: [AppComponent],
31
+ * imports: [BrowserModule],
32
+ * providers: [provideAngularQuery(new QueryClient())],
33
+ * bootstrap: [AppComponent],
34
+ * })
35
+ * export class AppModule {}
36
+ * ```
37
+ * @param queryClient - A `QueryClient` instance.
38
+ * @returns A set of providers to set up TanStack Query.
39
+ * @public
40
+ * @see https://tanstack.com/query/v5/docs/framework/angular/quick-start
41
+ */
3
42
  export declare function provideAngularQuery(queryClient: QueryClient): EnvironmentProviders;
@@ -1,15 +1,65 @@
1
1
  import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core';
2
2
  import type { CreateQueryOptions } from './types';
3
+ /**
4
+ * @public
5
+ */
3
6
  export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
4
7
  initialData?: undefined;
5
8
  };
6
9
  type NonUndefinedGuard<T> = T extends undefined ? never : T;
10
+ /**
11
+ * @public
12
+ */
7
13
  export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
8
14
  initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
9
15
  };
16
+ /**
17
+ * Allows to share and re-use query options in a type-safe way.
18
+ *
19
+ * The `queryKey` will be tagged with the type from `queryFn`.
20
+ *
21
+ * **Example**
22
+ *
23
+ * ```ts
24
+ * const { queryKey } = queryOptions({
25
+ * queryKey: ['key'],
26
+ * queryFn: () => Promise.resolve(5),
27
+ * // ^? Promise<number>
28
+ * })
29
+ *
30
+ * const queryClient = new QueryClient()
31
+ * const data = queryClient.getQueryData(queryKey)
32
+ * // ^? number | undefined
33
+ * ```
34
+ * @param options - The query options to tag with the type from `queryFn`.
35
+ * @returns The tagged query options.
36
+ * @public
37
+ */
10
38
  export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
11
39
  queryKey: DataTag<TQueryKey, TQueryFnData>;
12
40
  };
41
+ /**
42
+ * Allows to share and re-use query options in a type-safe way.
43
+ *
44
+ * The `queryKey` will be tagged with the type from `queryFn`.
45
+ *
46
+ * **Example**
47
+ *
48
+ * ```ts
49
+ * const { queryKey } = queryOptions({
50
+ * queryKey: ['key'],
51
+ * queryFn: () => Promise.resolve(5),
52
+ * // ^? Promise<number>
53
+ * })
54
+ *
55
+ * const queryClient = new QueryClient()
56
+ * const data = queryClient.getQueryData(queryKey)
57
+ * // ^? number | undefined
58
+ * ```
59
+ * @param options - The query options to tag with the type from `queryFn`.
60
+ * @returns The tagged query options.
61
+ * @public
62
+ */
13
63
  export declare function queryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
14
64
  queryKey: DataTag<TQueryKey, TQueryFnData>;
15
65
  };
@@ -4,10 +4,8 @@ export type MapToSignals<T> = {
4
4
  };
5
5
  /**
6
6
  * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
7
- *
8
7
  * Functions on the object are passed through as-is.
9
- *
10
8
  * @param inputSignal - `Signal` that must return an object.
11
- *
9
+ * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
12
10
  */
13
11
  export declare function signalProxy<TInput extends Record<string | symbol, any>>(inputSignal: Signal<TInput>): MapToSignals<TInput>;
package/build/types.d.ts CHANGED
@@ -1,42 +1,93 @@
1
1
  import type { DefaultError, DefinedInfiniteQueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, MutationObserverOptions, MutationObserverResult, OmitKeyof, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
2
2
  import type { MapToSignals } from './signal-proxy';
3
+ /**
4
+ * @public
5
+ */
3
6
  export interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
4
7
  }
8
+ /**
9
+ * @public
10
+ */
5
11
  export interface CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends OmitKeyof<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'suspense'> {
6
12
  }
13
+ /**
14
+ * @public
15
+ */
7
16
  type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
8
17
  status: TStatus;
9
18
  }>;
19
+ /**
20
+ * @public
21
+ */
10
22
  export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
11
23
  isSuccess: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>;
12
24
  isError: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>;
13
25
  isPending: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>;
14
26
  }
27
+ /**
28
+ * @public
29
+ */
15
30
  export interface CreateInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> extends OmitKeyof<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey, TPageParam>, 'suspense'> {
16
31
  }
32
+ /**
33
+ * @public
34
+ */
17
35
  export type CreateBaseQueryResult<TData = unknown, TError = DefaultError, TState = QueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>;
36
+ /**
37
+ * @public
38
+ */
18
39
  export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
40
+ /**
41
+ * @public
42
+ */
19
43
  export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TDefinedQueryObserver = DefinedQueryObserverResult<TData, TError>> = MapToSignals<TDefinedQueryObserver>;
44
+ /**
45
+ * @public
46
+ */
20
47
  export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = MapToSignals<InfiniteQueryObserverResult<TData, TError>>;
48
+ /**
49
+ * @public
50
+ */
21
51
  export type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<TData, TError>> = MapToSignals<TDefinedInfiniteQueryObserver>;
52
+ /**
53
+ * @public
54
+ */
22
55
  export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> {
23
56
  }
57
+ /**
58
+ * @public
59
+ */
24
60
  export type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TContext>>) => void;
61
+ /**
62
+ * @public
63
+ */
25
64
  export type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = MutateFunction<TData, TError, TVariables, TContext>;
65
+ /**
66
+ * @public
67
+ */
26
68
  export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TContext>, {
27
69
  mutate: CreateMutateFunction<TData, TError, TVariables, TContext>;
28
70
  }> & {
29
71
  mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TContext>;
30
72
  };
73
+ /**
74
+ * @public
75
+ */
31
76
  type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TContext>, {
32
77
  status: TStatus;
33
78
  }>;
79
+ /**
80
+ * @public
81
+ */
34
82
  export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> {
35
83
  isSuccess: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TContext>>;
36
84
  isError: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TContext>>;
37
85
  isPending: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TContext>>;
38
86
  isIdle: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>>;
39
87
  }
88
+ /**
89
+ * @public
90
+ */
40
91
  export type CreateMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown, TState = CreateStatusBasedMutationResult<CreateBaseMutationResult['status'], TData, TError, TVariables, TContext>> = BaseMutationNarrowing<TData, TError, TVariables, TContext> & MapToSignals<OmitKeyof<TState, keyof BaseMutationNarrowing, 'safely'>>;
41
92
  type Override<TTargetA, TTargetB> = {
42
93
  [AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/angular-query-experimental",
3
- "version": "5.33.0",
3
+ "version": "5.34.2",
4
4
  "description": "Signals for managing, caching and syncing asynchronous and remote data in Angular",
5
5
  "author": "Arnoud de Vries",
6
6
  "license": "MIT",
@@ -34,7 +34,7 @@
34
34
  ],
35
35
  "dependencies": {
36
36
  "tslib": "^2.6.2",
37
- "@tanstack/query-core": "5.32.1"
37
+ "@tanstack/query-core": "5.34.2"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@analogjs/vite-plugin-angular": "^1.1.2",
@@ -3,7 +3,6 @@ import { QueryClient } from '@tanstack/query-core'
3
3
  import { TestBed } from '@angular/core/testing'
4
4
  import { describe, expect, test, vi } from 'vitest'
5
5
  import { By } from '@angular/platform-browser'
6
- import { JsonPipe } from '@angular/common'
7
6
  import { injectMutation } from '../inject-mutation'
8
7
  import { injectMutationState } from '../inject-mutation-state'
9
8
  import { provideAngularQuery } from '../providers'
@@ -139,7 +138,6 @@ describe('injectMutationState', () => {
139
138
  }
140
139
  `,
141
140
  standalone: true,
142
- imports: [JsonPipe],
143
141
  })
144
142
  class FakeComponent {
145
143
  name = input.required<string>()
@@ -31,7 +31,7 @@ export function createBaseQuery<
31
31
  TQueryData,
32
32
  TQueryKey extends QueryKey,
33
33
  >(
34
- options: (
34
+ optionsFn: (
35
35
  client: QueryClient,
36
36
  ) => CreateBaseQueryOptions<
37
37
  TQueryFnData,
@@ -57,7 +57,7 @@ export function createBaseQuery<
57
57
  */
58
58
  const defaultedOptionsSignal = computed(() => {
59
59
  const defaultedOptions = queryClient.defaultQueryOptions(
60
- options(queryClient),
60
+ optionsFn(queryClient),
61
61
  )
62
62
  defaultedOptions._optimisticResults = 'optimistic'
63
63
  return defaultedOptions
package/src/index.ts CHANGED
@@ -20,9 +20,5 @@ export * from './inject-mutation'
20
20
  export * from './inject-mutation-state'
21
21
  export * from './inject-queries'
22
22
  export * from './inject-query'
23
- export {
24
- injectQueryClient,
25
- provideQueryClient,
26
- QUERY_CLIENT,
27
- } from './inject-query-client'
23
+ export { injectQueryClient, provideQueryClient } from './inject-query-client'
28
24
  export { provideAngularQuery } from './providers'
@@ -41,6 +41,14 @@ export type DefinedInitialDataInfiniteOptions<
41
41
  | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)
42
42
  }
43
43
 
44
+ /**
45
+ * Allows to share and re-use infinite query options in a type-safe way.
46
+ *
47
+ * The `queryKey` will be tagged with the type from `queryFn`.
48
+ * @param options - The infinite query options to tag with the type from `queryFn`.
49
+ * @returns The tagged infinite query options.
50
+ * @public
51
+ */
44
52
  export function infiniteQueryOptions<
45
53
  TQueryFnData,
46
54
  TError = DefaultError,
@@ -65,6 +73,14 @@ export function infiniteQueryOptions<
65
73
  queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
66
74
  }
67
75
 
76
+ /**
77
+ * Allows to share and re-use infinite query options in a type-safe way.
78
+ *
79
+ * The `queryKey` will be tagged with the type from `queryFn`.
80
+ * @param options - The infinite query options to tag with the type from `queryFn`.
81
+ * @returns The tagged infinite query options.
82
+ * @public
83
+ */
68
84
  export function infiniteQueryOptions<
69
85
  TQueryFnData,
70
86
  TError = DefaultError,
@@ -89,6 +105,14 @@ export function infiniteQueryOptions<
89
105
  queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>
90
106
  }
91
107
 
108
+ /**
109
+ * Allows to share and re-use infinite query options in a type-safe way.
110
+ *
111
+ * The `queryKey` will be tagged with the type from `queryFn`.
112
+ * @param options - The infinite query options to tag with the type from `queryFn`.
113
+ * @returns The tagged infinite query options.
114
+ * @public
115
+ */
92
116
  export function infiniteQueryOptions(options: unknown) {
93
117
  return options
94
118
  }
@@ -20,6 +20,14 @@ import type {
20
20
  UndefinedInitialDataInfiniteOptions,
21
21
  } from './infinite-query-options'
22
22
 
23
+ /**
24
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
25
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
26
+ * @param optionsFn - A function that returns infinite query options.
27
+ * @param injector - The Angular injector to use.
28
+ * @returns The infinite query result.
29
+ * @public
30
+ */
23
31
  export function injectInfiniteQuery<
24
32
  TQueryFnData,
25
33
  TError = DefaultError,
@@ -27,7 +35,7 @@ export function injectInfiniteQuery<
27
35
  TQueryKey extends QueryKey = QueryKey,
28
36
  TPageParam = unknown,
29
37
  >(
30
- options: (
38
+ optionsFn: (
31
39
  client: QueryClient,
32
40
  ) => UndefinedInitialDataInfiniteOptions<
33
41
  TQueryFnData,
@@ -39,6 +47,14 @@ export function injectInfiniteQuery<
39
47
  injector?: Injector,
40
48
  ): CreateInfiniteQueryResult<TData, TError>
41
49
 
50
+ /**
51
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
52
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
53
+ * @param optionsFn - A function that returns infinite query options.
54
+ * @param injector - The Angular injector to use.
55
+ * @returns The infinite query result.
56
+ * @public
57
+ */
42
58
  export function injectInfiniteQuery<
43
59
  TQueryFnData,
44
60
  TError = DefaultError,
@@ -46,7 +62,7 @@ export function injectInfiniteQuery<
46
62
  TQueryKey extends QueryKey = QueryKey,
47
63
  TPageParam = unknown,
48
64
  >(
49
- options: (
65
+ optionsFn: (
50
66
  client: QueryClient,
51
67
  ) => DefinedInitialDataInfiniteOptions<
52
68
  TQueryFnData,
@@ -58,6 +74,14 @@ export function injectInfiniteQuery<
58
74
  injector?: Injector,
59
75
  ): DefinedCreateInfiniteQueryResult<TData, TError>
60
76
 
77
+ /**
78
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
79
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
80
+ * @param optionsFn - A function that returns infinite query options.
81
+ * @param injector - The Angular injector to use.
82
+ * @returns The infinite query result.
83
+ * @public
84
+ */
61
85
  export function injectInfiniteQuery<
62
86
  TQueryFnData,
63
87
  TError = DefaultError,
@@ -65,7 +89,7 @@ export function injectInfiniteQuery<
65
89
  TQueryKey extends QueryKey = QueryKey,
66
90
  TPageParam = unknown,
67
91
  >(
68
- options: (
92
+ optionsFn: (
69
93
  client: QueryClient,
70
94
  ) => CreateInfiniteQueryOptions<
71
95
  TQueryFnData,
@@ -78,14 +102,22 @@ export function injectInfiniteQuery<
78
102
  injector?: Injector,
79
103
  ): CreateInfiniteQueryResult<TData, TError>
80
104
 
105
+ /**
106
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
107
+ * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
108
+ * @param optionsFn - A function that returns infinite query options.
109
+ * @param injector - The Angular injector to use.
110
+ * @returns The infinite query result.
111
+ * @public
112
+ */
81
113
  export function injectInfiniteQuery(
82
- options: (client: QueryClient) => CreateInfiniteQueryOptions,
114
+ optionsFn: (client: QueryClient) => CreateInfiniteQueryOptions,
83
115
  injector?: Injector,
84
116
  ) {
85
117
  return assertInjector(injectInfiniteQuery, injector, () => {
86
118
  const queryClient = injectQueryClient()
87
119
  return createBaseQuery(
88
- options,
120
+ optionsFn,
89
121
  InfiniteQueryObserver as typeof QueryObserver,
90
122
  queryClient,
91
123
  )
@@ -4,6 +4,16 @@ import { assertInjector } from './util/assert-injector/assert-injector'
4
4
  import { injectQueryClient } from './inject-query-client'
5
5
  import type { Injector, Signal } from '@angular/core'
6
6
 
7
+ /**
8
+ * Injects a signal that tracks the number of queries that your application is loading or
9
+ * fetching in the background.
10
+ *
11
+ * Can be used for app-wide loading indicators
12
+ * @param filters - The filters to apply to the query.
13
+ * @param injector - The Angular injector to use.
14
+ * @returns signal with number of loading or fetching queries.
15
+ * @public
16
+ */
7
17
  export function injectIsFetching(
8
18
  filters?: QueryFilters,
9
19
  injector?: Injector,
@@ -4,6 +4,15 @@ import { assertInjector } from './util/assert-injector/assert-injector'
4
4
  import { injectQueryClient } from './inject-query-client'
5
5
  import type { Injector, Signal } from '@angular/core'
6
6
 
7
+ /**
8
+ * Injects a signal that tracks the number of mutations that your application is fetching.
9
+ *
10
+ * Can be used for app-wide loading indicators
11
+ * @param filters - The filters to apply to the query.
12
+ * @param injector - The Angular injector to use.
13
+ * @returns signal with number of fetching mutations.
14
+ * @public
15
+ */
7
16
  export function injectIsMutating(
8
17
  filters?: MutationFilters,
9
18
  injector?: Injector,
@@ -43,10 +43,20 @@ function getResult<TResult = MutationState>(
43
43
  )
44
44
  }
45
45
 
46
+ /**
47
+ * @public
48
+ */
46
49
  export interface InjectMutationStateOptions {
47
50
  injector?: Injector
48
51
  }
49
52
 
53
+ /**
54
+ * Injects a signal that tracks the state of all mutations.
55
+ * @param mutationStateOptionsFn - A function that returns mutation state options.
56
+ * @param options - The Angular injector to use.
57
+ * @returns The signal that tracks the state of all mutations.
58
+ * @public
59
+ */
50
60
  export function injectMutationState<TResult = MutationState>(
51
61
  mutationStateOptionsFn: () => MutationStateOptions<TResult> = () => ({}),
52
62
  options?: InjectMutationStateOptions,
@@ -26,13 +26,22 @@ import type {
26
26
  CreateMutationResult,
27
27
  } from './types'
28
28
 
29
+ /**
30
+ * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
31
+ *
32
+ * Unlike queries, mutations are not run automatically.
33
+ * @param optionsFn - A function that returns mutation options.
34
+ * @param injector - The Angular injector to use.
35
+ * @returns The mutation.
36
+ * @public
37
+ */
29
38
  export function injectMutation<
30
39
  TData = unknown,
31
40
  TError = DefaultError,
32
41
  TVariables = void,
33
42
  TContext = unknown,
34
43
  >(
35
- options: (
44
+ optionsFn: (
36
45
  client: QueryClient,
37
46
  ) => CreateMutationOptions<TData, TError, TVariables, TContext>,
38
47
  injector?: Injector,
@@ -50,7 +59,7 @@ export function injectMutation<
50
59
  TError,
51
60
  TVariables,
52
61
  TContext
53
- >(queryClient, options(queryClient))
62
+ >(queryClient, optionsFn(queryClient))
54
63
  const mutate: CreateMutateFunction<
55
64
  TData,
56
65
  TError,
@@ -61,7 +70,7 @@ export function injectMutation<
61
70
  }
62
71
 
63
72
  effect(() => {
64
- observer.setOptions(options(queryClient))
73
+ observer.setOptions(optionsFn(queryClient))
65
74
  })
66
75
 
67
76
  const result = signal(observer.getCurrentResult())
@@ -119,6 +119,7 @@ type GetResults<T> =
119
119
 
120
120
  /**
121
121
  * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
122
+ * @public
122
123
  */
123
124
  export type QueriesOptions<
124
125
  T extends Array<any>,
@@ -161,6 +162,7 @@ export type QueriesOptions<
161
162
 
162
163
  /**
163
164
  * QueriesResults reducer recursively maps type param to results
165
+ * @public
164
166
  */
165
167
  export type QueriesResults<
166
168
  T extends Array<any>,
@@ -196,6 +198,9 @@ export type QueriesResults<
196
198
  : // Fallback
197
199
  Array<QueryObserverResult>
198
200
 
201
+ /**
202
+ * @public
203
+ */
199
204
  export function injectQueries<
200
205
  T extends Array<any>,
201
206
  TCombinedResult = QueriesResults<T>,