@fluidframework/tree 2.1.0-281041 → 2.1.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 (315) hide show
  1. package/.vscode/Tree.code-workspace +2 -1
  2. package/CHANGELOG.md +38 -0
  3. package/README.md +6 -6
  4. package/api-report/tree.alpha.api.md +1 -1
  5. package/api-report/tree.beta.api.md +1 -1
  6. package/api-report/tree.public.api.md +1 -1
  7. package/dist/core/forest/editableForest.d.ts.map +1 -1
  8. package/dist/core/forest/editableForest.js +4 -2
  9. package/dist/core/forest/editableForest.js.map +1 -1
  10. package/dist/core/tree/anchorSet.d.ts +1 -0
  11. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  12. package/dist/core/tree/anchorSet.js +13 -0
  13. package/dist/core/tree/anchorSet.js.map +1 -1
  14. package/dist/core/tree/detachedFieldIndex.d.ts +48 -11
  15. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  16. package/dist/core/tree/detachedFieldIndex.js +144 -20
  17. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  18. package/dist/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  19. package/dist/core/tree/detachedFieldIndexCodec.js +13 -4
  20. package/dist/core/tree/detachedFieldIndexCodec.js.map +1 -1
  21. package/dist/core/tree/detachedFieldIndexFormat.d.ts +1 -1
  22. package/dist/core/tree/detachedFieldIndexFormat.d.ts.map +1 -1
  23. package/dist/core/tree/detachedFieldIndexFormat.js.map +1 -1
  24. package/dist/core/tree/detachedFieldIndexTypes.d.ts +39 -4
  25. package/dist/core/tree/detachedFieldIndexTypes.d.ts.map +1 -1
  26. package/dist/core/tree/detachedFieldIndexTypes.js.map +1 -1
  27. package/dist/core/tree/index.d.ts +2 -1
  28. package/dist/core/tree/index.d.ts.map +1 -1
  29. package/dist/core/tree/index.js.map +1 -1
  30. package/dist/core/tree/visitDelta.d.ts +3 -1
  31. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  32. package/dist/core/tree/visitDelta.js +31 -15
  33. package/dist/core/tree/visitDelta.js.map +1 -1
  34. package/dist/core/tree/visitorUtils.d.ts +3 -3
  35. package/dist/core/tree/visitorUtils.d.ts.map +1 -1
  36. package/dist/core/tree/visitorUtils.js +4 -4
  37. package/dist/core/tree/visitorUtils.js.map +1 -1
  38. package/dist/feature-libraries/editableTreeBinder.js +1 -1
  39. package/dist/feature-libraries/editableTreeBinder.js.map +1 -1
  40. package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts +1 -8
  41. package/dist/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
  42. package/dist/feature-libraries/flex-map-tree/mapTreeNode.js +0 -52
  43. package/dist/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
  44. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +1 -13
  45. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  46. package/dist/feature-libraries/flex-tree/flexTreeTypes.js +0 -2
  47. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  48. package/dist/feature-libraries/flex-tree/index.d.ts +2 -1
  49. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  50. package/dist/feature-libraries/flex-tree/index.js +5 -1
  51. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  52. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +1 -2
  53. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  54. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  55. package/dist/feature-libraries/flex-tree/lazyField.d.ts +1 -2
  56. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  57. package/dist/feature-libraries/flex-tree/lazyField.js +10 -18
  58. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  59. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +1 -4
  60. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  61. package/dist/feature-libraries/flex-tree/lazyNode.js +0 -27
  62. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  63. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  64. package/dist/feature-libraries/forest-summary/forestSummarizer.js +1 -1
  65. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  66. package/dist/feature-libraries/index.d.ts +1 -1
  67. package/dist/feature-libraries/index.d.ts.map +1 -1
  68. package/dist/feature-libraries/index.js +4 -1
  69. package/dist/feature-libraries/index.js.map +1 -1
  70. package/dist/feature-libraries/modular-schema/discrepancies.js +3 -3
  71. package/dist/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  72. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +1 -1
  73. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  74. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  75. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +14 -17
  76. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  77. package/dist/feature-libraries/object-forest/objectForest.d.ts +3 -2
  78. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  79. package/dist/feature-libraries/object-forest/objectForest.js +5 -4
  80. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  81. package/dist/packageVersion.d.ts +1 -1
  82. package/dist/packageVersion.d.ts.map +1 -1
  83. package/dist/packageVersion.js +1 -1
  84. package/dist/packageVersion.js.map +1 -1
  85. package/dist/shared-tree/sharedTree.d.ts +5 -1
  86. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  87. package/dist/shared-tree/sharedTree.js +8 -1
  88. package/dist/shared-tree/sharedTree.js.map +1 -1
  89. package/dist/shared-tree/sharedTreeChangeEnricher.js +1 -1
  90. package/dist/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  91. package/dist/shared-tree/treeApi.js +1 -1
  92. package/dist/shared-tree/treeApi.js.map +1 -1
  93. package/dist/shared-tree/treeCheckout.d.ts +10 -1
  94. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  95. package/dist/shared-tree/treeCheckout.js +47 -4
  96. package/dist/shared-tree/treeCheckout.js.map +1 -1
  97. package/dist/shared-tree/treeView.d.ts.map +1 -1
  98. package/dist/shared-tree/treeView.js +7 -3
  99. package/dist/shared-tree/treeView.js.map +1 -1
  100. package/dist/shared-tree-core/branch.d.ts +6 -0
  101. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  102. package/dist/shared-tree-core/branch.js +2 -0
  103. package/dist/shared-tree-core/branch.js.map +1 -1
  104. package/dist/shared-tree-core/sharedTreeCore.d.ts +4 -0
  105. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  106. package/dist/shared-tree-core/sharedTreeCore.js +6 -0
  107. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  108. package/dist/simple-tree/arrayNode.js +1 -1
  109. package/dist/simple-tree/arrayNode.js.map +1 -1
  110. package/dist/simple-tree/index.d.ts +3 -3
  111. package/dist/simple-tree/index.d.ts.map +1 -1
  112. package/dist/simple-tree/index.js +2 -1
  113. package/dist/simple-tree/index.js.map +1 -1
  114. package/dist/simple-tree/proxies.d.ts.map +1 -1
  115. package/dist/simple-tree/proxies.js +7 -21
  116. package/dist/simple-tree/proxies.js.map +1 -1
  117. package/dist/simple-tree/proxyBinding.d.ts +4 -0
  118. package/dist/simple-tree/proxyBinding.d.ts.map +1 -1
  119. package/dist/simple-tree/proxyBinding.js +23 -1
  120. package/dist/simple-tree/proxyBinding.js.map +1 -1
  121. package/dist/simple-tree/tree.d.ts.map +1 -1
  122. package/dist/simple-tree/tree.js +1 -1
  123. package/dist/simple-tree/tree.js.map +1 -1
  124. package/dist/simple-tree/treeNodeApi.d.ts +2 -75
  125. package/dist/simple-tree/treeNodeApi.d.ts.map +1 -1
  126. package/dist/simple-tree/treeNodeApi.js +7 -15
  127. package/dist/simple-tree/treeNodeApi.js.map +1 -1
  128. package/dist/simple-tree/treeNodeKernel.d.ts +26 -0
  129. package/dist/simple-tree/treeNodeKernel.d.ts.map +1 -0
  130. package/dist/simple-tree/treeNodeKernel.js +83 -0
  131. package/dist/simple-tree/treeNodeKernel.js.map +1 -0
  132. package/dist/simple-tree/types.d.ts +73 -0
  133. package/dist/simple-tree/types.d.ts.map +1 -1
  134. package/dist/simple-tree/types.js +89 -1
  135. package/dist/simple-tree/types.js.map +1 -1
  136. package/dist/util/breakable.js +1 -1
  137. package/dist/util/breakable.js.map +1 -1
  138. package/dist/util/index.d.ts +1 -1
  139. package/dist/util/index.d.ts.map +1 -1
  140. package/dist/util/index.js.map +1 -1
  141. package/lib/core/forest/editableForest.d.ts.map +1 -1
  142. package/lib/core/forest/editableForest.js +4 -2
  143. package/lib/core/forest/editableForest.js.map +1 -1
  144. package/lib/core/tree/anchorSet.d.ts +1 -0
  145. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  146. package/lib/core/tree/anchorSet.js +13 -0
  147. package/lib/core/tree/anchorSet.js.map +1 -1
  148. package/lib/core/tree/detachedFieldIndex.d.ts +48 -11
  149. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  150. package/lib/core/tree/detachedFieldIndex.js +145 -21
  151. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  152. package/lib/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  153. package/lib/core/tree/detachedFieldIndexCodec.js +13 -4
  154. package/lib/core/tree/detachedFieldIndexCodec.js.map +1 -1
  155. package/lib/core/tree/detachedFieldIndexFormat.d.ts +1 -1
  156. package/lib/core/tree/detachedFieldIndexFormat.d.ts.map +1 -1
  157. package/lib/core/tree/detachedFieldIndexFormat.js.map +1 -1
  158. package/lib/core/tree/detachedFieldIndexTypes.d.ts +39 -4
  159. package/lib/core/tree/detachedFieldIndexTypes.d.ts.map +1 -1
  160. package/lib/core/tree/detachedFieldIndexTypes.js.map +1 -1
  161. package/lib/core/tree/index.d.ts +2 -1
  162. package/lib/core/tree/index.d.ts.map +1 -1
  163. package/lib/core/tree/index.js.map +1 -1
  164. package/lib/core/tree/visitDelta.d.ts +3 -1
  165. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  166. package/lib/core/tree/visitDelta.js +31 -15
  167. package/lib/core/tree/visitDelta.js.map +1 -1
  168. package/lib/core/tree/visitorUtils.d.ts +3 -3
  169. package/lib/core/tree/visitorUtils.d.ts.map +1 -1
  170. package/lib/core/tree/visitorUtils.js +4 -4
  171. package/lib/core/tree/visitorUtils.js.map +1 -1
  172. package/lib/feature-libraries/editableTreeBinder.js +1 -1
  173. package/lib/feature-libraries/editableTreeBinder.js.map +1 -1
  174. package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts +1 -8
  175. package/lib/feature-libraries/flex-map-tree/mapTreeNode.d.ts.map +1 -1
  176. package/lib/feature-libraries/flex-map-tree/mapTreeNode.js +2 -54
  177. package/lib/feature-libraries/flex-map-tree/mapTreeNode.js.map +1 -1
  178. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +1 -13
  179. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  180. package/lib/feature-libraries/flex-tree/flexTreeTypes.js +0 -2
  181. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  182. package/lib/feature-libraries/flex-tree/index.d.ts +2 -1
  183. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  184. package/lib/feature-libraries/flex-tree/index.js +2 -1
  185. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  186. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +1 -2
  187. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  188. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  189. package/lib/feature-libraries/flex-tree/lazyField.d.ts +1 -2
  190. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  191. package/lib/feature-libraries/flex-tree/lazyField.js +12 -20
  192. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  193. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +1 -4
  194. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  195. package/lib/feature-libraries/flex-tree/lazyNode.js +3 -30
  196. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  197. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  198. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -1
  199. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  200. package/lib/feature-libraries/index.d.ts +1 -1
  201. package/lib/feature-libraries/index.d.ts.map +1 -1
  202. package/lib/feature-libraries/index.js +1 -1
  203. package/lib/feature-libraries/index.js.map +1 -1
  204. package/lib/feature-libraries/modular-schema/discrepancies.js +3 -3
  205. package/lib/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  206. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +1 -1
  207. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  208. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  209. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +14 -17
  210. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  211. package/lib/feature-libraries/object-forest/objectForest.d.ts +3 -2
  212. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  213. package/lib/feature-libraries/object-forest/objectForest.js +5 -4
  214. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  215. package/lib/packageVersion.d.ts +1 -1
  216. package/lib/packageVersion.d.ts.map +1 -1
  217. package/lib/packageVersion.js +1 -1
  218. package/lib/packageVersion.js.map +1 -1
  219. package/lib/shared-tree/sharedTree.d.ts +5 -1
  220. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  221. package/lib/shared-tree/sharedTree.js +8 -1
  222. package/lib/shared-tree/sharedTree.js.map +1 -1
  223. package/lib/shared-tree/sharedTreeChangeEnricher.js +1 -1
  224. package/lib/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  225. package/lib/shared-tree/treeApi.js +1 -1
  226. package/lib/shared-tree/treeApi.js.map +1 -1
  227. package/lib/shared-tree/treeCheckout.d.ts +10 -1
  228. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  229. package/lib/shared-tree/treeCheckout.js +47 -4
  230. package/lib/shared-tree/treeCheckout.js.map +1 -1
  231. package/lib/shared-tree/treeView.d.ts.map +1 -1
  232. package/lib/shared-tree/treeView.js +4 -0
  233. package/lib/shared-tree/treeView.js.map +1 -1
  234. package/lib/shared-tree-core/branch.d.ts +6 -0
  235. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  236. package/lib/shared-tree-core/branch.js +2 -0
  237. package/lib/shared-tree-core/branch.js.map +1 -1
  238. package/lib/shared-tree-core/sharedTreeCore.d.ts +4 -0
  239. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  240. package/lib/shared-tree-core/sharedTreeCore.js +6 -0
  241. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  242. package/lib/simple-tree/arrayNode.js +2 -2
  243. package/lib/simple-tree/arrayNode.js.map +1 -1
  244. package/lib/simple-tree/index.d.ts +3 -3
  245. package/lib/simple-tree/index.d.ts.map +1 -1
  246. package/lib/simple-tree/index.js +1 -1
  247. package/lib/simple-tree/index.js.map +1 -1
  248. package/lib/simple-tree/proxies.d.ts.map +1 -1
  249. package/lib/simple-tree/proxies.js +7 -21
  250. package/lib/simple-tree/proxies.js.map +1 -1
  251. package/lib/simple-tree/proxyBinding.d.ts +4 -0
  252. package/lib/simple-tree/proxyBinding.d.ts.map +1 -1
  253. package/lib/simple-tree/proxyBinding.js +19 -0
  254. package/lib/simple-tree/proxyBinding.js.map +1 -1
  255. package/lib/simple-tree/tree.d.ts.map +1 -1
  256. package/lib/simple-tree/tree.js +1 -1
  257. package/lib/simple-tree/tree.js.map +1 -1
  258. package/lib/simple-tree/treeNodeApi.d.ts +2 -75
  259. package/lib/simple-tree/treeNodeApi.d.ts.map +1 -1
  260. package/lib/simple-tree/treeNodeApi.js +9 -17
  261. package/lib/simple-tree/treeNodeApi.js.map +1 -1
  262. package/lib/simple-tree/treeNodeKernel.d.ts +26 -0
  263. package/lib/simple-tree/treeNodeKernel.d.ts.map +1 -0
  264. package/lib/simple-tree/treeNodeKernel.js +79 -0
  265. package/lib/simple-tree/treeNodeKernel.js.map +1 -0
  266. package/lib/simple-tree/types.d.ts +73 -0
  267. package/lib/simple-tree/types.d.ts.map +1 -1
  268. package/lib/simple-tree/types.js +90 -2
  269. package/lib/simple-tree/types.js.map +1 -1
  270. package/lib/util/breakable.js +1 -1
  271. package/lib/util/breakable.js.map +1 -1
  272. package/lib/util/index.d.ts +1 -1
  273. package/lib/util/index.d.ts.map +1 -1
  274. package/lib/util/index.js.map +1 -1
  275. package/package.json +22 -22
  276. package/src/core/forest/editableForest.ts +10 -2
  277. package/src/core/tree/anchorSet.ts +14 -0
  278. package/src/core/tree/detachedFieldIndex.ts +217 -35
  279. package/src/core/tree/detachedFieldIndexCodec.ts +17 -8
  280. package/src/core/tree/detachedFieldIndexFormat.ts +1 -1
  281. package/src/core/tree/detachedFieldIndexTypes.ts +41 -5
  282. package/src/core/tree/index.ts +2 -1
  283. package/src/core/tree/visitDelta.ts +57 -16
  284. package/src/core/tree/visitorUtils.ts +7 -4
  285. package/src/feature-libraries/editableTreeBinder.ts +1 -1
  286. package/src/feature-libraries/flex-map-tree/mapTreeNode.ts +1 -65
  287. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +0 -19
  288. package/src/feature-libraries/flex-tree/index.ts +7 -1
  289. package/src/feature-libraries/flex-tree/lazyEntity.ts +0 -3
  290. package/src/feature-libraries/flex-tree/lazyField.ts +14 -26
  291. package/src/feature-libraries/flex-tree/lazyNode.ts +1 -42
  292. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -0
  293. package/src/feature-libraries/index.ts +3 -0
  294. package/src/feature-libraries/modular-schema/discrepancies.ts +3 -3
  295. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +1 -1
  296. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +22 -20
  297. package/src/feature-libraries/object-forest/objectForest.ts +7 -3
  298. package/src/packageVersion.ts +1 -1
  299. package/src/shared-tree/sharedTree.ts +8 -1
  300. package/src/shared-tree/sharedTreeChangeEnricher.ts +1 -1
  301. package/src/shared-tree/treeApi.ts +1 -1
  302. package/src/shared-tree/treeCheckout.ts +56 -5
  303. package/src/shared-tree/treeView.ts +5 -0
  304. package/src/shared-tree-core/branch.ts +9 -0
  305. package/src/shared-tree-core/sharedTreeCore.ts +7 -0
  306. package/src/simple-tree/arrayNode.ts +2 -2
  307. package/src/simple-tree/index.ts +3 -3
  308. package/src/simple-tree/proxies.ts +8 -29
  309. package/src/simple-tree/proxyBinding.ts +23 -0
  310. package/src/simple-tree/tree.ts +4 -1
  311. package/src/simple-tree/treeNodeApi.ts +14 -96
  312. package/src/simple-tree/treeNodeKernel.ts +91 -0
  313. package/src/simple-tree/types.ts +233 -2
  314. package/src/util/breakable.ts +1 -1
  315. package/src/util/index.ts +1 -0
