@fluidframework/merge-tree 2.21.0 → 2.22.1

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 (179) hide show
  1. package/.eslintrc.cjs +0 -1
  2. package/CHANGELOG.md +4 -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 +107 -43
  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.map +1 -1
  54. package/dist/test/client.obliterateFarm.spec.js +12 -3
  55. package/dist/test/client.obliterateFarm.spec.js.map +1 -1
  56. package/dist/test/client.reconnectFarm.spec.js +1 -1
  57. package/dist/test/client.reconnectFarm.spec.js.map +1 -1
  58. package/dist/test/client.searchForMarker.spec.js +2 -2
  59. package/dist/test/client.searchForMarker.spec.js.map +1 -1
  60. package/dist/test/mergeTreeOperationRunner.d.ts +1 -1
  61. package/dist/test/mergeTreeOperationRunner.d.ts.map +1 -1
  62. package/dist/test/mergeTreeOperationRunner.js +23 -11
  63. package/dist/test/mergeTreeOperationRunner.js.map +1 -1
  64. package/dist/test/obliterate.concurrent.spec.js +97 -1
  65. package/dist/test/obliterate.concurrent.spec.js.map +1 -1
  66. package/dist/test/obliterate.rangeExpansion.spec.js +81 -5
  67. package/dist/test/obliterate.rangeExpansion.spec.js.map +1 -1
  68. package/dist/test/obliterate.spec.js +3 -3
  69. package/dist/test/obliterate.spec.js.map +1 -1
  70. package/dist/test/obliterateOperations.d.ts.map +1 -1
  71. package/dist/test/obliterateOperations.js +29 -18
  72. package/dist/test/obliterateOperations.js.map +1 -1
  73. package/dist/test/partialSyncHelper.d.ts +42 -0
  74. package/dist/test/partialSyncHelper.d.ts.map +1 -0
  75. package/dist/test/partialSyncHelper.js +96 -0
  76. package/dist/test/partialSyncHelper.js.map +1 -0
  77. package/dist/test/revertibles.spec.js +3 -3
  78. package/dist/test/revertibles.spec.js.map +1 -1
  79. package/dist/test/sortedSegmentSet.spec.js +21 -0
  80. package/dist/test/sortedSegmentSet.spec.js.map +1 -1
  81. package/dist/test/testClient.d.ts +1 -1
  82. package/dist/test/testClient.d.ts.map +1 -1
  83. package/dist/test/testClient.js +1 -0
  84. package/dist/test/testClient.js.map +1 -1
  85. package/dist/test/testUtils.js +2 -2
  86. package/dist/test/testUtils.js.map +1 -1
  87. package/lib/attributionCollection.js +5 -7
  88. package/lib/attributionCollection.js.map +1 -1
  89. package/lib/localReference.js +6 -8
  90. package/lib/localReference.js.map +1 -1
  91. package/lib/mergeTree.d.ts.map +1 -1
  92. package/lib/mergeTree.js +107 -43
  93. package/lib/mergeTree.js.map +1 -1
  94. package/lib/mergeTreeNodes.d.ts +15 -4
  95. package/lib/mergeTreeNodes.d.ts.map +1 -1
  96. package/lib/mergeTreeNodes.js +1 -1
  97. package/lib/mergeTreeNodes.js.map +1 -1
  98. package/lib/partialLengths.d.ts +114 -144
  99. package/lib/partialLengths.d.ts.map +1 -1
  100. package/lib/partialLengths.js +432 -525
  101. package/lib/partialLengths.js.map +1 -1
  102. package/lib/perspective.d.ts +10 -1
  103. package/lib/perspective.d.ts.map +1 -1
  104. package/lib/perspective.js +10 -1
  105. package/lib/perspective.js.map +1 -1
  106. package/lib/properties.d.ts.map +1 -1
  107. package/lib/properties.js +2 -3
  108. package/lib/properties.js.map +1 -1
  109. package/lib/revertibles.js +3 -3
  110. package/lib/revertibles.js.map +1 -1
  111. package/lib/segmentInfos.d.ts +3 -0
  112. package/lib/segmentInfos.d.ts.map +1 -1
  113. package/lib/segmentInfos.js.map +1 -1
  114. package/lib/segmentPropertiesManager.js +3 -3
  115. package/lib/segmentPropertiesManager.js.map +1 -1
  116. package/lib/snapshotLoader.js +2 -2
  117. package/lib/snapshotLoader.js.map +1 -1
  118. package/lib/sortedSegmentSet.d.ts +5 -3
  119. package/lib/sortedSegmentSet.d.ts.map +1 -1
  120. package/lib/sortedSegmentSet.js +33 -41
  121. package/lib/sortedSegmentSet.js.map +1 -1
  122. package/lib/sortedSet.d.ts +20 -3
  123. package/lib/sortedSet.d.ts.map +1 -1
  124. package/lib/sortedSet.js +23 -14
  125. package/lib/sortedSet.js.map +1 -1
  126. package/lib/test/Snapshot.perf.spec.js +1 -1
  127. package/lib/test/Snapshot.perf.spec.js.map +1 -1
  128. package/lib/test/client.applyMsg.spec.js +20 -0
  129. package/lib/test/client.applyMsg.spec.js.map +1 -1
  130. package/lib/test/client.applyStashedOpFarm.spec.js +1 -1
  131. package/lib/test/client.applyStashedOpFarm.spec.js.map +1 -1
  132. package/lib/test/client.attributionFarm.spec.js +1 -1
  133. package/lib/test/client.attributionFarm.spec.js.map +1 -1
  134. package/lib/test/client.localReference.spec.js +48 -0
  135. package/lib/test/client.localReference.spec.js.map +1 -1
  136. package/lib/test/client.obliterateFarm.spec.d.ts.map +1 -1
  137. package/lib/test/client.obliterateFarm.spec.js +16 -5
  138. package/lib/test/client.obliterateFarm.spec.js.map +1 -1
  139. package/lib/test/client.reconnectFarm.spec.js +1 -1
  140. package/lib/test/client.reconnectFarm.spec.js.map +1 -1
  141. package/lib/test/client.searchForMarker.spec.js +2 -2
  142. package/lib/test/client.searchForMarker.spec.js.map +1 -1
  143. package/lib/test/mergeTreeOperationRunner.d.ts +1 -1
  144. package/lib/test/mergeTreeOperationRunner.d.ts.map +1 -1
  145. package/lib/test/mergeTreeOperationRunner.js +23 -11
  146. package/lib/test/mergeTreeOperationRunner.js.map +1 -1
  147. package/lib/test/obliterate.concurrent.spec.js +97 -1
  148. package/lib/test/obliterate.concurrent.spec.js.map +1 -1
  149. package/lib/test/obliterate.rangeExpansion.spec.js +81 -5
  150. package/lib/test/obliterate.rangeExpansion.spec.js.map +1 -1
  151. package/lib/test/obliterate.spec.js +3 -3
  152. package/lib/test/obliterate.spec.js.map +1 -1
  153. package/lib/test/obliterateOperations.d.ts.map +1 -1
  154. package/lib/test/obliterateOperations.js +29 -18
  155. package/lib/test/obliterateOperations.js.map +1 -1
  156. package/lib/test/partialSyncHelper.d.ts +42 -0
  157. package/lib/test/partialSyncHelper.d.ts.map +1 -0
  158. package/lib/test/partialSyncHelper.js +92 -0
  159. package/lib/test/partialSyncHelper.js.map +1 -0
  160. package/lib/test/revertibles.spec.js +3 -3
  161. package/lib/test/revertibles.spec.js.map +1 -1
  162. package/lib/test/sortedSegmentSet.spec.js +21 -0
  163. package/lib/test/sortedSegmentSet.spec.js.map +1 -1
  164. package/lib/test/testClient.d.ts +1 -1
  165. package/lib/test/testClient.d.ts.map +1 -1
  166. package/lib/test/testClient.js +1 -0
  167. package/lib/test/testClient.js.map +1 -1
  168. package/lib/test/testUtils.js +2 -2
  169. package/lib/test/testUtils.js.map +1 -1
  170. package/package.json +18 -18
  171. package/src/mergeTree.ts +126 -37
  172. package/src/mergeTreeNodes.ts +15 -4
  173. package/src/partialLengths.ts +559 -776
  174. package/src/perspective.ts +10 -1
  175. package/src/properties.ts +2 -3
  176. package/src/segmentInfos.ts +3 -0
  177. package/src/snapshotLoader.ts +1 -1
  178. package/src/sortedSegmentSet.ts +41 -50
  179. package/src/sortedSet.ts +32 -16
