@fluidframework/matrix 2.117.0 → 3.0.0

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 (58) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/README.md +53 -50
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
  4. package/dist/handlecache.js +3 -2
  5. package/dist/handlecache.js.map +1 -1
  6. package/dist/handletable.d.ts.map +1 -1
  7. package/dist/handletable.js +1 -0
  8. package/dist/handletable.js.map +1 -1
  9. package/dist/matrix.js +57 -53
  10. package/dist/matrix.js.map +1 -1
  11. package/dist/packageVersion.d.ts +1 -1
  12. package/dist/packageVersion.d.ts.map +1 -1
  13. package/dist/packageVersion.js +1 -1
  14. package/dist/packageVersion.js.map +1 -1
  15. package/dist/permutationvector.js +86 -83
  16. package/dist/permutationvector.js.map +1 -1
  17. package/dist/range.js +1 -2
  18. package/dist/range.js.map +1 -1
  19. package/dist/runtime.d.ts +1 -1
  20. package/dist/runtime.d.ts.map +1 -1
  21. package/dist/runtime.js +9 -9
  22. package/dist/runtime.js.map +1 -1
  23. package/dist/serialization.d.ts.map +1 -1
  24. package/dist/serialization.js +2 -2
  25. package/dist/serialization.js.map +1 -1
  26. package/dist/sparsearray2d.js +3 -2
  27. package/dist/sparsearray2d.js.map +1 -1
  28. package/dist/undoprovider.js +12 -0
  29. package/dist/undoprovider.js.map +1 -1
  30. package/lib/handlecache.js +3 -2
  31. package/lib/handlecache.js.map +1 -1
  32. package/lib/handletable.d.ts.map +1 -1
  33. package/lib/handletable.js +1 -0
  34. package/lib/handletable.js.map +1 -1
  35. package/lib/legacy.d.ts +1 -1
  36. package/lib/matrix.js +57 -53
  37. package/lib/matrix.js.map +1 -1
  38. package/lib/packageVersion.d.ts +1 -1
  39. package/lib/packageVersion.d.ts.map +1 -1
  40. package/lib/packageVersion.js +1 -1
  41. package/lib/packageVersion.js.map +1 -1
  42. package/lib/permutationvector.js +84 -81
  43. package/lib/permutationvector.js.map +1 -1
  44. package/lib/public.d.ts +1 -1
  45. package/lib/runtime.js +9 -9
  46. package/lib/runtime.js.map +1 -1
  47. package/lib/serialization.d.ts.map +1 -1
  48. package/lib/sparsearray2d.js +3 -2
  49. package/lib/sparsearray2d.js.map +1 -1
  50. package/lib/undoprovider.js +12 -0
  51. package/lib/undoprovider.js.map +1 -1
  52. package/package.json +40 -60
  53. package/src/packageVersion.ts +1 -1
  54. package/tsconfig.json +1 -1
  55. package/internal.d.ts +0 -11
  56. package/legacy.d.ts +0 -11
  57. /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
  58. /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
package/CHANGELOG.md CHANGED
@@ -1,8 +1,42 @@
1
1
  # @fluidframework/matrix
2
2
 
3
- ## 2.117.0
3
+ ## 3.0.0
4
4
 
