@fluidframework/merge-tree 2.117.0 → 3.0.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 (184) hide show
  1. package/CHANGELOG.md +36 -2
  2. package/README.md +53 -50
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
  4. package/dist/MergeTreeTextHelper.js +1 -0
  5. package/dist/MergeTreeTextHelper.js.map +1 -1
  6. package/dist/attributionCollection.js +6 -4
  7. package/dist/attributionCollection.js.map +1 -1
  8. package/dist/attributionPolicy.js +3 -4
  9. package/dist/attributionPolicy.js.map +1 -1
  10. package/dist/client.js +27 -10
  11. package/dist/client.js.map +1 -1
  12. package/dist/collections/rbTree.d.ts.map +1 -1
  13. package/dist/collections/rbTree.js +3 -0
  14. package/dist/collections/rbTree.js.map +1 -1
  15. package/dist/endOfTreeSegment.d.ts.map +1 -1
  16. package/dist/endOfTreeSegment.js +25 -26
  17. package/dist/endOfTreeSegment.js.map +1 -1
  18. package/dist/localReference.js +17 -7
  19. package/dist/localReference.js.map +1 -1
  20. package/dist/mergeTree.d.ts.map +1 -1
  21. package/dist/mergeTree.js +90 -74
  22. package/dist/mergeTree.js.map +1 -1
  23. package/dist/mergeTreeNodeWalk.js +5 -5
  24. package/dist/mergeTreeNodeWalk.js.map +1 -1
  25. package/dist/mergeTreeNodes.d.ts.map +1 -1
  26. package/dist/mergeTreeNodes.js +117 -90
  27. package/dist/mergeTreeNodes.js.map +1 -1
  28. package/dist/mergeTreeTracking.js +4 -0
  29. package/dist/mergeTreeTracking.js.map +1 -1
  30. package/dist/opBuilder.js +9 -10
  31. package/dist/opBuilder.js.map +1 -1
  32. package/dist/ordinal.js +1 -2
  33. package/dist/ordinal.js.map +1 -1
  34. package/dist/partialLengths.js +109 -73
  35. package/dist/partialLengths.js.map +1 -1
  36. package/dist/perspective.js +31 -11
  37. package/dist/perspective.js.map +1 -1
  38. package/dist/properties.js +6 -7
  39. package/dist/properties.js.map +1 -1
  40. package/dist/referencePositions.d.ts.map +1 -1
  41. package/dist/referencePositions.js +7 -7
  42. package/dist/referencePositions.js.map +1 -1
  43. package/dist/revertibles.js +4 -5
  44. package/dist/revertibles.js.map +1 -1
  45. package/dist/segmentGroupCollection.js +2 -0
  46. package/dist/segmentGroupCollection.js.map +1 -1
  47. package/dist/segmentInfos.d.ts.map +1 -1
  48. package/dist/segmentInfos.js +5 -5
  49. package/dist/segmentInfos.js.map +1 -1
  50. package/dist/segmentPropertiesManager.js +3 -5
  51. package/dist/segmentPropertiesManager.js.map +1 -1
  52. package/dist/sequencePlace.js +3 -3
  53. package/dist/sequencePlace.js.map +1 -1
  54. package/dist/snapshotChunks.d.ts.map +1 -1
  55. package/dist/snapshotChunks.js +6 -6
  56. package/dist/snapshotChunks.js.map +1 -1
  57. package/dist/snapshotLoader.js +85 -70
  58. package/dist/snapshotLoader.js.map +1 -1
  59. package/dist/snapshotV1.d.ts.map +1 -1
  60. package/dist/snapshotV1.js +34 -14
  61. package/dist/snapshotV1.js.map +1 -1
  62. package/dist/snapshotlegacy.d.ts.map +1 -1
  63. package/dist/snapshotlegacy.js +18 -10
  64. package/dist/snapshotlegacy.js.map +1 -1
  65. package/dist/sortedSet.js +1 -3
  66. package/dist/sortedSet.js.map +1 -1
  67. package/dist/stamps.js +11 -12
  68. package/dist/stamps.js.map +1 -1
  69. package/dist/test/attributionCollection.spec.js +1 -1
  70. package/dist/test/attributionCollection.spec.js.map +1 -1
  71. package/dist/test/beastTest.spec.js +15 -11
  72. package/dist/test/beastTest.spec.js.map +1 -1
  73. package/dist/test/client.apis.spec.js +2 -3
  74. package/dist/test/client.apis.spec.js.map +1 -1
  75. package/dist/test/client.replay.spec.js +17 -7
  76. package/dist/test/client.replay.spec.js.map +1 -1
  77. package/dist/test/clientTestHelper.js +7 -4
  78. package/dist/test/clientTestHelper.js.map +1 -1
  79. package/dist/test/mergeTreeOperationRunner.js +26 -16
  80. package/dist/test/mergeTreeOperationRunner.js.map +1 -1
  81. package/dist/test/obliterateOperations.d.ts.map +1 -1
  82. package/dist/test/revertibles.spec.js +1 -2
  83. package/dist/test/revertibles.spec.js.map +1 -1
  84. package/dist/test/snapshot.utils.d.ts.map +1 -1
  85. package/dist/test/snapshot.utils.js +7 -5
  86. package/dist/test/snapshot.utils.js.map +1 -1
  87. package/dist/test/stamps.spec.js +17 -7
  88. package/dist/test/stamps.spec.js.map +1 -1
  89. package/dist/test/testClient.d.ts.map +1 -1
  90. package/dist/test/testClient.js +19 -17
  91. package/dist/test/testClient.js.map +1 -1
  92. package/dist/test/testClientLogger.d.ts.map +1 -1
  93. package/dist/test/testClientLogger.js +12 -8
  94. package/dist/test/testClientLogger.js.map +1 -1
  95. package/dist/test/testServer.js +7 -7
  96. package/dist/test/testServer.js.map +1 -1
  97. package/dist/test/testUtils.d.ts +0 -1
  98. package/dist/test/testUtils.d.ts.map +1 -1
  99. package/dist/test/testUtils.js +9 -10
  100. package/dist/test/testUtils.js.map +1 -1
  101. package/dist/test/text.js +2 -3
  102. package/dist/test/text.js.map +1 -1
  103. package/dist/test/wordUnitTests.spec.js +1 -2
  104. package/dist/test/wordUnitTests.spec.js.map +1 -1
  105. package/dist/textSegment.js +3 -2
  106. package/dist/textSegment.js.map +1 -1
  107. package/dist/zamboni.js +20 -10
  108. package/dist/zamboni.js.map +1 -1
  109. package/lib/MergeTreeTextHelper.js +1 -0
  110. package/lib/MergeTreeTextHelper.js.map +1 -1
  111. package/lib/attributionCollection.js +4 -2
  112. package/lib/attributionCollection.js.map +1 -1
  113. package/lib/client.js +10 -3
  114. package/lib/client.js.map +1 -1
  115. package/lib/collections/rbTree.d.ts.map +1 -1
  116. package/lib/collections/rbTree.js +3 -0
  117. package/lib/collections/rbTree.js.map +1 -1
  118. package/lib/endOfTreeSegment.d.ts.map +1 -1
  119. package/lib/endOfTreeSegment.js +25 -26
  120. package/lib/endOfTreeSegment.js.map +1 -1
  121. package/lib/legacy.d.ts +1 -1
  122. package/lib/localReference.js +12 -2
  123. package/lib/localReference.js.map +1 -1
  124. package/lib/mergeTree.d.ts.map +1 -1
  125. package/lib/mergeTree.js +68 -62
  126. package/lib/mergeTree.js.map +1 -1
  127. package/lib/mergeTreeNodes.d.ts.map +1 -1
  128. package/lib/mergeTreeNodes.js +111 -84
  129. package/lib/mergeTreeNodes.js.map +1 -1
  130. package/lib/mergeTreeTracking.js +4 -0
  131. package/lib/mergeTreeTracking.js.map +1 -1
  132. package/lib/partialLengths.js +89 -63
  133. package/lib/partialLengths.js.map +1 -1
  134. package/lib/perspective.js +12 -2
  135. package/lib/perspective.js.map +1 -1
  136. package/lib/public.d.ts +1 -1
  137. package/lib/referencePositions.d.ts.map +1 -1
  138. package/lib/segmentGroupCollection.js +2 -0
  139. package/lib/segmentGroupCollection.js.map +1 -1
  140. package/lib/segmentInfos.d.ts.map +1 -1
  141. package/lib/segmentPropertiesManager.js +1 -3
  142. package/lib/segmentPropertiesManager.js.map +1 -1
  143. package/lib/snapshotChunks.d.ts.map +1 -1
  144. package/lib/snapshotChunks.js +2 -1
  145. package/lib/snapshotChunks.js.map +1 -1
  146. package/lib/snapshotLoader.js +68 -63
  147. package/lib/snapshotLoader.js.map +1 -1
  148. package/lib/snapshotV1.d.ts.map +1 -1
  149. package/lib/snapshotV1.js +17 -7
  150. package/lib/snapshotV1.js.map +1 -1
  151. package/lib/snapshotlegacy.d.ts.map +1 -1
  152. package/lib/snapshotlegacy.js +18 -10
  153. package/lib/snapshotlegacy.js.map +1 -1
  154. package/lib/sortedSet.js +1 -3
  155. package/lib/sortedSet.js.map +1 -1
  156. package/lib/test/attributionCollection.spec.js +1 -1
  157. package/lib/test/attributionCollection.spec.js.map +1 -1
  158. package/lib/test/beastTest.spec.js +7 -3
  159. package/lib/test/beastTest.spec.js.map +1 -1
  160. package/lib/test/clientTestHelper.js +7 -4
  161. package/lib/test/clientTestHelper.js.map +1 -1
  162. package/lib/test/obliterateOperations.d.ts.map +1 -1
  163. package/lib/test/snapshot.utils.d.ts.map +1 -1
  164. package/lib/test/snapshot.utils.js +5 -3
  165. package/lib/test/snapshot.utils.js.map +1 -1
  166. package/lib/test/testClient.d.ts.map +1 -1
  167. package/lib/test/testClient.js +16 -14
  168. package/lib/test/testClient.js.map +1 -1
  169. package/lib/test/testClientLogger.d.ts.map +1 -1
  170. package/lib/test/testClientLogger.js +10 -6
  171. package/lib/test/testClientLogger.js.map +1 -1
  172. package/lib/test/testServer.js +5 -5
  173. package/lib/test/testServer.js.map +1 -1
  174. package/lib/test/testUtils.d.ts +0 -1
  175. package/lib/test/testUtils.d.ts.map +1 -1
  176. package/lib/textSegment.js +3 -2
  177. package/lib/textSegment.js.map +1 -1
  178. package/package.json +39 -58
  179. package/src/snapshotChunks.ts +10 -6
  180. package/tsconfig.json +1 -1
  181. package/internal.d.ts +0 -11
  182. package/legacy.d.ts +0 -11
  183. /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
  184. /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