@@ -15,6 +15,79 @@ import { type FlexTreeNode, type MapTreeNode } from "../feature-libraries/index.
15
15
  * @public
16
16
  */
17
17
  export type Unhydrated<T> = T;
18
+ /**
19
+ * A collection of events that can be emitted by a {@link TreeNode}.
20
+ *
21
+ * @privateRemarks
22
+ * TODO: add a way to subscribe to a specific field (for nodeChanged and treeChanged).
23
+ * Probably have object node and map node specific APIs for this.
24
+ *
25
+ * TODO: ensure that subscription API for fields aligns with API for subscribing to the root.
26
+ *
27
+ * TODO: add more wider area (avoid needing tons of nodeChanged registration) events for use-cases other than treeChanged.
28
+ * Some ideas:
29
+ *
30
+ * - treeChanged, but with some subtrees/fields/paths excluded
31
+ * - helper to batch several nodeChanged calls to a treeChanged scope
32
+ * - parent change (ex: registration on the parent field for a specific index: maybe allow it for a range. Ex: node event takes optional field and optional index range?)
33
+ * - new content inserted into subtree. Either provide event for this and/or enough info to treeChanged to find and search the new sub-trees.
34
+ * Add separate (non event related) API to efficiently scan tree for given set of types (using low level cursor and schema based filtering)
35
+ * to allow efficiently searching for new content (and initial content) of a given type.
36
+ *
37
+ * @sealed @public
38
+ */
39
+ export interface TreeChangeEvents {
40
+ /**
41
+ * Emitted by a node after a batch of changes has been applied to the tree, if a change affected the node, where a
42
+ * change is:
43
+ *
44
+ * - For an object node, when the value of one of its properties changes (i.e., the property's value is set
45
+ * to something else, including `undefined`).
46
+ *
47
+ * - For an array node, when an element is added, removed, or moved.
48
+ *
49
+ * - For a map node, when an entry is added, updated, or removed.
50
+ *
51
+ * @remarks
52
+ * This event is not emitted when:
53
+ *
54
+ * - Properties of a child node change. Notably, updates to an array node or a map node (like adding or removing
55
+ * elements/entries) will emit this event on the array/map node itself, but not on the node that contains the
56
+ * array/map node as one of its properties.
57
+ *
58
+ * - The node is moved to a different location in the tree or removed from the tree.
59
+ * In this case the event is emitted on the _parent_ node, not the node itself.
60
+ *
61
+ * For remote edits, this event is not guaranteed to occur in the same order or quantity that it did in
62
+ * the client that made the original edit.
63
+ *
64
+ * When it is emitted, the tree is guaranteed to be in-schema.
65
+ *
66
+ * @privateRemarks
67
+ * This event occurs whenever the apparent contents of the node instance change, regardless of what caused the change.
68
+ * For example, it will fire when the local client reassigns a child, when part of a remote edit is applied to the
69
+ * node, or when the node has to be updated due to resolution of a merge conflict
70
+ * (for example a previously applied local change might be undone, then reapplied differently or not at all).
71
+ */
72
+ nodeChanged(): void;
73
+ /**
74
+ * Emitted by a node after a batch of changes has been applied to the tree, when something changed anywhere in the
75
+ * subtree rooted at it.
76
+ *
77
+ * @remarks
78
+ * This event is not emitted when the node itself is moved to a different location in the tree or removed from the tree.
79
+ * In that case it is emitted on the _parent_ node, not the node itself.
80
+ *
81
+ * The node itself is part of the subtree, so this event will be emitted even if the only changes are to the properties
82
+ * of the node itself.
83
+ *
84
+ * For remote edits, this event is not guaranteed to occur in the same order or quantity that it did in
85
+ * the client that made the original edit.
86
+ *
87
+ * When it is emitted, the tree is guaranteed to be in-schema.
88
+ */
89
+ treeChanged(): void;
90
+ }
18
91
  /**
19
92
  * A non-{@link NodeKind.Leaf|leaf} SharedTree node. Includes objects, arrays, and maps.
20
93
  *
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/simple-tree/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGlE,OAAO,EAEN,KAAK,cAAc,EACnB,KAAK,QAAQ,EACb,cAAc,EACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,WAAW,EAGhB,MAAM,+BAA+B,CAAC;AASvC;;;;;;;;GAQG;AACH,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,8BAAsB,QAAS,YAAW,QAAQ;;IA6BjD;;;;OAIG;IACH,aAAoB,CAAC,cAAc,CAAC,IAAI,MAAM,CAAC;IAE/C;;;;;;OAMG;WACW,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,QAAQ;IAErE;;;;;;OAMG;WACW,CAAC,MAAM,CAAC,WAAW,CAAC,CACjC,OAAO,SAAS,QAAQ,MACvB,GAAG,IAAI,EAAE,GAAG,EAAE,KACV,QAAQ,EACZ,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAAC,OAAO,CAAC;IAahE,SAAS;CAKT;AAED;;;;;GAKG;AAEH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAS9E;AAED;;;;;;;GAOG;AACH,8BAAsB,aAAa,CAAC,MA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AAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,KAAK,EAAE,YAAY,GACjB,aAAa,CAAC,CAAC,CAAC;IAInB;;OAEG;IACH,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAC9B,IAAI,EAAE,OAAO,aAAa,CAAC,CAAC,CAAC,EAC7B,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,EAC1B,KAAK,EAAE,CAAC,GACN,WAAW;IAId;;;OAGG;IACH,SAAS,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,aAAa,CAAC,CAAC,CAAC,GAAG,IAAI;IAErE;;;;;;;;;;;;;;;;;OAiBG;IACH,SAAS,CAAC,MAAM,CAAC,iBAAiB,EAAE,eAAe,GAAG,SAAS,GAAG,SAAS,CAAa;IAExF;;OAEG;WACW,eAAe,CAAC,IAAI,EAAE,OAAO,aAAa,GAAG,cAAc,GAAG,eAAe;gBAoCxE,KAAK,EAAE,MAAM,GAAG,gBAAgB;CAkCnD;AAID;;;;;;;;;;GAUG;AACH,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,WAAW,EAAE,OAAO,aAAa,GAAG,cAAc,CAAC;IAC5D,kBAAkB,EAAE,OAAO,CAAC;CAC5B;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,gBAChB,SAAQ,UAAU,CAAC,uCAAuC,CAAC;CAAG;AAE/D,wBAAgB,cAAc,CAAC,IAAI,EAAE,gBAAgB,GAAG,YAAY,CAGnE"}
@@ -2,6 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
+ var _a;
5
6
  var _TreeNode_brand;
6
7
  import { assert } from "@fluidframework/core-utils/internal";
7
8
  import { NodeKind, typeNameSymbol, } from "./schemaTypes.js";
@@ -11,7 +12,7 @@ import { isTreeNode } from "./proxies.js";
11
12
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
12
13
  import { getFlexSchema } from "./toFlexSchema.js";
13
14
  import { fail } from "../util/index.js";
14
- import { setFlexNode } from "./proxyBinding.js";
15
+ import { getFlexNode, createKernel, setFlexNode } from "./proxyBinding.js";
15
16
  import { tryGetSchema } from "./treeNodeApi.js";
16
17
  /**
17
18
  * A non-{@link NodeKind.Leaf|leaf} SharedTree node. Includes objects, arrays, and maps.
@@ -145,7 +146,7 @@ export class TreeNodeValid extends TreeNode {
145
146
  }
146
147
  assert(schemaBase.constructorCached === undefined, 0x962 /* overwriting wrong cache */);
147
148
  schemaBase.constructorCached = { constructor: this, oneTimeInitialized: false };
148
- assert(this.constructorCached === schemaBase.constructorCached, "Inheritance should work");
149
+ assert(this.constructorCached === schemaBase.constructorCached, 0x9b5 /* Inheritance should work */);
149
150
  return this.constructorCached;
150
151
  }
