@fluidframework/shared-object-base 2.0.0-internal.2.4.0 → 2.0.0-internal.3.0.1

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.
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/shared-object-base";
8
- export declare const pkgVersion = "2.0.0-internal.2.4.0";
8
+ export declare const pkgVersion = "2.0.0-internal.3.0.1";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/shared-object-base";
11
- exports.pkgVersion = "2.0.0-internal.2.4.0";
11
+ exports.pkgVersion = "2.0.0-internal.3.0.1";
12
12
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.2.4.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.3.0.1\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAwB,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EAAU,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAGpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEH,6BAA6B,EAKhC,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAmB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE7D;;GAEG;AACH,8BAAsB,gBAAgB,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CAC3F,SAAQ,6BAA6B,CAAC,MAAM,CAAE,YAAW,aAAa,CAAC,MAAM,CAAC;IAmDnE,EAAE,EAAE,MAAM;IACjB,SAAS,CAAC,OAAO,EAAE,sBAAsB;aACzB,UAAU,EAAE,kBAAkB;IApDlD,IAAW,cAAc,SAAmB;IAE5C,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAAyB;IAC5D,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAyB;IAEzD;;OAEG;IACH,SA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356
  * @returns `true` if the event had listeners, `false` otherwise.
357
357
  */
358
358
  emit(event, ...args) {
359
- return this.callbacksHelper.measure(() => super.emit(event, ...args));
359
+ return this.callbacksHelper.measure(() => {
360
+ // Creating ops while handling a DDS event can lead
361
+ // to undefined behavior and events observed in the wrong order.
362
+ // For example, we have two callbacks registered for a DDS, A and B.
363
+ // Then if on change #1 callback A creates change #2, the invocation flow will be:
364
+ //
365
+ // A because of #1
366
+ // A because of #2
367
+ // B because of #2
368
+ // B because of #1
369
+ //
370
+ // The runtime must enforce op coherence by not allowing any ops to be created during
371
+ // the event handler
372
+ return this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));
373
+ });
360
374
  }
