@fluidframework/tree 2.118.0 → 3.0.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 (1234) hide show
  1. package/CHANGELOG.md +367 -75
  2. package/README.md +55 -52
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -1
  4. package/api-report/tree.alpha.api.md +130 -145
  5. package/api-report/tree.beta.api.md +122 -91
  6. package/api-report/tree.legacy.beta.api.md +122 -91
  7. package/api-report/tree.legacy.public.api.md +26 -43
  8. package/api-report/tree.public.api.md +26 -43
  9. package/dist/api.d.ts +9 -1
  10. package/dist/api.d.ts.map +1 -1
  11. package/dist/api.js +2 -3
  12. package/dist/api.js.map +1 -1
  13. package/dist/codec/codec.d.ts +2 -2
  14. package/dist/codec/codec.d.ts.map +1 -1
  15. package/dist/codec/codec.js +9 -7
  16. package/dist/codec/codec.js.map +1 -1
  17. package/dist/codec/discriminatedUnions.js +1 -0
  18. package/dist/codec/discriminatedUnions.js.map +1 -1
  19. package/dist/codec/versioned/codec.d.ts.map +1 -1
  20. package/dist/codec/versioned/codec.js +4 -2
  21. package/dist/codec/versioned/codec.js.map +1 -1
  22. package/dist/componentApi.d.ts.map +1 -1
  23. package/dist/componentApi.js +20 -17
  24. package/dist/componentApi.js.map +1 -1
  25. package/dist/core/change-family/editBuilder.js +1 -0
  26. package/dist/core/change-family/editBuilder.js.map +1 -1
  27. package/dist/core/forest/editableForest.js +1 -2
  28. package/dist/core/forest/editableForest.js.map +1 -1
  29. package/dist/core/forest/forest.js +3 -3
  30. package/dist/core/forest/forest.js.map +1 -1
  31. package/dist/core/index.d.ts +2 -2
  32. package/dist/core/index.d.ts.map +1 -1
  33. package/dist/core/index.js +9 -5
  34. package/dist/core/index.js.map +1 -1
  35. package/dist/core/rebase/changeRebaser.js +5 -5
  36. package/dist/core/rebase/changeRebaser.js.map +1 -1
  37. package/dist/core/rebase/index.d.ts +1 -1
  38. package/dist/core/rebase/index.d.ts.map +1 -1
  39. package/dist/core/rebase/index.js +2 -1
  40. package/dist/core/rebase/index.js.map +1 -1
  41. package/dist/core/rebase/revisionTagCodec.d.ts +1 -1
  42. package/dist/core/rebase/revisionTagCodec.d.ts.map +1 -1
  43. package/dist/core/rebase/revisionTagCodec.js +3 -1
  44. package/dist/core/rebase/revisionTagCodec.js.map +1 -1
  45. package/dist/core/rebase/types.d.ts +12 -1
  46. package/dist/core/rebase/types.d.ts.map +1 -1
  47. package/dist/core/rebase/types.js +19 -15
  48. package/dist/core/rebase/types.js.map +1 -1
  49. package/dist/core/rebase/utils.js +9 -10
  50. package/dist/core/rebase/utils.js.map +1 -1
  51. package/dist/core/schema-stored/schema.js +9 -4
  52. package/dist/core/schema-stored/schema.js.map +1 -1
  53. package/dist/core/schema-stored/storedSchemaRepository.d.ts +1 -1
  54. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  55. package/dist/core/schema-stored/storedSchemaRepository.js +6 -4
  56. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  57. package/dist/core/tree/anchorSet.d.ts +1 -1
  58. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  59. package/dist/core/tree/anchorSet.js +62 -55
  60. package/dist/core/tree/anchorSet.js.map +1 -1
  61. package/dist/core/tree/chunk.js +2 -2
  62. package/dist/core/tree/chunk.js.map +1 -1
  63. package/dist/core/tree/cursor.js +12 -12
  64. package/dist/core/tree/cursor.js.map +1 -1
  65. package/dist/core/tree/deltaUtil.d.ts +34 -9
  66. package/dist/core/tree/deltaUtil.d.ts.map +1 -1
  67. package/dist/core/tree/deltaUtil.js +51 -17
  68. package/dist/core/tree/deltaUtil.js.map +1 -1
  69. package/dist/core/tree/detachedFieldIndex.js +23 -21
  70. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  71. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts +10 -10
  72. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -1
  73. package/dist/core/tree/detachedFieldIndexCodecCommon.js +1 -2
  74. package/dist/core/tree/detachedFieldIndexCodecCommon.js.map +1 -1
  75. package/dist/core/tree/detachedFieldIndexCodecV1.js +3 -2
  76. package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  77. package/dist/core/tree/detachedFieldIndexCodecV2.js +3 -2
  78. package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  79. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts +3 -3
  80. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -1
  81. package/dist/core/tree/detachedFieldIndexFormatV1.d.ts +1 -1
  82. package/dist/core/tree/detachedFieldIndexFormatV2.d.ts +2 -2
  83. package/dist/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -1
  84. package/dist/core/tree/index.d.ts +1 -1
  85. package/dist/core/tree/index.d.ts.map +1 -1
  86. package/dist/core/tree/index.js +7 -4
  87. package/dist/core/tree/index.js.map +1 -1
  88. package/dist/core/tree/mapTree.js +1 -2
  89. package/dist/core/tree/mapTree.js.map +1 -1
  90. package/dist/core/tree/pathTree.js +7 -8
  91. package/dist/core/tree/pathTree.js.map +1 -1
  92. package/dist/core/tree/persistedTreeTextFormat.d.ts +4 -4
  93. package/dist/core/tree/persistedTreeTextFormat.d.ts.map +1 -1
  94. package/dist/core/tree/sparseTree.js +17 -13
  95. package/dist/core/tree/sparseTree.js.map +1 -1
  96. package/dist/core/tree/treeTextFormat.js +4 -5
  97. package/dist/core/tree/treeTextFormat.js.map +1 -1
  98. package/dist/core/tree/types.js +3 -3
  99. package/dist/core/tree/types.js.map +1 -1
  100. package/dist/core/tree/visitDelta.js +1 -2
  101. package/dist/core/tree/visitDelta.js.map +1 -1
  102. package/dist/core/tree/visitorUtils.js +5 -6
  103. package/dist/core/tree/visitorUtils.js.map +1 -1
  104. package/dist/entrypoints/alpha.d.ts +1 -1
  105. package/dist/entrypoints/alpha.d.ts.map +1 -1
  106. package/dist/entrypoints/alpha.js +6 -4
  107. package/dist/entrypoints/alpha.js.map +1 -1
  108. package/dist/entrypoints/beta.d.ts +1 -1
  109. package/dist/entrypoints/beta.d.ts.map +1 -1
  110. package/dist/entrypoints/beta.js +2 -2
  111. package/dist/entrypoints/beta.js.map +1 -1
  112. package/dist/entrypoints/legacy.d.ts +1 -1
  113. package/dist/entrypoints/legacy.d.ts.map +1 -1
  114. package/dist/entrypoints/legacy.js +2 -2
  115. package/dist/entrypoints/legacy.js.map +1 -1
  116. package/dist/entrypoints/public.d.ts +1 -1
  117. package/dist/entrypoints/public.d.ts.map +1 -1
  118. package/dist/entrypoints/public.js +1 -2
  119. package/dist/entrypoints/public.js.map +1 -1
  120. package/dist/extensibleUnionNode.d.ts.map +1 -1
  121. package/dist/extensibleUnionNode.js +1 -1
  122. package/dist/extensibleUnionNode.js.map +1 -1
  123. package/dist/feature-libraries/changeAtomIdBTree.js +3 -4
  124. package/dist/feature-libraries/changeAtomIdBTree.js.map +1 -1
  125. package/dist/feature-libraries/changeAtomIdCodec.js +1 -2
  126. package/dist/feature-libraries/changeAtomIdCodec.js.map +1 -1
  127. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  128. package/dist/feature-libraries/chunked-forest/basicChunk.js +14 -1
  129. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  130. package/dist/feature-libraries/chunked-forest/chunkTree.js +28 -20
  131. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  132. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  133. package/dist/feature-libraries/chunked-forest/chunkedForest.js +22 -16
  134. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  135. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js +9 -11
  136. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  137. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +15 -7
  138. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  139. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +7 -3
  140. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  141. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +3 -2
  142. package/dist/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  143. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  144. package/dist/feature-libraries/chunked-forest/codec/codecs.js +2 -0
  145. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  146. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +33 -17
  147. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  148. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts +2 -2
  149. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts.map +1 -1
  150. package/dist/feature-libraries/chunked-forest/codec/format/versions.js +2 -2
  151. package/dist/feature-libraries/chunked-forest/codec/format/versions.js.map +1 -1
  152. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js +11 -2
  153. package/dist/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
  154. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +5 -6
  155. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  156. package/dist/feature-libraries/chunked-forest/codec/uncompressedEncode.js +2 -3
  157. package/dist/feature-libraries/chunked-forest/codec/uncompressedEncode.js.map +1 -1
  158. package/dist/feature-libraries/chunked-forest/sequenceChunk.js +1 -0
  159. package/dist/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  160. package/dist/feature-libraries/chunked-forest/uniformChunk.js +73 -15
  161. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  162. package/dist/feature-libraries/comparison-forest/comparisonForest.js +79 -79
  163. package/dist/feature-libraries/comparison-forest/comparisonForest.js.map +1 -1
  164. package/dist/feature-libraries/cursorComparator.d.ts +8 -0
  165. package/dist/feature-libraries/cursorComparator.d.ts.map +1 -1
  166. package/dist/feature-libraries/cursorComparator.js +43 -10
  167. package/dist/feature-libraries/cursorComparator.js.map +1 -1
  168. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +6 -3
  169. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  170. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +2 -2
  171. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  172. package/dist/feature-libraries/default-schema/mappedEditBuilder.js +2 -0
  173. package/dist/feature-libraries/default-schema/mappedEditBuilder.js.map +1 -1
  174. package/dist/feature-libraries/deltaUtils.js +2 -3
  175. package/dist/feature-libraries/deltaUtils.js.map +1 -1
  176. package/dist/feature-libraries/detachedFieldIndexSummarizer.js +2 -0
  177. package/dist/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  178. package/dist/feature-libraries/editableTreeBinder.js +1 -2
  179. package/dist/feature-libraries/editableTreeBinder.js.map +1 -1
  180. package/dist/feature-libraries/flex-tree/context.js +19 -3
  181. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  182. package/dist/feature-libraries/flex-tree/flexTreeTypes.js +2 -2
  183. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  184. package/dist/feature-libraries/flex-tree/lazyEntity.js +14 -14
  185. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  186. package/dist/feature-libraries/flex-tree/lazyField.js +28 -30
  187. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  188. package/dist/feature-libraries/flex-tree/lazyNode.js +24 -23
  189. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  190. package/dist/feature-libraries/flex-tree/observer.js +2 -2
  191. package/dist/feature-libraries/flex-tree/observer.js.map +1 -1
  192. package/dist/feature-libraries/flex-tree/utilities.js +5 -5
  193. package/dist/feature-libraries/flex-tree/utilities.js.map +1 -1
  194. package/dist/feature-libraries/forest-summary/forestSummarizer.js +122 -117
  195. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  196. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +49 -32
  197. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  198. package/dist/feature-libraries/forest-summary/summaryTypes.js +2 -3
  199. package/dist/feature-libraries/forest-summary/summaryTypes.js.map +1 -1
  200. package/dist/feature-libraries/indexing/anchorTreeIndex.js +35 -31
  201. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  202. package/dist/feature-libraries/mapTreeCursor.js +6 -7
  203. package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
  204. package/dist/feature-libraries/mitigatedChangeFamily.js +2 -3
  205. package/dist/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  206. package/dist/feature-libraries/modular-schema/comparison.js +6 -7
  207. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  208. package/dist/feature-libraries/modular-schema/crossFieldQueries.js +4 -4
  209. package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  210. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js +14 -12
  211. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  212. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +63 -10
  213. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  214. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js +3 -3
  215. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  216. package/dist/feature-libraries/modular-schema/fieldKind.js +10 -0
  217. package/dist/feature-libraries/modular-schema/fieldKind.js.map +1 -1
  218. package/dist/feature-libraries/modular-schema/filterEdits.d.ts +13 -0
  219. package/dist/feature-libraries/modular-schema/filterEdits.d.ts.map +1 -0
  220. package/dist/feature-libraries/modular-schema/filterEdits.js +51 -0
  221. package/dist/feature-libraries/modular-schema/filterEdits.js.map +1 -0
  222. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  223. package/dist/feature-libraries/modular-schema/genericFieldKind.js +7 -4
  224. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  225. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.js +1 -2
  226. package/dist/feature-libraries/modular-schema/genericFieldKindCodecs.js.map +1 -1
  227. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.d.ts +2 -2
  228. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.d.ts.map +1 -1
  229. package/dist/feature-libraries/modular-schema/genericFieldKindTypes.js +1 -2
  230. package/dist/feature-libraries/modular-schema/genericFieldKindTypes.js.map +1 -1
  231. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  232. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  233. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  234. package/dist/feature-libraries/modular-schema/invert.d.ts +1 -1
  235. package/dist/feature-libraries/modular-schema/invert.d.ts.map +1 -1
  236. package/dist/feature-libraries/modular-schema/invert.js +5 -30
  237. package/dist/feature-libraries/modular-schema/invert.js.map +1 -1
  238. package/dist/feature-libraries/modular-schema/isNeverTree.js +4 -5
  239. package/dist/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  240. package/dist/feature-libraries/modular-schema/minimizeModularChange.d.ts +5 -7
  241. package/dist/feature-libraries/modular-schema/minimizeModularChange.d.ts.map +1 -1
  242. package/dist/feature-libraries/modular-schema/minimizeModularChange.js +459 -10
  243. package/dist/feature-libraries/modular-schema/minimizeModularChange.js.map +1 -1
  244. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +14 -15
  245. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  246. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js +1 -2
  247. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -1
  248. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +2 -2
  249. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  250. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -10
  251. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  252. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +30 -97
  253. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  254. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +9 -9
  255. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  256. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +4 -4
  257. package/dist/feature-libraries/modular-schema/modularChangeTypes.js +1 -2
  258. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  259. package/dist/feature-libraries/modular-schema/modularChangeUtils.d.ts +13 -1
  260. package/dist/feature-libraries/modular-schema/modularChangeUtils.d.ts.map +1 -1
  261. package/dist/feature-libraries/modular-schema/modularChangeUtils.js +115 -12
  262. package/dist/feature-libraries/modular-schema/modularChangeUtils.js.map +1 -1
  263. package/dist/feature-libraries/modular-schema/prune.d.ts +2 -3
  264. package/dist/feature-libraries/modular-schema/prune.d.ts.map +1 -1
  265. package/dist/feature-libraries/modular-schema/prune.js +25 -8
  266. package/dist/feature-libraries/modular-schema/prune.js.map +1 -1
  267. package/dist/feature-libraries/node-identifier/mockNodeIdentifierManager.js +1 -3
  268. package/dist/feature-libraries/node-identifier/mockNodeIdentifierManager.js.map +1 -1
  269. package/dist/feature-libraries/node-identifier/nodeIdentifier.js +2 -2
  270. package/dist/feature-libraries/node-identifier/nodeIdentifier.js.map +1 -1
  271. package/dist/feature-libraries/node-identifier/nodeIdentifierManager.js +3 -3
  272. package/dist/feature-libraries/node-identifier/nodeIdentifierManager.js.map +1 -1
  273. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  274. package/dist/feature-libraries/object-forest/objectForest.js +274 -267
  275. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  276. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  277. package/dist/feature-libraries/optional-field/optionalField.js +27 -35
  278. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  279. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +7 -7
  280. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  281. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +8 -8
  282. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  283. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.js +1 -2
  284. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.js.map +1 -1
  285. package/dist/feature-libraries/optional-field/optionalFieldCodecs.d.ts.map +1 -1
  286. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +1 -2
  287. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  288. package/dist/feature-libraries/schema-index/schemaSummarizer.js +3 -0
  289. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  290. package/dist/feature-libraries/schemaChecker.js +5 -5
  291. package/dist/feature-libraries/schemaChecker.js.map +1 -1
  292. package/dist/feature-libraries/sequence-field/compose.js +8 -2
  293. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  294. package/dist/feature-libraries/sequence-field/filterEdits.d.ts +3 -3
  295. package/dist/feature-libraries/sequence-field/filterEdits.d.ts.map +1 -1
  296. package/dist/feature-libraries/sequence-field/filterEdits.js +29 -11
  297. package/dist/feature-libraries/sequence-field/filterEdits.js.map +1 -1
  298. package/dist/feature-libraries/sequence-field/formatV1.d.ts +102 -102
  299. package/dist/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  300. package/dist/feature-libraries/sequence-field/formatV2.d.ts +79 -79
  301. package/dist/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  302. package/dist/feature-libraries/sequence-field/formatV3.d.ts +56 -56
  303. package/dist/feature-libraries/sequence-field/formatV3.d.ts.map +1 -1
  304. package/dist/feature-libraries/sequence-field/invert.js +1 -2
  305. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  306. package/dist/feature-libraries/sequence-field/markListFactory.js +3 -4
  307. package/dist/feature-libraries/sequence-field/markListFactory.js.map +1 -1
  308. package/dist/feature-libraries/sequence-field/markQueue.js +4 -2
  309. package/dist/feature-libraries/sequence-field/markQueue.js.map +1 -1
  310. package/dist/feature-libraries/sequence-field/moveEffectTable.js +9 -9
  311. package/dist/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  312. package/dist/feature-libraries/sequence-field/prune.js +1 -2
  313. package/dist/feature-libraries/sequence-field/prune.js.map +1 -1
  314. package/dist/feature-libraries/sequence-field/rebase.js +7 -2
  315. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  316. package/dist/feature-libraries/sequence-field/relevantRemovedRoots.js +1 -2
  317. package/dist/feature-libraries/sequence-field/relevantRemovedRoots.js.map +1 -1
  318. package/dist/feature-libraries/sequence-field/replaceRevisions.js +1 -2
  319. package/dist/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  320. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +2 -3
  321. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  322. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js +1 -2
  323. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  324. package/dist/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  325. package/dist/feature-libraries/sequence-field/sequenceFieldEditor.d.ts +9 -9
  326. package/dist/feature-libraries/sequence-field/sequenceFieldEditor.d.ts.map +1 -1
  327. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +1 -2
  328. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  329. package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
  330. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  331. package/dist/feature-libraries/sequence-field/utils.js +54 -67
  332. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  333. package/dist/feature-libraries/treeCursorUtils.js +19 -15
  334. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  335. package/dist/feature-libraries/treeTextCursor.js +8 -8
  336. package/dist/feature-libraries/treeTextCursor.js.map +1 -1
  337. package/dist/feature-libraries/valueUtilities.js +4 -5
  338. package/dist/feature-libraries/valueUtilities.js.map +1 -1
  339. package/dist/index.d.ts +4 -29
  340. package/dist/index.d.ts.map +1 -1
  341. package/dist/index.js +6 -9
  342. package/dist/index.js.map +1 -1
  343. package/dist/internalTypes.d.ts +1 -1
  344. package/dist/internalTypes.d.ts.map +1 -1
  345. package/dist/internalTypes.js.map +1 -1
  346. package/dist/packageVersion.d.ts +1 -1
  347. package/dist/packageVersion.d.ts.map +1 -1
  348. package/dist/packageVersion.js +1 -1
  349. package/dist/packageVersion.js.map +1 -1
  350. package/dist/serializableDomainSchema.d.ts +1 -1
  351. package/dist/shared-tree/history.d.ts.map +1 -1
  352. package/dist/shared-tree/history.js +32 -13
  353. package/dist/shared-tree/history.js.map +1 -1
  354. package/dist/shared-tree/independentView.d.ts +27 -3
  355. package/dist/shared-tree/independentView.d.ts.map +1 -1
  356. package/dist/shared-tree/independentView.js +36 -7
  357. package/dist/shared-tree/independentView.js.map +1 -1
  358. package/dist/shared-tree/index.d.ts +2 -1
  359. package/dist/shared-tree/index.d.ts.map +1 -1
  360. package/dist/shared-tree/index.js +6 -2
  361. package/dist/shared-tree/index.js.map +1 -1
  362. package/dist/shared-tree/isAuditableFromOutcome.js +1 -2
  363. package/dist/shared-tree/isAuditableFromOutcome.js.map +1 -1
  364. package/dist/shared-tree/schematizeTree.js +3 -4
  365. package/dist/shared-tree/schematizeTree.js.map +1 -1
  366. package/dist/shared-tree/schematizingTreeView.d.ts +2 -2
  367. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  368. package/dist/shared-tree/schematizingTreeView.js +59 -26
  369. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  370. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  371. package/dist/shared-tree/sharedTree.js +28 -19
  372. package/dist/shared-tree/sharedTree.js.map +1 -1
  373. package/dist/shared-tree/sharedTreeChangeCodecs.js +3 -3
  374. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  375. package/dist/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  376. package/dist/shared-tree/sharedTreeChangeEnricher.js +12 -4
  377. package/dist/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  378. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  379. package/dist/shared-tree/sharedTreeChangeFamily.js +11 -8
  380. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  381. package/dist/shared-tree/sharedTreeChangeFormat.js +2 -3
  382. package/dist/shared-tree/sharedTreeChangeFormat.js.map +1 -1
  383. package/dist/shared-tree/sharedTreeEditBuilder.js +2 -0
  384. package/dist/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  385. package/dist/shared-tree/transactionMinimize.d.ts.map +1 -1
  386. package/dist/shared-tree/transactionMinimize.js +2 -1
  387. package/dist/shared-tree/transactionMinimize.js.map +1 -1
  388. package/dist/shared-tree/transactionPostProcessor.js +2 -3
  389. package/dist/shared-tree/transactionPostProcessor.js.map +1 -1
  390. package/dist/shared-tree/tree.js +2 -2
  391. package/dist/shared-tree/tree.js.map +1 -1
  392. package/dist/shared-tree/treeAlpha.d.ts +5 -16
  393. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  394. package/dist/shared-tree/treeAlpha.js +18 -11
  395. package/dist/shared-tree/treeAlpha.js.map +1 -1
  396. package/{lib/simple-tree/api → dist/shared-tree}/treeBeta.d.ts +8 -65
  397. package/dist/shared-tree/treeBeta.d.ts.map +1 -0
  398. package/dist/shared-tree/treeBeta.js +70 -0
  399. package/dist/shared-tree/treeBeta.js.map +1 -0
  400. package/dist/shared-tree/treeCheckout.d.ts +5 -0
  401. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  402. package/dist/shared-tree/treeCheckout.js +986 -907
  403. package/dist/shared-tree/treeCheckout.js.map +1 -1
  404. package/dist/shared-tree/unhydratedTreeContext.js +3 -4
  405. package/dist/shared-tree/unhydratedTreeContext.js.map +1 -1
  406. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  407. package/dist/shared-tree-core/branch.js +24 -20
  408. package/dist/shared-tree-core/branch.js.map +1 -1
  409. package/dist/shared-tree-core/branchCommitCounter.js +35 -32
  410. package/dist/shared-tree-core/branchCommitCounter.js.map +1 -1
  411. package/dist/shared-tree-core/branchCommitEnricher.js +9 -8
  412. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  413. package/dist/shared-tree-core/branchIdCodec.js +2 -3
  414. package/dist/shared-tree-core/branchIdCodec.js.map +1 -1
  415. package/dist/shared-tree-core/customMetadataCodec.js +2 -3
  416. package/dist/shared-tree-core/customMetadataCodec.js.map +1 -1
  417. package/dist/shared-tree-core/customMetadataFormat.d.ts.map +1 -1
  418. package/dist/shared-tree-core/defaultResubmitMachine.js +11 -9
  419. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  420. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  421. package/dist/shared-tree-core/editManager.js +73 -44
  422. package/dist/shared-tree-core/editManager.js.map +1 -1
  423. package/dist/shared-tree-core/editManagerCodecs.js +3 -3
  424. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  425. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +1 -1
  426. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  427. package/dist/shared-tree-core/editManagerCodecsCommons.js +33 -36
  428. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  429. package/dist/shared-tree-core/editManagerCodecsV1toV4.js +1 -2
  430. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  431. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js +1 -2
  432. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  433. package/dist/shared-tree-core/editManagerFormatCommons.d.ts +11 -11
  434. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  435. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +5 -4
  436. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  437. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts +10 -9
  438. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
  439. package/dist/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  440. package/dist/shared-tree-core/editManagerSummarizer.js +6 -1
  441. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  442. package/dist/shared-tree-core/messageCodecV1ToV4.js +1 -2
  443. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  444. package/dist/shared-tree-core/messageCodecVSharedBranches.js +1 -2
  445. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  446. package/dist/shared-tree-core/messageCodecs.js +3 -3
  447. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  448. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts +3 -2
  449. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  450. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts +3 -2
  451. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  452. package/dist/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  453. package/dist/shared-tree-core/sharedTreeCore.js +44 -22
  454. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  455. package/dist/shared-tree-core/summaryTypes.js +2 -2
  456. package/dist/shared-tree-core/summaryTypes.js.map +1 -1
  457. package/dist/shared-tree-core/transaction.js +36 -39
  458. package/dist/shared-tree-core/transaction.js.map +1 -1
  459. package/dist/shared-tree-core/versionedSummarizer.js +4 -0
  460. package/dist/shared-tree-core/versionedSummarizer.js.map +1 -1
  461. package/dist/simple-tree/api/cloneTree.d.ts +11 -0
  462. package/dist/simple-tree/api/cloneTree.d.ts.map +1 -0
  463. package/dist/simple-tree/api/cloneTree.js +31 -0
  464. package/dist/simple-tree/api/cloneTree.js.map +1 -0
  465. package/dist/simple-tree/api/conciseTree.js +2 -3
  466. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  467. package/dist/simple-tree/api/configuration.js +21 -2
  468. package/dist/simple-tree/api/configuration.js.map +1 -1
  469. package/dist/simple-tree/api/create.js +2 -3
  470. package/dist/simple-tree/api/create.js.map +1 -1
  471. package/dist/simple-tree/api/customTree.js +6 -6
  472. package/dist/simple-tree/api/customTree.js.map +1 -1
  473. package/dist/simple-tree/api/dirtyIndex.js +1 -2
  474. package/dist/simple-tree/api/dirtyIndex.js.map +1 -1
  475. package/dist/simple-tree/api/discrepancies.js +2 -3
  476. package/dist/simple-tree/api/discrepancies.js.map +1 -1
  477. package/dist/simple-tree/api/eraseSchemaDetails.js +2 -3
  478. package/dist/simple-tree/api/eraseSchemaDetails.js.map +1 -1
  479. package/dist/simple-tree/api/getJsonSchema.js +1 -2
  480. package/dist/simple-tree/api/getJsonSchema.js.map +1 -1
  481. package/dist/simple-tree/api/getSimpleSchema.js +1 -2
  482. package/dist/simple-tree/api/getSimpleSchema.js.map +1 -1
  483. package/dist/simple-tree/api/identifierIndex.js +1 -2
  484. package/dist/simple-tree/api/identifierIndex.js.map +1 -1
  485. package/dist/simple-tree/api/incrementalAllowedTypes.js +2 -2
  486. package/dist/simple-tree/api/incrementalAllowedTypes.js.map +1 -1
  487. package/dist/simple-tree/api/index.d.ts +3 -3
  488. package/dist/simple-tree/api/index.d.ts.map +1 -1
  489. package/dist/simple-tree/api/index.js +4 -7
  490. package/dist/simple-tree/api/index.js.map +1 -1
  491. package/dist/simple-tree/api/schemaCompatibilityTester.js +2 -3
  492. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  493. package/dist/simple-tree/api/schemaCreationUtilities.d.ts +3 -7
  494. package/dist/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  495. package/dist/simple-tree/api/schemaCreationUtilities.js +6 -9
  496. package/dist/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  497. package/dist/simple-tree/api/schemaFactory.d.ts +4 -9
  498. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  499. package/dist/simple-tree/api/schemaFactory.js +13 -12
  500. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  501. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +20 -22
  502. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  503. package/dist/simple-tree/api/schemaFactoryAlpha.js +78 -81
  504. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  505. package/dist/simple-tree/api/schemaFactoryBeta.d.ts +7 -9
  506. package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
  507. package/dist/simple-tree/api/schemaFactoryBeta.js +32 -35
  508. package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -1
  509. package/dist/simple-tree/api/schemaFactoryRecursive.js +1 -2
  510. package/dist/simple-tree/api/schemaFactoryRecursive.js.map +1 -1
  511. package/dist/simple-tree/api/schemaFromSimple.js +1 -2
  512. package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
  513. package/dist/simple-tree/api/schemaStatics.d.ts +7 -7
  514. package/dist/simple-tree/api/schemaStatics.d.ts.map +1 -1
  515. package/dist/simple-tree/api/simpleSchemaCodec.js +2 -3
  516. package/dist/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  517. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +2 -3
  518. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  519. package/dist/simple-tree/api/simpleTreeIndex.js +1 -2
  520. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  521. package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts +46 -2
  522. package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
  523. package/dist/simple-tree/api/snapshotCompatibilityChecker.js +54 -12
  524. package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  525. package/dist/simple-tree/api/storedSchema.js +2 -3
  526. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  527. package/dist/simple-tree/api/transactionTypes.d.ts +4 -4
  528. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  529. package/dist/simple-tree/api/tree.d.ts +80 -61
  530. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  531. package/dist/simple-tree/api/tree.js +3 -5
  532. package/dist/simple-tree/api/tree.js.map +1 -1
  533. package/dist/simple-tree/api/treeChangeEvents.d.ts +16 -4
  534. package/dist/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
  535. package/dist/simple-tree/api/treeChangeEvents.js.map +1 -1
  536. package/dist/simple-tree/api/treeChangeEventsBeta.d.ts +209 -0
  537. package/dist/simple-tree/api/treeChangeEventsBeta.d.ts.map +1 -0
  538. package/dist/simple-tree/api/{treeAlpha.js → treeChangeEventsBeta.js} +1 -1
  539. package/dist/simple-tree/api/treeChangeEventsBeta.js.map +1 -0
  540. package/dist/simple-tree/api/treeNodeApi.d.ts +1 -75
  541. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  542. package/dist/simple-tree/api/treeNodeApi.js +7 -7
  543. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  544. package/dist/simple-tree/api/typesUnsafe.d.ts +8 -6
  545. package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  546. package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
  547. package/dist/simple-tree/api/verboseTree.js +5 -6
  548. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  549. package/dist/simple-tree/core/allowedTypes.js +22 -13
  550. package/dist/simple-tree/core/allowedTypes.js.map +1 -1
  551. package/dist/simple-tree/core/context.js +3 -0
  552. package/dist/simple-tree/core/context.js.map +1 -1
  553. package/dist/simple-tree/core/flexList.js +2 -3
  554. package/dist/simple-tree/core/flexList.js.map +1 -1
  555. package/dist/simple-tree/core/getOrCreateNode.js +2 -3
  556. package/dist/simple-tree/core/getOrCreateNode.js.map +1 -1
  557. package/dist/simple-tree/core/index.d.ts +1 -1
  558. package/dist/simple-tree/core/index.d.ts.map +1 -1
  559. package/dist/simple-tree/core/index.js +2 -2
  560. package/dist/simple-tree/core/index.js.map +1 -1
  561. package/dist/simple-tree/core/treeNode.d.ts +3 -4
  562. package/dist/simple-tree/core/treeNode.d.ts.map +1 -1
  563. package/dist/simple-tree/core/treeNode.js +31 -32
  564. package/dist/simple-tree/core/treeNode.js.map +1 -1
  565. package/dist/simple-tree/core/treeNodeKernel.js +194 -192
  566. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  567. package/dist/simple-tree/core/treeNodeSchema.js +3 -3
  568. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  569. package/dist/simple-tree/core/treeNodeValid.js +23 -23
  570. package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
  571. package/dist/simple-tree/core/types.js +1 -2
  572. package/dist/simple-tree/core/types.js.map +1 -1
  573. package/dist/simple-tree/core/unhydratedFlexTree.js +177 -150
  574. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  575. package/dist/simple-tree/core/walkSchema.js +2 -3
  576. package/dist/simple-tree/core/walkSchema.js.map +1 -1
  577. package/dist/simple-tree/core/withType.d.ts +7 -9
  578. package/dist/simple-tree/core/withType.d.ts.map +1 -1
  579. package/dist/simple-tree/core/withType.js +6 -7
  580. package/dist/simple-tree/core/withType.js.map +1 -1
  581. package/dist/simple-tree/createContext.js +2 -3
  582. package/dist/simple-tree/createContext.js.map +1 -1
  583. package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
  584. package/dist/simple-tree/fieldSchema.js +33 -15
  585. package/dist/simple-tree/fieldSchema.js.map +1 -1
  586. package/dist/simple-tree/getTreeNodeForField.js +1 -2
  587. package/dist/simple-tree/getTreeNodeForField.js.map +1 -1
  588. package/dist/simple-tree/index.d.ts +2 -2
  589. package/dist/simple-tree/index.d.ts.map +1 -1
  590. package/dist/simple-tree/index.js +5 -8
  591. package/dist/simple-tree/index.js.map +1 -1
  592. package/dist/simple-tree/leafNodeSchema.d.ts +1 -1
  593. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  594. package/dist/simple-tree/leafNodeSchema.js +18 -17
  595. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  596. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +3 -2
  597. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  598. package/dist/simple-tree/node-kinds/array/arrayNode.js +31 -33
  599. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  600. package/dist/simple-tree/node-kinds/array/arrayNodeTypes.d.ts.map +1 -1
  601. package/dist/simple-tree/node-kinds/array/arrayNodeTypes.js +2 -2
  602. package/dist/simple-tree/node-kinds/array/arrayNodeTypes.js.map +1 -1
  603. package/dist/simple-tree/node-kinds/common.js +1 -2
  604. package/dist/simple-tree/node-kinds/common.js.map +1 -1
  605. package/dist/simple-tree/node-kinds/map/mapNode.d.ts +6 -6
  606. package/dist/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  607. package/dist/simple-tree/node-kinds/map/mapNode.js +10 -16
  608. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  609. package/dist/simple-tree/node-kinds/map/mapNodeTypes.d.ts.map +1 -1
  610. package/dist/simple-tree/node-kinds/map/mapNodeTypes.js +2 -2
  611. package/dist/simple-tree/node-kinds/map/mapNodeTypes.js.map +1 -1
  612. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  613. package/dist/simple-tree/node-kinds/object/objectNode.js +27 -28
  614. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  615. package/dist/simple-tree/node-kinds/object/objectNodeTypes.d.ts +1 -1
  616. package/dist/simple-tree/node-kinds/object/objectNodeTypes.d.ts.map +1 -1
  617. package/dist/simple-tree/node-kinds/object/objectNodeTypes.js +2 -2
  618. package/dist/simple-tree/node-kinds/object/objectNodeTypes.js.map +1 -1
  619. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  620. package/dist/simple-tree/node-kinds/record/recordNode.js +10 -13
  621. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  622. package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts +3 -2
  623. package/dist/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
  624. package/dist/simple-tree/node-kinds/record/recordNodeTypes.js +2 -2
  625. package/dist/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
  626. package/dist/simple-tree/prepareForInsertion.js +4 -5
  627. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  628. package/dist/simple-tree/toStoredSchema.js +11 -11
  629. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  630. package/dist/simple-tree/treeSchema.js +1 -2
  631. package/dist/simple-tree/treeSchema.js.map +1 -1
  632. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js +3 -4
  633. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  634. package/dist/simple-tree/walkFieldSchema.js +1 -2
  635. package/dist/simple-tree/walkFieldSchema.js.map +1 -1
  636. package/dist/tableSchema.d.ts +2 -87
  637. package/dist/tableSchema.d.ts.map +1 -1
  638. package/dist/tableSchema.js +309 -275
  639. package/dist/tableSchema.js.map +1 -1
  640. package/dist/text/codePointUtils.d.ts +16 -3
  641. package/dist/text/codePointUtils.d.ts.map +1 -1
  642. package/dist/text/codePointUtils.js +24 -13
  643. package/dist/text/codePointUtils.js.map +1 -1
  644. package/dist/text/textDomain.d.ts +7 -1
  645. package/dist/text/textDomain.d.ts.map +1 -1
  646. package/dist/text/textDomain.js +32 -28
  647. package/dist/text/textDomain.js.map +1 -1
  648. package/dist/text/textDomainFormatted.d.ts.map +1 -1
  649. package/dist/text/textDomainFormatted.js +45 -34
  650. package/dist/text/textDomainFormatted.js.map +1 -1
  651. package/dist/text/textDomainFormattedDefault.js +2 -5
  652. package/dist/text/textDomainFormattedDefault.js.map +1 -1
  653. package/dist/treeDataStore.js +2 -3
  654. package/dist/treeDataStore.js.map +1 -1
  655. package/dist/treeFactory.js +7 -7
  656. package/dist/treeFactory.js.map +1 -1
  657. package/dist/util/arrayUtilities.js +5 -6
  658. package/dist/util/arrayUtilities.js.map +1 -1
  659. package/dist/util/bTreeUtils.js +3 -4
  660. package/dist/util/bTreeUtils.js.map +1 -1
  661. package/dist/util/brand.js +6 -5
  662. package/dist/util/brand.js.map +1 -1
  663. package/dist/util/brandedMap.js +2 -3
  664. package/dist/util/brandedMap.js.map +1 -1
  665. package/dist/util/breakable.d.ts.map +1 -1
  666. package/dist/util/breakable.js +7 -4
  667. package/dist/util/breakable.js.map +1 -1
  668. package/dist/util/cloneWithReplacements.js +1 -2
  669. package/dist/util/cloneWithReplacements.js.map +1 -1
  670. package/dist/util/compressedIds.js +29 -7
  671. package/dist/util/compressedIds.js.map +1 -1
  672. package/dist/util/idAllocator.js +3 -3
  673. package/dist/util/idAllocator.js.map +1 -1
  674. package/dist/util/nestedMap.js +15 -17
  675. package/dist/util/nestedMap.js.map +1 -1
  676. package/dist/util/nestedSet.js +2 -3
  677. package/dist/util/nestedSet.js.map +1 -1
  678. package/dist/util/offsetList.js +2 -4
  679. package/dist/util/offsetList.js.map +1 -1
  680. package/dist/util/opaque.js +2 -3
  681. package/dist/util/opaque.js.map +1 -1
  682. package/dist/util/rangeMap.js +6 -2
  683. package/dist/util/rangeMap.js.map +1 -1
  684. package/dist/util/readSnapshotBlob.d.ts.map +1 -1
  685. package/dist/util/referenceCounting.js +1 -0
  686. package/dist/util/referenceCounting.js.map +1 -1
  687. package/dist/util/stackyIterator.js +3 -2
  688. package/dist/util/stackyIterator.js.map +1 -1
  689. package/dist/util/typeUtils.js +1 -2
  690. package/dist/util/typeUtils.js.map +1 -1
  691. package/dist/util/typeboxBrand.js +2 -3
  692. package/dist/util/typeboxBrand.js.map +1 -1
  693. package/dist/util/utils.d.ts +2 -2
  694. package/dist/util/utils.d.ts.map +1 -1
  695. package/dist/util/utils.js +32 -32
  696. package/dist/util/utils.js.map +1 -1
  697. package/lib/api.d.ts +9 -1
  698. package/lib/api.d.ts.map +1 -1
  699. package/lib/api.js.map +1 -1
  700. package/lib/codec/codec.d.ts +2 -2
  701. package/lib/codec/codec.d.ts.map +1 -1
  702. package/lib/codec/codec.js +2 -0
  703. package/lib/codec/codec.js.map +1 -1
  704. package/lib/codec/discriminatedUnions.js +1 -0
  705. package/lib/codec/discriminatedUnions.js.map +1 -1
  706. package/lib/codec/versioned/codec.d.ts.map +1 -1
  707. package/lib/codec/versioned/codec.js +2 -0
  708. package/lib/codec/versioned/codec.js.map +1 -1
  709. package/lib/componentApi.d.ts.map +1 -1
  710. package/lib/componentApi.js +20 -17
  711. package/lib/componentApi.js.map +1 -1
  712. package/lib/core/change-family/editBuilder.js +1 -0
  713. package/lib/core/change-family/editBuilder.js.map +1 -1
  714. package/lib/core/index.d.ts +2 -2
  715. package/lib/core/index.d.ts.map +1 -1
  716. package/lib/core/index.js +2 -2
  717. package/lib/core/index.js.map +1 -1
  718. package/lib/core/rebase/index.d.ts +1 -1
  719. package/lib/core/rebase/index.d.ts.map +1 -1
  720. package/lib/core/rebase/index.js +1 -1
  721. package/lib/core/rebase/index.js.map +1 -1
  722. package/lib/core/rebase/revisionTagCodec.js +3 -1
  723. package/lib/core/rebase/revisionTagCodec.js.map +1 -1
  724. package/lib/core/rebase/types.d.ts +12 -1
  725. package/lib/core/rebase/types.d.ts.map +1 -1
  726. package/lib/core/rebase/types.js +3 -0
  727. package/lib/core/rebase/types.js.map +1 -1
  728. package/lib/core/schema-stored/schema.js +5 -0
  729. package/lib/core/schema-stored/schema.js.map +1 -1
  730. package/lib/core/schema-stored/storedSchemaRepository.js +4 -2
  731. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  732. package/lib/core/tree/anchorSet.js +61 -54
  733. package/lib/core/tree/anchorSet.js.map +1 -1
  734. package/lib/core/tree/deltaUtil.d.ts +34 -9
  735. package/lib/core/tree/deltaUtil.d.ts.map +1 -1
  736. package/lib/core/tree/deltaUtil.js +41 -10
  737. package/lib/core/tree/deltaUtil.js.map +1 -1
  738. package/lib/core/tree/detachedFieldIndex.js +23 -21
  739. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  740. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts +10 -10
  741. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -1
  742. package/lib/core/tree/detachedFieldIndexCodecV1.js +2 -0
  743. package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  744. package/lib/core/tree/detachedFieldIndexCodecV2.js +2 -0
  745. package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  746. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts +3 -3
  747. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -1
  748. package/lib/core/tree/index.d.ts +1 -1
  749. package/lib/core/tree/index.d.ts.map +1 -1
  750. package/lib/core/tree/index.js +1 -1
  751. package/lib/core/tree/index.js.map +1 -1
  752. package/lib/core/tree/persistedTreeTextFormat.d.ts +4 -4
  753. package/lib/core/tree/persistedTreeTextFormat.d.ts.map +1 -1
  754. package/lib/core/tree/sparseTree.js +15 -11
  755. package/lib/core/tree/sparseTree.js.map +1 -1
  756. package/lib/entrypoints/alpha.d.ts +1 -1
  757. package/lib/entrypoints/alpha.d.ts.map +1 -1
  758. package/lib/entrypoints/alpha.js +1 -1
  759. package/lib/entrypoints/alpha.js.map +1 -1
  760. package/lib/entrypoints/beta.d.ts +1 -1
  761. package/lib/entrypoints/beta.d.ts.map +1 -1
  762. package/lib/entrypoints/beta.js +1 -1
  763. package/lib/entrypoints/beta.js.map +1 -1
  764. package/lib/entrypoints/legacy.d.ts +1 -1
  765. package/lib/entrypoints/legacy.d.ts.map +1 -1
  766. package/lib/entrypoints/legacy.js +1 -1
  767. package/lib/entrypoints/legacy.js.map +1 -1
  768. package/lib/entrypoints/public.d.ts +1 -1
  769. package/lib/entrypoints/public.d.ts.map +1 -1
  770. package/lib/entrypoints/public.js +1 -1
  771. package/lib/entrypoints/public.js.map +1 -1
  772. package/lib/extensibleUnionNode.d.ts.map +1 -1
  773. package/lib/extensibleUnionNode.js +2 -2
  774. package/lib/extensibleUnionNode.js.map +1 -1
  775. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  776. package/lib/feature-libraries/chunked-forest/basicChunk.js +14 -1
  777. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  778. package/lib/feature-libraries/chunked-forest/chunkTree.js +14 -6
  779. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  780. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  781. package/lib/feature-libraries/chunked-forest/chunkedForest.js +18 -12
  782. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  783. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js +1 -3
  784. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  785. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +8 -0
  786. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  787. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js +4 -0
  788. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  789. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js +1 -0
  790. package/lib/feature-libraries/chunked-forest/codec/chunkEncodingGeneric.js.map +1 -1
  791. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  792. package/lib/feature-libraries/chunked-forest/codec/codecs.js +2 -0
  793. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  794. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +28 -12
  795. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  796. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts +2 -2
  797. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts.map +1 -1
  798. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js +9 -0
  799. package/lib/feature-libraries/chunked-forest/codec/nodeEncoder.js.map +1 -1
  800. package/lib/feature-libraries/chunked-forest/sequenceChunk.js +1 -0
  801. package/lib/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  802. package/lib/feature-libraries/chunked-forest/uniformChunk.js +71 -13
  803. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  804. package/lib/feature-libraries/comparison-forest/comparisonForest.js +79 -79
  805. package/lib/feature-libraries/comparison-forest/comparisonForest.js.map +1 -1
  806. package/lib/feature-libraries/cursorComparator.d.ts +8 -0
  807. package/lib/feature-libraries/cursorComparator.d.ts.map +1 -1
  808. package/lib/feature-libraries/cursorComparator.js +43 -9
  809. package/lib/feature-libraries/cursorComparator.js.map +1 -1
  810. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  811. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  812. package/lib/feature-libraries/default-schema/mappedEditBuilder.js +2 -0
  813. package/lib/feature-libraries/default-schema/mappedEditBuilder.js.map +1 -1
  814. package/lib/feature-libraries/detachedFieldIndexSummarizer.js +2 -0
  815. package/lib/feature-libraries/detachedFieldIndexSummarizer.js.map +1 -1
  816. package/lib/feature-libraries/flex-tree/context.js +19 -3
  817. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  818. package/lib/feature-libraries/flex-tree/lazyEntity.js +12 -12
  819. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  820. package/lib/feature-libraries/flex-tree/lazyField.js +25 -27
  821. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  822. package/lib/feature-libraries/flex-tree/lazyNode.js +22 -21
  823. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  824. package/lib/feature-libraries/forest-summary/forestSummarizer.js +122 -117
  825. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  826. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +49 -32
  827. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  828. package/lib/feature-libraries/indexing/anchorTreeIndex.js +33 -29
  829. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  830. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js +14 -12
  831. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -1
  832. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +63 -10
  833. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  834. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  835. package/lib/feature-libraries/modular-schema/fieldKind.js +10 -0
  836. package/lib/feature-libraries/modular-schema/fieldKind.js.map +1 -1
  837. package/lib/feature-libraries/modular-schema/filterEdits.d.ts +13 -0
  838. package/lib/feature-libraries/modular-schema/filterEdits.d.ts.map +1 -0
  839. package/lib/feature-libraries/modular-schema/filterEdits.js +46 -0
  840. package/lib/feature-libraries/modular-schema/filterEdits.js.map +1 -0
  841. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  842. package/lib/feature-libraries/modular-schema/genericFieldKind.js +5 -2
  843. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  844. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.d.ts +2 -2
  845. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.d.ts.map +1 -1
  846. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  847. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  848. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  849. package/lib/feature-libraries/modular-schema/invert.d.ts +1 -1
  850. package/lib/feature-libraries/modular-schema/invert.d.ts.map +1 -1
  851. package/lib/feature-libraries/modular-schema/invert.js +6 -30
  852. package/lib/feature-libraries/modular-schema/invert.js.map +1 -1
  853. package/lib/feature-libraries/modular-schema/minimizeModularChange.d.ts +5 -7
  854. package/lib/feature-libraries/modular-schema/minimizeModularChange.d.ts.map +1 -1
  855. package/lib/feature-libraries/modular-schema/minimizeModularChange.js +458 -8
  856. package/lib/feature-libraries/modular-schema/minimizeModularChange.js.map +1 -1
  857. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +1 -10
  858. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  859. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +20 -85
  860. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  861. package/lib/feature-libraries/modular-schema/modularChangeUtils.d.ts +13 -1
  862. package/lib/feature-libraries/modular-schema/modularChangeUtils.d.ts.map +1 -1
  863. package/lib/feature-libraries/modular-schema/modularChangeUtils.js +100 -3
  864. package/lib/feature-libraries/modular-schema/modularChangeUtils.js.map +1 -1
  865. package/lib/feature-libraries/modular-schema/prune.d.ts +2 -3
  866. package/lib/feature-libraries/modular-schema/prune.d.ts.map +1 -1
  867. package/lib/feature-libraries/modular-schema/prune.js +25 -7
  868. package/lib/feature-libraries/modular-schema/prune.js.map +1 -1
  869. package/lib/feature-libraries/node-identifier/mockNodeIdentifierManager.js +1 -3
  870. package/lib/feature-libraries/node-identifier/mockNodeIdentifierManager.js.map +1 -1
  871. package/lib/feature-libraries/node-identifier/nodeIdentifierManager.js +1 -0
  872. package/lib/feature-libraries/node-identifier/nodeIdentifierManager.js.map +1 -1
  873. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  874. package/lib/feature-libraries/object-forest/objectForest.js +273 -266
  875. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  876. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  877. package/lib/feature-libraries/optional-field/optionalField.js +24 -32
  878. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  879. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +1 -1
  880. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  881. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +1 -1
  882. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  883. package/lib/feature-libraries/optional-field/optionalFieldCodecs.d.ts.map +1 -1
  884. package/lib/feature-libraries/schema-index/schemaSummarizer.js +3 -0
  885. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  886. package/lib/feature-libraries/sequence-field/compose.js +6 -0
  887. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  888. package/lib/feature-libraries/sequence-field/filterEdits.d.ts +3 -3
  889. package/lib/feature-libraries/sequence-field/filterEdits.d.ts.map +1 -1
  890. package/lib/feature-libraries/sequence-field/filterEdits.js +31 -12
  891. package/lib/feature-libraries/sequence-field/filterEdits.js.map +1 -1
  892. package/lib/feature-libraries/sequence-field/formatV1.d.ts +3 -3
  893. package/lib/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  894. package/lib/feature-libraries/sequence-field/formatV2.d.ts +3 -3
  895. package/lib/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  896. package/lib/feature-libraries/sequence-field/formatV3.d.ts +2 -2
  897. package/lib/feature-libraries/sequence-field/formatV3.d.ts.map +1 -1
  898. package/lib/feature-libraries/sequence-field/markListFactory.js +3 -4
  899. package/lib/feature-libraries/sequence-field/markListFactory.js.map +1 -1
  900. package/lib/feature-libraries/sequence-field/markQueue.js +4 -2
  901. package/lib/feature-libraries/sequence-field/markQueue.js.map +1 -1
  902. package/lib/feature-libraries/sequence-field/rebase.js +6 -0
  903. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  904. package/lib/feature-libraries/sequence-field/sequenceFieldCodecs.d.ts.map +1 -1
  905. package/lib/feature-libraries/sequence-field/sequenceFieldEditor.d.ts +9 -9
  906. package/lib/feature-libraries/sequence-field/sequenceFieldEditor.d.ts.map +1 -1
  907. package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
  908. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  909. package/lib/feature-libraries/sequence-field/utils.js +3 -15
  910. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  911. package/lib/feature-libraries/treeCursorUtils.js +13 -9
  912. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  913. package/lib/index.d.ts +4 -29
  914. package/lib/index.d.ts.map +1 -1
  915. package/lib/index.js +2 -17
  916. package/lib/index.js.map +1 -1
  917. package/lib/internalTypes.d.ts +1 -1
  918. package/lib/internalTypes.d.ts.map +1 -1
  919. package/lib/internalTypes.js.map +1 -1
  920. package/lib/packageVersion.d.ts +1 -1
  921. package/lib/packageVersion.d.ts.map +1 -1
  922. package/lib/packageVersion.js +1 -1
  923. package/lib/packageVersion.js.map +1 -1
  924. package/lib/serializableDomainSchema.d.ts +1 -1
  925. package/lib/shared-tree/history.d.ts.map +1 -1
  926. package/lib/shared-tree/history.js +32 -13
  927. package/lib/shared-tree/history.js.map +1 -1
  928. package/lib/shared-tree/independentView.d.ts +27 -3
  929. package/lib/shared-tree/independentView.d.ts.map +1 -1
  930. package/lib/shared-tree/independentView.js +30 -2
  931. package/lib/shared-tree/independentView.js.map +1 -1
  932. package/lib/shared-tree/index.d.ts +2 -1
  933. package/lib/shared-tree/index.d.ts.map +1 -1
  934. package/lib/shared-tree/index.js +2 -1
  935. package/lib/shared-tree/index.js.map +1 -1
  936. package/lib/shared-tree/schematizingTreeView.d.ts +2 -2
  937. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  938. package/lib/shared-tree/schematizingTreeView.js +60 -27
  939. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  940. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  941. package/lib/shared-tree/sharedTree.js +24 -15
  942. package/lib/shared-tree/sharedTree.js.map +1 -1
  943. package/lib/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  944. package/lib/shared-tree/sharedTreeChangeEnricher.js +12 -4
  945. package/lib/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  946. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  947. package/lib/shared-tree/sharedTreeChangeFamily.js +6 -3
  948. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  949. package/lib/shared-tree/sharedTreeEditBuilder.js +2 -0
  950. package/lib/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  951. package/lib/shared-tree/transactionMinimize.d.ts.map +1 -1
  952. package/lib/shared-tree/transactionMinimize.js +4 -3
  953. package/lib/shared-tree/transactionMinimize.js.map +1 -1
  954. package/lib/shared-tree/treeAlpha.d.ts +5 -16
  955. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  956. package/lib/shared-tree/treeAlpha.js +13 -6
  957. package/lib/shared-tree/treeAlpha.js.map +1 -1
  958. package/{dist/simple-tree/api → lib/shared-tree}/treeBeta.d.ts +8 -65
  959. package/lib/shared-tree/treeBeta.d.ts.map +1 -0
  960. package/lib/shared-tree/treeBeta.js +64 -0
  961. package/lib/shared-tree/treeBeta.js.map +1 -0
  962. package/lib/shared-tree/treeCheckout.d.ts +5 -0
  963. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  964. package/lib/shared-tree/treeCheckout.js +985 -906
  965. package/lib/shared-tree/treeCheckout.js.map +1 -1
  966. package/lib/shared-tree/unhydratedTreeContext.js +3 -4
  967. package/lib/shared-tree/unhydratedTreeContext.js.map +1 -1
  968. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  969. package/lib/shared-tree-core/branch.js +22 -18
  970. package/lib/shared-tree-core/branch.js.map +1 -1
  971. package/lib/shared-tree-core/branchCommitCounter.js +35 -32
  972. package/lib/shared-tree-core/branchCommitCounter.js.map +1 -1
  973. package/lib/shared-tree-core/branchCommitEnricher.js +9 -8
  974. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  975. package/lib/shared-tree-core/customMetadataFormat.d.ts.map +1 -1
  976. package/lib/shared-tree-core/defaultResubmitMachine.js +11 -9
  977. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  978. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  979. package/lib/shared-tree-core/editManager.js +73 -44
  980. package/lib/shared-tree-core/editManager.js.map +1 -1
  981. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +1 -1
  982. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  983. package/lib/shared-tree-core/editManagerCodecsCommons.js +32 -34
  984. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  985. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  986. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  987. package/lib/shared-tree-core/editManagerFormatCommons.d.ts +4 -4
  988. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  989. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +2 -1
  990. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  991. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts +2 -1
  992. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
  993. package/lib/shared-tree-core/editManagerSummarizer.d.ts.map +1 -1
  994. package/lib/shared-tree-core/editManagerSummarizer.js +6 -1
  995. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  996. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts +2 -1
  997. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  998. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts +2 -1
  999. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  1000. package/lib/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  1001. package/lib/shared-tree-core/sharedTreeCore.js +45 -23
  1002. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  1003. package/lib/shared-tree-core/transaction.js +36 -39
  1004. package/lib/shared-tree-core/transaction.js.map +1 -1
  1005. package/lib/shared-tree-core/versionedSummarizer.js +4 -0
  1006. package/lib/shared-tree-core/versionedSummarizer.js.map +1 -1
  1007. package/lib/simple-tree/api/cloneTree.d.ts +11 -0
  1008. package/lib/simple-tree/api/cloneTree.d.ts.map +1 -0
  1009. package/lib/simple-tree/api/cloneTree.js +28 -0
  1010. package/lib/simple-tree/api/cloneTree.js.map +1 -0
  1011. package/lib/simple-tree/api/configuration.js +19 -0
  1012. package/lib/simple-tree/api/configuration.js.map +1 -1
  1013. package/lib/simple-tree/api/index.d.ts +3 -3
  1014. package/lib/simple-tree/api/index.d.ts.map +1 -1
  1015. package/lib/simple-tree/api/index.js +1 -1
  1016. package/lib/simple-tree/api/index.js.map +1 -1
  1017. package/lib/simple-tree/api/schemaCreationUtilities.d.ts +3 -7
  1018. package/lib/simple-tree/api/schemaCreationUtilities.d.ts.map +1 -1
  1019. package/lib/simple-tree/api/schemaCreationUtilities.js +1 -3
  1020. package/lib/simple-tree/api/schemaCreationUtilities.js.map +1 -1
  1021. package/lib/simple-tree/api/schemaFactory.d.ts +4 -9
  1022. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  1023. package/lib/simple-tree/api/schemaFactory.js +9 -8
  1024. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  1025. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +18 -20
  1026. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  1027. package/lib/simple-tree/api/schemaFactoryAlpha.js +78 -81
  1028. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  1029. package/lib/simple-tree/api/schemaFactoryBeta.d.ts +7 -9
  1030. package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
  1031. package/lib/simple-tree/api/schemaFactoryBeta.js +32 -35
  1032. package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -1
  1033. package/lib/simple-tree/api/schemaStatics.d.ts +7 -7
  1034. package/lib/simple-tree/api/schemaStatics.d.ts.map +1 -1
  1035. package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts +46 -2
  1036. package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
  1037. package/lib/simple-tree/api/snapshotCompatibilityChecker.js +48 -6
  1038. package/lib/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  1039. package/lib/simple-tree/api/transactionTypes.d.ts +4 -4
  1040. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  1041. package/lib/simple-tree/api/tree.d.ts +80 -61
  1042. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  1043. package/lib/simple-tree/api/tree.js +2 -3
  1044. package/lib/simple-tree/api/tree.js.map +1 -1
  1045. package/lib/simple-tree/api/treeChangeEvents.d.ts +16 -4
  1046. package/lib/simple-tree/api/treeChangeEvents.d.ts.map +1 -1
  1047. package/lib/simple-tree/api/treeChangeEvents.js.map +1 -1
  1048. package/lib/simple-tree/api/treeChangeEventsBeta.d.ts +209 -0
  1049. package/lib/simple-tree/api/treeChangeEventsBeta.d.ts.map +1 -0
  1050. package/lib/simple-tree/api/{treeAlpha.js → treeChangeEventsBeta.js} +1 -1
  1051. package/lib/simple-tree/api/treeChangeEventsBeta.js.map +1 -0
  1052. package/lib/simple-tree/api/treeNodeApi.d.ts +1 -75
  1053. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  1054. package/lib/simple-tree/api/treeNodeApi.js +1 -1
  1055. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  1056. package/lib/simple-tree/api/typesUnsafe.d.ts +8 -6
  1057. package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  1058. package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
  1059. package/lib/simple-tree/core/allowedTypes.js +12 -3
  1060. package/lib/simple-tree/core/allowedTypes.js.map +1 -1
  1061. package/lib/simple-tree/core/context.js +3 -0
  1062. package/lib/simple-tree/core/context.js.map +1 -1
  1063. package/lib/simple-tree/core/index.d.ts +1 -1
  1064. package/lib/simple-tree/core/index.d.ts.map +1 -1
  1065. package/lib/simple-tree/core/index.js +1 -1
  1066. package/lib/simple-tree/core/index.js.map +1 -1
  1067. package/lib/simple-tree/core/treeNode.d.ts +3 -4
  1068. package/lib/simple-tree/core/treeNode.d.ts.map +1 -1
  1069. package/lib/simple-tree/core/treeNode.js +29 -30
  1070. package/lib/simple-tree/core/treeNode.js.map +1 -1
  1071. package/lib/simple-tree/core/treeNodeKernel.js +181 -179
  1072. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  1073. package/lib/simple-tree/core/treeNodeValid.js +19 -19
  1074. package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
  1075. package/lib/simple-tree/core/unhydratedFlexTree.js +173 -146
  1076. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  1077. package/lib/simple-tree/core/withType.d.ts +7 -9
  1078. package/lib/simple-tree/core/withType.d.ts.map +1 -1
  1079. package/lib/simple-tree/core/withType.js +5 -6
  1080. package/lib/simple-tree/core/withType.js.map +1 -1
  1081. package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
  1082. package/lib/simple-tree/fieldSchema.js +23 -5
  1083. package/lib/simple-tree/fieldSchema.js.map +1 -1
  1084. package/lib/simple-tree/index.d.ts +2 -2
  1085. package/lib/simple-tree/index.d.ts.map +1 -1
  1086. package/lib/simple-tree/index.js +2 -2
  1087. package/lib/simple-tree/index.js.map +1 -1
  1088. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  1089. package/lib/simple-tree/leafNodeSchema.js +16 -15
  1090. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  1091. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +3 -2
  1092. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  1093. package/lib/simple-tree/node-kinds/array/arrayNode.js +28 -32
  1094. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  1095. package/lib/simple-tree/node-kinds/array/arrayNodeTypes.d.ts.map +1 -1
  1096. package/lib/simple-tree/node-kinds/map/mapNode.d.ts +6 -6
  1097. package/lib/simple-tree/node-kinds/map/mapNode.d.ts.map +1 -1
  1098. package/lib/simple-tree/node-kinds/map/mapNode.js +10 -17
  1099. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  1100. package/lib/simple-tree/node-kinds/map/mapNodeTypes.d.ts.map +1 -1
  1101. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  1102. package/lib/simple-tree/node-kinds/object/objectNode.js +25 -28
  1103. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  1104. package/lib/simple-tree/node-kinds/object/objectNodeTypes.d.ts +1 -1
  1105. package/lib/simple-tree/node-kinds/object/objectNodeTypes.d.ts.map +1 -1
  1106. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  1107. package/lib/simple-tree/node-kinds/record/recordNode.js +10 -14
  1108. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  1109. package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts +3 -2
  1110. package/lib/simple-tree/node-kinds/record/recordNodeTypes.d.ts.map +1 -1
  1111. package/lib/simple-tree/node-kinds/record/recordNodeTypes.js.map +1 -1
  1112. package/lib/tableSchema.d.ts +2 -87
  1113. package/lib/tableSchema.d.ts.map +1 -1
  1114. package/lib/tableSchema.js +309 -275
  1115. package/lib/tableSchema.js.map +1 -1
  1116. package/lib/text/codePointUtils.d.ts +16 -3
  1117. package/lib/text/codePointUtils.d.ts.map +1 -1
  1118. package/lib/text/codePointUtils.js +22 -10
  1119. package/lib/text/codePointUtils.js.map +1 -1
  1120. package/lib/text/textDomain.d.ts +7 -1
  1121. package/lib/text/textDomain.d.ts.map +1 -1
  1122. package/lib/text/textDomain.js +21 -17
  1123. package/lib/text/textDomain.js.map +1 -1
  1124. package/lib/text/textDomainFormatted.d.ts.map +1 -1
  1125. package/lib/text/textDomainFormatted.js +43 -32
  1126. package/lib/text/textDomainFormatted.js.map +1 -1
  1127. package/lib/text/textDomainFormattedDefault.js +2 -5
  1128. package/lib/text/textDomainFormattedDefault.js.map +1 -1
  1129. package/lib/util/brand.js +1 -0
  1130. package/lib/util/brand.js.map +1 -1
  1131. package/lib/util/breakable.d.ts.map +1 -1
  1132. package/lib/util/breakable.js +3 -0
  1133. package/lib/util/breakable.js.map +1 -1
  1134. package/lib/util/compressedIds.js +22 -0
  1135. package/lib/util/compressedIds.js.map +1 -1
  1136. package/lib/util/nestedMap.js +2 -4
  1137. package/lib/util/nestedMap.js.map +1 -1
  1138. package/lib/util/offsetList.js +2 -4
  1139. package/lib/util/offsetList.js.map +1 -1
  1140. package/lib/util/rangeMap.js +4 -0
  1141. package/lib/util/rangeMap.js.map +1 -1
  1142. package/lib/util/readSnapshotBlob.d.ts.map +1 -1
  1143. package/lib/util/referenceCounting.js +1 -0
  1144. package/lib/util/referenceCounting.js.map +1 -1
  1145. package/lib/util/stackyIterator.js +3 -2
  1146. package/lib/util/stackyIterator.js.map +1 -1
  1147. package/lib/util/utils.d.ts +2 -2
  1148. package/lib/util/utils.d.ts.map +1 -1
  1149. package/package.json +67 -95
  1150. package/src/api.ts +11 -0
  1151. package/src/core/index.ts +6 -2
  1152. package/src/core/rebase/index.ts +1 -0
  1153. package/src/core/rebase/types.ts +16 -1
  1154. package/src/core/tree/anchorSet.ts +2 -2
  1155. package/src/core/tree/deltaUtil.ts +67 -13
  1156. package/src/core/tree/index.ts +5 -2
  1157. package/src/entrypoints/alpha.ts +19 -21
  1158. package/src/entrypoints/beta.ts +12 -5
  1159. package/src/entrypoints/legacy.ts +12 -5
  1160. package/src/entrypoints/public.ts +1 -5
  1161. package/src/extensibleUnionNode.ts +1 -2
  1162. package/src/feature-libraries/cursorComparator.ts +57 -9
  1163. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +77 -12
  1164. package/src/feature-libraries/modular-schema/filterEdits.ts +108 -0
  1165. package/src/feature-libraries/modular-schema/genericFieldKind.ts +7 -4
  1166. package/src/feature-libraries/modular-schema/index.ts +5 -2
  1167. package/src/feature-libraries/modular-schema/invert.ts +16 -61
  1168. package/src/feature-libraries/modular-schema/minimizeModularChange.ts +831 -10
  1169. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +10 -124
  1170. package/src/feature-libraries/modular-schema/modularChangeUtils.ts +164 -2
  1171. package/src/feature-libraries/modular-schema/prune.ts +52 -10
  1172. package/src/feature-libraries/optional-field/optionalField.ts +30 -42
  1173. package/src/feature-libraries/sequence-field/filterEdits.ts +62 -26
  1174. package/src/feature-libraries/sequence-field/utils.ts +7 -19
  1175. package/src/index.ts +7 -39
  1176. package/src/internalTypes.ts +1 -1
  1177. package/src/packageVersion.ts +1 -1
  1178. package/src/shared-tree/history.ts +41 -19
  1179. package/src/shared-tree/independentView.ts +40 -3
  1180. package/src/shared-tree/index.ts +5 -1
  1181. package/src/shared-tree/schematizingTreeView.ts +2 -2
  1182. package/src/shared-tree/sharedTree.ts +2 -1
  1183. package/src/shared-tree/transactionMinimize.ts +13 -4
  1184. package/src/shared-tree/treeAlpha.ts +17 -31
  1185. package/src/{simple-tree/api → shared-tree}/treeBeta.ts +56 -167
  1186. package/src/shared-tree/treeCheckout.ts +82 -9
  1187. package/src/shared-tree-core/editManager.ts +16 -8
  1188. package/src/shared-tree-core/editManagerCodecsCommons.ts +30 -34
  1189. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +1 -1
  1190. package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +2 -2
  1191. package/src/simple-tree/api/cloneTree.ts +47 -0
  1192. package/src/simple-tree/api/index.ts +15 -21
  1193. package/src/simple-tree/api/schemaFactoryAlpha.ts +2 -2
  1194. package/src/simple-tree/api/snapshotCompatibilityChecker.ts +87 -6
  1195. package/src/simple-tree/api/transactionTypes.ts +4 -4
  1196. package/src/simple-tree/api/tree.ts +139 -85
  1197. package/src/simple-tree/api/treeChangeEvents.ts +16 -4
  1198. package/src/simple-tree/api/treeChangeEventsBeta.ts +245 -0
  1199. package/src/simple-tree/api/treeNodeApi.ts +6 -85
  1200. package/src/simple-tree/api/typesUnsafe.ts +8 -6
  1201. package/src/simple-tree/core/index.ts +1 -1
  1202. package/src/simple-tree/core/treeNode.ts +3 -10
  1203. package/src/simple-tree/core/withType.ts +8 -11
  1204. package/src/simple-tree/index.ts +3 -7
  1205. package/src/simple-tree/node-kinds/array/arrayNode.ts +14 -12
  1206. package/src/simple-tree/node-kinds/map/mapNode.ts +14 -15
  1207. package/src/simple-tree/node-kinds/object/objectNode.ts +3 -6
  1208. package/src/simple-tree/node-kinds/record/recordNode.ts +6 -8
  1209. package/src/simple-tree/node-kinds/record/recordNodeTypes.ts +2 -1
  1210. package/src/tableSchema.ts +8 -187
  1211. package/src/text/codePointUtils.ts +25 -14
  1212. package/src/text/textDomain.ts +15 -2
  1213. package/src/text/textDomainFormatted.ts +9 -4
  1214. package/tsconfig.json +1 -1
  1215. package/alpha.d.ts +0 -11
  1216. package/beta.d.ts +0 -11
  1217. package/dist/simple-tree/api/treeAlpha.d.ts +0 -126
  1218. package/dist/simple-tree/api/treeAlpha.d.ts.map +0 -1
  1219. package/dist/simple-tree/api/treeAlpha.js.map +0 -1
  1220. package/dist/simple-tree/api/treeBeta.d.ts.map +0 -1
  1221. package/dist/simple-tree/api/treeBeta.js +0 -83
  1222. package/dist/simple-tree/api/treeBeta.js.map +0 -1
  1223. package/docs/main/glossary.md +0 -163
  1224. package/internal.d.ts +0 -11
  1225. package/legacy.d.ts +0 -11
  1226. package/lib/simple-tree/api/treeAlpha.d.ts +0 -126
  1227. package/lib/simple-tree/api/treeAlpha.d.ts.map +0 -1
  1228. package/lib/simple-tree/api/treeAlpha.js.map +0 -1
  1229. package/lib/simple-tree/api/treeBeta.d.ts.map +0 -1
  1230. package/lib/simple-tree/api/treeBeta.js +0 -77
  1231. package/lib/simple-tree/api/treeBeta.js.map +0 -1
  1232. package/src/simple-tree/api/treeAlpha.ts +0 -153
  1233. /package/api-extractor/{api-extractor.current.json → api-extractor-report.current.json} +0 -0
  1234. /package/api-extractor/{api-extractor.legacy.json → api-extractor-report.legacy.json} +0 -0
