@fluidframework/tree 2.42.0 → 2.43.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 (542) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/api-report/tree.alpha.api.md +72 -25
  3. package/api-report/tree.beta.api.md +34 -0
  4. package/api-report/tree.legacy.alpha.api.md +1 -0
  5. package/api-report/tree.legacy.public.api.md +1 -0
  6. package/api-report/tree.public.api.md +1 -0
  7. package/dist/alpha.d.ts +12 -6
  8. package/dist/beta.d.ts +6 -1
  9. package/dist/core/index.d.ts +1 -1
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/index.js +5 -2
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/core/schema-stored/formatV2.d.ts +80 -0
  14. package/dist/core/schema-stored/formatV2.d.ts.map +1 -0
  15. package/dist/core/schema-stored/formatV2.js +55 -0
  16. package/dist/core/schema-stored/formatV2.js.map +1 -0
  17. package/dist/core/schema-stored/index.d.ts +3 -1
  18. package/dist/core/schema-stored/index.d.ts.map +1 -1
  19. package/dist/core/schema-stored/index.js +5 -2
  20. package/dist/core/schema-stored/index.js.map +1 -1
  21. package/dist/core/schema-stored/schema.d.ts +49 -17
  22. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  23. package/dist/core/schema-stored/schema.js +65 -22
  24. package/dist/core/schema-stored/schema.js.map +1 -1
  25. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts +9 -7
  26. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts.map +1 -1
  27. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +13 -9
  28. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  29. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +3 -3
  30. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  31. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +6 -6
  32. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts +1 -1
  34. package/dist/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js +3 -3
  36. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  37. package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts +8 -3
  38. package/dist/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
  39. package/dist/feature-libraries/detachedFieldIndexSummarizer.js +2 -5
  40. package/dist/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  41. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +24 -25
  42. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  43. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  44. package/dist/feature-libraries/flex-tree/index.d.ts +0 -1
  45. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  46. package/dist/feature-libraries/flex-tree/index.js +1 -7
  47. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  48. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts +2 -2
  49. package/dist/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  50. package/dist/feature-libraries/flex-tree/lazyEntity.js +3 -0
  51. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  52. package/dist/feature-libraries/flex-tree/lazyField.d.ts +1 -2
  53. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  54. package/dist/feature-libraries/flex-tree/lazyField.js +2 -5
  55. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  56. package/dist/feature-libraries/flex-tree/lazyNode.d.ts +5 -5
  57. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  58. package/dist/feature-libraries/flex-tree/lazyNode.js +15 -7
  59. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  60. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +8 -3
  61. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  62. package/dist/feature-libraries/forest-summary/forestSummarizer.js +2 -5
  63. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  64. package/dist/feature-libraries/index.d.ts +2 -2
  65. package/dist/feature-libraries/index.d.ts.map +1 -1
  66. package/dist/feature-libraries/index.js +1 -2
  67. package/dist/feature-libraries/index.js.map +1 -1
  68. package/dist/feature-libraries/mapTreeCursor.d.ts +16 -2
  69. package/dist/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  70. package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
  71. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.d.ts.map +1 -1
  72. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js +2 -0
  73. package/dist/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
  74. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  75. package/dist/feature-libraries/object-forest/objectForest.js +2 -0
  76. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  77. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  78. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -4
  79. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  80. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -36
  81. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  82. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
  83. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  84. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  85. package/dist/feature-libraries/schema-index/codec.js +59 -9
  86. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  87. package/dist/feature-libraries/schema-index/formatV1.d.ts +1 -1
  88. package/dist/feature-libraries/schema-index/formatV2.d.ts +42 -0
  89. package/dist/feature-libraries/schema-index/formatV2.d.ts.map +1 -0
  90. package/dist/feature-libraries/schema-index/formatV2.js +26 -0
  91. package/dist/feature-libraries/schema-index/formatV2.js.map +1 -0
  92. package/dist/feature-libraries/schema-index/index.d.ts +2 -1
  93. package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
  94. package/dist/feature-libraries/schema-index/index.js +4 -2
  95. package/dist/feature-libraries/schema-index/index.js.map +1 -1
  96. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts +7 -2
  97. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  98. package/dist/feature-libraries/schema-index/schemaSummarizer.js +6 -6
  99. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  100. package/dist/index.d.ts +2 -2
  101. package/dist/index.d.ts.map +1 -1
  102. package/dist/index.js.map +1 -1
  103. package/dist/packageVersion.d.ts +1 -1
  104. package/dist/packageVersion.js +1 -1
  105. package/dist/packageVersion.js.map +1 -1
  106. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  107. package/dist/shared-tree/schematizeTree.js +1 -0
  108. package/dist/shared-tree/schematizeTree.js.map +1 -1
  109. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  110. package/dist/shared-tree/schematizingTreeView.js +3 -3
  111. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  112. package/dist/shared-tree/sharedTree.d.ts +5 -1
  113. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  114. package/dist/shared-tree/sharedTree.js +34 -5
  115. package/dist/shared-tree/sharedTree.js.map +1 -1
  116. package/dist/shared-tree/treeAlpha.d.ts +39 -1
  117. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  118. package/dist/shared-tree/treeAlpha.js +117 -11
  119. package/dist/shared-tree/treeAlpha.js.map +1 -1
  120. package/dist/shared-tree-core/editManagerSummarizer.d.ts +8 -3
  121. package/dist/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  122. package/dist/shared-tree-core/editManagerSummarizer.js +2 -5
  123. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  124. package/dist/shared-tree-core/sharedTreeCore.d.ts +18 -7
  125. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  126. package/dist/shared-tree-core/sharedTreeCore.js +15 -2
  127. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  128. package/dist/simple-tree/api/configuration.d.ts +15 -3
  129. package/dist/simple-tree/api/configuration.d.ts.map +1 -1
  130. package/dist/simple-tree/api/configuration.js +40 -22
  131. package/dist/simple-tree/api/configuration.js.map +1 -1
  132. package/dist/simple-tree/api/index.d.ts +1 -1
  133. package/dist/simple-tree/api/index.d.ts.map +1 -1
  134. package/dist/simple-tree/api/index.js +4 -4
  135. package/dist/simple-tree/api/index.js.map +1 -1
  136. package/dist/simple-tree/api/schemaCompatibilityTester.js +1 -1
  137. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  138. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +3 -3
  139. package/dist/simple-tree/api/schemaCreationUtilities.js +3 -3
  140. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  141. package/dist/simple-tree/api/schemaFactory.d.ts +15 -11
  142. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  143. package/dist/simple-tree/api/schemaFactory.js +4 -0
  144. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  145. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +41 -11
  146. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  147. package/dist/simple-tree/api/schemaFactoryAlpha.js +31 -4
  148. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  149. package/dist/simple-tree/api/storedSchema.js +2 -2
  150. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  151. package/dist/simple-tree/api/treeChangeEvents.d.ts +8 -3
  152. package/dist/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
  153. package/dist/simple-tree/api/treeChangeEvents.js.map +1 -1
  154. package/dist/simple-tree/api/treeNodeApi.d.ts +3 -0
  155. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  156. package/dist/simple-tree/api/treeNodeApi.js +1 -1
  157. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  158. package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  159. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +5 -0
  160. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  161. package/dist/simple-tree/core/context.d.ts +3 -3
  162. package/dist/simple-tree/core/context.d.ts.map +1 -1
  163. package/dist/simple-tree/core/context.js.map +1 -1
  164. package/dist/simple-tree/core/getOrCreateNode.d.ts +9 -0
  165. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  166. package/dist/simple-tree/core/getOrCreateNode.js +12 -1
  167. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  168. package/dist/simple-tree/core/index.d.ts +2 -2
  169. package/dist/simple-tree/core/index.d.ts.map +1 -1
  170. package/dist/simple-tree/core/index.js +3 -1
  171. package/dist/simple-tree/core/index.js.map +1 -1
  172. package/dist/simple-tree/core/treeNodeKernel.js +2 -2
  173. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  174. package/dist/simple-tree/core/treeNodeSchema.d.ts +68 -1
  175. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  176. package/dist/simple-tree/core/treeNodeSchema.js +24 -1
  177. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  178. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +5 -9
  179. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  180. package/dist/simple-tree/core/unhydratedFlexTree.js +12 -31
  181. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  182. package/dist/simple-tree/core/walkSchema.d.ts +3 -3
  183. package/dist/simple-tree/core/walkSchema.d.ts.map +1 -1
  184. package/dist/simple-tree/core/walkSchema.js +9 -5
  185. package/dist/simple-tree/core/walkSchema.js.map +1 -1
  186. package/dist/simple-tree/createContext.js +1 -1
  187. package/dist/simple-tree/createContext.js.map +1 -1
  188. package/dist/simple-tree/getTreeNodeForField.d.ts +1 -1
  189. package/dist/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  190. package/dist/simple-tree/getTreeNodeForField.js +3 -3
  191. package/dist/simple-tree/getTreeNodeForField.js.map +1 -1
  192. package/dist/simple-tree/index.d.ts +6 -6
  193. package/dist/simple-tree/index.d.ts.map +1 -1
  194. package/dist/simple-tree/index.js +8 -5
  195. package/dist/simple-tree/index.js.map +1 -1
  196. package/dist/simple-tree/leafNodeSchema.d.ts +4 -1
  197. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  198. package/dist/simple-tree/leafNodeSchema.js +1 -0
  199. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  200. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -1
  201. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  202. package/dist/simple-tree/node-kinds/array/arrayNode.js +21 -16
  203. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  204. package/dist/simple-tree/node-kinds/map/mapNode.d.ts +3 -2
  205. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  206. package/dist/simple-tree/node-kinds/map/mapNode.js +11 -5
  207. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  208. package/dist/simple-tree/node-kinds/object/objectNode.d.ts +3 -2
  209. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  210. package/dist/simple-tree/node-kinds/object/objectNode.js +12 -7
  211. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  212. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  213. package/dist/simple-tree/prepareForInsertion.js +5 -1
  214. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  215. package/dist/simple-tree/schemaTypes.d.ts +63 -30
  216. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  217. package/dist/simple-tree/schemaTypes.js +73 -40
  218. package/dist/simple-tree/schemaTypes.js.map +1 -1
  219. package/dist/simple-tree/simpleSchema.d.ts +22 -4
  220. package/dist/simple-tree/simpleSchema.d.ts.map +1 -1
  221. package/dist/simple-tree/simpleSchema.js.map +1 -1
  222. package/dist/simple-tree/toStoredSchema.d.ts +4 -0
  223. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  224. package/dist/simple-tree/toStoredSchema.js +15 -4
  225. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  226. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  227. package/dist/simple-tree/treeNodeValid.js +1 -2
  228. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  229. package/dist/simple-tree/walkFieldSchema.d.ts.map +1 -1
  230. package/dist/simple-tree/walkFieldSchema.js +1 -1
  231. package/dist/simple-tree/walkFieldSchema.js.map +1 -1
  232. package/dist/tableSchema.d.ts +1 -1
  233. package/dist/util/typeUtils.d.ts +2 -2
  234. package/dist/util/typeUtils.js.map +1 -1
  235. package/dist/util/utils.d.ts +2 -0
  236. package/dist/util/utils.d.ts.map +1 -1
  237. package/dist/util/utils.js.map +1 -1
  238. package/lib/alpha.d.ts +12 -6
  239. package/lib/beta.d.ts +6 -1
  240. package/lib/core/index.d.ts +1 -1
  241. package/lib/core/index.d.ts.map +1 -1
  242. package/lib/core/index.js +1 -1
  243. package/lib/core/index.js.map +1 -1
  244. package/lib/core/schema-stored/formatV2.d.ts +80 -0
  245. package/lib/core/schema-stored/formatV2.d.ts.map +1 -0
  246. package/lib/core/schema-stored/formatV2.js +52 -0
  247. package/lib/core/schema-stored/formatV2.js.map +1 -0
  248. package/lib/core/schema-stored/index.d.ts +3 -1
  249. package/lib/core/schema-stored/index.d.ts.map +1 -1
  250. package/lib/core/schema-stored/index.js +3 -1
  251. package/lib/core/schema-stored/index.js.map +1 -1
  252. package/lib/core/schema-stored/schema.d.ts +49 -17
  253. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  254. package/lib/core/schema-stored/schema.js +63 -21
  255. package/lib/core/schema-stored/schema.js.map +1 -1
  256. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts +9 -7
  257. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.d.ts.map +1 -1
  258. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +11 -7
  259. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  260. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts +3 -3
  261. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  262. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +7 -7
  263. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  264. package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts +1 -1
  265. package/lib/feature-libraries/chunked-forest/codec/nodeShape.d.ts.map +1 -1
  266. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js +3 -3
  267. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  268. package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts +8 -3
  269. package/lib/feature-libraries/detachedFieldIndexSummarizer.d.ts.map +1 -1
  270. package/lib/feature-libraries/detachedFieldIndexSummarizer.js +2 -5
  271. package/lib/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  272. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +24 -25
  273. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  274. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  275. package/lib/feature-libraries/flex-tree/index.d.ts +0 -1
  276. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  277. package/lib/feature-libraries/flex-tree/index.js +0 -1
  278. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  279. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts +2 -2
  280. package/lib/feature-libraries/flex-tree/lazyEntity.d.ts.map +1 -1
  281. package/lib/feature-libraries/flex-tree/lazyEntity.js +3 -0
  282. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  283. package/lib/feature-libraries/flex-tree/lazyField.d.ts +1 -2
  284. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  285. package/lib/feature-libraries/flex-tree/lazyField.js +3 -6
  286. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  287. package/lib/feature-libraries/flex-tree/lazyNode.d.ts +5 -5
  288. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  289. package/lib/feature-libraries/flex-tree/lazyNode.js +15 -7
  290. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  291. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +8 -3
  292. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  293. package/lib/feature-libraries/forest-summary/forestSummarizer.js +2 -5
  294. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  295. package/lib/feature-libraries/index.d.ts +2 -2
  296. package/lib/feature-libraries/index.d.ts.map +1 -1
  297. package/lib/feature-libraries/index.js +1 -1
  298. package/lib/feature-libraries/index.js.map +1 -1
  299. package/lib/feature-libraries/mapTreeCursor.d.ts +16 -2
  300. package/lib/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  301. package/lib/feature-libraries/mapTreeCursor.js.map +1 -1
  302. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.d.ts.map +1 -1
  303. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js +2 -0
  304. package/lib/feature-libraries/modular-schema/fieldKindWithEditor.js.map +1 -1
  305. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  306. package/lib/feature-libraries/object-forest/objectForest.js +2 -0
  307. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  308. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  309. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +8 -4
  310. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  311. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -36
  312. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  313. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js +3 -3
  314. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  315. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  316. package/lib/feature-libraries/schema-index/codec.js +60 -10
  317. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  318. package/lib/feature-libraries/schema-index/formatV1.d.ts +1 -1
  319. package/lib/feature-libraries/schema-index/formatV2.d.ts +42 -0
  320. package/lib/feature-libraries/schema-index/formatV2.d.ts.map +1 -0
  321. package/lib/feature-libraries/schema-index/formatV2.js +23 -0
  322. package/lib/feature-libraries/schema-index/formatV2.js.map +1 -0
  323. package/lib/feature-libraries/schema-index/index.d.ts +2 -1
  324. package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
  325. package/lib/feature-libraries/schema-index/index.js +2 -1
  326. package/lib/feature-libraries/schema-index/index.js.map +1 -1
  327. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts +7 -2
  328. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  329. package/lib/feature-libraries/schema-index/schemaSummarizer.js +6 -6
  330. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  331. package/lib/index.d.ts +2 -2
  332. package/lib/index.d.ts.map +1 -1
  333. package/lib/index.js.map +1 -1
  334. package/lib/packageVersion.d.ts +1 -1
  335. package/lib/packageVersion.js +1 -1
  336. package/lib/packageVersion.js.map +1 -1
  337. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  338. package/lib/shared-tree/schematizeTree.js +1 -0
  339. package/lib/shared-tree/schematizeTree.js.map +1 -1
  340. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  341. package/lib/shared-tree/schematizingTreeView.js +4 -4
  342. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  343. package/lib/shared-tree/sharedTree.d.ts +5 -1
  344. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  345. package/lib/shared-tree/sharedTree.js +34 -5
  346. package/lib/shared-tree/sharedTree.js.map +1 -1
  347. package/lib/shared-tree/treeAlpha.d.ts +39 -1
  348. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  349. package/lib/shared-tree/treeAlpha.js +111 -5
  350. package/lib/shared-tree/treeAlpha.js.map +1 -1
  351. package/lib/shared-tree-core/editManagerSummarizer.d.ts +8 -3
  352. package/lib/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  353. package/lib/shared-tree-core/editManagerSummarizer.js +2 -5
  354. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  355. package/lib/shared-tree-core/sharedTreeCore.d.ts +18 -7
  356. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  357. package/lib/shared-tree-core/sharedTreeCore.js +15 -2
  358. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  359. package/lib/simple-tree/api/configuration.d.ts +15 -3
  360. package/lib/simple-tree/api/configuration.d.ts.map +1 -1
  361. package/lib/simple-tree/api/configuration.js +42 -24
  362. package/lib/simple-tree/api/configuration.js.map +1 -1
  363. package/lib/simple-tree/api/index.d.ts +1 -1
  364. package/lib/simple-tree/api/index.d.ts.map +1 -1
  365. package/lib/simple-tree/api/index.js +1 -1
  366. package/lib/simple-tree/api/index.js.map +1 -1
  367. package/lib/simple-tree/api/schemaCompatibilityTester.js +1 -1
  368. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  369. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +3 -3
  370. package/lib/simple-tree/api/schemaCreationUtilities.js +3 -3
  371. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  372. package/lib/simple-tree/api/schemaFactory.d.ts +15 -11
  373. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  374. package/lib/simple-tree/api/schemaFactory.js +4 -0
  375. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  376. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +41 -11
  377. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  378. package/lib/simple-tree/api/schemaFactoryAlpha.js +31 -4
  379. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  380. package/lib/simple-tree/api/storedSchema.js +2 -2
  381. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  382. package/lib/simple-tree/api/treeChangeEvents.d.ts +8 -3
  383. package/lib/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
  384. package/lib/simple-tree/api/treeChangeEvents.js.map +1 -1
  385. package/lib/simple-tree/api/treeNodeApi.d.ts +3 -0
  386. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  387. package/lib/simple-tree/api/treeNodeApi.js +2 -2
  388. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  389. package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  390. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +5 -0
  391. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  392. package/lib/simple-tree/core/context.d.ts +3 -3
  393. package/lib/simple-tree/core/context.d.ts.map +1 -1
  394. package/lib/simple-tree/core/context.js.map +1 -1
  395. package/lib/simple-tree/core/getOrCreateNode.d.ts +9 -0
  396. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  397. package/lib/simple-tree/core/getOrCreateNode.js +10 -0
  398. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  399. package/lib/simple-tree/core/index.d.ts +2 -2
  400. package/lib/simple-tree/core/index.d.ts.map +1 -1
  401. package/lib/simple-tree/core/index.js +2 -2
  402. package/lib/simple-tree/core/index.js.map +1 -1
  403. package/lib/simple-tree/core/treeNodeKernel.js +2 -2
  404. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  405. package/lib/simple-tree/core/treeNodeSchema.d.ts +68 -1
  406. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  407. package/lib/simple-tree/core/treeNodeSchema.js +21 -0
  408. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  409. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +5 -9
  410. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  411. package/lib/simple-tree/core/unhydratedFlexTree.js +15 -34
  412. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  413. package/lib/simple-tree/core/walkSchema.d.ts +3 -3
  414. package/lib/simple-tree/core/walkSchema.d.ts.map +1 -1
  415. package/lib/simple-tree/core/walkSchema.js +9 -5
  416. package/lib/simple-tree/core/walkSchema.js.map +1 -1
  417. package/lib/simple-tree/createContext.js +1 -1
  418. package/lib/simple-tree/createContext.js.map +1 -1
  419. package/lib/simple-tree/getTreeNodeForField.d.ts +1 -1
  420. package/lib/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  421. package/lib/simple-tree/getTreeNodeForField.js +1 -1
  422. package/lib/simple-tree/getTreeNodeForField.js.map +1 -1
  423. package/lib/simple-tree/index.d.ts +6 -6
  424. package/lib/simple-tree/index.d.ts.map +1 -1
  425. package/lib/simple-tree/index.js +4 -4
  426. package/lib/simple-tree/index.js.map +1 -1
  427. package/lib/simple-tree/leafNodeSchema.d.ts +4 -1
  428. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  429. package/lib/simple-tree/leafNodeSchema.js +2 -1
  430. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  431. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -1
  432. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  433. package/lib/simple-tree/node-kinds/array/arrayNode.js +13 -8
  434. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  435. package/lib/simple-tree/node-kinds/map/mapNode.d.ts +3 -2
  436. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  437. package/lib/simple-tree/node-kinds/map/mapNode.js +14 -8
  438. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  439. package/lib/simple-tree/node-kinds/object/objectNode.d.ts +3 -2
  440. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  441. package/lib/simple-tree/node-kinds/object/objectNode.js +14 -9
  442. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  443. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  444. package/lib/simple-tree/prepareForInsertion.js +5 -1
  445. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  446. package/lib/simple-tree/schemaTypes.d.ts +63 -30
  447. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  448. package/lib/simple-tree/schemaTypes.js +70 -36
  449. package/lib/simple-tree/schemaTypes.js.map +1 -1
  450. package/lib/simple-tree/simpleSchema.d.ts +22 -4
  451. package/lib/simple-tree/simpleSchema.d.ts.map +1 -1
  452. package/lib/simple-tree/simpleSchema.js.map +1 -1
  453. package/lib/simple-tree/toStoredSchema.d.ts +4 -0
  454. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  455. package/lib/simple-tree/toStoredSchema.js +15 -4
  456. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  457. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  458. package/lib/simple-tree/treeNodeValid.js +1 -2
  459. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  460. package/lib/simple-tree/walkFieldSchema.d.ts.map +1 -1
  461. package/lib/simple-tree/walkFieldSchema.js +1 -1
  462. package/lib/simple-tree/walkFieldSchema.js.map +1 -1
  463. package/lib/tableSchema.d.ts +1 -1
  464. package/lib/util/typeUtils.d.ts +2 -2
  465. package/lib/util/typeUtils.js.map +1 -1
  466. package/lib/util/utils.d.ts +2 -0
  467. package/lib/util/utils.d.ts.map +1 -1
  468. package/lib/util/utils.js.map +1 -1
  469. package/package.json +23 -23
  470. package/src/core/index.ts +3 -1
  471. package/src/core/schema-stored/formatV2.ts +78 -0
  472. package/src/core/schema-stored/index.ts +4 -1
  473. package/src/core/schema-stored/schema.ts +123 -33
  474. package/src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts +16 -11
  475. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +16 -7
  476. package/src/feature-libraries/chunked-forest/codec/nodeShape.ts +4 -4
  477. package/src/feature-libraries/detachedFieldIndexSummarizer.ts +9 -16
  478. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +33 -30
  479. package/src/feature-libraries/flex-tree/index.ts +0 -8
  480. package/src/feature-libraries/flex-tree/lazyEntity.ts +5 -1
  481. package/src/feature-libraries/flex-tree/lazyField.ts +5 -8
  482. package/src/feature-libraries/flex-tree/lazyNode.ts +17 -8
  483. package/src/feature-libraries/forest-summary/forestSummarizer.ts +9 -16
  484. package/src/feature-libraries/index.ts +1 -1
  485. package/src/feature-libraries/mapTreeCursor.ts +17 -8
  486. package/src/feature-libraries/modular-schema/fieldKindWithEditor.ts +2 -0
  487. package/src/feature-libraries/object-forest/objectForest.ts +3 -0
  488. package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +11 -6
  489. package/src/feature-libraries/schema-edits/schemaChangeFormat.ts +3 -3
  490. package/src/feature-libraries/schema-index/codec.ts +73 -14
  491. package/src/feature-libraries/schema-index/formatV2.ts +30 -0
  492. package/src/feature-libraries/schema-index/index.ts +2 -1
  493. package/src/feature-libraries/schema-index/schemaSummarizer.ts +11 -18
  494. package/src/index.ts +6 -0
  495. package/src/packageVersion.ts +1 -1
  496. package/src/shared-tree/schematizeTree.ts +1 -0
  497. package/src/shared-tree/schematizingTreeView.ts +8 -5
  498. package/src/shared-tree/sharedTree.ts +42 -12
  499. package/src/shared-tree/treeAlpha.ts +196 -6
  500. package/src/shared-tree-core/editManagerSummarizer.ts +9 -16
  501. package/src/shared-tree-core/sharedTreeCore.ts +33 -24
  502. package/src/simple-tree/api/configuration.ts +59 -27
  503. package/src/simple-tree/api/index.ts +3 -3
  504. package/src/simple-tree/api/schemaCompatibilityTester.ts +1 -1
  505. package/src/simple-tree/api/schemaCreationUtilities.ts +3 -3
  506. package/src/simple-tree/api/schemaFactory.ts +16 -11
  507. package/src/simple-tree/api/schemaFactoryAlpha.ts +53 -8
  508. package/src/simple-tree/api/storedSchema.ts +4 -4
  509. package/src/simple-tree/api/treeChangeEvents.ts +8 -3
  510. package/src/simple-tree/api/treeNodeApi.ts +5 -2
  511. package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +5 -0
  512. package/src/simple-tree/core/context.ts +3 -3
  513. package/src/simple-tree/core/getOrCreateNode.ts +14 -0
  514. package/src/simple-tree/core/index.ts +7 -1
  515. package/src/simple-tree/core/treeNodeKernel.ts +2 -2
  516. package/src/simple-tree/core/treeNodeSchema.ts +113 -1
  517. package/src/simple-tree/core/unhydratedFlexTree.ts +22 -44
  518. package/src/simple-tree/core/walkSchema.ts +16 -7
  519. package/src/simple-tree/createContext.ts +1 -1
  520. package/src/simple-tree/getTreeNodeForField.ts +3 -1
  521. package/src/simple-tree/index.ts +12 -5
  522. package/src/simple-tree/leafNodeSchema.ts +9 -1
  523. package/src/simple-tree/node-kinds/array/arrayNode.ts +20 -9
  524. package/src/simple-tree/node-kinds/map/mapNode.ts +21 -6
  525. package/src/simple-tree/node-kinds/object/objectNode.ts +29 -12
  526. package/src/simple-tree/prepareForInsertion.ts +5 -1
  527. package/src/simple-tree/schemaTypes.ts +151 -71
  528. package/src/simple-tree/simpleSchema.ts +27 -5
  529. package/src/simple-tree/toStoredSchema.ts +17 -4
  530. package/src/simple-tree/treeNodeValid.ts +1 -1
  531. package/src/simple-tree/walkFieldSchema.ts +5 -1
  532. package/src/util/typeUtils.ts +2 -2
  533. package/src/util/utils.ts +2 -0
  534. package/dist/feature-libraries/flex-tree/navigation.d.ts +0 -46
  535. package/dist/feature-libraries/flex-tree/navigation.d.ts.map +0 -1
  536. package/dist/feature-libraries/flex-tree/navigation.js +0 -104
  537. package/dist/feature-libraries/flex-tree/navigation.js.map +0 -1
  538. package/lib/feature-libraries/flex-tree/navigation.d.ts +0 -46
  539. package/lib/feature-libraries/flex-tree/navigation.d.ts.map +0 -1
  540. package/lib/feature-libraries/flex-tree/navigation.js +0 -97
  541. package/lib/feature-libraries/flex-tree/navigation.js.map +0 -1
  542. package/src/feature-libraries/flex-tree/navigation.ts +0 -121
