@fluidframework/tree 2.12.0 → 2.13.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 (329) hide show
  1. package/CHANGELOG.md +136 -0
  2. package/api-report/tree.alpha.api.md +86 -10
  3. package/api-report/tree.beta.api.md +22 -10
  4. package/api-report/tree.legacy.alpha.api.md +22 -10
  5. package/api-report/tree.legacy.public.api.md +22 -10
  6. package/api-report/tree.public.api.md +22 -10
  7. package/dist/alpha.d.ts +11 -0
  8. package/dist/beta.d.ts +2 -0
  9. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
  10. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  11. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  12. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  13. package/dist/feature-libraries/index.d.ts +0 -1
  14. package/dist/feature-libraries/index.d.ts.map +1 -1
  15. package/dist/feature-libraries/index.js +2 -4
  16. package/dist/feature-libraries/index.js.map +1 -1
  17. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
  18. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  19. package/dist/feature-libraries/modular-schema/crossFieldQueries.js +8 -2
  20. package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  21. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
  22. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  23. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  24. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  25. package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -1
  26. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  27. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  28. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  29. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  30. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
  31. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  32. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
  33. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  34. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
  35. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  36. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  37. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  38. package/dist/feature-libraries/optional-field/optionalField.js +24 -4
  39. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  40. package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
  41. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  42. package/dist/feature-libraries/sequence-field/utils.js +14 -5
  43. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  44. package/dist/index.d.ts +2 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +2 -1
  47. package/dist/index.js.map +1 -1
  48. package/dist/legacy.d.ts +2 -0
  49. package/dist/packageVersion.d.ts +1 -1
  50. package/dist/packageVersion.js +1 -1
  51. package/dist/packageVersion.js.map +1 -1
  52. package/dist/public.d.ts +2 -0
  53. package/dist/shared-tree/index.d.ts +2 -1
  54. package/dist/shared-tree/index.d.ts.map +1 -1
  55. package/dist/shared-tree/index.js +2 -1
  56. package/dist/shared-tree/index.js.map +1 -1
  57. package/dist/shared-tree/schematizingTreeView.d.ts +10 -1
  58. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  59. package/dist/shared-tree/schematizingTreeView.js +43 -0
  60. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  61. package/dist/shared-tree/sharedTree.d.ts +6 -3
  62. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  63. package/dist/shared-tree/sharedTree.js +3 -1
  64. package/dist/shared-tree/sharedTree.js.map +1 -1
  65. package/dist/shared-tree/transactionTypes.d.ts +105 -0
  66. package/dist/shared-tree/transactionTypes.d.ts.map +1 -0
  67. package/dist/shared-tree/transactionTypes.js +13 -0
  68. package/dist/shared-tree/transactionTypes.js.map +1 -0
  69. package/dist/shared-tree/treeApi.d.ts +1 -25
  70. package/dist/shared-tree/treeApi.d.ts.map +1 -1
  71. package/dist/shared-tree/treeApi.js +4 -8
  72. package/dist/shared-tree/treeApi.js.map +1 -1
  73. package/dist/shared-tree/treeCheckout.d.ts +4 -1
  74. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  75. package/dist/shared-tree/treeCheckout.js +130 -15
  76. package/dist/shared-tree/treeCheckout.js.map +1 -1
  77. package/dist/shared-tree-core/sharedTreeCore.js +1 -1
  78. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  79. package/dist/simple-tree/api/index.d.ts +1 -0
  80. package/dist/simple-tree/api/index.d.ts.map +1 -1
  81. package/dist/simple-tree/api/index.js +3 -1
  82. package/dist/simple-tree/api/index.js.map +1 -1
  83. package/dist/simple-tree/api/jsonSchema.d.ts +6 -0
  84. package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
  85. package/dist/simple-tree/api/jsonSchema.js.map +1 -1
  86. package/dist/simple-tree/api/schemaFactory.d.ts +21 -12
  87. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  88. package/dist/simple-tree/api/schemaFactory.js +5 -2
  89. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  90. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
  91. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
  92. package/dist/simple-tree/api/schemaFactoryAlpha.js +90 -0
  93. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
  94. package/dist/simple-tree/api/simpleSchema.d.ts +5 -1
  95. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
  96. package/dist/simple-tree/api/simpleSchema.js.map +1 -1
  97. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +13 -10
  98. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  99. package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  100. package/dist/simple-tree/api/tree.d.ts +60 -0
  101. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  102. package/dist/simple-tree/api/tree.js.map +1 -1
  103. package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  104. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +11 -11
  105. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  106. package/dist/simple-tree/arrayNode.d.ts +2 -2
  107. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  108. package/dist/simple-tree/arrayNode.js +2 -1
  109. package/dist/simple-tree/arrayNode.js.map +1 -1
  110. package/dist/simple-tree/core/treeNodeSchema.d.ts +10 -6
  111. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  112. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  113. package/dist/simple-tree/index.d.ts +2 -2
  114. package/dist/simple-tree/index.d.ts.map +1 -1
  115. package/dist/simple-tree/index.js +3 -2
  116. package/dist/simple-tree/index.js.map +1 -1
  117. package/dist/simple-tree/leafNodeSchema.d.ts +5 -5
  118. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  119. package/dist/simple-tree/mapNode.d.ts +2 -2
  120. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  121. package/dist/simple-tree/mapNode.js +2 -1
  122. package/dist/simple-tree/mapNode.js.map +1 -1
  123. package/dist/simple-tree/objectNode.d.ts +2 -2
  124. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  125. package/dist/simple-tree/objectNode.js +2 -1
  126. package/dist/simple-tree/objectNode.js.map +1 -1
  127. package/dist/simple-tree/objectNodeTypes.d.ts +2 -2
  128. package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
  129. package/dist/simple-tree/objectNodeTypes.js.map +1 -1
  130. package/dist/simple-tree/schemaTypes.d.ts +47 -1
  131. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  132. package/dist/simple-tree/schemaTypes.js.map +1 -1
  133. package/dist/util/index.d.ts +2 -2
  134. package/dist/util/index.d.ts.map +1 -1
  135. package/dist/util/index.js +3 -5
  136. package/dist/util/index.js.map +1 -1
  137. package/dist/util/rangeMap.d.ts +72 -42
  138. package/dist/util/rangeMap.d.ts.map +1 -1
  139. package/dist/util/rangeMap.js +161 -151
  140. package/dist/util/rangeMap.js.map +1 -1
  141. package/dist/util/utils.d.ts +22 -1
  142. package/dist/util/utils.d.ts.map +1 -1
  143. package/dist/util/utils.js +10 -1
  144. package/dist/util/utils.js.map +1 -1
  145. package/lib/alpha.d.ts +11 -0
  146. package/lib/beta.d.ts +2 -0
  147. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
  148. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  149. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  150. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  151. package/lib/feature-libraries/index.d.ts +0 -1
  152. package/lib/feature-libraries/index.d.ts.map +1 -1
  153. package/lib/feature-libraries/index.js +0 -1
  154. package/lib/feature-libraries/index.js.map +1 -1
  155. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +1 -1
  156. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  157. package/lib/feature-libraries/modular-schema/crossFieldQueries.js +9 -3
  158. package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  159. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +12 -5
  160. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  161. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  162. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  163. package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -1
  164. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  165. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  166. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  167. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  168. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -0
  169. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  170. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +89 -25
  171. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  172. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +12 -0
  173. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  174. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  175. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  176. package/lib/feature-libraries/optional-field/optionalField.js +24 -4
  177. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  178. package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
  179. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  180. package/lib/feature-libraries/sequence-field/utils.js +14 -5
  181. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  182. package/lib/index.d.ts +2 -2
  183. package/lib/index.d.ts.map +1 -1
  184. package/lib/index.js +1 -1
  185. package/lib/index.js.map +1 -1
  186. package/lib/legacy.d.ts +2 -0
  187. package/lib/packageVersion.d.ts +1 -1
  188. package/lib/packageVersion.js +1 -1
  189. package/lib/packageVersion.js.map +1 -1
  190. package/lib/public.d.ts +2 -0
  191. package/lib/shared-tree/index.d.ts +2 -1
  192. package/lib/shared-tree/index.d.ts.map +1 -1
  193. package/lib/shared-tree/index.js +2 -1
  194. package/lib/shared-tree/index.js.map +1 -1
  195. package/lib/shared-tree/schematizingTreeView.d.ts +10 -1
  196. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  197. package/lib/shared-tree/schematizingTreeView.js +46 -3
  198. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  199. package/lib/shared-tree/sharedTree.d.ts +6 -3
  200. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  201. package/lib/shared-tree/sharedTree.js +3 -1
  202. package/lib/shared-tree/sharedTree.js.map +1 -1
  203. package/lib/shared-tree/transactionTypes.d.ts +105 -0
  204. package/lib/shared-tree/transactionTypes.d.ts.map +1 -0
  205. package/lib/shared-tree/transactionTypes.js +10 -0
  206. package/lib/shared-tree/transactionTypes.js.map +1 -0
  207. package/lib/shared-tree/treeApi.d.ts +1 -25
  208. package/lib/shared-tree/treeApi.d.ts.map +1 -1
  209. package/lib/shared-tree/treeApi.js +1 -5
  210. package/lib/shared-tree/treeApi.js.map +1 -1
  211. package/lib/shared-tree/treeCheckout.d.ts +4 -1
  212. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  213. package/lib/shared-tree/treeCheckout.js +130 -15
  214. package/lib/shared-tree/treeCheckout.js.map +1 -1
  215. package/lib/shared-tree-core/sharedTreeCore.js +1 -1
  216. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  217. package/lib/simple-tree/api/index.d.ts +1 -0
  218. package/lib/simple-tree/api/index.d.ts.map +1 -1
  219. package/lib/simple-tree/api/index.js +1 -0
  220. package/lib/simple-tree/api/index.js.map +1 -1
  221. package/lib/simple-tree/api/jsonSchema.d.ts +6 -0
  222. package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
  223. package/lib/simple-tree/api/jsonSchema.js.map +1 -1
  224. package/lib/simple-tree/api/schemaFactory.d.ts +21 -12
  225. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  226. package/lib/simple-tree/api/schemaFactory.js +5 -2
  227. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  228. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
  229. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
  230. package/lib/simple-tree/api/schemaFactoryAlpha.js +86 -0
  231. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
  232. package/lib/simple-tree/api/simpleSchema.d.ts +5 -1
  233. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
  234. package/lib/simple-tree/api/simpleSchema.js.map +1 -1
  235. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +14 -11
  236. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  237. package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  238. package/lib/simple-tree/api/tree.d.ts +60 -0
  239. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  240. package/lib/simple-tree/api/tree.js.map +1 -1
  241. package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  242. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +12 -12
  243. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  244. package/lib/simple-tree/arrayNode.d.ts +2 -2
  245. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  246. package/lib/simple-tree/arrayNode.js +2 -1
  247. package/lib/simple-tree/arrayNode.js.map +1 -1
  248. package/lib/simple-tree/core/treeNodeSchema.d.ts +10 -6
  249. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  250. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  251. package/lib/simple-tree/index.d.ts +2 -2
  252. package/lib/simple-tree/index.d.ts.map +1 -1
  253. package/lib/simple-tree/index.js +1 -1
  254. package/lib/simple-tree/index.js.map +1 -1
  255. package/lib/simple-tree/leafNodeSchema.d.ts +5 -5
  256. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  257. package/lib/simple-tree/mapNode.d.ts +2 -2
  258. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  259. package/lib/simple-tree/mapNode.js +2 -1
  260. package/lib/simple-tree/mapNode.js.map +1 -1
  261. package/lib/simple-tree/objectNode.d.ts +2 -2
  262. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  263. package/lib/simple-tree/objectNode.js +2 -1
  264. package/lib/simple-tree/objectNode.js.map +1 -1
  265. package/lib/simple-tree/objectNodeTypes.d.ts +2 -2
  266. package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
  267. package/lib/simple-tree/objectNodeTypes.js.map +1 -1
  268. package/lib/simple-tree/schemaTypes.d.ts +47 -1
  269. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  270. package/lib/simple-tree/schemaTypes.js.map +1 -1
  271. package/lib/util/index.d.ts +2 -2
  272. package/lib/util/index.d.ts.map +1 -1
  273. package/lib/util/index.js +2 -2
  274. package/lib/util/index.js.map +1 -1
  275. package/lib/util/rangeMap.d.ts +72 -42
  276. package/lib/util/rangeMap.d.ts.map +1 -1
  277. package/lib/util/rangeMap.js +159 -146
  278. package/lib/util/rangeMap.js.map +1 -1
  279. package/lib/util/utils.d.ts +22 -1
  280. package/lib/util/utils.d.ts.map +1 -1
  281. package/lib/util/utils.js +8 -0
  282. package/lib/util/utils.js.map +1 -1
  283. package/package.json +22 -22
  284. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +14 -1
  285. package/src/feature-libraries/index.ts +0 -1
  286. package/src/feature-libraries/modular-schema/crossFieldQueries.ts +9 -9
  287. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +13 -9
  288. package/src/feature-libraries/modular-schema/genericFieldKind.ts +4 -2
  289. package/src/feature-libraries/modular-schema/index.ts +1 -0
  290. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +124 -31
  291. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +12 -0
  292. package/src/feature-libraries/optional-field/optionalField.ts +34 -5
  293. package/src/feature-libraries/sequence-field/utils.ts +18 -7
  294. package/src/index.ts +11 -0
  295. package/src/packageVersion.ts +1 -1
  296. package/src/shared-tree/index.ts +12 -2
  297. package/src/shared-tree/schematizingTreeView.ts +91 -2
  298. package/src/shared-tree/sharedTree.ts +9 -4
  299. package/src/shared-tree/transactionTypes.ts +125 -0
  300. package/src/shared-tree/treeApi.ts +1 -28
  301. package/src/shared-tree/treeCheckout.ts +147 -13
  302. package/src/shared-tree-core/sharedTreeCore.ts +1 -1
  303. package/src/simple-tree/api/index.ts +1 -0
  304. package/src/simple-tree/api/jsonSchema.ts +7 -0
  305. package/src/simple-tree/api/schemaFactory.ts +33 -6
  306. package/src/simple-tree/api/schemaFactoryAlpha.ts +253 -0
  307. package/src/simple-tree/api/simpleSchema.ts +6 -1
  308. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +22 -12
  309. package/src/simple-tree/api/tree.ts +76 -4
  310. package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +19 -13
  311. package/src/simple-tree/arrayNode.ts +7 -1
  312. package/src/simple-tree/core/treeNodeSchema.ts +51 -7
  313. package/src/simple-tree/index.ts +3 -0
  314. package/src/simple-tree/mapNode.ts +7 -1
  315. package/src/simple-tree/objectNode.ts +7 -1
  316. package/src/simple-tree/objectNodeTypes.ts +4 -1
  317. package/src/simple-tree/schemaTypes.ts +50 -1
  318. package/src/util/index.ts +2 -6
  319. package/src/util/rangeMap.ts +199 -189
  320. package/src/util/utils.ts +47 -1
  321. package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
  322. package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
  323. package/dist/feature-libraries/memoizedIdRangeAllocator.js +0 -74
  324. package/dist/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
  325. package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
  326. package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
  327. package/lib/feature-libraries/memoizedIdRangeAllocator.js +0 -71
  328. package/lib/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
  329. package/src/feature-libraries/memoizedIdRangeAllocator.ts +0 -112
