@tanstack/angular-query-experimental 5.34.1 → 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 (78) hide show
  1. package/README.md +19 -2
  2. package/build/README.md +19 -2
  3. package/build/esm2022/create-base-query.mjs +3 -3
  4. package/build/esm2022/index.mjs +2 -2
  5. package/build/esm2022/infinite-query-options.mjs +9 -1
  6. package/build/esm2022/inject-infinite-query.mjs +11 -3
  7. package/build/esm2022/inject-is-fetching.mjs +11 -1
  8. package/build/esm2022/inject-is-mutating.mjs +10 -1
  9. package/build/esm2022/inject-mutation-state.mjs +8 -1
  10. package/build/esm2022/inject-mutation.mjs +13 -4
  11. package/build/esm2022/inject-queries.mjs +4 -1
  12. package/build/esm2022/inject-query-client.mjs +21 -3
  13. package/build/esm2022/inject-query.mjs +36 -3
  14. package/build/esm2022/providers.mjs +40 -1
  15. package/build/esm2022/query-options.mjs +23 -1
  16. package/build/esm2022/signal-proxy.mjs +2 -4
  17. package/build/esm2022/types.mjs +1 -1
  18. package/build/fesm2022/tanstack-angular-query-experimental.mjs +179 -14
  19. package/build/fesm2022/tanstack-angular-query-experimental.mjs.map +1 -1
  20. package/build/rollup.d.ts +591 -0
  21. package/package.json +10 -6
  22. package/build/create-base-query.d.ts +0 -6
  23. package/build/index.d.ts +0 -14
  24. package/build/infinite-query-options.d.ts +0 -18
  25. package/build/inject-infinite-query.d.ts +0 -7
  26. package/build/inject-is-fetching.d.ts +0 -3
  27. package/build/inject-is-mutating.d.ts +0 -3
  28. package/build/inject-mutation-state.d.ts +0 -11
  29. package/build/inject-mutation.d.ts +0 -4
  30. package/build/inject-queries.d.ts +0 -71
  31. package/build/inject-query-client.d.ts +0 -13
  32. package/build/inject-query.d.ts +0 -7
  33. package/build/providers.d.ts +0 -3
  34. package/build/query-options.d.ts +0 -16
  35. package/build/signal-proxy.d.ts +0 -13
  36. package/build/types.d.ts +0 -44
  37. package/build/util/assert-injector/assert-injector.d.ts +0 -54
  38. package/build/util/create-injection-token/create-injection-token.d.ts +0 -52
  39. package/build/util/index.d.ts +0 -2
  40. package/build/util/lazy-init/lazy-init.d.ts +0 -1
  41. package/build/util/lazy-signal-initializer/lazy-signal-initializer.d.ts +0 -4
  42. package/src/__tests__/inject-infinite-query.test.ts +0 -64
  43. package/src/__tests__/inject-is-fetching.test.ts +0 -35
  44. package/src/__tests__/inject-is-mutating.test.ts +0 -39
  45. package/src/__tests__/inject-mutation-state.test-d.ts +0 -22
  46. package/src/__tests__/inject-mutation-state.test.ts +0 -177
  47. package/src/__tests__/inject-mutation.test-d.ts +0 -71
  48. package/src/__tests__/inject-mutation.test.ts +0 -458
  49. package/src/__tests__/inject-query.test-d.ts +0 -59
  50. package/src/__tests__/inject-query.test.ts +0 -349
  51. package/src/__tests__/query-options.test-d.ts +0 -127
  52. package/src/__tests__/signal-proxy.test.ts +0 -27
  53. package/src/__tests__/test-utils.ts +0 -131
  54. package/src/__tests__/util/lazy-init/lazy-init.test.ts +0 -126
  55. package/src/__tests__/util/lazy-signal-initializer/lazy-signal-initializer.test.ts +0 -130
  56. package/src/create-base-query.ts +0 -116
  57. package/src/index.ts +0 -28
  58. package/src/infinite-query-options.ts +0 -94
  59. package/src/inject-infinite-query.ts +0 -93
  60. package/src/inject-is-fetching.ts +0 -39
  61. package/src/inject-is-mutating.ts +0 -39
  62. package/src/inject-mutation-state.ts +0 -97
  63. package/src/inject-mutation.ts +0 -109
  64. package/src/inject-queries.ts +0 -260
  65. package/src/inject-query-client.ts +0 -7
  66. package/src/inject-query.ts +0 -68
  67. package/src/providers.ts +0 -26
  68. package/src/query-options.ts +0 -50
  69. package/src/signal-proxy.ts +0 -48
  70. package/src/test-setup.ts +0 -12
  71. package/src/types.ts +0 -260
  72. package/src/util/assert-injector/assert-injector.test.ts +0 -74
  73. package/src/util/assert-injector/assert-injector.ts +0 -81
  74. package/src/util/create-injection-token/create-injection-token.test.ts +0 -32
  75. package/src/util/create-injection-token/create-injection-token.ts +0 -185
  76. package/src/util/index.ts +0 -13
  77. package/src/util/lazy-init/lazy-init.ts +0 -34
  78. package/src/util/lazy-signal-initializer/lazy-signal-initializer.ts +0 -28
