@fluid-experimental/attributor 2.0.0-internal.3.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/.eslintrc.js +20 -0
- package/.mocharc.js +12 -0
- package/LICENSE +21 -0
- package/README.md +106 -0
- package/api-extractor.json +4 -0
- package/dist/attributor.d.ts +56 -0
- package/dist/attributor.d.ts.map +1 -0
- package/dist/attributor.js +67 -0
- package/dist/attributor.js.map +1 -0
- package/dist/encoders.d.ts +28 -0
- package/dist/encoders.d.ts.map +1 -0
- package/dist/encoders.js +80 -0
- package/dist/encoders.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/lz4Encoder.d.ts +7 -0
- package/dist/lz4Encoder.d.ts.map +1 -0
- package/dist/lz4Encoder.js +29 -0
- package/dist/lz4Encoder.js.map +1 -0
- package/dist/mixinAttributor.d.ts +60 -0
- package/dist/mixinAttributor.d.ts.map +1 -0
- package/dist/mixinAttributor.js +153 -0
- package/dist/mixinAttributor.js.map +1 -0
- package/dist/stringInterner.d.ts +55 -0
- package/dist/stringInterner.d.ts.map +1 -0
- package/dist/stringInterner.js +66 -0
- package/dist/stringInterner.js.map +1 -0
- package/lib/attributor.d.ts +56 -0
- package/lib/attributor.d.ts.map +1 -0
- package/lib/attributor.js +62 -0
- package/lib/attributor.js.map +1 -0
- package/lib/encoders.d.ts +28 -0
- package/lib/encoders.d.ts.map +1 -0
- package/lib/encoders.js +75 -0
- package/lib/encoders.js.map +1 -0
- package/lib/index.d.ts +7 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +7 -0
- package/lib/index.js.map +1 -0
- package/lib/lz4Encoder.d.ts +7 -0
- package/lib/lz4Encoder.d.ts.map +1 -0
- package/lib/lz4Encoder.js +25 -0
- package/lib/lz4Encoder.js.map +1 -0
- package/lib/mixinAttributor.d.ts +60 -0
- package/lib/mixinAttributor.d.ts.map +1 -0
- package/lib/mixinAttributor.js +148 -0
- package/lib/mixinAttributor.js.map +1 -0
- package/lib/stringInterner.d.ts +55 -0
- package/lib/stringInterner.d.ts.map +1 -0
- package/lib/stringInterner.js +62 -0
- package/lib/stringInterner.js.map +1 -0
- package/package.json +106 -0
- package/prettier.config.cjs +8 -0
- package/src/attributor.ts +105 -0
- package/src/encoders.ts +112 -0
- package/src/index.ts +12 -0
- package/src/lz4Encoder.ts +27 -0
- package/src/mixinAttributor.ts +283 -0
- package/src/stringInterner.ts +86 -0
- package/tsconfig.esnext.json +7 -0
- package/tsconfig.json +10 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { compress, decompress } from "lz4js";
|
|
6
|
+
import { bufferToString, stringToBuffer } from "@fluidframework/common-utils";
|
|
7
|
+
/**
|
|
8
|
+
* @alpha
|
|
9
|
+
*/
|
|
10
|
+
export function makeLZ4Encoder() {
|
|
11
|
+
return {
|
|
12
|
+
encode: (decoded) => {
|
|
13
|
+
const uncompressed = new TextEncoder().encode(JSON.stringify(decoded));
|
|
14
|
+
const compressed = compress(uncompressed);
|
|
15
|
+
return bufferToString(compressed, "base64");
|
|
16
|
+
},
|
|
17
|
+
decode: (serializedSummary) => {
|
|
18
|
+
const compressed = new Uint8Array(stringToBuffer(serializedSummary, "base64"));
|
|
19
|
+
const uncompressed = decompress(compressed);
|
|
20
|
+
const decoded = JSON.parse(new TextDecoder().decode(uncompressed));
|
|
21
|
+
return decoded;
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=lz4Encoder.js.map
|
|
@@ -0,0 +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 \"@fluidframework/common-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"]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { ContainerRuntime } from "@fluidframework/container-runtime";
|
|
2
|
+
import { AttributionInfo, AttributionKey } from "@fluidframework/runtime-definitions";
|
|
3
|
+
/**
|
|
4
|
+
* @alpha
|
|
5
|
+
* Feature Gate Key -
|
|
6
|
+
* Whether or not a container runtime instantiated using `mixinAttributor`'s load should generate an attributor on
|
|
7
|
+
* new files. See package README for more notes on integration.
|
|
8
|
+
*/
|
|
9
|
+
export declare const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
|
|
10
|
+
/**
|
|
11
|
+
* @alpha
|
|
12
|
+
*/
|
|
13
|
+
export declare const IRuntimeAttributor: keyof IProvideRuntimeAttributor;
|
|
14
|
+
/**
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export interface IProvideRuntimeAttributor {
|
|
18
|
+
readonly IRuntimeAttributor: IRuntimeAttributor;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Provides access to attribution information stored on the container runtime.
|
|
22
|
+
*
|
|
23
|
+
* Attributors are only populated after the container runtime they are injected into has initialized.
|
|
24
|
+
* @sealed
|
|
25
|
+
* @alpha
|
|
26
|
+
*/
|
|
27
|
+
export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
28
|
+
/**
|
|
29
|
+
* @throws - If no AttributionInfo exists for this key.
|
|
30
|
+
*/
|
|
31
|
+
get(key: AttributionKey): AttributionInfo;
|
|
32
|
+
/**
|
|
33
|
+
* @returns - Whether any AttributionInfo exists for the provided key.
|
|
34
|
+
*/
|
|
35
|
+
has(key: AttributionKey): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* @returns - Whether the runtime is currently tracking attribution information for the loaded container.
|
|
38
|
+
* See {@link mixinAttributor} for more details on when this happens.
|
|
39
|
+
*/
|
|
40
|
+
readonly isEnabled: boolean;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data
|
|
44
|
+
* once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.
|
|
45
|
+
* @alpha
|
|
46
|
+
*/
|
|
47
|
+
export declare function createRuntimeAttributor(): IRuntimeAttributor;
|
|
48
|
+
/**
|
|
49
|
+
* Mixes in logic to load and store runtime-based attribution functionality.
|
|
50
|
+
*
|
|
51
|
+
* The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
|
|
52
|
+
*
|
|
53
|
+
* Existing documents without stored attributors will not start storing attribution information: if an
|
|
54
|
+
* IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
|
|
55
|
+
* that attributor's `has` method will always return `false`.
|
|
56
|
+
* @param Base - base class, inherits from FluidAttributorRuntime
|
|
57
|
+
* @alpha
|
|
58
|
+
*/
|
|
59
|
+
export declare const mixinAttributor: (Base?: typeof ContainerRuntime) => typeof ContainerRuntime;
|
|
60
|
+
//# sourceMappingURL=mixinAttributor.d.ts.map
|
|
@@ -0,0 +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;AAe7C;;;;;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,4BA+ErB,CAAC"}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { ContainerRuntime } from "@fluidframework/container-runtime";
|
|
2
|
+
import { addSummarizeResultToSummary, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
|
|
3
|
+
import { assert, bufferToString, unreachableCase } from "@fluidframework/common-utils";
|
|
4
|
+
import { UsageError } from "@fluidframework/container-utils";
|
|
5
|
+
import { loggerToMonitoringContext } from "@fluidframework/telemetry-utils";
|
|
6
|
+
import { Attributor, OpStreamAttributor } from "./attributor";
|
|
7
|
+
import { AttributorSerializer, chain, deltaEncoder } from "./encoders";
|
|
8
|
+
import { makeLZ4Encoder } from "./lz4Encoder";
|
|
9
|
+
// Summary tree keys
|
|
10
|
+
const attributorTreeName = ".attributor";
|
|
11
|
+
const opBlobName = "op";
|
|
12
|
+
/**
|
|
13
|
+
* @alpha
|
|
14
|
+
* Feature Gate Key -
|
|
15
|
+
* Whether or not a container runtime instantiated using `mixinAttributor`'s load should generate an attributor on
|
|
16
|
+
* new files. See package README for more notes on integration.
|
|
17
|
+
*/
|
|
18
|
+
export const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
|
|
19
|
+
/**
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export const IRuntimeAttributor = "IRuntimeAttributor";
|
|
23
|
+
/**
|
|
24
|
+
* @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data
|
|
25
|
+
* once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.
|
|
26
|
+
* @alpha
|
|
27
|
+
*/
|
|
28
|
+
export function createRuntimeAttributor() {
|
|
29
|
+
return new RuntimeAttributor();
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Mixes in logic to load and store runtime-based attribution functionality.
|
|
33
|
+
*
|
|
34
|
+
* The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
|
|
35
|
+
*
|
|
36
|
+
* Existing documents without stored attributors will not start storing attribution information: if an
|
|
37
|
+
* IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
|
|
38
|
+
* that attributor's `has` method will always return `false`.
|
|
39
|
+
* @param Base - base class, inherits from FluidAttributorRuntime
|
|
40
|
+
* @alpha
|
|
41
|
+
*/
|
|
42
|
+
export const mixinAttributor = (Base = ContainerRuntime) => class ContainerRuntimeWithAttributor extends Base {
|
|
43
|
+
static async load(context, registryEntries, requestHandler, runtimeOptions = {}, containerScope = context.scope, existing, ctor = ContainerRuntimeWithAttributor) {
|
|
44
|
+
var _a, _b, _c, _d;
|
|
45
|
+
var _e;
|
|
46
|
+
const runtimeAttributor = (_a = containerScope) === null || _a === void 0 ? void 0 : _a.IRuntimeAttributor;
|
|
47
|
+
if (!runtimeAttributor) {
|
|
48
|
+
throw new UsageError("ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor");
|
|
49
|
+
}
|
|
50
|
+
const pendingRuntimeState = context.pendingLocalState;
|
|
51
|
+
const baseSnapshot = (_b = pendingRuntimeState === null || pendingRuntimeState === void 0 ? void 0 : pendingRuntimeState.baseSnapshot) !== null && _b !== void 0 ? _b : context.baseSnapshot;
|
|
52
|
+
const { audience, deltaManager } = context;
|
|
53
|
+
assert(audience !== undefined, 0x508 /* Audience must exist when instantiating attribution-providing runtime */);
|
|
54
|
+
const mc = loggerToMonitoringContext(context.taggedLogger);
|
|
55
|
+
const shouldTrackAttribution = (_c = mc.config.getBoolean(enableOnNewFileKey)) !== null && _c !== void 0 ? _c : false;
|
|
56
|
+
if (shouldTrackAttribution) {
|
|
57
|
+
((_d = (_e = context.options).attribution) !== null && _d !== void 0 ? _d : (_e.attribution = {})).track = true;
|
|
58
|
+
}
|
|
59
|
+
const runtime = (await Base.load(context, registryEntries, requestHandler, runtimeOptions, containerScope, existing, ctor));
|
|
60
|
+
runtime.runtimeAttributor = runtimeAttributor;
|
|
61
|
+
// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize
|
|
62
|
+
// this to avoid blocking on such information until application actually requests some op-based attribution
|
|
63
|
+
// info or we need to summarize. All that really needs to happen immediately is to start recording
|
|
64
|
+
// op seq# -> attributionInfo for new ops.
|
|
65
|
+
await runtime.runtimeAttributor.initialize(deltaManager, audience, baseSnapshot, async (id) => runtime.storage.readBlob(id), shouldTrackAttribution);
|
|
66
|
+
return runtime;
|
|
67
|
+
}
|
|
68
|
+
addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext) {
|
|
69
|
+
var _a;
|
|
70
|
+
super.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);
|
|
71
|
+
const attributorSummary = (_a = this.runtimeAttributor) === null || _a === void 0 ? void 0 : _a.summarize();
|
|
72
|
+
if (attributorSummary) {
|
|
73
|
+
addSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
class RuntimeAttributor {
|
|
78
|
+
constructor() {
|
|
79
|
+
this.encoder = {
|
|
80
|
+
encode: unreachableCase,
|
|
81
|
+
decode: unreachableCase,
|
|
82
|
+
};
|
|
83
|
+
this.isEnabled = false;
|
|
84
|
+
}
|
|
85
|
+
get IRuntimeAttributor() {
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
get(key) {
|
|
89
|
+
assert(this.opAttributor !== undefined, 0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */);
|
|
90
|
+
if (key.type === "detached") {
|
|
91
|
+
throw new Error("Attribution of detached keys is not yet supported.");
|
|
92
|
+
}
|
|
93
|
+
if (key.type === "local") {
|
|
94
|
+
// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current
|
|
95
|
+
// client id in the audience. However, for read->write client transition, the container might have not yet
|
|
96
|
+
// received a client id. This is left as a TODO as it might be more easily solved once the detached case
|
|
97
|
+
// is settled (e.g. if it's reasonable for the host to know the current user information at container
|
|
98
|
+
// creation time, we could just use that here as well).
|
|
99
|
+
throw new Error("Attribution of local keys is not yet supported.");
|
|
100
|
+
}
|
|
101
|
+
return this.opAttributor.getAttributionInfo(key.seq);
|
|
102
|
+
}
|
|
103
|
+
has(key) {
|
|
104
|
+
var _a;
|
|
105
|
+
if (key.type === "detached") {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
if (key.type === "local") {
|
|
109
|
+
return false;
|
|
110
|
+
}
|
|
111
|
+
return ((_a = this.opAttributor) === null || _a === void 0 ? void 0 : _a.tryGetAttributionInfo(key.seq)) !== undefined;
|
|
112
|
+
}
|
|
113
|
+
async initialize(deltaManager, audience, baseSnapshot, readBlob, shouldAddAttributorOnNewFile) {
|
|
114
|
+
const attributorTree = baseSnapshot === null || baseSnapshot === void 0 ? void 0 : baseSnapshot.trees[attributorTreeName];
|
|
115
|
+
// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't
|
|
116
|
+
// inject any for now--this causes some back-compat integration problems that aren't fully worked out.
|
|
117
|
+
const shouldExcludeAttributor = (baseSnapshot !== undefined && attributorTree === undefined) ||
|
|
118
|
+
(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);
|
|
119
|
+
if (shouldExcludeAttributor) {
|
|
120
|
+
// This gives a consistent error for calls to `get` on keys that don't exist.
|
|
121
|
+
this.opAttributor = new Attributor();
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
this.isEnabled = true;
|
|
125
|
+
this.encoder = chain(new AttributorSerializer((entries) => new OpStreamAttributor(deltaManager, audience, entries), deltaEncoder), makeLZ4Encoder());
|
|
126
|
+
if (attributorTree !== undefined) {
|
|
127
|
+
const id = attributorTree.blobs[opBlobName];
|
|
128
|
+
assert(id !== undefined, 0x50a /* Attributor tree should have op attributor summary blob. */);
|
|
129
|
+
const blobContents = await readBlob(id);
|
|
130
|
+
const attributorSnapshot = bufferToString(blobContents, "utf8");
|
|
131
|
+
this.opAttributor = this.encoder.decode(attributorSnapshot);
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this.opAttributor = new OpStreamAttributor(deltaManager, audience);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
summarize() {
|
|
138
|
+
if (!this.isEnabled) {
|
|
139
|
+
// Loaded existing document without attributor data: avoid injecting any data.
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
assert(this.opAttributor !== undefined, 0x50b /* RuntimeAttributor should be initialized before summarization */);
|
|
143
|
+
const builder = new SummaryTreeBuilder();
|
|
144
|
+
builder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));
|
|
145
|
+
return builder.getSummaryTree();
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
//# sourceMappingURL=mixinAttributor.js.map
|
|
@@ -0,0 +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;AAGhG,OAAO,EAAE,MAAM,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,yBAAyB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,OAAO,EAAE,UAAU,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,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 { loggerToMonitoringContext } 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\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\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 runtime.runtimeAttributor.initialize(\n\t\t\t\tdeltaManager,\n\t\t\t\taudience,\n\t\t\t\tbaseSnapshot,\n\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\tshouldTrackAttribution,\n\t\t\t);\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"]}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The ID of the string that has been interned, which can be used by a {@link StringInterner} to retrieve the
|
|
7
|
+
* original string.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export declare type InternedStringId = number & {
|
|
11
|
+
readonly InternedStringId: "e221abc9-9d17-4493-8db0-70c871a1c27c";
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Interns strings as integers.
|
|
15
|
+
*/
|
|
16
|
+
export interface StringInterner {
|
|
17
|
+
getInternedId(input: string): InternedStringId | undefined;
|
|
18
|
+
getString(internedId: number): string;
|
|
19
|
+
getSerializable(): readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Interns strings as integers.
|
|
23
|
+
* Given a string, this class will produce a unique integer associated with that string that can then be used to
|
|
24
|
+
* retrieve the string.
|
|
25
|
+
*/
|
|
26
|
+
export declare class MutableStringInterner implements StringInterner {
|
|
27
|
+
private readonly stringToInternedIdMap;
|
|
28
|
+
private readonly internedStrings;
|
|
29
|
+
/**
|
|
30
|
+
* @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous
|
|
31
|
+
* `StringInterner`'s {@link StringInterner.getSerializable} return value.
|
|
32
|
+
*/
|
|
33
|
+
constructor(inputStrings?: readonly string[]);
|
|
34
|
+
/**
|
|
35
|
+
* @param input - The string to get the associated intern ID for
|
|
36
|
+
* @returns an intern ID that is uniquely associated with the input string
|
|
37
|
+
*/
|
|
38
|
+
getOrCreateInternedId(input: string): InternedStringId;
|
|
39
|
+
getInternedId(input: string): InternedStringId | undefined;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been
|
|
43
|
+
* used as inputs to calls of `getInternId`.
|
|
44
|
+
* @returns a string that is uniquely associated with the given intern ID
|
|
45
|
+
*/
|
|
46
|
+
getString(internId: number): string;
|
|
47
|
+
/**
|
|
48
|
+
* @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of
|
|
49
|
+
* each string.
|
|
50
|
+
*/
|
|
51
|
+
getSerializable(): readonly string[];
|
|
52
|
+
/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */
|
|
53
|
+
private createNewId;
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=stringInterner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringInterner.d.ts","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;GAIG;AACH,oBAAY,gBAAgB,GAAG,MAAM,GAAG;IACvC,QAAQ,CAAC,gBAAgB,EAAE,sCAAsC,CAAC;CAClE,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAC3D,SAAS,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,CAAC;IACtC,eAAe,IAAI,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;GAIG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAC3D,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAuC;IAC7E,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAgB;IAEhD;;;OAGG;gBACS,YAAY,GAAE,SAAS,MAAM,EAAO;IAMhD;;;OAGG;IACI,qBAAqB,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB;IAItD,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS;IAIjE;;;;;OAKG;IACI,SAAS,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM;IAQ1C;;;OAGG;IACI,eAAe,IAAI,SAAS,MAAM,EAAE;IAI3C,+GAA+G;IAC/G,OAAO,CAAC,WAAW;CAMnB"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { UsageError } from "@fluidframework/container-utils";
|
|
6
|
+
/**
|
|
7
|
+
* Interns strings as integers.
|
|
8
|
+
* Given a string, this class will produce a unique integer associated with that string that can then be used to
|
|
9
|
+
* retrieve the string.
|
|
10
|
+
*/
|
|
11
|
+
export class MutableStringInterner {
|
|
12
|
+
/**
|
|
13
|
+
* @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous
|
|
14
|
+
* `StringInterner`'s {@link StringInterner.getSerializable} return value.
|
|
15
|
+
*/
|
|
16
|
+
constructor(inputStrings = []) {
|
|
17
|
+
this.stringToInternedIdMap = new Map();
|
|
18
|
+
this.internedStrings = [];
|
|
19
|
+
for (const value of inputStrings) {
|
|
20
|
+
this.getOrCreateInternedId(value);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @param input - The string to get the associated intern ID for
|
|
25
|
+
* @returns an intern ID that is uniquely associated with the input string
|
|
26
|
+
*/
|
|
27
|
+
getOrCreateInternedId(input) {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_a = this.getInternedId(input)) !== null && _a !== void 0 ? _a : this.createNewId(input);
|
|
30
|
+
}
|
|
31
|
+
getInternedId(input) {
|
|
32
|
+
return this.stringToInternedIdMap.get(input);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been
|
|
37
|
+
* used as inputs to calls of `getInternId`.
|
|
38
|
+
* @returns a string that is uniquely associated with the given intern ID
|
|
39
|
+
*/
|
|
40
|
+
getString(internId) {
|
|
41
|
+
const result = this.internedStrings[internId];
|
|
42
|
+
if (!result) {
|
|
43
|
+
throw new UsageError(`No string associated with ${internId}.`);
|
|
44
|
+
}
|
|
45
|
+
return result;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of
|
|
49
|
+
* each string.
|
|
50
|
+
*/
|
|
51
|
+
getSerializable() {
|
|
52
|
+
return this.internedStrings;
|
|
53
|
+
}
|
|
54
|
+
/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */
|
|
55
|
+
createNewId(input) {
|
|
56
|
+
const internedId = this.stringToInternedIdMap.size;
|
|
57
|
+
this.stringToInternedIdMap.set(input, internedId);
|
|
58
|
+
this.internedStrings.push(input);
|
|
59
|
+
return internedId;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=stringInterner.js.map
|
|
@@ -0,0 +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,MAAA,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,mCAAI,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/container-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
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluid-experimental/attributor",
|
|
3
|
+
"version": "2.0.0-internal.3.3.0",
|
|
4
|
+
"description": "Operation attributor",
|
|
5
|
+
"homepage": "https://fluidframework.com",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/microsoft/FluidFramework.git",
|
|
9
|
+
"directory": "packages/framework/attributor"
|
|
10
|
+
},
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"author": "Microsoft and contributors",
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"main": "dist/index.js",
|
|
15
|
+
"module": "lib/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"nyc": {
|
|
18
|
+
"all": true,
|
|
19
|
+
"cache-dir": "nyc/.cache",
|
|
20
|
+
"exclude": [
|
|
21
|
+
"src/test/**/*.ts",
|
|
22
|
+
"dist/test/**/*.js"
|
|
23
|
+
],
|
|
24
|
+
"exclude-after-remap": false,
|
|
25
|
+
"include": [
|
|
26
|
+
"src/**/*.ts",
|
|
27
|
+
"dist/**/*.js"
|
|
28
|
+
],
|
|
29
|
+
"report-dir": "nyc/report",
|
|
30
|
+
"reporter": [
|
|
31
|
+
"cobertura",
|
|
32
|
+
"html",
|
|
33
|
+
"text"
|
|
34
|
+
],
|
|
35
|
+
"temp-directory": "nyc/.nyc_output"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@fluidframework/common-utils": "^1.1.1",
|
|
39
|
+
"@fluidframework/container-definitions": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
40
|
+
"@fluidframework/container-runtime": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
41
|
+
"@fluidframework/container-runtime-definitions": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
42
|
+
"@fluidframework/container-utils": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
43
|
+
"@fluidframework/core-interfaces": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
44
|
+
"@fluidframework/datastore-definitions": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
45
|
+
"@fluidframework/protocol-definitions": "^1.1.0",
|
|
46
|
+
"@fluidframework/runtime-definitions": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
47
|
+
"@fluidframework/runtime-utils": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
48
|
+
"@fluidframework/telemetry-utils": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
49
|
+
"lz4js": "^0.2.0"
|
|
50
|
+
},
|
|
51
|
+
"devDependencies": {
|
|
52
|
+
"@fluid-internal/stochastic-test-utils": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
53
|
+
"@fluid-tools/build-cli": "^0.12.0",
|
|
54
|
+
"@fluidframework/build-common": "^1.1.0",
|
|
55
|
+
"@fluidframework/build-tools": "^0.12.0",
|
|
56
|
+
"@fluidframework/driver-definitions": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
57
|
+
"@fluidframework/eslint-config-fluid": "^2.0.0",
|
|
58
|
+
"@fluidframework/merge-tree": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
59
|
+
"@fluidframework/mocha-test-setup": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
60
|
+
"@fluidframework/sequence": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
61
|
+
"@fluidframework/test-runtime-utils": ">=2.0.0-internal.3.3.0 <2.0.0-internal.4.0.0",
|
|
62
|
+
"@microsoft/api-extractor": "^7.22.2",
|
|
63
|
+
"@rushstack/eslint-config": "^2.5.1",
|
|
64
|
+
"@types/mocha": "^9.1.1",
|
|
65
|
+
"@types/node": "^14.18.36",
|
|
66
|
+
"concurrently": "^6.2.0",
|
|
67
|
+
"copyfiles": "^2.4.1",
|
|
68
|
+
"cross-env": "^7.0.2",
|
|
69
|
+
"eslint": "~8.6.0",
|
|
70
|
+
"mocha": "^10.0.0",
|
|
71
|
+
"nyc": "^15.0.0",
|
|
72
|
+
"prettier": "~2.6.2",
|
|
73
|
+
"rimraf": "^2.6.2",
|
|
74
|
+
"typescript": "~4.5.5"
|
|
75
|
+
},
|
|
76
|
+
"typeValidation": {
|
|
77
|
+
"disabled": true,
|
|
78
|
+
"broken": {}
|
|
79
|
+
},
|
|
80
|
+
"scripts": {
|
|
81
|
+
"build": "concurrently npm:build:compile npm:lint && npm run build:docs",
|
|
82
|
+
"build:commonjs": "npm run tsc && npm run typetests:gen && npm run build:test",
|
|
83
|
+
"build:compile": "concurrently npm:build:commonjs npm:build:esnext",
|
|
84
|
+
"build:docs": "api-extractor run --local --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/doc-models/* ../../../_api-extractor-temp/",
|
|
85
|
+
"build:esnext": "tsc --project ./tsconfig.esnext.json",
|
|
86
|
+
"build:full": "npm run build",
|
|
87
|
+
"build:full:compile": "npm run build:compile",
|
|
88
|
+
"build:test": "tsc --project ./src/test/tsconfig.json",
|
|
89
|
+
"ci:build:docs": "api-extractor run --typescript-compiler-folder ../../../node_modules/typescript && copyfiles -u 1 ./_api-extractor-temp/* ../../../_api-extractor-temp/",
|
|
90
|
+
"clean": "rimraf dist lib *.tsbuildinfo *.build.log",
|
|
91
|
+
"eslint": "eslint --format stylish src",
|
|
92
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
93
|
+
"format": "npm run prettier:fix",
|
|
94
|
+
"lint": "npm run prettier && npm run eslint",
|
|
95
|
+
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
|
|
96
|
+
"prettier": "prettier --check . --ignore-path ../../../.prettierignore",
|
|
97
|
+
"prettier:fix": "prettier --write . --ignore-path ../../../.prettierignore",
|
|
98
|
+
"test": "npm run test:mocha",
|
|
99
|
+
"test:coverage": "nyc npm test -- --reporter xunit --reporter-option output=nyc/junit-report.xml",
|
|
100
|
+
"test:mocha": "mocha --ignore 'dist/test/memory/**/*' --recursive 'dist/test/**/*.spec.js' -r node_modules/@fluidframework/mocha-test-setup --unhandled-rejections=strict",
|
|
101
|
+
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
102
|
+
"tsc": "tsc",
|
|
103
|
+
"typetests:gen": "fluid-type-test-generator",
|
|
104
|
+
"typetests:prepare": "flub generate typetests --prepare --dir . --pin"
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { assert } from "@fluidframework/common-utils";
|
|
6
|
+
import { IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
|
|
7
|
+
import { AttributionInfo } from "@fluidframework/runtime-definitions";
|
|
8
|
+
import { UsageError } from "@fluidframework/container-utils";
|
|
9
|
+
import { IAudience, IDeltaManager } from "@fluidframework/container-definitions";
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Provides lookup between attribution keys and their associated attribution information.
|
|
13
|
+
* @alpha
|
|
14
|
+
*/
|
|
15
|
+
export interface IAttributor {
|
|
16
|
+
/**
|
|
17
|
+
* Retrieves attribution information associated with a particular key.
|
|
18
|
+
* @param key - Attribution key to look up.
|
|
19
|
+
* @throws If no attribution information is recorded for that key.
|
|
20
|
+
*/
|
|
21
|
+
getAttributionInfo(key: number): AttributionInfo;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param key - Attribution key to look up.
|
|
25
|
+
* @returns the attribution information associated with the provided key, or undefined if no information exists.
|
|
26
|
+
*/
|
|
27
|
+
tryGetAttributionInfo(key: number): AttributionInfo | undefined;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @returns an iterable of (attribution key, attribution info) pairs for each stored key.
|
|
31
|
+
*/
|
|
32
|
+
entries(): IterableIterator<[number, AttributionInfo]>;
|
|
33
|
+
|
|
34
|
+
// TODO:
|
|
35
|
+
// - GC
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* {@inheritdoc IAttributor}
|
|
40
|
+
* @alpha
|
|
41
|
+
*/
|
|
42
|
+
export class Attributor implements IAttributor {
|
|
43
|
+
protected readonly keyToInfo: Map<number, AttributionInfo>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @param initialEntries - Any entries which should be populated on instantiation.
|
|
47
|
+
*/
|
|
48
|
+
constructor(initialEntries?: Iterable<[number, AttributionInfo]>) {
|
|
49
|
+
this.keyToInfo = new Map(initialEntries ?? []);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* {@inheritdoc IAttributor.getAttributionInfo}
|
|
54
|
+
*/
|
|
55
|
+
public getAttributionInfo(key: number): AttributionInfo {
|
|
56
|
+
const result = this.tryGetAttributionInfo(key);
|
|
57
|
+
if (!result) {
|
|
58
|
+
throw new UsageError(`Requested attribution information for unstored key: ${key}.`);
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* {@inheritdoc IAttributor.tryGetAttributionInfo}
|
|
65
|
+
*/
|
|
66
|
+
public tryGetAttributionInfo(key: number): AttributionInfo | undefined {
|
|
67
|
+
return this.keyToInfo.get(key);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* {@inheritdoc IAttributor.entries}
|
|
72
|
+
*/
|
|
73
|
+
public entries(): IterableIterator<[number, AttributionInfo]> {
|
|
74
|
+
return this.keyToInfo.entries();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Attributor which listens to an op stream and records entries for each op.
|
|
80
|
+
* Sequence numbers are used as attribution keys.
|
|
81
|
+
* @alpha
|
|
82
|
+
*/
|
|
83
|
+
export class OpStreamAttributor extends Attributor implements IAttributor {
|
|
84
|
+
constructor(
|
|
85
|
+
deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,
|
|
86
|
+
audience: IAudience,
|
|
87
|
+
initialEntries?: Iterable<[number, AttributionInfo]>,
|
|
88
|
+
) {
|
|
89
|
+
super(initialEntries);
|
|
90
|
+
deltaManager.on("op", (message: ISequencedDocumentMessage) => {
|
|
91
|
+
const client = audience.getMember(message.clientId);
|
|
92
|
+
if (message.type === "op") {
|
|
93
|
+
// TODO: This case may be legitimate, and if so we need to figure out how to handle it.
|
|
94
|
+
assert(
|
|
95
|
+
client !== undefined,
|
|
96
|
+
0x4af /* Received message from user not in the audience */,
|
|
97
|
+
);
|
|
98
|
+
this.keyToInfo.set(message.sequenceNumber, {
|
|
99
|
+
user: client.user,
|
|
100
|
+
timestamp: message.timestamp,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
}
|