@fluidframework/tree 2.10.0 → 2.11.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 (465) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/api-report/tree.alpha.api.md +47 -16
  3. package/api-report/tree.beta.api.md +5 -14
  4. package/api-report/tree.legacy.alpha.api.md +5 -14
  5. package/api-report/tree.legacy.public.api.md +5 -14
  6. package/api-report/tree.public.api.md +5 -14
  7. package/dist/alpha.d.ts +9 -0
  8. package/dist/core/forest/forest.d.ts +10 -2
  9. package/dist/core/forest/forest.d.ts.map +1 -1
  10. package/dist/core/forest/forest.js.map +1 -1
  11. package/dist/core/index.d.ts +2 -2
  12. package/dist/core/index.d.ts.map +1 -1
  13. package/dist/core/index.js +3 -2
  14. package/dist/core/index.js.map +1 -1
  15. package/dist/core/rebase/utils.d.ts +1 -1
  16. package/dist/core/rebase/utils.d.ts.map +1 -1
  17. package/dist/core/rebase/utils.js +11 -8
  18. package/dist/core/rebase/utils.js.map +1 -1
  19. package/dist/core/revertible.d.ts +30 -1
  20. package/dist/core/revertible.d.ts.map +1 -1
  21. package/dist/core/revertible.js.map +1 -1
  22. package/dist/core/schema-stored/storedSchemaRepository.d.ts +2 -2
  23. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  24. package/dist/core/schema-stored/storedSchemaRepository.js +5 -5
  25. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  26. package/dist/core/tree/anchorSet.d.ts +2 -2
  27. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  28. package/dist/core/tree/anchorSet.js +21 -21
  29. package/dist/core/tree/anchorSet.js.map +1 -1
  30. package/dist/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  31. package/dist/core/tree/detachedFieldIndexCodec.js +3 -2
  32. package/dist/core/tree/detachedFieldIndexCodec.js.map +1 -1
  33. package/dist/core/tree/index.d.ts +1 -1
  34. package/dist/core/tree/index.d.ts.map +1 -1
  35. package/dist/core/tree/index.js +2 -1
  36. package/dist/core/tree/index.js.map +1 -1
  37. package/dist/core/tree/visitorUtils.d.ts +25 -1
  38. package/dist/core/tree/visitorUtils.d.ts.map +1 -1
  39. package/dist/core/tree/visitorUtils.js +29 -1
  40. package/dist/core/tree/visitorUtils.js.map +1 -1
  41. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts +5 -2
  42. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  43. package/dist/feature-libraries/chunked-forest/chunkedForest.js +24 -14
  44. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  45. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  46. package/dist/feature-libraries/chunked-forest/uniformChunk.js +2 -2
  47. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  48. package/dist/feature-libraries/flex-tree/context.d.ts +1 -1
  49. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  50. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  51. package/dist/feature-libraries/index.d.ts +1 -0
  52. package/dist/feature-libraries/index.d.ts.map +1 -1
  53. package/dist/feature-libraries/index.js +4 -1
  54. package/dist/feature-libraries/index.js.map +1 -1
  55. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts +132 -0
  56. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -0
  57. package/dist/feature-libraries/indexing/anchorTreeIndex.js +361 -0
  58. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -0
  59. package/dist/feature-libraries/indexing/index.d.ts +7 -0
  60. package/dist/feature-libraries/indexing/index.d.ts.map +1 -0
  61. package/dist/feature-libraries/indexing/index.js +11 -0
  62. package/dist/feature-libraries/indexing/index.js.map +1 -0
  63. package/dist/feature-libraries/indexing/types.d.ts +32 -0
  64. package/dist/feature-libraries/indexing/types.d.ts.map +1 -0
  65. package/dist/{events/interop.js → feature-libraries/indexing/types.js} +1 -1
  66. package/dist/feature-libraries/indexing/types.js.map +1 -0
  67. package/dist/feature-libraries/object-forest/objectForest.d.ts +5 -2
  68. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  69. package/dist/feature-libraries/object-forest/objectForest.js +21 -11
  70. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  71. package/dist/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  72. package/dist/feature-libraries/sequence-field/invert.js +2 -2
  73. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  74. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +3 -2
  75. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  76. package/dist/index.d.ts +4 -4
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +4 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/packageVersion.d.ts +1 -1
  81. package/dist/packageVersion.js +1 -1
  82. package/dist/packageVersion.js.map +1 -1
  83. package/dist/shared-tree/index.d.ts +1 -1
  84. package/dist/shared-tree/index.d.ts.map +1 -1
  85. package/dist/shared-tree/index.js +1 -2
  86. package/dist/shared-tree/index.js.map +1 -1
  87. package/dist/shared-tree/schematizingTreeView.d.ts +7 -1
  88. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  89. package/dist/shared-tree/schematizingTreeView.js +31 -30
  90. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  91. package/dist/shared-tree/sharedTree.d.ts +3 -0
  92. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  93. package/dist/shared-tree/sharedTree.js +56 -20
  94. package/dist/shared-tree/sharedTree.js.map +1 -1
  95. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  96. package/dist/shared-tree/sharedTreeChangeFamily.js +3 -3
  97. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  98. package/dist/shared-tree/treeCheckout.d.ts +28 -64
  99. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  100. package/dist/shared-tree/treeCheckout.js +152 -129
  101. package/dist/shared-tree/treeCheckout.js.map +1 -1
  102. package/dist/shared-tree-core/branch.d.ts +25 -81
  103. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  104. package/dist/shared-tree-core/branch.js +72 -151
  105. package/dist/shared-tree-core/branch.js.map +1 -1
  106. package/dist/shared-tree-core/branchCommitEnricher.d.ts +19 -33
  107. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  108. package/dist/shared-tree-core/branchCommitEnricher.js +73 -54
  109. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  110. package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  111. package/dist/shared-tree-core/defaultResubmitMachine.js +2 -1
  112. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  113. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  114. package/dist/shared-tree-core/editManager.js +2 -2
  115. package/dist/shared-tree-core/editManager.js.map +1 -1
  116. package/dist/shared-tree-core/index.d.ts +1 -1
  117. package/dist/shared-tree-core/index.d.ts.map +1 -1
  118. package/dist/shared-tree-core/index.js +4 -3
  119. package/dist/shared-tree-core/index.js.map +1 -1
  120. package/dist/shared-tree-core/sharedTreeCore.d.ts +2 -2
  121. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  122. package/dist/shared-tree-core/sharedTreeCore.js +11 -52
  123. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  124. package/dist/shared-tree-core/transaction.d.ts +108 -0
  125. package/dist/shared-tree-core/transaction.d.ts.map +1 -0
  126. package/dist/shared-tree-core/transaction.js +99 -0
  127. package/dist/shared-tree-core/transaction.js.map +1 -0
  128. package/dist/shared-tree-core/transactionEnricher.d.ts +8 -13
  129. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  130. package/dist/shared-tree-core/transactionEnricher.js +41 -21
  131. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  132. package/dist/simple-tree/api/identifierIndex.d.ts +21 -0
  133. package/dist/simple-tree/api/identifierIndex.d.ts.map +1 -0
  134. package/dist/simple-tree/api/identifierIndex.js +45 -0
  135. package/dist/simple-tree/api/identifierIndex.js.map +1 -0
  136. package/dist/simple-tree/api/index.d.ts +2 -0
  137. package/dist/simple-tree/api/index.d.ts.map +1 -1
  138. package/dist/simple-tree/api/index.js +5 -1
  139. package/dist/simple-tree/api/index.js.map +1 -1
  140. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +9 -7
  141. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  142. package/dist/simple-tree/api/simpleTreeIndex.d.ts +65 -0
  143. package/dist/simple-tree/api/simpleTreeIndex.d.ts.map +1 -0
  144. package/dist/simple-tree/api/simpleTreeIndex.js +91 -0
  145. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -0
  146. package/dist/simple-tree/api/tree.d.ts +4 -5
  147. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  148. package/dist/simple-tree/api/tree.js.map +1 -1
  149. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  150. package/dist/simple-tree/core/index.d.ts +1 -1
  151. package/dist/simple-tree/core/index.d.ts.map +1 -1
  152. package/dist/simple-tree/core/index.js +2 -1
  153. package/dist/simple-tree/core/index.js.map +1 -1
  154. package/dist/simple-tree/core/treeNodeKernel.d.ts +6 -2
  155. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  156. package/dist/simple-tree/core/treeNodeKernel.js +53 -22
  157. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  158. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
  159. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  160. package/dist/simple-tree/core/unhydratedFlexTree.js +2 -2
  161. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  162. package/dist/simple-tree/index.d.ts +1 -1
  163. package/dist/simple-tree/index.d.ts.map +1 -1
  164. package/dist/simple-tree/index.js +4 -2
  165. package/dist/simple-tree/index.js.map +1 -1
  166. package/dist/simple-tree/objectNode.d.ts +7 -2
  167. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  168. package/dist/simple-tree/objectNode.js.map +1 -1
  169. package/dist/simple-tree/toMapTree.js +3 -3
  170. package/dist/simple-tree/toMapTree.js.map +1 -1
  171. package/dist/util/index.d.ts +1 -2
  172. package/dist/util/index.d.ts.map +1 -1
  173. package/dist/util/index.js +5 -4
  174. package/dist/util/index.js.map +1 -1
  175. package/dist/util/typeCheck.d.ts +6 -1
  176. package/dist/util/typeCheck.d.ts.map +1 -1
  177. package/dist/util/typeCheck.js.map +1 -1
  178. package/dist/util/typeCheckTests.d.ts +14 -2
  179. package/dist/util/typeCheckTests.d.ts.map +1 -1
  180. package/dist/util/typeCheckTests.js.map +1 -1
  181. package/dist/util/utils.d.ts +29 -0
  182. package/dist/util/utils.d.ts.map +1 -1
  183. package/dist/util/utils.js +13 -1
  184. package/dist/util/utils.js.map +1 -1
  185. package/lib/alpha.d.ts +9 -0
  186. package/lib/core/forest/forest.d.ts +10 -2
  187. package/lib/core/forest/forest.d.ts.map +1 -1
  188. package/lib/core/forest/forest.js.map +1 -1
  189. package/lib/core/index.d.ts +2 -2
  190. package/lib/core/index.d.ts.map +1 -1
  191. package/lib/core/index.js +2 -2
  192. package/lib/core/index.js.map +1 -1
  193. package/lib/core/rebase/utils.d.ts +1 -1
  194. package/lib/core/rebase/utils.d.ts.map +1 -1
  195. package/lib/core/rebase/utils.js +11 -8
  196. package/lib/core/rebase/utils.js.map +1 -1
  197. package/lib/core/revertible.d.ts +30 -1
  198. package/lib/core/revertible.d.ts.map +1 -1
  199. package/lib/core/revertible.js.map +1 -1
  200. package/lib/core/schema-stored/storedSchemaRepository.d.ts +2 -2
  201. package/lib/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  202. package/lib/core/schema-stored/storedSchemaRepository.js +1 -1
  203. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  204. package/lib/core/tree/anchorSet.d.ts +2 -2
  205. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  206. package/lib/core/tree/anchorSet.js +1 -1
  207. package/lib/core/tree/anchorSet.js.map +1 -1
  208. package/lib/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  209. package/lib/core/tree/detachedFieldIndexCodec.js +4 -3
  210. package/lib/core/tree/detachedFieldIndexCodec.js.map +1 -1
  211. package/lib/core/tree/index.d.ts +1 -1
  212. package/lib/core/tree/index.d.ts.map +1 -1
  213. package/lib/core/tree/index.js +1 -1
  214. package/lib/core/tree/index.js.map +1 -1
  215. package/lib/core/tree/visitorUtils.d.ts +25 -1
  216. package/lib/core/tree/visitorUtils.d.ts.map +1 -1
  217. package/lib/core/tree/visitorUtils.js +27 -0
  218. package/lib/core/tree/visitorUtils.js.map +1 -1
  219. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts +5 -2
  220. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  221. package/lib/feature-libraries/chunked-forest/chunkedForest.js +18 -8
  222. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  223. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  224. package/lib/feature-libraries/chunked-forest/uniformChunk.js +3 -3
  225. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  226. package/lib/feature-libraries/flex-tree/context.d.ts +1 -1
  227. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  228. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  229. package/lib/feature-libraries/index.d.ts +1 -0
  230. package/lib/feature-libraries/index.d.ts.map +1 -1
  231. package/lib/feature-libraries/index.js +1 -0
  232. package/lib/feature-libraries/index.js.map +1 -1
  233. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts +132 -0
  234. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -0
  235. package/lib/feature-libraries/indexing/anchorTreeIndex.js +356 -0
  236. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -0
  237. package/lib/feature-libraries/indexing/index.d.ts +7 -0
  238. package/lib/feature-libraries/indexing/index.d.ts.map +1 -0
  239. package/lib/{events → feature-libraries/indexing}/index.js +1 -1
  240. package/lib/feature-libraries/indexing/index.js.map +1 -0
  241. package/lib/feature-libraries/indexing/types.d.ts +32 -0
  242. package/lib/feature-libraries/indexing/types.d.ts.map +1 -0
  243. package/lib/{events/interop.js → feature-libraries/indexing/types.js} +1 -1
  244. package/lib/feature-libraries/indexing/types.js.map +1 -0
  245. package/lib/feature-libraries/object-forest/objectForest.d.ts +5 -2
  246. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  247. package/lib/feature-libraries/object-forest/objectForest.js +15 -5
  248. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  249. package/lib/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  250. package/lib/feature-libraries/sequence-field/invert.js +4 -4
  251. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  252. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +4 -3
  253. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  254. package/lib/index.d.ts +4 -4
  255. package/lib/index.d.ts.map +1 -1
  256. package/lib/index.js +1 -1
  257. package/lib/index.js.map +1 -1
  258. package/lib/packageVersion.d.ts +1 -1
  259. package/lib/packageVersion.js +1 -1
  260. package/lib/packageVersion.js.map +1 -1
  261. package/lib/shared-tree/index.d.ts +1 -1
  262. package/lib/shared-tree/index.d.ts.map +1 -1
  263. package/lib/shared-tree/index.js +1 -1
  264. package/lib/shared-tree/index.js.map +1 -1
  265. package/lib/shared-tree/schematizingTreeView.d.ts +7 -1
  266. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  267. package/lib/shared-tree/schematizingTreeView.js +2 -2
  268. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  269. package/lib/shared-tree/sharedTree.d.ts +3 -0
  270. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  271. package/lib/shared-tree/sharedTree.js +37 -1
  272. package/lib/shared-tree/sharedTree.js.map +1 -1
  273. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  274. package/lib/shared-tree/sharedTreeChangeFamily.js +5 -5
  275. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  276. package/lib/shared-tree/treeCheckout.d.ts +28 -64
  277. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  278. package/lib/shared-tree/treeCheckout.js +140 -116
  279. package/lib/shared-tree/treeCheckout.js.map +1 -1
  280. package/lib/shared-tree-core/branch.d.ts +25 -81
  281. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  282. package/lib/shared-tree-core/branch.js +72 -151
  283. package/lib/shared-tree-core/branch.js.map +1 -1
  284. package/lib/shared-tree-core/branchCommitEnricher.d.ts +19 -33
  285. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  286. package/lib/shared-tree-core/branchCommitEnricher.js +74 -55
  287. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  288. package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  289. package/lib/shared-tree-core/defaultResubmitMachine.js +3 -2
  290. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  291. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  292. package/lib/shared-tree-core/editManager.js +1 -1
  293. package/lib/shared-tree-core/editManager.js.map +1 -1
  294. package/lib/shared-tree-core/index.d.ts +1 -1
  295. package/lib/shared-tree-core/index.d.ts.map +1 -1
  296. package/lib/shared-tree-core/index.js +1 -1
  297. package/lib/shared-tree-core/index.js.map +1 -1
  298. package/lib/shared-tree-core/sharedTreeCore.d.ts +2 -2
  299. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  300. package/lib/shared-tree-core/sharedTreeCore.js +12 -53
  301. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  302. package/lib/shared-tree-core/transaction.d.ts +108 -0
  303. package/lib/shared-tree-core/transaction.d.ts.map +1 -0
  304. package/lib/shared-tree-core/transaction.js +95 -0
  305. package/lib/shared-tree-core/transaction.js.map +1 -0
  306. package/lib/shared-tree-core/transactionEnricher.d.ts +8 -13
  307. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  308. package/lib/shared-tree-core/transactionEnricher.js +41 -21
  309. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  310. package/lib/simple-tree/api/identifierIndex.d.ts +21 -0
  311. package/lib/simple-tree/api/identifierIndex.d.ts.map +1 -0
  312. package/lib/simple-tree/api/identifierIndex.js +41 -0
  313. package/lib/simple-tree/api/identifierIndex.js.map +1 -0
  314. package/lib/simple-tree/api/index.d.ts +2 -0
  315. package/lib/simple-tree/api/index.d.ts.map +1 -1
  316. package/lib/simple-tree/api/index.js +2 -0
  317. package/lib/simple-tree/api/index.js.map +1 -1
  318. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +11 -9
  319. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  320. package/lib/simple-tree/api/simpleTreeIndex.d.ts +65 -0
  321. package/lib/simple-tree/api/simpleTreeIndex.d.ts.map +1 -0
  322. package/lib/simple-tree/api/simpleTreeIndex.js +87 -0
  323. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -0
  324. package/lib/simple-tree/api/tree.d.ts +4 -5
  325. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  326. package/lib/simple-tree/api/tree.js.map +1 -1
  327. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  328. package/lib/simple-tree/core/index.d.ts +1 -1
  329. package/lib/simple-tree/core/index.d.ts.map +1 -1
  330. package/lib/simple-tree/core/index.js +1 -1
  331. package/lib/simple-tree/core/index.js.map +1 -1
  332. package/lib/simple-tree/core/treeNodeKernel.d.ts +6 -2
  333. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  334. package/lib/simple-tree/core/treeNodeKernel.js +31 -1
  335. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  336. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
  337. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  338. package/lib/simple-tree/core/unhydratedFlexTree.js +1 -1
  339. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  340. package/lib/simple-tree/index.d.ts +1 -1
  341. package/lib/simple-tree/index.d.ts.map +1 -1
  342. package/lib/simple-tree/index.js +1 -1
  343. package/lib/simple-tree/index.js.map +1 -1
  344. package/lib/simple-tree/objectNode.d.ts +7 -2
  345. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  346. package/lib/simple-tree/objectNode.js.map +1 -1
  347. package/lib/simple-tree/toMapTree.js +5 -5
  348. package/lib/simple-tree/toMapTree.js.map +1 -1
  349. package/lib/util/index.d.ts +1 -2
  350. package/lib/util/index.d.ts.map +1 -1
  351. package/lib/util/index.js +1 -2
  352. package/lib/util/index.js.map +1 -1
  353. package/lib/util/typeCheck.d.ts +6 -1
  354. package/lib/util/typeCheck.d.ts.map +1 -1
  355. package/lib/util/typeCheck.js.map +1 -1
  356. package/lib/util/typeCheckTests.d.ts +14 -2
  357. package/lib/util/typeCheckTests.d.ts.map +1 -1
  358. package/lib/util/typeCheckTests.js.map +1 -1
  359. package/lib/util/utils.d.ts +29 -0
  360. package/lib/util/utils.d.ts.map +1 -1
  361. package/lib/util/utils.js +9 -0
  362. package/lib/util/utils.js.map +1 -1
  363. package/package.json +22 -22
  364. package/src/core/forest/forest.ts +12 -1
  365. package/src/core/index.ts +8 -1
  366. package/src/core/rebase/utils.ts +12 -10
  367. package/src/core/revertible.ts +35 -1
  368. package/src/core/schema-stored/storedSchemaRepository.ts +2 -1
  369. package/src/core/tree/anchorSet.ts +2 -1
  370. package/src/core/tree/detachedFieldIndexCodec.ts +4 -3
  371. package/src/core/tree/index.ts +1 -0
  372. package/src/core/tree/visitorUtils.ts +56 -1
  373. package/src/feature-libraries/chunked-forest/chunkedForest.ts +33 -7
  374. package/src/feature-libraries/chunked-forest/uniformChunk.ts +3 -3
  375. package/src/feature-libraries/flex-tree/context.ts +1 -1
  376. package/src/feature-libraries/index.ts +9 -0
  377. package/src/feature-libraries/indexing/anchorTreeIndex.ts +453 -0
  378. package/src/feature-libraries/indexing/index.ts +11 -0
  379. package/src/feature-libraries/indexing/types.ts +37 -0
  380. package/src/feature-libraries/object-forest/objectForest.ts +22 -4
  381. package/src/feature-libraries/sequence-field/invert.ts +4 -4
  382. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +4 -4
  383. package/src/index.ts +16 -6
  384. package/src/packageVersion.ts +1 -1
  385. package/src/shared-tree/index.ts +0 -2
  386. package/src/shared-tree/schematizingTreeView.ts +7 -7
  387. package/src/shared-tree/sharedTree.ts +60 -6
  388. package/src/shared-tree/sharedTreeChangeFamily.ts +5 -4
  389. package/src/shared-tree/treeCheckout.ts +186 -193
  390. package/src/shared-tree-core/branch.ts +93 -220
  391. package/src/shared-tree-core/branchCommitEnricher.ts +69 -64
  392. package/src/shared-tree-core/defaultResubmitMachine.ts +3 -2
  393. package/src/shared-tree-core/editManager.ts +1 -1
  394. package/src/shared-tree-core/index.ts +9 -2
  395. package/src/shared-tree-core/sharedTreeCore.ts +17 -62
  396. package/src/shared-tree-core/transaction.ts +165 -0
  397. package/src/shared-tree-core/transactionEnricher.ts +30 -24
  398. package/src/simple-tree/api/identifierIndex.ts +64 -0
  399. package/src/simple-tree/api/index.ts +5 -0
  400. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +17 -18
  401. package/src/simple-tree/api/simpleTreeIndex.ts +231 -0
  402. package/src/simple-tree/api/tree.ts +8 -5
  403. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  404. package/src/simple-tree/core/index.ts +1 -0
  405. package/src/simple-tree/core/treeNodeKernel.ts +37 -2
  406. package/src/simple-tree/core/unhydratedFlexTree.ts +2 -1
  407. package/src/simple-tree/index.ts +4 -0
  408. package/src/simple-tree/objectNode.ts +19 -12
  409. package/src/simple-tree/toMapTree.ts +5 -5
  410. package/src/util/index.ts +3 -1
  411. package/src/util/typeCheck.ts +6 -1
  412. package/src/util/typeCheckTests.ts +11 -1
  413. package/src/util/utils.ts +38 -0
  414. package/dist/events/emitter.d.ts +0 -139
  415. package/dist/events/emitter.d.ts.map +0 -1
  416. package/dist/events/emitter.js +0 -165
  417. package/dist/events/emitter.js.map +0 -1
  418. package/dist/events/index.d.ts +0 -7
  419. package/dist/events/index.d.ts.map +0 -1
  420. package/dist/events/index.js +0 -11
  421. package/dist/events/index.js.map +0 -1
  422. package/dist/events/interop.d.ts +0 -30
  423. package/dist/events/interop.d.ts.map +0 -1
  424. package/dist/events/interop.js.map +0 -1
  425. package/dist/events/listeners.d.ts +0 -76
  426. package/dist/events/listeners.d.ts.map +0 -1
  427. package/dist/events/listeners.js +0 -7
  428. package/dist/events/listeners.js.map +0 -1
  429. package/dist/shared-tree-core/transactionStack.d.ts +0 -29
  430. package/dist/shared-tree-core/transactionStack.d.ts.map +0 -1
  431. package/dist/shared-tree-core/transactionStack.js +0 -41
  432. package/dist/shared-tree-core/transactionStack.js.map +0 -1
  433. package/dist/util/transactionResult.d.ts +0 -19
  434. package/dist/util/transactionResult.d.ts.map +0 -1
  435. package/dist/util/transactionResult.js +0 -23
  436. package/dist/util/transactionResult.js.map +0 -1
  437. package/lib/events/emitter.d.ts +0 -139
  438. package/lib/events/emitter.d.ts.map +0 -1
  439. package/lib/events/emitter.js +0 -160
  440. package/lib/events/emitter.js.map +0 -1
  441. package/lib/events/index.d.ts +0 -7
  442. package/lib/events/index.d.ts.map +0 -1
  443. package/lib/events/index.js.map +0 -1
  444. package/lib/events/interop.d.ts +0 -30
  445. package/lib/events/interop.d.ts.map +0 -1
  446. package/lib/events/interop.js.map +0 -1
  447. package/lib/events/listeners.d.ts +0 -76
  448. package/lib/events/listeners.d.ts.map +0 -1
  449. package/lib/events/listeners.js +0 -6
  450. package/lib/events/listeners.js.map +0 -1
  451. package/lib/shared-tree-core/transactionStack.d.ts +0 -29
  452. package/lib/shared-tree-core/transactionStack.d.ts.map +0 -1
  453. package/lib/shared-tree-core/transactionStack.js +0 -37
  454. package/lib/shared-tree-core/transactionStack.js.map +0 -1
  455. package/lib/util/transactionResult.d.ts +0 -19
  456. package/lib/util/transactionResult.d.ts.map +0 -1
  457. package/lib/util/transactionResult.js +0 -20
  458. package/lib/util/transactionResult.js.map +0 -1
  459. package/src/events/README.md +0 -3
  460. package/src/events/emitter.ts +0 -256
  461. package/src/events/index.ts +0 -19
  462. package/src/events/interop.ts +0 -38
  463. package/src/events/listeners.ts +0 -80
  464. package/src/shared-tree-core/transactionStack.ts +0 -45
  465. package/src/util/transactionResult.ts +0 -19
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import { type TelemetryEventBatcher } from "@fluidframework/telemetry-utils/internal";
6
6
  import { type BranchRebaseResult, type ChangeFamily, type ChangeFamilyEditor, CommitKind, type GraphCommit, type RevisionTag, type TaggedChange, type RebaseStatsWithDuration } from "../core/index.js";
