@fluidframework/shared-object-base 0.52.1 → 0.54.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/handle.d.ts +1 -7
- package/dist/handle.d.ts.map +1 -1
- package/dist/handle.js +0 -9
- package/dist/handle.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/sharedObject.d.ts +31 -0
- package/dist/sharedObject.d.ts.map +1 -1
- package/dist/sharedObject.js +53 -4
- package/dist/sharedObject.js.map +1 -1
- package/lib/handle.d.ts +1 -7
- package/lib/handle.d.ts.map +1 -1
- package/lib/handle.js +0 -9
- package/lib/handle.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/lib/sharedObject.d.ts +31 -0
- package/lib/sharedObject.d.ts.map +1 -1
- package/lib/sharedObject.js +53 -4
- package/lib/sharedObject.js.map +1 -1
- package/package.json +9 -8
- package/src/handle.ts +0 -12
- package/src/packageVersion.ts +1 -1
- package/src/sharedObject.ts +74 -5
package/dist/handle.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { IFluidHandleContext
|
|
5
|
+
import { IFluidHandleContext } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { FluidObjectHandle } from "@fluidframework/datastore";
|
|
7
7
|
import { ISharedObject } from "./types";
|
|
8
8
|
/**
|
|
@@ -30,11 +30,5 @@ export declare class SharedObjectHandle extends FluidObjectHandle<ISharedObject>
|
|
|
30
30
|
* When attaching the handle, it registers the associated shared object.
|
|
31
31
|
*/
|
|
32
32
|
attachGraph(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Returns 404.
|
|
35
|
-
* @param request - The request to make
|
|
36
|
-
* @returns A 404 error
|
|
37
|
-
*/
|
|
38
|
-
request(request: IRequest): Promise<IResponse>;
|
|
39
33
|
}
|
|
40
34
|
//# sourceMappingURL=handle.d.ts.map
|
package/dist/handle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,mBAAmB,
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,mBAAmB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,aAAa,CAAC;IACpE;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED;;;;;OAKG;gBAEC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,mBAAmB;IAKrC;;;OAGG;IACI,WAAW,IAAI,IAAI;CAI7B"}
|
package/dist/handle.js
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.SharedObjectHandle = void 0;
|
|
8
8
|
const datastore_1 = require("@fluidframework/datastore");
|
|
9
|
-
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
10
9
|
/**
|
|
11
10
|
* Handle for shared object
|
|
12
11
|
* This object is used for already loaded (in-memory) shared object
|
|
@@ -39,14 +38,6 @@ class SharedObjectHandle extends datastore_1.FluidObjectHandle {
|
|
|
39
38
|
this.value.bindToContext();
|
|
40
39
|
super.attachGraph();
|
|
41
40
|
}
|
|
42
|
-
/**
|
|
43
|
-
* Returns 404.
|
|
44
|
-
* @param request - The request to make
|
|
45
|
-
* @returns A 404 error
|
|
46
|
-
*/
|
|
47
|
-
async request(request) {
|
|
48
|
-
return runtime_utils_1.create404Response(request);
|
|
49
|
-
}
|
|
50
41
|
}
|
|
51
42
|
exports.SharedObjectHandle = SharedObjectHandle;
|
|
52
43
|
//# sourceMappingURL=handle.js.map
|
package/dist/handle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAKH,yDAA8D;AAG9D;;;;;;;GAOG;AACH,MAAa,kBAAmB,SAAQ,6BAAgC;IACpE;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,YACI,KAAoB,EACpB,IAAY,EACZ,YAAiC;QAEjC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,WAAW;QACd,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QAC3B,KAAK,CAAC,WAAW,EAAE,CAAC;IACxB,CAAC;CACJ;AA9BD,gDA8BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidHandleContext,\n} from \"@fluidframework/core-interfaces\";\nimport { FluidObjectHandle } from \"@fluidframework/datastore\";\nimport { ISharedObject } from \"./types\";\n\n/**\n * Handle for shared object\n * This object is used for already loaded (in-memory) shared object\n * and is used only for serialization purposes.\n * De-serialization process goes through FluidObjectHandle and request flow:\n * FluidDataStoreRuntime.request() recognizes requests in the form of '/<shared object id>'\n * and loads shared object.\n */\nexport class SharedObjectHandle extends FluidObjectHandle<ISharedObject> {\n /**\n * Whether services have been attached for the associated shared object.\n */\n public get isAttached(): boolean {\n return this.value.isAttached();\n }\n\n /**\n * Creates a new SharedObjectHandle.\n * @param value - The shared object this handle is for.\n * @param path - The id of the shared object. It is also the path to this object relative to the routeContext.\n * @param routeContext - The parent IFluidHandleContext that has a route to this handle.\n */\n constructor(\n value: ISharedObject,\n path: string,\n routeContext: IFluidHandleContext,\n ) {\n super(value, path, routeContext);\n }\n\n /**\n * Attaches all bound handles first (which may in turn attach further handles), then attaches this handle.\n * When attaching the handle, it registers the associated shared object.\n */\n public attachGraph(): void {\n this.value.bindToContext();\n super.attachGraph();\n }\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -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 = "0.
|
|
8
|
+
export declare const pkgVersion = "0.54.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/dist/packageVersion.js
CHANGED
|
@@ -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 = "0.
|
|
11
|
+
exports.pkgVersion = "0.54.0";
|
|
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,QAAQ,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 = \"0.
|
|
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,QAAQ,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 = \"0.54.0\";\n"]}
|
package/dist/sharedObject.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
48
48
|
* True while we are summarizing this object's data.
|
|
49
49
|
*/
|
|
50
50
|
private _isSummarizing;
|
|
51
|
+
/**
|
|
52
|
+
* Tracks error that closed this object.
|
|
53
|
+
*/
|
|
54
|
+
private closeError?;
|
|
51
55
|
/**
|
|
52
56
|
* Gets the connection state
|
|
53
57
|
* @returns The state of the connection
|
|
@@ -64,6 +68,27 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
64
68
|
* @param attributes - Attributes of the shared object
|
|
65
69
|
*/
|
|
66
70
|
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
71
|
+
/**
|
|
72
|
+
* Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
|
|
73
|
+
* would result in same error thrown. If called multiple times, only first error is remembered.
|
|
74
|
+
* @param error - error object that is thrown whenever an attempt is made to modify this object
|
|
75
|
+
*/
|
|
76
|
+
private closeWithError;
|
|
77
|
+
/**
|
|
78
|
+
* Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.
|
|
79
|
+
*/
|
|
80
|
+
private verifyNotClosed;
|
|
81
|
+
/**
|
|
82
|
+
* Event listener handler helper that can be used to react to exceptions thrown from event listeners
|
|
83
|
+
* It wraps error with DataProcessingError, closes this object and throws resulting error.
|
|
84
|
+
* See closeWithError() for more details
|
|
85
|
+
* Ideally such situation never happens, as consumers of DDS should never throw exceptions
|
|
86
|
+
* in event listeners (i.e. catch any of the issues and make determination on how to handle it).
|
|
87
|
+
* When such exceptions propagate through, most likely data model is no longer consistent, i.e.
|
|
88
|
+
* DDS state does not match what user sees. Because of it DDS moves to "corrupted state" and does not
|
|
89
|
+
* allow processing of ops or local changes, which very quickly results in container closure.
|
|
90
|
+
*/
|
|
91
|
+
private eventListenerErrorHandler;
|
|
67
92
|
private attachListeners;
|
|
68
93
|
/**
|
|
69
94
|
* A shared object, after construction, can either be loaded in the case that it is already part of
|
|
@@ -102,6 +127,12 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
102
127
|
* Derived classes must override this to provide custom list of references to other GC nodes.
|
|
103
128
|
*/
|
|
104
129
|
protected getGCDataCore(): IGarbageCollectionData;
|
|
130
|
+
/**
|
|
131
|
+
* Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
|
|
132
|
+
* to another object in the container.
|
|
133
|
+
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
134
|
+
*/
|
|
135
|
+
protected handleDecoded(decodedHandle: IFluidHandle): void;
|
|
105
136
|
/**
|
|
106
137
|
* Gets a form of the object that can be serialized.
|
|
107
138
|
* @returns A tree representing the snapshot of the shared object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAGtE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,E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B,SAAS,CAAC,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO;CAC3D"}
|
package/dist/sharedObject.js
CHANGED
|
@@ -10,6 +10,7 @@ const common_utils_1 = require("@fluidframework/common-utils");
|
|
|
10
10
|
const container_definitions_1 = require("@fluidframework/container-definitions");
|
|
11
11
|
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
12
12
|
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
13
|
+
const container_utils_1 = require("@fluidframework/container-utils");
|
|
13
14
|
const handle_1 = require("./handle");
|
|
14
15
|
const summarySerializer_1 = require("./summarySerializer");
|
|
15
16
|
/**
|
|
@@ -22,7 +23,7 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
22
23
|
* @param attributes - Attributes of the shared object
|
|
23
24
|
*/
|
|
24
25
|
constructor(id, runtime, attributes) {
|
|
25
|
-
super((
|
|
26
|
+
super((event, e) => this.eventListenerErrorHandler(event, e));
|
|
26
27
|
this.id = id;
|
|
27
28
|
this.runtime = runtime;
|
|
28
29
|
this.attributes = attributes;
|
|
@@ -40,7 +41,7 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
40
41
|
this._isSummarizing = false;
|
|
41
42
|
this.handle = new handle_1.SharedObjectHandle(this, id, runtime.IFluidHandleContext);
|
|
42
43
|
this.logger = telemetry_utils_1.ChildLogger.create(runtime.logger, undefined, { all: { sharedObjectId: uuid_1.v4() } });
|
|
43
|
-
this._serializer = new runtime_utils_1.FluidSerializer(this.runtime.channelsRoutingContext);
|
|
44
|
+
this._serializer = new runtime_utils_1.FluidSerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
|
|
44
45
|
this.attachListeners();
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
@@ -71,6 +72,40 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
71
72
|
common_utils_1.assert(!this._isSummarizing, 0x075 /* "SummarySerializer should be used for serializing data during summary." */);
|
|
72
73
|
return this._serializer;
|
|
73
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
|
|
77
|
+
* would result in same error thrown. If called multiple times, only first error is remembered.
|
|
78
|
+
* @param error - error object that is thrown whenever an attempt is made to modify this object
|
|
79
|
+
*/
|
|
80
|
+
closeWithError(error) {
|
|
81
|
+
if (this.closeError === undefined) {
|
|
82
|
+
this.closeError = error;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.
|
|
87
|
+
*/
|
|
88
|
+
verifyNotClosed() {
|
|
89
|
+
if (this.closeError !== undefined) {
|
|
90
|
+
throw this.closeError;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Event listener handler helper that can be used to react to exceptions thrown from event listeners
|
|
95
|
+
* It wraps error with DataProcessingError, closes this object and throws resulting error.
|
|
96
|
+
* See closeWithError() for more details
|
|
97
|
+
* Ideally such situation never happens, as consumers of DDS should never throw exceptions
|
|
98
|
+
* in event listeners (i.e. catch any of the issues and make determination on how to handle it).
|
|
99
|
+
* When such exceptions propagate through, most likely data model is no longer consistent, i.e.
|
|
100
|
+
* DDS state does not match what user sees. Because of it DDS moves to "corrupted state" and does not
|
|
101
|
+
* allow processing of ops or local changes, which very quickly results in container closure.
|
|
102
|
+
*/
|
|
103
|
+
eventListenerErrorHandler(event, e) {
|
|
104
|
+
const error = container_utils_1.DataProcessingError.wrapIfUnrecognized(e, "SharedObjectEventListenerException");
|
|
105
|
+
error.addTelemetryProperties({ emittedEventName: String(event) });
|
|
106
|
+
this.closeWithError(error);
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
74
109
|
attachListeners() {
|
|
75
110
|
// Only listen to these events if not attached.
|
|
76
111
|
if (!this.isAttached()) {
|
|
@@ -138,7 +173,7 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
138
173
|
this._isSummarizing = true;
|
|
139
174
|
let summaryTree;
|
|
140
175
|
try {
|
|
141
|
-
const serializer = new summarySerializer_1.SummarySerializer(this.runtime.channelsRoutingContext);
|
|
176
|
+
const serializer = new summarySerializer_1.SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
|
|
142
177
|
const snapshot = this.snapshotCore(serializer);
|
|
143
178
|
summaryTree = runtime_utils_1.convertToSummaryTreeWithStats(snapshot, fullTree);
|
|
144
179
|
common_utils_1.assert(this._isSummarizing, 0x077 /* "Possible re-entrancy! Summary should have been in progress." */);
|
|
@@ -175,7 +210,7 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
175
210
|
// We run the full summarize logic to get the list of outbound routes from this object. This is a little
|
|
176
211
|
// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.
|
|
177
212
|
// See: https://github.com/microsoft/FluidFramework/issues/4547
|
|
178
|
-
const serializer = new summarySerializer_1.SummarySerializer(this.runtime.channelsRoutingContext);
|
|
213
|
+
const serializer = new summarySerializer_1.SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
|
|
179
214
|
this.snapshotCore(serializer);
|
|
180
215
|
// The GC data for this shared object contains a single GC node. The outbound routes of this node are the
|
|
181
216
|
// routes of handles serialized during snapshot.
|
|
@@ -183,6 +218,18 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
183
218
|
gcNodes: { "/": serializer.getSerializedRoutes() },
|
|
184
219
|
};
|
|
185
220
|
}
|
|
221
|
+
/**
|
|
222
|
+
* Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
|
|
223
|
+
* to another object in the container.
|
|
224
|
+
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
225
|
+
*/
|
|
226
|
+
handleDecoded(decodedHandle) {
|
|
227
|
+
var _a, _b, _c;
|
|
228
|
+
if (this.isAttached()) {
|
|
229
|
+
// This represents an outbound reference from this object to the node represented by decodedHandle.
|
|
230
|
+
(_c = (_a = this.services) === null || _a === void 0 ? void 0 : (_b = _a.deltaConnection).addedGCOutboundReference) === null || _c === void 0 ? void 0 : _c.call(_b, this.handle, decodedHandle);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
186
233
|
/**
|
|
187
234
|
* Allows the distributed data type to perform custom local loading.
|
|
188
235
|
*/
|
|
@@ -204,6 +251,7 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
204
251
|
* also sent if we are asked to resubmit the message.
|
|
205
252
|
*/
|
|
206
253
|
submitLocalMessage(content, localOpMetadata = undefined) {
|
|
254
|
+
this.verifyNotClosed();
|
|
207
255
|
if (this.isAttached()) {
|
|
208
256
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
209
257
|
this.services.deltaConnection.submit(content, localOpMetadata);
|
|
@@ -316,6 +364,7 @@ class SharedObject extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
316
364
|
* For messages from a remote client, this will be undefined.
|
|
317
365
|
*/
|
|
318
366
|
process(message, local, localOpMetadata) {
|
|
367
|
+
this.verifyNotClosed(); // This will result in container closure.
|
|
319
368
|
this.emit("pre-op", message, local, this);
|
|
320
369
|
this.processCore(message, local, localOpMetadata);
|
|
321
370
|
this.emit("op", message, local, this);
|
package/dist/sharedObject.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,+DAAsD;AACtD,iFAAoE;AAapE,iEAA+F;AAC/F,qEAA6F;AAC7F,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,YAClB,SAAQ,+CAAqC;IAqE7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAE9C,KAAK,C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,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACK,kBAAkB,CAAC,SAAkB;QACzC,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;YAC/B,wCAAwC;YACxC,OAAO;SACV;QAED,8FAA8F;QAC9F,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,IAAI,CAAC,SAAS,EAAE;YACZ,8BAA8B;YAC9B,kEAAkE;YAClE,4FAA4F;YAC5F,EAAE;YACF,oEAAoE;YACpE,IAAI,CAAC,YAAY,EAAE,CAAC;SACvB;aAAM;YACH,kGAAkG;YAClG,sBAAsB;YACtB,IAAI,CAAC,SAAS,EAAE,CAAC;SACpB;IACL,CAAC;IAED;;;;;;OAMG;IACK,OAAO,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QACxF,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACK,QAAQ,CAAC,OAAY,EAAE,eAAwB;QACnD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAChD,CAAC;CAGJ;AAraD,oCAqaC","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 } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage, ITree } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { convertToSummaryTreeWithStats, FluidSerializer } from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\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 SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n /**\n * @param obj - The thing to check if it is a SharedObject\n * @returns Returns true if the thing is a SharedObject\n */\n public static is(obj: any): obj is SharedObject {\n return obj?.ISharedObject !== undefined;\n }\n\n public get ISharedObject() { return this; }\n public get IChannel() { return this; }\n public get IFluidLoadable() { return this; }\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\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 * True while we are summarizing this object's data.\n */\n private _isSummarizing: boolean = false;\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 protected get serializer(): IFluidSerializer {\n /**\n * During summarize, the SummarySerializer keeps track of IFluidHandles that are serialized. These handles\n * represent references to other Fluid objects and are used for garbage collection.\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._isSummarizing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\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 {\n super((eventName, error) => this.runtime.raiseContainerWarning(error));\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 { all: { sharedObjectId: uuid() } },\n );\n\n this._serializer = new FluidSerializer(this.runtime.channelsRoutingContext);\n\n this.attachListeners();\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 // Allow derived classes to perform custom processing prior to registering this object\n this.registerCore();\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public summarize(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created below)\n // to serialize handles in this object's data. The routes of these serialized handles are outbound routes\n // to other Fluid objects.\n assert(!this._isSummarizing, 0x076 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let summaryTree: ISummaryTreeWithStats;\n try {\n const serializer = new SummarySerializer(this.runtime.channelsRoutingContext);\n const snapshot: ITree = this.snapshotCore(serializer);\n summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);\n assert(this._isSummarizing, 0x077 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n return summaryTree;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created in\n // getGCDataCore) to serialize handles in this object's data.\n assert(!this._isSummarizing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n gcData = this.getGCDataCore();\n assert(this._isSummarizing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n\n return gcData;\n }\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected getGCDataCore(): IGarbageCollectionData {\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 const serializer = new SummarySerializer(this.runtime.channelsRoutingContext);\n this.snapshotCore(serializer);\n\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 snapshot.\n return {\n gcNodes: { \"/\": serializer.getSerializedRoutes() },\n };\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 snapshotCore(serializer: IFluidSerializer): ITree;\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 distributed data type the ability to perform custom processing once an attach has happened.\n */\n protected abstract registerCore();\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 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 });\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 ConsensesOrderedCollection 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.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"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 protected abstract applyStashedOp(content: any): unknown;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,+DAA6E;AAC7E,iFAAoE;AAapE,iEAA+F;AAC/F,qEAA6F;AAC7F,qEAAsE;AACtE,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,YAClB,SAAQ,+CAAqC;IA0E7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+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AAI,CAAC,UAAU,KAAK,SAAS,EAAE;YAC/B,wCAAwC;YACxC,OAAO;SACV;QAED,8FAA8F;QAC9F,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,IAAI,CAAC,SAAS,EAAE;YACZ,8BAA8B;YAC9B,kEAAkE;YAClE,4FAA4F;YAC5F,EAAE;YACF,oEAAoE;YACpE,IAAI,CAAC,YAAY,EAAE,CAAC;SACvB;aAAM;YACH,kGAAkG;YAClG,sBAAsB;YACtB,IAAI,CAAC,SAAS,EAAE,CAAC;SACpB;IACL,CAAC;IAED;;;;;;OAMG;IACK,OAAO,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QACxF,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,yCAAyC;QACjE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACK,QAAQ,CAAC,OAAY,EAAE,eAAwB;QACnD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAChD,CAAC;CAGJ;AAzeD,oCAyeC","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 } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage, ITree } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { convertToSummaryTreeWithStats, FluidSerializer } from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\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 SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n /**\n * @param obj - The thing to check if it is a SharedObject\n * @returns Returns true if the thing is a SharedObject\n */\n public static is(obj: any): obj is SharedObject {\n return obj?.ISharedObject !== undefined;\n }\n\n public get ISharedObject() { return this; }\n public get IChannel() { return this; }\n public get IFluidLoadable() { return this; }\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\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 * True while we are summarizing this object's data.\n */\n private _isSummarizing: 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 protected get serializer(): IFluidSerializer {\n /**\n * During summarize, the SummarySerializer keeps track of IFluidHandles that are serialized. These handles\n * represent references to other Fluid objects and are used for garbage collection.\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._isSummarizing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\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 {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\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 { all: { sharedObjectId: uuid() } },\n );\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n\n this.attachListeners();\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 // Allow derived classes to perform custom processing prior to registering this object\n this.registerCore();\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public summarize(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created below)\n // to serialize handles in this object's data. The routes of these serialized handles are outbound routes\n // to other Fluid objects.\n assert(!this._isSummarizing, 0x076 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let summaryTree: ISummaryTreeWithStats;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n const snapshot: ITree = this.snapshotCore(serializer);\n summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);\n assert(this._isSummarizing, 0x077 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n return summaryTree;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created in\n // getGCDataCore) to serialize handles in this object's data.\n assert(!this._isSummarizing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n gcData = this.getGCDataCore();\n assert(this._isSummarizing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n\n return gcData;\n }\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected getGCDataCore(): IGarbageCollectionData {\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 const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.snapshotCore(serializer);\n\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 snapshot.\n return {\n gcNodes: { \"/\": serializer.getSerializedRoutes() },\n };\n }\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 * 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 snapshotCore(serializer: IFluidSerializer): ITree;\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 distributed data type the ability to perform custom processing once an attach has happened.\n */\n protected abstract registerCore();\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 });\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 ConsensesOrderedCollection 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.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"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 protected abstract applyStashedOp(content: any): unknown;\n}\n"]}
|
package/lib/handle.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { IFluidHandleContext
|
|
5
|
+
import { IFluidHandleContext } from "@fluidframework/core-interfaces";
|
|
6
6
|
import { FluidObjectHandle } from "@fluidframework/datastore";
|
|
7
7
|
import { ISharedObject } from "./types";
|
|
8
8
|
/**
|
|
@@ -30,11 +30,5 @@ export declare class SharedObjectHandle extends FluidObjectHandle<ISharedObject>
|
|
|
30
30
|
* When attaching the handle, it registers the associated shared object.
|
|
31
31
|
*/
|
|
32
32
|
attachGraph(): void;
|
|
33
|
-
/**
|
|
34
|
-
* Returns 404.
|
|
35
|
-
* @param request - The request to make
|
|
36
|
-
* @returns A 404 error
|
|
37
|
-
*/
|
|
38
|
-
request(request: IRequest): Promise<IResponse>;
|
|
39
33
|
}
|
|
40
34
|
//# sourceMappingURL=handle.d.ts.map
|
package/lib/handle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,mBAAmB,
|
|
1
|
+
{"version":3,"file":"handle.d.ts","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACH,mBAAmB,EACtB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAExC;;;;;;;GAOG;AACH,qBAAa,kBAAmB,SAAQ,iBAAiB,CAAC,aAAa,CAAC;IACpE;;OAEG;IACH,IAAW,UAAU,IAAI,OAAO,CAE/B;IAED;;;;;OAKG;gBAEC,KAAK,EAAE,aAAa,EACpB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,mBAAmB;IAKrC;;;OAGG;IACI,WAAW,IAAI,IAAI;CAI7B"}
|
package/lib/handle.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { FluidObjectHandle } from "@fluidframework/datastore";
|
|
6
|
-
import { create404Response } from "@fluidframework/runtime-utils";
|
|
7
6
|
/**
|
|
8
7
|
* Handle for shared object
|
|
9
8
|
* This object is used for already loaded (in-memory) shared object
|
|
@@ -36,13 +35,5 @@ export class SharedObjectHandle extends FluidObjectHandle {
|
|
|
36
35
|
this.value.bindToContext();
|
|
37
36
|
super.attachGraph();
|
|
38
37
|
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns 404.
|
|
41
|
-
* @param request - The request to make
|
|
42
|
-
* @returns A 404 error
|
|
43
|
-
*/
|
|
44
|
-
async request(request) {
|
|
45
|
-
return create404Response(request);
|
|
46
|
-
}
|
|
47
38
|
}
|
|
48
39
|
//# sourceMappingURL=handle.js.map
|
package/lib/handle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"handle.js","sourceRoot":"","sources":["../src/handle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAG9D;;;;;;;GAOG;AACH,MAAM,OAAO,kBAAmB,SAAQ,iBAAgC;IACpE;;OAEG;IACH,IAAW,UAAU;QACjB,OAAO,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;IACnC,CAAC;IAED;;;;;OAKG;IACH,YACI,KAAoB,EACpB,IAAY,EACZ,YAAiC;QAEjC,KAAK,CAAC,KAAK,EAAE,IAAI,EAAE,YAAY,CAAC,CAAC;IACrC,CAAC;IAED;;;OAGG;IACI,WAAW;QACd,IAAI,CAAC,KAAK,CAAC,aAAa,EAAE,CAAC;QAC3B,KAAK,CAAC,WAAW,EAAE,CAAC;IACxB,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n IFluidHandleContext,\n} from \"@fluidframework/core-interfaces\";\nimport { FluidObjectHandle } from \"@fluidframework/datastore\";\nimport { ISharedObject } from \"./types\";\n\n/**\n * Handle for shared object\n * This object is used for already loaded (in-memory) shared object\n * and is used only for serialization purposes.\n * De-serialization process goes through FluidObjectHandle and request flow:\n * FluidDataStoreRuntime.request() recognizes requests in the form of '/<shared object id>'\n * and loads shared object.\n */\nexport class SharedObjectHandle extends FluidObjectHandle<ISharedObject> {\n /**\n * Whether services have been attached for the associated shared object.\n */\n public get isAttached(): boolean {\n return this.value.isAttached();\n }\n\n /**\n * Creates a new SharedObjectHandle.\n * @param value - The shared object this handle is for.\n * @param path - The id of the shared object. It is also the path to this object relative to the routeContext.\n * @param routeContext - The parent IFluidHandleContext that has a route to this handle.\n */\n constructor(\n value: ISharedObject,\n path: string,\n routeContext: IFluidHandleContext,\n ) {\n super(value, path, routeContext);\n }\n\n /**\n * Attaches all bound handles first (which may in turn attach further handles), then attaches this handle.\n * When attaching the handle, it registers the associated shared object.\n */\n public attachGraph(): void {\n this.value.bindToContext();\n super.attachGraph();\n }\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -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 = "0.
|
|
8
|
+
export declare const pkgVersion = "0.54.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -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,QAAQ,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 = \"0.
|
|
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,QAAQ,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 = \"0.54.0\";\n"]}
|
package/lib/sharedObject.d.ts
CHANGED
|
@@ -48,6 +48,10 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
48
48
|
* True while we are summarizing this object's data.
|
|
49
49
|
*/
|
|
50
50
|
private _isSummarizing;
|
|
51
|
+
/**
|
|
52
|
+
* Tracks error that closed this object.
|
|
53
|
+
*/
|
|
54
|
+
private closeError?;
|
|
51
55
|
/**
|
|
52
56
|
* Gets the connection state
|
|
53
57
|
* @returns The state of the connection
|
|
@@ -64,6 +68,27 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
64
68
|
* @param attributes - Attributes of the shared object
|
|
65
69
|
*/
|
|
66
70
|
constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
|
|
71
|
+
/**
|
|
72
|
+
* Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
|
|
73
|
+
* would result in same error thrown. If called multiple times, only first error is remembered.
|
|
74
|
+
* @param error - error object that is thrown whenever an attempt is made to modify this object
|
|
75
|
+
*/
|
|
76
|
+
private closeWithError;
|
|
77
|
+
/**
|
|
78
|
+
* Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.
|
|
79
|
+
*/
|
|
80
|
+
private verifyNotClosed;
|
|
81
|
+
/**
|
|
82
|
+
* Event listener handler helper that can be used to react to exceptions thrown from event listeners
|
|
83
|
+
* It wraps error with DataProcessingError, closes this object and throws resulting error.
|
|
84
|
+
* See closeWithError() for more details
|
|
85
|
+
* Ideally such situation never happens, as consumers of DDS should never throw exceptions
|
|
86
|
+
* in event listeners (i.e. catch any of the issues and make determination on how to handle it).
|
|
87
|
+
* When such exceptions propagate through, most likely data model is no longer consistent, i.e.
|
|
88
|
+
* DDS state does not match what user sees. Because of it DDS moves to "corrupted state" and does not
|
|
89
|
+
* allow processing of ops or local changes, which very quickly results in container closure.
|
|
90
|
+
*/
|
|
91
|
+
private eventListenerErrorHandler;
|
|
67
92
|
private attachListeners;
|
|
68
93
|
/**
|
|
69
94
|
* A shared object, after construction, can either be loaded in the case that it is already part of
|
|
@@ -102,6 +127,12 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
|
|
|
102
127
|
* Derived classes must override this to provide custom list of references to other GC nodes.
|
|
103
128
|
*/
|
|
104
129
|
protected getGCDataCore(): IGarbageCollectionData;
|
|
130
|
+
/**
|
|
131
|
+
* Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
|
|
132
|
+
* to another object in the container.
|
|
133
|
+
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
134
|
+
*/
|
|
135
|
+
protected handleDecoded(decodedHandle: IFluidHandle): void;
|
|
105
136
|
/**
|
|
106
137
|
* Gets a form of the object that can be serialized.
|
|
107
138
|
* @returns A tree representing the snapshot of the shared object.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAGtE,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,MAAM,sCAAsC,CAAC;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";
|
|
|
7
7
|
import { AttachState } from "@fluidframework/container-definitions";
|
|
8
8
|
import { convertToSummaryTreeWithStats, FluidSerializer } from "@fluidframework/runtime-utils";
|
|
9
9
|
import { ChildLogger, EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
|
|
10
|
+
import { DataProcessingError } from "@fluidframework/container-utils";
|
|
10
11
|
import { SharedObjectHandle } from "./handle";
|
|
11
12
|
import { SummarySerializer } from "./summarySerializer";
|
|
12
13
|
/**
|
|
@@ -19,7 +20,7 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
19
20
|
* @param attributes - Attributes of the shared object
|
|
20
21
|
*/
|
|
21
22
|
constructor(id, runtime, attributes) {
|
|
22
|
-
super((
|
|
23
|
+
super((event, e) => this.eventListenerErrorHandler(event, e));
|
|
23
24
|
this.id = id;
|
|
24
25
|
this.runtime = runtime;
|
|
25
26
|
this.attributes = attributes;
|
|
@@ -37,7 +38,7 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
37
38
|
this._isSummarizing = false;
|
|
38
39
|
this.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);
|
|
39
40
|
this.logger = ChildLogger.create(runtime.logger, undefined, { all: { sharedObjectId: uuid() } });
|
|
40
|
-
this._serializer = new FluidSerializer(this.runtime.channelsRoutingContext);
|
|
41
|
+
this._serializer = new FluidSerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
|
|
41
42
|
this.attachListeners();
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
@@ -68,6 +69,40 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
68
69
|
assert(!this._isSummarizing, 0x075 /* "SummarySerializer should be used for serializing data during summary." */);
|
|
69
70
|
return this._serializer;
|
|
70
71
|
}
|
|
72
|
+
/**
|
|
73
|
+
* Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
|
|
74
|
+
* would result in same error thrown. If called multiple times, only first error is remembered.
|
|
75
|
+
* @param error - error object that is thrown whenever an attempt is made to modify this object
|
|
76
|
+
*/
|
|
77
|
+
closeWithError(error) {
|
|
78
|
+
if (this.closeError === undefined) {
|
|
79
|
+
this.closeError = error;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.
|
|
84
|
+
*/
|
|
85
|
+
verifyNotClosed() {
|
|
86
|
+
if (this.closeError !== undefined) {
|
|
87
|
+
throw this.closeError;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Event listener handler helper that can be used to react to exceptions thrown from event listeners
|
|
92
|
+
* It wraps error with DataProcessingError, closes this object and throws resulting error.
|
|
93
|
+
* See closeWithError() for more details
|
|
94
|
+
* Ideally such situation never happens, as consumers of DDS should never throw exceptions
|
|
95
|
+
* in event listeners (i.e. catch any of the issues and make determination on how to handle it).
|
|
96
|
+
* When such exceptions propagate through, most likely data model is no longer consistent, i.e.
|
|
97
|
+
* DDS state does not match what user sees. Because of it DDS moves to "corrupted state" and does not
|
|
98
|
+
* allow processing of ops or local changes, which very quickly results in container closure.
|
|
99
|
+
*/
|
|
100
|
+
eventListenerErrorHandler(event, e) {
|
|
101
|
+
const error = DataProcessingError.wrapIfUnrecognized(e, "SharedObjectEventListenerException");
|
|
102
|
+
error.addTelemetryProperties({ emittedEventName: String(event) });
|
|
103
|
+
this.closeWithError(error);
|
|
104
|
+
throw error;
|
|
105
|
+
}
|
|
71
106
|
attachListeners() {
|
|
72
107
|
// Only listen to these events if not attached.
|
|
73
108
|
if (!this.isAttached()) {
|
|
@@ -135,7 +170,7 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
135
170
|
this._isSummarizing = true;
|
|
136
171
|
let summaryTree;
|
|
137
172
|
try {
|
|
138
|
-
const serializer = new SummarySerializer(this.runtime.channelsRoutingContext);
|
|
173
|
+
const serializer = new SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
|
|
139
174
|
const snapshot = this.snapshotCore(serializer);
|
|
140
175
|
summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);
|
|
141
176
|
assert(this._isSummarizing, 0x077 /* "Possible re-entrancy! Summary should have been in progress." */);
|
|
@@ -172,7 +207,7 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
172
207
|
// We run the full summarize logic to get the list of outbound routes from this object. This is a little
|
|
173
208
|
// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.
|
|
174
209
|
// See: https://github.com/microsoft/FluidFramework/issues/4547
|
|
175
|
-
const serializer = new SummarySerializer(this.runtime.channelsRoutingContext);
|
|
210
|
+
const serializer = new SummarySerializer(this.runtime.channelsRoutingContext, (handle) => this.handleDecoded(handle));
|
|
176
211
|
this.snapshotCore(serializer);
|
|
177
212
|
// The GC data for this shared object contains a single GC node. The outbound routes of this node are the
|
|
178
213
|
// routes of handles serialized during snapshot.
|
|
@@ -180,6 +215,18 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
180
215
|
gcNodes: { "/": serializer.getSerializedRoutes() },
|
|
181
216
|
};
|
|
182
217
|
}
|
|
218
|
+
/**
|
|
219
|
+
* Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
|
|
220
|
+
* to another object in the container.
|
|
221
|
+
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
222
|
+
*/
|
|
223
|
+
handleDecoded(decodedHandle) {
|
|
224
|
+
var _a, _b, _c;
|
|
225
|
+
if (this.isAttached()) {
|
|
226
|
+
// This represents an outbound reference from this object to the node represented by decodedHandle.
|
|
227
|
+
(_c = (_a = this.services) === null || _a === void 0 ? void 0 : (_b = _a.deltaConnection).addedGCOutboundReference) === null || _c === void 0 ? void 0 : _c.call(_b, this.handle, decodedHandle);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
183
230
|
/**
|
|
184
231
|
* Allows the distributed data type to perform custom local loading.
|
|
185
232
|
*/
|
|
@@ -201,6 +248,7 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
201
248
|
* also sent if we are asked to resubmit the message.
|
|
202
249
|
*/
|
|
203
250
|
submitLocalMessage(content, localOpMetadata = undefined) {
|
|
251
|
+
this.verifyNotClosed();
|
|
204
252
|
if (this.isAttached()) {
|
|
205
253
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
206
254
|
this.services.deltaConnection.submit(content, localOpMetadata);
|
|
@@ -313,6 +361,7 @@ export class SharedObject extends EventEmitterWithErrorHandling {
|
|
|
313
361
|
* For messages from a remote client, this will be undefined.
|
|
314
362
|
*/
|
|
315
363
|
process(message, local, localOpMetadata) {
|
|
364
|
+
this.verifyNotClosed(); // This will result in container closure.
|
|
316
365
|
this.emit("pre-op", message, local, this);
|
|
317
366
|
this.processCore(message, local, localOpMetadata);
|
|
318
367
|
this.emit("op", message, local, this);
|
package/lib/sharedObject.js.map
CHANGED
|
@@ -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,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAapE,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAgB,YAClB,SAAQ,6BAAqC;IAqE7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAE9C,KAAK,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE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CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACK,kBAAkB,CAAC,SAAkB;QACzC,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;YAC/B,wCAAwC;YACxC,OAAO;SACV;QAED,8FAA8F;QAC9F,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,IAAI,CAAC,SAAS,EAAE;YACZ,8BAA8B;YAC9B,kEAAkE;YAClE,4FAA4F;YAC5F,EAAE;YACF,oEAAoE;YACpE,IAAI,CAAC,YAAY,EAAE,CAAC;SACvB;aAAM;YACH,kGAAkG;YAClG,sBAAsB;YACtB,IAAI,CAAC,SAAS,EAAE,CAAC;SACpB;IACL,CAAC;IAED;;;;;;OAMG;IACK,OAAO,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QACxF,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACK,QAAQ,CAAC,OAAY,EAAE,eAAwB;QACnD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAChD,CAAC;CAGJ","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 } from \"@fluidframework/common-definitions\";\nimport { assert } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage, ITree } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { convertToSummaryTreeWithStats, FluidSerializer } from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\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 SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n /**\n * @param obj - The thing to check if it is a SharedObject\n * @returns Returns true if the thing is a SharedObject\n */\n public static is(obj: any): obj is SharedObject {\n return obj?.ISharedObject !== undefined;\n }\n\n public get ISharedObject() { return this; }\n public get IChannel() { return this; }\n public get IFluidLoadable() { return this; }\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\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 * True while we are summarizing this object's data.\n */\n private _isSummarizing: boolean = false;\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 protected get serializer(): IFluidSerializer {\n /**\n * During summarize, the SummarySerializer keeps track of IFluidHandles that are serialized. These handles\n * represent references to other Fluid objects and are used for garbage collection.\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._isSummarizing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\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 {\n super((eventName, error) => this.runtime.raiseContainerWarning(error));\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 { all: { sharedObjectId: uuid() } },\n );\n\n this._serializer = new FluidSerializer(this.runtime.channelsRoutingContext);\n\n this.attachListeners();\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 // Allow derived classes to perform custom processing prior to registering this object\n this.registerCore();\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public summarize(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created below)\n // to serialize handles in this object's data. The routes of these serialized handles are outbound routes\n // to other Fluid objects.\n assert(!this._isSummarizing, 0x076 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let summaryTree: ISummaryTreeWithStats;\n try {\n const serializer = new SummarySerializer(this.runtime.channelsRoutingContext);\n const snapshot: ITree = this.snapshotCore(serializer);\n summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);\n assert(this._isSummarizing, 0x077 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n return summaryTree;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created in\n // getGCDataCore) to serialize handles in this object's data.\n assert(!this._isSummarizing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n gcData = this.getGCDataCore();\n assert(this._isSummarizing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n\n return gcData;\n }\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected getGCDataCore(): IGarbageCollectionData {\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 const serializer = new SummarySerializer(this.runtime.channelsRoutingContext);\n this.snapshotCore(serializer);\n\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 snapshot.\n return {\n gcNodes: { \"/\": serializer.getSerializedRoutes() },\n };\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 snapshotCore(serializer: IFluidSerializer): ITree;\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 distributed data type the ability to perform custom processing once an attach has happened.\n */\n protected abstract registerCore();\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 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 });\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 ConsensesOrderedCollection 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.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"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 protected abstract applyStashedOp(content: any): unknown;\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;AAapE,OAAO,EAAE,6BAA6B,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAC/F,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,M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,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YACxC,CAAC;SACJ,CAAC,CAAC;QAEH,wBAAwB;QACxB,+DAA+D;QAC/D,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,SAAS,CAAC,CAAC;IACrE,CAAC;IAED;;;OAGG;IACK,kBAAkB,CAAC,SAAkB;QACzC,IAAI,IAAI,CAAC,UAAU,KAAK,SAAS,EAAE;YAC/B,wCAAwC;YACxC,OAAO;SACV;QAED,8FAA8F;QAC9F,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAE5B,IAAI,CAAC,SAAS,EAAE;YACZ,8BAA8B;YAC9B,kEAAkE;YAClE,4FAA4F;YAC5F,EAAE;YACF,oEAAoE;YACpE,IAAI,CAAC,YAAY,EAAE,CAAC;SACvB;aAAM;YACH,kGAAkG;YAClG,sBAAsB;YACtB,IAAI,CAAC,SAAS,EAAE,CAAC;SACpB;IACL,CAAC;IAED;;;;;;OAMG;IACK,OAAO,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QACxF,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,yCAAyC;QACjE,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,CAAC,OAAO,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED;;;;;OAKG;IACK,QAAQ,CAAC,OAAY,EAAE,eAAwB;QACnD,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE,eAAe,CAAC,CAAC;IAChD,CAAC;CAGJ","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 } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle, IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage, ITree } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { convertToSummaryTreeWithStats, FluidSerializer } from \"@fluidframework/runtime-utils\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\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 SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n /**\n * @param obj - The thing to check if it is a SharedObject\n * @returns Returns true if the thing is a SharedObject\n */\n public static is(obj: any): obj is SharedObject {\n return obj?.ISharedObject !== undefined;\n }\n\n public get ISharedObject() { return this; }\n public get IChannel() { return this; }\n public get IFluidLoadable() { return this; }\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\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 * True while we are summarizing this object's data.\n */\n private _isSummarizing: 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 protected get serializer(): IFluidSerializer {\n /**\n * During summarize, the SummarySerializer keeps track of IFluidHandles that are serialized. These handles\n * represent references to other Fluid objects and are used for garbage collection.\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._isSummarizing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\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 {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\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 { all: { sharedObjectId: uuid() } },\n );\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n\n this.attachListeners();\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 // Allow derived classes to perform custom processing prior to registering this object\n this.registerCore();\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).summarize}\n */\n public summarize(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created below)\n // to serialize handles in this object's data. The routes of these serialized handles are outbound routes\n // to other Fluid objects.\n assert(!this._isSummarizing, 0x076 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let summaryTree: ISummaryTreeWithStats;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n const snapshot: ITree = this.snapshotCore(serializer);\n summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);\n assert(this._isSummarizing, 0x077 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n return summaryTree;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isSummarizing to true. This flag is used to ensure that we only use SummarySerializer (created in\n // getGCDataCore) to serialize handles in this object's data.\n assert(!this._isSummarizing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isSummarizing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n gcData = this.getGCDataCore();\n assert(this._isSummarizing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isSummarizing = false;\n }\n\n return gcData;\n }\n\n /**\n * Returns the GC data for this shared object. It contains a list of GC nodes that contains references to\n * other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected getGCDataCore(): IGarbageCollectionData {\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 const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.snapshotCore(serializer);\n\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 snapshot.\n return {\n gcNodes: { \"/\": serializer.getSerializedRoutes() },\n };\n }\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 * 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 snapshotCore(serializer: IFluidSerializer): ITree;\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 distributed data type the ability to perform custom processing once an attach has happened.\n */\n protected abstract registerCore();\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 });\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 ConsensesOrderedCollection 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.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"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 protected abstract applyStashedOp(content: any): unknown;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/shared-object-base",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.54.0",
|
|
4
4
|
"description": "Fluid base class for shared distributed data structures",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -31,21 +31,22 @@
|
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
33
33
|
"@fluidframework/common-utils": "^0.32.1",
|
|
34
|
-
"@fluidframework/container-definitions": "^0.
|
|
34
|
+
"@fluidframework/container-definitions": "^0.44.0",
|
|
35
|
+
"@fluidframework/container-utils": "^0.54.0",
|
|
35
36
|
"@fluidframework/core-interfaces": "^0.41.0",
|
|
36
|
-
"@fluidframework/datastore": "^0.
|
|
37
|
-
"@fluidframework/datastore-definitions": "^0.
|
|
37
|
+
"@fluidframework/datastore": "^0.54.0",
|
|
38
|
+
"@fluidframework/datastore-definitions": "^0.54.0",
|
|
38
39
|
"@fluidframework/protocol-definitions": "^0.1026.0",
|
|
39
|
-
"@fluidframework/runtime-definitions": "^0.
|
|
40
|
-
"@fluidframework/runtime-utils": "^0.
|
|
41
|
-
"@fluidframework/telemetry-utils": "^0.
|
|
40
|
+
"@fluidframework/runtime-definitions": "^0.54.0",
|
|
41
|
+
"@fluidframework/runtime-utils": "^0.54.0",
|
|
42
|
+
"@fluidframework/telemetry-utils": "^0.54.0",
|
|
42
43
|
"uuid": "^8.3.1"
|
|
43
44
|
},
|
|
44
45
|
"devDependencies": {
|
|
45
46
|
"@fluidframework/build-common": "^0.23.0",
|
|
46
47
|
"@fluidframework/eslint-config-fluid": "^0.24.0",
|
|
47
48
|
"@microsoft/api-extractor": "^7.16.1",
|
|
48
|
-
"@types/node": "^
|
|
49
|
+
"@types/node": "^14.18.0",
|
|
49
50
|
"@typescript-eslint/eslint-plugin": "~4.14.0",
|
|
50
51
|
"@typescript-eslint/parser": "~4.14.0",
|
|
51
52
|
"concurrently": "^6.2.0",
|
package/src/handle.ts
CHANGED
|
@@ -5,11 +5,8 @@
|
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
7
|
IFluidHandleContext,
|
|
8
|
-
IRequest,
|
|
9
|
-
IResponse,
|
|
10
8
|
} from "@fluidframework/core-interfaces";
|
|
11
9
|
import { FluidObjectHandle } from "@fluidframework/datastore";
|
|
12
|
-
import { create404Response } from "@fluidframework/runtime-utils";
|
|
13
10
|
import { ISharedObject } from "./types";
|
|
14
11
|
|
|
15
12
|
/**
|
|
@@ -50,13 +47,4 @@ export class SharedObjectHandle extends FluidObjectHandle<ISharedObject> {
|
|
|
50
47
|
this.value.bindToContext();
|
|
51
48
|
super.attachGraph();
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Returns 404.
|
|
56
|
-
* @param request - The request to make
|
|
57
|
-
* @returns A 404 error
|
|
58
|
-
*/
|
|
59
|
-
public async request(request: IRequest): Promise<IResponse> {
|
|
60
|
-
return create404Response(request);
|
|
61
|
-
}
|
|
62
50
|
}
|
package/src/packageVersion.ts
CHANGED
package/src/sharedObject.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { v4 as uuid } from "uuid";
|
|
7
7
|
import { ITelemetryLogger } from "@fluidframework/common-definitions";
|
|
8
|
-
import { assert } from "@fluidframework/common-utils";
|
|
8
|
+
import { assert, EventEmitterEventType } from "@fluidframework/common-utils";
|
|
9
9
|
import { AttachState } from "@fluidframework/container-definitions";
|
|
10
10
|
import { IFluidHandle, IFluidSerializer } from "@fluidframework/core-interfaces";
|
|
11
11
|
import {
|
|
@@ -21,6 +21,7 @@ import {
|
|
|
21
21
|
} from "@fluidframework/runtime-definitions";
|
|
22
22
|
import { convertToSummaryTreeWithStats, FluidSerializer } from "@fluidframework/runtime-utils";
|
|
23
23
|
import { ChildLogger, EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
|
|
24
|
+
import { DataProcessingError } from "@fluidframework/container-utils";
|
|
24
25
|
import { SharedObjectHandle } from "./handle";
|
|
25
26
|
import { SummarySerializer } from "./summarySerializer";
|
|
26
27
|
import { ISharedObject, ISharedObjectEvents } from "./types";
|
|
@@ -72,6 +73,11 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
72
73
|
*/
|
|
73
74
|
private _isSummarizing: boolean = false;
|
|
74
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Tracks error that closed this object.
|
|
78
|
+
*/
|
|
79
|
+
private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;
|
|
80
|
+
|
|
75
81
|
/**
|
|
76
82
|
* Gets the connection state
|
|
77
83
|
* @returns The state of the connection
|
|
@@ -108,7 +114,7 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
108
114
|
protected runtime: IFluidDataStoreRuntime,
|
|
109
115
|
public readonly attributes: IChannelAttributes)
|
|
110
116
|
{
|
|
111
|
-
super((
|
|
117
|
+
super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));
|
|
112
118
|
|
|
113
119
|
this.handle = new SharedObjectHandle(
|
|
114
120
|
this,
|
|
@@ -121,11 +127,54 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
121
127
|
{ all: { sharedObjectId: uuid() } },
|
|
122
128
|
);
|
|
123
129
|
|
|
124
|
-
this._serializer = new FluidSerializer(
|
|
130
|
+
this._serializer = new FluidSerializer(
|
|
131
|
+
this.runtime.channelsRoutingContext,
|
|
132
|
+
(handle: IFluidHandle) => this.handleDecoded(handle),
|
|
133
|
+
);
|
|
125
134
|
|
|
126
135
|
this.attachListeners();
|
|
127
136
|
}
|
|
128
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)
|
|
140
|
+
* would result in same error thrown. If called multiple times, only first error is remembered.
|
|
141
|
+
* @param error - error object that is thrown whenever an attempt is made to modify this object
|
|
142
|
+
*/
|
|
143
|
+
private closeWithError(error: any) {
|
|
144
|
+
if (this.closeError === undefined) {
|
|
145
|
+
this.closeError = error;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.
|
|
151
|
+
*/
|
|
152
|
+
private verifyNotClosed() {
|
|
153
|
+
if (this.closeError !== undefined) {
|
|
154
|
+
throw this.closeError;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Event listener handler helper that can be used to react to exceptions thrown from event listeners
|
|
160
|
+
* It wraps error with DataProcessingError, closes this object and throws resulting error.
|
|
161
|
+
* See closeWithError() for more details
|
|
162
|
+
* Ideally such situation never happens, as consumers of DDS should never throw exceptions
|
|
163
|
+
* in event listeners (i.e. catch any of the issues and make determination on how to handle it).
|
|
164
|
+
* When such exceptions propagate through, most likely data model is no longer consistent, i.e.
|
|
165
|
+
* DDS state does not match what user sees. Because of it DDS moves to "corrupted state" and does not
|
|
166
|
+
* allow processing of ops or local changes, which very quickly results in container closure.
|
|
167
|
+
*/
|
|
168
|
+
private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {
|
|
169
|
+
const error = DataProcessingError.wrapIfUnrecognized(
|
|
170
|
+
e,
|
|
171
|
+
"SharedObjectEventListenerException");
|
|
172
|
+
error.addTelemetryProperties({ emittedEventName: String(event) });
|
|
173
|
+
|
|
174
|
+
this.closeWithError(error);
|
|
175
|
+
throw error;
|
|
176
|
+
}
|
|
177
|
+
|
|
129
178
|
private attachListeners() {
|
|
130
179
|
// Only listen to these events if not attached.
|
|
131
180
|
if (!this.isAttached()) {
|
|
@@ -203,7 +252,10 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
203
252
|
|
|
204
253
|
let summaryTree: ISummaryTreeWithStats;
|
|
205
254
|
try {
|
|
206
|
-
const serializer = new SummarySerializer(
|
|
255
|
+
const serializer = new SummarySerializer(
|
|
256
|
+
this.runtime.channelsRoutingContext,
|
|
257
|
+
(handle: IFluidHandle) => this.handleDecoded(handle),
|
|
258
|
+
);
|
|
207
259
|
const snapshot: ITree = this.snapshotCore(serializer);
|
|
208
260
|
summaryTree = convertToSummaryTreeWithStats(snapshot, fullTree);
|
|
209
261
|
assert(this._isSummarizing, 0x077 /* "Possible re-entrancy! Summary should have been in progress." */);
|
|
@@ -242,7 +294,10 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
242
294
|
// We run the full summarize logic to get the list of outbound routes from this object. This is a little
|
|
243
295
|
// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.
|
|
244
296
|
// See: https://github.com/microsoft/FluidFramework/issues/4547
|
|
245
|
-
const serializer = new SummarySerializer(
|
|
297
|
+
const serializer = new SummarySerializer(
|
|
298
|
+
this.runtime.channelsRoutingContext,
|
|
299
|
+
(handle: IFluidHandle) => this.handleDecoded(handle),
|
|
300
|
+
);
|
|
246
301
|
this.snapshotCore(serializer);
|
|
247
302
|
|
|
248
303
|
// The GC data for this shared object contains a single GC node. The outbound routes of this node are the
|
|
@@ -252,6 +307,18 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
252
307
|
};
|
|
253
308
|
}
|
|
254
309
|
|
|
310
|
+
/**
|
|
311
|
+
* Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference
|
|
312
|
+
* to another object in the container.
|
|
313
|
+
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
314
|
+
*/
|
|
315
|
+
protected handleDecoded(decodedHandle: IFluidHandle) {
|
|
316
|
+
if (this.isAttached()) {
|
|
317
|
+
// This represents an outbound reference from this object to the node represented by decodedHandle.
|
|
318
|
+
this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
255
322
|
/**
|
|
256
323
|
* Gets a form of the object that can be serialized.
|
|
257
324
|
* @returns A tree representing the snapshot of the shared object.
|
|
@@ -306,6 +373,7 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
306
373
|
* also sent if we are asked to resubmit the message.
|
|
307
374
|
*/
|
|
308
375
|
protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {
|
|
376
|
+
this.verifyNotClosed();
|
|
309
377
|
if (this.isAttached()) {
|
|
310
378
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
311
379
|
this.services!.deltaConnection.submit(content, localOpMetadata);
|
|
@@ -433,6 +501,7 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
|
|
|
433
501
|
* For messages from a remote client, this will be undefined.
|
|
434
502
|
*/
|
|
435
503
|
private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {
|
|
504
|
+
this.verifyNotClosed(); // This will result in container closure.
|
|
436
505
|
this.emit("pre-op", message, local, this);
|
|
437
506
|
this.processCore(message, local, localOpMetadata);
|
|
438
507
|
this.emit("op", message, local, this);
|