@fluidframework/tree 2.10.0 → 2.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (465) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/api-report/tree.alpha.api.md +47 -16
  3. package/api-report/tree.beta.api.md +5 -14
  4. package/api-report/tree.legacy.alpha.api.md +5 -14
  5. package/api-report/tree.legacy.public.api.md +5 -14
  6. package/api-report/tree.public.api.md +5 -14
  7. package/dist/alpha.d.ts +9 -0
  8. package/dist/core/forest/forest.d.ts +10 -2
  9. package/dist/core/forest/forest.d.ts.map +1 -1
  10. package/dist/core/forest/forest.js.map +1 -1
  11. package/dist/core/index.d.ts +2 -2
  12. package/dist/core/index.d.ts.map +1 -1
  13. package/dist/core/index.js +3 -2
  14. package/dist/core/index.js.map +1 -1
  15. package/dist/core/rebase/utils.d.ts +1 -1
  16. package/dist/core/rebase/utils.d.ts.map +1 -1
  17. package/dist/core/rebase/utils.js +11 -8
  18. package/dist/core/rebase/utils.js.map +1 -1
  19. package/dist/core/revertible.d.ts +30 -1
  20. package/dist/core/revertible.d.ts.map +1 -1
  21. package/dist/core/revertible.js.map +1 -1
  22. package/dist/core/schema-stored/storedSchemaRepository.d.ts +2 -2
  23. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  24. package/dist/core/schema-stored/storedSchemaRepository.js +5 -5
  25. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  26. package/dist/core/tree/anchorSet.d.ts +2 -2
  27. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  28. package/dist/core/tree/anchorSet.js +21 -21
  29. package/dist/core/tree/anchorSet.js.map +1 -1
  30. package/dist/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  31. package/dist/core/tree/detachedFieldIndexCodec.js +3 -2
  32. package/dist/core/tree/detachedFieldIndexCodec.js.map +1 -1
  33. package/dist/core/tree/index.d.ts +1 -1
  34. package/dist/core/tree/index.d.ts.map +1 -1
  35. package/dist/core/tree/index.js +2 -1
  36. package/dist/core/tree/index.js.map +1 -1
  37. package/dist/core/tree/visitorUtils.d.ts +25 -1
  38. package/dist/core/tree/visitorUtils.d.ts.map +1 -1
  39. package/dist/core/tree/visitorUtils.js +29 -1
  40. package/dist/core/tree/visitorUtils.js.map +1 -1
  41. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts +5 -2
  42. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  43. package/dist/feature-libraries/chunked-forest/chunkedForest.js +24 -14
  44. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  45. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  46. package/dist/feature-libraries/chunked-forest/uniformChunk.js +2 -2
  47. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  48. package/dist/feature-libraries/flex-tree/context.d.ts +1 -1
  49. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  50. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  51. package/dist/feature-libraries/index.d.ts +1 -0
  52. package/dist/feature-libraries/index.d.ts.map +1 -1
  53. package/dist/feature-libraries/index.js +4 -1
  54. package/dist/feature-libraries/index.js.map +1 -1
  55. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts +132 -0
  56. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -0
  57. package/dist/feature-libraries/indexing/anchorTreeIndex.js +361 -0
  58. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -0
  59. package/dist/feature-libraries/indexing/index.d.ts +7 -0
  60. package/dist/feature-libraries/indexing/index.d.ts.map +1 -0
  61. package/dist/feature-libraries/indexing/index.js +11 -0
  62. package/dist/feature-libraries/indexing/index.js.map +1 -0
  63. package/dist/feature-libraries/indexing/types.d.ts +32 -0
  64. package/dist/feature-libraries/indexing/types.d.ts.map +1 -0
  65. package/dist/{events/interop.js → feature-libraries/indexing/types.js} +1 -1
  66. package/dist/feature-libraries/indexing/types.js.map +1 -0
  67. package/dist/feature-libraries/object-forest/objectForest.d.ts +5 -2
  68. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  69. package/dist/feature-libraries/object-forest/objectForest.js +21 -11
  70. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  71. package/dist/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  72. package/dist/feature-libraries/sequence-field/invert.js +2 -2
  73. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  74. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +3 -2
  75. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  76. package/dist/index.d.ts +4 -4
  77. package/dist/index.d.ts.map +1 -1
  78. package/dist/index.js +4 -1
  79. package/dist/index.js.map +1 -1
  80. package/dist/packageVersion.d.ts +1 -1
  81. package/dist/packageVersion.js +1 -1
  82. package/dist/packageVersion.js.map +1 -1
  83. package/dist/shared-tree/index.d.ts +1 -1
  84. package/dist/shared-tree/index.d.ts.map +1 -1
  85. package/dist/shared-tree/index.js +1 -2
  86. package/dist/shared-tree/index.js.map +1 -1
  87. package/dist/shared-tree/schematizingTreeView.d.ts +7 -1
  88. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  89. package/dist/shared-tree/schematizingTreeView.js +31 -30
  90. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  91. package/dist/shared-tree/sharedTree.d.ts +3 -0
  92. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  93. package/dist/shared-tree/sharedTree.js +56 -20
  94. package/dist/shared-tree/sharedTree.js.map +1 -1
  95. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  96. package/dist/shared-tree/sharedTreeChangeFamily.js +3 -3
  97. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  98. package/dist/shared-tree/treeCheckout.d.ts +28 -64
  99. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  100. package/dist/shared-tree/treeCheckout.js +152 -129
  101. package/dist/shared-tree/treeCheckout.js.map +1 -1
  102. package/dist/shared-tree-core/branch.d.ts +25 -81
  103. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  104. package/dist/shared-tree-core/branch.js +72 -151
  105. package/dist/shared-tree-core/branch.js.map +1 -1
  106. package/dist/shared-tree-core/branchCommitEnricher.d.ts +19 -33
  107. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  108. package/dist/shared-tree-core/branchCommitEnricher.js +73 -54
  109. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  110. package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  111. package/dist/shared-tree-core/defaultResubmitMachine.js +2 -1
  112. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  113. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  114. package/dist/shared-tree-core/editManager.js +2 -2
  115. package/dist/shared-tree-core/editManager.js.map +1 -1
  116. package/dist/shared-tree-core/index.d.ts +1 -1
  117. package/dist/shared-tree-core/index.d.ts.map +1 -1
  118. package/dist/shared-tree-core/index.js +4 -3
  119. package/dist/shared-tree-core/index.js.map +1 -1
  120. package/dist/shared-tree-core/sharedTreeCore.d.ts +2 -2
  121. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  122. package/dist/shared-tree-core/sharedTreeCore.js +11 -52
  123. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  124. package/dist/shared-tree-core/transaction.d.ts +108 -0
  125. package/dist/shared-tree-core/transaction.d.ts.map +1 -0
  126. package/dist/shared-tree-core/transaction.js +99 -0
  127. package/dist/shared-tree-core/transaction.js.map +1 -0
  128. package/dist/shared-tree-core/transactionEnricher.d.ts +8 -13
  129. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  130. package/dist/shared-tree-core/transactionEnricher.js +41 -21
  131. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  132. package/dist/simple-tree/api/identifierIndex.d.ts +21 -0
  133. package/dist/simple-tree/api/identifierIndex.d.ts.map +1 -0
  134. package/dist/simple-tree/api/identifierIndex.js +45 -0
  135. package/dist/simple-tree/api/identifierIndex.js.map +1 -0
  136. package/dist/simple-tree/api/index.d.ts +2 -0
  137. package/dist/simple-tree/api/index.d.ts.map +1 -1
  138. package/dist/simple-tree/api/index.js +5 -1
  139. package/dist/simple-tree/api/index.js.map +1 -1
  140. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +9 -7
  141. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  142. package/dist/simple-tree/api/simpleTreeIndex.d.ts +65 -0
  143. package/dist/simple-tree/api/simpleTreeIndex.d.ts.map +1 -0
  144. package/dist/simple-tree/api/simpleTreeIndex.js +91 -0
  145. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -0
  146. package/dist/simple-tree/api/tree.d.ts +4 -5
  147. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  148. package/dist/simple-tree/api/tree.js.map +1 -1
  149. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  150. package/dist/simple-tree/core/index.d.ts +1 -1
  151. package/dist/simple-tree/core/index.d.ts.map +1 -1
  152. package/dist/simple-tree/core/index.js +2 -1
  153. package/dist/simple-tree/core/index.js.map +1 -1
  154. package/dist/simple-tree/core/treeNodeKernel.d.ts +6 -2
  155. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  156. package/dist/simple-tree/core/treeNodeKernel.js +53 -22
  157. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  158. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
  159. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  160. package/dist/simple-tree/core/unhydratedFlexTree.js +2 -2
  161. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  162. package/dist/simple-tree/index.d.ts +1 -1
  163. package/dist/simple-tree/index.d.ts.map +1 -1
  164. package/dist/simple-tree/index.js +4 -2
  165. package/dist/simple-tree/index.js.map +1 -1
  166. package/dist/simple-tree/objectNode.d.ts +7 -2
  167. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  168. package/dist/simple-tree/objectNode.js.map +1 -1
  169. package/dist/simple-tree/toMapTree.js +3 -3
  170. package/dist/simple-tree/toMapTree.js.map +1 -1
  171. package/dist/util/index.d.ts +1 -2
  172. package/dist/util/index.d.ts.map +1 -1
  173. package/dist/util/index.js +5 -4
  174. package/dist/util/index.js.map +1 -1
  175. package/dist/util/typeCheck.d.ts +6 -1
  176. package/dist/util/typeCheck.d.ts.map +1 -1
  177. package/dist/util/typeCheck.js.map +1 -1
  178. package/dist/util/typeCheckTests.d.ts +14 -2
  179. package/dist/util/typeCheckTests.d.ts.map +1 -1
  180. package/dist/util/typeCheckTests.js.map +1 -1
  181. package/dist/util/utils.d.ts +29 -0
  182. package/dist/util/utils.d.ts.map +1 -1
  183. package/dist/util/utils.js +13 -1
  184. package/dist/util/utils.js.map +1 -1
  185. package/lib/alpha.d.ts +9 -0
  186. package/lib/core/forest/forest.d.ts +10 -2
  187. package/lib/core/forest/forest.d.ts.map +1 -1
  188. package/lib/core/forest/forest.js.map +1 -1
  189. package/lib/core/index.d.ts +2 -2
  190. package/lib/core/index.d.ts.map +1 -1
  191. package/lib/core/index.js +2 -2
  192. package/lib/core/index.js.map +1 -1
  193. package/lib/core/rebase/utils.d.ts +1 -1
  194. package/lib/core/rebase/utils.d.ts.map +1 -1
  195. package/lib/core/rebase/utils.js +11 -8
  196. package/lib/core/rebase/utils.js.map +1 -1
  197. package/lib/core/revertible.d.ts +30 -1
  198. package/lib/core/revertible.d.ts.map +1 -1
  199. package/lib/core/revertible.js.map +1 -1
  200. package/lib/core/schema-stored/storedSchemaRepository.d.ts +2 -2
  201. package/lib/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  202. package/lib/core/schema-stored/storedSchemaRepository.js +1 -1
  203. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  204. package/lib/core/tree/anchorSet.d.ts +2 -2
  205. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  206. package/lib/core/tree/anchorSet.js +1 -1
  207. package/lib/core/tree/anchorSet.js.map +1 -1
  208. package/lib/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  209. package/lib/core/tree/detachedFieldIndexCodec.js +4 -3
  210. package/lib/core/tree/detachedFieldIndexCodec.js.map +1 -1
  211. package/lib/core/tree/index.d.ts +1 -1
  212. package/lib/core/tree/index.d.ts.map +1 -1
  213. package/lib/core/tree/index.js +1 -1
  214. package/lib/core/tree/index.js.map +1 -1
  215. package/lib/core/tree/visitorUtils.d.ts +25 -1
  216. package/lib/core/tree/visitorUtils.d.ts.map +1 -1
  217. package/lib/core/tree/visitorUtils.js +27 -0
  218. package/lib/core/tree/visitorUtils.js.map +1 -1
  219. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts +5 -2
  220. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  221. package/lib/feature-libraries/chunked-forest/chunkedForest.js +18 -8
  222. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  223. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  224. package/lib/feature-libraries/chunked-forest/uniformChunk.js +3 -3
  225. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  226. package/lib/feature-libraries/flex-tree/context.d.ts +1 -1
  227. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  228. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  229. package/lib/feature-libraries/index.d.ts +1 -0
  230. package/lib/feature-libraries/index.d.ts.map +1 -1
  231. package/lib/feature-libraries/index.js +1 -0
  232. package/lib/feature-libraries/index.js.map +1 -1
  233. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts +132 -0
  234. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -0
  235. package/lib/feature-libraries/indexing/anchorTreeIndex.js +356 -0
  236. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -0
  237. package/lib/feature-libraries/indexing/index.d.ts +7 -0
  238. package/lib/feature-libraries/indexing/index.d.ts.map +1 -0
  239. package/lib/{events → feature-libraries/indexing}/index.js +1 -1
  240. package/lib/feature-libraries/indexing/index.js.map +1 -0
  241. package/lib/feature-libraries/indexing/types.d.ts +32 -0
  242. package/lib/feature-libraries/indexing/types.d.ts.map +1 -0
  243. package/lib/{events/interop.js → feature-libraries/indexing/types.js} +1 -1
  244. package/lib/feature-libraries/indexing/types.js.map +1 -0
  245. package/lib/feature-libraries/object-forest/objectForest.d.ts +5 -2
  246. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  247. package/lib/feature-libraries/object-forest/objectForest.js +15 -5
  248. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  249. package/lib/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  250. package/lib/feature-libraries/sequence-field/invert.js +4 -4
  251. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  252. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +4 -3
  253. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  254. package/lib/index.d.ts +4 -4
  255. package/lib/index.d.ts.map +1 -1
  256. package/lib/index.js +1 -1
  257. package/lib/index.js.map +1 -1
  258. package/lib/packageVersion.d.ts +1 -1
  259. package/lib/packageVersion.js +1 -1
  260. package/lib/packageVersion.js.map +1 -1
  261. package/lib/shared-tree/index.d.ts +1 -1
  262. package/lib/shared-tree/index.d.ts.map +1 -1
  263. package/lib/shared-tree/index.js +1 -1
  264. package/lib/shared-tree/index.js.map +1 -1
  265. package/lib/shared-tree/schematizingTreeView.d.ts +7 -1
  266. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  267. package/lib/shared-tree/schematizingTreeView.js +2 -2
  268. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  269. package/lib/shared-tree/sharedTree.d.ts +3 -0
  270. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  271. package/lib/shared-tree/sharedTree.js +37 -1
  272. package/lib/shared-tree/sharedTree.js.map +1 -1
  273. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  274. package/lib/shared-tree/sharedTreeChangeFamily.js +5 -5
  275. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  276. package/lib/shared-tree/treeCheckout.d.ts +28 -64
  277. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  278. package/lib/shared-tree/treeCheckout.js +140 -116
  279. package/lib/shared-tree/treeCheckout.js.map +1 -1
  280. package/lib/shared-tree-core/branch.d.ts +25 -81
  281. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  282. package/lib/shared-tree-core/branch.js +72 -151
  283. package/lib/shared-tree-core/branch.js.map +1 -1
  284. package/lib/shared-tree-core/branchCommitEnricher.d.ts +19 -33
  285. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  286. package/lib/shared-tree-core/branchCommitEnricher.js +74 -55
  287. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  288. package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  289. package/lib/shared-tree-core/defaultResubmitMachine.js +3 -2
  290. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  291. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  292. package/lib/shared-tree-core/editManager.js +1 -1
  293. package/lib/shared-tree-core/editManager.js.map +1 -1
  294. package/lib/shared-tree-core/index.d.ts +1 -1
  295. package/lib/shared-tree-core/index.d.ts.map +1 -1
  296. package/lib/shared-tree-core/index.js +1 -1
  297. package/lib/shared-tree-core/index.js.map +1 -1
  298. package/lib/shared-tree-core/sharedTreeCore.d.ts +2 -2
  299. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  300. package/lib/shared-tree-core/sharedTreeCore.js +12 -53
  301. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  302. package/lib/shared-tree-core/transaction.d.ts +108 -0
  303. package/lib/shared-tree-core/transaction.d.ts.map +1 -0
  304. package/lib/shared-tree-core/transaction.js +95 -0
  305. package/lib/shared-tree-core/transaction.js.map +1 -0
  306. package/lib/shared-tree-core/transactionEnricher.d.ts +8 -13
  307. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  308. package/lib/shared-tree-core/transactionEnricher.js +41 -21
  309. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  310. package/lib/simple-tree/api/identifierIndex.d.ts +21 -0
  311. package/lib/simple-tree/api/identifierIndex.d.ts.map +1 -0
  312. package/lib/simple-tree/api/identifierIndex.js +41 -0
  313. package/lib/simple-tree/api/identifierIndex.js.map +1 -0
  314. package/lib/simple-tree/api/index.d.ts +2 -0
  315. package/lib/simple-tree/api/index.d.ts.map +1 -1
  316. package/lib/simple-tree/api/index.js +2 -0
  317. package/lib/simple-tree/api/index.js.map +1 -1
  318. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +11 -9
  319. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  320. package/lib/simple-tree/api/simpleTreeIndex.d.ts +65 -0
  321. package/lib/simple-tree/api/simpleTreeIndex.d.ts.map +1 -0
  322. package/lib/simple-tree/api/simpleTreeIndex.js +87 -0
  323. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -0
  324. package/lib/simple-tree/api/tree.d.ts +4 -5
  325. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  326. package/lib/simple-tree/api/tree.js.map +1 -1
  327. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  328. package/lib/simple-tree/core/index.d.ts +1 -1
  329. package/lib/simple-tree/core/index.d.ts.map +1 -1
  330. package/lib/simple-tree/core/index.js +1 -1
  331. package/lib/simple-tree/core/index.js.map +1 -1
  332. package/lib/simple-tree/core/treeNodeKernel.d.ts +6 -2
  333. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  334. package/lib/simple-tree/core/treeNodeKernel.js +31 -1
  335. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  336. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
  337. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  338. package/lib/simple-tree/core/unhydratedFlexTree.js +1 -1
  339. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  340. package/lib/simple-tree/index.d.ts +1 -1
  341. package/lib/simple-tree/index.d.ts.map +1 -1
  342. package/lib/simple-tree/index.js +1 -1
  343. package/lib/simple-tree/index.js.map +1 -1
  344. package/lib/simple-tree/objectNode.d.ts +7 -2
  345. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  346. package/lib/simple-tree/objectNode.js.map +1 -1
  347. package/lib/simple-tree/toMapTree.js +5 -5
  348. package/lib/simple-tree/toMapTree.js.map +1 -1
  349. package/lib/util/index.d.ts +1 -2
  350. package/lib/util/index.d.ts.map +1 -1
  351. package/lib/util/index.js +1 -2
  352. package/lib/util/index.js.map +1 -1
  353. package/lib/util/typeCheck.d.ts +6 -1
  354. package/lib/util/typeCheck.d.ts.map +1 -1
  355. package/lib/util/typeCheck.js.map +1 -1
  356. package/lib/util/typeCheckTests.d.ts +14 -2
  357. package/lib/util/typeCheckTests.d.ts.map +1 -1
  358. package/lib/util/typeCheckTests.js.map +1 -1
  359. package/lib/util/utils.d.ts +29 -0
  360. package/lib/util/utils.d.ts.map +1 -1
  361. package/lib/util/utils.js +9 -0
  362. package/lib/util/utils.js.map +1 -1
  363. package/package.json +22 -22
  364. package/src/core/forest/forest.ts +12 -1
  365. package/src/core/index.ts +8 -1
  366. package/src/core/rebase/utils.ts +12 -10
  367. package/src/core/revertible.ts +35 -1
  368. package/src/core/schema-stored/storedSchemaRepository.ts +2 -1
  369. package/src/core/tree/anchorSet.ts +2 -1
  370. package/src/core/tree/detachedFieldIndexCodec.ts +4 -3
  371. package/src/core/tree/index.ts +1 -0
  372. package/src/core/tree/visitorUtils.ts +56 -1
  373. package/src/feature-libraries/chunked-forest/chunkedForest.ts +33 -7
  374. package/src/feature-libraries/chunked-forest/uniformChunk.ts +3 -3
  375. package/src/feature-libraries/flex-tree/context.ts +1 -1
  376. package/src/feature-libraries/index.ts +9 -0
  377. package/src/feature-libraries/indexing/anchorTreeIndex.ts +453 -0
  378. package/src/feature-libraries/indexing/index.ts +11 -0
  379. package/src/feature-libraries/indexing/types.ts +37 -0
  380. package/src/feature-libraries/object-forest/objectForest.ts +22 -4
  381. package/src/feature-libraries/sequence-field/invert.ts +4 -4
  382. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +4 -4
  383. package/src/index.ts +16 -6
  384. package/src/packageVersion.ts +1 -1
  385. package/src/shared-tree/index.ts +0 -2
  386. package/src/shared-tree/schematizingTreeView.ts +7 -7
  387. package/src/shared-tree/sharedTree.ts +60 -6
  388. package/src/shared-tree/sharedTreeChangeFamily.ts +5 -4
  389. package/src/shared-tree/treeCheckout.ts +186 -193
  390. package/src/shared-tree-core/branch.ts +93 -220
  391. package/src/shared-tree-core/branchCommitEnricher.ts +69 -64
  392. package/src/shared-tree-core/defaultResubmitMachine.ts +3 -2
  393. package/src/shared-tree-core/editManager.ts +1 -1
  394. package/src/shared-tree-core/index.ts +9 -2
  395. package/src/shared-tree-core/sharedTreeCore.ts +17 -62
  396. package/src/shared-tree-core/transaction.ts +165 -0
  397. package/src/shared-tree-core/transactionEnricher.ts +30 -24
  398. package/src/simple-tree/api/identifierIndex.ts +64 -0
  399. package/src/simple-tree/api/index.ts +5 -0
  400. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +17 -18
  401. package/src/simple-tree/api/simpleTreeIndex.ts +231 -0
  402. package/src/simple-tree/api/tree.ts +8 -5
  403. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  404. package/src/simple-tree/core/index.ts +1 -0
  405. package/src/simple-tree/core/treeNodeKernel.ts +37 -2
  406. package/src/simple-tree/core/unhydratedFlexTree.ts +2 -1
  407. package/src/simple-tree/index.ts +4 -0
  408. package/src/simple-tree/objectNode.ts +19 -12
  409. package/src/simple-tree/toMapTree.ts +5 -5
  410. package/src/util/index.ts +3 -1
  411. package/src/util/typeCheck.ts +6 -1
  412. package/src/util/typeCheckTests.ts +11 -1
  413. package/src/util/utils.ts +38 -0
  414. package/dist/events/emitter.d.ts +0 -139
  415. package/dist/events/emitter.d.ts.map +0 -1
  416. package/dist/events/emitter.js +0 -165
  417. package/dist/events/emitter.js.map +0 -1
  418. package/dist/events/index.d.ts +0 -7
  419. package/dist/events/index.d.ts.map +0 -1
  420. package/dist/events/index.js +0 -11
  421. package/dist/events/index.js.map +0 -1
  422. package/dist/events/interop.d.ts +0 -30
  423. package/dist/events/interop.d.ts.map +0 -1
  424. package/dist/events/interop.js.map +0 -1
  425. package/dist/events/listeners.d.ts +0 -76
  426. package/dist/events/listeners.d.ts.map +0 -1
  427. package/dist/events/listeners.js +0 -7
  428. package/dist/events/listeners.js.map +0 -1
  429. package/dist/shared-tree-core/transactionStack.d.ts +0 -29
  430. package/dist/shared-tree-core/transactionStack.d.ts.map +0 -1
  431. package/dist/shared-tree-core/transactionStack.js +0 -41
  432. package/dist/shared-tree-core/transactionStack.js.map +0 -1
  433. package/dist/util/transactionResult.d.ts +0 -19
  434. package/dist/util/transactionResult.d.ts.map +0 -1
  435. package/dist/util/transactionResult.js +0 -23
  436. package/dist/util/transactionResult.js.map +0 -1
  437. package/lib/events/emitter.d.ts +0 -139
  438. package/lib/events/emitter.d.ts.map +0 -1
  439. package/lib/events/emitter.js +0 -160
  440. package/lib/events/emitter.js.map +0 -1
  441. package/lib/events/index.d.ts +0 -7
  442. package/lib/events/index.d.ts.map +0 -1
  443. package/lib/events/index.js.map +0 -1
  444. package/lib/events/interop.d.ts +0 -30
  445. package/lib/events/interop.d.ts.map +0 -1
  446. package/lib/events/interop.js.map +0 -1
  447. package/lib/events/listeners.d.ts +0 -76
  448. package/lib/events/listeners.d.ts.map +0 -1
  449. package/lib/events/listeners.js +0 -6
  450. package/lib/events/listeners.js.map +0 -1
  451. package/lib/shared-tree-core/transactionStack.d.ts +0 -29
  452. package/lib/shared-tree-core/transactionStack.d.ts.map +0 -1
  453. package/lib/shared-tree-core/transactionStack.js +0 -37
  454. package/lib/shared-tree-core/transactionStack.js.map +0 -1
  455. package/lib/util/transactionResult.d.ts +0 -19
  456. package/lib/util/transactionResult.d.ts.map +0 -1
  457. package/lib/util/transactionResult.js +0 -20
  458. package/lib/util/transactionResult.js.map +0 -1
  459. package/src/events/README.md +0 -3
  460. package/src/events/emitter.ts +0 -256
  461. package/src/events/index.ts +0 -19
  462. package/src/events/interop.ts +0 -38
  463. package/src/events/listeners.ts +0 -80
  464. package/src/shared-tree-core/transactionStack.ts +0 -45
  465. package/src/util/transactionResult.ts +0 -19