@@ -1 +1 @@
1
- {"version":3,"file":"mapNode.d.ts","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/map/mapNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH,OAAO,EAKN,KAAK,oBAAoB,EACzB,KAAK,6BAA6B,EAClC,KAAK,0CAA0C,EAC/C,KAAK,kBAAkB,EACvB,KAAK,gCAAgC,EAErC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAON,KAAK,QAAQ,EAMb,MAAM,qBAAqB,CAAC;AAO7B,OAAO,EAAgB,KAAK,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAGpF,OAAO,KAAK,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/F;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,oBAAoB,GAAG,oBAAoB,CACjF,SAAQ,WAAW,CAAC,MAAM,EAAE,gCAAgC,CAAC,CAAC,CAAC,CAAC,EAC/D,QAAQ;IACT;;;;;;;;OAQG;IACH,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,0CAA0C,CAAC,CAAC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AgC,CAAC,CAAC,CAAC,CAAC,KACzD,IAAI,EAGT,OAAO,CAAC,EAAE,GAAG,GACX,IAAI,CAAC;CACR;AA6FD;;;;;;GAMG;AAEH,wBAAgB,SAAS,CACxB,KAAK,SAAS,MAAM,EACpB,KAAK,CAAC,CAAC,SAAS,6BAA6B,EAC7C,KAAK,CAAC,uBAAuB,SAAS,OAAO,EAC7C,KAAK,CAAC,eAAe,GAAG,OAAO,EAE/B,UAAU,EAAE,KAAK,EACjB,IAAI,EAAE,CAAC,EACP,uBAAuB,EAAE,uBAAuB,EAChD,eAAe,EAAE,OAAO,EACxB,QAAQ,CAAC,EAAE,kBAAkB,CAAC,eAAe,CAAC,EAC9C,iBAAiB,CAAC,EAAE,4BAA4B,GAAG,SAAS,kKA6E5D;AAED;;;GAGG;AACH,MAAM,MAAM,qBAAqB,CAAC,CAAC,SAAS,oBAAoB,IAC7D,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,0CAA0C,CAAC,CAAC,CAAC,CAAC,CAAC,GAC1E,uBAAuB,CAAC,0CAA0C,CAAC,CAAC,CAAC,CAAC,CAAC"}
@@ -3,14 +3,14 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
  import { Lazy } from "@fluidframework/core-utils/internal";
6
- import { getTreeNodeForField } from "../../getTreeNodeForField.js";
7
- import { createFieldSchema, FieldKind, normalizeAllowedTypes, unannotateImplicitAllowedTypes, } from "../../schemaTypes.js";
6
+ import { tryGetTreeNodeForField } from "../../getTreeNodeForField.js";
7
+ import { createFieldSchema, FieldKind, normalizeAllowedTypes, normalizeAnnotatedAllowedTypes, unannotateImplicitAllowedTypes, } from "../../schemaTypes.js";
8
8
  import { getKernel, NodeKind,
9
9
  // eslint-disable-next-line import/no-deprecated
10
10
  typeNameSymbol, typeSchemaSymbol, getOrCreateInnerNode, } from "../../core/index.js";
11
11
  import { unhydratedFlexTreeFromInsertable, } from "../../unhydratedFlexTreeFromInsertable.js";
12
12
  import { prepareForInsertion } from "../../prepareForInsertion.js";
13
- import { brand, count } from "../../../util/index.js";
13
+ import { brand, count, } from "../../../util/index.js";
14
14
  import { TreeNodeValid } from "../../treeNodeValid.js";
15
15
  import { getUnhydratedContext } from "../../createContext.js";
16
16
  // TreeMapNode is invariant over schema type, so for this handler to work with all schema, the only possible type for the schema is `any`.
@@ -44,14 +44,14 @@ class CustomMapNodeBase extends TreeNodeValid {
44
44
  for (const key of node.keys()) {
45
45
  yield [
46
46
  key,
47
- getTreeNodeForField(node.getBoxed(key)),
47
+ tryGetTreeNodeForField(node.getBoxed(key)),
48
48
  ];
49
49
  }
50
50
  }
51
51
  get(key) {
52
52
  const node = this.innerNode;
53
53
  const field = node.getBoxed(brand(key));
54
- return getTreeNodeForField(field);
54
+ return tryGetTreeNodeForField(field);
55
55
  }
56
56
  has(key) {
57
57
  return this.innerNode.tryGetField(brand(key)) !== undefined;
@@ -77,8 +77,8 @@ class CustomMapNodeBase extends TreeNodeValid {
77
77
  }
78
78
  }
