@fluidframework/merge-tree 2.20.0 → 2.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. package/.eslintrc.cjs +0 -1
  2. package/CHANGELOG.md +8 -0
  3. package/README.md +1 -0
  4. package/dist/attributionCollection.js +5 -7
  5. package/dist/attributionCollection.js.map +1 -1
  6. package/dist/localReference.js +6 -8
  7. package/dist/localReference.js.map +1 -1
  8. package/dist/mergeTree.d.ts.map +1 -1
  9. package/dist/mergeTree.js +69 -34
  10. package/dist/mergeTree.js.map +1 -1
  11. package/dist/mergeTreeNodes.d.ts +15 -4
  12. package/dist/mergeTreeNodes.d.ts.map +1 -1
  13. package/dist/mergeTreeNodes.js +1 -1
  14. package/dist/mergeTreeNodes.js.map +1 -1
  15. package/dist/partialLengths.d.ts +114 -144
  16. package/dist/partialLengths.d.ts.map +1 -1
  17. package/dist/partialLengths.js +431 -525
  18. package/dist/partialLengths.js.map +1 -1
  19. package/dist/perspective.d.ts +10 -1
  20. package/dist/perspective.d.ts.map +1 -1
  21. package/dist/perspective.js +10 -1
  22. package/dist/perspective.js.map +1 -1
  23. package/dist/properties.d.ts.map +1 -1
  24. package/dist/properties.js +2 -3
  25. package/dist/properties.js.map +1 -1
  26. package/dist/revertibles.js +3 -3
  27. package/dist/revertibles.js.map +1 -1
  28. package/dist/segmentInfos.d.ts +3 -0
  29. package/dist/segmentInfos.d.ts.map +1 -1
  30. package/dist/segmentInfos.js.map +1 -1
  31. package/dist/segmentPropertiesManager.js +3 -3
  32. package/dist/segmentPropertiesManager.js.map +1 -1
  33. package/dist/snapshotLoader.js +2 -2
  34. package/dist/snapshotLoader.js.map +1 -1
  35. package/dist/sortedSegmentSet.d.ts +5 -3
  36. package/dist/sortedSegmentSet.d.ts.map +1 -1
  37. package/dist/sortedSegmentSet.js +33 -41
  38. package/dist/sortedSegmentSet.js.map +1 -1
  39. package/dist/sortedSet.d.ts +20 -3
  40. package/dist/sortedSet.d.ts.map +1 -1
  41. package/dist/sortedSet.js +23 -14
  42. package/dist/sortedSet.js.map +1 -1
  43. package/dist/test/Snapshot.perf.spec.js +1 -1
  44. package/dist/test/Snapshot.perf.spec.js.map +1 -1
  45. package/dist/test/client.applyMsg.spec.js +20 -0
  46. package/dist/test/client.applyMsg.spec.js.map +1 -1
  47. package/dist/test/client.applyStashedOpFarm.spec.js +1 -1
  48. package/dist/test/client.applyStashedOpFarm.spec.js.map +1 -1
  49. package/dist/test/client.attributionFarm.spec.js +1 -1
  50. package/dist/test/client.attributionFarm.spec.js.map +1 -1
  51. package/dist/test/client.localReference.spec.js +48 -0
  52. package/dist/test/client.localReference.spec.js.map +1 -1
  53. package/dist/test/client.obliterateFarm.spec.d.ts +12 -0
  54. package/dist/test/client.obliterateFarm.spec.d.ts.map +1 -0
  55. package/dist/test/client.obliterateFarm.spec.js +89 -0
  56. package/dist/test/client.obliterateFarm.spec.js.map +1 -0
  57. package/dist/test/client.reconnectFarm.spec.js +1 -1
  58. package/dist/test/client.reconnectFarm.spec.js.map +1 -1
  59. package/dist/test/client.searchForMarker.spec.js +2 -2
  60. package/dist/test/client.searchForMarker.spec.js.map +1 -1
  61. package/dist/test/mergeTreeOperationRunner.d.ts +7 -2
  62. package/dist/test/mergeTreeOperationRunner.d.ts.map +1 -1
  63. package/dist/test/mergeTreeOperationRunner.js +31 -14
  64. package/dist/test/mergeTreeOperationRunner.js.map +1 -1
  65. package/dist/test/obliterate.concurrent.spec.js +45 -1
  66. package/dist/test/obliterate.concurrent.spec.js.map +1 -1
  67. package/dist/test/obliterate.rangeExpansion.spec.js +81 -5
  68. package/dist/test/obliterate.rangeExpansion.spec.js.map +1 -1
  69. package/dist/test/obliterate.spec.js +3 -3
  70. package/dist/test/obliterate.spec.js.map +1 -1
  71. package/dist/test/obliterateOperations.d.ts +15 -0
  72. package/dist/test/obliterateOperations.d.ts.map +1 -0
  73. package/dist/test/obliterateOperations.js +132 -0
  74. package/dist/test/obliterateOperations.js.map +1 -0
  75. package/dist/test/partialSyncHelper.d.ts +42 -0
  76. package/dist/test/partialSyncHelper.d.ts.map +1 -0
  77. package/dist/test/partialSyncHelper.js +96 -0
  78. package/dist/test/partialSyncHelper.js.map +1 -0
  79. package/dist/test/revertibles.spec.js +3 -3
  80. package/dist/test/revertibles.spec.js.map +1 -1
  81. package/dist/test/sortedSegmentSet.spec.js +21 -0
  82. package/dist/test/sortedSegmentSet.spec.js.map +1 -1
  83. package/dist/test/testClient.d.ts +1 -1
  84. package/dist/test/testClient.d.ts.map +1 -1
  85. package/dist/test/testClient.js +1 -0
  86. package/dist/test/testClient.js.map +1 -1
  87. package/dist/test/testUtils.js +2 -2
  88. package/dist/test/testUtils.js.map +1 -1
  89. package/lib/attributionCollection.js +5 -7
  90. package/lib/attributionCollection.js.map +1 -1
  91. package/lib/localReference.js +6 -8
  92. package/lib/localReference.js.map +1 -1
  93. package/lib/mergeTree.d.ts.map +1 -1
  94. package/lib/mergeTree.js +69 -34
  95. package/lib/mergeTree.js.map +1 -1
  96. package/lib/mergeTreeNodes.d.ts +15 -4
  97. package/lib/mergeTreeNodes.d.ts.map +1 -1
  98. package/lib/mergeTreeNodes.js +1 -1
  99. package/lib/mergeTreeNodes.js.map +1 -1
  100. package/lib/partialLengths.d.ts +114 -144
  101. package/lib/partialLengths.d.ts.map +1 -1
  102. package/lib/partialLengths.js +432 -525
  103. package/lib/partialLengths.js.map +1 -1
  104. package/lib/perspective.d.ts +10 -1
  105. package/lib/perspective.d.ts.map +1 -1
  106. package/lib/perspective.js +10 -1
  107. package/lib/perspective.js.map +1 -1
  108. package/lib/properties.d.ts.map +1 -1
  109. package/lib/properties.js +2 -3
  110. package/lib/properties.js.map +1 -1
  111. package/lib/revertibles.js +3 -3
  112. package/lib/revertibles.js.map +1 -1
  113. package/lib/segmentInfos.d.ts +3 -0
  114. package/lib/segmentInfos.d.ts.map +1 -1
  115. package/lib/segmentInfos.js.map +1 -1
  116. package/lib/segmentPropertiesManager.js +3 -3
  117. package/lib/segmentPropertiesManager.js.map +1 -1
  118. package/lib/snapshotLoader.js +2 -2
  119. package/lib/snapshotLoader.js.map +1 -1
  120. package/lib/sortedSegmentSet.d.ts +5 -3
  121. package/lib/sortedSegmentSet.d.ts.map +1 -1
  122. package/lib/sortedSegmentSet.js +33 -41
  123. package/lib/sortedSegmentSet.js.map +1 -1
  124. package/lib/sortedSet.d.ts +20 -3
  125. package/lib/sortedSet.d.ts.map +1 -1
  126. package/lib/sortedSet.js +23 -14
  127. package/lib/sortedSet.js.map +1 -1
  128. package/lib/test/Snapshot.perf.spec.js +1 -1
  129. package/lib/test/Snapshot.perf.spec.js.map +1 -1
  130. package/lib/test/client.applyMsg.spec.js +20 -0
  131. package/lib/test/client.applyMsg.spec.js.map +1 -1
  132. package/lib/test/client.applyStashedOpFarm.spec.js +1 -1
  133. package/lib/test/client.applyStashedOpFarm.spec.js.map +1 -1
  134. package/lib/test/client.attributionFarm.spec.js +1 -1
  135. package/lib/test/client.attributionFarm.spec.js.map +1 -1
  136. package/lib/test/client.localReference.spec.js +48 -0
  137. package/lib/test/client.localReference.spec.js.map +1 -1
  138. package/lib/test/client.obliterateFarm.spec.d.ts +12 -0
  139. package/lib/test/client.obliterateFarm.spec.d.ts.map +1 -0
  140. package/lib/test/client.obliterateFarm.spec.js +88 -0
  141. package/lib/test/client.obliterateFarm.spec.js.map +1 -0
  142. package/lib/test/client.reconnectFarm.spec.js +1 -1
  143. package/lib/test/client.reconnectFarm.spec.js.map +1 -1
  144. package/lib/test/client.searchForMarker.spec.js +2 -2
  145. package/lib/test/client.searchForMarker.spec.js.map +1 -1
  146. package/lib/test/mergeTreeOperationRunner.d.ts +7 -2
  147. package/lib/test/mergeTreeOperationRunner.d.ts.map +1 -1
  148. package/lib/test/mergeTreeOperationRunner.js +31 -14
  149. package/lib/test/mergeTreeOperationRunner.js.map +1 -1
  150. package/lib/test/obliterate.concurrent.spec.js +45 -1
  151. package/lib/test/obliterate.concurrent.spec.js.map +1 -1
  152. package/lib/test/obliterate.rangeExpansion.spec.js +81 -5
  153. package/lib/test/obliterate.rangeExpansion.spec.js.map +1 -1
  154. package/lib/test/obliterate.spec.js +3 -3
  155. package/lib/test/obliterate.spec.js.map +1 -1
  156. package/lib/test/obliterateOperations.d.ts +15 -0
  157. package/lib/test/obliterateOperations.d.ts.map +1 -0
  158. package/lib/test/obliterateOperations.js +123 -0
  159. package/lib/test/obliterateOperations.js.map +1 -0
  160. package/lib/test/partialSyncHelper.d.ts +42 -0
  161. package/lib/test/partialSyncHelper.d.ts.map +1 -0
  162. package/lib/test/partialSyncHelper.js +92 -0
  163. package/lib/test/partialSyncHelper.js.map +1 -0
  164. package/lib/test/revertibles.spec.js +3 -3
  165. package/lib/test/revertibles.spec.js.map +1 -1
  166. package/lib/test/sortedSegmentSet.spec.js +21 -0
  167. package/lib/test/sortedSegmentSet.spec.js.map +1 -1
  168. package/lib/test/testClient.d.ts +1 -1
  169. package/lib/test/testClient.d.ts.map +1 -1
  170. package/lib/test/testClient.js +1 -0
  171. package/lib/test/testClient.js.map +1 -1
  172. package/lib/test/testUtils.js +2 -2
  173. package/lib/test/testUtils.js.map +1 -1
  174. package/package.json +21 -79
  175. package/src/mergeTree.ts +80 -28
  176. package/src/mergeTreeNodes.ts +15 -4
  177. package/src/partialLengths.ts +559 -776
  178. package/src/perspective.ts +10 -1
  179. package/src/properties.ts +2 -3
  180. package/src/segmentInfos.ts +3 -0
  181. package/src/snapshotLoader.ts +1 -1
  182. package/src/sortedSegmentSet.ts +41 -50
  183. package/src/sortedSet.ts +32 -16
