@fluidframework/shared-object-base 0.59.4001 → 1.1.0-75972

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/.eslintrc.js CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  module.exports = {
7
7
  "extends": [
8
- "@fluidframework/eslint-config-fluid"
8
+ require.resolve("@fluidframework/eslint-config-fluid")
9
9
  ],
10
10
  "parserOptions": {
11
11
  "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/shared-object-base";
8
- export declare const pkgVersion = "0.59.4001";
8
+ export declare const pkgVersion = "1.1.0-75972";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,cAAc,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,gBAAgB,CAAC"}
@@ -8,5 +8,5 @@
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.pkgVersion = exports.pkgName = void 0;
10
10
  exports.pkgName = "@fluidframework/shared-object-base";
11
- exports.pkgVersion = "0.59.4001";
11
+ exports.pkgVersion = "1.1.0-75972";
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,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"0.59.4001\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,oCAAoC,CAAC;AAC/C,QAAA,UAAU,GAAG,aAAa,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 = \"1.1.0-75972\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGpF;;GAEG;AACF,MAAM,WAAW,iBAAiB;IAE/B,IAAI,EAAE,kBAAkB,CAAC;IAGzB,GAAG,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,UAAW,GAAG,+BACP,CAAC;AAEvC,MAAM,WAAW,gBAAgB;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,GAAG,CAAC;IAE5C;;;;;;;;OAQG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IAExB;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAElD;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;OAQG;IACH,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,GAAG,CAAC;IAExB;;OAEG;IACH,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAAC;IAElD;;;OAGG;IACH,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC;CAC7B;AAED;;GAEG;AACH,qBAAa,eAAgB,YAAW,gBAAgB;IAIhD,OAAO,CAAC,QAAQ,CAAC,OAAO;IAExB,OAAO,CAAC,QAAQ,CAAC,cAAc;IALnC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAsB;gBAGtB,OAAO,EAAE,mBAAmB,EAE5B,cAAc,EAAE,CAAC,MAAM,EAAE,YAAY,KAAK,IAAI;IAQnE,IAAW,gBAAgB,SAAmB;IAE9C;;;;;;;;OAQG;IACK,MAAM,CACV,KAAK,EAAE,GAAG,EACV,IAAI,EAAE,YAAY;IAUtB;;;;;;;;OAQG;IACK,MAAM,CAAC,KAAK,EAAE,GAAG;IASlB,SAAS,CAAC,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,YAAY;IAKxC,KAAK,CAAC,KAAK,EAAE,MAAM;IAM1B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAQ1B;IAIF,OAAO,CAAC,QAAQ,CAAC,WAAW,CAe1B;IAKF,OAAO,CAAC,kBAAkB;IA+C1B,SAAS,CAAC,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY;;;;CAOrE"}
@@ -110,7 +110,6 @@ class FluidSerializer {
110
110
  return maybeReplaced;
111
111
  }
112
112
  // Otherwise descend into the object graph looking for IFluidHandle instances.
113
- // eslint-disable-next-line @typescript-eslint/ban-types
114
113
  let clone;
115
114
  for (const key of Object.keys(input)) {
116
115
  const value = input[key];
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.js","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,iEAA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C1B,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC;IACN,CAAC;CACJ;AAzJD,0CAyJC","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 */\n export interface ISerializedHandle {\n // Marker to indicate to JSON.parse that the object is a Fluid handle\n type: \"__fluid_handle__\";\n\n // URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n url: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n value?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n /**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n */\n encode(value: any, bind: IFluidHandle): any;\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n decode(input: any): any;\n\n /**\n * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n */\n stringify(value: any, bind: IFluidHandle): string;\n\n /**\n * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n * handles will be realized as part of the parse\n */\n parse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n private readonly root: IFluidHandleContext;\n\n public constructor(\n private readonly context: IFluidHandleContext,\n // To be called whenever a handle is parsed by this serializer.\n private readonly handleParsedCb: (handle: IFluidHandle) => void,\n ) {\n this.root = this.context;\n while (this.root.routeContext !== undefined) {\n this.root = this.root.routeContext;\n }\n }\n\n public get IFluidSerializer() { return this; }\n\n /**\n * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * Any unbound handles encountered are bound to the provided IFluidHandle.\n */\n public encode(\n input: any,\n bind: IFluidHandle,\n ) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.encodeValue, bind)\n : input;\n }\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n public decode(input: any) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.decodeValue)\n : input;\n }\n\n public stringify(input: any, bind: IFluidHandle) {\n return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n }\n\n // Parses the serialized data - context must match the context with which the JSON was stringified\n public parse(input: string) {\n return JSON.parse(input, (key, value) => this.decodeValue(value));\n }\n\n // If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n private readonly encodeValue = (value: any, bind: IFluidHandle) => {\n // Detect if 'value' is an IFluidHandle.\n const handle = value?.IFluidHandle;\n\n // If 'value' is an IFluidHandle return its encoded form.\n return handle !== undefined\n ? this.serializeHandle(handle, bind)\n : value;\n };\n\n // If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n private readonly decodeValue = (value: any) => {\n // If 'value' is a serialized IFluidHandle return the deserialized result.\n if (isSerializedHandle(value)) {\n // Old documents may have handles with relative path in their summaries. Convert these to absolute\n // paths. This will ensure that future summaries will have absolute paths for these handles.\n const absolutePath = value.url.startsWith(\"/\")\n ? value.url\n : generateHandleContextPath(value.url, this.context);\n\n const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n this.handleParsedCb(parsedHandle);\n return parsedHandle;\n } else {\n return value;\n }\n };\n\n // Invoked for non-null objects to recursively replace references to IFluidHandles.\n // Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n // returns the original `input`.\n private recursivelyReplace(\n input: any,\n replacer: (input: any, context: any) => any,\n context?: any,\n ) {\n // Note: Caller is responsible for ensuring that `input` is defined / non-null.\n // (Required for Object.keys() below.)\n\n // Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n // is a non-null object.\n const maybeReplaced = replacer(input, context);\n\n // If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n // leaves in the object graph.\n if (maybeReplaced !== input) {\n return maybeReplaced;\n }\n\n // Otherwise descend into the object graph looking for IFluidHandle instances.\n // eslint-disable-next-line @typescript-eslint/ban-types\n let clone: object | undefined;\n for (const key of Object.keys(input)) {\n const value = input[key];\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!!value && typeof value === \"object\") {\n // Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n // be JSON serializable.) Therefore, guarding against infinite recursion here would only\n // lead to a later error when attempting to stringify().\n const replaced = this.recursivelyReplace(value, replacer, context);\n\n // If the `replaced` object is different than the original `value` then the subgraph contained one\n // or more handles. If this happens, we need to return a clone of the `input` object where the\n // current property is replaced by the `replaced` value.\n if (replaced !== value) {\n // Lazily create a shallow clone of the `input` object if we haven't done so already.\n clone = clone ?? (Array.isArray(input)\n ? [...input]\n : { ...input });\n\n // Overwrite the current property `key` in the clone with the `replaced` value.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n clone![key] = replaced;\n }\n }\n }\n return clone ?? input;\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n bind.bind(handle);\n return {\n type: \"__fluid_handle__\",\n url: handle.absolutePath,\n };\n }\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,CACzE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AAD1B,QAAA,kBAAkB,sBACQ;AAmCvC;;GAEG;AACH,MAAa,eAAe;IAGxB,YACqB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QA0DnE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YAC9D,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS;gBACvB,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,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,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;oBACpB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;wBAClC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;wBACZ,CAAC,mBAAM,KAAK,CAAE,CAAC,CAAC;oBAEpB,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBAC1B;aACJ;SACJ;QACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC;IAC1B,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC;IACN,CAAC;CACJ;AAxJD,0CAwJC","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 */\n export interface ISerializedHandle {\n // Marker to indicate to JSON.parse that the object is a Fluid handle\n type: \"__fluid_handle__\";\n\n // URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n url: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n value?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n /**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n */\n encode(value: any, bind: IFluidHandle): any;\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n decode(input: any): any;\n\n /**\n * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n */\n stringify(value: any, bind: IFluidHandle): string;\n\n /**\n * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n * handles will be realized as part of the parse\n */\n parse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n private readonly root: IFluidHandleContext;\n\n public constructor(\n private readonly context: IFluidHandleContext,\n // To be called whenever a handle is parsed by this serializer.\n private readonly handleParsedCb: (handle: IFluidHandle) => void,\n ) {\n this.root = this.context;\n while (this.root.routeContext !== undefined) {\n this.root = this.root.routeContext;\n }\n }\n\n public get IFluidSerializer() { return this; }\n\n /**\n * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * Any unbound handles encountered are bound to the provided IFluidHandle.\n */\n public encode(\n input: any,\n bind: IFluidHandle,\n ) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.encodeValue, bind)\n : input;\n }\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n public decode(input: any) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.decodeValue)\n : input;\n }\n\n public stringify(input: any, bind: IFluidHandle) {\n return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n }\n\n // Parses the serialized data - context must match the context with which the JSON was stringified\n public parse(input: string) {\n return JSON.parse(input, (key, value) => this.decodeValue(value));\n }\n\n // If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n private readonly encodeValue = (value: any, bind: IFluidHandle) => {\n // Detect if 'value' is an IFluidHandle.\n const handle = value?.IFluidHandle;\n\n // If 'value' is an IFluidHandle return its encoded form.\n return handle !== undefined\n ? this.serializeHandle(handle, bind)\n : value;\n };\n\n // If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n private readonly decodeValue = (value: any) => {\n // If 'value' is a serialized IFluidHandle return the deserialized result.\n if (isSerializedHandle(value)) {\n // Old documents may have handles with relative path in their summaries. Convert these to absolute\n // paths. This will ensure that future summaries will have absolute paths for these handles.\n const absolutePath = value.url.startsWith(\"/\")\n ? value.url\n : generateHandleContextPath(value.url, this.context);\n\n const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n this.handleParsedCb(parsedHandle);\n return parsedHandle;\n } else {\n return value;\n }\n };\n\n // Invoked for non-null objects to recursively replace references to IFluidHandles.\n // Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n // returns the original `input`.\n private recursivelyReplace(\n input: any,\n replacer: (input: any, context: any) => any,\n context?: any,\n ) {\n // Note: Caller is responsible for ensuring that `input` is defined / non-null.\n // (Required for Object.keys() below.)\n\n // Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n // is a non-null object.\n const maybeReplaced = replacer(input, context);\n\n // If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n // leaves in the object graph.\n if (maybeReplaced !== input) {\n return maybeReplaced;\n }\n\n // Otherwise descend into the object graph looking for IFluidHandle instances.\n let clone: object | undefined;\n for (const key of Object.keys(input)) {\n const value = input[key];\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!!value && typeof value === \"object\") {\n // Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n // be JSON serializable.) Therefore, guarding against infinite recursion here would only\n // lead to a later error when attempting to stringify().\n const replaced = this.recursivelyReplace(value, replacer, context);\n\n // If the `replaced` object is different than the original `value` then the subgraph contained one\n // or more handles. If this happens, we need to return a clone of the `input` object where the\n // current property is replaced by the `replaced` value.\n if (replaced !== value) {\n // Lazily create a shallow clone of the `input` object if we haven't done so already.\n clone = clone ?? (Array.isArray(input)\n ? [...input]\n : { ...input });\n\n // Overwrite the current property `key` in the clone with the `replaced` value.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n clone![key] = replaced;\n }\n }\n }\n return clone ?? input;\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n bind.bind(handle);\n return {\n type: \"__fluid_handle__\",\n url: handle.absolutePath,\n };\n }\n}\n"]}
@@ -6,7 +6,7 @@ import { ITelemetryLogger } from "@fluidframework/common-definitions";
6
6
  import { IFluidHandle } from "@fluidframework/core-interfaces";
7
7
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelServices } from "@fluidframework/datastore-definitions";
8
8
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
9
- import { IGarbageCollectionData, ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
9
+ import { IGarbageCollectionData, ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
10
10
  import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
11
11
  import { IFluidSerializer } from "./serializer";
12
12
  import { SummarySerializer } from "./summarySerializer";
@@ -102,11 +102,11 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
102
102
  /**
103
103
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
104
104
  */
105
- abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
105
+ abstract getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
106
106
  /**
107
107
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
108
108
  */
109
- abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
109
+ abstract summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
110
110
  /**
111
111
  * {@inheritDoc (ISharedObject:interface).getGCData}
112
112
  */
@@ -198,6 +198,10 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
198
198
  * @param localOpMetadata - The local metadata associated with the original message.
199
199
  */
200
200
  private reSubmit;
201
+ /**
202
+ * Revert an op
203
+ */
204
+ protected rollback(content: any, localOpMetadata: unknown): void;
201
205
  /**
202
206
  * Apply changes from an op. Used when rehydrating an attached container
203
207
  * with pending changes. This prepares the SharedObject for seeing an ACK
@@ -213,6 +217,7 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
213
217
  * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.
214
218
  */
215
219
  export declare abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends SharedObjectCore<TEvent> {
220
+ private readonly telemetryContextPrefix;
216
221
  /**
217
222
  * True while we are garbage collecting this object's data.
218
223
  */
@@ -227,15 +232,15 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
227
232
  * @param runtime - The IFluidDataStoreRuntime which contains the shared object
228
233
  * @param attributes - Attributes of the shared object
229
234
  */
230
- constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
235
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, telemetryContextPrefix: string);
231
236
  /**
232
237
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
233
238
  */
234
- getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
239
+ getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
235
240
  /**
236
241
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
237
242
  */
238
- summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
243
+ summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
239
244
  /**
240
245
  * {@inheritDoc (ISharedObject:interface).getGCData}
241
246
  */
@@ -249,6 +254,7 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
249
254
  * Gets a form of the object that can be serialized.
250
255
  * @returns A tree representing the snapshot of the shared object.
251
256
  */
252
- protected abstract summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
257
+ protected abstract summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
258
+ private incrementTelemetryMetric;
253
259
  }
254
260
  //# sourceMappingURL=sharedObject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;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OAAO;CAC3D;AAED;;;GAGG;AACH,8BAAsB,YAAY,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CACvF,SAAQ,gBAAgB,CAAC,MAAM,CAAC;IAiC5B,OAAO,CAAC,QAAQ,CAAC,sBAAsB;IAhC3C;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAkB;IAElC;;OAEG;IACH,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAmB;IAE/C,SAAS,KAAK,UAAU,IAAI,gBAAgB,CAW3C;IAED;;;;OAIG;gBAEC,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,sBAAsB,EAC/B,UAAU,EAAE,kBAAkB,EACb,sBAAsB,EAAE,MAAM;IAUnD;;OAEG;IACI,gBAAgB,CACnB,QAAQ,GAAE,OAAe,EACzB,UAAU,GAAE,OAAe,EAC3B,gBAAgB,CAAC,EAAE,iBAAiB,GACrC,qBAAqB;IAOxB;;OAEG;IACU,SAAS,CAClB,QAAQ,GAAE,OAAe,EACzB,UAAU,GAAE,OAAe,EAC3B,gBAAgB,CAAC,EAAE,iBAAiB,GACrC,OAAO,CAAC,qBAAqB,CAAC;IAOjC;;OAEG;IACI,SAAS,CAAC,MAAM,GAAE,OAAe,GAAG,sBAAsB;IAwBjE;;;OAGG;IACH,SAAS,CAAC,iBAAiB,CAAC,UAAU,EAAE,iBAAiB;IAOzD;;;OAGG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAC5B,UAAU,EAAE,gBAAgB,EAC5B,gBAAgB,CAAC,EAAE,iBAAiB,GACrC,qBAAqB;IAExB,OAAO,CAAC,wBAAwB;CAInC"}
@@ -8,6 +8,7 @@ exports.SharedObject = exports.SharedObjectCore = void 0;
8
8
  const uuid_1 = require("uuid");
9
9
  const common_utils_1 = require("@fluidframework/common-utils");
10
10
  const container_definitions_1 = require("@fluidframework/container-definitions");
11
+ const runtime_definitions_1 = require("@fluidframework/runtime-definitions");
11
12
  const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
12
13
  const container_utils_1 = require("@fluidframework/container-utils");
13
14
  const serializer_1 = require("./serializer");
@@ -35,6 +36,7 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
35
36
  * True if the dds is bound to its parent.
36
37
  */
37
38
  this._isBoundToContext = false;
39
+ (0, common_utils_1.assert)(!id.includes("/"), 0x304 /* Id cannot contain slashes */);
38
40
  this.handle = new handle_1.SharedObjectHandle(this, id, runtime.IFluidHandleContext);
39
41
  this.logger = telemetry_utils_1.ChildLogger.create(runtime.logger, undefined, { all: { sharedObjectId: (0, uuid_1.v4)() } });
40
42
  this.attachListeners();
@@ -243,6 +245,9 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
243
245
  applyStashedOp: (content) => {
244
246
  return this.applyStashedOp(content);
245
247
  },
248
+ rollback: (content, localOpMetadata) => {
249
+ this.rollback(content, localOpMetadata);
250
+ },
246
251
  });
247
252
  // Trigger initial state
248
253
  // attachDeltaHandler is only called after services is assigned
@@ -268,7 +273,7 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
268
273
  this.onDisconnect();
269
274
  }