@@ -2,12 +2,12 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { __classPrivateFieldGet, __classPrivateFieldSet, __esDecorate, __runInitializers } from "tslib";
5
+ import { __esDecorate, __runInitializers } from "tslib";
6
6
  import { createEmitter } from "@fluid-internal/client-utils";
7
7
  import { assert, unreachableCase, fail } from "@fluidframework/core-utils/internal";
8
- import { UsageError } from "@fluidframework/telemetry-utils/internal";
8
+ import { UsageError, tagCodeArtifacts, } from "@fluidframework/telemetry-utils/internal";
9
9
  import { FluidClientVersion, FormatValidatorNoOp, } from "../codec/index.js";
10
- import { CommitKind, CommitOutcome, RevertibleStatus, TreeStoredSchemaRepository, combineVisitors, makeDetachedFieldIndex, rebaseChange, rootFieldKey, tagChange, visitDelta, isAncestor, moveToDetachedField, LeafNodeStoredSchema, diffHistories, makeAnonChange, deltaFieldMapHasVisibleChanges, findCommonAncestor, rebaseBranch, findAncestor, } from "../core/index.js";
10
+ import { CommitKind, CommitOutcome, RevertibleStatus, TreeStoredSchemaRepository, combineVisitors, makeDetachedFieldIndex, rebaseChange, rootFieldKey, tagChange, visitDelta, isAncestor, moveToDetachedField, LeafNodeStoredSchema, diffHistories, makeAnonChange, findCommonAncestor, rebaseBranch, getDeltaChangeProfile, findAncestor, } from "../core/index.js";
11
11
  import { allowsRepoSuperset, buildForest, createNodeIdentifierManager, defaultSchemaPolicy, fieldBatchCodecBuilder, TreeStatus, intoDelta, jsonableTreeFromCursor, } from "../feature-libraries/index.js";
