@fluidframework/tree 2.0.0-dev-rc.5.0.0.271262 → 2.0.0-dev-rc.5.0.0.272251

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 (458) hide show
  1. package/api-extractor/api-extractor-lint-beta.cjs.json +5 -0
  2. package/api-extractor/api-extractor-lint-beta.esm.json +5 -0
  3. package/api-extractor/api-extractor-lint-bundle.json +5 -0
  4. package/api-extractor/api-extractor-lint-public.cjs.json +5 -0
  5. package/api-extractor/api-extractor-lint-public.esm.json +5 -0
  6. package/api-report/tree.alpha.api.md +2 -13
  7. package/api-report/tree.beta.api.md +2 -13
  8. package/api-report/tree.public.api.md +2 -13
  9. package/dist/beta.d.ts +0 -1
  10. package/dist/codec/codec.js +0 -1
  11. package/dist/codec/codec.js.map +1 -1
  12. package/dist/codec/discriminatedUnions.js +0 -1
  13. package/dist/codec/discriminatedUnions.js.map +1 -1
  14. package/dist/core/change-family/editBuilder.js +0 -2
  15. package/dist/core/change-family/editBuilder.js.map +1 -1
  16. package/dist/core/rebase/revisionTagCodec.js +0 -2
  17. package/dist/core/rebase/revisionTagCodec.js.map +1 -1
  18. package/dist/core/schema-stored/schema.js +0 -4
  19. package/dist/core/schema-stored/schema.js.map +1 -1
  20. package/dist/core/schema-stored/storedSchemaRepository.js +1 -3
  21. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  22. package/dist/core/schema-view/view.js +0 -2
  23. package/dist/core/schema-view/view.js.map +1 -1
  24. package/dist/core/tree/anchorSet.js +46 -51
  25. package/dist/core/tree/anchorSet.js.map +1 -1
  26. package/dist/core/tree/detachedFieldIndex.js +2 -8
  27. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  28. package/dist/core/tree/detachedFieldIndexCodec.js +0 -3
  29. package/dist/core/tree/detachedFieldIndexCodec.js.map +1 -1
  30. package/dist/core/tree/sparseTree.js +11 -15
  31. package/dist/core/tree/sparseTree.js.map +1 -1
  32. package/dist/domains/schemaBuilder.js +70 -70
  33. package/dist/domains/schemaBuilder.js.map +1 -1
  34. package/dist/events/events.js +1 -2
  35. package/dist/events/events.js.map +1 -1
  36. package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -14
  37. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  38. package/dist/feature-libraries/chunked-forest/chunkTree.js +6 -13
  39. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  40. package/dist/feature-libraries/chunked-forest/chunkedForest.js +2 -9
  41. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  42. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js +3 -1
  43. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  44. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +13 -3
  45. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  46. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +6 -11
  47. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  48. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +3 -3
  49. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  50. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +2 -5
  51. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  52. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +0 -1
  53. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  54. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +2 -1
  55. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  56. package/dist/feature-libraries/chunked-forest/codec/codecs.js +4 -1
  57. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  58. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +13 -25
  59. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  60. package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
  61. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js +5 -8
  62. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  63. package/dist/feature-libraries/chunked-forest/sequenceChunk.js +0 -1
  64. package/dist/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  65. package/dist/feature-libraries/chunked-forest/uniformChunk.js +5 -40
  66. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  67. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +0 -2
  68. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  69. package/dist/feature-libraries/detachedFieldIndexSummarizer.js +1 -2
  70. package/dist/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  71. package/dist/feature-libraries/editableTreeBinder.js +12 -13
  72. package/dist/feature-libraries/editableTreeBinder.js.map +1 -1
  73. package/dist/feature-libraries/flex-map-tree/mapTreeNode.js +11 -12
  74. package/dist/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
  75. package/dist/feature-libraries/flex-tree/context.js +3 -7
  76. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  77. package/dist/feature-libraries/flex-tree/lazyEntity.js +22 -13
  78. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  79. package/dist/feature-libraries/flex-tree/lazyField.js +0 -6
  80. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  81. package/dist/feature-libraries/flex-tree/lazyNode.js +17 -10
  82. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  83. package/dist/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  84. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  85. package/dist/feature-libraries/index.d.ts +1 -1
  86. package/dist/feature-libraries/index.d.ts.map +1 -1
  87. package/dist/feature-libraries/index.js +2 -3
  88. package/dist/feature-libraries/index.js.map +1 -1
  89. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +7 -7
  90. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  91. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js +6 -6
  92. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  93. package/dist/feature-libraries/modular-schema/fieldKind.js +0 -2
  94. package/dist/feature-libraries/modular-schema/fieldKind.js.map +1 -1
  95. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js +0 -3
  96. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
  97. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  98. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  99. package/dist/feature-libraries/modular-schema/index.js +2 -2
  100. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  101. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +2 -0
  102. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  103. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +2 -0
  104. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  105. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +39 -24
  106. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  107. package/dist/feature-libraries/node-key/mockNodeKeyManager.js +4 -2
  108. package/dist/feature-libraries/node-key/mockNodeKeyManager.js.map +1 -1
  109. package/dist/feature-libraries/node-key/nodeKeyIndex.js +0 -3
  110. package/dist/feature-libraries/node-key/nodeKeyIndex.js.map +1 -1
  111. package/dist/feature-libraries/object-forest/objectForest.js +28 -23
  112. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  113. package/dist/feature-libraries/optional-field/optionalField.js +5 -3
  114. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  115. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -5
  116. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  117. package/dist/feature-libraries/schemaBuilderBase.js +3 -14
  118. package/dist/feature-libraries/schemaBuilderBase.js.map +1 -1
  119. package/dist/feature-libraries/sequence-field/compose.js +0 -6
  120. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  121. package/dist/feature-libraries/sequence-field/markListFactory.js +4 -3
  122. package/dist/feature-libraries/sequence-field/markListFactory.js.map +1 -1
  123. package/dist/feature-libraries/sequence-field/markQueue.js +2 -4
  124. package/dist/feature-libraries/sequence-field/markQueue.js.map +1 -1
  125. package/dist/feature-libraries/sequence-field/rebase.d.ts +2 -2
  126. package/dist/feature-libraries/sequence-field/rebase.d.ts.map +1 -1
  127. package/dist/feature-libraries/sequence-field/rebase.js +20 -20
  128. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  129. package/dist/feature-libraries/treeCursorUtils.js +9 -13
  130. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  131. package/dist/feature-libraries/typed-schema/typedTreeSchema.js +4 -23
  132. package/dist/feature-libraries/typed-schema/typedTreeSchema.js.map +1 -1
  133. package/dist/feature-libraries/typed-schema/view.js +0 -7
  134. package/dist/feature-libraries/typed-schema/view.js.map +1 -1
  135. package/dist/index.d.ts +1 -1
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +1 -2
  138. package/dist/index.js.map +1 -1
  139. package/dist/packageVersion.d.ts +1 -1
  140. package/dist/packageVersion.js +1 -1
  141. package/dist/packageVersion.js.map +1 -1
  142. package/dist/public.d.ts +0 -1
  143. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  144. package/dist/shared-tree/schematizingTreeView.js +10 -27
  145. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  146. package/dist/shared-tree/sharedTree.d.ts +4 -0
  147. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  148. package/dist/shared-tree/sharedTree.js +13 -10
  149. package/dist/shared-tree/sharedTree.js.map +1 -1
  150. package/dist/shared-tree/sharedTreeChangeEnricher.js +11 -14
  151. package/dist/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  152. package/dist/shared-tree/sharedTreeChangeFamily.js +3 -5
  153. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  154. package/dist/shared-tree/sharedTreeEditBuilder.js +0 -2
  155. package/dist/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  156. package/dist/shared-tree/treeCheckout.js +11 -22
  157. package/dist/shared-tree/treeCheckout.js.map +1 -1
  158. package/dist/shared-tree/treeView.js +0 -6
  159. package/dist/shared-tree/treeView.js.map +1 -1
  160. package/dist/shared-tree-core/branch.d.ts +18 -0
  161. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  162. package/dist/shared-tree-core/branch.js +28 -31
  163. package/dist/shared-tree-core/branch.js.map +1 -1
  164. package/dist/shared-tree-core/branchCommitEnricher.d.ts +4 -2
  165. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  166. package/dist/shared-tree-core/branchCommitEnricher.js +19 -15
  167. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  168. package/dist/shared-tree-core/defaultResubmitMachine.js +19 -21
  169. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  170. package/dist/shared-tree-core/editManager.js +37 -53
  171. package/dist/shared-tree-core/editManager.js.map +1 -1
  172. package/dist/shared-tree-core/editManagerSummarizer.js +1 -5
  173. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  174. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  175. package/dist/shared-tree-core/sharedTreeCore.js +16 -24
  176. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  177. package/dist/shared-tree-core/transactionEnricher.d.ts +11 -1
  178. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  179. package/dist/shared-tree-core/transactionEnricher.js +25 -4
  180. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  181. package/dist/shared-tree-core/transactionStack.js +3 -1
  182. package/dist/shared-tree-core/transactionStack.js.map +1 -1
  183. package/dist/simple-tree/arrayNode.js +34 -26
  184. package/dist/simple-tree/arrayNode.js.map +1 -1
  185. package/dist/simple-tree/leafNodeSchema.js +2 -4
  186. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  187. package/dist/simple-tree/mapNode.js +5 -5
  188. package/dist/simple-tree/mapNode.js.map +1 -1
  189. package/dist/simple-tree/objectNode.js +6 -6
  190. package/dist/simple-tree/objectNode.js.map +1 -1
  191. package/dist/simple-tree/schemaFactory.d.ts +18 -5
  192. package/dist/simple-tree/schemaFactory.d.ts.map +1 -1
  193. package/dist/simple-tree/schemaFactory.js +65 -53
  194. package/dist/simple-tree/schemaFactory.js.map +1 -1
  195. package/dist/simple-tree/schemaTypes.js +3 -12
  196. package/dist/simple-tree/schemaTypes.js.map +1 -1
  197. package/dist/simple-tree/tree.d.ts +1 -22
  198. package/dist/simple-tree/tree.d.ts.map +1 -1
  199. package/dist/simple-tree/tree.js +0 -21
  200. package/dist/simple-tree/tree.js.map +1 -1
  201. package/dist/simple-tree/treeNodeApi.d.ts +13 -4
  202. package/dist/simple-tree/treeNodeApi.d.ts.map +1 -1
  203. package/dist/simple-tree/treeNodeApi.js +8 -3
  204. package/dist/simple-tree/treeNodeApi.js.map +1 -1
  205. package/dist/simple-tree/types.d.ts +26 -6
  206. package/dist/simple-tree/types.d.ts.map +1 -1
  207. package/dist/simple-tree/types.js +79 -54
  208. package/dist/simple-tree/types.js.map +1 -1
  209. package/dist/treeFactory.js +10 -9
  210. package/dist/treeFactory.js.map +1 -1
  211. package/dist/util/brand.js +0 -1
  212. package/dist/util/brand.js.map +1 -1
  213. package/dist/util/nestedMap.js +4 -2
  214. package/dist/util/nestedMap.js.map +1 -1
  215. package/dist/util/offsetList.js +4 -2
  216. package/dist/util/offsetList.js.map +1 -1
  217. package/dist/util/referenceCounting.js +0 -1
  218. package/dist/util/referenceCounting.js.map +1 -1
  219. package/dist/util/stackyIterator.js +2 -3
  220. package/dist/util/stackyIterator.js.map +1 -1
  221. package/lib/beta.d.ts +0 -1
  222. package/lib/codec/codec.js +0 -1
  223. package/lib/codec/codec.js.map +1 -1
  224. package/lib/codec/discriminatedUnions.js +0 -1
  225. package/lib/codec/discriminatedUnions.js.map +1 -1
  226. package/lib/core/change-family/editBuilder.js +0 -2
  227. package/lib/core/change-family/editBuilder.js.map +1 -1
  228. package/lib/core/rebase/revisionTagCodec.js +0 -2
  229. package/lib/core/rebase/revisionTagCodec.js.map +1 -1
  230. package/lib/core/schema-stored/schema.js +0 -4
  231. package/lib/core/schema-stored/schema.js.map +1 -1
  232. package/lib/core/schema-stored/storedSchemaRepository.js +1 -3
  233. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  234. package/lib/core/schema-view/view.js +0 -2
  235. package/lib/core/schema-view/view.js.map +1 -1
  236. package/lib/core/tree/anchorSet.js +46 -51
  237. package/lib/core/tree/anchorSet.js.map +1 -1
  238. package/lib/core/tree/detachedFieldIndex.js +2 -8
  239. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  240. package/lib/core/tree/detachedFieldIndexCodec.js +0 -3
  241. package/lib/core/tree/detachedFieldIndexCodec.js.map +1 -1
  242. package/lib/core/tree/sparseTree.js +11 -15
  243. package/lib/core/tree/sparseTree.js.map +1 -1
  244. package/lib/domains/schemaBuilder.js +70 -70
  245. package/lib/domains/schemaBuilder.js.map +1 -1
  246. package/lib/events/events.js +1 -2
  247. package/lib/events/events.js.map +1 -1
  248. package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -14
  249. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  250. package/lib/feature-libraries/chunked-forest/chunkTree.js +6 -13
  251. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  252. package/lib/feature-libraries/chunked-forest/chunkedForest.js +2 -9
  253. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  254. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js +3 -1
  255. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  256. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +13 -3
  257. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  258. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +6 -11
  259. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  260. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +3 -3
  261. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  262. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +2 -5
  263. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  264. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +0 -1
  265. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  266. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +2 -1
  267. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  268. package/lib/feature-libraries/chunked-forest/codec/codecs.js +4 -1
  269. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  270. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +13 -25
  271. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  272. package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
  273. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js +5 -8
  274. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  275. package/lib/feature-libraries/chunked-forest/sequenceChunk.js +0 -1
  276. package/lib/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  277. package/lib/feature-libraries/chunked-forest/uniformChunk.js +5 -40
  278. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  279. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +0 -2
  280. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  281. package/lib/feature-libraries/detachedFieldIndexSummarizer.js +1 -2
  282. package/lib/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  283. package/lib/feature-libraries/editableTreeBinder.js +12 -13
  284. package/lib/feature-libraries/editableTreeBinder.js.map +1 -1
  285. package/lib/feature-libraries/flex-map-tree/mapTreeNode.js +11 -12
  286. package/lib/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
  287. package/lib/feature-libraries/flex-tree/context.js +3 -7
  288. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  289. package/lib/feature-libraries/flex-tree/lazyEntity.js +22 -13
  290. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  291. package/lib/feature-libraries/flex-tree/lazyField.js +0 -6
  292. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  293. package/lib/feature-libraries/flex-tree/lazyNode.js +17 -10
  294. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  295. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  296. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  297. package/lib/feature-libraries/index.d.ts +1 -1
  298. package/lib/feature-libraries/index.d.ts.map +1 -1
  299. package/lib/feature-libraries/index.js +1 -1
  300. package/lib/feature-libraries/index.js.map +1 -1
  301. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +7 -7
  302. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  303. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js +5 -5
  304. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  305. package/lib/feature-libraries/modular-schema/fieldKind.js +0 -2
  306. package/lib/feature-libraries/modular-schema/fieldKind.js.map +1 -1
  307. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js +0 -3
  308. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
  309. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  310. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  311. package/lib/feature-libraries/modular-schema/index.js +1 -1
  312. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  313. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +2 -0
  314. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  315. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +2 -0
  316. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  317. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +40 -25
  318. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  319. package/lib/feature-libraries/node-key/mockNodeKeyManager.js +4 -2
  320. package/lib/feature-libraries/node-key/mockNodeKeyManager.js.map +1 -1
  321. package/lib/feature-libraries/node-key/nodeKeyIndex.js +0 -3
  322. package/lib/feature-libraries/node-key/nodeKeyIndex.js.map +1 -1
  323. package/lib/feature-libraries/object-forest/objectForest.js +28 -23
  324. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  325. package/lib/feature-libraries/optional-field/optionalField.js +6 -4
  326. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  327. package/lib/feature-libraries/schema-index/schemaSummarizer.js +1 -5
  328. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  329. package/lib/feature-libraries/schemaBuilderBase.js +3 -14
  330. package/lib/feature-libraries/schemaBuilderBase.js.map +1 -1
  331. package/lib/feature-libraries/sequence-field/compose.js +0 -6
  332. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  333. package/lib/feature-libraries/sequence-field/markListFactory.js +4 -3
  334. package/lib/feature-libraries/sequence-field/markListFactory.js.map +1 -1
  335. package/lib/feature-libraries/sequence-field/markQueue.js +2 -4
  336. package/lib/feature-libraries/sequence-field/markQueue.js.map +1 -1
  337. package/lib/feature-libraries/sequence-field/rebase.d.ts +2 -2
  338. package/lib/feature-libraries/sequence-field/rebase.d.ts.map +1 -1
  339. package/lib/feature-libraries/sequence-field/rebase.js +21 -21
  340. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  341. package/lib/feature-libraries/treeCursorUtils.js +9 -13
  342. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  343. package/lib/feature-libraries/typed-schema/typedTreeSchema.js +4 -23
  344. package/lib/feature-libraries/typed-schema/typedTreeSchema.js.map +1 -1
  345. package/lib/feature-libraries/typed-schema/view.js +0 -7
  346. package/lib/feature-libraries/typed-schema/view.js.map +1 -1
  347. package/lib/index.d.ts +1 -1
  348. package/lib/index.d.ts.map +1 -1
  349. package/lib/index.js +1 -1
  350. package/lib/index.js.map +1 -1
  351. package/lib/packageVersion.d.ts +1 -1
  352. package/lib/packageVersion.js +1 -1
  353. package/lib/packageVersion.js.map +1 -1
  354. package/lib/public.d.ts +0 -1
  355. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  356. package/lib/shared-tree/schematizingTreeView.js +10 -27
  357. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  358. package/lib/shared-tree/sharedTree.d.ts +4 -0
  359. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  360. package/lib/shared-tree/sharedTree.js +13 -10
  361. package/lib/shared-tree/sharedTree.js.map +1 -1
  362. package/lib/shared-tree/sharedTreeChangeEnricher.js +11 -14
  363. package/lib/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  364. package/lib/shared-tree/sharedTreeChangeFamily.js +3 -5
  365. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  366. package/lib/shared-tree/sharedTreeEditBuilder.js +0 -2
  367. package/lib/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  368. package/lib/shared-tree/treeCheckout.js +11 -22
  369. package/lib/shared-tree/treeCheckout.js.map +1 -1
  370. package/lib/shared-tree/treeView.js +0 -6
  371. package/lib/shared-tree/treeView.js.map +1 -1
  372. package/lib/shared-tree-core/branch.d.ts +18 -0
  373. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  374. package/lib/shared-tree-core/branch.js +28 -31
  375. package/lib/shared-tree-core/branch.js.map +1 -1
  376. package/lib/shared-tree-core/branchCommitEnricher.d.ts +4 -2
  377. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  378. package/lib/shared-tree-core/branchCommitEnricher.js +19 -15
  379. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  380. package/lib/shared-tree-core/defaultResubmitMachine.js +19 -21
  381. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  382. package/lib/shared-tree-core/editManager.js +37 -53
  383. package/lib/shared-tree-core/editManager.js.map +1 -1
  384. package/lib/shared-tree-core/editManagerSummarizer.js +1 -5
  385. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  386. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  387. package/lib/shared-tree-core/sharedTreeCore.js +16 -24
  388. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  389. package/lib/shared-tree-core/transactionEnricher.d.ts +11 -1
  390. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  391. package/lib/shared-tree-core/transactionEnricher.js +25 -4
  392. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  393. package/lib/shared-tree-core/transactionStack.js +3 -1
  394. package/lib/shared-tree-core/transactionStack.js.map +1 -1
  395. package/lib/simple-tree/arrayNode.js +34 -26
  396. package/lib/simple-tree/arrayNode.js.map +1 -1
  397. package/lib/simple-tree/leafNodeSchema.js +2 -4
  398. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  399. package/lib/simple-tree/mapNode.js +5 -5
  400. package/lib/simple-tree/mapNode.js.map +1 -1
  401. package/lib/simple-tree/objectNode.js +6 -6
  402. package/lib/simple-tree/objectNode.js.map +1 -1
  403. package/lib/simple-tree/schemaFactory.d.ts +18 -5
  404. package/lib/simple-tree/schemaFactory.d.ts.map +1 -1
  405. package/lib/simple-tree/schemaFactory.js +65 -53
  406. package/lib/simple-tree/schemaFactory.js.map +1 -1
  407. package/lib/simple-tree/schemaTypes.js +3 -12
  408. package/lib/simple-tree/schemaTypes.js.map +1 -1
  409. package/lib/simple-tree/tree.d.ts +1 -22
  410. package/lib/simple-tree/tree.d.ts.map +1 -1
  411. package/lib/simple-tree/tree.js +0 -21
  412. package/lib/simple-tree/tree.js.map +1 -1
  413. package/lib/simple-tree/treeNodeApi.d.ts +13 -4
  414. package/lib/simple-tree/treeNodeApi.d.ts.map +1 -1
  415. package/lib/simple-tree/treeNodeApi.js +8 -3
  416. package/lib/simple-tree/treeNodeApi.js.map +1 -1
  417. package/lib/simple-tree/types.d.ts +26 -6
  418. package/lib/simple-tree/types.d.ts.map +1 -1
  419. package/lib/simple-tree/types.js +78 -54
  420. package/lib/simple-tree/types.js.map +1 -1
  421. package/lib/treeFactory.js +10 -9
  422. package/lib/treeFactory.js.map +1 -1
  423. package/lib/util/brand.js +0 -1
  424. package/lib/util/brand.js.map +1 -1
  425. package/lib/util/nestedMap.js +4 -2
  426. package/lib/util/nestedMap.js.map +1 -1
  427. package/lib/util/offsetList.js +4 -2
  428. package/lib/util/offsetList.js.map +1 -1
  429. package/lib/util/referenceCounting.js +0 -1
  430. package/lib/util/referenceCounting.js.map +1 -1
  431. package/lib/util/stackyIterator.js +2 -3
  432. package/lib/util/stackyIterator.js.map +1 -1
  433. package/package.json +27 -24
  434. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +22 -6
  435. package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +2 -2
  436. package/src/feature-libraries/chunked-forest/codec/codecs.ts +6 -2
  437. package/src/feature-libraries/chunked-forest/codec/nodeShape.ts +8 -3
  438. package/src/feature-libraries/index.ts +0 -1
  439. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +6 -7
  440. package/src/feature-libraries/modular-schema/index.ts +1 -1
  441. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +2 -0
  442. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +55 -23
  443. package/src/feature-libraries/optional-field/optionalField.ts +3 -3
  444. package/src/feature-libraries/sequence-field/rebase.ts +15 -33
  445. package/src/index.ts +0 -1
  446. package/src/packageVersion.ts +1 -1
  447. package/src/shared-tree/schematizingTreeView.ts +0 -2
  448. package/src/shared-tree/sharedTree.ts +8 -1
  449. package/src/shared-tree-core/branch.ts +24 -0
  450. package/src/shared-tree-core/branchCommitEnricher.ts +15 -6
  451. package/src/shared-tree-core/sharedTreeCore.ts +9 -0
  452. package/src/shared-tree-core/transactionEnricher.ts +27 -1
  453. package/src/simple-tree/arrayNode.ts +17 -17
  454. package/src/simple-tree/schemaFactory.ts +18 -5
  455. package/src/simple-tree/tree.ts +1 -26
  456. package/src/simple-tree/treeNodeApi.ts +25 -7
  457. package/src/simple-tree/types.ts +57 -9
  458. package/tsdoc.json +4 -0
