import { LoggingError } from "@fluidframework/telemetry-utils" ; import { IDocumentStorageService , IDocumentStorageServicePolicies , ISummaryContext , } from "@fluidframework/driver-definitions" ; import { ICreateBlobResponse , ISnapshotTree , ISummaryHandle , ISummaryTree , ITree , IVersion , } from "@fluidframework/protocol-definitions" ; import { IDisposable , ITelemetryLogger } from "@fluidframework/common-definitions" ; import { runWithRetry } from "./retryUtils" ; export class RetryErrorsStorageAdapter implements IDocumentStorageService , IDisposable { private _disposed = false ; constructor ( private readonly internalStorageService , private readonly logger ) { } public get policies ( ) : IDocumentStorageServicePolicies | undefined { return this . internalStorageService . policies ; } public get disposed ( ) { return this . _disposed ; } public dispose ( ) { this . _disposed = true ; } public get repositoryUrl ( ) : string { return this . internalStorageService . repositoryUrl ; } public async getSnapshotTree ( version ? ) { return this . runWithRetry ( async ( ) => this . internalStorageService . getSnapshotTree ( version ) , "storage_getSnapshotTree" ) ; } public async readBlob ( id ) { return this . runWithRetry ( async ( ) => this . internalStorageService . readBlob ( id ) , "storage_readBlob" ) ; } public async getVersions ( versionId , count ) { return this . runWithRetry ( async ( ) => this . internalStorageService . getVersions ( versionId , count ) , "storage_getVersions" ) ; } public async write ( tree , parents , message , ref ) { return this . runWithRetry ( async ( ) => this . internalStorageService . write ( tree , parents , message , ref ) , "storage_write" ) ; } public async uploadSummaryWithContext ( summary , context ) { return this . runWithRetry ( async ( ) => this . internalStorageService . uploadSummaryWithContext ( summary , context ) , "storage_uploadSummaryWithContext" ) ; } public async downloadSummary ( handle ) { return this . runWithRetry ( async ( ) => this . internalStorageService . downloadSummary ( handle ) , "storage_downloadSummary" ) ; } public async createBlob ( file ) { return this . runWithRetry ( async ( ) => this . internalStorageService . createBlob ( file ) , "storage_createBlob" ) ; } private checkStorageDisposed ( ) { if ( this . _disposed ) { throw new LoggingError ( "storageServiceDisposedCannotRetry" , { canRetry : false } ) ; } } private async runWithRetry < T > ( api , callName ) { return runWithRetry ( api , callName , this . logger , ( ) => this . checkStorageDisposed ( ) ) ; } }