12
12
  import { SquashingTransactionStack, SharedTreeBranch, TransactionResult as InternalTransactionResult, } from "../shared-tree-core/index.js";
13
13
  import { getInnerNode, getKernel, customFromCursorStored, } from "../simple-tree/index.js";
@@ -116,6 +116,7 @@ export function createTreeCheckout(idCompressor, mintRevisionTag, revisionTagCod
116
116
  change: changeFamily.rebaser.compose([]),
117
117
  revision: "root",
118
118
  customMetadata: undefined,
119
+ wasTrimmed: true,
119
120
  }, changeFamily, () => idCompressor.generateCompressedId());
120
121
  return new TreeCheckout(branch, true, changeFamily, schema, forest, mintRevisionTag, revisionTagCodec, idCompressor, args?.removedRoots);
121
122
  }
@@ -197,7 +198,6 @@ export function assertValidConstraint(constraint, onRevert) {
197
198
  * An implementation of {@link ITreeCheckout}.
198
199
  */
199
200
  let TreeCheckout = (() => {
200
- var _a, _TreeCheckout_events, _TreeCheckout_transaction, _TreeCheckout_validatedCommits;
201
201
  let _instanceExtraInitializers = [];
202
202
  let _exportVerbose_decorators;
203
203
  let _applySerializedChange_decorators;
@@ -207,990 +207,1069 @@ let TreeCheckout = (() => {
207
207
  let _withCombinedVisitor_decorators;
208
208
  let _viewWith_decorators;
209
209
  let _fork_decorators;
210
- return _a = class TreeCheckout {
211
- /**
212
- * Logger for telemetry events related to this checkout.
213
- * @remarks
214
- * This logger is provided by the {@link Breakable} passed to the constructor, and may be `undefined` if no logger was provided.
215
- * See the explanation on {@link Breakable.logger} for why this pattern makes sense.
216
- */
217
- get logger() {
218
- return this.breaker.logger;
210
+ return class TreeCheckout {
211
+ static {
212
+ const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
213
+ __esDecorate(this, null, _exportVerbose_decorators, { kind: "method", name: "exportVerbose", static: false, private: false, access: { has: obj => "exportVerbose" in obj, get: obj => obj.exportVerbose }, metadata: _metadata }, null, _instanceExtraInitializers);
214
+ __esDecorate(this, null, _applySerializedChange_decorators, { kind: "method", name: "applySerializedChange", static: false, private: false, access: { has: obj => "applySerializedChange" in obj, get: obj => obj.applySerializedChange }, metadata: _metadata }, null, _instanceExtraInitializers);
215
+ __esDecorate(this, null, _applyChange_decorators, { kind: "method", name: "applyChange", static: false, private: false, access: { has: obj => "applyChange" in obj, get: obj => obj.applyChange }, metadata: _metadata }, null, _instanceExtraInitializers);
216
+ __esDecorate(this, null, _runTransaction_decorators, { kind: "method", name: "runTransaction", static: false, private: false, access: { has: obj => "runTransaction" in obj, get: obj => obj.runTransaction }, metadata: _metadata }, null, _instanceExtraInitializers);
217
+ __esDecorate(this, null, _runTransactionAsync_decorators, { kind: "method", name: "runTransactionAsync", static: false, private: false, access: { has: obj => "runTransactionAsync" in obj, get: obj => obj.runTransactionAsync }, metadata: _metadata }, null, _instanceExtraInitializers);
218
+ __esDecorate(this, null, _withCombinedVisitor_decorators, { kind: "method", name: "withCombinedVisitor", static: false, private: false, access: { has: obj => "withCombinedVisitor" in obj, get: obj => obj.withCombinedVisitor }, metadata: _metadata }, null, _instanceExtraInitializers);
219
+ __esDecorate(this, null, _viewWith_decorators, { kind: "method", name: "viewWith", static: false, private: false, access: { has: obj => "viewWith" in obj, get: obj => obj.viewWith }, metadata: _metadata }, null, _instanceExtraInitializers);
220
+ __esDecorate(this, null, _fork_decorators, { kind: "method", name: "fork", static: false, private: false, access: { has: obj => "fork" in obj, get: obj => obj.fork }, metadata: _metadata }, null, _instanceExtraInitializers);
221
+ if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
222
+ }
223
+ branch = __runInitializers(this, _instanceExtraInitializers);
224
+ isSharedBranch;
225
+ changeFamily;
226
+ storedSchema;
227
+ forest;
228
+ mintRevisionTag;
229
+ revisionTagCodec;
230
+ idCompressor;
231
+ _removedRoots;
232
+ disposeForksAfterTransaction;
233
+ disposed = false;
234
+ /**
235
+ * Logger for telemetry events related to this checkout.
236
+ * @remarks
237
+ * This logger is provided by the {@link Breakable} passed to the constructor, and may be `undefined` if no logger was provided.
238
+ * See the explanation on {@link Breakable.logger} for why this pattern makes sense.
239
+ */
240
+ get logger() {
241
+ return this.breaker.logger;
242
+ }
243
+ /**
244
+ * The breaker for this checkout.
245
+ * @remarks
246
+ * As the forest is part of the mutable state of the checkout,
247
+ * we want to be broken if it is broken, so we use the forest's breaker as our own.
248
+ *
249
+ * This does mean that if something goes wrong in the checkout, we break the forest,
250
+ * which is not strictly necessary, but may be desirable as if something is wrong with the checkout,
251
+ * while the forest might be internally consistent, it likely doesn't contain the correct content
252
+ * (since the checkout is keeping it up to date properly anymore).
253
+ */
254
+ get breaker() {
255
+ return this.forest.breaker;
256
+ }
257
+ editLock;
258
+ /**
259
+ * Root of the mutable label tree tracking transaction nesting.
260
+ *
261
+ * @remarks
262
+ * The label tree is always isomorphic to the actual transaction tree — every transaction
263
+ * (whether labeled or not) gets its own node. To find the "current" (deepest open) node,
264
+ * walk down the right side of the tree, stopping at {@link TreeCheckout.mostRecentlyClosedLabelNode}.
265
+ *
266
+ * Cleared by {@link TreeCheckout.runWithTransactionLabel} after the commit event is emitted.
267
+ */
268
+ labelTreeNode;
269
+ /**
270
+ * Points to the most recently closed (committed) label node.
271
+ * Used by {@link TreeCheckout.currentLabelNode} to stop descending past committed nodes.
272
+ */
273
+ mostRecentlyClosedLabelNode;
274
+ views = new Set();
275
+ /**
276
+ * Event emitters for local commits.
277
+ */
278
+ localCommitEventEmitters = new Map();
279
+ /**
280
+ * Revertibles maintained for automatic disposal
281
+ */
282
+ revertibles = new Map();
283
+ /**
284
+ * Each branch's head commit corresponds to a revertible commit.
285
+ * Maintaining a whole branch ensures the commit graph is not pruned in a way that would prevent the commit from
286
+ * being reverted.
287
+ */
288
+ revertibleCommitBranches = new Map();
289
+ /**
290
+ * The name of the telemetry event logged for calls to {@link TreeCheckout.revertRevertible}.
291
+ * @privateRemarks Exposed for testing purposes.
292
+ */
293
+ static revertTelemetryEventName = "RevertRevertible";
294
+ /**
295
+ * The name of the telemetry event logged when a schema change is applied.
296
+ * @privateRemarks Exposed for testing purposes.
297
+ */
298
+ static schemaChangeTelemetryEventName = "SchemaChangeApplied";
299
+ #events = createEmitter();
300
+ events = this.#events;
301
+ _branchHistory;
302
+ constructor(branch,
303
+ /** True if and only if this checkout is for a branch which is persisted and shared with other clients. */
304
+ isSharedBranch, changeFamily, storedSchema, forest, mintRevisionTag, revisionTagCodec, idCompressor, _removedRoots = makeDetachedFieldIndex("repair"), disposeForksAfterTransaction = true) {
305
+ this.branch = branch;
306
+ this.isSharedBranch = isSharedBranch;
307
+ this.changeFamily = changeFamily;
308
+ this.storedSchema = storedSchema;
309
+ this.forest = forest;
310
+ this.mintRevisionTag = mintRevisionTag;
311
+ this.revisionTagCodec = revisionTagCodec;
312
+ this.idCompressor = idCompressor;
313
+ this._removedRoots = _removedRoots;
314
+ this.disposeForksAfterTransaction = disposeForksAfterTransaction;
315
+ this.#transaction = this.createTransactionStack(branch);
316
+ this.editLock = new EditLock(this.#transaction.activeBranchEditor);
317
+ this.registerForBranchEvents();
318
+ }
319
+ get branchHistory() {
320
+ this._branchHistory ??= new DefaultTreeBranchHistory(this.branch, this.idCompressor);
321
+ return this._branchHistory;
322
+ }
323
+ /**
324
+ * Pushes a new label node for a transaction nesting level.
325
+ *
326
+ * @param label - The label for this transaction level.
327
+ *
328
+ * @remarks
329
+ * Called at the start of each transaction (including nested ones).
330
+ * Creates a new {@link LabelTree} node as a child of the current deepest node (if any),
331
+ * or as the root if this is the outermost transaction.
332
+ */
333
+ pushLabelFrame(label) {
334
+ const node = { label, sublabels: [] };
335
+ if (this.labelTreeNode === undefined) {
336
+ this.labelTreeNode = node;
219
337
  }
220
- /**
221
- * The breaker for this checkout.
222
- * @remarks
223
- * As the forest is part of the mutable state of the checkout,
224
- * we want to be broken if it is broken, so we use the forest's breaker as our own.
225
- *
226
- * This does mean that if something goes wrong in the checkout, we break the forest,
227
- * which is not strictly necessary, but may be desirable as if something is wrong with the checkout,
228
- * while the forest might be internally consistent, it likely doesn't contain the correct content
229
- * (since the checkout is keeping it up to date properly anymore).
230
- */
231
- get breaker() {
232
- return this.forest.breaker;
338
+ else {
339
+ const current = this.currentLabelNode();
340
+ assert(current !== undefined, 0xcdb /* Expected current label node to exist */);
341
+ current.sublabels.push(node);
233
342
  }
234
- constructor(branch,
235
- /** True if and only if this checkout is for a branch which is persisted and shared with other clients. */
236
- isSharedBranch, changeFamily, storedSchema, forest, mintRevisionTag, revisionTagCodec, idCompressor, _removedRoots = makeDetachedFieldIndex("repair"), disposeForksAfterTransaction = true) {
237
- this.branch = (__runInitializers(this, _instanceExtraInitializers), branch);
238
- this.isSharedBranch = isSharedBranch;
239
- this.changeFamily = changeFamily;
240
- this.storedSchema = storedSchema;
241
- this.forest = forest;
242
- this.mintRevisionTag = mintRevisionTag;
243
- this.revisionTagCodec = revisionTagCodec;
244
- this.idCompressor = idCompressor;
245
- this._removedRoots = _removedRoots;
246
- this.disposeForksAfterTransaction = disposeForksAfterTransaction;
247
- this.disposed = false;
248
- this.views = new Set();
249
- /**
250
- * Event emitters for local commits.
251
- */
252
- this.localCommitEventEmitters = new Map();
253
- /**
254
- * Revertibles maintained for automatic disposal
255
- */
256
- this.revertibles = new Map();
257
- /**
258
- * Each branch's head commit corresponds to a revertible commit.
259
- * Maintaining a whole branch ensures the commit graph is not pruned in a way that would prevent the commit from
260
- * being reverted.
261
- */
262
- this.revertibleCommitBranches = new Map();
263
- _TreeCheckout_events.set(this, createEmitter());
264
- this.events = __classPrivateFieldGet(this, _TreeCheckout_events, "f");
265
- this.onCommitSequenced = (commit) => {
266
- const emitter = this.localCommitEventEmitters.get(commit.revision);
267
- if (emitter === undefined) {
268
- // If the commit predates the creation of this checkout, there will be no emitter associated with the commit.
269
- // In that case, we don't need to emit any events.
270
- return;
271
- }
272
- const constraintStatus = getConstraintStatus(commit.change);
273
- let outcome;
274
- switch (constraintStatus) {
275
- case ConstraintStatus.Satisfied: {
276
- outcome = CommitOutcome.FullyApplied;
277
- break;
278
- }
279
- case ConstraintStatus.ImplicitViolation: {
280
- outcome = CommitOutcome.FullyDropped;
343
+ }
344
+ /**
345
+ * Returns the deepest open node on the right side of the label tree, which corresponds
346
+ * to the current (most recently pushed, not yet committed or aborted) transaction.
347
+ * Returns `undefined` when {@link TreeCheckout.labelTreeNode} is not set.
348
+ */
349
+ currentLabelNode() {
350
+ if (this.labelTreeNode === undefined) {
351
+ return undefined;
352
+ }
353
+ // Walk down the right spine of the tree. Only one closed node is ever reachable
354
+ // during this traversal, so a single pointer (mostRecentlyClosedLabelNode) suffices
355
+ // to stop descending past committed nodes.
356
+ let node = this.labelTreeNode;
357
+ while (node.sublabels.length > 0) {
358
+ const lastChild = node.sublabels[node.sublabels.length - 1];
359
+ assert(lastChild !== undefined, 0xcdc /* Expected label tree node to have children */);
360
+ if (lastChild === this.mostRecentlyClosedLabelNode) {
361
+ break;
362
+ }
363
+ node = lastChild;
364
+ }
365
+ return node;
366
+ }
367
+ /**
368
+ * Pops the current label frame from the label tree.
369
+ * @param aborted - If true, the node is removed from the tree (transaction was aborted).
370
+ * If false, the node is kept in the tree but marked as closed (transaction was committed).
371
+ */
372
+ popLabelFrame(aborted) {
373
+ const node = this.currentLabelNode();
374
+ if (node === undefined) {
375
+ return;
376
+ }
377
+ if (aborted) {
378
+ if (node === this.labelTreeNode) {
379
+ this.labelTreeNode = undefined;
380
+ this.mostRecentlyClosedLabelNode = undefined;
381
+ }
382
+ else {
383
+ // Temporarily mark node as closed so currentLabelNode() returns its parent.
384
+ this.mostRecentlyClosedLabelNode = node;
385
+ const parent = this.currentLabelNode();
386
+ assert(parent !== undefined, 0xcdd /* Expected parent label node to exist */);
387
+ parent.sublabels.pop();
388
+ // Point to the parent's new last child (guaranteed closed if it exists),
389
+ // or undefined if the parent has no more children.
390
+ const newLastChild = parent.sublabels[parent.sublabels.length - 1];
391
+ this.mostRecentlyClosedLabelNode = newLastChild;
392
+ }
393
+ }
394
+ else {
395
+ this.mostRecentlyClosedLabelNode = node;
396
+ }
397
+ }
398
+ /**
399
+ * Helper method for {@link SchematizingSimpleTreeView.runTransaction} to properly clear transaction labels once the function completes.
400
+ *
401
+ * @remarks
402
+ * The label is stored during the execution of the function and will be included in the {@link ChangeMetadata} of the transaction.
403
+ *
404
+ * Labels supplied to nested transactions are ignored - only the outermost transaction label is ever used.
405
+ *
406
+ * @param fn - The function to execute. It receives the user provided transaction label as an optional parameter.
407
+ * @param label - The label to associate with the outermost transaction.
408
+ * @returns The result of executing `fn`.
409
+ */
410
+ runWithTransactionLabel(fn, label) {
411
+ try {
412
+ return fn(label);
413
+ }
414
+ finally {
415
+ // Only clear the label tree when the outermost transaction has completed.
416
+ // Inner transactions' commits don't fire the "changed" event, so the label tree
417
+ // must remain intact until the outermost commit reads it.
418
+ if (this.transaction.size === 0) {
419
+ this.labelTreeNode = undefined;
420
+ this.mostRecentlyClosedLabelNode = undefined;
421
+ }
422
+ }
423
+ }
424
+ get removedRoots() {
425
+ return this._removedRoots;
426
+ }
427
+ registerForBranchEvents() {
428
+ this.#transaction.branch.events.on("afterChange", this.onAfterBranchChange);
429
+ this.#transaction.branch.events.on("commitSequenced", this.onCommitSequenced);
430
+ this.#transaction.activeBranchEvents.on("afterChange", this.onAfterChange);
431
+ this.#transaction.activeBranchEvents.on("ancestryTrimmed", this.onAncestryTrimmed);
432
+ }
433
+ unregisterFromBranchEvents() {
434
+ this.#transaction.branch.events.off("afterChange", this.onAfterBranchChange);
435
+ this.#transaction.branch.events.off("commitSequenced", this.onCommitSequenced);
436
+ this.#transaction.activeBranchEvents.off("afterChange", this.onAfterChange);
437
+ this.#transaction.activeBranchEvents.off("ancestryTrimmed", this.onAncestryTrimmed);
438
+ }
439
+ createTransactionStack(branch) {
440
+ return new SquashingTransactionStack(branch, this.mintRevisionTag, () => {
441
+ // When each transaction is started, make a restorable checkpoint of the current state of removed roots
442
+ const restoreRemovedRoots = this._removedRoots.createCheckpoint();
443
+ return (result, viewUpdate) => {
444
+ const newHead = this.#transaction.branch.getHead();
445
+ switch (result) {
446
+ case InternalTransactionResult.Abort: {
447
+ restoreRemovedRoots();
448
+ if (viewUpdate !== undefined) {
449
+ this.applyInternalChange(viewUpdate, newHead.revision);
450
+ }
281
451
  break;
282
452
  }
283
- case ConstraintStatus.ExplicitViolation: {
284
- outcome = CommitOutcome.NewContentOnly;
453
+ case InternalTransactionResult.Commit: {
454
+ if (viewUpdate !== undefined) {
455
+ this.applyInternalChange(viewUpdate, newHead.revision);
456
+ }
457
+ if (this.transaction.size === 0) {
458
+ // The changes in a transaction squash commit have already applied to the checkout and are known to be valid, so we can validate the squash commit automatically.
459
+ this.validateCommit(newHead);
460
+ }
285
461
  break;
286
462
  }
287
463
  default: {
288
- unreachableCase(constraintStatus);
464
+ unreachableCase(result);
289
465
  }
290
466
  }
291
- this.emitChangedLocked(() => {
292
- emitter.emit("settled", outcome);
293
- }, "a commit settled event callback");
294
- // No more events will be emitted for this commit, so we can remove the emitter from the map.
295
- this.localCommitEventEmitters.delete(commit.revision);
296
467
  };
297
- this.onAfterBranchChange = (event) => {
298
- // The following logic allows revertibles to be generated for the change.
299
- // Currently only appends (including merges and transaction commits) are supported.
300
- if (event.type === "append") {
301
- // TODO:#20949: When the SharedTree is detached, these commits will already have been garbage collected.
302
- // Figure out a way to generate revertibles before the commits are garbage collected.
303
- for (const commit of event.newCommits) {
304
- const kind = event.type === "append" ? event.kind : CommitKind.Default;
305
- const { change, revision } = commit;
306
- // Snapshot the label tree for this commit before any listener runs, so the captured
307
- // value is stable against mutations to `metadata.labels.tree` (which aliases the
308
- // live `labelTreeNode`).
309
- const commitLabelTree = this.labelTreeNode === undefined ? undefined : cloneLabelTree(this.labelTreeNode);
310
- const getRevertible = hasSchemaChange(change)
311
- ? undefined
312
- : (onRevertibleDisposed) => {
313
- if (!withinEventContext) {
314
- throw new UsageError("Cannot get a revertible outside of the context of a changed event.");
315
- }
316
- if (this.revertibleCommitBranches.get(revision) !== undefined) {
317
- throw new UsageError("Cannot generate the same revertible more than once. Note that this can happen when multiple changed event listeners are registered.");
318
- }
319
- const revertible = this.createRevertible(revision, kind, this, onRevertibleDisposed, commitLabelTree);
320
- this.revertibleCommitBranches.set(revision, __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.fork(commit));
321
- this.revertibles.set(revision, revertible);
322
- return revertible;
323
- };
324
- let withinEventContext = true;
325
- const events = createEmitter();
326
- this.localCommitEventEmitters.set(commit.revision, events);
327
- const metadata = {
328
- kind,
329
- isLocal: true,
330
- getChange: () => {
331
- assert(commit.parent !== undefined, 0xca4 /* Expected applied commit to be parented */);
332
- return SerializedChange.V1.encode(this.idCompressor, this.changeFamily, change, revision);
333
- },
334
- getRevertible: (onDisposed) => getRevertible?.(onDisposed),
335
- label: this.labelTreeNode?.label,
336
- labels: buildLabelsSet(this.labelTreeNode),
337
- events,
338
- };
339
- this.emitChangedLocked(() => {
340
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("changed", metadata, getRevertible);
341
- });
342
- withinEventContext = false;
343
- }
344
- }
345
- else if (event.type === "remove") {
346
- // Commits that are rolled back should no longer be revertible
347
- for (const commit of event.removedCommits) {
348
- this.revertibles.get(commit.revision)?.dispose();
349
- }
350
- }
351
- else if (this.isRemoteChangeEvent(event)) {
352
- // TODO: figure out how to plumb through commit kind info for remote changes
353
- this.emitChangedLocked(() => {
354
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("changed", {
355
- isLocal: false,
356
- kind: CommitKind.Default,
357
- labels: new Set(),
358
- });
359
- });
360
- }
361
- };
362
- this.onAfterChange = (event) => {
363
- this.editLock.lock("a change event callback");
364
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("beforeBatch", event);
365
- if (event.change !== undefined) {
366
- const revision = event.type === "rebase"
367
- ? __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranch.getHead().revision
368
- : event.change.revision;
369
- this.applyInternalChange(event.change.change, revision);
370
- }
371
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("afterBatch");
372
- this.editLock.unlock();
373
- if (event.type === "append") {
374
- for (const commit of event.newCommits) {
375
- this.validateCommit(commit);
376
- }
377
- }
378
- };
379
- this.onAncestryTrimmed = (revisions) => {
380
- // When the branch is trimmed, we can garbage collect any repair data whose latest relevant revision is one of the
381
- // trimmed revisions.
382
- this.withCombinedVisitor((visitor) => {
383
- for (const revision of revisions) {
384
- // get all the roots last created or used by the revision
385
- const roots = this._removedRoots.getRootsLastTouchedByRevision(revision);
386
- // get the detached field for the root and delete it from the removed roots
387
- for (const root of roots) {
388
- visitor.destroy(this._removedRoots.toFieldKey(root), 1);
389
- }
390
- this._removedRoots.deleteRootsLastTouchedByRevision(revision);
391
- }
392
- });
393
- };
394
- /**
395
- * The {@link Transactor} for this checkout.
396
- * @remarks In the context of a checkout, transactions allow edits to be batched into atomic units.
397
- * Edits made during a transaction will update the local state of the tree immediately, but will be squashed into a single edit when the transaction is committed.
398
- * If the transaction is aborted, the local state will be reset to what it was before the transaction began.
399
- * Transactions may nest, meaning that a transaction may be started while a transaction is already ongoing.
400
- *
401
- * To avoid updating observers of the view state with intermediate results during a transaction,
402
- * use {@link ITreeCheckout#fork} and {@link ISharedTreeFork#merge}.
403
- */
404
- _TreeCheckout_transaction.set(this, void 0);
405
- // #region Commit Validation
406
- /** Used to maintain the contract of {@link onCommitValid}(). */
407
- _TreeCheckout_validatedCommits.set(this, new WeakMap());
408
- // #endregion Commit Validation
409
- // #region Enrichment
410
- /**
411
- * Statistics about enrichment operations performed by this checkout.
412
- * Used for testing. May be used for telemetry in the future.
413
- * The performance cost of maintaining this information is negligible.
414
- */
415
- this.enrichmentStats = { batches: 0, diffs: 0, commitsEnriched: 0, refreshers: 0, forks: 0, applied: 0 };
416
- __classPrivateFieldSet(this, _TreeCheckout_transaction, this.createTransactionStack(branch), "f");
417
- this.editLock = new EditLock(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEditor);
418
- this.registerForBranchEvents();
419
- }
420
- get branchHistory() {
421
- this._branchHistory ??= new DefaultTreeBranchHistory(this.branch, this.idCompressor);
422
- return this._branchHistory;
423
- }
424
- /**
425
- * Pushes a new label node for a transaction nesting level.
426
- *
427
- * @param label - The label for this transaction level.
428
- *
429
- * @remarks
430
- * Called at the start of each transaction (including nested ones).
431
- * Creates a new {@link LabelTree} node as a child of the current deepest node (if any),
432
- * or as the root if this is the outermost transaction.
433
- */
434
- pushLabelFrame(label) {
435
- const node = { label, sublabels: [] };
436
- if (this.labelTreeNode === undefined) {
437
- this.labelTreeNode = node;
468
+ });
469
+ }
470
+ exportVerbose() {
471
+ const cursor = this.forest.allocateCursor("contentSnapshot");
472
+ try {
473
+ moveToDetachedField(this.forest, cursor);
474
+ const length = cursor.getFieldLength();
475
+ if (length === 0) {
476
+ return undefined;
477
+ }
478
+ else if (length === 1) {
479
+ cursor.enterNode(0);
480
+ return verboseFromCursor(cursor, this.storedSchema.nodeSchema);
438
481
  }
439
482
  else {
440
- const current = this.currentLabelNode();
441
- assert(current !== undefined, 0xcdb /* Expected current label node to exist */);
442
- current.sublabels.push(node);
483
+ fail(0xac8 /* Invalid document root length */);
443
484
  }
444
485
  }
445
- /**
446
- * Returns the deepest open node on the right side of the label tree, which corresponds
447
- * to the current (most recently pushed, not yet committed or aborted) transaction.
448
- * Returns `undefined` when {@link TreeCheckout.labelTreeNode} is not set.
449
- */
450
- currentLabelNode() {
451
- if (this.labelTreeNode === undefined) {
452
- return undefined;
453
- }
454
- // Walk down the right spine of the tree. Only one closed node is ever reachable
455
- // during this traversal, so a single pointer (mostRecentlyClosedLabelNode) suffices
456
- // to stop descending past committed nodes.
457
- let node = this.labelTreeNode;
458
- while (node.sublabels.length > 0) {
459
- const lastChild = node.sublabels[node.sublabels.length - 1];
460
- assert(lastChild !== undefined, 0xcdc /* Expected label tree node to have children */);
461
- if (lastChild === this.mostRecentlyClosedLabelNode) {
462
- break;
463
- }
464
- node = lastChild;
465
- }
466
- return node;
486
+ finally {
487
+ cursor.free();
467
488
  }
468
- /**
469
- * Pops the current label frame from the label tree.
470
- * @param aborted - If true, the node is removed from the tree (transaction was aborted).
471
- * If false, the node is kept in the tree but marked as closed (transaction was committed).
472
- */
473
- popLabelFrame(aborted) {
474
- const node = this.currentLabelNode();
475
- if (node === undefined) {
476
- return;
477
- }
478
- if (aborted) {
479
- if (node === this.labelTreeNode) {
480
- this.labelTreeNode = undefined;
481
- this.mostRecentlyClosedLabelNode = undefined;
482
- }
483
- else {
484
- // Temporarily mark node as closed so currentLabelNode() returns its parent.
485
- this.mostRecentlyClosedLabelNode = node;
486
- const parent = this.currentLabelNode();
487
- assert(parent !== undefined, 0xcdd /* Expected parent label node to exist */);
488
- parent.sublabels.pop();
489
- // Point to the parent's new last child (guaranteed closed if it exists),
490
- // or undefined if the parent has no more children.
491
- const newLastChild = parent.sublabels[parent.sublabels.length - 1];
492
- this.mostRecentlyClosedLabelNode = newLastChild;
493
- }
489
+ }
490
+ onCommitSequenced = (commit) => {
491
+ const emitter = this.localCommitEventEmitters.get(commit.revision);
492
+ if (emitter === undefined) {
493
+ // If the commit predates the creation of this checkout, there will be no emitter associated with the commit.
494
+ // In that case, we don't need to emit any events.
495
+ return;
496
+ }
497
+ const constraintStatus = getConstraintStatus(commit.change);
498
+ let outcome;
499
+ switch (constraintStatus) {
500
+ case ConstraintStatus.Satisfied: {
501
+ outcome = CommitOutcome.FullyApplied;
502
+ break;
494
503
  }
495
- else {
496
- this.mostRecentlyClosedLabelNode = node;
504
+ case ConstraintStatus.ImplicitViolation: {
505
+ outcome = CommitOutcome.FullyDropped;
506
+ break;
497
507
  }
498
- }
499
- /**
500
- * Helper method for {@link SchematizingSimpleTreeView.runTransaction} to properly clear transaction labels once the function completes.
501
- *
502
- * @remarks
503
- * The label is stored during the execution of the function and will be included in the {@link ChangeMetadata} of the transaction.
504
- *
505
- * Labels supplied to nested transactions are ignored - only the outermost transaction label is ever used.
506
- *
507
- * @param fn - The function to execute. It receives the user provided transaction label as an optional parameter.
508
- * @param label - The label to associate with the outermost transaction.
509
- * @returns The result of executing `fn`.
510
- */
511
- runWithTransactionLabel(fn, label) {
512
- try {
513
- return fn(label);
508
+ case ConstraintStatus.ExplicitViolation: {
509
+ outcome = CommitOutcome.NewContentOnly;
510
+ break;
514
511
  }
515
- finally {
516
- // Only clear the label tree when the outermost transaction has completed.
517
- // Inner transactions' commits don't fire the "changed" event, so the label tree
518
- // must remain intact until the outermost commit reads it.
519
- if (this.transaction.size === 0) {
520
- this.labelTreeNode = undefined;
521
- this.mostRecentlyClosedLabelNode = undefined;
522
- }
512
+ default: {
513
+ unreachableCase(constraintStatus);
523
514
  }
524
515
  }
525
- get removedRoots() {
526
- return this._removedRoots;
527
- }
528
- registerForBranchEvents() {
529
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.events.on("afterChange", this.onAfterBranchChange);
530
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.events.on("commitSequenced", this.onCommitSequenced);
531
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEvents.on("afterChange", this.onAfterChange);
532
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEvents.on("ancestryTrimmed", this.onAncestryTrimmed);
533
- }
534
- unregisterFromBranchEvents() {
535
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.events.off("afterChange", this.onAfterBranchChange);
536
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.events.off("commitSequenced", this.onCommitSequenced);
537
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEvents.off("afterChange", this.onAfterChange);
538
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEvents.off("ancestryTrimmed", this.onAncestryTrimmed);
539
- }
540
- createTransactionStack(branch) {
541
- return new SquashingTransactionStack(branch, this.mintRevisionTag, () => {
542
- // When each transaction is started, make a restorable checkpoint of the current state of removed roots
543
- const restoreRemovedRoots = this._removedRoots.createCheckpoint();
544
- return (result, viewUpdate) => {
545
- const newHead = __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.getHead();
546
- switch (result) {
547
- case InternalTransactionResult.Abort: {
548
- restoreRemovedRoots();
549
- if (viewUpdate !== undefined) {
550
- this.applyInternalChange(viewUpdate, newHead.revision);
551
- }
552
- break;
553
- }
554
- case InternalTransactionResult.Commit: {
555
- if (viewUpdate !== undefined) {
556
- this.applyInternalChange(viewUpdate, newHead.revision);
557
- }
558
- if (this.transaction.size === 0) {
559
- // The changes in a transaction squash commit have already applied to the checkout and are known to be valid, so we can validate the squash commit automatically.
560
- this.validateCommit(newHead);
561
- }
562
- break;
516
+ this.emitChangedLocked(() => {
517
+ emitter.emit("settled", outcome);
518
+ }, "a commit settled event callback");
519
+ // No more events will be emitted for this commit, so we can remove the emitter from the map.
520
+ this.localCommitEventEmitters.delete(commit.revision);
521
+ };
522
+ onAfterBranchChange = (event) => {
523
+ // The following logic allows revertibles to be generated for the change.
524
+ // Currently only appends (including merges and transaction commits) are supported.
525
+ if (event.type === "append") {
526
+ // TODO:#20949: When the SharedTree is detached, these commits will already have been garbage collected.
527
+ // Figure out a way to generate revertibles before the commits are garbage collected.
528
+ for (const commit of event.newCommits) {
529
+ const kind = event.type === "append" ? event.kind : CommitKind.Default;
530
+ const { change, revision } = commit;
531
+ // Snapshot the label tree for this commit before any listener runs, so the captured
532
+ // value is stable against mutations to `metadata.labels.tree` (which aliases the
533
+ // live `labelTreeNode`).
534
+ const commitLabelTree = this.labelTreeNode === undefined ? undefined : cloneLabelTree(this.labelTreeNode);
535
+ const getRevertible = hasSchemaChange(change)
536
+ ? undefined
537
+ : (onRevertibleDisposed) => {
538
+ if (!withinEventContext) {
539
+ throw new UsageError("Cannot get a revertible outside of the context of a changed event.");
563
540
  }
564
- default: {
565
- unreachableCase(result);
541
+ if (this.revertibleCommitBranches.get(revision) !== undefined) {
542
+ throw new UsageError("Cannot generate the same revertible more than once. Note that this can happen when multiple changed event listeners are registered.");
566
543
  }
567
- }
544
+ const revertible = this.createRevertible(revision, kind, this, onRevertibleDisposed, commitLabelTree);
545
+ this.revertibleCommitBranches.set(revision, this.#transaction.branch.fork(commit));
546
+ this.revertibles.set(revision, revertible);
547
+ return revertible;
548
+ };
549
+ let withinEventContext = true;
550
+ const events = createEmitter();
551
+ this.localCommitEventEmitters.set(commit.revision, events);
552
+ const metadata = {
553
+ kind,
554
+ isLocal: true,
555
+ getChange: () => {
556
+ assert(commit.parent !== undefined, 0xca4 /* Expected applied commit to be parented */);
557
+ return SerializedChange.V1.encode(this.idCompressor, this.changeFamily, change, revision);
558
+ },
559
+ getRevertible: (onDisposed) => getRevertible?.(onDisposed),
560
+ label: this.labelTreeNode?.label,
561
+ labels: buildLabelsSet(this.labelTreeNode),
562
+ events,
568
563
  };
569
- });
570
- }
571
- exportVerbose() {
572
- const cursor = this.forest.allocateCursor("contentSnapshot");
573
- try {
574
- moveToDetachedField(this.forest, cursor);
575
- const length = cursor.getFieldLength();
576
- if (length === 0) {
577
- return undefined;
578
- }
579
- else if (length === 1) {
580
- cursor.enterNode(0);
581
- return verboseFromCursor(cursor, this.storedSchema.nodeSchema);
582
- }
583
- else {
584
- fail(0xac8 /* Invalid document root length */);
585
- }
586
- }
587
- finally {
588
- cursor.free();
564
+ this.emitChangedLocked(() => {
565
+ this.#events.emit("changed", metadata, getRevertible);
566
+ });
567
+ withinEventContext = false;
589
568
  }
590
569
  }
591
- /**
592
- * Hold the `editLock` for the duration of `emit`, so that re-entrant edits, transactions,
593
- * branch operations, etc. attempted from inside a `changed` listener throw the canonical
594
- * "forbidden during a change event" {@link UsageError} via {@link EditLock.checkUnlocked}.
595
- *
596
- * @remarks
597
- * Shared by both the local and remote `changed` emission paths in {@link TreeCheckout.onAfterBranchChange}.
598
- * The `try`/`finally` ensures the lock is released even if a listener throws.
599
- */
600
- emitChangedLocked(emit, reason = "a change event callback") {
601
- this.editLock.lock(reason);
602
- try {
603
- emit();
604
- }
605
- finally {
606
- // TODO: any event that throws potentially leaves the code which triggered that event,
607
- // and thus this checkout (and likely more) in a broken state.
608
- // Unlocking this editLock prevents future use of this broken state from giving a confusing error in this case,
609
- // however, a better approach would probably be to put something (this checkout and/or the editLock)
610
- // into a broken state (using a properly scoped `Breakable`),
611
- // likely by moving emitChangedLocked into EditLock, and having EditLock get a Breakable,
612
- // and having the new emitChangedLocked use `Breakable.use`.
613
- this.editLock.unlock();
570
+ else if (event.type === "remove") {
571
+ // Commits that are rolled back should no longer be revertible
572
+ for (const commit of event.removedCommits) {
573
+ this.revertibles.get(commit.revision)?.dispose();
614
574
  }
615
575
  }
616
- /**
617
- * Applies the given serialized change (as was produced via a `"changed"` event of another checkout) to this checkout.
618
- */
619
- applySerializedChange(serializedChange) {
620
- const change = SerializedChange.V1.decode(this.idCompressor, this.changeFamily, serializedChange);
621
- // Apply the change to the branch, but _not_ the `activeBranch` - we do not support squashing serialized commits in a transaction.
622
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.apply(change, CommitKind.Default, undefined);
576
+ else if (this.isRemoteChangeEvent(event)) {
577
+ // TODO: figure out how to plumb through commit kind info for remote changes
578
+ this.emitChangedLocked(() => {
579
+ this.#events.emit("changed", {
580
+ isLocal: false,
581
+ kind: CommitKind.Default,
582
+ labels: new Set(),
583
+ });
584
+ });
623
585
  }
624
- // #region UntypedTreeViewAlpha
625
- applyChange(change) {
626
- this.applySerializedChange(change);
586
+ };
587
+ /**
588
+ * Hold the `editLock` for the duration of `emit`, so that re-entrant edits, transactions,
589
+ * branch operations, etc. attempted from inside a `changed` listener throw the canonical
590
+ * "forbidden during a change event" {@link UsageError} via {@link EditLock.checkUnlocked}.
591
+ *
592
+ * @remarks
593
+ * Shared by both the local and remote `changed` emission paths in {@link TreeCheckout.onAfterBranchChange}.
594
+ * The `try`/`finally` ensures the lock is released even if a listener throws.
595
+ */
596
+ emitChangedLocked(emit, reason = "a change event callback") {
597
+ this.editLock.lock(reason);
598
+ try {
599
+ emit();
627
600
  }
628
- isBranch() {
629
- return this.isView();
601
+ finally {
602
+ // TODO: any event that throws potentially leaves the code which triggered that event,
603
+ // and thus this checkout (and likely more) in a broken state.
604
+ // Unlocking this editLock prevents future use of this broken state from giving a confusing error in this case,
605
+ // however, a better approach would probably be to put something (this checkout and/or the editLock)
606
+ // into a broken state (using a properly scoped `Breakable`),
607
+ // likely by moving emitChangedLocked into EditLock, and having EditLock get a Breakable,
608
+ // and having the new emitChangedLocked use `Breakable.use`.
609
+ this.editLock.unlock();
630
610
  }
631
- isView() {
632
- return true;
611
+ }
612
+ onAfterChange = (event) => {
613
+ this.editLock.lock("a change event callback");
614
+ this.#events.emit("beforeBatch", event);
615
+ if (event.change !== undefined) {
616
+ const revision = event.type === "rebase"
617
+ ? this.#transaction.activeBranch.getHead().revision
618
+ : event.change.revision;
619
+ this.applyInternalChange(event.change.change, revision);
633
620
  }
634
- hasRootSchema(_schema) {
635
- return false;
621
+ this.#events.emit("afterBatch");
622
+ this.editLock.unlock();
623
+ if (event.type === "append") {
624
+ for (const commit of event.newCommits) {
625
+ this.validateCommit(commit);
626
+ }
636
627
  }
637
- runTransaction(transaction, params) {
638
- this.mountTransaction(params, false);
639
- const transactionCallbackStatus = transaction();
640
- return this.unmountTransaction(transactionCallbackStatus, params);
628
+ };
629
+ /**
630
+ * Applies the given serialized change (as was produced via a `"changed"` event of another checkout) to this checkout.
631
+ */
632
+ applySerializedChange(serializedChange) {
633
+ const change = SerializedChange.V1.decode(this.idCompressor, this.changeFamily, serializedChange);
634
+ // Apply the change to the branch, but _not_ the `activeBranch` - we do not support squashing serialized commits in a transaction.
635
+ this.#transaction.branch.apply(change, CommitKind.Default, undefined);
636
+ }
637
+ // #region UntypedTreeViewAlpha
638
+ applyChange(change) {
639
+ this.applySerializedChange(change);
640
+ }
641
+ isBranch() {
642
+ return this.isView();
643
+ }
644
+ isView() {
645
+ return true;
646
+ }
647
+ hasRootSchema(_schema) {
648
+ return false;
649
+ }
650
+ runTransaction(transaction, params) {
651
+ this.mountTransaction(params, false);
652
+ const transactionCallbackStatus = transaction();
653
+ return this.unmountTransaction(transactionCallbackStatus, params);
654
+ }
655
+ async runTransactionAsync(transaction, params) {
656
+ this.mountTransaction(params, true);
657
+ const transactionCallbackStatus = await transaction();
658
+ return this.unmountTransaction(transactionCallbackStatus, params);
659
+ }
660
+ mountTransaction(params, isAsync) {
661
+ this.checkNotDisposed();
662
+ // Starting a transaction is an edit, so it is forbidden from within a change-event
663
+ // callback (where the edit lock is held), the same as direct edits. For the async
664
+ // entry point this throw is captured as a rejected promise by the `async` wrapper.
665
+ //
666
+ // Note: because runTransaction/runTransactionAsync are `@breakingMethod`, this throw also
667
+ // puts the checkout into a broken state (unlike a direct edit, which throws recoverably).
668
+ // That is the same pre-existing broken-state limitation tracked by the TODO in
669
+ // `emitChangedLocked`, not something specific to transactions.
670
+ this.editLock.checkUnlocked("Running a transaction");
671
+ if (isAsync && this.transaction.size > 0) {
672
+ throw new UsageError("An asynchronous transaction cannot be started while another transaction is already in progress.");
641
673
  }
642
- async runTransactionAsync(transaction, params) {
643
- this.mountTransaction(params, true);
644
- const transactionCallbackStatus = await transaction();
645
- return this.unmountTransaction(transactionCallbackStatus, params);
674
+ this.pushLabelFrame(params?.label);
675
+ this.transaction.start({
676
+ postProcessor: extractTransactionChangeProcessor(params?.postProcessor),
677
+ // Like the validation described above, rejecting malformed metadata breaks the checkout rather
678
+ // than being recoverable. Tracked by https://github.com/microsoft/FluidFramework/issues/28085.
679
+ customMetadata: snapshotCustomMetadata(params?.customMetadata),
680
+ });
681
+ addConstraintsToTransaction(this, false, params?.preconditions);
682
+ }
683
+ unmountTransaction(transactionCallbackStatus, params) {
684
+ this.checkNotDisposed();
685
+ const rollback = transactionCallbackStatus?.rollback;
686
+ const value = transactionCallbackStatus?.value;
687
+ if (rollback === true) {
688
+ this.popLabelFrame(true);
689
+ this.transaction.abort();
690
+ return value === undefined
691
+ ? { success: false }
692
+ : { success: false, value: value };
646
693
  }
647
- mountTransaction(params, isAsync) {
648
- this.checkNotDisposed();
649
- // Starting a transaction is an edit, so it is forbidden from within a change-event
650
- // callback (where the edit lock is held), the same as direct edits. For the async
651
- // entry point this throw is captured as a rejected promise by the `async` wrapper.
652
- //
653
- // Note: because runTransaction/runTransactionAsync are `@breakingMethod`, this throw also
654
- // puts the checkout into a broken state (unlike a direct edit, which throws recoverably).
655
- // That is the same pre-existing broken-state limitation tracked by the TODO in
656
- // `emitChangedLocked`, not something specific to transactions.
657
- this.editLock.checkUnlocked("Running a transaction");
658
- if (isAsync && this.transaction.size > 0) {
659
- throw new UsageError("An asynchronous transaction cannot be started while another transaction is already in progress.");
694
+ addConstraintsToTransaction(this, true, transactionCallbackStatus?.preconditionsOnRevert);
695
+ this.popLabelFrame(false);
696
+ this.runWithTransactionLabel(() => {
697
+ this.transaction.commit();
698
+ }, params?.label);
699
+ return value === undefined
700
+ ? { success: true }
701
+ : { success: true, value: value };
702
+ }
703
+ // #endregion UntypedTreeViewAlpha
704
+ // Revision is the revision of the commit, if any, which caused this change.
705
+ applyInternalChange(change, revision) {
706
+ // Conflicts due to schema will be empty and thus are not applied.
707
+ for (const innerChange of change.changes) {
708
+ if (innerChange.type === "data") {
709
+ const delta = intoDelta(tagChange(innerChange.innerChange, revision));
710
+ this.withCombinedVisitor((visitor) => {
711
+ visitDelta(delta, visitor, this._removedRoots, revision);
712
+ });
713
+ }
714
+ else if (innerChange.type === "schema") {
715
+ // Schema changes from a current to a new schema are expected to be backwards compatible.
716
+ // This guarantees that all data in the forest (which is valid before the schema change)
717
+ // is also valid under the new schema.
718
+ // Note however, that such schema changes may in some cases be rolled back:
719
+ // Case 1: A transaction with a schema change may be aborted.
720
+ // The transaction may have made some data changes that would render some trees invalid
721
+ // under the old schema, but these changes will also be rolled back, thereby putting the forest
722
+ // back in the state before the transaction, which is valid under the original (reinstated) schema.
723
+ // Case 2: A branch with a schema change may be rebased such that the schema change (because
724
+ // of a constraint) is no longer applied.
725
+ // Such a branch may contain data changes that would render some trees invalid under the
726
+ // original schema. These data changes may not necessarily be rolled back.
727
+ // They will however be rebased over the rollback of the schema change. This rebasing will
728
+ // ensure that these data changes are muted if they would render some trees invalid under the
729
+ // original (reinstated) schema.
730
+ const newSchema = innerChange.innerChange.schema.new;
731
+ const telemetryMetrics = getSchemaChangeTelemetryMetrics(this.storedSchema, newSchema, innerChange.innerChange.isInverse);
732
+ this.storedSchema.apply(newSchema);
733
+ this.logger?.sendTelemetryEvent({
734
+ eventName: TreeCheckout.schemaChangeTelemetryEventName,
735
+ ...tagCodeArtifacts({
736
+ details: JSON.stringify({
737
+ ...telemetryMetrics,
738
+ isSharedBranch: this.isSharedBranch,
739
+ }),
740
+ }),
741
+ });
742
+ }
743
+ else {
744
+ fail(0xad1 /* Unknown Shared Tree change type. */);
660
745
  }
661
- this.pushLabelFrame(params?.label);
662
- this.transaction.start({
663
- postProcessor: extractTransactionChangeProcessor(params?.postProcessor),
664
- // Like the validation described above, rejecting malformed metadata breaks the checkout rather
665
- // than being recoverable. Tracked by https://github.com/microsoft/FluidFramework/issues/28085.
666
- customMetadata: snapshotCustomMetadata(params?.customMetadata),
667
- });
668
- addConstraintsToTransaction(this, false, params?.preconditions);
669
746
  }
670
- unmountTransaction(transactionCallbackStatus, params) {
671
- this.checkNotDisposed();
672
- const rollback = transactionCallbackStatus?.rollback;
673
- const value = transactionCallbackStatus?.value;
674
- if (rollback === true) {
675
- this.popLabelFrame(true);
676
- this.transaction.abort();
677
- return value === undefined
678
- ? { success: false }
679
- : { success: false, value: value };
747
+ }
748
+ onAncestryTrimmed = (revisions) => {
749
+ // When the branch is trimmed, we can garbage collect any repair data whose latest relevant revision is one of the
750
+ // trimmed revisions.
751
+ this.withCombinedVisitor((visitor) => {
752
+ for (const revision of revisions) {
753
+ // get all the roots last created or used by the revision
754
+ const roots = this._removedRoots.getRootsLastTouchedByRevision(revision);
755
+ // get the detached field for the root and delete it from the removed roots
756
+ for (const root of roots) {
757
+ visitor.destroy(this._removedRoots.toFieldKey(root), 1);
758
+ }
759
+ this._removedRoots.deleteRootsLastTouchedByRevision(revision);
680
760
  }
681
- addConstraintsToTransaction(this, true, transactionCallbackStatus?.preconditionsOnRevert);
682
- this.popLabelFrame(false);
683
- this.runWithTransactionLabel(() => {
684
- this.transaction.commit();
685
- }, params?.label);
686
- return value === undefined
687
- ? { success: true }
688
- : { success: true, value: value };
761
+ });
762
+ };
763
+ withCombinedVisitor(fn) {
764
+ const anchorVisitor = this.forest.anchors.acquireVisitor();
765
+ const combinedVisitor = combineVisitors([this.forest.acquireVisitor(), anchorVisitor]);
766
+ fn(combinedVisitor);
767
+ combinedVisitor.free();
768
+ }
769
+ checkNotDisposed(usageError) {
770
+ this.breaker.use();
771
+ if (this.disposed) {
772
+ if (usageError !== undefined) {
773
+ throw new UsageError(usageError);
774
+ }
775
+ fail(0x911 /* Invalid operation on a disposed TreeCheckout */);
689
776
  }
690
- // #endregion UntypedTreeViewAlpha
691
- // Revision is the revision of the commit, if any, which caused this change.
692
- applyInternalChange(change, revision) {
693
- // Conflicts due to schema will be empty and thus are not applied.
694
- for (const innerChange of change.changes) {
695
- if (innerChange.type === "data") {
696
- const delta = intoDelta(tagChange(innerChange.innerChange, revision));
697
- this.withCombinedVisitor((visitor) => {
698
- visitDelta(delta, visitor, this._removedRoots, revision);
699
- });
777
+ }
778
+ /**
779
+ * Creates a {@link RevertibleAlpha} object that can undo a specific change in the tree's history.
780
+ * Revision must exist in the given {@link TreeCheckout}'s branch.
781
+ *
782
+ * @param revision - The revision tag identifying the change to be made revertible.
783
+ * @param kind - The {@link CommitKind} that produced this revertible (e.g., Default, Undo, Redo).
784
+ * @param checkout - The {@link TreeCheckout} instance this revertible belongs to.
785
+ * @param onRevertibleDisposed - Callback function that will be called when the revertible is disposed.
786
+ * @param labelTree - The {@link LabelTree} (if any) active when the original commit was produced.
787
+ * The revert commit inherits these labels so that commits and their reverts can be associated.
788
+ * @returns A {@link RevertibleAlpha} object.
789
+ */
790
+ createRevertible(revision, kind, checkout, onRevertibleDisposed, labelTree) {
791
+ const commitBranches = checkout.revertibleCommitBranches;
792
+ const revertible = {
793
+ get status() {
794
+ const revertibleCommit = commitBranches.get(revision);
795
+ return revertibleCommit === undefined
796
+ ? RevertibleStatus.Disposed
797
+ : RevertibleStatus.Valid;
798
+ },
799
+ revert: (releaseOrOptions = true) => {
800
+ if (revertible.status === RevertibleStatus.Disposed) {
801
+ throw new UsageError("Unable to revert a revertible that has been disposed.");
802
+ }
803
+ const options = typeof releaseOrOptions === "boolean"
804
+ ? { dispose: releaseOrOptions }
805
+ : releaseOrOptions;
806
+ const revertMetrics = checkout.revertRevertible(revision, kind, labelTree, snapshotCustomMetadata(options.customMetadata));
807
+ checkout.logger?.sendTelemetryEvent({
808
+ eventName: TreeCheckout.revertTelemetryEventName,
809
+ ...revertMetrics,
810
+ });
811
+ if (options.dispose ?? true) {
812
+ revertible.dispose();
700
813
  }
701
- else if (innerChange.type === "schema") {
702
- // Schema changes from a current to a new schema are expected to be backwards compatible.
703
- // This guarantees that all data in the forest (which is valid before the schema change)
704
- // is also valid under the new schema.
705
- // Note however, that such schema changes may in some cases be rolled back:
706
- // Case 1: A transaction with a schema change may be aborted.
707
- // The transaction may have made some data changes that would render some trees invalid
708
- // under the old schema, but these changes will also be rolled back, thereby putting the forest
709
- // back in the state before the transaction, which is valid under the original (reinstated) schema.
710
- // Case 2: A branch with a schema change may be rebased such that the schema change (because
711
- // of a constraint) is no longer applied.
712
- // Such a branch may contain data changes that would render some trees invalid under the
713
- // original schema. These data changes may not necessarily be rolled back.
714
- // They will however be rebased over the rollback of the schema change. This rebasing will
715
- // ensure that these data changes are muted if they would render some trees invalid under the
716
- // original (reinstated) schema.
717
- this.storedSchema.apply(innerChange.innerChange.schema.new);
814
+ },
815
+ clone: (targetView) => {
816
+ // TODO:#23442: When a revertible is cloned for a forked branch, optimize to create a fork of a revertible branch once per revision NOT once per revision per checkout.
817
+ const targetCheckout = getCheckout(targetView);
818
+ const revertibleBranch = this.revertibleCommitBranches.get(revision);
819
+ if (revertibleBranch === undefined) {
820
+ throw new UsageError("Unable to clone a revertible that has been disposed.");
718
821
  }
719
- else {
720
- fail(0xad1 /* Unknown Shared Tree change type. */);
822
+ const commitToRevert = revertibleBranch.getHead();
823
+ const branchHead = targetCheckout.#transaction.branch.getHead();
824
+ if (isAncestor(commitToRevert, branchHead, true) === false) {
825
+ throw new UsageError("Cannot clone revertible for a commit that is not present on the given branch.");
721
826
  }
722
- }
827
+ targetCheckout.revertibleCommitBranches.set(revision, revertibleBranch.fork());
828
+ return this.createRevertible(revision, kind, targetCheckout, onRevertibleDisposed, labelTree);
829
+ },
830
+ dispose: () => {
831
+ if (revertible.status === RevertibleStatus.Disposed) {
832
+ throw new UsageError("Unable to dispose a revertible that has already been disposed.");
833
+ }
834
+ checkout.disposeRevertible(revision);
835
+ onRevertibleDisposed?.(revertible);
836
+ },
837
+ };
838
+ return revertible;
839
+ }
840
+ viewWith(config) {
841
+ const view = new SchematizingSimpleTreeView(this, config, createNodeIdentifierManager(this.idCompressor), () => {
842
+ this.views.delete(view);
843
+ });
844
+ this.views.add(view);
845
+ return view;
846
+ }
847
+ get rootEvents() {
848
+ return this.forest.anchors.events;
849
+ }
850
+ get editor() {
851
+ this.checkNotDisposed();
852
+ return this.editLock.editor;
853
+ }
854
+ locate(anchor) {
855
+ this.checkNotDisposed();
856
+ return this.forest.anchors.locate(anchor);
857
+ }
858
+ get transaction() {
859
+ return this.#transaction;
860
+ }
861
+ /**
862
+ * The {@link Transactor} for this checkout.
863
+ * @remarks In the context of a checkout, transactions allow edits to be batched into atomic units.
864
+ * Edits made during a transaction will update the local state of the tree immediately, but will be squashed into a single edit when the transaction is committed.
865
+ * If the transaction is aborted, the local state will be reset to what it was before the transaction began.
866
+ * Transactions may nest, meaning that a transaction may be started while a transaction is already ongoing.
867
+ *
868
+ * To avoid updating observers of the view state with intermediate results during a transaction,
869
+ * use {@link ITreeCheckout#fork} and {@link ISharedTreeFork#merge}.
870
+ */
871
+ #transaction;
872
+ fork() {
873
+ this.checkNotDisposed("The parent branch has already been disposed and can no longer create new branches.");
874
+ // Branching after an unfinished transaction would expose the application to a state where its invariants may be violated.
875
+ if (this.transaction.size > 0) {
876
+ throw new UsageError("A view cannot be forked while it has a pending transaction.");
723
877
  }
724
- withCombinedVisitor(fn) {
725
- const anchorVisitor = this.forest.anchors.acquireVisitor();
726
- const combinedVisitor = combineVisitors([this.forest.acquireVisitor(), anchorVisitor]);
727
- fn(combinedVisitor);
728
- combinedVisitor.free();
878
+ const branch = this.#transaction.branch.fork();
879
+ const storedSchema = this.storedSchema.clone();
880
+ const forkBreaker = new Breakable("TreeCheckout", this.logger);
881
+ const forest = this.forest.clone(storedSchema, forkBreaker);
882
+ const checkout = new TreeCheckout(branch, false, this.changeFamily, storedSchema, forest, this.mintRevisionTag, this.revisionTagCodec, this.idCompressor, this._removedRoots.clone());
883
+ this.#events.emit("fork", checkout);
884
+ return checkout;
885
+ }
886
+ switchBranch(branch) {
887
+ assert(this.#transaction.size === 0, 0xc55 /* Cannot switch branches during a transaction */);
888
+ if (this.isSharedBranch) {
889
+ throw new UsageError("Cannot switch a view away from a shared branch. Consider forking first.");
729
890
  }
730
- checkNotDisposed(usageError) {
731
- this.breaker.use();
732
- if (this.disposed) {
733
- if (usageError !== undefined) {
734
- throw new UsageError(usageError);
735
- }
736
- fail(0x911 /* Invalid operation on a disposed TreeCheckout */);
737
- }
891
+ const diff = diffHistories(this.changeFamily.rebaser, this.#transaction.branch.getHead(), branch.getHead(), this.mintRevisionTag);
892
+ this.unregisterFromBranchEvents();
893
+ this.#transaction = this.createTransactionStack(branch);
894
+ this.branch = branch;
895
+ this._branchHistory?.dispose();
896
+ this._branchHistory = undefined;
897
+ this.editLock = new EditLock(this.#transaction.activeBranchEditor);
898
+ this.registerForBranchEvents();
899
+ // TODO: Rework eventing
900
+ this.applyInternalChange(diff);
901
+ this.#events.emit("afterBatch");
902
+ }
903
+ rewindTo(revisionString) {
904
+ this.checkNotDisposed("The branch has already been disposed and cannot be rewound.");
905
+ if (this.#transaction.size > 0) {
906
+ throw new UsageError("Rewinding is not supported during transactions.");
738
907
  }
739
- /**
740
- * Creates a {@link RevertibleAlpha} object that can undo a specific change in the tree's history.
741
- * Revision must exist in the given {@link TreeCheckout}'s branch.
742
- *
743
- * @param revision - The revision tag identifying the change to be made revertible.
744
- * @param kind - The {@link CommitKind} that produced this revertible (e.g., Default, Undo, Redo).
745
- * @param checkout - The {@link TreeCheckout} instance this revertible belongs to.
746
- * @param onRevertibleDisposed - Callback function that will be called when the revertible is disposed.
747
- * @param labelTree - The {@link LabelTree} (if any) active when the original commit was produced.
748
- * The revert commit inherits these labels so that commits and their reverts can be associated.
749
- * @returns A {@link RevertibleAlpha} object.
750
- */
751
- createRevertible(revision, kind, checkout, onRevertibleDisposed, labelTree) {
752
- const commitBranches = checkout.revertibleCommitBranches;
753
- const revertible = {
754
- get status() {
755
- const revertibleCommit = commitBranches.get(revision);
756
- return revertibleCommit === undefined
757
- ? RevertibleStatus.Disposed
758
- : RevertibleStatus.Valid;
759
- },
760
- revert: (releaseOrOptions = true) => {
761
- if (revertible.status === RevertibleStatus.Disposed) {
762
- throw new UsageError("Unable to revert a revertible that has been disposed.");
763
- }
764
- const options = typeof releaseOrOptions === "boolean"
765
- ? { dispose: releaseOrOptions }
766
- : releaseOrOptions;
767
- const revertMetrics = checkout.revertRevertible(revision, kind, labelTree, snapshotCustomMetadata(options.customMetadata));
768
- checkout.logger?.sendTelemetryEvent({
769
- eventName: _a.revertTelemetryEventName,
770
- ...revertMetrics,
771
- });
772
- if (options.dispose ?? true) {
773
- revertible.dispose();
774
- }
775
- },
776
- clone: (targetView) => {
777
- // TODO:#23442: When a revertible is cloned for a forked branch, optimize to create a fork of a revertible branch once per revision NOT once per revision per checkout.
778
- const targetCheckout = getCheckout(targetView);
779
- const revertibleBranch = this.revertibleCommitBranches.get(revision);
780
- if (revertibleBranch === undefined) {
781
- throw new UsageError("Unable to clone a revertible that has been disposed.");
782
- }
783
- const commitToRevert = revertibleBranch.getHead();
784
- const branchHead = __classPrivateFieldGet(targetCheckout, _TreeCheckout_transaction, "f").branch.getHead();
785
- if (isAncestor(commitToRevert, branchHead, true) === false) {
786
- throw new UsageError("Cannot clone revertible for a commit that is not present on the given branch.");
787
- }
788
- targetCheckout.revertibleCommitBranches.set(revision, revertibleBranch.fork());
789
- return this.createRevertible(revision, kind, targetCheckout, onRevertibleDisposed, labelTree);
790
- },
791
- dispose: () => {
792
- if (revertible.status === RevertibleStatus.Disposed) {
793
- throw new UsageError("Unable to dispose a revertible that has already been disposed.");
794
- }
795
- checkout.disposeRevertible(revision);
796
- onRevertibleDisposed?.(revertible);
797
- },
798
- };
799
- return revertible;
908
+ const revision = this.idCompressor.tryRecompress(revisionString);
909
+ if (revision === undefined) {
910
+ throw new UsageError(`Unrecognized revision id: ${revisionString}`);
800
911
  }
801
- viewWith(config) {
802
- const view = new SchematizingSimpleTreeView(this, config, createNodeIdentifierManager(this.idCompressor), () => {
803
- this.views.delete(view);
804
- });
805
- this.views.add(view);
806
- return view;
912
+ const targetCommit = findAncestor(this.#transaction.branch.getHead(), (commit) => commit.revision === revision);
913
+ if (targetCommit === undefined) {
914
+ throw new UsageError(`No commit found with revision: ${revisionString}`);
807
915
  }
808
- get rootEvents() {
809
- return this.forest.anchors.events;
916
+ this.switchBranch(this.#transaction.branch.fork(targetCommit));
917
+ }
918
+ revertTo(revisionString, options) {
919
+ this.checkNotDisposed("The branch has already been disposed and prior revisions cannot be reverted to.");
920
+ this.editLock.checkUnlocked("Reverting to a revision");
921
+ if (this.#transaction.size > 0) {
922
+ throw new UsageError("Reverting to a revision is not supported during transactions.");
810
923
  }
811
- get editor() {
812
- this.checkNotDisposed();
813
- return this.editLock.editor;
924
+ const customMetadata = snapshotCustomMetadata(options?.customMetadata);
925
+ const revision = this.idCompressor.tryRecompress(revisionString);
926
+ if (revision === undefined) {
927
+ throw new UsageError(`Unrecognized revision id: ${revisionString}`);
814
928
  }
815
- locate(anchor) {
816
- this.checkNotDisposed();
817
- return this.forest.anchors.locate(anchor);
929
+ // Populated with the commits that came after the target commit, from oldest to newest.
930
+ const commitsToUndo = [];
931
+ const targetCommit = findAncestor([this.#transaction.activeBranch.getHead(), commitsToUndo], (commit) => commit.revision === revision);
932
+ if (targetCommit === undefined) {
933
+ throw new UsageError(`No commit found with revision: ${revisionString}`);
818
934
  }
819
- get transaction() {
820
- return __classPrivateFieldGet(this, _TreeCheckout_transaction, "f");
935
+ if (!hasSome(commitsToUndo)) {
936
+ // The target commit is already the head of the branch, so there is nothing to revert.
937
+ return;
821
938
  }
822
- fork() {
823
- this.checkNotDisposed("The parent branch has already been disposed and can no longer create new branches.");
824
- // Branching after an unfinished transaction would expose the application to a state where its invariants may be violated.
825
- if (this.transaction.size > 0) {
826
- throw new UsageError("A view cannot be forked while it has a pending transaction.");
827
- }
828
- const branch = __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.fork();
829
- const storedSchema = this.storedSchema.clone();
830
- const forkBreaker = new Breakable("TreeCheckout", this.logger);
831
- const forest = this.forest.clone(storedSchema, forkBreaker);
832
- const checkout = new _a(branch, false, this.changeFamily, storedSchema, forest, this.mintRevisionTag, this.revisionTagCodec, this.idCompressor, this._removedRoots.clone());
833
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("fork", checkout);
834
- return checkout;
939
+ const revisionForInvert = this.mintRevisionTag();
940
+ const toUndo = this.changeFamily.rebaser.compose(commitsToUndo);
941
+ const inverse = this.changeFamily.rebaser.invert(makeAnonChange(toUndo), false, revisionForInvert);
942
+ this.#transaction.branch.apply(tagChange(inverse, revisionForInvert), CommitKind.Default, toMetadataTree(customMetadata));
943
+ }
944
+ rebase(view) {
945
+ const checkout = getCheckout(view);
946
+ this.checkNotDisposed("The target branch of the rebase has been disposed and cannot be rebased.");
947
+ checkout.checkNotDisposed("The source branch of the rebase has been disposed and cannot be rebased.");
948
+ this.editLock.checkUnlocked("Rebasing");
949
+ if (this.transaction.size > 0) {
950
+ throw new UsageError("Views cannot be rebased onto a view that has a pending transaction.");
835
951
  }
836
- switchBranch(branch) {
837
- assert(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").size === 0, 0xc55 /* Cannot switch branches during a transaction */);
838
- if (this.isSharedBranch) {
839
- throw new UsageError("Cannot switch a view away from a shared branch. Consider forking first.");
840
- }
841
- const diff = diffHistories(this.changeFamily.rebaser, __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.getHead(), branch.getHead(), this.mintRevisionTag);
842
- this.unregisterFromBranchEvents();
843
- __classPrivateFieldSet(this, _TreeCheckout_transaction, this.createTransactionStack(branch), "f");
844
- this.branch = branch;
845
- this._branchHistory?.dispose();
846
- this._branchHistory = undefined;
847
- this.editLock = new EditLock(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranchEditor);
848
- this.registerForBranchEvents();
849
- // TODO: Rework eventing
850
- this.applyInternalChange(diff);
851
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("afterBatch");
952
+ if (checkout.transaction.size > 0) {
953
+ throw new UsageError("A view cannot be rebased while it has a pending transaction.");
852
954
  }
853
- rewindTo(revisionString) {
854
- this.checkNotDisposed("The branch has already been disposed and cannot be rewound.");
855
- if (__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").size > 0) {
856
- throw new UsageError("Rewinding is not supported during transactions.");
857
- }
858
- const revision = this.idCompressor.tryRecompress(revisionString);
859
- if (revision === undefined) {
860
- throw new UsageError(`Unrecognized revision id: ${revisionString}`);
861
- }
862
- const targetCommit = findAncestor(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.getHead(), (commit) => commit.revision === revision);
863
- if (targetCommit === undefined) {
864
- throw new UsageError(`No commit found with revision: ${revisionString}`);
865
- }
866
- this.switchBranch(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.fork(targetCommit));
955
+ assert(!checkout.isSharedBranch, 0xa5d /* Shared branches cannot be rebased onto another branch. */);
956
+ checkout.#transaction.branch.rebaseOnto(this.#transaction.branch);
957
+ }
958
+ rebaseOnto(view) {
959
+ getCheckout(view).rebase(this);
960
+ }
961
+ isMissingEditsFrom(view) {
962
+ const viewCheckout = getCheckout(view);
963
+ const targetPath = [];
964
+ const ancestor = findCommonAncestor(this.mainBranch.getHead(), [
965
+ viewCheckout.mainBranch.getHead(),
966
+ targetPath,
967
+ ]);
968
+ if (ancestor === undefined) {
969
+ throw new UsageError("Branches do not share a common ancestor.");
867
970
  }
868
- revertTo(revisionString, options) {
869
- this.checkNotDisposed("The branch has already been disposed and prior revisions cannot be reverted to.");
870
- this.editLock.checkUnlocked("Reverting to a revision");
871
- if (__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").size > 0) {
872
- throw new UsageError("Reverting to a revision is not supported during transactions.");
873
- }
874
- const customMetadata = snapshotCustomMetadata(options?.customMetadata);
875
- const revision = this.idCompressor.tryRecompress(revisionString);
876
- if (revision === undefined) {
877
- throw new UsageError(`Unrecognized revision id: ${revisionString}`);
878
- }
879
- // Populated with the commits that came after the target commit, from oldest to newest.
880
- const commitsToUndo = [];
881
- const targetCommit = findAncestor([__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranch.getHead(), commitsToUndo], (commit) => commit.revision === revision);
882
- if (targetCommit === undefined) {
883
- throw new UsageError(`No commit found with revision: ${revisionString}`);
884
- }
885
- if (!hasSome(commitsToUndo)) {
886
- // The target commit is already the head of the branch, so there is nothing to revert.
887
- return;
888
- }
889
- const revisionForInvert = this.mintRevisionTag();
890
- const toUndo = this.changeFamily.rebaser.compose(commitsToUndo);
891
- const inverse = this.changeFamily.rebaser.invert(makeAnonChange(toUndo), false, revisionForInvert);
892
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.apply(tagChange(inverse, revisionForInvert), CommitKind.Default, toMetadataTree(customMetadata));
971
+ return targetPath.length > 0;
972
+ }
973
+ computeNetChangeIfRebasedOnto(view) {
974
+ const viewCheckout = getCheckout(view);
975
+ const rebased = rebaseBranch(this.mintRevisionTag, this.changeFamily.rebaser, this.#transaction.branch.getHead(), viewCheckout.#transaction.branch.getHead());
976
+ if (rebased.sourceChange === undefined) {
977
+ return undefined;
893
978
  }
894
- rebase(view) {
895
- const checkout = getCheckout(view);
896
- this.checkNotDisposed("The target branch of the rebase has been disposed and cannot be rebased.");
897
- checkout.checkNotDisposed("The source branch of the rebase has been disposed and cannot be rebased.");
898
- this.editLock.checkUnlocked("Rebasing");
899
- if (this.transaction.size > 0) {
900
- throw new UsageError("Views cannot be rebased onto a view that has a pending transaction.");
901
- }
902
- if (checkout.transaction.size > 0) {
903
- throw new UsageError("A view cannot be rebased while it has a pending transaction.");
904
- }
905
- assert(!checkout.isSharedBranch, 0xa5d /* Shared branches cannot be rebased onto another branch. */);
906
- __classPrivateFieldGet(checkout, _TreeCheckout_transaction, "f").branch.rebaseOnto(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch);
979
+ const revision = this.mintRevisionTag();
980
+ return SerializedChange.V1.encode(this.idCompressor, this.changeFamily, rebased.sourceChange, revision, undefined);
981
+ }
982
+ merge(view, disposeMerged = true) {
983
+ const checkout = getCheckout(view);
984
+ this.checkNotDisposed("The target branch of the merge has been disposed and cannot be merged.");
985
+ checkout.checkNotDisposed("The source branch of the merge has been disposed and cannot be merged.");
986
+ this.editLock.checkUnlocked("Merging");
987
+ if (this.transaction.size > 0) {
988
+ throw new UsageError("Views cannot be merged into a view while it has a pending transaction.");
907
989
  }
908
- rebaseOnto(view) {
909
- getCheckout(view).rebase(this);
990
+ if (checkout.transaction.size > 0) {
991
+ throw new UsageError("Views with an open transaction cannot be merged into another view.");
910
992
  }
911
- isMissingEditsFrom(view) {
912
- const viewCheckout = getCheckout(view);
913
- const targetPath = [];
914
- const ancestor = findCommonAncestor(this.mainBranch.getHead(), [
915
- viewCheckout.mainBranch.getHead(),
916
- targetPath,
917
- ]);
918
- if (ancestor === undefined) {
919
- throw new UsageError("Branches do not share a common ancestor.");
920
- }
921
- return targetPath.length > 0;
993
+ this.#transaction.branch.merge(checkout.#transaction.branch);
994
+ if (disposeMerged && !checkout.isSharedBranch) {
995
+ // Dispose the merged checkout unless it is a shared branch.
996
+ checkout[disposeSymbol]();
922
997
  }
923
- computeNetChangeIfRebasedOnto(view) {
924
- const viewCheckout = getCheckout(view);
925
- const rebased = rebaseBranch(this.mintRevisionTag, this.changeFamily.rebaser, __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.getHead(), __classPrivateFieldGet(viewCheckout, _TreeCheckout_transaction, "f").branch.getHead());
926
- if (rebased.sourceChange === undefined) {
927
- return undefined;
928
- }
929
- const revision = this.mintRevisionTag();
930
- return SerializedChange.V1.encode(this.idCompressor, this.changeFamily, rebased.sourceChange, revision, undefined);
998
+ }
999
+ updateSchema(newSchema, allowNonSupersetSchema) {
1000
+ this.checkNotDisposed();
1001
+ if (allowNonSupersetSchema !== true) {
1002
+ assert(allowsRepoSuperset(defaultSchemaPolicy, this.storedSchema.clone(), newSchema), 0xbe6 /* New schema must allow all documents allowed by old schema */);
931
1003
  }
932
- merge(view, disposeMerged = true) {
933
- const checkout = getCheckout(view);
934
- this.checkNotDisposed("The target branch of the merge has been disposed and cannot be merged.");
935
- checkout.checkNotDisposed("The source branch of the merge has been disposed and cannot be merged.");
936
- this.editLock.checkUnlocked("Merging");
937
- if (this.transaction.size > 0) {
938
- throw new UsageError("Views cannot be merged into a view while it has a pending transaction.");
939
- }
940
- if (checkout.transaction.size > 0) {
941
- throw new UsageError("Views with an open transaction cannot be merged into another view.");
942
- }
943
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.merge(__classPrivateFieldGet(checkout, _TreeCheckout_transaction, "f").branch);
944
- if (disposeMerged && !checkout.isSharedBranch) {
945
- // Dispose the merged checkout unless it is a shared branch.
946
- checkout[disposeSymbol]();
947
- }
1004
+ this.editor.schema.setStoredSchema(this.storedSchema.clone(), newSchema);
1005
+ }
1006
+ dispose() {
1007
+ this.editLock.checkUnlocked("Disposing a view");
1008
+ this[disposeSymbol]();
1009
+ }
1010
+ [(_exportVerbose_decorators = [throwIfBroken], _applySerializedChange_decorators = [throwIfBroken], _applyChange_decorators = [throwIfBroken], _runTransaction_decorators = [breakingMethod], _runTransactionAsync_decorators = [breakingMethod], _withCombinedVisitor_decorators = [breakingMethod], _viewWith_decorators = [throwIfBroken], _fork_decorators = [throwIfBroken], disposeSymbol)]() {
1011
+ this.checkNotDisposed("The branch has already been disposed and cannot be disposed again.");
1012
+ this.disposed = true;
1013
+ this.#transaction.branch.dispose();
1014
+ this.#transaction.dispose();
1015
+ this.purgeRevertibles();
1016
+ for (const view of this.views) {
1017
+ view.dispose();
948
1018
  }
949
- updateSchema(newSchema, allowNonSupersetSchema) {
950
- this.checkNotDisposed();
951
- if (allowNonSupersetSchema !== true) {
952
- assert(allowsRepoSuperset(defaultSchemaPolicy, this.storedSchema.clone(), newSchema), 0xbe6 /* New schema must allow all documents allowed by old schema */);
953
- }
954
- this.editor.schema.setStoredSchema(this.storedSchema.clone(), newSchema);
1019
+ this.#events.emit("dispose");
1020
+ this._branchHistory?.dispose();
1021
+ this._branchHistory = undefined;
1022
+ }
1023
+ getRemovedRoots() {
1024
+ this.assertNoUntrackedRoots();
1025
+ const trees = [];
1026
+ const cursor = this.forest.allocateCursor("getRemovedRoots");
1027
+ for (const { id, root } of this._removedRoots.entries()) {
1028
+ const parentField = this._removedRoots.toFieldKey(root);
1029
+ this.forest.moveCursorToPath({ parent: undefined, parentField, parentIndex: 0 }, cursor);
1030
+ const tree = jsonableTreeFromCursor(cursor);
1031
+ // This method is used for tree consistency comparison.
1032
+ const { major, minor } = id;
1033
+ const finalizedMajor = major === undefined ? major : this.revisionTagCodec.encode(major);
1034
+ trees.push([finalizedMajor, minor, tree]);
955
1035
  }
956
- dispose() {
957
- this.editLock.checkUnlocked("Disposing a view");
958
- this[disposeSymbol]();
1036
+ cursor.free();
1037
+ return trees;
1038
+ }
1039
+ /**
1040
+ * This must be called on the root/main checkout after loading from a summary.
1041
+ * @remarks This pattern is necessary because the EditManager skips the normal process of applying commits to branches when loading a summary.
1042
+ * Instead, it simply {@link SharedTreeBranch#setHead | mutates} the branches directly which does not propagate the typical events throughout the rest of the system.
1043
+ */
1044
+ load() {
1045
+ // Set the tip revision as the latest relevant revision for any removed roots that are loaded from a summary - this allows them to be garbage collected later.
1046
+ // When a load happens, the head of the trunk and the head of the local/main branch must be the same (this is enforced by SharedTree).
1047
+ this._removedRoots.setRevisionsForLoadedData(this.#transaction.branch.getHead().revision);
1048
+ // The content of the checkout (e.g. the forest) has (maybe) changed, so fire an afterBatch event.
1049
+ this.#events.emit("afterBatch");
1050
+ }
1051
+ purgeRevertibles() {
1052
+ for (const revertible of this.revertibles.values()) {
1053
+ revertible.dispose();
959
1054
  }
960
- [(_TreeCheckout_events = new WeakMap(), _TreeCheckout_transaction = new WeakMap(), _TreeCheckout_validatedCommits = new WeakMap(), _exportVerbose_decorators = [throwIfBroken], _applySerializedChange_decorators = [throwIfBroken], _applyChange_decorators = [throwIfBroken], _runTransaction_decorators = [breakingMethod], _runTransactionAsync_decorators = [breakingMethod], _withCombinedVisitor_decorators = [breakingMethod], _viewWith_decorators = [throwIfBroken], _fork_decorators = [throwIfBroken], disposeSymbol)]() {
961
- this.checkNotDisposed("The branch has already been disposed and cannot be disposed again.");
962
- this.disposed = true;
963
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.dispose();
964
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").dispose();
965
- this.purgeRevertibles();
966
- for (const view of this.views) {
967
- view.dispose();
968
- }
969
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("dispose");
970
- this._branchHistory?.dispose();
971
- this._branchHistory = undefined;
1055
+ }
1056
+ disposeRevertible(revision) {
1057
+ this.revertibleCommitBranches.get(revision)?.dispose();
1058
+ this.revertibleCommitBranches.delete(revision);
1059
+ this.revertibles.delete(revision);
1060
+ }
1061
+ revertRevertible(revision, kind, labelTree, customMetadata) {
1062
+ this.editLock.checkUnlocked("Reverting a commit");
1063
+ if (this.transaction.size > 0) {
1064
+ throw new UsageError("Undo is not yet supported during transactions.");
972
1065
  }
973
- getRemovedRoots() {
974
- this.assertNoUntrackedRoots();
975
- const trees = [];
976
- const cursor = this.forest.allocateCursor("getRemovedRoots");
977
- for (const { id, root } of this._removedRoots.entries()) {
978
- const parentField = this._removedRoots.toFieldKey(root);
979
- this.forest.moveCursorToPath({ parent: undefined, parentField, parentIndex: 0 }, cursor);
980
- const tree = jsonableTreeFromCursor(cursor);
981
- // This method is used for tree consistency comparison.
982
- const { major, minor } = id;
983
- const finalizedMajor = major === undefined ? major : this.revisionTagCodec.encode(major);
984
- trees.push([finalizedMajor, minor, tree]);
985
- }
986
- cursor.free();
987
- return trees;
1066
+ const revertibleBranch = this.revertibleCommitBranches.get(revision);
1067
+ assert(revertibleBranch !== undefined, 0x7cc /* expected to find a revertible commit */);
1068
+ const commitToRevert = revertibleBranch.getHead();
1069
+ const revisionForInvert = this.mintRevisionTag();
1070
+ let change = tagChange(this.changeFamily.rebaser.invert(commitToRevert, false, revisionForInvert), revisionForInvert);
1071
+ const headCommit = this.#transaction.branch.getHead();
1072
+ // Rebase the inverted change onto any commits that occurred after the undoable commits.
1073
+ if (commitToRevert !== headCommit) {
1074
+ // The inverse may be rebased over newer commits which (despite being present in the history)
1075
+ // have no net effect on the document state (e.g. an edit plus its undo).
1076
+ // In that case, a no-change constraint should not be violated during rebase.
1077
+ const diff = diffHistories(this.changeFamily.rebaser, commitToRevert, headCommit, this.mintRevisionTag);
1078
+ const ignoreNoChangeViolation = !sharedTreeChangeHasApplicationFacingChanges(diff);
1079
+ change = tagChange(rebaseChange(this.changeFamily.rebaser, change, commitToRevert, headCommit, this.mintRevisionTag, ignoreNoChangeViolation).change, revisionForInvert);
988
1080
  }
989
- /**
990
- * This must be called on the root/main checkout after loading from a summary.
991
- * @remarks This pattern is necessary because the EditManager skips the normal process of applying commits to branches when loading a summary.
992
- * Instead, it simply {@link SharedTreeBranch#setHead | mutates} the branches directly which does not propagate the typical events throughout the rest of the system.
993
- */
994
- load() {
995
- // Set the tip revision as the latest relevant revision for any removed roots that are loaded from a summary - this allows them to be garbage collected later.
996
- // When a load happens, the head of the trunk and the head of the local/main branch must be the same (this is enforced by SharedTree).
997
- this._removedRoots.setRevisionsForLoadedData(__classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.getHead().revision);
998
- // The content of the checkout (e.g. the forest) has (maybe) changed, so fire an afterBatch event.
999
- __classPrivateFieldGet(this, _TreeCheckout_events, "f").emit("afterBatch");
1081
+ // Install the original commit's label tree so the revert commit's metadata inherits
1082
+ // the same labels. Reusing the captured tree (rather than wrapping it) ensures
1083
+ // revert-of-revert does not introduce new nesting.
1084
+ const previousLabelTreeNode = this.labelTreeNode;
1085
+ this.labelTreeNode = labelTree;
1086
+ try {
1087
+ this.#transaction.branch.apply(change, kind === CommitKind.Default || kind === CommitKind.Redo
1088
+ ? CommitKind.Undo
1089
+ : CommitKind.Redo, toMetadataTree(customMetadata));
1000
1090
  }
1001
- purgeRevertibles() {
1002
- for (const revertible of this.revertibles.values()) {
1003
- revertible.dispose();
1004
- }
1091
+ finally {
1092
+ this.labelTreeNode = previousLabelTreeNode;
1005
1093
  }
1006
- disposeRevertible(revision) {
1007
- this.revertibleCommitBranches.get(revision)?.dispose();
1008
- this.revertibleCommitBranches.delete(revision);
1009
- this.revertibles.delete(revision);
1094
+ // Derive some stats about the reversion to return to the caller.
1095
+ let revertAge = 0;
1096
+ let currentCommit = headCommit;
1097
+ while (commitToRevert.revision !== currentCommit.revision) {
1098
+ revertAge++;
1099
+ const parentCommit = currentCommit.parent;
1100
+ assert(parentCommit !== undefined, 0x9a9 /* expected to find a parent commit */);
1101
+ currentCommit = parentCommit;
1010
1102
  }
1011
- revertRevertible(revision, kind, labelTree, customMetadata) {
1012
- this.editLock.checkUnlocked("Reverting a commit");
1013
- if (this.transaction.size > 0) {
1014
- throw new UsageError("Undo is not yet supported during transactions.");
1015
- }
1016
- const revertibleBranch = this.revertibleCommitBranches.get(revision);
1017
- assert(revertibleBranch !== undefined, 0x7cc /* expected to find a revertible commit */);
1018
- const commitToRevert = revertibleBranch.getHead();
1019
- const revisionForInvert = this.mintRevisionTag();
1020
- let change = tagChange(this.changeFamily.rebaser.invert(commitToRevert, false, revisionForInvert), revisionForInvert);
1021
- const headCommit = __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.getHead();
1022
- // Rebase the inverted change onto any commits that occurred after the undoable commits.
1023
- if (commitToRevert !== headCommit) {
1024
- // The inverse may be rebased over newer commits which (despite being present in the history)
1025
- // have no net effect on the document state (e.g. an edit plus its undo).
1026
- // In that case, a no-change constraint should not be violated during rebase.
1027
- const diff = diffHistories(this.changeFamily.rebaser, commitToRevert, headCommit, this.mintRevisionTag);
1028
- const ignoreNoChangeViolation = !sharedTreeChangeHasVisibleChanges(diff);
1029
- change = tagChange(rebaseChange(this.changeFamily.rebaser, change, commitToRevert, headCommit, this.mintRevisionTag, ignoreNoChangeViolation).change, revisionForInvert);
1030
- }
1031
- // Install the original commit's label tree so the revert commit's metadata inherits
1032
- // the same labels. Reusing the captured tree (rather than wrapping it) ensures
1033
- // revert-of-revert does not introduce new nesting.
1034
- const previousLabelTreeNode = this.labelTreeNode;
1035
- this.labelTreeNode = labelTree;
1036
- try {
1037
- __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch.apply(change, kind === CommitKind.Default || kind === CommitKind.Redo
1038
- ? CommitKind.Undo
1039
- : CommitKind.Redo, toMetadataTree(customMetadata));
1040
- }
1041
- finally {
1042
- this.labelTreeNode = previousLabelTreeNode;
1043
- }
1044
- // Derive some stats about the reversion to return to the caller.
1045
- let revertAge = 0;
1046
- let currentCommit = headCommit;
1047
- while (commitToRevert.revision !== currentCommit.revision) {
1048
- revertAge++;
1049
- const parentCommit = currentCommit.parent;
1050
- assert(parentCommit !== undefined, 0x9a9 /* expected to find a parent commit */);
1051
- currentCommit = parentCommit;
1052
- }
1053
- return { age: revertAge };
1103
+ return { age: revertAge };
1104
+ }
1105
+ assertNoUntrackedRoots() {
1106
+ const cursor = this.forest.getCursorAboveDetachedFields();
1107
+ const rootFields = new Set([rootFieldKey]);
1108
+ for (const { root } of this._removedRoots.entries()) {
1109
+ rootFields.add(this._removedRoots.toFieldKey(root));
1054
1110
  }
1055
- assertNoUntrackedRoots() {
1056
- const cursor = this.forest.getCursorAboveDetachedFields();
1057
- const rootFields = new Set([rootFieldKey]);
1058
- for (const { root } of this._removedRoots.entries()) {
1059
- rootFields.add(this._removedRoots.toFieldKey(root));
1060
- }
1061
- if (!cursor.firstField()) {
1062
- return;
1063
- }
1064
- do {
1065
- const field = cursor.getFieldKey();
1066
- assert(rootFields.has(field), 0xa22 /* Forest has a root field which is unknown to the detached field index */);
1067
- rootFields.delete(field);
1068
- } while (cursor.nextField());
1111
+ if (!cursor.firstField()) {
1112
+ return;
1069
1113
  }
1070
- /**
1071
- * `true` iff the given branch change event is due to a remote change
1072
- */
1073
- isRemoteChangeEvent(event) {
1074
- return (
1075
- // Remote changes are only ever applied to shared branches
1076
- this.isSharedBranch &&
1077
- // Remote changes are applied to the branch by rebasing it onto the trunk.
1078
- // No other rebases are allowed on shared branches, so we can use this to detect remote changes.
1079
- event.type === "rebase");
1114
+ do {
1115
+ const field = cursor.getFieldKey();
1116
+ assert(rootFields.has(field), 0xa22 /* Forest has a root field which is unknown to the detached field index */);
1117
+ rootFields.delete(field);
1118
+ } while (cursor.nextField());
1119
+ }
1120
+ /**
1121
+ * `true` iff the given branch change event is due to a remote change
1122
+ */
1123
+ isRemoteChangeEvent(event) {
1124
+ return (
1125
+ // Remote changes are only ever applied to shared branches
1126
+ this.isSharedBranch &&
1127
+ // Remote changes are applied to the branch by rebasing it onto the trunk.
1128
+ // No other rebases are allowed on shared branches, so we can use this to detect remote changes.
1129
+ event.type === "rebase");
1130
+ }
1131
+ // #region Commit Validation
1132
+ /** Used to maintain the contract of {@link onCommitValid}(). */
1133
+ #validatedCommits = new WeakMap();
1134
+ /**
1135
+ * Registers a function to be called when the given commit is validated.
1136
+ * @remarks A commit is validated by the checkout after it has been applied to the checkout's state (e.g. it has an effect on the forest).
1137
+ * If the commit applies successfully (i.e. it does not raise any unexpected errors), the commit is considered valid and the registered function is called.
1138
+ * If the commit does not apply successfully (because it causes an unexpected error), the function is not called (and the checkout will left in an error state).
1139
+ *
1140
+ * If the commit has already been validated when this function is called, the function is called immediately and this function returns `true`.
1141
+ * Otherwise, the function is registered to be called later and this function returns `false`.
1142
+ */
1143
+ onCommitValid(commit, fn) {
1144
+ const validated = getOrCreate(this.#validatedCommits, commit, () => []);
1145
+ if (validated === true) {
1146
+ fn(commit);
1147
+ return true;
1080
1148
  }
1081
- /**
1082
- * Registers a function to be called when the given commit is validated.
1083
- * @remarks A commit is validated by the checkout after it has been applied to the checkout's state (e.g. it has an effect on the forest).
1084
- * If the commit applies successfully (i.e. it does not raise any unexpected errors), the commit is considered valid and the registered function is called.
1085
- * If the commit does not apply successfully (because it causes an unexpected error), the function is not called (and the checkout will left in an error state).
1086
- *
1087
- * If the commit has already been validated when this function is called, the function is called immediately and this function returns `true`.
1088
- * Otherwise, the function is registered to be called later and this function returns `false`.
1089
- */
1090
- onCommitValid(commit, fn) {
1091
- const validated = getOrCreate(__classPrivateFieldGet(this, _TreeCheckout_validatedCommits, "f"), commit, () => []);
1092
- if (validated === true) {
1149
+ validated.push(fn);
1150
+ return false;
1151
+ }
1152
+ /** Mark the given commit as "validated" according to the contract of {@link onCommitValid}(). */
1153
+ validateCommit(commit) {
1154
+ const validated = getOrCreate(this.#validatedCommits, commit, () => []);
1155
+ if (validated !== true) {
1156
+ for (const fn of validated) {
1093
1157
  fn(commit);
1094
- return true;
1095
- }
1096
- validated.push(fn);
1097
- return false;
1098
- }
1099
- /** Mark the given commit as "validated" according to the contract of {@link onCommitValid}(). */
1100
- validateCommit(commit) {
1101
- const validated = getOrCreate(__classPrivateFieldGet(this, _TreeCheckout_validatedCommits, "f"), commit, () => []);
1102
- if (validated !== true) {
1103
- for (const fn of validated) {
1104
- fn(commit);
1105
- }
1106
- __classPrivateFieldGet(this, _TreeCheckout_validatedCommits, "f").set(commit, true);
1107
1158
  }
1159
+ this.#validatedCommits.set(commit, true);
1108
1160
  }
1109
- resetEnrichmentStats() {
1110
- this.enrichmentStats.batches = 0;
1111
- this.enrichmentStats.diffs = 0;
1112
- this.enrichmentStats.commitsEnriched = 0;
1113
- this.enrichmentStats.refreshers = 0;
1114
- this.enrichmentStats.forks = 0;
1115
- this.enrichmentStats.applied = 0;
1161
+ }
1162
+ // #endregion Commit Validation
1163
+ // #region Enrichment
1164
+ /**
1165
+ * Statistics about enrichment operations performed by this checkout.
1166
+ * Used for testing. May be used for telemetry in the future.
1167
+ * The performance cost of maintaining this information is negligible.
1168
+ */
1169
+ enrichmentStats = { batches: 0, diffs: 0, commitsEnriched: 0, refreshers: 0, forks: 0, applied: 0 };
1170
+ resetEnrichmentStats() {
1171
+ this.enrichmentStats.batches = 0;
1172
+ this.enrichmentStats.diffs = 0;
1173
+ this.enrichmentStats.commitsEnriched = 0;
1174
+ this.enrichmentStats.refreshers = 0;
1175
+ this.enrichmentStats.forks = 0;
1176
+ this.enrichmentStats.applied = 0;
1177
+ }
1178
+ getEnrichmentStats() {
1179
+ return { ...this.enrichmentStats };
1180
+ }
1181
+ enrich(context, changes, forceValidation) {
1182
+ if (!hasSome(changes)) {
1183
+ return [];
1116
1184
  }
1117
- getEnrichmentStats() {
1118
- return { ...this.enrichmentStats };
1185
+ this.enrichmentStats.batches += 1;
1186
+ const enricher = new SharedTreeChangeEnricher(this.forest, this._removedRoots, this.storedSchema, this.idCompressor, () => (this.enrichmentStats.commitsEnriched += 1), () => (this.enrichmentStats.refreshers += 1), () => (this.enrichmentStats.forks += 1), () => (this.enrichmentStats.applied += 1));
1187
+ // This `lastCommitApplied` may be on the main branch or on a transaction branch.
1188
+ // In either case, it is crucial that the state of the forest & detached field index reflects all changes up to and including this commit.
1189
+ const lastCommitApplied = this.#transaction.activeBranch.getHead();
1190
+ if (context !== lastCommitApplied) {
1191
+ enricher.enqueueChange(() => {
1192
+ this.enrichmentStats.diffs += 1;
1193
+ const diff = diffHistories(this.changeFamily.rebaser, lastCommitApplied, context, this.mintRevisionTag);
1194
+ return makeAnonChange(diff);
1195
+ });
1119
1196
  }
1120
- enrich(context, changes, forceValidation) {
1121
- if (!hasSome(changes)) {
1122
- return [];
1123
- }
1124
- this.enrichmentStats.batches += 1;
1125
- const enricher = new SharedTreeChangeEnricher(this.forest, this._removedRoots, this.storedSchema, this.idCompressor, () => (this.enrichmentStats.commitsEnriched += 1), () => (this.enrichmentStats.refreshers += 1), () => (this.enrichmentStats.forks += 1), () => (this.enrichmentStats.applied += 1));
1126
- // This `lastCommitApplied` may be on the main branch or on a transaction branch.
1127
- // In either case, it is crucial that the state of the forest & detached field index reflects all changes up to and including this commit.
1128
- const lastCommitApplied = __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").activeBranch.getHead();
1129
- if (context !== lastCommitApplied) {
1130
- enricher.enqueueChange(() => {
1131
- this.enrichmentStats.diffs += 1;
1132
- const diff = diffHistories(this.changeFamily.rebaser, lastCommitApplied, context, this.mintRevisionTag);
1133
- return makeAnonChange(diff);
1134
- });
1135
- }
1136
- const enrichedChanges = [];
1137
- for (const change of changes) {
1138
- const enrichedChange = enricher.enrich(change.change);
1139
- enrichedChanges.push(enrichedChange);
1140
- // We could either apply the original or the enriched change: either should allow subsequent changes to be enriched correctly.
1141
- // We choose to apply the enriched change in order to more closely replicate what a peer will experience (assuming no concurrent changes).
1142
- // This makes it more likely that we'll detect a bug in the enrichment logic.
1143
- // Note that enqueueing the change does not guarantee that it will be applied unless `forceValidation` is enabled.
1144
- enricher.enqueueChange(tagChange(enrichedChange, change.revision));
1145
- }
1146
- if (forceValidation) {
1147
- // Ensure that all changes can be applied successfully.
1148
- // This is useful for catching bugs in the enrichment logic and in the rebasing logic that may have been involved in producing the changes.
1149
- // Note that we cannot guarantee that the enriched change will be applied successfully even in the absence of concurrent changes,
1150
- // because the checkout state we are applying this enriched change to was derived from the state of the checkout, which may be different from that of a peer.
1151
- enricher.purgeChangeQueue();
1152
- }
1153
- enricher[disposeSymbol]();
1154
- return enrichedChanges;
1197
+ const enrichedChanges = [];
1198
+ for (const change of changes) {
1199
+ const enrichedChange = enricher.enrich(change.change);
1200
+ enrichedChanges.push(enrichedChange);
1201
+ // We could either apply the original or the enriched change: either should allow subsequent changes to be enriched correctly.
1202
+ // We choose to apply the enriched change in order to more closely replicate what a peer will experience (assuming no concurrent changes).
1203
+ // This makes it more likely that we'll detect a bug in the enrichment logic.
1204
+ // Note that enqueueing the change does not guarantee that it will be applied unless `forceValidation` is enabled.
1205
+ enricher.enqueueChange(tagChange(enrichedChange, change.revision));
1155
1206
  }
1156
- get mainBranch() {
1157
- return __classPrivateFieldGet(this, _TreeCheckout_transaction, "f").branch;
1207
+ if (forceValidation) {
1208
+ // Ensure that all changes can be applied successfully.
1209
+ // This is useful for catching bugs in the enrichment logic and in the rebasing logic that may have been involved in producing the changes.
1210
+ // Note that we cannot guarantee that the enriched change will be applied successfully even in the absence of concurrent changes,
1211
+ // because the checkout state we are applying this enriched change to was derived from the state of the checkout, which may be different from that of a peer.
1212
+ enricher.purgeChangeQueue();
1158
1213
  }
1159
- },
1160
- (() => {
1161
- const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
1162
- __esDecorate(_a, null, _exportVerbose_decorators, { kind: "method", name: "exportVerbose", static: false, private: false, access: { has: obj => "exportVerbose" in obj, get: obj => obj.exportVerbose }, metadata: _metadata }, null, _instanceExtraInitializers);
1163
- __esDecorate(_a, null, _applySerializedChange_decorators, { kind: "method", name: "applySerializedChange", static: false, private: false, access: { has: obj => "applySerializedChange" in obj, get: obj => obj.applySerializedChange }, metadata: _metadata }, null, _instanceExtraInitializers);
1164
- __esDecorate(_a, null, _applyChange_decorators, { kind: "method", name: "applyChange", static: false, private: false, access: { has: obj => "applyChange" in obj, get: obj => obj.applyChange }, metadata: _metadata }, null, _instanceExtraInitializers);
1165
- __esDecorate(_a, null, _runTransaction_decorators, { kind: "method", name: "runTransaction", static: false, private: false, access: { has: obj => "runTransaction" in obj, get: obj => obj.runTransaction }, metadata: _metadata }, null, _instanceExtraInitializers);
1166
- __esDecorate(_a, null, _runTransactionAsync_decorators, { kind: "method", name: "runTransactionAsync", static: false, private: false, access: { has: obj => "runTransactionAsync" in obj, get: obj => obj.runTransactionAsync }, metadata: _metadata }, null, _instanceExtraInitializers);
1167
- __esDecorate(_a, null, _withCombinedVisitor_decorators, { kind: "method", name: "withCombinedVisitor", static: false, private: false, access: { has: obj => "withCombinedVisitor" in obj, get: obj => obj.withCombinedVisitor }, metadata: _metadata }, null, _instanceExtraInitializers);
1168
- __esDecorate(_a, null, _viewWith_decorators, { kind: "method", name: "viewWith", static: false, private: false, access: { has: obj => "viewWith" in obj, get: obj => obj.viewWith }, metadata: _metadata }, null, _instanceExtraInitializers);
1169
- __esDecorate(_a, null, _fork_decorators, { kind: "method", name: "fork", static: false, private: false, access: { has: obj => "fork" in obj, get: obj => obj.fork }, metadata: _metadata }, null, _instanceExtraInitializers);
1170
- if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
1171
- })(),
1172
- /**
1173
- * The name of the telemetry event logged for calls to {@link TreeCheckout.revertRevertible}.
1174
- * @privateRemarks Exposed for testing purposes.
1175
- */
1176
- _a.revertTelemetryEventName = "RevertRevertible",
1177
- _a;
1214
+ enricher[disposeSymbol]();
1215
+ return enrichedChanges;
1216
+ }
1217
+ get mainBranch() {
1218
+ return this.#transaction.branch;
1219
+ }
1220
+ };
1178
1221
  })();
1179
1222
  export { TreeCheckout };
1223
+ function getSchemaChangeTelemetryMetrics(oldSchema, newSchema, isInverse) {
1224
+ let addedNodeSchemaCount = 0;
1225
+ for (const identifier of newSchema.nodeSchema.keys()) {
1226
+ if (!oldSchema.nodeSchema.has(identifier)) {
1227
+ addedNodeSchemaCount++;
1228
+ }
1229
+ }
1230
+ let removedNodeSchemaCount = 0;
1231
+ for (const identifier of oldSchema.nodeSchema.keys()) {
1232
+ if (!newSchema.nodeSchema.has(identifier)) {
1233
+ removedNodeSchemaCount++;
1234
+ }
1235
+ }
1236
+ return {
1237
+ changeKind: isInverse
1238
+ ? "rollback"
1239
+ : oldSchema.nodeSchema.size === 0
1240
+ ? "initialize"
1241
+ : allowsRepoSuperset(defaultSchemaPolicy, oldSchema, newSchema)
1242
+ ? "upgrade"
1243
+ : "restriction",
1244
+ isInverse,
1245
+ oldNodeSchemaCount: oldSchema.nodeSchema.size,
1246
+ newNodeSchemaCount: newSchema.nodeSchema.size,
1247
+ addedNodeSchemaCount,
1248
+ removedNodeSchemaCount,
1249
+ rootFieldKindChanged: oldSchema.rootFieldSchema.kind !== newSchema.rootFieldSchema.kind,
1250
+ oldRootAllowedTypeCount: oldSchema.rootFieldSchema.types.size,
1251
+ newRootAllowedTypeCount: newSchema.rootFieldSchema.types.size,
1252
+ };
1253
+ }
1180
1254
  /**
1181
1255
  * A helper class that assists {@link TreeCheckout} in preventing functionality from being used while the tree is in the middle of being edited.
1182
1256
  */
1183
1257
  class EditLock {
1258
+ /**
1259
+ * Edits the tree by calling the methods of the editor passed into the {@link EditLock} constructor.
1260
+ * @remarks Edits will throw an error if the lock is currently locked.
1261
+ */
1262
+ editor;
1263
+ /**
1264
+ * The current status of the lock.
1265
+ * The `reason` string will be included in the error message if an attempt is made to edit the tree while the lock is held.
1266
+ */
1267
+ status = { isLocked: false };
1184
1268
  /**
1185
1269
  * @param editor - an editor which will be used to create a new editor that is monitored to determine if any changes are happening to the tree.
1186
1270
  * Use {@link EditLock.editor} in place of the original editor to ensure that changes are monitored.
1187
1271
  */
1188
1272
  constructor(editor) {
1189
- /**
1190
- * The current status of the lock.
1191
- * The `reason` string will be included in the error message if an attempt is made to edit the tree while the lock is held.
1192
- */
1193
- this.status = { isLocked: false };
1194
1273
  const checkLock = () => this.checkUnlocked("Editing the tree");
1195
1274
  this.editor = {
1196
1275
  get schema() {
@@ -1288,19 +1367,19 @@ function verboseFromCursor(reader, schema) {
1288
1367
  };
1289
1368
  }
1290
1369
  /**
1291
- * Enumerates through a shared tree change, looking for schema change and field changes that result in visible changes to the tree (e.g. an insert, move, delete).
1292
- * This function also considers changes to detached roots to be visible changes, but not renames of roots or builds of new roots.
1370
+ * Whether the change contains any application-facing changes.
1293
1371
  *
1294
1372
  * @param change - The change to analyze.
1295
- * @returns True if the change contains any schema changes or any field changes that result in visible changes to the tree, false otherwise.
1373
+ * @returns True if the change contains any schema changes or any field changes (either in the document tree or in detached trees), false otherwise.
1296
1374
  */
1297
- function sharedTreeChangeHasVisibleChanges(change) {
1375
+ function sharedTreeChangeHasApplicationFacingChanges(change) {
1298
1376
  for (const inner of change.changes) {
1299
1377
  if (inner.type === "schema") {
1300
1378
  return true;
1301
1379
  }
1302
1380
  const delta = intoDelta(tagChange(inner.innerChange, undefined));
1303
- if (deltaFieldMapHasVisibleChanges(delta.fields)) {
1381
+ const profile = getDeltaChangeProfile(delta);
1382
+ if (profile.hasChangesInDocumentTree || profile.hasChangesInDetachedTrees) {
1304
1383
  return true;
1305
1384
  }
1306
1385
  }