@@ -37,37 +37,6 @@ exports.getChangeReplaceType = getChangeReplaceType;
37
37
  * A branch of changes that can be applied to a SharedTree.
38
38
  */
39
39
  class SharedTreeBranch extends index_js_2.EventEmitter {
40
- head;
41
- changeFamily;
42
- mintRevisionTag;
43
- branchTrimmer;
44
- editor;
45
- transactions = new transactionStack_js_1.TransactionStack();
46
- /**
47
- * After pushing a starting revision to the transaction stack, this branch might be rebased
48
- * over commits which are children of that starting revision. When the transaction is committed,
49
- * those rebased-over commits should not be included in the transaction's squash commit, even though
50
- * they exist between the starting revision and the final commit within the transaction.
51
- *
52
- * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the
53
- * original merge-base to the new merge-base.
54
- *
55
- * This state need only be retained for the lifetime of the transaction.
56
- *
57
- * TODO: This strategy might need to be revisited when adding better support for async transactions.
58
- * Since:
59
- *
60
- * 1. Transactionality is guaranteed primarily by squashing at commit time
61
- * 2. Branches may be rebased with an ongoing transaction
62
- *
63
- * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the
64
- * purpose of transactionality.
65
- *
66
- * AB#6483 and children items track this work.
67
- */
68
- initialTransactionRevToRebasedRev = new Map();
69
- disposed = false;
70
- unsubscribeBranchTrimmer;
71
40
  /**
72
41
  * Construct a new branch.
73
42
  * @param head - the head of the branch
@@ -81,6 +50,31 @@ class SharedTreeBranch extends index_js_2.EventEmitter {
81
50
  this.changeFamily = changeFamily;
82
51
  this.mintRevisionTag = mintRevisionTag;
83
52
  this.branchTrimmer = branchTrimmer;
53
+ this.transactions = new transactionStack_js_1.TransactionStack();
54
+ /**
55
+ * After pushing a starting revision to the transaction stack, this branch might be rebased
56
+ * over commits which are children of that starting revision. When the transaction is committed,
57
+ * those rebased-over commits should not be included in the transaction's squash commit, even though
58
+ * they exist between the starting revision and the final commit within the transaction.
59
+ *
60
+ * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the
61
+ * original merge-base to the new merge-base.
62
+ *
63
+ * This state need only be retained for the lifetime of the transaction.
64
+ *
65
+ * TODO: This strategy might need to be revisited when adding better support for async transactions.
66
+ * Since:
67
+ *
68
+ * 1. Transactionality is guaranteed primarily by squashing at commit time
69
+ * 2. Branches may be rebased with an ongoing transaction
70
+ *
71
+ * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the
72
+ * purpose of transactionality.
73
+ *
74
+ * AB#6483 and children items track this work.
75
+ */
76
+ this.initialTransactionRevToRebasedRev = new Map();
77
+ this.disposed = false;
84
78
  this.editor = this.changeFamily.buildEditor((change) => this.apply(change, mintRevisionTag()));
85
79
  this.unsubscribeBranchTrimmer = branchTrimmer?.on("ancestryTrimmed", (commit) => {
86
80
  this.emit("ancestryTrimmed", commit);
@@ -146,6 +140,7 @@ class SharedTreeBranch extends index_js_2.EventEmitter {
146
140
  onForkUnSubscribe();
147
141
  });
148
142
  this.editor.enterTransaction();
143
+ this.emit("transactionStarted", this.transactions.size === 1);
149
144
  }
150
145
  /**
151
146
  * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.
@@ -158,6 +153,7 @@ class SharedTreeBranch extends index_js_2.EventEmitter {
158
153
  this.assertNotDisposed();
159
154
  const [startCommit, commits] = this.popTransaction();
160
155
  this.editor.exitTransaction();
156
+ this.emit("transactionCommitted", this.transactions.size === 0);
161
157
  if (commits.length === 0) {
162
158
  return undefined;
163
159
  }
@@ -193,6 +189,7 @@ class SharedTreeBranch extends index_js_2.EventEmitter {
193
189
  this.assertNotDisposed();
194
190
  const [startCommit, commits] = this.popTransaction();
195
191
  this.editor.exitTransaction();
192
+ this.emit("transactionAborted", this.transactions.size === 0);
196
193
  if (commits.length === 0) {
197
194
  return [undefined, []];
198
195
  }
@@ -1 +1 @@
1
- {"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,+CAe0B;AAC1B,iDAAmE;AAEnE,+DAAyD;AAmCzD;;GAEG;AACH,SAAgB,oBAAoB,CACnC,MAA6D;IAE7D,uHAAuH;IACvH,oGAAoG;IACpG,2DAA2D;IAC3D,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,iGAAiG;IACjG,0FAA0F;IAC1F,EAAE;IACF,+DAA+D;IAC/D,gEAAgE;IAChE,EAAE;IACF,uEAAuE;IACvE,IACC,MAAM,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,EAClE,CAAC;QACF,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC5B,CAAC;AAzBD,oDAyBC;AAqDD;;GAEG;AACH,MAAa,gBAA8D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,EAAE,CAAC;QAElC,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC;IAEO,iBAAiB;QACxB,IAAA,iBAAM,EAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;CACD;AAnZD,4CAmZC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC/B,QAAW,EACX,MAAyB;IAEzB,MAAM,IAAI,GAAmB,EAAE,CAAC;IAChC,IAAI,CAAC,IAAI,CACR,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC,CAAC,CACF,CAAC;IACF,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC;AAZD,4CAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype BranchRebaseResult,\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tCommitKind,\n\ttype CommitMetadata,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\ttype TaggedChange,\n\tfindAncestor,\n\tmakeAnonChange,\n\tmintCommit,\n\trebaseBranch,\n\ttagChange,\n\ttagRollbackInverse,\n} from \"../core/index.js\";\nimport { EventEmitter, type Listenable } from \"../events/index.js\";\n\nimport { TransactionStack } from \"./transactionStack.js\";\n\n/**\n * Describes a change to a `SharedTreeBranch`. Various operations can mutate the head of the branch;\n * this change format describes each in terms of the \"removed commits\" (all commits which were present\n * on the branch before the operation but are no longer present after) and the \"new commits\" (all\n * commits which are present on the branch after the operation that were not present before). Each of\n * the following event types also provides a `change` which contains the net change to the branch\n * (or is undefined if there was no net change):\n * * Append - when one or more commits are appended to the head of the branch, for example via\n * a change applied by the branch's editor, or as a result of merging another branch into this one\n * * Remove - when one or more commits are removed from the head of the branch. This occurs\n * when a transaction is aborted and all commits pending in that transaction are removed.\n * * Replace - when an operation simultaneously removes and appends commits. For example, when this\n * branch is rebased and some commits are removed and replaced with rebased versions, or when a\n * transaction completes and all pending commits are replaced with a single squash commit.\n */\nexport type SharedTreeBranchChange<TChange> =\n\t| {\n\t\t\ttype: \"append\";\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t }\n\t| {\n\t\t\ttype: \"remove\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t }\n\t| {\n\t\t\ttype: \"replace\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t };\n\n/**\n * Returns the operation that caused the given {@link SharedTreeBranchChange}.\n */\nexport function getChangeReplaceType(\n\tchange: SharedTreeBranchChange<unknown> & { type: \"replace\" },\n): \"transactionCommit\" | \"rebase\" {\n\t// The \"replace\" variant of the change event is emitted by two operations: committing a transaction and doing a rebase.\n\t// Committing a transaction will always remove one or more commits (the commits that were squashed),\n\t// and will add exactly one new commit (the squash commit).\n\tif (change.removedCommits.length === 0 || change.newCommits.length !== 1) {\n\t\treturn \"rebase\";\n\t}\n\n\t// There is only one case in which a rebase both removes commits and adds exactly one new commit.\n\t// This occurs when there is exactly one divergent, but equivalent, commit on each branch:\n\t//\n\t// A ─ B (branch X)\t -- rebase Y onto X --> A ─ B (branch X)\n\t// └─ B' (branch Y) └─ (branch Y)\n\t//\n\t// B' is removed and replaced by B because both have the same revision.\n\tif (\n\t\tchange.removedCommits.length === 1 &&\n\t\tchange.removedCommits[0].revision === change.newCommits[0].revision\n\t) {\n\t\treturn \"rebase\";\n\t}\n\n\treturn \"transactionCommit\";\n}\n\n/**\n * The events emitted by a `SharedTreeBranch`\n */\nexport interface SharedTreeBranchEvents<TEditor extends ChangeFamilyEditor, TChange>\n\textends BranchTrimmingEvents {\n\t/**\n\t * Fired just before the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tbeforeChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired just after the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tafterChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * {@inheritdoc TreeViewEvents.commitApplied}\n\t */\n\tcommitApplied(data: CommitMetadata): void;\n\n\t/**\n\t * Fired when this branch forks\n\t * @param fork - the new branch that forked off of this branch\n\t */\n\tfork(fork: SharedTreeBranch<TEditor, TChange>): void;\n\n\t/**\n\t * Fired after this branch is disposed\n\t */\n\tdispose(): void;\n}\n\n/**\n * Events related to branch trimming.\n *\n * @remarks\n * Trimming is a very specific kind of mutation which is the only allowed mutations to branches.\n * References to commits from other commits are removed so that the commit objects can be GC'd by the JS engine.\n * This happens by changing a commit's parent property to undefined, which drops all commits that are in its \"ancestry\".\n * It is done as a performance optimization when it is determined that commits are no longer needed for future computation.\n */\nexport interface BranchTrimmingEvents {\n\t/**\n\t * Fired when some contiguous range of commits beginning with the \"global tail\" of this branch are trimmed from the branch.\n\t * This happens by deleting the parent pointer to the last commit in that range. This event can be fired at any time.\n\t */\n\tancestryTrimmed(trimmedRevisions: RevisionTag[]): void;\n}\n\n/**\n * A branch of changes that can be applied to a SharedTree.\n */\nexport class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChange> extends EventEmitter<\n\tSharedTreeBranchEvents<TEditor, TChange>\n> {\n\tpublic readonly editor: TEditor;\n\tprivate readonly transactions = new TransactionStack();\n\t/**\n\t * After pushing a starting revision to the transaction stack, this branch might be rebased\n\t * over commits which are children of that starting revision. When the transaction is committed,\n\t * those rebased-over commits should not be included in the transaction's squash commit, even though\n\t * they exist between the starting revision and the final commit within the transaction.\n\t *\n\t * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the\n\t * original merge-base to the new merge-base.\n\t *\n\t * This state need only be retained for the lifetime of the transaction.\n\t *\n\t * TODO: This strategy might need to be revisited when adding better support for async transactions.\n\t * Since:\n\t *\n\t * 1. Transactionality is guaranteed primarily by squashing at commit time\n\t * 2. Branches may be rebased with an ongoing transaction\n\t *\n\t * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the\n\t * purpose of transactionality.\n\t *\n\t * AB#6483 and children items track this work.\n\t */\n\tprivate readonly initialTransactionRevToRebasedRev = new Map<RevisionTag, RevisionTag>();\n\tprivate disposed = false;\n\tprivate readonly unsubscribeBranchTrimmer?: () => void;\n\t/**\n\t * Construct a new branch.\n\t * @param head - the head of the branch\n\t * @param changeFamily - determines the set of changes that this branch can commit\n\t * @param branchTrimmer - an optional event emitter that informs the branch it has been trimmed. If this is not supplied, then the branch must\n\t * never be trimmed. See {@link BranchTrimmingEvents} for details on trimming.\n\t */\n\tpublic constructor(\n\t\tprivate head: GraphCommit<TChange>,\n\t\tpublic readonly changeFamily: ChangeFamily<TEditor, TChange>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly branchTrimmer?: Listenable<BranchTrimmingEvents>,\n\t) {\n\t\tsuper();\n\t\tthis.editor = this.changeFamily.buildEditor((change) =>\n\t\t\tthis.apply(change, mintRevisionTag()),\n\t\t);\n\t\tthis.unsubscribeBranchTrimmer = branchTrimmer?.on(\"ancestryTrimmed\", (commit) => {\n\t\t\tthis.emit(\"ancestryTrimmed\", commit);\n\t\t});\n\t}\n\n\t/**\n\t * Sets the head of this branch. Emits no change events.\n\t */\n\tpublic setHead(head: GraphCommit<TChange>): void {\n\t\tthis.assertNotDisposed();\n\t\tassert(!this.isTransacting(), 0x685 /* Cannot set head during a transaction */);\n\t\tthis.head = head;\n\t}\n\n\t/**\n\t * Apply a change to this branch.\n\t * @param change - the change to apply\n\t * @param revision - the revision of the new head commit of the branch that contains `change`\n\t * @param changeKind - the kind of change to apply\n\t * @returns the change that was applied and the new head commit of the branch\n\t */\n\tpublic apply(\n\t\tchange: TChange,\n\t\trevision: RevisionTag,\n\t\tchangeKind: CommitKind = CommitKind.Default,\n\t): [change: TChange, newCommit: GraphCommit<TChange>] {\n\t\tthis.assertNotDisposed();\n\n\t\tconst changeWithRevision = this.changeFamily.rebaser.changeRevision(change, revision);\n\n\t\tconst newHead = mintCommit(this.head, {\n\t\t\trevision,\n\t\t\tchange: changeWithRevision,\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tchange: tagChange(changeWithRevision, revision),\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\n\t\t// If this is not part of a transaction, emit a commitApplied event\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.emit(\"commitApplied\", { isLocal: true, kind: changeKind });\n\t\t}\n\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [changeWithRevision, newHead];\n\t}\n\n\t/**\n\t * @returns the commit at the head of this branch.\n\t */\n\tpublic getHead(): GraphCommit<TChange> {\n\t\treturn this.head;\n\t}\n\n\t/**\n\t * Begin a transaction on this branch. If the transaction is committed via {@link commitTransaction},\n\t * all commits made since this call will be squashed into a single head commit.\n\t */\n\tpublic startTransaction(): void {\n\t\tthis.assertNotDisposed();\n\t\tconst forks = new Set<SharedTreeBranch<TEditor, TChange>>();\n\t\tconst onDisposeUnSubscribes: (() => void)[] = [];\n\t\tconst onForkUnSubscribe = onForkTransitive(this, (fork) => {\n\t\t\tforks.add(fork);\n\t\t\tonDisposeUnSubscribes.push(fork.on(\"dispose\", () => forks.delete(fork)));\n\t\t});\n\t\tthis.transactions.push(this.head.revision, () => {\n\t\t\tforks.forEach((fork) => fork.dispose());\n\t\t\tonDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());\n\t\t\tonForkUnSubscribe();\n\t\t});\n\t\tthis.editor.enterTransaction();\n\t}\n\n\t/**\n\t * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.\n\t * If there are commits in the current transaction, they will be squashed into a new single head commit.\n\t * @returns the commits that were squashed and the new squash commit if a squash occurred, otherwise `undefined`.\n\t * @remarks If the transaction had no changes applied during its lifetime, then no squash occurs (i.e. this method is a no-op).\n\t * Even if the transaction contained only one change, it will still be replaced with an (equivalent) squash change.\n\t */\n\tpublic commitTransaction():\n\t\t| [squashedCommits: GraphCommit<TChange>[], newCommit: GraphCommit<TChange>]\n\t\t| undefined {\n\t\tthis.assertNotDisposed();\n\t\tconst [startCommit, commits] = this.popTransaction();\n\t\tthis.editor.exitTransaction();\n\n\t\tif (commits.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Squash the changes and make the squash commit the new head of this branch\n\t\tconst squashedChange = this.changeFamily.rebaser.compose(commits);\n\t\tconst revision = this.mintRevisionTag();\n\n\t\tconst newHead = mintCommit(startCommit, {\n\t\t\trevision,\n\t\t\tchange: this.changeFamily.rebaser.changeRevision(squashedChange, revision),\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tchange: undefined,\n\t\t\tremovedCommits: commits,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\n\t\t// If this transaction is not nested, emit a commitApplied event\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.emit(\"commitApplied\", { isLocal: true, kind: CommitKind.Default });\n\t\t}\n\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [commits, newHead];\n\t}\n\n\t/**\n\t * Cancel the current transaction. There must be a transaction in progress that was begun via\n\t * {@link startTransaction}. All commits made during the transaction will be removed.\n\t * @returns the change to this branch resulting in the removal of the commits, and a list of the\n\t * commits that were removed.\n\t */\n\tpublic abortTransaction(): [\n\t\tchange: TChange | undefined,\n\t\tabortedCommits: GraphCommit<TChange>[],\n\t] {\n\t\tthis.assertNotDisposed();\n\t\tconst [startCommit, commits] = this.popTransaction();\n\t\tthis.editor.exitTransaction();\n\n\t\tif (commits.length === 0) {\n\t\t\treturn [undefined, []];\n\t\t}\n\n\t\tconst inverses: TaggedChange<TChange>[] = [];\n\t\tfor (let i = commits.length - 1; i >= 0; i--) {\n\t\t\tconst revision = this.mintRevisionTag();\n\t\t\tconst inverse = this.changeFamily.rebaser.changeRevision(\n\t\t\t\tthis.changeFamily.rebaser.invert(commits[i], false),\n\t\t\t\trevision,\n\t\t\t\tcommits[i].revision,\n\t\t\t);\n\n\t\t\tinverses.push(tagRollbackInverse(inverse, revision, commits[i].revision));\n\t\t}\n\t\tconst change =\n\t\t\tinverses.length > 0 ? this.changeFamily.rebaser.compose(inverses) : undefined;\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"remove\",\n\t\t\tchange: change === undefined ? undefined : makeAnonChange(change),\n\t\t\tremovedCommits: commits,\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = startCommit;\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [change, commits];\n\t}\n\n\t/**\n\t * True iff this branch is in the middle of a transaction that was begin via {@link startTransaction}\n\t */\n\tpublic isTransacting(): boolean {\n\t\treturn this.transactions.size !== 0;\n\t}\n\n\tprivate popTransaction(): [GraphCommit<TChange>, GraphCommit<TChange>[]] {\n\t\tconst { startRevision: startRevisionOriginal } = this.transactions.pop();\n\t\tlet startRevision = startRevisionOriginal;\n\t\twhile (this.initialTransactionRevToRebasedRev.has(startRevision)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tstartRevision = this.initialTransactionRevToRebasedRev.get(startRevision)!;\n\t\t}\n\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.initialTransactionRevToRebasedRev.clear();\n\t\t}\n\n\t\tconst commits: GraphCommit<TChange>[] = [];\n\t\tconst startCommit = findAncestor([this.head, commits], (c) => c.revision === startRevision);\n\t\tassert(\n\t\t\tstartCommit !== undefined,\n\t\t\t0x593 /* Expected branch to be ahead of transaction start revision */,\n\t\t);\n\t\treturn [startCommit, commits];\n\t}\n\n\t/**\n\t * Spawn a new branch that is based off of the current state of this branch.\n\t * Changes made to the new branch will not be applied to this branch until the new branch is merged back in.\n\t *\n\t * @remarks Forks created during a transaction will be disposed when the transaction ends.\n\t */\n\tpublic fork(): SharedTreeBranch<TEditor, TChange> {\n\t\tthis.assertNotDisposed();\n\t\tconst fork = new SharedTreeBranch(\n\t\t\tthis.head,\n\t\t\tthis.changeFamily,\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.branchTrimmer,\n\t\t);\n\t\tthis.emit(\"fork\", fork);\n\t\treturn fork;\n\t}\n\n\t/**\n\t * Rebase the changes that have been applied to this branch over divergent changes in the given branch.\n\t * After this operation completes, this branch will be based off of `branch`.\n\t *\n\t * @param branch - the branch to rebase onto\n\t * @param upTo - the furthest commit on `branch` over which to rebase (inclusive). Defaults to the head commit of `branch`.\n\t * @returns the result of the rebase or undefined if nothing changed\n\t */\n\tpublic rebaseOnto(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = branch.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tthis.assertNotDisposed();\n\n\t\t// Rebase this branch onto the given branch\n\t\tconst rebaseResult = this.rebaseBranch(this, branch, upTo);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The net change to this branch is provided by the `rebaseBranch` API\n\t\tconst { newSourceHead, commits } = rebaseResult;\n\t\tconst { deletedSourceCommits, targetCommits, sourceCommits } = commits;\n\n\t\tconst newCommits = targetCommits.concat(sourceCommits);\n\t\tif (this.isTransacting()) {\n\t\t\tconst src = targetCommits[0].parent?.revision;\n\t\t\tconst dst = targetCommits[targetCommits.length - 1].revision;\n\t\t\tif (src !== undefined && dst !== undefined) {\n\t\t\t\tthis.initialTransactionRevToRebasedRev.set(src, dst);\n\t\t\t}\n\t\t}\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tget change() {\n\t\t\t\tconst change = rebaseResult.sourceChange;\n\t\t\t\treturn change === undefined ? undefined : makeAnonChange(change);\n\t\t\t},\n\t\t\tremovedCommits: deletedSourceCommits,\n\t\t\tnewCommits,\n\t\t} as const;\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newSourceHead;\n\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn rebaseResult;\n\t}\n\n\t/**\n\t * Apply all the divergent changes on the given branch to this branch.\n\t *\n\t * @param branch - the branch to merge into this branch\n\t * @returns the net change to this branch and the commits that were added to this branch by the merge,\n\t * or undefined if nothing changed\n\t */\n\tpublic merge(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t): [change: TChange, newCommits: GraphCommit<TChange>[]] | undefined {\n\t\tthis.assertNotDisposed();\n\t\tbranch.assertNotDisposed();\n\t\tassert(\n\t\t\t!branch.isTransacting(),\n\t\t\t0x597 /* Branch may not be merged while transaction is in progress */,\n\t\t);\n\n\t\t// Rebase the given branch onto this branch\n\t\tconst rebaseResult = this.rebaseBranch(branch, this);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Compute the net change to this branch\n\t\tconst sourceCommits = rebaseResult.commits.sourceCommits;\n\t\tconst change = this.changeFamily.rebaser.compose(sourceCommits);\n\t\tconst taggedChange = makeAnonChange(change);\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tget change(): TaggedChange<TChange> {\n\t\t\t\treturn taggedChange;\n\t\t\t},\n\t\t\tnewCommits: sourceCommits,\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = rebaseResult.newSourceHead;\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [change, sourceCommits];\n\t}\n\n\t/** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */\n\tprivate rebaseBranch(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tonto: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = onto.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tconst { head } = branch;\n\t\tif (head === upTo) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst rebaseResult = rebaseBranch(\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.changeFamily.rebaser,\n\t\t\thead,\n\t\t\tupTo,\n\t\t\tonto.getHead(),\n\t\t);\n\t\tif (this.head === rebaseResult.newSourceHead) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn rebaseResult;\n\t}\n\n\t/**\n\t * Dispose this branch, freezing its state.\n\t *\n\t * @remarks\n\t * Attempts to further mutate the branch will error.\n\t * Any transactions in progress will be aborted.\n\t * Calling dispose more than once has no effect.\n\t */\n\tpublic dispose(): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\twhile (this.isTransacting()) {\n\t\t\tthis.abortTransaction();\n\t\t}\n\n\t\tthis.unsubscribeBranchTrimmer?.();\n\n\t\tthis.disposed = true;\n\t\tthis.emit(\"dispose\");\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tassert(!this.disposed, 0x66e /* Branch is disposed */);\n\t}\n}\n\n/**\n * Registers an event listener that fires when the given forkable object forks.\n * The listener will also fire when any of those forks fork, and when those forks of forks fork, and so on.\n * @param forkable - an object that emits an event when it is forked\n * @param onFork - the fork event listener\n * @returns a function which when called will deregister all registrations (including transitive) created by this function.\n * The deregister function has undefined behavior if called more than once.\n */\nexport function onForkTransitive<T extends Listenable<{ fork: (t: T) => void }>>(\n\tforkable: T,\n\tonFork: (fork: T) => void,\n): () => void {\n\tconst offs: (() => void)[] = [];\n\toffs.push(\n\t\tforkable.on(\"fork\", (fork) => {\n\t\t\toffs.push(onForkTransitive(fork, onFork));\n\t\t\tonFork(fork);\n\t\t}),\n\t);\n\treturn () => offs.forEach((off) => off());\n}\n"]}
1
+ {"version":3,"file":"branch.js","sourceRoot":"","sources":["../../src/shared-tree-core/branch.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,+CAe0B;AAC1B,iDAAmE;AAEnE,+DAAyD;AAmCzD;;GAEG;AACH,SAAgB,oBAAoB,CACnC,MAA6D;IAE7D,uHAAuH;IACvH,oGAAoG;IACpG,2DAA2D;IAC3D,IAAI,MAAM,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,CAAC,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC1E,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,iGAAiG;IACjG,0FAA0F;IAC1F,EAAE;IACF,+DAA+D;IAC/D,gEAAgE;IAChE,EAAE;IACF,uEAAuE;IACvE,IACC,MAAM,CAAC,cAAc,CAAC,MAAM,KAAK,CAAC;QAClC,MAAM,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,EAClE,CAAC;QACF,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED,OAAO,mBAAmB,CAAC;AAC5B,CAAC;AAzBD,oDAyBC;AA0ED;;GAEG;AACH,MAAa,gBAA8D,SAAQ,uBAElF;IA4BA;;;;;;OAMG;IACH,YACS,IAA0B,EAClB,YAA4C,EAC3C,eAAkC,EAClC,aAAgD;QAEjE,KAAK,EAAE,CAAC;QALA,SAAI,GAAJ,IAAI,CAAsB;QAClB,iBAAY,GAAZ,YAAY,CAAgC;QAC3C,oBAAe,GAAf,eAAe,CAAmB;QAClC,kBAAa,GAAb,aAAa,CAAmC;QArCjD,iBAAY,GAAG,IAAI,sCAAgB,EAAE,CAAC;QACvD;;;;;;;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AI,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;IACtB,CAAC;IAEO,iBAAiB;QACxB,IAAA,iBAAM,EAAC,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,wBAAwB,CAAC,CAAC;IACxD,CAAC;CACD;AAtZD,4CAsZC;AAED;;;;;;;GAOG;AACH,SAAgB,gBAAgB,CAC/B,QAAW,EACX,MAAyB;IAEzB,MAAM,IAAI,GAAmB,EAAE,CAAC;IAChC,IAAI,CAAC,IAAI,CACR,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,EAAE;QAC5B,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC;QAC1C,MAAM,CAAC,IAAI,CAAC,CAAC;IACd,CAAC,CAAC,CACF,CAAC;IACF,OAAO,GAAG,EAAE,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC;AAC3C,CAAC;AAZD,4CAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype BranchRebaseResult,\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tCommitKind,\n\ttype CommitMetadata,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\ttype TaggedChange,\n\tfindAncestor,\n\tmakeAnonChange,\n\tmintCommit,\n\trebaseBranch,\n\ttagChange,\n\ttagRollbackInverse,\n} from \"../core/index.js\";\nimport { EventEmitter, type Listenable } from \"../events/index.js\";\n\nimport { TransactionStack } from \"./transactionStack.js\";\n\n/**\n * Describes a change to a `SharedTreeBranch`. Various operations can mutate the head of the branch;\n * this change format describes each in terms of the \"removed commits\" (all commits which were present\n * on the branch before the operation but are no longer present after) and the \"new commits\" (all\n * commits which are present on the branch after the operation that were not present before). Each of\n * the following event types also provides a `change` which contains the net change to the branch\n * (or is undefined if there was no net change):\n * * Append - when one or more commits are appended to the head of the branch, for example via\n * a change applied by the branch's editor, or as a result of merging another branch into this one\n * * Remove - when one or more commits are removed from the head of the branch. This occurs\n * when a transaction is aborted and all commits pending in that transaction are removed.\n * * Replace - when an operation simultaneously removes and appends commits. For example, when this\n * branch is rebased and some commits are removed and replaced with rebased versions, or when a\n * transaction completes and all pending commits are replaced with a single squash commit.\n */\nexport type SharedTreeBranchChange<TChange> =\n\t| {\n\t\t\ttype: \"append\";\n\t\t\tchange: TaggedChange<TChange>;\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t }\n\t| {\n\t\t\ttype: \"remove\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t }\n\t| {\n\t\t\ttype: \"replace\";\n\t\t\tchange: TaggedChange<TChange> | undefined;\n\t\t\tremovedCommits: readonly GraphCommit<TChange>[];\n\t\t\tnewCommits: readonly GraphCommit<TChange>[];\n\t };\n\n/**\n * Returns the operation that caused the given {@link SharedTreeBranchChange}.\n */\nexport function getChangeReplaceType(\n\tchange: SharedTreeBranchChange<unknown> & { type: \"replace\" },\n): \"transactionCommit\" | \"rebase\" {\n\t// The \"replace\" variant of the change event is emitted by two operations: committing a transaction and doing a rebase.\n\t// Committing a transaction will always remove one or more commits (the commits that were squashed),\n\t// and will add exactly one new commit (the squash commit).\n\tif (change.removedCommits.length === 0 || change.newCommits.length !== 1) {\n\t\treturn \"rebase\";\n\t}\n\n\t// There is only one case in which a rebase both removes commits and adds exactly one new commit.\n\t// This occurs when there is exactly one divergent, but equivalent, commit on each branch:\n\t//\n\t// A ─ B (branch X)\t -- rebase Y onto X --> A ─ B (branch X)\n\t// └─ B' (branch Y) └─ (branch Y)\n\t//\n\t// B' is removed and replaced by B because both have the same revision.\n\tif (\n\t\tchange.removedCommits.length === 1 &&\n\t\tchange.removedCommits[0].revision === change.newCommits[0].revision\n\t) {\n\t\treturn \"rebase\";\n\t}\n\n\treturn \"transactionCommit\";\n}\n\n/**\n * The events emitted by a `SharedTreeBranch`\n */\nexport interface SharedTreeBranchEvents<TEditor extends ChangeFamilyEditor, TChange>\n\textends BranchTrimmingEvents {\n\t/**\n\t * Fired just before the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tbeforeChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * Fired just after the head of this branch changes.\n\t * @param change - the change to this branch's state and commits\n\t */\n\tafterChange(change: SharedTreeBranchChange<TChange>): void;\n\n\t/**\n\t * {@inheritdoc TreeViewEvents.commitApplied}\n\t */\n\tcommitApplied(data: CommitMetadata): void;\n\n\t/**\n\t * Fired when this branch forks\n\t * @param fork - the new branch that forked off of this branch\n\t */\n\tfork(fork: SharedTreeBranch<TEditor, TChange>): void;\n\n\t/**\n\t * Fired after this branch is disposed\n\t */\n\tdispose(): void;\n\n\t/**\n\t * Fired after a new transaction is started.\n\t * @param isOuterTransaction - true iff the transaction being started is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionStarted(isOuterTransaction: boolean): void;\n\n\t/**\n\t * Fired after the current transaction is aborted.\n\t * @param isOuterTransaction - true iff the transaction being aborted is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionAborted(isOuterTransaction: boolean): void;\n\n\t/**\n\t * Fired after the current transaction is committed.\n\t * @param isOuterTransaction - true iff the transaction being committed is the outermost transaction\n\t * as opposed to a nested transaction.\n\t */\n\ttransactionCommitted(isOuterTransaction: boolean): void;\n}\n\n/**\n * Events related to branch trimming.\n *\n * @remarks\n * Trimming is a very specific kind of mutation which is the only allowed mutations to branches.\n * References to commits from other commits are removed so that the commit objects can be GC'd by the JS engine.\n * This happens by changing a commit's parent property to undefined, which drops all commits that are in its \"ancestry\".\n * It is done as a performance optimization when it is determined that commits are no longer needed for future computation.\n */\nexport interface BranchTrimmingEvents {\n\t/**\n\t * Fired when some contiguous range of commits beginning with the \"global tail\" of this branch are trimmed from the branch.\n\t * This happens by deleting the parent pointer to the last commit in that range. This event can be fired at any time.\n\t */\n\tancestryTrimmed(trimmedRevisions: RevisionTag[]): void;\n}\n\n/**\n * A branch of changes that can be applied to a SharedTree.\n */\nexport class SharedTreeBranch<TEditor extends ChangeFamilyEditor, TChange> extends EventEmitter<\n\tSharedTreeBranchEvents<TEditor, TChange>\n> {\n\tpublic readonly editor: TEditor;\n\tprivate readonly transactions = new TransactionStack();\n\t/**\n\t * After pushing a starting revision to the transaction stack, this branch might be rebased\n\t * over commits which are children of that starting revision. When the transaction is committed,\n\t * those rebased-over commits should not be included in the transaction's squash commit, even though\n\t * they exist between the starting revision and the final commit within the transaction.\n\t *\n\t * Whenever `rebaseOnto` is called during a transaction, this map is augmented with an entry from the\n\t * original merge-base to the new merge-base.\n\t *\n\t * This state need only be retained for the lifetime of the transaction.\n\t *\n\t * TODO: This strategy might need to be revisited when adding better support for async transactions.\n\t * Since:\n\t *\n\t * 1. Transactionality is guaranteed primarily by squashing at commit time\n\t * 2. Branches may be rebased with an ongoing transaction\n\t *\n\t * a rebase operation might invalidate only a portion of a transaction's commits, thus defeating the\n\t * purpose of transactionality.\n\t *\n\t * AB#6483 and children items track this work.\n\t */\n\tprivate readonly initialTransactionRevToRebasedRev = new Map<RevisionTag, RevisionTag>();\n\tprivate disposed = false;\n\tprivate readonly unsubscribeBranchTrimmer?: () => void;\n\t/**\n\t * Construct a new branch.\n\t * @param head - the head of the branch\n\t * @param changeFamily - determines the set of changes that this branch can commit\n\t * @param branchTrimmer - an optional event emitter that informs the branch it has been trimmed. If this is not supplied, then the branch must\n\t * never be trimmed. See {@link BranchTrimmingEvents} for details on trimming.\n\t */\n\tpublic constructor(\n\t\tprivate head: GraphCommit<TChange>,\n\t\tpublic readonly changeFamily: ChangeFamily<TEditor, TChange>,\n\t\tprivate readonly mintRevisionTag: () => RevisionTag,\n\t\tprivate readonly branchTrimmer?: Listenable<BranchTrimmingEvents>,\n\t) {\n\t\tsuper();\n\t\tthis.editor = this.changeFamily.buildEditor((change) =>\n\t\t\tthis.apply(change, mintRevisionTag()),\n\t\t);\n\t\tthis.unsubscribeBranchTrimmer = branchTrimmer?.on(\"ancestryTrimmed\", (commit) => {\n\t\t\tthis.emit(\"ancestryTrimmed\", commit);\n\t\t});\n\t}\n\n\t/**\n\t * Sets the head of this branch. Emits no change events.\n\t */\n\tpublic setHead(head: GraphCommit<TChange>): void {\n\t\tthis.assertNotDisposed();\n\t\tassert(!this.isTransacting(), 0x685 /* Cannot set head during a transaction */);\n\t\tthis.head = head;\n\t}\n\n\t/**\n\t * Apply a change to this branch.\n\t * @param change - the change to apply\n\t * @param revision - the revision of the new head commit of the branch that contains `change`\n\t * @param changeKind - the kind of change to apply\n\t * @returns the change that was applied and the new head commit of the branch\n\t */\n\tpublic apply(\n\t\tchange: TChange,\n\t\trevision: RevisionTag,\n\t\tchangeKind: CommitKind = CommitKind.Default,\n\t): [change: TChange, newCommit: GraphCommit<TChange>] {\n\t\tthis.assertNotDisposed();\n\n\t\tconst changeWithRevision = this.changeFamily.rebaser.changeRevision(change, revision);\n\n\t\tconst newHead = mintCommit(this.head, {\n\t\t\trevision,\n\t\t\tchange: changeWithRevision,\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tchange: tagChange(changeWithRevision, revision),\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\n\t\t// If this is not part of a transaction, emit a commitApplied event\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.emit(\"commitApplied\", { isLocal: true, kind: changeKind });\n\t\t}\n\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [changeWithRevision, newHead];\n\t}\n\n\t/**\n\t * @returns the commit at the head of this branch.\n\t */\n\tpublic getHead(): GraphCommit<TChange> {\n\t\treturn this.head;\n\t}\n\n\t/**\n\t * Begin a transaction on this branch. If the transaction is committed via {@link commitTransaction},\n\t * all commits made since this call will be squashed into a single head commit.\n\t */\n\tpublic startTransaction(): void {\n\t\tthis.assertNotDisposed();\n\t\tconst forks = new Set<SharedTreeBranch<TEditor, TChange>>();\n\t\tconst onDisposeUnSubscribes: (() => void)[] = [];\n\t\tconst onForkUnSubscribe = onForkTransitive(this, (fork) => {\n\t\t\tforks.add(fork);\n\t\t\tonDisposeUnSubscribes.push(fork.on(\"dispose\", () => forks.delete(fork)));\n\t\t});\n\t\tthis.transactions.push(this.head.revision, () => {\n\t\t\tforks.forEach((fork) => fork.dispose());\n\t\t\tonDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());\n\t\t\tonForkUnSubscribe();\n\t\t});\n\t\tthis.editor.enterTransaction();\n\t\tthis.emit(\"transactionStarted\", this.transactions.size === 1);\n\t}\n\n\t/**\n\t * Commit the current transaction. There must be a transaction in progress that was begun via {@link startTransaction}.\n\t * If there are commits in the current transaction, they will be squashed into a new single head commit.\n\t * @returns the commits that were squashed and the new squash commit if a squash occurred, otherwise `undefined`.\n\t * @remarks If the transaction had no changes applied during its lifetime, then no squash occurs (i.e. this method is a no-op).\n\t * Even if the transaction contained only one change, it will still be replaced with an (equivalent) squash change.\n\t */\n\tpublic commitTransaction():\n\t\t| [squashedCommits: GraphCommit<TChange>[], newCommit: GraphCommit<TChange>]\n\t\t| undefined {\n\t\tthis.assertNotDisposed();\n\t\tconst [startCommit, commits] = this.popTransaction();\n\t\tthis.editor.exitTransaction();\n\n\t\tthis.emit(\"transactionCommitted\", this.transactions.size === 0);\n\t\tif (commits.length === 0) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Squash the changes and make the squash commit the new head of this branch\n\t\tconst squashedChange = this.changeFamily.rebaser.compose(commits);\n\t\tconst revision = this.mintRevisionTag();\n\n\t\tconst newHead = mintCommit(startCommit, {\n\t\t\trevision,\n\t\t\tchange: this.changeFamily.rebaser.changeRevision(squashedChange, revision),\n\t\t});\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tchange: undefined,\n\t\t\tremovedCommits: commits,\n\t\t\tnewCommits: [newHead],\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newHead;\n\n\t\t// If this transaction is not nested, emit a commitApplied event\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.emit(\"commitApplied\", { isLocal: true, kind: CommitKind.Default });\n\t\t}\n\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [commits, newHead];\n\t}\n\n\t/**\n\t * Cancel the current transaction. There must be a transaction in progress that was begun via\n\t * {@link startTransaction}. All commits made during the transaction will be removed.\n\t * @returns the change to this branch resulting in the removal of the commits, and a list of the\n\t * commits that were removed.\n\t */\n\tpublic abortTransaction(): [\n\t\tchange: TChange | undefined,\n\t\tabortedCommits: GraphCommit<TChange>[],\n\t] {\n\t\tthis.assertNotDisposed();\n\t\tconst [startCommit, commits] = this.popTransaction();\n\t\tthis.editor.exitTransaction();\n\n\t\tthis.emit(\"transactionAborted\", this.transactions.size === 0);\n\t\tif (commits.length === 0) {\n\t\t\treturn [undefined, []];\n\t\t}\n\n\t\tconst inverses: TaggedChange<TChange>[] = [];\n\t\tfor (let i = commits.length - 1; i >= 0; i--) {\n\t\t\tconst revision = this.mintRevisionTag();\n\t\t\tconst inverse = this.changeFamily.rebaser.changeRevision(\n\t\t\t\tthis.changeFamily.rebaser.invert(commits[i], false),\n\t\t\t\trevision,\n\t\t\t\tcommits[i].revision,\n\t\t\t);\n\n\t\t\tinverses.push(tagRollbackInverse(inverse, revision, commits[i].revision));\n\t\t}\n\t\tconst change =\n\t\t\tinverses.length > 0 ? this.changeFamily.rebaser.compose(inverses) : undefined;\n\n\t\tconst changeEvent = {\n\t\t\ttype: \"remove\",\n\t\t\tchange: change === undefined ? undefined : makeAnonChange(change),\n\t\t\tremovedCommits: commits,\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = startCommit;\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [change, commits];\n\t}\n\n\t/**\n\t * True iff this branch is in the middle of a transaction that was begin via {@link startTransaction}\n\t */\n\tpublic isTransacting(): boolean {\n\t\treturn this.transactions.size !== 0;\n\t}\n\n\tprivate popTransaction(): [GraphCommit<TChange>, GraphCommit<TChange>[]] {\n\t\tconst { startRevision: startRevisionOriginal } = this.transactions.pop();\n\t\tlet startRevision = startRevisionOriginal;\n\t\twhile (this.initialTransactionRevToRebasedRev.has(startRevision)) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tstartRevision = this.initialTransactionRevToRebasedRev.get(startRevision)!;\n\t\t}\n\n\t\tif (!this.isTransacting()) {\n\t\t\tthis.initialTransactionRevToRebasedRev.clear();\n\t\t}\n\n\t\tconst commits: GraphCommit<TChange>[] = [];\n\t\tconst startCommit = findAncestor([this.head, commits], (c) => c.revision === startRevision);\n\t\tassert(\n\t\t\tstartCommit !== undefined,\n\t\t\t0x593 /* Expected branch to be ahead of transaction start revision */,\n\t\t);\n\t\treturn [startCommit, commits];\n\t}\n\n\t/**\n\t * Spawn a new branch that is based off of the current state of this branch.\n\t * Changes made to the new branch will not be applied to this branch until the new branch is merged back in.\n\t *\n\t * @remarks Forks created during a transaction will be disposed when the transaction ends.\n\t */\n\tpublic fork(): SharedTreeBranch<TEditor, TChange> {\n\t\tthis.assertNotDisposed();\n\t\tconst fork = new SharedTreeBranch(\n\t\t\tthis.head,\n\t\t\tthis.changeFamily,\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.branchTrimmer,\n\t\t);\n\t\tthis.emit(\"fork\", fork);\n\t\treturn fork;\n\t}\n\n\t/**\n\t * Rebase the changes that have been applied to this branch over divergent changes in the given branch.\n\t * After this operation completes, this branch will be based off of `branch`.\n\t *\n\t * @param branch - the branch to rebase onto\n\t * @param upTo - the furthest commit on `branch` over which to rebase (inclusive). Defaults to the head commit of `branch`.\n\t * @returns the result of the rebase or undefined if nothing changed\n\t */\n\tpublic rebaseOnto(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = branch.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tthis.assertNotDisposed();\n\n\t\t// Rebase this branch onto the given branch\n\t\tconst rebaseResult = this.rebaseBranch(this, branch, upTo);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// The net change to this branch is provided by the `rebaseBranch` API\n\t\tconst { newSourceHead, commits } = rebaseResult;\n\t\tconst { deletedSourceCommits, targetCommits, sourceCommits } = commits;\n\n\t\tconst newCommits = targetCommits.concat(sourceCommits);\n\t\tif (this.isTransacting()) {\n\t\t\tconst src = targetCommits[0].parent?.revision;\n\t\t\tconst dst = targetCommits[targetCommits.length - 1].revision;\n\t\t\tif (src !== undefined && dst !== undefined) {\n\t\t\t\tthis.initialTransactionRevToRebasedRev.set(src, dst);\n\t\t\t}\n\t\t}\n\t\tconst changeEvent = {\n\t\t\ttype: \"replace\",\n\t\t\tget change() {\n\t\t\t\tconst change = rebaseResult.sourceChange;\n\t\t\t\treturn change === undefined ? undefined : makeAnonChange(change);\n\t\t\t},\n\t\t\tremovedCommits: deletedSourceCommits,\n\t\t\tnewCommits,\n\t\t} as const;\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = newSourceHead;\n\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn rebaseResult;\n\t}\n\n\t/**\n\t * Apply all the divergent changes on the given branch to this branch.\n\t *\n\t * @param branch - the branch to merge into this branch\n\t * @returns the net change to this branch and the commits that were added to this branch by the merge,\n\t * or undefined if nothing changed\n\t */\n\tpublic merge(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t): [change: TChange, newCommits: GraphCommit<TChange>[]] | undefined {\n\t\tthis.assertNotDisposed();\n\t\tbranch.assertNotDisposed();\n\t\tassert(\n\t\t\t!branch.isTransacting(),\n\t\t\t0x597 /* Branch may not be merged while transaction is in progress */,\n\t\t);\n\n\t\t// Rebase the given branch onto this branch\n\t\tconst rebaseResult = this.rebaseBranch(branch, this);\n\t\tif (rebaseResult === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\t// Compute the net change to this branch\n\t\tconst sourceCommits = rebaseResult.commits.sourceCommits;\n\t\tconst change = this.changeFamily.rebaser.compose(sourceCommits);\n\t\tconst taggedChange = makeAnonChange(change);\n\t\tconst changeEvent = {\n\t\t\ttype: \"append\",\n\t\t\tget change(): TaggedChange<TChange> {\n\t\t\t\treturn taggedChange;\n\t\t\t},\n\t\t\tnewCommits: sourceCommits,\n\t\t} as const;\n\n\t\tthis.emit(\"beforeChange\", changeEvent);\n\t\tthis.head = rebaseResult.newSourceHead;\n\t\tthis.emit(\"afterChange\", changeEvent);\n\t\treturn [change, sourceCommits];\n\t}\n\n\t/** Rebase `branchHead` onto `onto`, but return undefined if nothing changed */\n\tprivate rebaseBranch(\n\t\tbranch: SharedTreeBranch<TEditor, TChange>,\n\t\tonto: SharedTreeBranch<TEditor, TChange>,\n\t\tupTo = onto.getHead(),\n\t): BranchRebaseResult<TChange> | undefined {\n\t\tconst { head } = branch;\n\t\tif (head === upTo) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst rebaseResult = rebaseBranch(\n\t\t\tthis.mintRevisionTag,\n\t\t\tthis.changeFamily.rebaser,\n\t\t\thead,\n\t\t\tupTo,\n\t\t\tonto.getHead(),\n\t\t);\n\t\tif (this.head === rebaseResult.newSourceHead) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\treturn rebaseResult;\n\t}\n\n\t/**\n\t * Dispose this branch, freezing its state.\n\t *\n\t * @remarks\n\t * Attempts to further mutate the branch will error.\n\t * Any transactions in progress will be aborted.\n\t * Calling dispose more than once has no effect.\n\t */\n\tpublic dispose(): void {\n\t\tif (this.disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\twhile (this.isTransacting()) {\n\t\t\tthis.abortTransaction();\n\t\t}\n\n\t\tthis.unsubscribeBranchTrimmer?.();\n\n\t\tthis.disposed = true;\n\t\tthis.emit(\"dispose\");\n\t}\n\n\tprivate assertNotDisposed(): void {\n\t\tassert(!this.disposed, 0x66e /* Branch is disposed */);\n\t}\n}\n\n/**\n * Registers an event listener that fires when the given forkable object forks.\n * The listener will also fire when any of those forks fork, and when those forks of forks fork, and so on.\n * @param forkable - an object that emits an event when it is forked\n * @param onFork - the fork event listener\n * @returns a function which when called will deregister all registrations (including transitive) created by this function.\n * The deregister function has undefined behavior if called more than once.\n */\nexport function onForkTransitive<T extends Listenable<{ fork: (t: T) => void }>>(\n\tforkable: T,\n\tonFork: (fork: T) => void,\n): () => void {\n\tconst offs: (() => void)[] = [];\n\toffs.push(\n\t\tforkable.on(\"fork\", (fork) => {\n\t\t\toffs.push(onForkTransitive(fork, onFork));\n\t\t\tonFork(fork);\n\t\t}),\n\t);\n\treturn () => offs.forEach((off) => off());\n}\n"]}
@@ -8,8 +8,7 @@ import type { ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
8
8
  * Utility for enriching commits from a {@link Branch} before these commits are applied and submitted.
9
9
  */
10
10
  export declare class BranchCommitEnricher<TChange> {
11
- private transactionEnricher?;
12
- private readonly rebaser;
11
+ private readonly transactionEnricher;
13
12
  private readonly enricher;
14
13
  /**
15
14
  * Maps each local commit to the corresponding enriched commit.
@@ -24,6 +23,9 @@ export declare class BranchCommitEnricher<TChange> {
24
23
  * @returns The number of commits that have been prepared but not yet retrieved.
25
24
  */
26
25
  get preparedCommitsCount(): number;
26
+ startNewTransaction(): void;
27
+ commitCurrentTransaction(): void;
28
+ abortCurrentTransaction(): void;
27
29
  /**
28
30
  * Adds a commit to the enricher.
29
31
  * @param commit - A commit that is part of a transaction.
@@ -1 +1 @@
1
- {"version":3,"file":"branchCommitEnricher.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/branchCommitEnricher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,aAAa,EAAE,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H,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA8D;gBAG7F,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAC/B,QAAQ,EAAE,8BAA8B,CAAC,OAAO,CAAC;IAMlD;;OAEG;IACH,IAAW,oBAAoB,IAAI,MAAM,CAExC;IAEM,mBAAmB,IAAI,IAAI;IAI3B,wBAAwB,IAAI,IAAI;IAIhC,uBAAuB,IAAI,IAAI;IAItC;;;OAGG;IACI,uBAAuB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAMlE;;;;;;;OAOG;IACI,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,EAAE,yBAAyB,EAAE,OAAO,GAAG,IAAI;IAc5F;;;OAGG;IACI,iBAAiB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC;IAO5E;;;;;OAKG;IACI,oBAAoB,IAAI,IAAI;CAGnC"}
@@ -12,20 +12,17 @@ const transactionEnricher_js_1 = require("./transactionEnricher.js");
12
12
  * Utility for enriching commits from a {@link Branch} before these commits are applied and submitted.
13
13
  */
14
14
  class BranchCommitEnricher {
15
- transactionEnricher;
16
- rebaser;
17
- enricher;
18
- /**
19
- * Maps each local commit to the corresponding enriched commit.
20
- * Entries are added when the commits are prepared (before being applied and submitted).
21
- * Entries are removed when the commits are retrieved for submission (after being applied).
22
- * It's possible an entry will linger in the map indefinitely if it is never retrieved for submission.
23
- * This would happen if applying a commit were to fail and the commit were not retrieved/purged after the failure.
24
- */
25
- preparedCommits = new Map();
26
15
  constructor(rebaser, enricher) {
27
- this.rebaser = rebaser;
16
+ /**
17
+ * Maps each local commit to the corresponding enriched commit.
18
+ * Entries are added when the commits are prepared (before being applied and submitted).
19
+ * Entries are removed when the commits are retrieved for submission (after being applied).
20
+ * It's possible an entry will linger in the map indefinitely if it is never retrieved for submission.
21
+ * This would happen if applying a commit were to fail and the commit were not retrieved/purged after the failure.
22
+ */
23
+ this.preparedCommits = new Map();
28
24
  this.enricher = enricher;
25
+ this.transactionEnricher = new transactionEnricher_js_1.TransactionEnricher(rebaser, this.enricher);
29
26
  }
30
27
  /**
31
28
  * @returns The number of commits that have been prepared but not yet retrieved.
@@ -33,6 +30,15 @@ class BranchCommitEnricher {
33
30
  get preparedCommitsCount() {
34
31
  return this.preparedCommits.size;
35
32
  }
33
+ startNewTransaction() {
34
+ this.transactionEnricher.startNewTransaction();
35
+ }
36
+ commitCurrentTransaction() {
37
+ this.transactionEnricher.commitCurrentTransaction();
38
+ }
39
+ abortCurrentTransaction() {
40
+ this.transactionEnricher.abortCurrentTransaction();
41
+ }
36
42
  /**
37
43
  * Adds a commit to the enricher.
38
44
  * @param commit - A commit that is part of a transaction.
@@ -40,8 +46,7 @@ class BranchCommitEnricher {
40
46
  ingestTransactionCommit(commit) {
41
47
  // We do not submit ops for changes that are part of a transaction.
42
48
  // But we need to enrich the commits that will be sent if the transaction is committed.
43
- this.transactionEnricher ??= new transactionEnricher_js_1.TransactionEnricher(this.rebaser, this.enricher);
44
- this.transactionEnricher.addTransactionSteps(commit);
49
+ this.transactionEnricher.addTransactionStep(commit);
45
50
  }
46
51
  /**
47
52
  * Prepares an enriched commit for later submission (see {@link BranchCommitEnricher.getPreparedCommit}).
@@ -56,7 +61,6 @@ class BranchCommitEnricher {
56
61
  if (concludesOuterTransaction) {
57
62
  (0, internal_1.assert)(this.transactionEnricher !== undefined, "Unexpected transaction commit without transaction steps");
58
63
  enrichedChange = this.transactionEnricher.getComposedChange(commit.revision);
59
- delete this.transactionEnricher;
60
64
  }
61
65
  else {
62
66
  enrichedChange = this.enricher.updateChangeEnrichments(commit.change, commit.revision);
@@ -1 +1 @@
1
- {"version":3,"file":"branchCommitEnricher.js","sourceRoot":"","sources":["../../src/shared-tree-core/branchCommitEnricher.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,+CAAuF;AAEvF,qEAA+D;AAE/D;;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;;OAGG;IACI,iBAAiB,CAAC,MAA4B;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAClD,IAAA,iBAAM,EAAC,QAAQ,KAAK,SAAS,EAAE,gBAAgB,CAAC,CAAC;QACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB;QAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACD;AAlFD,oDAkFC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { type ChangeRebaser, type GraphCommit, replaceChange } from \"../core/index.js\";\nimport type { ChangeEnricherReadonlyCheckout } from \"./changeEnricher.js\";\nimport { TransactionEnricher } from \"./transactionEnricher.js\";\n\n/**\n * Utility for enriching commits from a {@link Branch} before these commits are applied and submitted.\n */\nexport class BranchCommitEnricher<TChange> {\n\tprivate transactionEnricher?: TransactionEnricher<TChange>;\n\tprivate readonly rebaser: ChangeRebaser<TChange>;\n\tprivate readonly enricher: ChangeEnricherReadonlyCheckout<TChange>;\n\t/**\n\t * Maps each local commit to the corresponding enriched commit.\n\t * Entries are added when the commits are prepared (before being applied and submitted).\n\t * Entries are removed when the commits are retrieved for submission (after being applied).\n\t * It's possible an entry will linger in the map indefinitely if it is never retrieved for submission.\n\t * This would happen if applying a commit were to fail and the commit were not retrieved/purged after the failure.\n\t */\n\tprivate readonly preparedCommits: Map<GraphCommit<TChange>, GraphCommit<TChange>> = new Map();\n\n\tpublic constructor(\n\t\trebaser: ChangeRebaser<TChange>,\n\t\tenricher: ChangeEnricherReadonlyCheckout<TChange>,\n\t) {\n\t\tthis.rebaser = rebaser;\n\t\tthis.enricher = enricher;\n\t}\n\n\t/**\n\t * @returns The number of commits that have been prepared but not yet retrieved.\n\t */\n\tpublic get preparedCommitsCount(): number {\n\t\treturn this.preparedCommits.size;\n\t}\n\n\t/**\n\t * Adds a commit to the enricher.\n\t * @param commit - A commit that is part of a transaction.\n\t */\n\tpublic ingestTransactionCommit(commit: GraphCommit<TChange>): void {\n\t\t// We do not submit ops for changes that are part of a transaction.\n\t\t// But we need to enrich the commits that will be sent if the transaction is committed.\n\t\tthis.transactionEnricher ??= new TransactionEnricher(this.rebaser, this.enricher);\n\t\tthis.transactionEnricher.addTransactionSteps(commit);\n\t}\n\n\t/**\n\t * Prepares an enriched commit for later submission (see {@link BranchCommitEnricher.getPreparedCommit}).\n\t * @param commit - The commit to prepare an enriched version of.\n\t * @param concludesOuterTransaction - Whether the commit concludes an outer transaction.\n\t *\n\t * Each call to this method must be followed by a call to {@link BranchCommitEnricher.getPreparedCommit} or\n\t * {@link BranchCommitEnricher.purgePreparedCommits}. Failing to do so will result in a memory leak.\n\t */\n\tpublic prepareCommit(commit: GraphCommit<TChange>, concludesOuterTransaction: boolean): void {\n\t\tlet enrichedChange: TChange;\n\t\tif (concludesOuterTransaction) {\n\t\t\tassert(\n\t\t\t\tthis.transactionEnricher !== undefined,\n\t\t\t\t\"Unexpected transaction commit without transaction steps\",\n\t\t\t);\n\t\t\tenrichedChange = this.transactionEnricher.getComposedChange(commit.revision);\n\t\t\tdelete this.transactionEnricher;\n\t\t} else {\n\t\t\tenrichedChange = this.enricher.updateChangeEnrichments(commit.change, commit.revision);\n\t\t}\n\t\tthis.preparedCommits.set(commit, replaceChange(commit, enrichedChange));\n\t}\n\n\t/**\n\t * @param commit - A commit previously passed to {@link BranchCommitEnricher.prepareCommit}.\n\t * @returns The enriched commit corresponds to the given commit.\n\t */\n\tpublic getPreparedCommit(commit: GraphCommit<TChange>): GraphCommit<TChange> {\n\t\tconst prepared = this.preparedCommits.get(commit);\n\t\tassert(prepared !== undefined, \"Unknown commit\");\n\t\tthis.preparedCommits.delete(commit);\n\t\treturn prepared;\n\t}\n\n\t/**\n\t * Purges all commits that have been prepared but not been retrieved.\n\t * This should be called to avoid memory leaks if the prepared commits are no longer needed.\n\t *\n\t * Does not affect ingested transaction commits.\n\t */\n\tpublic purgePreparedCommits(): void {\n\t\tthis.preparedCommits.clear();\n\t}\n}\n"]}
1
+ {"version":3,"file":"branchCommitEnricher.js","sourceRoot":"","sources":["../../src/shared-tree-core/branchCommitEnricher.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAC7D,+CAAuF;AAEvF,qEAA+D;AAE/D;;GAEG;AACH,MAAa,oBAAoB;IAYhC,YACC,OAA+B,EAC/B,QAAiD;QAXlD;;;;;;WAMG;QACc,oBAAe,GAAoD,IAAI,GAAG,EAAE,CAAC;QAM7F,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,mBAAmB,GAAG,IAAI,4CAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5E,CAAC;IAED;;OAEG;IACH,IAAW,oBAAoB;QAC9B,OAAO,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC;IAClC,CAAC;IAEM,mBAAmB;QACzB,IAAI,CAAC,mBAAmB,CAAC,mBAAmB,EAAE,CAAC;IAChD,CAAC;IAEM,wBAAwB;QAC9B,IAAI,CAAC,mBAAmB,CAAC,wBAAwB,EAAE,CAAC;IACrD,CAAC;IAEM,uBAAuB;QAC7B,IAAI,CAAC,mBAAmB,CAAC,uBAAuB,EAAE,CAAC;IACpD,CAAC;IAED;;;OAGG;IACI,uBAAuB,CAAC,MAA4B;QAC1D,mEAAmE;QACnE,uFAAuF;QACvF,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IACrD,CAAC;IAED;;;;;;;OAOG;IACI,aAAa,CAAC,MAA4B,EAAE,yBAAkC;QACpF,IAAI,cAAuB,CAAC;QAC5B,IAAI,yBAAyB,EAAE,CAAC;YAC/B,IAAA,iBAAM,EACL,IAAI,CAAC,mBAAmB,KAAK,SAAS,EACtC,yDAAyD,CACzD,CAAC;YACF,cAAc,GAAG,IAAI,CAAC,mBAAmB,CAAC,iBAAiB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9E,CAAC;aAAM,CAAC;YACP,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QACxF,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,EAAE,IAAA,wBAAa,EAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC;IACzE,CAAC;IAED;;;OAGG;IACI,iBAAiB,CAAC,MAA4B;QACpD,MAAM,QAAQ,GAAG,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QAClD,IAAA,iBAAM,EAAC,QAAQ,KAAK,SAAS,EAAE,gBAAgB,CAAC,CAAC;QACjD,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACpC,OAAO,QAAQ,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACI,oBAAoB;QAC1B,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;CACD;AA3FD,oDA2FC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { type ChangeRebaser, type GraphCommit, replaceChange } from \"../core/index.js\";\nimport type { ChangeEnricherReadonlyCheckout } from \"./changeEnricher.js\";\nimport { TransactionEnricher } from \"./transactionEnricher.js\";\n\n/**\n * Utility for enriching commits from a {@link Branch} before these commits are applied and submitted.\n */\nexport class BranchCommitEnricher<TChange> {\n\tprivate readonly transactionEnricher: TransactionEnricher<TChange>;\n\tprivate readonly enricher: ChangeEnricherReadonlyCheckout<TChange>;\n\t/**\n\t * Maps each local commit to the corresponding enriched commit.\n\t * Entries are added when the commits are prepared (before being applied and submitted).\n\t * Entries are removed when the commits are retrieved for submission (after being applied).\n\t * It's possible an entry will linger in the map indefinitely if it is never retrieved for submission.\n\t * This would happen if applying a commit were to fail and the commit were not retrieved/purged after the failure.\n\t */\n\tprivate readonly preparedCommits: Map<GraphCommit<TChange>, GraphCommit<TChange>> = new Map();\n\n\tpublic constructor(\n\t\trebaser: ChangeRebaser<TChange>,\n\t\tenricher: ChangeEnricherReadonlyCheckout<TChange>,\n\t) {\n\t\tthis.enricher = enricher;\n\t\tthis.transactionEnricher = new TransactionEnricher(rebaser, this.enricher);\n\t}\n\n\t/**\n\t * @returns The number of commits that have been prepared but not yet retrieved.\n\t */\n\tpublic get preparedCommitsCount(): number {\n\t\treturn this.preparedCommits.size;\n\t}\n\n\tpublic startNewTransaction(): void {\n\t\tthis.transactionEnricher.startNewTransaction();\n\t}\n\n\tpublic commitCurrentTransaction(): void {\n\t\tthis.transactionEnricher.commitCurrentTransaction();\n\t}\n\n\tpublic abortCurrentTransaction(): void {\n\t\tthis.transactionEnricher.abortCurrentTransaction();\n\t}\n\n\t/**\n\t * Adds a commit to the enricher.\n\t * @param commit - A commit that is part of a transaction.\n\t */\n\tpublic ingestTransactionCommit(commit: GraphCommit<TChange>): void {\n\t\t// We do not submit ops for changes that are part of a transaction.\n\t\t// But we need to enrich the commits that will be sent if the transaction is committed.\n\t\tthis.transactionEnricher.addTransactionStep(commit);\n\t}\n\n\t/**\n\t * Prepares an enriched commit for later submission (see {@link BranchCommitEnricher.getPreparedCommit}).\n\t * @param commit - The commit to prepare an enriched version of.\n\t * @param concludesOuterTransaction - Whether the commit concludes an outer transaction.\n\t *\n\t * Each call to this method must be followed by a call to {@link BranchCommitEnricher.getPreparedCommit} or\n\t * {@link BranchCommitEnricher.purgePreparedCommits}. Failing to do so will result in a memory leak.\n\t */\n\tpublic prepareCommit(commit: GraphCommit<TChange>, concludesOuterTransaction: boolean): void {\n\t\tlet enrichedChange: TChange;\n\t\tif (concludesOuterTransaction) {\n\t\t\tassert(\n\t\t\t\tthis.transactionEnricher !== undefined,\n\t\t\t\t\"Unexpected transaction commit without transaction steps\",\n\t\t\t);\n\t\t\tenrichedChange = this.transactionEnricher.getComposedChange(commit.revision);\n\t\t} else {\n\t\t\tenrichedChange = this.enricher.updateChangeEnrichments(commit.change, commit.revision);\n\t\t}\n\t\tthis.preparedCommits.set(commit, replaceChange(commit, enrichedChange));\n\t}\n\n\t/**\n\t * @param commit - A commit previously passed to {@link BranchCommitEnricher.prepareCommit}.\n\t * @returns The enriched commit corresponds to the given commit.\n\t */\n\tpublic getPreparedCommit(commit: GraphCommit<TChange>): GraphCommit<TChange> {\n\t\tconst prepared = this.preparedCommits.get(commit);\n\t\tassert(prepared !== undefined, \"Unknown commit\");\n\t\tthis.preparedCommits.delete(commit);\n\t\treturn prepared;\n\t}\n\n\t/**\n\t * Purges all commits that have been prepared but not been retrieved.\n\t * This should be called to avoid memory leaks if the prepared commits are no longer needed.\n\t *\n\t * Does not affect ingested transaction commits.\n\t */\n\tpublic purgePreparedCommits(): void {\n\t\tthis.preparedCommits.clear();\n\t}\n}\n"]}
@@ -11,27 +11,6 @@ const index_js_1 = require("../util/index.js");
11
11
  * Default implementation of {@link ResubmitMachine}.
12
12
  */
13
13
  class DefaultResubmitMachine {
14
- inverter;
15
- tip;
16
- /**
17
- * The list of commits (from oldest to most recent) that have been submitted but not sequenced.
18
- */
19
- inFlightQueue = [];
20
- /**
21
- * The list of commits (from oldest to most recent) that should be resubmitted.
22
- */
23
- resubmitQueue = [];
24
- /**
25
- * Represents the index in the `inFlightQueue` array of the most recent in flight commit that has
26
- * undergone rebasing but whose enrichments have not been updated.
27
- * All in-flight commits with an index inferior or equal to this number have stale enrichments.
28
- *
29
- * Is -1 when *any* of the following is true:
30
- * - There are no in-flight commits (i.e., no local commits have been made or they have all been sequenced)
31
- * - None of the in-flight commits have been rebased
32
- * - In-flight commits that have been rebased have all had their enrichments updated
33
- */
34
- latestInFlightCommitWithStaleEnrichments = -1;
35
14
  constructor(
36
15
  /**
37
16
  * A function that can invert a change.
@@ -44,6 +23,25 @@ class DefaultResubmitMachine {
44
23
  tip) {
45
24
  this.inverter = inverter;
46
25
  this.tip = tip;
26
+ /**
27
+ * The list of commits (from oldest to most recent) that have been submitted but not sequenced.
28
+ */
29
+ this.inFlightQueue = [];
30
+ /**
31
+ * The list of commits (from oldest to most recent) that should be resubmitted.
32
+ */
33
+ this.resubmitQueue = [];
34
+ /**
35
+ * Represents the index in the `inFlightQueue` array of the most recent in flight commit that has
36
+ * undergone rebasing but whose enrichments have not been updated.
37
+ * All in-flight commits with an index inferior or equal to this number have stale enrichments.
38
+ *
39
+ * Is -1 when *any* of the following is true:
40
+ * - There are no in-flight commits (i.e., no local commits have been made or they have all been sequenced)
41
+ * - None of the in-flight commits have been rebased
42
+ * - In-flight commits that have been rebased have all had their enrichments updated
43
+ */
44
+ this.latestInFlightCommitWithStaleEnrichments = -1;
47
45
  }
48
46
  onCommitSubmitted(commit) {
49
47
  if (this.isInResubmitPhase) {
@@ -1 +1 @@
1
- {"version":3,"file":"defaultResubmitMachine.js","sourceRoot":"","sources":["../../src/shared-tree-core/defaultResubmitMachine.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAE7D,+CAAiD;AAGjD;;GAEG;AACH,MAAa,sBAAsB;IA2BhB;IAKA;IA/BlB;;OAEG;IACK,aAAa,GAA2B,EAAE,CAAC;IAEnD;;OAEG;IACK,aAAa,GAA2B,EAAE,CAAC;IAEnD;;;;;;;;;OASG;IACK,wCAAwC,GAAW,CAAC,CAAC,CAAC;IAE9D;IACC;;OAEG;IACc,QAA0C;IAC3D;;;OAGG;IACc,GAA4C;QAL5C,aAAQ,GAAR,QAAQ,CAAkC;QAK1C,QAAG,GAAH,GAAG,CAAyC;IAC3D,CAAC;IAEG,iBAAiB,CAAC,MAA4B;QACpD,IAAI,IAAI,CAAC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C,EAAE,KAAK,CAAC,wCAAwC,CAAC,CAAC;YACtF,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,wCAAwC,IAAI,CAAC,EAAE,CAAC;gBACxD,IAAI,CAAC,wCAAwC,IAAI,CAAC,CAAC;YACpD,CAAC;QACF,CAAC;aAAM,CAAC;YACP,mCAAmC;YACnC,IAAI,CAAC,wCAAwC,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC/E,CAAC;IACF,CAAC;CACD;AArHD,wDAqHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ChangeRebaser, GraphCommit } from \"../core/index.js\";\nimport { disposeSymbol } from \"../util/index.js\";\nimport type { ChangeEnricherReadonlyCheckout, ResubmitMachine } from \"./index.js\";\n\n/**\n * Default implementation of {@link ResubmitMachine}.\n */\nexport class DefaultResubmitMachine<TChange> implements ResubmitMachine<TChange> {\n\t/**\n\t * The list of commits (from oldest to most recent) that have been submitted but not sequenced.\n\t */\n\tprivate inFlightQueue: GraphCommit<TChange>[] = [];\n\n\t/**\n\t * The list of commits (from oldest to most recent) that should be resubmitted.\n\t */\n\tprivate resubmitQueue: GraphCommit<TChange>[] = [];\n\n\t/**\n\t * Represents the index in the `inFlightQueue` array of the most recent in flight commit that has\n\t * undergone rebasing but whose enrichments have not been updated.\n\t * All in-flight commits with an index inferior or equal to this number have stale enrichments.\n\t *\n\t * Is -1 when *any* of the following is true:\n\t * - There are no in-flight commits (i.e., no local commits have been made or they have all been sequenced)\n\t * - None of the in-flight commits have been rebased\n\t * - In-flight commits that have been rebased have all had their enrichments updated\n\t */\n\tprivate latestInFlightCommitWithStaleEnrichments: number = -1;\n\n\tpublic constructor(\n\t\t/**\n\t\t * A function that can invert a change.\n\t\t */\n\t\tprivate readonly inverter: ChangeRebaser<TChange>[\"invert\"],\n\t\t/**\n\t\t * Change enricher that represent the tip of the top-level local branch (i.e., the branch on which in-flight\n\t\t * commits are applied and automatically rebased).\n\t\t */\n\t\tprivate readonly tip: ChangeEnricherReadonlyCheckout<TChange>,\n\t) {}\n\n\tpublic onCommitSubmitted(commit: GraphCommit<TChange>): void {\n\t\tif (this.isInResubmitPhase) {\n\t\t\tconst toResubmit = this.resubmitQueue.shift();\n\t\t\tassert(toResubmit === commit, \"Unexpected commit submitted during resubmit phase\");\n\t\t}\n\t\tthis.inFlightQueue.push(commit);\n\t}\n\n\tpublic prepareForResubmit(toResubmit: readonly GraphCommit<TChange>[]): void {\n\t\tassert(\n\t\t\t!this.isInResubmitPhase,\n\t\t\t0x957 /* Invalid resubmit phase start during incomplete resubmit phase */,\n\t\t);\n\t\tassert(\n\t\t\ttoResubmit.length === this.inFlightQueue.length,\n\t\t\t0x958 /* Unexpected resubmit of more or fewer commits than are in flight */,\n\t\t);\n\t\tif (this.latestInFlightCommitWithStaleEnrichments === -1) {\n\t\t\t// No in-flight commits have stale enrichments, so we can resubmit them as is\n\t\t\tthis.resubmitQueue = this.inFlightQueue;\n\t\t\tthis.inFlightQueue = [];\n\t\t} else {\n\t\t\tconst checkout = this.tip.fork();\n\t\t\t// Roll back the checkout to the state before the oldest commit\n\t\t\tfor (let iCommit = toResubmit.length - 1; iCommit >= 0; iCommit -= 1) {\n\t\t\t\tconst commit = toResubmit[iCommit];\n\t\t\t\tconst rollback = this.inverter(commit, true);\n\t\t\t\t// WARNING: it's not currently possible to roll back past a schema change (see AB#7265).\n\t\t\t\t// Either we have to make it possible to do so, or this logic will have to change to work\n\t\t\t\t// forwards from an earlier fork instead of backwards.\n\t\t\t\tcheckout.applyTipChange(rollback);\n\t\t\t}\n\t\t\t// Update the enrichments of the stale commits\n\t\t\tfor (\n\t\t\t\tlet iCommit = 0;\n\t\t\t\tiCommit <= this.latestInFlightCommitWithStaleEnrichments;\n\t\t\t\tiCommit += 1\n\t\t\t) {\n\t\t\t\tconst commit = toResubmit[iCommit];\n\t\t\t\tconst enrichedChange = checkout.updateChangeEnrichments(\n\t\t\t\t\tcommit.change,\n\t\t\t\t\tcommit.revision,\n\t\t\t\t);\n\t\t\t\tconst enrichedCommit = { ...commit, change: enrichedChange };\n\t\t\t\tthis.resubmitQueue.push(enrichedCommit);\n\t\t\t\tif (iCommit < this.latestInFlightCommitWithStaleEnrichments) {\n\t\t\t\t\tcheckout.applyTipChange(enrichedChange, commit.revision);\n\t\t\t\t}\n\t\t\t\tthis.inFlightQueue.shift();\n\t\t\t}\n\t\t\tcheckout[disposeSymbol]();\n\t\t\t// Whatever commits are left do not have stale enrichments\n\t\t\tfor (const commit of this.inFlightQueue) {\n\t\t\t\tthis.resubmitQueue.push(commit);\n\t\t\t}\n\t\t\tthis.inFlightQueue.length = 0;\n\t\t}\n\t\tthis.latestInFlightCommitWithStaleEnrichments = -1;\n\t}\n\n\tpublic peekNextCommit(): GraphCommit<TChange> {\n\t\tassert(this.isInResubmitPhase, \"No available commit to resubmit outside of resubmit phase\");\n\t\treturn this.resubmitQueue[0];\n\t}\n\n\tpublic get isInResubmitPhase(): boolean {\n\t\treturn this.resubmitQueue.length !== 0;\n\t}\n\n\tpublic onSequencedCommitApplied(isLocal: boolean): void {\n\t\tif (isLocal) {\n\t\t\t// The oldest in-flight commit has been sequenced\n\t\t\tassert(this.inFlightQueue.length > 0, 0x959 /* Sequencing of unknown local commit */);\n\t\t\tthis.inFlightQueue.shift();\n\t\t\tif (this.latestInFlightCommitWithStaleEnrichments >= 0) {\n\t\t\t\tthis.latestInFlightCommitWithStaleEnrichments -= 1;\n\t\t\t}\n\t\t} else {\n\t\t\t// A peer commit has been sequenced\n\t\t\tthis.latestInFlightCommitWithStaleEnrichments = this.inFlightQueue.length - 1;\n\t\t}\n\t}\n}\n"]}
1
+ {"version":3,"file":"defaultResubmitMachine.js","sourceRoot":"","sources":["../../src/shared-tree-core/defaultResubmitMachine.ts"],"names":[],"mappings":";AAAA;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AAG,CAAC,CAAC,CAAC;IACpD,CAAC;IAEM,cAAc;QACpB,IAAA,iBAAM,EAAC,IAAI,CAAC,iBAAiB,EAAE,2DAA2D,CAAC,CAAC;QAC5F,OAAO,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC;IAC9B,CAAC;IAED,IAAW,iBAAiB;QAC3B,OAAO,IAAI,CAAC,aAAa,CAAC,MAAM,KAAK,CAAC,CAAC;IACxC,CAAC;IAEM,wBAAwB,CAAC,OAAgB;QAC/C,IAAI,OAAO,EAAE,CAAC;YACb,iDAAiD;YACjD,IAAA,iBAAM,EAAC,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,KAAK,CAAC,wCAAwC,CAAC,CAAC;YACtF,IAAI,CAAC,aAAa,CAAC,KAAK,EAAE,CAAC;YAC3B,IAAI,IAAI,CAAC,wCAAwC,IAAI,CAAC,EAAE,CAAC;gBACxD,IAAI,CAAC,wCAAwC,IAAI,CAAC,CAAC;YACpD,CAAC;QACF,CAAC;aAAM,CAAC;YACP,mCAAmC;YACnC,IAAI,CAAC,wCAAwC,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;QAC/E,CAAC;IACF,CAAC;CACD;AArHD,wDAqHC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type { ChangeRebaser, GraphCommit } from \"../core/index.js\";\nimport { disposeSymbol } from \"../util/index.js\";\nimport type { ChangeEnricherReadonlyCheckout, ResubmitMachine } from \"./index.js\";\n\n/**\n * Default implementation of {@link ResubmitMachine}.\n */\nexport class DefaultResubmitMachine<TChange> implements ResubmitMachine<TChange> {\n\t/**\n\t * The list of commits (from oldest to most recent) that have been submitted but not sequenced.\n\t */\n\tprivate inFlightQueue: GraphCommit<TChange>[] = [];\n\n\t/**\n\t * The list of commits (from oldest to most recent) that should be resubmitted.\n\t */\n\tprivate resubmitQueue: GraphCommit<TChange>[] = [];\n\n\t/**\n\t * Represents the index in the `inFlightQueue` array of the most recent in flight commit that has\n\t * undergone rebasing but whose enrichments have not been updated.\n\t * All in-flight commits with an index inferior or equal to this number have stale enrichments.\n\t *\n\t * Is -1 when *any* of the following is true:\n\t * - There are no in-flight commits (i.e., no local commits have been made or they have all been sequenced)\n\t * - None of the in-flight commits have been rebased\n\t * - In-flight commits that have been rebased have all had their enrichments updated\n\t */\n\tprivate latestInFlightCommitWithStaleEnrichments: number = -1;\n\n\tpublic constructor(\n\t\t/**\n\t\t * A function that can invert a change.\n\t\t */\n\t\tprivate readonly inverter: ChangeRebaser<TChange>[\"invert\"],\n\t\t/**\n\t\t * Change enricher that represent the tip of the top-level local branch (i.e., the branch on which in-flight\n\t\t * commits are applied and automatically rebased).\n\t\t */\n\t\tprivate readonly tip: ChangeEnricherReadonlyCheckout<TChange>,\n\t) {}\n\n\tpublic onCommitSubmitted(commit: GraphCommit<TChange>): void {\n\t\tif (this.isInResubmitPhase) {\n\t\t\tconst toResubmit = this.resubmitQueue.shift();\n\t\t\tassert(toResubmit === commit, \"Unexpected commit submitted during resubmit phase\");\n\t\t}\n\t\tthis.inFlightQueue.push(commit);\n\t}\n\n\tpublic prepareForResubmit(toResubmit: readonly GraphCommit<TChange>[]): void {\n\t\tassert(\n\t\t\t!this.isInResubmitPhase,\n\t\t\t0x957 /* Invalid resubmit phase start during incomplete resubmit phase */,\n\t\t);\n\t\tassert(\n\t\t\ttoResubmit.length === this.inFlightQueue.length,\n\t\t\t0x958 /* Unexpected resubmit of more or fewer commits than are in flight */,\n\t\t);\n\t\tif (this.latestInFlightCommitWithStaleEnrichments === -1) {\n\t\t\t// No in-flight commits have stale enrichments, so we can resubmit them as is\n\t\t\tthis.resubmitQueue = this.inFlightQueue;\n\t\t\tthis.inFlightQueue = [];\n\t\t} else {\n\t\t\tconst checkout = this.tip.fork();\n\t\t\t// Roll back the checkout to the state before the oldest commit\n\t\t\tfor (let iCommit = toResubmit.length - 1; iCommit >= 0; iCommit -= 1) {\n\t\t\t\tconst commit = toResubmit[iCommit];\n\t\t\t\tconst rollback = this.inverter(commit, true);\n\t\t\t\t// WARNING: it's not currently possible to roll back past a schema change (see AB#7265).\n\t\t\t\t// Either we have to make it possible to do so, or this logic will have to change to work\n\t\t\t\t// forwards from an earlier fork instead of backwards.\n\t\t\t\tcheckout.applyTipChange(rollback);\n\t\t\t}\n\t\t\t// Update the enrichments of the stale commits\n\t\t\tfor (\n\t\t\t\tlet iCommit = 0;\n\t\t\t\tiCommit <= this.latestInFlightCommitWithStaleEnrichments;\n\t\t\t\tiCommit += 1\n\t\t\t) {\n\t\t\t\tconst commit = toResubmit[iCommit];\n\t\t\t\tconst enrichedChange = checkout.updateChangeEnrichments(\n\t\t\t\t\tcommit.change,\n\t\t\t\t\tcommit.revision,\n\t\t\t\t);\n\t\t\t\tconst enrichedCommit = { ...commit, change: enrichedChange };\n\t\t\t\tthis.resubmitQueue.push(enrichedCommit);\n\t\t\t\tif (iCommit < this.latestInFlightCommitWithStaleEnrichments) {\n\t\t\t\t\tcheckout.applyTipChange(enrichedChange, commit.revision);\n\t\t\t\t}\n\t\t\t\tthis.inFlightQueue.shift();\n\t\t\t}\n\t\t\tcheckout[disposeSymbol]();\n\t\t\t// Whatever commits are left do not have stale enrichments\n\t\t\tfor (const commit of this.inFlightQueue) {\n\t\t\t\tthis.resubmitQueue.push(commit);\n\t\t\t}\n\t\t\tthis.inFlightQueue.length = 0;\n\t\t}\n\t\tthis.latestInFlightCommitWithStaleEnrichments = -1;\n\t}\n\n\tpublic peekNextCommit(): GraphCommit<TChange> {\n\t\tassert(this.isInResubmitPhase, \"No available commit to resubmit outside of resubmit phase\");\n\t\treturn this.resubmitQueue[0];\n\t}\n\n\tpublic get isInResubmitPhase(): boolean {\n\t\treturn this.resubmitQueue.length !== 0;\n\t}\n\n\tpublic onSequencedCommitApplied(isLocal: boolean): void {\n\t\tif (isLocal) {\n\t\t\t// The oldest in-flight commit has been sequenced\n\t\t\tassert(this.inFlightQueue.length > 0, 0x959 /* Sequencing of unknown local commit */);\n\t\t\tthis.inFlightQueue.shift();\n\t\t\tif (this.latestInFlightCommitWithStaleEnrichments >= 0) {\n\t\t\t\tthis.latestInFlightCommitWithStaleEnrichments -= 1;\n\t\t\t}\n\t\t} else {\n\t\t\t// A peer commit has been sequenced\n\t\t\tthis.latestInFlightCommitWithStaleEnrichments = this.inFlightQueue.length - 1;\n\t\t}\n\t}\n}\n"]}
@@ -22,59 +22,6 @@ const minimumPossibleSequenceId = {
22
22
  */
23
23
  // TODO: Try to reduce this to a single type parameter
24
24
  class EditManager {
25
- changeFamily;
26
- localSessionId;
27
- mintRevisionTag;
28
- _events = (0, index_js_3.createEmitter)();
29
- /** The "trunk" branch. The trunk represents the list of received sequenced changes. */
30
- trunk;
31
- /**
32
- * Records extra data associated with commits in the {@link trunk}.
33
- * This does not include an entry for the {@link trunkBase}.
34
- */
35
- trunkMetadata = new Map();
36
- /**
37
- * A map from a sequence id to the commit in the {@link trunk} which has that sequence id.
38
- * This also includes an entry for the {@link trunkBase} which always has the lowest key in the map.
39
- */
40
- sequenceMap = new sorted_btree_es6_1.BTree(undefined, sequenceIdUtils_js_1.sequenceIdComparator);
41
- /**
42
- * Branches are maintained to represent the local change list that the issuing client had
43
- * at the time of submitting the latest known edit on the branch.
44
- * This means the head commit of each branch is always in its original (non-rebased) form.
45
- */
46
- peerLocalBranches = new Map();
47
- /**
48
- * This branch holds the changes made by this client which have not yet been confirmed as sequenced changes.
49
- */
50
- localBranch;
51
- /**
52
- * Tracks where on the trunk all registered branches are based. Each key is the sequence id of a commit on
53
- * the trunk, and the value is the set of all branches who have that commit as their common ancestor with the trunk.
54
- *
55
- * @remarks
56
- * This does not include the local branch.
57
- */
58
- trunkBranches = new sorted_btree_es6_1.BTree(undefined, sequenceIdUtils_js_1.sequenceIdComparator);
59
- /**
60
- * The sequence number of the newest commit on the trunk that has been received by all peers.
61
- * Defaults to {@link minimumPossibleSequenceNumber} if no commits have been received.
62
- *
63
- * @remarks If there are more than one commit with the same sequence number we assume this refers to the last commit in the batch.
64
- */
65
- minimumSequenceNumber = exports.minimumPossibleSequenceNumber;
66
- /**
67
- * A special commit that is a "base" (tail) of the trunk, though not part of the trunk itself.
68
- * This makes it possible to model the trunk in the same way as any other branch (it branches off of a base commit)
69
- * which allows it to use branching APIs to interact with the other branches.
70
- * Each time trunk eviction occurs, the most recent evicted commit becomes the new `trunkBase`.
71
- */
72
- trunkBase;
73
- /**
74
- * The list of commits (from oldest to most recent) that are on the local branch but not on the trunk.
75
- * When a local commit is sequenced, the first commit in this list shifted onto the tip of the trunk.
76
- */
77
- localCommits = [];
78
25
  /**
79
26
  * @param changeFamily - the change family of changes on the trunk and local branch
80
27
  * @param localSessionId - the id of the local session that will be used for local commits
@@ -83,6 +30,43 @@ class EditManager {
83
30
  this.changeFamily = changeFamily;
84
31
  this.localSessionId = localSessionId;
85
32
  this.mintRevisionTag = mintRevisionTag;
33
+ this._events = (0, index_js_3.createEmitter)();
34
+ /**
35
+ * Records extra data associated with commits in the {@link trunk}.
36
+ * This does not include an entry for the {@link trunkBase}.
37
+ */
38
+ this.trunkMetadata = new Map();
39
+ /**
40
+ * A map from a sequence id to the commit in the {@link trunk} which has that sequence id.
41
+ * This also includes an entry for the {@link trunkBase} which always has the lowest key in the map.
42
+ */
43
+ this.sequenceMap = new sorted_btree_es6_1.BTree(undefined, sequenceIdUtils_js_1.sequenceIdComparator);
44
+ /**
45
+ * Branches are maintained to represent the local change list that the issuing client had
46
+ * at the time of submitting the latest known edit on the branch.
47
+ * This means the head commit of each branch is always in its original (non-rebased) form.
48
+ */
49
+ this.peerLocalBranches = new Map();
50
+ /**
51
+ * Tracks where on the trunk all registered branches are based. Each key is the sequence id of a commit on
52
+ * the trunk, and the value is the set of all branches who have that commit as their common ancestor with the trunk.
53
+ *
54
+ * @remarks
55
+ * This does not include the local branch.
56
+ */
57
+ this.trunkBranches = new sorted_btree_es6_1.BTree(undefined, sequenceIdUtils_js_1.sequenceIdComparator);
58
+ /**
59
+ * The sequence number of the newest commit on the trunk that has been received by all peers.
60
+ * Defaults to {@link minimumPossibleSequenceNumber} if no commits have been received.
61
+ *
62
+ * @remarks If there are more than one commit with the same sequence number we assume this refers to the last commit in the batch.
63
+ */
64
+ this.minimumSequenceNumber = exports.minimumPossibleSequenceNumber;
65
+ /**
66
+ * The list of commits (from oldest to most recent) that are on the local branch but not on the trunk.
67
+ * When a local commit is sequenced, the first commit in this list shifted onto the tip of the trunk.
68
+ */
69
+ this.localCommits = [];
86
70
  this.trunkBase = {
87
71
  revision: "root",
88
72
  change: changeFamily.rebaser.compose([]),