@fluidframework/cell 2.0.0-dev.2.2.0.111723 → 2.0.0-dev.3.1.0.125672

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 (49) hide show
  1. package/.eslintrc.js +9 -7
  2. package/.mocharc.js +2 -2
  3. package/README.md +95 -1
  4. package/api-extractor.json +2 -2
  5. package/dist/cell.d.ts +47 -73
  6. package/dist/cell.d.ts.map +1 -1
  7. package/dist/cell.js +72 -75
  8. package/dist/cell.js.map +1 -1
  9. package/dist/cellFactory.d.ts +18 -1
  10. package/dist/cellFactory.d.ts.map +1 -1
  11. package/dist/cellFactory.js +18 -1
  12. package/dist/cellFactory.js.map +1 -1
  13. package/dist/index.d.ts +6 -1
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +5 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/interfaces.d.ts +116 -3
  18. package/dist/interfaces.d.ts.map +1 -1
  19. package/dist/interfaces.js.map +1 -1
  20. package/dist/packageVersion.d.ts +1 -1
  21. package/dist/packageVersion.js +1 -1
  22. package/dist/packageVersion.js.map +1 -1
  23. package/lib/cell.d.ts +47 -73
  24. package/lib/cell.d.ts.map +1 -1
  25. package/lib/cell.js +73 -76
  26. package/lib/cell.js.map +1 -1
  27. package/lib/cellFactory.d.ts +18 -1
  28. package/lib/cellFactory.d.ts.map +1 -1
  29. package/lib/cellFactory.js +18 -1
  30. package/lib/cellFactory.js.map +1 -1
  31. package/lib/index.d.ts +6 -1
  32. package/lib/index.d.ts.map +1 -1
  33. package/lib/index.js +5 -0
  34. package/lib/index.js.map +1 -1
  35. package/lib/interfaces.d.ts +116 -3
  36. package/lib/interfaces.d.ts.map +1 -1
  37. package/lib/interfaces.js.map +1 -1
  38. package/lib/packageVersion.d.ts +1 -1
  39. package/lib/packageVersion.js +1 -1
  40. package/lib/packageVersion.js.map +1 -1
  41. package/package.json +29 -20
  42. package/prettier.config.cjs +1 -1
  43. package/src/cell.ts +357 -317
  44. package/src/cellFactory.ts +52 -34
  45. package/src/index.ts +13 -1
  46. package/src/interfaces.ts +156 -32
  47. package/src/packageVersion.ts +1 -1
  48. package/tsconfig.esnext.json +6 -6
  49. package/tsconfig.json +9 -13
package/.eslintrc.js CHANGED
@@ -4,10 +4,12 @@
4
4
  */
5
5
 
6
6
  module.exports = {
7
- "extends": [
8
- require.resolve("@fluidframework/eslint-config-fluid"), "prettier"
9
- ],
10
- "parserOptions": {
11
- "project": ["./tsconfig.json", "./src/test/tsconfig.json"]
12
- },
13
- }
7
+ extends: [require.resolve("@fluidframework/eslint-config-fluid/strict"), "prettier"],
8
+ parserOptions: {
9
+ project: ["./tsconfig.json", "./src/test/tsconfig.json"],
10
+ },
11
+ rules: {
12
+ // TODO: consider re-enabling once we have addressed how this rule conflicts with our error codes.
13
+ "unicorn/numeric-separators-style": "off",
14
+ },
15
+ };
package/.mocharc.js CHANGED
@@ -3,9 +3,9 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- 'use strict';
6
+ "use strict";
7
7
 
8
- const getFluidTestMochaConfig = require('@fluidframework/mocha-test-setup/mocharc-common');
8
+ const getFluidTestMochaConfig = require("@fluidframework/mocha-test-setup/mocharc-common");
9
9
 
10
10
  const packageDir = __dirname;
11
11
  const config = getFluidTestMochaConfig(packageDir);
package/README.md CHANGED
@@ -1,3 +1,97 @@
1
1
  # @fluidframework/cell
2
2
 
