@fluid-experimental/attributor 2.0.0-internal.6.1.1 → 2.0.0-internal.6.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +4 -3
- package/dist/attributor.js +4 -4
- package/dist/attributor.js.map +1 -1
- package/dist/encoders.js +3 -3
- package/dist/encoders.js.map +1 -1
- package/dist/lz4Encoder.js +3 -3
- package/dist/lz4Encoder.js.map +1 -1
- package/dist/mixinAttributor.d.ts.map +1 -1
- package/dist/mixinAttributor.js +10 -10
- package/dist/mixinAttributor.js.map +1 -1
- package/dist/stringInterner.js +2 -2
- package/dist/stringInterner.js.map +1 -1
- package/lib/attributor.js +2 -2
- package/lib/attributor.js.map +1 -1
- package/lib/encoders.js +1 -1
- package/lib/encoders.js.map +1 -1
- package/lib/lz4Encoder.js +1 -1
- package/lib/lz4Encoder.js.map +1 -1
- package/lib/mixinAttributor.d.ts.map +1 -1
- package/lib/mixinAttributor.js +3 -3
- package/lib/mixinAttributor.js.map +1 -1
- package/lib/stringInterner.js +1 -1
- package/lib/stringInterner.js.map +1 -1
- package/package.json +23 -25
- package/src/attributor.ts +2 -2
- package/src/encoders.ts +1 -1
- package/src/lz4Encoder.ts +1 -1
- package/src/mixinAttributor.ts +4 -3
- package/src/stringInterner.ts +1 -1
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -13,9 +13,10 @@ When taking a dependency on a Fluid Framework library, we recommend using a `^`
|
|
|
13
13
|
While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
|
|
14
14
|
library consumers should always prefer `^`.
|
|
15
15
|
|
|
16
|
-
Note that when depending on a library version of the form 2.0.0-internal.x.y.z
|
|
17
|
-
|
|
18
|
-
|
|
16
|
+
Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
|
|
17
|
+
you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
|
|
18
|
+
Standard `^` and `~` ranges will not work as expected.
|
|
19
|
+
See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
|
|
19
20
|
package for more information including tools to convert between version schemes.
|
|
20
21
|
|
|
21
22
|
<!-- prettier-ignore-end -->
|
package/dist/attributor.js
CHANGED
|
@@ -5,8 +5,8 @@ exports.OpStreamAttributor = exports.Attributor = void 0;
|
|
|
5
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
6
6
|
* Licensed under the MIT License.
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
9
|
-
const
|
|
8
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
10
10
|
/**
|
|
11
11
|
* {@inheritdoc IAttributor}
|
|
12
12
|
* @alpha
|
|
@@ -24,7 +24,7 @@ class Attributor {
|
|
|
24
24
|
getAttributionInfo(key) {
|
|
25
25
|
const result = this.tryGetAttributionInfo(key);
|
|
26
26
|
if (!result) {
|
|
27
|
-
throw new
|
|
27
|
+
throw new telemetry_utils_1.UsageError(`Requested attribution information for unstored key: ${key}.`);
|
|
28
28
|
}
|
|
29
29
|
return result;
|
|
30
30
|
}
|
|
@@ -56,7 +56,7 @@ class OpStreamAttributor extends Attributor {
|
|
|
56
56
|
const client = audience.getMember(message.clientId);
|
|
57
57
|
if (message.type === "op") {
|
|
58
58
|
// TODO: This case may be legitimate, and if so we need to figure out how to handle it.
|
|
59
|
-
(0,
|
|
59
|
+
(0, core_utils_1.assert)(client !== undefined, 0x4af /* Received message from user not in the audience */);
|
|
60
60
|
this.keyToInfo.set(message.sequenceNumber, {
|
|
61
61
|
user: client.user,
|
|
62
62
|
timestamp: message.timestamp,
|
package/dist/attributor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH
|
|
1
|
+
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAAoD;AAGpD,qEAA6D;AA8B7D;;;GAGG;AACH,MAAa,UAAU;IAGtB;;OAEG;IACH,YAAY,cAAoD;QAC/D,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,4EAA4E;YAC5E,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;AAxBD,gDAwBC","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 { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\nimport { IAudience, IDeltaManager } from \"@fluidframework/container-definitions\";\n\n/**\n * Provides lookup between attribution keys and their associated attribution information.\n * @alpha\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 * @alpha\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\tconstructor(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 * @alpha\n */\nexport class OpStreamAttributor extends Attributor implements IAttributor {\n\tconstructor(\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\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\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.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.chain = exports.AttributorSerializer = exports.deltaEncoder = void 0;
|
|
|
5
5
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
6
6
|
* Licensed under the MIT License.
|
|
7
7
|
*/
|
|
8
|
-
const
|
|
8
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
9
9
|
const stringInterner_1 = require("./stringInterner");
|
|
10
10
|
exports.deltaEncoder = {
|
|
11
11
|
encode: (timestamps) => {
|
|
@@ -18,7 +18,7 @@ exports.deltaEncoder = {
|
|
|
18
18
|
return deltaTimestamps;
|
|
19
19
|
},
|
|
20
20
|
decode: (encoded) => {
|
|
21
|
-
(0,
|
|
21
|
+
(0, core_utils_1.assert)(Array.isArray(encoded), 0x4b0 /* Encoded timestamps should be an array of nummbers */);
|
|
22
22
|
const timestamps = new Array(encoded.length);
|
|
23
23
|
let cumulativeSum = 0;
|
|
24
24
|
for (let i = 0; i < encoded.length; i++) {
|
|
@@ -56,7 +56,7 @@ class AttributorSerializer {
|
|
|
56
56
|
const interner = new stringInterner_1.MutableStringInterner(encoded.interner);
|
|
57
57
|
const { seqs, timestamps: encodedTimestamps, attributionRefs } = encoded;
|
|
58
58
|
const timestamps = this.timestampEncoder.decode(encodedTimestamps);
|
|
59
|
-
(0,
|
|
59
|
+
(0, core_utils_1.assert)(seqs.length === timestamps.length && timestamps.length === attributionRefs.length, 0x4b1 /* serialized attribution columns should have the same length */);
|
|
60
60
|
const entries = new Array(seqs.length);
|
|
61
61
|
for (let i = 0; i < seqs.length; i++) {
|
|
62
62
|
const key = seqs[i];
|
package/dist/encoders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoders.js","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH
|
|
1
|
+
{"version":3,"file":"encoders.js","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":";;;AAAA;;;GAGG;AACH,2DAAoD;AAKpD,qDAA2E;AAY9D,QAAA,YAAY,GAAqB;IAC7C,MAAM,EAAE,CAAC,UAAoB,EAAE,EAAE;QAChC,MAAM,eAAe,GAAa,IAAI,KAAK,CAAC,UA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AC,CAAC;YAC/B,MAAM,IAAI,GAAU,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;YACxD,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC,CAAC;SACxC;QACD,OAAO,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC;CACD;AAhDD,oDAgDC;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 { Jsonable } from \"@fluidframework/datastore-definitions\";\nimport { IUser } from \"@fluidframework/protocol-definitions\";\nimport { AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { IAttributor } from \"./attributor\";\nimport { InternedStringId, MutableStringInterner } from \"./stringInterner\";\n\nexport interface Encoder<TDecoded, TEncoded> {\n\tencode(decoded: TDecoded): TEncoded;\n\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[] = new Array(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: Jsonable) => {\n\t\tassert(\n\t\t\tArray.isArray(encoded),\n\t\t\t0x4b0 /* Encoded timestamps should be an array of nummbers */,\n\t\t);\n\t\tconst timestamps: number[] = new Array(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\tconstructor(\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\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\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 = new Array(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: IUser = JSON.parse(interner.getString(ref));\n\t\t\tentries[i] = [key, { user, timestamp }];\n\t\t}\n\t\treturn this.makeAttributor(entries);\n\t}\n}\n\n/**\n * @returns 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/lz4Encoder.js
CHANGED
|
@@ -6,7 +6,7 @@ exports.makeLZ4Encoder = void 0;
|
|
|
6
6
|
* Licensed under the MIT License.
|
|
7
7
|
*/
|
|
8
8
|
const lz4js_1 = require("lz4js");
|
|
9
|
-
const
|
|
9
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
10
10
|
/**
|
|
11
11
|
* @alpha
|
|
12
12
|
*/
|
|
@@ -15,10 +15,10 @@ function makeLZ4Encoder() {
|
|
|
15
15
|
encode: (decoded) => {
|
|
16
16
|
const uncompressed = new TextEncoder().encode(JSON.stringify(decoded));
|
|
17
17
|
const compressed = (0, lz4js_1.compress)(uncompressed);
|
|
18
|
-
return (0,
|
|
18
|
+
return (0, client_utils_1.bufferToString)(compressed, "base64");
|
|
19
19
|
},
|
|
20
20
|
decode: (serializedSummary) => {
|
|
21
|
-
const compressed = new Uint8Array((0,
|
|
21
|
+
const compressed = new Uint8Array((0, client_utils_1.stringToBuffer)(serializedSummary, "base64"));
|
|
22
22
|
const uncompressed = (0, lz4js_1.decompress)(compressed);
|
|
23
23
|
const decoded = JSON.parse(new TextDecoder().decode(uncompressed));
|
|
24
24
|
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,EAAE,EAAE;YAChC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,IAAA,gBAAQ,EAAC,YAAY,CAAC,CAAC;YAC1C,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,MAAM,YAAY,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;YAC5C,MAAM,OAAO,GAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;YAChF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;AACH,CAAC;AAdD,wCAcC","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 \"@
|
|
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,EAAE,EAAE;YAChC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,IAAA,gBAAQ,EAAC,YAAY,CAAC,CAAC;YAC1C,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,MAAM,YAAY,GAAG,IAAA,kBAAU,EAAC,UAAU,CAAC,CAAC;YAC5C,MAAM,OAAO,GAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;YAChF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;AACH,CAAC;AAdD,wCAcC","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 { Jsonable } from \"@fluidframework/datastore-definitions\";\nimport { Encoder } from \"./encoders\";\n\n/**\n * @alpha\n */\nexport function makeLZ4Encoder<T>(): Encoder<Jsonable<T>, string> {\n\treturn {\n\t\tencode: (decoded: Jsonable<T>) => {\n\t\t\tconst uncompressed = new TextEncoder().encode(JSON.stringify(decoded));\n\t\t\tconst compressed = compress(uncompressed);\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\tconst uncompressed = decompress(compressed);\n\t\t\tconst decoded: Jsonable<T> = JSON.parse(new TextDecoder().decode(uncompressed));\n\t\t\treturn decoded;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EACN,eAAe,EACf,cAAc,EAId,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EACN,eAAe,EACf,cAAc,EAId,MAAM,qCAAqC,CAAC;AAoB7C;;;;;GAKG;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;;;;;;GAMG;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;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAE5D;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,UAAU,uBAAuB,4BAiGrB,CAAC"}
|
package/dist/mixinAttributor.js
CHANGED
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.mixinAttributor = exports.createRuntimeAttributor = exports.IRuntimeAttributor = exports.enableOnNewFileKey = void 0;
|
|
4
4
|
const container_runtime_1 = require("@fluidframework/container-runtime");
|
|
5
5
|
const runtime_utils_1 = require("@fluidframework/runtime-utils");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
6
|
+
const client_utils_1 = require("@fluid-internal/client-utils");
|
|
7
|
+
const core_utils_1 = require("@fluidframework/core-utils");
|
|
8
8
|
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
9
9
|
const attributor_1 = require("./attributor");
|
|
10
10
|
const encoders_1 = require("./encoders");
|
|
@@ -48,12 +48,12 @@ const mixinAttributor = (Base = container_runtime_1.ContainerRuntime) => class C
|
|
|
48
48
|
var _a;
|
|
49
49
|
const runtimeAttributor = containerScope?.IRuntimeAttributor;
|
|
50
50
|
if (!runtimeAttributor) {
|
|
51
|
-
throw new
|
|
51
|
+
throw new telemetry_utils_1.UsageError("ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor");
|
|
52
52
|
}
|
|
53
53
|
const pendingRuntimeState = context.pendingLocalState;
|
|
54
54
|
const baseSnapshot = pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
|
|
55
55
|
const { audience, deltaManager } = context;
|
|
56
|
-
(0,
|
|
56
|
+
(0, core_utils_1.assert)(audience !== undefined, 0x508 /* Audience must exist when instantiating attribution-providing runtime */);
|
|
57
57
|
const mc = (0, telemetry_utils_1.loggerToMonitoringContext)(context.taggedLogger);
|
|
58
58
|
const shouldTrackAttribution = mc.config.getBoolean(exports.enableOnNewFileKey) ?? false;
|
|
59
59
|
if (shouldTrackAttribution) {
|
|
@@ -91,8 +91,8 @@ exports.mixinAttributor = mixinAttributor;
|
|
|
91
91
|
class RuntimeAttributor {
|
|
92
92
|
constructor() {
|
|
93
93
|
this.encoder = {
|
|
94
|
-
encode:
|
|
95
|
-
decode:
|
|
94
|
+
encode: core_utils_1.unreachableCase,
|
|
95
|
+
decode: core_utils_1.unreachableCase,
|
|
96
96
|
};
|
|
97
97
|
this.isEnabled = false;
|
|
98
98
|
}
|
|
@@ -100,7 +100,7 @@ class RuntimeAttributor {
|
|
|
100
100
|
return this;
|
|
101
101
|
}
|
|
102
102
|
get(key) {
|
|
103
|
-
(0,
|
|
103
|
+
(0, core_utils_1.assert)(this.opAttributor !== undefined, 0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */);
|
|
104
104
|
if (key.type === "detached") {
|
|
105
105
|
throw new Error("Attribution of detached keys is not yet supported.");
|
|
106
106
|
}
|
|
@@ -138,9 +138,9 @@ class RuntimeAttributor {
|
|
|
138
138
|
this.encoder = (0, encoders_1.chain)(new encoders_1.AttributorSerializer((entries) => new attributor_1.OpStreamAttributor(deltaManager, audience, entries), encoders_1.deltaEncoder), (0, lz4Encoder_1.makeLZ4Encoder)());
|
|
139
139
|
if (attributorTree !== undefined) {
|
|
140
140
|
const id = attributorTree.blobs[opBlobName];
|
|
141
|
-
(0,
|
|
141
|
+
(0, core_utils_1.assert)(id !== undefined, 0x50a /* Attributor tree should have op attributor summary blob. */);
|
|
142
142
|
const blobContents = await readBlob(id);
|
|
143
|
-
const attributorSnapshot = (0,
|
|
143
|
+
const attributorSnapshot = (0, client_utils_1.bufferToString)(blobContents, "utf8");
|
|
144
144
|
this.opAttributor = this.encoder.decode(attributorSnapshot);
|
|
145
145
|
}
|
|
146
146
|
else {
|
|
@@ -152,7 +152,7 @@ class RuntimeAttributor {
|
|
|
152
152
|
// Loaded existing document without attributor data: avoid injecting any data.
|
|
153
153
|
return undefined;
|
|
154
154
|
}
|
|
155
|
-
(0,
|
|
155
|
+
(0, core_utils_1.assert)(this.opAttributor !== undefined, 0x50b /* RuntimeAttributor should be initialized before summarization */);
|
|
156
156
|
const builder = new runtime_utils_1.SummaryTreeBuilder();
|
|
157
157
|
builder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));
|
|
158
158
|
return builder.getSummaryTree();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":";;;AAUA,yEAAqE;AASrE,iEAAgG;AAGhG,+DAAuF;AACvF,qEAA6D;AAC7D,qEAIyC;AACzC,6CAA2E;AAC3E,yCAAgF;AAChF,6CAA8C;AAE9C,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;;;;GAKG;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,IAAI,CACvB,OAA0B,EAC1B,eAAmD,EACnD,cAEY,EACZ,iBAAuD,EAAE,EACzD,iBAA0C,OAAO,CAAC,KAAK,EACvD,QAA8B,EAC9B,OAAgC,8BAAoE;;QAEpG,MAAM,iBAAiB,GACtB,cACA,EAAE,kBAAkB,CAAC;QACtB,IAAI,CAAC,iBAAiB,EAAE;YACvB,MAAM,IAAI,4BAAU,CACnB,8FAA8F,CAC9F,CAAC;SACF;QAED,MAAM,mBAAmB,GAAG,OAAO,CAAC,iBAEnC,CAAC;QACF,MAAM,YAAY,GACjB,mBAAmB,EAAE,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC;QAE3D,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAC3C,IAAA,qBAAM,EACL,QAAQ,KAAK,SAAS,EACtB,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C;YAChE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SAC5D;aAAM;YACN,IAAI,CAAC,YAAY,GAAG,IAAI,+BAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;SACnE;IACF,CAAC;IAEM,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACpB,8EAA8E;YAC9E,OAAO,SAAS,CAAC;SACjB;QAED,IAAA,qBAAM,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\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 { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport {\n\tcreateChildLogger,\n\tPerformanceEvent,\n\tloggerToMonitoringContext,\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 * @alpha\n * Feature Gate Key -\n * Whether or not a container runtime instantiated using `mixinAttributor`'s load should generate an attributor on\n * new files. See package README for more notes on integration.\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @alpha\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @alpha\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 * @alpha\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 * @alpha\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 * @alpha\n */\nexport const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime) =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async load(\n\t\t\tcontext: IContainerContext,\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries,\n\t\t\trequestHandler?:\n\t\t\t\t| ((request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>)\n\t\t\t\t| undefined,\n\t\t\truntimeOptions: IContainerRuntimeOptions | undefined = {},\n\t\t\tcontainerScope: FluidObject | undefined = context.scope,\n\t\t\texisting?: boolean | undefined,\n\t\t\tctor: typeof ContainerRuntime = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t): Promise<ContainerRuntime> {\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.load(\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tctor,\n\t\t\t)) 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":";;;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;;;;;GAKG;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,IAAI,CACvB,OAA0B,EAC1B,eAAmD,EACnD,cAEY,EACZ,iBAAuD,EAAE,EACzD,iBAA0C,OAAO,CAAC,KAAK,EACvD,QAA8B,EAC9B,OAAgC,8BAAoE;;QAEpG,MAAM,iBAAiB,GACtB,cACA,EAAE,kBAAkB,CAAC;QACtB,IAAI,CAAC,iBAAiB,EAAE;YACvB,MAAM,IAAI,4BAAU,CACnB,8FAA8F,CAC9F,CAAC;SACF;QAED,MAAM,mBAAmB,GAAG,OAAO,CAAC,iBAEnC,CAAC;QACF,MAAM,YAAY,GACjB,mBAAmB,EAAE,YAAY,IAAI,OAAO,CAAC,YAAY,CAAC;QAE3D,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;QAC3C,IAAA,mBAAM,EACL,QAAQ,KAAK,SAAS,EACtB,KAAK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ChE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SAC5D;aAAM;YACN,IAAI,CAAC,YAAY,GAAG,IAAI,+BAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;SACnE;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\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 * @alpha\n * Feature Gate Key -\n * Whether or not a container runtime instantiated using `mixinAttributor`'s load should generate an attributor on\n * new files. See package README for more notes on integration.\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @alpha\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @alpha\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 * @alpha\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 * @alpha\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 * @alpha\n */\nexport const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime) =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async load(\n\t\t\tcontext: IContainerContext,\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries,\n\t\t\trequestHandler?:\n\t\t\t\t| ((request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>)\n\t\t\t\t| undefined,\n\t\t\truntimeOptions: IContainerRuntimeOptions | undefined = {},\n\t\t\tcontainerScope: FluidObject | undefined = context.scope,\n\t\t\texisting?: boolean | undefined,\n\t\t\tctor: typeof ContainerRuntime = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t): Promise<ContainerRuntime> {\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.load(\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tctor,\n\t\t\t)) 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"]}
|
package/dist/stringInterner.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
7
|
exports.MutableStringInterner = void 0;
|
|
8
|
-
const
|
|
8
|
+
const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
|
|
9
9
|
/**
|
|
10
10
|
* Interns strings as integers.
|
|
11
11
|
* Given a string, this class will produce a unique integer associated with that string that can then be used to
|
|
@@ -42,7 +42,7 @@ class MutableStringInterner {
|
|
|
42
42
|
getString(internId) {
|
|
43
43
|
const result = this.internedStrings[internId];
|
|
44
44
|
if (!result) {
|
|
45
|
-
throw new
|
|
45
|
+
throw new telemetry_utils_1.UsageError(`No string associated with ${internId}.`);
|
|
46
46
|
}
|
|
47
47
|
return result;
|
|
48
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringInterner.js","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAA6D;AAoB7D;;;;GAIG;AACH,MAAa,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,aAAa,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,QAAgB;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,4BAAU,CAAC,6BAA6B,QAAQ,GAAG,CAAC,CAAC;SAC/D;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED,+GAA+G;IACvG,WAAW,CAAC,KAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAwB,CAAC;QACvE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD;AAvDD,sDAuDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/
|
|
1
|
+
{"version":3,"file":"stringInterner.js","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAA6D;AAoB7D;;;;GAIG;AACH,MAAa,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,aAAa,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,QAAgB;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,4BAAU,CAAC,6BAA6B,QAAQ,GAAG,CAAC,CAAC;SAC/D;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED,+GAA+G;IACvG,WAAW,CAAC,KAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAwB,CAAC;QACvE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD;AAvDD,sDAuDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\n\n/**\n * The ID of the string that has been interned, which can be used by a {@link StringInterner} to retrieve the\n * original string.\n * @public\n */\nexport type InternedStringId = number & {\n\treadonly InternedStringId: \"e221abc9-9d17-4493-8db0-70c871a1c27c\";\n};\n\n/**\n * Interns strings as integers.\n */\nexport interface StringInterner {\n\tgetInternedId(input: string): InternedStringId | undefined;\n\tgetString(internedId: number): string;\n\tgetSerializable(): readonly string[];\n}\n\n/**\n * Interns strings as integers.\n * Given a string, this class will produce a unique integer associated with that string that can then be used to\n * retrieve the string.\n */\nexport class MutableStringInterner implements StringInterner {\n\tprivate readonly stringToInternedIdMap = new Map<string, InternedStringId>();\n\tprivate readonly internedStrings: string[] = [];\n\n\t/**\n\t * @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous\n\t * `StringInterner`'s {@link StringInterner.getSerializable} return value.\n\t */\n\tconstructor(inputStrings: readonly string[] = []) {\n\t\tfor (const value of inputStrings) {\n\t\t\tthis.getOrCreateInternedId(value);\n\t\t}\n\t}\n\n\t/**\n\t * @param input - The string to get the associated intern ID for\n\t * @returns an intern ID that is uniquely associated with the input string\n\t */\n\tpublic getOrCreateInternedId(input: string): InternedStringId {\n\t\treturn this.getInternedId(input) ?? this.createNewId(input);\n\t}\n\n\tpublic getInternedId(input: string): InternedStringId | undefined {\n\t\treturn this.stringToInternedIdMap.get(input);\n\t}\n\n\t/**\n\t *\n\t * @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been\n\t * used as inputs to calls of `getInternId`.\n\t * @returns a string that is uniquely associated with the given intern ID\n\t */\n\tpublic getString(internId: number): string {\n\t\tconst result = this.internedStrings[internId];\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`No string associated with ${internId}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of\n\t * each string.\n\t */\n\tpublic getSerializable(): readonly string[] {\n\t\treturn this.internedStrings;\n\t}\n\n\t/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */\n\tprivate createNewId(input: string): InternedStringId {\n\t\tconst internedId = this.stringToInternedIdMap.size as InternedStringId;\n\t\tthis.stringToInternedIdMap.set(input, internedId);\n\t\tthis.internedStrings.push(input);\n\t\treturn internedId;\n\t}\n}\n"]}
|
package/lib/attributor.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert } from "@fluidframework/
|
|
6
|
-
import { UsageError } from "@fluidframework/
|
|
5
|
+
import { assert } from "@fluidframework/core-utils";
|
|
6
|
+
import { UsageError } from "@fluidframework/telemetry-utils";
|
|
7
7
|
/**
|
|
8
8
|
* {@inheritdoc IAttributor}
|
|
9
9
|
* @alpha
|
package/lib/attributor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"attributor.js","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAGpD,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AA8B7D;;;GAGG;AACH,MAAM,OAAO,UAAU;IAGtB;;OAEG;IACH,YAAY,cAAoD;QAC/D,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,UAAU,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;AAED;;;;GAIG;AACH,MAAM,OAAO,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,4EAA4E;YAC5E,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,QAAkB,CAAC,CAAC;YAC9D,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE;gBAC1B,uFAAuF;gBACvF,MAAM,CACL,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","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 { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\nimport { IAudience, IDeltaManager } from \"@fluidframework/container-definitions\";\n\n/**\n * Provides lookup between attribution keys and their associated attribution information.\n * @alpha\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 * @alpha\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\tconstructor(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 * @alpha\n */\nexport class OpStreamAttributor extends Attributor implements IAttributor {\n\tconstructor(\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\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\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/lib/encoders.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert } from "@fluidframework/
|
|
5
|
+
import { assert } from "@fluidframework/core-utils";
|
|
6
6
|
import { MutableStringInterner } from "./stringInterner";
|
|
7
7
|
export const deltaEncoder = {
|
|
8
8
|
encode: (timestamps) => {
|
package/lib/encoders.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"encoders.js","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"encoders.js","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AAKpD,OAAO,EAAoB,qBAAqB,EAAE,MAAM,kBAAkB,CAAC;AAY3E,MAAM,CAAC,MAAM,YAAY,GAAqB;IAC7C,MAAM,EAAE,CAAC,UAAoB,EAAE,EAAE;QAChC,MAAM,eAAe,GAAa,IAAI,KAAK,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;QAC/D,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,UAAU,CAAC,CAAC,CAAC,CAAC;SACrB;QACD,OAAO,eAAe,CAAC;IACxB,CAAC;I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,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","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 { Jsonable } from \"@fluidframework/datastore-definitions\";\nimport { IUser } from \"@fluidframework/protocol-definitions\";\nimport { AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { IAttributor } from \"./attributor\";\nimport { InternedStringId, MutableStringInterner } from \"./stringInterner\";\n\nexport interface Encoder<TDecoded, TEncoded> {\n\tencode(decoded: TDecoded): TEncoded;\n\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[] = new Array(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: Jsonable) => {\n\t\tassert(\n\t\t\tArray.isArray(encoded),\n\t\t\t0x4b0 /* Encoded timestamps should be an array of nummbers */,\n\t\t);\n\t\tconst timestamps: number[] = new Array(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\tconstructor(\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\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\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 = new Array(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: IUser = JSON.parse(interner.getString(ref));\n\t\t\tentries[i] = [key, { user, timestamp }];\n\t\t}\n\t\treturn this.makeAttributor(entries);\n\t}\n}\n\n/**\n * @returns 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/lib/lz4Encoder.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { compress, decompress } from "lz4js";
|
|
6
|
-
import { bufferToString, stringToBuffer } from "@
|
|
6
|
+
import { bufferToString, stringToBuffer } from "@fluid-internal/client-utils";
|
|
7
7
|
/**
|
|
8
8
|
* @alpha
|
|
9
9
|
*/
|
package/lib/lz4Encoder.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lz4Encoder.js","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI9E;;GAEG;AACH,MAAM,UAAU,cAAc;IAC7B,OAAO;QACN,MAAM,EAAE,CAAC,OAAoB,EAAE,EAAE;YAChC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC1C,OAAO,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,EAAE,CAAC,iBAAyB,EAAe,EAAE;YAClD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC/E,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;YAC5C,MAAM,OAAO,GAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;YAChF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;AACH,CAAC","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 \"@
|
|
1
|
+
{"version":3,"file":"lz4Encoder.js","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAI9E;;GAEG;AACH,MAAM,UAAU,cAAc;IAC7B,OAAO;QACN,MAAM,EAAE,CAAC,OAAoB,EAAE,EAAE;YAChC,MAAM,YAAY,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;YACvE,MAAM,UAAU,GAAG,QAAQ,CAAC,YAAY,CAAC,CAAC;YAC1C,OAAO,cAAc,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;QACD,MAAM,EAAE,CAAC,iBAAyB,EAAe,EAAE;YAClD,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,cAAc,CAAC,iBAAiB,EAAE,QAAQ,CAAC,CAAC,CAAC;YAC/E,MAAM,YAAY,GAAG,UAAU,CAAC,UAAU,CAAC,CAAC;YAC5C,MAAM,OAAO,GAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;YAChF,OAAO,OAAO,CAAC;QAChB,CAAC;KACD,CAAC;AACH,CAAC","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 { Jsonable } from \"@fluidframework/datastore-definitions\";\nimport { Encoder } from \"./encoders\";\n\n/**\n * @alpha\n */\nexport function makeLZ4Encoder<T>(): Encoder<Jsonable<T>, string> {\n\treturn {\n\t\tencode: (decoded: Jsonable<T>) => {\n\t\t\tconst uncompressed = new TextEncoder().encode(JSON.stringify(decoded));\n\t\t\tconst compressed = compress(uncompressed);\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\tconst uncompressed = decompress(compressed);\n\t\t\tconst decoded: Jsonable<T> = JSON.parse(new TextDecoder().decode(uncompressed));\n\t\t\treturn decoded;\n\t\t},\n\t};\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EACN,eAAe,EACf,cAAc,EAId,MAAM,qCAAqC,CAAC;
|
|
1
|
+
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AAErE,OAAO,EACN,eAAe,EACf,cAAc,EAId,MAAM,qCAAqC,CAAC;AAoB7C;;;;;GAKG;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;;;;;;GAMG;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;;;;GAIG;AACH,wBAAgB,uBAAuB,IAAI,kBAAkB,CAE5D;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,UAAU,uBAAuB,4BAiGrB,CAAC"}
|
package/lib/mixinAttributor.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ContainerRuntime } from "@fluidframework/container-runtime";
|
|
2
2
|
import { addSummarizeResultToSummary, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { createChildLogger, PerformanceEvent,
|
|
3
|
+
import { bufferToString } from "@fluid-internal/client-utils";
|
|
4
|
+
import { assert, unreachableCase } from "@fluidframework/core-utils";
|
|
5
|
+
import { createChildLogger, loggerToMonitoringContext, PerformanceEvent, UsageError, } from "@fluidframework/telemetry-utils";
|
|
6
6
|
import { Attributor, OpStreamAttributor } from "./attributor";
|
|
7
7
|
import { AttributorSerializer, chain, deltaEncoder } from "./encoders";
|
|
8
8
|
import { makeLZ4Encoder } from "./lz4Encoder";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mixinAttributor.js","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AASrE,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGh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BAAkB,GAAG,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SAC5D;aAAM;YACN,IAAI,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;SACnE;IACF,CAAC;IAEM,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACpB,8EAA8E;YAC9E,OAAO,SAAS,CAAC;SACjB;QAED,MAAM,CACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,kBAAkB,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\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 { assert, bufferToString, unreachableCase } from \"@fluidframework/common-utils\";\nimport { UsageError } from \"@fluidframework/container-utils\";\nimport {\n\tcreateChildLogger,\n\tPerformanceEvent,\n\tloggerToMonitoringContext,\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 * @alpha\n * Feature Gate Key -\n * Whether or not a container runtime instantiated using `mixinAttributor`'s load should generate an attributor on\n * new files. See package README for more notes on integration.\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @alpha\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @alpha\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 * @alpha\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 * @alpha\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 * @alpha\n */\nexport const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime) =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async load(\n\t\t\tcontext: IContainerContext,\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries,\n\t\t\trequestHandler?:\n\t\t\t\t| ((request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>)\n\t\t\t\t| undefined,\n\t\t\truntimeOptions: IContainerRuntimeOptions | undefined = {},\n\t\t\tcontainerScope: FluidObject | undefined = context.scope,\n\t\t\texisting?: boolean | undefined,\n\t\t\tctor: typeof ContainerRuntime = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t): Promise<ContainerRuntime> {\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.load(\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tctor,\n\t\t\t)) 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":"AAUA,OAAO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC,CAAC;AASrE,OAAO,EAAE,2BAA2B,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAGhG,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AACrE,OAAO,EACN,iBAAiB,EACjB,yBAAyB,EACzB,gBAAgB,EAChB,UAAU,GACV,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAAE,UAAU,EAAe,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAC3E,OAAO,EAAE,oBAAoB,EAAE,KAAK,EAAE,YAAY,EAAW,MAAM,YAAY,CAAC;AAChF,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,oBAAoB;AACpB,MAAM,kBAAkB,GAAG,aAAa,CAAC;AACzC,MAAM,UAAU,GAAG,IAAI,CAAC;AAExB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,mCAAmC,CAAC;AAEtE;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAoC,oBAAoB,CAAC;AAkCxF;;;;GAIG;AACH,MAAM,UAAU,uBAAuB;IACtC,OAAO,IAAI,iBAAiB,EAAE,CAAC;AAChC,CAAC;AAED;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,OAAgC,gBAAgB,EAAE,EAAE,CACnF,MAAM,8BAA+B,SAAQ,IAAI;IACzC,MAAM,CAAC,KAAK,CAAC,IAAI,CACvB,OAA0B,EAC1B,eAAmD,EACnD,cAEY,EACZ,iBAA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E,OAAO,CAAC,EACpE,YAAY,CACZ,EACD,cAAc,EAAE,CAChB,CAAC;QAEF,IAAI,cAAc,KAAK,SAAS,EAAE;YACjC,MAAM,EAAE,GAAG,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YAC5C,MAAM,CACL,EAAE,KAAK,SAAS,EAChB,KAAK,CAAC,6DAA6D,CACnE,CAAC;YACF,MAAM,YAAY,GAAG,MAAM,QAAQ,CAAC,EAAE,CAAC,CAAC;YACxC,MAAM,kBAAkB,GAAG,cAAc,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;YAChE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC,CAAC;SAC5D;aAAM;YACN,IAAI,CAAC,YAAY,GAAG,IAAI,kBAAkB,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;SACnE;IACF,CAAC;IAEM,SAAS;QACf,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACpB,8EAA8E;YAC9E,OAAO,SAAS,CAAC;SACjB;QAED,MAAM,CACL,IAAI,CAAC,YAAY,KAAK,SAAS,EAC/B,KAAK,CAAC,kEAAkE,CACxE,CAAC;QACF,MAAM,OAAO,GAAG,IAAI,kBAAkB,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\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 * @alpha\n * Feature Gate Key -\n * Whether or not a container runtime instantiated using `mixinAttributor`'s load should generate an attributor on\n * new files. See package README for more notes on integration.\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @alpha\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @alpha\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 * @alpha\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 * @alpha\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 * @alpha\n */\nexport const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime) =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async load(\n\t\t\tcontext: IContainerContext,\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries,\n\t\t\trequestHandler?:\n\t\t\t\t| ((request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>)\n\t\t\t\t| undefined,\n\t\t\truntimeOptions: IContainerRuntimeOptions | undefined = {},\n\t\t\tcontainerScope: FluidObject | undefined = context.scope,\n\t\t\texisting?: boolean | undefined,\n\t\t\tctor: typeof ContainerRuntime = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t): Promise<ContainerRuntime> {\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.load(\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tctor,\n\t\t\t)) 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"]}
|
package/lib/stringInterner.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { UsageError } from "@fluidframework/
|
|
5
|
+
import { UsageError } from "@fluidframework/telemetry-utils";
|
|
6
6
|
/**
|
|
7
7
|
* Interns strings as integers.
|
|
8
8
|
* Given a string, this class will produce a unique integer associated with that string that can then be used to
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stringInterner.js","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAoB7D;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,aAAa,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,QAAgB;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,UAAU,CAAC,6BAA6B,QAAQ,GAAG,CAAC,CAAC;SAC/D;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED,+GAA+G;IACvG,WAAW,CAAC,KAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAwB,CAAC;QACvE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/
|
|
1
|
+
{"version":3,"file":"stringInterner.js","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAoB7D;;;;GAIG;AACH,MAAM,OAAO,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,aAAa,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,QAAgB;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,UAAU,CAAC,6BAA6B,QAAQ,GAAG,CAAC,CAAC;SAC/D;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED,+GAA+G;IACvG,WAAW,CAAC,KAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAwB,CAAC;QACvE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\n\n/**\n * The ID of the string that has been interned, which can be used by a {@link StringInterner} to retrieve the\n * original string.\n * @public\n */\nexport type InternedStringId = number & {\n\treadonly InternedStringId: \"e221abc9-9d17-4493-8db0-70c871a1c27c\";\n};\n\n/**\n * Interns strings as integers.\n */\nexport interface StringInterner {\n\tgetInternedId(input: string): InternedStringId | undefined;\n\tgetString(internedId: number): string;\n\tgetSerializable(): readonly string[];\n}\n\n/**\n * Interns strings as integers.\n * Given a string, this class will produce a unique integer associated with that string that can then be used to\n * retrieve the string.\n */\nexport class MutableStringInterner implements StringInterner {\n\tprivate readonly stringToInternedIdMap = new Map<string, InternedStringId>();\n\tprivate readonly internedStrings: string[] = [];\n\n\t/**\n\t * @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous\n\t * `StringInterner`'s {@link StringInterner.getSerializable} return value.\n\t */\n\tconstructor(inputStrings: readonly string[] = []) {\n\t\tfor (const value of inputStrings) {\n\t\t\tthis.getOrCreateInternedId(value);\n\t\t}\n\t}\n\n\t/**\n\t * @param input - The string to get the associated intern ID for\n\t * @returns an intern ID that is uniquely associated with the input string\n\t */\n\tpublic getOrCreateInternedId(input: string): InternedStringId {\n\t\treturn this.getInternedId(input) ?? this.createNewId(input);\n\t}\n\n\tpublic getInternedId(input: string): InternedStringId | undefined {\n\t\treturn this.stringToInternedIdMap.get(input);\n\t}\n\n\t/**\n\t *\n\t * @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been\n\t * used as inputs to calls of `getInternId`.\n\t * @returns a string that is uniquely associated with the given intern ID\n\t */\n\tpublic getString(internId: number): string {\n\t\tconst result = this.internedStrings[internId];\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`No string associated with ${internId}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of\n\t * each string.\n\t */\n\tpublic getSerializable(): readonly string[] {\n\t\treturn this.internedStrings;\n\t}\n\n\t/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */\n\tprivate createNewId(input: string): InternedStringId {\n\t\tconst internedId = this.stringToInternedIdMap.size as InternedStringId;\n\t\tthis.stringToInternedIdMap.set(input, internedId);\n\t\tthis.internedStrings.push(input);\n\t\treturn internedId;\n\t}\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluid-experimental/attributor",
|
|
3
|
-
"version": "2.0.0-internal.6.
|
|
3
|
+
"version": "2.0.0-internal.6.3.0",
|
|
4
4
|
"description": "Operation attributor",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"main": "dist/index.js",
|
|
15
15
|
"module": "lib/index.js",
|
|
16
16
|
"types": "dist/index.d.ts",
|
|
17
|
-
"
|
|
17
|
+
"c8": {
|
|
18
18
|
"all": true,
|
|
19
19
|
"cache-dir": "nyc/.cache",
|
|
20
20
|
"exclude": [
|
|
@@ -35,34 +35,34 @@
|
|
|
35
35
|
"temp-directory": "nyc/.nyc_output"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@
|
|
39
|
-
"@fluidframework/container-definitions": ">=2.0.0-internal.6.
|
|
40
|
-
"@fluidframework/container-runtime": ">=2.0.0-internal.6.
|
|
41
|
-
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.6.
|
|
42
|
-
"@fluidframework/
|
|
43
|
-
"@fluidframework/core-
|
|
44
|
-
"@fluidframework/datastore-definitions": ">=2.0.0-internal.6.
|
|
38
|
+
"@fluid-internal/client-utils": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
39
|
+
"@fluidframework/container-definitions": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
40
|
+
"@fluidframework/container-runtime": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
41
|
+
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
42
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
43
|
+
"@fluidframework/core-utils": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
44
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
45
45
|
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
46
|
-
"@fluidframework/runtime-definitions": ">=2.0.0-internal.6.
|
|
47
|
-
"@fluidframework/runtime-utils": ">=2.0.0-internal.6.
|
|
48
|
-
"@fluidframework/telemetry-utils": ">=2.0.0-internal.6.
|
|
46
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
47
|
+
"@fluidframework/runtime-utils": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
48
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
49
49
|
"lz4js": "^0.2.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.6.
|
|
52
|
+
"@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
53
53
|
"@fluid-tools/build-cli": "^0.22.0",
|
|
54
54
|
"@fluidframework/build-common": "^2.0.0",
|
|
55
55
|
"@fluidframework/build-tools": "^0.22.0",
|
|
56
|
-
"@fluidframework/driver-definitions": ">=2.0.0-internal.6.
|
|
57
|
-
"@fluidframework/eslint-config-fluid": "^2.
|
|
58
|
-
"@fluidframework/merge-tree": ">=2.0.0-internal.6.
|
|
59
|
-
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.
|
|
60
|
-
"@fluidframework/sequence": ">=2.0.0-internal.6.
|
|
61
|
-
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.
|
|
56
|
+
"@fluidframework/driver-definitions": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
57
|
+
"@fluidframework/eslint-config-fluid": "^2.1.0",
|
|
58
|
+
"@fluidframework/merge-tree": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
59
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
60
|
+
"@fluidframework/sequence": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
61
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.6.3.0 <2.0.0-internal.6.4.0",
|
|
62
62
|
"@microsoft/api-extractor": "^7.34.4",
|
|
63
63
|
"@types/mocha": "^9.1.1",
|
|
64
64
|
"@types/node": "^16.18.38",
|
|
65
|
-
"
|
|
65
|
+
"c8": "^7.7.1",
|
|
66
66
|
"copyfiles": "^2.4.1",
|
|
67
67
|
"cross-env": "^7.0.3",
|
|
68
68
|
"eslint": "~8.6.0",
|
|
@@ -70,7 +70,6 @@
|
|
|
70
70
|
"mocha-json-output-reporter": "^2.0.1",
|
|
71
71
|
"mocha-multi-reporters": "^1.5.1",
|
|
72
72
|
"moment": "^2.21.0",
|
|
73
|
-
"nyc": "^15.1.0",
|
|
74
73
|
"prettier": "~2.6.2",
|
|
75
74
|
"rimraf": "^4.4.0",
|
|
76
75
|
"typescript": "~4.5.5"
|
|
@@ -87,7 +86,7 @@
|
|
|
87
86
|
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
88
87
|
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
89
88
|
"ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
|
|
90
|
-
"clean": "rimraf --glob
|
|
89
|
+
"clean": "rimraf --glob 'dist' 'lib' '*.tsbuildinfo' '*.build.log' '_api-extractor-temp' 'nyc'",
|
|
91
90
|
"eslint": "eslint --format stylish src",
|
|
92
91
|
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
93
92
|
"format": "npm run prettier:fix",
|
|
@@ -96,9 +95,8 @@
|
|
|
96
95
|
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
|
|
97
96
|
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
|
|
98
97
|
"test": "npm run test:mocha",
|
|
99
|
-
"test:coverage": "
|
|
100
|
-
"test:mocha": "mocha --ignore 'dist/test/memory/**/*' --recursive 'dist/test/**/*.spec.js' -r node_modules/@fluidframework/mocha-test-setup
|
|
101
|
-
"test:mocha:multireport": "cross-env FLUID_TEST_MULTIREPORT=1 npm run test:mocha",
|
|
98
|
+
"test:coverage": "c8 npm test",
|
|
99
|
+
"test:mocha": "mocha --ignore 'dist/test/memory/**/*' --recursive 'dist/test/**/*.spec.js' -r node_modules/@fluidframework/mocha-test-setup",
|
|
102
100
|
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
103
101
|
"tsc": "tsc",
|
|
104
102
|
"typetests:gen": "fluid-type-test-generator",
|
package/src/attributor.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert } from "@fluidframework/
|
|
5
|
+
import { assert } from "@fluidframework/core-utils";
|
|
6
6
|
import { IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
7
7
|
import { AttributionInfo } from "@fluidframework/runtime-definitions";
|
|
8
|
-
import { UsageError } from "@fluidframework/
|
|
8
|
+
import { UsageError } from "@fluidframework/telemetry-utils";
|
|
9
9
|
import { IAudience, IDeltaManager } from "@fluidframework/container-definitions";
|
|
10
10
|
|
|
11
11
|
/**
|
package/src/encoders.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
|
-
import { assert } from "@fluidframework/
|
|
5
|
+
import { assert } from "@fluidframework/core-utils";
|
|
6
6
|
import { Jsonable } from "@fluidframework/datastore-definitions";
|
|
7
7
|
import { IUser } from "@fluidframework/protocol-definitions";
|
|
8
8
|
import { AttributionInfo } from "@fluidframework/runtime-definitions";
|
package/src/lz4Encoder.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { compress, decompress } from "lz4js";
|
|
6
|
-
import { bufferToString, stringToBuffer } from "@
|
|
6
|
+
import { bufferToString, stringToBuffer } from "@fluid-internal/client-utils";
|
|
7
7
|
import { Jsonable } from "@fluidframework/datastore-definitions";
|
|
8
8
|
import { Encoder } from "./encoders";
|
|
9
9
|
|
package/src/mixinAttributor.ts
CHANGED
|
@@ -20,12 +20,13 @@ import {
|
|
|
20
20
|
import { addSummarizeResultToSummary, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
|
|
21
21
|
import { IContainerRuntime } from "@fluidframework/container-runtime-definitions";
|
|
22
22
|
import { IRequest, IResponse, FluidObject } from "@fluidframework/core-interfaces";
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
23
|
+
import { bufferToString } from "@fluid-internal/client-utils";
|
|
24
|
+
import { assert, unreachableCase } from "@fluidframework/core-utils";
|
|
25
25
|
import {
|
|
26
26
|
createChildLogger,
|
|
27
|
-
PerformanceEvent,
|
|
28
27
|
loggerToMonitoringContext,
|
|
28
|
+
PerformanceEvent,
|
|
29
|
+
UsageError,
|
|
29
30
|
} from "@fluidframework/telemetry-utils";
|
|
30
31
|
import { Attributor, IAttributor, OpStreamAttributor } from "./attributor";
|
|
31
32
|
import { AttributorSerializer, chain, deltaEncoder, Encoder } from "./encoders";
|
package/src/stringInterner.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { UsageError } from "@fluidframework/
|
|
6
|
+
import { UsageError } from "@fluidframework/telemetry-utils";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* The ID of the string that has been interned, which can be used by a {@link StringInterner} to retrieve the
|