@@ -4,18 +4,14 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.runTransaction = exports.treeApi = exports.rollback = void 0;
7
+ exports.runTransaction = exports.treeApi = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
10
10
  const index_js_1 = require("../feature-libraries/index.js");
11
11
  const index_js_2 = require("../simple-tree/index.js");
12
12
  const schematizingTreeView_js_1 = require("./schematizingTreeView.js");
13
13
  const checkoutFlexTreeView_js_1 = require("./checkoutFlexTreeView.js");
14
- /**
15
- * A special object that signifies when a SharedTree {@link RunTransaction | transaction} should "roll back".
16
- * @public
17
- */
18
- exports.rollback = Symbol("SharedTree Transaction Rollback");
14
+ const transactionTypes_js_1 = require("./transactionTypes.js");
19
15
  /**
20
16
  * The `Tree` object holds various functions for interacting with {@link TreeNode}s.
21
17
  * @public
@@ -39,7 +35,7 @@ exports.treeApi = {
39
35
  function createRunTransaction() {
40
36
  /** A type-safe helper to add a "rollback" property (as required by the `RunTransaction` interface) to a given object */
41
37
  function defineRollbackProperty(target) {
42
- Reflect.defineProperty(target, "rollback", { value: exports.rollback });
38
+ Reflect.defineProperty(target, "rollback", { value: transactionTypes_js_1.rollback });
43
39
  return target;
44
40
  }
