@fluidframework/merge-tree 2.30.0 → 2.31.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 (308) hide show
  1. package/CHANGELOG.md +403 -399
  2. package/api-report/merge-tree.legacy.alpha.api.md +1 -0
  3. package/dist/MergeTreeTextHelper.d.ts +9 -3
  4. package/dist/MergeTreeTextHelper.d.ts.map +1 -1
  5. package/dist/MergeTreeTextHelper.js +5 -5
  6. package/dist/MergeTreeTextHelper.js.map +1 -1
  7. package/dist/client.d.ts +7 -13
  8. package/dist/client.d.ts.map +1 -1
  9. package/dist/client.js +136 -110
  10. package/dist/client.js.map +1 -1
  11. package/dist/endOfTreeSegment.d.ts +12 -8
  12. package/dist/endOfTreeSegment.d.ts.map +1 -1
  13. package/dist/endOfTreeSegment.js +2 -4
  14. package/dist/endOfTreeSegment.js.map +1 -1
  15. package/dist/index.d.ts +6 -3
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +2 -3
  18. package/dist/index.js.map +1 -1
  19. package/dist/mergeTree.d.ts +37 -23
  20. package/dist/mergeTree.d.ts.map +1 -1
  21. package/dist/mergeTree.js +400 -483
  22. package/dist/mergeTree.js.map +1 -1
  23. package/dist/mergeTreeDeltaCallback.d.ts +4 -8
  24. package/dist/mergeTreeDeltaCallback.d.ts.map +1 -1
  25. package/dist/mergeTreeDeltaCallback.js.map +1 -1
  26. package/dist/mergeTreeNodes.d.ts +32 -10
  27. package/dist/mergeTreeNodes.d.ts.map +1 -1
  28. package/dist/mergeTreeNodes.js +43 -28
  29. package/dist/mergeTreeNodes.js.map +1 -1
  30. package/dist/partialLengths.d.ts +2 -2
  31. package/dist/partialLengths.d.ts.map +1 -1
  32. package/dist/partialLengths.js +181 -109
  33. package/dist/partialLengths.js.map +1 -1
  34. package/dist/perspective.d.ts +8 -27
  35. package/dist/perspective.d.ts.map +1 -1
  36. package/dist/perspective.js +7 -67
  37. package/dist/perspective.js.map +1 -1
  38. package/dist/revertibles.d.ts.map +1 -1
  39. package/dist/revertibles.js +2 -2
  40. package/dist/revertibles.js.map +1 -1
  41. package/dist/segmentInfos.d.ts +20 -106
  42. package/dist/segmentInfos.d.ts.map +1 -1
  43. package/dist/segmentInfos.js +28 -42
  44. package/dist/segmentInfos.js.map +1 -1
  45. package/dist/segmentPropertiesManager.d.ts +1 -14
  46. package/dist/segmentPropertiesManager.d.ts.map +1 -1
  47. package/dist/segmentPropertiesManager.js +3 -17
  48. package/dist/segmentPropertiesManager.js.map +1 -1
  49. package/dist/snapshotLoader.d.ts.map +1 -1
  50. package/dist/snapshotLoader.js +62 -19
  51. package/dist/snapshotLoader.js.map +1 -1
  52. package/dist/snapshotV1.d.ts.map +1 -1
  53. package/dist/snapshotV1.js +55 -24
  54. package/dist/snapshotV1.js.map +1 -1
  55. package/dist/snapshotlegacy.d.ts.map +1 -1
  56. package/dist/snapshotlegacy.js +6 -9
  57. package/dist/snapshotlegacy.js.map +1 -1
  58. package/dist/stamps.d.ts +1 -1
  59. package/dist/stamps.js +1 -1
  60. package/dist/stamps.js.map +1 -1
  61. package/dist/test/Insertion.perf.spec.js +6 -51
  62. package/dist/test/Insertion.perf.spec.js.map +1 -1
  63. package/dist/test/PartialLengths.perf.spec.js +18 -25
  64. package/dist/test/PartialLengths.perf.spec.js.map +1 -1
  65. package/dist/test/Removal.perf.spec.js +13 -41
  66. package/dist/test/Removal.perf.spec.js.map +1 -1
  67. package/dist/test/beastTest.spec.d.ts.map +1 -1
  68. package/dist/test/beastTest.spec.js +41 -66
  69. package/dist/test/beastTest.spec.js.map +1 -1
  70. package/dist/test/client.annotateMarker.spec.js +1 -11
  71. package/dist/test/client.annotateMarker.spec.js.map +1 -1
  72. package/dist/test/client.applyMsg.spec.js +14 -14
  73. package/dist/test/client.applyMsg.spec.js.map +1 -1
  74. package/dist/test/client.getPosition.spec.js +1 -1
  75. package/dist/test/client.getPosition.spec.js.map +1 -1
  76. package/dist/test/client.localReference.spec.js +1 -1
  77. package/dist/test/client.localReference.spec.js.map +1 -1
  78. package/dist/test/client.rollback.spec.js +49 -58
  79. package/dist/test/client.rollback.spec.js.map +1 -1
  80. package/dist/test/client.rollbackFarm.spec.js +1 -1
  81. package/dist/test/client.rollbackFarm.spec.js.map +1 -1
  82. package/dist/test/client.searchForMarker.spec.js +4 -21
  83. package/dist/test/client.searchForMarker.spec.js.map +1 -1
  84. package/dist/test/index.d.ts +2 -2
  85. package/dist/test/index.d.ts.map +1 -1
  86. package/dist/test/index.js +2 -6
  87. package/dist/test/index.js.map +1 -1
  88. package/dist/test/mergeTree.annotate.deltaCallback.spec.js +14 -59
  89. package/dist/test/mergeTree.annotate.deltaCallback.spec.js.map +1 -1
  90. package/dist/test/mergeTree.annotate.spec.js +47 -63
  91. package/dist/test/mergeTree.annotate.spec.js.map +1 -1
  92. package/dist/test/mergeTree.insert.deltaCallback.spec.js +9 -62
  93. package/dist/test/mergeTree.insert.deltaCallback.spec.js.map +1 -1
  94. package/dist/test/mergeTree.insertingWalk.spec.js +59 -125
  95. package/dist/test/mergeTree.insertingWalk.spec.js.map +1 -1
  96. package/dist/test/mergeTree.markRangeRemoved.deltaCallback.spec.js +12 -93
  97. package/dist/test/mergeTree.markRangeRemoved.deltaCallback.spec.js.map +1 -1
  98. package/dist/test/mergeTree.markRangeRemoved.spec.js +10 -7
  99. package/dist/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
  100. package/dist/test/mergeTree.walk.spec.js +2 -14
  101. package/dist/test/mergeTree.walk.spec.js.map +1 -1
  102. package/dist/test/mergeTreeOperationRunner.js +2 -2
  103. package/dist/test/mergeTreeOperationRunner.js.map +1 -1
  104. package/dist/test/obliterate.concurrent.spec.js +18 -23
  105. package/dist/test/obliterate.concurrent.spec.js.map +1 -1
  106. package/dist/test/obliterate.partialLength.spec.js +166 -136
  107. package/dist/test/obliterate.partialLength.spec.js.map +1 -1
  108. package/dist/test/obliterate.spec.js +16 -126
  109. package/dist/test/obliterate.spec.js.map +1 -1
  110. package/dist/test/partialLength.spec.js +28 -196
  111. package/dist/test/partialLength.spec.js.map +1 -1
  112. package/dist/test/perspective.spec.js +34 -0
  113. package/dist/test/perspective.spec.js.map +1 -1
  114. package/dist/test/propertyManager.spec.js +1 -1
  115. package/dist/test/propertyManager.spec.js.map +1 -1
  116. package/dist/test/resetPendingSegmentsToOp.spec.js +0 -2
  117. package/dist/test/resetPendingSegmentsToOp.spec.js.map +1 -1
  118. package/dist/test/segmentGroupCollection.spec.js +10 -4
  119. package/dist/test/segmentGroupCollection.spec.js.map +1 -1
  120. package/dist/test/testClient.d.ts +1 -0
  121. package/dist/test/testClient.d.ts.map +1 -1
  122. package/dist/test/testClient.js +16 -26
  123. package/dist/test/testClient.js.map +1 -1
  124. package/dist/test/testClientLogger.d.ts.map +1 -1
  125. package/dist/test/testClientLogger.js +3 -10
  126. package/dist/test/testClientLogger.js.map +1 -1
  127. package/dist/test/testServer.d.ts +2 -1
  128. package/dist/test/testServer.d.ts.map +1 -1
  129. package/dist/test/testServer.js +7 -5
  130. package/dist/test/testServer.js.map +1 -1
  131. package/dist/test/testUtils.d.ts +36 -56
  132. package/dist/test/testUtils.d.ts.map +1 -1
  133. package/dist/test/testUtils.js +68 -77
  134. package/dist/test/testUtils.js.map +1 -1
  135. package/dist/test/text.d.ts +2 -2
  136. package/dist/test/text.d.ts.map +1 -1
  137. package/dist/test/text.js +5 -2
  138. package/dist/test/text.js.map +1 -1
  139. package/dist/textSegment.d.ts +0 -6
  140. package/dist/textSegment.d.ts.map +1 -1
  141. package/dist/textSegment.js.map +1 -1
  142. package/dist/zamboni.d.ts.map +1 -1
  143. package/dist/zamboni.js +53 -26
  144. package/dist/zamboni.js.map +1 -1
  145. package/lib/MergeTreeTextHelper.d.ts +9 -3
  146. package/lib/MergeTreeTextHelper.d.ts.map +1 -1
  147. package/lib/MergeTreeTextHelper.js +5 -5
  148. package/lib/MergeTreeTextHelper.js.map +1 -1
  149. package/lib/client.d.ts +7 -13
  150. package/lib/client.d.ts.map +1 -1
  151. package/lib/client.js +117 -116
  152. package/lib/client.js.map +1 -1
  153. package/lib/endOfTreeSegment.d.ts +12 -8
  154. package/lib/endOfTreeSegment.d.ts.map +1 -1
  155. package/lib/endOfTreeSegment.js +2 -4
  156. package/lib/endOfTreeSegment.js.map +1 -1
  157. package/lib/index.d.ts +6 -3
  158. package/lib/index.d.ts.map +1 -1
  159. package/lib/index.js +1 -1
  160. package/lib/index.js.map +1 -1
  161. package/lib/mergeTree.d.ts +37 -23
  162. package/lib/mergeTree.d.ts.map +1 -1
  163. package/lib/mergeTree.js +381 -488
  164. package/lib/mergeTree.js.map +1 -1
  165. package/lib/mergeTreeDeltaCallback.d.ts +4 -8
  166. package/lib/mergeTreeDeltaCallback.d.ts.map +1 -1
  167. package/lib/mergeTreeDeltaCallback.js.map +1 -1
  168. package/lib/mergeTreeNodes.d.ts +32 -10
  169. package/lib/mergeTreeNodes.d.ts.map +1 -1
  170. package/lib/mergeTreeNodes.js +42 -29
  171. package/lib/mergeTreeNodes.js.map +1 -1
  172. package/lib/partialLengths.d.ts +2 -2
  173. package/lib/partialLengths.d.ts.map +1 -1
  174. package/lib/partialLengths.js +160 -111
  175. package/lib/partialLengths.js.map +1 -1
  176. package/lib/perspective.d.ts +8 -27
  177. package/lib/perspective.d.ts.map +1 -1
  178. package/lib/perspective.js +8 -68
  179. package/lib/perspective.js.map +1 -1
  180. package/lib/revertibles.d.ts.map +1 -1
  181. package/lib/revertibles.js +2 -2
  182. package/lib/revertibles.js.map +1 -1
  183. package/lib/segmentInfos.d.ts +20 -106
  184. package/lib/segmentInfos.d.ts.map +1 -1
  185. package/lib/segmentInfos.js +26 -37
  186. package/lib/segmentInfos.js.map +1 -1
  187. package/lib/segmentPropertiesManager.d.ts +1 -14
  188. package/lib/segmentPropertiesManager.d.ts.map +1 -1
  189. package/lib/segmentPropertiesManager.js +2 -16
  190. package/lib/segmentPropertiesManager.js.map +1 -1
  191. package/lib/snapshotLoader.d.ts.map +1 -1
  192. package/lib/snapshotLoader.js +39 -19
  193. package/lib/snapshotLoader.js.map +1 -1
  194. package/lib/snapshotV1.d.ts.map +1 -1
  195. package/lib/snapshotV1.js +34 -26
  196. package/lib/snapshotV1.js.map +1 -1
  197. package/lib/snapshotlegacy.d.ts.map +1 -1
  198. package/lib/snapshotlegacy.js +7 -10
  199. package/lib/snapshotlegacy.js.map +1 -1
  200. package/lib/stamps.d.ts +1 -1
  201. package/lib/stamps.js +1 -1
  202. package/lib/stamps.js.map +1 -1
  203. package/lib/test/Insertion.perf.spec.js +6 -51
  204. package/lib/test/Insertion.perf.spec.js.map +1 -1
  205. package/lib/test/PartialLengths.perf.spec.js +18 -25
  206. package/lib/test/PartialLengths.perf.spec.js.map +1 -1
  207. package/lib/test/Removal.perf.spec.js +13 -41
  208. package/lib/test/Removal.perf.spec.js.map +1 -1
  209. package/lib/test/beastTest.spec.d.ts.map +1 -1
  210. package/lib/test/beastTest.spec.js +42 -67
  211. package/lib/test/beastTest.spec.js.map +1 -1
  212. package/lib/test/client.annotateMarker.spec.js +1 -11
  213. package/lib/test/client.annotateMarker.spec.js.map +1 -1
  214. package/lib/test/client.applyMsg.spec.js +14 -14
  215. package/lib/test/client.applyMsg.spec.js.map +1 -1
  216. package/lib/test/client.getPosition.spec.js +1 -1
  217. package/lib/test/client.getPosition.spec.js.map +1 -1
  218. package/lib/test/client.localReference.spec.js +1 -1
  219. package/lib/test/client.localReference.spec.js.map +1 -1
  220. package/lib/test/client.rollback.spec.js +50 -59
  221. package/lib/test/client.rollback.spec.js.map +1 -1
  222. package/lib/test/client.rollbackFarm.spec.js +1 -1
  223. package/lib/test/client.rollbackFarm.spec.js.map +1 -1
  224. package/lib/test/client.searchForMarker.spec.js +4 -21
  225. package/lib/test/client.searchForMarker.spec.js.map +1 -1
  226. package/lib/test/index.d.ts +2 -2
  227. package/lib/test/index.d.ts.map +1 -1
  228. package/lib/test/index.js +1 -1
  229. package/lib/test/index.js.map +1 -1
  230. package/lib/test/mergeTree.annotate.deltaCallback.spec.js +15 -60
  231. package/lib/test/mergeTree.annotate.deltaCallback.spec.js.map +1 -1
  232. package/lib/test/mergeTree.annotate.spec.js +48 -64
  233. package/lib/test/mergeTree.annotate.spec.js.map +1 -1
  234. package/lib/test/mergeTree.insert.deltaCallback.spec.js +10 -63
  235. package/lib/test/mergeTree.insert.deltaCallback.spec.js.map +1 -1
  236. package/lib/test/mergeTree.insertingWalk.spec.js +61 -127
  237. package/lib/test/mergeTree.insertingWalk.spec.js.map +1 -1
  238. package/lib/test/mergeTree.markRangeRemoved.deltaCallback.spec.js +13 -94
  239. package/lib/test/mergeTree.markRangeRemoved.deltaCallback.spec.js.map +1 -1
  240. package/lib/test/mergeTree.markRangeRemoved.spec.js +10 -7
  241. package/lib/test/mergeTree.markRangeRemoved.spec.js.map +1 -1
  242. package/lib/test/mergeTree.walk.spec.js +2 -14
  243. package/lib/test/mergeTree.walk.spec.js.map +1 -1
  244. package/lib/test/mergeTreeOperationRunner.js +3 -3
  245. package/lib/test/mergeTreeOperationRunner.js.map +1 -1
  246. package/lib/test/obliterate.concurrent.spec.js +18 -23
  247. package/lib/test/obliterate.concurrent.spec.js.map +1 -1
  248. package/lib/test/obliterate.partialLength.spec.js +167 -137
  249. package/lib/test/obliterate.partialLength.spec.js.map +1 -1
  250. package/lib/test/obliterate.spec.js +17 -127
  251. package/lib/test/obliterate.spec.js.map +1 -1
  252. package/lib/test/partialLength.spec.js +29 -197
  253. package/lib/test/partialLength.spec.js.map +1 -1
  254. package/lib/test/perspective.spec.js +34 -0
  255. package/lib/test/perspective.spec.js.map +1 -1
  256. package/lib/test/propertyManager.spec.js +2 -2
  257. package/lib/test/propertyManager.spec.js.map +1 -1
  258. package/lib/test/resetPendingSegmentsToOp.spec.js +0 -2
  259. package/lib/test/resetPendingSegmentsToOp.spec.js.map +1 -1
  260. package/lib/test/segmentGroupCollection.spec.js +10 -4
  261. package/lib/test/segmentGroupCollection.spec.js.map +1 -1
  262. package/lib/test/testClient.d.ts +1 -0
  263. package/lib/test/testClient.d.ts.map +1 -1
  264. package/lib/test/testClient.js +18 -28
  265. package/lib/test/testClient.js.map +1 -1
  266. package/lib/test/testClientLogger.d.ts.map +1 -1
  267. package/lib/test/testClientLogger.js +3 -10
  268. package/lib/test/testClientLogger.js.map +1 -1
  269. package/lib/test/testServer.d.ts +2 -1
  270. package/lib/test/testServer.d.ts.map +1 -1
  271. package/lib/test/testServer.js +7 -5
  272. package/lib/test/testServer.js.map +1 -1
  273. package/lib/test/testUtils.d.ts +36 -56
  274. package/lib/test/testUtils.d.ts.map +1 -1
  275. package/lib/test/testUtils.js +66 -48
  276. package/lib/test/testUtils.js.map +1 -1
  277. package/lib/test/text.d.ts +2 -2
  278. package/lib/test/text.d.ts.map +1 -1
  279. package/lib/test/text.js +6 -3
  280. package/lib/test/text.js.map +1 -1
  281. package/lib/textSegment.d.ts +0 -6
  282. package/lib/textSegment.d.ts.map +1 -1
  283. package/lib/textSegment.js.map +1 -1
  284. package/lib/tsdoc-metadata.json +1 -1
  285. package/lib/zamboni.d.ts.map +1 -1
  286. package/lib/zamboni.js +32 -28
  287. package/lib/zamboni.js.map +1 -1
  288. package/package.json +17 -20
  289. package/src/MergeTreeTextHelper.ts +17 -12
  290. package/src/client.ts +141 -197
  291. package/src/endOfTreeSegment.ts +11 -8
  292. package/src/index.ts +4 -3
  293. package/src/mergeTree.ts +482 -633
  294. package/src/mergeTreeDeltaCallback.ts +4 -8
  295. package/src/mergeTreeNodes.ts +66 -45
  296. package/src/partialLengths.ts +181 -137
  297. package/src/perspective.ts +17 -95
  298. package/src/revertibles.ts +2 -7
  299. package/src/segmentInfos.ts +48 -141
  300. package/src/segmentPropertiesManager.ts +2 -16
  301. package/src/snapshotLoader.ts +62 -30
  302. package/src/snapshotV1.ts +36 -28
  303. package/src/snapshotlegacy.ts +7 -16
  304. package/src/stamps.ts +1 -1
  305. package/src/textSegment.ts +0 -13
  306. package/src/zamboni.ts +38 -32
  307. package/tsconfig.json +1 -0
  308. package/prettier.config.cjs +0 -8
