import { ITelemetryBaseLogger } from "@fluidframework/common-definitions" ; import { IDocumentService , IDocumentServiceFactory , IResolvedUrl , } from "@fluidframework/driver-definitions" ; import { ISummaryTree } from "@fluidframework/protocol-definitions" ; import { TelemetryLogger , PerformanceEvent , } from "@fluidframework/telemetry-utils" ; import { ensureFluidResolvedUrl } from "@fluidframework/driver-utils" ; import { TokenFetchOptions , OdspResourceTokenFetchOptions , TokenFetcher , IPersistedCache , HostStoragePolicy , IFileEntry , } from "@fluidframework/odsp-driver-definitions" ; import { v4 as uuid } from "uuid" ; import { LocalPersistentCache , NonPersistentCache , } from "./odspCache" ; import { createOdspCacheAndTracker , ICacheAndTracker , } from "./epochTracker" ; import { OdspDocumentService } from "./odspDocumentService" ; import { INewFileInfo , getOdspResolvedUrl , createOdspLogger , toInstrumentedOdspTokenFetcher } from "./odspUtils" ; import { createNewFluidFile } from "./createFile" ; /**
 * Factory for creating the sharepoint document service. Use this if you want to
 * use the sharepoint implementation.
 *
 * This constructor should be used by environments that support dynamic imports and that wish
 * to leverage code splitting as a means to keep bundles as small as possible.
 */ export class OdspDocumentServiceFactoryCore implements IDocumentServiceFactory { public readonly protocolName = "fluid-odsp:" ; private readonly nonPersistentCache = new NonPersistentCache ( ) ; private readonly socketReferenceKeyPrefix ? : string ; public async createContainer ( createNewSummary , createNewResolvedUrl , logger ? ) { ensureFluidResolvedUrl ( createNewResolvedUrl ) ; let odspResolvedUrl = getOdspResolvedUrl ( createNewResolvedUrl ) ; const [ , queryString ] = odspResolvedUrl . url . split ( "?" ) ; const searchParams = new URLSearchParams ( queryString ) ; const filePath = searchParams . get ( "path" ) ; if ( filePath === undefined || filePath === null ) { throw new Error ( "File path should be provided!!" ) ; } const newFileInfo = { driveId : odspResolvedUrl . driveId , siteUrl : odspResolvedUrl . siteUrl , filePath , filename : odspResolvedUrl . fileName , createLinkType : this . hostPolicy . enableShareLinkWithCreate ? odspResolvedUrl . shareLinkInfo ?. createLink ?. type : undefined } ; const odspLogger = createOdspLogger ( logger ) ; const fileEntry = { resolvedUrl : odspResolvedUrl , docId : odspResolvedUrl . hashedDocumentId } ; const cacheAndTracker = createOdspCacheAndTracker ( this . persistedCache , this . nonPersistentCache , fileEntry , odspLogger ) ; return PerformanceEvent . timedExecAsync ( odspLogger , { eventName : "CreateNew" , isWithSummaryUpload : true } , async ( event ) => { odspResolvedUrl = await createNewFluidFile ( toInstrumentedOdspTokenFetcher ( odspLogger , odspResolvedUrl , this . getStorageToken , true ) , newFileInfo , odspLogger , createNewSummary , cacheAndTracker . epochTracker , fileEntry , this . hostPolicy . cacheCreateNewSummary ?? true ) ; const docService = this . createDocumentServiceCore ( odspResolvedUrl , odspLogger , cacheAndTracker ) ; event . end ( { docId : odspResolvedUrl . hashedDocumentId } ) ; return docService ; } ) ; } param getStorageToken param getWebsocketToken param storageFetchWrapper param deltasFetchWrapper param persistedCache constructor ( private readonly getStorageToken , private readonly getWebsocketToken , private readonly getSocketIOClient , protected persistedCache = new LocalPersistentCache ( ) , private readonly hostPolicy = { } ) { if ( this . hostPolicy . isolateSocketCache === true ) { this . socketReferenceKeyPrefix = uuid ( ) ; } } public async createDocumentService ( resolvedUrl , logger ? ) { return this . createDocumentServiceCore ( resolvedUrl , createOdspLogger ( logger ) ) ; } private async createDocumentServiceCore ( resolvedUrl , odspLogger , cacheAndTrackerArg ? ) { const odspResolvedUrl = getOdspResolvedUrl ( resolvedUrl ) ; const cacheAndTracker = cacheAndTrackerArg ?? createOdspCacheAndTracker ( this . persistedCache , this . nonPersistentCache , { resolvedUrl : odspResolvedUrl , docId : odspResolvedUrl . hashedDocumentId } , odspLogger ) ; const storageTokenFetcher = toInstrumentedOdspTokenFetcher ( odspLogger , odspResolvedUrl , this . getStorageToken , true ) ; const webSocketTokenFetcher = this . getWebsocketToken === undefined ? undefined : async ( options ) => toInstrumentedOdspTokenFetcher ( odspLogger , odspResolvedUrl , this . getWebsocketToken ! , false ) ( options , "GetWebsocketToken" ) ; return OdspDocumentService . create ( resolvedUrl , storageTokenFetcher , webSocketTokenFetcher , odspLogger , this . getSocketIOClient , cacheAndTracker . cache , this . hostPolicy , cacheAndTracker . epochTracker , this . socketReferenceKeyPrefix ) ; } }