@fluidframework/tree 2.22.1 → 2.23.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 (427) hide show
  1. package/.vscode/extensions.json +1 -0
  2. package/CHANGELOG.md +47 -0
  3. package/api-report/tree.alpha.api.md +31 -0
  4. package/dist/alpha.d.ts +1 -0
  5. package/dist/codec/codec.js +3 -3
  6. package/dist/codec/codec.js.map +1 -1
  7. package/dist/codec/discriminatedUnions.d.ts.map +1 -1
  8. package/dist/codec/discriminatedUnions.js +1 -1
  9. package/dist/codec/discriminatedUnions.js.map +1 -1
  10. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  11. package/dist/core/schema-stored/schema.js +3 -3
  12. package/dist/core/schema-stored/schema.js.map +1 -1
  13. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  14. package/dist/core/tree/anchorSet.js +18 -13
  15. package/dist/core/tree/anchorSet.js.map +1 -1
  16. package/dist/core/tree/treeTextFormat.js +1 -1
  17. package/dist/core/tree/treeTextFormat.js.map +1 -1
  18. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  19. package/dist/feature-libraries/chunked-forest/basicChunk.js +11 -8
  20. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  21. package/dist/feature-libraries/chunked-forest/chunkTree.js +2 -2
  22. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  23. package/dist/feature-libraries/chunked-forest/chunkedForest.js +3 -3
  24. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  25. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +2 -2
  26. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  27. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  28. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +4 -3
  29. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  30. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js +2 -2
  31. package/dist/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  32. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncoding.d.ts.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js +3 -3
  34. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/emptyChunk.js +14 -14
  36. package/dist/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  37. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  38. package/dist/feature-libraries/chunked-forest/uniformChunk.js +6 -4
  39. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  40. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +1 -1
  41. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  42. package/dist/feature-libraries/default-schema/schemaChecker.js +1 -1
  43. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  44. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  45. package/dist/feature-libraries/flex-tree/lazyField.js +4 -3
  46. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  47. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  48. package/dist/feature-libraries/flex-tree/lazyNode.js +5 -4
  49. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  50. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  51. package/dist/feature-libraries/indexing/anchorTreeIndex.js +1 -1
  52. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  53. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  54. package/dist/feature-libraries/modular-schema/comparison.js +6 -4
  55. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  56. package/dist/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  57. package/dist/feature-libraries/modular-schema/isNeverTree.js +4 -4
  58. package/dist/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  59. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  60. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  61. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  62. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +10 -11
  63. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  64. package/dist/feature-libraries/node-key/mockNodeKeyManager.js +1 -1
  65. package/dist/feature-libraries/node-key/mockNodeKeyManager.js.map +1 -1
  66. package/dist/feature-libraries/object-forest/objectForest.js +1 -1
  67. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  68. package/dist/feature-libraries/schema-index/codec.js +1 -1
  69. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  70. package/dist/feature-libraries/sequence-field/compose.js +1 -1
  71. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  72. package/dist/feature-libraries/sequence-field/invert.js +1 -1
  73. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  74. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  75. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  76. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  77. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  78. package/dist/feature-libraries/sequence-field/utils.js +1 -1
  79. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  80. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  81. package/dist/feature-libraries/treeCursorUtils.js +6 -4
  82. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  83. package/dist/index.d.ts +3 -1
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +5 -1
  86. package/dist/index.js.map +1 -1
  87. package/dist/jsonDomainSchema.d.ts +113 -0
  88. package/dist/jsonDomainSchema.d.ts.map +1 -0
  89. package/dist/jsonDomainSchema.js +101 -0
  90. package/dist/jsonDomainSchema.js.map +1 -0
  91. package/dist/packageVersion.d.ts +1 -1
  92. package/dist/packageVersion.js +1 -1
  93. package/dist/packageVersion.js.map +1 -1
  94. package/dist/serializableDomainSchema.d.ts +108 -0
  95. package/dist/serializableDomainSchema.d.ts.map +1 -0
  96. package/dist/serializableDomainSchema.js +90 -0
  97. package/dist/serializableDomainSchema.js.map +1 -0
  98. package/dist/shared-tree/index.d.ts +1 -1
  99. package/dist/shared-tree/index.d.ts.map +1 -1
  100. package/dist/shared-tree/index.js.map +1 -1
  101. package/dist/shared-tree/schematizeTree.js +1 -1
  102. package/dist/shared-tree/schematizeTree.js.map +1 -1
  103. package/dist/shared-tree/sharedTree.d.ts +37 -20
  104. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  105. package/dist/shared-tree/sharedTree.js +17 -17
  106. package/dist/shared-tree/sharedTree.js.map +1 -1
  107. package/dist/shared-tree/sharedTreeChangeFamily.js +1 -1
  108. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  109. package/dist/shared-tree/treeApiAlpha.d.ts.map +1 -1
  110. package/dist/shared-tree/treeApiAlpha.js +4 -4
  111. package/dist/shared-tree/treeApiAlpha.js.map +1 -1
  112. package/dist/shared-tree/treeCheckout.js +1 -1
  113. package/dist/shared-tree/treeCheckout.js.map +1 -1
  114. package/dist/shared-tree-core/editManager.d.ts +11 -2
  115. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  116. package/dist/shared-tree-core/editManager.js +70 -34
  117. package/dist/shared-tree-core/editManager.js.map +1 -1
  118. package/dist/shared-tree-core/resubmitMachine.d.ts +2 -0
  119. package/dist/shared-tree-core/resubmitMachine.d.ts.map +1 -1
  120. package/dist/shared-tree-core/resubmitMachine.js.map +1 -1
  121. package/dist/shared-tree-core/sharedTreeCore.d.ts +10 -3
  122. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  123. package/dist/shared-tree-core/sharedTreeCore.js +42 -7
  124. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  125. package/dist/simple-tree/api/customTree.js +3 -3
  126. package/dist/simple-tree/api/customTree.js.map +1 -1
  127. package/dist/simple-tree/api/schemaCreationUtilities.js +1 -1
  128. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  129. package/dist/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
  130. package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  131. package/dist/simple-tree/api/simpleTreeIndex.js +3 -3
  132. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  133. package/dist/simple-tree/api/tree.js +1 -1
  134. package/dist/simple-tree/api/tree.js.map +1 -1
  135. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  136. package/dist/simple-tree/api/treeNodeApi.js +9 -5
  137. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  138. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  139. package/dist/simple-tree/api/verboseTree.js +5 -4
  140. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  141. package/dist/simple-tree/api/view.js +1 -1
  142. package/dist/simple-tree/api/view.js.map +1 -1
  143. package/dist/simple-tree/arrayNode.js +2 -2
  144. package/dist/simple-tree/arrayNode.js.map +1 -1
  145. package/dist/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  146. package/dist/simple-tree/core/getOrCreateNode.js +1 -1
  147. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  148. package/dist/simple-tree/core/schemaCaching.js +1 -1
  149. package/dist/simple-tree/core/schemaCaching.js.map +1 -1
  150. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  151. package/dist/simple-tree/core/treeNodeKernel.js +6 -6
  152. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  153. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  154. package/dist/simple-tree/core/unhydratedFlexTree.js +5 -5
  155. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  156. package/dist/simple-tree/objectNode.js +2 -2
  157. package/dist/simple-tree/objectNode.js.map +1 -1
  158. package/dist/simple-tree/proxies.js +1 -1
  159. package/dist/simple-tree/proxies.js.map +1 -1
  160. package/dist/simple-tree/toMapTree.js +3 -3
  161. package/dist/simple-tree/toMapTree.js.map +1 -1
  162. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  163. package/dist/simple-tree/toStoredSchema.js +2 -1
  164. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  165. package/dist/simple-tree/treeNodeValid.d.ts.map +1 -1
  166. package/dist/simple-tree/treeNodeValid.js +5 -2
  167. package/dist/simple-tree/treeNodeValid.js.map +1 -1
  168. package/dist/util/idAllocator.js +1 -1
  169. package/dist/util/idAllocator.js.map +1 -1
  170. package/dist/util/index.d.ts +2 -2
  171. package/dist/util/index.d.ts.map +1 -1
  172. package/dist/util/index.js +5 -4
  173. package/dist/util/index.js.map +1 -1
  174. package/dist/util/nestedMap.d.ts +2 -10
  175. package/dist/util/nestedMap.d.ts.map +1 -1
  176. package/dist/util/nestedMap.js +9 -28
  177. package/dist/util/nestedMap.js.map +1 -1
  178. package/dist/util/utils.d.ts +23 -6
  179. package/dist/util/utils.d.ts.map +1 -1
  180. package/dist/util/utils.js +46 -13
  181. package/dist/util/utils.js.map +1 -1
  182. package/lib/alpha.d.ts +1 -0
  183. package/lib/codec/codec.js +3 -3
  184. package/lib/codec/codec.js.map +1 -1
  185. package/lib/codec/discriminatedUnions.d.ts.map +1 -1
  186. package/lib/codec/discriminatedUnions.js +1 -1
  187. package/lib/codec/discriminatedUnions.js.map +1 -1
  188. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  189. package/lib/core/schema-stored/schema.js +3 -3
  190. package/lib/core/schema-stored/schema.js.map +1 -1
  191. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  192. package/lib/core/tree/anchorSet.js +19 -14
  193. package/lib/core/tree/anchorSet.js.map +1 -1
  194. package/lib/core/tree/treeTextFormat.js +1 -1
  195. package/lib/core/tree/treeTextFormat.js.map +1 -1
  196. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  197. package/lib/feature-libraries/chunked-forest/basicChunk.js +11 -8
  198. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  199. package/lib/feature-libraries/chunked-forest/chunkTree.js +2 -2
  200. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  201. package/lib/feature-libraries/chunked-forest/chunkedForest.js +3 -3
  202. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  203. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +2 -2
  204. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  205. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.d.ts.map +1 -1
  206. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +4 -3
  207. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  208. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js +2 -2
  209. package/lib/feature-libraries/chunked-forest/codec/nodeShape.js.map +1 -1
  210. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncoding.d.ts.map +1 -1
  211. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js +3 -3
  212. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncoding.js.map +1 -1
  213. package/lib/feature-libraries/chunked-forest/emptyChunk.js +14 -14
  214. package/lib/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  215. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  216. package/lib/feature-libraries/chunked-forest/uniformChunk.js +6 -4
  217. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  218. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +1 -1
  219. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  220. package/lib/feature-libraries/default-schema/schemaChecker.js +1 -1
  221. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  222. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  223. package/lib/feature-libraries/flex-tree/lazyField.js +4 -3
  224. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  225. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  226. package/lib/feature-libraries/flex-tree/lazyNode.js +5 -4
  227. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  228. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -1
  229. package/lib/feature-libraries/indexing/anchorTreeIndex.js +1 -1
  230. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  231. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  232. package/lib/feature-libraries/modular-schema/comparison.js +6 -4
  233. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  234. package/lib/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  235. package/lib/feature-libraries/modular-schema/isNeverTree.js +4 -4
  236. package/lib/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  237. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  238. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  239. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  240. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +11 -12
  241. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  242. package/lib/feature-libraries/node-key/mockNodeKeyManager.js +1 -1
  243. package/lib/feature-libraries/node-key/mockNodeKeyManager.js.map +1 -1
  244. package/lib/feature-libraries/object-forest/objectForest.js +1 -1
  245. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  246. package/lib/feature-libraries/schema-index/codec.js +1 -1
  247. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  248. package/lib/feature-libraries/sequence-field/compose.js +1 -1
  249. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  250. package/lib/feature-libraries/sequence-field/invert.js +1 -1
  251. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  252. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  253. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  254. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  255. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  256. package/lib/feature-libraries/sequence-field/utils.js +1 -1
  257. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  258. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  259. package/lib/feature-libraries/treeCursorUtils.js +6 -4
  260. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  261. package/lib/index.d.ts +3 -1
  262. package/lib/index.d.ts.map +1 -1
  263. package/lib/index.js +2 -0
  264. package/lib/index.js.map +1 -1
  265. package/lib/jsonDomainSchema.d.ts +113 -0
  266. package/lib/jsonDomainSchema.d.ts.map +1 -0
  267. package/lib/jsonDomainSchema.js +98 -0
  268. package/lib/jsonDomainSchema.js.map +1 -0
  269. package/lib/packageVersion.d.ts +1 -1
  270. package/lib/packageVersion.js +1 -1
  271. package/lib/packageVersion.js.map +1 -1
  272. package/lib/serializableDomainSchema.d.ts +108 -0
  273. package/lib/serializableDomainSchema.d.ts.map +1 -0
  274. package/lib/serializableDomainSchema.js +87 -0
  275. package/lib/serializableDomainSchema.js.map +1 -0
  276. package/lib/shared-tree/index.d.ts +1 -1
  277. package/lib/shared-tree/index.d.ts.map +1 -1
  278. package/lib/shared-tree/index.js.map +1 -1
  279. package/lib/shared-tree/schematizeTree.js +1 -1
  280. package/lib/shared-tree/schematizeTree.js.map +1 -1
  281. package/lib/shared-tree/sharedTree.d.ts +37 -20
  282. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  283. package/lib/shared-tree/sharedTree.js +18 -18
  284. package/lib/shared-tree/sharedTree.js.map +1 -1
  285. package/lib/shared-tree/sharedTreeChangeFamily.js +1 -1
  286. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  287. package/lib/shared-tree/treeApiAlpha.d.ts.map +1 -1
  288. package/lib/shared-tree/treeApiAlpha.js +4 -4
  289. package/lib/shared-tree/treeApiAlpha.js.map +1 -1
  290. package/lib/shared-tree/treeCheckout.js +1 -1
  291. package/lib/shared-tree/treeCheckout.js.map +1 -1
  292. package/lib/shared-tree-core/editManager.d.ts +11 -2
  293. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  294. package/lib/shared-tree-core/editManager.js +70 -34
  295. package/lib/shared-tree-core/editManager.js.map +1 -1
  296. package/lib/shared-tree-core/resubmitMachine.d.ts +2 -0
  297. package/lib/shared-tree-core/resubmitMachine.d.ts.map +1 -1
  298. package/lib/shared-tree-core/resubmitMachine.js.map +1 -1
  299. package/lib/shared-tree-core/sharedTreeCore.d.ts +10 -3
  300. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  301. package/lib/shared-tree-core/sharedTreeCore.js +42 -7
  302. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  303. package/lib/simple-tree/api/customTree.js +3 -3
  304. package/lib/simple-tree/api/customTree.js.map +1 -1
  305. package/lib/simple-tree/api/schemaCreationUtilities.js +1 -1
  306. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  307. package/lib/simple-tree/api/schemaFactoryRecursive.d.ts +1 -1
  308. package/lib/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  309. package/lib/simple-tree/api/simpleTreeIndex.js +3 -3
  310. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  311. package/lib/simple-tree/api/tree.js +1 -1
  312. package/lib/simple-tree/api/tree.js.map +1 -1
  313. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  314. package/lib/simple-tree/api/treeNodeApi.js +9 -5
  315. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  316. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  317. package/lib/simple-tree/api/verboseTree.js +5 -4
  318. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  319. package/lib/simple-tree/api/view.js +1 -1
  320. package/lib/simple-tree/api/view.js.map +1 -1
  321. package/lib/simple-tree/arrayNode.js +2 -2
  322. package/lib/simple-tree/arrayNode.js.map +1 -1
  323. package/lib/simple-tree/core/getOrCreateNode.d.ts.map +1 -1
  324. package/lib/simple-tree/core/getOrCreateNode.js +1 -1
  325. package/lib/simple-tree/core/getOrCreateNode.js.map +1 -1
  326. package/lib/simple-tree/core/schemaCaching.js +1 -1
  327. package/lib/simple-tree/core/schemaCaching.js.map +1 -1
  328. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  329. package/lib/simple-tree/core/treeNodeKernel.js +6 -6
  330. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  331. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  332. package/lib/simple-tree/core/unhydratedFlexTree.js +5 -5
  333. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  334. package/lib/simple-tree/objectNode.js +2 -2
  335. package/lib/simple-tree/objectNode.js.map +1 -1
  336. package/lib/simple-tree/proxies.js +1 -1
  337. package/lib/simple-tree/proxies.js.map +1 -1
  338. package/lib/simple-tree/toMapTree.js +3 -3
  339. package/lib/simple-tree/toMapTree.js.map +1 -1
  340. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  341. package/lib/simple-tree/toStoredSchema.js +2 -1
  342. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  343. package/lib/simple-tree/treeNodeValid.d.ts.map +1 -1
  344. package/lib/simple-tree/treeNodeValid.js +5 -2
  345. package/lib/simple-tree/treeNodeValid.js.map +1 -1
  346. package/lib/util/idAllocator.js +1 -1
  347. package/lib/util/idAllocator.js.map +1 -1
  348. package/lib/util/index.d.ts +2 -2
  349. package/lib/util/index.d.ts.map +1 -1
  350. package/lib/util/index.js +2 -2
  351. package/lib/util/index.js.map +1 -1
  352. package/lib/util/nestedMap.d.ts +2 -10
  353. package/lib/util/nestedMap.d.ts.map +1 -1
  354. package/lib/util/nestedMap.js +5 -23
  355. package/lib/util/nestedMap.js.map +1 -1
  356. package/lib/util/utils.d.ts +23 -6
  357. package/lib/util/utils.d.ts.map +1 -1
  358. package/lib/util/utils.js +42 -11
  359. package/lib/util/utils.js.map +1 -1
  360. package/package.json +22 -22
  361. package/src/codec/codec.ts +3 -3
  362. package/src/codec/discriminatedUnions.ts +2 -1
  363. package/src/core/schema-stored/schema.ts +5 -3
  364. package/src/core/tree/anchorSet.ts +37 -26
  365. package/src/core/tree/treeTextFormat.ts +1 -1
  366. package/src/feature-libraries/chunked-forest/basicChunk.ts +11 -8
  367. package/src/feature-libraries/chunked-forest/chunkTree.ts +2 -2
  368. package/src/feature-libraries/chunked-forest/chunkedForest.ts +3 -3
  369. package/src/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.ts +2 -2
  370. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +4 -3
  371. package/src/feature-libraries/chunked-forest/codec/nodeShape.ts +2 -2
  372. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncoding.ts +4 -3
  373. package/src/feature-libraries/chunked-forest/emptyChunk.ts +14 -14
  374. package/src/feature-libraries/chunked-forest/uniformChunk.ts +6 -4
  375. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +1 -1
  376. package/src/feature-libraries/default-schema/schemaChecker.ts +1 -1
  377. package/src/feature-libraries/flex-tree/lazyField.ts +6 -8
  378. package/src/feature-libraries/flex-tree/lazyNode.ts +6 -4
  379. package/src/feature-libraries/indexing/anchorTreeIndex.ts +2 -1
  380. package/src/feature-libraries/modular-schema/comparison.ts +7 -5
  381. package/src/feature-libraries/modular-schema/isNeverTree.ts +6 -4
  382. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +4 -4
  383. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +16 -12
  384. package/src/feature-libraries/node-key/mockNodeKeyManager.ts +1 -1
  385. package/src/feature-libraries/object-forest/objectForest.ts +1 -1
  386. package/src/feature-libraries/schema-index/codec.ts +1 -1
  387. package/src/feature-libraries/sequence-field/compose.ts +1 -1
  388. package/src/feature-libraries/sequence-field/invert.ts +1 -1
  389. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +1 -1
  390. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +1 -1
  391. package/src/feature-libraries/sequence-field/utils.ts +1 -1
  392. package/src/feature-libraries/treeCursorUtils.ts +6 -4
  393. package/src/index.ts +3 -1
  394. package/src/jsonDomainSchema.ts +129 -0
  395. package/src/packageVersion.ts +1 -1
  396. package/src/serializableDomainSchema.ts +121 -0
  397. package/src/shared-tree/index.ts +0 -1
  398. package/src/shared-tree/schematizeTree.ts +1 -1
  399. package/src/shared-tree/sharedTree.ts +31 -41
  400. package/src/shared-tree/sharedTreeChangeFamily.ts +1 -1
  401. package/src/shared-tree/treeApiAlpha.ts +12 -4
  402. package/src/shared-tree/treeCheckout.ts +1 -1
  403. package/src/shared-tree-core/editManager.ts +85 -47
  404. package/src/shared-tree-core/resubmitMachine.ts +2 -0
  405. package/src/shared-tree-core/sharedTreeCore.ts +62 -14
  406. package/src/simple-tree/api/customTree.ts +3 -3
  407. package/src/simple-tree/api/schemaCreationUtilities.ts +1 -1
  408. package/src/simple-tree/api/schemaFactoryRecursive.ts +1 -1
  409. package/src/simple-tree/api/simpleTreeIndex.ts +3 -3
  410. package/src/simple-tree/api/tree.ts +1 -1
  411. package/src/simple-tree/api/treeNodeApi.ts +11 -6
  412. package/src/simple-tree/api/verboseTree.ts +8 -4
  413. package/src/simple-tree/api/view.ts +1 -1
  414. package/src/simple-tree/arrayNode.ts +2 -2
  415. package/src/simple-tree/core/getOrCreateNode.ts +2 -1
  416. package/src/simple-tree/core/schemaCaching.ts +1 -1
  417. package/src/simple-tree/core/treeNodeKernel.ts +9 -6
  418. package/src/simple-tree/core/unhydratedFlexTree.ts +7 -5
  419. package/src/simple-tree/objectNode.ts +2 -2
  420. package/src/simple-tree/proxies.ts +1 -1
  421. package/src/simple-tree/toMapTree.ts +3 -3
  422. package/src/simple-tree/toStoredSchema.ts +2 -1
  423. package/src/simple-tree/treeNodeValid.ts +5 -2
  424. package/src/util/idAllocator.ts +1 -1
  425. package/src/util/index.ts +3 -2
  426. package/src/util/nestedMap.ts +9 -33
  427. package/src/util/utils.ts +52 -12