361
375
  /**
362
376
  * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,+DAA6E;AAC7E,iFAAoE;AASpE,6EAM6C;AAC7C,qEAOyC;AACzC,qEAAsE;AACtE,6CAAiE;AACjE,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,gBAClB,SAAQ,+CAAqC;IA6C7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAC9C,KAAK,CAAC,CAAC,KAA4B,EAAE,CAAM,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAHnF,OAAE,GAAF,EAAE,CAAQ;QACP,YAAO,GAAP,OAAO,CAAwB;QACzB,eAAU,GAAV,UAAU,CAAoB;QApClD;;WAEG;QACK,eAAU,GAAG,KAAK,CAAC;QAO3B;;WAEG;QACK,sBAAiB,GAAY,KAAK,CAAC;QA0BvC,IAAA,qBAAM,EAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,+BAA+B,CA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CAAC,QAAQ,EAAE,KAAK,CAAC,mEAAmE,CAAC,CAAC;SACpG;gBAAS;YACN,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACzB;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,UAA6B;QACrD,wGAAwG;QACxG,2GAA2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAWO,wBAAwB,CAAC,YAAoB,EAAE,WAAmB,EAAE,gBAAoC;;QAC5G,MAAM,SAAS,GAAG,CAAC,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC,mCAAI,CAAC,CAAW,CAAC;QACpG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC9F,CAAC;CACJ;AA3HD,oCA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n blobCountPropertyName,\n totalBlobSizePropertyName,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n ChildLogger,\n EventEmitterWithErrorHandling,\n loggerToMonitoringContext,\n MonitoringContext,\n SampledTelemetryHelper,\n TelemetryDataTag,\n} from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n private readonly opProcessingHelper: SampledTelemetryHelper;\n private readonly callbacksHelper: SampledTelemetryHelper;\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n private readonly mc: MonitoringContext;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n assert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n {\n all: {\n sharedObjectId: uuid(),\n ddsType: {\n value: this.attributes.type,\n tag: TelemetryDataTag.CodeArtifact,\n },\n },\n },\n );\n this.mc = loggerToMonitoringContext(this.logger);\n\n [this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n this.attachListeners();\n }\n\n /**\n * This function is only supposed to be called from SharedObjectCore's constructor and\n * depends on a few things being set already. assert() calls make sure of it.\n * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n * to variables to avoid complaints from TypeScript.\n */\n private setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n assert(this.mc !== undefined && this.logger !== undefined,\n 0x349 /* this.mc and/or this.logger has not been set */);\n const opProcessingHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsOpProcessing\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 100,\n true,\n new Map<string, ITelemetryProperties>([\n [\"local\", { localOp: true }],\n [\"remote\", { localOp: false }],\n ]));\n const callbacksHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsEventCallbacks\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 100,\n true);\n\n this.runtime.once(\"dispose\", () => {\n this.callbacksHelper.dispose();\n this.opProcessingHelper.dispose();\n });\n\n return [opProcessingHelper, callbacksHelper];\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n rollback: (content: any, localOpMetadata: unknown) => {\n this.rollback(content, localOpMetadata);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emitInternal(\"pre-op\", message, local, this);\n\n this.opProcessingHelper.measure(\n () => { this.processCore(message, local, localOpMetadata); },\n local ? \"local\" : \"remote\");\n\n this.emitInternal(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Revert an op\n */\n protected rollback(content: any, localOpMetadata: unknown) {\n throw new Error(\"rollback not supported\");\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n\n /**\n * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n * future.\n *\n * @internal\n *\n * @param event - The event to emit.\n * @param args - Arguments to pass to the event listeners.\n * @returns `true` if the event had listeners, `false` otherwise.\n */\n public emit(event: EventEmitterEventType, ...args: any[]): boolean {\n return this.callbacksHelper.measure(() => super.emit(event, ...args));\n }\n\n /**\n * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n * done on the duration of the callbacks. Simply calls `super.emit()`.\n * @param event - Event to emit\n * @param args - Arguments for the event\n * @returns Whatever `super.emit()` returns.\n */\n private emitInternal(\n event: EventEmitterEventType,\n ...args: any[]): boolean {\n return super.emit(event, ...args);\n }\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly telemetryContextPrefix: string,\n ) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats> {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(\n serializer: IFluidSerializer,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {\n const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;\n telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n }\n}\n"]}
1
+ {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,+DAA6E;AAC7E,iFAAoE;AASpE,6EAM6C;AAC7C,qEAOyC;AACzC,qEAAsE;AACtE,6CAAiE;AACjE,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,gBAClB,SAAQ,+CAAqC;IA6C7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;Q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IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC9F,CAAC;CACJ;AA3HD,oCA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n blobCountPropertyName,\n totalBlobSizePropertyName,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n ChildLogger,\n EventEmitterWithErrorHandling,\n loggerToMonitoringContext,\n MonitoringContext,\n SampledTelemetryHelper,\n TelemetryDataTag,\n} from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n private readonly opProcessingHelper: SampledTelemetryHelper;\n private readonly callbacksHelper: SampledTelemetryHelper;\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n private readonly mc: MonitoringContext;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n assert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n {\n all: {\n sharedObjectId: uuid(),\n ddsType: {\n value: this.attributes.type,\n tag: TelemetryDataTag.CodeArtifact,\n },\n },\n },\n );\n this.mc = loggerToMonitoringContext(this.logger);\n\n [this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n this.attachListeners();\n }\n\n /**\n * This function is only supposed to be called from SharedObjectCore's constructor and\n * depends on a few things being set already. assert() calls make sure of it.\n * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n * to variables to avoid complaints from TypeScript.\n */\n private setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n assert(this.mc !== undefined && this.logger !== undefined,\n 0x349 /* this.mc and/or this.logger has not been set */);\n const opProcessingHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsOpProcessing\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 100,\n true,\n new Map<string, ITelemetryProperties>([\n [\"local\", { localOp: true }],\n [\"remote\", { localOp: false }],\n ]));\n const callbacksHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsEventCallbacks\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 100,\n true);\n\n this.runtime.once(\"dispose\", () => {\n this.callbacksHelper.dispose();\n this.opProcessingHelper.dispose();\n });\n\n return [opProcessingHelper, callbacksHelper];\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n rollback: (content: any, localOpMetadata: unknown) => {\n this.rollback(content, localOpMetadata);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emitInternal(\"pre-op\", message, local, this);\n\n this.opProcessingHelper.measure(\n () => { this.processCore(message, local, localOpMetadata); },\n local ? \"local\" : \"remote\");\n\n this.emitInternal(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Revert an op\n */\n protected rollback(content: any, localOpMetadata: unknown) {\n throw new Error(\"rollback not supported\");\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n\n /**\n * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n * future.\n *\n * @internal\n *\n * @param event - The event to emit.\n * @param args - Arguments to pass to the event listeners.\n * @returns `true` if the event had listeners, `false` otherwise.\n */\n public emit(event: EventEmitterEventType, ...args: any[]): boolean {\n return this.callbacksHelper.measure(() => {\n // Creating ops while handling a DDS event can lead\n // to undefined behavior and events observed in the wrong order.\n // For example, we have two callbacks registered for a DDS, A and B.\n // Then if on change #1 callback A creates change #2, the invocation flow will be:\n //\n // A because of #1\n // A because of #2\n // B because of #2\n // B because of #1\n //\n // The runtime must enforce op coherence by not allowing any ops to be created during\n // the event handler\n return this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));\n });\n }\n\n /**\n * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n * done on the duration of the callbacks. Simply calls `super.emit()`.\n * @param event - Event to emit\n * @param args - Arguments for the event\n * @returns Whatever `super.emit()` returns.\n */\n private emitInternal(\n event: EventEmitterEventType,\n ...args: any[]): boolean {\n return super.emit(event, ...args);\n }\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly telemetryContextPrefix: string,\n ) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats> {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(\n serializer: IFluidSerializer,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {\n const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;\n telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/shared-object-base";
8
- export declare const pkgVersion = "2.0.0-internal.2.4.0";
8
+ export declare const pkgVersion = "2.0.0-internal.3.0.1";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/shared-object-base";
8
- export const pkgVersion = "2.0.0-internal.2.4.0";
8
+ export const pkgVersion = "2.0.0-internal.3.0.1";
9
9
  //# sourceMappingURL=packageVersion.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.2.4.0\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.3.0.1\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAwB,MAAM,oCAAoC,CAAC;AAC5F,OAAO,EAAU,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AAE7E,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACrB,iBAAiB,EAGpB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAEH,6BAA6B,EAKhC,MAAM,iCAAiC,CAAC;AAEzC,OAAO,EAAmB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM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Ae,EACzB,UAAU,GAAE,OAAe,EAC3B,gBAAgB,CAAC,EAAE,iBAAiB,GACrC,OAAO,CAAC,qBAAqB,CAAC;IAOjC;;OAEG;IACI,SAAS,CAAC,MAAM,GAAE,OAAe,GAAG,sBAAsB;IAwBjE;;;OAGG;IACH,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,iBAAiB;IAOzD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAC5B,UAAU,EAAE,gBAAgB,EAC5B,gBAAgB,CAAC,EAAE,iBAAiB,GACrC,qBAAqB;IAExB,OAAO,CAAC,wBAAwB;CAInC"}
@@ -353,7 +353,21 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
353
353
  * @returns `true` if the event had listeners, `false` otherwise.
354
354
  */
355
355
  emit(event, ...args) {
356
- return this.callbacksHelper.measure(() => super.emit(event, ...args));
356
+ return this.callbacksHelper.measure(() => {
357
+ // Creating ops while handling a DDS event can lead
358
+ // to undefined behavior and events observed in the wrong order.
359
+ // For example, we have two callbacks registered for a DDS, A and B.
360
+ // Then if on change #1 callback A creates change #2, the invocation flow will be:
361
+ //
362
+ // A because of #1
363
+ // A because of #2
364
+ // B because of #2
365
+ // B because of #1
366
+ //
367
+ // The runtime must enforce op coherence by not allowing any ops to be created during
368
+ // the event handler
369
+ return this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));
370
+ });
357
371
  }
358
372
  /**
359
373
  * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAyB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AASpE,OAAO,EAIH,qBAAqB,EACrB,yBAAy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AAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC,mCAAI,CAAC,CAAW,CAAC;QACpG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC9F,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n blobCountPropertyName,\n totalBlobSizePropertyName,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n ChildLogger,\n EventEmitterWithErrorHandling,\n loggerToMonitoringContext,\n MonitoringContext,\n SampledTelemetryHelper,\n TelemetryDataTag,\n} from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n private readonly opProcessingHelper: SampledTelemetryHelper;\n private readonly callbacksHelper: SampledTelemetryHelper;\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n private readonly mc: MonitoringContext;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n assert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n {\n all: {\n sharedObjectId: uuid(),\n ddsType: {\n value: this.attributes.type,\n tag: TelemetryDataTag.CodeArtifact,\n },\n },\n },\n );\n this.mc = loggerToMonitoringContext(this.logger);\n\n [this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n this.attachListeners();\n }\n\n /**\n * This function is only supposed to be called from SharedObjectCore's constructor and\n * depends on a few things being set already. assert() calls make sure of it.\n * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n * to variables to avoid complaints from TypeScript.\n */\n private setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n assert(this.mc !== undefined && this.logger !== undefined,\n 0x349 /* this.mc and/or this.logger has not been set */);\n const opProcessingHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsOpProcessing\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 100,\n true,\n new Map<string, ITelemetryProperties>([\n [\"local\", { localOp: true }],\n [\"remote\", { localOp: false }],\n ]));\n const callbacksHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsEventCallbacks\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 100,\n true);\n\n this.runtime.once(\"dispose\", () => {\n this.callbacksHelper.dispose();\n this.opProcessingHelper.dispose();\n });\n\n return [opProcessingHelper, callbacksHelper];\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n rollback: (content: any, localOpMetadata: unknown) => {\n this.rollback(content, localOpMetadata);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emitInternal(\"pre-op\", message, local, this);\n\n this.opProcessingHelper.measure(\n () => { this.processCore(message, local, localOpMetadata); },\n local ? \"local\" : \"remote\");\n\n this.emitInternal(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Revert an op\n */\n protected rollback(content: any, localOpMetadata: unknown) {\n throw new Error(\"rollback not supported\");\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n\n /**\n * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n * future.\n *\n * @internal\n *\n * @param event - The event to emit.\n * @param args - Arguments to pass to the event listeners.\n * @returns `true` if the event had listeners, `false` otherwise.\n */\n public emit(event: EventEmitterEventType, ...args: any[]): boolean {\n return this.callbacksHelper.measure(() => super.emit(event, ...args));\n }\n\n /**\n * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n * done on the duration of the callbacks. Simply calls `super.emit()`.\n * @param event - Event to emit\n * @param args - Arguments for the event\n * @returns Whatever `super.emit()` returns.\n */\n private emitInternal(\n event: EventEmitterEventType,\n ...args: any[]): boolean {\n return super.emit(event, ...args);\n }\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly telemetryContextPrefix: string,\n ) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats> {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(\n serializer: IFluidSerializer,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {\n const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;\n telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n }\n}\n"]}
1
+ {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAyB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AASpE,OAAO,EAIH,qBAAqB,EACrB,yBAAyB,GAC5B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,WAAW,EACX,6BAA6B,EAC7B,yBAAyB,EAEzB,sBAAsB,EACtB,gBAAgB,GACnB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAoB,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAgB,gBAClB,SAAQ,6BAAqC;IA6C7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAC9C,KAAK,CAAC,CAAC,KAA4B,E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Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger, ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n blobCountPropertyName,\n totalBlobSizePropertyName,\n} from \"@fluidframework/runtime-definitions\";\nimport {\n ChildLogger,\n EventEmitterWithErrorHandling,\n loggerToMonitoringContext,\n MonitoringContext,\n SampledTelemetryHelper,\n TelemetryDataTag,\n} from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n private readonly opProcessingHelper: SampledTelemetryHelper;\n private readonly callbacksHelper: SampledTelemetryHelper;\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n private readonly mc: MonitoringContext;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n assert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n {\n all: {\n sharedObjectId: uuid(),\n ddsType: {\n value: this.attributes.type,\n tag: TelemetryDataTag.CodeArtifact,\n },\n },\n },\n );\n this.mc = loggerToMonitoringContext(this.logger);\n\n [this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n this.attachListeners();\n }\n\n /**\n * This function is only supposed to be called from SharedObjectCore's constructor and\n * depends on a few things being set already. assert() calls make sure of it.\n * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n * to variables to avoid complaints from TypeScript.\n */\n private setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n assert(this.mc !== undefined && this.logger !== undefined,\n 0x349 /* this.mc and/or this.logger has not been set */);\n const opProcessingHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsOpProcessing\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 100,\n true,\n new Map<string, ITelemetryProperties>([\n [\"local\", { localOp: true }],\n [\"remote\", { localOp: false }],\n ]));\n const callbacksHelper = new SampledTelemetryHelper(\n {\n eventName: \"ddsEventCallbacks\",\n category: \"performance\",\n },\n this.logger,\n this.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 100,\n true);\n\n this.runtime.once(\"dispose\", () => {\n this.callbacksHelper.dispose();\n this.opProcessingHelper.dispose();\n });\n\n return [opProcessingHelper, callbacksHelper];\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n rollback: (content: any, localOpMetadata: unknown) => {\n this.rollback(content, localOpMetadata);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emitInternal(\"pre-op\", message, local, this);\n\n this.opProcessingHelper.measure(\n () => { this.processCore(message, local, localOpMetadata); },\n local ? \"local\" : \"remote\");\n\n this.emitInternal(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Revert an op\n */\n protected rollback(content: any, localOpMetadata: unknown) {\n throw new Error(\"rollback not supported\");\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n\n /**\n * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n * future.\n *\n * @internal\n *\n * @param event - The event to emit.\n * @param args - Arguments to pass to the event listeners.\n * @returns `true` if the event had listeners, `false` otherwise.\n */\n public emit(event: EventEmitterEventType, ...args: any[]): boolean {\n return this.callbacksHelper.measure(() => {\n // Creating ops while handling a DDS event can lead\n // to undefined behavior and events observed in the wrong order.\n // For example, we have two callbacks registered for a DDS, A and B.\n // Then if on change #1 callback A creates change #2, the invocation flow will be:\n //\n // A because of #1\n // A because of #2\n // B because of #2\n // B because of #1\n //\n // The runtime must enforce op coherence by not allowing any ops to be created during\n // the event handler\n return this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));\n });\n }\n\n /**\n * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n * done on the duration of the callbacks. Simply calls `super.emit()`.\n * @param event - Event to emit\n * @param args - Arguments for the event\n * @returns Whatever `super.emit()` returns.\n */\n private emitInternal(\n event: EventEmitterEventType,\n ...args: any[]): boolean {\n return super.emit(event, ...args);\n }\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly telemetryContextPrefix: string,\n ) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats> {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(\n serializer: IFluidSerializer,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {\n const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;\n telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/shared-object-base",
3
- "version": "2.0.0-internal.2.4.0",
3
+ "version": "2.0.0-internal.3.0.1",
4
4
  "description": "Fluid base class for shared distributed data structures",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -65,16 +65,16 @@
65
65
  "dependencies": {
66
66
  "@fluidframework/common-definitions": "^0.20.1",
67
67
  "@fluidframework/common-utils": "^1.0.0",
68
- "@fluidframework/container-definitions": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
69
- "@fluidframework/container-runtime": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
70
- "@fluidframework/container-utils": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
71
- "@fluidframework/core-interfaces": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
72
- "@fluidframework/datastore": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
73
- "@fluidframework/datastore-definitions": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
68
+ "@fluidframework/container-definitions": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
69
+ "@fluidframework/container-runtime": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
70
+ "@fluidframework/container-utils": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
71
+ "@fluidframework/core-interfaces": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
72
+ "@fluidframework/datastore": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
73
+ "@fluidframework/datastore-definitions": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
74
74
  "@fluidframework/protocol-definitions": "^1.1.0",
75
- "@fluidframework/runtime-definitions": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
76
- "@fluidframework/runtime-utils": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
77
- "@fluidframework/telemetry-utils": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
75
+ "@fluidframework/runtime-definitions": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
76
+ "@fluidframework/runtime-utils": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
77
+ "@fluidframework/telemetry-utils": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
78
78
  "uuid": "^8.3.1"
79
79
  },
80
80
  "devDependencies": {
@@ -82,9 +82,9 @@
82
82
  "@fluidframework/build-common": "^1.1.0",
83
83
  "@fluidframework/build-tools": "^0.8.0",
84
84
  "@fluidframework/eslint-config-fluid": "^2.0.0",
85
- "@fluidframework/mocha-test-setup": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
85
+ "@fluidframework/mocha-test-setup": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
86
86
  "@fluidframework/shared-object-base-previous": "npm:@fluidframework/shared-object-base@2.0.0-internal.2.2.0",
87
- "@fluidframework/test-runtime-utils": ">=2.0.0-internal.2.4.0 <2.0.0-internal.3.0.0",
87
+ "@fluidframework/test-runtime-utils": ">=2.0.0-internal.3.0.1 <2.0.0-internal.4.0.0",
88
88
  "@microsoft/api-extractor": "^7.22.2",
89
89
  "@rushstack/eslint-config": "^2.5.1",
90
90
  "@types/benchmark": "^2.1.0",
@@ -103,9 +103,9 @@
103
103
  "typescript": "~4.5.5"
104
104
  },
105
105
  "typeValidation": {
106
- "version": "2.0.0-internal.2.3.0",
107
- "baselineRange": ">=2.0.0-internal.2.2.0 <2.0.0-internal.2.3.0",
108
- "baselineVersion": "2.0.0-internal.2.2.0",
106
+ "version": "2.0.0-internal.3.0.0",
107
+ "baselineRange": ">=2.0.0-internal.2.0.0 <2.0.0-internal.3.0.0",
108
+ "baselineVersion": "2.0.0-internal.2.1.1",
109
109
  "broken": {}
110
110
  }
111
111
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/shared-object-base";
9
- export const pkgVersion = "2.0.0-internal.2.4.0";
9
+ export const pkgVersion = "2.0.0-internal.3.0.1";
@@ -523,7 +523,21 @@ export abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISha
523
523
  * @returns `true` if the event had listeners, `false` otherwise.
524
524
  */
525
525
  public emit(event: EventEmitterEventType, ...args: any[]): boolean {
526
- return this.callbacksHelper.measure(() => super.emit(event, ...args));
526
+ return this.callbacksHelper.measure(() => {
527
+ // Creating ops while handling a DDS event can lead
528
+ // to undefined behavior and events observed in the wrong order.
529
+ // For example, we have two callbacks registered for a DDS, A and B.
530
+ // Then if on change #1 callback A creates change #2, the invocation flow will be:
531
+ //
532
+ // A because of #1
533
+ // A because of #2
534
+ // B because of #2
535
+ // B because of #1
536
+ //
537
+ // The runtime must enforce op coherence by not allowing any ops to be created during
538
+ // the event handler
539
+ return this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));
540
+ });
527
541
  }
528
542
 
529
543
  /**