@fluid-experimental/attributor 2.0.0-dev-rc.1.0.0.224419
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/CHANGELOG.md +122 -0
- package/LICENSE +21 -0
- package/README.md +144 -0
- package/api-extractor-lint.json +4 -0
- package/api-extractor.json +4 -0
- package/api-report/attributor.api.md +71 -0
- package/dist/attributor-alpha.d.ts +27 -0
- package/dist/attributor-beta.d.ts +31 -0
- package/dist/attributor-public.d.ts +31 -0
- package/dist/attributor-untrimmed.d.ts +124 -0
- package/dist/attributor.cjs +69 -0
- package/dist/attributor.cjs.map +1 -0
- package/dist/attributor.d.ts +56 -0
- package/dist/attributor.d.ts.map +1 -0
- package/dist/encoders.cjs +80 -0
- package/dist/encoders.cjs.map +1 -0
- package/dist/encoders.d.ts +28 -0
- package/dist/encoders.d.ts.map +1 -0
- package/dist/index.cjs +16 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/lz4Encoder.cjs +29 -0
- package/dist/lz4Encoder.cjs.map +1 -0
- package/dist/lz4Encoder.d.ts +7 -0
- package/dist/lz4Encoder.d.ts.map +1 -0
- package/dist/mixinAttributor.cjs +170 -0
- package/dist/mixinAttributor.cjs.map +1 -0
- package/dist/mixinAttributor.d.ts +57 -0
- package/dist/mixinAttributor.d.ts.map +1 -0
- package/dist/stringInterner.cjs +65 -0
- package/dist/stringInterner.cjs.map +1 -0
- package/dist/stringInterner.d.ts +55 -0
- package/dist/stringInterner.d.ts.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/attributor-alpha.d.mts +27 -0
- package/lib/attributor-beta.d.mts +31 -0
- package/lib/attributor-public.d.mts +31 -0
- package/lib/attributor-untrimmed.d.mts +124 -0
- package/lib/attributor.d.mts +56 -0
- package/lib/attributor.d.mts.map +1 -0
- package/lib/attributor.mjs +60 -0
- package/lib/attributor.mjs.map +1 -0
- package/lib/encoders.d.mts +28 -0
- package/lib/encoders.d.mts.map +1 -0
- package/lib/encoders.mjs +71 -0
- package/lib/encoders.mjs.map +1 -0
- package/lib/index.d.mts +3 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +3 -0
- package/lib/index.mjs.map +1 -0
- package/lib/lz4Encoder.d.mts +7 -0
- package/lib/lz4Encoder.d.mts.map +1 -0
- package/lib/lz4Encoder.mjs +21 -0
- package/lib/lz4Encoder.mjs.map +1 -0
- package/lib/mixinAttributor.d.mts +57 -0
- package/lib/mixinAttributor.d.mts.map +1 -0
- package/lib/mixinAttributor.mjs +165 -0
- package/lib/mixinAttributor.mjs.map +1 -0
- package/lib/stringInterner.d.mts +55 -0
- package/lib/stringInterner.d.mts.map +1 -0
- package/lib/stringInterner.mjs +61 -0
- package/lib/stringInterner.mjs.map +1 -0
- package/package.json +138 -0
- package/prettier.config.cjs +8 -0
- package/src/attributor.ts +107 -0
- package/src/encoders.ts +111 -0
- package/src/index.ts +12 -0
- package/src/lz4Encoder.ts +27 -0
- package/src/mixinAttributor.ts +317 -0
- package/src/stringInterner.ts +86 -0
- package/tsc-multi.test.json +4 -0
- package/tsconfig.json +12 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { compress, decompress } from "lz4js";
|
|
2
|
+
import { bufferToString, stringToBuffer } from "@fluid-internal/client-utils";
|
|
3
|
+
/**
|
|
4
|
+
* @alpha
|
|
5
|
+
*/
|
|
6
|
+
export function makeLZ4Encoder() {
|
|
7
|
+
return {
|
|
8
|
+
encode: (decoded) => {
|
|
9
|
+
const uncompressed = new TextEncoder().encode(JSON.stringify(decoded));
|
|
10
|
+
const compressed = compress(uncompressed);
|
|
11
|
+
return bufferToString(compressed, "base64");
|
|
12
|
+
},
|
|
13
|
+
decode: (serializedSummary) => {
|
|
14
|
+
const compressed = new Uint8Array(stringToBuffer(serializedSummary, "base64"));
|
|
15
|
+
const uncompressed = decompress(compressed);
|
|
16
|
+
const decoded = JSON.parse(new TextDecoder().decode(uncompressed));
|
|
17
|
+
return decoded;
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=lz4Encoder.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lz4Encoder.mjs","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":"OAIO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,OAAO;OACrC,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,8BAA8B;AAI7E;;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"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ContainerRuntime } from "@fluidframework/container-runtime";
|
|
2
|
+
import { AttributionInfo, AttributionKey } from "@fluidframework/runtime-definitions";
|
|
3
|
+
/**
|
|
4
|
+
* @internal
|
|
5
|
+
*/
|
|
6
|
+
export declare const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const IRuntimeAttributor: keyof IProvideRuntimeAttributor;
|
|
11
|
+
/**
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
export interface IProvideRuntimeAttributor {
|
|
15
|
+
readonly IRuntimeAttributor: IRuntimeAttributor;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Provides access to attribution information stored on the container runtime.
|
|
19
|
+
*
|
|
20
|
+
* Attributors are only populated after the container runtime they are injected into has initialized.
|
|
21
|
+
* @sealed
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
export interface IRuntimeAttributor extends IProvideRuntimeAttributor {
|
|
25
|
+
/**
|
|
26
|
+
* @throws - If no AttributionInfo exists for this key.
|
|
27
|
+
*/
|
|
28
|
+
get(key: AttributionKey): AttributionInfo;
|
|
29
|
+
/**
|
|
30
|
+
* @returns Whether any AttributionInfo exists for the provided key.
|
|
31
|
+
*/
|
|
32
|
+
has(key: AttributionKey): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* @returns Whether the runtime is currently tracking attribution information for the loaded container.
|
|
35
|
+
* See {@link mixinAttributor} for more details on when this happens.
|
|
36
|
+
*/
|
|
37
|
+
readonly isEnabled: boolean;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data
|
|
41
|
+
* once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.
|
|
42
|
+
* @internal
|
|
43
|
+
*/
|
|
44
|
+
export declare function createRuntimeAttributor(): IRuntimeAttributor;
|
|
45
|
+
/**
|
|
46
|
+
* Mixes in logic to load and store runtime-based attribution functionality.
|
|
47
|
+
*
|
|
48
|
+
* The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
|
|
49
|
+
*
|
|
50
|
+
* Existing documents without stored attributors will not start storing attribution information: if an
|
|
51
|
+
* IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
|
|
52
|
+
* that attributor's `has` method will always return `false`.
|
|
53
|
+
* @param Base - base class, inherits from FluidAttributorRuntime
|
|
54
|
+
* @internal
|
|
55
|
+
*/
|
|
56
|
+
export declare const mixinAttributor: (Base?: typeof ContainerRuntime) => typeof ContainerRuntime;
|
|
57
|
+
//# sourceMappingURL=mixinAttributor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixinAttributor.d.ts","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[],"mappings":"OAUO,EAAE,gBAAgB,EAAE,MAAM,mCAAmC;OAE7D,EACN,eAAe,EACf,cAAc,EAId,MAAM,qCAAqC;AAoB5C;;GAEG;AACH,eAAO,MAAM,kBAAkB,sCAAsC,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,kBAAkB,EAAE,MAAM,yBAAgD,CAAC;AAExF;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,kBAAkB,EAAE,kBAAkB,CAAC;CAChD;AAED;;;;;;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+GrB,CAAC"}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { ContainerRuntime } from "@fluidframework/container-runtime";
|
|
2
|
+
import { addSummarizeResultToSummary, SummaryTreeBuilder } from "@fluidframework/runtime-utils";
|
|
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
|
+
import { Attributor, OpStreamAttributor } from "./attributor.mjs";
|
|
7
|
+
import { AttributorSerializer, chain, deltaEncoder } from "./encoders.mjs";
|
|
8
|
+
import { makeLZ4Encoder } from "./lz4Encoder.mjs";
|
|
9
|
+
// Summary tree keys
|
|
10
|
+
const attributorTreeName = ".attributor";
|
|
11
|
+
const opBlobName = "op";
|
|
12
|
+
/**
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
export const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
|
|
16
|
+
/**
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
export const IRuntimeAttributor = "IRuntimeAttributor";
|
|
20
|
+
/**
|
|
21
|
+
* @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data
|
|
22
|
+
* once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
export function createRuntimeAttributor() {
|
|
26
|
+
return new RuntimeAttributor();
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Mixes in logic to load and store runtime-based attribution functionality.
|
|
30
|
+
*
|
|
31
|
+
* The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
|
|
32
|
+
*
|
|
33
|
+
* Existing documents without stored attributors will not start storing attribution information: if an
|
|
34
|
+
* IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
|
|
35
|
+
* that attributor's `has` method will always return `false`.
|
|
36
|
+
* @param Base - base class, inherits from FluidAttributorRuntime
|
|
37
|
+
* @internal
|
|
38
|
+
*/
|
|
39
|
+
export const mixinAttributor = (Base = ContainerRuntime) => class ContainerRuntimeWithAttributor extends Base {
|
|
40
|
+
static async loadRuntime(params) {
|
|
41
|
+
var _a;
|
|
42
|
+
const { context, registryEntries, existing, requestHandler, provideEntryPoint, runtimeOptions, containerScope, containerRuntimeCtor = ContainerRuntimeWithAttributor, } = params;
|
|
43
|
+
const runtimeAttributor = containerScope?.IRuntimeAttributor;
|
|
44
|
+
if (!runtimeAttributor) {
|
|
45
|
+
throw new UsageError("ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor");
|
|
46
|
+
}
|
|
47
|
+
const pendingRuntimeState = context.pendingLocalState;
|
|
48
|
+
const baseSnapshot = pendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;
|
|
49
|
+
const { audience, deltaManager } = context;
|
|
50
|
+
assert(audience !== undefined, 0x508 /* Audience must exist when instantiating attribution-providing runtime */);
|
|
51
|
+
const mc = loggerToMonitoringContext(context.taggedLogger);
|
|
52
|
+
const shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;
|
|
53
|
+
if (shouldTrackAttribution) {
|
|
54
|
+
((_a = context.options).attribution ?? (_a.attribution = {})).track = true;
|
|
55
|
+
}
|
|
56
|
+
const runtime = (await Base.loadRuntime({
|
|
57
|
+
context,
|
|
58
|
+
registryEntries,
|
|
59
|
+
requestHandler,
|
|
60
|
+
provideEntryPoint,
|
|
61
|
+
// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0
|
|
62
|
+
initializeEntryPoint: provideEntryPoint,
|
|
63
|
+
runtimeOptions,
|
|
64
|
+
containerScope,
|
|
65
|
+
existing,
|
|
66
|
+
containerRuntimeCtor,
|
|
67
|
+
}));
|
|
68
|
+
runtime.runtimeAttributor = runtimeAttributor;
|
|
69
|
+
const logger = createChildLogger({ logger: runtime.logger, namespace: "Attributor" });
|
|
70
|
+
// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize
|
|
71
|
+
// this to avoid blocking on such information until application actually requests some op-based attribution
|
|
72
|
+
// info or we need to summarize. All that really needs to happen immediately is to start recording
|
|
73
|
+
// op seq# -> attributionInfo for new ops.
|
|
74
|
+
await PerformanceEvent.timedExecAsync(logger, {
|
|
75
|
+
eventName: "initialize",
|
|
76
|
+
}, async (event) => {
|
|
77
|
+
await runtime.runtimeAttributor?.initialize(deltaManager, audience, baseSnapshot, async (id) => runtime.storage.readBlob(id), shouldTrackAttribution);
|
|
78
|
+
event.end({
|
|
79
|
+
attributionEnabledInConfig: shouldTrackAttribution,
|
|
80
|
+
attributionEnabledInDoc: runtime.runtimeAttributor
|
|
81
|
+
? runtime.runtimeAttributor.isEnabled
|
|
82
|
+
: false,
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
return runtime;
|
|
86
|
+
}
|
|
87
|
+
addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext) {
|
|
88
|
+
super.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);
|
|
89
|
+
const attributorSummary = this.runtimeAttributor?.summarize();
|
|
90
|
+
if (attributorSummary) {
|
|
91
|
+
addSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
class RuntimeAttributor {
|
|
96
|
+
constructor() {
|
|
97
|
+
this.encoder = {
|
|
98
|
+
encode: unreachableCase,
|
|
99
|
+
decode: unreachableCase,
|
|
100
|
+
};
|
|
101
|
+
this.isEnabled = false;
|
|
102
|
+
}
|
|
103
|
+
get IRuntimeAttributor() {
|
|
104
|
+
return this;
|
|
105
|
+
}
|
|
106
|
+
get(key) {
|
|
107
|
+
assert(this.opAttributor !== undefined, 0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */);
|
|
108
|
+
if (key.type === "detached") {
|
|
109
|
+
throw new Error("Attribution of detached keys is not yet supported.");
|
|
110
|
+
}
|
|
111
|
+
if (key.type === "local") {
|
|
112
|
+
// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current
|
|
113
|
+
// client id in the audience. However, for read->write client transition, the container might have not yet
|
|
114
|
+
// received a client id. This is left as a TODO as it might be more easily solved once the detached case
|
|
115
|
+
// is settled (e.g. if it's reasonable for the host to know the current user information at container
|
|
116
|
+
// creation time, we could just use that here as well).
|
|
117
|
+
throw new Error("Attribution of local keys is not yet supported.");
|
|
118
|
+
}
|
|
119
|
+
return this.opAttributor.getAttributionInfo(key.seq);
|
|
120
|
+
}
|
|
121
|
+
has(key) {
|
|
122
|
+
if (key.type === "detached") {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (key.type === "local") {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;
|
|
129
|
+
}
|
|
130
|
+
async initialize(deltaManager, audience, baseSnapshot, readBlob, shouldAddAttributorOnNewFile) {
|
|
131
|
+
const attributorTree = baseSnapshot?.trees[attributorTreeName];
|
|
132
|
+
// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't
|
|
133
|
+
// inject any for now--this causes some back-compat integration problems that aren't fully worked out.
|
|
134
|
+
const shouldExcludeAttributor = (baseSnapshot !== undefined && attributorTree === undefined) ||
|
|
135
|
+
(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);
|
|
136
|
+
if (shouldExcludeAttributor) {
|
|
137
|
+
// This gives a consistent error for calls to `get` on keys that don't exist.
|
|
138
|
+
this.opAttributor = new Attributor();
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
this.isEnabled = true;
|
|
142
|
+
this.encoder = chain(new AttributorSerializer((entries) => new OpStreamAttributor(deltaManager, audience, entries), deltaEncoder), makeLZ4Encoder());
|
|
143
|
+
if (attributorTree !== undefined) {
|
|
144
|
+
const id = attributorTree.blobs[opBlobName];
|
|
145
|
+
assert(id !== undefined, 0x50a /* Attributor tree should have op attributor summary blob. */);
|
|
146
|
+
const blobContents = await readBlob(id);
|
|
147
|
+
const attributorSnapshot = bufferToString(blobContents, "utf8");
|
|
148
|
+
this.opAttributor = this.encoder.decode(attributorSnapshot);
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.opAttributor = new OpStreamAttributor(deltaManager, audience);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
summarize() {
|
|
155
|
+
if (!this.isEnabled) {
|
|
156
|
+
// Loaded existing document without attributor data: avoid injecting any data.
|
|
157
|
+
return undefined;
|
|
158
|
+
}
|
|
159
|
+
assert(this.opAttributor !== undefined, 0x50b /* RuntimeAttributor should be initialized before summarization */);
|
|
160
|
+
const builder = new SummaryTreeBuilder();
|
|
161
|
+
builder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));
|
|
162
|
+
return builder.getSummaryTree();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=mixinAttributor.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixinAttributor.mjs","sourceRoot":"","sources":["../src/mixinAttributor.ts"],"names":[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C,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 * @internal\n */\nexport const enableOnNewFileKey = \"Fluid.Attribution.EnableOnNewFile\";\n\n/**\n * @internal\n */\nexport const IRuntimeAttributor: keyof IProvideRuntimeAttributor = \"IRuntimeAttributor\";\n\n/**\n * @internal\n */\nexport interface IProvideRuntimeAttributor {\n\treadonly IRuntimeAttributor: IRuntimeAttributor;\n}\n\n/**\n * Provides access to attribution information stored on the container runtime.\n *\n * Attributors are only populated after the container runtime they are injected into has initialized.\n * @sealed\n * @internal\n */\nexport interface IRuntimeAttributor extends IProvideRuntimeAttributor {\n\t/**\n\t * @throws - If no AttributionInfo exists for this key.\n\t */\n\tget(key: AttributionKey): AttributionInfo;\n\n\t/**\n\t * @returns Whether any AttributionInfo exists for the provided key.\n\t */\n\thas(key: AttributionKey): boolean;\n\n\t/**\n\t * @returns Whether the runtime is currently tracking attribution information for the loaded container.\n\t * See {@link mixinAttributor} for more details on when this happens.\n\t */\n\treadonly isEnabled: boolean;\n}\n\n/**\n * @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data\n * once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.\n * @internal\n */\nexport function createRuntimeAttributor(): IRuntimeAttributor {\n\treturn new RuntimeAttributor();\n}\n\n/**\n * Mixes in logic to load and store runtime-based attribution functionality.\n *\n * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.\n *\n * Existing documents without stored attributors will not start storing attribution information: if an\n * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,\n * that attributor's `has` method will always return `false`.\n * @param Base - base class, inherits from FluidAttributorRuntime\n * @internal\n */\nexport const mixinAttributor = (Base: typeof ContainerRuntime = ContainerRuntime) =>\n\tclass ContainerRuntimeWithAttributor extends Base {\n\t\tpublic static async loadRuntime(params: {\n\t\t\tcontext: IContainerContext;\n\t\t\tregistryEntries: NamedFluidDataStoreRegistryEntries;\n\t\t\texisting: boolean;\n\t\t\truntimeOptions?: IContainerRuntimeOptions;\n\t\t\tcontainerScope?: FluidObject;\n\t\t\tcontainerRuntimeCtor?: typeof ContainerRuntime;\n\t\t\t/** @deprecated Will be removed once Loader LTS version is \"2.0.0-internal.7.0.0\". Migrate all usage of IFluidRouter to the \"entryPoint\" pattern. Refer to Removing-IFluidRouter.md */\n\t\t\trequestHandler?: (request: IRequest, runtime: IContainerRuntime) => Promise<IResponse>;\n\t\t\tprovideEntryPoint: (containerRuntime: IContainerRuntime) => Promise<FluidObject>;\n\t\t}): Promise<ContainerRuntime> {\n\t\t\tconst {\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\texisting,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\tcontainerRuntimeCtor = ContainerRuntimeWithAttributor as unknown as typeof ContainerRuntime,\n\t\t\t} = params;\n\n\t\t\tconst runtimeAttributor = (\n\t\t\t\tcontainerScope as FluidObject<IProvideRuntimeAttributor> | undefined\n\t\t\t)?.IRuntimeAttributor;\n\t\t\tif (!runtimeAttributor) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"ContainerRuntimeWithAttributor must be passed a scope implementing IProvideRuntimeAttributor\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst pendingRuntimeState = context.pendingLocalState as {\n\t\t\t\tbaseSnapshot?: ISnapshotTree;\n\t\t\t};\n\t\t\tconst baseSnapshot: ISnapshotTree | undefined =\n\t\t\t\tpendingRuntimeState?.baseSnapshot ?? context.baseSnapshot;\n\n\t\t\tconst { audience, deltaManager } = context;\n\t\t\tassert(\n\t\t\t\taudience !== undefined,\n\t\t\t\t0x508 /* Audience must exist when instantiating attribution-providing runtime */,\n\t\t\t);\n\n\t\t\tconst mc = loggerToMonitoringContext(context.taggedLogger);\n\n\t\t\tconst shouldTrackAttribution = mc.config.getBoolean(enableOnNewFileKey) ?? false;\n\t\t\tif (shouldTrackAttribution) {\n\t\t\t\t(context.options.attribution ??= {}).track = true;\n\t\t\t}\n\n\t\t\tconst runtime = (await Base.loadRuntime({\n\t\t\t\tcontext,\n\t\t\t\tregistryEntries,\n\t\t\t\trequestHandler,\n\t\t\t\tprovideEntryPoint,\n\t\t\t\t// ! This prop is needed for back-compat. Can be removed in 2.0.0-internal.8.0.0\n\t\t\t\tinitializeEntryPoint: provideEntryPoint,\n\t\t\t\truntimeOptions,\n\t\t\t\tcontainerScope,\n\t\t\t\texisting,\n\t\t\t\tcontainerRuntimeCtor,\n\t\t\t} as any)) as ContainerRuntimeWithAttributor;\n\t\t\truntime.runtimeAttributor = runtimeAttributor as RuntimeAttributor;\n\n\t\t\tconst logger = createChildLogger({ logger: runtime.logger, namespace: \"Attributor\" });\n\n\t\t\t// Note: this fetches attribution blobs relatively eagerly in the load flow; we may want to optimize\n\t\t\t// this to avoid blocking on such information until application actually requests some op-based attribution\n\t\t\t// info or we need to summarize. All that really needs to happen immediately is to start recording\n\t\t\t// op seq# -> attributionInfo for new ops.\n\t\t\tawait PerformanceEvent.timedExecAsync(\n\t\t\t\tlogger,\n\t\t\t\t{\n\t\t\t\t\teventName: \"initialize\",\n\t\t\t\t},\n\t\t\t\tasync (event) => {\n\t\t\t\t\tawait runtime.runtimeAttributor?.initialize(\n\t\t\t\t\t\tdeltaManager,\n\t\t\t\t\t\taudience,\n\t\t\t\t\t\tbaseSnapshot,\n\t\t\t\t\t\tasync (id) => runtime.storage.readBlob(id),\n\t\t\t\t\t\tshouldTrackAttribution,\n\t\t\t\t\t);\n\t\t\t\t\tevent.end({\n\t\t\t\t\t\tattributionEnabledInConfig: shouldTrackAttribution,\n\t\t\t\t\t\tattributionEnabledInDoc: runtime.runtimeAttributor\n\t\t\t\t\t\t\t? runtime.runtimeAttributor.isEnabled\n\t\t\t\t\t\t\t: false,\n\t\t\t\t\t});\n\t\t\t\t},\n\t\t\t);\n\n\t\t\treturn runtime;\n\t\t}\n\n\t\tprivate runtimeAttributor: RuntimeAttributor | undefined;\n\n\t\tprotected addContainerStateToSummary(\n\t\t\tsummaryTree: ISummaryTreeWithStats,\n\t\t\tfullTree: boolean,\n\t\t\ttrackState: boolean,\n\t\t\ttelemetryContext?: ITelemetryContext,\n\t\t) {\n\t\t\tsuper.addContainerStateToSummary(summaryTree, fullTree, trackState, telemetryContext);\n\t\t\tconst attributorSummary = this.runtimeAttributor?.summarize();\n\t\t\tif (attributorSummary) {\n\t\t\t\taddSummarizeResultToSummary(summaryTree, attributorTreeName, attributorSummary);\n\t\t\t}\n\t\t}\n\t} as unknown as typeof ContainerRuntime;\n\nclass RuntimeAttributor implements IRuntimeAttributor {\n\tpublic get IRuntimeAttributor(): IRuntimeAttributor {\n\t\treturn this;\n\t}\n\n\tpublic get(key: AttributionKey): AttributionInfo {\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x509 /* RuntimeAttributor must be initialized before getAttributionInfo can be called */,\n\t\t);\n\n\t\tif (key.type === \"detached\") {\n\t\t\tthrow new Error(\"Attribution of detached keys is not yet supported.\");\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\t// Note: we can *almost* orchestrate this correctly with internal-only changes by looking up the current\n\t\t\t// client id in the audience. However, for read->write client transition, the container might have not yet\n\t\t\t// received a client id. This is left as a TODO as it might be more easily solved once the detached case\n\t\t\t// is settled (e.g. if it's reasonable for the host to know the current user information at container\n\t\t\t// creation time, we could just use that here as well).\n\t\t\tthrow new Error(\"Attribution of local keys is not yet supported.\");\n\t\t}\n\n\t\treturn this.opAttributor.getAttributionInfo(key.seq);\n\t}\n\n\tpublic has(key: AttributionKey): boolean {\n\t\tif (key.type === \"detached\") {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (key.type === \"local\") {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.opAttributor?.tryGetAttributionInfo(key.seq) !== undefined;\n\t}\n\n\tprivate encoder: Encoder<IAttributor, string> = {\n\t\tencode: unreachableCase,\n\t\tdecode: unreachableCase,\n\t};\n\n\tprivate opAttributor: IAttributor | undefined;\n\tpublic isEnabled = false;\n\n\tpublic async initialize(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\taudience: IAudience,\n\t\tbaseSnapshot: ISnapshotTree | undefined,\n\t\treadBlob: (id: string) => Promise<ArrayBufferLike>,\n\t\tshouldAddAttributorOnNewFile: boolean,\n\t): Promise<void> {\n\t\tconst attributorTree = baseSnapshot?.trees[attributorTreeName];\n\t\t// Existing documents that don't already have a snapshot containing runtime attribution info shouldn't\n\t\t// inject any for now--this causes some back-compat integration problems that aren't fully worked out.\n\t\tconst shouldExcludeAttributor =\n\t\t\t(baseSnapshot !== undefined && attributorTree === undefined) ||\n\t\t\t(baseSnapshot === undefined && !shouldAddAttributorOnNewFile);\n\t\tif (shouldExcludeAttributor) {\n\t\t\t// This gives a consistent error for calls to `get` on keys that don't exist.\n\t\t\tthis.opAttributor = new Attributor();\n\t\t\treturn;\n\t\t}\n\n\t\tthis.isEnabled = true;\n\t\tthis.encoder = chain(\n\t\t\tnew AttributorSerializer(\n\t\t\t\t(entries) => new OpStreamAttributor(deltaManager, audience, entries),\n\t\t\t\tdeltaEncoder,\n\t\t\t),\n\t\t\tmakeLZ4Encoder(),\n\t\t);\n\n\t\tif (attributorTree !== undefined) {\n\t\t\tconst id = attributorTree.blobs[opBlobName];\n\t\t\tassert(\n\t\t\t\tid !== undefined,\n\t\t\t\t0x50a /* Attributor tree should have op attributor summary blob. */,\n\t\t\t);\n\t\t\tconst blobContents = await readBlob(id);\n\t\t\tconst attributorSnapshot = bufferToString(blobContents, \"utf8\");\n\t\t\tthis.opAttributor = this.encoder.decode(attributorSnapshot);\n\t\t} else {\n\t\t\tthis.opAttributor = new OpStreamAttributor(deltaManager, audience);\n\t\t}\n\t}\n\n\tpublic summarize(): ISummaryTreeWithStats | undefined {\n\t\tif (!this.isEnabled) {\n\t\t\t// Loaded existing document without attributor data: avoid injecting any data.\n\t\t\treturn undefined;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.opAttributor !== undefined,\n\t\t\t0x50b /* RuntimeAttributor should be initialized before summarization */,\n\t\t);\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tbuilder.addBlob(opBlobName, this.encoder.encode(this.opAttributor));\n\t\treturn builder.getSummaryTree();\n\t}\n}\n"]}
|
|
@@ -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 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,MAAM,MAAM,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,61 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Copyright (c) Microsoft Corporation and contributors. All rights reserved.
|
|
3
|
+
* Licensed under the MIT License.
|
|
4
|
+
*/
|
|
5
|
+
import { UsageError } from "@fluidframework/telemetry-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
|
+
return this.getInternedId(input) ?? this.createNewId(input);
|
|
29
|
+
}
|
|
30
|
+
getInternedId(input) {
|
|
31
|
+
return this.stringToInternedIdMap.get(input);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
*
|
|
35
|
+
* @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been
|
|
36
|
+
* used as inputs to calls of `getInternId`.
|
|
37
|
+
* @returns a string that is uniquely associated with the given intern ID
|
|
38
|
+
*/
|
|
39
|
+
getString(internId) {
|
|
40
|
+
const result = this.internedStrings[internId];
|
|
41
|
+
if (!result) {
|
|
42
|
+
throw new UsageError(`No string associated with ${internId}.`);
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of
|
|
48
|
+
* each string.
|
|
49
|
+
*/
|
|
50
|
+
getSerializable() {
|
|
51
|
+
return this.internedStrings;
|
|
52
|
+
}
|
|
53
|
+
/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */
|
|
54
|
+
createNewId(input) {
|
|
55
|
+
const internedId = this.stringToInternedIdMap.size;
|
|
56
|
+
this.stringToInternedIdMap.set(input, internedId);
|
|
57
|
+
this.internedStrings.push(input);
|
|
58
|
+
return internedId;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=stringInterner.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringInterner.mjs","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":"AAAA;;;GAGG;OAEI,EAAE,UAAU,EAAE,MAAM,iCAAiC;AAoB5D;;;;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
ADDED
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fluid-experimental/attributor",
|
|
3
|
+
"version": "2.0.0-dev-rc.1.0.0.224419",
|
|
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
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": {
|
|
17
|
+
"types": "./lib/index.d.mts",
|
|
18
|
+
"default": "./lib/index.mjs"
|
|
19
|
+
},
|
|
20
|
+
"require": {
|
|
21
|
+
"types": "./dist/index.d.ts",
|
|
22
|
+
"default": "./dist/index.cjs"
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"main": "dist/index.cjs",
|
|
27
|
+
"module": "lib/index.mjs",
|
|
28
|
+
"types": "dist/index.d.ts",
|
|
29
|
+
"c8": {
|
|
30
|
+
"all": true,
|
|
31
|
+
"cache-dir": "nyc/.cache",
|
|
32
|
+
"exclude": [
|
|
33
|
+
"src/test/**/*.*ts",
|
|
34
|
+
"dist/test/**/*.*js"
|
|
35
|
+
],
|
|
36
|
+
"exclude-after-remap": false,
|
|
37
|
+
"include": [
|
|
38
|
+
"src/**/*.*ts",
|
|
39
|
+
"dist/**/*.*js"
|
|
40
|
+
],
|
|
41
|
+
"report-dir": "nyc/report",
|
|
42
|
+
"reporter": [
|
|
43
|
+
"cobertura",
|
|
44
|
+
"html",
|
|
45
|
+
"text"
|
|
46
|
+
],
|
|
47
|
+
"temp-directory": "nyc/.nyc_output"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"@fluid-internal/client-utils": "2.0.0-dev-rc.1.0.0.224419",
|
|
51
|
+
"@fluidframework/container-definitions": "2.0.0-dev-rc.1.0.0.224419",
|
|
52
|
+
"@fluidframework/container-runtime": "2.0.0-dev-rc.1.0.0.224419",
|
|
53
|
+
"@fluidframework/container-runtime-definitions": "2.0.0-dev-rc.1.0.0.224419",
|
|
54
|
+
"@fluidframework/core-interfaces": "2.0.0-dev-rc.1.0.0.224419",
|
|
55
|
+
"@fluidframework/core-utils": "2.0.0-dev-rc.1.0.0.224419",
|
|
56
|
+
"@fluidframework/datastore-definitions": "2.0.0-dev-rc.1.0.0.224419",
|
|
57
|
+
"@fluidframework/protocol-definitions": "^3.1.0-223007",
|
|
58
|
+
"@fluidframework/runtime-definitions": "2.0.0-dev-rc.1.0.0.224419",
|
|
59
|
+
"@fluidframework/runtime-utils": "2.0.0-dev-rc.1.0.0.224419",
|
|
60
|
+
"@fluidframework/telemetry-utils": "2.0.0-dev-rc.1.0.0.224419",
|
|
61
|
+
"lz4js": "^0.2.0"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@arethetypeswrong/cli": "^0.13.3",
|
|
65
|
+
"@fluid-private/stochastic-test-utils": "2.0.0-dev-rc.1.0.0.224419",
|
|
66
|
+
"@fluid-tools/build-cli": "0.29.0-222379",
|
|
67
|
+
"@fluidframework/build-common": "^2.0.3",
|
|
68
|
+
"@fluidframework/build-tools": "0.29.0-222379",
|
|
69
|
+
"@fluidframework/driver-definitions": "2.0.0-dev-rc.1.0.0.224419",
|
|
70
|
+
"@fluidframework/eslint-config-fluid": "^3.1.0",
|
|
71
|
+
"@fluidframework/merge-tree": "2.0.0-dev-rc.1.0.0.224419",
|
|
72
|
+
"@fluidframework/mocha-test-setup": "2.0.0-dev-rc.1.0.0.224419",
|
|
73
|
+
"@fluidframework/sequence": "2.0.0-dev-rc.1.0.0.224419",
|
|
74
|
+
"@fluidframework/test-runtime-utils": "2.0.0-dev-rc.1.0.0.224419",
|
|
75
|
+
"@microsoft/api-extractor": "^7.38.3",
|
|
76
|
+
"@types/mocha": "^9.1.1",
|
|
77
|
+
"@types/node": "^18.19.0",
|
|
78
|
+
"c8": "^7.7.1",
|
|
79
|
+
"copyfiles": "^2.4.1",
|
|
80
|
+
"cross-env": "^7.0.3",
|
|
81
|
+
"eslint": "~8.50.0",
|
|
82
|
+
"mocha": "^10.2.0",
|
|
83
|
+
"mocha-json-output-reporter": "^2.0.1",
|
|
84
|
+
"mocha-multi-reporters": "^1.5.1",
|
|
85
|
+
"moment": "^2.21.0",
|
|
86
|
+
"prettier": "~3.0.3",
|
|
87
|
+
"renamer": "^4.0.0",
|
|
88
|
+
"rimraf": "^4.4.0",
|
|
89
|
+
"tsc-multi": "^1.1.0",
|
|
90
|
+
"typescript": "~5.1.6"
|
|
91
|
+
},
|
|
92
|
+
"fluidBuild": {
|
|
93
|
+
"tasks": {
|
|
94
|
+
"build:docs": {
|
|
95
|
+
"dependsOn": [
|
|
96
|
+
"...",
|
|
97
|
+
"api-extractor:commonjs",
|
|
98
|
+
"api-extractor:esnext"
|
|
99
|
+
],
|
|
100
|
+
"script": false
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
"typeValidation": {
|
|
105
|
+
"disabled": true,
|
|
106
|
+
"broken": {}
|
|
107
|
+
},
|
|
108
|
+
"scripts": {
|
|
109
|
+
"api": "fluid-build . --task api",
|
|
110
|
+
"api-extractor:commonjs": "api-extractor run --local",
|
|
111
|
+
"api-extractor:esnext": "copyfiles -u 1 \"dist/**/*-@(alpha|beta|public|untrimmed).d.ts\" lib",
|
|
112
|
+
"build": "fluid-build . --task build",
|
|
113
|
+
"build:commonjs": "fluid-build . --task commonjs",
|
|
114
|
+
"build:compile": "fluid-build . --task compile",
|
|
115
|
+
"build:docs": "fluid-build . --task api",
|
|
116
|
+
"build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
|
|
117
|
+
"build:rename-types": "renamer \"lib/**\" -f .d.ts -r .d.mts --force",
|
|
118
|
+
"build:test": "tsc-multi --config ./tsc-multi.test.json",
|
|
119
|
+
"check:are-the-types-wrong": "attw --pack",
|
|
120
|
+
"check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
|
|
121
|
+
"ci:build:docs": "api-extractor run",
|
|
122
|
+
"clean": "rimraf --glob dist lib \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
|
|
123
|
+
"eslint": "eslint --format stylish src",
|
|
124
|
+
"eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
|
|
125
|
+
"format": "npm run prettier:fix",
|
|
126
|
+
"lint": "npm run prettier && npm run check:release-tags && npm run eslint",
|
|
127
|
+
"lint:fix": "npm run prettier:fix && npm run eslint:fix",
|
|
128
|
+
"prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
|
|
129
|
+
"prettier:fix": "prettier --write . --cache --ignore-path ../../../.prettierignore",
|
|
130
|
+
"test": "npm run test:mocha",
|
|
131
|
+
"test:coverage": "c8 npm test",
|
|
132
|
+
"test:mocha": "mocha --ignore \"dist/test/memory/**/*\" --recursive \"dist/test/**/*.spec.cjs\" -r node_modules/@fluidframework/mocha-test-setup",
|
|
133
|
+
"test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
|
|
134
|
+
"tsc": "tsc-multi --config ../../../common/build/build-common/tsc-multi.cjs.json",
|
|
135
|
+
"typetests:gen": "fluid-type-test-generator",
|
|
136
|
+
"typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
|
|
137
|
+
}
|
|
138
|
+
}
|