@@ -54,11 +54,22 @@ export interface ISegmentPrivate extends ISegmentInternal {
54
54
  segmentGroups?: SegmentGroupCollection;
55
55
  propertyManager?: PropertiesManager;
56
56
  /**
57
- * If a segment is inserted into an obliterated range,
58
- * but the newest obliteration of that range was by the inserting client,
59
- * then the segment is not obliterated because it is aware of the latest obliteration.
57
+ * Populated iff this segment was inserted into a range affected by concurrent obliterates at the time of its insertion.
58
+ * Contains information about the 'most recent' (i.e. 'winning' in the sense below) obliterate.
59
+ *
60
+ * BEWARE: We have opted for a certain form of last-write wins (LWW) semantics for obliterates:
61
+ * the client which last obliterated a range is considered to have "won ownership" of that range and may insert into it
62
+ * without that insertion being obliterated by other clients' concurrent obliterates.
63
+ *
64
+ * Therefore, this field can be populated even if the segment has not been obliterated (i.e. is still visible).
65
+ * This happens precisely when the segment was inserted by the same client that 'won' the obliterate (in a scenario where
66
+ * a client first issues a sided obliterate impacting a range, then inserts into that range before the server has acked the obliterate).
67
+ *
68
+ * See the test case "obliterate with mismatched final states" for an example of such a scenario.
69
+ *
70
+ * TODO:AB#29553: This property is not persisted in the summary, but it should be.
60
71
  */
61
- prevObliterateByInserter?: ObliterateInfo;
72
+ obliteratePrecedingInsertion?: ObliterateInfo;
62
73
  }
63
74
  /**
64
75
  * Segment leafs are segments that have both IMergeNodeInfo and IInsertionInfo. This means they
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeNodes.d.ts","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAE9E,OAAO,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAEpE,OAAO,EAAE,wBAAwB,EAAE,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEnE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EAAE,WAAW,EAAoB,KAAK,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,C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AoB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS;IAItD,SAAS,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIrC,MAAM,IAAI,IAAI;CAGd;AAED;;;;;GAKG;AACH,qBAAa,mBAAmB;IAC/B,QAAQ,SAAiB;IACzB,aAAa,UAAS;IAEtB;;OAEG;IACH,MAAM,SAAK;IACX;;OAEG;IACH,UAAU,SAAK;IAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8DG;IACH,QAAQ,SAAK;IAEb,QAAQ,CAAC,CAAC,EAAE,mBAAmB,GAAG,IAAI;CAMtC;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,MAAO,MAAM,KAAK,MAAM,KAAG,MAAe,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,cAAc,MAAO,MAAM,KAAK,MAAM,KAAG,MAA4B,CAAC"}
@@ -205,7 +205,7 @@ class BaseSegment {
205
205
  else {
206
206
  (0, internal_1.assert)(other.attribution === undefined, 0x4be /* attribution should not be set on appendee */);
207
207
  }
208
- this.cachedLength ?? (this.cachedLength = 0);
208
+ this.cachedLength ??= 0;
209
209
  this.cachedLength += other.cachedLength;
210
210
  }