@@ -1 +1 @@
1
- {"version":3,"file":"localReference.js","sourceRoot":"","sources":["../src/localReference.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAY,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAiB,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAChF,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAe,aAAa,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,MAAM,GAAG,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,CAAC;YACzD,OAAO,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;gBAC5E,IAAI,SAAS,EAAE,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;oBAC3E,OAAO,KAAK,CAAC;gBACd,CAAC;YACF,CAAC;YACD,MAAM,IAAI,SAAS,CAAC;YACpB,eAAe,CAAC,IAAI,CACnB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EACjC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,EAC7B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,KAAK,CAChC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD","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 { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { DoublyLinkedList, ListNode, walkList } from \"./collections/index.js\";\nimport { type ISegmentInternal } from \"./mergeTreeNodes.js\";\nimport { TrackingGroup, TrackingGroupCollection } from \"./mergeTreeTracking.js\";\nimport { ReferenceType } from \"./ops.js\";\nimport { PropertySet, addProperties } from \"./properties.js\";\nimport { ReferencePosition, refTypeIncludesFlag } from \"./referencePositions.js\";\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy\n * @alpha\n */\nexport const SlidingPreference = {\n\t/**\n\t * Prefer sliding towards the start of the tree\n\t */\n\tBACKWARD: 0,\n\t/**\n\t * Prefer sliding towards the end of the tree\n\t */\n\tFORWARD: 1,\n} as const;\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy\n * @alpha\n */\nexport type SlidingPreference = (typeof SlidingPreference)[keyof typeof SlidingPreference];\n\nfunction _validateReferenceType(refType: ReferenceType): void {\n\tlet exclusiveCount = 0;\n\tif (refTypeIncludesFlag(refType, ReferenceType.Transient)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.SlideOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.StayOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (exclusiveCount > 1) {\n\t\tthrow new UsageError(\n\t\t\t\"Reference types can only be one of Transient, SlideOnRemove, and StayOnRemove\",\n\t\t);\n\t}\n}\n/**\n * @sealed\n * @legacy\n * @alpha\n */\nexport interface LocalReferencePosition extends ReferencePosition {\n\tcallbacks?: Partial<\n\t\tRecord<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>\n\t>;\n\treadonly trackingCollection: TrackingGroupCollection;\n\t/**\n\t * Whether or not this reference position can slide onto one of the two\n\t * special segments representing the position before or after the tree\n\t */\n\treadonly canSlideToEndpoint?: boolean;\n\n\t/**\n\t * @param newProps - Properties to add to this reference.\n\t * @remarks Note that merge-tree does not broadcast changes to other clients. It is up to the consumer\n\t * to ensure broadcast happens if that is desired.\n\t */\n\taddProperties(newProps: PropertySet): void;\n}\n\n/**\n * @privateRemarks This should not be exported outside merge tree.\n * @internal\n */\nclass LocalReference implements LocalReferencePosition {\n\tpublic properties: PropertySet | undefined;\n\n\tprivate segment: ISegmentInternal | undefined;\n\tprivate offset: number = 0;\n\tprivate listNode: ListNode<LocalReference> | undefined;\n\n\tpublic callbacks?:\n\t\t| Partial<Record<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>>\n\t\t| undefined;\n\tprivate _trackingCollection?: TrackingGroupCollection;\n\tpublic get trackingCollection(): TrackingGroupCollection {\n\t\treturn (this._trackingCollection ??= new TrackingGroupCollection(this));\n\t}\n\n\tconstructor(\n\t\tpublic refType = ReferenceType.Simple,\n\t\tproperties?: PropertySet,\n\t\tpublic readonly slidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\t\tpublic readonly canSlideToEndpoint?: boolean,\n\t) {\n\t\t_validateReferenceType(refType);\n\t\tthis.properties = properties;\n\t}\n\n\tpublic link(\n\t\tsegment: ISegmentInternal | undefined,\n\t\toffset: number,\n\t\tlistNode: ListNode<LocalReference> | undefined,\n\t): void {\n\t\tif (listNode !== this.listNode && this.listNode !== undefined) {\n\t\t\tthis.segment?.localRefs?.removeLocalRef(this);\n\t\t}\n\t\tthis.listNode = listNode;\n\n\t\tif (segment !== this.segment) {\n\t\t\tconst groups: TrackingGroup[] = [];\n\t\t\tfor (const tg of this.trackingCollection.trackingGroups) {\n\t\t\t\ttg.unlink(this);\n\t\t\t\tgroups.push(tg);\n\t\t\t}\n\n\t\t\tthis.segment = segment;\n\n\t\t\tfor (const tg of groups) tg.link(this);\n\t\t}\n\t\tthis.offset = offset;\n\t}\n\n\tpublic isLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\n\tpublic addProperties(newProps: PropertySet): void {\n\t\tthis.properties = addProperties(this.properties, newProps);\n\t}\n\n\tpublic getSegment(): ISegmentInternal | undefined {\n\t\treturn this.segment;\n\t}\n\n\tpublic getOffset(): number {\n\t\treturn this.offset;\n\t}\n\n\tpublic getListNode(): ListNode<LocalReference> | undefined {\n\t\treturn this.listNode;\n\t}\n\n\tpublic getProperties(): PropertySet | undefined {\n\t\treturn this.properties;\n\t}\n}\n\n/**\n * Creates a new detached local reference.\n * @internal\n */\nexport function createDetachedLocalReferencePosition(\n\tslidingPreference: SlidingPreference | undefined,\n\trefType?: ReferenceType,\n): LocalReferencePosition {\n\treturn new LocalReference(refType, undefined, slidingPreference);\n}\n\ninterface IRefsAtOffset {\n\tbefore?: DoublyLinkedList<LocalReference>;\n\tat?: DoublyLinkedList<LocalReference>;\n\tafter?: DoublyLinkedList<LocalReference>;\n}\n\nfunction assertLocalReferences(lref: unknown): asserts lref is LocalReference {\n\tassert(lref instanceof LocalReference, 0x2e0 /* \"lref not a Local Reference\" */);\n}\n\n/**\n * Determines if the given function is true for any position within the collection.\n */\nexport function anyLocalReferencePosition(\n\tcollection: LocalReferenceCollection,\n\tfunc: (pos: LocalReferencePosition) => boolean,\n): boolean {\n\tfor (const pos of collection) {\n\t\tif (func(pos)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Finds the local reference positions that satisfy the given predicate.\n */\nexport function* filterLocalReferencePositions(\n\tcollection: LocalReferenceCollection,\n\tpredicate: (pos: LocalReferencePosition) => boolean,\n): Generator<LocalReferencePosition> {\n\tfor (const pos of collection) {\n\t\tif (predicate(pos)) {\n\t\t\tyield pos;\n\t\t}\n\t}\n}\n\n/**\n * Injectable hook for validating that the refCount property matches the\n * expected value\n */\nlet validateRefCount: ((collection?: LocalReferenceCollection) => void) | undefined;\n\nexport function setValidateRefCount(\n\tcb?: (collection?: LocalReferenceCollection) => void,\n): void {\n\tvalidateRefCount = cb;\n}\n\n/**\n * Represents a collection of {@link LocalReferencePosition}s associated with\n * one segment in a merge-tree.\n * Represents a collection of {@link LocalReferencePosition}s associated with one segment in a merge-tree.\n * @sealed\n *\n * @internal\n */\nexport class LocalReferenceCollection {\n\tpublic static append(seg1: ISegmentInternal, seg2: ISegmentInternal): void {\n\t\tif (seg2.localRefs && !seg2.localRefs.empty) {\n\t\t\tif (!seg1.localRefs) {\n\t\t\t\tseg1.localRefs = new LocalReferenceCollection(seg1);\n\t\t\t}\n\t\t\tassert(\n\t\t\t\tseg1.localRefs.refsByOffset.length === seg1.cachedLength,\n\t\t\t\t0x2be /* \"LocalReferences array contains a gap\" */,\n\t\t\t);\n\t\t\tseg1.localRefs.append(seg2.localRefs);\n\t\t} else if (seg1.localRefs) {\n\t\t\t// Since creating the LocalReferenceCollection, we may have appended\n\t\t\t// segments that had no local references. Account for them now by padding the array.\n\t\t\tseg1.localRefs.refsByOffset.length += seg2.cachedLength;\n\t\t}\n\t\tvalidateRefCount?.(seg1.localRefs);\n\t\tvalidateRefCount?.(seg2.localRefs);\n\t}\n\n\tpublic static setOrGet(segment: ISegmentInternal): LocalReferenceCollection {\n\t\treturn (segment.localRefs ??= new LocalReferenceCollection(segment));\n\t}\n\n\tprivate readonly refsByOffset: (IRefsAtOffset | undefined)[];\n\tprivate refCount: number = 0;\n\n\tprivate constructor(\n\t\t/**\n\t\t * The segment this `LocalReferenceCollection` is associated with.\n\t\t */\n\t\tprivate readonly segment: ISegmentInternal,\n\t\tinitialRefsByfOffset: (IRefsAtOffset | undefined)[] = Array.from({\n\t\t\tlength: segment.cachedLength,\n\t\t}),\n\t) {\n\t\t// Since javascript arrays are sparse the above won't populate any of the\n\t\t// indices, but it will ensure the length property of the array matches\n\t\t// the length of the segment.\n\t\tthis.refsByOffset = initialRefsByfOffset;\n\t}\n\n\t/**\n\t * Returns an iterator over this LocalReferenceCollection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic [Symbol.iterator](): {\n\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t} {\n\t\tconst subiterators: IterableIterator<ListNode<LocalReferencePosition>>[] = [];\n\t\tfor (const refs of this.refsByOffset) {\n\t\t\tif (refs) {\n\t\t\t\tif (refs.before) {\n\t\t\t\t\tsubiterators.push(refs.before[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.at) {\n\t\t\t\t\tsubiterators.push(refs.at[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.after) {\n\t\t\t\t\tsubiterators.push(refs.after[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst iterator = {\n\t\t\tnext(): IteratorResult<LocalReferencePosition> {\n\t\t\t\twhile (subiterators.length > 0) {\n\t\t\t\t\tconst next = subiterators[0].next();\n\t\t\t\t\tif (next.done === true) {\n\t\t\t\t\t\tsubiterators.shift();\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn { done: next.done, value: next.value.data };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { value: undefined, done: true };\n\t\t\t},\n\t\t\t[Symbol.iterator](): {\n\t\t\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t\t\t} {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * Determines if the collection has no references in it.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic get empty(): boolean {\n\t\tvalidateRefCount?.(this);\n\t\treturn this.refCount === 0;\n\t}\n\n\t/**\n\t * Creates a new local reference.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic createLocalRef(\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\tconst ref = new LocalReference(refType, properties, slidingPreference, canSlideToEndpoint);\n\t\tref.link(this.segment, offset, undefined);\n\t\tif (!refTypeIncludesFlag(ref, ReferenceType.Transient)) {\n\t\t\tthis.addLocalRef(ref, offset);\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t\treturn ref;\n\t}\n\n\t/**\n\t * Adds a local reference to the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addLocalRef(lref: LocalReferencePosition, offset: number): void {\n\t\tassertLocalReferences(lref);\n\t\tassert(\n\t\t\toffset < this.segment.cachedLength,\n\t\t\t0x348 /* offset cannot be beyond segment length */,\n\t\t);\n\t\tif (refTypeIncludesFlag(lref, ReferenceType.Transient)) {\n\t\t\tlref.link(this.segment, offset, undefined);\n\t\t} else {\n\t\t\tconst refsAtOffset = (this.refsByOffset[offset] = this.refsByOffset[offset] ?? {\n\t\t\t\tat: new DoublyLinkedList(),\n\t\t\t});\n\t\t\tconst atRefs = (refsAtOffset.at = refsAtOffset.at ?? new DoublyLinkedList());\n\n\t\t\tlref.link(this.segment, offset, atRefs.push(lref).last);\n\n\t\t\tthis.refCount++;\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Removes a local reference from the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic removeLocalRef(lref: LocalReferencePosition): LocalReferencePosition | undefined {\n\t\tif (this.has(lref)) {\n\t\t\tassertLocalReferences(lref);\n\n\t\t\tconst node = lref.getListNode();\n\t\t\tnode?.list?.remove(node);\n\n\t\t\tlref.link(undefined, 0, undefined);\n\n\t\t\tthis.refCount--;\n\t\t\tvalidateRefCount?.(this);\n\t\t\treturn lref;\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * Called by 'append()' implementations to append local refs from the given 'other' segment to the\n\t * end of 'this' segment.\n\t *\n\t * Note: This method should be invoked after the caller has ensured that segments can be merged,\n\t * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs\n\t * will be incorrect.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic append(other: LocalReferenceCollection): void {\n\t\tif (!other || other.empty) {\n\t\t\treturn;\n\t\t}\n\t\tthis.refCount += other.refCount;\n\t\tother.refCount = 0;\n\t\tfor (const lref of other) {\n\t\t\tassertLocalReferences(lref);\n\t\t\tlref.link(this.segment, lref.getOffset() + this.refsByOffset.length, lref.getListNode());\n\t\t}\n\n\t\tthis.refsByOffset.push(...other.refsByOffset);\n\t\tother.refsByOffset.length = 0;\n\t}\n\t/**\n\t * Returns true of the local reference is in the collection, otherwise false.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic has(lref: ReferencePosition): boolean {\n\t\tif (\n\t\t\t!(lref instanceof LocalReference) ||\n\t\t\trefTypeIncludesFlag(lref, ReferenceType.Transient)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tconst seg = lref.getSegment();\n\t\tif (seg !== this.segment) {\n\t\t\treturn false;\n\t\t}\n\t\t// we should be able to optimize finding the\n\t\t// list head\n\t\tconst listNode = lref.getListNode();\n\t\tif (listNode === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tconst offset = lref.getOffset();\n\t\tconst refsAtOffset = this.refsByOffset[offset];\n\t\tif (\n\t\t\t!!refsAtOffset?.before?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.at?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.after?.includes(listNode)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).\n\t * Local references in the former half of this split will remain associated with the segment used on construction.\n\t * Local references in the latter half of this split will be transferred to `splitSeg`,\n\t * and its `localRefs` field will be set.\n\t * @param offset - Offset into the original segment at which the collection should be split\n\t * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)\n\t * before splitting.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic split(offset: number, splitSeg: ISegmentInternal): void {\n\t\tif (this.empty) {\n\t\t\t// shrink the offset array when empty and splitting\n\t\t\tthis.refsByOffset.length = offset;\n\t\t} else {\n\t\t\tconst localRefs = new LocalReferenceCollection(\n\t\t\t\tsplitSeg,\n\t\t\t\tthis.refsByOffset.splice(offset, this.refsByOffset.length - offset),\n\t\t\t);\n\n\t\t\tsplitSeg.localRefs = localRefs;\n\t\t\tfor (const lref of localRefs) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tlref.link(splitSeg, lref.getOffset() - offset, lref.getListNode());\n\t\t\t\tthis.refCount--;\n\t\t\t\tlocalRefs.refCount++;\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Insert a reference before tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addBeforeTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst beforeRefs = this.refsByOffset[0]?.before ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[0]?.before === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[0] ??= { before: beforeRefs });\n\t\t\trefsAtOffset.before ??= beforeRefs;\n\t\t}\n\n\t\tlet precedingRef: ListNode<LocalReference> | undefined;\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tprecedingRef =\n\t\t\t\t\t\tprecedingRef === undefined\n\t\t\t\t\t\t\t? beforeRefs.unshift(lref)?.first\n\t\t\t\t\t\t\t: beforeRefs.insertAfter(precedingRef, lref)?.first;\n\t\t\t\t\tlref.link(this.segment, 0, precedingRef);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\t/**\n\t * Insert a reference after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addAfterTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst lastOffset = this.segment.cachedLength - 1;\n\t\tconst afterRefs = this.refsByOffset[lastOffset]?.after ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[lastOffset]?.after === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[lastOffset] ??= { after: afterRefs });\n\t\t\trefsAtOffset.after ??= afterRefs;\n\t\t}\n\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tafterRefs.push(lref);\n\t\t\t\t\tlref.link(this.segment, lastOffset, afterRefs.last);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Determines if a reference is after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic isAfterTombstone(lref: LocalReferencePosition): boolean {\n\t\tconst after = this.refsByOffset[lref.getOffset()]?.after;\n\t\tif (after) {\n\t\t\tassertLocalReferences(lref);\n\t\t\treturn after.includes(lref.getListNode());\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Walks all of the references in a collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic walkReferences(\n\t\tvisitor: (lref: LocalReferencePosition) => boolean | void | undefined,\n\t\tstart?: LocalReferencePosition,\n\t\tforward: boolean = true,\n\t): boolean {\n\t\tif (start !== undefined) {\n\t\t\tif (!this.has(start)) {\n\t\t\t\tthrow new UsageError(\"start must be in collection\");\n\t\t\t}\n\t\t\tassertLocalReferences(start);\n\t\t}\n\t\tlet offset = start?.getOffset() ?? (forward ? 0 : this.segment.cachedLength - 1);\n\n\t\tconst offsetPositions: DoublyLinkedList<IRefsAtOffset[keyof IRefsAtOffset]> =\n\t\t\tnew DoublyLinkedList();\n\t\toffsetPositions.push(\n\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\tthis.refsByOffset[offset]?.after,\n\t\t);\n\n\t\tconst startNode = start?.getListNode();\n\t\tconst startList = startNode?.list;\n\n\t\tif (startList !== undefined) {\n\t\t\tif (forward) {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.first !== startNode) {\n\t\t\t\t\toffsetPositions.shift();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.last !== startNode) {\n\t\t\t\t\toffsetPositions.pop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst listWalker = (pos: DoublyLinkedList<LocalReference>): boolean => {\n\t\t\treturn walkList(\n\t\t\t\tpos,\n\t\t\t\t(node) => visitor(node.data),\n\t\t\t\tstartList === pos ? startNode : undefined,\n\t\t\t\tforward,\n\t\t\t);\n\t\t};\n\t\tconst increment = forward ? 1 : -1;\n\t\twhile (offset >= 0 && offset < this.refsByOffset.length) {\n\t\t\twhile (offsetPositions.length > 0) {\n\t\t\t\tconst offsetPos = forward ? offsetPositions.shift() : offsetPositions.pop();\n\t\t\t\tif (offsetPos?.data !== undefined && listWalker(offsetPos.data) === false) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\toffset += increment;\n\t\t\toffsetPositions.push(\n\t\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\t\tthis.refsByOffset[offset]?.after,\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"localReference.js","sourceRoot":"","sources":["../src/localReference.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAY,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAE9E,OAAO,EAAiB,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAChF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AAC;YACzD,OAAO,eAAe,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACnC,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,eAAe,CAAC,GAAG,EAAE,CAAC;gBAC5E,IAAI,SAAS,EAAE,IAAI,KAAK,SAAS,IAAI,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,KAAK,EAAE,CAAC;oBAC3E,OAAO,KAAK,CAAC;gBACd,CAAC;YACF,CAAC;YACD,MAAM,IAAI,SAAS,CAAC;YACpB,eAAe,CAAC,IAAI,CACnB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,MAAM,EACjC,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,EAAE,EAC7B,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,EAAE,KAAK,CAChC,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACb,CAAC;CACD","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 { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { DoublyLinkedList, ListNode, walkList } from \"./collections/index.js\";\nimport { type ISegmentInternal } from \"./mergeTreeNodes.js\";\nimport { TrackingGroup, TrackingGroupCollection } from \"./mergeTreeTracking.js\";\nimport { ReferenceType } from \"./ops.js\";\nimport { PropertySet, addProperties } from \"./properties.js\";\nimport { ReferencePosition, refTypeIncludesFlag } from \"./referencePositions.js\";\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy\n * @alpha\n */\nexport const SlidingPreference = {\n\t/**\n\t * Prefer sliding towards the start of the tree\n\t */\n\tBACKWARD: 0,\n\t/**\n\t * Prefer sliding towards the end of the tree\n\t */\n\tFORWARD: 1,\n} as const;\n\n/**\n * Dictates the preferential direction for a {@link ReferencePosition} to slide\n * in a merge-tree\n * @legacy\n * @alpha\n */\nexport type SlidingPreference = (typeof SlidingPreference)[keyof typeof SlidingPreference];\n\nfunction _validateReferenceType(refType: ReferenceType): void {\n\tlet exclusiveCount = 0;\n\tif (refTypeIncludesFlag(refType, ReferenceType.Transient)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.SlideOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (refTypeIncludesFlag(refType, ReferenceType.StayOnRemove)) {\n\t\t++exclusiveCount;\n\t}\n\tif (exclusiveCount > 1) {\n\t\tthrow new UsageError(\n\t\t\t\"Reference types can only be one of Transient, SlideOnRemove, and StayOnRemove\",\n\t\t);\n\t}\n}\n/**\n * @sealed\n * @legacy\n * @alpha\n */\nexport interface LocalReferencePosition extends ReferencePosition {\n\tcallbacks?: Partial<\n\t\tRecord<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>\n\t>;\n\treadonly trackingCollection: TrackingGroupCollection;\n\t/**\n\t * Whether or not this reference position can slide onto one of the two\n\t * special segments representing the position before or after the tree\n\t */\n\treadonly canSlideToEndpoint?: boolean;\n\n\t/**\n\t * @param newProps - Properties to add to this reference.\n\t * @remarks Note that merge-tree does not broadcast changes to other clients. It is up to the consumer\n\t * to ensure broadcast happens if that is desired.\n\t */\n\taddProperties(newProps: PropertySet): void;\n}\n\n/**\n * @privateRemarks This should not be exported outside merge tree.\n * @internal\n */\nclass LocalReference implements LocalReferencePosition {\n\tpublic properties: PropertySet | undefined;\n\n\tprivate segment: ISegmentInternal | undefined;\n\tprivate offset: number = 0;\n\tprivate listNode: ListNode<LocalReference> | undefined;\n\n\tpublic callbacks?:\n\t\t| Partial<Record<\"beforeSlide\" | \"afterSlide\", (ref: LocalReferencePosition) => void>>\n\t\t| undefined;\n\tprivate _trackingCollection?: TrackingGroupCollection;\n\tpublic get trackingCollection(): TrackingGroupCollection {\n\t\treturn (this._trackingCollection ??= new TrackingGroupCollection(this));\n\t}\n\n\tconstructor(\n\t\tpublic refType = ReferenceType.Simple,\n\t\tproperties?: PropertySet,\n\t\tpublic readonly slidingPreference: SlidingPreference = SlidingPreference.FORWARD,\n\t\tpublic readonly canSlideToEndpoint?: boolean,\n\t) {\n\t\t_validateReferenceType(refType);\n\t\tthis.properties = properties;\n\t}\n\n\tpublic link(\n\t\tsegment: ISegmentInternal | undefined,\n\t\toffset: number,\n\t\tlistNode: ListNode<LocalReference> | undefined,\n\t): void {\n\t\tif (listNode !== this.listNode && this.listNode !== undefined) {\n\t\t\tthis.segment?.localRefs?.removeLocalRef(this);\n\t\t}\n\t\tthis.listNode = listNode;\n\n\t\tif (segment !== this.segment) {\n\t\t\tconst groups: TrackingGroup[] = [];\n\t\t\tfor (const tg of this.trackingCollection.trackingGroups) {\n\t\t\t\ttg.unlink(this);\n\t\t\t\tgroups.push(tg);\n\t\t\t}\n\n\t\t\tthis.segment = segment;\n\n\t\t\tfor (const tg of groups) tg.link(this);\n\t\t}\n\t\tthis.offset = offset;\n\t}\n\n\tpublic isLeaf(): this is ISegmentInternal {\n\t\treturn false;\n\t}\n\n\tpublic addProperties(newProps: PropertySet): void {\n\t\tthis.properties = addProperties(this.properties, newProps);\n\t}\n\n\tpublic getSegment(): ISegmentInternal | undefined {\n\t\treturn this.segment;\n\t}\n\n\tpublic getOffset(): number {\n\t\treturn this.offset;\n\t}\n\n\tpublic getListNode(): ListNode<LocalReference> | undefined {\n\t\treturn this.listNode;\n\t}\n\n\tpublic getProperties(): PropertySet | undefined {\n\t\treturn this.properties;\n\t}\n}\n\n/**\n * Creates a new detached local reference.\n * @internal\n */\nexport function createDetachedLocalReferencePosition(\n\tslidingPreference: SlidingPreference | undefined,\n\trefType?: ReferenceType,\n): LocalReferencePosition {\n\treturn new LocalReference(refType, undefined, slidingPreference);\n}\n\ninterface IRefsAtOffset {\n\tbefore?: DoublyLinkedList<LocalReference>;\n\tat?: DoublyLinkedList<LocalReference>;\n\tafter?: DoublyLinkedList<LocalReference>;\n}\n\nfunction assertLocalReferences(lref: unknown): asserts lref is LocalReference {\n\tassert(lref instanceof LocalReference, 0x2e0 /* \"lref not a Local Reference\" */);\n}\n\n/**\n * Determines if the given function is true for any position within the collection.\n */\nexport function anyLocalReferencePosition(\n\tcollection: LocalReferenceCollection,\n\tfunc: (pos: LocalReferencePosition) => boolean,\n): boolean {\n\tfor (const pos of collection) {\n\t\tif (func(pos)) {\n\t\t\treturn true;\n\t\t}\n\t}\n\n\treturn false;\n}\n\n/**\n * Finds the local reference positions that satisfy the given predicate.\n */\nexport function* filterLocalReferencePositions(\n\tcollection: LocalReferenceCollection,\n\tpredicate: (pos: LocalReferencePosition) => boolean,\n): Generator<LocalReferencePosition> {\n\tfor (const pos of collection) {\n\t\tif (predicate(pos)) {\n\t\t\tyield pos;\n\t\t}\n\t}\n}\n\n/**\n * Injectable hook for validating that the refCount property matches the\n * expected value\n */\nlet validateRefCount: ((collection?: LocalReferenceCollection) => void) | undefined;\n\nexport function setValidateRefCount(\n\tcb?: (collection?: LocalReferenceCollection) => void,\n): void {\n\tvalidateRefCount = cb;\n}\n\n/**\n * Represents a collection of {@link LocalReferencePosition}s associated with\n * one segment in a merge-tree.\n * Represents a collection of {@link LocalReferencePosition}s associated with one segment in a merge-tree.\n * @sealed\n *\n * @internal\n */\nexport class LocalReferenceCollection {\n\tpublic static append(seg1: ISegmentInternal, seg2: ISegmentInternal): void {\n\t\tif (seg2.localRefs && !seg2.localRefs.empty) {\n\t\t\tif (!seg1.localRefs) {\n\t\t\t\tseg1.localRefs = new LocalReferenceCollection(seg1);\n\t\t\t}\n\t\t\tassert(\n\t\t\t\tseg1.localRefs.refsByOffset.length === seg1.cachedLength,\n\t\t\t\t0x2be /* \"LocalReferences array contains a gap\" */,\n\t\t\t);\n\t\t\tseg1.localRefs.append(seg2.localRefs);\n\t\t} else if (seg1.localRefs) {\n\t\t\t// Since creating the LocalReferenceCollection, we may have appended\n\t\t\t// segments that had no local references. Account for them now by padding the array.\n\t\t\tseg1.localRefs.refsByOffset.length += seg2.cachedLength;\n\t\t}\n\t\tvalidateRefCount?.(seg1.localRefs);\n\t\tvalidateRefCount?.(seg2.localRefs);\n\t}\n\n\tpublic static setOrGet(segment: ISegmentInternal): LocalReferenceCollection {\n\t\treturn (segment.localRefs ??= new LocalReferenceCollection(segment));\n\t}\n\n\tprivate readonly refsByOffset: (IRefsAtOffset | undefined)[];\n\tprivate refCount: number = 0;\n\n\tprivate constructor(\n\t\t/**\n\t\t * The segment this `LocalReferenceCollection` is associated with.\n\t\t */\n\t\tprivate readonly segment: ISegmentInternal,\n\t\tinitialRefsByfOffset: (IRefsAtOffset | undefined)[] = Array.from({\n\t\t\tlength: segment.cachedLength,\n\t\t}),\n\t) {\n\t\t// Since javascript arrays are sparse the above won't populate any of the\n\t\t// indices, but it will ensure the length property of the array matches\n\t\t// the length of the segment.\n\t\tthis.refsByOffset = initialRefsByfOffset;\n\t}\n\n\t/**\n\t * Returns an iterator over this LocalReferenceCollection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic [Symbol.iterator](): {\n\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t} {\n\t\tconst subiterators: IterableIterator<ListNode<LocalReferencePosition>>[] = [];\n\t\tfor (const refs of this.refsByOffset) {\n\t\t\tif (refs) {\n\t\t\t\tif (refs.before) {\n\t\t\t\t\tsubiterators.push(refs.before[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.at) {\n\t\t\t\t\tsubiterators.push(refs.at[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t\tif (refs.after) {\n\t\t\t\t\tsubiterators.push(refs.after[Symbol.iterator]());\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst iterator = {\n\t\t\tnext(): IteratorResult<LocalReferencePosition> {\n\t\t\t\twhile (subiterators.length > 0) {\n\t\t\t\t\tconst next = subiterators[0].next();\n\t\t\t\t\tif (next.done === true) {\n\t\t\t\t\t\tsubiterators.shift();\n\t\t\t\t\t} else {\n\t\t\t\t\t\treturn { done: next.done, value: next.value.data };\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn { value: undefined, done: true };\n\t\t\t},\n\t\t\t[Symbol.iterator](): {\n\t\t\t\tnext(): IteratorResult<LocalReferencePosition>;\n\t\t\t\t[Symbol.iterator](): IterableIterator<LocalReferencePosition>;\n\t\t\t} {\n\t\t\t\treturn this;\n\t\t\t},\n\t\t};\n\t\treturn iterator;\n\t}\n\n\t/**\n\t * Determines if the collection has no references in it.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic get empty(): boolean {\n\t\tvalidateRefCount?.(this);\n\t\treturn this.refCount === 0;\n\t}\n\n\t/**\n\t * Creates a new local reference.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic createLocalRef(\n\t\toffset: number,\n\t\trefType: ReferenceType,\n\t\tproperties: PropertySet | undefined,\n\t\tslidingPreference?: SlidingPreference,\n\t\tcanSlideToEndpoint?: boolean,\n\t): LocalReferencePosition {\n\t\tconst ref = new LocalReference(refType, properties, slidingPreference, canSlideToEndpoint);\n\t\tref.link(this.segment, offset, undefined);\n\t\tif (!refTypeIncludesFlag(ref, ReferenceType.Transient)) {\n\t\t\tthis.addLocalRef(ref, offset);\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t\treturn ref;\n\t}\n\n\t/**\n\t * Adds a local reference to the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addLocalRef(lref: LocalReferencePosition, offset: number): void {\n\t\tassertLocalReferences(lref);\n\t\tassert(\n\t\t\toffset < this.segment.cachedLength,\n\t\t\t0x348 /* offset cannot be beyond segment length */,\n\t\t);\n\t\tif (refTypeIncludesFlag(lref, ReferenceType.Transient)) {\n\t\t\tlref.link(this.segment, offset, undefined);\n\t\t} else {\n\t\t\tconst refsAtOffset = (this.refsByOffset[offset] = this.refsByOffset[offset] ?? {\n\t\t\t\tat: new DoublyLinkedList(),\n\t\t\t});\n\t\t\tconst atRefs = (refsAtOffset.at = refsAtOffset.at ?? new DoublyLinkedList());\n\n\t\t\tlref.link(this.segment, offset, atRefs.push(lref).last);\n\n\t\t\tthis.refCount++;\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Removes a local reference from the collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic removeLocalRef(lref: LocalReferencePosition): LocalReferencePosition | undefined {\n\t\tif (this.has(lref)) {\n\t\t\tassertLocalReferences(lref);\n\n\t\t\tconst node = lref.getListNode();\n\t\t\tnode?.list?.remove(node);\n\n\t\t\tlref.link(undefined, 0, undefined);\n\n\t\t\tthis.refCount--;\n\t\t\tvalidateRefCount?.(this);\n\t\t\treturn lref;\n\t\t}\n\t}\n\n\t/**\n\t *\n\t * Called by 'append()' implementations to append local refs from the given 'other' segment to the\n\t * end of 'this' segment.\n\t *\n\t * Note: This method should be invoked after the caller has ensured that segments can be merged,\n\t * but before 'this' segment's cachedLength has changed, or the adjustment to the local refs\n\t * will be incorrect.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic append(other: LocalReferenceCollection): void {\n\t\tif (!other || other.empty) {\n\t\t\treturn;\n\t\t}\n\t\tthis.refCount += other.refCount;\n\t\tother.refCount = 0;\n\t\tfor (const lref of other) {\n\t\t\tassertLocalReferences(lref);\n\t\t\tlref.link(this.segment, lref.getOffset() + this.refsByOffset.length, lref.getListNode());\n\t\t}\n\n\t\tthis.refsByOffset.push(...other.refsByOffset);\n\t\tother.refsByOffset.length = 0;\n\t}\n\t/**\n\t * Returns true of the local reference is in the collection, otherwise false.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic has(lref: ReferencePosition): boolean {\n\t\tif (\n\t\t\t!(lref instanceof LocalReference) ||\n\t\t\trefTypeIncludesFlag(lref, ReferenceType.Transient)\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tconst seg = lref.getSegment();\n\t\tif (seg !== this.segment) {\n\t\t\treturn false;\n\t\t}\n\t\t// we should be able to optimize finding the\n\t\t// list head\n\t\tconst listNode = lref.getListNode();\n\t\tif (listNode === undefined) {\n\t\t\treturn false;\n\t\t}\n\t\tconst offset = lref.getOffset();\n\t\tconst refsAtOffset = this.refsByOffset[offset];\n\t\tif (\n\t\t\t!!refsAtOffset?.before?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.at?.includes(listNode) ||\n\t\t\t!!refsAtOffset?.after?.includes(listNode)\n\t\t) {\n\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Splits this `LocalReferenceCollection` into the intervals [0, offset) and [offset, originalLength).\n\t * Local references in the former half of this split will remain associated with the segment used on construction.\n\t * Local references in the latter half of this split will be transferred to `splitSeg`,\n\t * and its `localRefs` field will be set.\n\t * @param offset - Offset into the original segment at which the collection should be split\n\t * @param splitSeg - Split segment which originally corresponded to the indices [offset, originalLength)\n\t * before splitting.\n\t *\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic split(offset: number, splitSeg: ISegmentInternal): void {\n\t\tif (this.empty) {\n\t\t\t// shrink the offset array when empty and splitting\n\t\t\tthis.refsByOffset.length = offset;\n\t\t} else {\n\t\t\tconst localRefs = new LocalReferenceCollection(\n\t\t\t\tsplitSeg,\n\t\t\t\tthis.refsByOffset.splice(offset, this.refsByOffset.length - offset),\n\t\t\t);\n\n\t\t\tsplitSeg.localRefs = localRefs;\n\t\t\tfor (const lref of localRefs) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tlref.link(splitSeg, lref.getOffset() - offset, lref.getListNode());\n\t\t\t\tthis.refCount--;\n\t\t\t\tlocalRefs.refCount++;\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Insert a reference before tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addBeforeTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst beforeRefs = this.refsByOffset[0]?.before ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[0]?.before === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[0] ??= { before: beforeRefs });\n\t\t\trefsAtOffset.before ??= beforeRefs;\n\t\t}\n\n\t\tlet precedingRef: ListNode<LocalReference> | undefined;\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tprecedingRef =\n\t\t\t\t\t\tprecedingRef === undefined\n\t\t\t\t\t\t\t? beforeRefs.unshift(lref)?.first\n\t\t\t\t\t\t\t: beforeRefs.insertAfter(precedingRef, lref)?.first;\n\t\t\t\t\tlref.link(this.segment, 0, precedingRef);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\t/**\n\t * Insert a reference after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic addAfterTombstones(...refs: Iterable<LocalReferencePosition>[]): void {\n\t\tconst lastOffset = this.segment.cachedLength - 1;\n\t\tconst afterRefs = this.refsByOffset[lastOffset]?.after ?? new DoublyLinkedList();\n\n\t\tif (this.refsByOffset[lastOffset]?.after === undefined) {\n\t\t\tconst refsAtOffset = (this.refsByOffset[lastOffset] ??= { after: afterRefs });\n\t\t\trefsAtOffset.after ??= afterRefs;\n\t\t}\n\n\t\tfor (const iterable of refs) {\n\t\t\tfor (const lref of iterable) {\n\t\t\t\tassertLocalReferences(lref);\n\t\t\t\tif (refTypeIncludesFlag(lref, ReferenceType.StayOnRemove)) {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else if (refTypeIncludesFlag(lref, ReferenceType.SlideOnRemove)) {\n\t\t\t\t\tlref.callbacks?.beforeSlide?.(lref);\n\t\t\t\t\tafterRefs.push(lref);\n\t\t\t\t\tlref.link(this.segment, lastOffset, afterRefs.last);\n\t\t\t\t\tthis.refCount++;\n\t\t\t\t\tlref.callbacks?.afterSlide?.(lref);\n\t\t\t\t} else {\n\t\t\t\t\tlref.link(undefined, 0, undefined);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tvalidateRefCount?.(this);\n\t}\n\n\t/**\n\t * Determines if a reference is after tombstoned references.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic isAfterTombstone(lref: LocalReferencePosition): boolean {\n\t\tconst after = this.refsByOffset[lref.getOffset()]?.after;\n\t\tif (after) {\n\t\t\tassertLocalReferences(lref);\n\t\t\treturn after.includes(lref.getListNode());\n\t\t}\n\t\treturn false;\n\t}\n\n\t/**\n\t * Walks all of the references in a collection.\n\t * @remarks This method should only be called by mergeTree.\n\t */\n\tpublic walkReferences(\n\t\tvisitor: (lref: LocalReferencePosition) => boolean | void | undefined,\n\t\tstart?: LocalReferencePosition,\n\t\tforward: boolean = true,\n\t): boolean {\n\t\tif (start !== undefined) {\n\t\t\tif (!this.has(start)) {\n\t\t\t\tthrow new UsageError(\"start must be in collection\");\n\t\t\t}\n\t\t\tassertLocalReferences(start);\n\t\t}\n\t\tlet offset = start?.getOffset() ?? (forward ? 0 : this.segment.cachedLength - 1);\n\n\t\tconst offsetPositions: DoublyLinkedList<IRefsAtOffset[keyof IRefsAtOffset]> =\n\t\t\tnew DoublyLinkedList();\n\t\toffsetPositions.push(\n\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\tthis.refsByOffset[offset]?.after,\n\t\t);\n\n\t\tconst startNode = start?.getListNode();\n\t\tconst startList = startNode?.list;\n\n\t\tif (startList !== undefined) {\n\t\t\tif (forward) {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.first !== startNode) {\n\t\t\t\t\toffsetPositions.shift();\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\twhile (!offsetPositions.empty && offsetPositions.last !== startNode) {\n\t\t\t\t\toffsetPositions.pop();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst listWalker = (pos: DoublyLinkedList<LocalReference>): boolean => {\n\t\t\treturn walkList(\n\t\t\t\tpos,\n\t\t\t\t(node) => visitor(node.data),\n\t\t\t\tstartList === pos ? startNode : undefined,\n\t\t\t\tforward,\n\t\t\t);\n\t\t};\n\t\tconst increment = forward ? 1 : -1;\n\t\twhile (offset >= 0 && offset < this.refsByOffset.length) {\n\t\t\twhile (offsetPositions.length > 0) {\n\t\t\t\tconst offsetPos = forward ? offsetPositions.shift() : offsetPositions.pop();\n\t\t\t\tif (offsetPos?.data !== undefined && listWalker(offsetPos.data) === false) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\toffset += increment;\n\t\t\toffsetPositions.push(\n\t\t\t\tthis.refsByOffset[offset]?.before,\n\t\t\t\tthis.refsByOffset[offset]?.at,\n\t\t\t\tthis.refsByOffset[offset]?.after,\n\t\t\t);\n\t\t}\n\t\treturn true;\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTree.d.ts","sourceRoot":"","sources":["../src/mergeTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAU,IAAI,EAAa,MAAM,qCAAqC,CAAC;AAG9E,OAAO,EAAE,gCAAgC,EAAE,MAAM,4BAA4B,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,gBAAgB,EAAY,MAAM,wBAAwB,CAAC;AAOpE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAA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IAAI;IAqBP;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,OAAO,CAAC,OAAO;CA4Df"}
package/lib/mergeTree.js CHANGED
@@ -280,6 +280,8 @@ export class MergeTree {
280
280
  // for now assume only markers have ids and so point directly at the Segment
281
281
  // if we need to have pointers to non-markers, we can change to point at local refs
282
282
  this.idToMarker = new Map();
283
+ // TODO:AB#29553: This property doesn't seem to be adequately round-tripped through summarization.
284
+ // Specifically, it seems like we drop information about obliterates within the collab window for at least V1 summaries.
283
285
  this.obliterates = new Obliterates(this);
284
286
  this.splitLeafSegment = (segment, pos) => {
285
287
  if (!(pos > 0 && segment)) {
@@ -288,11 +290,11 @@ export class MergeTree {
288
290
  const next = segment.splitAt(pos);
289
291
  assertSegmentLeaf(next);
290
292
  if (segment?.segmentGroups) {
291
- next.segmentGroups ?? (next.segmentGroups = new SegmentGroupCollection(next));
293
+ next.segmentGroups ??= new SegmentGroupCollection(next);
292
294
  segment.segmentGroups.copyTo(next.segmentGroups);
293
295
  }
294
- if (segment.prevObliterateByInserter) {
295
- next.prevObliterateByInserter = segment.prevObliterateByInserter;
296
+ if (segment.obliteratePrecedingInsertion) {
297
+ next.obliteratePrecedingInsertion = segment.obliteratePrecedingInsertion;
296
298
  }
297
299
  copyPropertiesAndManager(segment, next);
298
300
  if (segment.localRefs) {
@@ -789,7 +791,7 @@ export class MergeTree {
789
791
  const overlappingRemoves = [];
790
792
  pendingSegmentGroup.segments.map((pendingSegment) => {
791
793
  const overlappingRemove = !ackSegment(pendingSegment, pendingSegmentGroup, opArgs);
792
- overwrite = overlappingRemove || overwrite;
794
+ overwrite ||= overlappingRemove || toMoveInfo(pendingSegment) !== undefined;
793
795
  overlappingRemoves.push(overlappingRemove);
794
796
  if (MergeTree.options.zamboniSegments) {
795
797
  this.addToLRUSet(pendingSegment, seq);
@@ -845,7 +847,7 @@ export class MergeTree {
845
847
  if (previousProps) {
846
848
  _segmentGroup.previousProps.push(previousProps);
847
849
  }
848
- const segmentGroups = (segment.segmentGroups ?? (segment.segmentGroups = new SegmentGroupCollection(segment)));
850
+ const segmentGroups = (segment.segmentGroups ??= new SegmentGroupCollection(segment));
849
851
  segmentGroups.enqueue(_segmentGroup);
850
852
  return _segmentGroup;
851
853
  }
@@ -1021,6 +1023,8 @@ export class MergeTree {
1021
1023
  let normalizedNewestSeq = 0;
1022
1024
  const movedClientIds = [];
1023
1025
  const movedSeqs = [];
1026
+ let newestAcked;
1027
+ let oldestUnacked;
1024
1028
  for (const ob of this.obliterates.findOverlapping(newSegment)) {
1025
1029
  // compute a normalized seq that takes into account local seqs
1026
1030
  // but is still comparable to remote seqs to keep the checks below easy
@@ -1030,42 +1034,81 @@ export class MergeTree {
1030
1034
  ? Number.MAX_SAFE_INTEGER - this.collabWindow.localSeq + ob.localSeq
1031
1035
  : ob.seq;
1032
1036
  if (normalizedObSeq > refSeq) {
1033
- if (oldest === undefined || normalizedOldestSeq > normalizedObSeq) {
1034
- normalizedOldestSeq = normalizedObSeq;
1035
- oldest = ob;
1036
- movedClientIds.unshift(ob.clientId);
1037
- movedSeqs.unshift(ob.seq);
1038
- }
1039
- else {
1040
- movedClientIds.push(ob.clientId);
1041
- movedSeqs.push(ob.seq);
1037
+ // Any obliterate from the same client that's inserting this segment cannot cause the segment to be marked as
1038
+ // obliterated (since that client must have performed the obliterate before this insertion).
1039
+ // We still need to consider such obliterates when determining the winning obliterate for the insertion point,
1040
+ // see `obliteratePrecedingInsertion` docs.
1041
+ if (clientId !== ob.clientId) {
1042
+ if (oldest === undefined || normalizedOldestSeq > normalizedObSeq) {
1043
+ normalizedOldestSeq = normalizedObSeq;
1044
+ oldest = ob;
1045
+ movedClientIds.unshift(ob.clientId);
1046
+ movedSeqs.unshift(ob.seq);
1047
+ }
1048
+ else {
1049
+ movedClientIds.push(ob.clientId);
1050
+ movedSeqs.push(ob.seq);
1051
+ }
1042
1052
  }
1043
1053
  if (newest === undefined || normalizedNewestSeq < normalizedObSeq) {
1044
1054
  normalizedNewestSeq = normalizedObSeq;
1045
1055
  newest = ob;
1046
1056
  }
1057
+ if (ob.seq !== UnassignedSequenceNumber &&
1058
+ (newestAcked === undefined || newestAcked.seq < ob.seq)) {
1059
+ newestAcked = ob;
1060
+ }
1061
+ if (ob.seq === UnassignedSequenceNumber &&
1062
+ (oldestUnacked === undefined || oldestUnacked.localSeq > ob.localSeq)) {
1063
+ // There can be one local obliterate surrounding a segment if a client repeatedly obliterates
1064
+ // a region (ex: in the text ABCDEFG, obliterate D, then obliterate CE, then BF). In this case,
1065
+ // the first one that's applied will be the one that actually removes the segment.
1066
+ oldestUnacked = ob;
1067
+ }
1047
1068
  }
1048
1069
  }
1070
+ newSegment.obliteratePrecedingInsertion = newest;
1071
+ // See doc comment on obliteratePrecedingInsertion for more details: if the newest obliterate was performed
1072
+ // by the same client that's inserting this segment, we let them insert into this range and therefore don't
1073
+ // mark it obliterated.
1049
1074
  if (oldest && newest?.clientId !== clientId) {
1050
- const moveInfo = {
1051
- movedClientIds,
1052
- movedSeq: oldest.seq,
1053
- movedSeqs,
1054
- localMovedSeq: oldest.localSeq,
1055
- wasMovedOnInsert: oldest.seq !== UnassignedSequenceNumber,
1056
- };
1075
+ let moveInfo;
1076
+ if (newestAcked === newest || newestAcked?.clientId !== clientId) {
1077
+ moveInfo = {
1078
+ movedClientIds,
1079
+ movedSeq: oldest.seq,
1080
+ movedSeqs,
1081
+ localMovedSeq: oldestUnacked?.localSeq,
1082
+ wasMovedOnInsert: oldest.seq !== UnassignedSequenceNumber,
1083
+ };
1084
+ }
1085
+ else {
1086
+ assert(oldestUnacked !== undefined, "Expected local obliterate to be defined if newestAcked is not equal to newest");
1087
+ // There's a pending local obliterate for this range, so it will be marked as obliterated by us. However,
1088
+ // all other clients are under the impression that the most recent acked obliterate won the right to insert
1089
+ // in this range.
1090
+ moveInfo = {
1091
+ movedClientIds: [oldestUnacked.clientId],
1092
+ movedSeq: oldestUnacked.seq,
1093
+ movedSeqs: [oldestUnacked.seq],
1094
+ localMovedSeq: oldestUnacked.localSeq,
1095
+ wasMovedOnInsert: false,
1096
+ };
1097
+ }
1057
1098
  overwriteInfo(newSegment, moveInfo);
1058
1099
  if (moveInfo.localMovedSeq !== undefined) {
1059
- assert(oldest.segmentGroup !== undefined, 0x86c /* expected segment group to exist */);
1060
- this.addToPendingList(newSegment, oldest.segmentGroup);
1100
+ assert(oldestUnacked?.segmentGroup !== undefined, 0x86c /* expected segment group to exist */);
1101
+ this.addToPendingList(newSegment, oldestUnacked?.segmentGroup);
1061
1102
  }
1062
1103
  if (newSegment.parent) {
1063
- this.blockUpdatePathLengths(newSegment.parent, seq, clientId);
1104
+ // The incremental update codepath in theory can handle most cases where segments are obliterated upon insertion,
1105
+ // but it's not idempotent with respect to segment insertion in the first place. Since we already update partial
1106
+ // lengths inside the inserting walk, we'd be at risk of double-counting the insertion in any case if we allow
1107
+ // incremental updates here.
1108
+ const newStructure = true;
1109
+ this.blockUpdatePathLengths(newSegment.parent, moveInfo.movedSeq, clientId, newStructure);
1064
1110
  }
1065
1111
  }
1066
- else if (oldest && newest?.clientId === clientId) {
1067
- newSegment.prevObliterateByInserter = newest;
1068
- }
1069
1112
  saveIfLocal(newSegment);
1070
1113
  }
1071
1114
  }
@@ -1241,7 +1284,7 @@ export class MergeTree {
1241
1284
  assert(!Marker.is(segment) ||
1242
1285
  !(reservedMarkerIdKey in opObj) ||
1243
1286
  opObj.markerId === segment.properties?.markerId, 0x5ad /* Cannot change the markerId of an existing marker */);
1244
- const propertyManager = (segment.propertyManager ?? (segment.propertyManager = new PropertiesManager()));
1287
+ const propertyManager = (segment.propertyManager ??= new PropertiesManager());
1245
1288
  const propertyDeltas = propertyManager.handleProperties(propsOrAdjust, segment, seq, this.collabWindow.minSeq, this.collabWindow.collaborating, rollback);
1246
1289
  if (!isRemovedOrMoved(segment)) {
1247
1290
  deltaSegments.push({ segment, propertyDeltas });
@@ -1317,40 +1360,53 @@ export class MergeTree {
1317
1360
  if ((start.side === Side.After && startPos === pos + segment.cachedLength) || // exclusive start segment
1318
1361
  (end.side === Side.Before &&
1319
1362
  endPos === pos &&
1320
- isSegmentPresent(segment, { refSeq, localSeq })) // exclusive end segment
1363
+ // TODO:AB#29765: The clientId check here should be handled by isSegmentPresent and/or PerspectiveImpl
1364
+ (segment.clientId === clientId || isSegmentPresent(segment, { refSeq, localSeq }))) // exclusive end segment
1321
1365
  ) {
1322
1366
  // We walk these segments because we want to also walk any concurrently inserted segments between here and the obliterated segments.
1323
1367
  // These segments are outside of the obliteration range though, so return true to keep walking.
1324
1368
  return true;
1325
1369
  }
1326
1370
  const existingMoveInfo = toMoveInfo(segment);
1327
- if (segment.prevObliterateByInserter?.seq === UnassignedSequenceNumber) {
1371
+ // The "last-to-obliterate-gets-to-insert" policy described by the doc comment on `obliteratePrecedingInsertion`
1372
+ // is mostly handled by logic at insertion time, but we need a small bit of handling here.
1373
+ // Specifically, we want to avoid marking a local-only segment as obliterated when we know one of our own local obliterates
1374
+ // will win against the obliterate we're processing, hence the early exit.
1375
+ if (segment.seq === UnassignedSequenceNumber &&
1376
+ segment.obliteratePrecedingInsertion?.seq === UnassignedSequenceNumber &&
1377
+ seq !== UnassignedSequenceNumber) {
1328
1378
  // We chose to not obliterate this segment because we are aware of an unacked local obliteration.
1329
1379
  // The local obliterate has not been sequenced yet, so it is still the newest obliterate we are aware of.
1330
1380
  // Other clients will also choose not to obliterate this segment because the most recent obliteration has the same clientId
1331
1381
  return true;
1332
1382
  }
1333
- const wasMovedOnInsert = clientId !== segment.clientId &&
1334
- segment.seq !== undefined &&
1335
- seq !== UnassignedSequenceNumber &&
1336
- (refSeq < segment.seq || segment.seq === UnassignedSequenceNumber);
1383
+ // Partial lengths incrementality is not supported for overlapping obliterate/removes.
1384
+ _overwrite ||= existingMoveInfo !== undefined || toRemovalInfo(segment) !== undefined;
1337
1385
  if (existingMoveInfo === undefined) {
1338
1386
  const movedSeg = overwriteInfo(segment, {
1339
1387
  movedClientIds: [clientId],
1340
1388
  movedSeq: seq,
1341
1389
  localMovedSeq: localSeq,
1342
1390
  movedSeqs: [seq],
1343
- wasMovedOnInsert,
1391
+ wasMovedOnInsert: segment.seq === UnassignedSequenceNumber && seq !== UnassignedSequenceNumber,
1344
1392
  });
1345
- if (!toRemovalInfo(movedSeg)) {
1393
+ const existingRemoval = toRemovalInfo(movedSeg);
1394
+ if (existingRemoval === undefined) {
1346
1395
  movedSegments.push(movedSeg);
1347
1396
  }
1397
+ else if (existingRemoval.removedSeq === UnassignedSequenceNumber &&
1398
+ segment.localRefs?.empty === false) {
1399
+ // We removed this locally already so we don't need to event it again, but it might have references
1400
+ // that need sliding now that a move may have been acked.
1401
+ localOverlapWithRefs.push(segment);
1402
+ }
1348
1403
  }
1349
1404
  else {
1350
- _overwrite = true;
1351
- // never move wasMovedOnInsert from true to false
1352
- existingMoveInfo.wasMovedOnInsert || (existingMoveInfo.wasMovedOnInsert = wasMovedOnInsert);
1353
1405
  if (existingMoveInfo.movedSeq === UnassignedSequenceNumber) {
1406
+ // Should not need explicit set here, but this should be implied:
1407
+ assert(!existingMoveInfo.wasMovedOnInsert, 0xab4 /* Local obliterate cannot have removed a segment as soon as it was inserted */);
1408
+ assert(seq !== UnassignedSequenceNumber, 0xab5 /* Cannot obliterate the same segment locally twice */);
1409
+ existingMoveInfo.wasMovedOnInsert = segment.seq === UnassignedSequenceNumber;
1354
1410
  // we moved this locally, but someone else moved it first
1355
1411
  // so put them at the head of the list
1356
1412
  // The list isn't ordered, but we keep the first move at the head
@@ -1435,18 +1491,26 @@ export class MergeTree {
1435
1491
  const localSeq = seq === UnassignedSequenceNumber ? ++this.collabWindow.localSeq : undefined;
1436
1492
  const markRemoved = (segment, pos, _start, _end) => {
1437
1493
  const existingRemovalInfo = toRemovalInfo(segment);
1494
+ // Partial lengths incrementality is not supported for overlapping obliterate/removes.
1495
+ _overwrite ||= existingRemovalInfo !== undefined || toMoveInfo(segment) !== undefined;
1438
1496
  if (existingRemovalInfo === undefined) {
1439
1497
  const removed = overwriteInfo(segment, {
1440
1498
  removedClientIds: [clientId],
1441
1499
  removedSeq: seq,
1442
1500
  localRemovedSeq: localSeq,
1443
1501
  });
1444
- if (!toMoveInfo(removed)) {
1502
+ const existingMoveInfo = toMoveInfo(removed);
1503
+ if (existingMoveInfo === undefined) {
1445
1504
  removedSegments.push(removed);
1446
1505
  }
1506
+ else if (existingMoveInfo.movedSeq === UnassignedSequenceNumber &&
1507
+ segment.localRefs?.empty === false) {
1508
+ // We moved this locally already so we don't need to event it again, but it might have references
1509
+ // that need sliding now that a remove may have been acked.
1510
+ localOverlapWithRefs.push(segment);
1511
+ }
1447
1512
  }
1448
1513
  else {
1449
- _overwrite = true;
1450
1514
  if (existingRemovalInfo.removedSeq === UnassignedSequenceNumber) {
1451
1515
  // we removed this locally, but someone else removed it first
1452
1516
  // so put them at the head of the list
@@ -1765,7 +1829,7 @@ export class MergeTree {
1765
1829
  const node = block.children[i];
1766
1830
  const nodeLength = nodeTotalLength(this, node);
1767
1831
  if (nodeLength !== undefined) {
1768
- len ?? (len = 0);
1832
+ len ??= 0;
1769
1833
  len += nodeLength;
1770
1834
  }
1771
1835
  if (node.isLeaf()) {
@@ -1785,7 +1849,7 @@ export class MergeTree {
1785
1849
  // The later, and right most children overwrite
1786
1850
  // whereas early, and left most do not overwrite
1787
1851
  rightmostTiles[tileLabel] = segment;
1788
- leftmostTiles[tileLabel] ?? (leftmostTiles[tileLabel] = segment);
1852
+ leftmostTiles[tileLabel] ??= segment;
1789
1853
  }
1790
1854
  }
1791
1855
  }