79
79
  forEach(callbackFn, thisArg) {
80
- for (const field of getOrCreateInnerNode(this).boxedIterator()) {
81
- const node = getTreeNodeForField(field);
80
+ for (const field of getOrCreateInnerNode(this)) {
81
+ const node = tryGetTreeNodeForField(field);
82
82
  callbackFn.call(thisArg, node, field.key, this);
83
83
  }
84
84
  }
@@ -89,10 +89,12 @@ CustomMapNodeBase.kind = NodeKind.Map;
89
89
  *
90
90
  * @param base - base schema type to extend.
91
91
  * @param useMapPrototype - should this type emulate a ES6 Map object (by faking its prototype with a proxy).
92
+ * @param persistedMetadata - Optional persisted metadata for the object node schema.
92
93
  */
93
94
  // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
94
- export function mapSchema(identifier, info, implicitlyConstructable, useMapPrototype, metadata) {
95
+ export function mapSchema(identifier, info, implicitlyConstructable, useMapPrototype, metadata, persistedMetadata) {
95
96
  const lazyChildTypes = new Lazy(() => normalizeAllowedTypes(unannotateImplicitAllowedTypes(info)));
97
+ const lazyAnnotatedTypes = new Lazy(() => [normalizeAnnotatedAllowedTypes(info)]);
96
98
  const lazyAllowedTypesIdentifiers = new Lazy(() => new Set([...lazyChildTypes.value].map((type) => type.identifier)));
97
99
  let unhydratedContext;
98
100
  class Schema extends CustomMapNodeBase {
@@ -116,6 +118,9 @@ export function mapSchema(identifier, info, implicitlyConstructable, useMapProto
116
118
  static get childTypes() {
117
119
  return lazyChildTypes.value;
118
120
  }
121
+ static get childAnnotatedAllowedTypes() {
122
+ return lazyAnnotatedTypes.value;
123
+ }
119
124
  // eslint-disable-next-line import/no-deprecated
120
125
  get [typeNameSymbol]() {
121
126
  return identifier;
@@ -129,6 +134,7 @@ export function mapSchema(identifier, info, implicitlyConstructable, useMapProto
129
134
  Schema.info = info;
130
135
  Schema.implicitlyConstructable = implicitlyConstructable;
131
136
  Schema.metadata = metadata ?? {};
137
+ Schema.persistedMetadata = persistedMetadata;
132
138
  const schemaErased = Schema;
133
139
  return schemaErased;
134
140
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mapNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/map/mapNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAO3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACN,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,8BAA8B,GAO9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,SAAS,EAET,QAAQ;AAER,gDAAgD;AAChD,cAAc,EAEd,gBAAgB,EAEhB,oBAAoB,GAGpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gCAAgC,GAGhC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAgC,MAAM,wBAAwB,CAAC;AACpF,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAw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,MAAM,CAAU,YAAY;YACrC,MAAM,MAAM,GAAG,IAAiC,CAAC;YACjD,iBAAiB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;YACjD,OAAO,iBAAiB,CAAC;QAC1B,CAAC;QAMM,MAAM,KAAK,UAAU;YAC3B,OAAO,cAAc,CAAC,KAAK,CAAC;QAC7B,CAAC;QAGD,gDAAgD;QAChD,IAAW,CAAC,cAAc,CAAC;YAC1B,OAAO,UAAU,CAAC;QACnB,CAAC;QACD,IAAW,CAAC,gBAAgB,CAAC;YAC5B,OAAO,MAAM,CAAC,iBAAiB,EAAE,WAA6C,CAAC;QAChF,CAAC;;IAvByB,wBAAiB,GAAgC,SAAS,CAAC;IAQ9D,iBAAU,GAAG,UAAU,CAAC;IACxB,WAAI,GAAG,IAAI,CAAC;IACZ,8BAAuB,GAC7C,uBAAuB,CAAC;IAIF,eAAQ,GAAwC,QAAQ,IAAI,EAAE,CAAC;IAUvF,MAAM,YAAY,GAMgE,MAAM,CAAC;IACzF,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tFlexibleNodeContent,\n\tFlexTreeNode,\n\tFlexTreeOptionalField,\n\tOptionalFieldEditBuilder,\n} from \"../../../feature-libraries/index.js\";\nimport { getTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport {\n\tcreateFieldSchema,\n\tFieldKind,\n\tnormalizeAllowedTypes,\n\tunannotateImplicitAllowedTypes,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitAnnotatedAllowedTypes,\n\ttype InsertableTreeNodeFromImplicitAllowedTypes,\n\ttype NodeSchemaMetadata,\n\ttype TreeNodeFromImplicitAllowedTypes,\n\ttype UnannotateImplicitAllowedTypes,\n} from \"../../schemaTypes.js\";\nimport {\n\tgetKernel,\n\ttype InnerNode,\n\tNodeKind,\n\ttype TreeNodeSchema,\n\t// eslint-disable-next-line import/no-deprecated\n\ttypeNameSymbol,\n\ttype TreeNode,\n\ttypeSchemaSymbol,\n\ttype Context,\n\tgetOrCreateInnerNode,\n\ttype InternalTreeNode,\n\ttype UnhydratedFlexTreeNode,\n} from \"../../core/index.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\ttype FactoryContent,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport { brand, count, type RestrictiveStringRecord } from \"../../../util/index.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"../../treeNodeValid.js\";\nimport { getUnhydratedContext } from \"../../createContext.js\";\nimport type { MapNodeCustomizableSchema, MapNodePojoEmulationSchema } from \"./mapNodeTypes.js\";\n\n/**\n * A map of string keys to tree objects.\n *\n * @privateRemarks\n * Add support for `clear` once we have established merge semantics for it.\n *\n * @sealed @public\n */\nexport interface TreeMapNode<T extends ImplicitAllowedTypes = ImplicitAllowedTypes>\n\textends ReadonlyMap<string, TreeNodeFromImplicitAllowedTypes<T>>,\n\t\tTreeNode {\n\t/**\n\t * Adds or updates an entry in the map with a specified `key` and a `value`.\n\t *\n\t * @param key - The key of the element to add to the map.\n\t * @param value - The value of the element to add to the map.\n\t *\n\t * @remarks\n\t * Setting the value at a key to `undefined` is equivalent to calling {@link TreeMapNode.delete} with that key.\n\t */\n\tset(key: string, value: InsertableTreeNodeFromImplicitAllowedTypes<T> | undefined): void;\n\n\t/**\n\t * Removes the specified element from this map by its `key`.\n\t *\n\t * @remarks\n\t * Note: unlike JavaScript's Map API, this method does not return a flag indicating whether or not the value was\n\t * deleted.\n\t *\n\t * @privateRemarks\n\t * Regarding the choice to not return a boolean: Since this data structure is distributed in nature, it isn't\n\t * possible to tell whether or not the item was deleted as a result of this method call. Returning a \"best guess\"\n\t * is more likely to create issues / promote bad usage patterns than offer useful information.\n\t *\n\t * @param key - The key of the element to remove from the map.\n\t */\n\tdelete(key: string): void;\n\n\t/**\n\t * Returns an iterable of keys in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the keys returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tkeys(): IterableIterator<string>;\n\n\t/**\n\t * Returns an iterable of values in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the values returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tvalues(): IterableIterator<TreeNodeFromImplicitAllowedTypes<T>>;\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the entries returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tentries(): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<T>]>;\n\n\t/**\n\t * Executes the provided function once per each key/value pair in this map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order in which the function is called with respect to the map's entries.\n\t * If your usage scenario depends on consistent ordering, you will need to account for this.\n\t */\n\tforEach(\n\t\tcallbackfn: (\n\t\t\tvalue: TreeNodeFromImplicitAllowedTypes<T>,\n\t\t\tkey: string,\n\t\t\tmap: ReadonlyMap<string, TreeNodeFromImplicitAllowedTypes<T>>,\n\t\t) => void,\n\t\t// Typing inherited from `ReadonlyMap`.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tthisArg?: any,\n\t): void;\n}\n\n// TreeMapNode is invariant over schema type, so for this handler to work with all schema, the only possible type for the schema is `any`.\n// This is not ideal, but no alternatives are possible.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst handler: ProxyHandler<TreeMapNode<any>> = {\n\tgetPrototypeOf: () => {\n\t\treturn Map.prototype;\n\t},\n};\n\nabstract class CustomMapNodeBase<const T extends ImplicitAllowedTypes> extends TreeNodeValid<\n\tMapNodeInsertableData<T>\n> {\n\tpublic static readonly kind = NodeKind.Map;\n\n\tpublic constructor(input?: InternalTreeNode | MapNodeInsertableData<T> | undefined) {\n\t\tsuper(input ?? []);\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<T>]> {\n\t\treturn this.entries();\n\t}\n\n\tprivate get innerNode(): InnerNode {\n\t\treturn getOrCreateInnerNode(this);\n\t}\n\n\tprivate editor(key: string): OptionalFieldEditBuilder<FlexibleNodeContent> {\n\t\tconst field = this.innerNode.getBoxed(brand(key)) as FlexTreeOptionalField;\n\t\treturn field.editor;\n\t}\n\n\tpublic delete(key: string): void {\n\t\tconst field = this.innerNode.getBoxed(brand(key));\n\t\tthis.editor(key).set(undefined, field.length === 0);\n\t}\n\tpublic *entries(): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<T>]> {\n\t\tconst node = this.innerNode;\n\t\tfor (const key of node.keys()) {\n\t\t\tyield [\n\t\t\t\tkey,\n\t\t\t\tgetTreeNodeForField(node.getBoxed(key)) as TreeNodeFromImplicitAllowedTypes<T>,\n\t\t\t];\n\t\t}\n\t}\n\tpublic get(key: string): TreeNodeFromImplicitAllowedTypes<T> {\n\t\tconst node = this.innerNode;\n\t\tconst field = node.getBoxed(brand(key));\n\t\treturn getTreeNodeForField(field) as TreeNodeFromImplicitAllowedTypes<T>;\n\t}\n\tpublic has(key: string): boolean {\n\t\treturn this.innerNode.tryGetField(brand(key)) !== undefined;\n\t}\n\tpublic keys(): IterableIterator<string> {\n\t\tconst node = this.innerNode;\n\t\treturn node.keys();\n\t}\n\tpublic set(key: string, value: InsertableTreeNodeFromImplicitAllowedTypes<T>): this {\n\t\tconst kernel = getKernel(this);\n\t\tconst node = this.innerNode;\n\t\tconst mapTree = prepareForInsertion(\n\t\t\tvalue as InsertableContent | undefined,\n\t\t\tcreateFieldSchema(FieldKind.Optional, kernel.schema.info as ImplicitAllowedTypes),\n\t\t\tnode.context,\n\t\t);\n\n\t\tconst field = node.getBoxed(brand(key));\n\n\t\tthis.editor(key).set(mapTree, field.length === 0);\n\t\treturn this;\n\t}\n\tpublic get size(): number {\n\t\treturn count(this.innerNode.keys());\n\t}\n\tpublic *values(): IterableIterator<TreeNodeFromImplicitAllowedTypes<T>> {\n\t\tfor (const [, value] of this.entries()) {\n\t\t\tyield value;\n\t\t}\n\t}\n\tpublic forEach<TThis extends TreeMapNode<T>>(\n\t\tthis: TThis,\n\t\tcallbackFn: (value: TreeNodeFromImplicitAllowedTypes<T>, key: string, map: TThis) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\tfor (const field of getOrCreateInnerNode(this).boxedIterator()) {\n\t\t\tconst node = getTreeNodeForField(field) as TreeNodeFromImplicitAllowedTypes<T>;\n\t\t\tcallbackFn.call(thisArg, node, field.key, this);\n\t\t}\n\t}\n\t// TODO: add `clear` once we have established merge semantics for it.\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.\n *\n * @param base - base schema type to extend.\n * @param useMapPrototype - should this type emulate a ES6 Map object (by faking its prototype with a proxy).\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function mapSchema<\n\tTName extends string,\n\tconst T extends ImplicitAnnotatedAllowedTypes,\n\tconst ImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\tidentifier: TName,\n\tinfo: T,\n\timplicitlyConstructable: ImplicitlyConstructable,\n\tuseMapPrototype: boolean,\n\tmetadata?: NodeSchemaMetadata<TCustomMetadata>,\n) {\n\tconst lazyChildTypes = new Lazy(() =>\n\t\tnormalizeAllowedTypes(unannotateImplicitAllowedTypes(info)),\n\t);\n\tconst lazyAllowedTypesIdentifiers = new Lazy(\n\t\t() => new Set([...lazyChildTypes.value].map((type) => type.identifier)),\n\t);\n\n\tlet unhydratedContext: Context;\n\n\tclass Schema\n\t\textends CustomMapNodeBase<UnannotateImplicitAllowedTypes<T>>\n\t\timplements TreeMapNode<UnannotateImplicitAllowedTypes<T>>\n\t{\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\tif (useMapPrototype) {\n\t\t\t\treturn new Proxy<Schema>(instance as Schema, handler as ProxyHandler<Schema>);\n\t\t\t}\n\t\t\treturn instance;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as FactoryContent, this as typeof Schema);\n\t\t}\n\n\t\tpublic static get allowedTypesIdentifiers(): ReadonlySet<string> {\n\t\t\treturn lazyAllowedTypesIdentifiers.value;\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tprotected static override oneTimeSetup<T2>(this: typeof TreeNodeValid<T2>): Context {\n\t\t\tconst schema = this as unknown as TreeNodeSchema;\n\t\t\tunhydratedContext = getUnhydratedContext(schema);\n\t\t\treturn unhydratedContext;\n\t\t}\n\n\t\tpublic static readonly identifier = identifier;\n\t\tpublic static readonly info = info;\n\t\tpublic static readonly implicitlyConstructable: ImplicitlyConstructable =\n\t\t\timplicitlyConstructable;\n\t\tpublic static get childTypes(): ReadonlySet<TreeNodeSchema> {\n\t\t\treturn lazyChildTypes.value;\n\t\t}\n\t\tpublic static readonly metadata: NodeSchemaMetadata<TCustomMetadata> = metadata ?? {};\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tpublic get [typeNameSymbol](): TName {\n\t\t\treturn identifier;\n\t\t}\n\t\tpublic get [typeSchemaSymbol](): typeof schemaErased {\n\t\t\treturn Schema.constructorCached?.constructor as unknown as typeof schemaErased;\n\t\t}\n\t}\n\tconst schemaErased: MapNodeCustomizableSchema<\n\t\tTName,\n\t\tT,\n\t\tImplicitlyConstructable,\n\t\tTCustomMetadata\n\t> &\n\t\tMapNodePojoEmulationSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> = Schema;\n\treturn schemaErased;\n}\n\n/**\n * Content which can be used to construct a Map node, explicitly or implicitly.\n * @system @public\n */\nexport type MapNodeInsertableData<T extends ImplicitAllowedTypes> =\n\t| Iterable<readonly [string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>\n\t| RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypes<T>>;\n"]}
1
+ {"version":3,"file":"mapNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/map/mapNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AAO3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,8BAA8B,CAAC;AACtE,OAAO,EACN,iBAAiB,EACjB,SAAS,EACT,qBAAqB,EACrB,8BAA8B,EAC9B,8BAA8B,GAO9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,SAAS,EAET,QAAQ;AAER,gDAAgD;AAChD,cAAc,EAEd,gBAAgB,EAEhB,oBAAoB,GAIpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gCAAgC,GAGhC,MAAM,2CAA2C,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACN,KAAK,EACL,KAAK,GAGL,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,aAAa,EAAwB,MAAM,wBAAwB,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAuF9D,0IAA0I;AAC1I,uDAAuD;AACvD,8DAA8D;AAC9D,MAAM,OAAO,GAAmC;IAC/C,cAAc,EAAE,GAAG,EAAE;QACpB,OAAO,GAAG,CAAC,SAAS,CAAC;IACtB,CAAC;CACD,CAAC;AAEF,MAAe,iBAAwD,SAAQ,aAE9E;IAGA,YAAmB,KAA+D;QACjF,KAAK,C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,cAAc,CAAC,KAAK,CAAC;QAC7B,CAAC;QACM,MAAM,KAAK,0BAA0B;YAC3C,OAAO,kBAAkB,CAAC,KAAK,CAAC;QACjC,CAAC;QAKD,gDAAgD;QAChD,IAAW,CAAC,cAAc,CAAC;YAC1B,OAAO,UAAU,CAAC;QACnB,CAAC;QACD,IAAW,CAAC,gBAAgB,CAAC;YAC5B,OAAO,MAAM,CAAC,iBAAiB,EAAE,WAA6C,CAAC;QAChF,CAAC;;IA5ByB,wBAAiB,GAAgC,SAAS,CAAC;IAQ9D,iBAAU,GAAG,UAAU,CAAC;IACxB,WAAI,GAAG,IAAI,CAAC;IACZ,8BAAuB,GAC7C,uBAAuB,CAAC;IAOF,eAAQ,GAAwC,QAAQ,IAAI,EAAE,CAAC;IAC/D,wBAAiB,GACvC,iBAAiB,CAAC;IAUpB,MAAM,YAAY,GAMgE,MAAM,CAAC;IACzF,OAAO,YAAY,CAAC;AACrB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { Lazy } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tFlexibleNodeContent,\n\tFlexTreeNode,\n\tFlexTreeOptionalField,\n\tOptionalFieldEditBuilder,\n} from \"../../../feature-libraries/index.js\";\nimport { tryGetTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport {\n\tcreateFieldSchema,\n\tFieldKind,\n\tnormalizeAllowedTypes,\n\tnormalizeAnnotatedAllowedTypes,\n\tunannotateImplicitAllowedTypes,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitAnnotatedAllowedTypes,\n\ttype InsertableTreeNodeFromImplicitAllowedTypes,\n\ttype NodeSchemaMetadata,\n\ttype TreeNodeFromImplicitAllowedTypes,\n\ttype UnannotateImplicitAllowedTypes,\n} from \"../../schemaTypes.js\";\nimport {\n\tgetKernel,\n\ttype InnerNode,\n\tNodeKind,\n\ttype TreeNodeSchema,\n\t// eslint-disable-next-line import/no-deprecated\n\ttypeNameSymbol,\n\ttype TreeNode,\n\ttypeSchemaSymbol,\n\ttype Context,\n\tgetOrCreateInnerNode,\n\ttype InternalTreeNode,\n\ttype UnhydratedFlexTreeNode,\n\ttype NormalizedAnnotatedAllowedTypes,\n} from \"../../core/index.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\ttype FactoryContent,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport {\n\tbrand,\n\tcount,\n\ttype JsonCompatibleReadOnlyObject,\n\ttype RestrictiveStringRecord,\n} from \"../../../util/index.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"../../treeNodeValid.js\";\nimport { getUnhydratedContext } from \"../../createContext.js\";\nimport type { MapNodeCustomizableSchema, MapNodePojoEmulationSchema } from \"./mapNodeTypes.js\";\n\n/**\n * A map of string keys to tree objects.\n *\n * @privateRemarks\n * Add support for `clear` once we have established merge semantics for it.\n *\n * @sealed @public\n */\nexport interface TreeMapNode<T extends ImplicitAllowedTypes = ImplicitAllowedTypes>\n\textends ReadonlyMap<string, TreeNodeFromImplicitAllowedTypes<T>>,\n\t\tTreeNode {\n\t/**\n\t * Adds or updates an entry in the map with a specified `key` and a `value`.\n\t *\n\t * @param key - The key of the element to add to the map.\n\t * @param value - The value of the element to add to the map.\n\t *\n\t * @remarks\n\t * Setting the value at a key to `undefined` is equivalent to calling {@link TreeMapNode.delete} with that key.\n\t */\n\tset(key: string, value: InsertableTreeNodeFromImplicitAllowedTypes<T> | undefined): void;\n\n\t/**\n\t * Removes the specified element from this map by its `key`.\n\t *\n\t * @remarks\n\t * Note: unlike JavaScript's Map API, this method does not return a flag indicating whether or not the value was\n\t * deleted.\n\t *\n\t * @privateRemarks\n\t * Regarding the choice to not return a boolean: Since this data structure is distributed in nature, it isn't\n\t * possible to tell whether or not the item was deleted as a result of this method call. Returning a \"best guess\"\n\t * is more likely to create issues / promote bad usage patterns than offer useful information.\n\t *\n\t * @param key - The key of the element to remove from the map.\n\t */\n\tdelete(key: string): void;\n\n\t/**\n\t * Returns an iterable of keys in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the keys returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tkeys(): IterableIterator<string>;\n\n\t/**\n\t * Returns an iterable of values in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the values returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tvalues(): IterableIterator<TreeNodeFromImplicitAllowedTypes<T>>;\n\n\t/**\n\t * Returns an iterable of key, value pairs for every entry in the map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order of the entries returned.\n\t * If your usage scenario depends on consistent ordering, you will need to sort these yourself.\n\t */\n\tentries(): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<T>]>;\n\n\t/**\n\t * Executes the provided function once per each key/value pair in this map.\n\t *\n\t * @remarks\n\t * Note: no guarantees are made regarding the order in which the function is called with respect to the map's entries.\n\t * If your usage scenario depends on consistent ordering, you will need to account for this.\n\t */\n\tforEach(\n\t\tcallbackfn: (\n\t\t\tvalue: TreeNodeFromImplicitAllowedTypes<T>,\n\t\t\tkey: string,\n\t\t\tmap: ReadonlyMap<string, TreeNodeFromImplicitAllowedTypes<T>>,\n\t\t) => void,\n\t\t// Typing inherited from `ReadonlyMap`.\n\t\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\t\tthisArg?: any,\n\t): void;\n}\n\n// TreeMapNode is invariant over schema type, so for this handler to work with all schema, the only possible type for the schema is `any`.\n// This is not ideal, but no alternatives are possible.\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst handler: ProxyHandler<TreeMapNode<any>> = {\n\tgetPrototypeOf: () => {\n\t\treturn Map.prototype;\n\t},\n};\n\nabstract class CustomMapNodeBase<const T extends ImplicitAllowedTypes> extends TreeNodeValid<\n\tMapNodeInsertableData<T>\n> {\n\tpublic static readonly kind = NodeKind.Map;\n\n\tpublic constructor(input?: InternalTreeNode | MapNodeInsertableData<T> | undefined) {\n\t\tsuper(input ?? []);\n\t}\n\n\tpublic [Symbol.iterator](): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<T>]> {\n\t\treturn this.entries();\n\t}\n\n\tprivate get innerNode(): InnerNode {\n\t\treturn getOrCreateInnerNode(this);\n\t}\n\n\tprivate editor(key: string): OptionalFieldEditBuilder<FlexibleNodeContent> {\n\t\tconst field = this.innerNode.getBoxed(brand(key)) as FlexTreeOptionalField;\n\t\treturn field.editor;\n\t}\n\n\tpublic delete(key: string): void {\n\t\tconst field = this.innerNode.getBoxed(brand(key));\n\t\tthis.editor(key).set(undefined, field.length === 0);\n\t}\n\tpublic *entries(): IterableIterator<[string, TreeNodeFromImplicitAllowedTypes<T>]> {\n\t\tconst node = this.innerNode;\n\t\tfor (const key of node.keys()) {\n\t\t\tyield [\n\t\t\t\tkey,\n\t\t\t\ttryGetTreeNodeForField(node.getBoxed(key)) as TreeNodeFromImplicitAllowedTypes<T>,\n\t\t\t];\n\t\t}\n\t}\n\tpublic get(key: string): TreeNodeFromImplicitAllowedTypes<T> {\n\t\tconst node = this.innerNode;\n\t\tconst field = node.getBoxed(brand(key));\n\t\treturn tryGetTreeNodeForField(field) as TreeNodeFromImplicitAllowedTypes<T>;\n\t}\n\tpublic has(key: string): boolean {\n\t\treturn this.innerNode.tryGetField(brand(key)) !== undefined;\n\t}\n\tpublic keys(): IterableIterator<string> {\n\t\tconst node = this.innerNode;\n\t\treturn node.keys();\n\t}\n\tpublic set(key: string, value: InsertableTreeNodeFromImplicitAllowedTypes<T>): this {\n\t\tconst kernel = getKernel(this);\n\t\tconst node = this.innerNode;\n\t\tconst mapTree = prepareForInsertion(\n\t\t\tvalue as InsertableContent | undefined,\n\t\t\tcreateFieldSchema(FieldKind.Optional, kernel.schema.info as ImplicitAllowedTypes),\n\t\t\tnode.context,\n\t\t);\n\n\t\tconst field = node.getBoxed(brand(key));\n\n\t\tthis.editor(key).set(mapTree, field.length === 0);\n\t\treturn this;\n\t}\n\tpublic get size(): number {\n\t\treturn count(this.innerNode.keys());\n\t}\n\tpublic *values(): IterableIterator<TreeNodeFromImplicitAllowedTypes<T>> {\n\t\tfor (const [, value] of this.entries()) {\n\t\t\tyield value;\n\t\t}\n\t}\n\tpublic forEach<TThis extends TreeMapNode<T>>(\n\t\tthis: TThis,\n\t\tcallbackFn: (value: TreeNodeFromImplicitAllowedTypes<T>, key: string, map: TThis) => void,\n\t\tthisArg?: unknown,\n\t): void {\n\t\tfor (const field of getOrCreateInnerNode(this)) {\n\t\t\tconst node = tryGetTreeNodeForField(field) as TreeNodeFromImplicitAllowedTypes<T>;\n\t\t\tcallbackFn.call(thisArg, node, field.key, this);\n\t\t}\n\t}\n\t// TODO: add `clear` once we have established merge semantics for it.\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link (TreeArrayNode:interface)}.\n *\n * @param base - base schema type to extend.\n * @param useMapPrototype - should this type emulate a ES6 Map object (by faking its prototype with a proxy).\n * @param persistedMetadata - Optional persisted metadata for the object node schema.\n */\n// eslint-disable-next-line @typescript-eslint/explicit-function-return-type\nexport function mapSchema<\n\tTName extends string,\n\tconst T extends ImplicitAnnotatedAllowedTypes,\n\tconst ImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\tidentifier: TName,\n\tinfo: T,\n\timplicitlyConstructable: ImplicitlyConstructable,\n\tuseMapPrototype: boolean,\n\tmetadata?: NodeSchemaMetadata<TCustomMetadata>,\n\tpersistedMetadata?: JsonCompatibleReadOnlyObject | undefined,\n) {\n\tconst lazyChildTypes = new Lazy(() =>\n\t\tnormalizeAllowedTypes(unannotateImplicitAllowedTypes(info)),\n\t);\n\tconst lazyAnnotatedTypes = new Lazy(() => [normalizeAnnotatedAllowedTypes(info)]);\n\tconst lazyAllowedTypesIdentifiers = new Lazy(\n\t\t() => new Set([...lazyChildTypes.value].map((type) => type.identifier)),\n\t);\n\n\tlet unhydratedContext: Context;\n\n\tclass Schema\n\t\textends CustomMapNodeBase<UnannotateImplicitAllowedTypes<T>>\n\t\timplements TreeMapNode<UnannotateImplicitAllowedTypes<T>>\n\t{\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\tif (useMapPrototype) {\n\t\t\t\treturn new Proxy<Schema>(instance as Schema, handler as ProxyHandler<Schema>);\n\t\t\t}\n\t\t\treturn instance;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as FactoryContent, this as typeof Schema);\n\t\t}\n\n\t\tpublic static get allowedTypesIdentifiers(): ReadonlySet<string> {\n\t\t\treturn lazyAllowedTypesIdentifiers.value;\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tprotected static override oneTimeSetup<T2>(this: typeof TreeNodeValid<T2>): Context {\n\t\t\tconst schema = this as unknown as TreeNodeSchema;\n\t\t\tunhydratedContext = getUnhydratedContext(schema);\n\t\t\treturn unhydratedContext;\n\t\t}\n\n\t\tpublic static readonly identifier = identifier;\n\t\tpublic static readonly info = info;\n\t\tpublic static readonly implicitlyConstructable: ImplicitlyConstructable =\n\t\t\timplicitlyConstructable;\n\t\tpublic static get childTypes(): ReadonlySet<TreeNodeSchema> {\n\t\t\treturn lazyChildTypes.value;\n\t\t}\n\t\tpublic static get childAnnotatedAllowedTypes(): readonly NormalizedAnnotatedAllowedTypes[] {\n\t\t\treturn lazyAnnotatedTypes.value;\n\t\t}\n\t\tpublic static readonly metadata: NodeSchemaMetadata<TCustomMetadata> = metadata ?? {};\n\t\tpublic static readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined =\n\t\t\tpersistedMetadata;\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tpublic get [typeNameSymbol](): TName {\n\t\t\treturn identifier;\n\t\t}\n\t\tpublic get [typeSchemaSymbol](): typeof schemaErased {\n\t\t\treturn Schema.constructorCached?.constructor as unknown as typeof schemaErased;\n\t\t}\n\t}\n\tconst schemaErased: MapNodeCustomizableSchema<\n\t\tTName,\n\t\tT,\n\t\tImplicitlyConstructable,\n\t\tTCustomMetadata\n\t> &\n\t\tMapNodePojoEmulationSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> = Schema;\n\treturn schemaErased;\n}\n\n/**\n * Content which can be used to construct a Map node, explicitly or implicitly.\n * @system @public\n */\nexport type MapNodeInsertableData<T extends ImplicitAllowedTypes> =\n\t| Iterable<readonly [string, InsertableTreeNodeFromImplicitAllowedTypes<T>]>\n\t| RestrictiveStringRecord<InsertableTreeNodeFromImplicitAllowedTypes<T>>;\n"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { FieldKey, SchemaPolicy } from "../../../core/index.js";
6
6
  import { type FlexTreeField } from "../../../feature-libraries/index.js";
7
- import type { RestrictiveStringRecord, FlattenKeys } from "../../../util/index.js";
7
+ import type { RestrictiveStringRecord, FlattenKeys, JsonCompatibleReadOnlyObject } from "../../../util/index.js";
8
8
  import { NodeKind, type WithType, type TreeNode } from "../../core/index.js";
9
9
  import { type ObjectNodeSchema, type ObjectNodeSchemaInternalData } from "./objectNodeTypes.js";
10
10
  import { type ImplicitFieldSchema, type TreeFieldFromImplicitField, type InsertableTreeFieldFromImplicitField, type FieldSchema, FieldKind, type NodeSchemaMetadata, type ImplicitAnnotatedFieldSchema, type UnannotateSchemaRecord } from "../../schemaTypes.js";
@@ -110,8 +110,9 @@ export declare function setField(field: FlexTreeField, simpleFieldSchema: FieldS
110
110
  *
111
111
  * @param name - Unique identifier for this schema within this factory's scope.
112
112
  * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.
113
+ * @param persistedMetadata - Optional persisted metadata for the object node schema.
113
114
  */
114
- export declare function objectSchema<TName extends string, const T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>, const ImplicitlyConstructable extends boolean, const TCustomMetadata = unknown>(identifier: TName, info: T, implicitlyConstructable: ImplicitlyConstructable, allowUnknownOptionalFields: boolean, metadata?: NodeSchemaMetadata<TCustomMetadata>): ObjectNodeSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> & ObjectNodeSchemaInternalData;
115
+ export declare function objectSchema<TName extends string, const T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>, const ImplicitlyConstructable extends boolean, const TCustomMetadata = unknown>(identifier: TName, info: T, implicitlyConstructable: ImplicitlyConstructable, allowUnknownOptionalFields: boolean, metadata?: NodeSchemaMetadata<TCustomMetadata>, persistedMetadata?: JsonCompatibleReadOnlyObject | undefined): ObjectNodeSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> & ObjectNodeSchemaInternalData;
115
116
  /**
116
117
  * Creates a policy for allowing unknown optional fields on an object node which delegates to the policy defined
117
118
  * on the object node's internal schema data.
@@ -1 +1 @@
1
- {"version":3,"file":"objectNode.d.ts","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/object/objectNode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAEN,KAAK,aAAa,EAIlB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,uBAAuB,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAEnF,OAAO,EAEN,QAAQ,EACR,KAAK,QAAQ,EAKb,KAAK,QAAQ,EAIb,MAAM,qBAAqB,CAAC;AAG7B,OAAO,EAEN,KAAK,gBAAgB,EACrB,KAAK,4BAA4B,EACjC,MAAM,sBAAsB,CAAC;AAE9B,OAAO,EAC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AAC,CAAC,CAAC,CAAC;AAEhE;;;;;;;GAOG;AACH,MAAM,MAAM,YAAY,GAAG,WAAW,CACrC,MAAM,GAAG,MAAM,EACf;IAAE,SAAS,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,WAAW,CAAA;CAAE,CAC5C,CAAC;AAkIF,wBAAgB,QAAQ,CACvB,KAAK,EAAE,aAAa,EACpB,iBAAiB,EAAE,WAAW,EAC9B,KAAK,EAAE,iBAAiB,GAAG,SAAS,GAClC,IAAI,CAmBN;AAQD;;;;;;GAMG;AACH,wBAAgB,YAAY,CAC3B,KAAK,SAAS,MAAM,EACpB,KAAK,CAAC,CAAC,SAAS,uBAAuB,CAAC,4BAA4B,CAAC,EACrE,KAAK,CAAC,uBAAuB,SAAS,OAAO,EAC7C,KAAK,CAAC,eAAe,GAAG,OAAO,EAE/B,UAAU,EAAE,KAAK,EACjB,IAAI,EAAE,CAAC,EACP,uBAAuB,EAAE,uBAAuB,EAChD,0BAA0B,EAAE,OAAO,EACnC,QAAQ,CAAC,EAAE,kBAAkB,CAAC,eAAe,CAAC,EAC9C,iBAAiB,CAAC,EAAE,4BAA4B,GAAG,SAAS,GAC1D,gBAAgB,CAAC,KAAK,EAAE,CAAC,EAAE,uBAAuB,EAAE,eAAe,CAAC,GACtE,4BAA4B,CAqK5B;AA0CD;;;GAGG;AACH,wBAAgB,gCAAgC,CAC/C,MAAM,EAAE,mBAAmB,GACzB,YAAY,CAAC,4BAA4B,CAAC,CAU5C"}
@@ -9,10 +9,10 @@ import { NodeKind,
9
9
  // eslint-disable-next-line import/no-deprecated
10
10
  typeNameSymbol, typeSchemaSymbol, getOrCreateInnerNode, } from "../../core/index.js";
11
11
  import { getUnhydratedContext } from "../../createContext.js";
12
- import { getTreeNodeForField } from "../../getTreeNodeForField.js";
12
+ import { tryGetTreeNodeForField } from "../../getTreeNodeForField.js";
13
13
  import { isObjectNodeSchema, } from "./objectNodeTypes.js";
14
14
  import { prepareForInsertion } from "../../prepareForInsertion.js";
15
- import { getStoredKey, getExplicitStoredKey, normalizeFieldSchema, FieldKind, ObjectFieldSchema, unannotateSchemaRecord, } from "../../schemaTypes.js";
15
+ import { getStoredKey, getExplicitStoredKey, normalizeFieldSchema, FieldKind, ObjectFieldSchema, } from "../../schemaTypes.js";
16
16
  import { unhydratedFlexTreeFromInsertable, } from "../../unhydratedFlexTreeFromInsertable.js";
17
17
  import { TreeNodeValid } from "../../treeNodeValid.js";
18
18
  /**
@@ -52,11 +52,11 @@ function createProxyHandler(schema, allowAdditionalProperties) {
52
52
  debugAssert(() => !flexNode.context.isDisposed() || "FlexTreeNode is disposed");
53
53
  const field = flexNode.tryGetField(fieldInfo.storedKey);
54
54
  if (field !== undefined) {
55
- return getTreeNodeForField(field);
55
+ return tryGetTreeNodeForField(field);
56
56
  }
57
57
  return undefined;
58
58
  }
59
- // POJO mode objects don't have TreeNode's build in members on their targets, so special case them:
59
+ // POJO mode objects don't have TreeNode's built in members on their targets, so special case them:
60
60
  if (propertyKey === typeSchemaSymbol) {
61
61
  return schema;
62
62
  }
@@ -105,7 +105,7 @@ function createProxyHandler(schema, allowAdditionalProperties) {
105
105
  const proxy = targetToProxy.get(target) ?? fail(0xadd /* missing proxy */);
106
106
  const field = getOrCreateInnerNode(proxy).tryGetField(fieldInfo.storedKey);
107
107
  const p = {
108
- value: field === undefined ? undefined : getTreeNodeForField(field),
108
+ value: field === undefined ? undefined : tryGetTreeNodeForField(field),
109
109
  writable: true,
110
110
  // Report empty fields as own properties so they shadow inherited properties (even when empty) to match TypeScript typing.
111
111
  // Make empty fields not enumerable so they get skipped when iterating over an object to better align with
@@ -144,16 +144,16 @@ CustomObjectNodeBase.kind = NodeKind.Object;
144
144
  *
145
145
  * @param name - Unique identifier for this schema within this factory's scope.
146
146
  * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.
147
+ * @param persistedMetadata - Optional persisted metadata for the object node schema.
147
148
  */
148
- export function objectSchema(identifier, info, implicitlyConstructable, allowUnknownOptionalFields, metadata) {
149
+ export function objectSchema(identifier, info, implicitlyConstructable, allowUnknownOptionalFields, metadata, persistedMetadata) {
149
150
  // Field set can't be modified after this since derived data is stored in maps.
150
151
  Object.freeze(info);
151
- const unannotatedInfo = unannotateSchemaRecord(info);
152
152
  // Ensure no collisions between final set of property keys, and final set of stored keys (including those
153
153
  // implicitly derived from property keys)
154
- assertUniqueKeys(identifier, unannotatedInfo);
154
+ assertUniqueKeys(identifier, info);
155
155
  // Performance optimization: cache property key => stored key and schema.
156
- const flexKeyMap = createFlexKeyMapping(unannotatedInfo);
156
+ const flexKeyMap = createFlexKeyMapping(info);
157
157
  const identifierFieldKeys = [];
158
158
  for (const item of flexKeyMap.values()) {
159
159
  if (item.schema.kind === FieldKind.Identifier) {
@@ -161,6 +161,7 @@ export function objectSchema(identifier, info, implicitlyConstructable, allowUnk
161
161
  }
162
162
  }
163
163
  const lazyChildTypes = new Lazy(() => new Set(Array.from(flexKeyMap.values(), (f) => [...f.schema.allowedTypeSet]).flat()));
164
+ const lazyAnnotatedTypes = new Lazy(() => Array.from(flexKeyMap.values(), ({ schema }) => normalizeFieldSchema(schema).annotatedAllowedTypesNormalized));
164
165
  let handler;
165
166
  let customizable;
166
167
  let unhydratedContext;
@@ -224,6 +225,9 @@ export function objectSchema(identifier, info, implicitlyConstructable, allowUnk
224
225
  static get childTypes() {
225
226
  return lazyChildTypes.value;
226
227
  }
228
+ static get childAnnotatedAllowedTypes() {
229
+ return lazyAnnotatedTypes.value;
230
+ }
227
231
  // eslint-disable-next-line import/no-deprecated
228
232
  get [typeNameSymbol]() {
229
233
  return identifier;
@@ -251,6 +255,7 @@ export function objectSchema(identifier, info, implicitlyConstructable, allowUnk
251
255
  CustomObjectNode.info = info;
252
256
  CustomObjectNode.implicitlyConstructable = implicitlyConstructable;
253
257
  CustomObjectNode.metadata = metadata ?? {};
258
+ CustomObjectNode.persistedMetadata = persistedMetadata;
254
259
  return CustomObjectNode;
255
260
  }
256
261
  const targetToProxy = new Weak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AG,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACpD,IAAI,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,UAAU,CACnB,eAAe,SAAS,gBAAgB,UAAU,6JAA6J,CAC/M,CAAC;QACH,CAAC;QACD,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC/C,MAA2B;IAE3B,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,UAAU,EAAE,EAAE;QACrB,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACpD,OAAO,CACN,YAAY,KAAK,SAAS;YAC1B,kBAAkB,CAAC,YAAY,CAAC;YAChC,YAAY,CAAC,0BAA0B,CACvC,CAAC;IACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Lazy, fail, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { FieldKey, SchemaPolicy } from \"../../../core/index.js\";\nimport {\n\tFieldKinds,\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n} from \"../../../feature-libraries/index.js\";\nimport type { RestrictiveStringRecord, FlattenKeys } from \"../../../util/index.js\";\n\nimport {\n\ttype TreeNodeSchema,\n\tNodeKind,\n\ttype WithType,\n\t// eslint-disable-next-line import/no-deprecated\n\ttypeNameSymbol,\n\ttypeSchemaSymbol,\n\ttype InternalTreeNode,\n\ttype TreeNode,\n\ttype Context,\n\ttype UnhydratedFlexTreeNode,\n\tgetOrCreateInnerNode,\n} from \"../../core/index.js\";\nimport { getUnhydratedContext } from \"../../createContext.js\";\nimport { getTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport {\n\tisObjectNodeSchema,\n\ttype ObjectNodeSchema,\n\ttype ObjectNodeSchemaInternalData,\n} from \"./objectNodeTypes.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\tgetStoredKey,\n\tgetExplicitStoredKey,\n\ttype TreeFieldFromImplicitField,\n\ttype InsertableTreeFieldFromImplicitField,\n\ttype FieldSchema,\n\tnormalizeFieldSchema,\n\tFieldKind,\n\ttype NodeSchemaMetadata,\n\ttype FieldSchemaAlpha,\n\tObjectFieldSchema,\n\ttype ImplicitAnnotatedFieldSchema,\n\tunannotateSchemaRecord,\n\ttype UnannotateSchemaRecord,\n} from \"../../schemaTypes.js\";\nimport type { SimpleObjectFieldSchema } from \"../../simpleSchema.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"../../treeNodeValid.js\";\n\n/**\n * Generates the properties for an ObjectNode from its field schema object.\n * @remarks\n * Due to {@link https://github.com/microsoft/TypeScript/issues/43826}, we can't enable implicit construction of {@link TreeNode|TreeNodes} for setters.\n * Therefore code assigning to these fields must explicitly construct nodes using the schema's constructor or create method,\n * or using some other method like {@link (TreeAlpha:interface).create}.\n * @system @public\n */\nexport type ObjectFromSchemaRecord<T extends RestrictiveStringRecord<ImplicitFieldSchema>> =\n\tRestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t\t? // eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t{}\n\t\t: {\n\t\t\t\t-readonly [Property in keyof T]: Property extends string\n\t\t\t\t\t? TreeFieldFromImplicitField<T[Property]>\n\t\t\t\t\t: unknown;\n\t\t\t};\n\n/**\n * A {@link TreeNode} which models a JavaScript object.\n * @remarks\n * Object nodes consist of a type which specifies which {@link TreeNodeSchema} they use (see {@link TreeNodeApi.schema} and {@link SchemaFactory.object}),\n * and a collections of fields, each with a distinct `key` and its own {@link FieldSchema} defining what can be placed under that key.\n *\n * All fields on an object node are exposed as own properties with string keys.\n * Non-empty fields are enumerable and empty optional fields are non-enumerable own properties with the value `undefined`.\n * No other own `own` or `enumerable` properties are included on object nodes unless the user of the node manually adds custom session only state.\n * This allows a majority of general purpose JavaScript object processing operations (like `for...in`, `Reflect.ownKeys()` and `Object.entries()`) to enumerate all the children.\n *\n * The API for fields is defined by {@link ObjectFromSchemaRecord}.\n * @public\n */\nexport type TreeObjectNode<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n\tTypeName extends string = string,\n> = TreeNode & ObjectFromSchemaRecord<T> & WithType<TypeName, NodeKind.Object, T>;\n\n/**\n * Type utility for determining if an implicit field schema is known to have a default value.\n *\n * @remarks Yields `false` when unknown.\n *\n * @privateRemarks\n * TODO: Account for field schemas with default value providers.\n * For now, this only captures field kinds that we know always have defaults - optional fields and identifier fields.\n *\n * @system @public\n */\nexport type FieldHasDefault<T extends ImplicitFieldSchema> = [T] extends [\n\tFieldSchema<FieldKind.Optional | FieldKind.Identifier>,\n]\n\t? true\n\t: false;\n\n/**\n * Helper used to produce types for:\n *\n * 1. Insertable content which can be used to construct an object node.\n * In this case, only own properties are considered.\n * This reduces the risk of incorrectly interpreting data at the cost of occasionally requiring users to convert data into a compatible format.\n *\n * 2. Insertable content which is an unhydrated object node.\n *\n * 3. Union of 1 and 2.\n *\n * @see {@link Input}\n *\n * @privateRemarks\n * TODO: consider separating these cases into different types.\n *\n * Empty objects don't get \"no excess property\" checks in literals.\n * To prevent extraneous properties in literals for the fields of an empty object from compiling, the empty case is special cased to produce `Record<string, never>`.\n * More details at {@link https://mercury.com/blog/creating-an-emptyobject-type-in-typescript}.\n *\n * Additionally when T is exactly `RestrictiveStringRecord<ImplicitFieldSchema>` produce just `never` so that it is assignable to the insertable for any given object type.\n *\n * Separating `{}` from `RestrictiveStringRecord<ImplicitFieldSchema>` is a bit messy since both extend each-other despite them being very different types.\n * A third dummy type `{ arbitraryKey: \"arbitraryValue\" }` is used to resolve this.\n *\n * @system @public\n */\nexport type InsertableObjectFromSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> = RestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t? { arbitraryKey: \"arbitraryValue\" } extends T\n\t\t? // {} case\n\t\t\tRecord<string, never>\n\t\t: // RestrictiveStringRecord<ImplicitFieldSchema> case\n\t\t\tnever\n\t: FlattenKeys<\n\t\t\t{\n\t\t\t\treadonly [Property in keyof T]?: InsertableTreeFieldFromImplicitField<\n\t\t\t\t\tT[Property & string]\n\t\t\t\t>;\n\t\t\t} & {\n\t\t\t\t// Field does not have a known default, make it required:\n\t\t\t\treadonly [Property in keyof T as FieldHasDefault<T[Property & string]> extends false\n\t\t\t\t\t? Property\n\t\t\t\t\t: never]: InsertableTreeFieldFromImplicitField<T[Property & string]>;\n\t\t\t}\n\t\t>;\n\n/**\n * Helper used to remove annotations from a schema record and produce insertable objects,\n *\n * @privateremarks\n * This calls {@link InsertableObjectFromSchemaRecord} in order to produce the insertable objects.\n *\n * @system @alpha\n */\nexport type InsertableObjectFromAnnotatedSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n> = InsertableObjectFromSchemaRecord<UnannotateSchemaRecord<T>>;\n\n/**\n * Maps from simple field keys (\"property\" keys) to information about the field.\n *\n * @remarks\n * A missing entry for a given property key indicates that no such field exists.\n * Keys with symbols are currently never used, but allowed to make lookups on non-field things\n * (returning undefined) easier.\n */\nexport type SimpleKeyMap = ReadonlyMap<\n\tstring | symbol,\n\t{ storedKey: FieldKey; schema: FieldSchema }\n>;\n\n/**\n * Caches the mappings from property keys to stored keys for the provided object field schemas in {@link simpleKeyToFlexKeyCache}.\n */\nfunction createFlexKeyMapping(fields: Record<string, ImplicitFieldSchema>): SimpleKeyMap {\n\tconst keyMap: Map<string | symbol, { storedKey: FieldKey; schema: FieldSchema }> = new Map();\n\tfor (const [propertyKey, fieldSchema] of Object.entries(fields)) {\n\t\tconst storedKey = getStoredKey(propertyKey, fieldSchema);\n\t\tkeyMap.set(propertyKey, { storedKey, schema: normalizeFieldSchema(fieldSchema) });\n\t}\n\n\treturn keyMap;\n}\n\n/**\n * Creates a proxy handler for the given schema.\n *\n * @param allowAdditionalProperties - If true, setting of unexpected properties will be forwarded to the target object.\n * Otherwise setting of unexpected properties will error.\n * TODO: consider implementing this using `Object.preventExtension` instead.\n * @param customTargetObject - Target object of the proxy.\n * If not provided `{}` is used for the target.\n */\nfunction createProxyHandler(\n\tschema: ObjectNodeSchema & ObjectNodeSchemaInternalData,\n\tallowAdditionalProperties: boolean,\n): ProxyHandler<TreeNode> {\n\t// To satisfy 'deepEquals' level scrutiny, the target of the proxy must be an object with the same\n\t// prototype as an object literal '{}'. This is because 'deepEquals' uses 'Object.getPrototypeOf'\n\t// as a way to quickly reject objects with different prototype chains.\n\t//\n\t// (Note that the prototype of an object literal appears as '[Object: null prototype] {}', not because\n\t// the prototype is null, but because the prototype object itself has a null prototype.)\n\n\t// TODO: Although the target is an object literal, it's still worthwhile to try experimenting with\n\t// a dispatch object to see if it improves performance.\n\tconst handler: ProxyHandler<TreeNode> = {\n\t\tget(target, propertyKey, proxy): unknown {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo !== undefined) {\n\t\t\t\tconst flexNode = getOrCreateInnerNode(proxy);\n\t\t\t\tdebugAssert(() => !flexNode.context.isDisposed() || \"FlexTreeNode is disposed\");\n\t\t\t\tconst field = flexNode.tryGetField(fieldInfo.storedKey);\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\treturn getTreeNodeForField(field);\n\t\t\t\t}\n\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// POJO mode objects don't have TreeNode's build in members on their targets, so special case them:\n\t\t\tif (propertyKey === typeSchemaSymbol) {\n\t\t\t\treturn schema;\n\t\t\t}\n\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\tif (propertyKey === typeNameSymbol) {\n\t\t\t\treturn schema.identifier;\n\t\t\t}\n\n\t\t\t// Pass the proxy as the receiver here, so that any methods on the prototype receive `proxy` as `this`.\n\t\t\treturn Reflect.get(target, propertyKey, proxy);\n\t\t},\n\t\tset(target, propertyKey, value: InsertableContent | undefined, proxy) {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo === undefined) {\n\t\t\t\t// Pass the proxy as the receiver here, so that setters on the prototype receive `proxy` as `this`.\n\t\t\t\treturn allowAdditionalProperties\n\t\t\t\t\t? Reflect.set(target, propertyKey, value, proxy)\n\t\t\t\t\t: false;\n\t\t\t}\n\n\t\t\tsetField(\n\t\t\t\tgetOrCreateInnerNode(proxy).getBoxed(fieldInfo.storedKey),\n\t\t\t\tfieldInfo.schema,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t\treturn true;\n\t\t},\n\t\tdeleteProperty(target, propertyKey): boolean {\n\t\t\t// TODO: supporting delete when it makes sense (custom local fields, and optional field) could be added as a feature in the future.\n\t\t\tthrow new UsageError(\n\t\t\t\t`Object nodes do not support the delete operator. Optional fields can be assigned to undefined instead.`,\n\t\t\t);\n\t\t},\n\t\thas: (target, propertyKey) => {\n\t\t\treturn (\n\t\t\t\tschema.flexKeyMap.has(propertyKey) ||\n\t\t\t\t(allowAdditionalProperties ? Reflect.has(target, propertyKey) : false)\n\t\t\t);\n\t\t},\n\t\townKeys: (target) => {\n\t\t\treturn [\n\t\t\t\t...schema.flexKeyMap.keys(),\n\t\t\t\t...(allowAdditionalProperties ? Reflect.ownKeys(target) : []),\n\t\t\t];\n\t\t},\n\t\tgetOwnPropertyDescriptor: (target, propertyKey) => {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\n\t\t\tif (fieldInfo === undefined) {\n\t\t\t\treturn allowAdditionalProperties\n\t\t\t\t\t? Reflect.getOwnPropertyDescriptor(target, propertyKey)\n\t\t\t\t\t: undefined;\n\t\t\t}\n\n\t\t\t// For some reason, the getOwnPropertyDescriptor is not passed in the receiver, so use a weak map.\n\t\t\t// If a refactoring is done to associated flex tree data with the target not the proxy, this extra map could be removed,\n\t\t\t// and the design would be more compatible with proxyless nodes.\n\t\t\tconst proxy = targetToProxy.get(target) ?? fail(0xadd /* missing proxy */);\n\t\t\tconst field = getOrCreateInnerNode(proxy).tryGetField(fieldInfo.storedKey);\n\n\t\t\tconst p: PropertyDescriptor = {\n\t\t\t\tvalue: field === undefined ? undefined : getTreeNodeForField(field),\n\t\t\t\twritable: true,\n\t\t\t\t// Report empty fields as own properties so they shadow inherited properties (even when empty) to match TypeScript typing.\n\t\t\t\t// Make empty fields not enumerable so they get skipped when iterating over an object to better align with\n\t\t\t\t// JSON and deep equals with JSON compatible object (which can't have undefined fields).\n\t\t\t\tenumerable: field !== undefined,\n\t\t\t\tconfigurable: true, // Must be 'configurable' if property is absent from proxy target.\n\t\t\t};\n\n\t\t\treturn p;\n\t\t},\n\t};\n\treturn handler;\n}\n\nexport function setField(\n\tfield: FlexTreeField,\n\tsimpleFieldSchema: FieldSchema,\n\tvalue: InsertableContent | undefined,\n): void {\n\tconst mapTree = prepareForInsertion(value, simpleFieldSchema, field.context);\n\n\tswitch (field.schema) {\n\t\tcase FieldKinds.required.identifier: {\n\t\t\tassert(mapTree !== undefined, 0xa04 /* Cannot set a required field to undefined */);\n\t\t\tconst typedField = field as FlexTreeRequiredField;\n\t\t\ttypedField.editor.set(mapTree);\n\t\t\tbreak;\n\t\t}\n\t\tcase FieldKinds.optional.identifier: {\n\t\t\tconst typedField = field as FlexTreeOptionalField;\n\t\t\ttypedField.editor.set(mapTree, typedField.length === 0);\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault:\n\t\t\tfail(0xade /* invalid FieldKind */);\n\t}\n}\n\nabstract class CustomObjectNodeBase<\n\tconst T extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> extends TreeNodeValid<InsertableObjectFromSchemaRecord<T>> {\n\tpublic static readonly kind = NodeKind.Object;\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link TreeObjectNode}.\n *\n * @param name - Unique identifier for this schema within this factory's scope.\n * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n */\nexport function objectSchema<\n\tTName extends string,\n\tconst T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n\tconst ImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\tidentifier: TName,\n\tinfo: T,\n\timplicitlyConstructable: ImplicitlyConstructable,\n\tallowUnknownOptionalFields: boolean,\n\tmetadata?: NodeSchemaMetadata<TCustomMetadata>,\n): ObjectNodeSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> &\n\tObjectNodeSchemaInternalData {\n\t// Field set can't be modified after this since derived data is stored in maps.\n\tObject.freeze(info);\n\n\tconst unannotatedInfo = unannotateSchemaRecord(info);\n\n\t// Ensure no collisions between final set of property keys, and final set of stored keys (including those\n\t// implicitly derived from property keys)\n\tassertUniqueKeys(identifier, unannotatedInfo);\n\n\t// Performance optimization: cache property key => stored key and schema.\n\tconst flexKeyMap: SimpleKeyMap = createFlexKeyMapping(unannotatedInfo);\n\n\tconst identifierFieldKeys: FieldKey[] = [];\n\tfor (const item of flexKeyMap.values()) {\n\t\tif (item.schema.kind === FieldKind.Identifier) {\n\t\t\tidentifierFieldKeys.push(item.storedKey);\n\t\t}\n\t}\n\n\tconst lazyChildTypes = new Lazy(\n\t\t() => new Set(Array.from(flexKeyMap.values(), (f) => [...f.schema.allowedTypeSet]).flat()),\n\t);\n\n\tlet handler: ProxyHandler<object>;\n\tlet customizable: boolean;\n\tlet unhydratedContext: Context;\n\n\tclass CustomObjectNode extends CustomObjectNodeBase<UnannotateSchemaRecord<T>> {\n\t\tpublic static readonly fields: ReadonlyMap<\n\t\t\tstring,\n\t\t\tFieldSchemaAlpha & SimpleObjectFieldSchema\n\t\t> = new Map(\n\t\t\tArray.from(flexKeyMap, ([key, value]) => [\n\t\t\t\tkey as string,\n\t\t\t\tnew ObjectFieldSchema(\n\t\t\t\t\tvalue.schema.kind,\n\t\t\t\t\tvalue.schema.allowedTypes,\n\t\t\t\t\t(value.schema as FieldSchemaAlpha).annotatedAllowedTypes,\n\t\t\t\t\t{\n\t\t\t\t\t\t...value.schema.props,\n\t\t\t\t\t\tkey: getStoredKey(key as string, value.schema),\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly flexKeyMap: SimpleKeyMap = flexKeyMap;\n\t\tpublic static readonly storedKeyToPropertyKey: ReadonlyMap<FieldKey, string> = new Map<\n\t\t\tFieldKey,\n\t\t\tstring\n\t\t>(\n\t\t\tArray.from(flexKeyMap, ([key, value]): [FieldKey, string] => [\n\t\t\t\tvalue.storedKey,\n\t\t\t\tkey as string,\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly identifierFieldKeys: readonly FieldKey[] = identifierFieldKeys;\n\t\tpublic static readonly allowUnknownOptionalFields: boolean = allowUnknownOptionalFields;\n\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\t// Differentiate between the following cases:\n\t\t\t//\n\t\t\t// Case 1: Direct construction (POJO emulation)\n\t\t\t//\n\t\t\t// const Foo = schemaFactory.object(\"Foo\", {bar: schemaFactory.number});\n\t\t\t//\n\t\t\t// assert.deepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t//\t\t \"Prototype chain equivalent to POJO.\");\n\t\t\t//\n\t\t\t// Case 2: Subclass construction (Customizable Object)\n\t\t\t//\n\t\t\t// \t class Foo extends schemaFactory.object(\"Foo\", {bar: schemaFactory.number}) {}\n\t\t\t//\n\t\t\t// \t assert.notDeepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t// \t \"Subclass prototype chain differs from POJO.\");\n\t\t\t//\n\t\t\t// In Case 1 (POJO emulation), the prototype chain match '{}' (proxyTarget = undefined)\n\t\t\t// In Case 2 (Customizable Object), the prototype chain include the user's subclass (proxyTarget = this)\n\n\t\t\tconst proxyTarget = customizable ? instance : {};\n\t\t\tconst proxy = new Proxy(proxyTarget, handler) as CustomObjectNode;\n\t\t\ttargetToProxy.set(proxyTarget, proxy);\n\t\t\treturn proxy;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as object, this as Output);\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tprotected static override oneTimeSetup<T2>(this: typeof TreeNodeValid<T2>): Context {\n\t\t\t// One time initialization that required knowing the most derived type (from this.constructor) and thus has to be lazy.\n\t\t\tcustomizable = (this as unknown) !== CustomObjectNode;\n\t\t\tconst schema = this as unknown as ObjectNodeSchema & ObjectNodeSchemaInternalData;\n\t\t\thandler = createProxyHandler(schema, customizable);\n\t\t\tunhydratedContext = getUnhydratedContext(schema);\n\n\t\t\t// First run, do extra validation.\n\t\t\t// TODO: provide a way for TreeConfiguration to trigger this same validation to ensure it gets run early.\n\t\t\t// Scan for shadowing inherited members which won't work, but stop scan early to allow shadowing built in (which seems to work ok).\n\t\t\t{\n\t\t\t\tlet prototype: object = this.prototype;\n\t\t\t\t// There isn't a clear cleaner way to author this loop.\n\t\t\t\twhile (prototype !== CustomObjectNode.prototype) {\n\t\t\t\t\tfor (const [key] of flexKeyMap) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t// constructor is a special case, since one is built in on the derived type, and shadowing it works fine since we only use it before fields are applied.\n\t\t\t\t\t\t\tkey !== \"constructor\" &&\n\t\t\t\t\t\t\tReflect.getOwnPropertyDescriptor(prototype, key) !== undefined\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t`Schema ${identifier} defines an inherited property \"${key.toString()}\" which shadows a field. Since fields are exposed as own properties, this shadowing will not work, and is an error.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Since this stops at CustomObjectNode, it should never see a null prototype, so this case is safe.\n\t\t\t\t\t// Additionally, if the prototype chain is ever messed up such that CustomObjectNode is not in it,\n\t\t\t\t\t// the null that would show up here does at least ensure this code throws instead of hanging.\n\t\t\t\t\tprototype = Reflect.getPrototypeOf(prototype) as object;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn unhydratedContext;\n\t\t}\n\n\t\tpublic static readonly identifier = identifier;\n\t\tpublic static readonly info = info;\n\t\tpublic static readonly implicitlyConstructable: ImplicitlyConstructable =\n\t\t\timplicitlyConstructable;\n\t\tpublic static get childTypes(): ReadonlySet<TreeNodeSchema> {\n\t\t\treturn lazyChildTypes.value;\n\t\t}\n\t\tpublic static readonly metadata: NodeSchemaMetadata<TCustomMetadata> = metadata ?? {};\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tpublic get [typeNameSymbol](): TName {\n\t\t\treturn identifier;\n\t\t}\n\t\tpublic get [typeSchemaSymbol](): Output {\n\t\t\treturn CustomObjectNode.constructorCached?.constructor as unknown as Output;\n\t\t}\n\t}\n\ttype Output = typeof CustomObjectNode &\n\t\t(new (\n\t\t\tinput: InsertableObjectFromAnnotatedSchemaRecord<T> | InternalTreeNode,\n\t\t) => TreeObjectNode<UnannotateSchemaRecord<T>, TName>);\n\treturn CustomObjectNode as Output;\n}\n\nconst targetToProxy: WeakMap<object, TreeNode> = new WeakMap();\n\n/**\n * Ensures that the set of property keys in the schema is unique.\n * Also ensure that the final set of stored keys (including those implicitly derived from property keys) is unique.\n * @throws Throws a `UsageError` if either of the key uniqueness invariants is violated.\n */\nfunction assertUniqueKeys<\n\tconst Name extends number | string,\n\tconst Fields extends RestrictiveStringRecord<ImplicitFieldSchema>,\n>(schemaName: Name, fields: Fields): void {\n\t// Verify that there are no duplicates among the explicitly specified stored keys.\n\tconst explicitStoredKeys = new Set<string>();\n\tfor (const schema of Object.values(fields)) {\n\t\tconst storedKey = getExplicitStoredKey(schema);\n\t\tif (storedKey === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (explicitStoredKeys.has(storedKey)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Duplicate stored key \"${storedKey}\" in schema \"${schemaName}\". Stored keys must be unique within an object schema.`,\n\t\t\t);\n\t\t}\n\t\texplicitStoredKeys.add(storedKey);\n\t}\n\n\t// Verify that there are no duplicates among the derived\n\t// (including those implicitly derived from property keys) stored keys.\n\tconst derivedStoredKeys = new Set<string>();\n\tfor (const [propertyKey, schema] of Object.entries(fields)) {\n\t\tconst storedKey = getStoredKey(propertyKey, schema);\n\t\tif (derivedStoredKeys.has(storedKey)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Stored key \"${storedKey}\" in schema \"${schemaName}\" conflicts with a property key of the same name, which is not overridden by a stored key. The final set of stored keys in an object schema must be unique.`,\n\t\t\t);\n\t\t}\n\t\tderivedStoredKeys.add(storedKey);\n\t}\n}\n\n/**\n * Creates a policy for allowing unknown optional fields on an object node which delegates to the policy defined\n * on the object node's internal schema data.\n */\nexport function createUnknownOptionalFieldPolicy(\n\tschema: ImplicitFieldSchema,\n): SchemaPolicy[\"allowUnknownOptionalFields\"] {\n\tconst context = getUnhydratedContext(schema);\n\treturn (identifier) => {\n\t\tconst storedSchema = context.schema.get(identifier);\n\t\treturn (\n\t\t\tstoredSchema !== undefined &&\n\t\t\tisObjectNodeSchema(storedSchema) &&\n\t\t\tstoredSchema.allowUnknownOptionalFields\n\t\t);\n\t};\n}\n"]}
1
+ {"version":3,"file":"objectNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/object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AwD;IACxD,uEAAuE;IACvE,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAU,CAAC;IAC5C,KAAK,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAC5D,MAAM,SAAS,GAAG,YAAY,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACpD,IAAI,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,UAAU,CACnB,eAAe,SAAS,gBAAgB,UAAU,6JAA6J,CAC/M,CAAC;QACH,CAAC;QACD,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;AACF,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gCAAgC,CAC/C,MAA2B;IAE3B,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,UAAU,EAAE,EAAE;QACrB,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU,CAAC,CAAC;QACpD,OAAO,CACN,YAAY,KAAK,SAAS;YAC1B,kBAAkB,CAAC,YAAY,CAAC;YAChC,YAAY,CAAC,0BAA0B,CACvC,CAAC;IACH,CAAC,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Lazy, fail, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport type { FieldKey, SchemaPolicy } from \"../../../core/index.js\";\nimport {\n\tFieldKinds,\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n} from \"../../../feature-libraries/index.js\";\nimport type {\n\tRestrictiveStringRecord,\n\tFlattenKeys,\n\tJsonCompatibleReadOnlyObject,\n} from \"../../../util/index.js\";\n\nimport {\n\ttype TreeNodeSchema,\n\tNodeKind,\n\ttype WithType,\n\t// eslint-disable-next-line import/no-deprecated\n\ttypeNameSymbol,\n\ttypeSchemaSymbol,\n\ttype InternalTreeNode,\n\ttype TreeNode,\n\ttype Context,\n\ttype UnhydratedFlexTreeNode,\n\tgetOrCreateInnerNode,\n\ttype NormalizedAnnotatedAllowedTypes,\n} from \"../../core/index.js\";\nimport { getUnhydratedContext } from \"../../createContext.js\";\nimport { tryGetTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport {\n\tisObjectNodeSchema,\n\ttype ObjectNodeSchema,\n\ttype ObjectNodeSchemaInternalData,\n} from \"./objectNodeTypes.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\tgetStoredKey,\n\tgetExplicitStoredKey,\n\ttype TreeFieldFromImplicitField,\n\ttype InsertableTreeFieldFromImplicitField,\n\ttype FieldSchema,\n\tnormalizeFieldSchema,\n\tFieldKind,\n\ttype NodeSchemaMetadata,\n\ttype FieldSchemaAlpha,\n\tObjectFieldSchema,\n\ttype ImplicitAnnotatedFieldSchema,\n\ttype UnannotateSchemaRecord,\n} from \"../../schemaTypes.js\";\nimport type { SimpleObjectFieldSchema } from \"../../simpleSchema.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"../../treeNodeValid.js\";\n\n/**\n * Generates the properties for an ObjectNode from its field schema object.\n * @remarks\n * Due to {@link https://github.com/microsoft/TypeScript/issues/43826}, we can't enable implicit construction of {@link TreeNode|TreeNodes} for setters.\n * Therefore code assigning to these fields must explicitly construct nodes using the schema's constructor or create method,\n * or using some other method like {@link (TreeAlpha:interface).create}.\n * @system @public\n */\nexport type ObjectFromSchemaRecord<T extends RestrictiveStringRecord<ImplicitFieldSchema>> =\n\tRestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t\t? // eslint-disable-next-line @typescript-eslint/ban-types\n\t\t\t{}\n\t\t: {\n\t\t\t\t-readonly [Property in keyof T]: Property extends string\n\t\t\t\t\t? TreeFieldFromImplicitField<T[Property]>\n\t\t\t\t\t: unknown;\n\t\t\t};\n\n/**\n * A {@link TreeNode} which models a JavaScript object.\n * @remarks\n * Object nodes consist of a type which specifies which {@link TreeNodeSchema} they use (see {@link TreeNodeApi.schema} and {@link SchemaFactory.object}),\n * and a collections of fields, each with a distinct `key` and its own {@link FieldSchema} defining what can be placed under that key.\n *\n * All fields on an object node are exposed as own properties with string keys.\n * Non-empty fields are enumerable and empty optional fields are non-enumerable own properties with the value `undefined`.\n * No other own `own` or `enumerable` properties are included on object nodes unless the user of the node manually adds custom session only state.\n * This allows a majority of general purpose JavaScript object processing operations (like `for...in`, `Reflect.ownKeys()` and `Object.entries()`) to enumerate all the children.\n *\n * The API for fields is defined by {@link ObjectFromSchemaRecord}.\n * @public\n */\nexport type TreeObjectNode<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n\tTypeName extends string = string,\n> = TreeNode & ObjectFromSchemaRecord<T> & WithType<TypeName, NodeKind.Object, T>;\n\n/**\n * Type utility for determining if an implicit field schema is known to have a default value.\n *\n * @remarks Yields `false` when unknown.\n *\n * @privateRemarks\n * TODO: Account for field schemas with default value providers.\n * For now, this only captures field kinds that we know always have defaults - optional fields and identifier fields.\n *\n * @system @public\n */\nexport type FieldHasDefault<T extends ImplicitFieldSchema> = [T] extends [\n\tFieldSchema<FieldKind.Optional | FieldKind.Identifier>,\n]\n\t? true\n\t: false;\n\n/**\n * Helper used to produce types for:\n *\n * 1. Insertable content which can be used to construct an object node.\n * In this case, only own properties are considered.\n * This reduces the risk of incorrectly interpreting data at the cost of occasionally requiring users to convert data into a compatible format.\n *\n * 2. Insertable content which is an unhydrated object node.\n *\n * 3. Union of 1 and 2.\n *\n * @see {@link Input}\n *\n * @privateRemarks\n * TODO: consider separating these cases into different types.\n *\n * Empty objects don't get \"no excess property\" checks in literals.\n * To prevent extraneous properties in literals for the fields of an empty object from compiling, the empty case is special cased to produce `Record<string, never>`.\n * More details at {@link https://mercury.com/blog/creating-an-emptyobject-type-in-typescript}.\n *\n * Additionally when T is exactly `RestrictiveStringRecord<ImplicitFieldSchema>` produce just `never` so that it is assignable to the insertable for any given object type.\n *\n * Separating `{}` from `RestrictiveStringRecord<ImplicitFieldSchema>` is a bit messy since both extend each-other despite them being very different types.\n * A third dummy type `{ arbitraryKey: \"arbitraryValue\" }` is used to resolve this.\n *\n * @system @public\n */\nexport type InsertableObjectFromSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> = RestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t? { arbitraryKey: \"arbitraryValue\" } extends T\n\t\t? // {} case\n\t\t\tRecord<string, never>\n\t\t: // RestrictiveStringRecord<ImplicitFieldSchema> case\n\t\t\tnever\n\t: FlattenKeys<\n\t\t\t{\n\t\t\t\treadonly [Property in keyof T]?: InsertableTreeFieldFromImplicitField<\n\t\t\t\t\tT[Property & string]\n\t\t\t\t>;\n\t\t\t} & {\n\t\t\t\t// Field does not have a known default, make it required:\n\t\t\t\treadonly [Property in keyof T as FieldHasDefault<T[Property & string]> extends false\n\t\t\t\t\t? Property\n\t\t\t\t\t: never]: InsertableTreeFieldFromImplicitField<T[Property & string]>;\n\t\t\t}\n\t\t>;\n\n/**\n * Helper used to remove annotations from a schema record and produce insertable objects,\n *\n * @privateremarks\n * This calls {@link InsertableObjectFromSchemaRecord} in order to produce the insertable objects.\n *\n * @system @alpha\n */\nexport type InsertableObjectFromAnnotatedSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n> = InsertableObjectFromSchemaRecord<UnannotateSchemaRecord<T>>;\n\n/**\n * Maps from simple field keys (\"property\" keys) to information about the field.\n *\n * @remarks\n * A missing entry for a given property key indicates that no such field exists.\n * Keys with symbols are currently never used, but allowed to make lookups on non-field things\n * (returning undefined) easier.\n */\nexport type SimpleKeyMap = ReadonlyMap<\n\tstring | symbol,\n\t{ storedKey: FieldKey; schema: FieldSchema }\n>;\n\n/**\n * Caches the mappings from property keys to stored keys for the provided object field schemas in {@link simpleKeyToFlexKeyCache}.\n */\nfunction createFlexKeyMapping(\n\tfields: Record<string, ImplicitAnnotatedFieldSchema>,\n): SimpleKeyMap {\n\tconst keyMap: Map<string | symbol, { storedKey: FieldKey; schema: FieldSchema }> = new Map();\n\tfor (const [propertyKey, fieldSchema] of Object.entries(fields)) {\n\t\tconst storedKey = getStoredKey(propertyKey, fieldSchema);\n\t\tkeyMap.set(propertyKey, { storedKey, schema: normalizeFieldSchema(fieldSchema) });\n\t}\n\n\treturn keyMap;\n}\n\n/**\n * Creates a proxy handler for the given schema.\n *\n * @param allowAdditionalProperties - If true, setting of unexpected properties will be forwarded to the target object.\n * Otherwise setting of unexpected properties will error.\n * TODO: consider implementing this using `Object.preventExtension` instead.\n * @param customTargetObject - Target object of the proxy.\n * If not provided `{}` is used for the target.\n */\nfunction createProxyHandler(\n\tschema: ObjectNodeSchema & ObjectNodeSchemaInternalData,\n\tallowAdditionalProperties: boolean,\n): ProxyHandler<TreeNode> {\n\t// To satisfy 'deepEquals' level scrutiny, the target of the proxy must be an object with the same\n\t// prototype as an object literal '{}'. This is because 'deepEquals' uses 'Object.getPrototypeOf'\n\t// as a way to quickly reject objects with different prototype chains.\n\t//\n\t// (Note that the prototype of an object literal appears as '[Object: null prototype] {}', not because\n\t// the prototype is null, but because the prototype object itself has a null prototype.)\n\n\t// TODO: Although the target is an object literal, it's still worthwhile to try experimenting with\n\t// a dispatch object to see if it improves performance.\n\tconst handler: ProxyHandler<TreeNode> = {\n\t\tget(target, propertyKey, proxy): unknown {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo !== undefined) {\n\t\t\t\tconst flexNode = getOrCreateInnerNode(proxy);\n\t\t\t\tdebugAssert(() => !flexNode.context.isDisposed() || \"FlexTreeNode is disposed\");\n\t\t\t\tconst field = flexNode.tryGetField(fieldInfo.storedKey);\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\treturn tryGetTreeNodeForField(field);\n\t\t\t\t}\n\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// POJO mode objects don't have TreeNode's built in members on their targets, so special case them:\n\t\t\tif (propertyKey === typeSchemaSymbol) {\n\t\t\t\treturn schema;\n\t\t\t}\n\t\t\t// eslint-disable-next-line import/no-deprecated\n\t\t\tif (propertyKey === typeNameSymbol) {\n\t\t\t\treturn schema.identifier;\n\t\t\t}\n\n\t\t\t// Pass the proxy as the receiver here, so that any methods on the prototype receive `proxy` as `this`.\n\t\t\treturn Reflect.get(target, propertyKey, proxy);\n\t\t},\n\t\tset(target, propertyKey, value: InsertableContent | undefined, proxy) {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo === undefined) {\n\t\t\t\t// Pass the proxy as the receiver here, so that setters on the prototype receive `proxy` as `this`.\n\t\t\t\treturn allowAdditionalProperties\n\t\t\t\t\t? Reflect.set(target, propertyKey, value, proxy)\n\t\t\t\t\t: false;\n\t\t\t}\n\n\t\t\tsetField(\n\t\t\t\tgetOrCreateInnerNode(proxy).getBoxed(fieldInfo.storedKey),\n\t\t\t\tfieldInfo.schema,\n\t\t\t\tvalue,\n\t\t\t);\n\t\t\treturn true;\n\t\t},\n\t\tdeleteProperty(target, propertyKey): boolean {\n\t\t\t// TODO: supporting delete when it makes sense (custom local fields, and optional field) could be added as a feature in the future.\n\t\t\tthrow new UsageError(\n\t\t\t\t`Object nodes do not support the delete operator. Optional fields can be assigned to undefined instead.`,\n\t\t\t);\n\t\t},\n\t\thas: (target, propertyKey) => {\n\t\t\treturn (\n\t\t\t\tschema.flexKeyMap.has(propertyKey) ||\n\t\t\t\t(allowAdditionalProperties ? Reflect.has(target, propertyKey) : false)\n\t\t\t);\n\t\t},\n\t\townKeys: (target) => {\n\t\t\treturn [\n\t\t\t\t...schema.flexKeyMap.keys(),\n\t\t\t\t...(allowAdditionalProperties ? Reflect.ownKeys(target) : []),\n\t\t\t];\n\t\t},\n\t\tgetOwnPropertyDescriptor: (target, propertyKey) => {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\n\t\t\tif (fieldInfo === undefined) {\n\t\t\t\treturn allowAdditionalProperties\n\t\t\t\t\t? Reflect.getOwnPropertyDescriptor(target, propertyKey)\n\t\t\t\t\t: undefined;\n\t\t\t}\n\n\t\t\t// For some reason, the getOwnPropertyDescriptor is not passed in the receiver, so use a weak map.\n\t\t\t// If a refactoring is done to associated flex tree data with the target not the proxy, this extra map could be removed,\n\t\t\t// and the design would be more compatible with proxyless nodes.\n\t\t\tconst proxy = targetToProxy.get(target) ?? fail(0xadd /* missing proxy */);\n\t\t\tconst field = getOrCreateInnerNode(proxy).tryGetField(fieldInfo.storedKey);\n\n\t\t\tconst p: PropertyDescriptor = {\n\t\t\t\tvalue: field === undefined ? undefined : tryGetTreeNodeForField(field),\n\t\t\t\twritable: true,\n\t\t\t\t// Report empty fields as own properties so they shadow inherited properties (even when empty) to match TypeScript typing.\n\t\t\t\t// Make empty fields not enumerable so they get skipped when iterating over an object to better align with\n\t\t\t\t// JSON and deep equals with JSON compatible object (which can't have undefined fields).\n\t\t\t\tenumerable: field !== undefined,\n\t\t\t\tconfigurable: true, // Must be 'configurable' if property is absent from proxy target.\n\t\t\t};\n\n\t\t\treturn p;\n\t\t},\n\t};\n\treturn handler;\n}\n\nexport function setField(\n\tfield: FlexTreeField,\n\tsimpleFieldSchema: FieldSchema,\n\tvalue: InsertableContent | undefined,\n): void {\n\tconst mapTree = prepareForInsertion(value, simpleFieldSchema, field.context);\n\n\tswitch (field.schema) {\n\t\tcase FieldKinds.required.identifier: {\n\t\t\tassert(mapTree !== undefined, 0xa04 /* Cannot set a required field to undefined */);\n\t\t\tconst typedField = field as FlexTreeRequiredField;\n\t\t\ttypedField.editor.set(mapTree);\n\t\t\tbreak;\n\t\t}\n\t\tcase FieldKinds.optional.identifier: {\n\t\t\tconst typedField = field as FlexTreeOptionalField;\n\t\t\ttypedField.editor.set(mapTree, typedField.length === 0);\n\t\t\tbreak;\n\t\t}\n\n\t\tdefault:\n\t\t\tfail(0xade /* invalid FieldKind */);\n\t}\n}\n\nabstract class CustomObjectNodeBase<\n\tconst T extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> extends TreeNodeValid<InsertableObjectFromSchemaRecord<T>> {\n\tpublic static readonly kind = NodeKind.Object;\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link TreeObjectNode}.\n *\n * @param name - Unique identifier for this schema within this factory's scope.\n * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n * @param persistedMetadata - Optional persisted metadata for the object node schema.\n */\nexport function objectSchema<\n\tTName extends string,\n\tconst T extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n\tconst ImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\tidentifier: TName,\n\tinfo: T,\n\timplicitlyConstructable: ImplicitlyConstructable,\n\tallowUnknownOptionalFields: boolean,\n\tmetadata?: NodeSchemaMetadata<TCustomMetadata>,\n\tpersistedMetadata?: JsonCompatibleReadOnlyObject | undefined,\n): ObjectNodeSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> &\n\tObjectNodeSchemaInternalData {\n\t// Field set can't be modified after this since derived data is stored in maps.\n\tObject.freeze(info);\n\n\t// Ensure no collisions between final set of property keys, and final set of stored keys (including those\n\t// implicitly derived from property keys)\n\tassertUniqueKeys(identifier, info);\n\n\t// Performance optimization: cache property key => stored key and schema.\n\tconst flexKeyMap: SimpleKeyMap = createFlexKeyMapping(info);\n\n\tconst identifierFieldKeys: FieldKey[] = [];\n\tfor (const item of flexKeyMap.values()) {\n\t\tif (item.schema.kind === FieldKind.Identifier) {\n\t\t\tidentifierFieldKeys.push(item.storedKey);\n\t\t}\n\t}\n\n\tconst lazyChildTypes = new Lazy(\n\t\t() => new Set(Array.from(flexKeyMap.values(), (f) => [...f.schema.allowedTypeSet]).flat()),\n\t);\n\tconst lazyAnnotatedTypes = new Lazy(() =>\n\t\tArray.from(\n\t\t\tflexKeyMap.values(),\n\t\t\t({ schema }) => normalizeFieldSchema(schema).annotatedAllowedTypesNormalized,\n\t\t),\n\t);\n\n\tlet handler: ProxyHandler<object>;\n\tlet customizable: boolean;\n\tlet unhydratedContext: Context;\n\n\tclass CustomObjectNode extends CustomObjectNodeBase<UnannotateSchemaRecord<T>> {\n\t\tpublic static readonly fields: ReadonlyMap<\n\t\t\tstring,\n\t\t\tFieldSchemaAlpha & SimpleObjectFieldSchema\n\t\t> = new Map(\n\t\t\tArray.from(flexKeyMap, ([key, value]) => [\n\t\t\t\tkey as string,\n\t\t\t\tnew ObjectFieldSchema(\n\t\t\t\t\tvalue.schema.kind,\n\t\t\t\t\tvalue.schema.allowedTypes,\n\t\t\t\t\t(value.schema as FieldSchemaAlpha).annotatedAllowedTypes,\n\t\t\t\t\t{\n\t\t\t\t\t\t...value.schema.props,\n\t\t\t\t\t\tkey: getStoredKey(key as string, value.schema),\n\t\t\t\t\t},\n\t\t\t\t),\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly flexKeyMap: SimpleKeyMap = flexKeyMap;\n\t\tpublic static readonly storedKeyToPropertyKey: ReadonlyMap<FieldKey, string> = new Map<\n\t\t\tFieldKey,\n\t\t\tstring\n\t\t>(\n\t\t\tArray.from(flexKeyMap, ([key, value]): [FieldKey, string] => [\n\t\t\t\tvalue.storedKey,\n\t\t\t\tkey as string,\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly identifierFieldKeys: readonly FieldKey[] = identifierFieldKeys;\n\t\tpublic static readonly allowUnknownOptionalFields: boolean = allowUnknownOptionalFields;\n\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\t// Differentiate between the following cases:\n\t\t\t//\n\t\t\t// Case 1: Direct construction (POJO emulation)\n\t\t\t//\n\t\t\t// const Foo = schemaFactory.object(\"Foo\", {bar: schemaFactory.number});\n\t\t\t//\n\t\t\t// assert.deepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t//\t\t \"Prototype chain equivalent to POJO.\");\n\t\t\t//\n\t\t\t// Case 2: Subclass construction (Customizable Object)\n\t\t\t//\n\t\t\t// \t class Foo extends schemaFactory.object(\"Foo\", {bar: schemaFactory.number}) {}\n\t\t\t//\n\t\t\t// \t assert.notDeepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t// \t \"Subclass prototype chain differs from POJO.\");\n\t\t\t//\n\t\t\t// In Case 1 (POJO emulation), the prototype chain match '{}' (proxyTarget = undefined)\n\t\t\t// In Case 2 (Customizable Object), the prototype chain include the user's subclass (proxyTarget = this)\n\n\t\t\tconst proxyTarget = customizable ? instance : {};\n\t\t\tconst proxy = new Proxy(proxyTarget, handler) as CustomObjectNode;\n\t\t\ttargetToProxy.set(proxyTarget, proxy);\n\t\t\treturn proxy;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as object, this as Output);\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tprotected static override oneTimeSetup<T2>(this: typeof TreeNodeValid<T2>): Context {\n\t\t\t// One time initialization that required knowing the most derived type (from this.constructor) and thus has to be lazy.\n\t\t\tcustomizable = (this as unknown) !== CustomObjectNode;\n\t\t\tconst schema = this as unknown as ObjectNodeSchema & ObjectNodeSchemaInternalData;\n\t\t\thandler = createProxyHandler(schema, customizable);\n\t\t\tunhydratedContext = getUnhydratedContext(schema);\n\n\t\t\t// First run, do extra validation.\n\t\t\t// TODO: provide a way for TreeConfiguration to trigger this same validation to ensure it gets run early.\n\t\t\t// Scan for shadowing inherited members which won't work, but stop scan early to allow shadowing built in (which seems to work ok).\n\t\t\t{\n\t\t\t\tlet prototype: object = this.prototype;\n\t\t\t\t// There isn't a clear cleaner way to author this loop.\n\t\t\t\twhile (prototype !== CustomObjectNode.prototype) {\n\t\t\t\t\tfor (const [key] of flexKeyMap) {\n\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t// constructor is a special case, since one is built in on the derived type, and shadowing it works fine since we only use it before fields are applied.\n\t\t\t\t\t\t\tkey !== \"constructor\" &&\n\t\t\t\t\t\t\tReflect.getOwnPropertyDescriptor(prototype, key) !== undefined\n\t\t\t\t\t\t) {\n\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t`Schema ${identifier} defines an inherited property \"${key.toString()}\" which shadows a field. Since fields are exposed as own properties, this shadowing will not work, and is an error.`,\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t// Since this stops at CustomObjectNode, it should never see a null prototype, so this case is safe.\n\t\t\t\t\t// Additionally, if the prototype chain is ever messed up such that CustomObjectNode is not in it,\n\t\t\t\t\t// the null that would show up here does at least ensure this code throws instead of hanging.\n\t\t\t\t\tprototype = Reflect.getPrototypeOf(prototype) as object;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\treturn unhydratedContext;\n\t\t}\n\n\t\tpublic static readonly identifier = identifier;\n\t\tpublic static readonly info = info;\n\t\tpublic static readonly implicitlyConstructable: ImplicitlyConstructable =\n\t\t\timplicitlyConstructable;\n\t\tpublic static get childTypes(): ReadonlySet<TreeNodeSchema> {\n\t\t\treturn lazyChildTypes.value;\n\t\t}\n\t\tpublic static get childAnnotatedAllowedTypes(): readonly NormalizedAnnotatedAllowedTypes[] {\n\t\t\treturn lazyAnnotatedTypes.value;\n\t\t}\n\t\tpublic static readonly metadata: NodeSchemaMetadata<TCustomMetadata> = metadata ?? {};\n\t\tpublic static readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined =\n\t\t\tpersistedMetadata;\n\n\t\t// eslint-disable-next-line import/no-deprecated\n\t\tpublic get [typeNameSymbol](): TName {\n\t\t\treturn identifier;\n\t\t}\n\t\tpublic get [typeSchemaSymbol](): Output {\n\t\t\treturn CustomObjectNode.constructorCached?.constructor as unknown as Output;\n\t\t}\n\t}\n\ttype Output = typeof CustomObjectNode &\n\t\t(new (\n\t\t\tinput: InsertableObjectFromAnnotatedSchemaRecord<T> | InternalTreeNode,\n\t\t) => TreeObjectNode<UnannotateSchemaRecord<T>, TName>);\n\treturn CustomObjectNode as Output;\n}\n\nconst targetToProxy: WeakMap<object, TreeNode> = new WeakMap();\n\n/**\n * Ensures that the set of property keys in the schema is unique.\n * Also ensure that the final set of stored keys (including those implicitly derived from property keys) is unique.\n * @throws Throws a `UsageError` if either of the key uniqueness invariants is violated.\n */\nfunction assertUniqueKeys<\n\tconst Name extends number | string,\n\tconst Fields extends RestrictiveStringRecord<ImplicitAnnotatedFieldSchema>,\n>(schemaName: Name, fields: Fields): void {\n\t// Verify that there are no duplicates among the explicitly specified stored keys.\n\tconst explicitStoredKeys = new Set<string>();\n\tfor (const schema of Object.values(fields)) {\n\t\tconst storedKey = getExplicitStoredKey(schema);\n\t\tif (storedKey === undefined) {\n\t\t\tcontinue;\n\t\t}\n\t\tif (explicitStoredKeys.has(storedKey)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Duplicate stored key \"${storedKey}\" in schema \"${schemaName}\". Stored keys must be unique within an object schema.`,\n\t\t\t);\n\t\t}\n\t\texplicitStoredKeys.add(storedKey);\n\t}\n\n\t// Verify that there are no duplicates among the derived\n\t// (including those implicitly derived from property keys) stored keys.\n\tconst derivedStoredKeys = new Set<string>();\n\tfor (const [propertyKey, schema] of Object.entries(fields)) {\n\t\tconst storedKey = getStoredKey(propertyKey, schema);\n\t\tif (derivedStoredKeys.has(storedKey)) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Stored key \"${storedKey}\" in schema \"${schemaName}\" conflicts with a property key of the same name, which is not overridden by a stored key. The final set of stored keys in an object schema must be unique.`,\n\t\t\t);\n\t\t}\n\t\tderivedStoredKeys.add(storedKey);\n\t}\n}\n\n/**\n * Creates a policy for allowing unknown optional fields on an object node which delegates to the policy defined\n * on the object node's internal schema data.\n */\nexport function createUnknownOptionalFieldPolicy(\n\tschema: ImplicitFieldSchema,\n): SchemaPolicy[\"allowUnknownOptionalFields\"] {\n\tconst context = getUnhydratedContext(schema);\n\treturn (identifier) => {\n\t\tconst storedSchema = context.schema.get(identifier);\n\t\treturn (\n\t\t\tstoredSchema !== undefined &&\n\t\t\tisObjectNodeSchema(storedSchema) &&\n\t\t\tstoredSchema.allowUnknownOptionalFields\n\t\t);\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"prepareForInsertion.d.ts","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACX,eAAe,EACf,mBAAmB,EAMnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,KAAK,eAAe,EAEpB,KAAK,8BAA8B,EAEnC,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAEN,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACN,KAAK,iBAAiB,EAEtB,MAAM,uCAAuC,CAAC;AAG/C,OAAO,EAA4B,KAAK,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAKxF;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,SAAS,iBAAiB,GAAG,SAAS,EAC5E,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,mBAAmB,EAC3B,kBAAkB,EAAE,eAAe,GACjC,GAAG,SAAS,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BAAmB,EAC3B,kBAAkB,EAAE,eAAe,GACjC,GAAG,SAAS,SAAS,GAAG,SAAS,GAAG,mBAAmB,CAOzD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,+BAA+B,CAC9C,IAAI,EAAE,SAAS,iBAAiB,EAAE,EAClC,MAAM,EAAE,oBAAoB,EAC5B,kBAAkB,EAAE,eAAe,GACjC,oBAAoB,CAmBtB;AAED;;;;;;;;GAQG;AACH,wBAAgB,8BAA8B,CAAC,GAAG,SAAS,iBAAiB,GAAG,SAAS,EACvF,IAAI,EAAE,GAAG,EACT,MAAM,EAAE,mBAAmB,EAC3B,eAAe,EAAE,eAAe,EAChC,YAAY,EAAE,8BAA8B,GAAG,SAAS,GACtD,GAAG,SAAS,SAAS,GAAG,SAAS,GAAG,mBAAmB,CAQzD;AA2DD;;;;;;;;;;;GAWG;AACH,wBAAgB,0BAA0B,CACzC,OAAO,EAAE,SAAS,sBAAsB,EAAE,EAC1C,MAAM,EAAE,mBAAmB,EAC3B,OAAO,EAAE,8BAA8B,GACrC,IAAI,CAuBN"}
@@ -38,7 +38,11 @@ export function prepareForInsertion(data, schema, destinationContext) {
38
38
  export function prepareArrayContentForInsertion(data, schema, destinationContext) {
39
39
  const mapTrees = data.map((item) => unhydratedFlexTreeFromInsertable(item, schema));
40
40
  const fieldSchema = convertField(normalizeFieldSchema(schema));
41
- validateAndPrepare(getSchemaAndPolicy(destinationContext), destinationContext.isHydrated() ? destinationContext : undefined, { kind: FieldKinds.sequence.identifier, types: fieldSchema.types }, mapTrees);
41
+ validateAndPrepare(getSchemaAndPolicy(destinationContext), destinationContext.isHydrated() ? destinationContext : undefined, {
42
+ kind: FieldKinds.sequence.identifier,
43
+ types: fieldSchema.types,
44
+ persistedMetadata: undefined,
45
+ }, mapTrees);
42
46
  return mapTrees;
43
47
  }
44
48
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"prepareForInsertion.js","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names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,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;gBACjC,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tSchemaAndPolicy,\n\tIForestSubscription,\n\tUpPath,\n\tNodeIndex,\n\tFieldKey,\n\tDetachedField,\n\tTreeFieldStoredSchema,\n} from \"../core/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tgetSchemaAndPolicy,\n\ttype FlexTreeHydratedContextMinimal,\n\tFieldKinds,\n\ttype FlexibleFieldContent,\n\ttype FlexibleNodeContent,\n} from \"../feature-libraries/index.js\";\nimport {\n\tnormalizeFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitFieldSchema,\n} from \"./schemaTypes.js\";\nimport {\n\ttype InsertableContent,\n\tunhydratedFlexTreeFromInsertable,\n} from \"./unhydratedFlexTreeFromInsertable.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { brand } from \"../util/index.js\";\nimport { getKernel, type TreeNode, type UnhydratedFlexTreeNode } from \"./core/index.js\";\nimport { debugAssert, oob } from \"@fluidframework/core-utils/internal\";\nimport { inSchemaOrThrow, isFieldInSchema } from \"../feature-libraries/index.js\";\nimport { convertField } from \"./toStoredSchema.js\";\n\n/**\n * Prepare content from a user for insertion into a tree.\n * @remarks\n * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.\n *\n * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,\n * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.\n */\nexport function prepareForInsertion<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tdestinationContext: FlexTreeContext,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\treturn prepareForInsertionContextless(\n\t\tdata,\n\t\tschema,\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t);\n}\n\n/**\n * {@link prepareForInsertion} but batched for array content.\n * @remarks\n * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).\n *\n * The next edits made to `destinationContext`'s forest must be the creation of a detached field.\n * One edit for each item in `data`, in order.\n *\n * @privateRemarks\n * This has to be done as a single operation for all items in data\n * (as opposed to mapping {@link prepareForInsertion} over the array)\n * due to how the eventing in prepareContentForHydration works.\n */\nexport function prepareArrayContentForInsertion(\n\tdata: readonly InsertableContent[],\n\tschema: ImplicitAllowedTypes,\n\tdestinationContext: FlexTreeContext,\n): FlexibleFieldContent {\n\tconst mapTrees: UnhydratedFlexTreeNode[] = data.map((item) =>\n\t\tunhydratedFlexTreeFromInsertable(item, schema),\n\t);\n\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\n\tvalidateAndPrepare(\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\t{ kind: FieldKinds.sequence.identifier, types: fieldSchema.types },\n\t\tmapTrees,\n\t);\n\n\treturn mapTrees;\n}\n\n/**\n * Split out from {@link prepareForInsertion} as to allow use without a context.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n *\n * @remarks\n * Adding this entry point is a workaround for initialize not currently having a context.\n */\nexport function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\tconst mapTree = unhydratedFlexTreeFromInsertable(data, schema);\n\n\tconst contentArray = mapTree === undefined ? [] : [mapTree];\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\tvalidateAndPrepare(schemaAndPolicy, hydratedData, fieldSchema, contentArray);\n\n\treturn mapTree;\n}\n\n/**\n * If hydrating, do a final validation against the schema and prepare the content for hydration.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n */\nfunction validateAndPrepare(\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tfieldSchema: TreeFieldStoredSchema,\n\tmapTrees: readonly UnhydratedFlexTreeNode[],\n): void {\n\tif (hydratedData !== undefined) {\n\t\t// Run `prepareContentForHydration` before walking the tree in `isFieldInSchema`.\n\t\t// This ensures that when `isFieldInSchema` requests identifiers (or any other contextual defaults),\n\t\t// they were already creating used the more specific context we have access to from `hydratedData`.\n\t\tprepareContentForHydration(mapTrees, hydratedData.checkout.forest, hydratedData);\n\t\tif (schemaAndPolicy.policy.validateSchema === true) {\n\t\t\tconst maybeError = isFieldInSchema(mapTrees, fieldSchema, schemaAndPolicy);\n\t\t\tinSchemaOrThrow(maybeError);\n\t\t}\n\t}\n}\n\n/**\n * An {@link UpPath} that is just index zero in a {@link DetachedField} which can be modified at a later time.\n */\ninterface Root extends UpPath {\n\treadonly parent: undefined;\n\tparentField: DetachedField & FieldKey;\n\treadonly parentIndex: NodeIndex & 0;\n}\n\n/**\n * The path from the included node to the root of the content tree it was inserted as part of.\n */\ninterface RelativeNodePath {\n\treadonly path: UpPath;\n\treadonly node: TreeNode;\n}\n\n/**\n * {@link RelativeNodePath}s for every {@link TreeNode} in the content tree inserted as an atomic operation.\n */\ninterface LocatedNodesBatch {\n\t/**\n\t * UpPath shared by all {@link RelativeNodePath}s in this batch corresponding to the root of the inserted content.\n\t */\n\treadonly rootPath: Root;\n\treadonly paths: RelativeNodePath[];\n}\n\n/**\n * A dummy key value used in {@link LocatedNodesBatch.rootPath} which will be replaced with the actual detached field once it is known.\n */\nconst placeholderKey: DetachedField & FieldKey = brand(\"placeholder\" as const);\n\n/**\n * Records any {@link TreeNode}s in the given `content` tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * Additionally populates any {@link UnhydratedFlexTreeField.pendingDefault}s using the provided `context`.\n *\n * @remarks If the content tree contains has any associated {@link TreeNode}s, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n *\n * Exported for testing purposes: otherwise should not be used outside this module.\n * @param content - the content subsequence to be inserted, of which might deeply contain {@link TreeNode}s which need to be hydrated.\n * @param forest - the forest the content is being inserted into.\n */\nexport function prepareContentForHydration(\n\tcontent: readonly UnhydratedFlexTreeNode[],\n\tforest: IForestSubscription,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tconst batches: LocatedNodesBatch[] = [];\n\tfor (const item of content) {\n\t\tconst batch: LocatedNodesBatch = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: placeholderKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tpaths: [],\n\t\t};\n\t\tbatches.push(batch);\n\t\twalkMapTree(\n\t\t\titem,\n\t\t\tbatch.rootPath,\n\t\t\t(p, node) => {\n\t\t\t\tbatch.paths.push({ path: p, node });\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tscheduleHydration(batches, forest);\n}\n\nfunction walkMapTree(\n\troot: UnhydratedFlexTreeNode,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tif (root.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: UnhydratedFlexTreeNode];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, root]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, node] = next;\n\t\tif (node !== undefined) {\n\t\t\tconst treeNode = node.treeNode;\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of node.allFieldsLazy) {\n\t\t\tfield.fillPendingDefaults(context);\n\t\t\tfor (const [i, child] of field.children.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Register events which will hydrate batches of nodes when they are inserted.\n * The next edits to forest must be their insertions, in order, or data corruption can occur.\n * @param locatedNodes - the nodes to register with the forest.\n * Each index in this array expects its content to be added and produce its own `afterRootFieldCreated` event.\n * If array subsequence insertion is optimized to produce a single event, this will not work correctly as is, and will need to be modified to take in a single {@link LocatedNodesBatch}.\n */\nfunction scheduleHydration(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n): void {\n\t// Only subscribe to the event if there is at least one TreeNode tree to hydrate - this is not the case when inserting an empty array [].\n\tif (locatedNodes.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Indexing is safe here because of the length check above. This assumes the array has not been modified which should be the case.\n\t\t\tconst batch = locatedNodes[i] ?? oob();\n\t\t\tdebugAssert(() => batch.rootPath.parentField === placeholderKey);\n\t\t\tbatch.rootPath.parentField = brand(fieldKey);\n\t\t\tfor (const { path, node } of batch.paths) {\n\t\t\t\tgetKernel(node).hydrate(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === locatedNodes.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
1
+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C,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC/C,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;gBACjC,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tSchemaAndPolicy,\n\tIForestSubscription,\n\tUpPath,\n\tNodeIndex,\n\tFieldKey,\n\tDetachedField,\n\tTreeFieldStoredSchema,\n} from \"../core/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tgetSchemaAndPolicy,\n\ttype FlexTreeHydratedContextMinimal,\n\tFieldKinds,\n\ttype FlexibleFieldContent,\n\ttype FlexibleNodeContent,\n} from \"../feature-libraries/index.js\";\nimport {\n\tnormalizeFieldSchema,\n\ttype ImplicitAllowedTypes,\n\ttype ImplicitFieldSchema,\n} from \"./schemaTypes.js\";\nimport {\n\ttype InsertableContent,\n\tunhydratedFlexTreeFromInsertable,\n} from \"./unhydratedFlexTreeFromInsertable.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { brand } from \"../util/index.js\";\nimport { getKernel, type TreeNode, type UnhydratedFlexTreeNode } from \"./core/index.js\";\nimport { debugAssert, oob } from \"@fluidframework/core-utils/internal\";\nimport { inSchemaOrThrow, isFieldInSchema } from \"../feature-libraries/index.js\";\nimport { convertField } from \"./toStoredSchema.js\";\n\n/**\n * Prepare content from a user for insertion into a tree.\n * @remarks\n * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.\n *\n * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,\n * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.\n */\nexport function prepareForInsertion<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tdestinationContext: FlexTreeContext,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\treturn prepareForInsertionContextless(\n\t\tdata,\n\t\tschema,\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t);\n}\n\n/**\n * {@link prepareForInsertion} but batched for array content.\n * @remarks\n * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).\n *\n * The next edits made to `destinationContext`'s forest must be the creation of a detached field.\n * One edit for each item in `data`, in order.\n *\n * @privateRemarks\n * This has to be done as a single operation for all items in data\n * (as opposed to mapping {@link prepareForInsertion} over the array)\n * due to how the eventing in prepareContentForHydration works.\n */\nexport function prepareArrayContentForInsertion(\n\tdata: readonly InsertableContent[],\n\tschema: ImplicitAllowedTypes,\n\tdestinationContext: FlexTreeContext,\n): FlexibleFieldContent {\n\tconst mapTrees: UnhydratedFlexTreeNode[] = data.map((item) =>\n\t\tunhydratedFlexTreeFromInsertable(item, schema),\n\t);\n\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\n\tvalidateAndPrepare(\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\t{\n\t\t\tkind: FieldKinds.sequence.identifier,\n\t\t\ttypes: fieldSchema.types,\n\t\t\tpersistedMetadata: undefined,\n\t\t},\n\t\tmapTrees,\n\t);\n\n\treturn mapTrees;\n}\n\n/**\n * Split out from {@link prepareForInsertion} as to allow use without a context.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n *\n * @remarks\n * Adding this entry point is a workaround for initialize not currently having a context.\n */\nexport function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\tconst mapTree = unhydratedFlexTreeFromInsertable(data, schema);\n\n\tconst contentArray = mapTree === undefined ? [] : [mapTree];\n\tconst fieldSchema = convertField(normalizeFieldSchema(schema));\n\tvalidateAndPrepare(schemaAndPolicy, hydratedData, fieldSchema, contentArray);\n\n\treturn mapTree;\n}\n\n/**\n * If hydrating, do a final validation against the schema and prepare the content for hydration.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n */\nfunction validateAndPrepare(\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tfieldSchema: TreeFieldStoredSchema,\n\tmapTrees: readonly UnhydratedFlexTreeNode[],\n): void {\n\tif (hydratedData !== undefined) {\n\t\t// Run `prepareContentForHydration` before walking the tree in `isFieldInSchema`.\n\t\t// This ensures that when `isFieldInSchema` requests identifiers (or any other contextual defaults),\n\t\t// they were already creating used the more specific context we have access to from `hydratedData`.\n\t\tprepareContentForHydration(mapTrees, hydratedData.checkout.forest, hydratedData);\n\t\tif (schemaAndPolicy.policy.validateSchema === true) {\n\t\t\tconst maybeError = isFieldInSchema(mapTrees, fieldSchema, schemaAndPolicy);\n\t\t\tinSchemaOrThrow(maybeError);\n\t\t}\n\t}\n}\n\n/**\n * An {@link UpPath} that is just index zero in a {@link DetachedField} which can be modified at a later time.\n */\ninterface Root extends UpPath {\n\treadonly parent: undefined;\n\tparentField: DetachedField & FieldKey;\n\treadonly parentIndex: NodeIndex & 0;\n}\n\n/**\n * The path from the included node to the root of the content tree it was inserted as part of.\n */\ninterface RelativeNodePath {\n\treadonly path: UpPath;\n\treadonly node: TreeNode;\n}\n\n/**\n * {@link RelativeNodePath}s for every {@link TreeNode} in the content tree inserted as an atomic operation.\n */\ninterface LocatedNodesBatch {\n\t/**\n\t * UpPath shared by all {@link RelativeNodePath}s in this batch corresponding to the root of the inserted content.\n\t */\n\treadonly rootPath: Root;\n\treadonly paths: RelativeNodePath[];\n}\n\n/**\n * A dummy key value used in {@link LocatedNodesBatch.rootPath} which will be replaced with the actual detached field once it is known.\n */\nconst placeholderKey: DetachedField & FieldKey = brand(\"placeholder\" as const);\n\n/**\n * Records any {@link TreeNode}s in the given `content` tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * Additionally populates any {@link UnhydratedFlexTreeField.pendingDefault}s using the provided `context`.\n *\n * @remarks If the content tree contains has any associated {@link TreeNode}s, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n *\n * Exported for testing purposes: otherwise should not be used outside this module.\n * @param content - the content subsequence to be inserted, of which might deeply contain {@link TreeNode}s which need to be hydrated.\n * @param forest - the forest the content is being inserted into.\n */\nexport function prepareContentForHydration(\n\tcontent: readonly UnhydratedFlexTreeNode[],\n\tforest: IForestSubscription,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tconst batches: LocatedNodesBatch[] = [];\n\tfor (const item of content) {\n\t\tconst batch: LocatedNodesBatch = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: placeholderKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tpaths: [],\n\t\t};\n\t\tbatches.push(batch);\n\t\twalkMapTree(\n\t\t\titem,\n\t\t\tbatch.rootPath,\n\t\t\t(p, node) => {\n\t\t\t\tbatch.paths.push({ path: p, node });\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tscheduleHydration(batches, forest);\n}\n\nfunction walkMapTree(\n\troot: UnhydratedFlexTreeNode,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tif (root.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: UnhydratedFlexTreeNode];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, root]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, node] = next;\n\t\tif (node !== undefined) {\n\t\t\tconst treeNode = node.treeNode;\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of node.allFieldsLazy) {\n\t\t\tfield.fillPendingDefaults(context);\n\t\t\tfor (const [i, child] of field.children.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Register events which will hydrate batches of nodes when they are inserted.\n * The next edits to forest must be their insertions, in order, or data corruption can occur.\n * @param locatedNodes - the nodes to register with the forest.\n * Each index in this array expects its content to be added and produce its own `afterRootFieldCreated` event.\n * If array subsequence insertion is optimized to produce a single event, this will not work correctly as is, and will need to be modified to take in a single {@link LocatedNodesBatch}.\n */\nfunction scheduleHydration(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n): void {\n\t// Only subscribe to the event if there is at least one TreeNode tree to hydrate - this is not the case when inserting an empty array [].\n\tif (locatedNodes.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Indexing is safe here because of the length check above. This assumes the array has not been modified which should be the case.\n\t\t\tconst batch = locatedNodes[i] ?? oob();\n\t\t\tdebugAssert(() => batch.rootPath.parentField === placeholderKey);\n\t\t\tbatch.rootPath.parentField = brand(fieldKey);\n\t\t\tfor (const { path, node } of batch.paths) {\n\t\t\t\tgetKernel(node).hydrate(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === locatedNodes.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n"]}