211
211
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,iDAAyE;AACzE,2DAA4F;AAC5F,iEAAiE;AAEjE,6CAA0D;AAE1D,mDAA8E;AAG9E,uDAY2B;AA6D3B;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAA+B,EAAE,CAClF,IAAA,4BAAU,EAAC,WAAW,CAAC,IAAI,IAAA,iCAAW,EAAC,WAAW,CAAC,CAAC;AADxC,QAAA,aAAa,iBAC2B;AAErD;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EA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AACI,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAAtE,QAAA,cAAc,kBAAwD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { AttributionKey } from \"@fluidframework/runtime-definitions/internal\";\n\nimport { IAttributionCollection } from \"./attributionCollection.js\";\nimport { LocalClientId, UnassignedSequenceNumber } from \"./constants.js\";\nimport { LocalReferenceCollection, type LocalReferencePosition } from \"./localReference.js\";\nimport { TrackingGroupCollection } from \"./mergeTreeTracking.js\";\nimport { IJSONSegment, IMarkerDef, ReferenceType } from \"./ops.js\";\nimport { computeHierarchicalOrdinal } from \"./ordinal.js\";\nimport type { PartialSequenceLengths } from \"./partialLengths.js\";\nimport { PropertySet, clone, createMap, type MapLike } from \"./properties.js\";\nimport { ReferencePosition } from \"./referencePositions.js\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\thasProp,\n\tisInserted,\n\tisMergeNodeInfo as isMergeNode,\n\tisMoved,\n\tisRemoved,\n\toverwriteInfo,\n\ttype IInsertionInfo,\n\ttype IMergeNodeInfo,\n\ttype IMoveInfo,\n\ttype IRemovalInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport { PropertiesManager } from \"./segmentPropertiesManager.js\";\n\n/**\n * This interface exposes internal things to dds that leverage merge tree,\n * like sequence and matrix.\n *\n * We use tiered interface to control visibility of segment properties.\n * This sits between ISegment and ISegmentPrivate. It should only expose\n * things tagged internal.\n *\n * Everything added here beyond ISegment should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * @internal\n */\nexport interface ISegmentInternal extends ISegment {\n\tlocalRefs?: LocalReferenceCollection;\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\n/**\n * We use tiered interface to control visibility of segment properties.\n * This is the lowest interface and is not exported, it site below ISegment and ISegmentInternal.\n * It should only expose unexported things.\n *\n * Everything added here beyond ISegmentInternal should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * someday we may split tree leaves from segments, but for now they are the same\n * this is just a convenience type that makes it clear that we need something that is both a segment and a leaf node\n */\nexport interface ISegmentPrivate extends ISegmentInternal {\n\tsegmentGroups?: SegmentGroupCollection;\n\tpropertyManager?: PropertiesManager;\n\t/**\n\t * If a segment is inserted into an obliterated range,\n\t * but the newest obliteration of that range was by the inserting client,\n\t * then the segment is not obliterated because it is aware of the latest obliteration.\n\t */\n\tprevObliterateByInserter?: ObliterateInfo;\n}\n/**\n * Segment leafs are segments that have both IMergeNodeInfo and IInsertionInfo. This means they\n * are inserted at a position, and bound via their parent MergeBlock to the merge tree. MergeBlocks'\n * children are either a segment leaf, or another merge block for interior nodes of the tree. When working\n * within the tree it is generally unnecessary to use type coercions methods common to the infos, and segment\n * leafs, as the children of MergeBlocks are already well typed. However, when segments come from outside the\n * merge tree, like via client's public methods, it becomes necessary to use the type coercions methods\n * to ensure the passed in segment objects are correctly bound to the merge tree.\n */\nexport type ISegmentLeaf = SegmentWithInfo<IMergeNodeInfo & IInsertionInfo>;\n/**\n * A type-guard which determines if the segment has segment leaf, and\n * returns true if it does, along with applying strong typing.\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment is a segment leaf, otherwise false.\n */\nexport const isSegmentLeaf = (segmentLike: unknown): segmentLike is ISegmentLeaf =>\n\tisInserted(segmentLike) && isMergeNode(segmentLike);\n\n/**\n * Converts a segment-like object to a segment leaf object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The segment leaf if the conversion is possible, otherwise undefined.\n */\nexport const toSegmentLeaf = (segmentLike: unknown): ISegmentLeaf | undefined =>\n\tisSegmentLeaf(segmentLike) ? segmentLike : undefined;\n/**\n * Asserts that the segment is a segment leaf. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment is not a segment leaf.\n */\nexport const assertSegmentLeaf: (segmentLike: unknown) => asserts segmentLike is ISegmentLeaf =\n\t(segmentLike) => assert(isSegmentLeaf(segmentLike), 0xaab /* must be segment leaf */);\n/**\n * This type is used for building MergeBlocks from segments and other MergeBlocks. We need this\n * type as segments may not yet be bound to the tree, so lack merge node info which is required for\n * segment leafs.\n */\nexport type IMergeNodeBuilder = MergeBlock | SegmentWithInfo<IInsertionInfo>;\n\n/**\n * This type is used by MergeBlocks to define their children, which are either segments or other\n * MergeBlocks.\n */\nexport type IMergeNode = MergeBlock | ISegmentLeaf;\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 * @legacy\n * @alpha\n */\nexport interface ISegment {\n\treadonly type: string;\n\n\treadonly trackingCollection: TrackingGroupCollection;\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 * Properties that have been added to this segment via annotation.\n\t */\n\tproperties?: PropertySet;\n\n\tclone(): ISegment;\n\tcanAppend(segment: ISegment): boolean;\n\tappend(segment: ISegment): void;\n\tsplitAt(pos: number): ISegment | undefined;\n\t// Changing this to something other than any would break consumers.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\ttoJSONObject(): any;\n\tisLeaf(): this is ISegment;\n}\n\n/**\n * Determine if a segment has been removed.\n * @legacy\n * @alpha\n */\nexport function segmentIsRemoved(segment: ISegment): boolean {\n\treturn isRemoved(segment);\n}\n\n/**\n * @legacy\n * @alpha\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}\nexport interface ISegmentChanges {\n\tnext?: SegmentWithInfo<IInsertionInfo>;\n\treplaceCurrent?: SegmentWithInfo<IInsertionInfo>;\n}\n\nexport interface InsertContext {\n\tcandidateSegment?: SegmentWithInfo<IInsertionInfo>;\n\tleaf: (segment: ISegmentLeaf | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: MergeBlock) => boolean;\n}\n\nexport interface ObliterateInfo {\n\tstart: LocalReferencePosition;\n\tend: LocalReferencePosition;\n\trefSeq: number;\n\tclientId: number;\n\tseq: number;\n\tlocalSeq: number | undefined;\n\tsegmentGroup: SegmentGroup | undefined;\n}\n\nexport interface SegmentGroup {\n\tsegments: ISegmentLeaf[];\n\tpreviousProps?: PropertySet[];\n\tlocalSeq?: number;\n\trefSeq: number;\n\tobliterateInfo?: ObliterateInfo;\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 */\nexport const MaxNodesInBlock = 8;\nexport class MergeBlock implements Partial<IMergeNodeInfo> {\n\tpublic children: IMergeNode[];\n\tpublic needsScour?: boolean;\n\tpublic parent?: MergeBlock;\n\tpublic index: number = 0;\n\tpublic ordinal: string = \"\";\n\tpublic cachedLength: number | undefined = 0;\n\n\t/**\n\t * Maps each tile label in this block to the rightmost (i.e. furthest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic rightmostTiles: Readonly<MapLike<Marker>>;\n\t/**\n\t * Maps each tile label in this block to the leftmost (i.e. nearest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic leftmostTiles: Readonly<MapLike<Marker>>;\n\n\tisLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\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\n\tpublic constructor(public childCount: number) {\n\t\t// Suppression needed due to the way the merge tree children are initalized - we\n\t\t// allocate 8 children blocks, but any unused blocks are not counted in the childCount.\n\t\t// Using Array.from leads to unused children being undefined, which are counted in childCount.\n\t\t// eslint-disable-next-line unicorn/no-new-array\n\t\tthis.children = new Array<IMergeNode>(MaxNodesInBlock);\n\t\tthis.rightmostTiles = createMap<Marker>();\n\t\tthis.leftmostTiles = createMap<Marker>();\n\t}\n\n\tpublic setOrdinal(child: IMergeNode, index: number): void {\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}\nexport function assignChild<C extends IMergeNodeBuilder>(\n\tparent: MergeBlock,\n\tchild: C,\n\tindex: number,\n\tupdateOrdinal = true,\n): asserts child is C & IMergeNodeInfo {\n\tconst node = Object.assign<C, IMergeNodeInfo>(child, {\n\t\tparent,\n\t\tindex,\n\t\tordinal: hasProp(child, \"ordinal\", \"string\") ? child.ordinal : \"\",\n\t});\n\tif (updateOrdinal) {\n\t\tparent.setOrdinal(node, index);\n\t}\n\tparent.children[index] = node;\n}\n\nexport function seqLTE(seq: number, minOrRefSeq: number): boolean {\n\treturn seq !== UnassignedSequenceNumber && seq <= minOrRefSeq;\n}\n\n/**\n * @legacy\n * @alpha\n */\nexport abstract class BaseSegment implements ISegment {\n\tpublic cachedLength: number = 0;\n\n\tpublic readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(\n\t\tthis,\n\t);\n\t/***/\n\tpublic attribution?: IAttributionCollection<AttributionKey>;\n\n\tpublic properties?: PropertySet;\n\tpublic abstract readonly type: string;\n\tpublic constructor(properties?: PropertySet) {\n\t\tif (properties !== undefined) {\n\t\t\tthis.properties = clone(properties);\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(): this is ISegment {\n\t\treturn true;\n\t}\n\n\tprotected cloneInto(b: ISegment): void {\n\t\tconst seg: ISegmentPrivate = b;\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IInsertionInfo>(seg, {\n\t\t\t\tclientId: this.clientId,\n\t\t\t\tseq: this.seq,\n\t\t\t});\n\t\t}\n\t\t// TODO: deep clone properties\n\t\tseg.properties = clone(this.properties);\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IRemovalInfo>(seg, {\n\t\t\t\tremovedSeq: this.removedSeq,\n\t\t\t\tremovedClientIds: [...this.removedClientIds],\n\t\t\t});\n\t\t}\n\t\tif (isMoved(this)) {\n\t\t\toverwriteInfo<IMoveInfo>(seg, {\n\t\t\t\tmovedSeq: this.movedSeq,\n\t\t\t\tmovedSeqs: [...this.movedSeqs],\n\t\t\t\twasMovedOnInsert: this.wasMovedOnInsert,\n\t\t\t\tmovedClientIds: [...this.movedClientIds],\n\t\t\t});\n\t\t}\n\t\tseg.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): void {\n\t\tif (this.properties) {\n\t\t\tjseg.props = { ...this.properties };\n\t\t}\n\t}\n\t// This has to return any type because the return type is different for different segment types.\n\t// TODO: If possible, change the return type to match what should be returned for each segment type.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic abstract toJSONObject(): any;\n\n\tpublic splitAt(pos: number): ISegment | undefined {\n\t\tif (pos <= 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst leafSegment: ISegmentPrivate | undefined = this.createSplitSegmentAt(pos);\n\n\t\tif (!leafSegment) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (isMergeNode(this)) {\n\t\t\toverwriteInfo<IMergeNodeInfo>(leafSegment, {\n\t\t\t\tindex: this.index + 1,\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\t// Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.\n\t\t\t\t// The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-code-point\n\t\t\t\tordinal: this.ordinal + String.fromCharCode(0),\n\t\t\t\tparent: this.parent,\n\t\t\t});\n\t\t}\n\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IInsertionInfo>(leafSegment, {\n\t\t\t\tseq: this.seq,\n\t\t\t\tlocalSeq: this.localSeq,\n\t\t\t\tclientId: this.clientId,\n\t\t\t});\n\t\t}\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IRemovalInfo>(leafSegment, {\n\t\t\t\tremovedClientIds: [...this.removedClientIds],\n\t\t\t\tremovedSeq: this.removedSeq,\n\t\t\t\tlocalRemovedSeq: this.localRemovedSeq,\n\t\t\t});\n\t\t}\n\t\tif (isMoved(this)) {\n\t\t\toverwriteInfo<IMoveInfo>(leafSegment, {\n\t\t\t\tmovedClientIds: [...this.movedClientIds],\n\t\t\t\tmovedSeq: this.movedSeq,\n\t\t\t\tmovedSeqs: [...this.movedSeqs],\n\t\t\t\tlocalMovedSeq: this.localMovedSeq,\n\t\t\t\twasMovedOnInsert: this.wasMovedOnInsert,\n\t\t\t});\n\t\t}\n\n\t\tthis.trackingCollection.copyTo(leafSegment);\n\t\tif (this.attribution) {\n\t\t\tleafSegment.attribution = this.attribution.splitAt(pos);\n\t\t}\n\n\t\treturn leafSegment;\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 * The special-cased property key that tracks the id of a {@link Marker}.\n *\n * @remarks In general, marker ids should be accessed using the inherent method\n * {@link Marker.getId}. Marker ids should not be updated after creation.\n * @legacy\n * @alpha\n */\nexport const reservedMarkerIdKey = \"markerId\";\n\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @legacy\n * @alpha\n */\nexport interface IJSONMarkerSegment extends IJSONSegment {\n\tmarker: IMarkerDef;\n}\n\n/**\n * Markers are a special kind of segment that do not hold any content.\n *\n * Markers with a reference type of {@link ReferenceType.Tile} support spatially\n * accelerated queries for finding the next marker to the left or right of it in\n * sub-linear time. This is useful, for example, in the case of jumping from the\n * start of a paragraph to the end, assuming a paragraph is bound by markers at\n * the start and end.\n *\n * @legacy\n * @alpha\n */\nexport class Marker extends BaseSegment implements ReferencePosition, ISegment {\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): Marker {\n\t\treturn new Marker(refType, props);\n\t}\n\n\tconstructor(\n\t\tpublic refType: ReferenceType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tsuper(props);\n\t\tthis.cachedLength = 1;\n\t}\n\n\ttoJSONObject(): IJSONMarkerSegment {\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: IJSONSegment): Marker | undefined {\n\t\tif (spec && typeof spec === \"object\" && \"marker\" in spec) {\n\t\t\treturn Marker.make((spec.marker as Marker).refType, spec.props as PropertySet);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tclone(): Marker {\n\t\tconst b = Marker.make(this.refType, this.properties);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tgetSegment(): Marker {\n\t\treturn this;\n\t}\n\n\tgetOffset(): number {\n\t\treturn 0;\n\t}\n\n\tgetProperties(): PropertySet | undefined {\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(): string {\n\t\treturn `M${this.getId()}`;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number): undefined {\n\t\treturn undefined;\n\t}\n\n\tcanAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tappend(): void {\n\t\tthrow new Error(\"Can not append to marker\");\n\t}\n}\n\n/**\n * This class is used to track facts about the current window of collaboration. This window is defined by the server\n * specified minimum sequence number to the last sequence number seen. Additionally, it track state for outstanding\n * local operations.\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 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): void {\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 * Compares two numbers.\n */\nexport const compareNumbers = (a: number, b: number): number => a - b;\n\n/**\n * Compares two strings.\n */\nexport const compareStrings = (a: string, b: string): number => a.localeCompare(b);\n"]}
1
+ {"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,iDAAyE;AACzE,2DAA4F;AAC5F,iEAAiE;AAEjE,6CAA0D;AAE1D,mDAA8E;AAG9E,uDAY2B;AAwE3B;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAA+B,EAAE,CAClF,IAAA,4BAAU,EAAC,WAAW,CAAC,IAAI,IAAA,iCAAW,EAAC,WAAW,CAAC,CAAC;AADxC,QAAA,aAAa,iBAC2B;AAErD;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,WAAoB,EAA4B,EAAE,CAC/E,IAAA,qBAAa,EAAC,WAAW,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC;AADzC,QAAA,aAAa,iBAC4B;AACtD;;;;;GAKG;AACI,MAAM,iBAAiB,GAC7B,CAAC,WAAW,EAAE,EAAE,CAAC,IAAA,iBAAM,EAAC,IAAA,qBAAa,EAAC,WAAW,CAAC,EAAE,KAAK,CAAC,0BAA0B,CAAC,CAAC;AAD1E,QAAA,iBAAiB,qBACyD;AA6DvF;;;;GAIG;AACH,SAAgB,gBAAgB,CAAC,OAAiB;IACjD,OAAO,IAAA,2BAAS,EAAC,OAAO,CAAC,CAAC;AAC3B,CAAC;AAFD,4CAEC;AA+CD;;;;;GAKG;AACU,QAAA,eAAe,GAAG,CAAC,CAAC;AACjC,MAAa,UAAU;IAqBtB,MAAM;QACL,OAAO,KAAK,CAAC;IACd,CAAC;IAYD,YAA0B,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;QA/BrC,UAAK,GAAW,CAAC,CAAC;QA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;QAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;WA8DG;QACH,aAAQ,GAAG,CAAC,CAAC;IAQd,CAAC;IANA,QAAQ,CAAC,CAAsB;QAC9B,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3B,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC,aAAa,CAAC;QACrC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,CAAC;QACvB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,UAAU,CAAC;IAChC,CAAC;CACD;AApFD,kDAoFC;AAED;;GAEG;AACI,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC;AAAzD,QAAA,cAAc,kBAA2C;AAEtE;;GAEG;AACI,MAAM,cAAc,GAAG,CAAC,CAAS,EAAE,CAAS,EAAU,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;AAAtE,QAAA,cAAc,kBAAwD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { AttributionKey } from \"@fluidframework/runtime-definitions/internal\";\n\nimport { IAttributionCollection } from \"./attributionCollection.js\";\nimport { LocalClientId, UnassignedSequenceNumber } from \"./constants.js\";\nimport { LocalReferenceCollection, type LocalReferencePosition } from \"./localReference.js\";\nimport { TrackingGroupCollection } from \"./mergeTreeTracking.js\";\nimport { IJSONSegment, IMarkerDef, ReferenceType } from \"./ops.js\";\nimport { computeHierarchicalOrdinal } from \"./ordinal.js\";\nimport type { PartialSequenceLengths } from \"./partialLengths.js\";\nimport { PropertySet, clone, createMap, type MapLike } from \"./properties.js\";\nimport { ReferencePosition } from \"./referencePositions.js\";\nimport { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\thasProp,\n\tisInserted,\n\tisMergeNodeInfo as isMergeNode,\n\tisMoved,\n\tisRemoved,\n\toverwriteInfo,\n\ttype IInsertionInfo,\n\ttype IMergeNodeInfo,\n\ttype IMoveInfo,\n\ttype IRemovalInfo,\n\ttype SegmentWithInfo,\n} from \"./segmentInfos.js\";\nimport { PropertiesManager } from \"./segmentPropertiesManager.js\";\n\n/**\n * This interface exposes internal things to dds that leverage merge tree,\n * like sequence and matrix.\n *\n * We use tiered interface to control visibility of segment properties.\n * This sits between ISegment and ISegmentPrivate. It should only expose\n * things tagged internal.\n *\n * Everything added here beyond ISegment should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * @internal\n */\nexport interface ISegmentInternal extends ISegment {\n\tlocalRefs?: LocalReferenceCollection;\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\n/**\n * We use tiered interface to control visibility of segment properties.\n * This is the lowest interface and is not exported, it site below ISegment and ISegmentInternal.\n * It should only expose unexported things.\n *\n * Everything added here beyond ISegmentInternal should be optional to keep the ability\n * to implicitly convert between the tiered interfaces.\n *\n * someday we may split tree leaves from segments, but for now they are the same\n * this is just a convenience type that makes it clear that we need something that is both a segment and a leaf node\n */\nexport interface ISegmentPrivate extends ISegmentInternal {\n\tsegmentGroups?: SegmentGroupCollection;\n\tpropertyManager?: PropertiesManager;\n\t/**\n\t * Populated iff this segment was inserted into a range affected by concurrent obliterates at the time of its insertion.\n\t * Contains information about the 'most recent' (i.e. 'winning' in the sense below) obliterate.\n\t *\n\t * BEWARE: We have opted for a certain form of last-write wins (LWW) semantics for obliterates:\n\t * the client which last obliterated a range is considered to have \"won ownership\" of that range and may insert into it\n\t * without that insertion being obliterated by other clients' concurrent obliterates.\n\t *\n\t * Therefore, this field can be populated even if the segment has not been obliterated (i.e. is still visible).\n\t * This happens precisely when the segment was inserted by the same client that 'won' the obliterate (in a scenario where\n\t * a client first issues a sided obliterate impacting a range, then inserts into that range before the server has acked the obliterate).\n\t *\n\t * See the test case \"obliterate with mismatched final states\" for an example of such a scenario.\n\t *\n\t * TODO:AB#29553: This property is not persisted in the summary, but it should be.\n\t */\n\tobliteratePrecedingInsertion?: ObliterateInfo;\n}\n/**\n * Segment leafs are segments that have both IMergeNodeInfo and IInsertionInfo. This means they\n * are inserted at a position, and bound via their parent MergeBlock to the merge tree. MergeBlocks'\n * children are either a segment leaf, or another merge block for interior nodes of the tree. When working\n * within the tree it is generally unnecessary to use type coercions methods common to the infos, and segment\n * leafs, as the children of MergeBlocks are already well typed. However, when segments come from outside the\n * merge tree, like via client's public methods, it becomes necessary to use the type coercions methods\n * to ensure the passed in segment objects are correctly bound to the merge tree.\n */\nexport type ISegmentLeaf = SegmentWithInfo<IMergeNodeInfo & IInsertionInfo>;\n/**\n * A type-guard which determines if the segment has segment leaf, and\n * returns true if it does, along with applying strong typing.\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment is a segment leaf, otherwise false.\n */\nexport const isSegmentLeaf = (segmentLike: unknown): segmentLike is ISegmentLeaf =>\n\tisInserted(segmentLike) && isMergeNode(segmentLike);\n\n/**\n * Converts a segment-like object to a segment leaf object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The segment leaf if the conversion is possible, otherwise undefined.\n */\nexport const toSegmentLeaf = (segmentLike: unknown): ISegmentLeaf | undefined =>\n\tisSegmentLeaf(segmentLike) ? segmentLike : undefined;\n/**\n * Asserts that the segment is a segment leaf. Usage of this function should not produce a user facing error.\n *\n * @param segmentLike - The segment-like object to check.\n * @throws Will throw an error if the segment is not a segment leaf.\n */\nexport const assertSegmentLeaf: (segmentLike: unknown) => asserts segmentLike is ISegmentLeaf =\n\t(segmentLike) => assert(isSegmentLeaf(segmentLike), 0xaab /* must be segment leaf */);\n/**\n * This type is used for building MergeBlocks from segments and other MergeBlocks. We need this\n * type as segments may not yet be bound to the tree, so lack merge node info which is required for\n * segment leafs.\n */\nexport type IMergeNodeBuilder = MergeBlock | SegmentWithInfo<IInsertionInfo>;\n\n/**\n * This type is used by MergeBlocks to define their children, which are either segments or other\n * MergeBlocks.\n */\nexport type IMergeNode = MergeBlock | ISegmentLeaf;\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 * @legacy\n * @alpha\n */\nexport interface ISegment {\n\treadonly type: string;\n\n\treadonly trackingCollection: TrackingGroupCollection;\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 * Properties that have been added to this segment via annotation.\n\t */\n\tproperties?: PropertySet;\n\n\tclone(): ISegment;\n\tcanAppend(segment: ISegment): boolean;\n\tappend(segment: ISegment): void;\n\tsplitAt(pos: number): ISegment | undefined;\n\t// Changing this to something other than any would break consumers.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\ttoJSONObject(): any;\n\tisLeaf(): this is ISegment;\n}\n\n/**\n * Determine if a segment has been removed.\n * @legacy\n * @alpha\n */\nexport function segmentIsRemoved(segment: ISegment): boolean {\n\treturn isRemoved(segment);\n}\n\n/**\n * @legacy\n * @alpha\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}\nexport interface ISegmentChanges {\n\tnext?: SegmentWithInfo<IInsertionInfo>;\n\treplaceCurrent?: SegmentWithInfo<IInsertionInfo>;\n}\n\nexport interface InsertContext {\n\tcandidateSegment?: SegmentWithInfo<IInsertionInfo>;\n\tleaf: (segment: ISegmentLeaf | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: MergeBlock) => boolean;\n}\n\nexport interface ObliterateInfo {\n\tstart: LocalReferencePosition;\n\tend: LocalReferencePosition;\n\trefSeq: number;\n\tclientId: number;\n\tseq: number;\n\tlocalSeq: number | undefined;\n\tsegmentGroup: SegmentGroup | undefined;\n}\n\nexport interface SegmentGroup {\n\tsegments: ISegmentLeaf[];\n\tpreviousProps?: PropertySet[];\n\tlocalSeq?: number;\n\trefSeq: number;\n\tobliterateInfo?: ObliterateInfo;\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 */\nexport const MaxNodesInBlock = 8;\nexport class MergeBlock implements Partial<IMergeNodeInfo> {\n\tpublic children: IMergeNode[];\n\tpublic needsScour?: boolean;\n\tpublic parent?: MergeBlock;\n\tpublic index: number = 0;\n\tpublic ordinal: string = \"\";\n\tpublic cachedLength: number | undefined = 0;\n\n\t/**\n\t * Maps each tile label in this block to the rightmost (i.e. furthest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic rightmostTiles: Readonly<MapLike<Marker>>;\n\t/**\n\t * Maps each tile label in this block to the leftmost (i.e. nearest) marker associated with that tile label.\n\t * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile\n\t * with a certain label before a given position\n\t */\n\tpublic leftmostTiles: Readonly<MapLike<Marker>>;\n\n\tisLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\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\n\tpublic constructor(public childCount: number) {\n\t\t// Suppression needed due to the way the merge tree children are initalized - we\n\t\t// allocate 8 children blocks, but any unused blocks are not counted in the childCount.\n\t\t// Using Array.from leads to unused children being undefined, which are counted in childCount.\n\t\t// eslint-disable-next-line unicorn/no-new-array\n\t\tthis.children = new Array<IMergeNode>(MaxNodesInBlock);\n\t\tthis.rightmostTiles = createMap<Marker>();\n\t\tthis.leftmostTiles = createMap<Marker>();\n\t}\n\n\tpublic setOrdinal(child: IMergeNode, index: number): void {\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}\nexport function assignChild<C extends IMergeNodeBuilder>(\n\tparent: MergeBlock,\n\tchild: C,\n\tindex: number,\n\tupdateOrdinal = true,\n): asserts child is C & IMergeNodeInfo {\n\tconst node = Object.assign<C, IMergeNodeInfo>(child, {\n\t\tparent,\n\t\tindex,\n\t\tordinal: hasProp(child, \"ordinal\", \"string\") ? child.ordinal : \"\",\n\t});\n\tif (updateOrdinal) {\n\t\tparent.setOrdinal(node, index);\n\t}\n\tparent.children[index] = node;\n}\n\nexport function seqLTE(seq: number, minOrRefSeq: number): boolean {\n\treturn seq !== UnassignedSequenceNumber && seq <= minOrRefSeq;\n}\n\n/**\n * @legacy\n * @alpha\n */\nexport abstract class BaseSegment implements ISegment {\n\tpublic cachedLength: number = 0;\n\n\tpublic readonly trackingCollection: TrackingGroupCollection = new TrackingGroupCollection(\n\t\tthis,\n\t);\n\t/***/\n\tpublic attribution?: IAttributionCollection<AttributionKey>;\n\n\tpublic properties?: PropertySet;\n\tpublic abstract readonly type: string;\n\tpublic constructor(properties?: PropertySet) {\n\t\tif (properties !== undefined) {\n\t\t\tthis.properties = clone(properties);\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(): this is ISegment {\n\t\treturn true;\n\t}\n\n\tprotected cloneInto(b: ISegment): void {\n\t\tconst seg: ISegmentPrivate = b;\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IInsertionInfo>(seg, {\n\t\t\t\tclientId: this.clientId,\n\t\t\t\tseq: this.seq,\n\t\t\t});\n\t\t}\n\t\t// TODO: deep clone properties\n\t\tseg.properties = clone(this.properties);\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IRemovalInfo>(seg, {\n\t\t\t\tremovedSeq: this.removedSeq,\n\t\t\t\tremovedClientIds: [...this.removedClientIds],\n\t\t\t});\n\t\t}\n\t\tif (isMoved(this)) {\n\t\t\toverwriteInfo<IMoveInfo>(seg, {\n\t\t\t\tmovedSeq: this.movedSeq,\n\t\t\t\tmovedSeqs: [...this.movedSeqs],\n\t\t\t\twasMovedOnInsert: this.wasMovedOnInsert,\n\t\t\t\tmovedClientIds: [...this.movedClientIds],\n\t\t\t});\n\t\t}\n\t\tseg.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): void {\n\t\tif (this.properties) {\n\t\t\tjseg.props = { ...this.properties };\n\t\t}\n\t}\n\t// This has to return any type because the return type is different for different segment types.\n\t// TODO: If possible, change the return type to match what should be returned for each segment type.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic abstract toJSONObject(): any;\n\n\tpublic splitAt(pos: number): ISegment | undefined {\n\t\tif (pos <= 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst leafSegment: ISegmentPrivate | undefined = this.createSplitSegmentAt(pos);\n\n\t\tif (!leafSegment) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tif (isMergeNode(this)) {\n\t\t\toverwriteInfo<IMergeNodeInfo>(leafSegment, {\n\t\t\t\tindex: this.index + 1,\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\t// Ordinals exist purely for lexicographical sort order and use a small set of valid bytes for each string character.\n\t\t\t\t// The extra handling fromCodePoint has for things like surrogate pairs is therefore unnecessary.\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-code-point\n\t\t\t\tordinal: this.ordinal + String.fromCharCode(0),\n\t\t\t\tparent: this.parent,\n\t\t\t});\n\t\t}\n\n\t\tif (isInserted(this)) {\n\t\t\toverwriteInfo<IInsertionInfo>(leafSegment, {\n\t\t\t\tseq: this.seq,\n\t\t\t\tlocalSeq: this.localSeq,\n\t\t\t\tclientId: this.clientId,\n\t\t\t});\n\t\t}\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IRemovalInfo>(leafSegment, {\n\t\t\t\tremovedClientIds: [...this.removedClientIds],\n\t\t\t\tremovedSeq: this.removedSeq,\n\t\t\t\tlocalRemovedSeq: this.localRemovedSeq,\n\t\t\t});\n\t\t}\n\t\tif (isMoved(this)) {\n\t\t\toverwriteInfo<IMoveInfo>(leafSegment, {\n\t\t\t\tmovedClientIds: [...this.movedClientIds],\n\t\t\t\tmovedSeq: this.movedSeq,\n\t\t\t\tmovedSeqs: [...this.movedSeqs],\n\t\t\t\tlocalMovedSeq: this.localMovedSeq,\n\t\t\t\twasMovedOnInsert: this.wasMovedOnInsert,\n\t\t\t});\n\t\t}\n\n\t\tthis.trackingCollection.copyTo(leafSegment);\n\t\tif (this.attribution) {\n\t\t\tleafSegment.attribution = this.attribution.splitAt(pos);\n\t\t}\n\n\t\treturn leafSegment;\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 * The special-cased property key that tracks the id of a {@link Marker}.\n *\n * @remarks In general, marker ids should be accessed using the inherent method\n * {@link Marker.getId}. Marker ids should not be updated after creation.\n * @legacy\n * @alpha\n */\nexport const reservedMarkerIdKey = \"markerId\";\n\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @legacy\n * @alpha\n */\nexport interface IJSONMarkerSegment extends IJSONSegment {\n\tmarker: IMarkerDef;\n}\n\n/**\n * Markers are a special kind of segment that do not hold any content.\n *\n * Markers with a reference type of {@link ReferenceType.Tile} support spatially\n * accelerated queries for finding the next marker to the left or right of it in\n * sub-linear time. This is useful, for example, in the case of jumping from the\n * start of a paragraph to the end, assuming a paragraph is bound by markers at\n * the start and end.\n *\n * @legacy\n * @alpha\n */\nexport class Marker extends BaseSegment implements ReferencePosition, ISegment {\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): Marker {\n\t\treturn new Marker(refType, props);\n\t}\n\n\tconstructor(\n\t\tpublic refType: ReferenceType,\n\t\tprops?: PropertySet,\n\t) {\n\t\tsuper(props);\n\t\tthis.cachedLength = 1;\n\t}\n\n\ttoJSONObject(): IJSONMarkerSegment {\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: IJSONSegment): Marker | undefined {\n\t\tif (spec && typeof spec === \"object\" && \"marker\" in spec) {\n\t\t\treturn Marker.make((spec.marker as Marker).refType, spec.props as PropertySet);\n\t\t}\n\t\treturn undefined;\n\t}\n\n\tclone(): Marker {\n\t\tconst b = Marker.make(this.refType, this.properties);\n\t\tthis.cloneInto(b);\n\t\treturn b;\n\t}\n\n\tgetSegment(): Marker {\n\t\treturn this;\n\t}\n\n\tgetOffset(): number {\n\t\treturn 0;\n\t}\n\n\tgetProperties(): PropertySet | undefined {\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(): string {\n\t\treturn `M${this.getId()}`;\n\t}\n\n\tprotected createSplitSegmentAt(pos: number): undefined {\n\t\treturn undefined;\n\t}\n\n\tcanAppend(segment: ISegment): boolean {\n\t\treturn false;\n\t}\n\n\tappend(): void {\n\t\tthrow new Error(\"Can not append to marker\");\n\t}\n}\n\n/**\n * This class is used to track facts about the current window of collaboration. This window is defined by the server\n * specified minimum sequence number to the last sequence number seen. Additionally, it track state for outstanding\n * local operations.\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 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): void {\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 * Compares two numbers.\n */\nexport const compareNumbers = (a: number, b: number): number => a - b;\n\n/**\n * Compares two strings.\n */\nexport const compareStrings = (a: string, b: string): number => a.localeCompare(b);\n"]}
@@ -2,13 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { RedBlackTree } from "./collections/index.js";
6
5
  import { MergeTree } from "./mergeTree.js";