45
41
  return defineRollbackProperty(runTransaction.bind({}));
@@ -92,7 +88,7 @@ function runTransactionInCheckout(checkout, transaction, preconditions) {
92
88
  checkout.transaction.abort();
93
89
  throw error;
94
90
  }
95
- if (result === exports.rollback) {
91
+ if (result === transactionTypes_js_1.rollback) {
96
92
  checkout.transaction.abort();
97
93
  }
98
94
  else {
@@ -1 +1 @@
1
- {"version":3,"file":"treeApi.js","sourceRoot":"","sources":["../../src/shared-tree/treeApi.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsE;AACtE,uEAAsE;AAEtE,4DAA2D;AAC3D,sD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AAO,KAAK,EAAE,CAAC;QAChB,qHAAqH;QACrH,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;QAC7B,MAAM,KAAK,CAAC;IACb,CAAC;IAED,IAAI,MAAM,KAAK,gBAAQ,EAAE,CAAC;QACzB,QAAQ,CAAC,WAAW,CAAC,KAAK,EAAE,CAAC;IAC9B,CAAC;SAAM,CAAC;QACP,QAAQ,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { TreeStatus } from \"../feature-libraries/index.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\ttype TreeNode,\n\ttype TreeNodeApi,\n\ttype TreeView,\n\tgetOrCreateInnerNode,\n\ttreeNodeApi,\n} from \"../simple-tree/index.js\";\n\nimport { SchematizingSimpleTreeView } from \"./schematizingTreeView.js\";\nimport type { ITreeCheckout } from \"./treeCheckout.js\";\nimport { getCheckoutFlexTreeView } from \"./checkoutFlexTreeView.js\";\n\n/**\n * A special object that signifies when a SharedTree {@link RunTransaction | transaction} should \"roll back\".\n * @public\n */\nexport const rollback = Symbol(\"SharedTree Transaction Rollback\");\n\n/**\n * A function which runs a transaction in a SharedTree.\n * @privateRemarks\n * This interface exists so that the (generously) overloaded `Tree.runTransaction` function can have the \"rollback\" property hanging off of it.\n * The rollback property being available on the function itself gives users a convenient option for rolling back a transaction without having to import another symbol.\n * @sealed @public\n */\nexport interface RunTransaction {\n\t/**\n\t * The {@link rollback} object used to roll back a transaction.\n\t */\n\treadonly rollback: typeof rollback;\n\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult,\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// TODO: TreeView is invariant over the schema, so to accept any view, `any` is the only real option unless a non generic (or covariant) base type for view is introduced (which is planned).\n\t// This use of any is actually type safe as it is only used as a constraint, and the actual strongly typed view (TView) is passed to the callback.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult,\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult | typeof rollback,\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult | typeof rollback,\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode>(node: TNode, transaction: (node: TNode) => void): void;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>>(tree: TView, transaction: (root: TView[\"root\"]) => void): void;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult | typeof rollback,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult | typeof rollback,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => void,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): void;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => void,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): void;\n}\n\n/**\n * Provides various functions for interacting with {@link TreeNode}s.\n * @remarks\n * This type should only be used via the public `Tree` export.\n * @system @sealed @public\n */\nexport interface TreeApi extends TreeNodeApi {\n\t/**\n\t * Run a {@link RunTransaction | transaction}.\n\t */\n\treadonly runTransaction: RunTransaction;\n\t/**\n\t * Check if the subtree defined by `node` contains `other`.\n\t *\n\t * @returns true if `other` is an inclusive descendant of `node`, and false otherwise.\n\t * @remarks\n\t * This includes direct and indirect children:\n\t * as long as `node` is an ancestor of `other` (occurs in its parentage chain), this returns true, regardless of the number of levels of the tree between.\n\t *\n\t * `node` is considered to contain itself, so the case where `node === other` returns true.\n\t *\n\t * This is handy when checking if moving `node` into `other` would create a cycle and thus is invalid.\n\t *\n\t * This check walks the parents of `other` looking for `node`,\n\t * and thus runs in time proportional to the depth of child in the tree.\n\t */\n\tcontains(node: TreeNode, other: TreeNode): boolean;\n}\n\n/**\n * The `Tree` object holds various functions for interacting with {@link TreeNode}s.\n * @public\n */\nexport const treeApi: TreeApi = {\n\t...treeNodeApi,\n\n\trunTransaction: createRunTransaction(),\n\n\tcontains(parent: TreeNode, child: TreeNode): boolean {\n\t\tlet toCheck: TreeNode | undefined = child;\n\t\twhile (toCheck !== undefined) {\n\t\t\tif (toCheck === parent) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\ttoCheck = treeApi.parent(toCheck);\n\t\t}\n\t\treturn false;\n\t},\n};\n\n/**\n * A requirement for a SharedTree transaction to succeed.\n * @remarks Transaction constraints are useful for validating that the state of the tree meets some requirement when a transaction runs.\n * In general, when running a transaction a client can validate their tree state in whatever way they wish and decide to either proceed with the transaction or not.\n * However, they cannot know what the tree state will be when the transaction is _sequenced_.\n * There may have been any number of edits from other clients that get sequenced before the transaction is eventually sequenced.\n * Constraints provide a way to validate the tree state after the transaction has been sequenced and abort the transaction if the constraints are not met.\n * All clients will validate the constraints of a transaction when it is sequenced, so all clients will agree on whether the transaction succeeds or not.\n * @public\n */\nexport type TransactionConstraint = NodeInDocumentConstraint; // TODO: Add more constraint types here\n\n/**\n * A transaction {@link TransactionConstraint | constraint} which requires that the given node exists in the tree.\n * @remarks The node must be in the document (its {@link TreeStatus | status} must be {@link TreeStatus.InDocument | InDocument}) to qualify as \"existing\".\n * @public\n */\nexport interface NodeInDocumentConstraint {\n\treadonly type: \"nodeInDocument\";\n\treadonly node: TreeNode;\n}\n\n// TODO: Add more constraint types here\n\n/** Creates a copy of `runTransaction` with the `rollback` property added so as to satisfy the `RunTransaction` interface. */\nfunction createRunTransaction(): RunTransaction {\n\t/** A type-safe helper to add a \"rollback\" property (as required by the `RunTransaction` interface) to a given object */\n\tfunction defineRollbackProperty<T extends object>(\n\t\ttarget: T,\n\t): T & { rollback: typeof rollback } {\n\t\tReflect.defineProperty(target, \"rollback\", { value: rollback });\n\t\treturn target as T & { readonly rollback: typeof rollback };\n\t}\n\n\treturn defineRollbackProperty(runTransaction.bind({}));\n}\n\n/**\n * Run the given transaction.\n * @remarks\n * This API is not publicly exported but is exported outside of this module so that test code may unit test the `Tree.runTransaction` function directly without being restricted to its public API overloads.\n */\nexport function runTransaction<\n\tTNode extends TreeNode,\n\tTRoot extends ImplicitFieldSchema,\n\tTResult,\n>(\n\ttreeOrNode: TNode | TreeView<TRoot>,\n\ttransaction:\n\t\t| ((node: TNode) => TResult | typeof rollback)\n\t\t| ((root: TRoot) => TResult | typeof rollback),\n\tpreconditions: readonly TransactionConstraint[] = [],\n): TResult | typeof rollback {\n\tif (treeOrNode instanceof SchematizingSimpleTreeView) {\n\t\tconst t = transaction as (root: TRoot) => TResult | typeof rollback;\n\t\treturn runTransactionInCheckout(\n\t\t\ttreeOrNode.checkout,\n\t\t\t() => t(treeOrNode.root as TRoot),\n\t\t\tpreconditions,\n\t\t);\n\t} else {\n\t\tconst node = treeOrNode as TNode;\n\t\tconst t = transaction as (node: TNode) => TResult | typeof rollback;\n\t\tconst context = getOrCreateInnerNode(node).context;\n\t\tif (context.isHydrated() === false) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Transactions cannot be run on Unhydrated nodes. Transactions apply to a TreeView and Unhydrated nodes are not part of a TreeView.\",\n\t\t\t);\n\t\t}\n\t\tconst treeView = getCheckoutFlexTreeView(context);\n\t\treturn runTransactionInCheckout(treeView.checkout, () => t(node), preconditions);\n\t}\n}\n\nfunction runTransactionInCheckout<TResult>(\n\tcheckout: ITreeCheckout,\n\ttransaction: () => TResult | typeof rollback,\n\tpreconditions: readonly TransactionConstraint[],\n): TResult | typeof rollback {\n\tcheckout.transaction.start();\n\tfor (const constraint of preconditions) {\n\t\tswitch (constraint.type) {\n\t\t\tcase \"nodeInDocument\": {\n\t\t\t\tconst node = getOrCreateInnerNode(constraint.node);\n\t\t\t\tconst nodeStatus = treeApi.status(constraint.node);\n\t\t\t\tif (nodeStatus !== TreeStatus.InDocument) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Attempted to add a \"nodeInDocument\" constraint, but the node is not currently in the document. Node status: ${nodeStatus}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcheckout.editor.addNodeExistsConstraint(node.anchorNode);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tunreachableCase(constraint.type);\n\t\t}\n\t}\n\tlet result: ReturnType<typeof transaction>;\n\ttry {\n\t\tresult = transaction();\n\t} catch (error) {\n\t\t// If the transaction has an unhandled error, abort and rollback the transaction but continue to propagate the error.\n\t\tcheckout.transaction.abort();\n\t\tthrow error;\n\t}\n\n\tif (result === rollback) {\n\t\tcheckout.transaction.abort();\n\t} else {\n\t\tcheckout.transaction.commit();\n\t}\n\n\treturn result;\n}\n"]}
1
+ {"version":3,"file":"treeApi.js","sourceRoot":"","sources":["../../src/shared-tree/treeApi.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsE;AACtE,uEAAsE;AAEtE,4DAA2D;AAC3D,sDAOiC;AAEjC,uEAAuE;AAEvE,uEAAoE;AACpE,+DAA6E;AA+U7E;;;GAGG;AACU,QAAA,OAAO,GAAY;IAC/B,GAAG,sBAAW;IAEd,cAAc,EAAE,oBAAoB,EAAE;IAEtC,QAAQ,CAAC,MAAgB,EAAE,KAAe;QACzC,IAAI,OAAO,GAAy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AAC,MAAM,EAAE,CAAC;IAC/B,CAAC;IAED,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { TreeStatus } from \"../feature-libraries/index.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\ttype TreeNode,\n\ttype TreeNodeApi,\n\ttype TreeView,\n\tgetOrCreateInnerNode,\n\ttreeNodeApi,\n} from \"../simple-tree/index.js\";\n\nimport { SchematizingSimpleTreeView } from \"./schematizingTreeView.js\";\nimport type { ITreeCheckout } from \"./treeCheckout.js\";\nimport { getCheckoutFlexTreeView } from \"./checkoutFlexTreeView.js\";\nimport { rollback, type TransactionConstraint } from \"./transactionTypes.js\";\n\n/**\n * A function which runs a transaction in a SharedTree.\n * @privateRemarks\n * This interface exists so that the (generously) overloaded `Tree.runTransaction` function can have the \"rollback\" property hanging off of it.\n * The rollback property being available on the function itself gives users a convenient option for rolling back a transaction without having to import another symbol.\n * @sealed @public\n */\nexport interface RunTransaction {\n\t/**\n\t * The {@link rollback} object used to roll back a transaction.\n\t */\n\treadonly rollback: typeof rollback;\n\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult,\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// TODO: TreeView is invariant over the schema, so to accept any view, `any` is the only real option unless a non generic (or covariant) base type for view is introduced (which is planned).\n\t// This use of any is actually type safe as it is only used as a constraint, and the actual strongly typed view (TView) is passed to the callback.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult,\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult | typeof rollback,\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult | typeof rollback,\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode>(node: TNode, transaction: (node: TNode) => void): void;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>>(tree: TView, transaction: (root: TView[\"root\"]) => void): void;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode, TResult>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => TResult | typeof rollback,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * At any point during the transaction, the function may return the special {@link RunTransaction.rollback | rollback value} (`Tree.runTransaction.rollback`) to abort the transaction and discard any changes it made so far.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @returns The value returned by the inner `transaction` function.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>, TResult>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => TResult | typeof rollback,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): TResult | typeof rollback;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param node - The node that will be passed to `transaction`.\n\t * This is typically the root node of the subtree that will be modified by the transaction.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the provided `node`.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t<TNode extends TreeNode>(\n\t\tnode: TNode,\n\t\ttransaction: (node: TNode) => void,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): void;\n\t/**\n\t * Apply one or more edits to the tree as a single atomic unit.\n\t * @param tree - The tree which will be edited by the transaction\n\t * @param transaction - The function to run as the body of the transaction.\n\t * This function is passed the root of the tree.\n\t * @param preconditions - An optional list of {@link TransactionConstraint | constraints} that are checked just before the transaction begins.\n\t * If any of the constraints are not met when `runTransaction` is called, it will throw an error.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t */\n\t// See comment on previous overload about use of any here.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t<TView extends TreeView<any>>(\n\t\ttree: TView,\n\t\ttransaction: (root: TView[\"root\"]) => void,\n\t\tpreconditions?: readonly TransactionConstraint[],\n\t): void;\n}\n\n/**\n * Provides various functions for interacting with {@link TreeNode}s.\n * @remarks\n * This type should only be used via the public `Tree` export.\n * @system @sealed @public\n */\nexport interface TreeApi extends TreeNodeApi {\n\t/**\n\t * Run a {@link RunTransaction | transaction}.\n\t */\n\treadonly runTransaction: RunTransaction;\n\t/**\n\t * Check if the subtree defined by `node` contains `other`.\n\t *\n\t * @returns true if `other` is an inclusive descendant of `node`, and false otherwise.\n\t * @remarks\n\t * This includes direct and indirect children:\n\t * as long as `node` is an ancestor of `other` (occurs in its parentage chain), this returns true, regardless of the number of levels of the tree between.\n\t *\n\t * `node` is considered to contain itself, so the case where `node === other` returns true.\n\t *\n\t * This is handy when checking if moving `node` into `other` would create a cycle and thus is invalid.\n\t *\n\t * This check walks the parents of `other` looking for `node`,\n\t * and thus runs in time proportional to the depth of child in the tree.\n\t */\n\tcontains(node: TreeNode, other: TreeNode): boolean;\n}\n\n/**\n * The `Tree` object holds various functions for interacting with {@link TreeNode}s.\n * @public\n */\nexport const treeApi: TreeApi = {\n\t...treeNodeApi,\n\n\trunTransaction: createRunTransaction(),\n\n\tcontains(parent: TreeNode, child: TreeNode): boolean {\n\t\tlet toCheck: TreeNode | undefined = child;\n\t\twhile (toCheck !== undefined) {\n\t\t\tif (toCheck === parent) {\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\ttoCheck = treeApi.parent(toCheck);\n\t\t}\n\t\treturn false;\n\t},\n};\n\n// TODO: Add more constraint types here\n\n/** Creates a copy of `runTransaction` with the `rollback` property added so as to satisfy the `RunTransaction` interface. */\nfunction createRunTransaction(): RunTransaction {\n\t/** A type-safe helper to add a \"rollback\" property (as required by the `RunTransaction` interface) to a given object */\n\tfunction defineRollbackProperty<T extends object>(\n\t\ttarget: T,\n\t): T & { rollback: typeof rollback } {\n\t\tReflect.defineProperty(target, \"rollback\", { value: rollback });\n\t\treturn target as T & { readonly rollback: typeof rollback };\n\t}\n\n\treturn defineRollbackProperty(runTransaction.bind({}));\n}\n\n/**\n * Run the given transaction.\n * @remarks\n * This API is not publicly exported but is exported outside of this module so that test code may unit test the `Tree.runTransaction` function directly without being restricted to its public API overloads.\n */\nexport function runTransaction<\n\tTNode extends TreeNode,\n\tTRoot extends ImplicitFieldSchema,\n\tTResult,\n>(\n\ttreeOrNode: TNode | TreeView<TRoot>,\n\ttransaction:\n\t\t| ((node: TNode) => TResult | typeof rollback)\n\t\t| ((root: TRoot) => TResult | typeof rollback),\n\tpreconditions: readonly TransactionConstraint[] = [],\n): TResult | typeof rollback {\n\tif (treeOrNode instanceof SchematizingSimpleTreeView) {\n\t\tconst t = transaction as (root: TRoot) => TResult | typeof rollback;\n\t\treturn runTransactionInCheckout(\n\t\t\ttreeOrNode.checkout,\n\t\t\t() => t(treeOrNode.root as TRoot),\n\t\t\tpreconditions,\n\t\t);\n\t} else {\n\t\tconst node = treeOrNode as TNode;\n\t\tconst t = transaction as (node: TNode) => TResult | typeof rollback;\n\t\tconst context = getOrCreateInnerNode(node).context;\n\t\tif (context.isHydrated() === false) {\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Transactions cannot be run on Unhydrated nodes. Transactions apply to a TreeView and Unhydrated nodes are not part of a TreeView.\",\n\t\t\t);\n\t\t}\n\t\tconst treeView = getCheckoutFlexTreeView(context);\n\t\treturn runTransactionInCheckout(treeView.checkout, () => t(node), preconditions);\n\t}\n}\n\nfunction runTransactionInCheckout<TResult>(\n\tcheckout: ITreeCheckout,\n\ttransaction: () => TResult | typeof rollback,\n\tpreconditions: readonly TransactionConstraint[],\n): TResult | typeof rollback {\n\tcheckout.transaction.start();\n\tfor (const constraint of preconditions) {\n\t\tswitch (constraint.type) {\n\t\t\tcase \"nodeInDocument\": {\n\t\t\t\tconst node = getOrCreateInnerNode(constraint.node);\n\t\t\t\tconst nodeStatus = treeApi.status(constraint.node);\n\t\t\t\tif (nodeStatus !== TreeStatus.InDocument) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t`Attempted to add a \"nodeInDocument\" constraint, but the node is not currently in the document. Node status: ${nodeStatus}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tcheckout.editor.addNodeExistsConstraint(node.anchorNode);\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tunreachableCase(constraint.type);\n\t\t}\n\t}\n\tlet result: ReturnType<typeof transaction>;\n\ttry {\n\t\tresult = transaction();\n\t} catch (error) {\n\t\t// If the transaction has an unhandled error, abort and rollback the transaction but continue to propagate the error.\n\t\tcheckout.transaction.abort();\n\t\tthrow error;\n\t}\n\n\tif (result === rollback) {\n\t\tcheckout.transaction.abort();\n\t} else {\n\t\tcheckout.transaction.commit();\n\t}\n\n\treturn result;\n}\n"]}
@@ -184,6 +184,7 @@ export declare function createTreeCheckout(idCompressor: IIdCompressor, mintRevi
184
184
  chunkCompressionStrategy?: TreeCompressionStrategy;
185
185
  logger?: ITelemetryLoggerExt;
186
186
  breaker?: Breakable;
187
+ disposeForksAfterTransaction?: boolean;
187
188
  }): TreeCheckout;
188
189
  /**
189
190
  * Branch (like in a version control system) of SharedTree.
@@ -221,7 +222,9 @@ export declare class TreeCheckout implements ITreeCheckoutFork {
221
222
  /** Optional logger for telemetry. */
222
223
  private readonly logger?;
223
224
  private readonly breaker;
225
+ private readonly disposeForksAfterTransaction;
224
226
  disposed: boolean;
227
+ private readonly editLock;
225
228
  private readonly views;
226
229
  /**
227
230
  * Set of revertibles maintained for automatic disposal
@@ -243,7 +246,7 @@ export declare class TreeCheckout implements ITreeCheckoutFork {
243
246
  /** True if and only if this checkout is for a forked branch and not the "main branch" of the tree. */
244
247
  isBranch: boolean, changeFamily: ChangeFamily<SharedTreeEditBuilder, SharedTreeChange>, storedSchema: TreeStoredSchemaRepository, forest: IEditableForest, mintRevisionTag: () => RevisionTag, revisionTagCodec: RevisionTagCodec, idCompressor: IIdCompressor, removedRoots?: DetachedFieldIndex,
245
248
  /** Optional logger for telemetry. */
246
- logger?: ITelemetryLoggerExt | undefined, breaker?: Breakable);
249
+ logger?: ITelemetryLoggerExt | undefined, breaker?: Breakable, disposeForksAfterTransaction?: boolean);
247
250
  private readonly onAfterChange;
