@fluidframework/tree 2.41.0 → 2.42.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 (416) hide show
  1. package/.vscode/settings.json +1 -0
  2. package/CHANGELOG.md +33 -0
  3. package/api-report/tree.alpha.api.md +11 -7
  4. package/dist/alpha.d.ts +1 -0
  5. package/dist/codec/codec.d.ts +23 -3
  6. package/dist/codec/codec.d.ts.map +1 -1
  7. package/dist/codec/codec.js.map +1 -1
  8. package/dist/codec/index.d.ts +1 -1
  9. package/dist/codec/index.d.ts.map +1 -1
  10. package/dist/codec/index.js.map +1 -1
  11. package/dist/codec/versioned/codec.d.ts +35 -2
  12. package/dist/codec/versioned/codec.d.ts.map +1 -1
  13. package/dist/codec/versioned/codec.js +38 -3
  14. package/dist/codec/versioned/codec.js.map +1 -1
  15. package/dist/core/tree/detachedFieldIndex.d.ts +2 -2
  16. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  17. package/dist/core/tree/detachedFieldIndex.js +5 -1
  18. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  19. package/dist/core/tree/mapTree.d.ts +2 -1
  20. package/dist/core/tree/mapTree.d.ts.map +1 -1
  21. package/dist/core/tree/mapTree.js +11 -5
  22. package/dist/core/tree/mapTree.js.map +1 -1
  23. package/dist/core/tree/visitorUtils.d.ts +2 -2
  24. package/dist/core/tree/visitorUtils.d.ts.map +1 -1
  25. package/dist/core/tree/visitorUtils.js.map +1 -1
  26. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +3 -2
  27. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  28. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  29. package/dist/feature-libraries/default-schema/schemaChecker.d.ts +4 -3
  30. package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  31. package/dist/feature-libraries/default-schema/schemaChecker.js +4 -3
  32. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  33. package/dist/feature-libraries/flex-tree/context.d.ts +14 -6
  34. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  35. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  36. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +34 -14
  37. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  38. package/dist/feature-libraries/flex-tree/flexTreeTypes.js +4 -0
  39. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  40. package/dist/feature-libraries/flex-tree/index.d.ts +2 -2
  41. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  42. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  43. package/dist/feature-libraries/flex-tree/lazyField.d.ts +6 -6
  44. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  45. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  46. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +3 -2
  47. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  48. package/dist/feature-libraries/flex-tree/lazyNode.js +3 -0
  49. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  50. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +2 -2
  51. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  52. package/dist/feature-libraries/forest-summary/forestSummarizer.js +7 -7
  53. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  54. package/dist/feature-libraries/index.d.ts +2 -2
  55. package/dist/feature-libraries/index.d.ts.map +1 -1
  56. package/dist/feature-libraries/index.js +4 -2
  57. package/dist/feature-libraries/index.js.map +1 -1
  58. package/dist/feature-libraries/mapTreeCursor.d.ts +39 -3
  59. package/dist/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  60. package/dist/feature-libraries/mapTreeCursor.js +45 -7
  61. package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
  62. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  63. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  64. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +5 -5
  65. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  66. package/dist/feature-libraries/treeCursorUtils.d.ts +5 -1
  67. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  68. package/dist/feature-libraries/treeCursorUtils.js +8 -2
  69. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  70. package/dist/index.d.ts +1 -1
  71. package/dist/index.d.ts.map +1 -1
  72. package/dist/index.js.map +1 -1
  73. package/dist/packageVersion.d.ts +1 -1
  74. package/dist/packageVersion.js +1 -1
  75. package/dist/packageVersion.js.map +1 -1
  76. package/dist/shared-tree/schematizingTreeView.d.ts +11 -1
  77. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  78. package/dist/shared-tree/schematizingTreeView.js +36 -22
  79. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  80. package/dist/shared-tree/sharedTree.d.ts +3 -3
  81. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  82. package/dist/shared-tree/sharedTree.js +1 -0
  83. package/dist/shared-tree/sharedTree.js.map +1 -1
  84. package/dist/shared-tree/tree.d.ts.map +1 -1
  85. package/dist/shared-tree/tree.js +8 -24
  86. package/dist/shared-tree/tree.js.map +1 -1
  87. package/dist/shared-tree/treeAlpha.d.ts +2 -3
  88. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  89. package/dist/shared-tree/treeAlpha.js +13 -15
  90. package/dist/shared-tree/treeAlpha.js.map +1 -1
  91. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  92. package/dist/shared-tree/treeCheckout.js +5 -2
  93. package/dist/shared-tree/treeCheckout.js.map +1 -1
  94. package/dist/simple-tree/api/configuration.d.ts +2 -2
  95. package/dist/simple-tree/api/configuration.js +1 -1
  96. package/dist/simple-tree/api/configuration.js.map +1 -1
  97. package/dist/simple-tree/api/create.d.ts +9 -4
  98. package/dist/simple-tree/api/create.d.ts.map +1 -1
  99. package/dist/simple-tree/api/create.js +29 -16
  100. package/dist/simple-tree/api/create.js.map +1 -1
  101. package/dist/simple-tree/api/customTree.d.ts +4 -0
  102. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  103. package/dist/simple-tree/api/customTree.js +9 -1
  104. package/dist/simple-tree/api/customTree.js.map +1 -1
  105. package/dist/simple-tree/api/index.d.ts +1 -1
  106. package/dist/simple-tree/api/index.d.ts.map +1 -1
  107. package/dist/simple-tree/api/index.js +1 -2
  108. package/dist/simple-tree/api/index.js.map +1 -1
  109. package/dist/simple-tree/api/schemaFactory.d.ts +10 -2
  110. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  111. package/dist/simple-tree/api/schemaFactory.js +38 -9
  112. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  113. package/dist/simple-tree/api/treeNodeApi.d.ts +14 -3
  114. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  115. package/dist/simple-tree/api/treeNodeApi.js +32 -17
  116. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  117. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  118. package/dist/simple-tree/api/verboseTree.js +12 -9
  119. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  120. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  121. package/dist/simple-tree/core/getOrCreateNode.js +2 -1
  122. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  123. package/dist/simple-tree/core/index.d.ts +2 -2
  124. package/dist/simple-tree/core/index.d.ts.map +1 -1
  125. package/dist/simple-tree/core/index.js +3 -4
  126. package/dist/simple-tree/core/index.js.map +1 -1
  127. package/dist/simple-tree/core/treeNodeKernel.d.ts +15 -25
  128. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  129. package/dist/simple-tree/core/treeNodeKernel.js +26 -33
  130. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  131. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +128 -59
  132. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  133. package/dist/simple-tree/core/unhydratedFlexTree.js +169 -182
  134. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  135. package/dist/simple-tree/index.d.ts +3 -3
  136. package/dist/simple-tree/index.d.ts.map +1 -1
  137. package/dist/simple-tree/index.js +5 -5
  138. package/dist/simple-tree/index.js.map +1 -1
  139. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  140. package/dist/simple-tree/node-kinds/array/arrayNode.js +5 -6
  141. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  142. package/dist/simple-tree/node-kinds/index.d.ts +1 -1
  143. package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
  144. package/dist/simple-tree/node-kinds/index.js +1 -2
  145. package/dist/simple-tree/node-kinds/index.js.map +1 -1
  146. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  147. package/dist/simple-tree/node-kinds/map/mapNode.js +2 -2
  148. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  149. package/dist/simple-tree/node-kinds/object/index.d.ts +1 -1
  150. package/dist/simple-tree/node-kinds/object/index.d.ts.map +1 -1
  151. package/dist/simple-tree/node-kinds/object/index.js +1 -2
  152. package/dist/simple-tree/node-kinds/object/index.js.map +1 -1
  153. package/dist/simple-tree/node-kinds/object/objectNode.d.ts +3 -14
  154. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  155. package/dist/simple-tree/node-kinds/object/objectNode.js +12 -43
  156. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  157. package/dist/simple-tree/prepareForInsertion.d.ts +20 -6
  158. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  159. package/dist/simple-tree/prepareForInsertion.js +26 -19
  160. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  161. package/dist/simple-tree/schemaTypes.d.ts +8 -8
  162. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  163. package/dist/simple-tree/schemaTypes.js.map +1 -1
  164. package/dist/simple-tree/toStoredSchema.d.ts +6 -1
  165. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  166. package/dist/simple-tree/toStoredSchema.js +6 -3
  167. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  168. package/dist/simple-tree/{toMapTree.d.ts → unhydratedFlexTreeFromInsertable.d.ts} +12 -23
  169. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -0
  170. package/dist/simple-tree/{toMapTree.js → unhydratedFlexTreeFromInsertable.js} +103 -185
  171. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -0
  172. package/dist/treeFactory.d.ts.map +1 -1
  173. package/dist/treeFactory.js +6 -1
  174. package/dist/treeFactory.js.map +1 -1
  175. package/dist/util/index.d.ts +1 -1
  176. package/dist/util/index.d.ts.map +1 -1
  177. package/dist/util/index.js +2 -1
  178. package/dist/util/index.js.map +1 -1
  179. package/dist/util/utils.d.ts +4 -0
  180. package/dist/util/utils.d.ts.map +1 -1
  181. package/dist/util/utils.js +8 -1
  182. package/dist/util/utils.js.map +1 -1
  183. package/docs/user-facing/schema-evolution.md +1 -1
  184. package/lib/alpha.d.ts +1 -0
  185. package/lib/codec/codec.d.ts +23 -3
  186. package/lib/codec/codec.d.ts.map +1 -1
  187. package/lib/codec/codec.js.map +1 -1
  188. package/lib/codec/index.d.ts +1 -1
  189. package/lib/codec/index.d.ts.map +1 -1
  190. package/lib/codec/index.js.map +1 -1
  191. package/lib/codec/versioned/codec.d.ts +35 -2
  192. package/lib/codec/versioned/codec.d.ts.map +1 -1
  193. package/lib/codec/versioned/codec.js +36 -2
  194. package/lib/codec/versioned/codec.js.map +1 -1
  195. package/lib/core/tree/detachedFieldIndex.d.ts +2 -2
  196. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  197. package/lib/core/tree/detachedFieldIndex.js +6 -2
  198. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  199. package/lib/core/tree/mapTree.d.ts +2 -1
  200. package/lib/core/tree/mapTree.d.ts.map +1 -1
  201. package/lib/core/tree/mapTree.js +11 -5
  202. package/lib/core/tree/mapTree.js.map +1 -1
  203. package/lib/core/tree/visitorUtils.d.ts +2 -2
  204. package/lib/core/tree/visitorUtils.d.ts.map +1 -1
  205. package/lib/core/tree/visitorUtils.js.map +1 -1
  206. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +3 -2
  207. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  208. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  209. package/lib/feature-libraries/default-schema/schemaChecker.d.ts +4 -3
  210. package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  211. package/lib/feature-libraries/default-schema/schemaChecker.js +4 -3
  212. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  213. package/lib/feature-libraries/flex-tree/context.d.ts +14 -6
  214. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  215. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  216. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +34 -14
  217. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  218. package/lib/feature-libraries/flex-tree/flexTreeTypes.js +4 -0
  219. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  220. package/lib/feature-libraries/flex-tree/index.d.ts +2 -2
  221. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  222. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  223. package/lib/feature-libraries/flex-tree/lazyField.d.ts +6 -6
  224. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  225. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  226. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +3 -2
  227. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  228. package/lib/feature-libraries/flex-tree/lazyNode.js +3 -0
  229. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  230. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +2 -2
  231. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  232. package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -2
  233. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  234. package/lib/feature-libraries/index.d.ts +2 -2
  235. package/lib/feature-libraries/index.d.ts.map +1 -1
  236. package/lib/feature-libraries/index.js +1 -1
  237. package/lib/feature-libraries/index.js.map +1 -1
  238. package/lib/feature-libraries/mapTreeCursor.d.ts +39 -3
  239. package/lib/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  240. package/lib/feature-libraries/mapTreeCursor.js +43 -7
  241. package/lib/feature-libraries/mapTreeCursor.js.map +1 -1
  242. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  243. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  244. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +5 -5
  245. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  246. package/lib/feature-libraries/treeCursorUtils.d.ts +5 -1
  247. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  248. package/lib/feature-libraries/treeCursorUtils.js +8 -2
  249. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  250. package/lib/index.d.ts +1 -1
  251. package/lib/index.d.ts.map +1 -1
  252. package/lib/index.js.map +1 -1
  253. package/lib/packageVersion.d.ts +1 -1
  254. package/lib/packageVersion.js +1 -1
  255. package/lib/packageVersion.js.map +1 -1
  256. package/lib/shared-tree/schematizingTreeView.d.ts +11 -1
  257. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  258. package/lib/shared-tree/schematizingTreeView.js +34 -21
  259. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  260. package/lib/shared-tree/sharedTree.d.ts +3 -3
  261. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  262. package/lib/shared-tree/sharedTree.js +2 -1
  263. package/lib/shared-tree/sharedTree.js.map +1 -1
  264. package/lib/shared-tree/tree.d.ts.map +1 -1
  265. package/lib/shared-tree/tree.js +2 -18
  266. package/lib/shared-tree/tree.js.map +1 -1
  267. package/lib/shared-tree/treeAlpha.d.ts +2 -3
  268. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  269. package/lib/shared-tree/treeAlpha.js +4 -6
  270. package/lib/shared-tree/treeAlpha.js.map +1 -1
  271. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  272. package/lib/shared-tree/treeCheckout.js +6 -3
  273. package/lib/shared-tree/treeCheckout.js.map +1 -1
  274. package/lib/simple-tree/api/configuration.d.ts +2 -2
  275. package/lib/simple-tree/api/configuration.js +1 -1
  276. package/lib/simple-tree/api/configuration.js.map +1 -1
  277. package/lib/simple-tree/api/create.d.ts +9 -4
  278. package/lib/simple-tree/api/create.d.ts.map +1 -1
  279. package/lib/simple-tree/api/create.js +22 -9
  280. package/lib/simple-tree/api/create.js.map +1 -1
  281. package/lib/simple-tree/api/customTree.d.ts +4 -0
  282. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  283. package/lib/simple-tree/api/customTree.js +7 -0
  284. package/lib/simple-tree/api/customTree.js.map +1 -1
  285. package/lib/simple-tree/api/index.d.ts +1 -1
  286. package/lib/simple-tree/api/index.d.ts.map +1 -1
  287. package/lib/simple-tree/api/index.js +1 -1
  288. package/lib/simple-tree/api/index.js.map +1 -1
  289. package/lib/simple-tree/api/schemaFactory.d.ts +10 -2
  290. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  291. package/lib/simple-tree/api/schemaFactory.js +40 -11
  292. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  293. package/lib/simple-tree/api/treeNodeApi.d.ts +14 -3
  294. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  295. package/lib/simple-tree/api/treeNodeApi.js +35 -20
  296. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  297. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  298. package/lib/simple-tree/api/verboseTree.js +13 -10
  299. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  300. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  301. package/lib/simple-tree/core/getOrCreateNode.js +3 -2
  302. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  303. package/lib/simple-tree/core/index.d.ts +2 -2
  304. package/lib/simple-tree/core/index.d.ts.map +1 -1
  305. package/lib/simple-tree/core/index.js +2 -2
  306. package/lib/simple-tree/core/index.js.map +1 -1
  307. package/lib/simple-tree/core/treeNodeKernel.d.ts +15 -25
  308. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  309. package/lib/simple-tree/core/treeNodeKernel.js +24 -32
  310. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  311. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +128 -59
  312. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  313. package/lib/simple-tree/core/unhydratedFlexTree.js +166 -181
  314. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  315. package/lib/simple-tree/index.d.ts +3 -3
  316. package/lib/simple-tree/index.d.ts.map +1 -1
  317. package/lib/simple-tree/index.js +3 -3
  318. package/lib/simple-tree/index.js.map +1 -1
  319. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  320. package/lib/simple-tree/node-kinds/array/arrayNode.js +4 -5
  321. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  322. package/lib/simple-tree/node-kinds/index.d.ts +1 -1
  323. package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
  324. package/lib/simple-tree/node-kinds/index.js +1 -1
  325. package/lib/simple-tree/node-kinds/index.js.map +1 -1
  326. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  327. package/lib/simple-tree/node-kinds/map/mapNode.js +3 -3
  328. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  329. package/lib/simple-tree/node-kinds/object/index.d.ts +1 -1
  330. package/lib/simple-tree/node-kinds/object/index.d.ts.map +1 -1
  331. package/lib/simple-tree/node-kinds/object/index.js +1 -1
  332. package/lib/simple-tree/node-kinds/object/index.js.map +1 -1
  333. package/lib/simple-tree/node-kinds/object/objectNode.d.ts +3 -14
  334. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  335. package/lib/simple-tree/node-kinds/object/objectNode.js +3 -33
  336. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  337. package/lib/simple-tree/prepareForInsertion.d.ts +20 -6
  338. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  339. package/lib/simple-tree/prepareForInsertion.js +25 -19
  340. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  341. package/lib/simple-tree/schemaTypes.d.ts +8 -8
  342. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  343. package/lib/simple-tree/schemaTypes.js.map +1 -1
  344. package/lib/simple-tree/toStoredSchema.d.ts +6 -1
  345. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  346. package/lib/simple-tree/toStoredSchema.js +4 -1
  347. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  348. package/lib/simple-tree/{toMapTree.d.ts → unhydratedFlexTreeFromInsertable.d.ts} +12 -23
  349. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -0
  350. package/lib/simple-tree/{toMapTree.js → unhydratedFlexTreeFromInsertable.js} +105 -186
  351. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -0
  352. package/lib/treeFactory.d.ts.map +1 -1
  353. package/lib/treeFactory.js +6 -1
  354. package/lib/treeFactory.js.map +1 -1
  355. package/lib/util/index.d.ts +1 -1
  356. package/lib/util/index.d.ts.map +1 -1
  357. package/lib/util/index.js +1 -1
  358. package/lib/util/index.js.map +1 -1
  359. package/lib/util/utils.d.ts +4 -0
  360. package/lib/util/utils.d.ts.map +1 -1
  361. package/lib/util/utils.js +6 -0
  362. package/lib/util/utils.js.map +1 -1
  363. package/package.json +21 -21
  364. package/src/codec/codec.ts +24 -3
  365. package/src/codec/index.ts +1 -0
  366. package/src/codec/versioned/codec.ts +42 -5
  367. package/src/core/tree/detachedFieldIndex.ts +13 -4
  368. package/src/core/tree/mapTree.ts +22 -7
  369. package/src/core/tree/visitorUtils.ts +2 -2
  370. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +3 -2
  371. package/src/feature-libraries/default-schema/schemaChecker.ts +7 -6
  372. package/src/feature-libraries/flex-tree/context.ts +17 -7
  373. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +36 -15
  374. package/src/feature-libraries/flex-tree/index.ts +4 -0
  375. package/src/feature-libraries/flex-tree/lazyField.ts +8 -6
  376. package/src/feature-libraries/flex-tree/lazyNode.ts +6 -2
  377. package/src/feature-libraries/forest-summary/forestSummarizer.ts +3 -2
  378. package/src/feature-libraries/index.ts +9 -0
  379. package/src/feature-libraries/mapTreeCursor.ts +103 -16
  380. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +9 -5
  381. package/src/feature-libraries/treeCursorUtils.ts +21 -10
  382. package/src/index.ts +1 -0
  383. package/src/packageVersion.ts +1 -1
  384. package/src/shared-tree/schematizingTreeView.ts +40 -22
  385. package/src/shared-tree/sharedTree.ts +9 -3
  386. package/src/shared-tree/tree.ts +5 -20
  387. package/src/shared-tree/treeAlpha.ts +17 -11
  388. package/src/shared-tree/treeCheckout.ts +6 -3
  389. package/src/simple-tree/api/configuration.ts +3 -3
  390. package/src/simple-tree/api/create.ts +49 -19
  391. package/src/simple-tree/api/customTree.ts +10 -0
  392. package/src/simple-tree/api/index.ts +1 -4
  393. package/src/simple-tree/api/schemaFactory.ts +62 -13
  394. package/src/simple-tree/api/treeNodeApi.ts +48 -27
  395. package/src/simple-tree/api/verboseTree.ts +15 -12
  396. package/src/simple-tree/core/getOrCreateNode.ts +4 -2
  397. package/src/simple-tree/core/index.ts +2 -3
  398. package/src/simple-tree/core/treeNodeKernel.ts +37 -54
  399. package/src/simple-tree/core/unhydratedFlexTree.ts +222 -261
  400. package/src/simple-tree/index.ts +3 -3
  401. package/src/simple-tree/node-kinds/array/arrayNode.ts +12 -13
  402. package/src/simple-tree/node-kinds/index.ts +0 -1
  403. package/src/simple-tree/node-kinds/map/mapNode.ts +6 -9
  404. package/src/simple-tree/node-kinds/object/index.ts +0 -1
  405. package/src/simple-tree/node-kinds/object/objectNode.ts +7 -49
  406. package/src/simple-tree/prepareForInsertion.ts +49 -42
  407. package/src/simple-tree/schemaTypes.ts +9 -8
  408. package/src/simple-tree/toStoredSchema.ts +7 -1
  409. package/src/simple-tree/{toMapTree.ts → unhydratedFlexTreeFromInsertable.ts} +134 -226
  410. package/src/treeFactory.ts +6 -1
  411. package/src/util/index.ts +1 -0
  412. package/src/util/utils.ts +7 -0
  413. package/dist/simple-tree/toMapTree.d.ts.map +0 -1
  414. package/dist/simple-tree/toMapTree.js.map +0 -1
  415. package/lib/simple-tree/toMapTree.d.ts.map +0 -1
  416. package/lib/simple-tree/toMapTree.js.map +0 -1