270
275
  else {
271
- // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending
276
+ // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending
272
277
  // messages will work.
273
278
  this.onConnect();
274
279
  }
@@ -295,6 +300,12 @@ class SharedObjectCore extends telemetry_utils_1.EventEmitterWithErrorHandling {
295
300
  reSubmit(content, localOpMetadata) {
296
301
  this.reSubmitCore(content, localOpMetadata);
297
302
  }
303
+ /**
304
+ * Revert an op
305
+ */
306
+ rollback(content, localOpMetadata) {
307
+ throw new Error("rollback not supported");
308
+ }
298
309
  }
299
310
  exports.SharedObjectCore = SharedObjectCore;
300
311
  /**
@@ -307,8 +318,9 @@ class SharedObject extends SharedObjectCore {
307
318
  * @param runtime - The IFluidDataStoreRuntime which contains the shared object
308
319
  * @param attributes - Attributes of the shared object
309
320
  */
310
- constructor(id, runtime, attributes) {
321
+ constructor(id, runtime, attributes, telemetryContextPrefix) {
311
322
  super(id, runtime, attributes);
323
+ this.telemetryContextPrefix = telemetryContextPrefix;
312
324
  /**
313
325
  * True while we are garbage collecting this object's data.
314
326
  */
@@ -329,14 +341,20 @@ class SharedObject extends SharedObjectCore {
329
341
  /**
330
342
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
331
343
  */
332
- getAttachSummary(fullTree = false, trackState = false) {
333
- return this.summarizeCore(this.serializer);
344
+ getAttachSummary(fullTree = false, trackState = false, telemetryContext) {
345
+ const result = this.summarizeCore(this.serializer, telemetryContext);
346
+ this.incrementTelemetryMetric(runtime_definitions_1.blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);
347
+ this.incrementTelemetryMetric(runtime_definitions_1.totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);
348
+ return result;
334
349
  }
335
350
  /**
336
351
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
337
352
  */
338
- async summarize(fullTree = false, trackState = false) {
339
- return this.summarizeCore(this.serializer);
353
+ async summarize(fullTree = false, trackState = false, telemetryContext) {
354
+ const result = this.summarizeCore(this.serializer, telemetryContext);
355
+ this.incrementTelemetryMetric(runtime_definitions_1.blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);
356
+ this.incrementTelemetryMetric(runtime_definitions_1.totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);
357
+ return result;
340
358
  }
341
359
  /**
342
360
  * {@inheritDoc (ISharedObject:interface).getGCData}
@@ -370,6 +388,11 @@ class SharedObject extends SharedObjectCore {
370
388
  // See: https://github.com/microsoft/FluidFramework/issues/4547
371
389
  this.summarizeCore(serializer);
372
390
  }
391
+ incrementTelemetryMetric(propertyName, incrementBy, telemetryContext) {
392
+ var _a;
393
+ const prevTotal = ((_a = telemetryContext === null || telemetryContext === void 0 ? void 0 : telemetryContext.get(this.telemetryContextPrefix, propertyName)) !== null && _a !== void 0 ? _a : 0);
394
+ telemetryContext === null || telemetryContext === void 0 ? void 0 : telemetryContext.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);
395
+ }
373
396
  }
374
397
  exports.SharedObject = SharedObject;
375
398
  //# sourceMappingURL=sharedObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,+DAA6E;AAC7E,iFAAoE;AAapE,qEAA6F;AAC7F,qEAAsE;AACtE,6CAAiE;AACjE,qCAA8C;AAC9C,2DAAwD;AAGxD;;GAEG;AACH,MAAsB,gBAClB,SAAQ,+CAAqC;IAyC7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAC9C,KAAK,CAAC,CAAC,KAA4B,EAAE,CAAM,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAHnF,OAAE,GAAF,EAAE,CAAQ;QACP,YAAO,GAAP,OAAO,CAAwB;QACzB,eAAU,GAAV,UAAU,CAAoB;QApClD;;WAEG;QACK,eAAU,GAAG,KAAK,CAAC;QAO3B;;WAEG;QACK,sBAAiB,GAAY,KAAK,CAAC;QA0BvC,IAAI,CAAC,MAAM,GAAG,IAAI,2BAAkB,CAChC,IAAI,EACJ,EAAE,EACF,OAAO,CAAC,mBAAmB,CAAC,CAAC;QAEjC,IAAI,CAAC,MAAM,GAAG,6BAAW,CAAC,MAAM,CAC5B,OAAO,CAAC,MAAM,EACd,SAAS,EACT,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,IAAA,SAAI,GAAE,EAAE,EAAE,CACtC,CAAC;QAEF,IAAI,CAAC,eAAe,EAAE,CAAC;IAC3B,CAAC;IA/DD,IAAW,cAAc,KAAK,OAAO,IAAI,CAAC,CAAC,CAAC;IAgC5C;;;OAGG;IACH,IAAW,SAAS;QA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SAAkB,KAAK;QACpC,4GAA4G;QAC5G,yBAAyB;QACzB,IAAA,qBAAM,EAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,wEAAwE,CAAC,CAAC;QACvG,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QAErB,IAAI,MAA8B,CAAC;QACnC,IAAI;YACA,MAAM,UAAU,GAAG,IAAI,qCAAiB,CACpC,IAAI,CAAC,OAAO,CAAC,sBAAsB,EACnC,CAAC,MAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CACvD,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,EAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,mEAAmE,CAAC,CAAC;SACpG;gBAAS;YACN,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACzB;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,UAA6B;QACrD,wGAAwG;QACxG,2GAA2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CAOJ;AAnGD,oCAmGC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n { all: { sharedObjectId: uuid() } },\n );\n\n this.attachListeners();\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n return this.summarizeCore(this.serializer);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(fullTree: boolean = false, trackState: boolean = false): Promise<ISummaryTreeWithStats> {\n return this.summarizeCore(this.serializer);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;\n}\n"]}
1
+ {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAAkC;AAElC,+DAA6E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C,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,mEAAmE,CAAC,CAAC;SACpG;gBAAS;YACN,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;SACzB;QAED,OAAO,MAAM,CAAC;IAClB,CAAC;IAED;;;OAGG;IACO,iBAAiB,CAAC,UAA6B;QACrD,wGAAwG;QACxG,2GAA2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;IAWO,wBAAwB,CAAC,YAAoB,EAAE,WAAmB,EAAE,gBAAoC;;QAC5G,MAAM,SAAS,GAAG,CAAC,MAAA,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,CAAC,mCAAI,CAAC,CAAW,CAAC;QACpG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC9F,CAAC;CACJ;AA3HD,oCA2HC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n blobCountPropertyName,\n totalBlobSizePropertyName,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n assert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n { all: { sharedObjectId: uuid() } },\n );\n\n this.attachListeners();\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n rollback: (content: any, localOpMetadata: unknown) => {\n this.rollback(content, localOpMetadata);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Revert an op\n */\n protected rollback(content: any, localOpMetadata: unknown) {\n throw new Error(\"rollback not supported\");\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly telemetryContextPrefix: string,\n ) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats> {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(\n serializer: IFluidSerializer,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {\n const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;\n telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n }\n}\n"]}
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export declare const pkgName = "@fluidframework/shared-object-base";
8
- export declare const pkgVersion = "0.59.4001";
8
+ export declare const pkgVersion = "1.1.0-75972";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,cAAc,CAAC"}
1
+ {"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,uCAAuC,CAAC;AAC5D,eAAO,MAAM,UAAU,gBAAgB,CAAC"}
@@ -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 = "0.59.4001";
8
+ export const pkgVersion = "1.1.0-75972";
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,WAAW,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/shared-object-base\";\nexport const pkgVersion = \"0.59.4001\";\n"]}
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,oCAAoC,CAAC;AAC5D,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,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 = \"1.1.0-75972\";\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"serializer.d.ts","sourceRoot":"","sources":["../src/serializer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGpF;;GAEG;AACF,MAAM,WAAW,iBAAiB;IAE/B,IAAI,EAAE,kBAAkB,CAAC;IAGzB,GAAG,EAAE,MAAM,CAAC;CACf;AAED,eAAO,MAAM,kBAAkB,UAAW,GAAG,+BACP,CAAC;AAEvC,MAAM,WAAW,gBAAgB;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,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maybeReplaced;
107
107
  }
108
108
  // Otherwise descend into the object graph looking for IFluidHandle instances.
109
- // eslint-disable-next-line @typescript-eslint/ban-types
110
109
  let clone;
111
110
  for (const key of Object.keys(input)) {
112
111
  const value = input[key];
@@ -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,CACzE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AAmCvC;;GAEG;AACH,MAAM,OAAO,eAAe;IAGxB,YACqB,OAA4B;IAC7C,+DAA+D;IAC9C,cAA8C;QAF9C,YAAO,GAAP,OAAO,CAAqB;QAE5B,mBAAc,GAAd,cAAc,CAAgC;QA0DnE,6EAA6E;QAC7E,iFAAiF;QAChE,gBAAW,GAAG,CAAC,KAAU,EAAE,IAAkB,EAAE,EAAE;YAC9D,wCAAwC;YACxC,MAAM,MAAM,GAAG,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,YAAY,CAAC;YAEnC,yDAAyD;YACzD,OAAO,MAAM,KAAK,SAAS;gBACvB,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,IAAI,CAAC;gBACpC,CAAC,CAAC,KAAK,CAAC;QAChB,CAAC,CAAC;QAEF,qFAAqF;QACrF,6EAA6E;QAC5D,gBAAW,GAAG,CAAC,KAAU,EAAE,EAAE;YAC1C,0EAA0E;YAC1E,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE;gBAC3B,kGAAkG;gBAClG,4FAA4F;gBAC5F,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,UAA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,GAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;wBAClC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;wBACZ,CAAC,mBAAM,KAAK,CAAE,CAAC,CAAC;oBAEpB,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBAC1B;aACJ;SACJ;QACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC;IAC1B,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC;IACN,CAAC;CACJ","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 */\n export interface ISerializedHandle {\n // Marker to indicate to JSON.parse that the object is a Fluid handle\n type: \"__fluid_handle__\";\n\n // URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n url: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n value?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n /**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n */\n encode(value: any, bind: IFluidHandle): any;\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n decode(input: any): any;\n\n /**\n * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n */\n stringify(value: any, bind: IFluidHandle): string;\n\n /**\n * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n * handles will be realized as part of the parse\n */\n parse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n private readonly root: IFluidHandleContext;\n\n public constructor(\n private readonly context: IFluidHandleContext,\n // To be called whenever a handle is parsed by this serializer.\n private readonly handleParsedCb: (handle: IFluidHandle) => void,\n ) {\n this.root = this.context;\n while (this.root.routeContext !== undefined) {\n this.root = this.root.routeContext;\n }\n }\n\n public get IFluidSerializer() { return this; }\n\n /**\n * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * Any unbound handles encountered are bound to the provided IFluidHandle.\n */\n public encode(\n input: any,\n bind: IFluidHandle,\n ) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.encodeValue, bind)\n : input;\n }\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n public decode(input: any) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.decodeValue)\n : input;\n }\n\n public stringify(input: any, bind: IFluidHandle) {\n return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n }\n\n // Parses the serialized data - context must match the context with which the JSON was stringified\n public parse(input: string) {\n return JSON.parse(input, (key, value) => this.decodeValue(value));\n }\n\n // If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n private readonly encodeValue = (value: any, bind: IFluidHandle) => {\n // Detect if 'value' is an IFluidHandle.\n const handle = value?.IFluidHandle;\n\n // If 'value' is an IFluidHandle return its encoded form.\n return handle !== undefined\n ? this.serializeHandle(handle, bind)\n : value;\n };\n\n // If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n private readonly decodeValue = (value: any) => {\n // If 'value' is a serialized IFluidHandle return the deserialized result.\n if (isSerializedHandle(value)) {\n // Old documents may have handles with relative path in their summaries. Convert these to absolute\n // paths. This will ensure that future summaries will have absolute paths for these handles.\n const absolutePath = value.url.startsWith(\"/\")\n ? value.url\n : generateHandleContextPath(value.url, this.context);\n\n const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n this.handleParsedCb(parsedHandle);\n return parsedHandle;\n } else {\n return value;\n }\n };\n\n // Invoked for non-null objects to recursively replace references to IFluidHandles.\n // Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n // returns the original `input`.\n private recursivelyReplace(\n input: any,\n replacer: (input: any, context: any) => any,\n context?: any,\n ) {\n // Note: Caller is responsible for ensuring that `input` is defined / non-null.\n // (Required for Object.keys() below.)\n\n // Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n // is a non-null object.\n const maybeReplaced = replacer(input, context);\n\n // If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n // leaves in the object graph.\n if (maybeReplaced !== input) {\n return maybeReplaced;\n }\n\n // Otherwise descend into the object graph looking for IFluidHandle instances.\n // eslint-disable-next-line @typescript-eslint/ban-types\n let clone: object | undefined;\n for (const key of Object.keys(input)) {\n const value = input[key];\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!!value && typeof value === \"object\") {\n // Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n // be JSON serializable.) Therefore, guarding against infinite recursion here would only\n // lead to a later error when attempting to stringify().\n const replaced = this.recursivelyReplace(value, replacer, context);\n\n // If the `replaced` object is different than the original `value` then the subgraph contained one\n // or more handles. If this happens, we need to return a clone of the `input` object where the\n // current property is replaced by the `replaced` value.\n if (replaced !== value) {\n // Lazily create a shallow clone of the `input` object if we haven't done so already.\n clone = clone ?? (Array.isArray(input)\n ? [...input]\n : { ...input });\n\n // Overwrite the current property `key` in the clone with the `replaced` value.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n clone![key] = replaced;\n }\n }\n }\n return clone ?? input;\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n bind.bind(handle);\n return {\n type: \"__fluid_handle__\",\n url: handle.absolutePath,\n };\n }\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,CACzE,CAAA,KAAK,aAAL,KAAK,uBAAL,KAAK,CAAE,IAAI,MAAK,kBAAkB,CAAC;AAmCvC;;GAEG;AACH,MAAM,OAAO,eAAe;IAGxB,YACqB,OAA4B;IAC7C,+DAA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G;QACrG,8BAA8B;QAC9B,IAAI,aAAa,KAAK,KAAK,EAAE;YACzB,OAAO,aAAa,CAAC;SACxB;QAED,8EAA8E;QAC9E,IAAI,KAAyB,CAAC;QAC9B,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE;YAClC,MAAM,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC;YACzB,yEAAyE;YACzE,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;gBACtC,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;oBACpB,qFAAqF;oBACrF,KAAK,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;wBAClC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC;wBACZ,CAAC,mBAAM,KAAK,CAAE,CAAC,CAAC;oBAEpB,+EAA+E;oBAC/E,oEAAoE;oBACpE,KAAM,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;iBAC1B;aACJ;SACJ;QACD,OAAO,KAAK,aAAL,KAAK,cAAL,KAAK,GAAI,KAAK,CAAC;IAC1B,CAAC;IAES,eAAe,CAAC,MAAoB,EAAE,IAAkB;QAC9D,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAClB,OAAO;YACH,IAAI,EAAE,kBAAkB;YACxB,GAAG,EAAE,MAAM,CAAC,YAAY;SAC3B,CAAC;IACN,CAAC;CACJ","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 */\n export interface ISerializedHandle {\n // Marker to indicate to JSON.parse that the object is a Fluid handle\n type: \"__fluid_handle__\";\n\n // URL to the object. Relative URLs are relative to the handle context passed to the stringify.\n url: string;\n}\n\nexport const isSerializedHandle = (value: any): value is ISerializedHandle =>\n value?.type === \"__fluid_handle__\";\n\nexport interface IFluidSerializer {\n /**\n * Given a mostly-plain object that may have handle objects embedded within, will return a fully-plain object\n * where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clones all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n */\n encode(value: any, bind: IFluidHandle): any;\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n decode(input: any): any;\n\n /**\n * Stringifies a given value. Converts any IFluidHandle to its stringified equivalent.\n */\n stringify(value: any, bind: IFluidHandle): string;\n\n /**\n * Parses the given JSON input string and returns the JavaScript object defined by it. Any Fluid\n * handles will be realized as part of the parse\n */\n parse(value: string): any;\n}\n\n/**\n * Data Store serializer implementation\n */\nexport class FluidSerializer implements IFluidSerializer {\n private readonly root: IFluidHandleContext;\n\n public constructor(\n private readonly context: IFluidHandleContext,\n // To be called whenever a handle is parsed by this serializer.\n private readonly handleParsedCb: (handle: IFluidHandle) => void,\n ) {\n this.root = this.context;\n while (this.root.routeContext !== undefined) {\n this.root = this.root.routeContext;\n }\n }\n\n public get IFluidSerializer() { return this; }\n\n /**\n * Given a mostly-jsonable object tree that may have handle objects embedded within, will return a\n * fully-jsonable object tree where any embedded IFluidHandles have been replaced with a serializable form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * Any unbound handles encountered are bound to the provided IFluidHandle.\n */\n public encode(\n input: any,\n bind: IFluidHandle,\n ) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.encodeValue, bind)\n : input;\n }\n\n /**\n * Given a fully-jsonable object tree that may have encoded handle objects embedded within, will return an\n * equivalent object tree where any encoded IFluidHandles have been replaced with their decoded form.\n *\n * The original `input` object is not mutated. This method will shallowly clone all objects in the path from\n * the root to any replaced handles. (If no handles are found, returns the original object.)\n *\n * The decoded handles are implicitly bound to the handle context of this serializer.\n */\n public decode(input: any) {\n // If the given 'input' cannot contain handles, return it immediately. Otherwise,\n // return the result of 'recursivelyReplace()'.\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n return !!input && typeof input === \"object\"\n ? this.recursivelyReplace(input, this.decodeValue)\n : input;\n }\n\n public stringify(input: any, bind: IFluidHandle) {\n return JSON.stringify(input, (key, value) => this.encodeValue(value, bind));\n }\n\n // Parses the serialized data - context must match the context with which the JSON was stringified\n public parse(input: string) {\n return JSON.parse(input, (key, value) => this.decodeValue(value));\n }\n\n // If the given 'value' is an IFluidHandle, returns the encoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'encode()' and 'stringify()'.\n private readonly encodeValue = (value: any, bind: IFluidHandle) => {\n // Detect if 'value' is an IFluidHandle.\n const handle = value?.IFluidHandle;\n\n // If 'value' is an IFluidHandle return its encoded form.\n return handle !== undefined\n ? this.serializeHandle(handle, bind)\n : value;\n };\n\n // If the given 'value' is an encoded IFluidHandle, returns the decoded IFluidHandle.\n // Otherwise returns the original 'value'. Used by 'decode()' and 'parse()'.\n private readonly decodeValue = (value: any) => {\n // If 'value' is a serialized IFluidHandle return the deserialized result.\n if (isSerializedHandle(value)) {\n // Old documents may have handles with relative path in their summaries. Convert these to absolute\n // paths. This will ensure that future summaries will have absolute paths for these handles.\n const absolutePath = value.url.startsWith(\"/\")\n ? value.url\n : generateHandleContextPath(value.url, this.context);\n\n const parsedHandle = new RemoteFluidObjectHandle(absolutePath, this.root);\n this.handleParsedCb(parsedHandle);\n return parsedHandle;\n } else {\n return value;\n }\n };\n\n // Invoked for non-null objects to recursively replace references to IFluidHandles.\n // Clones as-needed to avoid mutating the `input` object. If no IFluidHandes are present,\n // returns the original `input`.\n private recursivelyReplace(\n input: any,\n replacer: (input: any, context: any) => any,\n context?: any,\n ) {\n // Note: Caller is responsible for ensuring that `input` is defined / non-null.\n // (Required for Object.keys() below.)\n\n // Execute the `replace` on the current input. Note that Caller is responsible for ensuring that `input`\n // is a non-null object.\n const maybeReplaced = replacer(input, context);\n\n // If the replacer made a substitution there is no need to decscend further. IFluidHandles are always\n // leaves in the object graph.\n if (maybeReplaced !== input) {\n return maybeReplaced;\n }\n\n // Otherwise descend into the object graph looking for IFluidHandle instances.\n let clone: object | undefined;\n for (const key of Object.keys(input)) {\n const value = input[key];\n // eslint-disable-next-line @typescript-eslint/strict-boolean-expressions\n if (!!value && typeof value === \"object\") {\n // Note: Except for IFluidHandle, `input` must not contain circular references (as object must\n // be JSON serializable.) Therefore, guarding against infinite recursion here would only\n // lead to a later error when attempting to stringify().\n const replaced = this.recursivelyReplace(value, replacer, context);\n\n // If the `replaced` object is different than the original `value` then the subgraph contained one\n // or more handles. If this happens, we need to return a clone of the `input` object where the\n // current property is replaced by the `replaced` value.\n if (replaced !== value) {\n // Lazily create a shallow clone of the `input` object if we haven't done so already.\n clone = clone ?? (Array.isArray(input)\n ? [...input]\n : { ...input });\n\n // Overwrite the current property `key` in the clone with the `replaced` value.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n clone![key] = replaced;\n }\n }\n }\n return clone ?? input;\n }\n\n protected serializeHandle(handle: IFluidHandle, bind: IFluidHandle) {\n bind.bind(handle);\n return {\n type: \"__fluid_handle__\",\n url: handle.absolutePath,\n };\n }\n}\n"]}
@@ -6,7 +6,7 @@ import { ITelemetryLogger } from "@fluidframework/common-definitions";
6
6
  import { IFluidHandle } from "@fluidframework/core-interfaces";
7
7
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelServices } from "@fluidframework/datastore-definitions";
8
8
  import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
9
- import { IGarbageCollectionData, ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
9
+ import { IGarbageCollectionData, ISummaryTreeWithStats, ITelemetryContext } from "@fluidframework/runtime-definitions";
10
10
  import { EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
11
11
  import { IFluidSerializer } from "./serializer";
12
12
  import { SummarySerializer } from "./summarySerializer";
@@ -102,11 +102,11 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
102
102
  /**
103
103
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
104
104
  */
105
- abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
105
+ abstract getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
106
106
  /**
107
107
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
108
108
  */
109
- abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
109
+ abstract summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
110
110
  /**
111
111
  * {@inheritDoc (ISharedObject:interface).getGCData}
112
112
  */
@@ -198,6 +198,10 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
198
198
  * @param localOpMetadata - The local metadata associated with the original message.
199
199
  */
200
200
  private reSubmit;
201
+ /**
202
+ * Revert an op
203
+ */
204
+ protected rollback(content: any, localOpMetadata: unknown): void;
201
205
  /**
202
206
  * Apply changes from an op. Used when rehydrating an attached container
203
207
  * with pending changes. This prepares the SharedObject for seeing an ACK
@@ -213,6 +217,7 @@ export declare abstract class SharedObjectCore<TEvent extends ISharedObjectEvent
213
217
  * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.
214
218
  */
215
219
  export declare abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents> extends SharedObjectCore<TEvent> {
220
+ private readonly telemetryContextPrefix;
216
221
  /**
217
222
  * True while we are garbage collecting this object's data.
218
223
  */
@@ -227,15 +232,15 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
227
232
  * @param runtime - The IFluidDataStoreRuntime which contains the shared object
228
233
  * @param attributes - Attributes of the shared object
229
234
  */
230
- constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
235
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, telemetryContextPrefix: string);
231
236
  /**
232
237
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
233
238
  */
234
- getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
239
+ getAttachSummary(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
235
240
  /**
236
241
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
237
242
  */
238
- summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
243
+ summarize(fullTree?: boolean, trackState?: boolean, telemetryContext?: ITelemetryContext): Promise<ISummaryTreeWithStats>;
239
244
  /**
240
245
  * {@inheritDoc (ISharedObject:interface).getGCData}
241
246
  */
@@ -249,6 +254,7 @@ export declare abstract class SharedObject<TEvent extends ISharedObjectEvents =
249
254
  * Gets a form of the object that can be serialized.
250
255
  * @returns A tree representing the snapshot of the shared object.
251
256
  */
252
- protected abstract summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
257
+ protected abstract summarizeCore(serializer: IFluidSerializer, telemetryContext?: ITelemetryContext): ISummaryTreeWithStats;
258
+ private incrementTelemetryMetric;
253
259
  }
254
260
  //# sourceMappingURL=sharedObject.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.d.ts","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAGtE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,gBAAgB,EACnB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EACH,sBAAsB,EACtB,qBAAqB,EACxB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAe,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAE7F,OAAO,EAAmB,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEjE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE7D;;GAEG;AACH,8BAAsB,gBAAgB,CAAC,MAAM,SAAS,mBAAmB,GAAG,mBAAmB,CAC3F,SAAQ,6BAA6B,CAAC,MAAM,CAAE,YAAW,aAAa,CAAC,MAAM,CAAC;IA+CnE,EAAE,EAAE,MAAM;IACjB,SAAS,CAAC,OAAO,EAAE,sBAAsB;aACzB,UAAU,EAAE,kBAAkB;IAhDlD,IAAW,cAAc,SAAmB;IAE5C;;OAEG;IACH,SAAgB,MAAM,EAAE,YAAY,CAAC;IAErC;;OAEG;IACH,SAAS,CAAC,QAAQ,CA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E,gBAAgB,EAC5B,gBAAgB,CAAC,EAAE,iBAAiB,GACrC,qBAAqB;IAExB,OAAO,CAAC,wBAAwB;CAInC"}
@@ -5,6 +5,7 @@
5
5
  import { v4 as uuid } from "uuid";
6
6
  import { assert } from "@fluidframework/common-utils";
7
7
  import { AttachState } from "@fluidframework/container-definitions";
8
+ import { blobCountPropertyName, totalBlobSizePropertyName, } from "@fluidframework/runtime-definitions";
8
9
  import { ChildLogger, EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
9
10
  import { DataProcessingError } from "@fluidframework/container-utils";
10
11
  import { FluidSerializer } from "./serializer";
@@ -32,6 +33,7 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
32
33
  * True if the dds is bound to its parent.
33
34
  */
34
35
  this._isBoundToContext = false;
36
+ assert(!id.includes("/"), 0x304 /* Id cannot contain slashes */);
35
37
  this.handle = new SharedObjectHandle(this, id, runtime.IFluidHandleContext);
36
38
  this.logger = ChildLogger.create(runtime.logger, undefined, { all: { sharedObjectId: uuid() } });
37
39
  this.attachListeners();
@@ -240,6 +242,9 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
240
242
  applyStashedOp: (content) => {
241
243
  return this.applyStashedOp(content);
242
244
  },
245
+ rollback: (content, localOpMetadata) => {
246
+ this.rollback(content, localOpMetadata);
247
+ },
243
248
  });
244
249
  // Trigger initial state
245
250
  // attachDeltaHandler is only called after services is assigned
@@ -265,7 +270,7 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
265
270
  this.onDisconnect();
266
271
  }
267
272
  else {
268
- // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending
273
+ // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending
269
274
  // messages will work.
270
275
  this.onConnect();
271
276
  }
@@ -292,6 +297,12 @@ export class SharedObjectCore extends EventEmitterWithErrorHandling {
292
297
  reSubmit(content, localOpMetadata) {
293
298
  this.reSubmitCore(content, localOpMetadata);
294
299
  }
300
+ /**
301
+ * Revert an op
302
+ */
303
+ rollback(content, localOpMetadata) {
304
+ throw new Error("rollback not supported");
305
+ }
295
306
  }
296
307
  /**
297
308
  * SharedObject with simplified, synchronous summarization and GC.
@@ -303,8 +314,9 @@ export class SharedObject extends SharedObjectCore {
303
314
  * @param runtime - The IFluidDataStoreRuntime which contains the shared object
304
315
  * @param attributes - Attributes of the shared object
305
316
  */
306
- constructor(id, runtime, attributes) {
317
+ constructor(id, runtime, attributes, telemetryContextPrefix) {
307
318
  super(id, runtime, attributes);
319
+ this.telemetryContextPrefix = telemetryContextPrefix;
308
320
  /**
309
321
  * True while we are garbage collecting this object's data.
310
322
  */
@@ -325,14 +337,20 @@ export class SharedObject extends SharedObjectCore {
325
337
  /**
326
338
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
327
339
  */
328
- getAttachSummary(fullTree = false, trackState = false) {
329
- return this.summarizeCore(this.serializer);
340
+ getAttachSummary(fullTree = false, trackState = false, telemetryContext) {
341
+ const result = this.summarizeCore(this.serializer, telemetryContext);
342
+ this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);
343
+ this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);
344
+ return result;
330
345
  }
331
346
  /**
332
347
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
333
348
  */
334
- async summarize(fullTree = false, trackState = false) {
335
- return this.summarizeCore(this.serializer);
349
+ async summarize(fullTree = false, trackState = false, telemetryContext) {
350
+ const result = this.summarizeCore(this.serializer, telemetryContext);
351
+ this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);
352
+ this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);
353
+ return result;
336
354
  }
337
355
  /**
338
356
  * {@inheritDoc (ISharedObject:interface).getGCData}
@@ -366,5 +384,10 @@ export class SharedObject extends SharedObjectCore {
366
384
  // See: https://github.com/microsoft/FluidFramework/issues/4547
367
385
  this.summarizeCore(serializer);
368
386
  }
387
+ incrementTelemetryMetric(propertyName, incrementBy, telemetryContext) {
388
+ var _a;
389
+ const prevTotal = ((_a = telemetryContext === null || telemetryContext === void 0 ? void 0 : telemetryContext.get(this.telemetryContextPrefix, propertyName)) !== null && _a !== void 0 ? _a : 0);
390
+ telemetryContext === null || telemetryContext === void 0 ? void 0 : telemetryContext.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);
391
+ }
369
392
  }
370
393
  //# sourceMappingURL=sharedObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAyB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AAapE,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAoB,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAgB,gBAClB,SAAQ,6BAAqC;IAyC7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAC9C,KAAK,CAAC,CAAC,KAA4B,EAAE,CAAM,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAHnF,OAAE,GAAF,EAAE,CAAQ;QACP,YAAO,GAAP,OAAO,CAAwB;QACzB,eAAU,GAAV,UAAU,CAAoB;QApClD;;WAEG;QACK,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A2G;QAC3G,+DAA+D;QAC/D,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;IACnC,CAAC;CAOJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n { all: { sharedObjectId: uuid() } },\n );\n\n this.attachListeners();\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {\n return this.summarizeCore(this.serializer);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(fullTree: boolean = false, trackState: boolean = false): Promise<ISummaryTreeWithStats> {\n return this.summarizeCore(this.serializer);\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;\n}\n"]}
1
+ {"version":3,"file":"sharedObject.js","sourceRoot":"","sources":["../src/sharedObject.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,EAAE,IAAI,IAAI,EAAE,MAAM,MAAM,CAAC;AAElC,OAAO,EAAE,MAAM,EAAyB,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,uCAAuC,CAAC;AASpE,OAAO,EAIH,qBAAqB,EACrB,yBAAyB,GAC5B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,iCAAiC,CAAC;AAC7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,EAAE,eAAe,EAAoB,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD;;GAEG;AACH,MAAM,OAAgB,gBAClB,SAAQ,6BAAqC;IAyC7C;;;;OAIG;IACH,YACW,EAAU,EACP,OAA+B,EACzB,UAA8B;QAC9C,KAAK,CAAC,CAAC,KAA4B,EAAE,CAAM,EAAE,EAAE,CAAC,IAAI,CAAC,yBAAyB,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QAHnF,OAAE,GAAF,EAAE,CAAQ;QACP,YAAO,GAAP,OAAO,CAAwB;QACzB,eAAU,GAAV,UAAU,CAAoB;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CAAI,CAAC,CAAW,CAAC;QACpG,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,sBAAsB,EAAE,YAAY,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IAC9F,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { v4 as uuid } from \"uuid\";\nimport { ITelemetryLogger } from \"@fluidframework/common-definitions\";\nimport { assert, EventEmitterEventType } from \"@fluidframework/common-utils\";\nimport { AttachState } from \"@fluidframework/container-definitions\";\nimport { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport {\n IChannelAttributes,\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelServices,\n} from \"@fluidframework/datastore-definitions\";\nimport { ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport {\n IGarbageCollectionData,\n ISummaryTreeWithStats,\n ITelemetryContext,\n blobCountPropertyName,\n totalBlobSizePropertyName,\n} from \"@fluidframework/runtime-definitions\";\nimport { ChildLogger, EventEmitterWithErrorHandling } from \"@fluidframework/telemetry-utils\";\nimport { DataProcessingError } from \"@fluidframework/container-utils\";\nimport { FluidSerializer, IFluidSerializer } from \"./serializer\";\nimport { SharedObjectHandle } from \"./handle\";\nimport { SummarySerializer } from \"./summarySerializer\";\nimport { ISharedObject, ISharedObjectEvents } from \"./types\";\n\n/**\n * Base class from which all shared objects derive\n */\nexport abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends EventEmitterWithErrorHandling<TEvent> implements ISharedObject<TEvent> {\n public get IFluidLoadable() { return this; }\n\n /**\n * The handle referring to this SharedObject\n */\n public readonly handle: IFluidHandle;\n\n /**\n * Telemetry logger for the shared object\n */\n protected readonly logger: ITelemetryLogger;\n\n /**\n * Connection state\n */\n private _connected = false;\n\n /**\n * Services used by the shared object\n */\n private services: IChannelServices | undefined;\n\n /**\n * True if the dds is bound to its parent.\n */\n private _isBoundToContext: boolean = false;\n\n /**\n * Tracks error that closed this object.\n */\n private closeError?: ReturnType<typeof DataProcessingError.wrapIfUnrecognized>;\n\n /**\n * Gets the connection state\n * @returns The state of the connection\n */\n public get connected(): boolean {\n return this._connected;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n public id: string,\n protected runtime: IFluidDataStoreRuntime,\n public readonly attributes: IChannelAttributes) {\n super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));\n\n assert(!id.includes(\"/\"), 0x304 /* Id cannot contain slashes */);\n\n this.handle = new SharedObjectHandle(\n this,\n id,\n runtime.IFluidHandleContext);\n\n this.logger = ChildLogger.create(\n runtime.logger,\n undefined,\n { all: { sharedObjectId: uuid() } },\n );\n\n this.attachListeners();\n }\n\n /**\n * Marks this objects as closed. Any attempt to change it (local changes or processing remote ops)\n * would result in same error thrown. If called multiple times, only first error is remembered.\n * @param error - error object that is thrown whenever an attempt is made to modify this object\n */\n private closeWithError(error: any) {\n if (this.closeError === undefined) {\n this.closeError = error;\n }\n }\n\n /**\n * Verifies that this object is not closed via closeWithError(). If it is, throws an error used to close it.\n */\n private verifyNotClosed() {\n if (this.closeError !== undefined) {\n throw this.closeError;\n }\n }\n\n /**\n * Event listener handler helper that can be used to react to exceptions thrown from event listeners\n * It wraps error with DataProcessingError, closes this object and throws resulting error.\n * See closeWithError() for more details\n * Ideally such situation never happens, as consumers of DDS should never throw exceptions\n * in event listeners (i.e. catch any of the issues and make determination on how to handle it).\n * When such exceptions propagate through, most likely data model is no longer consistent, i.e.\n * DDS state does not match what user sees. Because of it DDS moves to \"corrupted state\" and does not\n * allow processing of ops or local changes, which very quickly results in container closure.\n */\n private eventListenerErrorHandler(event: EventEmitterEventType, e: any) {\n const error = DataProcessingError.wrapIfUnrecognized(\n e,\n \"SharedObjectEventListenerException\");\n error.addTelemetryProperties({ emittedEventName: String(event) });\n\n this.closeWithError(error);\n throw error;\n }\n\n private attachListeners() {\n // Only listen to these events if not attached.\n if (!this.isAttached()) {\n this.runtime.once(\"attaching\", () => {\n // Calling this will let the dds to do any custom processing based on attached\n // like starting generating ops.\n this.didAttach();\n });\n }\n }\n\n /**\n * A shared object, after construction, can either be loaded in the case that it is already part of\n * a shared document. Or later attached if it is being newly added.\n * @param services - Services used by the shared object\n */\n public async load(services: IChannelServices): Promise<void> {\n if (this.runtime.attachState !== AttachState.Detached) {\n this.services = services;\n }\n await this.loadCore(services.objectStorage);\n if (this.runtime.attachState !== AttachState.Detached) {\n this.attachDeltaHandler();\n }\n }\n\n /**\n * Initializes the object as a local, non-shared object. This object can become shared after\n * it is attached to the document.\n */\n public initializeLocal(): void {\n this.initializeLocalCore();\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).bindToContext}\n */\n public bindToContext(): void {\n if (this._isBoundToContext) {\n return;\n }\n\n this._isBoundToContext = true;\n\n this.runtime.bindChannel(this);\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).connect}\n */\n public connect(services: IChannelServices) {\n this.services = services;\n this.attachDeltaHandler();\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).isAttached}\n */\n public isAttached(): boolean {\n return this.services !== undefined && this.runtime.attachState !== AttachState.Detached;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public abstract getAttachSummary(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public abstract summarize(\n fullTree?: boolean,\n trackState?: boolean,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats>;\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public abstract getGCData(fullGC?: boolean): IGarbageCollectionData;\n\n /**\n * Called when a handle is decoded by this object. A handle in the object's data represents an outbound reference\n * to another object in the container.\n * @param decodedHandle - The handle of the Fluid object that is decoded.\n */\n protected handleDecoded(decodedHandle: IFluidHandle) {\n if (this.isAttached()) {\n // This represents an outbound reference from this object to the node represented by decodedHandle.\n this.services?.deltaConnection.addedGCOutboundReference?.(this.handle, decodedHandle);\n }\n }\n\n /**\n * Allows the distributed data type to perform custom loading\n * @param services - Storage used by the shared object\n */\n protected abstract loadCore(services: IChannelStorageService): Promise<void>;\n\n /**\n * Allows the distributed data type to perform custom local loading.\n */\n protected initializeLocalCore() {\n return;\n }\n\n /**\n * Allows the distributive data type the ability to perform custom processing once an attach has happened.\n * Also called after non-local data type get loaded.\n */\n protected didAttach() {\n return;\n }\n\n /**\n * Derived classes must override this to do custom processing on a remote message.\n * @param message - The message to process\n * @param local - True if the shared object is local\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected abstract processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown);\n\n /**\n * Called when the object has disconnected from the delta stream.\n */\n protected abstract onDisconnect();\n\n /**\n * Submits a message by the local client to the runtime.\n * @param content - Content of the message\n * @param localOpMetadata - The local metadata associated with the message. This is kept locally by the runtime\n * and not sent to the server. This will be sent back when this message is received back from the server. This is\n * also sent if we are asked to resubmit the message.\n */\n protected submitLocalMessage(content: any, localOpMetadata: unknown = undefined): void {\n this.verifyNotClosed();\n if (this.isAttached()) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.submit(content, localOpMetadata);\n }\n }\n\n /**\n * Marks this object as dirty so that it is part of the next summary. It is called by a SharedSummaryBlock\n * that want to be part of summary but does not generate ops.\n */\n protected dirty(): void {\n if (!this.isAttached()) {\n return;\n }\n\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.services!.deltaConnection.dirty();\n }\n\n /**\n * Called when the object has fully connected to the delta stream\n * Default implementation for DDS, override if different behavior is required.\n */\n protected onConnect() { }\n\n /**\n * Called when a message has to be resubmitted. This typically happens after a reconnection for unacked messages.\n * The default implementation here is to resubmit the same message. The client can override if different behavior\n * is required. It can choose to resubmit the same message, submit different / multiple messages or not submit\n * anything at all.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n protected reSubmitCore(content: any, localOpMetadata: unknown) {\n this.submitLocalMessage(content, localOpMetadata);\n }\n\n /**\n * Promises that are waiting for an ack from the server before resolving should use this instead of new Promise.\n * It ensures that if something changes that will interrupt that ack (e.g. the FluidDataStoreRuntime disposes),\n * the Promise will reject.\n * If runtime is disposed when this call is made, executor is not run and promise is rejected right away.\n */\n protected async newAckBasedPromise<T>(\n executor: (resolve: (value: T | PromiseLike<T>) => void, reject: (reason?: any) => void) => void,\n ): Promise<T> {\n let rejectBecauseDispose: () => void;\n return new Promise<T>((resolve, reject) => {\n rejectBecauseDispose =\n () => reject(new Error(\"FluidDataStoreRuntime disposed while this ack-based Promise was pending\"));\n\n if (this.runtime.disposed) {\n rejectBecauseDispose();\n return;\n }\n\n this.runtime.on(\"dispose\", rejectBecauseDispose);\n executor(resolve, reject);\n }).finally(() => {\n // Note: rejectBecauseDispose will never be undefined here\n this.runtime.off(\"dispose\", rejectBecauseDispose);\n });\n }\n\n private attachDeltaHandler() {\n // Services should already be there in case we are attaching delta handler.\n assert(this.services !== undefined, 0x07a /* \"Services should be there to attach delta handler\" */);\n this._isBoundToContext = true;\n // Allows objects to do any custom processing if it is attached.\n this.didAttach();\n\n // attachDeltaHandler is only called after services is assigned\n this.services.deltaConnection.attach({\n process: (message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) => {\n this.process(message, local, localOpMetadata);\n },\n setConnectionState: (connected: boolean) => {\n this.setConnectionState(connected);\n },\n reSubmit: (content: any, localOpMetadata: unknown) => {\n this.reSubmit(content, localOpMetadata);\n },\n applyStashedOp: (content: any): unknown => {\n return this.applyStashedOp(content);\n },\n rollback: (content: any, localOpMetadata: unknown) => {\n this.rollback(content, localOpMetadata);\n },\n });\n\n // Trigger initial state\n // attachDeltaHandler is only called after services is assigned\n this.setConnectionState(this.services.deltaConnection.connected);\n }\n\n /**\n * Set the state of connection to services.\n * @param connected - true if connected, false otherwise.\n */\n private setConnectionState(connected: boolean) {\n if (this._connected === connected) {\n // Not changing state, nothing the same.\n return;\n }\n\n // Should I change the state at the end? So that we *can't* send new stuff before we send old?\n this._connected = connected;\n\n if (!connected) {\n // Things that are true now...\n // - if we had a connection we can no longer send messages over it\n // - if we had outbound messages some may or may not be ACK'd. Won't know until next message\n //\n // - nack could get a new msn - but might as well do it in the join?\n this.onDisconnect();\n } else {\n // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending\n // messages will work.\n this.onConnect();\n }\n }\n\n /**\n * Handles a message being received from the remote delta server.\n * @param message - The message to process\n * @param local - Whether the message originated from the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n private process(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n this.verifyNotClosed(); // This will result in container closure.\n this.emit(\"pre-op\", message, local, this);\n this.processCore(message, local, localOpMetadata);\n this.emit(\"op\", message, local, this);\n }\n\n /**\n * Called when a message has to be resubmitted. This typically happens for unacked messages after a\n * reconnection.\n * @param content - The content of the original message.\n * @param localOpMetadata - The local metadata associated with the original message.\n */\n private reSubmit(content: any, localOpMetadata: unknown) {\n this.reSubmitCore(content, localOpMetadata);\n }\n\n /**\n * Revert an op\n */\n protected rollback(content: any, localOpMetadata: unknown) {\n throw new Error(\"rollback not supported\");\n }\n\n /**\n * Apply changes from an op. Used when rehydrating an attached container\n * with pending changes. This prepares the SharedObject for seeing an ACK\n * for the op or resubmitting the op upon reconnection.\n * @param content - Contents of a stashed op.\n * @returns localMetadata of the op, to be passed to process() or resubmit()\n * when the op is ACKed or resubmitted, respectively\n */\n protected abstract applyStashedOp(content: any): unknown;\n}\n\n/**\n * SharedObject with simplified, synchronous summarization and GC.\n * DDS implementations with async and incremental summarization should extend SharedObjectCore directly instead.\n */\nexport abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedObjectEvents>\n extends SharedObjectCore<TEvent> {\n /**\n * True while we are garbage collecting this object's data.\n */\n private _isGCing: boolean = false;\n\n /**\n * The serializer to use to serialize / parse handles, if any.\n */\n private readonly _serializer: IFluidSerializer;\n\n protected get serializer(): IFluidSerializer {\n /**\n * During garbage collection, the SummarySerializer keeps track of IFluidHandles that are serialized. These\n * handles represent references to other Fluid objects.\n *\n * This is fine for now. However, if we implement delay loading in DDss, they may load and de-serialize content\n * in summarize. When that happens, they may incorrectly hit this assert and we will have to change this.\n */\n assert(!this._isGCing,\n 0x075 /* \"SummarySerializer should be used for serializing data during summary.\" */);\n return this._serializer;\n }\n\n /**\n * @param id - The id of the shared object\n * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n * @param attributes - Attributes of the shared object\n */\n constructor(\n id: string,\n runtime: IFluidDataStoreRuntime,\n attributes: IChannelAttributes,\n private readonly telemetryContextPrefix: string,\n ) {\n super(id, runtime, attributes);\n\n this._serializer = new FluidSerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n */\n public getAttachSummary(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n */\n public async summarize(\n fullTree: boolean = false,\n trackState: boolean = false,\n telemetryContext?: ITelemetryContext,\n ): Promise<ISummaryTreeWithStats> {\n const result = this.summarizeCore(this.serializer, telemetryContext);\n this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);\n this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);\n return result;\n }\n\n /**\n * {@inheritDoc (ISharedObject:interface).getGCData}\n */\n public getGCData(fullGC: boolean = false): IGarbageCollectionData {\n // Set _isGCing to true. This flag is used to ensure that we only use SummarySerializer to serialize handles\n // in this object's data.\n assert(!this._isGCing, 0x078 /* \"Possible re-entrancy! Summary should not already be in progress.\" */);\n this._isGCing = true;\n\n let gcData: IGarbageCollectionData;\n try {\n const serializer = new SummarySerializer(\n this.runtime.channelsRoutingContext,\n (handle: IFluidHandle) => this.handleDecoded(handle),\n );\n this.processGCDataCore(serializer);\n // The GC data for this shared object contains a single GC node. The outbound routes of this node are the\n // routes of handles serialized during summarization.\n gcData = { gcNodes: { \"/\": serializer.getSerializedRoutes() } };\n assert(this._isGCing, 0x079 /* \"Possible re-entrancy! Summary should have been in progress.\" */);\n } finally {\n this._isGCing = false;\n }\n\n return gcData;\n }\n\n /**\n * Calls the serializer over all data in this object that reference other GC nodes.\n * Derived classes must override this to provide custom list of references to other GC nodes.\n */\n protected processGCDataCore(serializer: SummarySerializer) {\n // We run the full summarize logic to get the list of outbound routes from this object. This is a little\n // expensive but its okay for now. It will be updated to not use full summarize and make it more efficient.\n // See: https://github.com/microsoft/FluidFramework/issues/4547\n this.summarizeCore(serializer);\n }\n\n /**\n * Gets a form of the object that can be serialized.\n * @returns A tree representing the snapshot of the shared object.\n */\n protected abstract summarizeCore(\n serializer: IFluidSerializer,\n telemetryContext?: ITelemetryContext,\n ): ISummaryTreeWithStats;\n\n private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {\n const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;\n telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/shared-object-base",
3
- "version": "0.59.4001",
3
+ "version": "1.1.0-75972",
4
4
  "description": "Fluid base class for shared distributed data structures",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -63,47 +63,35 @@
63
63
  "dependencies": {
64
64
  "@fluidframework/common-definitions": "^0.20.1",
65
65
  "@fluidframework/common-utils": "^0.32.1",
66
- "@fluidframework/container-definitions": "^0.48.2000",
67
- "@fluidframework/container-runtime": "^0.59.4001",
68
- "@fluidframework/container-utils": "^0.59.4001",
69
- "@fluidframework/core-interfaces": "^0.43.1000",
70
- "@fluidframework/datastore": "^0.59.4001",
71
- "@fluidframework/datastore-definitions": "^0.59.4001",
66
+ "@fluidframework/container-definitions": "1.1.0-75972",
67
+ "@fluidframework/container-runtime": "1.1.0-75972",
68
+ "@fluidframework/container-utils": "1.1.0-75972",
69
+ "@fluidframework/core-interfaces": "1.1.0-75972",
70
+ "@fluidframework/datastore": "1.1.0-75972",
71
+ "@fluidframework/datastore-definitions": "1.1.0-75972",
72
72
  "@fluidframework/protocol-definitions": "^0.1028.2000",
73
- "@fluidframework/runtime-definitions": "^0.59.4001",
74
- "@fluidframework/runtime-utils": "^0.59.4001",
75
- "@fluidframework/telemetry-utils": "^0.59.4001",
73
+ "@fluidframework/runtime-definitions": "1.1.0-75972",
74
+ "@fluidframework/runtime-utils": "1.1.0-75972",
75
+ "@fluidframework/telemetry-utils": "1.1.0-75972",
76
76
  "uuid": "^8.3.1"
77
77
  },
78
78
  "devDependencies": {
79
- "@fluidframework/build-common": "^0.23.0",
80
- "@fluidframework/build-tools": "^0.2.70857",
79
+ "@fluidframework/build-common": "^0.24.0-0",
80
+ "@fluidframework/build-tools": "^0.2.71273",
81
81
  "@fluidframework/eslint-config-fluid": "^0.28.2000",
82
- "@fluidframework/mocha-test-setup": "^0.59.4001",
83
- "@fluidframework/shared-object-base-previous": "npm:@fluidframework/shared-object-base@0.59.4000",
82
+ "@fluidframework/mocha-test-setup": "1.1.0-75972",
83
+ "@fluidframework/shared-object-base-previous": "npm:@fluidframework/shared-object-base@^1.0.0",
84
+ "@fluidframework/test-runtime-utils": "1.1.0-75972",
84
85
  "@microsoft/api-extractor": "^7.22.2",
85
86
  "@rushstack/eslint-config": "^2.5.1",
86
87
  "@types/benchmark": "^2.1.0",
87
88
  "@types/mocha": "^9.1.1",
88
89
  "@types/node": "^14.18.0",
89
- "@typescript-eslint/eslint-plugin": "~5.9.0",
90
- "@typescript-eslint/parser": "~5.9.0",
91
90
  "benchmark": "^2.1.4",
92
91
  "concurrently": "^6.2.0",
93
92
  "copyfiles": "^2.1.0",
94
93
  "cross-env": "^7.0.2",
95
94
  "eslint": "~8.6.0",
96
- "eslint-plugin-editorconfig": "~3.2.0",
97
- "eslint-plugin-eslint-comments": "~3.2.0",
98
- "eslint-plugin-import": "~2.25.4",
99
- "eslint-plugin-jest": "~26.1.3",
100
- "eslint-plugin-jsdoc": "~39.3.0",
101
- "eslint-plugin-mocha": "~10.0.3",
102
- "eslint-plugin-promise": "~6.0.0",
103
- "eslint-plugin-react": "~7.28.0",
104
- "eslint-plugin-tsdoc": "~0.2.14",
105
- "eslint-plugin-unicorn": "~40.0.0",
106
- "eslint-plugin-unused-imports": "~2.0.0",
107
95
  "mocha": "^10.0.0",
108
96
  "nyc": "^15.0.0",
109
97
  "rimraf": "^2.6.2",
@@ -112,7 +100,7 @@
112
100
  "typescript-formatter": "7.1.0"
113
101
  },
114
102
  "typeValidation": {
115
- "version": "0.59.4001",
103
+ "version": "1.1.0",
116
104
  "broken": {}
117
105
  }
118
106
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/shared-object-base";
9
- export const pkgVersion = "0.59.4001";
9
+ export const pkgVersion = "1.1.0-75972";
package/src/serializer.ts CHANGED
@@ -177,7 +177,6 @@ export class FluidSerializer implements IFluidSerializer {
177
177
  }
178
178
 
179
179
  // Otherwise descend into the object graph looking for IFluidHandle instances.
180
- // eslint-disable-next-line @typescript-eslint/ban-types
181
180
  let clone: object | undefined;
182
181
  for (const key of Object.keys(input)) {
183
182
  const value = input[key];
@@ -18,6 +18,9 @@ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions"
18
18
  import {
19
19
  IGarbageCollectionData,
20
20
  ISummaryTreeWithStats,
21
+ ITelemetryContext,
22
+ blobCountPropertyName,
23
+ totalBlobSizePropertyName,
21
24
  } from "@fluidframework/runtime-definitions";
22
25
  import { ChildLogger, EventEmitterWithErrorHandling } from "@fluidframework/telemetry-utils";
23
26
  import { DataProcessingError } from "@fluidframework/container-utils";
@@ -82,6 +85,8 @@ export abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISha
82
85
  public readonly attributes: IChannelAttributes) {
83
86
  super((event: EventEmitterEventType, e: any) => this.eventListenerErrorHandler(event, e));
84
87
 
88
+ assert(!id.includes("/"), 0x304 /* Id cannot contain slashes */);
89
+
85
90
  this.handle = new SharedObjectHandle(
86
91
  this,
87
92
  id,
@@ -201,12 +206,20 @@ export abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISha
201
206
  /**
202
207
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
203
208
  */
204
- public abstract getAttachSummary(fullTree?: boolean, trackState?: boolean): ISummaryTreeWithStats;
209
+ public abstract getAttachSummary(
210
+ fullTree?: boolean,
211
+ trackState?: boolean,
212
+ telemetryContext?: ITelemetryContext,
213
+ ): ISummaryTreeWithStats;
205
214
 
206
215
  /**
207
216
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
208
217
  */
209
- public abstract summarize(fullTree?: boolean, trackState?: boolean): Promise<ISummaryTreeWithStats>;
218
+ public abstract summarize(
219
+ fullTree?: boolean,
220
+ trackState?: boolean,
221
+ telemetryContext?: ITelemetryContext,
222
+ ): Promise<ISummaryTreeWithStats>;
210
223
 
211
224
  /**
212
225
  * {@inheritDoc (ISharedObject:interface).getGCData}
@@ -354,6 +367,9 @@ export abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISha
354
367
  applyStashedOp: (content: any): unknown => {
355
368
  return this.applyStashedOp(content);
356
369
  },
370
+ rollback: (content: any, localOpMetadata: unknown) => {
371
+ this.rollback(content, localOpMetadata);
372
+ },
357
373
  });
358
374
 
359
375
  // Trigger initial state
@@ -382,7 +398,7 @@ export abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISha
382
398
  // - nack could get a new msn - but might as well do it in the join?
383
399
  this.onDisconnect();
384
400
  } else {
385
- // Call this for now so that DDSes like ConsensesOrderedCollection that maintain their own pending
401
+ // Call this for now so that DDSes like ConsensusOrderedCollection that maintain their own pending
386
402
  // messages will work.
387
403
  this.onConnect();
388
404
  }
@@ -412,6 +428,13 @@ export abstract class SharedObjectCore<TEvent extends ISharedObjectEvents = ISha
412
428
  this.reSubmitCore(content, localOpMetadata);
413
429
  }
414
430
 
431
+ /**
432
+ * Revert an op
433
+ */
434
+ protected rollback(content: any, localOpMetadata: unknown) {
435
+ throw new Error("rollback not supported");
436
+ }
437
+
415
438
  /**
416
439
  * Apply changes from an op. Used when rehydrating an attached container
417
440
  * with pending changes. This prepares the SharedObject for seeing an ACK
@@ -460,7 +483,9 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
460
483
  constructor(
461
484
  id: string,
462
485
  runtime: IFluidDataStoreRuntime,
463
- attributes: IChannelAttributes) {
486
+ attributes: IChannelAttributes,
487
+ private readonly telemetryContextPrefix: string,
488
+ ) {
464
489
  super(id, runtime, attributes);
465
490
 
466
491
  this._serializer = new FluidSerializer(
@@ -472,15 +497,29 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
472
497
  /**
473
498
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}
474
499
  */
475
- public getAttachSummary(fullTree: boolean = false, trackState: boolean = false): ISummaryTreeWithStats {
476
- return this.summarizeCore(this.serializer);
500
+ public getAttachSummary(
501
+ fullTree: boolean = false,
502
+ trackState: boolean = false,
503
+ telemetryContext?: ITelemetryContext,
504
+ ): ISummaryTreeWithStats {
505
+ const result = this.summarizeCore(this.serializer, telemetryContext);
506
+ this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);
507
+ this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);
508
+ return result;
477
509
  }
478
510
 
479
511
  /**
480
512
  * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}
481
513
  */
482
- public async summarize(fullTree: boolean = false, trackState: boolean = false): Promise<ISummaryTreeWithStats> {
483
- return this.summarizeCore(this.serializer);
514
+ public async summarize(
515
+ fullTree: boolean = false,
516
+ trackState: boolean = false,
517
+ telemetryContext?: ITelemetryContext,
518
+ ): Promise<ISummaryTreeWithStats> {
519
+ const result = this.summarizeCore(this.serializer, telemetryContext);
520
+ this.incrementTelemetryMetric(blobCountPropertyName, result.stats.blobNodeCount, telemetryContext);
521
+ this.incrementTelemetryMetric(totalBlobSizePropertyName, result.stats.totalBlobSize, telemetryContext);
522
+ return result;
484
523
  }
485
524
 
486
525
  /**
@@ -525,5 +564,13 @@ export abstract class SharedObject<TEvent extends ISharedObjectEvents = ISharedO
525
564
  * Gets a form of the object that can be serialized.
526
565
  * @returns A tree representing the snapshot of the shared object.
527
566
  */
528
- protected abstract summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
567
+ protected abstract summarizeCore(
568
+ serializer: IFluidSerializer,
569
+ telemetryContext?: ITelemetryContext,
570
+ ): ISummaryTreeWithStats;
571
+
572
+ private incrementTelemetryMetric(propertyName: string, incrementBy: number, telemetryContext?: ITelemetryContext) {
573
+ const prevTotal = (telemetryContext?.get(this.telemetryContextPrefix, propertyName) ?? 0) as number;
574
+ telemetryContext?.set(this.telemetryContextPrefix, propertyName, prevTotal + incrementBy);
575
+ }
529
576
  }