7
- import { type Listenable } from "../events/index.js";
7
+ import type { Listenable } from "@fluidframework/core-interfaces";
8
8
  /**
9
9
  * Describes a change to a `SharedTreeBranch`. Various operations can mutate the head of the branch;
10
10
  * this change format describes each in terms of the "removed commits" (all commits which were present
@@ -24,11 +24,11 @@ export type SharedTreeBranchChange<TChange> = {
24
24
  type: "append";
25
25
  kind: CommitKind;
26
26
  change: TaggedChange<TChange>;
27
- newCommits: readonly GraphCommit<TChange>[];
27
+ newCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];
28
28
  } | {
29
29
  type: "remove";
30
30
  change: TaggedChange<TChange> | undefined;
31
- removedCommits: readonly GraphCommit<TChange>[];
31
+ removedCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];
32
32
  } | {
33
33
  type: "replace";
34
34
  change: TaggedChange<TChange> | undefined;
@@ -64,30 +64,6 @@ export interface SharedTreeBranchEvents<TEditor extends ChangeFamilyEditor, TCha
64
64
  * Fired after this branch is disposed
65
65
  */
66
66
  dispose(): void;
67
- /**
68
- * Fired after a new transaction is started.
69
- * @param isOuterTransaction - true iff the transaction being started is the outermost transaction
70
- * as opposed to a nested transaction.
71
- */
72
- transactionStarted(isOuterTransaction: boolean): void;
73
- /**
74
- * Fired after the current transaction is aborted.
75
- * @param isOuterTransaction - true iff the transaction being aborted is the outermost transaction
76
- * as opposed to a nested transaction.
77
- */
78
- transactionAborted(isOuterTransaction: boolean): void;
79
- /**
80
- * Fired after the current transaction is completely rolled back.
81
- * @param isOuterTransaction - true iff the transaction being aborted is the outermost transaction
82
- * as opposed to a nested transaction.
83
- */
84
- transactionRolledBack(isOuterTransaction: boolean): void;
85
- /**
86
- * Fired after the current transaction is committed.
87
- * @param isOuterTransaction - true iff the transaction being committed is the outermost transaction
88
- * as opposed to a nested transaction.
89
- */
90
- transactionCommitted(isOuterTransaction: boolean): void;
91
67
  }
