@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
@@ -78,7 +78,10 @@ export interface RunTransaction {
78
78
  * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.
79
79
  * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.
80
80
  */
81
- <TView extends TreeView<ImplicitFieldSchema>, TResult>(
81
+ // TODO: TreeView is invariant over the schema, so to accept any view, `any` is the only real option unless a non generic (or covariant) base type for view is introduced (which is planned).
82
+ // This use of any is actually type safe as it is only used as a constraint, and the actual strongly typed view (TView) is passed to the callback.
83
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
84
+ <TView extends TreeView<any>, TResult>(
82
85
  tree: TView,
83
86
  transaction: (root: TView["root"]) => TResult,
84
87
  ): TResult;
@@ -123,7 +126,9 @@ export interface RunTransaction {
123
126
  * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.
124
127
  * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.
125
128
  */
126
- <TView extends TreeView<ImplicitFieldSchema>, TResult>(
129
+ // See comment on previous overload about use of any here.
130
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
131
+ <TView extends TreeView<any>, TResult>(
127
132
  tree: TView,
128
133
  transaction: (root: TView["root"]) => TResult | typeof rollback,
129
134
  ): TResult | typeof rollback;
@@ -161,10 +166,9 @@ export interface RunTransaction {
161
166
  * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.
162
167
  * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.
163
168
  */
164
- <TView extends TreeView<ImplicitFieldSchema>>(
165
- tree: TView,
166
- transaction: (root: TView["root"]) => void,
167
- ): void;
169
+ // See comment on previous overload about use of any here.
170
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
171
+ <TView extends TreeView<any>>(tree: TView, transaction: (root: TView["root"]) => void): void;
168
172
  /**
169
173
  * Apply one or more edits to the tree as a single atomic unit.
170
174
  * @param node - The node that will be passed to `transaction`.
@@ -211,7 +215,9 @@ export interface RunTransaction {
211
215
  * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.
212
216
  * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.
213
217
  */
214
- <TView extends TreeView<ImplicitFieldSchema>, TResult>(
218
+ // See comment on previous overload about use of any here.
219
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
220
+ <TView extends TreeView<any>, TResult>(
215
221
  tree: TView,
216
222
  transaction: (root: TView["root"]) => TResult,
217
223
  preconditions?: readonly TransactionConstraint[],
@@ -264,7 +270,9 @@ export interface RunTransaction {
264
270
  * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.
265
271
  * If the transaction is rolled back (whether by an error or by returning the {@link RunTransaction.rollback} | rollback value), a corresponding change event will also be emitted for the rollback.
266
272
  */
267
- <TView extends TreeView<ImplicitFieldSchema>, TResult>(
273
+ // See comment on previous overload about use of any here.
274
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
275
+ <TView extends TreeView<any>, TResult>(
268
276
  tree: TView,
269
277
  transaction: (root: TView["root"]) => TResult | typeof rollback,
270
278
  preconditions?: readonly TransactionConstraint[],
@@ -313,7 +321,9 @@ export interface RunTransaction {
313
321
  * If the transaction function throws an error then the transaction will be automatically rolled back (discarding any changes made to the tree so far) before the error is propagated up from this function.
314
322
  * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.
315
323
  */
316
- <TView extends TreeView<ImplicitFieldSchema>>(
324
+ // See comment on previous overload about use of any here.
325
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
326
+ <TView extends TreeView<any>>(
317
327
  tree: TView,
318
328
  transaction: (root: TView["root"]) => void,
319
329
  preconditions?: readonly TransactionConstraint[],
@@ -0,0 +1,401 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { assert } from "@fluidframework/core-utils/internal";
7
+ import { createIdCompressor } from "@fluidframework/id-compressor/internal";
8
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
9
+ import type { IFluidHandle } from "@fluidframework/core-interfaces";
10
+ import type { IIdCompressor } from "@fluidframework/id-compressor";
11
+
12
+ import {
13
+ getKernel,
14
+ type TreeNode,
15
+ type Unhydrated,
16
+ TreeBeta,
17
+ tryGetSchema,
18
+ createFromCursor,
19
+ createFromInsertable,
20
+ cursorFromInsertable,
21
+ FieldKind,
22
+ normalizeFieldSchema,
23
+ type ImplicitFieldSchema,
24
+ type InsertableField,
25
+ type TreeFieldFromImplicitField,
26
+ type TreeLeafValue,
27
+ type UnsafeUnknownSchema,
28
+ conciseFromCursor,
29
+ type ConciseTree,
30
+ applySchemaToParserOptions,
31
+ cursorFromVerbose,
32
+ verboseFromCursor,
33
+ type ParseOptions,
34
+ type VerboseTree,
35
+ type VerboseTreeNode,
36
+ toStoredSchema,
37
+ type EncodeOptions,
38
+ extractPersistedSchema,
39
+ TreeViewConfiguration,
40
+ type TreeBranch,
41
+ } from "../simple-tree/index.js";
42
+ import { fail, type JsonCompatible } from "../util/index.js";
43
+ import { noopValidator, type FluidClientVersion, type ICodecOptions } from "../codec/index.js";
44
+ import type { ITreeCursorSynchronous } from "../core/index.js";
45
+ import {
46
+ cursorForMapTreeField,
47
+ defaultSchemaPolicy,
48
+ isTreeValue,
49
+ makeFieldBatchCodec,
50
+ mapTreeFromCursor,
51
+ TreeCompressionStrategy,
52
+ type FieldBatch,
53
+ type FieldBatchEncodingContext,
54
+ } from "../feature-libraries/index.js";
55
+ import { independentInitializedView, type ViewContent } from "./independentView.js";
56
+ import { SchematizingSimpleTreeView, ViewSlot } from "./schematizingTreeView.js";
57
+
58
+ /**
59
+ * Extensions to {@link Tree} and {@link TreeBeta} which are not yet stable.
60
+ * @sealed @alpha
61
+ */
62
+ export const TreeAlpha: {
63
+ /**
64
+ * Retrieve the {@link TreeBranch | branch}, if any, for the given node.
65
+ * @param node - The node to query
66
+ * @remarks If the node has already been inserted into the tree, this will return the branch associated with that node's {@link TreeView | view}.
67
+ * Otherwise, it will return `undefined` (because the node has not yet been inserted and is therefore not part of a branch or view).
68
+ *
69
+ * This does not fork a new branch, but rather retrieves the _existing_ branch for the node.
70
+ * To create a new branch, use e.g. {@link TreeBranch.fork | `myBranch.fork()`}.
71
+ */
72
+ branch(node: TreeNode): TreeBranch | undefined;
73
+
74
+ /**
75
+ * Construct tree content that is compatible with the field defined by the provided `schema`.
76
+ * @param schema - The schema for what to construct. As this is an {@link ImplicitFieldSchema}, a {@link FieldSchema}, {@link TreeNodeSchema} or {@link AllowedTypes} array can be provided.
77
+ * @param data - The data used to construct the field content.
78
+ * @remarks
79
+ * When providing a {@link TreeNodeSchemaClass}, this is the same as invoking its constructor except that an unhydrated node can also be provided.
80
+ * This function exists as a generalization that can be used in other cases as well,
81
+ * such as when `undefined` might be allowed (for an optional field), or when the type should be inferred from the data when more than one type is possible.
82
+ *
83
+ * Like with {@link TreeNodeSchemaClass}'s constructor, it's an error to provide an existing node to this API.
84
+ * For that case, use {@link TreeBeta.clone}.
85
+ * @privateRemarks
86
+ * There should be a way to provide a source for defaulted identifiers, wither via this API or some way to add them to its output later.
87
+ */
88
+ create<const TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(
89
+ schema: UnsafeUnknownSchema extends TSchema
90
+ ? ImplicitFieldSchema
91
+ : TSchema & ImplicitFieldSchema,
92
+ data: InsertableField<TSchema>,
93
+ ): Unhydrated<
94
+ TSchema extends ImplicitFieldSchema
95
+ ? TreeFieldFromImplicitField<TSchema>
96
+ : TreeNode | TreeLeafValue | undefined
97
+ >;
98
+
99
+ /**
100
+ * Less type safe version of {@link TreeAlpha.create}, suitable for importing data.
101
+ * @remarks
102
+ * Due to {@link ConciseTree} relying on type inference from the data, its use is somewhat limited.
103
+ * This does not support {@link ConciseTree|ConciseTrees} with customized handle encodings or using persisted keys.
104
+ * Use "compressed" or "verbose" formats for more flexibility.
105
+ *
106
+ * When using this function,
107
+ * it is recommend to ensure your schema is unambiguous with {@link ITreeConfigurationOptions.preventAmbiguity}.
108
+ * If the schema is ambiguous, consider using {@link TreeAlpha.create} and {@link Unhydrated} nodes where needed,
109
+ * or using {@link TreeAlpha.(importVerbose:1)} and specify all types.
110
+ *
111
+ * Documented (and thus recoverable) error handling/reporting for this is not yet implemented,
112
+ * but for now most invalid inputs will throw a recoverable error.
113
+ */
114
+ importConcise<const TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(
115
+ schema: UnsafeUnknownSchema extends TSchema
116
+ ? ImplicitFieldSchema
117
+ : TSchema & ImplicitFieldSchema,
118
+ data: ConciseTree | undefined,
119
+ ): Unhydrated<
120
+ TSchema extends ImplicitFieldSchema
121
+ ? TreeFieldFromImplicitField<TSchema>
122
+ : TreeNode | TreeLeafValue | undefined
123
+ >;
124
+
125
+ /**
126
+ * Construct tree content compatible with a field defined by the provided `schema`.
127
+ * @param schema - The schema for what to construct. As this is an {@link ImplicitFieldSchema}, a {@link FieldSchema}, {@link TreeNodeSchema} or {@link AllowedTypes} array can be provided.
128
+ * @param data - The data used to construct the field content. See {@link TreeAlpha.(exportVerbose:1)}.
129
+ * @remarks
130
+ * This overload requires that any {@link @fluidframework/core-interfaces#IFluidHandle|IFluidHandles} are encoded as actual {@link @fluidframework/core-interfaces#IFluidHandle|IFluidHandles} in the input.
131
+ */
132
+ importVerbose<const TSchema extends ImplicitFieldSchema>(
133
+ schema: TSchema,
134
+ data: VerboseTree | undefined,
135
+ options?: Partial<ParseOptions<IFluidHandle>>,
136
+ ): Unhydrated<TreeFieldFromImplicitField<TSchema>>;
137
+
138
+ /**
139
+ * Construct tree content compatible with a field defined by the provided `schema`.
140
+ * @param schema - The schema for what to construct. As this is an {@link ImplicitFieldSchema}, a {@link FieldSchema}, {@link TreeNodeSchema} or {@link AllowedTypes} array can be provided.
141
+ * @param data - The data used to construct the field content. See {@link TreeAlpha.(exportVerbose:2)}.
142
+ *
143
+ * @typeparam THandle - How {@link @fluidframework/core-interfaces#IFluidHandle|IFluidHandles} in the input `data` are encoded.
144
+ * A converter from this encoding to {@link @fluidframework/core-interfaces#IFluidHandle} is required in `options`.
145
+ */
146
+ importVerbose<const TSchema extends ImplicitFieldSchema, THandle>(
147
+ schema: TSchema,
148
+ data: VerboseTree<THandle> | undefined,
149
+ options: ParseOptions<THandle>,
150
+ ): Unhydrated<TreeFieldFromImplicitField<TSchema>>;
151
+
152
+ /**
153
+ * Same as {@link TreeAlpha.(exportConcise:2)}, except leaves handles as is.
154
+ */
155
+ exportConcise(
156
+ node: TreeNode | TreeLeafValue,
157
+ options?: Partial<EncodeOptions<IFluidHandle>>,
158
+ ): ConciseTree;
159
+
160
+ /**
161
+ * Copy a snapshot of the current version of a TreeNode into a {@link ConciseTree}.
162
+ *
163
+ * @typeparam THandle - How {@link @fluidframework/core-interfaces#IFluidHandle|IFluidHandles} in the output should be encoded.
164
+ * A converter from from {@link @fluidframework/core-interfaces#IFluidHandle} to this format is required in `options`.
165
+ */
166
+ exportConcise<THandle>(
167
+ node: TreeNode | TreeLeafValue,
168
+ options: EncodeOptions<THandle>,
169
+ ): ConciseTree<THandle>;
170
+
171
+ /**
172
+ * Same {@link TreeAlpha.(exportVerbose:2)} except leaves handles as is.
173
+ */
174
+ exportVerbose(
175
+ node: TreeNode | TreeLeafValue,
176
+ options?: Partial<EncodeOptions<IFluidHandle>>,
177
+ ): VerboseTree;
178
+
179
+ /**
180
+ * Copy a snapshot of the current version of a TreeNode into a JSON compatible plain old JavaScript Object.
181
+ * Verbose tree format, with explicit type on every node.
182
+ *
183
+ * @typeparam THandle - How {@link @fluidframework/core-interfaces#IFluidHandle|IFluidHandles} in the output should be encoded.
184
+ * A converter from from {@link @fluidframework/core-interfaces#IFluidHandle} to this format is required in `options`.
185
+ *
186
+ * @remarks
187
+ * There are several cases this may be preferred to {@link TreeAlpha.(exportConcise:2)}:
188
+ *
189
+ * 1. When not using {@link ITreeConfigurationOptions.preventAmbiguity} (or when using `useStableFieldKeys`), `exportConcise` can produce ambiguous data (the type may be unclear on some nodes).
190
+ * `exportVerbose` will always be unambiguous and thus lossless.
191
+ *
192
+ * 2. When the data might be interpreted without access to the exact same view schema. In such cases, the types may be unknowable if not included.
193
+ *
194
+ * 3. When easy access to the type is desired.
195
+ */
196
+ exportVerbose<T>(node: TreeNode | TreeLeafValue, options: EncodeOptions<T>): VerboseTree<T>;
197
+
198
+ /**
199
+ * Export the content of the provided `tree` in a compressed JSON compatible format.
200
+ * @remarks
201
+ * If an `idCompressor` is provided, it will be used to compress identifiers and thus will be needed to decompress the data.
202
+ *
203
+ * Always uses "stored" keys.
204
+ * See {@link EncodeOptions.useStoredKeys} for details.
205
+ * @privateRemarks
206
+ * TODO: It is currently not clear how to work with the idCompressors correctly in the package API.
207
+ * Better APIs should probably be provided as there is currently no way to associate an un-hydrated tree with an idCompressor,
208
+ * Nor get the correct idCompressor from a subtree to use when exporting it.
209
+ * Additionally using `createIdCompressor` to make an idCompressor is `@legacy` and thus not intended for use in this API surface.
210
+ * It would probably make more sense if we provided a way to get an idCompressor from the context of a node,
211
+ * which could be optional (and settable if missing) for un0hydrated nodes and required for hydrated ones.
212
+ * Add in a stable public APi for creating idCompressors, and a way to get them from a tree (without view schema), and that should address the anticipated use-cases.
213
+ */
214
+ exportCompressed(
215
+ tree: TreeNode | TreeLeafValue,
216
+ options: { oldestCompatibleClient: FluidClientVersion; idCompressor?: IIdCompressor },
217
+ ): JsonCompatible<IFluidHandle>;
218
+
219
+ /**
220
+ * Import data encoded by {@link TreeAlpha.exportCompressed}.
221
+ *
222
+ * @param schema - Schema with which the data must be compatible. This compatibility is not verified and must be ensured by the caller.
223
+ * @param compressedData - Data compressed by {@link TreeAlpha.exportCompressed}.
224
+ * @param options - If {@link TreeAlpha.exportCompressed} was given an `idCompressor`, it must be provided here.
225
+ *
226
+ * @remarks
227
+ * If the data could have been encoded with a different schema, consider encoding the schema along side it using {@link extractPersistedSchema} and loading the data using {@link independentView}.
228
+ *
229
+ * @privateRemarks
230
+ * This API could be improved:
231
+ *
232
+ * 1. It could validate that the schema is compatible, and return or throw an error in the invalid case (maybe add a "try" version).
233
+ * 2. A "try" version of this could return an error if the data isn't in a supported format (as determined by version and/or JasonValidator).
234
+ * 3. Requiring the caller provide a JsonValidator isn't the most friendly API. It might be practical to provide a default.
235
+ */
236
+ importCompressed<const TSchema extends ImplicitFieldSchema>(
237
+ schema: TSchema,
238
+ compressedData: JsonCompatible<IFluidHandle>,
239
+ options: { idCompressor?: IIdCompressor } & ICodecOptions,
240
+ ): Unhydrated<TreeFieldFromImplicitField<TSchema>>;
241
+ } = {
242
+ branch(node: TreeNode): TreeBranch | undefined {
243
+ const kernel = getKernel(node);
244
+ if (!kernel.isHydrated()) {
245
+ return undefined;
246
+ }
247
+ const view = kernel.anchorNode.anchorSet.slots.get(ViewSlot);
248
+ assert(
249
+ view instanceof SchematizingSimpleTreeView,
250
+ 0xa5c /* Unexpected view implementation */,
251
+ );
252
+ return view;
253
+ },
254
+
255
+ create: createFromInsertable,
256
+
257
+ importConcise<TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema>(
258
+ schema: UnsafeUnknownSchema extends TSchema
259
+ ? ImplicitFieldSchema
260
+ : TSchema & ImplicitFieldSchema,
261
+ data: ConciseTree | undefined,
262
+ ): Unhydrated<
263
+ TSchema extends ImplicitFieldSchema
264
+ ? TreeFieldFromImplicitField<TSchema>
265
+ : TreeNode | TreeLeafValue | undefined
266
+ > {
267
+ return createFromInsertable<UnsafeUnknownSchema>(
268
+ schema,
269
+ data as InsertableField<UnsafeUnknownSchema>,
270
+ ) as Unhydrated<
271
+ TSchema extends ImplicitFieldSchema
272
+ ? TreeFieldFromImplicitField<TSchema>
273
+ : TreeNode | TreeLeafValue | undefined
274
+ >;
275
+ },
276
+
277
+ importVerbose<const TSchema extends ImplicitFieldSchema, THandle>(
278
+ schema: TSchema,
279
+ data: VerboseTree<THandle> | undefined,
280
+ options?: Partial<ParseOptions<THandle>>,
281
+ ): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
282
+ const config: ParseOptions<THandle> = {
283
+ valueConverter: (input: VerboseTree<THandle>) => {
284
+ return input as TreeLeafValue | VerboseTreeNode<THandle>;
285
+ },
286
+ ...options,
287
+ };
288
+ // Create a config which is standalone, and thus can be used without having to refer back to the schema.
289
+ const schemalessConfig = applySchemaToParserOptions(schema, config);
290
+ if (data === undefined) {
291
+ const field = normalizeFieldSchema(schema);
292
+ if (field.kind !== FieldKind.Optional) {
293
+ throw new UsageError("undefined provided for non-optional field.");
294
+ }
295
+ return undefined as Unhydrated<TreeFieldFromImplicitField<TSchema>>;
296
+ }
297
+ const cursor = cursorFromVerbose<THandle>(data, schemalessConfig);
298
+ return createFromCursor(schema, cursor);
299
+ },
300
+
301
+ exportConcise<T>(
302
+ node: TreeNode | TreeLeafValue,
303
+ options?: Partial<EncodeOptions<T>>,
304
+ ): ConciseTree<T> {
305
+ const config: EncodeOptions<T> = {
306
+ valueConverter(handle: IFluidHandle): T {
307
+ return handle as T;
308
+ },
309
+ ...options,
310
+ };
311
+
312
+ const cursor = borrowCursorFromTreeNodeOrValue(node);
313
+ return conciseFromCursor(cursor, tryGetSchema(node) ?? fail("invalid input"), config);
314
+ },
315
+
316
+ exportVerbose<T>(
317
+ node: TreeNode | TreeLeafValue,
318
+ options?: Partial<EncodeOptions<T>>,
319
+ ): VerboseTree<T> {
320
+ const config: EncodeOptions<T> = {
321
+ valueConverter(handle: IFluidHandle): T {
322
+ return handle as T;
323
+ },
324
+ ...options,
325
+ };
326
+
327
+ const cursor = borrowCursorFromTreeNodeOrValue(node);
328
+ return verboseFromCursor(cursor, tryGetSchema(node) ?? fail("invalid input"), config);
329
+ },
330
+
331
+ exportCompressed(
332
+ node: TreeNode | TreeLeafValue,
333
+ options: {
334
+ oldestCompatibleClient: FluidClientVersion;
335
+ idCompressor?: IIdCompressor;
336
+ },
337
+ ): JsonCompatible<IFluidHandle> {
338
+ const schema = tryGetSchema(node) ?? fail("invalid input");
339
+ const format = versionToFormat[options.oldestCompatibleClient];
340
+ const codec = makeFieldBatchCodec({ jsonValidator: noopValidator }, format);
341
+ const cursor = borrowFieldCursorFromTreeNodeOrValue(node);
342
+ const batch: FieldBatch = [cursor];
343
+ // If none provided, create a compressor which will not compress anything.
344
+ const idCompressor = options.idCompressor ?? createIdCompressor();
345
+ const context: FieldBatchEncodingContext = {
346
+ encodeType: TreeCompressionStrategy.Compressed,
347
+ idCompressor,
348
+ originatorId: idCompressor.localSessionId, // TODO: Why is this needed?
349
+ schema: { schema: toStoredSchema(schema), policy: defaultSchemaPolicy },
350
+ };
351
+ const result = codec.encode(batch, context);
352
+ return result;
353
+ },
354
+
355
+ importCompressed<const TSchema extends ImplicitFieldSchema>(
356
+ schema: TSchema,
357
+ compressedData: JsonCompatible<IFluidHandle>,
358
+ options: {
359
+ idCompressor?: IIdCompressor;
360
+ } & ICodecOptions,
361
+ ): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
362
+ const content: ViewContent = {
363
+ schema: extractPersistedSchema(schema),
364
+ tree: compressedData,
365
+ idCompressor: options.idCompressor ?? createIdCompressor(),
366
+ };
367
+ const config = new TreeViewConfiguration({ schema });
368
+ const view = independentInitializedView(config, options, content);
369
+ return TreeBeta.clone<TSchema>(view.root);
370
+ },
371
+ };
372
+
373
+ function borrowCursorFromTreeNodeOrValue(
374
+ node: TreeNode | TreeLeafValue,
375
+ ): ITreeCursorSynchronous {
376
+ if (isTreeValue(node)) {
377
+ return cursorFromInsertable<UnsafeUnknownSchema>(
378
+ tryGetSchema(node) ?? fail("missing schema"),
379
+ node,
380
+ );
381
+ }
382
+ const kernel = getKernel(node);
383
+ const cursor = kernel.getOrCreateInnerNode().borrowCursor();
384
+ return cursor;
385
+ }
386
+
387
+ function borrowFieldCursorFromTreeNodeOrValue(
388
+ node: TreeNode | TreeLeafValue,
389
+ ): ITreeCursorSynchronous {
390
+ const cursor = borrowCursorFromTreeNodeOrValue(node);
391
+ // TODO: avoid copy
392
+ const mapTree = mapTreeFromCursor(cursor);
393
+ return cursorForMapTreeField([mapTree]);
394
+ }
395
+
396
+ const versionToFormat = {
397
+ v2_0: 1,
398
+ v2_1: 1,
399
+ v2_2: 1,
400
+ v2_3: 1,
401
+ };
@@ -63,8 +63,10 @@ import type { ISharedTreeEditor, SharedTreeEditBuilder } from "./sharedTreeEditB
63
63
  import type { IDisposable } from "@fluidframework/core-interfaces";
64
64
  import type {
65
65
  ImplicitFieldSchema,
66
+ ReadSchema,
66
67
  TreeView,
67
68
  TreeViewConfiguration,
69
+ UnsafeUnknownSchema,
68
70
  ViewableTree,
69
71
  } from "../simple-tree/index.js";
70
72
  import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
@@ -104,7 +106,7 @@ export interface CheckoutEvents {
104
106
  * Changes may be synchronized across branches via merge and rebase operations provided on the branch object.
105
107
  * @alpha @sealed
106
108
  */
107
- export interface TreeBranch extends ViewableTree {
109
+ export interface BranchableTree extends ViewableTree {
108
110
  /**
109
111
  * Spawn a new branch which is based off of the current state of this branch.
110
112
  * Any mutations of the new branch will not apply to this branch until the new branch is merged back into this branch via `merge()`.
@@ -136,16 +138,16 @@ export interface TreeBranch extends ViewableTree {
136
138
  }
137
139
 
138
140
  /**
139
- * A {@link TreeBranch | branch} of a SharedTree that has merged from another branch.
141
+ * A {@link BranchableTree | branch} of a SharedTree that has merged from another branch.
140
142
  * @remarks This branch should be disposed when it is no longer needed in order to free resources.
141
143
  * @alpha @sealed
142
144
  */
143
- export interface TreeBranchFork extends TreeBranch, IDisposable {
145
+ export interface TreeBranchFork extends BranchableTree, IDisposable {
144
146
  /**
145
147
  * Rebase the changes that have been applied to this branch over all the new changes in the given branch.
146
148
  * @param branch - Either the root branch or a branch that was created by a call to `branch()`. It is not modified by this operation.
147
149
  */
148
- rebaseOnto(branch: TreeBranch): void;
150
+ rebaseOnto(branch: BranchableTree): void;
149
151
  }
150
152
 
151
153
  /**
@@ -283,6 +285,7 @@ export function createTreeCheckout(
283
285
  return new TreeCheckout(
284
286
  transaction,
285
287
  branch,
288
+ false,
286
289
  changeFamily,
287
290
  schema,
288
291
  forest,
@@ -424,6 +427,8 @@ export class TreeCheckout implements ITreeCheckoutFork {
424
427
  public constructor(
425
428
  public readonly transaction: ITransaction,
426
429
  private readonly _branch: SharedTreeBranch<SharedTreeEditBuilder, SharedTreeChange>,
430
+ /** True if and only if this checkout is for a forked branch and not the "main branch" of the tree. */
431
+ public readonly isBranch: boolean,
427
432
  private readonly changeFamily: ChangeFamily<SharedTreeEditBuilder, SharedTreeChange>,
428
433
  public readonly storedSchema: TreeStoredSchemaRepository,
429
434
  public readonly forest: IEditableForest,
@@ -516,6 +521,8 @@ export class TreeCheckout implements ITreeCheckoutFork {
516
521
  event.type === "append" ||
517
522
  (event.type === "replace" && getChangeReplaceType(event) === "transactionCommit")
518
523
  ) {
524
+ // TODO:#20949: When the SharedTree is detached, these commits will already have been garbage collected.
525
+ // Figure out a way to generate revertibles before the commits are garbage collected.
519
526
  for (const commit of event.newCommits) {
520
527
  const kind = event.type === "append" ? event.kind : CommitKind.Default;
521
528
  const { change, revision } = commit;
@@ -620,8 +627,18 @@ export class TreeCheckout implements ITreeCheckoutFork {
620
627
  }
621
628
  }
622
629
 
630
+ // For the new TreeViewAlpha API
631
+ public viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(
632
+ config: TreeViewConfiguration<ReadSchema<TRoot>>,
633
+ ): SchematizingSimpleTreeView<TRoot>;
634
+
635
+ // For the old TreeView API
623
636
  public viewWith<TRoot extends ImplicitFieldSchema>(
624
637
  config: TreeViewConfiguration<TRoot>,
638
+ ): TreeView<TRoot>;
639
+
640
+ public viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(
641
+ config: TreeViewConfiguration<ReadSchema<TRoot>>,
625
642
  ): SchematizingSimpleTreeView<TRoot> {
626
643
  const view = new SchematizingSimpleTreeView(
627
644
  this,
@@ -662,6 +679,7 @@ export class TreeCheckout implements ITreeCheckoutFork {
662
679
  return new TreeCheckout(
663
680
  transaction,
664
681
  branch,
682
+ true,
665
683
  this.changeFamily,
666
684
  storedSchema,
667
685
  forest,
@@ -686,6 +704,10 @@ export class TreeCheckout implements ITreeCheckoutFork {
686
704
  !checkout.transaction.inProgress(),
687
705
  0x9af /* A view cannot be rebased while it has a pending transaction */,
688
706
  );
707
+ assert(
708
+ checkout.isBranch,
709
+ 0xa5d /* The main branch cannot be rebased onto another branch. */,
710
+ );
689
711
  checkout._branch.rebaseOnto(this._branch);
690
712
  }
691
713
 
@@ -713,7 +735,8 @@ export class TreeCheckout implements ITreeCheckoutFork {
713
735
  checkout.transaction.commit();
714
736
  }
715
737
  this._branch.merge(checkout._branch);
716
- if (disposeMerged) {
738
+ if (disposeMerged && checkout.isBranch) {
739
+ // Dispose the merged checkout unless it is the main branch.
717
740
  checkout[disposeSymbol]();
718
741
  }
719
742
  }