import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions" ; import { IChannelAttributes , IFluidDataStoreRuntime , IChannelStorageService , Jsonable , IChannelFactory , } from "@fluidframework/datastore-definitions" ; import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions" ; import { readAndParse } from "@fluidframework/driver-utils" ; import { createSingleBlobSummary , IFluidSerializer , SharedObject , } from "@fluidframework/shared-object-base" ; import { SharedSummaryBlockFactory } from "./sharedSummaryBlockFactory" ; import { ISharedSummaryBlock } from "./interfaces" ; const snapshotFileName = "header" ; /**
 * Defines the in-memory object structure to be used for the conversion to/from serialized.
 * Directly used in JSON.stringify, direct result from JSON.parse.
 */ interface ISharedSummaryBlockDataSerializable { [ key ] : Jsonable ; } /**
 * Implementation of a shared summary block. It does not generate any ops. It is only part of the summary.
 * Data should be set in this object in response to a remote op.
 */ export class SharedSummaryBlock extends SharedObject implements ISharedSummaryBlock { param runtime param id returns public static create ( runtime , id ? ) { return runtime . createChannel ( id , SharedSummaryBlockFactory . Type ) as SharedSummaryBlock ; } returns public static getFactory ( ) { return new SharedSummaryBlockFactory ( ) ; } /**
     * The data held by this object.
     */ private readonly data = new Map < string , Jsonable > ( ) ; param id param runtime param attributes constructor ( id , runtime , attributes ) { super ( id , runtime , attributes ) ; } /**
     * {@inheritDoc ISharedSummaryBlock.get}
     */ public get < T > ( key ) { return this . data . get ( key ) as Jsonable < T > ; } /**
     * {@inheritDoc ISharedSummaryBlock.set}
     */ public set < T > ( key , value ) { this . data . set ( key , value ) ; this . dirty ( ) ; } /**
     * {@inheritDoc @fluidframework/shared-object-base#SharedObject.summarizeCore}
     */ protected summarizeCore ( serializer ) { const contentsBlob = { } ; this . data . forEach ( ( value , key ) => { contentsBlob [ key ] = value ; } ) ; return createSingleBlobSummary ( snapshotFileName , JSON . stringify ( contentsBlob ) ) ; } /**
     * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
     */ protected async loadCore ( storage ) { const contents = await readAndParse < ISharedSummaryBlockDataSerializable > ( storage , snapshotFileName ) ; for ( const [ key , value ] of Object . entries ( contents ) ) { this . data . set ( key , value ) ; } } /**
     * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
     */ protected registerCore ( ) { } /**
     * {@inheritDoc @fluidframework/shared-object-base#SharedObject.onDisconnect}
     */ protected onDisconnect ( ) { } /**
     * {@inheritDoc @fluidframework/shared-object-base#SharedObject.processCore}
     */ protected processCore ( message , local ) { throw new Error ( "shared summary block should not generate any ops." ) ; } protected applyStashedOp ( ) { throw new Error ( "not implemented" ) ; } }