UNPKG

@techsio/storefront-data

Version:

Medusa-first storefront data layer built on TanStack Query.

24 lines (23 loc) • 1.22 kB
import { createCacheConfig } from "../shared/cache-config.js"; import { createProductAttributeQueryKeys } from "./query-keys.js"; function createProductAttributeQueryOptionsFactory({ service, buildDetailParams, queryKeys, queryKeyNamespace = "storefront-data", cacheConfig }) { const resolvedCacheConfig = cacheConfig ?? createCacheConfig(); const resolvedQueryKeys = queryKeys ?? createProductAttributeQueryKeys(queryKeyNamespace); const buildDetail = buildDetailParams ?? ((input)=>input); return { getDetailQueryOptions: (input, options)=>{ const detailParams = buildDetail(input); const cacheStrategy = options?.cacheStrategy ?? "realtime"; return { queryKey: resolvedQueryKeys.detail(detailParams), queryFn: ({ signal })=>{ if (!input.productId) throw new Error("Product id is required for Product Attributes."); return service.getProductAttributes(detailParams, signal); }, ...resolvedCacheConfig[cacheStrategy], ...options?.queryOptions ?? {} }; } }; } export { createProductAttributeQueryOptionsFactory };