@fluidframework/counter 2.0.0-dev.6.4.0.192049 → 2.0.0-dev.7.2.0.204906

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 (46) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/api-extractor.json +10 -1
  3. package/api-report/counter.api.md +49 -0
  4. package/dist/counter-alpha.d.ts +131 -0
  5. package/dist/counter-beta.d.ts +131 -0
  6. package/dist/counter-public.d.ts +131 -0
  7. package/dist/counter-untrimmed.d.ts +162 -0
  8. package/dist/counter.d.ts +5 -5
  9. package/dist/counter.d.ts.map +1 -1
  10. package/dist/counter.js +9 -6
  11. package/dist/counter.js.map +1 -1
  12. package/dist/counterFactory.d.ts +2 -2
  13. package/dist/counterFactory.d.ts.map +1 -1
  14. package/dist/counterFactory.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/interfaces.d.ts +1 -1
  19. package/dist/interfaces.d.ts.map +1 -1
  20. package/dist/interfaces.js.map +1 -1
  21. package/dist/packageVersion.d.ts +1 -1
  22. package/dist/packageVersion.js +1 -1
  23. package/dist/packageVersion.js.map +1 -1
  24. package/dist/tsdoc-metadata.json +1 -1
  25. package/lib/counter.d.ts +5 -5
  26. package/lib/counter.d.ts.map +1 -1
  27. package/lib/counter.js +9 -6
  28. package/lib/counter.js.map +1 -1
  29. package/lib/counterFactory.d.ts +2 -2
  30. package/lib/counterFactory.d.ts.map +1 -1
  31. package/lib/counterFactory.js.map +1 -1
  32. package/lib/index.d.ts +1 -1
  33. package/lib/index.d.ts.map +1 -1
  34. package/lib/index.js.map +1 -1
  35. package/lib/interfaces.d.ts +1 -1
  36. package/lib/interfaces.d.ts.map +1 -1
  37. package/lib/interfaces.js.map +1 -1
  38. package/lib/packageVersion.d.ts +1 -1
  39. package/lib/packageVersion.js +1 -1
  40. package/lib/packageVersion.js.map +1 -1
  41. package/package.json +21 -22
  42. package/src/counter.ts +14 -10
  43. package/src/counterFactory.ts +5 -5
  44. package/src/index.ts +1 -1
  45. package/src/interfaces.ts +1 -1
  46. package/src/packageVersion.ts +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,57 @@
1
1
  # @fluidframework/counter
2
2
 
3
+ ## 2.0.0-internal.7.1.0
4
+
5
+ Dependency updates only.
6
+
7
+ ## 2.0.0-internal.7.0.0
8
+
9
+ ### Major Changes
10
+
11
+ - Dependencies on @fluidframework/protocol-definitions package updated to 3.0.0 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
12
+
13
+ This included the following changes from the protocol-definitions release:
14
+
15
+ - Updating signal interfaces for some planned improvements. The intention is split the interface between signals
16
+ submitted by clients to the server and the resulting signals sent from the server to clients.
17
+ - A new optional type member is available on the ISignalMessage interface and a new ISentSignalMessage interface has
18
+ been added, which will be the typing for signals sent from the client to the server. Both extend a new
19
+ ISignalMessageBase interface that contains common members.
20
+ - The @fluidframework/common-definitions package dependency has been updated to version 1.0.0.
21
+
22
+ - Server upgrade: dependencies on Fluid server packages updated to 2.0.1 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
23
+
24
+ Dependencies on the following Fluid server package have been updated to version 2.0.1:
25
+
26
+ - @fluidframework/gitresources: 2.0.1
27
+ - @fluidframework/server-kafka-orderer: 2.0.1
28
+ - @fluidframework/server-lambdas: 2.0.1
29
+ - @fluidframework/server-lambdas-driver: 2.0.1
30
+ - @fluidframework/server-local-server: 2.0.1
31
+ - @fluidframework/server-memory-orderer: 2.0.1
32
+ - @fluidframework/protocol-base: 2.0.1
33
+ - @fluidframework/server-routerlicious: 2.0.1
34
+ - @fluidframework/server-routerlicious-base: 2.0.1
35
+ - @fluidframework/server-services: 2.0.1
36
+ - @fluidframework/server-services-client: 2.0.1
37
+ - @fluidframework/server-services-core: 2.0.1
38
+ - @fluidframework/server-services-ordering-kafkanode: 2.0.1
39
+ - @fluidframework/server-services-ordering-rdkafka: 2.0.1
40
+ - @fluidframework/server-services-ordering-zookeeper: 2.0.1
41
+ - @fluidframework/server-services-shared: 2.0.1
42
+ - @fluidframework/server-services-telemetry: 2.0.1
43
+ - @fluidframework/server-services-utils: 2.0.1
44
+ - @fluidframework/server-test-utils: 2.0.1
45
+ - tinylicious: 2.0.1
46
+
47
+ - Minimum TypeScript version now 5.1.6 [871b3493dd](https://github.com/microsoft/FluidFramework/commits/871b3493dd0d7ea3a89be64998ceb6cb9021a04e)
48
+
49
+ The minimum supported TypeScript version for Fluid 2.0 clients is now 5.1.6.
50
+
51
+ ## 2.0.0-internal.6.4.0
52
+
53
+ Dependency updates only.
54
+
3
55
  ## 2.0.0-internal.6.3.0
4
56
 
5
57
  Dependency updates only.
@@ -1,4 +1,13 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "@fluidframework/build-common/api-extractor-common-strict.json"
3
+ "extends": "@fluidframework/build-common/api-extractor-base.json",
4
+
5
+ // TODO: Fix violations and remove these rule overrides
6
+ "messages": {
7
+ "extractorMessageReporting": {
8
+ "ae-forgotten-export": {
9
+ "logLevel": "none"
10
+ }
11
+ }
12
+ }
4
13
  }
