@fluidframework/matrix 2.1.0-276985 → 2.1.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 (88) hide show
  1. package/.eslintrc.cjs +2 -5
  2. package/CHANGELOG.md +4 -0
  3. package/api-extractor/api-extractor.current.json +5 -0
  4. package/api-extractor/api-extractor.legacy.json +1 -1
  5. package/api-extractor.json +1 -1
  6. package/api-report/matrix.legacy.public.api.md +9 -0
  7. package/dist/handlecache.d.ts +7 -3
  8. package/dist/handlecache.d.ts.map +1 -1
  9. package/dist/handlecache.js +25 -7
  10. package/dist/handlecache.js.map +1 -1
  11. package/dist/handletable.d.ts +3 -1
  12. package/dist/handletable.d.ts.map +1 -1
  13. package/dist/handletable.js.map +1 -1
  14. package/dist/legacy.d.ts +1 -1
  15. package/dist/matrix.d.ts +2 -1
  16. package/dist/matrix.d.ts.map +1 -1
  17. package/dist/matrix.js +23 -9
  18. package/dist/matrix.js.map +1 -1
  19. package/dist/packageVersion.d.ts +1 -1
  20. package/dist/packageVersion.d.ts.map +1 -1
  21. package/dist/packageVersion.js +1 -1
  22. package/dist/packageVersion.js.map +1 -1
  23. package/dist/permutationvector.d.ts +5 -5
  24. package/dist/permutationvector.d.ts.map +1 -1
  25. package/dist/permutationvector.js +11 -4
  26. package/dist/permutationvector.js.map +1 -1
  27. package/dist/public.d.ts +1 -1
  28. package/dist/range.d.ts.map +1 -1
  29. package/dist/range.js.map +1 -1
  30. package/dist/runtime.d.ts.map +1 -1
  31. package/dist/runtime.js.map +1 -1
  32. package/dist/serialization.d.ts.map +1 -1
  33. package/dist/serialization.js.map +1 -1
  34. package/dist/sparsearray2d.d.ts +9 -5
  35. package/dist/sparsearray2d.d.ts.map +1 -1
  36. package/dist/sparsearray2d.js +27 -7
  37. package/dist/sparsearray2d.js.map +1 -1
  38. package/dist/undoprovider.d.ts.map +1 -1
  39. package/dist/undoprovider.js +10 -3
  40. package/dist/undoprovider.js.map +1 -1
  41. package/internal.d.ts +1 -1
  42. package/legacy.d.ts +1 -1
  43. package/lib/handlecache.d.ts +7 -3
  44. package/lib/handlecache.d.ts.map +1 -1
  45. package/lib/handlecache.js +25 -7
  46. package/lib/handlecache.js.map +1 -1
  47. package/lib/handletable.d.ts +3 -1
  48. package/lib/handletable.d.ts.map +1 -1
  49. package/lib/handletable.js.map +1 -1
  50. package/lib/legacy.d.ts +1 -1
  51. package/lib/matrix.d.ts +2 -1
  52. package/lib/matrix.d.ts.map +1 -1
  53. package/lib/matrix.js +23 -9
  54. package/lib/matrix.js.map +1 -1
  55. package/lib/packageVersion.d.ts +1 -1
  56. package/lib/packageVersion.d.ts.map +1 -1
  57. package/lib/packageVersion.js +1 -1
  58. package/lib/packageVersion.js.map +1 -1
  59. package/lib/permutationvector.d.ts +5 -5
  60. package/lib/permutationvector.d.ts.map +1 -1
  61. package/lib/permutationvector.js +11 -4
  62. package/lib/permutationvector.js.map +1 -1
  63. package/lib/public.d.ts +1 -1
  64. package/lib/range.d.ts.map +1 -1
  65. package/lib/range.js.map +1 -1
  66. package/lib/runtime.d.ts.map +1 -1
  67. package/lib/runtime.js.map +1 -1
  68. package/lib/serialization.d.ts.map +1 -1
  69. package/lib/serialization.js.map +1 -1
  70. package/lib/sparsearray2d.d.ts +9 -5
  71. package/lib/sparsearray2d.d.ts.map +1 -1
  72. package/lib/sparsearray2d.js +27 -7
  73. package/lib/sparsearray2d.js.map +1 -1
  74. package/lib/undoprovider.d.ts.map +1 -1
  75. package/lib/undoprovider.js +10 -3
  76. package/lib/undoprovider.js.map +1 -1
  77. package/package.json +36 -30
  78. package/src/handlecache.ts +31 -16
  79. package/src/handletable.ts +11 -9
  80. package/src/matrix.ts +80 -50
  81. package/src/packageVersion.ts +1 -1
  82. package/src/permutationvector.ts +38 -23
  83. package/src/range.ts +1 -1
  84. package/src/runtime.ts +5 -2
  85. package/src/serialization.ts +4 -2
  86. package/src/sparsearray2d.ts +55 -36
  87. package/src/undoprovider.ts +26 -18
  88. package/tsconfig.json +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/matrix",
