@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
@@ -13,8 +13,10 @@ import type {
13
13
  InternalTreeNode,
14
14
  NodeKind,
15
15
  TreeNode,
16
+ TreeNodeSchema,
16
17
  TreeNodeSchemaClass,
17
18
  } from "../core/index.js";
19
+ import type { UnionToTuple } from "../../util/index.js";
18
20
 
19
21
  /*
20
22
  * This file does two things:
@@ -40,7 +42,7 @@ export function singletonSchema<TScope extends string, TName extends string | nu
40
42
  name: TName,
41
43
  ) {
42
44
  class SingletonSchema extends factory.object(name, {}) {
43
- public constructor(data?: InternalTreeNode) {
45
+ public constructor(data?: InternalTreeNode | Record<string, never>) {
44
46
  super(data ?? {});
45
47
  }
46
48
  public get value(): TName {
@@ -48,7 +50,7 @@ export function singletonSchema<TScope extends string, TName extends string | nu
48
50
  }
49
51
  }
50
52
 
51
- type NodeType = TreeNode & { readonly value: TName };
53
+ type SingletonNodeType = TreeNode & { readonly value: TName };
52
54
 
53
55
  // Returning SingletonSchema without a type conversion results in TypeScript generating something like `readonly "__#124291@#brand": unknown;`
54
56
  // for the private brand field of TreeNode.
@@ -58,11 +60,12 @@ export function singletonSchema<TScope extends string, TName extends string | nu
58
60
  const toReturn: TreeNodeSchemaClass<
59
61
  ScopedSchemaName<TScope, TName>,
60
62
  NodeKind.Object,
61
- NodeType,
62
- never,
63
- true
64
- > &
65
- (new () => NodeType) = SingletonSchema;
63
+ SingletonNodeType,
64
+ Record<string, never>,
65
+ true,
66
+ Record<string, never>,
67
+ undefined
68
+ > = SingletonSchema;
66
69
 
67
70
  return toReturn;
68
71
  }
@@ -84,15 +87,14 @@ export function singletonSchema<TScope extends string, TName extends string | nu
84
87
  * // Define the schema for each member of the enum using a nested scope to group them together.
85
88
  * const ModeNodes = adaptEnum(new SchemaFactory(`${schemaFactory.scope}.Mode`), Mode);
86
89
  * // Defined the types of the nodes which correspond to this the schema.
87
- * type ModeNodes = NodeFromSchema<(typeof ModeNodes)[keyof typeof ModeNodes]>;
90
+ * type ModeNodes = NodeFromSchema<(typeof ModeNodes.schema)[number]>;
88
91
  * // An example schema which has an enum as a child.
89
92
  * class Parent extends schemaFactory.object("Parent", {
90
- * // typedObjectValues extracts a list of all the fields of ModeNodes, which are the schema for each enum member.
91
- * // This means any member of the enum is allowed in this field.
92
- * mode: typedObjectValues(ModeNodes),
93
+ * // adaptEnum's return value has a ".schema" property can be use as an `AllowedTypes` array allowing any of the members of the enum.
94
+ * mode: ModeNodes.schema,
93
95
  * }) {}
94
96
  *
95
- * // Example usage of enum-based nodes, showing what type to use and that `.value` can be used to read out the enum value.
97
+ * // Example usage of enum based nodes, showing what type to use and that `.value` can be used to read out the enum value.
96
98
  * function getValue(node: ModeNodes): Mode {
97
99
  * return node.value;
98
100
  * }
@@ -131,35 +133,36 @@ export function adaptEnum<
131
133
  typeof singletonSchema<TScope, TEnum[Property]>
132
134
  >;
133
135
  };
136
+
137
+ type SchemaArray = UnionToTuple<TOut[keyof TEnum]>;
138
+ const schemaArray: TreeNodeSchema[] = [];
139
+
134
140
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
135
141
  const factoryOut = <TValue extends Values>(value: TValue) => {
136
142
  return new out[inverse.get(value) ?? fail("missing enum value")]() as NodeFromSchema<
137
143
  ReturnType<typeof singletonSchema<TScope, TValue>>
138
144
  >;
139
145
  };
140
- const out = factoryOut as typeof factoryOut & TOut;
146
+ const out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };
141
147
  for (const [key, value] of Object.entries(members)) {
148
+ const schema = singletonSchema(factory, value);
149
+ schemaArray.push(schema);
142
150
  Object.defineProperty(out, key, {
143
151
  enumerable: true,
144
152
  configurable: false,
145
153
  writable: false,
146
- value: singletonSchema(factory, value),
154
+ value: schema,
147
155
  });
148
156
  }
149
157
 
150
- return out;
151
- }
158
+ Object.defineProperty(out, "schema", {
159
+ enumerable: true,
160
+ configurable: false,
161
+ writable: false,
162
+ value: schemaArray,
163
+ });
152
164
 
153
- /**
154
- * `Object.values`, but with more specific types.
155
- * @remarks
156
- * Useful with collections of schema, like those returned by {@link adaptEnum} or {@link enumFromStrings}.
157
- * @alpha
158
- */
159
- export function typedObjectValues<TKey extends string, TValues>(
160
- object: Record<TKey, TValues>,
161
- ): TValues[] {
162
- return Object.values(object);
165
+ return out;
163
166
  }
