@fluidframework/counter 2.0.0-dev.7.3.0.210328 → 2.0.0-dev.7.3.0.212138

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 (47) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/api-extractor.json +4 -1
  3. package/dist/counter-alpha.d.ts +153 -0
  4. package/dist/counter-beta.d.ts +153 -0
  5. package/dist/counter-public.d.ts +153 -0
  6. package/dist/counter-untrimmed.d.ts +153 -0
  7. package/dist/{counter.js → counter.cjs} +2 -2
  8. package/dist/counter.cjs.map +1 -0
  9. package/dist/{counterFactory.js → counterFactory.cjs} +3 -3
  10. package/dist/counterFactory.cjs.map +1 -0
  11. package/dist/{index.js → index.cjs} +2 -2
  12. package/dist/index.cjs.map +1 -0
  13. package/dist/{interfaces.js → interfaces.cjs} +1 -1
  14. package/dist/interfaces.cjs.map +1 -0
  15. package/dist/{packageVersion.js → packageVersion.cjs} +2 -2
  16. package/dist/packageVersion.cjs.map +1 -0
  17. package/dist/packageVersion.d.ts +1 -1
  18. package/dist/tsdoc-metadata.json +1 -1
  19. package/lib/counter-alpha.d.ts +153 -0
  20. package/lib/counter-beta.d.ts +153 -0
  21. package/lib/counter-public.d.ts +153 -0
  22. package/lib/counter-untrimmed.d.ts +153 -0
  23. package/lib/{counter.js → counter.mjs} +2 -2
  24. package/lib/counter.mjs.map +1 -0
  25. package/lib/{counterFactory.js → counterFactory.mjs} +3 -3
  26. package/lib/counterFactory.mjs.map +1 -0
  27. package/lib/index.mjs +6 -0
  28. package/lib/index.mjs.map +1 -0
  29. package/lib/{interfaces.js → interfaces.mjs} +1 -1
  30. package/{dist/interfaces.js.map → lib/interfaces.mjs.map} +1 -1
  31. package/lib/packageVersion.d.ts +1 -1
  32. package/lib/{packageVersion.js → packageVersion.mjs} +2 -2
  33. package/lib/packageVersion.mjs.map +1 -0
  34. package/package.json +48 -19
  35. package/src/packageVersion.ts +1 -1
  36. package/tsc-multi.test.json +4 -0
  37. package/dist/counter.js.map +0 -1
  38. package/dist/counterFactory.js.map +0 -1
  39. package/dist/index.js.map +0 -1
  40. package/dist/packageVersion.js.map +0 -1
  41. package/lib/counter.js.map +0 -1
  42. package/lib/counterFactory.js.map +0 -1
  43. package/lib/index.js +0 -12
  44. package/lib/index.js.map +0 -1
  45. package/lib/interfaces.js.map +0 -1
  46. package/lib/packageVersion.js.map +0 -1
  47. package/tsconfig.esnext.json +0 -6
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counterFactory.cjs","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,2CAA0C;AAE1C,yDAA8C;AAE9C;;;;GAIG;AACH,MAAa,cAAc;IAe1B;;OAEG;IACH,IAAW,IAAI;QACd,OAAO,cAAc,CAAC,IAAI,CAAC;IAC5B,CAAC;IAED;;OAEG;IACH,IAAW,UAAU;QACpB,OAAO,cAAc,CAAC,UAAU,CAAC;IAClC,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,UAA8B;QAE9B,MAAM,OAAO,GAAG,IAAI,uBAAa,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QAC3D,MAAM,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC7B,OAAO,OAAO,CAAC;IAChB,CAAC;IAED;;OAEG;IACI,MAAM,CAAC,QAAgC,EAAE,EAAU;QACzD,MAAM,OAAO,GAAG,IAAI,uBAAa,CAAC,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;QACjE,OAAO,CAAC,eAAe,EAAE,CAAC;QAC1B,OAAO,OAAO,CAAC;IAChB,CAAC;;AAlDF,wCAmDC;AAlDA;;GAEG;AACoB,mBAAI,GAAG,2CAA2C,CAAC;AAE1E;;GAEG;AACoB,yBAAU,GAAuB;IACvD,IAAI,EAAE,cAAc,CAAC,IAAI;IACzB,qBAAqB,EAAE,KAAK;IAC5B,cAAc,EAAE,2BAAU;CAC1B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport {\n\ttype IChannelAttributes,\n\ttype IFluidDataStoreRuntime,\n\ttype IChannelServices,\n\ttype IChannelFactory,\n} from \"@fluidframework/datastore-definitions\";\nimport { SharedCounter } from \"./counter\";\nimport { type ISharedCounter } from \"./interfaces\";\nimport { pkgVersion } from \"./packageVersion\";\n\n/**\n * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.\n *\n * @sealed\n */\nexport class CounterFactory implements IChannelFactory {\n\t/**\n\t * Static value for {@link CounterFactory.\"type\"}.\n\t */\n\tpublic static readonly Type = \"https://graph.microsoft.com/types/counter\";\n\n\t/**\n\t * Static value for {@link CounterFactory.attributes}.\n\t */\n\tpublic static readonly Attributes: IChannelAttributes = {\n\t\ttype: CounterFactory.Type,\n\t\tsnapshotFormatVersion: \"0.1\",\n\t\tpackageVersion: pkgVersion,\n\t};\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.\"type\"}\n\t */\n\tpublic get type(): string {\n\t\treturn CounterFactory.Type;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.attributes}\n\t */\n\tpublic get attributes(): IChannelAttributes {\n\t\treturn CounterFactory.Attributes;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}\n\t */\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tattributes: IChannelAttributes,\n\t): Promise<ISharedCounter> {\n\t\tconst counter = new SharedCounter(id, runtime, attributes);\n\t\tawait counter.load(services);\n\t\treturn counter;\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}\n\t */\n\tpublic create(document: IFluidDataStoreRuntime, id: string): ISharedCounter {\n\t\tconst counter = new SharedCounter(id, document, this.attributes);\n\t\tcounter.initializeLocal();\n\t\treturn counter;\n\t}\n}\n"]}
@@ -11,6 +11,6 @@ exports.SharedCounter = void 0;
11
11
  *
