@techsio/storefront-data
Version:
Medusa-first storefront data layer built on TanStack Query.
44 lines • 2.86 kB
TypeScript
import type { QueryClient } from "@tanstack/react-query";
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 { CatalogListInputBase, CatalogListResponse, CatalogQueryKeys, CatalogService, RegionInfo, UseCatalogProductsResult, UseSuspenseCatalogProductsResult } from "./types";
export type CreateCatalogHooksConfig<TProduct, TListInput extends CatalogListInputBase, TListParams, TFacets> = {
service: CatalogService<TProduct, TListParams, TFacets>;
buildListParams?: (input: TListInput) => TListParams;
queryKeys?: CatalogQueryKeys<TListParams>;
queryKeyNamespace?: QueryNamespace;
cacheConfig?: CacheConfig;
defaultPageSize?: number;
requireRegion?: boolean;
fallbackFacets: TFacets;
};
export declare function createCatalogHooks<TProduct, TListInput extends CatalogListInputBase, TListParams, TFacets>({ service, buildListParams, queryKeys, queryKeyNamespace, cacheConfig, defaultPageSize, requireRegion, fallbackFacets, }: CreateCatalogHooksConfig<TProduct, TListInput, TListParams, TFacets>): {
getListQueryOptions: (input: TListInput, options?: {
queryOptions?: ReadQueryOptions<CatalogListResponse<TProduct, TFacets>> | undefined;
region?: RegionInfo | null;
cacheStrategy?: CacheStrategy;
} | undefined) => import("../shared/hook-types").QueryFactoryOptions<CatalogListResponse<TProduct, TFacets>>;
useCatalogProducts: (input: TListInput, options?: {
cacheStrategy?: CacheStrategy;
queryOptions?: ReadQueryOptions<CatalogListResponse<TProduct, TFacets>>;
}) => UseCatalogProductsResult<TProduct, TFacets>;
useSuspenseCatalogProducts: (input: TListInput, options?: {
cacheStrategy?: CacheStrategy;
queryOptions?: SuspenseQueryOptions<CatalogListResponse<TProduct, TFacets>>;
}) => UseSuspenseCatalogProductsResult<TProduct, TFacets>;
usePrefetchCatalogProducts: (options?: {
cacheStrategy?: CacheStrategy;
defaultDelay?: number;
skipIfCached?: boolean;
skipMode?: PrefetchSkipMode;
}) => {
prefetchCatalogProducts: (input: TListInput) => Promise<void>;
delayedPrefetch: (input: TListInput, delay?: number, prefetchId?: string) => string;
cancelPrefetch: (prefetchId: string) => void;
};
prefetchCatalogProducts: (queryClient: QueryClient, input: TListInput, region?: RegionInfo | null) => Promise<void>;
};
export type CatalogHooks<TProduct, TListInput extends CatalogListInputBase, TListParams, TFacets> = ReturnType<typeof createCatalogHooks<TProduct, TListInput, TListParams, TFacets>>;
//# sourceMappingURL=hooks.d.ts.map