@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
@@ -4,51 +4,69 @@
4
4
  */
5
5
 
6
6
  import {
7
- IChannelAttributes,
8
- IFluidDataStoreRuntime,
9
- IChannelServices,
10
- IChannelFactory,
7
+ IChannelAttributes,
8
+ IFluidDataStoreRuntime,
9
+ IChannelServices,
10
+ IChannelFactory,
11
11
  } from "@fluidframework/datastore-definitions";
12
12
  import { SharedCell } from "./cell";
13
13
  import { ISharedCell } from "./interfaces";
14
14
  import { pkgVersion } from "./packageVersion";
15
15
 
16
16
  /**
17
- * The factory that defines the map
17
+ * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link ISharedCell}.
18
+ *
19
+ * @sealed
18
20
  */
19
21
  export class CellFactory implements IChannelFactory {
20
- public static readonly Type = "https://graph.microsoft.com/types/cell";
22
+ /**
23
+ * {@inheritDoc CellFactory."type"}
24
+ */
25
+ public static readonly Type = "https://graph.microsoft.com/types/cell";
21
26
 
22
- public static readonly Attributes: IChannelAttributes = {
23
- type: CellFactory.Type,
24
- snapshotFormatVersion: "0.1",
25
- packageVersion: pkgVersion,
26
- };
27
+ /**
28
+ * {@inheritDoc CellFactory.attributes}
29
+ */
30
+ public static readonly Attributes: IChannelAttributes = {
31
+ type: CellFactory.Type,
32
+ snapshotFormatVersion: "0.1",
33
+ packageVersion: pkgVersion,
34
+ };
27
35
 
28
- public get type() {
29
- return CellFactory.Type;
30
- }
36
+ /**
37
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
38
+ */
39
+ public get type(): string {
40
+ return CellFactory.Type;
41
+ }
31
42
 
32
- public get attributes() {
33
- return CellFactory.Attributes;
34
- }
43
+ /**
44
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
45
+ */
46
+ public get attributes(): IChannelAttributes {
47
+ return CellFactory.Attributes;
48
+ }
35
49
 
36
- /**
37
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
38
- */
39
- public async load(
40
- runtime: IFluidDataStoreRuntime,
41
- id: string,
42
- services: IChannelServices,
43
- attributes: IChannelAttributes): Promise<ISharedCell> {
44
- const cell = new SharedCell(id, runtime, attributes);
45
- await cell.load(services);
46
- return cell;
47
- }
50
+ /**
51
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
52
+ */
53
+ public async load(
54
+ runtime: IFluidDataStoreRuntime,
55
+ id: string,
56
+ services: IChannelServices,
57
+ attributes: IChannelAttributes,
58
+ ): Promise<ISharedCell> {
59
+ const cell = new SharedCell(id, runtime, attributes);
60
+ await cell.load(services);
61
+ return cell;
62
+ }
48
63
 
49
- public create(document: IFluidDataStoreRuntime, id: string): ISharedCell {
50
- const cell = new SharedCell(id, document, this.attributes);
51
- cell.initializeLocal();
52
- return cell;
53
- }
64
+ /**
65
+ * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
66
+ */
67
+ public create(document: IFluidDataStoreRuntime, id: string): ISharedCell {
68
+ const cell = new SharedCell(id, document, this.attributes);
69
+ cell.initializeLocal();
70
+ return cell;
71
+ }
54
72
  }