@@ -1 +1 @@
1
- {"version":3,"file":"perspective.js","sourceRoot":"","sources":["../src/perspective.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,aAAa,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAEzE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,MAAM,EAAqB,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAC1E,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAkD5C,MAAe,eAAe;IAG7B;;;;;;;;OAQG;IACI,WAAW,CACjB,SAAoB,EACpB,OAAqB,EACrB,UAAmB,IAAI;QAEvB,IAAI,IAA8B,CAAC;QACnC,MAAM,MAAM,GAAG,CAAC,GAAiB,EAAuB,EAAE;YACzD,IAAI,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;gBAChC,IAAI,GAAG,GAAG,CAAC;gBACX,OAAO,UAAU,CAAC,IAAI,CAAC;YACxB,CAAC;QACF,CAAC,CAAC;QACF,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;QAClE,OAAO,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;IACxE,CAAC;IAED;;;;;OAKG;IACI,eAAe,CAAC,SAAoB,EAAE,OAAqB;QACjE,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,CAAC;IACpD,CAAC;IAEM,gBAAgB,CAAC,GAAiB;QACxC,MAAM,MAAM,GAAyB;YACpC,IAAI,E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CAAC;QACzD,MAAM,mBAAmB,GACxB,KAAK,CAAC,QAAQ,KAAK,SAAS,IAAI,KAAK,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QACjE,OAAO,iBAAiB,IAAI,mBAAmB,CAAC;IACjD,CAAC;CACD;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,uBAAwB,SAAQ,eAAe;IAG3D,YAAmC,QAAgB;QAClD,KAAK,EAAE,CAAC;QAD0B,aAAQ,GAAR,QAAQ,CAAQ;QAFnC,WAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAIjD,CAAC;IAEM,WAAW,CAAC,MAAsB;QACxC,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;;;;;GAOG;AACH,MAAM,OAAO,2BAA4B,SAAQ,eAAe;IAG/D,YAA4B,QAAgB;QAC3C,KAAK,EAAE,CAAC;QADmB,aAAQ,GAAR,QAAQ,CAAQ;QAF5B,WAAM,GAAG,MAAM,CAAC,gBAAgB,CAAC;IAIjD,CAAC;IAEM,WAAW,CAAC,KAAkD;QACpE,oHAAoH;QACpH,+GAA+G;QAC/G,yHAAyH;QACzH,sHAAsH;QACtH,iCAAiC;QACjC,IAAI,KAAK,CAAC,IAAI,KAAK,QAAQ,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAC5D,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { LocalClientId, UnassignedSequenceNumber } from \"./constants.js\";\nimport { type MergeTree } from \"./mergeTree.js\";\nimport { LeafAction, backwardExcursion, forwardExcursion } from \"./mergeTreeNodeWalk.js\";\nimport { seqLTE, type ISegmentLeaf } from \"./mergeTreeNodes.js\";\nimport { isInserted, toMoveInfo, toRemovalInfo } from \"./segmentInfos.js\";\nimport * as opstampUtils from \"./stamps.js\";\nimport type { OperationStamp, InsertOperationStamp, RemoveOperationStamp } from \"./stamps.js\";\n\n/**\n * A perspective which includes some subset of operations known to the local client.\n *\n * This helps the local client reason about the state of other clients when they issued an operation.\n */\nexport interface Perspective {\n\t/**\n\t * The sequence number last seen from this perspective. Same concept as `ISequencedDocumentMessage.referenceSequenceNumber`.\n\t * @privateRemarks\n\t * This currently allows inter-operation between MergeTree methods and the partial lengths implementation, which still depends\n\t * on the (refSeq, clientId, localSeq?) representation of perspectives.\n\t */\n\treadonly refSeq: number;\n\n\t/**\n\t * The client id for this perspective.\n\t * @privateRemarks\n\t * This currently allows inter-operation between MergeTree methods and the partial lengths implementation, which still depends\n\t * on the (refSeq, clientId, localSeq?) representation of perspectives.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * When this is a local perspective, the local sequence number last seen from this perspective.\n\t *\n\t * Perspectives with defined `localSeq` values are useful in reconnection flows, where the local client may need to resend some\n\t * of its ops after rederiving their new equivalents.\n\t * @privateRemarks\n\t * This currently allows inter-operation between MergeTree methods and the partial lengths implementation, which still depends\n\t * on the (refSeq, clientId, localSeq?) representation of perspectives.\n\t */\n\treadonly localSeq?: number;\n\n\t/**\n\t * @returns Whether the segment is present (visible) from this perspective\n\t */\n\tisSegmentPresent(segment: ISegmentLeaf): boolean;\n\n\t/**\n\t * @returns Whether this perspective has seen the given operation.\n\t */\n\thasOccurred(stamp: RemoveOperationStamp | InsertOperationStamp): boolean;\n\n\tnextSegment(mergeTree: MergeTree, segment: ISegmentLeaf, forward?: boolean): ISegmentLeaf;\n\tpreviousSegment(mergeTree: MergeTree, segment: ISegmentLeaf): ISegmentLeaf;\n}\n\nabstract class PerspectiveBase {\n\tabstract hasOccurred(stamp: RemoveOperationStamp | InsertOperationStamp): boolean;\n\n\t/**\n\t * Returns the immediately adjacent segment in the specified direction from this perspective.\n\t * There may actually be multiple segments between the given segment and the returned segment,\n\t * but they were either inserted after this perspective, or have been removed before this perspective.\n\t *\n\t * @param segment - The segment to start from.\n\t * @param forward - The direction to search.\n\t * @returns the next segment in the specified direction, or the start or end of the tree if there is no next segment.\n\t */\n\tpublic nextSegment(\n\t\tmergeTree: MergeTree,\n\t\tsegment: ISegmentLeaf,\n\t\tforward: boolean = true,\n\t): ISegmentLeaf {\n\t\tlet next: ISegmentLeaf | undefined;\n\t\tconst action = (seg: ISegmentLeaf): boolean | undefined => {\n\t\t\tif (this.isSegmentPresent(seg)) {\n\t\t\t\tnext = seg;\n\t\t\t\treturn LeafAction.Exit;\n\t\t\t}\n\t\t};\n\t\t(forward ? forwardExcursion : backwardExcursion)(segment, action);\n\t\treturn next ?? (forward ? mergeTree.endOfTree : mergeTree.startOfTree);\n\t}\n\n\t/**\n\t * Finds the segment prior to the given segment.\n\t * @param segment - The segment to start from.\n\t * @returns the previous segment, or the start of the tree if there is no previous segment.\n\t * @remarks This is a convenient equivalent to calling `nextSegment(segment, false)`.\n\t */\n\tpublic previousSegment(mergeTree: MergeTree, segment: ISegmentLeaf): ISegmentLeaf {\n\t\treturn this.nextSegment(mergeTree, segment, false);\n\t}\n\n\tpublic isSegmentPresent(seg: ISegmentLeaf): boolean {\n\t\tconst insert: InsertOperationStamp = {\n\t\t\ttype: \"insert\",\n\t\t\tclientId: seg.clientId,\n\t\t\tseq: seg.seq,\n\t\t\tlocalSeq: seg.localSeq,\n\t\t};\n\t\tif (isInserted(seg) && !this.hasOccurred(insert)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tconst removes: RemoveOperationStamp[] = [];\n\t\tconst removalInfo = toRemovalInfo(seg);\n\t\tif (removalInfo !== undefined) {\n\t\t\tremoves.push(\n\t\t\t\t...removalInfo.removedClientIds.map((clientId) =>\n\t\t\t\t\t(clientId === LocalClientId || clientId === 0) &&\n\t\t\t\t\tremovalInfo.localRemovedSeq !== undefined\n\t\t\t\t\t\t? ({\n\t\t\t\t\t\t\t\ttype: \"setRemove\",\n\t\t\t\t\t\t\t\tseq: UnassignedSequenceNumber,\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tlocalSeq: removalInfo.localRemovedSeq,\n\t\t\t\t\t\t\t} as const)\n\t\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\t({ type: \"setRemove\", seq: removalInfo.removedSeq, clientId } as const),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tconst moveInfo = toMoveInfo(seg);\n\t\tif (moveInfo !== undefined) {\n\t\t\tremoves.push(\n\t\t\t\t...moveInfo.movedClientIds.map((clientId, index) =>\n\t\t\t\t\t(clientId === LocalClientId || clientId === 0) &&\n\t\t\t\t\tmoveInfo.localMovedSeq !== undefined\n\t\t\t\t\t\t? ({\n\t\t\t\t\t\t\t\ttype: \"sliceRemove\",\n\t\t\t\t\t\t\t\tseq: UnassignedSequenceNumber,\n\t\t\t\t\t\t\t\tclientId,\n\t\t\t\t\t\t\t\tlocalSeq: moveInfo.localMovedSeq,\n\t\t\t\t\t\t\t} as const)\n\t\t\t\t\t\t: // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\t({ type: \"setRemove\", seq: moveInfo.movedSeqs[index]!, clientId } as const),\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tif (removes.some((remove) => this.hasOccurred(remove))) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\n/**\n * A perspective which includes edits at or before some reference sequence number alongside all edits from some particular client.\n *\n * @remarks\n * This works for both the local client as well as remote clients since refSeq-based checks disallow unacked edits, but the clientId check\n * catches unacked edits from the local client.\n */\nexport class PriorPerspective extends PerspectiveBase implements Perspective {\n\tpublic constructor(\n\t\tpublic readonly refSeq: number,\n\t\tpublic readonly clientId: number,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(stamp: OperationStamp): boolean {\n\t\tconst predatesViaRefSeq = seqLTE(stamp.seq, this.refSeq);\n\t\tconst predatesViaSameClient = stamp.clientId === this.clientId;\n\t\treturn predatesViaRefSeq || predatesViaSameClient;\n\t}\n}\n\n/**\n * A perspective which includes edits which were either:\n * - acked and at or before some reference sequence number\n * - unacked, but at or before some local sequence number\n *\n * This is a useful perspective when the local client is in the process of reconnecting, since it must\n * rederive positions for unacked ops while only considering a portion of its own edits as having been applied.\n */\nexport class LocalReconnectingPerspective extends PerspectiveBase implements Perspective {\n\tpublic constructor(\n\t\tpublic readonly refSeq: number,\n\t\tpublic readonly clientId: number,\n\t\tpublic readonly localSeq: number,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(stamp: OperationStamp): boolean {\n\t\tconst predatesViaRefSeq = seqLTE(stamp.seq, this.refSeq);\n\t\tconst predatesViaLocalSeq =\n\t\t\tstamp.localSeq !== undefined && stamp.localSeq <= this.localSeq;\n\t\treturn predatesViaRefSeq || predatesViaLocalSeq;\n\t}\n}\n\n/**\n * A perspective which includes all known edits.\n *\n * This is the perspective that the application sees.\n * @remarks\n * This can be represented using {@link PriorPerspective} with a refSeq of `Number.MAX_SAFE_INTEGER`, but having an explicit\n * variant of this perspective renders extra refSeq checks unnecessary and is a bit easier to read.\n */\nexport class LocalDefaultPerspective extends PerspectiveBase implements Perspective {\n\tpublic readonly refSeq = Number.MAX_SAFE_INTEGER;\n\n\tpublic constructor(public readonly clientId: number) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(_stamp: OperationStamp): boolean {\n\t\treturn true;\n\t}\n}\n\n/**\n * A perspective dictating whether segments are 'visible' to a remote obliterate operation.\n *\n * NOTE: Beware that partial lengths doesn't support this perspective, in the sense that consulting partial lengths' for the length of a block\n * can give different results than summing the lengths of present segments in that block.\n * This ends up not affecting the current obliterate implementation (which has some special casing in the mapRange calls it uses),\n * but use with caution.\n */\nexport class RemoteObliteratePerspective extends PerspectiveBase implements Perspective {\n\tpublic readonly refSeq = Number.MAX_SAFE_INTEGER;\n\n\tconstructor(public readonly clientId: number) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(stamp: InsertOperationStamp | RemoveOperationStamp): boolean {\n\t\t// Local-only removals are not visible to an obliterate operation, since this means the local removal was concurrent\n\t\t// to a remote obliterate and we may need to mark the segment appropriately to reflect this overlapping remove.\n\t\t// Every other type of operation is visible: obliterates do not affect segments that have already been removed and acked,\n\t\t// and they always affect segments within their range that have not been removed, even if those segments were inserted\n\t\t// after the obliterate's refSeq.\n\t\tif (stamp.type !== \"insert\" && opstampUtils.isLocal(stamp)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n"]}
1
+ {"version":3,"file":"perspective.js","sourceRoot":"","sources":["../src/perspective.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAiB,MAAM,qBAAqB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,YAAY,MAAM,aAAa,CAAC;AAgD5C,MAAe,eAAe;IAGtB,gBAAgB,CAAC,GAAa;QACpC,IAAI,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC;YACtD,OAAO,KAAK,CAAC;QACd,CAAC;QAED,IAAI,SAAS,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;YAC9E,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,eAAe;IACpD,YACiB,MAAc,EACd,QAAgB;QAEhC,KAAK,EAAE,CAAC;QAHQ,WAAM,GAAN,MAAM,CAAQ;QACd,aAAQ,GAAR,QAAQ,CAAQ;IAGjC,CAAC;IAEM,WAAW,CAAC,KAAqB;QACvC,MAAM,iBAAiB,GAAG,M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GAA+G;QAC/G,yHAAyH;QACzH,sHAAsH;QACtH,iCAAiC;QACjC,IAAI,sBAAsB,CAAC,KAAK,CAAC,IAAI,YAAY,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAClE,OAAO,KAAK,CAAC;QACd,CAAC;QAED,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AAED,SAAS,sBAAsB,CAAC,KAAqB;IACpD,MAAM,EAAE,IAAI,EAAE,GAAG,KAAwC,CAAC;IAC1D,OAAO,IAAI,KAAK,WAAW,IAAI,IAAI,KAAK,aAAa,CAAC;AACvD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { seqLTE, type ISegment } from \"./mergeTreeNodes.js\";\nimport { isInserted, isRemoved } from \"./segmentInfos.js\";\nimport * as opstampUtils from \"./stamps.js\";\nimport type { OperationStamp, RemoveOperationStamp } from \"./stamps.js\";\n\n/**\n * A perspective which includes some subset of operations known to the local client.\n *\n * This helps the local client reason about the state of other clients when they issued an operation.\n * @internal\n */\nexport interface Perspective {\n\t/**\n\t * The sequence number last seen from this perspective. Same concept as `ISequencedDocumentMessage.referenceSequenceNumber`.\n\t * @privateRemarks\n\t * This currently allows inter-operation between MergeTree methods and the partial lengths implementation, which still depends\n\t * on the (refSeq, clientId, localSeq?) representation of perspectives.\n\t */\n\treadonly refSeq: number;\n\n\t/**\n\t * The client id for this perspective.\n\t * @privateRemarks\n\t * This currently allows inter-operation between MergeTree methods and the partial lengths implementation, which still depends\n\t * on the (refSeq, clientId, localSeq?) representation of perspectives.\n\t */\n\treadonly clientId: number;\n\n\t/**\n\t * When this is a local perspective, the local sequence number last seen from this perspective.\n\t *\n\t * Perspectives with defined `localSeq` values are useful in reconnection flows, where the local client may need to resend some\n\t * of its ops after rederiving their new equivalents.\n\t * @privateRemarks\n\t * This currently allows inter-operation between MergeTree methods and the partial lengths implementation, which still depends\n\t * on the (refSeq, clientId, localSeq?) representation of perspectives.\n\t */\n\treadonly localSeq?: number;\n\n\t/**\n\t * @returns Whether the segment is present (visible) from this perspective\n\t */\n\tisSegmentPresent(segment: ISegment): boolean;\n\n\t/**\n\t * @returns Whether this perspective has seen the given operation.\n\t */\n\thasOccurred(stamp: OperationStamp): boolean;\n}\n\nabstract class PerspectiveBase {\n\tabstract hasOccurred(stamp: OperationStamp): boolean;\n\n\tpublic isSegmentPresent(seg: ISegment): boolean {\n\t\tif (isInserted(seg) && !this.hasOccurred(seg.insert)) {\n\t\t\treturn false;\n\t\t}\n\n\t\tif (isRemoved(seg) && seg.removes.some((remove) => this.hasOccurred(remove))) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\n/**\n * A perspective which includes edits at or before some reference sequence number alongside all edits from some particular client.\n *\n * @remarks\n * This works for both the local client as well as remote clients since refSeq-based checks disallow unacked edits, but the clientId check\n * catches unacked edits from the local client.\n */\nexport class PriorPerspective extends PerspectiveBase implements Perspective {\n\tpublic constructor(\n\t\tpublic readonly refSeq: number,\n\t\tpublic readonly clientId: number,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(stamp: OperationStamp): boolean {\n\t\tconst predatesViaRefSeq = seqLTE(stamp.seq, this.refSeq);\n\t\tconst predatesViaSameClient = stamp.clientId === this.clientId;\n\t\treturn predatesViaRefSeq || predatesViaSameClient;\n\t}\n}\n\n/**\n * A perspective which includes edits which were either:\n * - acked and at or before some reference sequence number\n * - unacked, but at or before some local sequence number\n *\n * This is a useful perspective when the local client is in the process of reconnecting, since it must\n * rederive positions for unacked ops while only considering a portion of its own edits as having been applied.\n */\nexport class LocalReconnectingPerspective extends PerspectiveBase implements Perspective {\n\tpublic constructor(\n\t\tpublic readonly refSeq: number,\n\t\tpublic readonly clientId: number,\n\t\tpublic readonly localSeq: number,\n\t) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(stamp: OperationStamp): boolean {\n\t\tconst predatesViaRefSeq = seqLTE(stamp.seq, this.refSeq);\n\t\tconst predatesViaLocalSeq =\n\t\t\tstamp.localSeq !== undefined && stamp.localSeq <= this.localSeq;\n\t\treturn predatesViaRefSeq || predatesViaLocalSeq;\n\t}\n}\n\n/**\n * A perspective which includes all known edits.\n *\n * This is the perspective that the application sees.\n * @remarks\n * This can be represented using {@link PriorPerspective} with a refSeq of `Number.MAX_SAFE_INTEGER`, but having an explicit\n * variant of this perspective renders extra refSeq checks unnecessary and is a bit easier to read.\n */\nexport class LocalDefaultPerspective extends PerspectiveBase implements Perspective {\n\tpublic readonly refSeq = Number.MAX_SAFE_INTEGER;\n\n\tpublic constructor(public readonly clientId: number) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(_stamp: OperationStamp): boolean {\n\t\treturn true;\n\t}\n}\n\n/**\n * A perspective dictating whether segments are 'visible' to a remote obliterate operation.\n *\n * NOTE: Beware that partial lengths doesn't support this perspective, in the sense that consulting partial lengths' for the length of a block\n * can give different results than summing the lengths of present segments in that block.\n * This ends up not affecting the current obliterate implementation (which has some special casing in the mapRange calls it uses),\n * but use with caution.\n */\nexport class RemoteObliteratePerspective extends PerspectiveBase implements Perspective {\n\tpublic readonly refSeq = Number.MAX_SAFE_INTEGER;\n\n\tconstructor(public readonly clientId: number) {\n\t\tsuper();\n\t}\n\n\tpublic hasOccurred(stamp: OperationStamp): boolean {\n\t\t// Local-only removals are not visible to an obliterate operation, since this means the local removal was concurrent\n\t\t// to a remote obliterate and we may need to mark the segment appropriately to reflect this overlapping remove.\n\t\t// Every other type of operation is visible: obliterates do not affect segments that have already been removed and acked,\n\t\t// and they always affect segments within their range that have not been removed, even if those segments were inserted\n\t\t// after the obliterate's refSeq.\n\t\tif (isRemoveOperationStamp(stamp) && opstampUtils.isLocal(stamp)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn true;\n\t}\n}\n\nfunction isRemoveOperationStamp(stamp: OperationStamp): stamp is RemoveOperationStamp {\n\tconst { type } = stamp as unknown as RemoveOperationStamp;\n\treturn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9C,WAAW,EAAE,wBAAwB,EAAE,GACrC,IAAI,CAWN;AAgJD;;;;;GAKG;AACH,wBAAgB,+BAA+B,CAC9C,MAAM,EAAE,yBAAyB,EACjC,WAAW,EAAE,wBAAwB,EAAE,GACrC,IAAI,CA4BN"}
@@ -180,7 +180,7 @@ function revertLocalRemove(driver, mergeTreeWithRevert, revertible) {
180
180
  }
181
181
  const props = tracked.properties;
182
182
  driver.insertFromSpec(realPos, props.segSpec);
183
- const insertSegment = mergeTreeWithRevert.getContainingSegment(realPos, mergeTreeWithRevert.collabWindow.currentSeq, mergeTreeWithRevert.collabWindow.clientId).segment;
183
+ const insertSegment = mergeTreeWithRevert.getContainingSegment(realPos, mergeTreeWithRevert.localPerspective).segment;
184
184
  assertSegmentLeaf(insertSegment);
185
185
  const localSlideFilter = (lref) => lref.properties?.referenceSpace ===
186
186
  "mergeTreeDeltaRevertible";
@@ -242,7 +242,7 @@ function revertLocalAnnotate(driver, mergeTreeWithRevert, revertible) {
242
242
  }
243
243
  }
