@fluidframework/cell 2.0.0-dev.2.3.0.115467 → 2.0.0-dev.4.1.0.148229

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 +91 -1
  4. package/api-extractor.json +2 -2
  5. package/dist/cell.d.ts +45 -72
  6. package/dist/cell.d.ts.map +1 -1
  7. package/dist/cell.js +72 -73
  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 +95 -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 +45 -72
  24. package/lib/cell.d.ts.map +1 -1
  25. package/lib/cell.js +73 -74
  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 +95 -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 +53 -53
  42. package/prettier.config.cjs +1 -1
  43. package/src/cell.ts +349 -320
  44. package/src/cellFactory.ts +52 -34
  45. package/src/index.ts +12 -1
  46. package/src/interfaces.ts +133 -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,16 @@
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
+ ICellOptions,
17
+ ICellAttributionOptions,
18
+ } from "./interfaces";
package/src/interfaces.ts CHANGED
@@ -5,44 +5,145 @@
5
5
 
6
6
  import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
7
7
  import { Serializable } from "@fluidframework/datastore-definitions";
8
+ import { AttributionKey } from "@fluidframework/runtime-definitions";
8
9
 
10
+ /**
11
+ * Events emitted by {@link ISharedCell}.
12
+ */
9
13
  export interface ISharedCellEvents<T> extends ISharedObjectEvents {
10
- (event: "valueChanged", listener: (value: Serializable<T>) => void);
11
- (event: "delete", listener: () => void);
14
+ /**
15
+ * Emitted when the value has changed.
16
+ *
17
+ * @remarks Event paramters:
18
+ *
19
+ * - `value`: The new value of the cell.
20
+ */
21
+ (event: "valueChanged", listener: (value: Serializable<T>) => void);
22
+
23
+ /**
24
+ * Emitted when the value has been deleted.
25
+ */
26
+ (event: "delete", listener: () => void);
12
27
  }
13
28
 
14
29
  /**
15
- * Shared cell interface
30
+ * A Distributed Data Structure (DDS), which stores a single shared value that can be edited or deleted.
31
+ *
32
+ * @typeParam T - The type of cell data. Must be serializable.
33
+ *
34
+ * @example Creation:
35
+ *
36
+ * To create a `SharedCell`, call the static create method:
37
+ *
38
+ * ```typescript
39
+ * const myCell = SharedCell.create(this.runtime, id);
40
+ * ```
41
+ *
42
+ * @example Usage:
43
+ *
44
+ * The value stored in the cell can be set with the `.set()` method and retrieved with the `.get()` method:
45
+ *
46
+ * ```typescript
47
+ * myCell.set(3);
48
+ * console.log(myCell.get()); // 3
49
+ * ```
50
+ *
51
+ * The value must only be plain JS objects or `SharedObject` handles (e.g. to another DDS or Fluid object).
52
+ * In collaborative scenarios, the value is settled with a policy of _last write wins_.
53
+ *
54
+ * The `.delete()` method will delete the stored value from the cell:
55
+ *
56
+ * ```typescript
57
+ * myCell.delete();
58
+ * console.log(myCell.get()); // undefined
59
+ * ```
60
+ *
61
+ * The `.empty()` method will check if the value is undefined.
62
+ *
63
+ * ```typescript
64
+ * if (myCell.empty()) {
65
+ * // myCell.get() will return undefined
66
+ * } else {
67
+ * // myCell.get() will return a non-undefined value
68
+ * }
69
+ * ```
70
+ *
71
+ * @example Eventing:
72
+ *
73
+ * `SharedCell` is an `EventEmitter`, and will emit events when other clients make modifications. You should
74
+ * register for these events and respond appropriately as the data is modified. `valueChanged` will be emitted
75
+ * in response to a `set`, and `delete` will be emitted in response to a `delete`.
16
76
  */
17
-
77
+ // TODO: use `unknown` instead (breaking change).
78
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
18
79
  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;
80
+ /**
81
+ * Retrieves the cell value.
82
+ *
83
+ * @returns - the value of the cell
84
+ */
85
+ get(): Serializable<T> | undefined;
86
+
87
+ /**
88
+ * Sets the cell value.
89
+ *
90
+ * @param value - a JSON-able or SharedObject value to set the cell to
91
+ */
92
+ set(value: Serializable<T>): void;
93
+
94
+ /**
95
+ * Checks whether cell is empty or not.
96
+ *
97
+ * @returns - `true` if the value of cell is `undefined`, `false` otherwise
98
+ */
99
+ empty(): boolean;
100
+
101
+ /**
102
+ * Delete the value from the cell.
103
+ */
104
+ delete(): void;
105
+
106
+ /**
107
+ * @alpha
108
+ * @returns the AttributionKey associated with the cell's most recent change.
109
+ */
110
+ getAttribution(): AttributionKey | undefined;
111
+ }
112
+
113
+ /**
114
+ * Describes a local Cell operation (op).
115
+ */
116
+ // TODO: use `unknown` instead.
117
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
118
+ export interface ICellLocalOpMetadata<T = any> {
119
+ /**
120
+ * Unique identifier for this local operation (op).
121
+ */
122
+ pendingMessageId: number;
123
+
124
+ /**
125
+ * The value of the {@link ISharedCell} prior to this operation (op).
126
+ */
127
+ previousValue?: Serializable<T>;
128
+ }
129
+
130
+ /**
131
+ * Options related to attribution
132
+ *
133
+ * @alpha
134
+ */
135
+ export interface ICellOptions {
136
+ attribution?: ICellAttributionOptions;
44
137
  }
45
- export interface ICellLocalOpMetadata {
46
- pendingMessageId: number;
47
- previousValue?: any;
138
+
139
+ /**
140
+ * This enables the cell to store the attribution information which can be accessed with the runtime
141
+ * (i.e. who creeated the content and when it was created)
142
+ *
143
+ * default: false
144
+ *
145
+ * @alpha
146
+ */
147
+ export interface ICellAttributionOptions {
148
+ track?: boolean;
48
149
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/cell";
9
- export const pkgVersion = "2.0.0-dev.2.3.0.115467";
9
+ export const pkgVersion = "2.0.0-dev.4.1.0.148229";
@@ -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
+ }