@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
@@ -1 +1 @@
1
- {"version":3,"file":"sharedTreeCore.js","sourceRoot":"","sources":["../../src/shared-tree-core/sharedTreeCore.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAclE,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAEN,YAAY,GACZ,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAGN,YAAY,EAGZ,gBAAgB,GAKhB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEN,KAAK,EACL,SAAS,EAET,aAAa,EACb,aAAa,GACb,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAAyB,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,6BAA6B,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAA+B,gBAAgB,EAA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KACD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport {\n\ttype IFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { ICodecOptions, IJsonCodec } from \"../codec/index.js\";\nimport {\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tfindAncestor,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\tRevisionTagCodec,\n\ttype SchemaAndPolicy,\n\ttype SchemaPolicy,\n\ttype TaggedChange,\n\ttype TreeStoredSchemaRepository,\n} from \"../core/index.js\";\nimport {\n\ttype JsonCompatibleReadOnly,\n\tbrand,\n\tBreakable,\n\ttype WithBreakable,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"../util/index.js\";\n\nimport { type SharedTreeBranch, getChangeReplaceType } from \"./branch.js\";\nimport { EditManager, minimumPossibleSequenceNumber } from \"./editManager.js\";\nimport { makeEditManagerCodec } from \"./editManagerCodecs.js\";\nimport type { SeqNumber } from \"./editManagerFormat.js\";\nimport { EditManagerSummarizer } from \"./editManagerSummarizer.js\";\nimport { type MessageEncodingContext, makeMessageCodec } from \"./messageCodecs.js\";\nimport type { DecodedMessage } from \"./messageTypes.js\";\nimport { type ChangeEnricherReadonlyCheckout, NoOpChangeEnricher } from \"./changeEnricher.js\";\nimport type { ResubmitMachine } from \"./resubmitMachine.js\";\nimport { DefaultResubmitMachine } from \"./defaultResubmitMachine.js\";\nimport { BranchCommitEnricher } from \"./branchCommitEnricher.js\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\n\n// TODO: Organize this to be adjacent to persisted types.\nconst summarizablesTreeKey = \"indexes\";\n\nexport interface ExplicitCoreCodecVersions {\n\teditManager: number;\n\tmessage: number;\n}\n\nexport interface ClonableSchemaAndPolicy extends SchemaAndPolicy {\n\tschema: TreeStoredSchemaRepository;\n}\n\n/**\n * Generic shared tree, which needs to be configured with indexes, field kinds and other configuration.\n */\n@breakingClass\nexport class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>\n\textends SharedObject\n\timplements WithBreakable\n{\n\tpublic readonly breaker: Breakable = new Breakable(\"Shared Tree\");\n\n\tprivate readonly editManager: EditManager<TEditor, TChange, ChangeFamily<TEditor, TChange>>;\n\tprivate readonly summarizables: readonly [EditManagerSummarizer<TChange>, ...Summarizable[]];\n\t/**\n\t * The sequence number that this instance is at.\n\t * This number is artificial in that it is made up by this instance as opposed to being provided by the runtime.\n\t * Is `undefined` after (and only after) this instance is attached.\n\t */\n\tprivate detachedRevision: SeqNumber | undefined = minimumPossibleSequenceNumber;\n\n\t/**\n\t * Used to edit the state of the tree. Edits will be immediately applied locally to the tree.\n\t * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.\n\t */\n\tpublic get editor(): TEditor {\n\t\treturn this.getLocalBranch().editor;\n\t}\n\n\t/**\n\t * Gets the revision at the head of the trunk.\n\t */\n\tprotected get trunkHeadRevision(): RevisionTag {\n\t\treturn this.editManager.getTrunkHead().revision;\n\t}\n\n\t/**\n\t * Used to encode/decode messages sent to/received from the Fluid runtime.\n\t *\n\t * @remarks Since there is currently only one format, this can just be cached on the class.\n\t * With more write formats active, it may make sense to keep around the \"usual\" format codec\n\t * (the one for the current persisted configuration) and resolve codecs for different versions\n\t * as necessary (e.g. an upgrade op came in, or the configuration changed within the collab window\n\t * and an op needs to be interpreted which isn't written with the current configuration).\n\t */\n\tprivate readonly messageCodec: IJsonCodec<\n\t\tDecodedMessage<TChange>,\n\t\tunknown,\n\t\tunknown,\n\t\tMessageEncodingContext\n\t>;\n\n\tprivate readonly idCompressor: IIdCompressor;\n\n\tprivate readonly resubmitMachine: ResubmitMachine<TChange>;\n\tprotected readonly commitEnricher: BranchCommitEnricher<TChange>;\n\n\tprotected readonly mintRevisionTag: () => RevisionTag;\n\n\tprivate readonly schemaAndPolicy: ClonableSchemaAndPolicy;\n\n\t/**\n\t * @param summarizables - Summarizers for all indexes used by this tree\n\t * @param changeFamily - The change family\n\t * @param editManager - The edit manager\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t * @param telemetryContextPrefix - The property prefix for telemetry pertaining to this object. See {@link ITelemetryContext}\n\t */\n\tpublic constructor(\n\t\tsummarizables: readonly Summarizable[],\n\t\tchangeFamily: ChangeFamily<TEditor, TChange>,\n\t\toptions: ICodecOptions,\n\t\tformatOptions: ExplicitCoreCodecVersions,\n\t\t// Base class arguments\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\ttelemetryContextPrefix: string,\n\t\tschema: TreeStoredSchemaRepository,\n\t\tschemaPolicy: SchemaPolicy,\n\t\tresubmitMachine?: ResubmitMachine<TChange>,\n\t\tenricher?: ChangeEnricherReadonlyCheckout<TChange>,\n\t) {\n\t\tsuper(id, runtime, attributes, telemetryContextPrefix);\n\n\t\tthis.schemaAndPolicy = {\n\t\t\tschema,\n\t\t\tpolicy: schemaPolicy,\n\t\t};\n\n\t\tconst rebaseLogger = createChildLogger({\n\t\t\tlogger: this.logger,\n\t\t\tnamespace: \"Rebase\",\n\t\t});\n\n\t\tassert(\n\t\t\truntime.idCompressor !== undefined,\n\t\t\t0x886 /* IdCompressor must be enabled to use SharedTree */,\n\t\t);\n\t\tthis.idCompressor = runtime.idCompressor;\n\t\tthis.mintRevisionTag = () => this.idCompressor.generateCompressedId();\n\t\t/**\n\t\t * A random ID that uniquely identifies this client in the collab session.\n\t\t * This is sent alongside every op to identify which client the op originated from.\n\t\t * This is used rather than the Fluid client ID because the Fluid client ID is not stable across reconnections.\n\t\t */\n\t\tconst localSessionId = runtime.idCompressor.localSessionId;\n\t\tthis.editManager = new EditManager(\n\t\t\tchangeFamily,\n\t\t\tlocalSessionId,\n\t\t\tthis.mintRevisionTag,\n\t\t\trebaseLogger,\n\t\t);\n\t\tthis.editManager.localBranch.events.on(\"transactionStarted\", () => {\n\t\t\tthis.commitEnricher.startNewTransaction();\n\t\t});\n\t\tthis.editManager.localBranch.events.on(\"transactionAborted\", () => {\n\t\t\tthis.commitEnricher.abortCurrentTransaction();\n\t\t});\n\t\tthis.editManager.localBranch.events.on(\"transactionCommitted\", () => {\n\t\t\tthis.commitEnricher.commitCurrentTransaction();\n\t\t});\n\t\tthis.editManager.localBranch.events.on(\"beforeChange\", (change) => {\n\t\t\t// Ensure that any previously prepared commits that have not been sent are purged.\n\t\t\tthis.commitEnricher.purgePreparedCommits();\n\t\t\tif (this.detachedRevision !== undefined) {\n\t\t\t\t// Edits submitted before the first attach do not need enrichment because they will not be applied by peers.\n\t\t\t} else if (change.type === \"append\") {\n\t\t\t\tif (this.getLocalBranch().isTransacting()) {\n\t\t\t\t\tfor (const newCommit of change.newCommits) {\n\t\t\t\t\t\tthis.commitEnricher.ingestTransactionCommit(newCommit);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (const newCommit of change.newCommits) {\n\t\t\t\t\t\tthis.commitEnricher.prepareCommit(newCommit, false);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (\n\t\t\t\tchange.type === \"replace\" &&\n\t\t\t\tgetChangeReplaceType(change) === \"transactionCommit\" &&\n\t\t\t\t!this.getLocalBranch().isTransacting()\n\t\t\t) {\n\t\t\t\tassert(\n\t\t\t\t\tchange.newCommits.length === 1,\n\t\t\t\t\t0x983 /* Unexpected number of commits when committing transaction */,\n\t\t\t\t);\n\t\t\t\tthis.commitEnricher.prepareCommit(change.newCommits[0] ?? oob(), true);\n\t\t\t}\n\t\t});\n\t\tthis.editManager.localBranch.events.on(\"afterChange\", (change) => {\n\t\t\tif (this.getLocalBranch().isTransacting()) {\n\t\t\t\t// We do not submit ops for changes that are part of a transaction.\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif (\n\t\t\t\tchange.type === \"append\" ||\n\t\t\t\t(change.type === \"replace\" && getChangeReplaceType(change) === \"transactionCommit\")\n\t\t\t) {\n\t\t\t\tif (this.detachedRevision !== undefined) {\n\t\t\t\t\tfor (const newCommit of change.newCommits) {\n\t\t\t\t\t\tthis.submitCommit(newCommit, this.schemaAndPolicy);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (const newCommit of change.newCommits) {\n\t\t\t\t\t\tconst prepared = this.commitEnricher.getPreparedCommit(newCommit);\n\t\t\t\t\t\tthis.submitCommit(prepared, this.schemaAndPolicy);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst revisionTagCodec = new RevisionTagCodec(runtime.idCompressor);\n\t\tconst editManagerCodec = makeEditManagerCodec(\n\t\t\tthis.editManager.changeFamily.codecs,\n\t\t\trevisionTagCodec,\n\t\t\toptions,\n\t\t\tformatOptions.editManager,\n\t\t);\n\t\tthis.summarizables = [\n\t\t\tnew EditManagerSummarizer(\n\t\t\t\tthis.editManager,\n\t\t\t\teditManagerCodec,\n\t\t\t\tthis.idCompressor,\n\t\t\t\tthis.schemaAndPolicy,\n\t\t\t),\n\t\t\t...summarizables,\n\t\t];\n\t\tassert(\n\t\t\tnew Set(this.summarizables.map((e) => e.key)).size === this.summarizables.length,\n\t\t\t0x350 /* Index summary element keys must be unique */,\n\t\t);\n\n\t\tthis.messageCodec = makeMessageCodec(\n\t\t\tchangeFamily.codecs,\n\t\t\tnew RevisionTagCodec(runtime.idCompressor),\n\t\t\toptions,\n\t\t\tformatOptions.message,\n\t\t);\n\n\t\tconst changeEnricher = enricher ?? new NoOpChangeEnricher();\n\t\tthis.resubmitMachine =\n\t\t\tresubmitMachine ??\n\t\t\tnew DefaultResubmitMachine(\n\t\t\t\t(change: TaggedChange<TChange>) =>\n\t\t\t\t\tchangeFamily.rebaser.invert(change, true, this.mintRevisionTag()),\n\t\t\t\tchangeEnricher,\n\t\t\t);\n\t\tthis.commitEnricher = new BranchCommitEnricher(changeFamily.rebaser, changeEnricher);\n\t}\n\n\t// TODO: SharedObject's merging of the two summary methods into summarizeCore is not what we want here:\n\t// We might want to not subclass it, or override/reimplement most of its functionality.\n\t@throwIfBroken\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tconst summarizableBuilder = new SummaryTreeBuilder();\n\t\t// Merge the summaries of all summarizables together under a single ISummaryTree\n\t\tfor (const s of this.summarizables) {\n\t\t\tsummarizableBuilder.addWithStats(\n\t\t\t\ts.key,\n\t\t\t\ts.getAttachSummary(\n\t\t\t\t\t(contents) => serializer.stringify(contents, this.handle),\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\ttelemetryContext,\n\t\t\t\t\tincrementalSummaryContext,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tbuilder.addWithStats(summarizablesTreeKey, summarizableBuilder.getSummaryTree());\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tprotected async loadCore(services: IChannelStorageService): Promise<void> {\n\t\tconst [editManagerSummarizer, ...summarizables] = this.summarizables;\n\t\tconst loadEditManager = this.loadSummarizable(editManagerSummarizer, services);\n\t\tconst loadSummarizables = summarizables.map(async (s) =>\n\t\t\tthis.loadSummarizable(s, services),\n\t\t);\n\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\t// If we are detached but loading from a summary, then we need to update our detached revision to ensure that it is ahead of all detached revisions in the summary.\n\t\t\t// First, finish loading the edit manager so that we can inspect the sequence numbers of the commits on the trunk.\n\t\t\tawait loadEditManager;\n\t\t\t// Find the most recent detached revision in the summary trunk...\n\t\t\tlet latestDetachedSequenceNumber: SeqNumber | undefined;\n\t\t\tfindAncestor(this.editManager.getTrunkHead(), (c) => {\n\t\t\t\tconst sequenceNumber = this.editManager.getSequenceNumber(c);\n\t\t\t\tif (sequenceNumber !== undefined && sequenceNumber < 0) {\n\t\t\t\t\tlatestDetachedSequenceNumber = sequenceNumber;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\t// ...and set our detached revision to be as it would be if we had been already created that revision.\n\t\t\tthis.detachedRevision = latestDetachedSequenceNumber ?? this.detachedRevision;\n\t\t\tawait Promise.all(loadSummarizables);\n\t\t} else {\n\t\t\tawait Promise.all([loadEditManager, ...loadSummarizables]);\n\t\t}\n\t}\n\n\tprivate async loadSummarizable(\n\t\tsummarizable: Summarizable,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\treturn summarizable.load(\n\t\t\tscopeStorageService(services, summarizablesTreeKey, summarizable.key),\n\t\t\t(contents) => this.serializer.parse(contents),\n\t\t);\n\t}\n\n\t/**\n\t * Submits an op to the Fluid runtime containing the given commit\n\t * @param commit - the commit to submit\n\t * @returns the submitted commit. This is undefined if the underlying `SharedObject` is not attached,\n\t * and may differ from `commit` due to enrichments like detached tree refreshers.\n\t */\n\n\tprivate submitCommit(\n\t\tcommit: GraphCommit<TChange>,\n\t\tschemaAndPolicy: ClonableSchemaAndPolicy,\n\t\tisResubmit = false,\n\t): void {\n\t\tassert(\n\t\t\t// Edits should not be submitted until all transactions finish\n\t\t\t!this.getLocalBranch().isTransacting() || isResubmit,\n\t\t\t0x68b /* Unexpected edit submitted during transaction */,\n\t\t);\n\t\tassert(\n\t\t\tthis.isAttached() === (this.detachedRevision === undefined),\n\t\t\t0x95a /* Detached revision should only be set when not attached */,\n\t\t);\n\n\t\t// Edits submitted before the first attach are treated as sequenced because they will be included\n\t\t// in the attach summary that is uploaded to the service.\n\t\t// Until this attach workflow happens, this instance essentially behaves as a centralized data structure.\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\tconst newRevision: SeqNumber = brand((this.detachedRevision as number) + 1);\n\t\t\tthis.detachedRevision = newRevision;\n\t\t\tthis.editManager.addSequencedChange(\n\t\t\t\t{ ...commit, sessionId: this.editManager.localSessionId },\n\t\t\t\tnewRevision,\n\t\t\t\tthis.detachedRevision,\n\t\t\t);\n\t\t\tthis.editManager.advanceMinimumSequenceNumber(newRevision, false);\n\t\t\treturn undefined;\n\t\t}\n\t\tconst message = this.messageCodec.encode(\n\t\t\t{\n\t\t\t\tcommit,\n\t\t\t\tsessionId: this.editManager.localSessionId,\n\t\t\t},\n\t\t\t{\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t\tschema: schemaAndPolicy,\n\t\t\t},\n\t\t);\n\t\tthis.submitLocalMessage(message, {\n\t\t\t// Clone the schema to ensure that during resubmit the schema has not been mutated by later changes\n\t\t\tschema: schemaAndPolicy.schema.clone(),\n\t\t\tpolicy: schemaAndPolicy.policy,\n\t\t});\n\t\tthis.resubmitMachine.onCommitSubmitted(commit);\n\t}\n\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst { commit, sessionId } = this.messageCodec.decode(message.contents, {\n\t\t\tidCompressor: this.idCompressor,\n\t\t});\n\n\t\tthis.editManager.addSequencedChange(\n\t\t\t{ ...commit, sessionId },\n\t\t\tbrand(message.sequenceNumber),\n\t\t\tbrand(message.referenceSequenceNumber),\n\t\t);\n\t\tthis.resubmitMachine.onSequencedCommitApplied(local);\n\n\t\tthis.editManager.advanceMinimumSequenceNumber(brand(message.minimumSequenceNumber));\n\t}\n\n\t/**\n\t * @returns the head commit of the root local branch\n\t */\n\tprotected getLocalBranch(): SharedTreeBranch<TEditor, TChange> {\n\t\treturn this.editManager.localBranch;\n\t}\n\n\tprotected onDisconnect(): void {}\n\n\tprotected override didAttach(): void {\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\tthis.detachedRevision = undefined;\n\t\t}\n\t}\n\n\tprotected override reSubmitCore(\n\t\tcontent: JsonCompatibleReadOnly,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision },\n\t\t} = this.messageCodec.decode(this.serializer.decode(content), {\n\t\t\tidCompressor: this.idCompressor,\n\t\t});\n\t\tconst [commit] = this.editManager.findLocalCommit(revision);\n\t\t// If a resubmit phase is not already in progress, then this must be the first commit of a new resubmit phase.\n\t\tif (this.resubmitMachine.isInResubmitPhase === false) {\n\t\t\tconst toResubmit = this.editManager.getLocalCommits();\n\t\t\tassert(\n\t\t\t\tcommit === toResubmit[0],\n\t\t\t\t0x95d /* Resubmit phase should start with the oldest local commit */,\n\t\t\t);\n\t\t\tthis.resubmitMachine.prepareForResubmit(toResubmit);\n\t\t}\n\t\tassert(\n\t\t\tisClonableSchemaPolicy(localOpMetadata),\n\t\t\t0x95e /* Local metadata must contain schema and policy. */,\n\t\t);\n\t\tassert(\n\t\t\tthis.resubmitMachine.isInResubmitPhase !== false,\n\t\t\t0x984 /* Invalid resubmit outside of resubmit phase */,\n\t\t);\n\t\tconst enrichedCommit = this.resubmitMachine.peekNextCommit();\n\t\tthis.submitCommit(enrichedCommit, localOpMetadata, true);\n\t}\n\n\tprotected applyStashedOp(content: JsonCompatibleReadOnly): void {\n\t\tassert(\n\t\t\t!this.getLocalBranch().isTransacting(),\n\t\t\t0x674 /* Unexpected transaction is open while applying stashed ops */,\n\t\t);\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision, change },\n\t\t} = this.messageCodec.decode(content, { idCompressor: this.idCompressor });\n\t\tthis.editManager.localBranch.apply({ change, revision });\n\t}\n\n\tpublic override getGCData(fullGC?: boolean): IGarbageCollectionData {\n\t\tconst gcNodes: IGarbageCollectionData[\"gcNodes\"] = super.getGCData(fullGC).gcNodes;\n\t\tfor (const s of this.summarizables) {\n\t\t\tfor (const [id, routes] of Object.entries(s.getGCData(fullGC).gcNodes)) {\n\t\t\t\tgcNodes[id] ??= [];\n\t\t\t\tfor (const route of routes) {\n\t\t\t\t\t// Non null asserting here because we are creating an array at gcNodes[id] if it is undefined\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tgcNodes[id]!.push(route);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tgcNodes,\n\t\t};\n\t}\n}\n\nfunction isClonableSchemaPolicy(\n\tmaybeSchemaPolicy: unknown,\n): maybeSchemaPolicy is ClonableSchemaAndPolicy {\n\tconst schemaAndPolicy = maybeSchemaPolicy as ClonableSchemaAndPolicy;\n\treturn schemaAndPolicy.schema !== undefined && schemaAndPolicy.policy !== undefined;\n}\n\n/**\n * Specifies the behavior of a component that puts data in a summary.\n */\nexport interface Summarizable {\n\t/**\n\t * Field name in summary json under which this element stores its data.\n\t */\n\treadonly key: string;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t */\n\tgetAttachSummary(\n\t\tstringify: SummaryElementStringifier,\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t */\n\tsummarize(\n\t\tstringify: SummaryElementStringifier,\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\t// TODO: Change this interface (and the one in ISharedObject, if necessary) to support \"handles within handles\".\n\t// Consider the case of a document with history; the return value here currently grows unboundedly.\n\tgetGCData(fullGC?: boolean): IGarbageCollectionData;\n\n\t/**\n\t * Allows the component to perform custom loading. The storage service is scoped to this component and therefore\n\t * paths in this component will not collide with those in other components, even if they are the same string.\n\t * @param service - Storage used by the component\n\t * @param parse - Parses serialized data from storage into runtime objects for the component\n\t */\n\tload(service: IChannelStorageService, parse: SummaryElementParser): Promise<void>;\n}\n\n/**\n * Serializes the given contents into a string acceptable for storing in summaries, i.e. all\n * Fluid handles have been replaced appropriately by an IFluidSerializer\n */\nexport type SummaryElementStringifier = (contents: unknown) => string;\n\n/**\n * Parses a serialized/summarized string into an object, rehydrating any Fluid handles as necessary\n */\nexport type SummaryElementParser = (contents: string) => unknown;\n\n/**\n * Compose an {@link IChannelStorageService} which prefixes all paths before forwarding them to the original service\n */\nfunction scopeStorageService(\n\tservice: IChannelStorageService,\n\t...pathElements: string[]\n): IChannelStorageService {\n\tconst scope = `${pathElements.join(\"/\")}/`;\n\n\treturn {\n\t\tasync readBlob(path: string): Promise<ArrayBufferLike> {\n\t\t\treturn service.readBlob(`${scope}${path}`);\n\t\t},\n\t\tasync contains(path) {\n\t\t\treturn service.contains(`${scope}${path}`);\n\t\t},\n\t\tasync list(path) {\n\t\t\treturn service.list(`${scope}${path}`);\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"sharedTreeCore.js","sourceRoot":"","sources":["../../src/shared-tree-core/sharedTreeCore.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;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ACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIFluidDataStoreRuntime,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\nimport type { ISequencedDocumentMessage } from \"@fluidframework/driver-definitions/internal\";\nimport type {\n\tIExperimentalIncrementalSummaryContext,\n\tIGarbageCollectionData,\n\tISummaryTreeWithStats,\n\tITelemetryContext,\n} from \"@fluidframework/runtime-definitions/internal\";\nimport { SummaryTreeBuilder } from \"@fluidframework/runtime-utils/internal\";\nimport {\n\ttype IFluidSerializer,\n\tSharedObject,\n} from \"@fluidframework/shared-object-base/internal\";\n\nimport type { ICodecOptions, IJsonCodec } from \"../codec/index.js\";\nimport {\n\ttype ChangeFamily,\n\ttype ChangeFamilyEditor,\n\tfindAncestor,\n\ttype GraphCommit,\n\ttype RevisionTag,\n\tRevisionTagCodec,\n\ttype SchemaAndPolicy,\n\ttype SchemaPolicy,\n\ttype TaggedChange,\n\ttype TreeStoredSchemaRepository,\n} from \"../core/index.js\";\nimport {\n\ttype JsonCompatibleReadOnly,\n\tbrand,\n\tBreakable,\n\ttype WithBreakable,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"../util/index.js\";\n\nimport { getChangeReplaceType, type SharedTreeBranch } from \"./branch.js\";\nimport { EditManager, minimumPossibleSequenceNumber } from \"./editManager.js\";\nimport { makeEditManagerCodec } from \"./editManagerCodecs.js\";\nimport type { SeqNumber } from \"./editManagerFormat.js\";\nimport { EditManagerSummarizer } from \"./editManagerSummarizer.js\";\nimport { type MessageEncodingContext, makeMessageCodec } from \"./messageCodecs.js\";\nimport type { DecodedMessage } from \"./messageTypes.js\";\nimport { type ChangeEnricherReadonlyCheckout, NoOpChangeEnricher } from \"./changeEnricher.js\";\nimport type { ResubmitMachine } from \"./resubmitMachine.js\";\nimport { DefaultResubmitMachine } from \"./defaultResubmitMachine.js\";\nimport { BranchCommitEnricher } from \"./branchCommitEnricher.js\";\nimport { createChildLogger } from \"@fluidframework/telemetry-utils/internal\";\n\n// TODO: Organize this to be adjacent to persisted types.\nconst summarizablesTreeKey = \"indexes\";\n\nexport interface ExplicitCoreCodecVersions {\n\teditManager: number;\n\tmessage: number;\n}\n\nexport interface ClonableSchemaAndPolicy extends SchemaAndPolicy {\n\tschema: TreeStoredSchemaRepository;\n}\n\n/**\n * Generic shared tree, which needs to be configured with indexes, field kinds and other configuration.\n */\n@breakingClass\nexport class SharedTreeCore<TEditor extends ChangeFamilyEditor, TChange>\n\textends SharedObject\n\timplements WithBreakable\n{\n\tpublic readonly breaker: Breakable = new Breakable(\"Shared Tree\");\n\n\tprivate readonly editManager: EditManager<TEditor, TChange, ChangeFamily<TEditor, TChange>>;\n\tprivate readonly summarizables: readonly [EditManagerSummarizer<TChange>, ...Summarizable[]];\n\t/**\n\t * The sequence number that this instance is at.\n\t * This number is artificial in that it is made up by this instance as opposed to being provided by the runtime.\n\t * Is `undefined` after (and only after) this instance is attached.\n\t */\n\tprivate detachedRevision: SeqNumber | undefined = minimumPossibleSequenceNumber;\n\n\t/**\n\t * Used to edit the state of the tree. Edits will be immediately applied locally to the tree.\n\t * If there is no transaction currently ongoing, then the edits will be submitted to Fluid immediately as well.\n\t */\n\tpublic get editor(): TEditor {\n\t\treturn this.getLocalBranch().editor;\n\t}\n\n\t/**\n\t * Gets the revision at the head of the trunk.\n\t */\n\tprotected get trunkHeadRevision(): RevisionTag {\n\t\treturn this.editManager.getTrunkHead().revision;\n\t}\n\n\t/**\n\t * Used to encode/decode messages sent to/received from the Fluid runtime.\n\t *\n\t * @remarks Since there is currently only one format, this can just be cached on the class.\n\t * With more write formats active, it may make sense to keep around the \"usual\" format codec\n\t * (the one for the current persisted configuration) and resolve codecs for different versions\n\t * as necessary (e.g. an upgrade op came in, or the configuration changed within the collab window\n\t * and an op needs to be interpreted which isn't written with the current configuration).\n\t */\n\tprivate readonly messageCodec: IJsonCodec<\n\t\tDecodedMessage<TChange>,\n\t\tunknown,\n\t\tunknown,\n\t\tMessageEncodingContext\n\t>;\n\n\tprivate readonly idCompressor: IIdCompressor;\n\n\tprivate readonly resubmitMachine: ResubmitMachine<TChange>;\n\tprotected readonly commitEnricher: BranchCommitEnricher<TChange>;\n\n\tprotected readonly mintRevisionTag: () => RevisionTag;\n\n\tprivate readonly schemaAndPolicy: ClonableSchemaAndPolicy;\n\n\t/**\n\t * @param summarizables - Summarizers for all indexes used by this tree\n\t * @param changeFamily - The change family\n\t * @param editManager - The edit manager\n\t * @param id - The id of the shared object\n\t * @param runtime - The IFluidDataStoreRuntime which contains the shared object\n\t * @param attributes - Attributes of the shared object\n\t * @param telemetryContextPrefix - The property prefix for telemetry pertaining to this object. See {@link ITelemetryContext}\n\t */\n\tpublic constructor(\n\t\tsummarizables: readonly Summarizable[],\n\t\tchangeFamily: ChangeFamily<TEditor, TChange>,\n\t\toptions: ICodecOptions,\n\t\tformatOptions: ExplicitCoreCodecVersions,\n\t\t// Base class arguments\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\ttelemetryContextPrefix: string,\n\t\tschema: TreeStoredSchemaRepository,\n\t\tschemaPolicy: SchemaPolicy,\n\t\tresubmitMachine?: ResubmitMachine<TChange>,\n\t\tenricher?: ChangeEnricherReadonlyCheckout<TChange>,\n\t) {\n\t\tsuper(id, runtime, attributes, telemetryContextPrefix);\n\n\t\tthis.schemaAndPolicy = {\n\t\t\tschema,\n\t\t\tpolicy: schemaPolicy,\n\t\t};\n\n\t\tconst rebaseLogger = createChildLogger({\n\t\t\tlogger: this.logger,\n\t\t\tnamespace: \"Rebase\",\n\t\t});\n\n\t\tassert(\n\t\t\truntime.idCompressor !== undefined,\n\t\t\t0x886 /* IdCompressor must be enabled to use SharedTree */,\n\t\t);\n\t\tthis.idCompressor = runtime.idCompressor;\n\t\tthis.mintRevisionTag = () => this.idCompressor.generateCompressedId();\n\t\t/**\n\t\t * A random ID that uniquely identifies this client in the collab session.\n\t\t * This is sent alongside every op to identify which client the op originated from.\n\t\t * This is used rather than the Fluid client ID because the Fluid client ID is not stable across reconnections.\n\t\t */\n\t\tconst localSessionId = runtime.idCompressor.localSessionId;\n\t\tthis.editManager = new EditManager(\n\t\t\tchangeFamily,\n\t\t\tlocalSessionId,\n\t\t\tthis.mintRevisionTag,\n\t\t\trebaseLogger,\n\t\t);\n\n\t\tthis.editManager.localBranch.events.on(\"beforeChange\", (change) => {\n\t\t\tif (this.detachedRevision === undefined) {\n\t\t\t\t// Commit enrichment is only necessary for changes that will be submitted as ops, and changes issued while detached are not submitted.\n\t\t\t\tthis.commitEnricher.processChange(change);\n\t\t\t}\n\t\t});\n\t\tthis.editManager.localBranch.events.on(\"afterChange\", (change) => {\n\t\t\tif (\n\t\t\t\tchange.type === \"append\" ||\n\t\t\t\t(change.type === \"replace\" && getChangeReplaceType(change) === \"transactionCommit\")\n\t\t\t) {\n\t\t\t\tfor (const commit of change.newCommits) {\n\t\t\t\t\tthis.submitCommit(commit, this.schemaAndPolicy);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\n\t\tconst revisionTagCodec = new RevisionTagCodec(runtime.idCompressor);\n\t\tconst editManagerCodec = makeEditManagerCodec(\n\t\t\tthis.editManager.changeFamily.codecs,\n\t\t\trevisionTagCodec,\n\t\t\toptions,\n\t\t\tformatOptions.editManager,\n\t\t);\n\t\tthis.summarizables = [\n\t\t\tnew EditManagerSummarizer(\n\t\t\t\tthis.editManager,\n\t\t\t\teditManagerCodec,\n\t\t\t\tthis.idCompressor,\n\t\t\t\tthis.schemaAndPolicy,\n\t\t\t),\n\t\t\t...summarizables,\n\t\t];\n\t\tassert(\n\t\t\tnew Set(this.summarizables.map((e) => e.key)).size === this.summarizables.length,\n\t\t\t0x350 /* Index summary element keys must be unique */,\n\t\t);\n\n\t\tthis.messageCodec = makeMessageCodec(\n\t\t\tchangeFamily.codecs,\n\t\t\tnew RevisionTagCodec(runtime.idCompressor),\n\t\t\toptions,\n\t\t\tformatOptions.message,\n\t\t);\n\n\t\tconst changeEnricher = enricher ?? new NoOpChangeEnricher();\n\t\tthis.resubmitMachine =\n\t\t\tresubmitMachine ??\n\t\t\tnew DefaultResubmitMachine(\n\t\t\t\t(change: TaggedChange<TChange>) =>\n\t\t\t\t\tchangeFamily.rebaser.invert(change, true, this.mintRevisionTag()),\n\t\t\t\tchangeEnricher,\n\t\t\t);\n\t\tthis.commitEnricher = new BranchCommitEnricher(changeFamily.rebaser, changeEnricher);\n\t}\n\n\t// TODO: SharedObject's merging of the two summary methods into summarizeCore is not what we want here:\n\t// We might want to not subclass it, or override/reimplement most of its functionality.\n\t@throwIfBroken\n\tprotected summarizeCore(\n\t\tserializer: IFluidSerializer,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats {\n\t\tconst builder = new SummaryTreeBuilder();\n\t\tconst summarizableBuilder = new SummaryTreeBuilder();\n\t\t// Merge the summaries of all summarizables together under a single ISummaryTree\n\t\tfor (const s of this.summarizables) {\n\t\t\tsummarizableBuilder.addWithStats(\n\t\t\t\ts.key,\n\t\t\t\ts.getAttachSummary(\n\t\t\t\t\t(contents) => serializer.stringify(contents, this.handle),\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\ttelemetryContext,\n\t\t\t\t\tincrementalSummaryContext,\n\t\t\t\t),\n\t\t\t);\n\t\t}\n\n\t\tbuilder.addWithStats(summarizablesTreeKey, summarizableBuilder.getSummaryTree());\n\t\treturn builder.getSummaryTree();\n\t}\n\n\tprotected async loadCore(services: IChannelStorageService): Promise<void> {\n\t\tconst [editManagerSummarizer, ...summarizables] = this.summarizables;\n\t\tconst loadEditManager = this.loadSummarizable(editManagerSummarizer, services);\n\t\tconst loadSummarizables = summarizables.map(async (s) =>\n\t\t\tthis.loadSummarizable(s, services),\n\t\t);\n\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\t// If we are detached but loading from a summary, then we need to update our detached revision to ensure that it is ahead of all detached revisions in the summary.\n\t\t\t// First, finish loading the edit manager so that we can inspect the sequence numbers of the commits on the trunk.\n\t\t\tawait loadEditManager;\n\t\t\t// Find the most recent detached revision in the summary trunk...\n\t\t\tlet latestDetachedSequenceNumber: SeqNumber | undefined;\n\t\t\tfindAncestor(this.editManager.getTrunkHead(), (c) => {\n\t\t\t\tconst sequenceNumber = this.editManager.getSequenceNumber(c);\n\t\t\t\tif (sequenceNumber !== undefined && sequenceNumber < 0) {\n\t\t\t\t\tlatestDetachedSequenceNumber = sequenceNumber;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t\treturn false;\n\t\t\t});\n\t\t\t// ...and set our detached revision to be as it would be if we had been already created that revision.\n\t\t\tthis.detachedRevision = latestDetachedSequenceNumber ?? this.detachedRevision;\n\t\t\tawait Promise.all(loadSummarizables);\n\t\t} else {\n\t\t\tawait Promise.all([loadEditManager, ...loadSummarizables]);\n\t\t}\n\t}\n\n\tprivate async loadSummarizable(\n\t\tsummarizable: Summarizable,\n\t\tservices: IChannelStorageService,\n\t): Promise<void> {\n\t\treturn summarizable.load(\n\t\t\tscopeStorageService(services, summarizablesTreeKey, summarizable.key),\n\t\t\t(contents) => this.serializer.parse(contents),\n\t\t);\n\t}\n\n\t/**\n\t * Submits an op to the Fluid runtime containing the given commit\n\t * @param commit - the commit to submit\n\t * @returns the submitted commit. This is undefined if the underlying `SharedObject` is not attached,\n\t * and may differ from `commit` due to enrichments like detached tree refreshers.\n\t */\n\tprotected submitCommit(\n\t\tcommit: GraphCommit<TChange>,\n\t\tschemaAndPolicy: ClonableSchemaAndPolicy,\n\t\tisResubmit = false,\n\t): void {\n\t\tassert(\n\t\t\tthis.isAttached() === (this.detachedRevision === undefined),\n\t\t\t0x95a /* Detached revision should only be set when not attached */,\n\t\t);\n\n\t\tconst enrichedCommit =\n\t\t\tthis.detachedRevision === undefined && !isResubmit\n\t\t\t\t? this.commitEnricher.enrich(commit)\n\t\t\t\t: commit;\n\n\t\t// Edits submitted before the first attach are treated as sequenced because they will be included\n\t\t// in the attach summary that is uploaded to the service.\n\t\t// Until this attach workflow happens, this instance essentially behaves as a centralized data structure.\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\tconst newRevision: SeqNumber = brand((this.detachedRevision as number) + 1);\n\t\t\tthis.detachedRevision = newRevision;\n\t\t\tthis.editManager.addSequencedChange(\n\t\t\t\t{ ...enrichedCommit, sessionId: this.editManager.localSessionId },\n\t\t\t\tnewRevision,\n\t\t\t\tthis.detachedRevision,\n\t\t\t);\n\t\t\tthis.editManager.advanceMinimumSequenceNumber(newRevision, false);\n\t\t\treturn undefined;\n\t\t}\n\t\tconst message = this.messageCodec.encode(\n\t\t\t{\n\t\t\t\tcommit: enrichedCommit,\n\t\t\t\tsessionId: this.editManager.localSessionId,\n\t\t\t},\n\t\t\t{\n\t\t\t\tidCompressor: this.idCompressor,\n\t\t\t\tschema: schemaAndPolicy,\n\t\t\t},\n\t\t);\n\t\tthis.submitLocalMessage(message, {\n\t\t\t// Clone the schema to ensure that during resubmit the schema has not been mutated by later changes\n\t\t\tschema: schemaAndPolicy.schema.clone(),\n\t\t\tpolicy: schemaAndPolicy.policy,\n\t\t});\n\t\tthis.resubmitMachine.onCommitSubmitted(enrichedCommit);\n\t}\n\n\tprotected processCore(\n\t\tmessage: ISequencedDocumentMessage,\n\t\tlocal: boolean,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst { commit, sessionId } = this.messageCodec.decode(message.contents, {\n\t\t\tidCompressor: this.idCompressor,\n\t\t});\n\n\t\tthis.editManager.addSequencedChange(\n\t\t\t{ ...commit, sessionId },\n\t\t\tbrand(message.sequenceNumber),\n\t\t\tbrand(message.referenceSequenceNumber),\n\t\t);\n\t\tthis.resubmitMachine.onSequencedCommitApplied(local);\n\n\t\tthis.editManager.advanceMinimumSequenceNumber(brand(message.minimumSequenceNumber));\n\t}\n\n\t/**\n\t * @returns the head commit of the root local branch\n\t */\n\tprotected getLocalBranch(): SharedTreeBranch<TEditor, TChange> {\n\t\treturn this.editManager.localBranch;\n\t}\n\n\tprotected onDisconnect(): void {}\n\n\tprotected override didAttach(): void {\n\t\tif (this.detachedRevision !== undefined) {\n\t\t\tthis.detachedRevision = undefined;\n\t\t}\n\t}\n\n\tprotected override reSubmitCore(\n\t\tcontent: JsonCompatibleReadOnly,\n\t\tlocalOpMetadata: unknown,\n\t): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision },\n\t\t} = this.messageCodec.decode(this.serializer.decode(content), {\n\t\t\tidCompressor: this.idCompressor,\n\t\t});\n\t\tconst [commit] = this.editManager.findLocalCommit(revision);\n\t\t// If a resubmit phase is not already in progress, then this must be the first commit of a new resubmit phase.\n\t\tif (this.resubmitMachine.isInResubmitPhase === false) {\n\t\t\tconst toResubmit = this.editManager.getLocalCommits();\n\t\t\tassert(\n\t\t\t\tcommit === toResubmit[0],\n\t\t\t\t0x95d /* Resubmit phase should start with the oldest local commit */,\n\t\t\t);\n\t\t\tthis.resubmitMachine.prepareForResubmit(toResubmit);\n\t\t}\n\t\tassert(\n\t\t\tisClonableSchemaPolicy(localOpMetadata),\n\t\t\t0x95e /* Local metadata must contain schema and policy. */,\n\t\t);\n\t\tassert(\n\t\t\tthis.resubmitMachine.isInResubmitPhase !== false,\n\t\t\t0x984 /* Invalid resubmit outside of resubmit phase */,\n\t\t);\n\t\tconst enrichedCommit = this.resubmitMachine.peekNextCommit();\n\t\tthis.submitCommit(enrichedCommit, localOpMetadata, true);\n\t}\n\n\tprotected applyStashedOp(content: JsonCompatibleReadOnly): void {\n\t\t// Empty context object is passed in, as our decode function is schema-agnostic.\n\t\tconst {\n\t\t\tcommit: { revision, change },\n\t\t} = this.messageCodec.decode(content, { idCompressor: this.idCompressor });\n\t\tthis.editManager.localBranch.apply({ change, revision });\n\t}\n\n\tpublic override getGCData(fullGC?: boolean): IGarbageCollectionData {\n\t\tconst gcNodes: IGarbageCollectionData[\"gcNodes\"] = super.getGCData(fullGC).gcNodes;\n\t\tfor (const s of this.summarizables) {\n\t\t\tfor (const [id, routes] of Object.entries(s.getGCData(fullGC).gcNodes)) {\n\t\t\t\tgcNodes[id] ??= [];\n\t\t\t\tfor (const route of routes) {\n\t\t\t\t\t// Non null asserting here because we are creating an array at gcNodes[id] if it is undefined\n\t\t\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t\t\tgcNodes[id]!.push(route);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn {\n\t\t\tgcNodes,\n\t\t};\n\t}\n}\n\nfunction isClonableSchemaPolicy(\n\tmaybeSchemaPolicy: unknown,\n): maybeSchemaPolicy is ClonableSchemaAndPolicy {\n\tconst schemaAndPolicy = maybeSchemaPolicy as ClonableSchemaAndPolicy;\n\treturn schemaAndPolicy.schema !== undefined && schemaAndPolicy.policy !== undefined;\n}\n\n/**\n * Specifies the behavior of a component that puts data in a summary.\n */\nexport interface Summarizable {\n\t/**\n\t * Field name in summary json under which this element stores its data.\n\t */\n\treadonly key: string;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).getAttachSummary}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t */\n\tgetAttachSummary(\n\t\tstringify: SummaryElementStringifier,\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t\tincrementalSummaryContext?: IExperimentalIncrementalSummaryContext,\n\t): ISummaryTreeWithStats;\n\n\t/**\n\t * {@inheritDoc @fluidframework/datastore-definitions#(IChannel:interface).summarize}\n\t * @param stringify - Serializes the contents of the component (including {@link (IFluidHandle:interface)}s) for storage.\n\t */\n\tsummarize(\n\t\tstringify: SummaryElementStringifier,\n\t\tfullTree?: boolean,\n\t\ttrackState?: boolean,\n\t\ttelemetryContext?: ITelemetryContext,\n\t): Promise<ISummaryTreeWithStats>;\n\n\t/**\n\t * {@inheritDoc (ISharedObject:interface).getGCData}\n\t */\n\t// TODO: Change this interface (and the one in ISharedObject, if necessary) to support \"handles within handles\".\n\t// Consider the case of a document with history; the return value here currently grows unboundedly.\n\tgetGCData(fullGC?: boolean): IGarbageCollectionData;\n\n\t/**\n\t * Allows the component to perform custom loading. The storage service is scoped to this component and therefore\n\t * paths in this component will not collide with those in other components, even if they are the same string.\n\t * @param service - Storage used by the component\n\t * @param parse - Parses serialized data from storage into runtime objects for the component\n\t */\n\tload(service: IChannelStorageService, parse: SummaryElementParser): Promise<void>;\n}\n\n/**\n * Serializes the given contents into a string acceptable for storing in summaries, i.e. all\n * Fluid handles have been replaced appropriately by an IFluidSerializer\n */\nexport type SummaryElementStringifier = (contents: unknown) => string;\n\n/**\n * Parses a serialized/summarized string into an object, rehydrating any Fluid handles as necessary\n */\nexport type SummaryElementParser = (contents: string) => unknown;\n\n/**\n * Compose an {@link IChannelStorageService} which prefixes all paths before forwarding them to the original service\n */\nfunction scopeStorageService(\n\tservice: IChannelStorageService,\n\t...pathElements: string[]\n): IChannelStorageService {\n\tconst scope = `${pathElements.join(\"/\")}/`;\n\n\treturn {\n\t\tasync readBlob(path: string): Promise<ArrayBufferLike> {\n\t\t\treturn service.readBlob(`${scope}${path}`);\n\t\t},\n\t\tasync contains(path) {\n\t\t\treturn service.contains(`${scope}${path}`);\n\t\t},\n\t\tasync list(path) {\n\t\t\treturn service.list(`${scope}${path}`);\n\t\t},\n\t};\n}\n"]}
@@ -0,0 +1,108 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import type { IDisposable, Listenable } from "@fluidframework/core-interfaces";
6
+ /**
7
+ * Describes the result of a transaction.
8
+ * Transactions may either succeed and commit, or fail and abort.
9
+ */
10
+ export declare enum TransactionResult {
11
+ /**
12
+ * Indicates the transaction failed.
13
+ */
14
+ Abort = 0,
15
+ /**
16
+ * Indicates the transaction succeeded.
17
+ */
18
+ Commit = 1
19
+ }
20
+ /**
21
+ * A simple API for managing transactions.
22
+ */
23
+ export interface Transactor {
24
+ /**
25
+ * Start a new transaction.
26
+ * If a transaction is already in progress when this new transaction starts, then this transaction will be "nested" inside of it,
27
+ * i.e. the outer transaction will still be in progress after this new transaction is committed or aborted.
28
+ *
29
+ * @remarks - Asynchronous transactions are not supported on the root checkout,
30
+ * since it is always kept up-to-date with the latest remote edits and the results of this rebasing (which might invalidate
31
+ * the transaction) is not visible to the application author.
32
+ * Instead,
33
+ *
34
+ * 1. fork the root checkout
35
+ * 2. run the transaction on the fork
36
+ * 3. merge the fork back into the root checkout
37
+ *
38
+ * @privateRemarks - There is currently no enforcement that asynchronous transactions don't happen on the root checkout.
39
+ * AB#6488 tracks adding some enforcement to make it more clear to application authors that this is not supported.
40
+ */
41
+ start(): void;
42
+ /**
43
+ * Close this transaction by squashing its edits and committing them as a single edit.
44
+ * If this is the root checkout and there are no ongoing transactions remaining, the squashed edit will be submitted to Fluid.
45
+ */
46
+ commit(): void;
47
+ /**
48
+ * Close this transaction and revert the state of the tree to what it was before this transaction began.
49
+ */
50
+ abort(): void;
51
+ /**
52
+ * True if there is at least one transaction currently in progress on this view, otherwise false.
53
+ */
54
+ isInProgress(): boolean;
55
+ /**
56
+ * Provides events for changes in transaction progress.
57
+ */
58
+ events: Listenable<TransactionEvents>;
59
+ }
60
+ export interface TransactionEvents {
61
+ /**
62
+ * Raised just after a transaction has begun.
63
+ * @remarks When this event fires, {@link Transactor.isInProgress} will be true because the transaction has already begun.
64
+ */
65
+ started(): void;
66
+ /**
67
+ * Raised just before a transaction is aborted.
68
+ * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.
69
+ */
70
+ aborting(): void;
71
+ /**
72
+ * Raised just before a transaction is committed.
73
+ * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.
74
+ */
75
+ committing(): void;
76
+ }
77
+ /**
78
+ * A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.
79
+ * @remarks This function may return {@link OnPop | its complement} - another function that will be called when the transaction is popped from the stack.
80
+ * 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.
81
+ */
82
+ export type OnPush = () => OnPop | void;
83
+ /**
84
+ * A function that will be called when a transaction is popped from the {@link TransactionStack | stack}.
85
+ * @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.
86
+ */
87
+ export type OnPop = (result: TransactionResult) => void;
88
+ /**
89
+ * An implementation of {@link Transactor} that uses a stack to manage transactions.
90
+ * @remarks Using a stack allows transactions to nest - i.e. an inner transaction may be started while an outer transaction is already in progress.
91
+ */
92
+ export declare class TransactionStack implements Transactor, IDisposable {
93
+ #private;
94
+ get events(): Listenable<TransactionEvents>;
95
+ get disposed(): boolean;
96
+ /**
97
+ * Construct a new {@link TransactionStack}.
98
+ * @param onPush - A {@link OnPush | function} that will be called when a transaction begins.
99
+ */
100
+ constructor(onPush?: () => OnPop | void);
101
+ isInProgress(): boolean;
102
+ start(): void;
103
+ commit(): void;
104
+ abort(): void;
105
+ dispose(): void;
106
+ private ensureNotDisposed;
107
+ }
108
+ //# sourceMappingURL=transaction.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/transaction.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAG/E;;;GAGG;AACH,oBAAY,iBAAiB;IAC5B;;OAEG;IACH,KAAK,IAAA;IACL;;OAEG;IACH,MAAM,IAAA;CACN;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IAC1B;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;;OAGG;IACH,MAAM,IAAI,IAAI,CAAC;IACf;;OAEG;IACH,KAAK,IAAI,IAAI,CAAC;IACd;;OAEG;IACH,YAAY,IAAI,OAAO,CAAC;IACxB;;OAEG;IACH,MAAM,EAAE,UAAU,CAAC,iBAAiB,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,iBAAiB;IACjC;;;OAGG;IACH,OAAO,IAAI,IAAI,CAAC;IAChB;;;OAGG;IACH,QAAQ,IAAI,IAAI,CAAC;IACjB;;;OAGG;IACH,UAAU,IAAI,IAAI,CAAC;CACnB;AAED;;;;GAIG;AACH,MAAM,MAAM,MAAM,GAAG,MAAM,KAAK,GAAG,IAAI,CAAC;AAExC;;;GAGG;AACH,MAAM,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAC;AAExD;;;GAGG;AACH,qBAAa,gBAAiB,YAAW,UAAU,EAAE,WAAW;;IAK/D,IAAW,MAAM,IAAI,UAAU,CAAC,iBAAiB,CAAC,CAEjD;IAGD,IAAW,QAAQ,IAAI,OAAO,CAE7B;IAED;;;OAGG;gBACgB,MAAM,CAAC,EAAE,MAAM,KAAK,GAAG,IAAI;IAIvC,YAAY,IAAI,OAAO;IAKvB,KAAK,IAAI,IAAI;IAMb,MAAM,IAAI,IAAI;IASd,KAAK,IAAI,IAAI;IASb,OAAO,IAAI,IAAI;IAQtB,OAAO,CAAC,iBAAiB;CAKzB"}
@@ -0,0 +1,95 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
6
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
7
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
8
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
9
+ };
10
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
11
+ if (kind === "m") throw new TypeError("Private method is not writable");
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
14
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
15
+ };
16
+ var _TransactionStack_stack, _TransactionStack_onPush, _TransactionStack_events, _TransactionStack_disposed;
17
+ import { createEmitter } from "@fluid-internal/client-utils";
18
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
19
+ /**
20
+ * Describes the result of a transaction.
21
+ * Transactions may either succeed and commit, or fail and abort.
22
+ */
23
+ export var TransactionResult;
24
+ (function (TransactionResult) {
25
+ /**
26
+ * Indicates the transaction failed.
27
+ */
28
+ TransactionResult[TransactionResult["Abort"] = 0] = "Abort";
29
+ /**
30
+ * Indicates the transaction succeeded.
31
+ */
32
+ TransactionResult[TransactionResult["Commit"] = 1] = "Commit";
33
+ })(TransactionResult || (TransactionResult = {}));
34
+ /**
35
+ * An implementation of {@link Transactor} that uses a stack to manage transactions.
36
+ * @remarks Using a stack allows transactions to nest - i.e. an inner transaction may be started while an outer transaction is already in progress.
37
+ */
38
+ export class TransactionStack {
39
+ get events() {
40
+ return __classPrivateFieldGet(this, _TransactionStack_events, "f");
41
+ }
42
+ get disposed() {
43
+ return __classPrivateFieldGet(this, _TransactionStack_disposed, "f");
44
+ }
45
+ /**
46
+ * Construct a new {@link TransactionStack}.
47
+ * @param onPush - A {@link OnPush | function} that will be called when a transaction begins.
48
+ */
49
+ constructor(onPush) {
50
+ _TransactionStack_stack.set(this, []);
51
+ _TransactionStack_onPush.set(this, void 0);
52
+ _TransactionStack_events.set(this, createEmitter());
53
+ _TransactionStack_disposed.set(this, false);
54
+ __classPrivateFieldSet(this, _TransactionStack_onPush, onPush, "f");
55
+ }
56
+ isInProgress() {
57
+ this.ensureNotDisposed();
58
+ return __classPrivateFieldGet(this, _TransactionStack_stack, "f").length > 0;
59
+ }
60
+ start() {
61
+ this.ensureNotDisposed();
62
+ __classPrivateFieldGet(this, _TransactionStack_stack, "f").push(__classPrivateFieldGet(this, _TransactionStack_onPush, "f")?.call(this));
63
+ __classPrivateFieldGet(this, _TransactionStack_events, "f").emit("started");
64
+ }
65
+ commit() {
66
+ this.ensureNotDisposed();
67
+ if (!this.isInProgress()) {
68
+ throw new UsageError("No transaction to commit");
69
+ }
70
+ __classPrivateFieldGet(this, _TransactionStack_events, "f").emit("committing");
71
+ __classPrivateFieldGet(this, _TransactionStack_stack, "f").pop()?.(TransactionResult.Commit);
72
+ }
73
+ abort() {
74
+ this.ensureNotDisposed();
75
+ if (!this.isInProgress()) {
76
+ throw new UsageError("No transaction to abort");
77
+ }
78
+ __classPrivateFieldGet(this, _TransactionStack_events, "f").emit("aborting");
79
+ __classPrivateFieldGet(this, _TransactionStack_stack, "f").pop()?.(TransactionResult.Abort);
80
+ }
81
+ dispose() {
82
+ this.ensureNotDisposed();
83
+ while (this.isInProgress()) {
84
+ this.abort();
85
+ }
86
+ __classPrivateFieldSet(this, _TransactionStack_disposed, true, "f");
87
+ }
88
+ ensureNotDisposed() {
89
+ if (this.disposed) {
90
+ throw new UsageError("Transactor is disposed");
91
+ }
92
+ }
93
+ }
94
+ _TransactionStack_stack = new WeakMap(), _TransactionStack_onPush = new WeakMap(), _TransactionStack_events = new WeakMap(), _TransactionStack_disposed = new WeakMap();
95
+ //# sourceMappingURL=transaction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transaction.js","sourceRoot":"","sources":["../../src/shared-tree-core/transaction.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE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AO,CAAC,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YAC1B,MAAM,IAAI,UAAU,CAAC,yBAAyB,CAAC,CAAC;QACjD,CAAC;QACD,uBAAA,IAAI,gCAAQ,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAC9B,uBAAA,IAAI,+BAAO,CAAC,GAAG,EAAE,EAAE,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC;IAC9C,CAAC;IAEM,OAAO;QACb,IAAI,CAAC,iBAAiB,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,YAAY,EAAE,EAAE,CAAC;YAC5B,IAAI,CAAC,KAAK,EAAE,CAAC;QACd,CAAC;QACD,uBAAA,IAAI,8BAAa,IAAI,MAAA,CAAC;IACvB,CAAC;IAEO,iBAAiB;QACxB,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,UAAU,CAAC,wBAAwB,CAAC,CAAC;QAChD,CAAC;IACF,CAAC;CACD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { IDisposable, Listenable } from \"@fluidframework/core-interfaces\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * Describes the result of a transaction.\n * Transactions may either succeed and commit, or fail and abort.\n */\nexport enum TransactionResult {\n\t/**\n\t * Indicates the transaction failed.\n\t */\n\tAbort,\n\t/**\n\t * Indicates the transaction succeeded.\n\t */\n\tCommit,\n}\n\n/**\n * A simple API for managing transactions.\n */\nexport interface Transactor {\n\t/**\n\t * Start a new transaction.\n\t * If a transaction is already in progress when this new transaction starts, then this transaction will be \"nested\" inside of it,\n\t * i.e. the outer transaction will still be in progress after this new transaction is committed or aborted.\n\t *\n\t * @remarks - Asynchronous transactions are not supported on the root checkout,\n\t * since it is always kept up-to-date with the latest remote edits and the results of this rebasing (which might invalidate\n\t * the transaction) is not visible to the application author.\n\t * Instead,\n\t *\n\t * 1. fork the root checkout\n\t * 2. run the transaction on the fork\n\t * 3. merge the fork back into the root checkout\n\t *\n\t * @privateRemarks - There is currently no enforcement that asynchronous transactions don't happen on the root checkout.\n\t * AB#6488 tracks adding some enforcement to make it more clear to application authors that this is not supported.\n\t */\n\tstart(): void;\n\t/**\n\t * Close this transaction by squashing its edits and committing them as a single edit.\n\t * If this is the root checkout and there are no ongoing transactions remaining, the squashed edit will be submitted to Fluid.\n\t */\n\tcommit(): void;\n\t/**\n\t * Close this transaction and revert the state of the tree to what it was before this transaction began.\n\t */\n\tabort(): void;\n\t/**\n\t * True if there is at least one transaction currently in progress on this view, otherwise false.\n\t */\n\tisInProgress(): boolean;\n\t/**\n\t * Provides events for changes in transaction progress.\n\t */\n\tevents: Listenable<TransactionEvents>;\n}\n\nexport interface TransactionEvents {\n\t/**\n\t * Raised just after a transaction has begun.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will be true because the transaction has already begun.\n\t */\n\tstarted(): void;\n\t/**\n\t * Raised just before a transaction is aborted.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.\n\t */\n\taborting(): void;\n\t/**\n\t * Raised just before a transaction is committed.\n\t * @remarks When this event fires, {@link Transactor.isInProgress} will still be true because the transaction has not yet ended.\n\t */\n\tcommitting(): void;\n}\n\n/**\n * A function that will be called when a transaction is pushed to the {@link TransactionStack | stack}.\n * @remarks This function may return {@link OnPop | its complement} - another function that will be called when the transaction is popped from the stack.\n * 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.\n */\nexport type OnPush = () => OnPop | void;\n\n/**\n * A function that will be called when a transaction is popped from the {@link TransactionStack | stack}.\n * @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.\n */\nexport type OnPop = (result: TransactionResult) => void;\n\n/**\n * An implementation of {@link Transactor} that uses a stack to manage transactions.\n * @remarks Using a stack allows transactions to nest - i.e. an inner transaction may be started while an outer transaction is already in progress.\n */\nexport class TransactionStack implements Transactor, IDisposable {\n\treadonly #stack: (OnPop | void)[] = [];\n\treadonly #onPush?: () => OnPop | void;\n\n\treadonly #events = createEmitter<TransactionEvents>();\n\tpublic get events(): Listenable<TransactionEvents> {\n\t\treturn this.#events;\n\t}\n\n\t#disposed = false;\n\tpublic get disposed(): boolean {\n\t\treturn this.#disposed;\n\t}\n\n\t/**\n\t * Construct a new {@link TransactionStack}.\n\t * @param onPush - A {@link OnPush | function} that will be called when a transaction begins.\n\t */\n\tpublic constructor(onPush?: () => OnPop | void) {\n\t\tthis.#onPush = onPush;\n\t}\n\n\tpublic isInProgress(): boolean {\n\t\tthis.ensureNotDisposed();\n\t\treturn this.#stack.length > 0;\n\t}\n\n\tpublic start(): void {\n\t\tthis.ensureNotDisposed();\n\t\tthis.#stack.push(this.#onPush?.());\n\t\tthis.#events.emit(\"started\");\n\t}\n\n\tpublic commit(): void {\n\t\tthis.ensureNotDisposed();\n\t\tif (!this.isInProgress()) {\n\t\t\tthrow new UsageError(\"No transaction to commit\");\n\t\t}\n\t\tthis.#events.emit(\"committing\");\n\t\tthis.#stack.pop()?.(TransactionResult.Commit);\n\t}\n\n\tpublic abort(): void {\n\t\tthis.ensureNotDisposed();\n\t\tif (!this.isInProgress()) {\n\t\t\tthrow new UsageError(\"No transaction to abort\");\n\t\t}\n\t\tthis.#events.emit(\"aborting\");\n\t\tthis.#stack.pop()?.(TransactionResult.Abort);\n\t}\n\n\tpublic dispose(): void {\n\t\tthis.ensureNotDisposed();\n\t\twhile (this.isInProgress()) {\n\t\t\tthis.abort();\n\t\t}\n\t\tthis.#disposed = true;\n\t}\n\n\tprivate ensureNotDisposed(): void {\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Transactor is disposed\");\n\t\t}\n\t}\n}\n"]}
@@ -8,21 +8,16 @@ import type { ChangeEnricherReadonlyCheckout } from "./changeEnricher.js";
8
8
  * Utility for producing an enriched commit out of multiple transaction steps
