@fluidframework/tree 2.4.0 → 2.5.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 (446) hide show
  1. package/.vscode/settings.json +12 -1
  2. package/CHANGELOG.md +371 -0
  3. package/api-report/tree.alpha.api.md +271 -80
  4. package/api-report/tree.beta.api.md +100 -51
  5. package/api-report/tree.legacy.alpha.api.md +99 -50
  6. package/api-report/tree.legacy.public.api.md +99 -50
  7. package/api-report/tree.public.api.md +99 -50
  8. package/dist/alpha.d.ts +32 -2
  9. package/dist/beta.d.ts +6 -0
  10. package/dist/codec/codec.d.ts +24 -0
  11. package/dist/codec/codec.d.ts.map +1 -1
  12. package/dist/codec/codec.js +26 -1
  13. package/dist/codec/codec.js.map +1 -1
  14. package/dist/codec/index.d.ts +1 -1
  15. package/dist/codec/index.d.ts.map +1 -1
  16. package/dist/codec/index.js +2 -1
  17. package/dist/codec/index.js.map +1 -1
  18. package/dist/core/rebase/index.d.ts +2 -2
  19. package/dist/core/rebase/index.d.ts.map +1 -1
  20. package/dist/core/rebase/index.js +2 -2
  21. package/dist/core/rebase/index.js.map +1 -1
  22. package/dist/core/rebase/types.d.ts +0 -4
  23. package/dist/core/rebase/types.d.ts.map +1 -1
  24. package/dist/core/rebase/types.js +1 -7
  25. package/dist/core/rebase/types.js.map +1 -1
  26. package/dist/core/rebase/utils.d.ts +1 -0
  27. package/dist/core/rebase/utils.d.ts.map +1 -1
  28. package/dist/core/rebase/utils.js +29 -4
  29. package/dist/core/rebase/utils.js.map +1 -1
  30. package/dist/events/interop.d.ts +1 -7
  31. package/dist/events/interop.d.ts.map +1 -1
  32. package/dist/events/interop.js.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -1
  34. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  36. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  37. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
  38. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  39. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  40. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
  41. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  42. package/dist/feature-libraries/flex-tree/lazyNode.js +3 -0
  43. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  44. package/dist/feature-libraries/object-forest/objectForest.js +1 -1
  45. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  46. package/dist/feature-libraries/treeCursorUtils.js +2 -2
  47. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  48. package/dist/index.d.ts +4 -4
  49. package/dist/index.d.ts.map +1 -1
  50. package/dist/index.js +12 -7
  51. package/dist/index.js.map +1 -1
  52. package/dist/internalTypes.d.ts +1 -1
  53. package/dist/internalTypes.d.ts.map +1 -1
  54. package/dist/internalTypes.js.map +1 -1
  55. package/dist/legacy.d.ts +6 -0
  56. package/dist/packageVersion.d.ts +1 -1
  57. package/dist/packageVersion.js +1 -1
  58. package/dist/packageVersion.js.map +1 -1
  59. package/dist/public.d.ts +6 -0
  60. package/dist/shared-tree/independentView.d.ts +57 -0
  61. package/dist/shared-tree/independentView.d.ts.map +1 -0
  62. package/dist/shared-tree/independentView.js +89 -0
  63. package/dist/shared-tree/independentView.js.map +1 -0
  64. package/dist/shared-tree/index.d.ts +3 -1
  65. package/dist/shared-tree/index.d.ts.map +1 -1
  66. package/dist/shared-tree/index.js +6 -1
  67. package/dist/shared-tree/index.js.map +1 -1
  68. package/dist/shared-tree/schematizingTreeView.d.ts +12 -8
  69. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  70. package/dist/shared-tree/schematizingTreeView.js +28 -0
  71. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  72. package/dist/shared-tree/sharedTree.d.ts +10 -7
  73. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  74. package/dist/shared-tree/sharedTree.js.map +1 -1
  75. package/dist/shared-tree/treeApi.d.ts +6 -6
  76. package/dist/shared-tree/treeApi.d.ts.map +1 -1
  77. package/dist/shared-tree/treeApi.js.map +1 -1
  78. package/dist/shared-tree/treeApiAlpha.d.ts +147 -0
  79. package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -0
  80. package/dist/shared-tree/treeApiAlpha.js +122 -0
  81. package/dist/shared-tree/treeApiAlpha.js.map +1 -0
  82. package/dist/shared-tree/treeCheckout.d.ts +12 -7
  83. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  84. package/dist/shared-tree/treeCheckout.js +11 -4
  85. package/dist/shared-tree/treeCheckout.js.map +1 -1
  86. package/dist/shared-tree-core/editManager.d.ts +13 -6
  87. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  88. package/dist/shared-tree-core/editManager.js +80 -33
  89. package/dist/shared-tree-core/editManager.js.map +1 -1
  90. package/dist/shared-tree-core/sharedTreeCore.d.ts +1 -0
  91. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  92. package/dist/shared-tree-core/sharedTreeCore.js +28 -3
  93. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  94. package/dist/simple-tree/api/conciseTree.d.ts +2 -1
  95. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  96. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  97. package/dist/simple-tree/api/create.d.ts +6 -24
  98. package/dist/simple-tree/api/create.d.ts.map +1 -1
  99. package/dist/simple-tree/api/create.js +4 -19
  100. package/dist/simple-tree/api/create.js.map +1 -1
  101. package/dist/simple-tree/api/customTree.d.ts +1 -0
  102. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  103. package/dist/simple-tree/api/customTree.js +2 -2
  104. package/dist/simple-tree/api/customTree.js.map +1 -1
  105. package/dist/simple-tree/api/index.d.ts +7 -7
  106. package/dist/simple-tree/api/index.d.ts.map +1 -1
  107. package/dist/simple-tree/api/index.js +10 -2
  108. package/dist/simple-tree/api/index.js.map +1 -1
  109. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
  110. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  111. package/dist/simple-tree/api/schemaCreationUtilities.js +31 -21
  112. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  113. package/dist/simple-tree/api/schemaFactory.d.ts +16 -12
  114. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  115. package/dist/simple-tree/api/schemaFactory.js +4 -0
  116. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  117. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
  118. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  119. package/dist/simple-tree/api/storedSchema.js +2 -2
  120. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  121. package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  122. package/dist/simple-tree/api/tree.d.ts +122 -5
  123. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  124. package/dist/simple-tree/api/tree.js +12 -4
  125. package/dist/simple-tree/api/tree.js.map +1 -1
  126. package/dist/simple-tree/api/treeApiBeta.d.ts +8 -5
  127. package/dist/simple-tree/api/treeApiBeta.d.ts.map +1 -1
  128. package/dist/simple-tree/api/treeApiBeta.js +3 -15
  129. package/dist/simple-tree/api/treeApiBeta.js.map +1 -1
  130. package/dist/simple-tree/api/typesUnsafe.d.ts +69 -17
  131. package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  132. package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
  133. package/dist/simple-tree/api/verboseTree.d.ts +3 -0
  134. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  135. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  136. package/dist/simple-tree/arrayNode.d.ts +15 -4
  137. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  138. package/dist/simple-tree/arrayNode.js +1 -1
  139. package/dist/simple-tree/arrayNode.js.map +1 -1
  140. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  141. package/dist/simple-tree/core/treeNodeSchema.d.ts +51 -11
  142. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  143. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  144. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
  145. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  146. package/dist/simple-tree/core/unhydratedFlexTree.js +3 -0
  147. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  148. package/dist/simple-tree/core/withType.d.ts +2 -1
  149. package/dist/simple-tree/core/withType.d.ts.map +1 -1
  150. package/dist/simple-tree/core/withType.js.map +1 -1
  151. package/dist/simple-tree/createContext.js +2 -2
  152. package/dist/simple-tree/createContext.js.map +1 -1
  153. package/dist/simple-tree/index.d.ts +6 -6
  154. package/dist/simple-tree/index.d.ts.map +1 -1
  155. package/dist/simple-tree/index.js +15 -5
  156. package/dist/simple-tree/index.js.map +1 -1
  157. package/dist/simple-tree/leafNodeSchema.d.ts +6 -5
  158. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  159. package/dist/simple-tree/leafNodeSchema.js +3 -0
  160. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  161. package/dist/simple-tree/mapNode.d.ts +1 -1
  162. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  163. package/dist/simple-tree/mapNode.js +6 -0
  164. package/dist/simple-tree/mapNode.js.map +1 -1
  165. package/dist/simple-tree/objectNode.d.ts +4 -2
  166. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  167. package/dist/simple-tree/objectNode.js.map +1 -1
  168. package/dist/simple-tree/schemaTypes.d.ts +210 -18
  169. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  170. package/dist/simple-tree/schemaTypes.js +66 -1
  171. package/dist/simple-tree/schemaTypes.js.map +1 -1
  172. package/dist/simple-tree/toMapTree.d.ts +4 -2
  173. package/dist/simple-tree/toMapTree.d.ts.map +1 -1
  174. package/dist/simple-tree/toMapTree.js.map +1 -1
  175. package/dist/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
  176. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -0
  177. package/dist/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
  178. package/dist/simple-tree/toStoredSchema.js.map +1 -0
  179. package/dist/simple-tree/treeNodeValid.d.ts +5 -1
  180. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  181. package/dist/simple-tree/treeNodeValid.js +7 -1
  182. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  183. package/dist/util/index.d.ts +3 -2
  184. package/dist/util/index.d.ts.map +1 -1
  185. package/dist/util/index.js +3 -1
  186. package/dist/util/index.js.map +1 -1
  187. package/dist/util/typeCheck.d.ts +9 -0
  188. package/dist/util/typeCheck.d.ts.map +1 -1
  189. package/dist/util/typeCheck.js.map +1 -1
  190. package/dist/util/typeUtils.d.ts +61 -0
  191. package/dist/util/typeUtils.d.ts.map +1 -1
  192. package/dist/util/typeUtils.js +27 -0
  193. package/dist/util/typeUtils.js.map +1 -1
  194. package/dist/util/utils.d.ts +7 -3
  195. package/dist/util/utils.d.ts.map +1 -1
  196. package/dist/util/utils.js +13 -3
  197. package/dist/util/utils.js.map +1 -1
  198. package/lib/alpha.d.ts +32 -2
  199. package/lib/beta.d.ts +6 -0
  200. package/lib/codec/codec.d.ts +24 -0
  201. package/lib/codec/codec.d.ts.map +1 -1
  202. package/lib/codec/codec.js +25 -0
  203. package/lib/codec/codec.js.map +1 -1
  204. package/lib/codec/index.d.ts +1 -1
  205. package/lib/codec/index.d.ts.map +1 -1
  206. package/lib/codec/index.js +1 -1
  207. package/lib/codec/index.js.map +1 -1
  208. package/lib/core/rebase/index.d.ts +2 -2
  209. package/lib/core/rebase/index.d.ts.map +1 -1
  210. package/lib/core/rebase/index.js +2 -2
  211. package/lib/core/rebase/index.js.map +1 -1
  212. package/lib/core/rebase/types.d.ts +0 -4
  213. package/lib/core/rebase/types.d.ts.map +1 -1
  214. package/lib/core/rebase/types.js +0 -5
  215. package/lib/core/rebase/types.js.map +1 -1
  216. package/lib/core/rebase/utils.d.ts +1 -0
  217. package/lib/core/rebase/utils.d.ts.map +1 -1
  218. package/lib/core/rebase/utils.js +27 -3
  219. package/lib/core/rebase/utils.js.map +1 -1
  220. package/lib/events/interop.d.ts +1 -7
  221. package/lib/events/interop.d.ts.map +1 -1
  222. package/lib/events/interop.js.map +1 -1
  223. package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
  224. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  225. package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  226. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  227. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +8 -1
  228. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  229. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  230. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +2 -1
  231. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  232. package/lib/feature-libraries/flex-tree/lazyNode.js +3 -0
  233. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  234. package/lib/feature-libraries/object-forest/objectForest.js +1 -1
  235. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  236. package/lib/feature-libraries/treeCursorUtils.js +2 -2
  237. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  238. package/lib/index.d.ts +4 -4
  239. package/lib/index.d.ts.map +1 -1
  240. package/lib/index.js +4 -3
  241. package/lib/index.js.map +1 -1
  242. package/lib/internalTypes.d.ts +1 -1
  243. package/lib/internalTypes.d.ts.map +1 -1
  244. package/lib/internalTypes.js.map +1 -1
  245. package/lib/legacy.d.ts +6 -0
  246. package/lib/packageVersion.d.ts +1 -1
  247. package/lib/packageVersion.js +1 -1
  248. package/lib/packageVersion.js.map +1 -1
  249. package/lib/public.d.ts +6 -0
  250. package/lib/shared-tree/independentView.d.ts +57 -0
  251. package/lib/shared-tree/independentView.d.ts.map +1 -0
  252. package/lib/shared-tree/independentView.js +84 -0
  253. package/lib/shared-tree/independentView.js.map +1 -0
  254. package/lib/shared-tree/index.d.ts +3 -1
  255. package/lib/shared-tree/index.d.ts.map +1 -1
  256. package/lib/shared-tree/index.js +2 -0
  257. package/lib/shared-tree/index.js.map +1 -1
  258. package/lib/shared-tree/schematizingTreeView.d.ts +12 -8
  259. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  260. package/lib/shared-tree/schematizingTreeView.js +29 -1
  261. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  262. package/lib/shared-tree/sharedTree.d.ts +10 -7
  263. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  264. package/lib/shared-tree/sharedTree.js.map +1 -1
  265. package/lib/shared-tree/treeApi.d.ts +6 -6
  266. package/lib/shared-tree/treeApi.d.ts.map +1 -1
  267. package/lib/shared-tree/treeApi.js.map +1 -1
  268. package/lib/shared-tree/treeApiAlpha.d.ts +147 -0
  269. package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -0
  270. package/lib/shared-tree/treeApiAlpha.js +119 -0
  271. package/lib/shared-tree/treeApiAlpha.js.map +1 -0
  272. package/lib/shared-tree/treeCheckout.d.ts +12 -7
  273. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  274. package/lib/shared-tree/treeCheckout.js +11 -4
  275. package/lib/shared-tree/treeCheckout.js.map +1 -1
  276. package/lib/shared-tree-core/editManager.d.ts +13 -6
  277. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  278. package/lib/shared-tree-core/editManager.js +80 -33
  279. package/lib/shared-tree-core/editManager.js.map +1 -1
  280. package/lib/shared-tree-core/sharedTreeCore.d.ts +1 -0
  281. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  282. package/lib/shared-tree-core/sharedTreeCore.js +29 -4
  283. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  284. package/lib/simple-tree/api/conciseTree.d.ts +2 -1
  285. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  286. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  287. package/lib/simple-tree/api/create.d.ts +6 -24
  288. package/lib/simple-tree/api/create.d.ts.map +1 -1
  289. package/lib/simple-tree/api/create.js +2 -16
  290. package/lib/simple-tree/api/create.js.map +1 -1
  291. package/lib/simple-tree/api/customTree.d.ts +1 -0
  292. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  293. package/lib/simple-tree/api/customTree.js +2 -2
  294. package/lib/simple-tree/api/customTree.js.map +1 -1
  295. package/lib/simple-tree/api/index.d.ts +7 -7
  296. package/lib/simple-tree/api/index.d.ts.map +1 -1
  297. package/lib/simple-tree/api/index.js +6 -4
  298. package/lib/simple-tree/api/index.js.map +1 -1
  299. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +25 -27
  300. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  301. package/lib/simple-tree/api/schemaCreationUtilities.js +30 -19
  302. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  303. package/lib/simple-tree/api/schemaFactory.d.ts +16 -12
  304. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  305. package/lib/simple-tree/api/schemaFactory.js +4 -0
  306. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  307. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +3 -3
  308. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  309. package/lib/simple-tree/api/storedSchema.js +1 -1
  310. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  311. package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  312. package/lib/simple-tree/api/tree.d.ts +122 -5
  313. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  314. package/lib/simple-tree/api/tree.js +9 -2
  315. package/lib/simple-tree/api/tree.js.map +1 -1
  316. package/lib/simple-tree/api/treeApiBeta.d.ts +8 -5
  317. package/lib/simple-tree/api/treeApiBeta.d.ts.map +1 -1
  318. package/lib/simple-tree/api/treeApiBeta.js +4 -16
  319. package/lib/simple-tree/api/treeApiBeta.js.map +1 -1
  320. package/lib/simple-tree/api/typesUnsafe.d.ts +69 -17
  321. package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  322. package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
  323. package/lib/simple-tree/api/verboseTree.d.ts +3 -0
  324. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  325. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  326. package/lib/simple-tree/arrayNode.d.ts +15 -4
  327. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  328. package/lib/simple-tree/arrayNode.js +1 -1
  329. package/lib/simple-tree/arrayNode.js.map +1 -1
  330. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  331. package/lib/simple-tree/core/treeNodeSchema.d.ts +51 -11
  332. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  333. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  334. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +2 -1
  335. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  336. package/lib/simple-tree/core/unhydratedFlexTree.js +4 -1
  337. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  338. package/lib/simple-tree/core/withType.d.ts +2 -1
  339. package/lib/simple-tree/core/withType.d.ts.map +1 -1
  340. package/lib/simple-tree/core/withType.js.map +1 -1
  341. package/lib/simple-tree/createContext.js +1 -1
  342. package/lib/simple-tree/createContext.js.map +1 -1
  343. package/lib/simple-tree/index.d.ts +6 -6
  344. package/lib/simple-tree/index.d.ts.map +1 -1
  345. package/lib/simple-tree/index.js +5 -5
  346. package/lib/simple-tree/index.js.map +1 -1
  347. package/lib/simple-tree/leafNodeSchema.d.ts +6 -5
  348. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  349. package/lib/simple-tree/leafNodeSchema.js +3 -0
  350. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  351. package/lib/simple-tree/mapNode.d.ts +1 -1
  352. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  353. package/lib/simple-tree/mapNode.js +6 -0
  354. package/lib/simple-tree/mapNode.js.map +1 -1
  355. package/lib/simple-tree/objectNode.d.ts +4 -2
  356. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  357. package/lib/simple-tree/objectNode.js.map +1 -1
  358. package/lib/simple-tree/schemaTypes.d.ts +210 -18
  359. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  360. package/lib/simple-tree/schemaTypes.js +64 -1
  361. package/lib/simple-tree/schemaTypes.js.map +1 -1
  362. package/lib/simple-tree/toMapTree.d.ts +4 -2
  363. package/lib/simple-tree/toMapTree.d.ts.map +1 -1
  364. package/lib/simple-tree/toMapTree.js.map +1 -1
  365. package/lib/simple-tree/{toFlexSchema.d.ts → toStoredSchema.d.ts} +1 -1
  366. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -0
  367. package/lib/simple-tree/{toFlexSchema.js → toStoredSchema.js} +1 -1
  368. package/lib/simple-tree/toStoredSchema.js.map +1 -0
  369. package/lib/simple-tree/treeNodeValid.d.ts +5 -1
  370. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  371. package/lib/simple-tree/treeNodeValid.js +7 -1
  372. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  373. package/lib/util/index.d.ts +3 -2
  374. package/lib/util/index.d.ts.map +1 -1
  375. package/lib/util/index.js +1 -0
  376. package/lib/util/index.js.map +1 -1
  377. package/lib/util/typeCheck.d.ts +9 -0
  378. package/lib/util/typeCheck.d.ts.map +1 -1
  379. package/lib/util/typeCheck.js.map +1 -1
  380. package/lib/util/typeUtils.d.ts +61 -0
  381. package/lib/util/typeUtils.d.ts.map +1 -1
  382. package/lib/util/typeUtils.js +25 -1
  383. package/lib/util/typeUtils.js.map +1 -1
  384. package/lib/util/utils.d.ts +7 -3
  385. package/lib/util/utils.d.ts.map +1 -1
  386. package/lib/util/utils.js +13 -3
  387. package/lib/util/utils.js.map +1 -1
  388. package/package.json +55 -30
  389. package/src/codec/codec.ts +25 -0
  390. package/src/codec/index.ts +1 -0
  391. package/src/core/rebase/index.ts +1 -1
  392. package/src/core/rebase/types.ts +0 -12
  393. package/src/core/rebase/utils.ts +35 -3
  394. package/src/events/interop.ts +1 -12
  395. package/src/feature-libraries/chunked-forest/basicChunk.ts +1 -1
  396. package/src/feature-libraries/chunked-forest/uniformChunk.ts +1 -1
  397. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +9 -0
  398. package/src/feature-libraries/flex-tree/lazyNode.ts +5 -0
  399. package/src/feature-libraries/object-forest/objectForest.ts +1 -1
  400. package/src/feature-libraries/treeCursorUtils.ts +2 -2
  401. package/src/index.ts +36 -6
  402. package/src/internalTypes.ts +4 -0
  403. package/src/packageVersion.ts +1 -1
  404. package/src/shared-tree/independentView.ts +176 -0
  405. package/src/shared-tree/index.ts +9 -1
  406. package/src/shared-tree/schematizingTreeView.ts +64 -13
  407. package/src/shared-tree/sharedTree.ts +29 -9
  408. package/src/shared-tree/treeApi.ts +19 -9
  409. package/src/shared-tree/treeApiAlpha.ts +401 -0
  410. package/src/shared-tree/treeCheckout.ts +28 -5
  411. package/src/shared-tree-core/editManager.ts +126 -59
  412. package/src/shared-tree-core/sharedTreeCore.ts +37 -8
  413. package/src/simple-tree/api/conciseTree.ts +2 -1
  414. package/src/simple-tree/api/create.ts +33 -65
  415. package/src/simple-tree/api/customTree.ts +3 -2
  416. package/src/simple-tree/api/index.ts +19 -8
  417. package/src/simple-tree/api/schemaCreationUtilities.ts +59 -37
  418. package/src/simple-tree/api/schemaFactory.ts +28 -12
  419. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +3 -3
  420. package/src/simple-tree/api/storedSchema.ts +1 -1
  421. package/src/simple-tree/api/tree.ts +152 -7
  422. package/src/simple-tree/api/treeApiBeta.ts +35 -31
  423. package/src/simple-tree/api/typesUnsafe.ts +125 -30
  424. package/src/simple-tree/api/verboseTree.ts +3 -0
  425. package/src/simple-tree/arrayNode.ts +38 -17
  426. package/src/simple-tree/core/getOrCreateNode.ts +1 -1
  427. package/src/simple-tree/core/treeNodeSchema.ts +107 -34
  428. package/src/simple-tree/core/unhydratedFlexTree.ts +6 -0
  429. package/src/simple-tree/core/withType.ts +2 -1
  430. package/src/simple-tree/createContext.ts +1 -1
  431. package/src/simple-tree/index.ts +34 -3
  432. package/src/simple-tree/leafNodeSchema.ts +6 -1
  433. package/src/simple-tree/mapNode.ts +13 -4
  434. package/src/simple-tree/objectNode.ts +5 -3
  435. package/src/simple-tree/schemaTypes.ts +342 -36
  436. package/src/simple-tree/toMapTree.ts +4 -1
  437. package/src/simple-tree/treeNodeValid.ts +11 -1
  438. package/src/util/index.ts +7 -0
  439. package/src/util/typeCheck.ts +13 -0
  440. package/src/util/typeUtils.ts +87 -0
  441. package/src/util/utils.ts +20 -7
  442. package/dist/simple-tree/toFlexSchema.d.ts.map +0 -1
  443. package/dist/simple-tree/toFlexSchema.js.map +0 -1
  444. package/lib/simple-tree/toFlexSchema.d.ts.map +0 -1
  445. package/lib/simple-tree/toFlexSchema.js.map +0 -1
  446. /package/src/simple-tree/{toFlexSchema.ts → toStoredSchema.ts} +0 -0