@@ -247,28 +247,7 @@ export class SchematizingSimpleTreeView<
247
247
  constraintsOnRevert: boolean,
248
248
  constraints: readonly TransactionConstraint[] = [],
249
249
  ): void => {
250
- for (const constraint of constraints) {
251
- switch (constraint.type) {
252
- case "nodeInDocument": {
253
- const node = getOrCreateInnerNode(constraint.node);
254
- const nodeStatus = getKernel(constraint.node).getStatus();
255
- if (nodeStatus !== TreeStatus.InDocument) {
256
- const revertText = constraintsOnRevert ? " on revert" : "";
257
- throw new UsageError(
258
- `Attempted to add a "nodeInDocument" constraint${revertText}, but the node is not currently in the document. Node status: ${nodeStatus}`,
259
- );
260
- }
261
- if (constraintsOnRevert) {
262
- this.checkout.editor.addNodeExistsConstraintOnRevert(node.anchorNode);
263
- } else {
264
- this.checkout.editor.addNodeExistsConstraint(node.anchorNode);
265
- }
266
- break;
267
- }
268
- default:
269
- unreachableCase(constraint.type);
270
- }
271
- }
250
+ addConstraintsToTransaction(this.checkout, constraintsOnRevert, constraints);
272
251
  };
273
252
 