package/src/index.ts CHANGED
@@ -3,5 +3,17 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ /**
7
+ * The `SharedCell` Distributed Data Structure (DDS) stores a single, shared value that can be edited or deleted.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+
6
12
  export { SharedCell } from "./cell";
7
- export { ISharedCell, ISharedCellEvents } from "./interfaces";
13
+ export {
14
+ ISharedCell,
15
+ ISharedCellEvents,
16
+ AttributionKey,
17
+ ICellOptions,
18
+ ICellAttributionOptions,
19
+ } from "./interfaces";
package/src/interfaces.ts CHANGED
@@ -6,43 +6,167 @@
6
6
  import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
7
7
  import { Serializable } from "@fluidframework/datastore-definitions";
8
8
 
9
+ /**
10
+ * Events emitted by {@link ISharedCell}.
11
+ */
9
12
  export interface ISharedCellEvents<T> extends ISharedObjectEvents {
10
- (event: "valueChanged", listener: (value: Serializable<T>) => void);
11
- (event: "delete", listener: () => void);
13
+ /**
14
+ * Emitted when the value has changed.
15
+ *
16
+ * @remarks Event paramters:
17
+ *
18
+ * - `value`: The new value of the cell.
19
+ */
20
+ (event: "valueChanged", listener: (value: Serializable<T>) => void);
21
+
22
+ /**
23
+ * Emitted when the value has been deleted.
24
+ */
25
+ (event: "delete", listener: () => void);
12
26
  }
13
27
 
14
28
  /**
15
- * Shared cell interface
29
+ * A Distributed Data Structure (DDS), which stores a single shared value that can be edited or deleted.
30
+ *
31
+ * @typeParam T - The type of cell data. Must be serializable.
32
+ *
33
+ * @example Creation:
34
+ *
35
+ * To create a `SharedCell`, call the static create method:
36
+ *
37
+ * ```typescript
38
+ * const myCell = SharedCell.create(this.runtime, id);
39
+ * ```
40
+ *
41
+ * @example Usage:
42
+ *
43
+ * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:
44
+ *
45
+ * ```typescript
46
+ * myCell.set(3);
47
+ * console.log(myCell.get()); // 3
48
+ * ```
49
+ *
50
+ * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).
51
+ * In collaborative scenarios, the value is settled with a policy of _last write wins_.
52
+ *
53
+ * The `.delete()` method will delete the stored value from the cell:
54
+ *
55
+ * ```typescript
56
+ * myCell.delete();
57
+ * console.log(myCell.get()); // undefined
58
+ * ```
59
+ *
60
+ * The `.empty()` method will check if the value is undefined.
61
+ *
62
+ * ```typescript
63
+ * if (myCell.empty()) {
64
+ * // myCell.get() will return undefined
65
+ * } else {
66
+ * // myCell.get() will return a non-undefined value
67
+ * }
68
+ * ```
69
+ *
70
+ * @example Eventing:
71
+ *
72
+ * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should
73
+ * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted
74
+ * in response to a `set`, and `delete` will be emitted in response to a `delete`.
16
75
  */
17
-
76
+ // TODO: use `unknown` instead (breaking change).
77
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
78
  export interface ISharedCell<T = any> extends ISharedObject<ISharedCellEvents<T>> {
19
- /**
20
- * Retrieves the cell value.
21
- *
22
- * @returns - the value of the cell
23
- */
24
- get(): Serializable<T> | undefined;
25
-
26
- /**
27
- * Sets the cell value.
28
- *
29
- * @param value - a JSON-able or SharedObject value to set the cell to
30
- */
31
- set(value: Serializable<T>): void;
32
-
33
- /**
34
- * Checks whether cell is empty or not.
35
- *
36
- * @returns - `true` if the value of cell is `undefined`, `false` otherwise
37
- */
38
- empty(): boolean;
39
-
40
- /**
41
- * Delete the value from the cell.
42
- */
43
- delete(): void;
79
+ /**
80
+ * Retrieves the cell value.
81
+ *
82
+ * @returns - the value of the cell
83
+ */
84
+ get(): Serializable<T> | undefined;
85
+
86
+ /**
87
+ * Sets the cell value.
88
+ *
89
+ * @param value - a JSON-able or SharedObject value to set the cell to
90
+ */
91
+ set(value: Serializable<T>): void;
92
+
93
+ /**
94
+ * Checks whether cell is empty or not.
95
+ *
96
+ * @returns - `true` if the value of cell is `undefined`, `false` otherwise
97
+ */
98
+ empty(): boolean;
99
+
100
+ /**
101
+ * Delete the value from the cell.
102
+ */
103
+ delete(): void;
104
+
105
+ /**
106
+ * @alpha
107
+ * @returns the AttributionKey associated with the cell's most recent change.
108
+ */
109
+ getAttribution(): AttributionKey | undefined;
110
+ }
111
+
112
+ /**
113
+ * Describes a local Cell operation (op).
114
+ */
115
+ // TODO: use `unknown` instead.
116
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
117
+ export interface ICellLocalOpMetadata<T = any> {
118
+ /**
119
+ * Unique identifier for this local operation (op).
120
+ */
121
+ pendingMessageId: number;
122
+
123
+ /**
124
+ * The value of the {@link ISharedCell} prior to this operation (op).
125
+ */
126
+ previousValue?: Serializable<T>;
44
127
  }