@@ -1 +1 @@
1
- {"version":3,"file":"unhydratedFlexTree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/unhydratedFlexTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGlE,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,gBAAgB,EACrB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAEhB,KAAK,sBAAsB,EAC3B,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,KAAK,EACV,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EACN,KAAK,eAAe,EACpB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EAGjB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,cAAc,EAEd,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAElB,KAAK,wBAAwB,EAE7B,MAAM,kCAAkC,CAAC;AAC1C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAE5C,UAAU,sCACT,SAAQ,wBAAwB,CAAC,gBAAgB,EAAE,CAAC;IACpD;;;;;OAKG;IACH,MAA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AM,IAAI,MAAM,CAE1B;IAEM,EAAE,CAAC,MAAM,SAAS,aAAa,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,IAAI,kBAAkB,CAAC,MAAM,CAAC;IAIlF,aAAa,IAAI,gBAAgB,CAAC,YAAY,CAAC;IAY/C,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAcvD;;;;;;;OAOG;IACH,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,QAAQ,EAAE,gBAAgB,EAAE,KAAK,IAAI,GAAG,gBAAgB,EAAE,GAAG,IAAI;IAYhF,YAAY,IAAI,WAAW;IAIlC,yCAAyC;IACzC,SAAS,CAAC,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,sBAAsB;CASxD;AAoDD,qBAAa,2BACZ,SAAQ,uBACR,YAAW,qBAAqB;IAEhC,SAAgB,MAAM,EAAE,sCAAsC,CA6B5D;IAEK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,sBAAsB,GAAG,SAAS;IAOrD,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE;IAI3E,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,gBAAgB,CAAC,sBAAsB,CAAC;CAKrE;AAkBD;;;GAGG;AACH,wBAAgB,yBAAyB,CACxC,OAAO,EAAE,OAAO,GACd,sBAAsB,GAAG,SAAS,CAEpC;AAgDD,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAM7D"}
@@ -25,7 +25,7 @@ class UnhydratedFlexTreeNode {
25
25
  return this.mapTree.type;
26
26
  }
27
27
  get storedSchema() {
28
- return this.context.schema.nodeSchema.get(this.mapTree.type) ?? (0, index_js_2.fail)("missing schema");
28
+ return (this.context.schema.nodeSchema.get(this.mapTree.type) ?? (0, index_js_2.fail)(0xb46 /* missing schema */));
29
29
  }
