Skip to content

Commit

Permalink
Add FluidObject to Scope and FluidModule and usages (#8302)
Browse files Browse the repository at this point in the history
FluidObject and IFluidObject are intentionally compatible. This change adds FluidObject to the type signature of our scope and fluid export properties, to ease the transition. I've also updated our internal usages to use scope and fluid export via FluidObject.

related to #8076
  • Loading branch information
anthony-murphy committed Nov 17, 2021
1 parent b165e00 commit 68ae59f
Show file tree
Hide file tree
Showing 22 changed files with 67 additions and 51 deletions.
6 changes: 3 additions & 3 deletions api-report/container-loader.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import { AttachState } from '@fluidframework/container-definitions';
import { ContainerWarning } from '@fluidframework/container-definitions';
import { EventEmitterWithErrorHandling } from '@fluidframework/telemetry-utils';
import { FluidObject } from '@fluidframework/core-interfaces';
import { IAudience } from '@fluidframework/container-definitions';
import { IClientConfiguration } from '@fluidframework/protocol-definitions';
import { IClientDetails } from '@fluidframework/protocol-definitions';
Expand All @@ -21,7 +22,6 @@ import { IDocumentServiceFactory } from '@fluidframework/driver-definitions';
import { IDocumentStorageService } from '@fluidframework/driver-definitions';
import { IFluidCodeDetails } from '@fluidframework/core-interfaces';
import { IFluidModule } from '@fluidframework/container-definitions';
import { IFluidObject } from '@fluidframework/core-interfaces';
import { IFluidResolvedUrl } from '@fluidframework/driver-definitions';
import { IFluidRouter } from '@fluidframework/core-interfaces';
import { IHostLoader } from '@fluidframework/container-definitions';
Expand Down Expand Up @@ -172,7 +172,7 @@ export interface ILoaderProps {
readonly logger?: ITelemetryBaseLogger;
readonly options?: ILoaderOptions;
readonly proxyLoaderFactories?: Map<string, IProxyLoaderFactory>;
readonly scope?: IFluidObject;
readonly scope?: FluidObject;
readonly urlResolver: IUrlResolver;
}

Expand All @@ -183,7 +183,7 @@ export interface ILoaderServices {
readonly documentServiceFactory: IDocumentServiceFactory;
readonly options: ILoaderOptions;
readonly proxyLoaderFactories: Map<string, IProxyLoaderFactory>;
readonly scope: IFluidObject;
readonly scope: FluidObject;
readonly subLogger: ITelemetryLogger;
readonly urlResolver: IUrlResolver;
}
Expand Down
3 changes: 2 additions & 1 deletion api-report/container-runtime-definitions.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { AttachState } from '@fluidframework/container-definitions';
import { ContainerWarning } from '@fluidframework/container-definitions';
import { FluidObject } from '@fluidframework/core-interfaces';
import { FlushMode } from '@fluidframework/runtime-definitions';
import { IClientDetails } from '@fluidframework/protocol-definitions';
import { IContainerRuntimeBase } from '@fluidframework/runtime-definitions';
Expand Down Expand Up @@ -56,7 +57,7 @@ export interface IContainerRuntime extends IProvideContainerRuntime, IProvideFlu
raiseContainerWarning(warning: ContainerWarning): void;
resolveHandle(request: IRequest): Promise<IResponse>;
// (undocumented)
readonly scope: IFluidObject;
readonly scope: IFluidObject & FluidObject;
// (undocumented)
readonly storage: IDocumentStorageService;
}
Expand Down
5 changes: 3 additions & 2 deletions api-report/container-runtime.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { AttachState } from '@fluidframework/container-definitions';
import { ContainerWarning } from '@fluidframework/container-definitions';
import { EventEmitter } from 'events';
import { FluidDataStoreRegistryEntry } from '@fluidframework/runtime-definitions';
import { FluidObject } from '@fluidframework/core-interfaces';
import { FlushMode } from '@fluidframework/runtime-definitions';
import { IAudience } from '@fluidframework/container-definitions';
import { IClientDetails } from '@fluidframework/protocol-definitions';
Expand Down Expand Up @@ -142,7 +143,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
// (undocumented)
get IFluidTokenProvider(): IFluidTokenProvider | undefined;
get isDirty(): boolean;
static load(context: IContainerContext, registryEntries: NamedFluidDataStoreRegistryEntries, requestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>, runtimeOptions?: IContainerRuntimeOptions, containerScope?: IFluidObject, existing?: boolean): Promise<ContainerRuntime>;
static load(context: IContainerContext, registryEntries: NamedFluidDataStoreRegistryEntries, requestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>, runtimeOptions?: IContainerRuntimeOptions, containerScope?: FluidObject, existing?: boolean): Promise<ContainerRuntime>;
// (undocumented)
readonly logger: ITelemetryLogger;
// (undocumented)
Expand All @@ -163,7 +164,7 @@ export class ContainerRuntime extends TypedEventEmitter<IContainerRuntimeEvents>
// @internal @deprecated (undocumented)
readonly runtimeVersion: string;
// (undocumented)
get scope(): IFluidObject;
get scope(): IFluidObject & FluidObject;
// (undocumented)
setAttachState(attachState: AttachState.Attaching | AttachState.Attached): void;
// (undocumented)
Expand Down
3 changes: 2 additions & 1 deletion api-report/runtime-definitions.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { AttachState } from '@fluidframework/container-definitions';
import { ContainerWarning } from '@fluidframework/container-definitions';
import { FluidObject } from '@fluidframework/core-interfaces';
import { IAudience } from '@fluidframework/container-definitions';
import { IClientDetails } from '@fluidframework/protocol-definitions';
import { IDeltaManager } from '@fluidframework/container-definitions';
Expand Down Expand Up @@ -166,7 +167,7 @@ export interface IFluidDataStoreContext extends IEventProvider<IFluidDataStoreCo
readonly options: ILoaderOptions;
readonly packagePath: readonly string[];
raiseContainerWarning(warning: ContainerWarning): void;
readonly scope: IFluidObject;
readonly scope: IFluidObject & FluidObject;
setChannelDirty(address: string): void;
// (undocumented)
readonly storage: IDocumentStorageService;
Expand Down
4 changes: 2 additions & 2 deletions api-report/test-runtime-utils.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { ContainerWarning } from '@fluidframework/container-definitions';
import { CreateChildSummarizerNodeFn } from '@fluidframework/runtime-definitions';
import { CreateChildSummarizerNodeParam } from '@fluidframework/runtime-definitions';
import { EventEmitter } from 'events';
import { FluidObject } from '@fluidframework/core-interfaces';
import { FluidSerializer } from '@fluidframework/runtime-utils';
import { IAudience } from '@fluidframework/container-definitions';
import { IChannel } from '@fluidframework/datastore-definitions';
Expand All @@ -31,7 +32,6 @@ import { IFluidDataStoreRegistry } from '@fluidframework/runtime-definitions';
import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
import { IFluidHandle } from '@fluidframework/core-interfaces';
import { IFluidHandleContext } from '@fluidframework/core-interfaces';
import { IFluidObject } from '@fluidframework/core-interfaces';
import { IGarbageCollectionData } from '@fluidframework/runtime-definitions';
import { IGarbageCollectionSummaryDetails } from '@fluidframework/runtime-definitions';
import { ILoader } from '@fluidframework/container-definitions';
Expand Down Expand Up @@ -325,7 +325,7 @@ export class MockFluidDataStoreContext implements IFluidDataStoreContext {
// (undocumented)
raiseContainerWarning(warning: ContainerWarning): void;
// (undocumented)
scope: IFluidObject;
scope: FluidObject;
// (undocumented)
setChannelDirty(address: string): void;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import { ConnectionMode } from '@fluidframework/protocol-definitions';
import { EventEmitter } from 'events';
import { FluidObject } from '@fluidframework/core-interfaces';
import { IClient } from '@fluidframework/protocol-definitions';
import { IClientConfiguration } from '@fluidframework/protocol-definitions';
import { IClientDetails } from '@fluidframework/protocol-definitions';
Expand Down Expand Up @@ -169,7 +170,7 @@ export interface IContainerContext extends IDisposable {
readonly quorum: IQuorum;
// (undocumented)
raiseContainerWarning(warning: ContainerWarning): void;
readonly scope: IFluidObject;
readonly scope: IFluidObject & FluidObject;
// (undocumented)
readonly serviceConfiguration: IClientConfiguration | undefined;
// (undocumented)
Expand Down Expand Up @@ -327,7 +328,7 @@ export interface IFluidCodeResolver {
// @public (undocumented)
export interface IFluidModule {
// (undocumented)
fluidExport: IFluidObject & Partial<Readonly<IProvideFluidCodeDetailsComparer>>;
fluidExport: IFluidObject & FluidObject<IRuntimeFactory & IProvideFluidCodeDetailsComparer>;
}

// @public @deprecated (undocumented)
Expand Down
5 changes: 3 additions & 2 deletions common/lib/container-definitions/src/fluidModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
* Licensed under the MIT License.
*/

import { IFluidObject, IProvideFluidCodeDetailsComparer } from "@fluidframework/core-interfaces";
import { FluidObject, IFluidObject, IProvideFluidCodeDetailsComparer } from "@fluidframework/core-interfaces";
import { IRuntimeFactory } from "./runtime";

export interface IFluidModule {
fluidExport: IFluidObject & Partial<Readonly<IProvideFluidCodeDetailsComparer>>;
fluidExport: IFluidObject & FluidObject<IRuntimeFactory & IProvideFluidCodeDetailsComparer>;
}
3 changes: 2 additions & 1 deletion common/lib/container-definitions/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
IFluidConfiguration,
IRequest,
IResponse,
FluidObject,
} from "@fluidframework/core-interfaces";
import { IDocumentStorageService } from "@fluidframework/driver-definitions";
import {
Expand Down Expand Up @@ -150,7 +151,7 @@ export interface IContainerContext extends IDisposable {
/**
* Ambient services provided with the context
*/
readonly scope: IFluidObject;
readonly scope: IFluidObject & FluidObject;

raiseContainerWarning(warning: ContainerWarning): void;

Expand Down
7 changes: 5 additions & 2 deletions examples/data-objects/prosemirror/src/prosemirror.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
IRequest,
IResponse,
IFluidHandle,
FluidObject,
} from "@fluidframework/core-interfaces";
import { FluidObjectHandle, mixinRequestHandler } from "@fluidframework/datastore";
import { ISharedMap, SharedMap } from "@fluidframework/map";
Expand All @@ -28,6 +29,7 @@ import { IFluidDataStoreRuntime } from "@fluidframework/datastore-definitions";
import { SharedString } from "@fluidframework/sequence";
import { IFluidHTMLOptions, IFluidHTMLView } from "@fluidframework/view-interfaces";
import { EditorView } from "prosemirror-view";
import { ILoader } from "@fluidframework/container-definitions";
import { nodeTypeKey } from "./fluidBridge";
import { FluidCollabManager, IProvideRichTextEditor } from "./fluidCollabManager";

Expand Down Expand Up @@ -151,10 +153,11 @@ export class ProseMirror extends EventEmitter
this.root = await this.runtime.getChannel("root") as ISharedMap;
this.text = await this.root.get<IFluidHandle<SharedString>>("text")!.get();

if (this.context.scope.ILoader === undefined) {
const scope: FluidObject<ILoader> = this.context.scope;
if (scope.ILoader === undefined) {
throw new Error("scope must include ILoader");
}
this.collabManager = new FluidCollabManager(this.text, this.context.scope.ILoader);
this.collabManager = new FluidCollabManager(this.text, scope.ILoader);

// Access for debugging
// eslint-disable-next-line @typescript-eslint/dot-notation
Expand Down
7 changes: 4 additions & 3 deletions examples/data-objects/scribe/src/scribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
FluidObject,
} from "@fluidframework/core-interfaces";
import { FluidObjectHandle, mixinRequestHandler } from "@fluidframework/datastore";
import { IContainerContext } from "@fluidframework/container-definitions";
import { IContainerContext, ILoader } from "@fluidframework/container-definitions";
import { ContainerRuntime } from "@fluidframework/container-runtime";
import { IDocumentFactory } from "@fluid-example/host-service-interfaces";
import { ISharedMap, SharedMap } from "@fluidframework/map";
Expand Down Expand Up @@ -275,13 +275,14 @@ function initialize(
}
typingDetails.classList.remove("hidden");

if (context.scope.ILoader === undefined) {
const scope: FluidObject<ILoader> = context.scope;
if (scope.ILoader === undefined) {
throw new Error("scope must contain ILoader");
}

// Start typing and register to update the UI
const typeP = scribe.type(
context.scope.ILoader,
scope.ILoader,
url,
root,
runtime,
Expand Down
6 changes: 3 additions & 3 deletions lerna-package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
IProvideFluidDependencySynthesizer,
} from "@fluidframework/synthesize";
import { RuntimeFactoryHelper } from "@fluidframework/runtime-utils";
import { FluidObject } from "@fluidframework/core-interfaces";

/**
* BaseContainerRuntimeFactory produces container runtimes with a given data store and service registry, as well as
Expand Down Expand Up @@ -69,7 +70,7 @@ export class BaseContainerRuntimeFactory
context: IContainerContext,
existing: boolean,
): Promise<ContainerRuntime> {
const scope: Partial<IProvideFluidDependencySynthesizer> = context.scope;
const scope: FluidObject<IProvideFluidDependencySynthesizer> = context.scope;
const parentDependencyContainer = scope.IFluidDependencySynthesizer;
const dc = new DependencyContainer(parentDependencyContainer);
for (const entry of Array.from(this.providerEntries)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License.
*/

import { IRequest, IFluidRouter } from "@fluidframework/core-interfaces";
import { IRequest, IFluidRouter, FluidObject } from "@fluidframework/core-interfaces";
import {
FluidDataStoreRuntime,
ISharedObjectRegistry,
Expand All @@ -26,6 +26,7 @@ import { IChannelFactory } from "@fluidframework/datastore-definitions";
import {
FluidObjectSymbolProvider,
DependencyContainer,
IFluidDependencySynthesizer,
} from "@fluidframework/synthesize";

import {
Expand Down Expand Up @@ -77,7 +78,8 @@ async function createDataObject<TObj extends PureDataObject<O, S, E>, O, S, E ex
// becomes globally available. But it's not full initialization - constructor can't
// access DDSs or other services of runtime as objects are not fully initialized.
// In order to use object, we need to go through full initialization by calling finishInitialization().
const dependencyContainer = new DependencyContainer(context.scope.IFluidDependencySynthesizer);
const scope: FluidObject<IFluidDependencySynthesizer> = context.scope;
const dependencyContainer = new DependencyContainer(scope.IFluidDependencySynthesizer);
const providers = dependencyContainer.synthesize<O>(optionalProviders, {});
const instance = new ctor({ runtime, context, providers, initProps });

Expand Down
7 changes: 4 additions & 3 deletions packages/loader/container-loader/src/containerContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IFluidCodeDetails,
IFluidCodeDetailsComparer,
IProvideFluidCodeDetailsComparer,
FluidObject,
} from "@fluidframework/core-interfaces";
import {
IAudience,
Expand Down Expand Up @@ -51,7 +52,7 @@ const PackageNotFactoryError = "Code package does not implement IRuntimeFactory"
export class ContainerContext implements IContainerContext {
public static async createOrLoad(
container: Container,
scope: IFluidObject,
scope: FluidObject,
codeLoader: ICodeDetailsLoader | ICodeLoader,
codeDetails: IFluidCodeDetails,
baseSnapshot: ISnapshotTree | undefined,
Expand Down Expand Up @@ -166,7 +167,7 @@ export class ContainerContext implements IContainerContext {

constructor(
private readonly container: Container,
public readonly scope: IFluidObject,
public readonly scope: IFluidObject & FluidObject,
private readonly codeLoader: ICodeDetailsLoader | ICodeLoader,
private readonly _codeDetails: IFluidCodeDetails,
private readonly _baseSnapshot: ISnapshotTree | undefined,
Expand Down Expand Up @@ -299,7 +300,7 @@ export class ContainerContext implements IContainerContext {
// #region private

private async getRuntimeFactory(): Promise<IRuntimeFactory> {
const fluidExport: Partial<IProvideRuntimeFactory> | undefined =
const fluidExport: FluidObject<IProvideRuntimeFactory> | undefined =
(await this._fluidModuleP).module?.fluidExport;
const runtimeFactory = fluidExport?.IRuntimeFactory;
if (runtimeFactory === undefined) {
Expand Down
9 changes: 4 additions & 5 deletions packages/loader/container-loader/src/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import { v4 as uuid } from "uuid";
import { ITelemetryBaseLogger, ITelemetryLogger } from "@fluidframework/common-definitions";
import {
FluidObject,
IFluidCodeDetails,
IFluidObject,
IFluidRouter,
IProvideFluidCodeDetailsComparer,
IRequest,
Expand Down Expand Up @@ -184,7 +184,7 @@ export interface ILoaderProps {
* Scope is provided to all container and is a set of shared
* services for container's to integrate with their host environment.
*/
readonly scope?: IFluidObject;
readonly scope?: FluidObject;

/**
* Proxy loader factories for loading containers via proxy in other contexts,
Expand Down Expand Up @@ -235,7 +235,7 @@ export interface ILoaderServices {
* Scope is provided to all container and is a set of shared
* services for container's to integrate with their host environment.
*/
readonly scope: IFluidObject;
readonly scope: FluidObject;

/**
* Proxy loader factories for loading containers via proxy in other contexts,
Expand Down Expand Up @@ -275,11 +275,10 @@ export class Loader implements IHostLoader {
private readonly logger: ITelemetryLogger;

constructor(loaderProps: ILoaderProps) {
const scope = { ...loaderProps.scope };
const scope = { ...loaderProps.scope as FluidObject<ILoader> };
if (loaderProps.options?.provideScopeLoader !== false) {
scope.ILoader = this;
}

this.services = {
urlResolver: createCachedResolver(MultiUrlResolver.create(loaderProps.urlResolver)),
documentServiceFactory: MultiDocumentServiceFactory.create(loaderProps.documentServiceFactory),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
IFluidObject,
IFluidRouter,
IFluidCodeDetails,
FluidObject,
} from "@fluidframework/core-interfaces";
import { IDocumentStorageService } from "@fluidframework/driver-definitions";
import {
Expand Down Expand Up @@ -85,7 +86,7 @@ export interface IContainerRuntime extends
readonly deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>;
readonly storage: IDocumentStorageService;
readonly flushMode: FlushMode;
readonly scope: IFluidObject;
readonly scope: IFluidObject & FluidObject;
/**
* Indicates the attachment state of the container to a host service.
*/
Expand Down
Loading

0 comments on commit 68ae59f

Please sign in to comment.