@fluidframework/counter 0.47.1 → 0.48.0-38105
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/dist/counter.d.ts +7 -1
- package/dist/counter.d.ts.map +1 -1
- package/dist/counter.js +7 -1
- package/dist/counter.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces.d.ts +7 -2
- 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 +7 -1
- package/lib/counter.d.ts.map +1 -1
- package/lib/counter.js +7 -1
- package/lib/counter.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +2 -1
- package/lib/index.js.map +1 -1
- package/lib/interfaces.d.ts +7 -2
- 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 +7 -7
- package/src/counter.ts +8 -2
- package/src/index.ts +2 -1
- package/src/interfaces.ts +7 -2
- package/src/packageVersion.ts +1 -1
package/dist/counter.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { SharedObject } from "@fluidframework/shared-object-base";
|
|
|
9
9
|
import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
|
|
10
10
|
/**
|
|
11
11
|
* A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
|
|
12
|
+
* @public
|
|
12
13
|
*
|
|
13
14
|
* @remarks
|
|
14
15
|
* ### Creation
|
|
@@ -66,18 +67,22 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
66
67
|
* Create a snapshot for the counter
|
|
67
68
|
*
|
|
68
69
|
* @returns the snapshot of the current state of the counter
|
|
70
|
+
* @internal
|
|
69
71
|
*/
|
|
70
72
|
protected snapshotCore(serializer: IFluidSerializer): ITree;
|
|
71
73
|
/**
|
|
72
74
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
75
|
+
* @internal
|
|
73
76
|
*/
|
|
74
77
|
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
75
78
|
/**
|
|
76
79
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
|
|
80
|
+
* @internal
|
|
77
81
|
*/
|
|
78
82
|
protected registerCore(): void;
|
|
79
83
|
/**
|
|
80
|
-
*
|
|
84
|
+
* Called when the object has disconnected from the delta stream.
|
|
85
|
+
* @internal
|
|
81
86
|
*/
|
|
82
87
|
protected onDisconnect(): void;
|
|
83
88
|
/**
|
|
@@ -91,6 +96,7 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
91
96
|
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
92
97
|
/**
|
|
93
98
|
* Not implemented.
|
|
99
|
+
* @internal
|
|
94
100
|
*/
|
|
95
101
|
protected applyStashedOp(): void;
|
|
96
102
|
}
|
package/dist/counter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAEH,yBAAyB,EACzB,KAAK,EAGR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAAE,cA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AG3B"}
|
package/dist/counter.js
CHANGED
|
@@ -12,6 +12,7 @@ const counterFactory_1 = require("./counterFactory");
|
|
|
12
12
|
const snapshotFileName = "header";
|
|
13
13
|
/**
|
|
14
14
|
* A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
|
|
15
|
+
* @public
|
|
15
16
|
*
|
|
16
17
|
* @remarks
|
|
17
18
|
* ### Creation
|
|
@@ -93,6 +94,7 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
93
94
|
* Create a snapshot for the counter
|
|
94
95
|
*
|
|
95
96
|
* @returns the snapshot of the current state of the counter
|
|
97
|
+
* @internal
|
|
96
98
|
*/
|
|
97
99
|
snapshotCore(serializer) {
|
|
98
100
|
// Get a serializable form of data
|
|
@@ -117,6 +119,7 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
117
119
|
}
|
|
118
120
|
/**
|
|
119
121
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
122
|
+
* @internal
|
|
120
123
|
*/
|
|
121
124
|
async loadCore(storage) {
|
|
122
125
|
const content = await driver_utils_1.readAndParse(storage, snapshotFileName);
|
|
@@ -124,11 +127,13 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
124
127
|
}
|
|
125
128
|
/**
|
|
126
129
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
|
|
130
|
+
* @internal
|
|
127
131
|
*/
|
|
128
132
|
registerCore() {
|
|
129
133
|
}
|
|
130
134
|
/**
|
|
131
|
-
*
|
|
135
|
+
* Called when the object has disconnected from the delta stream.
|
|
136
|
+
* @internal
|
|
132
137
|
*/
|
|
133
138
|
onDisconnect() { }
|
|
134
139
|
/**
|
|
@@ -153,6 +158,7 @@ class SharedCounter extends shared_object_base_1.SharedObject {
|
|
|
153
158
|
}
|
|
154
159
|
/**
|
|
155
160
|
* Not implemented.
|
|
161
|
+
* @internal
|
|
156
162
|
*/
|
|
157
163
|
applyStashedOp() {
|
|
158
164
|
throw new Error("not implemented");
|
package/dist/counter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+EAM8C;AAM9C,+DAA4D;AAC5D,2EAAkE;AAClE,qDAAkD;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,+EAM8C;AAM9C,+DAA4D;AAC5D,2EAAkE;AAClE,qDAAkD;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAa,aAAc,SAAQ,iCAAkC;IAArE;;QAqBY,WAAM,GAAW,CAAC,CAAC;IAoH/B,CAAC;IAxIG;;;;;;OAMG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAC7D,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,+BAAc,CAAC,IAAI,CAAkB,CAAC;IAC3E,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU;QACpB,OAAO,IAAI,+BAAc,EAAE,CAAC;IAChC,CAAC;IAID;;OAEG;IACH,IAAW,KAAK;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,eAAuB;QACpC,uGAAuG;QACvG,wGAAwG;QACxG,IAAI,eAAe,GAAG,CAAC,KAAK,CAAC,EAAE;YAC3B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACvD;QAED,MAAM,EAAE,GAAwB;YAC5B,IAAI,EAAE,WAAW;YACjB,eAAe;SAClB,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACpC,IAAI,CAAC,kBAAkB,CAAC,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e,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;OAGG;IACO,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ;AAzID,sCAyIC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n FileMode,\n ISequencedDocumentMessage,\n ITree,\n MessageType,\n TreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the op format for incrementing the counter\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n // The value of the counter\n value: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.\n * @public\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCounter`, get the factory and call create with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * ### Usage\n *\n * Once created, you can call `increment` to modify the value with either a positive or negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the `\"incremented\"` event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new shared counter\n *\n * @param runtime - data store runtime the new shared counter belongs to\n * @param id - optional name of the shared counter\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n /**\n * Get a factory for SharedCounter to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value() {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number) {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number) {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a snapshot for the counter\n *\n * @returns the snapshot of the current state of the counter\n * @internal\n */\n protected snapshotCore(serializer: IFluidSerializer): ITree {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the tree for it\n const tree: ITree = {\n entries: [\n {\n mode: FileMode.File,\n path: snapshotFileName,\n type: TreeEntry.Blob,\n value: {\n contents: JSON.stringify(content),\n encoding: \"utf-8\",\n },\n },\n ],\n };\n\n return tree;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}\n * @internal\n */\n protected registerCore() {\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n * @internal\n */\n protected onDisconnect() { }\n\n /**\n * Process a counter operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* This package contains the SharedCounter distributed data structure.
|
|
6
|
+
* This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object
|
|
7
|
+
* which holds a number that can be incremented or decremented.
|
|
7
8
|
*
|
|
8
9
|
* @packageDocumentation
|
|
9
10
|
*/
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -15,7 +15,8 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
/**
|
|
18
|
-
* This package contains the SharedCounter distributed data structure.
|
|
18
|
+
* This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object
|
|
19
|
+
* which holds a number that can be incremented or decremented.
|
|
19
20
|
*
|
|
20
21
|
* @packageDocumentation
|
|
21
22
|
*/
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;AAEH;;;;;GAKG;AAEH,4CAA0B;AAC1B,+CAA6B","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object\n * which holds a number that can be incremented or decremented.\n *\n * @packageDocumentation\n */\n\nexport * from \"./counter\";\nexport * from \"./interfaces\";\n"]}
|
package/dist/interfaces.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
|
|
6
|
+
/**
|
|
7
|
+
* Events sent by SharedCounters.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
6
10
|
export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
7
11
|
/**
|
|
8
12
|
* This event is raised when the counter is incremented or decremented.
|
|
@@ -15,7 +19,8 @@ export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
|
15
19
|
(event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
22
|
+
* SharedCounter interface.
|
|
23
|
+
* @public
|
|
19
24
|
*/
|
|
20
25
|
export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
21
26
|
/**
|
|
@@ -25,7 +30,7 @@ export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
|
25
30
|
/**
|
|
26
31
|
* Increments or decrements the value. Must only increment or decrement by a whole number value.
|
|
27
32
|
*
|
|
28
|
-
* @param incrementAmount - a whole number to increment or decrement by
|
|
33
|
+
* @param incrementAmount - a whole number to increment or decrement by.
|
|
29
34
|
*/
|
|
30
35
|
increment(incrementAmount: number): void;
|
|
31
36
|
}
|
package/dist/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC7D;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;CACzF;AAED
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC7D;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;CACzF;AAED;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,aAAa,CAAC,oBAAoB,CAAC;IACvE;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5C"}
|
package/dist/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\nexport interface ISharedCounterEvents extends ISharedObjectEvents {\n /**\n * This event is raised when the counter is incremented or decremented.\n *\n * @param event - The event name.\n * @param listener - An event listener.\n *\n * @eventProperty\n */\n (event: \"incremented\", listener: (incrementAmount: number, newValue: number) => void);\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Events sent by SharedCounters.\n * @public\n */\nexport interface ISharedCounterEvents extends ISharedObjectEvents {\n /**\n * This event is raised when the counter is incremented or decremented.\n *\n * @param event - The event name.\n * @param listener - An event listener.\n *\n * @eventProperty\n */\n (event: \"incremented\", listener: (incrementAmount: number, newValue: number) => void);\n}\n\n/**\n * SharedCounter interface.\n * @public\n */\nexport interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {\n /**\n * The counter value.\n */\n value: number;\n\n /**\n * Increments or decrements the value. Must only increment or decrement by a whole number value.\n *\n * @param incrementAmount - a whole number to increment or decrement by.\n */\n increment(incrementAmount: number): void;\n}\n"]}
|
package/dist/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/counter";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.48.0-38105";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/dist/packageVersion.js
CHANGED
|
@@ -8,5 +8,5 @@
|
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.pkgVersion = exports.pkgName = void 0;
|
|
10
10
|
exports.pkgName = "@fluidframework/counter";
|
|
11
|
-
exports.pkgVersion = "0.
|
|
11
|
+
exports.pkgVersion = "0.48.0-38105";
|
|
12
12
|
//# sourceMappingURL=packageVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/counter\";\nexport const pkgVersion = \"0.48.0-38105\";\n"]}
|
package/lib/counter.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ import { SharedObject } from "@fluidframework/shared-object-base";
|
|
|
9
9
|
import { ISharedCounter, ISharedCounterEvents } from "./interfaces";
|
|
10
10
|
/**
|
|
11
11
|
* A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
|
|
12
|
+
* @public
|
|
12
13
|
*
|
|
13
14
|
* @remarks
|
|
14
15
|
* ### Creation
|
|
@@ -66,18 +67,22 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
66
67
|
* Create a snapshot for the counter
|
|
67
68
|
*
|
|
68
69
|
* @returns the snapshot of the current state of the counter
|
|
70
|
+
* @internal
|
|
69
71
|
*/
|
|
70
72
|
protected snapshotCore(serializer: IFluidSerializer): ITree;
|
|
71
73
|
/**
|
|
72
74
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
75
|
+
* @internal
|
|
73
76
|
*/
|
|
74
77
|
protected loadCore(storage: IChannelStorageService): Promise<void>;
|
|
75
78
|
/**
|
|
76
79
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
|
|
80
|
+
* @internal
|
|
77
81
|
*/
|
|
78
82
|
protected registerCore(): void;
|
|
79
83
|
/**
|
|
80
|
-
*
|
|
84
|
+
* Called when the object has disconnected from the delta stream.
|
|
85
|
+
* @internal
|
|
81
86
|
*/
|
|
82
87
|
protected onDisconnect(): void;
|
|
83
88
|
/**
|
|
@@ -91,6 +96,7 @@ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> im
|
|
|
91
96
|
protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
|
|
92
97
|
/**
|
|
93
98
|
* Not implemented.
|
|
99
|
+
* @internal
|
|
94
100
|
*/
|
|
95
101
|
protected applyStashedOp(): void;
|
|
96
102
|
}
|
package/lib/counter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAEH,yBAAyB,EACzB,KAAK,EAGR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAoBpE
|
|
1
|
+
{"version":3,"file":"counter.d.ts","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAEH,yBAAyB,EACzB,KAAK,EAGR,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EACH,sBAAsB,EACtB,sBAAsB,EACtB,eAAe,EAClB,MAAM,uCAAuC,CAAC;AAE/C,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAoBpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,aAAc,SAAQ,YAAY,CAAC,oBAAoB,CAAE,YAAW,cAAc;IAC3F;;;;;;OAMG;WACW,MAAM,CAAC,OAAO,EAAE,sBAAsB,EAAE,EAAE,CAAC,EAAE,MAAM;IAIjE;;;;OAIG;WACW,UAAU,IAAI,eAAe;IAI3C,OAAO,CAAC,MAAM,CAAa;IAE3B;;OAEG;IACH,IAAW,KAAK,WAEf;IAED;;OAEG;IACI,SAAS,CAAC,eAAe,EAAE,MAAM;IAgBxC,OAAO,CAAC,aAAa;IAKrB;;;;;OAKG;IACH,SAAS,CAAC,YAAY,CAAC,UAAU,EAAE,gBAAgB,GAAG,KAAK;IAwB3D;;;OAGG;cACa,QAAQ,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,IAAI,CAAC;IAMxE;;;OAGG;IACH,SAAS,CAAC,YAAY;IAGtB;;;OAGG;IACH,SAAS,CAAC,YAAY;IAEtB;;;;;;;OAOG;IACH,SAAS,CAAC,WAAW,CAAC,OAAO,EAAE,yBAAyB,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,OAAO;IAelG;;;OAGG;IACH,SAAS,CAAC,cAAc;CAG3B"}
|
package/lib/counter.js
CHANGED
|
@@ -9,6 +9,7 @@ import { CounterFactory } from "./counterFactory";
|
|
|
9
9
|
const snapshotFileName = "header";
|
|
10
10
|
/**
|
|
11
11
|
* A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
|
|
12
|
+
* @public
|
|
12
13
|
*
|
|
13
14
|
* @remarks
|
|
14
15
|
* ### Creation
|
|
@@ -90,6 +91,7 @@ export class SharedCounter extends SharedObject {
|
|
|
90
91
|
* Create a snapshot for the counter
|
|
91
92
|
*
|
|
92
93
|
* @returns the snapshot of the current state of the counter
|
|
94
|
+
* @internal
|
|
93
95
|
*/
|
|
94
96
|
snapshotCore(serializer) {
|
|
95
97
|
// Get a serializable form of data
|
|
@@ -114,6 +116,7 @@ export class SharedCounter extends SharedObject {
|
|
|
114
116
|
}
|
|
115
117
|
/**
|
|
116
118
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
119
|
+
* @internal
|
|
117
120
|
*/
|
|
118
121
|
async loadCore(storage) {
|
|
119
122
|
const content = await readAndParse(storage, snapshotFileName);
|
|
@@ -121,11 +124,13 @@ export class SharedCounter extends SharedObject {
|
|
|
121
124
|
}
|
|
122
125
|
/**
|
|
123
126
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
|
|
127
|
+
* @internal
|
|
124
128
|
*/
|
|
125
129
|
registerCore() {
|
|
126
130
|
}
|
|
127
131
|
/**
|
|
128
|
-
*
|
|
132
|
+
* Called when the object has disconnected from the delta stream.
|
|
133
|
+
* @internal
|
|
129
134
|
*/
|
|
130
135
|
onDisconnect() { }
|
|
131
136
|
/**
|
|
@@ -150,6 +155,7 @@ export class SharedCounter extends SharedObject {
|
|
|
150
155
|
}
|
|
151
156
|
/**
|
|
152
157
|
* Not implemented.
|
|
158
|
+
* @internal
|
|
153
159
|
*/
|
|
154
160
|
applyStashedOp() {
|
|
155
161
|
throw new Error("not implemented");
|
package/lib/counter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,QAAQ,EAGR,WAAW,EACX,SAAS,GACZ,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC
|
|
1
|
+
{"version":3,"file":"counter.js","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EACH,QAAQ,EAGR,WAAW,EACX,SAAS,GACZ,MAAM,sCAAsC,CAAC;AAM9C,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAmBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,OAAO,aAAc,SAAQ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,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC;wBACjC,QAAQ,EAAE,OAAO;qBACpB;iBACJ;aACJ;SACJ,CAAC;QAEF,OAAO,IAAI,CAAC;IAChB,CAAC;IAED;;;OAGG;IACO,KAAK,CAAC,QAAQ,CAAC,OAA+B;QACpD,MAAM,OAAO,GAAG,MAAM,YAAY,CAAyB,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAEtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAChC,CAAC;IAED;;;OAGG;IACO,YAAY;IACtB,CAAC;IAED;;;OAGG;IACO,YAAY,KAAK,CAAC;IAE5B;;;;;;;OAOG;IACO,WAAW,CAAC,OAAkC,EAAE,KAAc,EAAE,eAAwB;QAC9F,IAAI,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YAClD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBACb,KAAK,WAAW;oBACZ,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;gBAEV;oBACI,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;aAC5C;SACJ;IACL,CAAC;IAED;;;OAGG;IACO,cAAc;QACpB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IACvC,CAAC;CACJ","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { IFluidSerializer } from \"@fluidframework/core-interfaces\";\nimport {\n FileMode,\n ISequencedDocumentMessage,\n ITree,\n MessageType,\n TreeEntry,\n} from \"@fluidframework/protocol-definitions\";\nimport {\n IFluidDataStoreRuntime,\n IChannelStorageService,\n IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { SharedObject } from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the op format for incrementing the counter\n */\ninterface IIncrementOperation {\n type: \"increment\";\n incrementAmount: number;\n}\n\n/**\n * Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n // The value of the counter\n value: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.\n * @public\n *\n * @remarks\n * ### Creation\n *\n * To create a `SharedCounter`, get the factory and call create with a runtime and string ID:\n *\n * ```typescript\n * const factory = SharedCounter.getFactory();\n * const counter = factory.create(this.runtime, id) as SharedCounter;\n * ```\n *\n * ### Usage\n *\n * Once created, you can call `increment` to modify the value with either a positive or negative number:\n *\n * ```typescript\n * counter.increment(10); // add 10 to the counter value\n * counter.increment(-5); // subtract 5 from the counter value\n * ```\n *\n * To observe changes to the value (including those from remote clients), register for the `\"incremented\"` event:\n *\n * ```typescript\n * counter.on(\"incremented\", (incrementAmount, newValue) => {\n * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);\n * });\n * ```\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n /**\n * Create a new shared counter\n *\n * @param runtime - data store runtime the new shared counter belongs to\n * @param id - optional name of the shared counter\n * @returns newly create shared counter (but not attached yet)\n */\n public static create(runtime: IFluidDataStoreRuntime, id?: string) {\n return runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n }\n\n /**\n * Get a factory for SharedCounter to register with the data store.\n *\n * @returns a factory that creates and load SharedCounter\n */\n public static getFactory(): IChannelFactory {\n return new CounterFactory();\n }\n\n private _value: number = 0;\n\n /**\n * {@inheritDoc ISharedCounter.value}\n */\n public get value() {\n return this._value;\n }\n\n /**\n * {@inheritDoc ISharedCounter.increment}\n */\n public increment(incrementAmount: number) {\n // Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n // increments are applied affects the result. A more-robust solution would be required to support this.\n if (incrementAmount % 1 !== 0) {\n throw new Error(\"Must increment by a whole number\");\n }\n\n const op: IIncrementOperation = {\n type: \"increment\",\n incrementAmount,\n };\n\n this.incrementCore(incrementAmount);\n this.submitLocalMessage(op);\n }\n\n private incrementCore(incrementAmount: number) {\n this._value += incrementAmount;\n this.emit(\"incremented\", incrementAmount, this._value);\n }\n\n /**\n * Create a snapshot for the counter\n *\n * @returns the snapshot of the current state of the counter\n * @internal\n */\n protected snapshotCore(serializer: IFluidSerializer): ITree {\n // Get a serializable form of data\n const content: ICounterSnapshotFormat = {\n value: this.value,\n };\n\n // And then construct the tree for it\n const tree: ITree = {\n entries: [\n {\n mode: FileMode.File,\n path: snapshotFileName,\n type: TreeEntry.Blob,\n value: {\n contents: JSON.stringify(content),\n encoding: \"utf-8\",\n },\n },\n ],\n };\n\n return tree;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n * @internal\n */\n protected async loadCore(storage: IChannelStorageService): Promise<void> {\n const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n this._value = content.value;\n }\n\n /**\n * {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}\n * @internal\n */\n protected registerCore() {\n }\n\n /**\n * Called when the object has disconnected from the delta stream.\n * @internal\n */\n protected onDisconnect() { }\n\n /**\n * Process a counter operation\n *\n * @param message - the message to prepare\n * @param local - whether the message was sent by the local client\n * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n * For messages from a remote client, this will be undefined.\n */\n protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown) {\n if (message.type === MessageType.Operation && !local) {\n const op = message.contents as IIncrementOperation;\n\n switch (op.type) {\n case \"increment\":\n this.incrementCore(op.incrementAmount);\n break;\n\n default:\n throw new Error(\"Unknown operation\");\n }\n }\n }\n\n /**\n * Not implemented.\n * @internal\n */\n protected applyStashedOp() {\n throw new Error(\"not implemented\");\n }\n}\n"]}
|
package/lib/index.d.ts
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* This package contains the SharedCounter distributed data structure.
|
|
6
|
+
* This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object
|
|
7
|
+
* which holds a number that can be incremented or decremented.
|
|
7
8
|
*
|
|
8
9
|
* @packageDocumentation
|
|
9
10
|
*/
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
|
-
* This package contains the SharedCounter distributed data structure.
|
|
6
|
+
* This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object
|
|
7
|
+
* which holds a number that can be incremented or decremented.
|
|
7
8
|
*
|
|
8
9
|
* @packageDocumentation
|
|
9
10
|
*/
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH;;;;;GAKG;AAEH,cAAc,WAAW,CAAC;AAC1B,cAAc,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object\n * which holds a number that can be incremented or decremented.\n *\n * @packageDocumentation\n */\n\nexport * from \"./counter\";\nexport * from \"./interfaces\";\n"]}
|
package/lib/interfaces.d.ts
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
* Licensed under the MIT License.
|
|
4
4
|
*/
|
|
5
5
|
import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
|
|
6
|
+
/**
|
|
7
|
+
* Events sent by SharedCounters.
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
6
10
|
export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
7
11
|
/**
|
|
8
12
|
* This event is raised when the counter is incremented or decremented.
|
|
@@ -15,7 +19,8 @@ export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
|
15
19
|
(event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
|
|
16
20
|
}
|
|
17
21
|
/**
|
|
18
|
-
*
|
|
22
|
+
* SharedCounter interface.
|
|
23
|
+
* @public
|
|
19
24
|
*/
|
|
20
25
|
export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
21
26
|
/**
|
|
@@ -25,7 +30,7 @@ export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
|
25
30
|
/**
|
|
26
31
|
* Increments or decrements the value. Must only increment or decrement by a whole number value.
|
|
27
32
|
*
|
|
28
|
-
* @param incrementAmount - a whole number to increment or decrement by
|
|
33
|
+
* @param incrementAmount - a whole number to increment or decrement by.
|
|
29
34
|
*/
|
|
30
35
|
increment(incrementAmount: number): void;
|
|
31
36
|
}
|
package/lib/interfaces.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC7D;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;CACzF;AAED
|
|
1
|
+
{"version":3,"file":"interfaces.d.ts","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AAExF;;;GAGG;AACH,MAAM,WAAW,oBAAqB,SAAQ,mBAAmB;IAC7D;;;;;;;OAOG;IACH,CAAC,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,IAAI,OAAE;CACzF;AAED;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,aAAa,CAAC,oBAAoB,CAAC;IACvE;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;;;OAIG;IACH,SAAS,CAAC,eAAe,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5C"}
|
package/lib/interfaces.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\nexport interface ISharedCounterEvents extends ISharedObjectEvents {\n /**\n * This event is raised when the counter is incremented or decremented.\n *\n * @param event - The event name.\n * @param listener - An event listener.\n *\n * @eventProperty\n */\n (event: \"incremented\", listener: (incrementAmount: number, newValue: number) => void);\n}\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { ISharedObject, ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Events sent by SharedCounters.\n * @public\n */\nexport interface ISharedCounterEvents extends ISharedObjectEvents {\n /**\n * This event is raised when the counter is incremented or decremented.\n *\n * @param event - The event name.\n * @param listener - An event listener.\n *\n * @eventProperty\n */\n (event: \"incremented\", listener: (incrementAmount: number, newValue: number) => void);\n}\n\n/**\n * SharedCounter interface.\n * @public\n */\nexport interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {\n /**\n * The counter value.\n */\n value: number;\n\n /**\n * Increments or decrements the value. Must only increment or decrement by a whole number value.\n *\n * @param incrementAmount - a whole number to increment or decrement by.\n */\n increment(incrementAmount: number): void;\n}\n"]}
|
package/lib/packageVersion.d.ts
CHANGED
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
|
|
6
6
|
*/
|
|
7
7
|
export declare const pkgName = "@fluidframework/counter";
|
|
8
|
-
export declare const pkgVersion = "0.
|
|
8
|
+
export declare const pkgVersion = "0.48.0-38105";
|
|
9
9
|
//# sourceMappingURL=packageVersion.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,
|
|
1
|
+
{"version":3,"file":"packageVersion.d.ts","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,eAAO,MAAM,OAAO,4BAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,iBAAiB,CAAC"}
|
package/lib/packageVersion.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n *\n * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY\n */\n\nexport const pkgName = \"@fluidframework/counter\";\nexport const pkgVersion = \"0.48.0-38105\";\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fluidframework/counter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.48.0-38105",
|
|
4
4
|
"description": "Counter DDS",
|
|
5
5
|
"homepage": "https://fluidframework.com",
|
|
6
6
|
"repository": "https://github.com/microsoft/FluidFramework",
|
|
@@ -55,16 +55,16 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@fluidframework/common-utils": "^0.32.1",
|
|
57
57
|
"@fluidframework/core-interfaces": "^0.39.7",
|
|
58
|
-
"@fluidframework/datastore-definitions": "
|
|
59
|
-
"@fluidframework/driver-utils": "
|
|
58
|
+
"@fluidframework/datastore-definitions": "0.48.0-38105",
|
|
59
|
+
"@fluidframework/driver-utils": "0.48.0-38105",
|
|
60
60
|
"@fluidframework/protocol-definitions": "^0.1024.0",
|
|
61
|
-
"@fluidframework/shared-object-base": "
|
|
61
|
+
"@fluidframework/shared-object-base": "0.48.0-38105"
|
|
62
62
|
},
|
|
63
63
|
"devDependencies": {
|
|
64
|
-
"@fluidframework/build-common": "^0.23.0",
|
|
64
|
+
"@fluidframework/build-common": "^0.23.0-0",
|
|
65
65
|
"@fluidframework/eslint-config-fluid": "^0.23.0",
|
|
66
|
-
"@fluidframework/mocha-test-setup": "
|
|
67
|
-
"@fluidframework/test-runtime-utils": "
|
|
66
|
+
"@fluidframework/mocha-test-setup": "0.48.0-38105",
|
|
67
|
+
"@fluidframework/test-runtime-utils": "0.48.0-38105",
|
|
68
68
|
"@microsoft/api-extractor": "^7.16.1",
|
|
69
69
|
"@types/mocha": "^8.2.2",
|
|
70
70
|
"@types/node": "^12.19.0",
|
package/src/counter.ts
CHANGED
|
@@ -41,6 +41,7 @@ const snapshotFileName = "header";
|
|
|
41
41
|
|
|
42
42
|
/**
|
|
43
43
|
* A `SharedCounter` is a shared object which holds a number that can be incremented or decremented.
|
|
44
|
+
* @public
|
|
44
45
|
*
|
|
45
46
|
* @remarks
|
|
46
47
|
* ### Creation
|
|
@@ -127,6 +128,7 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
127
128
|
* Create a snapshot for the counter
|
|
128
129
|
*
|
|
129
130
|
* @returns the snapshot of the current state of the counter
|
|
131
|
+
* @internal
|
|
130
132
|
*/
|
|
131
133
|
protected snapshotCore(serializer: IFluidSerializer): ITree {
|
|
132
134
|
// Get a serializable form of data
|
|
@@ -154,6 +156,7 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
154
156
|
|
|
155
157
|
/**
|
|
156
158
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
|
|
159
|
+
* @internal
|
|
157
160
|
*/
|
|
158
161
|
protected async loadCore(storage: IChannelStorageService): Promise<void> {
|
|
159
162
|
const content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);
|
|
@@ -163,14 +166,16 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
163
166
|
|
|
164
167
|
/**
|
|
165
168
|
* {@inheritDoc @fluidframework/shared-object-base#SharedObject.registerCore}
|
|
169
|
+
* @internal
|
|
166
170
|
*/
|
|
167
171
|
protected registerCore() {
|
|
168
172
|
}
|
|
169
173
|
|
|
170
174
|
/**
|
|
171
|
-
*
|
|
175
|
+
* Called when the object has disconnected from the delta stream.
|
|
176
|
+
* @internal
|
|
172
177
|
*/
|
|
173
|
-
protected onDisconnect() {}
|
|
178
|
+
protected onDisconnect() { }
|
|
174
179
|
|
|
175
180
|
/**
|
|
176
181
|
* Process a counter operation
|
|
@@ -197,6 +202,7 @@ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements
|
|
|
197
202
|
|
|
198
203
|
/**
|
|
199
204
|
* Not implemented.
|
|
205
|
+
* @internal
|
|
200
206
|
*/
|
|
201
207
|
protected applyStashedOp() {
|
|
202
208
|
throw new Error("not implemented");
|
package/src/index.ts
CHANGED
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* This package contains the SharedCounter distributed data structure.
|
|
7
|
+
* This package contains the SharedCounter distributed data structure. A SharedCounter is a shared object
|
|
8
|
+
* which holds a number that can be incremented or decremented.
|
|
8
9
|
*
|
|
9
10
|
* @packageDocumentation
|
|
10
11
|
*/
|
package/src/interfaces.ts
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
import { ISharedObject, ISharedObjectEvents } from "@fluidframework/shared-object-base";
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* Events sent by SharedCounters.
|
|
10
|
+
* @public
|
|
11
|
+
*/
|
|
8
12
|
export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
9
13
|
/**
|
|
10
14
|
* This event is raised when the counter is incremented or decremented.
|
|
@@ -18,7 +22,8 @@ export interface ISharedCounterEvents extends ISharedObjectEvents {
|
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
/**
|
|
21
|
-
*
|
|
25
|
+
* SharedCounter interface.
|
|
26
|
+
* @public
|
|
22
27
|
*/
|
|
23
28
|
export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
24
29
|
/**
|
|
@@ -29,7 +34,7 @@ export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
|
|
|
29
34
|
/**
|
|
30
35
|
* Increments or decrements the value. Must only increment or decrement by a whole number value.
|
|
31
36
|
*
|
|
32
|
-
* @param incrementAmount - a whole number to increment or decrement by
|
|
37
|
+
* @param incrementAmount - a whole number to increment or decrement by.
|
|
33
38
|
*/
|
|
34
39
|
increment(incrementAmount: number): void;
|
|
35
40
|
}
|
package/src/packageVersion.ts
CHANGED