@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
@@ -14,9 +14,8 @@ exports.onForkTransitive = exports.SharedTreeBranch = exports.getChangeReplaceTy
14
14
  const internal_1 = require("@fluidframework/core-utils/internal");
15
15
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
16
16
  const index_js_1 = require("../core/index.js");
17
- const index_js_2 = require("../events/index.js");
18
- const transactionStack_js_1 = require("./transactionStack.js");
19
- const index_js_3 = require("../util/index.js");
17
+ const client_utils_1 = require("@fluid-internal/client-utils");
18
+ const index_js_2 = require("../util/index.js");
20
19
  /**
21
20
  * Returns the operation that caused the given {@link SharedTreeBranchChange}.
22
21
  */
@@ -60,32 +59,8 @@ class SharedTreeBranch {
60
59
  this.mintRevisionTag = mintRevisionTag;
61
60
  this.branchTrimmer = branchTrimmer;
62
61
  this.telemetryEventBatcher = telemetryEventBatcher;
63
- _SharedTreeBranch_events.set(this, (0, index_js_2.createEmitter)());
62
+ _SharedTreeBranch_events.set(this, (0, client_utils_1.createEmitter)());
64
63
  this.events = __classPrivateFieldGet(this, _SharedTreeBranch_events, "f");
65
- this.transactions = new transactionStack_js_1.TransactionStack();
66
- /**
67
- * After pushing a starting revision to the transaction stack, this branch might be rebased
68
- * over commits which are children of that starting revision. When the transaction is committed,
69
- * those rebased-over commits should not be included in the transaction's squash commit, even though
70
- * they exist between the starting revision and the final commit within the transaction.
71
- *
72
- * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the
73
- * original merge-base to the new merge-base.
74
- *
75
- * This state need only be retained for the lifetime of the transaction.
76
- *
77
- * TODO: This strategy might need to be revisited when adding better support for async transactions.
78
- * Since:
79
- *
80
- * 1. Transactionality is guaranteed primarily by squashing at commit time
81
- * 2. Branches may be rebased with an ongoing transaction
82
- *
83
- * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the
84
- * purpose of transactionality.
85
- *
86
- * AB#6483 and children items track this work.
87
- */
88
- this.initialTransactionRevToRebasedRev = new Map();
89
64
  this.disposed = false;
90
65
  this.editor = this.changeFamily.buildEditor(mintRevisionTag, (change) => this.apply(change));
91
66
  this.unsubscribeBranchTrimmer = branchTrimmer?.on("ancestryTrimmed", (commit) => {
@@ -93,11 +68,12 @@ class SharedTreeBranch {
93
68
  });
94
69
  }
95
70
  /**
96
- * Sets the head of this branch. Emits no change events.
71
+ * Sets the head of this branch.
72
+ * @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.
73
+ * This might be necessary as a performance optimization, or to prevent parts of the system updating incorrectly (this method emits no change events!).
97
74
  */
98
75
  setHead(head) {
99
76
  this.assertNotDisposed();
100
- (0, internal_1.assert)(!this.isTransacting(), 0x685 /* Cannot set head during a transaction */);
101
77
  this.head = head;
102
78
  }
103
79
  /**
@@ -131,113 +107,6 @@ class SharedTreeBranch {
131
107
  getHead() {
132
108
  return this.head;
133
109
  }
134
- /**
135
- * Begin a transaction on this branch. If the transaction is committed via {@link commitTransaction},
136
- * all commits made since this call will be squashed into a single head commit.
137
- */
138
- startTransaction() {
139
- this.assertNotDisposed();
140
- const forks = new Set();
141
- const onDisposeUnSubscribes = [];
142
- const onForkUnSubscribe = onForkTransitive(this, (fork) => {
143
- forks.add(fork);
144
- onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
145
- });
146
- this.transactions.push(this.head.revision, () => {
147
- forks.forEach((fork) => fork.dispose());
148
- onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
149
- onForkUnSubscribe();
150
- });
151
- this.editor.enterTransaction();
152
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionStarted", this.transactions.size === 1);
153
- }
154
- /**
155
- * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.
156
- * If there are commits in the current transaction, they will be squashed into a new single head commit.
157
- * @returns the commits that were squashed and the new squash commit if a squash occurred, otherwise `undefined`.
158
- * @remarks If the transaction had no changes applied during its lifetime, then no squash occurs (i.e. this method is a no-op).
159
- * Even if the transaction contained only one change, it will still be replaced with an (equivalent) squash change.
160
- */
161
- commitTransaction() {
162
- this.assertNotDisposed();
163
- const [startCommit, commits] = this.popTransaction();
164
- this.editor.exitTransaction();
165
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionCommitted", this.transactions.size === 0);
166
- if (commits.length === 0) {
167
- return undefined;
168
- }
169
- // Squash the changes and make the squash commit the new head of this branch
170
- const squashedChange = this.changeFamily.rebaser.compose(commits);
171
- const revision = this.mintRevisionTag();
172
- const newHead = (0, index_js_1.mintCommit)(startCommit, {
173
- revision,
174
- change: this.changeFamily.rebaser.changeRevision(squashedChange, revision),
175
- });
176
- const changeEvent = {
177
- type: "replace",
178
- change: undefined,
179
- removedCommits: commits,
180
- newCommits: [newHead],
181
- };
182
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
183
- this.head = newHead;
184
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
185
- return [commits, newHead];
186
- }
187
- /**
188
- * Cancel the current transaction. There must be a transaction in progress that was begun via
189
- * {@link startTransaction}. All commits made during the transaction will be removed.
190
- * @returns the change to this branch resulting in the removal of the commits, and a list of the
191
- * commits that were removed.
192
- */
193
- abortTransaction() {
194
- this.assertNotDisposed();
195
- const [startCommit, commits] = this.popTransaction();
196
- this.editor.exitTransaction();
197
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionAborted", this.transactions.size === 0);
198
- if (commits.length === 0) {
199
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionRolledBack", this.transactions.size === 0);
200
- return [undefined, []];
201
- }
202
- const inverses = [];
203
- for (let i = commits.length - 1; i >= 0; i--) {
204
- const revision = this.mintRevisionTag();
205
- const commit = commits[i] ?? (0, index_js_3.fail)("This wont run because we are iterating through commits");
206
- const inverse = this.changeFamily.rebaser.changeRevision(this.changeFamily.rebaser.invert(commit, true, revision), revision, commit.revision);
207
- inverses.push((0, index_js_1.tagRollbackInverse)(inverse, revision, commit.revision));
208
- }
209
- const change = inverses.length > 0 ? this.changeFamily.rebaser.compose(inverses) : undefined;
210
- const changeEvent = {
211
- type: "remove",
212
- change: change === undefined ? undefined : (0, index_js_1.makeAnonChange)(change),
213
- removedCommits: commits,
214
- };
215
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
216
- this.head = startCommit;
217
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
218
- __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("transactionRolledBack", this.transactions.size === 0);
219
- return [change, commits];
220
- }
221
- /**
222
- * True iff this branch is in the middle of a transaction that was begin via {@link startTransaction}
223
- */
224
- isTransacting() {
225
- return this.transactions.size !== 0;
226
- }
227
- popTransaction() {
228
- const { startRevision: startRevisionOriginal } = this.transactions.pop();
229
- let startRevision = startRevisionOriginal;
230
- while (this.initialTransactionRevToRebasedRev.has(startRevision)) {
231
- startRevision = this.initialTransactionRevToRebasedRev.get(startRevision) ?? (0, internal_1.oob)();
232
- }
233
- if (!this.isTransacting()) {
234
- this.initialTransactionRevToRebasedRev.clear();
235
- }
236
- const commits = [];
237
- const startCommit = (0, index_js_1.findAncestor)([this.head, commits], (c) => c.revision === startRevision);
238
- (0, internal_1.assert)(startCommit !== undefined, 0x593 /* Expected branch to be ahead of transaction start revision */);
239
- return [startCommit, commits];
240
- }
241
110
  /**
242
111
  * Spawn a new branch that is based off of the current state of this branch.
243
112
  * @param commit - The commit to base the new branch off of. Defaults to the head of this branch.
@@ -268,16 +137,8 @@ class SharedTreeBranch {
268
137
  // The net change to this branch is provided by the `rebaseBranch` API
269
138
  const { newSourceHead, commits } = rebaseResult;
270
139
  const { deletedSourceCommits, targetCommits, sourceCommits } = commits;
140
+ (0, internal_1.assert)((0, index_js_2.hasSome)(targetCommits), 0xa83 /* Expected commit(s) for a non no-op rebase */);
271
141
  const newCommits = targetCommits.concat(sourceCommits);
