diff --git a/examples/apps/collaborative-textarea/src/container.ts b/examples/apps/collaborative-textarea/src/container.ts index b16f195a15ee..25f874ff6d03 100644 --- a/examples/apps/collaborative-textarea/src/container.ts +++ b/examples/apps/collaborative-textarea/src/container.ts @@ -18,6 +18,6 @@ import { CollaborativeText } from "./fluid-object/"; */ export const CollaborativeTextContainer = new ContainerRuntimeFactoryWithDefaultDataStore( - CollaborativeText.Name, + CollaborativeText.getFactory(), [[CollaborativeText.Name, Promise.resolve(CollaborativeText.getFactory())]], ); diff --git a/examples/apps/likes-and-comments/src/container.ts b/examples/apps/likes-and-comments/src/container.ts index e94c12d5262f..1976b49ecb41 100644 --- a/examples/apps/likes-and-comments/src/container.ts +++ b/examples/apps/likes-and-comments/src/container.ts @@ -20,6 +20,6 @@ import { LikesAndComments } from "./fluidObject"; * FluidObjects. */ export const LikesAndCommentsContainer = new ContainerRuntimeFactoryWithDefaultDataStore( - LikesAndComments.Name, + LikesAndComments.factory, new Map([LikesAndComments.factory.registryEntry]), ); diff --git a/examples/apps/spaces/src/container.ts b/examples/apps/spaces/src/container.ts index 35416f3e1408..3cb8a1381f24 100644 --- a/examples/apps/spaces/src/container.ts +++ b/examples/apps/spaces/src/container.ts @@ -18,6 +18,6 @@ import { Spaces } from "./fluid-object/"; */ export const SpacesContainer = new ContainerRuntimeFactoryWithDefaultDataStore( - Spaces.ComponentName, + Spaces.getFactory(), [[Spaces.ComponentName, Promise.resolve(Spaces.getFactory())]], ); diff --git a/examples/data-objects/canvas/src/index.ts b/examples/data-objects/canvas/src/index.ts index 4112328560d9..dbbca28322ec 100644 --- a/examples/data-objects/canvas/src/index.ts +++ b/examples/data-objects/canvas/src/index.ts @@ -10,12 +10,8 @@ import { import { Ink } from "@fluidframework/ink"; import { Canvas } from "./canvas"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../package.json"); -export const CanvasName = pkg.name as string; - export const CanvasInstantiationFactory = new DataObjectFactory( - CanvasName, + "Canvas", Canvas, [ Ink.getFactory(), @@ -24,8 +20,8 @@ export const CanvasInstantiationFactory = new DataObjectFactory( ); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - CanvasName, + CanvasInstantiationFactory, new Map([ - [CanvasName, Promise.resolve(CanvasInstantiationFactory)], + [CanvasInstantiationFactory.type, Promise.resolve(CanvasInstantiationFactory)], ]), ); diff --git a/examples/data-objects/clicker/src/index.tsx b/examples/data-objects/clicker/src/index.tsx index 3b5967b767a4..9be9344b882f 100644 --- a/examples/data-objects/clicker/src/index.tsx +++ b/examples/data-objects/clicker/src/index.tsx @@ -12,9 +12,7 @@ import React from "react"; import ReactDOM from "react-dom"; import { ClickerAgent } from "./agent"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../package.json"); -export const ClickerName = pkg.name as string; +export const ClickerName = "Clicker"; const counterKey = "counter"; diff --git a/examples/data-objects/diceroller/src/index.ts b/examples/data-objects/diceroller/src/index.ts index f7c23c8aa563..9a44f10e41ab 100644 --- a/examples/data-objects/diceroller/src/index.ts +++ b/examples/data-objects/diceroller/src/index.ts @@ -23,7 +23,7 @@ export { DiceRoller, DiceRollerInstantiationFactory } from "./main"; * Fluid objects. */ export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - DiceRoller.Name, + DiceRollerInstantiationFactory, new Map([ [DiceRoller.Name, Promise.resolve(DiceRollerInstantiationFactory)], ]), diff --git a/examples/data-objects/image-gallery/src/index.tsx b/examples/data-objects/image-gallery/src/index.tsx index ef13dd464a05..53807c7ab875 100644 --- a/examples/data-objects/image-gallery/src/index.tsx +++ b/examples/data-objects/image-gallery/src/index.tsx @@ -106,7 +106,7 @@ export const ImageGalleryInstantiationFactory = new DataObjectFactory( ); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - imageGalleryName, + ImageGalleryInstantiationFactory, new Map([ [imageGalleryName, Promise.resolve(ImageGalleryInstantiationFactory)], ]), diff --git a/examples/data-objects/key-value-cache/src/index.ts b/examples/data-objects/key-value-cache/src/index.ts index f3ed4b3584df..1ed916af5f8f 100644 --- a/examples/data-objects/key-value-cache/src/index.ts +++ b/examples/data-objects/key-value-cache/src/index.ts @@ -32,10 +32,6 @@ import { import { defaultRouteRequestHandler } from "@fluidframework/aqueduct"; import { assert } from "@fluidframework/common-utils"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../package.json"); -export const ComponentName = pkg.name; - export const IKeyValue: keyof IProvideKeyValue = "IKeyValue"; export interface IProvideKeyValue { @@ -139,7 +135,7 @@ export class KeyValueFactoryComponent implements IRuntimeFactory, IFluidDataStor public async instantiateRuntime(context: IContainerContext): Promise { const runtime: ContainerRuntime = await ContainerRuntime.load( context, - new Map([[ComponentName, Promise.resolve(this)]]), + new Map([[this.type, Promise.resolve(this)]]), buildRuntimeRequestHandler( defaultRouteRequestHandler(this.defaultComponentId), innerRequestHandler, @@ -147,7 +143,7 @@ export class KeyValueFactoryComponent implements IRuntimeFactory, IFluidDataStor ); if (!runtime.existing) { - await runtime.createRootDataStore(ComponentName, this.defaultComponentId); + await runtime.createRootDataStore(this.type, this.defaultComponentId); } return runtime; diff --git a/examples/data-objects/monaco/src/index.ts b/examples/data-objects/monaco/src/index.ts index db5f20f34f8a..674e2c1dac17 100644 --- a/examples/data-objects/monaco/src/index.ts +++ b/examples/data-objects/monaco/src/index.ts @@ -26,7 +26,7 @@ const componentFactory = new DataObjectFactory( ); const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - monacoName, + componentFactory, new Map([ [monacoName, Promise.resolve(componentFactory)], ]), diff --git a/examples/data-objects/musica/src/index.tsx b/examples/data-objects/musica/src/index.tsx index 3e89cd4eda68..4ea02988bf7b 100644 --- a/examples/data-objects/musica/src/index.tsx +++ b/examples/data-objects/musica/src/index.tsx @@ -108,7 +108,7 @@ export const MusicaInstantiationFactory = new DataObjectFactory( ); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - musicaName, + MusicaInstantiationFactory, new Map([ [musicaName, Promise.resolve(MusicaInstantiationFactory)], ]), diff --git a/examples/data-objects/pond/src/data-objects/clicker.tsx b/examples/data-objects/pond/src/data-objects/clicker.tsx index 997ea10019d0..fbfea2d05208 100644 --- a/examples/data-objects/pond/src/data-objects/clicker.tsx +++ b/examples/data-objects/pond/src/data-objects/clicker.tsx @@ -15,9 +15,6 @@ const storedMapKey = "storedMap"; const counter1Key = "counter"; const counter2Key = "counter2"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../../package.json"); - /** * Basic Clicker example using new interfaces and stock component classes. */ @@ -27,7 +24,7 @@ export class Clicker extends DataObject implements IFluidHTMLView { private counter1: SharedCounter | undefined; private counter2: SharedCounter | undefined; - public static readonly ComponentName = `${pkg.name as string}-clicker`; + public static readonly ComponentName = `@fluid-example/pond-clicker`; /** * Do setup work here diff --git a/examples/data-objects/pond/src/data-objects/exampleUsingProviders.tsx b/examples/data-objects/pond/src/data-objects/exampleUsingProviders.tsx index 033aad327609..082f6c4036e6 100644 --- a/examples/data-objects/pond/src/data-objects/exampleUsingProviders.tsx +++ b/examples/data-objects/pond/src/data-objects/exampleUsingProviders.tsx @@ -12,9 +12,6 @@ import ReactDOM from "react-dom"; import { IFluidUserInformation } from "../interfaces"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../../package.json"); - /** * Basic example that takes a container provider */ @@ -25,7 +22,7 @@ export class ExampleUsingProviders private userInformation: IFluidUserInformation | undefined; - public static readonly ComponentName = `${pkg.name as string}-example-using-provider`; + public static readonly ComponentName = `@fluid-example/pond-example-using-provider`; protected async hasInitialized() { this.userInformation = await this.providers.IFluidUserInformation; diff --git a/examples/data-objects/pond/src/index.tsx b/examples/data-objects/pond/src/index.tsx index 929ef008fe8d..c1c6f2bc4458 100644 --- a/examples/data-objects/pond/src/index.tsx +++ b/examples/data-objects/pond/src/index.tsx @@ -20,9 +20,7 @@ import { import { IFluidUserInformation } from "./interfaces"; import { userInfoFactory } from "./providers"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../package.json"); -export const PondName = pkg.name as string; +export const PondName = "Pond"; /** * Basic Pond example using stock component classes. @@ -115,7 +113,7 @@ export class Pond extends DataObject implements IFluidHTMLView { // ----- CONTAINER SETUP STUFF ----- export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - Pond.getFactory().type, + Pond.getFactory(), new Map([ Pond.getFactory().registryEntry, ]), diff --git a/examples/data-objects/primitives/src/index.ts b/examples/data-objects/primitives/src/index.ts index 931ba98be06d..93e7eedbbe58 100644 --- a/examples/data-objects/primitives/src/index.ts +++ b/examples/data-objects/primitives/src/index.ts @@ -22,7 +22,7 @@ import { PrimitivesInstantiationFactory } from "./primitivesInstantiationFactory * components. */ export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - PrimitivesName, + PrimitivesInstantiationFactory, new Map([ [PrimitivesName, Promise.resolve(PrimitivesInstantiationFactory)], ]), diff --git a/examples/data-objects/primitives/src/main.tsx b/examples/data-objects/primitives/src/main.tsx index 7a54c3a79ec3..324ab9cb573e 100644 --- a/examples/data-objects/primitives/src/main.tsx +++ b/examples/data-objects/primitives/src/main.tsx @@ -12,9 +12,7 @@ import ReactDOM from "react-dom"; import { SharedMap, IDirectory, IDirectoryValueChanged } from "@fluidframework/map"; import { DdsCollectionComponent } from "./ddsCollection"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../package.json"); -export const PrimitivesName = pkg.name as string; +export const PrimitivesName = "PrimitivesCollection"; /** * Basic DDS examples using view interfaces and stock component classes. diff --git a/examples/data-objects/simple-fluidobject-embed/src/index.tsx b/examples/data-objects/simple-fluidobject-embed/src/index.tsx index f7ae772dd816..dd66874bdd3b 100644 --- a/examples/data-objects/simple-fluidobject-embed/src/index.tsx +++ b/examples/data-objects/simple-fluidobject-embed/src/index.tsx @@ -58,7 +58,7 @@ export const SimpleFluidObjectEmbedInstantiationFactory = new DataObjectFactory( ); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - SimpleFluidObjectEmbedInstantiationFactory.type, + SimpleFluidObjectEmbedInstantiationFactory, new Map([ SimpleFluidObjectEmbedInstantiationFactory.registryEntry, ClickerInstantiationFactory.registryEntry, diff --git a/examples/data-objects/table-document/src/test/tableWithInterception.spec.ts b/examples/data-objects/table-document/src/test/tableWithInterception.spec.ts index 8e47a5bfb78a..94d2323fa128 100644 --- a/examples/data-objects/table-document/src/test/tableWithInterception.spec.ts +++ b/examples/data-objects/table-document/src/test/tableWithInterception.spec.ts @@ -67,7 +67,7 @@ describe("Table Document with Interception", () => { beforeEach(async () => { const factory = new ContainerRuntimeFactoryWithDefaultDataStore( - TableDocumentType, + TableDocument.getFactory(), new Map([ [TableDocumentType, Promise.resolve(TableDocument.getFactory())], ]), diff --git a/examples/data-objects/table-view/package.json b/examples/data-objects/table-view/package.json index ad7e4f42b47e..03b43472f48a 100644 --- a/examples/data-objects/table-view/package.json +++ b/examples/data-objects/table-view/package.json @@ -40,7 +40,9 @@ "@fluid-example/flow-util-lib": "^0.29.0", "@fluid-example/table-document": "^0.29.0", "@fluidframework/aqueduct": "^0.29.0", + "@fluidframework/container-definitions": "^0.29.0", "@fluidframework/core-interfaces": "^0.29.0", + "@fluidframework/runtime-utils": "^0.29.0", "@fluidframework/view-interfaces": "^0.29.0", "@tiny-calc/micro": "0.0.0-alpha.5" }, diff --git a/examples/data-objects/table-view/src/runtime.ts b/examples/data-objects/table-view/src/runtime.ts index 078f0d4610d0..9b0709a7a0f5 100644 --- a/examples/data-objects/table-view/src/runtime.ts +++ b/examples/data-objects/table-view/src/runtime.ts @@ -3,13 +3,19 @@ * Licensed under the MIT License. */ +import { createDataStoreFactory } from "@fluidframework/runtime-utils"; import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqueduct"; +import { IRuntimeFactory } from "@fluidframework/container-definitions"; import { tableViewType } from "./tableview"; -export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( +const factory = createDataStoreFactory( tableViewType, + // eslint-disable-next-line max-len + import(/* webpackChunkName: "table-view", webpackPreload: true */ "./tableview").then((m) => m.TableView.getFactory())); + +export const fluidExport: IRuntimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( + factory, new Map([ - // eslint-disable-next-line max-len - [tableViewType, import(/* webpackChunkName: "table-view", webpackPreload: true */ "./tableview").then((m) => m.TableView.getFactory())], + [factory.type, Promise.resolve(factory)], ]), ); diff --git a/examples/data-objects/todo/src/Todo/Todo.tsx b/examples/data-objects/todo/src/Todo/Todo.tsx index fe339e4c7700..2a2a02851e4a 100644 --- a/examples/data-objects/todo/src/Todo/Todo.tsx +++ b/examples/data-objects/todo/src/Todo/Todo.tsx @@ -12,9 +12,7 @@ import ReactDOM from "react-dom"; import { ITodoItemInitialState, TodoItem } from "../TodoItem/index"; import { TodoView } from "./TodoView"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../../package.json"); -export const TodoName = `${pkg.name as string}-todo`; +export const TodoName = "Todo"; /** * Todo base component. diff --git a/examples/data-objects/todo/src/Todo/todoInstantiationFactory.ts b/examples/data-objects/todo/src/Todo/todoInstantiationFactory.ts index 61098797d0f6..06b2aacefe6b 100644 --- a/examples/data-objects/todo/src/Todo/todoInstantiationFactory.ts +++ b/examples/data-objects/todo/src/Todo/todoInstantiationFactory.ts @@ -6,14 +6,13 @@ import { DataObjectFactory } from "@fluidframework/aqueduct"; import { SharedCell } from "@fluidframework/cell"; import { SharedMap } from "@fluidframework/map"; -import { IFluidDataStoreFactory } from "@fluidframework/runtime-definitions"; import { SharedObjectSequence, SharedString } from "@fluidframework/sequence"; import { TodoItem } from "../TodoItem"; import { TodoName } from "./Todo"; import { Todo } from "./index"; -export const TodoInstantiationFactory: IFluidDataStoreFactory = new DataObjectFactory( +export const TodoInstantiationFactory = new DataObjectFactory( TodoName, Todo, [ diff --git a/examples/data-objects/todo/src/index.tsx b/examples/data-objects/todo/src/index.tsx index aeaaf4f20d5e..2e5dc422d1ba 100644 --- a/examples/data-objects/todo/src/index.tsx +++ b/examples/data-objects/todo/src/index.tsx @@ -7,7 +7,7 @@ import { ContainerRuntimeFactoryWithDefaultDataStore } from "@fluidframework/aqu import { TodoInstantiationFactory, TodoName } from "./Todo"; export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - TodoName, + TodoInstantiationFactory, new Map([ [TodoName, Promise.resolve(TodoInstantiationFactory)], ]), diff --git a/examples/data-objects/vltava/src/index.ts b/examples/data-objects/vltava/src/index.ts index 88cb9742226e..245d22b0b318 100644 --- a/examples/data-objects/vltava/src/index.ts +++ b/examples/data-objects/vltava/src/index.ts @@ -16,6 +16,7 @@ import { IFluidLastEditedTracker, } from "@fluidframework/last-edited-experimental"; import { + IFluidDataStoreFactory, IFluidDataStoreRegistry, IProvideFluidDataStoreFactory, NamedFluidDataStoreRegistryEntries, @@ -67,10 +68,10 @@ export class InternalRegistry implements IFluidDataStoreRegistry, IFluidObjectIn export class VltavaRuntimeFactory extends ContainerRuntimeFactoryWithDefaultDataStore { constructor( - defaultFluidObjectName: string, + defaultFactory: IFluidDataStoreFactory, registryEntries: NamedFluidDataStoreRegistryEntries, ) { - super(defaultFluidObjectName, registryEntries); + super(defaultFactory, registryEntries); } /** @@ -129,7 +130,7 @@ const generateFactory = () => { // TODO: You should be able to specify the default registry instead of just a list of fluidObjects // and the default registry is already determined Issue:#1138 return new VltavaRuntimeFactory( - Anchor.getFactory().type, + Anchor.getFactory(), [ ...containerFluidObjects, LastEditedTrackerDataObject.getFactory().registryEntry, diff --git a/examples/hosts/app-integration/container-views/src/containerCode.ts b/examples/hosts/app-integration/container-views/src/containerCode.ts index 6fdfdf596640..9505ebc54b06 100644 --- a/examples/hosts/app-integration/container-views/src/containerCode.ts +++ b/examples/hosts/app-integration/container-views/src/containerCode.ts @@ -20,7 +20,7 @@ import { DiceRoller, DiceRollerInstantiationFactory } from "./model"; * Fluid objects. */ export const DiceRollerContainerRuntimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - DiceRoller.Name, + DiceRollerInstantiationFactory, new Map([ [DiceRoller.Name, Promise.resolve(DiceRollerInstantiationFactory)], ]), diff --git a/examples/hosts/app-integration/external-views/src/containerCode.ts b/examples/hosts/app-integration/external-views/src/containerCode.ts index 9d5184d17967..74bb658a2c63 100644 --- a/examples/hosts/app-integration/external-views/src/containerCode.ts +++ b/examples/hosts/app-integration/external-views/src/containerCode.ts @@ -18,7 +18,7 @@ import { DiceRollerInstantiationFactory } from "./dataObject"; * Container with a URL of "/", so it can be retrieved via container.request("/"). */ export const DiceRollerContainerRuntimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - DiceRollerInstantiationFactory.type, + DiceRollerInstantiationFactory, new Map([ DiceRollerInstantiationFactory.registryEntry, ]), diff --git a/packages/framework/aqueduct/src/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.ts b/packages/framework/aqueduct/src/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.ts index ceb887d5107f..8f49070f5cd8 100644 --- a/packages/framework/aqueduct/src/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.ts +++ b/packages/framework/aqueduct/src/container-runtime-factories/containerRuntimeFactoryWithDefaultDataStore.ts @@ -4,7 +4,7 @@ */ import { IContainerRuntimeOptions } from "@fluidframework/container-runtime"; -import { NamedFluidDataStoreRegistryEntries } from "@fluidframework/runtime-definitions"; +import { IFluidDataStoreFactory, NamedFluidDataStoreRegistryEntries } from "@fluidframework/runtime-definitions"; import { IContainerRuntime } from "@fluidframework/container-runtime-definitions"; import { DependencyContainerRegistry } from "@fluidframework/synthesize"; import { @@ -26,7 +26,7 @@ export class ContainerRuntimeFactoryWithDefaultDataStore extends BaseContainerRu public static readonly defaultDataStoreId = defaultDataStoreId; constructor( - private readonly defaultDataStoreName: string, + protected readonly defaultFactory: IFluidDataStoreFactory, registryEntries: NamedFluidDataStoreRegistryEntries, providerEntries: DependencyContainerRegistry = [], requestHandlers: RuntimeRequestHandler[] = [], @@ -48,12 +48,9 @@ export class ContainerRuntimeFactoryWithDefaultDataStore extends BaseContainerRu * {@inheritDoc BaseContainerRuntimeFactory.containerInitializingFirstTime} */ protected async containerInitializingFirstTime(runtime: IContainerRuntime) { - const router = await runtime.createRootDataStore( - this.defaultDataStoreName, - ContainerRuntimeFactoryWithDefaultDataStore.defaultDataStoreId, + await runtime.createRootDataStore( + this.defaultFactory.type, + defaultDataStoreId, ); - // We need to request the data store before attaching to ensure it - // runs through its entire instantiation flow. - await router.request({ url: "/" }); } } diff --git a/packages/loader/container-definitions/src/browserPackage.ts b/packages/loader/container-definitions/src/browserPackage.ts index d460cf45dc0c..1a6b26e0df9f 100644 --- a/packages/loader/container-definitions/src/browserPackage.ts +++ b/packages/loader/container-definitions/src/browserPackage.ts @@ -34,7 +34,7 @@ export interface IFluidBrowserPackageEnvironment extends IFluidPackageEnvironmen */ export interface IFluidBrowserPackage extends IFluidPackage { /** - * {@inheritdoc} + * {@inheritDoc @fluidframework/core-interfaces#IFluidPackage.fluid} */ fluid: { /** @@ -42,7 +42,7 @@ export interface IFluidBrowserPackage extends IFluidPackage { */ browser: IFluidBrowserPackageEnvironment; /** - * {@inheritdoc} + * {@inheritDoc @fluidframework/core-interfaces#IFluidPackage.fluid.environment} */ [environment: string]: IFluidPackageEnvironment; } diff --git a/packages/runtime/container-runtime/src/dataStoreRegistry.ts b/packages/runtime/container-runtime/src/dataStoreRegistry.ts index 71d76b928696..38868c2f0615 100644 --- a/packages/runtime/container-runtime/src/dataStoreRegistry.ts +++ b/packages/runtime/container-runtime/src/dataStoreRegistry.ts @@ -9,7 +9,7 @@ import { } from "@fluidframework/runtime-definitions"; export class FluidDataStoreRegistry implements IFluidDataStoreRegistry { - private readonly map: Map>; + private readonly map: Map>; public get IFluidDataStoreRegistry() { return this; } diff --git a/packages/runtime/runtime-utils/src/dataStoreHelpers.ts b/packages/runtime/runtime-utils/src/dataStoreHelpers.ts index 50d7eb6dc800..dbe69db2e3dd 100644 --- a/packages/runtime/runtime-utils/src/dataStoreHelpers.ts +++ b/packages/runtime/runtime-utils/src/dataStoreHelpers.ts @@ -9,6 +9,11 @@ import { IFluidRouter, IRequest, } from "@fluidframework/core-interfaces"; +import { + IFluidDataStoreFactory, + IFluidDataStoreRegistry, + IProvideFluidDataStoreRegistry, +} from "@fluidframework/runtime-definitions"; export async function requestFluidObject( router: IFluidRouter, url: string | IRequest): Promise { @@ -22,3 +27,19 @@ export async function requestFluidObject( assert(response.value); return response.value as T; } + +export type Factory = IFluidDataStoreFactory & Partial; + +export function createDataStoreFactory( + type: string, + factory: Factory | Promise, + ): IFluidDataStoreFactory & IFluidDataStoreRegistry +{ + return { + type, + get IFluidDataStoreFactory() { return this; }, + get IFluidDataStoreRegistry() { return this; }, + instantiateDataStore: async (context) => (await factory).instantiateDataStore(context), + get: async (name: string) => (await factory).IFluidDataStoreRegistry?.get(name), + }; +} diff --git a/packages/test/end-to-end-tests/src/test/contextReload.spec.ts b/packages/test/end-to-end-tests/src/test/contextReload.spec.ts index 5bb78cab3b27..77192f6e8530 100644 --- a/packages/test/end-to-end-tests/src/test/contextReload.spec.ts +++ b/packages/test/end-to-end-tests/src/test/contextReload.spec.ts @@ -115,9 +115,10 @@ describe("context reload", function() { const createRuntimeFactory = (dataStore): IRuntimeFactory => { const type = TestDataStore.type; + const factory = new DataObjectFactory(type, dataStore, [], {}); return new ContainerRuntimeFactoryWithDefaultDataStore( - type, - [[type, Promise.resolve(new DataObjectFactory(type, dataStore, [], {}))]], + factory, + [[type, Promise.resolve(factory)]], ); }; diff --git a/packages/test/end-to-end-tests/src/test/documentDirty.spec.ts b/packages/test/end-to-end-tests/src/test/documentDirty.spec.ts index 055b0260c3d5..6397947e31dc 100644 --- a/packages/test/end-to-end-tests/src/test/documentDirty.spec.ts +++ b/packages/test/end-to-end-tests/src/test/documentDirty.spec.ts @@ -82,13 +82,14 @@ describe("Document Dirty", () => { [ [mapId, SharedMap.getFactory()], ], + "default", ); const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - "default", + factory, [ - ["default", Promise.resolve(factory)], + [factory.type, Promise.resolve(factory)], ], ); diff --git a/packages/test/end-to-end-tests/src/test/loaderTest.spec.ts b/packages/test/end-to-end-tests/src/test/loaderTest.spec.ts index bacabd86564e..1ca49fb9d5ad 100644 --- a/packages/test/end-to-end-tests/src/test/loaderTest.spec.ts +++ b/packages/test/end-to-end-tests/src/test/loaderTest.spec.ts @@ -80,10 +80,10 @@ describe("Loader.request", () => { async function createContainer(): Promise { const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - "default", + testSharedDataObjectFactory1, [ - ["default", Promise.resolve(testSharedDataObjectFactory1)], - ["TestSharedDataObject2", Promise.resolve(testSharedDataObjectFactory2)], + [testSharedDataObjectFactory1.type, Promise.resolve(testSharedDataObjectFactory1)], + [testSharedDataObjectFactory2.type, Promise.resolve(testSharedDataObjectFactory2)], ], ); loader = createLocalLoader([[codeDetails, runtimeFactory]], deltaConnectionServer, urlResolver); diff --git a/packages/test/end-to-end-tests/src/test/opsOnReconnect.spec.ts b/packages/test/end-to-end-tests/src/test/opsOnReconnect.spec.ts index 51daa4ca0ba7..9276c8956137 100644 --- a/packages/test/end-to-end-tests/src/test/opsOnReconnect.spec.ts +++ b/packages/test/end-to-end-tests/src/test/opsOnReconnect.spec.ts @@ -20,7 +20,7 @@ import { LocalDocumentServiceFactory, LocalResolver } from "@fluidframework/loca import { SharedMap, SharedDirectory } from "@fluidframework/map"; import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions"; import { IEnvelope, FlushMode } from "@fluidframework/runtime-definitions"; -import { requestFluidObject } from "@fluidframework/runtime-utils"; +import { requestFluidObject, createDataStoreFactory } from "@fluidframework/runtime-utils"; import { ILocalDeltaConnectionServer, LocalDeltaConnectionServer } from "@fluidframework/server-local-server"; import { SharedString } from "@fluidframework/sequence"; import { @@ -72,12 +72,14 @@ describe("Ops on Reconnect", () => { ], ); + const defaultFactory = createDataStoreFactory("default", factory); + const dataObject2Factory = createDataStoreFactory("dataObject2", factory); const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - "default", + defaultFactory, [ - ["default", Promise.resolve(factory)], - ["dataObject2", Promise.resolve(factory)], + [defaultFactory.type, Promise.resolve(defaultFactory)], + [dataObject2Factory.type, Promise.resolve(dataObject2Factory)], ], ); diff --git a/packages/test/service-load-test/src/loadTestDataStore.ts b/packages/test/service-load-test/src/loadTestDataStore.ts index 96c0df218f80..67369913bd46 100644 --- a/packages/test/service-load-test/src/loadTestDataStore.ts +++ b/packages/test/service-load-test/src/loadTestDataStore.ts @@ -135,6 +135,6 @@ const LoadTestDataStoreInstantiationFactory = new DataObjectFactory( ); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - LoadTestDataStore.DataStoreName, + LoadTestDataStoreInstantiationFactory, new Map([[LoadTestDataStore.DataStoreName, Promise.resolve(LoadTestDataStoreInstantiationFactory)]]), ); diff --git a/packages/test/test-utils/package.json b/packages/test/test-utils/package.json index 636d9c73b623..d4ec1543a57a 100644 --- a/packages/test/test-utils/package.json +++ b/packages/test/test-utils/package.json @@ -62,6 +62,7 @@ "@fluidframework/protocol-definitions": "^0.1014.0", "@fluidframework/request-handler": "^0.29.0", "@fluidframework/runtime-definitions": "^0.29.0", + "@fluidframework/runtime-utils": "^0.29.0", "@fluidframework/server-local-server": "^0.1014.0", "assert": "^2.0.0" }, diff --git a/packages/test/test-utils/src/localCodeLoader.ts b/packages/test/test-utils/src/localCodeLoader.ts index 86b172dc6ebf..9d8e5cf344fa 100644 --- a/packages/test/test-utils/src/localCodeLoader.ts +++ b/packages/test/test-utils/src/localCodeLoader.ts @@ -12,6 +12,7 @@ import { } from "@fluidframework/container-definitions"; import { IFluidCodeDetails, IProvideFluidCodeDetailsComparer } from "@fluidframework/core-interfaces"; import { IProvideFluidDataStoreFactory, IProvideFluidDataStoreRegistry } from "@fluidframework/runtime-definitions"; +import { createDataStoreFactory } from "@fluidframework/runtime-utils"; export type SupportedExportInterfaces = Partial< IProvideRuntimeFactory & @@ -49,16 +50,15 @@ export class LocalCodeLoader implements ICodeLoader { if (maybeExport.IRuntimeFactory !== undefined) { fluidModule = { fluidExport: maybeExport }; } else { - assert( - maybeExport.IFluidDataStoreFactory !== undefined - || maybeExport.IFluidDataStoreRegistry !== undefined); + assert(maybeExport.IFluidDataStoreFactory !== undefined); + const defaultFactory = createDataStoreFactory("default", maybeExport.IFluidDataStoreFactory); fluidModule = { fluidExport: { ... maybeExport, IRuntimeFactory: new ContainerRuntimeFactoryWithDefaultDataStore( - "default", - [["default", Promise.resolve(maybeExport)]]), + defaultFactory, + [[defaultFactory.type, Promise.resolve(defaultFactory)]]), }, }; } diff --git a/packages/test/test-utils/src/testFluidObject.ts b/packages/test/test-utils/src/testFluidObject.ts index 935056681b20..378c5cc932f7 100644 --- a/packages/test/test-utils/src/testFluidObject.ts +++ b/packages/test/test-utils/src/testFluidObject.ts @@ -123,9 +123,6 @@ export type ChannelFactoryRegistry = Iterable<[string | undefined, IChannelFacto * sharedDir = testFluidObject.getSharedObject("sharedDirectory"); */ export class TestFluidObjectFactory implements IFluidDataStoreFactory { - public static readonly type = "TestFluidObjectFactory"; - public readonly type = TestFluidObjectFactory.type; - public get IFluidDataStoreFactory() { return this; } /** @@ -134,7 +131,8 @@ export class TestFluidObjectFactory implements IFluidDataStoreFactory { * IChannelFactory. Entries with string ids are passed to the Fluid object so that it can create a shared object * for it. */ - constructor(private readonly factoryEntries: ChannelFactoryRegistry) { } + constructor(private readonly factoryEntries: ChannelFactoryRegistry, + public readonly type = "TestFluidObjectFactory") { } public async instantiateDataStore(context: IFluidDataStoreContext) { const dataTypes = new Map(); diff --git a/packages/test/version-test-1/@fluid-internal/version-test-2/package.json b/packages/test/version-test-1/@fluid-internal/version-test-2/package.json index 4f0b62b50a0e..a6ba1872bd51 100644 --- a/packages/test/version-test-1/@fluid-internal/version-test-2/package.json +++ b/packages/test/version-test-1/@fluid-internal/version-test-2/package.json @@ -29,6 +29,7 @@ }, "dependencies": { "@fluidframework/aqueduct": "^0.29.0", + "@fluidframework/runtime-utils": "^0.29.0", "@fluidframework/view-interfaces": "^0.29.0", "react": "^16.10.2", "react-dom": "^16.10.2" diff --git a/packages/test/version-test-1/@fluid-internal/version-test-2/src/index.ts b/packages/test/version-test-1/@fluid-internal/version-test-2/src/index.ts index c4c943230b89..8c690a396ff4 100644 --- a/packages/test/version-test-1/@fluid-internal/version-test-2/src/index.ts +++ b/packages/test/version-test-1/@fluid-internal/version-test-2/src/index.ts @@ -6,17 +6,19 @@ import { ContainerRuntimeFactoryWithDefaultDataStore, } from "@fluidframework/aqueduct"; +import { createDataStoreFactory } from "@fluidframework/runtime-utils"; import { VersiontestInstantiationFactory } from "./main"; -// eslint-disable-next-line @typescript-eslint/no-var-requires, @typescript-eslint/no-require-imports -const pkg = require("../package.json"); -const fluidPackageName = pkg.name as string; +const fluidPackageName = "@fluid-internal/version-test-2"; + +const defaultFactory = createDataStoreFactory(fluidPackageName, VersiontestInstantiationFactory); +const object2Factory = createDataStoreFactory("@fluid-internal/version-test-1", VersiontestInstantiationFactory); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - fluidPackageName, + defaultFactory, new Map([ - [fluidPackageName, Promise.resolve(VersiontestInstantiationFactory)], - ["@fluid-internal/version-test-1", Promise.resolve(VersiontestInstantiationFactory)], + [defaultFactory.type, Promise.resolve(defaultFactory)], + [object2Factory.type, Promise.resolve(object2Factory)], ]), ); diff --git a/packages/test/version-test-1/package.json b/packages/test/version-test-1/package.json index c00199368cd5..f9fd362a2008 100644 --- a/packages/test/version-test-1/package.json +++ b/packages/test/version-test-1/package.json @@ -39,6 +39,7 @@ "@fluidframework/aqueduct": "^0.29.0", "@fluidframework/base-host": "^0.29.0", "@fluidframework/common-utils": "^0.25.0", + "@fluidframework/runtime-utils": "^0.29.0", "@fluidframework/view-interfaces": "^0.29.0", "react": "^16.10.2", "react-dom": "^16.10.2" diff --git a/packages/test/version-test-1/src/index.ts b/packages/test/version-test-1/src/index.ts index 832fb3527c17..3a12cc7a1fe4 100644 --- a/packages/test/version-test-1/src/index.ts +++ b/packages/test/version-test-1/src/index.ts @@ -6,16 +6,17 @@ import { ContainerRuntimeFactoryWithDefaultDataStore, } from "@fluidframework/aqueduct"; +import { createDataStoreFactory } from "@fluidframework/runtime-utils"; import { VersiontestInstantiationFactory } from "./main"; -// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires -const pkg = require("../package.json"); -const fluidPackageName = pkg.name as string; +const fluidPackageName = "@fluid-internal/version-test-1"; + +const defaultFactory = createDataStoreFactory(fluidPackageName, VersiontestInstantiationFactory); export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - fluidPackageName, + defaultFactory, new Map([ - [fluidPackageName, Promise.resolve(VersiontestInstantiationFactory)], + [defaultFactory.type, Promise.resolve(defaultFactory)], ]), ); diff --git a/packages/tools/webpack-fluid-loader/src/loader.ts b/packages/tools/webpack-fluid-loader/src/loader.ts index b0331862dbb2..97788f3d3596 100644 --- a/packages/tools/webpack-fluid-loader/src/loader.ts +++ b/packages/tools/webpack-fluid-loader/src/loader.ts @@ -26,7 +26,7 @@ import { import { IFluidObject, IFluidPackage, IFluidCodeDetails } from "@fluidframework/core-interfaces"; import { IDocumentServiceFactory } from "@fluidframework/driver-definitions"; import { LocalDocumentServiceFactory, LocalResolver } from "@fluidframework/local-driver"; -import { RequestParser } from "@fluidframework/runtime-utils"; +import { RequestParser, createDataStoreFactory } from "@fluidframework/runtime-utils"; import { MultiUrlResolver } from "./multiResolver"; import { deltaConns, getDocumentServiceFactory } from "./multiDocumentServiceFactory"; @@ -89,10 +89,12 @@ function wrapWithRuntimeFactoryIfNeeded(packageJson: IFluidPackage, fluidModule: if (fluidModule.fluidExport.IRuntimeFactory === undefined) { const dataStoreFactory = fluidModule.fluidExport.IFluidDataStoreFactory; + const defaultFactory = createDataStoreFactory(packageJson.name, dataStoreFactory); + const runtimeFactory = new ContainerRuntimeFactoryWithDefaultDataStore( - packageJson.name, + defaultFactory, new Map([ - [packageJson.name, Promise.resolve(dataStoreFactory)], + [defaultFactory.type, Promise.resolve(defaultFactory)], ]), ); return { diff --git a/tools/generator-fluid/app/templates/src/index.ts b/tools/generator-fluid/app/templates/src/index.ts index ad5afb960edb..6fdb6977a8cb 100644 --- a/tools/generator-fluid/app/templates/src/index.ts +++ b/tools/generator-fluid/app/templates/src/index.ts @@ -8,7 +8,7 @@ export { DiceRoller }; * as a DataObject that can be created in the container. */ export const fluidExport = new ContainerRuntimeFactoryWithDefaultDataStore( - DiceRoller.factory.type, + DiceRoller.factory, new Map([ DiceRoller.factory.registryEntry, // Add another data store here to create it within the container