@fluidframework/matrix 2.0.0-internal.7.3.0 → 2.0.0-internal.7.4.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 (68) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +39 -0
  3. package/api-extractor-lint.json +13 -0
  4. package/api-extractor.json +8 -3
  5. package/api-report/matrix.api.md +19 -9
  6. package/dist/index.cjs.map +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/matrix-alpha.d.ts +71 -11
  10. package/dist/matrix-beta.d.ts +41 -134
  11. package/dist/matrix-public.d.ts +41 -134
  12. package/dist/matrix-untrimmed.d.ts +71 -11
  13. package/dist/matrix.cjs +175 -46
  14. package/dist/matrix.cjs.map +1 -1
  15. package/dist/matrix.d.ts +67 -9
  16. package/dist/matrix.d.ts.map +1 -1
  17. package/dist/ops.cjs +1 -0
  18. package/dist/ops.cjs.map +1 -1
  19. package/dist/ops.d.ts +5 -1
  20. package/dist/ops.d.ts.map +1 -1
  21. package/dist/packageVersion.cjs +1 -1
  22. package/dist/packageVersion.cjs.map +1 -1
  23. package/dist/packageVersion.d.ts +1 -1
  24. package/dist/runtime.cjs +1 -1
  25. package/dist/runtime.cjs.map +1 -1
  26. package/dist/runtime.d.ts +1 -1
  27. package/dist/types.cjs.map +1 -1
  28. package/dist/types.d.ts +2 -2
  29. package/lib/handlecache.d.ts +2 -2
  30. package/lib/handlecache.d.ts.map +1 -1
  31. package/lib/index.d.ts +3 -3
  32. package/lib/index.d.ts.map +1 -1
  33. package/lib/index.mjs.map +1 -1
  34. package/lib/matrix-alpha.d.ts +71 -11
  35. package/lib/matrix-beta.d.ts +41 -134
  36. package/lib/matrix-public.d.ts +41 -134
  37. package/lib/matrix-untrimmed.d.ts +71 -11
  38. package/lib/matrix.d.ts +69 -11
  39. package/lib/matrix.d.ts.map +1 -1
  40. package/lib/matrix.mjs +175 -46
  41. package/lib/matrix.mjs.map +1 -1
  42. package/lib/ops.d.ts +5 -1
  43. package/lib/ops.d.ts.map +1 -1
  44. package/lib/ops.mjs +1 -0
  45. package/lib/ops.mjs.map +1 -1
  46. package/lib/packageVersion.d.ts +1 -1
  47. package/lib/packageVersion.mjs +1 -1
  48. package/lib/packageVersion.mjs.map +1 -1
  49. package/lib/permutationvector.d.ts +3 -3
  50. package/lib/permutationvector.d.ts.map +1 -1
  51. package/lib/runtime.d.ts +1 -1
  52. package/lib/runtime.d.ts.map +1 -1
  53. package/lib/runtime.mjs +1 -1
  54. package/lib/runtime.mjs.map +1 -1
  55. package/lib/serialization.d.ts.map +1 -1
  56. package/lib/sparsearray2d.d.ts.map +1 -1
  57. package/lib/types.d.ts +2 -2
  58. package/lib/types.mjs.map +1 -1
  59. package/lib/undoprovider.d.ts +4 -4
  60. package/lib/undoprovider.d.ts.map +1 -1
  61. package/matrix.test-files.tar +0 -0
  62. package/package.json +26 -31
  63. package/src/index.ts +1 -1
  64. package/src/matrix.ts +282 -60
  65. package/src/ops.ts +5 -0
  66. package/src/packageVersion.ts +1 -1
  67. package/src/runtime.ts +1 -1
  68. package/src/types.ts +2 -2
@@ -3,6 +3,7 @@ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
3
3
  import { IChannelFactory } from '@fluidframework/datastore-definitions';
4
4
  import { IChannelServices } from '@fluidframework/datastore-definitions';
5
5
  import { IChannelStorageService } from '@fluidframework/datastore-definitions';
6
+ import { IEventThisPlaceHolder } from '@fluidframework/core-interfaces';
6
7
  import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
7
8
  import { IFluidSerializer } from '@fluidframework/shared-object-base';
8
9
  import { IJSONSegment } from '@fluidframework/merge-tree';