272
- if (this.isTransacting()) {
273
- const firstCommit = targetCommits[0] ?? (0, internal_1.oob)();
274
- const lastCommit = targetCommits[targetCommits.length - 1] ?? (0, internal_1.oob)();
275
- const src = firstCommit.parent?.revision;
276
- const dst = lastCommit.revision;
277
- if (src !== undefined && dst !== undefined) {
278
- this.initialTransactionRevToRebasedRev.set(src, dst);
279
- }
280
- }
281
142
  const changeEvent = {
282
143
  type: "replace",
283
144
  get change() {
@@ -292,6 +153,70 @@ class SharedTreeBranch {
292
153
  __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
293
154
  return rebaseResult;
294
155
  }
156
+ /**
157
+ * Remove a range of commits from this branch.
158
+ * @param commit - All commits after (but not including) this commit will be removed.
159
+ * @returns The net change to this branch and the commits that were removed from this branch.
160
+ */
161
+ removeAfter(commit) {
162
+ if (commit === this.head) {
163
+ return [undefined, []];
164
+ }
165
+ const removedCommits = [];
166
+ const inverses = [];
167
+ (0, index_js_1.findAncestor)([this.head, removedCommits], (c) => {
168
+ // TODO: Pull this side effect out if/when more diverse ancestry walking helpers are available
169
+ if (c !== commit) {
170
+ const revision = this.mintRevisionTag();
171
+ const inverse = this.changeFamily.rebaser.changeRevision(this.changeFamily.rebaser.invert(c, true, revision), revision, c.revision);
172
+ inverses.push((0, index_js_1.tagRollbackInverse)(inverse, revision, c.revision));
173
+ return false;
174
+ }
175
+ return true;
176
+ });
177
+ (0, internal_1.assert)((0, index_js_2.hasSome)(removedCommits), 0xa84 /* Commit must be in the branch's ancestry */);
178
+ const change = (0, index_js_1.makeAnonChange)(this.changeFamily.rebaser.compose(inverses));
179
+ const changeEvent = {
180
+ type: "remove",
181
+ change,
182
+ removedCommits,
183
+ };
184
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
185
+ this.head = commit;
186
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
187
+ return [change, removedCommits];
188
+ }
189
+ /**
190
+ * Replace a range of commits on this branch with a single commit composed of equivalent changes.
191
+ * @param commit - All commits after (but not including) this commit will be squashed.
192
+ * @returns The commits that were squashed and removed from this branch.
193
+ * @remarks The commits after `commit` will be removed from this branch, and the squash commit will become the new head of this branch.
194
+ * The change event emitted by this operation will have a `change` property that is undefined, since no net change occurred.
195
+ */
196
+ squashAfter(commit) {
197
+ if (commit === this.head) {
198
+ return [];
199
+ }
200
+ const removedCommits = [];
201
+ (0, index_js_1.findAncestor)([this.head, removedCommits], (c) => c === commit);
202
+ (0, internal_1.assert)((0, index_js_2.hasSome)(removedCommits), 0xa85 /* Commit must be in the branch's ancestry */);
203
+ const squashedChange = this.changeFamily.rebaser.compose(removedCommits);
204
+ const revision = this.mintRevisionTag();
205
+ const newHead = (0, index_js_1.mintCommit)(commit, {
206
+ revision,
207
+ change: this.changeFamily.rebaser.changeRevision(squashedChange, revision),
208
+ });
209
+ const changeEvent = {
210
+ type: "replace",
211
+ change: undefined,
212
+ removedCommits,
213
+ newCommits: [newHead],
214
+ };
215
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("beforeChange", changeEvent);
216
+ this.head = newHead;
217
+ __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("afterChange", changeEvent);
218
+ return removedCommits;
219
+ }
295
220
  /**
296
221
  * Apply all the divergent changes on the given branch to this branch.
297
222
  *
@@ -302,7 +227,6 @@ class SharedTreeBranch {
302
227
  merge(branch) {
303
228
  this.assertNotDisposed();
304
229
  branch.assertNotDisposed();
305
- (0, internal_1.assert)(!branch.isTransacting(), 0x597 /* Branch may not be merged while transaction is in progress */);
306
230
  if (branch === this) {
307
231
  return undefined;
308
232
  }
@@ -313,6 +237,7 @@ class SharedTreeBranch {
313
237
  }
314
238
  // Compute the net change to this branch
315
239
  const sourceCommits = rebaseResult.commits.sourceCommits;
240
+ (0, internal_1.assert)((0, index_js_2.hasSome)(sourceCommits), 0xa86 /* Expected source commits in non no-op merge */);
316
241
  const change = this.changeFamily.rebaser.compose(sourceCommits);
317
242
  const taggedChange = (0, index_js_1.makeAnonChange)(change);
318
243
  const changeEvent = {
@@ -353,9 +278,6 @@ class SharedTreeBranch {
353
278
  if (this.disposed) {
354
279
  return;
355
280
  }
356
- while (this.isTransacting()) {
357
- this.abortTransaction();
358
- }
359
281
  this.unsubscribeBranchTrimmer?.();
360
282
  this.disposed = true;
361
283
  __classPrivateFieldGet(this, _SharedTreeBranch_events, "f").emit("dispose");
@@ -375,7 +297,6 @@ _SharedTreeBranch_events = new WeakMap();
375
297
  * The deregister function has undefined behavior if called more than once.
376
298
  */
377
299
  // Branches are invariant over TChange
378
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
379
300
  function onForkTransitive(branch, onFork) {
380
301
  const offs = [];
381
302
  offs.push(branch.events.on("fork", (fork) => {
@@ -1 +1 @@
1
- {"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,kEAAkE;AAClE,uEAA+F;AAE/F,+CAc0B;AAC1B,iDAAoE;AAEpE,+DAAyD;AACzD,+CAAwC;AAoCxC;;GAEG;AACH,SAAgB,oBAAoB,CACnC,MAA6D;IAE7D,uHAAuH;IACvH,oGAAoG;IACpG,2DA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;AAC3C,CAAC;AAZD,4CAYC","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,kEAA6D;AAC7D,uEAA+F;AAE/F,+CAc0B;AAE1B,+DAA6D;AAE7D,+CAA2C;AAoC3C;;GAEG;AACH,SAAgB,oBAAoB,CACnC,MAA6D;IAE7D,uHAAuH;IACvH,oGAAoG;IACpG,2DAA2D;IAC3D,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,iGAAiG;IACjG,0FAA0F;IAC1F,EAAE;IACF,+DAA+D;IAC/D,gEAAgE;IAChE,EAAE;IACF,uEAAuE;IACvE,IAAA,iB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,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;AAZD,4CAYC","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"]}
@@ -4,53 +4,39 @@
4
4
  */
5
5
  import { type ChangeRebaser, type GraphCommit } from "../core/index.js";
6
6
  import type { ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
7
+ import { type SharedTreeBranchChange } from "./branch.js";
7
8
  /**
8
9
  * Utility for enriching commits from a {@link Branch} before these commits are applied and submitted.
9
10
  */
10
11
  export declare class BranchCommitEnricher<TChange> {
11
- private readonly transactionEnricher;
12
- private readonly enricher;
13
- /**
14
- * Maps each local commit to the corresponding enriched commit.
15
- * Entries are added when the commits are prepared (before being applied and submitted).
16
- * Entries are removed when the commits are retrieved for submission (after being applied).
17
- * It's possible an entry will linger in the map indefinitely if it is never retrieved for submission.
18
- * This would happen if applying a commit were to fail and the commit were not retrieved/purged after the failure.
19
- */
20
- private readonly preparedCommits;
12
+ #private;
21
13
  constructor(rebaser: ChangeRebaser<TChange>, enricher: ChangeEnricherReadonlyCheckout<TChange>);
22
14
  /**
23
- * @returns The number of commits that have been prepared but not yet retrieved.
15
+ * Process the given change, preparing new commits for {@link BranchCommitEnricher.enrich | enrichment}.
16
+ * @param change - The change to process.
17
+ * @param isAttached - Whether or not the SharedTree is attached to the service.
24
18
  */
25
- get preparedCommitsCount(): number;
26
- startNewTransaction(): void;
27
- commitCurrentTransaction(): void;
28
- abortCurrentTransaction(): void;
19
+ processChange(change: SharedTreeBranchChange<TChange>): void;
29
20
  /**
30
- * Adds a commit to the enricher.
31
- * @param commit - A commit that is part of a transaction.
21
+ * Retrieves the enriched version of the given commit.
22
+ * @param commit - A commit {@link BranchCommitEnricher.processChange | processed during the most recent change}.
23
+ * @remarks A commit can only be enriched once - subsequent calls to this method with the same commit will throw an error.
32
24
  */
33
- ingestTransactionCommit(commit: GraphCommit<TChange>): void;
25
+ enrich(commit: GraphCommit<TChange>): GraphCommit<TChange>;
34
26
  /**
35
- * Prepares an enriched commit for later submission (see {@link BranchCommitEnricher.getPreparedCommit}).
36
- * @param commit - The commit to prepare an enriched version of.
37
- * @param concludesOuterTransaction - Whether the commit concludes an outer transaction.
38
- *
39
- * Each call to this method must be followed by a call to {@link BranchCommitEnricher.getPreparedCommit} or
40
- * {@link BranchCommitEnricher.purgePreparedCommits}. Failing to do so will result in a memory leak.
27
+ * Notify the enricher that a new transaction has started.
28
+ * @remarks This may be called multiple times without calling {@link BranchCommitEnricher.commitTransaction | commitTransaction}, producing "nested transactions".
41
29
  */
42
- prepareCommit(commit: GraphCommit<TChange>, concludesOuterTransaction: boolean): void;
30
+ startTransaction(): void;
43
31
  /**
44
- * @param commit - A commit previously passed to {@link BranchCommitEnricher.prepareCommit}.
45
- * @returns The enriched commit corresponds to the given commit.
32
+ * Commit the current transaction.
33
+ * @remarks This should be called _before_ the corresponding transaction commit change is {@link BranchCommitEnricher.processChange | processed}.
46
34
  */
47
- getPreparedCommit(commit: GraphCommit<TChange>): GraphCommit<TChange>;
35
+ commitTransaction(): void;
48
36
  /**
49
- * Purges all commits that have been prepared but not been retrieved.
50
- * This should be called to avoid memory leaks if the prepared commits are no longer needed.
51
- *
52
- * Does not affect ingested transaction commits.
37
+ * Notify the enricher that the current transaction has been aborted.
38
+ * @remarks This will throw an error if there is no ongoing transaction.
53
39
  */
54
- purgePreparedCommits(): void;
40
+ abortTransaction(): void;
55
41
  }
56
42
  //# sourceMappingURL=branchCommitEnricher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"branchCommitEnricher.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/branchCommitEnricher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAE,KAAK,WAAW,EAAiB,MAAM,kBAAkB,CAAC;AACvF,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAG1E;;GAEG;AACH,qBAAa,oBAAoB,CAAC,OAAO;IACxC,OAAO,CAAC,QAAQ,CAAC,mBAAmB,CAA+B;IACnE,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IACnE;;;;;;OAMG;IACH,OAAO,CAAC,QAAQ,CAAC,eAAe,CACrB;gBAGV,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAC/B,QAAQ,EAAE,8BAA8B,CAAC,OAAO,CAAC;IAMlD;;OAEG;IACH,IAAW,oBAAoB,IAAI,MAAM,CAExC;IAEM,mBAAmB,IAAI,IAAI;IAI3B,wBAAwB,IAAI,IAAI;IAIhC,uBAAuB,IAAI,IAAI;IAItC;;;OAGG;IACI,uBAAuB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAMlE;;;;;;;OAOG;IACI,aAAa,CACnB,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAC5B,yBAAyB,EAAE,OAAO,GAChC,IAAI;IAcP;;;OAGG;IACI,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC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