92
68
  /**
93
69
  * Events related to branch trimming.
@@ -117,30 +93,6 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
117
93
  private readonly telemetryEventBatcher?;
118
94
  readonly events: Listenable<SharedTreeBranchEvents<TEditor, TChange>>;
119
95
  readonly editor: TEditor;
120
- private readonly transactions;
121
- /**
122
- * After pushing a starting revision to the transaction stack, this branch might be rebased
123
- * over commits which are children of that starting revision. When the transaction is committed,
124
- * those rebased-over commits should not be included in the transaction's squash commit, even though
125
- * they exist between the starting revision and the final commit within the transaction.
126
- *
127
- * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the
128
- * original merge-base to the new merge-base.
129
- *
130
- * This state need only be retained for the lifetime of the transaction.
131
- *
132
- * TODO: This strategy might need to be revisited when adding better support for async transactions.
133
- * Since:
134
- *
135
- * 1. Transactionality is guaranteed primarily by squashing at commit time
136
- * 2. Branches may be rebased with an ongoing transaction
137
- *
138
- * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the
139
- * purpose of transactionality.
140
- *
141
- * AB#6483 and children items track this work.
142
- */
143
- private readonly initialTransactionRevToRebasedRev;
144
96
  private disposed;
145
97
  private readonly unsubscribeBranchTrimmer?;
146
98
  /**
@@ -152,7 +104,9 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
152
104
  */
153
105
  constructor(head: GraphCommit<TChange>, changeFamily: ChangeFamily<TEditor, TChange>, mintRevisionTag: () => RevisionTag, branchTrimmer?: Listenable<BranchTrimmingEvents> | undefined, telemetryEventBatcher?: TelemetryEventBatcher<keyof RebaseStatsWithDuration> | undefined);
154
106
  /**
155
- * Sets the head of this branch. Emits no change events.
107
+ * Sets the head of this branch.
108
+ * @remarks This is a "manual override" of sorts, for when the branch needs to be set to a certain state without going through the usual flow of edits.
109
+ * This might be necessary as a performance optimization, or to prevent parts of the system updating incorrectly (this method emits no change events!).
156
110
  */
157
111
  setHead(head: GraphCommit<TChange>): void;
158
112
  /**
@@ -166,34 +120,6 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
166
120
  * @returns the commit at the head of this branch.
167
121
  */
168
122
  getHead(): GraphCommit<TChange>;
169
- /**
170
- * Begin a transaction on this branch. If the transaction is committed via {@link commitTransaction},
171
- * all commits made since this call will be squashed into a single head commit.
172
- */
173
- startTransaction(): void;
174
- /**
175
- * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.
176
- * If there are commits in the current transaction, they will be squashed into a new single head commit.
177
- * @returns the commits that were squashed and the new squash commit if a squash occurred, otherwise `undefined`.
178
- * @remarks If the transaction had no changes applied during its lifetime, then no squash occurs (i.e. this method is a no-op).
179
- * Even if the transaction contained only one change, it will still be replaced with an (equivalent) squash change.
180
- */
181
- commitTransaction(): [squashedCommits: GraphCommit<TChange>[], newCommit: GraphCommit<TChange>] | undefined;
182
- /**
183
- * Cancel the current transaction. There must be a transaction in progress that was begun via
184
- * {@link startTransaction}. All commits made during the transaction will be removed.
185
- * @returns the change to this branch resulting in the removal of the commits, and a list of the
186
- * commits that were removed.
187
- */
188
- abortTransaction(): [
189
- change: TChange | undefined,
190
- abortedCommits: GraphCommit<TChange>[]
191
- ];
192
- /**
193
- * True iff this branch is in the middle of a transaction that was begin via {@link startTransaction}
194
- */
195
- isTransacting(): boolean;
196
- private popTransaction;
197
123
  /**
198
124
  * Spawn a new branch that is based off of the current state of this branch.
199
125
  * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.
@@ -210,6 +136,20 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
210
136
  * @returns the result of the rebase or undefined if nothing changed
211
137
  */
212
138
  rebaseOnto(branch: SharedTreeBranch<TEditor, TChange>, upTo?: GraphCommit<TChange>): BranchRebaseResult<TChange> | undefined;