9
9
  */
10
10
  export declare class TransactionEnricher<TChange> {
11
- private readonly rebaser;
12
- private readonly enricher;
13
- private readonly transactionCommits;
11
+ #private;
12
+ constructor(rebaser: ChangeRebaser<TChange>, enricher: ChangeEnricherReadonlyCheckout<TChange>);
13
+ isTransacting(): boolean;
14
+ startTransaction(): void;
14
15
  /**
15
- * The number of commits before the start of each active transaction scope.
16
- * For a stack of `n` transaction scopes, the array will contain `n` integers,
17
- * where the integer at index `i` is the number of commits made before the start of the `i`th transaction scope
18
- * (therefore, the first element in the array, if present, is always 0)
16
+ * Commits the current transaction.
17
+ * @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.
19
18
  */
20
- private readonly transactionScopesStart;
21
- constructor(rebaser: ChangeRebaser<TChange>, enricher: ChangeEnricherReadonlyCheckout<TChange>);
22
- startNewTransaction(): void;
23
- commitCurrentTransaction(): void;
24
- abortCurrentTransaction(): void;
19
+ commitTransaction(): ((revision: RevisionTag) => TChange) | undefined;
20
+ abortTransaction(): void;
25
21
  addTransactionStep(commit: GraphCommit<TChange>): void;
26
- getComposedChange(revision: RevisionTag): TChange;
27
22
  }
