@fluidframework/tree 2.74.0 → 2.80.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 (895) hide show
  1. package/.eslintrc.cjs +1 -16
  2. package/CHANGELOG.md +18 -0
  3. package/api-report/tree.alpha.api.md +20 -2
  4. package/dist/alpha.d.ts +4 -0
  5. package/dist/codec/codec.d.ts +31 -3
  6. package/dist/codec/codec.d.ts.map +1 -1
  7. package/dist/codec/codec.js +10 -0
  8. package/dist/codec/codec.js.map +1 -1
  9. package/dist/codec/index.d.ts +2 -2
  10. package/dist/codec/index.d.ts.map +1 -1
  11. package/dist/codec/index.js +2 -2
  12. package/dist/codec/index.js.map +1 -1
  13. package/dist/codec/versioned/codec.d.ts +80 -22
  14. package/dist/codec/versioned/codec.d.ts.map +1 -1
  15. package/dist/codec/versioned/codec.js +137 -15
  16. package/dist/codec/versioned/codec.js.map +1 -1
  17. package/dist/codec/versioned/index.d.ts +1 -1
  18. package/dist/codec/versioned/index.d.ts.map +1 -1
  19. package/dist/codec/versioned/index.js +2 -2
  20. package/dist/codec/versioned/index.js.map +1 -1
  21. package/dist/core/index.d.ts +2 -2
  22. package/dist/core/index.d.ts.map +1 -1
  23. package/dist/core/index.js +3 -4
  24. package/dist/core/index.js.map +1 -1
  25. package/dist/core/rebase/changeRebaser.d.ts +36 -2
  26. package/dist/core/rebase/changeRebaser.d.ts.map +1 -1
  27. package/dist/core/rebase/changeRebaser.js.map +1 -1
  28. package/dist/core/rebase/index.d.ts +2 -2
  29. package/dist/core/rebase/index.d.ts.map +1 -1
  30. package/dist/core/rebase/index.js +1 -2
  31. package/dist/core/rebase/index.js.map +1 -1
  32. package/dist/core/rebase/types.d.ts +6 -2
  33. package/dist/core/rebase/types.d.ts.map +1 -1
  34. package/dist/core/rebase/types.js +1 -12
  35. package/dist/core/rebase/types.js.map +1 -1
  36. package/dist/core/rebase/utils.js +3 -3
  37. package/dist/core/rebase/utils.js.map +1 -1
  38. package/dist/core/schema-stored/schema.js +3 -3
  39. package/dist/core/schema-stored/schema.js.map +1 -1
  40. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  41. package/dist/core/tree/anchorSet.js +3 -4
  42. package/dist/core/tree/anchorSet.js.map +1 -1
  43. package/dist/core/tree/detachedFieldIndex.d.ts +1 -2
  44. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  45. package/dist/core/tree/detachedFieldIndex.js +12 -56
  46. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  47. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts +18 -10
  48. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -1
  49. package/dist/core/tree/detachedFieldIndexCodecCommon.js +6 -6
  50. package/dist/core/tree/detachedFieldIndexCodecCommon.js.map +1 -1
  51. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts +2 -3
  52. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  53. package/dist/core/tree/detachedFieldIndexCodecV1.js +4 -5
  54. package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  55. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts +2 -3
  56. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  57. package/dist/core/tree/detachedFieldIndexCodecV2.js +4 -6
  58. package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  59. package/dist/core/tree/detachedFieldIndexCodecs.d.ts +5 -6
  60. package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  61. package/dist/core/tree/detachedFieldIndexCodecs.js +11 -41
  62. package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  63. package/dist/core/tree/index.d.ts +1 -1
  64. package/dist/core/tree/index.d.ts.map +1 -1
  65. package/dist/core/tree/index.js +2 -2
  66. package/dist/core/tree/index.js.map +1 -1
  67. package/dist/core/tree/mapTree.js +1 -1
  68. package/dist/core/tree/mapTree.js.map +1 -1
  69. package/dist/core/tree/sparseTree.d.ts.map +1 -1
  70. package/dist/core/tree/sparseTree.js +1 -0
  71. package/dist/core/tree/sparseTree.js.map +1 -1
  72. package/dist/core/tree/treeTextFormat.d.ts.map +1 -1
  73. package/dist/core/tree/treeTextFormat.js +5 -9
  74. package/dist/core/tree/treeTextFormat.js.map +1 -1
  75. package/dist/feature-libraries/changeAtomIdBTree.d.ts +10 -0
  76. package/dist/feature-libraries/changeAtomIdBTree.d.ts.map +1 -0
  77. package/dist/feature-libraries/changeAtomIdBTree.js +16 -0
  78. package/dist/feature-libraries/changeAtomIdBTree.js.map +1 -0
  79. package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -1
  80. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  81. package/dist/feature-libraries/chunked-forest/chunkedForest.js +6 -6
  82. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  83. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  84. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +7 -4
  85. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  86. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  87. package/dist/feature-libraries/chunked-forest/codec/codecs.js +19 -11
  88. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  89. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +3 -3
  90. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  91. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +9 -5
  92. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  93. package/dist/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  94. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  95. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +15 -5
  96. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  97. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +19 -14
  98. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  99. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -1
  100. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  101. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +11 -1
  102. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  103. package/dist/feature-libraries/default-schema/mappedEditBuilder.d.ts +2 -0
  104. package/dist/feature-libraries/default-schema/mappedEditBuilder.d.ts.map +1 -1
  105. package/dist/feature-libraries/default-schema/mappedEditBuilder.js +6 -0
  106. package/dist/feature-libraries/default-schema/mappedEditBuilder.js.map +1 -1
  107. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  108. package/dist/feature-libraries/flex-tree/lazyField.js +11 -13
  109. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  110. package/dist/feature-libraries/index.d.ts +3 -2
  111. package/dist/feature-libraries/index.d.ts.map +1 -1
  112. package/dist/feature-libraries/index.js +9 -7
  113. package/dist/feature-libraries/index.js.map +1 -1
  114. package/dist/feature-libraries/indexing/anchorTreeIndex.js +6 -6
  115. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  116. package/dist/feature-libraries/mitigatedChangeFamily.d.ts.map +1 -1
  117. package/dist/feature-libraries/mitigatedChangeFamily.js +10 -1
  118. package/dist/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  119. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  120. package/dist/feature-libraries/modular-schema/comparison.js +12 -9
  121. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  122. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +25 -0
  123. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -0
  124. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js +59 -0
  125. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -0
  126. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +3 -3
  127. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  128. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  129. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  130. package/dist/feature-libraries/modular-schema/genericFieldKind.js +4 -4
  131. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  132. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.js +2 -2
  133. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.js.map +1 -1
  134. package/dist/feature-libraries/modular-schema/index.d.ts +4 -2
  135. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  136. package/dist/feature-libraries/modular-schema/index.js +11 -7
  137. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  138. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +49 -0
  139. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -0
  140. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +315 -0
  141. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -0
  142. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.d.ts +15 -0
  143. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.d.ts.map +1 -0
  144. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js +31 -0
  145. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -0
  146. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
  147. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  148. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +25 -288
  149. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  150. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +14 -8
  151. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  152. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +225 -195
  153. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  154. package/dist/feature-libraries/modular-schema/{modularChangeFormat.d.ts → modularChangeFormatV1.d.ts} +5 -6
  155. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -0
  156. package/dist/feature-libraries/modular-schema/{modularChangeFormat.js → modularChangeFormatV1.js} +7 -7
  157. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -0
  158. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +112 -0
  159. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -0
  160. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js +21 -0
  161. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -0
  162. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +13 -3
  163. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  164. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  165. package/dist/feature-libraries/node-identifier/mockNodeIdentifierManager.js +1 -1
  166. package/dist/feature-libraries/node-identifier/mockNodeIdentifierManager.js.map +1 -1
  167. package/dist/feature-libraries/object-forest/objectForest.js +4 -4
  168. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  169. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  170. package/dist/feature-libraries/optional-field/optionalField.js +34 -39
  171. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  172. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  173. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +14 -2
  174. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  175. package/dist/feature-libraries/schema-index/codec.d.ts +7 -21
  176. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  177. package/dist/feature-libraries/schema-index/codec.js +28 -70
  178. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  179. package/dist/feature-libraries/schema-index/index.d.ts +2 -2
  180. package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
  181. package/dist/feature-libraries/schema-index/index.js +2 -5
  182. package/dist/feature-libraries/schema-index/index.js.map +1 -1
  183. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts +1 -9
  184. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  185. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -12
  186. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  187. package/dist/feature-libraries/schemaChecker.d.ts.map +1 -1
  188. package/dist/feature-libraries/schemaChecker.js +11 -6
  189. package/dist/feature-libraries/schemaChecker.js.map +1 -1
  190. package/dist/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  191. package/dist/feature-libraries/sequence-field/compose.js +17 -13
  192. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  193. package/dist/feature-libraries/sequence-field/invert.js +5 -4
  194. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  195. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  196. package/dist/feature-libraries/sequence-field/moveEffectTable.js +15 -9
  197. package/dist/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  198. package/dist/feature-libraries/sequence-field/rebase.js +26 -18
  199. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  200. package/dist/feature-libraries/sequence-field/replaceRevisions.d.ts +2 -2
  201. package/dist/feature-libraries/sequence-field/replaceRevisions.d.ts.map +1 -1
  202. package/dist/feature-libraries/sequence-field/replaceRevisions.js +40 -35
  203. package/dist/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  204. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  205. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +16 -8
  206. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  207. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  208. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js +4 -2
  209. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  210. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  211. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +6 -3
  212. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  213. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  214. package/dist/feature-libraries/sequence-field/utils.js +46 -27
  215. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  216. package/dist/feature-libraries/treeCursorUtils.js +7 -7
  217. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  218. package/dist/feature-libraries/treeTextCursor.js +2 -2
  219. package/dist/feature-libraries/treeTextCursor.js.map +1 -1
  220. package/dist/feature-libraries/valueUtilities.d.ts.map +1 -1
  221. package/dist/feature-libraries/valueUtilities.js +16 -8
  222. package/dist/feature-libraries/valueUtilities.js.map +1 -1
  223. package/dist/index.d.ts +2 -2
  224. package/dist/index.d.ts.map +1 -1
  225. package/dist/index.js.map +1 -1
  226. package/dist/packageVersion.d.ts +1 -1
  227. package/dist/packageVersion.js +1 -1
  228. package/dist/packageVersion.js.map +1 -1
  229. package/dist/shared-tree/schematizingTreeView.d.ts +2 -3
  230. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  231. package/dist/shared-tree/schematizingTreeView.js +20 -9
  232. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  233. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  234. package/dist/shared-tree/sharedTree.js +61 -44
  235. package/dist/shared-tree/sharedTree.js.map +1 -1
  236. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +1 -1
  237. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  238. package/dist/shared-tree/sharedTreeChangeCodecs.js +9 -8
  239. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  240. package/dist/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  241. package/dist/shared-tree/sharedTreeChangeEnricher.js +4 -2
  242. package/dist/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  243. package/dist/shared-tree/sharedTreeChangeFamily.d.ts +3 -2
  244. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  245. package/dist/shared-tree/sharedTreeChangeFamily.js +19 -14
  246. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  247. package/dist/shared-tree/sharedTreeEditBuilder.d.ts.map +1 -1
  248. package/dist/shared-tree/sharedTreeEditBuilder.js +1 -1
  249. package/dist/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  250. package/dist/shared-tree/treeAlpha.d.ts +35 -29
  251. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  252. package/dist/shared-tree/treeAlpha.js +21 -23
  253. package/dist/shared-tree/treeAlpha.js.map +1 -1
  254. package/dist/shared-tree/treeCheckout.d.ts +2 -0
  255. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  256. package/dist/shared-tree/treeCheckout.js +31 -18
  257. package/dist/shared-tree/treeCheckout.js.map +1 -1
  258. package/dist/shared-tree-core/branch.d.ts +3 -1
  259. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  260. package/dist/shared-tree-core/branch.js +5 -3
  261. package/dist/shared-tree-core/branch.js.map +1 -1
  262. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  263. package/dist/shared-tree-core/branchCommitEnricher.js +1 -1
  264. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  265. package/dist/shared-tree-core/editManager.js +1 -1
  266. package/dist/shared-tree-core/editManager.js.map +1 -1
  267. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  268. package/dist/shared-tree-core/editManagerCodecs.js +9 -4
  269. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  270. package/dist/shared-tree-core/editManagerFormatCommons.d.ts +1 -0
  271. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  272. package/dist/shared-tree-core/editManagerFormatCommons.js +6 -0
  273. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  274. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +2 -2
  275. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  276. package/dist/shared-tree-core/editManagerFormatV1toV4.js +1 -0
  277. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  278. package/dist/shared-tree-core/editManagerSummarizer.js +3 -3
  279. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  280. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +1 -1
  281. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  282. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  283. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  284. package/dist/shared-tree-core/messageCodecVSharedBranches.js +2 -1
  285. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  286. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  287. package/dist/shared-tree-core/messageCodecs.js +8 -4
  288. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  289. package/dist/shared-tree-core/messageFormat.d.ts +1 -0
  290. package/dist/shared-tree-core/messageFormat.d.ts.map +1 -1
  291. package/dist/shared-tree-core/messageFormat.js +6 -0
  292. package/dist/shared-tree-core/messageFormat.js.map +1 -1
  293. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts +3 -2
  294. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  295. package/dist/shared-tree-core/messageFormatV1ToV4.js +8 -1
  296. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  297. package/dist/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  298. package/dist/shared-tree-core/sequenceIdUtils.js +4 -4
  299. package/dist/shared-tree-core/sequenceIdUtils.js.map +1 -1
  300. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  301. package/dist/shared-tree-core/sharedTreeCore.js +12 -8
  302. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  303. package/dist/shared-tree-core/transaction.d.ts +25 -8
  304. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  305. package/dist/shared-tree-core/transaction.js +65 -30
  306. package/dist/shared-tree-core/transaction.js.map +1 -1
  307. package/dist/shared-tree-core/transactionEnricher.d.ts +2 -2
  308. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  309. package/dist/shared-tree-core/transactionEnricher.js +3 -3
  310. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  311. package/dist/simple-tree/api/configuration.js +1 -1
  312. package/dist/simple-tree/api/configuration.js.map +1 -1
  313. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  314. package/dist/simple-tree/api/customTree.js +13 -9
  315. package/dist/simple-tree/api/customTree.js.map +1 -1
  316. package/dist/simple-tree/api/discrepancies.d.ts.map +1 -1
  317. package/dist/simple-tree/api/discrepancies.js +21 -17
  318. package/dist/simple-tree/api/discrepancies.js.map +1 -1
  319. package/dist/simple-tree/api/index.d.ts +1 -1
  320. package/dist/simple-tree/api/index.d.ts.map +1 -1
  321. package/dist/simple-tree/api/index.js.map +1 -1
  322. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  323. package/dist/simple-tree/api/schemaFactory.js +12 -8
  324. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  325. package/dist/simple-tree/api/schemaFromSimple.js +18 -9
  326. package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
  327. package/dist/simple-tree/api/simpleSchemaCodec.js +10 -5
  328. package/dist/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  329. package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  330. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +15 -11
  331. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  332. package/dist/simple-tree/api/simpleTreeIndex.js +10 -10
  333. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  334. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  335. package/dist/simple-tree/api/storedSchema.js +2 -3
  336. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  337. package/dist/simple-tree/api/transactionTypes.d.ts +17 -4
  338. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  339. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  340. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  341. package/dist/simple-tree/api/treeNodeApi.js +21 -13
  342. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  343. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  344. package/dist/simple-tree/api/verboseTree.js +14 -9
  345. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  346. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  347. package/dist/simple-tree/core/treeNodeKernel.js +6 -3
  348. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  349. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  350. package/dist/simple-tree/core/unhydratedFlexTree.js +20 -15
  351. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  352. package/dist/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  353. package/dist/simple-tree/getTreeNodeForField.js +2 -1
  354. package/dist/simple-tree/getTreeNodeForField.js.map +1 -1
  355. package/dist/simple-tree/index.d.ts +1 -1
  356. package/dist/simple-tree/index.d.ts.map +1 -1
  357. package/dist/simple-tree/index.js.map +1 -1
  358. package/dist/simple-tree/leafNodeSchema.js +9 -6
  359. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  360. package/dist/simple-tree/node-kinds/array/arrayNode.js +15 -15
  361. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  362. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  363. package/dist/simple-tree/node-kinds/object/objectNode.js +4 -5
  364. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  365. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  366. package/dist/simple-tree/node-kinds/record/recordNode.js +2 -3
  367. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  368. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  369. package/dist/simple-tree/toStoredSchema.js +9 -5
  370. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  371. package/dist/treeFactory.js +7 -3
  372. package/dist/treeFactory.js.map +1 -1
  373. package/dist/util/bTreeUtils.js +1 -1
  374. package/dist/util/bTreeUtils.js.map +1 -1
  375. package/dist/util/breakable.js +7 -9
  376. package/dist/util/breakable.js.map +1 -1
  377. package/dist/util/idAllocator.d.ts.map +1 -1
  378. package/dist/util/idAllocator.js +1 -2
  379. package/dist/util/idAllocator.js.map +1 -1
  380. package/dist/util/nestedMap.d.ts.map +1 -1
  381. package/dist/util/nestedMap.js +1 -1
  382. package/dist/util/nestedMap.js.map +1 -1
  383. package/dist/util/utils.d.ts.map +1 -1
  384. package/dist/util/utils.js +16 -15
  385. package/dist/util/utils.js.map +1 -1
  386. package/eslint.config.mts +1 -16
  387. package/lib/alpha.d.ts +4 -0
  388. package/lib/codec/codec.d.ts +31 -3
  389. package/lib/codec/codec.d.ts.map +1 -1
  390. package/lib/codec/codec.js +10 -0
  391. package/lib/codec/codec.js.map +1 -1
  392. package/lib/codec/index.d.ts +2 -2
  393. package/lib/codec/index.d.ts.map +1 -1
  394. package/lib/codec/index.js +1 -1
  395. package/lib/codec/index.js.map +1 -1
  396. package/lib/codec/versioned/codec.d.ts +80 -22
  397. package/lib/codec/versioned/codec.d.ts.map +1 -1
  398. package/lib/codec/versioned/codec.js +138 -15
  399. package/lib/codec/versioned/codec.js.map +1 -1
  400. package/lib/codec/versioned/index.d.ts +1 -1
  401. package/lib/codec/versioned/index.d.ts.map +1 -1
  402. package/lib/codec/versioned/index.js +1 -1
  403. package/lib/codec/versioned/index.js.map +1 -1
  404. package/lib/core/index.d.ts +2 -2
  405. package/lib/core/index.d.ts.map +1 -1
  406. package/lib/core/index.js +2 -2
  407. package/lib/core/index.js.map +1 -1
  408. package/lib/core/rebase/changeRebaser.d.ts +36 -2
  409. package/lib/core/rebase/changeRebaser.d.ts.map +1 -1
  410. package/lib/core/rebase/changeRebaser.js.map +1 -1
  411. package/lib/core/rebase/index.d.ts +2 -2
  412. package/lib/core/rebase/index.d.ts.map +1 -1
  413. package/lib/core/rebase/index.js +1 -1
  414. package/lib/core/rebase/index.js.map +1 -1
  415. package/lib/core/rebase/types.d.ts +6 -2
  416. package/lib/core/rebase/types.d.ts.map +1 -1
  417. package/lib/core/rebase/types.js +0 -10
  418. package/lib/core/rebase/types.js.map +1 -1
  419. package/lib/core/rebase/utils.js +3 -3
  420. package/lib/core/rebase/utils.js.map +1 -1
  421. package/lib/core/schema-stored/schema.js +3 -3
  422. package/lib/core/schema-stored/schema.js.map +1 -1
  423. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  424. package/lib/core/tree/anchorSet.js +3 -4
  425. package/lib/core/tree/anchorSet.js.map +1 -1
  426. package/lib/core/tree/detachedFieldIndex.d.ts +1 -2
  427. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  428. package/lib/core/tree/detachedFieldIndex.js +13 -57
  429. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  430. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts +18 -10
  431. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -1
  432. package/lib/core/tree/detachedFieldIndexCodecCommon.js +4 -4
  433. package/lib/core/tree/detachedFieldIndexCodecCommon.js.map +1 -1
  434. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts +2 -3
  435. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  436. package/lib/core/tree/detachedFieldIndexCodecV1.js +4 -5
  437. package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  438. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts +2 -3
  439. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  440. package/lib/core/tree/detachedFieldIndexCodecV2.js +4 -6
  441. package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  442. package/lib/core/tree/detachedFieldIndexCodecs.d.ts +5 -6
  443. package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  444. package/lib/core/tree/detachedFieldIndexCodecs.js +12 -39
  445. package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  446. package/lib/core/tree/index.d.ts +1 -1
  447. package/lib/core/tree/index.d.ts.map +1 -1
  448. package/lib/core/tree/index.js +1 -1
  449. package/lib/core/tree/index.js.map +1 -1
  450. package/lib/core/tree/mapTree.js +1 -1
  451. package/lib/core/tree/mapTree.js.map +1 -1
  452. package/lib/core/tree/sparseTree.d.ts.map +1 -1
  453. package/lib/core/tree/sparseTree.js +1 -0
  454. package/lib/core/tree/sparseTree.js.map +1 -1
  455. package/lib/core/tree/treeTextFormat.d.ts.map +1 -1
  456. package/lib/core/tree/treeTextFormat.js +5 -9
  457. package/lib/core/tree/treeTextFormat.js.map +1 -1
  458. package/lib/feature-libraries/changeAtomIdBTree.d.ts +10 -0
  459. package/lib/feature-libraries/changeAtomIdBTree.d.ts.map +1 -0
  460. package/lib/feature-libraries/changeAtomIdBTree.js +11 -0
  461. package/lib/feature-libraries/changeAtomIdBTree.js.map +1 -0
  462. package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
  463. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  464. package/lib/feature-libraries/chunked-forest/chunkedForest.js +6 -6
  465. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  466. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  467. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +7 -4
  468. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  469. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  470. package/lib/feature-libraries/chunked-forest/codec/codecs.js +19 -11
  471. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  472. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +3 -3
  473. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  474. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +9 -5
  475. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  476. package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  477. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  478. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +15 -5
  479. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  480. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +19 -14
  481. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  482. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -1
  483. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  484. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +11 -1
  485. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  486. package/lib/feature-libraries/default-schema/mappedEditBuilder.d.ts +2 -0
  487. package/lib/feature-libraries/default-schema/mappedEditBuilder.d.ts.map +1 -1
  488. package/lib/feature-libraries/default-schema/mappedEditBuilder.js +6 -0
  489. package/lib/feature-libraries/default-schema/mappedEditBuilder.js.map +1 -1
  490. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  491. package/lib/feature-libraries/flex-tree/lazyField.js +11 -13
  492. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  493. package/lib/feature-libraries/index.d.ts +3 -2
  494. package/lib/feature-libraries/index.d.ts.map +1 -1
  495. package/lib/feature-libraries/index.js +3 -2
  496. package/lib/feature-libraries/index.js.map +1 -1
  497. package/lib/feature-libraries/indexing/anchorTreeIndex.js +6 -6
  498. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  499. package/lib/feature-libraries/mitigatedChangeFamily.d.ts.map +1 -1
  500. package/lib/feature-libraries/mitigatedChangeFamily.js +10 -1
  501. package/lib/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  502. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  503. package/lib/feature-libraries/modular-schema/comparison.js +12 -9
  504. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  505. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +25 -0
  506. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -0
  507. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js +55 -0
  508. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -0
  509. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +3 -3
  510. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  511. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  512. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  513. package/lib/feature-libraries/modular-schema/genericFieldKind.js +5 -5
  514. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  515. package/lib/feature-libraries/modular-schema/genericFieldKindCodecs.js +1 -1
  516. package/lib/feature-libraries/modular-schema/genericFieldKindCodecs.js.map +1 -1
  517. package/lib/feature-libraries/modular-schema/index.d.ts +4 -2
  518. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  519. package/lib/feature-libraries/modular-schema/index.js +3 -1
  520. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  521. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +49 -0
  522. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -0
  523. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +298 -0
  524. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -0
  525. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.d.ts +15 -0
  526. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.d.ts.map +1 -0
  527. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.js +27 -0
  528. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -0
  529. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +2 -2
  530. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  531. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +27 -290
  532. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  533. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +14 -8
  534. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  535. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +118 -88
  536. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  537. package/lib/feature-libraries/modular-schema/{modularChangeFormat.d.ts → modularChangeFormatV1.d.ts} +5 -6
  538. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -0
  539. package/lib/feature-libraries/modular-schema/{modularChangeFormat.js → modularChangeFormatV1.js} +4 -4
  540. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -0
  541. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +112 -0
  542. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -0
  543. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.js +18 -0
  544. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -0
  545. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +13 -3
  546. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  547. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  548. package/lib/feature-libraries/node-identifier/mockNodeIdentifierManager.js +1 -1
  549. package/lib/feature-libraries/node-identifier/mockNodeIdentifierManager.js.map +1 -1
  550. package/lib/feature-libraries/object-forest/objectForest.js +4 -4
  551. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  552. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  553. package/lib/feature-libraries/optional-field/optionalField.js +35 -40
  554. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  555. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  556. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +15 -3
  557. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  558. package/lib/feature-libraries/schema-index/codec.d.ts +7 -21
  559. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  560. package/lib/feature-libraries/schema-index/codec.js +30 -68
  561. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  562. package/lib/feature-libraries/schema-index/index.d.ts +2 -2
  563. package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
  564. package/lib/feature-libraries/schema-index/index.js +2 -2
  565. package/lib/feature-libraries/schema-index/index.js.map +1 -1
  566. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts +1 -9
  567. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  568. package/lib/feature-libraries/schema-index/schemaSummarizer.js +0 -10
  569. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  570. package/lib/feature-libraries/schemaChecker.d.ts.map +1 -1
  571. package/lib/feature-libraries/schemaChecker.js +11 -6
  572. package/lib/feature-libraries/schemaChecker.js.map +1 -1
  573. package/lib/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  574. package/lib/feature-libraries/sequence-field/compose.js +17 -13
  575. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  576. package/lib/feature-libraries/sequence-field/invert.js +5 -4
  577. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  578. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  579. package/lib/feature-libraries/sequence-field/moveEffectTable.js +15 -9
  580. package/lib/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  581. package/lib/feature-libraries/sequence-field/rebase.js +26 -18
  582. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  583. package/lib/feature-libraries/sequence-field/replaceRevisions.d.ts +2 -2
  584. package/lib/feature-libraries/sequence-field/replaceRevisions.d.ts.map +1 -1
  585. package/lib/feature-libraries/sequence-field/replaceRevisions.js +41 -36
  586. package/lib/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  587. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  588. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +16 -8
  589. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  590. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  591. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js +4 -2
  592. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  593. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  594. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +6 -3
  595. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  596. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  597. package/lib/feature-libraries/sequence-field/utils.js +46 -27
  598. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  599. package/lib/feature-libraries/treeCursorUtils.js +7 -7
  600. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  601. package/lib/feature-libraries/treeTextCursor.js +2 -2
  602. package/lib/feature-libraries/treeTextCursor.js.map +1 -1
  603. package/lib/feature-libraries/valueUtilities.d.ts.map +1 -1
  604. package/lib/feature-libraries/valueUtilities.js +16 -8
  605. package/lib/feature-libraries/valueUtilities.js.map +1 -1
  606. package/lib/index.d.ts +2 -2
  607. package/lib/index.d.ts.map +1 -1
  608. package/lib/index.js.map +1 -1
  609. package/lib/packageVersion.d.ts +1 -1
  610. package/lib/packageVersion.js +1 -1
  611. package/lib/packageVersion.js.map +1 -1
  612. package/lib/shared-tree/schematizingTreeView.d.ts +2 -3
  613. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  614. package/lib/shared-tree/schematizingTreeView.js +20 -9
  615. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  616. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  617. package/lib/shared-tree/sharedTree.js +30 -13
  618. package/lib/shared-tree/sharedTree.js.map +1 -1
  619. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +1 -1
  620. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  621. package/lib/shared-tree/sharedTreeChangeCodecs.js +9 -8
  622. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  623. package/lib/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  624. package/lib/shared-tree/sharedTreeChangeEnricher.js +4 -2
  625. package/lib/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  626. package/lib/shared-tree/sharedTreeChangeFamily.d.ts +3 -2
  627. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  628. package/lib/shared-tree/sharedTreeChangeFamily.js +19 -14
  629. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  630. package/lib/shared-tree/sharedTreeEditBuilder.d.ts.map +1 -1
  631. package/lib/shared-tree/sharedTreeEditBuilder.js +1 -1
  632. package/lib/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  633. package/lib/shared-tree/treeAlpha.d.ts +35 -29
  634. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  635. package/lib/shared-tree/treeAlpha.js +21 -23
  636. package/lib/shared-tree/treeAlpha.js.map +1 -1
  637. package/lib/shared-tree/treeCheckout.d.ts +2 -0
  638. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  639. package/lib/shared-tree/treeCheckout.js +32 -19
  640. package/lib/shared-tree/treeCheckout.js.map +1 -1
  641. package/lib/shared-tree-core/branch.d.ts +3 -1
  642. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  643. package/lib/shared-tree-core/branch.js +5 -3
  644. package/lib/shared-tree-core/branch.js.map +1 -1
  645. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  646. package/lib/shared-tree-core/branchCommitEnricher.js +2 -2
  647. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  648. package/lib/shared-tree-core/editManager.js +1 -1
  649. package/lib/shared-tree-core/editManager.js.map +1 -1
  650. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  651. package/lib/shared-tree-core/editManagerCodecs.js +9 -4
  652. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  653. package/lib/shared-tree-core/editManagerFormatCommons.d.ts +1 -0
  654. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  655. package/lib/shared-tree-core/editManagerFormatCommons.js +6 -0
  656. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  657. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +2 -2
  658. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  659. package/lib/shared-tree-core/editManagerFormatV1toV4.js +1 -0
  660. package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  661. package/lib/shared-tree-core/editManagerSummarizer.js +3 -3
  662. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  663. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +1 -1
  664. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  665. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  666. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  667. package/lib/shared-tree-core/messageCodecVSharedBranches.js +2 -1
  668. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  669. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  670. package/lib/shared-tree-core/messageCodecs.js +8 -4
  671. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  672. package/lib/shared-tree-core/messageFormat.d.ts +1 -0
  673. package/lib/shared-tree-core/messageFormat.d.ts.map +1 -1
  674. package/lib/shared-tree-core/messageFormat.js +6 -0
  675. package/lib/shared-tree-core/messageFormat.js.map +1 -1
  676. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts +3 -2
  677. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  678. package/lib/shared-tree-core/messageFormatV1ToV4.js +8 -1
  679. package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  680. package/lib/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  681. package/lib/shared-tree-core/sequenceIdUtils.js +4 -4
  682. package/lib/shared-tree-core/sequenceIdUtils.js.map +1 -1
  683. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  684. package/lib/shared-tree-core/sharedTreeCore.js +12 -8
  685. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  686. package/lib/shared-tree-core/transaction.d.ts +25 -8
  687. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  688. package/lib/shared-tree-core/transaction.js +67 -32
  689. package/lib/shared-tree-core/transaction.js.map +1 -1
  690. package/lib/shared-tree-core/transactionEnricher.d.ts +2 -2
  691. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  692. package/lib/shared-tree-core/transactionEnricher.js +3 -3
  693. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  694. package/lib/simple-tree/api/configuration.js +1 -1
  695. package/lib/simple-tree/api/configuration.js.map +1 -1
  696. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  697. package/lib/simple-tree/api/customTree.js +13 -9
  698. package/lib/simple-tree/api/customTree.js.map +1 -1
  699. package/lib/simple-tree/api/discrepancies.d.ts.map +1 -1
  700. package/lib/simple-tree/api/discrepancies.js +21 -17
  701. package/lib/simple-tree/api/discrepancies.js.map +1 -1
  702. package/lib/simple-tree/api/index.d.ts +1 -1
  703. package/lib/simple-tree/api/index.d.ts.map +1 -1
  704. package/lib/simple-tree/api/index.js.map +1 -1
  705. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  706. package/lib/simple-tree/api/schemaFactory.js +12 -8
  707. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  708. package/lib/simple-tree/api/schemaFromSimple.js +18 -9
  709. package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
  710. package/lib/simple-tree/api/simpleSchemaCodec.js +10 -5
  711. package/lib/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  712. package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  713. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +15 -11
  714. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  715. package/lib/simple-tree/api/simpleTreeIndex.js +10 -10
  716. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  717. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  718. package/lib/simple-tree/api/storedSchema.js +4 -7
  719. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  720. package/lib/simple-tree/api/transactionTypes.d.ts +17 -4
  721. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  722. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  723. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  724. package/lib/simple-tree/api/treeNodeApi.js +21 -13
  725. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  726. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  727. package/lib/simple-tree/api/verboseTree.js +14 -9
  728. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  729. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  730. package/lib/simple-tree/core/treeNodeKernel.js +6 -3
  731. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  732. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  733. package/lib/simple-tree/core/unhydratedFlexTree.js +20 -15
  734. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  735. package/lib/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  736. package/lib/simple-tree/getTreeNodeForField.js +2 -1
  737. package/lib/simple-tree/getTreeNodeForField.js.map +1 -1
  738. package/lib/simple-tree/index.d.ts +1 -1
  739. package/lib/simple-tree/index.d.ts.map +1 -1
  740. package/lib/simple-tree/index.js.map +1 -1
  741. package/lib/simple-tree/leafNodeSchema.js +9 -6
  742. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  743. package/lib/simple-tree/node-kinds/array/arrayNode.js +15 -15
  744. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  745. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  746. package/lib/simple-tree/node-kinds/object/objectNode.js +4 -5
  747. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  748. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  749. package/lib/simple-tree/node-kinds/record/recordNode.js +2 -3
  750. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  751. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  752. package/lib/simple-tree/toStoredSchema.js +9 -5
  753. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  754. package/lib/treeFactory.js +7 -3
  755. package/lib/treeFactory.js.map +1 -1
  756. package/lib/util/bTreeUtils.js +1 -1
  757. package/lib/util/bTreeUtils.js.map +1 -1
  758. package/lib/util/breakable.js +7 -9
  759. package/lib/util/breakable.js.map +1 -1
  760. package/lib/util/idAllocator.d.ts.map +1 -1
  761. package/lib/util/idAllocator.js +1 -2
  762. package/lib/util/idAllocator.js.map +1 -1
  763. package/lib/util/nestedMap.d.ts.map +1 -1
  764. package/lib/util/nestedMap.js +1 -1
  765. package/lib/util/nestedMap.js.map +1 -1
  766. package/lib/util/utils.d.ts.map +1 -1
  767. package/lib/util/utils.js +16 -15
  768. package/lib/util/utils.js.map +1 -1
  769. package/package.json +32 -32
  770. package/src/codec/codec.ts +48 -8
  771. package/src/codec/index.ts +4 -1
  772. package/src/codec/versioned/codec.ts +340 -22
  773. package/src/codec/versioned/index.ts +3 -1
  774. package/src/core/index.ts +2 -2
  775. package/src/core/rebase/changeRebaser.ts +40 -6
  776. package/src/core/rebase/index.ts +1 -1
  777. package/src/core/rebase/types.ts +6 -18
  778. package/src/core/rebase/utils.ts +3 -3
  779. package/src/core/schema-stored/schema.ts +3 -3
  780. package/src/core/tree/anchorSet.ts +3 -4
  781. package/src/core/tree/detachedFieldIndex.ts +13 -74
  782. package/src/core/tree/detachedFieldIndexCodecCommon.ts +4 -8
  783. package/src/core/tree/detachedFieldIndexCodecV1.ts +3 -7
  784. package/src/core/tree/detachedFieldIndexCodecV2.ts +5 -9
  785. package/src/core/tree/detachedFieldIndexCodecs.ts +21 -64
  786. package/src/core/tree/index.ts +1 -1
  787. package/src/core/tree/mapTree.ts +1 -1
  788. package/src/core/tree/sparseTree.ts +1 -0
  789. package/src/core/tree/treeTextFormat.ts +5 -9
  790. package/src/feature-libraries/changeAtomIdBTree.ts +24 -0
  791. package/src/feature-libraries/chunked-forest/basicChunk.ts +1 -1
  792. package/src/feature-libraries/chunked-forest/chunkedForest.ts +5 -5
  793. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +7 -4
  794. package/src/feature-libraries/chunked-forest/codec/codecs.ts +19 -11
  795. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +3 -3
  796. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +9 -5
  797. package/src/feature-libraries/chunked-forest/uniformChunk.ts +1 -1
  798. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +48 -17
  799. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +12 -2
  800. package/src/feature-libraries/default-schema/mappedEditBuilder.ts +6 -0
  801. package/src/feature-libraries/flex-tree/lazyField.ts +13 -14
  802. package/src/feature-libraries/index.ts +10 -5
  803. package/src/feature-libraries/indexing/anchorTreeIndex.ts +5 -5
  804. package/src/feature-libraries/mitigatedChangeFamily.ts +11 -6
  805. package/src/feature-libraries/modular-schema/comparison.ts +12 -9
  806. package/src/feature-libraries/modular-schema/defaultRevisionReplacer.ts +70 -0
  807. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +3 -6
  808. package/src/feature-libraries/modular-schema/genericFieldKind.ts +5 -7
  809. package/src/feature-libraries/modular-schema/genericFieldKindCodecs.ts +1 -1
  810. package/src/feature-libraries/modular-schema/index.ts +5 -2
  811. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +703 -0
  812. package/src/feature-libraries/modular-schema/modularChangeCodecV2.ts +89 -0
  813. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +39 -523
  814. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +159 -125
  815. package/src/feature-libraries/modular-schema/{modularChangeFormat.ts → modularChangeFormatV1.ts} +4 -4
  816. package/src/feature-libraries/modular-schema/modularChangeFormatV2.ts +34 -0
  817. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +13 -4
  818. package/src/feature-libraries/node-identifier/mockNodeIdentifierManager.ts +1 -1
  819. package/src/feature-libraries/object-forest/objectForest.ts +4 -4
  820. package/src/feature-libraries/optional-field/optionalField.ts +34 -46
  821. package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +18 -3
  822. package/src/feature-libraries/schema-index/codec.ts +30 -90
  823. package/src/feature-libraries/schema-index/index.ts +2 -4
  824. package/src/feature-libraries/schema-index/schemaSummarizer.ts +0 -17
  825. package/src/feature-libraries/schemaChecker.ts +11 -6
  826. package/src/feature-libraries/sequence-field/compose.ts +17 -13
  827. package/src/feature-libraries/sequence-field/invert.ts +5 -4
  828. package/src/feature-libraries/sequence-field/moveEffectTable.ts +15 -9
  829. package/src/feature-libraries/sequence-field/rebase.ts +26 -18
  830. package/src/feature-libraries/sequence-field/replaceRevisions.ts +52 -56
  831. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +16 -8
  832. package/src/feature-libraries/sequence-field/sequenceFieldCodecV3.ts +4 -2
  833. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +6 -3
  834. package/src/feature-libraries/sequence-field/utils.ts +46 -27
  835. package/src/feature-libraries/treeCursorUtils.ts +7 -7
  836. package/src/feature-libraries/treeTextCursor.ts +2 -2
  837. package/src/feature-libraries/valueUtilities.ts +16 -8
  838. package/src/index.ts +4 -0
  839. package/src/packageVersion.ts +1 -1
  840. package/src/shared-tree/schematizingTreeView.ts +23 -13
  841. package/src/shared-tree/sharedTree.ts +30 -14
  842. package/src/shared-tree/sharedTreeChangeCodecs.ts +10 -9
  843. package/src/shared-tree/sharedTreeChangeEnricher.ts +4 -2
  844. package/src/shared-tree/sharedTreeChangeFamily.ts +29 -19
  845. package/src/shared-tree/sharedTreeEditBuilder.ts +9 -5
  846. package/src/shared-tree/treeAlpha.ts +60 -51
  847. package/src/shared-tree/treeCheckout.ts +66 -50
  848. package/src/shared-tree-core/branch.ts +8 -3
  849. package/src/shared-tree-core/branchCommitEnricher.ts +3 -8
  850. package/src/shared-tree-core/editManager.ts +1 -1
  851. package/src/shared-tree-core/editManagerCodecs.ts +9 -4
  852. package/src/shared-tree-core/editManagerFormatCommons.ts +6 -0
  853. package/src/shared-tree-core/editManagerFormatV1toV4.ts +3 -1
  854. package/src/shared-tree-core/editManagerSummarizer.ts +3 -3
  855. package/src/shared-tree-core/messageCodecV1ToV4.ts +2 -1
  856. package/src/shared-tree-core/messageCodecVSharedBranches.ts +2 -1
  857. package/src/shared-tree-core/messageCodecs.ts +8 -4
  858. package/src/shared-tree-core/messageFormat.ts +6 -1
  859. package/src/shared-tree-core/messageFormatV1ToV4.ts +16 -2
  860. package/src/shared-tree-core/sequenceIdUtils.ts +4 -4
  861. package/src/shared-tree-core/sharedTreeCore.ts +11 -7
  862. package/src/shared-tree-core/transaction.ts +115 -56
  863. package/src/shared-tree-core/transactionEnricher.ts +5 -6
  864. package/src/simple-tree/api/configuration.ts +1 -1
  865. package/src/simple-tree/api/customTree.ts +14 -10
  866. package/src/simple-tree/api/discrepancies.ts +23 -17
  867. package/src/simple-tree/api/index.ts +2 -0
  868. package/src/simple-tree/api/schemaFactory.ts +11 -7
  869. package/src/simple-tree/api/schemaFromSimple.ts +18 -9
  870. package/src/simple-tree/api/simpleSchemaCodec.ts +10 -5
  871. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +17 -13
  872. package/src/simple-tree/api/simpleTreeIndex.ts +8 -8
  873. package/src/simple-tree/api/storedSchema.ts +10 -7
  874. package/src/simple-tree/api/transactionTypes.ts +19 -4
  875. package/src/simple-tree/api/treeNodeApi.ts +21 -13
  876. package/src/simple-tree/api/verboseTree.ts +14 -9
  877. package/src/simple-tree/core/treeNodeKernel.ts +6 -3
  878. package/src/simple-tree/core/unhydratedFlexTree.ts +22 -17
  879. package/src/simple-tree/getTreeNodeForField.ts +2 -1
  880. package/src/simple-tree/index.ts +2 -0
  881. package/src/simple-tree/leafNodeSchema.ts +8 -5
  882. package/src/simple-tree/node-kinds/array/arrayNode.ts +23 -23
  883. package/src/simple-tree/node-kinds/object/objectNode.ts +4 -5
  884. package/src/simple-tree/node-kinds/record/recordNode.ts +2 -3
  885. package/src/simple-tree/toStoredSchema.ts +9 -5
  886. package/src/treeFactory.ts +10 -5
  887. package/src/util/bTreeUtils.ts +1 -1
  888. package/src/util/breakable.ts +9 -9
  889. package/src/util/idAllocator.ts +1 -2
  890. package/src/util/nestedMap.ts +1 -3
  891. package/src/util/utils.ts +14 -13
  892. package/dist/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +0 -1
  893. package/dist/feature-libraries/modular-schema/modularChangeFormat.js.map +0 -1
  894. package/lib/feature-libraries/modular-schema/modularChangeFormat.d.ts.map +0 -1
  895. package/lib/feature-libraries/modular-schema/modularChangeFormat.js.map +0 -1