30
30
  get events() {
31
31
  return this._events;
@@ -117,7 +117,7 @@ class UnhydratedFlexTreeNode {
117
117
  get anchorNode() {
118
118
  // This API is relevant to `LazyTreeNode`s, but not `UnhydratedFlexTreeNode`s.
119
119
  // TODO: Refactor the FlexTreeNode interface so that stubbing this out isn't necessary.
120
- return (0, index_js_2.fail)("UnhydratedFlexTreeNode does not implement anchorNode");
120
+ return (0, index_js_2.fail)(0xb47 /* UnhydratedFlexTreeNode does not implement anchorNode */);
121
121
  }
122
122
  walkTree() {
123
123
  for (const [key, mapTrees] of this.mapTree.fields) {
@@ -185,10 +185,10 @@ const unparentedLocation = {
185
185
  },
186
186
  schema: (0, index_js_2.brand)(index_js_1.forbiddenFieldKindIdentifier),
187
187
  get context() {
188
- return (0, index_js_2.fail)("unsupported");
188
+ return (0, index_js_2.fail)(0xb48 /* unsupported */);
189
189
  },
190
190
  getFieldPath() {
191
- (0, index_js_2.fail)("unsupported");
191
+ (0, index_js_2.fail)(0xb49 /* unsupported */);
192
192
  },
193
193
  },
194
194
  index: -1,
@@ -353,7 +353,7 @@ class UnhydratedTreeSequenceField extends UnhydratedFlexTreeField {
353
353
  this.edit((mapTrees) => {
354
354
  removed = mapTrees.splice(index, count);
355
355
  });
356
- return removed ?? (0, index_js_2.fail)("Expected removed to be set by edit");
356
+ return removed ?? (0, index_js_2.fail)(0xb4a /* Expected removed to be set by edit */);
357
357
  },
358
358
  };
359
359
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unhydratedFlexTree.js","sourceRoot":"","sources":["../../../src/simple-tree/core/unhydratedFlexTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,kEAAkE;AAClE,+DAA6D;AAE7D,uEAAsE;AAEtE,kDAgB6B;AAC7B,kDAA4E;AAC5E,+DAiB0C;AAsB1C;;;;;;;GAOG;AACH,MAAa,sBAAsB;IAClC,IAAW,MAAM;QAChB,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;IAC1B,CAAC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AAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvF,CAAC;AAED,4CAA4C;AAE5C,SAAgB,qBAAqB,CAAC,OAAgB;IACrD,OAAO,IAAI,qBAAU,CACpB,GACC,OAAO,IAAI,WACZ,4EAA4E,CAC5E,CAAC;AACH,CAAC;AAND,sDAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\tEmptyKey,\n\ttype ExclusiveMapTree,\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldUpPath,\n\tforbiddenFieldKindIdentifier,\n\ttype ITreeCursorSynchronous,\n\ttype MapTree,\n\ttype SchemaPolicy,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\ttype Value,\n} from \"../../core/index.js\";\nimport { brand, fail, getOrCreate, mapIterable } from \"../../util/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tFlexTreeEntityKind,\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeSequenceField,\n\ttype FlexTreeTypedField,\n\ttype FlexTreeUnknownUnboxed,\n\tflexTreeMarker,\n\tindexForAt,\n\ttype FlexTreeHydratedContext,\n\ttype FlexFieldKind,\n\tFieldKinds,\n\ttype SequenceFieldEditBuilder,\n\tcursorForMapTreeNode,\n} from \"../../feature-libraries/index.js\";\nimport type { Context } from \"./context.js\";\n\ninterface UnhydratedTreeSequenceFieldEditBuilder\n\textends SequenceFieldEditBuilder<ExclusiveMapTree[]> {\n\t/**\n\t * Issues a change which removes `count` elements starting at the given `index`.\n\t * @param index - The index of the first removed element.\n\t * @param count - The number of elements to remove.\n\t * @returns the MapTrees that were removed\n\t */\n\tremove(index: number, count: number): ExclusiveMapTree[];\n}\n\ntype UnhydratedFlexTreeNodeEvents = Pick<AnchorEvents, \"childrenChangedAfterBatch\">;\n\n/** A node's parent field and its index in that field */\ninterface LocationInField {\n\treadonly parent: FlexTreeField;\n\treadonly index: number;\n}\n\n/**\n * An unhydrated implementation of {@link FlexTreeNode} which wraps a {@link MapTree}.\n * @remarks\n * MapTreeNodes are unconditionally cached -\n * when retrieved via {@link getOrCreateNode}, the same {@link MapTree} object will always produce the same `UnhydratedFlexTreeNode` object.\n *\n * Create a `UnhydratedFlexTreeNode` by calling {@link getOrCreate}.\n */\nexport class UnhydratedFlexTreeNode implements UnhydratedFlexTreeNode {\n\tpublic get schema(): TreeNodeSchemaIdentifier {\n\t\treturn this.mapTree.type;\n\t}\n\n\tpublic get storedSchema(): TreeNodeStoredSchema {\n\t\treturn this.context.schema.nodeSchema.get(this.mapTree.type) ?? fail(\"missing schema\");\n\t}\n\n\tpublic readonly [flexTreeMarker] = FlexTreeEntityKind.Node as const;\n\n\tprivate readonly _events = createEmitter<UnhydratedFlexTreeNodeEvents>();\n\tpublic get events(): Listenable<UnhydratedFlexTreeNodeEvents> {\n\t\treturn this._events;\n\t}\n\n\t/**\n\t * Create a {@link UnhydratedFlexTreeNode} that wraps the given {@link MapTree}, or get the node that already exists for that {@link MapTree} if there is one.\n\t * @param nodeSchema - the {@link FlexTreeNodeSchema | schema} that the node conforms to\n\t * @param mapTree - the {@link MapTree} containing the data for this node.\n\t * @remarks It must conform to the `nodeSchema`.\n\t */\n\tpublic static getOrCreate(\n\t\tcontext: Context,\n\t\tmapTree: ExclusiveMapTree,\n\t): UnhydratedFlexTreeNode {\n\t\treturn nodeCache.get(mapTree) ?? new UnhydratedFlexTreeNode(context, mapTree, undefined);\n\t}\n\n\tpublic get context(): FlexTreeContext {\n\t\treturn this.simpleContext.flexContext;\n\t}\n\n\t/**\n\t * Create a new UnhydratedFlexTreeNode.\n\t * @param location - the parentage of this node, if it is being created underneath an existing node and field, or undefined if not\n\t * @remarks This class (and its subclasses) should not be directly constructed outside of this module.\n\t * Instead, use {@link getOrCreateNode} to create a UnhydratedFlexTreeNode from a {@link MapTree}.\n\t * A `UnhydratedFlexTreeNode` may never be constructed more than once for the same {@link MapTree} object.\n\t * Instead, it should always be acquired via {@link getOrCreateNode}.\n\t */\n\tpublic constructor(\n\t\tpublic readonly simpleContext: Context,\n\t\t/** The underlying {@link MapTree} that this `UnhydratedFlexTreeNode` reads its data from */\n\t\tpublic readonly mapTree: ExclusiveMapTree,\n\t\tprivate location = unparentedLocation,\n\t) {\n\t\tassert(!nodeCache.has(mapTree), 0x98b /* A node already exists for the given MapTree */);\n\t\tnodeCache.set(mapTree, this);\n\n\t\t// Fully demand the tree to ensure that parent pointers are present and accurate on all nodes.\n\t\t// When a UnhydratedFlexTreeNode is constructed, its MapTree may contain nodes (anywhere below) that map (via the `nodeCache`) to pre-existing UnhydratedFlexTreeNodes.\n\t\t// Put another way, for a given MapTree, some ancestor UnhydratedFlexTreeNode can be created after any number of its descendant UnhydratedFlexTreeNodes already exist.\n\t\t// In such a case, the spine of nodes between the descendant and ancestor need to exist in order for the ancestor to be able to walk upwards via the `parentField` property.\n\t\t// This needs to happen for all UnhydratedFlexTreeNodes that are descendants of the ancestor UnhydratedFlexTreeNode.\n\t\t// Demanding the entire tree is overkill to solve this problem since not all descendant MapTree nodes will have corresponding UnhydratedFlexTreeNodes.\n\t\t// However, demanding the full tree also lets us eagerly validate that there are no duplicate MapTrees (i.e. same MapTree object) anywhere in the tree.\n\t\tthis.walkTree();\n\t}\n\n\tpublic get type(): TreeNodeSchemaIdentifier {\n\t\treturn this.mapTree.type;\n\t}\n\n\t/**\n\t * Set this node's parentage (see {@link FlexTreeNode.parentField}).\n\t * @remarks The node may be given a parent if it has none, or may have its parent removed (by passing `undefined`).\n\t * However, a node with a parent may not be directly re-assigned a different parent.\n\t * That likely indicates either an attempted multi-parenting or an attempt to \"move\" the node, neither of which are supported.\n\t * Removing a node's parent twice in a row is also not supported, as it likely indicates a bug.\n\t */\n\tpublic adoptBy(parent: undefined): void;\n\tpublic adoptBy(parent: UnhydratedFlexTreeField, index: number): void;\n\tpublic adoptBy(parent: UnhydratedFlexTreeField | undefined, index?: number): void {\n\t\tif (parent !== undefined) {\n\t\t\tassert(\n\t\t\t\tthis.location === unparentedLocation,\n\t\t\t\t0x98c /* Node may not be adopted if it already has a parent */,\n\t\t\t);\n\t\t\tassert(index !== undefined, 0xa08 /* Expected index */);\n\t\t\tthis.location = { parent, index };\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tthis.location !== unparentedLocation,\n\t\t\t\t0xa09 /* Node may not be un-adopted if it does not have a parent */,\n\t\t\t);\n\t\t\tthis.location = unparentedLocation;\n\t\t}\n\t}\n\n\t/**\n\t * The field this tree is in, and the index within that field.\n\t * @remarks If this node is unparented, this method will return the special {@link unparentedLocation} as the parent.\n\t */\n\tpublic get parentField(): LocationInField {\n\t\treturn this.location;\n\t}\n\n\tpublic borrowCursor(): ITreeCursorSynchronous {\n\t\treturn cursorForMapTreeNode(this.mapTree);\n\t}\n\n\tpublic tryGetField(key: FieldKey): UnhydratedFlexTreeField | undefined {\n\t\tconst field = this.mapTree.fields.get(key);\n\t\t// Only return the field if it is not empty, in order to fulfill the contract of `tryGetField`.\n\t\tif (field !== undefined && field.length > 0) {\n\t\t\treturn getOrCreateField(this, key, this.storedSchema.getFieldSchema(key).kind, () =>\n\t\t\t\tthis.emitChangedEvent(key),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic getBoxed(key: string): FlexTreeField {\n\t\tconst fieldKey: FieldKey = brand(key);\n\t\treturn getOrCreateField(\n\t\t\tthis,\n\t\t\tfieldKey,\n\t\t\tthis.storedSchema.getFieldSchema(fieldKey).kind,\n\t\t\t() => this.emitChangedEvent(fieldKey),\n\t\t);\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeField> {\n\t\treturn mapIterable(this.mapTree.fields.entries(), ([key]) =>\n\t\t\tgetOrCreateField(this, key, this.storedSchema.getFieldSchema(key).kind, () =>\n\t\t\t\tthis.emitChangedEvent(key),\n\t\t\t),\n\t\t);\n\t}\n\n\tpublic keys(): IterableIterator<FieldKey> {\n\t\t// TODO: how this should handle missing defaults (and empty keys if they end up being allowed) needs to be determined.\n\t\treturn this.mapTree.fields.keys();\n\t}\n\n\tpublic get value(): Value {\n\t\treturn this.mapTree.value;\n\t}\n\n\tpublic get anchorNode(): AnchorNode {\n\t\t// This API is relevant to `LazyTreeNode`s, but not `UnhydratedFlexTreeNode`s.\n\t\t// TODO: Refactor the FlexTreeNode interface so that stubbing this out isn't necessary.\n\t\treturn fail(\"UnhydratedFlexTreeNode does not implement anchorNode\");\n\t}\n\n\tprivate walkTree(): void {\n\t\tfor (const [key, mapTrees] of this.mapTree.fields) {\n\t\t\tconst field = getOrCreateField(\n\t\t\t\tthis,\n\t\t\t\tkey,\n\t\t\t\tthis.storedSchema.getFieldSchema(key).kind,\n\t\t\t\t() => this.emitChangedEvent(key),\n\t\t\t);\n\t\t\tfor (let index = 0; index < field.length; index++) {\n\t\t\t\tconst child = getOrCreateChild(this.simpleContext, mapTrees[index] ?? oob(), {\n\t\t\t\t\tparent: field,\n\t\t\t\t\tindex,\n\t\t\t\t});\n\t\t\t\t// These next asserts detect the case where `getOrCreateChild` gets a cache hit of a different node than the one we're trying to create\n\t\t\t\tassert(child.location !== undefined, 0x98d /* Expected node to have parent */);\n\t\t\t\tassert(\n\t\t\t\t\tchild.location.parent.parent === this,\n\t\t\t\t\t0x98e /* Node may not be multi-parented */,\n\t\t\t\t);\n\t\t\t\tassert(child.location.index === index, 0x98f /* Node may not be multi-parented */);\n\t\t\t\tchild.walkTree();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate emitChangedEvent(key: FieldKey): void {\n\t\tthis._events.emit(\"childrenChangedAfterBatch\", { changedFields: new Set([key]) });\n\t}\n}\n\n/**\n * Implementation of `FlexTreeContext`.\n *\n * @remarks An editor is required to edit the FlexTree.\n */\nexport class UnhydratedContext implements FlexTreeContext {\n\t/**\n\t * @param flexSchema - Schema to use when working with the tree.\n\t */\n\tpublic constructor(\n\t\tpublic readonly schemaPolicy: SchemaPolicy,\n\t\tpublic readonly schema: TreeStoredSchema,\n\t) {}\n\n\tpublic isHydrated(): this is FlexTreeHydratedContext {\n\t\treturn false;\n\t}\n}\n\n// #region Fields\n\n/**\n * A special singleton that is the implicit {@link LocationInField} of all un-parented {@link UnhydratedFlexTreeNode}s.\n * @remarks This exists because {@link UnhydratedFlexTreeNode.parentField} must return a field.\n * If a {@link UnhydratedFlexTreeNode} is created without a parent, its {@link UnhydratedFlexTreeNode.parentField} property will point to this object.\n * However, this field cannot be used in any practical way because it is empty, i.e. it does not actually contain the children that claim to be parented under it.\n * It has the \"empty\" schema and it will always contain zero children if queried.\n * Any nodes with this location will have a dummy parent index of `-1`.\n */\nconst unparentedLocation: LocationInField = {\n\tparent: {\n\t\t[flexTreeMarker]: FlexTreeEntityKind.Field as const,\n\t\tlength: 0,\n\t\tkey: EmptyKey,\n\t\tparent: undefined,\n\t\tis<TKind2 extends FlexFieldKind>(kind: TKind2) {\n\t\t\treturn this.schema === kind.identifier;\n\t\t},\n\t\tboxedIterator(): IterableIterator<FlexTreeNode> {\n\t\t\treturn [].values();\n\t\t},\n\t\tboxedAt(index: number): FlexTreeNode | undefined {\n\t\t\treturn undefined;\n\t\t},\n\t\tschema: brand(forbiddenFieldKindIdentifier),\n\t\tget context(): never {\n\t\t\treturn fail(\"unsupported\");\n\t\t},\n\t\tgetFieldPath() {\n\t\t\tfail(\"unsupported\");\n\t\t},\n\t},\n\tindex: -1,\n};\n\nclass UnhydratedFlexTreeField implements FlexTreeField {\n\tpublic [flexTreeMarker] = FlexTreeEntityKind.Field as const;\n\n\tpublic get context(): FlexTreeContext {\n\t\treturn this.simpleContext.flexContext;\n\t}\n\n\tpublic constructor(\n\t\tpublic readonly simpleContext: Context,\n\t\tpublic readonly schema: FieldKindIdentifier,\n\t\tpublic readonly key: FieldKey,\n\t\tpublic readonly parent: UnhydratedFlexTreeNode,\n\t\tpublic readonly onEdit?: () => void,\n\t) {\n\t\tconst fieldKeyCache = getFieldKeyCache(parent);\n\t\tassert(!fieldKeyCache.has(key), 0x990 /* A field already exists for the given MapTrees */);\n\t\tfieldKeyCache.set(key, this);\n\n\t\t// When this field is created (which only happens one time, because it is cached), all the children become parented for the first time.\n\t\t// \"Adopt\" each child by updating its parent information to point to this field.\n\t\tfor (const [i, mapTree] of this.mapTrees.entries()) {\n\t\t\tconst mapTreeNodeChild = nodeCache.get(mapTree);\n\t\t\tif (mapTreeNodeChild !== undefined) {\n\t\t\t\tif (mapTreeNodeChild.parentField !== unparentedLocation) {\n\t\t\t\t\tthrow new UsageError(\"A node may not be in more than one place in the tree\");\n\t\t\t\t}\n\t\t\t\tmapTreeNodeChild.adoptBy(this, i);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic get mapTrees(): readonly ExclusiveMapTree[] {\n\t\treturn this.parent.mapTree.fields.get(this.key) ?? [];\n\t}\n\n\tpublic get length(): number {\n\t\treturn this.mapTrees.length;\n\t}\n\n\tpublic is<TKind2 extends FlexFieldKind>(kind: TKind2): this is FlexTreeTypedField<TKind2> {\n\t\treturn this.schema === kind.identifier;\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeNode> {\n\t\treturn this.mapTrees\n\t\t\t.map(\n\t\t\t\t(m, index) =>\n\t\t\t\t\tgetOrCreateChild(this.simpleContext, m, {\n\t\t\t\t\t\tparent: this,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t}) as FlexTreeNode,\n\t\t\t)\n\t\t\t.values();\n\t}\n\n\tpublic boxedAt(index: number): FlexTreeNode | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst m = this.mapTrees[i];\n\t\tif (m !== undefined) {\n\t\t\treturn getOrCreateChild(this.simpleContext, m, {\n\t\t\t\tparent: this,\n\t\t\t\tindex: i,\n\t\t\t}) as FlexTreeNode;\n\t\t}\n\t}\n\n\t/**\n\t * Mutate this field.\n\t * @param edit - A function which receives the current `MapTree`s that comprise the contents of the field so that it may be mutated.\n\t * The function may mutate the array in place or return a new array.\n\t * If a new array is returned then it will be used as the new contents of the field, otherwise the original array will be continue to be used.\n\t * @remarks All edits to the field (i.e. mutations of the field's MapTrees) should be directed through this function.\n\t * This function ensures that the parent MapTree has no empty fields (which is an invariant of `MapTree`) after the mutation.\n\t */\n\tprotected edit(edit: (mapTrees: ExclusiveMapTree[]) => void | ExclusiveMapTree[]): void {\n\t\tconst oldMapTrees = this.parent.mapTree.fields.get(this.key) ?? [];\n\t\tconst newMapTrees = edit(oldMapTrees) ?? oldMapTrees;\n\t\tif (newMapTrees.length > 0) {\n\t\t\tthis.parent.mapTree.fields.set(this.key, newMapTrees);\n\t\t} else {\n\t\t\tthis.parent.mapTree.fields.delete(this.key);\n\t\t}\n\n\t\tthis.onEdit?.();\n\t}\n\n\tpublic getFieldPath(): FieldUpPath {\n\t\tthrow unsupportedUsageError(\"Editing an array\");\n\t}\n\n\t/** Unboxes leaf nodes to their values */\n\tprotected unboxed(index: number): FlexTreeUnknownUnboxed {\n\t\tconst mapTree: ExclusiveMapTree = this.mapTrees[index] ?? oob();\n\t\tconst value = mapTree.value;\n\t\tif (value !== undefined) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn getOrCreateChild(this.simpleContext, mapTree, { parent: this, index });\n\t}\n}\n\nclass EagerMapTreeOptionalField\n\textends UnhydratedFlexTreeField\n\timplements FlexTreeOptionalField\n{\n\tpublic readonly editor = {\n\t\tset: (newContent: ExclusiveMapTree | undefined): void => {\n\t\t\t// If the new content is a UnhydratedFlexTreeNode, it needs to have its parent pointer updated\n\t\t\tif (newContent !== undefined) {\n\t\t\t\tnodeCache.get(newContent)?.adoptBy(this, 0);\n\t\t\t}\n\t\t\t// If the old content is a UnhydratedFlexTreeNode, it needs to have its parent pointer unset\n\t\t\tconst oldContent = this.mapTrees[0];\n\t\t\tif (oldContent !== undefined) {\n\t\t\t\tnodeCache.get(oldContent)?.adoptBy(undefined);\n\t\t\t}\n\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent !== undefined) {\n\t\t\t\t\tmapTrees[0] = newContent;\n\t\t\t\t} else {\n\t\t\t\t\tmapTrees.length = 0;\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n\n\tpublic get content(): FlexTreeUnknownUnboxed | undefined {\n\t\tconst value = this.mapTrees[0];\n\t\tif (value !== undefined) {\n\t\t\treturn this.unboxed(0);\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n\nclass EagerMapTreeRequiredField\n\textends EagerMapTreeOptionalField\n\timplements FlexTreeRequiredField\n{\n\tpublic override get content(): FlexTreeUnknownUnboxed {\n\t\t// This cannot use ?? since null is a legal value here.\n\t\tassert(\n\t\t\tsuper.content !== undefined,\n\t\t\t0xa57 /* Expected EagerMapTree required field to have a value */,\n\t\t);\n\t\treturn super.content;\n\t}\n}\n\nexport class UnhydratedTreeSequenceField\n\textends UnhydratedFlexTreeField\n\timplements FlexTreeSequenceField\n{\n\tpublic readonly editor: UnhydratedTreeSequenceFieldEditBuilder = {\n\t\tinsert: (index, newContent): void => {\n\t\t\tfor (let i = 0; i < newContent.length; i++) {\n\t\t\t\tconst c = newContent[i];\n\t\t\t\tassert(c !== undefined, 0xa0a /* Unexpected sparse array content */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(this, index + i);\n\t\t\t}\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent.length < 1000) {\n\t\t\t\t\t// For \"smallish arrays\" (`1000` is not empirically derived), the `splice` function is appropriate...\n\t\t\t\t\tmapTrees.splice(index, 0, ...newContent);\n\t\t\t\t} else {\n\t\t\t\t\t// ...but we avoid using `splice` + spread for very large input arrays since there is a limit on how many elements can be spread (too many will overflow the stack).\n\t\t\t\t\treturn mapTrees.slice(0, index).concat(newContent, mapTrees.slice(index));\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tremove: (index, count): ExclusiveMapTree[] => {\n\t\t\tfor (let i = index; i < index + count; i++) {\n\t\t\t\tconst c = this.mapTrees[i];\n\t\t\t\tassert(c !== undefined, 0xa0b /* Unexpected sparse array */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(undefined);\n\t\t\t}\n\t\t\tlet removed: ExclusiveMapTree[] | undefined;\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tremoved = mapTrees.splice(index, count);\n\t\t\t});\n\t\t\treturn removed ?? fail(\"Expected removed to be set by edit\");\n\t\t},\n\t};\n\n\tpublic at(index: number): FlexTreeUnknownUnboxed | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.unboxed(i);\n\t}\n\tpublic map<U>(callbackfn: (value: FlexTreeUnknownUnboxed, index: number) => U): U[] {\n\t\treturn Array.from(this, callbackfn);\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<FlexTreeUnknownUnboxed> {\n\t\tfor (const [i] of this.mapTrees.entries()) {\n\t\t\tyield this.unboxed(i);\n\t\t}\n\t}\n}\n\n// #endregion Fields\n\n// #region Caching and unboxing utilities\n\nconst nodeCache = new WeakMap<MapTree, UnhydratedFlexTreeNode>();\n/** Node Parent -\\> Field Key -\\> Field */\nconst fieldCache = new WeakMap<\n\tUnhydratedFlexTreeNode,\n\tMap<FieldKey, UnhydratedFlexTreeField>\n>();\nfunction getFieldKeyCache(\n\tparent: UnhydratedFlexTreeNode,\n): WeakMap<FieldKey, UnhydratedFlexTreeField> {\n\treturn getOrCreate(fieldCache, parent, () => new Map());\n}\n\n/**\n * If there exists a {@link UnhydratedFlexTreeNode} for the given {@link MapTree}, returns it, otherwise returns `undefined`.\n * @remarks {@link UnhydratedFlexTreeNode | UnhydratedFlexTreeNodes} are created via {@link getOrCreateNode}.\n */\nexport function tryUnhydratedFlexTreeNode(\n\tmapTree: MapTree,\n): UnhydratedFlexTreeNode | undefined {\n\treturn nodeCache.get(mapTree);\n}\n\n/** Helper for creating a `UnhydratedFlexTreeNode` given the parent field (e.g. when \"walking down\") */\nfunction getOrCreateChild(\n\tcontext: Context,\n\tmapTree: ExclusiveMapTree,\n\tparent: LocationInField | undefined,\n): UnhydratedFlexTreeNode {\n\tconst cached = nodeCache.get(mapTree);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\treturn new UnhydratedFlexTreeNode(context, mapTree, parent);\n}\n\n/** Creates a field with the given attributes, or returns a cached field if there is one */\nfunction getOrCreateField(\n\tparent: UnhydratedFlexTreeNode,\n\tkey: FieldKey,\n\tschema: FieldKindIdentifier,\n\tonEdit?: () => void,\n): UnhydratedFlexTreeField {\n\tconst cached = getFieldKeyCache(parent).get(key);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tif (\n\t\tschema === FieldKinds.required.identifier ||\n\t\tschema === FieldKinds.identifier.identifier\n\t) {\n\t\treturn new EagerMapTreeRequiredField(parent.simpleContext, schema, key, parent, onEdit);\n\t}\n\n\tif (schema === FieldKinds.optional.identifier) {\n\t\treturn new EagerMapTreeOptionalField(parent.simpleContext, schema, key, parent, onEdit);\n\t}\n\n\tif (schema === FieldKinds.sequence.identifier) {\n\t\treturn new UnhydratedTreeSequenceField(parent.simpleContext, schema, key, parent, onEdit);\n\t}\n\n\treturn new UnhydratedFlexTreeField(parent.simpleContext, schema, key, parent, onEdit);\n}\n\n// #endregion Caching and unboxing utilities\n\nexport function unsupportedUsageError(message?: string): Error {\n\treturn new UsageError(\n\t\t`${\n\t\t\tmessage ?? \"Operation\"\n\t\t} is not supported for content that has not yet been inserted into the tree`,\n\t);\n}\n"]}
1
+ {"version":3,"file":"unhydratedFlexTree.js","sourceRoot":"","sources":["../../../src/simple-tree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,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACzF,CAAC;IAED,IAAI,MAAM,KAAK,qBAAU,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC;QAC/C,OAAO,IAAI,2BAA2B,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAC3F,CAAC;IAED,OAAO,IAAI,uBAAuB,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACvF,CAAC;AAED,4CAA4C;AAE5C,SAAgB,qBAAqB,CAAC,OAAgB;IACrD,OAAO,IAAI,qBAAU,CACpB,GACC,OAAO,IAAI,WACZ,4EAA4E,CAC5E,CAAC;AACH,CAAC;AAND,sDAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\tEmptyKey,\n\ttype ExclusiveMapTree,\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldUpPath,\n\tforbiddenFieldKindIdentifier,\n\ttype ITreeCursorSynchronous,\n\ttype MapTree,\n\ttype SchemaPolicy,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\ttype Value,\n} from \"../../core/index.js\";\nimport { brand, fail, getOrCreate, mapIterable } from \"../../util/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tFlexTreeEntityKind,\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeSequenceField,\n\ttype FlexTreeTypedField,\n\ttype FlexTreeUnknownUnboxed,\n\tflexTreeMarker,\n\tindexForAt,\n\ttype FlexTreeHydratedContext,\n\ttype FlexFieldKind,\n\tFieldKinds,\n\ttype SequenceFieldEditBuilder,\n\tcursorForMapTreeNode,\n} from \"../../feature-libraries/index.js\";\nimport type { Context } from \"./context.js\";\n\ninterface UnhydratedTreeSequenceFieldEditBuilder\n\textends SequenceFieldEditBuilder<ExclusiveMapTree[]> {\n\t/**\n\t * Issues a change which removes `count` elements starting at the given `index`.\n\t * @param index - The index of the first removed element.\n\t * @param count - The number of elements to remove.\n\t * @returns the MapTrees that were removed\n\t */\n\tremove(index: number, count: number): ExclusiveMapTree[];\n}\n\ntype UnhydratedFlexTreeNodeEvents = Pick<AnchorEvents, \"childrenChangedAfterBatch\">;\n\n/** A node's parent field and its index in that field */\ninterface LocationInField {\n\treadonly parent: FlexTreeField;\n\treadonly index: number;\n}\n\n/**\n * An unhydrated implementation of {@link FlexTreeNode} which wraps a {@link MapTree}.\n * @remarks\n * MapTreeNodes are unconditionally cached -\n * when retrieved via {@link getOrCreateNode}, the same {@link MapTree} object will always produce the same `UnhydratedFlexTreeNode` object.\n *\n * Create a `UnhydratedFlexTreeNode` by calling {@link getOrCreate}.\n */\nexport class UnhydratedFlexTreeNode implements UnhydratedFlexTreeNode {\n\tpublic get schema(): TreeNodeSchemaIdentifier {\n\t\treturn this.mapTree.type;\n\t}\n\n\tpublic get storedSchema(): TreeNodeStoredSchema {\n\t\treturn (\n\t\t\tthis.context.schema.nodeSchema.get(this.mapTree.type) ?? fail(0xb46 /* missing schema */)\n\t\t);\n\t}\n\n\tpublic readonly [flexTreeMarker] = FlexTreeEntityKind.Node as const;\n\n\tprivate readonly _events = createEmitter<UnhydratedFlexTreeNodeEvents>();\n\tpublic get events(): Listenable<UnhydratedFlexTreeNodeEvents> {\n\t\treturn this._events;\n\t}\n\n\t/**\n\t * Create a {@link UnhydratedFlexTreeNode} that wraps the given {@link MapTree}, or get the node that already exists for that {@link MapTree} if there is one.\n\t * @param nodeSchema - the {@link FlexTreeNodeSchema | schema} that the node conforms to\n\t * @param mapTree - the {@link MapTree} containing the data for this node.\n\t * @remarks It must conform to the `nodeSchema`.\n\t */\n\tpublic static getOrCreate(\n\t\tcontext: Context,\n\t\tmapTree: ExclusiveMapTree,\n\t): UnhydratedFlexTreeNode {\n\t\treturn nodeCache.get(mapTree) ?? new UnhydratedFlexTreeNode(context, mapTree, undefined);\n\t}\n\n\tpublic get context(): FlexTreeContext {\n\t\treturn this.simpleContext.flexContext;\n\t}\n\n\t/**\n\t * Create a new UnhydratedFlexTreeNode.\n\t * @param location - the parentage of this node, if it is being created underneath an existing node and field, or undefined if not\n\t * @remarks This class (and its subclasses) should not be directly constructed outside of this module.\n\t * Instead, use {@link getOrCreateNode} to create a UnhydratedFlexTreeNode from a {@link MapTree}.\n\t * A `UnhydratedFlexTreeNode` may never be constructed more than once for the same {@link MapTree} object.\n\t * Instead, it should always be acquired via {@link getOrCreateNode}.\n\t */\n\tpublic constructor(\n\t\tpublic readonly simpleContext: Context,\n\t\t/** The underlying {@link MapTree} that this `UnhydratedFlexTreeNode` reads its data from */\n\t\tpublic readonly mapTree: ExclusiveMapTree,\n\t\tprivate location = unparentedLocation,\n\t) {\n\t\tassert(!nodeCache.has(mapTree), 0x98b /* A node already exists for the given MapTree */);\n\t\tnodeCache.set(mapTree, this);\n\n\t\t// Fully demand the tree to ensure that parent pointers are present and accurate on all nodes.\n\t\t// When a UnhydratedFlexTreeNode is constructed, its MapTree may contain nodes (anywhere below) that map (via the `nodeCache`) to pre-existing UnhydratedFlexTreeNodes.\n\t\t// Put another way, for a given MapTree, some ancestor UnhydratedFlexTreeNode can be created after any number of its descendant UnhydratedFlexTreeNodes already exist.\n\t\t// In such a case, the spine of nodes between the descendant and ancestor need to exist in order for the ancestor to be able to walk upwards via the `parentField` property.\n\t\t// This needs to happen for all UnhydratedFlexTreeNodes that are descendants of the ancestor UnhydratedFlexTreeNode.\n\t\t// Demanding the entire tree is overkill to solve this problem since not all descendant MapTree nodes will have corresponding UnhydratedFlexTreeNodes.\n\t\t// However, demanding the full tree also lets us eagerly validate that there are no duplicate MapTrees (i.e. same MapTree object) anywhere in the tree.\n\t\tthis.walkTree();\n\t}\n\n\tpublic get type(): TreeNodeSchemaIdentifier {\n\t\treturn this.mapTree.type;\n\t}\n\n\t/**\n\t * Set this node's parentage (see {@link FlexTreeNode.parentField}).\n\t * @remarks The node may be given a parent if it has none, or may have its parent removed (by passing `undefined`).\n\t * However, a node with a parent may not be directly re-assigned a different parent.\n\t * That likely indicates either an attempted multi-parenting or an attempt to \"move\" the node, neither of which are supported.\n\t * Removing a node's parent twice in a row is also not supported, as it likely indicates a bug.\n\t */\n\tpublic adoptBy(parent: undefined): void;\n\tpublic adoptBy(parent: UnhydratedFlexTreeField, index: number): void;\n\tpublic adoptBy(parent: UnhydratedFlexTreeField | undefined, index?: number): void {\n\t\tif (parent !== undefined) {\n\t\t\tassert(\n\t\t\t\tthis.location === unparentedLocation,\n\t\t\t\t0x98c /* Node may not be adopted if it already has a parent */,\n\t\t\t);\n\t\t\tassert(index !== undefined, 0xa08 /* Expected index */);\n\t\t\tthis.location = { parent, index };\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tthis.location !== unparentedLocation,\n\t\t\t\t0xa09 /* Node may not be un-adopted if it does not have a parent */,\n\t\t\t);\n\t\t\tthis.location = unparentedLocation;\n\t\t}\n\t}\n\n\t/**\n\t * The field this tree is in, and the index within that field.\n\t * @remarks If this node is unparented, this method will return the special {@link unparentedLocation} as the parent.\n\t */\n\tpublic get parentField(): LocationInField {\n\t\treturn this.location;\n\t}\n\n\tpublic borrowCursor(): ITreeCursorSynchronous {\n\t\treturn cursorForMapTreeNode(this.mapTree);\n\t}\n\n\tpublic tryGetField(key: FieldKey): UnhydratedFlexTreeField | undefined {\n\t\tconst field = this.mapTree.fields.get(key);\n\t\t// Only return the field if it is not empty, in order to fulfill the contract of `tryGetField`.\n\t\tif (field !== undefined && field.length > 0) {\n\t\t\treturn getOrCreateField(this, key, this.storedSchema.getFieldSchema(key).kind, () =>\n\t\t\t\tthis.emitChangedEvent(key),\n\t\t\t);\n\t\t}\n\t}\n\n\tpublic getBoxed(key: string): FlexTreeField {\n\t\tconst fieldKey: FieldKey = brand(key);\n\t\treturn getOrCreateField(\n\t\t\tthis,\n\t\t\tfieldKey,\n\t\t\tthis.storedSchema.getFieldSchema(fieldKey).kind,\n\t\t\t() => this.emitChangedEvent(fieldKey),\n\t\t);\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeField> {\n\t\treturn mapIterable(this.mapTree.fields.entries(), ([key]) =>\n\t\t\tgetOrCreateField(this, key, this.storedSchema.getFieldSchema(key).kind, () =>\n\t\t\t\tthis.emitChangedEvent(key),\n\t\t\t),\n\t\t);\n\t}\n\n\tpublic keys(): IterableIterator<FieldKey> {\n\t\t// TODO: how this should handle missing defaults (and empty keys if they end up being allowed) needs to be determined.\n\t\treturn this.mapTree.fields.keys();\n\t}\n\n\tpublic get value(): Value {\n\t\treturn this.mapTree.value;\n\t}\n\n\tpublic get anchorNode(): AnchorNode {\n\t\t// This API is relevant to `LazyTreeNode`s, but not `UnhydratedFlexTreeNode`s.\n\t\t// TODO: Refactor the FlexTreeNode interface so that stubbing this out isn't necessary.\n\t\treturn fail(0xb47 /* UnhydratedFlexTreeNode does not implement anchorNode */);\n\t}\n\n\tprivate walkTree(): void {\n\t\tfor (const [key, mapTrees] of this.mapTree.fields) {\n\t\t\tconst field = getOrCreateField(\n\t\t\t\tthis,\n\t\t\t\tkey,\n\t\t\t\tthis.storedSchema.getFieldSchema(key).kind,\n\t\t\t\t() => this.emitChangedEvent(key),\n\t\t\t);\n\t\t\tfor (let index = 0; index < field.length; index++) {\n\t\t\t\tconst child = getOrCreateChild(this.simpleContext, mapTrees[index] ?? oob(), {\n\t\t\t\t\tparent: field,\n\t\t\t\t\tindex,\n\t\t\t\t});\n\t\t\t\t// These next asserts detect the case where `getOrCreateChild` gets a cache hit of a different node than the one we're trying to create\n\t\t\t\tassert(child.location !== undefined, 0x98d /* Expected node to have parent */);\n\t\t\t\tassert(\n\t\t\t\t\tchild.location.parent.parent === this,\n\t\t\t\t\t0x98e /* Node may not be multi-parented */,\n\t\t\t\t);\n\t\t\t\tassert(child.location.index === index, 0x98f /* Node may not be multi-parented */);\n\t\t\t\tchild.walkTree();\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate emitChangedEvent(key: FieldKey): void {\n\t\tthis._events.emit(\"childrenChangedAfterBatch\", { changedFields: new Set([key]) });\n\t}\n}\n\n/**\n * Implementation of `FlexTreeContext`.\n *\n * @remarks An editor is required to edit the FlexTree.\n */\nexport class UnhydratedContext implements FlexTreeContext {\n\t/**\n\t * @param flexSchema - Schema to use when working with the tree.\n\t */\n\tpublic constructor(\n\t\tpublic readonly schemaPolicy: SchemaPolicy,\n\t\tpublic readonly schema: TreeStoredSchema,\n\t) {}\n\n\tpublic isHydrated(): this is FlexTreeHydratedContext {\n\t\treturn false;\n\t}\n}\n\n// #region Fields\n\n/**\n * A special singleton that is the implicit {@link LocationInField} of all un-parented {@link UnhydratedFlexTreeNode}s.\n * @remarks This exists because {@link UnhydratedFlexTreeNode.parentField} must return a field.\n * If a {@link UnhydratedFlexTreeNode} is created without a parent, its {@link UnhydratedFlexTreeNode.parentField} property will point to this object.\n * However, this field cannot be used in any practical way because it is empty, i.e. it does not actually contain the children that claim to be parented under it.\n * It has the \"empty\" schema and it will always contain zero children if queried.\n * Any nodes with this location will have a dummy parent index of `-1`.\n */\nconst unparentedLocation: LocationInField = {\n\tparent: {\n\t\t[flexTreeMarker]: FlexTreeEntityKind.Field as const,\n\t\tlength: 0,\n\t\tkey: EmptyKey,\n\t\tparent: undefined,\n\t\tis<TKind2 extends FlexFieldKind>(kind: TKind2) {\n\t\t\treturn this.schema === kind.identifier;\n\t\t},\n\t\tboxedIterator(): IterableIterator<FlexTreeNode> {\n\t\t\treturn [].values();\n\t\t},\n\t\tboxedAt(index: number): FlexTreeNode | undefined {\n\t\t\treturn undefined;\n\t\t},\n\t\tschema: brand(forbiddenFieldKindIdentifier),\n\t\tget context(): never {\n\t\t\treturn fail(0xb48 /* unsupported */);\n\t\t},\n\t\tgetFieldPath() {\n\t\t\tfail(0xb49 /* unsupported */);\n\t\t},\n\t},\n\tindex: -1,\n};\n\nclass UnhydratedFlexTreeField implements FlexTreeField {\n\tpublic [flexTreeMarker] = FlexTreeEntityKind.Field as const;\n\n\tpublic get context(): FlexTreeContext {\n\t\treturn this.simpleContext.flexContext;\n\t}\n\n\tpublic constructor(\n\t\tpublic readonly simpleContext: Context,\n\t\tpublic readonly schema: FieldKindIdentifier,\n\t\tpublic readonly key: FieldKey,\n\t\tpublic readonly parent: UnhydratedFlexTreeNode,\n\t\tpublic readonly onEdit?: () => void,\n\t) {\n\t\tconst fieldKeyCache = getFieldKeyCache(parent);\n\t\tassert(!fieldKeyCache.has(key), 0x990 /* A field already exists for the given MapTrees */);\n\t\tfieldKeyCache.set(key, this);\n\n\t\t// When this field is created (which only happens one time, because it is cached), all the children become parented for the first time.\n\t\t// \"Adopt\" each child by updating its parent information to point to this field.\n\t\tfor (const [i, mapTree] of this.mapTrees.entries()) {\n\t\t\tconst mapTreeNodeChild = nodeCache.get(mapTree);\n\t\t\tif (mapTreeNodeChild !== undefined) {\n\t\t\t\tif (mapTreeNodeChild.parentField !== unparentedLocation) {\n\t\t\t\t\tthrow new UsageError(\"A node may not be in more than one place in the tree\");\n\t\t\t\t}\n\t\t\t\tmapTreeNodeChild.adoptBy(this, i);\n\t\t\t}\n\t\t}\n\t}\n\n\tpublic get mapTrees(): readonly ExclusiveMapTree[] {\n\t\treturn this.parent.mapTree.fields.get(this.key) ?? [];\n\t}\n\n\tpublic get length(): number {\n\t\treturn this.mapTrees.length;\n\t}\n\n\tpublic is<TKind2 extends FlexFieldKind>(kind: TKind2): this is FlexTreeTypedField<TKind2> {\n\t\treturn this.schema === kind.identifier;\n\t}\n\n\tpublic boxedIterator(): IterableIterator<FlexTreeNode> {\n\t\treturn this.mapTrees\n\t\t\t.map(\n\t\t\t\t(m, index) =>\n\t\t\t\t\tgetOrCreateChild(this.simpleContext, m, {\n\t\t\t\t\t\tparent: this,\n\t\t\t\t\t\tindex,\n\t\t\t\t\t}) as FlexTreeNode,\n\t\t\t)\n\t\t\t.values();\n\t}\n\n\tpublic boxedAt(index: number): FlexTreeNode | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\tconst m = this.mapTrees[i];\n\t\tif (m !== undefined) {\n\t\t\treturn getOrCreateChild(this.simpleContext, m, {\n\t\t\t\tparent: this,\n\t\t\t\tindex: i,\n\t\t\t}) as FlexTreeNode;\n\t\t}\n\t}\n\n\t/**\n\t * Mutate this field.\n\t * @param edit - A function which receives the current `MapTree`s that comprise the contents of the field so that it may be mutated.\n\t * The function may mutate the array in place or return a new array.\n\t * If a new array is returned then it will be used as the new contents of the field, otherwise the original array will be continue to be used.\n\t * @remarks All edits to the field (i.e. mutations of the field's MapTrees) should be directed through this function.\n\t * This function ensures that the parent MapTree has no empty fields (which is an invariant of `MapTree`) after the mutation.\n\t */\n\tprotected edit(edit: (mapTrees: ExclusiveMapTree[]) => void | ExclusiveMapTree[]): void {\n\t\tconst oldMapTrees = this.parent.mapTree.fields.get(this.key) ?? [];\n\t\tconst newMapTrees = edit(oldMapTrees) ?? oldMapTrees;\n\t\tif (newMapTrees.length > 0) {\n\t\t\tthis.parent.mapTree.fields.set(this.key, newMapTrees);\n\t\t} else {\n\t\t\tthis.parent.mapTree.fields.delete(this.key);\n\t\t}\n\n\t\tthis.onEdit?.();\n\t}\n\n\tpublic getFieldPath(): FieldUpPath {\n\t\tthrow unsupportedUsageError(\"Editing an array\");\n\t}\n\n\t/** Unboxes leaf nodes to their values */\n\tprotected unboxed(index: number): FlexTreeUnknownUnboxed {\n\t\tconst mapTree: ExclusiveMapTree = this.mapTrees[index] ?? oob();\n\t\tconst value = mapTree.value;\n\t\tif (value !== undefined) {\n\t\t\treturn value;\n\t\t}\n\n\t\treturn getOrCreateChild(this.simpleContext, mapTree, { parent: this, index });\n\t}\n}\n\nclass EagerMapTreeOptionalField\n\textends UnhydratedFlexTreeField\n\timplements FlexTreeOptionalField\n{\n\tpublic readonly editor = {\n\t\tset: (newContent: ExclusiveMapTree | undefined): void => {\n\t\t\t// If the new content is a UnhydratedFlexTreeNode, it needs to have its parent pointer updated\n\t\t\tif (newContent !== undefined) {\n\t\t\t\tnodeCache.get(newContent)?.adoptBy(this, 0);\n\t\t\t}\n\t\t\t// If the old content is a UnhydratedFlexTreeNode, it needs to have its parent pointer unset\n\t\t\tconst oldContent = this.mapTrees[0];\n\t\t\tif (oldContent !== undefined) {\n\t\t\t\tnodeCache.get(oldContent)?.adoptBy(undefined);\n\t\t\t}\n\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent !== undefined) {\n\t\t\t\t\tmapTrees[0] = newContent;\n\t\t\t\t} else {\n\t\t\t\t\tmapTrees.length = 0;\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t};\n\n\tpublic get content(): FlexTreeUnknownUnboxed | undefined {\n\t\tconst value = this.mapTrees[0];\n\t\tif (value !== undefined) {\n\t\t\treturn this.unboxed(0);\n\t\t}\n\n\t\treturn undefined;\n\t}\n}\n\nclass EagerMapTreeRequiredField\n\textends EagerMapTreeOptionalField\n\timplements FlexTreeRequiredField\n{\n\tpublic override get content(): FlexTreeUnknownUnboxed {\n\t\t// This cannot use ?? since null is a legal value here.\n\t\tassert(\n\t\t\tsuper.content !== undefined,\n\t\t\t0xa57 /* Expected EagerMapTree required field to have a value */,\n\t\t);\n\t\treturn super.content;\n\t}\n}\n\nexport class UnhydratedTreeSequenceField\n\textends UnhydratedFlexTreeField\n\timplements FlexTreeSequenceField\n{\n\tpublic readonly editor: UnhydratedTreeSequenceFieldEditBuilder = {\n\t\tinsert: (index, newContent): void => {\n\t\t\tfor (let i = 0; i < newContent.length; i++) {\n\t\t\t\tconst c = newContent[i];\n\t\t\t\tassert(c !== undefined, 0xa0a /* Unexpected sparse array content */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(this, index + i);\n\t\t\t}\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tif (newContent.length < 1000) {\n\t\t\t\t\t// For \"smallish arrays\" (`1000` is not empirically derived), the `splice` function is appropriate...\n\t\t\t\t\tmapTrees.splice(index, 0, ...newContent);\n\t\t\t\t} else {\n\t\t\t\t\t// ...but we avoid using `splice` + spread for very large input arrays since there is a limit on how many elements can be spread (too many will overflow the stack).\n\t\t\t\t\treturn mapTrees.slice(0, index).concat(newContent, mapTrees.slice(index));\n\t\t\t\t}\n\t\t\t});\n\t\t},\n\t\tremove: (index, count): ExclusiveMapTree[] => {\n\t\t\tfor (let i = index; i < index + count; i++) {\n\t\t\t\tconst c = this.mapTrees[i];\n\t\t\t\tassert(c !== undefined, 0xa0b /* Unexpected sparse array */);\n\t\t\t\tnodeCache.get(c)?.adoptBy(undefined);\n\t\t\t}\n\t\t\tlet removed: ExclusiveMapTree[] | undefined;\n\t\t\tthis.edit((mapTrees) => {\n\t\t\t\tremoved = mapTrees.splice(index, count);\n\t\t\t});\n\t\t\treturn removed ?? fail(0xb4a /* Expected removed to be set by edit */);\n\t\t},\n\t};\n\n\tpublic at(index: number): FlexTreeUnknownUnboxed | undefined {\n\t\tconst i = indexForAt(index, this.length);\n\t\tif (i === undefined) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.unboxed(i);\n\t}\n\tpublic map<U>(callbackfn: (value: FlexTreeUnknownUnboxed, index: number) => U): U[] {\n\t\treturn Array.from(this, callbackfn);\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<FlexTreeUnknownUnboxed> {\n\t\tfor (const [i] of this.mapTrees.entries()) {\n\t\t\tyield this.unboxed(i);\n\t\t}\n\t}\n}\n\n// #endregion Fields\n\n// #region Caching and unboxing utilities\n\nconst nodeCache = new WeakMap<MapTree, UnhydratedFlexTreeNode>();\n/** Node Parent -\\> Field Key -\\> Field */\nconst fieldCache = new WeakMap<\n\tUnhydratedFlexTreeNode,\n\tMap<FieldKey, UnhydratedFlexTreeField>\n>();\nfunction getFieldKeyCache(\n\tparent: UnhydratedFlexTreeNode,\n): WeakMap<FieldKey, UnhydratedFlexTreeField> {\n\treturn getOrCreate(fieldCache, parent, () => new Map());\n}\n\n/**\n * If there exists a {@link UnhydratedFlexTreeNode} for the given {@link MapTree}, returns it, otherwise returns `undefined`.\n * @remarks {@link UnhydratedFlexTreeNode | UnhydratedFlexTreeNodes} are created via {@link getOrCreateNode}.\n */\nexport function tryUnhydratedFlexTreeNode(\n\tmapTree: MapTree,\n): UnhydratedFlexTreeNode | undefined {\n\treturn nodeCache.get(mapTree);\n}\n\n/** Helper for creating a `UnhydratedFlexTreeNode` given the parent field (e.g. when \"walking down\") */\nfunction getOrCreateChild(\n\tcontext: Context,\n\tmapTree: ExclusiveMapTree,\n\tparent: LocationInField | undefined,\n): UnhydratedFlexTreeNode {\n\tconst cached = nodeCache.get(mapTree);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\treturn new UnhydratedFlexTreeNode(context, mapTree, parent);\n}\n\n/** Creates a field with the given attributes, or returns a cached field if there is one */\nfunction getOrCreateField(\n\tparent: UnhydratedFlexTreeNode,\n\tkey: FieldKey,\n\tschema: FieldKindIdentifier,\n\tonEdit?: () => void,\n): UnhydratedFlexTreeField {\n\tconst cached = getFieldKeyCache(parent).get(key);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tif (\n\t\tschema === FieldKinds.required.identifier ||\n\t\tschema === FieldKinds.identifier.identifier\n\t) {\n\t\treturn new EagerMapTreeRequiredField(parent.simpleContext, schema, key, parent, onEdit);\n\t}\n\n\tif (schema === FieldKinds.optional.identifier) {\n\t\treturn new EagerMapTreeOptionalField(parent.simpleContext, schema, key, parent, onEdit);\n\t}\n\n\tif (schema === FieldKinds.sequence.identifier) {\n\t\treturn new UnhydratedTreeSequenceField(parent.simpleContext, schema, key, parent, onEdit);\n\t}\n\n\treturn new UnhydratedFlexTreeField(parent.simpleContext, schema, key, parent, onEdit);\n}\n\n// #endregion Caching and unboxing utilities\n\nexport function unsupportedUsageError(message?: string): Error {\n\treturn new UsageError(\n\t\t`${\n\t\t\tmessage ?? \"Operation\"\n\t\t} is not supported for content that has not yet been inserted into the tree`,\n\t);\n}\n"]}
@@ -108,7 +108,7 @@ function createProxyHandler(schema, allowAdditionalProperties) {
108
108
  // For some reason, the getOwnPropertyDescriptor is not passed in the receiver, so use a weak map.
109
109
  // If a refactoring is done to associated flex tree data with the target not the proxy, this extra map could be removed,
110
110
  // and the design would be more compatible with proxyless nodes.
111
- const proxy = targetToProxy.get(target) ?? (0, index_js_3.fail)("missing proxy");
111
+ const proxy = targetToProxy.get(target) ?? (0, index_js_3.fail)(0xadd /* missing proxy */);
112
112
  const field = (0, index_js_2.getOrCreateInnerNode)(proxy).tryGetField(fieldInfo.storedKey);
113
113
  const p = {
114
114
  value: field === undefined ? undefined : (0, proxies_js_1.getTreeNodeForField)(field),
@@ -142,7 +142,7 @@ function setField(field, simpleFieldSchema, value) {
142
142
  break;
143
143
  }
144
144
  default:
145
- (0, index_js_3.fail)("invalid FieldKind");
145
+ (0, index_js_3.fail)(0xade /* invalid FieldKind */);
146
146
  }
147
147
  }
