import { default as AbortController } from "abort-controller" ; import { ITelemetryBaseLogger } from "@fluidframework/common-definitions" ; import { assert } from "@fluidframework/common-utils" ; import { IResolvedUrl } from "@fluidframework/driver-definitions" ; import { IOdspResolvedUrl , IPersistedCache , ISnapshotOptions , OdspResourceTokenFetchOptions , TokenFetcher , } from "@fluidframework/odsp-driver-definitions" ; import { ChildLogger , PerformanceEvent } from "@fluidframework/telemetry-utils" ; import { createCacheSnapshotKey , createOdspLogger , getOdspResolvedUrl , toInstrumentedOdspTokenFetcher , } from "./odspUtils" ; import { downloadSnapshot , fetchSnapshotWithRedeem } from "./fetchSnapshot" ; import { IVersionedValueWithEpoch } from "./contracts" ; param resolvedUrl param getStorageToken param persistedCache param logger param hostSnapshotFetchOptions param enableRedeemFallback returns export async function prefetchLatestSnapshot ( resolvedUrl , getStorageToken , persistedCache , logger , hostSnapshotFetchOptions , enableRedeemFallback ? , fetchBinarySnapshotFormat ? ) { const odspLogger = createOdspLogger ( ChildLogger . create ( logger , "PrefetchSnapshot" ) ) ; const odspResolvedUrl = getOdspResolvedUrl ( resolvedUrl ) ; const storageTokenFetcher = toInstrumentedOdspTokenFetcher ( odspLogger , odspResolvedUrl , getStorageToken , true ) ; const snapshotDownloader = async ( finalOdspResolvedUrl , storageToken , snapshotOptions , controller ? ) => { return downloadSnapshot ( finalOdspResolvedUrl , storageToken , odspLogger , snapshotOptions , fetchBinarySnapshotFormat , controller ) ; } ; const snapshotKey = createCacheSnapshotKey ( odspResolvedUrl ) ; let cacheP ; const putInCache = async ( valueWithEpoch ) => { cacheP = persistedCache . put ( snapshotKey , valueWithEpoch ) ; return cacheP ; } ; const removeEntries = async ( ) => persistedCache . removeEntries ( snapshotKey . file ) ; return PerformanceEvent . timedExecAsync ( odspLogger , { eventName : "PrefetchLatestSnapshot" } , async ( ) => { await fetchSnapshotWithRedeem ( odspResolvedUrl , storageTokenFetcher , hostSnapshotFetchOptions , odspLogger , snapshotDownloader , putInCache , removeEntries , enableRedeemFallback ) ; assert ( cacheP !== undefined , 0x1e7 ) ; await cacheP ; return true ; } ) . catch ( async ( error ) => false ) ; }