12
12
  * @packageDocumentation
13
13
  */
14
- var counter_1 = require("./counter");
14
+ var counter_1 = require("./counter.cjs");
15
15
  Object.defineProperty(exports, "SharedCounter", { enumerable: true, get: function () { return counter_1.SharedCounter; } });
16
- //# sourceMappingURL=index.js.map
16
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;GAKG;AAEH,yCAA0C;AAAjC,wGAAA,aAAa,OAAA","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/**\n * This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.\n * A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.\n *\n * @packageDocumentation\n */\n\nexport { SharedCounter } from \"./counter\";\nexport type { ISharedCounter, ISharedCounterEvents } from \"./interfaces\";\n"]}
@@ -4,4 +4,4 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=interfaces.js.map
7
+ //# sourceMappingURL=interfaces.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.cjs","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 { type ISharedObject, type ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Events sent by {@link SharedCounter}.\n *\n * @public\n */\nexport interface ISharedCounterEvents extends ISharedObjectEvents {\n\t/**\n\t * This event is raised when the counter is incremented or decremented.\n\t *\n\t * @param event - The event name.\n\t * @param listener - An event listener.\n\t *\n\t * @eventProperty\n\t */\n\t(event: \"incremented\", listener: (incrementAmount: number, newValue: number) => void);\n}\n\n/**\n * A shared object that holds a number that can be incremented or decremented.\n *\n * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.\n *\n * @example Creating a `SharedCounter`\n *\n * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}\n * 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 * The initial value of a new `SharedCounter` is 0.\n * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before\n * attaching the Container, or before inserting it into an existing shared object.\n *\n * @example Using the `SharedCounter`\n *\n * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or\n * 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\n * {@link ISharedCounterEvents | 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 *\n * @public\n */\nexport interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {\n\t/**\n\t * The counter value.\n\t *\n\t * @remarks Must be a whole number.\n\t */\n\tvalue: number;\n\n\t/**\n\t * Increments or decrements the value.\n\t * Must only increment or decrement by a whole number value.\n\t *\n\t * @param incrementAmount - A whole number to increment or decrement by.\n\t */\n\tincrement(incrementAmount: number): void;\n}\n"]}
@@ -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 = "2.0.0-dev.7.3.0.210328";
12
- //# sourceMappingURL=packageVersion.js.map
11
+ exports.pkgVersion = "2.0.0-dev.7.3.0.212138";
12
+ //# sourceMappingURL=packageVersion.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.cjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,wBAAwB,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 = \"2.0.0-dev.7.3.0.212138\";\n"]}
@@ -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 = "2.0.0-dev.7.3.0.210328";
8
+ export declare const pkgVersion = "2.0.0-dev.7.3.0.212138";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -5,7 +5,7 @@
5
5
  "toolPackages": [
6
6
  {
7
7
  "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.38.0"
8
+ "packageVersion": "7.38.3"
9
9
  }
10
10
  ]