148
148
  exports.setField = setField;
@@ -1 +1 @@
1
- {"version":3,"file":"objectNode.js","sourceRoot":"","sources":["../../src/simple-tree/objectNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAmE;AACnE,uEAAsE;AAGtE,4DAOuC;AACvC,6CAA+E;AAC/E,qDAW0B;AAC1B,8CAYyB;AACzB,iDAA6E;AAC7E,+CAAwF;AACxF,6DAI8B;AAC9B,yDAAyE;AACzE,yDAA0D;AA+F1D;;GAEG;AACH,SAAS,oBAAoB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All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Lazy } 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\tgetSchemaAndPolicy,\n} from \"../feature-libraries/index.js\";\nimport { getTreeNodeForField, prepareContentForHydration } from \"./proxies.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\tgetStoredKey,\n\tgetExplicitStoredKey,\n\ttype TreeFieldFromImplicitField,\n\ttype InsertableTreeFieldFromImplicitField,\n\ttype FieldSchema,\n\tnormalizeFieldSchema,\n\ttype ImplicitAllowedTypes,\n\tFieldKind,\n\ttype NodeSchemaMetadata,\n} from \"./schemaTypes.js\";\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\tUnhydratedFlexTreeNode,\n\tgetOrCreateInnerNode,\n} from \"./core/index.js\";\nimport { mapTreeFromNodeData, type InsertableContent } from \"./toMapTree.js\";\nimport { type RestrictiveStringRecord, fail, type FlattenKeys } from \"../util/index.js\";\nimport {\n\tisObjectNodeSchema,\n\ttype ObjectNodeSchema,\n\ttype ObjectNodeSchemaInternalData,\n} from \"./objectNodeTypes.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"./treeNodeValid.js\";\nimport { getUnhydratedContext } from \"./createContext.js\";\n\n/**\n * Generates the properties for an ObjectNode from its field schema object.\n * @system @public\n */\nexport type ObjectFromSchemaRecord<T extends RestrictiveStringRecord<ImplicitFieldSchema>> = {\n\t-readonly [Property in keyof T]: Property extends string\n\t\t? TreeFieldFromImplicitField<T[Property]>\n\t\t: unknown;\n};\n\n/**\n * A {@link TreeNode} which modules a JavaScript object.\n * @remarks\n * Object nodes consist of a type which specifies which {@link TreeNodeSchema} they use (see {@link TreeNodeApi.schema}), 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 * @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 whether or not an implicit field schema has a default value.\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 FieldSchema<\n\tFieldKind.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 * @system @public\n */\nexport type InsertableObjectFromSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> = Record<string, never> extends T\n\t? Record<string, never>\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 * 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 * @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\n\t\t\tif (fieldInfo !== undefined) {\n\t\t\t\tconst flexNode = getOrCreateInnerNode(proxy);\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\t// TODO: this special case logic should move to the inner node (who's schema claims it has an identifier), rather than here, after we already read undefined out of a required field.\n\t\t\t\t// Check if the user is trying to read an identifier field of an unhydrated node, but the identifier is not present.\n\t\t\t\t// This means the identifier is an \"auto-generated identifier\", because otherwise it would have been supplied by the user at construction time and would have been successfully read just above.\n\t\t\t\t// In this case, it is categorically impossible to provide an identifier (auto-generated identifiers can't be created until hydration/insertion time), so we emit an error.\n\t\t\t\tif (\n\t\t\t\t\tfieldInfo.schema.kind === FieldKind.Identifier &&\n\t\t\t\t\tflexNode instanceof UnhydratedFlexTreeNode\n\t\t\t\t) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"An automatically generated node identifier may not be queried until the node is inserted into the tree\",\n\t\t\t\t\t);\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(\"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 = mapTreeFromNodeData(\n\t\tvalue,\n\t\tsimpleFieldSchema,\n\t\tfield.context.isHydrated() ? field.context.nodeKeyManager : undefined,\n\t\tgetSchemaAndPolicy(field),\n\t);\n\n\tif (field.context.isHydrated()) {\n\t\tprepareContentForHydration(mapTree, field.context.checkout.forest);\n\t}\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(\"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<ImplicitFieldSchema>,\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// 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\n\tlet handler: ProxyHandler<object>;\n\tlet customizable: boolean;\n\tlet unhydratedContext: Context;\n\n\tclass CustomObjectNode extends CustomObjectNodeBase<T> {\n\t\tpublic static readonly fields: ReadonlyMap<string, FieldSchema> = new Map(\n\t\t\tArray.from(flexKeyMap, ([key, value]) => [key as string, value.schema]),\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 UnhydratedFlexTreeNode.getOrCreate(\n\t\t\t\tunhydratedContext,\n\t\t\t\tmapTreeFromNodeData(input as object, this as unknown as ImplicitAllowedTypes),\n\t\t\t);\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> | undefined =\n\t\t\tmetadata;\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: InsertableObjectFromSchemaRecord<T> | InternalTreeNode,\n\t\t) => TreeObjectNode<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/objectNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAmE;AACnE,uEAAsE;AAGtE,4DAOuC;AACvC,6CAA+E;AAC/E,qDAW0B;AAC1B,8CAYyB;AACzB,iDAA6E;AAC7E,+CAAwF;AACxF,6DAI8B;AAC9B,yDAAyE;AACzE,yDAA0D;AA+F1D;;GAEG;AACH,SAAS,oBAAoB,CAAC,MAA2C;IACxE,MAAM,MAAM,GAAuE,IAAI,GAAG,EAAE,CAAC;IAC7F,KAAK,MAAM,CAAC,WAAW,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACjE,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AC,SAAS,CAAC,EAAE,CAAC;YACvC,MAAM,IAAI,qBAAU,CACnB,yBAAyB,SAAS,gBAAgB,UAAU,wDAAwD,CACpH,CAAC;QACH,CAAC;QACD,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;IACnC,CAAC;IAED,wDAAwD;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,IAAA,6BAAY,EAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACpD,IAAI,iBAAiB,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YACtC,MAAM,IAAI,qBAAU,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,SAAgB,gCAAgC,CAC/C,MAA2B;IAE3B,MAAM,OAAO,GAAG,IAAA,uCAAoB,EAAC,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,IAAA,uCAAkB,EAAC,YAAY,CAAC;YAChC,YAAY,CAAC,0BAA0B,CACvC,CAAC;IACH,CAAC,CAAC;AACH,CAAC;AAZD,4EAYC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Lazy } 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\tgetSchemaAndPolicy,\n} from \"../feature-libraries/index.js\";\nimport { getTreeNodeForField, prepareContentForHydration } from \"./proxies.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\tgetStoredKey,\n\tgetExplicitStoredKey,\n\ttype TreeFieldFromImplicitField,\n\ttype InsertableTreeFieldFromImplicitField,\n\ttype FieldSchema,\n\tnormalizeFieldSchema,\n\ttype ImplicitAllowedTypes,\n\tFieldKind,\n\ttype NodeSchemaMetadata,\n} from \"./schemaTypes.js\";\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\tUnhydratedFlexTreeNode,\n\tgetOrCreateInnerNode,\n} from \"./core/index.js\";\nimport { mapTreeFromNodeData, type InsertableContent } from \"./toMapTree.js\";\nimport { type RestrictiveStringRecord, fail, type FlattenKeys } from \"../util/index.js\";\nimport {\n\tisObjectNodeSchema,\n\ttype ObjectNodeSchema,\n\ttype ObjectNodeSchemaInternalData,\n} from \"./objectNodeTypes.js\";\nimport { TreeNodeValid, type MostDerivedData } from \"./treeNodeValid.js\";\nimport { getUnhydratedContext } from \"./createContext.js\";\n\n/**\n * Generates the properties for an ObjectNode from its field schema object.\n * @system @public\n */\nexport type ObjectFromSchemaRecord<T extends RestrictiveStringRecord<ImplicitFieldSchema>> = {\n\t-readonly [Property in keyof T]: Property extends string\n\t\t? TreeFieldFromImplicitField<T[Property]>\n\t\t: unknown;\n};\n\n/**\n * A {@link TreeNode} which modules a JavaScript object.\n * @remarks\n * Object nodes consist of a type which specifies which {@link TreeNodeSchema} they use (see {@link TreeNodeApi.schema}), 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 * @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 whether or not an implicit field schema has a default value.\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 FieldSchema<\n\tFieldKind.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 * @system @public\n */\nexport type InsertableObjectFromSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> = Record<string, never> extends T\n\t? Record<string, never>\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 * 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 * @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\n\t\t\tif (fieldInfo !== undefined) {\n\t\t\t\tconst flexNode = getOrCreateInnerNode(proxy);\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\t// TODO: this special case logic should move to the inner node (who's schema claims it has an identifier), rather than here, after we already read undefined out of a required field.\n\t\t\t\t// Check if the user is trying to read an identifier field of an unhydrated node, but the identifier is not present.\n\t\t\t\t// This means the identifier is an \"auto-generated identifier\", because otherwise it would have been supplied by the user at construction time and would have been successfully read just above.\n\t\t\t\t// In this case, it is categorically impossible to provide an identifier (auto-generated identifiers can't be created until hydration/insertion time), so we emit an error.\n\t\t\t\tif (\n\t\t\t\t\tfieldInfo.schema.kind === FieldKind.Identifier &&\n\t\t\t\t\tflexNode instanceof UnhydratedFlexTreeNode\n\t\t\t\t) {\n\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\"An automatically generated node identifier may not be queried until the node is inserted into the tree\",\n\t\t\t\t\t);\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 = mapTreeFromNodeData(\n\t\tvalue,\n\t\tsimpleFieldSchema,\n\t\tfield.context.isHydrated() ? field.context.nodeKeyManager : undefined,\n\t\tgetSchemaAndPolicy(field),\n\t);\n\n\tif (field.context.isHydrated()) {\n\t\tprepareContentForHydration(mapTree, field.context.checkout.forest);\n\t}\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<ImplicitFieldSchema>,\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// 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\n\tlet handler: ProxyHandler<object>;\n\tlet customizable: boolean;\n\tlet unhydratedContext: Context;\n\n\tclass CustomObjectNode extends CustomObjectNodeBase<T> {\n\t\tpublic static readonly fields: ReadonlyMap<string, FieldSchema> = new Map(\n\t\t\tArray.from(flexKeyMap, ([key, value]) => [key as string, value.schema]),\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 UnhydratedFlexTreeNode.getOrCreate(\n\t\t\t\tunhydratedContext,\n\t\t\t\tmapTreeFromNodeData(input as object, this as unknown as ImplicitAllowedTypes),\n\t\t\t);\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> | undefined =\n\t\t\tmetadata;\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: InsertableObjectFromSchemaRecord<T> | InternalTreeNode,\n\t\t) => TreeObjectNode<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"]}
@@ -34,7 +34,7 @@ function getTreeNodeForField(field) {
34
34
  return field.content;
35
35
  }
