@fluidframework/fluid-static 2.73.0 → 2.74.0-365691
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/fluidContainer.js
CHANGED
|
@@ -90,9 +90,11 @@ class FluidContainer extends client_utils_1.TypedEventEmitter {
|
|
|
90
90
|
}
|
|
91
91
|
throw new Error("Cannot attach container. Attach method not provided.");
|
|
92
92
|
}
|
|
93
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
93
94
|
async connect() {
|
|
94
95
|
this.container.connect?.();
|
|
95
96
|
}
|
|
97
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
96
98
|
async disconnect() {
|
|
97
99
|
this.container.disconnect?.();
|
|
98
100
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidContainer.js","sourceRoot":"","sources":["../src/fluidContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,iFAI+C;AAU/C,kEAA6D;AAyP7D;;;;GAIG;AACI,KAAK,UAAU,oBAAoB,CAExC,KAED;IACA,MAAM,UAAU,GAAmC,MAAM,KAAK,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;IACzF,IAAA,iBAAM,EACL,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAC1C,KAAK,CAAC,kDAAkD,CACxD,CAAC;IACF,OAAO,IAAI,cAAc,CACxB,KAAK,CAAC,SAAS,EACf,UAAU,CAAC,iBAAiB,CAAC,cAAc,EAC3C,UAAU,CAAC,iBAAiB,CAAC,cAAc,CAC3C,CAAC;AACH,CAAC;AAfD,oDAeC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CACvC,SAAsE;IAEtE,+EAA+E;IAC/E,4EAA4E;IAC5E,kCAAkC;IAClC,OAAO,SAAS,YAAY,cAAc,CAAC;AAC5C,CAAC;AAPD,4DAOC;AAED;;;;;;;;GAQG;AACH,MAAM,cACL,SAAQ,gCA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C,YAAY,CAAC,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport {\n\tAttachState,\n\ttype ConnectionState,\n\ttype ICriticalContainerError,\n} from \"@fluidframework/container-definitions\";\nimport type { IContainer } from \"@fluidframework/container-definitions/internal\";\nimport type { ContainerExtensionStore } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tFluidObject,\n\tIEvent,\n\tIEventProvider,\n\tIFluidHandle,\n\tIFluidLoadable,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport type {\n\tContainerAttachProps,\n\tContainerSchema,\n\tIRootDataObject,\n\tIStaticEntryPoint,\n} from \"./types.js\";\n\n/**\n * Extract the type of 'initialObjects' from the given {@link ContainerSchema} type.\n * @public\n */\nexport type InitialObjects<T extends ContainerSchema> = {\n\t// Construct a LoadableObjectRecord type by enumerating the keys of\n\t// 'ContainerSchema.initialObjects' and inferring the value type of each key.\n\t//\n\t// The '? TChannel : never' is required because infer can only be used in\n\t// a conditional 'extends' expression.\n\t[K in keyof T[\"initialObjects\"]]: T[\"initialObjects\"][K] extends SharedObjectKind<\n\t\tinfer TChannel\n\t>\n\t\t? TChannel\n\t\t: never;\n};\n\n/**\n * Events emitted from {@link IFluidContainer}.\n *\n * @remarks Note: external implementations of this interface are not supported.\n * @sealed\n * @public\n */\nexport interface IFluidContainerEvents extends IEvent {\n\t/**\n\t * Emitted when the {@link IFluidContainer} completes connecting to the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.connect}\n\t */\n\t(event: \"connected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} becomes disconnected from the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.disconnect}\n\t */\n\t(event: \"disconnected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when all local changes/edits have been acknowledged by the service.\n\t *\n\t * @remarks \"dirty\" event will be emitted when the next local change has been made.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"saved\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the first local change has been made, following a \"saved\" event.\n\t *\n\t * @remarks \"saved\" event will be emitted once all local changes have been acknowledged by the service.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"dirty\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} is closed, which permanently disables it.\n\t *\n\t * @remarks Listener parameters:\n\t *\n\t * - `error`: If the container was closed due to error (as opposed to an explicit call to\n\t * {@link IFluidContainer.dispose}), this will contain details about the error that caused it.\n\t */\n\t(event: \"disposed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Provides an entrypoint into the client side of collaborative Fluid data.\n * Provides access to the data as well as status on the collaboration session.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n *\n * @remarks Note: external implementations of this interface are not supported.\n *\n * @sealed\n * @public\n */\nexport interface IFluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends IEventProvider<IFluidContainerEvents> {\n\t/**\n\t * Provides the current connected state of the container\n\t */\n\treadonly connectionState: ConnectionState;\n\n\t/**\n\t * A container is considered **dirty** if it has local changes that have not yet been acknowledged by the service.\n\t *\n\t * @remarks\n\t *\n\t * You should always check the `isDirty` flag before closing the container or navigating away from the page.\n\t * Closing the container while `isDirty === true` may result in the loss of operations that have not yet been\n\t * acknowledged by the service.\n\t *\n\t * A container is considered dirty in the following cases:\n\t *\n\t * 1. The container has been created in the detached state, and either it has not been attached yet or it is\n\t * in the process of being attached (container is in `attaching` state). If container is closed prior to being\n\t * attached, host may never know if the file was created or not.\n\t *\n\t * 2. The container was attached, but it has local changes that have not yet been saved to service endpoint.\n\t * This occurs as part of normal op flow where pending operation (changes) are awaiting acknowledgement from the\n\t * service. In some cases this can be due to lack of network connection. If the network connection is down,\n\t * it needs to be restored for the pending changes to be acknowledged.\n\t */\n\treadonly isDirty: boolean;\n\n\t/**\n\t * Whether or not the container is disposed, which permanently disables it.\n\t */\n\treadonly disposed: boolean;\n\n\t/**\n\t * The collection of data objects and Distributed Data Stores (DDSes) that were specified by the schema.\n\t *\n\t * @remarks These data objects and DDSes exist for the lifetime of the container.\n\t */\n\treadonly initialObjects: InitialObjects<TContainerSchema>;\n\n\t/**\n\t * The current attachment state of the container.\n\t *\n\t * @remarks\n\t *\n\t * Once a container has been attached, it remains attached.\n\t * When loading an existing container, it will already be attached.\n\t */\n\treadonly attachState: AttachState;\n\n\t/**\n\t * A newly created container starts detached from the collaborative service.\n\t * Calling `attach()` uploads the new container to the service and connects to the collaborative service.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#AttachState.Detached} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.attachState}.\n\t *\n\t * @returns A promise which resolves when the attach is complete, with the string identifier of the container.\n\t */\n\tattach(props?: ContainerAttachProps): Promise<string>;\n\n\t/**\n\t * Attempts to connect the container to the delta stream and process operations.\n\t *\n\t * @throws Will throw an error if connection is unsuccessful.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Disconnected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tconnect(): void;\n\n\t/**\n\t * Disconnects the container from the delta stream and stops processing operations.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Connected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tdisconnect(): void;\n\n\t/**\n\t * Create a new data object or Distributed Data Store (DDS) of the specified type.\n\t *\n\t * @param objectClass - The class of the `DataObject` or `SharedObject` to create.\n\t *\n\t * @typeParam T - The class of the `DataObject` or `SharedObject`.\n\t *\n\t * @remarks\n\t *\n\t * In order to share the data object or DDS with other collaborators and retrieve it later,\n\t * store its handle in a collection like a SharedDirectory from your initialObjects.\n\t * It's typically a good idea to set any initial state on the object before doing so,\n\t * as it is both more efficient and helpful to maintain domain model invariants\n\t * (e.g. this approach easily allows state to only be set once).\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const existingDirectory = container.initialObjects.myDirectory;\n\t * const map = await container.create(SharedMap);\n\t * map.set(\"initialState\", \"someValue\");\n\t * existingDirectory.set(\"myMap\", map.handle);\n\t * ```\n\t */\n\tcreate<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T>;\n\n\t/**\n\t * Dispose of the container instance, permanently disabling it.\n\t */\n\tdispose(): void;\n}\n\n/**\n * Internal interface for {@link IFluidContainer}.\n *\n * @internal\n */\nexport interface IFluidContainerInternal extends ContainerExtensionStore {\n\t/**\n\t * The underlying {@link @fluidframework/container-definitions#IContainer}.\n\t *\n\t * @remarks Used to power debug tooling and experimental features.\n\t */\n\treadonly container: IContainer;\n\n\t/**\n\t * Upload a blob of data.\n\t * Although it is marked as internal, there is external usage of this function for experimental purposes.\n\t * Please contact yunho-microsoft or vladsud if you need to change it.\n\t * @param blob - blob to be uploaded.\n\t *\n\t * @remarks This method is used to expose uploadBlob to the IFluidContainer level. UploadBlob will upload data to server side (as of now, ODSP only). There is no downloadBlob provided as it is not needed(blob lifetime managed by server).\n\t */\n\tuploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>;\n}\n\n/**\n * Creates an {@link IFluidContainer} from the provided `container` and `rootDataObject`.\n *\n * @internal\n */\nexport async function createFluidContainer<\n\tTContainerSchema extends ContainerSchema = ContainerSchema,\n>(props: {\n\tcontainer: IContainer;\n}): Promise<IFluidContainer<TContainerSchema>> {\n\tconst entryPoint: FluidObject<IStaticEntryPoint> = await props.container.getEntryPoint();\n\tassert(\n\t\tentryPoint.IStaticEntryPoint !== undefined,\n\t\t0xb9e /* entryPoint must be of type IStaticEntryPoint */,\n\t);\n\treturn new FluidContainer<TContainerSchema>(\n\t\tprops.container,\n\t\tentryPoint.IStaticEntryPoint.rootDataObject,\n\t\tentryPoint.IStaticEntryPoint.extensionStore,\n\t);\n}\n\n/**\n * Check that the provided `container` is an internal {@link IFluidContainerInternal}.\n *\n * @internal\n */\nexport function isInternalFluidContainer<TContainerSchema extends ContainerSchema>(\n\tcontainer: IFluidContainer<TContainerSchema> | IFluidContainerInternal,\n): container is IFluidContainerInternal {\n\t// IFluidContainer is sealed; so we never expect an `IFluidContainer` not to be\n\t// `IFluidContainerInternal` implemented by `FluidContainer`. To be caution,\n\t// we use `instanceof` to confirm.\n\treturn container instanceof FluidContainer;\n}\n\n/**\n * {@link IFluidContainer} implementation.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n * @remarks\n *\n * Note: this implementation is not complete. Consumers who rely on {@link IFluidContainer.attach}\n * will need to utilize or provide a service-specific implementation of this type that implements that method.\n */\nclass FluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends TypedEventEmitter<IFluidContainerEvents>\n\timplements IFluidContainer<TContainerSchema>, IFluidContainerInternal\n{\n\tprivate readonly connectedHandler = (): boolean => this.emit(\"connected\");\n\tprivate readonly disconnectedHandler = (): boolean => this.emit(\"disconnected\");\n\tprivate readonly disposedHandler = (error?: ICriticalContainerError): boolean =>\n\t\tthis.emit(\"disposed\", error);\n\tprivate readonly savedHandler = (): boolean => this.emit(\"saved\");\n\tprivate readonly dirtyHandler = (): boolean => this.emit(\"dirty\");\n\tpublic readonly acquireExtension: ContainerExtensionStore[\"acquireExtension\"];\n\n\tpublic constructor(\n\t\tpublic readonly container: IContainer,\n\t\tprivate readonly rootDataObject: IRootDataObject,\n\t\textensionStore: ContainerExtensionStore,\n\t) {\n\t\tsuper();\n\t\tthis.acquireExtension = extensionStore.acquireExtension.bind(extensionStore);\n\t\tcontainer.on(\"connected\", this.connectedHandler);\n\t\tcontainer.on(\"closed\", this.disposedHandler);\n\t\tcontainer.on(\"disconnected\", this.disconnectedHandler);\n\t\tcontainer.on(\"saved\", this.savedHandler);\n\t\tcontainer.on(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic get isDirty(): boolean {\n\t\treturn this.container.isDirty;\n\t}\n\n\tpublic get attachState(): AttachState {\n\t\treturn this.container.attachState;\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this.container.closed;\n\t}\n\n\tpublic get connectionState(): ConnectionState {\n\t\treturn this.container.connectionState;\n\t}\n\n\tpublic get initialObjects(): InitialObjects<TContainerSchema> {\n\t\treturn this.rootDataObject.initialObjects as InitialObjects<TContainerSchema>;\n\t}\n\n\t/**\n\t * Incomplete base implementation of {@link IFluidContainer.attach}.\n\t *\n\t * @remarks\n\t *\n\t * Note: this implementation will unconditionally throw.\n\t * Consumers who rely on this will need to utilize or provide a service specific implementation of this base type\n\t * that provides an implementation of this method.\n\t *\n\t * The reason is because externally we are presenting a separation between the service and the `FluidContainer`,\n\t * but internally this separation is not there.\n\t */\n\tpublic async attach(props?: ContainerAttachProps): Promise<string> {\n\t\tif (this.container.attachState !== AttachState.Detached) {\n\t\t\tthrow new Error(\"Cannot attach container. Container is not in detached state.\");\n\t\t}\n\t\tthrow new Error(\"Cannot attach container. Attach method not provided.\");\n\t}\n\n\tpublic async connect(): Promise<void> {\n\t\tthis.container.connect?.();\n\t}\n\n\tpublic async disconnect(): Promise<void> {\n\t\tthis.container.disconnect?.();\n\t}\n\n\tpublic async create<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T> {\n\t\treturn this.rootDataObject.create(objectClass);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.container.close();\n\t\tthis.container.off(\"connected\", this.connectedHandler);\n\t\tthis.container.off(\"closed\", this.disposedHandler);\n\t\tthis.container.off(\"disconnected\", this.disconnectedHandler);\n\t\tthis.container.off(\"saved\", this.savedHandler);\n\t\tthis.container.off(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\treturn this.rootDataObject.uploadBlob(blob);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fluidContainer.js","sourceRoot":"","sources":["../src/fluidContainer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAiE;AACjE,iFAI+C;AAU/C,kEAA6D;AAyP7D;;;;GAIG;AACI,KAAK,UAAU,oBAAoB,CAExC,KAED;IACA,MAAM,UAAU,GAAmC,MAAM,KAAK,CAAC,SAAS,CAAC,aAAa,EAAE,CAAC;IACzF,IAAA,iBAAM,EACL,UAAU,CAAC,iBAAiB,KAAK,SAAS,EAC1C,KAAK,CAAC,kDAAkD,CACxD,CAAC;IACF,OAAO,IAAI,cAAc,CACxB,KAAK,CAAC,SAAS,EACf,UAAU,CAAC,iBAAiB,CAAC,cAAc,EAC3C,UAAU,CAAC,iBAAiB,CAAC,cAAc,CAC3C,CAAC;AACH,CAAC;AAfD,oDAeC;AAED;;;;GAIG;AACH,SAAgB,wBAAwB,CACvC,SAAsE;IAEtE,+EAA+E;IAC/E,4EAA4E;IAC5E,kCAAkC;IAClC,OAAO,SAAS,YAAY,cAAc,CAAC;AAC5C,CAAC;AAPD,4DAOC;AAED;;;;;;;;GAQG;AACH,MAAM,cACL,SAAQ,gCAAwC;IAWhD,YACiB,SAAqB,EACpB,cAA+B,EAChD,cAAuC;QAEvC,KA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IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport {\n\tAttachState,\n\ttype ConnectionState,\n\ttype ICriticalContainerError,\n} from \"@fluidframework/container-definitions\";\nimport type { IContainer } from \"@fluidframework/container-definitions/internal\";\nimport type { ContainerExtensionStore } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tFluidObject,\n\tIEvent,\n\tIEventProvider,\n\tIFluidHandle,\n\tIFluidLoadable,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport type {\n\tContainerAttachProps,\n\tContainerSchema,\n\tIRootDataObject,\n\tIStaticEntryPoint,\n} from \"./types.js\";\n\n/**\n * Extract the type of 'initialObjects' from the given {@link ContainerSchema} type.\n * @public\n */\nexport type InitialObjects<T extends ContainerSchema> = {\n\t// Construct a LoadableObjectRecord type by enumerating the keys of\n\t// 'ContainerSchema.initialObjects' and inferring the value type of each key.\n\t//\n\t// The '? TChannel : never' is required because infer can only be used in\n\t// a conditional 'extends' expression.\n\t[K in keyof T[\"initialObjects\"]]: T[\"initialObjects\"][K] extends SharedObjectKind<\n\t\tinfer TChannel\n\t>\n\t\t? TChannel\n\t\t: never;\n};\n\n/**\n * Events emitted from {@link IFluidContainer}.\n *\n * @remarks Note: external implementations of this interface are not supported.\n * @sealed\n * @public\n */\nexport interface IFluidContainerEvents extends IEvent {\n\t/**\n\t * Emitted when the {@link IFluidContainer} completes connecting to the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.connect}\n\t */\n\t(event: \"connected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} becomes disconnected from the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.disconnect}\n\t */\n\t(event: \"disconnected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when all local changes/edits have been acknowledged by the service.\n\t *\n\t * @remarks \"dirty\" event will be emitted when the next local change has been made.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"saved\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the first local change has been made, following a \"saved\" event.\n\t *\n\t * @remarks \"saved\" event will be emitted once all local changes have been acknowledged by the service.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"dirty\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} is closed, which permanently disables it.\n\t *\n\t * @remarks Listener parameters:\n\t *\n\t * - `error`: If the container was closed due to error (as opposed to an explicit call to\n\t * {@link IFluidContainer.dispose}), this will contain details about the error that caused it.\n\t */\n\t(event: \"disposed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Provides an entrypoint into the client side of collaborative Fluid data.\n * Provides access to the data as well as status on the collaboration session.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n *\n * @remarks Note: external implementations of this interface are not supported.\n *\n * @sealed\n * @public\n */\nexport interface IFluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends IEventProvider<IFluidContainerEvents> {\n\t/**\n\t * Provides the current connected state of the container\n\t */\n\treadonly connectionState: ConnectionState;\n\n\t/**\n\t * A container is considered **dirty** if it has local changes that have not yet been acknowledged by the service.\n\t *\n\t * @remarks\n\t *\n\t * You should always check the `isDirty` flag before closing the container or navigating away from the page.\n\t * Closing the container while `isDirty === true` may result in the loss of operations that have not yet been\n\t * acknowledged by the service.\n\t *\n\t * A container is considered dirty in the following cases:\n\t *\n\t * 1. The container has been created in the detached state, and either it has not been attached yet or it is\n\t * in the process of being attached (container is in `attaching` state). If container is closed prior to being\n\t * attached, host may never know if the file was created or not.\n\t *\n\t * 2. The container was attached, but it has local changes that have not yet been saved to service endpoint.\n\t * This occurs as part of normal op flow where pending operation (changes) are awaiting acknowledgement from the\n\t * service. In some cases this can be due to lack of network connection. If the network connection is down,\n\t * it needs to be restored for the pending changes to be acknowledged.\n\t */\n\treadonly isDirty: boolean;\n\n\t/**\n\t * Whether or not the container is disposed, which permanently disables it.\n\t */\n\treadonly disposed: boolean;\n\n\t/**\n\t * The collection of data objects and Distributed Data Stores (DDSes) that were specified by the schema.\n\t *\n\t * @remarks These data objects and DDSes exist for the lifetime of the container.\n\t */\n\treadonly initialObjects: InitialObjects<TContainerSchema>;\n\n\t/**\n\t * The current attachment state of the container.\n\t *\n\t * @remarks\n\t *\n\t * Once a container has been attached, it remains attached.\n\t * When loading an existing container, it will already be attached.\n\t */\n\treadonly attachState: AttachState;\n\n\t/**\n\t * A newly created container starts detached from the collaborative service.\n\t * Calling `attach()` uploads the new container to the service and connects to the collaborative service.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#AttachState.Detached} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.attachState}.\n\t *\n\t * @returns A promise which resolves when the attach is complete, with the string identifier of the container.\n\t */\n\tattach(props?: ContainerAttachProps): Promise<string>;\n\n\t/**\n\t * Attempts to connect the container to the delta stream and process operations.\n\t *\n\t * @throws Will throw an error if connection is unsuccessful.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Disconnected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tconnect(): void;\n\n\t/**\n\t * Disconnects the container from the delta stream and stops processing operations.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Connected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tdisconnect(): void;\n\n\t/**\n\t * Create a new data object or Distributed Data Store (DDS) of the specified type.\n\t *\n\t * @param objectClass - The class of the `DataObject` or `SharedObject` to create.\n\t *\n\t * @typeParam T - The class of the `DataObject` or `SharedObject`.\n\t *\n\t * @remarks\n\t *\n\t * In order to share the data object or DDS with other collaborators and retrieve it later,\n\t * store its handle in a collection like a SharedDirectory from your initialObjects.\n\t * It's typically a good idea to set any initial state on the object before doing so,\n\t * as it is both more efficient and helpful to maintain domain model invariants\n\t * (e.g. this approach easily allows state to only be set once).\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const existingDirectory = container.initialObjects.myDirectory;\n\t * const map = await container.create(SharedMap);\n\t * map.set(\"initialState\", \"someValue\");\n\t * existingDirectory.set(\"myMap\", map.handle);\n\t * ```\n\t */\n\tcreate<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T>;\n\n\t/**\n\t * Dispose of the container instance, permanently disabling it.\n\t */\n\tdispose(): void;\n}\n\n/**\n * Internal interface for {@link IFluidContainer}.\n *\n * @internal\n */\nexport interface IFluidContainerInternal extends ContainerExtensionStore {\n\t/**\n\t * The underlying {@link @fluidframework/container-definitions#IContainer}.\n\t *\n\t * @remarks Used to power debug tooling and experimental features.\n\t */\n\treadonly container: IContainer;\n\n\t/**\n\t * Upload a blob of data.\n\t * Although it is marked as internal, there is external usage of this function for experimental purposes.\n\t * Please contact yunho-microsoft or vladsud if you need to change it.\n\t * @param blob - blob to be uploaded.\n\t *\n\t * @remarks This method is used to expose uploadBlob to the IFluidContainer level. UploadBlob will upload data to server side (as of now, ODSP only). There is no downloadBlob provided as it is not needed(blob lifetime managed by server).\n\t */\n\tuploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>;\n}\n\n/**\n * Creates an {@link IFluidContainer} from the provided `container` and `rootDataObject`.\n *\n * @internal\n */\nexport async function createFluidContainer<\n\tTContainerSchema extends ContainerSchema = ContainerSchema,\n>(props: {\n\tcontainer: IContainer;\n}): Promise<IFluidContainer<TContainerSchema>> {\n\tconst entryPoint: FluidObject<IStaticEntryPoint> = await props.container.getEntryPoint();\n\tassert(\n\t\tentryPoint.IStaticEntryPoint !== undefined,\n\t\t0xb9e /* entryPoint must be of type IStaticEntryPoint */,\n\t);\n\treturn new FluidContainer<TContainerSchema>(\n\t\tprops.container,\n\t\tentryPoint.IStaticEntryPoint.rootDataObject,\n\t\tentryPoint.IStaticEntryPoint.extensionStore,\n\t);\n}\n\n/**\n * Check that the provided `container` is an internal {@link IFluidContainerInternal}.\n *\n * @internal\n */\nexport function isInternalFluidContainer<TContainerSchema extends ContainerSchema>(\n\tcontainer: IFluidContainer<TContainerSchema> | IFluidContainerInternal,\n): container is IFluidContainerInternal {\n\t// IFluidContainer is sealed; so we never expect an `IFluidContainer` not to be\n\t// `IFluidContainerInternal` implemented by `FluidContainer`. To be caution,\n\t// we use `instanceof` to confirm.\n\treturn container instanceof FluidContainer;\n}\n\n/**\n * {@link IFluidContainer} implementation.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n * @remarks\n *\n * Note: this implementation is not complete. Consumers who rely on {@link IFluidContainer.attach}\n * will need to utilize or provide a service-specific implementation of this type that implements that method.\n */\nclass FluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends TypedEventEmitter<IFluidContainerEvents>\n\timplements IFluidContainer<TContainerSchema>, IFluidContainerInternal\n{\n\tprivate readonly connectedHandler = (): boolean => this.emit(\"connected\");\n\tprivate readonly disconnectedHandler = (): boolean => this.emit(\"disconnected\");\n\tprivate readonly disposedHandler = (error?: ICriticalContainerError): boolean =>\n\t\tthis.emit(\"disposed\", error);\n\tprivate readonly savedHandler = (): boolean => this.emit(\"saved\");\n\tprivate readonly dirtyHandler = (): boolean => this.emit(\"dirty\");\n\tpublic readonly acquireExtension: ContainerExtensionStore[\"acquireExtension\"];\n\n\tpublic constructor(\n\t\tpublic readonly container: IContainer,\n\t\tprivate readonly rootDataObject: IRootDataObject,\n\t\textensionStore: ContainerExtensionStore,\n\t) {\n\t\tsuper();\n\t\tthis.acquireExtension = extensionStore.acquireExtension.bind(extensionStore);\n\t\tcontainer.on(\"connected\", this.connectedHandler);\n\t\tcontainer.on(\"closed\", this.disposedHandler);\n\t\tcontainer.on(\"disconnected\", this.disconnectedHandler);\n\t\tcontainer.on(\"saved\", this.savedHandler);\n\t\tcontainer.on(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic get isDirty(): boolean {\n\t\treturn this.container.isDirty;\n\t}\n\n\tpublic get attachState(): AttachState {\n\t\treturn this.container.attachState;\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this.container.closed;\n\t}\n\n\tpublic get connectionState(): ConnectionState {\n\t\treturn this.container.connectionState;\n\t}\n\n\tpublic get initialObjects(): InitialObjects<TContainerSchema> {\n\t\treturn this.rootDataObject.initialObjects as InitialObjects<TContainerSchema>;\n\t}\n\n\t/**\n\t * Incomplete base implementation of {@link IFluidContainer.attach}.\n\t *\n\t * @remarks\n\t *\n\t * Note: this implementation will unconditionally throw.\n\t * Consumers who rely on this will need to utilize or provide a service specific implementation of this base type\n\t * that provides an implementation of this method.\n\t *\n\t * The reason is because externally we are presenting a separation between the service and the `FluidContainer`,\n\t * but internally this separation is not there.\n\t */\n\tpublic async attach(props?: ContainerAttachProps): Promise<string> {\n\t\tif (this.container.attachState !== AttachState.Detached) {\n\t\t\tthrow new Error(\"Cannot attach container. Container is not in detached state.\");\n\t\t}\n\t\tthrow new Error(\"Cannot attach container. Attach method not provided.\");\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\tpublic async connect(): Promise<void> {\n\t\tthis.container.connect?.();\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\tpublic async disconnect(): Promise<void> {\n\t\tthis.container.disconnect?.();\n\t}\n\n\tpublic async create<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T> {\n\t\treturn this.rootDataObject.create(objectClass);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.container.close();\n\t\tthis.container.off(\"connected\", this.connectedHandler);\n\t\tthis.container.off(\"closed\", this.disposedHandler);\n\t\tthis.container.off(\"disconnected\", this.disconnectedHandler);\n\t\tthis.container.off(\"saved\", this.savedHandler);\n\t\tthis.container.off(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\treturn this.rootDataObject.uploadBlob(blob);\n\t}\n}\n"]}
|
package/lib/fluidContainer.js
CHANGED
|
@@ -85,9 +85,11 @@ class FluidContainer extends TypedEventEmitter {
|
|
|
85
85
|
}
|
|
86
86
|
throw new Error("Cannot attach container. Attach method not provided.");
|
|
87
87
|
}
|
|
88
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
88
89
|
async connect() {
|
|
89
90
|
this.container.connect?.();
|
|
90
91
|
}
|
|
92
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
91
93
|
async disconnect() {
|
|
92
94
|
this.container.disconnect?.();
|
|
93
95
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fluidContainer.js","sourceRoot":"","sources":["../src/fluidContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACN,WAAW,GAGX,MAAM,uCAAuC,CAAC;AAU/C,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAyP7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAExC,KAED;IACA,MAAM,UAAU,GAAmC,MAAM,KAAK,CAAC,SAAS,CAAC,a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I,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport {\n\tAttachState,\n\ttype ConnectionState,\n\ttype ICriticalContainerError,\n} from \"@fluidframework/container-definitions\";\nimport type { IContainer } from \"@fluidframework/container-definitions/internal\";\nimport type { ContainerExtensionStore } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tFluidObject,\n\tIEvent,\n\tIEventProvider,\n\tIFluidHandle,\n\tIFluidLoadable,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport type {\n\tContainerAttachProps,\n\tContainerSchema,\n\tIRootDataObject,\n\tIStaticEntryPoint,\n} from \"./types.js\";\n\n/**\n * Extract the type of 'initialObjects' from the given {@link ContainerSchema} type.\n * @public\n */\nexport type InitialObjects<T extends ContainerSchema> = {\n\t// Construct a LoadableObjectRecord type by enumerating the keys of\n\t// 'ContainerSchema.initialObjects' and inferring the value type of each key.\n\t//\n\t// The '? TChannel : never' is required because infer can only be used in\n\t// a conditional 'extends' expression.\n\t[K in keyof T[\"initialObjects\"]]: T[\"initialObjects\"][K] extends SharedObjectKind<\n\t\tinfer TChannel\n\t>\n\t\t? TChannel\n\t\t: never;\n};\n\n/**\n * Events emitted from {@link IFluidContainer}.\n *\n * @remarks Note: external implementations of this interface are not supported.\n * @sealed\n * @public\n */\nexport interface IFluidContainerEvents extends IEvent {\n\t/**\n\t * Emitted when the {@link IFluidContainer} completes connecting to the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.connect}\n\t */\n\t(event: \"connected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} becomes disconnected from the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.disconnect}\n\t */\n\t(event: \"disconnected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when all local changes/edits have been acknowledged by the service.\n\t *\n\t * @remarks \"dirty\" event will be emitted when the next local change has been made.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"saved\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the first local change has been made, following a \"saved\" event.\n\t *\n\t * @remarks \"saved\" event will be emitted once all local changes have been acknowledged by the service.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"dirty\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} is closed, which permanently disables it.\n\t *\n\t * @remarks Listener parameters:\n\t *\n\t * - `error`: If the container was closed due to error (as opposed to an explicit call to\n\t * {@link IFluidContainer.dispose}), this will contain details about the error that caused it.\n\t */\n\t(event: \"disposed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Provides an entrypoint into the client side of collaborative Fluid data.\n * Provides access to the data as well as status on the collaboration session.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n *\n * @remarks Note: external implementations of this interface are not supported.\n *\n * @sealed\n * @public\n */\nexport interface IFluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends IEventProvider<IFluidContainerEvents> {\n\t/**\n\t * Provides the current connected state of the container\n\t */\n\treadonly connectionState: ConnectionState;\n\n\t/**\n\t * A container is considered **dirty** if it has local changes that have not yet been acknowledged by the service.\n\t *\n\t * @remarks\n\t *\n\t * You should always check the `isDirty` flag before closing the container or navigating away from the page.\n\t * Closing the container while `isDirty === true` may result in the loss of operations that have not yet been\n\t * acknowledged by the service.\n\t *\n\t * A container is considered dirty in the following cases:\n\t *\n\t * 1. The container has been created in the detached state, and either it has not been attached yet or it is\n\t * in the process of being attached (container is in `attaching` state). If container is closed prior to being\n\t * attached, host may never know if the file was created or not.\n\t *\n\t * 2. The container was attached, but it has local changes that have not yet been saved to service endpoint.\n\t * This occurs as part of normal op flow where pending operation (changes) are awaiting acknowledgement from the\n\t * service. In some cases this can be due to lack of network connection. If the network connection is down,\n\t * it needs to be restored for the pending changes to be acknowledged.\n\t */\n\treadonly isDirty: boolean;\n\n\t/**\n\t * Whether or not the container is disposed, which permanently disables it.\n\t */\n\treadonly disposed: boolean;\n\n\t/**\n\t * The collection of data objects and Distributed Data Stores (DDSes) that were specified by the schema.\n\t *\n\t * @remarks These data objects and DDSes exist for the lifetime of the container.\n\t */\n\treadonly initialObjects: InitialObjects<TContainerSchema>;\n\n\t/**\n\t * The current attachment state of the container.\n\t *\n\t * @remarks\n\t *\n\t * Once a container has been attached, it remains attached.\n\t * When loading an existing container, it will already be attached.\n\t */\n\treadonly attachState: AttachState;\n\n\t/**\n\t * A newly created container starts detached from the collaborative service.\n\t * Calling `attach()` uploads the new container to the service and connects to the collaborative service.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#AttachState.Detached} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.attachState}.\n\t *\n\t * @returns A promise which resolves when the attach is complete, with the string identifier of the container.\n\t */\n\tattach(props?: ContainerAttachProps): Promise<string>;\n\n\t/**\n\t * Attempts to connect the container to the delta stream and process operations.\n\t *\n\t * @throws Will throw an error if connection is unsuccessful.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Disconnected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tconnect(): void;\n\n\t/**\n\t * Disconnects the container from the delta stream and stops processing operations.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Connected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tdisconnect(): void;\n\n\t/**\n\t * Create a new data object or Distributed Data Store (DDS) of the specified type.\n\t *\n\t * @param objectClass - The class of the `DataObject` or `SharedObject` to create.\n\t *\n\t * @typeParam T - The class of the `DataObject` or `SharedObject`.\n\t *\n\t * @remarks\n\t *\n\t * In order to share the data object or DDS with other collaborators and retrieve it later,\n\t * store its handle in a collection like a SharedDirectory from your initialObjects.\n\t * It's typically a good idea to set any initial state on the object before doing so,\n\t * as it is both more efficient and helpful to maintain domain model invariants\n\t * (e.g. this approach easily allows state to only be set once).\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const existingDirectory = container.initialObjects.myDirectory;\n\t * const map = await container.create(SharedMap);\n\t * map.set(\"initialState\", \"someValue\");\n\t * existingDirectory.set(\"myMap\", map.handle);\n\t * ```\n\t */\n\tcreate<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T>;\n\n\t/**\n\t * Dispose of the container instance, permanently disabling it.\n\t */\n\tdispose(): void;\n}\n\n/**\n * Internal interface for {@link IFluidContainer}.\n *\n * @internal\n */\nexport interface IFluidContainerInternal extends ContainerExtensionStore {\n\t/**\n\t * The underlying {@link @fluidframework/container-definitions#IContainer}.\n\t *\n\t * @remarks Used to power debug tooling and experimental features.\n\t */\n\treadonly container: IContainer;\n\n\t/**\n\t * Upload a blob of data.\n\t * Although it is marked as internal, there is external usage of this function for experimental purposes.\n\t * Please contact yunho-microsoft or vladsud if you need to change it.\n\t * @param blob - blob to be uploaded.\n\t *\n\t * @remarks This method is used to expose uploadBlob to the IFluidContainer level. UploadBlob will upload data to server side (as of now, ODSP only). There is no downloadBlob provided as it is not needed(blob lifetime managed by server).\n\t */\n\tuploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>;\n}\n\n/**\n * Creates an {@link IFluidContainer} from the provided `container` and `rootDataObject`.\n *\n * @internal\n */\nexport async function createFluidContainer<\n\tTContainerSchema extends ContainerSchema = ContainerSchema,\n>(props: {\n\tcontainer: IContainer;\n}): Promise<IFluidContainer<TContainerSchema>> {\n\tconst entryPoint: FluidObject<IStaticEntryPoint> = await props.container.getEntryPoint();\n\tassert(\n\t\tentryPoint.IStaticEntryPoint !== undefined,\n\t\t0xb9e /* entryPoint must be of type IStaticEntryPoint */,\n\t);\n\treturn new FluidContainer<TContainerSchema>(\n\t\tprops.container,\n\t\tentryPoint.IStaticEntryPoint.rootDataObject,\n\t\tentryPoint.IStaticEntryPoint.extensionStore,\n\t);\n}\n\n/**\n * Check that the provided `container` is an internal {@link IFluidContainerInternal}.\n *\n * @internal\n */\nexport function isInternalFluidContainer<TContainerSchema extends ContainerSchema>(\n\tcontainer: IFluidContainer<TContainerSchema> | IFluidContainerInternal,\n): container is IFluidContainerInternal {\n\t// IFluidContainer is sealed; so we never expect an `IFluidContainer` not to be\n\t// `IFluidContainerInternal` implemented by `FluidContainer`. To be caution,\n\t// we use `instanceof` to confirm.\n\treturn container instanceof FluidContainer;\n}\n\n/**\n * {@link IFluidContainer} implementation.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n * @remarks\n *\n * Note: this implementation is not complete. Consumers who rely on {@link IFluidContainer.attach}\n * will need to utilize or provide a service-specific implementation of this type that implements that method.\n */\nclass FluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends TypedEventEmitter<IFluidContainerEvents>\n\timplements IFluidContainer<TContainerSchema>, IFluidContainerInternal\n{\n\tprivate readonly connectedHandler = (): boolean => this.emit(\"connected\");\n\tprivate readonly disconnectedHandler = (): boolean => this.emit(\"disconnected\");\n\tprivate readonly disposedHandler = (error?: ICriticalContainerError): boolean =>\n\t\tthis.emit(\"disposed\", error);\n\tprivate readonly savedHandler = (): boolean => this.emit(\"saved\");\n\tprivate readonly dirtyHandler = (): boolean => this.emit(\"dirty\");\n\tpublic readonly acquireExtension: ContainerExtensionStore[\"acquireExtension\"];\n\n\tpublic constructor(\n\t\tpublic readonly container: IContainer,\n\t\tprivate readonly rootDataObject: IRootDataObject,\n\t\textensionStore: ContainerExtensionStore,\n\t) {\n\t\tsuper();\n\t\tthis.acquireExtension = extensionStore.acquireExtension.bind(extensionStore);\n\t\tcontainer.on(\"connected\", this.connectedHandler);\n\t\tcontainer.on(\"closed\", this.disposedHandler);\n\t\tcontainer.on(\"disconnected\", this.disconnectedHandler);\n\t\tcontainer.on(\"saved\", this.savedHandler);\n\t\tcontainer.on(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic get isDirty(): boolean {\n\t\treturn this.container.isDirty;\n\t}\n\n\tpublic get attachState(): AttachState {\n\t\treturn this.container.attachState;\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this.container.closed;\n\t}\n\n\tpublic get connectionState(): ConnectionState {\n\t\treturn this.container.connectionState;\n\t}\n\n\tpublic get initialObjects(): InitialObjects<TContainerSchema> {\n\t\treturn this.rootDataObject.initialObjects as InitialObjects<TContainerSchema>;\n\t}\n\n\t/**\n\t * Incomplete base implementation of {@link IFluidContainer.attach}.\n\t *\n\t * @remarks\n\t *\n\t * Note: this implementation will unconditionally throw.\n\t * Consumers who rely on this will need to utilize or provide a service specific implementation of this base type\n\t * that provides an implementation of this method.\n\t *\n\t * The reason is because externally we are presenting a separation between the service and the `FluidContainer`,\n\t * but internally this separation is not there.\n\t */\n\tpublic async attach(props?: ContainerAttachProps): Promise<string> {\n\t\tif (this.container.attachState !== AttachState.Detached) {\n\t\t\tthrow new Error(\"Cannot attach container. Container is not in detached state.\");\n\t\t}\n\t\tthrow new Error(\"Cannot attach container. Attach method not provided.\");\n\t}\n\n\tpublic async connect(): Promise<void> {\n\t\tthis.container.connect?.();\n\t}\n\n\tpublic async disconnect(): Promise<void> {\n\t\tthis.container.disconnect?.();\n\t}\n\n\tpublic async create<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T> {\n\t\treturn this.rootDataObject.create(objectClass);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.container.close();\n\t\tthis.container.off(\"connected\", this.connectedHandler);\n\t\tthis.container.off(\"closed\", this.disposedHandler);\n\t\tthis.container.off(\"disconnected\", this.disconnectedHandler);\n\t\tthis.container.off(\"saved\", this.savedHandler);\n\t\tthis.container.off(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\treturn this.rootDataObject.uploadBlob(blob);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"fluidContainer.js","sourceRoot":"","sources":["../src/fluidContainer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACN,WAAW,GAGX,MAAM,uCAAuC,CAAC;AAU/C,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAyP7D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAExC,KAED;IACA,MAAM,UAAU,GAAmC,MAA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CAAC,WAAW,CAAC,CAAC;IAChD,CAAC;IAEM,OAAO;QACb,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,IAAI,CAAC,gBAAgB,CAAC,CAAC;QACvD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,eAAe,CAAC,CAAC;QACnD,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC7D,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAChD,CAAC;IAEM,KAAK,CAAC,UAAU,CAAC,IAAqB;QAC5C,OAAO,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;IAC7C,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport {\n\tAttachState,\n\ttype ConnectionState,\n\ttype ICriticalContainerError,\n} from \"@fluidframework/container-definitions\";\nimport type { IContainer } from \"@fluidframework/container-definitions/internal\";\nimport type { ContainerExtensionStore } from \"@fluidframework/container-runtime-definitions/internal\";\nimport type {\n\tFluidObject,\n\tIEvent,\n\tIEventProvider,\n\tIFluidHandle,\n\tIFluidLoadable,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base/internal\";\n\nimport type {\n\tContainerAttachProps,\n\tContainerSchema,\n\tIRootDataObject,\n\tIStaticEntryPoint,\n} from \"./types.js\";\n\n/**\n * Extract the type of 'initialObjects' from the given {@link ContainerSchema} type.\n * @public\n */\nexport type InitialObjects<T extends ContainerSchema> = {\n\t// Construct a LoadableObjectRecord type by enumerating the keys of\n\t// 'ContainerSchema.initialObjects' and inferring the value type of each key.\n\t//\n\t// The '? TChannel : never' is required because infer can only be used in\n\t// a conditional 'extends' expression.\n\t[K in keyof T[\"initialObjects\"]]: T[\"initialObjects\"][K] extends SharedObjectKind<\n\t\tinfer TChannel\n\t>\n\t\t? TChannel\n\t\t: never;\n};\n\n/**\n * Events emitted from {@link IFluidContainer}.\n *\n * @remarks Note: external implementations of this interface are not supported.\n * @sealed\n * @public\n */\nexport interface IFluidContainerEvents extends IEvent {\n\t/**\n\t * Emitted when the {@link IFluidContainer} completes connecting to the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.connect}\n\t */\n\t(event: \"connected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} becomes disconnected from the Fluid service.\n\t *\n\t * @remarks Reflects connection state changes against the (delta) service acknowledging ops/edits.\n\t *\n\t * @see\n\t *\n\t * - {@link IFluidContainer.connectionState}\n\t *\n\t * - {@link IFluidContainer.disconnect}\n\t */\n\t(event: \"disconnected\", listener: () => void): void;\n\n\t/**\n\t * Emitted when all local changes/edits have been acknowledged by the service.\n\t *\n\t * @remarks \"dirty\" event will be emitted when the next local change has been made.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"saved\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the first local change has been made, following a \"saved\" event.\n\t *\n\t * @remarks \"saved\" event will be emitted once all local changes have been acknowledged by the service.\n\t *\n\t * @see {@link IFluidContainer.isDirty}\n\t */\n\t(event: \"dirty\", listener: () => void): void;\n\n\t/**\n\t * Emitted when the {@link IFluidContainer} is closed, which permanently disables it.\n\t *\n\t * @remarks Listener parameters:\n\t *\n\t * - `error`: If the container was closed due to error (as opposed to an explicit call to\n\t * {@link IFluidContainer.dispose}), this will contain details about the error that caused it.\n\t */\n\t(event: \"disposed\", listener: (error?: ICriticalContainerError) => void);\n}\n\n/**\n * Provides an entrypoint into the client side of collaborative Fluid data.\n * Provides access to the data as well as status on the collaboration session.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n *\n * @remarks Note: external implementations of this interface are not supported.\n *\n * @sealed\n * @public\n */\nexport interface IFluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends IEventProvider<IFluidContainerEvents> {\n\t/**\n\t * Provides the current connected state of the container\n\t */\n\treadonly connectionState: ConnectionState;\n\n\t/**\n\t * A container is considered **dirty** if it has local changes that have not yet been acknowledged by the service.\n\t *\n\t * @remarks\n\t *\n\t * You should always check the `isDirty` flag before closing the container or navigating away from the page.\n\t * Closing the container while `isDirty === true` may result in the loss of operations that have not yet been\n\t * acknowledged by the service.\n\t *\n\t * A container is considered dirty in the following cases:\n\t *\n\t * 1. The container has been created in the detached state, and either it has not been attached yet or it is\n\t * in the process of being attached (container is in `attaching` state). If container is closed prior to being\n\t * attached, host may never know if the file was created or not.\n\t *\n\t * 2. The container was attached, but it has local changes that have not yet been saved to service endpoint.\n\t * This occurs as part of normal op flow where pending operation (changes) are awaiting acknowledgement from the\n\t * service. In some cases this can be due to lack of network connection. If the network connection is down,\n\t * it needs to be restored for the pending changes to be acknowledged.\n\t */\n\treadonly isDirty: boolean;\n\n\t/**\n\t * Whether or not the container is disposed, which permanently disables it.\n\t */\n\treadonly disposed: boolean;\n\n\t/**\n\t * The collection of data objects and Distributed Data Stores (DDSes) that were specified by the schema.\n\t *\n\t * @remarks These data objects and DDSes exist for the lifetime of the container.\n\t */\n\treadonly initialObjects: InitialObjects<TContainerSchema>;\n\n\t/**\n\t * The current attachment state of the container.\n\t *\n\t * @remarks\n\t *\n\t * Once a container has been attached, it remains attached.\n\t * When loading an existing container, it will already be attached.\n\t */\n\treadonly attachState: AttachState;\n\n\t/**\n\t * A newly created container starts detached from the collaborative service.\n\t * Calling `attach()` uploads the new container to the service and connects to the collaborative service.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#AttachState.Detached} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.attachState}.\n\t *\n\t * @returns A promise which resolves when the attach is complete, with the string identifier of the container.\n\t */\n\tattach(props?: ContainerAttachProps): Promise<string>;\n\n\t/**\n\t * Attempts to connect the container to the delta stream and process operations.\n\t *\n\t * @throws Will throw an error if connection is unsuccessful.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Disconnected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tconnect(): void;\n\n\t/**\n\t * Disconnects the container from the delta stream and stops processing operations.\n\t *\n\t * @remarks\n\t *\n\t * This should only be called when the container is in the\n\t * {@link @fluidframework/container-definitions#(ConnectionState:namespace).Connected} state.\n\t *\n\t * This can be determined by observing {@link IFluidContainer.connectionState}.\n\t */\n\tdisconnect(): void;\n\n\t/**\n\t * Create a new data object or Distributed Data Store (DDS) of the specified type.\n\t *\n\t * @param objectClass - The class of the `DataObject` or `SharedObject` to create.\n\t *\n\t * @typeParam T - The class of the `DataObject` or `SharedObject`.\n\t *\n\t * @remarks\n\t *\n\t * In order to share the data object or DDS with other collaborators and retrieve it later,\n\t * store its handle in a collection like a SharedDirectory from your initialObjects.\n\t * It's typically a good idea to set any initial state on the object before doing so,\n\t * as it is both more efficient and helpful to maintain domain model invariants\n\t * (e.g. this approach easily allows state to only be set once).\n\t *\n\t * @example\n\t *\n\t * ```typescript\n\t * const existingDirectory = container.initialObjects.myDirectory;\n\t * const map = await container.create(SharedMap);\n\t * map.set(\"initialState\", \"someValue\");\n\t * existingDirectory.set(\"myMap\", map.handle);\n\t * ```\n\t */\n\tcreate<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T>;\n\n\t/**\n\t * Dispose of the container instance, permanently disabling it.\n\t */\n\tdispose(): void;\n}\n\n/**\n * Internal interface for {@link IFluidContainer}.\n *\n * @internal\n */\nexport interface IFluidContainerInternal extends ContainerExtensionStore {\n\t/**\n\t * The underlying {@link @fluidframework/container-definitions#IContainer}.\n\t *\n\t * @remarks Used to power debug tooling and experimental features.\n\t */\n\treadonly container: IContainer;\n\n\t/**\n\t * Upload a blob of data.\n\t * Although it is marked as internal, there is external usage of this function for experimental purposes.\n\t * Please contact yunho-microsoft or vladsud if you need to change it.\n\t * @param blob - blob to be uploaded.\n\t *\n\t * @remarks This method is used to expose uploadBlob to the IFluidContainer level. UploadBlob will upload data to server side (as of now, ODSP only). There is no downloadBlob provided as it is not needed(blob lifetime managed by server).\n\t */\n\tuploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>>;\n}\n\n/**\n * Creates an {@link IFluidContainer} from the provided `container` and `rootDataObject`.\n *\n * @internal\n */\nexport async function createFluidContainer<\n\tTContainerSchema extends ContainerSchema = ContainerSchema,\n>(props: {\n\tcontainer: IContainer;\n}): Promise<IFluidContainer<TContainerSchema>> {\n\tconst entryPoint: FluidObject<IStaticEntryPoint> = await props.container.getEntryPoint();\n\tassert(\n\t\tentryPoint.IStaticEntryPoint !== undefined,\n\t\t0xb9e /* entryPoint must be of type IStaticEntryPoint */,\n\t);\n\treturn new FluidContainer<TContainerSchema>(\n\t\tprops.container,\n\t\tentryPoint.IStaticEntryPoint.rootDataObject,\n\t\tentryPoint.IStaticEntryPoint.extensionStore,\n\t);\n}\n\n/**\n * Check that the provided `container` is an internal {@link IFluidContainerInternal}.\n *\n * @internal\n */\nexport function isInternalFluidContainer<TContainerSchema extends ContainerSchema>(\n\tcontainer: IFluidContainer<TContainerSchema> | IFluidContainerInternal,\n): container is IFluidContainerInternal {\n\t// IFluidContainer is sealed; so we never expect an `IFluidContainer` not to be\n\t// `IFluidContainerInternal` implemented by `FluidContainer`. To be caution,\n\t// we use `instanceof` to confirm.\n\treturn container instanceof FluidContainer;\n}\n\n/**\n * {@link IFluidContainer} implementation.\n *\n * @typeparam TContainerSchema - Used to determine the type of 'initialObjects'.\n * @remarks\n *\n * Note: this implementation is not complete. Consumers who rely on {@link IFluidContainer.attach}\n * will need to utilize or provide a service-specific implementation of this type that implements that method.\n */\nclass FluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>\n\textends TypedEventEmitter<IFluidContainerEvents>\n\timplements IFluidContainer<TContainerSchema>, IFluidContainerInternal\n{\n\tprivate readonly connectedHandler = (): boolean => this.emit(\"connected\");\n\tprivate readonly disconnectedHandler = (): boolean => this.emit(\"disconnected\");\n\tprivate readonly disposedHandler = (error?: ICriticalContainerError): boolean =>\n\t\tthis.emit(\"disposed\", error);\n\tprivate readonly savedHandler = (): boolean => this.emit(\"saved\");\n\tprivate readonly dirtyHandler = (): boolean => this.emit(\"dirty\");\n\tpublic readonly acquireExtension: ContainerExtensionStore[\"acquireExtension\"];\n\n\tpublic constructor(\n\t\tpublic readonly container: IContainer,\n\t\tprivate readonly rootDataObject: IRootDataObject,\n\t\textensionStore: ContainerExtensionStore,\n\t) {\n\t\tsuper();\n\t\tthis.acquireExtension = extensionStore.acquireExtension.bind(extensionStore);\n\t\tcontainer.on(\"connected\", this.connectedHandler);\n\t\tcontainer.on(\"closed\", this.disposedHandler);\n\t\tcontainer.on(\"disconnected\", this.disconnectedHandler);\n\t\tcontainer.on(\"saved\", this.savedHandler);\n\t\tcontainer.on(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic get isDirty(): boolean {\n\t\treturn this.container.isDirty;\n\t}\n\n\tpublic get attachState(): AttachState {\n\t\treturn this.container.attachState;\n\t}\n\n\tpublic get disposed(): boolean {\n\t\treturn this.container.closed;\n\t}\n\n\tpublic get connectionState(): ConnectionState {\n\t\treturn this.container.connectionState;\n\t}\n\n\tpublic get initialObjects(): InitialObjects<TContainerSchema> {\n\t\treturn this.rootDataObject.initialObjects as InitialObjects<TContainerSchema>;\n\t}\n\n\t/**\n\t * Incomplete base implementation of {@link IFluidContainer.attach}.\n\t *\n\t * @remarks\n\t *\n\t * Note: this implementation will unconditionally throw.\n\t * Consumers who rely on this will need to utilize or provide a service specific implementation of this base type\n\t * that provides an implementation of this method.\n\t *\n\t * The reason is because externally we are presenting a separation between the service and the `FluidContainer`,\n\t * but internally this separation is not there.\n\t */\n\tpublic async attach(props?: ContainerAttachProps): Promise<string> {\n\t\tif (this.container.attachState !== AttachState.Detached) {\n\t\t\tthrow new Error(\"Cannot attach container. Container is not in detached state.\");\n\t\t}\n\t\tthrow new Error(\"Cannot attach container. Attach method not provided.\");\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\tpublic async connect(): Promise<void> {\n\t\tthis.container.connect?.();\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-misused-promises\n\tpublic async disconnect(): Promise<void> {\n\t\tthis.container.disconnect?.();\n\t}\n\n\tpublic async create<T extends IFluidLoadable>(objectClass: SharedObjectKind<T>): Promise<T> {\n\t\treturn this.rootDataObject.create(objectClass);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.container.close();\n\t\tthis.container.off(\"connected\", this.connectedHandler);\n\t\tthis.container.off(\"closed\", this.disposedHandler);\n\t\tthis.container.off(\"disconnected\", this.disconnectedHandler);\n\t\tthis.container.off(\"saved\", this.savedHandler);\n\t\tthis.container.off(\"dirty\", this.dirtyHandler);\n\t}\n\n\tpublic async uploadBlob(blob: ArrayBufferLike): Promise<IFluidHandle<ArrayBufferLike>> {\n\t\treturn this.rootDataObject.uploadBlob(blob);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/fluid-static",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.74.0-365691",
|
|
4
4
|
"description": "A tool to enable consumption of Fluid Data Objects without requiring custom container code.",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -69,34 +69,34 @@
|
|
|
69
69
|
"temp-directory": "nyc/.nyc_output"
|
|
70
70
|
},
|
|
71
71
|
"dependencies": {
|
|
72
|
-
"@fluid-internal/client-utils": "
|
|
73
|
-
"@fluidframework/aqueduct": "
|
|
74
|
-
"@fluidframework/container-definitions": "
|
|
75
|
-
"@fluidframework/container-loader": "
|
|
76
|
-
"@fluidframework/container-runtime": "
|
|
77
|
-
"@fluidframework/container-runtime-definitions": "
|
|
78
|
-
"@fluidframework/core-interfaces": "
|
|
79
|
-
"@fluidframework/core-utils": "
|
|
80
|
-
"@fluidframework/datastore-definitions": "
|
|
81
|
-
"@fluidframework/driver-definitions": "
|
|
82
|
-
"@fluidframework/request-handler": "
|
|
83
|
-
"@fluidframework/runtime-definitions": "
|
|
84
|
-
"@fluidframework/runtime-utils": "
|
|
85
|
-
"@fluidframework/shared-object-base": "
|
|
86
|
-
"@fluidframework/telemetry-utils": "
|
|
87
|
-
"@fluidframework/tree": "
|
|
72
|
+
"@fluid-internal/client-utils": "2.74.0-365691",
|
|
73
|
+
"@fluidframework/aqueduct": "2.74.0-365691",
|
|
74
|
+
"@fluidframework/container-definitions": "2.74.0-365691",
|
|
75
|
+
"@fluidframework/container-loader": "2.74.0-365691",
|
|
76
|
+
"@fluidframework/container-runtime": "2.74.0-365691",
|
|
77
|
+
"@fluidframework/container-runtime-definitions": "2.74.0-365691",
|
|
78
|
+
"@fluidframework/core-interfaces": "2.74.0-365691",
|
|
79
|
+
"@fluidframework/core-utils": "2.74.0-365691",
|
|
80
|
+
"@fluidframework/datastore-definitions": "2.74.0-365691",
|
|
81
|
+
"@fluidframework/driver-definitions": "2.74.0-365691",
|
|
82
|
+
"@fluidframework/request-handler": "2.74.0-365691",
|
|
83
|
+
"@fluidframework/runtime-definitions": "2.74.0-365691",
|
|
84
|
+
"@fluidframework/runtime-utils": "2.74.0-365691",
|
|
85
|
+
"@fluidframework/shared-object-base": "2.74.0-365691",
|
|
86
|
+
"@fluidframework/telemetry-utils": "2.74.0-365691",
|
|
87
|
+
"@fluidframework/tree": "2.74.0-365691"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@arethetypeswrong/cli": "^0.17.1",
|
|
91
91
|
"@biomejs/biome": "~1.9.3",
|
|
92
|
-
"@fluid-internal/mocha-test-setup": "
|
|
92
|
+
"@fluid-internal/mocha-test-setup": "2.74.0-365691",
|
|
93
93
|
"@fluid-tools/build-cli": "^0.60.0",
|
|
94
94
|
"@fluidframework/build-common": "^2.0.3",
|
|
95
95
|
"@fluidframework/build-tools": "^0.60.0",
|
|
96
|
-
"@fluidframework/eslint-config-fluid": "
|
|
97
|
-
"@fluidframework/fluid-static-previous": "npm:@fluidframework/fluid-static@2.
|
|
98
|
-
"@fluidframework/map": "
|
|
99
|
-
"@fluidframework/sequence": "
|
|
96
|
+
"@fluidframework/eslint-config-fluid": "2.74.0-365691",
|
|
97
|
+
"@fluidframework/fluid-static-previous": "npm:@fluidframework/fluid-static@2.73.0",
|
|
98
|
+
"@fluidframework/map": "2.74.0-365691",
|
|
99
|
+
"@fluidframework/sequence": "2.74.0-365691",
|
|
100
100
|
"@microsoft/api-extractor": "7.52.11",
|
|
101
101
|
"@types/mocha": "^10.0.10",
|
|
102
102
|
"@types/node": "^18.19.0",
|
package/src/fluidContainer.ts
CHANGED
|
@@ -377,10 +377,12 @@ class FluidContainer<TContainerSchema extends ContainerSchema = ContainerSchema>
|
|
|
377
377
|
throw new Error("Cannot attach container. Attach method not provided.");
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
380
381
|
public async connect(): Promise<void> {
|
|
381
382
|
this.container.connect?.();
|
|
382
383
|
}
|
|
383
384
|
|
|
385
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
384
386
|
public async disconnect(): Promise<void> {
|
|
385
387
|
this.container.disconnect?.();
|
|
386
388
|
}
|