3
- "version": "2.1.0-276985",
3
+ "version": "2.1.0",
4
4
  "description": "Distributed matrix",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -63,35 +63,35 @@
63
63
  "temp-directory": "nyc/.nyc_output"
64
64
  },
65
65
  "dependencies": {
66
- "@fluid-internal/client-utils": "2.1.0-276985",
67
- "@fluidframework/core-interfaces": "2.1.0-276985",
68
- "@fluidframework/core-utils": "2.1.0-276985",
69
- "@fluidframework/datastore-definitions": "2.1.0-276985",
70
- "@fluidframework/driver-definitions": "2.1.0-276985",
71
- "@fluidframework/driver-utils": "2.1.0-276985",
72
- "@fluidframework/merge-tree": "2.1.0-276985",
73
- "@fluidframework/runtime-definitions": "2.1.0-276985",
74
- "@fluidframework/runtime-utils": "2.1.0-276985",
75
- "@fluidframework/shared-object-base": "2.1.0-276985",
76
- "@fluidframework/telemetry-utils": "2.1.0-276985",
66
+ "@fluid-internal/client-utils": "~2.1.0",
67
+ "@fluidframework/core-interfaces": "~2.1.0",
68
+ "@fluidframework/core-utils": "~2.1.0",
69
+ "@fluidframework/datastore-definitions": "~2.1.0",
70
+ "@fluidframework/driver-definitions": "~2.1.0",
71
+ "@fluidframework/driver-utils": "~2.1.0",
72
+ "@fluidframework/merge-tree": "~2.1.0",
73
+ "@fluidframework/runtime-definitions": "~2.1.0",
74
+ "@fluidframework/runtime-utils": "~2.1.0",
75
+ "@fluidframework/shared-object-base": "~2.1.0",
76
+ "@fluidframework/telemetry-utils": "~2.1.0",
77
77
  "@tiny-calc/nano": "0.0.0-alpha.5",
78
78
  "double-ended-queue": "^2.1.0-0",
79
79
  "tslib": "^1.10.0"
80
80
  },
81
81
  "devDependencies": {
82
82
  "@arethetypeswrong/cli": "^0.15.2",
83
- "@biomejs/biome": "^1.7.3",
84
- "@fluid-internal/mocha-test-setup": "2.1.0-276985",
85
- "@fluid-private/stochastic-test-utils": "2.1.0-276985",
86
- "@fluid-private/test-dds-utils": "2.1.0-276985",
83
+ "@biomejs/biome": "~1.8.3",
84
+ "@fluid-internal/mocha-test-setup": "~2.1.0",
85
+ "@fluid-private/stochastic-test-utils": "~2.1.0",
86
+ "@fluid-private/test-dds-utils": "~2.1.0",
87
87
  "@fluid-tools/benchmark": "^0.48.0",
88
- "@fluid-tools/build-cli": "^0.39.0",
88
+ "@fluid-tools/build-cli": "^0.41.0",
89
89
  "@fluidframework/build-common": "^2.0.3",
90
- "@fluidframework/build-tools": "^0.39.0",
91
- "@fluidframework/container-definitions": "2.1.0-276985",
90
+ "@fluidframework/build-tools": "^0.41.0",
91
+ "@fluidframework/container-definitions": "~2.1.0",
92
92
  "@fluidframework/eslint-config-fluid": "^5.3.0",
93
- "@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.0.0-rc.5.0.0",
94
- "@fluidframework/test-runtime-utils": "2.1.0-276985",
93
+ "@fluidframework/matrix-previous": "npm:@fluidframework/matrix@2.0.0",
94
+ "@fluidframework/test-runtime-utils": "~2.1.0",
95
95
  "@microsoft/api-extractor": "^7.45.1",
96
96
  "@tiny-calc/micro": "0.0.0-alpha.5",
97
97
  "@types/double-ended-queue": "^2.1.0",
@@ -115,7 +115,11 @@
115
115
  "typescript": "~5.4.5"
116
116
  },
