@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # @fluidframework/counter
2
2
 
3
+ ## 2.0.0-internal.7.3.0
4
+
5
+ Dependency updates only.
6
+
3
7
  ## 2.0.0-internal.7.2.0
4
8
 
5
9
  Dependency updates only.
@@ -1,4 +1,7 @@
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-base.json"
3
+ "extends": "@fluidframework/build-common/api-extractor-base.json",
4
+ "dtsRollup": {
5
+ "enabled": true
6
+ }
4
7
  }
@@ -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 { }
@@ -9,7 +9,7 @@ const core_utils_1 = require("@fluidframework/core-utils");
9
9
  const protocol_definitions_1 = require("@fluidframework/protocol-definitions");
10
10
  const driver_utils_1 = require("@fluidframework/driver-utils");
11
11
  const shared_object_base_1 = require("@fluidframework/shared-object-base");
12
- const counterFactory_1 = require("./counterFactory");
12
+ const counterFactory_1 = require("./counterFactory.cjs");
13
13
  const snapshotFileName = "header";
14
14
  /**
15
15
  * {@inheritDoc ISharedCounter}
@@ -125,4 +125,4 @@ class SharedCounter extends shared_object_base_1.SharedObject {
125
125
  }
126
126
  }
127
127
  exports.SharedCounter = SharedCounter;
128
- //# sourceMappingURL=counter.js.map
128
+ //# sourceMappingURL=counter.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counter.cjs","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":"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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { type ISequencedDocumentMessage, MessageType } from \"@fluidframework/protocol-definitions\";\nimport {\n\ttype IFluidDataStoreRuntime,\n\ttype IChannelStorageService,\n\ttype IChannelFactory,\n\ttype IChannelAttributes,\n} from \"@fluidframework/datastore-definitions\";\nimport { readAndParse } from \"@fluidframework/driver-utils\";\nimport { type ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions\";\nimport {\n\tcreateSingleBlobSummary,\n\ttype IFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base\";\nimport { CounterFactory } from \"./counterFactory\";\nimport { type ISharedCounter, type ISharedCounterEvents } from \"./interfaces\";\n\n/**\n * Describes the operation (op) format for incrementing the {@link SharedCounter}.\n */\ninterface IIncrementOperation {\n\ttype: \"increment\";\n\tincrementAmount: number;\n}\n\n/**\n * @remarks Used in snapshotting.\n */\ninterface ICounterSnapshotFormat {\n\t/**\n\t * The value of the counter.\n\t */\n\tvalue: number;\n}\n\nconst snapshotFileName = \"header\";\n\n/**\n * {@inheritDoc ISharedCounter}\n *\n * @public\n */\nexport class SharedCounter extends SharedObject<ISharedCounterEvents> implements ISharedCounter {\n\t/**\n\t * Create a new {@link SharedCounter}.\n\t *\n\t * @param runtime - The data store runtime to which the new `SharedCounter` will belong.\n\t * @param id - Optional name of the `SharedCounter`. If not provided, one will be generated.\n\t *\n\t * @returns newly create shared counter (but not attached yet)\n\t */\n\tpublic static create(runtime: IFluidDataStoreRuntime, id?: string): SharedCounter {\n\t\treturn runtime.createChannel(id, CounterFactory.Type) as SharedCounter;\n\t}\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t) {\n\t\tsuper(id, runtime, attributes, \"fluid_counter_\");\n\t}\n\n\t/**\n\t * Get a factory for {@link SharedCounter} to register with the data store.\n\t *\n\t * @returns a factory that creates and load SharedCounter\n\t */\n\tpublic static getFactory(): IChannelFactory {\n\t\treturn new CounterFactory();\n\t}\n\n\tprivate _value: number = 0;\n\n\t/**\n\t * {@inheritDoc ISharedCounter.value}\n\t */\n\tpublic get value(): number {\n\t\treturn this._value;\n\t}\n\n\t/**\n\t * {@inheritDoc ISharedCounter.increment}\n\t */\n\tpublic increment(incrementAmount: number): void {\n\t\t// Incrementing by floating point numbers will be eventually inconsistent, since the order in which the\n\t\t// increments are applied affects the result. A more-robust solution would be required to support this.\n\t\tif (incrementAmount % 1 !== 0) {\n\t\t\tthrow new Error(\"Must increment by a whole number\");\n\t\t}\n\n\t\tconst op: IIncrementOperation = {\n\t\t\ttype: \"increment\",\n\t\t\tincrementAmount,\n\t\t};\n\n\t\tthis.incrementCore(incrementAmount);\n\t\tthis.submitLocalMessage(op);\n\t}\n\n\tprivate incrementCore(incrementAmount: number): void {\n\t\tthis._value += incrementAmount;\n\t\tthis.emit(\"incremented\", incrementAmount, this._value);\n\t}\n\n\t/**\n\t * Create a summary for the counter.\n\t *\n\t * @returns The summary of the current state of the counter.\n\t */\n\tprotected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats {\n\t\t// Get a serializable form of data\n\t\tconst content: ICounterSnapshotFormat = {\n\t\t\tvalue: this.value,\n\t\t};\n\n\t\t// And then construct the summary for it\n\t\treturn createSingleBlobSummary(snapshotFileName, JSON.stringify(content));\n\t}\n\n\t/**\n\t * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}\n\t */\n\tprotected async loadCore(storage: IChannelStorageService): Promise<void> {\n\t\tconst content = await readAndParse<ICounterSnapshotFormat>(storage, snapshotFileName);\n\n\t\tthis._value = content.value;\n\t}\n\n\t/**\n\t * Called when the object has disconnected from the delta stream.\n\t */\n\tprotected onDisconnect(): void {}\n\n\t/**\n\t * Process a counter operation (op).\n\t *\n\t * @param message - The message to prepare.\n\t * @param local - Whether or not the message was sent by the local client.\n\t * @param localOpMetadata - For local client messages, this is the metadata that was submitted with the message.\n\t * For messages from a remote client, this will be `undefined`.\n\t */\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-enum-comparison\n\t\tif (message.type === MessageType.Operation && !local) {\n\t\t\tconst op = message.contents as IIncrementOperation;\n\n\t\t\tswitch (op.type) {\n\t\t\t\tcase \"increment\": {\n\t\t\t\t\tthis.incrementCore(op.incrementAmount);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(\"Unknown operation\");\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * {@inheritdoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}\n\t */\n\tprotected applyStashedOp(op: unknown): void {\n\t\tconst counterOp = op as IIncrementOperation;\n\n\t\t// TODO: Clean up error code linter violations repo-wide.\n\n\t\t// eslint-disable-next-line unicorn/numeric-separators-style\n\t\tassert(counterOp.type === \"increment\", 0x3ec /* Op type is not increment */);\n\n\t\tthis.incrementCore(counterOp.incrementAmount);\n\t}\n}\n"]}
@@ -5,8 +5,8 @@
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.CounterFactory = void 0;
8
- const counter_1 = require("./counter");
9
- const packageVersion_1 = require("./packageVersion");
8
+ const counter_1 = require("./counter.cjs");
9
+ const packageVersion_1 = require("./packageVersion.cjs");
10
10
  /**
11
11
  * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedCounter}.
12
12
  *
@@ -55,4 +55,4 @@ CounterFactory.Attributes = {
55
55
  snapshotFormatVersion: "0.1",
56
56
  packageVersion: packageVersion_1.pkgVersion,
57
57
  };
58
- //# sourceMappingURL=counterFactory.js.map
58
+ //# sourceMappingURL=counterFactory.cjs.map