248
251
  private readonly onAncestryTrimmed;
249
252
  private withCombinedVisitor;
@@ -1 +1 @@
1
- {"version":3,"file":"treeCheckout.d.ts","sourceRoot":"","sources":["../../src/shared-tree/treeCheckout.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAE3E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAEN,KAAK,mBAAmB,EACxB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACN,KAAK,MAAM,EACX,KAAK,aAAa,EAClB,KAAK,UA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MzB,OAAO,CAAC,gBAAgB;IAmDxB,OAAO,CAAC,sBAAsB;IAsB9B;;OAEG;IACH,OAAO,CAAC,mBAAmB;IAkB3B;;;;;;;;OAQG;IACI,aAAa,CACnB,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,EACrC,EAAE,EAAE,CAAC,MAAM,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,GACjD,OAAO;IAWV,iGAAiG;IACjG,OAAO,CAAC,cAAc;CAStB"}
@@ -47,7 +47,7 @@ function createTreeCheckout(idCompressor, mintRevisionTag, revisionTagCodec, arg
47
47
  change: changeFamily.rebaser.compose([]),
48
48
  revision: "root",
49
49
  }, changeFamily, () => idCompressor.generateCompressedId());
50
- return new TreeCheckout(branch, false, changeFamily, schema, forest, mintRevisionTag, revisionTagCodec, idCompressor, args?.removedRoots, args?.logger, args?.breaker);
50
+ return new TreeCheckout(branch, false, changeFamily, schema, forest, mintRevisionTag, revisionTagCodec, idCompressor, args?.removedRoots, args?.logger, args?.breaker, args?.disposeForksAfterTransaction);
51
51
  }
