import { IFluidSerializer } from '@fluidframework/shared-object-base' ; import { ErrorString } from './Common' ; import { EditLog } from './EditLog' ; import { ChangeNode , Edit , SharedTreeSummaryBase , SharedTreeSummary } from './generic' ; /** The summary format version that is read by SharedTree. */ export const readFormatVersion = '0.1.0' ; internal export interface SharedTreeSummary_0_0_2 < TChange > extends SharedTreeSummaryBase { readonly currentTree : ChangeNode ; /**
     * A list of edits.
     */ readonly sequencedEdits : readonly Edit < TChange > [ ] ; } param jsonSummary param serializer returns export function deserialize ( jsonSummary , serializer ) { let summary ; try { summary = serializer . parse ( jsonSummary ) ; } catch { return 'Json syntax error in Summary' ; } if ( typeof summary !== 'object' ) { return 'Summary is not an object' ; } const { version } = summary ; if ( version !== undefined ) { return { version , ... summary } ; } return 'Missing fields on summary' ; } returns export function convertSummaryToReadFormat < TChange > ( summary ) { const { version } = summary ; if ( version === readFormatVersion ) { const { currentTree , editHistory } = summary as SharedTreeSummary < TChange > ; if ( editHistory !== undefined ) { if ( typeof editHistory !== 'object' ) { return 'Edit history is not an object' ; } const { editChunks , editIds } = editHistory ; if ( editChunks !== undefined && editIds !== undefined ) { return { currentTree , editHistory , version } ; } } } else if ( version === '0.0.2' ) { const { currentTree , sequencedEdits } = summary as SharedTreeSummary_0_0_2 < TChange > ; if ( sequencedEdits !== undefined ) { /**
             * The number of edits that can safely fit in a blob upload.
             */ const maxChunkSize = 1000 ; const temporaryLog = new EditLog < TChange > ( undefined , undefined , maxChunkSize ) ; sequencedEdits . forEach ( ( edit ) => temporaryLog . addSequencedEdit ( edit , { sequenceNumber : 1 , referenceSequenceNumber : 0 } ) ) ; return { currentTree , editHistory : temporaryLog . getEditLogSummary ( ) , version : readFormatVersion } ; } } else { return 'Format version is not supported' ; } return 'Missing fields on summary' ; }