139
+ /**
140
+ * Remove a range of commits from this branch.
141
+ * @param commit - All commits after (but not including) this commit will be removed.
142
+ * @returns The net change to this branch and the commits that were removed from this branch.
143
+ */
144
+ removeAfter(commit: GraphCommit<TChange>): [change: TaggedChange<TChange> | undefined, removedCommits: GraphCommit<TChange>[]];
145
+ /**
146
+ * Replace a range of commits on this branch with a single commit composed of equivalent changes.
147
+ * @param commit - All commits after (but not including) this commit will be squashed.
148
+ * @returns The commits that were squashed and removed from this branch.
149
+ * @remarks The commits after `commit` will be removed from this branch, and the squash commit will become the new head of this branch.
150
+ * The change event emitted by this operation will have a `change` property that is undefined, since no net change occurred.
151
+ */
152
+ squashAfter(commit: GraphCommit<TChange>): GraphCommit<TChange>[];
213
153
  /**
214
154
  * Apply all the divergent changes on the given branch to this branch.
215
155
  *
@@ -239,5 +179,9 @@ export declare class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChang
239
179
  * @returns a function which when called will deregister all registrations (including transitive) created by this function.
240
180
  * The deregister function has undefined behavior if called more than once.
241
181
  */
242
- export declare function onForkTransitive<T extends SharedTreeBranch<ChangeFamilyEditor, any>>(branch: T, onFork: (fork: T) => void): () => void;
182
+ export declare function onForkTransitive<T extends {
183
+ events: Listenable<{
184
+ fork(t: T): void;
185
+ }>;
186
+ }>(branch: T, onFork: (fork: T) => void): () => void;
243
187
  //# sourceMappingURL=branch.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"branch.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,qBAAqB,EAAW,MAAM,0CAA0C,CAAC;AAE/F,OAAO,EACN,KAAK,kBAAkB,EACvB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,UAAU,EACV,KAAK,WAAW,EAChB,KAAK,WAAW,EAChB,KAAK,YAAY,EAMjB,KAAK,uBAAuB,EAC5B,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAKpE;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,sBAAsB,CAAC,OAAO,IACvC;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,IAAI,EAAE,UAAU,CAAC;IACjB,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC9B,UAAU,EAAE,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;CAC3C,GACD;IACA,IAAI,EAAE,QAAQ,CAAC;IACf,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC1C,cAAc,EAAE,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;CAC/C,GACD;IACA,IAAI,EAAE,SAAS,CAAC;IAChB,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IAC1C,cAAc,EAAE,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAChD,UAAU,EAAE,SAAS,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;CAC3C,CAAC;AAEL;;GAEG;AACH,wBAAgB,oBAAoB,CACnC,MAAM,EAAE,sBAAsB,CAAC,OAAO,CA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O,EAAE,OAAO,CAAC;IAYzF;;;;;;;OAOG;IACI,UAAU,CAChB,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,EAC1C,IAAI,uBAAmB,GACrB,kBAAkB,CAAC,OAAO,CAAC,GAAG,SAAS;IA+B1C;;;;OAIG;IACI,WAAW,CACjB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAC1B,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,SAAS,EAAE,cAAc,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC;IAsCtF;;;;;;OAMG;IACI,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC,EAAE;IA6BxE;;;;;;OAMG;IACI,KAAK,CACX,MAAM,EAAE,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,GACxC,CAAC,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,SAAS;IAkCpE,+EAA+E;IAC/E,OAAO,CAAC,YAAY;IA6BpB;;;;;;;OAOG;IACI,OAAO,IAAI,IAAI;IAWtB,OAAO,CAAC,iBAAiB;CAGzB;AAED;;;;;;;GAOG;AAEH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS;IAAE,MAAM,EAAE,UAAU,CAAC;QAAE,IAAI,CAAC,CAAC,EAAE,CAAC,GAAG,IAAI,CAAA;KAAE,CAAC,CAAA;CAAE,EACtF,MAAM,EAAE,CAAC,EACT,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,GACvB,MAAM,IAAI,CASZ"}
@@ -8,12 +8,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
8
8
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
9
9
  };
10
10
  var _SharedTreeBranch_events;
11
- import { assert, oob } from "@fluidframework/core-utils/internal";
11
+ import { assert } from "@fluidframework/core-utils/internal";
12
12
  import { measure } from "@fluidframework/telemetry-utils/internal";
13
13
  import { CommitKind, findAncestor, makeAnonChange, mintCommit, rebaseBranch, tagRollbackInverse, } from "../core/index.js";
14
- import { createEmitter } from "../events/index.js";
15
- import { TransactionStack } from "./transactionStack.js";
16
- import { fail } from "../util/index.js";
14
+ import { createEmitter } from "@fluid-internal/client-utils";
15
+ import { hasSome } from "../util/index.js";
17
16
  /**
18
17
  * Returns the operation that caused the given {@link SharedTreeBranchChange}.
19
18
  */
@@ -58,30 +57,6 @@ export class SharedTreeBranch {
58
57
  this.telemetryEventBatcher = telemetryEventBatcher;
59
58
  _SharedTreeBranch_events.set(this, createEmitter());
60
59
  this.events = __classPrivateFieldGet(this, _SharedTreeBranch_events, "f");
61
- this.transactions = new TransactionStack();
62
- /**
63
- * After pushing a starting revision to the transaction stack, this branch might be rebased
64
- * over commits which are children of that starting revision. When the transaction is committed,
65
- * those rebased-over commits should not be included in the transaction's squash commit, even though
66
- * they exist between the starting revision and the final commit within the transaction.
67
- *
68
- * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the
69
- * original merge-base to the new merge-base.
70
- *
71
- * This state need only be retained for the lifetime of the transaction.
72
- *
73
- * TODO: This strategy might need to be revisited when adding better support for async transactions.
74
- * Since:
75
- *
76
- * 1. Transactionality is guaranteed primarily by squashing at commit time
77
- * 2. Branches may be rebased with an ongoing transaction
78
- *
79
- * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the
80
- * purpose of transactionality.
81
- *
82
- * AB#6483 and children items track this work.
83
- */
84
- this.initialTransactionRevToRebasedRev = new Map();
85
60
  this.disposed = false;
86
61
  this.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) => this.apply(change));
87
62
  this.unsubscribeBranchTrimmer = branchTrimmer?.on("ancestryTrimmed", (commit) => {
@@ -89,11 +64,12 @@ export class SharedTreeBranch {
89
64
  });
90
65
  }
91
66
  /**
92
- * Sets the head of this branch. Emits no change events.
67
+ * Sets the head of this branch.
68
+ * @remarks This is a "manual override" of sorts, for when the branch needs to be set to a certain state without going through the usual flow of edits.
69
+ * This might be necessary as a performance optimization, or to prevent parts of the system updating incorrectly (this method emits no change events!).
93
70
  */
94
71
  setHead(head) {
95
72
  this.assertNotDisposed();
96
- assert(!this.isTransacting(), 0x685 /* Cannot set head during a transaction */);
97
73
  this.head = head;
98
74
  }
99
75
  /**
@@ -127,113 +103,6 @@ export class SharedTreeBranch {
127
103
  getHead() {
128
104
  return this.head;
129
105
  }
130
- /**
131
- * Begin a transaction on this branch. If the transaction is committed via {@link commitTransaction},
132
- * all commits made since this call will be squashed into a single head commit.
133
- */
134
- startTransaction() {
135
- this.assertNotDisposed();
136
- const forks = new Set();
137
- const onDisposeUnSubscribes = [];
138
- const onForkUnSubscribe = onForkTransitive(this, (fork) => {
139
- forks.add(fork);
140
- onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
141
- });
142
- this.transactions.push(this.head.revision, () => {
143
- forks.forEach((fork) => fork.dispose());
144
- onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
145
- onForkUnSubscribe();
146
- });
147
- this.editor.enterTransaction();
148
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionStarted", this.transactions.size === 1);
149
- }
150
- /**
151
- * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.
152
- * If there are commits in the current transaction, they will be squashed into a new single head commit.
153
- * @returns the commits that were squashed and the new squash commit if a squash occurred, otherwise `undefined`.
154
- * @remarks If the transaction had no changes applied during its lifetime, then no squash occurs (i.e. this method is a no-op).
155
- * Even if the transaction contained only one change, it will still be replaced with an (equivalent) squash change.
156
- */
157
- commitTransaction() {
158
- this.assertNotDisposed();
159
- const [startCommit, commits] = this.popTransaction();
160
- this.editor.exitTransaction();
161
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionCommitted", this.transactions.size === 0);
162
- if (commits.length === 0) {
163
- return undefined;
164
- }
165
- // Squash the changes and make the squash commit the new head of this branch
166
- const squashedChange = this.changeFamily.rebaser.compose(commits);
167
- const revision = this.mintRevisionTag();
168
- const newHead = mintCommit(startCommit, {
169
- revision,
170
- change: this.changeFamily.rebaser.changeRevision(squashedChange, revision),
171
- });
172
- const changeEvent = {
173
- type: "replace",
174
- change: undefined,
175
- removedCommits: commits,
176
- newCommits: [newHead],
177
- };
178
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
179
- this.head = newHead;
180
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
181
- return [commits, newHead];
182
- }
183
- /**
184
- * Cancel the current transaction. There must be a transaction in progress that was begun via
185
- * {@link startTransaction}. All commits made during the transaction will be removed.
186
- * @returns the change to this branch resulting in the removal of the commits, and a list of the
187
- * commits that were removed.
188
- */
189
- abortTransaction() {
190
- this.assertNotDisposed();
191
- const [startCommit, commits] = this.popTransaction();
192
- this.editor.exitTransaction();
193
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionAborted", this.transactions.size === 0);
194
- if (commits.length === 0) {
195
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionRolledBack", this.transactions.size === 0);
196
- return [undefined, []];
197
- }
198
- const inverses = [];
199
- for (let i = commits.length - 1; i >= 0; i--) {
200
- const revision = this.mintRevisionTag();
201
- const commit = commits[i] ?? fail("This wont run because we are iterating through commits");
202
- const inverse = this.changeFamily.rebaser.changeRevision(this.changeFamily.rebaser.invert(commit, true, revision), revision, commit.revision);
203
- inverses.push(tagRollbackInverse(inverse, revision, commit.revision));
204
- }
205
- const change = inverses.length > 0 ? this.changeFamily.rebaser.compose(inverses) : undefined;
206
- const changeEvent = {
207
- type: "remove",
208
- change: change === undefined ? undefined : makeAnonChange(change),
209
- removedCommits: commits,
210
- };
211
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
212
- this.head = startCommit;
213
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
214
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionRolledBack", this.transactions.size === 0);
215
- return [change, commits];
216
- }
217
- /**
218
- * True iff this branch is in the middle of a transaction that was begin via {@link startTransaction}
219
- */
220
- isTransacting() {
221
- return this.transactions.size !== 0;
222
- }
223
- popTransaction() {
224
- const { startRevision: startRevisionOriginal } = this.transactions.pop();
225
- let startRevision = startRevisionOriginal;
226
- while (this.initialTransactionRevToRebasedRev.has(startRevision)) {
227
- startRevision = this.initialTransactionRevToRebasedRev.get(startRevision) ?? oob();
228
- }
229
- if (!this.isTransacting()) {
230
- this.initialTransactionRevToRebasedRev.clear();
231
- }
232
- const commits = [];
233
- const startCommit = findAncestor([this.head, commits], (c) => c.revision === startRevision);
234
- assert(startCommit !== undefined, 0x593 /* Expected branch to be ahead of transaction start revision */);
235
- return [startCommit, commits];
236
- }
237
106
  /**
238
107
  * Spawn a new branch that is based off of the current state of this branch.
239
108
  * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.
@@ -264,16 +133,8 @@ export class SharedTreeBranch {
264
133
  // The net change to this branch is provided by the `rebaseBranch` API
265
134
  const { newSourceHead, commits } = rebaseResult;
266
135
  const { deletedSourceCommits, targetCommits, sourceCommits } = commits;
136
+ assert(hasSome(targetCommits), 0xa83 /* Expected commit(s) for a non no-op rebase */);
267
137
  const newCommits = targetCommits.concat(sourceCommits);