45
- export interface ICellLocalOpMetadata {
46
- pendingMessageId: number;
47
- previousValue?: any;
128
+
129
+ /**
130
+ * Options related to attribution
131
+ *
132
+ * @alpha
133
+ */
134
+ export interface ICellOptions {
135
+ attribution?: ICellAttributionOptions;
136
+ }
137
+
138
+ /**
139
+ * This enables the cell to store the attribution information which can be accessed with the runtime
140
+ * (i.e. who creeated the content and when it was created)
141
+ *
142
+ * default: false
143
+ *
144
+ * @alpha
145
+ */
146
+ export interface ICellAttributionOptions {
147
+ track?: boolean;
148
+ }
149
+
150
+ /**
151
+ * Can be indexed into the ContainerRuntime in order to retrieve attribution info.
152
+ *
153
+ * @alpha
154
+ */
155
+ export interface AttributionKey {
156
+ /**
157
+ * The type of attribution this key corresponds to.
158
+ *
159
+ * Keys currently all represent op-based attribution, so have the form `{ type: "op", key: sequenceNumber }`.
160
+ * Thus, they can be used with an `OpStreamAttributor` to recover timestamp/user information.
161
+ *
162
+ * @remarks - If we want to support different types of attribution, a reasonable extensibility point is to make
163
+ * AttributionKey a discriminated union on the 'type' field. This would empower
164
+ * consumers with the ability to implement different attribution policies.
165
+ */
166
+ type: "op";
167
+
168
+ /**
169
+ * The sequenceNumber of the op this attribution key is for.
170
+ */
171
+ seq: number;
48
172
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/cell";
9
- export const pkgVersion = "2.0.0-dev.2.2.0.111723";
9
+ export const pkgVersion = "2.0.0-dev.3.1.0.125672";
@@ -1,7 +1,7 @@
1
1
  {
2
- "extends": "./tsconfig.json",
3
- "compilerOptions": {
4
- "outDir": "./lib",
5
- "module": "esnext"
6
- },
7
- }
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "outDir": "./lib",
5
+ "module": "esnext",
6
+ },
7
+ }
package/tsconfig.json CHANGED
@@ -1,14 +1,10 @@
1
1
  {
2
- "extends": "@fluidframework/build-common/ts-common-config.json",
3
- "exclude": [
4
- "src/test/**/*"
5
- ],
6
- "compilerOptions": {
7
- "rootDir": "./src",
8
- "outDir": "./dist",
9
- "composite": true
10
- },
11
- "include": [
12
- "src/**/*"
13
- ]
14
- }
2
+ "extends": "@fluidframework/build-common/ts-common-config.json",
3
+ "exclude": ["src/test/**/*"],
4
+ "compilerOptions": {
5
+ "rootDir": "./src",
6
+ "outDir": "./dist",
7
+ "composite": true,
8
+ },
9
+ "include": ["src/**/*"],
10
+ }