244
244
  function getPosition(mergeTreeWithRevert, segment) {
245
- return mergeTreeWithRevert.getPosition(segment, mergeTreeWithRevert.collabWindow.currentSeq, mergeTreeWithRevert.collabWindow.clientId);
245
+ return mergeTreeWithRevert.getPosition(segment, mergeTreeWithRevert.localPerspective);
246
246
  }
247
247
  /**
248
248
  * Reverts all operations in the list of revertibles.
@@ -1 +1 @@
1
- {"version":3,"file":"revertibles.js","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAA0B,MAAM,qBAAqB,CAAC;AACvF,OAAO,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AAC,QAAQ,CAAC,CAAC,CAAC;oBAClC,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC;oBACpD,MAAM;gBACP,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACT,eAAe,CAAC,SAAS,CAAC,CAAC;gBAC5B,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { DoublyLinkedList } from \"./collections/index.js\";\nimport { EndOfTreeSegment } from \"./endOfTreeSegment.js\";\nimport { LocalReferenceCollection, LocalReferencePosition } from \"./localReference.js\";\nimport { MergeTree, findRootMergeBlock } from \"./mergeTree.js\";\nimport { IMergeTreeDeltaCallbackArgs } from \"./mergeTreeDeltaCallback.js\";\nimport { depthFirstNodeWalk } from \"./mergeTreeNodeWalk.js\";\nimport {\n\tassertSegmentLeaf,\n\tisSegmentLeaf,\n\ttoSegmentLeaf,\n\ttype ISegmentLeaf,\n\ttype ISegmentPrivate,\n} from \"./mergeTreeNodes.js\";\nimport { ITrackingGroup, Trackable, UnorderedTrackingGroup } from \"./mergeTreeTracking.js\";\nimport { IJSONSegment, MergeTreeDeltaType, ReferenceType } from \"./ops.js\";\nimport { PropertySet, matchProperties } from \"./properties.js\";\nimport { DetachedReferencePosition } from \"./referencePositions.js\";\nimport { toRemovalInfo } from \"./segmentInfos.js\";\n\n/**\n * @legacy\n * @alpha\n */\nexport type MergeTreeDeltaRevertible =\n\t| {\n\t\t\toperation: typeof MergeTreeDeltaType.INSERT;\n\t\t\ttrackingGroup: ITrackingGroup;\n\t }\n\t| {\n\t\t\toperation: typeof MergeTreeDeltaType.REMOVE;\n\t\t\ttrackingGroup: ITrackingGroup;\n\t }\n\t| {\n\t\t\toperation: typeof MergeTreeDeltaType.ANNOTATE;\n\t\t\ttrackingGroup: ITrackingGroup;\n\t\t\tpropertyDeltas: PropertySet;\n\t };\n\n/**\n * Tests whether x is a MergeTreeDeltaRevertible\n * @internal\n */\nexport function isMergeTreeDeltaRevertible(x: unknown): x is MergeTreeDeltaRevertible {\n\treturn !!x && typeof x === \"object\" && \"operation\" in x && \"trackingGroup\" in x;\n}\n\ntype TypedRevertible<T extends MergeTreeDeltaRevertible[\"operation\"]> =\n\tMergeTreeDeltaRevertible & {\n\t\toperation: T;\n\t};\n\ninterface RemoveSegmentRefProperties {\n\t/**\n\t * the serialized form of the segment, so it can be re-inserted\n\t */\n\tsegSpec: IJSONSegment;\n\t/**\n\t * a tag so the reference can be identified as being created for revert\n\t */\n\treferenceSpace: \"mergeTreeDeltaRevertible\";\n}\n\n/**\n * @legacy\n * @alpha\n */\nexport interface MergeTreeRevertibleDriver {\n\tinsertFromSpec(pos: number, spec: IJSONSegment): void;\n\tremoveRange(start: number, end: number): void;\n\tannotateRange(start: number, end: number, props: PropertySet): void;\n}\n\n/**\n * exported for test only. should not be exported out the the package\n * @internal\n */\nexport interface MergeTreeWithRevert extends MergeTree {\n\t__mergeTreeRevertible: {\n\t\tdetachedReferences: EndOfTreeSegment;\n\t\trefCallbacks: LocalReferencePosition[\"callbacks\"];\n\t};\n}\n\nexport type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\nfunction findMergeTreeWithRevert(trackable: Trackable): MergeTreeWithRevert {\n\tconst segmentOrNode = trackable.isLeaf() ? trackable : trackable.getSegment();\n\tconst maybeRoot = findRootMergeBlock(toSegmentLeaf(segmentOrNode));\n\tassert(\n\t\tmaybeRoot?.mergeTree !== undefined,\n\t\t0x5c2 /* trackable is invalid as it is not in a rooted merge tree. */,\n\t);\n\tconst mergeTree: PickPartial<MergeTreeWithRevert, \"__mergeTreeRevertible\"> =\n\t\tmaybeRoot.mergeTree;\n\n\tif (mergeTree.__mergeTreeRevertible === undefined) {\n\t\tconst detachedReferences = new EndOfTreeSegment(maybeRoot.mergeTree);\n\t\tconst refCallbacks: MergeTreeWithRevert[\"__mergeTreeRevertible\"][\"refCallbacks\"] = {\n\t\t\tafterSlide: (r: LocalReferencePosition) => {\n\t\t\t\tif (mergeTree.referencePositionToLocalPosition(r) === DetachedReferencePosition) {\n\t\t\t\t\tconst refs = LocalReferenceCollection.setOrGet(detachedReferences);\n\t\t\t\t\trefs.addAfterTombstones([r]);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tmergeTree.__mergeTreeRevertible = {\n\t\t\trefCallbacks,\n\t\t\tdetachedReferences,\n\t\t};\n\t}\n\treturn mergeTree as MergeTreeWithRevert;\n}\n\nfunction appendLocalInsertToRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): MergeTreeDeltaRevertible[] {\n\tif (revertibles[revertibles.length - 1]?.operation !== MergeTreeDeltaType.INSERT) {\n\t\trevertibles.push({\n\t\t\toperation: MergeTreeDeltaType.INSERT,\n\t\t\ttrackingGroup: new UnorderedTrackingGroup(),\n\t\t});\n\t}\n\tconst last = revertibles[revertibles.length - 1];\n\tfor (const t of deltaArgs.deltaSegments) last.trackingGroup.link(t.segment);\n\n\treturn revertibles;\n}\n\nfunction appendLocalRemoveToRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): MergeTreeDeltaRevertible[] {\n\tif (revertibles[revertibles.length - 1]?.operation !== MergeTreeDeltaType.REMOVE) {\n\t\trevertibles.push({\n\t\t\toperation: MergeTreeDeltaType.REMOVE,\n\t\t\ttrackingGroup: new UnorderedTrackingGroup(),\n\t\t});\n\t}\n\tconst last = revertibles[revertibles.length - 1];\n\n\tconst mergeTreeWithRevert = findMergeTreeWithRevert(deltaArgs.deltaSegments[0].segment);\n\n\tfor (const t of deltaArgs.deltaSegments) {\n\t\tconst props: RemoveSegmentRefProperties = {\n\t\t\tsegSpec: t.segment.toJSONObject() as IJSONSegment,\n\t\t\treferenceSpace: \"mergeTreeDeltaRevertible\",\n\t\t};\n\t\tconst ref = mergeTreeWithRevert.createLocalReferencePosition(\n\t\t\tt.segment,\n\t\t\t0,\n\t\t\tReferenceType.SlideOnRemove,\n\t\t\tprops,\n\t\t);\n\t\tref.callbacks = mergeTreeWithRevert.__mergeTreeRevertible.refCallbacks;\n\t\tfor (const tg of t.segment.trackingCollection.trackingGroups) {\n\t\t\ttg.link(ref);\n\t\t\ttg.unlink(t.segment);\n\t\t}\n\n\t\tlast.trackingGroup.link(ref);\n\t}\n\treturn revertibles;\n}\n\nfunction appendLocalAnnotateToRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): MergeTreeDeltaRevertible[] {\n\tlet last = revertibles[revertibles.length - 1];\n\tfor (const ds of deltaArgs.deltaSegments) {\n\t\tconst propertyDeltas = ds.propertyDeltas;\n\t\tif (propertyDeltas) {\n\t\t\tif (\n\t\t\t\tlast?.operation === MergeTreeDeltaType.ANNOTATE &&\n\t\t\t\tmatchProperties(last?.propertyDeltas, propertyDeltas)\n\t\t\t) {\n\t\t\t\tlast.trackingGroup.link(ds.segment);\n\t\t\t} else {\n\t\t\t\tlast = {\n\t\t\t\t\toperation: MergeTreeDeltaType.ANNOTATE,\n\t\t\t\t\tpropertyDeltas,\n\t\t\t\t\ttrackingGroup: new UnorderedTrackingGroup(),\n\t\t\t\t};\n\t\t\t\tlast.trackingGroup.link(ds.segment);\n\t\t\t\trevertibles.push(last);\n\t\t\t}\n\t\t}\n\t}\n\treturn revertibles;\n}\n\n/**\n * Appends a merge tree delta to the list of revertibles.\n *\n * @legacy\n * @alpha\n */\nexport function appendToMergeTreeDeltaRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): void {\n\tif (deltaArgs.deltaSegments.length === 0) {\n\t\treturn;\n\t}\n\tswitch (deltaArgs.operation) {\n\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\tappendLocalInsertToRevertibles(deltaArgs, revertibles);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\tappendLocalRemoveToRevertibles(deltaArgs, revertibles);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\tappendLocalAnnotateToRevertibles(deltaArgs, revertibles);\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported event delta type\", {\n\t\t\t\toperation: deltaArgs.operation,\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Removes all revertibles from the list of revertibles.\n *\n * @legacy\n * @alpha\n */\nexport function discardMergeTreeDeltaRevertible(\n\trevertibles: MergeTreeDeltaRevertible[],\n): void {\n\tfor (const r of revertibles) {\n\t\tfor (const t of r.trackingGroup.tracked) {\n\t\t\tt.trackingCollection.unlink(r.trackingGroup);\n\t\t\t// remove untracked local references\n\t\t\tif (t.trackingCollection.empty && !t.isLeaf()) {\n\t\t\t\tconst segment: ISegmentPrivate | undefined = t.getSegment();\n\t\t\t\tsegment?.localRefs?.removeLocalRef(t);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction revertLocalInsert(\n\tdriver: MergeTreeRevertibleDriver,\n\tmergeTreeWithRevert: MergeTreeWithRevert,\n\trevertible: TypedRevertible<typeof MergeTreeDeltaType.INSERT>,\n): void {\n\twhile (revertible.trackingGroup.size > 0) {\n\t\tconst tracked = revertible.trackingGroup.tracked[0];\n\t\tassert(\n\t\t\ttracked.trackingCollection.unlink(revertible.trackingGroup),\n\t\t\t0x3f1 /* tracking group removed */,\n\t\t);\n\t\tassert(isSegmentLeaf(tracked), 0x3f2 /* inserts must track segments */);\n\t\tif (toRemovalInfo(tracked) === undefined) {\n\t\t\tconst start = getPosition(mergeTreeWithRevert, tracked);\n\t\t\tdriver.removeRange(start, start + tracked.cachedLength);\n\t\t}\n\t}\n}\n\nfunction revertLocalRemove(\n\tdriver: MergeTreeRevertibleDriver,\n\tmergeTreeWithRevert: MergeTreeWithRevert,\n\trevertible: TypedRevertible<typeof MergeTreeDeltaType.REMOVE>,\n): void {\n\twhile (revertible.trackingGroup.size > 0) {\n\t\tconst tracked = revertible.trackingGroup.tracked[0];\n\n\t\tassert(\n\t\t\ttracked.trackingCollection.unlink(revertible.trackingGroup),\n\t\t\t0x3f3 /* tracking group removed */,\n\t\t);\n\n\t\tassert(!tracked.isLeaf(), 0x3f4 /* removes must track local refs */);\n\n\t\tconst refSeg = tracked.getSegment();\n\t\tlet realPos = mergeTreeWithRevert.referencePositionToLocalPosition(tracked);\n\n\t\t// References which are on EndOfStringSegment don't return detached for pos,\n\t\t// they will return the length of the merge-tree. this case just catches\n\t\t// random references, likely not created in the revertible flow,\n\t\t// that are tying to be reverted for some reason.\n\t\tif (realPos === DetachedReferencePosition || !isSegmentLeaf(refSeg)) {\n\t\t\tthrow new UsageError(\"Cannot insert at detached references position\");\n\t\t}\n\n\t\tif (toRemovalInfo(refSeg) === undefined && refSeg.localRefs?.isAfterTombstone(tracked)) {\n\t\t\trealPos++;\n\t\t}\n\n\t\tconst props = tracked.properties as RemoveSegmentRefProperties;\n\t\tdriver.insertFromSpec(realPos, props.segSpec);\n\t\tconst insertSegment = mergeTreeWithRevert.getContainingSegment(\n\t\t\trealPos,\n\t\t\tmergeTreeWithRevert.collabWindow.currentSeq,\n\t\t\tmergeTreeWithRevert.collabWindow.clientId,\n\t\t).segment;\n\t\tassertSegmentLeaf(insertSegment);\n\n\t\tconst localSlideFilter = (lref: LocalReferencePosition): boolean =>\n\t\t\t(lref.properties as Partial<RemoveSegmentRefProperties>)?.referenceSpace ===\n\t\t\t\"mergeTreeDeltaRevertible\";\n\n\t\tconst insertRef: Partial<\n\t\t\tRecord<\"before\" | \"after\", DoublyLinkedList<LocalReferencePosition>>\n\t\t> = {};\n\t\tconst forward = insertSegment.ordinal < refSeg.ordinal;\n\t\tconst refHandler = (lref: LocalReferencePosition): false | undefined => {\n\t\t\t// once we reach it keep the original reference where it is\n\t\t\t// we'll move tracking groups, and remove it as a last step.\n\t\t\tif (tracked === lref) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (localSlideFilter(lref)) {\n\t\t\t\tif (forward) {\n\t\t\t\t\tconst before = (insertRef.before ??= new DoublyLinkedList());\n\t\t\t\t\tbefore.push(lref);\n\t\t\t\t} else {\n\t\t\t\t\tconst after = (insertRef.after ??= new DoublyLinkedList());\n\t\t\t\t\tafter.unshift(lref);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tdepthFirstNodeWalk(\n\t\t\tinsertSegment.parent,\n\t\t\tinsertSegment,\n\t\t\tundefined,\n\t\t\t(seg: ISegmentPrivate) => {\n\t\t\t\tif (seg.localRefs?.empty === false) {\n\t\t\t\t\treturn seg.localRefs.walkReferences(refHandler, undefined, forward);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tundefined,\n\t\t\tforward,\n\t\t);\n\t\tif (\n\t\t\tmergeTreeWithRevert?.__mergeTreeRevertible?.detachedReferences?.localRefs?.has(tracked)\n\t\t) {\n\t\t\tassert(forward, 0x3f6 /* forward should always be true when detached */);\n\t\t\tmergeTreeWithRevert?.__mergeTreeRevertible.detachedReferences.localRefs.walkReferences(\n\t\t\t\trefHandler,\n\t\t\t);\n\t\t}\n\n\t\tif (insertRef !== undefined) {\n\t\t\tconst localRefs = LocalReferenceCollection.setOrGet(insertSegment);\n\t\t\tif (insertRef.before?.empty === false) {\n\t\t\t\tlocalRefs.addBeforeTombstones(insertRef.before.map((n) => n.data));\n\t\t\t}\n\t\t\tif (insertRef.after?.empty === false) {\n\t\t\t\tlocalRefs.addAfterTombstones(insertRef.after.map((n) => n.data));\n\t\t\t}\n\t\t}\n\n\t\tfor (const tg of tracked.trackingCollection.trackingGroups) {\n\t\t\ttg.link(insertSegment);\n\t\t\ttg.unlink(tracked);\n\t\t}\n\t\tconst segment: ISegmentPrivate | undefined = tracked.getSegment();\n\t\tsegment?.localRefs?.removeLocalRef(tracked);\n\t}\n}\n\nfunction revertLocalAnnotate(\n\tdriver: MergeTreeRevertibleDriver,\n\tmergeTreeWithRevert: MergeTreeWithRevert,\n\trevertible: TypedRevertible<typeof MergeTreeDeltaType.ANNOTATE>,\n): void {\n\twhile (revertible.trackingGroup.size > 0) {\n\t\tconst tracked = revertible.trackingGroup.tracked[0];\n\t\tconst unlinked = tracked.trackingCollection.unlink(revertible.trackingGroup);\n\t\tassert(unlinked && isSegmentLeaf(tracked), 0x3f7 /* annotates must track segments */);\n\t\tif (toRemovalInfo(tracked) === undefined) {\n\t\t\tconst start = getPosition(mergeTreeWithRevert, tracked);\n\t\t\tdriver.annotateRange(start, start + tracked.cachedLength, revertible.propertyDeltas);\n\t\t}\n\t}\n}\n\nfunction getPosition(mergeTreeWithRevert: MergeTreeWithRevert, segment: ISegmentLeaf): number {\n\treturn mergeTreeWithRevert.getPosition(\n\t\tsegment,\n\t\tmergeTreeWithRevert.collabWindow.currentSeq,\n\t\tmergeTreeWithRevert.collabWindow.clientId,\n\t);\n}\n\n/**\n * Reverts all operations in the list of revertibles.\n *\n * @legacy\n * @alpha\n */\nexport function revertMergeTreeDeltaRevertibles(\n\tdriver: MergeTreeRevertibleDriver,\n\trevertibles: MergeTreeDeltaRevertible[],\n): void {\n\tlet mergeTreeWithRevert: MergeTreeWithRevert | undefined;\n\n\twhile (revertibles.length > 0) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst r = revertibles.pop()!;\n\t\tconst operation = r.operation;\n\t\tif (r.trackingGroup.size > 0) {\n\t\t\tmergeTreeWithRevert ??= findMergeTreeWithRevert(r.trackingGroup.tracked[0]);\n\t\t\tswitch (operation) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t\trevertLocalInsert(driver, mergeTreeWithRevert, r);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\trevertLocalRemove(driver, mergeTreeWithRevert, r);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\trevertLocalAnnotate(driver, mergeTreeWithRevert, r);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(operation);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"revertibles.js","sourceRoot":"","sources":["../src/revertibles.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAC9E,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,wBAAwB,EAA0B,MAAM,qBAAqB,CAAC;AACvF,OAAO,EAAa,kBAAkB,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACN,iBAAiB,EACjB,aAAa,EACb,aAAa,GAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAA6B,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AAC3F,OAAO,EAAgB,kBAAkB,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC3E,OAAO,EAAe,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,yBAAyB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAqBlD;;;GAGG;AACH,MAAM,UAAU,0BAA0B,CAAC,CAAU;IAC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,CAAC;QAC/B,oEAAoE;QACpE,MAAM,CAAC,GAAG,WAAW,CAAC,GAAG,EAAG,CAAC;QAC7B,MAAM,SAAS,GAAG,CAAC,CAAC,SAAS,CAAC;QAC9B,IAAI,CAAC,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAC9B,mBAAmB,KAAK,uBAAuB,CAAC,CAAC,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;YAC5E,QAAQ,SAAS,EAAE,CAAC;gBACnB,KAAK,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;oBAChC,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC;oBAClD,MAAM;gBACP,CAAC;gBACD,KAAK,kBAAkB,CAAC,MAAM,CAAC,CAAC,CAAC;oBAChC,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC;oBAClD,MAAM;gBACP,CAAC;gBACD,KAAK,kBAAkB,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAClC,mBAAmB,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,CAAC,CAAC;oBACpD,MAAM;gBACP,CAAC;gBACD,OAAO,CAAC,CAAC,CAAC;oBACT,eAAe,CAAC,SAAS,CAAC,CAAC;gBAC5B,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { DoublyLinkedList } from \"./collections/index.js\";\nimport { EndOfTreeSegment } from \"./endOfTreeSegment.js\";\nimport { LocalReferenceCollection, LocalReferencePosition } from \"./localReference.js\";\nimport { MergeTree, findRootMergeBlock } from \"./mergeTree.js\";\nimport { IMergeTreeDeltaCallbackArgs } from \"./mergeTreeDeltaCallback.js\";\nimport { depthFirstNodeWalk } from \"./mergeTreeNodeWalk.js\";\nimport {\n\tassertSegmentLeaf,\n\tisSegmentLeaf,\n\ttoSegmentLeaf,\n\ttype ISegmentLeaf,\n\ttype ISegmentPrivate,\n} from \"./mergeTreeNodes.js\";\nimport { ITrackingGroup, Trackable, UnorderedTrackingGroup } from \"./mergeTreeTracking.js\";\nimport { IJSONSegment, MergeTreeDeltaType, ReferenceType } from \"./ops.js\";\nimport { PropertySet, matchProperties } from \"./properties.js\";\nimport { DetachedReferencePosition } from \"./referencePositions.js\";\nimport { toRemovalInfo } from \"./segmentInfos.js\";\n\n/**\n * @legacy\n * @alpha\n */\nexport type MergeTreeDeltaRevertible =\n\t| {\n\t\t\toperation: typeof MergeTreeDeltaType.INSERT;\n\t\t\ttrackingGroup: ITrackingGroup;\n\t }\n\t| {\n\t\t\toperation: typeof MergeTreeDeltaType.REMOVE;\n\t\t\ttrackingGroup: ITrackingGroup;\n\t }\n\t| {\n\t\t\toperation: typeof MergeTreeDeltaType.ANNOTATE;\n\t\t\ttrackingGroup: ITrackingGroup;\n\t\t\tpropertyDeltas: PropertySet;\n\t };\n\n/**\n * Tests whether x is a MergeTreeDeltaRevertible\n * @internal\n */\nexport function isMergeTreeDeltaRevertible(x: unknown): x is MergeTreeDeltaRevertible {\n\treturn !!x && typeof x === \"object\" && \"operation\" in x && \"trackingGroup\" in x;\n}\n\ntype TypedRevertible<T extends MergeTreeDeltaRevertible[\"operation\"]> =\n\tMergeTreeDeltaRevertible & {\n\t\toperation: T;\n\t};\n\ninterface RemoveSegmentRefProperties {\n\t/**\n\t * the serialized form of the segment, so it can be re-inserted\n\t */\n\tsegSpec: IJSONSegment;\n\t/**\n\t * a tag so the reference can be identified as being created for revert\n\t */\n\treferenceSpace: \"mergeTreeDeltaRevertible\";\n}\n\n/**\n * @legacy\n * @alpha\n */\nexport interface MergeTreeRevertibleDriver {\n\tinsertFromSpec(pos: number, spec: IJSONSegment): void;\n\tremoveRange(start: number, end: number): void;\n\tannotateRange(start: number, end: number, props: PropertySet): void;\n}\n\n/**\n * exported for test only. should not be exported out the the package\n * @internal\n */\nexport interface MergeTreeWithRevert extends MergeTree {\n\t__mergeTreeRevertible: {\n\t\tdetachedReferences: EndOfTreeSegment;\n\t\trefCallbacks: LocalReferencePosition[\"callbacks\"];\n\t};\n}\n\nexport type PickPartial<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>;\nfunction findMergeTreeWithRevert(trackable: Trackable): MergeTreeWithRevert {\n\tconst segmentOrNode = trackable.isLeaf() ? trackable : trackable.getSegment();\n\tconst maybeRoot = findRootMergeBlock(toSegmentLeaf(segmentOrNode));\n\tassert(\n\t\tmaybeRoot?.mergeTree !== undefined,\n\t\t0x5c2 /* trackable is invalid as it is not in a rooted merge tree. */,\n\t);\n\tconst mergeTree: PickPartial<MergeTreeWithRevert, \"__mergeTreeRevertible\"> =\n\t\tmaybeRoot.mergeTree;\n\n\tif (mergeTree.__mergeTreeRevertible === undefined) {\n\t\tconst detachedReferences = new EndOfTreeSegment(maybeRoot.mergeTree);\n\t\tconst refCallbacks: MergeTreeWithRevert[\"__mergeTreeRevertible\"][\"refCallbacks\"] = {\n\t\t\tafterSlide: (r: LocalReferencePosition) => {\n\t\t\t\tif (mergeTree.referencePositionToLocalPosition(r) === DetachedReferencePosition) {\n\t\t\t\t\tconst refs = LocalReferenceCollection.setOrGet(detachedReferences);\n\t\t\t\t\trefs.addAfterTombstones([r]);\n\t\t\t\t}\n\t\t\t},\n\t\t};\n\t\tmergeTree.__mergeTreeRevertible = {\n\t\t\trefCallbacks,\n\t\t\tdetachedReferences,\n\t\t};\n\t}\n\treturn mergeTree as MergeTreeWithRevert;\n}\n\nfunction appendLocalInsertToRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): MergeTreeDeltaRevertible[] {\n\tif (revertibles[revertibles.length - 1]?.operation !== MergeTreeDeltaType.INSERT) {\n\t\trevertibles.push({\n\t\t\toperation: MergeTreeDeltaType.INSERT,\n\t\t\ttrackingGroup: new UnorderedTrackingGroup(),\n\t\t});\n\t}\n\tconst last = revertibles[revertibles.length - 1];\n\tfor (const t of deltaArgs.deltaSegments) last.trackingGroup.link(t.segment);\n\n\treturn revertibles;\n}\n\nfunction appendLocalRemoveToRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): MergeTreeDeltaRevertible[] {\n\tif (revertibles[revertibles.length - 1]?.operation !== MergeTreeDeltaType.REMOVE) {\n\t\trevertibles.push({\n\t\t\toperation: MergeTreeDeltaType.REMOVE,\n\t\t\ttrackingGroup: new UnorderedTrackingGroup(),\n\t\t});\n\t}\n\tconst last = revertibles[revertibles.length - 1];\n\n\tconst mergeTreeWithRevert = findMergeTreeWithRevert(deltaArgs.deltaSegments[0].segment);\n\n\tfor (const t of deltaArgs.deltaSegments) {\n\t\tconst props: RemoveSegmentRefProperties = {\n\t\t\tsegSpec: t.segment.toJSONObject() as IJSONSegment,\n\t\t\treferenceSpace: \"mergeTreeDeltaRevertible\",\n\t\t};\n\t\tconst ref = mergeTreeWithRevert.createLocalReferencePosition(\n\t\t\tt.segment,\n\t\t\t0,\n\t\t\tReferenceType.SlideOnRemove,\n\t\t\tprops,\n\t\t);\n\t\tref.callbacks = mergeTreeWithRevert.__mergeTreeRevertible.refCallbacks;\n\t\tfor (const tg of t.segment.trackingCollection.trackingGroups) {\n\t\t\ttg.link(ref);\n\t\t\ttg.unlink(t.segment);\n\t\t}\n\n\t\tlast.trackingGroup.link(ref);\n\t}\n\treturn revertibles;\n}\n\nfunction appendLocalAnnotateToRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): MergeTreeDeltaRevertible[] {\n\tlet last = revertibles[revertibles.length - 1];\n\tfor (const ds of deltaArgs.deltaSegments) {\n\t\tconst propertyDeltas = ds.propertyDeltas;\n\t\tif (propertyDeltas) {\n\t\t\tif (\n\t\t\t\tlast?.operation === MergeTreeDeltaType.ANNOTATE &&\n\t\t\t\tmatchProperties(last?.propertyDeltas, propertyDeltas)\n\t\t\t) {\n\t\t\t\tlast.trackingGroup.link(ds.segment);\n\t\t\t} else {\n\t\t\t\tlast = {\n\t\t\t\t\toperation: MergeTreeDeltaType.ANNOTATE,\n\t\t\t\t\tpropertyDeltas,\n\t\t\t\t\ttrackingGroup: new UnorderedTrackingGroup(),\n\t\t\t\t};\n\t\t\t\tlast.trackingGroup.link(ds.segment);\n\t\t\t\trevertibles.push(last);\n\t\t\t}\n\t\t}\n\t}\n\treturn revertibles;\n}\n\n/**\n * Appends a merge tree delta to the list of revertibles.\n *\n * @legacy\n * @alpha\n */\nexport function appendToMergeTreeDeltaRevertibles(\n\tdeltaArgs: IMergeTreeDeltaCallbackArgs,\n\trevertibles: MergeTreeDeltaRevertible[],\n): void {\n\tif (deltaArgs.deltaSegments.length === 0) {\n\t\treturn;\n\t}\n\tswitch (deltaArgs.operation) {\n\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\tappendLocalInsertToRevertibles(deltaArgs, revertibles);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\tappendLocalRemoveToRevertibles(deltaArgs, revertibles);\n\t\t\tbreak;\n\t\t}\n\n\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\tappendLocalAnnotateToRevertibles(deltaArgs, revertibles);\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault: {\n\t\t\tthrow new UsageError(\"Unsupported event delta type\", {\n\t\t\t\toperation: deltaArgs.operation,\n\t\t\t});\n\t\t}\n\t}\n}\n\n/**\n * Removes all revertibles from the list of revertibles.\n *\n * @legacy\n * @alpha\n */\nexport function discardMergeTreeDeltaRevertible(\n\trevertibles: MergeTreeDeltaRevertible[],\n): void {\n\tfor (const r of revertibles) {\n\t\tfor (const t of r.trackingGroup.tracked) {\n\t\t\tt.trackingCollection.unlink(r.trackingGroup);\n\t\t\t// remove untracked local references\n\t\t\tif (t.trackingCollection.empty && !t.isLeaf()) {\n\t\t\t\tconst segment: ISegmentPrivate | undefined = t.getSegment();\n\t\t\t\tsegment?.localRefs?.removeLocalRef(t);\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction revertLocalInsert(\n\tdriver: MergeTreeRevertibleDriver,\n\tmergeTreeWithRevert: MergeTreeWithRevert,\n\trevertible: TypedRevertible<typeof MergeTreeDeltaType.INSERT>,\n): void {\n\twhile (revertible.trackingGroup.size > 0) {\n\t\tconst tracked = revertible.trackingGroup.tracked[0];\n\t\tassert(\n\t\t\ttracked.trackingCollection.unlink(revertible.trackingGroup),\n\t\t\t0x3f1 /* tracking group removed */,\n\t\t);\n\t\tassert(isSegmentLeaf(tracked), 0x3f2 /* inserts must track segments */);\n\t\tif (toRemovalInfo(tracked) === undefined) {\n\t\t\tconst start = getPosition(mergeTreeWithRevert, tracked);\n\t\t\tdriver.removeRange(start, start + tracked.cachedLength);\n\t\t}\n\t}\n}\n\nfunction revertLocalRemove(\n\tdriver: MergeTreeRevertibleDriver,\n\tmergeTreeWithRevert: MergeTreeWithRevert,\n\trevertible: TypedRevertible<typeof MergeTreeDeltaType.REMOVE>,\n): void {\n\twhile (revertible.trackingGroup.size > 0) {\n\t\tconst tracked = revertible.trackingGroup.tracked[0];\n\n\t\tassert(\n\t\t\ttracked.trackingCollection.unlink(revertible.trackingGroup),\n\t\t\t0x3f3 /* tracking group removed */,\n\t\t);\n\n\t\tassert(!tracked.isLeaf(), 0x3f4 /* removes must track local refs */);\n\n\t\tconst refSeg = tracked.getSegment();\n\t\tlet realPos = mergeTreeWithRevert.referencePositionToLocalPosition(tracked);\n\n\t\t// References which are on EndOfStringSegment don't return detached for pos,\n\t\t// they will return the length of the merge-tree. this case just catches\n\t\t// random references, likely not created in the revertible flow,\n\t\t// that are tying to be reverted for some reason.\n\t\tif (realPos === DetachedReferencePosition || !isSegmentLeaf(refSeg)) {\n\t\t\tthrow new UsageError(\"Cannot insert at detached references position\");\n\t\t}\n\n\t\tif (toRemovalInfo(refSeg) === undefined && refSeg.localRefs?.isAfterTombstone(tracked)) {\n\t\t\trealPos++;\n\t\t}\n\n\t\tconst props = tracked.properties as RemoveSegmentRefProperties;\n\t\tdriver.insertFromSpec(realPos, props.segSpec);\n\t\tconst insertSegment = mergeTreeWithRevert.getContainingSegment(\n\t\t\trealPos,\n\t\t\tmergeTreeWithRevert.localPerspective,\n\t\t).segment;\n\t\tassertSegmentLeaf(insertSegment);\n\n\t\tconst localSlideFilter = (lref: LocalReferencePosition): boolean =>\n\t\t\t(lref.properties as Partial<RemoveSegmentRefProperties>)?.referenceSpace ===\n\t\t\t\"mergeTreeDeltaRevertible\";\n\n\t\tconst insertRef: Partial<\n\t\t\tRecord<\"before\" | \"after\", DoublyLinkedList<LocalReferencePosition>>\n\t\t> = {};\n\t\tconst forward = insertSegment.ordinal < refSeg.ordinal;\n\t\tconst refHandler = (lref: LocalReferencePosition): false | undefined => {\n\t\t\t// once we reach it keep the original reference where it is\n\t\t\t// we'll move tracking groups, and remove it as a last step.\n\t\t\tif (tracked === lref) {\n\t\t\t\treturn false;\n\t\t\t}\n\t\t\tif (localSlideFilter(lref)) {\n\t\t\t\tif (forward) {\n\t\t\t\t\tconst before = (insertRef.before ??= new DoublyLinkedList());\n\t\t\t\t\tbefore.push(lref);\n\t\t\t\t} else {\n\t\t\t\t\tconst after = (insertRef.after ??= new DoublyLinkedList());\n\t\t\t\t\tafter.unshift(lref);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tdepthFirstNodeWalk(\n\t\t\tinsertSegment.parent,\n\t\t\tinsertSegment,\n\t\t\tundefined,\n\t\t\t(seg: ISegmentPrivate) => {\n\t\t\t\tif (seg.localRefs?.empty === false) {\n\t\t\t\t\treturn seg.localRefs.walkReferences(refHandler, undefined, forward);\n\t\t\t\t}\n\t\t\t\treturn true;\n\t\t\t},\n\t\t\tundefined,\n\t\t\tforward,\n\t\t);\n\t\tif (\n\t\t\tmergeTreeWithRevert?.__mergeTreeRevertible?.detachedReferences?.localRefs?.has(tracked)\n\t\t) {\n\t\t\tassert(forward, 0x3f6 /* forward should always be true when detached */);\n\t\t\tmergeTreeWithRevert?.__mergeTreeRevertible.detachedReferences.localRefs.walkReferences(\n\t\t\t\trefHandler,\n\t\t\t);\n\t\t}\n\n\t\tif (insertRef !== undefined) {\n\t\t\tconst localRefs = LocalReferenceCollection.setOrGet(insertSegment);\n\t\t\tif (insertRef.before?.empty === false) {\n\t\t\t\tlocalRefs.addBeforeTombstones(insertRef.before.map((n) => n.data));\n\t\t\t}\n\t\t\tif (insertRef.after?.empty === false) {\n\t\t\t\tlocalRefs.addAfterTombstones(insertRef.after.map((n) => n.data));\n\t\t\t}\n\t\t}\n\n\t\tfor (const tg of tracked.trackingCollection.trackingGroups) {\n\t\t\ttg.link(insertSegment);\n\t\t\ttg.unlink(tracked);\n\t\t}\n\t\tconst segment: ISegmentPrivate | undefined = tracked.getSegment();\n\t\tsegment?.localRefs?.removeLocalRef(tracked);\n\t}\n}\n\nfunction revertLocalAnnotate(\n\tdriver: MergeTreeRevertibleDriver,\n\tmergeTreeWithRevert: MergeTreeWithRevert,\n\trevertible: TypedRevertible<typeof MergeTreeDeltaType.ANNOTATE>,\n): void {\n\twhile (revertible.trackingGroup.size > 0) {\n\t\tconst tracked = revertible.trackingGroup.tracked[0];\n\t\tconst unlinked = tracked.trackingCollection.unlink(revertible.trackingGroup);\n\t\tassert(unlinked && isSegmentLeaf(tracked), 0x3f7 /* annotates must track segments */);\n\t\tif (toRemovalInfo(tracked) === undefined) {\n\t\t\tconst start = getPosition(mergeTreeWithRevert, tracked);\n\t\t\tdriver.annotateRange(start, start + tracked.cachedLength, revertible.propertyDeltas);\n\t\t}\n\t}\n}\n\nfunction getPosition(mergeTreeWithRevert: MergeTreeWithRevert, segment: ISegmentLeaf): number {\n\treturn mergeTreeWithRevert.getPosition(segment, mergeTreeWithRevert.localPerspective);\n}\n\n/**\n * Reverts all operations in the list of revertibles.\n *\n * @legacy\n * @alpha\n */\nexport function revertMergeTreeDeltaRevertibles(\n\tdriver: MergeTreeRevertibleDriver,\n\trevertibles: MergeTreeDeltaRevertible[],\n): void {\n\tlet mergeTreeWithRevert: MergeTreeWithRevert | undefined;\n\n\twhile (revertibles.length > 0) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\tconst r = revertibles.pop()!;\n\t\tconst operation = r.operation;\n\t\tif (r.trackingGroup.size > 0) {\n\t\t\tmergeTreeWithRevert ??= findMergeTreeWithRevert(r.trackingGroup.tracked[0]);\n\t\t\tswitch (operation) {\n\t\t\t\tcase MergeTreeDeltaType.INSERT: {\n\t\t\t\t\trevertLocalInsert(driver, mergeTreeWithRevert, r);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.REMOVE: {\n\t\t\t\t\trevertLocalRemove(driver, mergeTreeWithRevert, r);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tcase MergeTreeDeltaType.ANNOTATE: {\n\t\t\t\t\trevertLocalAnnotate(driver, mergeTreeWithRevert, r);\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tunreachableCase(operation);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n"]}
@@ -3,12 +3,12 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { ISegmentInternal, ISegmentPrivate, MergeBlock } from "./mergeTreeNodes.js";
6
- import type { ReferencePosition } from "./referencePositions.js";
6
+ import type { InsertOperationStamp, RemoveOperationStamp } from "./stamps.js";
7
7
  export interface StringToType {
8
8
  "string": string;
9
9
  "number": number;
10
10
  "object": object;
11
- "array": [];
11
+ "array": unknown[];
12
12
  "boolean": boolean;
13
13
  }
