import { IContainerContext } from "@fluidframework/container-definitions" ; import { ContainerRuntime , } from "@fluidframework/container-runtime" ; import { buildRuntimeRequestHandler , RuntimeRequestHandler , } from "@fluidframework/request-handler" ; import { NamedFluidDataStoreRegistryEntries , IFluidDataStoreFactory , } from "@fluidframework/runtime-definitions" ; import { RuntimeFactoryHelper } from "@fluidframework/runtime-utils" ; const defaultStoreId = "" as const ; export class RuntimeFactory extends RuntimeFactoryHelper { private readonly registry : NamedFluidDataStoreRegistryEntries ; constructor ( private readonly defaultStoreFactory , storeFactories = [ defaultStoreFactory ] , private readonly requestHandlers = [ ] ) { super ( ) ; this . registry = ( storeFactories . includes ( defaultStoreFactory ) ? storeFactories : storeFactories . concat ( defaultStoreFactory ) ) . map ( ( factory ) => [ factory . type , factory ] ) as NamedFluidDataStoreRegistryEntries ; } public async instantiateFirstTime ( runtime ) { await runtime . createRootDataStore ( this . defaultStoreFactory . type , defaultStoreId ) ; } public async preInitialize ( context , existing ) { const runtime = await ContainerRuntime . load ( context , this . registry , buildRuntimeRequestHandler ( ... this . requestHandlers ) , undefined , undefined , existing ) ; return runtime ; } }