@@ -22,9 +22,8 @@ export function applySchemaToParserOptions(schema, options) {
22
22
  };
23
23
  const context = getUnhydratedContext(schema);
24
24
  return {
25
- keyConverter: config.keys !== KeyEncodingOptions.usePropertyKeys
26
- ? undefined
27
- : {
25
+ keyConverter: config.keys === KeyEncodingOptions.usePropertyKeys
26
+ ? {
28
27
  encode: (type, key) => {
29
28
  // translate stored key into property key.
30
29
  const simpleNodeSchema = context.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);
@@ -55,7 +54,8 @@ export function applySchemaToParserOptions(schema, options) {
55
54
  }
56
55
  return brand(inputKey);
57
56
  },
58
- },
57
+ }
58
+ : undefined,
59
59
  };
60
60
  }
61
61
  /**
@@ -81,13 +81,16 @@ function verboseTreeAdapter(options) {
81
81
  },
82
82
  type: (node) => {
83
83
  switch (typeof node) {
84
- case "number":
84
+ case "number": {
85
85
  return brand(numberSchema.identifier);
86
- case "string":
86
+ }
87
+ case "string": {
87
88
  return brand(stringSchema.identifier);
88
- case "boolean":
89
+ }
90
+ case "boolean": {
89
91
  return brand(booleanSchema.identifier);
90
- default:
92
+ }
93
+ default: {
91
94
  if (node === null) {
92
95
  return brand(nullSchema.identifier);
93
96
  }
@@ -95,6 +98,7 @@ function verboseTreeAdapter(options) {
95
98
  return brand(handleSchema.identifier);
96
99
  }
97
100
  return brand(node.type);
101
+ }
98
102
  }
99
103
  },
100
104
  keysFromNode: (node) => {
@@ -116,8 +120,9 @@ function verboseTreeAdapter(options) {
116
120
  }
117
121
  return inputKeys.map((k) => converter.parse(node.type, k));
118
122
  }
119
- default:
123
+ default: {
120
124
  return [];
125
+ }
121
126
  }
122
127
  },
123
128
  getFieldFromNode: (node, key) => {
@@ -1 +1 @@
1
- {"version":3,"file":"verboseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,oBAAoB,EACpB,QAAQ,EACR,kBAAkB,EAClB,oBAAoB,GAKpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EACN,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,aAAa,EACb,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,YAAY,GACZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EACN,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,GAKhB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAkE3D;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACzC,MAA2B,EAC3B,OAA4B;IAE5B,MAAM,MAAM,GAAkC;QAC7C,IAAI,EAAE,kBAAkB,CAAC,eAAe;QACxC,GAAG,OAAO;KACV,CAAC;IAEF,MAAM,OAAO,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAE7C,OAAO;QACN,YAAY,EACX,MAAM,CAAC,IAAI,KAAK,kBAAkB,CA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,OAAO,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,EAAE,SAAS,CAAC,CAAC;AAC3E,CAAC;AAED,SAAS,sBAAsB,CAC9B,MAAmB,EACnB,OAAsC,EACtC,YAAuD,EACvD,MAA2C;IAE3C,MAAM,MAAM,GAAG,gBAAgB,CAC9B,MAAM,EACN,OAAO,EACP,YAAY,EACZ,MAAM,EACN,sBAAsB,CACtB,CAAC;IACF,MAAM,UAAU,GACf,YAAY,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;IACtF,IAAI,UAAU,YAAY,oBAAoB,EAAE,CAAC;QAChD,OAAO,MAAuB,CAAC;IAChC,CAAC;IAED,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,MAAM,EAAE,MAAqC;KAC7C,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACxC,IAAiB,EACjB,QAA4B;IAE5B,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAmB,CAAC;AACzD,CAAC","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 { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\taboveRootPlaceholder,\n\tEmptyKey,\n\tkeyAsDetachedField,\n\tLeafNodeStoredSchema,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype ITreeCursorSynchronous,\n\ttype TreeNodeStoredSchema,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport type { Context, TreeLeafValue, TreeNodeSchema } from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tstackTreeFieldCursor,\n\tstackTreeNodeCursor,\n\ttype CursorAdapter,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../node-kinds/index.js\";\nimport {\n\tcustomFromCursor,\n\tKeyEncodingOptions,\n\treplaceHandles,\n\tunknownTypeError,\n\ttype CustomTreeNode,\n\ttype HandleConverter,\n\ttype SchemalessParseOptions,\n\ttype TreeEncodingOptions,\n} from \"./customTree.js\";\nimport { getUnhydratedContext } from \"../createContext.js\";\n\n/**\n * Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} is a {@link VerboseTreeNode}.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type VerboseTree<THandle = IFluidHandle> =\n\t| VerboseTreeNode<THandle>\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle;\n\n/**\n * Verbose encoding of a {@link TreeNode}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} has an explicit `type` property, and `fields`.\n * This allowed VerboseTreeNode to be unambiguous regarding which type each node is without relying on symbols or hidden state.\n *\n * Any IFluidHandle values have been replaced by `THandle`. If the `THandle` is JSON compatible, then this type is JSON compatible as well.\n *\n * @privateRemarks\n * This type is only used for data which is copied into and out of the tree.\n * When being copied out, its fine to have the data be mutable since its a copy.\n *\n * When being copied in, we don't need to mutate, so we could use a readonly variant of this type.\n * however the copy in case (createFromVerbose) probably isn't harmed much by just reusing this type as is,\n * since if the caller has immutable data, TypeScript doesn't prevent assigning immutable data to a mutable type anyway.\n * Also relaxing the input methods to take readonly data would be a non-breaking change so it can be done later if desired.\n *\n * This format is simple-tree specialized alternative to {@link JsonableTree}.\n * This format allows for all simple-tree compatible trees to be represented.\n *\n * Unlike `JsonableTree`, leaf nodes are not boxed into node objects, and instead have their schema inferred from the value.\n * Additionally, sequence fields can only occur on a node that has a single sequence field (with the empty key)\n * replicating the behavior of simple-tree ArrayNodes.\n * @alpha\n */\nexport interface VerboseTreeNode<THandle = IFluidHandle> {\n\t/**\n\t * The meaning of this node.\n\t * Provides contexts/semantics for this node and its content.\n\t * @remarks\n\t * Typically used to associate a node with metadata (including a schema) and source code (types, behaviors, etc).\n\t * When used with this package's schema system, it will be the {@link TreeNodeSchemaCore.identifier}.\n\t */\n\ttype: string;\n\n\t/**\n\t * Content of this node.\n\t * For array nodes, an array of children.\n\t * For map and object nodes, an object which children under keys.\n\t * @remarks\n\t * For object nodes, the keys could be either the stored keys, or the property keys depending on usage.\n\t */\n\tfields:\n\t\t| VerboseTree<THandle>[]\n\t\t| {\n\t\t\t\t[key: string]: VerboseTree<THandle>;\n\t\t };\n}\n\n/**\n * Use info from `schema` to convert `options` to {@link SchemalessParseOptions}.\n */\nexport function applySchemaToParserOptions(\n\tschema: ImplicitFieldSchema,\n\toptions: TreeEncodingOptions,\n): SchemalessParseOptions {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t...options,\n\t};\n\n\tconst context = getUnhydratedContext(schema);\n\n\treturn {\n\t\tkeyConverter:\n\t\t\tconfig.keys !== KeyEncodingOptions.usePropertyKeys\n\t\t\t\t? undefined\n\t\t\t\t: {\n\t\t\t\t\t\tencode: (type, key: FieldKey): string => {\n\t\t\t\t\t\t\t// translate stored key into property key.\n\t\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);\n\t\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\t\tconst propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);\n\t\t\t\t\t\t\t\tif (propertyKey !== undefined) {\n\t\t\t\t\t\t\t\t\treturn propertyKey;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Looking up an out of schema key.\n\t\t\t\t\t\t\t\t// This must point to a non-existent field.\n\t\t\t\t\t\t\t\t// It's possible that the key, if we returned it unmodified, could point to some data\n\t\t\t\t\t\t\t\t// (for example if looking up a key which is a stored key already when using property keys).\n\t\t\t\t\t\t\t\t// Thus return an arbitrary key that was selected randomly, so should not exist on non-adversarial data:\n\t\t\t\t\t\t\t\tconst arbitrary = \"arbitrary unused key: fe71614a-bf3e-43b3-b7b0-4cef39538e90\";\n\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\t!simpleNodeSchema.storedKeyToPropertyKey.has(brand(arbitrary)),\n\t\t\t\t\t\t\t\t\t0xa13 /* arbitrarily selected unused key was actually used */,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\treturn arbitrary;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn key;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tparse: (type, inputKey): FieldKey => {\n\t\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? unknownTypeError(type);\n\t\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\t\tconst info = simpleNodeSchema.flexKeyMap.get(inputKey);\n\t\t\t\t\t\t\t\tif (info === undefined) {\n\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t`Failed to parse VerboseTree due to unexpected key ${JSON.stringify(inputKey)} on type ${JSON.stringify(type)}.`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn info.storedKey;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn brand(inputKey);\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t};\n}\n\n/**\n * Used to read a VerboseTree as a node cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.\n */\nexport function cursorFromVerbose(\n\tdata: VerboseTree,\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeNodeCursor(verboseTreeAdapter(options), data);\n}\n\n/**\n * Used to read a VerboseTree[] as a field cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.\n */\nexport function fieldCursorFromVerbose(\n\tdata: VerboseTree[],\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeFieldCursor(\n\t\tverboseTreeAdapter(options),\n\t\t{ type: aboveRootPlaceholder, fields: data },\n\t\tkeyAsDetachedField(EmptyKey),\n\t);\n}\n\nfunction verboseTreeAdapter(options: SchemalessParseOptions): CursorAdapter<VerboseTree> {\n\treturn {\n\t\tvalue: (node: VerboseTree) => {\n\t\t\treturn isTreeValue(node) ? node : undefined;\n\t\t},\n\t\ttype: (node: VerboseTree) => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"number\":\n\t\t\t\t\treturn brand(numberSchema.identifier);\n\t\t\t\tcase \"string\":\n\t\t\t\t\treturn brand(stringSchema.identifier);\n\t\t\t\tcase \"boolean\":\n\t\t\t\t\treturn brand(booleanSchema.identifier);\n\t\t\t\tdefault:\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn brand(nullSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn brand(handleSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\treturn brand(node.type);\n\t\t\t}\n\t\t},\n\t\tkeysFromNode: (node: VerboseTree): readonly FieldKey[] => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"object\": {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\t\t\treturn node.fields.length === 0 ? [] : [EmptyKey];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst inputKeys = Object.keys(node.fields);\n\t\t\t\t\tconst converter = options.keyConverter;\n\t\t\t\t\tif (converter === undefined) {\n\t\t\t\t\t\treturn inputKeys as FieldKey[];\n\t\t\t\t\t}\n\t\t\t\t\treturn inputKeys.map((k) => converter.parse(node.type, k));\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\treturn [];\n\t\t\t}\n\t\t},\n\t\tgetFieldFromNode: (node: VerboseTree, key: FieldKey): readonly VerboseTree[] => {\n\t\t\t// Object.prototype.hasOwnProperty can return true for strings (ex: with key \"0\"), so we have to filter them out.\n\t\t\t// Rather than just special casing strings, we can handle them with an early return for all primitives.\n\t\t\tif (typeof node !== \"object\") {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (node === null) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (isFluidHandle(node)) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\treturn key === EmptyKey ? node.fields : [];\n\t\t\t}\n\n\t\t\tconst convertedKey =\n\t\t\t\toptions.keyConverter === undefined ? key : options.keyConverter.encode(node.type, key);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(node.fields, convertedKey)) {\n\t\t\t\tconst field = node.fields[convertedKey];\n\t\t\t\treturn field === undefined ? [] : [field];\n\t\t\t}\n\n\t\t\treturn [];\n\t\t},\n\t};\n}\n\n/**\n * Used to read a node cursor as a VerboseTree.\n */\nexport function verboseFromCursor(\n\treader: ITreeCursor,\n\tcontext: Context,\n\toptions: TreeEncodingOptions,\n): VerboseTree {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t...options,\n\t};\n\n\tconst storedSchemaMap = context.flexContext.schema.nodeSchema;\n\tconst schemaMap = context.schema;\n\n\treturn verboseFromCursorInner(reader, config, storedSchemaMap, schemaMap);\n}\n\nfunction verboseFromCursorInner(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): VerboseTree {\n\tconst fields = customFromCursor(\n\t\treader,\n\t\toptions,\n\t\tstoredSchema,\n\t\tschema,\n\t\tverboseFromCursorInner,\n\t);\n\tconst nodeSchema =\n\t\tstoredSchema.get(reader.type) ?? fail(0xb3c /* missing schema for type in cursor */);\n\tif (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn fields as TreeLeafValue;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<VerboseTree>,\n\t};\n}\n\n/**\n * Clones tree, replacing any handles.\n * @remarks\n * A strongly types version of {@link replaceHandles}.\n * @alpha\n */\nexport function replaceVerboseTreeHandles<T>(\n\ttree: VerboseTree,\n\treplacer: HandleConverter<T>,\n): VerboseTree<T> {\n\treturn replaceHandles(tree, replacer) as VerboseTree<T>;\n}\n"]}
1
+ {"version":3,"file":"verboseTree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/verboseTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,MAAM,wCAAwC,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,oBAAoB,EACpB,QAAQ,EACR,kBAAkB,EAClB,oBAAoB,GAKpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAG5C,OAAO,EACN,WAAW,EACX,oBAAoB,EACpB,mBAAmB,GAEnB,MAAM,kCAAkC,CAAC;AAC1C,OAAO,EACN,aAAa,EACb,YAAY,EACZ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E,MAAqC;KAC7C,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CACxC,IAAiB,EACjB,QAA4B;IAE5B,OAAO,cAAc,CAAC,IAAI,EAAE,QAAQ,CAAmB,CAAC;AACzD,CAAC","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 { isFluidHandle } from \"@fluidframework/runtime-utils/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\taboveRootPlaceholder,\n\tEmptyKey,\n\tkeyAsDetachedField,\n\tLeafNodeStoredSchema,\n\ttype FieldKey,\n\ttype ITreeCursor,\n\ttype ITreeCursorSynchronous,\n\ttype TreeNodeStoredSchema,\n} from \"../../core/index.js\";\nimport { brand } from \"../../util/index.js\";\nimport type { ImplicitFieldSchema } from \"../fieldSchema.js\";\nimport type { Context, TreeLeafValue, TreeNodeSchema } from \"../core/index.js\";\nimport {\n\tisTreeValue,\n\tstackTreeFieldCursor,\n\tstackTreeNodeCursor,\n\ttype CursorAdapter,\n} from \"../../feature-libraries/index.js\";\nimport {\n\tbooleanSchema,\n\thandleSchema,\n\tnullSchema,\n\tnumberSchema,\n\tstringSchema,\n} from \"../leafNodeSchema.js\";\nimport { isObjectNodeSchema } from \"../node-kinds/index.js\";\nimport {\n\tcustomFromCursor,\n\tKeyEncodingOptions,\n\treplaceHandles,\n\tunknownTypeError,\n\ttype CustomTreeNode,\n\ttype HandleConverter,\n\ttype SchemalessParseOptions,\n\ttype TreeEncodingOptions,\n} from \"./customTree.js\";\nimport { getUnhydratedContext } from \"../createContext.js\";\n\n/**\n * Verbose encoding of a {@link TreeNode} or {@link TreeLeafValue}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} is a {@link VerboseTreeNode}.\n * Any IFluidHandle values have been replaced by `THandle`.\n * @privateRemarks\n * This can store all possible simple trees,\n * but it can not store all possible trees representable by our internal representations like FlexTree and JsonableTree.\n * @alpha\n */\nexport type VerboseTree<THandle = IFluidHandle> =\n\t| VerboseTreeNode<THandle>\n\t| Exclude<TreeLeafValue, IFluidHandle>\n\t| THandle;\n\n/**\n * Verbose encoding of a {@link TreeNode}.\n * @remarks\n * This is verbose meaning that every {@link TreeNode} has an explicit `type` property, and `fields`.\n * This allowed VerboseTreeNode to be unambiguous regarding which type each node is without relying on symbols or hidden state.\n *\n * Any IFluidHandle values have been replaced by `THandle`. If the `THandle` is JSON compatible, then this type is JSON compatible as well.\n *\n * @privateRemarks\n * This type is only used for data which is copied into and out of the tree.\n * When being copied out, its fine to have the data be mutable since its a copy.\n *\n * When being copied in, we don't need to mutate, so we could use a readonly variant of this type.\n * however the copy in case (createFromVerbose) probably isn't harmed much by just reusing this type as is,\n * since if the caller has immutable data, TypeScript doesn't prevent assigning immutable data to a mutable type anyway.\n * Also relaxing the input methods to take readonly data would be a non-breaking change so it can be done later if desired.\n *\n * This format is simple-tree specialized alternative to {@link JsonableTree}.\n * This format allows for all simple-tree compatible trees to be represented.\n *\n * Unlike `JsonableTree`, leaf nodes are not boxed into node objects, and instead have their schema inferred from the value.\n * Additionally, sequence fields can only occur on a node that has a single sequence field (with the empty key)\n * replicating the behavior of simple-tree ArrayNodes.\n * @alpha\n */\nexport interface VerboseTreeNode<THandle = IFluidHandle> {\n\t/**\n\t * The meaning of this node.\n\t * Provides contexts/semantics for this node and its content.\n\t * @remarks\n\t * Typically used to associate a node with metadata (including a schema) and source code (types, behaviors, etc).\n\t * When used with this package's schema system, it will be the {@link TreeNodeSchemaCore.identifier}.\n\t */\n\ttype: string;\n\n\t/**\n\t * Content of this node.\n\t * For array nodes, an array of children.\n\t * For map and object nodes, an object which children under keys.\n\t * @remarks\n\t * For object nodes, the keys could be either the stored keys, or the property keys depending on usage.\n\t */\n\tfields:\n\t\t| VerboseTree<THandle>[]\n\t\t| {\n\t\t\t\t[key: string]: VerboseTree<THandle>;\n\t\t };\n}\n\n/**\n * Use info from `schema` to convert `options` to {@link SchemalessParseOptions}.\n */\nexport function applySchemaToParserOptions(\n\tschema: ImplicitFieldSchema,\n\toptions: TreeEncodingOptions,\n): SchemalessParseOptions {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t...options,\n\t};\n\n\tconst context = getUnhydratedContext(schema);\n\n\treturn {\n\t\tkeyConverter:\n\t\t\tconfig.keys === KeyEncodingOptions.usePropertyKeys\n\t\t\t\t? {\n\t\t\t\t\t\tencode: (type, key: FieldKey): string => {\n\t\t\t\t\t\t\t// translate stored key into property key.\n\t\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? fail(0xb39 /* missing schema */);\n\t\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\t\tconst propertyKey = simpleNodeSchema.storedKeyToPropertyKey.get(key);\n\t\t\t\t\t\t\t\tif (propertyKey !== undefined) {\n\t\t\t\t\t\t\t\t\treturn propertyKey;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// Looking up an out of schema key.\n\t\t\t\t\t\t\t\t// This must point to a non-existent field.\n\t\t\t\t\t\t\t\t// It's possible that the key, if we returned it unmodified, could point to some data\n\t\t\t\t\t\t\t\t// (for example if looking up a key which is a stored key already when using property keys).\n\t\t\t\t\t\t\t\t// Thus return an arbitrary key that was selected randomly, so should not exist on non-adversarial data:\n\t\t\t\t\t\t\t\tconst arbitrary = \"arbitrary unused key: fe71614a-bf3e-43b3-b7b0-4cef39538e90\";\n\t\t\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\t\t\t!simpleNodeSchema.storedKeyToPropertyKey.has(brand(arbitrary)),\n\t\t\t\t\t\t\t\t\t0xa13 /* arbitrarily selected unused key was actually used */,\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\treturn arbitrary;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn key;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tparse: (type, inputKey): FieldKey => {\n\t\t\t\t\t\t\tconst simpleNodeSchema =\n\t\t\t\t\t\t\t\tcontext.schema.get(brand(type)) ?? unknownTypeError(type);\n\t\t\t\t\t\t\tif (isObjectNodeSchema(simpleNodeSchema)) {\n\t\t\t\t\t\t\t\tconst info = simpleNodeSchema.flexKeyMap.get(inputKey);\n\t\t\t\t\t\t\t\tif (info === undefined) {\n\t\t\t\t\t\t\t\t\tthrow new UsageError(\n\t\t\t\t\t\t\t\t\t\t`Failed to parse VerboseTree due to unexpected key ${JSON.stringify(inputKey)} on type ${JSON.stringify(type)}.`,\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\treturn info.storedKey;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn brand(inputKey);\n\t\t\t\t\t\t},\n\t\t\t\t\t}\n\t\t\t\t: undefined,\n\t};\n}\n\n/**\n * Used to read a VerboseTree as a node cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single node in nodes mode.\n */\nexport function cursorFromVerbose(\n\tdata: VerboseTree,\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeNodeCursor(verboseTreeAdapter(options), data);\n}\n\n/**\n * Used to read a VerboseTree[] as a field cursor.\n *\n * @returns an {@link ITreeCursorSynchronous} for a single field in fields mode.\n */\nexport function fieldCursorFromVerbose(\n\tdata: VerboseTree[],\n\toptions: SchemalessParseOptions,\n): ITreeCursorSynchronous {\n\treturn stackTreeFieldCursor(\n\t\tverboseTreeAdapter(options),\n\t\t{ type: aboveRootPlaceholder, fields: data },\n\t\tkeyAsDetachedField(EmptyKey),\n\t);\n}\n\nfunction verboseTreeAdapter(options: SchemalessParseOptions): CursorAdapter<VerboseTree> {\n\treturn {\n\t\tvalue: (node: VerboseTree) => {\n\t\t\treturn isTreeValue(node) ? node : undefined;\n\t\t},\n\t\ttype: (node: VerboseTree) => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"number\": {\n\t\t\t\t\treturn brand(numberSchema.identifier);\n\t\t\t\t}\n\t\t\t\tcase \"string\": {\n\t\t\t\t\treturn brand(stringSchema.identifier);\n\t\t\t\t}\n\t\t\t\tcase \"boolean\": {\n\t\t\t\t\treturn brand(booleanSchema.identifier);\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn brand(nullSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn brand(handleSchema.identifier);\n\t\t\t\t\t}\n\t\t\t\t\treturn brand(node.type);\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tkeysFromNode: (node: VerboseTree): readonly FieldKey[] => {\n\t\t\tswitch (typeof node) {\n\t\t\t\tcase \"object\": {\n\t\t\t\t\tif (node === null) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (isFluidHandle(node)) {\n\t\t\t\t\t\treturn [];\n\t\t\t\t\t}\n\t\t\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\t\t\treturn node.fields.length === 0 ? [] : [EmptyKey];\n\t\t\t\t\t}\n\n\t\t\t\t\tconst inputKeys = Object.keys(node.fields);\n\t\t\t\t\tconst converter = options.keyConverter;\n\t\t\t\t\tif (converter === undefined) {\n\t\t\t\t\t\treturn inputKeys as FieldKey[];\n\t\t\t\t\t}\n\t\t\t\t\treturn inputKeys.map((k) => converter.parse(node.type, k));\n\t\t\t\t}\n\t\t\t\tdefault: {\n\t\t\t\t\treturn [];\n\t\t\t\t}\n\t\t\t}\n\t\t},\n\t\tgetFieldFromNode: (node: VerboseTree, key: FieldKey): readonly VerboseTree[] => {\n\t\t\t// Object.prototype.hasOwnProperty can return true for strings (ex: with key \"0\"), so we have to filter them out.\n\t\t\t// Rather than just special casing strings, we can handle them with an early return for all primitives.\n\t\t\tif (typeof node !== \"object\") {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (node === null) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (isFluidHandle(node)) {\n\t\t\t\treturn [];\n\t\t\t}\n\n\t\t\tif (Array.isArray(node.fields)) {\n\t\t\t\treturn key === EmptyKey ? node.fields : [];\n\t\t\t}\n\n\t\t\tconst convertedKey =\n\t\t\t\toptions.keyConverter === undefined ? key : options.keyConverter.encode(node.type, key);\n\n\t\t\tif (Object.prototype.hasOwnProperty.call(node.fields, convertedKey)) {\n\t\t\t\tconst field = node.fields[convertedKey];\n\t\t\t\treturn field === undefined ? [] : [field];\n\t\t\t}\n\n\t\t\treturn [];\n\t\t},\n\t};\n}\n\n/**\n * Used to read a node cursor as a VerboseTree.\n */\nexport function verboseFromCursor(\n\treader: ITreeCursor,\n\tcontext: Context,\n\toptions: TreeEncodingOptions,\n): VerboseTree {\n\tconst config: Required<TreeEncodingOptions> = {\n\t\tkeys: KeyEncodingOptions.usePropertyKeys,\n\t\t...options,\n\t};\n\n\tconst storedSchemaMap = context.flexContext.schema.nodeSchema;\n\tconst schemaMap = context.schema;\n\n\treturn verboseFromCursorInner(reader, config, storedSchemaMap, schemaMap);\n}\n\nfunction verboseFromCursorInner(\n\treader: ITreeCursor,\n\toptions: Required<TreeEncodingOptions>,\n\tstoredSchema: ReadonlyMap<string, TreeNodeStoredSchema>,\n\tschema: ReadonlyMap<string, TreeNodeSchema>,\n): VerboseTree {\n\tconst fields = customFromCursor(\n\t\treader,\n\t\toptions,\n\t\tstoredSchema,\n\t\tschema,\n\t\tverboseFromCursorInner,\n\t);\n\tconst nodeSchema =\n\t\tstoredSchema.get(reader.type) ?? fail(0xb3c /* missing schema for type in cursor */);\n\tif (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn fields as TreeLeafValue;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<VerboseTree>,\n\t};\n}\n\n/**\n * Clones tree, replacing any handles.\n * @remarks\n * A strongly types version of {@link replaceHandles}.\n * @alpha\n */\nexport function replaceVerboseTreeHandles<T>(\n\ttree: VerboseTree,\n\treplacer: HandleConverter<T>,\n): VerboseTree<T> {\n\treturn replaceHandles(tree, replacer) as VerboseTree<T>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"treeNodeKernel.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAgB,UAAU,EAAO,MAAM,0CAA0C,CAAC;AAS9F,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,UAAU,EAEf,KAAK,SAAS,EACd,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAIN,UAAU,EAEV,KAAK,YAAY,EACjB,KAAK,oBAAoB,EACzB,MAAM,kCAAkC,CAAC;AAE1C,OAAO,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,KAAK,EAAoB,UAAU,EAAE,MAAM,YAAY,CAAC;AAC/D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAIjE,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,cAAc,CAIxD;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,UAAU,CAAC,SAAS,EAAE,OAAO,GAAG,SAAS,IAAI,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAAC,CAE3F;AAED;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,SAAS,GAAG,cAAc,CAG/E;AAuBD;;;;GAIG;AACH,qBAAa,cAAc;;aA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AC;AAStE;;;;;;;;;GASG;AACH,wBAAgB,sBAAsB,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI,CAajE;AAoMD;;;GAGG;AACH,MAAM,MAAM,SAAS,GAAG,YAAY,CAAC;AAErC;;GAEG;AACH,wBAAgB,kBAAkB,CACjC,SAAS,EAAE,SAAS,GAClB,OAAO,CAAC,SAAS,IAAI,sBAAsB,GAAG,oBAAoB,CAKpE;AAED;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,oDAAyB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAO/D;AAED;;GAEG;AACH,wBAAgB,gCAAgC,CAAC,SAAS,EAAE,SAAS,GAAG,cAAc,CAGrF;AAED;;GAEG;AACH,wBAAgB,6BAA6B,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAU3E;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAG1D;AAmBD;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,QAAQ,GAAG,SAAS,CAQ/E;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CAAC,SAAS,EAAE,SAAS,GAAG,QAAQ,GAAG,SAAS,CAQlF;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,2DAAgC,CAAC"}
@@ -370,13 +370,16 @@ class KernelEventBuffer {
370
370
  _KernelEventBuffer_disposed = new WeakMap(), _KernelEventBuffer_disposeOnFlushListener = new WeakMap(), _KernelEventBuffer_events = new WeakMap(), _KernelEventBuffer_eventSource = new WeakMap(), _KernelEventBuffer_disposeSourceListeners = new WeakMap(), _KernelEventBuffer_childrenChangedBuffer = new WeakMap(), _KernelEventBuffer_subTreeChangedBuffer = new WeakMap(), _KernelEventBuffer_instances = new WeakSet(), _KernelEventBuffer_emit = function _KernelEventBuffer_emit(eventName, arg) {
371
371
  __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_assertNotDisposed).call(this);
372
372
  switch (eventName) {
373
- case "childrenChangedAfterBatch":
373
+ case "childrenChangedAfterBatch": {
374
374
  assert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);
375
375
  return __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_handleChildrenChangedAfterBatch).call(this, arg.changedFields);
376
- case "subtreeChangedAfterBatch":
376
+ }
377
+ case "subtreeChangedAfterBatch": {
377
378
  return __classPrivateFieldGet(this, _KernelEventBuffer_instances, "m", _KernelEventBuffer_handleSubtreeChangedAfterBatch).call(this);
378
- default:
379
+ }
380
+ default: {
379
381
  unreachableCase(eventName);
382
+ }
380
383
  }
381
384
  }, _KernelEventBuffer_handleChildrenChangedAfterBatch = function _KernelEventBuffer_handleChildrenChangedAfterBatch(changedFields) {
382
385
  if (bufferTreeEvents) {
@@ -1 +1 @@
1
- {"version":3,"file":"treeNodeKernel.js","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAEH,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EACN,MAAM,EACN,IAAI,EACJ,WAAW,EACX,eAAe,GACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,UAAU,GAKV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,+BAA+B,EAAE,MAAM,kCAAkC,CAAC;AACnF,OAAO,EACN,WAAW,EACX,YAAY,EACZ,UAAU,EACV,UAAU,EACV,yBAAyB,GAGzB,MAAM,kCAAkC,CAAC;AAM1C,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AAEjE,MAAM,gBAAgB,GAAG,IAAI,OAAO,EAA4B,CAAC;AAEjE,MAAM,UAAU,S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AAc,CAAC,aAAa,CAAC,CAAC;IACrE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC7D,MAAM,WAAW,GAAG,+BAA+B,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IACrE,MAAM,CAAC,IAAI,EAAE,CAAC;IACd,OAAO,WAAW,CAAC;AACpB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAsB;IACxD,MAAM,MAAM,GAAG,UAAU,CAAC,KAAK,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAAC;IACxD,IAAI,MAAM,KAAK,SAAS,EAAE,CAAC;QAC1B,OAAO,MAAM,CAAC;IACf,CAAC;IAED,MAAM,QAAQ,GAAG,kBAAkB,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,uBAAuB,CAAC,QAAQ,CAAC,CAAC;AAC1C,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAoB;IAC3D,MAAM,WAAW,GAAG,gCAAgC,CAAC,SAAS,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,SAAwC,CAAC;IAC1D,OAAO,OAAO,WAAW,KAAK,UAAU;QACvC,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAE,WAAwE,CAAC,MAAM,CAChF,QAAQ,CACR,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,EAAmB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable, Off } from \"@fluidframework/core-interfaces/internal\";\nimport {\n\tassert,\n\tfail,\n\tdebugAssert,\n\tunreachableCase,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tanchorSlot,\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\ttype FieldKey,\n\ttype TreeValue,\n} from \"../../core/index.js\";\nimport { getOrCreateHydratedFlexTreeNode } from \"../../feature-libraries/index.js\";\nimport {\n\tContextSlot,\n\tflexTreeSlot,\n\tLazyEntity,\n\tTreeStatus,\n\ttreeStatusFromAnchorCache,\n\ttype FlexTreeNode,\n\ttype HydratedFlexTreeNode,\n} from \"../../feature-libraries/index.js\";\n\nimport type { Context, HydratedContext } from \"./context.js\";\nimport type { TreeNode } from \"./treeNode.js\";\nimport type { TreeNodeSchema } from \"./treeNodeSchema.js\";\nimport type { InternalTreeNode, Unhydrated } from \"./types.js\";\nimport { UnhydratedFlexTreeNode } from \"./unhydratedFlexTree.js\";\n\nconst treeNodeToKernel = new WeakMap<TreeNode, TreeNodeKernel>();\n\nexport function getKernel(node: TreeNode): TreeNodeKernel {\n\tconst kernel = treeNodeToKernel.get(node);\n\tassert(kernel !== undefined, 0x9b1 /* Expected tree node to have kernel */);\n\treturn kernel;\n}\n\n/**\n * Detects if the given 'candidate' is a TreeNode.\n *\n * @remarks\n * Supports both Hydrated and {@link Unhydrated} TreeNodes, both of which return true.\n *\n * Because the common usage is to check if a value being inserted/set is a TreeNode,\n * this function permits calling with primitives as well as objects.\n *\n * Primitives will always return false (as they are copies of data, not references to nodes).\n *\n * @param candidate - Value which may be a TreeNode\n * @returns true if the given 'candidate' is a hydrated TreeNode.\n */\nexport function isTreeNode(candidate: unknown): candidate is TreeNode | Unhydrated<TreeNode> {\n\treturn treeNodeToKernel.has(candidate as TreeNode);\n}\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode}.\n *\n * Returns undefined for other values.\n * @remarks\n * Does not give schema for a {@link TreeLeafValue}.\n */\nexport function tryGetTreeNodeSchema(value: unknown): undefined | TreeNodeSchema {\n\tconst kernel = treeNodeToKernel.get(value as TreeNode);\n\treturn kernel?.schema;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} before the kernel is hydrated */\ninterface UnhydratedState {\n\treadonly innerNode: UnhydratedFlexTreeNode;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} after the kernel is hydrated */\ninterface HydratedState {\n\t/** The flex node for this kernel */\n\treadonly innerNode: HydratedFlexTreeNode;\n\t/** All {@link Off | event deregistration functions} that should be run when the kernel is disposed. */\n\treadonly offAnchorNode: Set<Off>;\n}\n\n/** State within a {@link TreeNodeKernel} that is related to the hydration process */\ntype HydrationState = UnhydratedState | HydratedState;\n\n/** True if and only if the given {@link HydrationState} is post-hydration */\nfunction isHydrated(state: HydrationState): state is HydratedState {\n\treturn state.innerNode.isHydrated();\n}\n\n/**\n * Contains state and an internal API for managing {@link TreeNode}s.\n * @remarks All {@link TreeNode}s have an associated kernel object.\n * The kernel has the same lifetime as the node and spans both its unhydrated and hydrated states.\n */\nexport class TreeNodeKernel {\n\tprivate disposed = false;\n\n\t/**\n\t * Generation number which is incremented any time we have an edit on the node.\n\t * Used during iteration to make sure there has been no edits that were concurrently made.\n\t * @remarks\n\t * This is updated monotonically by this class when edits are applied.\n\t * TODO: update this when applying edits to unhydrated trees.\n\t *\n\t * If TypeScript supported making this immutable from outside the class without making it readonly from inside, that would be used here,\n\t * but they only way to do that is add a separate public accessor and make it private, which was deemed not worth the boilerplate, runtime overhead and bundle size.\n\t */\n\tpublic generationNumber: number = 0;\n\n\t#hydrationState: HydrationState;\n\n\t/**\n\t * Events registered before hydration.\n\t * @remarks\n\t * Since these are usually not used, they are allocated lazily as an optimization.\n\t * The laziness also avoids extra forwarding overhead for events from this kernel's anchor node and also avoids registering for events that are unneeded.\n\t * This means optimizations like skipping processing data in subtrees where no subtreeChanged events are subscribed to would be able to work,\n\t * since the kernel does not unconditionally subscribe to those events (like a design which simply forwards all events would).\n\t */\n\treadonly #eventBuffer: KernelEventBuffer;\n\n\t/**\n\t * Create a TreeNodeKernel which can be looked up with {@link getKernel}.\n\t *\n\t * @param initialContext - context from when this node was originally created. Only used when unhydrated.\n\t * @param innerNode - When unhydrated the MapTreeNode. Otherwise HydratedFlexTreeNode.\n\t * @remarks\n\t * Exactly one kernel per TreeNode should be created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly node: TreeNode,\n\t\tpublic readonly schema: TreeNodeSchema,\n\t\tinnerNode: InnerNode,\n\t\tprivate readonly initialContext: Context,\n\t) {\n\t\tsplitInnerNodeType(innerNode);\n\n\t\tassert(!treeNodeToKernel.has(node), 0xa1a /* only one kernel per node can be made */);\n\t\ttreeNodeToKernel.set(node, this);\n\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t// Unhydrated case\n\n\t\t\tdebugAssert(() => innerNode.treeNode === undefined);\n\t\t\tinnerNode.treeNode = node;\n\n\t\t\tthis.#hydrationState = {\n\t\t\t\tinnerNode,\n\t\t\t};\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.events);\n\t\t} else {\n\t\t\t// Hydrated case\n\t\t\tthis.#hydrationState = this.createHydratedState(innerNode);\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.anchorNode.events);\n\t\t}\n\t}\n\n\tpublic get context(): Context {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\t// This can't be cached on this.#hydrated during hydration since initial tree is hydrated before the context is cached on the anchorSet.\n\t\t\treturn (\n\t\t\t\tthis.#hydrationState.innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot) ??\n\t\t\t\tfail(0xb40 /* missing simple-tree context */)\n\t\t\t);\n\t\t}\n\t\treturn this.initialContext;\n\t}\n\n\t/**\n\t * Transition from {@link Unhydrated} to hydrated.\n\t * Bi-directionally associates the given hydrated TreeNode to the HydratedFlexTreeNode.\n\t * @remarks\n\t * Happens at most once for any given node.\n\t * Cleans up mappings to {@link UnhydratedFlexTreeNode} - it is assumed that they are no longer needed once this node has an anchor node.\n\t */\n\tpublic hydrate(inner: HydratedFlexTreeNode): void {\n\t\tassert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);\n\t\tassert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);\n\n\t\tthis.#hydrationState = this.createHydratedState(inner);\n\n\t\t// Lazily migrate existing event listeners to the anchor node\n\t\tthis.#eventBuffer.migrateEventSource(inner.anchorNode.events);\n\t}\n\n\tprivate createHydratedState(innerNode: HydratedFlexTreeNode): HydratedState {\n\t\tassert(\n\t\t\t!innerNode.anchorNode.slots.has(simpleTreeNodeSlot),\n\t\t\t0x7f5 /* Cannot associate an flex node with multiple simple-tree nodes */,\n\t\t);\n\t\tinnerNode.anchorNode.slots.set(simpleTreeNodeSlot, this.node);\n\t\treturn {\n\t\t\tinnerNode,\n\t\t\toffAnchorNode: new Set([\n\t\t\t\tinnerNode.anchorNode.events.on(\"afterDestroy\", () => this.dispose()),\n\t\t\t\t// TODO: this should be triggered on change even for unhydrated nodes.\n\t\t\t\tinnerNode.anchorNode.events.on(\"childrenChanging\", () => {\n\t\t\t\t\tthis.generationNumber += 1;\n\t\t\t\t}),\n\t\t\t]),\n\t\t};\n\t}\n\n\tpublic getStatus(): TreeStatus {\n\t\tif (this.disposed) {\n\t\t\treturn TreeStatus.Deleted;\n\t\t}\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\treturn TreeStatus.New;\n\t\t}\n\n\t\t// TODO: Replace this check with the proper check against the cursor state when the cursor becomes part of the kernel\n\t\tconst flex = this.#hydrationState.innerNode.anchorNode.slots.get(flexTreeSlot);\n\t\tif (flex !== undefined) {\n\t\t\tassert(flex instanceof LazyEntity, 0x9b4 /* Unexpected flex node implementation */);\n\t\t\tif (flex.isFreed()) {\n\t\t\t\treturn TreeStatus.Deleted;\n\t\t\t}\n\t\t}\n\n\t\treturn treeStatusFromAnchorCache(this.#hydrationState.innerNode.anchorNode);\n\t}\n\n\tpublic get events(): Listenable<KernelEvents> {\n\t\treturn this.#eventBuffer;\n\t}\n\n\tpublic dispose(): void {\n\t\tdebugAssert(() => !this.disposed || \"Cannot dispose a disposed node\");\n\t\tthis.disposed = true;\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\tfor (const off of this.#hydrationState.offAnchorNode) {\n\t\t\t\toff();\n\t\t\t}\n\t\t}\n\t\tthis.#eventBuffer.dispose();\n\t\t// TODO: go to the context and remove myself from withAnchors\n\t}\n\n\tpublic isHydrated(): this is { anchorNode: AnchorNode; context: HydratedContext } {\n\t\treturn isHydrated(this.#hydrationState);\n\t}\n\n\tpublic get anchorNode(): AnchorNode | undefined {\n\t\treturn isHydrated(this.#hydrationState)\n\t\t\t? this.#hydrationState.innerNode.anchorNode\n\t\t\t: undefined;\n\t}\n\n\t/**\n\t * Retrieves the flex node associated with the given target.\n\t * @remarks\n\t * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n\t *\n\t * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n\t *\n\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n\t */\n\tpublic getInnerNode(): InnerNode {\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tthis.#hydrationState.innerNode?.context.isDisposed() === false ||\n\t\t\t\t\t\"Unhydrated node should never be disposed\",\n\t\t\t);\n\t\t\treturn this.#hydrationState.innerNode; // Unhydrated case\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Cannot access a deleted node.\");\n\t\t}\n\n\t\treturn this.#hydrationState.innerNode;\n\t}\n\n\t/**\n\t * Retrieves the {@link UnhydratedFlexTreeNode} if unhydrated. otherwise undefined.\n\t */\n\tpublic getInnerNodeIfUnhydrated(): UnhydratedFlexTreeNode | undefined {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.#hydrationState.innerNode;\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst kernelEvents = [\"childrenChangedAfterBatch\", \"subtreeChangedAfterBatch\"] as const;\n\ntype KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;\n\n// #region TreeNodeEventBuffer\n\n/**\n * Whether or not events from {@link TreeNodeKernel} should be buffered instead of emitted immediately.\n */\nlet bufferTreeEvents: boolean = false;\n\n/**\n * Call the provided callback with {@link TreeNode}s' events paused until after the callback's completion.\n *\n * Events that would otherwise have been emitted immediately are merged and buffered until after the\n * provided callback has been completed.\n *\n * @remarks\n * Note: this should be used with caution. User application behaviors are implicitly coupled to event timing.\n * Disrupting this timing can lead to unexpected behavior.\n */\nexport function withBufferedTreeEvents(callback: () => void): void {\n\tif (bufferTreeEvents) {\n\t\t// Already buffering - just run the callback\n\t\tcallback();\n\t} else {\n\t\tbufferTreeEvents = true;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tbufferTreeEvents = false;\n\t\t\tflushEventsEmitter.emit(\"flush\");\n\t\t}\n\t}\n}\n\n/**\n * Event emitter to notify subscribers when tree events buffered due to {@link withBufferedTreeEvents} should be flushed.\n */\nconst flushEventsEmitter = createEmitter<{\n\tflush: () => void;\n}>();\n\n/**\n * Event emitter for {@link TreeNodeKernel}, which optionally buffers events based on {@link bufferTreeEvents}.\n * @remarks Listens to {@link flushEventsEmitter} to know when to flush any buffered events.\n */\nclass KernelEventBuffer implements Listenable<KernelEvents> {\n\t#disposed: boolean = false;\n\n\t/**\n\t * Listen to {@link flushEventsEmitter} to know when to flush buffered events.\n\t */\n\treadonly #disposeOnFlushListener = flushEventsEmitter.on(\"flush\", () => {\n\t\tthis.flush();\n\t});\n\n\treadonly #events = createEmitter<KernelEvents>();\n\n\t#eventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>;\n\treadonly #disposeSourceListeners: Map<keyof KernelEvents, Off> = new Map();\n\n\t/**\n\t * Buffer of fields that have changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.childrenChangedAfterBatch} event will be emitted\n\t * containing the accumulated set of changed fields.\n\t */\n\treadonly #childrenChangedBuffer: Set<FieldKey> = new Set();\n\n\t/**\n\t * Whether or not the subtree has changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.subTreeChanged} event will be emitted if and only\n\t * if the subtree has changed.\n\t */\n\t#subTreeChangedBuffer: boolean = false;\n\n\tpublic constructor(\n\t\t/**\n\t\t * Source of the kernel events.\n\t\t * Subscriptions will be created on-demand when listeners are added to this.events,\n\t\t * and those subscriptions will be cleaned up when all corresponding listeners have been removed.\n\t\t */\n\t\teventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t) {\n\t\tthis.#eventSource = eventSource;\n\t}\n\n\t/**\n\t * Migrate this event buffer to a new event source.\n\t *\n\t * @remarks\n\t * Cleans up any existing event subscriptions from the old source.\n\t * Binds events to the new source for each event with active listeners.\n\t */\n\tpublic migrateEventSource(\n\t\tnewSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t): void {\n\t\t// Unsubscribe from the old source\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#eventSource = newSource;\n\n\t\tif (this.#events.hasListeners(\"childrenChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"childrenChangedAfterBatch\", ({ changedFields }) =>\n\t\t\t\tthis.#emit(\"childrenChangedAfterBatch\", { changedFields }),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"childrenChangedAfterBatch\", off);\n\t\t}\n\t\tif (this.#events.hasListeners(\"subtreeChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"subtreeChangedAfterBatch\", () =>\n\t\t\t\tthis.#emit(\"subtreeChangedAfterBatch\"),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"subtreeChangedAfterBatch\", off);\n\t\t}\n\t}\n\n\tpublic on(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): Off {\n\t\t// Lazily bind event listeners to the source.\n\t\t// If we do not have any existing listeners for this event, then we need to bind to the source.\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tassert(\n\t\t\t\t!this.#disposeSourceListeners.has(eventName),\n\t\t\t\t0xc4f /* Should not have a dispose function without listeners */,\n\t\t\t);\n\n\t\t\tconst off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));\n\t\t\tthis.#disposeSourceListeners.set(eventName, off);\n\t\t}\n\n\t\tthis.#events.on(eventName, listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tpublic off(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): void {\n\t\tthis.#events.off(eventName, listener);\n\n\t\t// If there are no remaining listeners for the event, unbind from the source\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tconst off = this.#disposeSourceListeners.get(eventName);\n\t\t\toff?.();\n\t\t\tthis.#disposeSourceListeners.delete(eventName);\n\t\t}\n\t}\n\n\t#emit(\n\t\teventName: keyof KernelEvents,\n\t\targ?: {\n\t\t\tchangedFields: ReadonlySet<FieldKey>;\n\t\t},\n\t): void {\n\t\tthis.#assertNotDisposed();\n\t\tswitch (eventName) {\n\t\t\tcase \"childrenChangedAfterBatch\":\n\t\t\t\tassert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);\n\t\t\t\treturn this.#handleChildrenChangedAfterBatch(arg.changedFields);\n\t\t\tcase \"subtreeChangedAfterBatch\":\n\t\t\t\treturn this.#handleSubtreeChangedAfterBatch();\n\t\t\tdefault:\n\t\t\t\tunreachableCase(eventName);\n\t\t}\n\t}\n\n\t#handleChildrenChangedAfterBatch(changedFields: ReadonlySet<FieldKey>): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tfor (const fieldKey of changedFields) {\n\t\t\t\tthis.#childrenChangedBuffer.add(fieldKey);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", { changedFields });\n\t\t}\n\t}\n\n\t#handleSubtreeChangedAfterBatch(): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tthis.#subTreeChangedBuffer = true;\n\t\t} else {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t}\n\t}\n\n\t/**\n\t * Flushes any events buffered due to {@link withBufferedTreeEvents}.\n\t */\n\tpublic flush(): void {\n\t\tthis.#assertNotDisposed();\n\n\t\tif (this.#childrenChangedBuffer.size > 0) {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", {\n\t\t\t\tchangedFields: this.#childrenChangedBuffer,\n\t\t\t});\n\t\t\tthis.#childrenChangedBuffer.clear();\n\t\t}\n\n\t\tif (this.#subTreeChangedBuffer) {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t\tthis.#subTreeChangedBuffer = false;\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tassert(!this.#disposed, 0xc51 /* Event handler disposed. */);\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,\n\t\t\t0xc52 /* Buffered kernel events should have been flushed before disposing. */,\n\t\t);\n\n\t\tthis.#disposeOnFlushListener();\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#childrenChangedBuffer.clear();\n\t\tthis.#subTreeChangedBuffer = false;\n\n\t\tthis.#disposed = true;\n\t}\n}\n\n// #endregion\n\n/**\n * For hydrated nodes this is a HydratedFlexTreeNode thats a projection of forest content.\n * For {@link Unhydrated} nodes this is a UnhydratedFlexTreeNode.\n */\nexport type InnerNode = FlexTreeNode;\n\n/**\n * Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.\n */\nexport function splitInnerNodeType(\n\tinnerNode: InnerNode,\n): asserts innerNode is UnhydratedFlexTreeNode | HydratedFlexTreeNode {\n\tassert(\n\t\tinnerNode instanceof UnhydratedFlexTreeNode || innerNode.isHydrated(),\n\t\t0xbc8 /* Invalid inner node type */,\n\t);\n}\n\n/**\n * An anchor slot which associates an anchor with its corresponding {@link TreeNode}, if there is one.\n * @remarks\n * For this to work, we have to require that there is at most a single view using a given AnchorSet.\n * FlexTree already has this assumption, and we also assume there is a single simple-tree per FlexTree, so this is valid.\n */\nexport const simpleTreeNodeSlot = anchorSlot<TreeNode>();\n\n/**\n * Dispose a TreeNode (if any) for an existing anchor without disposing the anchor.\n */\nexport function tryDisposeTreeNode(anchorNode: AnchorNode): void {\n\tconst treeNode = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (treeNode !== undefined) {\n\t\tconst kernel = getKernel(treeNode);\n\t\tkernel.dispose();\n\t\tanchorNode.slots.delete(simpleTreeNodeSlot);\n\t}\n}\n\n/**\n * Gets the {@link TreeNodeSchema} for the {@link InnerNode}.\n */\nexport function getSimpleNodeSchemaFromInnerNode(innerNode: InnerNode): TreeNodeSchema {\n\tconst context: Context = getSimpleContextFromInnerNode(innerNode);\n\treturn context.schema.get(innerNode.type) ?? fail(0xb3f /* missing schema from context */);\n}\n\n/**\n * Gets the {@link Context} for the {@link InnerNode}.\n */\nexport function getSimpleContextFromInnerNode(innerNode: InnerNode): Context {\n\tsplitInnerNodeType(innerNode);\n\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\treturn innerNode.simpleContext;\n\t}\n\n\tconst context = innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot);\n\tassert(context !== undefined, 0xa55 /* missing simple tree context */);\n\n\treturn context;\n}\n\n/**\n * Retrieves the flex node associated with the given target.\n * @remarks\n * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n *\n * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n *\n * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n */\nexport function getInnerNode(treeNode: TreeNode): InnerNode {\n\tconst kernel = getKernel(treeNode);\n\treturn kernel.getInnerNode();\n}\n\n/**\n * Gets a flex node from an anchor node\n */\nfunction flexNodeFromAnchor(anchorNode: AnchorNode): HydratedFlexTreeNode {\n\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\tif (flexNode !== undefined) {\n\t\treturn flexNode; // If it does have a flex node, return it...\n\t} // ...otherwise, the flex node must be created\n\tconst context =\n\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb45 /* missing context */);\n\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\tconst newFlexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\tcursor.free();\n\treturn newFlexNode;\n}\n\n/**\n * Gets a tree node from an anchor node\n */\nexport function treeNodeFromAnchor(anchorNode: AnchorNode): TreeNode | TreeValue {\n\tconst cached = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst flexNode = flexNodeFromAnchor(anchorNode);\n\treturn createTreeNodeFromInner(flexNode);\n}\n\n/**\n * Constructs a TreeNode from an InnerNode.\n * @remarks\n * This does not do caching or validation: caller must ensure duplicate nodes for a given inner node are not created, and that the inner node is valid.\n */\nexport function createTreeNodeFromInner(innerNode: InnerNode): TreeNode | TreeValue {\n\tconst classSchema = getSimpleNodeSchemaFromInnerNode(innerNode);\n\tconst internal = innerNode as unknown as InternalTreeNode;\n\treturn typeof classSchema === \"function\"\n\t\t? new classSchema(internal)\n\t\t: (classSchema as { create(data: InternalTreeNode): TreeNode | TreeValue }).create(\n\t\t\t\tinternal,\n\t\t\t);\n}\n\n/**\n * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n * @remarks\n * See also {@link ContextSlot} in which the flex-tree context is stored.\n */\nexport const SimpleContextSlot = anchorSlot<HydratedContext>();\n"]}
1
+ {"version":3,"file":"treeNodeKernel.js","sourceRoot":"","sources":["../../../src/simple-tree/core/treeNodeKernel.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;;;;;;;AAE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AoB;IAC3D,MAAM,WAAW,GAAG,gCAAgC,CAAC,SAAS,CAAC,CAAC;IAChE,MAAM,QAAQ,GAAG,SAAwC,CAAC;IAC1D,OAAO,OAAO,WAAW,KAAK,UAAU;QACvC,CAAC,CAAC,IAAI,WAAW,CAAC,QAAQ,CAAC;QAC3B,CAAC,CAAE,WAAwE,CAAC,MAAM,CAChF,QAAQ,CACR,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,EAAmB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable, Off } from \"@fluidframework/core-interfaces/internal\";\nimport {\n\tassert,\n\tfail,\n\tdebugAssert,\n\tunreachableCase,\n} from \"@fluidframework/core-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tanchorSlot,\n\ttype AnchorEvents,\n\ttype AnchorNode,\n\ttype FieldKey,\n\ttype TreeValue,\n} from \"../../core/index.js\";\nimport { getOrCreateHydratedFlexTreeNode } from \"../../feature-libraries/index.js\";\nimport {\n\tContextSlot,\n\tflexTreeSlot,\n\tLazyEntity,\n\tTreeStatus,\n\ttreeStatusFromAnchorCache,\n\ttype FlexTreeNode,\n\ttype HydratedFlexTreeNode,\n} from \"../../feature-libraries/index.js\";\n\nimport type { Context, HydratedContext } from \"./context.js\";\nimport type { TreeNode } from \"./treeNode.js\";\nimport type { TreeNodeSchema } from \"./treeNodeSchema.js\";\nimport type { InternalTreeNode, Unhydrated } from \"./types.js\";\nimport { UnhydratedFlexTreeNode } from \"./unhydratedFlexTree.js\";\n\nconst treeNodeToKernel = new WeakMap<TreeNode, TreeNodeKernel>();\n\nexport function getKernel(node: TreeNode): TreeNodeKernel {\n\tconst kernel = treeNodeToKernel.get(node);\n\tassert(kernel !== undefined, 0x9b1 /* Expected tree node to have kernel */);\n\treturn kernel;\n}\n\n/**\n * Detects if the given 'candidate' is a TreeNode.\n *\n * @remarks\n * Supports both Hydrated and {@link Unhydrated} TreeNodes, both of which return true.\n *\n * Because the common usage is to check if a value being inserted/set is a TreeNode,\n * this function permits calling with primitives as well as objects.\n *\n * Primitives will always return false (as they are copies of data, not references to nodes).\n *\n * @param candidate - Value which may be a TreeNode\n * @returns true if the given 'candidate' is a hydrated TreeNode.\n */\nexport function isTreeNode(candidate: unknown): candidate is TreeNode | Unhydrated<TreeNode> {\n\treturn treeNodeToKernel.has(candidate as TreeNode);\n}\n\n/**\n * Returns a schema for a value if the value is a {@link TreeNode}.\n *\n * Returns undefined for other values.\n * @remarks\n * Does not give schema for a {@link TreeLeafValue}.\n */\nexport function tryGetTreeNodeSchema(value: unknown): undefined | TreeNodeSchema {\n\tconst kernel = treeNodeToKernel.get(value as TreeNode);\n\treturn kernel?.schema;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} before the kernel is hydrated */\ninterface UnhydratedState {\n\treadonly innerNode: UnhydratedFlexTreeNode;\n}\n\n/** The {@link HydrationState} of a {@link TreeNodeKernel} after the kernel is hydrated */\ninterface HydratedState {\n\t/** The flex node for this kernel */\n\treadonly innerNode: HydratedFlexTreeNode;\n\t/** All {@link Off | event deregistration functions} that should be run when the kernel is disposed. */\n\treadonly offAnchorNode: Set<Off>;\n}\n\n/** State within a {@link TreeNodeKernel} that is related to the hydration process */\ntype HydrationState = UnhydratedState | HydratedState;\n\n/** True if and only if the given {@link HydrationState} is post-hydration */\nfunction isHydrated(state: HydrationState): state is HydratedState {\n\treturn state.innerNode.isHydrated();\n}\n\n/**\n * Contains state and an internal API for managing {@link TreeNode}s.\n * @remarks All {@link TreeNode}s have an associated kernel object.\n * The kernel has the same lifetime as the node and spans both its unhydrated and hydrated states.\n */\nexport class TreeNodeKernel {\n\tprivate disposed = false;\n\n\t/**\n\t * Generation number which is incremented any time we have an edit on the node.\n\t * Used during iteration to make sure there has been no edits that were concurrently made.\n\t * @remarks\n\t * This is updated monotonically by this class when edits are applied.\n\t * TODO: update this when applying edits to unhydrated trees.\n\t *\n\t * If TypeScript supported making this immutable from outside the class without making it readonly from inside, that would be used here,\n\t * but they only way to do that is add a separate public accessor and make it private, which was deemed not worth the boilerplate, runtime overhead and bundle size.\n\t */\n\tpublic generationNumber: number = 0;\n\n\t#hydrationState: HydrationState;\n\n\t/**\n\t * Events registered before hydration.\n\t * @remarks\n\t * Since these are usually not used, they are allocated lazily as an optimization.\n\t * The laziness also avoids extra forwarding overhead for events from this kernel's anchor node and also avoids registering for events that are unneeded.\n\t * This means optimizations like skipping processing data in subtrees where no subtreeChanged events are subscribed to would be able to work,\n\t * since the kernel does not unconditionally subscribe to those events (like a design which simply forwards all events would).\n\t */\n\treadonly #eventBuffer: KernelEventBuffer;\n\n\t/**\n\t * Create a TreeNodeKernel which can be looked up with {@link getKernel}.\n\t *\n\t * @param initialContext - context from when this node was originally created. Only used when unhydrated.\n\t * @param innerNode - When unhydrated the MapTreeNode. Otherwise HydratedFlexTreeNode.\n\t * @remarks\n\t * Exactly one kernel per TreeNode should be created.\n\t */\n\tpublic constructor(\n\t\tpublic readonly node: TreeNode,\n\t\tpublic readonly schema: TreeNodeSchema,\n\t\tinnerNode: InnerNode,\n\t\tprivate readonly initialContext: Context,\n\t) {\n\t\tsplitInnerNodeType(innerNode);\n\n\t\tassert(!treeNodeToKernel.has(node), 0xa1a /* only one kernel per node can be made */);\n\t\ttreeNodeToKernel.set(node, this);\n\n\t\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\t\t// Unhydrated case\n\n\t\t\tdebugAssert(() => innerNode.treeNode === undefined);\n\t\t\tinnerNode.treeNode = node;\n\n\t\t\tthis.#hydrationState = {\n\t\t\t\tinnerNode,\n\t\t\t};\n\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.events);\n\t\t} else {\n\t\t\t// Hydrated case\n\t\t\tthis.#hydrationState = this.createHydratedState(innerNode);\n\t\t\tthis.#eventBuffer = new KernelEventBuffer(innerNode.anchorNode.events);\n\t\t}\n\t}\n\n\tpublic get context(): Context {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\t// This can't be cached on this.#hydrated during hydration since initial tree is hydrated before the context is cached on the anchorSet.\n\t\t\treturn (\n\t\t\t\tthis.#hydrationState.innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot) ??\n\t\t\t\tfail(0xb40 /* missing simple-tree context */)\n\t\t\t);\n\t\t}\n\t\treturn this.initialContext;\n\t}\n\n\t/**\n\t * Transition from {@link Unhydrated} to hydrated.\n\t * Bi-directionally associates the given hydrated TreeNode to the HydratedFlexTreeNode.\n\t * @remarks\n\t * Happens at most once for any given node.\n\t * Cleans up mappings to {@link UnhydratedFlexTreeNode} - it is assumed that they are no longer needed once this node has an anchor node.\n\t */\n\tpublic hydrate(inner: HydratedFlexTreeNode): void {\n\t\tassert(!this.disposed, 0xa2a /* cannot hydrate a disposed node */);\n\t\tassert(!isHydrated(this.#hydrationState), 0xa2b /* hydration should only happen once */);\n\n\t\tthis.#hydrationState = this.createHydratedState(inner);\n\n\t\t// Lazily migrate existing event listeners to the anchor node\n\t\tthis.#eventBuffer.migrateEventSource(inner.anchorNode.events);\n\t}\n\n\tprivate createHydratedState(innerNode: HydratedFlexTreeNode): HydratedState {\n\t\tassert(\n\t\t\t!innerNode.anchorNode.slots.has(simpleTreeNodeSlot),\n\t\t\t0x7f5 /* Cannot associate an flex node with multiple simple-tree nodes */,\n\t\t);\n\t\tinnerNode.anchorNode.slots.set(simpleTreeNodeSlot, this.node);\n\t\treturn {\n\t\t\tinnerNode,\n\t\t\toffAnchorNode: new Set([\n\t\t\t\tinnerNode.anchorNode.events.on(\"afterDestroy\", () => this.dispose()),\n\t\t\t\t// TODO: this should be triggered on change even for unhydrated nodes.\n\t\t\t\tinnerNode.anchorNode.events.on(\"childrenChanging\", () => {\n\t\t\t\t\tthis.generationNumber += 1;\n\t\t\t\t}),\n\t\t\t]),\n\t\t};\n\t}\n\n\tpublic getStatus(): TreeStatus {\n\t\tif (this.disposed) {\n\t\t\treturn TreeStatus.Deleted;\n\t\t}\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\treturn TreeStatus.New;\n\t\t}\n\n\t\t// TODO: Replace this check with the proper check against the cursor state when the cursor becomes part of the kernel\n\t\tconst flex = this.#hydrationState.innerNode.anchorNode.slots.get(flexTreeSlot);\n\t\tif (flex !== undefined) {\n\t\t\tassert(flex instanceof LazyEntity, 0x9b4 /* Unexpected flex node implementation */);\n\t\t\tif (flex.isFreed()) {\n\t\t\t\treturn TreeStatus.Deleted;\n\t\t\t}\n\t\t}\n\n\t\treturn treeStatusFromAnchorCache(this.#hydrationState.innerNode.anchorNode);\n\t}\n\n\tpublic get events(): Listenable<KernelEvents> {\n\t\treturn this.#eventBuffer;\n\t}\n\n\tpublic dispose(): void {\n\t\tdebugAssert(() => !this.disposed || \"Cannot dispose a disposed node\");\n\t\tthis.disposed = true;\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\tfor (const off of this.#hydrationState.offAnchorNode) {\n\t\t\t\toff();\n\t\t\t}\n\t\t}\n\t\tthis.#eventBuffer.dispose();\n\t\t// TODO: go to the context and remove myself from withAnchors\n\t}\n\n\tpublic isHydrated(): this is { anchorNode: AnchorNode; context: HydratedContext } {\n\t\treturn isHydrated(this.#hydrationState);\n\t}\n\n\tpublic get anchorNode(): AnchorNode | undefined {\n\t\treturn isHydrated(this.#hydrationState)\n\t\t\t? this.#hydrationState.innerNode.anchorNode\n\t\t\t: undefined;\n\t}\n\n\t/**\n\t * Retrieves the flex node associated with the given target.\n\t * @remarks\n\t * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n\t *\n\t * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n\t *\n\t * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n\t */\n\tpublic getInnerNode(): InnerNode {\n\t\tif (!isHydrated(this.#hydrationState)) {\n\t\t\tdebugAssert(\n\t\t\t\t() =>\n\t\t\t\t\tthis.#hydrationState.innerNode?.context.isDisposed() === false ||\n\t\t\t\t\t\"Unhydrated node should never be disposed\",\n\t\t\t);\n\t\t\treturn this.#hydrationState.innerNode; // Unhydrated case\n\t\t}\n\n\t\tif (this.disposed) {\n\t\t\tthrow new UsageError(\"Cannot access a deleted node.\");\n\t\t}\n\n\t\treturn this.#hydrationState.innerNode;\n\t}\n\n\t/**\n\t * Retrieves the {@link UnhydratedFlexTreeNode} if unhydrated. otherwise undefined.\n\t */\n\tpublic getInnerNodeIfUnhydrated(): UnhydratedFlexTreeNode | undefined {\n\t\tif (isHydrated(this.#hydrationState)) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.#hydrationState.innerNode;\n\t}\n}\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nconst kernelEvents = [\"childrenChangedAfterBatch\", \"subtreeChangedAfterBatch\"] as const;\n\ntype KernelEvents = Pick<AnchorEvents, (typeof kernelEvents)[number]>;\n\n// #region TreeNodeEventBuffer\n\n/**\n * Whether or not events from {@link TreeNodeKernel} should be buffered instead of emitted immediately.\n */\nlet bufferTreeEvents: boolean = false;\n\n/**\n * Call the provided callback with {@link TreeNode}s' events paused until after the callback's completion.\n *\n * Events that would otherwise have been emitted immediately are merged and buffered until after the\n * provided callback has been completed.\n *\n * @remarks\n * Note: this should be used with caution. User application behaviors are implicitly coupled to event timing.\n * Disrupting this timing can lead to unexpected behavior.\n */\nexport function withBufferedTreeEvents(callback: () => void): void {\n\tif (bufferTreeEvents) {\n\t\t// Already buffering - just run the callback\n\t\tcallback();\n\t} else {\n\t\tbufferTreeEvents = true;\n\t\ttry {\n\t\t\tcallback();\n\t\t} finally {\n\t\t\tbufferTreeEvents = false;\n\t\t\tflushEventsEmitter.emit(\"flush\");\n\t\t}\n\t}\n}\n\n/**\n * Event emitter to notify subscribers when tree events buffered due to {@link withBufferedTreeEvents} should be flushed.\n */\nconst flushEventsEmitter = createEmitter<{\n\tflush: () => void;\n}>();\n\n/**\n * Event emitter for {@link TreeNodeKernel}, which optionally buffers events based on {@link bufferTreeEvents}.\n * @remarks Listens to {@link flushEventsEmitter} to know when to flush any buffered events.\n */\nclass KernelEventBuffer implements Listenable<KernelEvents> {\n\t#disposed: boolean = false;\n\n\t/**\n\t * Listen to {@link flushEventsEmitter} to know when to flush buffered events.\n\t */\n\treadonly #disposeOnFlushListener = flushEventsEmitter.on(\"flush\", () => {\n\t\tthis.flush();\n\t});\n\n\treadonly #events = createEmitter<KernelEvents>();\n\n\t#eventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>;\n\treadonly #disposeSourceListeners: Map<keyof KernelEvents, Off> = new Map();\n\n\t/**\n\t * Buffer of fields that have changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.childrenChangedAfterBatch} event will be emitted\n\t * containing the accumulated set of changed fields.\n\t */\n\treadonly #childrenChangedBuffer: Set<FieldKey> = new Set();\n\n\t/**\n\t * Whether or not the subtree has changed since events were paused.\n\t * When events are flushed, a single {@link AnchorEvents.subTreeChanged} event will be emitted if and only\n\t * if the subtree has changed.\n\t */\n\t#subTreeChangedBuffer: boolean = false;\n\n\tpublic constructor(\n\t\t/**\n\t\t * Source of the kernel events.\n\t\t * Subscriptions will be created on-demand when listeners are added to this.events,\n\t\t * and those subscriptions will be cleaned up when all corresponding listeners have been removed.\n\t\t */\n\t\teventSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t) {\n\t\tthis.#eventSource = eventSource;\n\t}\n\n\t/**\n\t * Migrate this event buffer to a new event source.\n\t *\n\t * @remarks\n\t * Cleans up any existing event subscriptions from the old source.\n\t * Binds events to the new source for each event with active listeners.\n\t */\n\tpublic migrateEventSource(\n\t\tnewSource: Listenable<KernelEvents> & HasListeners<KernelEvents>,\n\t): void {\n\t\t// Unsubscribe from the old source\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#eventSource = newSource;\n\n\t\tif (this.#events.hasListeners(\"childrenChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"childrenChangedAfterBatch\", ({ changedFields }) =>\n\t\t\t\tthis.#emit(\"childrenChangedAfterBatch\", { changedFields }),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"childrenChangedAfterBatch\", off);\n\t\t}\n\t\tif (this.#events.hasListeners(\"subtreeChangedAfterBatch\")) {\n\t\t\tconst off = this.#eventSource.on(\"subtreeChangedAfterBatch\", () =>\n\t\t\t\tthis.#emit(\"subtreeChangedAfterBatch\"),\n\t\t\t);\n\t\t\tthis.#disposeSourceListeners.set(\"subtreeChangedAfterBatch\", off);\n\t\t}\n\t}\n\n\tpublic on(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): Off {\n\t\t// Lazily bind event listeners to the source.\n\t\t// If we do not have any existing listeners for this event, then we need to bind to the source.\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tassert(\n\t\t\t\t!this.#disposeSourceListeners.has(eventName),\n\t\t\t\t0xc4f /* Should not have a dispose function without listeners */,\n\t\t\t);\n\n\t\t\tconst off = this.#eventSource.on(eventName, (args) => this.#emit(eventName, args));\n\t\t\tthis.#disposeSourceListeners.set(eventName, off);\n\t\t}\n\n\t\tthis.#events.on(eventName, listener);\n\t\treturn () => this.off(eventName, listener);\n\t}\n\n\tpublic off(eventName: keyof KernelEvents, listener: KernelEvents[typeof eventName]): void {\n\t\tthis.#events.off(eventName, listener);\n\n\t\t// If there are no remaining listeners for the event, unbind from the source\n\t\tif (!this.#events.hasListeners(eventName)) {\n\t\t\tconst off = this.#disposeSourceListeners.get(eventName);\n\t\t\toff?.();\n\t\t\tthis.#disposeSourceListeners.delete(eventName);\n\t\t}\n\t}\n\n\t#emit(\n\t\teventName: keyof KernelEvents,\n\t\targ?: {\n\t\t\tchangedFields: ReadonlySet<FieldKey>;\n\t\t},\n\t): void {\n\t\tthis.#assertNotDisposed();\n\t\tswitch (eventName) {\n\t\t\tcase \"childrenChangedAfterBatch\": {\n\t\t\t\tassert(arg !== undefined, 0xc50 /* childrenChangedAfterBatch should have arg */);\n\t\t\t\treturn this.#handleChildrenChangedAfterBatch(arg.changedFields);\n\t\t\t}\n\t\t\tcase \"subtreeChangedAfterBatch\": {\n\t\t\t\treturn this.#handleSubtreeChangedAfterBatch();\n\t\t\t}\n\t\t\tdefault: {\n\t\t\t\tunreachableCase(eventName);\n\t\t\t}\n\t\t}\n\t}\n\n\t#handleChildrenChangedAfterBatch(changedFields: ReadonlySet<FieldKey>): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tfor (const fieldKey of changedFields) {\n\t\t\t\tthis.#childrenChangedBuffer.add(fieldKey);\n\t\t\t}\n\t\t} else {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", { changedFields });\n\t\t}\n\t}\n\n\t#handleSubtreeChangedAfterBatch(): void {\n\t\tif (bufferTreeEvents) {\n\t\t\tthis.#subTreeChangedBuffer = true;\n\t\t} else {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t}\n\t}\n\n\t/**\n\t * Flushes any events buffered due to {@link withBufferedTreeEvents}.\n\t */\n\tpublic flush(): void {\n\t\tthis.#assertNotDisposed();\n\n\t\tif (this.#childrenChangedBuffer.size > 0) {\n\t\t\tthis.#events.emit(\"childrenChangedAfterBatch\", {\n\t\t\t\tchangedFields: this.#childrenChangedBuffer,\n\t\t\t});\n\t\t\tthis.#childrenChangedBuffer.clear();\n\t\t}\n\n\t\tif (this.#subTreeChangedBuffer) {\n\t\t\tthis.#events.emit(\"subtreeChangedAfterBatch\");\n\t\t\tthis.#subTreeChangedBuffer = false;\n\t\t}\n\t}\n\n\t#assertNotDisposed(): void {\n\t\tassert(!this.#disposed, 0xc51 /* Event handler disposed. */);\n\t}\n\n\tpublic dispose(): void {\n\t\tif (this.#disposed) {\n\t\t\treturn;\n\t\t}\n\n\t\tassert(\n\t\t\tthis.#childrenChangedBuffer.size === 0 && !this.#subTreeChangedBuffer,\n\t\t\t0xc52 /* Buffered kernel events should have been flushed before disposing. */,\n\t\t);\n\n\t\tthis.#disposeOnFlushListener();\n\t\tthis.#disposeSourceListeners.forEach((off) => off());\n\t\tthis.#disposeSourceListeners.clear();\n\n\t\tthis.#childrenChangedBuffer.clear();\n\t\tthis.#subTreeChangedBuffer = false;\n\n\t\tthis.#disposed = true;\n\t}\n}\n\n// #endregion\n\n/**\n * For hydrated nodes this is a HydratedFlexTreeNode thats a projection of forest content.\n * For {@link Unhydrated} nodes this is a UnhydratedFlexTreeNode.\n */\nexport type InnerNode = FlexTreeNode;\n\n/**\n * Narrows innerNode to either {@link UnhydratedFlexTreeNode} or {@link HydratedFlexTreeNode}.\n */\nexport function splitInnerNodeType(\n\tinnerNode: InnerNode,\n): asserts innerNode is UnhydratedFlexTreeNode | HydratedFlexTreeNode {\n\tassert(\n\t\tinnerNode instanceof UnhydratedFlexTreeNode || innerNode.isHydrated(),\n\t\t0xbc8 /* Invalid inner node type */,\n\t);\n}\n\n/**\n * An anchor slot which associates an anchor with its corresponding {@link TreeNode}, if there is one.\n * @remarks\n * For this to work, we have to require that there is at most a single view using a given AnchorSet.\n * FlexTree already has this assumption, and we also assume there is a single simple-tree per FlexTree, so this is valid.\n */\nexport const simpleTreeNodeSlot = anchorSlot<TreeNode>();\n\n/**\n * Dispose a TreeNode (if any) for an existing anchor without disposing the anchor.\n */\nexport function tryDisposeTreeNode(anchorNode: AnchorNode): void {\n\tconst treeNode = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (treeNode !== undefined) {\n\t\tconst kernel = getKernel(treeNode);\n\t\tkernel.dispose();\n\t\tanchorNode.slots.delete(simpleTreeNodeSlot);\n\t}\n}\n\n/**\n * Gets the {@link TreeNodeSchema} for the {@link InnerNode}.\n */\nexport function getSimpleNodeSchemaFromInnerNode(innerNode: InnerNode): TreeNodeSchema {\n\tconst context: Context = getSimpleContextFromInnerNode(innerNode);\n\treturn context.schema.get(innerNode.type) ?? fail(0xb3f /* missing schema from context */);\n}\n\n/**\n * Gets the {@link Context} for the {@link InnerNode}.\n */\nexport function getSimpleContextFromInnerNode(innerNode: InnerNode): Context {\n\tsplitInnerNodeType(innerNode);\n\tif (innerNode instanceof UnhydratedFlexTreeNode) {\n\t\treturn innerNode.simpleContext;\n\t}\n\n\tconst context = innerNode.anchorNode.anchorSet.slots.get(SimpleContextSlot);\n\tassert(context !== undefined, 0xa55 /* missing simple tree context */);\n\n\treturn context;\n}\n\n/**\n * Retrieves the flex node associated with the given target.\n * @remarks\n * For {@link Unhydrated} nodes, this returns the MapTreeNode.\n *\n * For hydrated nodes it returns a FlexTreeNode backed by the forest.\n *\n * @throws A {@link @fluidframework/telemetry-utils#UsageError} if the node has been deleted.\n */\nexport function getInnerNode(treeNode: TreeNode): InnerNode {\n\tconst kernel = getKernel(treeNode);\n\treturn kernel.getInnerNode();\n}\n\n/**\n * Gets a flex node from an anchor node\n */\nfunction flexNodeFromAnchor(anchorNode: AnchorNode): HydratedFlexTreeNode {\n\tconst flexNode = anchorNode.slots.get(flexTreeSlot);\n\tif (flexNode !== undefined) {\n\t\treturn flexNode; // If it does have a flex node, return it...\n\t} // ...otherwise, the flex node must be created\n\tconst context =\n\t\tanchorNode.anchorSet.slots.get(ContextSlot) ?? fail(0xb45 /* missing context */);\n\tconst cursor = context.checkout.forest.allocateCursor(\"getFlexNode\");\n\tcontext.checkout.forest.moveCursorToPath(anchorNode, cursor);\n\tconst newFlexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\tcursor.free();\n\treturn newFlexNode;\n}\n\n/**\n * Gets a tree node from an anchor node\n */\nexport function treeNodeFromAnchor(anchorNode: AnchorNode): TreeNode | TreeValue {\n\tconst cached = anchorNode.slots.get(simpleTreeNodeSlot);\n\tif (cached !== undefined) {\n\t\treturn cached;\n\t}\n\n\tconst flexNode = flexNodeFromAnchor(anchorNode);\n\treturn createTreeNodeFromInner(flexNode);\n}\n\n/**\n * Constructs a TreeNode from an InnerNode.\n * @remarks\n * This does not do caching or validation: caller must ensure duplicate nodes for a given inner node are not created, and that the inner node is valid.\n */\nexport function createTreeNodeFromInner(innerNode: InnerNode): TreeNode | TreeValue {\n\tconst classSchema = getSimpleNodeSchemaFromInnerNode(innerNode);\n\tconst internal = innerNode as unknown as InternalTreeNode;\n\treturn typeof classSchema === \"function\"\n\t\t? new classSchema(internal)\n\t\t: (classSchema as { create(data: InternalTreeNode): TreeNode | TreeValue }).create(\n\t\t\t\tinternal,\n\t\t\t);\n}\n\n/**\n * Creating multiple simple tree contexts for the same branch, and thus with the same underlying AnchorSet does not work due to how TreeNode caching works.\n * This slot is used to detect if one already exists and error if creating a second.\n * @remarks\n * See also {@link ContextSlot} in which the flex-tree context is stored.\n */\nexport const SimpleContextSlot = anchorSlot<HydratedContext>();\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"unhydratedFlexTree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/core/unhydratedFlexTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAIzF,OAAO,EACN,KAAK,YAAY,EAEjB,KAAK,QAAQ,EACb,KAAK,mBAAmB,EACxB,KAAK,sBAAsB,EAC3B,KAAK,QAAQ,EACb,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,gBAAgB,EACrB,KAAK,SAAS,EACd,KAAK,KAAK,EACV,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,KAAK,eAAe,EACpB,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,qBAAqB,EAE1B,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,sBAAsB,EAC3B,cAAc,EAEd,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAMlB,KAAK,mBAAmB,EACxB,KAAK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AAsB,GAAG,SAAS;IAOrD,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,KAAK,EAAE,sBAAsB,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,GAAG,CAAC,EAAE;CAGnF;AAID,gDAAgD;AAChD,wBAAgB,WAAW,CAC1B,GAAG,IAAI,EAAE,qBAAqB,CAAC,OAAO,uBAAuB,CAAC,GAC5D,uBAAuB,CAoBzB;AAED,wBAAgB,qBAAqB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,KAAK,CAM7D"}
@@ -99,7 +99,11 @@ export class UnhydratedFlexTreeNode {
99
99
  });