28
23
  //# sourceMappingURL=transactionEnricher.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactionEnricher.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/transactionEnricher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAE1E;;GAEG;AACH,qBAAa,mBAAmB,CAAC,OAAO;IACvC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA0C;IACnE,OAAO,CAAC,QAAQ,CAAC,kBAAkB,CAA8B;IACjE;;;;;OAKG;IACH,OAAO,CAAC,QAAQ,CAAC,sBAAsB,CAAgB;gBAGtD,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAC/B,QAAQ,EAAE,8BAA8B,CAAC,OAAO,CAAC;IAM3C,mBAAmB,IAAI,IAAI;IAI3B,wBAAwB,IAAI,IAAI;IAKhC,uBAAuB,IAAI,IAAI;IAM/B,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;IAStD,iBAAiB,CAAC,QAAQ,EAAE,WAAW,GAAG,OAAO;CAOxD"}
1
+ {"version":3,"file":"transactionEnricher.d.ts","sourceRoot":"","sources":["../../src/shared-tree-core/transactionEnricher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChF,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAE1E;;GAEG;AACH,qBAAa,mBAAmB,CAAC,OAAO;;gBAatC,OAAO,EAAE,aAAa,CAAC,OAAO,CAAC,EAC/B,QAAQ,EAAE,8BAA8B,CAAC,OAAO,CAAC;IAM3C,aAAa,IAAI,OAAO;IAIxB,gBAAgB,IAAI,IAAI;IAI/B;;;OAGG;IACI,iBAAiB,IAAI,CAAC,CAAC,QAAQ,EAAE,WAAW,KAAK,OAAO,CAAC,GAAG,SAAS;IAWrE,gBAAgB,IAAI,IAAI;IAMxB,kBAAkB,CAAC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,GAAG,IAAI;CAQ7D"}
@@ -2,46 +2,66 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
6
+ if (kind === "m") throw new TypeError("Private method is not writable");
7
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
8
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
9
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
10
+ };
11
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
14
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
+ };
16
+ var _TransactionEnricher_rebaser, _TransactionEnricher_enricher, _TransactionEnricher_transactionCommits, _TransactionEnricher_transactionScopesStart;
5
17
  import { assert } from "@fluidframework/core-utils/internal";
