@fluidframework/tree 2.81.1 → 2.83.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 (695) hide show
  1. package/CHANGELOG.md +168 -0
  2. package/README.md +33 -5
  3. package/api-report/tree.alpha.api.md +75 -39
  4. package/api-report/tree.beta.api.md +164 -3
  5. package/api-report/tree.legacy.beta.api.md +164 -3
  6. package/api-report/tree.legacy.public.api.md +2 -1
  7. package/api-report/tree.public.api.md +2 -1
  8. package/dist/alpha.d.ts +10 -4
  9. package/dist/beta.d.ts +4 -0
  10. package/dist/codec/codec.d.ts +18 -45
  11. package/dist/codec/codec.d.ts.map +1 -1
  12. package/dist/codec/codec.js +12 -50
  13. package/dist/codec/codec.js.map +1 -1
  14. package/dist/codec/index.d.ts +1 -1
  15. package/dist/codec/index.d.ts.map +1 -1
  16. package/dist/codec/index.js +2 -2
  17. package/dist/codec/index.js.map +1 -1
  18. package/dist/codec/versioned/codec.d.ts +20 -7
  19. package/dist/codec/versioned/codec.d.ts.map +1 -1
  20. package/dist/codec/versioned/codec.js +56 -30
  21. package/dist/codec/versioned/codec.js.map +1 -1
  22. package/dist/core/index.d.ts +1 -1
  23. package/dist/core/index.d.ts.map +1 -1
  24. package/dist/core/index.js +4 -2
  25. package/dist/core/index.js.map +1 -1
  26. package/dist/core/rebase/changeRebaser.d.ts +3 -2
  27. package/dist/core/rebase/changeRebaser.d.ts.map +1 -1
  28. package/dist/core/rebase/changeRebaser.js.map +1 -1
  29. package/dist/core/rebase/index.d.ts +1 -1
  30. package/dist/core/rebase/index.d.ts.map +1 -1
  31. package/dist/core/rebase/index.js +4 -2
  32. package/dist/core/rebase/index.js.map +1 -1
  33. package/dist/core/rebase/types.d.ts +23 -3
  34. package/dist/core/rebase/types.d.ts.map +1 -1
  35. package/dist/core/rebase/types.js +30 -16
  36. package/dist/core/rebase/types.js.map +1 -1
  37. package/dist/core/schema-stored/formatV1.d.ts +2 -2
  38. package/dist/core/schema-stored/formatV1.d.ts.map +1 -1
  39. package/dist/core/schema-stored/formatV1.js +0 -5
  40. package/dist/core/schema-stored/formatV1.js.map +1 -1
  41. package/dist/core/schema-stored/formatV2.d.ts +11 -10
  42. package/dist/core/schema-stored/formatV2.d.ts.map +1 -1
  43. package/dist/core/schema-stored/formatV2.js +1 -6
  44. package/dist/core/schema-stored/formatV2.js.map +1 -1
  45. package/dist/core/schema-stored/index.d.ts.map +1 -1
  46. package/dist/core/schema-stored/index.js.map +1 -1
  47. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  48. package/dist/core/schema-stored/schema.js.map +1 -1
  49. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  50. package/dist/core/tree/anchorSet.js.map +1 -1
  51. package/dist/core/tree/delta.d.ts +9 -7
  52. package/dist/core/tree/delta.d.ts.map +1 -1
  53. package/dist/core/tree/delta.js.map +1 -1
  54. package/dist/core/tree/deltaUtil.js +1 -1
  55. package/dist/core/tree/deltaUtil.js.map +1 -1
  56. package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  57. package/dist/core/tree/detachedFieldIndexCodecs.js +6 -4
  58. package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  59. package/dist/core/tree/visitDelta.js +2 -2
  60. package/dist/core/tree/visitDelta.js.map +1 -1
  61. package/dist/extensibleUnionNode.d.ts +97 -0
  62. package/dist/extensibleUnionNode.d.ts.map +1 -0
  63. package/dist/extensibleUnionNode.js +89 -0
  64. package/dist/extensibleUnionNode.js.map +1 -0
  65. package/dist/feature-libraries/changeAtomIdBTree.d.ts +4 -2
  66. package/dist/feature-libraries/changeAtomIdBTree.d.ts.map +1 -1
  67. package/dist/feature-libraries/changeAtomIdBTree.js +9 -1
  68. package/dist/feature-libraries/changeAtomIdBTree.js.map +1 -1
  69. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +1 -1
  70. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  71. package/dist/feature-libraries/chunked-forest/codec/codecs.js +4 -4
  72. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  73. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -3
  74. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  75. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +20 -21
  76. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  77. package/dist/feature-libraries/default-schema/index.d.ts +1 -1
  78. package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
  79. package/dist/feature-libraries/default-schema/index.js.map +1 -1
  80. package/dist/feature-libraries/forest-summary/codec.d.ts +2 -1
  81. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  82. package/dist/feature-libraries/forest-summary/codec.js +7 -1
  83. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  84. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  85. package/dist/feature-libraries/forest-summary/forestSummarizer.js +5 -2
  86. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  87. package/dist/feature-libraries/forest-summary/formatCommon.d.ts +4 -42
  88. package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  89. package/dist/feature-libraries/forest-summary/formatCommon.js +1 -2
  90. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  91. package/dist/feature-libraries/forest-summary/formatV1.d.ts +2 -41
  92. package/dist/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
  93. package/dist/feature-libraries/forest-summary/formatV1.js +1 -2
  94. package/dist/feature-libraries/forest-summary/formatV1.js.map +1 -1
  95. package/dist/feature-libraries/forest-summary/formatV2.d.ts +2 -41
  96. package/dist/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
  97. package/dist/feature-libraries/forest-summary/formatV2.js +1 -2
  98. package/dist/feature-libraries/forest-summary/formatV2.js.map +1 -1
  99. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +1 -1
  100. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  101. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +1 -1
  102. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  103. package/dist/feature-libraries/index.d.ts +3 -3
  104. package/dist/feature-libraries/index.d.ts.map +1 -1
  105. package/dist/feature-libraries/index.js +4 -3
  106. package/dist/feature-libraries/index.js.map +1 -1
  107. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +2 -2
  108. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -1
  109. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js +42 -22
  110. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  111. package/dist/feature-libraries/modular-schema/genericFieldKind.js +1 -1
  112. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  113. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  114. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  115. package/dist/feature-libraries/modular-schema/index.js +2 -1
  116. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  117. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +3 -3
  118. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  119. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +13 -9
  120. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  121. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +11 -1
  122. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  123. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +30 -7
  124. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  125. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  126. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +38 -27
  127. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  128. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +10 -127
  129. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  130. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -4
  131. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  132. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +3 -79
  133. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  134. package/dist/feature-libraries/optional-field/optionalField.js +1 -1
  135. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  136. package/dist/feature-libraries/optional-field/requiredField.d.ts.map +1 -1
  137. package/dist/feature-libraries/optional-field/requiredField.js.map +1 -1
  138. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  139. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  140. package/dist/feature-libraries/schema-index/codec.js +6 -4
  141. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  142. package/dist/feature-libraries/schema-index/formatV2.d.ts +4 -4
  143. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  144. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  145. package/dist/feature-libraries/sequence-field/invert.js +2 -2
  146. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  147. package/dist/feature-libraries/sequence-field/replaceRevisions.js +16 -16
  148. package/dist/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  149. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -1
  150. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  151. package/dist/index.d.ts +5 -5
  152. package/dist/index.d.ts.map +1 -1
  153. package/dist/index.js +5 -2
  154. package/dist/index.js.map +1 -1
  155. package/dist/legacy.d.ts +4 -0
  156. package/dist/packageVersion.d.ts +1 -1
  157. package/dist/packageVersion.js +1 -1
  158. package/dist/packageVersion.js.map +1 -1
  159. package/dist/shared-tree/independentView.d.ts +36 -13
  160. package/dist/shared-tree/independentView.d.ts.map +1 -1
  161. package/dist/shared-tree/independentView.js +1 -0
  162. package/dist/shared-tree/independentView.js.map +1 -1
  163. package/dist/shared-tree/index.d.ts +1 -1
  164. package/dist/shared-tree/index.d.ts.map +1 -1
  165. package/dist/shared-tree/index.js.map +1 -1
  166. package/dist/shared-tree/schematizingTreeView.d.ts +10 -0
  167. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  168. package/dist/shared-tree/schematizingTreeView.js +25 -9
  169. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  170. package/dist/shared-tree/sharedTree.d.ts +3 -3
  171. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  172. package/dist/shared-tree/sharedTree.js +8 -32
  173. package/dist/shared-tree/sharedTree.js.map +1 -1
  174. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +11 -3
  175. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  176. package/dist/shared-tree/sharedTreeChangeCodecs.js +39 -5
  177. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  178. package/dist/shared-tree/sharedTreeChangeFormat.d.ts +4 -4
  179. package/dist/shared-tree/tree.d.ts +1 -1
  180. package/dist/shared-tree/tree.js +1 -1
  181. package/dist/shared-tree/tree.js.map +1 -1
  182. package/dist/shared-tree/treeAlpha.d.ts +1 -1
  183. package/dist/shared-tree/treeAlpha.js.map +1 -1
  184. package/dist/shared-tree/treeCheckout.d.ts +20 -0
  185. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  186. package/dist/shared-tree/treeCheckout.js +41 -7
  187. package/dist/shared-tree/treeCheckout.js.map +1 -1
  188. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +3 -3
  189. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  190. package/dist/shared-tree-core/editManagerCodecsCommons.js +2 -2
  191. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  192. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +2 -2
  193. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  194. package/dist/shared-tree-core/editManagerCodecsV1toV4.js +1 -1
  195. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  196. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +2 -2
  197. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  198. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js +1 -1
  199. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  200. package/dist/shared-tree-core/editManagerSummarizer.js +1 -1
  201. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  202. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  203. package/dist/shared-tree-core/messageCodecV1ToV4.js +2 -2
  204. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  205. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  206. package/dist/shared-tree-core/messageCodecs.js +2 -2
  207. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  208. package/dist/shared-tree-core/transaction.d.ts +14 -3
  209. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  210. package/dist/shared-tree-core/transaction.js +59 -16
  211. package/dist/shared-tree-core/transaction.js.map +1 -1
  212. package/dist/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  213. package/dist/shared-tree-core/versionedSummarizer.js +1 -1
  214. package/dist/shared-tree-core/versionedSummarizer.js.map +1 -1
  215. package/dist/simple-tree/api/index.d.ts +2 -2
  216. package/dist/simple-tree/api/index.d.ts.map +1 -1
  217. package/dist/simple-tree/api/index.js +4 -3
  218. package/dist/simple-tree/api/index.js.map +1 -1
  219. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +9 -0
  220. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  221. package/dist/simple-tree/api/schemaCreationUtilities.js +16 -1
  222. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  223. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  224. package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts +148 -29
  225. package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
  226. package/dist/simple-tree/api/snapshotCompatibilityChecker.js +180 -99
  227. package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  228. package/dist/simple-tree/api/transactionTypes.d.ts +10 -0
  229. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  230. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  231. package/dist/simple-tree/api/tree.d.ts +82 -7
  232. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  233. package/dist/simple-tree/api/tree.js.map +1 -1
  234. package/dist/simple-tree/api/treeBeta.d.ts +1 -1
  235. package/dist/simple-tree/api/treeBeta.js.map +1 -1
  236. package/dist/simple-tree/core/allowedTypes.d.ts +1 -1
  237. package/dist/simple-tree/core/allowedTypes.js.map +1 -1
  238. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  239. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  240. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +1 -0
  241. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  242. package/dist/simple-tree/core/unhydratedFlexTree.js +29 -0
  243. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  244. package/dist/simple-tree/index.d.ts +2 -2
  245. package/dist/simple-tree/index.d.ts.map +1 -1
  246. package/dist/simple-tree/index.js +5 -3
  247. package/dist/simple-tree/index.js.map +1 -1
  248. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  249. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  250. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +63 -0
  251. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  252. package/dist/simple-tree/node-kinds/array/arrayNode.js +47 -14
  253. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  254. package/dist/simple-tree/node-kinds/array/index.d.ts +1 -1
  255. package/dist/simple-tree/node-kinds/array/index.d.ts.map +1 -1
  256. package/dist/simple-tree/node-kinds/array/index.js +2 -1
  257. package/dist/simple-tree/node-kinds/array/index.js.map +1 -1
  258. package/dist/simple-tree/node-kinds/index.d.ts +1 -1
  259. package/dist/simple-tree/node-kinds/index.d.ts.map +1 -1
  260. package/dist/simple-tree/node-kinds/index.js +2 -1
  261. package/dist/simple-tree/node-kinds/index.js.map +1 -1
  262. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  263. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  264. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
  265. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js +33 -7
  266. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  267. package/dist/tableSchema.d.ts +71 -48
  268. package/dist/tableSchema.d.ts.map +1 -1
  269. package/dist/tableSchema.js +200 -98
  270. package/dist/tableSchema.js.map +1 -1
  271. package/dist/text/textDomainFormatted.d.ts +3 -3
  272. package/dist/text/textDomainFormatted.d.ts.map +1 -1
  273. package/dist/text/textDomainFormatted.js +48 -32
  274. package/dist/text/textDomainFormatted.js.map +1 -1
  275. package/dist/util/bTreeUtils.d.ts +30 -4
  276. package/dist/util/bTreeUtils.d.ts.map +1 -1
  277. package/dist/util/bTreeUtils.js +35 -23
  278. package/dist/util/bTreeUtils.js.map +1 -1
  279. package/dist/util/brand.d.ts.map +1 -1
  280. package/dist/util/brand.js.map +1 -1
  281. package/dist/util/brandedMap.d.ts.map +1 -1
  282. package/dist/util/brandedMap.js.map +1 -1
  283. package/dist/util/breakable.d.ts.map +1 -1
  284. package/dist/util/breakable.js +2 -1
  285. package/dist/util/breakable.js.map +1 -1
  286. package/dist/util/index.d.ts +2 -2
  287. package/dist/util/index.d.ts.map +1 -1
  288. package/dist/util/index.js +6 -3
  289. package/dist/util/index.js.map +1 -1
  290. package/dist/util/opaque.d.ts.map +1 -1
  291. package/dist/util/opaque.js.map +1 -1
  292. package/dist/util/rangeMap.d.ts +3 -2
  293. package/dist/util/rangeMap.d.ts.map +1 -1
  294. package/dist/util/rangeMap.js +12 -7
  295. package/dist/util/rangeMap.js.map +1 -1
  296. package/dist/util/readSnapshotBlob.d.ts +1 -1
  297. package/dist/util/readSnapshotBlob.d.ts.map +1 -1
  298. package/dist/util/readSnapshotBlob.js.map +1 -1
  299. package/dist/util/typeCheck.d.ts.map +1 -1
  300. package/dist/util/typeCheck.js.map +1 -1
  301. package/dist/util/utils.d.ts +20 -16
  302. package/dist/util/utils.d.ts.map +1 -1
  303. package/dist/util/utils.js +49 -17
  304. package/dist/util/utils.js.map +1 -1
  305. package/eslint.config.mts +0 -9
  306. package/lib/alpha.d.ts +10 -4
  307. package/lib/beta.d.ts +4 -0
  308. package/lib/codec/codec.d.ts +18 -45
  309. package/lib/codec/codec.d.ts.map +1 -1
  310. package/lib/codec/codec.js +10 -47
  311. package/lib/codec/codec.js.map +1 -1
  312. package/lib/codec/index.d.ts +1 -1
  313. package/lib/codec/index.d.ts.map +1 -1
  314. package/lib/codec/index.js +1 -1
  315. package/lib/codec/index.js.map +1 -1
  316. package/lib/codec/versioned/codec.d.ts +20 -7
  317. package/lib/codec/versioned/codec.d.ts.map +1 -1
  318. package/lib/codec/versioned/codec.js +59 -33
  319. package/lib/codec/versioned/codec.js.map +1 -1
  320. package/lib/core/index.d.ts +1 -1
  321. package/lib/core/index.d.ts.map +1 -1
  322. package/lib/core/index.js +1 -1
  323. package/lib/core/index.js.map +1 -1
  324. package/lib/core/rebase/changeRebaser.d.ts +3 -2
  325. package/lib/core/rebase/changeRebaser.d.ts.map +1 -1
  326. package/lib/core/rebase/changeRebaser.js.map +1 -1
  327. package/lib/core/rebase/index.d.ts +1 -1
  328. package/lib/core/rebase/index.d.ts.map +1 -1
  329. package/lib/core/rebase/index.js +1 -1
  330. package/lib/core/rebase/index.js.map +1 -1
  331. package/lib/core/rebase/types.d.ts +23 -3
  332. package/lib/core/rebase/types.d.ts.map +1 -1
  333. package/lib/core/rebase/types.js +27 -15
  334. package/lib/core/rebase/types.js.map +1 -1
  335. package/lib/core/schema-stored/formatV1.d.ts +2 -2
  336. package/lib/core/schema-stored/formatV1.d.ts.map +1 -1
  337. package/lib/core/schema-stored/formatV1.js +0 -5
  338. package/lib/core/schema-stored/formatV1.js.map +1 -1
  339. package/lib/core/schema-stored/formatV2.d.ts +11 -10
  340. package/lib/core/schema-stored/formatV2.d.ts.map +1 -1
  341. package/lib/core/schema-stored/formatV2.js +1 -6
  342. package/lib/core/schema-stored/formatV2.js.map +1 -1
  343. package/lib/core/schema-stored/index.d.ts.map +1 -1
  344. package/lib/core/schema-stored/index.js +2 -0
  345. package/lib/core/schema-stored/index.js.map +1 -1
  346. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  347. package/lib/core/schema-stored/schema.js.map +1 -1
  348. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  349. package/lib/core/tree/anchorSet.js.map +1 -1
  350. package/lib/core/tree/delta.d.ts +9 -7
  351. package/lib/core/tree/delta.d.ts.map +1 -1
  352. package/lib/core/tree/delta.js.map +1 -1
  353. package/lib/core/tree/deltaUtil.js +1 -1
  354. package/lib/core/tree/deltaUtil.js.map +1 -1
  355. package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  356. package/lib/core/tree/detachedFieldIndexCodecs.js +6 -4
  357. package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  358. package/lib/core/tree/visitDelta.js +2 -2
  359. package/lib/core/tree/visitDelta.js.map +1 -1
  360. package/lib/extensibleUnionNode.d.ts +97 -0
  361. package/lib/extensibleUnionNode.d.ts.map +1 -0
  362. package/lib/extensibleUnionNode.js +86 -0
  363. package/lib/extensibleUnionNode.js.map +1 -0
  364. package/lib/feature-libraries/changeAtomIdBTree.d.ts +4 -2
  365. package/lib/feature-libraries/changeAtomIdBTree.d.ts.map +1 -1
  366. package/lib/feature-libraries/changeAtomIdBTree.js +7 -0
  367. package/lib/feature-libraries/changeAtomIdBTree.js.map +1 -1
  368. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +1 -1
  369. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  370. package/lib/feature-libraries/chunked-forest/codec/codecs.js +5 -5
  371. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  372. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -3
  373. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  374. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +4 -5
  375. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  376. package/lib/feature-libraries/default-schema/index.d.ts +1 -1
  377. package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
  378. package/lib/feature-libraries/default-schema/index.js.map +1 -1
  379. package/lib/feature-libraries/forest-summary/codec.d.ts +2 -1
  380. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  381. package/lib/feature-libraries/forest-summary/codec.js +8 -2
  382. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  383. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  384. package/lib/feature-libraries/forest-summary/forestSummarizer.js +6 -3
  385. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  386. package/lib/feature-libraries/forest-summary/formatCommon.d.ts +4 -42
  387. package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  388. package/lib/feature-libraries/forest-summary/formatCommon.js +2 -3
  389. package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  390. package/lib/feature-libraries/forest-summary/formatV1.d.ts +2 -41
  391. package/lib/feature-libraries/forest-summary/formatV1.d.ts.map +1 -1
  392. package/lib/feature-libraries/forest-summary/formatV1.js +1 -2
  393. package/lib/feature-libraries/forest-summary/formatV1.js.map +1 -1
  394. package/lib/feature-libraries/forest-summary/formatV2.d.ts +2 -41
  395. package/lib/feature-libraries/forest-summary/formatV2.d.ts.map +1 -1
  396. package/lib/feature-libraries/forest-summary/formatV2.js +1 -2
  397. package/lib/feature-libraries/forest-summary/formatV2.js.map +1 -1
  398. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +1 -1
  399. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  400. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +1 -1
  401. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  402. package/lib/feature-libraries/index.d.ts +3 -3
  403. package/lib/feature-libraries/index.d.ts.map +1 -1
  404. package/lib/feature-libraries/index.js +3 -3
  405. package/lib/feature-libraries/index.js.map +1 -1
  406. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +2 -2
  407. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -1
  408. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js +41 -21
  409. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  410. package/lib/feature-libraries/modular-schema/genericFieldKind.js +1 -1
  411. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  412. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  413. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  414. package/lib/feature-libraries/modular-schema/index.js +1 -1
  415. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  416. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +3 -3
  417. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  418. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +14 -10
  419. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  420. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +11 -1
  421. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  422. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +29 -6
  423. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  424. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  425. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +41 -30
  426. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  427. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +10 -127
  428. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  429. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -4
  430. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  431. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +3 -79
  432. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  433. package/lib/feature-libraries/optional-field/optionalField.js +1 -1
  434. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  435. package/lib/feature-libraries/optional-field/requiredField.d.ts.map +1 -1
  436. package/lib/feature-libraries/optional-field/requiredField.js.map +1 -1
  437. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +2 -2
  438. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  439. package/lib/feature-libraries/schema-index/codec.js +6 -4
  440. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  441. package/lib/feature-libraries/schema-index/formatV2.d.ts +4 -4
  442. package/lib/feature-libraries/schema-index/schemaSummarizer.js +1 -1
  443. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  444. package/lib/feature-libraries/sequence-field/invert.js +2 -2
  445. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  446. package/lib/feature-libraries/sequence-field/replaceRevisions.js +16 -16
  447. package/lib/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  448. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -1
  449. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  450. package/lib/index.d.ts +5 -5
  451. package/lib/index.d.ts.map +1 -1
  452. package/lib/index.js +4 -3
  453. package/lib/index.js.map +1 -1
  454. package/lib/legacy.d.ts +4 -0
  455. package/lib/packageVersion.d.ts +1 -1
  456. package/lib/packageVersion.js +1 -1
  457. package/lib/packageVersion.js.map +1 -1
  458. package/lib/shared-tree/independentView.d.ts +36 -13
  459. package/lib/shared-tree/independentView.d.ts.map +1 -1
  460. package/lib/shared-tree/independentView.js +1 -0
  461. package/lib/shared-tree/independentView.js.map +1 -1
  462. package/lib/shared-tree/index.d.ts +1 -1
  463. package/lib/shared-tree/index.d.ts.map +1 -1
  464. package/lib/shared-tree/index.js.map +1 -1
  465. package/lib/shared-tree/schematizingTreeView.d.ts +10 -0
  466. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  467. package/lib/shared-tree/schematizingTreeView.js +25 -9
  468. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  469. package/lib/shared-tree/sharedTree.d.ts +3 -3
  470. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  471. package/lib/shared-tree/sharedTree.js +10 -34
  472. package/lib/shared-tree/sharedTree.js.map +1 -1
  473. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +11 -3
  474. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  475. package/lib/shared-tree/sharedTreeChangeCodecs.js +40 -6
  476. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  477. package/lib/shared-tree/sharedTreeChangeFormat.d.ts +4 -4
  478. package/lib/shared-tree/tree.d.ts +1 -1
  479. package/lib/shared-tree/tree.js +1 -1
  480. package/lib/shared-tree/tree.js.map +1 -1
  481. package/lib/shared-tree/treeAlpha.d.ts +1 -1
  482. package/lib/shared-tree/treeAlpha.js.map +1 -1
  483. package/lib/shared-tree/treeCheckout.d.ts +20 -0
  484. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  485. package/lib/shared-tree/treeCheckout.js +41 -7
  486. package/lib/shared-tree/treeCheckout.js.map +1 -1
  487. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +3 -3
  488. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  489. package/lib/shared-tree-core/editManagerCodecsCommons.js +2 -2
  490. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  491. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +2 -2
  492. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  493. package/lib/shared-tree-core/editManagerCodecsV1toV4.js +2 -2
  494. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  495. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts +2 -2
  496. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  497. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js +2 -2
  498. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  499. package/lib/shared-tree-core/editManagerSummarizer.js +1 -1
  500. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  501. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  502. package/lib/shared-tree-core/messageCodecV1ToV4.js +2 -2
  503. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  504. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  505. package/lib/shared-tree-core/messageCodecs.js +2 -2
  506. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  507. package/lib/shared-tree-core/transaction.d.ts +14 -3
  508. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  509. package/lib/shared-tree-core/transaction.js +61 -18
  510. package/lib/shared-tree-core/transaction.js.map +1 -1
  511. package/lib/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  512. package/lib/shared-tree-core/versionedSummarizer.js +1 -1
  513. package/lib/shared-tree-core/versionedSummarizer.js.map +1 -1
  514. package/lib/simple-tree/api/index.d.ts +2 -2
  515. package/lib/simple-tree/api/index.d.ts.map +1 -1
  516. package/lib/simple-tree/api/index.js +2 -2
  517. package/lib/simple-tree/api/index.js.map +1 -1
  518. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +9 -0
  519. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  520. package/lib/simple-tree/api/schemaCreationUtilities.js +14 -0
  521. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  522. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  523. package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts +148 -29
  524. package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
  525. package/lib/simple-tree/api/snapshotCompatibilityChecker.js +179 -98
  526. package/lib/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  527. package/lib/simple-tree/api/transactionTypes.d.ts +10 -0
  528. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  529. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  530. package/lib/simple-tree/api/tree.d.ts +82 -7
  531. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  532. package/lib/simple-tree/api/tree.js.map +1 -1
  533. package/lib/simple-tree/api/treeBeta.d.ts +1 -1
  534. package/lib/simple-tree/api/treeBeta.js.map +1 -1
  535. package/lib/simple-tree/core/allowedTypes.d.ts +1 -1
  536. package/lib/simple-tree/core/allowedTypes.js.map +1 -1
  537. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  538. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  539. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +1 -0
  540. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  541. package/lib/simple-tree/core/unhydratedFlexTree.js +29 -0
  542. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  543. package/lib/simple-tree/index.d.ts +2 -2
  544. package/lib/simple-tree/index.d.ts.map +1 -1
  545. package/lib/simple-tree/index.js +2 -2
  546. package/lib/simple-tree/index.js.map +1 -1
  547. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  548. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  549. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +63 -0
  550. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  551. package/lib/simple-tree/node-kinds/array/arrayNode.js +46 -14
  552. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  553. package/lib/simple-tree/node-kinds/array/index.d.ts +1 -1
  554. package/lib/simple-tree/node-kinds/array/index.d.ts.map +1 -1
  555. package/lib/simple-tree/node-kinds/array/index.js +1 -1
  556. package/lib/simple-tree/node-kinds/array/index.js.map +1 -1
  557. package/lib/simple-tree/node-kinds/index.d.ts +1 -1
  558. package/lib/simple-tree/node-kinds/index.d.ts.map +1 -1
  559. package/lib/simple-tree/node-kinds/index.js +1 -1
  560. package/lib/simple-tree/node-kinds/index.js.map +1 -1
  561. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  562. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  563. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
  564. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js +34 -8
  565. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  566. package/lib/tableSchema.d.ts +71 -48
  567. package/lib/tableSchema.d.ts.map +1 -1
  568. package/lib/tableSchema.js +201 -99
  569. package/lib/tableSchema.js.map +1 -1
  570. package/lib/text/textDomainFormatted.d.ts +3 -3
  571. package/lib/text/textDomainFormatted.d.ts.map +1 -1
  572. package/lib/text/textDomainFormatted.js +30 -14
  573. package/lib/text/textDomainFormatted.js.map +1 -1
  574. package/lib/util/bTreeUtils.d.ts +30 -4
  575. package/lib/util/bTreeUtils.d.ts.map +1 -1
  576. package/lib/util/bTreeUtils.js +33 -22
  577. package/lib/util/bTreeUtils.js.map +1 -1
  578. package/lib/util/brand.d.ts.map +1 -1
  579. package/lib/util/brand.js.map +1 -1
  580. package/lib/util/brandedMap.d.ts.map +1 -1
  581. package/lib/util/brandedMap.js.map +1 -1
  582. package/lib/util/breakable.d.ts.map +1 -1
  583. package/lib/util/breakable.js +2 -1
  584. package/lib/util/breakable.js.map +1 -1
  585. package/lib/util/index.d.ts +2 -2
  586. package/lib/util/index.d.ts.map +1 -1
  587. package/lib/util/index.js +2 -2
  588. package/lib/util/index.js.map +1 -1
  589. package/lib/util/opaque.d.ts.map +1 -1
  590. package/lib/util/opaque.js.map +1 -1
  591. package/lib/util/rangeMap.d.ts +3 -2
  592. package/lib/util/rangeMap.d.ts.map +1 -1
  593. package/lib/util/rangeMap.js +12 -7
  594. package/lib/util/rangeMap.js.map +1 -1
  595. package/lib/util/readSnapshotBlob.d.ts +1 -1
  596. package/lib/util/readSnapshotBlob.d.ts.map +1 -1
  597. package/lib/util/readSnapshotBlob.js.map +1 -1
  598. package/lib/util/typeCheck.d.ts.map +1 -1
  599. package/lib/util/typeCheck.js.map +1 -1
  600. package/lib/util/utils.d.ts +20 -16
  601. package/lib/util/utils.d.ts.map +1 -1
  602. package/lib/util/utils.js +44 -15
  603. package/lib/util/utils.js.map +1 -1
  604. package/package.json +24 -24
  605. package/src/codec/codec.ts +33 -116
  606. package/src/codec/index.ts +2 -3
  607. package/src/codec/versioned/codec.ts +127 -95
  608. package/src/core/index.ts +3 -1
  609. package/src/core/rebase/changeRebaser.ts +3 -2
  610. package/src/core/rebase/index.ts +3 -1
  611. package/src/core/rebase/types.ts +51 -13
  612. package/src/core/schema-stored/formatV1.ts +2 -4
  613. package/src/core/schema-stored/formatV2.ts +9 -7
  614. package/src/core/schema-stored/index.ts +2 -0
  615. package/src/core/schema-stored/schema.ts +4 -1
  616. package/src/core/tree/anchorSet.ts +1 -3
  617. package/src/core/tree/delta.ts +9 -7
  618. package/src/core/tree/deltaUtil.ts +1 -1
  619. package/src/core/tree/detachedFieldIndexCodecs.ts +6 -4
  620. package/src/core/tree/visitDelta.ts +2 -2
  621. package/src/extensibleUnionNode.ts +177 -0
  622. package/src/feature-libraries/changeAtomIdBTree.ts +17 -2
  623. package/src/feature-libraries/chunked-forest/codec/codecs.ts +5 -11
  624. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +5 -6
  625. package/src/feature-libraries/default-schema/index.ts +0 -1
  626. package/src/feature-libraries/forest-summary/codec.ts +15 -9
  627. package/src/feature-libraries/forest-summary/forestSummarizer.ts +15 -3
  628. package/src/feature-libraries/forest-summary/formatCommon.ts +7 -6
  629. package/src/feature-libraries/forest-summary/formatV1.ts +1 -3
  630. package/src/feature-libraries/forest-summary/formatV2.ts +1 -3
  631. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +4 -5
  632. package/src/feature-libraries/index.ts +3 -2
  633. package/src/feature-libraries/modular-schema/defaultRevisionReplacer.ts +57 -31
  634. package/src/feature-libraries/modular-schema/genericFieldKind.ts +1 -1
  635. package/src/feature-libraries/modular-schema/index.ts +4 -1
  636. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +12 -12
  637. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +32 -7
  638. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +54 -33
  639. package/src/feature-libraries/modular-schema/modularChangeFormatV1.ts +2 -4
  640. package/src/feature-libraries/optional-field/optionalField.ts +1 -1
  641. package/src/feature-libraries/optional-field/requiredField.ts +2 -4
  642. package/src/feature-libraries/schema-index/codec.ts +7 -5
  643. package/src/feature-libraries/schema-index/schemaSummarizer.ts +1 -1
  644. package/src/feature-libraries/sequence-field/invert.ts +2 -2
  645. package/src/feature-libraries/sequence-field/replaceRevisions.ts +17 -10
  646. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +1 -1
  647. package/src/index.ts +14 -9
  648. package/src/packageVersion.ts +1 -1
  649. package/src/shared-tree/independentView.ts +42 -6
  650. package/src/shared-tree/index.ts +2 -0
  651. package/src/shared-tree/schematizingTreeView.ts +63 -18
  652. package/src/shared-tree/sharedTree.ts +19 -37
  653. package/src/shared-tree/sharedTreeChangeCodecs.ts +45 -11
  654. package/src/shared-tree/tree.ts +2 -2
  655. package/src/shared-tree/treeAlpha.ts +1 -1
  656. package/src/shared-tree/treeCheckout.ts +52 -7
  657. package/src/shared-tree-core/editManagerCodecsCommons.ts +7 -7
  658. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +3 -10
  659. package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +3 -10
  660. package/src/shared-tree-core/editManagerSummarizer.ts +1 -1
  661. package/src/shared-tree-core/messageCodecV1ToV4.ts +4 -3
  662. package/src/shared-tree-core/messageCodecs.ts +2 -6
  663. package/src/shared-tree-core/transaction.ts +125 -23
  664. package/src/shared-tree-core/versionedSummarizer.ts +3 -2
  665. package/src/simple-tree/api/index.ts +3 -2
  666. package/src/simple-tree/api/schemaCreationUtilities.ts +35 -5
  667. package/src/simple-tree/api/simpleTreeIndex.ts +1 -1
  668. package/src/simple-tree/api/snapshotCompatibilityChecker.ts +344 -142
  669. package/src/simple-tree/api/transactionTypes.ts +10 -0
  670. package/src/simple-tree/api/tree.ts +89 -7
  671. package/src/simple-tree/api/treeBeta.ts +1 -1
  672. package/src/simple-tree/core/allowedTypes.ts +1 -1
  673. package/src/simple-tree/core/treeNodeSchema.ts +5 -8
  674. package/src/simple-tree/core/unhydratedFlexTree.ts +43 -1
  675. package/src/simple-tree/index.ts +5 -2
  676. package/src/simple-tree/leafNodeSchema.ts +3 -2
  677. package/src/simple-tree/node-kinds/array/arrayNode.ts +99 -19
  678. package/src/simple-tree/node-kinds/array/index.ts +2 -0
  679. package/src/simple-tree/node-kinds/index.ts +2 -0
  680. package/src/simple-tree/node-kinds/object/objectNode.ts +19 -18
  681. package/src/simple-tree/unhydratedFlexTreeFromInsertable.ts +51 -10
  682. package/src/tableSchema.ts +280 -140
  683. package/src/text/textDomainFormatted.ts +37 -17
  684. package/src/util/bTreeUtils.ts +55 -32
  685. package/src/util/brand.ts +4 -12
  686. package/src/util/brandedMap.ts +2 -6
  687. package/src/util/breakable.ts +3 -2
  688. package/src/util/index.ts +9 -3
  689. package/src/util/opaque.ts +2 -6
  690. package/src/util/rangeMap.ts +20 -11
  691. package/src/util/readSnapshotBlob.ts +3 -3
  692. package/src/util/typeCheck.ts +11 -9
  693. package/src/util/utils.ts +57 -28
  694. package/api-extractor-lint.json +0 -4
  695. package/biome.jsonc +0 -4
