@fluidframework/merge-tree 2.12.0 → 2.13.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.
- package/CHANGELOG.md +4 -0
- package/dist/MergeTreeTextHelper.d.ts.map +1 -1
- package/dist/MergeTreeTextHelper.js +0 -2
- package/dist/MergeTreeTextHelper.js.map +1 -1
- package/dist/attributionPolicy.d.ts.map +1 -1
- package/dist/attributionPolicy.js +6 -16
- package/dist/attributionPolicy.js.map +1 -1
- package/dist/client.d.ts +3 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +39 -28
- package/dist/client.js.map +1 -1
- package/dist/endOfTreeSegment.d.ts +2 -1
- package/dist/endOfTreeSegment.d.ts.map +1 -1
- package/dist/endOfTreeSegment.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -4
- package/dist/index.js.map +1 -1
- package/dist/mergeTree.d.ts +8 -7
- package/dist/mergeTree.d.ts.map +1 -1
- package/dist/mergeTree.js +190 -216
- package/dist/mergeTree.js.map +1 -1
- package/dist/mergeTreeNodeWalk.d.ts.map +1 -1
- package/dist/mergeTreeNodeWalk.js +3 -2
- package/dist/mergeTreeNodeWalk.js.map +1 -1
- package/dist/mergeTreeNodes.d.ts +76 -162
- package/dist/mergeTreeNodes.d.ts.map +1 -1
- package/dist/mergeTreeNodes.js +100 -112
- package/dist/mergeTreeNodes.js.map +1 -1
- package/dist/mergeTreeTracking.d.ts.map +1 -1
- package/dist/mergeTreeTracking.js +0 -2
- package/dist/mergeTreeTracking.js.map +1 -1
- package/dist/partialLengths.d.ts +2 -2
- package/dist/partialLengths.d.ts.map +1 -1
- package/dist/partialLengths.js +28 -26
- package/dist/partialLengths.js.map +1 -1
- package/dist/perspective.d.ts +3 -2
- package/dist/perspective.d.ts.map +1 -1
- package/dist/perspective.js +11 -4
- package/dist/perspective.js.map +1 -1
- package/dist/referencePositions.d.ts.map +1 -1
- package/dist/referencePositions.js +4 -1
- package/dist/referencePositions.js.map +1 -1
- package/dist/revertibles.d.ts.map +1 -1
- package/dist/revertibles.js +10 -11
- package/dist/revertibles.js.map +1 -1
- package/dist/segmentGroupCollection.d.ts +4 -4
- package/dist/segmentGroupCollection.d.ts.map +1 -1
- package/dist/segmentGroupCollection.js +0 -6
- package/dist/segmentGroupCollection.js.map +1 -1
- package/dist/segmentInfos.d.ts +257 -0
- package/dist/segmentInfos.d.ts.map +1 -0
- package/dist/segmentInfos.js +166 -0
- package/dist/segmentInfos.js.map +1 -0
- package/dist/snapshotLoader.d.ts.map +1 -1
- package/dist/snapshotLoader.js +38 -44
- package/dist/snapshotLoader.js.map +1 -1
- package/dist/snapshotV1.d.ts.map +1 -1
- package/dist/snapshotV1.js +9 -12
- package/dist/snapshotV1.js.map +1 -1
- package/dist/snapshotlegacy.d.ts +2 -2
- package/dist/snapshotlegacy.d.ts.map +1 -1
- package/dist/snapshotlegacy.js +5 -3
- package/dist/snapshotlegacy.js.map +1 -1
- package/dist/sortedSegmentSet.d.ts.map +1 -1
- package/dist/sortedSegmentSet.js +5 -8
- package/dist/sortedSegmentSet.js.map +1 -1
- package/dist/test/beastTest.spec.d.ts +0 -2
- package/dist/test/beastTest.spec.d.ts.map +1 -1
- package/dist/test/beastTest.spec.js +1 -5
- package/dist/test/beastTest.spec.js.map +1 -1
- package/dist/test/client.annotateMarker.spec.js.map +1 -1
- package/dist/test/client.applyMsg.spec.js +15 -12
- package/dist/test/client.applyMsg.spec.js.map +1 -1
- package/dist/test/client.attributionFarm.spec.js.map +1 -1
- package/dist/test/client.getPosition.spec.js +3 -2
- package/dist/test/client.getPosition.spec.js.map +1 -1
- package/dist/test/client.localReference.spec.js +6 -6
- package/dist/test/client.localReference.spec.js.map +1 -1
- package/dist/test/client.localReferenceFarm.spec.js.map +1 -1
- package/dist/test/client.rollback.spec.js.map +1 -1
- package/dist/test/dirname.cjs +0 -1
- package/dist/test/dirname.cjs.map +1 -1
- package/dist/test/index.d.ts +1 -1
- package/dist/test/index.d.ts.map +1 -1
- package/dist/test/index.js +2 -4
- package/dist/test/index.js.map +1 -1
- package/dist/test/mergeTree.annotate.spec.js +3 -0
- package/dist/test/mergeTree.annotate.spec.js.map +1 -1
- package/dist/test/mergeTree.insertingWalk.spec.js +1 -1
- package/dist/test/mergeTree.insertingWalk.spec.js.map +1 -1
- package/dist/test/mergeTree.markRangeRemoved.spec.js +2 -0
- package/dist/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
- package/dist/test/mergeTree.walk.spec.js.map +1 -1
- package/dist/test/mergeTreeOperationRunner.d.ts.map +1 -1
- package/dist/test/mergeTreeOperationRunner.js +2 -3
- package/dist/test/mergeTreeOperationRunner.js.map +1 -1
- package/dist/test/obliterate.spec.js.map +1 -1
- package/dist/test/propertyManager.spec.js.map +1 -1
- package/dist/test/reconnectHelper.d.ts +2 -1
- package/dist/test/reconnectHelper.d.ts.map +1 -1
- package/dist/test/reconnectHelper.js.map +1 -1
- package/dist/test/resetPendingSegmentsToOp.spec.js.map +1 -1
- package/dist/test/revertibleFarm.spec.js.map +1 -1
- package/dist/test/segmentGroupCollection.spec.js +15 -3
- package/dist/test/segmentGroupCollection.spec.js.map +1 -1
- package/dist/test/snapshot.utils.d.ts +2 -2
- package/dist/test/snapshot.utils.d.ts.map +1 -1
- package/dist/test/snapshot.utils.js.map +1 -1
- package/dist/test/sortedSegmentSet.spec.js +4 -3
- package/dist/test/sortedSegmentSet.spec.js.map +1 -1
- package/dist/test/testClient.d.ts +8 -6
- package/dist/test/testClient.d.ts.map +1 -1
- package/dist/test/testClient.js +29 -27
- package/dist/test/testClient.js.map +1 -1
- package/dist/test/testClientLogger.d.ts.map +1 -1
- package/dist/test/testClientLogger.js +6 -4
- package/dist/test/testClientLogger.js.map +1 -1
- package/dist/test/testUtils.d.ts +2 -2
- package/dist/test/testUtils.d.ts.map +1 -1
- package/dist/test/testUtils.js +32 -8
- package/dist/test/testUtils.js.map +1 -1
- package/dist/test/text.d.ts +2 -2
- package/dist/test/text.d.ts.map +1 -1
- package/dist/test/text.js +12 -6
- package/dist/test/text.js.map +1 -1
- package/dist/test/tracking.spec.js.map +1 -1
- package/dist/test/wordUnitTests.spec.js +1 -1
- package/dist/test/wordUnitTests.spec.js.map +1 -1
- package/dist/zamboni.d.ts.map +1 -1
- package/dist/zamboni.js +8 -7
- package/dist/zamboni.js.map +1 -1
- package/lib/MergeTreeTextHelper.d.ts.map +1 -1
- package/lib/MergeTreeTextHelper.js +0 -2
- package/lib/MergeTreeTextHelper.js.map +1 -1
- package/lib/attributionPolicy.d.ts.map +1 -1
- package/lib/attributionPolicy.js +6 -16
- package/lib/attributionPolicy.js.map +1 -1
- package/lib/client.d.ts +3 -4
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +40 -29
- package/lib/client.js.map +1 -1
- package/lib/endOfTreeSegment.d.ts +2 -1
- package/lib/endOfTreeSegment.d.ts.map +1 -1
- package/lib/endOfTreeSegment.js.map +1 -1
- package/lib/index.d.ts +2 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/mergeTree.d.ts +8 -7
- package/lib/mergeTree.d.ts.map +1 -1
- package/lib/mergeTree.js +177 -205
- package/lib/mergeTree.js.map +1 -1
- package/lib/mergeTreeNodeWalk.d.ts.map +1 -1
- package/lib/mergeTreeNodeWalk.js +3 -2
- package/lib/mergeTreeNodeWalk.js.map +1 -1
- package/lib/mergeTreeNodes.d.ts +76 -162
- package/lib/mergeTreeNodes.d.ts.map +1 -1
- package/lib/mergeTreeNodes.js +95 -108
- package/lib/mergeTreeNodes.js.map +1 -1
- package/lib/mergeTreeTracking.d.ts.map +1 -1
- package/lib/mergeTreeTracking.js +0 -2
- package/lib/mergeTreeTracking.js.map +1 -1
- package/lib/partialLengths.d.ts +2 -2
- package/lib/partialLengths.d.ts.map +1 -1
- package/lib/partialLengths.js +25 -23
- package/lib/partialLengths.js.map +1 -1
- package/lib/perspective.d.ts +3 -2
- package/lib/perspective.d.ts.map +1 -1
- package/lib/perspective.js +11 -4
- package/lib/perspective.js.map +1 -1
- package/lib/referencePositions.d.ts.map +1 -1
- package/lib/referencePositions.js +4 -1
- package/lib/referencePositions.js.map +1 -1
- package/lib/revertibles.d.ts.map +1 -1
- package/lib/revertibles.js +8 -9
- package/lib/revertibles.js.map +1 -1
- package/lib/segmentGroupCollection.d.ts +4 -4
- package/lib/segmentGroupCollection.d.ts.map +1 -1
- package/lib/segmentGroupCollection.js +0 -6
- package/lib/segmentGroupCollection.js.map +1 -1
- package/lib/segmentInfos.d.ts +257 -0
- package/lib/segmentInfos.d.ts.map +1 -0
- package/lib/segmentInfos.js +145 -0
- package/lib/segmentInfos.js.map +1 -0
- package/lib/snapshotLoader.d.ts.map +1 -1
- package/lib/snapshotLoader.js +38 -44
- package/lib/snapshotLoader.js.map +1 -1
- package/lib/snapshotV1.d.ts.map +1 -1
- package/lib/snapshotV1.js +9 -12
- package/lib/snapshotV1.js.map +1 -1
- package/lib/snapshotlegacy.d.ts +2 -2
- package/lib/snapshotlegacy.d.ts.map +1 -1
- package/lib/snapshotlegacy.js +5 -3
- package/lib/snapshotlegacy.js.map +1 -1
- package/lib/sortedSegmentSet.d.ts.map +1 -1
- package/lib/sortedSegmentSet.js +5 -8
- package/lib/sortedSegmentSet.js.map +1 -1
- package/lib/test/beastTest.spec.d.ts +0 -2
- package/lib/test/beastTest.spec.d.ts.map +1 -1
- package/lib/test/beastTest.spec.js +0 -3
- package/lib/test/beastTest.spec.js.map +1 -1
- package/lib/test/client.annotateMarker.spec.js.map +1 -1
- package/lib/test/client.applyMsg.spec.js +15 -12
- package/lib/test/client.applyMsg.spec.js.map +1 -1
- package/lib/test/client.attributionFarm.spec.js.map +1 -1
- package/lib/test/client.getPosition.spec.js +3 -2
- package/lib/test/client.getPosition.spec.js.map +1 -1
- package/lib/test/client.localReference.spec.js +1 -1
- package/lib/test/client.localReference.spec.js.map +1 -1
- package/lib/test/client.localReferenceFarm.spec.js.map +1 -1
- package/lib/test/client.rollback.spec.js +1 -1
- package/lib/test/client.rollback.spec.js.map +1 -1
- package/lib/test/dirname.cjs +0 -1
- package/lib/test/dirname.cjs.map +1 -1
- package/lib/test/index.d.ts +1 -1
- package/lib/test/index.d.ts.map +1 -1
- package/lib/test/index.js +1 -1
- package/lib/test/index.js.map +1 -1
- package/lib/test/mergeTree.annotate.spec.js +3 -0
- package/lib/test/mergeTree.annotate.spec.js.map +1 -1
- package/lib/test/mergeTree.insertingWalk.spec.js +2 -2
- package/lib/test/mergeTree.insertingWalk.spec.js.map +1 -1
- package/lib/test/mergeTree.markRangeRemoved.spec.js +2 -0
- package/lib/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
- package/lib/test/mergeTree.walk.spec.js.map +1 -1
- package/lib/test/mergeTreeOperationRunner.d.ts.map +1 -1
- package/lib/test/mergeTreeOperationRunner.js +1 -2
- package/lib/test/mergeTreeOperationRunner.js.map +1 -1
- package/lib/test/obliterate.spec.js.map +1 -1
- package/lib/test/propertyManager.spec.js.map +1 -1
- package/lib/test/reconnectHelper.d.ts +2 -1
- package/lib/test/reconnectHelper.d.ts.map +1 -1
- package/lib/test/reconnectHelper.js.map +1 -1
- package/lib/test/resetPendingSegmentsToOp.spec.js.map +1 -1
- package/lib/test/revertibleFarm.spec.js.map +1 -1
- package/lib/test/segmentGroupCollection.spec.js +15 -3
- package/lib/test/segmentGroupCollection.spec.js.map +1 -1
- package/lib/test/snapshot.utils.d.ts +2 -2
- package/lib/test/snapshot.utils.d.ts.map +1 -1
- package/lib/test/snapshot.utils.js.map +1 -1
- package/lib/test/sortedSegmentSet.spec.js +4 -3
- package/lib/test/sortedSegmentSet.spec.js.map +1 -1
- package/lib/test/testClient.d.ts +8 -6
- package/lib/test/testClient.d.ts.map +1 -1
- package/lib/test/testClient.js +30 -28
- package/lib/test/testClient.js.map +1 -1
- package/lib/test/testClientLogger.d.ts.map +1 -1
- package/lib/test/testClientLogger.js +5 -3
- package/lib/test/testClientLogger.js.map +1 -1
- package/lib/test/testUtils.d.ts +2 -2
- package/lib/test/testUtils.d.ts.map +1 -1
- package/lib/test/testUtils.js +9 -8
- package/lib/test/testUtils.js.map +1 -1
- package/lib/test/text.d.ts +2 -2
- package/lib/test/text.d.ts.map +1 -1
- package/lib/test/text.js +12 -6
- package/lib/test/text.js.map +1 -1
- package/lib/test/tracking.spec.js.map +1 -1
- package/lib/test/wordUnitTests.spec.js +1 -1
- package/lib/test/wordUnitTests.spec.js.map +1 -1
- package/lib/zamboni.d.ts.map +1 -1
- package/lib/zamboni.js +7 -6
- package/lib/zamboni.js.map +1 -1
- package/package.json +17 -17
- package/src/MergeTreeTextHelper.ts +2 -4
- package/src/attributionPolicy.ts +5 -13
- package/src/client.ts +55 -44
- package/src/endOfTreeSegment.ts +3 -3
- package/src/index.ts +4 -6
- package/src/mergeTree.ts +245 -282
- package/src/mergeTreeNodeWalk.ts +3 -2
- package/src/mergeTreeNodes.ts +190 -322
- package/src/mergeTreeTracking.ts +0 -3
- package/src/partialLengths.ts +42 -27
- package/src/perspective.ts +27 -4
- package/src/referencePositions.ts +4 -1
- package/src/revertibles.ts +19 -13
- package/src/segmentGroupCollection.ts +7 -18
- package/src/segmentInfos.ts +377 -0
- package/src/snapshotLoader.ts +60 -57
- package/src/snapshotV1.ts +14 -16
- package/src/snapshotlegacy.ts +12 -17
- package/src/sortedSegmentSet.ts +6 -8
- package/src/zamboni.ts +10 -12
package/lib/client.js
CHANGED
|
@@ -10,19 +10,21 @@ import { toDeltaManagerInternal } from "@fluidframework/runtime-utils/internal";
|
|
|
10
10
|
import { LoggingError, UsageError, } from "@fluidframework/telemetry-utils/internal";
|
|
11
11
|
import { MergeTreeTextHelper } from "./MergeTreeTextHelper.js";
|
|
12
12
|
import { RedBlackTree } from "./collections/index.js";
|
|
13
|
-
import { UnassignedSequenceNumber, UniversalSequenceNumber } from "./constants.js";
|
|
13
|
+
import { NonCollabClient, UnassignedSequenceNumber, UniversalSequenceNumber, } from "./constants.js";
|
|
14
14
|
import { MergeTree, errorIfOptionNotTrue, } from "./mergeTree.js";
|
|
15
15
|
import { walkAllChildSegments } from "./mergeTreeNodeWalk.js";
|
|
16
|
-
import { compareStrings,
|
|
16
|
+
import { compareStrings, isSegmentLeaf, } from "./mergeTreeNodes.js";
|
|
17
17
|
import { createAdjustRangeOp, createAnnotateMarkerOp, createAnnotateRangeOp,
|
|
18
18
|
// eslint-disable-next-line import/no-deprecated
|
|
19
19
|
createGroupOp, createInsertSegmentOp, createObliterateRangeOp, createObliterateRangeOpSided, createRemoveRangeOp, } from "./opBuilder.js";
|
|
20
20
|
import { MergeTreeDeltaType, } from "./ops.js";
|
|
21
21
|
import { DetachedReferencePosition } from "./referencePositions.js";
|
|
22
|
+
import { isInserted, isMoved, isRemoved, overwriteInfo, toMoveInfo, } from "./segmentInfos.js";
|
|
22
23
|
import { Side } from "./sequencePlace.js";
|
|
23
24
|
import { SnapshotLoader } from "./snapshotLoader.js";
|
|
24
25
|
import { SnapshotV1 } from "./snapshotV1.js";
|
|
25
26
|
import { SnapshotLegacy } from "./snapshotlegacy.js";
|
|
27
|
+
const UNBOUND_SEGMENT_ERROR = "The provided segment is not bound to this DDS.";
|
|
26
28
|
/**
|
|
27
29
|
* This class encapsulates a merge-tree, and provides a local client specific view over it and
|
|
28
30
|
* the capability to modify it as the local client. Additionally it provides
|
|
@@ -70,13 +72,19 @@ export class Client extends TypedEventEmitter {
|
|
|
70
72
|
policy.attach(this);
|
|
71
73
|
}
|
|
72
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* The merge tree maintains a queue of segment groups for each local operation.
|
|
77
|
+
* These segment groups track segments modified by an operation.
|
|
78
|
+
* This method peeks the tail of that queue, and returns the segments groups there.
|
|
79
|
+
* It is used to get the segment group(s) for the previous operations.
|
|
80
|
+
* @param count - The number segment groups to get peek from the tail of the queue. Default 1.
|
|
81
|
+
*/
|
|
73
82
|
peekPendingSegmentGroups(count = 1) {
|
|
74
83
|
const pending = this._mergeTree.pendingSegments;
|
|
75
84
|
let node = pending?.last;
|
|
76
85
|
if (count === 1 || pending === undefined) {
|
|
77
86
|
return node?.data;
|
|
78
87
|
}
|
|
79
|
-
// eslint-disable-next-line import/no-deprecated
|
|
80
88
|
const taken = Array.from({ length: Math.min(count, pending.length) });
|
|
81
89
|
for (let i = taken.length - 1; i >= 0; i--) {
|
|
82
90
|
taken[i] = node.data;
|
|
@@ -192,14 +200,14 @@ export class Client extends TypedEventEmitter {
|
|
|
192
200
|
let localInserts = 0;
|
|
193
201
|
let localRemoves = 0;
|
|
194
202
|
walkAllChildSegments(this._mergeTree.root, (seg) => {
|
|
195
|
-
if (seg.seq === UnassignedSequenceNumber) {
|
|
203
|
+
if (isInserted(seg) && seg.seq === UnassignedSequenceNumber) {
|
|
196
204
|
localInserts++;
|
|
197
205
|
}
|
|
198
|
-
if (seg.removedSeq === UnassignedSequenceNumber) {
|
|
206
|
+
if (isRemoved(seg) && seg.removedSeq === UnassignedSequenceNumber) {
|
|
199
207
|
localRemoves++;
|
|
200
208
|
}
|
|
201
209
|
// Only serialize segments that have not been removed.
|
|
202
|
-
if (seg
|
|
210
|
+
if (!isRemoved(seg)) {
|
|
203
211
|
handleCollectingSerializer.stringify(seg.clone().toJSONObject(), handle);
|
|
204
212
|
}
|
|
205
213
|
return true;
|
|
@@ -212,7 +220,6 @@ export class Client extends TypedEventEmitter {
|
|
|
212
220
|
});
|
|
213
221
|
}
|
|
214
222
|
}
|
|
215
|
-
// eslint-disable-next-line import/no-deprecated
|
|
216
223
|
getCollabWindow() {
|
|
217
224
|
return this._mergeTree.collabWindow;
|
|
218
225
|
}
|
|
@@ -222,11 +229,10 @@ export class Client extends TypedEventEmitter {
|
|
|
222
229
|
* @param segment - The segment to get the position of
|
|
223
230
|
*/
|
|
224
231
|
getPosition(segment, localSeq) {
|
|
225
|
-
|
|
226
|
-
if (mergeSegment?.parent === undefined) {
|
|
232
|
+
if (!isSegmentLeaf(segment)) {
|
|
227
233
|
return -1;
|
|
228
234
|
}
|
|
229
|
-
return this._mergeTree.getPosition(
|
|
235
|
+
return this._mergeTree.getPosition(segment, this.getCurrentSeq(), this.getClientId(), localSeq);
|
|
230
236
|
}
|
|
231
237
|
/**
|
|
232
238
|
* Creates a `LocalReferencePosition` on this client. If the refType does not include ReferenceType.Transient,
|
|
@@ -240,6 +246,9 @@ export class Client extends TypedEventEmitter {
|
|
|
240
246
|
* before the start of or after the end of the tree
|
|
241
247
|
*/
|
|
242
248
|
createLocalReferencePosition(segment, offset, refType, properties, slidingPreference, canSlideToEndpoint) {
|
|
249
|
+
if (!isSegmentLeaf(segment) && typeof segment !== "string") {
|
|
250
|
+
throw new UsageError(UNBOUND_SEGMENT_ERROR);
|
|
251
|
+
}
|
|
243
252
|
return this._mergeTree.createLocalReferencePosition(segment, offset ?? 0, refType, properties, slidingPreference, canSlideToEndpoint);
|
|
244
253
|
}
|
|
245
254
|
/**
|
|
@@ -274,7 +283,6 @@ export class Client extends TypedEventEmitter {
|
|
|
274
283
|
* Revert an op
|
|
275
284
|
*/
|
|
276
285
|
rollback(op, localOpMetadata) {
|
|
277
|
-
// eslint-disable-next-line import/no-deprecated
|
|
278
286
|
this._mergeTree.rollback(op, localOpMetadata);
|
|
279
287
|
}
|
|
280
288
|
applyObliterateRangeOp(opArgs) {
|
|
@@ -523,11 +531,12 @@ export class Client extends TypedEventEmitter {
|
|
|
523
531
|
findReconnectionPosition(segment, localSeq) {
|
|
524
532
|
assert(localSeq <= this._mergeTree.collabWindow.localSeq, 0x032 /* "localSeq greater than collab window" */);
|
|
525
533
|
const { currentSeq, clientId } = this.getCollabWindow();
|
|
534
|
+
if (!isSegmentLeaf(segment)) {
|
|
535
|
+
throw new UsageError(UNBOUND_SEGMENT_ERROR);
|
|
536
|
+
}
|
|
526
537
|
return this._mergeTree.getPosition(segment, currentSeq, clientId, localSeq);
|
|
527
538
|
}
|
|
528
|
-
resetPendingDeltaToOps(resetOp,
|
|
529
|
-
// eslint-disable-next-line import/no-deprecated
|
|
530
|
-
segmentGroup) {
|
|
539
|
+
resetPendingDeltaToOps(resetOp, segmentGroup) {
|
|
531
540
|
assert(!!segmentGroup, 0x033 /* "Segment group undefined" */);
|
|
532
541
|
const NACKedSegmentGroup = this.pendingRebase?.shift()?.data;
|
|
533
542
|
assert(segmentGroup === NACKedSegmentGroup, 0x034 /* "Segment group not at head of pending rebase queue" */);
|
|
@@ -535,7 +544,6 @@ export class Client extends TypedEventEmitter {
|
|
|
535
544
|
this.pendingRebase = undefined;
|
|
536
545
|
}
|
|
537
546
|
// if this is an obliterate op, keep all segments in same segment group
|
|
538
|
-
// eslint-disable-next-line import/no-deprecated
|
|
539
547
|
const obliterateSegmentGroup = {
|
|
540
548
|
segments: [],
|
|
541
549
|
localSeq: segmentGroup.localSeq,
|
|
@@ -551,7 +559,7 @@ export class Client extends TypedEventEmitter {
|
|
|
551
559
|
// By sorting we ensure the nearer segment will be applied and sequenced before the farther segments
|
|
552
560
|
// so their recalculated positions will be correct.
|
|
553
561
|
for (const segment of segmentGroup.segments.sort((a, b) => a.ordinal < b.ordinal ? -1 : 1)) {
|
|
554
|
-
assert(segment.segmentGroups?.remove
|
|
562
|
+
assert(segment.segmentGroups?.remove(segmentGroup) === true, 0x035 /* "Segment group not in segment pending queue" */);
|
|
555
563
|
assert(segmentGroup.localSeq !== undefined, 0x867 /* expected segment group localSeq to be defined */);
|
|
556
564
|
const segmentPosition = this.findReconnectionPosition(segment, segmentGroup.localSeq);
|
|
557
565
|
let newOp;
|
|
@@ -562,10 +570,10 @@ export class Client extends TypedEventEmitter {
|
|
|
562
570
|
// if the segment has been removed or obliterated, there's no need to send the annotate op
|
|
563
571
|
// unless the remove was local, in which case the annotate must have come
|
|
564
572
|
// before the remove
|
|
565
|
-
if ((segment
|
|
573
|
+
if ((!isRemoved(segment) ||
|
|
566
574
|
(segment.localRemovedSeq !== undefined &&
|
|
567
575
|
segment.removedSeq === UnassignedSequenceNumber)) &&
|
|
568
|
-
(segment
|
|
576
|
+
(!isMoved(segment) ||
|
|
569
577
|
(segment.localMovedSeq !== undefined &&
|
|
570
578
|
segment.movedSeq === UnassignedSequenceNumber))) {
|
|
571
579
|
newOp =
|
|
@@ -576,7 +584,7 @@ export class Client extends TypedEventEmitter {
|
|
|
576
584
|
break;
|
|
577
585
|
}
|
|
578
586
|
case MergeTreeDeltaType.INSERT: {
|
|
579
|
-
assert(segment.seq === UnassignedSequenceNumber, 0x037 /* "Segment already has assigned sequence number" */);
|
|
587
|
+
assert(isInserted(segment) && segment.seq === UnassignedSequenceNumber, 0x037 /* "Segment already has assigned sequence number" */);
|
|
580
588
|
const moveInfo = toMoveInfo(segment);
|
|
581
589
|
if (moveInfo !== undefined) {
|
|
582
590
|
errorIfOptionNotTrue(this._mergeTree.options, "mergeTreeEnableObliterateReconnect");
|
|
@@ -585,8 +593,11 @@ export class Client extends TypedEventEmitter {
|
|
|
585
593
|
// we set the seq to the universal seq and remove the local seq,
|
|
586
594
|
// so its length is not considered for subsequent local changes
|
|
587
595
|
// this allows us to not send the op as even the local client will ignore the segment
|
|
588
|
-
segment
|
|
589
|
-
|
|
596
|
+
overwriteInfo(segment, {
|
|
597
|
+
seq: UniversalSequenceNumber,
|
|
598
|
+
localSeq: undefined,
|
|
599
|
+
clientId: NonCollabClient,
|
|
600
|
+
});
|
|
590
601
|
break;
|
|
591
602
|
}
|
|
592
603
|
}
|
|
@@ -599,9 +610,10 @@ export class Client extends TypedEventEmitter {
|
|
|
599
610
|
break;
|
|
600
611
|
}
|
|
601
612
|
case MergeTreeDeltaType.REMOVE: {
|
|
602
|
-
if (segment
|
|
613
|
+
if (isRemoved(segment) &&
|
|
614
|
+
segment.localRemovedSeq !== undefined &&
|
|
603
615
|
segment.removedSeq === UnassignedSequenceNumber &&
|
|
604
|
-
(segment
|
|
616
|
+
(!isMoved(segment) ||
|
|
605
617
|
(segment.localMovedSeq !== undefined &&
|
|
606
618
|
segment.movedSeq === UnassignedSequenceNumber))) {
|
|
607
619
|
newOp = createRemoveRangeOp(segmentPosition, segmentPosition + segment.cachedLength);
|
|
@@ -610,9 +622,10 @@ export class Client extends TypedEventEmitter {
|
|
|
610
622
|
}
|
|
611
623
|
case MergeTreeDeltaType.OBLITERATE: {
|
|
612
624
|
errorIfOptionNotTrue(this._mergeTree.options, "mergeTreeEnableObliterateReconnect");
|
|
613
|
-
if (segment
|
|
625
|
+
if (isMoved(segment) &&
|
|
626
|
+
segment.localMovedSeq !== undefined &&
|
|
614
627
|
segment.movedSeq === UnassignedSequenceNumber &&
|
|
615
|
-
(segment
|
|
628
|
+
(!isRemoved(segment) ||
|
|
616
629
|
(segment.localRemovedSeq !== undefined &&
|
|
617
630
|
segment.removedSeq === UnassignedSequenceNumber))) {
|
|
618
631
|
newOp = createObliterateRangeOp(segmentPosition, segmentPosition + segment.cachedLength);
|
|
@@ -763,9 +776,8 @@ export class Client extends TypedEventEmitter {
|
|
|
763
776
|
* @param resetOp - The op to reset
|
|
764
777
|
* @param segmentGroup - The segment group associated with the op
|
|
765
778
|
*/
|
|
766
|
-
regeneratePendingOp(resetOp,
|
|
767
|
-
|
|
768
|
-
segmentGroup) {
|
|
779
|
+
regeneratePendingOp(resetOp, localOpMetadata) {
|
|
780
|
+
const segmentGroup = localOpMetadata;
|
|
769
781
|
if (this.pendingRebase === undefined || this.pendingRebase.empty) {
|
|
770
782
|
let firstGroup;
|
|
771
783
|
if (Array.isArray(segmentGroup)) {
|
|
@@ -812,7 +824,6 @@ export class Client extends TypedEventEmitter {
|
|
|
812
824
|
// eslint-disable-next-line import/no-deprecated
|
|
813
825
|
return opList.length === 1 ? opList[0] : createGroupOp(...opList);
|
|
814
826
|
}
|
|
815
|
-
// eslint-disable-next-line import/no-deprecated
|
|
816
827
|
createTextHelper() {
|
|
817
828
|
return new MergeTreeTextHelper(this._mergeTree);
|
|
818
829
|
}
|
package/lib/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","source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gB,EAAE,WAAmB,EAAE,QAAQ,GAAG,IAAI;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IACnF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { type IEventThisPlaceHolder, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase, isObject } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { toDeltaManagerInternal } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tLoggingError,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { MergeTreeTextHelper } from \"./MergeTreeTextHelper.js\";\nimport { DoublyLinkedList, RedBlackTree } from \"./collections/index.js\";\nimport { UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants.js\";\nimport { LocalReferencePosition, SlidingPreference } from \"./localReference.js\";\nimport {\n\tMergeTree,\n\terrorIfOptionNotTrue,\n\ttype IMergeTreeOptionsInternal,\n} from \"./mergeTree.js\";\nimport type {\n\tIMergeTreeClientSequenceArgs,\n\tIMergeTreeDeltaCallbackArgs,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeMaintenanceCallbackArgs,\n} from \"./mergeTreeDeltaCallback.js\";\nimport { walkAllChildSegments } from \"./mergeTreeNodeWalk.js\";\nimport {\n\t// eslint-disable-next-line import/no-deprecated\n\tCollaborationWindow,\n\tISegment,\n\tISegmentAction,\n\tISegmentLeaf,\n\tMarker,\n\t// eslint-disable-next-line import/no-deprecated\n\tSegmentGroup,\n\tcompareStrings,\n\ttoMoveInfo,\n} from \"./mergeTreeNodes.js\";\nimport {\n\tcreateAdjustRangeOp,\n\tcreateAnnotateMarkerOp,\n\tcreateAnnotateRangeOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertSegmentOp,\n\tcreateObliterateRangeOp,\n\tcreateObliterateRangeOpSided,\n\tcreateRemoveRangeOp,\n} from \"./opBuilder.js\";\nimport {\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeGroupMsg,\n\tIMergeTreeInsertMsg,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tMergeTreeDeltaType,\n\tReferenceType,\n\ttype AdjustParams,\n\ttype IMergeTreeAnnotateAdjustMsg,\n\ttype IMergeTreeObliterateSidedMsg,\n} from \"./ops.js\";\nimport { PropertySet, type MapLike } from \"./properties.js\";\nimport { DetachedReferencePosition, ReferencePosition } from \"./referencePositions.js\";\nimport { Side, type InteriorSequencePlace } from \"./sequencePlace.js\";\nimport { SnapshotLoader } from \"./snapshotLoader.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\n// eslint-disable-next-line import/no-deprecated\nimport { IMergeTreeTextHelper } from \"./textSegment.js\";\n\ntype IMergeTreeDeltaRemoteOpArgs = Omit<IMergeTreeDeltaOpArgs, \"sequencedMessage\"> &\n\tRequired<Pick<IMergeTreeDeltaOpArgs, \"sequencedMessage\">>;\n\n/**\n * A range [start, end)\n * @internal\n */\nexport interface IIntegerRange {\n\tstart: number;\n\tend: number;\n}\n\n/**\n * Emitted before this client's merge-tree normalizes its segments on reconnect, potentially\n * ordering them. Useful for DDS-like consumers built atop the merge-tree to compute any information\n * they need for rebasing their ops on reconnection.\n * @internal\n */\nexport interface IClientEvents {\n\t(event: \"normalize\", listener: (target: IEventThisPlaceHolder) => void): void;\n\t(\n\t\tevent: \"delta\",\n\t\tlistener: (\n\t\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t\t\ttarget: IEventThisPlaceHolder,\n\t\t) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (\n\t\t\targs: IMergeTreeMaintenanceCallbackArgs,\n\t\t\tdeltaArgs: IMergeTreeDeltaOpArgs | undefined,\n\t\t\ttarget: IEventThisPlaceHolder,\n\t\t) => void,\n\t): void;\n}\n\n/**\n * This class encapsulates a merge-tree, and provides a local client specific view over it and\n * the capability to modify it as the local client. Additionally it provides\n * binding for processing remote ops on the encapsulated merge tree, and projects local and remote events\n * caused by all modification to the underlying merge-tree.\n *\n * @internal\n */\nexport class Client extends TypedEventEmitter<IClientEvents> {\n\tpublic longClientId: string | undefined;\n\n\tprivate readonly _mergeTree: MergeTree;\n\n\tprivate readonly clientNameToIds = new RedBlackTree<string, number>(compareStrings);\n\tprivate readonly shortClientIdMap: string[] = [];\n\n\t/**\n\t * @param specToSegment - Rehydrates a segment from its JSON representation\n\t * @param logger - Telemetry logger for diagnostics\n\t * @param options - Options for this client. See {@link IMergeTreeOptions} for details.\n\t * @param getMinInFlightRefSeq - Upon applying a message (see {@link Client.applyMsg}), client purges collab-window information which\n\t * is no longer necessary based on that message's minimum sequence number.\n\t * However, if the user of this client has in-flight messages which refer to positions in this Client,\n\t * they may wish to preserve additional merge information.\n\t * The effective minimum sequence number will be the minimum of the message's minimumSequenceNumber and the result of this function.\n\t * If this function returns undefined, the message's minimumSequenceNumber will be used.\n\t *\n\t * @privateRemarks\n\t * - Passing specToSegment would be unnecessary if Client were merged with SharedSegmentSequence\n\t * - AB#6866 tracks a more unified approach to collab window min seq handling.\n\t */\n\tconstructor(\n\t\tpublic readonly specToSegment: (spec: IJSONSegment) => ISegment,\n\t\tpublic readonly logger: ITelemetryLoggerExt,\n\t\toptions?: IMergeTreeOptionsInternal & PropertySet,\n\t\tprivate readonly getMinInFlightRefSeq: () => number | undefined = (): undefined =>\n\t\t\tundefined,\n\t) {\n\t\tsuper();\n\t\tthis._mergeTree = new MergeTree(options);\n\t\tthis._mergeTree.mergeTreeDeltaCallback = (opArgs, deltaArgs): void => {\n\t\t\tthis.emit(\"delta\", opArgs, deltaArgs, this);\n\t\t};\n\t\tthis._mergeTree.mergeTreeMaintenanceCallback = (args, opArgs): void => {\n\t\t\tthis.emit(\"maintenance\", args, opArgs, this);\n\t\t};\n\n\t\tif (options?.attribution?.track) {\n\t\t\tconst policy = this._mergeTree?.attributionPolicy;\n\t\t\tif (policy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when attribution tracking is requested.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tpolicy.attach(this);\n\t\t}\n\t}\n\n\t/**\n\t * The merge tree maintains a queue of segment groups for each local operation.\n\t * These segment groups track segments modified by an operation.\n\t * This method peeks the tail of that queue, and returns the segments groups there.\n\t * It is used to get the segment group(s) for the previous operations.\n\t * @param count - The number segment groups to get peek from the tail of the queue. Default 1.\n\t */\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic peekPendingSegmentGroups(): SegmentGroup | undefined;\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic peekPendingSegmentGroups(count: number): SegmentGroup | SegmentGroup[] | undefined;\n\tpublic peekPendingSegmentGroups(\n\t\tcount: number = 1,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t): SegmentGroup | SegmentGroup[] | undefined {\n\t\tconst pending = this._mergeTree.pendingSegments;\n\t\tlet node = pending?.last;\n\t\tif (count === 1 || pending === undefined) {\n\t\t\treturn node?.data;\n\t\t}\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tconst taken: SegmentGroup[] = Array.from({ length: Math.min(count, pending.length) });\n\t\tfor (let i = taken.length - 1; i >= 0; i--) {\n\t\t\ttaken[i] = node!.data;\n\t\t\tnode = node!.prev;\n\t\t}\n\t\treturn taken;\n\t}\n\n\t/**\n\t * Annotates the markers with the provided properties\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t * @returns The annotate op if valid, otherwise undefined\n\t */\n\tpublic annotateMarker(\n\t\tmarker: Marker,\n\t\tprops: PropertySet,\n\t): IMergeTreeAnnotateMsg | undefined {\n\t\tconst annotateOp = createAnnotateMarkerOp(marker, props)!;\n\t\tthis.applyAnnotateRangeOp({ op: annotateOp });\n\t\treturn annotateOp;\n\t}\n\n\t/**\n\t * Annotates the range with the provided properties\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t * @returns The annotate op if valid, otherwise undefined\n\t */\n\tpublic annotateRangeLocal(\n\t\tstart: number,\n\t\tend: number,\n\t\tprops: PropertySet,\n\t): IMergeTreeAnnotateMsg | undefined {\n\t\tconst annotateOp = createAnnotateRangeOp(start, end, props);\n\t\tthis.applyAnnotateRangeOp({ op: annotateOp });\n\t\treturn annotateOp;\n\t}\n\n\t/**\n\t * adjusts a value\n\t */\n\tpublic annotateAdjustRangeLocal(\n\t\tstart: number,\n\t\tend: number,\n\t\tadjust: MapLike<AdjustParams>,\n\t): IMergeTreeAnnotateAdjustMsg {\n\t\tconst annotateOp = createAdjustRangeOp(start, end, adjust);\n\n\t\tfor (const [key, value] of Object.entries(adjust)) {\n\t\t\tif (value.min !== undefined && value.max !== undefined && value.min > value.max) {\n\t\t\t\tthrow new UsageError(`min is greater than max for ${key}`);\n\t\t\t}\n\t\t}\n\n\t\tthis.applyAnnotateRangeOp({ op: annotateOp });\n\t\treturn annotateOp;\n\t}\n\n\t/**\n\t * Removes the range\n\t *\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tpublic removeRangeLocal(start: number, end: number): IMergeTreeRemoveMsg {\n\t\tconst removeOp = createRemoveRangeOp(start, end);\n\t\tthis.applyRemoveRangeOp({ op: removeOp });\n\t\treturn removeOp;\n\t}\n\n\t/**\n\t * Obliterates the range. This is similar to removing the range, but also\n\t * includes any concurrently inserted content.\n\t *\n\t * @param start - The start of the range to obliterate. Inclusive is side is Before (default).\n\t * @param end - The end of the range to obliterate. Exclusive is side is After\n\t * (default is to be after the last included character, but number index is exclusive).\n\t */\n\tpublic obliterateRangeLocal(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t): IMergeTreeObliterateMsg | IMergeTreeObliterateSidedMsg {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tlet obliterateOp: IMergeTreeObliterateMsg | IMergeTreeObliterateSidedMsg;\n\t\tif (this._mergeTree.options?.mergeTreeEnableSidedObliterate) {\n\t\t\tobliterateOp = createObliterateRangeOpSided(start, end);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof start === \"number\" && typeof end === \"number\",\n\t\t\t\t0xa42 /* Start and end must be numbers if mergeTreeEnableSidedObliterate is not enabled. */,\n\t\t\t);\n\t\t\tobliterateOp = createObliterateRangeOp(start, end);\n\t\t}\n\t\tthis.applyObliterateRangeOp({ op: obliterateOp });\n\t\treturn obliterateOp;\n\t}\n\n\t/**\n\t * Create and insert a segment at the specified position.\n\t * @param pos - The position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertSegmentLocal(pos: number, segment: ISegment): IMergeTreeInsertMsg | undefined {\n\t\tif (segment.cachedLength <= 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst insertOp = createInsertSegmentOp(pos, segment);\n\t\tthis.applyInsertOp({ op: insertOp });\n\t\treturn insertOp;\n\t}\n\n\t/**\n\t * Create and insert a segment at the specified reference position.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertAtReferencePositionLocal(\n\t\trefPos: ReferencePosition,\n\t\tsegment: ISegment,\n\t): IMergeTreeInsertMsg | undefined {\n\t\tconst pos = this._mergeTree.referencePositionToLocalPosition(\n\t\t\trefPos,\n\t\t\tthis.getCurrentSeq(),\n\t\t\tthis.getClientId(),\n\t\t);\n\n\t\tif (pos === DetachedReferencePosition) {\n\t\t\tthrow new UsageError(\"Cannot insert at detached local reference.\");\n\t\t}\n\t\treturn this.insertSegmentLocal(pos, segment);\n\t}\n\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\taccum: TClientData,\n\t\tsplitRange?: boolean,\n\t): void;\n\tpublic walkSegments(\n\t\thandler: ISegmentAction<undefined>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: undefined,\n\t\tsplitRange?: boolean,\n\t): void;\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\taccum: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis._mergeTree.mapRange(\n\t\t\thandler,\n\t\t\tthis.getCurrentSeq(),\n\t\t\tthis.getClientId(),\n\t\t\taccum,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tsplitRange,\n\t\t);\n\t}\n\n\tprotected walkAllSegments<TClientData>(\n\t\taction: (segment: ISegment, accum?: TClientData) => boolean,\n\t\taccum?: TClientData,\n\t): boolean {\n\t\treturn walkAllChildSegments(\n\t\t\tthis._mergeTree.root,\n\t\t\taccum === undefined ? action : (seg): boolean => action(seg, accum),\n\t\t);\n\t}\n\n\t/**\n\t * Serializes the data required for garbage collection. The IFluidHandles stored in all segments that haven't\n\t * been removed represent routes to other objects. We serialize the data in these segments using the passed in\n\t * serializer which keeps track of all serialized handles.\n\t */\n\tpublic serializeGCData(\n\t\thandle: IFluidHandle,\n\t\thandleCollectingSerializer: IFluidSerializer,\n\t): void {\n\t\tlet localInserts = 0;\n\t\tlet localRemoves = 0;\n\t\twalkAllChildSegments(this._mergeTree.root, (seg: ISegmentLeaf) => {\n\t\t\tif (seg.seq === UnassignedSequenceNumber) {\n\t\t\t\tlocalInserts++;\n\t\t\t}\n\t\t\tif (seg.removedSeq === UnassignedSequenceNumber) {\n\t\t\t\tlocalRemoves++;\n\t\t\t}\n\t\t\t// Only serialize segments that have not been removed.\n\t\t\tif (seg.removedSeq === undefined) {\n\t\t\t\thandleCollectingSerializer.stringify(seg.clone().toJSONObject(), handle);\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\n\t\tif (localInserts > 0 || localRemoves > 0) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"LocalEditsInProcessGCData\",\n\t\t\t\tlocalInserts,\n\t\t\t\tlocalRemoves,\n\t\t\t});\n\t\t}\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic getCollabWindow(): CollaborationWindow {\n\t\treturn this._mergeTree.collabWindow;\n\t}\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this merge tree\n\t * @param segment - The segment to get the position of\n\t */\n\tpublic getPosition(segment: ISegment | undefined, localSeq?: number): number {\n\t\tconst mergeSegment: ISegmentLeaf | undefined = segment;\n\t\tif (mergeSegment?.parent === undefined) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn this._mergeTree.getPosition(\n\t\t\tmergeSegment,\n\t\t\tthis.getCurrentSeq(),\n\t\t\tthis.getClientId(),\n\t\t\tlocalSeq,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a `LocalReferencePosition` on this client. If the refType does not include ReferenceType.Transient,\n\t * the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t * @param canSlideToEndpoint - Whether or not the created local reference can\n\t * slide onto one of the special endpoint segments denoting the position\n\t * before the start of or after the end of the tree\n\t */\n\tpublic createLocalReferencePosition(\n\t\tsegment: ISegment | \"start\" | \"end\",\n\t\toffset: number | undefined,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\treturn this._mergeTree.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset ?? 0,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this client.\n\t */\n\tpublic removeLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined {\n\t\treturn this._mergeTree.removeLocalReferencePosition(lref);\n\t}\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of {@link ReferenceType}. To handle this case specifically, one may wish\n\t * to look at the segment returned by {@link ReferencePosition.getSegment}.\n\t */\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this._mergeTree.referencePositionToLocalPosition(lref);\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition): number {\n\t\treturn this._mergeTree.posFromRelativePos(relativePos);\n\t}\n\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this._mergeTree.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tpublic rollback?(op: unknown, localOpMetadata: unknown): void {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tthis._mergeTree.rollback(op as IMergeTreeDeltaOp, localOpMetadata as SegmentGroup);\n\t}\n\n\tprivate applyObliterateRangeOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE_SIDED,\n\t\t\t0x866 /* Unexpected op type on range obliterate! */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tif (this._mergeTree.options?.mergeTreeEnableSidedObliterate) {\n\t\t\tconst { start, end } = this.getValidSidedRange(op, clientArgs);\n\t\t\tthis._mergeTree.obliterateRange(\n\t\t\t\tstart,\n\t\t\t\tend,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t\tclientArgs.sequenceNumber,\n\t\t\t\topArgs,\n\t\t\t);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\top.type === MergeTreeDeltaType.OBLITERATE,\n\t\t\t\t0xa43 /* Unexpected sided obliterate while mergeTreeEnableSidedObliterate is disabled */,\n\t\t\t);\n\t\t\tconst range = this.getValidOpRange(op, clientArgs);\n\t\t\tthis._mergeTree.obliterateRange(\n\t\t\t\trange.start,\n\t\t\t\trange.end,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t\tclientArgs.sequenceNumber,\n\t\t\t\topArgs,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Performs the remove based on the provided op\n\t * @param opArgs - The ops args for the op\n\t */\n\tprivate applyRemoveRangeOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.REMOVE,\n\t\t\t0x02d /* \"Unexpected op type on range remove!\" */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tconst range = this.getValidOpRange(op, clientArgs);\n\n\t\tthis._mergeTree.markRangeRemoved(\n\t\t\trange.start,\n\t\t\trange.end,\n\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\tclientArgs.clientId,\n\t\t\tclientArgs.sequenceNumber,\n\t\t\topArgs,\n\t\t);\n\t}\n\n\t/**\n\t * Performs the annotate based on the provided op\n\t * @param opArgs - The ops args for the op\n\t */\n\tprivate applyAnnotateRangeOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.ANNOTATE,\n\t\t\t0x02e /* \"Unexpected op type on range annotate!\" */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tconst range = this.getValidOpRange(op, clientArgs);\n\n\t\tthis._mergeTree.annotateRange(\n\t\t\trange.start,\n\t\t\trange.end,\n\t\t\top,\n\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\tclientArgs.clientId,\n\t\t\tclientArgs.sequenceNumber,\n\t\t\topArgs,\n\t\t);\n\t}\n\n\t/**\n\t * Performs the insert based on the provided op\n\t * @param opArgs - The ops args for the op\n\t * @returns True if the insert was applied. False if it could not be.\n\t */\n\tprivate applyInsertOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.INSERT,\n\t\t\t0x02f /* \"Unexpected op type on range insert!\" */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tconst range = this.getValidOpRange(op, clientArgs);\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\tconst segments = [this.specToSegment(op.seg)];\n\n\t\tthis._mergeTree.insertSegments(\n\t\t\trange.start,\n\t\t\tsegments,\n\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\tclientArgs.clientId,\n\t\t\tclientArgs.sequenceNumber,\n\t\t\topArgs,\n\t\t);\n\t}\n\n\t/**\n\t * Returns a valid range for the op, or throws if the range is invalid\n\t * @param op - The op to generate the range for\n\t * @param clientArgs - The client args for the op\n\t * @throws LoggingError if the range is invalid\n\t */\n\tprivate getValidSidedRange(\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\top: IMergeTreeObliterateSidedMsg | IMergeTreeObliterateMsg,\n\t\tclientArgs: IMergeTreeClientSequenceArgs,\n\t): {\n\t\tstart: InteriorSequencePlace;\n\t\tend: InteriorSequencePlace;\n\t} {\n\t\tconst invalidPositions: string[] = [];\n\t\tlet start: InteriorSequencePlace | undefined;\n\t\tlet end: InteriorSequencePlace | undefined;\n\t\tif (op.pos1 === undefined) {\n\t\t\tinvalidPositions.push(\"start\");\n\t\t} else {\n\t\t\tstart =\n\t\t\t\ttypeof op.pos1 === \"object\"\n\t\t\t\t\t? { pos: op.pos1.pos, side: op.pos1.before ? Side.Before : Side.After }\n\t\t\t\t\t: { pos: op.pos1, side: Side.Before };\n\t\t}\n\t\tif (op.pos2 === undefined) {\n\t\t\tinvalidPositions.push(\"end\");\n\t\t} else {\n\t\t\tend =\n\t\t\t\ttypeof op.pos2 === \"object\"\n\t\t\t\t\t? { pos: op.pos2.pos, side: op.pos2.before ? Side.Before : Side.After }\n\t\t\t\t\t: { pos: op.pos2 - 1, side: Side.After };\n\t\t}\n\n\t\t// Validate if local op\n\t\tif (clientArgs.clientId === this.getClientId()) {\n\t\t\tconst length = this._mergeTree.getLength(\n\t\t\t\tthis.getCollabWindow().currentSeq,\n\t\t\t\tthis.getClientId(),\n\t\t\t);\n\t\t\tif (start !== undefined && (start.pos >= length || start.pos < 0)) {\n\t\t\t\t// start out of bounds\n\t\t\t\tinvalidPositions.push(\"start\");\n\t\t\t}\n\t\t\tif (end !== undefined && (end.pos >= length || end.pos < 0)) {\n\t\t\t\tinvalidPositions.push(\"end\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\tstart !== undefined &&\n\t\t\t\tend !== undefined &&\n\t\t\t\t(start.pos > end.pos ||\n\t\t\t\t\t(start.pos === end.pos && start.side !== end.side && start.side === Side.After))\n\t\t\t) {\n\t\t\t\t// end is before start\n\t\t\t\tinvalidPositions.push(\"inverted\");\n\t\t\t}\n\t\t\tif (invalidPositions.length > 0) {\n\t\t\t\tthrow new LoggingError(\"InvalidRange\", {\n\t\t\t\t\tusageError: true,\n\t\t\t\t\tinvalidPositions: invalidPositions.toString(),\n\t\t\t\t\tlength,\n\t\t\t\t\topType: op.type,\n\t\t\t\t\topPos1Relative: op.relativePos1 !== undefined,\n\t\t\t\t\topPos2Relative: op.relativePos2 !== undefined,\n\t\t\t\t\topPos1: JSON.stringify(op.pos1),\n\t\t\t\t\topPos2: JSON.stringify(op.pos2),\n\t\t\t\t\tstart: JSON.stringify(start),\n\t\t\t\t\tend: JSON.stringify(end),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tstart !== undefined && end !== undefined,\n\t\t\t0xa44 /* Missing start or end of range */,\n\t\t);\n\t\treturn { start, end };\n\t}\n\n\t/**\n\t * Returns a valid range for the op, or undefined\n\t * @param op - The op to generate the range for\n\t * @param clientArgs - The client args for the op\n\t */\n\tprivate getValidOpRange(\n\t\top:\n\t\t\t| IMergeTreeAnnotateMsg\n\t\t\t| IMergeTreeAnnotateAdjustMsg\n\t\t\t| IMergeTreeInsertMsg\n\t\t\t| IMergeTreeRemoveMsg\n\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t| IMergeTreeObliterateMsg,\n\t\tclientArgs: IMergeTreeClientSequenceArgs,\n\t): IIntegerRange {\n\t\tlet start: number | undefined = op.pos1;\n\t\tif (start === undefined && op.relativePos1) {\n\t\t\tstart = this._mergeTree.posFromRelativePos(\n\t\t\t\top.relativePos1,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t);\n\t\t}\n\n\t\tlet end: number | undefined = op.pos2;\n\t\tif (end === undefined && op.relativePos2) {\n\t\t\tend = this._mergeTree.posFromRelativePos(\n\t\t\t\top.relativePos2,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t);\n\t\t}\n\n\t\t// Validate if local op\n\t\tif (clientArgs.clientId === this.getClientId()) {\n\t\t\tconst length = this.getLength();\n\n\t\t\tconst invalidPositions: string[] = [];\n\n\t\t\t// Validate start position\n\t\t\t//\n\t\t\tif (\n\t\t\t\tstart === undefined ||\n\t\t\t\tstart < 0 ||\n\t\t\t\tstart > length ||\n\t\t\t\t(start === length && op.type !== MergeTreeDeltaType.INSERT)\n\t\t\t) {\n\t\t\t\tinvalidPositions.push(\"start\");\n\t\t\t}\n\t\t\t// Validate end if not insert, or insert has end\n\t\t\tif (\n\t\t\t\t(op.type !== MergeTreeDeltaType.INSERT || end !== undefined) &&\n\t\t\t\t(end === undefined || end <= start!)\n\t\t\t) {\n\t\t\t\tinvalidPositions.push(\"end\");\n\t\t\t}\n\n\t\t\tif (op.type === MergeTreeDeltaType.OBLITERATE && end !== undefined && end > length) {\n\t\t\t\tinvalidPositions.push(\"end\");\n\t\t\t}\n\n\t\t\tif (invalidPositions.length > 0) {\n\t\t\t\tthrow new LoggingError(\"RangeOutOfBounds\", {\n\t\t\t\t\tusageError: true,\n\t\t\t\t\tend,\n\t\t\t\t\tinvalidPositions: invalidPositions.toString(),\n\t\t\t\t\tlength,\n\t\t\t\t\topPos1: op.pos1,\n\t\t\t\t\topPos1Relative: op.relativePos1 !== undefined,\n\t\t\t\t\topPos2: op.pos2,\n\t\t\t\t\topPos2Relative: op.relativePos2 !== undefined,\n\t\t\t\t\topType: op.type,\n\t\t\t\t\tstart,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// start and end are guaranteed to be non-null here, otherwise we throw above.\n\t\treturn { start: start!, end: end! };\n\t}\n\n\t/**\n\t * Gets the client args from the op if remote, otherwise uses the local clients info\n\t * @param sequencedMessage - The sequencedMessage to get the client sequence args for\n\t */\n\tprivate getClientSequenceArgsForMessage(\n\t\tsequencedMessage:\n\t\t\t| ISequencedDocumentMessage\n\t\t\t| Pick<ISequencedDocumentMessage, \"referenceSequenceNumber\" | \"clientId\">\n\t\t\t| undefined,\n\t): IMergeTreeClientSequenceArgs {\n\t\t// If there this no sequenced message, then the op is local\n\t\t// and unacked, so use this clients sequenced args\n\t\t//\n\t\tif (sequencedMessage) {\n\t\t\treturn {\n\t\t\t\tclientId: this.getOrAddShortClientIdFromMessage(sequencedMessage),\n\t\t\t\treferenceSequenceNumber: sequencedMessage.referenceSequenceNumber,\n\t\t\t\t// Note: return value satisfies overload signatures despite the cast, as if input argument doesn't contain sequenceNumber,\n\t\t\t\t// return value isn't expected to have it either.\n\t\t\t\tsequenceNumber: (sequencedMessage as ISequencedDocumentMessage).sequenceNumber,\n\t\t\t};\n\t\t} else {\n\t\t\tconst segWindow = this.getCollabWindow();\n\t\t\treturn {\n\t\t\t\tclientId: segWindow.clientId,\n\t\t\t\treferenceSequenceNumber: segWindow.currentSeq,\n\t\t\t\tsequenceNumber: this.getLocalSequenceNumber(),\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Gets the client args from the op if remote, otherwise uses the local clients info\n\t * @param opArgs - The op arg to get the client sequence args for\n\t */\n\tprivate getClientSequenceArgs(opArgs: IMergeTreeDeltaOpArgs): IMergeTreeClientSequenceArgs {\n\t\treturn this.getClientSequenceArgsForMessage(opArgs.sequencedMessage);\n\t}\n\n\tprivate ackPendingSegment(opArgs: IMergeTreeDeltaRemoteOpArgs): void {\n\t\tif (opArgs.op.type === MergeTreeDeltaType.GROUP) {\n\t\t\tfor (const memberOp of opArgs.op.ops) {\n\t\t\t\tthis._mergeTree.ackPendingSegment({\n\t\t\t\t\tgroupOp: opArgs.op,\n\t\t\t\t\top: memberOp,\n\t\t\t\t\tsequencedMessage: opArgs.sequencedMessage,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tthis._mergeTree.ackPendingSegment(opArgs);\n\t\t}\n\t}\n\n\tgetOrAddShortClientId(longClientId: string): number {\n\t\tif (!this.clientNameToIds.get(longClientId)) {\n\t\t\tthis.addLongClientId(longClientId);\n\t\t}\n\t\treturn this.getShortClientId(longClientId);\n\t}\n\n\tprotected getShortClientId(longClientId: string): number {\n\t\treturn this.clientNameToIds.get(longClientId)!.data;\n\t}\n\n\tgetLongClientId(shortClientId: number): string {\n\t\treturn shortClientId >= 0 ? this.shortClientIdMap[shortClientId] : \"original\";\n\t}\n\n\taddLongClientId(longClientId: string): void {\n\t\tthis.clientNameToIds.put(longClientId, this.shortClientIdMap.length);\n\t\tthis.shortClientIdMap.push(longClientId);\n\t}\n\n\tprivate getOrAddShortClientIdFromMessage(\n\t\tmsg: Pick<ISequencedDocumentMessage, \"clientId\">,\n\t): number {\n\t\treturn this.getOrAddShortClientId(msg.clientId ?? \"server\");\n\t}\n\n\t/**\n\t * During reconnect, we must find the positions to pending segments\n\t * relative to other pending segments. This methods computes that\n\t * position relative to a localSeq. Pending segments above the localSeq\n\t * will be ignored.\n\t *\n\t * @param segment - The segment to find the position for\n\t * @param localSeq - The localSeq to find the position of the segment at\n\t */\n\tpublic findReconnectionPosition(segment: ISegment, localSeq: number): number {\n\t\tassert(\n\t\t\tlocalSeq <= this._mergeTree.collabWindow.localSeq,\n\t\t\t0x032 /* \"localSeq greater than collab window\" */,\n\t\t);\n\t\tconst { currentSeq, clientId } = this.getCollabWindow();\n\t\treturn this._mergeTree.getPosition(segment, currentSeq, clientId, localSeq);\n\t}\n\n\tprivate resetPendingDeltaToOps(\n\t\tresetOp: IMergeTreeDeltaOp,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tsegmentGroup: SegmentGroup<ISegmentLeaf>,\n\t): IMergeTreeDeltaOp[] {\n\t\tassert(!!segmentGroup, 0x033 /* \"Segment group undefined\" */);\n\t\tconst NACKedSegmentGroup = this.pendingRebase?.shift()?.data;\n\t\tassert(\n\t\t\tsegmentGroup === NACKedSegmentGroup,\n\t\t\t0x034 /* \"Segment group not at head of pending rebase queue\" */,\n\t\t);\n\t\tif (this.pendingRebase?.empty) {\n\t\t\tthis.pendingRebase = undefined;\n\t\t}\n\n\t\t// if this is an obliterate op, keep all segments in same segment group\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tconst obliterateSegmentGroup: SegmentGroup = {\n\t\t\tsegments: [],\n\t\t\tlocalSeq: segmentGroup.localSeq,\n\t\t\trefSeq: this.getCollabWindow().currentSeq,\n\t\t\tobliterateInfo: {\n\t\t\t\t...segmentGroup.obliterateInfo!,\n\t\t\t},\n\t\t};\n\n\t\tconst opList: IMergeTreeDeltaOp[] = [];\n\t\t// We need to sort the segments by ordinal, as the segments are not sorted in the segment group.\n\t\t// The reason they need them sorted, as they have the same local sequence number and which means\n\t\t// farther segments will take into account nearer segments when calculating their position.\n\t\t// By sorting we ensure the nearer segment will be applied and sequenced before the farther segments\n\t\t// so their recalculated positions will be correct.\n\t\tfor (const segment of segmentGroup.segments.sort((a, b) =>\n\t\t\ta.ordinal < b.ordinal ? -1 : 1,\n\t\t)) {\n\t\t\tassert(\n\t\t\t\tsegment.segmentGroups?.remove?.(segmentGroup) === true,\n\t\t\t\t0x035 /* \"Segment group not in segment pending queue\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tsegmentGroup.localSeq !== undefined,\n\t\t\t\t0x867 /* expected segment group localSeq to be defined */,\n\t\t\t);\n\t\t\tconst segmentPosition = this.findReconnectionPosition(segment, segmentGroup.localSeq);\n\t\t\tlet newOp: IMergeTreeDeltaOp | undefined;\n\t\t\tswitch (resetOp.type) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsegment.propertyManager?.hasPendingProperties(resetOp.props ?? resetOp.adjust) ===\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t0x036 /* \"Segment has no pending properties\" */,\n\t\t\t\t\t);\n\t\t\t\t\t// if the segment has been removed or obliterated, there's no need to send the annotate op\n\t\t\t\t\t// unless the remove was local, in which case the annotate must have come\n\t\t\t\t\t// before the remove\n\t\t\t\t\tif (\n\t\t\t\t\t\t(segment.removedSeq === undefined ||\n\t\t\t\t\t\t\t(segment.localRemovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber)) &&\n\t\t\t\t\t\t(segment.movedSeq === undefined ||\n\t\t\t\t\t\t\t(segment.localMovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.movedSeq === UnassignedSequenceNumber))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewOp =\n\t\t\t\t\t\t\tresetOp.props === undefined\n\t\t\t\t\t\t\t\t? createAdjustRangeOp(\n\t\t\t\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t\t\t\t\tresetOp.adjust,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: createAnnotateRangeOp(\n\t\t\t\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t\t\t\t\tresetOp.props,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsegment.seq === UnassignedSequenceNumber,\n\t\t\t\t\t\t0x037 /* \"Segment already has assigned sequence number\" */,\n\t\t\t\t\t);\n\t\t\t\t\tconst moveInfo = toMoveInfo(segment);\n\n\t\t\t\t\tif (moveInfo !== undefined) {\n\t\t\t\t\t\terrorIfOptionNotTrue(\n\t\t\t\t\t\t\tthis._mergeTree.options,\n\t\t\t\t\t\t\t\"mergeTreeEnableObliterateReconnect\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (moveInfo.movedSeq !== UnassignedSequenceNumber) {\n\t\t\t\t\t\t\t// the segment was remotely obliterated, so is considered removed\n\t\t\t\t\t\t\t// we set the seq to the universal seq and remove the local seq,\n\t\t\t\t\t\t\t// so its length is not considered for subsequent local changes\n\t\t\t\t\t\t\t// this allows us to not send the op as even the local client will ignore the segment\n\t\t\t\t\t\t\tsegment.seq = UniversalSequenceNumber;\n\t\t\t\t\t\t\tsegment.localSeq = undefined;\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst segInsertOp: ISegment = segment.clone();\n\t\t\t\t\tconst opProps =\n\t\t\t\t\t\tisObject(resetOp.seg) && \"props\" in resetOp.seg && isObject(resetOp.seg.props)\n\t\t\t\t\t\t\t? { ...resetOp.seg.props }\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tsegInsertOp.properties = opProps;\n\t\t\t\t\tnewOp = createInsertSegmentOp(segmentPosition, segInsertOp);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tif (\n\t\t\t\t\t\tsegment.localRemovedSeq !== undefined &&\n\t\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber &&\n\t\t\t\t\t\t(segment.movedSeq === undefined ||\n\t\t\t\t\t\t\t(segment.localMovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.movedSeq === UnassignedSequenceNumber))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewOp = createRemoveRangeOp(\n\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\terrorIfOptionNotTrue(this._mergeTree.options, \"mergeTreeEnableObliterateReconnect\");\n\t\t\t\t\tif (\n\t\t\t\t\t\tsegment.localMovedSeq !== undefined &&\n\t\t\t\t\t\tsegment.movedSeq === UnassignedSequenceNumber &&\n\t\t\t\t\t\t(segment.removedSeq === undefined ||\n\t\t\t\t\t\t\t(segment.localRemovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewOp = createObliterateRangeOp(\n\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(`Invalid op type`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (newOp && resetOp.type === MergeTreeDeltaType.OBLITERATE) {\n\t\t\t\tsegment.segmentGroups.enqueue(obliterateSegmentGroup);\n\n\t\t\t\tconst first = opList[0];\n\n\t\t\t\tif (\n\t\t\t\t\t!!first &&\n\t\t\t\t\tfirst.pos2 !== undefined &&\n\t\t\t\t\tfirst.type !== MergeTreeDeltaType.OBLITERATE_SIDED &&\n\t\t\t\t\tnewOp.type !== MergeTreeDeltaType.OBLITERATE_SIDED\n\t\t\t\t) {\n\t\t\t\t\tfirst.pos2 += newOp.pos2! - newOp.pos1!;\n\t\t\t\t} else {\n\t\t\t\t\topList.push(newOp);\n\t\t\t\t}\n\t\t\t} else if (newOp) {\n\t\t\t\tconst newSegmentGroup: SegmentGroup = {\n\t\t\t\t\tsegments: [],\n\t\t\t\t\tlocalSeq: segmentGroup.localSeq,\n\t\t\t\t\trefSeq: this.getCollabWindow().currentSeq,\n\t\t\t\t};\n\t\t\t\tsegment.segmentGroups.enqueue(newSegmentGroup);\n\n\t\t\t\tthis._mergeTree.pendingSegments.push(newSegmentGroup);\n\n\t\t\t\topList.push(newOp);\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tresetOp.type === MergeTreeDeltaType.OBLITERATE &&\n\t\t\tobliterateSegmentGroup.segments.length > 0\n\t\t) {\n\t\t\tthis._mergeTree.pendingSegments.push(obliterateSegmentGroup);\n\t\t}\n\n\t\treturn opList;\n\t}\n\n\tprivate applyRemoteOp(opArgs: IMergeTreeDeltaRemoteOpArgs): void {\n\t\tconst op = opArgs.op;\n\t\tconst msg = opArgs.sequencedMessage;\n\t\tthis.getOrAddShortClientIdFromMessage(msg);\n\t\tswitch (op.type) {\n\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\tthis.applyInsertOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\tthis.applyRemoveRangeOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\tthis.applyAnnotateRangeOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.OBLITERATE:\n\t\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED: {\n\t\t\t\tthis.applyObliterateRangeOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.GROUP: {\n\t\t\t\tfor (const memberOp of op.ops) {\n\t\t\t\t\tthis.applyRemoteOp({\n\t\t\t\t\t\top: memberOp,\n\t\t\t\t\t\tgroupOp: op,\n\t\t\t\t\t\tsequencedMessage: msg,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyStashedOp(op: IMergeTreeOp): void {\n\t\tswitch (op.type) {\n\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\tthis.applyInsertOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\tthis.applyRemoveRangeOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\tthis.applyAnnotateRangeOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED:\n\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\tthis.applyObliterateRangeOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.GROUP: {\n\t\t\t\top.ops.map((o) => this.applyStashedOp(o));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(op, \"unrecognized op type\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyMsg(msg: ISequencedDocumentMessage, local: boolean = false): void {\n\t\t// Ensure client ID is registered\n\t\tthis.getOrAddShortClientIdFromMessage(msg);\n\t\t// Apply if an operation message\n\t\tif (msg.type === MessageType.Operation) {\n\t\t\tconst opArgs: IMergeTreeDeltaRemoteOpArgs = {\n\t\t\t\top: msg.contents as IMergeTreeOp,\n\t\t\t\tsequencedMessage: msg,\n\t\t\t};\n\t\t\tif (opArgs.sequencedMessage?.clientId === this.longClientId || local) {\n\t\t\t\tthis.ackPendingSegment(opArgs);\n\t\t\t} else {\n\t\t\t\tthis.applyRemoteOp(opArgs);\n\t\t\t}\n\t\t}\n\n\t\tconst min = Math.min(\n\t\t\tthis.getMinInFlightRefSeq() ?? Number.POSITIVE_INFINITY,\n\t\t\tmsg.minimumSequenceNumber,\n\t\t);\n\t\tthis.updateSeqNumbers(min, msg.sequenceNumber);\n\t}\n\n\tprivate updateSeqNumbers(min: number, seq: number): void {\n\t\tconst collabWindow = this.getCollabWindow();\n\t\t// Equal is fine here due to SharedSegmentSequence<>.snapshotContent() potentially updating with same #\n\t\tassert(\n\t\t\tcollabWindow.currentSeq <= seq,\n\t\t\t0x038 /* \"Incoming op sequence# < local collabWindow's currentSequence#\" */,\n\t\t);\n\t\tcollabWindow.currentSeq = seq;\n\t\tassert(min <= seq, 0x039 /* \"Incoming op sequence# < minSequence#\" */);\n\t\tthis.updateMinSeq(min);\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\tconst shortRemoteClientId = this.getOrAddShortClientId(remoteClientId);\n\t\treturn this._mergeTree.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tshortRemoteClientId,\n\t\t);\n\t}\n\n\tprivate lastNormalizationRefSeq = 0;\n\n\t// eslint-disable-next-line import/no-deprecated\n\tprivate pendingRebase: DoublyLinkedList<SegmentGroup> | undefined;\n\n\t/**\n\t * Given a pending operation and segment group, regenerate the op, so it\n\t * can be resubmitted\n\t * @param resetOp - The op to reset\n\t * @param segmentGroup - The segment group associated with the op\n\t */\n\tpublic regeneratePendingOp(\n\t\tresetOp: IMergeTreeOp,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tsegmentGroup: SegmentGroup | SegmentGroup[],\n\t): IMergeTreeOp {\n\t\tif (this.pendingRebase === undefined || this.pendingRebase.empty) {\n\t\t\tlet firstGroup: SegmentGroup;\n\t\t\tif (Array.isArray(segmentGroup)) {\n\t\t\t\tif (segmentGroup.length === 0) {\n\t\t\t\t\t// sometimes we rebase to an empty op\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\treturn createGroupOp();\n\t\t\t\t}\n\t\t\t\tfirstGroup = segmentGroup[0];\n\t\t\t} else {\n\t\t\t\tfirstGroup = segmentGroup;\n\t\t\t}\n\t\t\tconst firstGroupNode = this._mergeTree.pendingSegments.find(\n\t\t\t\t(node) => node.data === firstGroup,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tfirstGroupNode !== undefined,\n\t\t\t\t0x70e /* segment group must exist in pending list */,\n\t\t\t);\n\t\t\tthis.pendingRebase = this._mergeTree.pendingSegments.splice(firstGroupNode);\n\t\t}\n\n\t\tconst rebaseTo = this.getCollabWindow().currentSeq;\n\t\tif (rebaseTo !== this.lastNormalizationRefSeq) {\n\t\t\tthis.emit(\"normalize\", this);\n\t\t\tthis._mergeTree.normalizeSegmentsOnRebase();\n\t\t\tthis.lastNormalizationRefSeq = rebaseTo;\n\t\t}\n\n\t\tconst opList: IMergeTreeDeltaOp[] = [];\n\t\tif (resetOp.type === MergeTreeDeltaType.GROUP) {\n\t\t\tif (Array.isArray(segmentGroup)) {\n\t\t\t\tassert(\n\t\t\t\t\tresetOp.ops.length === segmentGroup.length,\n\t\t\t\t\t0x03a /* \"Number of ops in 'resetOp' must match the number of segment groups provided.\" */,\n\t\t\t\t);\n\n\t\t\t\tfor (let i = 0; i < resetOp.ops.length; i++) {\n\t\t\t\t\topList.push(...this.resetPendingDeltaToOps(resetOp.ops[i], segmentGroup[i]));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// A group op containing a single op will pass a direct reference to 'segmentGroup'\n\t\t\t\t// rather than an array of segment groups. (See 'peekPendingSegmentGroups()')\n\t\t\t\tassert(\n\t\t\t\t\tresetOp.ops.length === 1,\n\t\t\t\t\t0x03b /* \"Number of ops in 'resetOp' must match the number of segment groups provided.\" */,\n\t\t\t\t);\n\t\t\t\topList.push(...this.resetPendingDeltaToOps(resetOp.ops[0], segmentGroup));\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\t(resetOp.type as unknown) !== MergeTreeDeltaType.GROUP,\n\t\t\t\t0x03c /* \"Reset op has 'group' delta type!\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\t!Array.isArray(segmentGroup),\n\t\t\t\t0x03d /* \"segmentGroup is array rather than singleton!\" */,\n\t\t\t);\n\t\t\topList.push(...this.resetPendingDeltaToOps(resetOp, segmentGroup));\n\t\t}\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\treturn opList.length === 1 ? opList[0] : createGroupOp(...opList);\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tpublic createTextHelper(): IMergeTreeTextHelper {\n\t\treturn new MergeTreeTextHelper(this._mergeTree);\n\t}\n\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t\tcatchUpMsgs: ISequencedDocumentMessage[],\n\t): ISummaryTreeWithStats {\n\t\tconst deltaManager = toDeltaManagerInternal(runtime.deltaManager);\n\t\tconst minSeq = deltaManager.minimumSequenceNumber;\n\n\t\t// Catch up to latest MSN, if we have not had a chance to do it.\n\t\t// Required for case where FluidDataStoreRuntime.attachChannel()\n\t\t// generates summary right after loading data store.\n\n\t\tthis.updateSeqNumbers(minSeq, deltaManager.lastSequenceNumber);\n\n\t\t// One of the summaries (from SPO) I observed to have chunk.chunkSequenceNumber > minSeq!\n\t\t// Not sure why - need to catch it sooner\n\t\tassert(\n\t\t\tthis.getCollabWindow().minSeq === minSeq,\n\t\t\t0x03e /* \"minSeq mismatch between collab window and delta manager!\" */,\n\t\t);\n\n\t\t// Must continue to support legacy\n\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\tif (this._mergeTree.options?.newMergeTreeSnapshotFormat === true) {\n\t\t\tassert(\n\t\t\t\tcatchUpMsgs === undefined || catchUpMsgs.length === 0,\n\t\t\t\t0x03f /* \"New format should not emit catchup ops\" */,\n\t\t\t);\n\t\t\tconst snap = new SnapshotV1(this._mergeTree, this.logger, (id) =>\n\t\t\t\tthis.getLongClientId(id),\n\t\t\t);\n\t\t\tsnap.extractSync();\n\t\t\treturn snap.emit(serializer, handle);\n\t\t} else {\n\t\t\tconst snap = new SnapshotLegacy(this._mergeTree, this.logger);\n\t\t\tsnap.extractSync();\n\t\t\treturn snap.emit(catchUpMsgs, serializer, handle);\n\t\t}\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst loader = new SnapshotLoader(runtime, this, this._mergeTree, this.logger, serializer);\n\n\t\treturn loader.initialize(storage);\n\t}\n\n\tprivate getLocalSequenceNumber(): number {\n\t\tconst segWindow = this.getCollabWindow();\n\t\treturn segWindow.collaborating ? UnassignedSequenceNumber : UniversalSequenceNumber;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tlocalTransaction(groupOp: IMergeTreeGroupMsg): void {\n\t\tfor (const op of groupOp.ops) {\n\t\t\tconst opArgs: IMergeTreeDeltaOpArgs = {\n\t\t\t\top,\n\t\t\t\tgroupOp,\n\t\t\t};\n\t\t\tswitch (op.type) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t\tthis.applyInsertOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tthis.applyAnnotateRangeOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tthis.applyRemoveRangeOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED:\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\tthis.applyObliterateRangeOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tupdateMinSeq(minSeq: number): void {\n\t\tthis._mergeTree.setMinSeq(minSeq);\n\t}\n\n\tgetContainingSegment<T extends ISegment>(\n\t\tpos: number,\n\t\tsequenceArgs?: Pick<ISequencedDocumentMessage, \"referenceSequenceNumber\" | \"clientId\">,\n\t\tlocalSeq?: number,\n\t): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\tconst { referenceSequenceNumber, clientId } =\n\t\t\tthis.getClientSequenceArgsForMessage(sequenceArgs);\n\t\treturn this._mergeTree.getContainingSegment<T>(\n\t\t\tpos,\n\t\t\treferenceSequenceNumber,\n\t\t\tclientId,\n\t\t\tlocalSeq,\n\t\t);\n\t}\n\n\tgetPropertiesAtPosition(pos: number): PropertySet | undefined {\n\t\tlet propertiesAtPosition: PropertySet | undefined;\n\t\tconst segoff = this.getContainingSegment(pos);\n\t\tconst seg = segoff.segment;\n\t\tif (seg) {\n\t\t\tpropertiesAtPosition = seg.properties;\n\t\t}\n\t\treturn propertiesAtPosition;\n\t}\n\n\tgetRangeExtentsOfPosition(pos: number): {\n\t\tposStart: number | undefined;\n\t\tposAfterEnd: number | undefined;\n\t} {\n\t\tlet posStart: number | undefined;\n\t\tlet posAfterEnd: number | undefined;\n\n\t\tconst segoff = this.getContainingSegment(pos);\n\t\tconst seg = segoff.segment;\n\t\tif (seg) {\n\t\t\tposStart = this.getPosition(seg);\n\t\t\tposAfterEnd = posStart + seg.cachedLength;\n\t\t}\n\t\treturn { posStart, posAfterEnd };\n\t}\n\n\tgetCurrentSeq(): number {\n\t\treturn this.getCollabWindow().currentSeq;\n\t}\n\n\tgetClientId(): number {\n\t\treturn this.getCollabWindow().clientId;\n\t}\n\n\tgetLength(): number {\n\t\treturn this._mergeTree.length ?? 0;\n\t}\n\n\tstartOrUpdateCollaboration(\n\t\tlongClientId: string | undefined,\n\t\tminSeq = 0,\n\t\tcurrentSeq = 0,\n\t): void {\n\t\t// we should always have a client id if we are collaborating\n\t\t// if the client id is undefined we are likely bound to a detached\n\t\t// container, so we should keep going in local mode. once\n\t\t// the container attaches this will be called again on connect with the\n\t\t// client id\n\t\tif (longClientId !== undefined) {\n\t\t\tif (this.longClientId === undefined) {\n\t\t\t\tthis.longClientId = longClientId;\n\t\t\t\tthis.addLongClientId(this.longClientId);\n\t\t\t\tthis._mergeTree.startCollaboration(\n\t\t\t\t\tthis.getShortClientId(this.longClientId),\n\t\t\t\t\tminSeq,\n\t\t\t\t\tcurrentSeq,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst oldClientId = this.longClientId;\n\t\t\t\tconst oldData = this.clientNameToIds.get(oldClientId)!.data;\n\t\t\t\tthis.longClientId = longClientId;\n\t\t\t\tthis.clientNameToIds.put(longClientId, oldData);\n\t\t\t\tthis.shortClientIdMap[oldData] = longClientId;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search. Makes use of block-accelerated search functions for log(n) complexity.\n\t *\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tsearchForMarker(startPos: number, markerLabel: string, forwards = true): Marker | undefined {\n\t\tconst clientId = this.getClientId();\n\t\treturn this._mergeTree.searchForMarker(startPos, clientId, markerLabel, forwards);\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,6DAA6D;AAE7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAEjE,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAKxF,OAAO,EACN,WAAW,GAEX,MAAM,6CAA6C,CAAC;AAErD,OAAO,EAAE,sBAAsB,EAAE,MAAM,wCAAwC,CAAC;AAEhF,OAAO,EAEN,YAAY,EACZ,UAAU,GACV,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAoB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AAC;YAC/C,CAAC;QACF,CAAC;IACF,CAAC;IAED;;;;;;;;OAQG;IACH,eAAe,CAAC,QAAgB,EAAE,WAAmB,EAAE,QAAQ,GAAG,IAAI;QACrE,MAAM,QAAQ,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;QACpC,OAAO,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,QAAQ,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,CAAC,CAAC;IACnF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { TypedEventEmitter } from \"@fluid-internal/client-utils\";\nimport { type IEventThisPlaceHolder, IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert, unreachableCase, isObject } from \"@fluidframework/core-utils/internal\";\nimport {\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport {\n\tMessageType,\n\tISequencedDocumentMessage,\n} from \"@fluidframework/driver-definitions/internal\";\nimport { ISummaryTreeWithStats } from \"@fluidframework/runtime-definitions/internal\";\nimport { toDeltaManagerInternal } from \"@fluidframework/runtime-utils/internal\";\nimport { IFluidSerializer } from \"@fluidframework/shared-object-base/internal\";\nimport {\n\tITelemetryLoggerExt,\n\tLoggingError,\n\tUsageError,\n} from \"@fluidframework/telemetry-utils/internal\";\n\nimport { MergeTreeTextHelper } from \"./MergeTreeTextHelper.js\";\nimport { DoublyLinkedList, RedBlackTree } from \"./collections/index.js\";\nimport {\n\tNonCollabClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\nimport { LocalReferencePosition, SlidingPreference } from \"./localReference.js\";\nimport {\n\tMergeTree,\n\terrorIfOptionNotTrue,\n\ttype IMergeTreeOptionsInternal,\n} from \"./mergeTree.js\";\nimport type {\n\tIMergeTreeClientSequenceArgs,\n\tIMergeTreeDeltaCallbackArgs,\n\tIMergeTreeDeltaOpArgs,\n\tIMergeTreeMaintenanceCallbackArgs,\n} from \"./mergeTreeDeltaCallback.js\";\nimport { walkAllChildSegments } from \"./mergeTreeNodeWalk.js\";\nimport {\n\tCollaborationWindow,\n\tISegment,\n\tISegmentAction,\n\tISegmentPrivate,\n\tMarker,\n\tSegmentGroup,\n\tcompareStrings,\n\tisSegmentLeaf,\n} from \"./mergeTreeNodes.js\";\nimport {\n\tcreateAdjustRangeOp,\n\tcreateAnnotateMarkerOp,\n\tcreateAnnotateRangeOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tcreateGroupOp,\n\tcreateInsertSegmentOp,\n\tcreateObliterateRangeOp,\n\tcreateObliterateRangeOpSided,\n\tcreateRemoveRangeOp,\n} from \"./opBuilder.js\";\nimport {\n\tIJSONSegment,\n\tIMergeTreeAnnotateMsg,\n\tIMergeTreeDeltaOp,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeGroupMsg,\n\tIMergeTreeInsertMsg,\n\t// eslint-disable-next-line import/no-deprecated\n\tIMergeTreeObliterateMsg,\n\tIMergeTreeOp,\n\tIMergeTreeRemoveMsg,\n\tIRelativePosition,\n\tMergeTreeDeltaType,\n\tReferenceType,\n\ttype AdjustParams,\n\ttype IMergeTreeAnnotateAdjustMsg,\n\ttype IMergeTreeObliterateSidedMsg,\n} from \"./ops.js\";\nimport { PropertySet, type MapLike } from \"./properties.js\";\nimport { DetachedReferencePosition, ReferencePosition } from \"./referencePositions.js\";\nimport {\n\tisInserted,\n\tisMoved,\n\tisRemoved,\n\toverwriteInfo,\n\ttoMoveInfo,\n\ttype IInsertionInfo,\n} from \"./segmentInfos.js\";\nimport { Side, type InteriorSequencePlace } from \"./sequencePlace.js\";\nimport { SnapshotLoader } from \"./snapshotLoader.js\";\nimport { SnapshotV1 } from \"./snapshotV1.js\";\nimport { SnapshotLegacy } from \"./snapshotlegacy.js\";\nimport { IMergeTreeTextHelper } from \"./textSegment.js\";\n\ntype IMergeTreeDeltaRemoteOpArgs = Omit<IMergeTreeDeltaOpArgs, \"sequencedMessage\"> &\n\tRequired<Pick<IMergeTreeDeltaOpArgs, \"sequencedMessage\">>;\n\n/**\n * A range [start, end)\n * @internal\n */\nexport interface IIntegerRange {\n\tstart: number;\n\tend: number;\n}\n\n/**\n * Emitted before this client's merge-tree normalizes its segments on reconnect, potentially\n * ordering them. Useful for DDS-like consumers built atop the merge-tree to compute any information\n * they need for rebasing their ops on reconnection.\n * @internal\n */\nexport interface IClientEvents {\n\t(event: \"normalize\", listener: (target: IEventThisPlaceHolder) => void): void;\n\t(\n\t\tevent: \"delta\",\n\t\tlistener: (\n\t\t\topArgs: IMergeTreeDeltaOpArgs,\n\t\t\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\t\t\ttarget: IEventThisPlaceHolder,\n\t\t) => void,\n\t): void;\n\t(\n\t\tevent: \"maintenance\",\n\t\tlistener: (\n\t\t\targs: IMergeTreeMaintenanceCallbackArgs,\n\t\t\tdeltaArgs: IMergeTreeDeltaOpArgs | undefined,\n\t\t\ttarget: IEventThisPlaceHolder,\n\t\t) => void,\n\t): void;\n}\n\nconst UNBOUND_SEGMENT_ERROR = \"The provided segment is not bound to this DDS.\";\n\n/**\n * This class encapsulates a merge-tree, and provides a local client specific view over it and\n * the capability to modify it as the local client. Additionally it provides\n * binding for processing remote ops on the encapsulated merge tree, and projects local and remote events\n * caused by all modification to the underlying merge-tree.\n *\n * @internal\n */\nexport class Client extends TypedEventEmitter<IClientEvents> {\n\tpublic longClientId: string | undefined;\n\n\tprivate readonly _mergeTree: MergeTree;\n\n\tprivate readonly clientNameToIds = new RedBlackTree<string, number>(compareStrings);\n\tprivate readonly shortClientIdMap: string[] = [];\n\n\t/**\n\t * @param specToSegment - Rehydrates a segment from its JSON representation\n\t * @param logger - Telemetry logger for diagnostics\n\t * @param options - Options for this client. See {@link IMergeTreeOptions} for details.\n\t * @param getMinInFlightRefSeq - Upon applying a message (see {@link Client.applyMsg}), client purges collab-window information which\n\t * is no longer necessary based on that message's minimum sequence number.\n\t * However, if the user of this client has in-flight messages which refer to positions in this Client,\n\t * they may wish to preserve additional merge information.\n\t * The effective minimum sequence number will be the minimum of the message's minimumSequenceNumber and the result of this function.\n\t * If this function returns undefined, the message's minimumSequenceNumber will be used.\n\t *\n\t * @privateRemarks\n\t * - Passing specToSegment would be unnecessary if Client were merged with SharedSegmentSequence\n\t * - AB#6866 tracks a more unified approach to collab window min seq handling.\n\t */\n\tconstructor(\n\t\tpublic readonly specToSegment: (spec: IJSONSegment) => ISegment,\n\t\tpublic readonly logger: ITelemetryLoggerExt,\n\t\toptions?: IMergeTreeOptionsInternal & PropertySet,\n\t\tprivate readonly getMinInFlightRefSeq: () => number | undefined = (): undefined =>\n\t\t\tundefined,\n\t) {\n\t\tsuper();\n\t\tthis._mergeTree = new MergeTree(options);\n\t\tthis._mergeTree.mergeTreeDeltaCallback = (opArgs, deltaArgs): void => {\n\t\t\tthis.emit(\"delta\", opArgs, deltaArgs, this);\n\t\t};\n\t\tthis._mergeTree.mergeTreeMaintenanceCallback = (args, opArgs): void => {\n\t\t\tthis.emit(\"maintenance\", args, opArgs, this);\n\t\t};\n\n\t\tif (options?.attribution?.track) {\n\t\t\tconst policy = this._mergeTree?.attributionPolicy;\n\t\t\tif (policy === undefined) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"Attribution policy must be provided when attribution tracking is requested.\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tpolicy.attach(this);\n\t\t}\n\t}\n\n\t/**\n\t * The merge tree maintains a queue of segment groups for each local operation.\n\t * These segment groups track segments modified by an operation.\n\t * This method peeks the tail of that queue, and returns the segments groups there.\n\t * It is used to get the segment group(s) for the previous operations.\n\t * @param count - The number segment groups to get peek from the tail of the queue. Default 1.\n\t */\n\n\tpublic peekPendingSegmentGroups(count: number = 1): unknown {\n\t\tconst pending = this._mergeTree.pendingSegments;\n\t\tlet node = pending?.last;\n\t\tif (count === 1 || pending === undefined) {\n\t\t\treturn node?.data;\n\t\t}\n\n\t\tconst taken: SegmentGroup[] = Array.from({ length: Math.min(count, pending.length) });\n\t\tfor (let i = taken.length - 1; i >= 0; i--) {\n\t\t\ttaken[i] = node!.data;\n\t\t\tnode = node!.prev;\n\t\t}\n\t\treturn taken;\n\t}\n\n\t/**\n\t * Annotates the markers with the provided properties\n\t * @param marker - The marker to annotate\n\t * @param props - The properties to annotate the marker with\n\t * @returns The annotate op if valid, otherwise undefined\n\t */\n\tpublic annotateMarker(\n\t\tmarker: Marker,\n\t\tprops: PropertySet,\n\t): IMergeTreeAnnotateMsg | undefined {\n\t\tconst annotateOp = createAnnotateMarkerOp(marker, props)!;\n\t\tthis.applyAnnotateRangeOp({ op: annotateOp });\n\t\treturn annotateOp;\n\t}\n\n\t/**\n\t * Annotates the range with the provided properties\n\t * @param start - The inclusive start position of the range to annotate\n\t * @param end - The exclusive end position of the range to annotate\n\t * @param props - The properties to annotate the range with\n\t * @returns The annotate op if valid, otherwise undefined\n\t */\n\tpublic annotateRangeLocal(\n\t\tstart: number,\n\t\tend: number,\n\t\tprops: PropertySet,\n\t): IMergeTreeAnnotateMsg | undefined {\n\t\tconst annotateOp = createAnnotateRangeOp(start, end, props);\n\t\tthis.applyAnnotateRangeOp({ op: annotateOp });\n\t\treturn annotateOp;\n\t}\n\n\t/**\n\t * adjusts a value\n\t */\n\tpublic annotateAdjustRangeLocal(\n\t\tstart: number,\n\t\tend: number,\n\t\tadjust: MapLike<AdjustParams>,\n\t): IMergeTreeAnnotateAdjustMsg {\n\t\tconst annotateOp = createAdjustRangeOp(start, end, adjust);\n\n\t\tfor (const [key, value] of Object.entries(adjust)) {\n\t\t\tif (value.min !== undefined && value.max !== undefined && value.min > value.max) {\n\t\t\t\tthrow new UsageError(`min is greater than max for ${key}`);\n\t\t\t}\n\t\t}\n\n\t\tthis.applyAnnotateRangeOp({ op: annotateOp });\n\t\treturn annotateOp;\n\t}\n\n\t/**\n\t * Removes the range\n\t *\n\t * @param start - The inclusive start of the range to remove\n\t * @param end - The exclusive end of the range to remove\n\t */\n\tpublic removeRangeLocal(start: number, end: number): IMergeTreeRemoveMsg {\n\t\tconst removeOp = createRemoveRangeOp(start, end);\n\t\tthis.applyRemoveRangeOp({ op: removeOp });\n\t\treturn removeOp;\n\t}\n\n\t/**\n\t * Obliterates the range. This is similar to removing the range, but also\n\t * includes any concurrently inserted content.\n\t *\n\t * @param start - The start of the range to obliterate. Inclusive is side is Before (default).\n\t * @param end - The end of the range to obliterate. Exclusive is side is After\n\t * (default is to be after the last included character, but number index is exclusive).\n\t */\n\tpublic obliterateRangeLocal(\n\t\tstart: number | InteriorSequencePlace,\n\t\tend: number | InteriorSequencePlace,\n\t\t// eslint-disable-next-line import/no-deprecated\n\t): IMergeTreeObliterateMsg | IMergeTreeObliterateSidedMsg {\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tlet obliterateOp: IMergeTreeObliterateMsg | IMergeTreeObliterateSidedMsg;\n\t\tif (this._mergeTree.options?.mergeTreeEnableSidedObliterate) {\n\t\t\tobliterateOp = createObliterateRangeOpSided(start, end);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\ttypeof start === \"number\" && typeof end === \"number\",\n\t\t\t\t0xa42 /* Start and end must be numbers if mergeTreeEnableSidedObliterate is not enabled. */,\n\t\t\t);\n\t\t\tobliterateOp = createObliterateRangeOp(start, end);\n\t\t}\n\t\tthis.applyObliterateRangeOp({ op: obliterateOp });\n\t\treturn obliterateOp;\n\t}\n\n\t/**\n\t * Create and insert a segment at the specified position.\n\t * @param pos - The position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertSegmentLocal(pos: number, segment: ISegment): IMergeTreeInsertMsg | undefined {\n\t\tif (segment.cachedLength <= 0) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst insertOp = createInsertSegmentOp(pos, segment);\n\t\tthis.applyInsertOp({ op: insertOp });\n\t\treturn insertOp;\n\t}\n\n\t/**\n\t * Create and insert a segment at the specified reference position.\n\t * @param refPos - The reference position to insert the segment at\n\t * @param segment - The segment to insert\n\t */\n\tpublic insertAtReferencePositionLocal(\n\t\trefPos: ReferencePosition,\n\t\tsegment: ISegment,\n\t): IMergeTreeInsertMsg | undefined {\n\t\tconst pos = this._mergeTree.referencePositionToLocalPosition(\n\t\t\trefPos,\n\t\t\tthis.getCurrentSeq(),\n\t\t\tthis.getClientId(),\n\t\t);\n\n\t\tif (pos === DetachedReferencePosition) {\n\t\t\tthrow new UsageError(\"Cannot insert at detached local reference.\");\n\t\t}\n\t\treturn this.insertSegmentLocal(pos, segment);\n\t}\n\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\taccum: TClientData,\n\t\tsplitRange?: boolean,\n\t): void;\n\tpublic walkSegments(\n\t\thandler: ISegmentAction<undefined>,\n\t\tstart?: number,\n\t\tend?: number,\n\t\taccum?: undefined,\n\t\tsplitRange?: boolean,\n\t): void;\n\tpublic walkSegments<TClientData>(\n\t\thandler: ISegmentAction<TClientData>,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\taccum: TClientData,\n\t\tsplitRange: boolean = false,\n\t): void {\n\t\tthis._mergeTree.mapRange(\n\t\t\thandler,\n\t\t\tthis.getCurrentSeq(),\n\t\t\tthis.getClientId(),\n\t\t\taccum,\n\t\t\tstart,\n\t\t\tend,\n\t\t\tsplitRange,\n\t\t);\n\t}\n\n\tprotected walkAllSegments<TClientData>(\n\t\taction: (segment: ISegment, accum?: TClientData) => boolean,\n\t\taccum?: TClientData,\n\t): boolean {\n\t\treturn walkAllChildSegments(\n\t\t\tthis._mergeTree.root,\n\t\t\taccum === undefined ? action : (seg): boolean => action(seg, accum),\n\t\t);\n\t}\n\n\t/**\n\t * Serializes the data required for garbage collection. The IFluidHandles stored in all segments that haven't\n\t * been removed represent routes to other objects. We serialize the data in these segments using the passed in\n\t * serializer which keeps track of all serialized handles.\n\t */\n\tpublic serializeGCData(\n\t\thandle: IFluidHandle,\n\t\thandleCollectingSerializer: IFluidSerializer,\n\t): void {\n\t\tlet localInserts = 0;\n\t\tlet localRemoves = 0;\n\t\twalkAllChildSegments(this._mergeTree.root, (seg: ISegmentPrivate) => {\n\t\t\tif (isInserted(seg) && seg.seq === UnassignedSequenceNumber) {\n\t\t\t\tlocalInserts++;\n\t\t\t}\n\t\t\tif (isRemoved(seg) && seg.removedSeq === UnassignedSequenceNumber) {\n\t\t\t\tlocalRemoves++;\n\t\t\t}\n\t\t\t// Only serialize segments that have not been removed.\n\t\t\tif (!isRemoved(seg)) {\n\t\t\t\thandleCollectingSerializer.stringify(seg.clone().toJSONObject(), handle);\n\t\t\t}\n\t\t\treturn true;\n\t\t});\n\n\t\tif (localInserts > 0 || localRemoves > 0) {\n\t\t\tthis.logger.sendErrorEvent({\n\t\t\t\teventName: \"LocalEditsInProcessGCData\",\n\t\t\t\tlocalInserts,\n\t\t\t\tlocalRemoves,\n\t\t\t});\n\t\t}\n\t}\n\n\tpublic getCollabWindow(): CollaborationWindow {\n\t\treturn this._mergeTree.collabWindow;\n\t}\n\n\t/**\n\t * Returns the current position of a segment, and -1 if the segment\n\t * does not exist in this merge tree\n\t * @param segment - The segment to get the position of\n\t */\n\tpublic getPosition(segment: ISegment | undefined, localSeq?: number): number {\n\t\tif (!isSegmentLeaf(segment)) {\n\t\t\treturn -1;\n\t\t}\n\t\treturn this._mergeTree.getPosition(\n\t\t\tsegment,\n\t\t\tthis.getCurrentSeq(),\n\t\t\tthis.getClientId(),\n\t\t\tlocalSeq,\n\t\t);\n\t}\n\n\t/**\n\t * Creates a `LocalReferencePosition` on this client. If the refType does not include ReferenceType.Transient,\n\t * the returned reference will be added to the localRefs on the provided segment.\n\t * @param segment - Segment to add the local reference on\n\t * @param offset - Offset on the segment at which to place the local reference\n\t * @param refType - ReferenceType for the created local reference\n\t * @param properties - PropertySet to place on the created local reference\n\t * @param canSlideToEndpoint - Whether or not the created local reference can\n\t * slide onto one of the special endpoint segments denoting the position\n\t * before the start of or after the end of the tree\n\t */\n\tpublic createLocalReferencePosition(\n\t\tsegment: ISegment | \"start\" | \"end\",\n\t\toffset: number | undefined,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\tif (!isSegmentLeaf(segment) && typeof segment !== \"string\") {\n\t\t\tthrow new UsageError(UNBOUND_SEGMENT_ERROR);\n\t\t}\n\t\treturn this._mergeTree.createLocalReferencePosition(\n\t\t\tsegment,\n\t\t\toffset ?? 0,\n\t\t\trefType,\n\t\t\tproperties,\n\t\t\tslidingPreference,\n\t\t\tcanSlideToEndpoint,\n\t\t);\n\t}\n\n\t/**\n\t * Removes a `LocalReferencePosition` from this client.\n\t */\n\tpublic removeLocalReferencePosition(\n\t\tlref: LocalReferencePosition,\n\t): LocalReferencePosition | undefined {\n\t\treturn this._mergeTree.removeLocalReferencePosition(lref);\n\t}\n\n\t/**\n\t * Resolves a `ReferencePosition` into a character position using this client's perspective.\n\t *\n\t * Reference positions that point to a character that has been removed will\n\t * always return the position of the nearest non-removed character, regardless\n\t * of {@link ReferenceType}. To handle this case specifically, one may wish\n\t * to look at the segment returned by {@link ReferencePosition.getSegment}.\n\t */\n\tpublic localReferencePositionToPosition(lref: ReferencePosition): number {\n\t\treturn this._mergeTree.referencePositionToLocalPosition(lref);\n\t}\n\n\t/**\n\t * Given a position specified relative to a marker id, lookup the marker\n\t * and convert the position to a character position.\n\t * @param relativePos - Id of marker (may be indirect) and whether position is before or after marker.\n\t */\n\tpublic posFromRelativePos(relativePos: IRelativePosition): number {\n\t\treturn this._mergeTree.posFromRelativePos(relativePos);\n\t}\n\n\tpublic getMarkerFromId(id: string): ISegment | undefined {\n\t\treturn this._mergeTree.getMarkerFromId(id);\n\t}\n\n\t/**\n\t * Revert an op\n\t */\n\tpublic rollback?(op: unknown, localOpMetadata: unknown): void {\n\t\tthis._mergeTree.rollback(op as IMergeTreeDeltaOp, localOpMetadata as SegmentGroup);\n\t}\n\n\tprivate applyObliterateRangeOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE ||\n\t\t\t\topArgs.op.type === MergeTreeDeltaType.OBLITERATE_SIDED,\n\t\t\t0x866 /* Unexpected op type on range obliterate! */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tif (this._mergeTree.options?.mergeTreeEnableSidedObliterate) {\n\t\t\tconst { start, end } = this.getValidSidedRange(op, clientArgs);\n\t\t\tthis._mergeTree.obliterateRange(\n\t\t\t\tstart,\n\t\t\t\tend,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t\tclientArgs.sequenceNumber,\n\t\t\t\topArgs,\n\t\t\t);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\top.type === MergeTreeDeltaType.OBLITERATE,\n\t\t\t\t0xa43 /* Unexpected sided obliterate while mergeTreeEnableSidedObliterate is disabled */,\n\t\t\t);\n\t\t\tconst range = this.getValidOpRange(op, clientArgs);\n\t\t\tthis._mergeTree.obliterateRange(\n\t\t\t\trange.start,\n\t\t\t\trange.end,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t\tclientArgs.sequenceNumber,\n\t\t\t\topArgs,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Performs the remove based on the provided op\n\t * @param opArgs - The ops args for the op\n\t */\n\tprivate applyRemoveRangeOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.REMOVE,\n\t\t\t0x02d /* \"Unexpected op type on range remove!\" */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tconst range = this.getValidOpRange(op, clientArgs);\n\n\t\tthis._mergeTree.markRangeRemoved(\n\t\t\trange.start,\n\t\t\trange.end,\n\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\tclientArgs.clientId,\n\t\t\tclientArgs.sequenceNumber,\n\t\t\topArgs,\n\t\t);\n\t}\n\n\t/**\n\t * Performs the annotate based on the provided op\n\t * @param opArgs - The ops args for the op\n\t */\n\tprivate applyAnnotateRangeOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.ANNOTATE,\n\t\t\t0x02e /* \"Unexpected op type on range annotate!\" */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tconst range = this.getValidOpRange(op, clientArgs);\n\n\t\tthis._mergeTree.annotateRange(\n\t\t\trange.start,\n\t\t\trange.end,\n\t\t\top,\n\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\tclientArgs.clientId,\n\t\t\tclientArgs.sequenceNumber,\n\t\t\topArgs,\n\t\t);\n\t}\n\n\t/**\n\t * Performs the insert based on the provided op\n\t * @param opArgs - The ops args for the op\n\t * @returns True if the insert was applied. False if it could not be.\n\t */\n\tprivate applyInsertOp(opArgs: IMergeTreeDeltaOpArgs): void {\n\t\tassert(\n\t\t\topArgs.op.type === MergeTreeDeltaType.INSERT,\n\t\t\t0x02f /* \"Unexpected op type on range insert!\" */,\n\t\t);\n\t\tconst op = opArgs.op;\n\t\tconst clientArgs = this.getClientSequenceArgs(opArgs);\n\t\tconst range = this.getValidOpRange(op, clientArgs);\n\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n\t\tconst segments = [this.specToSegment(op.seg)];\n\n\t\tthis._mergeTree.insertSegments(\n\t\t\trange.start,\n\t\t\tsegments,\n\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\tclientArgs.clientId,\n\t\t\tclientArgs.sequenceNumber,\n\t\t\topArgs,\n\t\t);\n\t}\n\n\t/**\n\t * Returns a valid range for the op, or throws if the range is invalid\n\t * @param op - The op to generate the range for\n\t * @param clientArgs - The client args for the op\n\t * @throws LoggingError if the range is invalid\n\t */\n\tprivate getValidSidedRange(\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\top: IMergeTreeObliterateSidedMsg | IMergeTreeObliterateMsg,\n\t\tclientArgs: IMergeTreeClientSequenceArgs,\n\t): {\n\t\tstart: InteriorSequencePlace;\n\t\tend: InteriorSequencePlace;\n\t} {\n\t\tconst invalidPositions: string[] = [];\n\t\tlet start: InteriorSequencePlace | undefined;\n\t\tlet end: InteriorSequencePlace | undefined;\n\t\tif (op.pos1 === undefined) {\n\t\t\tinvalidPositions.push(\"start\");\n\t\t} else {\n\t\t\tstart =\n\t\t\t\ttypeof op.pos1 === \"object\"\n\t\t\t\t\t? { pos: op.pos1.pos, side: op.pos1.before ? Side.Before : Side.After }\n\t\t\t\t\t: { pos: op.pos1, side: Side.Before };\n\t\t}\n\t\tif (op.pos2 === undefined) {\n\t\t\tinvalidPositions.push(\"end\");\n\t\t} else {\n\t\t\tend =\n\t\t\t\ttypeof op.pos2 === \"object\"\n\t\t\t\t\t? { pos: op.pos2.pos, side: op.pos2.before ? Side.Before : Side.After }\n\t\t\t\t\t: { pos: op.pos2 - 1, side: Side.After };\n\t\t}\n\n\t\t// Validate if local op\n\t\tif (clientArgs.clientId === this.getClientId()) {\n\t\t\tconst length = this._mergeTree.getLength(\n\t\t\t\tthis.getCollabWindow().currentSeq,\n\t\t\t\tthis.getClientId(),\n\t\t\t);\n\t\t\tif (start !== undefined && (start.pos >= length || start.pos < 0)) {\n\t\t\t\t// start out of bounds\n\t\t\t\tinvalidPositions.push(\"start\");\n\t\t\t}\n\t\t\tif (end !== undefined && (end.pos >= length || end.pos < 0)) {\n\t\t\t\tinvalidPositions.push(\"end\");\n\t\t\t}\n\t\t\tif (\n\t\t\t\tstart !== undefined &&\n\t\t\t\tend !== undefined &&\n\t\t\t\t(start.pos > end.pos ||\n\t\t\t\t\t(start.pos === end.pos && start.side !== end.side && start.side === Side.After))\n\t\t\t) {\n\t\t\t\t// end is before start\n\t\t\t\tinvalidPositions.push(\"inverted\");\n\t\t\t}\n\t\t\tif (invalidPositions.length > 0) {\n\t\t\t\tthrow new LoggingError(\"InvalidRange\", {\n\t\t\t\t\tusageError: true,\n\t\t\t\t\tinvalidPositions: invalidPositions.toString(),\n\t\t\t\t\tlength,\n\t\t\t\t\topType: op.type,\n\t\t\t\t\topPos1Relative: op.relativePos1 !== undefined,\n\t\t\t\t\topPos2Relative: op.relativePos2 !== undefined,\n\t\t\t\t\topPos1: JSON.stringify(op.pos1),\n\t\t\t\t\topPos2: JSON.stringify(op.pos2),\n\t\t\t\t\tstart: JSON.stringify(start),\n\t\t\t\t\tend: JSON.stringify(end),\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tassert(\n\t\t\tstart !== undefined && end !== undefined,\n\t\t\t0xa44 /* Missing start or end of range */,\n\t\t);\n\t\treturn { start, end };\n\t}\n\n\t/**\n\t * Returns a valid range for the op, or undefined\n\t * @param op - The op to generate the range for\n\t * @param clientArgs - The client args for the op\n\t */\n\tprivate getValidOpRange(\n\t\top:\n\t\t\t| IMergeTreeAnnotateMsg\n\t\t\t| IMergeTreeAnnotateAdjustMsg\n\t\t\t| IMergeTreeInsertMsg\n\t\t\t| IMergeTreeRemoveMsg\n\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t| IMergeTreeObliterateMsg,\n\t\tclientArgs: IMergeTreeClientSequenceArgs,\n\t): IIntegerRange {\n\t\tlet start: number | undefined = op.pos1;\n\t\tif (start === undefined && op.relativePos1) {\n\t\t\tstart = this._mergeTree.posFromRelativePos(\n\t\t\t\top.relativePos1,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t);\n\t\t}\n\n\t\tlet end: number | undefined = op.pos2;\n\t\tif (end === undefined && op.relativePos2) {\n\t\t\tend = this._mergeTree.posFromRelativePos(\n\t\t\t\top.relativePos2,\n\t\t\t\tclientArgs.referenceSequenceNumber,\n\t\t\t\tclientArgs.clientId,\n\t\t\t);\n\t\t}\n\n\t\t// Validate if local op\n\t\tif (clientArgs.clientId === this.getClientId()) {\n\t\t\tconst length = this.getLength();\n\n\t\t\tconst invalidPositions: string[] = [];\n\n\t\t\t// Validate start position\n\t\t\t//\n\t\t\tif (\n\t\t\t\tstart === undefined ||\n\t\t\t\tstart < 0 ||\n\t\t\t\tstart > length ||\n\t\t\t\t(start === length && op.type !== MergeTreeDeltaType.INSERT)\n\t\t\t) {\n\t\t\t\tinvalidPositions.push(\"start\");\n\t\t\t}\n\t\t\t// Validate end if not insert, or insert has end\n\t\t\tif (\n\t\t\t\t(op.type !== MergeTreeDeltaType.INSERT || end !== undefined) &&\n\t\t\t\t(end === undefined || end <= start!)\n\t\t\t) {\n\t\t\t\tinvalidPositions.push(\"end\");\n\t\t\t}\n\n\t\t\tif (op.type === MergeTreeDeltaType.OBLITERATE && end !== undefined && end > length) {\n\t\t\t\tinvalidPositions.push(\"end\");\n\t\t\t}\n\n\t\t\tif (invalidPositions.length > 0) {\n\t\t\t\tthrow new LoggingError(\"RangeOutOfBounds\", {\n\t\t\t\t\tusageError: true,\n\t\t\t\t\tend,\n\t\t\t\t\tinvalidPositions: invalidPositions.toString(),\n\t\t\t\t\tlength,\n\t\t\t\t\topPos1: op.pos1,\n\t\t\t\t\topPos1Relative: op.relativePos1 !== undefined,\n\t\t\t\t\topPos2: op.pos2,\n\t\t\t\t\topPos2Relative: op.relativePos2 !== undefined,\n\t\t\t\t\topType: op.type,\n\t\t\t\t\tstart,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\t// start and end are guaranteed to be non-null here, otherwise we throw above.\n\t\treturn { start: start!, end: end! };\n\t}\n\n\t/**\n\t * Gets the client args from the op if remote, otherwise uses the local clients info\n\t * @param sequencedMessage - The sequencedMessage to get the client sequence args for\n\t */\n\tprivate getClientSequenceArgsForMessage(\n\t\tsequencedMessage:\n\t\t\t| ISequencedDocumentMessage\n\t\t\t| Pick<ISequencedDocumentMessage, \"referenceSequenceNumber\" | \"clientId\">\n\t\t\t| undefined,\n\t): IMergeTreeClientSequenceArgs {\n\t\t// If there this no sequenced message, then the op is local\n\t\t// and unacked, so use this clients sequenced args\n\t\t//\n\t\tif (sequencedMessage) {\n\t\t\treturn {\n\t\t\t\tclientId: this.getOrAddShortClientIdFromMessage(sequencedMessage),\n\t\t\t\treferenceSequenceNumber: sequencedMessage.referenceSequenceNumber,\n\t\t\t\t// Note: return value satisfies overload signatures despite the cast, as if input argument doesn't contain sequenceNumber,\n\t\t\t\t// return value isn't expected to have it either.\n\t\t\t\tsequenceNumber: (sequencedMessage as ISequencedDocumentMessage).sequenceNumber,\n\t\t\t};\n\t\t} else {\n\t\t\tconst segWindow = this.getCollabWindow();\n\t\t\treturn {\n\t\t\t\tclientId: segWindow.clientId,\n\t\t\t\treferenceSequenceNumber: segWindow.currentSeq,\n\t\t\t\tsequenceNumber: this.getLocalSequenceNumber(),\n\t\t\t};\n\t\t}\n\t}\n\n\t/**\n\t * Gets the client args from the op if remote, otherwise uses the local clients info\n\t * @param opArgs - The op arg to get the client sequence args for\n\t */\n\tprivate getClientSequenceArgs(opArgs: IMergeTreeDeltaOpArgs): IMergeTreeClientSequenceArgs {\n\t\treturn this.getClientSequenceArgsForMessage(opArgs.sequencedMessage);\n\t}\n\n\tprivate ackPendingSegment(opArgs: IMergeTreeDeltaRemoteOpArgs): void {\n\t\tif (opArgs.op.type === MergeTreeDeltaType.GROUP) {\n\t\t\tfor (const memberOp of opArgs.op.ops) {\n\t\t\t\tthis._mergeTree.ackPendingSegment({\n\t\t\t\t\tgroupOp: opArgs.op,\n\t\t\t\t\top: memberOp,\n\t\t\t\t\tsequencedMessage: opArgs.sequencedMessage,\n\t\t\t\t});\n\t\t\t}\n\t\t} else {\n\t\t\tthis._mergeTree.ackPendingSegment(opArgs);\n\t\t}\n\t}\n\n\tgetOrAddShortClientId(longClientId: string): number {\n\t\tif (!this.clientNameToIds.get(longClientId)) {\n\t\t\tthis.addLongClientId(longClientId);\n\t\t}\n\t\treturn this.getShortClientId(longClientId);\n\t}\n\n\tprotected getShortClientId(longClientId: string): number {\n\t\treturn this.clientNameToIds.get(longClientId)!.data;\n\t}\n\n\tgetLongClientId(shortClientId: number): string {\n\t\treturn shortClientId >= 0 ? this.shortClientIdMap[shortClientId] : \"original\";\n\t}\n\n\taddLongClientId(longClientId: string): void {\n\t\tthis.clientNameToIds.put(longClientId, this.shortClientIdMap.length);\n\t\tthis.shortClientIdMap.push(longClientId);\n\t}\n\n\tprivate getOrAddShortClientIdFromMessage(\n\t\tmsg: Pick<ISequencedDocumentMessage, \"clientId\">,\n\t): number {\n\t\treturn this.getOrAddShortClientId(msg.clientId ?? \"server\");\n\t}\n\n\t/**\n\t * During reconnect, we must find the positions to pending segments\n\t * relative to other pending segments. This methods computes that\n\t * position relative to a localSeq. Pending segments above the localSeq\n\t * will be ignored.\n\t *\n\t * @param segment - The segment to find the position for\n\t * @param localSeq - The localSeq to find the position of the segment at\n\t */\n\tpublic findReconnectionPosition(segment: ISegment, localSeq: number): number {\n\t\tassert(\n\t\t\tlocalSeq <= this._mergeTree.collabWindow.localSeq,\n\t\t\t0x032 /* \"localSeq greater than collab window\" */,\n\t\t);\n\t\tconst { currentSeq, clientId } = this.getCollabWindow();\n\t\tif (!isSegmentLeaf(segment)) {\n\t\t\tthrow new UsageError(UNBOUND_SEGMENT_ERROR);\n\t\t}\n\t\treturn this._mergeTree.getPosition(segment, currentSeq, clientId, localSeq);\n\t}\n\n\tprivate resetPendingDeltaToOps(\n\t\tresetOp: IMergeTreeDeltaOp,\n\n\t\tsegmentGroup: SegmentGroup,\n\t): IMergeTreeDeltaOp[] {\n\t\tassert(!!segmentGroup, 0x033 /* \"Segment group undefined\" */);\n\t\tconst NACKedSegmentGroup = this.pendingRebase?.shift()?.data;\n\t\tassert(\n\t\t\tsegmentGroup === NACKedSegmentGroup,\n\t\t\t0x034 /* \"Segment group not at head of pending rebase queue\" */,\n\t\t);\n\t\tif (this.pendingRebase?.empty) {\n\t\t\tthis.pendingRebase = undefined;\n\t\t}\n\n\t\t// if this is an obliterate op, keep all segments in same segment group\n\n\t\tconst obliterateSegmentGroup: SegmentGroup = {\n\t\t\tsegments: [],\n\t\t\tlocalSeq: segmentGroup.localSeq,\n\t\t\trefSeq: this.getCollabWindow().currentSeq,\n\t\t\tobliterateInfo: {\n\t\t\t\t...segmentGroup.obliterateInfo!,\n\t\t\t},\n\t\t};\n\n\t\tconst opList: IMergeTreeDeltaOp[] = [];\n\t\t// We need to sort the segments by ordinal, as the segments are not sorted in the segment group.\n\t\t// The reason they need them sorted, as they have the same local sequence number and which means\n\t\t// farther segments will take into account nearer segments when calculating their position.\n\t\t// By sorting we ensure the nearer segment will be applied and sequenced before the farther segments\n\t\t// so their recalculated positions will be correct.\n\t\tfor (const segment of segmentGroup.segments.sort((a, b) =>\n\t\t\ta.ordinal < b.ordinal ? -1 : 1,\n\t\t)) {\n\t\t\tassert(\n\t\t\t\tsegment.segmentGroups?.remove(segmentGroup) === true,\n\t\t\t\t0x035 /* \"Segment group not in segment pending queue\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tsegmentGroup.localSeq !== undefined,\n\t\t\t\t0x867 /* expected segment group localSeq to be defined */,\n\t\t\t);\n\t\t\tconst segmentPosition = this.findReconnectionPosition(segment, segmentGroup.localSeq);\n\t\t\tlet newOp: IMergeTreeDeltaOp | undefined;\n\t\t\tswitch (resetOp.type) {\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tsegment.propertyManager?.hasPendingProperties(resetOp.props ?? resetOp.adjust) ===\n\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t0x036 /* \"Segment has no pending properties\" */,\n\t\t\t\t\t);\n\t\t\t\t\t// if the segment has been removed or obliterated, there's no need to send the annotate op\n\t\t\t\t\t// unless the remove was local, in which case the annotate must have come\n\t\t\t\t\t// before the remove\n\t\t\t\t\tif (\n\t\t\t\t\t\t(!isRemoved(segment) ||\n\t\t\t\t\t\t\t(segment.localRemovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber)) &&\n\t\t\t\t\t\t(!isMoved(segment) ||\n\t\t\t\t\t\t\t(segment.localMovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.movedSeq === UnassignedSequenceNumber))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewOp =\n\t\t\t\t\t\t\tresetOp.props === undefined\n\t\t\t\t\t\t\t\t? createAdjustRangeOp(\n\t\t\t\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t\t\t\t\tresetOp.adjust,\n\t\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t\t: createAnnotateRangeOp(\n\t\t\t\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t\t\t\t\tresetOp.props,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t\tassert(\n\t\t\t\t\t\tisInserted(segment) && segment.seq === UnassignedSequenceNumber,\n\t\t\t\t\t\t0x037 /* \"Segment already has assigned sequence number\" */,\n\t\t\t\t\t);\n\t\t\t\t\tconst moveInfo = toMoveInfo(segment);\n\n\t\t\t\t\tif (moveInfo !== undefined) {\n\t\t\t\t\t\terrorIfOptionNotTrue(\n\t\t\t\t\t\t\tthis._mergeTree.options,\n\t\t\t\t\t\t\t\"mergeTreeEnableObliterateReconnect\",\n\t\t\t\t\t\t);\n\t\t\t\t\t\tif (moveInfo.movedSeq !== UnassignedSequenceNumber) {\n\t\t\t\t\t\t\t// the segment was remotely obliterated, so is considered removed\n\t\t\t\t\t\t\t// we set the seq to the universal seq and remove the local seq,\n\t\t\t\t\t\t\t// so its length is not considered for subsequent local changes\n\t\t\t\t\t\t\t// this allows us to not send the op as even the local client will ignore the segment\n\t\t\t\t\t\t\toverwriteInfo<IInsertionInfo>(segment, {\n\t\t\t\t\t\t\t\tseq: UniversalSequenceNumber,\n\t\t\t\t\t\t\t\tlocalSeq: undefined,\n\t\t\t\t\t\t\t\tclientId: NonCollabClient,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tconst segInsertOp: ISegment = segment.clone();\n\t\t\t\t\tconst opProps =\n\t\t\t\t\t\tisObject(resetOp.seg) && \"props\" in resetOp.seg && isObject(resetOp.seg.props)\n\t\t\t\t\t\t\t? { ...resetOp.seg.props }\n\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\tsegInsertOp.properties = opProps;\n\t\t\t\t\tnewOp = createInsertSegmentOp(segmentPosition, segInsertOp);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tif (\n\t\t\t\t\t\tisRemoved(segment) &&\n\t\t\t\t\t\tsegment.localRemovedSeq !== undefined &&\n\t\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber &&\n\t\t\t\t\t\t(!isMoved(segment) ||\n\t\t\t\t\t\t\t(segment.localMovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.movedSeq === UnassignedSequenceNumber))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewOp = createRemoveRangeOp(\n\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\terrorIfOptionNotTrue(this._mergeTree.options, \"mergeTreeEnableObliterateReconnect\");\n\t\t\t\t\tif (\n\t\t\t\t\t\tisMoved(segment) &&\n\t\t\t\t\t\tsegment.localMovedSeq !== undefined &&\n\t\t\t\t\t\tsegment.movedSeq === UnassignedSequenceNumber &&\n\t\t\t\t\t\t(!isRemoved(segment) ||\n\t\t\t\t\t\t\t(segment.localRemovedSeq !== undefined &&\n\t\t\t\t\t\t\t\tsegment.removedSeq === UnassignedSequenceNumber))\n\t\t\t\t\t) {\n\t\t\t\t\t\tnewOp = createObliterateRangeOp(\n\t\t\t\t\t\t\tsegmentPosition,\n\t\t\t\t\t\t\tsegmentPosition + segment.cachedLength,\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tthrow new Error(`Invalid op type`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (newOp && resetOp.type === MergeTreeDeltaType.OBLITERATE) {\n\t\t\t\tsegment.segmentGroups.enqueue(obliterateSegmentGroup);\n\n\t\t\t\tconst first = opList[0];\n\n\t\t\t\tif (\n\t\t\t\t\t!!first &&\n\t\t\t\t\tfirst.pos2 !== undefined &&\n\t\t\t\t\tfirst.type !== MergeTreeDeltaType.OBLITERATE_SIDED &&\n\t\t\t\t\tnewOp.type !== MergeTreeDeltaType.OBLITERATE_SIDED\n\t\t\t\t) {\n\t\t\t\t\tfirst.pos2 += newOp.pos2! - newOp.pos1!;\n\t\t\t\t} else {\n\t\t\t\t\topList.push(newOp);\n\t\t\t\t}\n\t\t\t} else if (newOp) {\n\t\t\t\tconst newSegmentGroup: SegmentGroup = {\n\t\t\t\t\tsegments: [],\n\t\t\t\t\tlocalSeq: segmentGroup.localSeq,\n\t\t\t\t\trefSeq: this.getCollabWindow().currentSeq,\n\t\t\t\t};\n\t\t\t\tsegment.segmentGroups.enqueue(newSegmentGroup);\n\n\t\t\t\tthis._mergeTree.pendingSegments.push(newSegmentGroup);\n\n\t\t\t\topList.push(newOp);\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tresetOp.type === MergeTreeDeltaType.OBLITERATE &&\n\t\t\tobliterateSegmentGroup.segments.length > 0\n\t\t) {\n\t\t\tthis._mergeTree.pendingSegments.push(obliterateSegmentGroup);\n\t\t}\n\n\t\treturn opList;\n\t}\n\n\tprivate applyRemoteOp(opArgs: IMergeTreeDeltaRemoteOpArgs): void {\n\t\tconst op = opArgs.op;\n\t\tconst msg = opArgs.sequencedMessage;\n\t\tthis.getOrAddShortClientIdFromMessage(msg);\n\t\tswitch (op.type) {\n\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\tthis.applyInsertOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\tthis.applyRemoveRangeOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\tthis.applyAnnotateRangeOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.OBLITERATE:\n\t\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED: {\n\t\t\t\tthis.applyObliterateRangeOp(opArgs);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.GROUP: {\n\t\t\t\tfor (const memberOp of op.ops) {\n\t\t\t\t\tthis.applyRemoteOp({\n\t\t\t\t\t\top: memberOp,\n\t\t\t\t\t\tgroupOp: op,\n\t\t\t\t\t\tsequencedMessage: msg,\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyStashedOp(op: IMergeTreeOp): void {\n\t\tswitch (op.type) {\n\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\tthis.applyInsertOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\tthis.applyRemoveRangeOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\tthis.applyAnnotateRangeOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED:\n\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\tthis.applyObliterateRangeOp({ op });\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tcase MergeTreeDeltaType.GROUP: {\n\t\t\t\top.ops.map((o) => this.applyStashedOp(o));\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(op, \"unrecognized op type\");\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic applyMsg(msg: ISequencedDocumentMessage, local: boolean = false): void {\n\t\t// Ensure client ID is registered\n\t\tthis.getOrAddShortClientIdFromMessage(msg);\n\t\t// Apply if an operation message\n\t\tif (msg.type === MessageType.Operation) {\n\t\t\tconst opArgs: IMergeTreeDeltaRemoteOpArgs = {\n\t\t\t\top: msg.contents as IMergeTreeOp,\n\t\t\t\tsequencedMessage: msg,\n\t\t\t};\n\t\t\tif (opArgs.sequencedMessage?.clientId === this.longClientId || local) {\n\t\t\t\tthis.ackPendingSegment(opArgs);\n\t\t\t} else {\n\t\t\t\tthis.applyRemoteOp(opArgs);\n\t\t\t}\n\t\t}\n\n\t\tconst min = Math.min(\n\t\t\tthis.getMinInFlightRefSeq() ?? Number.POSITIVE_INFINITY,\n\t\t\tmsg.minimumSequenceNumber,\n\t\t);\n\t\tthis.updateSeqNumbers(min, msg.sequenceNumber);\n\t}\n\n\tprivate updateSeqNumbers(min: number, seq: number): void {\n\t\tconst collabWindow = this.getCollabWindow();\n\t\t// Equal is fine here due to SharedSegmentSequence<>.snapshotContent() potentially updating with same #\n\t\tassert(\n\t\t\tcollabWindow.currentSeq <= seq,\n\t\t\t0x038 /* \"Incoming op sequence# < local collabWindow's currentSequence#\" */,\n\t\t);\n\t\tcollabWindow.currentSeq = seq;\n\t\tassert(min <= seq, 0x039 /* \"Incoming op sequence# < minSequence#\" */);\n\t\tthis.updateMinSeq(min);\n\t}\n\n\t/**\n\t * Resolves a remote client's position against the local sequence\n\t * and returns the remote client's position relative to the local\n\t * sequence\n\t * @param remoteClientPosition - The remote client's position to resolve\n\t * @param remoteClientRefSeq - The reference sequence number of the remote client\n\t * @param remoteClientId - The client id of the remote client\n\t */\n\tpublic resolveRemoteClientPosition(\n\t\tremoteClientPosition: number,\n\t\tremoteClientRefSeq: number,\n\t\tremoteClientId: string,\n\t): number | undefined {\n\t\tconst shortRemoteClientId = this.getOrAddShortClientId(remoteClientId);\n\t\treturn this._mergeTree.resolveRemoteClientPosition(\n\t\t\tremoteClientPosition,\n\t\t\tremoteClientRefSeq,\n\t\t\tshortRemoteClientId,\n\t\t);\n\t}\n\n\tprivate lastNormalizationRefSeq = 0;\n\n\tprivate pendingRebase: DoublyLinkedList<SegmentGroup> | undefined;\n\n\t/**\n\t * Given a pending operation and segment group, regenerate the op, so it\n\t * can be resubmitted\n\t * @param resetOp - The op to reset\n\t * @param segmentGroup - The segment group associated with the op\n\t */\n\tpublic regeneratePendingOp(resetOp: IMergeTreeOp, localOpMetadata: unknown): IMergeTreeOp {\n\t\tconst segmentGroup = localOpMetadata as SegmentGroup | SegmentGroup[];\n\t\tif (this.pendingRebase === undefined || this.pendingRebase.empty) {\n\t\t\tlet firstGroup: SegmentGroup;\n\t\t\tif (Array.isArray(segmentGroup)) {\n\t\t\t\tif (segmentGroup.length === 0) {\n\t\t\t\t\t// sometimes we rebase to an empty op\n\t\t\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\t\t\treturn createGroupOp();\n\t\t\t\t}\n\t\t\t\tfirstGroup = segmentGroup[0];\n\t\t\t} else {\n\t\t\t\tfirstGroup = segmentGroup;\n\t\t\t}\n\t\t\tconst firstGroupNode = this._mergeTree.pendingSegments.find(\n\t\t\t\t(node) => node.data === firstGroup,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\tfirstGroupNode !== undefined,\n\t\t\t\t0x70e /* segment group must exist in pending list */,\n\t\t\t);\n\t\t\tthis.pendingRebase = this._mergeTree.pendingSegments.splice(firstGroupNode);\n\t\t}\n\n\t\tconst rebaseTo = this.getCollabWindow().currentSeq;\n\t\tif (rebaseTo !== this.lastNormalizationRefSeq) {\n\t\t\tthis.emit(\"normalize\", this);\n\t\t\tthis._mergeTree.normalizeSegmentsOnRebase();\n\t\t\tthis.lastNormalizationRefSeq = rebaseTo;\n\t\t}\n\n\t\tconst opList: IMergeTreeDeltaOp[] = [];\n\t\tif (resetOp.type === MergeTreeDeltaType.GROUP) {\n\t\t\tif (Array.isArray(segmentGroup)) {\n\t\t\t\tassert(\n\t\t\t\t\tresetOp.ops.length === segmentGroup.length,\n\t\t\t\t\t0x03a /* \"Number of ops in 'resetOp' must match the number of segment groups provided.\" */,\n\t\t\t\t);\n\n\t\t\t\tfor (let i = 0; i < resetOp.ops.length; i++) {\n\t\t\t\t\topList.push(...this.resetPendingDeltaToOps(resetOp.ops[i], segmentGroup[i]));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// A group op containing a single op will pass a direct reference to 'segmentGroup'\n\t\t\t\t// rather than an array of segment groups. (See 'peekPendingSegmentGroups()')\n\t\t\t\tassert(\n\t\t\t\t\tresetOp.ops.length === 1,\n\t\t\t\t\t0x03b /* \"Number of ops in 'resetOp' must match the number of segment groups provided.\" */,\n\t\t\t\t);\n\t\t\t\topList.push(...this.resetPendingDeltaToOps(resetOp.ops[0], segmentGroup));\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\t(resetOp.type as unknown) !== MergeTreeDeltaType.GROUP,\n\t\t\t\t0x03c /* \"Reset op has 'group' delta type!\" */,\n\t\t\t);\n\t\t\tassert(\n\t\t\t\t!Array.isArray(segmentGroup),\n\t\t\t\t0x03d /* \"segmentGroup is array rather than singleton!\" */,\n\t\t\t);\n\t\t\topList.push(...this.resetPendingDeltaToOps(resetOp, segmentGroup));\n\t\t}\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\treturn opList.length === 1 ? opList[0] : createGroupOp(...opList);\n\t}\n\n\tpublic createTextHelper(): IMergeTreeTextHelper {\n\t\treturn new MergeTreeTextHelper(this._mergeTree);\n\t}\n\n\tpublic summarize(\n\t\truntime: IFluidDataStoreRuntime,\n\t\thandle: IFluidHandle,\n\t\tserializer: IFluidSerializer,\n\t\tcatchUpMsgs: ISequencedDocumentMessage[],\n\t): ISummaryTreeWithStats {\n\t\tconst deltaManager = toDeltaManagerInternal(runtime.deltaManager);\n\t\tconst minSeq = deltaManager.minimumSequenceNumber;\n\n\t\t// Catch up to latest MSN, if we have not had a chance to do it.\n\t\t// Required for case where FluidDataStoreRuntime.attachChannel()\n\t\t// generates summary right after loading data store.\n\n\t\tthis.updateSeqNumbers(minSeq, deltaManager.lastSequenceNumber);\n\n\t\t// One of the summaries (from SPO) I observed to have chunk.chunkSequenceNumber > minSeq!\n\t\t// Not sure why - need to catch it sooner\n\t\tassert(\n\t\t\tthis.getCollabWindow().minSeq === minSeq,\n\t\t\t0x03e /* \"minSeq mismatch between collab window and delta manager!\" */,\n\t\t);\n\n\t\t// Must continue to support legacy\n\t\t// (See https://github.com/microsoft/FluidFramework/issues/84)\n\t\tif (this._mergeTree.options?.newMergeTreeSnapshotFormat === true) {\n\t\t\tassert(\n\t\t\t\tcatchUpMsgs === undefined || catchUpMsgs.length === 0,\n\t\t\t\t0x03f /* \"New format should not emit catchup ops\" */,\n\t\t\t);\n\t\t\tconst snap = new SnapshotV1(this._mergeTree, this.logger, (id) =>\n\t\t\t\tthis.getLongClientId(id),\n\t\t\t);\n\t\t\tsnap.extractSync();\n\t\t\treturn snap.emit(serializer, handle);\n\t\t} else {\n\t\t\tconst snap = new SnapshotLegacy(this._mergeTree, this.logger);\n\t\t\tsnap.extractSync();\n\t\t\treturn snap.emit(catchUpMsgs, serializer, handle);\n\t\t}\n\t}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tstorage: IChannelStorageService,\n\t\tserializer: IFluidSerializer,\n\t): Promise<{ catchupOpsP: Promise<ISequencedDocumentMessage[]> }> {\n\t\tconst loader = new SnapshotLoader(runtime, this, this._mergeTree, this.logger, serializer);\n\n\t\treturn loader.initialize(storage);\n\t}\n\n\tprivate getLocalSequenceNumber(): number {\n\t\tconst segWindow = this.getCollabWindow();\n\t\treturn segWindow.collaborating ? UnassignedSequenceNumber : UniversalSequenceNumber;\n\t}\n\n\t// eslint-disable-next-line import/no-deprecated\n\tlocalTransaction(groupOp: IMergeTreeGroupMsg): void {\n\t\tfor (const op of groupOp.ops) {\n\t\t\tconst opArgs: IMergeTreeDeltaOpArgs = {\n\t\t\t\top,\n\t\t\t\tgroupOp,\n\t\t\t};\n\t\t\tswitch (op.type) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t\tthis.applyInsertOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\tthis.applyAnnotateRangeOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\tthis.applyRemoveRangeOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE_SIDED:\n\t\t\t\tcase MergeTreeDeltaType.OBLITERATE: {\n\t\t\t\t\tthis.applyObliterateRangeOp(opArgs);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tupdateMinSeq(minSeq: number): void {\n\t\tthis._mergeTree.setMinSeq(minSeq);\n\t}\n\n\tgetContainingSegment<T extends ISegment>(\n\t\tpos: number,\n\t\tsequenceArgs?: Pick<ISequencedDocumentMessage, \"referenceSequenceNumber\" | \"clientId\">,\n\t\tlocalSeq?: number,\n\t): {\n\t\tsegment: T | undefined;\n\t\toffset: number | undefined;\n\t} {\n\t\tconst { referenceSequenceNumber, clientId } =\n\t\t\tthis.getClientSequenceArgsForMessage(sequenceArgs);\n\t\treturn this._mergeTree.getContainingSegment(\n\t\t\tpos,\n\t\t\treferenceSequenceNumber,\n\t\t\tclientId,\n\t\t\tlocalSeq,\n\t\t) as {\n\t\t\tsegment: T | undefined;\n\t\t\toffset: number | undefined;\n\t\t};\n\t}\n\n\tgetPropertiesAtPosition(pos: number): PropertySet | undefined {\n\t\tlet propertiesAtPosition: PropertySet | undefined;\n\t\tconst segoff = this.getContainingSegment(pos);\n\t\tconst seg = segoff.segment;\n\t\tif (seg) {\n\t\t\tpropertiesAtPosition = seg.properties;\n\t\t}\n\t\treturn propertiesAtPosition;\n\t}\n\n\tgetRangeExtentsOfPosition(pos: number): {\n\t\tposStart: number | undefined;\n\t\tposAfterEnd: number | undefined;\n\t} {\n\t\tlet posStart: number | undefined;\n\t\tlet posAfterEnd: number | undefined;\n\n\t\tconst segoff = this.getContainingSegment(pos);\n\t\tconst seg = segoff.segment;\n\t\tif (seg) {\n\t\t\tposStart = this.getPosition(seg);\n\t\t\tposAfterEnd = posStart + seg.cachedLength;\n\t\t}\n\t\treturn { posStart, posAfterEnd };\n\t}\n\n\tgetCurrentSeq(): number {\n\t\treturn this.getCollabWindow().currentSeq;\n\t}\n\n\tgetClientId(): number {\n\t\treturn this.getCollabWindow().clientId;\n\t}\n\n\tgetLength(): number {\n\t\treturn this._mergeTree.length ?? 0;\n\t}\n\n\tstartOrUpdateCollaboration(\n\t\tlongClientId: string | undefined,\n\t\tminSeq = 0,\n\t\tcurrentSeq = 0,\n\t): void {\n\t\t// we should always have a client id if we are collaborating\n\t\t// if the client id is undefined we are likely bound to a detached\n\t\t// container, so we should keep going in local mode. once\n\t\t// the container attaches this will be called again on connect with the\n\t\t// client id\n\t\tif (longClientId !== undefined) {\n\t\t\tif (this.longClientId === undefined) {\n\t\t\t\tthis.longClientId = longClientId;\n\t\t\t\tthis.addLongClientId(this.longClientId);\n\t\t\t\tthis._mergeTree.startCollaboration(\n\t\t\t\t\tthis.getShortClientId(this.longClientId),\n\t\t\t\t\tminSeq,\n\t\t\t\t\tcurrentSeq,\n\t\t\t\t);\n\t\t\t} else {\n\t\t\t\tconst oldClientId = this.longClientId;\n\t\t\t\tconst oldData = this.clientNameToIds.get(oldClientId)!.data;\n\t\t\t\tthis.longClientId = longClientId;\n\t\t\t\tthis.clientNameToIds.put(longClientId, oldData);\n\t\t\t\tthis.shortClientIdMap[oldData] = longClientId;\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Searches a string for the nearest marker in either direction to a given start position.\n\t * The search will include the start position, so markers at the start position are valid\n\t * results of the search. Makes use of block-accelerated search functions for log(n) complexity.\n\t *\n\t * @param startPos - Position at which to start the search\n\t * @param markerLabel - Label of the marker to search for\n\t * @param forwards - Whether the desired marker comes before (false) or after (true) `startPos`\n\t */\n\tsearchForMarker(startPos: number, markerLabel: string, forwards = true): Marker | undefined {\n\t\tconst clientId = this.getClientId();\n\t\treturn this._mergeTree.searchForMarker(startPos, clientId, markerLabel, forwards);\n\t}\n}\n"]}
|