@@ -11,144 +12,50 @@ import { IMatrixProducer } from '@tiny-calc/nano';
11
12
  import { IMatrixReader } from '@tiny-calc/nano';
12
13
  import { IMatrixWriter } from '@tiny-calc/nano';
13
14
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
14
16
  import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
15
17
  import { Serializable } from '@fluidframework/datastore-definitions';
16
18
  import { SharedObject } from '@fluidframework/shared-object-base';
17
19
  import { SummarySerializer } from '@fluidframework/shared-object-base';
18
20
 
19
- /**
20
- * @public
21
- */
22
- export declare interface IRevertible {
23
- revert(): any;
24
- discard(): any;
25
- }
26
-
27
- /**
28
- * @public
29
- */
30
- export declare interface IUndoConsumer {
31
- pushToCurrentOperation(revertible: IRevertible): any;
32
- }
33
-
34
- /**
35
- * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,
36
- * excluding null. (However, nulls may be embedded inside objects and arrays.)
37
- * @public
38
- */
39
- export declare type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;
40
-
41
- /**
42
- * A SharedMatrix holds a rectangular 2D array of values. Supported operations
43
- * include setting values and inserting/removing rows and columns.
44
- *
45
- * Matrix values may be any Fluid serializable type, which is the set of JSON
46
- * serializable types extended to include IFluidHandles.
47
- *
48
- * Fluid's SharedMatrix implementation works equally well for dense and sparse
49
- * matrix data and physically stores data in Z-order to leverage CPU caches and
50
- * prefetching when reading in either row or column major order. (See README.md
51
- * for more details.)
52
- *
53
- * @public
54
- */
55
- export declare class SharedMatrix<T = any> extends SharedObject implements IMatrixProducer<MatrixItem<T>>, IMatrixReader<MatrixItem<T>>, IMatrixWriter<MatrixItem<T>> {
56
- id: string;
57
- private readonly consumers;
58
- static getFactory(): SharedMatrixFactory;
59
- private readonly rows;
60
- private readonly cols;
61
- private cells;
62
- private pending;
63
- constructor(runtime: IFluidDataStoreRuntime, id: string, attributes: IChannelAttributes);
64
- private undo?;
65
- /**
66
- * Subscribes the given IUndoConsumer to the matrix.
67
- */
68
- openUndo(consumer: IUndoConsumer): void;
69
- private get rowHandles();
70
- private get colHandles();
71
- /**
72
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.create}
73
- */
74
- static create<T>(runtime: IFluidDataStoreRuntime, id?: string): SharedMatrix<T>;
75
- openMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): IMatrixReader<MatrixItem<T>>;
76
- closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void;
77
- get rowCount(): number;
78
- get colCount(): number;
79
- getCell(row: number, col: number): MatrixItem<T>;
80
- get matrixProducer(): IMatrixProducer<MatrixItem<T>>;
81
- setCell(row: number, col: number, value: MatrixItem<T>): void;
82
- setCells(rowStart: number, colStart: number, colCount: number, values: readonly MatrixItem<T>[]): void;
83
- private setCellCore;
84
- private sendSetCellOp;
85
- private submitVectorMessage;
86
- private submitColMessage;
87
- insertCols(colStart: number, count: number): void;
88
- removeCols(colStart: number, count: number): void;
89
- private submitRowMessage;
90
- insertRows(rowStart: number, count: number): void;
91
- removeRows(rowStart: number, count: number): void;
92
- /* Excluded from this release type: _undoRemoveRows */
93
- /* Excluded from this release type: _undoRemoveCols */
94
- protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
95
- /**
96
- * Runs serializer on the GC data for this SharedMatrix.
97
- * All the IFluidHandle's stored in the cells represent routes to other objects.
98
- */
99
- protected processGCDataCore(serializer: SummarySerializer): void;
100
- /**
101
- * Advances the 'localSeq' counter for the cell data operation currently being queued.
102
- *
103
- * Do not use with 'submitColMessage()/submitRowMessage()' as these helpers + the MergeTree will
104
- * automatically advance 'localSeq'.
105
- */
106
- private nextLocalSeq;
107
- protected submitLocalMessage(message: any, localOpMetadata?: any): void;
108
- protected didAttach(): void;
109
- protected onConnect(): void;
110
- private rebasePosition;
111
- protected reSubmitCore(content: any, localOpMetadata: unknown): void;
112
- protected onDisconnect(): void;
113
- /**
114
- * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
115
- */
116
- protected loadCore(storage: IChannelStorageService): Promise<void>;
117
- protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
118
- private readonly onRowDelta;
119
- private readonly onColDelta;
120
- private readonly onRowHandlesRecycled;
121
- private readonly onColHandlesRecycled;
122
- /**
123
- * Returns true if the latest pending write to the cell indicated by the given row/col handles
124
- * matches the given 'localSeq'.
125
- *
126
- * A return value of `true` indicates that there are no later local operations queued that will
127
- * clobber the write op at the given 'localSeq'. This includes later ops that overwrite the cell
128
- * with a different value as well as row/col removals that might recycled the given row/col handles.
129
- */
130
- private isLatestPendingWrite;
131
- toString(): string;
132
- /**
133
- * {@inheritDoc @fluidframework/shared-object-base#SharedObjectCore.applyStashedOp}
134
- */
135
- protected applyStashedOp(content: any): unknown;
136
- }
137
-
138
- /**
139
- * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedMatrix}.
140
- * @public
141
- */
142
- export declare class SharedMatrixFactory implements IChannelFactory {
143
- static Type: string;
144
- static readonly Attributes: IChannelAttributes;
145
- get type(): string;
146
- get attributes(): IChannelAttributes;
147
- /**
148
- * {@inheritDoc @fluidframework/datastore-definitions#IChannelFactory.load}
149
- */
150
- load(runtime: IFluidDataStoreRuntime, id: string, services: IChannelServices, attributes: IChannelAttributes): Promise<IChannel>;
151
- create(document: IFluidDataStoreRuntime, id: string): IChannel;
152
- }
21
+ /* Excluded from this release type: IChannel */
22
+
23
+ /* Excluded from this release type: IChannelAttributes */
24
+
25
+ /* Excluded from this release type: IChannelFactory */
26
+
27
+ /* Excluded from this release type: IChannelServices */
28
+
29
+ /* Excluded from this release type: IChannelStorageService */
30
+
31
+ /* Excluded from this release type: IEventThisPlaceHolder */
32
+
33
+ /* Excluded from this release type: IFluidDataStoreRuntime */
34
+
35
+ /* Excluded from this release type: IFluidSerializer */
36
+
37
+ /* Excluded from this release type: IJSONSegment */
38
+
39
+ /* Excluded from this release type: IRevertible */
40
+
41
+ /* Excluded from this release type: ISharedMatrixEvents */
42
+
43
+ /* Excluded from this release type: ISharedObjectEvents */
44
+
45
+ /* Excluded from this release type: ISummaryTreeWithStats */
46
+
47
+ /* Excluded from this release type: IUndoConsumer */
48
+
49
+ /* Excluded from this release type: MatrixItem */
50
+
51
+ /* Excluded from this release type: Serializable */
52
+
53
+ /* Excluded from this release type: SharedMatrix */
54
+
55
+ /* Excluded from this release type: SharedMatrixFactory */
56
+
57
+ /* Excluded from this release type: SharedObject */
58
+
59
+ /* Excluded from this release type: SummarySerializer */
153
60
 
