@fluidframework/counter 2.0.0-dev-rc.1.0.0.225277 → 2.0.0-dev-rc.1.0.0.228517

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,39 @@
1
1
  # @fluidframework/counter
2
2
 
3
+ ## 2.0.0-rc.1.0.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Updated server dependencies ([#19122](https://github.com/microsoft/FluidFramework/issues/19122)) [25366b4229](https://github.com/microsoft/FluidFramework/commits/25366b422918cb43685c5f328b50450749592902)
8
+
9
+ The following Fluid server dependencies have been updated to the latest version, 3.0.0. [See the full changelog.](https://github.com/microsoft/FluidFramework/releases/tag/server_v3.0.0)
10
+
11
+ - @fluidframework/gitresources
12
+ - @fluidframework/server-kafka-orderer
13
+ - @fluidframework/server-lambdas
14
+ - @fluidframework/server-lambdas-driver
15
+ - @fluidframework/server-local-server
16
+ - @fluidframework/server-memory-orderer
17
+ - @fluidframework/protocol-base
18
+ - @fluidframework/server-routerlicious
19
+ - @fluidframework/server-routerlicious-base
20
+ - @fluidframework/server-services
21
+ - @fluidframework/server-services-client
22
+ - @fluidframework/server-services-core
23
+ - @fluidframework/server-services-ordering-kafkanode
24
+ - @fluidframework/server-services-ordering-rdkafka
25
+ - @fluidframework/server-services-ordering-zookeeper
26
+ - @fluidframework/server-services-shared
27
+ - @fluidframework/server-services-telemetry
28
+ - @fluidframework/server-services-utils
29
+ - @fluidframework/server-test-utils
30
+ - tinylicious
31
+
32
+ - Updated @fluidframework/protocol-definitions ([#19122](https://github.com/microsoft/FluidFramework/issues/19122)) [25366b4229](https://github.com/microsoft/FluidFramework/commits/25366b422918cb43685c5f328b50450749592902)
33
+
34
+ The @fluidframework/protocol-definitions dependency has been upgraded to v3.1.0. [See the full
35
+ changelog.](https://github.com/microsoft/FluidFramework/blob/main/common/lib/protocol-definitions/CHANGELOG.md#310)
36
+
3
37
  ## 2.0.0-internal.8.0.0
4
38
 
5
39
  Dependency updates only.
package/README.md CHANGED
@@ -1,173 +1,94 @@
1
- # @fluidframework/counter
1
+ # @fluidframework/cell
2
2
 
3
- <!-- AUTO-GENERATED-CONTENT:START (README_DEPENDENCY_GUIDELINES_SECTION:includeHeading=TRUE) -->
3
+ The `SharedCell` Distributed Data Structure (DDS) stores a single, shared value that can be edited or deleted.
4
+
5
+ <!-- AUTO-GENERATED-CONTENT:START (README_INSTALLATION_SECTION:includeHeading=TRUE) -->
4
6
 
5
7
  <!-- prettier-ignore-start -->
6
8
  <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
7
9
 
8
- ## Using Fluid Framework libraries
10
+ ## Installation
9
11
 
10
- When taking a dependency on a Fluid Framework library, we recommend using a `^` (caret) version range, such as `^1.3.4`.
11
- While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
12
- library consumers should always prefer `^`.
12
+ To get started, install the package by running the following command:
13
13
 
14
- Note that when depending on a library version of the form `2.0.0-internal.x.y.z`, called the Fluid internal version scheme,
15
- you must use a `>= <` dependency range (such as `>=2.0.0-internal.x.y.z <2.0.0-internal.w.0.0` where `w` is `x+1`).
16
- Standard `^` and `~` ranges will not work as expected.
17
- See the [@fluid-tools/version-tools](https://github.com/microsoft/FluidFramework/blob/main/build-tools/packages/version-tools/README.md)
18
- package for more information including tools to convert between version schemes.
14
+ ```bash
15
+ npm i @fluidframework/counter
16
+ ```
19
17
 
20
18
  <!-- prettier-ignore-end -->
21
19
 
22
20
  <!-- AUTO-GENERATED-CONTENT:END -->
23
21
 
24
- ## Introduction
25
-
26
- The `SharedCounter` distributed data structure (DDS) is used to store an integer counter value that can be modified by multiple clients simultaneously.
27
- The data structure affords incrementing and decrementing the shared value via its `increment` method. Decrements are done by providing a negative value.
28
-
29
- The `SharedCounter` is a specialized [Optimistic DDS][].
30
- It operates on communicated _deltas_ (amounts by which the shared value should be incremented or decremented), rather than direct changes to the shared value.
31
- In this way, it avoids the pitfalls of DDSes with simpler merge strategies, in which one user's edit may clobber another's (see [below](#why-a-specialized-dds)).
32
-
33
- Note that the `SharedCounter` only operates on integer values.
34
-
35
- ### Why a specialized DDS?
36
-
37
- You may be asking yourself, why not just store the shared integer value directly in another DDS like a [SharedMap][]?
38
- Why incur the overhead of another runtime type?
39
-
40
- The key to the answer here is that DDSes with simpler merge strategies (like `SharedMap`) take a somewhat brute-force approach to merging concurrent edits.
41
- For a semantic data type like a counter, this can result in undesirable behavior.
42
-
43
- #### SharedMap Example
44
-
45
- Let's illustrate the issue with an example.
46
-
47
- Consider a polling widget.
48
- The widget displays a list of options and allows users to click a checkbox to vote for a given option.
49
- Next to each option in the list, a live counter is displayed that shows the number of votes for that item.
50
-
51
- Whenever a user checks an option, all users should see the counter corresponding to that option increment by 1.
52
-
53
- In this example, the application is storing its vote counts in a [SharedMap][], where the map keys are `strings` representing the IDs of the options, and the values are `numbers` representing the associated vote counts.
54
-
55
- For simplicity, we will look at a scenario in which 2 users vote for the same option at around the same time.
56
-
57
- Specifically, **User A** clicks the checkbox for option **Foo**, which currently has **0** votes.
58
- The application then optimistically updates the vote count for that object by writing the updated counter value of **1** for option **Foo** to its `SharedMap`.
59
-
60
- The value change operation (op) is then transmitted to the service to be sequenced and eventually sent to other users in the collaborative session.
61
-
62
- At around the same time, **User B** clicks the checkbox for option **Foo**, which in their view currently has **0** votes.
63
- Similarly to before, the application optimistically updates the associated counter value to **1**, and transmits its own update op.
64
-
65
- The service receives the op from **User A** first, and sequences their op updating **Foo** to **1** as **op 0**. **User B**'s op is received second, and is sequenced as **op 1**.
66
-
67
- Both users then receive acknowledgement of their update, and receive **op 0** and **op 1** to be applied in order.
68
- Both clients apply **op 0** by setting **Foo** to **1**.
69
- Then both clients apply **op 1** by setting **Foo** to **1**.
70
-
71
- But this isn't right.
72
- Two different users voted for option **Foo**, but the counter now displays **1**.
73
-
74
- `SharedCounter` solves this problem by expressing its operations in terms of _increments_ and _decrements_ rather than as direct value updates.
75
-
76
- So for the scenario above, if the system was using `SharedCounter`s to represent the vote counts, **User A** would submit an op _incrementing_ **Foo** by **+1**, rather than updating the value of **Foo** from **0** to **1**.
77
- At around the same time, **User B** would submit their own **+1** op for **Foo**.
78
-
79
- Assuming the same sequencing, both users first apply **op 0** and increment their counter for **Foo** by **+1** (from **0** to **1**).
80
- Next, they both apply **op 1** and increment their counter for **Foo** by **+1** a second time (from **1** to **2**).
81
-
82
- Now both users see the right vote count for `Foo`!
83
-
84
- ## Usage
85
-
86
- The `SharedCounter` object provides a simple API surface for managing a shared integer whose value may be incremented and decremented by collaborators.
87
-
88
- A new `SharedCounter` value will be initialized with its value set to `0`.
89
- If you wish to initialize the counter to a different value, you may [modify the value](#incrementing--decrementing-the-value) before attaching the container, or before storing it in another shared object like a `SharedMap`.
22
+ <!-- AUTO-GENERATED-CONTENT:START (README_DEPENDENCY_GUIDELINES_SECTION:includeHeading=TRUE) -->
90
23
 
91
- ## Installation
24
+ <!-- prettier-ignore-start -->
25
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
92
26
 
93
- The package containing the `SharedCounter` library is [@fluidframework/shared-counter](https://www.npmjs.com/package/@fluidframework/counter).
27
+ ## Using Fluid Framework libraries
94
28
 
95
- To get started, run the following from a terminal in your repository:
29
+ When taking a dependency on a Fluid Framework library, we recommend using a `^` (caret) version range, such as `^1.3.4`.
30
+ While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
31
+ library consumers should always prefer `^`.
96
32
 
97
- ```bash
98
- npm install @fluidframework/shared-counter
99
- ```
33
+ <!-- prettier-ignore-end -->
100
34
 
101
- ### Creation
35
+ <!-- AUTO-GENERATED-CONTENT:END -->
102
36
 
103
- The workflow for creating a `SharedCounter` is effectively the same as many of our other DDSes.
104
- For an example of how to create one, please see our workflow examples for [SharedMap creation][].
37
+ <!-- AUTO-GENERATED-CONTENT:START (README_API_DOCS_SECTION:includeHeading=TRUE) -->
105
38
 
106
- ### Incrementing / decrementing the value
39
+ <!-- prettier-ignore-start -->
107
40
 
108
- Once you have created your `SharedCounter`, you can change its value using the [increment][] method.
109
- This method accepts a positive or negative _integer_ to be applied to the shared value.
41
+ <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
110
42
 
111
- ```javascript
112
- sharedCounter.increment(3); // Adds 3 to the current value
113
- sharedCounter.increment(-5); // Subtracts 5 from the current value
114
- ```
43
+ ## API Documentation
115
44
 
116
- ### `incremented` event
45
+ API documentation for **@fluidframework/cell** is available at <https://fluidframework.com/docs/api/v1/cell>.
117
46
 
118
- The [incremented][] event is sent when a client in the collaborative session changes the counter value via the `increment` method.
47
+ <!-- prettier-ignore-end -->
119
48
 
120
- Signature:
49
+ <!-- AUTO-GENERATED-CONTENT:END -->
121
50
 
122
- ```javascript
123
- (event: "incremented", listener: (incrementAmount: number, newValue: number) => void)
124
- ```
51
+ <!-- AUTO-GENERATED-CONTENT:START (README_CONTRIBUTION_GUIDELINES_SECTION:includeHeading=TRUE) -->
125
52
 
126
- By listening to this event, you can receive and apply the changes coming from other collaborators.
127
- Consider the following code example for configuring a Counter widget:
53
+ <!-- prettier-ignore-start -->
54
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
128
55
 
129
- ```javascript
130
- const sharedCounter = container.initialObjects.sharedCounter;
131
- let counterValue = sharedCounter.value;
56
+ ## Contribution Guidelines
132
57
 
133
- const incrementButton = document.createElement("button");
134
- button.textContent = "Increment";
135
- const decrementButton = document.createElement("button");
136
- button.textContent = "Decrement";
58
+ There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
137
59
 
138
- // Increment / decrement shared counter value when the corresponding button is clicked
139
- incrementButton.addEventListener("click", () => sharedCounter.increment(1));
140
- decrementButton.addEventListener("click", () => sharedCounter.increment(-1));
60
+ - Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
61
+ - [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
62
+ - Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
63
+ - [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
141
64
 
142
- const counterValueLabel = document.createElement("label");
143
- counterValueLabel.textContent = `${counterValue}`;
65
+ Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/wiki).
144
66
 
145
- // This function will be called each time the shared counter value is incremented
146
- // (including increments from this client).
147
- // Update the local counter value and the corresponding label being displayed in the widget.
148
- const updateCounterValueLabel = (delta) => {
149
- counterValue += delta;
150
- counterValueLabel.textContent = `${counterValue}`;
151
- };
67
+ This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
68
+ For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
152
69
 
153
- // Register to be notified when the counter is incremented
154
- sharedCounter.on("incremented", updateCounterValueLabel);
155
- ```
70
+ This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
71
+ Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
72
+ Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship.
156
73
 
157
- In the code above, whenever a user presses either the Increment or Decrement button, the `sharedCounter.increment` is called with +/- 1.
158
- This causes the `incremented` event to be sent to all of the clients who have this container open.
74
+ <!-- prettier-ignore-end -->
159
75
 
160
- Since `updateCounterValueLabel` is listening for all `incremented` events, the view will always refresh with the appropriate updated value any time a collaborator increments or decrements the counter value.
76
+ <!-- AUTO-GENERATED-CONTENT:END -->
161
77
 
162
- <!-- AUTO-GENERATED-CONTENT:START (README_API_DOCS_SECTION:includeHeading=TRUE) -->
78
+ <!-- AUTO-GENERATED-CONTENT:START (README_HELP_SECTION:includeHeading=TRUE) -->
163
79
 
164
80
  <!-- prettier-ignore-start -->
81
+ <!-- NOTE: This section is automatically generated using @fluid-tools/markdown-magic. Do not update these generated contents directly. -->
165
82
 
166
- <!-- This section is automatically generated. To update it, make the appropriate changes to docs/md-magic.config.js or the embedded content, then run 'npm run build:md-magic' in the docs folder. -->
83
+ ## Help
167
84
 
168
- ## API Documentation
85
+ Not finding what you're looking for in this README? Check out our [GitHub
86
+ Wiki](https://github.com/microsoft/FluidFramework/wiki) or [fluidframework.com](https://fluidframework.com/docs/).
87
+
88
+ Still not finding what you're looking for? Please [file an
89
+ issue](https://github.com/microsoft/FluidFramework/wiki/Submitting-Bugs-and-Feature-Requests).
169
90
 
170
- API documentation for **@fluidframework/counter** is available at <https://fluidframework.com/docs/apis/counter>.
91
+ Thank you!
171
92
 
172
93
  <!-- prettier-ignore-end -->
173
94
 
@@ -189,11 +110,3 @@ Use of Microsoft trademarks or logos in modified versions of this project must n
189
110
  <!-- prettier-ignore-end -->
190
111
 
191
112
  <!-- AUTO-GENERATED-CONTENT:END -->
192
-
193
- <!-- Links -->
194
-
195
- [increment]: https://fluidframework.com/docs/apis/counter/isharedcounter-interface#increment-methodsignature
196
- [incremented]: https://fluidframework.com/docs/apis/counter/isharedcounterevents-interface#_call_-callsignature
197
- [optimistic dds]: https://fluidframework.com/docs/build/dds/#optimistic-data-structures
198
- [sharedmap]: https://fluidframework.com/docs/data-structures/map
199
- [sharedmap creation]: https://fluidframework.com/docs/data-structures/map/#creation
@@ -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.cjs");
12
+ const counterFactory_1 = require("./counterFactory");
13
13
  const snapshotFileName = "header";
14
14
  /**
15
15
  * {@inheritDoc ISharedCounter}
@@ -124,4 +124,4 @@ class SharedCounter extends shared_object_base_1.SharedObject {
124
124
  }
125
125
  }
126
126
  exports.SharedCounter = SharedCounter;
127
- //# sourceMappingURL=counter.cjs.map
127
+ //# sourceMappingURL=counter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counter.js","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 * @alpha\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.cjs");
9
- const packageVersion_1 = require("./packageVersion.cjs");
8
+ const counter_1 = require("./counter");
9
+ const packageVersion_1 = require("./packageVersion");
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.cjs.map
58
+ //# sourceMappingURL=counterFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"counterFactory.js","sourceRoot":"","sources":["../src/counterFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAQH,uCAA0C;AAE1C,qDAA8C;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.cjs");
14
+ var counter_1 = require("./counter");
15
15
  Object.defineProperty(exports, "SharedCounter", { enumerable: true, get: function () { return counter_1.SharedCounter; } });
16
- //# sourceMappingURL=index.cjs.map
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH;;;;;GAKG;AAEH,qCAA0C;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.cjs.map
7
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../src/interfaces.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { type ISharedObject, type ISharedObjectEvents } from \"@fluidframework/shared-object-base\";\n\n/**\n * Events sent by {@link SharedCounter}.\n * @alpha\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 * @alpha\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"]}
@@ -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-rc.1.0.0.225277";
8
+ export declare const pkgVersion = "2.0.0-dev-rc.1.0.0.228517";
9
9
  //# sourceMappingURL=packageVersion.d.ts.map
@@ -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-rc.1.0.0.225277";
12
- //# sourceMappingURL=packageVersion.cjs.map
11
+ exports.pkgVersion = "2.0.0-dev-rc.1.0.0.228517";
12
+ //# sourceMappingURL=packageVersion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"packageVersion.js","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEU,QAAA,OAAO,GAAG,yBAAyB,CAAC;AACpC,QAAA,UAAU,GAAG,2BAA2B,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-rc.1.0.0.228517\";\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-rc.1.0.0.225277";
8
+ export declare const pkgVersion = "2.0.0-dev-rc.1.0.0.228517";
9
9
  //# sourceMappingURL=packageVersion.d.mts.map
@@ -5,5 +5,5 @@
5
5
  * THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY
6
6
  */
7
7
  export const pkgName = "@fluidframework/counter";
8
- export const pkgVersion = "2.0.0-dev-rc.1.0.0.225277";
8
+ export const pkgVersion = "2.0.0-dev-rc.1.0.0.228517";
9
9
  //# sourceMappingURL=packageVersion.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"packageVersion.mjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,2BAA2B,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-rc.1.0.0.225277\";\n"]}
1
+ {"version":3,"file":"packageVersion.mjs","sourceRoot":"","sources":["../src/packageVersion.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,yBAAyB,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,2BAA2B,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-rc.1.0.0.228517\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/counter",
3
- "version": "2.0.0-dev-rc.1.0.0.225277",
3
+ "version": "2.0.0-dev-rc.1.0.0.228517",
4
4
  "description": "Counter DDS",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -19,7 +19,7 @@
19
19
  },
20
20
  "require": {
21
21
  "types": "./dist/index.d.ts",
22
- "default": "./dist/index.cjs"
22
+ "default": "./dist/index.js"
23
23
  }
24
24
  },
25
25
  "./alpha": {
@@ -29,7 +29,7 @@
29
29
  },
30
30
  "require": {
31
31
  "types": "./dist/counter-alpha.d.ts",
32
- "default": "./dist/index.cjs"
32
+ "default": "./dist/index.js"
33
33
  }
34
34
  },
35
35
  "./beta": {
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "require": {
41
41
  "types": "./dist/counter-beta.d.ts",
42
- "default": "./dist/index.cjs"
42
+ "default": "./dist/index.js"
43
43
  }
44
44
  },
45
45
  "./internal": {
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "require": {
51
51
  "types": "./dist/index.d.ts",
52
- "default": "./dist/index.cjs"
52
+ "default": "./dist/index.js"
53
53
  }
54
54
  },
55
55
  "./public": {
@@ -59,11 +59,11 @@
59
59
  },
60
60
  "require": {
61
61
  "types": "./dist/counter-public.d.ts",
62
- "default": "./dist/index.cjs"
62
+ "default": "./dist/index.js"
63
63
  }
64
64
  }
65
65
  },
66
- "main": "dist/index.cjs",
66
+ "main": "dist/index.js",
67
67
  "module": "lib/index.mjs",
68
68
  "types": "dist/index.d.ts",
69
69
  "c8": {
@@ -87,23 +87,23 @@
87
87
  "temp-directory": "nyc/.nyc_output"
88
88
  },
89
89
  "dependencies": {
90
- "@fluidframework/core-interfaces": "2.0.0-dev-rc.1.0.0.225277",
91
- "@fluidframework/core-utils": "2.0.0-dev-rc.1.0.0.225277",
92
- "@fluidframework/datastore-definitions": "2.0.0-dev-rc.1.0.0.225277",
93
- "@fluidframework/driver-utils": "2.0.0-dev-rc.1.0.0.225277",
94
- "@fluidframework/protocol-definitions": "^3.1.0-223007",
95
- "@fluidframework/runtime-definitions": "2.0.0-dev-rc.1.0.0.225277",
96
- "@fluidframework/shared-object-base": "2.0.0-dev-rc.1.0.0.225277"
90
+ "@fluidframework/core-interfaces": "2.0.0-dev-rc.1.0.0.228517",
91
+ "@fluidframework/core-utils": "2.0.0-dev-rc.1.0.0.228517",
92
+ "@fluidframework/datastore-definitions": "2.0.0-dev-rc.1.0.0.228517",
93
+ "@fluidframework/driver-utils": "2.0.0-dev-rc.1.0.0.228517",
94
+ "@fluidframework/protocol-definitions": "^3.1.0",
95
+ "@fluidframework/runtime-definitions": "2.0.0-dev-rc.1.0.0.228517",
96
+ "@fluidframework/shared-object-base": "2.0.0-dev-rc.1.0.0.228517"
97
97
  },
98
98
  "devDependencies": {
99
99
  "@arethetypeswrong/cli": "^0.13.3",
100
- "@fluid-tools/build-cli": "0.29.0-222379",
100
+ "@fluid-tools/build-cli": "^0.29.0",
101
101
  "@fluidframework/build-common": "^2.0.3",
102
- "@fluidframework/build-tools": "0.29.0-222379",
102
+ "@fluidframework/build-tools": "^0.29.0",
103
103
  "@fluidframework/counter-previous": "npm:@fluidframework/counter@2.0.0-internal.8.0.0",
104
- "@fluidframework/eslint-config-fluid": "^3.1.0",
105
- "@fluidframework/mocha-test-setup": "2.0.0-dev-rc.1.0.0.225277",
106
- "@fluidframework/test-runtime-utils": "2.0.0-dev-rc.1.0.0.225277",
104
+ "@fluidframework/eslint-config-fluid": "^3.2.0",
105
+ "@fluidframework/mocha-test-setup": "2.0.0-dev-rc.1.0.0.228517",
106
+ "@fluidframework/test-runtime-utils": "2.0.0-dev-rc.1.0.0.228517",
107
107
  "@microsoft/api-extractor": "^7.38.3",
108
108
  "@types/mocha": "^9.1.1",
109
109
  "@types/node": "^18.19.0",
@@ -146,7 +146,7 @@
146
146
  "build:docs": "fluid-build . --task api",
147
147
  "build:esnext": "tsc-multi --config ../../../common/build/build-common/tsc-multi.esm.json",
148
148
  "build:genver": "gen-version",
149
- "build:test": "tsc-multi --config ./tsc-multi.test.json",
149
+ "build:test": "tsc --project ./src/test/tsconfig.json",
150
150
  "check:are-the-types-wrong": "attw --pack . --entrypoints .",
151
151
  "check:release-tags": "api-extractor run --local --config ./api-extractor-lint.json",
152
152
  "ci:build:docs": "api-extractor run",
@@ -162,7 +162,7 @@
162
162
  "test:coverage": "c8 npm test",
163
163
  "test:mocha": "mocha --ignore \"dist/test/types/*\" --recursive dist/test -r node_modules/@fluidframework/mocha-test-setup",
164
164
  "test:mocha:verbose": "cross-env FLUID_TEST_VERBOSE=1 npm run test:mocha",
165
- "tsc": "tsc-multi --config ../../../common/build/build-common/tsc-multi.cjs.json",
165
+ "tsc": "tsc",
166
166
  "typetests:gen": "fluid-type-test-generator",
167
167
  "typetests:prepare": "flub typetests --dir . --reset --previous --normalize"
168
168
  }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/counter";
9
- export const pkgVersion = "2.0.0-dev-rc.1.0.0.225277";
9
+ export const pkgVersion = "2.0.0-dev-rc.1.0.0.228517";
@@ -1 +0,0 @@
1
- {"version":3,"file":"counter.cjs","sourceRoot":"","sources":["../src/counter.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2DAAoD;AACpD,+EAAmG;AAOnG,+DAA4D;AAE5D,2EAI4C;AAC5C,yDAAkD;AAqBlD,MAAM,gBAAgB,GAAG,QAAQ,CAAC;AAElC;;;GAGG;AACH,MAAa,aAAc,SAAQ,iCAAkC;IACpE;;;;;;;OAOG;IACI,MAAM,CAAC,MAAM,CAAC,OAA+B,EAAE,EAAW;QAChE,OAAO,OAAO,CAAC,aAAa,CAAC,EAAE,EAAE,+BAAc,CAAC,IAAI,CAAkB,CAAC;IACxE,CAAC;IAED,YACC,EAAU,EACV,OAA+B,EAC/B,UAA8B;QAE9B,KAAK,CAAC,EAAE,EAAE,OAAO,EAAE,UAAU,EAAE,gBAAgB,CAAC,CAAC;QAY1C,WAAM,GAAW,CAAC,CAAC;IAX3B,CAAC;IAED;;;;OAIG;IACI,MAAM,CAAC,UAAU;QACvB,OAAO,IAAI,+BAAc,EAAE,CAAC;IAC7B,CAAC;IAID;;OAEG;IACH,IAAW,KAAK;QACf,OAAO,IAAI,CAAC,MAAM,CAAC;IACpB,CAAC;IAED;;OAEG;IACI,SAAS,CAAC,eAAuB;QACvC,uGAAuG;QACvG,wGAAwG;QACxG,IAAI,eAAe,GAAG,CAAC,KAAK,CAAC,EAAE;YAC9B,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;SACpD;QAED,MAAM,EAAE,GAAwB;YAC/B,IAAI,EAAE,WAAW;YACjB,eAAe;SACf,CAAC;QAEF,IAAI,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;QACpC,IAAI,CAAC,kBAAkB,CAAC,EAAE,CAAC,CAAC;IAC7B,CAAC;IAEO,aAAa,CAAC,eAAuB;QAC5C,IAAI,CAAC,MAAM,IAAI,eAAe,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,eAAe,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC;IACxD,CAAC;IAED;;;;OAIG;IACO,aAAa,CAAC,UAA4B;QACnD,kCAAkC;QAClC,MAAM,OAAO,GAA2B;YACvC,KAAK,EAAE,IAAI,CAAC,KAAK;SACjB,CAAC;QAEF,wCAAwC;QACxC,OAAO,IAAA,4CAAuB,EAAC,gBAAgB,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC;IAC3E,CAAC;IAED;;OAEG;IACO,KAAK,CAAC,QAAQ,CAAC,OAA+B;QACvD,MAAM,OAAO,GAAG,MAAM,IAAA,2BAAY,EAAyB,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAEtF,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,KAAK,CAAC;IAC7B,CAAC;IAED;;OAEG;IACO,YAAY,KAAU,CAAC;IAEjC;;;;;;;OAOG;IACO,WAAW,CACpB,OAAkC,EAClC,KAAc,EACd,eAAwB;QAExB,wEAAwE;QACxE,IAAI,OAAO,CAAC,IAAI,KAAK,kCAAW,CAAC,SAAS,IAAI,CAAC,KAAK,EAAE;YACrD,MAAM,EAAE,GAAG,OAAO,CAAC,QAA+B,CAAC;YAEnD,QAAQ,EAAE,CAAC,IAAI,EAAE;gBAChB,KAAK,WAAW,CAAC,CAAC;oBACjB,IAAI,CAAC,aAAa,CAAC,EAAE,CAAC,eAAe,CAAC,CAAC;oBACvC,MAAM;iBACN;gBAED,OAAO,CAAC,CAAC;oBACR,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;iBACrC;aACD;SACD;IACF,CAAC;IAED;;OAEG;IACO,cAAc,CAAC,EAAW;QACnC,MAAM,SAAS,GAAG,EAAyB,CAAC;QAE5C,yDAAyD;QAEzD,4DAA4D;QAC5D,IAAA,mBAAM,EAAC,SAAS,CAAC,IAAI,KAAK,WAAW,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC;QAE7E,IAAI,CAAC,aAAa,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAC/C,CAAC;CACD;AAvID,sCAuIC","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 * @alpha\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"]}
@@ -1 +0,0 @@
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"]}
@@ -1 +0,0 @@
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"]}
@@ -1 +0,0 @@
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 * @alpha\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 * @alpha\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"]}
@@ -1 +0,0 @@
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,2BAA2B,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-rc.1.0.0.225277\";\n"]}
@@ -1,4 +0,0 @@
1
- {
2
- "targets": [{ "extname": ".cjs", "module": "CommonJS", "moduleResolution": "Node10" }],
3
- "projects": ["./tsconfig.json", "./src/test/tsconfig.json"]
4
- }