7
- import { CollaborationWindow, ISegmentPrivate, type MergeBlock } from "./mergeTreeNodes.js";
8
- interface IOverlapClient {
9
- clientId: number;
10
- seglen: number;
11
- }
6
+ import { CollaborationWindow, type MergeBlock } from "./mergeTreeNodes.js";
12
7
  /**
13
8
  * Tracks length information for a part of a MergeTree (block) at a given time (seq).
14
9
  * These objects are associated with internal nodes (i.e. blocks).
@@ -30,43 +25,6 @@ export interface PartialSequenceLength {
30
25
  * clientId for the client that submitted the op with sequence number `seq`.
31
26
  */
32
27
  clientId?: number;
33
- /**
34
- * If this partial length obliterated remote segments, this is the length of
35
- * those segments
36
- */
37
- remoteObliteratedLen?: number;
38
- /**
39
- * This field maps each client to the size of the intersection between segments deleted at this seq
40
- * and segments concurrently deleted by that client.
41
- *
42
- * For example, this PartialSequenceLength:
43
- * ```typescript
44
- * {
45
- * seq: 5,
46
- * len: 100,
47
- * seglen: -10,
48
- * clientId: 0,
49
- * overlapRemoveClients: <RedBlack tree with key-values expressed by>{
50
- * 1: { clientId: 1, seglen: -5 },
51
- * 3: { clientId: 3, seglen: -10 }
52
- * }
53
- * }
54
- * ```
55
- *
56
- * corresponds to an op submitted by client 0 which:
57
- * - reduces the length of this block by 10 (it may have deleted a single segment of length 10,
58
- * several segments totalling length 10, or even delete and add content for a total reduction of 10 length)
59
- * - was concurrent to one or more ops submitted by client 1 that also removed some of the same segments,
60
- * whose length totalled 5
61
- * - was concurrent to one or more ops submitted by client 3 that removed some of the same segments,
62
- * whose length totalled 10
63
- */
64
- overlapRemoveClients?: RedBlackTree<number, IOverlapClient>;
65
- /**
66
- * This field is the same as `overlapRemoveClients`, except that it tracks
67
- * overlapping obliterates rather than removes.
68
- */
69
- overlapObliterateClients?: RedBlackTree<number, IOverlapClient>;
70
28
  }