@@ -1,18 +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
- 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> & {
13
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
14
- };
15
- 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> & {
16
- queryKey: DataTag<TQueryKey, InfiniteData<TQueryFnData>>;
17
- };
18
- export {};
@@ -1,7 +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
- export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: (client: QueryClient) => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, injector?: Injector): CreateInfiniteQueryResult<TData, TError>;
6
- export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: (client: QueryClient) => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, injector?: Injector): DefinedCreateInfiniteQueryResult<TData, TError>;
7
- export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: (client: QueryClient) => CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey, TPageParam>, injector?: Injector): CreateInfiniteQueryResult<TData, TError>;
@@ -1,3 +0,0 @@
1
- import { type QueryFilters } from '@tanstack/query-core';
2
- import type { Injector, Signal } from '@angular/core';
3
- export declare function injectIsFetching(filters?: QueryFilters, injector?: Injector): Signal<number>;
@@ -1,3 +0,0 @@
1
- import { type MutationFilters } from '@tanstack/query-core';
2
- import type { Injector, Signal } from '@angular/core';
3
- export declare function injectIsMutating(filters?: MutationFilters, injector?: Injector): Signal<number>;
@@ -1,11 +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
- export interface InjectMutationStateOptions {
8
- injector?: Injector;
9
- }
10
- export declare function injectMutationState<TResult = MutationState>(mutationStateOptionsFn?: () => MutationStateOptions<TResult>, options?: InjectMutationStateOptions): Signal<Array<TResult>>;
11
- export {};
@@ -1,4 +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
- export declare function injectMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: (client: QueryClient) => CreateMutationOptions<TData, TError, TVariables, TContext>, injector?: Injector): CreateMutationResult<TData, TError, TVariables, TContext>;
@@ -1,71 +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
- */
46
- 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<[
47
- ...Tail
48
- ], [
49
- ...TResult,
50
- GetOptions<Head>
51
- ], [
52
- ...TDepth,
53
- 1
54
- ]> : 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>;
55
- /**
56
- * QueriesResults reducer recursively maps type param to results
57
- */
58
- 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<[
59
- ...Tail
60
- ], [
61
- ...TResult,
62
- GetResults<Head>
63
- ], [
64
- ...TDepth,
65
- 1
66
- ]> : 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>;
67
- export declare function injectQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>({ queries, ...options }: {
68
- queries: Signal<[...QueriesOptions<T>]>;
69
- combine?: (result: QueriesResults<T>) => TCombinedResult;
70
- }, injector?: Injector): Signal<TCombinedResult>;
71
- export {};
@@ -1,13 +0,0 @@
1
- import type { QueryClient } from '@tanstack/query-core';
2
- declare const injectQueryClient: {
3
- (): QueryClient;
4
- (injectOptions: import("@angular/core").InjectOptions & {
5
- optional?: false;
6
- } & {
7
- injector?: import("@angular/core").Injector;
8
- }): QueryClient;
9
- (injectOptions: import("@angular/core").InjectOptions & {
10
- injector?: import("@angular/core").Injector;
11
- }): QueryClient;
12
- }, provideQueryClient: ((value: QueryClient | (() => QueryClient)) => import("@angular/core").Provider) & ((value: QueryClient | (() => QueryClient)) => import("@angular/core").Provider), QUERY_CLIENT: import("@angular/core").InjectionToken<QueryClient>;
13
- export { injectQueryClient, provideQueryClient, QUERY_CLIENT };
@@ -1,7 +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
- 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>;
@@ -1,3 +0,0 @@
1
- import type { EnvironmentProviders } from '@angular/core';
2
- import type { QueryClient } from '@tanstack/query-core';
3
- export declare function provideAngularQuery(queryClient: QueryClient): EnvironmentProviders;
@@ -1,16 +0,0 @@
1
- import type { DataTag, DefaultError, QueryKey } from '@tanstack/query-core';
2
- import type { CreateQueryOptions } from './types';
3
- export type UndefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
4
- initialData?: undefined;
5
- };
6
- type NonUndefinedGuard<T> = T extends undefined ? never : T;
7
- export type DefinedInitialDataOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {
8
- initialData: NonUndefinedGuard<TQueryFnData> | (() => NonUndefinedGuard<TQueryFnData>);
9
- };
10
- 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
- queryKey: DataTag<TQueryKey, TQueryFnData>;
12
- };
13
- 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
- queryKey: DataTag<TQueryKey, TQueryFnData>;
15
- };
16
- export {};
@@ -1,13 +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
- *
8
- * Functions on the object are passed through as-is.
9
- *
10
- * @param inputSignal - `Signal` that must return an object.
11
- *
12
- */
13
- export declare function signalProxy<TInput extends Record<string | symbol, any>>(inputSignal: Signal<TInput>): MapToSignals<TInput>;
package/build/types.d.ts DELETED
@@ -1,44 +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
- export interface CreateBaseQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey> {
4
- }
5
- export interface CreateQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> extends OmitKeyof<CreateBaseQueryOptions<TQueryFnData, TError, TData, TQueryFnData, TQueryKey>, 'suspense'> {
6
- }
7
- type CreateStatusBasedQueryResult<TStatus extends QueryObserverResult['status'], TData = unknown, TError = DefaultError> = Extract<QueryObserverResult<TData, TError>, {
8
- status: TStatus;
9
- }>;
10
- export interface BaseQueryNarrowing<TData = unknown, TError = DefaultError> {
11
- isSuccess: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'success', TData, TError>>;
12
- isError: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'error', TData, TError>>;
13
- isPending: (this: CreateBaseQueryResult<TData, TError>) => this is CreateBaseQueryResult<TData, TError, CreateStatusBasedQueryResult<'pending', TData, TError>>;
14
- }
15
- 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
- }
17
- export type CreateBaseQueryResult<TData = unknown, TError = DefaultError, TState = QueryObserverResult<TData, TError>> = BaseQueryNarrowing<TData, TError> & MapToSignals<OmitKeyof<TState, keyof BaseQueryNarrowing, 'safely'>>;
18
- export type CreateQueryResult<TData = unknown, TError = DefaultError> = CreateBaseQueryResult<TData, TError>;
19
- export type DefinedCreateQueryResult<TData = unknown, TError = DefaultError, TDefinedQueryObserver = DefinedQueryObserverResult<TData, TError>> = MapToSignals<TDefinedQueryObserver>;
20
- export type CreateInfiniteQueryResult<TData = unknown, TError = DefaultError> = MapToSignals<InfiniteQueryObserverResult<TData, TError>>;
21
- export type DefinedCreateInfiniteQueryResult<TData = unknown, TError = DefaultError, TDefinedInfiniteQueryObserver = DefinedInfiniteQueryObserverResult<TData, TError>> = MapToSignals<TDefinedInfiniteQueryObserver>;
22
- export interface CreateMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends OmitKeyof<MutationObserverOptions<TData, TError, TVariables, TContext>, '_defaulted'> {
23
- }
24
- export type CreateMutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (...args: Parameters<MutateFunction<TData, TError, TVariables, TContext>>) => void;
25
- export type CreateMutateAsyncFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = MutateFunction<TData, TError, TVariables, TContext>;
26
- export type CreateBaseMutationResult<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Override<MutationObserverResult<TData, TError, TVariables, TContext>, {
27
- mutate: CreateMutateFunction<TData, TError, TVariables, TContext>;
28
- }> & {
29
- mutateAsync: CreateMutateAsyncFunction<TData, TError, TVariables, TContext>;
30
- };
31
- type CreateStatusBasedMutationResult<TStatus extends CreateBaseMutationResult['status'], TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> = Extract<CreateBaseMutationResult<TData, TError, TVariables, TContext>, {
32
- status: TStatus;
33
- }>;
34
- export interface BaseMutationNarrowing<TData = unknown, TError = DefaultError, TVariables = unknown, TContext = unknown> {
35
- isSuccess: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'success', TData, TError, TVariables, TContext>>;
36
- isError: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'error', TData, TError, TVariables, TContext>>;
37
- isPending: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'pending', TData, TError, TVariables, TContext>>;
38
- isIdle: (this: CreateMutationResult<TData, TError, TVariables, TContext>) => this is CreateMutationResult<TData, TError, TVariables, TContext, CreateStatusBasedMutationResult<'idle', TData, TError, TVariables, TContext>>;
39
- }
40
- 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
- type Override<TTargetA, TTargetB> = {
42
- [AKey in keyof TTargetA]: AKey extends keyof TTargetB ? TTargetB[AKey] : TTargetA[AKey];
43
- };
44
- 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;
@@ -1,52 +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 { type EnvironmentProviders, type Host, type InjectOptions, InjectionToken, type Injector, type Optional, type Provider, type Self, type SkipSelf, type Type } from '@angular/core';
12
- type CreateInjectionTokenDep<TTokenType> = Type<TTokenType> | (abstract new (...args: Array<any>) => TTokenType) | InjectionToken<TTokenType>;
13
- type CreateInjectionTokenDeps<TFactory extends (...args: Array<any>) => any, TFactoryDeps extends Parameters<TFactory> = Parameters<TFactory>> = {
14
- [Index in keyof TFactoryDeps]: CreateInjectionTokenDep<TFactoryDeps[Index]> | [
15
- ...modifiers: Array<Optional | Self | SkipSelf | Host>,
16
- token: CreateInjectionTokenDep<TFactoryDeps[Index]>
17
- ];
18
- } & {
19
- length: TFactoryDeps['length'];
20
- };
21
- type CreateInjectionTokenOptions<TFactory extends (...args: Array<any>) => any, TFactoryDeps extends Parameters<TFactory> = Parameters<TFactory>> = (TFactoryDeps[0] extends undefined ? {
22
- deps?: never;
23
- } : {
24
- deps: CreateInjectionTokenDeps<TFactory, TFactoryDeps>;
25
- }) & {
26
- isRoot?: boolean;
27
- multi?: boolean;
28
- token?: InjectionToken<ReturnType<TFactory>>;
29
- extraProviders?: Provider | EnvironmentProviders;
30
- };
31
- type InjectFn<TFactoryReturn> = {
32
- (): TFactoryReturn;
33
- (injectOptions: InjectOptions & {
34
- optional?: false;
35
- } & {
36
- injector?: Injector;
37
- }): TFactoryReturn;
38
- (injectOptions: InjectOptions & {
39
- injector?: Injector;
40
- }): TFactoryReturn | null;
41
- };
42
- type ProvideFn<TNoop extends boolean, TFactoryReturn, TReturn = TFactoryReturn extends Array<infer Item> ? Item : TFactoryReturn> = (TNoop extends true ? (value: TReturn | (() => TReturn)) => Provider : () => Provider) & (TReturn extends Function ? (value: TReturn | (() => TReturn), isFunctionValue: boolean) => Provider : (value: TReturn | (() => TReturn)) => Provider);
43
- type CreateInjectionTokenReturn<TFactoryReturn, TNoop extends boolean = false> = [
44
- InjectFn<TFactoryReturn>,
45
- ProvideFn<TNoop, TFactoryReturn>,
46
- InjectionToken<TFactoryReturn>,
47
- () => Provider
48
- ];
49
- export declare function createNoopInjectionToken<TValue, TMulti extends boolean = false, TOptions = Pick<CreateInjectionTokenOptions<() => void, []>, 'extraProviders'> & (TMulti extends true ? {
50
- multi: true;
51
- } : Record<string, never>)>(description: string, options?: TOptions): CreateInjectionTokenReturn<TMulti extends true ? TValue[] : TValue, true>;
52
- export {};
@@ -1,2 +0,0 @@
1
- export declare function shouldThrowError<T extends (...args: Array<any>) => boolean>(throwError: boolean | T | undefined, params: Parameters<T>): boolean;
2
- export declare function noop(): void;
@@ -1 +0,0 @@
1
- export declare function lazyInit<T extends object>(initializer: () => T): T;
@@ -1,4 +0,0 @@
1
- import { Injector, type Signal } from '@angular/core';
2
- type SignalInitializerFn<T> = (injector: Injector) => Signal<T>;
3
- export declare function lazySignalInitializer<T>(initializerFn: SignalInitializerFn<T>): Signal<T>;
4
- export {};
@@ -1,64 +0,0 @@
1
- import { TestBed } from '@angular/core/testing'
2
- import { QueryClient } from '@tanstack/query-core'
3
- import { afterEach } from 'vitest'
4
- import { injectInfiniteQuery } from '../inject-infinite-query'
5
- import { provideAngularQuery } from '../providers'
6
- import { expectSignals, infiniteFetcher } from './test-utils'
7
-
8
- const QUERY_DURATION = 1000
9
-
10
- const resolveQueries = () => vi.advanceTimersByTimeAsync(QUERY_DURATION)
11
-
12
- describe('injectInfiniteQuery', () => {
13
- let queryClient: QueryClient
14
-
15
- beforeEach(() => {
16
- queryClient = new QueryClient()
17
- vi.useFakeTimers()
18
- TestBed.configureTestingModule({
19
- providers: [provideAngularQuery(queryClient)],
20
- })
21
- })
22
-
23
- afterEach(() => {
24
- vi.useRealTimers()
25
- })
26
-
27
- test('should properly execute infinite query', async () => {
28
- const query = TestBed.runInInjectionContext(() => {
29
- return injectInfiniteQuery(() => ({
30
- queryKey: ['infiniteQuery'],
31
- queryFn: infiniteFetcher,
32
- initialPageParam: 0,
33
- getNextPageParam: () => 12,
34
- }))
35
- })
36
-
37
- expectSignals(query, {
38
- data: undefined,
39
- status: 'pending',
40
- })
41
-
42
- await resolveQueries()
43
-
44
- expectSignals(query, {
45
- data: {
46
- pageParams: [0],
47
- pages: ['data on page 0'],
48
- },
49
- status: 'success',
50
- })
51
-
52
- void query.fetchNextPage()
53
-
54
- await resolveQueries()
55
-
56
- expectSignals(query, {
57
- data: {
58
- pageParams: [0, 12],
59
- pages: ['data on page 0', 'data on page 12'],
60
- },
61
- status: 'success',
62
- })
63
- })
64
- })
@@ -1,35 +0,0 @@
1
- import { TestBed, fakeAsync, flush, tick } from '@angular/core/testing'
2
- import { QueryClient } from '@tanstack/query-core'
3
- import { beforeEach, describe, expect } from 'vitest'
4
- import { injectIsFetching } from '../inject-is-fetching'
5
- import { injectQuery } from '../inject-query'
6
- import { provideAngularQuery } from '../providers'
7
- import { delayedFetcher } from './test-utils'
8
-
9
- describe('injectIsFetching', () => {
10
- let queryClient: QueryClient
11
-
12
- beforeEach(() => {
13
- queryClient = new QueryClient()
14
-
15
- TestBed.configureTestingModule({
16
- providers: [provideAngularQuery(queryClient)],
17
- })
18
- })
19
-
20
- test('Returns number of fetching queries', fakeAsync(() => {
21
- const isFetching = TestBed.runInInjectionContext(() => {
22
- injectQuery(() => ({
23
- queryKey: ['isFetching1'],
24
- queryFn: delayedFetcher(100),
25
- }))
26
- return injectIsFetching()
27
- })
28
-
29
- tick()
30
-
31
- expect(isFetching()).toStrictEqual(1)
32
- flush()
33
- expect(isFetching()).toStrictEqual(0)
34
- }))
35
- })
@@ -1,39 +0,0 @@
1
- import { QueryClient } from '@tanstack/query-core'
2
- import { beforeEach, describe } from 'vitest'
3
- import { TestBed, fakeAsync, tick } from '@angular/core/testing'
4
- import { injectIsMutating } from '../inject-is-mutating'
5
- import { injectMutation } from '../inject-mutation'
6
- import { provideAngularQuery } from '../providers'
7
- import { successMutator } from './test-utils'
8
-
9
- describe('injectIsMutating', () => {
10
- let queryClient: QueryClient
11
-
12
- beforeEach(() => {
13
- queryClient = new QueryClient()
14
-
15
- TestBed.configureTestingModule({
16
- providers: [provideAngularQuery(queryClient)],
17
- })
18
- })
19
-
20
- test('should properly return isMutating state', fakeAsync(() => {
21
- TestBed.runInInjectionContext(() => {
22
- const isMutating = injectIsMutating()
23
- const mutation = injectMutation(() => ({
24
- mutationKey: ['isMutating1'],
25
- mutationFn: successMutator<{ par1: string }>,
26
- }))
27
-
28
- expect(isMutating()).toBe(0)
29
-
30
- mutation.mutate({
31
- par1: 'par1',
32
- })
33
-
34
- tick()
35
-
36
- expect(isMutating()).toBe(1)
37
- })
38
- }))
39
- })
@@ -1,22 +0,0 @@
1
- import { describe, expectTypeOf } from 'vitest'
2
- import { injectMutationState } from '../inject-mutation-state'
3
- import type { MutationState, MutationStatus } from '@tanstack/query-core'
4
-
5
- describe('injectMutationState', () => {
6
- it('should default to QueryState', () => {
7
- const result = injectMutationState(() => ({
8
- filters: { status: 'pending' },
9
- }))
10
-
11
- expectTypeOf(result()).toEqualTypeOf<Array<MutationState>>()
12
- })
13
-
14
- it('should infer with select', () => {
15
- const result = injectMutationState(() => ({
16
- filters: { status: 'pending' },
17
- select: (mutation) => mutation.state.status,
18
- }))
19
-
20
- expectTypeOf(result()).toEqualTypeOf<Array<MutationStatus>>()
21
- })
22
- })