@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
@@ -2,16 +2,22 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { assert, oob } from "@fluidframework/core-utils/internal";
5
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
6
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
7
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
8
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
9
+ };
10
+ var _TreeCheckout_transaction;
11
+ import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
12
+ import { createEmitter } from "@fluid-internal/client-utils";
6
13
  import { UsageError, } from "@fluidframework/telemetry-utils/internal";
7
14
  import { noopValidator } from "../codec/index.js";
8
15
  import { AnchorSet, CommitKind, RevertibleStatus, TreeStoredSchemaRepository, combineVisitors, makeDetachedFieldIndex, rebaseChange, rootFieldKey, tagChange, visitDelta, } from "../core/index.js";
9
- import { createEmitter, } from "../events/index.js";
10
16
  import { buildForest, createNodeKeyManager, intoDelta, jsonableTreeFromCursor, makeFieldBatchCodec, } from "../feature-libraries/index.js";
11
- import { SharedTreeBranch, getChangeReplaceType, } from "../shared-tree-core/index.js";
12
- import { Breakable, TransactionResult, disposeSymbol, fail } from "../util/index.js";
17
+ import { SharedTreeBranch, TransactionResult, TransactionStack, getChangeReplaceType, onForkTransitive, } from "../shared-tree-core/index.js";
18
+ import { Breakable, disposeSymbol, fail, getLast, hasSome } from "../util/index.js";
13
19
  import { SharedTreeChangeFamily, hasSchemaChange } from "./sharedTreeChangeFamily.js";
14
- import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
20
+ import { getCheckout, SchematizingSimpleTreeView } from "./schematizingTreeView.js";
15
21
  /**
16
22
  * Creates a {@link TreeCheckout}.
17
23
  * @param args - an object containing optional components that will be used to build the view.
@@ -33,41 +39,17 @@ export function createTreeCheckout(idCompressor, mintRevisionTag, revisionTagCod
33
39
  revision: "root",
34
40
  }, changeFamily, () => idCompressor.generateCompressedId());
35
41
  const events = args?.events ?? createEmitter();
36
- const transaction = new Transaction(branch);
37
- return new TreeCheckout(transaction, branch, false, changeFamily, schema, forest, events, mintRevisionTag, revisionTagCodec, idCompressor, args?.removedRoots, args?.logger, args?.breaker);
38
- }
39
- class Transaction {
40
- constructor(branch) {
41
- this.branch = branch;
42
- }
43
- start() {
44
- this.branch.startTransaction();
45
- this.branch.editor.enterTransaction();
46
- }
47
- commit() {
48
- this.branch.commitTransaction();
49
- this.branch.editor.exitTransaction();
50
- return TransactionResult.Commit;
51
- }
52
- abort() {
53
- this.branch.abortTransaction();
54
- this.branch.editor.exitTransaction();
55
- return TransactionResult.Abort;
56
- }
57
- inProgress() {
58
- return this.branch.isTransacting();
59
- }
42
+ return new TreeCheckout(branch, false, changeFamily, schema, forest, events, mintRevisionTag, revisionTagCodec, idCompressor, args?.removedRoots, args?.logger, args?.breaker);
60
43
  }
61
44
  /**
62
45
  * An implementation of {@link ITreeCheckoutFork}.
63
46
  */