@@ -5,21 +5,10 @@
5
5
 
6
6
  import type { IEvent } from "@fluidframework/core-interfaces";
7
7
  import type { Listeners } from "./listeners.js";
8
+ import type { UnionToIntersection } from "../util/index.js";
8
9
 
9
10
  // TODO: this file is currently unused. Use it or remove it.
10
11
 
11
- /**
12
- * Convert a union of types to an intersection of those types. Useful for `TransformEvents`.
13
- * @privateRemarks
14
- * First an always true extends clause is used (T extends T) to distribute T into to a union of types contravariant over each member of the T union.
15
- * Then the constraint on the type parameter in this new context is inferred, giving the intersection.
16
- */
17
- export type UnionToIntersection<T> = (T extends T ? (k: T) => unknown : never) extends (
18
- k: infer U,
19
- ) => unknown
20
- ? U
21
- : never;
22
-
23
12
  /**
24
13
  * Converts a {@link Listeners} type (i.e. the event registry for a {@link Listenable}) into a type consumable
25
14
  * by an IEventProvider from `@fluidframework/core-interfaces`.
@@ -253,7 +253,7 @@ export class BasicChunkCursor extends SynchronousCursor implements ChunkedCursor
253
253
  return {
254
254
  field:
255
255
  this.indexStack.length === 1
256
- ? prefix?.rootFieldOverride ?? this.getFieldKey()
256
+ ? (prefix?.rootFieldOverride ?? this.getFieldKey())
257
257
  : this.getFieldKey(),
258
258
  parent: this.getOffsetPath(1, prefix),
259
259
  };
@@ -533,7 +533,7 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
533
533
  this.indexOfField =
534
534
  fieldInfo === undefined
535
535
  ? fieldMap.size
536
- : fieldInfo.indexOfParentField ?? fail("children should have parents");
536
+ : (fieldInfo.indexOfParentField ?? fail("children should have parents"));
537
537
  this.fieldKey = key;
538
538
  this.mode = CursorLocationType.Fields;
539
539
  }
@@ -9,6 +9,7 @@ import {
9
9
  type FieldKey,
10
10
  type FieldKindIdentifier,
11
11
  type FieldUpPath,
12
+ type ITreeCursorSynchronous,
12
13
  type TreeNodeSchemaIdentifier,
13
14
  type TreeValue,
14
15
  anchorSlot,
@@ -184,6 +185,14 @@ export interface FlexTreeNode extends FlexTreeEntity {
184
185
  * If well-formed, it must follow this schema.
185
186
  */
