@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.
Files changed (75) hide show
  1. package/.eslintrc.js +20 -0
  2. package/.mocharc.js +12 -0
  3. package/CHANGELOG.md +122 -0
  4. package/LICENSE +21 -0
  5. package/README.md +144 -0
  6. package/api-extractor-lint.json +4 -0
  7. package/api-extractor.json +4 -0
  8. package/api-report/attributor.api.md +71 -0
  9. package/dist/attributor-alpha.d.ts +27 -0
  10. package/dist/attributor-beta.d.ts +31 -0
  11. package/dist/attributor-public.d.ts +31 -0
  12. package/dist/attributor-untrimmed.d.ts +124 -0
  13. package/dist/attributor.cjs +69 -0
  14. package/dist/attributor.cjs.map +1 -0
  15. package/dist/attributor.d.ts +56 -0
  16. package/dist/attributor.d.ts.map +1 -0
  17. package/dist/encoders.cjs +80 -0
  18. package/dist/encoders.cjs.map +1 -0
  19. package/dist/encoders.d.ts +28 -0
  20. package/dist/encoders.d.ts.map +1 -0
  21. package/dist/index.cjs +16 -0
  22. package/dist/index.cjs.map +1 -0
  23. package/dist/index.d.ts +7 -0
  24. package/dist/index.d.ts.map +1 -0
  25. package/dist/lz4Encoder.cjs +29 -0
  26. package/dist/lz4Encoder.cjs.map +1 -0
  27. package/dist/lz4Encoder.d.ts +7 -0
  28. package/dist/lz4Encoder.d.ts.map +1 -0
  29. package/dist/mixinAttributor.cjs +170 -0
  30. package/dist/mixinAttributor.cjs.map +1 -0
  31. package/dist/mixinAttributor.d.ts +57 -0
  32. package/dist/mixinAttributor.d.ts.map +1 -0
  33. package/dist/stringInterner.cjs +65 -0
  34. package/dist/stringInterner.cjs.map +1 -0
  35. package/dist/stringInterner.d.ts +55 -0
  36. package/dist/stringInterner.d.ts.map +1 -0
  37. package/dist/tsdoc-metadata.json +11 -0
  38. package/lib/attributor-alpha.d.mts +27 -0
  39. package/lib/attributor-beta.d.mts +31 -0
  40. package/lib/attributor-public.d.mts +31 -0
  41. package/lib/attributor-untrimmed.d.mts +124 -0
  42. package/lib/attributor.d.mts +56 -0
  43. package/lib/attributor.d.mts.map +1 -0
  44. package/lib/attributor.mjs +60 -0
  45. package/lib/attributor.mjs.map +1 -0
  46. package/lib/encoders.d.mts +28 -0
  47. package/lib/encoders.d.mts.map +1 -0
  48. package/lib/encoders.mjs +71 -0
  49. package/lib/encoders.mjs.map +1 -0
  50. package/lib/index.d.mts +3 -0
  51. package/lib/index.d.mts.map +1 -0
  52. package/lib/index.mjs +3 -0
  53. package/lib/index.mjs.map +1 -0
  54. package/lib/lz4Encoder.d.mts +7 -0
  55. package/lib/lz4Encoder.d.mts.map +1 -0
  56. package/lib/lz4Encoder.mjs +21 -0
  57. package/lib/lz4Encoder.mjs.map +1 -0
  58. package/lib/mixinAttributor.d.mts +57 -0
  59. package/lib/mixinAttributor.d.mts.map +1 -0
  60. package/lib/mixinAttributor.mjs +165 -0
  61. package/lib/mixinAttributor.mjs.map +1 -0
  62. package/lib/stringInterner.d.mts +55 -0
  63. package/lib/stringInterner.d.mts.map +1 -0
  64. package/lib/stringInterner.mjs +61 -0
  65. package/lib/stringInterner.mjs.map +1 -0
  66. package/package.json +138 -0
  67. package/prettier.config.cjs +8 -0
  68. package/src/attributor.ts +107 -0
  69. package/src/encoders.ts +111 -0
  70. package/src/index.ts +12 -0
  71. package/src/lz4Encoder.ts +27 -0
  72. package/src/mixinAttributor.ts +317 -0
  73. package/src/stringInterner.ts +86 -0
  74. package/tsc-multi.test.json +4 -0
  75. package/tsconfig.json +12 -0
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ /*!
3
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
+ * Licensed under the MIT License.
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.MutableStringInterner = void 0;
8
+ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
9
+ /**
10
+ * Interns strings as integers.
11
+ * Given a string, this class will produce a unique integer associated with that string that can then be used to
12
+ * retrieve the string.
13
+ */
14
+ class MutableStringInterner {
15
+ /**
16
+ * @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous
17
+ * `StringInterner`'s {@link StringInterner.getSerializable} return value.
18
+ */
19
+ constructor(inputStrings = []) {
20
+ this.stringToInternedIdMap = new Map();
21
+ this.internedStrings = [];
22
+ for (const value of inputStrings) {
23
+ this.getOrCreateInternedId(value);
24
+ }
25
+ }
26
+ /**
27
+ * @param input - The string to get the associated intern ID for
28
+ * @returns an intern ID that is uniquely associated with the input string
29
+ */
30
+ getOrCreateInternedId(input) {
31
+ return this.getInternedId(input) ?? this.createNewId(input);
32
+ }
33
+ getInternedId(input) {
34
+ return this.stringToInternedIdMap.get(input);
35
+ }
36
+ /**
37
+ *
38
+ * @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been
39
+ * used as inputs to calls of `getInternId`.
40
+ * @returns a string that is uniquely associated with the given intern ID
41
+ */
42
+ getString(internId) {
43
+ const result = this.internedStrings[internId];
44
+ if (!result) {
45
+ throw new telemetry_utils_1.UsageError(`No string associated with ${internId}.`);
46
+ }
47
+ return result;
48
+ }
49
+ /**
50
+ * @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of
51
+ * each string.
52
+ */
53
+ getSerializable() {
54
+ return this.internedStrings;
55
+ }
56
+ /** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */
57
+ createNewId(input) {
58
+ const internedId = this.stringToInternedIdMap.size;
59
+ this.stringToInternedIdMap.set(input, internedId);
60
+ this.internedStrings.push(input);
61
+ return internedId;
62
+ }
63
+ }
64
+ exports.MutableStringInterner = MutableStringInterner;
65
+ //# sourceMappingURL=stringInterner.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringInterner.cjs","sourceRoot":"","sources":["../src/stringInterner.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,qEAA6D;AAoB7D;;;;GAIG;AACH,MAAa,qBAAqB;IAIjC;;;OAGG;IACH,YAAY,eAAkC,EAAE;QAP/B,0BAAqB,GAAG,IAAI,GAAG,EAA4B,CAAC;QAC5D,oBAAe,GAAa,EAAE,CAAC;QAO/C,KAAK,MAAM,KAAK,IAAI,YAAY,EAAE;YACjC,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;SAClC;IACF,CAAC;IAED;;;OAGG;IACI,qBAAqB,CAAC,KAAa;QACzC,OAAO,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,IAAI,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;IAC7D,CAAC;IAEM,aAAa,CAAC,KAAa;QACjC,OAAO,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAED;;;;;OAKG;IACI,SAAS,CAAC,QAAgB;QAChC,MAAM,MAAM,GAAG,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,4BAAU,CAAC,6BAA6B,QAAQ,GAAG,CAAC,CAAC;SAC/D;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;;OAGG;IACI,eAAe;QACrB,OAAO,IAAI,CAAC,eAAe,CAAC;IAC7B,CAAC;IAED,+GAA+G;IACvG,WAAW,CAAC,KAAa;QAChC,MAAM,UAAU,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAwB,CAAC;QACvE,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,KAAK,EAAE,UAAU,CAAC,CAAC;QAClD,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACjC,OAAO,UAAU,CAAC;IACnB,CAAC;CACD;AAvDD,sDAuDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\n\n/**\n * The ID of the string that has been interned, which can be used by a {@link StringInterner} to retrieve the\n * original string.\n * @public\n */\nexport type InternedStringId = number & {\n\treadonly InternedStringId: \"e221abc9-9d17-4493-8db0-70c871a1c27c\";\n};\n\n/**\n * Interns strings as integers.\n */\nexport interface StringInterner {\n\tgetInternedId(input: string): InternedStringId | undefined;\n\tgetString(internedId: number): string;\n\tgetSerializable(): readonly string[];\n}\n\n/**\n * Interns strings as integers.\n * Given a string, this class will produce a unique integer associated with that string that can then be used to\n * retrieve the string.\n */\nexport class MutableStringInterner implements StringInterner {\n\tprivate readonly stringToInternedIdMap = new Map<string, InternedStringId>();\n\tprivate readonly internedStrings: string[] = [];\n\n\t/**\n\t * @param inputStrings - A list of strings to intern in the order given. Can be used to rehydrate from a previous\n\t * `StringInterner`'s {@link StringInterner.getSerializable} return value.\n\t */\n\tconstructor(inputStrings: readonly string[] = []) {\n\t\tfor (const value of inputStrings) {\n\t\t\tthis.getOrCreateInternedId(value);\n\t\t}\n\t}\n\n\t/**\n\t * @param input - The string to get the associated intern ID for\n\t * @returns an intern ID that is uniquely associated with the input string\n\t */\n\tpublic getOrCreateInternedId(input: string): InternedStringId {\n\t\treturn this.getInternedId(input) ?? this.createNewId(input);\n\t}\n\n\tpublic getInternedId(input: string): InternedStringId | undefined {\n\t\treturn this.stringToInternedIdMap.get(input);\n\t}\n\n\t/**\n\t *\n\t * @param internId - The intern ID to get the associated string for. Can only retrieve strings that have been\n\t * used as inputs to calls of `getInternId`.\n\t * @returns a string that is uniquely associated with the given intern ID\n\t */\n\tpublic getString(internId: number): string {\n\t\tconst result = this.internedStrings[internId];\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`No string associated with ${internId}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * @returns The list of strings interned where the indices map to the associated {@link InternedStringId} of\n\t * each string.\n\t */\n\tpublic getSerializable(): readonly string[] {\n\t\treturn this.internedStrings;\n\t}\n\n\t/** Create a new interned id. Assumes without validation that the input doesn't already have an interned id. */\n\tprivate createNewId(input: string): InternedStringId {\n\t\tconst internedId = this.stringToInternedIdMap.size as InternedStringId;\n\t\tthis.stringToInternedIdMap.set(input, internedId);\n\t\tthis.internedStrings.push(input);\n\t\treturn internedId;\n\t}\n}\n"]}
@@ -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,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.38.3"
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,27 @@
1
+ import { AttributionInfo } from '@fluidframework/runtime-definitions';
2
+ import { AttributionKey } from '@fluidframework/runtime-definitions';
3
+ import { ContainerRuntime } from '@fluidframework/container-runtime';
4
+ import { IAudience } from '@fluidframework/container-definitions';
5
+ import { IDeltaManager } from '@fluidframework/container-definitions';
6
+ import { IDocumentMessage } from '@fluidframework/protocol-definitions';
7
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
8
+
9
+ /* Excluded from this release type: AttributionInfo */
10
+
11
+ /* Excluded from this release type: Attributor */
12
+
13
+ /* Excluded from this release type: createRuntimeAttributor */
14
+
15
+ /* Excluded from this release type: enableOnNewFileKey */
16
+
17
+ /* Excluded from this release type: IAttributor */
18
+
19
+ /* Excluded from this release type: IProvideRuntimeAttributor */
20
+
21
+ /* Excluded from this release type: IRuntimeAttributor */
22
+
23
+ /* Excluded from this release type: mixinAttributor */
24
+
25
+ /* Excluded from this release type: OpStreamAttributor */
26
+
27
+ export { }
@@ -0,0 +1,31 @@
1
+ import { AttributionInfo } from '@fluidframework/runtime-definitions';
2
+ import { AttributionKey } from '@fluidframework/runtime-definitions';
3
+ import { ContainerRuntime } from '@fluidframework/container-runtime';
4
+ import { IAudience } from '@fluidframework/container-definitions';
5
+ import { IDeltaManager } from '@fluidframework/container-definitions';
6
+ import { IDocumentMessage } from '@fluidframework/protocol-definitions';
7
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
8
+
9
+ /* Excluded from this release type: AttributionInfo */
10
+
11
+ /* Excluded from this release type: AttributionKey */
12
+
13
+ /* Excluded from this release type: Attributor */
14
+
15
+ /* Excluded from this release type: ContainerRuntime */
16
+
17
+ /* Excluded from this release type: createRuntimeAttributor */
18
+
19
+ /* Excluded from this release type: enableOnNewFileKey */
20
+
21
+ /* Excluded from this release type: IAttributor */
22
+
23
+ /* Excluded from this release type: IProvideRuntimeAttributor */
24
+
25
+ /* Excluded from this release type: IRuntimeAttributor */
26
+
27
+ /* Excluded from this release type: mixinAttributor */
28
+
29
+ /* Excluded from this release type: OpStreamAttributor */
30
+
31
+ export { }
@@ -0,0 +1,31 @@
1
+ import { AttributionInfo } from '@fluidframework/runtime-definitions';
2
+ import { AttributionKey } from '@fluidframework/runtime-definitions';
3
+ import { ContainerRuntime } from '@fluidframework/container-runtime';
4
+ import { IAudience } from '@fluidframework/container-definitions';
5
+ import { IDeltaManager } from '@fluidframework/container-definitions';
6
+ import { IDocumentMessage } from '@fluidframework/protocol-definitions';
7
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
8
+
9
+ /* Excluded from this release type: AttributionInfo */
10
+
11
+ /* Excluded from this release type: AttributionKey */
12
+
13
+ /* Excluded from this release type: Attributor */
14
+
15
+ /* Excluded from this release type: ContainerRuntime */
16
+
17
+ /* Excluded from this release type: createRuntimeAttributor */
18
+
19
+ /* Excluded from this release type: enableOnNewFileKey */
20
+
21
+ /* Excluded from this release type: IAttributor */
22
+
23
+ /* Excluded from this release type: IProvideRuntimeAttributor */
24
+
25
+ /* Excluded from this release type: IRuntimeAttributor */
26
+
27
+ /* Excluded from this release type: mixinAttributor */
28
+
29
+ /* Excluded from this release type: OpStreamAttributor */
30
+
31
+ export { }
@@ -0,0 +1,124 @@
1
+ import { AttributionInfo } from '@fluidframework/runtime-definitions';
2
+ import { AttributionKey } from '@fluidframework/runtime-definitions';
3
+ import { ContainerRuntime } from '@fluidframework/container-runtime';
4
+ import { IAudience } from '@fluidframework/container-definitions';
5
+ import { IDeltaManager } from '@fluidframework/container-definitions';
6
+ import { IDocumentMessage } from '@fluidframework/protocol-definitions';
7
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
8
+
9
+ /**
10
+ * {@inheritdoc IAttributor}
11
+ * @internal
12
+ */
13
+ export declare class Attributor implements IAttributor {
14
+ protected readonly keyToInfo: Map<number, AttributionInfo>;
15
+ /**
16
+ * @param initialEntries - Any entries which should be populated on instantiation.
17
+ */
18
+ constructor(initialEntries?: Iterable<[number, AttributionInfo]>);
19
+ /**
20
+ * {@inheritdoc IAttributor.getAttributionInfo}
21
+ */
22
+ getAttributionInfo(key: number): AttributionInfo;
23
+ /**
24
+ * {@inheritdoc IAttributor.tryGetAttributionInfo}
25
+ */
26
+ tryGetAttributionInfo(key: number): AttributionInfo | undefined;
27
+ /**
28
+ * {@inheritdoc IAttributor.entries}
29
+ */
30
+ entries(): IterableIterator<[number, AttributionInfo]>;
31
+ }
32
+
33
+ /**
34
+ * @returns an IRuntimeAttributor for usage with `mixinAttributor`. The attributor will only be populated with data
35
+ * once it's passed via scope to a container runtime load flow. See {@link mixinAttributor}.
36
+ * @internal
37
+ */
38
+ export declare function createRuntimeAttributor(): IRuntimeAttributor;
39
+
40
+ /**
41
+ * @internal
42
+ */
43
+ export declare const enableOnNewFileKey = "Fluid.Attribution.EnableOnNewFile";
44
+
45
+ /**
46
+ * Provides lookup between attribution keys and their associated attribution information.
47
+ * @internal
48
+ */
49
+ export declare interface IAttributor {
50
+ /**
51
+ * Retrieves attribution information associated with a particular key.
52
+ * @param key - Attribution key to look up.
53
+ * @throws If no attribution information is recorded for that key.
54
+ */
55
+ getAttributionInfo(key: number): AttributionInfo;
56
+ /**
57
+ * @param key - Attribution key to look up.
58
+ * @returns the attribution information associated with the provided key, or undefined if no information exists.
59
+ */
60
+ tryGetAttributionInfo(key: number): AttributionInfo | undefined;
61
+ /**
62
+ * @returns an iterable of (attribution key, attribution info) pairs for each stored key.
63
+ */
64
+ entries(): IterableIterator<[number, AttributionInfo]>;
65
+ }
66
+
67
+ /**
68
+ * @internal
69
+ */
70
+ export declare interface IProvideRuntimeAttributor {
71
+ readonly IRuntimeAttributor: IRuntimeAttributor;
72
+ }
73
+
74
+ /**
75
+ * @internal
76
+ */
77
+ export declare const IRuntimeAttributor: keyof IProvideRuntimeAttributor;
78
+
79
+ /**
80
+ * Provides access to attribution information stored on the container runtime.
81
+ *
82
+ * Attributors are only populated after the container runtime they are injected into has initialized.
83
+ * @sealed
84
+ * @internal
85
+ */
86
+ export declare interface IRuntimeAttributor extends IProvideRuntimeAttributor {
87
+ /**
88
+ * @throws - If no AttributionInfo exists for this key.
89
+ */
90
+ get(key: AttributionKey): AttributionInfo;
91
+ /**
92
+ * @returns Whether any AttributionInfo exists for the provided key.
93
+ */
94
+ has(key: AttributionKey): boolean;
95
+ /**
96
+ * @returns Whether the runtime is currently tracking attribution information for the loaded container.
97
+ * See {@link mixinAttributor} for more details on when this happens.
98
+ */
99
+ readonly isEnabled: boolean;
100
+ }
101
+
102
+ /**
103
+ * Mixes in logic to load and store runtime-based attribution functionality.
104
+ *
105
+ * The `scope` passed to `load` should implement `IProvideRuntimeAttributor`.
106
+ *
107
+ * Existing documents without stored attributors will not start storing attribution information: if an
108
+ * IRuntimeAttributor is passed via scope to load a document that never previously had attribution information,
109
+ * that attributor's `has` method will always return `false`.
110
+ * @param Base - base class, inherits from FluidAttributorRuntime
111
+ * @internal
112
+ */
113
+ export declare const mixinAttributor: (Base?: typeof ContainerRuntime) => typeof ContainerRuntime;
114
+
115
+ /**
116
+ * Attributor which listens to an op stream and records entries for each op.
117
+ * Sequence numbers are used as attribution keys.
118
+ * @internal
119
+ */
120
+ export declare class OpStreamAttributor extends Attributor implements IAttributor {
121
+ constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, audience: IAudience, initialEntries?: Iterable<[number, AttributionInfo]>);
122
+ }
123
+
124
+ export { }
@@ -0,0 +1,56 @@
1
+ import { IDocumentMessage, ISequencedDocumentMessage } from "@fluidframework/protocol-definitions";
2
+ import { AttributionInfo } from "@fluidframework/runtime-definitions";
3
+ import { IAudience, IDeltaManager } from "@fluidframework/container-definitions";
4
+ /**
5
+ * Provides lookup between attribution keys and their associated attribution information.
6
+ * @internal
7
+ */
8
+ export interface IAttributor {
9
+ /**
10
+ * Retrieves attribution information associated with a particular key.
11
+ * @param key - Attribution key to look up.
12
+ * @throws If no attribution information is recorded for that key.
13
+ */
14
+ getAttributionInfo(key: number): AttributionInfo;
15
+ /**
16
+ * @param key - Attribution key to look up.
17
+ * @returns the attribution information associated with the provided key, or undefined if no information exists.
18
+ */
19
+ tryGetAttributionInfo(key: number): AttributionInfo | undefined;
20
+ /**
21
+ * @returns an iterable of (attribution key, attribution info) pairs for each stored key.
22
+ */
23
+ entries(): IterableIterator<[number, AttributionInfo]>;
24
+ }
25
+ /**
26
+ * {@inheritdoc IAttributor}
27
+ * @internal
28
+ */
29
+ export declare class Attributor implements IAttributor {
30
+ protected readonly keyToInfo: Map<number, AttributionInfo>;
31
+ /**
32
+ * @param initialEntries - Any entries which should be populated on instantiation.
33
+ */
34
+ constructor(initialEntries?: Iterable<[number, AttributionInfo]>);
35
+ /**
36
+ * {@inheritdoc IAttributor.getAttributionInfo}
37
+ */
38
+ getAttributionInfo(key: number): AttributionInfo;
39
+ /**
40
+ * {@inheritdoc IAttributor.tryGetAttributionInfo}
41
+ */
42
+ tryGetAttributionInfo(key: number): AttributionInfo | undefined;
43
+ /**
44
+ * {@inheritdoc IAttributor.entries}
45
+ */
46
+ entries(): IterableIterator<[number, AttributionInfo]>;
47
+ }
48
+ /**
49
+ * Attributor which listens to an op stream and records entries for each op.
50
+ * Sequence numbers are used as attribution keys.
51
+ * @internal
52
+ */
53
+ export declare class OpStreamAttributor extends Attributor implements IAttributor {
54
+ constructor(deltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>, audience: IAudience, initialEntries?: Iterable<[number, AttributionInfo]>);
55
+ }
56
+ //# sourceMappingURL=attributor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributor.d.ts","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"OAKO,EAAE,gBAAgB,EAAE,yBAAyB,EAAE,MAAM,sCAAsC;OAC3F,EAAE,eAAe,EAAE,MAAM,qCAAqC;OAE9D,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,uCAAuC;AAEhF;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC3B;;;;OAIG;IACH,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,CAAC;IAEjD;;;OAGG;IACH,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS,CAAC;IAEhE;;OAEG;IACH,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC;CAIvD;AAED;;;GAGG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC7C,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE3D;;OAEG;gBACS,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAIhE;;OAEG;IACI,kBAAkB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe;IAQvD;;OAEG;IACI,qBAAqB,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG,SAAS;IAItE;;OAEG;IACI,OAAO,IAAI,gBAAgB,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAG7D;AAED;;;;GAIG;AACH,qBAAa,kBAAmB,SAAQ,UAAW,YAAW,WAAW;gBAEvE,YAAY,EAAE,aAAa,CAAC,yBAAyB,EAAE,gBAAgB,CAAC,EACxE,QAAQ,EAAE,SAAS,EACnB,cAAc,CAAC,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;CAoBrD"}
@@ -0,0 +1,60 @@
1
+ import { assert } from "@fluidframework/core-utils";
2
+ import { UsageError } from "@fluidframework/telemetry-utils";
3
+ /**
4
+ * {@inheritdoc IAttributor}
5
+ * @internal
6
+ */
7
+ export class Attributor {
8
+ /**
9
+ * @param initialEntries - Any entries which should be populated on instantiation.
10
+ */
11
+ constructor(initialEntries) {
12
+ this.keyToInfo = new Map(initialEntries ?? []);
13
+ }
14
+ /**
15
+ * {@inheritdoc IAttributor.getAttributionInfo}
16
+ */
17
+ getAttributionInfo(key) {
18
+ const result = this.tryGetAttributionInfo(key);
19
+ if (!result) {
20
+ throw new UsageError(`Requested attribution information for unstored key: ${key}.`);
21
+ }
22
+ return result;
23
+ }
24
+ /**
25
+ * {@inheritdoc IAttributor.tryGetAttributionInfo}
26
+ */
27
+ tryGetAttributionInfo(key) {
28
+ return this.keyToInfo.get(key);
29
+ }
30
+ /**
31
+ * {@inheritdoc IAttributor.entries}
32
+ */
33
+ entries() {
34
+ return this.keyToInfo.entries();
35
+ }
36
+ }
37
+ /**
38
+ * Attributor which listens to an op stream and records entries for each op.
39
+ * Sequence numbers are used as attribution keys.
40
+ * @internal
41
+ */
42
+ export class OpStreamAttributor extends Attributor {
43
+ constructor(deltaManager, audience, initialEntries) {
44
+ super(initialEntries);
45
+ deltaManager.on("op", (message) => {
46
+ // TODO: Verify whether this should be able to handle server-generated ops (with null clientId)
47
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
48
+ const client = audience.getMember(message.clientId);
49
+ if (message.type === "op") {
50
+ // TODO: This case may be legitimate, and if so we need to figure out how to handle it.
51
+ assert(client !== undefined, 0x4af /* Received message from user not in the audience */);
52
+ this.keyToInfo.set(message.sequenceNumber, {
53
+ user: client.user,
54
+ timestamp: message.timestamp,
55
+ });
56
+ }
57
+ });
58
+ }
59
+ }
60
+ //# sourceMappingURL=attributor.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attributor.mjs","sourceRoot":"","sources":["../src/attributor.ts"],"names":[],"mappings":"OAIO,EAAE,MAAM,EAAE,MAAM,4BAA4B;OAG5C,EAAE,UAAU,EAAE,MAAM,iCAAiC;AA8B5D;;;GAGG;AACH,MAAM,OAAO,UAAU;IAGtB;;OAEG;IACH,YAAY,cAAoD;QAC/D,IAAI,CAAC,SAAS,GAAG,IAAI,GAAG,CAAC,cAAc,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,kBAAkB,CAAC,GAAW;QACpC,MAAM,MAAM,GAAG,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,CAAC;QAC/C,IAAI,CAAC,MAAM,EAAE;YACZ,MAAM,IAAI,UAAU,CAAC,uDAAuD,GAAG,GAAG,CAAC,CAAC;SACpF;QACD,OAAO,MAAM,CAAC;IACf,CAAC;IAED;;OAEG;IACI,qBAAqB,CAAC,GAAW;QACvC,OAAO,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED;;OAEG;IACI,OAAO;QACb,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,CAAC;IACjC,CAAC;CACD;AAED;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IACjD,YACC,YAAwE,EACxE,QAAmB,EACnB,cAAoD;QAEpD,KAAK,CAAC,cAAc,CAAC,CAAC;QACtB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,OAAkC,EAAE,EAAE;YAC5D,+FAA+F;YAC/F,4EAA4E;YAC5E,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,QAAkB,CAAC,CAAC;YAC9D,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE;gBAC1B,uFAAuF;gBACvF,MAAM,CACL,MAAM,KAAK,SAAS,EACpB,KAAK,CAAC,oDAAoD,CAC1D,CAAC;gBACF,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,cAAc,EAAE;oBAC1C,IAAI,EAAE,MAAM,CAAC,IAAI;oBACjB,SAAS,EAAE,OAAO,CAAC,SAAS;iBAC5B,CAAC,CAAC;aACH;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { assert } from \"@fluidframework/core-utils\";\nimport { IDocumentMessage, ISequencedDocumentMessage } from \"@fluidframework/protocol-definitions\";\nimport { AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { UsageError } from \"@fluidframework/telemetry-utils\";\nimport { IAudience, IDeltaManager } from \"@fluidframework/container-definitions\";\n\n/**\n * Provides lookup between attribution keys and their associated attribution information.\n * @internal\n */\nexport interface IAttributor {\n\t/**\n\t * Retrieves attribution information associated with a particular key.\n\t * @param key - Attribution key to look up.\n\t * @throws If no attribution information is recorded for that key.\n\t */\n\tgetAttributionInfo(key: number): AttributionInfo;\n\n\t/**\n\t * @param key - Attribution key to look up.\n\t * @returns the attribution information associated with the provided key, or undefined if no information exists.\n\t */\n\ttryGetAttributionInfo(key: number): AttributionInfo | undefined;\n\n\t/**\n\t * @returns an iterable of (attribution key, attribution info) pairs for each stored key.\n\t */\n\tentries(): IterableIterator<[number, AttributionInfo]>;\n\n\t// TODO:\n\t// - GC\n}\n\n/**\n * {@inheritdoc IAttributor}\n * @internal\n */\nexport class Attributor implements IAttributor {\n\tprotected readonly keyToInfo: Map<number, AttributionInfo>;\n\n\t/**\n\t * @param initialEntries - Any entries which should be populated on instantiation.\n\t */\n\tconstructor(initialEntries?: Iterable<[number, AttributionInfo]>) {\n\t\tthis.keyToInfo = new Map(initialEntries ?? []);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.getAttributionInfo}\n\t */\n\tpublic getAttributionInfo(key: number): AttributionInfo {\n\t\tconst result = this.tryGetAttributionInfo(key);\n\t\tif (!result) {\n\t\t\tthrow new UsageError(`Requested attribution information for unstored key: ${key}.`);\n\t\t}\n\t\treturn result;\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.tryGetAttributionInfo}\n\t */\n\tpublic tryGetAttributionInfo(key: number): AttributionInfo | undefined {\n\t\treturn this.keyToInfo.get(key);\n\t}\n\n\t/**\n\t * {@inheritdoc IAttributor.entries}\n\t */\n\tpublic entries(): IterableIterator<[number, AttributionInfo]> {\n\t\treturn this.keyToInfo.entries();\n\t}\n}\n\n/**\n * Attributor which listens to an op stream and records entries for each op.\n * Sequence numbers are used as attribution keys.\n * @internal\n */\nexport class OpStreamAttributor extends Attributor implements IAttributor {\n\tconstructor(\n\t\tdeltaManager: IDeltaManager<ISequencedDocumentMessage, IDocumentMessage>,\n\t\taudience: IAudience,\n\t\tinitialEntries?: Iterable<[number, AttributionInfo]>,\n\t) {\n\t\tsuper(initialEntries);\n\t\tdeltaManager.on(\"op\", (message: ISequencedDocumentMessage) => {\n\t\t\t// TODO: Verify whether this should be able to handle server-generated ops (with null clientId)\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n\t\t\tconst client = audience.getMember(message.clientId as string);\n\t\t\tif (message.type === \"op\") {\n\t\t\t\t// TODO: This case may be legitimate, and if so we need to figure out how to handle it.\n\t\t\t\tassert(\n\t\t\t\t\tclient !== undefined,\n\t\t\t\t\t0x4af /* Received message from user not in the audience */,\n\t\t\t\t);\n\t\t\t\tthis.keyToInfo.set(message.sequenceNumber, {\n\t\t\t\t\tuser: client.user,\n\t\t\t\t\ttimestamp: message.timestamp,\n\t\t\t\t});\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import { AttributionInfo } from "@fluidframework/runtime-definitions";
2
+ import { IAttributor } from "./attributor.mjs";
3
+ import { InternedStringId } from "./stringInterner.mjs";
4
+ export interface Encoder<TDecoded, TEncoded> {
5
+ encode(decoded: TDecoded): TEncoded;
6
+ decode(encoded: TEncoded): TDecoded;
7
+ }
8
+ export type TimestampEncoder = Encoder<number[], number[]>;
9
+ export declare const deltaEncoder: TimestampEncoder;
10
+ export type IAttributorSerializer = Encoder<IAttributor, SerializedAttributor>;
11
+ export interface SerializedAttributor {
12
+ interner: readonly string[];
13
+ seqs: number[];
14
+ timestamps: number[];
15
+ attributionRefs: InternedStringId[];
16
+ }
17
+ export declare class AttributorSerializer implements IAttributorSerializer {
18
+ private readonly makeAttributor;
19
+ private readonly timestampEncoder;
20
+ constructor(makeAttributor: (entries: Iterable<[number, AttributionInfo]>) => IAttributor, timestampEncoder: TimestampEncoder);
21
+ encode(attributor: IAttributor): SerializedAttributor;
22
+ decode(encoded: SerializedAttributor): IAttributor;
23
+ }
24
+ /**
25
+ * @returns an encoder which composes `a` and `b`.
26
+ */
27
+ export declare const chain: <T1, T2, T3>(a: Encoder<T1, T2>, b: Encoder<T2, T3>) => Encoder<T1, T3>;
28
+ //# sourceMappingURL=encoders.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoders.d.ts","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"OAMO,EAAE,eAAe,EAAE,MAAM,qCAAqC;OAC9D,EAAE,WAAW,EAAE;OACf,EAAE,gBAAgB,EAAyB;AAElD,MAAM,WAAW,OAAO,CAAC,QAAQ,EAAE,QAAQ;IAC1C,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAEpC,MAAM,CAAC,OAAO,EAAE,QAAQ,GAAG,QAAQ,CAAC;CACpC;AAID,MAAM,MAAM,gBAAgB,GAAG,OAAO,CAAC,MAAM,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;AAE3D,eAAO,MAAM,YAAY,EAAE,gBAuB1B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG,OAAO,CAAC,WAAW,EAAE,oBAAoB,CAAC,CAAC;AAE/E,MAAM,WAAW,oBAAoB;IACpC,QAAQ,EAAE,SAAS,MAAM,EAAE,CAA+D;IAC1F,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,eAAe,EAAE,gBAAgB,EAAE,CAAC;CACpC;AAED,qBAAa,oBAAqB,YAAW,qBAAqB;IAEhE,OAAO,CAAC,QAAQ,CAAC,cAAc;IAG/B,OAAO,CAAC,QAAQ,CAAC,gBAAgB;gBAHhB,cAAc,EAAE,CAChC,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC,KACxC,WAAW,EACC,gBAAgB,EAAE,gBAAgB;IAG7C,MAAM,CAAC,UAAU,EAAE,WAAW,GAAG,oBAAoB;IAsBrD,MAAM,CAAC,OAAO,EAAE,oBAAoB,GAAG,WAAW;CAkBzD;AAED;;GAEG;AACH,eAAO,MAAM,KAAK,yEAGhB,CAAC"}
@@ -0,0 +1,71 @@
1
+ import { assert } from "@fluidframework/core-utils";
2
+ import { MutableStringInterner } from "./stringInterner.mjs";
3
+ export const deltaEncoder = {
4
+ encode: (timestamps) => {
5
+ const deltaTimestamps = new Array(timestamps.length);
6
+ let prev = 0;
7
+ for (let i = 0; i < timestamps.length; i++) {
8
+ deltaTimestamps[i] = timestamps[i] - prev;
9
+ prev = timestamps[i];
10
+ }
11
+ return deltaTimestamps;
12
+ },
13
+ decode: (encoded) => {
14
+ assert(Array.isArray(encoded), 0x4b0 /* Encoded timestamps should be an array of numbers */);
15
+ const timestamps = new Array(encoded.length);
16
+ let cumulativeSum = 0;
17
+ for (let i = 0; i < encoded.length; i++) {
18
+ cumulativeSum += encoded[i];
19
+ timestamps[i] = cumulativeSum;
20
+ }
21
+ return timestamps;
22
+ },
23
+ };
24
+ export class AttributorSerializer {
25
+ constructor(makeAttributor, timestampEncoder) {
26
+ this.makeAttributor = makeAttributor;
27
+ this.timestampEncoder = timestampEncoder;
28
+ }
29
+ encode(attributor) {
30
+ const interner = new MutableStringInterner();
31
+ const seqs = [];
32
+ const timestamps = [];
33
+ const attributionRefs = [];
34
+ for (const [seq, { user, timestamp }] of attributor.entries()) {
35
+ seqs.push(seq);
36
+ timestamps.push(timestamp);
37
+ const ref = interner.getOrCreateInternedId(JSON.stringify(user));
38
+ attributionRefs.push(ref);
39
+ }
40
+ const serialized = {
41
+ interner: interner.getSerializable(),
42
+ seqs,
43
+ timestamps: this.timestampEncoder.encode(timestamps),
44
+ attributionRefs,
45
+ };
46
+ return serialized;
47
+ }
48
+ decode(encoded) {
49
+ const interner = new MutableStringInterner(encoded.interner);
50
+ const { seqs, timestamps: encodedTimestamps, attributionRefs } = encoded;
51
+ const timestamps = this.timestampEncoder.decode(encodedTimestamps);
52
+ assert(seqs.length === timestamps.length && timestamps.length === attributionRefs.length, 0x4b1 /* serialized attribution columns should have the same length */);
53
+ const entries = new Array(seqs.length);
54
+ for (let i = 0; i < seqs.length; i++) {
55
+ const key = seqs[i];
56
+ const timestamp = timestamps[i];
57
+ const ref = attributionRefs[i];
58
+ const user = JSON.parse(interner.getString(ref));
59
+ entries[i] = [key, { user, timestamp }];
60
+ }
61
+ return this.makeAttributor(entries);
62
+ }
63
+ }
64
+ /**
65
+ * @returns an encoder which composes `a` and `b`.
66
+ */
67
+ export const chain = (a, b) => ({
68
+ encode: (content) => b.encode(a.encode(content)),
69
+ decode: (content) => a.decode(b.decode(content)),
70
+ });
71
+ //# sourceMappingURL=encoders.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"encoders.mjs","sourceRoot":"","sources":["../src/encoders.ts"],"names":[],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nimport { assert } from \"@fluidframework/core-utils\";\nimport { IUser } from \"@fluidframework/protocol-definitions\";\nimport { AttributionInfo } from \"@fluidframework/runtime-definitions\";\nimport { IAttributor } from \"./attributor\";\nimport { InternedStringId, MutableStringInterner } from \"./stringInterner\";\n\nexport interface Encoder<TDecoded, TEncoded> {\n\tencode(decoded: TDecoded): TEncoded;\n\n\tdecode(encoded: TEncoded): TDecoded;\n}\n\n// Note: the encoded format doesn't matter as long as it's serializable;\n// these types could be weakened.\nexport type TimestampEncoder = Encoder<number[], number[]>;\n\nexport const deltaEncoder: TimestampEncoder = {\n\tencode: (timestamps: number[]) => {\n\t\tconst deltaTimestamps: number[] = new Array(timestamps.length);\n\t\tlet prev = 0;\n\t\tfor (let i = 0; i < timestamps.length; i++) {\n\t\t\tdeltaTimestamps[i] = timestamps[i] - prev;\n\t\t\tprev = timestamps[i];\n\t\t}\n\t\treturn deltaTimestamps;\n\t},\n\tdecode: (encoded: unknown) => {\n\t\tassert(\n\t\t\tArray.isArray(encoded),\n\t\t\t0x4b0 /* Encoded timestamps should be an array of numbers */,\n\t\t);\n\t\tconst timestamps: number[] = new Array(encoded.length);\n\t\tlet cumulativeSum = 0;\n\t\tfor (let i = 0; i < encoded.length; i++) {\n\t\t\tcumulativeSum += encoded[i];\n\t\t\ttimestamps[i] = cumulativeSum;\n\t\t}\n\t\treturn timestamps;\n\t},\n};\n\nexport type IAttributorSerializer = Encoder<IAttributor, SerializedAttributor>;\n\nexport interface SerializedAttributor {\n\tinterner: readonly string[] /* result of calling getSerializable() on a StringInterner */;\n\tseqs: number[];\n\ttimestamps: number[];\n\tattributionRefs: InternedStringId[];\n}\n\nexport class AttributorSerializer implements IAttributorSerializer {\n\tconstructor(\n\t\tprivate readonly makeAttributor: (\n\t\t\tentries: Iterable<[number, AttributionInfo]>,\n\t\t) => IAttributor,\n\t\tprivate readonly timestampEncoder: TimestampEncoder,\n\t) {}\n\n\tpublic encode(attributor: IAttributor): SerializedAttributor {\n\t\tconst interner = new MutableStringInterner();\n\t\tconst seqs: number[] = [];\n\t\tconst timestamps: number[] = [];\n\t\tconst attributionRefs: InternedStringId[] = [];\n\t\tfor (const [seq, { user, timestamp }] of attributor.entries()) {\n\t\t\tseqs.push(seq);\n\t\t\ttimestamps.push(timestamp);\n\t\t\tconst ref = interner.getOrCreateInternedId(JSON.stringify(user));\n\t\t\tattributionRefs.push(ref);\n\t\t}\n\n\t\tconst serialized: SerializedAttributor = {\n\t\t\tinterner: interner.getSerializable(),\n\t\t\tseqs,\n\t\t\ttimestamps: this.timestampEncoder.encode(timestamps),\n\t\t\tattributionRefs,\n\t\t};\n\n\t\treturn serialized;\n\t}\n\n\tpublic decode(encoded: SerializedAttributor): IAttributor {\n\t\tconst interner = new MutableStringInterner(encoded.interner);\n\t\tconst { seqs, timestamps: encodedTimestamps, attributionRefs } = encoded;\n\t\tconst timestamps = this.timestampEncoder.decode(encodedTimestamps);\n\t\tassert(\n\t\t\tseqs.length === timestamps.length && timestamps.length === attributionRefs.length,\n\t\t\t0x4b1 /* serialized attribution columns should have the same length */,\n\t\t);\n\t\tconst entries = new Array(seqs.length);\n\t\tfor (let i = 0; i < seqs.length; i++) {\n\t\t\tconst key = seqs[i];\n\t\t\tconst timestamp = timestamps[i];\n\t\t\tconst ref = attributionRefs[i];\n\t\t\tconst user: IUser = JSON.parse(interner.getString(ref));\n\t\t\tentries[i] = [key, { user, timestamp }];\n\t\t}\n\t\treturn this.makeAttributor(entries);\n\t}\n}\n\n/**\n * @returns an encoder which composes `a` and `b`.\n */\nexport const chain = <T1, T2, T3>(a: Encoder<T1, T2>, b: Encoder<T2, T3>): Encoder<T1, T3> => ({\n\tencode: (content) => b.encode(a.encode(content)),\n\tdecode: (content) => a.decode(b.decode(content)),\n});\n"]}
@@ -0,0 +1,3 @@
1
+ export { Attributor, OpStreamAttributor, IAttributor } from "./attributor.mjs";
2
+ export { createRuntimeAttributor, enableOnNewFileKey, IProvideRuntimeAttributor, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.mjs";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"OAIO,EAAE,UAAU,EAAE,kBAAkB,EAAE,WAAW,EAAE;OAC/C,EACN,uBAAuB,EACvB,kBAAkB,EAClB,yBAAyB,EACzB,kBAAkB,EAClB,eAAe,GACf"}
package/lib/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ export { Attributor, OpStreamAttributor } from "./attributor.mjs";
2
+ export { createRuntimeAttributor, enableOnNewFileKey, IRuntimeAttributor, mixinAttributor, } from "./mixinAttributor.mjs";
3
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"OAIO,EAAE,UAAU,EAAE,kBAAkB,EAAe;OAC/C,EACN,uBAAuB,EACvB,kBAAkB,EAElB,kBAAkB,EAClB,eAAe,GACf","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\nexport { Attributor, OpStreamAttributor, IAttributor } from \"./attributor\";\nexport {\n\tcreateRuntimeAttributor,\n\tenableOnNewFileKey,\n\tIProvideRuntimeAttributor,\n\tIRuntimeAttributor,\n\tmixinAttributor,\n} from \"./mixinAttributor\";\n"]}
@@ -0,0 +1,7 @@
1
+ import { Jsonable } from "@fluidframework/datastore-definitions";
2
+ import { Encoder } from "./encoders.mjs";
3
+ /**
4
+ * @alpha
5
+ */
6
+ export declare function makeLZ4Encoder<T>(): Encoder<Jsonable<T>, string>;
7
+ //# sourceMappingURL=lz4Encoder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lz4Encoder.d.ts","sourceRoot":"","sources":["../src/lz4Encoder.ts"],"names":[],"mappings":"OAMO,EAAE,QAAQ,EAAE,MAAM,uCAAuC;OACzD,EAAE,OAAO,EAAE;AAElB;;GAEG;AACH,wBAAgB,cAAc,CAAC,CAAC,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,CAchE"}