@@ -4,7 +4,11 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.walkAllChildSegments = exports.backwardExcursion = exports.forwardExcursion = exports.depthFirstNodeWalk = exports.NodeAction = exports.LeafAction = void 0;
7
+ exports.NodeAction = exports.LeafAction = void 0;
8
+ exports.depthFirstNodeWalk = depthFirstNodeWalk;
9
+ exports.forwardExcursion = forwardExcursion;
10
+ exports.backwardExcursion = backwardExcursion;
11
+ exports.walkAllChildSegments = walkAllChildSegments;
8
12
  const segmentInfos_js_1 = require("./segmentInfos.js");
9
13
  exports.LeafAction = {
10
14
  Exit: false,
@@ -94,7 +98,6 @@ function depthFirstNodeWalk(startBlock, startChild, downAction, leafActionOverri
94
98
  start = block.children[nextIndex];
95
99
  }
96
100
  }
97
- exports.depthFirstNodeWalk = depthFirstNodeWalk;
98
101
  /**
99
102
  * Visit segments starting from node's right/far/forward siblings, then up to node's parent.
100
103
  * All segments past `node` are visited, regardless of their visibility.
@@ -109,7 +112,6 @@ function forwardExcursion(startNode, leafAction) {
109
112
  // the startNode only
110
113
  startNode.parent.children[startNode.index + 1], undefined /* downAction */, leafAction);
111
114
  }
112
- exports.forwardExcursion = forwardExcursion;
113
115
  /**
114
116
  * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.
115
117
  * All segments past `node` are visited, regardless of their visibility.
@@ -124,7 +126,6 @@ function backwardExcursion(startNode, leafAction) {
124
126
  // the startNode only
125
127
  startNode.parent.children[startNode.index - 1], undefined /* downAction */, leafAction, undefined /* upAction */, false /* forward */);
126
128
  }