151
152
  else if (this.constructorCached.constructor === this) {
@@ -172,6 +173,7 @@ export class TreeNodeValid extends TreeNode {
172
173
  : schema.buildRawNode(this, input);
173
174
  assert(tryGetSimpleNodeSchema(node.schema) === schema, 0x83b /* building node with wrong schema */);
174
175
  const result = schema.prepareInstance(this, node);
176
+ createKernel(result);
175
177
  setFlexNode(result, node);
176
178
  return result;
177
179
  }
@@ -201,4 +203,90 @@ export function toFlexTreeNode(node) {
201
203
  assert(isFlexTreeNode(node), 0x963 /* Invalid InternalTreeNode */);
202
204
  return node;
203
205
  }
206
+ // #region NodeJS custom inspect for TreeNodes.
207
+ /**
208
+ * Used to customize "inspect" behavior in NodeJS.
209
+ * See https://nodejs.org/api/util.html#utilinspectcustom for details.
210
+ *
211
+ * VS-Code's debugger also uses this to inspect objects,
212
+ * see https://github.com/microsoft/vscode-js-debug/blob/64df2686c92bac402909dee5c3c389bbb7a81f6d/src/adapter/templates/getStringyProps.ts#L11 for details.
213
+ */
214
+ const customInspectSymbol = Symbol.for("nodejs.util.inspect.custom");
215
+ /**
216
+ * Node inspecting function for use with {@link customInspectSymbol}.
217
+ */
218
+ function inspectNodeFunction(depth, options, inspect) {
219
+ // TODO: replicated from tryGetSchema to avoid cycle.
220
+ // This case could be optimized, for example by placing the simple schema in a symbol on tree nodes.
221
+ const schema = tryGetSimpleNodeSchema(getFlexNode(this).schema);
222
+ const title = `${schema.name}: ${NodeKind[schema.kind]} Node (${schema.identifier})`;
223
+ if (depth < 2) {
224
+ const short = shortContent(this);
225
+ if (short !== undefined) {
226
+ return `${title} ${short}`;
227
+ }
228
+ return title;
229
+ }
230
+ const content = `${title} ${JSON.stringify(this)}`;
231
+ return content;
232
+ }
233
+ /**
234
+ * If the node has no items, a short JSON string for it.
235
+ */
236
+ function shortContent(node) {
237
+ if (Object.values(node).length === 0) {
238
+ return JSON.stringify(node);
239
+ }
240
+ return undefined;
241
+ }
242
+ /**
243
+ * Add inherited non-enumerable symbol for NodeJS inspection to all nodes.
244
+ *
245
+ * See {@link customInspectSymbol}.
246
+ */
247
+ Object.defineProperty(TreeNodeValid.prototype, customInspectSymbol, {
248
+ value: inspectNodeFunction,
249
+ enumerable: false,
250
+ });
251
+ // #endregion
252
+ // #region Browser custom debug format for TreeNodes
253
+ // This section has side-effects, so including it in this file ensures its loaded whenever TreeNodes could exist.
254
+ // Supported in at least Chrome and FireFox, more details at https://firefox-source-docs.mozilla.org/devtools-user/custom_formatters/index.html
255
+ // For this to work the browser's dev tools generally have to "Enable custom formatters".
256
+ // This formatter is inspired by https://github.com/andrewdavey/immutable-devtools/blob/master/src/createFormatters.js which provides a similar formatter for the immutable.js library.
257
+ const globals = typeof window === "undefined" ? globalThis : window;
258
+ const formatters = ((_a = globals).devtoolsFormatters ?? (_a.devtoolsFormatters = []));
259
+ const nodeFormatter = {
260
+ header(object, config) {
261
+ if (isTreeNode(object)) {
262
+ return ["span", `${inspectNodeFunction.call(object, 1)}`];
263
+ }
264
+ return null;
265
+ },
266
+ body(object, config) {
267
+ const children = [];
268
+ for (const [key, value] of Object.entries(object)) {
269
+ children.push(["li", ["span", `${key}: `], formattedReference(value)]);
270
+ }
271
+ // TODO:
272
+ // for array nodes, this isn't great since (at least in FireFox) the list items show up with a prefixed number starting from 1.
273
+ // This looks messy when followed by the array index.
274
+ // Find a way to hide the list index.
275
+ // { style: 'list-style-type: none` } did not seem to work.
276
+ return ["ol", ...children];
277
+ },
278
+ hasBody(object, config) {
279
+ return shortContent(object) === undefined;
280
+ },
281
+ };
282
+ function formattedReference(object, config) {
283
+ if (typeof object === "undefined") {
284
+ return ["span", "undefined"];
285
+ }
286
+ else if (object === "null") {
287
+ return ["span", "null"];
288
+ }
289
+ return ["object", { object, config }];
290
+ }
291
+ formatters.push(nodeFormatter);
204
292
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/simple-tree/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EACN,QAAQ,EAGR,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,cAAc,EACd,SAAS,GACT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAahD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAgB,QAAQ;IA0DtB,MAAM,CAAC,mCAAC,MAAM,CAAC,WAAW,EAAC,CAA8B,KAAc;QAC7E,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,MAAM,KAAK,SAAS,IAAI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MAAM,CAAC,eAAe,EAAE,CAAC;QACvC,IAAI,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC;YAC/B,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;YACzC,MAAM,CACL,sBAAsB,CAAC,UAAU,CAAC,KAAK,MAAM,EAC7C,KAAK,CAAC,0CAA0C,CAChD,CAAC;YACF,MAAM,CAAC,YAAY,EAAE,CAAC;YACtB,KAAK,CAAC,kBAAkB,GAAG,IAAI,CAAC;QACjC,CAAC;QAED,IAAI,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,sFAAsF;YACtF,MAAM,IAAI,UAAU,CACnB,qjBAAqjB,CACrjB,CAAC;QACH,CAAC;QAED,MAAM,IAAI,GAAiB,cAAc,CAAC,KAAK,CAAC;YAC/C,CAAC,CAAC,KAAK;YACP,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACpC,MAAM,CACL,sBAAsB,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,MAAM,EAC9C,KAAK,CAAC,qCAAqC,CAC3C,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;QAClD,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QAC1B,OAAO,MAAM,CAAC;IACf,CAAC;;AA3FD;;;;;;;;;;;;;;;;;GAiBG;AACc,+BAAiB,GAA4C,SAAS,CAAC;AA2EzF,gJAAgJ;AAChJ,SAAS,CAAC,aAAa,CAAC,CAAC;AA6BzB,MAAM,UAAU,cAAc,CAAC,IAAsB;IACpD,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACnE,OAAO,IAAI,CAAC;AACb,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tNodeKind,\n\ttype TreeNodeSchema,\n\ttype WithType,\n\ttypeNameSymbol,\n} from \"./schemaTypes.js\";\nimport {\n\ttype FlexTreeNode,\n\ttype MapTreeNode,\n\tisFlexTreeNode,\n\tmarkEager,\n} from \"../feature-libraries/index.js\";\nimport { tryGetSimpleNodeSchema } from \"./schemaCaching.js\";\nimport { isTreeNode } from \"./proxies.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { getFlexSchema } from \"./toFlexSchema.js\";\nimport { fail } from \"../util/index.js\";\nimport { setFlexNode } from \"./proxyBinding.js\";\nimport { tryGetSchema } from \"./treeNodeApi.js\";\n\n/**\n * Type alias to document which values are un-hydrated.\n *\n * Un-hydrated values are nodes produced from schema's create functions that haven't been inserted into a tree yet.\n *\n * Since un-hydrated nodes become hydrated when inserted, strong typing can't be used to distinguish them.\n * This no-op wrapper is used instead.\n * @public\n */\nexport type Unhydrated<T> = T;\n\n/**\n * A non-{@link NodeKind.Leaf|leaf} SharedTree node. Includes objects, arrays, and maps.\n *\n * @remarks\n * Base type which all nodes implement.\n *\n * This can be used as a type to indicate/document values which should be tree nodes.\n * Runtime use of this class object (for example when used with `instanceof` or extending it), is not currently supported.\n *\n * Instances of tree nodes must be created by opening an existing document, inserting values into the document,\n * or by using the constructors and create functions of {@link TreeNodeSchema} produced by {@link SchemaFactory}.\n * @privateRemarks\n * This is a class not an interface to enable stricter type checking (see {@link TreeNode.#brand})\n * and some runtime enforcement of schema class policy (see the the validation in the constructor).\n * This class is however only `type` exported not value exported, preventing the class object from being used,\n * similar to how interfaces work.\n *\n * Not all node implementations include this in their prototype chain (some hide it with a proxy),\n * and thus cause the default/built in `instanceof` to return false despite our type checking and all other APIs treating them as TreeNodes.\n * This class provides a custom `Symbol.hasInstance` to fix `instanceof` for this class and all classes extending it.\n * For now the type-only export prevents use of `instanceof` on this class (but allows it in subclasses like schema classes).\n * @sealed @public\n */\nexport abstract class TreeNode implements WithType {\n\t/**\n\t * This is added to prevent TypeScript from implicitly allowing non-TreeNode types to be used as TreeNodes.\n\t * @remarks\n\t * This field forces TypeScript to use nominal instead of structural typing,\n\t * preventing compiler error messages and tools like \"add missing properties\"\n\t * from adding the [type] field as a solution when using a non-TreeNode object where a TreeNode is required.\n\t * Instead TreeNodes must be created through the appropriate APIs, see the documentation on {@link TreeNode} for details.\n\t *\n\t * @privateRemarks\n\t * This is a JavaScript private field, so is not accessible from outside this class.\n\t * This prevents it from having name collisions with object fields.\n\t * Since this is private, the type of this field is stripped in the d.ts file.\n\t * To get matching type checking within and from outside the package, the least informative type (`unknown`) is used.\n\t * To avoid this having any runtime impact, the field is uninitialized.\n\t *\n\t * Making this field optional results in different type checking within this project than outside of it, since the d.ts file drops the optional aspect of the field.\n\t * This is extra confusing since since the tests get in-project typing for intellisense and separate project checking at build time.\n\t * To avoid all this mess, this field is required, not optional.\n\t *\n\t * Another option would be to use a symbol (possibly as a private field).\n\t * That approach ran into some strange difficulties causing SchemaFactory to fail to compile, and was not investigated further.\n\t *\n\t * The [type] symbol provides a lot of the value this private brand does, but is not all of it:\n\t * someone could manually (or via Intellisense auto-implement completion, or in response to a type error)\n\t * make an object literal with the [type] field and pass it off as a node: this private brand prevents that.\n\t */\n\treadonly #brand!: unknown;\n\n\t/**\n\t * Adds a type symbol for stronger typing.\n\t * @privateRemarks\n\t * Subclasses provide more specific strings for this to get strong typing of otherwise type compatible nodes.\n\t */\n\tpublic abstract get [typeNameSymbol](): string;\n\n\t/**\n\t * Provides `instanceof` support for testing if a value is a `TreeNode`.\n\t * @remarks\n\t * For more options, like including leaf values or narrowing to collections of schema, use `is` or `schema` from {@link TreeNodeApi}.\n\t * @privateRemarks\n\t * Due to type-only export, this functionality is not available outside the package.\n\t */\n\tpublic static [Symbol.hasInstance](value: unknown): value is TreeNode;\n\n\t/**\n\t * Provides `instanceof` support for all schema classes with public constructors.\n\t * @remarks\n\t * For more options, like including leaf values or narrowing to collections of schema, use `is` or `schema` from {@link TreeNodeApi}.\n\t * @privateRemarks\n\t * Despite type-only export, this functionality is available outside the package since it is inherited by subclasses.\n\t */\n\tpublic static [Symbol.hasInstance]<\n\t\tTSchema extends abstract new (\n\t\t\t...args: any[]\n\t\t) => TreeNode,\n\t>(this: TSchema, value: unknown): value is InstanceType<TSchema>;\n\n\tpublic static [Symbol.hasInstance](this: { prototype: object }, value: unknown): boolean {\n\t\tconst schema = tryGetSchema(value);\n\n\t\tif (schema === undefined || schema.kind === NodeKind.Leaf) {\n\t\t\treturn false;\n\t\t}\n\n\t\tassert(\"prototype\" in schema, 0x98a /* expected class based schema */);\n\t\treturn inPrototypeChain(schema.prototype, this.prototype);\n\t}\n\n\tprotected constructor() {\n\t\tif (!inPrototypeChain(Reflect.getPrototypeOf(this), TreeNodeValid.prototype)) {\n\t\t\tthrow new UsageError(\"TreeNodes must extend schema classes created by SchemaFactory\");\n\t\t}\n\t}\n}\n\n/**\n * Check if the prototype derived's prototype chain contains `base`.\n * @param derived - prototype to check\n * @param base - prototype to search for\n * @returns true iff `base` is in the prototype chain starting at `derived`.\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport function inPrototypeChain(derived: object | null, base: object): boolean {\n\tlet checking = derived;\n\twhile (checking !== null) {\n\t\tif (base === checking) {\n\t\t\treturn true;\n\t\t}\n\t\tchecking = Reflect.getPrototypeOf(checking);\n\t}\n\treturn false;\n}\n\n/**\n * Class which all {@link TreeNode}s must extend.\n * Since this is not exported, it allows robust detection of attempts to create TreeNodes which do not go through SchemaFactory which is the only place which exposes classes that extend this.\n *\n * This has static members which schema classes can override to provide schema specific functionality.\n * These static members are only intended to be used / overridden by code within this package, and are used by the various node kinds.\n * Access to these static members has to be done via `this.constructor.staticMember` to support the overrides, and thus can only be used in the constructor, after the base constructor has been invoked.\n */\nexport abstract class TreeNodeValid<TInput> extends TreeNode {\n\t/**\n\t * Schema classes can override this to control what happens at the end of the constructor.\n\t * The return value from this is returned from the constructor, allowing substituting a proxy if desired.\n\t *\n\t * This is not simply done in the derived constructor to enable:\n\t * - this class to access the value which is being returned before it's returned from the constructor.\n\t * - the derived class to be provided the input `FlexTreeNode` without relying on a field on the node to hold it.\n\t */\n\tprotected static prepareInstance<T>(\n\t\tthis: typeof TreeNodeValid<T>,\n\t\tinstance: TreeNodeValid<T>,\n\t\tinput: FlexTreeNode,\n\t): TreeNodeValid<T> {\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Schema classes must override to provide an implementation of RawTreeNode construction.\n\t */\n\tprotected static buildRawNode<T>(\n\t\tthis: typeof TreeNodeValid<T>,\n\t\tinstance: TreeNodeValid<T>,\n\t\tinput: T,\n\t): MapTreeNode {\n\t\treturn fail(\"Schema must override buildRawNode\");\n\t}\n\n\t/**\n\t * Schema classes can override to provide a callback that is called once when the first node is constructed.\n\t * This is a good place to perform extra validation and cache schema derived data needed for the implementation of the node.\n\t */\n\tprotected static oneTimeSetup<T>(this: typeof TreeNodeValid<T>): void {}\n\n\t/**\n\t * The most derived constructor (the one invoked with the `new` operator, not a parent class constructor invoked with as `super`) used to construct an instance of this type.\n\t * @remarks\n\t * Captured when an instance is constructed.\n\t *\n\t * Used to ensure that some derived class (which must override this member, defaulting it to `undefined`) is only instantiated with a single \"most derived\" class (the constructor actually invoked the the user with `new`).\n\t *\n\t * Typically this is override in the class that statically implements {@link TreeNodeSchema} to enforce that all nodes using that schema use the same class and not different subclasses of it.\n\t *\n\t * Also used to detect if oneTimeSetup has run.\n\t *\n\t * @privateRemarks\n\t * This defaults to \"default\", which is used to trigger an error if not overridden in the derived class.\n\t *\n\t * The value of this on TreeNodeValid must only be overridden by base classes and never modified.\n\t * Ways to enforce this immutability prevent it from being overridden,\n\t * so code modifying constructorCached should be extra careful to avoid accidentally modifying the base/inherited value.\n\t */\n\tprotected static constructorCached: MostDerivedData | \"default\" | undefined = \"default\";\n\n\t/**\n\t * Indicate that `this` is the most derived version of a schema, and thus the only one allowed to be used (other than by being subclassed a single time).\n\t */\n\tpublic static markMostDerived(this: typeof TreeNodeValid & TreeNodeSchema): MostDerivedData {\n\t\tassert(this.constructorCached !== \"default\", 0x95f /* invalid schema class */);\n\n\t\tif (this.constructorCached === undefined) {\n\t\t\t// Set the constructorCached on the layer of the prototype chain that declared it.\n\t\t\t// This is necessary to ensure there is only one subclass of that type used:\n\t\t\t// if constructorCached was simply set on `schema`,\n\t\t\t// then a base classes between `schema` (exclusive) and where `constructorCached` is set (inclusive) and other subclasses of them\n\t\t\t// would not see the stored `constructorCached`, and the validation above against multiple derived classes would not work.\n\n\t\t\t// This is not just an alias of `this`, but a reference to the item in the prototype chain being walked, which happens to start at `this`.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\t\tlet schemaBase: typeof TreeNodeValid = this;\n\t\t\twhile (!Object.prototype.hasOwnProperty.call(schemaBase, \"constructorCached\")) {\n\t\t\t\tschemaBase = Reflect.getPrototypeOf(schemaBase) as typeof TreeNodeValid;\n\t\t\t}\n\t\t\tassert(schemaBase.constructorCached === undefined, 0x962 /* overwriting wrong cache */);\n\t\t\tschemaBase.constructorCached = { constructor: this, oneTimeInitialized: false };\n\t\t\tassert(\n\t\t\t\tthis.constructorCached === schemaBase.constructorCached,\n\t\t\t\t\"Inheritance should work\",\n\t\t\t);\n\t\t\treturn this.constructorCached;\n\t\t} else if (this.constructorCached.constructor === this) {\n\t\t\treturn this.constructorCached;\n\t\t}\n\n\t\tthrow new UsageError(\n\t\t\t`Two schema classes were used (${this.name} and ${\n\t\t\t\tthis.constructorCached.constructor.name\n\t\t\t}) which derived from the same SchemaFactory generated class (${JSON.stringify(\n\t\t\t\tthis.identifier,\n\t\t\t)}). This is invalid.`,\n\t\t);\n\t}\n\n\tpublic constructor(input: TInput | InternalTreeNode) {\n\t\tsuper();\n\t\tconst schema = this.constructor as typeof TreeNodeValid & TreeNodeSchema;\n\t\tconst cache = schema.markMostDerived();\n\t\tif (!cache.oneTimeInitialized) {\n\t\t\tconst flexSchema = getFlexSchema(schema);\n\t\t\tassert(\n\t\t\t\ttryGetSimpleNodeSchema(flexSchema) === schema,\n\t\t\t\t0x961 /* Schema class not properly configured */,\n\t\t\t);\n\t\t\tschema.oneTimeSetup();\n\t\t\tcache.oneTimeInitialized = true;\n\t\t}\n\n\t\tif (isTreeNode(input)) {\n\t\t\t// TODO: update this once we have better support for deep-copying and move operations.\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Existing nodes may not be used as the constructor parameter for a new node. The existing node may be used directly instead of creating a new one, used as a child of the new node (if it has not yet been inserted into the tree). If the desired result is copying the provided node, it must be deep copied (since any child node would be parented under both the new and old nodes). Currently no API is provided to make deep copies, but it can be done manually with object spreads - for example `new Foo({...oldFoo})` will work if all fields of `oldFoo` are leaf nodes.\",\n\t\t\t);\n\t\t}\n\n\t\tconst node: FlexTreeNode = isFlexTreeNode(input)\n\t\t\t? input\n\t\t\t: schema.buildRawNode(this, input);\n\t\tassert(\n\t\t\ttryGetSimpleNodeSchema(node.schema) === schema,\n\t\t\t0x83b /* building node with wrong schema */,\n\t\t);\n\n\t\tconst result = schema.prepareInstance(this, node);\n\t\tsetFlexNode(result, node);\n\t\treturn result;\n\t}\n}\n// Class objects are functions (callable), so we need a strong way to distinguish between `schema` and `() => schema` when used as a `LazyItem`.\nmarkEager(TreeNodeValid);\n\n/**\n * Data cached about the most derived type in a schema's class hierarchy.\n * @remarks\n * The most derived type is the only one allowed to be referenced by other schema or constructed as a node.\n * It has to be discovered lazily (when a node is constructed or when a {@link TreeViewConfiguration} is made),\n * since JavaScript provides no way to find derived classes, or inject static class initialization time logic into base classes.\n * Additionally since schema can reference other schema through lazy references which might be forward or recursive references,\n * this can not be evaluated for one schema when referenced by another schema.\n *\n * See {@link TreeNodeValid.constructorCached} and {@link TreeNodeValid.markMostDerived}.\n */\nexport interface MostDerivedData {\n\treadonly constructor: typeof TreeNodeValid & TreeNodeSchema;\n\toneTimeInitialized: boolean;\n}\n\n/**\n * A node type internal to `@fluidframework/tree`.\n * @remarks\n * This type is used in the construction of {@link TreeNode} as an implementation detail, but leaks into the public API due to how schema are implemented.\n * @privateRemarks\n * A {@link FlexTreeNode}. Includes {@link RawTreeNode}s.\n * @sealed @public\n */\nexport interface InternalTreeNode\n\textends ErasedType<\"@fluidframework/tree.InternalTreeNode\"> {}\n\nexport function toFlexTreeNode(node: InternalTreeNode): FlexTreeNode {\n\tassert(isFlexTreeNode(node), 0x963 /* Invalid InternalTreeNode */);\n\treturn node;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/simple-tree/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;AAGH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAE7D,OAAO,EACN,QAAQ,EAIR,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,cAAc,EACd,SAAS,GACT,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAwFhD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,OAAgB,QAAQ;IA0DtB,MAAM,CAAC,mCAAC,MAAM,CAAC,WAAW,EAAC,CAA8B,KAAc;QAC7E,MAAM,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC,CAAC;QAEnC,IAAI,MAAM,KAAK,SAAS,IAAI,MAAM,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI,EA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AO,CAAC,QAAQ,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;AACvC,CAAC;AAED,UAAU,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType } from \"@fluidframework/core-interfaces\";\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tNodeKind,\n\ttype TreeNodeSchema,\n\ttype TreeNodeSchemaClass,\n\ttype WithType,\n\ttypeNameSymbol,\n} from \"./schemaTypes.js\";\nimport {\n\ttype FlexTreeNode,\n\ttype MapTreeNode,\n\tisFlexTreeNode,\n\tmarkEager,\n} from \"../feature-libraries/index.js\";\nimport { tryGetSimpleNodeSchema } from \"./schemaCaching.js\";\nimport { isTreeNode } from \"./proxies.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { getFlexSchema } from \"./toFlexSchema.js\";\nimport { fail } from \"../util/index.js\";\nimport { getFlexNode, createKernel, setFlexNode } from \"./proxyBinding.js\";\nimport { tryGetSchema } from \"./treeNodeApi.js\";\n\n/**\n * Type alias to document which values are un-hydrated.\n *\n * Un-hydrated values are nodes produced from schema's create functions that haven't been inserted into a tree yet.\n *\n * Since un-hydrated nodes become hydrated when inserted, strong typing can't be used to distinguish them.\n * This no-op wrapper is used instead.\n * @public\n */\nexport type Unhydrated<T> = T;\n\n/**\n * A collection of events that can be emitted by a {@link TreeNode}.\n *\n * @privateRemarks\n * TODO: add a way to subscribe to a specific field (for nodeChanged and treeChanged).\n * Probably have object node and map node specific APIs for this.\n *\n * TODO: ensure that subscription API for fields aligns with API for subscribing to the root.\n *\n * TODO: add more wider area (avoid needing tons of nodeChanged registration) events for use-cases other than treeChanged.\n * Some ideas:\n *\n * - treeChanged, but with some subtrees/fields/paths excluded\n * - helper to batch several nodeChanged calls to a treeChanged scope\n * - parent change (ex: registration on the parent field for a specific index: maybe allow it for a range. Ex: node event takes optional field and optional index range?)\n * - new content inserted into subtree. Either provide event for this and/or enough info to treeChanged to find and search the new sub-trees.\n * Add separate (non event related) API to efficiently scan tree for given set of types (using low level cursor and schema based filtering)\n * to allow efficiently searching for new content (and initial content) of a given type.\n *\n * @sealed @public\n */\nexport interface TreeChangeEvents {\n\t/**\n\t * Emitted by a node after a batch of changes has been applied to the tree, if a change affected the node, where a\n\t * change is:\n\t *\n\t * - For an object node, when the value of one of its properties changes (i.e., the property's value is set\n\t * to something else, including `undefined`).\n\t *\n\t * - For an array node, when an element is added, removed, or moved.\n\t *\n\t * - For a map node, when an entry is added, updated, or removed.\n\t *\n\t * @remarks\n\t * This event is not emitted when:\n\t *\n\t * - Properties of a child node change. Notably, updates to an array node or a map node (like adding or removing\n\t * elements/entries) will emit this event on the array/map node itself, but not on the node that contains the\n\t * array/map node as one of its properties.\n\t *\n\t * - The node is moved to a different location in the tree or removed from the tree.\n\t * In this case the event is emitted on the _parent_ node, not the node itself.\n\t *\n\t * For remote edits, this event is not guaranteed to occur in the same order or quantity that it did in\n\t * the client that made the original edit.\n\t *\n\t * When it is emitted, the tree is guaranteed to be in-schema.\n\t *\n\t * @privateRemarks\n\t * This event occurs whenever the apparent contents of the node instance change, regardless of what caused the change.\n\t * For example, it will fire when the local client reassigns a child, when part of a remote edit is applied to the\n\t * node, or when the node has to be updated due to resolution of a merge conflict\n\t * (for example a previously applied local change might be undone, then reapplied differently or not at all).\n\t */\n\tnodeChanged(): void;\n\n\t/**\n\t * Emitted by a node after a batch of changes has been applied to the tree, when something changed anywhere in the\n\t * subtree rooted at it.\n\t *\n\t * @remarks\n\t * This event is not emitted when the node itself is moved to a different location in the tree or removed from the tree.\n\t * In that case it is emitted on the _parent_ node, not the node itself.\n\t *\n\t * The node itself is part of the subtree, so this event will be emitted even if the only changes are to the properties\n\t * of the node itself.\n\t *\n\t * For remote edits, this event is not guaranteed to occur in the same order or quantity that it did in\n\t * the client that made the original edit.\n\t *\n\t * When it is emitted, the tree is guaranteed to be in-schema.\n\t */\n\ttreeChanged(): void;\n}\n\n/**\n * A non-{@link NodeKind.Leaf|leaf} SharedTree node. Includes objects, arrays, and maps.\n *\n * @remarks\n * Base type which all nodes implement.\n *\n * This can be used as a type to indicate/document values which should be tree nodes.\n * Runtime use of this class object (for example when used with `instanceof` or extending it), is not currently supported.\n *\n * Instances of tree nodes must be created by opening an existing document, inserting values into the document,\n * or by using the constructors and create functions of {@link TreeNodeSchema} produced by {@link SchemaFactory}.\n * @privateRemarks\n * This is a class not an interface to enable stricter type checking (see {@link TreeNode.#brand})\n * and some runtime enforcement of schema class policy (see the the validation in the constructor).\n * This class is however only `type` exported not value exported, preventing the class object from being used,\n * similar to how interfaces work.\n *\n * Not all node implementations include this in their prototype chain (some hide it with a proxy),\n * and thus cause the default/built in `instanceof` to return false despite our type checking and all other APIs treating them as TreeNodes.\n * This class provides a custom `Symbol.hasInstance` to fix `instanceof` for this class and all classes extending it.\n * For now the type-only export prevents use of `instanceof` on this class (but allows it in subclasses like schema classes).\n * @sealed @public\n */\nexport abstract class TreeNode implements WithType {\n\t/**\n\t * This is added to prevent TypeScript from implicitly allowing non-TreeNode types to be used as TreeNodes.\n\t * @remarks\n\t * This field forces TypeScript to use nominal instead of structural typing,\n\t * preventing compiler error messages and tools like \"add missing properties\"\n\t * from adding the [type] field as a solution when using a non-TreeNode object where a TreeNode is required.\n\t * Instead TreeNodes must be created through the appropriate APIs, see the documentation on {@link TreeNode} for details.\n\t *\n\t * @privateRemarks\n\t * This is a JavaScript private field, so is not accessible from outside this class.\n\t * This prevents it from having name collisions with object fields.\n\t * Since this is private, the type of this field is stripped in the d.ts file.\n\t * To get matching type checking within and from outside the package, the least informative type (`unknown`) is used.\n\t * To avoid this having any runtime impact, the field is uninitialized.\n\t *\n\t * Making this field optional results in different type checking within this project than outside of it, since the d.ts file drops the optional aspect of the field.\n\t * This is extra confusing since since the tests get in-project typing for intellisense and separate project checking at build time.\n\t * To avoid all this mess, this field is required, not optional.\n\t *\n\t * Another option would be to use a symbol (possibly as a private field).\n\t * That approach ran into some strange difficulties causing SchemaFactory to fail to compile, and was not investigated further.\n\t *\n\t * The [type] symbol provides a lot of the value this private brand does, but is not all of it:\n\t * someone could manually (or via Intellisense auto-implement completion, or in response to a type error)\n\t * make an object literal with the [type] field and pass it off as a node: this private brand prevents that.\n\t */\n\treadonly #brand!: unknown;\n\n\t/**\n\t * Adds a type symbol for stronger typing.\n\t * @privateRemarks\n\t * Subclasses provide more specific strings for this to get strong typing of otherwise type compatible nodes.\n\t */\n\tpublic abstract get [typeNameSymbol](): string;\n\n\t/**\n\t * Provides `instanceof` support for testing if a value is a `TreeNode`.\n\t * @remarks\n\t * For more options, like including leaf values or narrowing to collections of schema, use `is` or `schema` from {@link TreeNodeApi}.\n\t * @privateRemarks\n\t * Due to type-only export, this functionality is not available outside the package.\n\t */\n\tpublic static [Symbol.hasInstance](value: unknown): value is TreeNode;\n\n\t/**\n\t * Provides `instanceof` support for all schema classes with public constructors.\n\t * @remarks\n\t * For more options, like including leaf values or narrowing to collections of schema, use `is` or `schema` from {@link TreeNodeApi}.\n\t * @privateRemarks\n\t * Despite type-only export, this functionality is available outside the package since it is inherited by subclasses.\n\t */\n\tpublic static [Symbol.hasInstance]<\n\t\tTSchema extends abstract new (\n\t\t\t...args: any[]\n\t\t) => TreeNode,\n\t>(this: TSchema, value: unknown): value is InstanceType<TSchema>;\n\n\tpublic static [Symbol.hasInstance](this: { prototype: object }, value: unknown): boolean {\n\t\tconst schema = tryGetSchema(value);\n\n\t\tif (schema === undefined || schema.kind === NodeKind.Leaf) {\n\t\t\treturn false;\n\t\t}\n\n\t\tassert(\"prototype\" in schema, 0x98a /* expected class based schema */);\n\t\treturn inPrototypeChain(schema.prototype, this.prototype);\n\t}\n\n\tprotected constructor() {\n\t\tif (!inPrototypeChain(Reflect.getPrototypeOf(this), TreeNodeValid.prototype)) {\n\t\t\tthrow new UsageError(\"TreeNodes must extend schema classes created by SchemaFactory\");\n\t\t}\n\t}\n}\n\n/**\n * Check if the prototype derived's prototype chain contains `base`.\n * @param derived - prototype to check\n * @param base - prototype to search for\n * @returns true iff `base` is in the prototype chain starting at `derived`.\n */\n// eslint-disable-next-line @rushstack/no-new-null\nexport function inPrototypeChain(derived: object | null, base: object): boolean {\n\tlet checking = derived;\n\twhile (checking !== null) {\n\t\tif (base === checking) {\n\t\t\treturn true;\n\t\t}\n\t\tchecking = Reflect.getPrototypeOf(checking);\n\t}\n\treturn false;\n}\n\n/**\n * Class which all {@link TreeNode}s must extend.\n * Since this is not exported, it allows robust detection of attempts to create TreeNodes which do not go through SchemaFactory which is the only place which exposes classes that extend this.\n *\n * This has static members which schema classes can override to provide schema specific functionality.\n * These static members are only intended to be used / overridden by code within this package, and are used by the various node kinds.\n * Access to these static members has to be done via `this.constructor.staticMember` to support the overrides, and thus can only be used in the constructor, after the base constructor has been invoked.\n */\nexport abstract class TreeNodeValid<TInput> extends TreeNode {\n\t/**\n\t * Schema classes can override this to control what happens at the end of the constructor.\n\t * The return value from this is returned from the constructor, allowing substituting a proxy if desired.\n\t *\n\t * This is not simply done in the derived constructor to enable:\n\t * - this class to access the value which is being returned before it's returned from the constructor.\n\t * - the derived class to be provided the input `FlexTreeNode` without relying on a field on the node to hold it.\n\t */\n\tprotected static prepareInstance<T>(\n\t\tthis: typeof TreeNodeValid<T>,\n\t\tinstance: TreeNodeValid<T>,\n\t\tinput: FlexTreeNode,\n\t): TreeNodeValid<T> {\n\t\treturn instance;\n\t}\n\n\t/**\n\t * Schema classes must override to provide an implementation of RawTreeNode construction.\n\t */\n\tprotected static buildRawNode<T>(\n\t\tthis: typeof TreeNodeValid<T>,\n\t\tinstance: TreeNodeValid<T>,\n\t\tinput: T,\n\t): MapTreeNode {\n\t\treturn fail(\"Schema must override buildRawNode\");\n\t}\n\n\t/**\n\t * Schema classes can override to provide a callback that is called once when the first node is constructed.\n\t * This is a good place to perform extra validation and cache schema derived data needed for the implementation of the node.\n\t */\n\tprotected static oneTimeSetup<T>(this: typeof TreeNodeValid<T>): void {}\n\n\t/**\n\t * The most derived constructor (the one invoked with the `new` operator, not a parent class constructor invoked with as `super`) used to construct an instance of this type.\n\t * @remarks\n\t * Captured when an instance is constructed.\n\t *\n\t * Used to ensure that some derived class (which must override this member, defaulting it to `undefined`) is only instantiated with a single \"most derived\" class (the constructor actually invoked the the user with `new`).\n\t *\n\t * Typically this is override in the class that statically implements {@link TreeNodeSchema} to enforce that all nodes using that schema use the same class and not different subclasses of it.\n\t *\n\t * Also used to detect if oneTimeSetup has run.\n\t *\n\t * @privateRemarks\n\t * This defaults to \"default\", which is used to trigger an error if not overridden in the derived class.\n\t *\n\t * The value of this on TreeNodeValid must only be overridden by base classes and never modified.\n\t * Ways to enforce this immutability prevent it from being overridden,\n\t * so code modifying constructorCached should be extra careful to avoid accidentally modifying the base/inherited value.\n\t */\n\tprotected static constructorCached: MostDerivedData | \"default\" | undefined = \"default\";\n\n\t/**\n\t * Indicate that `this` is the most derived version of a schema, and thus the only one allowed to be used (other than by being subclassed a single time).\n\t */\n\tpublic static markMostDerived(this: typeof TreeNodeValid & TreeNodeSchema): MostDerivedData {\n\t\tassert(this.constructorCached !== \"default\", 0x95f /* invalid schema class */);\n\n\t\tif (this.constructorCached === undefined) {\n\t\t\t// Set the constructorCached on the layer of the prototype chain that declared it.\n\t\t\t// This is necessary to ensure there is only one subclass of that type used:\n\t\t\t// if constructorCached was simply set on `schema`,\n\t\t\t// then a base classes between `schema` (exclusive) and where `constructorCached` is set (inclusive) and other subclasses of them\n\t\t\t// would not see the stored `constructorCached`, and the validation above against multiple derived classes would not work.\n\n\t\t\t// This is not just an alias of `this`, but a reference to the item in the prototype chain being walked, which happens to start at `this`.\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-this-alias\n\t\t\tlet schemaBase: typeof TreeNodeValid = this;\n\t\t\twhile (!Object.prototype.hasOwnProperty.call(schemaBase, \"constructorCached\")) {\n\t\t\t\tschemaBase = Reflect.getPrototypeOf(schemaBase) as typeof TreeNodeValid;\n\t\t\t}\n\t\t\tassert(schemaBase.constructorCached === undefined, 0x962 /* overwriting wrong cache */);\n\t\t\tschemaBase.constructorCached = { constructor: this, oneTimeInitialized: false };\n\t\t\tassert(\n\t\t\t\tthis.constructorCached === schemaBase.constructorCached,\n\t\t\t\t0x9b5 /* Inheritance should work */,\n\t\t\t);\n\t\t\treturn this.constructorCached;\n\t\t} else if (this.constructorCached.constructor === this) {\n\t\t\treturn this.constructorCached;\n\t\t}\n\n\t\tthrow new UsageError(\n\t\t\t`Two schema classes were used (${this.name} and ${\n\t\t\t\tthis.constructorCached.constructor.name\n\t\t\t}) which derived from the same SchemaFactory generated class (${JSON.stringify(\n\t\t\t\tthis.identifier,\n\t\t\t)}). This is invalid.`,\n\t\t);\n\t}\n\n\tpublic constructor(input: TInput | InternalTreeNode) {\n\t\tsuper();\n\t\tconst schema = this.constructor as typeof TreeNodeValid & TreeNodeSchema;\n\t\tconst cache = schema.markMostDerived();\n\t\tif (!cache.oneTimeInitialized) {\n\t\t\tconst flexSchema = getFlexSchema(schema);\n\t\t\tassert(\n\t\t\t\ttryGetSimpleNodeSchema(flexSchema) === schema,\n\t\t\t\t0x961 /* Schema class not properly configured */,\n\t\t\t);\n\t\t\tschema.oneTimeSetup();\n\t\t\tcache.oneTimeInitialized = true;\n\t\t}\n\n\t\tif (isTreeNode(input)) {\n\t\t\t// TODO: update this once we have better support for deep-copying and move operations.\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Existing nodes may not be used as the constructor parameter for a new node. The existing node may be used directly instead of creating a new one, used as a child of the new node (if it has not yet been inserted into the tree). If the desired result is copying the provided node, it must be deep copied (since any child node would be parented under both the new and old nodes). Currently no API is provided to make deep copies, but it can be done manually with object spreads - for example `new Foo({...oldFoo})` will work if all fields of `oldFoo` are leaf nodes.\",\n\t\t\t);\n\t\t}\n\n\t\tconst node: FlexTreeNode = isFlexTreeNode(input)\n\t\t\t? input\n\t\t\t: schema.buildRawNode(this, input);\n\t\tassert(\n\t\t\ttryGetSimpleNodeSchema(node.schema) === schema,\n\t\t\t0x83b /* building node with wrong schema */,\n\t\t);\n\n\t\tconst result = schema.prepareInstance(this, node);\n\t\tcreateKernel(result);\n\t\tsetFlexNode(result, node);\n\t\treturn result;\n\t}\n}\n// Class objects are functions (callable), so we need a strong way to distinguish between `schema` and `() => schema` when used as a `LazyItem`.\nmarkEager(TreeNodeValid);\n\n/**\n * Data cached about the most derived type in a schema's class hierarchy.\n * @remarks\n * The most derived type is the only one allowed to be referenced by other schema or constructed as a node.\n * It has to be discovered lazily (when a node is constructed or when a {@link TreeViewConfiguration} is made),\n * since JavaScript provides no way to find derived classes, or inject static class initialization time logic into base classes.\n * Additionally since schema can reference other schema through lazy references which might be forward or recursive references,\n * this can not be evaluated for one schema when referenced by another schema.\n *\n * See {@link TreeNodeValid.constructorCached} and {@link TreeNodeValid.markMostDerived}.\n */\nexport interface MostDerivedData {\n\treadonly constructor: typeof TreeNodeValid & TreeNodeSchema;\n\toneTimeInitialized: boolean;\n}\n\n/**\n * A node type internal to `@fluidframework/tree`.\n * @remarks\n * This type is used in the construction of {@link TreeNode} as an implementation detail, but leaks into the public API due to how schema are implemented.\n * @privateRemarks\n * A {@link FlexTreeNode}. Includes {@link RawTreeNode}s.\n * @sealed @public\n */\nexport interface InternalTreeNode\n\textends ErasedType<\"@fluidframework/tree.InternalTreeNode\"> {}\n\nexport function toFlexTreeNode(node: InternalTreeNode): FlexTreeNode {\n\tassert(isFlexTreeNode(node), 0x963 /* Invalid InternalTreeNode */);\n\treturn node;\n}\n\n// #region NodeJS custom inspect for TreeNodes.\n\n/**\n * Used to customize \"inspect\" behavior in NodeJS.\n * See https://nodejs.org/api/util.html#utilinspectcustom for details.\n *\n * VS-Code's debugger also uses this to inspect objects,\n * see https://github.com/microsoft/vscode-js-debug/blob/64df2686c92bac402909dee5c3c389bbb7a81f6d/src/adapter/templates/getStringyProps.ts#L11 for details.\n */\nconst customInspectSymbol = Symbol.for(\"nodejs.util.inspect.custom\");\n\n/**\n * Node inspecting function for use with {@link customInspectSymbol}.\n */\nfunction inspectNodeFunction(\n\tthis: TreeNodeValid<unknown>,\n\tdepth: number,\n\toptions?: unknown,\n\tinspect?: unknown,\n): unknown {\n\t// TODO: replicated from tryGetSchema to avoid cycle.\n\t// This case could be optimized, for example by placing the simple schema in a symbol on tree nodes.\n\tconst schema = tryGetSimpleNodeSchema(getFlexNode(this).schema) as TreeNodeSchemaClass;\n\tconst title = `${schema.name}: ${NodeKind[schema.kind]} Node (${schema.identifier})`;\n\n\tif (depth < 2) {\n\t\tconst short = shortContent(this);\n\t\tif (short !== undefined) {\n\t\t\treturn `${title} ${short}`;\n\t\t}\n\t\treturn title;\n\t}\n\tconst content = `${title} ${JSON.stringify(this)}`;\n\treturn content;\n}\n\n/**\n * If the node has no items, a short JSON string for it.\n */\nfunction shortContent(node: TreeNodeValid<unknown>): string | undefined {\n\tif (Object.values(node).length === 0) {\n\t\treturn JSON.stringify(node);\n\t}\n\treturn undefined;\n}\n\n/**\n * Add inherited non-enumerable symbol for NodeJS inspection to all nodes.\n *\n * See {@link customInspectSymbol}.\n */\nObject.defineProperty(TreeNodeValid.prototype, customInspectSymbol, {\n\tvalue: inspectNodeFunction,\n\tenumerable: false,\n});\n\n// #endregion\n\n// #region Browser custom debug format for TreeNodes\n\n// This section has side-effects, so including it in this file ensures its loaded whenever TreeNodes could exist.\n// Supported in at least Chrome and FireFox, more details at https://firefox-source-docs.mozilla.org/devtools-user/custom_formatters/index.html\n// For this to work the browser's dev tools generally have to \"Enable custom formatters\".\n\n// This formatter is inspired by https://github.com/andrewdavey/immutable-devtools/blob/master/src/createFormatters.js which provides a similar formatter for the immutable.js library.\n\nconst globals = typeof window === \"undefined\" ? globalThis : window;\nconst formatters = ((\n\tglobals as { devtoolsFormatters?: DevtoolsFormatter.DevtoolsFormatter[] }\n).devtoolsFormatters ??= []);\n\nconst nodeFormatter: DevtoolsFormatter.DevtoolsFormatter = {\n\theader(object, config) {\n\t\tif (isTreeNode(object)) {\n\t\t\treturn [\"span\", `${inspectNodeFunction.call(object, 1)}`];\n\t\t}\n\t\treturn null;\n\t},\n\tbody(object, config): DevtoolsFormatter.Item {\n\t\tconst children: DevtoolsFormatter.Item[] = [];\n\t\tfor (const [key, value] of Object.entries(object as TreeNode)) {\n\t\t\tchildren.push([\"li\", [\"span\", `${key}: `], formattedReference(value)]);\n\t\t}\n\n\t\t// TODO:\n\t\t// for array nodes, this isn't great since (at least in FireFox) the list items show up with a prefixed number starting from 1.\n\t\t// This looks messy when followed by the array index.\n\t\t// Find a way to hide the list index.\n\t\t// { style: 'list-style-type: none` } did not seem to work.\n\n\t\treturn [\"ol\", ...children];\n\t},\n\thasBody(object, config) {\n\t\treturn shortContent(object as TreeNodeValid<undefined>) === undefined;\n\t},\n};\n\nfunction formattedReference(\n\tobject: unknown,\n\tconfig?: DevtoolsFormatter.ObjectConfig,\n): DevtoolsFormatter.Item {\n\tif (typeof object === \"undefined\") {\n\t\treturn [\"span\", \"undefined\"];\n\t} else if (object === \"null\") {\n\t\treturn [\"span\", \"null\"];\n\t}\n\n\treturn [\"object\", { object, config }];\n}\n\nformatters.push(nodeFormatter);\n\n// #endregion\n\n// These types are based on https://github.com/BenjaminAster/Better-TypeScript/blob/main/types/devtools-formatters.d.ts\n// however the original package causes multiple compile errors due to some of its other types it used, so the relevant part has been extracted and adjusted to better match our conventions.\ndeclare namespace DevtoolsFormatter {\n\ttype ObjectConfig = Record<string | symbol, unknown>;\n\n\ttype ElementTagName = \"div\" | \"span\" | \"ol\" | \"li\" | \"table\" | \"tr\" | \"td\";\n\n\ttype ElementTemplate = StyledElementTemplate | UnstyledElementTemplate;\n\n\ttype StyledElementTemplate = readonly [\n\t\tElementTagName,\n\t\t{\n\t\t\tstyle?: string;\n\t\t},\n\t\t...Item[],\n\t];\n\n\ttype UnstyledElementTemplate = readonly [ElementTagName, ...Item[]];\n\n\ttype ObjectReference = readonly [\n\t\t\"object\",\n\t\t{\n\t\t\tobject: unknown;\n\t\t\tconfig?: ObjectConfig;\n\t\t},\n\t];\n\n\ttype Item = string | ElementTemplate | ObjectReference;\n\n\tinterface DevtoolsFormatter {\n\t\theader(\n\t\t\tobject?: unknown,\n\t\t\tconfig?: ObjectConfig,\n\t\t\t// eslint-disable-next-line @rushstack/no-new-null\n\t\t): Item | null;\n\t\thasBody(object?: unknown, config?: ObjectConfig): boolean;\n\t\tbody(object?: unknown, config?: ObjectConfig): Item;\n\t}\n}\n"]}
@@ -69,7 +69,7 @@ export class Breakable {
69
69
  * This is pretty much only safe in tests which just were checking a specific error was thrown, and which know that error closepath is actually exception safe.
70
70
  */
71
71
  clearError() {
72
- assert(this.brokenBy !== undefined, "No error to clear");
72
+ assert(this.brokenBy !== undefined, 0x9b6 /* No error to clear */);
73
73
  this.brokenBy = undefined;
74
74
  }
75
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"breakable.js","sourceRoot":"","sources":["../../src/util/breakable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE;;GAEG;AACH,MAAM,OAAO,SAAS;IAGrB,YAAoC,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEpD;;;;OAIG;IACI,GAAG;QACT,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,UAAU,CACnB,kBAAkB,IAAI,CAAC,IAAI,+EAA+E,IAAI,CAAC,QAAQ,EAAE,CACzH,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,QAAe;QAC3B,2FAA2F;QAC3F,0KAA0K;QAC1K,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,QAAQ,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C,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9B,cAAc,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;gBACxB,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBACpE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC9B,SAAS;oBACT,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC5C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;4BAClC,gKAAgK;4BAChK,UAAU,CAAC,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;4BACpD,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;wBACtE,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QACD,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC3B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * An object which can enter a \"broken\" state where trying to use it is a UsageError.\n */\nexport class Breakable {\n\tprivate brokenBy?: Error;\n\n\tpublic constructor(private readonly name: string) {}\n\n\t/**\n\t * Throws if the object is in the broken state.\n\t * @remarks\n\t * Can use {@link throwIfBroken} to apply this to a method.\n\t */\n\tpublic use(): void {\n\t\tif (this.brokenBy !== undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Invalid use of ${this.name} after it was put into an invalid state by another error.\\nOriginal Error:\\n${this.brokenBy}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Puts this object into the broken state, and throws an error.\n\t *\n\t * @throws If already broken by a different error, throws a UsageError, otherwise throws `brokenBy`.\n\t */\n\tpublic break(brokenBy: Error): never {\n\t\t// If already broken by this error, let it bubble up without rethrowing a modified version.\n\t\t// This prevents internal errors like asserts getting rethrown as different errors when wrapped with multiple call to `{@link Breakable.run}` or `{@link breakingMethod}`.\n\t\tif (this.brokenBy !== brokenBy) {\n\t\t\tthis.use();\n\t\t\tthis.brokenBy = brokenBy;\n\t\t}\n\t\tthrow brokenBy;\n\t}\n\n\t/**\n\t * {@link Breakable.break}, except tolerates `unknown` to be more easily used by catch blocks.\n\t * @privateRemarks\n\t * If there is a use-case, this should be made public.\n\t */\n\tprivate rethrowCaught(brokenBy: unknown): never {\n\t\tif (brokenBy instanceof Error) {\n\t\t\tthis.break(brokenBy);\n\t\t}\n\t\tthis.break(\n\t\t\tnew Error(`Non-error thrown breaking ${this.name}. Thrown value: \"${brokenBy}\"`),\n\t\t);\n\t}\n\n\t/**\n\t * Runs code which should break the object if it throws.\n\t * @remarks\n\t * This also throws if already broken like {@link Breakable.use}.\n\t * Any exceptions this catches are re-thrown.\n\t * Can use {@link breakingMethod} to apply this to a method.\n\t */\n\tpublic run<TResult>(breaker: () => TResult): TResult {\n\t\tthis.use();\n\t\ttry {\n\t\t\treturn breaker();\n\t\t} catch (error: unknown) {\n\t\t\tthis.rethrowCaught(error);\n\t\t}\n\t}\n\n\t/**\n\t * Clears the existing broken state.\n\t * @remarks\n\t * This is rarely safe to to: it is only ok when all objects using this breaker are known to not have been left in an invalid state.\n\t * This is pretty much only safe in tests which just were checking a specific error was thrown, and which know that error closepath is actually exception safe.\n\t */\n\tpublic clearError(): void {\n\t\tassert(this.brokenBy !== undefined, \"No error to clear\");\n\t\tthis.brokenBy = undefined;\n\t}\n}\n\n/**\n * Marks an object as being able to be in a broken state (unknown/unspecified/broken state due to unhandled exception).\n * @remarks\n * See decorators {@link breakingMethod} and {@link throwIfBroken} for ease of use.\n */\nexport interface WithBreakable {\n\treadonly breaker: Breakable;\n}\n\n/**\n * Decorator for methods which should break the object when they throw.\n * @remarks\n * This also throws if already broken like {@link throwIfBroken}.\n * See {@link Breakable.run} for details.\n *\n * This should be used on methods which modify data that could result in an unsupported/broken state if an exception is thrown while modifying.\n * It is ok for breakingMethods to call each-other.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function breakingMethod<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context?: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tif (this.breaker === undefined) {\n\t\t\t// This case is necessary for when wrapping methods which are invoked inside the constructor of the base class before `breaker` is set.\n\t\t\t// Since the constructor throwing does not return an object, failing to put it into a broken state is not too bad.\n\t\t\t// However when more than just the constructed object should be broken, this can result in missing a break.\n\t\t\treturn target.call(this, ...args);\n\t\t}\n\t\treturn this.breaker.run(() => {\n\t\t\treturn target.call(this, ...args);\n\t\t});\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n/**\n * Decorator for methods which should throw if the object is in a broken state.\n * @remarks\n * This should be used on methods which read data that could be invalid when the object is broken.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function throwIfBroken<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tthis.breaker.use();\n\t\treturn target.call(this, ...args);\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\ntype PossiblyNamedFunction = Function & { displayName?: undefined | string };\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction nameFunctionFrom(toName: Function, nameFrom: Function): void {\n\t(toName as PossiblyNamedFunction).displayName =\n\t\t(nameFrom as PossiblyNamedFunction).displayName ?? nameFrom.name;\n}\n\nconst isBreakerSymbol: unique symbol = Symbol(\"isBreaker\");\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction markBreaker(f: Function): void {\n\t(f as unknown as Record<typeof isBreakerSymbol, true>)[isBreakerSymbol] = true;\n}\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction isBreaker(f: Function): boolean {\n\treturn isBreakerSymbol in (f as unknown as Record<typeof isBreakerSymbol, true>);\n}\n\n/**\n * Decorator for classes which should break when their methods throw.\n * @remarks\n * Applies {@link breakingMethod} to all methods declared directly by class or its base classes.\n * Does not include those on derived classes.\n * Does not include getters or setters, or value properties.\n * Methods already marked as {@link breakingMethod} or {@link throwIfBroken} are unaffected.\n */\nexport function breakingClass<Target extends abstract new (...args: any[]) => WithBreakable>(\n\ttarget: Target,\n\tcontext: ClassDecoratorContext<Target>,\n): Target {\n\tabstract class DecoratedBreakable extends target {}\n\n\t// Keep track of what keys we have seen,\n\t// since we visit most derived properties first and need to avoid wrapping base properties overriding more derived ones.\n\tconst overriddenKeys: Set<string | symbol> = new Set();\n\n\tlet prototype: object | null = target.prototype;\n\twhile (prototype !== null) {\n\t\tfor (const key of Reflect.ownKeys(prototype)) {\n\t\t\tif (!overriddenKeys.has(key)) {\n\t\t\t\toverriddenKeys.add(key);\n\t\t\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\t// Method\n\t\t\t\t\tif (typeof descriptor.value === \"function\") {\n\t\t\t\t\t\tif (!isBreaker(descriptor.value)) {\n\t\t\t\t\t\t\t// This does not affect the original class, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor\n\t\t\t\t\t\t\tdescriptor.value = breakingMethod(descriptor.value);\n\t\t\t\t\t\t\tObject.defineProperty(DecoratedBreakable.prototype, key, descriptor);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprototype = Reflect.getPrototypeOf(prototype);\n\t}\n\n\treturn DecoratedBreakable;\n}\n"]}
1
+ {"version":3,"file":"breakable.js","sourceRoot":"","sources":["../../src/util/breakable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE;;GAEG;AACH,MAAM,OAAO,SAAS;IAGrB,YAAoC,IAAY;QAAZ,SAAI,GAAJ,IAAI,CAAQ;IAAG,CAAC;IAEpD;;;;OAIG;IACI,GAAG;QACT,IAAI,IAAI,CAAC,QAAQ,KAAK,SAAS,EAAE,CAAC;YACjC,MAAM,IAAI,UAAU,CACnB,kBAAkB,IAAI,CAAC,IAAI,+EAA+E,IAAI,CAAC,QAAQ,EAAE,CACzH,CAAC;QACH,CAAC;IACF,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,QAAe;QAC3B,2FAA2F;QAC3F,0KAA0K;QAC1K,IAAI,IAAI,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAChC,IAAI,CAAC,GAAG,EAAE,CAAC;YACX,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAC1B,CAAC;QACD,MAAM,QAAQ,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACK,aAAa,CAAC,QAAiB;QACtC,IAAI,QAAQ,YAAY,KAAK,EAAE,CAAC;YAC/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,CAAC,CAAC;gBACxB,MAAM,UAAU,GAAG,OAAO,CAAC,wBAAwB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;gBACpE,IAAI,UAAU,KAAK,SAAS,EAAE,CAAC;oBAC9B,SAAS;oBACT,IAAI,OAAO,UAAU,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;wBAC5C,IAAI,CAAC,SAAS,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,CAAC;4BAClC,gKAAgK;4BAChK,UAAU,CAAC,KAAK,GAAG,cAAc,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;4BACpD,MAAM,CAAC,cAAc,CAAC,kBAAkB,CAAC,SAAS,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC;wBACtE,CAAC;oBACF,CAAC;gBACF,CAAC;YACF,CAAC;QACF,CAAC;QACD,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;IAC/C,CAAC;IAED,OAAO,kBAAkB,CAAC;AAC3B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\n/**\n * An object which can enter a \"broken\" state where trying to use it is a UsageError.\n */\nexport class Breakable {\n\tprivate brokenBy?: Error;\n\n\tpublic constructor(private readonly name: string) {}\n\n\t/**\n\t * Throws if the object is in the broken state.\n\t * @remarks\n\t * Can use {@link throwIfBroken} to apply this to a method.\n\t */\n\tpublic use(): void {\n\t\tif (this.brokenBy !== undefined) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Invalid use of ${this.name} after it was put into an invalid state by another error.\\nOriginal Error:\\n${this.brokenBy}`,\n\t\t\t);\n\t\t}\n\t}\n\n\t/**\n\t * Puts this object into the broken state, and throws an error.\n\t *\n\t * @throws If already broken by a different error, throws a UsageError, otherwise throws `brokenBy`.\n\t */\n\tpublic break(brokenBy: Error): never {\n\t\t// If already broken by this error, let it bubble up without rethrowing a modified version.\n\t\t// This prevents internal errors like asserts getting rethrown as different errors when wrapped with multiple call to `{@link Breakable.run}` or `{@link breakingMethod}`.\n\t\tif (this.brokenBy !== brokenBy) {\n\t\t\tthis.use();\n\t\t\tthis.brokenBy = brokenBy;\n\t\t}\n\t\tthrow brokenBy;\n\t}\n\n\t/**\n\t * {@link Breakable.break}, except tolerates `unknown` to be more easily used by catch blocks.\n\t * @privateRemarks\n\t * If there is a use-case, this should be made public.\n\t */\n\tprivate rethrowCaught(brokenBy: unknown): never {\n\t\tif (brokenBy instanceof Error) {\n\t\t\tthis.break(brokenBy);\n\t\t}\n\t\tthis.break(\n\t\t\tnew Error(`Non-error thrown breaking ${this.name}. Thrown value: \"${brokenBy}\"`),\n\t\t);\n\t}\n\n\t/**\n\t * Runs code which should break the object if it throws.\n\t * @remarks\n\t * This also throws if already broken like {@link Breakable.use}.\n\t * Any exceptions this catches are re-thrown.\n\t * Can use {@link breakingMethod} to apply this to a method.\n\t */\n\tpublic run<TResult>(breaker: () => TResult): TResult {\n\t\tthis.use();\n\t\ttry {\n\t\t\treturn breaker();\n\t\t} catch (error: unknown) {\n\t\t\tthis.rethrowCaught(error);\n\t\t}\n\t}\n\n\t/**\n\t * Clears the existing broken state.\n\t * @remarks\n\t * This is rarely safe to to: it is only ok when all objects using this breaker are known to not have been left in an invalid state.\n\t * This is pretty much only safe in tests which just were checking a specific error was thrown, and which know that error closepath is actually exception safe.\n\t */\n\tpublic clearError(): void {\n\t\tassert(this.brokenBy !== undefined, 0x9b6 /* No error to clear */);\n\t\tthis.brokenBy = undefined;\n\t}\n}\n\n/**\n * Marks an object as being able to be in a broken state (unknown/unspecified/broken state due to unhandled exception).\n * @remarks\n * See decorators {@link breakingMethod} and {@link throwIfBroken} for ease of use.\n */\nexport interface WithBreakable {\n\treadonly breaker: Breakable;\n}\n\n/**\n * Decorator for methods which should break the object when they throw.\n * @remarks\n * This also throws if already broken like {@link throwIfBroken}.\n * See {@link Breakable.run} for details.\n *\n * This should be used on methods which modify data that could result in an unsupported/broken state if an exception is thrown while modifying.\n * It is ok for breakingMethods to call each-other.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function breakingMethod<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context?: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tif (this.breaker === undefined) {\n\t\t\t// This case is necessary for when wrapping methods which are invoked inside the constructor of the base class before `breaker` is set.\n\t\t\t// Since the constructor throwing does not return an object, failing to put it into a broken state is not too bad.\n\t\t\t// However when more than just the constructed object should be broken, this can result in missing a break.\n\t\t\treturn target.call(this, ...args);\n\t\t}\n\t\treturn this.breaker.run(() => {\n\t\t\treturn target.call(this, ...args);\n\t\t});\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n/**\n * Decorator for methods which should throw if the object is in a broken state.\n * @remarks\n * This should be used on methods which read data that could be invalid when the object is broken.\n * @privateRemarks\n * Explicitly capturing the full `Target` type is necessary to make this work with generic methods with unknown numbers of type parameters.\n */\nexport function throwIfBroken<\n\tTarget extends ((...args: any[]) => unknown) & ((this: This, ...args: Args) => Return),\n\tThis extends WithBreakable,\n\tArgs extends never[],\n\tReturn,\n>(target: Target, context: ClassMethodDecoratorContext<This, Target>): Target {\n\tfunction replacementMethod(this: This, ...args: Args): Return {\n\t\tthis.breaker.use();\n\t\treturn target.call(this, ...args);\n\t}\n\tmarkBreaker(replacementMethod);\n\tnameFunctionFrom(replacementMethod, target);\n\treturn replacementMethod as Target;\n}\n\n// eslint-disable-next-line @typescript-eslint/ban-types\ntype PossiblyNamedFunction = Function & { displayName?: undefined | string };\n\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction nameFunctionFrom(toName: Function, nameFrom: Function): void {\n\t(toName as PossiblyNamedFunction).displayName =\n\t\t(nameFrom as PossiblyNamedFunction).displayName ?? nameFrom.name;\n}\n\nconst isBreakerSymbol: unique symbol = Symbol(\"isBreaker\");\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction markBreaker(f: Function): void {\n\t(f as unknown as Record<typeof isBreakerSymbol, true>)[isBreakerSymbol] = true;\n}\n\n// Accepting any function like value is desired and safe here as this does not call the provided function.\n// eslint-disable-next-line @typescript-eslint/ban-types\nfunction isBreaker(f: Function): boolean {\n\treturn isBreakerSymbol in (f as unknown as Record<typeof isBreakerSymbol, true>);\n}\n\n/**\n * Decorator for classes which should break when their methods throw.\n * @remarks\n * Applies {@link breakingMethod} to all methods declared directly by class or its base classes.\n * Does not include those on derived classes.\n * Does not include getters or setters, or value properties.\n * Methods already marked as {@link breakingMethod} or {@link throwIfBroken} are unaffected.\n */\nexport function breakingClass<Target extends abstract new (...args: any[]) => WithBreakable>(\n\ttarget: Target,\n\tcontext: ClassDecoratorContext<Target>,\n): Target {\n\tabstract class DecoratedBreakable extends target {}\n\n\t// Keep track of what keys we have seen,\n\t// since we visit most derived properties first and need to avoid wrapping base properties overriding more derived ones.\n\tconst overriddenKeys: Set<string | symbol> = new Set();\n\n\tlet prototype: object | null = target.prototype;\n\twhile (prototype !== null) {\n\t\tfor (const key of Reflect.ownKeys(prototype)) {\n\t\t\tif (!overriddenKeys.has(key)) {\n\t\t\t\toverriddenKeys.add(key);\n\t\t\t\tconst descriptor = Reflect.getOwnPropertyDescriptor(prototype, key);\n\t\t\t\tif (descriptor !== undefined) {\n\t\t\t\t\t// Method\n\t\t\t\t\tif (typeof descriptor.value === \"function\") {\n\t\t\t\t\t\tif (!isBreaker(descriptor.value)) {\n\t\t\t\t\t\t\t// This does not affect the original class, see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor\n\t\t\t\t\t\t\tdescriptor.value = breakingMethod(descriptor.value);\n\t\t\t\t\t\t\tObject.defineProperty(DecoratedBreakable.prototype, key, descriptor);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tprototype = Reflect.getPrototypeOf(prototype);\n\t}\n\n\treturn DecoratedBreakable;\n}\n"]}
@@ -5,7 +5,7 @@
5
5
  export { brand, type Brand, BrandedType, type NameFromBranded, type ValueFromBranded, } from "./brand.js";
