@fluidframework/merge-tree 2.0.0-dev.7.4.0.216897 → 2.0.0-dev.7.4.0.217884
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/api-report/merge-tree.api.md +0 -3
- package/dist/merge-tree-alpha.d.ts +8 -16
- package/dist/merge-tree-untrimmed.d.ts +75 -2
- package/dist/mergeTreeNodes.d.ts +75 -2
- package/dist/mergeTreeNodes.d.ts.map +1 -1
- package/dist/mergeTreeNodes.js +69 -3
- package/dist/mergeTreeNodes.js.map +1 -1
- package/lib/merge-tree-alpha.d.ts +8 -16
- package/lib/merge-tree-untrimmed.d.ts +75 -2
- package/lib/mergeTreeNodes.d.ts +75 -2
- package/lib/mergeTreeNodes.d.ts.map +1 -1
- package/lib/mergeTreeNodes.js +69 -3
- package/lib/mergeTreeNodes.js.map +1 -1
- package/package.json +15 -15
- package/src/mergeTreeNodes.ts +76 -5
|
@@ -196,13 +196,10 @@ export class CollaborationWindow {
|
|
|
196
196
|
clientId: number;
|
|
197
197
|
// (undocumented)
|
|
198
198
|
collaborating: boolean;
|
|
199
|
-
// (undocumented)
|
|
200
199
|
currentSeq: number;
|
|
201
200
|
// (undocumented)
|
|
202
201
|
loadFrom(a: CollaborationWindow): void;
|
|
203
|
-
// (undocumented)
|
|
204
202
|
localSeq: number;
|
|
205
|
-
// (undocumented)
|
|
206
203
|
minSeq: number;
|
|
207
204
|
}
|
|
208
205
|
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
+
import { IChannelStorageService } from '@fluidframework/datastore-definitions';
|
|
2
|
+
import { IEventThisPlaceHolder } from '@fluidframework/core-interfaces';
|
|
3
|
+
import { IFluidDataStoreRuntime } from '@fluidframework/datastore-definitions';
|
|
4
|
+
import { IFluidHandle } from '@fluidframework/core-interfaces';
|
|
5
|
+
import { IFluidSerializer } from '@fluidframework/shared-object-base';
|
|
1
6
|
import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions';
|
|
7
|
+
import { ISummaryTreeWithStats } from '@fluidframework/runtime-definitions';
|
|
8
|
+
import { ITelemetryLoggerExt } from '@fluidframework/telemetry-utils';
|
|
9
|
+
import { TypedEventEmitter } from '@fluid-internal/client-utils';
|
|
2
10
|
|
|
3
11
|
/* Excluded from this release type: addProperties */
|
|
4
12
|
|
|
@@ -64,8 +72,6 @@ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions'
|
|
|
64
72
|
|
|
65
73
|
/* Excluded from this release type: IAttributionCollectionSpec */
|
|
66
74
|
|
|
67
|
-
/* Excluded from this release type: IChannelStorageService */
|
|
68
|
-
|
|
69
75
|
/* Excluded from this release type: IClientEvents */
|
|
70
76
|
|
|
71
77
|
/* Excluded from this release type: ICombiningOp */
|
|
@@ -74,14 +80,6 @@ import { ISequencedDocumentMessage } from '@fluidframework/protocol-definitions'
|
|
|
74
80
|
|
|
75
81
|
/* Excluded from this release type: IConsensusValue */
|
|
76
82
|
|
|
77
|
-
/* Excluded from this release type: IEventThisPlaceHolder */
|
|
78
|
-
|
|
79
|
-
/* Excluded from this release type: IFluidDataStoreRuntime */
|
|
80
|
-
|
|
81
|
-
/* Excluded from this release type: IFluidHandle */
|
|
82
|
-
|
|
83
|
-
/* Excluded from this release type: IFluidSerializer */
|
|
84
|
-
|
|
85
83
|
/* Excluded from this release type: IIntegerRange */
|
|
86
84
|
|
|
87
85
|
/* Excluded from this release type: IJSONMarkerSegment */
|
|
@@ -148,10 +146,6 @@ declare interface IRefsAtOffset {
|
|
|
148
146
|
|
|
149
147
|
/* Excluded from this release type: isMergeTreeDeltaRevertible */
|
|
150
148
|
|
|
151
|
-
/* Excluded from this release type: ISummaryTreeWithStats */
|
|
152
|
-
|
|
153
|
-
/* Excluded from this release type: ITelemetryLoggerExt */
|
|
154
|
-
|
|
155
149
|
/* Excluded from this release type: ITrackingGroup */
|
|
156
150
|
|
|
157
151
|
/* Excluded from this release type: KeyComparer */
|
|
@@ -312,8 +306,6 @@ declare interface ListNodeRange<T> {
|
|
|
312
306
|
|
|
313
307
|
/* Excluded from this release type: TreeMaintenanceSequenceNumber */
|
|
314
308
|
|
|
315
|
-
/* Excluded from this release type: TypedEventEmitter */
|
|
316
|
-
|
|
317
309
|
/* Excluded from this release type: UnassignedSequenceNumber */
|
|
318
310
|
|
|
319
311
|
/* Excluded from this release type: UniversalSequenceNumber */
|
|
@@ -333,8 +333,77 @@ export declare function clone<T>(extension: MapLike<T> | undefined): MapLike<T>
|
|
|
333
333
|
export declare class CollaborationWindow {
|
|
334
334
|
clientId: number;
|
|
335
335
|
collaborating: boolean;
|
|
336
|
+
/**
|
|
337
|
+
* Lowest-numbered segment in window; no client can reference a state before this one
|
|
338
|
+
*/
|
|
336
339
|
minSeq: number;
|
|
340
|
+
/**
|
|
341
|
+
* Highest-numbered segment in window and current reference sequence number for this client.
|
|
342
|
+
*/
|
|
337
343
|
currentSeq: number;
|
|
344
|
+
/**
|
|
345
|
+
* Highest-numbered localSeq used for a pending segment.
|
|
346
|
+
* Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
|
|
347
|
+
* for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
|
|
348
|
+
*
|
|
349
|
+
* @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
|
|
350
|
+
* at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
|
|
351
|
+
*
|
|
352
|
+
* It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
|
|
353
|
+
* the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.
|
|
354
|
+
*
|
|
355
|
+
* For example, imagine a client with initial state "123456" submits some ops to create the text "123456ABC".
|
|
356
|
+
* If they insert the "C" first, then "B", then "A", their local segment state might look like this:
|
|
357
|
+
* ```js
|
|
358
|
+
* [
|
|
359
|
+
* { seq: 0, text: "1234" },
|
|
360
|
+
* { seq: 5, text: "56" },
|
|
361
|
+
* { localSeq: 3, seq: UnassignedSequenceNumber, text: "A" },
|
|
362
|
+
* { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
|
|
363
|
+
* { localSeq: 1, seq: UnassignedSequenceNumber, text: "C" },
|
|
364
|
+
* ]
|
|
365
|
+
* ```
|
|
366
|
+
* (note that {@link ISegment.localSeq} tracks the localSeq at which a segment was inserted)
|
|
367
|
+
*
|
|
368
|
+
* Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate
|
|
369
|
+
* that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.
|
|
370
|
+
*
|
|
371
|
+
* It will generate the ops
|
|
372
|
+
* 1. \{ pos: 6, text: "C" \}
|
|
373
|
+
* 2. \{ pos: 6, text: "B" \}
|
|
374
|
+
* 3. \{ pos: 6, text: "A" \}
|
|
375
|
+
*
|
|
376
|
+
* since when submitting the first op, remote clients don't know that this client is about to submit the "A" and "B".
|
|
377
|
+
*
|
|
378
|
+
* On the other hand, imagine if the client had originally submitted the ops in the order "A", "B", "C"
|
|
379
|
+
* such that the segments' local state was instead:
|
|
380
|
+
*
|
|
381
|
+
* ```js
|
|
382
|
+
* [
|
|
383
|
+
* { seq: 0, text: "1234" },
|
|
384
|
+
* { seq: 5, text: "56" },
|
|
385
|
+
* { localSeq: 1, seq: UnassignedSequenceNumber, text: "A" },
|
|
386
|
+
* { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
|
|
387
|
+
* { localSeq: 3, seq: UnassignedSequenceNumber, text: "C" },
|
|
388
|
+
* ]
|
|
389
|
+
* ```
|
|
390
|
+
*
|
|
391
|
+
* The resubmitted ops should instead be:
|
|
392
|
+
* 1. \{ pos: 6, text: "A" \}
|
|
393
|
+
* 2. \{ pos: 7, text: "B" \}
|
|
394
|
+
* 3. \{ pos: 8, text: "C" \}
|
|
395
|
+
*
|
|
396
|
+
* since remote clients will have seen the "A" when processing the "B" as well as both the "A" and "B" when processing the "C".
|
|
397
|
+
* As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing
|
|
398
|
+
* in `localSeq`.
|
|
399
|
+
*
|
|
400
|
+
* This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client
|
|
401
|
+
* was disconnected, the resubmitted ops end up matching the original ops exactly.
|
|
402
|
+
* However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked
|
|
403
|
+
* and local information as appropriate.
|
|
404
|
+
* Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible
|
|
405
|
+
* from a given (seq, localSeq) perspective.
|
|
406
|
+
*/
|
|
338
407
|
localSeq: number;
|
|
339
408
|
loadFrom(a: CollaborationWindow): void;
|
|
340
409
|
}
|
|
@@ -985,8 +1054,11 @@ export declare interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo
|
|
|
985
1054
|
*/
|
|
986
1055
|
propertyManager?: PropertiesManager;
|
|
987
1056
|
/**
|
|
988
|
-
* Local seq at which this segment was inserted.
|
|
1057
|
+
* Local seq at which this segment was inserted.
|
|
1058
|
+
* This is defined if and only if the insertion of the segment is pending ack, i.e. `seq` is UnassignedSequenceNumber.
|
|
989
1059
|
* Once the segment is acked, this field is cleared.
|
|
1060
|
+
*
|
|
1061
|
+
* See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.
|
|
990
1062
|
*/
|
|
991
1063
|
localSeq?: number;
|
|
992
1064
|
/**
|
|
@@ -994,7 +1066,8 @@ export declare interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo
|
|
|
994
1066
|
* UnassignedSequenceNumber. However, if another client concurrently removes the same segment, `removedSeq`
|
|
995
1067
|
* will be updated to the seq at which that client removed this segment.
|
|
996
1068
|
*
|
|
997
|
-
* Like
|
|
1069
|
+
* Like {@link ISegment.localSeq}, this field is cleared once the local removal of the segment is acked.
|
|
1070
|
+
* See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.
|
|
998
1071
|
*/
|
|
999
1072
|
localRemovedSeq?: number;
|
|
1000
1073
|
/**
|
package/dist/mergeTreeNodes.d.ts
CHANGED
|
@@ -147,8 +147,11 @@ export interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo> {
|
|
|
147
147
|
*/
|
|
148
148
|
propertyManager?: PropertiesManager;
|
|
149
149
|
/**
|
|
150
|
-
* Local seq at which this segment was inserted.
|
|
150
|
+
* Local seq at which this segment was inserted.
|
|
151
|
+
* This is defined if and only if the insertion of the segment is pending ack, i.e. `seq` is UnassignedSequenceNumber.
|
|
151
152
|
* Once the segment is acked, this field is cleared.
|
|
153
|
+
*
|
|
154
|
+
* See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.
|
|
152
155
|
*/
|
|
153
156
|
localSeq?: number;
|
|
154
157
|
/**
|
|
@@ -156,7 +159,8 @@ export interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo> {
|
|
|
156
159
|
* UnassignedSequenceNumber. However, if another client concurrently removes the same segment, `removedSeq`
|
|
157
160
|
* will be updated to the seq at which that client removed this segment.
|
|
158
161
|
*
|
|
159
|
-
* Like
|
|
162
|
+
* Like {@link ISegment.localSeq}, this field is cleared once the local removal of the segment is acked.
|
|
163
|
+
* See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.
|
|
160
164
|
*/
|
|
161
165
|
localRemovedSeq?: number;
|
|
162
166
|
/**
|
|
@@ -426,8 +430,77 @@ export declare class IncrementalMapState<TContext> {
|
|
|
426
430
|
export declare class CollaborationWindow {
|
|
427
431
|
clientId: number;
|
|
428
432
|
collaborating: boolean;
|
|
433
|
+
/**
|
|
434
|
+
* Lowest-numbered segment in window; no client can reference a state before this one
|
|
435
|
+
*/
|
|
429
436
|
minSeq: number;
|
|
437
|
+
/**
|
|
438
|
+
* Highest-numbered segment in window and current reference sequence number for this client.
|
|
439
|
+
*/
|
|
430
440
|
currentSeq: number;
|
|
441
|
+
/**
|
|
442
|
+
* Highest-numbered localSeq used for a pending segment.
|
|
443
|
+
* Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
|
|
444
|
+
* for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
|
|
445
|
+
*
|
|
446
|
+
* @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
|
|
447
|
+
* at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
|
|
448
|
+
*
|
|
449
|
+
* It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
|
|
450
|
+
* the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.
|
|
451
|
+
*
|
|
452
|
+
* For example, imagine a client with initial state "123456" submits some ops to create the text "123456ABC".
|
|
453
|
+
* If they insert the "C" first, then "B", then "A", their local segment state might look like this:
|
|
454
|
+
* ```js
|
|
455
|
+
* [
|
|
456
|
+
* { seq: 0, text: "1234" },
|
|
457
|
+
* { seq: 5, text: "56" },
|
|
458
|
+
* { localSeq: 3, seq: UnassignedSequenceNumber, text: "A" },
|
|
459
|
+
* { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
|
|
460
|
+
* { localSeq: 1, seq: UnassignedSequenceNumber, text: "C" },
|
|
461
|
+
* ]
|
|
462
|
+
* ```
|
|
463
|
+
* (note that {@link ISegment.localSeq} tracks the localSeq at which a segment was inserted)
|
|
464
|
+
*
|
|
465
|
+
* Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate
|
|
466
|
+
* that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.
|
|
467
|
+
*
|
|
468
|
+
* It will generate the ops
|
|
469
|
+
* 1. \{ pos: 6, text: "C" \}
|
|
470
|
+
* 2. \{ pos: 6, text: "B" \}
|
|
471
|
+
* 3. \{ pos: 6, text: "A" \}
|
|
472
|
+
*
|
|
473
|
+
* since when submitting the first op, remote clients don't know that this client is about to submit the "A" and "B".
|
|
474
|
+
*
|
|
475
|
+
* On the other hand, imagine if the client had originally submitted the ops in the order "A", "B", "C"
|
|
476
|
+
* such that the segments' local state was instead:
|
|
477
|
+
*
|
|
478
|
+
* ```js
|
|
479
|
+
* [
|
|
480
|
+
* { seq: 0, text: "1234" },
|
|
481
|
+
* { seq: 5, text: "56" },
|
|
482
|
+
* { localSeq: 1, seq: UnassignedSequenceNumber, text: "A" },
|
|
483
|
+
* { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
|
|
484
|
+
* { localSeq: 3, seq: UnassignedSequenceNumber, text: "C" },
|
|
485
|
+
* ]
|
|
486
|
+
* ```
|
|
487
|
+
*
|
|
488
|
+
* The resubmitted ops should instead be:
|
|
489
|
+
* 1. \{ pos: 6, text: "A" \}
|
|
490
|
+
* 2. \{ pos: 7, text: "B" \}
|
|
491
|
+
* 3. \{ pos: 8, text: "C" \}
|
|
492
|
+
*
|
|
493
|
+
* since remote clients will have seen the "A" when processing the "B" as well as both the "A" and "B" when processing the "C".
|
|
494
|
+
* As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing
|
|
495
|
+
* in `localSeq`.
|
|
496
|
+
*
|
|
497
|
+
* This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client
|
|
498
|
+
* was disconnected, the resubmitted ops end up matching the original ops exactly.
|
|
499
|
+
* However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked
|
|
500
|
+
* and local information as appropriate.
|
|
501
|
+
* Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible
|
|
502
|
+
* from a given (seq, localSeq) perspective.
|
|
503
|
+
*/
|
|
431
504
|
localSeq: number;
|
|
432
505
|
loadFrom(a: CollaborationWindow): void;
|
|
433
506
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeNodes.d.ts","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,C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MAAM,cAAc,MAAO,MAAM,KAAK,MAAM,WAAuB,CAAC;AAG3E;;;GAGG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAAE,MAAM,UAQvC;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACrB;AACD;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAgE1D"}
|
package/dist/mergeTreeNodes.js
CHANGED
|
@@ -313,11 +313,77 @@ class CollaborationWindow {
|
|
|
313
313
|
constructor() {
|
|
314
314
|
this.clientId = constants_1.LocalClientId;
|
|
315
315
|
this.collaborating = false;
|
|
316
|
-
|
|
316
|
+
/**
|
|
317
|
+
* Lowest-numbered segment in window; no client can reference a state before this one
|
|
318
|
+
*/
|
|
317
319
|
this.minSeq = 0;
|
|
318
|
-
|
|
319
|
-
|
|
320
|
+
/**
|
|
321
|
+
* Highest-numbered segment in window and current reference sequence number for this client.
|
|
322
|
+
*/
|
|
320
323
|
this.currentSeq = 0;
|
|
324
|
+
/**
|
|
325
|
+
* Highest-numbered localSeq used for a pending segment.
|
|
326
|
+
* Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
|
|
327
|
+
* for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
|
|
328
|
+
*
|
|
329
|
+
* @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
|
|
330
|
+
* at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
|
|
331
|
+
*
|
|
332
|
+
* It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
|
|
333
|
+
* the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.
|
|
334
|
+
*
|
|
335
|
+
* For example, imagine a client with initial state "123456" submits some ops to create the text "123456ABC".
|
|
336
|
+
* If they insert the "C" first, then "B", then "A", their local segment state might look like this:
|
|
337
|
+
* ```js
|
|
338
|
+
* [
|
|
339
|
+
* { seq: 0, text: "1234" },
|
|
340
|
+
* { seq: 5, text: "56" },
|
|
341
|
+
* { localSeq: 3, seq: UnassignedSequenceNumber, text: "A" },
|
|
342
|
+
* { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
|
|
343
|
+
* { localSeq: 1, seq: UnassignedSequenceNumber, text: "C" },
|
|
344
|
+
* ]
|
|
345
|
+
* ```
|
|
346
|
+
* (note that {@link ISegment.localSeq} tracks the localSeq at which a segment was inserted)
|
|
347
|
+
*
|
|
348
|
+
* Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate
|
|
349
|
+
* that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.
|
|
350
|
+
*
|
|
351
|
+
* It will generate the ops
|
|
352
|
+
* 1. \{ pos: 6, text: "C" \}
|
|
353
|
+
* 2. \{ pos: 6, text: "B" \}
|
|
354
|
+
* 3. \{ pos: 6, text: "A" \}
|
|
355
|
+
*
|
|
356
|
+
* since when submitting the first op, remote clients don't know that this client is about to submit the "A" and "B".
|
|
357
|
+
*
|
|
358
|
+
* On the other hand, imagine if the client had originally submitted the ops in the order "A", "B", "C"
|
|
359
|
+
* such that the segments' local state was instead:
|
|
360
|
+
*
|
|
361
|
+
* ```js
|
|
362
|
+
* [
|
|
363
|
+
* { seq: 0, text: "1234" },
|
|
364
|
+
* { seq: 5, text: "56" },
|
|
365
|
+
* { localSeq: 1, seq: UnassignedSequenceNumber, text: "A" },
|
|
366
|
+
* { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
|
|
367
|
+
* { localSeq: 3, seq: UnassignedSequenceNumber, text: "C" },
|
|
368
|
+
* ]
|
|
369
|
+
* ```
|
|
370
|
+
*
|
|
371
|
+
* The resubmitted ops should instead be:
|
|
372
|
+
* 1. \{ pos: 6, text: "A" \}
|
|
373
|
+
* 2. \{ pos: 7, text: "B" \}
|
|
374
|
+
* 3. \{ pos: 8, text: "C" \}
|
|
375
|
+
*
|
|
376
|
+
* since remote clients will have seen the "A" when processing the "B" as well as both the "A" and "B" when processing the "C".
|
|
377
|
+
* As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing
|
|
378
|
+
* in `localSeq`.
|
|
379
|
+
*
|
|
380
|
+
* This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client
|
|
381
|
+
* was disconnected, the resubmitted ops end up matching the original ops exactly.
|
|
382
|
+
* However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked
|
|
383
|
+
* and local information as appropriate.
|
|
384
|
+
* Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible
|
|
385
|
+
* from a given (seq, localSeq) perspective.
|
|
386
|
+
*/
|
|
321
387
|
this.localSeq = 0;
|
|
322
388
|
}
|
|
323
389
|
loadFrom(a) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAA6D;AAC7D,yCAAyC;AAEzC,2DAAoD;AAGpD,2CAA+F;AAC/F,qDAA4D;AAE5D,2DAA8D;AAC9D,+BAAkG;AAClG,uCAAuD;AAEvD,6CAAsE;AACtE,6DAM8B;AAC9B,qEAAkE;AAClE,yEAAmF;AA0FnF;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAwC;IACrE,IAAI,KAAK,EAAE,gBAAgB,KAAK,SAAS,IAAI,KAAK,EAAE,UAAU,KAAK,SAAS,EAAE;QAC7E,OAAO,KAAqB,CAAC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AAC,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxD,wEAAwE;YACxE,uCAAuC;YACvC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,YAAY,CAAC;YAE7C,+DAA+D;YAC/D,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,CAAC,YAAY,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/E,CAAC,CAAC,CAAC;KACH;IACD,OAAO,KAAK,IAAI,KAAK,IAAI,IAAI,IAAI,EAAE,CAAC;AACrC,CAAC;AAhED,kDAgEC","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/* eslint-disable import/no-deprecated */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { AttributionKey } from \"@fluidframework/runtime-definitions\";\nimport { IAttributionCollection } from \"./attributionCollection\";\nimport { LocalClientId, UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants\";\nimport { LocalReferenceCollection } from \"./localReference\";\nimport { IMergeTreeDeltaOpArgs } from \"./mergeTreeDeltaCallback\";\nimport { TrackingGroupCollection } from \"./mergeTreeTracking\";\nimport { ICombiningOp, IJSONSegment, IMarkerDef, MergeTreeDeltaType, ReferenceType } from \"./ops\";\nimport { computeHierarchicalOrdinal } from \"./ordinal\";\nimport { PartialSequenceLengths } from \"./partialLengths\";\nimport { clone, createMap, MapLike, PropertySet } from \"./properties\";\nimport {\n\trefTypeIncludesFlag,\n\tRangeStackMap,\n\tReferencePosition,\n\trefGetRangeLabels,\n\trefGetTileLabels,\n} from \"./referencePositions\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection\";\nimport { PropertiesManager, PropertiesRollback } from \"./segmentPropertiesManager\";\n\n/**\n * Common properties for a node in a merge tree.\n * @internal\n */\nexport interface IMergeNodeCommon {\n\t/**\n\t * The index of this node in its parent's list of children.\n\t */\n\tindex: number;\n\t/**\n\t * A string that can be used for comparing the location of this node to other `MergeNode`s in the same tree.\n\t * `a.ordinal < b.ordinal` if and only if `a` comes before `b` in a pre-order traversal of the tree.\n\t */\n\tordinal: string;\n\tisLeaf(): this is ISegment;\n}\n\nexport type IMergeLeaf = ISegment & { parent?: IMergeBlock };\nexport type IMergeNode = IMergeBlock | IMergeLeaf;\n/**\n * Internal (i.e. non-leaf) node in a merge tree.\n * @internal\n */\nexport interface IMergeBlock extends IMergeNodeCommon {\n\tparent?: IMergeBlock;\n\n\tneedsScour?: boolean;\n\t/**\n\t * Number of direct children of this node\n\t */\n\tchildCount: number;\n\t/**\n\t * Array of child nodes.\n\t *\n\t * @remarks To avoid reallocation, this is always initialized to have maximum length as deemed by\n\t * the merge tree's branching factor. Use `childCount` to determine how many children this node actually has.\n\t */\n\tchildren: IMergeNode[];\n\t/**\n\t * Supports querying the total length of all descendants of this IMergeBlock from the perspective of any\n\t * (clientId, seq) within the collab window.\n\t *\n\t * @remarks This is only optional for implementation reasons (internal nodes can be created/moved without\n\t * immediately initializing the partial lengths). Aside from mid-update on tree operations, these lengths\n\t * objects are always defined.\n\t */\n\tpartialLengths?: PartialSequenceLengths;\n\t/**\n\t * The length of the contents of the node.\n\t */\n\tcachedLength: number | undefined;\n\thierBlock(): IHierBlock | undefined;\n\tassignChild(child: IMergeNode, index: number, updateOrdinal?: boolean): void;\n\tsetOrdinal(child: IMergeNode, index: number): void;\n}\n\n/**\n * @internal\n */\nexport interface IHierBlock extends IMergeBlock {\n\thierToString(indentCount: number): string;\n\trightmostTiles: MapLike<ReferencePosition>;\n\tleftmostTiles: MapLike<ReferencePosition>;\n\trangeStacks: RangeStackMap;\n}\n\n/**\n * Contains removal information associated to an {@link ISegment}.\n * @internal\n */\nexport interface IRemovalInfo {\n\t/**\n\t * Local seq at which this segment was removed, if the removal is yet-to-be acked.\n\t */\n\tlocalRemovedSeq?: number;\n\t/**\n\t * Seq at which this segment was removed.\n\t */\n\tremovedSeq: number;\n\t/**\n\t * List of client IDs that have removed this segment.\n\t * The client that actually removed the segment (i.e. whose removal op was sequenced first) is stored as the first\n\t * client in this list. Other clients in the list have all issued concurrent ops to remove the segment.\n\t * @remarks When this list has length \\> 1, this is referred to as the \"overlapping remove\" case.\n\t */\n\tremovedClientIds: number[];\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport function toRemovalInfo(maybe: Partial<IRemovalInfo> | undefined): IRemovalInfo | undefined {\n\tif (maybe?.removedClientIds !== undefined && maybe?.removedSeq !== undefined) {\n\t\treturn maybe as IRemovalInfo;\n\t}\n\tassert(\n\t\tmaybe?.removedClientIds === undefined && maybe?.removedSeq === undefined,\n\t\t0x2bf /* \"both removedClientIds and removedSeq should be set or not set\" */,\n\t);\n}\n\n/**\n * A segment representing a portion of the merge tree.\n * Segments are leaf nodes of the merge tree and contain data.\n * @internal\n */\nexport interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo> {\n\treadonly type: string;\n\treadonly segmentGroups: SegmentGroupCollection;\n\treadonly trackingCollection: TrackingGroupCollection;\n\t/**\n\t * Whether or not this segment is a special segment denoting the start or\n\t * end of the tree\n\t *\n\t * Endpoint segments are imaginary segments positioned immediately before or\n\t * after the tree. These segments cannot be referenced by regular operations\n\t * and exist primarily as a bucket for local references to slide onto during\n\t * deletion of regular segments.\n\t */\n\treadonly endpointType?: \"start\" | \"end\";\n\n\t/**\n\t * The length of the contents of the node.\n\t */\n\tcachedLength: number;\n\t/**\n\t * Stores attribution keys associated with offsets of this segment.\n\t * This data is only persisted if MergeTree's `attributions.track` flag is set to true.\n\t * Pending segments (i.e. ones that only exist locally and haven't been acked by the server) also have\n\t * `attribution === undefined` until ack.\n\t *\n\t * Keys can be used opaquely with an IAttributor or a container runtime that provides attribution.\n\t * @remarks There are plans to make the shape of the data stored extensible in a couple ways:\n\t *\n\t * 1. Injection of custom attribution information associated with the segment (ex: copy-paste of\n\t * content but keeping the old attribution information).\n\t *\n\t * 2. Storage of multiple \"channels\" of information (ex: track property changes separately from insertion,\n\t * or only attribute certain property modifications, etc.)\n\t */\n\tattribution?: IAttributionCollection<AttributionKey>;\n\n\t/**\n\t * Manages pending local state for properties on this segment.\n\t */\n\tpropertyManager?: PropertiesManager;\n\t/**\n\t * Local seq at which this segment was inserted. If this is defined, `seq` will be UnassignedSequenceNumber.\n\t * Once the segment is acked, this field is cleared.\n\t */\n\tlocalSeq?: number;\n\t/**\n\t * Local seq at which this segment was removed. If this is defined, `removedSeq` will initially be set to\n\t * UnassignedSequenceNumber. However, if another client concurrently removes the same segment, `removedSeq`\n\t * will be updated to the seq at which that client removed this segment.\n\t *\n\t * Like `localSeq`, this field is cleared once the local removal of the segment is acked.\n\t */\n\tlocalRemovedSeq?: number;\n\t/**\n\t * Seq at which this segment was inserted.\n\t * If undefined, it is assumed the segment was inserted prior to the collab window's minimum sequence number.\n\t */\n\tseq?: number;\n\t/**\n\t * Short clientId for the client that inserted this segment.\n\t */\n\tclientId: number;\n\t/**\n\t * Local references added to this segment.\n\t */\n\tlocalRefs?: LocalReferenceCollection;\n\t/**\n\t * Properties that have been added to this segment via annotation.\n\t */\n\tproperties?: PropertySet;\n\taddProperties(\n\t\tnewProps: PropertySet,\n\t\top?: ICombiningOp,\n\t\tseq?: number,\n\t\tcollabWindow?: CollaborationWindow,\n\t\trollback?: PropertiesRollback,\n\t): PropertySet | undefined;\n\tclone(): ISegment;\n\tcanAppend(segment: ISegment): boolean;\n\tappend(segment: ISegment): void;\n\tsplitAt(pos: number): ISegment | undefined;\n\ttoJSONObject(): any;\n\t/**\n\t * Acks the current segment against the segment group, op, and merge tree.\n\t *\n\t * @param segmentGroup - Pending segment group associated with this op.\n\t * @param opArgs - Information about the op that was acked\n\t * @returns `true` if the op modifies the segment, otherwise `false`.\n\t * The only current false case is overlapping remove, where a segment is removed\n\t * by a previously sequenced operation before the current operation is acked.\n\t * @throws - error if the segment state doesn't match segment group or op.\n\t * E.g. if the segment group is not first in the pending queue, or\n\t * an inserted segment does not have unassigned sequence number.\n\t *\n\t * @deprecated This functionality was not meant to be exported and will be removed in a future release\n\t */\n\tack(segmentGroup: SegmentGroup, opArgs: IMergeTreeDeltaOpArgs): boolean;\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface IMarkerModifiedAction {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(marker: Marker): void;\n}\n\n/**\n * @internal\n */\nexport interface ISegmentAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tsegment: ISegment,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number,\n\t\tend: number,\n\t\taccum: TClientData,\n\t): boolean;\n}\n/**\n * @internal\n */\nexport interface ISegmentChanges {\n\tnext?: ISegment;\n\treplaceCurrent?: ISegment;\n}\n/**\n * @internal\n */\nexport interface BlockAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tblock: IMergeBlock,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\taccum: TClientData,\n\t): boolean;\n}\n\n/**\n * @internal\n */\nexport interface NodeAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tnode: IMergeNode,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\tclientData: TClientData,\n\t): boolean;\n}\n/**\n * @internal\n */\nexport interface IncrementalSegmentAction<TContext> {\n\t(segment: ISegment, state: IncrementalMapState<TContext>);\n}\n\n/**\n * @internal\n */\nexport interface IncrementalBlockAction<TContext> {\n\t(state: IncrementalMapState<TContext>);\n}\n/**\n * @internal\n * */\nexport interface BlockUpdateActions {\n\tchild: (block: IMergeBlock, index: number) => void;\n}\n\n/**\n * @internal\n */\nexport interface InsertContext {\n\tcandidateSegment?: ISegment;\n\tprepareEvents?: boolean;\n\tstructureChange?: boolean;\n\tleaf: (segment: ISegment | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: IMergeBlock) => boolean;\n}\n\n/**\n * @internal\n */\nexport interface SegmentActions<TClientData> {\n\tleaf?: ISegmentAction<TClientData>;\n\tshift?: NodeAction<TClientData>;\n\tcontains?: NodeAction<TClientData>;\n\tpre?: BlockAction<TClientData>;\n\tpost?: BlockAction<TClientData>;\n}\n/**\n * @internal\n */\nexport interface IncrementalSegmentActions<TContext> {\n\tleaf: IncrementalSegmentAction<TContext>;\n\tpre?: IncrementalBlockAction<TContext>;\n\tpost?: IncrementalBlockAction<TContext>;\n}\n\n/**\n * @internal\n */\nexport interface SearchResult {\n\ttext: string;\n\tpos: number;\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface SegmentGroup {\n\tsegments: ISegment[];\n\tpreviousProps?: PropertySet[];\n\tlocalSeq: number;\n\trefSeq: number;\n}\n\n/**\n * @internal\n */\nexport class MergeNode implements IMergeNodeCommon {\n\tindex: number = 0;\n\tordinal: string = \"\";\n\tcachedLength: number = 0;\n\n\tisLeaf(): this is ISegment {\n\t\treturn false;\n\t}\n}\n\n/**\n * Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because\n * the MergeTree always inserts first, then checks for overflow and splits if the child count equals\n * `MaxNodesInBlock`. (i.e., `MaxNodesInBlock` contains 1 extra slot for temporary storage to\n * facilitate splits.)\n * @internal\n */\nexport const MaxNodesInBlock = 8;\n/**\n * @internal\n */\nexport class MergeBlock extends MergeNode implements IMergeBlock {\n\tparent?: IMergeBlock;\n\tpublic children: IMergeNode[];\n\tpublic constructor(public childCount: number) {\n\t\tsuper();\n\t\tthis.children = new Array<IMergeNode>(MaxNodesInBlock);\n\t}\n\n\tpublic hierBlock(): IHierBlock | undefined {\n\t\treturn undefined;\n\t}\n\n\tpublic setOrdinal(child: IMergeNode, index: number) {\n\t\tconst childCount = this.childCount;\n\t\tassert(\n\t\t\tchildCount >= 1 && childCount <= MaxNodesInBlock,\n\t\t\t0x040 /* \"Child count is not within [1,8] range!\" */,\n\t\t);\n\t\tchild.ordinal = computeHierarchicalOrdinal(\n\t\t\tMaxNodesInBlock,\n\t\t\tchildCount,\n\t\t\tthis.ordinal,\n\t\t\tindex === 0 ? undefined : this.children[index - 1]?.ordinal,\n\t\t);\n\t}\n\n\tpublic assignChild(child: IMergeNode, index: number, updateOrdinal = true) {\n\t\tchild.parent = this;\n\t\tchild.index = index;\n\t\tif (updateOrdinal) {\n\t\t\tthis.setOrdinal(child, index);\n\t\t}\n\t\tthis.children[index] = child;\n\t}\n}\n\nexport function seqLTE(seq: number, minOrRefSeq: number) {\n\treturn seq !== UnassignedSequenceNumber && seq <= minOrRefSeq;\n}\n\n/**\n * @internal\n */\nexport abstract class BaseSegment extends MergeNode implements ISegment {\n\tpublic clientId: number = LocalClientId;\n\tpublic seq: number = UniversalSequenceNumber;\n\tpublic removedSeq?: number;\n\tpublic removedClientIds?: number[];\n\tpublic readonly segmentGroups: SegmentGroupCollection = new SegmentGroupCollection(this);\n\tpublic readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(this);\n\t/***/\n\tpublic attribution?: IAttributionCollection<AttributionKey>;\n\tpublic propertyManager?: PropertiesManager;\n\tpublic properties?: PropertySet;\n\tpublic localRefs?: LocalReferenceCollection;\n\tpublic abstract readonly type: string;\n\tpublic localSeq?: number;\n\tpublic localRemovedSeq?: number;\n\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\top?: ICombiningOp,\n\t\tseq?: number,\n\t\tcollabWindow?: CollaborationWindow,\n\t\trollback: PropertiesRollback = PropertiesRollback.None,\n\t) {\n\t\tthis.propertyManager ??= new PropertiesManager();\n\t\tthis.properties ??= createMap<any>();\n\t\treturn this.propertyManager.addProperties(\n\t\t\tthis.properties,\n\t\t\tnewProps,\n\t\t\top,\n\t\t\tseq,\n\t\t\tcollabWindow && collabWindow.collaborating,\n\t\t\trollback,\n\t\t);\n\t}\n\n\tpublic hasProperty(key: string): boolean {\n\t\treturn !!this.properties && this.properties[key] !== undefined;\n\t}\n\n\tpublic isLeaf() {\n\t\treturn true;\n\t}\n\n\tprotected cloneInto(b: ISegment) {\n\t\tb.clientId = this.clientId;\n\t\t// TODO: deep clone properties\n\t\tb.properties = clone(this.properties);\n\t\tb.removedClientIds = this.removedClientIds?.slice();\n\t\t// TODO: copy removed client overlap and branch removal info\n\t\tb.removedSeq = this.removedSeq;\n\t\tb.seq = this.seq;\n\t\tb.attribution = this.attribution?.clone();\n\t}\n\n\tpublic canAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tprotected addSerializedProps(jseg: IJSONSegment) {\n\t\tif (this.properties) {\n\t\t\tjseg.props = this.properties;\n\t\t}\n\t}\n\n\tpublic abstract toJSONObject(): any;\n\n\t/**\n\t * @deprecated This functionality was not meant to be exported and will be removed in a future release\n\t */\n\tpublic ack(segmentGroup: SegmentGroup, opArgs: IMergeTreeDeltaOpArgs): boolean {\n\t\tconst currentSegmentGroup = this.segmentGroups.dequeue();\n\t\tassert(\n\t\t\tcurrentSegmentGroup === segmentGroup,\n\t\t\t0x043 /* \"On ack, unexpected segmentGroup!\" */,\n\t\t);\n\t\tswitch (opArgs.op.type) {\n\t\t\tcase MergeTreeDeltaType.ANNOTATE:\n\t\t\t\tassert(\n\t\t\t\t\t!!this.propertyManager,\n\t\t\t\t\t0x044 /* \"On annotate ack, missing segment property manager!\" */,\n\t\t\t\t);\n\t\t\t\tthis.propertyManager.ackPendingProperties(opArgs.op);\n\t\t\t\treturn true;\n\n\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\tassert(\n\t\t\t\t\tthis.seq === UnassignedSequenceNumber,\n\t\t\t\t\t0x045 /* \"On insert, seq number already assigned!\" */,\n\t\t\t\t);\n\t\t\t\tthis.seq = opArgs.sequencedMessage!.sequenceNumber;\n\t\t\t\tthis.localSeq = undefined;\n\t\t\t\treturn true;\n\n\t\t\tcase MergeTreeDeltaType.REMOVE:\n\t\t\t\tconst removalInfo: IRemovalInfo | undefined = toRemovalInfo(this);\n\t\t\t\tassert(\n\t\t\t\t\tremovalInfo !== undefined,\n\t\t\t\t\t0x046 /* \"On remove ack, missing removal info!\" */,\n\t\t\t\t);\n\t\t\t\tthis.localRemovedSeq = undefined;\n\t\t\t\tif (removalInfo.removedSeq === UnassignedSequenceNumber) {\n\t\t\t\t\tremovalInfo.removedSeq = opArgs.sequencedMessage!.sequenceNumber;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`${opArgs.op.type} is in unrecognized operation type`);\n\t\t}\n\t}\n\n\tpublic splitAt(pos: number): ISegment | undefined {\n\t\tif (pos > 0) {\n\t\t\tconst leafSegment: IMergeLeaf | undefined = this.createSplitSegmentAt(pos);\n\t\t\tif (leafSegment) {\n\t\t\t\tthis.copyPropertiesTo(leafSegment);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\t\t\tconst thisAsMergeSegment: IMergeLeaf = this;\n\t\t\t\tleafSegment.parent = thisAsMergeSegment.parent;\n\n\t\t\t\t// Give the leaf a temporary yet valid ordinal.\n\t\t\t\t// when this segment is put in the tree, it will get its real ordinal,\n\t\t\t\t// but this ordinal meets all the necessary invariants for now.\n\t\t\t\tleafSegment.ordinal = this.ordinal + String.fromCharCode(0);\n\n\t\t\t\tleafSegment.removedClientIds = this.removedClientIds?.slice();\n\t\t\t\tleafSegment.removedSeq = this.removedSeq;\n\t\t\t\tleafSegment.localRemovedSeq = this.localRemovedSeq;\n\t\t\t\tleafSegment.seq = this.seq;\n\t\t\t\tleafSegment.localSeq = this.localSeq;\n\t\t\t\tleafSegment.clientId = this.clientId;\n\t\t\t\tthis.segmentGroups.copyTo(leafSegment);\n\t\t\t\tthis.trackingCollection.copyTo(leafSegment);\n\t\t\t\tif (this.localRefs) {\n\t\t\t\t\tthis.localRefs.split(pos, leafSegment);\n\t\t\t\t}\n\t\t\t\tif (this.attribution) {\n\t\t\t\t\tleafSegment.attribution = this.attribution.splitAt(pos);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn leafSegment;\n\t\t}\n\t}\n\n\tprivate copyPropertiesTo(other: ISegment) {\n\t\tif (this.propertyManager) {\n\t\t\tif (this.properties) {\n\t\t\t\tother.propertyManager = new PropertiesManager();\n\t\t\t\tother.properties = this.propertyManager.copyTo(\n\t\t\t\t\tthis.properties,\n\t\t\t\t\tother.properties,\n\t\t\t\t\tother.propertyManager,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic abstract clone(): ISegment;\n\n\tpublic append(other: ISegment): void {\n\t\t// Note: Must call 'appendLocalRefs' before modifying this segment's length as\n\t\t// 'this.cachedLength' is used to adjust the offsets of the local refs.\n\t\tLocalReferenceCollection.append(this, other);\n\t\tif (this.attribution) {\n\t\t\tassert(\n\t\t\t\tother.attribution !== undefined,\n\t\t\t\t0x4bd /* attribution should be set on appendee */,\n\t\t\t);\n\t\t\tthis.attribution.append(other.attribution);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tother.attribution === undefined,\n\t\t\t\t0x4be /* attribution should not be set on appendee */,\n\t\t\t);\n\t\t}\n\n\t\tthis.cachedLength ??= 0;\n\t\tthis.cachedLength += other.cachedLength;\n\t}\n\n\tprotected abstract createSplitSegmentAt(pos: number): BaseSegment | undefined;\n}\n\n/**\n * @internal\n */\nexport const reservedMarkerIdKey = \"markerId\";\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @internal\n */\nexport interface IJSONMarkerSegment extends IJSONSegment {\n\tmarker: IMarkerDef;\n}\n\n/**\n * @internal\n */\nexport class Marker extends BaseSegment implements ReferencePosition {\n\tpublic static readonly type = \"Marker\";\n\tpublic static is(segment: ISegment): segment is Marker {\n\t\treturn segment.type === Marker.type;\n\t}\n\tpublic readonly type = Marker.type;\n\n\tpublic static make(refType: ReferenceType, props?: PropertySet) {\n\t\tconst marker = new Marker(refType);\n\t\tif (props) {\n\t\t\tmarker.addProperties(props);\n\t\t}\n\t\treturn marker;\n\t}\n\n\tconstructor(public refType: ReferenceType) {\n\t\tsuper();\n\t\tthis.cachedLength = 1;\n\t}\n\n\ttoJSONObject() {\n\t\tconst obj: IJSONMarkerSegment = { marker: { refType: this.refType } };\n\t\tsuper.addSerializedProps(obj);\n\t\treturn obj;\n\t}\n\n\tstatic fromJSONObject(spec: any) {\n\t\tif (spec && typeof spec === \"object\" && \"marker\" in spec) {\n\t\t\treturn Marker.make(spec.marker.refType, spec.props as PropertySet);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tclone() {\n\t\tconst b = Marker.make(this.refType, this.properties);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tgetSegment() {\n\t\treturn this;\n\t}\n\n\tgetOffset() {\n\t\treturn 0;\n\t}\n\n\thasSimpleType(simpleTypeName: string) {\n\t\treturn !!this.properties && this.properties[reservedMarkerSimpleTypeKey] === simpleTypeName;\n\t}\n\n\tgetProperties() {\n\t\treturn this.properties;\n\t}\n\n\tgetId(): string | undefined {\n\t\treturn this.properties?.[reservedMarkerIdKey] as string;\n\t}\n\n\ttoString() {\n\t\treturn `M${this.getId()}`;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number) {\n\t\treturn undefined;\n\t}\n\n\tcanAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tappend() {\n\t\tthrow new Error(\"Can not append to marker\");\n\t}\n}\n/**\n * @internal\n */\nexport enum IncrementalExecOp {\n\tGo,\n\tStop,\n\tYield,\n}\n/**\n * @internal\n */\nexport class IncrementalMapState<TContext> {\n\top = IncrementalExecOp.Go;\n\tconstructor(\n\t\tpublic block: IMergeBlock,\n\t\tpublic actions: IncrementalSegmentActions<TContext>,\n\t\tpublic pos: number,\n\t\tpublic refSeq: number,\n\t\tpublic clientId: number,\n\t\tpublic context: TContext,\n\t\tpublic start: number,\n\t\tpublic end: number,\n\t\tpublic childIndex = 0,\n\t) {}\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport class CollaborationWindow {\n\tclientId = LocalClientId;\n\tcollaborating = false;\n\t// Lowest-numbered segment in window; no client can reference a state before this one\n\tminSeq = 0;\n\t// Highest-numbered segment in window and current\n\t// reference segment for this client\n\tcurrentSeq = 0;\n\n\tlocalSeq = 0;\n\n\tloadFrom(a: CollaborationWindow) {\n\t\tthis.clientId = a.clientId;\n\t\tthis.collaborating = a.collaborating;\n\t\tthis.minSeq = a.minSeq;\n\t\tthis.currentSeq = a.currentSeq;\n\t}\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport const compareNumbers = (a: number, b: number) => a - b;\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport const compareStrings = (a: string, b: string) => a.localeCompare(b);\n\nconst indentStrings = [\"\", \" \", \" \"];\n/**\n * @deprecated This functionality is deprecated and will be removed in a future release.\n * @internal\n */\nexport function internedSpaces(n: number) {\n\tif (indentStrings[n] === undefined) {\n\t\tindentStrings[n] = \"\";\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tindentStrings[n] += \" \";\n\t\t}\n\t}\n\treturn indentStrings[n];\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface IConsensusInfo {\n\tmarker: Marker;\n\tcallback: (m: Marker) => void;\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface SegmentAccumulator {\n\tsegments: ISegment[];\n}\n/**\n * @internal\n */\nexport interface MinListener {\n\tminRequired: number;\n\tonMinGE(minSeq: number): void;\n}\n\n/**\n * @internal\n */\nexport function debugMarkerToString(marker: Marker): string {\n\tlet bbuf = \"\";\n\tif (refTypeIncludesFlag(marker, ReferenceType.Tile)) {\n\t\tbbuf += \"Tile\";\n\t}\n\tif (refTypeIncludesFlag(marker, ReferenceType.NestBegin)) {\n\t\tif (bbuf.length > 0) {\n\t\t\tbbuf += \"; \";\n\t\t}\n\t\tbbuf += \"RangeBegin\";\n\t}\n\tif (refTypeIncludesFlag(marker, ReferenceType.NestEnd)) {\n\t\tif (bbuf.length > 0) {\n\t\t\tbbuf += \"; \";\n\t\t}\n\t\tbbuf += \"RangeEnd\";\n\t}\n\tlet lbuf = \"\";\n\tconst id = marker.getId();\n\tif (id) {\n\t\tbbuf += ` (${id}) `;\n\t}\n\tconst tileLabels = refGetTileLabels(marker);\n\tif (tileLabels) {\n\t\tlbuf += \"tile -- \";\n\t\tfor (let i = 0, len = tileLabels.length; i < len; i++) {\n\t\t\tconst tileLabel = tileLabels[i];\n\t\t\tif (i > 0) {\n\t\t\t\tlbuf += \"; \";\n\t\t\t}\n\t\t\tlbuf += tileLabel;\n\t\t}\n\t}\n\tconst rangeLabels = refGetRangeLabels(marker);\n\tif (rangeLabels) {\n\t\tlet rangeKind = \"begin\";\n\t\tif (refTypeIncludesFlag(marker, ReferenceType.NestEnd)) {\n\t\t\trangeKind = \"end\";\n\t\t}\n\t\tif (tileLabels) {\n\t\t\tlbuf += \" \";\n\t\t}\n\t\tlbuf += `range ${rangeKind} -- `;\n\t\tconst labels = rangeLabels;\n\t\tfor (let i = 0, len = labels.length; i < len; i++) {\n\t\t\tconst rangeLabel = labels[i];\n\t\t\tif (i > 0) {\n\t\t\t\tlbuf += \"; \";\n\t\t\t}\n\t\t\tlbuf += rangeLabel;\n\t\t}\n\t}\n\tlet pbuf = \"\";\n\tif (marker.properties) {\n\t\tpbuf += JSON.stringify(marker.properties, (key, value) => {\n\t\t\t// Avoid circular reference when stringifying makers containing handles.\n\t\t\t// (Substitute a debug string instead.)\n\t\t\tconst handle = !!value && value.IFluidHandle;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn handle ? `#Handle(${handle.routeContext.path}/${handle.path})` : value;\n\t\t});\n\t}\n\treturn `M ${bbuf}: ${lbuf} ${pbuf}`;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,6DAA6D;AAC7D,yCAAyC;AAEzC,2DAAoD;AAGpD,2CAA+F;AAC/F,qDAA4D;AAE5D,2DAA8D;AAC9D,+BAAkG;AAClG,uCAAuD;AAEvD,6CAAsE;AACtE,6DAM8B;AAC9B,qEAAkE;AAClE,yEAAmF;AA0FnF;;;GAGG;AACH,SAAgB,aAAa,CAAC,KAAwC;IACrE,IAAI,KAAK,EAAE,gBAAgB,KAAK,SAAS,IAAI,KAAK,EAAE,UAAU,KAAK,SAAS,EAAE;QAC7E,OAAO,KAAqB,CAAC;KAC7B;IACD,IAAA,mBAAM,EACL,KAAK,EAAE,gBAAgB,KAAK,SAAS,IAAI,KAAK,EAAE,UAAU,KAAK,SAAS,EACxE,KAAK,CAAC,qEAAqE,CAC3E,CAAC;AACH,CAAC;AARD,sCAQC;AAiPD;;GAEG;AACH,MAAa,SAAS;IAAtB;QACC,UAAK,GAAW,CAAC,CAAC;QAClB,YAAO,GAAW,EAAE,CAAC;QACrB,iBAAY,GAAW,CAAC,CAAC;IAK1B,CAAC;IAHA,MAAM;QACL,OAAO,KAAK,CAAC;IACd,CAAC;CACD;AARD,8BAQC;AAED;;;;;;GAMG;AACU,QAAA,eAAe,GAAG,CAAC,CAAC;AACjC;;GAEG;AACH,MAAa,UAAW,SAAQ,SAAS;IAGxC,YAA0B,UAAkB;QAC3C,KAAK,EAAE,CAAC;QADiB,eAAU,GAAV,UAAU,CAAQ;QAE3C,IAAI,CAAC,QAAQ,GAAG,IAAI,KAAK,CAAa,uBAAe,CAAC,CAA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,WAAW,EAAE;QAChB,IAAI,SAAS,GAAG,OAAO,CAAC;QACxB,IAAI,IAAA,wCAAmB,EAAC,MAAM,EAAE,mBAAa,CAAC,OAAO,CAAC,EAAE;YACvD,SAAS,GAAG,KAAK,CAAC;SAClB;QACD,IAAI,UAAU,EAAE;YACf,IAAI,IAAI,GAAG,CAAC;SACZ;QACD,IAAI,IAAI,SAAS,SAAS,MAAM,CAAC;QACjC,MAAM,MAAM,GAAG,WAAW,CAAC;QAC3B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,GAAG,GAAG,MAAM,CAAC,MAAM,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;YAClD,MAAM,UAAU,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;YAC7B,IAAI,CAAC,GAAG,CAAC,EAAE;gBACV,IAAI,IAAI,IAAI,CAAC;aACb;YACD,IAAI,IAAI,UAAU,CAAC;SACnB;KACD;IACD,IAAI,IAAI,GAAG,EAAE,CAAC;IACd,IAAI,MAAM,CAAC,UAAU,EAAE;QACtB,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;YACxD,wEAAwE;YACxE,uCAAuC;YACvC,MAAM,MAAM,GAAG,CAAC,CAAC,KAAK,IAAI,KAAK,CAAC,YAAY,CAAC;YAE7C,+DAA+D;YAC/D,OAAO,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,CAAC,YAAY,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC;QAC/E,CAAC,CAAC,CAAC;KACH;IACD,OAAO,KAAK,IAAI,KAAK,IAAI,IAAI,IAAI,EAAE,CAAC;AACrC,CAAC;AAhED,kDAgEC","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/* eslint-disable import/no-deprecated */\n\nimport { assert } from \"@fluidframework/core-utils\";\nimport { AttributionKey } from \"@fluidframework/runtime-definitions\";\nimport { IAttributionCollection } from \"./attributionCollection\";\nimport { LocalClientId, UnassignedSequenceNumber, UniversalSequenceNumber } from \"./constants\";\nimport { LocalReferenceCollection } from \"./localReference\";\nimport { IMergeTreeDeltaOpArgs } from \"./mergeTreeDeltaCallback\";\nimport { TrackingGroupCollection } from \"./mergeTreeTracking\";\nimport { ICombiningOp, IJSONSegment, IMarkerDef, MergeTreeDeltaType, ReferenceType } from \"./ops\";\nimport { computeHierarchicalOrdinal } from \"./ordinal\";\nimport { PartialSequenceLengths } from \"./partialLengths\";\nimport { clone, createMap, MapLike, PropertySet } from \"./properties\";\nimport {\n\trefTypeIncludesFlag,\n\tRangeStackMap,\n\tReferencePosition,\n\trefGetRangeLabels,\n\trefGetTileLabels,\n} from \"./referencePositions\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection\";\nimport { PropertiesManager, PropertiesRollback } from \"./segmentPropertiesManager\";\n\n/**\n * Common properties for a node in a merge tree.\n * @internal\n */\nexport interface IMergeNodeCommon {\n\t/**\n\t * The index of this node in its parent's list of children.\n\t */\n\tindex: number;\n\t/**\n\t * A string that can be used for comparing the location of this node to other `MergeNode`s in the same tree.\n\t * `a.ordinal < b.ordinal` if and only if `a` comes before `b` in a pre-order traversal of the tree.\n\t */\n\tordinal: string;\n\tisLeaf(): this is ISegment;\n}\n\nexport type IMergeLeaf = ISegment & { parent?: IMergeBlock };\nexport type IMergeNode = IMergeBlock | IMergeLeaf;\n/**\n * Internal (i.e. non-leaf) node in a merge tree.\n * @internal\n */\nexport interface IMergeBlock extends IMergeNodeCommon {\n\tparent?: IMergeBlock;\n\n\tneedsScour?: boolean;\n\t/**\n\t * Number of direct children of this node\n\t */\n\tchildCount: number;\n\t/**\n\t * Array of child nodes.\n\t *\n\t * @remarks To avoid reallocation, this is always initialized to have maximum length as deemed by\n\t * the merge tree's branching factor. Use `childCount` to determine how many children this node actually has.\n\t */\n\tchildren: IMergeNode[];\n\t/**\n\t * Supports querying the total length of all descendants of this IMergeBlock from the perspective of any\n\t * (clientId, seq) within the collab window.\n\t *\n\t * @remarks This is only optional for implementation reasons (internal nodes can be created/moved without\n\t * immediately initializing the partial lengths). Aside from mid-update on tree operations, these lengths\n\t * objects are always defined.\n\t */\n\tpartialLengths?: PartialSequenceLengths;\n\t/**\n\t * The length of the contents of the node.\n\t */\n\tcachedLength: number | undefined;\n\thierBlock(): IHierBlock | undefined;\n\tassignChild(child: IMergeNode, index: number, updateOrdinal?: boolean): void;\n\tsetOrdinal(child: IMergeNode, index: number): void;\n}\n\n/**\n * @internal\n */\nexport interface IHierBlock extends IMergeBlock {\n\thierToString(indentCount: number): string;\n\trightmostTiles: MapLike<ReferencePosition>;\n\tleftmostTiles: MapLike<ReferencePosition>;\n\trangeStacks: RangeStackMap;\n}\n\n/**\n * Contains removal information associated to an {@link ISegment}.\n * @internal\n */\nexport interface IRemovalInfo {\n\t/**\n\t * Local seq at which this segment was removed, if the removal is yet-to-be acked.\n\t */\n\tlocalRemovedSeq?: number;\n\t/**\n\t * Seq at which this segment was removed.\n\t */\n\tremovedSeq: number;\n\t/**\n\t * List of client IDs that have removed this segment.\n\t * The client that actually removed the segment (i.e. whose removal op was sequenced first) is stored as the first\n\t * client in this list. Other clients in the list have all issued concurrent ops to remove the segment.\n\t * @remarks When this list has length \\> 1, this is referred to as the \"overlapping remove\" case.\n\t */\n\tremovedClientIds: number[];\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport function toRemovalInfo(maybe: Partial<IRemovalInfo> | undefined): IRemovalInfo | undefined {\n\tif (maybe?.removedClientIds !== undefined && maybe?.removedSeq !== undefined) {\n\t\treturn maybe as IRemovalInfo;\n\t}\n\tassert(\n\t\tmaybe?.removedClientIds === undefined && maybe?.removedSeq === undefined,\n\t\t0x2bf /* \"both removedClientIds and removedSeq should be set or not set\" */,\n\t);\n}\n\n/**\n * A segment representing a portion of the merge tree.\n * Segments are leaf nodes of the merge tree and contain data.\n * @internal\n */\nexport interface ISegment extends IMergeNodeCommon, Partial<IRemovalInfo> {\n\treadonly type: string;\n\treadonly segmentGroups: SegmentGroupCollection;\n\treadonly trackingCollection: TrackingGroupCollection;\n\t/**\n\t * Whether or not this segment is a special segment denoting the start or\n\t * end of the tree\n\t *\n\t * Endpoint segments are imaginary segments positioned immediately before or\n\t * after the tree. These segments cannot be referenced by regular operations\n\t * and exist primarily as a bucket for local references to slide onto during\n\t * deletion of regular segments.\n\t */\n\treadonly endpointType?: \"start\" | \"end\";\n\n\t/**\n\t * The length of the contents of the node.\n\t */\n\tcachedLength: number;\n\t/**\n\t * Stores attribution keys associated with offsets of this segment.\n\t * This data is only persisted if MergeTree's `attributions.track` flag is set to true.\n\t * Pending segments (i.e. ones that only exist locally and haven't been acked by the server) also have\n\t * `attribution === undefined` until ack.\n\t *\n\t * Keys can be used opaquely with an IAttributor or a container runtime that provides attribution.\n\t * @remarks There are plans to make the shape of the data stored extensible in a couple ways:\n\t *\n\t * 1. Injection of custom attribution information associated with the segment (ex: copy-paste of\n\t * content but keeping the old attribution information).\n\t *\n\t * 2. Storage of multiple \"channels\" of information (ex: track property changes separately from insertion,\n\t * or only attribute certain property modifications, etc.)\n\t */\n\tattribution?: IAttributionCollection<AttributionKey>;\n\n\t/**\n\t * Manages pending local state for properties on this segment.\n\t */\n\tpropertyManager?: PropertiesManager;\n\t/**\n\t * Local seq at which this segment was inserted.\n\t * This is defined if and only if the insertion of the segment is pending ack, i.e. `seq` is UnassignedSequenceNumber.\n\t * Once the segment is acked, this field is cleared.\n\t *\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\tlocalSeq?: number;\n\t/**\n\t * Local seq at which this segment was removed. If this is defined, `removedSeq` will initially be set to\n\t * UnassignedSequenceNumber. However, if another client concurrently removes the same segment, `removedSeq`\n\t * will be updated to the seq at which that client removed this segment.\n\t *\n\t * Like {@link ISegment.localSeq}, this field is cleared once the local removal of the segment is acked.\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\tlocalRemovedSeq?: number;\n\t/**\n\t * Seq at which this segment was inserted.\n\t * If undefined, it is assumed the segment was inserted prior to the collab window's minimum sequence number.\n\t */\n\tseq?: number;\n\t/**\n\t * Short clientId for the client that inserted this segment.\n\t */\n\tclientId: number;\n\t/**\n\t * Local references added to this segment.\n\t */\n\tlocalRefs?: LocalReferenceCollection;\n\t/**\n\t * Properties that have been added to this segment via annotation.\n\t */\n\tproperties?: PropertySet;\n\taddProperties(\n\t\tnewProps: PropertySet,\n\t\top?: ICombiningOp,\n\t\tseq?: number,\n\t\tcollabWindow?: CollaborationWindow,\n\t\trollback?: PropertiesRollback,\n\t): PropertySet | undefined;\n\tclone(): ISegment;\n\tcanAppend(segment: ISegment): boolean;\n\tappend(segment: ISegment): void;\n\tsplitAt(pos: number): ISegment | undefined;\n\ttoJSONObject(): any;\n\t/**\n\t * Acks the current segment against the segment group, op, and merge tree.\n\t *\n\t * @param segmentGroup - Pending segment group associated with this op.\n\t * @param opArgs - Information about the op that was acked\n\t * @returns `true` if the op modifies the segment, otherwise `false`.\n\t * The only current false case is overlapping remove, where a segment is removed\n\t * by a previously sequenced operation before the current operation is acked.\n\t * @throws - error if the segment state doesn't match segment group or op.\n\t * E.g. if the segment group is not first in the pending queue, or\n\t * an inserted segment does not have unassigned sequence number.\n\t *\n\t * @deprecated This functionality was not meant to be exported and will be removed in a future release\n\t */\n\tack(segmentGroup: SegmentGroup, opArgs: IMergeTreeDeltaOpArgs): boolean;\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface IMarkerModifiedAction {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(marker: Marker): void;\n}\n\n/**\n * @internal\n */\nexport interface ISegmentAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tsegment: ISegment,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number,\n\t\tend: number,\n\t\taccum: TClientData,\n\t): boolean;\n}\n/**\n * @internal\n */\nexport interface ISegmentChanges {\n\tnext?: ISegment;\n\treplaceCurrent?: ISegment;\n}\n/**\n * @internal\n */\nexport interface BlockAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tblock: IMergeBlock,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\taccum: TClientData,\n\t): boolean;\n}\n\n/**\n * @internal\n */\nexport interface NodeAction<TClientData> {\n\t// eslint-disable-next-line @typescript-eslint/prefer-function-type\n\t(\n\t\tnode: IMergeNode,\n\t\tpos: number,\n\t\trefSeq: number,\n\t\tclientId: number,\n\t\tstart: number | undefined,\n\t\tend: number | undefined,\n\t\tclientData: TClientData,\n\t): boolean;\n}\n/**\n * @internal\n */\nexport interface IncrementalSegmentAction<TContext> {\n\t(segment: ISegment, state: IncrementalMapState<TContext>);\n}\n\n/**\n * @internal\n */\nexport interface IncrementalBlockAction<TContext> {\n\t(state: IncrementalMapState<TContext>);\n}\n/**\n * @internal\n * */\nexport interface BlockUpdateActions {\n\tchild: (block: IMergeBlock, index: number) => void;\n}\n\n/**\n * @internal\n */\nexport interface InsertContext {\n\tcandidateSegment?: ISegment;\n\tprepareEvents?: boolean;\n\tstructureChange?: boolean;\n\tleaf: (segment: ISegment | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: IMergeBlock) => boolean;\n}\n\n/**\n * @internal\n */\nexport interface SegmentActions<TClientData> {\n\tleaf?: ISegmentAction<TClientData>;\n\tshift?: NodeAction<TClientData>;\n\tcontains?: NodeAction<TClientData>;\n\tpre?: BlockAction<TClientData>;\n\tpost?: BlockAction<TClientData>;\n}\n/**\n * @internal\n */\nexport interface IncrementalSegmentActions<TContext> {\n\tleaf: IncrementalSegmentAction<TContext>;\n\tpre?: IncrementalBlockAction<TContext>;\n\tpost?: IncrementalBlockAction<TContext>;\n}\n\n/**\n * @internal\n */\nexport interface SearchResult {\n\ttext: string;\n\tpos: number;\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface SegmentGroup {\n\tsegments: ISegment[];\n\tpreviousProps?: PropertySet[];\n\tlocalSeq: number;\n\trefSeq: number;\n}\n\n/**\n * @internal\n */\nexport class MergeNode implements IMergeNodeCommon {\n\tindex: number = 0;\n\tordinal: string = \"\";\n\tcachedLength: number = 0;\n\n\tisLeaf(): this is ISegment {\n\t\treturn false;\n\t}\n}\n\n/**\n * Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because\n * the MergeTree always inserts first, then checks for overflow and splits if the child count equals\n * `MaxNodesInBlock`. (i.e., `MaxNodesInBlock` contains 1 extra slot for temporary storage to\n * facilitate splits.)\n * @internal\n */\nexport const MaxNodesInBlock = 8;\n/**\n * @internal\n */\nexport class MergeBlock extends MergeNode implements IMergeBlock {\n\tparent?: IMergeBlock;\n\tpublic children: IMergeNode[];\n\tpublic constructor(public childCount: number) {\n\t\tsuper();\n\t\tthis.children = new Array<IMergeNode>(MaxNodesInBlock);\n\t}\n\n\tpublic hierBlock(): IHierBlock | undefined {\n\t\treturn undefined;\n\t}\n\n\tpublic setOrdinal(child: IMergeNode, index: number) {\n\t\tconst childCount = this.childCount;\n\t\tassert(\n\t\t\tchildCount >= 1 && childCount <= MaxNodesInBlock,\n\t\t\t0x040 /* \"Child count is not within [1,8] range!\" */,\n\t\t);\n\t\tchild.ordinal = computeHierarchicalOrdinal(\n\t\t\tMaxNodesInBlock,\n\t\t\tchildCount,\n\t\t\tthis.ordinal,\n\t\t\tindex === 0 ? undefined : this.children[index - 1]?.ordinal,\n\t\t);\n\t}\n\n\tpublic assignChild(child: IMergeNode, index: number, updateOrdinal = true) {\n\t\tchild.parent = this;\n\t\tchild.index = index;\n\t\tif (updateOrdinal) {\n\t\t\tthis.setOrdinal(child, index);\n\t\t}\n\t\tthis.children[index] = child;\n\t}\n}\n\nexport function seqLTE(seq: number, minOrRefSeq: number) {\n\treturn seq !== UnassignedSequenceNumber && seq <= minOrRefSeq;\n}\n\n/**\n * @internal\n */\nexport abstract class BaseSegment extends MergeNode implements ISegment {\n\tpublic clientId: number = LocalClientId;\n\tpublic seq: number = UniversalSequenceNumber;\n\tpublic removedSeq?: number;\n\tpublic removedClientIds?: number[];\n\tpublic readonly segmentGroups: SegmentGroupCollection = new SegmentGroupCollection(this);\n\tpublic readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(this);\n\t/***/\n\tpublic attribution?: IAttributionCollection<AttributionKey>;\n\tpublic propertyManager?: PropertiesManager;\n\tpublic properties?: PropertySet;\n\tpublic localRefs?: LocalReferenceCollection;\n\tpublic abstract readonly type: string;\n\tpublic localSeq?: number;\n\tpublic localRemovedSeq?: number;\n\n\tpublic addProperties(\n\t\tnewProps: PropertySet,\n\t\top?: ICombiningOp,\n\t\tseq?: number,\n\t\tcollabWindow?: CollaborationWindow,\n\t\trollback: PropertiesRollback = PropertiesRollback.None,\n\t) {\n\t\tthis.propertyManager ??= new PropertiesManager();\n\t\tthis.properties ??= createMap<any>();\n\t\treturn this.propertyManager.addProperties(\n\t\t\tthis.properties,\n\t\t\tnewProps,\n\t\t\top,\n\t\t\tseq,\n\t\t\tcollabWindow && collabWindow.collaborating,\n\t\t\trollback,\n\t\t);\n\t}\n\n\tpublic hasProperty(key: string): boolean {\n\t\treturn !!this.properties && this.properties[key] !== undefined;\n\t}\n\n\tpublic isLeaf() {\n\t\treturn true;\n\t}\n\n\tprotected cloneInto(b: ISegment) {\n\t\tb.clientId = this.clientId;\n\t\t// TODO: deep clone properties\n\t\tb.properties = clone(this.properties);\n\t\tb.removedClientIds = this.removedClientIds?.slice();\n\t\t// TODO: copy removed client overlap and branch removal info\n\t\tb.removedSeq = this.removedSeq;\n\t\tb.seq = this.seq;\n\t\tb.attribution = this.attribution?.clone();\n\t}\n\n\tpublic canAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tprotected addSerializedProps(jseg: IJSONSegment) {\n\t\tif (this.properties) {\n\t\t\tjseg.props = this.properties;\n\t\t}\n\t}\n\n\tpublic abstract toJSONObject(): any;\n\n\t/**\n\t * @deprecated This functionality was not meant to be exported and will be removed in a future release\n\t */\n\tpublic ack(segmentGroup: SegmentGroup, opArgs: IMergeTreeDeltaOpArgs): boolean {\n\t\tconst currentSegmentGroup = this.segmentGroups.dequeue();\n\t\tassert(\n\t\t\tcurrentSegmentGroup === segmentGroup,\n\t\t\t0x043 /* \"On ack, unexpected segmentGroup!\" */,\n\t\t);\n\t\tswitch (opArgs.op.type) {\n\t\t\tcase MergeTreeDeltaType.ANNOTATE:\n\t\t\t\tassert(\n\t\t\t\t\t!!this.propertyManager,\n\t\t\t\t\t0x044 /* \"On annotate ack, missing segment property manager!\" */,\n\t\t\t\t);\n\t\t\t\tthis.propertyManager.ackPendingProperties(opArgs.op);\n\t\t\t\treturn true;\n\n\t\t\tcase MergeTreeDeltaType.INSERT:\n\t\t\t\tassert(\n\t\t\t\t\tthis.seq === UnassignedSequenceNumber,\n\t\t\t\t\t0x045 /* \"On insert, seq number already assigned!\" */,\n\t\t\t\t);\n\t\t\t\tthis.seq = opArgs.sequencedMessage!.sequenceNumber;\n\t\t\t\tthis.localSeq = undefined;\n\t\t\t\treturn true;\n\n\t\t\tcase MergeTreeDeltaType.REMOVE:\n\t\t\t\tconst removalInfo: IRemovalInfo | undefined = toRemovalInfo(this);\n\t\t\t\tassert(\n\t\t\t\t\tremovalInfo !== undefined,\n\t\t\t\t\t0x046 /* \"On remove ack, missing removal info!\" */,\n\t\t\t\t);\n\t\t\t\tthis.localRemovedSeq = undefined;\n\t\t\t\tif (removalInfo.removedSeq === UnassignedSequenceNumber) {\n\t\t\t\t\tremovalInfo.removedSeq = opArgs.sequencedMessage!.sequenceNumber;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`${opArgs.op.type} is in unrecognized operation type`);\n\t\t}\n\t}\n\n\tpublic splitAt(pos: number): ISegment | undefined {\n\t\tif (pos > 0) {\n\t\t\tconst leafSegment: IMergeLeaf | undefined = this.createSplitSegmentAt(pos);\n\t\t\tif (leafSegment) {\n\t\t\t\tthis.copyPropertiesTo(leafSegment);\n\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\t\t\tconst thisAsMergeSegment: IMergeLeaf = this;\n\t\t\t\tleafSegment.parent = thisAsMergeSegment.parent;\n\n\t\t\t\t// Give the leaf a temporary yet valid ordinal.\n\t\t\t\t// when this segment is put in the tree, it will get its real ordinal,\n\t\t\t\t// but this ordinal meets all the necessary invariants for now.\n\t\t\t\tleafSegment.ordinal = this.ordinal + String.fromCharCode(0);\n\n\t\t\t\tleafSegment.removedClientIds = this.removedClientIds?.slice();\n\t\t\t\tleafSegment.removedSeq = this.removedSeq;\n\t\t\t\tleafSegment.localRemovedSeq = this.localRemovedSeq;\n\t\t\t\tleafSegment.seq = this.seq;\n\t\t\t\tleafSegment.localSeq = this.localSeq;\n\t\t\t\tleafSegment.clientId = this.clientId;\n\t\t\t\tthis.segmentGroups.copyTo(leafSegment);\n\t\t\t\tthis.trackingCollection.copyTo(leafSegment);\n\t\t\t\tif (this.localRefs) {\n\t\t\t\t\tthis.localRefs.split(pos, leafSegment);\n\t\t\t\t}\n\t\t\t\tif (this.attribution) {\n\t\t\t\t\tleafSegment.attribution = this.attribution.splitAt(pos);\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn leafSegment;\n\t\t}\n\t}\n\n\tprivate copyPropertiesTo(other: ISegment) {\n\t\tif (this.propertyManager) {\n\t\t\tif (this.properties) {\n\t\t\t\tother.propertyManager = new PropertiesManager();\n\t\t\t\tother.properties = this.propertyManager.copyTo(\n\t\t\t\t\tthis.properties,\n\t\t\t\t\tother.properties,\n\t\t\t\t\tother.propertyManager,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic abstract clone(): ISegment;\n\n\tpublic append(other: ISegment): void {\n\t\t// Note: Must call 'appendLocalRefs' before modifying this segment's length as\n\t\t// 'this.cachedLength' is used to adjust the offsets of the local refs.\n\t\tLocalReferenceCollection.append(this, other);\n\t\tif (this.attribution) {\n\t\t\tassert(\n\t\t\t\tother.attribution !== undefined,\n\t\t\t\t0x4bd /* attribution should be set on appendee */,\n\t\t\t);\n\t\t\tthis.attribution.append(other.attribution);\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tother.attribution === undefined,\n\t\t\t\t0x4be /* attribution should not be set on appendee */,\n\t\t\t);\n\t\t}\n\n\t\tthis.cachedLength ??= 0;\n\t\tthis.cachedLength += other.cachedLength;\n\t}\n\n\tprotected abstract createSplitSegmentAt(pos: number): BaseSegment | undefined;\n}\n\n/**\n * @internal\n */\nexport const reservedMarkerIdKey = \"markerId\";\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @internal\n */\nexport interface IJSONMarkerSegment extends IJSONSegment {\n\tmarker: IMarkerDef;\n}\n\n/**\n * @internal\n */\nexport class Marker extends BaseSegment implements ReferencePosition {\n\tpublic static readonly type = \"Marker\";\n\tpublic static is(segment: ISegment): segment is Marker {\n\t\treturn segment.type === Marker.type;\n\t}\n\tpublic readonly type = Marker.type;\n\n\tpublic static make(refType: ReferenceType, props?: PropertySet) {\n\t\tconst marker = new Marker(refType);\n\t\tif (props) {\n\t\t\tmarker.addProperties(props);\n\t\t}\n\t\treturn marker;\n\t}\n\n\tconstructor(public refType: ReferenceType) {\n\t\tsuper();\n\t\tthis.cachedLength = 1;\n\t}\n\n\ttoJSONObject() {\n\t\tconst obj: IJSONMarkerSegment = { marker: { refType: this.refType } };\n\t\tsuper.addSerializedProps(obj);\n\t\treturn obj;\n\t}\n\n\tstatic fromJSONObject(spec: any) {\n\t\tif (spec && typeof spec === \"object\" && \"marker\" in spec) {\n\t\t\treturn Marker.make(spec.marker.refType, spec.props as PropertySet);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tclone() {\n\t\tconst b = Marker.make(this.refType, this.properties);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tgetSegment() {\n\t\treturn this;\n\t}\n\n\tgetOffset() {\n\t\treturn 0;\n\t}\n\n\thasSimpleType(simpleTypeName: string) {\n\t\treturn !!this.properties && this.properties[reservedMarkerSimpleTypeKey] === simpleTypeName;\n\t}\n\n\tgetProperties() {\n\t\treturn this.properties;\n\t}\n\n\tgetId(): string | undefined {\n\t\treturn this.properties?.[reservedMarkerIdKey] as string;\n\t}\n\n\ttoString() {\n\t\treturn `M${this.getId()}`;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number) {\n\t\treturn undefined;\n\t}\n\n\tcanAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tappend() {\n\t\tthrow new Error(\"Can not append to marker\");\n\t}\n}\n/**\n * @internal\n */\nexport enum IncrementalExecOp {\n\tGo,\n\tStop,\n\tYield,\n}\n/**\n * @internal\n */\nexport class IncrementalMapState<TContext> {\n\top = IncrementalExecOp.Go;\n\tconstructor(\n\t\tpublic block: IMergeBlock,\n\t\tpublic actions: IncrementalSegmentActions<TContext>,\n\t\tpublic pos: number,\n\t\tpublic refSeq: number,\n\t\tpublic clientId: number,\n\t\tpublic context: TContext,\n\t\tpublic start: number,\n\t\tpublic end: number,\n\t\tpublic childIndex = 0,\n\t) {}\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport class CollaborationWindow {\n\tclientId = LocalClientId;\n\tcollaborating = false;\n\n\t/**\n\t * Lowest-numbered segment in window; no client can reference a state before this one\n\t */\n\tminSeq = 0;\n\t/**\n\t * Highest-numbered segment in window and current reference sequence number for this client.\n\t */\n\tcurrentSeq = 0;\n\n\t/**\n\t * Highest-numbered localSeq used for a pending segment.\n\t * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:\n\t * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.\n\t *\n\t * @remarks - This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree\n\t * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.\n\t *\n\t * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from\n\t * the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.\n\t *\n\t * For example, imagine a client with initial state \"123456\" submits some ops to create the text \"123456ABC\".\n\t * If they insert the \"C\" first, then \"B\", then \"A\", their local segment state might look like this:\n\t * ```js\n\t * [\n\t * { seq: 0, text: \"1234\" },\n\t * { seq: 5, text: \"56\" },\n\t * { localSeq: 3, seq: UnassignedSequenceNumber, text: \"A\" },\n\t * { localSeq: 2, seq: UnassignedSequenceNumber, text: \"B\" },\n\t * { localSeq: 1, seq: UnassignedSequenceNumber, text: \"C\" },\n\t * ]\n\t * ```\n\t * (note that {@link ISegment.localSeq} tracks the localSeq at which a segment was inserted)\n\t *\n\t * Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate\n\t * that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.\n\t *\n\t * It will generate the ops\n\t * 1. \\{ pos: 6, text: \"C\" \\}\n\t * 2. \\{ pos: 6, text: \"B\" \\}\n\t * 3. \\{ pos: 6, text: \"A\" \\}\n\t *\n\t * since when submitting the first op, remote clients don't know that this client is about to submit the \"A\" and \"B\".\n\t *\n\t * On the other hand, imagine if the client had originally submitted the ops in the order \"A\", \"B\", \"C\"\n\t * such that the segments' local state was instead:\n\t *\n\t * ```js\n\t * [\n\t * { seq: 0, text: \"1234\" },\n\t * { seq: 5, text: \"56\" },\n\t * { localSeq: 1, seq: UnassignedSequenceNumber, text: \"A\" },\n\t * { localSeq: 2, seq: UnassignedSequenceNumber, text: \"B\" },\n\t * { localSeq: 3, seq: UnassignedSequenceNumber, text: \"C\" },\n\t * ]\n\t * ```\n\t *\n\t * The resubmitted ops should instead be:\n\t * 1. \\{ pos: 6, text: \"A\" \\}\n\t * 2. \\{ pos: 7, text: \"B\" \\}\n\t * 3. \\{ pos: 8, text: \"C\" \\}\n\t *\n\t * since remote clients will have seen the \"A\" when processing the \"B\" as well as both the \"A\" and \"B\" when processing the \"C\".\n\t * As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing\n\t * in `localSeq`.\n\t *\n\t * This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client\n\t * was disconnected, the resubmitted ops end up matching the original ops exactly.\n\t * However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked\n\t * and local information as appropriate.\n\t * Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible\n\t * from a given (seq, localSeq) perspective.\n\t */\n\tlocalSeq = 0;\n\n\tloadFrom(a: CollaborationWindow) {\n\t\tthis.clientId = a.clientId;\n\t\tthis.collaborating = a.collaborating;\n\t\tthis.minSeq = a.minSeq;\n\t\tthis.currentSeq = a.currentSeq;\n\t}\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport const compareNumbers = (a: number, b: number) => a - b;\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport const compareStrings = (a: string, b: string) => a.localeCompare(b);\n\nconst indentStrings = [\"\", \" \", \" \"];\n/**\n * @deprecated This functionality is deprecated and will be removed in a future release.\n * @internal\n */\nexport function internedSpaces(n: number) {\n\tif (indentStrings[n] === undefined) {\n\t\tindentStrings[n] = \"\";\n\t\tfor (let i = 0; i < n; i++) {\n\t\t\tindentStrings[n] += \" \";\n\t\t}\n\t}\n\treturn indentStrings[n];\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface IConsensusInfo {\n\tmarker: Marker;\n\tcallback: (m: Marker) => void;\n}\n\n/**\n * @deprecated This functionality was not meant to be exported and will be removed in a future release\n * @internal\n */\nexport interface SegmentAccumulator {\n\tsegments: ISegment[];\n}\n/**\n * @internal\n */\nexport interface MinListener {\n\tminRequired: number;\n\tonMinGE(minSeq: number): void;\n}\n\n/**\n * @internal\n */\nexport function debugMarkerToString(marker: Marker): string {\n\tlet bbuf = \"\";\n\tif (refTypeIncludesFlag(marker, ReferenceType.Tile)) {\n\t\tbbuf += \"Tile\";\n\t}\n\tif (refTypeIncludesFlag(marker, ReferenceType.NestBegin)) {\n\t\tif (bbuf.length > 0) {\n\t\t\tbbuf += \"; \";\n\t\t}\n\t\tbbuf += \"RangeBegin\";\n\t}\n\tif (refTypeIncludesFlag(marker, ReferenceType.NestEnd)) {\n\t\tif (bbuf.length > 0) {\n\t\t\tbbuf += \"; \";\n\t\t}\n\t\tbbuf += \"RangeEnd\";\n\t}\n\tlet lbuf = \"\";\n\tconst id = marker.getId();\n\tif (id) {\n\t\tbbuf += ` (${id}) `;\n\t}\n\tconst tileLabels = refGetTileLabels(marker);\n\tif (tileLabels) {\n\t\tlbuf += \"tile -- \";\n\t\tfor (let i = 0, len = tileLabels.length; i < len; i++) {\n\t\t\tconst tileLabel = tileLabels[i];\n\t\t\tif (i > 0) {\n\t\t\t\tlbuf += \"; \";\n\t\t\t}\n\t\t\tlbuf += tileLabel;\n\t\t}\n\t}\n\tconst rangeLabels = refGetRangeLabels(marker);\n\tif (rangeLabels) {\n\t\tlet rangeKind = \"begin\";\n\t\tif (refTypeIncludesFlag(marker, ReferenceType.NestEnd)) {\n\t\t\trangeKind = \"end\";\n\t\t}\n\t\tif (tileLabels) {\n\t\t\tlbuf += \" \";\n\t\t}\n\t\tlbuf += `range ${rangeKind} -- `;\n\t\tconst labels = rangeLabels;\n\t\tfor (let i = 0, len = labels.length; i < len; i++) {\n\t\t\tconst rangeLabel = labels[i];\n\t\t\tif (i > 0) {\n\t\t\t\tlbuf += \"; \";\n\t\t\t}\n\t\t\tlbuf += rangeLabel;\n\t\t}\n\t}\n\tlet pbuf = \"\";\n\tif (marker.properties) {\n\t\tpbuf += JSON.stringify(marker.properties, (key, value) => {\n\t\t\t// Avoid circular reference when stringifying makers containing handles.\n\t\t\t// (Substitute a debug string instead.)\n\t\t\tconst handle = !!value && value.IFluidHandle;\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-return\n\t\t\treturn handle ? `#Handle(${handle.routeContext.path}/${handle.path})` : value;\n\t\t});\n\t}\n\treturn `M ${bbuf}: ${lbuf} ${pbuf}`;\n}\n"]}
|