127
- exports.backwardExcursion = backwardExcursion;
128
129
  /**
129
130
  * Walks all segments below the specific start block
130
131
  * @param startBlock - The block to start the walk at
@@ -145,5 +146,4 @@ function walkAllChildSegments(startBlock, leafAction) {
145
146
  ? undefined
146
147
  : (node) => ancestors.has(node.parent) ? exports.NodeAction.Exit : exports.NodeAction.Continue, leafAction);
147
148
  }
148
- exports.walkAllChildSegments = walkAllChildSegments;
149
149
  //# sourceMappingURL=mergeTreeNodeWalk.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeNodeWalk.js","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,uDAAoD;AAEvC,QAAA,UAAU,GAAG;IACzB,IAAI,EAAE,KAAK;CACF,CAAC;AAIE,QAAA,UAAU,GAAG;IACzB,QAAQ,EAAE,SAAS;IACnB,iDAAiD;IACjD,IAAI,EAAE,kBAAU,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC;CACE,CAAC;AAOX;;;;;;;;;;GAUG;AACH,SAAgB,kBAAkB,CACjC,UAAsB,EACtB,UAAkC,EAClC,UAA6C,EAC7C,kBAAsD,EACtD,QAAsC,EACtC,UAAmB,IAAI;IAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,C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AI,CAAC,CAAC,CAAC,kBAAU,CAAC,QAAQ,EACrE,UAAU,CACV,CAAC;AACH,CAAC;AAxBD,oDAwBC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISegmentLeaf, MergeBlock, IMergeNode } from \"./mergeTreeNodes.js\";\nimport { isMergeNodeInfo } from \"./segmentInfos.js\";\n\nexport const LeafAction = {\n\tExit: false,\n} as const;\n\nexport type LeafAction = boolean | undefined | void;\n\nexport const NodeAction = {\n\tContinue: undefined,\n\t// exit is false to unify with leafActionOverride\n\tExit: LeafAction.Exit,\n\tSkip: 2,\n} as const;\n\n// we exclude true from, as we only want one continue value, undefined\nexport type NodeAction =\n\t| (typeof NodeAction)[keyof typeof NodeAction]\n\t| Exclude<LeafAction, true>;\n\n/**\n * Does a depth first walk of the tree from the specific start.\n *\n * @param startBlock - The block of the tree to start the walk from\n * @param startChild - The child of that block to start from\n * @param downAction - Called as we walk down the tree to the leaves.\n * @param leafActionOverride - Overrides downAction for leaves, generally used without downAction\n * @param upAction - Called after all the children of a block are walked.\n * @param forward - whether to walk forward or backward\n * @returns true if we naturally exit, false if exiting due to Exit action result\n */\nexport function depthFirstNodeWalk(\n\tstartBlock: MergeBlock,\n\tstartChild: IMergeNode | undefined,\n\tdownAction?: (node: IMergeNode) => NodeAction,\n\tleafActionOverride?: (seg: ISegmentLeaf) => LeafAction,\n\tupAction?: (block: MergeBlock) => void,\n\tforward: boolean = true,\n): boolean {\n\tconst increment = forward ? 1 : -1;\n\tconst leafAction = leafActionOverride ?? downAction;\n\tif (leafAction === undefined) {\n\t\treturn true;\n\t}\n\n\tlet block = startBlock;\n\tlet childCount = block.childCount;\n\tlet start: IMergeNode | undefined = startChild;\n\n\twhile (true) {\n\t\t// go down to the leaf level\n\t\tlet blockResult: NodeAction;\n\t\twhile (start?.isLeaf() === false) {\n\t\t\t// cast is safe due to isLeaf === false in while above\n\t\t\tblock = start as MergeBlock;\n\t\t\tchildCount = block.childCount;\n\t\t\tblockResult = downAction?.(block);\n\t\t\t// setting start undefined will skip the leaf walk\n\t\t\t// so if the block result isn't continue, set it\n\t\t\t// undefined\n\t\t\tstart =\n\t\t\t\tblockResult === NodeAction.Continue\n\t\t\t\t\t? block.children[forward ? 0 : childCount - 1]\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tlet exit = blockResult === NodeAction.Exit;\n\n\t\t// walk the leaves if we reached them\n\t\tif (start !== undefined) {\n\t\t\tfor (let i = start.index; i !== -1 && i !== childCount; i += increment) {\n\t\t\t\t// the above loop ensures start is a leaf or undefined, so all children\n\t\t\t\t// will be leaves if start exits, so the cast is safe\n\t\t\t\tif (leafAction(block.children[i] as ISegmentLeaf) === LeafAction.Exit) {\n\t\t\t\t\texit = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if there is no upAction, we don't need to walk up before exiting\n\t\tif (upAction === undefined && exit) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// since we already enumerated the children\n\t\t// we walk up to the next level until there is a sibling\n\t\t// or all the way up if exit is true\n\t\tlet nextIndex = -1;\n\t\tdo {\n\t\t\t// if the blockAction was exit or skip\n\t\t\t// we shouldn't process that block again,\n\t\t\t// if there are subsequent parents while walking up\n\t\t\t// we will process those.\n\t\t\tif (blockResult === NodeAction.Continue) {\n\t\t\t\tupAction?.(block);\n\t\t\t} else {\n\t\t\t\tblockResult = NodeAction.Continue;\n\t\t\t}\n\t\t\tif (block.parent === undefined) {\n\t\t\t\treturn !exit;\n\t\t\t}\n\t\t\tstart = block;\n\t\t\tblock = block.parent;\n\t\t\tchildCount = block.childCount;\n\t\t\tnextIndex = start.index + increment;\n\t\t} while (exit || nextIndex === -1 || nextIndex === childCount);\n\t\t// the above loop ensured that siblings are possible\n\t\tstart = block.children[nextIndex];\n\t}\n}\n\n/**\n * Visit segments starting from node's right/far/forward siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function forwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index + 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t);\n}\n\n/**\n * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function backwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index - 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t\tundefined /* upAction */,\n\t\tfalse /* forward */,\n\t);\n}\n\n/**\n * Walks all segments below the specific start block\n * @param startBlock - The block to start the walk at\n * @param leafAction - The action to perform on the leaves\n * @returns true if we naturally exit, false if exiting due to leaf action result\n */\nexport function walkAllChildSegments(\n\tstartBlock: MergeBlock,\n\tleafAction: (segment: ISegmentLeaf) => boolean | undefined | void,\n): boolean {\n\tif (startBlock.childCount === 0) {\n\t\treturn true;\n\t}\n\n\t// undefined shouldn't actually be added, but this allows subsequent check for `node.parent` to typecheck\n\t// without further runtime work.\n\tconst ancestors = new Set<MergeBlock | undefined>();\n\tfor (let cur = startBlock.parent; cur !== undefined; cur = cur.parent) {\n\t\tancestors.add(cur);\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartBlock,\n\t\tstartBlock.children[0],\n\t\tancestors.size === 0\n\t\t\t? undefined\n\t\t\t: (node): false | undefined =>\n\t\t\t\t\tancestors.has(node.parent) ? NodeAction.Exit : NodeAction.Continue,\n\t\tleafAction,\n\t);\n}\n"]}
1
+ {"version":3,"file":"mergeTreeNodeWalk.js","sourceRoot":"","sources":["../src/mergeTreeNodeWalk.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAkCH,gDA+EC;AAMD,4CAiBC;AAMD,8CAkBC;AAQD,oDAwBC;AA7LD,uDAAoD;AAEvC,QAAA,UAAU,GAAG;IACzB,IAAI,EAAE,KAAK;CACF,CAAC;AAIE,QAAA,UAAU,GAAG;IACzB,QAAQ,EAAE,SAAS;IACnB,iDAAiD;IACjD,IAAI,EAAE,kBAAU,CAAC,IAAI;IACrB,IAAI,EAAE,CAAC;CACE,CAAC;AAOX;;;;;;;;;;GAUG;AACH,SAAgB,kBAAkB,CACjC,UAAsB,EACtB,UAAkC,EAClC,UAA6C,EAC7C,kBAAsD,EACtD,QAAsC,EACtC,UAAmB,IAAI;IAEvB,MAAM,SAAS,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACnC,MAAM,UAAU,GAAG,kBAAkB,IAAI,UAAU,CAAC;IACpD,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;QAC9B,OAAO,IAAI,CAAC;IACb,CAAC;IAED,IAAI,KAAK,GAAG,UAAU,CAAC;IACvB,IAAI,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IAClC,IAAI,KAAK,GAA2B,UAAU,CAAC;IAE/C,OAAO,IAAI,EAAE,CAAC;QACb,4BAA4B;QAC5B,IAAI,WAAuB,CAAC;QAC5B,OAAO,KAAK,EAAE,MAAM,EAAE,KAAK,KAAK,EAAE,CAAC;YAClC,sDAAsD;YACtD,KAAK,GAAG,KAAmB,CAAC;YAC5B,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;YAC9B,WAAW,GAAG,UAAU,EAAE,CAAC,KAAK,CAAC,CAAC;YAClC,kDAAkD;YA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ACnC,UAAsB,EACtB,UAAiE;IAEjE,IAAI,UAAU,CAAC,UAAU,KAAK,CAAC,EAAE,CAAC;QACjC,OAAO,IAAI,CAAC;IACb,CAAC;IAED,yGAAyG;IACzG,gCAAgC;IAChC,MAAM,SAAS,GAAG,IAAI,GAAG,EAA0B,CAAC;IACpD,KAAK,IAAI,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,GAAG,KAAK,SAAS,EAAE,GAAG,GAAG,GAAG,CAAC,MAAM,EAAE,CAAC;QACvE,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,kBAAkB,CACxB,UAAU,EACV,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EACtB,SAAS,CAAC,IAAI,KAAK,CAAC;QACnB,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,CAAC,IAAI,EAAqB,EAAE,CAC5B,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,kBAAU,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAU,CAAC,QAAQ,EACrE,UAAU,CACV,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ISegmentLeaf, MergeBlock, IMergeNode } from \"./mergeTreeNodes.js\";\nimport { isMergeNodeInfo } from \"./segmentInfos.js\";\n\nexport const LeafAction = {\n\tExit: false,\n} as const;\n\nexport type LeafAction = boolean | undefined | void;\n\nexport const NodeAction = {\n\tContinue: undefined,\n\t// exit is false to unify with leafActionOverride\n\tExit: LeafAction.Exit,\n\tSkip: 2,\n} as const;\n\n// we exclude true from, as we only want one continue value, undefined\nexport type NodeAction =\n\t| (typeof NodeAction)[keyof typeof NodeAction]\n\t| Exclude<LeafAction, true>;\n\n/**\n * Does a depth first walk of the tree from the specific start.\n *\n * @param startBlock - The block of the tree to start the walk from\n * @param startChild - The child of that block to start from\n * @param downAction - Called as we walk down the tree to the leaves.\n * @param leafActionOverride - Overrides downAction for leaves, generally used without downAction\n * @param upAction - Called after all the children of a block are walked.\n * @param forward - whether to walk forward or backward\n * @returns true if we naturally exit, false if exiting due to Exit action result\n */\nexport function depthFirstNodeWalk(\n\tstartBlock: MergeBlock,\n\tstartChild: IMergeNode | undefined,\n\tdownAction?: (node: IMergeNode) => NodeAction,\n\tleafActionOverride?: (seg: ISegmentLeaf) => LeafAction,\n\tupAction?: (block: MergeBlock) => void,\n\tforward: boolean = true,\n): boolean {\n\tconst increment = forward ? 1 : -1;\n\tconst leafAction = leafActionOverride ?? downAction;\n\tif (leafAction === undefined) {\n\t\treturn true;\n\t}\n\n\tlet block = startBlock;\n\tlet childCount = block.childCount;\n\tlet start: IMergeNode | undefined = startChild;\n\n\twhile (true) {\n\t\t// go down to the leaf level\n\t\tlet blockResult: NodeAction;\n\t\twhile (start?.isLeaf() === false) {\n\t\t\t// cast is safe due to isLeaf === false in while above\n\t\t\tblock = start as MergeBlock;\n\t\t\tchildCount = block.childCount;\n\t\t\tblockResult = downAction?.(block);\n\t\t\t// setting start undefined will skip the leaf walk\n\t\t\t// so if the block result isn't continue, set it\n\t\t\t// undefined\n\t\t\tstart =\n\t\t\t\tblockResult === NodeAction.Continue\n\t\t\t\t\t? block.children[forward ? 0 : childCount - 1]\n\t\t\t\t\t: undefined;\n\t\t}\n\n\t\tlet exit = blockResult === NodeAction.Exit;\n\n\t\t// walk the leaves if we reached them\n\t\tif (start !== undefined) {\n\t\t\tfor (let i = start.index; i !== -1 && i !== childCount; i += increment) {\n\t\t\t\t// the above loop ensures start is a leaf or undefined, so all children\n\t\t\t\t// will be leaves if start exits, so the cast is safe\n\t\t\t\tif (leafAction(block.children[i] as ISegmentLeaf) === LeafAction.Exit) {\n\t\t\t\t\texit = true;\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// if there is no upAction, we don't need to walk up before exiting\n\t\tif (upAction === undefined && exit) {\n\t\t\treturn false;\n\t\t}\n\n\t\t// since we already enumerated the children\n\t\t// we walk up to the next level until there is a sibling\n\t\t// or all the way up if exit is true\n\t\tlet nextIndex = -1;\n\t\tdo {\n\t\t\t// if the blockAction was exit or skip\n\t\t\t// we shouldn't process that block again,\n\t\t\t// if there are subsequent parents while walking up\n\t\t\t// we will process those.\n\t\t\tif (blockResult === NodeAction.Continue) {\n\t\t\t\tupAction?.(block);\n\t\t\t} else {\n\t\t\t\tblockResult = NodeAction.Continue;\n\t\t\t}\n\t\t\tif (block.parent === undefined) {\n\t\t\t\treturn !exit;\n\t\t\t}\n\t\t\tstart = block;\n\t\t\tblock = block.parent;\n\t\t\tchildCount = block.childCount;\n\t\t\tnextIndex = start.index + increment;\n\t\t} while (exit || nextIndex === -1 || nextIndex === childCount);\n\t\t// the above loop ensured that siblings are possible\n\t\tstart = block.children[nextIndex];\n\t}\n}\n\n/**\n * Visit segments starting from node's right/far/forward siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function forwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index + 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t);\n}\n\n/**\n * Visit segments starting from node's left/near/backwards siblings, then up to node's parent.\n * All segments past `node` are visited, regardless of their visibility.\n */\nexport function backwardExcursion(\n\tstartNode: IMergeNode,\n\tleafAction: (seg: ISegmentLeaf) => boolean | undefined,\n): boolean {\n\tif (!isMergeNodeInfo(startNode)) {\n\t\treturn true;\n\t}\n\treturn depthFirstNodeWalk(\n\t\tstartNode.parent,\n\t\t// this will either be the sibling, or undefined\n\t\t// either is fine, and will result in skipping\n\t\t// the startNode only\n\t\tstartNode.parent.children[startNode.index - 1],\n\t\tundefined /* downAction */,\n\t\tleafAction,\n\t\tundefined /* upAction */,\n\t\tfalse /* forward */,\n\t);\n}\n\n/**\n * Walks all segments below the specific start block\n * @param startBlock - The block to start the walk at\n * @param leafAction - The action to perform on the leaves\n * @returns true if we naturally exit, false if exiting due to leaf action result\n */\nexport function walkAllChildSegments(\n\tstartBlock: MergeBlock,\n\tleafAction: (segment: ISegmentLeaf) => boolean | undefined | void,\n): boolean {\n\tif (startBlock.childCount === 0) {\n\t\treturn true;\n\t}\n\n\t// undefined shouldn't actually be added, but this allows subsequent check for `node.parent` to typecheck\n\t// without further runtime work.\n\tconst ancestors = new Set<MergeBlock | undefined>();\n\tfor (let cur = startBlock.parent; cur !== undefined; cur = cur.parent) {\n\t\tancestors.add(cur);\n\t}\n\n\treturn depthFirstNodeWalk(\n\t\tstartBlock,\n\t\tstartBlock.children[0],\n\t\tancestors.size === 0\n\t\t\t? undefined\n\t\t\t: (node): false | undefined =>\n\t\t\t\t\tancestors.has(node.parent) ? NodeAction.Exit : NodeAction.Continue,\n\t\tleafAction,\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeNodes.d.ts","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAC;AAEnF,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,4BAA4B,CAAC;AAOzE,OAAO,EAAE,wBAAwB,EAAE,KAAK,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAC5F,OAAO,EAAE,uBAAuB,EAAE,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAExE,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAClE,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ACzB,aAAa,UAAS;IAEtB;;OAEG;IACH,MAAM,SAAK;IACX;;OAEG;IACH,UAAU,SAAK;IAEf;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8DG;IACH,QAAQ,SAAK;IAEN,gBAAgB,EAAE,WAAW,CAA8C;IAE3E,QAAQ,CAAC,CAAC,EAAE,mBAAmB,GAAG,IAAI;IAOtC,2BAA2B,IAAI,cAAc;CAWpD;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAAe,CAAC;AAEtE;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,GAAG,MAAM,EAAE,GAAG,MAAM,KAAG,MAA4B,CAAC"}
@@ -4,7 +4,12 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.compareStrings = exports.compareNumbers = exports.CollaborationWindow = exports.getMinSeqPerspective = exports.getMinSeqStamp = exports.Marker = exports.reservedMarkerSimpleTypeKey = exports.reservedMarkerIdKey = exports.BaseSegment = exports.seqLTE = exports.assignChild = exports.MergeBlock = exports.MaxNodesInBlock = exports.segmentIsRemoved = exports.assertSegmentLeaf = exports.toSegmentLeaf = exports.isSegmentLeaf = void 0;
7
+ exports.compareStrings = exports.compareNumbers = exports.CollaborationWindow = exports.Marker = exports.reservedMarkerSimpleTypeKey = exports.reservedMarkerIdKey = exports.BaseSegment = exports.MergeBlock = exports.MaxNodesInBlock = exports.assertSegmentLeaf = exports.toSegmentLeaf = exports.isSegmentLeaf = void 0;
8
+ exports.segmentIsRemoved = segmentIsRemoved;
9
+ exports.assignChild = assignChild;
10
+ exports.seqLTE = seqLTE;
11
+ exports.getMinSeqStamp = getMinSeqStamp;
12
+ exports.getMinSeqPerspective = getMinSeqPerspective;
8
13
  const internal_1 = require("@fluidframework/core-utils/internal");
9
14
  const constants_js_1 = require("./constants.js");
10
15
  const localReference_js_1 = require("./localReference.js");
@@ -44,7 +49,6 @@ exports.assertSegmentLeaf = assertSegmentLeaf;
44
49
  function segmentIsRemoved(segment) {
45
50
  return (0, segmentInfos_js_1.isRemoved)(segment);
46
51
  }
47
- exports.segmentIsRemoved = segmentIsRemoved;
48
52
  /**
49
53
  * Note that the actual branching factor of the MergeTree is `MaxNodesInBlock - 1`. This is because
50
54
  * the MergeTree always inserts first, then checks for overflow and splits if the child count equals
@@ -53,14 +57,39 @@ exports.segmentIsRemoved = segmentIsRemoved;
53
57
  */
54
58
  exports.MaxNodesInBlock = 8;
55
59
  class MergeBlock {
60
+ childCount;
61
+ children;
62
+ needsScour;
63
+ parent;
64
+ index = 0;
65
+ ordinal = "";
66
+ cachedLength = 0;
67
+ /**
68
+ * Maps each tile label in this block to the rightmost (i.e. furthest) marker associated with that tile label.
69
+ * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile
70
+ * with a certain label before a given position
71
+ */
72
+ rightmostTiles;
73
+ /**
74
+ * Maps each tile label in this block to the leftmost (i.e. nearest) marker associated with that tile label.
75
+ * When combined with the tree structure of MergeBlocks, this allows accelerated queries for nearest tile
76
+ * with a certain label before a given position
77
+ */
78
+ leftmostTiles;
56
79
  isLeaf() {
57
80
  return false;
58
81
  }
82
+ /**
83
+ * Supports querying the total length of all descendants of this IMergeBlock from the perspective of any
84
+ * (clientId, seq) within the collab window.
85
+ *
86
+ * @remarks This is only optional for implementation reasons (internal nodes can be created/moved without
87
+ * immediately initializing the partial lengths). Aside from mid-update on tree operations, these lengths
88
+ * objects are always defined.
89
+ */
90
+ partialLengths;
59
91
  constructor(childCount) {
60
92
  this.childCount = childCount;
61
- this.index = 0;
62
- this.ordinal = "";
63
- this.cachedLength = 0;
64
93
  // Suppression needed due to the way the merge tree children are initialized - we
65
94
  // allocate 8 children blocks, but any unused blocks are not counted in the childCount.
66
95
  // Using Array.from leads to unused children being undefined, which are counted in childCount.
@@ -87,18 +116,19 @@ function assignChild(parent, child, index, updateOrdinal = true) {
87
116
  }
88
117
  parent.children[index] = node;
89
118
  }
90
- exports.assignChild = assignChild;
91
119
  function seqLTE(seq, minOrRefSeq) {
92
120
  return seq !== constants_js_1.UnassignedSequenceNumber && seq <= minOrRefSeq;
93
121
  }
94
- exports.seqLTE = seqLTE;
95
122
  /**
96
123
  * @legacy @beta
97
124
  */
98
125
  class BaseSegment {
126
+ cachedLength = 0;
127
+ trackingCollection = new mergeTreeTracking_js_1.TrackingGroupCollection(this);
128
+ /***/
129
+ attribution;
130
+ properties;
99
131
  constructor(properties) {
100
- this.cachedLength = 0;
101
- this.trackingCollection = new mergeTreeTracking_js_1.TrackingGroupCollection(this);
102
132
  if (properties !== undefined) {
103
133
  this.properties = (0, properties_js_1.clone)(properties);
104
134
  }
@@ -214,16 +244,18 @@ exports.reservedMarkerSimpleTypeKey = "markerSimpleType";
214
244
  * @legacy @beta
215
245
  */
216
246
  class Marker extends BaseSegment {
247
+ refType;
248
+ static type = "Marker";
217
249
  static is(segment) {
218
250
  return segment.type === Marker.type;
219
251
  }
252
+ type = Marker.type;
220
253
  static make(refType, props) {
221
254
  return new Marker(refType, props);
222
255
  }
223
256
  constructor(refType, props) {
224
257
  super(props);
225
258
  this.refType = refType;
226
- this.type = Marker.type;
227
259
  this.cachedLength = 1;
228
260
  }
229
261
  toJSONObject() {
@@ -268,7 +300,6 @@ class Marker extends BaseSegment {
268
300
  }
269
301
  }
270
302
  exports.Marker = Marker;
271
- Marker.type = "Marker";
272
303
  /**
273
304
  * Returns a stamp that occurs at the minimum sequence number.
274
305
  * @privateRemarks
@@ -281,7 +312,6 @@ Marker.type = "Marker";
281
312
  function getMinSeqStamp(collabWindow) {
282
313
  return { seq: collabWindow.minSeq, clientId: constants_js_1.NonCollabClient };
283
314
  }
284
- exports.getMinSeqStamp = getMinSeqStamp;
285
315
  /**
286
316
  * Returns a perspective representing a readonly client's view of the tree at the minimum sequence number.
287
317
  * @privateRemarks
@@ -294,7 +324,6 @@ exports.getMinSeqStamp = getMinSeqStamp;
294
324
  function getMinSeqPerspective(collabWindow) {
295
325
  return new perspective_js_1.PriorPerspective(collabWindow.minSeq, constants_js_1.NonCollabClient);
296
326
  }
297
- exports.getMinSeqPerspective = getMinSeqPerspective;
298
327
  /**
299
328
  * This class is used to track facts about the current window of collaboration. This window is defined by the server
300
329
  * specified minimum sequence number to the last sequence number seen. Additionally, it track state for outstanding
@@ -302,83 +331,81 @@ exports.getMinSeqPerspective = getMinSeqPerspective;
302
331
  * @internal
303
332
  */
304
333
  class CollaborationWindow {
305
- constructor() {
306
- this.clientId = constants_js_1.LocalClientId;
307
- this.collaborating = false;
308
- /**
309
- * Lowest-numbered segment in window; no client can reference a state before this one
310
- */
311
- this.minSeq = 0;
312
- /**
313
- * Highest-numbered segment in window and current reference sequence number for this client.
314
- */
315
- this.currentSeq = 0;
316
- /**
317
- * Highest-numbered localSeq used for a pending segment.
318
- * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
319
- * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
320
- *
321
- * @remarks This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
322
- * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
323
- *
324
- * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
325
- * the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.
326
- *
327
- * For example, imagine a client with initial state "123456" submits some ops to create the text "123456ABC".
328
- * If they insert the "C" first, then "B", then "A", their local segment state might look like this:
329
- * ```js
330
- * [
331
- * { seq: 0, text: "1234" },
332
- * { seq: 5, text: "56" },
333
- * { localSeq: 3, seq: UnassignedSequenceNumber, text: "A" },
334
- * { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
335
- * { localSeq: 1, seq: UnassignedSequenceNumber, text: "C" },
336
- * ]
337
- * ```
338
- * (note that localSeq tracks the localSeq at which a segment was inserted)
339
- *
340
- * Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate
341
- * that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.
342
- *
343
- * It will generate the ops
344
- * 1. \{ pos: 6, text: "C" \}
345
- * 2. \{ pos: 6, text: "B" \}
346
- * 3. \{ pos: 6, text: "A" \}
347
- *
348
- * since when submitting the first op, remote clients don't know that this client is about to submit the "A" and "B".
349
- *
350
- * On the other hand, imagine if the client had originally submitted the ops in the order "A", "B", "C"
351
- * such that the segments' local state was instead:
352
- *
353
- * ```js
354
- * [
355
- * { seq: 0, text: "1234" },
356
- * { seq: 5, text: "56" },
357
- * { localSeq: 1, seq: UnassignedSequenceNumber, text: "A" },
358
- * { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
359
- * { localSeq: 3, seq: UnassignedSequenceNumber, text: "C" },
360
- * ]
361
- * ```
362
- *
363
- * The resubmitted ops should instead be:
364
- * 1. \{ pos: 6, text: "A" \}
365
- * 2. \{ pos: 7, text: "B" \}
366
- * 3. \{ pos: 8, text: "C" \}
367
- *
368
- * since remote clients will have seen the "A" when processing the "B" as well as both the "A" and "B" when processing the "C".
369
- * As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing
370
- * in `localSeq`.
371
- *
372
- * This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client
373
- * was disconnected, the resubmitted ops end up matching the original ops exactly.
374
- * However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked
375
- * and local information as appropriate.
376
- * Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible
377
- * from a given (seq, localSeq) perspective.
378
- */
379
- this.localSeq = 0;
380
- this.localPerspective = new perspective_js_1.LocalDefaultPerspective(this.clientId);
381
- }
334
+ clientId = constants_js_1.LocalClientId;
335
+ collaborating = false;
336
+ /**
337
+ * Lowest-numbered segment in window; no client can reference a state before this one
338
+ */
339
+ minSeq = 0;
340
+ /**
341
+ * Highest-numbered segment in window and current reference sequence number for this client.
342
+ */
343
+ currentSeq = 0;
344
+ /**
345
+ * Highest-numbered localSeq used for a pending segment.
346
+ * Semantically, `localSeq`s provide an ordering on in-flight merge-tree operations:
347
+ * for operations stamped with localSeqs `a` and `b`, `a < b` if and only if `a` was submitted before `b`.
348
+ *
349
+ * @remarks This field is analogous to the `clientSequenceNumber` field on ops, but it's accessible to merge-tree
350
+ * at op submission time rather than only at ack time. This enables more natural state tracking for in-flight ops.
351
+ *
352
+ * It's useful to stamp ops with such an incrementing counter because it enables reasoning about which segments existed from
353
+ * the perspective of the local client at a given point in 'un-acked' time, which is necessary to support the reconnect flow.
354
+ *
355
+ * For example, imagine a client with initial state "123456" submits some ops to create the text "123456ABC".
356
+ * If they insert the "C" first, then "B", then "A", their local segment state might look like this:
357
+ * ```js
358
+ * [
359
+ * { seq: 0, text: "1234" },
360
+ * { seq: 5, text: "56" },
361
+ * { localSeq: 3, seq: UnassignedSequenceNumber, text: "A" },
362
+ * { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
363
+ * { localSeq: 1, seq: UnassignedSequenceNumber, text: "C" },
364
+ * ]
365
+ * ```
366
+ * (note that localSeq tracks the localSeq at which a segment was inserted)
367
+ *
368
+ * Suppose the client then disconnects and reconnects before any of its insertions are acked. The reconnect flow will necessitate
369
+ * that the client regenerates and resubmits ops based on its current segment state as well as the original op that was sent.
370
+ *
371
+ * It will generate the ops
372
+ * 1. \{ pos: 6, text: "C" \}
373
+ * 2. \{ pos: 6, text: "B" \}
374
+ * 3. \{ pos: 6, text: "A" \}
375
+ *
376
+ * since when submitting the first op, remote clients don't know that this client is about to submit the "A" and "B".
377
+ *
378
+ * On the other hand, imagine if the client had originally submitted the ops in the order "A", "B", "C"
379
+ * such that the segments' local state was instead:
380
+ *
381
+ * ```js
382
+ * [
383
+ * { seq: 0, text: "1234" },
384
+ * { seq: 5, text: "56" },
385
+ * { localSeq: 1, seq: UnassignedSequenceNumber, text: "A" },
386
+ * { localSeq: 2, seq: UnassignedSequenceNumber, text: "B" },
387
+ * { localSeq: 3, seq: UnassignedSequenceNumber, text: "C" },
388
+ * ]
389
+ * ```
390
+ *
391
+ * The resubmitted ops should instead be:
392
+ * 1. \{ pos: 6, text: "A" \}
393
+ * 2. \{ pos: 7, text: "B" \}
394
+ * 3. \{ pos: 8, text: "C" \}
395
+ *
396
+ * since remote clients will have seen the "A" when processing the "B" as well as both the "A" and "B" when processing the "C".
397
+ * As can be seen, the list of resubmitted ops is different in the two cases despite the merge-tree's segment state only differing
398
+ * in `localSeq`.
399
+ *
400
+ * This example is a bit simplified from the general scenario: since no remote clients modified the merge-tree while the client
401
+ * was disconnected, the resubmitted ops end up matching the original ops exactly.
402
+ * However, this is not generally true: the production reconnect code takes into account visibility of segments based on both acked
403
+ * and local information as appropriate.
404
+ * Nonetheless, this simple scenario is enough to understand why it's useful to be able to determine if a segment should be visible
405
+ * from a given (seq, localSeq) perspective.
406
+ */
407
+ localSeq = 0;
408
+ localPerspective = new perspective_js_1.LocalDefaultPerspective(this.clientId);
382
409
  loadFrom(a) {
383
410
  this.clientId = a.clientId;
384
411
  this.collaborating = a.collaborating;
@@ -1 +1 @@
1
- {"version":3,"file":"mergeTreeNodes.js","sourceRoot":"","sources":["../src/mergeTreeNodes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAI7D,iDAKwB;AACxB,2DAA4F;AAC5F,iEAAsF;AAEtF,6CAA0D;AAE1D,qDAA+F;AAC/F,mDAAmF;AAGnF,uDAY2B;AAyD3B;;;;;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,SAA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AAc,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 type { AttributionKey } from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { IAttributionCollection } from \"./attributionCollection.js\";\nimport {\n\tLocalClientId,\n\tNonCollabClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\nimport { LocalReferenceCollection, type LocalReferencePosition } from \"./localReference.js\";\nimport { TrackingGroupCollection, type ITrackingGroup } from \"./mergeTreeTracking.js\";\nimport type { IJSONSegment, IMarkerDef, ReferenceType } from \"./ops.js\";\nimport { computeHierarchicalOrdinal } from \"./ordinal.js\";\nimport type { PartialSequenceLengths } from \"./partialLengths.js\";\nimport { LocalDefaultPerspective, PriorPerspective, type Perspective } from \"./perspective.js\";\nimport { type PropertySet, clone, createMap, type MapLike } from \"./properties.js\";\nimport type { ReferencePosition } from \"./referencePositions.js\";\nimport type { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\thasProp,\n\tisInserted,\n\tisMergeNodeInfo as isMergeNode,\n\tisRemoved,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype IMergeNodeInfo,\n\ttype IHasRemovalInfo,\n\ttype SegmentWithInfo,\n\ttype ISegmentInsideObliterateInfo,\n\tisInsideObliterate,\n} from \"./segmentInfos.js\";\nimport type { PropertiesManager } from \"./segmentPropertiesManager.js\";\nimport type { Side } from \"./sequencePlace.js\";\nimport type { OperationStamp, SliceRemoveOperationStamp } from \"./stamps.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}\n/**\n * Segment leafs are segments that have both IMergeNodeInfo and IHasInsertionInfo. 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 & IHasInsertionInfo>;\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<IHasInsertionInfo>;\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 @beta\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 @beta\n */\nexport function segmentIsRemoved(segment: ISegment): boolean {\n\treturn isRemoved(segment);\n}\n\n/**\n * @legacy @beta\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<IHasInsertionInfo>;\n\treplaceCurrent?: SegmentWithInfo<IHasInsertionInfo>;\n}\n\nexport interface InsertContext {\n\tcandidateSegment?: SegmentWithInfo<IHasInsertionInfo>;\n\tleaf: (segment: ISegmentLeaf | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: MergeBlock) => boolean;\n}\n\nexport interface ObliterateInfo {\n\tstart: LocalReferencePosition;\n\tstartSide: Side;\n\tend: LocalReferencePosition;\n\tendSide: Side;\n\trefSeq: number;\n\tstamp: SliceRemoveOperationStamp;\n\tsegmentGroup: SegmentGroup | undefined;\n\t/**\n\t * Defined only for unacked obliterates.\n\t *\n\t * Contains all segments inserted into the range this obliterate affects where at the time of insertion,\n\t * this obliterate was the newest concurrent obliterate that overlapped the insertion point (this information\n\t * is relevant for the tiebreak policy of allowing last-obliterater to insert).\n\t *\n\t * We need to keep this around for unacked ops because on reconnect, outstanding local obliterates may have set `obliteratePrecedingInsertion`\n\t * (tiebreak) on segments they no longer apply to, since the reissued obliterate may affect a smaller range than the original one when content\n\t * near the obliterate's endpoints was removed by another client between the time of the original obliterate and reissuing.\n\t */\n\ttiebreakTrackingGroup: ITrackingGroup | 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 initialized - 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 @beta\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<IHasInsertionInfo>(seg, {\n\t\t\t\tinsert: this.insert,\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<IHasRemovalInfo>(seg, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\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<IHasInsertionInfo>(leafSegment, { insert: this.insert });\n\t\t}\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IHasRemovalInfo>(leafSegment, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\t\tif (isInsideObliterate(this)) {\n\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(leafSegment, {\n\t\t\t\tobliteratePrecedingInsertion: this.obliteratePrecedingInsertion,\n\t\t\t\tinsertionRefSeqStamp: this.insertionRefSeqStamp,\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 @beta\n */\nexport const reservedMarkerIdKey = \"markerId\";\n\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @legacy @beta\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 @beta\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 * Returns a stamp that occurs at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqStamp(collabWindow: CollaborationWindow): OperationStamp {\n\treturn { seq: collabWindow.minSeq, clientId: NonCollabClient };\n}\n\n/**\n * Returns a perspective representing a readonly client's view of the tree at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqPerspective(collabWindow: CollaborationWindow): Perspective {\n\treturn new PriorPerspective(collabWindow.minSeq, NonCollabClient);\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\tpublic localPerspective: Perspective = new LocalDefaultPerspective(this.clientId);\n\n\tpublic loadFrom(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\tpublic mintNextLocalOperationStamp(): OperationStamp {\n\t\tif (this.collaborating) {\n\t\t\tthis.localSeq++;\n\t\t}\n\n\t\treturn {\n\t\t\tseq: this.collaborating ? UnassignedSequenceNumber : UniversalSequenceNumber,\n\t\t\tclientId: this.clientId,\n\t\t\tlocalSeq: this.localSeq,\n\t\t};\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;;;AAkLH,4CAEC;AA4HD,kCAeC;AAED,wBAEC;AAwPD,wCAEC;AAWD,oDAEC;AAxkBD,kEAA6D;AAI7D,iDAKwB;AACxB,2DAA4F;AAC5F,iEAAsF;AAEtF,6CAA0D;AAE1D,qDAA+F;AAC/F,mDAAmF;AAGnF,uDAY2B;AAyD3B;;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C,aAAa,CAAC,CAAC,CAAC,uCAAwB,CAAC,CAAC,CAAC,sCAAuB;YAC5E,QAAQ,EAAE,IAAI,CAAC,QAAQ;YACvB,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACvB,CAAC;IACH,CAAC;CACD;AAlGD,kDAkGC;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 type { AttributionKey } from \"@fluidframework/runtime-definitions/internal\";\n\nimport type { IAttributionCollection } from \"./attributionCollection.js\";\nimport {\n\tLocalClientId,\n\tNonCollabClient,\n\tUnassignedSequenceNumber,\n\tUniversalSequenceNumber,\n} from \"./constants.js\";\nimport { LocalReferenceCollection, type LocalReferencePosition } from \"./localReference.js\";\nimport { TrackingGroupCollection, type ITrackingGroup } from \"./mergeTreeTracking.js\";\nimport type { IJSONSegment, IMarkerDef, ReferenceType } from \"./ops.js\";\nimport { computeHierarchicalOrdinal } from \"./ordinal.js\";\nimport type { PartialSequenceLengths } from \"./partialLengths.js\";\nimport { LocalDefaultPerspective, PriorPerspective, type Perspective } from \"./perspective.js\";\nimport { type PropertySet, clone, createMap, type MapLike } from \"./properties.js\";\nimport type { ReferencePosition } from \"./referencePositions.js\";\nimport type { SegmentGroupCollection } from \"./segmentGroupCollection.js\";\nimport {\n\thasProp,\n\tisInserted,\n\tisMergeNodeInfo as isMergeNode,\n\tisRemoved,\n\toverwriteInfo,\n\ttype IHasInsertionInfo,\n\ttype IMergeNodeInfo,\n\ttype IHasRemovalInfo,\n\ttype SegmentWithInfo,\n\ttype ISegmentInsideObliterateInfo,\n\tisInsideObliterate,\n} from \"./segmentInfos.js\";\nimport type { PropertiesManager } from \"./segmentPropertiesManager.js\";\nimport type { Side } from \"./sequencePlace.js\";\nimport type { OperationStamp, SliceRemoveOperationStamp } from \"./stamps.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}\n/**\n * Segment leafs are segments that have both IMergeNodeInfo and IHasInsertionInfo. 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 & IHasInsertionInfo>;\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<IHasInsertionInfo>;\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 @beta\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 @beta\n */\nexport function segmentIsRemoved(segment: ISegment): boolean {\n\treturn isRemoved(segment);\n}\n\n/**\n * @legacy @beta\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<IHasInsertionInfo>;\n\treplaceCurrent?: SegmentWithInfo<IHasInsertionInfo>;\n}\n\nexport interface InsertContext {\n\tcandidateSegment?: SegmentWithInfo<IHasInsertionInfo>;\n\tleaf: (segment: ISegmentLeaf | undefined, pos: number, ic: InsertContext) => ISegmentChanges;\n\tcontinuePredicate?: (continueFromBlock: MergeBlock) => boolean;\n}\n\nexport interface ObliterateInfo {\n\tstart: LocalReferencePosition;\n\tstartSide: Side;\n\tend: LocalReferencePosition;\n\tendSide: Side;\n\trefSeq: number;\n\tstamp: SliceRemoveOperationStamp;\n\tsegmentGroup: SegmentGroup | undefined;\n\t/**\n\t * Defined only for unacked obliterates.\n\t *\n\t * Contains all segments inserted into the range this obliterate affects where at the time of insertion,\n\t * this obliterate was the newest concurrent obliterate that overlapped the insertion point (this information\n\t * is relevant for the tiebreak policy of allowing last-obliterater to insert).\n\t *\n\t * We need to keep this around for unacked ops because on reconnect, outstanding local obliterates may have set `obliteratePrecedingInsertion`\n\t * (tiebreak) on segments they no longer apply to, since the reissued obliterate may affect a smaller range than the original one when content\n\t * near the obliterate's endpoints was removed by another client between the time of the original obliterate and reissuing.\n\t */\n\ttiebreakTrackingGroup: ITrackingGroup | 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 initialized - 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 @beta\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<IHasInsertionInfo>(seg, {\n\t\t\t\tinsert: this.insert,\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<IHasRemovalInfo>(seg, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\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<IHasInsertionInfo>(leafSegment, { insert: this.insert });\n\t\t}\n\t\tif (isRemoved(this)) {\n\t\t\toverwriteInfo<IHasRemovalInfo>(leafSegment, {\n\t\t\t\tremoves: [...this.removes],\n\t\t\t});\n\t\t}\n\t\tif (isInsideObliterate(this)) {\n\t\t\toverwriteInfo<ISegmentInsideObliterateInfo>(leafSegment, {\n\t\t\t\tobliteratePrecedingInsertion: this.obliteratePrecedingInsertion,\n\t\t\t\tinsertionRefSeqStamp: this.insertionRefSeqStamp,\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 @beta\n */\nexport const reservedMarkerIdKey = \"markerId\";\n\n/**\n * @internal\n */\nexport const reservedMarkerSimpleTypeKey = \"markerSimpleType\";\n\n/**\n * @legacy @beta\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 @beta\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 * Returns a stamp that occurs at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqStamp(collabWindow: CollaborationWindow): OperationStamp {\n\treturn { seq: collabWindow.minSeq, clientId: NonCollabClient };\n}\n\n/**\n * Returns a perspective representing a readonly client's view of the tree at the minimum sequence number.\n * @privateRemarks\n * This is a free function over something obtainable on CollaborationWindow to avoid exposing Perspective\n * and OperationStamp from the package (even internally), at least for now.\n * If/when `Client`'s API is refactored to be structured similarly to MergeTree (so that SharedString passes in\n * things closer to `Perspective`s when calling methods on `Client` rather than refSeq/localSeq/clientId etc),\n * it may be more reasonable to expose this more directly on `CollaborationWindow`.\n */\nexport function getMinSeqPerspective(collabWindow: CollaborationWindow): Perspective {\n\treturn new PriorPerspective(collabWindow.minSeq, NonCollabClient);\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\tpublic localPerspective: Perspective = new LocalDefaultPerspective(this.clientId);\n\n\tpublic loadFrom(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\tpublic mintNextLocalOperationStamp(): OperationStamp {\n\t\tif (this.collaborating) {\n\t\t\tthis.localSeq++;\n\t\t}\n\n\t\treturn {\n\t\t\tseq: this.collaborating ? UnassignedSequenceNumber : UniversalSequenceNumber,\n\t\t\tclientId: this.clientId,\n\t\t\tlocalSeq: this.localSeq,\n\t\t};\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"]}
@@ -10,6 +10,7 @@ const sortedSegmentSet_js_1 = require("./sortedSegmentSet.js");
10
10
  * @legacy @beta
11
11
  */
12
12
  class TrackingGroup {
13
+ trackedSet;
13
14
  constructor() {
14
15
  this.trackedSet = new sortedSegmentSet_js_1.SortedSegmentSet();
15
16
  }
@@ -41,6 +42,7 @@ exports.TrackingGroup = TrackingGroup;
41
42
  * Tracking group backed by an unordered set. Lookup, insertion, and deletion are O(1)
42
43
  */
43
44
  class UnorderedTrackingGroup {
45
+ trackedSet;
44
46
  constructor() {
45
47
  this.trackedSet = new Set();
46
48
  }
@@ -73,6 +75,8 @@ exports.UnorderedTrackingGroup = UnorderedTrackingGroup;
73
75
  * @legacy @beta
74
76
  */
75
77
  class TrackingGroupCollection {
78
+ trackable;
79
+ _trackingGroups;
76
80
  get trackingGroups() {
77
81
  // Cast here is necessary to avoid a breaking change to
78
82
  // `TrackingGroupCollection`. Ideally we could just return