Skip to content

Commit

Permalink
feat(query): removed useless conversion function
Browse files Browse the repository at this point in the history
  • Loading branch information
Giordano Paruccini committed Jan 19, 2024
1 parent a1622c4 commit 0f5998a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 66 deletions.
56 changes: 43 additions & 13 deletions query/src/lib/query-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ import {
FetchInfiniteQueryOptions,
FetchQueryOptions,
InfiniteData,
InfiniteQueryObserverOptions,
QueryKey,
QueryObserverOptions,
} from '@tanstack/query-core';
import { CreateBaseQueryOptions } from './base-query';
import { CreateInfiniteQueryOptions } from './infinite-query';
import { QUERY_CLIENT_OPTIONS } from './query-client-options';
import { normalizeOptions, queryObserverOptions } from './query-options';
import { normalizeOptions } from './query-options';

const QueryClientToken = new InjectionToken<QueryClient>('QueryClient', {
providedIn: 'root',
Expand Down Expand Up @@ -123,10 +125,15 @@ export class QueryClient extends _QueryClient {
TQueryKey
>,
): Promise<TData> {
const baseOptions = queryObserverOptions(options);
const defaultedOptions = normalizeOptions(
this,
baseOptions,
options as QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey
>,
this.#injector,
) as unknown as FetchQueryOptions<
TQueryFnData,
Expand Down Expand Up @@ -202,10 +209,16 @@ export class QueryClient extends _QueryClient {
TPageParam
>,
): Promise<TData> {
const baseOptions = queryObserverOptions(options);
const defaultedOptions = normalizeOptions(
this,
baseOptions,
options as QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey,
TPageParam
>,
this.#injector,
) as unknown as FetchQueryOptions<
TQueryFnData,
Expand Down Expand Up @@ -267,10 +280,15 @@ export class QueryClient extends _QueryClient {
TQueryKey
>,
): Promise<void> {
const baseOptions = queryObserverOptions(options);
const defaultedOptions = normalizeOptions(
this,
baseOptions,
options as QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey
>,
this.#injector,
) as unknown as FetchQueryOptions<
TQueryFnData,
Expand All @@ -290,7 +308,7 @@ export class QueryClient extends _QueryClient {
*
* queryClient = injectQueryClient();
*
* const data = await queryClient.fetchInfiniteQuery({ queryKey, queryFn })
* const data = await queryClient.fetchInfiniteQuery({ queryKey, queryFn, initialPageParam, getPreviousPageParam, getNextPageParam }) })
*
*/
override fetchInfiniteQuery<
Expand Down Expand Up @@ -340,10 +358,16 @@ export class QueryClient extends _QueryClient {
TPageParam
>,
): Promise<InfiniteData<TData, TPageParam>> {
const baseOptions = queryObserverOptions(options);
const defaultedOptions = normalizeOptions(
this,
baseOptions,
options as InfiniteQueryObserverOptions<
TQueryFnData,
TError,
TQueryFnData,
TQueryFnData,
TQueryKey,
TPageParam
>,
this.#injector,
) as unknown as FetchInfiniteQueryOptions<
TQueryFnData,
Expand All @@ -363,7 +387,7 @@ export class QueryClient extends _QueryClient {
*
* queryClient = injectQueryClient();
*
* await queryClient.prefetchInfiniteQuery({ queryKey, queryFn })
* await queryClient.prefetchInfiniteQuery({ queryKey, queryFn, initialPageParam, getPreviousPageParam, getNextPageParam })
*
*/
override prefetchInfiniteQuery<
Expand Down Expand Up @@ -413,10 +437,16 @@ export class QueryClient extends _QueryClient {
TPageParam
>,
): Promise<void> {
const baseOptions = queryObserverOptions(options);
const defaultedOptions = normalizeOptions(
this,
baseOptions,
options as InfiniteQueryObserverOptions<
TQueryFnData,
TError,
TQueryFnData,
TQueryFnData,
TQueryKey,
TPageParam
>,
this.#injector,
) as unknown as FetchInfiniteQueryOptions<
TQueryFnData,
Expand Down
53 changes: 0 additions & 53 deletions query/src/lib/query-options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Injector, runInInjectionContext } from '@angular/core';
import type {
DataTag,
DefaultError,
InfiniteQueryObserverOptions,
QueryClient,
QueryFunctionContext,
QueryKey,
Expand Down Expand Up @@ -57,7 +56,6 @@ export function queryOptions<
): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
queryKey: DataTag<TQueryKey, TData>;
};

export function queryOptions<
TQueryFnData = unknown,
TError = DefaultError,
Expand All @@ -68,7 +66,6 @@ export function queryOptions<
): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey> & {
queryKey: DataTag<TQueryKey, TData>;
};

export function queryOptions<
TQueryFnData = unknown,
TError = DefaultError,
Expand Down Expand Up @@ -98,56 +95,6 @@ export function queryOptions(options: unknown) {
return options;
}

export function queryObserverOptions<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
TPageParam = never,
>(
options: CreateInfiniteQueryOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey,
TPageParam
>,
): InfiniteQueryObserverOptions<
TQueryFnData,
TError,
TQueryFnData,
TQueryFnData,
TQueryKey,
TPageParam
>;
export function queryObserverOptions<
TQueryFnData = unknown,
TError = DefaultError,
TData = TQueryFnData,
TQueryKey extends QueryKey = QueryKey,
TPageParam = never,
>(
options: CreateBaseQueryOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey,
TPageParam
>,
): QueryObserverOptions<
TQueryFnData,
TError,
TData,
TQueryFnData,
TQueryKey,
TPageParam
>;
export function queryObserverOptions(options: unknown) {
return options;
}

export function normalizeOptions<
TQueryFnData,
TError,
Expand Down

0 comments on commit 0f5998a

Please sign in to comment.