36
36
  default:
37
- (0, index_js_3.fail)("invalid field kind");
37
+ (0, index_js_3.fail)(0xadf /* invalid field kind */);
38
38
  }
39
39
  }
40
40
  exports.getTreeNodeForField = getTreeNodeForField;
@@ -1 +1 @@
1
- {"version":3,"file":"proxies.js","sourceRoot":"","sources":["../../src/simple-tree/proxies.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAEtE,+CAM0B;AAE1B,4DAMuC;AACvC,+CAAuE;AACvE,8CAMyB;AAEzB;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAoB;IACvD,SAAS,gBAAgB,CACxB,SAAwD;QAExD,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC;QACvC,OAAO,IAAA,yBAAc,EAAC,YAAY,CAAC;YAClC,CAAC,CAAC,IAAA,uCAA4B,EAAC,YAAY,CAAC;YAC5C,CAAC,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AK,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC5B,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,iDAAiD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\ttype IForestSubscription,\n\ttype MapTree,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../core/index.js\";\n\nimport {\n\tFieldKinds,\n\ttype FlexTreeField,\n\tisFlexTreeNode,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeOptionalField,\n} from \"../feature-libraries/index.js\";\nimport { type Mutable, fail, isReadonlyArray } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype TreeNode,\n\tgetOrCreateNodeFromInnerNode,\n\ttryUnhydratedFlexTreeNode,\n\tunhydratedFlexTreeNodeToTreeNode,\n} from \"./core/index.js\";\n\n/**\n * Retrieve the associated {@link TreeNode} for the given field's content.\n */\nexport function getTreeNodeForField(field: FlexTreeField): TreeNode | TreeValue | undefined {\n\tfunction tryToUnboxLeaves(\n\t\tflexField: FlexTreeOptionalField | FlexTreeRequiredField,\n\t): TreeNode | TreeValue | undefined {\n\t\tconst maybeContent = flexField.content;\n\t\treturn isFlexTreeNode(maybeContent)\n\t\t\t? getOrCreateNodeFromInnerNode(maybeContent)\n\t\t\t: maybeContent;\n\t}\n\tswitch (field.schema) {\n\t\tcase FieldKinds.required.identifier: {\n\t\t\tconst typedField = field as FlexTreeRequiredField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.optional.identifier: {\n\t\t\tconst typedField = field as FlexTreeOptionalField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.identifier.identifier: {\n\t\t\t// Identifier fields are just value fields that hold strings\n\t\t\treturn (field as FlexTreeRequiredField).content as string;\n\t\t}\n\n\t\tdefault:\n\t\t\tfail(\"invalid field kind\");\n\t}\n}\n\n// #region Content insertion and proxy binding\n\n/** The path of a proxy, relative to the root of the content tree that the proxy belongs to */\ninterface RelativeProxyPath {\n\treadonly path: UpPath;\n\treadonly proxy: TreeNode;\n}\n\n/** All {@link RelativeProxyPath}s that are under the given root path */\ninterface RootedProxyPaths {\n\treadonly rootPath: UpPath;\n\treadonly proxyPaths: RelativeProxyPath[];\n}\n\n/**\n * Records any proxies in the given content tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * @remarks If the content tree contains any proxies, 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 * @param content - the tree of content to be inserted, of which any of its object/map/array nodes might be a proxy\n * @param anchors - the {@link AnchorSet} for the tree\n * @returns The content after having all proxies replaced inline with plain javascript objects.\n * See {@link extractFactoryContent} for more details.\n */\nexport function prepareContentForHydration(\n\tcontent: MapTree | readonly MapTree[] | undefined,\n\tforest: IForestSubscription,\n): void {\n\tif (isReadonlyArray(content)) {\n\t\treturn prepareArrayContentForHydration(content, forest);\n\t}\n\n\tif (content !== undefined) {\n\t\tconst proxies: RootedProxyPaths = {\n\t\t\trootPath: { parent: undefined, parentField: EmptyKey, parentIndex: 0 },\n\t\t\tproxyPaths: [],\n\t\t};\n\n\t\twalkMapTree(content, proxies.rootPath, (p, proxy) => {\n\t\t\tproxies.proxyPaths.push({ path: p, proxy });\n\t\t});\n\n\t\tbindProxies([proxies], forest);\n\t}\n}\n\nfunction prepareArrayContentForHydration(\n\tcontent: readonly MapTree[],\n\tforest: IForestSubscription,\n): void {\n\tconst proxyPaths: RootedProxyPaths[] = [];\n\tfor (const item of content) {\n\t\tconst proxyPath: RootedProxyPaths = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: EmptyKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tproxyPaths: [],\n\t\t};\n\t\tproxyPaths.push(proxyPath);\n\t\twalkMapTree(item, proxyPath.rootPath, (p, proxy) => {\n\t\t\tproxyPath.proxyPaths.push({ path: p, proxy });\n\t\t});\n\t}\n\n\tbindProxies(proxyPaths, forest);\n}\n\nfunction walkMapTree(\n\tmapTree: MapTree,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n): void {\n\tif (tryUnhydratedFlexTreeNode(mapTree)?.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: MapTree];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, mapTree]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, m] = next;\n\t\tconst mapTreeNode = tryUnhydratedFlexTreeNode(m);\n\t\tif (mapTreeNode !== undefined) {\n\t\t\tconst treeNode = unhydratedFlexTreeNodeToTreeNode.get(mapTreeNode);\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 m.fields) {\n\t\t\tfor (const [i, child] of field.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\nfunction bindProxies(proxies: RootedProxyPaths[], forest: IForestSubscription): void {\n\t// Only subscribe to the event if there is at least one proxy tree to hydrate - this is not the case when inserting an empty array [].\n\tif (proxies.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// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t(proxies[i]!.rootPath as Mutable<UpPath>).parentField = fieldKey;\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tfor (const { path, proxy } of proxies[i]!.proxyPaths) {\n\t\t\t\tgetKernel(proxy).anchorProxy(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === proxies.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n\n// #endregion Content insertion and proxy binding\n"]}
1
+ {"version":3,"file":"proxies.js","sourceRoot":"","sources":["../../src/simple-tree/proxies.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,uEAAsE;AAEtE,+CAM0B;AAE1B,4DAMuC;AACvC,+CAAuE;AACvE,8CAMyB;AAEzB;;GAEG;AACH,SAAgB,mBAAmB,CAAC,KAAoB;IACvD,SAAS,gBAAgB,CACxB,SAAwD;QAExD,MAAM,YAAY,GAAG,SAAS,CAAC,OAAO,CAAC;QACvC,OAAO,IAAA,yBAAc,EAAC,YAAY,CAAC;YAClC,CAAC,CAAC,IAAA,uCAA4B,EAAC,YAAY,CAAC;YAC5C,CAAC,CAAC,YAAY,CAAC;IACjB,CAAC;IACD,QAAQ,KAAK,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,qBAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;YACrC,MAAM,UAAU,GAAG,KAA8B,CAAC;YAClD,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,qBAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC,CAAC;YACrC,MAAM,UAAU,GAAG,KAA8B,CAAC;YAClD,OAAO,gBAAgB,CAAC,UAAU,CAAC,CAAC;QACrC,CAAC;QACD,KAAK,qBAAU,CAAC,UAAU,CAAC,UAAU,CAAC,C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,IAAI,CAAC;oBACV;wBACC,MAAM,EAAE,CAAC;wBACT,WAAW,EAAE,GAAG;wBAChB,WAAW,EAAE,CAAC;qBACd;oBACD,KAAK;iBACL,CAAC,CAAC;YACJ,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,WAAW,CAAC,OAA2B,EAAE,MAA2B;IAC5E,sIAAsI;IACtI,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,8GAA8G;QAC9G,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,uBAAuB,EAAE,CAAC,QAAQ,EAAE,EAAE;YAClE,4DAA4D;YAC5D,oEAAoE;YACnE,OAAO,CAAC,CAAC,CAAE,CAAC,QAA4B,CAAC,WAAW,GAAG,QAAQ,CAAC;YACjE,4DAA4D;YAC5D,oEAAoE;YACpE,KAAK,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,OAAO,CAAC,CAAC,CAAE,CAAC,UAAU,EAAE,CAAC;gBACtD,IAAA,oBAAS,EAAC,KAAK,CAAC,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YACpD,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC;gBAC5B,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC;AAED,iDAAiD","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tEmptyKey,\n\ttype IForestSubscription,\n\ttype MapTree,\n\ttype TreeValue,\n\ttype UpPath,\n} from \"../core/index.js\";\n\nimport {\n\tFieldKinds,\n\ttype FlexTreeField,\n\tisFlexTreeNode,\n\ttype FlexTreeRequiredField,\n\ttype FlexTreeOptionalField,\n} from \"../feature-libraries/index.js\";\nimport { type Mutable, fail, isReadonlyArray } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype TreeNode,\n\tgetOrCreateNodeFromInnerNode,\n\ttryUnhydratedFlexTreeNode,\n\tunhydratedFlexTreeNodeToTreeNode,\n} from \"./core/index.js\";\n\n/**\n * Retrieve the associated {@link TreeNode} for the given field's content.\n */\nexport function getTreeNodeForField(field: FlexTreeField): TreeNode | TreeValue | undefined {\n\tfunction tryToUnboxLeaves(\n\t\tflexField: FlexTreeOptionalField | FlexTreeRequiredField,\n\t): TreeNode | TreeValue | undefined {\n\t\tconst maybeContent = flexField.content;\n\t\treturn isFlexTreeNode(maybeContent)\n\t\t\t? getOrCreateNodeFromInnerNode(maybeContent)\n\t\t\t: maybeContent;\n\t}\n\tswitch (field.schema) {\n\t\tcase FieldKinds.required.identifier: {\n\t\t\tconst typedField = field as FlexTreeRequiredField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.optional.identifier: {\n\t\t\tconst typedField = field as FlexTreeOptionalField;\n\t\t\treturn tryToUnboxLeaves(typedField);\n\t\t}\n\t\tcase FieldKinds.identifier.identifier: {\n\t\t\t// Identifier fields are just value fields that hold strings\n\t\t\treturn (field as FlexTreeRequiredField).content as string;\n\t\t}\n\n\t\tdefault:\n\t\t\tfail(0xadf /* invalid field kind */);\n\t}\n}\n\n// #region Content insertion and proxy binding\n\n/** The path of a proxy, relative to the root of the content tree that the proxy belongs to */\ninterface RelativeProxyPath {\n\treadonly path: UpPath;\n\treadonly proxy: TreeNode;\n}\n\n/** All {@link RelativeProxyPath}s that are under the given root path */\ninterface RootedProxyPaths {\n\treadonly rootPath: UpPath;\n\treadonly proxyPaths: RelativeProxyPath[];\n}\n\n/**\n * Records any proxies in the given content tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * @remarks If the content tree contains any proxies, 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 * @param content - the tree of content to be inserted, of which any of its object/map/array nodes might be a proxy\n * @param anchors - the {@link AnchorSet} for the tree\n * @returns The content after having all proxies replaced inline with plain javascript objects.\n * See {@link extractFactoryContent} for more details.\n */\nexport function prepareContentForHydration(\n\tcontent: MapTree | readonly MapTree[] | undefined,\n\tforest: IForestSubscription,\n): void {\n\tif (isReadonlyArray(content)) {\n\t\treturn prepareArrayContentForHydration(content, forest);\n\t}\n\n\tif (content !== undefined) {\n\t\tconst proxies: RootedProxyPaths = {\n\t\t\trootPath: { parent: undefined, parentField: EmptyKey, parentIndex: 0 },\n\t\t\tproxyPaths: [],\n\t\t};\n\n\t\twalkMapTree(content, proxies.rootPath, (p, proxy) => {\n\t\t\tproxies.proxyPaths.push({ path: p, proxy });\n\t\t});\n\n\t\tbindProxies([proxies], forest);\n\t}\n}\n\nfunction prepareArrayContentForHydration(\n\tcontent: readonly MapTree[],\n\tforest: IForestSubscription,\n): void {\n\tconst proxyPaths: RootedProxyPaths[] = [];\n\tfor (const item of content) {\n\t\tconst proxyPath: RootedProxyPaths = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: EmptyKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tproxyPaths: [],\n\t\t};\n\t\tproxyPaths.push(proxyPath);\n\t\twalkMapTree(item, proxyPath.rootPath, (p, proxy) => {\n\t\t\tproxyPath.proxyPaths.push({ path: p, proxy });\n\t\t});\n\t}\n\n\tbindProxies(proxyPaths, forest);\n}\n\nfunction walkMapTree(\n\tmapTree: MapTree,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n): void {\n\tif (tryUnhydratedFlexTreeNode(mapTree)?.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: MapTree];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, mapTree]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, m] = next;\n\t\tconst mapTreeNode = tryUnhydratedFlexTreeNode(m);\n\t\tif (mapTreeNode !== undefined) {\n\t\t\tconst treeNode = unhydratedFlexTreeNodeToTreeNode.get(mapTreeNode);\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 m.fields) {\n\t\t\tfor (const [i, child] of field.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\nfunction bindProxies(proxies: RootedProxyPaths[], forest: IForestSubscription): void {\n\t// Only subscribe to the event if there is at least one proxy tree to hydrate - this is not the case when inserting an empty array [].\n\tif (proxies.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// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\t(proxies[i]!.rootPath as Mutable<UpPath>).parentField = fieldKey;\n\t\t\t// Non null asserting here because of the length check above\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tfor (const { path, proxy } of proxies[i]!.proxyPaths) {\n\t\t\t\tgetKernel(proxy).anchorProxy(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === proxies.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n\n// #endregion Content insertion and proxy binding\n"]}
@@ -85,7 +85,7 @@ function nodeDataToMapTree(data, allowedTypes) {
85
85
  result = objectToMapTree(data, schema);
86
86
  break;
87
87
  default:
88
- (0, index_js_3.fail)("Unrecognized schema kind");
88
+ (0, index_js_3.fail)(0xae0 /* Unrecognized schema kind */);
89
89
  }