274
253
  this.checkout.transaction.start();
@@ -520,3 +499,42 @@ export function requireSchema(
520
499
 
521
500
  return view;
522
501
  }
502
+
503
+ /**
504
+ * Adds constraints to a `checkout`'s pending transaction.
505
+ *
506
+ * @param checkout - The checkout's who's transaction will have the constraints added to it.
507
+ * @param constraintsOnRevert - If true, use {@link ISharedTreeEditor.addNodeExistsConstraintOnRevert}.
508
+ * @param constraints - The constraints to add to the transaction.
509
+ *
510
+ * @see {@link RunTransactionParams.preconditions}.
511
+ */
512
+ export function addConstraintsToTransaction(
513
+ checkout: ITreeCheckout,
514
+ constraintsOnRevert: boolean,
515
+ constraints: readonly TransactionConstraint[] = [],
516
+ ): void {
517
+ for (const constraint of constraints) {
518
+ switch (constraint.type) {
519
+ case "nodeInDocument": {
520
+ const node = getOrCreateInnerNode(constraint.node);
521
+ const nodeStatus = getKernel(constraint.node).getStatus();
522
+ if (nodeStatus !== TreeStatus.InDocument) {
523
+ const revertText = constraintsOnRevert ? " on revert" : "";
524
+ throw new UsageError(
525
+ `Attempted to add a "nodeInDocument" constraint${revertText}, but the node is not currently in the document. Node status: ${nodeStatus}`,
526
+ );
527
+ }
528
+ assert(node.isHydrated(), "In document node must be hydrated.");
529
+ if (constraintsOnRevert) {
530
+ checkout.editor.addNodeExistsConstraintOnRevert(node.anchorNode);
531
+ } else {
532
+ checkout.editor.addNodeExistsConstraint(node.anchorNode);
533
+ }
534
+ break;
535
+ }
536
+ default:
537
+ unreachableCase(constraint.type);
538
+ }
539
+ }
540
+ }
@@ -21,7 +21,12 @@ import {
21
21
  type ITelemetryLoggerExt,
22
22
  } from "@fluidframework/telemetry-utils/internal";