11
11
  }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
3
+ * A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
9
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
10
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
11
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
12
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
13
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
14
+ import { ISharedObject } from '@fluidframework/shared-object-base';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
16
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
17
+ import { SharedObject } from '@fluidframework/shared-object-base';
18
+
19
+ /**
20
+ * A shared object that holds a number that can be incremented or decremented.
21
+ *
22
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
23
+ *
24
+ * @example Creating a `SharedCounter`
25
+ *
26
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
27
+ * with a runtime and string ID:
28
+ *
29
+ * ```typescript
30
+ * const factory = SharedCounter.getFactory();
31
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
32
+ * ```
33
+ *
34
+ * The initial value of a new `SharedCounter` is 0.
35
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
36
+ * attaching the Container, or before inserting it into an existing shared object.
37
+ *
38
+ * @example Using the `SharedCounter`
39
+ *
40
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
41
+ * negative number:
42
+ *
43
+ * ```typescript
44
+ * counter.increment(10); // add 10 to the counter value
45
+ * counter.increment(-5); // subtract 5 from the counter value
46
+ * ```
47
+ *
48
+ * To observe changes to the value (including those from remote clients), register for the
49
+ * {@link ISharedCounterEvents | incremented} event:
50
+ *
51
+ * ```typescript
52
+ * counter.on("incremented", (incrementAmount, newValue) => {
53
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
54
+ * });
55
+ * ```
56
+ *
57
+ * @public
58
+ */
59
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
60
+ /**
61
+ * The counter value.
62
+ *
63
+ * @remarks Must be a whole number.
64
+ */
65
+ value: number;
66
+ /**
67
+ * Increments or decrements the value.
68
+ * Must only increment or decrement by a whole number value.
69
+ *
70
+ * @param incrementAmount - A whole number to increment or decrement by.
71
+ */
72
+ increment(incrementAmount: number): void;
73
+ }
74
+
75
+ /**
76
+ * Events sent by {@link SharedCounter}.
77
+ *
78
+ * @public
79
+ */
80
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
81
+ /**
82
+ * This event is raised when the counter is incremented or decremented.
83
+ *
84
+ * @param event - The event name.
85
+ * @param listener - An event listener.
86
+ *
87
+ * @eventProperty
88
+ */
89
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
90
+ }
91
+
92
+ /**
93
+ * {@inheritDoc ISharedCounter}
94
+ *
95
+ * @public
96
+ */
97
+ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
98
+ /**
99
+ * Create a new {@link SharedCounter}.
100
+ *
101
+ * @param runtime - The data store runtime to which the new `SharedCounter` will belong.
102
+ * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
103
+ *
104
+ * @returns newly create shared counter (but not attached yet)
105
+ */
106
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
107
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
108
+ /**
109
+ * Get a factory for {@link SharedCounter} to register with the data store.
110
+ *
111
+ * @returns a factory that creates and load SharedCounter
112
+ */
113
+ static getFactory(): IChannelFactory;
114
+ private _value;
115
+ /**
116
+ * {@inheritDoc ISharedCounter.value}
117
+ */
118
+ get value(): number;
119
+ /**
120
+ * {@inheritDoc ISharedCounter.increment}
121
+ */
122
+ increment(incrementAmount: number): void;
123
+ private incrementCore;
124
+ /**
125
+ * Create a summary for the counter.
126
+ *
127
+ * @returns The summary of the current state of the counter.
128
+ */
129
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
130
+ /**
131
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
132
+ */
133
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
134
+ /**
135
+ * Called when the object has disconnected from the delta stream.
136
+ */
137
+ protected onDisconnect(): void;
138
+ /**
139
+ * Process a counter operation (op).
140
+ *
141
+ * @param message - The message to prepare.
142
+ * @param local - Whether or not the message was sent by the local client.
143
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
144
+ * For messages from a remote client, this will be `undefined`.
145
+ */
146
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
147
+ /**
148
+ * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
149
+ */
150
+ protected applyStashedOp(op: unknown): void;
151
+ }
152
+
153
+ export { }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
3
+ * A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
9
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
10
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
11
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
12
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
13
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
14
+ import { ISharedObject } from '@fluidframework/shared-object-base';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
16
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
17
+ import { SharedObject } from '@fluidframework/shared-object-base';
18
+
19
+ /**
20
+ * A shared object that holds a number that can be incremented or decremented.
21
+ *
22
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
23
+ *
24
+ * @example Creating a `SharedCounter`
25
+ *
26
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
27
+ * with a runtime and string ID:
28
+ *
29
+ * ```typescript
30
+ * const factory = SharedCounter.getFactory();
31
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
32
+ * ```
33
+ *
34
+ * The initial value of a new `SharedCounter` is 0.
35
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
36
+ * attaching the Container, or before inserting it into an existing shared object.
37
+ *
38
+ * @example Using the `SharedCounter`
39
+ *
40
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
41
+ * negative number:
42
+ *
43
+ * ```typescript
44
+ * counter.increment(10); // add 10 to the counter value
45
+ * counter.increment(-5); // subtract 5 from the counter value
46
+ * ```
47
+ *
48
+ * To observe changes to the value (including those from remote clients), register for the
49
+ * {@link ISharedCounterEvents | incremented} event:
50
+ *
51
+ * ```typescript
52
+ * counter.on("incremented", (incrementAmount, newValue) => {
53
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
54
+ * });
55
+ * ```
56
+ *
57
+ * @public
58
+ */
59
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
60
+ /**
61
+ * The counter value.
62
+ *
63
+ * @remarks Must be a whole number.
64
+ */
65
+ value: number;
66
+ /**
67
+ * Increments or decrements the value.
68
+ * Must only increment or decrement by a whole number value.
69
+ *
70
+ * @param incrementAmount - A whole number to increment or decrement by.
71
+ */
72
+ increment(incrementAmount: number): void;
73
+ }
74
+
75
+ /**
76
+ * Events sent by {@link SharedCounter}.
77
+ *
78
+ * @public
79
+ */
80
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
81
+ /**
82
+ * This event is raised when the counter is incremented or decremented.
83
+ *
84
+ * @param event - The event name.
85
+ * @param listener - An event listener.
86
+ *
87
+ * @eventProperty
88
+ */
89
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
90
+ }
91
+
92
+ /**
93
+ * {@inheritDoc ISharedCounter}
94
+ *
95
+ * @public
96
+ */
97
+ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
98
+ /**
99
+ * Create a new {@link SharedCounter}.
100
+ *
101
+ * @param runtime - The data store runtime to which the new `SharedCounter` will belong.
102
+ * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
103
+ *
104
+ * @returns newly create shared counter (but not attached yet)
105
+ */
106
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
107
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
108
+ /**
109
+ * Get a factory for {@link SharedCounter} to register with the data store.
110
+ *
111
+ * @returns a factory that creates and load SharedCounter
112
+ */
113
+ static getFactory(): IChannelFactory;
114
+ private _value;
115
+ /**
116
+ * {@inheritDoc ISharedCounter.value}
117
+ */
118
+ get value(): number;
119
+ /**
120
+ * {@inheritDoc ISharedCounter.increment}
121
+ */
122
+ increment(incrementAmount: number): void;
123
+ private incrementCore;
124
+ /**
125
+ * Create a summary for the counter.
126
+ *
127
+ * @returns The summary of the current state of the counter.
128
+ */
129
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
130
+ /**
131
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
132
+ */
133
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
134
+ /**
135
+ * Called when the object has disconnected from the delta stream.
136
+ */
137
+ protected onDisconnect(): void;
138
+ /**
139
+ * Process a counter operation (op).
140
+ *
141
+ * @param message - The message to prepare.
142
+ * @param local - Whether or not the message was sent by the local client.
143
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
144
+ * For messages from a remote client, this will be `undefined`.
145
+ */
146
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
147
+ /**
148
+ * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
149
+ */
150
+ protected applyStashedOp(op: unknown): void;
151
+ }
152
+
153
+ export { }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
3
+ * A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
9
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
10
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
11
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
12
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
13
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
14
+ import { ISharedObject } from '@fluidframework/shared-object-base';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
16
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
17
+ import { SharedObject } from '@fluidframework/shared-object-base';
18
+
19
+ /**
20
+ * A shared object that holds a number that can be incremented or decremented.
21
+ *
22
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
23
+ *
24
+ * @example Creating a `SharedCounter`
25
+ *
26
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
27
+ * with a runtime and string ID:
28
+ *
29
+ * ```typescript
30
+ * const factory = SharedCounter.getFactory();
31
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
32
+ * ```
33
+ *
34
+ * The initial value of a new `SharedCounter` is 0.
35
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
36
+ * attaching the Container, or before inserting it into an existing shared object.
37
+ *
38
+ * @example Using the `SharedCounter`
39
+ *
40
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
41
+ * negative number:
42
+ *
43
+ * ```typescript
44
+ * counter.increment(10); // add 10 to the counter value
45
+ * counter.increment(-5); // subtract 5 from the counter value
46
+ * ```
47
+ *
48
+ * To observe changes to the value (including those from remote clients), register for the
49
+ * {@link ISharedCounterEvents | incremented} event:
50
+ *
51
+ * ```typescript
52
+ * counter.on("incremented", (incrementAmount, newValue) => {
53
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
54
+ * });
55
+ * ```
56
+ *
57
+ * @public
58
+ */
59
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
60
+ /**
61
+ * The counter value.
62
+ *
63
+ * @remarks Must be a whole number.
64
+ */
65
+ value: number;
66
+ /**
67
+ * Increments or decrements the value.
68
+ * Must only increment or decrement by a whole number value.
69
+ *
70
+ * @param incrementAmount - A whole number to increment or decrement by.
71
+ */
72
+ increment(incrementAmount: number): void;
73
+ }
74
+
75
+ /**
76
+ * Events sent by {@link SharedCounter}.
77
+ *
78
+ * @public
79
+ */
80
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
81
+ /**
82
+ * This event is raised when the counter is incremented or decremented.
83
+ *
84
+ * @param event - The event name.
85
+ * @param listener - An event listener.
86
+ *
87
+ * @eventProperty
88
+ */
89
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
90
+ }
91
+
92
+ /**
93
+ * {@inheritDoc ISharedCounter}
94
+ *
95
+ * @public
96
+ */
97
+ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
98
+ /**
99
+ * Create a new {@link SharedCounter}.
100
+ *
101
+ * @param runtime - The data store runtime to which the new `SharedCounter` will belong.
102
+ * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
103
+ *
104
+ * @returns newly create shared counter (but not attached yet)
105
+ */
106
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
107
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
108
+ /**
109
+ * Get a factory for {@link SharedCounter} to register with the data store.
110
+ *
111
+ * @returns a factory that creates and load SharedCounter
112
+ */
113
+ static getFactory(): IChannelFactory;
114
+ private _value;
115
+ /**
116
+ * {@inheritDoc ISharedCounter.value}
117
+ */
118
+ get value(): number;
119
+ /**
120
+ * {@inheritDoc ISharedCounter.increment}
121
+ */
122
+ increment(incrementAmount: number): void;
123
+ private incrementCore;
124
+ /**
125
+ * Create a summary for the counter.
126
+ *
127
+ * @returns The summary of the current state of the counter.
128
+ */
129
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
130
+ /**
131
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
132
+ */
133
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
134
+ /**
135
+ * Called when the object has disconnected from the delta stream.
136
+ */
137
+ protected onDisconnect(): void;
138
+ /**
139
+ * Process a counter operation (op).
140
+ *
141
+ * @param message - The message to prepare.
142
+ * @param local - Whether or not the message was sent by the local client.
143
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
144
+ * For messages from a remote client, this will be `undefined`.
145
+ */
146
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
147
+ /**
148
+ * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
149
+ */
150
+ protected applyStashedOp(op: unknown): void;
151
+ }
152
+
153
+ export { }
@@ -0,0 +1,153 @@
1
+ /**
2
+ * This library contains the {@link ISharedCounter | SharedCounter} distributed data structure.
3
+ * A `SharedCounter` is a shared object which holds a whole number that can be incremented or decremented.
4
+ *
5
+ * @packageDocumentation
6
+ */
7
+
8
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
9
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
10
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
11
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
12
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
13
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
14
+ import { ISharedObject } from '@fluidframework/shared-object-base';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
16
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
17
+ import { SharedObject } from '@fluidframework/shared-object-base';
18
+
19
+ /**
20
+ * A shared object that holds a number that can be incremented or decremented.
21
+ *
22
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
23
+ *
24
+ * @example Creating a `SharedCounter`
25
+ *
26
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
27
+ * with a runtime and string ID:
28
+ *
29
+ * ```typescript
30
+ * const factory = SharedCounter.getFactory();
31
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
32
+ * ```
33
+ *
34
+ * The initial value of a new `SharedCounter` is 0.
35
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
36
+ * attaching the Container, or before inserting it into an existing shared object.
37
+ *
38
+ * @example Using the `SharedCounter`
39
+ *
40
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
41
+ * negative number:
42
+ *
43
+ * ```typescript
44
+ * counter.increment(10); // add 10 to the counter value
45
+ * counter.increment(-5); // subtract 5 from the counter value
46
+ * ```
47
+ *
48
+ * To observe changes to the value (including those from remote clients), register for the
49
+ * {@link ISharedCounterEvents | incremented} event:
50
+ *
51
+ * ```typescript
52
+ * counter.on("incremented", (incrementAmount, newValue) => {
53
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
54
+ * });
55
+ * ```
56
+ *
57
+ * @public
58
+ */
59
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
60
+ /**
61
+ * The counter value.
62
+ *
63
+ * @remarks Must be a whole number.
64
+ */
65
+ value: number;
66
+ /**
67
+ * Increments or decrements the value.
68
+ * Must only increment or decrement by a whole number value.
69
+ *
70
+ * @param incrementAmount - A whole number to increment or decrement by.
71
+ */
72
+ increment(incrementAmount: number): void;
73
+ }
74
+
75
+ /**
76
+ * Events sent by {@link SharedCounter}.
77
+ *
78
+ * @public
79
+ */
80
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
81
+ /**
82
+ * This event is raised when the counter is incremented or decremented.
83
+ *
84
+ * @param event - The event name.
85
+ * @param listener - An event listener.
86
+ *
87
+ * @eventProperty
88
+ */
89
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
90
+ }
91
+
92
+ /**
93
+ * {@inheritDoc ISharedCounter}
94
+ *
95
+ * @public
96
+ */
97
+ export declare class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
98
+ /**
99
+ * Create a new {@link SharedCounter}.
100
+ *
101
+ * @param runtime - The data store runtime to which the new `SharedCounter` will belong.
102
+ * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.
103
+ *
104
+ * @returns newly create shared counter (but not attached yet)
105
+ */
106
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
107
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
108
+ /**
109
+ * Get a factory for {@link SharedCounter} to register with the data store.
110
+ *
111
+ * @returns a factory that creates and load SharedCounter
112
+ */
113
+ static getFactory(): IChannelFactory;
114
+ private _value;
115
+ /**
116
+ * {@inheritDoc ISharedCounter.value}
117
+ */
118
+ get value(): number;
119
+ /**
120
+ * {@inheritDoc ISharedCounter.increment}
121
+ */
122
+ increment(incrementAmount: number): void;
123
+ private incrementCore;
124
+ /**
125
+ * Create a summary for the counter.
126
+ *
127
+ * @returns The summary of the current state of the counter.
128
+ */
129
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
130
+ /**
131
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
132
+ */
133
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
134
+ /**
135
+ * Called when the object has disconnected from the delta stream.
136
+ */
137
+ protected onDisconnect(): void;
138
+ /**
139
+ * Process a counter operation (op).
140
+ *
141
+ * @param message - The message to prepare.
142
+ * @param local - Whether or not the message was sent by the local client.
143
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
144
+ * For messages from a remote client, this will be `undefined`.
145
+ */
146
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
147
+ /**
148
+ * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
149
+ */
150
+ protected applyStashedOp(op: unknown): void;
151
+ }
152
+
153
+ export { }