164
167
 
165
168
  /**
@@ -171,44 +174,63 @@ export function typedObjectValues<TKey extends string, TValues>(
171
174
  * The produced nodes use the provided strings as their `name`, and don't store any data beyond that.
172
175
  * @example
173
176
  * ```typescript
177
+ * const schemaFactory = new SchemaFactory("com.myApp");
174
178
  * const Mode = enumFromStrings(schemaFactory, ["Fun", "Cool"]);
175
- * type Mode = NodeFromSchema<(typeof Mode)[keyof typeof Mode]>;
179
+ * type Mode = NodeFromSchema<(typeof Mode.schema)[number]>;
176
180
  * const nodeFromString: Mode = Mode("Fun");
177
181
  * const nodeFromSchema: Mode = new Mode.Fun();
178
- * const nameFromNode = nodeFromSchema.value;
179
182
  *
180
- * class Parent extends schemaFactory.object("Parent", { mode: typedObjectValues(Mode) }) {}
183
+ * // Schema nodes have a strongly typed `.value` property.
184
+ * const nameFromNode: "Fun" | "Cool" = nodeFromSchema.value;
185
+ *
186
+ * class Parent extends schemaFactory.object("Parent", { mode: Mode.schema }) {}
181
187
  * ```
182
188
  * @see {@link adaptEnum} for a similar function that works on enums instead of arrays of strings.
183
189
  * @alpha
184
190
  */