186
187
  readonly schema: TreeNodeSchemaIdentifier;
188
+
189
+ /**
190
+ * Get a cursor for the underlying data.
191
+ * @remarks
192
+ * This cursor might be one the node uses in its implementation, and thus must be returned to its original location before using any other APIs to interact with the tree.
193
+ * Must not be held onto across edits or any other tree API use.
194
+ */
195
+ borrowCursor(): ITreeCursorSynchronous;
187
196
  }
188
197
 
189
198
  /**
@@ -10,6 +10,7 @@ import {
10
10
  type AnchorNode,
11
11
  CursorLocationType,
12
12
  type FieldKey,
13
+ type ITreeCursorSynchronous,
13
14
  type FieldKindIdentifier,
14
15
  type ITreeSubscriptionCursor,
15
16
  type TreeNavigationResult,
@@ -91,6 +92,10 @@ export class LazyTreeNode extends LazyEntity<Anchor> implements FlexTreeNode {
91
92
  this.#removeDeleteCallback = anchorNode.on("afterDestroy", cleanupTree);
92
93
  }
93
94
 
95
+ public borrowCursor(): ITreeCursorSynchronous {
96
+ return this[cursorSymbol] as ITreeCursorSynchronous;
97
+ }
98
+
94
99
  protected override [tryMoveCursorToAnchorSymbol](
95
100
  cursor: ITreeSubscriptionCursor,
96
101
  ): TreeNavigationResult {
@@ -140,7 +140,7 @@ export class ObjectForest implements IEditableForest {
140
140
  );
141
141
  if (this.currentCursors.size > 1) {
142
142
  const unexpectedSources = [...this.currentCursors].flatMap((c) =>
143
- c === cursor ? [] : c.source ?? null,
143
+ c === cursor ? [] : (c.source ?? null),
144
144
  );
145
145
 
146
146
  throw new Error(
@@ -194,7 +194,7 @@ class StackCursor<TNode> extends SynchronousCursor implements CursorWithNode<TNo
194
194
  return {
195
195
  field:
196
196
  this.indexStack.length === 1
197
- ? prefix?.rootFieldOverride ?? this.getFieldKey()
197
+ ? (prefix?.rootFieldOverride ?? this.getFieldKey())
198
198
  : this.getFieldKey(),
199
199
  parent: this.getOffsetPath(1, prefix),
200
200
  };
@@ -427,7 +427,7 @@ export function prefixFieldPath(
427
427
  return path;
428
428
  }
429
429
  return {
430
- field: path.parent === undefined ? prefix.rootFieldOverride ?? path.field : path.field,
430
+ field: path.parent === undefined ? (prefix.rootFieldOverride ?? path.field) : path.field,
431
431
  parent: prefixPath(prefix, path.parent),
432
432
  };
433
433
  }
package/src/index.ts CHANGED
@@ -58,8 +58,12 @@ export {
58
58
  rollback,
59
59
  type ForestOptions,
60
60
  getBranch,
61
- type TreeBranch,
61
+ type BranchableTree,
62
62
  type TreeBranchFork,
63
+ independentInitializedView,
64
+ type ViewContent,
65
+ TreeAlpha,
66
+ independentView,
63
67
  } from "./shared-tree/index.js";
64
68
 
65
69
  export {
@@ -114,6 +118,8 @@ export {
114
118
  type InsertableObjectFromSchemaRecordUnsafe,
115
119
  type InsertableTreeFieldFromImplicitFieldUnsafe,
116
120
  type FieldSchemaUnsafe,
121
+ type TreeNodeSchemaClassUnsafe,
122
+ type InsertableTreeNodeFromAllowedTypesUnsafe,
117
123
  // System types (not in Internal types for various reasons, like doc links or cannot be named errors).
118
124
  type typeSchemaSymbol,
119
125
  type TreeNodeSchemaNonClass,
@@ -124,7 +130,15 @@ export {
124
130
  adaptEnum,
125
131
  enumFromStrings,
126
132
  singletonSchema,
127
- typedObjectValues,
133
+ type UnsafeUnknownSchema,
134
+ type TreeViewAlpha,
135
+ type InsertableField,
136
+ type Insertable,
137
+ type InsertableContent,
138
+ type FactoryContent,
139
+ type FactoryContentObject,
140
+ type ReadableField,
141
+ type ReadSchema,
128
142
  // test recursive schema for checking that d.ts files handles schema correctly
129
143
  test_RecursiveObject,
130
144
  test_RecursiveObject_base,
@@ -132,8 +146,13 @@ export {
132
146
  // Beta APIs
133
147
  TreeBeta,
134
148
  type TreeChangeEventsBeta,
149
+ type VerboseTreeNode,
150
+ type EncodeOptions,
151
+ type ParseOptions,
152
+ type VerboseTree,
135
153
  extractPersistedSchema,
136
154
  comparePersistedSchema,
155
+ type ConciseTree,
137
156
  // Back to normal types
138
157
  type JsonTreeSchema,
139
158
  type JsonSchemaId,
@@ -151,16 +170,23 @@ export {
151
170
  getJsonSchema,
152
171
  type LazyItem,
153
172
  type Unenforced,
173
+ type ReadonlyArrayNode,
174
+ type InsertableTreeNodeFromAllowedTypes,
175
+ type Input,
176
+ type TreeBranch,
177
+ type TreeBranchEvents,
178
+ asTreeViewAlpha,
154
179
  } from "./simple-tree/index.js";
155
180
  export {
156
181
  SharedTree,
157
182
  configuredSharedTree,
158
183
  } from "./treeFactory.js";
159
184
 
160
- export type {
161
- ICodecOptions,
162
- JsonValidator,
163
- SchemaValidationFunction,
185
+ export {
186
+ type ICodecOptions,
187
+ type JsonValidator,
188
+ type SchemaValidationFunction,
189
+ FluidClientVersion,
164
190
  } from "./codec/index.js";
165
191
  export { noopValidator } from "./codec/index.js";
166
192
  export { typeboxValidator } from "./external-utilities/index.js";
@@ -171,6 +197,10 @@ export {
171
197
  type RestrictiveReadonlyRecord,
172
198
  type RestrictiveStringRecord,
173
199
  type MakeNominal,
200
+ type IsUnion,
201
+ type UnionToIntersection,
202
+ type UnionToTuple,
203
+ type PopUnion,
174
204
  } from "./util/index.js";
175
205
 
176
206
  import * as InternalTypes from "./internalTypes.js";
@@ -10,6 +10,7 @@
10
10
  export type { _InlineTrick, FlattenKeys } from "./util/index.js";
11
11
  export type {
12
12
  ApplyKind,
13
+ ApplyKindInput,
13
14
  NodeBuilderData,
14
15
  FieldHasDefault,
15
16
  TreeArrayNodeBase,
@@ -33,6 +34,9 @@ export type {
33
34
  NodeBuilderDataUnsafe,
34
35
  NodeFromSchemaUnsafe,
35
36
  ReadonlyMapInlined,
37
+ TreeNodeSchemaUnsafe,
38
+ AllowedTypesUnsafe,
39
+ TreeNodeSchemaNonClassUnsafe,
36
40
  } from "./simple-tree/index.js";
37
41
  export type { FlexList, FlexListToUnion, ExtractItemType } from "./simple-tree/index.js";
38
42
 
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/tree";
9
- export const pkgVersion = "2.4.0";
9
+ export const pkgVersion = "2.5.0";
@@ -0,0 +1,176 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { IFluidHandle } from "@fluidframework/core-interfaces";
7
+ import { assert } from "@fluidframework/core-utils/internal";
8
+ import {
9
+ type IIdCompressor,
10
+ createIdCompressor,
11
+ } from "@fluidframework/id-compressor/internal";
12
+ import type { ICodecOptions } from "../codec/index.js";
13
+ import {
14
+ type RevisionTag,
15
+ RevisionTagCodec,
16
+ TreeStoredSchemaRepository,
17
+ initializeForest,
18
+ type ITreeCursorSynchronous,
19
+ mapCursorField,
20
+ } from "../core/index.js";
21
+ import {
22
+ createNodeKeyManager,
23
+ makeFieldBatchCodec,
24
+ makeSchemaCodec,
25
+ type FieldBatchEncodingContext,
26
+ defaultSchemaPolicy,
27
+ chunkTree,
28
+ defaultChunkPolicy,
29
+ TreeCompressionStrategy,
30
+ } from "../feature-libraries/index.js";
31
+ // eslint-disable-next-line import/no-internal-modules
32
+ import type { Format } from "../feature-libraries/schema-index/format.js";
33
+ import type {
34
+ TreeViewConfiguration,
35
+ ImplicitFieldSchema,
36
+ TreeViewAlpha,
37
+ } from "../simple-tree/index.js";
38
+ import type { JsonCompatibleReadOnly, JsonCompatible } from "../util/index.js";
39
+ import {
40
+ buildConfiguredForest,
41
+ defaultSharedTreeOptions,
42
+ type ForestOptions,
43
+ } from "./sharedTree.js";
44
+ import { createTreeCheckout } from "./treeCheckout.js";
45
+ import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
46
+
47
+ /**
48
+ * Create an uninitialized {@link TreeView} that is not tied to any {@link ITree} instance.
49
+ *
50
+ * @remarks
51
+ * Such a view can never experience collaboration or be persisted to to a Fluid Container.
52
+ *
53
+ * This can be useful for testing, as well as use-cases like working on local files instead of documents stored in some Fluid service.
54
+ * @alpha
55
+ */
56
+ export function independentView<const TSchema extends ImplicitFieldSchema>(
57
+ config: TreeViewConfiguration<TSchema>,
58
+ options: ForestOptions & { idCompressor?: IIdCompressor | undefined },
59
+ ): TreeViewAlpha<TSchema> {
60
+ const idCompressor: IIdCompressor = options.idCompressor ?? createIdCompressor();
61
+ const mintRevisionTag = (): RevisionTag => idCompressor.generateCompressedId();
62
+ const revisionTagCodec = new RevisionTagCodec(idCompressor);
63
+ const schema = new TreeStoredSchemaRepository();
64
+ const forest = buildConfiguredForest(
65
+ options.forest ?? defaultSharedTreeOptions.forest,
66
+ schema,
67
+ idCompressor,
68
+ );
69
+ const checkout = createTreeCheckout(idCompressor, mintRevisionTag, revisionTagCodec, {
70
+ forest,
71
+ schema,
72
+ });
73
+ const out: TreeViewAlpha<TSchema> = new SchematizingSimpleTreeView<TSchema>(
74
+ checkout,
75
+ config,
76
+ createNodeKeyManager(idCompressor),
77
+ );
78
+ return out;
79
+ }
80
+ /**
81
+ * Create an initialized {@link TreeView} that is not tied to any {@link ITree} instance.
82
+ *
83
+ * @remarks
84
+ * Such a view can never experience collaboration or be persisted to to a Fluid Container.
85
+ *
86
+ * This can be useful for testing, as well as use-cases like working on local files instead of documents stored in some Fluid service.
87
+ * @alpha
88
+ */
89
+ export function independentInitializedView<const TSchema extends ImplicitFieldSchema>(
90
+ config: TreeViewConfiguration<TSchema>,
91
+ options: ForestOptions & ICodecOptions,
92
+ content: ViewContent,
93
+ ): TreeViewAlpha<TSchema> {
94
+ const idCompressor: IIdCompressor = content.idCompressor;
95
+ const mintRevisionTag = (): RevisionTag => idCompressor.generateCompressedId();
96
+ const revisionTagCodec = new RevisionTagCodec(idCompressor);
97
+
98
+ const fieldBatchCodec = makeFieldBatchCodec(options, 1);
99
+ const schemaCodec = makeSchemaCodec(options);
100
+
101
+ const schema = new TreeStoredSchemaRepository(schemaCodec.decode(content.schema as Format));
102
+ const forest = buildConfiguredForest(
103
+ options.forest ?? defaultSharedTreeOptions.forest,
104
+ schema,
105
+ idCompressor,
106
+ );
107
+
108
+ const context: FieldBatchEncodingContext = {
109
+ encodeType: TreeCompressionStrategy.Compressed,
110
+ idCompressor,
111
+ originatorId: idCompressor.localSessionId, // Is this right? If so, why is is needed?
112
+ schema: { schema, policy: defaultSchemaPolicy },
113
+ };
114
+
115
+ const fieldCursors = fieldBatchCodec.decode(content.tree as JsonCompatibleReadOnly, context);
116
+ assert(fieldCursors.length === 1, 0xa5b /* must have exactly 1 field in batch */);
117
+ // Checked above.
118
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
119
+ const cursors = fieldCursorToNodesCursors(fieldCursors[0]!);
120
+
121
+ initializeForest(forest, cursors, revisionTagCodec, idCompressor, false);
122
+
123
+ const checkout = createTreeCheckout(idCompressor, mintRevisionTag, revisionTagCodec, {
124
+ forest,
125
+ schema,
126
+ });
127
+ const out: TreeViewAlpha<TSchema> = new SchematizingSimpleTreeView<TSchema>(
128
+ checkout,
129
+ config,
130
+ createNodeKeyManager(idCompressor),
131
+ );
132
+ return out;
133
+ }
134
+
135
+ function fieldCursorToNodesCursors(
136
+ fieldCursor: ITreeCursorSynchronous,
137
+ ): ITreeCursorSynchronous[] {
138
+ return mapCursorField(fieldCursor, copyNodeCursor);
139
+ }
140
+
141
+ /**
142
+ * TODO: avoid needing this, or optimize it.
143
+ */
144
+ function copyNodeCursor(cursor: ITreeCursorSynchronous): ITreeCursorSynchronous {
145
+ const copy = chunkTree(cursor, {
146
+ policy: defaultChunkPolicy,
147
+ idCompressor: undefined,
148
+ }).cursor();
149
+ copy.enterNode(0);
150
+ return copy;
151
+ }
152
+
153
+ /**
154
+ * The portion of SharedTree data typically persisted by the container.
155
+ * Usable with {@link independentInitializedView} to create a {@link TreeView}
156
+ * without loading a container.
157
+ * @alpha
158
+ */
159
+ export interface ViewContent {
160
+ /**
161
+ * Compressed tree from {@link TreeAlpha.exportCompressed}.
162
+ * @remarks
163
+ * This is an owning reference:
164
+ * consumers of this content might modify this data in place (for example when applying edits) to avoid copying.
165
+ */
166
+ readonly tree: JsonCompatible<IFluidHandle>;
167
+ /**
168
+ * Persisted schema from {@link extractPersistedSchema}.
169
+ */
170
+ readonly schema: JsonCompatible;
171
+ /**
172
+ * IIdCompressor which will be used to decompress any compressed identifiers in `tree`
173
+ * as well as for any other identifiers added to the view.
174
+ */
175
+ readonly idCompressor: IIdCompressor;
176
+ }
@@ -26,7 +26,7 @@ export {
26
26
  type CheckoutEvents,
27
27
  type ITransaction,
28
28
  type ITreeCheckoutFork,
29
- type TreeBranch,
29
+ type BranchableTree,
30
30
  type TreeBranchFork,
31
31
  } from "./treeCheckout.js";
