@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
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema-stored/schema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAE3D,mDAAoE;AACpE,kDAO6B;AAE7B,+CAOuB;AASvB;;GAEG;AACU,QAAA,mBAAmB,GAAG,IAAA,qBAAU,EAAC,qBAAqB,EAAE;IACpE,EAAE,EAAE,CAAC;IACL;;OAEG;IACH,EAAE,EAAE,CAAC;CACL,CAAC,CAAC;AAKH;;;;;;;;GAQG;AACH,IAAY,WAMX;AAND,WAAY,WAAW;IACtB,iDAAM,CAAA;IACN,iDAAM,CAAA;IACN,mDAAO,CAAA;IACP,2DAAW,CAAA;IACX,6CAAI,CAAA;AACL,CAAC,EANW,WAAW,2BAAX,WAAW,QAMtB;AAmGD;;;;;;;;;GASG;AACU,QAAA,4BAA4B,GAAG,IAAA,qBAAU,EAAC,WAAW,CAAC,EAAuB,CAAC;AAE3F;;;GAGG;AACU,QAAA,sBAAsB,GAA0B;IAC5D,4CAA4C;IAC5C,IAAI,EAAE,oCAA4B;IAClC,qFAAqF;IACrF,KAAK,EAAE,IAAI,GAAG,EAAE;IAChB,iBAAiB,EAAE,SAAS;CAC5B,CAAC;AAEF;;GAEG;AACU,QAAA,6BAA6B,GAAG,YAAY,CAAC;AAE1D,MAAsB,oBAAoB;IAGzC;;;OAGG;IACH,YAAmC,QAA6C;QAA7C,aAAQ,G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K,CAAC,kCAAkC,CAAC,CAAC;AAC1F,CAAC;AAED,SAAS,iBAAiB,CAAC,QAA8B;IACxD,OAAO,iBAAiB,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,IAAA,eAAI,EAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;AACjF,CAAC;AAED,SAAgB,mBAAmB,CAAC,MAA6B;IAChE,OAAO;QACN,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,iHAAiH;QACjH,KAAK,EAAE,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE;KAC/B,CAAC;AACH,CAAC;AAND,kDAMC;AAED,SAAgB,mBAAmB,CAAC,MAA6B;IAChE,MAAM,WAAW,GAAwB,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAErE,mDAAmD;IACnD,OAAO,MAAM,CAAC,iBAAiB,KAAK,SAAS;QAC5C,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,iBAAiB,EAAE;QACxD,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,CAAC;AACvB,CAAC;AAPD,kDAOC;AAED,SAAgB,iBAAiB,CAAC,MAA2B;IAC5D,MAAM,GAAG,GAA0B;QAClC,kFAAkF;QAClF,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;QAC5B,iBAAiB,EAAE,MAAM,CAAC,QAAQ;KAClC,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC;AARD,8CAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\n\nimport { DiscriminatedUnionDispatcher } from \"../../codec/index.js\";\nimport {\n\ttype JsonCompatibleReadOnlyObject,\n\ttype MakeNominal,\n\ttype Values,\n\tbrandConst,\n\tinvertMap,\n\tstrictEnum,\n} from \"../../util/index.js\";\n\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldSchemaFormat as FieldSchemaFormatV1,\n\tPersistedValueSchema,\n\ttype TreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV1,\n\ttype TreeNodeSchemaIdentifier,\n} from \"./formatV1.js\";\nimport type {\n\tFieldSchemaFormat as FieldSchemaFormatV2,\n\tPersistedMetadataFormat,\n\tTreeNodeSchemaUnionFormat,\n\tTreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV2,\n} from \"./formatV2.js\";\nimport type { Multiplicity } from \"./multiplicity.js\";\n\n/**\n * The format version for the schema.\n */\nexport const SchemaFormatVersion = strictEnum(\"SchemaFormatVersion\", {\n\tv1: 1,\n\t/**\n\t * Adds persisted metadata to the node schema and field schema.\n\t */\n\tv2: 2,\n});\nexport type SchemaFormatVersion = Values<typeof SchemaFormatVersion>;\n\ntype FieldSchemaFormat = FieldSchemaFormatV1 | FieldSchemaFormatV2;\n\n/**\n * Schema for what {@link TreeLeafValue} is allowed on a Leaf node.\n * @privateRemarks\n * See also {@link TreeValue}.\n * If further stabilizing this,\n * consider the implications of how this might prevent adding of new leaf types in the future.\n * Maybe add a disclaimer that it might be extended like on {@link NodeKind}?\n * @alpha\n */\nexport enum ValueSchema {\n\tNumber,\n\tString,\n\tBoolean,\n\tFluidHandle,\n\tNull,\n}\n\n/**\n * Set of allowed tree types.\n * Providing multiple values here allows polymorphism, tagged union style.\n *\n * In the future, this could be extended to allow inlining a TreeNodeStoredSchema here\n * (or some similar structural schema system).\n * For structural types which could go here, there are a few interesting options:\n *\n * - Allow replacing the whole set with a structural type for terminal / non-tree data,\n * and use this as a replacement for values on the tree nodes.\n *\n * - Allow expression structural constraints for child trees, for example requiring specific traits\n * (ex: via TreeNodeStoredSchema), instead of by type.\n *\n * There are two ways this could work:\n *\n * - Constrain the child nodes based on their shape:\n * this makes schema safe editing difficult because nodes would incur extra editing constraints to prevent them\n * from going out of schema based on their location in such a field.\n *\n * - Constrain the types allowed based on which types guarantee their data will always meet the constraints.\n *\n * Care would need to be taken to make sure this is sound for the schema updating mechanisms.\n */\nexport type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;\n\n/**\n * Declarative portion of a {@link FlexFieldKind}.\n *\n * @remarks\n * Enough info about a field kind to know if a given tree is is schema.\n *\n * Note that compatibility between trees and schema is not sufficient to evaluate if a schema upgrade should be allowed.\n * Currently schema upgrades are restricted to field kind changes which can not be cyclic (like version upgrades but not down grades).\n * See {@link FlexFieldKind.allowsFieldSuperset} for more details.\n */\nexport interface FieldKindData {\n\t/**\n\t * Globally scoped identifier.\n\t */\n\treadonly identifier: FieldKindIdentifier;\n\t/**\n\t * Bound on the number of children that fields of this kind may have.\n\t * TODO: consider replacing this with numeric upper and lower bounds.\n\t */\n\treadonly multiplicity: Multiplicity;\n}\n\n/**\n * Everything needed to define what it means for a tree to be in schema.\n */\nexport interface SchemaAndPolicy {\n\treadonly schema: StoredSchemaCollection;\n\treadonly policy: SchemaPolicy;\n}\n\n/**\n * Extra data needed to interpret stored schema.\n * @remarks\n * This contains information that describes the semantics of things which can be referenced in stored schema.\n * For example, field kind identifiers refer to specific field kinds, which imply specific rules around what is valid in a given field (the multiplicity).\n * This structure provides such information, allowing it to be possible to determine if a given tree complies with a particular stored schema.\n */\nexport interface SchemaPolicy {\n\t/**\n\t * Policy information about FieldKinds:\n\t * This is typically stored as code, not in documents, and defines how to handle fields based on their kind.\n\t * It is assumed that all users of a document will have exactly the same FieldKind policies,\n\t * though older applications might be missing some,\n\t * and will be unable to process any changes that use those FieldKinds.\n\t */\n\treadonly fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindData>;\n}\n\n/**\n * Schema for a field.\n * Object implementing this interface should never be modified.\n */\nexport interface TreeFieldStoredSchema {\n\treadonly kind: FieldKindIdentifier;\n\n\t/**\n\t * The set of allowed child types.\n\t * If not specified, types are unconstrained.\n\t */\n\treadonly types: TreeTypeSet;\n\n\t/**\n\t * Portion of the metadata which can be persisted.\n\t * @remarks\n\t * Discarded when encoding to {@link SchemaFormatVersion.V1}.\n\t * @privateRemarks\n\t * This field corresponds to the `metadata` field in the persisted schema format.\n\t */\n\treadonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * Identifier used for the FieldKind for fields which must be empty.\n *\n * @remarks\n * This mainly show up in:\n *\n * 1. The root default field for documents.\n *\n * 2. The schema used for out of schema fields (which thus must be empty/not exist) on object and leaf nodes.\n */\nexport const forbiddenFieldKindIdentifier = brandConst(\"Forbidden\")<FieldKindIdentifier>();\n\n/**\n * A schema for empty fields (fields which must always be empty).\n * There are multiple ways this could be encoded, but this is the most explicit.\n */\nexport const storedEmptyFieldSchema: TreeFieldStoredSchema = {\n\t// This kind requires the field to be empty.\n\tkind: forbiddenFieldKindIdentifier,\n\t// This type set also forces the field to be empty not not allowing any types as all.\n\ttypes: new Set(),\n\tpersistedMetadata: undefined,\n};\n\n/**\n * Identifier used for the FieldKind for fields of type identifier.\n */\nexport const identifierFieldKindIdentifier = \"Identifier\";\n\nexport abstract class TreeNodeStoredSchema {\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * Constructor for a TreeNodeStoredSchema.\n\t * @param metadata - Persisted metadata for this node schema.\n\t */\n\tpublic constructor(public readonly metadata: PersistedMetadataFormat | undefined) {}\n\n\t/**\n\t * Encode in the v1 schema format.\n\t */\n\tpublic abstract encodeV1(): TreeNodeSchemaDataFormatV1;\n\n\t/**\n\t * Encode in the v2 schema format.\n\t * @remarks Post-condition: if metadata was specified on the input schema, it will be present in the output.\n\t */\n\tpublic abstract encodeV2(): TreeNodeSchemaDataFormatV2;\n\n\t/**\n\t * Returns the schema for the provided field.\n\t */\n\tpublic abstract getFieldSchema(field: FieldKey): TreeFieldStoredSchema;\n}\n\nexport class ObjectNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param objectNodeFields - Schema for fields with keys scoped to this TreeNodeStoredSchema.\n\t * This refers to the TreeFieldStoredSchema directly\n\t * (as opposed to just supporting FieldSchemaIdentifier and having a central FieldKey -\\> TreeFieldStoredSchema map).\n\t * This allows us short friendly field keys which can be ergonomically used as field names in code.\n\t * It also interoperates well with mapFields being used as a map with arbitrary data as keys.\n\t */\n\tpublic constructor(\n\t\tpublic readonly objectNodeFields: ReadonlyMap<FieldKey, TreeFieldStoredSchema>,\n\t\tmetadata?: PersistedMetadataFormat | undefined,\n\t) {\n\t\tsuper(metadata);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> =\n\t\t\tthis.encodeFieldsObject(encodeFieldSchemaV1);\n\n\t\treturn {\n\t\t\tobject: fieldsObject,\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> =\n\t\t\tthis.encodeFieldsObject(encodeFieldSchemaV2);\n\t\tconst kind = { object: fieldsObject };\n\n\t\treturn { kind, metadata: this.metadata };\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.objectNodeFields.get(field) ?? storedEmptyFieldSchema;\n\t}\n\n\tprivate encodeFieldsObject(\n\t\tencodeFieldSchema: (storedFieldSchema: TreeFieldStoredSchema) => FieldSchemaFormat,\n\t): Record<string, FieldSchemaFormat> {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> = Object.create(null);\n\t\t// Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).\n\t\t// This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.\n\t\tfor (const key of [...this.objectNodeFields.keys()].sort()) {\n\t\t\tObject.defineProperty(fieldsObject, key, {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: encodeFieldSchema(\n\t\t\t\t\tthis.objectNodeFields.get(key) ?? fail(0xae7 /* missing field */),\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t\treturn fieldsObject;\n\t}\n}\n\nexport class MapNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param mapFields - Allows using the fields as a map, with the keys being\n\t * FieldKeys and the values being constrained by this TreeFieldStoredSchema.\n\t * Usually `FieldKind.Value` should NOT be used here\n\t * since no nodes can ever be in schema if you use `FieldKind.Value` here\n\t * (that would require infinite children).\n\t */\n\tpublic constructor(\n\t\tpublic readonly mapFields: TreeFieldStoredSchema,\n\t\tmetadata?: PersistedMetadataFormat | undefined,\n\t) {\n\t\tsuper(metadata);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\treturn {\n\t\t\tmap: encodeFieldSchemaV1(this.mapFields),\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\tconst kind = { map: encodeFieldSchemaV2(this.mapFields) };\n\t\treturn { kind, metadata: this.metadata };\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.mapFields;\n\t}\n}\n\nexport class LeafNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param leafValue - There are several approaches for how to store actual data in the tree\n\t * (special node types, special field contents, data on nodes etc.)\n\t * as well as several options about how the data should be modeled at this level\n\t * (byte sequence? javascript type? json?),\n\t * as well as options for how much of this would be exposed in the schema language\n\t * (ex: would all nodes with values be special built-ins, or could any schema add them?)\n\t * A simple easy to do in javascript approach is taken here:\n\t * this is not intended to be a suggestion of what approach to take, or what to expose in the schema language.\n\t * This is simply one approach that can work for modeling them in the internal schema representation.\n\t */\n\tpublic constructor(public readonly leafValue: ValueSchema) {\n\t\t// No metadata for leaf nodes.\n\t\tsuper(undefined);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\treturn {\n\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\treturn {\n\t\t\t// No metadata for leaf nodes, so don't emit a metadata field.\n\t\t\tkind: {\n\t\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn storedEmptyFieldSchema;\n\t}\n}\n\n/**\n * Decoder wrapper function for {@link TreeNodeStoredSchema} implementations.\n * Curries the constructor so that the caller can inject metadata.\n */\ntype StoredSchemaDecoder = (\n\tmetadata: PersistedMetadataFormat | undefined,\n) => TreeNodeStoredSchema;\n\nexport const storedSchemaDecodeDispatcher: DiscriminatedUnionDispatcher<\n\tTreeNodeSchemaUnionFormat,\n\t[],\n\tStoredSchemaDecoder\n> = new DiscriminatedUnionDispatcher({\n\tleaf: (data: PersistedValueSchema) => (metadata) =>\n\t\tnew LeafNodeStoredSchema(decodeValueSchema(data)),\n\tobject: (data: Record<TreeNodeSchemaIdentifier, FieldSchemaFormat>) => (metadata) => {\n\t\tconst map = new Map();\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tmap.set(key, decodeFieldSchema(value));\n\t\t}\n\t\treturn new ObjectNodeStoredSchema(map, metadata);\n\t},\n\tmap: (data: FieldSchemaFormat) => (metadata) =>\n\t\tnew MapNodeStoredSchema(decodeFieldSchema(data), metadata),\n});\n\nconst valueSchemaEncode = new Map([\n\t[ValueSchema.Number, PersistedValueSchema.Number],\n\t[ValueSchema.String, PersistedValueSchema.String],\n\t[ValueSchema.Boolean, PersistedValueSchema.Boolean],\n\t[ValueSchema.FluidHandle, PersistedValueSchema.FluidHandle],\n\t[ValueSchema.Null, PersistedValueSchema.Null],\n]);\n\nconst valueSchemaDecode = invertMap(valueSchemaEncode);\n\nfunction encodeValueSchema(inMemory: ValueSchema): PersistedValueSchema {\n\treturn valueSchemaEncode.get(inMemory) ?? fail(0xae8 /* missing PersistedValueSchema */);\n}\n\nfunction decodeValueSchema(inMemory: PersistedValueSchema): ValueSchema {\n\treturn valueSchemaDecode.get(inMemory) ?? fail(0xae9 /* missing ValueSchema */);\n}\n\nexport function encodeFieldSchemaV1(schema: TreeFieldStoredSchema): FieldSchemaFormatV1 {\n\treturn {\n\t\tkind: schema.kind,\n\t\t// Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.\n\t\ttypes: [...schema.types].sort(),\n\t};\n}\n\nexport function encodeFieldSchemaV2(schema: TreeFieldStoredSchema): FieldSchemaFormatV2 {\n\tconst fieldSchema: FieldSchemaFormatV1 = encodeFieldSchemaV1(schema);\n\n\t// Omit metadata from the output if it is undefined\n\treturn schema.persistedMetadata !== undefined\n\t\t? { ...fieldSchema, metadata: schema.persistedMetadata }\n\t\t: { ...fieldSchema };\n}\n\nexport function decodeFieldSchema(schema: FieldSchemaFormatV2): TreeFieldStoredSchema {\n\tconst out: TreeFieldStoredSchema = {\n\t\t// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.\n\t\tkind: schema.kind,\n\t\ttypes: new Set(schema.types),\n\t\tpersistedMetadata: schema.metadata,\n\t};\n\treturn out;\n}\n\n/**\n * Document schema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hand onto a specific version, make a copy.\n */\nexport interface TreeStoredSchema extends StoredSchemaCollection {\n\t/**\n\t * Schema for the root field which contains the whole tree.\n\t */\n\treadonly rootFieldSchema: TreeFieldStoredSchema;\n}\n\n/**\n * Collection of TreeNodeSchema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hang onto a specific version, make a copy.\n */\nexport interface StoredSchemaCollection {\n\t/**\n\t * {@inheritdoc StoredSchemaCollection}\n\t */\n\treadonly nodeSchema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;\n}\n"]}
1
+ {"version":3,"file":"schema.js","sourceRoot":"","sources":["../../../src/core/schema-stored/schema.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA2D;AAE3D,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AAC,MAAM,CAAC,CAAC;IAErE,mDAAmD;IACnD,OAAO,MAAM,CAAC,iBAAiB,KAAK,SAAS;QAC5C,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE;QACpB,CAAC,CAAC,EAAE,GAAG,WAAW,EAAE,QAAQ,EAAE,MAAM,CAAC,iBAAiB,EAAE,CAAC;AAC3D,CAAC;AAPD,kDAOC;AAED,SAAgB,iBAAiB,CAAC,MAA2B;IAC5D,MAAM,GAAG,GAA0B;QAClC,kFAAkF;QAClF,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,KAAK,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC;QAC5B,iBAAiB,EAAE,MAAM,CAAC,QAAQ;KAClC,CAAC;IACF,OAAO,GAAG,CAAC;AACZ,CAAC;AARD,8CAQC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { fail } from \"@fluidframework/core-utils/internal\";\n\nimport { DiscriminatedUnionDispatcher } from \"../../codec/index.js\";\nimport {\n\ttype JsonCompatibleReadOnlyObject,\n\ttype MakeNominal,\n\ttype Values,\n\tbrandConst,\n\tinvertMap,\n\tstrictEnum,\n} from \"../../util/index.js\";\n\nimport {\n\ttype FieldKey,\n\ttype FieldKindIdentifier,\n\ttype FieldSchemaFormat as FieldSchemaFormatV1,\n\tPersistedValueSchema,\n\ttype TreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV1,\n\ttype TreeNodeSchemaIdentifier,\n} from \"./formatV1.js\";\nimport type {\n\tFieldSchemaFormat as FieldSchemaFormatV2,\n\tPersistedMetadataFormat,\n\tTreeNodeSchemaUnionFormat,\n\tTreeNodeSchemaDataFormat as TreeNodeSchemaDataFormatV2,\n} from \"./formatV2.js\";\nimport type { Multiplicity } from \"./multiplicity.js\";\n\n/**\n * The format version for the schema.\n */\nexport const SchemaFormatVersion = strictEnum(\"SchemaFormatVersion\", {\n\tv1: 1,\n\t/**\n\t * Adds persisted metadata to the node schema and field schema.\n\t */\n\tv2: 2,\n});\nexport type SchemaFormatVersion = Values<typeof SchemaFormatVersion>;\n\ntype FieldSchemaFormat = FieldSchemaFormatV1 | FieldSchemaFormatV2;\n\n/**\n * Schema for what {@link TreeLeafValue} is allowed on a Leaf node.\n * @privateRemarks\n * See also {@link TreeValue}.\n * If further stabilizing this,\n * consider the implications of how this might prevent adding of new leaf types in the future.\n * Maybe add a disclaimer that it might be extended like on {@link NodeKind}?\n * @alpha\n */\nexport enum ValueSchema {\n\tNumber,\n\tString,\n\tBoolean,\n\tFluidHandle,\n\tNull,\n}\n\n/**\n * Set of allowed tree types.\n * Providing multiple values here allows polymorphism, tagged union style.\n *\n * In the future, this could be extended to allow inlining a TreeNodeStoredSchema here\n * (or some similar structural schema system).\n * For structural types which could go here, there are a few interesting options:\n *\n * - Allow replacing the whole set with a structural type for terminal / non-tree data,\n * and use this as a replacement for values on the tree nodes.\n *\n * - Allow expression structural constraints for child trees, for example requiring specific traits\n * (ex: via TreeNodeStoredSchema), instead of by type.\n *\n * There are two ways this could work:\n *\n * - Constrain the child nodes based on their shape:\n * this makes schema safe editing difficult because nodes would incur extra editing constraints to prevent them\n * from going out of schema based on their location in such a field.\n *\n * - Constrain the types allowed based on which types guarantee their data will always meet the constraints.\n *\n * Care would need to be taken to make sure this is sound for the schema updating mechanisms.\n */\nexport type TreeTypeSet = ReadonlySet<TreeNodeSchemaIdentifier>;\n\n/**\n * Declarative portion of a {@link FlexFieldKind}.\n *\n * @remarks\n * Enough info about a field kind to know if a given tree is is schema.\n *\n * Note that compatibility between trees and schema is not sufficient to evaluate if a schema upgrade should be allowed.\n * Currently schema upgrades are restricted to field kind changes which can not be cyclic (like version upgrades but not down grades).\n * See {@link FlexFieldKind.allowsFieldSuperset} for more details.\n */\nexport interface FieldKindData {\n\t/**\n\t * Globally scoped identifier.\n\t */\n\treadonly identifier: FieldKindIdentifier;\n\t/**\n\t * Bound on the number of children that fields of this kind may have.\n\t * TODO: consider replacing this with numeric upper and lower bounds.\n\t */\n\treadonly multiplicity: Multiplicity;\n}\n\n/**\n * Everything needed to define what it means for a tree to be in schema.\n */\nexport interface SchemaAndPolicy {\n\treadonly schema: StoredSchemaCollection;\n\treadonly policy: SchemaPolicy;\n}\n\n/**\n * Extra data needed to interpret stored schema.\n * @remarks\n * This contains information that describes the semantics of things which can be referenced in stored schema.\n * For example, field kind identifiers refer to specific field kinds, which imply specific rules around what is valid in a given field (the multiplicity).\n * This structure provides such information, allowing it to be possible to determine if a given tree complies with a particular stored schema.\n */\nexport interface SchemaPolicy {\n\t/**\n\t * Policy information about FieldKinds:\n\t * This is typically stored as code, not in documents, and defines how to handle fields based on their kind.\n\t * It is assumed that all users of a document will have exactly the same FieldKind policies,\n\t * though older applications might be missing some,\n\t * and will be unable to process any changes that use those FieldKinds.\n\t */\n\treadonly fieldKinds: ReadonlyMap<FieldKindIdentifier, FieldKindData>;\n}\n\n/**\n * Schema for a field.\n * Object implementing this interface should never be modified.\n */\nexport interface TreeFieldStoredSchema {\n\treadonly kind: FieldKindIdentifier;\n\n\t/**\n\t * The set of allowed child types.\n\t * If not specified, types are unconstrained.\n\t */\n\treadonly types: TreeTypeSet;\n\n\t/**\n\t * Portion of the metadata which can be persisted.\n\t * @remarks\n\t * Discarded when encoding to {@link SchemaFormatVersion.V1}.\n\t * @privateRemarks\n\t * This field corresponds to the `metadata` field in the persisted schema format.\n\t */\n\treadonly persistedMetadata: JsonCompatibleReadOnlyObject | undefined;\n}\n\n/**\n * Identifier used for the FieldKind for fields which must be empty.\n *\n * @remarks\n * This mainly show up in:\n *\n * 1. The root default field for documents.\n *\n * 2. The schema used for out of schema fields (which thus must be empty/not exist) on object and leaf nodes.\n */\nexport const forbiddenFieldKindIdentifier = brandConst(\"Forbidden\")<FieldKindIdentifier>();\n\n/**\n * A schema for empty fields (fields which must always be empty).\n * There are multiple ways this could be encoded, but this is the most explicit.\n */\nexport const storedEmptyFieldSchema: TreeFieldStoredSchema = {\n\t// This kind requires the field to be empty.\n\tkind: forbiddenFieldKindIdentifier,\n\t// This type set also forces the field to be empty not not allowing any types as all.\n\ttypes: new Set(),\n\tpersistedMetadata: undefined,\n};\n\n/**\n * Identifier used for the FieldKind for fields of type identifier.\n */\nexport const identifierFieldKindIdentifier = \"Identifier\";\n\nexport abstract class TreeNodeStoredSchema {\n\tprotected _typeCheck!: MakeNominal;\n\n\t/**\n\t * Constructor for a TreeNodeStoredSchema.\n\t * @param metadata - Persisted metadata for this node schema.\n\t */\n\tpublic constructor(public readonly metadata: PersistedMetadataFormat | undefined) {}\n\n\t/**\n\t * Encode in the v1 schema format.\n\t */\n\tpublic abstract encodeV1(): TreeNodeSchemaDataFormatV1;\n\n\t/**\n\t * Encode in the v2 schema format.\n\t * @remarks Post-condition: if metadata was specified on the input schema, it will be present in the output.\n\t */\n\tpublic abstract encodeV2(): TreeNodeSchemaDataFormatV2;\n\n\t/**\n\t * Returns the schema for the provided field.\n\t */\n\tpublic abstract getFieldSchema(field: FieldKey): TreeFieldStoredSchema;\n}\n\nexport class ObjectNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param objectNodeFields - Schema for fields with keys scoped to this TreeNodeStoredSchema.\n\t * This refers to the TreeFieldStoredSchema directly\n\t * (as opposed to just supporting FieldSchemaIdentifier and having a central FieldKey -\\> TreeFieldStoredSchema map).\n\t * This allows us short friendly field keys which can be ergonomically used as field names in code.\n\t * It also interoperates well with mapFields being used as a map with arbitrary data as keys.\n\t */\n\tpublic constructor(\n\t\tpublic readonly objectNodeFields: ReadonlyMap<FieldKey, TreeFieldStoredSchema>,\n\t\tmetadata?: PersistedMetadataFormat | undefined,\n\t) {\n\t\tsuper(metadata);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> =\n\t\t\tthis.encodeFieldsObject(encodeFieldSchemaV1);\n\n\t\treturn {\n\t\t\tobject: fieldsObject,\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> =\n\t\t\tthis.encodeFieldsObject(encodeFieldSchemaV2);\n\t\tconst kind = { object: fieldsObject };\n\n\t\treturn { kind, metadata: this.metadata };\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.objectNodeFields.get(field) ?? storedEmptyFieldSchema;\n\t}\n\n\tprivate encodeFieldsObject(\n\t\tencodeFieldSchema: (storedFieldSchema: TreeFieldStoredSchema) => FieldSchemaFormat,\n\t): Record<string, FieldSchemaFormat> {\n\t\tconst fieldsObject: Record<string, FieldSchemaFormat> = Object.create(null);\n\t\t// Sort fields to ensure output is identical for for equivalent schema (since field order is not considered significant).\n\t\t// This makes comparing schema easier, and ensures chunk reuse for schema summaries isn't needlessly broken.\n\t\tfor (const key of [...this.objectNodeFields.keys()].sort()) {\n\t\t\tObject.defineProperty(fieldsObject, key, {\n\t\t\t\tenumerable: true,\n\t\t\t\tconfigurable: true,\n\t\t\t\twritable: true,\n\t\t\t\tvalue: encodeFieldSchema(\n\t\t\t\t\tthis.objectNodeFields.get(key) ?? fail(0xae7 /* missing field */),\n\t\t\t\t),\n\t\t\t});\n\t\t}\n\t\treturn fieldsObject;\n\t}\n}\n\nexport class MapNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param mapFields - Allows using the fields as a map, with the keys being\n\t * FieldKeys and the values being constrained by this TreeFieldStoredSchema.\n\t * Usually `FieldKind.Value` should NOT be used here\n\t * since no nodes can ever be in schema if you use `FieldKind.Value` here\n\t * (that would require infinite children).\n\t */\n\tpublic constructor(\n\t\tpublic readonly mapFields: TreeFieldStoredSchema,\n\t\tmetadata?: PersistedMetadataFormat | undefined,\n\t) {\n\t\tsuper(metadata);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\treturn {\n\t\t\tmap: encodeFieldSchemaV1(this.mapFields),\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\tconst kind = { map: encodeFieldSchemaV2(this.mapFields) };\n\t\treturn { kind, metadata: this.metadata };\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn this.mapFields;\n\t}\n}\n\nexport class LeafNodeStoredSchema extends TreeNodeStoredSchema {\n\t/**\n\t * @param leafValue - There are several approaches for how to store actual data in the tree\n\t * (special node types, special field contents, data on nodes etc.)\n\t * as well as several options about how the data should be modeled at this level\n\t * (byte sequence? javascript type? json?),\n\t * as well as options for how much of this would be exposed in the schema language\n\t * (ex: would all nodes with values be special built-ins, or could any schema add them?)\n\t * A simple easy to do in javascript approach is taken here:\n\t * this is not intended to be a suggestion of what approach to take, or what to expose in the schema language.\n\t * This is simply one approach that can work for modeling them in the internal schema representation.\n\t */\n\tpublic constructor(public readonly leafValue: ValueSchema) {\n\t\t// No metadata for leaf nodes.\n\t\tsuper(undefined);\n\t}\n\n\tpublic override encodeV1(): TreeNodeSchemaDataFormatV1 {\n\t\treturn {\n\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t};\n\t}\n\n\tpublic override encodeV2(): TreeNodeSchemaDataFormatV2 {\n\t\treturn {\n\t\t\t// No metadata for leaf nodes, so don't emit a metadata field.\n\t\t\tkind: {\n\t\t\t\tleaf: encodeValueSchema(this.leafValue),\n\t\t\t},\n\t\t};\n\t}\n\n\tpublic override getFieldSchema(field: FieldKey): TreeFieldStoredSchema {\n\t\treturn storedEmptyFieldSchema;\n\t}\n}\n\n/**\n * Decoder wrapper function for {@link TreeNodeStoredSchema} implementations.\n * Curries the constructor so that the caller can inject metadata.\n */\ntype StoredSchemaDecoder = (\n\tmetadata: PersistedMetadataFormat | undefined,\n) => TreeNodeStoredSchema;\n\nexport const storedSchemaDecodeDispatcher: DiscriminatedUnionDispatcher<\n\tTreeNodeSchemaUnionFormat,\n\t[],\n\tStoredSchemaDecoder\n> = new DiscriminatedUnionDispatcher({\n\tleaf: (data: PersistedValueSchema) => (metadata) =>\n\t\tnew LeafNodeStoredSchema(decodeValueSchema(data)),\n\tobject: (data: Record<TreeNodeSchemaIdentifier, FieldSchemaFormat>) => (metadata) => {\n\t\tconst map = new Map();\n\t\tfor (const [key, value] of Object.entries(data)) {\n\t\t\tmap.set(key, decodeFieldSchema(value));\n\t\t}\n\t\treturn new ObjectNodeStoredSchema(map, metadata);\n\t},\n\tmap: (data: FieldSchemaFormat) => (metadata) =>\n\t\tnew MapNodeStoredSchema(decodeFieldSchema(data), metadata),\n});\n\nconst valueSchemaEncode = new Map([\n\t[ValueSchema.Number, PersistedValueSchema.Number],\n\t[ValueSchema.String, PersistedValueSchema.String],\n\t[ValueSchema.Boolean, PersistedValueSchema.Boolean],\n\t[ValueSchema.FluidHandle, PersistedValueSchema.FluidHandle],\n\t[ValueSchema.Null, PersistedValueSchema.Null],\n]);\n\nconst valueSchemaDecode = invertMap(valueSchemaEncode);\n\nfunction encodeValueSchema(inMemory: ValueSchema): PersistedValueSchema {\n\treturn valueSchemaEncode.get(inMemory) ?? fail(0xae8 /* missing PersistedValueSchema */);\n}\n\nfunction decodeValueSchema(inMemory: PersistedValueSchema): ValueSchema {\n\treturn valueSchemaDecode.get(inMemory) ?? fail(0xae9 /* missing ValueSchema */);\n}\n\nexport function encodeFieldSchemaV1(schema: TreeFieldStoredSchema): FieldSchemaFormatV1 {\n\treturn {\n\t\tkind: schema.kind,\n\t\t// Types are sorted by identifier to improve stability of persisted data to increase chance of schema blob reuse.\n\t\ttypes: [...schema.types].sort(),\n\t};\n}\n\nexport function encodeFieldSchemaV2(schema: TreeFieldStoredSchema): FieldSchemaFormatV2 {\n\tconst fieldSchema: FieldSchemaFormatV1 = encodeFieldSchemaV1(schema);\n\n\t// Omit metadata from the output if it is undefined\n\treturn schema.persistedMetadata === undefined\n\t\t? { ...fieldSchema }\n\t\t: { ...fieldSchema, metadata: schema.persistedMetadata };\n}\n\nexport function decodeFieldSchema(schema: FieldSchemaFormatV2): TreeFieldStoredSchema {\n\tconst out: TreeFieldStoredSchema = {\n\t\t// TODO: maybe provide actual FieldKind objects here, error on unrecognized kinds.\n\t\tkind: schema.kind,\n\t\ttypes: new Set(schema.types),\n\t\tpersistedMetadata: schema.metadata,\n\t};\n\treturn out;\n}\n\n/**\n * Document schema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hand onto a specific version, make a copy.\n */\nexport interface TreeStoredSchema extends StoredSchemaCollection {\n\t/**\n\t * Schema for the root field which contains the whole tree.\n\t */\n\treadonly rootFieldSchema: TreeFieldStoredSchema;\n}\n\n/**\n * Collection of TreeNodeSchema data that can be stored in a document.\n *\n * @remarks\n * Note: the owner of this may modify it over time:\n * thus if needing to hang onto a specific version, make a copy.\n */\nexport interface StoredSchemaCollection {\n\t/**\n\t * {@inheritdoc StoredSchemaCollection}\n\t */\n\treadonly nodeSchema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"anchorSet.d.ts","sourceRoot":"","sources":["../../../src/core/tree/anchorSet.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAGzF,OAAO,EACN,KAAK,KAAK,EACV,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,MAAM,EACX,oBAAoB,EAKpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAG1D,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AAEzC,OAAO,EAEN,KAAK,iBAAiB,EAItB,KAAK,MAAM,EACX,MAAM,eAAe,CAAC;AAEvB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,MAA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K,EAAE,MAAM,GAAG,QAAQ;IAmBxD,eAAe,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS;IAO1E;;;;OAIG;IACI,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI;IAczC;;;;OAIG;IACI,eAAe,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IAM3C;;;;;;OAMG;IACH,OAAO,CAAC,eAAe;CAUvB"}
@@ -171,10 +171,8 @@ class AnchorSet {
171
171
  * Does not add a ref!
172
172
  */
173
173
  find(path) {
174
- if (path instanceof PathNode) {
175
- if (path.anchorSet === this) {
176
- return path;
177
- }
174
+ if (path instanceof PathNode && path.anchorSet === this) {
175
+ return path;
178
176
  }
179
177
  const parent = path.parent ?? this.root;
180
178
  const parentPath = this.find(parent);
@@ -820,6 +818,7 @@ class PathNode extends index_js_1.ReferenceCountedBase {
820
818
  (0, internal_1.assert)(this.status !== Status.Disposed, 0x41d /* PathNode must not be disposed */);
821
819
  if (this.isUnreferenced() && this.children.size === 0 && !this.events.hasListeners()) {
822
820
  if (this.status === Status.Alive) {
821
+ // eslint-disable-next-line unicorn/prefer-dom-node-remove -- Custom tree structure, not DOM
823
822
  this.parentPath?.removeChild(this);
824
823
  }
825
824
  this.status = Status.Disposed;
@@ -1 +1 @@
1
- {"version":3,"file":"anchorSet.js","sourceRoot":"","sources":["../../../src/core/tree/anchorSet.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,6DAA6D;AAE7D,+DAA6D;AAE7D,kEAAmE;AAEnE,kDAU6B;AAK7B,iDAAgD;AAChD,+CAOuB;AACvB,yCAAsC;AAStC;;GAEG;AACH,MAAM,WAAW,GAAW,IAAA,gBAAK,EAAC,CAAC,CAAC,CAAC;AA+MrC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU;IACzB,OAAO,IAAA,sBAAW,GAAwB,CAAC;AAC5C,CAAC;AAFD,gCAEC;AAED;;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AAC;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,CAAC,+BAA+B;QAC7C,CAAC;aAAM,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;YAC1B,GAAG,GAAG,GAAG,CAAC,CAAC,iCAAiC;QAC7C,CAAC;aAAM,CAAC;YACP,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,gCAAgC;QAChD,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,qEAAqE;AACxF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype Brand,\n\ttype BrandedKey,\n\ttype BrandedMapSubset,\n\ttype Opaque,\n\tReferenceCountedBase,\n\tbrand,\n\tbrandedSlot,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n} from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { ITreeCursorSynchronous } from \"./cursor.js\";\nimport type * as Delta from \"./delta.js\";\nimport { offsetDetachId } from \"./deltaUtil.js\";\nimport {\n\tisDetachedUpPathRoot,\n\ttype INormalizedUpPath,\n\ttype NormalizedUpPath,\n\ttype PlaceIndex,\n\ttype Range,\n\ttype UpPath,\n} from \"./pathTree.js\";\nimport { EmptyKey } from \"./types.js\";\nimport type { DeltaVisitor } from \"./visitDelta.js\";\n\n/**\n * A way to refer to a particular tree location within an {@link AnchorSet}.\n * Associated with a ref count on the underlying {@link AnchorNode}.\n */\nexport type Anchor = Brand<number, \"rebaser.Anchor\">;\n\n/**\n * A singleton which represents a permanently invalid location (i.e. there is never a node there)\n */\nconst NeverAnchor: Anchor = brand(0);\n\n/**\n * Maps anchors (which must be ones this locator knows about) to paths.\n */\nexport interface AnchorLocator {\n\t/**\n\t * Get the current location of an Anchor.\n\t * The returned value should not be used after an edit has occurred.\n\t *\n\t * TODO: support extra/custom return types for specific/custom anchor types:\n\t * for now caller must rely on data in anchor + returned node location\n\t * (not ideal for anchors for places or ranges instead of nodes).\n\t */\n\tlocate(anchor: Anchor): AnchorNode | undefined;\n}\n\n/**\n * Stores arbitrary, user-defined data on an {@link Anchor}.\n * This data is preserved over the course of that anchor's lifetime.\n * @see {@link anchorSlot} for creation and an example use case.\n */\nexport type AnchorSlot<TContent> = BrandedKey<Opaque<Brand<number, \"AnchorSlot\">>, TContent>;\n\n/**\n * Events for {@link AnchorNode}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorEvents {\n\t/**\n\t * When the anchor node will never get reused by its AnchorSet.\n\t * This means that the content it corresponds to has been permanently destroyed.\n\t *\n\t * @remarks\n\t * When this happens depends entirely on how the anchorSet is used.\n\t * It's possible nodes removed from the tree will be kept indefinitely, and thus never trigger this event, or they may be discarded immediately.\n\t *\n\t * @privateRemarks\n\t * The specifics of the delta visit algorithm can impact the behavior of these events.\n\t * Refer to the privateRemarks of specific events and/or the documentation of the delta visit algorithm (as of\n\t * 2024-04-02, src/core/tree/visitDelta.ts) for more information.\n\t */\n\tafterDestroy(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children are about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t */\n\tchildrenChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t */\n\tchildrenChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if one or more of this node's\n\t * direct children changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChanged} which is emitted in the middle of the batch/delta-visit.\n\t */\n\tchildrenChangedAfterBatch(arg: {\n\t\tchangedFields: ReadonlySet<FieldKey>;\n\t}): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ be about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Called on every parent (transitively) when a change is occurring.\n\t */\n\tsubtreeChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ have just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * While this event is always emitted in the presence of changes to the subtree,\n\t * it may also be emitted even though no changes have been made to the subtree.\n\t * It may be emitted multiple times within the application of a single edit or transaction.\n\t *\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, at\n\t * least once on each ancestor.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t *\n\t * @privateRemarks\n\t * The delta visit algorithm is complicated and it may fire this event multiple times for the same change to a node.\n\t * The change to the tree may not be visible until the event fires for the last time.\n\t * Refer to the documentation of the delta visit algorithm for more details.\n\t */\n\tsubtreeChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if something in the subtree\n\t * rooted at `anchor` changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, from bottom to top.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChanged} which is emitted in the middle of the batch/delta-visit.\n\t *\n\t * @privateRemarks\n\t * Note that because this is fired after the full batch of changes is applied, it guarantees that something in the\n\t * subtree changed, compared to {@link AnchorEvents.subtreeChanged} or {@link AnchorEvents.subtreeChanging} which\n\t * fire when something _may_ have changed or _may_ be about to change.\n\t */\n\tsubtreeChangedAfterBatch(): void;\n}\n\n/**\n * Events for {@link AnchorSet}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Design how events should be ordered.\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorSetRootEvents {\n\t/**\n\t * What children are at the root is changing.\n\t */\n\tchildrenChanging(anchors: AnchorSet): void;\n\n\t/**\n\t * Something in the tree is changing.\n\t */\n\ttreeChanging(anchors: AnchorSet): void;\n}\n\n/**\n * Node in a tree of anchors.\n */\nexport interface AnchorNode extends INormalizedUpPath<AnchorNode> {\n\t/**\n\t * Events for this anchor node.\n\t */\n\treadonly events: Listenable<AnchorEvents> & HasListeners<AnchorEvents>;\n\n\t/**\n\t * Allows access to data stored on the Anchor in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t */\n\t// See note on BrandedKey\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly slots: BrandedMapSubset<AnchorSlot<any>>;\n\n\t/**\n\t * The set this anchor node is part of.\n\t */\n\treadonly anchorSet: AnchorSet;\n\n\t/**\n\t * Gets a child of this node.\n\t *\n\t * @remarks\n\t * This does not return an AnchorNode since there might not be one, and lazily creating one here would have messy lifetime management (See {@link AnchorNode#getOrCreateChildRef})\n\t * If an AnchorNode is required, use the AnchorSet to track then locate the returned path.\n\t * TODO:\n\t * Revisit this API.\n\t * Perhaps if we use weak down pointers and remove ref counting, we can make this return a AnchorNode.\n\t *\n\t */\n\tchild(key: FieldKey, index: number): UpPath<AnchorNode>;\n\n\t/**\n\t * Gets the child AnchorNode if already exists.\n\t *\n\t * Does NOT add a ref, so the returned AnchorNode must be used with care.\n\t */\n\tchildIfAnchored(key: FieldKey, index: number): AnchorNode | undefined;\n\n\t/**\n\t * Gets a child AnchorNode (creating it if needed), and an Anchor owning a ref to it.\n\t * Caller is responsible for freeing the returned Anchor, and must not use the AnchorNode after that.\n\t */\n\tgetOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode];\n}\n\n/**\n * Define a strongly typed slot on anchors in which data can be stored.\n *\n * @remarks\n * This is mainly useful for caching data associated with a location in the tree.\n *\n * Example usage:\n * ```typescript\n * const counterSlot = anchorSlot<number>();\n *\n * function useSlot(anchor: AnchorNode): void {\n * \tanchor.slots.set(counterSlot, 1 + anchor.slots.get(counterSlot) ?? 0);\n * }\n * ```\n */\nexport function anchorSlot<TContent>(): AnchorSlot<TContent> {\n\treturn brandedSlot<AnchorSlot<TContent>>();\n}\n\n/**\n * Collection of Anchors at a specific revision.\n *\n * See `Rebaser` for how to update across revisions.\n *\n * TODO: this should not be package exported.\n * If it's needed outside the package an Interface should be used instead which can reduce its\n * API surface to a small subset.\n *\n * @sealed\n */\nexport class AnchorSet implements AnchorLocator {\n\treadonly #events = createEmitter<AnchorSetRootEvents>();\n\tpublic readonly events: Listenable<AnchorSetRootEvents> = this.#events;\n\n\t/**\n\t * Incrementing counter to give each anchor in this set a unique index for its identifier.\n\t * \"0\" is reserved for the `NeverAnchor`.\n\t */\n\tprivate anchorCounter = 1;\n\n\t/**\n\t * Incrementing number that is bumped each time that the {@link AnchorSet} is changed.\n\t * This allows consumers to cache state associated with a particular generation number and later determine if that state may have been invalidated using a comparison with the current generation number.\n\t * For example, anchor slots can be used to cache the removal status of a node to memoize repeated walks up the tree.\n\t */\n\tpublic generationNumber = 0;\n\n\t/**\n\t * Special root node under which all anchors in this anchor set are transitively parented.\n\t * This does not appear in the UpPaths (instead they use undefined for the root).\n\t * Immediate children of this root are in detached fields (which have their identifiers used as the field keys).\n\t *\n\t * This is allocated with refCount one, which is never freed so it is never cleaned up\n\t * (as long as this AnchorSet is not garbage collected).\n\t *\n\t * There should never be any children other than the special root detached field under this between transactions:\n\t * TODO: check for and enforce this.\n\t */\n\tprivate readonly root = new PathNode(this, EmptyKey, 0, undefined);\n\n\t// TODO: anchor system could be optimized a bit to avoid the maps (Anchor is ref to Path, path has ref count).\n\t// For now use this more encapsulated approach with maps.\n\tprivate readonly anchorToPath: Map<Anchor, PathNode> = new Map();\n\n\tprivate activeVisitor?: DeltaVisitor;\n\n\tpublic constructor() {\n\t\tthis.events.on(\"treeChanging\", () => {\n\t\t\tthis.generationNumber += 1;\n\t\t});\n\t}\n\n\t/**\n\t * Allows access to data stored on the AnchorSet in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t *\n\t * @privateRemarks\n\t * This forwards to the slots of the special above root anchor which locate can't access.\n\t */\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic get slots(): BrandedMapSubset<AnchorSlot<any>> {\n\t\treturn this.root.slots;\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<AnchorNode> {\n\t\tconst stack: PathNode[] = [];\n\t\tlet node: PathNode | undefined = this.root;\n\t\twhile (node !== undefined) {\n\t\t\tyield node;\n\t\t\tfor (const [_, children] of node.children) {\n\t\t\t\tfor (const child of children) {\n\t\t\t\t\tstack.push(child);\n\t\t\t\t}\n\t\t\t}\n\t\t\tnode = stack.pop();\n\t\t}\n\t}\n\n\t/**\n\t * Check if there are currently no anchors tracked.\n\t * Mainly for testing anchor cleanup.\n\t */\n\tpublic isEmpty(): boolean {\n\t\treturn this.root.children.size === 0;\n\t}\n\n\tpublic locate(anchor: Anchor): AnchorNode | undefined {\n\t\tif (anchor === NeverAnchor) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst path = this.anchorToPath.get(anchor);\n\t\tassert(\n\t\t\tpath !== undefined,\n\t\t\t0x3a6 /* Cannot locate anchor which is not in this AnchorSet */,\n\t\t);\n\t\treturn path.status === Status.Alive ? path : undefined;\n\t}\n\n\tpublic forget(anchor: Anchor): void {\n\t\tif (anchor !== NeverAnchor) {\n\t\t\tconst path = this.anchorToPath.get(anchor);\n\t\t\tassert(path !== undefined, 0x351 /* cannot forget unknown Anchor */);\n\t\t\tpath.removeRef();\n\t\t\tthis.anchorToPath.delete(anchor);\n\t\t}\n\t}\n\n\t/**\n\t * TODO: Add APIs need to allow callers of this function to reduce copying here.\n\t * Ex: maybe return something extending UpPath here.\n\t * @param path - the path to the node to be tracked. If null, returns an anchor\n\t * which is permanently invalid.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic track(path: UpPath | null): Anchor {\n\t\tif (path === null) {\n\t\t\treturn NeverAnchor;\n\t\t}\n\n\t\tconst foundPath = this.trackInner(path);\n\t\tconst anchor: Anchor = brand(this.anchorCounter++);\n\t\tthis.anchorToPath.set(anchor, foundPath);\n\t\treturn anchor;\n\t}\n\n\t/**\n\t * Finds a path node, creating if needed, and adds a ref count to it.\n\t */\n\tprivate trackInner(path: UpPath): PathNode {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\tpath.addRef();\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.trackInner(parent);\n\n\t\tconst child = parentPath.getOrCreateChild(path.parentField, path.parentIndex);\n\n\t\t// Now that child is added (if needed), remove the extra ref that we added in the recursive call.\n\t\tparentPath.removeRef();\n\n\t\treturn child;\n\t}\n\n\t/**\n\t * Finds a path node if it already exists.\n\t *\n\t * Does not add a ref!\n\t */\n\tpublic find(path: UpPath): PathNode | undefined {\n\t\tif (path instanceof PathNode) {\n\t\t\tif (path.anchorSet === this) {\n\t\t\t\treturn path;\n\t\t\t}\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.find(parent);\n\t\treturn parentPath?.childIfAnchored(path.parentField, path.parentIndex);\n\t}\n\n\t/**\n\t * Returns an equivalent path making as much of it with PathNodes as possible.\n\t * This allows future operations (like find, track, locate) on this path (and derived ones) to be faster.\n\t * Note that the returned path may use AnchorNodes from this AnchorSet,\n\t * but does not have a tracked reference to them, so this should not be held onto across anything that might free an AnchorNode.\n\t *\n\t * @remarks\n\t * Also ensures that any PathNode in the path is from this AnchorSet.\n\t */\n\tpublic internalizePath(originalPath: UpPath): UpPath {\n\t\tlet path: UpPath | undefined = originalPath;\n\t\tconst stack: UpPath[] = [];\n\t\twhile (path !== undefined) {\n\t\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tstack.push(path);\n\t\t\tpath = path.parent;\n\t\t}\n\n\t\t// Now `path` contains an internalized path.\n\t\t// It just needs the paths from stackOut to wrap it.\n\n\t\tlet wrapWith: UpPath | undefined;\n\t\twhile ((wrapWith = stack.pop()) !== undefined) {\n\t\t\tif (path === undefined || path instanceof PathNode) {\n\t\t\t\t// If path already has an anchor, get an anchor for it's child if there is one:\n\t\t\t\tconst child = (path ?? this.root).childIfAnchored(\n\t\t\t\t\twrapWith.parentField,\n\t\t\t\t\twrapWith.parentIndex,\n\t\t\t\t);\n\t\t\t\tif (child !== undefined) {\n\t\t\t\t\tpath = child;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Replacing this if with a ternary makes the documentation harder to include and hurts readability.\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (path === wrapWith.parent && !(wrapWith instanceof PathNode)) {\n\t\t\t\t// path is safe to reuse from input path, so use it to avoid allocating another object.\n\t\t\t\tpath = wrapWith;\n\t\t\t} else {\n\t\t\t\tpath = {\n\t\t\t\t\tparent: path,\n\t\t\t\t\tparentField: wrapWith.parentField,\n\t\t\t\t\tparentIndex: wrapWith.parentIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn path ?? fail(0xaea /* internalize path must be a path */);\n\t}\n\n\t/**\n\t * Recursively marks the given `nodes` and their descendants as disposed and pointing to a deleted node.\n\t * Note that this does NOT detach the nodes.\n\t */\n\tprivate deepDelete(nodes: readonly PathNode[]): void {\n\t\tconst stack = [...nodes];\n\t\twhile (stack.length > 0) {\n\t\t\tconst node = stack.pop()!;\n\t\t\tassert(node.status === Status.Alive, 0x408 /* PathNode must be alive */);\n\t\t\tnode.status = Status.Dangling;\n\t\t\tnode.events.emit(\"afterDestroy\", node);\n\t\t\tfor (const children of node.children.values()) {\n\t\t\t\tstack.push(...children);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Decouple nodes from their parent.\n\t * This removes the reference from the parent to the decoupled children, and updates the indexes of the remaining children accordingly.\n\t * This does NOT update the decoupled children: both their index and parent are left at their existing values.\n\t * To decouple and fixup the children, see `removeChildren` and `moveChildren`.\n\t * @param startPath - The path to the first node that is being decoupled.\n\t * @param count - number of siblings that are decoupled from the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate decoupleNodes(startPath: UpPath, count: number): PathNode[] {\n\t\tassert(count > 0, 0x681 /* count must be positive */);\n\n\t\tconst sourceParent = this.find(startPath.parent ?? this.root);\n\t\tconst sourceChildren = sourceParent?.children?.get(startPath.parentField);\n\t\tlet nodes: PathNode[] = [];\n\n\t\tif (sourceChildren !== undefined) {\n\t\t\tlet numberBeforeDecouple = 0;\n\t\t\tlet numberToDecouple = 0;\n\t\t\tlet index = 0;\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex\n\t\t\t) {\n\t\t\t\tnumberBeforeDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex + count\n\t\t\t) {\n\t\t\t\tnumberToDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (index < sourceChildren.length) {\n\t\t\t\t// Fix indexes in source after moved items (subtract count).\n\t\t\t\tsourceChildren[index]!.parentIndex -= count;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\t// Sever the parent -> child connections\n\t\t\tnodes = sourceChildren.splice(numberBeforeDecouple, numberToDecouple);\n\t\t\tif (sourceChildren.length === 0) {\n\t\t\t\tsourceParent!.afterEmptyField(startPath.parentField);\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * Couple nodes to a parent.\n\t * @param destination - where the siblings are coupled to.\n\t * @param count - number of siblings that are coupled in the original tree.\n\t * @param coupleInfo - this object contains the nodes to couple and the parent index of the first node that is coupled in the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate coupleNodes(\n\t\tdestination: UpPath,\n\t\tcount: number,\n\t\tcoupleInfo: { startParentIndex: number; nodes: PathNode[] },\n\t): void {\n\t\tassert(coupleInfo.nodes.length > 0, 0x682 /* coupleInfo must have nodes to couple */);\n\n\t\t// The destination needs to be created if it does not exist yet.\n\t\tconst destinationPath = this.trackInner(destination.parent ?? this.root);\n\n\t\t// Update nodes for new parent.\n\t\tfor (const node of coupleInfo.nodes) {\n\t\t\tnode.parentIndex += destination.parentIndex - coupleInfo.startParentIndex;\n\t\t\tnode.parentPath = destinationPath;\n\t\t\tnode.parentField = destination.parentField;\n\t\t\t// If the destination is a detached root, propagate its detachedNodeId, otherwise remove any existing one\n\t\t\tnode.detachedNodeId = isDetachedUpPathRoot(destination)\n\t\t\t\t? offsetDetachId(\n\t\t\t\t\t\tdestination.detachedNodeId,\n\t\t\t\t\t\tnode.parentIndex - destination.parentIndex,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t}\n\n\t\t// Update new parent to add children\n\t\tconst field = destinationPath.children.get(destination.parentField);\n\t\tif (field === undefined) {\n\t\t\tdestinationPath.children.set(destination.parentField, coupleInfo.nodes);\n\t\t} else {\n\t\t\t// Update existing field contents\n\t\t\tconst numberBeforeCouple = this.increaseParentIndexes(\n\t\t\t\tfield,\n\t\t\t\tdestination.parentIndex,\n\t\t\t\tcount,\n\t\t\t);\n\n\t\t\t// TODO: this will fail for very large numbers of anchors due to argument limits.\n\t\t\tfield.splice(numberBeforeCouple, 0, ...coupleInfo.nodes);\n\t\t}\n\n\t\tdestinationPath.removeRef();\n\t}\n\n\t/**\n\t * Updates the parent indexes within `field` to account for `count` children being inserted at `fromParentIndex`. Note that\n\t * `fromParentIndex` is the logical position within the field, not the index with the sparse PathNode array.\n\t *\n\t * @param field - the field to update.\n\t * @param fromParentIndex - the logical index within the field to start updating from.\n\t * @param count - the number to increase parent indexes.\n\t * @returns the number of items in the field that are not increased.\n\t *\n\t * TODO: tests\n\t */\n\tprivate increaseParentIndexes(\n\t\tfield: PathNode[],\n\t\tfromParentIndex: number,\n\t\tcount: number,\n\t): number {\n\t\tlet index = 0;\n\t\twhile (index < field.length && field[index]!.parentIndex < fromParentIndex) {\n\t\t\tindex++;\n\t\t}\n\t\tconst numberBeforeIncrease = index;\n\t\twhile (index < field.length) {\n\t\t\tfield[index]!.parentIndex += count;\n\t\t\tindex++;\n\t\t}\n\n\t\treturn numberBeforeIncrease;\n\t}\n\n\t/**\n\t * Updates paths for a range move (including re-parenting path items and updating indexes).\n\t * @param sourceStart - where the siblings are removed from.\n\t * @param destination - where the siblings are moved to.\n\t * @param count - number of siblings to move.\n\t *\n\t * TODO:\n\t * How should anchors that become invalid, then valid again (ex: into content that was deleted, then undone) work?\n\t * Add an API to resurrect them? Store them in special detached fields? Store them in special non-detached fields?\n\t *\n\t * TODO:\n\t * How should custom anchors work (ex: ones not just tied to a specific Node)?\n\t * This design assumes they can be expressed in terms of a Node anchor + some extra stuff,\n\t * but we don't have an API for the extra stuff yet.\n\t *\n\t * TODO: tests\n\t */\n\tprivate moveChildren(sourceStart: UpPath, destination: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(sourceStart, count);\n\t\tif (nodes.length > 0) {\n\t\t\tthis.coupleNodes(destination, count, {\n\t\t\t\tstartParentIndex: sourceStart.parentIndex,\n\t\t\t\tnodes,\n\t\t\t});\n\t\t} else {\n\t\t\t// If there are no nodes to move, we still need to update the parent indexes of the nodes\n\t\t\t// affected in the move in.\n\t\t\tthis.offsetChildren(destination, count);\n\t\t}\n\t}\n\n\tprivate removeChildren(path: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(path, count);\n\t\tthis.deepDelete(nodes);\n\t}\n\n\t/**\n\t * Updates the parent indexes of all the nodes located at right side of the given path by the given offset.\n\t * @param firstSiblingToOffset - the path to offset children of.\n\t * @param offset - the offset to apply to the children.\n\t *\n\t */\n\tprivate offsetChildren(firstSiblingToOffset: UpPath, offset: number): void {\n\t\tconst nodePath = this.find(firstSiblingToOffset.parent ?? this.root);\n\t\tconst field = nodePath?.children.get(firstSiblingToOffset.parentField);\n\t\tif (field !== undefined) {\n\t\t\tthis.increaseParentIndexes(field, firstSiblingToOffset.parentIndex, offset);\n\t\t}\n\t}\n\n\t/**\n\t * Provides a visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @returns A visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @remarks\n\t * Mutating the {@link AnchorSet} does NOT update the forest.\n\t * The visitor must be released after use by calling {@link DeltaVisitor.free} on it.\n\t * It is invalid to acquire a visitor without releasing the previous one,\n\t * and this method will throw an error if this is attempted.\n\t */\n\tpublic acquireVisitor(): DeltaVisitor {\n\t\tassert(\n\t\t\tthis.activeVisitor === undefined,\n\t\t\t0x767 /* Must release existing visitor before acquiring another */,\n\t\t);\n\n\t\tconst referencedPathNodes: PathNode[] = [];\n\t\tconst visitor = {\n\t\t\tanchorSet: this,\n\t\t\t// Run `withNode` on anchorNode for parent if there is such an anchorNode.\n\t\t\t// If at root, run `withRoot` instead.\n\t\t\tmaybeWithNode(withNode: (anchorNode: PathNode) => void, withRoot?: () => void) {\n\t\t\t\tif (this.parent === undefined && withRoot !== undefined) {\n\t\t\t\t\twithRoot();\n\t\t\t\t} else {\n\t\t\t\t\tassert(this.parent !== undefined, 0x5b0 /* parent must exist */);\n\t\t\t\t\t// TODO:Perf:\n\t\t\t\t\t// When traversing to a depth D when there are not anchors in that subtree, this goes O(D^2).\n\t\t\t\t\t// Delta traversal should early out in this case because no work is needed (and all move outs are known to not contain anchors).\n\t\t\t\t\tthis.parent = this.anchorSet.internalizePath(this.parent);\n\t\t\t\t\tif (this.parent instanceof PathNode) {\n\t\t\t\t\t\tthis.parent.addRef();\n\t\t\t\t\t\treferencedPathNodes.push(this.parent);\n\t\t\t\t\t\twithNode(this.parent);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tparentField: undefined as FieldKey | undefined,\n\t\t\tparent: undefined as UpPath | undefined,\n\n\t\t\t/**\n\t\t\t * Events collected during the visit which get sent as a batch during \"free\".\n\t\t\t */\n\t\t\tbufferedEvents: [] as BufferedEvent[],\n\n\t\t\t/**\n\t\t\t * 'currentDepth' and 'depthThresholdForSubtreeChanged' serve to keep track of when do we need to emit\n\t\t\t * subtreeChangedAfterBatch events.\n\t\t\t * The algorithm works as follows:\n\t\t\t *\n\t\t\t * - Initialize both to 0.\n\t\t\t * - As we walk the tree from the root towards the leaves, when we enter a node increment currentDepth by 1.\n\t\t\t * - When we edit a node, set depthThresholdForSubtreeChanged = currentDepth.\n\t\t\t * Intuitively, depthThresholdForSubtreeChanged means \"as you walk the tree towards the root, when you exit a\n\t\t\t * node at this depth you should emit a subtreeChangedAfterBatch event\".\n\t\t\t * - When we exit a node, if d === currentDepth then emit a subtreeChangedAfterBatch and decrement d by 1.\n\t\t\t * Then decrement currentDepth unconditionally.\n\t\t\t *\n\t\t\t * Note that the event will be emitted when exiting a node that was edited (depthThresholdForSubtreeChanged will\n\t\t\t * have been set to the current depth when the edit happened), it will be emitted when exiting a node that is the\n\t\t\t * parent of a node that already emitted the event (because both depthThresholdForSubtreeChanged and currentDepth\n\t\t\t * get decremented when exiting a node so they stay in sync), and if we're already emitting the event but start\n\t\t\t * walking the tree back towards the leaves in a path where no edits happen, currentDepth will be increased again\n\t\t\t * as we walk that path, depthThresholdForSubtreeChanged will not, and thus no event will be emitted when walking\n\t\t\t * back up that path, until we get back to the depth where we were already emitting the event, and will continue\n\t\t\t * emitting it on the way to the root.\n\t\t\t */\n\t\t\tcurrentDepth: 0,\n\t\t\t/**\n\t\t\t * See {@link visitor.currentDepth}.\n\t\t\t */\n\t\t\tdepthThresholdForSubtreeChanged: 0,\n\n\t\t\tfree() {\n\t\t\t\tassert(\n\t\t\t\t\tthis.anchorSet.activeVisitor !== undefined,\n\t\t\t\t\t0x768 /* Multiple free calls for same visitor */,\n\t\t\t\t);\n\t\t\t\tfor (const node of referencedPathNodes) {\n\t\t\t\t\tnode.removeRef();\n\t\t\t\t}\n\t\t\t\tthis.anchorSet.activeVisitor = undefined;\n\n\t\t\t\t// Aggregate changedFields by node.\n\t\t\t\tconst eventsByNode: Map<PathNode, Set<FieldKey>> = new Map();\n\t\t\t\tfor (const { node, event, changedField } of this.bufferedEvents) {\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst keys = getOrCreate(eventsByNode, node, () => new Set());\n\t\t\t\t\t\tkeys.add(\n\t\t\t\t\t\t\tchangedField ??\n\t\t\t\t\t\t\t\tfail(0xb57 /* childrenChangedAfterBatch events should have a changedField */),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst alreadyEmitted = new Map<PathNode, (keyof AnchorEvents)[]>();\n\t\t\t\tfor (const { node, event } of this.bufferedEvents) {\n\t\t\t\t\tconst emittedEvents = getOrAddEmptyToMap(alreadyEmitted, node);\n\t\t\t\t\tif (emittedEvents.includes(event)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\temittedEvents.push(event);\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst changedFields =\n\t\t\t\t\t\t\teventsByNode.get(node) ??\n\t\t\t\t\t\t\tfail(0xaeb /* childrenChangedAfterBatch events should have changedFields */);\n\t\t\t\t\t\tnode.events.emit(event, { changedFields });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.events.emit(event);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotifyChildrenChanging(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => p.events.emit(\"childrenChanging\", p),\n\t\t\t\t\t() => this.anchorSet.#events.emit(\"childrenChanging\", this.anchorSet),\n\t\t\t\t);\n\t\t\t},\n\t\t\tnotifyChildrenChanged(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t\t\t0xa24 /* Must be in a field to modify its contents */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tp.events.emit(\"childrenChanged\", p);\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"childrenChangedAfterBatch\",\n\t\t\t\t\t\t\tchangedField: this.parentField,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t},\n\t\t\tattach(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.attachEdit(source, count, destination);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tattachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a2 /* Must be in a field in order to attach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: source,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t};\n\t\t\t\tconst destinationPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: destination,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, count);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\tdetach(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(source, destination, detachedNodeId);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdetachEdit(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a5 /* Must be in a field in order to detach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath: UpPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: source.start,\n\t\t\t\t};\n\t\t\t\tconst destinationPath: NormalizedUpPath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: destination,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\tdetachedNodeId,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, source.end - source.start);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\treplace(\n\t\t\t\tnewContentSource: FieldKey,\n\t\t\t\trange: Range,\n\t\t\t\toldContentDestination: FieldKey,\n\t\t\t\tdestinationDetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(range, oldContentDestination, destinationDetachedNodeId);\n\t\t\t\tthis.attachEdit(newContentSource, range.end - range.start, range.start);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdestroy(detachedField: FieldKey, count: number): void {\n\t\t\t\tthis.anchorSet.removeChildren(\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t\tparentField: detachedField,\n\t\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\t},\n\t\t\t\t\tcount,\n\t\t\t\t);\n\t\t\t},\n\t\t\tcreate(content: ITreeCursorSynchronous[], destination: FieldKey): void {\n\t\t\t\t// Nothing to do since content can only be created in a new detached field,\n\t\t\t\t// which cannot contain any anchors.\n\t\t\t},\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(this.parentField !== undefined, 0x3ab /* Must be in a field to enter node */);\n\n\t\t\t\tthis.parent = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: index,\n\t\t\t\t};\n\t\t\t\tthis.parentField = undefined;\n\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\tp.events.emit(\"subtreeChanging\", p);\n\t\t\t\t});\n\t\t\t\tthis.currentDepth++;\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(this.parent !== undefined, 0x3ac /* Must have parent node */);\n\t\t\t\tif (this.depthThresholdForSubtreeChanged === this.currentDepth) {\n\t\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\t\tp.events.emit(\"subtreeChanged\", p);\n\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"subtreeChangedAfterBatch\",\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tthis.depthThresholdForSubtreeChanged--;\n\t\t\t\t}\n\t\t\t\tconst parent = this.parent;\n\t\t\t\tthis.parentField = parent.parentField;\n\t\t\t\tthis.parent = parent.parent;\n\t\t\t\tthis.currentDepth--;\n\t\t\t},\n\t\t\tenterField(key: FieldKey): void {\n\t\t\t\tthis.parentField = key;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tthis.parentField = undefined;\n\t\t\t},\n\t\t};\n\t\tthis.#events.emit(\"treeChanging\", this);\n\t\tthis.activeVisitor = visitor;\n\t\treturn visitor;\n\t}\n}\n\n/**\n * Indicates the status of a `NodePath`.\n */\nenum Status {\n\t/**\n\t * Indicates the `NodePath` is being maintained and corresponds to a valid\n\t * (i.e., not removed) node in the document.\n\t */\n\tAlive,\n\t/**\n\t * Indicates the `NodePath` is not being maintained by the `AnchorSet`.\n\t * The `NodePath` may or may not correspond to a valid node in the document.\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDisposed,\n\t/**\n\t * Indicates the `NodePath` corresponds to a removed node in the document.\n\t * Such `NodePath`s are not maintained by the `AnchorSet` (other than updating\n\t * their status to `Disposed` when appropriate).\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDangling,\n}\n\n/**\n * Tree of anchors.\n *\n * Contains both child and parent pointers, which are kept in sync.\n *\n * Each anchor is equivalent to a path through the tree.\n * This tree structure stores a collection of these paths, but deduplicating the common prefixes of the tree\n * prefix-tree style.\n *\n * These anchors are used instead of just holding onto the node objects in forests for several reasons:\n *\n * - Update policy might be more complex than just tracking a node object in the forest.\n *\n * - Not all forests will have node objects: some may use compressed binary formats with no objects to reference.\n *\n * - Anchors are needed even when not using forests, and for nodes that are outside the currently loaded part of the\n * forest.\n *\n * - Forest in general do not need to support up pointers, but they are needed for anchors.\n *\n * Thus this can be thought of as a sparse copy of the subset of trees which are used as anchors,\n * plus the parent paths for them.\n *\n * ReferenceCountedBase tracks the number of references to this from external sources (`Anchors` via `AnchorSet`.).\n * Kept alive as if any of the follow are true:\n * 1. there are children.\n * 2. refcount is non-zero.\n * 3. events are registered.\n */\nclass PathNode extends ReferenceCountedBase implements AnchorNode {\n\tpublic status: Status = Status.Alive;\n\t/**\n\t * Event emitter for this anchor.\n\t */\n\tpublic readonly events = createEmitter<AnchorEvents>(() => this.considerDispose());\n\n\t/**\n\t * PathNode arrays are kept sorted the PathNode's parentIndex for efficient search.\n\t * Users of this field must take care to maintain invariants (correct parent pointers, not empty child arrays etc.)\n\t *\n\t * Performance Note:\n\t * Large child lists could be updated more efficiently here using a data-structure optimized\n\t * for efficient prefix sum updates, such as a Fenwick tree or Finger tree.\n\t * This would be complicated by the need for parent pointers (including indexes),\n\t * but is possible to do.\n\t */\n\tpublic readonly children: Map<FieldKey, PathNode[]> = new Map();\n\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic readonly slots: BrandedMapSubset<AnchorSlot<any>> = new Map();\n\n\t/**\n\t * {@inheritdoc UpPath.detachedNodeId}\n\t */\n\tpublic detachedNodeId: Delta.DetachedNodeId | undefined;\n\n\t/**\n\t * Construct a PathNode with refcount 1.\n\t * @param anchorSet - used to determine if this PathNode is already part of a specific anchorSet\n\t * to early out UpPath walking.\n\t */\n\tpublic constructor(\n\t\tpublic readonly anchorSet: AnchorSet,\n\t\tpublic parentField: FieldKey,\n\t\tpublic parentIndex: number,\n\t\t/**\n\t\t * The parent of this `PathNode` (an up pointer in the `PathNode` tree).\n\t\t * If the status of this node is `Alive`, then there must be a corresponding down pointer from the\n\t\t * `parentPath` node to this node.\n\t\t * When undefined, this node is the {@link AnchorSet.root} for `this.anchorSet` and thus has no parent.\n\t\t *\n\t\t * When updating the tree, `AnchorSet` may transiently leave the up and down pointers inconsistent\n\t\t * (updating down pointers first), but must ensure they are consistent before the editing operation returns\n\t\t * to non-`AnchorSet` code.\n\t\t * This consistency guarantee only applies to nodes that are `Alive`.\n\t\t */\n\t\tpublic parentPath: PathNode | undefined,\n\t) {\n\t\tsuper(1);\n\t}\n\n\tpublic child(key: FieldKey, index: number): UpPath<AnchorNode> {\n\t\t// Fast path: if child exists, return it.\n\t\treturn (\n\t\t\tthis.childIfAnchored(key, index) ?? {\n\t\t\t\tparent: this,\n\t\t\t\tparentField: key,\n\t\t\t\tparentIndex: index,\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic getOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode] {\n\t\tconst anchor = this.anchorSet.track(this.child(key, index));\n\t\tconst node =\n\t\t\tthis.anchorSet.locate(anchor) ??\n\t\t\tfail(0xaec /* cannot reference child that does not exist */);\n\t\treturn [anchor, node];\n\t}\n\n\t/**\n\t * Whether or not this `PathNode` is the special root node that sits above all the detached fields.\n\t * @remarks\n\t * In this case, the fields are detached sequences.\n\t * Note that the special root node should never appear in an UpPath\n\t * since UpPaths represent this root as `undefined`.\n\t */\n\tprivate isRoot(): boolean {\n\t\treturn this.parentPath === undefined;\n\t}\n\n\tpublic get parent(): PathNode | undefined {\n\t\tassert(this.status !== Status.Disposed, 0x409 /* PathNode must not be disposed */);\n\t\tassert(\n\t\t\tthis.parentPath !== undefined,\n\t\t\t0x355 /* PathNode.parent is an UpPath API and thus should never be called on the root PathNode. */,\n\t\t);\n\t\t// Root PathNode corresponds to the undefined root for UpPath API.\n\t\tif (this.parentPath.isRoot()) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.parentPath;\n\t}\n\n\tpublic addRef(count = 1): void {\n\t\tassert(this.status === Status.Alive, 0x40a /* PathNode must be alive */);\n\t\tthis.referenceAdded(count);\n\t}\n\n\tpublic removeRef(count = 1): void {\n\t\tassert(this.status !== Status.Disposed, 0x40b /* PathNode must not be disposed */);\n\t\tthis.referenceRemoved(count);\n\t}\n\n\t// Called when refcount is set to 0.\n\t// Node may be kept alive by children or events after this point.\n\tprotected onUnreferenced(): void {\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * Gets a child, adding a ref to it.\n\t * Creates child (with 1 ref) if needed.\n\t */\n\tpublic getOrCreateChild(key: FieldKey, index: number): PathNode {\n\t\tassert(this.status === Status.Alive, 0x40c /* PathNode must be alive */);\n\t\tlet field = this.children.get(key);\n\t\tif (field === undefined) {\n\t\t\tfield = [];\n\t\t\tthis.children.set(key, field);\n\t\t}\n\t\tlet child = binaryFind(field, index);\n\t\tif (child === undefined) {\n\t\t\tchild = new PathNode(this.anchorSet, key, index, this);\n\t\t\tfield.push(child);\n\t\t\t// Keep list sorted by index.\n\t\t\tfield.sort((a, b) => a.parentIndex - b.parentIndex);\n\t\t} else {\n\t\t\tchild.addRef();\n\t\t}\n\t\treturn child;\n\t}\n\n\tpublic childIfAnchored(key: FieldKey, index: number): PathNode | undefined {\n\t\tassert(this.status === Status.Alive, 0x40d /* PathNode must be alive */);\n\t\tconst field = this.children.get(key);\n\n\t\treturn field === undefined ? undefined : binaryFind(field, index);\n\t}\n\n\t/**\n\t * Removes reference from this to `child`.\n\t * Since PathNodes are doubly linked,\n\t * the caller must ensure that the reference from child to parent is also removed (or the child is no longer used).\n\t */\n\tpublic removeChild(child: PathNode): void {\n\t\tassert(this.status === Status.Alive, 0x40e /* PathNode must be alive */);\n\t\tconst key = child.parentField;\n\t\tconst field = this.children.get(key);\n\t\t// TODO: should do more optimized search (ex: binary search or better) using child.parentIndex()\n\t\t// Note that this is the index in the list of child paths, not the index within the field\n\t\tconst childIndex = field?.indexOf(child) ?? -1;\n\t\tassert(childIndex !== -1, 0x35c /* child must be parented to be removed */);\n\t\tfield?.splice(childIndex, 1);\n\t\tif (field?.length === 0) {\n\t\t\tthis.afterEmptyField(key);\n\t\t}\n\t}\n\n\t/**\n\t * Call this after directly editing the child array for a field to be empty.\n\t * Handles cleaning up unneeded data\n\t * (like the field in the map, and possibly this entire PathNode and its parents if they are no longer needed.)\n\t */\n\tpublic afterEmptyField(key: FieldKey): void {\n\t\tassert(this.status === Status.Alive, 0x40f /* PathNode must be alive */);\n\t\tthis.children.delete(key);\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * If node is no longer needed (has no references, no children and no events):\n\t * removes this from parent if alive, and sets this to disposed.\n\t * Must only be called when .\n\t *\n\t * Allowed when dangling (but not when disposed).\n\t */\n\tprivate considerDispose(): void {\n\t\tassert(this.status !== Status.Disposed, 0x41d /* PathNode must not be disposed */);\n\t\tif (this.isUnreferenced() && this.children.size === 0 && !this.events.hasListeners()) {\n\t\t\tif (this.status === Status.Alive) {\n\t\t\t\tthis.parentPath?.removeChild(this);\n\t\t\t}\n\t\t\tthis.status = Status.Disposed;\n\t\t}\n\t}\n}\n\n/**\n * Find a child PathNode by index using a binary search.\n * @param sorted - array of PathNode's sorted by parentIndex.\n * @param index - index being looked for.\n * @returns child with the requested parentIndex, or undefined.\n * @privateRemarks\n * This function is very commonly used with small arrays (length 0 or one for all non sequence fields),\n * and is currently a hot path due to how flex tree leaves to excessive cursor to anchor and anchor to cursor translations,\n * both of which walk paths down the AnchorSet.\n * Additionally current usages tends to fully populate the anchor tree leading the correct array index to be the requested parent index.\n * This makes the performance of this performance both important in small cases and easy to overly tune to the current usage patterns.\n * This lead to not implementing a general purpose reusable binary search.\n * Once this function is not so heavily overused due to inefficient patterns in flex-tree,\n * replacing it with a standard binary search is likely fine.\n * Until then, care and benchmarking should be used when messing with this function.\n */\nfunction binaryFind(sorted: readonly PathNode[], index: number): PathNode | undefined {\n\t// Try guessing the list is not sparse as a starter:\n\tconst guess = sorted[index];\n\tif (guess !== undefined && guess.parentIndex === index) {\n\t\treturn guess;\n\t}\n\n\t// inclusive\n\tlet min = 0;\n\t// exclusive\n\tlet max = sorted.length;\n\n\twhile (min !== max) {\n\t\tconst mid = Math.floor((min + max) / 2);\n\t\tconst item = sorted[mid]!;\n\t\tconst found = item.parentIndex;\n\t\tif (found === index) {\n\t\t\treturn item; // Found the target, return it.\n\t\t} else if (found > index) {\n\t\t\tmax = mid; // Continue search on lower half.\n\t\t} else {\n\t\t\tmin = mid + 1; // Continue search on left half.\n\t\t}\n\t}\n\treturn undefined; // If we reach here, target is not in array (or array was not sorted)\n}\n\ninterface BufferedEvent {\n\tnode: PathNode;\n\tevent: keyof AnchorEvents;\n\t/**\n\t * The key for the impacted field, if the event is associated with a key.\n\t * Some events, such as afterDestroy, do not involve a key, and thus leave this undefined.\n\t */\n\tchangedField?: FieldKey;\n}\n"]}
1
+ {"version":3,"file":"anchorSet.js","sourceRoot":"","sources":["../../../src/core/tree/anchorSet.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,6DAA6D;AAE7D,+DAA6D;AAE7D,kEAAmE;AAEnE,kDAU6B;AAK7B,iDAAgD;AAChD,+CAOuB;AACvB,yCAAsC;AAStC;;GAEG;AACH,MAAM,WAAW,GAAW,IAAA,gBAAK,EAAC,CAAC,CAAC,CAAC;AA+MrC;;;;;;;;;;;;;;GAcG;AACH,SAAgB,UAAU;IACzB,OAAO,IAAA,sBAAW,GAAwB,CAAC;AAC5C,CAAC;AAFD,gCAEC;AAED;;;;;;;;;;GAUG;AACH,MAAa,SAAS;IAoCrB;QAnCS,4BAAU,IAAA,4BAAa,GAAuB,EAAC;QACxC,WAAM,GAAoC,uBAAA,IAAI,yBAAQ,CAAC;QAEvE;;;WAGG;QACK,kBAAa,GAAG,CAAC,CAAC;QAE1B;;;;WAIG;QACI,qBAAgB,GAAG,CAAC,CAAC;QAE5B;;;;;;;;;;WAUG;QACc,SAAI,GAAG,IAAI,QAAQ,CAAC,IAAI,EAAE,mBAAQ,EAAE,CAAC,EAAE,SAAS,CAAC,CAAC;QAEnE,8GAA8G;QAC9G,yDAAyD;QACxC,iBAAY,GAA0B,IAAI,GAAG,EAAE,CAAC;QAKhE,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,cAAc,EAAE,GAAG,EAAE;YACnC,IAAI,CAAC,gBAAgB,IAAI,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;IACJ,CAAC;IAED;;;;;;OAMG;IACH,0BAA0B;IAC1B,8DAA8D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MAAM,CAAC,QAAQ,CAAC;QAC/B,CAAC;IACF,CAAC;CACD;AAED;;;;;;;;;;;;;;;GAeG;AACH,SAAS,UAAU,CAAC,MAA2B,EAAE,KAAa;IAC7D,oDAAoD;IACpD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5B,IAAI,KAAK,KAAK,SAAS,IAAI,KAAK,CAAC,WAAW,KAAK,KAAK,EAAE,CAAC;QACxD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,YAAY;IACZ,IAAI,GAAG,GAAG,CAAC,CAAC;IACZ,YAAY;IACZ,IAAI,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC;IAExB,OAAO,GAAG,KAAK,GAAG,EAAE,CAAC;QACpB,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC;QACxC,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAE,CAAC;QAC1B,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC;QAC/B,IAAI,KAAK,KAAK,KAAK,EAAE,CAAC;YACrB,OAAO,IAAI,CAAC,CAAC,+BAA+B;QAC7C,CAAC;aAAM,IAAI,KAAK,GAAG,KAAK,EAAE,CAAC;YAC1B,GAAG,GAAG,GAAG,CAAC,CAAC,iCAAiC;QAC7C,CAAC;aAAM,CAAC;YACP,GAAG,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,gCAAgC;QAChD,CAAC;IACF,CAAC;IACD,OAAO,SAAS,CAAC,CAAC,qEAAqE;AACxF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\n/* eslint-disable @typescript-eslint/no-non-null-assertion */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { HasListeners, Listenable } from \"@fluidframework/core-interfaces/internal\";\nimport { assert, fail } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype Brand,\n\ttype BrandedKey,\n\ttype BrandedMapSubset,\n\ttype Opaque,\n\tReferenceCountedBase,\n\tbrand,\n\tbrandedSlot,\n\tgetOrAddEmptyToMap,\n\tgetOrCreate,\n} from \"../../util/index.js\";\nimport type { FieldKey } from \"../schema-stored/index.js\";\n\nimport type { ITreeCursorSynchronous } from \"./cursor.js\";\nimport type * as Delta from \"./delta.js\";\nimport { offsetDetachId } from \"./deltaUtil.js\";\nimport {\n\tisDetachedUpPathRoot,\n\ttype INormalizedUpPath,\n\ttype NormalizedUpPath,\n\ttype PlaceIndex,\n\ttype Range,\n\ttype UpPath,\n} from \"./pathTree.js\";\nimport { EmptyKey } from \"./types.js\";\nimport type { DeltaVisitor } from \"./visitDelta.js\";\n\n/**\n * A way to refer to a particular tree location within an {@link AnchorSet}.\n * Associated with a ref count on the underlying {@link AnchorNode}.\n */\nexport type Anchor = Brand<number, \"rebaser.Anchor\">;\n\n/**\n * A singleton which represents a permanently invalid location (i.e. there is never a node there)\n */\nconst NeverAnchor: Anchor = brand(0);\n\n/**\n * Maps anchors (which must be ones this locator knows about) to paths.\n */\nexport interface AnchorLocator {\n\t/**\n\t * Get the current location of an Anchor.\n\t * The returned value should not be used after an edit has occurred.\n\t *\n\t * TODO: support extra/custom return types for specific/custom anchor types:\n\t * for now caller must rely on data in anchor + returned node location\n\t * (not ideal for anchors for places or ranges instead of nodes).\n\t */\n\tlocate(anchor: Anchor): AnchorNode | undefined;\n}\n\n/**\n * Stores arbitrary, user-defined data on an {@link Anchor}.\n * This data is preserved over the course of that anchor's lifetime.\n * @see {@link anchorSlot} for creation and an example use case.\n */\nexport type AnchorSlot<TContent> = BrandedKey<Opaque<Brand<number, \"AnchorSlot\">>, TContent>;\n\n/**\n * Events for {@link AnchorNode}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorEvents {\n\t/**\n\t * When the anchor node will never get reused by its AnchorSet.\n\t * This means that the content it corresponds to has been permanently destroyed.\n\t *\n\t * @remarks\n\t * When this happens depends entirely on how the anchorSet is used.\n\t * It's possible nodes removed from the tree will be kept indefinitely, and thus never trigger this event, or they may be discarded immediately.\n\t *\n\t * @privateRemarks\n\t * The specifics of the delta visit algorithm can impact the behavior of these events.\n\t * Refer to the privateRemarks of specific events and/or the documentation of the delta visit algorithm (as of\n\t * 2024-04-02, src/core/tree/visitDelta.ts) for more information.\n\t */\n\tafterDestroy(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children are about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t */\n\tchildrenChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if one or more of this node's\n\t * direct children just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t */\n\tchildrenChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if one or more of this node's\n\t * direct children changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * Does not include edits of child subtrees: instead only includes changes to nodes which are direct children in this\n\t * node's fields.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.childrenChanged} which is emitted in the middle of the batch/delta-visit.\n\t */\n\tchildrenChangedAfterBatch(arg: {\n\t\tchangedFields: ReadonlySet<FieldKey>;\n\t}): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ be about to change due to updates from the batch.\n\t *\n\t * @remarks\n\t * Called on every parent (transitively) when a change is occurring.\n\t */\n\tsubtreeChanging(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted in the middle of applying a batch of changes (i.e. during a delta a visit), if something in the subtree\n\t * rooted at `anchor` _may_ have just changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * While this event is always emitted in the presence of changes to the subtree,\n\t * it may also be emitted even though no changes have been made to the subtree.\n\t * It may be emitted multiple times within the application of a single edit or transaction.\n\t *\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, at\n\t * least once on each ancestor.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChangedAfterBatch} which is emitted after the whole batch has been applied.\n\t *\n\t * @privateRemarks\n\t * The delta visit algorithm is complicated and it may fire this event multiple times for the same change to a node.\n\t * The change to the tree may not be visible until the event fires for the last time.\n\t * Refer to the documentation of the delta visit algorithm for more details.\n\t */\n\tsubtreeChanged(anchor: AnchorNode): void;\n\n\t/**\n\t * Emitted after a batch of changes has been applied (i.e. when a delta visit completes), if something in the subtree\n\t * rooted at `anchor` changed due to updates from the batch.\n\t *\n\t * @remarks\n\t * If this event is emitted by a node, it will later be emitted by all its ancestors up to the root as well, from bottom to top.\n\t *\n\t * This event is guaranteed to be emitted on a given node only once per batch.\n\t *\n\t * Compare to {@link AnchorEvents.subtreeChanged} which is emitted in the middle of the batch/delta-visit.\n\t *\n\t * @privateRemarks\n\t * Note that because this is fired after the full batch of changes is applied, it guarantees that something in the\n\t * subtree changed, compared to {@link AnchorEvents.subtreeChanged} or {@link AnchorEvents.subtreeChanging} which\n\t * fire when something _may_ have changed or _may_ be about to change.\n\t */\n\tsubtreeChangedAfterBatch(): void;\n}\n\n/**\n * Events for {@link AnchorSet}.\n * These events are triggered while the internal data structures are being updated.\n * Thus these events must not trigger reading of the anchorSet or forest.\n *\n * TODO:\n * - Design how events should be ordered.\n * - Include sub-deltas in events.\n * - Add more events.\n */\nexport interface AnchorSetRootEvents {\n\t/**\n\t * What children are at the root is changing.\n\t */\n\tchildrenChanging(anchors: AnchorSet): void;\n\n\t/**\n\t * Something in the tree is changing.\n\t */\n\ttreeChanging(anchors: AnchorSet): void;\n}\n\n/**\n * Node in a tree of anchors.\n */\nexport interface AnchorNode extends INormalizedUpPath<AnchorNode> {\n\t/**\n\t * Events for this anchor node.\n\t */\n\treadonly events: Listenable<AnchorEvents> & HasListeners<AnchorEvents>;\n\n\t/**\n\t * Allows access to data stored on the Anchor in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t */\n\t// See note on BrandedKey\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\treadonly slots: BrandedMapSubset<AnchorSlot<any>>;\n\n\t/**\n\t * The set this anchor node is part of.\n\t */\n\treadonly anchorSet: AnchorSet;\n\n\t/**\n\t * Gets a child of this node.\n\t *\n\t * @remarks\n\t * This does not return an AnchorNode since there might not be one, and lazily creating one here would have messy lifetime management (See {@link AnchorNode#getOrCreateChildRef})\n\t * If an AnchorNode is required, use the AnchorSet to track then locate the returned path.\n\t * TODO:\n\t * Revisit this API.\n\t * Perhaps if we use weak down pointers and remove ref counting, we can make this return a AnchorNode.\n\t *\n\t */\n\tchild(key: FieldKey, index: number): UpPath<AnchorNode>;\n\n\t/**\n\t * Gets the child AnchorNode if already exists.\n\t *\n\t * Does NOT add a ref, so the returned AnchorNode must be used with care.\n\t */\n\tchildIfAnchored(key: FieldKey, index: number): AnchorNode | undefined;\n\n\t/**\n\t * Gets a child AnchorNode (creating it if needed), and an Anchor owning a ref to it.\n\t * Caller is responsible for freeing the returned Anchor, and must not use the AnchorNode after that.\n\t */\n\tgetOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode];\n}\n\n/**\n * Define a strongly typed slot on anchors in which data can be stored.\n *\n * @remarks\n * This is mainly useful for caching data associated with a location in the tree.\n *\n * Example usage:\n * ```typescript\n * const counterSlot = anchorSlot<number>();\n *\n * function useSlot(anchor: AnchorNode): void {\n * \tanchor.slots.set(counterSlot, 1 + anchor.slots.get(counterSlot) ?? 0);\n * }\n * ```\n */\nexport function anchorSlot<TContent>(): AnchorSlot<TContent> {\n\treturn brandedSlot<AnchorSlot<TContent>>();\n}\n\n/**\n * Collection of Anchors at a specific revision.\n *\n * See `Rebaser` for how to update across revisions.\n *\n * TODO: this should not be package exported.\n * If it's needed outside the package an Interface should be used instead which can reduce its\n * API surface to a small subset.\n *\n * @sealed\n */\nexport class AnchorSet implements AnchorLocator {\n\treadonly #events = createEmitter<AnchorSetRootEvents>();\n\tpublic readonly events: Listenable<AnchorSetRootEvents> = this.#events;\n\n\t/**\n\t * Incrementing counter to give each anchor in this set a unique index for its identifier.\n\t * \"0\" is reserved for the `NeverAnchor`.\n\t */\n\tprivate anchorCounter = 1;\n\n\t/**\n\t * Incrementing number that is bumped each time that the {@link AnchorSet} is changed.\n\t * This allows consumers to cache state associated with a particular generation number and later determine if that state may have been invalidated using a comparison with the current generation number.\n\t * For example, anchor slots can be used to cache the removal status of a node to memoize repeated walks up the tree.\n\t */\n\tpublic generationNumber = 0;\n\n\t/**\n\t * Special root node under which all anchors in this anchor set are transitively parented.\n\t * This does not appear in the UpPaths (instead they use undefined for the root).\n\t * Immediate children of this root are in detached fields (which have their identifiers used as the field keys).\n\t *\n\t * This is allocated with refCount one, which is never freed so it is never cleaned up\n\t * (as long as this AnchorSet is not garbage collected).\n\t *\n\t * There should never be any children other than the special root detached field under this between transactions:\n\t * TODO: check for and enforce this.\n\t */\n\tprivate readonly root = new PathNode(this, EmptyKey, 0, undefined);\n\n\t// TODO: anchor system could be optimized a bit to avoid the maps (Anchor is ref to Path, path has ref count).\n\t// For now use this more encapsulated approach with maps.\n\tprivate readonly anchorToPath: Map<Anchor, PathNode> = new Map();\n\n\tprivate activeVisitor?: DeltaVisitor;\n\n\tpublic constructor() {\n\t\tthis.events.on(\"treeChanging\", () => {\n\t\t\tthis.generationNumber += 1;\n\t\t});\n\t}\n\n\t/**\n\t * Allows access to data stored on the AnchorSet in \"slots\".\n\t * Use {@link anchorSlot} to create slots.\n\t *\n\t * @privateRemarks\n\t * This forwards to the slots of the special above root anchor which locate can't access.\n\t */\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic get slots(): BrandedMapSubset<AnchorSlot<any>> {\n\t\treturn this.root.slots;\n\t}\n\n\tpublic *[Symbol.iterator](): IterableIterator<AnchorNode> {\n\t\tconst stack: PathNode[] = [];\n\t\tlet node: PathNode | undefined = this.root;\n\t\twhile (node !== undefined) {\n\t\t\tyield node;\n\t\t\tfor (const [_, children] of node.children) {\n\t\t\t\tfor (const child of children) {\n\t\t\t\t\tstack.push(child);\n\t\t\t\t}\n\t\t\t}\n\t\t\tnode = stack.pop();\n\t\t}\n\t}\n\n\t/**\n\t * Check if there are currently no anchors tracked.\n\t * Mainly for testing anchor cleanup.\n\t */\n\tpublic isEmpty(): boolean {\n\t\treturn this.root.children.size === 0;\n\t}\n\n\tpublic locate(anchor: Anchor): AnchorNode | undefined {\n\t\tif (anchor === NeverAnchor) {\n\t\t\treturn undefined;\n\t\t}\n\n\t\tconst path = this.anchorToPath.get(anchor);\n\t\tassert(\n\t\t\tpath !== undefined,\n\t\t\t0x3a6 /* Cannot locate anchor which is not in this AnchorSet */,\n\t\t);\n\t\treturn path.status === Status.Alive ? path : undefined;\n\t}\n\n\tpublic forget(anchor: Anchor): void {\n\t\tif (anchor !== NeverAnchor) {\n\t\t\tconst path = this.anchorToPath.get(anchor);\n\t\t\tassert(path !== undefined, 0x351 /* cannot forget unknown Anchor */);\n\t\t\tpath.removeRef();\n\t\t\tthis.anchorToPath.delete(anchor);\n\t\t}\n\t}\n\n\t/**\n\t * TODO: Add APIs need to allow callers of this function to reduce copying here.\n\t * Ex: maybe return something extending UpPath here.\n\t * @param path - the path to the node to be tracked. If null, returns an anchor\n\t * which is permanently invalid.\n\t */\n\t// eslint-disable-next-line @rushstack/no-new-null\n\tpublic track(path: UpPath | null): Anchor {\n\t\tif (path === null) {\n\t\t\treturn NeverAnchor;\n\t\t}\n\n\t\tconst foundPath = this.trackInner(path);\n\t\tconst anchor: Anchor = brand(this.anchorCounter++);\n\t\tthis.anchorToPath.set(anchor, foundPath);\n\t\treturn anchor;\n\t}\n\n\t/**\n\t * Finds a path node, creating if needed, and adds a ref count to it.\n\t */\n\tprivate trackInner(path: UpPath): PathNode {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\tpath.addRef();\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.trackInner(parent);\n\n\t\tconst child = parentPath.getOrCreateChild(path.parentField, path.parentIndex);\n\n\t\t// Now that child is added (if needed), remove the extra ref that we added in the recursive call.\n\t\tparentPath.removeRef();\n\n\t\treturn child;\n\t}\n\n\t/**\n\t * Finds a path node if it already exists.\n\t *\n\t * Does not add a ref!\n\t */\n\tpublic find(path: UpPath): PathNode | undefined {\n\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\treturn path;\n\t\t}\n\t\tconst parent = path.parent ?? this.root;\n\t\tconst parentPath = this.find(parent);\n\t\treturn parentPath?.childIfAnchored(path.parentField, path.parentIndex);\n\t}\n\n\t/**\n\t * Returns an equivalent path making as much of it with PathNodes as possible.\n\t * This allows future operations (like find, track, locate) on this path (and derived ones) to be faster.\n\t * Note that the returned path may use AnchorNodes from this AnchorSet,\n\t * but does not have a tracked reference to them, so this should not be held onto across anything that might free an AnchorNode.\n\t *\n\t * @remarks\n\t * Also ensures that any PathNode in the path is from this AnchorSet.\n\t */\n\tpublic internalizePath(originalPath: UpPath): UpPath {\n\t\tlet path: UpPath | undefined = originalPath;\n\t\tconst stack: UpPath[] = [];\n\t\twhile (path !== undefined) {\n\t\t\tif (path instanceof PathNode && path.anchorSet === this) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t\tstack.push(path);\n\t\t\tpath = path.parent;\n\t\t}\n\n\t\t// Now `path` contains an internalized path.\n\t\t// It just needs the paths from stackOut to wrap it.\n\n\t\tlet wrapWith: UpPath | undefined;\n\t\twhile ((wrapWith = stack.pop()) !== undefined) {\n\t\t\tif (path === undefined || path instanceof PathNode) {\n\t\t\t\t// If path already has an anchor, get an anchor for it's child if there is one:\n\t\t\t\tconst child = (path ?? this.root).childIfAnchored(\n\t\t\t\t\twrapWith.parentField,\n\t\t\t\t\twrapWith.parentIndex,\n\t\t\t\t);\n\t\t\t\tif (child !== undefined) {\n\t\t\t\t\tpath = child;\n\t\t\t\t\tcontinue;\n\t\t\t\t}\n\t\t\t}\n\t\t\t// Replacing this if with a ternary makes the documentation harder to include and hurts readability.\n\t\t\t// eslint-disable-next-line unicorn/prefer-ternary\n\t\t\tif (path === wrapWith.parent && !(wrapWith instanceof PathNode)) {\n\t\t\t\t// path is safe to reuse from input path, so use it to avoid allocating another object.\n\t\t\t\tpath = wrapWith;\n\t\t\t} else {\n\t\t\t\tpath = {\n\t\t\t\t\tparent: path,\n\t\t\t\t\tparentField: wrapWith.parentField,\n\t\t\t\t\tparentIndex: wrapWith.parentIndex,\n\t\t\t\t};\n\t\t\t}\n\t\t}\n\n\t\treturn path ?? fail(0xaea /* internalize path must be a path */);\n\t}\n\n\t/**\n\t * Recursively marks the given `nodes` and their descendants as disposed and pointing to a deleted node.\n\t * Note that this does NOT detach the nodes.\n\t */\n\tprivate deepDelete(nodes: readonly PathNode[]): void {\n\t\tconst stack = [...nodes];\n\t\twhile (stack.length > 0) {\n\t\t\tconst node = stack.pop()!;\n\t\t\tassert(node.status === Status.Alive, 0x408 /* PathNode must be alive */);\n\t\t\tnode.status = Status.Dangling;\n\t\t\tnode.events.emit(\"afterDestroy\", node);\n\t\t\tfor (const children of node.children.values()) {\n\t\t\t\tstack.push(...children);\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Decouple nodes from their parent.\n\t * This removes the reference from the parent to the decoupled children, and updates the indexes of the remaining children accordingly.\n\t * This does NOT update the decoupled children: both their index and parent are left at their existing values.\n\t * To decouple and fixup the children, see `removeChildren` and `moveChildren`.\n\t * @param startPath - The path to the first node that is being decoupled.\n\t * @param count - number of siblings that are decoupled from the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate decoupleNodes(startPath: UpPath, count: number): PathNode[] {\n\t\tassert(count > 0, 0x681 /* count must be positive */);\n\n\t\tconst sourceParent = this.find(startPath.parent ?? this.root);\n\t\tconst sourceChildren = sourceParent?.children?.get(startPath.parentField);\n\t\tlet nodes: PathNode[] = [];\n\n\t\tif (sourceChildren !== undefined) {\n\t\t\tlet numberBeforeDecouple = 0;\n\t\t\tlet numberToDecouple = 0;\n\t\t\tlet index = 0;\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex\n\t\t\t) {\n\t\t\t\tnumberBeforeDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (\n\t\t\t\tindex < sourceChildren.length &&\n\t\t\t\tsourceChildren[index]!.parentIndex < startPath.parentIndex + count\n\t\t\t) {\n\t\t\t\tnumberToDecouple++;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\twhile (index < sourceChildren.length) {\n\t\t\t\t// Fix indexes in source after moved items (subtract count).\n\t\t\t\tsourceChildren[index]!.parentIndex -= count;\n\t\t\t\tindex++;\n\t\t\t}\n\t\t\t// Sever the parent -> child connections\n\t\t\tnodes = sourceChildren.splice(numberBeforeDecouple, numberToDecouple);\n\t\t\tif (sourceChildren.length === 0) {\n\t\t\t\tsourceParent!.afterEmptyField(startPath.parentField);\n\t\t\t}\n\t\t}\n\n\t\treturn nodes;\n\t}\n\n\t/**\n\t * Couple nodes to a parent.\n\t * @param destination - where the siblings are coupled to.\n\t * @param count - number of siblings that are coupled in the original tree.\n\t * @param coupleInfo - this object contains the nodes to couple and the parent index of the first node that is coupled in the original tree.\n\t *\n\t * TODO: tests\n\t */\n\tprivate coupleNodes(\n\t\tdestination: UpPath,\n\t\tcount: number,\n\t\tcoupleInfo: { startParentIndex: number; nodes: PathNode[] },\n\t): void {\n\t\tassert(coupleInfo.nodes.length > 0, 0x682 /* coupleInfo must have nodes to couple */);\n\n\t\t// The destination needs to be created if it does not exist yet.\n\t\tconst destinationPath = this.trackInner(destination.parent ?? this.root);\n\n\t\t// Update nodes for new parent.\n\t\tfor (const node of coupleInfo.nodes) {\n\t\t\tnode.parentIndex += destination.parentIndex - coupleInfo.startParentIndex;\n\t\t\tnode.parentPath = destinationPath;\n\t\t\tnode.parentField = destination.parentField;\n\t\t\t// If the destination is a detached root, propagate its detachedNodeId, otherwise remove any existing one\n\t\t\tnode.detachedNodeId = isDetachedUpPathRoot(destination)\n\t\t\t\t? offsetDetachId(\n\t\t\t\t\t\tdestination.detachedNodeId,\n\t\t\t\t\t\tnode.parentIndex - destination.parentIndex,\n\t\t\t\t\t)\n\t\t\t\t: undefined;\n\t\t}\n\n\t\t// Update new parent to add children\n\t\tconst field = destinationPath.children.get(destination.parentField);\n\t\tif (field === undefined) {\n\t\t\tdestinationPath.children.set(destination.parentField, coupleInfo.nodes);\n\t\t} else {\n\t\t\t// Update existing field contents\n\t\t\tconst numberBeforeCouple = this.increaseParentIndexes(\n\t\t\t\tfield,\n\t\t\t\tdestination.parentIndex,\n\t\t\t\tcount,\n\t\t\t);\n\n\t\t\t// TODO: this will fail for very large numbers of anchors due to argument limits.\n\t\t\tfield.splice(numberBeforeCouple, 0, ...coupleInfo.nodes);\n\t\t}\n\n\t\tdestinationPath.removeRef();\n\t}\n\n\t/**\n\t * Updates the parent indexes within `field` to account for `count` children being inserted at `fromParentIndex`. Note that\n\t * `fromParentIndex` is the logical position within the field, not the index with the sparse PathNode array.\n\t *\n\t * @param field - the field to update.\n\t * @param fromParentIndex - the logical index within the field to start updating from.\n\t * @param count - the number to increase parent indexes.\n\t * @returns the number of items in the field that are not increased.\n\t *\n\t * TODO: tests\n\t */\n\tprivate increaseParentIndexes(\n\t\tfield: PathNode[],\n\t\tfromParentIndex: number,\n\t\tcount: number,\n\t): number {\n\t\tlet index = 0;\n\t\twhile (index < field.length && field[index]!.parentIndex < fromParentIndex) {\n\t\t\tindex++;\n\t\t}\n\t\tconst numberBeforeIncrease = index;\n\t\twhile (index < field.length) {\n\t\t\tfield[index]!.parentIndex += count;\n\t\t\tindex++;\n\t\t}\n\n\t\treturn numberBeforeIncrease;\n\t}\n\n\t/**\n\t * Updates paths for a range move (including re-parenting path items and updating indexes).\n\t * @param sourceStart - where the siblings are removed from.\n\t * @param destination - where the siblings are moved to.\n\t * @param count - number of siblings to move.\n\t *\n\t * TODO:\n\t * How should anchors that become invalid, then valid again (ex: into content that was deleted, then undone) work?\n\t * Add an API to resurrect them? Store them in special detached fields? Store them in special non-detached fields?\n\t *\n\t * TODO:\n\t * How should custom anchors work (ex: ones not just tied to a specific Node)?\n\t * This design assumes they can be expressed in terms of a Node anchor + some extra stuff,\n\t * but we don't have an API for the extra stuff yet.\n\t *\n\t * TODO: tests\n\t */\n\tprivate moveChildren(sourceStart: UpPath, destination: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(sourceStart, count);\n\t\tif (nodes.length > 0) {\n\t\t\tthis.coupleNodes(destination, count, {\n\t\t\t\tstartParentIndex: sourceStart.parentIndex,\n\t\t\t\tnodes,\n\t\t\t});\n\t\t} else {\n\t\t\t// If there are no nodes to move, we still need to update the parent indexes of the nodes\n\t\t\t// affected in the move in.\n\t\t\tthis.offsetChildren(destination, count);\n\t\t}\n\t}\n\n\tprivate removeChildren(path: UpPath, count: number): void {\n\t\tconst nodes = this.decoupleNodes(path, count);\n\t\tthis.deepDelete(nodes);\n\t}\n\n\t/**\n\t * Updates the parent indexes of all the nodes located at right side of the given path by the given offset.\n\t * @param firstSiblingToOffset - the path to offset children of.\n\t * @param offset - the offset to apply to the children.\n\t *\n\t */\n\tprivate offsetChildren(firstSiblingToOffset: UpPath, offset: number): void {\n\t\tconst nodePath = this.find(firstSiblingToOffset.parent ?? this.root);\n\t\tconst field = nodePath?.children.get(firstSiblingToOffset.parentField);\n\t\tif (field !== undefined) {\n\t\t\tthis.increaseParentIndexes(field, firstSiblingToOffset.parentIndex, offset);\n\t\t}\n\t}\n\n\t/**\n\t * Provides a visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @returns A visitor that can be used to mutate this {@link AnchorSet}.\n\t *\n\t * @remarks\n\t * Mutating the {@link AnchorSet} does NOT update the forest.\n\t * The visitor must be released after use by calling {@link DeltaVisitor.free} on it.\n\t * It is invalid to acquire a visitor without releasing the previous one,\n\t * and this method will throw an error if this is attempted.\n\t */\n\tpublic acquireVisitor(): DeltaVisitor {\n\t\tassert(\n\t\t\tthis.activeVisitor === undefined,\n\t\t\t0x767 /* Must release existing visitor before acquiring another */,\n\t\t);\n\n\t\tconst referencedPathNodes: PathNode[] = [];\n\t\tconst visitor = {\n\t\t\tanchorSet: this,\n\t\t\t// Run `withNode` on anchorNode for parent if there is such an anchorNode.\n\t\t\t// If at root, run `withRoot` instead.\n\t\t\tmaybeWithNode(withNode: (anchorNode: PathNode) => void, withRoot?: () => void) {\n\t\t\t\tif (this.parent === undefined && withRoot !== undefined) {\n\t\t\t\t\twithRoot();\n\t\t\t\t} else {\n\t\t\t\t\tassert(this.parent !== undefined, 0x5b0 /* parent must exist */);\n\t\t\t\t\t// TODO:Perf:\n\t\t\t\t\t// When traversing to a depth D when there are not anchors in that subtree, this goes O(D^2).\n\t\t\t\t\t// Delta traversal should early out in this case because no work is needed (and all move outs are known to not contain anchors).\n\t\t\t\t\tthis.parent = this.anchorSet.internalizePath(this.parent);\n\t\t\t\t\tif (this.parent instanceof PathNode) {\n\t\t\t\t\t\tthis.parent.addRef();\n\t\t\t\t\t\treferencedPathNodes.push(this.parent);\n\t\t\t\t\t\twithNode(this.parent);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tparentField: undefined as FieldKey | undefined,\n\t\t\tparent: undefined as UpPath | undefined,\n\n\t\t\t/**\n\t\t\t * Events collected during the visit which get sent as a batch during \"free\".\n\t\t\t */\n\t\t\tbufferedEvents: [] as BufferedEvent[],\n\n\t\t\t/**\n\t\t\t * 'currentDepth' and 'depthThresholdForSubtreeChanged' serve to keep track of when do we need to emit\n\t\t\t * subtreeChangedAfterBatch events.\n\t\t\t * The algorithm works as follows:\n\t\t\t *\n\t\t\t * - Initialize both to 0.\n\t\t\t * - As we walk the tree from the root towards the leaves, when we enter a node increment currentDepth by 1.\n\t\t\t * - When we edit a node, set depthThresholdForSubtreeChanged = currentDepth.\n\t\t\t * Intuitively, depthThresholdForSubtreeChanged means \"as you walk the tree towards the root, when you exit a\n\t\t\t * node at this depth you should emit a subtreeChangedAfterBatch event\".\n\t\t\t * - When we exit a node, if d === currentDepth then emit a subtreeChangedAfterBatch and decrement d by 1.\n\t\t\t * Then decrement currentDepth unconditionally.\n\t\t\t *\n\t\t\t * Note that the event will be emitted when exiting a node that was edited (depthThresholdForSubtreeChanged will\n\t\t\t * have been set to the current depth when the edit happened), it will be emitted when exiting a node that is the\n\t\t\t * parent of a node that already emitted the event (because both depthThresholdForSubtreeChanged and currentDepth\n\t\t\t * get decremented when exiting a node so they stay in sync), and if we're already emitting the event but start\n\t\t\t * walking the tree back towards the leaves in a path where no edits happen, currentDepth will be increased again\n\t\t\t * as we walk that path, depthThresholdForSubtreeChanged will not, and thus no event will be emitted when walking\n\t\t\t * back up that path, until we get back to the depth where we were already emitting the event, and will continue\n\t\t\t * emitting it on the way to the root.\n\t\t\t */\n\t\t\tcurrentDepth: 0,\n\t\t\t/**\n\t\t\t * See {@link visitor.currentDepth}.\n\t\t\t */\n\t\t\tdepthThresholdForSubtreeChanged: 0,\n\n\t\t\tfree() {\n\t\t\t\tassert(\n\t\t\t\t\tthis.anchorSet.activeVisitor !== undefined,\n\t\t\t\t\t0x768 /* Multiple free calls for same visitor */,\n\t\t\t\t);\n\t\t\t\tfor (const node of referencedPathNodes) {\n\t\t\t\t\tnode.removeRef();\n\t\t\t\t}\n\t\t\t\tthis.anchorSet.activeVisitor = undefined;\n\n\t\t\t\t// Aggregate changedFields by node.\n\t\t\t\tconst eventsByNode: Map<PathNode, Set<FieldKey>> = new Map();\n\t\t\t\tfor (const { node, event, changedField } of this.bufferedEvents) {\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst keys = getOrCreate(eventsByNode, node, () => new Set());\n\t\t\t\t\t\tkeys.add(\n\t\t\t\t\t\t\tchangedField ??\n\t\t\t\t\t\t\t\tfail(0xb57 /* childrenChangedAfterBatch events should have a changedField */),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tconst alreadyEmitted = new Map<PathNode, (keyof AnchorEvents)[]>();\n\t\t\t\tfor (const { node, event } of this.bufferedEvents) {\n\t\t\t\t\tconst emittedEvents = getOrAddEmptyToMap(alreadyEmitted, node);\n\t\t\t\t\tif (emittedEvents.includes(event)) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\t\t\t\t\temittedEvents.push(event);\n\t\t\t\t\tif (event === \"childrenChangedAfterBatch\") {\n\t\t\t\t\t\tconst changedFields =\n\t\t\t\t\t\t\teventsByNode.get(node) ??\n\t\t\t\t\t\t\tfail(0xaeb /* childrenChangedAfterBatch events should have changedFields */);\n\t\t\t\t\t\tnode.events.emit(event, { changedFields });\n\t\t\t\t\t} else {\n\t\t\t\t\t\tnode.events.emit(event);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tnotifyChildrenChanging(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => p.events.emit(\"childrenChanging\", p),\n\t\t\t\t\t() => this.anchorSet.#events.emit(\"childrenChanging\", this.anchorSet),\n\t\t\t\t);\n\t\t\t},\n\t\t\tnotifyChildrenChanged(): void {\n\t\t\t\tthis.maybeWithNode(\n\t\t\t\t\t(p) => {\n\t\t\t\t\t\tassert(\n\t\t\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t\t\t0xa24 /* Must be in a field to modify its contents */,\n\t\t\t\t\t\t);\n\t\t\t\t\t\tp.events.emit(\"childrenChanged\", p);\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"childrenChangedAfterBatch\",\n\t\t\t\t\t\t\tchangedField: this.parentField,\n\t\t\t\t\t\t});\n\t\t\t\t\t},\n\t\t\t\t\t() => {},\n\t\t\t\t);\n\t\t\t},\n\t\t\tattach(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.attachEdit(source, count, destination);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tattachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a2 /* Must be in a field in order to attach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: source,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t};\n\t\t\t\tconst destinationPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: destination,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, count);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\tdetach(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(source, destination, detachedNodeId);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdetachEdit(\n\t\t\t\tsource: Range,\n\t\t\t\tdestination: FieldKey,\n\t\t\t\tdetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tassert(\n\t\t\t\t\tthis.parentField !== undefined,\n\t\t\t\t\t0x7a5 /* Must be in a field in order to detach */,\n\t\t\t\t);\n\t\t\t\tconst sourcePath: UpPath = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: source.start,\n\t\t\t\t};\n\t\t\t\tconst destinationPath: NormalizedUpPath = {\n\t\t\t\t\tparent: this.anchorSet.root,\n\t\t\t\t\tparentField: destination,\n\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\tdetachedNodeId,\n\t\t\t\t};\n\t\t\t\tthis.anchorSet.moveChildren(sourcePath, destinationPath, source.end - source.start);\n\t\t\t\tthis.depthThresholdForSubtreeChanged = this.currentDepth;\n\t\t\t},\n\t\t\treplace(\n\t\t\t\tnewContentSource: FieldKey,\n\t\t\t\trange: Range,\n\t\t\t\toldContentDestination: FieldKey,\n\t\t\t\tdestinationDetachedNodeId: Delta.DetachedNodeId,\n\t\t\t): void {\n\t\t\t\tthis.notifyChildrenChanging();\n\t\t\t\tthis.detachEdit(range, oldContentDestination, destinationDetachedNodeId);\n\t\t\t\tthis.attachEdit(newContentSource, range.end - range.start, range.start);\n\t\t\t\tthis.notifyChildrenChanged();\n\t\t\t},\n\t\t\tdestroy(detachedField: FieldKey, count: number): void {\n\t\t\t\tthis.anchorSet.removeChildren(\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: undefined,\n\t\t\t\t\t\tparentField: detachedField,\n\t\t\t\t\t\tparentIndex: 0,\n\t\t\t\t\t},\n\t\t\t\t\tcount,\n\t\t\t\t);\n\t\t\t},\n\t\t\tcreate(content: ITreeCursorSynchronous[], destination: FieldKey): void {\n\t\t\t\t// Nothing to do since content can only be created in a new detached field,\n\t\t\t\t// which cannot contain any anchors.\n\t\t\t},\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(this.parentField !== undefined, 0x3ab /* Must be in a field to enter node */);\n\n\t\t\t\tthis.parent = {\n\t\t\t\t\tparent: this.parent,\n\t\t\t\t\tparentField: this.parentField,\n\t\t\t\t\tparentIndex: index,\n\t\t\t\t};\n\t\t\t\tthis.parentField = undefined;\n\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\tp.events.emit(\"subtreeChanging\", p);\n\t\t\t\t});\n\t\t\t\tthis.currentDepth++;\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(this.parent !== undefined, 0x3ac /* Must have parent node */);\n\t\t\t\tif (this.depthThresholdForSubtreeChanged === this.currentDepth) {\n\t\t\t\t\tthis.maybeWithNode((p) => {\n\t\t\t\t\t\tp.events.emit(\"subtreeChanged\", p);\n\n\t\t\t\t\t\tthis.bufferedEvents.push({\n\t\t\t\t\t\t\tnode: p,\n\t\t\t\t\t\t\tevent: \"subtreeChangedAfterBatch\",\n\t\t\t\t\t\t});\n\t\t\t\t\t});\n\t\t\t\t\tthis.depthThresholdForSubtreeChanged--;\n\t\t\t\t}\n\t\t\t\tconst parent = this.parent;\n\t\t\t\tthis.parentField = parent.parentField;\n\t\t\t\tthis.parent = parent.parent;\n\t\t\t\tthis.currentDepth--;\n\t\t\t},\n\t\t\tenterField(key: FieldKey): void {\n\t\t\t\tthis.parentField = key;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tthis.parentField = undefined;\n\t\t\t},\n\t\t};\n\t\tthis.#events.emit(\"treeChanging\", this);\n\t\tthis.activeVisitor = visitor;\n\t\treturn visitor;\n\t}\n}\n\n/**\n * Indicates the status of a `NodePath`.\n */\nenum Status {\n\t/**\n\t * Indicates the `NodePath` is being maintained and corresponds to a valid\n\t * (i.e., not removed) node in the document.\n\t */\n\tAlive,\n\t/**\n\t * Indicates the `NodePath` is not being maintained by the `AnchorSet`.\n\t * The `NodePath` may or may not correspond to a valid node in the document.\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDisposed,\n\t/**\n\t * Indicates the `NodePath` corresponds to a removed node in the document.\n\t * Such `NodePath`s are not maintained by the `AnchorSet` (other than updating\n\t * their status to `Disposed` when appropriate).\n\t *\n\t * Accessing such a node is invalid.\n\t * Nodes in this state are retained to detect use-after-free bugs.\n\t */\n\tDangling,\n}\n\n/**\n * Tree of anchors.\n *\n * Contains both child and parent pointers, which are kept in sync.\n *\n * Each anchor is equivalent to a path through the tree.\n * This tree structure stores a collection of these paths, but deduplicating the common prefixes of the tree\n * prefix-tree style.\n *\n * These anchors are used instead of just holding onto the node objects in forests for several reasons:\n *\n * - Update policy might be more complex than just tracking a node object in the forest.\n *\n * - Not all forests will have node objects: some may use compressed binary formats with no objects to reference.\n *\n * - Anchors are needed even when not using forests, and for nodes that are outside the currently loaded part of the\n * forest.\n *\n * - Forest in general do not need to support up pointers, but they are needed for anchors.\n *\n * Thus this can be thought of as a sparse copy of the subset of trees which are used as anchors,\n * plus the parent paths for them.\n *\n * ReferenceCountedBase tracks the number of references to this from external sources (`Anchors` via `AnchorSet`.).\n * Kept alive as if any of the follow are true:\n * 1. there are children.\n * 2. refcount is non-zero.\n * 3. events are registered.\n */\nclass PathNode extends ReferenceCountedBase implements AnchorNode {\n\tpublic status: Status = Status.Alive;\n\t/**\n\t * Event emitter for this anchor.\n\t */\n\tpublic readonly events = createEmitter<AnchorEvents>(() => this.considerDispose());\n\n\t/**\n\t * PathNode arrays are kept sorted the PathNode's parentIndex for efficient search.\n\t * Users of this field must take care to maintain invariants (correct parent pointers, not empty child arrays etc.)\n\t *\n\t * Performance Note:\n\t * Large child lists could be updated more efficiently here using a data-structure optimized\n\t * for efficient prefix sum updates, such as a Fenwick tree or Finger tree.\n\t * This would be complicated by the need for parent pointers (including indexes),\n\t * but is possible to do.\n\t */\n\tpublic readonly children: Map<FieldKey, PathNode[]> = new Map();\n\n\t// See note on BrandedKey.\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tpublic readonly slots: BrandedMapSubset<AnchorSlot<any>> = new Map();\n\n\t/**\n\t * {@inheritdoc UpPath.detachedNodeId}\n\t */\n\tpublic detachedNodeId: Delta.DetachedNodeId | undefined;\n\n\t/**\n\t * Construct a PathNode with refcount 1.\n\t * @param anchorSet - used to determine if this PathNode is already part of a specific anchorSet\n\t * to early out UpPath walking.\n\t */\n\tpublic constructor(\n\t\tpublic readonly anchorSet: AnchorSet,\n\t\tpublic parentField: FieldKey,\n\t\tpublic parentIndex: number,\n\t\t/**\n\t\t * The parent of this `PathNode` (an up pointer in the `PathNode` tree).\n\t\t * If the status of this node is `Alive`, then there must be a corresponding down pointer from the\n\t\t * `parentPath` node to this node.\n\t\t * When undefined, this node is the {@link AnchorSet.root} for `this.anchorSet` and thus has no parent.\n\t\t *\n\t\t * When updating the tree, `AnchorSet` may transiently leave the up and down pointers inconsistent\n\t\t * (updating down pointers first), but must ensure they are consistent before the editing operation returns\n\t\t * to non-`AnchorSet` code.\n\t\t * This consistency guarantee only applies to nodes that are `Alive`.\n\t\t */\n\t\tpublic parentPath: PathNode | undefined,\n\t) {\n\t\tsuper(1);\n\t}\n\n\tpublic child(key: FieldKey, index: number): UpPath<AnchorNode> {\n\t\t// Fast path: if child exists, return it.\n\t\treturn (\n\t\t\tthis.childIfAnchored(key, index) ?? {\n\t\t\t\tparent: this,\n\t\t\t\tparentField: key,\n\t\t\t\tparentIndex: index,\n\t\t\t}\n\t\t);\n\t}\n\n\tpublic getOrCreateChildRef(key: FieldKey, index: number): [Anchor, AnchorNode] {\n\t\tconst anchor = this.anchorSet.track(this.child(key, index));\n\t\tconst node =\n\t\t\tthis.anchorSet.locate(anchor) ??\n\t\t\tfail(0xaec /* cannot reference child that does not exist */);\n\t\treturn [anchor, node];\n\t}\n\n\t/**\n\t * Whether or not this `PathNode` is the special root node that sits above all the detached fields.\n\t * @remarks\n\t * In this case, the fields are detached sequences.\n\t * Note that the special root node should never appear in an UpPath\n\t * since UpPaths represent this root as `undefined`.\n\t */\n\tprivate isRoot(): boolean {\n\t\treturn this.parentPath === undefined;\n\t}\n\n\tpublic get parent(): PathNode | undefined {\n\t\tassert(this.status !== Status.Disposed, 0x409 /* PathNode must not be disposed */);\n\t\tassert(\n\t\t\tthis.parentPath !== undefined,\n\t\t\t0x355 /* PathNode.parent is an UpPath API and thus should never be called on the root PathNode. */,\n\t\t);\n\t\t// Root PathNode corresponds to the undefined root for UpPath API.\n\t\tif (this.parentPath.isRoot()) {\n\t\t\treturn undefined;\n\t\t}\n\t\treturn this.parentPath;\n\t}\n\n\tpublic addRef(count = 1): void {\n\t\tassert(this.status === Status.Alive, 0x40a /* PathNode must be alive */);\n\t\tthis.referenceAdded(count);\n\t}\n\n\tpublic removeRef(count = 1): void {\n\t\tassert(this.status !== Status.Disposed, 0x40b /* PathNode must not be disposed */);\n\t\tthis.referenceRemoved(count);\n\t}\n\n\t// Called when refcount is set to 0.\n\t// Node may be kept alive by children or events after this point.\n\tprotected onUnreferenced(): void {\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * Gets a child, adding a ref to it.\n\t * Creates child (with 1 ref) if needed.\n\t */\n\tpublic getOrCreateChild(key: FieldKey, index: number): PathNode {\n\t\tassert(this.status === Status.Alive, 0x40c /* PathNode must be alive */);\n\t\tlet field = this.children.get(key);\n\t\tif (field === undefined) {\n\t\t\tfield = [];\n\t\t\tthis.children.set(key, field);\n\t\t}\n\t\tlet child = binaryFind(field, index);\n\t\tif (child === undefined) {\n\t\t\tchild = new PathNode(this.anchorSet, key, index, this);\n\t\t\tfield.push(child);\n\t\t\t// Keep list sorted by index.\n\t\t\tfield.sort((a, b) => a.parentIndex - b.parentIndex);\n\t\t} else {\n\t\t\tchild.addRef();\n\t\t}\n\t\treturn child;\n\t}\n\n\tpublic childIfAnchored(key: FieldKey, index: number): PathNode | undefined {\n\t\tassert(this.status === Status.Alive, 0x40d /* PathNode must be alive */);\n\t\tconst field = this.children.get(key);\n\n\t\treturn field === undefined ? undefined : binaryFind(field, index);\n\t}\n\n\t/**\n\t * Removes reference from this to `child`.\n\t * Since PathNodes are doubly linked,\n\t * the caller must ensure that the reference from child to parent is also removed (or the child is no longer used).\n\t */\n\tpublic removeChild(child: PathNode): void {\n\t\tassert(this.status === Status.Alive, 0x40e /* PathNode must be alive */);\n\t\tconst key = child.parentField;\n\t\tconst field = this.children.get(key);\n\t\t// TODO: should do more optimized search (ex: binary search or better) using child.parentIndex()\n\t\t// Note that this is the index in the list of child paths, not the index within the field\n\t\tconst childIndex = field?.indexOf(child) ?? -1;\n\t\tassert(childIndex !== -1, 0x35c /* child must be parented to be removed */);\n\t\tfield?.splice(childIndex, 1);\n\t\tif (field?.length === 0) {\n\t\t\tthis.afterEmptyField(key);\n\t\t}\n\t}\n\n\t/**\n\t * Call this after directly editing the child array for a field to be empty.\n\t * Handles cleaning up unneeded data\n\t * (like the field in the map, and possibly this entire PathNode and its parents if they are no longer needed.)\n\t */\n\tpublic afterEmptyField(key: FieldKey): void {\n\t\tassert(this.status === Status.Alive, 0x40f /* PathNode must be alive */);\n\t\tthis.children.delete(key);\n\t\tthis.considerDispose();\n\t}\n\n\t/**\n\t * If node is no longer needed (has no references, no children and no events):\n\t * removes this from parent if alive, and sets this to disposed.\n\t * Must only be called when .\n\t *\n\t * Allowed when dangling (but not when disposed).\n\t */\n\tprivate considerDispose(): void {\n\t\tassert(this.status !== Status.Disposed, 0x41d /* PathNode must not be disposed */);\n\t\tif (this.isUnreferenced() && this.children.size === 0 && !this.events.hasListeners()) {\n\t\t\tif (this.status === Status.Alive) {\n\t\t\t\t// eslint-disable-next-line unicorn/prefer-dom-node-remove -- Custom tree structure, not DOM\n\t\t\t\tthis.parentPath?.removeChild(this);\n\t\t\t}\n\t\t\tthis.status = Status.Disposed;\n\t\t}\n\t}\n}\n\n/**\n * Find a child PathNode by index using a binary search.\n * @param sorted - array of PathNode's sorted by parentIndex.\n * @param index - index being looked for.\n * @returns child with the requested parentIndex, or undefined.\n * @privateRemarks\n * This function is very commonly used with small arrays (length 0 or one for all non sequence fields),\n * and is currently a hot path due to how flex tree leaves to excessive cursor to anchor and anchor to cursor translations,\n * both of which walk paths down the AnchorSet.\n * Additionally current usages tends to fully populate the anchor tree leading the correct array index to be the requested parent index.\n * This makes the performance of this performance both important in small cases and easy to overly tune to the current usage patterns.\n * This lead to not implementing a general purpose reusable binary search.\n * Once this function is not so heavily overused due to inefficient patterns in flex-tree,\n * replacing it with a standard binary search is likely fine.\n * Until then, care and benchmarking should be used when messing with this function.\n */\nfunction binaryFind(sorted: readonly PathNode[], index: number): PathNode | undefined {\n\t// Try guessing the list is not sparse as a starter:\n\tconst guess = sorted[index];\n\tif (guess !== undefined && guess.parentIndex === index) {\n\t\treturn guess;\n\t}\n\n\t// inclusive\n\tlet min = 0;\n\t// exclusive\n\tlet max = sorted.length;\n\n\twhile (min !== max) {\n\t\tconst mid = Math.floor((min + max) / 2);\n\t\tconst item = sorted[mid]!;\n\t\tconst found = item.parentIndex;\n\t\tif (found === index) {\n\t\t\treturn item; // Found the target, return it.\n\t\t} else if (found > index) {\n\t\t\tmax = mid; // Continue search on lower half.\n\t\t} else {\n\t\t\tmin = mid + 1; // Continue search on left half.\n\t\t}\n\t}\n\treturn undefined; // If we reach here, target is not in array (or array was not sorted)\n}\n\ninterface BufferedEvent {\n\tnode: PathNode;\n\tevent: keyof AnchorEvents;\n\t/**\n\t * The key for the impacted field, if the event is associated with a key.\n\t * Some events, such as afterDestroy, do not involve a key, and thus leave this undefined.\n\t */\n\tchangedField?: FieldKey;\n}\n"]}
@@ -8,7 +8,7 @@ import { type IdAllocator, type JsonCompatibleReadOnly } from "../../util/index.
8
8
  import type { RevisionTag, RevisionTagCodec } from "../rebase/index.js";
9
9
  import type { FieldKey } from "../schema-stored/index.js";
10
10
  import type * as Delta from "./delta.js";
11
- import type { ForestRootId, Major } from "./detachedFieldIndexTypes.js";
11
+ import type { ForestRootId } from "./detachedFieldIndexTypes.js";
12
12
  /**
13
13
  * Readonly interface for {@link DetachedFieldIndex}.
14
14
  */
@@ -88,7 +88,6 @@ export declare class DetachedFieldIndex implements ReadOnlyDetachedFieldIndex {
88
88
  * Removes all entries from the index.
89
89
  */
90
90
  purge(): void;
91
- updateMajor(current: Major, updated: Major): void;
92
91
  toFieldKey(id: ForestRootId): FieldKey;
93
92
  tryGetEntry(id: Delta.DetachedNodeId): ForestRootId | undefined;
94
93
  getEntry(id: Delta.DetachedNodeId): ForestRootId;
@@ -1 +1 @@
1
- {"version":3,"file":"detachedFieldIndex.d.ts","sourceRoot":"","sources":["../../../src/core/tree/detachedFieldIndex.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAEnE,OAAO,EACN,KAAK,iBAAiB,EAItB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,sBAAsB,EAS3B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACxE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,KAAK,KAAK,KAAK,MAAM,YAAY,CAAC;AACzC,OAAO,KAAK,EAGX,YAAY,EACZ,KAAK,EAEL,MAAM,8BAA8B,CAAC;AAGtC;;GAEG;AACH,MAAM,WAAW,0BAA0B;IAC1C;;OAEG;IACH,KAAK,IAAI,kBAAkB,CAAC;IAE5B;;;OAGG;IACH,UAAU,CAAC,EAAE,EAAE,YAAY,GAAG,QAAQ,CAAC;IAEvC;;;OAGG;IACH,WAAW,CAAC,EAAE,EAAE,KAAK,CAAC,cAAc,GAAG,YAAY,GAAG,SAAS,CAAC;IAEhE;;;OAGG;IACH,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC,cAAc,GAAG,YAAY,CAAC;CACjD;AAED;;;GAGG;AACH,MAAM,MAAM,4BAA4B,GAAG,MAAM,IAAI,CAAC;AAEtD;;GAEG;AACH,qBAAa,kBAAmB,YAAW,0BAA0B;IAoCnE,OAAO,CAAC,QAAQ,CAAC,IAA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,EAAE,WAAW,GAAG,QAAQ,CAAC,YAAY,CAAC;IAOpF;;OAEG;IACI,gCAAgC,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI;IAiB7D,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,cAAc,GAAG,IAAI;IAWtD;;;;;;;OAOG;IACI,WAAW,CACjB,MAAM,CAAC,EAAE,KAAK,CAAC,cAAc,EAC7B,QAAQ,CAAC,EAAE,WAAW,EACtB,KAAK,GAAE,MAAU,GACf,YAAY;IAsBf;;OAEG;IACI,oBAAoB,CAC1B,EAAE,EAAE,KAAK,CAAC,cAAc,EACxB,QAAQ,EAAE,WAAW,GAAG,SAAS,GAC/B,IAAI;IAmBA,MAAM,IAAI,sBAAsB;IAOvC;;OAEG;IACI,QAAQ,CAAC,IAAI,EAAE,sBAAsB,GAAG,IAAI;IAmBnD;;;;OAIG;IACI,yBAAyB,CAAC,cAAc,EAAE,WAAW,GAAG,IAAI;CAqBnE"}
@@ -47,7 +47,11 @@ class DetachedFieldIndex {
47
47
  jsonValidator: index_js_1.FormatValidatorNoOp,
48
48
  minVersionForCollab: index_js_1.FluidClientVersion.v2_0,
49
49
  };
50
- this.codec = (0, detachedFieldIndexCodecs_js_1.makeDetachedFieldIndexCodec)(revisionTagCodec, this.options, idCompressor);
50
+ this.codec = detachedFieldIndexCodecs_js_1.detachedFieldIndexCodecBuilder.build({
51
+ ...this.options,
52
+ revisionTagCodec,
53
+ idCompressor,
54
+ });
51
55
  }
52
56
  clone() {
53
57
  const clone = new DetachedFieldIndex(this.name, (0, index_js_2.idAllocatorFromMaxId)(this.rootIdAllocator.getMaxId()), this.revisionTagCodec, this.idCompressor, this.options);
@@ -69,18 +73,18 @@ class DetachedFieldIndex {
69
73
  }
70
74
  *entries() {
71
75
  for (const [major, innerMap] of this.detachedNodeToField) {
72
- if (major !== undefined) {
76
+ if (major === undefined) {
73
77
  for (const [minor, { root, latestRelevantRevision }] of innerMap) {
74
- yield latestRelevantRevision !== undefined
75
- ? { id: { major, minor }, root, latestRelevantRevision }
76
- : { id: { major, minor }, root };
78
+ yield latestRelevantRevision === undefined
79
+ ? { id: { minor }, root }
80
+ : { id: { minor }, root, latestRelevantRevision };
77
81
  }
78
82
  }
79
83
  else {
80
84
  for (const [minor, { root, latestRelevantRevision }] of innerMap) {
81
- yield latestRelevantRevision !== undefined
82
- ? { id: { minor }, root, latestRelevantRevision }
83
- : { id: { minor }, root };
85
+ yield latestRelevantRevision === undefined
86
+ ? { id: { major, minor }, root }
87
+ : { id: { major, minor }, root, latestRelevantRevision };
84
88
  }
85
89
  }
86
90
  }
@@ -92,54 +96,6 @@ class DetachedFieldIndex {
92
96
  this.detachedNodeToField.clear();
93
97
  this.latestRelevantRevisionToFields.clear();
94
98
  }
95
- updateMajor(current, updated) {
96
- // Update latestRelevantRevision information corresponding to `current`
97
- {
98
- const inner = this.latestRelevantRevisionToFields.get(current);
99
- if (inner !== undefined) {
100
- for (const nodeId of inner.values()) {
101
- const entry = (0, index_js_2.tryGetFromNestedMap)(this.detachedNodeToField, nodeId.major, nodeId.minor);
102
- (0, internal_1.assert)(entry !== undefined, 0x9b8 /* Inconsistent data: missing detached node entry */);
103
- (0, index_js_2.setInNestedMap)(this.detachedNodeToField, nodeId.major, nodeId.minor, {
104
- ...entry,
105
- latestRelevantRevision: updated,
106
- });
107
- }
108
- this.latestRelevantRevisionToFields.delete(current);
109
- const updatedInner = this.latestRelevantRevisionToFields.get(updated);
110
- if (updatedInner !== undefined) {
111
- for (const [root, nodeId] of inner) {
112
- updatedInner.set(root, nodeId);
113
- }
114
- }
115
- else {
116
- this.latestRelevantRevisionToFields.set(updated, inner);
117
- }
118
- }
119
- }
120
- // Update the major keys corresponding to `current`
121
- {
122
- const innerCurrent = this.detachedNodeToField.get(current);
123
- if (innerCurrent !== undefined) {
124
- this.detachedNodeToField.delete(current);
125
- const innerUpdated = this.detachedNodeToField.get(updated);
126
- if (innerUpdated === undefined) {
127
- this.detachedNodeToField.set(updated, innerCurrent);
128
- }
129
- else {
130
- for (const [minor, entry] of innerCurrent) {
131
- (0, internal_1.assert)(innerUpdated.get(minor) === undefined, 0x7a9 /* Collision during index update */);
132
- innerUpdated.set(minor, entry);
133
- }
134
- }
135
- for (const [minor, entry] of innerCurrent) {
136
- const entryInLatest = this.latestRelevantRevisionToFields.get(entry.latestRelevantRevision);
137
- (0, internal_1.assert)(entryInLatest !== undefined, 0x9b9 /* Inconsistent data: missing node entry in latestRelevantRevision */);
138
- entryInLatest.set(entry.root, { major: updated, minor });
139
- }
140
- }
141
- }
142
- }
143
99
  toFieldKey(id) {
144
100
  return (0, index_js_2.brand)(`${this.name}-${id}`);
145
101
  }