import fs from "fs" ; import { LocalOrdererManager } from "@fluidframework/server-local-server" ; import { DocumentStorage } from "@fluidframework/server-services-shared" ; import { generateToken , Historian } from "@fluidframework/server-services-client" ; import { MongoDatabaseManager , MongoManager , IResourcesFactory } from "@fluidframework/server-services-core" ; import * as utils from "@fluidframework/server-services-utils" ; import * as git from "isomorphic-git" ; import { Provider } from "nconf" ; import { Server } from "socket.io" ; import winston from "winston" ; import { TinyliciousResources } from "./resources" ; import { DbFactory , PubSubPublisher , TaskMessageSender , TenantManager , WebServerFactory , } from "./services" ; const defaultTinyliciousPort = 7070 ; export class TinyliciousResourcesFactory implements IResourcesFactory < TinyliciousResources > { public async create ( config ) { const port = utils . normalizePort ( process . env . PORT ?? defaultTinyliciousPort ) ; const collectionNames = config . get ( "mongo:collectionNames" ) ; const tenantManager = new TenantManager ( `http://localhost:${ port }` ) ; const dbFactory = new DbFactory ( config ) ; const taskMessageSender = new TaskMessageSender ( ) ; const mongoManager = new MongoManager ( dbFactory ) ; const databaseManager = new MongoDatabaseManager ( mongoManager , collectionNames . nodes , collectionNames . documents , collectionNames . deltas , collectionNames . scribeDeltas ) ; const storage = new DocumentStorage ( databaseManager , tenantManager , false ) ; const io = new Server ( { allowEIO3 : true , } ) ; const pubsub = new PubSubPublisher ( io ) ; const webServerFactory = new WebServerFactory ( io ) ; git . plugins . set ( "fs" , fs ) ; const orderManager = new LocalOrdererManager ( storage , databaseManager , tenantManager , taskMessageSender , config . get ( "foreman:permissions" ) , generateToken , async ( tenantId ) => { const url = `http://localhost:${ port }/repos/${ encodeURIComponent ( tenantId ) }` ; return new Historian ( url , false , false ) ; } , winston , undefined , pubsub ) ; return new TinyliciousResources ( config , orderManager , tenantManager , storage , mongoManager , port , webServerFactory ) ; } }