@fluid-experimental/attributor 2.1.0 → 2.3.0-288113

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +2 -2
  3. package/dist/attributorContracts.d.ts +49 -0
  4. package/dist/attributorContracts.d.ts.map +1 -0
  5. package/dist/attributorContracts.js +22 -0
  6. package/dist/attributorContracts.js.map +1 -0
  7. package/dist/index.d.ts +2 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js +6 -4
  10. package/dist/index.js.map +1 -1
  11. package/dist/mixinAttributor.d.ts +8 -49
  12. package/dist/mixinAttributor.d.ts.map +1 -1
  13. package/dist/mixinAttributor.js +35 -140
  14. package/dist/mixinAttributor.js.map +1 -1
  15. package/dist/runtimeAttributor.d.ts +19 -0
  16. package/dist/runtimeAttributor.d.ts.map +1 -0
  17. package/dist/runtimeAttributor.js +71 -0
  18. package/dist/runtimeAttributor.js.map +1 -0
  19. package/dist/runtimeAttributorDataStoreChannel.d.ts +92 -0
  20. package/dist/runtimeAttributorDataStoreChannel.d.ts.map +1 -0
  21. package/dist/runtimeAttributorDataStoreChannel.js +177 -0
  22. package/dist/runtimeAttributorDataStoreChannel.js.map +1 -0
  23. package/dist/runtimeAttributorDataStoreFactory.d.ts +15 -0
  24. package/dist/runtimeAttributorDataStoreFactory.d.ts.map +1 -0
  25. package/dist/runtimeAttributorDataStoreFactory.js +39 -0
  26. package/dist/runtimeAttributorDataStoreFactory.js.map +1 -0
  27. package/lib/attributorContracts.d.ts +49 -0
  28. package/lib/attributorContracts.d.ts.map +1 -0
  29. package/lib/attributorContracts.js +19 -0
  30. package/lib/attributorContracts.js.map +1 -0
  31. package/lib/index.d.ts +2 -1
  32. package/lib/index.d.ts.map +1 -1
  33. package/lib/index.js +2 -1
  34. package/lib/index.js.map +1 -1
  35. package/lib/mixinAttributor.d.ts +8 -49
  36. package/lib/mixinAttributor.d.ts.map +1 -1
  37. package/lib/mixinAttributor.js +33 -138
  38. package/lib/mixinAttributor.js.map +1 -1
  39. package/lib/runtimeAttributor.d.ts +19 -0
  40. package/lib/runtimeAttributor.d.ts.map +1 -0
  41. package/lib/runtimeAttributor.js +67 -0
  42. package/lib/runtimeAttributor.js.map +1 -0
  43. package/lib/runtimeAttributorDataStoreChannel.d.ts +92 -0
  44. package/lib/runtimeAttributorDataStoreChannel.d.ts.map +1 -0
  45. package/lib/runtimeAttributorDataStoreChannel.js +173 -0
  46. package/lib/runtimeAttributorDataStoreChannel.js.map +1 -0
  47. package/lib/runtimeAttributorDataStoreFactory.d.ts +15 -0
  48. package/lib/runtimeAttributorDataStoreFactory.d.ts.map +1 -0
  49. package/lib/runtimeAttributorDataStoreFactory.js +35 -0
  50. package/lib/runtimeAttributorDataStoreFactory.js.map +1 -0
  51. package/package.json +20 -19
  52. package/src/attributorContracts.ts +61 -0
  53. package/src/index.ts +3 -3
  54. package/src/mixinAttributor.ts +45 -267
  55. package/src/runtimeAttributor.ts +111 -0
  56. package/src/runtimeAttributorDataStoreChannel.ts +261 -0
  57. package/src/runtimeAttributorDataStoreFactory.ts +59 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluid-experimental/attributor
2
2
 
3
+ ## 2.2.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.1.0
4
8
 
5
9
  Dependency updates only.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This package contains definitions and implementations for framework-provided attribution functionality.
4
4
 
5
- <!-- AUTO-GENERATED-CONTENT:START (LIBRARY_PACKAGE_README_HEADER) -->
5
+ <!-- AUTO-GENERATED-CONTENT:START (LIBRARY_README_HEADER) -->
6
6
 
7
7
  <!-- prettier-ignore-start -->
8
8
  <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
@@ -139,7 +139,7 @@ The behavior of `"Fluid.Attribution.WriteOnNewFile"` supports the standard strat
139
139
  "reading the new format" corresponds to using a container runtime initialized with `mixinAttributor`, and "writing the new format" to enabling `"Fluid.Attribution.WriteOnNewFile"` in configuration.
140
140
  During the "waiting to saturate" period, developers are free to experiment with turning the feature flag on locally and testing various compatability scenarios.
141
141
 
142
- <!-- AUTO-GENERATED-CONTENT:START (LIBRARY_PACKAGE_README_FOOTER) -->
142
+ <!-- AUTO-GENERATED-CONTENT:START (README_FOOTER) -->
143
143
 
144
144
  <!-- prettier-ignore-start -->
145
145
  <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