@@ -3,7 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { assert, oob } from "@fluidframework/core-utils/internal";
6
+ import { assert } from "@fluidframework/core-utils/internal";
7
7
  import type {
8
8
  IChannelAttributes,
9
9
  IFluidDataStoreRuntime,
@@ -45,7 +45,7 @@ import {
45
45
  breakingClass,
46
46
  } from "../util/index.js";
47
47
 
48
- import { type SharedTreeBranch, getChangeReplaceType } from "./branch.js";
48
+ import { getChangeReplaceType, type SharedTreeBranch } from "./branch.js";
49
49
  import { EditManager, minimumPossibleSequenceNumber } from "./editManager.js";
50
50
  import { makeEditManagerCodec } from "./editManagerCodecs.js";
51
51
  import type { SeqNumber } from "./editManagerFormat.js";
@@ -183,60 +183,20 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
183
183
  this.mintRevisionTag,
184
184
  rebaseLogger,
185
185
  );
186
- this.editManager.localBranch.events.on("transactionStarted", () => {
187
- this.commitEnricher.startNewTransaction();
188
- });
189
- this.editManager.localBranch.events.on("transactionAborted", () => {
190
- this.commitEnricher.abortCurrentTransaction();
191
- });
192
- this.editManager.localBranch.events.on("transactionCommitted", () => {
193
- this.commitEnricher.commitCurrentTransaction();
194
- });
186
+
195
187
  this.editManager.localBranch.events.on("beforeChange", (change) => {
196
- // Ensure that any previously prepared commits that have not been sent are purged.
197
- this.commitEnricher.purgePreparedCommits();
198
- if (this.detachedRevision !== undefined) {
199
- // Edits submitted before the first attach do not need enrichment because they will not be applied by peers.
200
- } else if (change.type === "append") {
201
- if (this.getLocalBranch().isTransacting()) {
202
- for (const newCommit of change.newCommits) {
203
- this.commitEnricher.ingestTransactionCommit(newCommit);
204
- }
205
- } else {
206
- for (const newCommit of change.newCommits) {
207
- this.commitEnricher.prepareCommit(newCommit, false);
208
- }
209
- }
210
- } else if (
211
- change.type === "replace" &&
212
- getChangeReplaceType(change) === "transactionCommit" &&
213
- !this.getLocalBranch().isTransacting()
214
- ) {
215
- assert(
216
- change.newCommits.length === 1,
217
- 0x983 /* Unexpected number of commits when committing transaction */,
218
- );
219
- this.commitEnricher.prepareCommit(change.newCommits[0] ?? oob(), true);
188
+ if (this.detachedRevision === undefined) {
189
+ // Commit enrichment is only necessary for changes that will be submitted as ops, and changes issued while detached are not submitted.
190
+ this.commitEnricher.processChange(change);
220
191
  }
221
192
  });
222
193
  this.editManager.localBranch.events.on("afterChange", (change) => {
223
- if (this.getLocalBranch().isTransacting()) {
224
- // We do not submit ops for changes that are part of a transaction.
225
- return;
226
- }
227
194
  if (
228
195
  change.type === "append" ||
229
196
  (change.type === "replace" && getChangeReplaceType(change) === "transactionCommit")
230
197
  ) {
231
- if (this.detachedRevision !== undefined) {
232
- for (const newCommit of change.newCommits) {
233
- this.submitCommit(newCommit, this.schemaAndPolicy);
234
- }
235
- } else {
236
- for (const newCommit of change.newCommits) {
237
- const prepared = this.commitEnricher.getPreparedCommit(newCommit);
238
- this.submitCommit(prepared, this.schemaAndPolicy);
239
- }
198
+ for (const commit of change.newCommits) {
199
+ this.submitCommit(commit, this.schemaAndPolicy);
240
200
  }
241
201
  }
242
202
  });
@@ -353,22 +313,21 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
353
313
  * @returns the submitted commit. This is undefined if the underlying `SharedObject` is not attached,
354
314
  * and may differ from `commit` due to enrichments like detached tree refreshers.
355
315
  */
356
-
357
- private submitCommit(
316
+ protected submitCommit(
358
317
  commit: GraphCommit<TChange>,
359
318
  schemaAndPolicy: ClonableSchemaAndPolicy,
360
319
  isResubmit = false,
361
320
  ): void {
362
- assert(
363
- // Edits should not be submitted until all transactions finish
364
- !this.getLocalBranch().isTransacting() || isResubmit,
365
- 0x68b /* Unexpected edit submitted during transaction */,
366
- );
367
321
  assert(
368
322
  this.isAttached() === (this.detachedRevision === undefined),
369
323
  0x95a /* Detached revision should only be set when not attached */,
370
324
  );
371
325
 
326
+ const enrichedCommit =
327
+ this.detachedRevision === undefined && !isResubmit
328
+ ? this.commitEnricher.enrich(commit)
329
+ : commit;
330
+
372
331
  // Edits submitted before the first attach are treated as sequenced because they will be included
373
332
  // in the attach summary that is uploaded to the service.
374
333
  // Until this attach workflow happens, this instance essentially behaves as a centralized data structure.
@@ -376,7 +335,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
376
335
  const newRevision: SeqNumber = brand((this.detachedRevision as number) + 1);
377
336
  this.detachedRevision = newRevision;
378
337
  this.editManager.addSequencedChange(
379
- { ...commit, sessionId: this.editManager.localSessionId },
338
+ { ...enrichedCommit, sessionId: this.editManager.localSessionId },
380
339
  newRevision,
381
340
  this.detachedRevision,
382
341
  );
@@ -385,7 +344,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
385
344
  }
386
345
  const message = this.messageCodec.encode(
387
346
  {
388
- commit,
347
+ commit: enrichedCommit,
389
348
  sessionId: this.editManager.localSessionId,
390
349
  },
391
350
  {
@@ -398,7 +357,7 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
398
357
  schema: schemaAndPolicy.schema.clone(),
399
358
  policy: schemaAndPolicy.policy,
400
359
  });
401
- this.resubmitMachine.onCommitSubmitted(commit);
360
+ this.resubmitMachine.onCommitSubmitted(enrichedCommit);
402
361
  }
403
362
 
404
363
  protected processCore(
@@ -469,10 +428,6 @@ export class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>
469
428
  }
470
429
 
471
430
  protected applyStashedOp(content: JsonCompatibleReadOnly): void {
472
- assert(
473
- !this.getLocalBranch().isTransacting(),
474
- 0x674 /* Unexpected transaction is open while applying stashed ops */,
475
- );
476
431
  // Empty context object is passed in, as our decode function is schema-agnostic.
477
432
  const {
478
433
  commit: { revision, change },
@@ -0,0 +1,165 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { createEmitter } from "@fluid-internal/client-utils";
7
+ import type { IDisposable, Listenable } from "@fluidframework/core-interfaces";
8
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
9
+
10
+ /**
11
+ * Describes the result of a transaction.
12
+ * Transactions may either succeed and commit, or fail and abort.
13
+ */
14
+ export enum TransactionResult {
15
+ /**
16
+ * Indicates the transaction failed.
17
+ */
18
+ Abort,
19
+ /**
20
+ * Indicates the transaction succeeded.
21
+ */
22
+ Commit,
23
+ }
24
+
25
+ /**
26
+ * A simple API for managing transactions.
27
+ */
28
+ export interface Transactor {
29
+ /**
30
+ * Start a new transaction.
31
+ * If a transaction is already in progress when this new transaction starts, then this transaction will be "nested" inside of it,
32
+ * i.e. the outer transaction will still be in progress after this new transaction is committed or aborted.
33
+ *
34
+ * @remarks - Asynchronous transactions are not supported on the root checkout,
35
+ * since it is always kept up-to-date with the latest remote edits and the results of this rebasing (which might invalidate
36
+ * the transaction) is not visible to the application author.
37
+ * Instead,
38
+ *
39
+ * 1. fork the root checkout
40
+ * 2. run the transaction on the fork
41
+ * 3. merge the fork back into the root checkout
42
+ *
43
+ * @privateRemarks - There is currently no enforcement that asynchronous transactions don't happen on the root checkout.
44
+ * AB#6488 tracks adding some enforcement to make it more clear to application authors that this is not supported.
45
+ */
46
+ start(): void;
47
+ /**
48
+ * Close this transaction by squashing its edits and committing them as a single edit.
49
+ * If this is the root checkout and there are no ongoing transactions remaining, the squashed edit will be submitted to Fluid.
50
+ */
51
+ commit(): void;
52
+ /**
53
+ * Close this transaction and revert the state of the tree to what it was before this transaction began.
54
+ */
55
+ abort(): void;
56
+ /**
57
+ * True if there is at least one transaction currently in progress on this view, otherwise false.
58
+ */
59
+ isInProgress(): boolean;
60
+ /**
61
+ * Provides events for changes in transaction progress.
62
+ */
63
+ events: Listenable<TransactionEvents>;
64
+ }
65
+
66
+ export interface TransactionEvents {
67
+ /**
68
+ * Raised just after a transaction has begun.
69
+ * @remarks When this event fires, {@link Transactor.isInProgress} will be true because the transaction has already begun.
70
+ */
71
+ started(): void;
72
+ /**
73
+ * Raised just before a transaction is aborted.
74
+ * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.
75
+ */
76
+ aborting(): void;
77
+ /**
78
+ * Raised just before a transaction is committed.
79
+ * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.
80
+ */
81
+ committing(): void;
82
+ }
83
+
84
+ /**
85
+ * A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.
86
+ * @remarks This function may return {@link OnPop | its complement} - another function that will be called when the transaction is popped from the stack.
87
+ * This function runs just before the transaction begins, so if this is the beginning of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.
88
+ */
89
+ export type OnPush = () => OnPop | void;
90
+
91
+ /**
92
+ * A function that will be called when a transaction is popped from the {@link TransactionStack | stack}.
93
+ * @remarks This function runs just after the transaction ends, so if this is the end of an outermost (not nested) transaction then {@link Transactor.isInProgress} will be false during its execution.
94
+ */
95
+ export type OnPop = (result: TransactionResult) => void;
96
+
97
+ /**
98
+ * An implementation of {@link Transactor} that uses a stack to manage transactions.
99
+ * @remarks Using a stack allows transactions to nest - i.e. an inner transaction may be started while an outer transaction is already in progress.
100
+ */
101
+ export class TransactionStack implements Transactor, IDisposable {
102
+ readonly #stack: (OnPop | void)[] = [];
103
+ readonly #onPush?: () => OnPop | void;
104
+
105
+ readonly #events = createEmitter<TransactionEvents>();
106
+ public get events(): Listenable<TransactionEvents> {
107
+ return this.#events;
108
+ }
109
+
110
+ #disposed = false;
111
+ public get disposed(): boolean {
112
+ return this.#disposed;
113
+ }
114
+
115
+ /**
116
+ * Construct a new {@link TransactionStack}.
117
+ * @param onPush - A {@link OnPush | function} that will be called when a transaction begins.
118
+ */
119
+ public constructor(onPush?: () => OnPop | void) {
120
+ this.#onPush = onPush;
121
+ }
122
+
123
+ public isInProgress(): boolean {
124
+ this.ensureNotDisposed();
125
+ return this.#stack.length > 0;
126
+ }
127
+
128
+ public start(): void {
129
+ this.ensureNotDisposed();
130
+ this.#stack.push(this.#onPush?.());
131
+ this.#events.emit("started");
132
+ }
133
+
134
+ public commit(): void {
135
+ this.ensureNotDisposed();
136
+ if (!this.isInProgress()) {
137
+ throw new UsageError("No transaction to commit");
138
+ }
139
+ this.#events.emit("committing");
140
+ this.#stack.pop()?.(TransactionResult.Commit);
141
+ }
142
+
143
+ public abort(): void {
144
+ this.ensureNotDisposed();
145
+ if (!this.isInProgress()) {
146
+ throw new UsageError("No transaction to abort");
147
+ }
148
+ this.#events.emit("aborting");
149
+ this.#stack.pop()?.(TransactionResult.Abort);
150
+ }
151
+
152
+ public dispose(): void {
153
+ this.ensureNotDisposed();
154
+ while (this.isInProgress()) {
155
+ this.abort();
156
+ }
157
+ this.#disposed = true;
158
+ }
159
+
160
+ private ensureNotDisposed(): void {
161
+ if (this.disposed) {
162
+ throw new UsageError("Transactor is disposed");
163
+ }
164
+ }
165
+ }
@@ -11,54 +11,60 @@ import type { ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
11
11
  * Utility for producing an enriched commit out of multiple transaction steps
12
12
  */
13
13
  export class TransactionEnricher<TChange> {
14
- private readonly rebaser: ChangeRebaser<TChange>;
15
- private readonly enricher: ChangeEnricherReadonlyCheckout<TChange>;
16
- private readonly transactionCommits: GraphCommit<TChange>[] = [];
14
+ readonly #rebaser: ChangeRebaser<TChange>;
15
+ readonly #enricher: ChangeEnricherReadonlyCheckout<TChange>;
16
+ #transactionCommits: GraphCommit<TChange>[] = [];
17
17
  /**
18
18
  * The number of commits before the start of each active transaction scope.
19
19
  * For a stack of `n` transaction scopes, the array will contain `n` integers,
20
20
  * where the integer at index `i` is the number of commits made before the start of the `i`th transaction scope
21
21
  * (therefore, the first element in the array, if present, is always 0)
22
22
  */
23
- private readonly transactionScopesStart: number[] = [];
23
+ readonly #transactionScopesStart: number[] = [];
24
24
 
25
25
  public constructor(
26
26
  rebaser: ChangeRebaser<TChange>,
27
27
  enricher: ChangeEnricherReadonlyCheckout<TChange>,
28
28
  ) {
29
- this.rebaser = rebaser;
30
- this.enricher = enricher;
29
+ this.#rebaser = rebaser;
30
+ this.#enricher = enricher;
31
31
  }
32
32
 
33
- public startNewTransaction(): void {
34
- this.transactionScopesStart.push(this.transactionCommits.length);
33
+ public isTransacting(): boolean {
34
+ return this.#transactionScopesStart.length !== 0;
35
35
  }
36
36
 
37
- public commitCurrentTransaction(): void {
38
- const commitsCommitted = this.transactionScopesStart.pop();
37
+ public startTransaction(): void {
38
+ this.#transactionScopesStart.push(this.#transactionCommits.length);
39
+ }
40
+
41
+ /**
42
+ * Commits the current transaction.
43
+ * @returns If and only if the closed transaction was the outermost transaction, returns a function which can be used to compute the composed change for that transaction's commits.
44
+ */
45
+ public commitTransaction(): ((revision: RevisionTag) => TChange) | undefined {
46
+ const commitsCommitted = this.#transactionScopesStart.pop();
39
47
  assert(commitsCommitted !== undefined, 0x985 /* No transaction to commit */);
48
+ if (this.#transactionScopesStart.length === 0) {
49
+ const transactionCommits = this.#transactionCommits;
50
+ this.#transactionCommits = [];
51
+ return (revision: RevisionTag) =>
52
+ this.#rebaser.changeRevision(this.#rebaser.compose(transactionCommits), revision);
53
+ }
40
54
  }
41
55
 
42
- public abortCurrentTransaction(): void {
43
- const scopeStart = this.transactionScopesStart.pop();
56
+ public abortTransaction(): void {
57
+ const scopeStart = this.#transactionScopesStart.pop();
44
58
  assert(scopeStart !== undefined, 0x986 /* No transaction to abort */);
45
- this.transactionCommits.length = scopeStart;
59
+ this.#transactionCommits.length = scopeStart;
46
60
  }
47
61
 
48
62
  public addTransactionStep(commit: GraphCommit<TChange>): void {
49
63
  assert(
50
- this.transactionScopesStart.length !== 0,
64
+ this.#transactionScopesStart.length !== 0,
51
65
  0x987 /* No transaction to add a step to */,
52
66
  );
53
- const change = this.enricher.updateChangeEnrichments(commit.change, commit.revision);
54
- this.transactionCommits.push({ ...commit, change });
55
- }
56
-
57
- public getComposedChange(revision: RevisionTag): TChange {
58
- assert(this.transactionScopesStart.length === 0, 0x988 /* Transaction not committed */);
59
- const squashed = this.rebaser.compose(this.transactionCommits);
60
- const tagged = this.rebaser.changeRevision(squashed, revision);
61
- this.transactionCommits.length = 0;
62
- return tagged;
67
+ const change = this.#enricher.updateChangeEnrichments(commit.change, commit.revision);
68
+ this.#transactionCommits.push({ ...commit, change });
63
69
  }
64
70
  }
@@ -0,0 +1,64 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
7
+ import type { TreeIndexKey } from "../../feature-libraries/index.js";
8
+ import { FieldKind, type ImplicitFieldSchema } from "../schemaTypes.js";
9
+ import type { TreeNode } from "../core/index.js";
10
+ import { ObjectNodeSchema } from "../objectNodeTypes.js";
11
+ import type { TreeView } from "./tree.js";
12
+ import { walkFieldSchema } from "../walkFieldSchema.js";
13
+ import { createSimpleTreeIndex, type SimpleTreeIndex } from "./simpleTreeIndex.js";
14
+
15
+ /**
16
+ * An index that returns tree nodes given their associated identifiers.
17
+ *
18
+ * @alpha
19
+ */
20
+ export type IdentifierIndex = SimpleTreeIndex<string, TreeNode>;
21
+
22
+ function isStringKey(key: TreeIndexKey): key is string {
23
+ return typeof key === "string";
24
+ }
25
+
26
+ /**
27
+ * Creates an {@link IdentifierIndex} for a given {@link TreeView}.
28
+ *
29
+ * @alpha
30
+ */
31
+ export function createIdentifierIndex<TSchema extends ImplicitFieldSchema>(
32
+ view: TreeView<TSchema>,
33
+ ): IdentifierIndex {
34
+ // For each node schema, find which field key the identifier field is under.
35
+ // This can be done easily because identifiers are their own field kinds.
36
+ const identifierFields = new Map<string, string>();
37
+ walkFieldSchema(view.schema, {
38
+ node: (schemus) => {
39
+ if (schemus instanceof ObjectNodeSchema) {
40
+ for (const [fieldKey, fieldSchema] of schemus.fields.entries()) {
41
+ if (fieldSchema.kind === FieldKind.Identifier) {
42
+ identifierFields.set(schemus.identifier, fieldKey);
43
+ break;
44
+ }
45
+ }
46
+ }
47
+ },
48
+ });
49
+
50
+ return createSimpleTreeIndex(
51
+ view,
52
+ (schemus) => identifierFields.get(schemus.identifier),
53
+ (nodes) => {
54
+ if (nodes.length > 1) {
55
+ throw new UsageError(
56
+ "cannot retrieve node from index: there are multiple nodes with the same identifier",
57
+ );
58
+ }
59
+
60
+ return nodes[0];
61
+ },
62
+ isStringKey,
63
+ );
64
+ }
@@ -95,6 +95,11 @@ export type { EncodeOptions } from "./customTree.js";
95
95
  export { type ConciseTree, conciseFromCursor } from "./conciseTree.js";
96
96
 
97
97
  export { TreeBeta, type NodeChangedData, type TreeChangeEventsBeta } from "./treeApiBeta.js";
98
+ export { createSimpleTreeIndex, type SimpleTreeIndex } from "./simpleTreeIndex.js";
99
+ export {
100
+ createIdentifierIndex,
101
+ type IdentifierIndex,
102
+ } from "./identifierIndex.js";
98
103
 
99
104
  export {
100
105
  extractPersistedSchema,
@@ -3,10 +3,10 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { oob, unreachableCase } from "@fluidframework/core-utils/internal";
6
+ import { unreachableCase } from "@fluidframework/core-utils/internal";
7
7
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
8
8
  import { ValueSchema } from "../../core/index.js";
9
- import { getOrCreate, type Mutable } from "../../util/index.js";
9
+ import { getOrCreate, hasSingle, type Mutable } from "../../util/index.js";
10
10
  import type {
11
11
  JsonArrayNodeSchema,
12
12
  JsonFieldSchema,
@@ -42,9 +42,9 @@ export function toJsonSchema(schema: SimpleTreeSchema): JsonTreeSchema {
42
42
  allowedTypes.push(createSchemaRef(allowedType));
43
43
  }
44
44
 
45
- return allowedTypes.length === 1
45
+ return hasSingle(allowedTypes)
46
46
  ? {
47
- ...(allowedTypes[0] ?? oob()),
47
+ ...allowedTypes[0],
48
48
  $defs: definitions,
49
49
  }
50
50
  : {
@@ -96,8 +96,9 @@ function convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSch
96
96
  allowedTypes.push(createSchemaRef(type));
97
97
  });
98
98
 
99
- const items: JsonFieldSchema =
100
- allowedTypes.length === 1 ? (allowedTypes[0] ?? oob()) : { anyOf: allowedTypes };
99
+ const items: JsonFieldSchema = hasSingle(allowedTypes)
100
+ ? allowedTypes[0]
101
+ : { anyOf: allowedTypes };
101
102
 
102
103
  return {
103
104
  type: "array",
@@ -142,12 +143,11 @@ function convertObjectNodeSchema(schema: SimpleObjectNodeSchema): JsonObjectNode
142
143
  allowedTypes.push(createSchemaRef(allowedType));
143
144
  }
144
145
 
145
- const output: Mutable<JsonFieldSchema> =
146
- allowedTypes.length === 1
147
- ? (allowedTypes[0] ?? oob())
148
- : {
149
- anyOf: allowedTypes,
150
- };
146
+ const output: Mutable<JsonFieldSchema> = hasSingle(allowedTypes)
147
+ ? allowedTypes[0]
148
+ : {
149
+ anyOf: allowedTypes,
150
+ };
151
151
 
152
152
  // Don't include "description" property at all if it's not present in the input.
153
153
  if (value.metadata?.description !== undefined) {
@@ -178,12 +178,11 @@ function convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {
178
178
  type: "object",
179
179
  _treeNodeSchemaKind: NodeKind.Map,
180
180
  patternProperties: {
181
- "^.*$":
182
- allowedTypes.length === 1
183
- ? (allowedTypes[0] ?? oob())
184
- : {
185
- anyOf: allowedTypes,
186
- },
181
+ "^.*$": hasSingle(allowedTypes)
182
+ ? allowedTypes[0]
183
+ : {
184
+ anyOf: allowedTypes,
185
+ },
187
186
  },
188
187
  };
189
188
  }