@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
@@ -1 +0,0 @@
1
- {"version":3,"file":"toMapTree.js","sourceRoot":"","sources":["../../src/simple-tree/toMapTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAoF;AACpF,uEAAsE;AACtE,qEAAuE;AAEvE,+CAO0B;AAC1B,4DAIuC;AACvC,+CAAoF;AAEpF,2DAAiD;AACjD,qDAW0B;AAC1B,8CAUyB;AACzB,oEAAoE;AACpE,qFAAqF;AACrF,iFAAiF;AACjF,mCAAmC;AACnC,sDAAsD;AACtD,+EAA4E;AAG5E;;;;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U,EAAC,MAAM,CAAC,EAAE,CAAC;QACxB,OAAO,IAAA,oBAAS,EAAC,MAAM,CAAC,CAAC,eAAe,EAAE,CAAC;IAC5C,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\n\nimport {\n\tEmptyKey,\n\ttype FieldKey,\n\ttype MapTree,\n\ttype TreeValue,\n\ttype ValueSchema,\n\ttype ExclusiveMapTree,\n} from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tvalueSchemaAllows,\n\ttype NodeIdentifierManager,\n} from \"../feature-libraries/index.js\";\nimport { brand, isReadonlyArray, find, hasSome, hasSingle } from \"../util/index.js\";\n\nimport { nullSchema } from \"./leafNodeSchema.js\";\nimport {\n\ttype FieldSchema,\n\ttype ImplicitAllowedTypes,\n\tnormalizeAllowedTypes,\n\textractFieldProvider,\n\tisConstant,\n\ttype FieldProvider,\n\ttype ImplicitFieldSchema,\n\tnormalizeFieldSchema,\n\tFieldKind,\n\ttype TreeLeafValue,\n} from \"./schemaTypes.js\";\nimport {\n\tgetKernel,\n\tgetSimpleNodeSchemaFromInnerNode,\n\tisTreeNode,\n\tNodeKind,\n\ttype InnerNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype Unhydrated,\n\tUnhydratedFlexTreeNode,\n} from \"./core/index.js\";\n// Required to prevent the introduction of new circular dependencies\n// TODO: Having the schema provide their own policy functions for compatibility which\n// toMapTree invokes instead of manually handling each kind would remove this bad\n// dependency, and reduce coupling.\n// eslint-disable-next-line import/no-internal-modules\nimport { isObjectNodeSchema } from \"./node-kinds/object/objectNodeTypes.js\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\n\n/**\n * Module notes:\n *\n * The flow of the below code is in terms of the structure of the input data. We then verify that the associated\n * schema is appropriate for that kind of data. This is fine while we have a 1:1 mapping of kind of input data to\n * the kind of schema we expect for it (e.g. an input that is an array always need to be associated with a sequence in\n * the schema). If/when we begin accepting kinds of input data that are ambiguous (e.g. accepting an input that is an\n * array of key/value tuples to instantiate a map) we may need to rethink the structure here to be based more on the\n * schema than on the input data.\n */\n\n/**\n * Transforms an input {@link TypedNode} tree to a {@link MapTree}.\n * @param data - The input tree to be converted.\n * If the data is an unsupported value (e.g. NaN), a fallback value will be used when supported,\n * otherwise an error will be thrown.\n *\n * Fallbacks:\n *\n * * `NaN` =\\> `null`\n *\n * * `+/-∞` =\\> `null`\n *\n * * `-0` =\\> `+0`\n *\n * For fields with a default value, the field may be omitted.\n * If `context` is not provided, defaults which require a context will be left empty which can be out of schema.\n *\n * @param allowedTypes - The set of types allowed by the parent context. Used to validate the input tree.\n * @param context - An optional context which, if present, will allow defaults to be created by {@link ContextualFieldProvider}s.\n * If absent, only defaults from {@link ConstantFieldProvider}s will be created.\n * @param schemaValidationPolicy - The stored schema and policy to be used for validation, if the policy says schema\n * validation should happen. If it does, the input tree will be validated against this schema + policy, and an error will\n * be thrown if the tree does not conform to the schema. If undefined, no validation against the stored schema is done.\n * @remarks The resulting tree will be populated with any defaults from {@link FieldProvider}s in the schema.\n */\nexport function mapTreeFromNodeData<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tallowedTypes: ImplicitFieldSchema,\n\tcontext?: NodeIdentifierManager,\n): TIn extends undefined ? undefined : ExclusiveMapTree {\n\tconst normalizedFieldSchema = normalizeFieldSchema(allowedTypes);\n\n\tif (data === undefined) {\n\t\t// TODO: this code-path should support defaults\n\t\tif (normalizedFieldSchema.kind !== FieldKind.Optional) {\n\t\t\tthrow new UsageError(\"Got undefined for non-optional field.\");\n\t\t}\n\t\treturn undefined as TIn extends undefined ? undefined : ExclusiveMapTree;\n\t}\n\n\tconst mapTree = nodeDataToMapTree(data, normalizedFieldSchema.allowedTypeSet);\n\t// Add what defaults can be provided. If no `context` is providing, some defaults may still be missing.\n\taddDefaultsToMapTree(mapTree, normalizedFieldSchema.allowedTypes, context);\n\n\treturn mapTree as TIn extends undefined ? undefined : ExclusiveMapTree;\n}\n\n/**\n * Copy content from `data` into a MapTree.\n * Does NOT generate and default values for fields.\n * Often throws UsageErrors for invalid data, but may miss some cases.\n * @remarks\n * Output is likely out of schema even for valid input due to missing defaults.\n */\nfunction nodeDataToMapTree(\n\tdata: InsertableContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): ExclusiveMapTree {\n\t// A special cache path for processing unhydrated nodes.\n\t// They already have the mapTree, so there is no need to recompute it.\n\tconst innerNode = tryGetInnerNode(data);\n\tif (innerNode !== undefined) {\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\tif (!allowedTypes.has(getSimpleNodeSchemaFromInnerNode(innerNode))) {\n\t\t\t\tthrow new UsageError(\"Invalid schema for this context.\");\n\t\t\t}\n\t\t\t// TODO: mapTreeFromNodeData modifies the trees it gets to add defaults.\n\t\t\t// Using a cached value here can result in this tree having defaults applied to it more than once.\n\t\t\t// This is unnecessary and inefficient, but should be a no-op if all calls provide the same context (which they might not).\n\t\t\t// A cleaner design (avoiding this cast) might be to apply defaults eagerly if they don't need a context, and lazily (when hydrating) if they do.\n\t\t\t// This could avoid having to mutate the map tree to apply defaults, removing the need for this cast.\n\t\t\treturn innerNode.mapTree;\n\t\t} else {\n\t\t\t// The node is already hydrated, meaning that it already got inserted into the tree previously\n\t\t\tthrow new UsageError(\"A node may not be inserted into the tree more than once\");\n\t\t}\n\t}\n\n\tassert(!isTreeNode(data), 0xa23 /* data without an inner node cannot be TreeNode */);\n\n\tconst schema = getType(data, allowedTypes);\n\n\tlet result: ExclusiveMapTree;\n\tswitch (schema.kind) {\n\t\tcase NodeKind.Leaf:\n\t\t\tresult = leafToMapTree(data, schema, allowedTypes);\n\t\t\tbreak;\n\t\tcase NodeKind.Array:\n\t\t\tresult = arrayToMapTree(data, schema);\n\t\t\tbreak;\n\t\tcase NodeKind.Map:\n\t\t\tresult = mapToMapTree(data, schema);\n\t\t\tbreak;\n\t\tcase NodeKind.Object:\n\t\t\tresult = objectToMapTree(data, schema);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tunreachableCase(schema.kind);\n\t}\n\n\treturn result;\n}\n\n/**\n * Transforms data under a Leaf schema.\n * @param data - The tree data to be transformed. Must be a {@link TreeValue}.\n * @param schema - The schema associated with the value.\n * @param allowedTypes - The allowed types specified by the parent.\n * Used to determine which fallback values may be appropriate.\n */\nfunction leafToMapTree(\n\tdata: FactoryContent,\n\tschema: TreeNodeSchema,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): ExclusiveMapTree {\n\tassert(schema.kind === NodeKind.Leaf, 0x921 /* Expected a leaf schema. */);\n\tif (!isTreeValue(data)) {\n\t\t// This rule exists to protect against useless `toString` output like `[object Object]`.\n\t\t// In this case, that's actually reasonable behavior, since object input is not compatible with Leaf schemas.\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tthrow new UsageError(`Input data is incompatible with leaf schema: ${data}`);\n\t}\n\n\tconst mappedValue = mapValueWithFallbacks(data, allowedTypes);\n\tconst mappedSchema = getType(mappedValue, allowedTypes);\n\n\tassert(\n\t\tallowsValue(mappedSchema, mappedValue),\n\t\t0x84a /* Unsupported schema for provided primitive. */,\n\t);\n\n\treturn {\n\t\tvalue: mappedValue,\n\t\ttype: brand(mappedSchema.identifier),\n\t\tfields: new Map(),\n\t};\n}\n\n/**\n * Checks an incoming {@link TreeLeafValue} to ensure it is compatible with its requirements.\n * For unsupported values with a schema-compatible replacement, return the replacement value.\n * For unsupported values without a schema-compatible replacement, throw.\n * For supported values, return the input.\n */\nfunction mapValueWithFallbacks(\n\tvalue: TreeLeafValue,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): TreeValue {\n\tswitch (typeof value) {\n\t\tcase \"number\": {\n\t\t\tif (Object.is(value, -0)) {\n\t\t\t\t// Our serialized data format does not support -0.\n\t\t\t\t// Map such input to +0.\n\t\t\t\treturn 0;\n\t\t\t} else if (!Number.isFinite(value)) {\n\t\t\t\t// Our serialized data format does not support NaN nor +/-∞.\n\t\t\t\t// If the schema supports `null`, fall back to that. Otherwise, throw.\n\t\t\t\t// This is intended to match JSON's behavior for such values.\n\t\t\t\tif (allowedTypes.has(nullSchema)) {\n\t\t\t\t\treturn null;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(`Received unsupported numeric value: ${value}.`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t\tcase \"string\":\n\t\t// TODO:\n\t\t// This should detect invalid strings. Something like @stdlib/regexp-utf16-unpaired-surrogate could be used to do this.\n\t\t// See SchemaFactory.string for details.\n\t\tcase \"boolean\":\n\t\t\treturn value;\n\t\tcase \"object\": {\n\t\t\tif (value === null || isFluidHandle(value)) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tthrow new UsageError(`Received unsupported leaf value: ${value}.`);\n\t}\n}\n\n/**\n * Transforms data under an Array schema.\n * @param data - The tree data to be transformed.\n * @param allowedTypes - The set of types allowed by the parent context. Used to validate the input tree.\n */\nfunction arrayChildToMapTree(\n\tchild: InsertableContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): ExclusiveMapTree {\n\t// We do not support undefined sequence entries.\n\t// If we encounter an undefined entry, use null instead if supported by the schema, otherwise throw.\n\tlet childWithFallback = child;\n\tif (child === undefined) {\n\t\tif (allowedTypes.has(nullSchema)) {\n\t\t\tchildWithFallback = null;\n\t\t} else {\n\t\t\tthrow new TypeError(`Received unsupported array entry value: ${child}.`);\n\t\t}\n\t}\n\treturn nodeDataToMapTree(childWithFallback, allowedTypes);\n}\n\n/**\n * Transforms data under an Array schema.\n * @param data - The tree data to be transformed. Must be an iterable.\n * @param schema - The schema associated with the value.\n * @param schemaValidationPolicy - The stored schema and policy to be used for validation, if the policy says schema\n * validation should happen. If it does, the input tree will be validated against this schema + policy, and an error will\n * be thrown if the tree does not conform to the schema. If undefined, no validation against the stored schema is done.\n */\nfunction arrayToMapTree(data: FactoryContent, schema: TreeNodeSchema): ExclusiveMapTree {\n\tassert(schema.kind === NodeKind.Array, 0x922 /* Expected an array schema. */);\n\tif (!(typeof data === \"object\" && data !== null && Symbol.iterator in data)) {\n\t\tthrow new UsageError(`Input data is incompatible with Array schema: ${data}`);\n\t}\n\n\tconst allowedChildTypes = normalizeAllowedTypes(schema.info as ImplicitAllowedTypes);\n\n\tconst mappedData = Array.from(data, (child) =>\n\t\tarrayChildToMapTree(child, allowedChildTypes),\n\t);\n\n\t// Array nodes have a single `EmptyKey` field:\n\tconst fieldsEntries = mappedData.length === 0 ? [] : ([[EmptyKey, mappedData]] as const);\n\n\treturn {\n\t\ttype: brand(schema.identifier),\n\t\tfields: new Map(fieldsEntries),\n\t};\n}\n\n/**\n * Transforms data under a Map schema.\n * @param data - The tree data to be transformed. Must be an iterable.\n * @param schema - The schema associated with the value.\n * @param schemaValidationPolicy - The stored schema and policy to be used for validation, if the policy says schema\n * validation should happen. If it does, the input tree will be validated against this schema + policy, and an error will\n * be thrown if the tree does not conform to the schema. If undefined, no validation against the stored schema is done.\n */\nfunction mapToMapTree(data: FactoryContent, schema: TreeNodeSchema): ExclusiveMapTree {\n\tassert(schema.kind === NodeKind.Map, 0x923 /* Expected a Map schema. */);\n\tif (!(typeof data === \"object\" && data !== null)) {\n\t\tthrow new UsageError(`Input data is incompatible with Map schema: ${data}`);\n\t}\n\n\tconst allowedChildTypes = normalizeAllowedTypes(schema.info as ImplicitAllowedTypes);\n\n\tconst fieldsIterator = (\n\t\tSymbol.iterator in data\n\t\t\t? // Support iterables of key value pairs (including Map objects)\n\t\t\t\tdata\n\t\t\t: // Support record objects for JSON style Map data\n\t\t\t\tObject.entries(data)\n\t) as Iterable<readonly [string, InsertableContent]>;\n\n\tconst transformedFields = new Map<FieldKey, ExclusiveMapTree[]>();\n\tfor (const item of fieldsIterator) {\n\t\tif (!isReadonlyArray(item) || item.length !== 2 || typeof item[0] !== \"string\") {\n\t\t\tthrow new UsageError(`Input data is incompatible with map entry: ${item}`);\n\t\t}\n\t\tconst [key, value] = item;\n\t\tassert(!transformedFields.has(brand(key)), 0x84c /* Keys should not be duplicated */);\n\n\t\t// Omit undefined values - an entry with an undefined value is equivalent to one that has been removed or omitted\n\t\tif (value !== undefined) {\n\t\t\tconst mappedField = nodeDataToMapTree(value, allowedChildTypes);\n\t\t\ttransformedFields.set(brand(key), [mappedField]);\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: brand(schema.identifier),\n\t\tfields: transformedFields,\n\t};\n}\n\n/**\n * Transforms data under an Object schema.\n * @param data - The tree data to be transformed. Must be a Record-like object.\n * @param schema - The schema associated with the value.\n */\nfunction objectToMapTree(data: FactoryContent, schema: TreeNodeSchema): ExclusiveMapTree {\n\tassert(isObjectNodeSchema(schema), 0x924 /* Expected an Object schema. */);\n\tif (\n\t\ttypeof data !== \"object\" ||\n\t\tdata === null ||\n\t\tSymbol.iterator in data ||\n\t\tisFluidHandle(data)\n\t) {\n\t\tthrow new UsageError(`Input data is incompatible with Object schema: ${data}`);\n\t}\n\n\tconst fields = new Map<FieldKey, ExclusiveMapTree[]>();\n\n\t// Loop through field keys without data.\n\t// This does NOT apply defaults.\n\tfor (const [key, fieldInfo] of schema.flexKeyMap) {\n\t\tif (checkFieldProperty(data, key)) {\n\t\t\tconst value = (data as Record<string, InsertableContent>)[key as string];\n\t\t\tsetFieldValue(fields, value, fieldInfo.schema, fieldInfo.storedKey);\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: brand(schema.identifier),\n\t\tfields,\n\t};\n}\n\n/**\n * Check {@link FactoryContentObject} for a property which could be store a field.\n * @remarks\n * The currently policy is to only consider own properties.\n * See {@link InsertableObjectFromSchemaRecord} for where this policy is documented in the public API.\n *\n * Explicit undefined members are considered to exist, as long as they are own properties.\n */\nfunction checkFieldProperty(\n\tdata: FactoryContentObject,\n\tkey: string | symbol,\n): data is {\n\treadonly [P in string]: InsertableContent | undefined;\n} {\n\t// This policy only allows own properties.\n\treturn Object.hasOwnProperty.call(data, key);\n}\n\nfunction setFieldValue(\n\tfields: Map<FieldKey, readonly MapTree[]>,\n\tfieldValue: InsertableContent | undefined,\n\tfieldSchema: FieldSchema,\n\tflexKey: FieldKey,\n): void {\n\tif (fieldValue !== undefined) {\n\t\tconst mappedChildTree = nodeDataToMapTree(fieldValue, fieldSchema.allowedTypeSet);\n\n\t\tassert(!fields.has(flexKey), 0x956 /* Keys must not be duplicated */);\n\t\tfields.set(flexKey, [mappedChildTree]);\n\t}\n}\n\nfunction getType(\n\tdata: FactoryContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): TreeNodeSchema {\n\tconst possibleTypes = getPossibleTypes(allowedTypes, data);\n\tif (possibleTypes.length === 0) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is incompatible with all of the types allowed by the schema. The set of allowed types is: ${JSON.stringify(\n\t\t\t\t[...allowedTypes].map((schema) => schema.identifier),\n\t\t\t)}.`,\n\t\t);\n\t}\n\tassert(\n\t\thasSome(possibleTypes),\n\t\t0x84e /* data is incompatible with all types allowed by the schema */,\n\t);\n\tif (!hasSingle(possibleTypes)) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is compatible with more than one type allowed by the schema.\nThe set of possible types is ${JSON.stringify([\n\t\t\t\t...possibleTypes.map((schema) => schema.identifier),\n\t\t\t])}.\nExplicitly construct an unhydrated node of the desired type to disambiguate.\nFor class-based schema, this can be done by replacing an expression like \"{foo: 1}\" with \"new MySchema({foo: 1})\".`,\n\t\t);\n\t}\n\treturn possibleTypes[0];\n}\n\n/**\n * Returns all types for which the data is schema-compatible.\n */\nexport function getPossibleTypes(\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\tdata: FactoryContent,\n): TreeNodeSchema[] {\n\tlet best = CompatibilityLevel.None;\n\tconst possibleTypes: TreeNodeSchema[] = [];\n\tfor (const schema of allowedTypes) {\n\t\tconst level = shallowCompatibilityTest(schema, data);\n\t\tif (level > best) {\n\t\t\tpossibleTypes.length = 0;\n\t\t\tbest = level;\n\t\t}\n\t\tif (best === level) {\n\t\t\tpossibleTypes.push(schema);\n\t\t}\n\t}\n\treturn best === CompatibilityLevel.None ? [] : possibleTypes;\n}\n\n/**\n * Indicates a compatibility level for inferring a schema to apply to insertable data.\n * @remarks\n * Only the highest compatibility options are used.\n * This approach allows adding new possible matching at a new lower compatibility level as a non breaking change,\n * since that way they can't make a case that was compatible before ambiguous now.\n */\nenum CompatibilityLevel {\n\t/**\n\t * Not compatible. Constructor typing indicates incompatibility.\n\t */\n\tNone = 0,\n\t/**\n\t * Additional compatibility cases added in Fluid Framework 2.2.\n\t */\n\tLow = 1,\n\t/**\n\t * Compatible in Fluid Framework 2.0.\n\t */\n\tNormal = 2,\n}\n\n/**\n * Checks if data might be schema-compatible.\n *\n * @returns false if `data` is incompatible with `type` based on a cheap/shallow check.\n *\n * Note that this may return true for cases where data is incompatible, but it must not return false in cases where the data is compatible.\n */\nfunction shallowCompatibilityTest(\n\tschema: TreeNodeSchema,\n\tdata: FactoryContent,\n): CompatibilityLevel {\n\tassert(data !== undefined, 0x889 /* undefined cannot be used as FactoryContent. */);\n\n\tif (isTreeValue(data)) {\n\t\treturn allowsValue(schema, data) ? CompatibilityLevel.Normal : CompatibilityLevel.None;\n\t}\n\tif (schema.kind === NodeKind.Leaf) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\t// Typing (of schema based constructors and thus implicit node construction)\n\t// allows iterables for constructing maps and arrays.\n\t// Some users of this API may have unions of maps and arrays,\n\t// and rely on Arrays ending up as array nodes and maps as Map nodes,\n\t// despite both being iterable and thus compatible with both.\n\t// This uses a priority based system where an array would be parsed as an array when unioned with a map,\n\t// but if in a map only context, could still be used as a map.\n\n\tif (data instanceof Map) {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Map:\n\t\t\t\treturn CompatibilityLevel.Normal;\n\t\t\tcase NodeKind.Array:\n\t\t\t\t// Maps are iterable, so type checking does allow constructing an ArrayNode from a map if the array's type is an array that includes the key and value types of the map.\n\t\t\t\treturn CompatibilityLevel.Low;\n\t\t\tdefault:\n\t\t\t\treturn CompatibilityLevel.None;\n\t\t}\n\t}\n\n\tif (isReadonlyArray(data)) {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Array:\n\t\t\t\treturn CompatibilityLevel.Normal;\n\t\t\tcase NodeKind.Map:\n\t\t\t\t// Arrays are iterable, so type checking does allow constructing an array from a MapNode from an if the array's type is key values pairs for the map.\n\t\t\t\treturn CompatibilityLevel.Low;\n\t\t\tdefault:\n\t\t\t\treturn CompatibilityLevel.None;\n\t\t}\n\t}\n\n\tconst mapOrArray = schema.kind === NodeKind.Array || schema.kind === NodeKind.Map;\n\n\tif (Symbol.iterator in data) {\n\t\treturn mapOrArray ? CompatibilityLevel.Normal : CompatibilityLevel.None;\n\t}\n\n\t// At this point, it is assumed data is a record-like object since all the other cases have been eliminated.\n\n\tif (schema.kind === NodeKind.Array) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\tif (schema.kind === NodeKind.Map) {\n\t\t// When not unioned with an ObjectNode, allow objects to be used to create maps.\n\t\treturn CompatibilityLevel.Low;\n\t}\n\n\tassert(isObjectNodeSchema(schema), 0x9e6 /* unexpected schema kind */);\n\n\t// TODO: Improve type inference by making this logic more thorough. Handle at least:\n\t// * Types which are strict subsets of other types in the same polymorphic union\n\t// * Types which have the same keys but different types for those keys in the polymorphic union\n\t// * Types which have the same required fields but different optional fields and enough of those optional fields are populated to disambiguate\n\n\t// TODO#7441: Consider allowing data to be inserted which has keys that are extraneous/unknown to the schema (those keys are ignored)\n\n\t// If the schema has a required key which is not present in the input object, reject it.\n\tfor (const [fieldKey, fieldSchema] of schema.fields) {\n\t\tif (fieldSchema.requiresValue) {\n\t\t\tif (checkFieldProperty(data, fieldKey)) {\n\t\t\t\tif (data[fieldKey] === undefined) {\n\t\t\t\t\treturn CompatibilityLevel.None;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn CompatibilityLevel.None;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn CompatibilityLevel.Normal;\n}\n\nfunction allowsValue(schema: TreeNodeSchema, value: TreeValue): boolean {\n\tif (schema.kind === NodeKind.Leaf) {\n\t\treturn valueSchemaAllows(schema.info as ValueSchema, value);\n\t}\n\treturn false;\n}\n\n/**\n * Walk the given {@link ExclusiveMapTree} and deeply provide any field defaults for fields that are missing in the tree but present in the schema.\n * @param mapTree - The tree to populate with defaults. This is borrowed: no references to it are kept by this function.\n * @param allowedTypes - Some {@link TreeNodeSchema}, at least one of which the input tree must conform to\n * @param context - An optional context for generating defaults.\n * If present, all applicable defaults will be provided.\n * If absent, only defaults produced by a {@link ConstantFieldProvider} will be provided, and defaults produced by a {@link ContextualFieldProvider} will be ignored.\n * @remarks This function mutates the input tree by deeply adding new fields to the field maps where applicable.\n */\nexport function addDefaultsToMapTree(\n\tmapTree: ExclusiveMapTree,\n\tallowedTypes: ImplicitAllowedTypes,\n\tcontext: NodeIdentifierManager | undefined,\n): void {\n\tconst schema =\n\t\tfind(normalizeAllowedTypes(allowedTypes), (s) => s.identifier === mapTree.type) ??\n\t\tfail(0xae1 /* MapTree is incompatible with schema */);\n\n\tif (isObjectNodeSchema(schema)) {\n\t\tfor (const [_key, fieldInfo] of schema.flexKeyMap) {\n\t\t\tconst field = mapTree.fields.get(fieldInfo.storedKey);\n\t\t\tif (field !== undefined) {\n\t\t\t\tfor (const child of field) {\n\t\t\t\t\taddDefaultsToMapTree(child, fieldInfo.schema.allowedTypes, context);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst defaultProvider = fieldInfo.schema.props?.defaultProvider;\n\t\t\t\tif (defaultProvider !== undefined) {\n\t\t\t\t\tconst fieldProvider = extractFieldProvider(defaultProvider);\n\t\t\t\t\tconst data = provideDefault(fieldProvider, context);\n\t\t\t\t\tif (data !== undefined) {\n\t\t\t\t\t\tsetFieldValue(mapTree.fields, data, fieldInfo.schema, fieldInfo.storedKey);\n\t\t\t\t\t\t// call addDefaultsToMapTree on newly inserted default values\n\t\t\t\t\t\tfor (const child of mapTree.fields.get(fieldInfo.storedKey) ??\n\t\t\t\t\t\t\tfail(0xae2 /* Expected field to be populated */)) {\n\t\t\t\t\t\t\taddDefaultsToMapTree(child, fieldInfo.schema.allowedTypes, context);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tswitch (schema.kind) {\n\t\tcase NodeKind.Array:\n\t\tcase NodeKind.Map:\n\t\t\t{\n\t\t\t\tfor (const field of mapTree.fields.values()) {\n\t\t\t\t\tfor (const child of field) {\n\t\t\t\t\t\taddDefaultsToMapTree(child, schema.info as ImplicitAllowedTypes, context);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tassert(schema.kind === NodeKind.Leaf, 0x989 /* Unrecognized schema kind */);\n\t\t\tbreak;\n\t}\n}\n\n/**\n * Provides the default value (which can be undefined, for example with optional fields), or undefined if a context is required but not provided.\n * @privateRemarks\n * It is a bit concerning that there is no way for the caller to know when undefined is returned if that is the default value, or a context was required.\n * TODO: maybe better formalize the two stage defaulting (without then with context), or rework this design we only do one stage.\n */\nfunction provideDefault(\n\tfieldProvider: FieldProvider,\n\tcontext: NodeIdentifierManager | undefined,\n): InsertableContent | undefined {\n\tif (context !== undefined) {\n\t\treturn fieldProvider(context);\n\t} else {\n\t\tif (isConstant(fieldProvider)) {\n\t\t\treturn fieldProvider();\n\t\t} else {\n\t\t\t// Leaving field empty despite it needing a default value since a context was required and none was provided.\n\t\t\t// Caller better handle this case by providing the default at some other point in time when the context becomes known.\n\t\t}\n\t}\n}\n\n/**\n * Retrieves the InnerNode associated with the given target via {@link setInnerNode}, if any.\n * @remarks\n * If `target` is a unhydrated node, returns its MapTreeNode.\n * If `target` is a cooked node (or marinated but a FlexTreeNode exists) returns the FlexTreeNode.\n * If the target is not a node, or a marinated node with no FlexTreeNode for its anchor, returns undefined.\n */\nfunction tryGetInnerNode(target: unknown): InnerNode | undefined {\n\tif (isTreeNode(target)) {\n\t\treturn getKernel(target).tryGetInnerNode();\n\t}\n}\n\n/**\n * Content which can be used to build a node.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n * @system @alpha\n */\nexport type FactoryContent =\n\t| IFluidHandle\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| Iterable<readonly [string, InsertableContent]>\n\t| readonly InsertableContent[]\n\t| FactoryContentObject;\n\n/**\n * Record-like object which can be used to build some kinds of nodes.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n *\n * Supports object and map nodes.\n * @system @alpha\n */\nexport type FactoryContentObject = {\n\treadonly [P in string]?: InsertableContent;\n};\n\n/**\n * Content which can be inserted into a tree.\n * @system @alpha\n */\nexport type InsertableContent = Unhydrated<TreeNode> | FactoryContent;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"toMapTree.d.ts","sourceRoot":"","sources":["../../src/simple-tree/toMapTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,OAAO,EAMN,KAAK,gBAAgB,EACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAGN,KAAK,qBAAqB,EAC1B,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAEN,KAAK,oBAAoB,EAKzB,KAAK,mBAAmB,EAIxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAMN,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,UAAU,EAEf,MAAM,iBAAiB,CAAC;AAOzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE;;;;;;;;;GASG;AAEH;;;;;;;;;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M,CAAC;QACP,IAAI,UAAU,CAAC,aAAa,CAAC,EAAE,CAAC;YAC/B,OAAO,aAAa,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACP,6GAA6G;YAC7G,sHAAsH;QACvH,CAAC;IACF,CAAC;AACF,CAAC;AAED;;;;;;GAMG;AACH,SAAS,eAAe,CAAC,MAAe;IACvC,IAAI,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC;QACxB,OAAO,SAAS,CAAC,MAAM,CAAC,CAAC,eAAe,EAAE,CAAC;IAC5C,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\n\nimport {\n\tEmptyKey,\n\ttype FieldKey,\n\ttype MapTree,\n\ttype TreeValue,\n\ttype ValueSchema,\n\ttype ExclusiveMapTree,\n} from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tvalueSchemaAllows,\n\ttype NodeIdentifierManager,\n} from \"../feature-libraries/index.js\";\nimport { brand, isReadonlyArray, find, hasSome, hasSingle } from \"../util/index.js\";\n\nimport { nullSchema } from \"./leafNodeSchema.js\";\nimport {\n\ttype FieldSchema,\n\ttype ImplicitAllowedTypes,\n\tnormalizeAllowedTypes,\n\textractFieldProvider,\n\tisConstant,\n\ttype FieldProvider,\n\ttype ImplicitFieldSchema,\n\tnormalizeFieldSchema,\n\tFieldKind,\n\ttype TreeLeafValue,\n} from \"./schemaTypes.js\";\nimport {\n\tgetKernel,\n\tgetSimpleNodeSchemaFromInnerNode,\n\tisTreeNode,\n\tNodeKind,\n\ttype InnerNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\ttype Unhydrated,\n\tUnhydratedFlexTreeNode,\n} from \"./core/index.js\";\n// Required to prevent the introduction of new circular dependencies\n// TODO: Having the schema provide their own policy functions for compatibility which\n// toMapTree invokes instead of manually handling each kind would remove this bad\n// dependency, and reduce coupling.\n// eslint-disable-next-line import/no-internal-modules\nimport { isObjectNodeSchema } from \"./node-kinds/object/objectNodeTypes.js\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\n\n/**\n * Module notes:\n *\n * The flow of the below code is in terms of the structure of the input data. We then verify that the associated\n * schema is appropriate for that kind of data. This is fine while we have a 1:1 mapping of kind of input data to\n * the kind of schema we expect for it (e.g. an input that is an array always need to be associated with a sequence in\n * the schema). If/when we begin accepting kinds of input data that are ambiguous (e.g. accepting an input that is an\n * array of key/value tuples to instantiate a map) we may need to rethink the structure here to be based more on the\n * schema than on the input data.\n */\n\n/**\n * Transforms an input {@link TypedNode} tree to a {@link MapTree}.\n * @param data - The input tree to be converted.\n * If the data is an unsupported value (e.g. NaN), a fallback value will be used when supported,\n * otherwise an error will be thrown.\n *\n * Fallbacks:\n *\n * * `NaN` =\\> `null`\n *\n * * `+/-∞` =\\> `null`\n *\n * * `-0` =\\> `+0`\n *\n * For fields with a default value, the field may be omitted.\n * If `context` is not provided, defaults which require a context will be left empty which can be out of schema.\n *\n * @param allowedTypes - The set of types allowed by the parent context. Used to validate the input tree.\n * @param context - An optional context which, if present, will allow defaults to be created by {@link ContextualFieldProvider}s.\n * If absent, only defaults from {@link ConstantFieldProvider}s will be created.\n * @param schemaValidationPolicy - The stored schema and policy to be used for validation, if the policy says schema\n * validation should happen. If it does, the input tree will be validated against this schema + policy, and an error will\n * be thrown if the tree does not conform to the schema. If undefined, no validation against the stored schema is done.\n * @remarks The resulting tree will be populated with any defaults from {@link FieldProvider}s in the schema.\n */\nexport function mapTreeFromNodeData<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tallowedTypes: ImplicitFieldSchema,\n\tcontext?: NodeIdentifierManager,\n): TIn extends undefined ? undefined : ExclusiveMapTree {\n\tconst normalizedFieldSchema = normalizeFieldSchema(allowedTypes);\n\n\tif (data === undefined) {\n\t\t// TODO: this code-path should support defaults\n\t\tif (normalizedFieldSchema.kind !== FieldKind.Optional) {\n\t\t\tthrow new UsageError(\"Got undefined for non-optional field.\");\n\t\t}\n\t\treturn undefined as TIn extends undefined ? undefined : ExclusiveMapTree;\n\t}\n\n\tconst mapTree = nodeDataToMapTree(data, normalizedFieldSchema.allowedTypeSet);\n\t// Add what defaults can be provided. If no `context` is providing, some defaults may still be missing.\n\taddDefaultsToMapTree(mapTree, normalizedFieldSchema.allowedTypes, context);\n\n\treturn mapTree as TIn extends undefined ? undefined : ExclusiveMapTree;\n}\n\n/**\n * Copy content from `data` into a MapTree.\n * Does NOT generate and default values for fields.\n * Often throws UsageErrors for invalid data, but may miss some cases.\n * @remarks\n * Output is likely out of schema even for valid input due to missing defaults.\n */\nfunction nodeDataToMapTree(\n\tdata: InsertableContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): ExclusiveMapTree {\n\t// A special cache path for processing unhydrated nodes.\n\t// They already have the mapTree, so there is no need to recompute it.\n\tconst innerNode = tryGetInnerNode(data);\n\tif (innerNode !== undefined) {\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\tif (!allowedTypes.has(getSimpleNodeSchemaFromInnerNode(innerNode))) {\n\t\t\t\tthrow new UsageError(\"Invalid schema for this context.\");\n\t\t\t}\n\t\t\t// TODO: mapTreeFromNodeData modifies the trees it gets to add defaults.\n\t\t\t// Using a cached value here can result in this tree having defaults applied to it more than once.\n\t\t\t// This is unnecessary and inefficient, but should be a no-op if all calls provide the same context (which they might not).\n\t\t\t// A cleaner design (avoiding this cast) might be to apply defaults eagerly if they don't need a context, and lazily (when hydrating) if they do.\n\t\t\t// This could avoid having to mutate the map tree to apply defaults, removing the need for this cast.\n\t\t\treturn innerNode.mapTree;\n\t\t} else {\n\t\t\t// The node is already hydrated, meaning that it already got inserted into the tree previously\n\t\t\tthrow new UsageError(\"A node may not be inserted into the tree more than once\");\n\t\t}\n\t}\n\n\tassert(!isTreeNode(data), 0xa23 /* data without an inner node cannot be TreeNode */);\n\n\tconst schema = getType(data, allowedTypes);\n\n\tlet result: ExclusiveMapTree;\n\tswitch (schema.kind) {\n\t\tcase NodeKind.Leaf:\n\t\t\tresult = leafToMapTree(data, schema, allowedTypes);\n\t\t\tbreak;\n\t\tcase NodeKind.Array:\n\t\t\tresult = arrayToMapTree(data, schema);\n\t\t\tbreak;\n\t\tcase NodeKind.Map:\n\t\t\tresult = mapToMapTree(data, schema);\n\t\t\tbreak;\n\t\tcase NodeKind.Object:\n\t\t\tresult = objectToMapTree(data, schema);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tunreachableCase(schema.kind);\n\t}\n\n\treturn result;\n}\n\n/**\n * Transforms data under a Leaf schema.\n * @param data - The tree data to be transformed. Must be a {@link TreeValue}.\n * @param schema - The schema associated with the value.\n * @param allowedTypes - The allowed types specified by the parent.\n * Used to determine which fallback values may be appropriate.\n */\nfunction leafToMapTree(\n\tdata: FactoryContent,\n\tschema: TreeNodeSchema,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): ExclusiveMapTree {\n\tassert(schema.kind === NodeKind.Leaf, 0x921 /* Expected a leaf schema. */);\n\tif (!isTreeValue(data)) {\n\t\t// This rule exists to protect against useless `toString` output like `[object Object]`.\n\t\t// In this case, that's actually reasonable behavior, since object input is not compatible with Leaf schemas.\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tthrow new UsageError(`Input data is incompatible with leaf schema: ${data}`);\n\t}\n\n\tconst mappedValue = mapValueWithFallbacks(data, allowedTypes);\n\tconst mappedSchema = getType(mappedValue, allowedTypes);\n\n\tassert(\n\t\tallowsValue(mappedSchema, mappedValue),\n\t\t0x84a /* Unsupported schema for provided primitive. */,\n\t);\n\n\treturn {\n\t\tvalue: mappedValue,\n\t\ttype: brand(mappedSchema.identifier),\n\t\tfields: new Map(),\n\t};\n}\n\n/**\n * Checks an incoming {@link TreeLeafValue} to ensure it is compatible with its requirements.\n * For unsupported values with a schema-compatible replacement, return the replacement value.\n * For unsupported values without a schema-compatible replacement, throw.\n * For supported values, return the input.\n */\nfunction mapValueWithFallbacks(\n\tvalue: TreeLeafValue,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): TreeValue {\n\tswitch (typeof value) {\n\t\tcase \"number\": {\n\t\t\tif (Object.is(value, -0)) {\n\t\t\t\t// Our serialized data format does not support -0.\n\t\t\t\t// Map such input to +0.\n\t\t\t\treturn 0;\n\t\t\t} else if (!Number.isFinite(value)) {\n\t\t\t\t// Our serialized data format does not support NaN nor +/-∞.\n\t\t\t\t// If the schema supports `null`, fall back to that. Otherwise, throw.\n\t\t\t\t// This is intended to match JSON's behavior for such values.\n\t\t\t\tif (allowedTypes.has(nullSchema)) {\n\t\t\t\t\treturn null;\n\t\t\t\t} else {\n\t\t\t\t\tthrow new UsageError(`Received unsupported numeric value: ${value}.`);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t\tcase \"string\":\n\t\t// TODO:\n\t\t// This should detect invalid strings. Something like @stdlib/regexp-utf16-unpaired-surrogate could be used to do this.\n\t\t// See SchemaFactory.string for details.\n\t\tcase \"boolean\":\n\t\t\treturn value;\n\t\tcase \"object\": {\n\t\t\tif (value === null || isFluidHandle(value)) {\n\t\t\t\treturn value;\n\t\t\t}\n\t\t}\n\t\tdefault:\n\t\t\tthrow new UsageError(`Received unsupported leaf value: ${value}.`);\n\t}\n}\n\n/**\n * Transforms data under an Array schema.\n * @param data - The tree data to be transformed.\n * @param allowedTypes - The set of types allowed by the parent context. Used to validate the input tree.\n */\nfunction arrayChildToMapTree(\n\tchild: InsertableContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): ExclusiveMapTree {\n\t// We do not support undefined sequence entries.\n\t// If we encounter an undefined entry, use null instead if supported by the schema, otherwise throw.\n\tlet childWithFallback = child;\n\tif (child === undefined) {\n\t\tif (allowedTypes.has(nullSchema)) {\n\t\t\tchildWithFallback = null;\n\t\t} else {\n\t\t\tthrow new TypeError(`Received unsupported array entry value: ${child}.`);\n\t\t}\n\t}\n\treturn nodeDataToMapTree(childWithFallback, allowedTypes);\n}\n\n/**\n * Transforms data under an Array schema.\n * @param data - The tree data to be transformed. Must be an iterable.\n * @param schema - The schema associated with the value.\n * @param schemaValidationPolicy - The stored schema and policy to be used for validation, if the policy says schema\n * validation should happen. If it does, the input tree will be validated against this schema + policy, and an error will\n * be thrown if the tree does not conform to the schema. If undefined, no validation against the stored schema is done.\n */\nfunction arrayToMapTree(data: FactoryContent, schema: TreeNodeSchema): ExclusiveMapTree {\n\tassert(schema.kind === NodeKind.Array, 0x922 /* Expected an array schema. */);\n\tif (!(typeof data === \"object\" && data !== null && Symbol.iterator in data)) {\n\t\tthrow new UsageError(`Input data is incompatible with Array schema: ${data}`);\n\t}\n\n\tconst allowedChildTypes = normalizeAllowedTypes(schema.info as ImplicitAllowedTypes);\n\n\tconst mappedData = Array.from(data, (child) =>\n\t\tarrayChildToMapTree(child, allowedChildTypes),\n\t);\n\n\t// Array nodes have a single `EmptyKey` field:\n\tconst fieldsEntries = mappedData.length === 0 ? [] : ([[EmptyKey, mappedData]] as const);\n\n\treturn {\n\t\ttype: brand(schema.identifier),\n\t\tfields: new Map(fieldsEntries),\n\t};\n}\n\n/**\n * Transforms data under a Map schema.\n * @param data - The tree data to be transformed. Must be an iterable.\n * @param schema - The schema associated with the value.\n * @param schemaValidationPolicy - The stored schema and policy to be used for validation, if the policy says schema\n * validation should happen. If it does, the input tree will be validated against this schema + policy, and an error will\n * be thrown if the tree does not conform to the schema. If undefined, no validation against the stored schema is done.\n */\nfunction mapToMapTree(data: FactoryContent, schema: TreeNodeSchema): ExclusiveMapTree {\n\tassert(schema.kind === NodeKind.Map, 0x923 /* Expected a Map schema. */);\n\tif (!(typeof data === \"object\" && data !== null)) {\n\t\tthrow new UsageError(`Input data is incompatible with Map schema: ${data}`);\n\t}\n\n\tconst allowedChildTypes = normalizeAllowedTypes(schema.info as ImplicitAllowedTypes);\n\n\tconst fieldsIterator = (\n\t\tSymbol.iterator in data\n\t\t\t? // Support iterables of key value pairs (including Map objects)\n\t\t\t\tdata\n\t\t\t: // Support record objects for JSON style Map data\n\t\t\t\tObject.entries(data)\n\t) as Iterable<readonly [string, InsertableContent]>;\n\n\tconst transformedFields = new Map<FieldKey, ExclusiveMapTree[]>();\n\tfor (const item of fieldsIterator) {\n\t\tif (!isReadonlyArray(item) || item.length !== 2 || typeof item[0] !== \"string\") {\n\t\t\tthrow new UsageError(`Input data is incompatible with map entry: ${item}`);\n\t\t}\n\t\tconst [key, value] = item;\n\t\tassert(!transformedFields.has(brand(key)), 0x84c /* Keys should not be duplicated */);\n\n\t\t// Omit undefined values - an entry with an undefined value is equivalent to one that has been removed or omitted\n\t\tif (value !== undefined) {\n\t\t\tconst mappedField = nodeDataToMapTree(value, allowedChildTypes);\n\t\t\ttransformedFields.set(brand(key), [mappedField]);\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: brand(schema.identifier),\n\t\tfields: transformedFields,\n\t};\n}\n\n/**\n * Transforms data under an Object schema.\n * @param data - The tree data to be transformed. Must be a Record-like object.\n * @param schema - The schema associated with the value.\n */\nfunction objectToMapTree(data: FactoryContent, schema: TreeNodeSchema): ExclusiveMapTree {\n\tassert(isObjectNodeSchema(schema), 0x924 /* Expected an Object schema. */);\n\tif (\n\t\ttypeof data !== \"object\" ||\n\t\tdata === null ||\n\t\tSymbol.iterator in data ||\n\t\tisFluidHandle(data)\n\t) {\n\t\tthrow new UsageError(`Input data is incompatible with Object schema: ${data}`);\n\t}\n\n\tconst fields = new Map<FieldKey, ExclusiveMapTree[]>();\n\n\t// Loop through field keys without data.\n\t// This does NOT apply defaults.\n\tfor (const [key, fieldInfo] of schema.flexKeyMap) {\n\t\tif (checkFieldProperty(data, key)) {\n\t\t\tconst value = (data as Record<string, InsertableContent>)[key as string];\n\t\t\tsetFieldValue(fields, value, fieldInfo.schema, fieldInfo.storedKey);\n\t\t}\n\t}\n\n\treturn {\n\t\ttype: brand(schema.identifier),\n\t\tfields,\n\t};\n}\n\n/**\n * Check {@link FactoryContentObject} for a property which could be store a field.\n * @remarks\n * The currently policy is to only consider own properties.\n * See {@link InsertableObjectFromSchemaRecord} for where this policy is documented in the public API.\n *\n * Explicit undefined members are considered to exist, as long as they are own properties.\n */\nfunction checkFieldProperty(\n\tdata: FactoryContentObject,\n\tkey: string | symbol,\n): data is {\n\treadonly [P in string]: InsertableContent | undefined;\n} {\n\t// This policy only allows own properties.\n\treturn Object.hasOwnProperty.call(data, key);\n}\n\nfunction setFieldValue(\n\tfields: Map<FieldKey, readonly MapTree[]>,\n\tfieldValue: InsertableContent | undefined,\n\tfieldSchema: FieldSchema,\n\tflexKey: FieldKey,\n): void {\n\tif (fieldValue !== undefined) {\n\t\tconst mappedChildTree = nodeDataToMapTree(fieldValue, fieldSchema.allowedTypeSet);\n\n\t\tassert(!fields.has(flexKey), 0x956 /* Keys must not be duplicated */);\n\t\tfields.set(flexKey, [mappedChildTree]);\n\t}\n}\n\nfunction getType(\n\tdata: FactoryContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): TreeNodeSchema {\n\tconst possibleTypes = getPossibleTypes(allowedTypes, data);\n\tif (possibleTypes.length === 0) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is incompatible with all of the types allowed by the schema. The set of allowed types is: ${JSON.stringify(\n\t\t\t\t[...allowedTypes].map((schema) => schema.identifier),\n\t\t\t)}.`,\n\t\t);\n\t}\n\tassert(\n\t\thasSome(possibleTypes),\n\t\t0x84e /* data is incompatible with all types allowed by the schema */,\n\t);\n\tif (!hasSingle(possibleTypes)) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is compatible with more than one type allowed by the schema.\nThe set of possible types is ${JSON.stringify([\n\t\t\t\t...possibleTypes.map((schema) => schema.identifier),\n\t\t\t])}.\nExplicitly construct an unhydrated node of the desired type to disambiguate.\nFor class-based schema, this can be done by replacing an expression like \"{foo: 1}\" with \"new MySchema({foo: 1})\".`,\n\t\t);\n\t}\n\treturn possibleTypes[0];\n}\n\n/**\n * Returns all types for which the data is schema-compatible.\n */\nexport function getPossibleTypes(\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\tdata: FactoryContent,\n): TreeNodeSchema[] {\n\tlet best = CompatibilityLevel.None;\n\tconst possibleTypes: TreeNodeSchema[] = [];\n\tfor (const schema of allowedTypes) {\n\t\tconst level = shallowCompatibilityTest(schema, data);\n\t\tif (level > best) {\n\t\t\tpossibleTypes.length = 0;\n\t\t\tbest = level;\n\t\t}\n\t\tif (best === level) {\n\t\t\tpossibleTypes.push(schema);\n\t\t}\n\t}\n\treturn best === CompatibilityLevel.None ? [] : possibleTypes;\n}\n\n/**\n * Indicates a compatibility level for inferring a schema to apply to insertable data.\n * @remarks\n * Only the highest compatibility options are used.\n * This approach allows adding new possible matching at a new lower compatibility level as a non breaking change,\n * since that way they can't make a case that was compatible before ambiguous now.\n */\nenum CompatibilityLevel {\n\t/**\n\t * Not compatible. Constructor typing indicates incompatibility.\n\t */\n\tNone = 0,\n\t/**\n\t * Additional compatibility cases added in Fluid Framework 2.2.\n\t */\n\tLow = 1,\n\t/**\n\t * Compatible in Fluid Framework 2.0.\n\t */\n\tNormal = 2,\n}\n\n/**\n * Checks if data might be schema-compatible.\n *\n * @returns false if `data` is incompatible with `type` based on a cheap/shallow check.\n *\n * Note that this may return true for cases where data is incompatible, but it must not return false in cases where the data is compatible.\n */\nfunction shallowCompatibilityTest(\n\tschema: TreeNodeSchema,\n\tdata: FactoryContent,\n): CompatibilityLevel {\n\tassert(data !== undefined, 0x889 /* undefined cannot be used as FactoryContent. */);\n\n\tif (isTreeValue(data)) {\n\t\treturn allowsValue(schema, data) ? CompatibilityLevel.Normal : CompatibilityLevel.None;\n\t}\n\tif (schema.kind === NodeKind.Leaf) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\t// Typing (of schema based constructors and thus implicit node construction)\n\t// allows iterables for constructing maps and arrays.\n\t// Some users of this API may have unions of maps and arrays,\n\t// and rely on Arrays ending up as array nodes and maps as Map nodes,\n\t// despite both being iterable and thus compatible with both.\n\t// This uses a priority based system where an array would be parsed as an array when unioned with a map,\n\t// but if in a map only context, could still be used as a map.\n\n\tif (data instanceof Map) {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Map:\n\t\t\t\treturn CompatibilityLevel.Normal;\n\t\t\tcase NodeKind.Array:\n\t\t\t\t// Maps are iterable, so type checking does allow constructing an ArrayNode from a map if the array's type is an array that includes the key and value types of the map.\n\t\t\t\treturn CompatibilityLevel.Low;\n\t\t\tdefault:\n\t\t\t\treturn CompatibilityLevel.None;\n\t\t}\n\t}\n\n\tif (isReadonlyArray(data)) {\n\t\tswitch (schema.kind) {\n\t\t\tcase NodeKind.Array:\n\t\t\t\treturn CompatibilityLevel.Normal;\n\t\t\tcase NodeKind.Map:\n\t\t\t\t// Arrays are iterable, so type checking does allow constructing an array from a MapNode from an if the array's type is key values pairs for the map.\n\t\t\t\treturn CompatibilityLevel.Low;\n\t\t\tdefault:\n\t\t\t\treturn CompatibilityLevel.None;\n\t\t}\n\t}\n\n\tconst mapOrArray = schema.kind === NodeKind.Array || schema.kind === NodeKind.Map;\n\n\tif (Symbol.iterator in data) {\n\t\treturn mapOrArray ? CompatibilityLevel.Normal : CompatibilityLevel.None;\n\t}\n\n\t// At this point, it is assumed data is a record-like object since all the other cases have been eliminated.\n\n\tif (schema.kind === NodeKind.Array) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\tif (schema.kind === NodeKind.Map) {\n\t\t// When not unioned with an ObjectNode, allow objects to be used to create maps.\n\t\treturn CompatibilityLevel.Low;\n\t}\n\n\tassert(isObjectNodeSchema(schema), 0x9e6 /* unexpected schema kind */);\n\n\t// TODO: Improve type inference by making this logic more thorough. Handle at least:\n\t// * Types which are strict subsets of other types in the same polymorphic union\n\t// * Types which have the same keys but different types for those keys in the polymorphic union\n\t// * Types which have the same required fields but different optional fields and enough of those optional fields are populated to disambiguate\n\n\t// TODO#7441: Consider allowing data to be inserted which has keys that are extraneous/unknown to the schema (those keys are ignored)\n\n\t// If the schema has a required key which is not present in the input object, reject it.\n\tfor (const [fieldKey, fieldSchema] of schema.fields) {\n\t\tif (fieldSchema.requiresValue) {\n\t\t\tif (checkFieldProperty(data, fieldKey)) {\n\t\t\t\tif (data[fieldKey] === undefined) {\n\t\t\t\t\treturn CompatibilityLevel.None;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\treturn CompatibilityLevel.None;\n\t\t\t}\n\t\t}\n\t}\n\n\treturn CompatibilityLevel.Normal;\n}\n\nfunction allowsValue(schema: TreeNodeSchema, value: TreeValue): boolean {\n\tif (schema.kind === NodeKind.Leaf) {\n\t\treturn valueSchemaAllows(schema.info as ValueSchema, value);\n\t}\n\treturn false;\n}\n\n/**\n * Walk the given {@link ExclusiveMapTree} and deeply provide any field defaults for fields that are missing in the tree but present in the schema.\n * @param mapTree - The tree to populate with defaults. This is borrowed: no references to it are kept by this function.\n * @param allowedTypes - Some {@link TreeNodeSchema}, at least one of which the input tree must conform to\n * @param context - An optional context for generating defaults.\n * If present, all applicable defaults will be provided.\n * If absent, only defaults produced by a {@link ConstantFieldProvider} will be provided, and defaults produced by a {@link ContextualFieldProvider} will be ignored.\n * @remarks This function mutates the input tree by deeply adding new fields to the field maps where applicable.\n */\nexport function addDefaultsToMapTree(\n\tmapTree: ExclusiveMapTree,\n\tallowedTypes: ImplicitAllowedTypes,\n\tcontext: NodeIdentifierManager | undefined,\n): void {\n\tconst schema =\n\t\tfind(normalizeAllowedTypes(allowedTypes), (s) => s.identifier === mapTree.type) ??\n\t\tfail(0xae1 /* MapTree is incompatible with schema */);\n\n\tif (isObjectNodeSchema(schema)) {\n\t\tfor (const [_key, fieldInfo] of schema.flexKeyMap) {\n\t\t\tconst field = mapTree.fields.get(fieldInfo.storedKey);\n\t\t\tif (field !== undefined) {\n\t\t\t\tfor (const child of field) {\n\t\t\t\t\taddDefaultsToMapTree(child, fieldInfo.schema.allowedTypes, context);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst defaultProvider = fieldInfo.schema.props?.defaultProvider;\n\t\t\t\tif (defaultProvider !== undefined) {\n\t\t\t\t\tconst fieldProvider = extractFieldProvider(defaultProvider);\n\t\t\t\t\tconst data = provideDefault(fieldProvider, context);\n\t\t\t\t\tif (data !== undefined) {\n\t\t\t\t\t\tsetFieldValue(mapTree.fields, data, fieldInfo.schema, fieldInfo.storedKey);\n\t\t\t\t\t\t// call addDefaultsToMapTree on newly inserted default values\n\t\t\t\t\t\tfor (const child of mapTree.fields.get(fieldInfo.storedKey) ??\n\t\t\t\t\t\t\tfail(0xae2 /* Expected field to be populated */)) {\n\t\t\t\t\t\t\taddDefaultsToMapTree(child, fieldInfo.schema.allowedTypes, context);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn;\n\t}\n\n\tswitch (schema.kind) {\n\t\tcase NodeKind.Array:\n\t\tcase NodeKind.Map:\n\t\t\t{\n\t\t\t\tfor (const field of mapTree.fields.values()) {\n\t\t\t\t\tfor (const child of field) {\n\t\t\t\t\t\taddDefaultsToMapTree(child, schema.info as ImplicitAllowedTypes, context);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tassert(schema.kind === NodeKind.Leaf, 0x989 /* Unrecognized schema kind */);\n\t\t\tbreak;\n\t}\n}\n\n/**\n * Provides the default value (which can be undefined, for example with optional fields), or undefined if a context is required but not provided.\n * @privateRemarks\n * It is a bit concerning that there is no way for the caller to know when undefined is returned if that is the default value, or a context was required.\n * TODO: maybe better formalize the two stage defaulting (without then with context), or rework this design we only do one stage.\n */\nfunction provideDefault(\n\tfieldProvider: FieldProvider,\n\tcontext: NodeIdentifierManager | undefined,\n): InsertableContent | undefined {\n\tif (context !== undefined) {\n\t\treturn fieldProvider(context);\n\t} else {\n\t\tif (isConstant(fieldProvider)) {\n\t\t\treturn fieldProvider();\n\t\t} else {\n\t\t\t// Leaving field empty despite it needing a default value since a context was required and none was provided.\n\t\t\t// Caller better handle this case by providing the default at some other point in time when the context becomes known.\n\t\t}\n\t}\n}\n\n/**\n * Retrieves the InnerNode associated with the given target via {@link setInnerNode}, if any.\n * @remarks\n * If `target` is a unhydrated node, returns its MapTreeNode.\n * If `target` is a cooked node (or marinated but a FlexTreeNode exists) returns the FlexTreeNode.\n * If the target is not a node, or a marinated node with no FlexTreeNode for its anchor, returns undefined.\n */\nfunction tryGetInnerNode(target: unknown): InnerNode | undefined {\n\tif (isTreeNode(target)) {\n\t\treturn getKernel(target).tryGetInnerNode();\n\t}\n}\n\n/**\n * Content which can be used to build a node.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n * @system @alpha\n */\nexport type FactoryContent =\n\t| IFluidHandle\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| Iterable<readonly [string, InsertableContent]>\n\t| readonly InsertableContent[]\n\t| FactoryContentObject;\n\n/**\n * Record-like object which can be used to build some kinds of nodes.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n *\n * Supports object and map nodes.\n * @system @alpha\n */\nexport type FactoryContentObject = {\n\treadonly [P in string]?: InsertableContent;\n};\n\n/**\n * Content which can be inserted into a tree.\n * @system @alpha\n */\nexport type InsertableContent = Unhydrated<TreeNode> | FactoryContent;\n"]}