@tanstack/angular-query-experimental 5.34.2 → 5.35.0

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 (59) hide show
  1. package/build/rollup.d.ts +591 -0
  2. package/package.json +9 -5
  3. package/build/create-base-query.d.ts +0 -6
  4. package/build/index.d.ts +0 -14
  5. package/build/infinite-query-options.d.ts +0 -34
  6. package/build/inject-infinite-query.d.ts +0 -31
  7. package/build/inject-is-fetching.d.ts +0 -13
  8. package/build/inject-is-mutating.d.ts +0 -12
  9. package/build/inject-mutation-state.d.ts +0 -21
  10. package/build/inject-mutation.d.ts +0 -13
  11. package/build/inject-queries.d.ts +0 -76
  12. package/build/inject-query-client.d.ts +0 -30
  13. package/build/inject-query.d.ts +0 -106
  14. package/build/providers.d.ts +0 -42
  15. package/build/query-options.d.ts +0 -66
  16. package/build/signal-proxy.d.ts +0 -11
  17. package/build/types.d.ts +0 -95
  18. package/build/util/assert-injector/assert-injector.d.ts +0 -54
  19. package/build/util/create-injection-token/create-injection-token.d.ts +0 -52
  20. package/build/util/index.d.ts +0 -2
  21. package/build/util/lazy-init/lazy-init.d.ts +0 -1
  22. package/build/util/lazy-signal-initializer/lazy-signal-initializer.d.ts +0 -4
  23. package/src/__tests__/inject-infinite-query.test.ts +0 -64
  24. package/src/__tests__/inject-is-fetching.test.ts +0 -35
  25. package/src/__tests__/inject-is-mutating.test.ts +0 -39
  26. package/src/__tests__/inject-mutation-state.test-d.ts +0 -22
  27. package/src/__tests__/inject-mutation-state.test.ts +0 -175
  28. package/src/__tests__/inject-mutation.test-d.ts +0 -71
  29. package/src/__tests__/inject-mutation.test.ts +0 -458
  30. package/src/__tests__/inject-query.test-d.ts +0 -59
  31. package/src/__tests__/inject-query.test.ts +0 -349
  32. package/src/__tests__/query-options.test-d.ts +0 -127
  33. package/src/__tests__/signal-proxy.test.ts +0 -27
  34. package/src/__tests__/test-utils.ts +0 -131
  35. package/src/__tests__/util/lazy-init/lazy-init.test.ts +0 -126
  36. package/src/__tests__/util/lazy-signal-initializer/lazy-signal-initializer.test.ts +0 -130
  37. package/src/create-base-query.ts +0 -116
  38. package/src/index.ts +0 -24
  39. package/src/infinite-query-options.ts +0 -118
  40. package/src/inject-infinite-query.ts +0 -125
  41. package/src/inject-is-fetching.ts +0 -49
  42. package/src/inject-is-mutating.ts +0 -48
  43. package/src/inject-mutation-state.ts +0 -107
  44. package/src/inject-mutation.ts +0 -118
  45. package/src/inject-queries.ts +0 -265
  46. package/src/inject-query-client.ts +0 -25
  47. package/src/inject-query.ts +0 -200
  48. package/src/providers.ts +0 -65
  49. package/src/query-options.ts +0 -122
  50. package/src/signal-proxy.ts +0 -46
  51. package/src/test-setup.ts +0 -12
  52. package/src/types.ts +0 -311
  53. package/src/util/assert-injector/assert-injector.test.ts +0 -74
  54. package/src/util/assert-injector/assert-injector.ts +0 -81
  55. package/src/util/create-injection-token/create-injection-token.test.ts +0 -32
  56. package/src/util/create-injection-token/create-injection-token.ts +0 -185
  57. package/src/util/index.ts +0 -13
  58. package/src/util/lazy-init/lazy-init.ts +0 -34
  59. package/src/util/lazy-signal-initializer/lazy-signal-initializer.ts +0 -28
