@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.
- package/.eslintrc.js +9 -7
- package/.mocharc.js +2 -2
- package/README.md +91 -1
- package/api-extractor.json +2 -2
- package/dist/cell.d.ts +45 -72
- package/dist/cell.d.ts.map +1 -1
- package/dist/cell.js +72 -73
- package/dist/cell.js.map +1 -1
- package/dist/cellFactory.d.ts +18 -1
- package/dist/cellFactory.d.ts.map +1 -1
- package/dist/cellFactory.js +18 -1
- package/dist/cellFactory.js.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +95 -3
- package/dist/interfaces.d.ts.map +1 -1
- package/dist/interfaces.js.map +1 -1
- package/dist/packageVersion.d.ts +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/cell.d.ts +45 -72
- package/lib/cell.d.ts.map +1 -1
- package/lib/cell.js +73 -74
- package/lib/cell.js.map +1 -1
- package/lib/cellFactory.d.ts +18 -1
- package/lib/cellFactory.d.ts.map +1 -1
- package/lib/cellFactory.js +18 -1
- package/lib/cellFactory.js.map +1 -1
- package/lib/index.d.ts +6 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +5 -0
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +95 -3
- package/lib/interfaces.d.ts.map +1 -1
- package/lib/interfaces.js.map +1 -1
- package/lib/packageVersion.d.ts +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +53 -53
- package/prettier.config.cjs +1 -1
- package/src/cell.ts +349 -320
- package/src/cellFactory.ts +52 -34
- package/src/index.ts +12 -1
- package/src/interfaces.ts +133 -32
- package/src/packageVersion.ts +1 -1
- package/tsconfig.esnext.json +6 -6
- package/tsconfig.json +9 -13
package/src/cellFactory.ts
CHANGED
|
@@ -4,51 +4,69 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
*
|
|
17
|
+
* {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link ISharedCell}.
|
|
18
|
+
*
|
|
19
|
+
* @sealed
|
|
18
20
|
*/
|
|
19
21
|
export class CellFactory implements IChannelFactory {
|
|
20
|
-
|
|
22
|
+
/**
|
|
23
|
+
* {@inheritDoc CellFactory."type"}
|
|
24
|
+
*/
|
|
25
|
+
public static readonly Type = "https://graph.microsoft.com/types/cell";
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
38
|
+
*/
|
|
39
|
+
public get type(): string {
|
|
40
|
+
return CellFactory.Type;
|
|
41
|
+
}
|
|
31
42
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
43
|
+
/**
|
|
44
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
45
|
+
*/
|
|
46
|
+
public get attributes(): IChannelAttributes {
|
|
47
|
+
return CellFactory.Attributes;
|
|
48
|
+
}
|
|
35
49
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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 {
|
|
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
|
-
|
|
11
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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
|
}
|
package/src/packageVersion.ts
CHANGED
package/tsconfig.esnext.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
}
|