117
117
  "typeValidation": {
118
- "broken": {}
118
+ "broken": {
119
+ "Variable_SharedMatrix": {
120
+ "forwardCompat": false
121
+ }
122
+ }
119
123
  },
120
124
  "scripts": {
121
125
  "api": "fluid-build . --task api",
@@ -124,18 +128,19 @@
124
128
  "bench": "cd bench && node --expose-gc -r ts-node/register src/index.ts",
125
129
  "bench:profile": "cd bench && node -r ts-node/register --prof --logfile=profile.log --no-logfile-per-isolate src/index.ts --runInBand && node --prof-process profile.log > profile.txt && rimraf profile.log && echo See results in bench/profile.txt",
126
130
  "build": "fluid-build . --task build",
131
+ "build:api-reports": "concurrently \"npm:build:api-reports:*\"",
132
+ "build:api-reports:current": "api-extractor run --local --config api-extractor/api-extractor.current.json",
133
+ "build:api-reports:legacy": "api-extractor run --local --config api-extractor/api-extractor.legacy.json",
127
134
  "build:commonjs": "fluid-build . --task commonjs",
128
135
  "build:compile": "fluid-build . --task compile",
129
- "build:docs": "concurrently \"npm:build:docs:*\"",
130
- "build:docs:current": "api-extractor run --local",
131
- "build:docs:legacy": "api-extractor run --local --config api-extractor/api-extractor.legacy.json",
136
+ "build:docs": "api-extractor run --local",
132
137
  "build:esnext": "tsc --project ./tsconfig.json",
133
138
  "build:genver": "gen-version",
134
139
  "build:test": "npm run build:test:esm && npm run build:test:cjs",
135
140
  "build:test:cjs": "fluid-tsc commonjs --project ./src/test/tsconfig.cjs.json",
136
141
  "build:test:esm": "tsc --project ./src/test/tsconfig.json",
137
142
  "check:are-the-types-wrong": "attw --pack .",
138
- "check:biome": "biome check . --formatter-enabled=true",
143
+ "check:biome": "biome check .",
139
144
  "check:exports": "concurrently \"npm:check:exports:*\"",
140
145
  "check:exports:bundle-release-tags": "api-extractor run --config api-extractor/api-extractor-lint-bundle.json",
141
146
  "check:exports:cjs:legacy": "api-extractor run --config api-extractor/api-extractor-lint-legacy.cjs.json",
@@ -144,14 +149,15 @@
144
149
  "check:exports:esm:public": "api-extractor run --config api-extractor/api-extractor-lint-public.esm.json",
145
150
  "check:format": "npm run check:biome",
146
151
  "check:prettier": "prettier --check . --cache --ignore-path ../../../.prettierignore",
147
- "ci:build:docs": "concurrently \"npm:ci:build:docs:*\"",
148
- "ci:build:docs:current": "api-extractor run",
149
- "ci:build:docs:legacy": "api-extractor run --config api-extractor/api-extractor.legacy.json",
152
+ "ci:build:api-reports": "concurrently \"npm:ci:build:api-reports:*\"",
153
+ "ci:build:api-reports:current": "api-extractor run --config api-extractor/api-extractor.current.json",
154
+ "ci:build:api-reports:legacy": "api-extractor run --config api-extractor/api-extractor.legacy.json",
155
+ "ci:build:docs": "api-extractor run",
150
156
  "clean": "rimraf --glob dist lib \"*.d.ts\" bench/dist \"**/*.tsbuildinfo\" \"**/*.build.log\" _api-extractor-temp nyc",
151
157
  "eslint": "eslint --format stylish src",
152
158
  "eslint:fix": "eslint --format stylish src --fix --fix-type problem,suggestion,layout",
153
159
  "format": "npm run format:biome",
154
- "format:biome": "biome check . --formatter-enabled=true --apply",
160
+ "format:biome": "biome check . --write",
155
161
  "format:prettier": "prettier --write . --cache --ignore-path ../../../.prettierignore",
156
162
  "lint": "fluid-build . --task lint",
157
163
  "lint:fix": "fluid-build . --task eslint:fix --task format",
@@ -28,7 +28,7 @@ export class HandleCache implements IVectorConsumer<Handle> {
28
28
  * Returns the index of the given position in the 'handles' array as a Uint32.
29
29
  * (If the position is not in the array, returns an integer greater than 'handles.length').
30
30
  */
31
- private getIndex(position: number) {
31
+ private getIndex(position: number): number {
32
32
  return (position - this.start) >>> 0;
33
33
  }
34
34
 
@@ -37,10 +37,10 @@ export class HandleCache implements IVectorConsumer<Handle> {
37
37
  * the result with 'isValidHandle(..)' to see if a handle has been allocated for
38
38
  * the given position.
39
39
  *
40
- * Throws a 'RangeError' if the provided 'position' is out-of-bounds wrt. the
40
+ * @throws A 'RangeError' if the provided 'position' is out-of-bounds with regards to the
41
41
  * PermutationVector's length.
42
42
  */
43
- public getHandle(position: number) {
43
+ public getHandle(position: number): Handle {
44
44
  const index = this.getIndex(position);
45
45
 
46
46
  // Perf: To encourage inlining, handling of the 'cacheMiss(..)' case has been extracted
@@ -50,25 +50,35 @@ export class HandleCache implements IVectorConsumer<Handle> {
50
50
  // checking that 'position' is in bounds until 'cacheMiss(..)'. This yields an
51
51
  // ~40% speedup when the position is in the cache (node v12 x64).
52
52
 
53
- return index < this.handles.length ? this.handles[index] : this.cacheMiss(position);
53
+ const handle = this.handles[index];
54
+ if (handle !== undefined) {
55
+ return handle;
56
+ }
57
+ return this.cacheMiss(position);
54
58
  }
55
59
 
56
- /** Update the cache when a handle has been allocated for a given position. */
57
- public addHandle(position: number, handle: Handle) {
60
+ /**
61
+ * Update the cache when a handle has been allocated for a given position.
62
+ */
63
+ public addHandle(position: number, handle: Handle): void {
58
64
  assert(isHandleValid(handle), 0x017 /* "Trying to add invalid handle!" */);
59
65
 
60
66
  const index = this.getIndex(position);
61
67
  if (index < this.handles.length) {
62
68
  assert(
63
- !isHandleValid(this.handles[index]),
69
+ // Non null asserting, above we checked that the index is less than the length.
70
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
71
+ !isHandleValid(this.handles[index]!),
64
72
  0x018 /* "Trying to insert handle into position with already valid handle!" */,
65
73
  );
66
74
  this.handles[index] = handle;
67
75
  }
68
76
  }
69
77
 
70
- /** Used by 'CacheMiss()' to retrieve handles for a range of positions. */
71
- private getHandles(start: number, end: number) {
78
+ /**
79
+ * Used by {@link HandleCache.cacheMiss} to retrieve handles for a range of positions.
80
+ */
81
+ private getHandles(start: number, end: number): Handle[] {
72
82
  // TODO: This can be accelerated substantially using 'walkSegments()'. The only catch
73
83
  // is that
74
84
 
@@ -85,7 +95,7 @@ export class HandleCache implements IVectorConsumer<Handle> {
85
95
  return handles;
86
96
  }
87
97
 
88
- private cacheMiss(position: number) {
98
+ private cacheMiss(position: number): Handle {
89
99
  // Coercing 'position' to an Uint32 allows us to handle a negative 'position' value
90
100
  // with the same logic that handles 'position' >= length.
91
101
  const _position = position >>> 0;
@@ -98,16 +108,21 @@ export class HandleCache implements IVectorConsumer<Handle> {
98
108
  // the handle cache).
99
109
 
100
110
  if (_position < this.start) {
101
- this.handles = this.getHandles(_position, this.start).concat(this.handles);
111
+ this.handles = [...this.getHandles(_position, this.start), ...this.handles];
102
112
  this.start = _position;
103
- return this.handles[0];
113
+ // TODO why are we non null asserting here?
114
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
115
+ return this.handles[0]!;
104
116
  } else {
105
117
  ensureRange(_position, this.vector.getLength());
106
118
 
107
- this.handles = this.handles.concat(
108
- this.getHandles(this.start + this.handles.length, _position + 1),
109
- );
110
- return this.handles[this.handles.length - 1];
119
+ this.handles = [
120
+ ...this.handles,
121
+ ...this.getHandles(this.start + this.handles.length, _position + 1),
122
+ ];
123
+ // TODO why are we non null asserting here?
124
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
125
+ return this.handles[this.handles.length - 1]!;
111
126
  }
112
127
  }
113
128
 
@@ -9,7 +9,9 @@ export const enum Handle {
9
9
  */
10
10
  none = 0,
11
11
 
12
- /** Minimum valid handle. */
12
+ /**
13
+ * Minimum valid handle.
14
+ */
13
15
  valid = 1,
14
16
 
15
17
  /**
@@ -19,7 +21,7 @@ export const enum Handle {
19
21
  unallocated = -0x80000000,
20
22
  }
21
23
 
22
- export const isHandleValid = (handle: Handle) => handle >= Handle.valid;
24
+ export const isHandleValid = (handle: Handle): boolean => handle >= Handle.valid;
23
25
 
24
26
  /**
25
27
  * A handle table provides a fast mapping from an integer `handle` to a value `T`.
@@ -30,7 +32,7 @@ export class HandleTable<T> {
30
32
  // us to delay allocate the following slot in the array on the first allocation.
31
33
  public constructor(private readonly handles: (Handle | T)[] = [1]) {}
32
34
 
33
- public clear() {
35
+ public clear(): void {
34
36
  // Restore the HandleTable's initial state by deleting all items in the handles array
35
37
  // and then re-inserting the value '1' in the 0th slot. (See comment at `handles` decl
36
38
  // for explanation.)
@@ -62,7 +64,7 @@ export class HandleTable<T> {
62
64
  /**
63
65
  * Allocates and returns the next available `count` handles.
64
66
  */
65
- public allocateMany(count: Handle) {
67
+ public allocateMany(count: Handle): Uint32Array {
66
68
  const handles = new Uint32Array(count);
67
69
  for (let i = 0; i < count; i++) {
68
70
  handles[i] = this.allocate();
@@ -73,7 +75,7 @@ export class HandleTable<T> {
73
75
  /**
74
76
  * Returns the given handle to the free list.
75
77
  */
76
- public free(handle: Handle) {
78
+ public free(handle: Handle): void {
77
79
  this.handles[handle] = this.next;
78
80
  this.next = handle;
79
81
  }
@@ -88,24 +90,24 @@ export class HandleTable<T> {
88
90
  /**
89
91
  * Set the value `T` associated with the given handle.
90
92
  */
91
- public set(handle: Handle, value: T) {
93
+ public set(handle: Handle, value: T): void {
92
94
  this.handles[handle] = value;
93
95
  }
94
96
 
95
97
  // Private helpers to get/set the head of the free list, which is stored in the 0th slot
96
98
  // of the handle array.
97
- private get next() {
99
+ private get next(): Handle {
98
100
  return this.handles[0] as Handle;
99
101
  }
100
102
  private set next(handle: Handle) {
101
103
  this.handles[0] = handle;
102
104
  }
103
105
 
104
- public getSummaryContent() {
106
+ public getSummaryContent(): (Handle | T)[] {
105
107
  return this.handles;
106
108
  }
107
109
 
108
- public static load<T>(data: (Handle | T)[]) {
110
+ public static load<T>(data: (Handle | T)[]): HandleTable<T> {
109
111
  return new HandleTable<T>(data);
110
112
  }
111
113
  }