32
32
 
@@ -46,3 +46,11 @@ export {
46
46
  type RunTransaction,
47
47
  rollback,
48
48
  } from "./treeApi.js";
49
+
50
+ export { TreeAlpha } from "./treeApiAlpha.js";
51
+
52
+ export {
53
+ independentInitializedView,
54
+ type ViewContent,
55
+ independentView,
56
+ } from "./independentView.js";
@@ -29,8 +29,6 @@ import {
29
29
  type FieldSchema,
30
30
  type ImplicitFieldSchema,
31
31
  type SchemaCompatibilityStatus,
32
- type InsertableTreeFieldFromImplicitField,
33
- type TreeFieldFromImplicitField,
34
32
  type TreeView,
35
33
  type TreeViewEvents,
36
34
  getTreeNodeForField,
@@ -43,13 +41,23 @@ import {
43
41
  prepareContentForHydration,
44
42
  comparePersistedSchemaInternal,
45
43
  toStoredSchema,
44
+ type TreeViewAlpha,
45
+ type InsertableField,
46
+ type ReadableField,
47
+ type ReadSchema,
48
+ type UnsafeUnknownSchema,
49
+ type TreeBranch,
46
50
  } from "../simple-tree/index.js";
47
51
  import { Breakable, breakingClass, disposeSymbol, type WithBreakable } from "../util/index.js";
48
52
 
49
53
  import { canInitialize, ensureSchema, initialize } from "./schematizeTree.js";
50
54
  import type { ITreeCheckout, TreeCheckout } from "./treeCheckout.js";
51
55
  import { CheckoutFlexTreeView } from "./checkoutFlexTreeView.js";
52
- import { HydratedContext, SimpleContextSlot } from "../simple-tree/index.js";
56
+ import {
57
+ HydratedContext,
58
+ SimpleContextSlot,
59
+ areImplicitFieldSchemaEqual,
60
+ } from "../simple-tree/index.js";
53
61
  /**
54
62
  * Creating multiple tree views from the same checkout is not supported. This slot is used to detect if one already
55
63
  * exists and error if creating a second.
@@ -60,8 +68,9 @@ export const ViewSlot = anchorSlot<TreeView<ImplicitFieldSchema>>();
60
68
  * Implementation of TreeView wrapping a FlexTreeView.
61
69
  */
62
70
  @breakingClass
63
- export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitFieldSchema>
64
- implements TreeView<TRootSchema>, WithBreakable
71
+ export class SchematizingSimpleTreeView<
72
+ in out TRootSchema extends ImplicitFieldSchema | UnsafeUnknownSchema,
73
+ > implements TreeBranch, TreeViewAlpha<TRootSchema>, WithBreakable
65
74
  {
66
75
  /**
67
76
  * The view is set to undefined when this object is disposed or the view schema does not support viewing the document's stored schema.
@@ -96,7 +105,7 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
96
105
 
97
106
  public constructor(
98
107
  public readonly checkout: TreeCheckout,
99
- public readonly config: TreeViewConfiguration<TRootSchema>,
108
+ public readonly config: TreeViewConfiguration<ReadSchema<TRootSchema>>,
100
109
  public readonly nodeKeyManager: NodeKeyManager,
101
110
  public readonly breaker: Breakable = new Breakable("SchematizingSimpleTreeView"),
102
111
  private readonly onDispose?: () => void,
@@ -130,11 +139,17 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
130
139
  );
131
140
  }
132
141
 
133
- public get schema(): TRootSchema {
142
+ public hasRootSchema<TSchema extends ImplicitFieldSchema>(
143
+ schema: TSchema,
144
+ ): this is TreeViewAlpha<TSchema> {
145
+ return areImplicitFieldSchemaEqual(this.rootFieldSchema, schema);
146
+ }
147
+
148
+ public get schema(): ReadSchema<TRootSchema> {
134
149
  return this.config.schema;
135
150
  }
136
151
 
137
- public initialize(content: InsertableTreeFieldFromImplicitField<TRootSchema>): void {
152
+ public initialize(content: InsertableField<TRootSchema>): void {
138
153
  this.ensureUndisposed();
139
154
 
140
155
  const compatibility = this.compatibility;
@@ -144,7 +159,7 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
144
159
 
145
160
  this.runSchemaEdit(() => {
146
161
  const mapTree = mapTreeFromNodeData(
147
- content as InsertableContent,
162
+ content as InsertableContent | undefined,
148
163
  this.rootFieldSchema,
149
164
  this.nodeKeyManager,
150
165
  {
@@ -338,9 +353,13 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
338
353
  this.checkout.forest.anchors.slots.delete(ViewSlot);
339
354
  this.currentCompatibility = undefined;
340
355
  this.onDispose?.();
356
+ if (this.checkout.isBranch && !this.checkout.disposed) {
357
+ // All (non-main) branches are 1:1 with views, so if a user manually disposes a view, we should also dispose the checkout/branch.
358
+ this.checkout.dispose();
359
+ }
341
360
  }
342
361
 
343
- public get root(): TreeFieldFromImplicitField<TRootSchema> {
362
+ public get root(): ReadableField<TRootSchema> {
344
363
  this.breaker.use();
345
364
  if (!this.compatibility.canView) {
346
365
  throw new UsageError(
@@ -348,10 +367,10 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
348
367
  );
349
368
  }
350
369
  const view = this.getView();
351
- return getTreeNodeForField(view.flexTree) as TreeFieldFromImplicitField<TRootSchema>;
370
+ return getTreeNodeForField(view.flexTree) as ReadableField<TRootSchema>;
352
371
  }
353
372
 
354
- public set root(newRoot: InsertableTreeFieldFromImplicitField<TRootSchema>) {
373
+ public set root(newRoot: InsertableField<TRootSchema>) {
355
374
  this.breaker.use();
356
375
  if (!this.compatibility.canView) {
357
376
  throw new UsageError(
@@ -359,8 +378,40 @@ export class SchematizingSimpleTreeView<in out TRootSchema extends ImplicitField
359
378
  );
360
379
  }
361
380
  const view = this.getView();
362
- setField(view.context.root, this.rootFieldSchema, newRoot as InsertableContent);
381
+ setField(
382
+ view.context.root,
383
+ this.rootFieldSchema,
384
+ newRoot as InsertableContent | undefined,
385
+ );
386
+ }
387
+
388
+ // #region Branching
389
+
390
+ public fork(): ReturnType<TreeBranch["fork"]> & TreeViewAlpha<TRootSchema> {
391
+ return this.checkout.branch().viewWith(this.config);
392
+ }
393
+
394
+ public merge(context: TreeBranch, disposeMerged = true): void {
395
+ this.checkout.merge(getCheckout(context), disposeMerged);
396
+ }
397
+
398
+ public rebaseOnto(context: TreeBranch): void {
399
+ getCheckout(context).rebase(this.checkout);
400
+ }
401
+
402
+ // #endregion Branching
403
+ }
404
+
405
+ /**
406
+ * Get the {@link TreeCheckout} associated with a given {@link TreeBranch}.
407
+ * @remarks Currently, all contexts are also {@link SchematizingSimpleTreeView}s.
408
+ * Other checkout implementations (e.g. not associated with a view) may be supported in the future.
409
+ */
410
+ function getCheckout(context: TreeBranch): TreeCheckout {
411
+ if (context instanceof SchematizingSimpleTreeView) {
412
+ return context.checkout;
363
413
  }
414
+ throw new UsageError("Unsupported context implementation");
364
415
  }
365
416
 
366
417
  /**
@@ -53,8 +53,11 @@ import {
53
53
  import type {
54
54
  ITree,
55
55
  ImplicitFieldSchema,
56
+ ReadSchema,
56
57
  TreeView,
58
+ TreeViewAlpha,
57
59
  TreeViewConfiguration,
60
+ UnsafeUnknownSchema,
58
61
  } from "../simple-tree/index.js";
59
62
 
60
63
  import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
@@ -65,7 +68,7 @@ import type { SharedTreeEditBuilder } from "./sharedTreeEditBuilder.js";
65
68
  import {
66
69
  type CheckoutEvents,
67
70
  type TreeCheckout,
68
- type TreeBranch,
71
+ type BranchableTree,
69
72
  createTreeCheckout,
70
73
  } from "./treeCheckout.js";
71
74
  import { breakingClass, throwIfBroken } from "../util/index.js";
@@ -324,10 +327,21 @@ export class SharedTree
324
327
  }
325
328
  }
326
329
 
330
+ // For the new TreeViewAlpha API
331
+ public viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(
332
+ config: TreeViewConfiguration<ReadSchema<TRoot>>,
333
+ ): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>>;
334
+
335
+ // For the old TreeView API
327
336
  public viewWith<TRoot extends ImplicitFieldSchema>(
328
337
  config: TreeViewConfiguration<TRoot>,
329
- ): SchematizingSimpleTreeView<TRoot> {
330
- return this.checkout.viewWith(config);
338
+ ): SchematizingSimpleTreeView<TRoot> & TreeView<TRoot>;
339
+
340
+ public viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(
341
+ config: TreeViewConfiguration<ReadSchema<TRoot>>,
342
+ ): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>> {
343
+ return this.checkout.viewWith(config) as SchematizingSimpleTreeView<TRoot> &
344
+ TreeView<ReadSchema<TRoot>>;
331
345
  }
332
346
 
333
347
  protected override async loadCore(services: IChannelStorageService): Promise<void> {
@@ -338,30 +352,36 @@ export class SharedTree
338
352
  }
339
353
 
340
354
  /**
341
- * Get a {@link TreeBranch} from a {@link ITree}.
355
+ * Get a {@link BranchableTree} from a {@link ITree}.
342
356
  * @remarks The branch can be used for "version control"-style coordination of edits on the tree.
343
357
  * @privateRemarks This function will be removed if/when the branching API becomes public,
344
358
  * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.
345
359
  * @alpha
360
+ * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.
346
361
  */
347
- export function getBranch(tree: ITree): TreeBranch;
362
+ export function getBranch(tree: ITree): BranchableTree;
348
363
  /**
349
- * Get a {@link TreeBranch} from a {@link TreeView}.
364
+ * Get a {@link BranchableTree} from a {@link TreeView}.
350
365
  * @remarks The branch can be used for "version control"-style coordination of edits on the tree.
351
366
  * Branches are currently an unstable "alpha" API and are subject to change in the future.
352
367
  * @privateRemarks This function will be removed if/when the branching API becomes public,
353
368
  * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.
354
369
  * @alpha
370
+ * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.
355
371
  */
356
- export function getBranch(view: TreeView<ImplicitFieldSchema>): TreeBranch;
357
- export function getBranch(treeOrView: ITree | TreeView<ImplicitFieldSchema>): TreeBranch {
372
+ export function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(
373
+ view: TreeViewAlpha<T>,
374
+ ): BranchableTree;
375
+ export function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(
376
+ treeOrView: ITree | TreeViewAlpha<T>,
377
+ ): BranchableTree {
358
378
  assert(
359
379
  treeOrView instanceof SharedTree || treeOrView instanceof SchematizingSimpleTreeView,
360
380
  0xa48 /* Unsupported implementation */,
361
381
  );
362
382
  const checkout: TreeCheckout = treeOrView.checkout;
363
383
  // This cast is safe so long as TreeCheckout supports all the operations on the branch interface.
364
- return checkout as unknown as TreeBranch;
384
+ return checkout as unknown as BranchableTree;
365
385
  }
366
386
 
367
387
  /**