import { IFluidHandle } from '@fluidframework/core-interfaces' ; import { IFluidSerializer , serializeHandles } from '@fluidframework/shared-object-base' ; import { assert , assertNotUndefined } from '../Common' ; import { EditLogSummary , OrderedEditSet } from '../EditLog' ; import { Snapshot } from '../Snapshot' ; import { readFormatVersion , SharedTreeSummary_0_0_2 } from '../SummaryBackCompatibility' ; import { ChangeNode , Edit } from './PersistedTypes' ; /**
 * Format version for summaries that are written.
 * When next changing the format, we should add a new format version variable for the edit-specific summaries and assign it an independent
 * version number.
 */ export const formatVersion = '0.0.2' ; returns internal export type SharedTreeSummarizer < TChange > = ( editLog : OrderedEditSet < TChange > , currentView : Snapshot ) => SharedTreeSummaryBase ; /**
 * The minimal information on a SharedTree summary. Contains the summary format version.
 */ export interface SharedTreeSummaryBase { /**
     * Field on summary under which version is stored.
     */ readonly version : string ; } public export interface SharedTreeSummary < TChange > extends SharedTreeSummaryBase { readonly currentTree : ChangeNode ; /**
     * Information that can populate an edit log.
     */ readonly editHistory ? : EditLogSummary < TChange > ; } param summary param serializer param bind export function serialize ( summary , serializer , bind ) { return assertNotUndefined ( serializeHandles ( summary , serializer , bind ) ) ; } public export function fullHistorySummarizer < TChange > ( editLog , currentView ) { const { editChunks , editIds } = editLog . getEditLogSummary ( ) ; const sequencedEdits = [ ] ; let idIndex = 0 ; editChunks . forEach ( ( { chunk } ) => { assert ( Array . isArray ( chunk ) , 'Handles should not be included in the summary until format version 0.1.0 is being written.' ) ; chunk . forEach ( ( { changes } ) => { sequencedEdits . push ( { changes , id : assertNotUndefined ( editIds [ idIndex ++ ] , 'Number of edits should match number of edit IDs.' ) } ) ; } ) ; } ) ; return { currentTree : currentView . getChangeNodeTree ( ) , sequencedEdits , version : formatVersion } ; } /**
 * Generates a summary with format version 0.1.0. This will prefer handles over edits in edit chunks where possible.
 */ export function fullHistorySummarizer_0_1_0 < TChange > ( editLog , currentView ) { return { currentTree : currentView . getChangeNodeTree ( ) , editHistory : editLog . getEditLogSummary ( true ) , version : readFormatVersion } ; }