154
61
  export { }
@@ -3,6 +3,7 @@ import { IChannelAttributes } from '@fluidframework/datastore-definitions';
3
3
  import { IChannelFactory } from '@fluidframework/datastore-definitions';
4
4
  import { IChannelServices } from '@fluidframework/datastore-definitions';
5
5
  import { IChannelStorageService } from '@fluidframework/datastore-definitions';
6
+ import { IEventThisPlaceHolder } from '@fluidframework/core-interfaces';
6
7
  import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
7
8
  import { IFluidSerializer } from '@fluidframework/shared-object-base';
8
9
  import { IJSONSegment } from '@fluidframework/merge-tree';
@@ -11,13 +12,14 @@ import { IMatrixProducer } from '@tiny-calc/nano';
11
12
  import { IMatrixReader } from '@tiny-calc/nano';
12
13
  import { IMatrixWriter } from '@tiny-calc/nano';
13
14
  import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
15
+ import { ISharedObjectEvents } from '@fluidframework/shared-object-base';
14
16
  import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
15
17
  import { Serializable } from '@fluidframework/datastore-definitions';
16
18
  import { SharedObject } from '@fluidframework/shared-object-base';
17
19
  import { SummarySerializer } from '@fluidframework/shared-object-base';
18
20
 
19
21
  /**
20
- * @public
22
+ * @alpha
21
23
  */