@@ -0,0 +1,49 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { type AttributionInfo, type AttributionKey } from "@fluidframework/runtime-definitions/internal";
6
+ export declare const opBlobName = "opAttributor";
7
+ /**
8
+ * @internal
9
+ */
10
+ export declare const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
11
+ /**
12
+ * @internal
13
+ */
14
+ export declare const IRuntimeAttributor: keyof IProvideRuntimeAttributor;
15
+ /**
16
+ * @internal
17
+ */
18
+ export interface IProvideRuntimeAttributor {
19
+ readonly IRuntimeAttributor: IRuntimeAttributor;
20
+ }
21
+ /**
22
+ * @internal
23
+ */
24
+ export declare const attributorDataStoreAlias = "attributor-cf9b6fe4-4c50-4a5d-9045-eb73b886f740";
25
+ /**
26
+ * Provides access to attribution information stored on the container runtime.
27
+ *
28
+ * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.
29
+ *
30
+ * @sealed
31
+ * @internal
32
+ */
33
+ export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
34
+ /**
35
+ * @throws - If no AttributionInfo exists for this key.
36
+ */
37
+ get(key: AttributionKey): AttributionInfo;
38
+ /**
39
+ * @returns Whether any AttributionInfo exists for the provided key.
40
+ */
41
+ has(key: AttributionKey): boolean;
42
+ /**
43
+ * @returns Whether the runtime is currently tracking attribution information for the loaded container.
44
+ * If enabled, the runtime attributor can be asked for the attribution info for different keys.
45
+ * See {@link mixinAttributor} for more details on when this happens.
46
+ */
47
+ readonly isEnabled: boolean;
48
+ }
49
+ //# sourceMappingURL=attributorContracts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributorContracts.d.ts","sourceRoot":"","sources":["../src/attributorContracts.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,MAAM,8CAA8C,CAAC;AAGtD,eAAO,MAAM,UAAU,iBAAiB,CAAC;AAEzC;;GAEG;AACH,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,yBAAgD,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;CAChD;AAED;;GAEG;AACH,eAAO,MAAM,wBAAwB,oDAAoD,CAAC;AAE1F;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IACpE;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.attributorDataStoreAlias = exports.IRuntimeAttributor = exports.enableOnNewFileKey = exports.opBlobName = void 0;
8
+ // Summary tree keys
9
+ exports.opBlobName = "opAttributor";
10
+ /**
11
+ * @internal
12
+ */
13
+ exports.enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
14
+ /**
15
+ * @internal
16
+ */
17
+ exports.IRuntimeAttributor = "IRuntimeAttributor";
18
+ /**
19
+ * @internal
20
+ */
21
+ exports.attributorDataStoreAlias = "attributor-cf9b6fe4-4c50-4a5d-9045-eb73b886f740";
22
+ //# sourceMappingURL=attributorContracts.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributorContracts.js","sourceRoot":"","sources":["../src/attributorContracts.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH,oBAAoB;AACP,QAAA,UAAU,GAAG,cAAc,CAAC;AAEzC;;GAEG;AACU,QAAA,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE;;GAEG;AACU,QAAA,kBAAkB,GAAoC,oBAAoB,CAAC;AASxF;;GAEG;AACU,QAAA,wBAAwB,GAAG,iDAAiD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n} from \"@fluidframework/runtime-definitions/internal\";\n\n// Summary tree keys\nexport const opBlobName = \"opAttributor\";\n\n/**\n * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * @internal\n */\nexport const attributorDataStoreAlias = \"attributor-cf9b6fe4-4c50-4a5d-9045-eb73b886f740\";\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.\n *\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * If enabled, the runtime attributor can be asked for the attribution info for different keys.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n"]}
package/dist/index.d.ts CHANGED
@@ -3,5 +3,6 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  export { type IAttributor } from "./attributor.js";
6
- export { createRuntimeAttributor, enableOnNewFileKey, type IProvideRuntimeAttributor, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.js";
6
+ export { mixinAttributor, getRuntimeAttributor } from "./mixinAttributor.js";
7
+ export { attributorDataStoreAlias, enableOnNewFileKey, type IProvideRuntimeAttributor, IRuntimeAttributor, } from "./attributorContracts.js";
7
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EACN,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,eAAe,GACf,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EACN,wBAAwB,EACxB,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,kBAAkB,GAClB,MAAM,0BAA0B,CAAC"}
package/dist/index.js CHANGED
@@ -4,10 +4,12 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.mixinAttributor = exports.IRuntimeAttributor = exports.enableOnNewFileKey = exports.createRuntimeAttributor = void 0;
7
+ exports.IRuntimeAttributor = exports.enableOnNewFileKey = exports.attributorDataStoreAlias = exports.getRuntimeAttributor = exports.mixinAttributor = void 0;
8
8
  var mixinAttributor_js_1 = require("./mixinAttributor.js");
9
- Object.defineProperty(exports, "createRuntimeAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.createRuntimeAttributor; } });
10
- Object.defineProperty(exports, "enableOnNewFileKey", { enumerable: true, get: function () { return mixinAttributor_js_1.enableOnNewFileKey; } });
11
- Object.defineProperty(exports, "IRuntimeAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.IRuntimeAttributor; } });
12
9
  Object.defineProperty(exports, "mixinAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.mixinAttributor; } });
10
+ Object.defineProperty(exports, "getRuntimeAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.getRuntimeAttributor; } });
11
+ var attributorContracts_js_1 = require("./attributorContracts.js");
12
+ Object.defineProperty(exports, "attributorDataStoreAlias", { enumerable: true, get: function () { return attributorContracts_js_1.attributorDataStoreAlias; } });
13
+ Object.defineProperty(exports, "enableOnNewFileKey", { enumerable: true, get: function () { return attributorContracts_js_1.enableOnNewFileKey; } });
14
+ Object.defineProperty(exports, "IRuntimeAttributor", { enumerable: true, get: function () { return attributorContracts_js_1.IRuntimeAttributor; } });
13
15
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2DAM8B;AAL7B,6HAAA,uBAAuB,OAAA;AACvB,wHAAA,kBAAkB,OAAA;AAElB,wHAAA,kBAAkB,OAAA;AAClB,qHAAA,eAAe,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { type IAttributor } from \"./attributor.js\";\nexport {\n\tcreateRuntimeAttributor,\n\tenableOnNewFileKey,\n\ttype IProvideRuntimeAttributor,\n\tIRuntimeAttributor,\n\tmixinAttributor,\n} from \"./mixinAttributor.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2DAA6E;AAApE,qHAAA,eAAe,OAAA;AAAE,0HAAA,oBAAoB,OAAA;AAC9C,mEAKkC;AAJjC,kIAAA,wBAAwB,OAAA;AACxB,4HAAA,kBAAkB,OAAA;AAElB,4HAAA,kBAAkB,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport { type IAttributor } from \"./attributor.js\";\nexport { mixinAttributor, getRuntimeAttributor } from \"./mixinAttributor.js\";\nexport {\n\tattributorDataStoreAlias,\n\tenableOnNewFileKey,\n\ttype IProvideRuntimeAttributor,\n\tIRuntimeAttributor,\n} from \"./attributorContracts.js\";\n"]}
@@ -3,61 +3,20 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ContainerRuntime } from "@fluidframework/container-runtime/internal";
6
- import { type AttributionInfo, type AttributionKey } from "@fluidframework/runtime-definitions/internal";
6
+ import { type IContainerRuntime } from "@fluidframework/container-runtime-definitions/internal";
7
+ import { type IRuntimeAttributor } from "./attributorContracts.js";
7
8
  /**
9
+ * Utility function to get the runtime attributor from the container runtime.
10
+ * @param runtime - container runtime from which attributor is to be fetched.
11
+ * @returns IRuntimeAttributor if it exists, otherwise undefined.
8
12
  * @internal
9
13
  */
10
- export declare const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
11
- /**
12
- * @internal
13
- */
14
- export declare const IRuntimeAttributor: keyof IProvideRuntimeAttributor;
15
- /**
16
- * @internal
17
- */
18
- export interface IProvideRuntimeAttributor {
19
- readonly IRuntimeAttributor: IRuntimeAttributor;
20
- }
21
- /**
22
- * Provides access to attribution information stored on the container runtime.
23
- *
24
- * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.
25
- *
26
- * @sealed
27
- * @internal
28
- */
29
- export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
30
- /**
31
- * @throws - If no AttributionInfo exists for this key.
32
- */
33
- get(key: AttributionKey): AttributionInfo;
34
- /**
35
- * @returns Whether any AttributionInfo exists for the provided key.
36
- */
37
- has(key: AttributionKey): boolean;
38
- /**
39
- * @returns Whether the runtime is currently tracking attribution information for the loaded container.
40
- * If enabled, the runtime attributor can be asked for the attribution info for different keys.
41
- * See {@link mixinAttributor} for more details on when this happens.
42
- */
43
- readonly isEnabled: boolean;
44
- }
45
- /**
46
- * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.
47
- *
48
- * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.
49
- *
50
- * @internal
51
- */
52
- export declare function createRuntimeAttributor(): IRuntimeAttributor;
14
+ export declare function getRuntimeAttributor(runtime: IContainerRuntime): Promise<IRuntimeAttributor | undefined>;
53
15
  /**
54
16
  * Mixes in logic to load and store runtime-based attribution functionality.
55
17
  *
56
- * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
57
- *
58
- * Existing documents without stored attributors will not start storing attribution information: if an
59
- * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
60
- * that attributor's `has` method will always return `false`.
18
+ * Existing documents without stored attributor will not start storing attribution information. We only create the attributor
19
+ * if its tracking is enabled and we are creating a new document.
61
20
  * @param Base - base class, inherits from FluidAttributorRuntime
62
21
  * @internal
63
22
  */
@@ -1 +1 @@
1
- {"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAOH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAe9E,OAAO,EAGN,KAAK,eAAe,EACpB,KAAK,cAAc,EAEnB,MAAM,8CAA8C,CAAC;AAoBtD;;GAEG;AACH,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,yBAAgD,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;CAChD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,kBAAmB,SAAQ,yBAAyB;IACpE;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,eAAe,CAAC;IAE1C;;OAEG;IACH,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO,CAAC;IAElC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAE5D;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,UACrB,uBAAuB,KAC3B,uBAwHqC,CAAC"}
1
+ {"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,4CAA4C,CAAC;AAE9E,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,wDAAwD,CAAC;AAUhG,OAAO,EAIN,KAAK,kBAAkB,EACvB,MAAM,0BAA0B,CAAC;AAGlC;;;;;GAKG;AACH,wBAAsB,oBAAoB,CACzC,OAAO,EAAE,iBAAiB,GACxB,OAAO,CAAC,kBAAkB,GAAG,SAAS,CAAC,CAMzC;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,eAAe,UACrB,uBAAuB,KAC3B,uBAsEqC,CAAC"}
@@ -4,61 +4,42 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.mixinAttributor = exports.createRuntimeAttributor = exports.IRuntimeAttributor = exports.enableOnNewFileKey = void 0;
8
- const client_utils_1 = require("@fluid-internal/client-utils");
7
+ exports.mixinAttributor = exports.getRuntimeAttributor = void 0;
9
8
  const internal_1 = require("@fluidframework/container-runtime/internal");
10
9
  const internal_2 = require("@fluidframework/core-utils/internal");
11
- const internal_3 = require("@fluidframework/runtime-utils/internal");
12
- const internal_4 = require("@fluidframework/telemetry-utils/internal");
13
- const attributor_js_1 = require("./attributor.js");
14
- const encoders_js_1 = require("./encoders.js");
15
- const lz4Encoder_js_1 = require("./lz4Encoder.js");
16
- // Summary tree keys
17
- const attributorTreeName = ".attributor";
18
- const opBlobName = "op";
10
+ const internal_3 = require("@fluidframework/telemetry-utils/internal");
11
+ const attributorContracts_js_1 = require("./attributorContracts.js");
12
+ const runtimeAttributorDataStoreFactory_js_1 = require("./runtimeAttributorDataStoreFactory.js");
19
13
  /**
14
+ * Utility function to get the runtime attributor from the container runtime.
15
+ * @param runtime - container runtime from which attributor is to be fetched.
16
+ * @returns IRuntimeAttributor if it exists, otherwise undefined.
20
17
  * @internal
21
18
  */
22
- exports.enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
23
- /**
24
- * @internal
25
- */
26
- exports.IRuntimeAttributor = "IRuntimeAttributor";
27
- /**
28
- * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.
29
- *
30
- * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.
31
- *
32
- * @internal
33
- */
34
- function createRuntimeAttributor() {
35
- return new RuntimeAttributor();
19
+ async function getRuntimeAttributor(runtime) {
20
+ const entryPoint = await runtime.getAliasedDataStoreEntryPoint(attributorContracts_js_1.attributorDataStoreAlias);
21
+ const runtimeAttributor = (await entryPoint?.get());
22
+ return runtimeAttributor?.IRuntimeAttributor;
36
23
  }
37
- exports.createRuntimeAttributor = createRuntimeAttributor;
24
+ exports.getRuntimeAttributor = getRuntimeAttributor;
38
25
  /**
39
26
  * Mixes in logic to load and store runtime-based attribution functionality.
40
27
  *
41
- * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
42
- *
43
- * Existing documents without stored attributors will not start storing attribution information: if an
44
- * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
45
- * that attributor's `has` method will always return `false`.
28
+ * Existing documents without stored attributor will not start storing attribution information. We only create the attributor
29
+ * if its tracking is enabled and we are creating a new document.
46
30
  * @param Base - base class, inherits from FluidAttributorRuntime
47
31
  * @internal
48
32
  */
49
33
  const mixinAttributor = (Base = internal_1.ContainerRuntime) => class ContainerRuntimeWithAttributor extends Base {
50
34
  static async loadRuntime(params) {
51
35
  const { context, registryEntries, existing, requestHandler, provideEntryPoint, runtimeOptions, containerScope, containerRuntimeCtor = ContainerRuntimeWithAttributor, } = params;
52
- const runtimeAttributor = containerScope?.IRuntimeAttributor;
53
- if (!runtimeAttributor) {
54
- throw new internal_4.UsageError("ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor");
55
- }
56
- const pendingRuntimeState = context.pendingLocalState;
57
- const baseSnapshot = pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
58
- const { quorum, deltaManager, taggedLogger } = context;
59
- (0, internal_2.assert)(quorum !== undefined, 0x968 /* quorum must exist when instantiating attribution-providing runtime */);
60
- const mc = (0, internal_4.loggerToMonitoringContext)(taggedLogger);
61
- const shouldTrackAttribution = mc.config.getBoolean(exports.enableOnNewFileKey) ?? false;
36
+ const mc = (0, internal_3.loggerToMonitoringContext)(context.taggedLogger);
37
+ const factory = new runtimeAttributorDataStoreFactory_js_1.RuntimeAttributorFactory();
38
+ const registryEntriesCopy = [
39
+ ...registryEntries,
40
+ [runtimeAttributorDataStoreFactory_js_1.RuntimeAttributorFactory.type, Promise.resolve(factory)],
41
+ ];
42
+ const shouldTrackAttribution = mc.config.getBoolean(attributorContracts_js_1.enableOnNewFileKey) ?? false;
62
43
  if (shouldTrackAttribution) {
63
44
  const { options } = context;
64
45
  // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
@@ -67,116 +48,30 @@ const mixinAttributor = (Base = internal_1.ContainerRuntime) => class ContainerR
67
48
  // eslint-disable-next-line @typescript-eslint/no-unsafe-argument
68
49
  const runtime = (await Base.loadRuntime({
69
50
  context,
70
- registryEntries,
51
+ registryEntries: registryEntriesCopy,
71
52
  requestHandler,
72
53
  provideEntryPoint,
73
- // ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0
74
- initializeEntryPoint: provideEntryPoint,
75
54
  runtimeOptions,
76
55
  containerScope,
77
56
  existing,
78
57
  containerRuntimeCtor,
79
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
59
  }));
81
- runtime.runtimeAttributor = runtimeAttributor;
82
- const logger = (0, internal_4.createChildLogger)({
83
- logger: runtime.baseLogger,
84
- namespace: "Attributor",
85
- });
86
- // Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize
87
- // this to avoid blocking on such information until application actually requests some op-based attribution
88
- // info or we need to summarize. All that really needs to happen immediately is to start recording
89
- // op seq# -> attributionInfo for new ops.
90
- await internal_4.PerformanceEvent.timedExecAsync(logger, {
91
- eventName: "initialize",
92
- }, async (event) => {
93
- await runtime.runtimeAttributor?.initialize(deltaManager, quorum, baseSnapshot, async (id) => runtime.storage.readBlob(id), shouldTrackAttribution);
94
- event.end({
95
- attributionEnabledInConfig: shouldTrackAttribution,
96
- attributionEnabledInDoc: runtime.runtimeAttributor
97
- ? runtime.runtimeAttributor.isEnabled
98
- : false,
99
- });
100
- });
101
- return runtime;
102
- }
103
- addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext) {
104
- super.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);
105
- const attributorSummary = this.runtimeAttributor?.summarize();
106
- if (attributorSummary) {
107
- (0, internal_3.addSummarizeResultToSummary)(summaryTree, attributorTreeName, attributorSummary);
60
+ let runtimeAttributor;
61
+ if (shouldTrackAttribution) {
62
+ if (existing) {
63
+ runtimeAttributor = await getRuntimeAttributor(runtime);
64
+ }
65
+ else {
66
+ const datastore = await runtime.createDataStore(runtimeAttributorDataStoreFactory_js_1.RuntimeAttributorFactory.type);
67
+ const result = await datastore.trySetAlias(attributorContracts_js_1.attributorDataStoreAlias);
68
+ (0, internal_2.assert)(result === "Success", 0xa1b /* Failed to set alias for attributor data store */);
69
+ runtimeAttributor = (await datastore.entryPoint.get());
70
+ (0, internal_2.assert)(runtimeAttributor !== undefined, 0xa1c /* Attributor should be defined */);
71
+ }
108
72
  }
73
+ return runtime;
109
74
  }
110
75
  };
111
76
  exports.mixinAttributor = mixinAttributor;
112
- class RuntimeAttributor {
113
- constructor() {
114
- this.encoder = {
115
- encode: internal_2.unreachableCase,
116
- decode: internal_2.unreachableCase,
117
- };
118
- this.isEnabled = false;
119
- }
120
- get IRuntimeAttributor() {
121
- return this;
122
- }
123
- get(key) {
124
- (0, internal_2.assert)(this.opAttributor !== undefined, 0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */);
125
- if (key.type === "detached") {
126
- throw new Error("Attribution of detached keys is not yet supported.");
127
- }
128
- if (key.type === "local") {
129
- // Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current
130
- // client id in the audience. However, for read->write client transition, the container might have not yet
131
- // received a client id. This is left as a TODO as it might be more easily solved once the detached case
132
- // is settled (e.g. if it's reasonable for the host to know the current user information at container
133
- // creation time, we could just use that here as well).
134
- throw new Error("Attribution of local keys is not yet supported.");
135
- }
136
- return this.opAttributor.getAttributionInfo(key.seq);
137
- }
138
- has(key) {
139
- if (key.type === "detached") {
140
- return false;
141
- }
142
- if (key.type === "local") {
143
- return false;
144
- }
145
- return this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;
146
- }
147
- async initialize(deltaManager, quorum, baseSnapshot, readBlob, shouldAddAttributorOnNewFile) {
148
- const attributorTree = baseSnapshot?.trees[attributorTreeName];
149
- // Existing documents that don't already have a snapshot containing runtime attribution info shouldn't
150
- // inject any for now--this causes some back-compat integration problems that aren't fully worked out.
151
- const shouldExcludeAttributor = (baseSnapshot !== undefined && attributorTree === undefined) ||
152
- (baseSnapshot === undefined && !shouldAddAttributorOnNewFile);
153
- if (shouldExcludeAttributor) {
154
- // This gives a consistent error for calls to `get` on keys that don't exist.
155
- this.opAttributor = new attributor_js_1.Attributor();
156
- return;
157
- }
158
- this.isEnabled = true;
159
- this.encoder = (0, encoders_js_1.chain)(new encoders_js_1.AttributorSerializer((entries) => new attributor_js_1.OpStreamAttributor(deltaManager, quorum, entries), encoders_js_1.deltaEncoder), (0, lz4Encoder_js_1.makeLZ4Encoder)());
160
- if (attributorTree === undefined) {
161
- this.opAttributor = new attributor_js_1.OpStreamAttributor(deltaManager, quorum);
162
- }
163
- else {
164
- const id = attributorTree.blobs[opBlobName];
165
- (0, internal_2.assert)(id !== undefined, 0x50a /* Attributor tree should have op attributor summary blob. */);
166
- const blobContents = await readBlob(id);
167
- const attributorSnapshot = (0, client_utils_1.bufferToString)(blobContents, "utf8");
168
- this.opAttributor = this.encoder.decode(attributorSnapshot);
169
- }
170
- }
171
- summarize() {
172
- if (!this.isEnabled) {
173
- // Loaded existing document without attributor data: avoid injecting any data.
174
- return undefined;
175
- }
176
- (0, internal_2.assert)(this.opAttributor !== undefined, 0x50b /* RuntimeAttributor should be initialized before summarization */);
177
- const builder = new internal_3.SummaryTreeBuilder();
178
- builder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));
179
- return builder.getSummaryTree();
180
- }
181
- }
182
77
  //# sourceMappingURL=mixinAttributor.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAK9D,yEAA8E;AAQ9E,kEAA8E;AAc9E,qEAGgD;AAChD,uEAKkD;AAElD,mDAAmF;AACnF,+CAAwF;AACxF,mDAAiD;AAEjD,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACU,QAAA,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE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C,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;QAC7D,CAAC;IACF,CAAC;IAEM,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC;YACrB,8EAA8E;YAC9E,OAAO,SAAS,CAAC;QAClB,CAAC;QAED,IAAA,iBAAM,EACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,6BAAkB,EAAE,CAAC;QACzC,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC,CAAC;QACpE,OAAO,OAAO,CAAC,cAAc,EAAE,CAAC;IACjC,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport {\n\ttype IDeltaManager,\n\ttype IContainerContext,\n} from \"@fluidframework/container-definitions/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime/internal\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport {\n\ttype FluidObject,\n\ttype IRequest,\n\ttype IResponse,\n} from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { type IQuorumClients } from \"@fluidframework/driver-definitions\";\nimport {\n\ttype IDocumentMessage,\n\ttype ISnapshotTree,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype ISummaryTreeWithStats,\n\ttype ITelemetryContext,\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype NamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport {\n\tSummaryTreeBuilder,\n\taddSummarizeResultToSummary,\n} from \"@fluidframework/runtime-utils/internal\";\nimport {\n\tPerformanceEvent,\n\tUsageError,\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nimport { AttributorSerializer, type Encoder, chain, deltaEncoder } from \"./encoders.js\";\nimport { makeLZ4Encoder } from \"./lz4Encoder.js\";\n\n// Summary tree keys\nconst attributorTreeName = \".attributor\";\nconst opBlobName = \"op\";\n\n/**\n * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.\n *\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * If enabled, the runtime attributor can be asked for the attribution info for different keys.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.\n *\n * @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.\n *\n * @internal\n */\nexport function createRuntimeAttributor(): IRuntimeAttributor {\n\treturn new RuntimeAttributor();\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.\n *\n * Existing documents without stored attributors will not start storing attribution information: if an\n * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,\n * that attributor's `has` method will always return `false`.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (\n\tBase: typeof ContainerRuntime = ContainerRuntime,\n): typeof ContainerRuntime =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/**\n\t\t\t * @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t\t\t */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst runtimeAttributor = (\n\t\t\t\tcontainerScope as FluidObject<IProvideRuntimeAttributor> | undefined\n\t\t\t)?.IRuntimeAttributor;\n\t\t\tif (!runtimeAttributor) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst pendingRuntimeState = context.pendingLocalState as {\n\t\t\t\tbaseSnapshot?: ISnapshotTree;\n\t\t\t};\n\t\t\tconst baseSnapshot: ISnapshotTree | undefined =\n\t\t\t\tpendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;\n\n\t\t\tconst { quorum, deltaManager, taggedLogger } = context;\n\t\t\tassert(\n\t\t\t\tquorum !== undefined,\n\t\t\t\t0x968 /* quorum must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tconst { options } = context;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\t// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0\n\t\t\t\tinitializeEntryPoint: provideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({\n\t\t\t\tlogger: runtime.baseLogger,\n\t\t\t\tnamespace: \"Attributor\",\n\t\t\t});\n\n\t\t\t// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize\n\t\t\t// this to avoid blocking on such information until application actually requests some op-based attribution\n\t\t\t// info or we need to summarize. All that really needs to happen immediately is to start recording\n\t\t\t// op seq# -> attributionInfo for new ops.\n\t\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"initialize\",\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tawait runtime.runtimeAttributor?.initialize(\n\t\t\t\t\t\tdeltaManager,\n\t\t\t\t\t\tquorum,\n\t\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\t\t\tshouldTrackAttribution,\n\t\t\t\t\t);\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tattributionEnabledInConfig: shouldTrackAttribution,\n\t\t\t\t\t\tattributionEnabledInDoc: runtime.runtimeAttributor\n\t\t\t\t\t\t\t? runtime.runtimeAttributor.isEnabled\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn runtime;\n\t\t}\n\n\t\tprivate runtimeAttributor: RuntimeAttributor | undefined;\n\n\t\tprotected addContainerStateToSummary(\n\t\t\tsummaryTree: ISummaryTreeWithStats,\n\t\t\tfullTree: boolean,\n\t\t\ttrackState: boolean,\n\t\t\ttelemetryContext?: ITelemetryContext,\n\t\t): void {\n\t\t\tsuper.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);\n\t\t\tconst attributorSummary = this.runtimeAttributor?.summarize();\n\t\t\tif (attributorSummary) {\n\t\t\t\taddSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);\n\t\t\t}\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n\nclass RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = false;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tquorum: IQuorumClients,\n\t\tbaseSnapshot: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t\tshouldAddAttributorOnNewFile: boolean,\n\t): Promise<void> {\n\t\tconst attributorTree = baseSnapshot?.trees[attributorTreeName];\n\t\t// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't\n\t\t// inject any for now--this causes some back-compat integration problems that aren't fully worked out.\n\t\tconst shouldExcludeAttributor =\n\t\t\t(baseSnapshot !== undefined && attributorTree === undefined) ||\n\t\t\t(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);\n\t\tif (shouldExcludeAttributor) {\n\t\t\t// This gives a consistent error for calls to `get` on keys that don't exist.\n\t\t\tthis.opAttributor = new Attributor();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isEnabled = true;\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, quorum, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (attributorTree === undefined) {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, quorum);\n\t\t} else {\n\t\t\tconst id = attributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t}\n\t}\n\n\tpublic summarize(): ISummaryTreeWithStats | undefined {\n\t\tif (!this.isEnabled) {\n\t\t\t// Loaded existing document without attributor data: avoid injecting any data.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x50b /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}