@@ -1,34 +0,0 @@
1
- import type { DataTag } from '@tanstack/query-core';
2
- import type { InfiniteData } from '@tanstack/query-core';
3
- import type { CreateInfiniteQueryOptions } from './types';
4
- import type { DefaultError, QueryKey } from '@tanstack/query-core';
5
- export type UndefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam> & {
6
- initialData?: undefined;
7
- };
8
- type NonUndefinedGuard<T> = T extends undefined ? never : T;
9
- export type DefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam> & {
10
- initialData: NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>);
11
- };
12
- /**
13
- * Allows to share and re-use infinite query options in a type-safe way.
14
- *
15
- * The `queryKey` will be tagged with the type from `queryFn`.
16
- * @param options - The infinite query options to tag with the type from `queryFn`.
17
- * @returns The tagged infinite query options.
18
- * @public
19
- */
20
- export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
21
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
22
- };
23
- /**
24
- * Allows to share and re-use infinite query options in a type-safe way.
25
- *
26
- * The `queryKey` will be tagged with the type from `queryFn`.
27
- * @param options - The infinite query options to tag with the type from `queryFn`.
28
- * @returns The tagged infinite query options.
29
- * @public
30
- */
31
- export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
32
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
33
- };
34
- export {};
@@ -1,31 +0,0 @@
1
- import type { Injector } from '@angular/core';
2
- import type { DefaultError, InfiniteData, QueryClient, QueryKey } from '@tanstack/query-core';
3
- import type { CreateInfiniteQueryOptions, CreateInfiniteQueryResult, DefinedCreateInfiniteQueryResult } from './types';
4
- import type { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions } from './infinite-query-options';
5
- /**
6
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
7
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
8
- * @param optionsFn - A function that returns infinite query options.
9
- * @param injector - The Angular injector to use.
10
- * @returns The infinite query result.
11
- * @public
12
- */
13
- export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: (client: QueryClient) => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, injector?: Injector): CreateInfiniteQueryResult<TData, TError>;
14
- /**
15
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
16
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
17
- * @param optionsFn - A function that returns infinite query options.
18
- * @param injector - The Angular injector to use.
19
- * @returns The infinite query result.
20
- * @public
21
- */
22
- export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: (client: QueryClient) => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, injector?: Injector): DefinedCreateInfiniteQueryResult<TData, TError>;
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
- */
31
- export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: (client: QueryClient) => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam>, injector?: Injector): CreateInfiniteQueryResult<TData, TError>;
@@ -1,13 +0,0 @@
1
- import { type QueryFilters } from '@tanstack/query-core';
2
- import type { Injector, Signal } from '@angular/core';
3
- /**
4
- * Injects a signal that tracks the number of queries that your application is loading or
5
- * fetching in the background.
6
- *
7
- * Can be used for app-wide loading indicators
8
- * @param filters - The filters to apply to the query.
9
- * @param injector - The Angular injector to use.
10
- * @returns signal with number of loading or fetching queries.
11
- * @public
12
- */
13
- export declare function injectIsFetching(filters?: QueryFilters, injector?: Injector): Signal<number>;
@@ -1,12 +0,0 @@
1
- import { type MutationFilters } from '@tanstack/query-core';
2
- import type { Injector, Signal } from '@angular/core';
3
- /**
4
- * Injects a signal that tracks the number of mutations that your application is fetching.
5
- *
6
- * Can be used for app-wide loading indicators
7
- * @param filters - The filters to apply to the query.
8
- * @param injector - The Angular injector to use.
9
- * @returns signal with number of fetching mutations.
10
- * @public
11
- */
12
- export declare function injectIsMutating(filters?: MutationFilters, injector?: Injector): Signal<number>;
@@ -1,21 +0,0 @@
1
- import { type DefaultError, type Mutation, type MutationFilters, type MutationState } from '@tanstack/query-core';
2
- import type { Injector, Signal } from '@angular/core';
3
- type MutationStateOptions<TResult = MutationState> = {
4
- filters?: MutationFilters;
5
- select?: (mutation: Mutation<unknown, DefaultError, unknown, unknown>) => TResult;
6
- };
7
- /**
8
- * @public
9
- */
10
- export interface InjectMutationStateOptions {
11
- injector?: Injector;
12
- }
13
- /**
14
- * Injects a signal that tracks the state of all mutations.
15
- * @param mutationStateOptionsFn - A function that returns mutation state options.
16
- * @param options - The Angular injector to use.
17
- * @returns The signal that tracks the state of all mutations.
18
- * @public
19
- */
20
- export declare function injectMutationState<TResult = MutationState>(mutationStateOptionsFn?: () => MutationStateOptions<TResult>, options?: InjectMutationStateOptions): Signal<Array<TResult>>;
21
- export {};
@@ -1,13 +0,0 @@
1
- import { Injector } from '@angular/core';
2
- import type { DefaultError, QueryClient } from '@tanstack/query-core';
3
- import type { CreateMutationOptions, CreateMutationResult } from './types';
4
- /**
5
- * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
6
- *
7
- * Unlike queries, mutations are not run automatically.
8
- * @param optionsFn - A function that returns mutation options.
9
- * @param injector - The Angular injector to use.
10
- * @returns The mutation.
11
- * @public
12
- */
13
- export declare function injectMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(optionsFn: (client: QueryClient) => CreateMutationOptions<TData, TError, TVariables, TContext>, injector?: Injector): CreateMutationResult<TData, TError, TVariables, TContext>;
@@ -1,76 +0,0 @@
1
- import type { Injector, Signal } from '@angular/core';
2
- import type { DefaultError, OmitKeyof, QueriesPlaceholderDataFunction, QueryFunction, QueryKey, QueryObserverOptions, QueryObserverResult, SkipToken, ThrowOnError } from '@tanstack/query-core';
3
- type QueryObserverOptionsForCreateQueries<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = OmitKeyof<QueryObserverOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'placeholderData'> & {
4
- placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>;
5
- };
6
- type MAXIMUM_DEPTH = 20;
7
- type GetOptions<T> = T extends {
8
- queryFnData: infer TQueryFnData;
9
- error?: infer TError;
10
- data: infer TData;
11
- } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends {
12
- queryFnData: infer TQueryFnData;
13
- error?: infer TError;
14
- } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError> : T extends {
15
- data: infer TData;
16
- error?: infer TError;
17
- } ? QueryObserverOptionsForCreateQueries<unknown, TError, TData> : T extends [infer TQueryFnData, infer TError, infer TData] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData> : T extends [infer TQueryFnData, infer TError] ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError> : T extends [infer TQueryFnData] ? QueryObserverOptionsForCreateQueries<TQueryFnData> : T extends {
18
- queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipToken;
19
- select: (data: any) => infer TData;
20
- throwOnError?: ThrowOnError<any, infer TError, any, any>;
21
- } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey> : T extends {
22
- queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> | SkipToken;
23
- throwOnError?: ThrowOnError<any, infer TError, any, any>;
24
- } ? QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TQueryFnData, TQueryKey> : QueryObserverOptionsForCreateQueries;
25
- type GetResults<T> = T extends {
26
- queryFnData: any;
27
- error?: infer TError;
28
- data: infer TData;
29
- } ? QueryObserverResult<TData, TError> : T extends {
30
- queryFnData: infer TQueryFnData;
31
- error?: infer TError;
32
- } ? QueryObserverResult<TQueryFnData, TError> : T extends {
33
- data: infer TData;
34
- error?: infer TError;
35
- } ? QueryObserverResult<TData, TError> : T extends [any, infer TError, infer TData] ? QueryObserverResult<TData, TError> : T extends [infer TQueryFnData, infer TError] ? QueryObserverResult<TQueryFnData, TError> : T extends [infer TQueryFnData] ? QueryObserverResult<TQueryFnData> : T extends {
36
- queryFn?: QueryFunction<unknown, any>;
37
- select: (data: any) => infer TData;
38
- throwOnError?: ThrowOnError<any, infer TError, any, any>;
39
- } ? QueryObserverResult<TData, unknown extends TError ? DefaultError : TError> : T extends {
40
- queryFn?: QueryFunction<infer TQueryFnData, any>;
41
- throwOnError?: ThrowOnError<any, infer TError, any, any>;
42
- } ? QueryObserverResult<TQueryFnData, unknown extends TError ? DefaultError : TError> : QueryObserverResult;
43
- /**
44
- * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
45
- * @public
46
- */
47
- export type QueriesOptions<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<QueryObserverOptionsForCreateQueries> : T extends [] ? [] : T extends [infer Head] ? [...TResult, GetOptions<Head>] : T extends [infer Head, ...infer Tail] ? QueriesOptions<[
48
- ...Tail
49
- ], [
50
- ...TResult,
51
- GetOptions<Head>
52
- ], [
53
- ...TDepth,
54
- 1
55
- ]> : ReadonlyArray<unknown> extends T ? T : T extends Array<QueryObserverOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, infer TQueryKey>> ? Array<QueryObserverOptionsForCreateQueries<TQueryFnData, TError, TData, TQueryKey>> : Array<QueryObserverOptionsForCreateQueries>;
56
- /**
57
- * QueriesResults reducer recursively maps type param to results
58
- * @public
59
- */
60
- export type QueriesResults<T extends Array<any>, TResult extends Array<any> = [], TDepth extends ReadonlyArray<number> = []> = TDepth['length'] extends MAXIMUM_DEPTH ? Array<QueryObserverResult> : T extends [] ? [] : T extends [infer Head] ? [...TResult, GetResults<Head>] : T extends [infer Head, ...infer Tail] ? QueriesResults<[
61
- ...Tail
62
- ], [
63
- ...TResult,
64
- GetResults<Head>
65
- ], [
66
- ...TDepth,
67
- 1
68
- ]> : T extends Array<QueryObserverOptionsForCreateQueries<infer TQueryFnData, infer TError, infer TData, any>> ? Array<QueryObserverResult<unknown extends TData ? TQueryFnData : TData, unknown extends TError ? DefaultError : TError>> : Array<QueryObserverResult>;
69
- /**
70
- * @public
71
- */
72
- export declare function injectQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>({ queries, ...options }: {
73
- queries: Signal<[...QueriesOptions<T>]>;
74
- combine?: (result: QueriesResults<T>) => TCombinedResult;
75
- }, injector?: Injector): Signal<TCombinedResult>;
76
- export {};
@@ -1,30 +0,0 @@
1
- import type { QueryClient } from '@tanstack/query-core';
2
- /**
3
- * Injects the `QueryClient` instance into the component or service.
4
- *
5
- * **Example**
6
- * ```ts
7
- * const queryClient = injectQueryClient();
8
- * ```
9
- * @returns The `QueryClient` instance.
10
- * @public
11
- */
12
- export declare const injectQueryClient: {
13
- (): QueryClient;
14
- (injectOptions: import("@angular/core").InjectOptions & {
15
- optional?: false;
16
- } & {
17
- injector?: import("@angular/core").Injector;
18
- }): QueryClient;
19
- (injectOptions: import("@angular/core").InjectOptions & {
20
- injector?: import("@angular/core").Injector;
21
- }): QueryClient;
22
- };
23
- /**
24
- * Usually {@link provideAngularQuery} is used once to set up TanStack Query and the
25
- * {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient}
26
- * for the entire application. You can use `provideQueryClient` to provide a
27
- * different `QueryClient` instance for a part of the application.
28
- * @public
29
- */
30
- export declare const provideQueryClient: ((value: QueryClient | (() => QueryClient)) => import("@angular/core").Provider) & ((value: QueryClient | (() => QueryClient)) => import("@angular/core").Provider);
@@ -1,106 +0,0 @@
1
- import type { DefaultError, QueryClient, QueryKey } from '@tanstack/query-core';
2
- import type { Injector } from '@angular/core';
3
- import type { CreateQueryOptions, CreateQueryResult, DefinedCreateQueryResult } from './types';
4
- import type { DefinedInitialDataOptions, UndefinedInitialDataOptions } from './query-options';
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,42 +0,0 @@
1
- import type { EnvironmentProviders } from '@angular/core';
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
- */
42
- export declare function provideAngularQuery(queryClient: QueryClient): EnvironmentProviders;
@@ -1,66 +0,0 @@
1
- import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core';
2
- import type { CreateQueryOptions } from './types';
3
- /**
4
- * @public
5
- */
6
- export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
7
- initialData?: undefined;
8
- };
9
- type NonUndefinedGuard<T> = T extends undefined ? never : T;
10
- /**
11
- * @public
12
- */
13
- export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
14
- initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
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
- */
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> & {
39
- queryKey: DataTag<TQueryKey, TQueryFnData>;
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
- */
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> & {
64
- queryKey: DataTag<TQueryKey, TQueryFnData>;
65
- };
66
- export {};
@@ -1,11 +0,0 @@
1
- import type { Signal } from '@angular/core';
2
- export type MapToSignals<T> = {
3
- [K in keyof T]: T[K] extends Function ? T[K] : Signal<T[K]>;
4
- };
5
- /**
6
- * Exposes fields of an object passed via an Angular `Signal` as `Computed` signals.
7
- * Functions on the object are passed through as-is.
8
- * @param inputSignal - `Signal` that must return an object.
9
- * @returns A proxy object with the same fields as the input object, but with each field wrapped in a `Computed` signal.
10
- */
11
- export declare function signalProxy<TInput extends Record<string | symbol, any>>(inputSignal: Signal<TInput>): MapToSignals<TInput>;
package/build/types.d.ts DELETED
@@ -1,95 +0,0 @@
1
- import type { DefaultError, DefinedInfiniteQueryObserverResult, DefinedQueryObserverResult, InfiniteQueryObserverOptions, InfiniteQueryObserverResult, MutateFunction, MutationObserverOptions, MutationObserverResult, OmitKeyof, QueryKey, QueryObserverOptions, QueryObserverResult } from '@tanstack/query-core';
2
- import type { MapToSignals } from './signal-proxy';
3
- /**
4
- * @public
5
- */
6
- export interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
7
- }
8
- /**
9
- * @public
10
- */
11
- export interface CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends OmitKeyof<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'suspense'> {
12
- }
13
- /**
14
- * @public
15
- */
16
- type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
17
- status: TStatus;
18
- }>;
19
- /**
20
- * @public
21
- */
22
- export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
23
- isSuccess: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>;
24
- isError: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>;
25
- isPending: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>;
26
- }
27
- /**
28
- * @public
29
- */
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'> {
31
- }
32
- /**
33
- * @public
34
- */
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
- */
39
- export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
40
- /**
41
- * @public
42
- */
43
- export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TDefinedQueryObserver = DefinedQueryObserverResult<TData, TError>> = MapToSignals<TDefinedQueryObserver>;
44
- /**
45
- * @public
46
- */
47
- export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = MapToSignals<InfiniteQueryObserverResult<TData, TError>>;
48
- /**
49
- * @public
50
- */
51
- export type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<TData, TError>> = MapToSignals<TDefinedInfiniteQueryObserver>;
52
- /**
53
- * @public
54
- */
55
- export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> {
56
- }
57
- /**
58
- * @public
59
- */
60
- export type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TContext>>) => void;
61
- /**
62
- * @public
63
- */
64
- export type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = MutateFunction<TData, TError, TVariables, TContext>;
65
- /**
66
- * @public
67
- */
68
- export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TContext>, {
69
- mutate: CreateMutateFunction<TData, TError, TVariables, TContext>;
70
- }> & {
71
- mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TContext>;
72
- };
73
- /**
74
- * @public
75
- */
76
- type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TContext>, {
77
- status: TStatus;
78
- }>;
79
- /**
80
- * @public
81
- */
82
- export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> {
83
- isSuccess: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TContext>>;
84
- isError: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TContext>>;
85
- isPending: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TContext>>;
86
- isIdle: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>>;
87
- }
88
- /**
89
- * @public
90
- */
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'>>;
92
- type Override<TTargetA, TTargetB> = {
93
- [AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey];
94
- };
95
- export {};
@@ -1,54 +0,0 @@
1
- /**
2
- * The code in this file is adapted from NG Extension Platform at https://ngxtension.netlify.app.
3
- *
4
- * Original Author: Chau Tran
5
- *
6
- * NG Extension Platform is an open-source project licensed under the MIT license.
7
- *
8
- * For more information about the original code, see
9
- * https://github.com/nartc/ngxtension-platform
10
- */
11
- import { Injector } from '@angular/core';
12
- /**
13
- * `assertInjector` extends `assertInInjectionContext` with an optional `Injector`
14
- * After assertion, `assertInjector` runs the `runner` function with the guaranteed `Injector`
15
- * whether it is the default `Injector` within the current **Injection Context**
16
- * or the custom `Injector` that was passed in.
17
- *
18
- * @template {() => any} Runner - Runner is a function that can return anything
19
- * @param {Function} fn - the Function to pass in `assertInInjectionContext`
20
- * @param {Injector | undefined | null} injector - the optional "custom" Injector
21
- * @param {Runner} runner - the runner fn
22
- * @returns {ReturnType<Runner>} result - returns the result of the Runner
23
- *
24
- * @example
25
- * ```ts
26
- * function injectValue(injector?: Injector) {
27
- * return assertInjector(injectValue, injector, () => 'value');
28
- * }
29
- *
30
- * injectValue(); // string
31
- * ```
32
- */
33
- export declare function assertInjector<TRunner extends () => any>(fn: Function, injector: Injector | undefined | null, runner: TRunner): ReturnType<TRunner>;
34
- /**
35
- * `assertInjector` extends `assertInInjectionContext` with an optional `Injector`
36
- * After assertion, `assertInjector` returns a guaranteed `Injector` whether it is the default `Injector`
37
- * within the current **Injection Context** or the custom `Injector` that was passed in.
38
- *
39
- * @param {Function} fn - the Function to pass in `assertInInjectionContext`
40
- * @param {Injector | undefined | null} injector - the optional "custom" Injector
41
- * @returns Injector
42
- *
43
- * @example
44
- * ```ts
45
- * function injectDestroy(injector?: Injector) {
46
- * injector = assertInjector(injectDestroy, injector);
47
- *
48
- * return runInInjectionContext(injector, () => {
49
- * // code
50
- * })
51
- * }
52
- * ```
53
- */
54
- export declare function assertInjector(fn: Function, injector: Injector | undefined | null): Injector;