100
100
  }
101
101
  adoptBy(parent, index) {
102
- if (parent !== undefined) {
102
+ if (parent === undefined) {
103
+ assert(this.location !== unparentedLocation, 0xa09 /* Node may not be un-adopted if it does not have a parent */);
104
+ this.location = unparentedLocation;
105
+ }
106
+ else {
103
107
  assert(index !== undefined, 0xa08 /* Expected index */);
104
108
  if (this.location !== unparentedLocation) {
105
109
  throw new UsageError("A node may not be in more than one place in the tree");
@@ -115,10 +119,6 @@ export class UnhydratedFlexTreeNode {
115
119
  }
116
120
  this.location = { parent, index };
117
121
  }
118
- else {
119
- assert(this.location !== unparentedLocation, 0xa09 /* Node may not be un-adopted if it does not have a parent */);
120
- this.location = unparentedLocation;
121
- }
122
122
  }
123
123
  /**
124
124
  * The field this tree is in, and the index within that field.
@@ -234,7 +234,7 @@ export class UnhydratedFlexTreeField {
234
234
  return cursorForMapTreeField(this.children);
235
235
  }
236
236
  getPendingDefault() {
237
- return !Array.isArray(this.lazyChildren) ? this.lazyChildren : undefined;
237
+ return Array.isArray(this.lazyChildren) ? undefined : this.lazyChildren;
238
238
  }
239
239
  /**
240
240
  * Populate pending default (if present) using the provided context.
@@ -325,11 +325,11 @@ export class UnhydratedOptionalField extends UnhydratedFlexTreeField {
325
325
  assert(newContent instanceof UnhydratedFlexTreeNode, 0xbb7 /* Expected unhydrated node */);
326
326
  }