6
6
  export { brandedNumberType, brandedStringType } from "./typeboxBrand.js";
7
7
  export { brandOpaque, extractFromOpaque, type ExtractFromOpaque, type Opaque, } from "./opaque.js";
8
- export { deleteFromNestedMap, getOrAddInMap, getOrAddInNestedMap, getOrDefaultInNestedMap, forEachInNestedMap, type NestedMap, SizedNestedMap, populateNestedMap, setInNestedMap, tryAddToNestedMap, tryGetFromNestedMap, mapNestedMap, nestedMapToFlatList, nestedMapFromFlatList, } from "./nestedMap.js";
8
+ export { deleteFromNestedMap, getOrAddInMap, getOrAddInNestedMap, getOrDefaultInNestedMap, forEachInNestedMap, type NestedMap, type ReadonlyNestedMap, SizedNestedMap, populateNestedMap, setInNestedMap, tryAddToNestedMap, tryGetFromNestedMap, mapNestedMap, nestedMapToFlatList, nestedMapFromFlatList, } from "./nestedMap.js";
9
9
  export { addToNestedSet, type NestedSet, nestedSetContains } from "./nestedSet.js";
10
10
  export { type OffsetList, OffsetListFactory } from "./offsetList.js";
11
11
  export { TransactionResult } from "./transactionResult.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,EACL,KAAK,KAAK,EACV,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,m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uB,EACvB,kBAAkB,EAClB,cAAc,EACd,IAAI,GACJ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAE,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAErF,YAAY,EACX,aAAa,EACb,cAAc,EACd,cAAc,EACd,eAAe,EACf,yBAAyB,EACzB,yBAAyB,EACzB,MAAM,EACN,YAAY,EACZ,WAAW,GACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,yBAAyB,EACzB,eAAe,EACf,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,aAAa,EACb,kBAAkB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACN,KAAK,WAAW,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EACT,KAAK,aAAa,EAClB,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,EACL,KAAK,KAAK,EACV,WAAW,EACX,KAAK,eAAe,EACpB,KAAK,gBAAgB,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,iBAAiB,EACjB,KAAK,iBAAiB,EACtB,KAAK,MAAM,GACX,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAClB,KAAK,SAAS,EACd,KAAK,i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BAAyB,EACzB,yBAAyB,EACzB,MAAM,EACN,YAAY,EACZ,WAAW,GACX,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACN,KAAK,UAAU,EACf,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,sBAAsB,EACtB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,yBAAyB,EACzB,eAAe,EACf,KAAK,UAAU,EACf,KAAK,QAAQ,EACb,KAAK,gBAAgB,EACrB,aAAa,EACb,kBAAkB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACN,KAAK,WAAW,EAChB,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,iBAAiB,EACtB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EACT,KAAK,aAAa,EAClB,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,EAEL,WAAW,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,iBAAiB,GAGjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAElB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAkB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAmB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAgB3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACN,SAAS,EACT,KAAK,EACL,WAAW,EACX,IAAI,EACJ,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,eAAe,EAKf,4BAA4B,EAC5B,SAAS,EACT,WAAW,EACX,cAAc,EAId,gBAAgB,EAChB,gBAAgB,EAChB,4BAA4B,EAC5B,WAAW,EACX,SAAS,EACT,UAAU,EAEV,YAAY,EACZ,aAAa,EAEb,UAAU,EACV,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,IAAI,GACJ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,wBAAwB,CAAC;AAcrF,OAAO,EAIN,sBAAsB,EACtB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,yBAAyB,EACzB,eAAe,EAIf,aAAa,EACb,kBAAkB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEN,oBAAoB,EACpB,oBAAoB,EAEpB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EAET,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tbrand,\n\ttype Brand,\n\tBrandedType,\n\ttype NameFromBranded,\n\ttype ValueFromBranded,\n} from \"./brand.js\";\nexport { brandedNumberType, brandedStringType } from \"./typeboxBrand.js\";\nexport {\n\tbrandOpaque,\n\textractFromOpaque,\n\ttype ExtractFromOpaque,\n\ttype Opaque,\n} from \"./opaque.js\";\nexport {\n\tdeleteFromNestedMap,\n\tgetOrAddInMap,\n\tgetOrAddInNestedMap,\n\tgetOrDefaultInNestedMap,\n\tforEachInNestedMap,\n\ttype NestedMap,\n\tSizedNestedMap,\n\tpopulateNestedMap,\n\tsetInNestedMap,\n\ttryAddToNestedMap,\n\ttryGetFromNestedMap,\n\tmapNestedMap,\n\tnestedMapToFlatList,\n\tnestedMapFromFlatList,\n} from \"./nestedMap.js\";\nexport { addToNestedSet, type NestedSet, nestedSetContains } from \"./nestedSet.js\";\nexport { type OffsetList, OffsetListFactory } from \"./offsetList.js\";\nexport { TransactionResult } from \"./transactionResult.js\";\nexport type {\n\tareSafelyAssignable,\n\tContravariant,\n\tCovariant,\n\teitherIsAny,\n\tEnforceTypeCheckTests,\n\tInvariant,\n\tisAny,\n\tisAssignableTo,\n\tisStrictSubset,\n\tMakeNominal,\n\trequireFalse,\n\trequireTrue,\n\trequireAssignableTo,\n} from \"./typeCheck.js\";\nexport { StackyIterator } from \"./stackyIterator.js\";\nexport {\n\tasMutable,\n\tclone,\n\tcompareSets,\n\tfail,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n\tisJsonObject,\n\tisReadonlyArray,\n\ttype JsonCompatible,\n\ttype JsonCompatibleObject,\n\ttype JsonCompatibleReadOnly,\n\ttype JsonCompatibleReadOnlyObject,\n\tJsonCompatibleReadOnlySchema,\n\tmakeArray,\n\tmapIterable,\n\tfilterIterable,\n\ttype Mutable,\n\ttype Populated,\n\ttype RecursiveReadonly,\n\tassertValidIndex,\n\tassertValidRange,\n\tassertNonNegativeSafeInteger,\n\tobjectToMap,\n\tinvertMap,\n\toneFromSet,\n\ttype Named,\n\tcompareNamed,\n\tdisposeSymbol,\n\ttype IDisposable,\n\tcapitalize,\n\tassertValidRangeIndices,\n\ttransformObjectMap,\n\tcompareStrings,\n\tfind,\n} from \"./utils.js\";\nexport { ReferenceCountedBase, type ReferenceCounted } from \"./referenceCounting.js\";\n\nexport type {\n\tAllowOptional,\n\tRequiredFields,\n\tOptionalFields,\n\t_RecursiveTrick,\n\tAllowOptionalNotFlattened,\n\tRestrictiveReadonlyRecord,\n\tAssume,\n\t_InlineTrick,\n\tFlattenKeys,\n} from \"./typeUtils.js\";\n\nexport {\n\ttype BrandedKey,\n\ttype BrandedKeyContent,\n\ttype BrandedMapSubset,\n\tgetOrCreateSlotContent,\n\tbrandedSlot,\n} from \"./brandedMap.js\";\n\nexport {\n\tgetFirstEntryFromRangeMap,\n\tgetFromRangeMap,\n\ttype RangeEntry,\n\ttype RangeMap,\n\ttype RangeQueryResult,\n\tsetInRangeMap,\n\tdeleteFromRangeMap,\n} from \"./rangeMap.js\";\n\nexport {\n\ttype IdAllocator,\n\tidAllocatorFromMaxId,\n\tidAllocatorFromState,\n\ttype IdAllocationState,\n\tfakeIdAllocator,\n} from \"./idAllocator.js\";\n\nexport {\n\tBreakable,\n\ttype WithBreakable,\n\tbreakingMethod,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"./breakable.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/util/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EACN,KAAK,EAEL,WAAW,GAGX,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EACN,WAAW,EACX,iBAAiB,GAGjB,MAAM,aAAa,CAAC;AACrB,OAAO,EACN,mBAAmB,EACnB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,kBAAkB,EAGlB,cAAc,EACd,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,GACrB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,cAAc,EAAkB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnF,OAAO,EAAmB,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAgB3D,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EACN,SAAS,EACT,KAAK,EACL,WAAW,EACX,IAAI,EACJ,kBAAkB,EAClB,WAAW,EACX,YAAY,EACZ,eAAe,EAKf,4BAA4B,EAC5B,SAAS,EACT,WAAW,EACX,cAAc,EAId,gBAAgB,EAChB,gBAAgB,EAChB,4BAA4B,EAC5B,WAAW,EACX,SAAS,EACT,UAAU,EAEV,YAAY,EACZ,aAAa,EAEb,UAAU,EACV,uBAAuB,EACvB,kBAAkB,EAClB,cAAc,EACd,IAAI,GACJ,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,oBAAoB,EAAyB,MAAM,wBAAwB,CAAC;AAcrF,OAAO,EAIN,sBAAsB,EACtB,WAAW,GACX,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACN,yBAAyB,EACzB,eAAe,EAIf,aAAa,EACb,kBAAkB,GAClB,MAAM,eAAe,CAAC;AAEvB,OAAO,EAEN,oBAAoB,EACpB,oBAAoB,EAEpB,eAAe,GACf,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACN,SAAS,EAET,cAAc,EACd,aAAa,EACb,aAAa,GACb,MAAM,gBAAgB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nexport {\n\tbrand,\n\ttype Brand,\n\tBrandedType,\n\ttype NameFromBranded,\n\ttype ValueFromBranded,\n} from \"./brand.js\";\nexport { brandedNumberType, brandedStringType } from \"./typeboxBrand.js\";\nexport {\n\tbrandOpaque,\n\textractFromOpaque,\n\ttype ExtractFromOpaque,\n\ttype Opaque,\n} from \"./opaque.js\";\nexport {\n\tdeleteFromNestedMap,\n\tgetOrAddInMap,\n\tgetOrAddInNestedMap,\n\tgetOrDefaultInNestedMap,\n\tforEachInNestedMap,\n\ttype NestedMap,\n\ttype ReadonlyNestedMap,\n\tSizedNestedMap,\n\tpopulateNestedMap,\n\tsetInNestedMap,\n\ttryAddToNestedMap,\n\ttryGetFromNestedMap,\n\tmapNestedMap,\n\tnestedMapToFlatList,\n\tnestedMapFromFlatList,\n} from \"./nestedMap.js\";\nexport { addToNestedSet, type NestedSet, nestedSetContains } from \"./nestedSet.js\";\nexport { type OffsetList, OffsetListFactory } from \"./offsetList.js\";\nexport { TransactionResult } from \"./transactionResult.js\";\nexport type {\n\tareSafelyAssignable,\n\tContravariant,\n\tCovariant,\n\teitherIsAny,\n\tEnforceTypeCheckTests,\n\tInvariant,\n\tisAny,\n\tisAssignableTo,\n\tisStrictSubset,\n\tMakeNominal,\n\trequireFalse,\n\trequireTrue,\n\trequireAssignableTo,\n} from \"./typeCheck.js\";\nexport { StackyIterator } from \"./stackyIterator.js\";\nexport {\n\tasMutable,\n\tclone,\n\tcompareSets,\n\tfail,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n\tisJsonObject,\n\tisReadonlyArray,\n\ttype JsonCompatible,\n\ttype JsonCompatibleObject,\n\ttype JsonCompatibleReadOnly,\n\ttype JsonCompatibleReadOnlyObject,\n\tJsonCompatibleReadOnlySchema,\n\tmakeArray,\n\tmapIterable,\n\tfilterIterable,\n\ttype Mutable,\n\ttype Populated,\n\ttype RecursiveReadonly,\n\tassertValidIndex,\n\tassertValidRange,\n\tassertNonNegativeSafeInteger,\n\tobjectToMap,\n\tinvertMap,\n\toneFromSet,\n\ttype Named,\n\tcompareNamed,\n\tdisposeSymbol,\n\ttype IDisposable,\n\tcapitalize,\n\tassertValidRangeIndices,\n\ttransformObjectMap,\n\tcompareStrings,\n\tfind,\n} from \"./utils.js\";\nexport { ReferenceCountedBase, type ReferenceCounted } from \"./referenceCounting.js\";\n\nexport type {\n\tAllowOptional,\n\tRequiredFields,\n\tOptionalFields,\n\t_RecursiveTrick,\n\tAllowOptionalNotFlattened,\n\tRestrictiveReadonlyRecord,\n\tAssume,\n\t_InlineTrick,\n\tFlattenKeys,\n} from \"./typeUtils.js\";\n\nexport {\n\ttype BrandedKey,\n\ttype BrandedKeyContent,\n\ttype BrandedMapSubset,\n\tgetOrCreateSlotContent,\n\tbrandedSlot,\n} from \"./brandedMap.js\";\n\nexport {\n\tgetFirstEntryFromRangeMap,\n\tgetFromRangeMap,\n\ttype RangeEntry,\n\ttype RangeMap,\n\ttype RangeQueryResult,\n\tsetInRangeMap,\n\tdeleteFromRangeMap,\n} from \"./rangeMap.js\";\n\nexport {\n\ttype IdAllocator,\n\tidAllocatorFromMaxId,\n\tidAllocatorFromState,\n\ttype IdAllocationState,\n\tfakeIdAllocator,\n} from \"./idAllocator.js\";\n\nexport {\n\tBreakable,\n\ttype WithBreakable,\n\tbreakingMethod,\n\tthrowIfBroken,\n\tbreakingClass,\n} from \"./breakable.js\";\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree",