52
52
  exports.createTreeCheckout = createTreeCheckout;
53
53
  /**
@@ -58,7 +58,7 @@ class TreeCheckout {
58
58
  /** True if and only if this checkout is for a forked branch and not the "main branch" of the tree. */
59
59
  isBranch, changeFamily, storedSchema, forest, mintRevisionTag, revisionTagCodec, idCompressor, removedRoots = (0, index_js_2.makeDetachedFieldIndex)("repair", revisionTagCodec, idCompressor),
60
60
  /** Optional logger for telemetry. */
61
- logger, breaker = new index_js_5.Breakable("TreeCheckout")) {
61
+ logger, breaker = new index_js_5.Breakable("TreeCheckout"), disposeForksAfterTransaction = true) {
62
62
  this.isBranch = isBranch;
63
63
  this.changeFamily = changeFamily;
64
64
  this.storedSchema = storedSchema;
@@ -69,6 +69,7 @@ class TreeCheckout {
69
69
  this.removedRoots = removedRoots;
70
70
  this.logger = logger;
71
71
  this.breaker = breaker;
72
+ this.disposeForksAfterTransaction = disposeForksAfterTransaction;
72
73
  this.disposed = false;
73
74
  this.views = new Set();
74
75
  /**
@@ -84,6 +85,7 @@ class TreeCheckout {
84
85
  _TreeCheckout_events.set(this, (0, client_utils_1.createEmitter)());
85
86
  this.events = __classPrivateFieldGet(this, _TreeCheckout_events, "f");
86
87
  this.onAfterChange = (event) => {
88
+ this.editLock.lock();
87
89
  __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("beforeBatch", event);
88
90
  if (event.change !== undefined) {
89
91
  const revision = event.type === "rebase"
@@ -121,6 +123,7 @@ class TreeCheckout {
121
123
  }
122
124
  }
123
125
  __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("afterBatch");
126
+ this.editLock.unlock();
124
127
  if (event.type === "append") {
125
128
  event.newCommits.forEach((commit) => this.validateCommit(commit));
126
129
  }
@@ -163,14 +166,9 @@ class TreeCheckout {
163
166
  const change = this.changeFamily.rebaser.changeRevision(squashedChange, revision);
164
167
  return (0, index_js_2.tagChange)(change, revision);
165
168
  }, () => {
166
- // Keep track of all the forks created during the transaction so that we can dispose them when the transaction ends.
167
- // This is a policy decision that we think is useful for the user, but it is not necessary for correctness.
168
- const forks = new Set();
169
- const onDisposeUnSubscribes = [];
170
- const onForkUnSubscribe = (0, index_js_4.onForkTransitive)(this, (fork) => {
171
- forks.add(fork);
172
- onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
173
- });
169
+ const disposeForks = this.disposeForksAfterTransaction
170
+ ? trackForksForDisposal(this)
171
+ : undefined;
174
172
  // When each transaction is started, take a snapshot of the current state of removed roots
175
173
  const removedRootsSnapshot = this.removedRoots.clone();
176
174
  return (result) => {
@@ -187,11 +185,10 @@ class TreeCheckout {
187
185
  default:
188
186
  (0, internal_1.unreachableCase)(result);
189
187
  }
190
- forks.forEach((fork) => fork.dispose());
191
- onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
192
- onForkUnSubscribe();
188
+ disposeForks?.();
193
189
  };
194
190
  }), "f");
191
+ this.editLock = new EditLock(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEditor);
195
192
  branch.events.on("afterChange", (event) => {
196
193
  // The following logic allows revertibles to be generated for the change.
197
194
  // Currently only appends (including merges and transaction commits) are supported.
@@ -307,7 +304,7 @@ class TreeCheckout {
307
304
  }
308
305
  get editor() {
309
306
  this.checkNotDisposed();
310
- return __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEditor;
307
+ return this.editLock.editor;
311
308
  }
312
309
  locate(anchor) {
313
310
  this.checkNotDisposed();
@@ -318,17 +315,19 @@ class TreeCheckout {
318
315
  }
319
316
  branch() {
320
317
  this.checkNotDisposed("The parent branch has already been disposed and can no longer create new branches.");
318
+ this.editLock.checkUnlocked("Branching");
321
319
  const anchors = new index_js_2.AnchorSet();
322
320
  const branch = __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranch.fork();
323
321
  const storedSchema = this.storedSchema.clone();
324
322
  const forest = this.forest.clone(storedSchema, anchors);
325
- const checkout = new TreeCheckout(branch, true, this.changeFamily, storedSchema, forest, this.mintRevisionTag, this.revisionTagCodec, this.idCompressor, this.removedRoots.clone(), this.logger, this.breaker);
323
+ const checkout = new TreeCheckout(branch, true, this.changeFamily, storedSchema, forest, this.mintRevisionTag, this.revisionTagCodec, this.idCompressor, this.removedRoots.clone(), this.logger, this.breaker, this.disposeForksAfterTransaction);
326
324
  __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("fork", checkout);
327
325
  return checkout;
328
326
  }
329
327
  rebase(checkout) {
330
328
  this.checkNotDisposed("The target of the branch rebase has been disposed and cannot be rebased.");
331
329
  checkout.checkNotDisposed("The source of the branch rebase has been disposed and cannot be rebased.");
330
+ this.editLock.checkUnlocked("Rebasing");
332
331
  (0, internal_1.assert)(!checkout.transaction.isInProgress(), 0x9af /* A view cannot be rebased while it has a pending transaction */);
333
332
  (0, internal_1.assert)(checkout.isBranch, 0xa5d /* The main branch cannot be rebased onto another branch. */);
334
333
  __classPrivateFieldGet(checkout, _TreeCheckout_transaction, "f").activeBranch.rebaseOnto(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranch);
@@ -340,6 +339,7 @@ class TreeCheckout {
340
339
  merge(checkout, disposeMerged = true) {
341
340
  this.checkNotDisposed("The target of the branch merge has been disposed and cannot be merged.");
342
341
  checkout.checkNotDisposed("The source of the branch merge has been disposed and cannot be merged.");
342
+ this.editLock.checkUnlocked("Merging");
343
343
  (0, internal_1.assert)(!this.transaction.isInProgress(), 0x9b0 /* Views cannot be merged into a view while it has a pending transaction */);
344
344
  while (checkout.transaction.isInProgress()) {
345
345
  checkout.transaction.commit();
@@ -355,6 +355,7 @@ class TreeCheckout {
355
355
  this.editor.schema.setStoredSchema(this.storedSchema.clone(), newSchema);
356
356
  }
357
357
  dispose() {
358
+ this.editLock.checkUnlocked("Disposing a view");
358
359
  this[index_js_5.disposeSymbol]();
359
360
  }
360
361
  [(_TreeCheckout_events = new WeakMap(), _TreeCheckout_transaction = new WeakMap(), _TreeCheckout_validatedCommits = new WeakMap(), index_js_5.disposeSymbol)]() {
@@ -493,4 +494,118 @@ exports.TreeCheckout = TreeCheckout;
493
494
  * @privateRemarks Exposed for testing purposes.
494
495
  */
495
496
  TreeCheckout.revertTelemetryEventName = "RevertRevertible";
497
+ /**
498
+ * A helper class that assists {@link TreeCheckout} in preventing functionality from being used while the tree is in the middle of being edited.
499
+ */
500
+ class EditLock {
501
+ /**
502
+ * @param editor - an editor which will be used to create a new editor that is monitored to determine if any changes are happening to the tree.
503
+ * Use {@link EditLock.editor} in place of the original editor to ensure that changes are monitored.
504
+ */
505
+ constructor(editor) {
506
+ this.locked = false;
507
+ const checkLock = () => this.checkUnlocked("Editing the tree");
508
+ this.editor = {
509
+ get schema() {
510
+ return editor.schema;
511
+ },
512
+ valueField(...fieldArgs) {
513
+ const valueField = editor.valueField(...fieldArgs);
514
+ return {
515
+ set(...editArgs) {
516
+ checkLock();
517
+ valueField.set(...editArgs);
518
+ },
519
+ };
520
+ },
521
+ optionalField(...fieldArgs) {
522
+ const optionalField = editor.optionalField(...fieldArgs);
523
+ return {
524
+ set(...editArgs) {
525
+ checkLock();
526
+ optionalField.set(...editArgs);
527
+ },
528
+ };
529
+ },
530
+ sequenceField(...fieldArgs) {
531
+ const sequenceField = editor.sequenceField(...fieldArgs);
532
+ return {
533
+ insert(...editArgs) {
534
+ checkLock();
535
+ sequenceField.insert(...editArgs);
536
+ },
537
+ remove(...editArgs) {
538
+ checkLock();
539
+ sequenceField.remove(...editArgs);
540
+ },
541
+ };
542
+ },
543
+ move(...moveArgs) {
544
+ checkLock();
545
+ editor.move(...moveArgs);
546
+ },
547
+ addNodeExistsConstraint(path) {
548
+ editor.addNodeExistsConstraint(path);
549
+ },
550
+ addNodeExistsConstraintOnRevert(path) {
551
+ editor.addNodeExistsConstraintOnRevert(path);
552
+ },
553
+ };
554
+ }
555
+ /**
556
+ * Prevent further changes from being made to {@link EditLock.editor} until {@link EditLock.unlock} is called.
557
+ * @remarks May only be called when the lock is not already locked.
558
+ */
559
+ lock() {
560
+ if (this.locked) {
561
+ debugger;
562
+ }
563
+ (0, internal_1.assert)(!this.locked, 0xaa7 /* Checkout has already been locked */);
564
+ this.locked = true;
565
+ }
566
+ /**
567
+ * Throws an error if the lock is currently locked.
568
+ * @param action - The current action being performed by the user.
569
+ * This must start with a capital letter, as it shows up as the first part of the error message and we want it to look nice.
570
+ */
571
+ checkUnlocked(action) {
572
+ if (this.locked) {
573
+ // These type assertions ensure that the event name strings used here match the actual event names
574
+ const nodeChanged = "nodeChanged";
575
+ const treeChanged = "treeChanged";
576
+ throw new internal_2.UsageError(`${action} is forbidden during a ${nodeChanged} or ${treeChanged} event`);
577
+ }
578
+ }
579
+ /**
580
+ * Allow changes to be made to {@link EditLock.editor} again.
581
+ * @remarks May only be called when the lock is currently locked.
582
+ */
583
+ unlock() {
584
+ (0, internal_1.assert)(this.locked, 0xaa8 /* Checkout has not been locked */);
585
+ this.locked = false;
586
+ }
587
+ }
588
+ /**
589
+ * Keeps track of all new forks created until the returned function is invoked, which will dispose all of those for.
590
+ * The returned function may only be called once.
591
+ *
592
+ * @param checkout - The tree checkout for which you want to monitor forks for disposal.
593
+ * @returns a function which can be called to dispose all of the tracked forks.
594
+ */
595
+ function trackForksForDisposal(checkout) {
596
+ const forks = new Set();
597
+ const onDisposeUnSubscribes = [];
598
+ const onForkUnSubscribe = (0, index_js_4.onForkTransitive)(checkout, (fork) => {
599
+ forks.add(fork);
600
+ onDisposeUnSubscribes.push(fork.events.on("dispose", () => forks.delete(fork)));
601
+ });
602
+ let disposed = false;
603
+ return () => {
604
+ (0, internal_1.assert)(!disposed, 0xaa9 /* Forks may only be disposed once */);
605
+ forks.forEach((fork) => fork.dispose());
606
+ onDisposeUnSubscribes.forEach((unsubscribe) => unsubscribe());
607
+ onForkUnSubscribe();
608
+ disposed = true;
609
+ };
610
+ }
496
611
  //# sourceMappingURL=treeCheckout.js.map