22
24
  export declare interface IRevertible {
23
25
  revert(): any;
@@ -25,7 +27,34 @@ export declare interface IRevertible {
25
27
  }
26
28
 
27
29
  /**
28
- * @public
30
+ * Events emitted by Shared Matrix.
31
+ * @alpha
32
+ */
33
+ export declare interface ISharedMatrixEvents<T> extends ISharedObjectEvents {
34
+ /**
35
+ * This event is only emitted when the SetCell Resolution Policy is First Write Win(FWW).
36
+ * This is emitted when two clients race and send changes without observing each other changes,
37
+ * the changes that gets sequenced last would be rejected, and only client who's changes rejected
38
+ * would be notified via this event, with expectation that it will merge its changes back by
39
+ * accounting new information (state from winner of the race).
40
+ *
41
+ * @remarks Listener parameters:
42
+ *
43
+ * - `row` - Row number at which conflict happened.
44
+ *
45
+ * - `col` - Col number at which conflict happened.
46
+ *
47
+ * - `currentValue` - The current value of the cell.
48
+ *
49
+ * - `conflictingValue` - The value that this client tried to set in the cell and got ignored due to conflict.
50
+ *
51
+ * - `target` - The {@link SharedMatrix} itself.
52
+ */
53
+ (event: "conflict", listener: (row: number, col: number, currentValue: MatrixItem<T>, conflictingValue: MatrixItem<T>, target: IEventThisPlaceHolder) => void): any;
54
+ }
55
+
56
+ /**
57
+ * @alpha
29
58
  */
30
59
  export declare interface IUndoConsumer {
31
60
  pushToCurrentOperation(revertible: IRevertible): any;
@@ -34,7 +63,7 @@ export declare interface IUndoConsumer {
34
63
  /**
35
64
  * A matrix cell value may be undefined (indicating an empty cell) or any serializable type,
36
65
  * excluding null. (However, nulls may be embedded inside objects and arrays.)
37
- * @public
66
+ * @alpha
38
67
  */
39
68
  export declare type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;
40
69
 
@@ -49,18 +78,29 @@ export declare type MatrixItem<T> = Serializable<Exclude<T, null>> | undefined;
49
78
  * matrix data and physically stores data in Z-order to leverage CPU caches and
50
79
  * prefetching when reading in either row or column major order. (See README.md
51
80
  * for more details.)
52
- *
53
- * @public
81
+ * @alpha
54
82
  */
55
- export declare class SharedMatrix<T = any> extends SharedObject implements IMatrixProducer<MatrixItem<T>>, IMatrixReader<MatrixItem<T>>, IMatrixWriter<MatrixItem<T>> {
83
+ export declare class SharedMatrix<T = any> extends SharedObject<ISharedMatrixEvents<T>> implements IMatrixProducer<MatrixItem<T>>, IMatrixReader<MatrixItem<T>>, IMatrixWriter<MatrixItem<T>> {
56
84
  id: string;
57
85
  private readonly consumers;
58
86
  static getFactory(): SharedMatrixFactory;
59
87
  private readonly rows;
60
88
  private readonly cols;
61
89
  private cells;
62
- private pending;
63
- constructor(runtime: IFluidDataStoreRuntime, id: string, attributes: IChannelAttributes);
90
+ private readonly pending;
91
+ private cellLastWriteTracker;
92
+ private setCellLwwToFwwPolicySwitchOpSeqNumber;
93
+ private userSwitchedSetCellPolicy;
94
+ private reentrantCount;
95
+ /**
96
+ * Constructor for the Shared Matrix
97
+ * @param runtime - DataStore runtime.
98
+ * @param id - id of the dds
99
+ * @param attributes - channel attributes
100
+ * @param _isSetCellConflictResolutionPolicyFWW - Conflict resolution for Matrix set op is First Writer Win in case of
101
+ * race condition. Client can still overwrite values in case of no race.
102
+ */
103
+ constructor(runtime: IFluidDataStoreRuntime, id: string, attributes: IChannelAttributes, _isSetCellConflictResolutionPolicyFWW?: boolean);
64
104
  private undo?;
65
105
  /**
66
106
  * Subscribes the given IUndoConsumer to the matrix.
@@ -76,12 +116,22 @@ export declare class SharedMatrix<T = any> extends SharedObject implements IMatr
76
116
  closeMatrix(consumer: IMatrixConsumer<MatrixItem<T>>): void;
77
117
  get rowCount(): number;
78
118
  get colCount(): number;
119
+ isSetCellConflictResolutionPolicyFWW(): boolean;
79
120
  getCell(row: number, col: number): MatrixItem<T>;
80
121
  get matrixProducer(): IMatrixProducer<MatrixItem<T>>;
81
122
  setCell(row: number, col: number, value: MatrixItem<T>): void;
82
123
  setCells(rowStart: number, colStart: number, colCount: number, values: readonly MatrixItem<T>[]): void;
83
124
  private setCellCore;
84
125
  private sendSetCellOp;
126
+ /**
127
+ * This makes sure that the code inside the callback is not reentrant. We need to do that because we raise notifications
128
+ * to the consumers telling about these changes and they can try to change the matrix while listening to those notifications
129
+ * which can make the shared matrix to be in bad state. For example, we are raising notification for a setCell changes and
130
+ * a consumer tries to delete that row/col on receiving that notification which can lead to this matrix trying to setCell in
131
+ * a deleted row/col.
132
+ * @param callback - code that needs to protected against reentrancy.
133
+ */
134
+ private protectAgainstReentrancy;
85
135
  private submitVectorMessage;
86
136
  private submitColMessage;
87
137
  insertCols(colStart: number, count: number): void;
@@ -89,8 +139,8 @@ export declare class SharedMatrix<T = any> extends SharedObject implements IMatr
89
139
  private submitRowMessage;
90
140
  insertRows(rowStart: number, count: number): void;
91
141
  removeRows(rowStart: number, count: number): void;
92
- /** @internal */ _undoRemoveRows(rowStart: number, spec: IJSONSegment): void;
93
- /** @internal */ _undoRemoveCols(colStart: number, spec: IJSONSegment): void;
142
+ /***/ _undoRemoveRows(rowStart: number, spec: IJSONSegment): void;
143
+ /***/ _undoRemoveCols(colStart: number, spec: IJSONSegment): void;
94
144
  protected summarizeCore(serializer: IFluidSerializer): ISummaryTreeWithStats;
95
145
  /**
96
146
  * Runs serializer on the GC data for this SharedMatrix.
@@ -114,11 +164,21 @@ export declare class SharedMatrix<T = any> extends SharedObject implements IMatr
114
164
  * {@inheritDoc @fluidframework/shared-object-base#SharedObject.loadCore}
115
165
  */
116
166
  protected loadCore(storage: IChannelStorageService): Promise<void>;
167
+ /**
168
+ * Tells whether the setCell op should be applied or not based on First Write Win policy. It assumes
169
+ * we are in FWW mode.
170
+ */
171
+ private shouldSetCellBasedOnFWW;
117
172
  protected processCore(rawMessage: ISequencedDocumentMessage, local: boolean, localOpMetadata: unknown): void;
118
173
  private readonly onRowDelta;
119
174
  private readonly onColDelta;
120
175
  private readonly onRowHandlesRecycled;
121
176
  private readonly onColHandlesRecycled;
177
+ /**
178
+ * Api to switch Set Op policy from Last Writer Win to First Writer Win. It only switches from LWW to FWW
179
+ * and not from FWW to LWW. The next SetOp which is sent will communicate this policy to other clients.
180
+ */
181
+ switchSetCellPolicy(): void;
122
182
  /**
123
183
  * Returns true if the latest pending write to the cell indicated by the given row/col handles
124
184
  * matches the given 'localSeq'.
@@ -137,7 +197,7 @@ export declare class SharedMatrix<T = any> extends SharedObject implements IMatr
137
197
 
138
198
  /**
139
199
  * {@link @fluidframework/datastore-definitions#IChannelFactory} for {@link SharedMatrix}.
140
- * @public
200
+ * @alpha
141
201
  */
142
202
  export declare class SharedMatrixFactory implements IChannelFactory {
143
203
  static Type: string;