268
- if (this.isTransacting()) {
269
- const firstCommit = targetCommits[0] ?? oob();
270
- const lastCommit = targetCommits[targetCommits.length - 1] ?? oob();
271
- const src = firstCommit.parent?.revision;
272
- const dst = lastCommit.revision;
273
- if (src !== undefined && dst !== undefined) {
274
- this.initialTransactionRevToRebasedRev.set(src, dst);
275
- }
276
- }
277
138
  const changeEvent = {
278
139
  type: "replace",
279
140
  get change() {
@@ -288,6 +149,70 @@ export class SharedTreeBranch {
288
149
  __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
289
150
  return rebaseResult;
290
151
  }
152
+ /**
153
+ * Remove a range of commits from this branch.
154
+ * @param commit - All commits after (but not including) this commit will be removed.
155
+ * @returns The net change to this branch and the commits that were removed from this branch.
156
+ */
157
+ removeAfter(commit) {
158
+ if (commit === this.head) {
159
+ return [undefined, []];
160
+ }
161
+ const removedCommits = [];
162
+ const inverses = [];
163
+ findAncestor([this.head, removedCommits], (c) => {
164
+ // TODO: Pull this side effect out if/when more diverse ancestry walking helpers are available
165
+ if (c !== commit) {
166
+ const revision = this.mintRevisionTag();
167
+ const inverse = this.changeFamily.rebaser.changeRevision(this.changeFamily.rebaser.invert(c, true, revision), revision, c.revision);
168
+ inverses.push(tagRollbackInverse(inverse, revision, c.revision));
169
+ return false;
170
+ }
171
+ return true;
172
+ });
173
+ assert(hasSome(removedCommits), 0xa84 /* Commit must be in the branch's ancestry */);
174
+ const change = makeAnonChange(this.changeFamily.rebaser.compose(inverses));
175
+ const changeEvent = {
176
+ type: "remove",
177
+ change,
178
+ removedCommits,
179
+ };
180
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
181
+ this.head = commit;
182
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
183
+ return [change, removedCommits];
184
+ }
185
+ /**
186
+ * Replace a range of commits on this branch with a single commit composed of equivalent changes.
187
+ * @param commit - All commits after (but not including) this commit will be squashed.
188
+ * @returns The commits that were squashed and removed from this branch.
189
+ * @remarks The commits after `commit` will be removed from this branch, and the squash commit will become the new head of this branch.
190
+ * The change event emitted by this operation will have a `change` property that is undefined, since no net change occurred.
191
+ */
192
+ squashAfter(commit) {
193
+ if (commit === this.head) {
194
+ return [];
195
+ }
196
+ const removedCommits = [];
197
+ findAncestor([this.head, removedCommits], (c) => c === commit);
198
+ assert(hasSome(removedCommits), 0xa85 /* Commit must be in the branch's ancestry */);
199
+ const squashedChange = this.changeFamily.rebaser.compose(removedCommits);
200
+ const revision = this.mintRevisionTag();
201
+ const newHead = mintCommit(commit, {
202
+ revision,
203
+ change: this.changeFamily.rebaser.changeRevision(squashedChange, revision),
204
+ });
205
+ const changeEvent = {
206
+ type: "replace",
207
+ change: undefined,
208
+ removedCommits,
209
+ newCommits: [newHead],
210
+ };
211
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
212
+ this.head = newHead;
213
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
214
+ return removedCommits;
215
+ }
291
216
  /**
292
217
  * Apply all the divergent changes on the given branch to this branch.
293
218
  *
@@ -298,7 +223,6 @@ export class SharedTreeBranch {
298
223
  merge(branch) {
299
224
  this.assertNotDisposed();
300
225
  branch.assertNotDisposed();
301
- assert(!branch.isTransacting(), 0x597 /* Branch may not be merged while transaction is in progress */);
302
226
  if (branch === this) {
303
227
  return undefined;
304
228
  }
@@ -309,6 +233,7 @@ export class SharedTreeBranch {
309
233
  }
310
234
  // Compute the net change to this branch
311
235
  const sourceCommits = rebaseResult.commits.sourceCommits;
236
+ assert(hasSome(sourceCommits), 0xa86 /* Expected source commits in non no-op merge */);
312
237
  const change = this.changeFamily.rebaser.compose(sourceCommits);
313
238
  const taggedChange = makeAnonChange(change);
314
239
  const changeEvent = {
@@ -349,9 +274,6 @@ export class SharedTreeBranch {
349
274
  if (this.disposed) {
350
275
  return;
351
276
  }
352
- while (this.isTransacting()) {
353
- this.abortTransaction();
354
- }
355
277
  this.unsubscribeBranchTrimmer?.();
356
278
  this.disposed = true;
357
279
  __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("dispose");
@@ -370,7 +292,6 @@ _SharedTreeBranch_events = new WeakMap();
370
292
  * The deregister function has undefined behavior if called more than once.
371
293
  */
372
294
  // Branches are invariant over TChange
373
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
374
295
  export function onForkTransitive(branch, onFork) {
375
296
  const offs = [];
376
297
  offs.push(branch.events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,UAAU,gBAAgB,CAC/B,MAAS,EACT,MAAyB;IAEzB,MAAM,IAAI,GAAmB,EAAE,CAAC;IAChC,IAAI,CAAC,IAAI,CACR,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAO,EAAE,EAAE;QACpC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC,CAAC,CACF,CAAC;IACF,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport { type TelemetryEventBatcher, measure } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype BranchRebaseResult,\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tCommitKind,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\ttype TaggedChange,\n\tfindAncestor,\n\tmakeAnonChange,\n\tmintCommit,\n\trebaseBranch,\n\ttagRollbackInverse,\n\ttype RebaseStatsWithDuration,\n} from \"../core/index.js\";\nimport { createEmitter, type Listenable } from \"../events/index.js\";\n\nimport { TransactionStack } from \"./transactionStack.js\";\nimport { fail } from \"../util/index.js\";\n\n/**\n * Describes a change to a `SharedTreeBranch`. Various operations can mutate the head of the branch;\n * this change format describes each in terms of the \"removed commits\" (all commits which were present\n * on the branch before the operation but are no longer present after) and the \"new commits\" (all\n * commits which are present on the branch after the operation that were not present before). Each of\n * the following event types also provides a `change` which contains the net change to the branch\n * (or is undefined if there was no net change):\n * * Append - when one or more commits are appended to the head of the branch, for example via\n * a change applied by the branch's editor, or as a result of merging another branch into this one\n * * Remove - when one or more commits are removed from the head of the branch. This occurs\n * when a transaction is aborted and all commits pending in that transaction are removed.\n * * Replace - when an operation simultaneously removes and appends commits. For example, when this\n * branch is rebased and some commits are removed and replaced with rebased versions, or when a\n * transaction completes and all pending commits are replaced with a single squash commit.\n */\nexport type SharedTreeBranchChange<TChange> =\n\t| {\n\t\t\ttype: \"append\";\n\t\t\tkind: CommitKind;\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t }\n\t| {\n\t\t\ttype: \"remove\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t }\n\t| {\n\t\t\ttype: \"replace\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t };\n\n/**\n * Returns the operation that caused the given {@link SharedTreeBranchChange}.\n */\nexport function getChangeReplaceType(\n\tchange: SharedTreeBranchChange<unknown> & { type: \"replace\" },\n): \"transactionCommit\" | \"rebase\" {\n\t// The \"replace\" variant of the change event is emitted by two operations: committing a transaction and doing a rebase.\n\t// Committing a transaction will always remove one or more commits (the commits that were squashed),\n\t// and will add exactly one new commit (the squash commit).\n\tif (change.removedCommits.length === 0 || change.newCommits.length !== 1) {\n\t\treturn \"rebase\";\n\t}\n\n\t// There is only one case in which a rebase both removes commits and adds exactly one new commit.\n\t// This occurs when there is exactly one divergent, but equivalent, commit on each branch:\n\t//\n\t// A ─ B (branch X)\t -- rebase Y onto X --> A ─ B (branch X)\n\t// └─ B' (branch Y) └─ (branch Y)\n\t//\n\t// B' is removed and replaced by B because both have the same revision.\n\tassert(\n\t\tchange.removedCommits[0] !== undefined,\n\t\t0x9e4 /* This wont run due to the length check above */,\n\t);\n\tassert(\n\t\tchange.newCommits[0] !== undefined,\n\t\t0x9e5 /* This wont run because a replace operation always has new commits */,\n\t);\n\tif (\n\t\tchange.removedCommits.length === 1 &&\n\t\tchange.removedCommits[0].revision === change.newCommits[0].revision\n\t) {\n\t\treturn \"rebase\";\n\t}\n\n\treturn \"transactionCommit\";\n}\n\n/**\n * The events emitted by a `SharedTreeBranch`\n */\nexport interface SharedTreeBranchEvents<TEditor extends ChangeFamilyEditor, TChange>\n\textends BranchTrimmingEvents {\n\t/**\n\t * Fired just before the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tbeforeChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired just after the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tafterChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired when this branch forks\n\t * @param fork - the new branch that forked off of this branch\n\t */\n\tfork(fork: SharedTreeBranch<TEditor, TChange>): void;\n\n\t/**\n\t * Fired after this branch is disposed\n\t */\n\tdispose(): void;\n\n\t/**\n\t * Fired after a new transaction is started.\n\t * @param isOuterTransaction - true iff the transaction being started is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionStarted(isOuterTransaction: boolean): void;\n\n\t/**\n\t * Fired after the current transaction is aborted.\n\t * @param isOuterTransaction - true iff the transaction being aborted is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionAborted(isOuterTransaction: boolean): void;\n\n\t/**\n\t * Fired after the current transaction is completely rolled back.\n\t * @param isOuterTransaction - true iff the transaction being aborted is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionRolledBack(isOuterTransaction: boolean): void;\n\n\t/**\n\t * Fired after the current transaction is committed.\n\t * @param isOuterTransaction - true iff the transaction being committed is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionCommitted(isOuterTransaction: boolean): void;\n}\n\n/**\n * Events related to branch trimming.\n *\n * @remarks\n * Trimming is a very specific kind of mutation which is the only allowed mutations to branches.\n * References to commits from other commits are removed so that the commit objects can be GC'd by the JS engine.\n * This happens by changing a commit's parent property to undefined, which drops all commits that are in its \"ancestry\".\n * It is done as a performance optimization when it is determined that commits are no longer needed for future computation.\n */\nexport interface BranchTrimmingEvents {\n\t/**\n\t * Fired when some contiguous range of commits beginning with the \"global tail\" of this branch are trimmed from the branch.\n\t * This happens by deleting the parent pointer to the last commit in that range. This event can be fired at any time.\n\t */\n\tancestryTrimmed(trimmedRevisions: RevisionTag[]): void;\n}\n\n/**\n * A branch of changes that can be applied to a SharedTree.\n */\nexport class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChange> {\n\treadonly #events = createEmitter<SharedTreeBranchEvents<TEditor, TChange>>();\n\tpublic readonly events: Listenable<SharedTreeBranchEvents<TEditor, TChange>> = this.#events;\n\tpublic readonly editor: TEditor;\n\tprivate readonly transactions = new TransactionStack();\n\t/**\n\t * After pushing a starting revision to the transaction stack, this branch might be rebased\n\t * over commits which are children of that starting revision. When the transaction is committed,\n\t * those rebased-over commits should not be included in the transaction's squash commit, even though\n\t * they exist between the starting revision and the final commit within the transaction.\n\t *\n\t * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the\n\t * original merge-base to the new merge-base.\n\t *\n\t * This state need only be retained for the lifetime of the transaction.\n\t *\n\t * TODO: This strategy might need to be revisited when adding better support for async transactions.\n\t * Since:\n\t *\n\t * 1. Transactionality is guaranteed primarily by squashing at commit time\n\t * 2. Branches may be rebased with an ongoing transaction\n\t *\n\t * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the\n\t * purpose of transactionality.\n\t *\n\t * AB#6483 and children items track this work.\n\t */\n\tprivate readonly initialTransactionRevToRebasedRev = new Map<RevisionTag, RevisionTag>();\n\tprivate disposed = false;\n\tprivate readonly unsubscribeBranchTrimmer?: () => void;\n\t/**\n\t * Construct a new branch.\n\t * @param head - the head of the branch\n\t * @param changeFamily - determines the set of changes that this branch can commit\n\t * @param branchTrimmer - an optional event emitter that informs the branch it has been trimmed. If this is not supplied, then the branch must\n\t * never be trimmed. See {@link BranchTrimmingEvents} for details on trimming.\n\t */\n\tpublic constructor(\n\t\tprivate head: GraphCommit<TChange>,\n\t\tpublic readonly changeFamily: ChangeFamily<TEditor, TChange>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly branchTrimmer?: Listenable<BranchTrimmingEvents>,\n\t\tprivate readonly telemetryEventBatcher?: TelemetryEventBatcher<\n\t\t\tkeyof RebaseStatsWithDuration\n\t\t>,\n\t) {\n\t\tthis.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) =>\n\t\t\tthis.apply(change),\n\t\t);\n\t\tthis.unsubscribeBranchTrimmer = branchTrimmer?.on(\"ancestryTrimmed\", (commit) => {\n\t\t\tthis.#events.emit(\"ancestryTrimmed\", commit);\n\t\t});\n\t}\n\n\t/**\n\t * Sets the head of this branch. Emits no change events.\n\t */\n\tpublic setHead(head: GraphCommit<TChange>): void {\n\t\tthis.assertNotDisposed();\n\t\tassert(!this.isTransacting(), 0x685 /* Cannot set head during a transaction */);\n\t\tthis.head = head;\n\t}\n\n\t/**\n\t * Apply a change to this branch.\n\t * @param taggedChange - the change to apply\n\t * @param kind - the kind of change to apply\n\t * @returns the change that was applied and the new head commit of the branch\n\t */\n\tpublic apply(\n\t\ttaggedChange: TaggedChange<TChange>,\n\t\tkind: CommitKind = CommitKind.Default,\n\t): [change: TChange, newCommit: GraphCommit<TChange>] {\n\t\tthis.assertNotDisposed();\n\n\t\tconst revisionTag = taggedChange.revision;\n\t\tassert(revisionTag !== undefined, 0xa49 /* Revision tag must be provided */);\n\n\t\tconst newHead = mintCommit(this.head, {\n\t\t\trevision: revisionTag,\n\t\t\tchange: taggedChange.change,\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tkind,\n\t\t\tchange: taggedChange,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn [taggedChange.change, newHead];\n\t}\n\n\t/**\n\t * @returns the commit at the head of this branch.\n\t */\n\tpublic getHead(): GraphCommit<TChange> {\n\t\treturn this.head;\n\t}\n\n\t/**\n\t * Begin a transaction on this branch. If the transaction is committed via {@link commitTransaction},\n\t * all commits made since this call will be squashed into a single head commit.\n\t */\n\tpublic startTransaction(): void {\n\t\tthis.assertNotDisposed();\n\t\tconst forks = new Set<SharedTreeBranch<TEditor, TChange>>();\n\t\tconst onDisposeUnSubscribes: (() => void)[] = [];\n\t\tconst onForkUnSubscribe = onForkTransitive(this, (fork) => {\n\t\t\tforks.add(fork);\n\t\t\tonDisposeUnSubscribes.push(fork.events.on(\"dispose\", () => forks.delete(fork)));\n\t\t});\n\t\tthis.transactions.push(this.head.revision, () => {\n\t\t\tforks.forEach((fork) => fork.dispose());\n\t\t\tonDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());\n\t\t\tonForkUnSubscribe();\n\t\t});\n\t\tthis.editor.enterTransaction();\n\t\tthis.#events.emit(\"transactionStarted\", this.transactions.size === 1);\n\t}\n\n\t/**\n\t * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.\n\t * If there are commits in the current transaction, they will be squashed into a new single head commit.\n\t * @returns the commits that were squashed and the new squash commit if a squash occurred, otherwise `undefined`.\n\t * @remarks If the transaction had no changes applied during its lifetime, then no squash occurs (i.e. this method is a no-op).\n\t * Even if the transaction contained only one change, it will still be replaced with an (equivalent) squash change.\n\t */\n\tpublic commitTransaction():\n\t\t| [squashedCommits: GraphCommit<TChange>[], newCommit: GraphCommit<TChange>]\n\t\t| undefined {\n\t\tthis.assertNotDisposed();\n\t\tconst [startCommit, commits] = this.popTransaction();\n\t\tthis.editor.exitTransaction();\n\n\t\tthis.#events.emit(\"transactionCommitted\", this.transactions.size === 0);\n\t\tif (commits.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Squash the changes and make the squash commit the new head of this branch\n\t\tconst squashedChange = this.changeFamily.rebaser.compose(commits);\n\t\tconst revision = this.mintRevisionTag();\n\n\t\tconst newHead = mintCommit(startCommit, {\n\t\t\trevision,\n\t\t\tchange: this.changeFamily.rebaser.changeRevision(squashedChange, revision),\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tchange: undefined,\n\t\t\tremovedCommits: commits,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn [commits, newHead];\n\t}\n\n\t/**\n\t * Cancel the current transaction. There must be a transaction in progress that was begun via\n\t * {@link startTransaction}. All commits made during the transaction will be removed.\n\t * @returns the change to this branch resulting in the removal of the commits, and a list of the\n\t * commits that were removed.\n\t */\n\tpublic abortTransaction(): [\n\t\tchange: TChange | undefined,\n\t\tabortedCommits: GraphCommit<TChange>[],\n\t] {\n\t\tthis.assertNotDisposed();\n\t\tconst [startCommit, commits] = this.popTransaction();\n\t\tthis.editor.exitTransaction();\n\n\t\tthis.#events.emit(\"transactionAborted\", this.transactions.size === 0);\n\t\tif (commits.length === 0) {\n\t\t\tthis.#events.emit(\"transactionRolledBack\", this.transactions.size === 0);\n\t\t\treturn [undefined, []];\n\t\t}\n\n\t\tconst inverses: TaggedChange<TChange>[] = [];\n\t\tfor (let i = commits.length - 1; i >= 0; i--) {\n\t\t\tconst revision = this.mintRevisionTag();\n\t\t\tconst commit =\n\t\t\t\tcommits[i] ?? fail(\"This wont run because we are iterating through commits\");\n\t\t\tconst inverse = this.changeFamily.rebaser.changeRevision(\n\t\t\t\tthis.changeFamily.rebaser.invert(commit, true, revision),\n\t\t\t\trevision,\n\t\t\t\tcommit.revision,\n\t\t\t);\n\n\t\t\tinverses.push(tagRollbackInverse(inverse, revision, commit.revision));\n\t\t}\n\t\tconst change =\n\t\t\tinverses.length > 0 ? this.changeFamily.rebaser.compose(inverses) : undefined;\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"remove\",\n\t\t\tchange: change === undefined ? undefined : makeAnonChange(change),\n\t\t\tremovedCommits: commits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = startCommit;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\tthis.#events.emit(\"transactionRolledBack\", this.transactions.size === 0);\n\t\treturn [change, commits];\n\t}\n\n\t/**\n\t * True iff this branch is in the middle of a transaction that was begin via {@link startTransaction}\n\t */\n\tpublic isTransacting(): boolean {\n\t\treturn this.transactions.size !== 0;\n\t}\n\n\tprivate popTransaction(): [GraphCommit<TChange>, GraphCommit<TChange>[]] {\n\t\tconst { startRevision: startRevisionOriginal } = this.transactions.pop();\n\t\tlet startRevision = startRevisionOriginal;\n\t\twhile (this.initialTransactionRevToRebasedRev.has(startRevision)) {\n\t\t\tstartRevision = this.initialTransactionRevToRebasedRev.get(startRevision) ?? oob();\n\t\t}\n\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.initialTransactionRevToRebasedRev.clear();\n\t\t}\n\n\t\tconst commits: GraphCommit<TChange>[] = [];\n\t\tconst startCommit = findAncestor(\n\t\t\t[this.head, commits],\n\t\t\t(c) => c.revision === startRevision,\n\t\t);\n\t\tassert(\n\t\t\tstartCommit !== undefined,\n\t\t\t0x593 /* Expected branch to be ahead of transaction start revision */,\n\t\t);\n\t\treturn [startCommit, commits];\n\t}\n\n\t/**\n\t * Spawn a new branch that is based off of the current state of this branch.\n\t * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.\n\t * @remarks Changes made to the new branch will not be applied to this branch until the new branch is {@link SharedTreeBranch.merge | merged} back in.\n\t * Forks created during a transaction will be disposed when the transaction ends.\n\t */\n\tpublic fork(commit: GraphCommit<TChange> = this.head): SharedTreeBranch<TEditor, TChange> {\n\t\tthis.assertNotDisposed();\n\t\tconst fork = new SharedTreeBranch(\n\t\t\tcommit,\n\t\t\tthis.changeFamily,\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.branchTrimmer,\n\t\t);\n\t\tthis.#events.emit(\"fork\", fork);\n\t\treturn fork;\n\t}\n\n\t/**\n\t * Rebase the changes that have been applied to this branch over divergent changes in the given branch.\n\t * After this operation completes, this branch will be based off of `branch`.\n\t *\n\t * @param branch - the branch to rebase onto\n\t * @param upTo - the furthest commit on `branch` over which to rebase (inclusive). Defaults to the head commit of `branch`.\n\t * @returns the result of the rebase or undefined if nothing changed\n\t */\n\tpublic rebaseOnto(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = branch.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tthis.assertNotDisposed();\n\n\t\t// Rebase this branch onto the given branch\n\t\tconst rebaseResult = this.rebaseBranch(this, branch, upTo);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The net change to this branch is provided by the `rebaseBranch` API\n\t\tconst { newSourceHead, commits } = rebaseResult;\n\t\tconst { deletedSourceCommits, targetCommits, sourceCommits } = commits;\n\n\t\tconst newCommits = targetCommits.concat(sourceCommits);\n\t\tif (this.isTransacting()) {\n\t\t\tconst firstCommit = targetCommits[0] ?? oob();\n\t\t\tconst lastCommit = targetCommits[targetCommits.length - 1] ?? oob();\n\t\t\tconst src = firstCommit.parent?.revision;\n\t\t\tconst dst = lastCommit.revision;\n\t\t\tif (src !== undefined && dst !== undefined) {\n\t\t\t\tthis.initialTransactionRevToRebasedRev.set(src, dst);\n\t\t\t}\n\t\t}\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tget change() {\n\t\t\t\tconst change = rebaseResult.sourceChange;\n\t\t\t\treturn change === undefined ? undefined : makeAnonChange(change);\n\t\t\t},\n\t\t\tremovedCommits: deletedSourceCommits,\n\t\t\tnewCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn rebaseResult;\n\t}\n\n\t/**\n\t * Apply all the divergent changes on the given branch to this branch.\n\t *\n\t * @param branch - the branch to merge into this branch\n\t * @returns the net change to this branch and the commits that were added to this branch by the merge,\n\t * or undefined if nothing changed\n\t */\n\tpublic merge(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t): [change: TChange, newCommits: GraphCommit<TChange>[]] | undefined {\n\t\tthis.assertNotDisposed();\n\t\tbranch.assertNotDisposed();\n\t\tassert(\n\t\t\t!branch.isTransacting(),\n\t\t\t0x597 /* Branch may not be merged while transaction is in progress */,\n\t\t);\n\n\t\tif (branch === this) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Rebase the given branch onto this branch\n\t\tconst rebaseResult = this.rebaseBranch(branch, this);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Compute the net change to this branch\n\t\tconst sourceCommits = rebaseResult.commits.sourceCommits;\n\t\tconst change = this.changeFamily.rebaser.compose(sourceCommits);\n\t\tconst taggedChange = makeAnonChange(change);\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tkind: CommitKind.Default,\n\t\t\tget change(): TaggedChange<TChange> {\n\t\t\t\treturn taggedChange;\n\t\t\t},\n\t\t\tnewCommits: sourceCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = rebaseResult.newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn [change, sourceCommits];\n\t}\n\n\t/** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */\n\tprivate rebaseBranch(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tonto: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = onto.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tconst { head } = branch;\n\t\tif (head === upTo) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { duration, output } = measure(() =>\n\t\t\trebaseBranch(\n\t\t\t\tthis.mintRevisionTag,\n\t\t\t\tthis.changeFamily.rebaser,\n\t\t\t\thead,\n\t\t\t\tupTo,\n\t\t\t\tonto.getHead(),\n\t\t\t),\n\t\t);\n\n\t\tthis.telemetryEventBatcher?.accumulateAndLog({ duration, ...output.telemetryProperties });\n\n\t\tif (this.head === output.newSourceHead) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\t/**\n\t * Dispose this branch, freezing its state.\n\t *\n\t * @remarks\n\t * Attempts to further mutate the branch will error.\n\t * Any transactions in progress will be aborted.\n\t * Calling dispose more than once has no effect.\n\t */\n\tpublic dispose(): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\twhile (this.isTransacting()) {\n\t\t\tthis.abortTransaction();\n\t\t}\n\n\t\tthis.unsubscribeBranchTrimmer?.();\n\n\t\tthis.disposed = true;\n\t\tthis.#events.emit(\"dispose\");\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tassert(!this.disposed, 0x66e /* Branch is disposed */);\n\t}\n}\n\n/**\n * Registers an event listener that fires when the given branch forks.\n * The listener will also fire when any of those forks fork, and when those forks of forks fork, and so on.\n * @param branch - the branch that will be listened to for forks\n * @param onFork - the fork event listener\n * @returns a function which when called will deregister all registrations (including transitive) created by this function.\n * The deregister function has undefined behavior if called more than once.\n */\n// Branches are invariant over TChange\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport function onForkTransitive<T extends SharedTreeBranch<ChangeFamilyEditor, any>>(\n\tbranch: T,\n\tonFork: (fork: T) => void,\n): () => void {\n\tconst offs: (() => void)[] = [];\n\toffs.push(\n\t\tbranch.events.on(\"fork\", (fork: T) => {\n\t\t\toffs.push(onForkTransitive(fork, onFork));\n\t\t\tonFork(fork);\n\t\t}),\n\t);\n\treturn () => offs.forEach((off) => off());\n}\n"]}
1
+ {"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;AAEH,OAAO,EAAE,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QAED,IAAI,CAAC,wBAAwB,EAAE,EAAE,CAAC;QAElC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,uBAAA,IAAI,gCAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IAC9B,CAAC;IAEO,iBAAiB;QACxB,MAAM,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;CACD;;AAED;;;;;;;GAOG;AACH,sCAAsC;AACtC,MAAM,UAAU,gBAAgB,CAC/B,MAAS,EACT,MAAyB;IAEzB,MAAM,IAAI,GAAmB,EAAE,CAAC;IAChC,IAAI,CAAC,IAAI,CACR,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAO,EAAE,EAAE;QACpC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC,CAAC,CACF,CAAC;IACF,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { type TelemetryEventBatcher, measure } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype BranchRebaseResult,\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tCommitKind,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\ttype TaggedChange,\n\tfindAncestor,\n\tmakeAnonChange,\n\tmintCommit,\n\trebaseBranch,\n\ttagRollbackInverse,\n\ttype RebaseStatsWithDuration,\n} from \"../core/index.js\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { createEmitter } from \"@fluid-internal/client-utils\";\n\nimport { hasSome } from \"../util/index.js\";\n\n/**\n * Describes a change to a `SharedTreeBranch`. Various operations can mutate the head of the branch;\n * this change format describes each in terms of the \"removed commits\" (all commits which were present\n * on the branch before the operation but are no longer present after) and the \"new commits\" (all\n * commits which are present on the branch after the operation that were not present before). Each of\n * the following event types also provides a `change` which contains the net change to the branch\n * (or is undefined if there was no net change):\n * * Append - when one or more commits are appended to the head of the branch, for example via\n * a change applied by the branch's editor, or as a result of merging another branch into this one\n * * Remove - when one or more commits are removed from the head of the branch. This occurs\n * when a transaction is aborted and all commits pending in that transaction are removed.\n * * Replace - when an operation simultaneously removes and appends commits. For example, when this\n * branch is rebased and some commits are removed and replaced with rebased versions, or when a\n * transaction completes and all pending commits are replaced with a single squash commit.\n */\nexport type SharedTreeBranchChange<TChange> =\n\t| {\n\t\t\ttype: \"append\";\n\t\t\tkind: CommitKind;\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\tnewCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];\n\t }\n\t| {\n\t\t\ttype: \"remove\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly [GraphCommit<TChange>, ...GraphCommit<TChange>[]];\n\t }\n\t| {\n\t\t\ttype: \"replace\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t };\n\n/**\n * Returns the operation that caused the given {@link SharedTreeBranchChange}.\n */\nexport function getChangeReplaceType(\n\tchange: SharedTreeBranchChange<unknown> & { type: \"replace\" },\n): \"transactionCommit\" | \"rebase\" {\n\t// The \"replace\" variant of the change event is emitted by two operations: committing a transaction and doing a rebase.\n\t// Committing a transaction will always remove one or more commits (the commits that were squashed),\n\t// and will add exactly one new commit (the squash commit).\n\tif (change.removedCommits.length === 0 || change.newCommits.length !== 1) {\n\t\treturn \"rebase\";\n\t}\n\n\t// There is only one case in which a rebase both removes commits and adds exactly one new commit.\n\t// This occurs when there is exactly one divergent, but equivalent, commit on each branch:\n\t//\n\t// A ─ B (branch X)\t -- rebase Y onto X --> A ─ B (branch X)\n\t// └─ B' (branch Y) └─ (branch Y)\n\t//\n\t// B' is removed and replaced by B because both have the same revision.\n\tassert(\n\t\tchange.removedCommits[0] !== undefined,\n\t\t0x9e4 /* This wont run due to the length check above */,\n\t);\n\tassert(\n\t\tchange.newCommits[0] !== undefined,\n\t\t0x9e5 /* This wont run because a replace operation always has new commits */,\n\t);\n\tif (\n\t\tchange.removedCommits.length === 1 &&\n\t\tchange.removedCommits[0].revision === change.newCommits[0].revision\n\t) {\n\t\treturn \"rebase\";\n\t}\n\n\treturn \"transactionCommit\";\n}\n\n/**\n * The events emitted by a `SharedTreeBranch`\n */\nexport interface SharedTreeBranchEvents<TEditor extends ChangeFamilyEditor, TChange>\n\textends BranchTrimmingEvents {\n\t/**\n\t * Fired just before the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tbeforeChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired just after the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tafterChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired when this branch forks\n\t * @param fork - the new branch that forked off of this branch\n\t */\n\tfork(fork: SharedTreeBranch<TEditor, TChange>): void;\n\n\t/**\n\t * Fired after this branch is disposed\n\t */\n\tdispose(): void;\n}\n\n/**\n * Events related to branch trimming.\n *\n * @remarks\n * Trimming is a very specific kind of mutation which is the only allowed mutations to branches.\n * References to commits from other commits are removed so that the commit objects can be GC'd by the JS engine.\n * This happens by changing a commit's parent property to undefined, which drops all commits that are in its \"ancestry\".\n * It is done as a performance optimization when it is determined that commits are no longer needed for future computation.\n */\nexport interface BranchTrimmingEvents {\n\t/**\n\t * Fired when some contiguous range of commits beginning with the \"global tail\" of this branch are trimmed from the branch.\n\t * This happens by deleting the parent pointer to the last commit in that range. This event can be fired at any time.\n\t */\n\tancestryTrimmed(trimmedRevisions: RevisionTag[]): void;\n}\n\n/**\n * A branch of changes that can be applied to a SharedTree.\n */\nexport class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChange> {\n\treadonly #events = createEmitter<SharedTreeBranchEvents<TEditor, TChange>>();\n\tpublic readonly events: Listenable<SharedTreeBranchEvents<TEditor, TChange>> = this.#events;\n\tpublic readonly editor: TEditor;\n\tprivate disposed = false;\n\tprivate readonly unsubscribeBranchTrimmer?: () => void;\n\t/**\n\t * Construct a new branch.\n\t * @param head - the head of the branch\n\t * @param changeFamily - determines the set of changes that this branch can commit\n\t * @param branchTrimmer - an optional event emitter that informs the branch it has been trimmed. If this is not supplied, then the branch must\n\t * never be trimmed. See {@link BranchTrimmingEvents} for details on trimming.\n\t */\n\tpublic constructor(\n\t\tprivate head: GraphCommit<TChange>,\n\t\tpublic readonly changeFamily: ChangeFamily<TEditor, TChange>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly branchTrimmer?: Listenable<BranchTrimmingEvents>,\n\t\tprivate readonly telemetryEventBatcher?: TelemetryEventBatcher<\n\t\t\tkeyof RebaseStatsWithDuration\n\t\t>,\n\t) {\n\t\tthis.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) =>\n\t\t\tthis.apply(change),\n\t\t);\n\t\tthis.unsubscribeBranchTrimmer = branchTrimmer?.on(\"ancestryTrimmed\", (commit) => {\n\t\t\tthis.#events.emit(\"ancestryTrimmed\", commit);\n\t\t});\n\t}\n\n\t/**\n\t * Sets the head of this branch.\n\t * @remarks This is a \"manual override\" of sorts, for when the branch needs to be set to a certain state without going through the usual flow of edits.\n\t * This might be necessary as a performance optimization, or to prevent parts of the system updating incorrectly (this method emits no change events!).\n\t */\n\tpublic setHead(head: GraphCommit<TChange>): void {\n\t\tthis.assertNotDisposed();\n\t\tthis.head = head;\n\t}\n\n\t/**\n\t * Apply a change to this branch.\n\t * @param taggedChange - the change to apply\n\t * @param kind - the kind of change to apply\n\t * @returns the change that was applied and the new head commit of the branch\n\t */\n\tpublic apply(\n\t\ttaggedChange: TaggedChange<TChange>,\n\t\tkind: CommitKind = CommitKind.Default,\n\t): [change: TChange, newCommit: GraphCommit<TChange>] {\n\t\tthis.assertNotDisposed();\n\n\t\tconst revisionTag = taggedChange.revision;\n\t\tassert(revisionTag !== undefined, 0xa49 /* Revision tag must be provided */);\n\n\t\tconst newHead = mintCommit(this.head, {\n\t\t\trevision: revisionTag,\n\t\t\tchange: taggedChange.change,\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tkind,\n\t\t\tchange: taggedChange,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn [taggedChange.change, newHead];\n\t}\n\n\t/**\n\t * @returns the commit at the head of this branch.\n\t */\n\tpublic getHead(): GraphCommit<TChange> {\n\t\treturn this.head;\n\t}\n\n\t/**\n\t * Spawn a new branch that is based off of the current state of this branch.\n\t * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.\n\t * @remarks Changes made to the new branch will not be applied to this branch until the new branch is {@link SharedTreeBranch.merge | merged} back in.\n\t * Forks created during a transaction will be disposed when the transaction ends.\n\t */\n\tpublic fork(commit: GraphCommit<TChange> = this.head): SharedTreeBranch<TEditor, TChange> {\n\t\tthis.assertNotDisposed();\n\t\tconst fork = new SharedTreeBranch(\n\t\t\tcommit,\n\t\t\tthis.changeFamily,\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.branchTrimmer,\n\t\t);\n\t\tthis.#events.emit(\"fork\", fork);\n\t\treturn fork;\n\t}\n\n\t/**\n\t * Rebase the changes that have been applied to this branch over divergent changes in the given branch.\n\t * After this operation completes, this branch will be based off of `branch`.\n\t *\n\t * @param branch - the branch to rebase onto\n\t * @param upTo - the furthest commit on `branch` over which to rebase (inclusive). Defaults to the head commit of `branch`.\n\t * @returns the result of the rebase or undefined if nothing changed\n\t */\n\tpublic rebaseOnto(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = branch.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tthis.assertNotDisposed();\n\n\t\t// Rebase this branch onto the given branch\n\t\tconst rebaseResult = this.rebaseBranch(this, branch, upTo);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The net change to this branch is provided by the `rebaseBranch` API\n\t\tconst { newSourceHead, commits } = rebaseResult;\n\t\tconst { deletedSourceCommits, targetCommits, sourceCommits } = commits;\n\t\tassert(hasSome(targetCommits), 0xa83 /* Expected commit(s) for a non no-op rebase */);\n\n\t\tconst newCommits = targetCommits.concat(sourceCommits);\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tget change() {\n\t\t\t\tconst change = rebaseResult.sourceChange;\n\t\t\t\treturn change === undefined ? undefined : makeAnonChange(change);\n\t\t\t},\n\t\t\tremovedCommits: deletedSourceCommits,\n\t\t\tnewCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn rebaseResult;\n\t}\n\n\t/**\n\t * Remove a range of commits from this branch.\n\t * @param commit - All commits after (but not including) this commit will be removed.\n\t * @returns The net change to this branch and the commits that were removed from this branch.\n\t */\n\tpublic removeAfter(\n\t\tcommit: GraphCommit<TChange>,\n\t): [change: TaggedChange<TChange> | undefined, removedCommits: GraphCommit<TChange>[]] {\n\t\tif (commit === this.head) {\n\t\t\treturn [undefined, []];\n\t\t}\n\n\t\tconst removedCommits: GraphCommit<TChange>[] = [];\n\t\tconst inverses: TaggedChange<TChange>[] = [];\n\t\tfindAncestor([this.head, removedCommits], (c) => {\n\t\t\t// TODO: Pull this side effect out if/when more diverse ancestry walking helpers are available\n\t\t\tif (c !== commit) {\n\t\t\t\tconst revision = this.mintRevisionTag();\n\t\t\t\tconst inverse = this.changeFamily.rebaser.changeRevision(\n\t\t\t\t\tthis.changeFamily.rebaser.invert(c, true, revision),\n\t\t\t\t\trevision,\n\t\t\t\t\tc.revision,\n\t\t\t\t);\n\n\t\t\t\tinverses.push(tagRollbackInverse(inverse, revision, c.revision));\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\treturn true;\n\t\t});\n\t\tassert(hasSome(removedCommits), 0xa84 /* Commit must be in the branch's ancestry */);\n\n\t\tconst change = makeAnonChange(this.changeFamily.rebaser.compose(inverses));\n\t\tconst changeEvent = {\n\t\t\ttype: \"remove\",\n\t\t\tchange,\n\t\t\tremovedCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = commit;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn [change, removedCommits];\n\t}\n\n\t/**\n\t * Replace a range of commits on this branch with a single commit composed of equivalent changes.\n\t * @param commit - All commits after (but not including) this commit will be squashed.\n\t * @returns The commits that were squashed and removed from this branch.\n\t * @remarks The commits after `commit` will be removed from this branch, and the squash commit will become the new head of this branch.\n\t * The change event emitted by this operation will have a `change` property that is undefined, since no net change occurred.\n\t */\n\tpublic squashAfter(commit: GraphCommit<TChange>): GraphCommit<TChange>[] {\n\t\tif (commit === this.head) {\n\t\t\treturn [];\n\t\t}\n\n\t\tconst removedCommits: GraphCommit<TChange>[] = [];\n\t\tfindAncestor([this.head, removedCommits], (c) => c === commit);\n\t\tassert(hasSome(removedCommits), 0xa85 /* Commit must be in the branch's ancestry */);\n\n\t\tconst squashedChange = this.changeFamily.rebaser.compose(removedCommits);\n\t\tconst revision = this.mintRevisionTag();\n\t\tconst newHead = mintCommit(commit, {\n\t\t\trevision,\n\t\t\tchange: this.changeFamily.rebaser.changeRevision(squashedChange, revision),\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tchange: undefined,\n\t\t\tremovedCommits,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn removedCommits;\n\t}\n\n\t/**\n\t * Apply all the divergent changes on the given branch to this branch.\n\t *\n\t * @param branch - the branch to merge into this branch\n\t * @returns the net change to this branch and the commits that were added to this branch by the merge,\n\t * or undefined if nothing changed\n\t */\n\tpublic merge(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t): [change: TChange, newCommits: GraphCommit<TChange>[]] | undefined {\n\t\tthis.assertNotDisposed();\n\t\tbranch.assertNotDisposed();\n\n\t\tif (branch === this) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Rebase the given branch onto this branch\n\t\tconst rebaseResult = this.rebaseBranch(branch, this);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Compute the net change to this branch\n\t\tconst sourceCommits = rebaseResult.commits.sourceCommits;\n\t\tassert(hasSome(sourceCommits), 0xa86 /* Expected source commits in non no-op merge */);\n\t\tconst change = this.changeFamily.rebaser.compose(sourceCommits);\n\t\tconst taggedChange = makeAnonChange(change);\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tkind: CommitKind.Default,\n\t\t\tget change(): TaggedChange<TChange> {\n\t\t\t\treturn taggedChange;\n\t\t\t},\n\t\t\tnewCommits: sourceCommits,\n\t\t} as const;\n\n\t\tthis.#events.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = rebaseResult.newSourceHead;\n\t\tthis.#events.emit(\"afterChange\", changeEvent);\n\t\treturn [change, sourceCommits];\n\t}\n\n\t/** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */\n\tprivate rebaseBranch(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tonto: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = onto.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tconst { head } = branch;\n\t\tif (head === upTo) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst { duration, output } = measure(() =>\n\t\t\trebaseBranch(\n\t\t\t\tthis.mintRevisionTag,\n\t\t\t\tthis.changeFamily.rebaser,\n\t\t\t\thead,\n\t\t\t\tupTo,\n\t\t\t\tonto.getHead(),\n\t\t\t),\n\t\t);\n\n\t\tthis.telemetryEventBatcher?.accumulateAndLog({ duration, ...output.telemetryProperties });\n\n\t\tif (this.head === output.newSourceHead) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn output;\n\t}\n\n\t/**\n\t * Dispose this branch, freezing its state.\n\t *\n\t * @remarks\n\t * Attempts to further mutate the branch will error.\n\t * Any transactions in progress will be aborted.\n\t * Calling dispose more than once has no effect.\n\t */\n\tpublic dispose(): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.unsubscribeBranchTrimmer?.();\n\n\t\tthis.disposed = true;\n\t\tthis.#events.emit(\"dispose\");\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tassert(!this.disposed, 0x66e /* Branch is disposed */);\n\t}\n}\n\n/**\n * Registers an event listener that fires when the given branch forks.\n * The listener will also fire when any of those forks fork, and when those forks of forks fork, and so on.\n * @param branch - the branch that will be listened to for forks\n * @param onFork - the fork event listener\n * @returns a function which when called will deregister all registrations (including transitive) created by this function.\n * The deregister function has undefined behavior if called more than once.\n */\n// Branches are invariant over TChange\nexport function onForkTransitive<T extends { events: Listenable<{ fork(t: T): void }> }>(\n\tbranch: T,\n\tonFork: (fork: T) => void,\n): () => void {\n\tconst offs: (() => void)[] = [];\n\toffs.push(\n\t\tbranch.events.on(\"fork\", (fork: T) => {\n\t\t\toffs.push(onForkTransitive(fork, onFork));\n\t\t\tonFork(fork);\n\t\t}),\n\t);\n\treturn () => offs.forEach((off) => off());\n}\n"]}