@@ -0,0 +1,49 @@
1
+ ## API Report File for "@fluidframework/counter"
2
+
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ ```ts
6
+
7
+ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
8
+ import { IChannelFactory } from '@fluidframework/datastore-definitions';
9
+ import { IChannelStorageService } from '@fluidframework/datastore-definitions';
10
+ import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
11
+ import { IFluidSerializer } from '@fluidframework/shared-object-base';
12
+ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
13
+ import { ISharedObject } from '@fluidframework/shared-object-base';
14
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
15
+ import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
16
+ import { SharedObject } from '@fluidframework/shared-object-base';
17
+
18
+ // @public
19
+ export interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
20
+ increment(incrementAmount: number): void;
21
+ value: number;
22
+ }
23
+
24
+ // @public
25
+ export interface ISharedCounterEvents extends ISharedObjectEvents {
26
+ // @eventProperty
27
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
28
+ }
29
+
30
+ // @public
31
+ export class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {
32
+ constructor(id: string, runtime: IFluidDataStoreRuntime, attributes: IChannelAttributes);
33
+ // @internal (undocumented)
34
+ protected applyStashedOp(op: unknown): void;
35
+ static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter;
36
+ static getFactory(): IChannelFactory;
37
+ increment(incrementAmount: number): void;
38
+ // @internal (undocumented)
39
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
40
+ // @internal
41
+ protected onDisconnect(): void;
42
+ // @internal
43
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
44
+ // @internal
45
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
46
+ get value(): number;
47
+ }
48
+
49
+ ```
@@ -0,0 +1,131 @@
1
+ /**
2
+ * This library contains the {@link 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
+ * {@link SharedCounter} interface.
21
+ *
22
+ * @public
23
+ */
24
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
25
+ /**
26
+ * The counter value.
27
+ *
28
+ * @remarks Must be a whole number.
29
+ */
30
+ value: number;
31
+ /**
32
+ * Increments or decrements the value.
33
+ * Must only increment or decrement by a whole number value.
34
+ *
35
+ * @param incrementAmount - A whole number to increment or decrement by.
36
+ */
37
+ increment(incrementAmount: number): void;
38
+ }
39
+
40
+ /**
41
+ * Events sent by {@link SharedCounter}.
42
+ *
43
+ * @public
44
+ */
45
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
46
+ /**
47
+ * This event is raised when the counter is incremented or decremented.
48
+ *
49
+ * @param event - The event name.
50
+ * @param listener - An event listener.
51
+ *
52
+ * @eventProperty
53
+ */
54
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
55
+ }
56
+
57
+ /**
58
+ * A shared object that holds a number that can be incremented or decremented.
59
+ *
60
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
61
+ *
62
+ * @example Creating a `SharedCounter`
63
+ *
64
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
65
+ * with a runtime and string ID:
66
+ *
67
+ * ```typescript
68
+ * const factory = SharedCounter.getFactory();
69
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
70
+ * ```
71
+ *
72
+ * The initial value of a new `SharedCounter` is 0.
73
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
74
+ * attaching the Container, or before inserting it into an existing shared object.
75
+ *
76
+ * @example Using the `SharedCounter`
77
+ *
78
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
79
+ * negative number:
80
+ *
81
+ * ```typescript
82
+ * counter.increment(10); // add 10 to the counter value
83
+ * counter.increment(-5); // subtract 5 from the counter value
84
+ * ```
85
+ *
86
+ * To observe changes to the value (including those from remote clients), register for the
87
+ * {@link ISharedCounterEvents | incremented} event:
88
+ *
89
+ * ```typescript
90
+ * counter.on("incremented", (incrementAmount, newValue) => {
91
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
92
+ * });
93
+ * ```
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
+ /* Excluded from this release type: summarizeCore */
125
+ /* Excluded from this release type: loadCore */
126
+ /* Excluded from this release type: onDisconnect */
127
+ /* Excluded from this release type: processCore */
128
+ /* Excluded from this release type: applyStashedOp */
129
+ }
130
+
131
+ export { }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * This library contains the {@link 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
+ * {@link SharedCounter} interface.
21
+ *
22
+ * @public
23
+ */
24
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
25
+ /**
26
+ * The counter value.
27
+ *
28
+ * @remarks Must be a whole number.
29
+ */
30
+ value: number;
31
+ /**
32
+ * Increments or decrements the value.
33
+ * Must only increment or decrement by a whole number value.
34
+ *
35
+ * @param incrementAmount - A whole number to increment or decrement by.
36
+ */
37
+ increment(incrementAmount: number): void;
38
+ }
39
+
40
+ /**
41
+ * Events sent by {@link SharedCounter}.
42
+ *
43
+ * @public
44
+ */
45
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
46
+ /**
47
+ * This event is raised when the counter is incremented or decremented.
48
+ *
49
+ * @param event - The event name.
50
+ * @param listener - An event listener.
51
+ *
52
+ * @eventProperty
53
+ */
54
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
55
+ }
56
+
57
+ /**
58
+ * A shared object that holds a number that can be incremented or decremented.
59
+ *
60
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
61
+ *
62
+ * @example Creating a `SharedCounter`
63
+ *
64
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
65
+ * with a runtime and string ID:
66
+ *
67
+ * ```typescript
68
+ * const factory = SharedCounter.getFactory();
69
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
70
+ * ```
71
+ *
72
+ * The initial value of a new `SharedCounter` is 0.
73
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
74
+ * attaching the Container, or before inserting it into an existing shared object.
75
+ *
76
+ * @example Using the `SharedCounter`
77
+ *
78
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
79
+ * negative number:
80
+ *
81
+ * ```typescript
82
+ * counter.increment(10); // add 10 to the counter value
83
+ * counter.increment(-5); // subtract 5 from the counter value
84
+ * ```
85
+ *
86
+ * To observe changes to the value (including those from remote clients), register for the
87
+ * {@link ISharedCounterEvents | incremented} event:
88
+ *
89
+ * ```typescript
90
+ * counter.on("incremented", (incrementAmount, newValue) => {
91
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
92
+ * });
93
+ * ```
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
+ /* Excluded from this release type: summarizeCore */
125
+ /* Excluded from this release type: loadCore */
126
+ /* Excluded from this release type: onDisconnect */
127
+ /* Excluded from this release type: processCore */
128
+ /* Excluded from this release type: applyStashedOp */
129
+ }
130
+
131
+ export { }
@@ -0,0 +1,131 @@
1
+ /**
2
+ * This library contains the {@link 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
+ * {@link SharedCounter} interface.
21
+ *
22
+ * @public
23
+ */
24
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
25
+ /**
26
+ * The counter value.
27
+ *
28
+ * @remarks Must be a whole number.
29
+ */
30
+ value: number;
31
+ /**
32
+ * Increments or decrements the value.
33
+ * Must only increment or decrement by a whole number value.
34
+ *
35
+ * @param incrementAmount - A whole number to increment or decrement by.
36
+ */
37
+ increment(incrementAmount: number): void;
38
+ }
39
+
40
+ /**
41
+ * Events sent by {@link SharedCounter}.
42
+ *
43
+ * @public
44
+ */
45
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
46
+ /**
47
+ * This event is raised when the counter is incremented or decremented.
48
+ *
49
+ * @param event - The event name.
50
+ * @param listener - An event listener.
51
+ *
52
+ * @eventProperty
53
+ */
54
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
55
+ }
56
+
57
+ /**
58
+ * A shared object that holds a number that can be incremented or decremented.
59
+ *
60
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
61
+ *
62
+ * @example Creating a `SharedCounter`
63
+ *
64
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
65
+ * with a runtime and string ID:
66
+ *
67
+ * ```typescript
68
+ * const factory = SharedCounter.getFactory();
69
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
70
+ * ```
71
+ *
72
+ * The initial value of a new `SharedCounter` is 0.
73
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
74
+ * attaching the Container, or before inserting it into an existing shared object.
75
+ *
76
+ * @example Using the `SharedCounter`
77
+ *
78
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
79
+ * negative number:
80
+ *
81
+ * ```typescript
82
+ * counter.increment(10); // add 10 to the counter value
83
+ * counter.increment(-5); // subtract 5 from the counter value
84
+ * ```
85
+ *
86
+ * To observe changes to the value (including those from remote clients), register for the
87
+ * {@link ISharedCounterEvents | incremented} event:
88
+ *
89
+ * ```typescript
90
+ * counter.on("incremented", (incrementAmount, newValue) => {
91
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
92
+ * });
93
+ * ```
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
+ /* Excluded from this release type: summarizeCore */
125
+ /* Excluded from this release type: loadCore */
126
+ /* Excluded from this release type: onDisconnect */
127
+ /* Excluded from this release type: processCore */
128
+ /* Excluded from this release type: applyStashedOp */
129
+ }
130
+
131
+ export { }
@@ -0,0 +1,162 @@
1
+ /**
2
+ * This library contains the {@link 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
+ * {@link SharedCounter} interface.
21
+ *
22
+ * @public
23
+ */
24
+ export declare interface ISharedCounter extends ISharedObject<ISharedCounterEvents> {
25
+ /**
26
+ * The counter value.
27
+ *
28
+ * @remarks Must be a whole number.
29
+ */
30
+ value: number;
31
+ /**
32
+ * Increments or decrements the value.
33
+ * Must only increment or decrement by a whole number value.
34
+ *
35
+ * @param incrementAmount - A whole number to increment or decrement by.
36
+ */
37
+ increment(incrementAmount: number): void;
38
+ }
39
+
40
+ /**
41
+ * Events sent by {@link SharedCounter}.
42
+ *
43
+ * @public
44
+ */
45
+ export declare interface ISharedCounterEvents extends ISharedObjectEvents {
46
+ /**
47
+ * This event is raised when the counter is incremented or decremented.
48
+ *
49
+ * @param event - The event name.
50
+ * @param listener - An event listener.
51
+ *
52
+ * @eventProperty
53
+ */
54
+ (event: "incremented", listener: (incrementAmount: number, newValue: number) => void): any;
55
+ }
56
+
57
+ /**
58
+ * A shared object that holds a number that can be incremented or decremented.
59
+ *
60
+ * @remarks Note that `SharedCounter` only operates on integer values. This is validated at runtime.
61
+ *
62
+ * @example Creating a `SharedCounter`
63
+ *
64
+ * First, get the factory and call {@link @fluidframework/datastore-definitions#IChannelFactory.create}
65
+ * with a runtime and string ID:
66
+ *
67
+ * ```typescript
68
+ * const factory = SharedCounter.getFactory();
69
+ * const counter = factory.create(this.runtime, id) as SharedCounter;
70
+ * ```
71
+ *
72
+ * The initial value of a new `SharedCounter` is 0.
73
+ * If you wish to initialize the counter to a different value, you may call {@link SharedCounter.increment} before
74
+ * attaching the Container, or before inserting it into an existing shared object.
75
+ *
76
+ * @example Using the `SharedCounter`
77
+ *
78
+ * Once created, you can call {@link SharedCounter.increment} to modify the value with either a positive or
79
+ * negative number:
80
+ *
81
+ * ```typescript
82
+ * counter.increment(10); // add 10 to the counter value
83
+ * counter.increment(-5); // subtract 5 from the counter value
84
+ * ```
85
+ *
86
+ * To observe changes to the value (including those from remote clients), register for the
87
+ * {@link ISharedCounterEvents | incremented} event:
88
+ *
89
+ * ```typescript
90
+ * counter.on("incremented", (incrementAmount, newValue) => {
91
+ * console.log(`The counter incremented by ${incrementAmount} and now has a value of ${newValue}`);
92
+ * });
93
+ * ```
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
+ * @internal
130
+ */
131
+ protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
132
+ /**
133
+ * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
134
+ *
135
+ * @internal
136
+ */
137
+ protected loadCore(storage: IChannelStorageService): Promise<void>;
138
+ /**
139
+ * Called when the object has disconnected from the delta stream.
140
+ *
141
+ * @internal
142
+ */
143
+ protected onDisconnect(): void;
144
+ /**
145
+ * Process a counter operation (op).
146
+ *
147
+ * @param message - The message to prepare.
148
+ * @param local - Whether or not the message was sent by the local client.
149
+ * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.
150
+ * For messages from a remote client, this will be `undefined`.
151
+ *
152
+ * @internal
153
+ */
154
+ protected processCore(message: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
155
+ /**
156
+ * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
157
+ * @internal
158
+ */
159
+ protected applyStashedOp(op: unknown): void;
160
+ }
161
+
162
+ export { }