71
29
  export interface PartialSequenceLengthsOptions {
72
30
  verifier?: (partialLengths: PartialSequenceLengths) => void;
@@ -81,13 +39,13 @@ export interface PartialSequenceLengthsOptions {
81
39
  * "What is the length of `block` from the perspective of some particular seq and clientId?".
82
40
  *
83
41
  * It also supports incremental updating of state for newly-sequenced ops that don't affect the structure of the
84
- * MergeTree.
42
+ * MergeTree (in most cases--see AB#31003 or comments on {@link PartialSequenceLengths.update}).
85
43
  *
86
44
  * To answer these queries, it pre-builds several lists which track the length of the block at a per-sequence-number
87
45
  * level. These lists are:
88
46
  *
89
47
  * 1. (`partialLengths`): Stores the total length of the block.
90
- * 2. (`clientSeqNumbers[clientId]`): Stores only the total lengths of segments submitted by `clientId`. [see footnote]
48
+ * 2. (`perClientAdjustments[clientId]`): Stores adjustments to the base length which account for all changes submitted by `clientId`. [see footnote]
91
49
  *
92
50
  * The reason both lists are necessary is that resolving the length of the block from the perspective of
93
51
  * (clientId, refSeq) requires including both of the following types of segments:
@@ -110,13 +68,19 @@ export interface PartialSequenceLengthsOptions {
110
68
  * (length of the block at the minimum sequence number)
111
69
  * + (partialLengths total length at refSeq)
112
70
  * + (unsequenced edits' total length submitted before localSeq)
113
- * - (overlapping remove of the unsequenced edits' total length at refSeq)
71
+ * + (adjustments for changes double-counted by happening at or before both localSeq and refSeq)
114
72
  *
115
73
  * This algorithm scales roughly linearly with number of editing clients and the size of the collab window.
116
74
  * (certain unlikely sequences of operations may introduce log factors on those variables)
117
75
  *
118
- * Note: there is some slight complication with clientSeqNumbers resulting from the possibility of different clients
119
- * concurrently removing the same segment. See the field's documentation for more details.
76
+ * @privateRemarks
77
+ * If you are looking to understand this class in more detail, a suggested order of internalization is:
78
+ *
79
+ * 1. The above description and how it relates to the implementation of `getPartialLength` (which implements the above high-level description
80
+ * 2. `PartialSequenceLengthsSet`, which allows binary searching for overall length deltas at a given sequence number and handles updates.
81
+ * 3. The `fromLeaves` method, which is the base case for the [potential] recursion in `combine`
82
+ * 4. The logic in `combine` to aggregate smaller block entries into larger ones
83
+ * 5. The incremental code path of `update`
120
84
  */
121
85
  export declare class PartialSequenceLengths {
122
86
  /**
@@ -125,63 +89,6 @@ export declare class PartialSequenceLengths {
125
89
  */
126
90
  minSeq: number;
127
91
  static options: PartialSequenceLengthsOptions;
128
- /**
129
- * Combine the partial lengths of block's children
130
- * @param block - an interior node. If `recur` is false, it is assumed that each interior node child of this block
131
- * has its partials up to date.
132
- * @param collabWindow - segment window of the segment tree containing `block`.
133
- * @param recur - whether to recursively compute partial lengths for internal children of `block`.
134
- * This incurs more work, but gives correct bookkeeping in the case that a descendant in the merge tree has been
135
- * modified without bubbling up the resulting partial length change to this block's partials.
136
- * @param computeLocalPartials - whether to compute partial length information about local unsequenced ops.
137
- * This enables querying for the length of the block at a given localSeq, but incurs extra work.
138
- * Local partial information doesn't support `update`.
139
- */
140
- static combine(block: MergeBlock, collabWindow: CollaborationWindow, recur?: boolean, computeLocalPartials?: boolean): PartialSequenceLengths;
141
- /**
142
- * Creates and returns a PartialSequenceLengths structure that tracks the lengths of only the
143
- * leaf children of the provided MergeBlock.
144
- */
145
- private static fromLeaves;
146
- private static getOverlapClients;
147
- private static accumulateRemoveClientOverlap;
148
- private static accumulateMoveClientOverlap;
149
- /**
150
- * Coalesce overlapping move lengths for a partial length entry that already
151
- * exists
152
- *
153
- * @param segmentLen - Length of segment with overlapping moves
154
- * @param segment - Segment with overlapping moves
155
- * @param firstGte - Existing partial length entry
156
- * @param clientIds - Ids of clients that concurrently obliterated this segment
157
- */
158
- static accumulateMoveOverlapForExisting(segmentLen: number, segment: ISegmentPrivate, firstGte: PartialSequenceLength, clientIds: number[]): void;
159
- /**
160
- * Tracks which clients have made concurrent obliterates.
161
- *
162
- * @param obliterateOverlapLen - Length of segment with overlap
163
- * @param clientIds - Ids of clients that have concurrently obliterated this
164
- * segment
165
- */
166
- private static getMoveOverlapForExisting;
167
- private static updatePartialsAfterInsertion;
168
- /**
169
- * Inserts length information about the insertion of `segment` into
170
- * `combinedPartialLengths.partialLengths`.
171
- *
172
- * Does not update the clientSeqNumbers field to account for this segment.
173
- *
174
- * If `removalInfo` or `moveInfo` are defined, this operation updates the
175
- * bookkeeping to account for the (re)moval of this segment at the (re)movedSeq
176
- * instead.
177
- *
178
- * When the insertion or (re)moval of the segment is un-acked and
179
- * `combinedPartialLengths` is meant to compute such records, this does the
180
- * analogous addition to the bookkeeping for the local segment in
181
- * `combinedPartialLengths.unsequencedRecords`.
182
- */
183
- private static insertSegment;
184
- private static addSeq;
185
92
  /**
186
93
  * Length of the block this PartialSequenceLength corresponds to when viewed at `minSeq`.
187
94
  */
@@ -194,23 +101,64 @@ export declare class PartialSequenceLengths {
194
101
  * List of PartialSequenceLength objects--ordered by increasing seq--giving length information about
195
102
  * the block associated with this PartialSequenceLengths object.
196
103
  *
197
- * `partialLengths[i].len` contains the length of this block considering only sequenced segments with
198
- * `sequenceNumber <= partialLengths[i].seq`.
104
+ * `minLength + partialLengths[i].len` gives the length of this block when considering the perspective of an observer
105
+ * client who has received edits up to (and including) sequence number `i`.
199
106
  */
200
107
  private readonly partialLengths;
201
108
  /**
202
- * clientSeqNumbers[clientId] is a list of partial lengths for sequenced ops which either:
203
- * - were submitted by `clientId`.
204
- * - deleted a range containing segments that were concurrently deleted by `clientId`
109
+ * perClientAdjustments[clientId] contains a PartialSequenceLengthsSet of adjustments to the observer client's
110
+ * perspective (see {@link PartialSequenceLengths.partialLengths}) necessary to account for changes made by
111
+ * that client.
112
+ *
113
+ * As per doc comment on {@link PartialSequenceLengths}, the overall adjustment performed for the perspective of
114
+ * (clientId, refSeq) is given by the sum of length deltas in `perClientAdjustments[clientId]`
115
+ * for all sequence numbers S such that S \>= refSeq.
116
+ *
117
+ * (since these are ordered by sequence number and we cache cumulative sums, this is implemented using two lookups and a subtraction).
118
+ *
119
+ * The specific adjustments are roughly categorized as follows:
205
120
  *
206
- * The second case is referred to as the "overlapping delete" case. It is necessary to avoid double-counting
207
- * the removal of those segments in queries including clientId.
121
+ * - Ops submitted by a given client generally receive a partial lengths entry corresponding to their sequence number.
122
+ * e.g. insert of "ABC" at seq 5 will have a per-client adjustment entry of \{ seq: 5, seglen: 3 \}.
123
+ *
124
+ * - When client A deletes a segment concurrently with client B and loses the race (B's delete is sequenced first),
125
+ * A's per-client adjustments will contain an entry with a negative `seglen` corresponding to the length of the segment
126
+ * and a sequence number corresponding to that of B's delete. It will *not* receive a per-client adjustment for its own delete.
127
+ * This ensures that for perspectives (A, refSeq), the deleted segment will show up as a negative delta for all values of refSeq, since:
128
+ * 1. For refSeq \< B's delete, the per-client adjustment will apply and be added to the total length
129
+ * 2. For refSeq \>= B's delete, B's partial length entry in the overall set will apply, and the per-client adjustment will not apply
130
+ *
131
+ * - When client A attempts to insert a segment into a location that is concurrently obliterated by client B immediately upon insertion,
132
+ * A's per-client adjustments will again not include an entry for its own insert.
133
+ * Instead, the entry which would normally contain `seq` equal to that of A's insert would instead have `seq` equal to that of B's obliterate.
134
+ * This gives the overall correct behavior: for any perspective which isn't client A, there is no adjustment necessary anywhere (it's as if
135
+ * the segment never existed). For client A's perspective, the segment should be considered visible until A has acked B's obliterate.
136
+ * This is accomplished as for the perspective (A, refSeq):
137
+ * 1. For refSeq \< B's obliterate, the segment length will be included as part of the per-client adjustment for A
138
+ * 2. For refSeq \>= B's obliterate, the segment will be omitted from the per-client adjustment for A
139
+ *
140
+ * Note that the special-casing for inserting segments that are immediately obliterated is only necessary for segments that never were visible
141
+ * in the tree. If an insert and obliterate are concurrent but the insert is sequenced first, the normal per-client adjustment is fine.
142
+ *
143
+ * The second case (overlapping removal) applies to any combination of remove / obliterate operations.
208
144
  */
209
- private readonly clientSeqNumbers;
145
+ private readonly perClientAdjustments;
210
146
  /**
211
147
  * Contains information required to answer queries for the length of this segment from the perspective of
212
148
  * the local client but not including all local segments (i.e., `localSeq !== collabWindow.localSeq`).
213
149
  * This field is only computed if requested in the constructor (i.e. `computeLocalPartials === true`).
150
+ *
151
+ * Note that the usage pattern for this list is a bit different from perClientAdjustments: when dealing with perspectives of remote clients,
152
+ * we generally want to know what their view of the block was accounting for all changes made by that client as well as all \<= some refSeq.
153
+ *
154
+ * However, when dealing with perspectives relevant to the local client, we are still interested in changes made \<= some refSeq, but instead
155
+ * of caring about all changes made by the local client, we additionally want the subset of them that were made \<= some localSeq.
156
+ *
157
+ * The PartialSequenceLengthsSets stored in this field therefore track localSeqs rather than seqs (it's still named seq for ease of implementation).
158
+ * Furthermore, when computing the length of the block at a given refSeq/localSeq perspective,
159
+ * rather than add something like `perClientAdjustments[clientId].latestLeq(latestSeq) - perClientAdjustments[clientId].latestLeq(refSeq)` [to
160
+ * get the tail end of adjustments necessary for a remote client client], we instead add `unsequencedRecords.partialLengths.latestLeq(localSeq)`
161
+ * [to get the head end of adjustments necessary for the local client].
214
162
  */
215
163
  private unsequencedRecords;
216
164
  constructor(
@@ -219,6 +167,45 @@ export declare class PartialSequenceLengths {
219
167
  * or if no such calls have been made, the one used on construction.
220
168
  */
221
169
  minSeq: number, computeLocalPartials: boolean);
170
+ /**
171
+ * Combine the partial lengths of block's children
172
+ * @param block - an interior node. If `recur` is false, it is assumed that each interior node child of this block
173
+ * has its partials up to date.
174
+ * @param collabWindow - segment window of the segment tree containing `block`.
175
+ * @param recur - whether to recursively compute partial lengths for internal children of `block`.
176
+ * This incurs more work, but gives correct bookkeeping in the case that a descendant in the merge tree has been
177
+ * modified without bubbling up the resulting partial length change to this block's partials.
178
+ * @param computeLocalPartials - whether to compute partial length information about local unsequenced ops.
179
+ * This enables querying for the length of the block at a given localSeq, but incurs extra work.
180
+ * Local partial information doesn't support `update`.
181
+ */
182
+ static combine(block: MergeBlock, collabWindow: CollaborationWindow, recur?: boolean, computeLocalPartials?: boolean): PartialSequenceLengths;
183
+ /**
184
+ * Create a `PartialSequenceLengths` which tracks only changes incurred by direct child leaves of `block`.
185
+ */
186
+ private static fromLeaves;
187
+ /**
188
+ * Assuming this segment was moved on insertion, inserts length information about that operation
189
+ * into the appropriate per-client adjustments (the overall view needs no such adjustment since
190
+ * from an observing client's perspective, the segment never exists).
191
+ */
192
+ private static accountForMoveOnInsert;
193
+ /**
194
+ * Inserts length information about the insertion of `segment` into
195
+ * `combinedPartialLengths.partialLengths` and the appropriate per-client adjustments.
196
+ */
197
+ private static accountForInsertion;
198
+ /**
199
+ * Inserts length information about the removal or obliteration of `segment` into
200
+ * `combinedPartialLengths.partialLengths` and the appropriate per-client adjustments.
201
+ */
202
+ private static accountForRemoval;
203
+ /**
204
+ * If incremental update of partial lengths fails, this gets set to the seq of the failed update.
205
+ * When higher up blocks attempt to incrementally update, they first check if the seq they are updating for
206
+ * matches this value. If it does, they propagate a full refresh instead.
207
+ */
208
+ private lastIncrementalInvalidationSeq;
222
209
  update(node: MergeBlock, seq: number, clientId: number, collabWindow: CollaborationWindow): void;
223
210
  /**
224
211
  * Returns the length of this block as viewed from the perspective of `clientId` at `refSeq`.
@@ -232,23 +219,7 @@ export declare class PartialSequenceLengths {
232
219
  */
233
220
  getPartialLength(refSeq: number, clientId: number, localSeq?: number): number;
234
221
  /**
235
- * Computes the seglen for the double-counted removed overlap at (refSeq, localSeq). This logic is equivalent
236
- * to the following:
237
- *
238
- * ```typescript
239
- * let total = 0;
240
- * for (const partialLength of this.unsequencedRecords!.overlappingRemoves) {
241
- * if (partialLength.seq > refSeq) {
242
- * break;
243
- * }
244
- *
245
- * if (partialLength.localSeq <= localSeq) {
246
- * total += partialLength.seglen;
247
- * }
248
- * }
249
- *
250
- * return total;
251
- * ```
222
+ * Computes the seglen for the double-counted removed overlap at (refSeq, localSeq).
252
223
  *
253
224
  * Reconnect happens to only need to compute these lengths for two refSeq values: before and
254
225
  * after the rebase. Since these lists potentially scale with O(collab window * number of local edits)
@@ -256,23 +227,22 @@ export declare class PartialSequenceLengths {
256
227
  * we cache the results for a given refSeq in `this.unsequencedRecords.cachedOverlappingByRefSeq` so
257
228
  * that they can be binary-searched the same way the usual partialLengths lists are.
258
229
  */
259
- private computeOverlappingLocalRemoves;
230
+ private computeOverallRefSeqAdjustment;
260
231
  toString(glc?: (id: number) => string, indentCount?: number): string;
261
232
  private zamboni;
262
- private addClientSeqNumber;
263
- private addClientSeqNumberFromPartial;
264
- private cliLatestLEQ;
265
- private cliLatest;
233
+ private addClientAdjustment;
234
+ private addLocalAdjustment;
235
+ /**
236
+ * Returns the partial lengths associated with the latest change associated with `clientId` at or before `refSeq`.
237
+ * Returns undefined if no such change exists.
238
+ */
239
+ private latestClientEntryLEQ;
240
+ /**
241
+ * Get the partial lengths associated with the most recent change received by `clientId`, or undefined
242
+ * if this client has made no changes in this block within the collab window.
243
+ */
244
+ private latestClientEntry;
266
245
  }
267
246
  export declare function verifyExpectedPartialLengths(mergeTree: MergeTree, node: MergeBlock, refSeq: number, clientId: number, localSeq?: number): void;
268
247
  export declare function verifyPartialLengths(partialSeqLengths: PartialSequenceLengths): void;
269
- /**
270
- * Combines the `overlapRemoveClients` and `overlapObliterateClients` fields of
271
- * two `PartialSequenceLength` objects, modifying the first PartialSequenceLength's
272
- * bookkeeping in-place.
273
- *
274
- * Combination is performed additively on `seglen` on a per-client basis.
275
- */
276
- export declare function combineOverlapClients(a: PartialSequenceLength, b: PartialSequenceLength): void;
277
- export {};
278
248
  //# sourceMappingURL=partialLengths.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"partialLengths.d.ts","sourceRoot":"","sources":["../src/partialLengths.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAY,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAEhE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EACN,mBAAmB,EAEnB,eAAe,EAGf,KAAK,UAAU,EACf,MAAM,qBAAqB,CAAC;AA+F7B,UAAU,cAAc;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,qBAAqB;IACrC;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;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