@fluidframework/counter 1.2.7 → 2.0.0-dev.1.3.0.96595
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/.mocharc.js +12 -0
- package/README.md +159 -1
- package/api-extractor.json +1 -1
- package/dist/counter.d.ts +33 -18
- package/dist/counter.d.ts.map +1 -1
- package/dist/counter.js +34 -19
- package/dist/counter.js.map +1 -1
- package/dist/counterFactory.d.ts +18 -1
- package/dist/counterFactory.d.ts.map +1 -1
- package/dist/counterFactory.js +18 -1
- package/dist/counterFactory.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +9 -4
- 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.d.ts.map +1 -1
- package/dist/packageVersion.js +1 -1
- package/dist/packageVersion.js.map +1 -1
- package/lib/counter.d.ts +33 -18
- package/lib/counter.d.ts.map +1 -1
- package/lib/counter.js +34 -19
- package/lib/counter.js.map +1 -1
- package/lib/counterFactory.d.ts +18 -1
- package/lib/counterFactory.d.ts.map +1 -1
- package/lib/counterFactory.js +18 -1
- package/lib/counterFactory.js.map +1 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +2 -2
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +9 -4
- 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.d.ts.map +1 -1
- package/lib/packageVersion.js +1 -1
- package/lib/packageVersion.js.map +1 -1
- package/package.json +16 -16
- package/src/counter.ts +45 -28
- package/src/counterFactory.ts +20 -3
- package/src/index.ts +2 -2
- package/src/interfaces.ts +9 -4
- package/src/packageVersion.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/counter",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "2.0.0-dev.1.3.0.96595",
|
|
4
4
|
"description": "Counter DDS",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": {
|
|
@@ -58,27 +58,27 @@
|
|
|
58
58
|
"temp-directory": "nyc/.nyc_output"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@fluidframework/common-utils": "^0.
|
|
62
|
-
"@fluidframework/core-interfaces": "
|
|
63
|
-
"@fluidframework/datastore-definitions": "
|
|
64
|
-
"@fluidframework/driver-utils": "
|
|
65
|
-
"@fluidframework/protocol-definitions": "^0.
|
|
66
|
-
"@fluidframework/runtime-definitions": "
|
|
67
|
-
"@fluidframework/shared-object-base": "
|
|
61
|
+
"@fluidframework/common-utils": "^1.0.0",
|
|
62
|
+
"@fluidframework/core-interfaces": "2.0.0-dev.1.3.0.96595",
|
|
63
|
+
"@fluidframework/datastore-definitions": "2.0.0-dev.1.3.0.96595",
|
|
64
|
+
"@fluidframework/driver-utils": "2.0.0-dev.1.3.0.96595",
|
|
65
|
+
"@fluidframework/protocol-definitions": "^1.0.0",
|
|
66
|
+
"@fluidframework/runtime-definitions": "2.0.0-dev.1.3.0.96595",
|
|
67
|
+
"@fluidframework/shared-object-base": "2.0.0-dev.1.3.0.96595"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@fluidframework/build-common": "^0.
|
|
71
|
-
"@fluidframework/build-tools": "^0.
|
|
72
|
-
"@fluidframework/counter-previous": "npm:@fluidframework/counter
|
|
73
|
-
"@fluidframework/eslint-config-fluid": "^0.
|
|
74
|
-
"@fluidframework/mocha-test-setup": "
|
|
75
|
-
"@fluidframework/test-runtime-utils": "
|
|
70
|
+
"@fluidframework/build-common": "^1.0.0",
|
|
71
|
+
"@fluidframework/build-tools": "^0.4.6000",
|
|
72
|
+
"@fluidframework/counter-previous": "npm:@fluidframework/counter@^1.0.0",
|
|
73
|
+
"@fluidframework/eslint-config-fluid": "^1.0.0",
|
|
74
|
+
"@fluidframework/mocha-test-setup": "2.0.0-dev.1.3.0.96595",
|
|
75
|
+
"@fluidframework/test-runtime-utils": "2.0.0-dev.1.3.0.96595",
|
|
76
76
|
"@microsoft/api-extractor": "^7.22.2",
|
|
77
77
|
"@rushstack/eslint-config": "^2.5.1",
|
|
78
78
|
"@types/mocha": "^9.1.1",
|
|
79
79
|
"@types/node": "^14.18.0",
|
|
80
80
|
"concurrently": "^6.2.0",
|
|
81
|
-
"copyfiles": "^2.1
|
|
81
|
+
"copyfiles": "^2.4.1",
|
|
82
82
|
"cross-env": "^7.0.2",
|
|
83
83
|
"eslint": "~8.6.0",
|
|
84
84
|
"mocha": "^10.0.0",
|
|
@@ -87,7 +87,7 @@
|
|
|
87
87
|
"typescript": "~4.5.5"
|
|
88
88
|
},
|
|
89
89
|
"typeValidation": {
|
|
90
|
-
"version": "
|
|
90
|
+
"version": "2.0.0",
|
|
91
91
|
"broken": {}
|
|
92
92
|
}
|
|
93
93
|
}
|
package/src/counter.ts
CHANGED
|
@@ -17,7 +17,7 @@ import { CounterFactory } from "./counterFactory";
|
|
|
17
17
|
import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Describes the op format for incrementing the
|
|
20
|
+
* Describes the operation (op) format for incrementing the {@link SharedCounter}.
|
|
21
21
|
*/
|
|
22
22
|
interface IIncrementOperation {
|
|
23
23
|
type: "increment";
|
|
@@ -25,55 +25,67 @@ interface IIncrementOperation {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Used in snapshotting.
|
|
28
|
+
* @remarks Used in snapshotting.
|
|
29
29
|
*/
|
|
30
30
|
interface ICounterSnapshotFormat {
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The value of the counter.
|
|
33
|
+
*/
|
|
32
34
|
value: number;
|
|
33
35
|
}
|
|
34
36
|
|
|
35
37
|
const snapshotFileName = "header";
|
|
36
38
|
|
|
37
39
|
/**
|
|
38
|
-
* A
|
|
39
|
-
*
|
|
40
|
+
* A shared object that holds a number that can be incremented or decremented.
|
|
41
|
+
*
|
|
42
|
+
* @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
|
|
40
43
|
*
|
|
41
|
-
* @
|
|
42
|
-
* ### Creation
|
|
44
|
+
* @example Creating a `SharedCounter`:
|
|
43
45
|
*
|
|
44
|
-
*
|
|
46
|
+
* First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
47
|
+
* with a runtime and string ID:
|
|
45
48
|
*
|
|
46
49
|
* ```typescript
|
|
47
50
|
* const factory = SharedCounter.getFactory();
|
|
48
51
|
* const counter = factory.create(this.runtime, id) as SharedCounter;
|
|
49
52
|
* ```
|
|
50
53
|
*
|
|
51
|
-
*
|
|
54
|
+
* The initial value of a new `SharedCounter` is 0.
|
|
55
|
+
* If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
|
|
56
|
+
* attaching the Container, or before inserting it into an existing shared object.
|
|
52
57
|
*
|
|
53
|
-
*
|
|
58
|
+
* @example Using the `SharedCounter`:
|
|
59
|
+
*
|
|
60
|
+
* Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
|
|
61
|
+
* negative number:
|
|
54
62
|
*
|
|
55
63
|
* ```typescript
|
|
56
64
|
* counter.increment(10); // add 10 to the counter value
|
|
57
65
|
* counter.increment(-5); // subtract 5 from the counter value
|
|
58
66
|
* ```
|
|
59
67
|
*
|
|
60
|
-
* To observe changes to the value (including those from remote clients), register for the
|
|
68
|
+
* To observe changes to the value (including those from remote clients), register for the
|
|
69
|
+
* {@link ISharedCounterEvents | incremented} event:
|
|
61
70
|
*
|
|
62
71
|
* ```typescript
|
|
63
72
|
* counter.on("incremented", (incrementAmount, newValue) => {
|
|
64
73
|
* console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
|
|
65
74
|
* });
|
|
66
75
|
* ```
|
|
76
|
+
*
|
|
77
|
+
* @public
|
|
67
78
|
*/
|
|
68
79
|
export class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
|
|
69
80
|
/**
|
|
70
|
-
* Create a new
|
|
81
|
+
* Create a new {@link SharedCounter}.
|
|
82
|
+
*
|
|
83
|
+
* @param runtime - The data store runtime to which the new `SharedCounter` will belong.
|
|
84
|
+
* @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
|
|
71
85
|
*
|
|
72
|
-
* @param runtime - data store runtime the new shared counter belongs to
|
|
73
|
-
* @param id - optional name of the shared counter
|
|
74
86
|
* @returns newly create shared counter (but not attached yet)
|
|
75
87
|
*/
|
|
76
|
-
public static create(runtime: IFluidDataStoreRuntime, id?: string) {
|
|
88
|
+
public static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter {
|
|
77
89
|
return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;
|
|
78
90
|
}
|
|
79
91
|
|
|
@@ -82,7 +94,7 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
82
94
|
}
|
|
83
95
|
|
|
84
96
|
/**
|
|
85
|
-
* Get a factory for SharedCounter to register with the data store.
|
|
97
|
+
* Get a factory for {@link SharedCounter} to register with the data store.
|
|
86
98
|
*
|
|
87
99
|
* @returns a factory that creates and load SharedCounter
|
|
88
100
|
*/
|
|
@@ -95,14 +107,14 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
95
107
|
/**
|
|
96
108
|
* {@inheritDoc ISharedCounter.value}
|
|
97
109
|
*/
|
|
98
|
-
public get value() {
|
|
110
|
+
public get value(): number {
|
|
99
111
|
return this._value;
|
|
100
112
|
}
|
|
101
113
|
|
|
102
114
|
/**
|
|
103
115
|
* {@inheritDoc ISharedCounter.increment}
|
|
104
116
|
*/
|
|
105
|
-
public increment(incrementAmount: number) {
|
|
117
|
+
public increment(incrementAmount: number): void {
|
|
106
118
|
// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the
|
|
107
119
|
// increments are applied affects the result. A more-robust solution would be required to support this.
|
|
108
120
|
if (incrementAmount % 1 !== 0) {
|
|
@@ -118,15 +130,16 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
118
130
|
this.submitLocalMessage(op);
|
|
119
131
|
}
|
|
120
132
|
|
|
121
|
-
private incrementCore(incrementAmount: number) {
|
|
133
|
+
private incrementCore(incrementAmount: number): void {
|
|
122
134
|
this._value += incrementAmount;
|
|
123
135
|
this.emit("incremented", incrementAmount, this._value);
|
|
124
136
|
}
|
|
125
137
|
|
|
126
138
|
/**
|
|
127
|
-
* Create a summary for the counter
|
|
139
|
+
* Create a summary for the counter.
|
|
140
|
+
*
|
|
141
|
+
* @returns The summary of the current state of the counter.
|
|
128
142
|
*
|
|
129
|
-
* @returns the summary of the current state of the counter
|
|
130
143
|
* @internal
|
|
131
144
|
*/
|
|
132
145
|
protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {
|
|
@@ -141,6 +154,7 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
141
154
|
|
|
142
155
|
/**
|
|
143
156
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
157
|
+
*
|
|
144
158
|
* @internal
|
|
145
159
|
*/
|
|
146
160
|
protected async loadCore(storage: IChannelStorageService): Promise<void> {
|
|
@@ -151,20 +165,22 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
151
165
|
|
|
152
166
|
/**
|
|
153
167
|
* Called when the object has disconnected from the delta stream.
|
|
168
|
+
*
|
|
154
169
|
* @internal
|
|
155
170
|
*/
|
|
156
|
-
protected onDisconnect() { }
|
|
171
|
+
protected onDisconnect(): void { }
|
|
157
172
|
|
|
158
173
|
/**
|
|
159
|
-
* Process a counter operation
|
|
174
|
+
* Process a counter operation (op).
|
|
160
175
|
*
|
|
161
|
-
* @param message -
|
|
162
|
-
* @param local -
|
|
176
|
+
* @param message - The message to prepare.
|
|
177
|
+
* @param local - Whether or not the message was sent by the local client.
|
|
163
178
|
* @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
|
|
164
|
-
* For messages from a remote client, this will be undefined
|
|
179
|
+
* For messages from a remote client, this will be `undefined`.
|
|
180
|
+
*
|
|
165
181
|
* @internal
|
|
166
182
|
*/
|
|
167
|
-
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {
|
|
183
|
+
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void {
|
|
168
184
|
if (message.type === MessageType.Operation && !local) {
|
|
169
185
|
const op = message.contents as IIncrementOperation;
|
|
170
186
|
|
|
@@ -181,9 +197,10 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
181
197
|
|
|
182
198
|
/**
|
|
183
199
|
* Not implemented.
|
|
200
|
+
*
|
|
184
201
|
* @internal
|
|
185
202
|
*/
|
|
186
203
|
protected applyStashedOp() {
|
|
187
|
-
throw new Error("
|
|
204
|
+
throw new Error("Not implemented");
|
|
188
205
|
}
|
|
189
206
|
}
|
package/src/counterFactory.ts
CHANGED
|
@@ -14,22 +14,36 @@ import { ISharedCounter } from "./interfaces";
|
|
|
14
14
|
import { pkgVersion } from "./packageVersion";
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.
|
|
18
|
+
*
|
|
19
|
+
* @sealed
|
|
18
20
|
*/
|
|
19
21
|
export class CounterFactory implements IChannelFactory {
|
|
22
|
+
/**
|
|
23
|
+
* Static value for {@link CounterFactory."type"}.
|
|
24
|
+
*/
|
|
20
25
|
public static readonly Type = "https://graph.microsoft.com/types/counter";
|
|
21
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Static value for {@link CounterFactory.attributes}.
|
|
29
|
+
*/
|
|
22
30
|
public static readonly Attributes: IChannelAttributes = {
|
|
23
31
|
type: CounterFactory.Type,
|
|
24
32
|
snapshotFormatVersion: "0.1",
|
|
25
33
|
packageVersion: pkgVersion,
|
|
26
34
|
};
|
|
27
35
|
|
|
28
|
-
|
|
36
|
+
/**
|
|
37
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory."type"}
|
|
38
|
+
*/
|
|
39
|
+
public get type(): string {
|
|
29
40
|
return CounterFactory.Type;
|
|
30
41
|
}
|
|
31
42
|
|
|
32
|
-
|
|
43
|
+
/**
|
|
44
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}
|
|
45
|
+
*/
|
|
46
|
+
public get attributes(): IChannelAttributes {
|
|
33
47
|
return CounterFactory.Attributes;
|
|
34
48
|
}
|
|
35
49
|
|
|
@@ -46,6 +60,9 @@ export class CounterFactory implements IChannelFactory {
|
|
|
46
60
|
return counter;
|
|
47
61
|
}
|
|
48
62
|
|
|
63
|
+
/**
|
|
64
|
+
* {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
|
|
65
|
+
*/
|
|
49
66
|
public create(document: IFluidDataStoreRuntime, id: string): ISharedCounter {
|
|
50
67
|
const counter = new SharedCounter(id, document, this.attributes);
|
|
51
68
|
counter.initializeLocal();
|
package/src/index.ts
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* This
|
|
8
|
-
* which holds a number that can be incremented or decremented.
|
|
7
|
+
* This library contains the {@link SharedCounter} distributed data structure.
|
|
8
|
+
* A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
|
|
9
9
|
*
|
|
10
10
|
* @packageDocumentation
|
|
11
11
|
*/
|
package/src/interfaces.ts
CHANGED
|
@@ -6,7 +6,8 @@
|
|
|
6
6
|
import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
* Events sent by
|
|
9
|
+
* Events sent by {@link SharedCounter}.
|
|
10
|
+
*
|
|
10
11
|
* @public
|
|
11
12
|
*/
|
|
12
13
|
export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
@@ -22,19 +23,23 @@ export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
/**
|
|
25
|
-
* SharedCounter interface.
|
|
26
|
+
* {@link SharedCounter} interface.
|
|
27
|
+
*
|
|
26
28
|
* @public
|
|
27
29
|
*/
|
|
28
30
|
export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
29
31
|
/**
|
|
30
32
|
* The counter value.
|
|
33
|
+
*
|
|
34
|
+
* @remarks Must be a whole number.
|
|
31
35
|
*/
|
|
32
36
|
value: number;
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
|
-
* Increments or decrements the value.
|
|
39
|
+
* Increments or decrements the value.
|
|
40
|
+
* Must only increment or decrement by a whole number value.
|
|
36
41
|
*
|
|
37
|
-
* @param incrementAmount -
|
|
42
|
+
* @param incrementAmount - A whole number to increment or decrement by.
|
|
38
43
|
*/
|
|
39
44
|
increment(incrementAmount: number): void;
|
|
40
45
|
}
|
package/src/packageVersion.ts
CHANGED