import { IBlob , ITree } from "@fluidframework/gitresources" ; import { IWholeFlatSummary , IWholeFlatSummaryBlob , IWholeFlatSummaryTreeEntry , } from "@fluidframework/server-services-client" ; export class WholeSummaryReadGitManager { constructor ( /**
     * Find the sha for latest version of a document's summary.
     */ private readonly getLatestVersion , /**
     * Read blob from storage.
     */ private readonly readBlob , /**
     * Read tree recursively from storage.
     */ private readonly readTreeRecursive ) { } public async readSummary ( sha ) { let versionId = sha ; if ( versionId === "latest" ) { versionId = await this . getLatestVersion ( ) ; } const rawTree = await this . readTreeRecursive ( versionId ) ; const wholeFlatSummaryTreeEntries = [ ] ; const wholeFlatSummaryBlobPs = [ ] ; rawTree . tree . forEach ( ( treeEntry ) => { if ( treeEntry . type === "blob" ) { wholeFlatSummaryTreeEntries . push ( { type : "blob" , id : treeEntry . sha , path : treeEntry . path } ) ; wholeFlatSummaryBlobPs . push ( this . getBlob ( treeEntry . sha ) ) ; } else { wholeFlatSummaryTreeEntries . push ( { type : "tree" , path : treeEntry . path } ) ; } } ) ; const wholeFlatSummaryBlobs = await Promise . all ( wholeFlatSummaryBlobPs ) ; return { id : rawTree . sha , trees : [ { id : rawTree . sha , entries : wholeFlatSummaryTreeEntries , sequenceNumber : - 1 } , ] , blobs : wholeFlatSummaryBlobs } ; } private async getBlob ( sha ) { const blob = await this . readBlob ( sha ) ; return { content : blob . content , encoding : blob . encoding === "base64" ? "base64" : "utf-8" , id : blob . sha , size : blob . size } ; } }