6
18
  /**
7
19
  * Utility for producing an enriched commit out of multiple transaction steps
8
20
  */
9
21
  export class TransactionEnricher {
10
22
  constructor(rebaser, enricher) {
11
- this.transactionCommits = [];
23
+ _TransactionEnricher_rebaser.set(this, void 0);
24
+ _TransactionEnricher_enricher.set(this, void 0);
25
+ _TransactionEnricher_transactionCommits.set(this, []);
12
26
  /**
13
27
  * The number of commits before the start of each active transaction scope.
14
28
  * For a stack of `n` transaction scopes, the array will contain `n` integers,
15
29
  * where the integer at index `i` is the number of commits made before the start of the `i`th transaction scope
16
30
  * (therefore, the first element in the array, if present, is always 0)
17
31
  */
18
- this.transactionScopesStart = [];
19
- this.rebaser = rebaser;
20
- this.enricher = enricher;
32
+ _TransactionEnricher_transactionScopesStart.set(this, []);
33
+ __classPrivateFieldSet(this, _TransactionEnricher_rebaser, rebaser, "f");
34
+ __classPrivateFieldSet(this, _TransactionEnricher_enricher, enricher, "f");
21
35
  }
22
- startNewTransaction() {
23
- this.transactionScopesStart.push(this.transactionCommits.length);
36
+ isTransacting() {
37
+ return __classPrivateFieldGet(this, _TransactionEnricher_transactionScopesStart, "f").length !== 0;
24
38
  }
25
- commitCurrentTransaction() {
26
- const commitsCommitted = this.transactionScopesStart.pop();
39
+ startTransaction() {
40
+ __classPrivateFieldGet(this, _TransactionEnricher_transactionScopesStart, "f").push(__classPrivateFieldGet(this, _TransactionEnricher_transactionCommits, "f").length);
41
+ }
42
+ /**
43
+ * Commits the current transaction.
44
+ * @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.
45
+ */
46
+ commitTransaction() {
47
+ const commitsCommitted = __classPrivateFieldGet(this, _TransactionEnricher_transactionScopesStart, "f").pop();
27
48
  assert(commitsCommitted !== undefined, 0x985 /* No transaction to commit */);
49
+ if (__classPrivateFieldGet(this, _TransactionEnricher_transactionScopesStart, "f").length === 0) {
50
+ const transactionCommits = __classPrivateFieldGet(this, _TransactionEnricher_transactionCommits, "f");
51
+ __classPrivateFieldSet(this, _TransactionEnricher_transactionCommits, [], "f");
52
+ return (revision) => __classPrivateFieldGet(this, _TransactionEnricher_rebaser, "f").changeRevision(__classPrivateFieldGet(this, _TransactionEnricher_rebaser, "f").compose(transactionCommits), revision);
53
+ }
28
54
  }
29
- abortCurrentTransaction() {
30
- const scopeStart = this.transactionScopesStart.pop();
55
+ abortTransaction() {
56
+ const scopeStart = __classPrivateFieldGet(this, _TransactionEnricher_transactionScopesStart, "f").pop();
31
57
  assert(scopeStart !== undefined, 0x986 /* No transaction to abort */);
32
- this.transactionCommits.length = scopeStart;
58
+ __classPrivateFieldGet(this, _TransactionEnricher_transactionCommits, "f").length = scopeStart;
33
59
  }
34
60
  addTransactionStep(commit) {
35
- assert(this.transactionScopesStart.length !== 0, 0x987 /* No transaction to add a step to */);
36
- const change = this.enricher.updateChangeEnrichments(commit.change, commit.revision);
37
- this.transactionCommits.push({ ...commit, change });
38
- }
39
- getComposedChange(revision) {
40
- assert(this.transactionScopesStart.length === 0, 0x988 /* Transaction not committed */);
41
- const squashed = this.rebaser.compose(this.transactionCommits);
42
- const tagged = this.rebaser.changeRevision(squashed, revision);
43
- this.transactionCommits.length = 0;
44
- return tagged;
61
+ assert(__classPrivateFieldGet(this, _TransactionEnricher_transactionScopesStart, "f").length !== 0, 0x987 /* No transaction to add a step to */);
62
+ const change = __classPrivateFieldGet(this, _TransactionEnricher_enricher, "f").updateChangeEnrichments(commit.change, commit.revision);
63
+ __classPrivateFieldGet(this, _TransactionEnricher_transactionCommits, "f").push({ ...commit, change });
45
64
  }
46
65
  }
66
+ _TransactionEnricher_rebaser = new WeakMap(), _TransactionEnricher_enricher = new WeakMap(), _TransactionEnricher_transactionCommits = new WeakMap(), _TransactionEnricher_transactionScopesStart = new WeakMap();
47
67
  //# sourceMappingURL=transactionEnricher.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactionEnricher.js","sourceRoot":"","sources":["../../src/shared-tree-core/transactionEnricher.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAI7D;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAY/B,YACC,OAA+B,EAC/B,QAAiD;QAXjC,uBAAkB,GAA2B,EAAE,CAAC;QACjE;;;;;WAKG;QACc,2BAAsB,GAAa,EAAE,CAAC;QAMtD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC1B,CAAC;IAEM,mBAAmB;QACzB,IAAI,CAAC,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAClE,CAAC;IAEM,wBAAwB;QAC9B,MAAM,gBAAgB,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC;QAC3D,MAAM,CAAC,gBAAgB,KAAK,SAAS,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC;IAC9E,CAAC;IAEM,uBAAuB;QAC7B,MAAM,UAAU,GAAG,IAAI,CAAC,sBAAsB,CAAC,GAAG,EAAE,CAAC;QACrD,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACtE,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,UAAU,CAAC;IAC7C,CAAC;IAEM,kBAAkB,CAAC,MAA4B;QACrD,MAAM,CACL,IAAI,CAAC,sBAAsB,CAAC,MAAM,KAAK,CAAC,EACxC,KAAK,CAAC,qCAAqC,CAC3C,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,QAAQ,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QACrF,IAAI,CAAC,kBAAkB,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACrD,CAAC;IAEM,iBAAiB,CAAC,QAAqB;QAC7C,MAAM,CAAC,IAAI,CAAC,sBAAsB,CAAC,MAAM,KAAK,CAAC,EAAE,KAAK,CAAC,+BAA+B,CAAC,CAAC;QACxF,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QAC/D,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC/D,IAAI,CAAC,kBAAkB,CAAC,MAAM,GAAG,CAAC,CAAC;QACnC,OAAO,MAAM,CAAC;IACf,CAAC;CACD","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, RevisionTag } from \"../core/index.js\";\nimport type { ChangeEnricherReadonlyCheckout } from \"./changeEnricher.js\";\n\n/**\n * Utility for producing an enriched commit out of multiple transaction steps\n */\nexport class TransactionEnricher<TChange> {\n\tprivate readonly rebaser: ChangeRebaser<TChange>;\n\tprivate readonly enricher: ChangeEnricherReadonlyCheckout<TChange>;\n\tprivate readonly transactionCommits: GraphCommit<TChange>[] = [];\n\t/**\n\t * The number of commits before the start of each active transaction scope.\n\t * For a stack of `n` transaction scopes, the array will contain `n` integers,\n\t * where the integer at index `i` is the number of commits made before the start of the `i`th transaction scope\n\t * (therefore, the first element in the array, if present, is always 0)\n\t */\n\tprivate readonly transactionScopesStart: number[] = [];\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\tpublic startNewTransaction(): void {\n\t\tthis.transactionScopesStart.push(this.transactionCommits.length);\n\t}\n\n\tpublic commitCurrentTransaction(): void {\n\t\tconst commitsCommitted = this.transactionScopesStart.pop();\n\t\tassert(commitsCommitted !== undefined, 0x985 /* No transaction to commit */);\n\t}\n\n\tpublic abortCurrentTransaction(): void {\n\t\tconst scopeStart = this.transactionScopesStart.pop();\n\t\tassert(scopeStart !== undefined, 0x986 /* No transaction to abort */);\n\t\tthis.transactionCommits.length = scopeStart;\n\t}\n\n\tpublic addTransactionStep(commit: GraphCommit<TChange>): void {\n\t\tassert(\n\t\t\tthis.transactionScopesStart.length !== 0,\n\t\t\t0x987 /* No transaction to add a step to */,\n\t\t);\n\t\tconst change = this.enricher.updateChangeEnrichments(commit.change, commit.revision);\n\t\tthis.transactionCommits.push({ ...commit, change });\n\t}\n\n\tpublic getComposedChange(revision: RevisionTag): TChange {\n\t\tassert(this.transactionScopesStart.length === 0, 0x988 /* Transaction not committed */);\n\t\tconst squashed = this.rebaser.compose(this.transactionCommits);\n\t\tconst tagged = this.rebaser.changeRevision(squashed, revision);\n\t\tthis.transactionCommits.length = 0;\n\t\treturn tagged;\n\t}\n}\n"]}
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I,mDAAwB,CAAC,GAAG,EAAE,CAAC;QACtD,MAAM,CAAC,UAAU,KAAK,SAAS,EAAE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QACtE,uBAAA,IAAI,+CAAoB,CAAC,MAAM,GAAG,UAAU,CAAC;IAC9C,CAAC;IAEM,kBAAkB,CAAC,MAA4B;QACrD,MAAM,CACL,uBAAA,IAAI,mDAAwB,CAAC,MAAM,KAAK,CAAC,EACzC,KAAK,CAAC,qCAAqC,CAC3C,CAAC;QACF,MAAM,MAAM,GAAG,uBAAA,IAAI,qCAAU,CAAC,uBAAuB,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC;QACtF,uBAAA,IAAI,+CAAoB,CAAC,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACtD,CAAC;CACD","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, RevisionTag } from \"../core/index.js\";\nimport type { ChangeEnricherReadonlyCheckout } from \"./changeEnricher.js\";\n\n/**\n * Utility for producing an enriched commit out of multiple transaction steps\n */\nexport class TransactionEnricher<TChange> {\n\treadonly #rebaser: ChangeRebaser<TChange>;\n\treadonly #enricher: ChangeEnricherReadonlyCheckout<TChange>;\n\t#transactionCommits: GraphCommit<TChange>[] = [];\n\t/**\n\t * The number of commits before the start of each active transaction scope.\n\t * For a stack of `n` transaction scopes, the array will contain `n` integers,\n\t * where the integer at index `i` is the number of commits made before the start of the `i`th transaction scope\n\t * (therefore, the first element in the array, if present, is always 0)\n\t */\n\treadonly #transactionScopesStart: number[] = [];\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\tpublic isTransacting(): boolean {\n\t\treturn this.#transactionScopesStart.length !== 0;\n\t}\n\n\tpublic startTransaction(): void {\n\t\tthis.#transactionScopesStart.push(this.#transactionCommits.length);\n\t}\n\n\t/**\n\t * Commits the current transaction.\n\t * @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.\n\t */\n\tpublic commitTransaction(): ((revision: RevisionTag) => TChange) | undefined {\n\t\tconst commitsCommitted = this.#transactionScopesStart.pop();\n\t\tassert(commitsCommitted !== undefined, 0x985 /* No transaction to commit */);\n\t\tif (this.#transactionScopesStart.length === 0) {\n\t\t\tconst transactionCommits = this.#transactionCommits;\n\t\t\tthis.#transactionCommits = [];\n\t\t\treturn (revision: RevisionTag) =>\n\t\t\t\tthis.#rebaser.changeRevision(this.#rebaser.compose(transactionCommits), revision);\n\t\t}\n\t}\n\n\tpublic abortTransaction(): void {\n\t\tconst scopeStart = this.#transactionScopesStart.pop();\n\t\tassert(scopeStart !== undefined, 0x986 /* No transaction to abort */);\n\t\tthis.#transactionCommits.length = scopeStart;\n\t}\n\n\tpublic addTransactionStep(commit: GraphCommit<TChange>): void {\n\t\tassert(\n\t\t\tthis.#transactionScopesStart.length !== 0,\n\t\t\t0x987 /* No transaction to add a step to */,\n\t\t);\n\t\tconst change = this.#enricher.updateChangeEnrichments(commit.change, commit.revision);\n\t\tthis.#transactionCommits.push({ ...commit, change });\n\t}\n}\n"]}
@@ -0,0 +1,21 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { type ImplicitFieldSchema } from "../schemaTypes.js";
6
+ import type { TreeNode } from "../core/index.js";
7
+ import type { TreeView } from "./tree.js";
8
+ import { type SimpleTreeIndex } from "./simpleTreeIndex.js";
9
+ /**
10
+ * An index that returns tree nodes given their associated identifiers.
11
+ *
12
+ * @alpha
13
+ */
14
+ export type IdentifierIndex = SimpleTreeIndex<string, TreeNode>;
15
+ /**
16
+ * Creates an {@link IdentifierIndex} for a given {@link TreeView}.
17
+ *
18
+ * @alpha
19
+ */
20
+ export declare function createIdentifierIndex<TSchema extends ImplicitFieldSchema>(view: TreeView<TSchema>): IdentifierIndex;
21
+ //# sourceMappingURL=identifierIndex.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifierIndex.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/identifierIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAa,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAEjD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAE1C,OAAO,EAAyB,KAAK,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEnF;;;;GAIG;AACH,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAMhE;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,SAAS,mBAAmB,EACxE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GACrB,eAAe,CA+BjB"}
@@ -0,0 +1,41 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
6
+ import { FieldKind } from "../schemaTypes.js";
7
+ import { ObjectNodeSchema } from "../objectNodeTypes.js";
8
+ import { walkFieldSchema } from "../walkFieldSchema.js";
9
+ import { createSimpleTreeIndex } from "./simpleTreeIndex.js";
10
+ function isStringKey(key) {
11
+ return typeof key === "string";
12
+ }
13
+ /**
14
+ * Creates an {@link IdentifierIndex} for a given {@link TreeView}.
15
+ *
16
+ * @alpha
17
+ */
18
+ export function createIdentifierIndex(view) {
19
+ // For each node schema, find which field key the identifier field is under.
20
+ // This can be done easily because identifiers are their own field kinds.
21
+ const identifierFields = new Map();
22
+ walkFieldSchema(view.schema, {
23
+ node: (schemus) => {
24
+ if (schemus instanceof ObjectNodeSchema) {
25
+ for (const [fieldKey, fieldSchema] of schemus.fields.entries()) {
26
+ if (fieldSchema.kind === FieldKind.Identifier) {
27
+ identifierFields.set(schemus.identifier, fieldKey);
28
+ break;
29
+ }
30
+ }
31
+ }
32
+ },
33
+ });
34
+ return createSimpleTreeIndex(view, (schemus) => identifierFields.get(schemus.identifier), (nodes) => {
35
+ if (nodes.length > 1) {
36
+ throw new UsageError("cannot retrieve node from index: there are multiple nodes with the same identifier");
37
+ }
38
+ return nodes[0];
39
+ }, isStringKey);
40
+ }
41
+ //# sourceMappingURL=identifierIndex.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identifierIndex.js","sourceRoot":"","sources":["../../../src/simple-tree/api/identifierIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EAAE,SAAS,EAA4B,MAAM,mBAAmB,CAAC;AAExE,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAwB,MAAM,sBAAsB,CAAC;AASnF,SAAS,WAAW,CAAC,GAAiB;IACrC,OAAO,OAAO,GAAG,KAAK,QAAQ,CAAC;AAChC,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CACpC,IAAuB;IAEvB,4EAA4E;IAC5E,yEAAyE;IACzE,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAkB,CAAC;IACnD,eAAe,CAAC,IAAI,CAAC,MAAM,EAAE;QAC5B,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE;YACjB,IAAI,OAAO,YAAY,gBAAgB,EAAE,CAAC;gBACzC,KAAK,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,IAAI,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;oBAChE,IAAI,WAAW,CAAC,IAAI,KAAK,SAAS,CAAC,UAAU,EAAE,CAAC;wBAC/C,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,QAAQ,CAAC,CAAC;wBACnD,MAAM;oBACP,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;KACD,CAAC,CAAC;IAEH,OAAO,qBAAqB,CAC3B,IAAI,EACJ,CAAC,OAAO,EAAE,EAAE,CAAC,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,CAAC,EACrD,CAAC,KAAK,EAAE,EAAE;QACT,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,UAAU,CACnB,oFAAoF,CACpF,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;IACjB,CAAC,EACD,WAAW,CACX,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport type { TreeIndexKey } from \"../../feature-libraries/index.js\";\nimport { FieldKind, type ImplicitFieldSchema } from \"../schemaTypes.js\";\nimport type { TreeNode } from \"../core/index.js\";\nimport { ObjectNodeSchema } from \"../objectNodeTypes.js\";\nimport type { TreeView } from \"./tree.js\";\nimport { walkFieldSchema } from \"../walkFieldSchema.js\";\nimport { createSimpleTreeIndex, type SimpleTreeIndex } from \"./simpleTreeIndex.js\";\n\n/**\n * An index that returns tree nodes given their associated identifiers.\n *\n * @alpha\n */\nexport type IdentifierIndex = SimpleTreeIndex<string, TreeNode>;\n\nfunction isStringKey(key: TreeIndexKey): key is string {\n\treturn typeof key === \"string\";\n}\n\n/**\n * Creates an {@link IdentifierIndex} for a given {@link TreeView}.\n *\n * @alpha\n */\nexport function createIdentifierIndex<TSchema extends ImplicitFieldSchema>(\n\tview: TreeView<TSchema>,\n): IdentifierIndex {\n\t// For each node schema, find which field key the identifier field is under.\n\t// This can be done easily because identifiers are their own field kinds.\n\tconst identifierFields = new Map<string, string>();\n\twalkFieldSchema(view.schema, {\n\t\tnode: (schemus) => {\n\t\t\tif (schemus instanceof ObjectNodeSchema) {\n\t\t\t\tfor (const [fieldKey, fieldSchema] of schemus.fields.entries()) {\n\t\t\t\t\tif (fieldSchema.kind === FieldKind.Identifier) {\n\t\t\t\t\t\tidentifierFields.set(schemus.identifier, fieldKey);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t});\n\n\treturn createSimpleTreeIndex(\n\t\tview,\n\t\t(schemus) => identifierFields.get(schemus.identifier),\n\t\t(nodes) => {\n\t\t\tif (nodes.length > 1) {\n\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\"cannot retrieve node from index: there are multiple nodes with the same identifier\",\n\t\t\t\t);\n\t\t\t}\n\n\t\t\treturn nodes[0];\n\t\t},\n\t\tisStringKey,\n\t);\n}\n"]}