@fluid-experimental/attributor 2.0.0-rc.1.0.6 → 2.0.0-rc.2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{.eslintrc.js → .eslintrc.cjs} +6 -2
- package/{.mocharc.js → .mocharc.cjs} +1 -1
- package/CHANGELOG.md +4 -0
- package/{api-extractor-esm.json → api-extractor-cjs.json} +5 -1
- package/api-extractor-lint.json +1 -1
- package/api-extractor.json +1 -1
- package/api-report/attributor.api.md +1 -1
- package/dist/attributor-untrimmed.d.ts +6 -3
- package/dist/attributor.d.ts +3 -3
- package/dist/attributor.d.ts.map +1 -1
- package/dist/attributor.js +0 -1
- package/dist/attributor.js.map +1 -1
- package/dist/encoders.d.ts +10 -4
- package/dist/encoders.d.ts.map +1 -1
- package/dist/encoders.js +13 -7
- package/dist/encoders.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/dist/lz4Encoder.d.ts +2 -2
- package/dist/lz4Encoder.d.ts.map +1 -1
- package/dist/lz4Encoder.js +4 -0
- package/dist/lz4Encoder.js.map +1 -1
- package/dist/mixinAttributor.d.ts +7 -4
- package/dist/mixinAttributor.d.ts.map +1 -1
- package/dist/mixinAttributor.js +20 -15
- package/dist/mixinAttributor.js.map +1 -1
- package/dist/package.json +3 -0
- package/dist/stringInterner.d.ts +9 -6
- package/dist/stringInterner.d.ts.map +1 -1
- package/dist/stringInterner.js +9 -6
- package/dist/stringInterner.js.map +1 -1
- package/dist/tsdoc-metadata.json +1 -1
- package/lib/{attributor-untrimmed.d.mts → attributor-untrimmed.d.ts} +6 -3
- package/lib/{attributor.d.mts → attributor.d.ts} +4 -4
- package/lib/attributor.d.ts.map +1 -0
- package/lib/{attributor.mjs → attributor.js} +5 -2
- package/lib/attributor.js.map +1 -0
- package/lib/{encoders.d.mts → encoders.d.ts} +11 -5
- package/lib/encoders.d.ts.map +1 -0
- package/lib/{encoders.mjs → encoders.js} +16 -6
- package/lib/encoders.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/lz4Encoder.d.ts +7 -0
- package/lib/lz4Encoder.d.ts.map +1 -0
- package/lib/{lz4Encoder.mjs → lz4Encoder.js} +9 -1
- package/lib/lz4Encoder.js.map +1 -0
- package/lib/{mixinAttributor.d.mts → mixinAttributor.d.ts} +8 -5
- package/lib/mixinAttributor.d.ts.map +1 -0
- package/lib/{mixinAttributor.mjs → mixinAttributor.js} +19 -14
- package/lib/mixinAttributor.js.map +1 -0
- package/lib/{stringInterner.d.mts → stringInterner.d.ts} +10 -7
- package/lib/stringInterner.d.ts.map +1 -0
- package/lib/{stringInterner.mjs → stringInterner.js} +10 -7
- package/lib/stringInterner.js.map +1 -0
- package/lib/test/attribution/dirname.cjs +16 -0
- package/lib/test/attribution/dirname.cjs.map +1 -0
- package/lib/test/attribution/sharedString.attribution.spec.js +398 -0
- package/lib/test/attribution/sharedString.attribution.spec.js.map +1 -0
- package/lib/test/attributor.spec.js +32 -0
- package/lib/test/attributor.spec.js.map +1 -0
- package/lib/test/attributorSerializer.spec.js +123 -0
- package/lib/test/attributorSerializer.spec.js.map +1 -0
- package/lib/test/deltaEncoder.spec.js +36 -0
- package/lib/test/deltaEncoder.spec.js.map +1 -0
- package/lib/test/lz4Encoder.spec.js +27 -0
- package/lib/test/lz4Encoder.spec.js.map +1 -0
- package/lib/test/mixinAttributor.spec.js +219 -0
- package/lib/test/mixinAttributor.spec.js.map +1 -0
- package/lib/test/opStreamAttributor.spec.js +43 -0
- package/lib/test/opStreamAttributor.spec.js.map +1 -0
- package/lib/test/stringInterner.spec.js +71 -0
- package/lib/test/stringInterner.spec.js.map +1 -0
- package/lib/test/utils.js +32 -0
- package/lib/test/utils.js.map +1 -0
- package/package.json +42 -59
- package/src/attributor.ts +8 -6
- package/src/encoders.ts +16 -11
- package/src/index.ts +3 -3
- package/src/lz4Encoder.ts +10 -6
- package/src/mixinAttributor.ts +41 -26
- package/src/stringInterner.ts +10 -7
- package/tsconfig.cjs.json +7 -0
- package/tsconfig.json +2 -5
- package/lib/attributor.d.mts.map +0 -1
- package/lib/attributor.mjs.map +0 -1
- package/lib/encoders.d.mts.map +0 -1
- package/lib/encoders.mjs.map +0 -1
- package/lib/index.d.mts +0 -3
- package/lib/index.d.mts.map +0 -1
- package/lib/index.mjs +0 -3
- package/lib/index.mjs.map +0 -1
- package/lib/lz4Encoder.d.mts +0 -7
- package/lib/lz4Encoder.d.mts.map +0 -1
- package/lib/lz4Encoder.mjs.map +0 -1
- package/lib/mixinAttributor.d.mts.map +0 -1
- package/lib/mixinAttributor.mjs.map +0 -1
- package/lib/stringInterner.d.mts.map +0 -1
- package/lib/stringInterner.mjs.map +0 -1
- /package/lib/{attributor-alpha.d.mts → attributor-alpha.d.ts} +0 -0
- /package/lib/{attributor-beta.d.mts → attributor-beta.d.ts} +0 -0
- /package/lib/{attributor-public.d.mts → attributor-public.d.ts} +0 -0
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
module.exports = {
|
|
7
|
-
extends: [require.resolve("@fluidframework/eslint-config-fluid
|
|
7
|
+
extends: [require.resolve("@fluidframework/eslint-config-fluid"), "prettier"],
|
|
8
8
|
parserOptions: {
|
|
9
9
|
project: ["./tsconfig.json", "./src/test/tsconfig.json"],
|
|
10
10
|
},
|
|
@@ -13,7 +13,11 @@ module.exports = {
|
|
|
13
13
|
// Rules only for test files
|
|
14
14
|
files: ["*.spec.ts", "src/test/**"],
|
|
15
15
|
rules: {
|
|
16
|
-
"import/no-nodejs-modules": [
|
|
16
|
+
"import/no-nodejs-modules": [
|
|
17
|
+
"error",
|
|
18
|
+
{ allow: ["node:assert", "node:fs", "node:path"] },
|
|
19
|
+
],
|
|
20
|
+
"unicorn/prefer-module": "off",
|
|
17
21
|
},
|
|
18
22
|
},
|
|
19
23
|
],
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
"use strict";
|
|
7
7
|
|
|
8
|
-
const getFluidTestMochaConfig = require("@
|
|
8
|
+
const getFluidTestMochaConfig = require("@fluid-internal/mocha-test-setup/mocharc-common");
|
|
9
9
|
|
|
10
10
|
const packageDir = __dirname;
|
|
11
11
|
const config = getFluidTestMochaConfig(packageDir);
|
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
|
|
3
|
-
"extends": "../../../common/build/build-common/api-extractor-base
|
|
3
|
+
"extends": "../../../common/build/build-common/api-extractor-base.cjs.primary.json",
|
|
4
|
+
// CJS is actually secondary; so, no report.
|
|
5
|
+
"apiReport": {
|
|
6
|
+
"enabled": false
|
|
7
|
+
}
|
|
4
8
|
}
|
package/api-extractor-lint.json
CHANGED
package/api-extractor.json
CHANGED
|
@@ -24,7 +24,7 @@ export class Attributor implements IAttributor {
|
|
|
24
24
|
tryGetAttributionInfo(key: number): AttributionInfo | undefined;
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// @internal
|
|
27
|
+
// @internal
|
|
28
28
|
export function createRuntimeAttributor(): IRuntimeAttributor;
|
|
29
29
|
|
|
30
30
|
// @internal (undocumented)
|
|
@@ -31,8 +31,10 @@ export declare class Attributor implements IAttributor {
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
35
|
-
*
|
|
34
|
+
* Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.
|
|
35
|
+
*
|
|
36
|
+
* @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.
|
|
37
|
+
*
|
|
36
38
|
* @internal
|
|
37
39
|
*/
|
|
38
40
|
export declare function createRuntimeAttributor(): IRuntimeAttributor;
|
|
@@ -79,7 +81,8 @@ export declare const IRuntimeAttributor: keyof IProvideRuntimeAttributor;
|
|
|
79
81
|
/**
|
|
80
82
|
* Provides access to attribution information stored on the container runtime.
|
|
81
83
|
*
|
|
82
|
-
* Attributors are only populated after the container runtime they are injected
|
|
84
|
+
* @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.
|
|
85
|
+
*
|
|
83
86
|
* @sealed
|
|
84
87
|
* @internal
|
|
85
88
|
*/
|
package/dist/attributor.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
2
|
-
import { AttributionInfo } from "@fluidframework/runtime-definitions";
|
|
3
|
-
import { IAudience, IDeltaManager } from "@fluidframework/container-definitions";
|
|
1
|
+
import { type IDocumentMessage, type ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
2
|
+
import { type AttributionInfo } from "@fluidframework/runtime-definitions";
|
|
3
|
+
import { type IAudience, type IDeltaManager } from "@fluidframework/container-definitions";
|
|
4
4
|
/**
|
|
5
5
|
* Provides lookup between attribution keys and their associated attribution information.
|
|
6
6
|
* @internal
|
package/dist/attributor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAKA,OAAO,
|
|
1
|
+
{"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,gBAAgB,EACrB,KAAK,yBAAyB,EAC9B,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAE3E,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,MAAM,uCAAuC,CAAC;AAE3F;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IAEjD;;;OAGG;IACH,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAEhE;;OAEG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAIvD;AAED;;;GAGG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC7C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE3D;;OAEG;gBACgB,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAIvE;;OAEG;IACI,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe;IAQvD;;OAEG;IACI,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAItE;;OAEG;IACI,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAG7D;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,UAAW,YAAW,WAAW;gBAEvE,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,QAAQ,EAAE,SAAS,EACnB,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAmBrD"}
|
package/dist/attributor.js
CHANGED
|
@@ -52,7 +52,6 @@ class OpStreamAttributor extends Attributor {
|
|
|
52
52
|
super(initialEntries);
|
|
53
53
|
deltaManager.on("op", (message) => {
|
|
54
54
|
// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
56
55
|
const client = audience.getMember(message.clientId);
|
|
57
56
|
if (message.type === "op") {
|
|
58
57
|
// TODO: This case may be legitimate, and if so we need to figure out how to handle it.
|
package/dist/attributor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAAoD;
|
|
1
|
+
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAAoD;AAMpD,qEAA6D;AA8B7D;;;GAGG;AACH,MAAa,UAAU;IAGtB;;OAEG;IACH,YAAmB,cAAoD;QACtE,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,kBAAkB,CAAC,GAAW;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,4BAAU,CAAC,uDAAuD,GAAG,GAAG,CAAC,CAAC;SACpF;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;OAEG;IACI,qBAAqB,CAAC,GAAW;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,OAAO;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;CACD;AAlCD,gCAkCC;AAED;;;;GAIG;AACH,MAAa,kBAAmB,SAAQ,UAAU;IACjD,YACC,YAAwE,EACxE,QAAmB,EACnB,cAAoD;QAEpD,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,OAAkC,EAAE,EAAE;YAC5D,+FAA+F;YAC/F,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,QAAkB,CAAC,CAAC;YAC9D,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE;gBAC1B,uFAAuF;gBACvF,IAAA,mBAAM,EACL,MAAM,KAAK,SAAS,EACpB,KAAK,CAAC,oDAAoD,CAC1D,CAAC;gBACF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE;oBAC1C,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,OAAO,CAAC,SAAS;iBAC5B,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD;AAvBD,gDAuBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { assert } from \"@fluidframework/core-utils\";\nimport {\n\ttype IDocumentMessage,\n\ttype ISequencedDocumentMessage,\n} from \"@fluidframework/protocol-definitions\";\nimport { type AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\nimport { type IAudience, type IDeltaManager } from \"@fluidframework/container-definitions\";\n\n/**\n * Provides lookup between attribution keys and their associated attribution information.\n * @internal\n */\nexport interface IAttributor {\n\t/**\n\t * Retrieves attribution information associated with a particular key.\n\t * @param key - Attribution key to look up.\n\t * @throws If no attribution information is recorded for that key.\n\t */\n\tgetAttributionInfo(key: number): AttributionInfo;\n\n\t/**\n\t * @param key - Attribution key to look up.\n\t * @returns the attribution information associated with the provided key, or undefined if no information exists.\n\t */\n\ttryGetAttributionInfo(key: number): AttributionInfo | undefined;\n\n\t/**\n\t * @returns an iterable of (attribution key, attribution info) pairs for each stored key.\n\t */\n\tentries(): IterableIterator<[number, AttributionInfo]>;\n\n\t// TODO:\n\t// - GC\n}\n\n/**\n * {@inheritdoc IAttributor}\n * @internal\n */\nexport class Attributor implements IAttributor {\n\tprotected readonly keyToInfo: Map<number, AttributionInfo>;\n\n\t/**\n\t * @param initialEntries - Any entries which should be populated on instantiation.\n\t */\n\tpublic constructor(initialEntries?: Iterable<[number, AttributionInfo]>) {\n\t\tthis.keyToInfo = new Map(initialEntries ?? []);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.getAttributionInfo}\n\t */\n\tpublic getAttributionInfo(key: number): AttributionInfo {\n\t\tconst result = this.tryGetAttributionInfo(key);\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`Requested attribution information for unstored key: ${key}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.tryGetAttributionInfo}\n\t */\n\tpublic tryGetAttributionInfo(key: number): AttributionInfo | undefined {\n\t\treturn this.keyToInfo.get(key);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.entries}\n\t */\n\tpublic entries(): IterableIterator<[number, AttributionInfo]> {\n\t\treturn this.keyToInfo.entries();\n\t}\n}\n\n/**\n * Attributor which listens to an op stream and records entries for each op.\n * Sequence numbers are used as attribution keys.\n * @internal\n */\nexport class OpStreamAttributor extends Attributor implements IAttributor {\n\tpublic constructor(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\taudience: IAudience,\n\t\tinitialEntries?: Iterable<[number, AttributionInfo]>,\n\t) {\n\t\tsuper(initialEntries);\n\t\tdeltaManager.on(\"op\", (message: ISequencedDocumentMessage) => {\n\t\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\t\tconst client = audience.getMember(message.clientId as string);\n\t\t\tif (message.type === \"op\") {\n\t\t\t\t// TODO: This case may be legitimate, and if so we need to figure out how to handle it.\n\t\t\t\tassert(\n\t\t\t\t\tclient !== undefined,\n\t\t\t\t\t0x4af /* Received message from user not in the audience */,\n\t\t\t\t);\n\t\t\t\tthis.keyToInfo.set(message.sequenceNumber, {\n\t\t\t\t\tuser: client.user,\n\t\t\t\t\ttimestamp: message.timestamp,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
|
package/dist/encoders.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AttributionInfo } from "@fluidframework/runtime-definitions";
|
|
2
|
-
import { IAttributor } from "./attributor";
|
|
3
|
-
import { InternedStringId } from "./stringInterner";
|
|
1
|
+
import { type AttributionInfo } from "@fluidframework/runtime-definitions";
|
|
2
|
+
import { type IAttributor } from "./attributor.js";
|
|
3
|
+
import { type InternedStringId } from "./stringInterner.js";
|
|
4
4
|
export interface Encoder<TDecoded, TEncoded> {
|
|
5
5
|
encode(decoded: TDecoded): TEncoded;
|
|
6
6
|
decode(encoded: TEncoded): TDecoded;
|
|
@@ -18,11 +18,17 @@ export declare class AttributorSerializer implements IAttributorSerializer {
|
|
|
18
18
|
private readonly makeAttributor;
|
|
19
19
|
private readonly timestampEncoder;
|
|
20
20
|
constructor(makeAttributor: (entries: Iterable<[number, AttributionInfo]>) => IAttributor, timestampEncoder: TimestampEncoder);
|
|
21
|
+
/**
|
|
22
|
+
* {@inheritDoc Encoder.encode}
|
|
23
|
+
*/
|
|
21
24
|
encode(attributor: IAttributor): SerializedAttributor;
|
|
25
|
+
/**
|
|
26
|
+
* {@inheritDoc Encoder.decode}
|
|
27
|
+
*/
|
|
22
28
|
decode(encoded: SerializedAttributor): IAttributor;
|
|
23
29
|
}
|
|
24
30
|
/**
|
|
25
|
-
*
|
|
31
|
+
* Creates an encoder which composes `a` and `b`.
|
|
26
32
|
*/
|
|
27
33
|
export declare const chain: <T1, T2, T3>(a: Encoder<T1, T2>, b: Encoder<T2, T3>) => Encoder<T1, T3>;
|
|
28
34
|
//# sourceMappingURL=encoders.d.ts.map
|
package/dist/encoders.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoders.d.ts","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"encoders.d.ts","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC3E,OAAO,EAAE,KAAK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
8
|
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
|
-
const
|
|
9
|
+
const stringInterner_js_1 = require("./stringInterner.js");
|
|
10
10
|
exports.deltaEncoder = {
|
|
11
11
|
encode: (timestamps) => {
|
|
12
|
-
const deltaTimestamps =
|
|
12
|
+
const deltaTimestamps = Array.from({ length: timestamps.length });
|
|
13
13
|
let prev = 0;
|
|
14
14
|
for (let i = 0; i < timestamps.length; i++) {
|
|
15
15
|
deltaTimestamps[i] = timestamps[i] - prev;
|
|
@@ -19,7 +19,7 @@ exports.deltaEncoder = {
|
|
|
19
19
|
},
|
|
20
20
|
decode: (encoded) => {
|
|
21
21
|
(0, core_utils_1.assert)(Array.isArray(encoded), 0x4b0 /* Encoded timestamps should be an array of numbers */);
|
|
22
|
-
const timestamps =
|
|
22
|
+
const timestamps = Array.from({ length: encoded.length });
|
|
23
23
|
let cumulativeSum = 0;
|
|
24
24
|
for (let i = 0; i < encoded.length; i++) {
|
|
25
25
|
cumulativeSum += encoded[i];
|
|
@@ -33,8 +33,11 @@ class AttributorSerializer {
|
|
|
33
33
|
this.makeAttributor = makeAttributor;
|
|
34
34
|
this.timestampEncoder = timestampEncoder;
|
|
35
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc Encoder.encode}
|
|
38
|
+
*/
|
|
36
39
|
encode(attributor) {
|
|
37
|
-
const interner = new
|
|
40
|
+
const interner = new stringInterner_js_1.MutableStringInterner();
|
|
38
41
|
const seqs = [];
|
|
39
42
|
const timestamps = [];
|
|
40
43
|
const attributionRefs = [];
|
|
@@ -52,12 +55,15 @@ class AttributorSerializer {
|
|
|
52
55
|
};
|
|
53
56
|
return serialized;
|
|
54
57
|
}
|
|
58
|
+
/**
|
|
59
|
+
* {@inheritDoc Encoder.decode}
|
|
60
|
+
*/
|
|
55
61
|
decode(encoded) {
|
|
56
|
-
const interner = new
|
|
62
|
+
const interner = new stringInterner_js_1.MutableStringInterner(encoded.interner);
|
|
57
63
|
const { seqs, timestamps: encodedTimestamps, attributionRefs } = encoded;
|
|
58
64
|
const timestamps = this.timestampEncoder.decode(encodedTimestamps);
|
|
59
65
|
(0, core_utils_1.assert)(seqs.length === timestamps.length && timestamps.length === attributionRefs.length, 0x4b1 /* serialized attribution columns should have the same length */);
|
|
60
|
-
const entries =
|
|
66
|
+
const entries = Array.from({ length: seqs.length });
|
|
61
67
|
for (let i = 0; i < seqs.length; i++) {
|
|
62
68
|
const key = seqs[i];
|
|
63
69
|
const timestamp = timestamps[i];
|
|
@@ -70,7 +76,7 @@ class AttributorSerializer {
|
|
|
70
76
|
}
|
|
71
77
|
exports.AttributorSerializer = AttributorSerializer;
|
|
72
78
|
/**
|
|
73
|
-
*
|
|
79
|
+
* Creates an encoder which composes `a` and `b`.
|
|
74
80
|
*/
|
|
75
81
|
const chain = (a, b) => ({
|
|
76
82
|
encode: (content) => b.encode(a.encode(content)),
|
package/dist/encoders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoders.js","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAAoD;AAIpD,
|
|
1
|
+
{"version":3,"file":"encoders.js","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAAoD;AAIpD,2DAAmF;AAWtE,QAAA,YAAY,GAAqB;IAC7C,MAAM,EAAE,CAAC,UAAoB,EAAE,EAAE;QAChC,MAAM,eAAe,GAAa,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC;QAC5E,IAAI,IAAI,GAAG,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;YAC3C,eAAe,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;YAC1C,IAAI,GAAG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AI,EAAE,SAAS,EAAE,CAAC,CAAC;SACxC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACD;AAtDD,oDAsDC;AAED;;GAEG;AACI,MAAM,KAAK,GAAG,CAAa,CAAkB,EAAE,CAAkB,EAAmB,EAAE,CAAC,CAAC;IAC9F,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IAChD,MAAM,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CAChD,CAAC,CAAC;AAHU,QAAA,KAAK,SAGf","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { assert } from \"@fluidframework/core-utils\";\nimport { type IUser } from \"@fluidframework/protocol-definitions\";\nimport { type AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { type IAttributor } from \"./attributor.js\";\nimport { type InternedStringId, MutableStringInterner } from \"./stringInterner.js\";\n\nexport interface Encoder<TDecoded, TEncoded> {\n\tencode(decoded: TDecoded): TEncoded;\n\tdecode(encoded: TEncoded): TDecoded;\n}\n\n// Note: the encoded format doesn't matter as long as it's serializable;\n// these types could be weakened.\nexport type TimestampEncoder = Encoder<number[], number[]>;\n\nexport const deltaEncoder: TimestampEncoder = {\n\tencode: (timestamps: number[]) => {\n\t\tconst deltaTimestamps: number[] = Array.from({ length: timestamps.length });\n\t\tlet prev = 0;\n\t\tfor (let i = 0; i < timestamps.length; i++) {\n\t\t\tdeltaTimestamps[i] = timestamps[i] - prev;\n\t\t\tprev = timestamps[i];\n\t\t}\n\t\treturn deltaTimestamps;\n\t},\n\tdecode: (encoded: unknown) => {\n\t\tassert(\n\t\t\tArray.isArray(encoded),\n\t\t\t0x4b0 /* Encoded timestamps should be an array of numbers */,\n\t\t);\n\t\tconst timestamps: number[] = Array.from({ length: encoded.length });\n\t\tlet cumulativeSum = 0;\n\t\tfor (let i = 0; i < encoded.length; i++) {\n\t\t\tcumulativeSum += encoded[i];\n\t\t\ttimestamps[i] = cumulativeSum;\n\t\t}\n\t\treturn timestamps;\n\t},\n};\n\nexport type IAttributorSerializer = Encoder<IAttributor, SerializedAttributor>;\n\nexport interface SerializedAttributor {\n\tinterner: readonly string[] /* result of calling getSerializable() on a StringInterner */;\n\tseqs: number[];\n\ttimestamps: number[];\n\tattributionRefs: InternedStringId[];\n}\n\nexport class AttributorSerializer implements IAttributorSerializer {\n\tpublic constructor(\n\t\tprivate readonly makeAttributor: (\n\t\t\tentries: Iterable<[number, AttributionInfo]>,\n\t\t) => IAttributor,\n\t\tprivate readonly timestampEncoder: TimestampEncoder,\n\t) {}\n\n\t/**\n\t * {@inheritDoc Encoder.encode}\n\t */\n\tpublic encode(attributor: IAttributor): SerializedAttributor {\n\t\tconst interner = new MutableStringInterner();\n\t\tconst seqs: number[] = [];\n\t\tconst timestamps: number[] = [];\n\t\tconst attributionRefs: InternedStringId[] = [];\n\t\tfor (const [seq, { user, timestamp }] of attributor.entries()) {\n\t\t\tseqs.push(seq);\n\t\t\ttimestamps.push(timestamp);\n\t\t\tconst ref = interner.getOrCreateInternedId(JSON.stringify(user));\n\t\t\tattributionRefs.push(ref);\n\t\t}\n\n\t\tconst serialized: SerializedAttributor = {\n\t\t\tinterner: interner.getSerializable(),\n\t\t\tseqs,\n\t\t\ttimestamps: this.timestampEncoder.encode(timestamps),\n\t\t\tattributionRefs,\n\t\t};\n\n\t\treturn serialized;\n\t}\n\n\t/**\n\t * {@inheritDoc Encoder.decode}\n\t */\n\tpublic decode(encoded: SerializedAttributor): IAttributor {\n\t\tconst interner = new MutableStringInterner(encoded.interner);\n\t\tconst { seqs, timestamps: encodedTimestamps, attributionRefs } = encoded;\n\t\tconst timestamps = this.timestampEncoder.decode(encodedTimestamps);\n\t\tassert(\n\t\t\tseqs.length === timestamps.length && timestamps.length === attributionRefs.length,\n\t\t\t0x4b1 /* serialized attribution columns should have the same length */,\n\t\t);\n\t\tconst entries: [number, AttributionInfo][] = Array.from({ length: seqs.length });\n\t\tfor (let i = 0; i < seqs.length; i++) {\n\t\t\tconst key = seqs[i];\n\t\t\tconst timestamp = timestamps[i];\n\t\t\tconst ref = attributionRefs[i];\n\t\t\tconst user = JSON.parse(interner.getString(ref)) as IUser;\n\t\t\tentries[i] = [key, { user, timestamp }];\n\t\t}\n\t\treturn this.makeAttributor(entries);\n\t}\n}\n\n/**\n * Creates an encoder which composes `a` and `b`.\n */\nexport const chain = <T1, T2, T3>(a: Encoder<T1, T2>, b: Encoder<T2, T3>): Encoder<T1, T3> => ({\n\tencode: (content) => b.encode(a.encode(content)),\n\tdecode: (content) => a.decode(b.decode(content)),\n});\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
export { Attributor,
|
|
6
|
-
export { createRuntimeAttributor, enableOnNewFileKey, IProvideRuntimeAttributor, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor";
|
|
5
|
+
export { Attributor, type IAttributor, OpStreamAttributor } from "./attributor.js";
|
|
6
|
+
export { createRuntimeAttributor, enableOnNewFileKey, type IProvideRuntimeAttributor, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.js";
|
|
7
7
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,KAAK,WAAW,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,EACN,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,kBAAkB,EAClB,eAAe,GACf,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -5,12 +5,12 @@ exports.mixinAttributor = exports.IRuntimeAttributor = exports.enableOnNewFileKe
|
|
|
5
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
6
6
|
* Licensed under the MIT License.
|
|
7
7
|
*/
|
|
8
|
-
var
|
|
9
|
-
Object.defineProperty(exports, "Attributor", { enumerable: true, get: function () { return
|
|
10
|
-
Object.defineProperty(exports, "OpStreamAttributor", { enumerable: true, get: function () { return
|
|
11
|
-
var
|
|
12
|
-
Object.defineProperty(exports, "createRuntimeAttributor", { enumerable: true, get: function () { return
|
|
13
|
-
Object.defineProperty(exports, "enableOnNewFileKey", { enumerable: true, get: function () { return
|
|
14
|
-
Object.defineProperty(exports, "IRuntimeAttributor", { enumerable: true, get: function () { return
|
|
15
|
-
Object.defineProperty(exports, "mixinAttributor", { enumerable: true, get: function () { return
|
|
8
|
+
var attributor_js_1 = require("./attributor.js");
|
|
9
|
+
Object.defineProperty(exports, "Attributor", { enumerable: true, get: function () { return attributor_js_1.Attributor; } });
|
|
10
|
+
Object.defineProperty(exports, "OpStreamAttributor", { enumerable: true, get: function () { return attributor_js_1.OpStreamAttributor; } });
|
|
11
|
+
var mixinAttributor_js_1 = require("./mixinAttributor.js");
|
|
12
|
+
Object.defineProperty(exports, "createRuntimeAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.createRuntimeAttributor; } });
|
|
13
|
+
Object.defineProperty(exports, "enableOnNewFileKey", { enumerable: true, get: function () { return mixinAttributor_js_1.enableOnNewFileKey; } });
|
|
14
|
+
Object.defineProperty(exports, "IRuntimeAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.IRuntimeAttributor; } });
|
|
15
|
+
Object.defineProperty(exports, "mixinAttributor", { enumerable: true, get: function () { return mixinAttributor_js_1.mixinAttributor; } });
|
|
16
16
|
//# 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;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,iDAAmF;AAA1E,2GAAA,UAAU,OAAA;AAAoB,mHAAA,kBAAkB,OAAA;AACzD,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 */\nexport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nexport {\n\tcreateRuntimeAttributor,\n\tenableOnNewFileKey,\n\ttype IProvideRuntimeAttributor,\n\tIRuntimeAttributor,\n\tmixinAttributor,\n} from \"./mixinAttributor.js\";\n"]}
|
package/dist/lz4Encoder.d.ts
CHANGED
package/dist/lz4Encoder.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lz4Encoder.d.ts","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,QAAQ,EAAE,MAAM,uCAAuC,CAAC;
|
|
1
|
+
{"version":3,"file":"lz4Encoder.d.ts","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7C;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAgBhE"}
|
package/dist/lz4Encoder.js
CHANGED
|
@@ -7,6 +7,8 @@ exports.makeLZ4Encoder = void 0;
|
|
|
7
7
|
*/
|
|
8
8
|
const lz4js_1 = require("lz4js");
|
|
9
9
|
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
10
|
+
// TODO: document this
|
|
11
|
+
// eslint-disable-next-line jsdoc/require-description
|
|
10
12
|
/**
|
|
11
13
|
* @alpha
|
|
12
14
|
*/
|
|
@@ -14,11 +16,13 @@ function makeLZ4Encoder() {
|
|
|
14
16
|
return {
|
|
15
17
|
encode: (decoded) => {
|
|
16
18
|
const uncompressed = new TextEncoder().encode(JSON.stringify(decoded));
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
17
20
|
const compressed = (0, lz4js_1.compress)(uncompressed);
|
|
18
21
|
return (0, client_utils_1.bufferToString)(compressed, "base64");
|
|
19
22
|
},
|
|
20
23
|
decode: (serializedSummary) => {
|
|
21
24
|
const compressed = new Uint8Array((0, client_utils_1.stringToBuffer)(serializedSummary, "base64"));
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
22
26
|
const uncompressed = (0, lz4js_1.decompress)(compressed);
|
|
23
27
|
const decoded = JSON.parse(new TextDecoder().decode(uncompressed));
|
|
24
28
|
return decoded;
|
package/dist/lz4Encoder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lz4Encoder.js","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,iCAA6C;AAC7C,+DAA8E;AAI9E;;GAEG;AACH,SAAgB,cAAc;IAC7B,OAAO;QACN,MAAM,EAAE,CAAC,OAAoB,
|
|
1
|
+
{"version":3,"file":"lz4Encoder.js","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,iCAA6C;AAC7C,+DAA8E;AAI9E,sBAAsB;AACtB,qDAAqD;AACrD;;GAEG;AACH,SAAgB,cAAc;IAC7B,OAAO;QACN,MAAM,EAAE,CAAC,OAAoB,EAAU,EAAE;YACxC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACvE,6DAA6D;YAC7D,MAAM,UAAU,GAAG,IAAA,gBAAQ,EAAC,YAAY,CAAoB,CAAC;YAC7D,OAAO,IAAA,6BAAc,EAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,EAAE,CAAC,iBAAyB,EAAe,EAAE;YAClD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,IAAA,6BAAc,EAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC/E,6DAA6D;YAC7D,MAAM,YAAY,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAiB,CAAC;YAC5D,MAAM,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAgB,CAAC;YAClF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;AACH,CAAC;AAhBD,wCAgBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { compress, decompress } from \"lz4js\";\nimport { bufferToString, stringToBuffer } from \"@fluid-internal/client-utils\";\nimport { type Jsonable } from \"@fluidframework/datastore-definitions\";\nimport { type Encoder } from \"./encoders.js\";\n\n// TODO: document this\n// eslint-disable-next-line jsdoc/require-description\n/**\n * @alpha\n */\nexport function makeLZ4Encoder<T>(): Encoder<Jsonable<T>, string> {\n\treturn {\n\t\tencode: (decoded: Jsonable<T>): string => {\n\t\t\tconst uncompressed = new TextEncoder().encode(JSON.stringify(decoded));\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\t\tconst compressed = compress(uncompressed) as ArrayBufferLike;\n\t\t\treturn bufferToString(compressed, \"base64\");\n\t\t},\n\t\tdecode: (serializedSummary: string): Jsonable<T> => {\n\t\t\tconst compressed = new Uint8Array(stringToBuffer(serializedSummary, \"base64\"));\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-call\n\t\t\tconst uncompressed = decompress(compressed) as BufferSource;\n\t\t\tconst decoded = JSON.parse(new TextDecoder().decode(uncompressed)) as Jsonable<T>;\n\t\t\treturn decoded;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ContainerRuntime } from "@fluidframework/container-runtime";
|
|
2
|
-
import { AttributionInfo, AttributionKey } from "@fluidframework/runtime-definitions";
|
|
2
|
+
import { type AttributionInfo, type AttributionKey } from "@fluidframework/runtime-definitions";
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
5
5
|
*/
|
|
@@ -17,7 +17,8 @@ export interface IProvideRuntimeAttributor {
|
|
|
17
17
|
/**
|
|
18
18
|
* Provides access to attribution information stored on the container runtime.
|
|
19
19
|
*
|
|
20
|
-
* Attributors are only populated after the container runtime they are injected
|
|
20
|
+
* @remarks Attributors are only populated after the container runtime into which they are being injected has initialized.
|
|
21
|
+
*
|
|
21
22
|
* @sealed
|
|
22
23
|
* @internal
|
|
23
24
|
*/
|
|
@@ -37,8 +38,10 @@ export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
|
37
38
|
readonly isEnabled: boolean;
|
|
38
39
|
}
|
|
39
40
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
41
|
+
* Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.
|
|
42
|
+
*
|
|
43
|
+
* @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.
|
|
44
|
+
*
|
|
42
45
|
* @internal
|
|
43
46
|
*/
|
|
44
47
|
export declare function createRuntimeAttributor(): IRuntimeAttributor;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,cAAc,EAInB,MAAM,qCAAqC,CAAC;AAoB7C;;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;;;OAGG;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,uBAqHqC,CAAC"}
|
package/dist/mixinAttributor.js
CHANGED
|
@@ -6,9 +6,9 @@ const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
|
6
6
|
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
7
7
|
const core_utils_1 = require("@fluidframework/core-utils");
|
|
8
8
|
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
9
|
+
const attributor_js_1 = require("./attributor.js");
|
|
10
|
+
const encoders_js_1 = require("./encoders.js");
|
|
11
|
+
const lz4Encoder_js_1 = require("./lz4Encoder.js");
|
|
12
12
|
// Summary tree keys
|
|
13
13
|
const attributorTreeName = ".attributor";
|
|
14
14
|
const opBlobName = "op";
|
|
@@ -21,8 +21,10 @@ exports.enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
|
|
|
21
21
|
*/
|
|
22
22
|
exports.IRuntimeAttributor = "IRuntimeAttributor";
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
25
|
-
*
|
|
24
|
+
* Creates an `IRuntimeAttributor` for usage with {@link mixinAttributor}.
|
|
25
|
+
*
|
|
26
|
+
* @remarks The attributor will only be populated with data once it's passed via scope to a container runtime load flow.
|
|
27
|
+
*
|
|
26
28
|
* @internal
|
|
27
29
|
*/
|
|
28
30
|
function createRuntimeAttributor() {
|
|
@@ -42,7 +44,6 @@ exports.createRuntimeAttributor = createRuntimeAttributor;
|
|
|
42
44
|
*/
|
|
43
45
|
const mixinAttributor = (Base = container_runtime_1.ContainerRuntime) => class ContainerRuntimeWithAttributor extends Base {
|
|
44
46
|
static async loadRuntime(params) {
|
|
45
|
-
var _a;
|
|
46
47
|
const { context, registryEntries, existing, requestHandler, provideEntryPoint, runtimeOptions, containerScope, containerRuntimeCtor = ContainerRuntimeWithAttributor, } = params;
|
|
47
48
|
const runtimeAttributor = containerScope?.IRuntimeAttributor;
|
|
48
49
|
if (!runtimeAttributor) {
|
|
@@ -50,13 +51,16 @@ const mixinAttributor = (Base = container_runtime_1.ContainerRuntime) => class C
|
|
|
50
51
|
}
|
|
51
52
|
const pendingRuntimeState = context.pendingLocalState;
|
|
52
53
|
const baseSnapshot = pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
|
|
53
|
-
const { audience, deltaManager } = context;
|
|
54
|
+
const { audience, deltaManager, taggedLogger } = context;
|
|
54
55
|
(0, core_utils_1.assert)(audience !== undefined, 0x508 /* Audience must exist when instantiating attribution-providing runtime */);
|
|
55
|
-
const mc = (0, telemetry_utils_1.loggerToMonitoringContext)(
|
|
56
|
+
const mc = (0, telemetry_utils_1.loggerToMonitoringContext)(taggedLogger);
|
|
56
57
|
const shouldTrackAttribution = mc.config.getBoolean(exports.enableOnNewFileKey) ?? false;
|
|
57
58
|
if (shouldTrackAttribution) {
|
|
58
|
-
|
|
59
|
+
const { options } = context;
|
|
60
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
61
|
+
(options.attribution ?? (options.attribution = {})).track = true;
|
|
59
62
|
}
|
|
63
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
|
60
64
|
const runtime = (await Base.loadRuntime({
|
|
61
65
|
context,
|
|
62
66
|
registryEntries,
|
|
@@ -68,6 +72,7 @@ const mixinAttributor = (Base = container_runtime_1.ContainerRuntime) => class C
|
|
|
68
72
|
containerScope,
|
|
69
73
|
existing,
|
|
70
74
|
containerRuntimeCtor,
|
|
75
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
76
|
}));
|
|
72
77
|
runtime.runtimeAttributor = runtimeAttributor;
|
|
73
78
|
const logger = (0, telemetry_utils_1.createChildLogger)({ logger: runtime.logger, namespace: "Attributor" });
|
|
@@ -140,21 +145,21 @@ class RuntimeAttributor {
|
|
|
140
145
|
(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);
|
|
141
146
|
if (shouldExcludeAttributor) {
|
|
142
147
|
// This gives a consistent error for calls to `get` on keys that don't exist.
|
|
143
|
-
this.opAttributor = new
|
|
148
|
+
this.opAttributor = new attributor_js_1.Attributor();
|
|
144
149
|
return;
|
|
145
150
|
}
|
|
146
151
|
this.isEnabled = true;
|
|
147
|
-
this.encoder = (0,
|
|
148
|
-
if (attributorTree
|
|
152
|
+
this.encoder = (0, encoders_js_1.chain)(new encoders_js_1.AttributorSerializer((entries) => new attributor_js_1.OpStreamAttributor(deltaManager, audience, entries), encoders_js_1.deltaEncoder), (0, lz4Encoder_js_1.makeLZ4Encoder)());
|
|
153
|
+
if (attributorTree === undefined) {
|
|
154
|
+
this.opAttributor = new attributor_js_1.OpStreamAttributor(deltaManager, audience);
|
|
155
|
+
}
|
|
156
|
+
else {
|
|
149
157
|
const id = attributorTree.blobs[opBlobName];
|
|
150
158
|
(0, core_utils_1.assert)(id !== undefined, 0x50a /* Attributor tree should have op attributor summary blob. */);
|
|
151
159
|
const blobContents = await readBlob(id);
|
|
152
160
|
const attributorSnapshot = (0, client_utils_1.bufferToString)(blobContents, "utf8");
|
|
153
161
|
this.opAttributor = this.encoder.decode(attributorSnapshot);
|
|
154
162
|
}
|
|
155
|
-
else {
|
|
156
|
-
this.opAttributor = new attributor_1.OpStreamAttributor(deltaManager, audience);
|
|
157
|
-
}
|
|
158
163
|
}
|
|
159
164
|
summarize() {
|
|
160
165
|
if (!this.isEnabled) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":";;;AAUA,yEAAqE;AASrE,iEAAgG;AAGhG,+DAA8D;AAC9D,2DAAqE;AACrE,qEAKyC;AACzC,6CAA2E;AAC3E,yCAAgF;AAChF,6CAA8C;AAE9C,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;GAEG;AACU,QAAA,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE;;GAEG;AACU,QAAA,kBAAkB,GAAoC,oBAAoB,CAAC;AAkCxF;;;;GAIG;AACH,SAAgB,uBAAuB;IACtC,OAAO,IAAI,iBAAiB,EAAE,CAAC;AAChC,CAAC;AAFD,0DAEC;AAED;;;;;;;;;;GAUG;AACI,MAAM,eAAe,GAAG,CAAC,OAAgC,oCAAgB,EAAE,EAAE,CACnF,MAAM,8BAA+B,SAAQ,IAAI;IACzC,MAAM,CAAC,KAAK,CAAC,WAAW,C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["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport {\n\tIDocumentMessage,\n\tISequencedDocumentMessage,\n\tISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport { IAudience, IContainerContext, IDeltaManager } from \"@fluidframework/container-definitions\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime\";\nimport {\n\tAttributionInfo,\n\tAttributionKey,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n\tNamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions\";\nimport { addSummarizeResultToSummary, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { IContainerRuntime } from \"@fluidframework/container-runtime-definitions\";\nimport { IRequest, IResponse, FluidObject } from \"@fluidframework/core-interfaces\";\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils\";\nimport {\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n\tPerformanceEvent,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils\";\nimport { Attributor, IAttributor, OpStreamAttributor } from \"./attributor\";\nimport { AttributorSerializer, chain, deltaEncoder, Encoder } from \"./encoders\";\nimport { makeLZ4Encoder } from \"./lz4Encoder\";\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 * Attributors are only populated after the container runtime they are injected into has initialized.\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 * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data\n * once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.\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 = (Base: typeof ContainerRuntime = 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/** @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\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 { audience, deltaManager } = context;\n\t\t\tassert(\n\t\t\t\taudience !== undefined,\n\t\t\t\t0x508 /* Audience must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(context.taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\t(context.options.attribution ??= {}).track = true;\n\t\t\t}\n\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} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({ logger: runtime.logger, namespace: \"Attributor\" });\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\taudience,\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) {\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\taudience: IAudience,\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, audience, 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\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} else {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, audience);\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":";;;AAcA,yEAAqE;AASrE,iEAAgG;AAGhG,+DAA8D;AAC9D,2DAAqE;AACrE,qEAKyC;AACzC,mDAAmF;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IAAA,6BAAc,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SAC5D;IACF,CAAC;IAEM,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACpB,8EAA8E;YAC9E,OAAO,SAAS,CAAC;SACjB;QAED,IAAA,mBAAM,EACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,kCAAkB,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 */\nimport {\n\ttype IDocumentMessage,\n\ttype ISequencedDocumentMessage,\n\ttype ISnapshotTree,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype IAudience,\n\ttype IContainerContext,\n\ttype IDeltaManager,\n} from \"@fluidframework/container-definitions\";\nimport { ContainerRuntime } from \"@fluidframework/container-runtime\";\nimport type { IContainerRuntimeOptions } from \"@fluidframework/container-runtime\";\nimport {\n\ttype AttributionInfo,\n\ttype AttributionKey,\n\ttype ISummaryTreeWithStats,\n\ttype ITelemetryContext,\n\ttype NamedFluidDataStoreRegistryEntries,\n} from \"@fluidframework/runtime-definitions\";\nimport { addSummarizeResultToSummary, SummaryTreeBuilder } from \"@fluidframework/runtime-utils\";\nimport { type IContainerRuntime } from \"@fluidframework/container-runtime-definitions\";\nimport { type IRequest, type IResponse, type FluidObject } from \"@fluidframework/core-interfaces\";\nimport { bufferToString } from \"@fluid-internal/client-utils\";\nimport { assert, unreachableCase } from \"@fluidframework/core-utils\";\nimport {\n\tcreateChildLogger,\n\tloggerToMonitoringContext,\n\tPerformanceEvent,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils\";\nimport { Attributor, type IAttributor, OpStreamAttributor } from \"./attributor.js\";\nimport { AttributorSerializer, chain, deltaEncoder, type Encoder } 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 * 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 { audience, deltaManager, taggedLogger } = context;\n\t\t\tassert(\n\t\t\t\taudience !== undefined,\n\t\t\t\t0x508 /* Audience 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({ logger: runtime.logger, namespace: \"Attributor\" });\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\taudience,\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\taudience: IAudience,\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, audience, 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, audience);\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"]}
|