@techsio/storefront-data
Version:
Medusa-first storefront data layer built on TanStack Query.
58 lines • 3.87 kB
TypeScript
import { type CacheConfig, type CacheStrategy } from "../shared/cache-config";
import type { ReadQueryOptions, SuspenseQueryOptions } from "../shared/hook-types";
import type { PrefetchSkipMode } from "../shared/prefetch";
import type { QueryNamespace } from "../shared/query-keys";
import type { CollectionDetailInputBase, CollectionListInputBase, CollectionListResponse, CollectionQueryKeys, CollectionService, UseCollectionResult, UseCollectionsResult, UseSuspenseCollectionResult, UseSuspenseCollectionsResult } from "./types";
export type CreateCollectionHooksConfig<TCollection, TListInput extends CollectionListInputBase, TListParams, TDetailInput extends CollectionDetailInputBase, TDetailParams> = {
service: CollectionService<TCollection, TListParams, TDetailParams>;
buildListParams?: (input: TListInput) => TListParams;
buildDetailParams?: (input: TDetailInput) => TDetailParams;
queryKeys?: CollectionQueryKeys<TListParams, TDetailParams>;
queryKeyNamespace?: QueryNamespace;
cacheConfig?: CacheConfig;
defaultPageSize?: number;
};
export declare function createCollectionHooks<TCollection, TListInput extends CollectionListInputBase, TListParams, TDetailInput extends CollectionDetailInputBase, TDetailParams>({ service, buildListParams, buildDetailParams, queryKeys, queryKeyNamespace, cacheConfig, defaultPageSize, }: CreateCollectionHooksConfig<TCollection, TListInput, TListParams, TDetailInput, TDetailParams>): {
getListQueryOptions: (input: TListInput, options?: {
queryOptions?: ReadQueryOptions<CollectionListResponse<TCollection>> | undefined;
cacheStrategy?: CacheStrategy;
} | undefined) => import("../shared/hook-types").QueryFactoryOptions<CollectionListResponse<TCollection>>;
getDetailQueryOptions: (input: TDetailInput, options?: {
queryOptions?: ReadQueryOptions<TCollection | null> | undefined;
cacheStrategy?: CacheStrategy;
} | undefined) => import("../shared/hook-types").QueryFactoryOptions<TCollection | null>;
useCollections: (input: TListInput, options?: {
queryOptions?: ReadQueryOptions<CollectionListResponse<TCollection>>;
}) => UseCollectionsResult<TCollection>;
useSuspenseCollections: (input: TListInput, options?: {
queryOptions?: SuspenseQueryOptions<CollectionListResponse<TCollection>>;
}) => UseSuspenseCollectionsResult<TCollection>;
useCollection: (input: TDetailInput, options?: {
queryOptions?: ReadQueryOptions<TCollection | null>;
}) => UseCollectionResult<TCollection>;
useSuspenseCollection: (input: TDetailInput, options?: {
queryOptions?: SuspenseQueryOptions<TCollection | null>;
}) => UseSuspenseCollectionResult<TCollection>;
usePrefetchCollections: (options?: {
cacheStrategy?: CacheStrategy;
defaultDelay?: number;
skipIfCached?: boolean;
skipMode?: PrefetchSkipMode;
}) => {
prefetchCollections: (input: TListInput) => Promise<void>;
delayedPrefetch: (input: TListInput, delay?: number, prefetchId?: string) => string;
cancelPrefetch: (prefetchId: string) => void;
};
usePrefetchCollection: (options?: {
cacheStrategy?: CacheStrategy;
defaultDelay?: number;
skipIfCached?: boolean;
skipMode?: PrefetchSkipMode;
}) => {
prefetchCollection: (input: TDetailInput) => Promise<void>;
delayedPrefetch: (input: TDetailInput, delay?: number, prefetchId?: string) => string;
cancelPrefetch: (prefetchId: string) => void;
};
};
export type CollectionHooks<TCollection, TListInput extends CollectionListInputBase, TListParams, TDetailInput extends CollectionDetailInputBase, TDetailParams> = ReturnType<typeof createCollectionHooks<TCollection, TListInput, TListParams, TDetailInput, TDetailParams>>;
//# sourceMappingURL=hooks.d.ts.map