@@ -1 +1 @@
1
- {"version":3,"file":"objectNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/object/objectNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsF;AACtF,qEAAuE;AACvE,uEAAsE;AAEtE,qDAIgC;AAChC,kEAO6C;AAM7C,qDAA+C;AAE/C,kDAwB6B;AAC7B,6DAGgC;AAChC,yDAc8B;AAC9B,yEAAsE;AACtE,yEAAmE;AAEnE,+DAA2D;AAC3D,mGAMmD;AA4InD;;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,MAAM,MAAM,GAAG,IAAA,qCAAoB,EAAC,WAAW,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAA,6BAAY,EAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACpD,MAAM,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,MAAM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AC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC3C,OAAQ,IAA0C,CAAC,GAAa,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CACxB,MAA+B,EAC/B,IAA0E,EAC1E,SAAuD,EACvD,KAAoC;IAEpC,MAAM,KAAK,GACV,IAAI,CAAC,IAAI,KAAK,OAAO;QACpB,CAAC,CAAC,IAAI,CAAC,IAAI;QACX,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACtE,MAAM,KAAK,GAAG,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAC;IAClC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,IAAA,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAA,iBAAM,EACL,YAAY,YAAY,iCAAsB,EAC9C,KAAK,CAAC,qCAAqC,CAC3C,CAAC;IAEF,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,SAAS,EAAE,CAAC;QACjF,OAAO;IACR,CAAC;IAED,QAAQ,CACP,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,EACnC,SAAS,CAAC,MAAM,EAChB,KAAK,EACL,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,CAChD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Lazy, fail, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tObjectNodeStoredSchema,\n\ttype FieldKey,\n\ttype TreeFieldStoredSchema,\n} from \"../../../core/index.js\";\nimport {\n\tFieldKinds,\n\tisTreeValue,\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n} from \"../../../feature-libraries/index.js\";\nimport type {\n\tRestrictiveStringRecord,\n\tFlattenKeys,\n\tJsonCompatibleReadOnlyObject,\n} from \"../../../util/index.js\";\nimport { brand } from \"../../../util/index.js\";\nimport type { ObjectSchemaOptionsAlpha } from \"../../api/index.js\";\nimport {\n\tCompatibilityLevel,\n\ttype TreeNodeSchema,\n\tNodeKind,\n\ttype WithType,\n\t// eslint-disable-next-line import-x/no-deprecated\n\ttypeNameSymbol,\n\ttypeSchemaSymbol,\n\ttype InternalTreeNode,\n\ttype TreeNode,\n\ttype UnhydratedFlexTreeNode,\n\tgetInnerNode,\n\ttype NodeSchemaMetadata,\n\ttype ImplicitAllowedTypes,\n\tTreeNodeValid,\n\ttype MostDerivedData,\n\ttype TreeNodeSchemaInitializedData,\n\tprivateDataSymbol,\n\tcreateTreeNodeSchemaPrivateData,\n\ttype FlexContent,\n\ttype UnhydratedFlexTreeField,\n\tcreateField,\n\ttype TreeNodeSchemaCorePrivate,\n\ttype TreeNodeSchemaPrivateData,\n} from \"../../core/index.js\";\nimport {\n\tgetTreeNodeSchemaInitializedData,\n\tgetUnhydratedContext,\n} from \"../../createContext.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\tgetStoredKey,\n\tgetExplicitStoredKey,\n\ttype TreeFieldFromImplicitField,\n\ttype InsertableTreeFieldFromImplicitField,\n\ttype FieldSchema,\n\tFieldSchemaAlpha,\n\tnormalizeFieldSchema,\n\tFieldKind,\n\ttype FieldProps,\n\ttype ContextualFieldProvider,\n\textractFieldProvider,\n\tisConstant,\n} from \"../../fieldSchema.js\";\nimport { tryGetTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport type { SimpleObjectFieldSchema } from \"../../simpleSchema.js\";\nimport { convertFieldKind } from \"../../toStoredSchema.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\tunhydratedFlexTreeFromInsertableNode,\n\ttype FactoryContent,\n\ttype FactoryContentObject,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\n\nimport type {\n\tObjectNodeSchema,\n\tObjectNodeSchemaInternalData,\n\tObjectNodeSchemaPrivate,\n} from \"./objectNodeTypes.js\";\n\n/**\n * Generates the properties for an ObjectNode from its field schema object.\n * @remarks\n * Due to {@link https://github.com/microsoft/TypeScript/issues/43826}, we can't enable implicit construction of {@link TreeNode|TreeNodes} for setters.\n * Therefore code assigning to these fields must explicitly construct nodes using the schema's constructor or create method,\n * or using some other method like {@link (TreeAlpha:interface).create}.\n * @system @public\n */\nexport type ObjectFromSchemaRecord<T extends RestrictiveStringRecord<ImplicitFieldSchema>> =\n\tRestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t\t? // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n\t\t\t{}\n\t\t: {\n\t\t\t\t-readonly [Property in keyof T]: Property extends string\n\t\t\t\t\t? TreeFieldFromImplicitField<T[Property]>\n\t\t\t\t\t: unknown;\n\t\t\t};\n\n/**\n * A {@link TreeNode} which models a JavaScript object.\n * @remarks\n * Object nodes consist of a type which specifies which {@link TreeNodeSchema} they use (see {@link TreeNodeApi.schema} and {@link SchemaFactory.object}),\n * and a collections of fields, each with a distinct `key` and its own {@link FieldSchema} defining what can be placed under that key.\n *\n * All fields on an object node are exposed as own properties with string keys.\n * Non-empty fields are enumerable and empty optional fields are non-enumerable own properties with the value `undefined`.\n * No other own `own` or `enumerable` properties are included on object nodes unless the user of the node manually adds custom session only state.\n * This allows a majority of general purpose JavaScript object processing operations (like `for...in`, `Reflect.ownKeys()` and `Object.entries()`) to enumerate all the children.\n *\n * Field Assignment and Deletion\n * Assigning to a field updates the tree value as long as it is still valid based on the schema.\n * - For required fields, assigning `undefined` is invalid, and will throw.\n * - For optional fields, assigning `undefined` removes the field's contents, and marks it as empty (non-enumerable and value set to undefined).\n *\n * Example:\n * ```ts\n * const Foo = schemaFactory.object(\"Foo\", {bar: schemaFactory.optional(schemaFactory.number)});\n * const node = new Foo({bar: 1})\n *\n * // This clears the field, is non-enumerable, and value is undefined.\n * delete node.bar;\n *\n * // This is equivalent to the delete example.\n * node.bar = undefined\n * ```\n *\n * The API for fields is defined by {@link ObjectFromSchemaRecord}.\n * @public\n */\nexport type TreeObjectNode<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n\tTypeName extends string = string,\n> = TreeNode & ObjectFromSchemaRecord<T> & WithType<TypeName, NodeKind.Object, T>;\n\n/**\n * Type utility for determining if an implicit field schema is known to have a default value.\n *\n * @remarks Yields `false` when unknown.\n *\n * @privateRemarks\n * TODO: Account for field schemas with default value providers.\n * For now, this only captures field kinds that we know always have defaults - optional fields and identifier fields.\n *\n * @system @public\n */\nexport type FieldHasDefault<T extends ImplicitFieldSchema> = [T] extends [\n\tFieldSchema<FieldKind.Optional | FieldKind.Identifier>,\n]\n\t? true\n\t: false;\n\n/**\n * Helper used to produce types for:\n *\n * 1. Insertable content which can be used to construct an object node.\n * In this case, only own properties are considered.\n * This reduces the risk of incorrectly interpreting data at the cost of occasionally requiring users to convert data into a compatible format.\n *\n * 2. Insertable content which is an unhydrated object node.\n *\n * 3. Union of 1 and 2.\n *\n * @see {@link Input}\n *\n * @privateRemarks\n * TODO: consider separating these cases into different types.\n *\n * Empty objects don't get \"no excess property\" checks in literals.\n * To prevent extraneous properties in literals for the fields of an empty object from compiling, the empty case is special cased to produce `Record<string, never>`.\n * More details at {@link https://mercury.com/blog/creating-an-emptyobject-type-in-typescript}.\n *\n * Additionally when T is exactly `RestrictiveStringRecord<ImplicitFieldSchema>` produce just `never` so that it is assignable to the insertable for any given object type.\n *\n * Separating `{}` from `RestrictiveStringRecord<ImplicitFieldSchema>` is a bit messy since both extend each-other despite them being very different types.\n * A third dummy type `{ arbitraryKey: \"arbitraryValue\" }` is used to resolve this.\n *\n * @system @public\n */\nexport type InsertableObjectFromSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> = RestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t? { arbitraryKey: \"arbitraryValue\" } extends T\n\t\t? // {} case\n\t\t\tRecord<string, never>\n\t\t: // RestrictiveStringRecord<ImplicitFieldSchema> case\n\t\t\tnever\n\t: FlattenKeys<\n\t\t\t{\n\t\t\t\treadonly [Property in keyof T]?: InsertableTreeFieldFromImplicitField<\n\t\t\t\t\tT[Property & string]\n\t\t\t\t>;\n\t\t\t} & {\n\t\t\t\t// Field does not have a known default, make it required:\n\t\t\t\treadonly [Property in keyof T as FieldHasDefault<T[Property & string]> extends false\n\t\t\t\t\t? Property\n\t\t\t\t\t: never]: InsertableTreeFieldFromImplicitField<T[Property & string]>;\n\t\t\t}\n\t\t>;\n\n/**\n * 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 schema = normalizeFieldSchema(fieldSchema);\n\t\tconst storedKey = getStoredKey(propertyKey, schema);\n\t\tkeyMap.set(propertyKey, { storedKey, schema });\n\t}\n\n\treturn keyMap;\n}\n\n/**\n * Creates a proxy handler for the given schema.\n *\n * @param allowAdditionalProperties - If true, setting of unexpected properties will be forwarded to the target object.\n * Otherwise setting of unexpected properties will error.\n * TODO: consider implementing this using `Object.preventExtension` instead.\n * @param customTargetObject - Target object of the proxy.\n * If not provided `{}` is used for the target.\n */\nfunction createProxyHandler(\n\tschema: ObjectNodeSchemaPrivate,\n\tallowAdditionalProperties: boolean,\n): ProxyHandler<TreeNode> {\n\t// To satisfy 'deepEquals' level scrutiny, the target of the proxy must be an object with the same\n\t// prototype as an object literal '{}'. This is because 'deepEquals' uses 'Object.getPrototypeOf'\n\t// as a way to quickly reject objects with different prototype chains.\n\t//\n\t// (Note that the prototype of an object literal appears as '[Object: null prototype] {}', not because\n\t// the prototype is null, but because the prototype object itself has a null prototype.)\n\n\t// TODO: Although the target is an object literal, it's still worthwhile to try experimenting with\n\t// a dispatch object to see if it improves performance.\n\tconst handler: ProxyHandler<TreeNode> = {\n\t\tget(target, propertyKey, proxy): unknown {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo !== undefined) {\n\t\t\t\tconst flexNode = getInnerNode(proxy);\n\t\t\t\tdebugAssert(() => !flexNode.context.isDisposed() || \"FlexTreeNode is disposed\");\n\t\t\t\tconst field = flexNode.tryGetField(fieldInfo.storedKey);\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\treturn tryGetTreeNodeForField(field);\n\t\t\t\t}\n\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// POJO mode objects don't have TreeNode's built in members on their targets, so special case them:\n\t\t\tif (propertyKey === typeSchemaSymbol) {\n\t\t\t\treturn schema;\n\t\t\t}\n\t\t\t// eslint-disable-next-line import-x/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\tapplyFieldChange(schema, { kind: \"proxy\", node: proxy }, fieldInfo, value);\n\t\t\treturn true;\n\t\t},\n\t\tdeleteProperty(target, propertyKey): boolean {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo === undefined) {\n\t\t\t\treturn allowAdditionalProperties ? Reflect.deleteProperty(target, propertyKey) : false;\n\t\t\t}\n\n\t\t\tapplyFieldChange(schema, { kind: \"target\", node: target }, fieldInfo, undefined);\n\t\t\treturn true;\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 = getInnerNode(proxy).tryGetField(fieldInfo.storedKey);\n\n\t\t\tconst p: PropertyDescriptor = {\n\t\t\t\tvalue: field === undefined ? undefined : tryGetTreeNodeForField(field),\n\t\t\t\twritable: true,\n\t\t\t\t// Report empty fields as own properties so they shadow inherited properties (even when empty) to match TypeScript typing.\n\t\t\t\t// Make empty fields not enumerable so they get skipped when iterating over an object to better align with\n\t\t\t\t// JSON and deep equals with JSON compatible object (which can't have undefined fields).\n\t\t\t\tenumerable: field !== undefined,\n\t\t\t\tconfigurable: true, // Must be 'configurable' if property is absent from proxy target.\n\t\t\t};\n\n\t\t\treturn p;\n\t\t},\n\t};\n\treturn handler;\n}\n\nexport function setField(\n\tfield: FlexTreeField,\n\tsimpleFieldSchema: FieldSchema,\n\tvalue: InsertableContent | undefined,\n\tdestinationSchema: TreeFieldStoredSchema,\n): void {\n\tconst mapTree = prepareForInsertion(\n\t\tvalue,\n\t\tsimpleFieldSchema,\n\t\tfield.context,\n\t\tdestinationSchema,\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\t}\n\t}\n}\n\n/**\n * {@link FieldSchemaAlpha} including {@link SimpleObjectFieldSchema}.\n */\nexport class ObjectFieldSchema<\n\t\tKind extends FieldKind,\n\t\tTypes extends ImplicitAllowedTypes,\n\t\tTCustomMetadata = unknown,\n\t>\n\textends FieldSchemaAlpha<Kind, Types, TCustomMetadata>\n\timplements SimpleObjectFieldSchema\n{\n\tpublic readonly storedKey: string;\n\n\tpublic constructor(\n\t\tkind: Kind,\n\t\tallowedTypes: Types,\n\t\tprops: FieldProps<TCustomMetadata> & { readonly key: string },\n\t) {\n\t\tsuper(kind, allowedTypes, props);\n\t\tthis.storedKey = props.key;\n\t}\n}\n\nabstract class CustomObjectNodeBase<\n\tconst T extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> extends TreeNodeValid<InsertableObjectFromSchemaRecord<T>> {\n\tpublic static readonly kind = NodeKind.Object;\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link TreeObjectNode}.\n *\n * @param name - Unique identifier for this schema within this factory's scope.\n * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n * @param persistedMetadata - Optional persisted metadata for the object node schema.\n */\nexport function objectSchema<\n\tTName extends string,\n\tconst T extends RestrictiveStringRecord<ImplicitFieldSchema>,\n\tconst ImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\tidentifier: TName,\n\tinfo: T,\n\timplicitlyConstructable: ImplicitlyConstructable,\n\tnodeOptions: ObjectSchemaOptionsAlpha<TCustomMetadata>,\n): ObjectNodeSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> &\n\tObjectNodeSchemaInternalData &\n\tTreeNodeSchemaCorePrivate {\n\t// Field set can't be modified after this since derived data is stored in maps.\n\tObject.freeze(info);\n\n\t// Ensure no collisions between final set of property keys, and final set of stored keys (including those\n\t// implicitly derived from property keys)\n\tassertUniqueKeys(identifier, info);\n\n\t// Performance optimization: cache property key => stored key and schema.\n\tconst flexKeyMap: SimpleKeyMap = createFlexKeyMapping(info);\n\n\tconst identifierFieldKeys: FieldKey[] = [];\n\tfor (const item of flexKeyMap.values()) {\n\t\tif (item.schema.kind === FieldKind.Identifier) {\n\t\t\tidentifierFieldKeys.push(item.storedKey);\n\t\t}\n\t}\n\n\tconst lazyChildTypes = new Lazy(\n\t\t() => new Set(Array.from(flexKeyMap.values(), (f) => [...f.schema.allowedTypeSet]).flat()),\n\t);\n\n\tlet privateData: TreeNodeSchemaPrivateData | undefined;\n\n\tlet handler: ProxyHandler<object>;\n\tlet customizable: boolean;\n\n\tclass CustomObjectNode extends CustomObjectNodeBase<T> {\n\t\tpublic static readonly fields: ReadonlyMap<\n\t\t\tstring,\n\t\t\tFieldSchemaAlpha & SimpleObjectFieldSchema\n\t\t> = new Map(\n\t\t\tArray.from(flexKeyMap, ([key, value]) => [\n\t\t\t\tkey as string,\n\t\t\t\tnew ObjectFieldSchema(value.schema.kind, value.schema.allowedTypes, {\n\t\t\t\t\t...value.schema.props,\n\t\t\t\t\tkey: getStoredKey(key as string, value.schema),\n\t\t\t\t}),\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly flexKeyMap: SimpleKeyMap = flexKeyMap;\n\t\tpublic static readonly storedKeyToPropertyKey: ReadonlyMap<FieldKey, string> = new Map<\n\t\t\tFieldKey,\n\t\t\tstring\n\t\t>(\n\t\t\tArray.from(flexKeyMap, ([key, value]): [FieldKey, string] => [\n\t\t\t\tvalue.storedKey,\n\t\t\t\tkey as string,\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly identifierFieldKeys: readonly FieldKey[] = identifierFieldKeys;\n\t\tpublic static readonly allowUnknownOptionalFields: boolean =\n\t\t\tnodeOptions.allowUnknownOptionalFields ?? false;\n\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\t// Differentiate between the following cases:\n\t\t\t//\n\t\t\t// Case 1: Direct construction (POJO emulation)\n\t\t\t//\n\t\t\t// const Foo = schemaFactory.object(\"Foo\", {bar: schemaFactory.number});\n\t\t\t//\n\t\t\t// assert.deepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t//\t\t \"Prototype chain equivalent to POJO.\");\n\t\t\t//\n\t\t\t// Case 2: Subclass construction (Customizable Object)\n\t\t\t//\n\t\t\t// \t class Foo extends schemaFactory.object(\"Foo\", {bar: schemaFactory.number}) {}\n\t\t\t//\n\t\t\t// \t assert.notDeepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t// \t \"Subclass prototype chain differs from POJO.\");\n\t\t\t//\n\t\t\t// In Case 1 (POJO emulation), the prototype chain match '{}' (proxyTarget = undefined)\n\t\t\t// In Case 2 (Customizable Object), the prototype chain include the user's subclass (proxyTarget = this)\n\n\t\t\tconst proxyTarget = customizable ? instance : {};\n\t\t\tconst proxy = new Proxy(proxyTarget, handler) as CustomObjectNode;\n\t\t\ttargetToProxy.set(proxyTarget, proxy);\n\t\t\treturn proxy;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as object, this as Output);\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tprotected static override oneTimeSetup(): TreeNodeSchemaInitializedData {\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 ObjectNodeSchemaPrivate;\n\t\t\thandler = createProxyHandler(schema, customizable);\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 getTreeNodeSchemaInitializedData(schema, {\n\t\t\t\tshallowCompatibilityTest: (data: FactoryContent): CompatibilityLevel =>\n\t\t\t\t\tshallowCompatibilityTest(data, schema),\n\t\t\t\ttoFlexContent: (\n\t\t\t\t\tdata: FactoryContent,\n\t\t\t\t\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\t\t\t\t): FlexContent => objectToFlexContent(data, schema),\n\t\t\t});\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> =\n\t\t\tnodeOptions.metadata ?? {};\n\t\tpublic static readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined =\n\t\t\tnodeOptions.persistedMetadata;\n\n\t\t// eslint-disable-next-line import-x/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\n\t\tpublic static get [privateDataSymbol](): TreeNodeSchemaPrivateData {\n\t\t\treturn (privateData ??= createTreeNodeSchemaPrivateData(\n\t\t\t\tthis,\n\t\t\t\tArray.from(CustomObjectNode.fields.values(), (schema) => schema.allowedTypesFull),\n\t\t\t));\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 * {@link TreeNodeSchemaInitializedData.toFlexContent} for object nodes.\n *\n * @param data - The tree data to be transformed. Must be a Record-like object.\n * @param schema - The schema to comply with.\n */\nfunction objectToFlexContent(\n\tdata: FactoryContent,\n\tschema: TreeNodeSchema & ObjectNodeSchemaInternalData,\n): FlexContent {\n\tif (\n\t\ttypeof data !== \"object\" ||\n\t\tdata === null ||\n\t\tSymbol.iterator in data ||\n\t\tisFluidHandle(data)\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tthrow new UsageError(`Input data is incompatible with Object schema: ${data}`);\n\t}\n\n\tconst fields = new Map<FieldKey, UnhydratedFlexTreeField>();\n\tconst context = getUnhydratedContext(schema).flexContext;\n\n\tfor (const [key, fieldInfo] of schema.flexKeyMap) {\n\t\tconst value = getFieldProperty(data, key);\n\n\t\tlet children: UnhydratedFlexTreeNode[] | ContextualFieldProvider;\n\t\tif (value === undefined) {\n\t\t\tconst defaultProvider =\n\t\t\t\tfieldInfo.schema.props?.defaultProvider ??\n\t\t\t\tfail(0xbb1 /* missing field has no default provider */);\n\t\t\tconst fieldProvider = extractFieldProvider(defaultProvider);\n\t\t\tchildren = isConstant(fieldProvider) ? fieldProvider() : fieldProvider;\n\t\t} else {\n\t\t\tchildren = [\n\t\t\t\tunhydratedFlexTreeFromInsertableNode(value, fieldInfo.schema.allowedTypeSet),\n\t\t\t];\n\t\t}\n\n\t\tconst kind =\n\t\t\tconvertFieldKind.get(fieldInfo.schema.kind) ?? fail(0xbb2 /* Invalid field kind */);\n\t\tfields.set(\n\t\t\tfieldInfo.storedKey,\n\t\t\tcreateField(context, kind.identifier, fieldInfo.storedKey, children),\n\t\t);\n\t}\n\n\treturn [{ type: brand(schema.identifier) }, fields];\n}\n\n/**\n * {@link TreeNodeSchemaInitializedData.shallowCompatibilityTest} for Object nodes.\n */\nfunction shallowCompatibilityTest(\n\tdata: FactoryContent,\n\tschema: ObjectNodeSchema & ObjectNodeSchemaInternalData,\n): CompatibilityLevel {\n\tif (isTreeValue(data)) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\tif (Symbol.iterator in data) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\t// TODO: Improve type inference by making this logic more thorough. Handle at least:\n\t// * Types which are strict subsets of other types in the same polymorphic union\n\t// * Types which have the same keys but different types for those keys in the polymorphic union\n\t// * Types which have the same required fields but different optional fields and enough of those optional fields are populated to disambiguate\n\n\t// TODO#7441: Consider allowing data to be inserted which has keys that are extraneous/unknown to the schema (those keys are ignored)\n\n\t// If the schema has a required key which is not present in the input object, reject it.\n\tfor (const [fieldKey, fieldSchema] of schema.fields) {\n\t\tif (fieldSchema.requiresValue && getFieldProperty(data, fieldKey) === undefined) {\n\t\t\treturn CompatibilityLevel.None;\n\t\t}\n\t}\n\n\treturn CompatibilityLevel.Normal;\n}\n\n/**\n * Check {@link FactoryContentObject} for a property which could be store a field.\n *\n * @returns If the property exists, return its value. Otherwise, returns undefined.\n * @remarks\n * The currently policy is to only consider own properties.\n * See {@link InsertableObjectFromSchemaRecord} for where this policy is documented in the public API.\n *\n * Explicit undefined values are treated the same as missing properties to allow explicit use of undefined with defaulted identifiers.\n *\n * @privateRemarks\n * If we ever want to have an optional field which defaults to something other than undefined, this will need changes.\n * It would need to adjusting the handling of explicit undefined in contexts where undefined is allowed, and a default provider also exists.\n */\nfunction getFieldProperty(\n\tdata: FactoryContentObject,\n\tkey: string | symbol,\n): InsertableContent | undefined {\n\t// This policy only allows own properties.\n\tif (Object.hasOwnProperty.call(data, key)) {\n\t\treturn (data as Record<string, InsertableContent>)[key as string];\n\t}\n\treturn undefined;\n}\n\nfunction applyFieldChange(\n\tschema: ObjectNodeSchemaPrivate,\n\tfrom: { kind: \"proxy\"; node: TreeNode } | { kind: \"target\"; node: object },\n\tfieldInfo: { storedKey: FieldKey; schema: FieldSchema },\n\tvalue: InsertableContent | undefined,\n): void {\n\tconst proxy =\n\t\tfrom.kind === \"proxy\"\n\t\t\t? from.node\n\t\t\t: (targetToProxy.get(from.node) ?? fail(0xc95 /* missing proxy */));\n\tconst inner = getInnerNode(proxy);\n\tconst storedSchema = inner.context.schema.nodeSchema.get(brand(schema.identifier));\n\tassert(\n\t\tstoredSchema instanceof ObjectNodeStoredSchema,\n\t\t0xc96 /* Expected ObjectNodeStoredSchema */,\n\t);\n\n\tif (value === undefined && inner.tryGetField(fieldInfo.storedKey) === undefined) {\n\t\treturn;\n\t}\n\n\tsetField(\n\t\tinner.getBoxed(fieldInfo.storedKey),\n\t\tfieldInfo.schema,\n\t\tvalue,\n\t\tstoredSchema.getFieldSchema(fieldInfo.storedKey),\n\t);\n}\n"]}
1
+ {"version":3,"file":"objectNode.js","sourceRoot":"","sources":["../../../../src/simple-tree/node-kinds/object/objectNode.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsF;AACtF,qEAAuE;AACvE,uEAAsE;AAEtE,qDAIgC;AAChC,kEAO6C;AAM7C,qDAA+C;AAE/C,kDAwB6B;AAC7B,6DAGgC;AAChC,yDAc8B;AAC9B,yEAAsE;AACtE,yEAAmE;AAEnE,+DAA2D;AAC3D,mGAMmD;AA6InD;;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,MAAM,MAAM,GAAG,IAAA,qCAAoB,EAAC,WAAW,CAAC,CAAC;QACjD,MAAM,SAAS,GAAG,IAAA,6BAAY,EAAC,WAAW,EAAE,MAAM,CAAC,CAAC;QACpD,MAAM,CAAC,GA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GAAoB;IAEpB,0CAA0C;IAC1C,IAAI,MAAM,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,EAAE,CAAC;QAC3C,OAAQ,IAA0C,CAAC,GAAa,CAAC,CAAC;IACnE,CAAC;IACD,OAAO,SAAS,CAAC;AAClB,CAAC;AAED,SAAS,gBAAgB,CACxB,MAA+B,EAC/B,IAA0E,EAC1E,SAAuD,EACvD,KAAoC;IAEpC,MAAM,KAAK,GACV,IAAI,CAAC,IAAI,KAAK,OAAO;QACpB,CAAC,CAAC,IAAI,CAAC,IAAI;QACX,CAAC,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC,CAAC;IACtE,MAAM,KAAK,GAAG,IAAA,uBAAY,EAAC,KAAK,CAAC,CAAC;IAClC,MAAM,YAAY,GAAG,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,IAAA,gBAAK,EAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;IACnF,IAAA,iBAAM,EACL,YAAY,YAAY,iCAAsB,EAC9C,KAAK,CAAC,qCAAqC,CAC3C,CAAC;IAEF,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,SAAS,CAAC,KAAK,SAAS,EAAE,CAAC;QACjF,OAAO;IACR,CAAC;IAED,QAAQ,CACP,KAAK,CAAC,QAAQ,CAAC,SAAS,CAAC,SAAS,CAAC,EACnC,SAAS,CAAC,MAAM,EAChB,KAAK,EACL,YAAY,CAAC,cAAc,CAAC,SAAS,CAAC,SAAS,CAAC,CAChD,CAAC;AACH,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, Lazy, fail, debugAssert } from \"@fluidframework/core-utils/internal\";\nimport { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tObjectNodeStoredSchema,\n\ttype FieldKey,\n\ttype TreeFieldStoredSchema,\n} from \"../../../core/index.js\";\nimport {\n\tFieldKinds,\n\tisTreeValue,\n\ttype FlexTreeField,\n\ttype FlexTreeNode,\n\ttype FlexTreeOptionalField,\n\ttype FlexTreeRequiredField,\n} from \"../../../feature-libraries/index.js\";\nimport type {\n\tRestrictiveStringRecord,\n\tFlattenKeys,\n\tJsonCompatibleReadOnlyObject,\n} from \"../../../util/index.js\";\nimport { brand } from \"../../../util/index.js\";\nimport type { ObjectSchemaOptionsAlpha } from \"../../api/index.js\";\nimport {\n\tCompatibilityLevel,\n\ttype TreeNodeSchema,\n\tNodeKind,\n\ttype WithType,\n\t// eslint-disable-next-line import-x/no-deprecated\n\ttypeNameSymbol,\n\ttypeSchemaSymbol,\n\ttype InternalTreeNode,\n\ttype TreeNode,\n\ttype UnhydratedFlexTreeNode,\n\tgetInnerNode,\n\ttype NodeSchemaMetadata,\n\ttype ImplicitAllowedTypes,\n\tTreeNodeValid,\n\ttype MostDerivedData,\n\ttype TreeNodeSchemaInitializedData,\n\tprivateDataSymbol,\n\tcreateTreeNodeSchemaPrivateData,\n\ttype FlexContent,\n\ttype UnhydratedFlexTreeField,\n\tcreateField,\n\ttype TreeNodeSchemaCorePrivate,\n\ttype TreeNodeSchemaPrivateData,\n} from \"../../core/index.js\";\nimport {\n\tgetTreeNodeSchemaInitializedData,\n\tgetUnhydratedContext,\n} from \"../../createContext.js\";\nimport {\n\ttype ImplicitFieldSchema,\n\tgetStoredKey,\n\tgetExplicitStoredKey,\n\ttype TreeFieldFromImplicitField,\n\ttype InsertableTreeFieldFromImplicitField,\n\ttype FieldSchema,\n\tFieldSchemaAlpha,\n\tnormalizeFieldSchema,\n\tFieldKind,\n\ttype FieldProps,\n\ttype ContextualFieldProvider,\n\textractFieldProvider,\n\tisConstant,\n} from \"../../fieldSchema.js\";\nimport { tryGetTreeNodeForField } from \"../../getTreeNodeForField.js\";\nimport { prepareForInsertion } from \"../../prepareForInsertion.js\";\nimport type { SimpleObjectFieldSchema } from \"../../simpleSchema.js\";\nimport { convertFieldKind } from \"../../toStoredSchema.js\";\nimport {\n\tunhydratedFlexTreeFromInsertable,\n\tunhydratedFlexTreeFromInsertableNode,\n\ttype FactoryContent,\n\ttype FactoryContentObject,\n\ttype InsertableContent,\n} from \"../../unhydratedFlexTreeFromInsertable.js\";\n\nimport type {\n\tObjectNodeSchema,\n\tObjectNodeSchemaInternalData,\n\tObjectNodeSchemaPrivate,\n} from \"./objectNodeTypes.js\";\n\n/**\n * Generates the properties for an ObjectNode from its field schema object.\n * @remarks\n * Due to {@link https://github.com/microsoft/TypeScript/issues/43826}, we can't enable implicit construction of {@link TreeNode|TreeNodes} for setters.\n * Therefore code assigning to these fields must explicitly construct nodes using the schema's constructor or create method,\n * or using some other method like {@link (TreeAlpha:interface).create}.\n * @system @public\n */\nexport type ObjectFromSchemaRecord<T extends RestrictiveStringRecord<ImplicitFieldSchema>> =\n\tRestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t\t? // eslint-disable-next-line @typescript-eslint/no-empty-object-type\n\t\t\t{}\n\t\t: {\n\t\t\t\t-readonly [Property in keyof T]: Property extends string\n\t\t\t\t\t? TreeFieldFromImplicitField<T[Property]>\n\t\t\t\t\t: unknown;\n\t\t\t};\n\n/**\n * A {@link TreeNode} which models a JavaScript object.\n * @remarks\n * Object nodes consist of a type which specifies which {@link TreeNodeSchema} they use (see {@link TreeNodeApi.schema} and {@link SchemaFactory.object}),\n * and a collections of fields, each with a distinct `key` and its own {@link FieldSchema} defining what can be placed under that key.\n *\n * All fields on an object node are exposed as own properties with string keys.\n * Non-empty fields are enumerable and empty optional fields are non-enumerable own properties with the value `undefined`.\n * No other own `own` or `enumerable` properties are included on object nodes unless the user of the node manually adds custom session only state.\n * This allows a majority of general purpose JavaScript object processing operations (like `for...in`, `Reflect.ownKeys()` and `Object.entries()`) to enumerate all the children.\n *\n * Field Assignment and Deletion\n * Assigning to a field updates the tree value as long as it is still valid based on the schema.\n * - For required fields, assigning `undefined` is invalid, and will throw.\n * - For optional fields, assigning `undefined` removes the field's contents, and marks it as empty (non-enumerable and value set to undefined).\n *\n * Example:\n * ```ts\n * const Foo = schemaFactory.object(\"Foo\", {bar: schemaFactory.optional(schemaFactory.number)});\n * const node = new Foo({bar: 1})\n *\n * // This clears the field, is non-enumerable, and value is undefined.\n * delete node.bar;\n *\n * // This is equivalent to the delete example.\n * node.bar = undefined\n * ```\n *\n * The API for fields is defined by {@link ObjectFromSchemaRecord}.\n * @public\n */\nexport type TreeObjectNode<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n\tTypeName extends string = string,\n> = TreeNode & ObjectFromSchemaRecord<T> & WithType<TypeName, NodeKind.Object, T>;\n\n/**\n * Type utility for determining if an implicit field schema is known to have a default value.\n *\n * @remarks Yields `false` when unknown.\n *\n * @privateRemarks\n * TODO: Account for field schemas with default value providers.\n * For now, this only captures field kinds that we know always have defaults - optional fields and identifier fields.\n *\n * @system @public\n */\nexport type FieldHasDefault<T extends ImplicitFieldSchema> = [T] extends [\n\tFieldSchema<FieldKind.Optional | FieldKind.Identifier>,\n]\n\t? true\n\t: false;\n\n/**\n * Helper used to produce types for:\n *\n * 1. Insertable content which can be used to construct an object node.\n * In this case, only own properties are considered.\n * This reduces the risk of incorrectly interpreting data at the cost of occasionally requiring users to convert data into a compatible format.\n *\n * 2. Insertable content which is an unhydrated object node.\n *\n * 3. Union of 1 and 2.\n *\n * @see {@link Input}\n *\n * @privateRemarks\n * TODO: consider separating these cases into different types.\n *\n * Empty objects don't get \"no excess property\" checks in literals.\n * To prevent extraneous properties in literals for the fields of an empty object from compiling, the empty case is special cased to produce `Record<string, never>`.\n * More details at {@link https://mercury.com/blog/creating-an-emptyobject-type-in-typescript}.\n *\n * Additionally when T is exactly `RestrictiveStringRecord<ImplicitFieldSchema>` produce just `never` so that it is assignable to the insertable for any given object type.\n *\n * Separating `{}` from `RestrictiveStringRecord<ImplicitFieldSchema>` is a bit messy since both extend each-other despite them being very different types.\n * A third dummy type `{ arbitraryKey: \"arbitraryValue\" }` is used to resolve this.\n *\n * @system @public\n */\nexport type InsertableObjectFromSchemaRecord<\n\tT extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> =\n\tRestrictiveStringRecord<ImplicitFieldSchema> extends T\n\t\t? { arbitraryKey: \"arbitraryValue\" } extends T\n\t\t\t? // {} case\n\t\t\t\tRecord<string, never>\n\t\t\t: // RestrictiveStringRecord<ImplicitFieldSchema> case\n\t\t\t\tnever\n\t\t: FlattenKeys<\n\t\t\t\t{\n\t\t\t\t\treadonly [Property in keyof T]?: InsertableTreeFieldFromImplicitField<\n\t\t\t\t\t\tT[Property & string]\n\t\t\t\t\t>;\n\t\t\t\t} & {\n\t\t\t\t\t// Field does not have a known default, make it required:\n\t\t\t\t\treadonly [Property in keyof T as FieldHasDefault<T[Property & string]> extends false\n\t\t\t\t\t\t? Property\n\t\t\t\t\t\t: never]: InsertableTreeFieldFromImplicitField<T[Property & string]>;\n\t\t\t\t}\n\t\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 schema = normalizeFieldSchema(fieldSchema);\n\t\tconst storedKey = getStoredKey(propertyKey, schema);\n\t\tkeyMap.set(propertyKey, { storedKey, schema });\n\t}\n\n\treturn keyMap;\n}\n\n/**\n * Creates a proxy handler for the given schema.\n *\n * @param allowAdditionalProperties - If true, setting of unexpected properties will be forwarded to the target object.\n * Otherwise setting of unexpected properties will error.\n * TODO: consider implementing this using `Object.preventExtension` instead.\n * @param customTargetObject - Target object of the proxy.\n * If not provided `{}` is used for the target.\n */\nfunction createProxyHandler(\n\tschema: ObjectNodeSchemaPrivate,\n\tallowAdditionalProperties: boolean,\n): ProxyHandler<TreeNode> {\n\t// To satisfy 'deepEquals' level scrutiny, the target of the proxy must be an object with the same\n\t// prototype as an object literal '{}'. This is because 'deepEquals' uses 'Object.getPrototypeOf'\n\t// as a way to quickly reject objects with different prototype chains.\n\t//\n\t// (Note that the prototype of an object literal appears as '[Object: null prototype] {}', not because\n\t// the prototype is null, but because the prototype object itself has a null prototype.)\n\n\t// TODO: Although the target is an object literal, it's still worthwhile to try experimenting with\n\t// a dispatch object to see if it improves performance.\n\tconst handler: ProxyHandler<TreeNode> = {\n\t\tget(target, propertyKey, proxy): unknown {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo !== undefined) {\n\t\t\t\tconst flexNode = getInnerNode(proxy);\n\t\t\t\tdebugAssert(() => !flexNode.context.isDisposed() || \"FlexTreeNode is disposed\");\n\t\t\t\tconst field = flexNode.tryGetField(fieldInfo.storedKey);\n\t\t\t\tif (field !== undefined) {\n\t\t\t\t\treturn tryGetTreeNodeForField(field);\n\t\t\t\t}\n\n\t\t\t\treturn undefined;\n\t\t\t}\n\n\t\t\t// POJO mode objects don't have TreeNode's built in members on their targets, so special case them:\n\t\t\tif (propertyKey === typeSchemaSymbol) {\n\t\t\t\treturn schema;\n\t\t\t}\n\t\t\t// eslint-disable-next-line import-x/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\tapplyFieldChange(schema, { kind: \"proxy\", node: proxy }, fieldInfo, value);\n\t\t\treturn true;\n\t\t},\n\t\tdeleteProperty(target, propertyKey): boolean {\n\t\t\tconst fieldInfo = schema.flexKeyMap.get(propertyKey);\n\t\t\tif (fieldInfo === undefined) {\n\t\t\t\treturn allowAdditionalProperties ? Reflect.deleteProperty(target, propertyKey) : false;\n\t\t\t}\n\n\t\t\tapplyFieldChange(schema, { kind: \"target\", node: target }, fieldInfo, undefined);\n\t\t\treturn true;\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 = getInnerNode(proxy).tryGetField(fieldInfo.storedKey);\n\n\t\t\tconst p: PropertyDescriptor = {\n\t\t\t\tvalue: field === undefined ? undefined : tryGetTreeNodeForField(field),\n\t\t\t\twritable: true,\n\t\t\t\t// Report empty fields as own properties so they shadow inherited properties (even when empty) to match TypeScript typing.\n\t\t\t\t// Make empty fields not enumerable so they get skipped when iterating over an object to better align with\n\t\t\t\t// JSON and deep equals with JSON compatible object (which can't have undefined fields).\n\t\t\t\tenumerable: field !== undefined,\n\t\t\t\tconfigurable: true, // Must be 'configurable' if property is absent from proxy target.\n\t\t\t};\n\n\t\t\treturn p;\n\t\t},\n\t};\n\treturn handler;\n}\n\nexport function setField(\n\tfield: FlexTreeField,\n\tsimpleFieldSchema: FieldSchema,\n\tvalue: InsertableContent | undefined,\n\tdestinationSchema: TreeFieldStoredSchema,\n): void {\n\tconst mapTree = prepareForInsertion(\n\t\tvalue,\n\t\tsimpleFieldSchema,\n\t\tfield.context,\n\t\tdestinationSchema,\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\t}\n\t}\n}\n\n/**\n * {@link FieldSchemaAlpha} including {@link SimpleObjectFieldSchema}.\n */\nexport class ObjectFieldSchema<\n\t\tKind extends FieldKind,\n\t\tTypes extends ImplicitAllowedTypes,\n\t\tTCustomMetadata = unknown,\n\t>\n\textends FieldSchemaAlpha<Kind, Types, TCustomMetadata>\n\timplements SimpleObjectFieldSchema\n{\n\tpublic readonly storedKey: string;\n\n\tpublic constructor(\n\t\tkind: Kind,\n\t\tallowedTypes: Types,\n\t\tprops: FieldProps<TCustomMetadata> & { readonly key: string },\n\t) {\n\t\tsuper(kind, allowedTypes, props);\n\t\tthis.storedKey = props.key;\n\t}\n}\n\nabstract class CustomObjectNodeBase<\n\tconst T extends RestrictiveStringRecord<ImplicitFieldSchema>,\n> extends TreeNodeValid<InsertableObjectFromSchemaRecord<T>> {\n\tpublic static readonly kind = NodeKind.Object;\n}\n\n/**\n * Define a {@link TreeNodeSchema} for a {@link TreeObjectNode}.\n *\n * @param name - Unique identifier for this schema within this factory's scope.\n * @param fields - Schema for fields of the object node's schema. Defines what children can be placed under each key.\n * @param persistedMetadata - Optional persisted metadata for the object node schema.\n */\nexport function objectSchema<\n\tTName extends string,\n\tconst T extends RestrictiveStringRecord<ImplicitFieldSchema>,\n\tconst ImplicitlyConstructable extends boolean,\n\tconst TCustomMetadata = unknown,\n>(\n\tidentifier: TName,\n\tinfo: T,\n\timplicitlyConstructable: ImplicitlyConstructable,\n\tnodeOptions: ObjectSchemaOptionsAlpha<TCustomMetadata>,\n): ObjectNodeSchema<TName, T, ImplicitlyConstructable, TCustomMetadata> &\n\tObjectNodeSchemaInternalData &\n\tTreeNodeSchemaCorePrivate {\n\t// Field set can't be modified after this since derived data is stored in maps.\n\tObject.freeze(info);\n\n\t// Ensure no collisions between final set of property keys, and final set of stored keys (including those\n\t// implicitly derived from property keys)\n\tassertUniqueKeys(identifier, info);\n\n\t// Performance optimization: cache property key => stored key and schema.\n\tconst flexKeyMap: SimpleKeyMap = createFlexKeyMapping(info);\n\n\tconst identifierFieldKeys: FieldKey[] = [];\n\tfor (const item of flexKeyMap.values()) {\n\t\tif (item.schema.kind === FieldKind.Identifier) {\n\t\t\tidentifierFieldKeys.push(item.storedKey);\n\t\t}\n\t}\n\n\tconst lazyChildTypes = new Lazy(\n\t\t() => new Set(Array.from(flexKeyMap.values(), (f) => [...f.schema.allowedTypeSet]).flat()),\n\t);\n\n\tlet privateData: TreeNodeSchemaPrivateData | undefined;\n\n\tlet handler: ProxyHandler<object>;\n\tlet customizable: boolean;\n\n\tclass CustomObjectNode extends CustomObjectNodeBase<T> {\n\t\tpublic static readonly fields: ReadonlyMap<\n\t\t\tstring,\n\t\t\tFieldSchemaAlpha & SimpleObjectFieldSchema\n\t\t> = new Map(\n\t\t\tArray.from(flexKeyMap, ([key, value]) => [\n\t\t\t\tkey as string,\n\t\t\t\tnew ObjectFieldSchema(value.schema.kind, value.schema.allowedTypes, {\n\t\t\t\t\t...value.schema.props,\n\t\t\t\t\tkey: getStoredKey(key as string, value.schema),\n\t\t\t\t}),\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly flexKeyMap: SimpleKeyMap = flexKeyMap;\n\t\tpublic static readonly storedKeyToPropertyKey: ReadonlyMap<FieldKey, string> = new Map<\n\t\t\tFieldKey,\n\t\t\tstring\n\t\t>(\n\t\t\tArray.from(flexKeyMap, ([key, value]): [FieldKey, string] => [\n\t\t\t\tvalue.storedKey,\n\t\t\t\tkey as string,\n\t\t\t]),\n\t\t);\n\t\tpublic static readonly identifierFieldKeys: readonly FieldKey[] = identifierFieldKeys;\n\t\tpublic static readonly allowUnknownOptionalFields: boolean =\n\t\t\tnodeOptions.allowUnknownOptionalFields ?? false;\n\n\t\tpublic static override prepareInstance<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tflexNode: FlexTreeNode,\n\t\t): TreeNodeValid<T2> {\n\t\t\t// Differentiate between the following cases:\n\t\t\t//\n\t\t\t// Case 1: Direct construction (POJO emulation)\n\t\t\t//\n\t\t\t// const Foo = schemaFactory.object(\"Foo\", {bar: schemaFactory.number});\n\t\t\t//\n\t\t\t// assert.deepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t//\t\t \"Prototype chain equivalent to POJO.\");\n\t\t\t//\n\t\t\t// Case 2: Subclass construction (Customizable Object)\n\t\t\t//\n\t\t\t// \t class Foo extends schemaFactory.object(\"Foo\", {bar: schemaFactory.number}) {}\n\t\t\t//\n\t\t\t// \t assert.notDeepEqual(new Foo({ bar: 42 }), { bar: 42 },\n\t\t\t// \t \"Subclass prototype chain differs from POJO.\");\n\t\t\t//\n\t\t\t// In Case 1 (POJO emulation), the prototype chain match '{}' (proxyTarget = undefined)\n\t\t\t// In Case 2 (Customizable Object), the prototype chain include the user's subclass (proxyTarget = this)\n\n\t\t\tconst proxyTarget = customizable ? instance : {};\n\t\t\tconst proxy = new Proxy(proxyTarget, handler) as CustomObjectNode;\n\t\t\ttargetToProxy.set(proxyTarget, proxy);\n\t\t\treturn proxy;\n\t\t}\n\n\t\tpublic static override buildRawNode<T2>(\n\t\t\tthis: typeof TreeNodeValid<T2>,\n\t\t\tinstance: TreeNodeValid<T2>,\n\t\t\tinput: T2,\n\t\t): UnhydratedFlexTreeNode {\n\t\t\treturn unhydratedFlexTreeFromInsertable(input as object, this as Output);\n\t\t}\n\n\t\tprotected static override constructorCached: MostDerivedData | undefined = undefined;\n\n\t\tprotected static override oneTimeSetup(): TreeNodeSchemaInitializedData {\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 ObjectNodeSchemaPrivate;\n\t\t\thandler = createProxyHandler(schema, customizable);\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 getTreeNodeSchemaInitializedData(schema, {\n\t\t\t\tshallowCompatibilityTest: (data: FactoryContent): CompatibilityLevel =>\n\t\t\t\t\tshallowCompatibilityTest(data, schema),\n\t\t\t\ttoFlexContent: (\n\t\t\t\t\tdata: FactoryContent,\n\t\t\t\t\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\t\t\t\t): FlexContent => objectToFlexContent(data, schema),\n\t\t\t});\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> =\n\t\t\tnodeOptions.metadata ?? {};\n\t\tpublic static readonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined =\n\t\t\tnodeOptions.persistedMetadata;\n\n\t\t// eslint-disable-next-line import-x/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\n\t\tpublic static get [privateDataSymbol](): TreeNodeSchemaPrivateData {\n\t\t\treturn (privateData ??= createTreeNodeSchemaPrivateData(\n\t\t\t\tthis,\n\t\t\t\tArray.from(CustomObjectNode.fields.values(), (schema) => schema.allowedTypesFull),\n\t\t\t));\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 * {@link TreeNodeSchemaInitializedData.toFlexContent} for object nodes.\n *\n * @param data - The tree data to be transformed. Must be a Record-like object.\n * @param schema - The schema to comply with.\n */\nfunction objectToFlexContent(\n\tdata: FactoryContent,\n\tschema: TreeNodeSchema & ObjectNodeSchemaInternalData,\n): FlexContent {\n\tif (\n\t\ttypeof data !== \"object\" ||\n\t\tdata === null ||\n\t\tSymbol.iterator in data ||\n\t\tisFluidHandle(data)\n\t) {\n\t\t// eslint-disable-next-line @typescript-eslint/no-base-to-string\n\t\tthrow new UsageError(`Input data is incompatible with Object schema: ${data}`);\n\t}\n\n\tconst fields = new Map<FieldKey, UnhydratedFlexTreeField>();\n\tconst context = getUnhydratedContext(schema).flexContext;\n\n\tfor (const [key, fieldInfo] of schema.flexKeyMap) {\n\t\tconst value = getFieldProperty(data, key);\n\n\t\tlet children: UnhydratedFlexTreeNode[] | ContextualFieldProvider;\n\t\tif (value === undefined) {\n\t\t\tconst defaultProvider =\n\t\t\t\tfieldInfo.schema.props?.defaultProvider ??\n\t\t\t\tfail(0xbb1 /* missing field has no default provider */);\n\t\t\tconst fieldProvider = extractFieldProvider(defaultProvider);\n\t\t\tchildren = isConstant(fieldProvider) ? fieldProvider() : fieldProvider;\n\t\t} else {\n\t\t\tchildren = [\n\t\t\t\tunhydratedFlexTreeFromInsertableNode(value, fieldInfo.schema.allowedTypeSet),\n\t\t\t];\n\t\t}\n\n\t\tconst kind =\n\t\t\tconvertFieldKind.get(fieldInfo.schema.kind) ?? fail(0xbb2 /* Invalid field kind */);\n\t\tfields.set(\n\t\t\tfieldInfo.storedKey,\n\t\t\tcreateField(context, kind.identifier, fieldInfo.storedKey, children),\n\t\t);\n\t}\n\n\treturn [{ type: brand(schema.identifier) }, fields];\n}\n\n/**\n * {@link TreeNodeSchemaInitializedData.shallowCompatibilityTest} for Object nodes.\n */\nfunction shallowCompatibilityTest(\n\tdata: FactoryContent,\n\tschema: ObjectNodeSchema & ObjectNodeSchemaInternalData,\n): CompatibilityLevel {\n\tif (isTreeValue(data)) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\tif (Symbol.iterator in data) {\n\t\treturn CompatibilityLevel.None;\n\t}\n\n\t// TODO: Improve type inference by making this logic more thorough. Handle at least:\n\t// * Types which are strict subsets of other types in the same polymorphic union\n\t// * Types which have the same keys but different types for those keys in the polymorphic union\n\t// * Types which have the same required fields but different optional fields and enough of those optional fields are populated to disambiguate\n\n\t// TODO#7441: Consider allowing data to be inserted which has keys that are extraneous/unknown to the schema (those keys are ignored)\n\n\t// If the schema has a required key which is not present in the input object, reject it.\n\tfor (const [fieldKey, fieldSchema] of schema.fields) {\n\t\tif (fieldSchema.requiresValue && getFieldProperty(data, fieldKey) === undefined) {\n\t\t\treturn CompatibilityLevel.None;\n\t\t}\n\t}\n\n\treturn CompatibilityLevel.Normal;\n}\n\n/**\n * Check {@link FactoryContentObject} for a property which could be store a field.\n *\n * @returns If the property exists, return its value. Otherwise, returns undefined.\n * @remarks\n * The currently policy is to only consider own properties.\n * See {@link InsertableObjectFromSchemaRecord} for where this policy is documented in the public API.\n *\n * Explicit undefined values are treated the same as missing properties to allow explicit use of undefined with defaulted identifiers.\n *\n * @privateRemarks\n * If we ever want to have an optional field which defaults to something other than undefined, this will need changes.\n * It would need to adjusting the handling of explicit undefined in contexts where undefined is allowed, and a default provider also exists.\n */\nfunction getFieldProperty(\n\tdata: FactoryContentObject,\n\tkey: string | symbol,\n): InsertableContent | undefined {\n\t// This policy only allows own properties.\n\tif (Object.hasOwnProperty.call(data, key)) {\n\t\treturn (data as Record<string, InsertableContent>)[key as string];\n\t}\n\treturn undefined;\n}\n\nfunction applyFieldChange(\n\tschema: ObjectNodeSchemaPrivate,\n\tfrom: { kind: \"proxy\"; node: TreeNode } | { kind: \"target\"; node: object },\n\tfieldInfo: { storedKey: FieldKey; schema: FieldSchema },\n\tvalue: InsertableContent | undefined,\n): void {\n\tconst proxy =\n\t\tfrom.kind === \"proxy\"\n\t\t\t? from.node\n\t\t\t: (targetToProxy.get(from.node) ?? fail(0xc95 /* missing proxy */));\n\tconst inner = getInnerNode(proxy);\n\tconst storedSchema = inner.context.schema.nodeSchema.get(brand(schema.identifier));\n\tassert(\n\t\tstoredSchema instanceof ObjectNodeStoredSchema,\n\t\t0xc96 /* Expected ObjectNodeStoredSchema */,\n\t);\n\n\tif (value === undefined && inner.tryGetField(fieldInfo.storedKey) === undefined) {\n\t\treturn;\n\t}\n\n\tsetField(\n\t\tinner.getBoxed(fieldInfo.storedKey),\n\t\tfieldInfo.schema,\n\t\tvalue,\n\t\tstoredSchema.getFieldSchema(fieldInfo.storedKey),\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"unhydratedFlexTreeFromInsertable.d.ts","sourceRoot":"","sources":["../../src/simple-tree/unhydratedFlexTreeFromInsertable.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAMpE,OAAO,EAKN,KAAK,QAAQ,EACb,KAAK,cAAc,EAEnB,KAAK,UAAU,EACf,sBAAsB,EACtB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAmC,KAAK,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAgB,gCAAgC,CAAC,GAAG,SAAS,iBAAiB,GAAG,SAAS,EACzF,IAAI,EAAE,GAAG,EACT,YAAY,EAAE,mBAAmB,GAC/B,GAAG,SAAS,SAAS,GAAG,SAAS,GAAG,sBAAsB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AAS,GAAG,sBAAsB,CAmB5D;AA2CD;;GAEG;AACH,wBAAgB,oCAAoC,CACnD,IAAI,EAAE,iBAAiB,EACvB,YAAY,EAAE,WAAW,CAAC,cAAc,CAAC,GACvC,sBAAsB,CA4BxB;AAuBD;;;GAGG;AACH,wBAAgB,gBAAgB,CAC/B,YAAY,EAAE,WAAW,CAAC,cAAc,CAAC,EACzC,IAAI,EAAE,cAAc,GAClB,cAAc,EAAE,CA2BlB;AAED;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GACvB,YAAY,GACZ,MAAM,GACN,MAAM,GACN,OAAO,GAEP,IAAI,GACJ,QAAQ,CAAC,SAAS,CAAC,MAAM,EAAE,iBAAiB,CAAC,CAAC,GAC9C,SAAS,iBAAiB,EAAE,GAC5B,oBAAoB,CAAC;AAExB;;;;;;;GAOG;AACH,MAAM,MAAM,oBAAoB,GAAG;IAClC,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,CAAC,EAAE,iBAAiB;CAC1C,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,UAAU,CAAC,QAAQ,CAAC,GAAG,cAAc,CAAC"}
@@ -42,7 +42,7 @@ function unhydratedFlexTreeFromInsertable(data, allowedTypes) {
42
42
  if (data === undefined) {
43
43
  // TODO: this code-path should support defaults
44
44
  if (normalizedFieldSchema.kind !== fieldSchema_js_1.FieldKind.Optional) {
45
- throw new internal_2.UsageError("Got undefined for non-optional field.");
45
+ throw new internal_2.UsageError(`Got undefined for non-optional field expecting one of ${quotedAllowedTypesWithNames(normalizedFieldSchema.allowedTypeSet)}`);
46
46
  }
47
47
  return undefined;
48
48
  }
@@ -50,6 +50,34 @@ function unhydratedFlexTreeFromInsertable(data, allowedTypes) {
50
50
  return flexTree;
51
51
  }
52
52
  exports.unhydratedFlexTreeFromInsertable = unhydratedFlexTreeFromInsertable;
53
+ /**
54
+ * Throw a usage error with a helpful message about `schema` not being in `allowedTypes` for insertable content.
55
+ */
56
+ function allowedTypesInsertableSchemaError(allowedTypes, schema) {
57
+ (0, internal_1.debugAssert)(() => !allowedTypes.has(schema) ||
58
+ "This function should only be called if the schema is not in the allowed types.");
59
+ const map = new Map([...allowedTypes].map((s) => [s.identifier, s]));
60
+ const expected = map.get(schema.identifier);
61
+ if (expected !== undefined) {
62
+ throw new internal_2.UsageError(`A node with schema ${quotedSchemaIdentifierWithName(schema)} was provided where a node with that identifier is allowed, but the actual schema required (${quotedSchemaIdentifierWithName(expected)}) is not the same schema object.
63
+ TreeNodeSchema have significant object identity and thus the exact same object must be used as the schema when defining what nodes are allowed and when constructing the node to use.`);
64
+ }
65
+ throw new internal_2.UsageError(`Expected insertable for one of ${quotedAllowedTypesWithNames(allowedTypes)}. Got node with schema ${quotedSchemaIdentifierWithName(schema)}.
66
+ Nodes are valid insertable objects, but only if their schema are in the allowed list.`);
67
+ }
68
+ /**
69
+ * Gets a description of a schema for use in error messages.
70
+ */
71
+ function quotedSchemaIdentifierWithName(schema) {
72
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
73
+ return `${JSON.stringify(schema.identifier)} (name: ${JSON.stringify(schema.name)})`;
74
+ }
75
+ /**
76
+ * Gets a description of an allowedTypes for use in error messages.
77
+ */
78
+ function quotedAllowedTypesWithNames(allowedTypes) {
79
+ return `[${[...allowedTypes].map(quotedSchemaIdentifierWithName).join(", ")}]`;
80
+ }
53
81
  /**
54
82
  * Copy content from `data` into a UnhydratedFlexTreeNode.
55
83
  */
@@ -59,11 +87,11 @@ function unhydratedFlexTreeFromInsertableNode(data, allowedTypes) {
59
87
  const inner = kernel.getInnerNodeIfUnhydrated();
60
88
  if (inner === undefined) {
61
89
  // The node is already hydrated, meaning that it already got inserted into the tree previously
62
- throw new internal_2.UsageError("A node may not be inserted into the tree more than once");
90
+ throw new internal_2.UsageError(`A node with schema ${quotedSchemaIdentifierWithName(kernel.schema)} was inserted into the tree more than once. This is not supported.`);
63
91
  }
64
92
  else {
65
93
  if (!allowedTypes.has(kernel.schema)) {
66
- throw new internal_2.UsageError("Invalid schema for this context.");
94
+ allowedTypesInsertableSchemaError(allowedTypes, kernel.schema);
67
95
  }
68
96
  return inner;
69
97
  }
@@ -81,13 +109,11 @@ exports.unhydratedFlexTreeFromInsertableNode = unhydratedFlexTreeFromInsertableN
81
109
  function getType(data, allowedTypes) {
82
110
  const possibleTypes = getPossibleTypes(allowedTypes, data);
83
111
  if (possibleTypes.length === 0) {
84
- throw new internal_2.UsageError(`The provided data is incompatible with all of the types allowed by the schema. The set of allowed types is: ${JSON.stringify([...allowedTypes].map((schema) => schema.identifier))}.`);
112
+ throw new internal_2.UsageError(`The provided data is incompatible with all of the types allowed by the schema. The set of allowed types is: ${quotedAllowedTypesWithNames(allowedTypes)}.`);
85
113
  }
86
114
  if (!(0, index_js_1.hasSingle)(possibleTypes)) {
87
115
  throw new internal_2.UsageError(`The provided data is compatible with more than one type allowed by the schema.
88
- The set of possible types is ${JSON.stringify([
89
- ...possibleTypes.map((schema) => schema.identifier),
90
- ])}.
116
+ The set of possible types is ${quotedAllowedTypesWithNames(possibleTypes)}.
91
117
  Explicitly construct an unhydrated node of the desired type to disambiguate.
92
118
  For class-based schema, this can be done by replacing an expression like "{foo: 1}" with "new MySchema({foo: 1})".`);
93
119
  }
@@ -1 +1 @@
1
- {"version":3,"file":"unhydratedFlexTreeFromInsertable.js","sourceRoot":"","sources":["../../src/simple-tree/unhydratedFlexTreeFromInsertable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAAmE;AACnE,uEAAsE;AAEtE,+CAA8E;AAE9E,8CAUyB;AACzB,yDAA0D;AAC1D,qDAA6F;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,gCAAgC,CAC/C,IAAS,EACT,YAAiC;IAEjC,MAAM,qBAAqB,GAAG,IAAA,qCAAoB,EAAC,YAAY,CAAC,CAAC;IAEjE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,+CAA+C;QAC/C,IA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I,CAAC,8BAAmB,CAAC,CAAC;QACvC,OAAO,GAAG,IAAA,yBAAc,EAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC;IAChF,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,YAAY,CAAC;IACxB,CAAC;IAED,2GAA2G;IAC3G,IAAI,IAAI,GAAG,6BAAkB,CAAC,GAAG,CAAC;IAClC,MAAM,aAAa,GAAqB,EAAE,CAAC;IAC3C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAA,uCAA4B,EAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,CAAC;QAC5E,MAAM,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC;YAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;YACzB,IAAI,GAAG,KAAK,CAAC;QACd,CAAC;QACD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;IACD,OAAO,aAAa,CAAC;AACtB,CAAC;AA9BD,4CA8BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { filterIterable, hasSingle, oneFromIterable } from \"../util/index.js\";\n\nimport {\n\tCompatibilityLevel,\n\tgetKernel,\n\tgetTreeNodeSchemaPrivateData,\n\tisTreeNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\tcontentSchemaSymbol,\n\ttype Unhydrated,\n\tUnhydratedFlexTreeNode,\n} from \"./core/index.js\";\nimport { getUnhydratedContext } from \"./createContext.js\";\nimport { normalizeFieldSchema, FieldKind, type ImplicitFieldSchema } from \"./fieldSchema.js\";\n\n/**\n * Transforms an input {@link TypedNode} tree to an {@link UnhydratedFlexTreeNode}.\n * @param data - The input tree to be converted.\n * If the data is an unsupported value (e.g. NaN), a fallback value will be used when supported,\n * otherwise an error will be thrown.\n *\n * Fallbacks:\n *\n * * `NaN` =\\> `null`\n *\n * * `+/-∞` =\\> `null`\n *\n * * `-0` =\\> `+0`\n *\n * For fields with a default value, the field may be omitted.\n * If `context` is not provided, defaults which require a context will be left empty which can be out of schema.\n *\n * @param allowedTypes - The set of types allowed by the parent context. Used to validate the input tree.\n * @remarks\n * The resulting tree will be populated with any defaults from {@link FieldProvider}s in the schema.\n *\n * Often throws UsageErrors for invalid data, but may miss some cases.\n *\n * Output should comply with the provided view schema, but this is not explicitly validated:\n * validation against stored schema (to guard against document corruption) is done elsewhere.\n */\nexport function unhydratedFlexTreeFromInsertable<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tallowedTypes: ImplicitFieldSchema,\n): TIn extends undefined ? undefined : UnhydratedFlexTreeNode {\n\tconst normalizedFieldSchema = normalizeFieldSchema(allowedTypes);\n\n\tif (data === undefined) {\n\t\t// TODO: this code-path should support defaults\n\t\tif (normalizedFieldSchema.kind !== FieldKind.Optional) {\n\t\t\tthrow new UsageError(\"Got undefined for non-optional field.\");\n\t\t}\n\t\treturn undefined as TIn extends undefined ? undefined : UnhydratedFlexTreeNode;\n\t}\n\n\tconst flexTree: UnhydratedFlexTreeNode = unhydratedFlexTreeFromInsertableNode(\n\t\tdata,\n\t\tnormalizedFieldSchema.allowedTypeSet,\n\t);\n\n\treturn flexTree as TIn extends undefined ? undefined : UnhydratedFlexTreeNode;\n}\n\n/**\n * Copy content from `data` into a UnhydratedFlexTreeNode.\n */\nexport function unhydratedFlexTreeFromInsertableNode(\n\tdata: InsertableContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): UnhydratedFlexTreeNode {\n\tif (isTreeNode(data)) {\n\t\tconst kernel = getKernel(data);\n\t\tconst inner = kernel.getInnerNodeIfUnhydrated();\n\t\tif (inner === undefined) {\n\t\t\t// The node is already hydrated, meaning that it already got inserted into the tree previously\n\t\t\tthrow new UsageError(\"A node may not be inserted into the tree more than once\");\n\t\t} else {\n\t\t\tif (!allowedTypes.has(kernel.schema)) {\n\t\t\t\tthrow new UsageError(\"Invalid schema for this context.\");\n\t\t\t}\n\t\t\treturn inner;\n\t\t}\n\t}\n\n\tconst schema = getType(data, allowedTypes);\n\tconst handler = getTreeNodeSchemaPrivateData(schema).idempotentInitialize();\n\tconst result = handler.toFlexContent(data, allowedTypes);\n\n\t// Might not match schema due to fallbacks, see TODO on toFlexContent\n\t// TODO: fix TODO in `toFlexContent`, and remove this.\n\tconst finalSchema =\n\t\toneFromIterable(filterIterable(allowedTypes, (s) => s.identifier === result[0].type)) ??\n\t\tfail(0xc9d /* missing schema */);\n\n\treturn new UnhydratedFlexTreeNode(...result, getUnhydratedContext(finalSchema));\n}\n\nfunction getType(\n\tdata: FactoryContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): TreeNodeSchema {\n\tconst possibleTypes = getPossibleTypes(allowedTypes, data);\n\tif (possibleTypes.length === 0) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is incompatible with all of the types allowed by the schema. The set of allowed types is: ${JSON.stringify(\n\t\t\t\t[...allowedTypes].map((schema) => schema.identifier),\n\t\t\t)}.`,\n\t\t);\n\t}\n\tif (!hasSingle(possibleTypes)) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is compatible with more than one type allowed by the schema.\nThe set of possible types is ${JSON.stringify([\n\t\t\t\t...possibleTypes.map((schema) => schema.identifier),\n\t\t\t])}.\nExplicitly construct an unhydrated node of the desired type to disambiguate.\nFor class-based schema, this can be done by replacing an expression like \"{foo: 1}\" with \"new MySchema({foo: 1})\".`,\n\t\t);\n\t}\n\treturn possibleTypes[0];\n}\n\n/**\n * Returns all types for which the data is schema-compatible.\n * @remarks This will respect the {@link contentSchemaSymbol} property on data to disambiguate types - if present, only that type will be returned.\n */\nexport function getPossibleTypes(\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\tdata: FactoryContent,\n): TreeNodeSchema[] {\n\tassert(data !== undefined, 0x889 /* undefined cannot be used as FactoryContent. */);\n\n\tlet toCheck: Iterable<TreeNodeSchema>;\n\tif (typeof data === \"object\" && data !== null && contentSchemaSymbol in data) {\n\t\t// If the data has an explicit brand via contentSchemaSymbol, only check that type.\n\t\tconst type = data[contentSchemaSymbol];\n\t\ttoCheck = filterIterable(allowedTypes, (schema) => schema.identifier === type);\n\t} else {\n\t\ttoCheck = allowedTypes;\n\t}\n\n\t// Start at the lowest level of compat we would ever accept: this discards types which are less compatible.\n\tlet best = CompatibilityLevel.Low;\n\tconst possibleTypes: TreeNodeSchema[] = [];\n\tfor (const schema of toCheck) {\n\t\tconst handler = getTreeNodeSchemaPrivateData(schema).idempotentInitialize();\n\t\tconst level = handler.shallowCompatibilityTest(data);\n\t\tif (level > best) {\n\t\t\tpossibleTypes.length = 0;\n\t\t\tbest = level;\n\t\t}\n\t\tif (best === level) {\n\t\t\tpossibleTypes.push(schema);\n\t\t}\n\t}\n\treturn possibleTypes;\n}\n\n/**\n * Content which can be used to build a node.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n * @system @alpha\n */\nexport type FactoryContent =\n\t| IFluidHandle\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| Iterable<readonly [string, InsertableContent]>\n\t| readonly InsertableContent[]\n\t| FactoryContentObject;\n\n/**\n * Record-like object which can be used to build some kinds of nodes.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n *\n * Supports object and map nodes.\n * @system @alpha\n */\nexport type FactoryContentObject = {\n\treadonly [P in string]?: InsertableContent;\n};\n\n/**\n * Content which can be inserted into a tree.\n * @system @alpha\n */\nexport type InsertableContent = Unhydrated<TreeNode> | FactoryContent;\n"]}
1
+ {"version":3,"file":"unhydratedFlexTreeFromInsertable.js","sourceRoot":"","sources":["../../src/simple-tree/unhydratedFlexTreeFromInsertable.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,kEAAgF;AAChF,uEAAsE;AAEtE,+CAA8E;AAE9E,8CAUyB;AACzB,yDAA0D;AAC1D,qDAA6F;AAE7F;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,SAAgB,gCAAgC,CAC/C,IAAS,EACT,YAAiC;IAEjC,MAAM,qBAAqB,GAAG,IAAA,qCAAoB,EAAC,YAAY,CAAC,CAAC;IAEjE,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;QACxB,+CAA+C;QAC/C,IAAI,qBAAqB,CAAC,IAAI,KAAK,0BAAS,CAAC,QAAQ,EAAE,CAAC;YACvD,MAAM,IAAI,qBAAU,CACnB,yDAAyD,2BAA2B,CAAC,qBAAqB,CAAC,cAAc,CAAC,EAAE,CAC5H,CAAC;QACH,CAAC;QACD,OAAO,SAAuE,CAAC;IAChF,CAAC;IAED,MAAM,QAAQ,GAA2B,oCAAoC,CAC5E,IAAI,EACJ,qBAAqB,CAAC,cAAc,CACpC,CAAC;IAEF,OAAO,QAAsE,CAAC;AAC/E,CAAC;AAtBD,4EAsBC;AAED;;GAEG;AACH,SAAS,iCAAiC,CACzC,YAAyC,EACzC,MAAsB;IAEtB,IAAA,sBAAW,EACV,GAAG,EAAE,CACJ,CAAC,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC;QACzB,gFAAgF,CACjF,CAAC;IACF,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACrE,MAAM,QAAQ,GAAG,GAAG,CAAC,GAAG,CAAC,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AyC,EACzC,IAAoB;IAEpB,IAAA,iBAAM,EAAC,IAAI,KAAK,SAAS,EAAE,KAAK,CAAC,iDAAiD,CAAC,CAAC;IAEpF,IAAI,OAAiC,CAAC;IACtC,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAI,8BAAmB,IAAI,IAAI,EAAE,CAAC;QAC9E,mFAAmF;QACnF,MAAM,IAAI,GAAG,IAAI,CAAC,8BAAmB,CAAC,CAAC;QACvC,OAAO,GAAG,IAAA,yBAAc,EAAC,YAAY,EAAE,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,KAAK,IAAI,CAAC,CAAC;IAChF,CAAC;SAAM,CAAC;QACP,OAAO,GAAG,YAAY,CAAC;IACxB,CAAC;IAED,2GAA2G;IAC3G,IAAI,IAAI,GAAG,6BAAkB,CAAC,GAAG,CAAC;IAClC,MAAM,aAAa,GAAqB,EAAE,CAAC;IAC3C,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC9B,MAAM,OAAO,GAAG,IAAA,uCAA4B,EAAC,MAAM,CAAC,CAAC,oBAAoB,EAAE,CAAC;QAC5E,MAAM,KAAK,GAAG,OAAO,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC;QACrD,IAAI,KAAK,GAAG,IAAI,EAAE,CAAC;YAClB,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC;YACzB,IAAI,GAAG,KAAK,CAAC;QACd,CAAC;QACD,IAAI,IAAI,KAAK,KAAK,EAAE,CAAC;YACpB,aAAa,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACF,CAAC;IACD,OAAO,aAAa,CAAC;AACtB,CAAC;AA9BD,4CA8BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces\";\nimport { assert, debugAssert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { filterIterable, hasSingle, oneFromIterable } from \"../util/index.js\";\n\nimport {\n\tCompatibilityLevel,\n\tgetKernel,\n\tgetTreeNodeSchemaPrivateData,\n\tisTreeNode,\n\ttype TreeNode,\n\ttype TreeNodeSchema,\n\tcontentSchemaSymbol,\n\ttype Unhydrated,\n\tUnhydratedFlexTreeNode,\n} from \"./core/index.js\";\nimport { getUnhydratedContext } from \"./createContext.js\";\nimport { normalizeFieldSchema, FieldKind, type ImplicitFieldSchema } from \"./fieldSchema.js\";\n\n/**\n * Transforms an input {@link TypedNode} tree to an {@link UnhydratedFlexTreeNode}.\n * @param data - The input tree to be converted.\n * If the data is an unsupported value (e.g. NaN), a fallback value will be used when supported,\n * otherwise an error will be thrown.\n *\n * Fallbacks:\n *\n * * `NaN` =\\> `null`\n *\n * * `+/-∞` =\\> `null`\n *\n * * `-0` =\\> `+0`\n *\n * For fields with a default value, the field may be omitted.\n * If `context` is not provided, defaults which require a context will be left empty which can be out of schema.\n *\n * @param allowedTypes - The set of types allowed by the parent context. Used to validate the input tree.\n * @remarks\n * The resulting tree will be populated with any defaults from {@link FieldProvider}s in the schema.\n *\n * Often throws UsageErrors for invalid data, but may miss some cases.\n *\n * Output should comply with the provided view schema, but this is not explicitly validated:\n * validation against stored schema (to guard against document corruption) is done elsewhere.\n */\nexport function unhydratedFlexTreeFromInsertable<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tallowedTypes: ImplicitFieldSchema,\n): TIn extends undefined ? undefined : UnhydratedFlexTreeNode {\n\tconst normalizedFieldSchema = normalizeFieldSchema(allowedTypes);\n\n\tif (data === undefined) {\n\t\t// TODO: this code-path should support defaults\n\t\tif (normalizedFieldSchema.kind !== FieldKind.Optional) {\n\t\t\tthrow new UsageError(\n\t\t\t\t`Got undefined for non-optional field expecting one of ${quotedAllowedTypesWithNames(normalizedFieldSchema.allowedTypeSet)}`,\n\t\t\t);\n\t\t}\n\t\treturn undefined as TIn extends undefined ? undefined : UnhydratedFlexTreeNode;\n\t}\n\n\tconst flexTree: UnhydratedFlexTreeNode = unhydratedFlexTreeFromInsertableNode(\n\t\tdata,\n\t\tnormalizedFieldSchema.allowedTypeSet,\n\t);\n\n\treturn flexTree as TIn extends undefined ? undefined : UnhydratedFlexTreeNode;\n}\n\n/**\n * Throw a usage error with a helpful message about `schema` not being in `allowedTypes` for insertable content.\n */\nfunction allowedTypesInsertableSchemaError(\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\tschema: TreeNodeSchema,\n): never {\n\tdebugAssert(\n\t\t() =>\n\t\t\t!allowedTypes.has(schema) ||\n\t\t\t\"This function should only be called if the schema is not in the allowed types.\",\n\t);\n\tconst map = new Map([...allowedTypes].map((s) => [s.identifier, s]));\n\tconst expected = map.get(schema.identifier);\n\tif (expected !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t`A node with schema ${quotedSchemaIdentifierWithName(schema)} was provided where a node with that identifier is allowed, but the actual schema required (${quotedSchemaIdentifierWithName(expected)}) is not the same schema object.\nTreeNodeSchema have significant object identity and thus the exact same object must be used as the schema when defining what nodes are allowed and when constructing the node to use.`,\n\t\t);\n\t}\n\tthrow new UsageError(\n\t\t`Expected insertable for one of ${quotedAllowedTypesWithNames(allowedTypes)}. Got node with schema ${quotedSchemaIdentifierWithName(schema)}.\nNodes are valid insertable objects, but only if their schema are in the allowed list.`,\n\t);\n}\n\n/**\n * Gets a description of a schema for use in error messages.\n */\nfunction quotedSchemaIdentifierWithName(schema: TreeNodeSchema): string {\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type\n\treturn `${JSON.stringify(schema.identifier)} (name: ${JSON.stringify((schema as Function).name)})`;\n}\n\n/**\n * Gets a description of an allowedTypes for use in error messages.\n */\nfunction quotedAllowedTypesWithNames(allowedTypes: Iterable<TreeNodeSchema>): string {\n\treturn `[${[...allowedTypes].map(quotedSchemaIdentifierWithName).join(\", \")}]`;\n}\n\n/**\n * Copy content from `data` into a UnhydratedFlexTreeNode.\n */\nexport function unhydratedFlexTreeFromInsertableNode(\n\tdata: InsertableContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): UnhydratedFlexTreeNode {\n\tif (isTreeNode(data)) {\n\t\tconst kernel = getKernel(data);\n\t\tconst inner = kernel.getInnerNodeIfUnhydrated();\n\t\tif (inner === undefined) {\n\t\t\t// The node is already hydrated, meaning that it already got inserted into the tree previously\n\t\t\tthrow new UsageError(\n\t\t\t\t`A node with schema ${quotedSchemaIdentifierWithName(kernel.schema)} was inserted into the tree more than once. This is not supported.`,\n\t\t\t);\n\t\t} else {\n\t\t\tif (!allowedTypes.has(kernel.schema)) {\n\t\t\t\tallowedTypesInsertableSchemaError(allowedTypes, kernel.schema);\n\t\t\t}\n\t\t\treturn inner;\n\t\t}\n\t}\n\n\tconst schema = getType(data, allowedTypes);\n\tconst handler = getTreeNodeSchemaPrivateData(schema).idempotentInitialize();\n\tconst result = handler.toFlexContent(data, allowedTypes);\n\n\t// Might not match schema due to fallbacks, see TODO on toFlexContent\n\t// TODO: fix TODO in `toFlexContent`, and remove this.\n\tconst finalSchema =\n\t\toneFromIterable(filterIterable(allowedTypes, (s) => s.identifier === result[0].type)) ??\n\t\tfail(0xc9d /* missing schema */);\n\n\treturn new UnhydratedFlexTreeNode(...result, getUnhydratedContext(finalSchema));\n}\n\nfunction getType(\n\tdata: FactoryContent,\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n): TreeNodeSchema {\n\tconst possibleTypes = getPossibleTypes(allowedTypes, data);\n\tif (possibleTypes.length === 0) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is incompatible with all of the types allowed by the schema. The set of allowed types is: ${quotedAllowedTypesWithNames(allowedTypes)}.`,\n\t\t);\n\t}\n\tif (!hasSingle(possibleTypes)) {\n\t\tthrow new UsageError(\n\t\t\t`The provided data is compatible with more than one type allowed by the schema.\nThe set of possible types is ${quotedAllowedTypesWithNames(possibleTypes)}.\nExplicitly construct an unhydrated node of the desired type to disambiguate.\nFor class-based schema, this can be done by replacing an expression like \"{foo: 1}\" with \"new MySchema({foo: 1})\".`,\n\t\t);\n\t}\n\treturn possibleTypes[0];\n}\n\n/**\n * Returns all types for which the data is schema-compatible.\n * @remarks This will respect the {@link contentSchemaSymbol} property on data to disambiguate types - if present, only that type will be returned.\n */\nexport function getPossibleTypes(\n\tallowedTypes: ReadonlySet<TreeNodeSchema>,\n\tdata: FactoryContent,\n): TreeNodeSchema[] {\n\tassert(data !== undefined, 0x889 /* undefined cannot be used as FactoryContent. */);\n\n\tlet toCheck: Iterable<TreeNodeSchema>;\n\tif (typeof data === \"object\" && data !== null && contentSchemaSymbol in data) {\n\t\t// If the data has an explicit brand via contentSchemaSymbol, only check that type.\n\t\tconst type = data[contentSchemaSymbol];\n\t\ttoCheck = filterIterable(allowedTypes, (schema) => schema.identifier === type);\n\t} else {\n\t\ttoCheck = allowedTypes;\n\t}\n\n\t// Start at the lowest level of compat we would ever accept: this discards types which are less compatible.\n\tlet best = CompatibilityLevel.Low;\n\tconst possibleTypes: TreeNodeSchema[] = [];\n\tfor (const schema of toCheck) {\n\t\tconst handler = getTreeNodeSchemaPrivateData(schema).idempotentInitialize();\n\t\tconst level = handler.shallowCompatibilityTest(data);\n\t\tif (level > best) {\n\t\t\tpossibleTypes.length = 0;\n\t\t\tbest = level;\n\t\t}\n\t\tif (best === level) {\n\t\t\tpossibleTypes.push(schema);\n\t\t}\n\t}\n\treturn possibleTypes;\n}\n\n/**\n * Content which can be used to build a node.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n * @system @alpha\n */\nexport type FactoryContent =\n\t| IFluidHandle\n\t| string\n\t| number\n\t| boolean\n\t// eslint-disable-next-line @rushstack/no-new-null\n\t| null\n\t| Iterable<readonly [string, InsertableContent]>\n\t| readonly InsertableContent[]\n\t| FactoryContentObject;\n\n/**\n * Record-like object which can be used to build some kinds of nodes.\n * @remarks\n * Can contain unhydrated nodes, but can not be an unhydrated node at the root.\n *\n * Supports object and map nodes.\n * @system @alpha\n */\nexport type FactoryContentObject = {\n\treadonly [P in string]?: InsertableContent;\n};\n\n/**\n * Content which can be inserted into a tree.\n * @system @alpha\n */\nexport type InsertableContent = Unhydrated<TreeNode> | FactoryContent;\n"]}