64
47
  export class TreeCheckout {
65
- constructor(transaction, _branch,
48
+ constructor(_branch,
66
49
  /** True if and only if this checkout is for a forked branch and not the "main branch" of the tree. */
67
50
  isBranch, changeFamily, storedSchema, forest, events, mintRevisionTag, revisionTagCodec, idCompressor, removedRoots = makeDetachedFieldIndex("repair", revisionTagCodec, idCompressor),
68
51
  /** Optional logger for telemetry. */
69
52
  logger, breaker = new Breakable("TreeCheckout")) {
70
- this.transaction = transaction;
71
53
  this._branch = _branch;
72
54
  this.isBranch = isBranch;
73
55
  this.changeFamily = changeFamily;
@@ -93,34 +75,68 @@ export class TreeCheckout {
93
75
  */
94
76
  this.revertibleCommitBranches = new Map();
95
77
  /**
96
- * copies of the removed roots used as snapshots for reverting to previous state when transactions are aborted
78
+ * The {@link Transactor} for this checkout.
79
+ * @remarks In the context of a checkout, transactions allow edits to be batched into atomic units.
80
+ * Edits made during a transaction will update the local state of the tree immediately, but will be squashed into a single edit when the transaction is committed.
81
+ * If the transaction is aborted, the local state will be reset to what it was before the transaction began.
82
+ * Transactions may nest, meaning that a transaction may be started while a transaction is already ongoing.
83
+ *
84
+ * To avoid updating observers of the view state with intermediate results during a transaction,
85
+ * use {@link ITreeCheckout#branch} and {@link ISharedTreeFork#merge}.
97
86
  */
98
- this.removedRootsSnapshots = [];
99
- // when a transaction is started, take a snapshot of the current state of removed roots
100
- _branch.events.on("transactionStarted", () => {
101
- this.removedRootsSnapshots.push(this.removedRoots.clone());
102
- });
103
- // when a transaction is committed, the latest snapshot of removed roots can be discarded
104
- _branch.events.on("transactionCommitted", () => {
105
- this.removedRootsSnapshots.pop();
106
- });
107
- // after a transaction is rolled back, revert removed roots back to the latest snapshot
108
- _branch.events.on("transactionRolledBack", () => {
109
- const snapshot = this.removedRootsSnapshots.pop();
110
- assert(snapshot !== undefined, 0x9ae /* a snapshot for removed roots does not exist */);
111
- this.removedRoots = snapshot;
112
- });
87
+ _TreeCheckout_transaction.set(this, new TransactionStack(() => {
88
+ // Keep track of the commit that each transaction was on when it started
89
+ // TODO:#8603: This may need to be computed differently if we allow rebasing during a transaction.
90
+ const startCommit = this._branch.getHead();
91
+ // Keep track of all the forks created during the transaction so that we can dispose them when the transaction ends.
92
+ // This is a policy decision that we think is useful for the user, but it is not necessary for correctness.
93
+ const forks = new Set();
94
+ const onDisposeUnSubscribes = [];
95
+ const onForkUnSubscribe = onForkTransitive(this, (fork) => {
96
+ forks.add(fork);
97
+ onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
98
+ });
99
+ // When each transaction is started, take a snapshot of the current state of removed roots
100
+ const removedRoots = this.removedRoots.clone();
101
+ this._branch.editor.enterTransaction();
102
+ return (result) => {
103
+ this._branch.editor.exitTransaction();
104
+ switch (result) {
105
+ case TransactionResult.Abort:
106
+ this._branch.removeAfter(startCommit);
107
+ // If a transaction is rolled back, revert removed roots back to the latest snapshot
108
+ this.removedRoots = removedRoots;
109
+ break;
110
+ case TransactionResult.Commit: {
111
+ const removedCommits = this._branch.squashAfter(startCommit);
112
+ const transactionRevision = this._branch.getHead().revision;
113
+ for (const transactionStep of removedCommits) {
114
+ this.removedRoots.updateMajor(transactionStep.revision, transactionRevision);
115
+ }
116
+ break;
117
+ }
118
+ default:
119
+ unreachableCase(result);
120
+ }
121
+ forks.forEach((fork) => fork.dispose());
122
+ onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
123
+ onForkUnSubscribe();
124
+ };
125
+ }));
113
126
  // We subscribe to `beforeChange` rather than `afterChange` here because it's possible that the change is invalid WRT our forest.
114
127
  // For example, a bug in the editor might produce a malformed change object and thus applying the change to the forest will throw an error.
115
128
  // In such a case we will crash here, preventing the change from being added to the commit graph, and preventing `afterChange` from firing.
116
129
  // One important consequence of this is that we will not submit the op containing the invalid change, since op submissions happens in response to `afterChange`.
117
130
  _branch.events.on("beforeChange", (event) => {
118
131
  if (event.change !== undefined) {
119
- const revision = event.type === "replace"
120
- ? // Change events will always contain new commits
121
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
122
- event.newCommits[event.newCommits.length - 1].revision
123
- : event.change.revision;
132
+ let revision;
133
+ if (event.type === "replace") {
134
+ assert(hasSome(event.newCommits), 0xa81 /* Expected new commit for non no-op change event */);
135
+ revision = getLast(event.newCommits).revision;
136
+ }
137
+ else {
138
+ revision = event.change.revision;
139
+ }
124
140
  // Conflicts due to schema will be empty and thus are not applied.
125
141
  for (const change of event.change.change.changes) {
126
142
  if (change.type === "data") {
@@ -153,18 +169,11 @@ export class TreeCheckout {
153
169
  }
154
170
  this.events.emit("afterBatch");
155
171
  }
156
- if (event.type === "replace" && getChangeReplaceType(event) === "transactionCommit") {
157
- const firstCommit = event.newCommits[0] ?? oob();
158
- const transactionRevision = firstCommit.revision;
159
- for (const transactionStep of event.removedCommits) {
160
- this.removedRoots.updateMajor(transactionStep.revision, transactionRevision);
161
- }
162
- }
163
172
  });
164
173
  _branch.events.on("afterChange", (event) => {
165
174
  // The following logic allows revertibles to be generated for the change.
166
175
  // Currently only appends (including merges) and transaction commits are supported.
167
- if (!_branch.isTransacting()) {
176
+ if (!this.transaction.isInProgress()) {
168
177
  if (event.type === "append" ||
169
178
  (event.type === "replace" && getChangeReplaceType(event) === "transactionCommit")) {
170
179
  // TODO:#20949: When the SharedTree is detached, these commits will already have been garbage collected.
@@ -181,35 +190,7 @@ export class TreeCheckout {
181
190
  if (this.revertibleCommitBranches.get(revision) !== undefined) {
182
191
  throw new UsageError("Cannot generate the same revertible more than once. Note that this can happen when multiple changed event listeners are registered.");
183
192
  }
184
- const revertibleCommits = this.revertibleCommitBranches;
185
- const revertible = {
186
- get status() {
187
- const revertibleCommit = revertibleCommits.get(revision);
188
- return revertibleCommit === undefined
189
- ? RevertibleStatus.Disposed
190
- : RevertibleStatus.Valid;
191
- },
192
- revert: (release = true) => {
193
- if (revertible.status === RevertibleStatus.Disposed) {
194
- throw new UsageError("Unable to revert a revertible that has been disposed.");
195
- }
196
- const revertMetrics = this.revertRevertible(revision, kind);
197
- this.logger?.sendTelemetryEvent({
198
- eventName: TreeCheckout.revertTelemetryEventName,
199
- ...revertMetrics,
200
- });
201
- if (release) {
202
- revertible.dispose();
203
- }
204
- },
205
- dispose: () => {
206
- if (revertible.status === RevertibleStatus.Disposed) {
207
- throw new UsageError("Unable to dispose a revertible that has already been disposed.");
208
- }
209
- this.disposeRevertible(revertible, revision);
210
- onRevertibleDisposed?.(revertible);
211
- },
212
- };
193
+ const revertible = this.createRevertible(revision, kind, this, onRevertibleDisposed);
213
194
  this.revertibleCommitBranches.set(revision, _branch.fork(commit));
214
195
  this.revertibles.add(revertible);
215
196
  return revertible;
@@ -255,6 +236,59 @@ export class TreeCheckout {
255
236
  assert(false, 0x911 /* Invalid operation on a disposed TreeCheckout */);
256
237
  }
257
238
  }
239
+ /**
240
+ * Creates a {@link RevertibleAlpha} object that can undo a specific change in the tree's history.
241
+ * Revision must exist in the given {@link TreeCheckout}'s branch.
242
+ *
243
+ * @param revision - The revision tag identifying the change to be made revertible.
244
+ * @param kind - The {@link CommitKind} that produced this revertible (e.g., Default, Undo, Redo).
245
+ * @param checkout - The {@link TreeCheckout} instance this revertible belongs to.
246
+ * @param onRevertibleDisposed - Callback function that will be called when the revertible is disposed.
247
+ * @returns - {@link RevertibleAlpha}
248
+ */
249
+ createRevertible(revision, kind, checkout, onRevertibleDisposed) {
250
+ const commitBranches = checkout.revertibleCommitBranches;
251
+ const revertible = {
252
+ get status() {
253
+ const revertibleCommit = commitBranches.get(revision);
254
+ return revertibleCommit === undefined
255
+ ? RevertibleStatus.Disposed
256
+ : RevertibleStatus.Valid;
257
+ },
258
+ revert: (release = true) => {
259
+ if (revertible.status === RevertibleStatus.Disposed) {
260
+ throw new UsageError("Unable to revert a revertible that has been disposed.");
261
+ }
262
+ const revertMetrics = checkout.revertRevertible(revision, kind);
263
+ checkout.logger?.sendTelemetryEvent({
264
+ eventName: TreeCheckout.revertTelemetryEventName,
265
+ ...revertMetrics,
266
+ });
267
+ if (release) {
268
+ revertible.dispose();
269
+ }
270
+ },
271
+ clone: (forkedBranch) => {
272
+ if (forkedBranch === undefined) {
273
+ return this.createRevertible(revision, kind, checkout, onRevertibleDisposed);
274
+ }
275
+ // TODO:#23442: When a revertible is cloned for a forked branch, optimize to create a fork of a revertible branch once per revision NOT once per revision per checkout.
276
+ const forkedCheckout = getCheckout(forkedBranch);
277
+ const revertibleBranch = this.revertibleCommitBranches.get(revision);
278
+ assert(revertibleBranch !== undefined, 0xa82 /* change to revert does not exist on the given forked branch */);
279
+ forkedCheckout.revertibleCommitBranches.set(revision, revertibleBranch.fork());
280
+ return this.createRevertible(revision, kind, forkedCheckout, onRevertibleDisposed);
281
+ },
282
+ dispose: () => {
283
+ if (revertible.status === RevertibleStatus.Disposed) {
284
+ throw new UsageError("Unable to dispose a revertible that has already been disposed.");
285
+ }
286
+ checkout.disposeRevertible(revertible, revision);
287
+ onRevertibleDisposed?.(revertible);
288
+ },
289
+ };
290
+ return revertible;
291
+ }
258
292
  viewWith(config) {
259
293
  const view = new SchematizingSimpleTreeView(this, config, createNodeKeyManager(this.idCompressor), this.breaker, () => {
260
294
  this.views.delete(view);
@@ -273,19 +307,23 @@ export class TreeCheckout {
273
307
  this.checkNotDisposed();
274
308
  return this.forest.anchors.locate(anchor);
275
309
  }
310
+ get transaction() {
311
+ return __classPrivateFieldGet(this, _TreeCheckout_transaction, "f");
312
+ }
276
313
  branch() {
277
314
  this.checkNotDisposed("The parent branch has already been disposed and can no longer create new branches.");
278
315
  const anchors = new AnchorSet();
279
316
  const branch = this._branch.fork();
280
317
  const storedSchema = this.storedSchema.clone();
281
318
  const forest = this.forest.clone(storedSchema, anchors);
282
- const transaction = new Transaction(branch);
283
- return new TreeCheckout(transaction, branch, true, this.changeFamily, storedSchema, forest, createEmitter(), this.mintRevisionTag, this.revisionTagCodec, this.idCompressor, this.removedRoots.clone(), this.logger, this.breaker);
319
+ const checkout = new TreeCheckout(branch, true, this.changeFamily, storedSchema, forest, createEmitter(), this.mintRevisionTag, this.revisionTagCodec, this.idCompressor, this.removedRoots.clone(), this.logger, this.breaker);
320
+ this.events.emit("fork", checkout);
321
+ return checkout;
284
322
  }
285
323
  rebase(checkout) {
286
324
  this.checkNotDisposed("The target of the branch rebase has been disposed and cannot be rebased.");
287
325
  checkout.checkNotDisposed("The source of the branch rebase has been disposed and cannot be rebased.");
288
- assert(!checkout.transaction.inProgress(), 0x9af /* A view cannot be rebased while it has a pending transaction */);
326
+ assert(!checkout.transaction.isInProgress(), 0x9af /* A view cannot be rebased while it has a pending transaction */);
289
327
  assert(checkout.isBranch, 0xa5d /* The main branch cannot be rebased onto another branch. */);
290
328
  checkout._branch.rebaseOnto(this._branch);
291
329
  }
@@ -296,8 +334,8 @@ export class TreeCheckout {
296
334
  merge(checkout, disposeMerged = true) {
297
335
  this.checkNotDisposed("The target of the branch merge has been disposed and cannot be merged.");
298
336
  checkout.checkNotDisposed("The source of the branch merge has been disposed and cannot be merged.");
299
- assert(!this.transaction.inProgress(), 0x9b0 /* Views cannot be merged into a view while it has a pending transaction */);
300
- while (checkout.transaction.inProgress()) {
337
+ assert(!this.transaction.isInProgress(), 0x9b0 /* Views cannot be merged into a view while it has a pending transaction */);
338
+ while (checkout.transaction.isInProgress()) {
301
339
  checkout.transaction.commit();
302
340
  }
303
341
  this._branch.merge(checkout._branch);
@@ -313,14 +351,16 @@ export class TreeCheckout {
313
351
  dispose() {
314
352
  this[disposeSymbol]();
315
353
  }
316
- [disposeSymbol]() {
354
+ [(_TreeCheckout_transaction = new WeakMap(), disposeSymbol)]() {
317
355
  this.checkNotDisposed("The branch has already been disposed and cannot be disposed again.");
318
356
  this.disposed = true;
357
+ __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").dispose();
319
358
  this.purgeRevertibles();
320
359
  this._branch.dispose();
321
360
  for (const view of this.views) {
322
361
  view.dispose();
323
362
  }
363
+ this.events.emit("dispose");
324
364
  }
325
365
  getRemovedRoots() {
326
366
  this.assertNoUntrackedRoots();
@@ -356,7 +396,7 @@ export class TreeCheckout {
356
396
  this.revertibles.delete(revertible);
357
397
  }
358
398
  revertRevertible(revision, kind) {
359
- if (this._branch.isTransacting()) {
399
+ if (this.transaction.isInProgress()) {
360
400
  throw new UsageError("Undo is not yet supported during transactions.");
361
401
  }
362
402
  const revertibleBranch = this.revertibleCommitBranches.get(revision);
@@ -403,13 +443,12 @@ export class TreeCheckout {
403
443
  */
404
444
  isRemoteChangeEvent(event) {
405
445
  return (
406
- // remote changes are only ever applied to the main branch
446
+ // Remote changes are only ever applied to the main branch
407
447
  !this.isBranch &&
408
- // remote changes are applied to the main branch by rebasing it onto the trunk,
409
- // no other rebases are allowed on the main branch so this means any replaces that are not
410
- // transaction commits are remote changes
448
+ // Remote changes are applied to the main branch by rebasing it onto the trunk.
449
+ // No other rebases are allowed on the main branch, so we can use this to detect remote changes.
411
450
  event.type === "replace" &&
412
- getChangeReplaceType(event) !== "transactionCommit");
451
+ getChangeReplaceType(event) === "rebase");
413
452
  }
414
453
  }
415
454
  /**
@@ -417,19 +456,4 @@ export class TreeCheckout {
417
456
  * @privateRemarks Exposed for testing purposes.
418
457
  */
419
458
  TreeCheckout.revertTelemetryEventName = "RevertRevertible";
420
- /**
421
- * Run a synchronous transaction on the given shared tree view.
422
- * This is a convenience helper around the {@link SharedTreeFork#transaction} APIs.
423
- * @param view - the view on which to run the transaction
424
- * @param transaction - the transaction function. This will be executed immediately. It is passed `view` as an argument for convenience.
425
- * If this function returns an `Abort` result then the transaction will be aborted. Otherwise, it will be committed.
426
- * @returns whether or not the transaction was committed or aborted
427
- */
428
- export function runSynchronous(view, transaction) {
429
- view.transaction.start();
430
- const result = transaction(view);
431
- return result === TransactionResult.Abort
432
- ? view.transaction.abort()
433
- : view.transaction.commit();
434
- }
435
459
  //# sourceMappingURL=treeCheckout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"treeCheckout.js","sourceRoot":"","sources":["../../src/shared-tree/treeCheckout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAA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E,CAAC;IACzB,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,OAAO,MAAM,KAAK,iBAAiB,CAAC,KAAK;QACxC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE;QAC1B,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;AAC9B,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 { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport {\n\tUsageError,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { noopValidator } from \"../codec/index.js\";\nimport {\n\ttype Anchor,\n\ttype AnchorLocator,\n\ttype AnchorNode,\n\tAnchorSet,\n\ttype AnchorSetRootEvents,\n\ttype ChangeFamily,\n\tCommitKind,\n\ttype CommitMetadata,\n\ttype DeltaVisitor,\n\ttype DetachedFieldIndex,\n\ttype IEditableForest,\n\ttype IForestSubscription,\n\ttype JsonableTree,\n\ttype Revertible,\n\tRevertibleStatus,\n\ttype RevisionTag,\n\ttype RevisionTagCodec,\n\ttype TreeStoredSchema,\n\tTreeStoredSchemaRepository,\n\ttype TreeStoredSchemaSubscription,\n\tcombineVisitors,\n\tmakeDetachedFieldIndex,\n\trebaseChange,\n\trootFieldKey,\n\ttagChange,\n\tvisitDelta,\n\ttype RevertibleFactory,\n} from \"../core/index.js\";\nimport {\n\ttype HasListeners,\n\ttype IEmitter,\n\ttype Listenable,\n\tcreateEmitter,\n} from \"../events/index.js\";\nimport {\n\ttype FieldBatchCodec,\n\ttype TreeCompressionStrategy,\n\tbuildForest,\n\tcreateNodeKeyManager,\n\tintoDelta,\n\tjsonableTreeFromCursor,\n\tmakeFieldBatchCodec,\n} from \"../feature-libraries/index.js\";\nimport {\n\tSharedTreeBranch,\n\tgetChangeReplaceType,\n\ttype SharedTreeBranchChange,\n} from \"../shared-tree-core/index.js\";\nimport { Breakable, TransactionResult, disposeSymbol, fail } from \"../util/index.js\";\n\nimport { SharedTreeChangeFamily, hasSchemaChange } from \"./sharedTreeChangeFamily.js\";\nimport type { SharedTreeChange } from \"./sharedTreeChangeTypes.js\";\nimport type { ISharedTreeEditor, SharedTreeEditBuilder } from \"./sharedTreeEditBuilder.js\";\nimport type { IDisposable } from \"@fluidframework/core-interfaces\";\nimport type {\n\tImplicitFieldSchema,\n\tReadSchema,\n\tTreeView,\n\tTreeViewConfiguration,\n\tUnsafeUnknownSchema,\n\tViewableTree,\n} from \"../simple-tree/index.js\";\nimport { SchematizingSimpleTreeView } from \"./schematizingTreeView.js\";\n\n/**\n * Events for {@link ITreeCheckout}.\n */\nexport interface CheckoutEvents {\n\t/**\n\t * A batch of changes has finished processing and the view is in a consistent state.\n\t * It is once again safe to access the FlexTree, Forest and AnchorSet.\n\t *\n\t * @remarks\n\t * This is mainly useful for knowing when to do followup work scheduled during events from Anchors.\n\t */\n\tafterBatch(): void;\n\n\t/**\n\t * Fired when a change is made to the branch. Includes data about the change that is made which listeners\n\t * can use to filter on changes they care about e.g. local vs remote changes.\n\t *\n\t * @param data - information about the change\n\t * @param getRevertible - a function provided that allows users to get a revertible for the change. If not provided,\n\t * this change is not revertible.\n\t */\n\tchanged(data: CommitMetadata, getRevertible?: RevertibleFactory): void;\n}\n\n/**\n * A \"version control\"-style branch of a SharedTree.\n * @remarks Branches may be used to coordinate edits to a SharedTree, e.g. via merge and rebase operations.\n * Changes applied to a branch of a branch only apply to that branch and are isolated from other branches.\n * Changes may be synchronized across branches via merge and rebase operations provided on the branch object.\n * @alpha @sealed\n */\nexport interface BranchableTree extends ViewableTree {\n\t/**\n\t * Spawn a new branch which is based off of the current state of this branch.\n\t * Any mutations of the new branch will not apply to this branch until the new branch is merged back into this branch via `merge()`.\n\t */\n\tbranch(): TreeBranchFork;\n\n\t/**\n\t * Apply all the new changes on the given branch to this branch.\n\t * @param view - a branch which was created by a call to `branch()`.\n\t * It is automatically disposed after the merge completes.\n\t * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.\n\t * A \"changed\" event and a corresponding {@link Revertible} will be emitted on this branch for each new change merged from 'branch'.\n\t */\n\tmerge(branch: TreeBranchFork): void;\n\n\t/**\n\t * Apply all the new changes on the given branch to this branch.\n\t * @param branch - a branch which was created by a call to `branch()`.\n\t * @param disposeMerged - whether or not to dispose `branch` after the merge completes.\n\t * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.\n\t */\n\tmerge(branch: TreeBranchFork, disposeMerged: boolean): void;\n\n\t/**\n\t * Rebase the given branch onto this branch.\n\t * @param branch - a branch which was created by a call to `branch()`. It is modified by this operation.\n\t */\n\trebase(branch: TreeBranchFork): void;\n}\n\n/**\n * A {@link BranchableTree | branch} of a SharedTree that has merged from another branch.\n * @remarks This branch should be disposed when it is no longer needed in order to free resources.\n * @alpha @sealed\n */\nexport interface TreeBranchFork extends BranchableTree, IDisposable {\n\t/**\n\t * Rebase the changes that have been applied to this branch over all the new changes in the given branch.\n\t * @param branch - Either the root branch or a branch that was created by a call to `branch()`. It is not modified by this operation.\n\t */\n\trebaseOnto(branch: BranchableTree): void;\n}\n\n/**\n * Provides a means for interacting with a SharedTree.\n * This includes reading data from the tree and running transactions to mutate the tree.\n * @remarks This interface should not have any implementations other than those provided by the SharedTree package libraries.\n * @privateRemarks\n * API for interacting with a {@link SharedTreeBranch}.\n * Implementations of this interface must implement the {@link branchKey} property.\n */\nexport interface ITreeCheckout extends AnchorLocator, ViewableTree {\n\t/**\n\t * Read and Write access for schema stored in the document.\n\t *\n\t * These APIs are temporary and will be replaced with different abstractions (View Schema based) in a different place later.\n\t *\n\t * TODO:\n\t * Editing of this should be moved into transactions with the rest of tree editing to they can be intermixed.\n\t * This will be done after the relations between views, branches and Indexes are figured out.\n\t *\n\t * TODO:\n\t * Public APIs for dealing with schema should be in terms of View Schema, and schema update policies.\n\t * The actual stored schema should be hidden (or ar least not be the most prominent way to interact with schema).\n\t *\n\t * TODO:\n\t * Something should ensure the document contents are always in schema.\n\t */\n\treadonly storedSchema: TreeStoredSchemaSubscription;\n\t/**\n\t * Current contents.\n\t * Updated by edits (local and remote).\n\t * Use `editor` to create a local edit.\n\t */\n\treadonly forest: IForestSubscription;\n\n\t/**\n\t * Used to edit the state of the tree. Edits will be immediately applied locally to the tree.\n\t * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.\n\t */\n\treadonly editor: ISharedTreeEditor;\n\n\t/**\n\t * A collection of functions for managing transactions.\n\t */\n\treadonly transaction: ITransaction;\n\n\tbranch(): ITreeCheckoutFork;\n\n\tmerge(checkout: ITreeCheckoutFork): void;\n\n\tmerge(checkout: ITreeCheckoutFork, disposeMerged: boolean): void;\n\n\trebase(checkout: ITreeCheckoutFork): void;\n\n\t/**\n\t * Replaces all schema with the provided schema.\n\t * Can over-write preexisting schema, and removes unmentioned schema.\n\t */\n\tupdateSchema(newSchema: TreeStoredSchema): void;\n\n\t/**\n\t * Events about this view.\n\t */\n\treadonly events: Listenable<CheckoutEvents>;\n\n\t/**\n\t * Events about the root of the tree in this view.\n\t */\n\treadonly rootEvents: Listenable<AnchorSetRootEvents>;\n\n\t/**\n\t * Returns a JsonableTree for each tree that was removed from (and not restored to) the document.\n\t * This list is guaranteed to contain all nodes that are recoverable through undo/redo on this checkout.\n\t * The list may also contain additional nodes.\n\t *\n\t * This is only intended for use in testing and exceptional code paths: it is not performant.\n\t */\n\tgetRemovedRoots(): [string | number | undefined, number, JsonableTree][];\n}\n\n/**\n * Creates a {@link TreeCheckout}.\n * @param args - an object containing optional components that will be used to build the view.\n * Any components not provided will be created by default.\n * @remarks This does not create a {@link SharedTree}, but rather a view with the minimal state\n * and functionality required to implement {@link ITreeCheckout}.\n */\nexport function createTreeCheckout(\n\tidCompressor: IIdCompressor,\n\tmintRevisionTag: () => RevisionTag,\n\trevisionTagCodec: RevisionTagCodec,\n\targs?: {\n\t\tbranch?: SharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>;\n\t\tchangeFamily?: ChangeFamily<SharedTreeEditBuilder, SharedTreeChange>;\n\t\tschema?: TreeStoredSchemaRepository;\n\t\tforest?: IEditableForest;\n\t\tfieldBatchCodec?: FieldBatchCodec;\n\t\tevents?: Listenable<CheckoutEvents> &\n\t\t\tIEmitter<CheckoutEvents> &\n\t\t\tHasListeners<CheckoutEvents>;\n\t\tremovedRoots?: DetachedFieldIndex;\n\t\tchunkCompressionStrategy?: TreeCompressionStrategy;\n\t\tlogger?: ITelemetryLoggerExt;\n\t\tbreaker?: Breakable;\n\t},\n): TreeCheckout {\n\tconst forest = args?.forest ?? buildForest();\n\tconst schema = args?.schema ?? new TreeStoredSchemaRepository();\n\tconst defaultCodecOptions = { jsonValidator: noopValidator };\n\tconst defaultFieldBatchVersion = 1;\n\tconst changeFamily =\n\t\targs?.changeFamily ??\n\t\tnew SharedTreeChangeFamily(\n\t\t\trevisionTagCodec,\n\t\t\targs?.fieldBatchCodec ??\n\t\t\t\tmakeFieldBatchCodec(defaultCodecOptions, defaultFieldBatchVersion),\n\t\t\t{ jsonValidator: noopValidator },\n\t\t\targs?.chunkCompressionStrategy,\n\t\t\tidCompressor,\n\t\t);\n\tconst branch =\n\t\targs?.branch ??\n\t\tnew SharedTreeBranch(\n\t\t\t{\n\t\t\t\tchange: changeFamily.rebaser.compose([]),\n\t\t\t\trevision: \"root\",\n\t\t\t},\n\t\t\tchangeFamily,\n\t\t\t() => idCompressor.generateCompressedId(),\n\t\t);\n\tconst events = args?.events ?? createEmitter();\n\n\tconst transaction = new Transaction(branch);\n\n\treturn new TreeCheckout(\n\t\ttransaction,\n\t\tbranch,\n\t\tfalse,\n\t\tchangeFamily,\n\t\tschema,\n\t\tforest,\n\t\tevents,\n\t\tmintRevisionTag,\n\t\trevisionTagCodec,\n\t\tidCompressor,\n\t\targs?.removedRoots,\n\t\targs?.logger,\n\t\targs?.breaker,\n\t);\n}\n\n/**\n * A collection of functions for managing transactions.\n * Transactions allow edits to be batched into atomic units.\n * Edits made during a transaction will update the local state of the tree immediately, but will be squashed into a single edit when the transaction is committed.\n * If the transaction is aborted, the local state will be reset to what it was before the transaction began.\n * Transactions may nest, meaning that a transaction may be started while a transaction is already ongoing.\n *\n * To avoid updating observers of the view state with intermediate results during a transaction,\n * use {@link ITreeCheckout#branch} and {@link ISharedTreeFork#merge}.\n */\nexport interface ITransaction {\n\t/**\n\t * Start a new transaction.\n\t * If a transaction is already in progress when this new transaction starts, then this transaction will be \"nested\" inside of it,\n\t * i.e. the outer transaction will still be in progress after this new transaction is committed or aborted.\n\t *\n\t * @remarks - Asynchronous transactions are not supported on the root checkout,\n\t * since it is always kept up-to-date with the latest remote edits and the results of this rebasing (which might invalidate\n\t * the transaction) is not visible to the application author.\n\t * Instead,\n\t *\n\t * 1. fork the root checkout\n\t * 2. run the transaction on the fork\n\t * 3. merge the fork back into the root checkout\n\t *\n\t * @privateRemarks - There is currently no enforcement that asynchronous transactions don't happen on the root checkout.\n\t * AB#6488 tracks adding some enforcement to make it more clear to application authors that this is not supported.\n\t */\n\tstart(): void;\n\t/**\n\t * Close this transaction by squashing its edits and committing them as a single edit.\n\t * If this is the root checkout and there are no ongoing transactions remaining, the squashed edit will be submitted to Fluid.\n\t */\n\tcommit(): TransactionResult.Commit;\n\t/**\n\t * Close this transaction and revert the state of the tree to what it was before this transaction began.\n\t */\n\tabort(): TransactionResult.Abort;\n\t/**\n\t * True if there is at least one transaction currently in progress on this view, otherwise false.\n\t */\n\tinProgress(): boolean;\n}\n\nclass Transaction implements ITransaction {\n\tpublic constructor(\n\t\tprivate readonly branch: SharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>,\n\t) {}\n\n\tpublic start(): void {\n\t\tthis.branch.startTransaction();\n\t\tthis.branch.editor.enterTransaction();\n\t}\n\tpublic commit(): TransactionResult.Commit {\n\t\tthis.branch.commitTransaction();\n\t\tthis.branch.editor.exitTransaction();\n\t\treturn TransactionResult.Commit;\n\t}\n\tpublic abort(): TransactionResult.Abort {\n\t\tthis.branch.abortTransaction();\n\t\tthis.branch.editor.exitTransaction();\n\t\treturn TransactionResult.Abort;\n\t}\n\tpublic inProgress(): boolean {\n\t\treturn this.branch.isTransacting();\n\t}\n}\n\n/**\n * Branch (like in a version control system) of SharedTree.\n *\n * {@link ITreeCheckout} that has forked off of the main trunk/branch.\n */\nexport interface ITreeCheckoutFork extends ITreeCheckout {\n\trebaseOnto(view: ITreeCheckout): void;\n}\n\n/**\n * Metrics derived from a revert operation.\n *\n * @see {@link TreeCheckout.revertRevertible}.\n */\nexport interface RevertMetrics {\n\t/**\n\t * The age of the revertible commit relative to the head of the branch to which the reversion will be applied.\n\t */\n\treadonly age: number;\n\n\t// TODO: add other stats as needed for telemetry, etc.\n}\n\n/**\n * An implementation of {@link ITreeCheckoutFork}.\n */\nexport class TreeCheckout implements ITreeCheckoutFork {\n\tpublic disposed = false;\n\n\tprivate readonly views = new Set<TreeView<ImplicitFieldSchema>>();\n\n\t/**\n\t * Set of revertibles maintained for automatic disposal\n\t */\n\tprivate readonly revertibles = new Set<DisposableRevertible>();\n\n\t/**\n\t * Each branch's head commit corresponds to a revertible commit.\n\t * Maintaining a whole branch ensures the commit graph is not pruned in a way that would prevent the commit from\n\t * being reverted.\n\t */\n\tprivate readonly revertibleCommitBranches = new Map<\n\t\tRevisionTag,\n\t\tSharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>\n\t>();\n\n\t/**\n\t * copies of the removed roots used as snapshots for reverting to previous state when transactions are aborted\n\t */\n\tprivate readonly removedRootsSnapshots: DetachedFieldIndex[] = [];\n\n\t/**\n\t * The name of the telemetry event logged for calls to {@link TreeCheckout.revertRevertible}.\n\t * @privateRemarks Exposed for testing purposes.\n\t */\n\tpublic static readonly revertTelemetryEventName = \"RevertRevertible\";\n\n\tpublic constructor(\n\t\tpublic readonly transaction: ITransaction,\n\t\tprivate readonly _branch: SharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>,\n\t\t/** True if and only if this checkout is for a forked branch and not the \"main branch\" of the tree. */\n\t\tpublic readonly isBranch: boolean,\n\t\tprivate readonly changeFamily: ChangeFamily<SharedTreeEditBuilder, SharedTreeChange>,\n\t\tpublic readonly storedSchema: TreeStoredSchemaRepository,\n\t\tpublic readonly forest: IEditableForest,\n\t\tpublic readonly events: Listenable<CheckoutEvents> &\n\t\t\tIEmitter<CheckoutEvents> &\n\t\t\tHasListeners<CheckoutEvents>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t\tprivate removedRoots: DetachedFieldIndex = makeDetachedFieldIndex(\n\t\t\t\"repair\",\n\t\t\trevisionTagCodec,\n\t\t\tidCompressor,\n\t\t),\n\t\t/** Optional logger for telemetry. */\n\t\tprivate readonly logger?: ITelemetryLoggerExt,\n\t\tprivate readonly breaker: Breakable = new Breakable(\"TreeCheckout\"),\n\t) {\n\t\t// when a transaction is started, take a snapshot of the current state of removed roots\n\t\t_branch.events.on(\"transactionStarted\", () => {\n\t\t\tthis.removedRootsSnapshots.push(this.removedRoots.clone());\n\t\t});\n\t\t// when a transaction is committed, the latest snapshot of removed roots can be discarded\n\t\t_branch.events.on(\"transactionCommitted\", () => {\n\t\t\tthis.removedRootsSnapshots.pop();\n\t\t});\n\t\t// after a transaction is rolled back, revert removed roots back to the latest snapshot\n\t\t_branch.events.on(\"transactionRolledBack\", () => {\n\t\t\tconst snapshot = this.removedRootsSnapshots.pop();\n\t\t\tassert(snapshot !== undefined, 0x9ae /* a snapshot for removed roots does not exist */);\n\t\t\tthis.removedRoots = snapshot;\n\t\t});\n\n\t\t// We subscribe to `beforeChange` rather than `afterChange` here because it's possible that the change is invalid WRT our forest.\n\t\t// For example, a bug in the editor might produce a malformed change object and thus applying the change to the forest will throw an error.\n\t\t// In such a case we will crash here, preventing the change from being added to the commit graph, and preventing `afterChange` from firing.\n\t\t// One important consequence of this is that we will not submit the op containing the invalid change, since op submissions happens in response to `afterChange`.\n\t\t_branch.events.on(\"beforeChange\", (event) => {\n\t\t\tif (event.change !== undefined) {\n\t\t\t\tconst revision =\n\t\t\t\t\tevent.type === \"replace\"\n\t\t\t\t\t\t? // Change events will always contain new commits\n\t\t\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\t\t\tevent.newCommits[event.newCommits.length - 1]!.revision\n\t\t\t\t\t\t: event.change.revision;\n\n\t\t\t\t// Conflicts due to schema will be empty and thus are not applied.\n\t\t\t\tfor (const change of event.change.change.changes) {\n\t\t\t\t\tif (change.type === \"data\") {\n\t\t\t\t\t\tconst delta = intoDelta(tagChange(change.innerChange, revision));\n\t\t\t\t\t\tthis.withCombinedVisitor((visitor) => {\n\t\t\t\t\t\t\tvisitDelta(delta, visitor, this.removedRoots, revision);\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (change.type === \"schema\") {\n\t\t\t\t\t\t// Schema changes from a current to a new schema are expected to be backwards compatible.\n\t\t\t\t\t\t// This guarantees that all data in the forest (which is valid before the schema change)\n\t\t\t\t\t\t// is also valid under the new schema.\n\t\t\t\t\t\t// Note however, that such schema changes may in some cases be rolled back:\n\t\t\t\t\t\t// Case 1: A transaction with a schema change may be aborted.\n\t\t\t\t\t\t// The transaction may have made some data changes that would render some trees invalid\n\t\t\t\t\t\t// under the old schema, but these changes will also be rolled back, thereby putting the forest\n\t\t\t\t\t\t// back in the state before the transaction, which is valid under the original (reinstated) schema.\n\t\t\t\t\t\t// Case 2: A branch with a schema change may be rebased such that the schema change (because\n\t\t\t\t\t\t// of a constraint) is no longer applied.\n\t\t\t\t\t\t// Such a branch may contain data changes that would render some trees invalid under the\n\t\t\t\t\t\t// original schema. These data changes may not necessarily be rolled back.\n\t\t\t\t\t\t// They will however be rebased over the rollback of the schema change. This rebasing will\n\t\t\t\t\t\t// ensure that these data changes are muted if they would render some trees invalid under the\n\t\t\t\t\t\t// original (reinstated) schema.\n\t\t\t\t\t\tstoredSchema.apply(change.innerChange.schema.new);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfail(\"Unknown Shared Tree change type.\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.events.emit(\"afterBatch\");\n\t\t\t}\n\t\t\tif (event.type === \"replace\" && getChangeReplaceType(event) === \"transactionCommit\") {\n\t\t\t\tconst firstCommit = event.newCommits[0] ?? oob();\n\t\t\t\tconst transactionRevision = firstCommit.revision;\n\t\t\t\tfor (const transactionStep of event.removedCommits) {\n\t\t\t\t\tthis.removedRoots.updateMajor(transactionStep.revision, transactionRevision);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\t_branch.events.on(\"afterChange\", (event) => {\n\t\t\t// The following logic allows revertibles to be generated for the change.\n\t\t\t// Currently only appends (including merges) and transaction commits are supported.\n\t\t\tif (!_branch.isTransacting()) {\n\t\t\t\tif (\n\t\t\t\t\tevent.type === \"append\" ||\n\t\t\t\t\t(event.type === \"replace\" && getChangeReplaceType(event) === \"transactionCommit\")\n\t\t\t\t) {\n\t\t\t\t\t// TODO:#20949: When the SharedTree is detached, these commits will already have been garbage collected.\n\t\t\t\t\t// Figure out a way to generate revertibles before the commits are garbage collected.\n\t\t\t\t\tfor (const commit of event.newCommits) {\n\t\t\t\t\t\tconst kind = event.type === \"append\" ? event.kind : CommitKind.Default;\n\t\t\t\t\t\tconst { change, revision } = commit;\n\n\t\t\t\t\t\tconst getRevertible = hasSchemaChange(change)\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: (onRevertibleDisposed?: (revertible: Revertible) => void) => {\n\t\t\t\t\t\t\t\t\tif (!withinEventContext) {\n\t\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t\t\"Cannot get a revertible outside of the context of a changed event.\",\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (this.revertibleCommitBranches.get(revision) !== undefined) {\n\t\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t\t\"Cannot generate the same revertible more than once. Note that this can happen when multiple changed event listeners are registered.\",\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst revertibleCommits = this.revertibleCommitBranches;\n\t\t\t\t\t\t\t\t\tconst revertible: DisposableRevertible = {\n\t\t\t\t\t\t\t\t\t\tget status(): RevertibleStatus {\n\t\t\t\t\t\t\t\t\t\t\tconst revertibleCommit = revertibleCommits.get(revision);\n\t\t\t\t\t\t\t\t\t\t\treturn revertibleCommit === undefined\n\t\t\t\t\t\t\t\t\t\t\t\t? RevertibleStatus.Disposed\n\t\t\t\t\t\t\t\t\t\t\t\t: RevertibleStatus.Valid;\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\trevert: (release: boolean = true) => {\n\t\t\t\t\t\t\t\t\t\t\tif (revertible.status === RevertibleStatus.Disposed) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Unable to revert a revertible that has been disposed.\",\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tconst revertMetrics = this.revertRevertible(revision, kind);\n\t\t\t\t\t\t\t\t\t\t\tthis.logger?.sendTelemetryEvent({\n\t\t\t\t\t\t\t\t\t\t\t\teventName: TreeCheckout.revertTelemetryEventName,\n\t\t\t\t\t\t\t\t\t\t\t\t...revertMetrics,\n\t\t\t\t\t\t\t\t\t\t\t});\n\n\t\t\t\t\t\t\t\t\t\t\tif (release) {\n\t\t\t\t\t\t\t\t\t\t\t\trevertible.dispose();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\tdispose: () => {\n\t\t\t\t\t\t\t\t\t\t\tif (revertible.status === RevertibleStatus.Disposed) {\n\t\t\t\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Unable to dispose a revertible that has already been disposed.\",\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tthis.disposeRevertible(revertible, revision);\n\t\t\t\t\t\t\t\t\t\t\tonRevertibleDisposed?.(revertible);\n\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\t\t\t\tthis.revertibleCommitBranches.set(revision, _branch.fork(commit));\n\t\t\t\t\t\t\t\t\tthis.revertibles.add(revertible);\n\t\t\t\t\t\t\t\t\treturn revertible;\n\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\tlet withinEventContext = true;\n\t\t\t\t\t\tthis.events.emit(\"changed\", { isLocal: true, kind }, getRevertible);\n\t\t\t\t\t\twithinEventContext = false;\n\t\t\t\t\t}\n\t\t\t\t} else if (this.isRemoteChangeEvent(event)) {\n\t\t\t\t\t// TODO: figure out how to plumb through commit kind info for remote changes\n\t\t\t\t\tthis.events.emit(\"changed\", { isLocal: false, kind: CommitKind.Default });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// When the branch is trimmed, we can garbage collect any repair data whose latest relevant revision is one of the\n\t\t// trimmed revisions.\n\t\t_branch.events.on(\"ancestryTrimmed\", (revisions) => {\n\t\t\tthis.withCombinedVisitor((visitor) => {\n\t\t\t\trevisions.forEach((revision) => {\n\t\t\t\t\t// get all the roots last created or used by the revision\n\t\t\t\t\tconst roots = this.removedRoots.getRootsLastTouchedByRevision(revision);\n\n\t\t\t\t\t// get the detached field for the root and delete it from the removed roots\n\t\t\t\t\tfor (const root of roots) {\n\t\t\t\t\t\tvisitor.destroy(this.removedRoots.toFieldKey(root), 1);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.removedRoots.deleteRootsLastTouchedByRevision(revision);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate withCombinedVisitor(fn: (visitor: DeltaVisitor) => void): void {\n\t\tconst anchorVisitor = this.forest.anchors.acquireVisitor();\n\t\tconst combinedVisitor = combineVisitors(\n\t\t\t[this.forest.acquireVisitor(), anchorVisitor],\n\t\t\t[anchorVisitor],\n\t\t);\n\t\tfn(combinedVisitor);\n\t\tcombinedVisitor.free();\n\t}\n\n\tprivate checkNotDisposed(usageError?: string): void {\n\t\tif (this.disposed) {\n\t\t\tif (usageError !== undefined) {\n\t\t\t\tthrow new UsageError(usageError);\n\t\t\t}\n\t\t\tassert(false, 0x911 /* Invalid operation on a disposed TreeCheckout */);\n\t\t}\n\t}\n\n\t// For the new TreeViewAlpha API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot>;\n\n\t// For the old TreeView API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot> {\n\t\tconst view = new SchematizingSimpleTreeView(\n\t\t\tthis,\n\t\t\tconfig,\n\t\t\tcreateNodeKeyManager(this.idCompressor),\n\t\t\tthis.breaker,\n\t\t\t() => {\n\t\t\t\tthis.views.delete(view);\n\t\t\t},\n\t\t);\n\t\tthis.views.add(view);\n\t\treturn view;\n\t}\n\n\tpublic get rootEvents(): Listenable<AnchorSetRootEvents> {\n\t\treturn this.forest.anchors.events;\n\t}\n\n\tpublic get editor(): ISharedTreeEditor {\n\t\tthis.checkNotDisposed();\n\t\treturn this._branch.editor;\n\t}\n\n\tpublic locate(anchor: Anchor): AnchorNode | undefined {\n\t\tthis.checkNotDisposed();\n\t\treturn this.forest.anchors.locate(anchor);\n\t}\n\n\tpublic branch(): TreeCheckout {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The parent branch has already been disposed and can no longer create new branches.\",\n\t\t);\n\t\tconst anchors = new AnchorSet();\n\t\tconst branch = this._branch.fork();\n\t\tconst storedSchema = this.storedSchema.clone();\n\t\tconst forest = this.forest.clone(storedSchema, anchors);\n\t\tconst transaction = new Transaction(branch);\n\t\treturn new TreeCheckout(\n\t\t\ttransaction,\n\t\t\tbranch,\n\t\t\ttrue,\n\t\t\tthis.changeFamily,\n\t\t\tstoredSchema,\n\t\t\tforest,\n\t\t\tcreateEmitter(),\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.revisionTagCodec,\n\t\t\tthis.idCompressor,\n\t\t\tthis.removedRoots.clone(),\n\t\t\tthis.logger,\n\t\t\tthis.breaker,\n\t\t);\n\t}\n\n\tpublic rebase(checkout: TreeCheckout): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The target of the branch rebase has been disposed and cannot be rebased.\",\n\t\t);\n\t\tcheckout.checkNotDisposed(\n\t\t\t\"The source of the branch rebase has been disposed and cannot be rebased.\",\n\t\t);\n\t\tassert(\n\t\t\t!checkout.transaction.inProgress(),\n\t\t\t0x9af /* A view cannot be rebased while it has a pending transaction */,\n\t\t);\n\t\tassert(\n\t\t\tcheckout.isBranch,\n\t\t\t0xa5d /* The main branch cannot be rebased onto another branch. */,\n\t\t);\n\t\tcheckout._branch.rebaseOnto(this._branch);\n\t}\n\n\tpublic rebaseOnto(checkout: ITreeCheckout): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The target of the branch rebase has been disposed and cannot be rebased.\",\n\t\t);\n\t\tcheckout.rebase(this);\n\t}\n\n\tpublic merge(checkout: TreeCheckout): void;\n\tpublic merge(checkout: TreeCheckout, disposeMerged: boolean): void;\n\tpublic merge(checkout: TreeCheckout, disposeMerged = true): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The target of the branch merge has been disposed and cannot be merged.\",\n\t\t);\n\t\tcheckout.checkNotDisposed(\n\t\t\t\"The source of the branch merge has been disposed and cannot be merged.\",\n\t\t);\n\t\tassert(\n\t\t\t!this.transaction.inProgress(),\n\t\t\t0x9b0 /* Views cannot be merged into a view while it has a pending transaction */,\n\t\t);\n\t\twhile (checkout.transaction.inProgress()) {\n\t\t\tcheckout.transaction.commit();\n\t\t}\n\t\tthis._branch.merge(checkout._branch);\n\t\tif (disposeMerged && checkout.isBranch) {\n\t\t\t// Dispose the merged checkout unless it is the main branch.\n\t\t\tcheckout[disposeSymbol]();\n\t\t}\n\t}\n\n\tpublic updateSchema(newSchema: TreeStoredSchema): void {\n\t\tthis.checkNotDisposed();\n\t\tthis.editor.schema.setStoredSchema(this.storedSchema.clone(), newSchema);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis[disposeSymbol]();\n\t}\n\n\tpublic [disposeSymbol](): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The branch has already been disposed and cannot be disposed again.\",\n\t\t);\n\t\tthis.disposed = true;\n\t\tthis.purgeRevertibles();\n\t\tthis._branch.dispose();\n\t\tfor (const view of this.views) {\n\t\t\tview.dispose();\n\t\t}\n\t}\n\n\tpublic getRemovedRoots(): [string | number | undefined, number, JsonableTree][] {\n\t\tthis.assertNoUntrackedRoots();\n\t\tconst trees: [string | number | undefined, number, JsonableTree][] = [];\n\t\tconst cursor = this.forest.allocateCursor(\"getRemovedRoots\");\n\t\tfor (const { id, root } of this.removedRoots.entries()) {\n\t\t\tconst parentField = this.removedRoots.toFieldKey(root);\n\t\t\tthis.forest.moveCursorToPath({ parent: undefined, parentField, parentIndex: 0 }, cursor);\n\t\t\tconst tree = jsonableTreeFromCursor(cursor);\n\t\t\t// This method is used for tree consistency comparison.\n\t\t\tconst { major, minor } = id;\n\t\t\tconst finalizedMajor = major !== undefined ? this.revisionTagCodec.encode(major) : major;\n\t\t\ttrees.push([finalizedMajor, minor, tree]);\n\t\t}\n\t\tcursor.free();\n\t\treturn trees;\n\t}\n\n\t/**\n\t * This sets the tip revision as the latest relevant revision for any removed roots that are loaded from a summary.\n\t * This needs to be called right after loading {@link this.removedRoots} from a summary to allow loaded data to be garbage collected.\n\t */\n\tpublic setTipRevisionForLoadedData(revision: RevisionTag): void {\n\t\tthis.removedRoots.setRevisionsForLoadedData(revision);\n\t}\n\n\tprivate purgeRevertibles(): void {\n\t\tfor (const revertible of this.revertibles) {\n\t\t\trevertible.dispose();\n\t\t}\n\t}\n\n\tprivate disposeRevertible(revertible: DisposableRevertible, revision: RevisionTag): void {\n\t\tthis.revertibleCommitBranches.get(revision)?.dispose();\n\t\tthis.revertibleCommitBranches.delete(revision);\n\t\tthis.revertibles.delete(revertible);\n\t}\n\n\tprivate revertRevertible(revision: RevisionTag, kind: CommitKind): RevertMetrics {\n\t\tif (this._branch.isTransacting()) {\n\t\t\tthrow new UsageError(\"Undo is not yet supported during transactions.\");\n\t\t}\n\n\t\tconst revertibleBranch = this.revertibleCommitBranches.get(revision);\n\t\tassert(revertibleBranch !== undefined, 0x7cc /* expected to find a revertible commit */);\n\t\tconst commitToRevert = revertibleBranch.getHead();\n\t\tconst revisionForInvert = this.mintRevisionTag();\n\n\t\tlet change = tagChange(\n\t\t\tthis.changeFamily.rebaser.invert(commitToRevert, false, revisionForInvert),\n\t\t\trevisionForInvert,\n\t\t);\n\n\t\tconst headCommit = this._branch.getHead();\n\t\t// Rebase the inverted change onto any commits that occurred after the undoable commits.\n\t\tif (commitToRevert !== headCommit) {\n\t\t\tchange = tagChange(\n\t\t\t\trebaseChange(\n\t\t\t\t\tthis.changeFamily.rebaser,\n\t\t\t\t\tchange,\n\t\t\t\t\tcommitToRevert,\n\t\t\t\t\theadCommit,\n\t\t\t\t\tthis.mintRevisionTag,\n\t\t\t\t).change,\n\t\t\t\trevisionForInvert,\n\t\t\t);\n\t\t}\n\n\t\tthis._branch.apply(\n\t\t\tchange,\n\t\t\tkind === CommitKind.Default || kind === CommitKind.Redo\n\t\t\t\t? CommitKind.Undo\n\t\t\t\t: CommitKind.Redo,\n\t\t);\n\n\t\t// Derive some stats about the reversion to return to the caller.\n\t\tlet revertAge = 0;\n\t\tlet currentCommit = headCommit;\n\t\twhile (commitToRevert.revision !== currentCommit.revision) {\n\t\t\trevertAge++;\n\n\t\t\tconst parentCommit = currentCommit.parent;\n\t\t\tassert(parentCommit !== undefined, 0x9a9 /* expected to find a parent commit */);\n\t\t\tcurrentCommit = parentCommit;\n\t\t}\n\n\t\treturn { age: revertAge };\n\t}\n\n\tprivate assertNoUntrackedRoots(): void {\n\t\tconst cursor = this.forest.getCursorAboveDetachedFields();\n\t\tconst rootFields = new Set([rootFieldKey]);\n\t\tfor (const { root } of this.removedRoots.entries()) {\n\t\t\trootFields.add(this.removedRoots.toFieldKey(root));\n\t\t}\n\n\t\tif (!cursor.firstField()) {\n\t\t\treturn;\n\t\t}\n\n\t\tdo {\n\t\t\tconst field = cursor.getFieldKey();\n\t\t\tassert(\n\t\t\t\trootFields.has(field),\n\t\t\t\t0xa22 /* Forest has a root field which is unknown to the detached field index */,\n\t\t\t);\n\n\t\t\trootFields.delete(field);\n\t\t} while (cursor.nextField());\n\t}\n\n\t/**\n\t * `true` iff the given branch change event is due to a remote change\n\t */\n\tprivate isRemoteChangeEvent(event: SharedTreeBranchChange<SharedTreeChange>): boolean {\n\t\treturn (\n\t\t\t// remote changes are only ever applied to the main branch\n\t\t\t!this.isBranch &&\n\t\t\t// remote changes are applied to the main branch by rebasing it onto the trunk,\n\t\t\t// no other rebases are allowed on the main branch so this means any replaces that are not\n\t\t\t// transaction commits are remote changes\n\t\t\tevent.type === \"replace\" &&\n\t\t\tgetChangeReplaceType(event) !== \"transactionCommit\"\n\t\t);\n\t}\n}\n\n/**\n * Run a synchronous transaction on the given shared tree view.\n * This is a convenience helper around the {@link SharedTreeFork#transaction} APIs.\n * @param view - the view on which to run the transaction\n * @param transaction - the transaction function. This will be executed immediately. It is passed `view` as an argument for convenience.\n * If this function returns an `Abort` result then the transaction will be aborted. Otherwise, it will be committed.\n * @returns whether or not the transaction was committed or aborted\n */\nexport function runSynchronous(\n\tview: ITreeCheckout,\n\ttransaction: (view: ITreeCheckout) => TransactionResult | void,\n): TransactionResult {\n\tview.transaction.start();\n\tconst result = transaction(view);\n\treturn result === TransactionResult.Abort\n\t\t? view.transaction.abort()\n\t\t: view.transaction.commit();\n}\n\ninterface DisposableRevertible extends Revertible {\n\tdispose: () => void;\n}\n"]}
1
+ {"version":3,"file":"treeCheckout.js","sourceRoot":"","sources":["../../src/shared-tree/treeCheckout.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;AAEH,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AAM9E,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EACN,UAAU,GAEV,MAAM,0CAA0C,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAIN,SAAS,EAGT,UAAU,EAOV,gBAAgB,EAIhB,0BAA0B,EAE1B,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,YAAY,EACZ,SAAS,EACT,UAAU,GAGV,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,WAAW,EACX,oBAAoB,EACpB,SAAS,EACT,sBAAsB,EACtB,mBAAmB,GACnB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACN,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,GAGhB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAEpF,OAAO,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAatF,OAAO,EAAE,WAAW,EAAE,0BAA0B,EAAE,MA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N,0DAA0D;QAC1D,CAAC,IAAI,CAAC,QAAQ;YACd,+EAA+E;YAC/E,gGAAgG;YAChG,KAAK,CAAC,IAAI,KAAK,SAAS;YACxB,oBAAoB,CAAC,KAAK,CAAC,KAAK,QAAQ,CACxC,CAAC;IACH,CAAC;;AAniBD;;;GAGG;AACoB,qCAAwB,GAAG,kBAAkB,AAArB,CAAsB","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tHasListeners,\n\tIEmitter,\n\tListenable,\n} from \"@fluidframework/core-interfaces/internal\";\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport {\n\tUsageError,\n\ttype ITelemetryLoggerExt,\n} from \"@fluidframework/telemetry-utils/internal\";\nimport { noopValidator } from \"../codec/index.js\";\nimport {\n\ttype Anchor,\n\ttype AnchorLocator,\n\ttype AnchorNode,\n\tAnchorSet,\n\ttype AnchorSetRootEvents,\n\ttype ChangeFamily,\n\tCommitKind,\n\ttype CommitMetadata,\n\ttype DeltaVisitor,\n\ttype DetachedFieldIndex,\n\ttype IEditableForest,\n\ttype IForestSubscription,\n\ttype JsonableTree,\n\tRevertibleStatus,\n\ttype RevisionTag,\n\ttype RevisionTagCodec,\n\ttype TreeStoredSchema,\n\tTreeStoredSchemaRepository,\n\ttype TreeStoredSchemaSubscription,\n\tcombineVisitors,\n\tmakeDetachedFieldIndex,\n\trebaseChange,\n\trootFieldKey,\n\ttagChange,\n\tvisitDelta,\n\ttype RevertibleAlphaFactory,\n\ttype RevertibleAlpha,\n} from \"../core/index.js\";\nimport {\n\ttype FieldBatchCodec,\n\ttype TreeCompressionStrategy,\n\tbuildForest,\n\tcreateNodeKeyManager,\n\tintoDelta,\n\tjsonableTreeFromCursor,\n\tmakeFieldBatchCodec,\n} from \"../feature-libraries/index.js\";\nimport {\n\tSharedTreeBranch,\n\tTransactionResult,\n\tTransactionStack,\n\tgetChangeReplaceType,\n\tonForkTransitive,\n\ttype SharedTreeBranchChange,\n\ttype Transactor,\n} from \"../shared-tree-core/index.js\";\nimport { Breakable, disposeSymbol, fail, getLast, hasSome } from \"../util/index.js\";\n\nimport { SharedTreeChangeFamily, hasSchemaChange } from \"./sharedTreeChangeFamily.js\";\nimport type { SharedTreeChange } from \"./sharedTreeChangeTypes.js\";\nimport type { ISharedTreeEditor, SharedTreeEditBuilder } from \"./sharedTreeEditBuilder.js\";\nimport type { IDisposable } from \"@fluidframework/core-interfaces\";\nimport type {\n\tImplicitFieldSchema,\n\tReadSchema,\n\tTreeView,\n\tTreeViewConfiguration,\n\tUnsafeUnknownSchema,\n\tViewableTree,\n\tTreeBranch,\n} from \"../simple-tree/index.js\";\nimport { getCheckout, SchematizingSimpleTreeView } from \"./schematizingTreeView.js\";\n\n/**\n * Events for {@link ITreeCheckout}.\n */\nexport interface CheckoutEvents {\n\t/**\n\t * A batch of changes has finished processing and the view is in a consistent state.\n\t * It is once again safe to access the FlexTree, Forest and AnchorSet.\n\t *\n\t * @remarks\n\t * This is mainly useful for knowing when to do followup work scheduled during events from Anchors.\n\t */\n\tafterBatch(): void;\n\n\t/**\n\t * Fired when a change is made to the branch. Includes data about the change that is made which listeners\n\t * can use to filter on changes they care about e.g. local vs remote changes.\n\t *\n\t * @param data - information about the change\n\t * @param getRevertible - a function provided that allows users to get a revertible for the change. If not provided,\n\t * this change is not revertible.\n\t */\n\tchanged(data: CommitMetadata, getRevertible?: RevertibleAlphaFactory): void;\n\n\t/**\n\t * Fired when a new branch is created from this checkout.\n\t */\n\tfork(branch: ITreeCheckout): void;\n\n\t/**\n\t * Fired when the checkout is disposed.\n\t */\n\tdispose(): void;\n}\n\n/**\n * A \"version control\"-style branch of a SharedTree.\n * @remarks Branches may be used to coordinate edits to a SharedTree, e.g. via merge and rebase operations.\n * Changes applied to a branch of a branch only apply to that branch and are isolated from other branches.\n * Changes may be synchronized across branches via merge and rebase operations provided on the branch object.\n * @alpha @sealed\n */\nexport interface BranchableTree extends ViewableTree {\n\t/**\n\t * Spawn a new branch which is based off of the current state of this branch.\n\t * Any mutations of the new branch will not apply to this branch until the new branch is merged back into this branch via `merge()`.\n\t */\n\tbranch(): TreeBranchFork;\n\n\t/**\n\t * Apply all the new changes on the given branch to this branch.\n\t * @param view - a branch which was created by a call to `branch()`.\n\t * It is automatically disposed after the merge completes.\n\t * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.\n\t * A \"changed\" event and a corresponding {@link Revertible} will be emitted on this branch for each new change merged from 'branch'.\n\t */\n\tmerge(branch: TreeBranchFork): void;\n\n\t/**\n\t * Apply all the new changes on the given branch to this branch.\n\t * @param branch - a branch which was created by a call to `branch()`.\n\t * @param disposeMerged - whether or not to dispose `branch` after the merge completes.\n\t * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.\n\t */\n\tmerge(branch: TreeBranchFork, disposeMerged: boolean): void;\n\n\t/**\n\t * Rebase the given branch onto this branch.\n\t * @param branch - a branch which was created by a call to `branch()`. It is modified by this operation.\n\t */\n\trebase(branch: TreeBranchFork): void;\n}\n\n/**\n * A {@link BranchableTree | branch} of a SharedTree that has merged from another branch.\n * @remarks This branch should be disposed when it is no longer needed in order to free resources.\n * @alpha @sealed\n */\nexport interface TreeBranchFork extends BranchableTree, IDisposable {\n\t/**\n\t * Rebase the changes that have been applied to this branch over all the new changes in the given branch.\n\t * @param branch - Either the root branch or a branch that was created by a call to `branch()`. It is not modified by this operation.\n\t */\n\trebaseOnto(branch: BranchableTree): void;\n}\n\n/**\n * Provides a means for interacting with a SharedTree.\n * This includes reading data from the tree and running transactions to mutate the tree.\n * @remarks This interface should not have any implementations other than those provided by the SharedTree package libraries.\n * @privateRemarks\n * API for interacting with a {@link SharedTreeBranch}.\n * Implementations of this interface must implement the {@link branchKey} property.\n */\nexport interface ITreeCheckout extends AnchorLocator, ViewableTree {\n\t/**\n\t * Read and Write access for schema stored in the document.\n\t *\n\t * These APIs are temporary and will be replaced with different abstractions (View Schema based) in a different place later.\n\t *\n\t * TODO:\n\t * Editing of this should be moved into transactions with the rest of tree editing to they can be intermixed.\n\t * This will be done after the relations between views, branches and Indexes are figured out.\n\t *\n\t * TODO:\n\t * Public APIs for dealing with schema should be in terms of View Schema, and schema update policies.\n\t * The actual stored schema should be hidden (or ar least not be the most prominent way to interact with schema).\n\t *\n\t * TODO:\n\t * Something should ensure the document contents are always in schema.\n\t */\n\treadonly storedSchema: TreeStoredSchemaSubscription;\n\t/**\n\t * Current contents.\n\t * Updated by edits (local and remote).\n\t * Use `editor` to create a local edit.\n\t */\n\treadonly forest: IForestSubscription;\n\n\t/**\n\t * Used to edit the state of the tree. Edits will be immediately applied locally to the tree.\n\t * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.\n\t */\n\treadonly editor: ISharedTreeEditor;\n\n\t/**\n\t * A collection of functions for managing transactions.\n\t */\n\treadonly transaction: Transactor;\n\n\tbranch(): ITreeCheckoutFork;\n\n\tmerge(checkout: ITreeCheckoutFork): void;\n\n\tmerge(checkout: ITreeCheckoutFork, disposeMerged: boolean): void;\n\n\trebase(checkout: ITreeCheckoutFork): void;\n\n\t/**\n\t * Replaces all schema with the provided schema.\n\t * Can over-write preexisting schema, and removes unmentioned schema.\n\t */\n\tupdateSchema(newSchema: TreeStoredSchema): void;\n\n\t/**\n\t * Events about this view.\n\t */\n\treadonly events: Listenable<CheckoutEvents>;\n\n\t/**\n\t * Events about the root of the tree in this view.\n\t */\n\treadonly rootEvents: Listenable<AnchorSetRootEvents>;\n\n\t/**\n\t * Returns a JsonableTree for each tree that was removed from (and not restored to) the document.\n\t * This list is guaranteed to contain all nodes that are recoverable through undo/redo on this checkout.\n\t * The list may also contain additional nodes.\n\t *\n\t * This is only intended for use in testing and exceptional code paths: it is not performant.\n\t */\n\tgetRemovedRoots(): [string | number | undefined, number, JsonableTree][];\n}\n\n/**\n * Creates a {@link TreeCheckout}.\n * @param args - an object containing optional components that will be used to build the view.\n * Any components not provided will be created by default.\n * @remarks This does not create a {@link SharedTree}, but rather a view with the minimal state\n * and functionality required to implement {@link ITreeCheckout}.\n */\nexport function createTreeCheckout(\n\tidCompressor: IIdCompressor,\n\tmintRevisionTag: () => RevisionTag,\n\trevisionTagCodec: RevisionTagCodec,\n\targs?: {\n\t\tbranch?: SharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>;\n\t\tchangeFamily?: ChangeFamily<SharedTreeEditBuilder, SharedTreeChange>;\n\t\tschema?: TreeStoredSchemaRepository;\n\t\tforest?: IEditableForest;\n\t\tfieldBatchCodec?: FieldBatchCodec;\n\t\tevents?: Listenable<CheckoutEvents> &\n\t\t\tIEmitter<CheckoutEvents> &\n\t\t\tHasListeners<CheckoutEvents>;\n\t\tremovedRoots?: DetachedFieldIndex;\n\t\tchunkCompressionStrategy?: TreeCompressionStrategy;\n\t\tlogger?: ITelemetryLoggerExt;\n\t\tbreaker?: Breakable;\n\t},\n): TreeCheckout {\n\tconst forest = args?.forest ?? buildForest();\n\tconst schema = args?.schema ?? new TreeStoredSchemaRepository();\n\tconst defaultCodecOptions = { jsonValidator: noopValidator };\n\tconst defaultFieldBatchVersion = 1;\n\tconst changeFamily =\n\t\targs?.changeFamily ??\n\t\tnew SharedTreeChangeFamily(\n\t\t\trevisionTagCodec,\n\t\t\targs?.fieldBatchCodec ??\n\t\t\t\tmakeFieldBatchCodec(defaultCodecOptions, defaultFieldBatchVersion),\n\t\t\t{ jsonValidator: noopValidator },\n\t\t\targs?.chunkCompressionStrategy,\n\t\t\tidCompressor,\n\t\t);\n\tconst branch =\n\t\targs?.branch ??\n\t\tnew SharedTreeBranch(\n\t\t\t{\n\t\t\t\tchange: changeFamily.rebaser.compose([]),\n\t\t\t\trevision: \"root\",\n\t\t\t},\n\t\t\tchangeFamily,\n\t\t\t() => idCompressor.generateCompressedId(),\n\t\t);\n\tconst events = args?.events ?? createEmitter();\n\n\treturn new TreeCheckout(\n\t\tbranch,\n\t\tfalse,\n\t\tchangeFamily,\n\t\tschema,\n\t\tforest,\n\t\tevents,\n\t\tmintRevisionTag,\n\t\trevisionTagCodec,\n\t\tidCompressor,\n\t\targs?.removedRoots,\n\t\targs?.logger,\n\t\targs?.breaker,\n\t);\n}\n\n/**\n * Branch (like in a version control system) of SharedTree.\n *\n * {@link ITreeCheckout} that has forked off of the main trunk/branch.\n */\nexport interface ITreeCheckoutFork extends ITreeCheckout {\n\trebaseOnto(view: ITreeCheckout): void;\n}\n\n/**\n * Metrics derived from a revert operation.\n *\n * @see {@link TreeCheckout.revertRevertible}.\n */\nexport interface RevertMetrics {\n\t/**\n\t * The age of the revertible commit relative to the head of the branch to which the reversion will be applied.\n\t */\n\treadonly age: number;\n\n\t// TODO: add other stats as needed for telemetry, etc.\n}\n\n/**\n * An implementation of {@link ITreeCheckoutFork}.\n */\nexport class TreeCheckout implements ITreeCheckoutFork {\n\tpublic disposed = false;\n\n\tprivate readonly views = new Set<TreeView<ImplicitFieldSchema>>();\n\n\t/**\n\t * Set of revertibles maintained for automatic disposal\n\t */\n\tprivate readonly revertibles = new Set<RevertibleAlpha>();\n\n\t/**\n\t * Each branch's head commit corresponds to a revertible commit.\n\t * Maintaining a whole branch ensures the commit graph is not pruned in a way that would prevent the commit from\n\t * being reverted.\n\t */\n\tprivate readonly revertibleCommitBranches = new Map<\n\t\tRevisionTag,\n\t\tSharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>\n\t>();\n\n\t/**\n\t * The name of the telemetry event logged for calls to {@link TreeCheckout.revertRevertible}.\n\t * @privateRemarks Exposed for testing purposes.\n\t */\n\tpublic static readonly revertTelemetryEventName = \"RevertRevertible\";\n\n\tpublic constructor(\n\t\tprivate readonly _branch: SharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>,\n\t\t/** True if and only if this checkout is for a forked branch and not the \"main branch\" of the tree. */\n\t\tpublic readonly isBranch: boolean,\n\t\tprivate readonly changeFamily: ChangeFamily<SharedTreeEditBuilder, SharedTreeChange>,\n\t\tpublic readonly storedSchema: TreeStoredSchemaRepository,\n\t\tpublic readonly forest: IEditableForest,\n\t\tpublic readonly events: Listenable<CheckoutEvents> &\n\t\t\tIEmitter<CheckoutEvents> &\n\t\t\tHasListeners<CheckoutEvents>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly revisionTagCodec: RevisionTagCodec,\n\t\tprivate readonly idCompressor: IIdCompressor,\n\t\tprivate removedRoots: DetachedFieldIndex = makeDetachedFieldIndex(\n\t\t\t\"repair\",\n\t\t\trevisionTagCodec,\n\t\t\tidCompressor,\n\t\t),\n\t\t/** Optional logger for telemetry. */\n\t\tprivate readonly logger?: ITelemetryLoggerExt,\n\t\tprivate readonly breaker: Breakable = new Breakable(\"TreeCheckout\"),\n\t) {\n\t\t// We subscribe to `beforeChange` rather than `afterChange` here because it's possible that the change is invalid WRT our forest.\n\t\t// For example, a bug in the editor might produce a malformed change object and thus applying the change to the forest will throw an error.\n\t\t// In such a case we will crash here, preventing the change from being added to the commit graph, and preventing `afterChange` from firing.\n\t\t// One important consequence of this is that we will not submit the op containing the invalid change, since op submissions happens in response to `afterChange`.\n\t\t_branch.events.on(\"beforeChange\", (event) => {\n\t\t\tif (event.change !== undefined) {\n\t\t\t\tlet revision: RevisionTag | undefined;\n\t\t\t\tif (event.type === \"replace\") {\n\t\t\t\t\tassert(\n\t\t\t\t\t\thasSome(event.newCommits),\n\t\t\t\t\t\t0xa81 /* Expected new commit for non no-op change event */,\n\t\t\t\t\t);\n\t\t\t\t\trevision = getLast(event.newCommits).revision;\n\t\t\t\t} else {\n\t\t\t\t\trevision = event.change.revision;\n\t\t\t\t}\n\n\t\t\t\t// Conflicts due to schema will be empty and thus are not applied.\n\t\t\t\tfor (const change of event.change.change.changes) {\n\t\t\t\t\tif (change.type === \"data\") {\n\t\t\t\t\t\tconst delta = intoDelta(tagChange(change.innerChange, revision));\n\t\t\t\t\t\tthis.withCombinedVisitor((visitor) => {\n\t\t\t\t\t\t\tvisitDelta(delta, visitor, this.removedRoots, revision);\n\t\t\t\t\t\t});\n\t\t\t\t\t} else if (change.type === \"schema\") {\n\t\t\t\t\t\t// Schema changes from a current to a new schema are expected to be backwards compatible.\n\t\t\t\t\t\t// This guarantees that all data in the forest (which is valid before the schema change)\n\t\t\t\t\t\t// is also valid under the new schema.\n\t\t\t\t\t\t// Note however, that such schema changes may in some cases be rolled back:\n\t\t\t\t\t\t// Case 1: A transaction with a schema change may be aborted.\n\t\t\t\t\t\t// The transaction may have made some data changes that would render some trees invalid\n\t\t\t\t\t\t// under the old schema, but these changes will also be rolled back, thereby putting the forest\n\t\t\t\t\t\t// back in the state before the transaction, which is valid under the original (reinstated) schema.\n\t\t\t\t\t\t// Case 2: A branch with a schema change may be rebased such that the schema change (because\n\t\t\t\t\t\t// of a constraint) is no longer applied.\n\t\t\t\t\t\t// Such a branch may contain data changes that would render some trees invalid under the\n\t\t\t\t\t\t// original schema. These data changes may not necessarily be rolled back.\n\t\t\t\t\t\t// They will however be rebased over the rollback of the schema change. This rebasing will\n\t\t\t\t\t\t// ensure that these data changes are muted if they would render some trees invalid under the\n\t\t\t\t\t\t// original (reinstated) schema.\n\t\t\t\t\t\tstoredSchema.apply(change.innerChange.schema.new);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tfail(\"Unknown Shared Tree change type.\");\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tthis.events.emit(\"afterBatch\");\n\t\t\t}\n\t\t});\n\t\t_branch.events.on(\"afterChange\", (event) => {\n\t\t\t// The following logic allows revertibles to be generated for the change.\n\t\t\t// Currently only appends (including merges) and transaction commits are supported.\n\t\t\tif (!this.transaction.isInProgress()) {\n\t\t\t\tif (\n\t\t\t\t\tevent.type === \"append\" ||\n\t\t\t\t\t(event.type === \"replace\" && getChangeReplaceType(event) === \"transactionCommit\")\n\t\t\t\t) {\n\t\t\t\t\t// TODO:#20949: When the SharedTree is detached, these commits will already have been garbage collected.\n\t\t\t\t\t// Figure out a way to generate revertibles before the commits are garbage collected.\n\t\t\t\t\tfor (const commit of event.newCommits) {\n\t\t\t\t\t\tconst kind = event.type === \"append\" ? event.kind : CommitKind.Default;\n\t\t\t\t\t\tconst { change, revision } = commit;\n\n\t\t\t\t\t\tconst getRevertible = hasSchemaChange(change)\n\t\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t\t: (onRevertibleDisposed?: (revertible: RevertibleAlpha) => void) => {\n\t\t\t\t\t\t\t\t\tif (!withinEventContext) {\n\t\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t\t\"Cannot get a revertible outside of the context of a changed event.\",\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tif (this.revertibleCommitBranches.get(revision) !== undefined) {\n\t\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t\t\"Cannot generate the same revertible more than once. Note that this can happen when multiple changed event listeners are registered.\",\n\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\tconst revertible = this.createRevertible(\n\t\t\t\t\t\t\t\t\t\trevision,\n\t\t\t\t\t\t\t\t\t\tkind,\n\t\t\t\t\t\t\t\t\t\tthis,\n\t\t\t\t\t\t\t\t\t\tonRevertibleDisposed,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\tthis.revertibleCommitBranches.set(revision, _branch.fork(commit));\n\t\t\t\t\t\t\t\t\tthis.revertibles.add(revertible);\n\t\t\t\t\t\t\t\t\treturn revertible;\n\t\t\t\t\t\t\t\t};\n\n\t\t\t\t\t\tlet withinEventContext = true;\n\t\t\t\t\t\tthis.events.emit(\"changed\", { isLocal: true, kind }, getRevertible);\n\t\t\t\t\t\twithinEventContext = false;\n\t\t\t\t\t}\n\t\t\t\t} else if (this.isRemoteChangeEvent(event)) {\n\t\t\t\t\t// TODO: figure out how to plumb through commit kind info for remote changes\n\t\t\t\t\tthis.events.emit(\"changed\", { isLocal: false, kind: CommitKind.Default });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\t// When the branch is trimmed, we can garbage collect any repair data whose latest relevant revision is one of the\n\t\t// trimmed revisions.\n\t\t_branch.events.on(\"ancestryTrimmed\", (revisions) => {\n\t\t\tthis.withCombinedVisitor((visitor) => {\n\t\t\t\trevisions.forEach((revision) => {\n\t\t\t\t\t// get all the roots last created or used by the revision\n\t\t\t\t\tconst roots = this.removedRoots.getRootsLastTouchedByRevision(revision);\n\n\t\t\t\t\t// get the detached field for the root and delete it from the removed roots\n\t\t\t\t\tfor (const root of roots) {\n\t\t\t\t\t\tvisitor.destroy(this.removedRoots.toFieldKey(root), 1);\n\t\t\t\t\t}\n\n\t\t\t\t\tthis.removedRoots.deleteRootsLastTouchedByRevision(revision);\n\t\t\t\t});\n\t\t\t});\n\t\t});\n\t}\n\n\tprivate withCombinedVisitor(fn: (visitor: DeltaVisitor) => void): void {\n\t\tconst anchorVisitor = this.forest.anchors.acquireVisitor();\n\t\tconst combinedVisitor = combineVisitors(\n\t\t\t[this.forest.acquireVisitor(), anchorVisitor],\n\t\t\t[anchorVisitor],\n\t\t);\n\t\tfn(combinedVisitor);\n\t\tcombinedVisitor.free();\n\t}\n\n\tprivate checkNotDisposed(usageError?: string): void {\n\t\tif (this.disposed) {\n\t\t\tif (usageError !== undefined) {\n\t\t\t\tthrow new UsageError(usageError);\n\t\t\t}\n\t\t\tassert(false, 0x911 /* Invalid operation on a disposed TreeCheckout */);\n\t\t}\n\t}\n\n\t/**\n\t * Creates a {@link RevertibleAlpha} object that can undo a specific change in the tree's history.\n\t * Revision must exist in the given {@link TreeCheckout}'s branch.\n\t *\n\t * @param revision - The revision tag identifying the change to be made revertible.\n\t * @param kind - The {@link CommitKind} that produced this revertible (e.g., Default, Undo, Redo).\n\t * @param checkout - The {@link TreeCheckout} instance this revertible belongs to.\n\t * @param onRevertibleDisposed - Callback function that will be called when the revertible is disposed.\n\t * @returns - {@link RevertibleAlpha}\n\t */\n\tprivate createRevertible(\n\t\trevision: RevisionTag,\n\t\tkind: CommitKind,\n\t\tcheckout: TreeCheckout,\n\t\tonRevertibleDisposed: ((revertible: RevertibleAlpha) => void) | undefined,\n\t): RevertibleAlpha {\n\t\tconst commitBranches = checkout.revertibleCommitBranches;\n\n\t\tconst revertible: RevertibleAlpha = {\n\t\t\tget status(): RevertibleStatus {\n\t\t\t\tconst revertibleCommit = commitBranches.get(revision);\n\t\t\t\treturn revertibleCommit === undefined\n\t\t\t\t\t? RevertibleStatus.Disposed\n\t\t\t\t\t: RevertibleStatus.Valid;\n\t\t\t},\n\t\t\trevert: (release: boolean = true) => {\n\t\t\t\tif (revertible.status === RevertibleStatus.Disposed) {\n\t\t\t\t\tthrow new UsageError(\"Unable to revert a revertible that has been disposed.\");\n\t\t\t\t}\n\n\t\t\t\tconst revertMetrics = checkout.revertRevertible(revision, kind);\n\t\t\t\tcheckout.logger?.sendTelemetryEvent({\n\t\t\t\t\teventName: TreeCheckout.revertTelemetryEventName,\n\t\t\t\t\t...revertMetrics,\n\t\t\t\t});\n\n\t\t\t\tif (release) {\n\t\t\t\t\trevertible.dispose();\n\t\t\t\t}\n\t\t\t},\n\t\t\tclone: (forkedBranch: TreeBranch) => {\n\t\t\t\tif (forkedBranch === undefined) {\n\t\t\t\t\treturn this.createRevertible(revision, kind, checkout, onRevertibleDisposed);\n\t\t\t\t}\n\n\t\t\t\t// TODO:#23442: When a revertible is cloned for a forked branch, optimize to create a fork of a revertible branch once per revision NOT once per revision per checkout.\n\t\t\t\tconst forkedCheckout = getCheckout(forkedBranch);\n\t\t\t\tconst revertibleBranch = this.revertibleCommitBranches.get(revision);\n\t\t\t\tassert(\n\t\t\t\t\trevertibleBranch !== undefined,\n\t\t\t\t\t0xa82 /* change to revert does not exist on the given forked branch */,\n\t\t\t\t);\n\t\t\t\tforkedCheckout.revertibleCommitBranches.set(revision, revertibleBranch.fork());\n\n\t\t\t\treturn this.createRevertible(revision, kind, forkedCheckout, onRevertibleDisposed);\n\t\t\t},\n\t\t\tdispose: () => {\n\t\t\t\tif (revertible.status === RevertibleStatus.Disposed) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"Unable to dispose a revertible that has already been disposed.\",\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcheckout.disposeRevertible(revertible, revision);\n\t\t\t\tonRevertibleDisposed?.(revertible);\n\t\t\t},\n\t\t};\n\n\t\treturn revertible;\n\t}\n\n\t// For the new TreeViewAlpha API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot>;\n\n\t// For the old TreeView API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot> {\n\t\tconst view = new SchematizingSimpleTreeView(\n\t\t\tthis,\n\t\t\tconfig,\n\t\t\tcreateNodeKeyManager(this.idCompressor),\n\t\t\tthis.breaker,\n\t\t\t() => {\n\t\t\t\tthis.views.delete(view);\n\t\t\t},\n\t\t);\n\t\tthis.views.add(view);\n\t\treturn view;\n\t}\n\n\tpublic get rootEvents(): Listenable<AnchorSetRootEvents> {\n\t\treturn this.forest.anchors.events;\n\t}\n\n\tpublic get editor(): ISharedTreeEditor {\n\t\tthis.checkNotDisposed();\n\t\treturn this._branch.editor;\n\t}\n\n\tpublic locate(anchor: Anchor): AnchorNode | undefined {\n\t\tthis.checkNotDisposed();\n\t\treturn this.forest.anchors.locate(anchor);\n\t}\n\n\tpublic get transaction(): Transactor {\n\t\treturn this.#transaction;\n\t}\n\t/**\n\t * The {@link Transactor} for this checkout.\n\t * @remarks In the context of a checkout, transactions allow edits to be batched into atomic units.\n\t * Edits made during a transaction will update the local state of the tree immediately, but will be squashed into a single edit when the transaction is committed.\n\t * If the transaction is aborted, the local state will be reset to what it was before the transaction began.\n\t * Transactions may nest, meaning that a transaction may be started while a transaction is already ongoing.\n\t *\n\t * To avoid updating observers of the view state with intermediate results during a transaction,\n\t * use {@link ITreeCheckout#branch} and {@link ISharedTreeFork#merge}.\n\t */\n\treadonly #transaction = new TransactionStack(() => {\n\t\t// Keep track of the commit that each transaction was on when it started\n\t\t// TODO:#8603: This may need to be computed differently if we allow rebasing during a transaction.\n\t\tconst startCommit = this._branch.getHead();\n\t\t// Keep track of all the forks created during the transaction so that we can dispose them when the transaction ends.\n\t\t// This is a policy decision that we think is useful for the user, but it is not necessary for correctness.\n\t\tconst forks = new Set<TreeCheckout>();\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\t// When each transaction is started, take a snapshot of the current state of removed roots\n\t\tconst removedRoots = this.removedRoots.clone();\n\t\tthis._branch.editor.enterTransaction();\n\t\treturn (result) => {\n\t\t\tthis._branch.editor.exitTransaction();\n\t\t\tswitch (result) {\n\t\t\t\tcase TransactionResult.Abort:\n\t\t\t\t\tthis._branch.removeAfter(startCommit);\n\t\t\t\t\t// If a transaction is rolled back, revert removed roots back to the latest snapshot\n\t\t\t\t\tthis.removedRoots = removedRoots;\n\t\t\t\t\tbreak;\n\t\t\t\tcase TransactionResult.Commit: {\n\t\t\t\t\tconst removedCommits = this._branch.squashAfter(startCommit);\n\t\t\t\t\tconst transactionRevision = this._branch.getHead().revision;\n\t\t\t\t\tfor (const transactionStep of removedCommits) {\n\t\t\t\t\t\tthis.removedRoots.updateMajor(transactionStep.revision, transactionRevision);\n\t\t\t\t\t}\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tunreachableCase(result);\n\t\t\t}\n\n\t\t\tforks.forEach((fork) => fork.dispose());\n\t\t\tonDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());\n\t\t\tonForkUnSubscribe();\n\t\t};\n\t});\n\n\tpublic branch(): TreeCheckout {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The parent branch has already been disposed and can no longer create new branches.\",\n\t\t);\n\t\tconst anchors = new AnchorSet();\n\t\tconst branch = this._branch.fork();\n\t\tconst storedSchema = this.storedSchema.clone();\n\t\tconst forest = this.forest.clone(storedSchema, anchors);\n\t\tconst checkout = new TreeCheckout(\n\t\t\tbranch,\n\t\t\ttrue,\n\t\t\tthis.changeFamily,\n\t\t\tstoredSchema,\n\t\t\tforest,\n\t\t\tcreateEmitter(),\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.revisionTagCodec,\n\t\t\tthis.idCompressor,\n\t\t\tthis.removedRoots.clone(),\n\t\t\tthis.logger,\n\t\t\tthis.breaker,\n\t\t);\n\t\tthis.events.emit(\"fork\", checkout);\n\t\treturn checkout;\n\t}\n\n\tpublic rebase(checkout: TreeCheckout): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The target of the branch rebase has been disposed and cannot be rebased.\",\n\t\t);\n\t\tcheckout.checkNotDisposed(\n\t\t\t\"The source of the branch rebase has been disposed and cannot be rebased.\",\n\t\t);\n\t\tassert(\n\t\t\t!checkout.transaction.isInProgress(),\n\t\t\t0x9af /* A view cannot be rebased while it has a pending transaction */,\n\t\t);\n\t\tassert(\n\t\t\tcheckout.isBranch,\n\t\t\t0xa5d /* The main branch cannot be rebased onto another branch. */,\n\t\t);\n\n\t\tcheckout._branch.rebaseOnto(this._branch);\n\t}\n\n\tpublic rebaseOnto(checkout: ITreeCheckout): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The target of the branch rebase has been disposed and cannot be rebased.\",\n\t\t);\n\t\tcheckout.rebase(this);\n\t}\n\n\tpublic merge(checkout: TreeCheckout): void;\n\tpublic merge(checkout: TreeCheckout, disposeMerged: boolean): void;\n\tpublic merge(checkout: TreeCheckout, disposeMerged = true): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The target of the branch merge has been disposed and cannot be merged.\",\n\t\t);\n\t\tcheckout.checkNotDisposed(\n\t\t\t\"The source of the branch merge has been disposed and cannot be merged.\",\n\t\t);\n\t\tassert(\n\t\t\t!this.transaction.isInProgress(),\n\t\t\t0x9b0 /* Views cannot be merged into a view while it has a pending transaction */,\n\t\t);\n\t\twhile (checkout.transaction.isInProgress()) {\n\t\t\tcheckout.transaction.commit();\n\t\t}\n\t\tthis._branch.merge(checkout._branch);\n\t\tif (disposeMerged && checkout.isBranch) {\n\t\t\t// Dispose the merged checkout unless it is the main branch.\n\t\t\tcheckout[disposeSymbol]();\n\t\t}\n\t}\n\n\tpublic updateSchema(newSchema: TreeStoredSchema): void {\n\t\tthis.checkNotDisposed();\n\t\tthis.editor.schema.setStoredSchema(this.storedSchema.clone(), newSchema);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis[disposeSymbol]();\n\t}\n\n\tpublic [disposeSymbol](): void {\n\t\tthis.checkNotDisposed(\n\t\t\t\"The branch has already been disposed and cannot be disposed again.\",\n\t\t);\n\t\tthis.disposed = true;\n\t\tthis.#transaction.dispose();\n\t\tthis.purgeRevertibles();\n\t\tthis._branch.dispose();\n\t\tfor (const view of this.views) {\n\t\t\tview.dispose();\n\t\t}\n\t\tthis.events.emit(\"dispose\");\n\t}\n\n\tpublic getRemovedRoots(): [string | number | undefined, number, JsonableTree][] {\n\t\tthis.assertNoUntrackedRoots();\n\t\tconst trees: [string | number | undefined, number, JsonableTree][] = [];\n\t\tconst cursor = this.forest.allocateCursor(\"getRemovedRoots\");\n\t\tfor (const { id, root } of this.removedRoots.entries()) {\n\t\t\tconst parentField = this.removedRoots.toFieldKey(root);\n\t\t\tthis.forest.moveCursorToPath({ parent: undefined, parentField, parentIndex: 0 }, cursor);\n\t\t\tconst tree = jsonableTreeFromCursor(cursor);\n\t\t\t// This method is used for tree consistency comparison.\n\t\t\tconst { major, minor } = id;\n\t\t\tconst finalizedMajor = major !== undefined ? this.revisionTagCodec.encode(major) : major;\n\t\t\ttrees.push([finalizedMajor, minor, tree]);\n\t\t}\n\t\tcursor.free();\n\t\treturn trees;\n\t}\n\n\t/**\n\t * This sets the tip revision as the latest relevant revision for any removed roots that are loaded from a summary.\n\t * This needs to be called right after loading {@link this.removedRoots} from a summary to allow loaded data to be garbage collected.\n\t */\n\tpublic setTipRevisionForLoadedData(revision: RevisionTag): void {\n\t\tthis.removedRoots.setRevisionsForLoadedData(revision);\n\t}\n\n\tprivate purgeRevertibles(): void {\n\t\tfor (const revertible of this.revertibles) {\n\t\t\trevertible.dispose();\n\t\t}\n\t}\n\n\tprivate disposeRevertible(revertible: RevertibleAlpha, revision: RevisionTag): void {\n\t\tthis.revertibleCommitBranches.get(revision)?.dispose();\n\t\tthis.revertibleCommitBranches.delete(revision);\n\t\tthis.revertibles.delete(revertible);\n\t}\n\n\tprivate revertRevertible(revision: RevisionTag, kind: CommitKind): RevertMetrics {\n\t\tif (this.transaction.isInProgress()) {\n\t\t\tthrow new UsageError(\"Undo is not yet supported during transactions.\");\n\t\t}\n\n\t\tconst revertibleBranch = this.revertibleCommitBranches.get(revision);\n\t\tassert(revertibleBranch !== undefined, 0x7cc /* expected to find a revertible commit */);\n\t\tconst commitToRevert = revertibleBranch.getHead();\n\t\tconst revisionForInvert = this.mintRevisionTag();\n\n\t\tlet change = tagChange(\n\t\t\tthis.changeFamily.rebaser.invert(commitToRevert, false, revisionForInvert),\n\t\t\trevisionForInvert,\n\t\t);\n\n\t\tconst headCommit = this._branch.getHead();\n\t\t// Rebase the inverted change onto any commits that occurred after the undoable commits.\n\t\tif (commitToRevert !== headCommit) {\n\t\t\tchange = tagChange(\n\t\t\t\trebaseChange(\n\t\t\t\t\tthis.changeFamily.rebaser,\n\t\t\t\t\tchange,\n\t\t\t\t\tcommitToRevert,\n\t\t\t\t\theadCommit,\n\t\t\t\t\tthis.mintRevisionTag,\n\t\t\t\t).change,\n\t\t\t\trevisionForInvert,\n\t\t\t);\n\t\t}\n\n\t\tthis._branch.apply(\n\t\t\tchange,\n\t\t\tkind === CommitKind.Default || kind === CommitKind.Redo\n\t\t\t\t? CommitKind.Undo\n\t\t\t\t: CommitKind.Redo,\n\t\t);\n\n\t\t// Derive some stats about the reversion to return to the caller.\n\t\tlet revertAge = 0;\n\t\tlet currentCommit = headCommit;\n\t\twhile (commitToRevert.revision !== currentCommit.revision) {\n\t\t\trevertAge++;\n\n\t\t\tconst parentCommit = currentCommit.parent;\n\t\t\tassert(parentCommit !== undefined, 0x9a9 /* expected to find a parent commit */);\n\t\t\tcurrentCommit = parentCommit;\n\t\t}\n\n\t\treturn { age: revertAge };\n\t}\n\n\tprivate assertNoUntrackedRoots(): void {\n\t\tconst cursor = this.forest.getCursorAboveDetachedFields();\n\t\tconst rootFields = new Set([rootFieldKey]);\n\t\tfor (const { root } of this.removedRoots.entries()) {\n\t\t\trootFields.add(this.removedRoots.toFieldKey(root));\n\t\t}\n\n\t\tif (!cursor.firstField()) {\n\t\t\treturn;\n\t\t}\n\n\t\tdo {\n\t\t\tconst field = cursor.getFieldKey();\n\t\t\tassert(\n\t\t\t\trootFields.has(field),\n\t\t\t\t0xa22 /* Forest has a root field which is unknown to the detached field index */,\n\t\t\t);\n\n\t\t\trootFields.delete(field);\n\t\t} while (cursor.nextField());\n\t}\n\n\t/**\n\t * `true` iff the given branch change event is due to a remote change\n\t */\n\tprivate isRemoteChangeEvent(event: SharedTreeBranchChange<SharedTreeChange>): boolean {\n\t\treturn (\n\t\t\t// Remote changes are only ever applied to the main branch\n\t\t\t!this.isBranch &&\n\t\t\t// Remote changes are applied to the main branch by rebasing it onto the trunk.\n\t\t\t// No other rebases are allowed on the main branch, so we can use this to detect remote changes.\n\t\t\tevent.type === \"replace\" &&\n\t\t\tgetChangeReplaceType(event) === \"rebase\"\n\t\t);\n\t}\n}\n"]}