1
+ {"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,yEAA8E;AAQ9E,kEAA6D;AAE7D,uEAAqF;AAErF,qEAKkC;AAClC,iGAAkF;AAElF;;;;;GAKG;AACI,KAAK,UAAU,oBAAoB,CACzC,OAA0B;IAE1B,MAAM,UAAU,GAAG,MAAM,OAAO,CAAC,6BAA6B,CAAC,iDAAwB,CAAC,CAAC;IACzF,MAAM,iBAAiB,GAAG,CAAC,MAAM,UAAU,EAAE,GAAG,EAAE,CAEtC,CAAC;IACb,OAAO,iBAAiB,EAAE,kBAAkB,C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iBAAiB,GAAG,MAAM,oBAAoB,CAAC,OAAO,CAAC,CAAC;YACzD,CAAC;iBAAM,CAAC;gBACP,MAAM,SAAS,GAAG,MAAM,OAAO,CAAC,eAAe,CAAC,+DAAwB,CAAC,IAAI,CAAC,CAAC;gBAC/E,MAAM,MAAM,GAAG,MAAM,SAAS,CAAC,WAAW,CAAC,iDAAwB,CAAC,CAAC;gBACrE,IAAA,iBAAM,EACL,MAAM,KAAK,SAAS,EACpB,KAAK,CAAC,mDAAmD,CACzD,CAAC;gBACF,iBAAiB,GAAG,CAAC,MAAM,SAAS,CAAC,UAAU,CAAC,GAAG,EAAE,CAAuB,CAAC;gBAC7E,IAAA,iBAAM,EAAC,iBAAiB,KAAK,SAAS,EAAE,KAAK,CAAC,kCAAkC,CAAC,CAAC;YACnF,CAAC;QACF,CAAC;QAED,OAAO,OAAO,CAAC;IAChB,CAAC;CACqC,CAAC;AAxE5B,QAAA,eAAe,mBAwEa","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type IContainerContext } from \"@fluidframework/container-definitions/internal\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime/internal\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime/internal\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions/internal\";\nimport {\n\ttype FluidObject,\n\ttype IRequest,\n\ttype IResponse,\n} from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { type NamedFluidDataStoreRegistryEntries } from \"@fluidframework/runtime-definitions/internal\";\nimport { loggerToMonitoringContext } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tattributorDataStoreAlias,\n\tenableOnNewFileKey,\n\ttype IProvideRuntimeAttributor,\n\ttype IRuntimeAttributor,\n} from \"./attributorContracts.js\";\nimport { RuntimeAttributorFactory } from \"./runtimeAttributorDataStoreFactory.js\";\n\n/**\n * Utility function to get the runtime attributor from the container runtime.\n * @param runtime - container runtime from which attributor is to be fetched.\n * @returns IRuntimeAttributor if it exists, otherwise undefined.\n * @internal\n */\nexport async function getRuntimeAttributor(\n\truntime: IContainerRuntime,\n): Promise<IRuntimeAttributor | undefined> {\n\tconst entryPoint = await runtime.getAliasedDataStoreEntryPoint(attributorDataStoreAlias);\n\tconst runtimeAttributor = (await entryPoint?.get()) as\n\t\t| FluidObject<IProvideRuntimeAttributor>\n\t\t| undefined;\n\treturn runtimeAttributor?.IRuntimeAttributor;\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * Existing documents without stored attributor will not start storing attribution information. We only create the attributor\n * if its tracking is enabled and we are creating a new document.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (\n\tBase: typeof ContainerRuntime = ContainerRuntime,\n): typeof ContainerRuntime =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/**\n\t\t\t * @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md\n\t\t\t */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst mc = loggerToMonitoringContext(context.taggedLogger);\n\t\t\tconst factory = new RuntimeAttributorFactory();\n\t\t\tconst registryEntriesCopy: NamedFluidDataStoreRegistryEntries = [\n\t\t\t\t...registryEntries,\n\t\t\t\t[RuntimeAttributorFactory.type, Promise.resolve(factory)],\n\t\t\t];\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tconst { options } = context;\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\t\t\t(options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries: registryEntriesCopy,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\n\t\t\tlet runtimeAttributor: IRuntimeAttributor | undefined;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\tif (existing) {\n\t\t\t\t\truntimeAttributor = await getRuntimeAttributor(runtime);\n\t\t\t\t} else {\n\t\t\t\t\tconst datastore = await runtime.createDataStore(RuntimeAttributorFactory.type);\n\t\t\t\t\tconst result = await datastore.trySetAlias(attributorDataStoreAlias);\n\t\t\t\t\tassert(\n\t\t\t\t\t\tresult === \"Success\",\n\t\t\t\t\t\t0xa1b /* Failed to set alias for attributor data store */,\n\t\t\t\t\t);\n\t\t\t\t\truntimeAttributor = (await datastore.entryPoint.get()) as IRuntimeAttributor;\n\t\t\t\t\tassert(runtimeAttributor !== undefined, 0xa1c /* Attributor should be defined */);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn runtime;\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n"]}
@@ -0,0 +1,19 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { IDeltaManager } from "@fluidframework/container-definitions/internal";
6
+ import { IDocumentMessage, type ISnapshotTree, ISequencedDocumentMessage, IQuorumClients } from "@fluidframework/driver-definitions/internal";
7
+ import { type AttributionInfo, type AttributionKey, type ISummaryTreeWithStats } from "@fluidframework/runtime-definitions/internal";
8
+ import { type IRuntimeAttributor } from "./attributorContracts.js";
9
+ export declare class RuntimeAttributor implements IRuntimeAttributor {
10
+ get IRuntimeAttributor(): IRuntimeAttributor;
11
+ get(key: AttributionKey): AttributionInfo;
12
+ has(key: AttributionKey): boolean;
13
+ private encoder;
14
+ private opAttributor;
15
+ isEnabled: boolean;
16
+ initialize(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, quorum: IQuorumClients, baseSnapshotForAttributorTree: ISnapshotTree | undefined, readBlob: (id: string) => Promise<ArrayBufferLike>): Promise<void>;
17
+ summarizeOpAttributor(): ISummaryTreeWithStats;
18
+ }
19
+ //# sourceMappingURL=runtimeAttributor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeAttributor.d.ts","sourceRoot":"","sources":["../src/runtimeAttributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,gDAAgD,CAAC;AAE/E,OAAO,EACN,gBAAgB,EAChB,KAAK,aAAa,EAClB,yBAAyB,EACzB,cAAc,EACd,MAAM,6CAA6C,CAAC;AACrD,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,qBAAqB,EAC1B,MAAM,8CAA8C,CAAC;AAItD,OAAO,EAAc,KAAK,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAI/E,qBAAa,iBAAkB,YAAW,kBAAkB;IAC3D,IAAW,kBAAkB,IAAI,kBAAkB,CAElD;IAEM,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,eAAe;IAsBzC,GAAG,CAAC,GAAG,EAAE,cAAc,GAAG,OAAO;IAYxC,OAAO,CAAC,OAAO,CAGb;IAEF,OAAO,CAAC,YAAY,CAA0B;IACvC,SAAS,UAAQ;IAEX,UAAU,CACtB,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,MAAM,EAAE,cAAc,EACtB,6BAA6B,EAAE,aAAa,GAAG,SAAS,EACxD,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,eAAe,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC;IAuBT,qBAAqB,IAAI,qBAAqB;CASrD"}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.RuntimeAttributor = void 0;
8
+ const client_utils_1 = require("@fluid-internal/client-utils");
9
+ const internal_1 = require("@fluidframework/core-utils/internal");
10
+ const internal_2 = require("@fluidframework/runtime-utils/internal");
11
+ const attributor_js_1 = require("./attributor.js");
12
+ const attributorContracts_js_1 = require("./attributorContracts.js");
13
+ const encoders_js_1 = require("./encoders.js");
14
+ const lz4Encoder_js_1 = require("./lz4Encoder.js");
15
+ class RuntimeAttributor {
16
+ constructor() {
17
+ this.encoder = {
18
+ encode: internal_1.unreachableCase,
19
+ decode: internal_1.unreachableCase,
20
+ };
21
+ this.isEnabled = true;
22
+ }
23
+ get IRuntimeAttributor() {
24
+ return this;
25
+ }
26
+ get(key) {
27
+ (0, internal_1.assert)(this.opAttributor !== undefined, 0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */);
28
+ if (key.type === "detached") {
29
+ throw new Error("Attribution of detached keys is not yet supported.");
30
+ }
31
+ if (key.type === "local") {
32
+ // Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current
33
+ // client id in the audience. However, for read->write client transition, the container might have not yet
34
+ // received a client id. This is left as a TODO as it might be more easily solved once the detached case
35
+ // is settled (e.g. if it's reasonable for the host to know the current user information at container
36
+ // creation time, we could just use that here as well).
37
+ throw new Error("Attribution of local keys is not yet supported.");
38
+ }
39
+ return this.opAttributor.getAttributionInfo(key.seq);
40
+ }
41
+ has(key) {
42
+ if (key.type === "detached") {
43
+ return false;
44
+ }
45
+ if (key.type === "local") {
46
+ return false;
47
+ }
48
+ return this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;
49
+ }
50
+ async initialize(deltaManager, quorum, baseSnapshotForAttributorTree, readBlob) {
51
+ this.encoder = (0, encoders_js_1.chain)(new encoders_js_1.AttributorSerializer((entries) => new attributor_js_1.OpStreamAttributor(deltaManager, quorum, entries), encoders_js_1.deltaEncoder), (0, lz4Encoder_js_1.makeLZ4Encoder)());
52
+ if (baseSnapshotForAttributorTree === undefined) {
53
+ this.opAttributor = new attributor_js_1.OpStreamAttributor(deltaManager, quorum);
54
+ }
55
+ else {
56
+ const id = baseSnapshotForAttributorTree.blobs[attributorContracts_js_1.opBlobName];
57
+ (0, internal_1.assert)(id !== undefined, 0x50a /* Attributor tree should have op attributor summary blob. */);
58
+ const blobContents = await readBlob(id);
59
+ const attributorSnapshot = (0, client_utils_1.bufferToString)(blobContents, "utf8");
60
+ this.opAttributor = this.encoder.decode(attributorSnapshot);
61
+ }
62
+ }
63
+ summarizeOpAttributor() {
64
+ (0, internal_1.assert)(this.opAttributor !== undefined, 0xa1d /* RuntimeAttributor should be initialized before summarization */);
65
+ const builder = new internal_2.SummaryTreeBuilder();
66
+ builder.addBlob(attributorContracts_js_1.opBlobName, this.encoder.encode(this.opAttributor));
67
+ return builder.getSummaryTree();
68
+ }
69
+ }
70
+ exports.RuntimeAttributor = RuntimeAttributor;
71
+ //# sourceMappingURL=runtimeAttributor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtimeAttributor.js","sourceRoot":"","sources":["../src/runtimeAttributor.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+DAA8D;AAE9D,kEAA8E;AAY9E,qEAA4E;AAE5E,mDAAuE;AACvE,qEAA+E;AAC/E,+CAAwF;AACxF,mDAAiD;AAEjD,MAAa,iBAAiB;IAA9B;QAuCS,YAAO,GAAiC;YAC/C,MAAM,EAAE,0BAAe;YACvB,MAAM,EAAE,0BAAe;SACvB,CAAC;QAGK,cAAS,GAAG,IAAI,CAAC;IAuCzB,CAAC;IAnFA,IAAW,kBAAkB;QAC5B,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,GAAG,CAAC,GAAmB;QAC7B,IAAA,iBAAM,EACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,mFAAmF,CACzF,CAAC;QAEF,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,MAAM,IAAI,KAAK,CAAC,oDAAoD,CAAC,CAAC;QACvE,CAAC;QAED,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC1B,wGAAwG;YACxG,0GAA0G;YAC1G,wGAAwG;YACxG,qGAAqG;YACrG,uDAAuD;YACvD,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAC;QACpE,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,CAAC,kBAAkB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACtD,CAAC;IAEM,GAAG,CAAC,GAAmB;QAC7B,IAAI,GAAG,CAAC,IAAI,KAAK,UAAU,EAAE,CAAC;YAC7B,OAAO,KAAK,CAAC;QACd,CAAC;QAED,IAAI,GAAG,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YAC1B,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC,YAAY,EAAE,qBA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D;AApFD,8CAoFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { IDeltaManager } from \"@fluidframework/container-definitions/internal\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIDocumentMessage,\n\ttype ISnapshotTree,\n\tISequencedDocumentMessage,\n\tIQuorumClients,\n} from \"@fluidframework/driver-definitions/internal\";\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype ISummaryTreeWithStats,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\n\nimport { OpStreamAttributor, type IAttributor } from \"./attributor.js\";\nimport { opBlobName, type IRuntimeAttributor } from \"./attributorContracts.js\";\nimport { AttributorSerializer, chain, deltaEncoder, type Encoder } from \"./encoders.js\";\nimport { makeLZ4Encoder } from \"./lz4Encoder.js\";\n\nexport class RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = true;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\tquorum: IQuorumClients,\n\t\tbaseSnapshotForAttributorTree: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t): Promise<void> {\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, quorum, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (baseSnapshotForAttributorTree === undefined) {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, quorum);\n\t\t} else {\n\t\t\tconst id = baseSnapshotForAttributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t}\n\t}\n\n\tpublic summarizeOpAttributor(): ISummaryTreeWithStats {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0xa1d /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}