90
90
  return result;
91
91
  }
@@ -441,7 +441,7 @@ function allowsValue(schema, value) {
441
441
  */
442
442
  function addDefaultsToMapTree(mapTree, allowedTypes, context) {
443
443
  const schema = (0, index_js_3.find)((0, schemaTypes_js_1.normalizeAllowedTypes)(allowedTypes), (s) => s.identifier === mapTree.type) ??
444
- (0, index_js_3.fail)("MapTree is incompatible with schema");
444
+ (0, index_js_3.fail)(0xae1 /* MapTree is incompatible with schema */);
445
445
  if ((0, objectNodeTypes_js_1.isObjectNodeSchema)(schema)) {
446
446
  for (const [_key, fieldInfo] of schema.flexKeyMap) {
447
447
  const field = mapTree.fields.get(fieldInfo.storedKey);
@@ -459,7 +459,7 @@ function addDefaultsToMapTree(mapTree, allowedTypes, context) {
459
459
  setFieldValue(mapTree.fields, data, fieldInfo.schema, fieldInfo.storedKey);
460
460
  // call addDefaultsToMapTree on newly inserted default values
461
461
  for (const child of mapTree.fields.get(fieldInfo.storedKey) ??
462
- (0, index_js_3.fail)("Expected field to be populated")) {
462
+ (0, index_js_3.fail)(0xae2 /* Expected field to be populated */)) {
463
463
  addDefaultsToMapTree(child, fieldInfo.schema.allowedTypes, context);
464
464
  }
465
465
  }