185
191
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
186
- export function enumFromStrings<TScope extends string, const Members extends string>(
187
- factory: SchemaFactory<TScope>,
188
- members: readonly Members[],
189
- ) {
192
+ export function enumFromStrings<
193
+ TScope extends string,
194
+ const Members extends readonly string[],
195
+ >(factory: SchemaFactory<TScope>, members: Members) {
190
196
  const names = new Set(members);
191
197
  if (names.size !== members.length) {
192
198
  throw new UsageError("All members of enums must have distinct names");
193
199
  }
194
200
 
195
- type TOut = Record<Members, ReturnType<typeof singletonSchema<TScope, Members>>>;
201
+ type TOut = Record<
202
+ Members[number],
203
+ ReturnType<typeof singletonSchema<TScope, Members[number]>>
204
+ >;
196
205
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
197
- const factoryOut = <TValue extends Members>(value: TValue) => {
206
+ const factoryOut = <TValue extends Members[number]>(value: TValue) => {
198
207
  return new out[value]() as NodeFromSchema<
199
208
  ReturnType<typeof singletonSchema<TScope, TValue>>
200
209
  >;
201
210
  };
202
- const out = factoryOut as typeof factoryOut & TOut;
211
+
212
+ type SchemaArray = UnionToTuple<TOut[Members[number]]>;
213
+ const schemaArray: TreeNodeSchema[] = [];
214
+
215
+ const out = factoryOut as typeof factoryOut & TOut & { readonly schema: SchemaArray };
203
216
  for (const name of members) {
217
+ const schema = singletonSchema(factory, name);
218
+ schemaArray.push(schema);
204
219
  Object.defineProperty(out, name, {
205
220
  enumerable: true,
206
221
  configurable: false,
207
222
  writable: false,
208
- value: singletonSchema(factory, name),
223
+ value: schema,
209
224
  });
210
225
  }
211
226
 
227
+ Object.defineProperty(out, "schema", {
228
+ enumerable: true,
229
+ configurable: false,
230
+ writable: false,
231
+ value: schemaArray,
232
+ });
233
+
212
234
  return out;
213
235
  }
214
236
 
@@ -120,6 +120,10 @@ export type ScopedSchemaName<
120
120
  * Typically this is just `string` but it is also possible to use `string` or `number` based enums if you prefer to identify your types that way.
121
121
  *
122
122
  * @remarks
123
+ * For details related to inputting data constrained by schema (including via assignment), and how non-exact schema types are handled in general refer to {@link Input}.
124
+ * For information about recursive schema support, see methods postfixed with "recursive" and {@link ValidateRecursiveSchema}.
125
+ * To apply schema defined with this factory to a tree, see {@link ViewableTree.viewWith} and {@link TreeViewConfiguration}.
126
+ *
123
127
  * All schema produced by this factory get a {@link TreeNodeSchemaCore.identifier|unique identifier} by combining the {@link SchemaFactory.scope} with the schema's `Name`.
124
128
  * The `Name` part may be explicitly provided as a parameter, or inferred as a structural combination of the provided types.
125
129
  * The APIs which use this second approach, structural naming, also deduplicate all equivalent calls.
@@ -337,7 +341,8 @@ export class SchemaFactory<
337
341
  TreeMapNode<T> & WithType<ScopedSchemaName<TScope, `Map<${string}>`>, NodeKind.Map>,
338
342
  MapNodeInsertableData<T>,
339
343
  true,
340
- T
344
+ T,
345
+ undefined
341
346
  >;
342
347
 
343
348
  /**
@@ -359,7 +364,8 @@ export class SchemaFactory<
359
364
  TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>,
360
365
  MapNodeInsertableData<T>,
361
366
  true,
362
- T
367
+ T,
368
+ undefined
363
369
  >;
364
370
 
365
371
  /**
@@ -391,7 +397,8 @@ export class SchemaFactory<
391
397
  TreeMapNode<T>,
392
398
  MapNodeInsertableData<T>,
393
399
  true,
394
- T
400
+ T,
401
+ undefined
395
402
  >;
396
403
  }
397
404
  // To actually have type safety, assign to the type this method should return before implicitly upcasting when returning.
@@ -401,7 +408,8 @@ export class SchemaFactory<
401
408
  TreeMapNode<T>,
402
409
  MapNodeInsertableData<T>,
403
410
  true,
404
- T
411
+ T,
412
+ undefined
405
413
  > = this.namedMap(nameOrAllowedTypes as TName, allowedTypes, true, true);
406
414
  return out;
407
415
  }
@@ -426,7 +434,8 @@ export class SchemaFactory<
426
434
  TreeMapNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Map>,
427
435
  MapNodeInsertableData<T>,
428
436
  ImplicitlyConstructable,
429
- T
437
+ T,
438
+ undefined
430
439
  > {
431
440
  return mapSchema(
432
441
  this.scoped(name),
@@ -478,7 +487,8 @@ export class SchemaFactory<
478
487
  TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, `Array<${string}>`>, NodeKind.Array>,
479
488
  Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
480
489
  true,
481
- T
490
+ T,
491
+ undefined
482
492
  >;
483
493
 
484
494
  /**
@@ -502,7 +512,8 @@ export class SchemaFactory<
502
512
  TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, Name>, NodeKind.Array>,
503
513
  Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
504
514
  true,
505
- T
515
+ T,
516
+ undefined
506
517
  >;
507
518
 
508
519
  /**
@@ -531,7 +542,8 @@ export class SchemaFactory<
531
542
  TreeArrayNode<T>,
532
543
  Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
533
544
  true,
534
- T
545
+ T,
546
+ undefined
535
547
  >;
536
548
  }
537
549
  const out: TreeNodeSchemaBoth<
@@ -540,7 +552,8 @@ export class SchemaFactory<
540
552
  TreeArrayNode<T>,
541
553
  Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
542
554
  true,
543
- T
555
+ T,
556
+ undefined
544
557
  > = this.namedArray(nameOrAllowedTypes as TName, allowedTypes, true, true);
545
558
  return out;
546
559
  }
@@ -569,7 +582,8 @@ export class SchemaFactory<
569
582
  TreeArrayNode<T> & WithType<ScopedSchemaName<TScope, string>, NodeKind.Array>,
570
583
  Iterable<InsertableTreeNodeFromImplicitAllowedTypes<T>>,
571
584
  ImplicitlyConstructable,
572
- T
585
+ T,
586
+ undefined
573
587
  > {
574
588
  return arraySchema(this.scoped(name), allowedTypes, implicitlyConstructable, customizable);
575
589
  }
@@ -743,7 +757,8 @@ export class SchemaFactory<
743
757
  [Symbol.iterator](): Iterator<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>;
744
758
  },
745
759
  false,
746
- T
760
+ T,
761
+ undefined
747
762
  >;
748
763
  }
749
764
 
@@ -789,7 +804,8 @@ export class SchemaFactory<
789
804
  // Ideally this would be included, but doing so breaks recursive types.
790
805
  // | RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypesUnsafe<T>>,
791
806
  false,
792
- T
807
+ T,
808
+ undefined
793
809
  >;
794
810
  }
795
811
  }
@@ -97,7 +97,7 @@ function convertArrayNodeSchema(schema: SimpleArrayNodeSchema): JsonArrayNodeSch
97
97
  });
98
98
 
99
99
  const items: JsonFieldSchema =
100
- allowedTypes.length === 1 ? allowedTypes[0] ?? oob() : { anyOf: allowedTypes };
100
+ allowedTypes.length === 1 ? (allowedTypes[0] ?? oob()) : { anyOf: allowedTypes };
101
101
 
102
102
  return {
103
103
  type: "array",
@@ -144,7 +144,7 @@ function convertObjectNodeSchema(schema: SimpleObjectNodeSchema): JsonObjectNode
144
144
 
145
145
  const output: Mutable<JsonFieldSchema> =
146
146
  allowedTypes.length === 1
147
- ? allowedTypes[0] ?? oob()
147
+ ? (allowedTypes[0] ?? oob())
148
148
  : {
149
149
  anyOf: allowedTypes,
150
150
  };
@@ -180,7 +180,7 @@ function convertMapNodeSchema(schema: SimpleMapNodeSchema): JsonMapNodeSchema {
180
180
  patternProperties: {
181
181
  "^.*$":
182
182
  allowedTypes.length === 1
183
- ? allowedTypes[0] ?? oob()
183
+ ? (allowedTypes[0] ?? oob())
184
184
  : {
185
185
  anyOf: allowedTypes,
186
186
  },
@@ -14,7 +14,7 @@ import {
14
14
  import type { Format } from "../../feature-libraries/schema-index/index.js";
15
15
  import type { JsonCompatible } from "../../util/index.js";
16
16
  import type { ImplicitFieldSchema } from "../schemaTypes.js";
17
- import { toStoredSchema } from "../toFlexSchema.js";
17
+ import { toStoredSchema } from "../toStoredSchema.js";
18
18
  import type { SchemaCompatibilityStatus } from "./tree.js";
19
19
  import { ViewSchema } from "./view.js";
20
20
 
@@ -11,12 +11,16 @@ import type { Listenable } from "../../events/index.js";
11
11
 
12
12
  import {
13
13
  type ImplicitFieldSchema,
14
+ type InsertableField,
14
15
  type InsertableTreeFieldFromImplicitField,
16
+ type ReadableField,
17
+ type ReadSchema,
15
18
  type TreeFieldFromImplicitField,
19
+ type UnsafeUnknownSchema,
16
20
  FieldKind,
17
21
  } from "../schemaTypes.js";
18
22
  import { NodeKind, type TreeNodeSchema } from "../core/index.js";
19
- import { toStoredSchema } from "../toFlexSchema.js";
23
+ import { toStoredSchema } from "../toStoredSchema.js";
20
24
  import { LeafNodeSchema } from "../leafNodeSchema.js";
21
25
  import { assert } from "@fluidframework/core-utils/internal";
22
26
  import { isObjectNodeSchema, type ObjectNodeSchema } from "../objectNodeTypes.js";
@@ -26,6 +30,14 @@ import type { MakeNominal } from "../../util/index.js";
26
30
  import { walkFieldSchema } from "../walkFieldSchema.js";
27
31
  /**
28
32
  * A tree from which a {@link TreeView} can be created.
33
+ *
34
+ * @privateRemarks
35
+ * TODO:
36
+ * Add stored key versions of {@link TreeAlpha.(exportVerbose:2)}, {@link TreeAlpha.(exportConcise:2)} and {@link TreeAlpha.exportCompressed} here so tree content can be accessed without a view schema.
37
+ * Add exportSimpleSchema and exportJsonSchema methods (which should exactly match the concise format, and match the free functions for exporting view schema).
38
+ * Maybe rename "exportJsonSchema" to align on "concise" terminology.
39
+ * Ensure schema exporting APIs here align and reference APIs for exporting view schema to the same formats (which should include stored vs property key choice).
40
+ * Make sure users of independentView can use these export APIs (maybe provide a reference back to the ViewableTree from the TreeView to accomplish that).
29
41
  * @system @sealed @public
30
42
  */
31
43
  export interface ViewableTree {
@@ -45,7 +57,7 @@ export interface ViewableTree {
45
57
  * Only one schematized view may exist for a given ITree at a time.
46
58
  * If creating a second, the first must be disposed before calling `viewWith` again.
47
59
  *
48
- * @privateRemarks
60
+ *
49
61
  * TODO: Provide a way to make a generic view schema for any document.
50
62
  * TODO: Support adapters for handling out-of-schema data.
51
63
  *
@@ -190,8 +202,9 @@ export interface ITreeViewConfiguration<
190
202
  * Configuration for {@link ViewableTree.viewWith}.
191
203
  * @sealed @public
192
204
  */
193
- export class TreeViewConfiguration<TSchema extends ImplicitFieldSchema = ImplicitFieldSchema>
194
- implements Required<ITreeViewConfiguration<TSchema>>
205
+ export class TreeViewConfiguration<
206
+ const TSchema extends ImplicitFieldSchema = ImplicitFieldSchema,
207
+ > implements Required<ITreeViewConfiguration<TSchema>>
195
208
  {
196
209
  protected _typeCheck!: MakeNominal;
197
210
 
@@ -238,7 +251,7 @@ export class TreeViewConfiguration<TSchema extends ImplicitFieldSchema = Implici
238
251
  if (ambiguityErrors.length !== 0) {
239
252
  // Duplicate errors are common since when two types conflict, both orders error:
240
253
  const deduplicated = new Set(ambiguityErrors);
241
- throw new UsageError(`Ambigious schema found:\n${[...deduplicated].join("\n")}`);
254
+ throw new UsageError(`Ambiguous schema found:\n${[...deduplicated].join("\n")}`);
242
255
  }
243
256
 
244
257
  // Eagerly perform this conversion to surface errors sooner.
@@ -346,6 +359,84 @@ export function checkUnion(union: Iterable<TreeNodeSchema>, errors: string[]): v
346
359
  }
347
360
  }
348
361
 
362
+ /**
363
+ * A collection of functionality associated with a (version-control-style) branch of a SharedTree.
364
+ * @remarks A `TreeBranch` allows for the {@link TreeBranch.fork | creation of branches} and for those branches to later be {@link TreeBranch.merge | merged}.
365
+ *
366
+ * The `TreeBranch` for a specific {@link TreeNode} may be acquired by calling `TreeAlpha.branch`.
367
+ *
368
+ * A branch does not necessarily know the schema of its SharedTree - to convert a branch to a {@link TreeViewAlpha | view with a schema}, use {@link TreeBranch.hasRootSchema | hasRootSchema()}.
369
+ *
370
+ * The branch associated directly with the {@link ITree | SharedTree} is the "main" branch, and all other branches fork (directly or transitively) from that main branch.
371
+ * @sealed @alpha
372
+ */
373
+ export interface TreeBranch extends IDisposable {
374
+ /**
375
+ * Events for the branch
376
+ */
377
+ readonly events: Listenable<TreeBranchEvents>;
378
+
379
+ /**
380
+ * Returns true if this branch has the given schema as its root schema.
381
+ * @remarks This is a type guard which allows this branch to become strongly typed as a {@link TreeViewAlpha | view} of the given schema.
382
+ *
383
+ * To succeed, the given schema must be invariant to the schema of the view - it must include exactly the same allowed types.
384
+ * For example, a schema of `Foo | Bar` will not match a view schema of `Foo`, and likewise a schema of `Foo` will not match a view schema of `Foo | Bar`.
385
+ * @example
386
+ * ```typescript
387
+ * if (branch.hasRootSchema(MySchema)) {
388
+ * const { root } = branch; // `branch` is now a TreeViewAlpha<MySchema>
389
+ * // ...
390
+ * }
391
+ * ```
392
+ */
393
+ hasRootSchema<TSchema extends ImplicitFieldSchema>(
394
+ schema: TSchema,
395
+ ): this is TreeViewAlpha<TSchema>;
396
+
397
+ /**
398
+ * Fork a new branch off of this branch which is based off of this branch's current state.
399
+ * @remarks Any changes to the tree on the new branch will not apply to this branch until the new branch is e.g. {@link TreeBranch.merge | merged} back into this branch.
400
+ * The branch should be disposed when no longer needed, either {@link TreeBranch.dispose | explicitly} or {@link TreeBranch.merge | implicitly when merging} into another branch.
401
+ */
402
+ fork(): TreeBranch;
403
+
404
+ /**
405
+ * Apply all the new changes on the given branch to this branch.
406
+ * @param branch - a branch which was created by a call to `branch()`.
407
+ * @param disposeMerged - whether or not to dispose `branch` after the merge completes.
408
+ * Defaults to true.
409
+ * The {@link TreeBranch | main branch} cannot be disposed - attempting to do so will have no effect.
410
+ * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.
411
+ */
412
+ merge(branch: TreeBranch, disposeMerged?: boolean): void;
413
+
414
+ /**
415
+ * Advance this branch forward such that all new changes on the target branch become part of this branch.
416
+ * @param branch - The branch to rebase onto.
417
+ * @remarks After rebasing, this branch will be "ahead" of the target branch, that is, its unique changes will have been recreated as if they happened after all changes on the target branch.
418
+ * This method may only be called on branches produced via {@link TreeBranch.fork | branch} - attempting to rebase the main branch will throw.
419
+ *
420
+ * Rebasing long-lived branches is important to avoid consuming memory unnecessarily.
421
+ * In particular, the SharedTree retains all sequenced changes made to the tree since the "most-behind" branch was created or last rebased.
422
+ *
423
+ * The {@link TreeBranch | main branch} cannot be rebased onto another branch - attempting to do so will throw an error.
424
+ */
425
+ rebaseOnto(branch: TreeBranch): void;
426
+
427
+ /**
428
+ * Dispose of this branch, cleaning up any resources associated with it.
429
+ * @param error - Optional error indicating the reason for the disposal, if the object was disposed as the result of an error.
430
+ * @remarks Branches can also be automatically disposed when {@link TreeBranch.merge | they are merged} into another branch.
431
+ *
432
+ * Disposing branches is important to avoid consuming memory unnecessarily.
433
+ * In particular, the SharedTree retains all sequenced changes made to the tree since the "most-behind" branch was created or last {@link TreeBranch.rebaseOnto | rebased}.
434
+ *
435
+ * The {@link TreeBranch | main branch} cannot be disposed - attempting to do so will have no effect.
436
+ */
437
+ dispose(error?: Error): void;
438
+ }
439
+
349
440
  /**
350
441
  * An editable view of a (version control style) branch of a shared tree based on some schema.
351
442
  *
@@ -363,7 +454,7 @@ export function checkUnion(union: Iterable<TreeNodeSchema>, errors: string[]): v
363
454
  * Thus this design was chosen at the risk of apps blindly accessing `root` then breaking unexpectedly when the document is incompatible.
364
455
  * @sealed @public
365
456
  */
366
- export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposable {
457
+ export interface TreeView<in out TSchema extends ImplicitFieldSchema> extends IDisposable {
367
458
  /**
368
459
  * The current root of the tree.
369
460
  *
@@ -424,6 +515,24 @@ export interface TreeView<TSchema extends ImplicitFieldSchema> extends IDisposab
424
515
  readonly schema: TSchema;
425
516
  }
426
517
 
518
+ /**
519
+ * {@link TreeView} with proposed changes to the schema aware typing to allow use with `UnsafeUnknownSchema`.
520
+ * @sealed @alpha
521
+ */
522
+ export interface TreeViewAlpha<
523
+ in out TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema,
524
+ > extends Omit<TreeView<ReadSchema<TSchema>>, "root" | "initialize">,
525
+ Omit<TreeBranch, "events"> {
526
+ get root(): ReadableField<TSchema>;
527
+
528
+ set root(newRoot: InsertableField<TSchema>);
529
+
530
+ initialize(content: InsertableField<TSchema>): void;
531
+
532
+ // Override the base branch method to return a typed view rather than merely a branch.
533
+ fork(): ReturnType<TreeBranch["fork"]> & TreeViewAlpha<TSchema>;
534
+ }
535
+
427
536
  /**
428
537
  * Information about a view schema's compatibility with the document's stored schema.
429
538
  *
@@ -491,7 +600,7 @@ export interface SchemaCompatibilityStatus {
491
600
  *
492
601
  * @remarks
493
602
  * It's not necessary to check this field before calling {@link TreeView.initialize} in most scenarios; application authors typically know from
494
- * context that they're in a flow which creates a new `SharedTree` and would like to initialize it.
603
+ * branch that they're in a flow which creates a new `SharedTree` and would like to initialize it.
495
604
  */
496
605
  readonly canInitialize: boolean;
497
606
 
@@ -500,6 +609,32 @@ export interface SchemaCompatibilityStatus {
500
609
  // - details about the differences between the stored and view schema sufficient for implementing "safe mismatch" policies
501
610
  }
502
611
 
612
+ /**
613
+ * Events for {@link TreeBranch}.
614
+ * @sealed @alpha
615
+ */
616
+ export interface TreeBranchEvents {
617
+ /**
618
+ * The stored schema for the document has changed.
619
+ */
620
+ schemaChanged(): void;
621
+
622
+ /**
623
+ * Fired when:
624
+ * - a local commit is applied outside of a transaction
625
+ * - a local transaction is committed
626
+ *
627
+ * The event is not fired when:
628
+ * - a local commit is applied within a transaction
629
+ * - a remote commit is applied
630
+ *
631
+ * @param data - information about the commit that was applied
632
+ * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,
633
+ * this commit is not revertible.
634
+ */
635
+ commitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;
636
+ }
637
+
503
638
  /**
504
639
  * Events for {@link TreeView}.
505
640
  * @sealed @public
@@ -539,3 +674,13 @@ export interface TreeViewEvents {
539
674
  */
540
675
  commitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;
541
676
  }
677
+
678
+ /**
679
+ * Retrieve the {@link TreeViewAlpha | alpha API} for a {@link TreeView}.
680
+ * @alpha
681
+ */
682
+ export function asTreeViewAlpha<TSchema extends ImplicitFieldSchema>(
683
+ view: TreeView<TSchema>,
684
+ ): TreeViewAlpha<TSchema> {
685
+ return view as TreeViewAlpha<TSchema>;
686
+ }