3
- Documentation available at https://fluidframework.com/docs/apis/cell/.
3
+ The `SharedCell` Distributed Data Structure (DDS) stores a single, shared value that can be edited or deleted.
4
+
5
+ <!-- AUTO-GENERATED-CONTENT:START (README_INSTALLATION_SECTION:includeHeading=TRUE) -->
6
+
7
+ <!-- prettier-ignore-start -->
8
+
9
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
10
+
11
+ ## Installation
12
+
13
+ To get started, install the package by running the following command:
14
+
15
+ ```bash
16
+ npm i @fluidframework/cell
17
+ ```
18
+
19
+ <!-- prettier-ignore-end -->
20
+
21
+ <!-- AUTO-GENERATED-CONTENT:END -->
22
+
23
+ <!-- AUTO-GENERATED-CONTENT:START (README_API_DOCS_SECTION:includeHeading=TRUE) -->
24
+
25
+ <!-- prettier-ignore-start -->
26
+
27
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
28
+
29
+ ## API Documentation
30
+
31
+ API documentation for **@fluidframework/cell** is available at <https://fluidframework.com/docs/apis/cell>.
32
+
33
+ <!-- prettier-ignore-end -->
34
+
35
+ <!-- AUTO-GENERATED-CONTENT:END -->
36
+
37
+ <!-- AUTO-GENERATED-CONTENT:START (README_CONTRIBUTION_GUIDELINES_SECTION:includeHeading=TRUE) -->
38
+
39
+ <!-- prettier-ignore-start -->
40
+
41
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
42
+
43
+ ## Contribution Guidelines
44
+
45
+ There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
46
+
47
+ - Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
48
+ - [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
49
+ - Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
50
+ - [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
51
+
52
+ Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
53
+
54
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
55
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
56
+
57
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
58
+ Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
59
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
60
+
61
+ <!-- prettier-ignore-end -->
62
+
63
+ <!-- AUTO-GENERATED-CONTENT:END -->
64
+
65
+ <!-- AUTO-GENERATED-CONTENT:START (README_HELP_SECTION:includeHeading=TRUE) -->
66
+
67
+ <!-- prettier-ignore-start -->
68
+
69
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
70
+
71
+ ## Help
72
+
73
+ Not finding what you're looking for in this README?
74
+ Check out our [GitHub Wiki](https://github.com/microsoft/FluidFramework/wiki) or [fluidframework.com](https://fluidframework.com/docs/).
75
+
76
+ Still not finding what you're looking for? Please [file an issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
77
+ Thank you!
78
+
79
+ <!-- prettier-ignore-end -->
80
+
81
+ <!-- AUTO-GENERATED-CONTENT:END -->
82
+
83
+ <!-- AUTO-GENERATED-CONTENT:START (README_TRADEMARK_SECTION:includeHeading=TRUE) -->
84
+
85
+ <!-- prettier-ignore-start -->
86
+
87
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
88
+
89
+ ## Trademark
90
+
91
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
92
+ Use of these trademarks or logos must follow Microsoft's [Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks/usage/general).
93
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
94
+
95
+ <!-- prettier-ignore-end -->
96
+
97
+ <!-- AUTO-GENERATED-CONTENT:END -->
@@ -1,4 +1,4 @@
1
1
  {
2
- "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-common-report.json"
2
+ "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
+ "extends": "@fluidframework/build-common/api-extractor-common-report.json"
4
4
  }
package/dist/cell.d.ts CHANGED
@@ -6,67 +6,24 @@ import { ISequencedDocumentMessage } from "@fluidframework/protocol-definitions"
6
6
  import { IChannelAttributes, IFluidDataStoreRuntime, IChannelStorageService, IChannelFactory, Serializable } from "@fluidframework/datastore-definitions";
7
7
  import { ISummaryTreeWithStats } from "@fluidframework/runtime-definitions";
8
8
  import { IFluidSerializer, SharedObject } from "@fluidframework/shared-object-base";
9
- import { ISharedCell, ISharedCellEvents } from "./interfaces";
9
+ import { ISharedCell, ISharedCellEvents, AttributionKey, ICellOptions } from "./interfaces";
10
10
  /**
11
- * The SharedCell distributed data structure can be used to store a single serializable value.
12
- *
13
- * @remarks
14
- * ### Creation
15
- *
16
- * To create a `SharedCell`, call the static create method:
17
- *
18
- * ```typescript
19
- * const myCell = SharedCell.create(this.runtime, id);
20
- * ```
21
- *
22
- * ### Usage
23
- *
24
- * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:
25
- *
26
- * ```typescript
27
- * myCell.set(3);
28
- * console.log(myCell.get()); // 3
29
- * ```
30
- *
31
- * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).
32
- * In collaborative scenarios, the value is settled with a policy of _last write wins_.
33
- *
34
- * The `.delete()` method will delete the stored value from the cell:
35
- *
36
- * ```typescript
37
- * myCell.delete();
38
- * console.log(myCell.get()); // undefined
39
- * ```
40
- *
41
- * The `.empty()` method will check if the value is undefined.
42
- *
43
- * ```typescript
44
- * if (myCell.empty()) {
45
- * // myCell.get() will return undefined
46
- * } else {
47
- * // myCell.get() will return a non-undefined value
48
- * }
49
- * ```
50
- *
51
- * ### Eventing
52
- *
53
- * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should
54
- * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted
55
- * in response to a `set`, and `delete` will be emitted in response to a `delete`.
11
+ * {@inheritDoc ISharedCell}
56
12
  */
57
13
  export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<T>> implements ISharedCell<T> {
58
14
  /**
59
- * Create a new shared cell
15
+ * Create a new `SharedCell`.
60
16
  *
61
- * @param runtime - data store runtime the new shared map belongs to
62
- * @param id - optional name of the shared map
63
- * @returns newly create shared map (but not attached yet)
17
+ * @param runtime - The data store runtime to which the `SharedCell` belongs.
18
+ * @param id - Unique identifier for the `SharedCell`.
19
+ *
20
+ * @returns The newly create `SharedCell`. Note that it will not yet be attached.
64
21
  */
65
- static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCell<any>;
22
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCell;
66
23
  /**
67
- * Get a factory for SharedCell to register with the data store.
24
+ * Gets the factory for the `SharedCell` to register with the data store.
68
25
  *
69
- * @returns a factory that creates and load SharedCell
26
+ * @returns A factory that creates and loads `SharedCell`s.
70
27
  */
71
28
  static getFactory(): IChannelFactory;
72
29
  /**
@@ -84,14 +41,18 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
84
41
  */
85
42
  private messageIdObserved;
86
43
  private readonly pendingMessageIds;
44
+ private attribution;
45
+ private readonly options;
87
46
  /**
88
- * Constructs a new shared cell. If the object is non-local an id and service interfaces will
89
- * be provided
47
+ * Constructs a new `SharedCell`.
48
+ * If the object is non-local an id and service interfaces will be provided.
49
+ *
50
+ * @alpha
90
51
  *
91
- * @param runtime - data store runtime the shared map belongs to
92
- * @param id - optional name of the shared map
52
+ * @param runtime - The data store runtime to which the `SharedCell` belongs.
53
+ * @param id - Unique identifier for the `SharedCell`.
93
54
  */
94
- constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
55
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes, options?: ICellOptions);
95
56
  /**
96
57
  * {@inheritDoc ISharedCell.get}
97
58
  */
@@ -109,9 +70,18 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
109
70
  */
110
71
  empty(): boolean;
111
72
  /**
112
- * Create a summary for the cell
73
+ * {@inheritDoc ISharedCell.getAttribution}
74
+ * @alpha
75
+ */
76
+ getAttribution(): AttributionKey | undefined;
77
+ /**
78
+ * Set the attribution through the SequencedDocumentMessage
79
+ */
80
+ private setAttribution;
81
+ /**
82
+ * Creates a summary for the Cell.
113
83
  *
114
- * @returns the summary of the current state of the cell
84
+ * @returns The summary of the current state of the Cell.
115
85
  */
116
86
  protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
117
87
  /**
@@ -119,25 +89,26 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
119
89
  */
120
90
  protected loadCore(storage: IChannelStorageService): Promise<void>;
121
91
  /**
122
- * Initialize a local instance of cell
92
+ * Initialize a local instance of cell.
123
93
  */
124
94
  protected initializeLocalCore(): void;
125
95
  /**
126
- * Call back on disconnect
96
+ * Call back on disconnect.
127
97
  */
128
98
  protected onDisconnect(): void;
129
99
  /**
130
- * Apply inner op
100
+ * Apply inner op.
101
+ *
131
102
  * @param content - ICellOperation content
132
103
  */
133
104
  private applyInnerOp;
134
105
  /**
135
- * Process a cell operation
106
+ * Process a cell operation (op).
136
107
  *
137
- * @param message - the message to prepare
138
- * @param local - whether the message was sent by the local client
108
+ * @param message - The message to prepare.
109
+ * @param local - Whether or not the message was sent by the local client.
139
110
  * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
140
- * For messages from a remote client, this will be undefined.
111
+ * For messages from a remote client, this will be `undefined`.
141
112
  */
142
113
  protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
143
114
  private setCore;
@@ -146,20 +117,23 @@ export declare class SharedCell<T = any> extends SharedObject<ISharedCellEvents<
146
117
  private createLocalOpMetadata;
147
118
  /**
148
119
  * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
120
+ *
149
121
  * @internal
150
122
  */
151
123
  protected applyStashedOp(content: unknown): unknown;
152
124
  /**
153
- * Rollback a local op
154
- * @param content - The operation to rollback
125
+ * Rollback a local op.
126
+ *
127
+ * @param content - The operation to rollback.
155
128
  * @param localOpMetadata - The local metadata associated with the op.
156
129
  */
157
130
  protected rollback(content: any, localOpMetadata: unknown): void;
158
131
  /**
159
- * Submit a cell message to remote clients.
160
- * @param op - The cell message
161
- * @param previousValue - The value of the cell before this op
162
- */
132
+ * Submit a cell message to remote clients.
133
+ *
134
+ * @param op - The cell message.
135
+ * @param previousValue - The value of the cell before this op.
136
+ */
163
137
  private submitCellMessage;
164
138
  }
165
139
  //# sourceMappingURL=cell.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cell.d.ts","sourceRoot":"","sources":["../src/cell.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,yBAAyB,EAAe,MAAM,sCAAsC,CAAC;AAC9F,OAAO,EACH,kBAAkB,EAClB,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EACf,YAAY,EACf,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qCAAqC,CAAC;AAE5E,OAAO,EAA2B,gBAAgB,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAE7G,OAAO,EACH,WAAW,EACX,iBAAiB,EAEpB,MAAM,cAAc,CAAC;AAuBtB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,UAAU,CAAC,CAAC,GAAG,GAAG,CAAE,SAAQ,YAAY,CAAC,iBAAiB,CAAC,CAAC,CAAC,CACtE,YAAW,WAAW,CAAC,CAAC,CAAC;IACzB;;;;;;OAMG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIjE;;;;OAIG;WACW,UAAU,IAAI,eA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OAEG;IACI,MAAM,IAAI,IAAI;IAerB;;OAEG;IACI,KAAK,IAAI,OAAO;IAIvB;;;OAGG;IACI,cAAc,IAAI,cAAc,GAAG,SAAS;IAInD;;OAEG;IACH,OAAO,CAAC,cAAc;IAMtB;;;;OAIG;IACH,SAAS,CAAC,aAAa,CAAC,UAAU,EAAE,gBAAgB,GAAG,qBAAqB;IAQ5E;;OAEG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAOxE;;OAEG;IACH,SAAS,CAAC,mBAAmB,IAAI,IAAI;IAIrC;;OAEG;IACH,SAAS,CAAC,YAAY,IAAI,IAAI;IAE9B;;;;OAIG;IACH,OAAO,CAAC,YAAY;IAapB;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CACpB,OAAO,EAAE,yBAAyB,EAClC,KAAK,EAAE,OAAO,EACd,eAAe,EAAE,OAAO,GACtB,IAAI;IAgCP,OAAO,CAAC,OAAO;IAOf,OAAO,CAAC,UAAU;IAOlB,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,qBAAqB;IAa7B;;;;OAIG;IACH,SAAS,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO;IAMnD;;;;;OAKG;IAGH,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,OAAO,GAAG,IAAI;IAmBhE;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;CAIzB"}
package/dist/cell.js CHANGED
@@ -7,66 +7,29 @@ Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.SharedCell = void 0;
8
8
  const common_utils_1 = require("@fluidframework/common-utils");
9
9
  const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
10
+ const telemetry_utils_1 = require("@fluidframework/telemetry-utils");
10
11
  const driver_utils_1 = require("@fluidframework/driver-utils");
11
12
  const shared_object_base_1 = require("@fluidframework/shared-object-base");
12
13
  const cellFactory_1 = require("./cellFactory");
13
14
  const snapshotFileName = "header";
14
15
  /**
15
- * The SharedCell distributed data structure can be used to store a single serializable value.
16
- *
17
- * @remarks
18
- * ### Creation
19
- *
20
- * To create a `SharedCell`, call the static create method:
21
- *
22
- * ```typescript
23
- * const myCell = SharedCell.create(this.runtime, id);
24
- * ```
25
- *
26
- * ### Usage
27
- *
28
- * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:
29
- *
30
- * ```typescript
31
- * myCell.set(3);
32
- * console.log(myCell.get()); // 3
33
- * ```
34
- *
35
- * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).
36
- * In collaborative scenarios, the value is settled with a policy of _last write wins_.
37
- *
38
- * The `.delete()` method will delete the stored value from the cell:
39
- *
40
- * ```typescript
41
- * myCell.delete();
42
- * console.log(myCell.get()); // undefined
43
- * ```
44
- *
45
- * The `.empty()` method will check if the value is undefined.
46
- *
47
- * ```typescript
48
- * if (myCell.empty()) {
49
- * // myCell.get() will return undefined
50
- * } else {
51
- * // myCell.get() will return a non-undefined value
52
- * }
53
- * ```
54
- *
55
- * ### Eventing
56
- *
57
- * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should
58
- * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted
59
- * in response to a `set`, and `delete` will be emitted in response to a `delete`.
16
+ * {@inheritDoc ISharedCell}
60
17
  */
18
+ // TODO: use `unknown` instead (breaking change).
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
20
  class SharedCell extends shared_object_base_1.SharedObject {
62
21
  /**
63
- * Constructs a new shared cell. If the object is non-local an id and service interfaces will
64
- * be provided
22
+ * Constructs a new `SharedCell`.
23
+ * If the object is non-local an id and service interfaces will be provided.
65
24
  *
66
- * @param runtime - data store runtime the shared map belongs to
67
- * @param id - optional name of the shared map
25
+ * @alpha
26
+ *
27
+ * @param runtime - The data store runtime to which the `SharedCell` belongs.
28
+ * @param id - Unique identifier for the `SharedCell`.
68
29
  */
69
- constructor(id, runtime, attributes) {
30
+ // eslint-disable-next-line @typescript-eslint/explicit-member-accessibility
31
+ constructor(id, runtime, attributes, options) {
32
+ var _a, _b;
70
33
  super(id, runtime, attributes, "fluid_cell_");
71
34
  /**
72
35
  * This is used to assign a unique id to outgoing messages. It is used to track messages until
@@ -79,21 +42,27 @@ class SharedCell extends shared_object_base_1.SharedObject {
79
42
  */
80
43
  this.messageIdObserved = -1;
81
44
  this.pendingMessageIds = [];
45
+ (_a = this.options) !== null && _a !== void 0 ? _a : (this.options = options);
46
+ const configSetAttribution = (0, telemetry_utils_1.loggerToMonitoringContext)(this.logger).config.getBoolean("Fluid.Attribution.EnableOnNewFile");
47
+ if (configSetAttribution !== undefined) {
48
+ ((_b = this.options) !== null && _b !== void 0 ? _b : (this.options = {})).attribution = { track: configSetAttribution };
49
+ }
82
50
  }
83
51
  /**
84
- * Create a new shared cell
52
+ * Create a new `SharedCell`.
85
53
  *
86
- * @param runtime - data store runtime the new shared map belongs to
87
- * @param id - optional name of the shared map
88
- * @returns newly create shared map (but not attached yet)
54
+ * @param runtime - The data store runtime to which the `SharedCell` belongs.
55
+ * @param id - Unique identifier for the `SharedCell`.
56
+ *
57
+ * @returns The newly create `SharedCell`. Note that it will not yet be attached.
89
58
  */
90
59
  static create(runtime, id) {
91
60
  return runtime.createChannel(id, cellFactory_1.CellFactory.Type);
92
61
  }
93
62
  /**
94
- * Get a factory for SharedCell to register with the data store.
63
+ * Gets the factory for the `SharedCell` to register with the data store.
95
64
  *
96
- * @returns a factory that creates and load SharedCell
65
+ * @returns A factory that creates and loads `SharedCell`s.
97
66
  */
98
67
  static getFactory() {
99
68
  return new cellFactory_1.CellFactory();
@@ -146,12 +115,28 @@ class SharedCell extends shared_object_base_1.SharedObject {
146
115
  return this.data === undefined;
147
116
  }
148
117
  /**
149
- * Create a summary for the cell
118
+ * {@inheritDoc ISharedCell.getAttribution}
119
+ * @alpha
120
+ */
121
+ getAttribution() {
122
+ return this.attribution;
123
+ }
124
+ /**
125
+ * Set the attribution through the SequencedDocumentMessage
126
+ */
127
+ setAttribution(message) {
128
+ var _a, _b, _c;
129
+ if ((_c = (_b = (_a = this.options) === null || _a === void 0 ? void 0 : _a.attribution) === null || _b === void 0 ? void 0 : _b.track) !== null && _c !== void 0 ? _c : false) {
130
+ this.attribution = { type: "op", seq: message.sequenceNumber };
131
+ }
132
+ }
133
+ /**
134
+ * Creates a summary for the Cell.
150
135
  *
151
- * @returns the summary of the current state of the cell
136
+ * @returns The summary of the current state of the Cell.
152
137
  */
153
138
  summarizeCore(serializer) {
154
- const content = { value: this.data };
139
+ const content = { value: this.data, attribution: this.attribution };
155
140
  return (0, shared_object_base_1.createSingleBlobSummary)(snapshotFileName, serializer.stringify(content, this.handle));
156
141
  }
157
142
  /**
@@ -160,19 +145,21 @@ class SharedCell extends shared_object_base_1.SharedObject {
160
145
  async loadCore(storage) {
161
146
  const content = await (0, driver_utils_1.readAndParse)(storage, snapshotFileName);
162
147
  this.data = this.decode(content);
148
+ this.attribution = content.attribution;
163
149
  }
164
150
  /**
165
- * Initialize a local instance of cell
151
+ * Initialize a local instance of cell.
166
152
  */
167
153
  initializeLocalCore() {
168
154
  this.data = undefined;
169
155
  }
170
156
  /**
171
- * Call back on disconnect
157
+ * Call back on disconnect.
172
158
  */
173
159
  onDisconnect() { }
174
160
  /**
175
- * Apply inner op
161
+ * Apply inner op.
162
+ *
176
163
  * @param content - ICellOperation content
177
164
  */
178
165
  applyInnerOp(content) {
@@ -186,12 +173,12 @@ class SharedCell extends shared_object_base_1.SharedObject {
186
173
  }
187
174
  }
188
175
  /**
189
- * Process a cell operation
176
+ * Process a cell operation (op).
190
177
  *
191
- * @param message - the message to prepare
192
- * @param local - whether the message was sent by the local client
178
+ * @param message - The message to prepare.
179
+ * @param local - Whether or not the message was sent by the local client.
193
180
  * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
194
- * For messages from a remote client, this will be undefined.
181
+ * For messages from a remote client, this will be `undefined`.
195
182
  */
196
183
  processCore(message, local, localOpMetadata) {
197
184
  const cellOpMetadata = localOpMetadata;
@@ -201,15 +188,19 @@ class SharedCell extends shared_object_base_1.SharedObject {
201
188
  const messageIdReceived = cellOpMetadata.pendingMessageId;
202
189
  (0, common_utils_1.assert)(messageIdReceived !== undefined && messageIdReceived <= this.messageId, 0x00c /* "messageId is incorrect from from the local client's ACK" */);
203
190
  (0, common_utils_1.assert)(this.pendingMessageIds !== undefined &&
204
- this.pendingMessageIds[0] === cellOpMetadata.pendingMessageId, "Unexpected pending message received");
191
+ this.pendingMessageIds[0] === cellOpMetadata.pendingMessageId, 0x471 /* Unexpected pending message received */);
205
192
  this.pendingMessageIds.shift();
206
193
  // We got an ACK. Update messageIdObserved.
207
194
  this.messageIdObserved = cellOpMetadata.pendingMessageId;
195
+ // update the attributor
196
+ this.setAttribution(message);
208
197
  }
209
198
  return;
210
199
  }
211
200
  if (message.type === protocol_definitions_1.MessageType.Operation && !local) {
212
201
  const op = message.contents;
202
+ // update the attributor
203
+ this.setAttribution(message);
213
204
  this.applyInnerOp(op);
214
205
  }
215
206
  }
@@ -227,19 +218,20 @@ class SharedCell extends shared_object_base_1.SharedObject {
227
218
  }
228
219
  decode(cellValue) {
229
220
  const value = cellValue.value;
230
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
231
221
  return this.serializer.decode(value);
232
222
  }
233
223
  createLocalOpMetadata(op, previousValue) {
234
224
  const pendingMessageId = ++this.messageId;
235
225
  this.pendingMessageIds.push(pendingMessageId);
236
226
  const localMetadata = {
237
- pendingMessageId, previousValue,
227
+ pendingMessageId,
228
+ previousValue,
238
229
  };
239
230
  return localMetadata;
240
231
  }
241
232
  /**
242
233
  * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
234
+ *
243
235
  * @internal
244
236
  */
245
237
  applyStashedOp(content) {
@@ -248,12 +240,16 @@ class SharedCell extends shared_object_base_1.SharedObject {
248
240
  return this.createLocalOpMetadata(cellContent, previousValue);
249
241
  }
250
242
  /**
251
- * Rollback a local op
252
- * @param content - The operation to rollback
243
+ * Rollback a local op.
244
+ *
245
+ * @param content - The operation to rollback.
253
246
  * @param localOpMetadata - The local metadata associated with the op.
254
247
  */
248
+ // TODO: use `unknown` instead (breaking change).
249
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/explicit-module-boundary-types
255
250
  rollback(content, localOpMetadata) {
256
251
  const cellOpMetadata = localOpMetadata;
252
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
257
253
  if (content.type === "setCell" || content.type === "deleteCell") {
258
254
  if (cellOpMetadata.previousValue === undefined) {
259
255
  this.deleteCore();
@@ -271,10 +267,11 @@ class SharedCell extends shared_object_base_1.SharedObject {
271
267
  }
272
268
  }
273
269
  /**
274
- * Submit a cell message to remote clients.
275
- * @param op - The cell message
276
- * @param previousValue - The value of the cell before this op
277
- */
270
+ * Submit a cell message to remote clients.
271
+ *
272
+ * @param op - The cell message.
273
+ * @param previousValue - The value of the cell before this op.
274
+ */
278
275
  submitCellMessage(op, previousValue) {
279
276
  const localMetadata = this.createLocalOpMetadata(op, previousValue);
280
277
  this.submitLocalMessage(op, localMetadata);