23
23
 
24
- import { type ICodecOptions, noopValidator } from "../codec/index.js";
24
+ import {
25
+ type CodecWriteOptions,
26
+ FluidClientVersion,
27
+ type ICodecOptions,
28
+ noopValidator,
29
+ } from "../codec/index.js";
25
30
  import {
26
31
  type FieldKey,
27
32
  type GraphCommit,
@@ -585,9 +590,9 @@ export type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;
585
590
 
586
591
  /**
587
592
  * Configuration options for SharedTree.
588
- * @alpha
593
+ * @alpha @input
589
594
  */
590
- export type SharedTreeOptions = Partial<ICodecOptions> &
595
+ export type SharedTreeOptions = Partial<CodecWriteOptions> &
591
596
  Partial<SharedTreeFormatOptions> &
592
597
  ForestOptions;
593
598
 
@@ -702,6 +707,7 @@ export function buildConfiguredForest(
702
707
 
703
708
  export const defaultSharedTreeOptions: Required<SharedTreeOptionsInternal> = {
704
709
  jsonValidator: noopValidator,
710
+ oldestCompatibleClient: FluidClientVersion.v2_0,
705
711
  forest: ForestTypeReference,
706
712
  treeEncodeType: TreeCompressionStrategy.Compressed,
707
713
  formatVersion: SharedTreeFormatVersion.v3,
@@ -3,10 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { unreachableCase } from "@fluidframework/core-utils/internal";
7
6
  import { UsageError } from "@fluidframework/telemetry-utils/internal";
8
7
 
9
- import { TreeStatus } from "../feature-libraries/index.js";
10
8
  import {
11
9
  type ImplicitFieldSchema,
12
10
  type TreeNode,
@@ -19,7 +17,10 @@ import {
19
17
  } from "../simple-tree/index.js";
20
18
 
21
19
  import { getCheckoutFlexTreeView } from "./checkoutFlexTreeView.js";
22
- import { SchematizingSimpleTreeView } from "./schematizingTreeView.js";
20
+ import {
21
+ addConstraintsToTransaction,
22
+ SchematizingSimpleTreeView,
23
+ } from "./schematizingTreeView.js";
23
24
  import type { ITreeCheckout } from "./treeCheckout.js";
24
25
 
25
26
  /**
@@ -463,23 +464,7 @@ function runTransactionInCheckout<TResult>(
463
464
  preconditions: readonly TransactionConstraint[],
464
465
  ): TResult | typeof rollback {
465
466
  checkout.transaction.start();
466
- for (const constraint of preconditions) {
467
- switch (constraint.type) {
468
- case "nodeInDocument": {
469
- const node = getOrCreateInnerNode(constraint.node);
470
- const nodeStatus = Tree.status(constraint.node);
471
- if (nodeStatus !== TreeStatus.InDocument) {
472
- throw new UsageError(
473
- `Attempted to add a "nodeInDocument" constraint, but the node is not currently in the document. Node status: ${nodeStatus}`,
474
- );
475
- }
476
- checkout.editor.addNodeExistsConstraint(node.anchorNode);
477
- break;
478
- }
479
- default:
480
- unreachableCase(constraint.type);
481
- }
482
- }
467
+ addConstraintsToTransaction(checkout, false, preconditions);
483
468
 
484
469
  let result: ReturnType<typeof transaction>;
485
470
  try {
@@ -38,10 +38,11 @@ import {
38
38
  getPropertyKeyFromStoredKey,
39
39
  treeNodeApi,
40
40
  getIdentifierFromNode,
41
- mapTreeFromNodeData,
41
+ unhydratedFlexTreeFromInsertable,
42
+ getOrCreateNodeFromInnerNode,
42
43
  } from "../simple-tree/index.js";
43
44
  import { extractFromOpaque, type JsonCompatible } from "../util/index.js";
44
- import { noopValidator, type FluidClientVersion, type ICodecOptions } from "../codec/index.js";
45
+ import type { CodecWriteOptions, ICodecOptions } from "../codec/index.js";
45
46
  import type { ITreeCursorSynchronous } from "../core/index.js";
46
47
  import {
47
48
  cursorForMapTreeField,
@@ -57,8 +58,7 @@ import {
57
58
  } from "../feature-libraries/index.js";
58
59
  import { independentInitializedView, type ViewContent } from "./independentView.js";
59
60
  import { SchematizingSimpleTreeView, ViewSlot } from "./schematizingTreeView.js";
60
- import { currentVersion } from "../codec/index.js";
61
- import { createFromMapTree } from "../simple-tree/index.js";
61
+ import { currentVersion, noopValidator } from "../codec/index.js";
62
62
 
63
63
  const identifier: TreeIdentifierUtils = (node: TreeNode): string | undefined => {
64
64
  const nodeIdentifier = getIdentifierFromNode(node, "uncompressed");
@@ -295,7 +295,10 @@ export interface TreeAlpha {
295
295
  */
296
296
  exportCompressed(
297
297
  tree: TreeNode | TreeLeafValue,
298
- options: { oldestCompatibleClient: FluidClientVersion; idCompressor?: IIdCompressor },
298
+ options: { idCompressor?: IIdCompressor } & Pick<
299
+ CodecWriteOptions,
300
+ "oldestCompatibleClient"
301
+ >,
299
302
  ): JsonCompatible<IFluidHandle>;
300
303
 
301
304
  /**
@@ -367,8 +370,11 @@ export const TreeAlpha: TreeAlpha = {
367
370
  ? TreeFieldFromImplicitField<TSchema>
368
371
  : TreeNode | TreeLeafValue | undefined
369
372
  > {
370
- const mapTree = mapTreeFromNodeData(data as InsertableField<UnsafeUnknownSchema>, schema);
371
- const result = mapTree === undefined ? undefined : createFromMapTree(schema, mapTree);
373
+ const mapTree = unhydratedFlexTreeFromInsertable(
374
+ data as InsertableField<UnsafeUnknownSchema>,
375
+ schema,
376
+ );
377
+ const result = mapTree === undefined ? undefined : getOrCreateNodeFromInnerNode(mapTree);
372
378
  return result as Unhydrated<
373
379
  TSchema extends ImplicitFieldSchema
374
380
  ? TreeFieldFromImplicitField<TSchema>
@@ -426,10 +432,10 @@ export const TreeAlpha: TreeAlpha = {
426
432
 
427
433
  exportCompressed(
428
434
  node: TreeNode | TreeLeafValue,
429
- options: {
430
- oldestCompatibleClient: FluidClientVersion;
431
- idCompressor?: IIdCompressor;
432
- },
435
+ options: { idCompressor?: IIdCompressor } & Pick<
436
+ CodecWriteOptions,
437
+ "oldestCompatibleClient"
438
+ >,
433
439
  ): JsonCompatible<IFluidHandle> {
434
440
  const schema = tryGetSchema(node) ?? fail(0xacf /* invalid input */);
435
441
  const format = fluidVersionToFieldBatchCodecWriteVersion(options.oldestCompatibleClient);
@@ -11,7 +11,7 @@ import {
11
11
  UsageError,
12
12
  type ITelemetryLoggerExt,
13
13
  } from "@fluidframework/telemetry-utils/internal";
14
- import { noopValidator } from "../codec/index.js";
14
+ import { FluidClientVersion, noopValidator } from "../codec/index.js";
15
15
  import {
16
16
  type Anchor,
17
17
  type AnchorLocator,
@@ -279,7 +279,10 @@ export function createTreeCheckout(
279
279
  const breaker = args?.breaker ?? new Breakable("TreeCheckout");
280
280
  const schema = args?.schema ?? new TreeStoredSchemaRepository();
281
281
  const forest = args?.forest ?? buildForest(breaker, schema);
282
- const defaultCodecOptions = { jsonValidator: noopValidator };
282
+ const defaultCodecOptions = {
283
+ jsonValidator: noopValidator,
284
+ oldestCompatibleClient: FluidClientVersion.v2_0,
285
+ };
283
286
  const defaultFieldBatchVersion = 1;
284
287
  const changeFamily =
285
288
  args?.changeFamily ??
@@ -287,7 +290,7 @@ export function createTreeCheckout(
287
290
  revisionTagCodec,
288
291
  args?.fieldBatchCodec ??
289
292
  makeFieldBatchCodec(defaultCodecOptions, defaultFieldBatchVersion),
290
- { jsonValidator: noopValidator },
293
+ defaultCodecOptions,
291
294
  args?.chunkCompressionStrategy,
292
295
  idCompressor,
293
296
  );
@@ -107,8 +107,8 @@ export interface ITreeConfigurationOptions {
107
107
  *
108
108
  * To make this more permissive in the future we can:
109
109
  *
110
- * - Make toMapTree more permissive (ex: allow disambiguation based on leaf type)
111
- * - Update this check to more tightly match toMapTree
110
+ * - Make unhydratedFlexTreeFromInsertable more permissive (ex: allow disambiguation based on leaf type)
111
+ * - Update this check to more tightly match unhydratedFlexTreeFromInsertable
112
112
  * - Add options to help schema authors disambiguate their types, such as "constant fields" which are not persisted, and always have a constant value.
113
113
  *
114
114
  * The above examples exist in executable form in this files tests, and should be updated there then copied back here.
@@ -343,7 +343,7 @@ export function checkUnion(union: Iterable<TreeNodeSchema>, errors: string[]): v
343
343
  // Allow using the type of the field to disambiguate, at least for leaf types.
344
344
  // Add "constant" fields which can be used to disambiguate even more cases without adding persisted data: maybe make them optional in constructor?
345
345
  // Consider separating unambiguous implicit construction format from constructor arguments at type level, allowing constructor to superset the implicit construction options (ex: optional constant fields).
346
- // The policy here however must remain at least as conservative as shallowCompatibilityTest in src/simple-tree/toMapTree.ts.
346
+ // The policy here however must remain at least as conservative as shallowCompatibilityTest in src/simple-tree/unhydratedFlexTreeFromInsertable.ts.
347
347
 
348
348
  errors.push(
349
349
  `The required fields of ${JSON.stringify(schema.identifier)} are insufficient to differentiate it from the following types: ${formatTypes(possiblyAmbiguous)}. For objects to be considered unambiguous, each must have required fields that do not all occur on any other object in the union.`,
@@ -5,35 +5,46 @@
5
5
 
6
6
  import { assert } from "@fluidframework/core-utils/internal";
7
7
 
8
- import type {
9
- ExclusiveMapTree,
10
- ITreeCursorSynchronous,
11
- SchemaAndPolicy,
8
+ import {
9
+ CursorLocationType,
10
+ mapCursorField,
11
+ mapCursorFields,
12
+ type ITreeCursorSynchronous,
13
+ type SchemaAndPolicy,
12
14
  } from "../../core/index.js";
13
15
  import type { ImplicitFieldSchema, TreeFieldFromImplicitField } from "../schemaTypes.js";
14
16
  import {
17
+ type Context,
15
18
  getOrCreateNodeFromInnerNode,
16
- UnhydratedFlexTreeNode,
19
+ type NodeKind,
17
20
  type Unhydrated,
21
+ UnhydratedFlexTreeNode,
22
+ createField,
18
23
  } from "../core/index.js";
19
24
  import {
20
25
  defaultSchemaPolicy,
21
26
  inSchemaOrThrow,
22
- mapTreeFromCursor,
23
27
  isFieldInSchema,
24
28
  } from "../../feature-libraries/index.js";
25
29
  import { getUnhydratedContext } from "../createContext.js";
26
30
  import { createUnknownOptionalFieldPolicy } from "../node-kinds/index.js";
31
+ import type { SimpleNodeSchema, SimpleNodeSchemaBase } from "../simpleSchema.js";
32
+ import { getStoredSchema } from "../toStoredSchema.js";
33
+ import { unknownTypeError } from "./customTree.js";
27
34
 
28
35
  /**
29
36
  * Creates an unhydrated simple-tree field from a cursor in nodes mode.
37
+ * @remarks
38
+ * Does not support defaults.
39
+ * Validates the field is in schema.
30
40
  */
31
41
  export function createFromCursor<const TSchema extends ImplicitFieldSchema>(
32
42
  schema: TSchema,
33
43
  cursor: ITreeCursorSynchronous | undefined,
34
44
  ): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
35
- const mapTrees = cursor === undefined ? [] : [mapTreeFromCursor(cursor)];
36
45
  const context = getUnhydratedContext(schema);
46
+ const mapTrees = cursor === undefined ? [] : [unhydratedFlexTreeFromCursor(context, cursor)];
47
+
37
48
  const flexSchema = context.flexContext.schema;
38
49
 
39
50
  const schemaValidationPolicy: SchemaAndPolicy = {
@@ -58,21 +69,40 @@ export function createFromCursor<const TSchema extends ImplicitFieldSchema>(
58
69
  // Length asserted above, so this is safe. This assert is done instead of checking for undefined after indexing to ensure a length greater than 1 also errors.
59
70
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
60
71
  const mapTree = mapTrees[0]!;
61
- return createFromMapTree(schema, mapTree);
72
+
73
+ return getOrCreateNodeFromInnerNode(mapTree) as Unhydrated<
74
+ TreeFieldFromImplicitField<TSchema>
75
+ >;
62
76
  }
63
77
 
64
78
  /**
65
- * Creates an unhydrated simple-tree field from an ExclusiveMapTree.
79
+ * Construct an {@link UnhydratedFlexTreeNode} from a cursor in Nodes mode.
80
+ * @remarks
81
+ * This does not validate the node is in schema.
66
82
  */
67
- export function createFromMapTree<const TSchema extends ImplicitFieldSchema>(
68
- schema: TSchema,
69
- mapTree: ExclusiveMapTree,
70
- ): Unhydrated<TreeFieldFromImplicitField<TSchema>> {
71
- const mapTreeNode = UnhydratedFlexTreeNode.getOrCreate(
72
- getUnhydratedContext(schema),
73
- mapTree,
83
+ export function unhydratedFlexTreeFromCursor(
84
+ context: Context,
85
+ cursor: ITreeCursorSynchronous,
86
+ ): UnhydratedFlexTreeNode {
87
+ assert(cursor.mode === CursorLocationType.Nodes, 0xbb4 /* Expected nodes cursor */);
88
+ const schema = context.schema.get(cursor.type) ?? unknownTypeError(cursor.type);
89
+ const storedSchema = getStoredSchema(
90
+ schema as SimpleNodeSchemaBase<NodeKind> as SimpleNodeSchema,
91
+ );
92
+ const fields = new Map(
93
+ mapCursorFields(cursor, () => [
94
+ cursor.getFieldKey(),
95
+ createField(
96
+ context.flexContext,
97
+ storedSchema.getFieldSchema(cursor.getFieldKey()).kind,
98
+ cursor.getFieldKey(),
99
+ mapCursorField(cursor, () => unhydratedFlexTreeFromCursor(context, cursor)),
100
+ ),
101
+ ]),
102
+ );
103
+ return new UnhydratedFlexTreeNode(
104
+ { type: cursor.type, value: cursor.value },
105
+ fields,
106
+ context,
74
107
  );
75
-
76
- const result = getOrCreateNodeFromInnerNode(mapTreeNode);
77
- return result as Unhydrated<TreeFieldFromImplicitField<TSchema>>;
78
108
  }
@@ -6,6 +6,7 @@
6
6
  import type { IFluidHandle } from "@fluidframework/core-interfaces";
7
7
  import { assert, fail } from "@fluidframework/core-utils/internal";
8
8
  import { isFluidHandle } from "@fluidframework/runtime-utils/internal";
9
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
9
10
 
10
11
  import {
11
12
  EmptyKey,
@@ -231,3 +232,12 @@ export function replaceHandles<T>(tree: unknown, replacer: HandleConverter<T>):
231
232
  }
232
233
  });
233
234
  }
235
+
236
+ /**
237
+ * Throws a `UsageError` indicating that a type is unknown in the current context.
238
+ */
239
+ export function unknownTypeError(type: string): never {
240
+ throw new UsageError(
241
+ `Failed to parse tree due to occurrence of type ${JSON.stringify(type)} which is not defined in this context.`,
242
+ );
243
+ }
@@ -52,10 +52,7 @@ export {
52
52
  getPropertyKeyFromStoredKey,
53
53
  getIdentifierFromNode,
54
54
  } from "./treeNodeApi.js";
55
- export {
56
- createFromCursor,
57
- createFromMapTree,
58
- } from "./create.js";
55
+ export { createFromCursor } from "./create.js";
59
56
  export {
60
57
  type JsonSchemaId,
61
58
  type JsonSchemaType,
@@ -6,14 +6,15 @@
6
6
  import type { IFluidHandle } from "@fluidframework/core-interfaces";
7
7
  import { assert, unreachableCase } from "@fluidframework/core-utils/internal";
8
8
  import { isFluidHandle } from "@fluidframework/runtime-utils/internal";
9
+ import { UsageError } from "@fluidframework/telemetry-utils/internal";
9
10
 
10
11
  import type { TreeValue } from "../../core/index.js";
11
- import type { NodeIdentifierManager } from "../../feature-libraries/index.js";
12
12
  // This import is required for intellisense in @link doc comments on mouseover in VSCode.
13
13
  // eslint-disable-next-line unused-imports/no-unused-imports, @typescript-eslint/no-unused-vars
14
14
  import type { TreeAlpha } from "../../shared-tree/index.js";
15
15
  import {
16
16
  type RestrictiveStringRecord,
17
+ compareSets,
17
18
  getOrCreate,
18
19
  isReadonlyArray,
19
20
  } from "../../util/index.js";
@@ -24,6 +25,7 @@ import type {
24
25
  TreeNodeSchemaClass,
25
26
  TreeNodeSchemaNonClass,
26
27
  TreeNodeSchemaBoth,
28
+ UnhydratedFlexTreeNode,
27
29
  } from "../core/index.js";
28
30
  import { isLazy } from "../flexList.js";
29
31
  import {
@@ -60,10 +62,15 @@ import {
60
62
  type ImplicitAnnotatedAllowedTypes,
61
63
  type UnannotateImplicitAllowedTypes,
62
64
  type UnannotateSchemaRecord,
65
+ normalizeAllowedTypes,
63
66
  } from "../schemaTypes.js";
64
67
 
65
68
  import { createFieldSchemaUnsafe } from "./schemaFactoryRecursive.js";
66
69
  import type { System_Unsafe, FieldSchemaAlphaUnsafe } from "./typesUnsafe.js";
70
+ import type { IIdCompressor } from "@fluidframework/id-compressor";
71
+ import { createIdCompressor } from "@fluidframework/id-compressor/internal";
72
+ import type { FlexTreeHydratedContextMinimal } from "../../feature-libraries/index.js";
73
+ import { unhydratedFlexTreeFromInsertable } from "../unhydratedFlexTreeFromInsertable.js";
67
74
 
68
75
  /**
69
76
  * Gets the leaf domain schema compatible with a given {@link TreeValue}.
@@ -293,9 +300,7 @@ export interface SchemaStatics {
293
300
  ) => System_Unsafe.FieldSchemaUnsafe<FieldKind.Required, T, TCustomMetadata>;
294
301
  }
295
302
 
296
- const defaultOptionalProvider: DefaultProvider = getDefaultProvider(() => {
297
- return undefined;
298
- });
303
+ const defaultOptionalProvider: DefaultProvider = getDefaultProvider(() => []);
299
304
 
300
305
  // The following overloads for optional and required are used to get around the fact that
301
306
  // the compiler can't infer that UnannotateImplicitAllowedTypes<T> is equal to T when T is known to extend ImplicitAllowedTypes
@@ -766,9 +771,9 @@ export class SchemaFactory<
766
771
  if (allowedTypes === undefined) {
767
772
  const types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];
768
773
  const fullName = structuralName("Map", types);
769
- return getOrCreate(
770
- this.structuralTypes,
774
+ return this.getStructuralType(
771
775
  fullName,
776
+ types,
772
777
  () =>
773
778
  this.namedMap(
774
779
  fullName as TName,
@@ -954,7 +959,7 @@ export class SchemaFactory<
954
959
  if (allowedTypes === undefined) {
955
960
  const types = nameOrAllowedTypes as (T & TreeNodeSchema) | readonly TreeNodeSchema[];
956
961
  const fullName = structuralName("Array", types);
957
- return getOrCreate(this.structuralTypes, fullName, () =>
962
+ return this.getStructuralType(fullName, types, () =>
958
963
  this.namedArray(fullName, nameOrAllowedTypes as T, false, true),
959
964
  ) as TreeNodeSchemaClass<
960
965
  ScopedSchemaName<TScope, string>,
@@ -978,6 +983,35 @@ export class SchemaFactory<
978
983
  return out;
979
984
  }
980
985
 
986
+ /**
987
+ * Retrieves or creates a structural {@link TreeNodeSchema} with the specified name and types.
988
+ *
989
+ * @param fullName - The name for the structural schema.
990
+ * @param types - The input schema(s) used to define the structural schema.
991
+ * @param builder - A function that builds the schema if it does not already exist.
992
+ * @returns The structural {@link TreeNodeSchema} associated with the given name and types.
993
+ * @throws `UsageError` if a schema structurally named schema with the same name is cached in `structuralTypes` but had different input types.
994
+ */
995
+ private getStructuralType(
996
+ fullName: string,
997
+ types: TreeNodeSchema | readonly TreeNodeSchema[],
998
+ builder: () => TreeNodeSchema,
999
+ ): TreeNodeSchema {
1000
+ const structural = getOrCreate(this.structuralTypes, fullName, builder);
1001
+ const inputTypes = new Set(normalizeAllowedTypes(types));
1002
+ const outputTypes = new Set(
1003
+ normalizeAllowedTypes(structural.info as TreeNodeSchema | readonly TreeNodeSchema[]),
1004
+ );
1005
+ // If our cached value had a different set of types then were requested, the user must have caused a collision.
1006
+ const same = compareSets({ a: inputTypes, b: outputTypes });
1007
+ if (!same) {
1008
+ throw new UsageError(
1009
+ `Structurally named schema collision: two schema named "${fullName}" were defined with different input schema.`,
1010
+ );
1011
+ }
1012
+ return structural;
1013
+ }
1014
+
981
1015
  /**
982
1016
  * Define a {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.
983
1017
  *
@@ -1080,8 +1114,6 @@ export class SchemaFactory<
1080
1114
  *
1081
1115
  * - A compressed form of the identifier can be accessed at runtime via the {@link TreeNodeApi.shortId|Tree.shortId()} API.
1082
1116
  *
1083
- * - It will not be present in the object's iterable properties until explicitly read or until having been inserted into a tree.
1084
- *
1085
1117
  * However, a user may alternatively supply their own string as the identifier if desired (for example, if importing identifiers from another system).
1086
1118
  * In that case, if the user requires it to be unique, it is up to them to ensure uniqueness.
1087
1119
  * User-supplied identifiers may be read immediately, even before insertion into the tree.
@@ -1090,10 +1122,19 @@ export class SchemaFactory<
1090
1122
  */
1091
1123
  public get identifier(): FieldSchema<FieldKind.Identifier, typeof this.string> {
1092
1124
  const defaultIdentifierProvider: DefaultProvider = getDefaultProvider(
1093
- (nodeKeyManager: NodeIdentifierManager) => {
1094
- return nodeKeyManager.stabilizeNodeIdentifier(
1095
- nodeKeyManager.generateLocalNodeIdentifier(),
1096
- );
1125
+ (
1126
+ context: FlexTreeHydratedContextMinimal | "UseGlobalContext",
1127
+ ): UnhydratedFlexTreeNode[] => {
1128
+ const id =
1129
+ context === "UseGlobalContext"
1130
+ ? globalIdentifierAllocator.decompress(
1131
+ globalIdentifierAllocator.generateCompressedId(),
1132
+ )
1133
+ : context.nodeKeyManager.stabilizeNodeIdentifier(
1134
+ context.nodeKeyManager.generateLocalNodeIdentifier(),
1135
+ );
1136
+
1137
+ return [unhydratedFlexTreeFromInsertable(id, this.string)];
1097
1138
  },
1098
1139
  );
1099
1140
  return createFieldSchema(FieldKind.Identifier, this.string, {
@@ -1266,3 +1307,11 @@ export function structuralName<const T extends string>(
1266
1307
  }
1267
1308
  return `${collectionName}<${inner}>`;
1268
1309
  }
1310
+
1311
+ /**
1312
+ * Used to allocate default identifiers for unhydrated nodes when no context is available.
1313
+ * @remarks
1314
+ * The identifiers allocated by this will never be compressed to Short Ids.
1315
+ * Using this is only better than creating fully random V4 UUIDs because it reduces the entropy making it possible for things like text compression to work slightly better.
1316
+ */
1317
+ const globalIdentifierAllocator: IIdCompressor = createIdCompressor();