@fluidframework/shared-object-base 2.0.0-internal.5.4.0 → 2.0.0-internal.6.1.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/CHANGELOG.md +12 -0
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/dist/remoteObjectHandle.d.ts +6 -0
- package/dist/remoteObjectHandle.d.ts.map +1 -1
- package/dist/remoteObjectHandle.js +6 -0
- package/dist/remoteObjectHandle.js.map +1 -1
- package/dist/serializer.js +4 -4
- package/dist/serializer.js.map +1 -1
- package/dist/sharedObject.js +12 -11
- package/dist/sharedObject.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/remoteObjectHandle.d.ts +6 -0
- package/lib/remoteObjectHandle.d.ts.map +1 -1
- package/lib/remoteObjectHandle.js +6 -0
- package/lib/remoteObjectHandle.js.map +1 -1
- package/lib/serializer.js +4 -4
- package/lib/serializer.js.map +1 -1
- package/lib/sharedObject.js +12 -11
- package/lib/sharedObject.js.map +1 -1
- package/package.json +16 -16
- package/src/packageVersion.ts +1 -1
- package/src/remoteObjectHandle.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @fluidframework/shared-object-base
|
|
2
2
|
|
|
3
|
+
## 2.0.0-internal.6.1.0
|
|
4
|
+
|
|
5
|
+
Dependency updates only.
|
|
6
|
+
|
|
7
|
+
## 2.0.0-internal.6.0.0
|
|
8
|
+
|
|
9
|
+
### Major Changes
|
|
10
|
+
|
|
11
|
+
- Upgraded typescript transpilation target to ES2020 [8abce8cdb4](https://github.com/microsoft/FluidFramework/commits/8abce8cdb4e2832fb6405fb44e393bef03d5648a)
|
|
12
|
+
|
|
13
|
+
Upgraded typescript transpilation target to ES2020. This is done in order to decrease the bundle sizes of Fluid Framework packages. This has provided size improvements across the board for ex. Loader, Driver, Runtime etc. Reduced bundle sizes helps to load lesser code in apps and hence also helps to improve the perf.If any app wants to target any older versions of browsers with which this target version is not compatible, then they can use packages like babel to transpile to a older target.
|
|
14
|
+
|
|
3
15
|
## 2.0.0-internal.5.4.0
|
|
4
16
|
|
|
5
17
|
Dependency updates only.
|
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 = "2.0.0-internal.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.6.1.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 = "2.0.0-internal.
|
|
11
|
+
exports.pkgVersion = "2.0.0-internal.6.1.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,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.6.1.0\";\n"]}
|
|
@@ -13,6 +13,9 @@ import { IFluidHandle, IFluidHandleContext, IRequest, IResponse } from "@fluidfr
|
|
|
13
13
|
export declare class RemoteFluidObjectHandle implements IFluidHandle {
|
|
14
14
|
readonly absolutePath: string;
|
|
15
15
|
readonly routeContext: IFluidHandleContext;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
18
|
+
*/
|
|
16
19
|
get IFluidRouter(): this;
|
|
17
20
|
get IFluidHandleContext(): this;
|
|
18
21
|
get IFluidHandle(): this;
|
|
@@ -27,6 +30,9 @@ export declare class RemoteFluidObjectHandle implements IFluidHandle {
|
|
|
27
30
|
get(): Promise<any>;
|
|
28
31
|
attachGraph(): void;
|
|
29
32
|
bind(handle: IFluidHandle): void;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
35
|
+
*/
|
|
30
36
|
request(request: IRequest): Promise<IResponse>;
|
|
31
37
|
}
|
|
32
38
|
//# sourceMappingURL=remoteObjectHandle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteObjectHandle.d.ts","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,SAAS,EAGT,MAAM,iCAAiC,CAAC;AAOzC;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"remoteObjectHandle.d.ts","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,SAAS,EAGT,MAAM,iCAAiC,CAAC;AAOzC;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,YAAY;aAuB1C,YAAY,EAAE,MAAM;aACpB,YAAY,EAAE,mBAAmB;IAvBlD;;OAEG;IACH,IAAW,YAAY,SAEtB;IACD,IAAW,mBAAmB,SAE7B;IACD,IAAW,YAAY,SAEtB;IAED,SAAgB,UAAU,QAAQ;IAClC,OAAO,CAAC,OAAO,CAAmC;IAElD;;;;OAIG;gBAEc,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB;IAQrC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAoBzB,WAAW,IAAI,IAAI;IAInB,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAIvC;;OAEG;IACU,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;CAU3D"}
|
|
@@ -27,6 +27,9 @@ class RemoteFluidObjectHandle {
|
|
|
27
27
|
this.isAttached = true;
|
|
28
28
|
(0, common_utils_1.assert)(absolutePath.startsWith("/"), 0x19d /* "Handles should always have absolute paths" */);
|
|
29
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
32
|
+
*/
|
|
30
33
|
get IFluidRouter() {
|
|
31
34
|
return this;
|
|
32
35
|
}
|
|
@@ -61,6 +64,9 @@ class RemoteFluidObjectHandle {
|
|
|
61
64
|
bind(handle) {
|
|
62
65
|
handle.attachGraph();
|
|
63
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
69
|
+
*/
|
|
64
70
|
async request(request) {
|
|
65
71
|
try {
|
|
66
72
|
const object = await this.get();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteObjectHandle.js","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,yEAAmE;AASnE,iEAIuC;AAEvC;;;;;;GAMG;AACH,MAAa,uBAAuB;
|
|
1
|
+
{"version":3,"file":"remoteObjectHandle.js","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAAsD;AACtD,yEAAmE;AASnE,iEAIuC;AAEvC;;;;;;GAMG;AACH,MAAa,uBAAuB;IAiBnC;;;;OAIG;IACH,YACiB,YAAoB,EACpB,YAAiC;QADjC,iBAAY,GAAZ,YAAY,CAAQ;QACpB,iBAAY,GAAZ,YAAY,CAAqB;QAVlC,eAAU,GAAG,IAAI,CAAC;QAYjC,IAAA,qBAAM,EACL,YAAY,CAAC,UAAU,CAAC,GAAG,CAAC,EAC5B,KAAK,CAAC,iDAAiD,CACvD,CAAC;IACH,CAAC;IA7BD;;OAEG;IACH,IAAW,YAAY;QACtB,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAW,mBAAmB;QAC7B,OAAO,IAAI,CAAC;IACb,CAAC;IACD,IAAW,YAAY;QACtB,OAAO,IAAI,CAAC;IACb,CAAC;IAoBM,KAAK,CAAC,GAAG;QACf,IAAI,IAAI,CAAC,OAAO,KAAK,SAAS,EAAE;YAC/B,6EAA6E;YAC7E,MAAM,OAAO,GAAa;gBACzB,GAAG,EAAE,IAAI,CAAC,YAAY;gBACtB,OAAO,EAAE,EAAE,CAAC,kCAAc,CAAC,SAAS,CAAC,EAAE,IAAI,EAAE;aAC7C,CAAC;YACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY;iBAC9B,aAAa,CAAC,OAAO,CAAC;iBACtB,IAAI,CAAc,CAAC,QAAQ,EAAE,EAAE;gBAC/B,IAAI,QAAQ,CAAC,QAAQ,KAAK,cAAc,EAAE;oBACzC,MAAM,WAAW,GAAgB,QAAQ,CAAC,KAAK,CAAC;oBAChD,OAAO,WAAW,CAAC;iBACnB;gBACD,MAAM,IAAA,mCAAmB,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEM,WAAW;QACjB,OAAO;IACR,CAAC;IAEM,IAAI,CAAC,MAAoB;QAC/B,MAAM,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,OAAiB;QACrC,IAAI;YACH,MAAM,MAAM,GAA8B,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;YAEnC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAA,iCAAiB,EAAC,OAAO,CAAC,CAAC;SACnF;QAAC,OAAO,KAAK,EAAE;YACf,OAAO,IAAA,mCAAmB,EAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;CACD;AAzED,0DAyEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { RuntimeHeaders } from \"@fluidframework/container-runtime\";\nimport {\n\tIFluidHandle,\n\tIFluidHandleContext,\n\tIRequest,\n\tIResponse,\n\tFluidObject,\n\tIFluidRouter,\n} from \"@fluidframework/core-interfaces\";\nimport {\n\tcreate404Response,\n\texceptionToResponse,\n\tresponseToException,\n} from \"@fluidframework/runtime-utils\";\n\n/**\n * This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized\n * FluidObjectHandle.\n * This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSes,\n * custom objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the\n * IFluidHandle can be retrieved by calling `get` on it.\n */\nexport class RemoteFluidObjectHandle implements IFluidHandle {\n\t/**\n\t * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t */\n\tpublic get IFluidRouter() {\n\t\treturn this;\n\t}\n\tpublic get IFluidHandleContext() {\n\t\treturn this;\n\t}\n\tpublic get IFluidHandle() {\n\t\treturn this;\n\t}\n\n\tpublic readonly isAttached = true;\n\tprivate objectP: Promise<FluidObject> | undefined;\n\n\t/**\n\t * Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.\n\t * @param absolutePath - The absolute path to the handle from the container runtime.\n\t * @param routeContext - The root IFluidHandleContext that has a route to this handle.\n\t */\n\tconstructor(\n\t\tpublic readonly absolutePath: string,\n\t\tpublic readonly routeContext: IFluidHandleContext,\n\t) {\n\t\tassert(\n\t\t\tabsolutePath.startsWith(\"/\"),\n\t\t\t0x19d /* \"Handles should always have absolute paths\" */,\n\t\t);\n\t}\n\n\tpublic async get(): Promise<any> {\n\t\tif (this.objectP === undefined) {\n\t\t\t// Add `viaHandle` header to distinguish from requests from non-handle paths.\n\t\t\tconst request: IRequest = {\n\t\t\t\turl: this.absolutePath,\n\t\t\t\theaders: { [RuntimeHeaders.viaHandle]: true },\n\t\t\t};\n\t\t\tthis.objectP = this.routeContext\n\t\t\t\t.resolveHandle(request)\n\t\t\t\t.then<FluidObject>((response) => {\n\t\t\t\t\tif (response.mimeType === \"fluid/object\") {\n\t\t\t\t\t\tconst fluidObject: FluidObject = response.value;\n\t\t\t\t\t\treturn fluidObject;\n\t\t\t\t\t}\n\t\t\t\t\tthrow responseToException(response, request);\n\t\t\t\t});\n\t\t}\n\t\treturn this.objectP;\n\t}\n\n\tpublic attachGraph(): void {\n\t\treturn;\n\t}\n\n\tpublic bind(handle: IFluidHandle): void {\n\t\thandle.attachGraph();\n\t}\n\n\t/**\n\t * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t */\n\tpublic async request(request: IRequest): Promise<IResponse> {\n\t\ttry {\n\t\t\tconst object: FluidObject<IFluidRouter> = await this.get();\n\t\t\tconst router = object.IFluidRouter;\n\n\t\t\treturn router !== undefined ? router.request(request) : create404Response(request);\n\t\t} catch (error) {\n\t\t\treturn exceptionToResponse(error);\n\t\t}\n\t}\n}\n"]}
|
package/dist/serializer.js
CHANGED
|
@@ -9,7 +9,7 @@ exports.FluidSerializer = exports.isSerializedHandle = void 0;
|
|
|
9
9
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
10
10
|
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
11
11
|
const remoteObjectHandle_1 = require("./remoteObjectHandle");
|
|
12
|
-
const isSerializedHandle = (value) =>
|
|
12
|
+
const isSerializedHandle = (value) => value?.type === "__fluid_handle__";
|
|
13
13
|
exports.isSerializedHandle = isSerializedHandle;
|
|
14
14
|
/**
|
|
15
15
|
* Data Store serializer implementation
|
|
@@ -24,7 +24,7 @@ class FluidSerializer {
|
|
|
24
24
|
// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.
|
|
25
25
|
this.encodeValue = (value, bind) => {
|
|
26
26
|
// Detect if 'value' is an IFluidHandle.
|
|
27
|
-
const handle = value
|
|
27
|
+
const handle = value?.IFluidHandle;
|
|
28
28
|
// If 'value' is an IFluidHandle return its encoded form.
|
|
29
29
|
return handle !== undefined ? this.serializeHandle(handle, bind) : value;
|
|
30
30
|
};
|
|
@@ -124,14 +124,14 @@ class FluidSerializer {
|
|
|
124
124
|
// current property is replaced by the `replaced` value.
|
|
125
125
|
if (replaced !== value) {
|
|
126
126
|
// Lazily create a shallow clone of the `input` object if we haven't done so already.
|
|
127
|
-
clone = clone
|
|
127
|
+
clone = clone ?? (Array.isArray(input) ? [...input] : { ...input });
|
|
128
128
|
// Overwrite the current property `key` in the clone with the `replaced` value.
|
|
129
129
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
130
130
|
clone[key] = replaced;
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
return clone
|
|
134
|
+
return clone ?? input;
|
|
135
135
|
}
|
|
136
136
|
serializeHandle(handle, bind) {
|
|
137
137
|
bind.bind(handle);
|
package/dist/serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iEAAiE;AACjE,wDAAwD;AAExD,iEAA0E;AAE1E,6DAA+D;AAaxD,MAAM,kBAAkB,GAAG,CAAC,KAAU,EAA8B,EAAE,CAC5E,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AADvB,QAAA,kBAAkB,sBACK;AAmCpC;;GAEG;AACH,MAAa,eAAe;IAG3B,YACkB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QAyDhE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YACjE,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,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C9F,+FAA+F;gBAC/F,8DAA8D;gBAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEnE,kGAAkG;gBAClG,+FAA+F;gBAC/F,wDAAwD;gBACxD,IAAI,QAAQ,KAAK,KAAK,EAAE;oBACvB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,mBAAM,KAAK,CAAE,CAAC,CAAC;oBAEpE,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBACvB;aACD;SACD;QACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC;IACvB,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QACjE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACN,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SACxB,CAAC;IACH,CAAC;CACD;AAnJD,0CAmJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// RATIONALE: Many methods consume and return 'any' by necessity.\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport { generateHandleContextPath } from \"@fluidframework/runtime-utils\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { RemoteFluidObjectHandle } from \"./remoteObjectHandle\";\n\n/**\n * JSON serialized form of an IFluidHandle\n */\nexport interface ISerializedHandle {\n\t// Marker to indicate to JSON.parse that the object is a Fluid handle\n\ttype: \"__fluid_handle__\";\n\n\t// URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n\turl: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n\tvalue?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n\t/**\n\t * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n\t * where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t */\n\tencode(value: any, bind: IFluidHandle): any;\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tdecode(input: any): any;\n\n\t/**\n\t * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n\t */\n\tstringify(value: any, bind: IFluidHandle): string;\n\n\t/**\n\t * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n\t * handles will be realized as part of the parse\n\t */\n\tparse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n\tprivate readonly root: IFluidHandleContext;\n\n\tpublic constructor(\n\t\tprivate readonly context: IFluidHandleContext,\n\t\t// To be called whenever a handle is parsed by this serializer.\n\t\tprivate readonly handleParsedCb: (handle: IFluidHandle) => void,\n\t) {\n\t\tthis.root = this.context;\n\t\twhile (this.root.routeContext !== undefined) {\n\t\t\tthis.root = this.root.routeContext;\n\t\t}\n\t}\n\n\tpublic get IFluidSerializer() {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n\t * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * Any unbound handles encountered are bound to the provided IFluidHandle.\n\t */\n\tpublic encode(input: any, bind: IFluidHandle) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.encodeValue, bind)\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tpublic decode(input: any) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.decodeValue)\n\t\t\t: input;\n\t}\n\n\tpublic stringify(input: any, bind: IFluidHandle) {\n\t\treturn JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n\t}\n\n\t// Parses the serialized data - context must match the context with which the JSON was stringified\n\tpublic parse(input: string) {\n\t\treturn JSON.parse(input, (key, value) => this.decodeValue(value));\n\t}\n\n\t// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n\tprivate readonly encodeValue = (value: any, bind: IFluidHandle) => {\n\t\t// Detect if 'value' is an IFluidHandle.\n\t\tconst handle = value?.IFluidHandle;\n\n\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\treturn handle !== undefined ? this.serializeHandle(handle, bind) : value;\n\t};\n\n\t// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n\tprivate readonly decodeValue = (value: any) => {\n\t\t// If 'value' is a serialized IFluidHandle return the deserialized result.\n\t\tif (isSerializedHandle(value)) {\n\t\t\t// Old documents may have handles with relative path in their summaries. Convert these to absolute\n\t\t\t// paths. This will ensure that future summaries will have absolute paths for these handles.\n\t\t\tconst absolutePath = value.url.startsWith(\"/\")\n\t\t\t\t? value.url\n\t\t\t\t: generateHandleContextPath(value.url, this.context);\n\n\t\t\tconst parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n\t\t\tthis.handleParsedCb(parsedHandle);\n\t\t\treturn parsedHandle;\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t};\n\n\t// Invoked for non-null objects to recursively replace references to IFluidHandles.\n\t// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n\t// returns the original `input`.\n\tprivate recursivelyReplace(\n\t\tinput: any,\n\t\treplacer: (input: any, context: any) => any,\n\t\tcontext?: any,\n\t) {\n\t\t// Note: Caller is responsible for ensuring that `input` is defined / non-null.\n\t\t// (Required for Object.keys() below.)\n\n\t\t// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n\t\t// is a non-null object.\n\t\tconst maybeReplaced = replacer(input, context);\n\n\t\t// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n\t\t// leaves in the object graph.\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\n\t\t// Otherwise descend into the object graph looking for IFluidHandle instances.\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\tconst value = input[key];\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\tif (!!value && typeof value === \"object\") {\n\t\t\t\t// Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n\t\t\t\t// be JSON serializable.) Therefore, guarding against infinite recursion here would only\n\t\t\t\t// lead to a later error when attempting to stringify().\n\t\t\t\tconst replaced = this.recursivelyReplace(value, replacer, context);\n\n\t\t\t\t// If the `replaced` object is different than the original `value` then the subgraph contained one\n\t\t\t\t// or more handles. If this happens, we need to return a clone of the `input` object where the\n\t\t\t\t// current property is replaced by the `replaced` value.\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\t// Lazily create a shallow clone of the `input` object if we haven't done so already.\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\n\t\t\t\t\t// Overwrite the current property `key` in the clone with the `replaced` value.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tclone![key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn clone ?? input;\n\t}\n\n\tprotected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n\t\tbind.bind(handle);\n\t\treturn {\n\t\t\ttype: \"__fluid_handle__\",\n\t\t\turl: handle.absolutePath,\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iEAAiE;AACjE,wDAAwD;AAExD,iEAA0E;AAE1E,6DAA+D;AAaxD,MAAM,kBAAkB,GAAG,CAAC,KAAU,EAA8B,EAAE,CAC5E,KAAK,EAAE,IAAI,KAAK,kBAAkB,CAAC;AADvB,QAAA,kBAAkB,sBACK;AAmCpC;;GAEG;AACH,MAAa,eAAe;IAG3B,YACkB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QAyDhE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YACjE,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,EAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,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AK,QAAQ,EAAE;gBACzC,8FAA8F;gBAC9F,+FAA+F;gBAC/F,8DAA8D;gBAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEnE,kGAAkG;gBAClG,+FAA+F;gBAC/F,wDAAwD;gBACxD,IAAI,QAAQ,KAAK,KAAK,EAAE;oBACvB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;oBAEpE,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBACvB;aACD;SACD;QACD,OAAO,KAAK,IAAI,KAAK,CAAC;IACvB,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QACjE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACN,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SACxB,CAAC;IACH,CAAC;CACD;AAnJD,0CAmJC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// RATIONALE: Many methods consume and return 'any' by necessity.\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport { generateHandleContextPath } from \"@fluidframework/runtime-utils\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { RemoteFluidObjectHandle } from \"./remoteObjectHandle\";\n\n/**\n * JSON serialized form of an IFluidHandle\n */\nexport interface ISerializedHandle {\n\t// Marker to indicate to JSON.parse that the object is a Fluid handle\n\ttype: \"__fluid_handle__\";\n\n\t// URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n\turl: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n\tvalue?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n\t/**\n\t * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n\t * where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t */\n\tencode(value: any, bind: IFluidHandle): any;\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tdecode(input: any): any;\n\n\t/**\n\t * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n\t */\n\tstringify(value: any, bind: IFluidHandle): string;\n\n\t/**\n\t * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n\t * handles will be realized as part of the parse\n\t */\n\tparse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n\tprivate readonly root: IFluidHandleContext;\n\n\tpublic constructor(\n\t\tprivate readonly context: IFluidHandleContext,\n\t\t// To be called whenever a handle is parsed by this serializer.\n\t\tprivate readonly handleParsedCb: (handle: IFluidHandle) => void,\n\t) {\n\t\tthis.root = this.context;\n\t\twhile (this.root.routeContext !== undefined) {\n\t\t\tthis.root = this.root.routeContext;\n\t\t}\n\t}\n\n\tpublic get IFluidSerializer() {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n\t * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * Any unbound handles encountered are bound to the provided IFluidHandle.\n\t */\n\tpublic encode(input: any, bind: IFluidHandle) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.encodeValue, bind)\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tpublic decode(input: any) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.decodeValue)\n\t\t\t: input;\n\t}\n\n\tpublic stringify(input: any, bind: IFluidHandle) {\n\t\treturn JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n\t}\n\n\t// Parses the serialized data - context must match the context with which the JSON was stringified\n\tpublic parse(input: string) {\n\t\treturn JSON.parse(input, (key, value) => this.decodeValue(value));\n\t}\n\n\t// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n\tprivate readonly encodeValue = (value: any, bind: IFluidHandle) => {\n\t\t// Detect if 'value' is an IFluidHandle.\n\t\tconst handle = value?.IFluidHandle;\n\n\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\treturn handle !== undefined ? this.serializeHandle(handle, bind) : value;\n\t};\n\n\t// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n\tprivate readonly decodeValue = (value: any) => {\n\t\t// If 'value' is a serialized IFluidHandle return the deserialized result.\n\t\tif (isSerializedHandle(value)) {\n\t\t\t// Old documents may have handles with relative path in their summaries. Convert these to absolute\n\t\t\t// paths. This will ensure that future summaries will have absolute paths for these handles.\n\t\t\tconst absolutePath = value.url.startsWith(\"/\")\n\t\t\t\t? value.url\n\t\t\t\t: generateHandleContextPath(value.url, this.context);\n\n\t\t\tconst parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n\t\t\tthis.handleParsedCb(parsedHandle);\n\t\t\treturn parsedHandle;\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t};\n\n\t// Invoked for non-null objects to recursively replace references to IFluidHandles.\n\t// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n\t// returns the original `input`.\n\tprivate recursivelyReplace(\n\t\tinput: any,\n\t\treplacer: (input: any, context: any) => any,\n\t\tcontext?: any,\n\t) {\n\t\t// Note: Caller is responsible for ensuring that `input` is defined / non-null.\n\t\t// (Required for Object.keys() below.)\n\n\t\t// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n\t\t// is a non-null object.\n\t\tconst maybeReplaced = replacer(input, context);\n\n\t\t// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n\t\t// leaves in the object graph.\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\n\t\t// Otherwise descend into the object graph looking for IFluidHandle instances.\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\tconst value = input[key];\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\tif (!!value && typeof value === \"object\") {\n\t\t\t\t// Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n\t\t\t\t// be JSON serializable.) Therefore, guarding against infinite recursion here would only\n\t\t\t\t// lead to a later error when attempting to stringify().\n\t\t\t\tconst replaced = this.recursivelyReplace(value, replacer, context);\n\n\t\t\t\t// If the `replaced` object is different than the original `value` then the subgraph contained one\n\t\t\t\t// or more handles. If this happens, we need to return a clone of the `input` object where the\n\t\t\t\t// current property is replaced by the `replaced` value.\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\t// Lazily create a shallow clone of the `input` object if we haven't done so already.\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\n\t\t\t\t\t// Overwrite the current property `key` in the clone with the `replaced` value.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tclone![key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn clone ?? input;\n\t}\n\n\tprotected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n\t\tbind.bind(handle);\n\t\treturn {\n\t\t\ttype: \"__fluid_handle__\",\n\t\t\turl: handle.absolutePath,\n\t\t};\n\t}\n}\n"]}
|
package/dist/sharedObject.js
CHANGED
|
@@ -41,9 +41,12 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
41
41
|
this.logger = (0, telemetry_utils_1.createChildLogger)({
|
|
42
42
|
logger: runtime.logger,
|
|
43
43
|
properties: {
|
|
44
|
-
all:
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
all: {
|
|
45
|
+
sharedObjectId: (0, uuid_1.v4)(),
|
|
46
|
+
...(0, telemetry_utils_1.tagCodeArtifacts)({
|
|
47
|
+
ddsType: this.attributes.type,
|
|
48
|
+
}),
|
|
49
|
+
},
|
|
47
50
|
},
|
|
48
51
|
});
|
|
49
52
|
this.mc = (0, telemetry_utils_1.loggerToMonitoringContext)(this.logger);
|
|
@@ -67,19 +70,18 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
67
70
|
* to variables to avoid complaints from TypeScript.
|
|
68
71
|
*/
|
|
69
72
|
setUpSampledTelemetryHelpers() {
|
|
70
|
-
var _a, _b;
|
|
71
73
|
(0, common_utils_1.assert)(this.mc !== undefined && this.logger !== undefined, 0x349 /* this.mc and/or this.logger has not been set */);
|
|
72
74
|
const opProcessingHelper = new telemetry_utils_1.SampledTelemetryHelper({
|
|
73
75
|
eventName: "ddsOpProcessing",
|
|
74
76
|
category: "performance",
|
|
75
|
-
}, this.logger,
|
|
77
|
+
}, this.logger, this.mc.config.getNumber("Fluid.SharedObject.OpProcessingTelemetrySampling") ?? 1000, true, new Map([
|
|
76
78
|
["local", { localOp: true }],
|
|
77
79
|
["remote", { localOp: false }],
|
|
78
80
|
]));
|
|
79
81
|
const callbacksHelper = new telemetry_utils_1.SampledTelemetryHelper({
|
|
80
82
|
eventName: "ddsEventCallbacks",
|
|
81
83
|
category: "performance",
|
|
82
|
-
}, this.logger,
|
|
84
|
+
}, this.logger, this.mc.config.getNumber("Fluid.SharedObject.DdsCallbacksTelemetrySampling") ?? 1000, true);
|
|
83
85
|
this.runtime.once("dispose", () => {
|
|
84
86
|
this.callbacksHelper.dispose();
|
|
85
87
|
this.opProcessingHelper.dispose();
|
|
@@ -180,10 +182,9 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
|
|
|
180
182
|
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
181
183
|
*/
|
|
182
184
|
handleDecoded(decodedHandle) {
|
|
183
|
-
var _a, _b, _c;
|
|
184
185
|
if (this.isAttached()) {
|
|
185
186
|
// This represents an outbound reference from this object to the node represented by decodedHandle.
|
|
186
|
-
|
|
187
|
+
this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);
|
|
187
188
|
}
|
|
188
189
|
}
|
|
189
190
|
/**
|
|
@@ -467,9 +468,9 @@ class SharedObject extends SharedObjectCore {
|
|
|
467
468
|
this.summarizeCore(serializer);
|
|
468
469
|
}
|
|
469
470
|
incrementTelemetryMetric(propertyName, incrementBy, telemetryContext) {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
telemetryContext
|
|
471
|
+
const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ??
|
|
472
|
+
0);
|
|
473
|
+
telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);
|
|
473
474
|
}
|
|
474
475
|
}
|
|
475
476
|
exports.SharedObject = SharedObject;
|
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,qEAQyC;AACzC,+DAA6E;AAC7E,iFAAoE;AASpE,6EAO6C;AAC7C,qEAAsE;AACtE,6CAAiE;AACjE,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,gBACrB,SAAQ,+CAAqC;IAiD7C;;;;OAIG;IACH,YACQ,EAAU,EACP,OAA+B,EACzB,UAA8B;QAE9C,KAAK,CAAC,CAAC,KAA4B,EAAE,CAAM,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAJnF,OAAE,GAAF,EAAE,CAAQ;QACP,YAAO,GAAP,OAAO,CAAwB;QACzB,eAAU,GAAV,UAAU,CAAoB;QApC/C;;WAEG;QACK,eAAU,GAAG,KAAK,CAAC;QAO3B;;WAEG;QACK,sBAAiB,GAAY,KAAK,CAAC;QA2B1C,IAAA,qBAAM,EAAC,CAAC,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;QAEjE,IAAI,CAAC,MAAM,GAAG,IAAI,2BAAkB,CAAC,IAAI,EAAE,EAAE,EAAE,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAE5E,IAAI,CAAC,MAAM,GAAG,IAAA,mCAAiB,EAAC;YAC/B,MAAM,EAAE,OAAO,CAAC,MAAM;YACtB,UAAU,EAAE;gBACX,GAAG,kBACF,cAAc,EAAE,I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C,mEAAmE,CACzE,CAAC;SACF;gBAAS;YACT,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACtB;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,UAA6B;QACxD,wGAAwG;QACxG,2GAA2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAYO,wBAAwB,CAC/B,YAAoB,EACpB,WAAmB,EACnB,gBAAoC;;QAEpC,MAAM,SAAS,GAAG,CAAC,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC,mCAClF,CAAC,CAAW,CAAC;QACd,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC3F,CAAC;CACD;AA/JD,oCA+JC","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 { ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n\tEventEmitterWithErrorHandling,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tSampledTelemetryHelper,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\tblobCountPropertyName,\n\ttotalBlobSizePropertyName,\n\tIExperimentalIncrementalSummaryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n\textends EventEmitterWithErrorHandling<TEvent>\n\timplements ISharedObject<TEvent>\n{\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate readonly opProcessingHelper: SampledTelemetryHelper;\n\tprivate readonly callbacksHelper: SampledTelemetryHelper;\n\n\t/**\n\t * The handle referring to this SharedObject\n\t */\n\tpublic readonly handle: IFluidHandle;\n\n\t/**\n\t * Telemetry logger for the shared object\n\t */\n\tprotected readonly logger: ITelemetryLoggerExt;\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Connection state\n\t */\n\tprivate _connected = false;\n\n\t/**\n\t * Services used by the shared object\n\t */\n\tprivate services: IChannelServices | undefined;\n\n\t/**\n\t * True if the dds is bound to its parent.\n\t */\n\tprivate _isBoundToContext: boolean = false;\n\n\t/**\n\t * Tracks error that closed this object.\n\t */\n\tprivate closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n\t/**\n\t * Gets the connection state\n\t * @returns The state of the connection\n\t */\n\tpublic get connected(): boolean {\n\t\treturn this._connected;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tpublic id: string,\n\t\tprotected runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly attributes: IChannelAttributes,\n\t) {\n\t\tsuper((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n\t\tassert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n\t\tthis.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);\n\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: runtime.logger,\n\t\t\tproperties: {\n\t\t\t\tall: {\n\t\t\t\t\tsharedObjectId: uuid(),\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tddsType: this.attributes.type,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\tthis.mc = loggerToMonitoringContext(this.logger);\n\n\t\t[this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n\t\tthis.attachListeners();\n\t}\n\n\t/**\n\t * This function is only supposed to be called from SharedObjectCore's constructor and\n\t * depends on a few things being set already. assert() calls make sure of it.\n\t * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n\t * to variables to avoid complaints from TypeScript.\n\t */\n\tprivate setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n\t\tassert(\n\t\t\tthis.mc !== undefined && this.logger !== undefined,\n\t\t\t0x349 /* this.mc and/or this.logger has not been set */,\n\t\t);\n\t\tconst opProcessingHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsOpProcessing\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t\tnew Map<string, ITelemetryProperties>([\n\t\t\t\t[\"local\", { localOp: true }],\n\t\t\t\t[\"remote\", { localOp: false }],\n\t\t\t]),\n\t\t);\n\t\tconst callbacksHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsEventCallbacks\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t);\n\n\t\tthis.runtime.once(\"dispose\", () => {\n\t\t\tthis.callbacksHelper.dispose();\n\t\t\tthis.opProcessingHelper.dispose();\n\t\t});\n\n\t\treturn [opProcessingHelper, callbacksHelper];\n\t}\n\n\t/**\n\t * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n\t * would result in same error thrown. If called multiple times, only first error is remembered.\n\t * @param error - error object that is thrown whenever an attempt is made to modify this object\n\t */\n\tprivate closeWithError(error: any) {\n\t\tif (this.closeError === undefined) {\n\t\t\tthis.closeError = error;\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n\t */\n\tprivate verifyNotClosed() {\n\t\tif (this.closeError !== undefined) {\n\t\t\tthrow this.closeError;\n\t\t}\n\t}\n\n\t/**\n\t * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n\t * It wraps error with DataProcessingError, closes this object and throws resulting error.\n\t * See closeWithError() for more details\n\t * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n\t * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n\t * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n\t * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n\t * allow processing of ops or local changes, which very quickly results in container closure.\n\t */\n\tprivate eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n\t\tconst error = DataProcessingError.wrapIfUnrecognized(\n\t\t\te,\n\t\t\t\"SharedObjectEventListenerException\",\n\t\t);\n\t\terror.addTelemetryProperties({ emittedEventName: String(event) });\n\n\t\tthis.closeWithError(error);\n\t\tthrow error;\n\t}\n\n\tprivate attachListeners() {\n\t\t// Only listen to these events if not attached.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.runtime.once(\"attaching\", () => {\n\t\t\t\t// Calling this will let the dds to do any custom processing based on attached\n\t\t\t\t// like starting generating ops.\n\t\t\t\tthis.didAttach();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * A shared object, after construction, can either be loaded in the case that it is already part of\n\t * a shared document. Or later attached if it is being newly added.\n\t * @param services - Services used by the shared object\n\t */\n\tpublic async load(services: IChannelServices): Promise<void> {\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.services = services;\n\t\t}\n\t\tawait this.loadCore(services.objectStorage);\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.attachDeltaHandler();\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the object as a local, non-shared object. This object can become shared after\n\t * it is attached to the document.\n\t */\n\tpublic initializeLocal(): void {\n\t\tthis.initializeLocalCore();\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).bindToContext}\n\t */\n\tpublic bindToContext(): void {\n\t\tif (this._isBoundToContext) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._isBoundToContext = true;\n\n\t\tthis.runtime.bindChannel(this);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n\t */\n\tpublic connect(services: IChannelServices) {\n\t\tthis.services = services;\n\t\tthis.attachDeltaHandler();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n\t */\n\tpublic isAttached(): boolean {\n\t\treturn this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic abstract getAttachSummary(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic abstract summarize(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n\t/**\n\t * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n\t * to another object in the container.\n\t * @param decodedHandle - The handle of the Fluid object that is decoded.\n\t */\n\tprotected handleDecoded(decodedHandle: IFluidHandle) {\n\t\tif (this.isAttached()) {\n\t\t\t// This represents an outbound reference from this object to the node represented by decodedHandle.\n\t\t\tthis.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n\t\t}\n\t}\n\n\t/**\n\t * Allows the distributed data type to perform custom loading\n\t * @param services - Storage used by the shared object\n\t */\n\tprotected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n\t/**\n\t * Allows the distributed data type to perform custom local loading.\n\t */\n\tprotected initializeLocalCore() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n\t * Also called after non-local data type get loaded.\n\t */\n\tprotected didAttach() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Derived classes must override this to do custom processing on a remote message.\n\t * @param message - The message to process\n\t * @param local - True if the shared object is local\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected abstract processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t);\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected abstract onDisconnect();\n\n\t/**\n\t * Submits a message by the local client to the runtime.\n\t * @param content - Content of the message\n\t * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n\t * and not sent to the server. This will be sent back when this message is received back from the server. This is\n\t * also sent if we are asked to resubmit the message.\n\t */\n\tprotected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n\t\tthis.verifyNotClosed();\n\t\tif (this.isAttached()) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.services!.deltaConnection.submit(content, localOpMetadata);\n\t\t}\n\t}\n\n\t/**\n\t * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n\t * that want to be part of summary but does not generate ops.\n\t */\n\tprotected dirty(): void {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.services!.deltaConnection.dirty();\n\t}\n\n\t/**\n\t * Called when the object has fully connected to the delta stream\n\t * Default implementation for DDS, override if different behavior is required.\n\t */\n\tprotected onConnect() {}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n\t * The default implementation here is to resubmit the same message. The client can override if different behavior\n\t * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n\t * anything at all.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tthis.submitLocalMessage(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n\t * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n\t * the Promise will reject.\n\t * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n\t */\n\tprotected async newAckBasedPromise<T>(\n\t\texecutor: (\n\t\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\t\treject: (reason?: any) => void,\n\t\t) => void,\n\t): Promise<T> {\n\t\tlet rejectBecauseDispose: () => void;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\trejectBecauseDispose = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\tif (this.runtime.disposed) {\n\t\t\t\trejectBecauseDispose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.runtime.on(\"dispose\", rejectBecauseDispose);\n\t\t\texecutor(resolve, reject);\n\t\t}).finally(() => {\n\t\t\t// Note: rejectBecauseDispose will never be undefined here\n\t\t\tthis.runtime.off(\"dispose\", rejectBecauseDispose);\n\t\t});\n\t}\n\n\tprivate attachDeltaHandler() {\n\t\t// Services should already be there in case we are attaching delta handler.\n\t\tassert(\n\t\t\tthis.services !== undefined,\n\t\t\t0x07a /* \"Services should be there to attach delta handler\" */,\n\t\t);\n\t\tthis._isBoundToContext = true;\n\t\t// Allows objects to do any custom processing if it is attached.\n\t\tthis.didAttach();\n\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.services.deltaConnection.attach({\n\t\t\tprocess: (\n\t\t\t\tmessage: ISequencedDocumentMessage,\n\t\t\t\tlocal: boolean,\n\t\t\t\tlocalOpMetadata: unknown,\n\t\t\t) => {\n\t\t\t\tthis.process(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tsetConnectionState: (connected: boolean) => {\n\t\t\t\tthis.setConnectionState(connected);\n\t\t\t},\n\t\t\treSubmit: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.reSubmit(content, localOpMetadata);\n\t\t\t},\n\t\t\tapplyStashedOp: (content: any): unknown => {\n\t\t\t\treturn this.applyStashedOp(content);\n\t\t\t},\n\t\t\trollback: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.rollback(content, localOpMetadata);\n\t\t\t},\n\t\t});\n\n\t\t// Trigger initial state\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.setConnectionState(this.services.deltaConnection.connected);\n\t}\n\n\t/**\n\t * Set the state of connection to services.\n\t * @param connected - true if connected, false otherwise.\n\t */\n\tprivate setConnectionState(connected: boolean) {\n\t\tif (this._connected === connected) {\n\t\t\t// Not changing state, nothing the same.\n\t\t\treturn;\n\t\t}\n\n\t\t// Should I change the state at the end? So that we *can't* send new stuff before we send old?\n\t\tthis._connected = connected;\n\n\t\tif (!connected) {\n\t\t\t// Things that are true now...\n\t\t\t// - if we had a connection we can no longer send messages over it\n\t\t\t// - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n\t\t\t//\n\t\t\t// - nack could get a new msn - but might as well do it in the join?\n\t\t\tthis.onDisconnect();\n\t\t} else {\n\t\t\t// Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n\t\t\t// messages will work.\n\t\t\tthis.onConnect();\n\t\t}\n\t}\n\n\t/**\n\t * Handles a message being received from the remote delta server.\n\t * @param message - The message to process\n\t * @param local - Whether the message originated from the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprivate process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tthis.verifyNotClosed(); // This will result in container closure.\n\t\tthis.emitInternal(\"pre-op\", message, local, this);\n\n\t\tthis.opProcessingHelper.measure(\n\t\t\t() => {\n\t\t\t\tthis.processCore(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tlocal ? \"local\" : \"remote\",\n\t\t);\n\n\t\tthis.emitInternal(\"op\", message, local, this);\n\t}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n\t * reconnection.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprivate reSubmit(content: any, localOpMetadata: unknown) {\n\t\tthis.reSubmitCore(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown) {\n\t\tthrow new Error(\"rollback not supported\");\n\t}\n\n\t/**\n\t * Apply changes from an op. Used when rehydrating an attached container\n\t * with pending changes. This prepares the SharedObject for seeing an ACK\n\t * for the op or resubmitting the op upon reconnection.\n\t * @param content - Contents of a stashed op.\n\t * @returns localMetadata of the op, to be passed to process() or resubmit()\n\t * when the op is ACKed or resubmitted, respectively\n\t */\n\tprotected abstract applyStashedOp(content: any): unknown;\n\n\t/**\n\t * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n\t * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n\t * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n\t * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n\t * future.\n\t *\n\t * @internal\n\t *\n\t * @param event - The event to emit.\n\t * @param args - Arguments to pass to the event listeners.\n\t * @returns `true` if the event had listeners, `false` otherwise.\n\t */\n\tpublic emit(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn this.callbacksHelper.measure(() => {\n\t\t\t// Creating ops while handling a DDS event can lead\n\t\t\t// to undefined behavior and events observed in the wrong order.\n\t\t\t// For example, we have two callbacks registered for a DDS, A and B.\n\t\t\t// Then if on change #1 callback A creates change #2, the invocation flow will be:\n\t\t\t//\n\t\t\t// A because of #1\n\t\t\t// A because of #2\n\t\t\t// B because of #2\n\t\t\t// B because of #1\n\t\t\t//\n\t\t\t// The runtime must enforce op coherence by not allowing any ops to be created during\n\t\t\t// the event handler\n\t\t\treturn this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));\n\t\t});\n\t}\n\n\t/**\n\t * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n\t * done on the duration of the callbacks. Simply calls `super.emit()`.\n\t * @param event - Event to emit\n\t * @param args - Arguments for the event\n\t * @returns Whatever `super.emit()` returns.\n\t */\n\tprivate emitInternal(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn super.emit(event, ...args);\n\t}\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<\n\tTEvent extends ISharedObjectEvents = ISharedObjectEvents,\n> extends SharedObjectCore<TEvent> {\n\t/**\n\t * True while we are garbage collecting this object's data.\n\t */\n\tprivate _isGCing: boolean = false;\n\n\t/**\n\t * The serializer to use to serialize / parse handles, if any.\n\t */\n\tprivate readonly _serializer: IFluidSerializer;\n\n\tprotected get serializer(): IFluidSerializer {\n\t\t/**\n\t\t * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n\t\t * handles represent references to other Fluid objects.\n\t\t *\n\t\t * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n\t\t * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n\t\t */\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */,\n\t\t);\n\t\treturn this._serializer;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly telemetryContextPrefix: string,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis._serializer = new FluidSerializer(\n\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic getAttachSummary(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst result = this.summarizeCore(this.serializer, telemetryContext);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic async summarize(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): Promise<ISummaryTreeWithStats> {\n\t\tconst result = this.summarizeCore(\n\t\t\tthis.serializer,\n\t\t\ttelemetryContext,\n\t\t\tincrementalSummaryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\t// Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n\t\t// in this object's data.\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */,\n\t\t);\n\t\tthis._isGCing = true;\n\n\t\tlet gcData: IGarbageCollectionData;\n\t\ttry {\n\t\t\tconst serializer = new SummarySerializer(\n\t\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t\t);\n\t\t\tthis.processGCDataCore(serializer);\n\t\t\t// The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n\t\t\t// routes of handles serialized during summarization.\n\t\t\tgcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n\t\t\tassert(\n\t\t\t\tthis._isGCing,\n\t\t\t\t0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis._isGCing = false;\n\t\t}\n\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * Calls the serializer over all data in this object that reference other GC nodes.\n\t * Derived classes must override this to provide custom list of references to other GC nodes.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\t// We run the full summarize logic to get the list of outbound routes from this object. This is a little\n\t\t// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n\t\t// See: https://github.com/microsoft/FluidFramework/issues/4547\n\t\tthis.summarizeCore(serializer);\n\t}\n\n\t/**\n\t * Gets a form of the object that can be serialized.\n\t * @returns A tree representing the snapshot of the shared object.\n\t */\n\tprotected abstract summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\tprivate incrementTelemetryMetric(\n\t\tpropertyName: string,\n\t\tincrementBy: number,\n\t\ttelemetryContext?: ITelemetryContext,\n\t) {\n\t\tconst prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ??\n\t\t\t0) as number;\n\t\ttelemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,qEAQyC;AACzC,+DAA6E;AAC7E,iFAAoE;AASpE,6EAO6C;AAC7C,qEAAsE;AACtE,6CAAiE;AACjE,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,gBACrB,SAAQ,+CAAqC;IAiD7C;;;;OAIG;IACH,YACQ,EAAU,EACP,OAA+B,EACzB,UAA8B;QAE9C,KAAK,CAAC,CAAC,KAA4B,EAAE,CAAM,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAJnF,OAAE,GAAF,EAAE,CAAQ;QACP,YAAO,GAAP,OAAO,CAAwB;QACzB,eAAU,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Q,GAAG,IAAI,CAAC;QAErB,IAAI,MAA8B,CAAC;QACnC,IAAI;YACH,MAAM,UAAU,GAAG,IAAI,qCAAiB,CACvC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EACnC,CAAC,MAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CACpD,CAAC;YACF,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;YACnC,yGAAyG;YACzG,qDAAqD;YACrD,MAAM,GAAG,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,mBAAmB,EAAE,EAAE,EAAE,CAAC;YAChE,IAAA,qBAAM,EACL,IAAI,CAAC,QAAQ,EACb,KAAK,CAAC,mEAAmE,CACzE,CAAC;SACF;gBAAS;YACT,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACtB;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,UAA6B;QACxD,wGAAwG;QACxG,2GAA2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAYO,wBAAwB,CAC/B,YAAoB,EACpB,WAAmB,EACnB,gBAAoC;QAEpC,MAAM,SAAS,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC;YAClF,CAAC,CAAW,CAAC;QACd,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC3F,CAAC;CACD;AA/JD,oCA+JC","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 { ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n\tEventEmitterWithErrorHandling,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tSampledTelemetryHelper,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\tblobCountPropertyName,\n\ttotalBlobSizePropertyName,\n\tIExperimentalIncrementalSummaryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n\textends EventEmitterWithErrorHandling<TEvent>\n\timplements ISharedObject<TEvent>\n{\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate readonly opProcessingHelper: SampledTelemetryHelper;\n\tprivate readonly callbacksHelper: SampledTelemetryHelper;\n\n\t/**\n\t * The handle referring to this SharedObject\n\t */\n\tpublic readonly handle: IFluidHandle;\n\n\t/**\n\t * Telemetry logger for the shared object\n\t */\n\tprotected readonly logger: ITelemetryLoggerExt;\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Connection state\n\t */\n\tprivate _connected = false;\n\n\t/**\n\t * Services used by the shared object\n\t */\n\tprivate services: IChannelServices | undefined;\n\n\t/**\n\t * True if the dds is bound to its parent.\n\t */\n\tprivate _isBoundToContext: boolean = false;\n\n\t/**\n\t * Tracks error that closed this object.\n\t */\n\tprivate closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n\t/**\n\t * Gets the connection state\n\t * @returns The state of the connection\n\t */\n\tpublic get connected(): boolean {\n\t\treturn this._connected;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tpublic id: string,\n\t\tprotected runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly attributes: IChannelAttributes,\n\t) {\n\t\tsuper((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n\t\tassert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n\t\tthis.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);\n\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: runtime.logger,\n\t\t\tproperties: {\n\t\t\t\tall: {\n\t\t\t\t\tsharedObjectId: uuid(),\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tddsType: this.attributes.type,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\tthis.mc = loggerToMonitoringContext(this.logger);\n\n\t\t[this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n\t\tthis.attachListeners();\n\t}\n\n\t/**\n\t * This function is only supposed to be called from SharedObjectCore's constructor and\n\t * depends on a few things being set already. assert() calls make sure of it.\n\t * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n\t * to variables to avoid complaints from TypeScript.\n\t */\n\tprivate setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n\t\tassert(\n\t\t\tthis.mc !== undefined && this.logger !== undefined,\n\t\t\t0x349 /* this.mc and/or this.logger has not been set */,\n\t\t);\n\t\tconst opProcessingHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsOpProcessing\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t\tnew Map<string, ITelemetryProperties>([\n\t\t\t\t[\"local\", { localOp: true }],\n\t\t\t\t[\"remote\", { localOp: false }],\n\t\t\t]),\n\t\t);\n\t\tconst callbacksHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsEventCallbacks\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t);\n\n\t\tthis.runtime.once(\"dispose\", () => {\n\t\t\tthis.callbacksHelper.dispose();\n\t\t\tthis.opProcessingHelper.dispose();\n\t\t});\n\n\t\treturn [opProcessingHelper, callbacksHelper];\n\t}\n\n\t/**\n\t * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n\t * would result in same error thrown. If called multiple times, only first error is remembered.\n\t * @param error - error object that is thrown whenever an attempt is made to modify this object\n\t */\n\tprivate closeWithError(error: any) {\n\t\tif (this.closeError === undefined) {\n\t\t\tthis.closeError = error;\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n\t */\n\tprivate verifyNotClosed() {\n\t\tif (this.closeError !== undefined) {\n\t\t\tthrow this.closeError;\n\t\t}\n\t}\n\n\t/**\n\t * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n\t * It wraps error with DataProcessingError, closes this object and throws resulting error.\n\t * See closeWithError() for more details\n\t * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n\t * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n\t * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n\t * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n\t * allow processing of ops or local changes, which very quickly results in container closure.\n\t */\n\tprivate eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n\t\tconst error = DataProcessingError.wrapIfUnrecognized(\n\t\t\te,\n\t\t\t\"SharedObjectEventListenerException\",\n\t\t);\n\t\terror.addTelemetryProperties({ emittedEventName: String(event) });\n\n\t\tthis.closeWithError(error);\n\t\tthrow error;\n\t}\n\n\tprivate attachListeners() {\n\t\t// Only listen to these events if not attached.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.runtime.once(\"attaching\", () => {\n\t\t\t\t// Calling this will let the dds to do any custom processing based on attached\n\t\t\t\t// like starting generating ops.\n\t\t\t\tthis.didAttach();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * A shared object, after construction, can either be loaded in the case that it is already part of\n\t * a shared document. Or later attached if it is being newly added.\n\t * @param services - Services used by the shared object\n\t */\n\tpublic async load(services: IChannelServices): Promise<void> {\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.services = services;\n\t\t}\n\t\tawait this.loadCore(services.objectStorage);\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.attachDeltaHandler();\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the object as a local, non-shared object. This object can become shared after\n\t * it is attached to the document.\n\t */\n\tpublic initializeLocal(): void {\n\t\tthis.initializeLocalCore();\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).bindToContext}\n\t */\n\tpublic bindToContext(): void {\n\t\tif (this._isBoundToContext) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._isBoundToContext = true;\n\n\t\tthis.runtime.bindChannel(this);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n\t */\n\tpublic connect(services: IChannelServices) {\n\t\tthis.services = services;\n\t\tthis.attachDeltaHandler();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n\t */\n\tpublic isAttached(): boolean {\n\t\treturn this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic abstract getAttachSummary(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic abstract summarize(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n\t/**\n\t * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n\t * to another object in the container.\n\t * @param decodedHandle - The handle of the Fluid object that is decoded.\n\t */\n\tprotected handleDecoded(decodedHandle: IFluidHandle) {\n\t\tif (this.isAttached()) {\n\t\t\t// This represents an outbound reference from this object to the node represented by decodedHandle.\n\t\t\tthis.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n\t\t}\n\t}\n\n\t/**\n\t * Allows the distributed data type to perform custom loading\n\t * @param services - Storage used by the shared object\n\t */\n\tprotected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n\t/**\n\t * Allows the distributed data type to perform custom local loading.\n\t */\n\tprotected initializeLocalCore() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n\t * Also called after non-local data type get loaded.\n\t */\n\tprotected didAttach() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Derived classes must override this to do custom processing on a remote message.\n\t * @param message - The message to process\n\t * @param local - True if the shared object is local\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected abstract processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t);\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected abstract onDisconnect();\n\n\t/**\n\t * Submits a message by the local client to the runtime.\n\t * @param content - Content of the message\n\t * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n\t * and not sent to the server. This will be sent back when this message is received back from the server. This is\n\t * also sent if we are asked to resubmit the message.\n\t */\n\tprotected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n\t\tthis.verifyNotClosed();\n\t\tif (this.isAttached()) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.services!.deltaConnection.submit(content, localOpMetadata);\n\t\t}\n\t}\n\n\t/**\n\t * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n\t * that want to be part of summary but does not generate ops.\n\t */\n\tprotected dirty(): void {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.services!.deltaConnection.dirty();\n\t}\n\n\t/**\n\t * Called when the object has fully connected to the delta stream\n\t * Default implementation for DDS, override if different behavior is required.\n\t */\n\tprotected onConnect() {}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n\t * The default implementation here is to resubmit the same message. The client can override if different behavior\n\t * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n\t * anything at all.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tthis.submitLocalMessage(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n\t * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n\t * the Promise will reject.\n\t * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n\t */\n\tprotected async newAckBasedPromise<T>(\n\t\texecutor: (\n\t\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\t\treject: (reason?: any) => void,\n\t\t) => void,\n\t): Promise<T> {\n\t\tlet rejectBecauseDispose: () => void;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\trejectBecauseDispose = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\tif (this.runtime.disposed) {\n\t\t\t\trejectBecauseDispose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.runtime.on(\"dispose\", rejectBecauseDispose);\n\t\t\texecutor(resolve, reject);\n\t\t}).finally(() => {\n\t\t\t// Note: rejectBecauseDispose will never be undefined here\n\t\t\tthis.runtime.off(\"dispose\", rejectBecauseDispose);\n\t\t});\n\t}\n\n\tprivate attachDeltaHandler() {\n\t\t// Services should already be there in case we are attaching delta handler.\n\t\tassert(\n\t\t\tthis.services !== undefined,\n\t\t\t0x07a /* \"Services should be there to attach delta handler\" */,\n\t\t);\n\t\tthis._isBoundToContext = true;\n\t\t// Allows objects to do any custom processing if it is attached.\n\t\tthis.didAttach();\n\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.services.deltaConnection.attach({\n\t\t\tprocess: (\n\t\t\t\tmessage: ISequencedDocumentMessage,\n\t\t\t\tlocal: boolean,\n\t\t\t\tlocalOpMetadata: unknown,\n\t\t\t) => {\n\t\t\t\tthis.process(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tsetConnectionState: (connected: boolean) => {\n\t\t\t\tthis.setConnectionState(connected);\n\t\t\t},\n\t\t\treSubmit: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.reSubmit(content, localOpMetadata);\n\t\t\t},\n\t\t\tapplyStashedOp: (content: any): unknown => {\n\t\t\t\treturn this.applyStashedOp(content);\n\t\t\t},\n\t\t\trollback: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.rollback(content, localOpMetadata);\n\t\t\t},\n\t\t});\n\n\t\t// Trigger initial state\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.setConnectionState(this.services.deltaConnection.connected);\n\t}\n\n\t/**\n\t * Set the state of connection to services.\n\t * @param connected - true if connected, false otherwise.\n\t */\n\tprivate setConnectionState(connected: boolean) {\n\t\tif (this._connected === connected) {\n\t\t\t// Not changing state, nothing the same.\n\t\t\treturn;\n\t\t}\n\n\t\t// Should I change the state at the end? So that we *can't* send new stuff before we send old?\n\t\tthis._connected = connected;\n\n\t\tif (!connected) {\n\t\t\t// Things that are true now...\n\t\t\t// - if we had a connection we can no longer send messages over it\n\t\t\t// - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n\t\t\t//\n\t\t\t// - nack could get a new msn - but might as well do it in the join?\n\t\t\tthis.onDisconnect();\n\t\t} else {\n\t\t\t// Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n\t\t\t// messages will work.\n\t\t\tthis.onConnect();\n\t\t}\n\t}\n\n\t/**\n\t * Handles a message being received from the remote delta server.\n\t * @param message - The message to process\n\t * @param local - Whether the message originated from the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprivate process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tthis.verifyNotClosed(); // This will result in container closure.\n\t\tthis.emitInternal(\"pre-op\", message, local, this);\n\n\t\tthis.opProcessingHelper.measure(\n\t\t\t() => {\n\t\t\t\tthis.processCore(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tlocal ? \"local\" : \"remote\",\n\t\t);\n\n\t\tthis.emitInternal(\"op\", message, local, this);\n\t}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n\t * reconnection.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprivate reSubmit(content: any, localOpMetadata: unknown) {\n\t\tthis.reSubmitCore(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown) {\n\t\tthrow new Error(\"rollback not supported\");\n\t}\n\n\t/**\n\t * Apply changes from an op. Used when rehydrating an attached container\n\t * with pending changes. This prepares the SharedObject for seeing an ACK\n\t * for the op or resubmitting the op upon reconnection.\n\t * @param content - Contents of a stashed op.\n\t * @returns localMetadata of the op, to be passed to process() or resubmit()\n\t * when the op is ACKed or resubmitted, respectively\n\t */\n\tprotected abstract applyStashedOp(content: any): unknown;\n\n\t/**\n\t * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n\t * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n\t * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n\t * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n\t * future.\n\t *\n\t * @internal\n\t *\n\t * @param event - The event to emit.\n\t * @param args - Arguments to pass to the event listeners.\n\t * @returns `true` if the event had listeners, `false` otherwise.\n\t */\n\tpublic emit(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn this.callbacksHelper.measure(() => {\n\t\t\t// Creating ops while handling a DDS event can lead\n\t\t\t// to undefined behavior and events observed in the wrong order.\n\t\t\t// For example, we have two callbacks registered for a DDS, A and B.\n\t\t\t// Then if on change #1 callback A creates change #2, the invocation flow will be:\n\t\t\t//\n\t\t\t// A because of #1\n\t\t\t// A because of #2\n\t\t\t// B because of #2\n\t\t\t// B because of #1\n\t\t\t//\n\t\t\t// The runtime must enforce op coherence by not allowing any ops to be created during\n\t\t\t// the event handler\n\t\t\treturn this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));\n\t\t});\n\t}\n\n\t/**\n\t * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n\t * done on the duration of the callbacks. Simply calls `super.emit()`.\n\t * @param event - Event to emit\n\t * @param args - Arguments for the event\n\t * @returns Whatever `super.emit()` returns.\n\t */\n\tprivate emitInternal(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn super.emit(event, ...args);\n\t}\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<\n\tTEvent extends ISharedObjectEvents = ISharedObjectEvents,\n> extends SharedObjectCore<TEvent> {\n\t/**\n\t * True while we are garbage collecting this object's data.\n\t */\n\tprivate _isGCing: boolean = false;\n\n\t/**\n\t * The serializer to use to serialize / parse handles, if any.\n\t */\n\tprivate readonly _serializer: IFluidSerializer;\n\n\tprotected get serializer(): IFluidSerializer {\n\t\t/**\n\t\t * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n\t\t * handles represent references to other Fluid objects.\n\t\t *\n\t\t * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n\t\t * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n\t\t */\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */,\n\t\t);\n\t\treturn this._serializer;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly telemetryContextPrefix: string,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis._serializer = new FluidSerializer(\n\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic getAttachSummary(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst result = this.summarizeCore(this.serializer, telemetryContext);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic async summarize(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): Promise<ISummaryTreeWithStats> {\n\t\tconst result = this.summarizeCore(\n\t\t\tthis.serializer,\n\t\t\ttelemetryContext,\n\t\t\tincrementalSummaryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\t// Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n\t\t// in this object's data.\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */,\n\t\t);\n\t\tthis._isGCing = true;\n\n\t\tlet gcData: IGarbageCollectionData;\n\t\ttry {\n\t\t\tconst serializer = new SummarySerializer(\n\t\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t\t);\n\t\t\tthis.processGCDataCore(serializer);\n\t\t\t// The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n\t\t\t// routes of handles serialized during summarization.\n\t\t\tgcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n\t\t\tassert(\n\t\t\t\tthis._isGCing,\n\t\t\t\t0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis._isGCing = false;\n\t\t}\n\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * Calls the serializer over all data in this object that reference other GC nodes.\n\t * Derived classes must override this to provide custom list of references to other GC nodes.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\t// We run the full summarize logic to get the list of outbound routes from this object. This is a little\n\t\t// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n\t\t// See: https://github.com/microsoft/FluidFramework/issues/4547\n\t\tthis.summarizeCore(serializer);\n\t}\n\n\t/**\n\t * Gets a form of the object that can be serialized.\n\t * @returns A tree representing the snapshot of the shared object.\n\t */\n\tprotected abstract summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\tprivate incrementTelemetryMetric(\n\t\tpropertyName: string,\n\t\tincrementBy: number,\n\t\ttelemetryContext?: ITelemetryContext,\n\t) {\n\t\tconst prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ??\n\t\t\t0) as number;\n\t\ttelemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n\t}\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 = "2.0.0-internal.
|
|
8
|
+
export declare const pkgVersion = "2.0.0-internal.6.1.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
package/lib/packageVersion.js
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export const pkgName = "@fluidframework/shared-object-base";
|
|
8
|
-
export const pkgVersion = "2.0.0-internal.
|
|
8
|
+
export const pkgVersion = "2.0.0-internal.6.1.0";
|
|
9
9
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,sBAAsB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"2.0.0-internal.6.1.0\";\n"]}
|
|
@@ -13,6 +13,9 @@ import { IFluidHandle, IFluidHandleContext, IRequest, IResponse } from "@fluidfr
|
|
|
13
13
|
export declare class RemoteFluidObjectHandle implements IFluidHandle {
|
|
14
14
|
readonly absolutePath: string;
|
|
15
15
|
readonly routeContext: IFluidHandleContext;
|
|
16
|
+
/**
|
|
17
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
18
|
+
*/
|
|
16
19
|
get IFluidRouter(): this;
|
|
17
20
|
get IFluidHandleContext(): this;
|
|
18
21
|
get IFluidHandle(): this;
|
|
@@ -27,6 +30,9 @@ export declare class RemoteFluidObjectHandle implements IFluidHandle {
|
|
|
27
30
|
get(): Promise<any>;
|
|
28
31
|
attachGraph(): void;
|
|
29
32
|
bind(handle: IFluidHandle): void;
|
|
33
|
+
/**
|
|
34
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
35
|
+
*/
|
|
30
36
|
request(request: IRequest): Promise<IResponse>;
|
|
31
37
|
}
|
|
32
38
|
//# sourceMappingURL=remoteObjectHandle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteObjectHandle.d.ts","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,SAAS,EAGT,MAAM,iCAAiC,CAAC;AAOzC;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"remoteObjectHandle.d.ts","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACR,SAAS,EAGT,MAAM,iCAAiC,CAAC;AAOzC;;;;;;GAMG;AACH,qBAAa,uBAAwB,YAAW,YAAY;aAuB1C,YAAY,EAAE,MAAM;aACpB,YAAY,EAAE,mBAAmB;IAvBlD;;OAEG;IACH,IAAW,YAAY,SAEtB;IACD,IAAW,mBAAmB,SAE7B;IACD,IAAW,YAAY,SAEtB;IAED,SAAgB,UAAU,QAAQ;IAClC,OAAO,CAAC,OAAO,CAAmC;IAElD;;;;OAIG;gBAEc,YAAY,EAAE,MAAM,EACpB,YAAY,EAAE,mBAAmB;IAQrC,GAAG,IAAI,OAAO,CAAC,GAAG,CAAC;IAoBzB,WAAW,IAAI,IAAI;IAInB,IAAI,CAAC,MAAM,EAAE,YAAY,GAAG,IAAI;IAIvC;;OAEG;IACU,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;CAU3D"}
|
|
@@ -24,6 +24,9 @@ export class RemoteFluidObjectHandle {
|
|
|
24
24
|
this.isAttached = true;
|
|
25
25
|
assert(absolutePath.startsWith("/"), 0x19d /* "Handles should always have absolute paths" */);
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
29
|
+
*/
|
|
27
30
|
get IFluidRouter() {
|
|
28
31
|
return this;
|
|
29
32
|
}
|
|
@@ -58,6 +61,9 @@ export class RemoteFluidObjectHandle {
|
|
|
58
61
|
bind(handle) {
|
|
59
62
|
handle.attachGraph();
|
|
60
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
66
|
+
*/
|
|
61
67
|
async request(request) {
|
|
62
68
|
try {
|
|
63
69
|
const object = await this.get();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"remoteObjectHandle.js","sourceRoot":"","sources":["../src/remoteObjectHandle.ts"],"names":[],"mappings":"AA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ACF,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,YAAY;iBAC9B,aAAa,CAAC,OAAO,CAAC;iBACtB,IAAI,CAAc,CAAC,QAAQ,EAAE,EAAE;gBAC/B,IAAI,QAAQ,CAAC,QAAQ,KAAK,cAAc,EAAE;oBACzC,MAAM,WAAW,GAAgB,QAAQ,CAAC,KAAK,CAAC;oBAChD,OAAO,WAAW,CAAC;iBACnB;gBACD,MAAM,mBAAmB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;YAC9C,CAAC,CAAC,CAAC;SACJ;QACD,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEM,WAAW;QACjB,OAAO;IACR,CAAC;IAEM,IAAI,CAAC,MAAoB;QAC/B,MAAM,CAAC,WAAW,EAAE,CAAC;IACtB,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,OAAiB;QACrC,IAAI;YACH,MAAM,MAAM,GAA8B,MAAM,IAAI,CAAC,GAAG,EAAE,CAAC;YAC3D,MAAM,MAAM,GAAG,MAAM,CAAC,YAAY,CAAC;YAEnC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC;SACnF;QAAC,OAAO,KAAK,EAAE;YACf,OAAO,mBAAmB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/common-utils\";\nimport { RuntimeHeaders } from \"@fluidframework/container-runtime\";\nimport {\n\tIFluidHandle,\n\tIFluidHandleContext,\n\tIRequest,\n\tIResponse,\n\tFluidObject,\n\tIFluidRouter,\n} from \"@fluidframework/core-interfaces\";\nimport {\n\tcreate404Response,\n\texceptionToResponse,\n\tresponseToException,\n} from \"@fluidframework/runtime-utils\";\n\n/**\n * This handle is used to dynamically load a Fluid object on a remote client and is created on parsing a serialized\n * FluidObjectHandle.\n * This class is used to generate an IFluidHandle when de-serializing any all handles (including handles to DDSes,\n * custom objects) that are stored in SharedObjects. The Data Store or SharedObject corresponding to the\n * IFluidHandle can be retrieved by calling `get` on it.\n */\nexport class RemoteFluidObjectHandle implements IFluidHandle {\n\t/**\n\t * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t */\n\tpublic get IFluidRouter() {\n\t\treturn this;\n\t}\n\tpublic get IFluidHandleContext() {\n\t\treturn this;\n\t}\n\tpublic get IFluidHandle() {\n\t\treturn this;\n\t}\n\n\tpublic readonly isAttached = true;\n\tprivate objectP: Promise<FluidObject> | undefined;\n\n\t/**\n\t * Creates a new RemoteFluidObjectHandle when parsing an IFluidHandle.\n\t * @param absolutePath - The absolute path to the handle from the container runtime.\n\t * @param routeContext - The root IFluidHandleContext that has a route to this handle.\n\t */\n\tconstructor(\n\t\tpublic readonly absolutePath: string,\n\t\tpublic readonly routeContext: IFluidHandleContext,\n\t) {\n\t\tassert(\n\t\t\tabsolutePath.startsWith(\"/\"),\n\t\t\t0x19d /* \"Handles should always have absolute paths\" */,\n\t\t);\n\t}\n\n\tpublic async get(): Promise<any> {\n\t\tif (this.objectP === undefined) {\n\t\t\t// Add `viaHandle` header to distinguish from requests from non-handle paths.\n\t\t\tconst request: IRequest = {\n\t\t\t\turl: this.absolutePath,\n\t\t\t\theaders: { [RuntimeHeaders.viaHandle]: true },\n\t\t\t};\n\t\t\tthis.objectP = this.routeContext\n\t\t\t\t.resolveHandle(request)\n\t\t\t\t.then<FluidObject>((response) => {\n\t\t\t\t\tif (response.mimeType === \"fluid/object\") {\n\t\t\t\t\t\tconst fluidObject: FluidObject = response.value;\n\t\t\t\t\t\treturn fluidObject;\n\t\t\t\t\t}\n\t\t\t\t\tthrow responseToException(response, request);\n\t\t\t\t});\n\t\t}\n\t\treturn this.objectP;\n\t}\n\n\tpublic attachGraph(): void {\n\t\treturn;\n\t}\n\n\tpublic bind(handle: IFluidHandle): void {\n\t\thandle.attachGraph();\n\t}\n\n\t/**\n\t * @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t */\n\tpublic async request(request: IRequest): Promise<IResponse> {\n\t\ttry {\n\t\t\tconst object: FluidObject<IFluidRouter> = await this.get();\n\t\t\tconst router = object.IFluidRouter;\n\n\t\t\treturn router !== undefined ? router.request(request) : create404Response(request);\n\t\t} catch (error) {\n\t\t\treturn exceptionToResponse(error);\n\t\t}\n\t}\n}\n"]}
|
package/lib/serializer.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-unsafe-return */
|
|
7
7
|
import { generateHandleContextPath } from "@fluidframework/runtime-utils";
|
|
8
8
|
import { RemoteFluidObjectHandle } from "./remoteObjectHandle";
|
|
9
|
-
export const isSerializedHandle = (value) =>
|
|
9
|
+
export const isSerializedHandle = (value) => value?.type === "__fluid_handle__";
|
|
10
10
|
/**
|
|
11
11
|
* Data Store serializer implementation
|
|
12
12
|
*/
|
|
@@ -20,7 +20,7 @@ export class FluidSerializer {
|
|
|
20
20
|
// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.
|
|
21
21
|
this.encodeValue = (value, bind) => {
|
|
22
22
|
// Detect if 'value' is an IFluidHandle.
|
|
23
|
-
const handle = value
|
|
23
|
+
const handle = value?.IFluidHandle;
|
|
24
24
|
// If 'value' is an IFluidHandle return its encoded form.
|
|
25
25
|
return handle !== undefined ? this.serializeHandle(handle, bind) : value;
|
|
26
26
|
};
|
|
@@ -120,14 +120,14 @@ export class FluidSerializer {
|
|
|
120
120
|
// current property is replaced by the `replaced` value.
|
|
121
121
|
if (replaced !== value) {
|
|
122
122
|
// Lazily create a shallow clone of the `input` object if we haven't done so already.
|
|
123
|
-
clone = clone
|
|
123
|
+
clone = clone ?? (Array.isArray(input) ? [...input] : { ...input });
|
|
124
124
|
// Overwrite the current property `key` in the clone with the `replaced` value.
|
|
125
125
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
126
126
|
clone[key] = replaced;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
return clone
|
|
130
|
+
return clone ?? input;
|
|
131
131
|
}
|
|
132
132
|
serializeHandle(handle, bind) {
|
|
133
133
|
bind.bind(handle);
|
package/lib/serializer.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iEAAiE;AACjE,wDAAwD;AAExD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAa/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAU,EAA8B,EAAE,CAC5E,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AAmCpC;;GAEG;AACH,MAAM,OAAO,eAAe;IAG3B,YACkB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QAyDhE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YACjE,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QAC1E,CAAC,CAAC;QAEF,qFAAqF;QACrF,6EA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AAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEnE,kGAAkG;gBAClG,+FAA+F;gBAC/F,wDAAwD;gBACxD,IAAI,QAAQ,KAAK,KAAK,EAAE;oBACvB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,mBAAM,KAAK,CAAE,CAAC,CAAC;oBAEpE,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBACvB;aACD;SACD;QACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC;IACvB,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QACjE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACN,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SACxB,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// RATIONALE: Many methods consume and return 'any' by necessity.\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport { generateHandleContextPath } from \"@fluidframework/runtime-utils\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { RemoteFluidObjectHandle } from \"./remoteObjectHandle\";\n\n/**\n * JSON serialized form of an IFluidHandle\n */\nexport interface ISerializedHandle {\n\t// Marker to indicate to JSON.parse that the object is a Fluid handle\n\ttype: \"__fluid_handle__\";\n\n\t// URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n\turl: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n\tvalue?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n\t/**\n\t * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n\t * where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t */\n\tencode(value: any, bind: IFluidHandle): any;\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tdecode(input: any): any;\n\n\t/**\n\t * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n\t */\n\tstringify(value: any, bind: IFluidHandle): string;\n\n\t/**\n\t * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n\t * handles will be realized as part of the parse\n\t */\n\tparse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n\tprivate readonly root: IFluidHandleContext;\n\n\tpublic constructor(\n\t\tprivate readonly context: IFluidHandleContext,\n\t\t// To be called whenever a handle is parsed by this serializer.\n\t\tprivate readonly handleParsedCb: (handle: IFluidHandle) => void,\n\t) {\n\t\tthis.root = this.context;\n\t\twhile (this.root.routeContext !== undefined) {\n\t\t\tthis.root = this.root.routeContext;\n\t\t}\n\t}\n\n\tpublic get IFluidSerializer() {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n\t * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * Any unbound handles encountered are bound to the provided IFluidHandle.\n\t */\n\tpublic encode(input: any, bind: IFluidHandle) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.encodeValue, bind)\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tpublic decode(input: any) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.decodeValue)\n\t\t\t: input;\n\t}\n\n\tpublic stringify(input: any, bind: IFluidHandle) {\n\t\treturn JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n\t}\n\n\t// Parses the serialized data - context must match the context with which the JSON was stringified\n\tpublic parse(input: string) {\n\t\treturn JSON.parse(input, (key, value) => this.decodeValue(value));\n\t}\n\n\t// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n\tprivate readonly encodeValue = (value: any, bind: IFluidHandle) => {\n\t\t// Detect if 'value' is an IFluidHandle.\n\t\tconst handle = value?.IFluidHandle;\n\n\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\treturn handle !== undefined ? this.serializeHandle(handle, bind) : value;\n\t};\n\n\t// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n\tprivate readonly decodeValue = (value: any) => {\n\t\t// If 'value' is a serialized IFluidHandle return the deserialized result.\n\t\tif (isSerializedHandle(value)) {\n\t\t\t// Old documents may have handles with relative path in their summaries. Convert these to absolute\n\t\t\t// paths. This will ensure that future summaries will have absolute paths for these handles.\n\t\t\tconst absolutePath = value.url.startsWith(\"/\")\n\t\t\t\t? value.url\n\t\t\t\t: generateHandleContextPath(value.url, this.context);\n\n\t\t\tconst parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n\t\t\tthis.handleParsedCb(parsedHandle);\n\t\t\treturn parsedHandle;\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t};\n\n\t// Invoked for non-null objects to recursively replace references to IFluidHandles.\n\t// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n\t// returns the original `input`.\n\tprivate recursivelyReplace(\n\t\tinput: any,\n\t\treplacer: (input: any, context: any) => any,\n\t\tcontext?: any,\n\t) {\n\t\t// Note: Caller is responsible for ensuring that `input` is defined / non-null.\n\t\t// (Required for Object.keys() below.)\n\n\t\t// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n\t\t// is a non-null object.\n\t\tconst maybeReplaced = replacer(input, context);\n\n\t\t// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n\t\t// leaves in the object graph.\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\n\t\t// Otherwise descend into the object graph looking for IFluidHandle instances.\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\tconst value = input[key];\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\tif (!!value && typeof value === \"object\") {\n\t\t\t\t// Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n\t\t\t\t// be JSON serializable.) Therefore, guarding against infinite recursion here would only\n\t\t\t\t// lead to a later error when attempting to stringify().\n\t\t\t\tconst replaced = this.recursivelyReplace(value, replacer, context);\n\n\t\t\t\t// If the `replaced` object is different than the original `value` then the subgraph contained one\n\t\t\t\t// or more handles. If this happens, we need to return a clone of the `input` object where the\n\t\t\t\t// current property is replaced by the `replaced` value.\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\t// Lazily create a shallow clone of the `input` object if we haven't done so already.\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\n\t\t\t\t\t// Overwrite the current property `key` in the clone with the `replaced` value.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tclone![key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn clone ?? input;\n\t}\n\n\tprotected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n\t\tbind.bind(handle);\n\t\treturn {\n\t\t\ttype: \"__fluid_handle__\",\n\t\t\turl: handle.absolutePath,\n\t\t};\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,iEAAiE;AACjE,wDAAwD;AAExD,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAE1E,OAAO,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAa/D,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAU,EAA8B,EAAE,CAC5E,KAAK,EAAE,IAAI,KAAK,kBAAkB,CAAC;AAmCpC;;GAEG;AACH,MAAM,OAAO,eAAe;IAG3B,YACkB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QAyDhE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YACjE,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,EAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC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C/F,8DAA8D;gBAC9D,MAAM,QAAQ,GAAG,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;gBAEnE,kGAAkG;gBAClG,+FAA+F;gBAC/F,wDAAwD;gBACxD,IAAI,QAAQ,KAAK,KAAK,EAAE;oBACvB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;oBAEpE,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBACvB;aACD;SACD;QACD,OAAO,KAAK,IAAI,KAAK,CAAC;IACvB,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QACjE,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACN,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SACxB,CAAC;IACH,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n// RATIONALE: Many methods consume and return 'any' by necessity.\n/* eslint-disable @typescript-eslint/no-unsafe-return */\n\nimport { generateHandleContextPath } from \"@fluidframework/runtime-utils\";\nimport { IFluidHandle, IFluidHandleContext } from \"@fluidframework/core-interfaces\";\nimport { RemoteFluidObjectHandle } from \"./remoteObjectHandle\";\n\n/**\n * JSON serialized form of an IFluidHandle\n */\nexport interface ISerializedHandle {\n\t// Marker to indicate to JSON.parse that the object is a Fluid handle\n\ttype: \"__fluid_handle__\";\n\n\t// URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n\turl: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n\tvalue?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n\t/**\n\t * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n\t * where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t */\n\tencode(value: any, bind: IFluidHandle): any;\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tdecode(input: any): any;\n\n\t/**\n\t * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n\t */\n\tstringify(value: any, bind: IFluidHandle): string;\n\n\t/**\n\t * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n\t * handles will be realized as part of the parse\n\t */\n\tparse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n\tprivate readonly root: IFluidHandleContext;\n\n\tpublic constructor(\n\t\tprivate readonly context: IFluidHandleContext,\n\t\t// To be called whenever a handle is parsed by this serializer.\n\t\tprivate readonly handleParsedCb: (handle: IFluidHandle) => void,\n\t) {\n\t\tthis.root = this.context;\n\t\twhile (this.root.routeContext !== undefined) {\n\t\t\tthis.root = this.root.routeContext;\n\t\t}\n\t}\n\n\tpublic get IFluidSerializer() {\n\t\treturn this;\n\t}\n\n\t/**\n\t * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n\t * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * Any unbound handles encountered are bound to the provided IFluidHandle.\n\t */\n\tpublic encode(input: any, bind: IFluidHandle) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.encodeValue, bind)\n\t\t\t: input;\n\t}\n\n\t/**\n\t * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n\t * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n\t *\n\t * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n\t * the root to any replaced handles. (If no handles are found, returns the original object.)\n\t *\n\t * The decoded handles are implicitly bound to the handle context of this serializer.\n\t */\n\tpublic decode(input: any) {\n\t\t// If the given 'input' cannot contain handles, return it immediately. Otherwise,\n\t\t// return the result of 'recursivelyReplace()'.\n\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\treturn !!input && typeof input === \"object\"\n\t\t\t? this.recursivelyReplace(input, this.decodeValue)\n\t\t\t: input;\n\t}\n\n\tpublic stringify(input: any, bind: IFluidHandle) {\n\t\treturn JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n\t}\n\n\t// Parses the serialized data - context must match the context with which the JSON was stringified\n\tpublic parse(input: string) {\n\t\treturn JSON.parse(input, (key, value) => this.decodeValue(value));\n\t}\n\n\t// If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n\tprivate readonly encodeValue = (value: any, bind: IFluidHandle) => {\n\t\t// Detect if 'value' is an IFluidHandle.\n\t\tconst handle = value?.IFluidHandle;\n\n\t\t// If 'value' is an IFluidHandle return its encoded form.\n\t\treturn handle !== undefined ? this.serializeHandle(handle, bind) : value;\n\t};\n\n\t// If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n\t// Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n\tprivate readonly decodeValue = (value: any) => {\n\t\t// If 'value' is a serialized IFluidHandle return the deserialized result.\n\t\tif (isSerializedHandle(value)) {\n\t\t\t// Old documents may have handles with relative path in their summaries. Convert these to absolute\n\t\t\t// paths. This will ensure that future summaries will have absolute paths for these handles.\n\t\t\tconst absolutePath = value.url.startsWith(\"/\")\n\t\t\t\t? value.url\n\t\t\t\t: generateHandleContextPath(value.url, this.context);\n\n\t\t\tconst parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n\t\t\tthis.handleParsedCb(parsedHandle);\n\t\t\treturn parsedHandle;\n\t\t} else {\n\t\t\treturn value;\n\t\t}\n\t};\n\n\t// Invoked for non-null objects to recursively replace references to IFluidHandles.\n\t// Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n\t// returns the original `input`.\n\tprivate recursivelyReplace(\n\t\tinput: any,\n\t\treplacer: (input: any, context: any) => any,\n\t\tcontext?: any,\n\t) {\n\t\t// Note: Caller is responsible for ensuring that `input` is defined / non-null.\n\t\t// (Required for Object.keys() below.)\n\n\t\t// Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n\t\t// is a non-null object.\n\t\tconst maybeReplaced = replacer(input, context);\n\n\t\t// If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n\t\t// leaves in the object graph.\n\t\tif (maybeReplaced !== input) {\n\t\t\treturn maybeReplaced;\n\t\t}\n\n\t\t// Otherwise descend into the object graph looking for IFluidHandle instances.\n\t\tlet clone: object | undefined;\n\t\tfor (const key of Object.keys(input)) {\n\t\t\tconst value = input[key];\n\t\t\t// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n\t\t\tif (!!value && typeof value === \"object\") {\n\t\t\t\t// Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n\t\t\t\t// be JSON serializable.) Therefore, guarding against infinite recursion here would only\n\t\t\t\t// lead to a later error when attempting to stringify().\n\t\t\t\tconst replaced = this.recursivelyReplace(value, replacer, context);\n\n\t\t\t\t// If the `replaced` object is different than the original `value` then the subgraph contained one\n\t\t\t\t// or more handles. If this happens, we need to return a clone of the `input` object where the\n\t\t\t\t// current property is replaced by the `replaced` value.\n\t\t\t\tif (replaced !== value) {\n\t\t\t\t\t// Lazily create a shallow clone of the `input` object if we haven't done so already.\n\t\t\t\t\tclone = clone ?? (Array.isArray(input) ? [...input] : { ...input });\n\n\t\t\t\t\t// Overwrite the current property `key` in the clone with the `replaced` value.\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tclone![key] = replaced;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn clone ?? input;\n\t}\n\n\tprotected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n\t\tbind.bind(handle);\n\t\treturn {\n\t\t\ttype: \"__fluid_handle__\",\n\t\t\turl: handle.absolutePath,\n\t\t};\n\t}\n}\n"]}
|
package/lib/sharedObject.js
CHANGED
|
@@ -38,9 +38,12 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
|
|
|
38
38
|
this.logger = createChildLogger({
|
|
39
39
|
logger: runtime.logger,
|
|
40
40
|
properties: {
|
|
41
|
-
all:
|
|
42
|
-
|
|
43
|
-
|
|
41
|
+
all: {
|
|
42
|
+
sharedObjectId: uuid(),
|
|
43
|
+
...tagCodeArtifacts({
|
|
44
|
+
ddsType: this.attributes.type,
|
|
45
|
+
}),
|
|
46
|
+
},
|
|
44
47
|
},
|
|
45
48
|
});
|
|
46
49
|
this.mc = loggerToMonitoringContext(this.logger);
|
|
@@ -64,19 +67,18 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
|
|
|
64
67
|
* to variables to avoid complaints from TypeScript.
|
|
65
68
|
*/
|
|
66
69
|
setUpSampledTelemetryHelpers() {
|
|
67
|
-
var _a, _b;
|
|
68
70
|
assert(this.mc !== undefined && this.logger !== undefined, 0x349 /* this.mc and/or this.logger has not been set */);
|
|
69
71
|
const opProcessingHelper = new SampledTelemetryHelper({
|
|
70
72
|
eventName: "ddsOpProcessing",
|
|
71
73
|
category: "performance",
|
|
72
|
-
}, this.logger,
|
|
74
|
+
}, this.logger, this.mc.config.getNumber("Fluid.SharedObject.OpProcessingTelemetrySampling") ?? 1000, true, new Map([
|
|
73
75
|
["local", { localOp: true }],
|
|
74
76
|
["remote", { localOp: false }],
|
|
75
77
|
]));
|
|
76
78
|
const callbacksHelper = new SampledTelemetryHelper({
|
|
77
79
|
eventName: "ddsEventCallbacks",
|
|
78
80
|
category: "performance",
|
|
79
|
-
}, this.logger,
|
|
81
|
+
}, this.logger, this.mc.config.getNumber("Fluid.SharedObject.DdsCallbacksTelemetrySampling") ?? 1000, true);
|
|
80
82
|
this.runtime.once("dispose", () => {
|
|
81
83
|
this.callbacksHelper.dispose();
|
|
82
84
|
this.opProcessingHelper.dispose();
|
|
@@ -177,10 +179,9 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
|
|
|
177
179
|
* @param decodedHandle - The handle of the Fluid object that is decoded.
|
|
178
180
|
*/
|
|
179
181
|
handleDecoded(decodedHandle) {
|
|
180
|
-
var _a, _b, _c;
|
|
181
182
|
if (this.isAttached()) {
|
|
182
183
|
// This represents an outbound reference from this object to the node represented by decodedHandle.
|
|
183
|
-
|
|
184
|
+
this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
/**
|
|
@@ -463,9 +464,9 @@ export class SharedObject extends SharedObjectCore {
|
|
|
463
464
|
this.summarizeCore(serializer);
|
|
464
465
|
}
|
|
465
466
|
incrementTelemetryMetric(propertyName, incrementBy, telemetryContext) {
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
telemetryContext
|
|
467
|
+
const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ??
|
|
468
|
+
0);
|
|
469
|
+
telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);
|
|
469
470
|
}
|
|
470
471
|
}
|
|
471
472
|
//# sourceMappingURL=sharedObject.js.map
|
package/lib/s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rD,MAAM,GAAG,EAAE,OAAO,EAAE,EAAE,GAAG,EAAE,UAAU,CAAC,mBAAmB,EAAE,EAAE,EAAE,CAAC;YAChE,MAAM,CACL,IAAI,CAAC,QAAQ,EACb,KAAK,CAAC,mEAAmE,CACzE,CAAC;SACF;gBAAS;YACT,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACtB;QAED,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,UAA6B;QACxD,wGAAwG;QACxG,2GAA2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IAChC,CAAC;IAYO,wBAAwB,CAC/B,YAAoB,EACpB,WAAmB,EACnB,gBAAoC;;QAEpC,MAAM,SAAS,GAAG,CAAC,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC,mCAClF,CAAC,CAAW,CAAC;QACd,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC3F,CAAC;CACD","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 { ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n\tEventEmitterWithErrorHandling,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tSampledTelemetryHelper,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\tblobCountPropertyName,\n\ttotalBlobSizePropertyName,\n\tIExperimentalIncrementalSummaryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n\textends EventEmitterWithErrorHandling<TEvent>\n\timplements ISharedObject<TEvent>\n{\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate readonly opProcessingHelper: SampledTelemetryHelper;\n\tprivate readonly callbacksHelper: SampledTelemetryHelper;\n\n\t/**\n\t * The handle referring to this SharedObject\n\t */\n\tpublic readonly handle: IFluidHandle;\n\n\t/**\n\t * Telemetry logger for the shared object\n\t */\n\tprotected readonly logger: ITelemetryLoggerExt;\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Connection state\n\t */\n\tprivate _connected = false;\n\n\t/**\n\t * Services used by the shared object\n\t */\n\tprivate services: IChannelServices | undefined;\n\n\t/**\n\t * True if the dds is bound to its parent.\n\t */\n\tprivate _isBoundToContext: boolean = false;\n\n\t/**\n\t * Tracks error that closed this object.\n\t */\n\tprivate closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n\t/**\n\t * Gets the connection state\n\t * @returns The state of the connection\n\t */\n\tpublic get connected(): boolean {\n\t\treturn this._connected;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tpublic id: string,\n\t\tprotected runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly attributes: IChannelAttributes,\n\t) {\n\t\tsuper((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n\t\tassert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n\t\tthis.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);\n\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: runtime.logger,\n\t\t\tproperties: {\n\t\t\t\tall: {\n\t\t\t\t\tsharedObjectId: uuid(),\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tddsType: this.attributes.type,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\tthis.mc = loggerToMonitoringContext(this.logger);\n\n\t\t[this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n\t\tthis.attachListeners();\n\t}\n\n\t/**\n\t * This function is only supposed to be called from SharedObjectCore's constructor and\n\t * depends on a few things being set already. assert() calls make sure of it.\n\t * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n\t * to variables to avoid complaints from TypeScript.\n\t */\n\tprivate setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n\t\tassert(\n\t\t\tthis.mc !== undefined && this.logger !== undefined,\n\t\t\t0x349 /* this.mc and/or this.logger has not been set */,\n\t\t);\n\t\tconst opProcessingHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsOpProcessing\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t\tnew Map<string, ITelemetryProperties>([\n\t\t\t\t[\"local\", { localOp: true }],\n\t\t\t\t[\"remote\", { localOp: false }],\n\t\t\t]),\n\t\t);\n\t\tconst callbacksHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsEventCallbacks\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t);\n\n\t\tthis.runtime.once(\"dispose\", () => {\n\t\t\tthis.callbacksHelper.dispose();\n\t\t\tthis.opProcessingHelper.dispose();\n\t\t});\n\n\t\treturn [opProcessingHelper, callbacksHelper];\n\t}\n\n\t/**\n\t * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n\t * would result in same error thrown. If called multiple times, only first error is remembered.\n\t * @param error - error object that is thrown whenever an attempt is made to modify this object\n\t */\n\tprivate closeWithError(error: any) {\n\t\tif (this.closeError === undefined) {\n\t\t\tthis.closeError = error;\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n\t */\n\tprivate verifyNotClosed() {\n\t\tif (this.closeError !== undefined) {\n\t\t\tthrow this.closeError;\n\t\t}\n\t}\n\n\t/**\n\t * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n\t * It wraps error with DataProcessingError, closes this object and throws resulting error.\n\t * See closeWithError() for more details\n\t * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n\t * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n\t * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n\t * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n\t * allow processing of ops or local changes, which very quickly results in container closure.\n\t */\n\tprivate eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n\t\tconst error = DataProcessingError.wrapIfUnrecognized(\n\t\t\te,\n\t\t\t\"SharedObjectEventListenerException\",\n\t\t);\n\t\terror.addTelemetryProperties({ emittedEventName: String(event) });\n\n\t\tthis.closeWithError(error);\n\t\tthrow error;\n\t}\n\n\tprivate attachListeners() {\n\t\t// Only listen to these events if not attached.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.runtime.once(\"attaching\", () => {\n\t\t\t\t// Calling this will let the dds to do any custom processing based on attached\n\t\t\t\t// like starting generating ops.\n\t\t\t\tthis.didAttach();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * A shared object, after construction, can either be loaded in the case that it is already part of\n\t * a shared document. Or later attached if it is being newly added.\n\t * @param services - Services used by the shared object\n\t */\n\tpublic async load(services: IChannelServices): Promise<void> {\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.services = services;\n\t\t}\n\t\tawait this.loadCore(services.objectStorage);\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.attachDeltaHandler();\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the object as a local, non-shared object. This object can become shared after\n\t * it is attached to the document.\n\t */\n\tpublic initializeLocal(): void {\n\t\tthis.initializeLocalCore();\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).bindToContext}\n\t */\n\tpublic bindToContext(): void {\n\t\tif (this._isBoundToContext) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._isBoundToContext = true;\n\n\t\tthis.runtime.bindChannel(this);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n\t */\n\tpublic connect(services: IChannelServices) {\n\t\tthis.services = services;\n\t\tthis.attachDeltaHandler();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n\t */\n\tpublic isAttached(): boolean {\n\t\treturn this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic abstract getAttachSummary(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic abstract summarize(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n\t/**\n\t * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n\t * to another object in the container.\n\t * @param decodedHandle - The handle of the Fluid object that is decoded.\n\t */\n\tprotected handleDecoded(decodedHandle: IFluidHandle) {\n\t\tif (this.isAttached()) {\n\t\t\t// This represents an outbound reference from this object to the node represented by decodedHandle.\n\t\t\tthis.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n\t\t}\n\t}\n\n\t/**\n\t * Allows the distributed data type to perform custom loading\n\t * @param services - Storage used by the shared object\n\t */\n\tprotected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n\t/**\n\t * Allows the distributed data type to perform custom local loading.\n\t */\n\tprotected initializeLocalCore() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n\t * Also called after non-local data type get loaded.\n\t */\n\tprotected didAttach() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Derived classes must override this to do custom processing on a remote message.\n\t * @param message - The message to process\n\t * @param local - True if the shared object is local\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected abstract processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t);\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected abstract onDisconnect();\n\n\t/**\n\t * Submits a message by the local client to the runtime.\n\t * @param content - Content of the message\n\t * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n\t * and not sent to the server. This will be sent back when this message is received back from the server. This is\n\t * also sent if we are asked to resubmit the message.\n\t */\n\tprotected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n\t\tthis.verifyNotClosed();\n\t\tif (this.isAttached()) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.services!.deltaConnection.submit(content, localOpMetadata);\n\t\t}\n\t}\n\n\t/**\n\t * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n\t * that want to be part of summary but does not generate ops.\n\t */\n\tprotected dirty(): void {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.services!.deltaConnection.dirty();\n\t}\n\n\t/**\n\t * Called when the object has fully connected to the delta stream\n\t * Default implementation for DDS, override if different behavior is required.\n\t */\n\tprotected onConnect() {}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n\t * The default implementation here is to resubmit the same message. The client can override if different behavior\n\t * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n\t * anything at all.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tthis.submitLocalMessage(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n\t * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n\t * the Promise will reject.\n\t * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n\t */\n\tprotected async newAckBasedPromise<T>(\n\t\texecutor: (\n\t\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\t\treject: (reason?: any) => void,\n\t\t) => void,\n\t): Promise<T> {\n\t\tlet rejectBecauseDispose: () => void;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\trejectBecauseDispose = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\tif (this.runtime.disposed) {\n\t\t\t\trejectBecauseDispose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.runtime.on(\"dispose\", rejectBecauseDispose);\n\t\t\texecutor(resolve, reject);\n\t\t}).finally(() => {\n\t\t\t// Note: rejectBecauseDispose will never be undefined here\n\t\t\tthis.runtime.off(\"dispose\", rejectBecauseDispose);\n\t\t});\n\t}\n\n\tprivate attachDeltaHandler() {\n\t\t// Services should already be there in case we are attaching delta handler.\n\t\tassert(\n\t\t\tthis.services !== undefined,\n\t\t\t0x07a /* \"Services should be there to attach delta handler\" */,\n\t\t);\n\t\tthis._isBoundToContext = true;\n\t\t// Allows objects to do any custom processing if it is attached.\n\t\tthis.didAttach();\n\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.services.deltaConnection.attach({\n\t\t\tprocess: (\n\t\t\t\tmessage: ISequencedDocumentMessage,\n\t\t\t\tlocal: boolean,\n\t\t\t\tlocalOpMetadata: unknown,\n\t\t\t) => {\n\t\t\t\tthis.process(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tsetConnectionState: (connected: boolean) => {\n\t\t\t\tthis.setConnectionState(connected);\n\t\t\t},\n\t\t\treSubmit: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.reSubmit(content, localOpMetadata);\n\t\t\t},\n\t\t\tapplyStashedOp: (content: any): unknown => {\n\t\t\t\treturn this.applyStashedOp(content);\n\t\t\t},\n\t\t\trollback: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.rollback(content, localOpMetadata);\n\t\t\t},\n\t\t});\n\n\t\t// Trigger initial state\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.setConnectionState(this.services.deltaConnection.connected);\n\t}\n\n\t/**\n\t * Set the state of connection to services.\n\t * @param connected - true if connected, false otherwise.\n\t */\n\tprivate setConnectionState(connected: boolean) {\n\t\tif (this._connected === connected) {\n\t\t\t// Not changing state, nothing the same.\n\t\t\treturn;\n\t\t}\n\n\t\t// Should I change the state at the end? So that we *can't* send new stuff before we send old?\n\t\tthis._connected = connected;\n\n\t\tif (!connected) {\n\t\t\t// Things that are true now...\n\t\t\t// - if we had a connection we can no longer send messages over it\n\t\t\t// - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n\t\t\t//\n\t\t\t// - nack could get a new msn - but might as well do it in the join?\n\t\t\tthis.onDisconnect();\n\t\t} else {\n\t\t\t// Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n\t\t\t// messages will work.\n\t\t\tthis.onConnect();\n\t\t}\n\t}\n\n\t/**\n\t * Handles a message being received from the remote delta server.\n\t * @param message - The message to process\n\t * @param local - Whether the message originated from the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprivate process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tthis.verifyNotClosed(); // This will result in container closure.\n\t\tthis.emitInternal(\"pre-op\", message, local, this);\n\n\t\tthis.opProcessingHelper.measure(\n\t\t\t() => {\n\t\t\t\tthis.processCore(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tlocal ? \"local\" : \"remote\",\n\t\t);\n\n\t\tthis.emitInternal(\"op\", message, local, this);\n\t}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n\t * reconnection.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprivate reSubmit(content: any, localOpMetadata: unknown) {\n\t\tthis.reSubmitCore(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown) {\n\t\tthrow new Error(\"rollback not supported\");\n\t}\n\n\t/**\n\t * Apply changes from an op. Used when rehydrating an attached container\n\t * with pending changes. This prepares the SharedObject for seeing an ACK\n\t * for the op or resubmitting the op upon reconnection.\n\t * @param content - Contents of a stashed op.\n\t * @returns localMetadata of the op, to be passed to process() or resubmit()\n\t * when the op is ACKed or resubmitted, respectively\n\t */\n\tprotected abstract applyStashedOp(content: any): unknown;\n\n\t/**\n\t * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n\t * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n\t * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n\t * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n\t * future.\n\t *\n\t * @internal\n\t *\n\t * @param event - The event to emit.\n\t * @param args - Arguments to pass to the event listeners.\n\t * @returns `true` if the event had listeners, `false` otherwise.\n\t */\n\tpublic emit(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn this.callbacksHelper.measure(() => {\n\t\t\t// Creating ops while handling a DDS event can lead\n\t\t\t// to undefined behavior and events observed in the wrong order.\n\t\t\t// For example, we have two callbacks registered for a DDS, A and B.\n\t\t\t// Then if on change #1 callback A creates change #2, the invocation flow will be:\n\t\t\t//\n\t\t\t// A because of #1\n\t\t\t// A because of #2\n\t\t\t// B because of #2\n\t\t\t// B because of #1\n\t\t\t//\n\t\t\t// The runtime must enforce op coherence by not allowing any ops to be created during\n\t\t\t// the event handler\n\t\t\treturn this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));\n\t\t});\n\t}\n\n\t/**\n\t * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n\t * done on the duration of the callbacks. Simply calls `super.emit()`.\n\t * @param event - Event to emit\n\t * @param args - Arguments for the event\n\t * @returns Whatever `super.emit()` returns.\n\t */\n\tprivate emitInternal(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn super.emit(event, ...args);\n\t}\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<\n\tTEvent extends ISharedObjectEvents = ISharedObjectEvents,\n> extends SharedObjectCore<TEvent> {\n\t/**\n\t * True while we are garbage collecting this object's data.\n\t */\n\tprivate _isGCing: boolean = false;\n\n\t/**\n\t * The serializer to use to serialize / parse handles, if any.\n\t */\n\tprivate readonly _serializer: IFluidSerializer;\n\n\tprotected get serializer(): IFluidSerializer {\n\t\t/**\n\t\t * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n\t\t * handles represent references to other Fluid objects.\n\t\t *\n\t\t * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n\t\t * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n\t\t */\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */,\n\t\t);\n\t\treturn this._serializer;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly telemetryContextPrefix: string,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis._serializer = new FluidSerializer(\n\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic getAttachSummary(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst result = this.summarizeCore(this.serializer, telemetryContext);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic async summarize(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): Promise<ISummaryTreeWithStats> {\n\t\tconst result = this.summarizeCore(\n\t\t\tthis.serializer,\n\t\t\ttelemetryContext,\n\t\t\tincrementalSummaryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\t// Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n\t\t// in this object's data.\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */,\n\t\t);\n\t\tthis._isGCing = true;\n\n\t\tlet gcData: IGarbageCollectionData;\n\t\ttry {\n\t\t\tconst serializer = new SummarySerializer(\n\t\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t\t);\n\t\t\tthis.processGCDataCore(serializer);\n\t\t\t// The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n\t\t\t// routes of handles serialized during summarization.\n\t\t\tgcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n\t\t\tassert(\n\t\t\t\tthis._isGCing,\n\t\t\t\t0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis._isGCing = false;\n\t\t}\n\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * Calls the serializer over all data in this object that reference other GC nodes.\n\t * Derived classes must override this to provide custom list of references to other GC nodes.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\t// We run the full summarize logic to get the list of outbound routes from this object. This is a little\n\t\t// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n\t\t// See: https://github.com/microsoft/FluidFramework/issues/4547\n\t\tthis.summarizeCore(serializer);\n\t}\n\n\t/**\n\t * Gets a form of the object that can be serialized.\n\t * @returns A tree representing the snapshot of the shared object.\n\t */\n\tprotected abstract summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\tprivate incrementTelemetryMetric(\n\t\tpropertyName: string,\n\t\tincrementBy: number,\n\t\ttelemetryContext?: ITelemetryContext,\n\t) {\n\t\tconst prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ??\n\t\t\t0) as number;\n\t\ttelemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n\t}\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,EAEN,iBAAiB,EACjB,6BAA6B,EAC7B,yBAAyB,EAEzB,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,MAAM,EAAyB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AASpE,OAAO,EAIN,qBAAqB,EACrB,yBAA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nB,gBAAoC;QAEpC,MAAM,SAAS,GAAG,CAAC,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC;YAClF,CAAC,CAAW,CAAC;QACd,gBAAgB,EAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC3F,CAAC;CACD","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 { ITelemetryProperties } from \"@fluidframework/common-definitions\";\nimport {\n\tITelemetryLoggerExt,\n\tcreateChildLogger,\n\tEventEmitterWithErrorHandling,\n\tloggerToMonitoringContext,\n\tMonitoringContext,\n\tSampledTelemetryHelper,\n\ttagCodeArtifacts,\n} from \"@fluidframework/telemetry-utils\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n\tIChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\tblobCountPropertyName,\n\ttotalBlobSizePropertyName,\n\tIExperimentalIncrementalSummaryContext,\n} from \"@fluidframework/runtime-definitions\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive.\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n\textends EventEmitterWithErrorHandling<TEvent>\n\timplements ISharedObject<TEvent>\n{\n\tpublic get IFluidLoadable() {\n\t\treturn this;\n\t}\n\n\tprivate readonly opProcessingHelper: SampledTelemetryHelper;\n\tprivate readonly callbacksHelper: SampledTelemetryHelper;\n\n\t/**\n\t * The handle referring to this SharedObject\n\t */\n\tpublic readonly handle: IFluidHandle;\n\n\t/**\n\t * Telemetry logger for the shared object\n\t */\n\tprotected readonly logger: ITelemetryLoggerExt;\n\tprivate readonly mc: MonitoringContext;\n\n\t/**\n\t * Connection state\n\t */\n\tprivate _connected = false;\n\n\t/**\n\t * Services used by the shared object\n\t */\n\tprivate services: IChannelServices | undefined;\n\n\t/**\n\t * True if the dds is bound to its parent.\n\t */\n\tprivate _isBoundToContext: boolean = false;\n\n\t/**\n\t * Tracks error that closed this object.\n\t */\n\tprivate closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n\t/**\n\t * Gets the connection state\n\t * @returns The state of the connection\n\t */\n\tpublic get connected(): boolean {\n\t\treturn this._connected;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tpublic id: string,\n\t\tprotected runtime: IFluidDataStoreRuntime,\n\t\tpublic readonly attributes: IChannelAttributes,\n\t) {\n\t\tsuper((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n\t\tassert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n\t\tthis.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);\n\n\t\tthis.logger = createChildLogger({\n\t\t\tlogger: runtime.logger,\n\t\t\tproperties: {\n\t\t\t\tall: {\n\t\t\t\t\tsharedObjectId: uuid(),\n\t\t\t\t\t...tagCodeArtifacts({\n\t\t\t\t\t\tddsType: this.attributes.type,\n\t\t\t\t\t}),\n\t\t\t\t},\n\t\t\t},\n\t\t});\n\t\tthis.mc = loggerToMonitoringContext(this.logger);\n\n\t\t[this.opProcessingHelper, this.callbacksHelper] = this.setUpSampledTelemetryHelpers();\n\n\t\tthis.attachListeners();\n\t}\n\n\t/**\n\t * This function is only supposed to be called from SharedObjectCore's constructor and\n\t * depends on a few things being set already. assert() calls make sure of it.\n\t * @returns The telemetry sampling helpers, so the constructor can be the one to assign them\n\t * to variables to avoid complaints from TypeScript.\n\t */\n\tprivate setUpSampledTelemetryHelpers(): SampledTelemetryHelper[] {\n\t\tassert(\n\t\t\tthis.mc !== undefined && this.logger !== undefined,\n\t\t\t0x349 /* this.mc and/or this.logger has not been set */,\n\t\t);\n\t\tconst opProcessingHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsOpProcessing\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.OpProcessingTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t\tnew Map<string, ITelemetryProperties>([\n\t\t\t\t[\"local\", { localOp: true }],\n\t\t\t\t[\"remote\", { localOp: false }],\n\t\t\t]),\n\t\t);\n\t\tconst callbacksHelper = new SampledTelemetryHelper(\n\t\t\t{\n\t\t\t\teventName: \"ddsEventCallbacks\",\n\t\t\t\tcategory: \"performance\",\n\t\t\t},\n\t\t\tthis.logger,\n\t\t\tthis.mc.config.getNumber(\"Fluid.SharedObject.DdsCallbacksTelemetrySampling\") ?? 1000,\n\t\t\ttrue,\n\t\t);\n\n\t\tthis.runtime.once(\"dispose\", () => {\n\t\t\tthis.callbacksHelper.dispose();\n\t\t\tthis.opProcessingHelper.dispose();\n\t\t});\n\n\t\treturn [opProcessingHelper, callbacksHelper];\n\t}\n\n\t/**\n\t * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n\t * would result in same error thrown. If called multiple times, only first error is remembered.\n\t * @param error - error object that is thrown whenever an attempt is made to modify this object\n\t */\n\tprivate closeWithError(error: any) {\n\t\tif (this.closeError === undefined) {\n\t\t\tthis.closeError = error;\n\t\t}\n\t}\n\n\t/**\n\t * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n\t */\n\tprivate verifyNotClosed() {\n\t\tif (this.closeError !== undefined) {\n\t\t\tthrow this.closeError;\n\t\t}\n\t}\n\n\t/**\n\t * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n\t * It wraps error with DataProcessingError, closes this object and throws resulting error.\n\t * See closeWithError() for more details\n\t * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n\t * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n\t * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n\t * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n\t * allow processing of ops or local changes, which very quickly results in container closure.\n\t */\n\tprivate eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n\t\tconst error = DataProcessingError.wrapIfUnrecognized(\n\t\t\te,\n\t\t\t\"SharedObjectEventListenerException\",\n\t\t);\n\t\terror.addTelemetryProperties({ emittedEventName: String(event) });\n\n\t\tthis.closeWithError(error);\n\t\tthrow error;\n\t}\n\n\tprivate attachListeners() {\n\t\t// Only listen to these events if not attached.\n\t\tif (!this.isAttached()) {\n\t\t\tthis.runtime.once(\"attaching\", () => {\n\t\t\t\t// Calling this will let the dds to do any custom processing based on attached\n\t\t\t\t// like starting generating ops.\n\t\t\t\tthis.didAttach();\n\t\t\t});\n\t\t}\n\t}\n\n\t/**\n\t * A shared object, after construction, can either be loaded in the case that it is already part of\n\t * a shared document. Or later attached if it is being newly added.\n\t * @param services - Services used by the shared object\n\t */\n\tpublic async load(services: IChannelServices): Promise<void> {\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.services = services;\n\t\t}\n\t\tawait this.loadCore(services.objectStorage);\n\t\tif (this.runtime.attachState !== AttachState.Detached) {\n\t\t\tthis.attachDeltaHandler();\n\t\t}\n\t}\n\n\t/**\n\t * Initializes the object as a local, non-shared object. This object can become shared after\n\t * it is attached to the document.\n\t */\n\tpublic initializeLocal(): void {\n\t\tthis.initializeLocalCore();\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).bindToContext}\n\t */\n\tpublic bindToContext(): void {\n\t\tif (this._isBoundToContext) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis._isBoundToContext = true;\n\n\t\tthis.runtime.bindChannel(this);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n\t */\n\tpublic connect(services: IChannelServices) {\n\t\tthis.services = services;\n\t\tthis.attachDeltaHandler();\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n\t */\n\tpublic isAttached(): boolean {\n\t\treturn this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic abstract getAttachSummary(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic abstract summarize(\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n\t/**\n\t * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n\t * to another object in the container.\n\t * @param decodedHandle - The handle of the Fluid object that is decoded.\n\t */\n\tprotected handleDecoded(decodedHandle: IFluidHandle) {\n\t\tif (this.isAttached()) {\n\t\t\t// This represents an outbound reference from this object to the node represented by decodedHandle.\n\t\t\tthis.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n\t\t}\n\t}\n\n\t/**\n\t * Allows the distributed data type to perform custom loading\n\t * @param services - Storage used by the shared object\n\t */\n\tprotected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n\t/**\n\t * Allows the distributed data type to perform custom local loading.\n\t */\n\tprotected initializeLocalCore() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n\t * Also called after non-local data type get loaded.\n\t */\n\tprotected didAttach() {\n\t\treturn;\n\t}\n\n\t/**\n\t * Derived classes must override this to do custom processing on a remote message.\n\t * @param message - The message to process\n\t * @param local - True if the shared object is local\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprotected abstract processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t);\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected abstract onDisconnect();\n\n\t/**\n\t * Submits a message by the local client to the runtime.\n\t * @param content - Content of the message\n\t * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n\t * and not sent to the server. This will be sent back when this message is received back from the server. This is\n\t * also sent if we are asked to resubmit the message.\n\t */\n\tprotected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n\t\tthis.verifyNotClosed();\n\t\tif (this.isAttached()) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tthis.services!.deltaConnection.submit(content, localOpMetadata);\n\t\t}\n\t}\n\n\t/**\n\t * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n\t * that want to be part of summary but does not generate ops.\n\t */\n\tprotected dirty(): void {\n\t\tif (!this.isAttached()) {\n\t\t\treturn;\n\t\t}\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tthis.services!.deltaConnection.dirty();\n\t}\n\n\t/**\n\t * Called when the object has fully connected to the delta stream\n\t * Default implementation for DDS, override if different behavior is required.\n\t */\n\tprotected onConnect() {}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n\t * The default implementation here is to resubmit the same message. The client can override if different behavior\n\t * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n\t * anything at all.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprotected reSubmitCore(content: any, localOpMetadata: unknown) {\n\t\tthis.submitLocalMessage(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n\t * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n\t * the Promise will reject.\n\t * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n\t */\n\tprotected async newAckBasedPromise<T>(\n\t\texecutor: (\n\t\t\tresolve: (value: T | PromiseLike<T>) => void,\n\t\t\treject: (reason?: any) => void,\n\t\t) => void,\n\t): Promise<T> {\n\t\tlet rejectBecauseDispose: () => void;\n\t\treturn new Promise<T>((resolve, reject) => {\n\t\t\trejectBecauseDispose = () =>\n\t\t\t\treject(\n\t\t\t\t\tnew Error(\n\t\t\t\t\t\t\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\",\n\t\t\t\t\t),\n\t\t\t\t);\n\n\t\t\tif (this.runtime.disposed) {\n\t\t\t\trejectBecauseDispose();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tthis.runtime.on(\"dispose\", rejectBecauseDispose);\n\t\t\texecutor(resolve, reject);\n\t\t}).finally(() => {\n\t\t\t// Note: rejectBecauseDispose will never be undefined here\n\t\t\tthis.runtime.off(\"dispose\", rejectBecauseDispose);\n\t\t});\n\t}\n\n\tprivate attachDeltaHandler() {\n\t\t// Services should already be there in case we are attaching delta handler.\n\t\tassert(\n\t\t\tthis.services !== undefined,\n\t\t\t0x07a /* \"Services should be there to attach delta handler\" */,\n\t\t);\n\t\tthis._isBoundToContext = true;\n\t\t// Allows objects to do any custom processing if it is attached.\n\t\tthis.didAttach();\n\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.services.deltaConnection.attach({\n\t\t\tprocess: (\n\t\t\t\tmessage: ISequencedDocumentMessage,\n\t\t\t\tlocal: boolean,\n\t\t\t\tlocalOpMetadata: unknown,\n\t\t\t) => {\n\t\t\t\tthis.process(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tsetConnectionState: (connected: boolean) => {\n\t\t\t\tthis.setConnectionState(connected);\n\t\t\t},\n\t\t\treSubmit: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.reSubmit(content, localOpMetadata);\n\t\t\t},\n\t\t\tapplyStashedOp: (content: any): unknown => {\n\t\t\t\treturn this.applyStashedOp(content);\n\t\t\t},\n\t\t\trollback: (content: any, localOpMetadata: unknown) => {\n\t\t\t\tthis.rollback(content, localOpMetadata);\n\t\t\t},\n\t\t});\n\n\t\t// Trigger initial state\n\t\t// attachDeltaHandler is only called after services is assigned\n\t\tthis.setConnectionState(this.services.deltaConnection.connected);\n\t}\n\n\t/**\n\t * Set the state of connection to services.\n\t * @param connected - true if connected, false otherwise.\n\t */\n\tprivate setConnectionState(connected: boolean) {\n\t\tif (this._connected === connected) {\n\t\t\t// Not changing state, nothing the same.\n\t\t\treturn;\n\t\t}\n\n\t\t// Should I change the state at the end? So that we *can't* send new stuff before we send old?\n\t\tthis._connected = connected;\n\n\t\tif (!connected) {\n\t\t\t// Things that are true now...\n\t\t\t// - if we had a connection we can no longer send messages over it\n\t\t\t// - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n\t\t\t//\n\t\t\t// - nack could get a new msn - but might as well do it in the join?\n\t\t\tthis.onDisconnect();\n\t\t} else {\n\t\t\t// Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n\t\t\t// messages will work.\n\t\t\tthis.onConnect();\n\t\t}\n\t}\n\n\t/**\n\t * Handles a message being received from the remote delta server.\n\t * @param message - The message to process\n\t * @param local - Whether the message originated from the local client\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be undefined.\n\t */\n\tprivate process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n\t\tthis.verifyNotClosed(); // This will result in container closure.\n\t\tthis.emitInternal(\"pre-op\", message, local, this);\n\n\t\tthis.opProcessingHelper.measure(\n\t\t\t() => {\n\t\t\t\tthis.processCore(message, local, localOpMetadata);\n\t\t\t},\n\t\t\tlocal ? \"local\" : \"remote\",\n\t\t);\n\n\t\tthis.emitInternal(\"op\", message, local, this);\n\t}\n\n\t/**\n\t * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n\t * reconnection.\n\t * @param content - The content of the original message.\n\t * @param localOpMetadata - The local metadata associated with the original message.\n\t */\n\tprivate reSubmit(content: any, localOpMetadata: unknown) {\n\t\tthis.reSubmitCore(content, localOpMetadata);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tprotected rollback(content: any, localOpMetadata: unknown) {\n\t\tthrow new Error(\"rollback not supported\");\n\t}\n\n\t/**\n\t * Apply changes from an op. Used when rehydrating an attached container\n\t * with pending changes. This prepares the SharedObject for seeing an ACK\n\t * for the op or resubmitting the op upon reconnection.\n\t * @param content - Contents of a stashed op.\n\t * @returns localMetadata of the op, to be passed to process() or resubmit()\n\t * when the op is ACKed or resubmitted, respectively\n\t */\n\tprotected abstract applyStashedOp(content: any): unknown;\n\n\t/**\n\t * Emit an event. This function is only intended for use by DDS classes that extend SharedObject/SharedObjectCore,\n\t * specifically to emit events that are part of the public interface of the DDS (i.e. those that can have listeners\n\t * attached to them by the consumers of the DDS). It should not be called from outside the class or to emit events\n\t * which are only internal to the DDS. Support for calling it from outside the DDS instance might be removed in the\n\t * future.\n\t *\n\t * @internal\n\t *\n\t * @param event - The event to emit.\n\t * @param args - Arguments to pass to the event listeners.\n\t * @returns `true` if the event had listeners, `false` otherwise.\n\t */\n\tpublic emit(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn this.callbacksHelper.measure(() => {\n\t\t\t// Creating ops while handling a DDS event can lead\n\t\t\t// to undefined behavior and events observed in the wrong order.\n\t\t\t// For example, we have two callbacks registered for a DDS, A and B.\n\t\t\t// Then if on change #1 callback A creates change #2, the invocation flow will be:\n\t\t\t//\n\t\t\t// A because of #1\n\t\t\t// A because of #2\n\t\t\t// B because of #2\n\t\t\t// B because of #1\n\t\t\t//\n\t\t\t// The runtime must enforce op coherence by not allowing any ops to be created during\n\t\t\t// the event handler\n\t\t\treturn this.runtime.ensureNoDataModelChanges(() => super.emit(event, ...args));\n\t\t});\n\t}\n\n\t/**\n\t * Use to emit events inside {@link SharedObjectCore}, with no telemetry measurement\n\t * done on the duration of the callbacks. Simply calls `super.emit()`.\n\t * @param event - Event to emit\n\t * @param args - Arguments for the event\n\t * @returns Whatever `super.emit()` returns.\n\t */\n\tprivate emitInternal(event: EventEmitterEventType, ...args: any[]): boolean {\n\t\treturn super.emit(event, ...args);\n\t}\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<\n\tTEvent extends ISharedObjectEvents = ISharedObjectEvents,\n> extends SharedObjectCore<TEvent> {\n\t/**\n\t * True while we are garbage collecting this object's data.\n\t */\n\tprivate _isGCing: boolean = false;\n\n\t/**\n\t * The serializer to use to serialize / parse handles, if any.\n\t */\n\tprivate readonly _serializer: IFluidSerializer;\n\n\tprotected get serializer(): IFluidSerializer {\n\t\t/**\n\t\t * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n\t\t * handles represent references to other Fluid objects.\n\t\t *\n\t\t * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n\t\t * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n\t\t */\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */,\n\t\t);\n\t\treturn this._serializer;\n\t}\n\n\t/**\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t */\n\tconstructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\tprivate readonly telemetryContextPrefix: string,\n\t) {\n\t\tsuper(id, runtime, attributes);\n\n\t\tthis._serializer = new FluidSerializer(\n\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t);\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t */\n\tpublic getAttachSummary(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst result = this.summarizeCore(this.serializer, telemetryContext);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t */\n\tpublic async summarize(\n\t\tfullTree: boolean = false,\n\t\ttrackState: boolean = false,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): Promise<ISummaryTreeWithStats> {\n\t\tconst result = this.summarizeCore(\n\t\t\tthis.serializer,\n\t\t\ttelemetryContext,\n\t\t\tincrementalSummaryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\tblobCountPropertyName,\n\t\t\tresult.stats.blobNodeCount,\n\t\t\ttelemetryContext,\n\t\t);\n\t\tthis.incrementTelemetryMetric(\n\t\t\ttotalBlobSizePropertyName,\n\t\t\tresult.stats.totalBlobSize,\n\t\t\ttelemetryContext,\n\t\t);\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\tpublic getGCData(fullGC: boolean = false): IGarbageCollectionData {\n\t\t// Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n\t\t// in this object's data.\n\t\tassert(\n\t\t\t!this._isGCing,\n\t\t\t0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */,\n\t\t);\n\t\tthis._isGCing = true;\n\n\t\tlet gcData: IGarbageCollectionData;\n\t\ttry {\n\t\t\tconst serializer = new SummarySerializer(\n\t\t\t\tthis.runtime.channelsRoutingContext,\n\t\t\t\t(handle: IFluidHandle) => this.handleDecoded(handle),\n\t\t\t);\n\t\t\tthis.processGCDataCore(serializer);\n\t\t\t// The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n\t\t\t// routes of handles serialized during summarization.\n\t\t\tgcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n\t\t\tassert(\n\t\t\t\tthis._isGCing,\n\t\t\t\t0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */,\n\t\t\t);\n\t\t} finally {\n\t\t\tthis._isGCing = false;\n\t\t}\n\n\t\treturn gcData;\n\t}\n\n\t/**\n\t * Calls the serializer over all data in this object that reference other GC nodes.\n\t * Derived classes must override this to provide custom list of references to other GC nodes.\n\t */\n\tprotected processGCDataCore(serializer: SummarySerializer) {\n\t\t// We run the full summarize logic to get the list of outbound routes from this object. This is a little\n\t\t// expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n\t\t// See: https://github.com/microsoft/FluidFramework/issues/4547\n\t\tthis.summarizeCore(serializer);\n\t}\n\n\t/**\n\t * Gets a form of the object that can be serialized.\n\t * @returns A tree representing the snapshot of the shared object.\n\t */\n\tprotected abstract summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\tprivate incrementTelemetryMetric(\n\t\tpropertyName: string,\n\t\tincrementBy: number,\n\t\ttelemetryContext?: ITelemetryContext,\n\t) {\n\t\tconst prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ??\n\t\t\t0) as number;\n\t\ttelemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/shared-object-base",
|
|
3
|
-
"version": "2.0.0-internal.
|
|
3
|
+
"version": "2.0.0-internal.6.1.0",
|
|
4
4
|
"description": "Fluid base class for shared distributed data structures",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -37,26 +37,26 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@fluidframework/common-definitions": "^0.20.1",
|
|
39
39
|
"@fluidframework/common-utils": "^1.1.1",
|
|
40
|
-
"@fluidframework/container-definitions": ">=2.0.0-internal.
|
|
41
|
-
"@fluidframework/container-runtime": ">=2.0.0-internal.
|
|
42
|
-
"@fluidframework/container-utils": ">=2.0.0-internal.
|
|
43
|
-
"@fluidframework/core-interfaces": ">=2.0.0-internal.
|
|
44
|
-
"@fluidframework/datastore": ">=2.0.0-internal.
|
|
45
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-internal.
|
|
40
|
+
"@fluidframework/container-definitions": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
41
|
+
"@fluidframework/container-runtime": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
42
|
+
"@fluidframework/container-utils": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
43
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
44
|
+
"@fluidframework/datastore": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
45
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
46
46
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
47
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-internal.
|
|
48
|
-
"@fluidframework/runtime-utils": ">=2.0.0-internal.
|
|
49
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-internal.
|
|
47
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
48
|
+
"@fluidframework/runtime-utils": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
49
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
50
50
|
"uuid": "^8.3.1"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
|
-
"@fluid-tools/build-cli": "^0.
|
|
54
|
-
"@fluidframework/build-common": "^
|
|
55
|
-
"@fluidframework/build-tools": "^0.
|
|
53
|
+
"@fluid-tools/build-cli": "^0.22.0",
|
|
54
|
+
"@fluidframework/build-common": "^2.0.0",
|
|
55
|
+
"@fluidframework/build-tools": "^0.22.0",
|
|
56
56
|
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
57
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.
|
|
58
|
-
"@fluidframework/shared-object-base-previous": "npm:@fluidframework/shared-object-base@2.0.0-internal.
|
|
59
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.
|
|
57
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
58
|
+
"@fluidframework/shared-object-base-previous": "npm:@fluidframework/shared-object-base@2.0.0-internal.6.0.0",
|
|
59
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.1.0 <2.0.0-internal.6.2.0",
|
|
60
60
|
"@microsoft/api-extractor": "^7.34.4",
|
|
61
61
|
"@types/benchmark": "^2.1.0",
|
|
62
62
|
"@types/mocha": "^9.1.1",
|
package/src/packageVersion.ts
CHANGED
|
@@ -27,6 +27,9 @@ import {
|
|
|
27
27
|
* IFluidHandle can be retrieved by calling `get` on it.
|
|
28
28
|
*/
|
|
29
29
|
export class RemoteFluidObjectHandle implements IFluidHandle {
|
|
30
|
+
/**
|
|
31
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
32
|
+
*/
|
|
30
33
|
public get IFluidRouter() {
|
|
31
34
|
return this;
|
|
32
35
|
}
|
|
@@ -83,6 +86,9 @@ export class RemoteFluidObjectHandle implements IFluidHandle {
|
|
|
83
86
|
handle.attachGraph();
|
|
84
87
|
}
|
|
85
88
|
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated - Will be removed in future major release. Migrate all usage of IFluidRouter to the "entryPoint" pattern. Refer to Removing-IFluidRouter.md
|
|
91
|
+
*/
|
|
86
92
|
public async request(request: IRequest): Promise<IResponse> {
|
|
87
93
|
try {
|
|
88
94
|
const object: FluidObject<IFluidRouter> = await this.get();
|