try{let e=typeof window<`u`?window:typeof global<`u`?global:typeof globalThis<`u`?globalThis:typeof self<`u`?self:{},t=new e.Error().stack;t&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[t]=`89be105f-d4b5-4e09-8c4d-9129f578ac6e`,e._sentryDebugIdIdentifier=`sentry-dbid-89be105f-d4b5-4e09-8c4d-9129f578ac6e`)}catch{}import"./rolldown-runtime-eb2nym32.js";import{Ga as e}from"./entry.client-dr7r6s9a.js";import{t}from"./BatchFetchCacheAdaptor-jppkke5o.js";import{t as n}from"./getCatalogMaxBatchSize-ggepkzod.js";var r=class r extends t{static createHydrationCache(t,n,r,i){return new e({name:`HydrationCache+${n}+${r}`,version:1,tables:Object.fromEntries(t.map(e=>[e,{keyPath:e===`BaysideLowTopaz0`?`ids.storeId`:`StoreId`,indexes:null,cacheTimeMs:i}]))})}catalogServiceAdaptor;cacheableHydrationTypes;hydrationCache;queryInvalidator;constructor(e,t,n,i,a,o,s){let c=r.createHydrationCache(n,i,a,t);super(c,s),this.hydrationCache=c,this.catalogServiceAdaptor=e,this.cacheableHydrationTypes=n,this.queryInvalidator=o}async fetchProductInfo(e,t,n,r){return this.isCacheableHydrationType(n)?this.fetchCacheWithBatch(r,e,t,n):this.fetchFromSource(r,e,t,n)}async fetchProductInfosByAlternateId(e,t,n,r,i){let{productIds:a,productInfos:o}=await this.catalogServiceAdaptor.fetchProductInfosByAlternateId(e,t,n,r,i);for(let i in o){if(!Object.prototype.hasOwnProperty.call(o,r))continue;let a=o[r];this.update(i,a,e,t,n)}return{productIds:a,productInfos:o}}async search(e,t,n,r,i,a,o,s){let c=await this.catalogServiceAdaptor.search(e,t,n,r,i,a,o,s);if(this.isCacheableHydrationType(n)){let r=c.Products;for(let[i,a]of Object.entries(r))a!==void 0&&this.update(i,a,e,t,n)}return c}async update(e,t,n,r,i){this.isCacheableHydrationType(i)&&await this.updateCache(e,t,n,r,i)}async preloadCache(e){if(this.cacheableHydrationTypes){let t=this.cacheableHydrationTypes.map(async t=>{let n=e[t];if(n&&n.length>0){let e=this.hydrationCache.getTable(t);if(e)try{await e.setValues(n)}catch(e){throw AggregateError([e],`Failed to preload cache for ${t}: ${e}`)}}});await Promise.all(t)}}addSingleEntryToCache(e,t){if(this.isCacheableHydrationType(t)){let n=this.hydrationCache.getTable(t);n&&n.setValue(e)}}getTableNameForParams(e,t,n,r){return r}async fetchFromSource(e,t,n,r){return this.catalogServiceAdaptor.fetchProductInfo(t,n,r,e)}onCacheUpdated(e,t,n,r){this.queryInvalidator(e,r)}fetchManyFromSource(e,t,n,r){return this.catalogServiceAdaptor.fetchProductInfosFromService(t,n,r,e)}getBatchOptions(e,t,r){return{dbBatchConfig:{batch:!0,maxBatchSize:50},remoteBatchConfig:{batch:!0,windowMs:10,maxBatchSize:n(r)}}}isCacheableHydrationType(e){return this.cacheableHydrationTypes.includes(e)}};export{r as CatalogServiceAdaptorIndexedDbWrapper};