5
- Dependency updates only.
5
+ ### Minor Changes
6
+
7
+ - Removal of direct CommonJS support ([#28124](https://github.com/microsoft/FluidFramework/pull/28124)) [0f84e3b8878](https://github.com/microsoft/FluidFramework/commit/0f84e3b8878a5e75b2253976d98fd963bbd9db88)
8
+
9
+ Direct `require()` import is no longer directly supported.
10
+ Package is transpiled as ECMAScript Module.
11
+
12
+ See [Removal of direct CommonJS support in v3.0](https://github.com/microsoft/FluidFramework/issues/27444) for more information.
13
+
14
+ - Require modern TypeScript module resolution ([#27970](https://github.com/microsoft/FluidFramework/pull/27970)) [325e2016ca9](https://github.com/microsoft/FluidFramework/commit/325e2016ca9978d4a1f7552c97ba34feac9df41f)
15
+
16
+ Fluid Framework Client packages no longer include type declaration compatibility entrypoints for TypeScript's legacy Node10 resolution mode (`"moduleResolution": "node"` or `"node10"`).
17
+ Applications upgrading to Fluid Framework 3.0 must use one of the following supported configurations:
18
+ - `"module": "Node16"` with `"moduleResolution": "Node16"`
19
+ - `"module": "NodeNext"` with `"moduleResolution": "NodeNext"`
20
+ - `"module": "ESNext"` with `"moduleResolution": "Bundler"`
21
+
22
+ Existing public package entrypoints exposed through `package.json` exports, including `/alpha`, `/beta`, and `/legacy`, remain available under supported module resolution modes.
23
+
24
+ See [Removal of Node10 resolutions in v3.0](https://github.com/microsoft/FluidFramework/issues/27457) for more information.
25
+
26
+ - Client packages now target ES2022 ([#27846](https://github.com/microsoft/FluidFramework/pull/27846)) [91c78541bdd](https://github.com/microsoft/FluidFramework/commit/91c78541bddcbca5d6c5f357b023eeaee617d885)
27
+
28
+ The TypeScript compilation `target` and `lib` for the Fluid Framework client packages have been raised from ES2021/ES2020 to **ES2022**.
29
+ The published JavaScript now uses ES2022 language features (with correspondingly less down-leveling), so consuming these packages requires a runtime that supports ES2022.
30
+ All actively supported Node.js versions and evergreen browsers already meet this requirement.
31
+
32
+ Note that Fluid Framework has not officially supported targets older than ES2022 since before 2.0: this is documented in [ClientRequirements.md](https://github.com/microsoft/FluidFramework/blob/main/ClientRequirements.md) as well as the README for every client package.
33
+
34
+ It is possible this change could impact users of less up to date JavaScript runtimes.
35
+ Impacted users can use a tool like [babel](https://babeljs.io/) to transpile out unsupported language features.
36
+
37
+ - Build with TypeScript 6 ([#28052](https://github.com/microsoft/FluidFramework/pull/28052)) [7ab015c49de](https://github.com/microsoft/FluidFramework/commit/7ab015c49deec84833cdfe1fb5e1606b901f6e81)
38
+
39
+ FluidFramework Client SDK is now built using TypeScript 6. Consumers should build with TypeScript v6 or v7 or compatible tooling.
6
40
 
7
41
  ## 2.116.0
8
42
 
package/README.md CHANGED
@@ -9,15 +9,15 @@ SharedMatrix is a rectangular 2D array of values. Matrix values are a superset o
9
9
 
10
10
  ## Using Fluid Framework libraries
11
11
 
12
- When taking a dependency on a Fluid Framework library's public APIs, we recommend using a `^` (caret) version range, such as `^1.3.4`.
13
- While Fluid Framework libraries may use different ranges with interdependencies between other Fluid Framework libraries,
14
- library consumers should always prefer `^`.
12
+ For a dependency on a Fluid Framework library's public APIs, we recommend a `^` (caret) version range.
13
+ For example, use `^1.3.4`.
15
14
 
16
- If using any of Fluid Framework's unstable APIs (for example, its `beta` APIs), we recommend using a more constrained version range, such as `~`.
15
+ For a dependency on an unstable API, such as a `beta` API, we recommend a more restrictive version range.
16
+ For example, use a `~` version range.
17
17
 
18
18
  ## Installation
19
19
 
20
- To get started, install the package by running the following command:
20
+ Run this command to install the package:
21
21
 
22
22
  ```bash
23
23
  npm i @fluidframework/matrix
@@ -25,16 +25,16 @@ npm i @fluidframework/matrix
25
25
 
26
26
  ## Importing from this package
27
27
 
28
- This package leverages [package.json exports](https://nodejs.org/api/packages.html#exports) to separate its APIs by support level.
29
- For more information on the related support guarantees, see [API Support Levels](https://fluidframework.com/docs/build/releases-and-apitags/#api-support-levels).
28
+ This package uses [package.json exports](https://nodejs.org/api/packages.html#exports) to separate APIs by support level.
29
+ For information about the support guarantees, read [API Support Levels](https://fluidframework.com/docs/build/releases-and-apitags/#api-support-levels).
30
30
 
31
- To access the `public` ([SemVer](https://semver.org/)) APIs, import via `@fluidframework/matrix` like normal.
31
+ Import the `public` APIs from `@fluidframework/matrix`.
32
32
 
33
- To access the `legacy` APIs, import via `@fluidframework/matrix/legacy`.
33
+ Import the `legacy` APIs from `@fluidframework/matrix/legacy`.
34
34
 
35
35
  ## API Documentation
36
36
 
37
- API documentation for **@fluidframework/matrix** is available at <https://fluidframework.com/docs/apis/matrix>.
37
+ Read the **@fluidframework/matrix** API documentation at <https://fluidframework.com/docs/apis/matrix>.
38
38
 
39
39
  <!-- prettier-ignore-end -->
40
40
 
@@ -183,62 +183,69 @@ ops for C1.
183
183
 
184
184
  ## Minimum Client Requirements
185
185
 
186
- These are the platform requirements for the current version of Fluid Framework Client Packages.
187
- These requirements err on the side of being too strict since within a major version they can be relaxed over time, but not made stricter.
188
- For Long Term Support (LTS) versions this can require supporting these platforms for several years.
186
+ Fluid Framework client libraries support the platforms in this document.
187
+ These requirements are intentionally restrictive.
188
+ Within a major version series, we can relax these requirements, but we cannot make them stricter.
189
+ For a Long Term Support (LTS) version, we might need to support these platforms for several years.
189
190
 
190
- It is likely that other configurations will work, but they are not supported: if they stop working, we do not consider that a bug.
191
- If you would benefit from support for something not listed here, file an issue and the product team will evaluate your request.
192
- When making such a request please include if the configuration already works (and thus the request is just that it becomes officially supported), or if changes are required to get it working.
191
+ Other configurations can work, but Fluid Framework does not support them.
192
+ If an unsupported configuration stops working, we do not classify this as a bug.
193
+ To request support for a configuration that is not listed, file an issue.
194
+ The product team will evaluate your request.
195
+ In the issue, specify the current status of the configuration:
196
+
197
+ - The configuration works but needs official support.
198
+ - The configuration does not work and requires changes.
193
199
 
194
200
  ### Supported Runtimes
195
201
 
196
- - NodeJs ^22.22.2 except that we will drop support for it [when NodeJs 22 loses its upstream support on 2027-04-30](https://github.com/nodejs/release#release-schedule), and will support a newer LTS version of NodeJS at least 1 year before 22 is end-of-life.
197
- - Running Fluid in a Node.js environment with the `--no-experimental-fetch` flag is not supported.
198
- - Modern browsers supporting the es2022 standard library: in response to asks we can add explicit support for using babel to polyfill to target specific standards or runtimes (meaning we can avoid/remove use of things that don't polyfill robustly, but otherwise target modern standards).
202
+ - Fluid Framework supports Node.js versions 22 and 24 while they receive [upstream support](https://nodejs.org/en/about/previous-releases).
203
+ - Fluid Framework will stop support for version 22 [when upstream support ends on 2027-04-30](https://github.com/nodejs/release#release-schedule).
204
+ - Fluid Framework does not support Node.js with the `--no-experimental-fetch` flag.
205
+ - Fluid Framework supports modern browsers that support the ES2022 standard library.
199
206
 
200
207
  ### Supported Tools
201
208
 
202
- - TypeScript 5.4:
203
- - All [`strict`](https://www.typescriptlang.org/tsconfig) options are supported.
204
- - [`strictNullChecks`](https://www.typescriptlang.org/tsconfig) is required.
205
- - [Configuration options deprecated in 5.0](https://github.com/microsoft/TypeScript/issues/51909) are not supported.
206
- - `exactOptionalPropertyTypes` is currently not fully supported.
207
- If used, narrowing members of Fluid Framework types types using `in`, `Reflect.has`, `Object.hasOwn` or `Object.prototype.hasOwnProperty` should be avoided as they may incorrectly exclude `undefined` from the possible values in some cases.
209
+ - [TypeScript 6.0](https://typescriptdocs.com/release-notes/TypeScript%206.0):
210
+ - Fluid Framework supports all [`strict`](https://www.typescriptlang.org/tsconfig) options.
211
+ - Set the build targets (`lib`, `target`) to `ES2022` or later.
212
+ - Enable [`strictNullChecks`](https://www.typescriptlang.org/tsconfig).
213
+ - Fluid Framework does not support [configuration options deprecated in TypeScript 6.0](https://typescriptdocs.com/release-notes/TypeScript%206.0#breaking-changes-and-deprecations-in-typescript-6-0).
214
+ - Fluid Framework does not fully support `exactOptionalPropertyTypes`.
215
+ If you enable this option, do not use `in`, `Reflect.has`, `Object.hasOwn`, or `Object.prototype.hasOwnProperty` to narrow members of Fluid Framework types.
216
+ These methods can incorrectly exclude `undefined` from the possible values.
208
217
  - [webpack](https://webpack.js.org/) 5
209
- - We are not intending to be prescriptive about what bundler to use.
210
- Other bundlers which can handle ES Modules should work, but webpack is the only one we actively test.
218
+ - We do not require a specific bundler.
219
+ Other bundlers that handle ES Modules can work, but we actively test only webpack.
211
220
 
212
221
  ### Module Resolution
213
222
 
214
- [`Node16`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) resolution should be used with TypeScript compilerOptions to follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
215
- Node10 resolution is not supported as it does not support Fluid Framework's API structuring pattern that is used to distinguish stable APIs from those that are in development.
223
+ In TypeScript `compilerOptions`, use [`Node16`, `Node20`, `NodeNext`, or `Bundler`](https://www.typescriptlang.org/tsconfig#moduleResolution) module resolution.
224
+ These settings follow the [Node.js v12+ ESM Resolution and Loading algorithm](https://nodejs.github.io/nodejs.dev/en/api/v20/esm/#resolution-and-loading-algorithm).
225
+
226
+ Do not use `Node10` module resolution.
216
227
 
217
228
  ### Module Formats
218
229
 
219
230
  - ES Modules:
220
- ES Modules are the preferred way to consume our client packages (including in NodeJs) and consuming our client packages from ES Modules is fully supported.
221
- - CommonJs:
222
- Consuming our client packages as CommonJs is supported only in NodeJS and only for the cases listed below.
223
- This is done to accommodate some workflows without good ES Module support.
224
- If you have a workflow you would like included in this list, file an issue.
225
- Once this list of workflows motivating CommonJS support is empty, we may drop support for CommonJS one year after notice of the change is posted here.
226
-
227
- - Testing with Jest (which lacks [stable ESM support](https://jestjs.io/docs/ecmascript-modules) due to [unstable APIs in NodeJs](https://github.com/nodejs/node/issues/37648))
231
+ Use ES Modules to consume Fluid Framework client packages, including in Node.js.
232
+ - CommonJS:
233
+ Fluid Framework does not officially support CommonJS in version 3.0 or later.
228
234
 
229
235
  ## Contribution Guidelines
230
236
 
231
- There are many ways to [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid.
237
+ You can [contribute](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md) to Fluid Framework in these ways:
232
238
 
233
- - Participate in Q&A in our [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
234
- - [Submit bugs](https://github.com/microsoft/FluidFramework/issues) and help us verify fixes as they are checked in.
235
- - Review the [source code changes](https://github.com/microsoft/FluidFramework/pulls).
239
+ - Answer questions in [GitHub Discussions](https://github.com/microsoft/FluidFramework/discussions).
240
+ - [Submit bug reports](https://github.com/microsoft/FluidFramework/issues) and help verify fixes.
241
+ - Review [source code changes](https://github.com/microsoft/FluidFramework/pulls).
236
242
  - [Contribute bug fixes](https://github.com/microsoft/FluidFramework/blob/main/CONTRIBUTING.md).
237
243
 
238
- Detailed instructions for working in the repo can be found in the [Wiki](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Home.md).
244
+ For detailed instructions, read the [repo documentation](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Home.md).
239
245
 
240
- This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
241
- 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.
246
+ This project follows the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
247
+ For more information, read the [Code of Conduct frequently asked questions](https://opensource.microsoft.com/codeofconduct/faq/).
248
+ For questions or comments, contact [opencode@microsoft.com](mailto:opencode@microsoft.com).
242
249
 
243
250
  This project may contain Microsoft trademarks or logos for Microsoft projects, products, or services.
244
251
  Use of these trademarks or logos must follow Microsoft’s [Trademark & Brand Guidelines](https://www.microsoft.com/trademarks).
@@ -246,13 +253,9 @@ Use of Microsoft trademarks or logos in modified versions of this project must n
246
253
 
247
254
  ## Help
248
255
 
249
- Not finding what you're looking for in this README?
250
- Check out [fluidframework.com](https://fluidframework.com/docs/).
251
-
252
- Still not finding what you're looking for?
253
- Please [file an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
256
+ Read the [Fluid Framework documentation](https://fluidframework.com/docs/) for information about Fluid Framework concepts and APIs.
254
257
 
255
- Thank you!
258
+ To request information that the documentation does not contain, [create an issue](https://github.com/microsoft/FluidFramework/blob/main/docs/content/Contributing/Submitting-Bugs-and-Feature-Requests.md).
256
259
 
257
260
  ## Trademark
258
261
 
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
3
- "extends": "../../../common/build/build-common/api-extractor-model.esm.json"
3
+ "extends": "<projectFolder>/../../../common/build/build-common/api-extractor-model.esm.json"
4
4
  }
@@ -16,10 +16,11 @@ const range_js_1 = require("./range.js");
16
16
  * so far there's no measurable perf penalty for being a separate object (node 12 x64)
17
17
  */
18
18
  class HandleCache {
19
+ vector;
20
+ handles = [];
21
+ start = 0;
19
22
  constructor(vector) {
20
23
  this.vector = vector;
21
- this.handles = [];
22
- this.start = 0;
23
24
  }
24
25
  /**
25
26
  * Returns the index of the given position in the 'handles' array as a Uint32.
@@ -1 +1 @@
1
- {"version":3,"file":"handlecache.js","sourceRoot":"","sources":["../src/handlecache.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O,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAC/E,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,0BAA0B;IAE1B,YAAY,CAAC,KAAa,EAAE,YAAoB,EAAE,aAAqB;QACtE,8EAA8E;QAC9E,6EAA6E;QAC7E,aAAa;QACb,EAAE;QACF,4EAA4E;QAC5E,wBAAwB;QACxB,EAAE;QACF,6FAA6F;QAC7F,2EAA2E;QAC3E,EAAE;QACF,gFAAgF;QAEhF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;QAC7B,CAAC;IACF,CAAC;CAGD;AAvHD,kCAuHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IVectorConsumer } from \"@tiny-calc/nano\";\n\nimport { type Handle, isHandleValid } from \"./handletable.js\";\nimport type { PermutationSegment, PermutationVector } from \"./permutationvector.js\";\nimport { ensureRange } from \"./range.js\";\n\n/**\n * Used by PermutationVector to cache position -\\> handle lookups.\n *\n * Perf: Possibly, this should eventually be inlined into PermutationVector itself, but\n * so far there's no measurable perf penalty for being a separate object (node 12 x64)\n */\nexport class HandleCache implements IVectorConsumer<Handle> {\n\tprivate handles: Handle[] = [];\n\tprivate start = 0;\n\n\tconstructor(public readonly vector: PermutationVector) {}\n\n\t/**\n\t * Returns the index of the given position in the 'handles' array as a Uint32.\n\t * (If the position is not in the array, returns an integer greater than 'handles.length').\n\t */\n\tprivate getIndex(position: number): number {\n\t\treturn (position - this.start) >>> 0;\n\t}\n\n\t/**\n\t * Returns the handle currently assigned to the given 'position' (if any). Check\n\t * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n\t * the given position.\n\t *\n\t * @throws A 'RangeError' if the provided 'position' is out-of-bounds with regards to the\n\t * PermutationVector's length.\n\t */\n\tpublic getHandle(position: number): Handle {\n\t\tconst index = this.getIndex(position);\n\n\t\t// Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n\t\t// to a separate method.\n\n\t\t// Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n\t\t// checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n\t\t// ~40% speedup when the position is in the cache (node v12 x64).\n\n\t\treturn index < this.handles.length ? this.handles[index] : this.cacheMiss(position);\n\t}\n\n\t/**\n\t * Update the cache when a handle has been allocated for a given position.\n\t */\n\tpublic addHandle(position: number, handle: Handle): void {\n\t\tassert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n\t\tconst index = this.getIndex(position);\n\t\tif (index < this.handles.length) {\n\t\t\tassert(\n\t\t\t\t!isHandleValid(this.handles[index]),\n\t\t\t\t0x018 /* \"Trying to insert handle into position with already valid handle!\" */,\n\t\t\t);\n\t\t\tthis.handles[index] = handle;\n\t\t}\n\t}\n\n\t/**\n\t * Used by {@link HandleCache.cacheMiss} to retrieve handles for a range of positions.\n\t * @param start - The start position (inclusive).\n\t * @param end - The end position (exclusive).\n\t * @param handles - The array to populate with handles. Note that it is mutated in place.\n\t */\n\tprivate getHandles(start: number, end: number, handles: Handle[]): void {\n\t\t// TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n\t\t// is that\n\n\t\tconst { vector } = this;\n\n\t\tfor (let pos = start; pos < end; pos++) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst { segment, offset } = vector.getContainingSegment(pos)!;\n\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\thandles.push(asPerm.start + offset);\n\t\t}\n\t}\n\n\tprivate cacheMiss(position: number): Handle {\n\t\t// Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n\t\t// with the same logic that handles 'position' >= length.\n\t\tconst _position = position >>> 0;\n\n\t\t// TODO: To bound memory usage, there should be a limit on the maximum size of\n\t\t// handle[].\n\n\t\t// TODO: To reduce MergeTree lookups, this code should opportunistically grow\n\t\t// the cache to the next MergeTree segment boundary (within the limits of\n\t\t// the handle cache).\n\n\t\tif (_position < this.start) {\n\t\t\tconst handles: Handle[] = [];\n\t\t\tthis.getHandles(_position, this.start, handles);\n\t\t\thandles.push(...this.handles);\n\t\t\tthis.handles = handles;\n\t\t\tthis.start = _position;\n\t\t\treturn this.handles[0];\n\t\t} else {\n\t\t\tensureRange(_position, this.vector.getLength());\n\t\t\tthis.getHandles(this.start + this.handles.length, _position + 1, this.handles);\n\t\t\treturn this.handles[this.handles.length - 1];\n\t\t}\n\t}\n\n\t// #region IVectorConsumer\n\n\titemsChanged(start: number, removedCount: number, insertedCount: number): void {\n\t\t// If positions were inserted/removed, our current policy is to trim the array\n\t\t// at the beginning of the invalidate range and lazily repopulate the handles\n\t\t// on demand.\n\t\t//\n\t\t// Some alternatives to consider that preserve the previously cached handles\n\t\t// that are still valid:\n\t\t//\n\t\t// * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n\t\t// to be Handle.unallocated, so we don't even need to look them up.)\n\t\t//\n\t\t// * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n\t\tconst index = this.getIndex(start);\n\t\tif (index < this.handles.length) {\n\t\t\tthis.handles.length = index;\n\t\t}\n\t}\n\n\t// #endregion IVectorConsumer\n}\n"]}
1
+ {"version":3,"file":"handlecache.js","sourceRoot":"","sources":["../src/handlecache.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,+BAA+B;AAE/B,kEAA6D;AAG7D,qDAA8D;AAE9D,yCAAyC;AAEzC;;;;;GAKG;AACH,MAAa,WAAW;IAIK;I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C,MAAM,GAAG,CAAC,CAAC,CAAC;QAC9C,CAAC;IACF,CAAC;IAED,0BAA0B;IAE1B,YAAY,CAAC,KAAa,EAAE,YAAoB,EAAE,aAAqB;QACtE,8EAA8E;QAC9E,6EAA6E;QAC7E,aAAa;QACb,EAAE;QACF,4EAA4E;QAC5E,wBAAwB;QACxB,EAAE;QACF,6FAA6F;QAC7F,2EAA2E;QAC3E,EAAE;QACF,gFAAgF;QAEhF,MAAM,KAAK,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACnC,IAAI,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC;YACjC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC;QAC7B,CAAC;IACF,CAAC;CAGD;AAvHD,kCAuHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable no-bitwise */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { IVectorConsumer } from \"@tiny-calc/nano\";\n\nimport { type Handle, isHandleValid } from \"./handletable.js\";\nimport type { PermutationSegment, PermutationVector } from \"./permutationvector.js\";\nimport { ensureRange } from \"./range.js\";\n\n/**\n * Used by PermutationVector to cache position -\\> handle lookups.\n *\n * Perf: Possibly, this should eventually be inlined into PermutationVector itself, but\n * so far there's no measurable perf penalty for being a separate object (node 12 x64)\n */\nexport class HandleCache implements IVectorConsumer<Handle> {\n\tprivate handles: Handle[] = [];\n\tprivate start = 0;\n\n\tconstructor(public readonly vector: PermutationVector) {}\n\n\t/**\n\t * Returns the index of the given position in the 'handles' array as a Uint32.\n\t * (If the position is not in the array, returns an integer greater than 'handles.length').\n\t */\n\tprivate getIndex(position: number): number {\n\t\treturn (position - this.start) >>> 0;\n\t}\n\n\t/**\n\t * Returns the handle currently assigned to the given 'position' (if any). Check\n\t * the result with 'isValidHandle(..)' to see if a handle has been allocated for\n\t * the given position.\n\t *\n\t * @throws A 'RangeError' if the provided 'position' is out-of-bounds with regards to the\n\t * PermutationVector's length.\n\t */\n\tpublic getHandle(position: number): Handle {\n\t\tconst index = this.getIndex(position);\n\n\t\t// Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted\n\t\t// to a separate method.\n\n\t\t// Perf: A cache hit implies that 'position' was in bounds. Therefore, we can defer\n\t\t// checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an\n\t\t// ~40% speedup when the position is in the cache (node v12 x64).\n\n\t\treturn index < this.handles.length ? this.handles[index] : this.cacheMiss(position);\n\t}\n\n\t/**\n\t * Update the cache when a handle has been allocated for a given position.\n\t */\n\tpublic addHandle(position: number, handle: Handle): void {\n\t\tassert(isHandleValid(handle), 0x017 /* \"Trying to add invalid handle!\" */);\n\n\t\tconst index = this.getIndex(position);\n\t\tif (index < this.handles.length) {\n\t\t\tassert(\n\t\t\t\t!isHandleValid(this.handles[index]),\n\t\t\t\t0x018 /* \"Trying to insert handle into position with already valid handle!\" */,\n\t\t\t);\n\t\t\tthis.handles[index] = handle;\n\t\t}\n\t}\n\n\t/**\n\t * Used by {@link HandleCache.cacheMiss} to retrieve handles for a range of positions.\n\t * @param start - The start position (inclusive).\n\t * @param end - The end position (exclusive).\n\t * @param handles - The array to populate with handles. Note that it is mutated in place.\n\t */\n\tprivate getHandles(start: number, end: number, handles: Handle[]): void {\n\t\t// TODO: This can be accelerated substantially using 'walkSegments()'. The only catch\n\t\t// is that\n\n\t\tconst { vector } = this;\n\n\t\tfor (let pos = start; pos < end; pos++) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst { segment, offset } = vector.getContainingSegment(pos)!;\n\t\t\tconst asPerm = segment as PermutationSegment;\n\t\t\thandles.push(asPerm.start + offset);\n\t\t}\n\t}\n\n\tprivate cacheMiss(position: number): Handle {\n\t\t// Coercing 'position' to an Uint32 allows us to handle a negative 'position' value\n\t\t// with the same logic that handles 'position' >= length.\n\t\tconst _position = position >>> 0;\n\n\t\t// TODO: To bound memory usage, there should be a limit on the maximum size of\n\t\t// handle[].\n\n\t\t// TODO: To reduce MergeTree lookups, this code should opportunistically grow\n\t\t// the cache to the next MergeTree segment boundary (within the limits of\n\t\t// the handle cache).\n\n\t\tif (_position < this.start) {\n\t\t\tconst handles: Handle[] = [];\n\t\t\tthis.getHandles(_position, this.start, handles);\n\t\t\thandles.push(...this.handles);\n\t\t\tthis.handles = handles;\n\t\t\tthis.start = _position;\n\t\t\treturn this.handles[0];\n\t\t} else {\n\t\t\tensureRange(_position, this.vector.getLength());\n\t\t\tthis.getHandles(this.start + this.handles.length, _position + 1, this.handles);\n\t\t\treturn this.handles[this.handles.length - 1];\n\t\t}\n\t}\n\n\t// #region IVectorConsumer\n\n\titemsChanged(start: number, removedCount: number, insertedCount: number): void {\n\t\t// If positions were inserted/removed, our current policy is to trim the array\n\t\t// at the beginning of the invalidate range and lazily repopulate the handles\n\t\t// on demand.\n\t\t//\n\t\t// Some alternatives to consider that preserve the previously cached handles\n\t\t// that are still valid:\n\t\t//\n\t\t// * Eagerly populate the 'handles[]' with the newly insert values (currently guaranteed\n\t\t// to be Handle.unallocated, so we don't even need to look them up.)\n\t\t//\n\t\t// * Use a sentinel value or other mechanism to allow \"holes\" in the cache.\n\n\t\tconst index = this.getIndex(start);\n\t\tif (index < this.handles.length) {\n\t\t\tthis.handles.length = index;\n\t\t}\n\t}\n\n\t// #endregion IVectorConsumer\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"handletable.d.ts","sourceRoot":"","sources":["../src/handletable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,0BAAkB,MAAM;IACvB;;OAEG;IACH,IAAI,IAAI;IAER;;OAEG;IACH,KAAK,IAAI;IAET;;;OAGG;IACH,WAAW,cAAc;CACzB;AAED,eAAO,MAAM,aAAa,WAAY,MAAM,KAAG,OAAiC,CAAC;AAEjF;;GAEG;AACH,qBAAa,WAAW,CAAC,CAAC;IAIN,OAAO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AAG,IAAI;IAKjC;;OAEG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,CAAC;IAI7B;;OAEG;IACI,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAM1C,OAAO,KAAK,IAAI,GAEf;IACD,OAAO,KAAK,IAAI,QAEf;IAEM,iBAAiB,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE;WAI5B,IAAI,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,GAAG,WAAW,CAAC,CAAC,CAAC;CAG3D"}
@@ -11,6 +11,7 @@ exports.isHandleValid = isHandleValid;
11
11
  * A handle table provides a fast mapping from an integer `handle` to a value `T`.
12
12
  */
13
13
  class HandleTable {
14
+ handles;
14
15
  // Note: the first slot of the 'handles' array is reserved to store the pointer to the first
15
16
  // free handle. We initialize this slot with a pointer to slot '1', which will cause
16
17
  // us to delay allocate the following slot in the array on the first allocation.
@@ -1 +1 @@
1
- {"version":3,"file":"handletable.js","sourceRoot":"","sources":["../src/handletable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBI,MAAM,aAAa,GAAG,CAAC,MAAc,EAAW,EAAE,CAAC,MAAM,wBAAgB,CAAC;AAApE,QAAA,aAAa,iBAAuD;AAEjF;;GAEG;AACH,MAAa,WAAW;IACvB,4FAA4F;IAC5F,2FAA2F;IAC3F,sFAAsF;IACtF,YAAoC,UAA0B,CAAC,CAAC,CAAC;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAE9D,KAAK;QACX,qFAAqF;QACrF,uFAAuF;QACvF,oBAAoB;QACpB,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IAED;;OAEG;IACI,QAAQ;QACd,wCAAwC;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,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QACvB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAoB;QACzC,OAAO,IAAI,WAAW,CAAI,IAAI,CAAC,CAAC;IACjC,CAAC;CACD;AApFD,kCAoFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum Handle {\n\t/**\n\t * Sentinel representing the absence of a valid handle.\n\t */\n\tnone = 0,\n\n\t/**\n\t * Minimum valid handle.\n\t */\n\tvalid = 1,\n\n\t/**\n\t * Sentinel representing an unallocated Handle. Used by PermutationVector\n\t * to delay allocate handles when previously empty row/cols become populated.\n\t */\n\tunallocated = -0x80000000,\n}\n\nexport const isHandleValid = (handle: Handle): boolean => handle >= Handle.valid;\n\n/**\n * A handle table provides a fast mapping from an integer `handle` to a value `T`.\n */\nexport class HandleTable<T> {\n\t// Note: the first slot of the 'handles' array is reserved to store the pointer to the first\n\t// free handle. We initialize this slot with a pointer to slot '1', which will cause\n\t// us to delay allocate the following slot in the array on the first allocation.\n\tpublic constructor(private readonly handles: (Handle | T)[] = [1]) {}\n\n\tpublic clear(): void {\n\t\t// Restore the HandleTable's initial state by deleting all items in the handles array\n\t\t// and then re-inserting the value '1' in the 0th slot. (See comment at `handles` decl\n\t\t// for explanation.)\n\t\tthis.handles.splice(0, this.handles.length, 1);\n\t}\n\n\t/**\n\t * Allocates and returns the next available handle. Note that freed handles are recycled.\n\t */\n\tpublic allocate(): Handle {\n\t\t// Get the handle to the next free slot.\n\t\tconst free = this.next;\n\n\t\t// Update 'next' to point to the new head of the free list. We use the contents of\n\t\t// recycled slots to store the free list. The contents of the handles[free] will point\n\t\t// to the next available slot. If there are no free slots (i.e., 'handles' is full),\n\t\t// the slot will point to 'handles.length'. In this case, the handles array will grow\n\t\t// and we update 'next' to point to the new end of the array.\n\t\tthis.next = (this.handles[free] as Handle) ?? free + 1;\n\n\t\t// Out of paranoia, overwrite the contents of the newly allocated free slot with an\n\t\t// invalid handle value. This may help catch/diagnose bugs in the event the free list\n\t\t// becomes corrupted.\n\t\tthis.handles[free] = Handle.none;\n\n\t\treturn free;\n\t}\n\n\t/**\n\t * Allocates and returns the next available `count` handles.\n\t */\n\tpublic allocateMany(count: Handle): Uint32Array {\n\t\tconst handles = new Uint32Array(count);\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\thandles[i] = this.allocate();\n\t\t}\n\t\treturn handles;\n\t}\n\n\t/**\n\t * Returns the given handle to the free list.\n\t */\n\tpublic free(handle: Handle): void {\n\t\tthis.handles[handle] = this.next;\n\t\tthis.next = handle;\n\t}\n\n\t/**\n\t * Get the value `T` associated with the given handle, if any.\n\t */\n\tpublic get(handle: Handle): T {\n\t\treturn this.handles[handle] as T;\n\t}\n\n\t/**\n\t * Set the value `T` associated with the given handle.\n\t */\n\tpublic set(handle: Handle, value: T): void {\n\t\tthis.handles[handle] = value;\n\t}\n\n\t// Private helpers to get/set the head of the free list, which is stored in the 0th slot\n\t// of the handle array.\n\tprivate get next(): Handle {\n\t\treturn this.handles[0] as Handle;\n\t}\n\tprivate set next(handle: Handle) {\n\t\tthis.handles[0] = handle;\n\t}\n\n\tpublic getSummaryContent(): (Handle | T)[] {\n\t\treturn this.handles;\n\t}\n\n\tpublic static load<T>(data: (Handle | T)[]): HandleTable<T> {\n\t\treturn new HandleTable<T>(data);\n\t}\n}\n"]}
1
+ {"version":3,"file":"handletable.js","sourceRoot":"","sources":["../src/handletable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAoBI,MAAM,aAAa,GAAG,CAAC,MAAc,EAAW,EAAE,CAAC,MAAM,wBAAgB,CAAC;AAApE,QAAA,aAAa,iBAAuD;AAEjF;;GAEG;AACH,MAAa,WAAW;IAIa;IAHpC,4FAA4F;IAC5F,2FAA2F;IAC3F,sFAAsF;IACtF,YAAoC,UAA0B,CAAC,CAAC,CAAC;QAA7B,YAAO,GAAP,OAAO,CAAsB;IAAG,CAAC;IAE9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C;IAC9B,CAAC;IAED,wFAAwF;IACxF,uBAAuB;IACvB,IAAY,IAAI;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAW,CAAC;IAClC,CAAC;IACD,IAAY,IAAI,CAAC,MAAc;QAC9B,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC;IAC1B,CAAC;IAEM,iBAAiB;QACvB,OAAO,IAAI,CAAC,OAAO,CAAC;IACrB,CAAC;IAEM,MAAM,CAAC,IAAI,CAAI,IAAoB;QACzC,OAAO,IAAI,WAAW,CAAI,IAAI,CAAC,CAAC;IACjC,CAAC;CACD;AApFD,kCAoFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport const enum Handle {\n\t/**\n\t * Sentinel representing the absence of a valid handle.\n\t */\n\tnone = 0,\n\n\t/**\n\t * Minimum valid handle.\n\t */\n\tvalid = 1,\n\n\t/**\n\t * Sentinel representing an unallocated Handle. Used by PermutationVector\n\t * to delay allocate handles when previously empty row/cols become populated.\n\t */\n\tunallocated = -0x80000000,\n}\n\nexport const isHandleValid = (handle: Handle): boolean => handle >= Handle.valid;\n\n/**\n * A handle table provides a fast mapping from an integer `handle` to a value `T`.\n */\nexport class HandleTable<T> {\n\t// Note: the first slot of the 'handles' array is reserved to store the pointer to the first\n\t// free handle. We initialize this slot with a pointer to slot '1', which will cause\n\t// us to delay allocate the following slot in the array on the first allocation.\n\tpublic constructor(private readonly handles: (Handle | T)[] = [1]) {}\n\n\tpublic clear(): void {\n\t\t// Restore the HandleTable's initial state by deleting all items in the handles array\n\t\t// and then re-inserting the value '1' in the 0th slot. (See comment at `handles` decl\n\t\t// for explanation.)\n\t\tthis.handles.splice(0, this.handles.length, 1);\n\t}\n\n\t/**\n\t * Allocates and returns the next available handle. Note that freed handles are recycled.\n\t */\n\tpublic allocate(): Handle {\n\t\t// Get the handle to the next free slot.\n\t\tconst free = this.next;\n\n\t\t// Update 'next' to point to the new head of the free list. We use the contents of\n\t\t// recycled slots to store the free list. The contents of the handles[free] will point\n\t\t// to the next available slot. If there are no free slots (i.e., 'handles' is full),\n\t\t// the slot will point to 'handles.length'. In this case, the handles array will grow\n\t\t// and we update 'next' to point to the new end of the array.\n\t\tthis.next = (this.handles[free] as Handle) ?? free + 1;\n\n\t\t// Out of paranoia, overwrite the contents of the newly allocated free slot with an\n\t\t// invalid handle value. This may help catch/diagnose bugs in the event the free list\n\t\t// becomes corrupted.\n\t\tthis.handles[free] = Handle.none;\n\n\t\treturn free;\n\t}\n\n\t/**\n\t * Allocates and returns the next available `count` handles.\n\t */\n\tpublic allocateMany(count: Handle): Uint32Array {\n\t\tconst handles = new Uint32Array(count);\n\t\tfor (let i = 0; i < count; i++) {\n\t\t\thandles[i] = this.allocate();\n\t\t}\n\t\treturn handles;\n\t}\n\n\t/**\n\t * Returns the given handle to the free list.\n\t */\n\tpublic free(handle: Handle): void {\n\t\tthis.handles[handle] = this.next;\n\t\tthis.next = handle;\n\t}\n\n\t/**\n\t * Get the value `T` associated with the given handle, if any.\n\t */\n\tpublic get(handle: Handle): T {\n\t\treturn this.handles[handle] as T;\n\t}\n\n\t/**\n\t * Set the value `T` associated with the given handle.\n\t */\n\tpublic set(handle: Handle, value: T): void {\n\t\tthis.handles[handle] = value;\n\t}\n\n\t// Private helpers to get/set the head of the free list, which is stored in the 0th slot\n\t// of the handle array.\n\tprivate get next(): Handle {\n\t\treturn this.handles[0] as Handle;\n\t}\n\tprivate set next(handle: Handle) {\n\t\tthis.handles[0] = handle;\n\t}\n\n\tpublic getSummaryContent(): (Handle | T)[] {\n\t\treturn this.handles;\n\t}\n\n\tpublic static load<T>(data: (Handle | T)[]): HandleTable<T> {\n\t\treturn new HandleTable<T>(data);\n\t}\n}\n"]}
package/dist/matrix.js CHANGED
@@ -38,6 +38,28 @@ const undoprovider_js_1 = require("./undoprovider.js");
38
38
  // TODO: if possible, transition SharedMatrix to not use `any`.
39
39
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
40
40
  class SharedMatrix extends internal_4.SharedObject {
41
+ id;
42
+ consumers = new Set();
43
+ /**
44
+ * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.
45
+ * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process
46
+ * incoming leave/join ops before putting an op that this DDS submits over the wire.
47
+ *
48
+ * E.g. SharedMatrix submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime
49
+ * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber
50
+ * on the SharedMatrix op is 11.
51
+ */
52
+ inFlightRefSeqs = new double_ended_queue_1.default();
53
+ getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);
54
+ rows; // Map logical row to storage handle (if any)
55
+ cols; // Map logical col to storage handle (if any)
56
+ cells = new sparsearray2d_js_1.SparseArray2D(); // Stores cell values.
57
+ pending = new sparsearray2d_js_1.SparseArray2D(); // Tracks pending writes.
58
+ fwwPolicy = {
59
+ state: "off",
60
+ };
61
+ // Used to track if there is any reentrancy in setCell code.
62
+ reentrantCount = 0;
41
63
  /**
42
64
  * Constructor for the Shared Matrix
43
65
  * @param runtime - DataStore runtime.
@@ -49,62 +71,10 @@ class SharedMatrix extends internal_4.SharedObject {
49
71
  constructor(runtime, id, attributes) {
50
72
  super(id, runtime, attributes, "fluid_matrix_");
51
73
  this.id = id;
52
- this.consumers = new Set();
53
- /**
54
- * Note: this field only provides a lower-bound on the reference sequence numbers for in-flight ops.
55
- * The exact reason isn't understood, but some e2e tests suggest that the runtime may sometimes process
56
- * incoming leave/join ops before putting an op that this DDS submits over the wire.
57
- *
58
- * E.g. SharedMatrix submits an op while deltaManager has lastSequenceNumber = 10, but before the runtime
59
- * puts this op over the wire, it processes a client join/leave op with sequence number 11, so the referenceSequenceNumber
60
- * on the SharedMatrix op is 11.
61
- */
62
- this.inFlightRefSeqs = new double_ended_queue_1.default();
63
- this.getMinInFlightRefSeq = () => this.inFlightRefSeqs.get(0);
64
- this.cells = new sparsearray2d_js_1.SparseArray2D(); // Stores cell values.
65
- this.pending = new sparsearray2d_js_1.SparseArray2D(); // Tracks pending writes.
66
- this.fwwPolicy = {
67
- state: "off",
68
- };
69
- // Used to track if there is any reentrancy in setCell code.
70
- this.reentrantCount = 0;
71
- // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.
72
- this.onRowDelta = (position, removedCount, insertedCount) => {
73
- for (const consumer of this.consumers) {
74
- consumer.rowsChanged(position, removedCount, insertedCount, this);
75
- }
76
- };
77
- // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.
78
- this.onColDelta = (position, removedCount, insertedCount) => {
79
- for (const consumer of this.consumers) {
80
- consumer.colsChanged(position, removedCount, insertedCount, this);
81
- }
82
- };
83
- this.onRowHandlesRecycled = (rowHandles) => {
84
- for (const rowHandle of rowHandles) {
85
- this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);
86
- this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);
87
- if (this.fwwPolicy.state === "on") {
88
- this.fwwPolicy.cellLastWriteTracker?.clearRows(
89
- /* rowStart: */ rowHandle,
90
- /* rowCount: */ 1);
91
- }
92
- }
93
- };
94
- this.onColHandlesRecycled = (colHandles) => {
95
- for (const colHandle of colHandles) {
96
- this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);
97
- this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);
98
- if (this.fwwPolicy.state === "on") {
99
- this.fwwPolicy.cellLastWriteTracker?.clearCols(
100
- /* colStart: */ colHandle,
101
- /* colCount: */ 1);
102
- }
103
- }
104
- };
105
74
  this.rows = new permutationvector_js_1.PermutationVector(ops_js_1.SnapshotPath.rows, this.logger, runtime, this.onRowDelta, this.onRowHandlesRecycled, this.getMinInFlightRefSeq);
106
75
  this.cols = new permutationvector_js_1.PermutationVector(ops_js_1.SnapshotPath.cols, this.logger, runtime, this.onColDelta, this.onColHandlesRecycled, this.getMinInFlightRefSeq);
107
76
  }
77
+ undo;
108
78
  /**
109
79
  * Subscribes the given IUndoConsumer to the matrix.
110
80
  */
@@ -705,6 +675,40 @@ class SharedMatrix extends internal_4.SharedObject {
705
675
  }
706
676
  }
707
677
  }
678
+ // Invoked by PermutationVector to notify IMatrixConsumers of row insertion/deletions.
679
+ onRowDelta = (position, removedCount, insertedCount) => {
680
+ for (const consumer of this.consumers) {
681
+ consumer.rowsChanged(position, removedCount, insertedCount, this);
682
+ }
683
+ };
684
+ // Invoked by PermutationVector to notify IMatrixConsumers of col insertion/deletions.
685
+ onColDelta = (position, removedCount, insertedCount) => {
686
+ for (const consumer of this.consumers) {
687
+ consumer.colsChanged(position, removedCount, insertedCount, this);
688
+ }
689
+ };
690
+ onRowHandlesRecycled = (rowHandles) => {
691
+ for (const rowHandle of rowHandles) {
692
+ this.cells.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);
693
+ this.pending.clearRows(/* rowStart: */ rowHandle, /* rowCount: */ 1);
694
+ if (this.fwwPolicy.state === "on") {
695
+ this.fwwPolicy.cellLastWriteTracker?.clearRows(
696
+ /* rowStart: */ rowHandle,
697
+ /* rowCount: */ 1);
698
+ }
699
+ }
700
+ };
701
+ onColHandlesRecycled = (colHandles) => {
702
+ for (const colHandle of colHandles) {
703
+ this.cells.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);
704
+ this.pending.clearCols(/* colStart: */ colHandle, /* colCount: */ 1);
705
+ if (this.fwwPolicy.state === "on") {
706
+ this.fwwPolicy.cellLastWriteTracker?.clearCols(
707
+ /* colStart: */ colHandle,
708
+ /* colCount: */ 1);
709
+ }
710
+ }
711
+ };
708
712
  switchSetCellPolicy() {
709
713
  if (this.fwwPolicy.state === "off") {
710
714
  this.fwwPolicy = this.isAttached()