14
14
  export declare function propExists<P extends string>(thing: unknown, prop: P): thing is Record<P, unknown>;
@@ -17,25 +17,8 @@ export declare function propInstanceOf<P extends string, T>(thing: unknown, prop
17
17
  /**
18
18
  * Contains insertion information associated to an {@link ISegment}.
19
19
  */
20
- export interface IInsertionInfo {
21
- /**
22
- * Short clientId for the client that inserted this segment.
23
- */
24
- clientId: number;
25
- /**
26
- * Local seq at which this segment was inserted.
27
- * This is defined if and only if the insertion of the segment is pending ack, i.e. `seq` is UnassignedSequenceNumber.
28
- * Once the segment is acked, this field is cleared.
29
- *
30
- * @privateRemarks
31
- * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.
32
- */
33
- localSeq?: number;
34
- /**
35
- * Seq at which this segment was inserted.
36
- * If undefined, it is assumed the segment was inserted prior to the collab window's minimum sequence number.
37
- */
38
- seq: number;
20
+ export interface IHasInsertionInfo {
21
+ insert: InsertOperationStamp;
39
22
  }
40
23
  /**
41
24
  * Converts a segment-like object to an insertion info object if possible.
@@ -43,7 +26,7 @@ export interface IInsertionInfo {
43
26
  * @param segmentLike - The segment-like object to convert.
44
27
  * @returns The insertion info object if the conversion is possible, otherwise undefined.
45
28
  */
46
- export declare const toInsertionInfo: (segmentLike: unknown) => IInsertionInfo | undefined;
29
+ export declare const toInsertionInfo: (segmentLike: unknown) => IHasInsertionInfo | undefined;
47
30
  /**
48
31
  * A type-guard which determines if the segment has insertion info, and
49
32
  * returns true if it does, along with applying strong typing.
@@ -51,14 +34,14 @@ export declare const toInsertionInfo: (segmentLike: unknown) => IInsertionInfo |
51
34
  * @param segmentLike - The segment-like object to check.
52
35
  * @returns True if the segment has insertion info, otherwise false.
53
36
  */
54
- export declare const isInserted: (segmentLike: unknown) => segmentLike is IInsertionInfo;
37
+ export declare const isInserted: (segmentLike: unknown) => segmentLike is IHasInsertionInfo;
55
38
  /**
56
39
  * Asserts that the segment has insertion info. Usage of this function should not produce a user facing error.
57
40
  *
58
41
  * @param segmentLike - The segment-like object to check.
59
42
  * @throws Will throw an error if the segment does not have insertion info.
60
43
  */
61
- export declare const assertInserted: <T extends Partial<IInsertionInfo> | undefined>(segmentLike: ISegmentInternal | Partial<IInsertionInfo> | T) => asserts segmentLike is IInsertionInfo | Exclude<T, Partial<IInsertionInfo>>;
44
+ export declare const assertInserted: <T extends Partial<IHasInsertionInfo> | undefined>(segmentLike: ISegmentInternal | Partial<IHasInsertionInfo> | T) => asserts segmentLike is IHasInsertionInfo | Exclude<T, Partial<IHasInsertionInfo>>;
62
45
  /**
63
46
  * Common properties for a node in a merge tree.
64
47
  */
@@ -108,24 +91,15 @@ export declare const assertMergeNode: <T extends Partial<IMergeNodeInfo> | undef
108
91
  */
109
92
  export declare const removeMergeNodeInfo: (nodeLike: IMergeNodeInfo) => asserts nodeLike is never;
110
93
  /**
111
- * Contains removal information associated to an {@link ISegment}.
94
+ * Contains removal information associated with an {@link ISegment}.
95
+ *
96
+ * Segments can be removed concurrently by multiple clients.
112
97
  */
113
- export interface IRemovalInfo {
114
- /**
115
- * Local seq at which this segment was removed, if the removal is yet-to-be acked.
116
- */
117
- localRemovedSeq?: number;
98
+ export interface IHasRemovalInfo {
118
99
  /**
119
- * Seq at which this segment was removed.
100
+ * Operation stamps which have removed this segment. This list is sorted by stamp order, where removes[0] is the earliest removal.
120
101
  */
121
- removedSeq: number;
122
- /**
123
- * List of client IDs that have removed this segment.
124
- * The client that actually removed the segment (i.e. whose removal op was sequenced first) is stored as the first
125
- * client in this list. Other clients in the list have all issued concurrent ops to remove the segment.
126
- * @remarks When this list has length \> 1, this is referred to as the "overlapping remove" case.
127
- */
128
- removedClientIds: number[];
102
+ removes: RemoveOperationStamp[];
129
103
  }
130
104
  /**
131
105
  * Converts a segment-like object to a removal info object if possible.
@@ -133,7 +107,7 @@ export interface IRemovalInfo {
133
107
  * @param segmentLike - The segment-like object to convert.
134
108
  * @returns The removal info object if the conversion is possible, otherwise undefined.
135
109
  */
136
- export declare const toRemovalInfo: (segmentLike: unknown) => IRemovalInfo | undefined;
110
+ export declare const toRemovalInfo: (segmentLike: unknown) => IHasRemovalInfo | undefined;
137
111
  /**
138
112
  * A type-guard which determines if the segment has removal info, and
139
113
  * returns true if it does, along with applying strong typing.
@@ -141,14 +115,14 @@ export declare const toRemovalInfo: (segmentLike: unknown) => IRemovalInfo | und
141
115
  * @param segmentLike - The segment-like object to check.
142
116
  * @returns True if the segment has removal info, otherwise false.
143
117
  */
144
- export declare const isRemoved: (segmentLike: unknown) => segmentLike is IRemovalInfo;
118
+ export declare const isRemoved: (segmentLike: unknown) => segmentLike is IHasRemovalInfo;
145
119
  /**
146
120
  * Asserts that the segment has removal info. Usage of this function should not produce a user facing error.
147
121
  *
148
122
  * @param segmentLike - The segment-like object to check.
149
123
  * @throws Will throw an error if the segment does not have removal info.
150
124
  */
151
- export declare const assertRemoved: <T extends Partial<IRemovalInfo> | undefined>(segmentLike: ISegmentInternal | Partial<IRemovalInfo> | T) => asserts segmentLike is IRemovalInfo | Exclude<T, Partial<IRemovalInfo>>;
125
+ export declare const assertRemoved: <T extends Partial<IHasRemovalInfo> | undefined>(segmentLike: ISegmentInternal | Partial<IHasRemovalInfo> | T) => asserts segmentLike is IHasRemovalInfo | Exclude<T, Partial<IHasRemovalInfo>>;
152
126
  /**
153
127
  * Removes the removal info. This is used in rollback.
154
128
  * @param segmentLike - The segment-like object to check.
@@ -156,62 +130,9 @@ export declare const assertRemoved: <T extends Partial<IRemovalInfo> | undefined
156
130
  * ensures no further usage of the removed removal info is allowed. if continued use is required other
157
131
  * type coercion methods should be use to correctly re-type the variable.
158
132
  */
159
- export declare const removeRemovalInfo: (nodeLike: IRemovalInfo) => asserts nodeLike is never;
160
- /**
161
- * Tracks information about when and where this segment was moved to.
162
- *
163
- * Note that merge-tree does not currently support moving and only supports
164
- * obliterate. The fields below include "move" in their names to avoid renaming
165
- * in the future, when moves _are_ supported.
166
- */
167
- export interface IMoveInfo {
168
- /**
169
- * Local seq at which this segment was moved if the move is yet-to-be
170
- * acked.
171
- */
172
- localMovedSeq?: number;
173
- /**
174
- * The first seq at which this segment was moved.
175
- */
176
- movedSeq: number;
177
- /**
178
- * All seqs at which this segment was moved. In the case of overlapping,
179
- * concurrent moves this array will contain multiple seqs.
180
- *
181
- * The seq at `movedSeqs[i]` corresponds to the client id at `movedClientIds[i]`.
182
- *
183
- * The first element corresponds to the seq of the first move
184
- */
185
- movedSeqs: number[];
186
- /**
187
- * A reference to the inserted destination segment corresponding to this
188
- * segment's move.
189
- *
190
- * If undefined, the move was an obliterate.
191
- *
192
- * Currently this field is unused, as we only support obliterate operations
193
- */
194
- moveDst?: ReferencePosition;
195
- /**
196
- * List of client IDs that have moved this segment.
197
- *
198
- * The client that actually moved the segment (i.e. whose move op was sequenced
199
- * first) is stored as the first client in this list. Other clients in the
200
- * list have all issued concurrent ops to move the segment.
201
- */
202
- movedClientIds: number[];
203
- }
204
- export declare const toMoveInfo: (segmentLike: unknown) => IMoveInfo | undefined;
205
- /**
206
- * A type-guard which determines if the segment has move info, and
207
- * returns true if it does, along with applying strong typing.
208
- *
209
- * @param segmentLike - The segment-like object to check.
210
- * @returns True if the segment has move info, otherwise false.
211
- */
212
- export declare const isMoved: (segmentLike: unknown) => segmentLike is IMoveInfo;
133
+ export declare const removeRemovalInfo: (nodeLike: IHasRemovalInfo) => asserts nodeLike is never;
213
134
  /**
214
- * Returns whether this segment was marked moved as soon as its insertion was acked.
135
+ * Returns whether this segment was marked removed as soon as its insertion was acked.
215
136
  *
216
137
  * This can happen when an an insert occurs concurrent to an obliterate over the range the segment was inserted into,
217
138
  * and the obliterate was sequenced first.
@@ -219,18 +140,11 @@ export declare const isMoved: (segmentLike: unknown) => segmentLike is IMoveInfo
219
140
  * When this happens, the segment is only ever visible to the client that inserted the segment
220
141
  * (and only until that client has seen the obliterate which removed their segment).
221
142
  */
222
- export declare function wasMovedOnInsert(segment: IInsertionInfo & ISegmentPrivate): boolean;
223
- /**
224
- * Asserts that the segment has move info. Usage of this function should not produce a user facing error.
225
- *
226
- * @param segmentLike - The segment-like object to check.
227
- * @throws Will throw an error if the segment does not have move info.
228
- */
229
- export declare const assertMoved: <T extends Partial<IMoveInfo> | undefined>(segmentLike: ISegmentInternal | Partial<IMoveInfo> | T) => asserts segmentLike is IMoveInfo | Exclude<T, Partial<IMoveInfo>>;
143
+ export declare function wasRemovedOnInsert(segment: IHasInsertionInfo & ISegmentPrivate): boolean;
230
144
  /**
231
145
  * A union type representing any segment info.
232
146
  */
233
- export type SegmentInfo = IMergeNodeInfo | IInsertionInfo | IMoveInfo | IRemovalInfo;
147
+ export type SegmentInfo = IMergeNodeInfo | IHasInsertionInfo | IHasRemovalInfo;
234
148
  /**
235
149
  * A type representing a segment with additional info.
236
150
  */
@@ -1 +1 @@
1
- {"version":3,"file":"segmentInfos.d.ts","sourceRoot":"","sources":["../src/segmentInfos.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACpF,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,WAAW,YAAY;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,EAAE,CAAC;IACZ,SAAS,EAAE,OAAO,CAAC;CACnB;AAED,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAC1C,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,CAAC,GACL,KAAK,IAAI,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAE7B;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,MAAM,YAAY,EACrE,KAAK,EAAE,OAAO,EACd,IAAI,EAAE,CAAC,EACP,IAAI,EAAE,CAAC,GACL,KAAK,IAAI,MAAM,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,IAAI,CAAC,CAAC,CAK/C;AAED,wBAAgB,cAAc,CAAC,CAAC,SAAS,MAAM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AC,CAAC,EAAE,OAAO,CAAC,eAAe,CAAC,CAGY,CAAC;AAE9F;;;;;;GAMG;AACH,eAAO,MAAM,iBAAiB,EAAE,CAAC,QAAQ,EAAE,eAAe,KAAK,OAAO,CAAC,QAAQ,IAAI,KAKhF,CAAC;AAEJ;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,GAAG,OAAO,CASxF;AAED;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,cAAc,GAAG,iBAAiB,GAAG,eAAe,CAAC;AAE/E;;GAEG;AACH,MAAM,MAAM,eAAe,CAC1B,CAAC,SAAS,WAAW,EACrB,CAAC,SAAS,eAAe,GAAG,eAAe,IACxC,CAAC,GAAG,CAAC,CAAC;AAEV;;;;;;GAMG;AACH,eAAO,MAAM,aAAa,oFAIZ,CAAC,QACR,CAAC,KACL,gBAAgB,CAAC,EAAE,CAAC,CAAqC,CAAC"}
@@ -21,9 +21,14 @@ export function propInstanceOf(thing, prop, type) {
21
21
  * @param segmentLike - The segment-like object to convert.
22
22
  * @returns The insertion info object if the conversion is possible, otherwise undefined.
23
23
  */
24
- export const toInsertionInfo = (segmentLike) => hasProp(segmentLike, "clientId", "number") && hasProp(segmentLike, "seq", "number")
25
- ? segmentLike
26
- : undefined;
24
+ export const toInsertionInfo = (segmentLike) => {
25
+ return segmentLike !== undefined &&
26
+ hasProp(segmentLike, "insert", "object") &&
27
+ hasProp(segmentLike.insert, "clientId", "number") &&
28
+ hasProp(segmentLike.insert, "seq", "number")
29
+ ? segmentLike
30
+ : undefined;
31
+ };
27
32
  /**
28
33
  * A type-guard which determines if the segment has insertion info, and
29
34
  * returns true if it does, along with applying strong typing.
@@ -83,10 +88,14 @@ export const removeMergeNodeInfo = (nodeLike) => Object.assign(nodeLike, {
83
88
  * @param segmentLike - The segment-like object to convert.
84
89
  * @returns The removal info object if the conversion is possible, otherwise undefined.
85
90
  */
86
- export const toRemovalInfo = (segmentLike) => hasProp(segmentLike, "removedClientIds", "array") &&
87
- hasProp(segmentLike, "removedSeq", "number")
88
- ? segmentLike
89
- : undefined;
91
+ export const toRemovalInfo = (segmentLike) => {
92
+ return hasProp(segmentLike, "removes", "array") &&
93
+ segmentLike.removes.length > 0 &&
94
+ hasProp(segmentLike.removes[0], "clientId", "number") &&
95
+ hasProp(segmentLike.removes[0], "seq", "number")
96
+ ? segmentLike
97
+ : undefined;
98
+ };
90
99
  /**
91
100
  * A type-guard which determines if the segment has removal info, and
92
101
  * returns true if it does, along with applying strong typing.
@@ -94,6 +103,8 @@ export const toRemovalInfo = (segmentLike) => hasProp(segmentLike, "removedClien
94
103
  * @param segmentLike - The segment-like object to check.
95
104
  * @returns True if the segment has removal info, otherwise false.
96
105
  */
106
+ // export const isRemoved = (segmentLike: unknown): segmentLike is IHasRemovalInfo =>
107
+ // toRemovalInfo(segmentLike) !== undefined;
97
108
  export const isRemoved = (segmentLike) => toRemovalInfo(segmentLike) !== undefined;
98
109
  /**
99
110
  * Asserts that the segment has removal info. Usage of this function should not produce a user facing error.
@@ -110,25 +121,10 @@ export const assertRemoved = (segmentLike) => assert(segmentLike === undefined |
110
121
  * type coercion methods should be use to correctly re-type the variable.
111
122
  */
112
123
  export const removeRemovalInfo = (nodeLike) => Object.assign(nodeLike, {
113
- localRemovedSeq: undefined,
114
- removedClientIds: undefined,
115
- removedSeq: undefined,
124
+ removes: undefined,
116
125
  });
117
- export const toMoveInfo = (segmentLike) => hasProp(segmentLike, "movedClientIds", "array") &&
118
- hasProp(segmentLike, "movedSeq", "number") &&
119
- hasProp(segmentLike, "movedSeqs", "array")
120
- ? segmentLike
121
- : undefined;
122
- /**
123
- * A type-guard which determines if the segment has move info, and
124
- * returns true if it does, along with applying strong typing.
125
- *
126
- * @param segmentLike - The segment-like object to check.
127
- * @returns True if the segment has move info, otherwise false.
128
- */
129
- export const isMoved = (segmentLike) => toMoveInfo(segmentLike) !== undefined;
130
126
  /**
131
- * Returns whether this segment was marked moved as soon as its insertion was acked.
127
+ * Returns whether this segment was marked removed as soon as its insertion was acked.
132
128
  *
133
129
  * This can happen when an an insert occurs concurrent to an obliterate over the range the segment was inserted into,
134
130
  * and the obliterate was sequenced first.
@@ -136,22 +132,15 @@ export const isMoved = (segmentLike) => toMoveInfo(segmentLike) !== undefined;
136
132
  * When this happens, the segment is only ever visible to the client that inserted the segment
137
133
  * (and only until that client has seen the obliterate which removed their segment).
138
134
  */
139
- export function wasMovedOnInsert(segment) {
140
- const moveInfo = toMoveInfo(segment);
141
- const movedSeq = moveInfo?.movedSeq;
142
- if (movedSeq === undefined || movedSeq === UnassignedSequenceNumber) {
135
+ export function wasRemovedOnInsert(segment) {
136
+ const removeInfo = toRemovalInfo(segment);
137
+ const removedSeq = removeInfo?.removes[0].seq;
138
+ if (removedSeq === undefined || removedSeq === UnassignedSequenceNumber) {
143
139
  return false;
144
140
  }
145
- const insertSeq = segment.seq;
146
- return insertSeq === UnassignedSequenceNumber || insertSeq > movedSeq;
141
+ const insertSeq = segment.insert.seq;
142
+ return insertSeq === UnassignedSequenceNumber || insertSeq > removedSeq;
147
143
  }
148
- /**
149
- * Asserts that the segment has move info. Usage of this function should not produce a user facing error.
150
- *
151
- * @param segmentLike - The segment-like object to check.
152
- * @throws Will throw an error if the segment does not have move info.
153
- */
154
- export const assertMoved = (segmentLike) => assert(segmentLike === undefined || isMoved(segmentLike), 0xaa3 /* must be moveInfo */);
155
144
  /**
156
145
  * Overwrites the segment info on a segment-like object.
157
146
  *
@@ -1 +1 @@
1
- {"version":3,"file":"segmentInfos.js","sourceRoot":"","sources":["../src/segmentInfos.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,qCAAqC,CAAC;AAEvE,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAqC,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAWpF,MAAM,UAAU,UAAU,CACzB,KA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,sBAAsB,CAAC,CAAC;AAezF;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAI5B,WAAc,EACd,IAAO,EACiB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, isObject } from \"@fluidframework/core-utils/internal\";\n\nimport { UnassignedSequenceNumber } from \"./constants.js\";\nimport { ISegmentInternal, ISegmentPrivate, MergeBlock } from \"./mergeTreeNodes.js\";\nimport type { ReferencePosition } from \"./referencePositions.js\";\n\nexport interface StringToType {\n\t\"string\": string;\n\t\"number\": number;\n\t\"object\": object;\n\t\"array\": [];\n\t\"boolean\": boolean;\n}\n\nexport function propExists<P extends string>(\n\tthing: unknown,\n\tprop: P,\n): thing is Record<P, unknown> {\n\treturn isObject(thing) && prop in thing;\n}\n\nexport function hasProp<P extends string, T extends keyof StringToType>(\n\tthing: unknown,\n\tprop: P,\n\ttype: T,\n): thing is Record<P, StringToType[typeof type]> {\n\treturn (\n\t\tpropExists(thing, prop) &&\n\t\t(type === \"array\" ? Array.isArray(thing[prop]) : typeof thing[prop] === type)\n\t);\n}\n\nexport function propInstanceOf<P extends string, T>(\n\tthing: unknown,\n\tprop: P,\n\ttype: new (...args: any[]) => T,\n): thing is Record<P, T> {\n\treturn propExists(thing, prop) && thing[prop] instanceof type;\n}\n\n/**\n * Contains insertion information associated to an {@link ISegment}.\n */\nexport interface IInsertionInfo {\n\t/**\n\t * Short clientId for the client that inserted this segment.\n\t */\n\tclientId: number;\n\t/**\n\t * Local seq at which this segment was inserted.\n\t * This is defined if and only if the insertion of the segment is pending ack, i.e. `seq` is UnassignedSequenceNumber.\n\t * Once the segment is acked, this field is cleared.\n\t *\n\t * @privateRemarks\n\t * See {@link CollaborationWindow.localSeq} for more information on the semantics of localSeq.\n\t */\n\tlocalSeq?: number;\n\t/**\n\t * Seq at which this segment was inserted.\n\t * If undefined, it is assumed the segment was inserted prior to the collab window's minimum sequence number.\n\t */\n\tseq: number;\n}\n\n/**\n * Converts a segment-like object to an insertion info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The insertion info object if the conversion is possible, otherwise undefined.\n */\nexport const toInsertionInfo = (segmentLike: unknown): IInsertionInfo | undefined =>\n\thasProp(segmentLike, \"clientId\", \"number\") && hasProp(segmentLike, \"seq\", \"number\")\n\t\t? segmentLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has insertion info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has insertion info, otherwise false.\n */\nexport const isInserted = (segmentLike: unknown): segmentLike is IInsertionInfo =>\n\ttoInsertionInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has insertion info. 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 does not have insertion info.\n */\nexport const assertInserted: <T extends Partial<IInsertionInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IInsertionInfo> | T,\n) => asserts segmentLike is IInsertionInfo | Exclude<T, Partial<IInsertionInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(\n\t\tsegmentLike === undefined || isInserted(segmentLike),\n\t\t0xaa0 /* must be insertionInfo */,\n\t);\n\n/**\n * Common properties for a node in a merge tree.\n */\nexport interface IMergeNodeInfo {\n\t/**\n\t * The parent merge block if the node is parented\n\t */\n\tparent: MergeBlock;\n\n\t/**\n\t * The index of this node in its parent's list of children.\n\t */\n\tindex: number;\n\n\t/**\n\t * A string that can be used for comparing the location of this node to other `MergeNode`s in the same tree.\n\t * `a.ordinal < b.ordinal` if and only if `a` comes before `b` in a pre-order traversal of the tree.\n\t */\n\tordinal: string;\n}\n\n/**\n * Converts a segment-like object to a merge node info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The merge node info object if the conversion is possible, otherwise undefined.\n */\nexport const toMergeNodeInfo = (nodeLike: unknown): IMergeNodeInfo | undefined =>\n\tpropInstanceOf(nodeLike, \"parent\", MergeBlock) &&\n\thasProp(nodeLike, \"ordinal\", \"string\") &&\n\thasProp(nodeLike, \"index\", \"number\")\n\t\t? nodeLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has merge node info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment has merge node info, otherwise false.\n */\nexport const isMergeNodeInfo = (nodeLike: unknown): nodeLike is IMergeNodeInfo =>\n\ttoMergeNodeInfo(nodeLike) !== undefined;\n\n/**\n * Asserts that the segment has merge node info. 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 does not have merge node info.\n */\nexport const assertMergeNode: <T extends Partial<IMergeNodeInfo> | undefined>(\n\tnodeLike: ISegmentInternal | ISegmentPrivate | Partial<IMergeNodeInfo> | T,\n) => asserts nodeLike is IMergeNodeInfo | Exclude<T, Partial<IMergeNodeInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(\n\t\tsegmentLike === undefined || isMergeNodeInfo(segmentLike),\n\t\t0xaa1 /* must be MergeNodeInfo */,\n\t);\n\n/**\n * Removes the merge node info. This is used to remove nodes from the merge-tree.\n * @param segmentLike - The segment-like object to check.\n * @returns This function will change the type of the provided node like to never via an assertion. This\n * ensures no further usage of the removed merge node info is allowed. if continued use is required other\n * type coercion methods should be used to correctly re-type the variable.\n */\nexport const removeMergeNodeInfo: (nodeLike: IMergeNodeInfo) => asserts nodeLike is never = (\n\tnodeLike,\n) =>\n\tObject.assign<IMergeNodeInfo, Record<keyof IMergeNodeInfo, undefined>>(nodeLike, {\n\t\tparent: undefined,\n\t\tindex: undefined,\n\t\tordinal: undefined,\n\t});\n\n/**\n * Contains removal information associated to an {@link ISegment}.\n */\nexport interface IRemovalInfo {\n\t/**\n\t * Local seq at which this segment was removed, if the removal is yet-to-be acked.\n\t */\n\tlocalRemovedSeq?: number;\n\t/**\n\t * Seq at which this segment was removed.\n\t */\n\tremovedSeq: number;\n\t/**\n\t * List of client IDs that have removed this segment.\n\t * The client that actually removed the segment (i.e. whose removal op was sequenced first) is stored as the first\n\t * client in this list. Other clients in the list have all issued concurrent ops to remove the segment.\n\t * @remarks When this list has length \\> 1, this is referred to as the \"overlapping remove\" case.\n\t */\n\tremovedClientIds: number[];\n}\n\n/**\n * Converts a segment-like object to a removal info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The removal info object if the conversion is possible, otherwise undefined.\n */\nexport const toRemovalInfo = (segmentLike: unknown): IRemovalInfo | undefined =>\n\thasProp(segmentLike, \"removedClientIds\", \"array\") &&\n\thasProp(segmentLike, \"removedSeq\", \"number\")\n\t\t? segmentLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has removal info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has removal info, otherwise false.\n */\nexport const isRemoved = (segmentLike: unknown): segmentLike is IRemovalInfo =>\n\ttoRemovalInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has removal info. 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 does not have removal info.\n */\nexport const assertRemoved: <T extends Partial<IRemovalInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IRemovalInfo> | T,\n) => asserts segmentLike is IRemovalInfo | Exclude<T, Partial<IRemovalInfo>> = (segmentLike) =>\n\tassert(segmentLike === undefined || isRemoved(segmentLike), 0xaa2 /* must be removalInfo */);\n\n/**\n * Removes the removal info. This is used in rollback.\n * @param segmentLike - The segment-like object to check.\n * @returns This function will change the type of the provided node like to never via an assertion. This\n * ensures no further usage of the removed removal info is allowed. if continued use is required other\n * type coercion methods should be use to correctly re-type the variable.\n */\nexport const removeRemovalInfo: (nodeLike: IRemovalInfo) => asserts nodeLike is never = (\n\tnodeLike,\n) =>\n\tObject.assign<IRemovalInfo, Record<keyof IRemovalInfo, undefined>>(nodeLike, {\n\t\tlocalRemovedSeq: undefined,\n\t\tremovedClientIds: undefined,\n\t\tremovedSeq: undefined,\n\t});\n\n/**\n * Tracks information about when and where this segment was moved to.\n *\n * Note that merge-tree does not currently support moving and only supports\n * obliterate. The fields below include \"move\" in their names to avoid renaming\n * in the future, when moves _are_ supported.\n */\nexport interface IMoveInfo {\n\t/**\n\t * Local seq at which this segment was moved if the move is yet-to-be\n\t * acked.\n\t */\n\tlocalMovedSeq?: number;\n\n\t/**\n\t * The first seq at which this segment was moved.\n\t */\n\tmovedSeq: number;\n\n\t/**\n\t * All seqs at which this segment was moved. In the case of overlapping,\n\t * concurrent moves this array will contain multiple seqs.\n\t *\n\t * The seq at `movedSeqs[i]` corresponds to the client id at `movedClientIds[i]`.\n\t *\n\t * The first element corresponds to the seq of the first move\n\t */\n\tmovedSeqs: number[];\n\n\t/**\n\t * A reference to the inserted destination segment corresponding to this\n\t * segment's move.\n\t *\n\t * If undefined, the move was an obliterate.\n\t *\n\t * Currently this field is unused, as we only support obliterate operations\n\t */\n\tmoveDst?: ReferencePosition;\n\n\t/**\n\t * List of client IDs that have moved this segment.\n\t *\n\t * The client that actually moved the segment (i.e. whose move op was sequenced\n\t * first) is stored as the first client in this list. Other clients in the\n\t * list have all issued concurrent ops to move the segment.\n\t */\n\tmovedClientIds: number[];\n}\n\nexport const toMoveInfo = (segmentLike: unknown): IMoveInfo | undefined =>\n\thasProp(segmentLike, \"movedClientIds\", \"array\") &&\n\thasProp(segmentLike, \"movedSeq\", \"number\") &&\n\thasProp(segmentLike, \"movedSeqs\", \"array\")\n\t\t? segmentLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has move info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has move info, otherwise false.\n */\nexport const isMoved = (segmentLike: unknown): segmentLike is IMoveInfo =>\n\ttoMoveInfo(segmentLike) !== undefined;\n\n/**\n * Returns whether this segment was marked moved as soon as its insertion was acked.\n *\n * This can happen when an an insert occurs concurrent to an obliterate over the range the segment was inserted into,\n * and the obliterate was sequenced first.\n *\n * When this happens, the segment is only ever visible to the client that inserted the segment\n * (and only until that client has seen the obliterate which removed their segment).\n */\nexport function wasMovedOnInsert(segment: IInsertionInfo & ISegmentPrivate): boolean {\n\tconst moveInfo = toMoveInfo(segment);\n\tconst movedSeq = moveInfo?.movedSeq;\n\tif (movedSeq === undefined || movedSeq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\tconst insertSeq = segment.seq;\n\treturn insertSeq === UnassignedSequenceNumber || insertSeq > movedSeq;\n}\n\n/**\n * Asserts that the segment has move info. 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 does not have move info.\n */\nexport const assertMoved: <T extends Partial<IMoveInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IMoveInfo> | T,\n) => asserts segmentLike is IMoveInfo | Exclude<T, Partial<IMoveInfo>> = (segmentLike) =>\n\tassert(segmentLike === undefined || isMoved(segmentLike), 0xaa3 /* must be moveInfo */);\n\n/**\n * A union type representing any segment info.\n */\nexport type SegmentInfo = IMergeNodeInfo | IInsertionInfo | IMoveInfo | IRemovalInfo;\n\n/**\n * A type representing a segment with additional info.\n */\nexport type SegmentWithInfo<\n\tT extends SegmentInfo,\n\tS extends ISegmentPrivate = ISegmentPrivate,\n> = S & T;\n\n/**\n * Overwrites the segment info on a segment-like object.\n *\n * @param segmentLike - The segment-like object to set the info on.\n * @param info - The segment info to overwrite.\n * @returns The segment-like object with the info set.\n */\nexport const overwriteInfo = <\n\tT extends SegmentInfo,\n\tS extends ISegmentPrivate = ISegmentPrivate,\n>(\n\tsegmentLike: S,\n\tinfo: T,\n): SegmentWithInfo<T, S> => Object.assign(segmentLike, info);\n"]}
1
+ {"version":3,"file":"segmentInfos.js","sourceRoot":"","sources":["../src/segmentInfos.ts"],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;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAI5B,WAAc,EACd,IAAO,EACiB,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,WAAW,EAAE,IAAI,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, isObject } from \"@fluidframework/core-utils/internal\";\n\nimport { UnassignedSequenceNumber } from \"./constants.js\";\nimport { ISegmentInternal, ISegmentPrivate, MergeBlock } from \"./mergeTreeNodes.js\";\nimport type { InsertOperationStamp, RemoveOperationStamp } from \"./stamps.js\";\n\nexport interface StringToType {\n\t\"string\": string;\n\t\"number\": number;\n\t\"object\": object;\n\t\"array\": unknown[];\n\t\"boolean\": boolean;\n}\n\nexport function propExists<P extends string>(\n\tthing: unknown,\n\tprop: P,\n): thing is Record<P, unknown> {\n\treturn isObject(thing) && prop in thing;\n}\n\nexport function hasProp<P extends string, T extends keyof StringToType>(\n\tthing: unknown,\n\tprop: P,\n\ttype: T,\n): thing is Record<P, StringToType[typeof type]> {\n\treturn (\n\t\tpropExists(thing, prop) &&\n\t\t(type === \"array\" ? Array.isArray(thing[prop]) : typeof thing[prop] === type)\n\t);\n}\n\nexport function propInstanceOf<P extends string, T>(\n\tthing: unknown,\n\tprop: P,\n\ttype: new (...args: any[]) => T,\n): thing is Record<P, T> {\n\treturn propExists(thing, prop) && thing[prop] instanceof type;\n}\n\n/**\n * Contains insertion information associated to an {@link ISegment}.\n */\nexport interface IHasInsertionInfo {\n\tinsert: InsertOperationStamp;\n}\n\n/**\n * Converts a segment-like object to an insertion info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The insertion info object if the conversion is possible, otherwise undefined.\n */\nexport const toInsertionInfo = (segmentLike: unknown): IHasInsertionInfo | undefined => {\n\treturn segmentLike !== undefined &&\n\t\thasProp(segmentLike, \"insert\", \"object\") &&\n\t\thasProp(segmentLike.insert, \"clientId\", \"number\") &&\n\t\thasProp(segmentLike.insert, \"seq\", \"number\")\n\t\t? (segmentLike as IHasInsertionInfo)\n\t\t: undefined;\n};\n\n/**\n * A type-guard which determines if the segment has insertion info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has insertion info, otherwise false.\n */\nexport const isInserted = (segmentLike: unknown): segmentLike is IHasInsertionInfo =>\n\ttoInsertionInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has insertion info. 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 does not have insertion info.\n */\nexport const assertInserted: <T extends Partial<IHasInsertionInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IHasInsertionInfo> | T,\n) => asserts segmentLike is IHasInsertionInfo | Exclude<T, Partial<IHasInsertionInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(\n\t\tsegmentLike === undefined || isInserted(segmentLike),\n\t\t0xaa0 /* must be insertionInfo */,\n\t);\n\n/**\n * Common properties for a node in a merge tree.\n */\nexport interface IMergeNodeInfo {\n\t/**\n\t * The parent merge block if the node is parented\n\t */\n\tparent: MergeBlock;\n\n\t/**\n\t * The index of this node in its parent's list of children.\n\t */\n\tindex: number;\n\n\t/**\n\t * A string that can be used for comparing the location of this node to other `MergeNode`s in the same tree.\n\t * `a.ordinal < b.ordinal` if and only if `a` comes before `b` in a pre-order traversal of the tree.\n\t */\n\tordinal: string;\n}\n\n/**\n * Converts a segment-like object to a merge node info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The merge node info object if the conversion is possible, otherwise undefined.\n */\nexport const toMergeNodeInfo = (nodeLike: unknown): IMergeNodeInfo | undefined =>\n\tpropInstanceOf(nodeLike, \"parent\", MergeBlock) &&\n\thasProp(nodeLike, \"ordinal\", \"string\") &&\n\thasProp(nodeLike, \"index\", \"number\")\n\t\t? nodeLike\n\t\t: undefined;\n\n/**\n * A type-guard which determines if the segment has merge node info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param nodeLike - The segment-like object to check.\n * @returns True if the segment has merge node info, otherwise false.\n */\nexport const isMergeNodeInfo = (nodeLike: unknown): nodeLike is IMergeNodeInfo =>\n\ttoMergeNodeInfo(nodeLike) !== undefined;\n\n/**\n * Asserts that the segment has merge node info. 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 does not have merge node info.\n */\nexport const assertMergeNode: <T extends Partial<IMergeNodeInfo> | undefined>(\n\tnodeLike: ISegmentInternal | ISegmentPrivate | Partial<IMergeNodeInfo> | T,\n) => asserts nodeLike is IMergeNodeInfo | Exclude<T, Partial<IMergeNodeInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(\n\t\tsegmentLike === undefined || isMergeNodeInfo(segmentLike),\n\t\t0xaa1 /* must be MergeNodeInfo */,\n\t);\n\n/**\n * Removes the merge node info. This is used to remove nodes from the merge-tree.\n * @param segmentLike - The segment-like object to check.\n * @returns This function will change the type of the provided node like to never via an assertion. This\n * ensures no further usage of the removed merge node info is allowed. if continued use is required other\n * type coercion methods should be used to correctly re-type the variable.\n */\nexport const removeMergeNodeInfo: (nodeLike: IMergeNodeInfo) => asserts nodeLike is never = (\n\tnodeLike,\n) =>\n\tObject.assign<IMergeNodeInfo, Record<keyof IMergeNodeInfo, undefined>>(nodeLike, {\n\t\tparent: undefined,\n\t\tindex: undefined,\n\t\tordinal: undefined,\n\t});\n\n/**\n * Contains removal information associated with an {@link ISegment}.\n *\n * Segments can be removed concurrently by multiple clients.\n */\nexport interface IHasRemovalInfo {\n\t/**\n\t * Operation stamps which have removed this segment. This list is sorted by stamp order, where removes[0] is the earliest removal.\n\t */\n\tremoves: RemoveOperationStamp[];\n}\n\n/**\n * Converts a segment-like object to a removal info object if possible.\n *\n * @param segmentLike - The segment-like object to convert.\n * @returns The removal info object if the conversion is possible, otherwise undefined.\n */\nexport const toRemovalInfo = (segmentLike: unknown): IHasRemovalInfo | undefined => {\n\treturn hasProp(segmentLike, \"removes\", \"array\") &&\n\t\tsegmentLike.removes.length > 0 &&\n\t\thasProp(segmentLike.removes[0], \"clientId\", \"number\") &&\n\t\thasProp(segmentLike.removes[0], \"seq\", \"number\")\n\t\t? (segmentLike as IHasRemovalInfo)\n\t\t: undefined;\n};\n\n/**\n * A type-guard which determines if the segment has removal info, and\n * returns true if it does, along with applying strong typing.\n *\n * @param segmentLike - The segment-like object to check.\n * @returns True if the segment has removal info, otherwise false.\n */\n// export const isRemoved = (segmentLike: unknown): segmentLike is IHasRemovalInfo =>\n// \ttoRemovalInfo(segmentLike) !== undefined;\n\nexport const isRemoved = (segmentLike: unknown): segmentLike is IHasRemovalInfo =>\n\ttoRemovalInfo(segmentLike) !== undefined;\n\n/**\n * Asserts that the segment has removal info. 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 does not have removal info.\n */\nexport const assertRemoved: <T extends Partial<IHasRemovalInfo> | undefined>(\n\tsegmentLike: ISegmentInternal | Partial<IHasRemovalInfo> | T,\n) => asserts segmentLike is IHasRemovalInfo | Exclude<T, Partial<IHasRemovalInfo>> = (\n\tsegmentLike,\n) =>\n\tassert(segmentLike === undefined || isRemoved(segmentLike), 0xaa2 /* must be removalInfo */);\n\n/**\n * Removes the removal info. This is used in rollback.\n * @param segmentLike - The segment-like object to check.\n * @returns This function will change the type of the provided node like to never via an assertion. This\n * ensures no further usage of the removed removal info is allowed. if continued use is required other\n * type coercion methods should be use to correctly re-type the variable.\n */\nexport const removeRemovalInfo: (nodeLike: IHasRemovalInfo) => asserts nodeLike is never = (\n\tnodeLike,\n) =>\n\tObject.assign<IHasRemovalInfo, Record<keyof IHasRemovalInfo, undefined>>(nodeLike, {\n\t\tremoves: undefined,\n\t});\n\n/**\n * Returns whether this segment was marked removed as soon as its insertion was acked.\n *\n * This can happen when an an insert occurs concurrent to an obliterate over the range the segment was inserted into,\n * and the obliterate was sequenced first.\n *\n * When this happens, the segment is only ever visible to the client that inserted the segment\n * (and only until that client has seen the obliterate which removed their segment).\n */\nexport function wasRemovedOnInsert(segment: IHasInsertionInfo & ISegmentPrivate): boolean {\n\tconst removeInfo = toRemovalInfo(segment);\n\tconst removedSeq = removeInfo?.removes[0].seq;\n\tif (removedSeq === undefined || removedSeq === UnassignedSequenceNumber) {\n\t\treturn false;\n\t}\n\n\tconst insertSeq = segment.insert.seq;\n\treturn insertSeq === UnassignedSequenceNumber || insertSeq > removedSeq;\n}\n\n/**\n * A union type representing any segment info.\n */\nexport type SegmentInfo = IMergeNodeInfo | IHasInsertionInfo | IHasRemovalInfo;\n\n/**\n * A type representing a segment with additional info.\n */\nexport type SegmentWithInfo<\n\tT extends SegmentInfo,\n\tS extends ISegmentPrivate = ISegmentPrivate,\n> = S & T;\n\n/**\n * Overwrites the segment info on a segment-like object.\n *\n * @param segmentLike - The segment-like object to set the info on.\n * @param info - The segment info to overwrite.\n * @returns The segment-like object with the info set.\n */\nexport const overwriteInfo = <\n\tT extends SegmentInfo,\n\tS extends ISegmentPrivate = ISegmentPrivate,\n>(\n\tsegmentLike: S,\n\tinfo: T,\n): SegmentWithInfo<T, S> => Object.assign(segmentLike, info);\n"]}