3
- "version": "2.1.0-281041",
3
+ "version": "2.1.0",
4
4
  "description": "Distributed tree",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -67,17 +67,17 @@
67
67
  "temp-directory": "nyc/.nyc_output"
68
68
  },
69
69
  "dependencies": {
70
- "@fluid-internal/client-utils": "2.1.0-281041",
71
- "@fluidframework/container-runtime": "2.1.0-281041",
72
- "@fluidframework/core-interfaces": "2.1.0-281041",
73
- "@fluidframework/core-utils": "2.1.0-281041",
74
- "@fluidframework/datastore-definitions": "2.1.0-281041",
75
- "@fluidframework/driver-definitions": "2.1.0-281041",
76
- "@fluidframework/id-compressor": "2.1.0-281041",
77
- "@fluidframework/runtime-definitions": "2.1.0-281041",
78
- "@fluidframework/runtime-utils": "2.1.0-281041",
79
- "@fluidframework/shared-object-base": "2.1.0-281041",
80
- "@fluidframework/telemetry-utils": "2.1.0-281041",
70
+ "@fluid-internal/client-utils": "~2.1.0",
71
+ "@fluidframework/container-runtime": "~2.1.0",
72
+ "@fluidframework/core-interfaces": "~2.1.0",
73
+ "@fluidframework/core-utils": "~2.1.0",
74
+ "@fluidframework/datastore-definitions": "~2.1.0",
75
+ "@fluidframework/driver-definitions": "~2.1.0",
76
+ "@fluidframework/id-compressor": "~2.1.0",
77
+ "@fluidframework/runtime-definitions": "~2.1.0",
78
+ "@fluidframework/runtime-utils": "~2.1.0",
79
+ "@fluidframework/shared-object-base": "~2.1.0",
80
+ "@fluidframework/telemetry-utils": "~2.1.0",
81
81
  "@sinclair/typebox": "^0.32.29",
82
82
  "@tylerbu/sorted-btree-es6": "^1.8.0",
83
83
  "@ungap/structured-clone": "^1.2.0",
@@ -86,19 +86,19 @@
86
86
  "devDependencies": {
87
87
  "@arethetypeswrong/cli": "^0.15.2",
88
88
  "@biomejs/biome": "~1.8.3",
89
- "@fluid-internal/mocha-test-setup": "2.1.0-281041",
90
- "@fluid-private/stochastic-test-utils": "2.1.0-281041",
91
- "@fluid-private/test-dds-utils": "2.1.0-281041",
92
- "@fluid-private/test-drivers": "2.1.0-281041",
89
+ "@fluid-internal/mocha-test-setup": "~2.1.0",
90
+ "@fluid-private/stochastic-test-utils": "~2.1.0",
91
+ "@fluid-private/test-dds-utils": "~2.1.0",
92
+ "@fluid-private/test-drivers": "~2.1.0",
93
93
  "@fluid-tools/benchmark": "^0.48.0",
94
- "@fluid-tools/build-cli": "^0.40.0",
94
+ "@fluid-tools/build-cli": "^0.41.0",
95
95
  "@fluidframework/build-common": "^2.0.3",
96
- "@fluidframework/build-tools": "^0.40.0",
97
- "@fluidframework/container-definitions": "2.1.0-281041",
98
- "@fluidframework/container-loader": "2.1.0-281041",
96
+ "@fluidframework/build-tools": "^0.41.0",
97
+ "@fluidframework/container-definitions": "~2.1.0",
98
+ "@fluidframework/container-loader": "~2.1.0",
99
99
  "@fluidframework/eslint-config-fluid": "^5.3.0",
100
- "@fluidframework/test-runtime-utils": "2.1.0-281041",
101
- "@fluidframework/test-utils": "2.1.0-281041",
100
+ "@fluidframework/test-runtime-utils": "~2.1.0",
101
+ "@fluidframework/test-utils": "~2.1.0",
102
102
  "@fluidframework/tree-previous": "npm:@fluidframework/tree@2.0.0",
103
103
  "@microsoft/api-extractor": "^7.45.1",
104
104
  "@types/diff": "^3.5.1",
@@ -3,6 +3,7 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
+ import type { SessionSpaceCompressedId } from "@fluidframework/id-compressor";
6
7
  import { assert } from "@fluidframework/core-utils/internal";
7
8
 
8
9
  import type { RevisionTagCodec } from "../rebase/index.js";
@@ -61,12 +62,19 @@ export function initializeForest(
61
62
  const delta: DeltaRoot = deltaForRootInitialization(content);
62
63
  let visitor = forest.acquireVisitor();
63
64
  if (visitAnchors) {
64
- assert(forest.anchors.isEmpty(), "anchor set must be empty");
65
+ assert(forest.anchors.isEmpty(), 0x9b7 /* anchor set must be empty */);
65
66
  const anchorVisitor = forest.anchors.acquireVisitor();
66
67
  visitor = combineVisitors([visitor, anchorVisitor], [anchorVisitor]);
67
68
  }
68
69
 
69
- visitDelta(delta, visitor, makeDetachedFieldIndex("init", revisionTagCodec, idCompressor));
70
+ // any detached trees built here are immediately attached so the revision used here doesn't matter
71
+ // we use a dummy revision to make correctness checks in the detached field index easier
72
+ visitDelta(
73
+ delta,
74
+ visitor,
75
+ makeDetachedFieldIndex("init", revisionTagCodec, idCompressor),
76
+ 0 as SessionSpaceCompressedId,
77
+ );
70
78
  visitor.free();
71
79
  }
72
80
 
@@ -334,6 +334,20 @@ export class AnchorSet implements Listenable<AnchorSetRootEvents>, AnchorLocator
334
334
  return this.root.slots;
335
335
  }
336
336
 
337
+ public *[Symbol.iterator](): IterableIterator<AnchorNode> {
338
+ const stack: PathNode[] = [];
339
+ let node: PathNode | undefined = this.root;
340
+ while (node !== undefined) {
341
+ yield node;
342
+ for (const [_, children] of node.children) {
343
+ for (const child of children) {
344
+ stack.push(child);
345
+ }
346
+ }
347
+ node = stack.pop();
348
+ }
349
+ }
350
+
337
351
  public on<K extends keyof AnchorSetRootEvents>(
338
352
  eventName: K,
339
353
  listener: AnchorSetRootEvents[K],