327
327
  this.edit((mapTrees) => {
328
- if (newContent !== undefined) {
329
- mapTrees[0] = newContent;
328
+ if (newContent === undefined) {
329
+ mapTrees.length = 0;
330
330
  }
331
331
  else {
332
- mapTrees.length = 0;
332
+ mapTrees[0] = newContent;
333
333
  }
334
334
  });
335
335
  },
@@ -370,7 +370,7 @@ export class UnhydratedSequenceField extends UnhydratedFlexTreeField {
370
370
  }
371
371
  else {
372
372
  // ...but we avoid using `splice` + spread for very large input arrays since there is a limit on how many elements can be spread (too many will overflow the stack).
373
- return mapTrees.slice(0, index).concat(newContentChecked, mapTrees.slice(index));
373
+ return [...mapTrees.slice(0, index), ...newContentChecked, ...mapTrees.slice(index)];
374
374
  }
375
375
  });
376
376
  },
@@ -403,17 +403,22 @@ export class UnhydratedSequenceField extends UnhydratedFlexTreeField {
403
403
  export function createField(...args) {
404
404
  switch (args[1]) {
405
405
  case FieldKinds.required.identifier:
406
- case FieldKinds.identifier.identifier:
406
+ case FieldKinds.identifier.identifier: {
407
407
  return new UnhydratedRequiredField(...args);
408
- case FieldKinds.optional.identifier:
408
+ }
409
+ case FieldKinds.optional.identifier: {
409
410
  return new UnhydratedOptionalField(...args);
410
- case FieldKinds.sequence.identifier:
411
+ }
412
+ case FieldKinds.sequence.identifier: {
411
413
  return new UnhydratedSequenceField(...args);
412
- case FieldKinds.forbidden.identifier:
414
+ }
415
+ case FieldKinds.forbidden.identifier: {
413
416
  // TODO: this seems to used by unknown optional fields. They should probably use "optional" not "Forbidden" schema.
414
417
  return new UnhydratedFlexTreeField(...args);
415
- default:
418
+ }
419
+ default: {
416
420
  return fail(0xb9d /* unsupported field kind */);
421
+ }
417
422
  }
418
423
  }
419
424
  export function unsupportedUsageError(message) {