@fluidframework/tree 2.12.0 → 2.20.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 (496) hide show
  1. package/CHANGELOG.md +154 -0
  2. package/api-report/tree.alpha.api.md +108 -22
  3. package/api-report/tree.beta.api.md +31 -15
  4. package/api-report/tree.legacy.alpha.api.md +31 -15
  5. package/api-report/tree.legacy.public.api.md +31 -15
  6. package/api-report/tree.public.api.md +31 -15
  7. package/assertTagging.config.mjs +14 -0
  8. package/dist/alpha.d.ts +14 -0
  9. package/dist/beta.d.ts +2 -0
  10. package/dist/core/index.d.ts +2 -2
  11. package/dist/core/index.d.ts.map +1 -1
  12. package/dist/core/index.js +6 -4
  13. package/dist/core/index.js.map +1 -1
  14. package/dist/core/rebase/index.d.ts +2 -2
  15. package/dist/core/rebase/index.d.ts.map +1 -1
  16. package/dist/core/rebase/index.js +5 -1
  17. package/dist/core/rebase/index.js.map +1 -1
  18. package/dist/core/rebase/types.d.ts +5 -4
  19. package/dist/core/rebase/types.d.ts.map +1 -1
  20. package/dist/core/rebase/types.js +29 -1
  21. package/dist/core/rebase/types.js.map +1 -1
  22. package/dist/core/rebase/utils.d.ts +10 -0
  23. package/dist/core/rebase/utils.d.ts.map +1 -1
  24. package/dist/core/rebase/utils.js +22 -1
  25. package/dist/core/rebase/utils.js.map +1 -1
  26. package/dist/core/tree/delta.d.ts +21 -26
  27. package/dist/core/tree/delta.d.ts.map +1 -1
  28. package/dist/core/tree/delta.js.map +1 -1
  29. package/dist/core/tree/deltaUtil.d.ts +1 -3
  30. package/dist/core/tree/deltaUtil.d.ts.map +1 -1
  31. package/dist/core/tree/deltaUtil.js +2 -14
  32. package/dist/core/tree/deltaUtil.js.map +1 -1
  33. package/dist/core/tree/index.d.ts +1 -1
  34. package/dist/core/tree/index.d.ts.map +1 -1
  35. package/dist/core/tree/index.js +1 -3
  36. package/dist/core/tree/index.js.map +1 -1
  37. package/dist/core/tree/visitDelta.d.ts.map +1 -1
  38. package/dist/core/tree/visitDelta.js +82 -80
  39. package/dist/core/tree/visitDelta.js.map +1 -1
  40. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
  41. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  42. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  43. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  44. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  45. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  46. package/dist/feature-libraries/deltaUtils.d.ts.map +1 -1
  47. package/dist/feature-libraries/deltaUtils.js +13 -0
  48. package/dist/feature-libraries/deltaUtils.js.map +1 -1
  49. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  50. package/dist/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  51. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  52. package/dist/feature-libraries/index.d.ts +0 -1
  53. package/dist/feature-libraries/index.d.ts.map +1 -1
  54. package/dist/feature-libraries/index.js +2 -4
  55. package/dist/feature-libraries/index.js.map +1 -1
  56. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +5 -5
  57. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  58. package/dist/feature-libraries/modular-schema/crossFieldQueries.js +2 -3
  59. package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  60. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +30 -6
  61. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  62. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  63. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  64. package/dist/feature-libraries/modular-schema/genericFieldKind.js +2 -1
  65. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  66. package/dist/feature-libraries/modular-schema/index.d.ts +2 -2
  67. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  68. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  69. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  70. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  71. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +8 -8
  72. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  73. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +5 -4
  74. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  75. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +186 -216
  76. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  77. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +23 -20
  78. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  79. package/dist/feature-libraries/modular-schema/modularChangeTypes.js +20 -0
  80. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  81. package/dist/feature-libraries/optional-field/optionalField.d.ts +3 -3
  82. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  83. package/dist/feature-libraries/optional-field/optionalField.js +24 -4
  84. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  85. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts +1 -1
  86. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  87. package/dist/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  88. package/dist/feature-libraries/sequence-field/rebase.js +4 -4
  89. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  90. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  91. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  92. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  93. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  94. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  95. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  96. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  97. package/dist/feature-libraries/sequence-field/utils.d.ts +2 -2
  98. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  99. package/dist/feature-libraries/sequence-field/utils.js +50 -9
  100. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  101. package/dist/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  102. package/dist/feature-libraries/treeCursorUtils.js +4 -1
  103. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  104. package/dist/index.d.ts +27 -3
  105. package/dist/index.d.ts.map +1 -1
  106. package/dist/index.js +5 -2
  107. package/dist/index.js.map +1 -1
  108. package/dist/legacy.d.ts +2 -0
  109. package/dist/package.json +2 -1
  110. package/dist/packageVersion.d.ts +1 -1
  111. package/dist/packageVersion.js +1 -1
  112. package/dist/packageVersion.js.map +1 -1
  113. package/dist/public.d.ts +2 -0
  114. package/dist/shared-tree/index.d.ts +3 -2
  115. package/dist/shared-tree/index.d.ts.map +1 -1
  116. package/dist/shared-tree/index.js +6 -3
  117. package/dist/shared-tree/index.js.map +1 -1
  118. package/dist/shared-tree/schematizingTreeView.d.ts +10 -1
  119. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  120. package/dist/shared-tree/schematizingTreeView.js +43 -0
  121. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  122. package/dist/shared-tree/sharedTree.d.ts +44 -21
  123. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  124. package/dist/shared-tree/sharedTree.js +41 -35
  125. package/dist/shared-tree/sharedTree.js.map +1 -1
  126. package/dist/shared-tree/transactionTypes.d.ts +105 -0
  127. package/dist/shared-tree/transactionTypes.d.ts.map +1 -0
  128. package/dist/shared-tree/transactionTypes.js +13 -0
  129. package/dist/shared-tree/transactionTypes.js.map +1 -0
  130. package/dist/shared-tree/treeApi.d.ts +1 -25
  131. package/dist/shared-tree/treeApi.d.ts.map +1 -1
  132. package/dist/shared-tree/treeApi.js +4 -8
  133. package/dist/shared-tree/treeApi.js.map +1 -1
  134. package/dist/shared-tree/treeCheckout.d.ts +4 -1
  135. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  136. package/dist/shared-tree/treeCheckout.js +142 -23
  137. package/dist/shared-tree/treeCheckout.js.map +1 -1
  138. package/dist/shared-tree-core/sharedTreeCore.js +1 -1
  139. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  140. package/dist/simple-tree/api/index.d.ts +1 -0
  141. package/dist/simple-tree/api/index.d.ts.map +1 -1
  142. package/dist/simple-tree/api/index.js +3 -1
  143. package/dist/simple-tree/api/index.js.map +1 -1
  144. package/dist/simple-tree/api/jsonSchema.d.ts +6 -0
  145. package/dist/simple-tree/api/jsonSchema.d.ts.map +1 -1
  146. package/dist/simple-tree/api/jsonSchema.js.map +1 -1
  147. package/dist/simple-tree/api/schemaFactory.d.ts +21 -12
  148. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  149. package/dist/simple-tree/api/schemaFactory.js +5 -2
  150. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  151. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
  152. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
  153. package/dist/simple-tree/api/schemaFactoryAlpha.js +90 -0
  154. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
  155. package/dist/simple-tree/api/simpleSchema.d.ts +5 -1
  156. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
  157. package/dist/simple-tree/api/simpleSchema.js.map +1 -1
  158. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +13 -10
  159. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  160. package/dist/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  161. package/dist/simple-tree/api/tree.d.ts +60 -0
  162. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  163. package/dist/simple-tree/api/tree.js.map +1 -1
  164. package/dist/simple-tree/api/treeNodeApi.js +1 -1
  165. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  166. package/dist/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  167. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js +11 -11
  168. package/dist/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  169. package/dist/simple-tree/arrayNode.d.ts +2 -2
  170. package/dist/simple-tree/arrayNode.d.ts.map +1 -1
  171. package/dist/simple-tree/arrayNode.js +3 -2
  172. package/dist/simple-tree/arrayNode.js.map +1 -1
  173. package/dist/simple-tree/core/treeNodeSchema.d.ts +10 -6
  174. package/dist/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  175. package/dist/simple-tree/core/treeNodeSchema.js.map +1 -1
  176. package/dist/simple-tree/index.d.ts +2 -2
  177. package/dist/simple-tree/index.d.ts.map +1 -1
  178. package/dist/simple-tree/index.js +3 -2
  179. package/dist/simple-tree/index.js.map +1 -1
  180. package/dist/simple-tree/leafNodeSchema.d.ts +5 -5
  181. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  182. package/dist/simple-tree/mapNode.d.ts +2 -2
  183. package/dist/simple-tree/mapNode.d.ts.map +1 -1
  184. package/dist/simple-tree/mapNode.js +2 -1
  185. package/dist/simple-tree/mapNode.js.map +1 -1
  186. package/dist/simple-tree/objectNode.d.ts +2 -2
  187. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  188. package/dist/simple-tree/objectNode.js +2 -1
  189. package/dist/simple-tree/objectNode.js.map +1 -1
  190. package/dist/simple-tree/objectNodeTypes.d.ts +2 -2
  191. package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
  192. package/dist/simple-tree/objectNodeTypes.js.map +1 -1
  193. package/dist/simple-tree/schemaTypes.d.ts +47 -1
  194. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  195. package/dist/simple-tree/schemaTypes.js.map +1 -1
  196. package/dist/simple-tree/toMapTree.js +1 -1
  197. package/dist/simple-tree/toMapTree.js.map +1 -1
  198. package/dist/util/bTreeUtils.d.ts +10 -0
  199. package/dist/util/bTreeUtils.d.ts.map +1 -0
  200. package/dist/util/bTreeUtils.js +52 -0
  201. package/dist/util/bTreeUtils.js.map +1 -0
  202. package/dist/util/idAllocator.d.ts +0 -2
  203. package/dist/util/idAllocator.d.ts.map +1 -1
  204. package/dist/util/idAllocator.js +0 -2
  205. package/dist/util/idAllocator.js.map +1 -1
  206. package/dist/util/index.d.ts +3 -2
  207. package/dist/util/index.d.ts.map +1 -1
  208. package/dist/util/index.js +7 -5
  209. package/dist/util/index.js.map +1 -1
  210. package/dist/util/rangeMap.d.ts +95 -43
  211. package/dist/util/rangeMap.d.ts.map +1 -1
  212. package/dist/util/rangeMap.js +202 -148
  213. package/dist/util/rangeMap.js.map +1 -1
  214. package/dist/util/utils.d.ts +26 -2
  215. package/dist/util/utils.d.ts.map +1 -1
  216. package/dist/util/utils.js +17 -2
  217. package/dist/util/utils.js.map +1 -1
  218. package/lib/alpha.d.ts +14 -0
  219. package/lib/beta.d.ts +2 -0
  220. package/lib/core/index.d.ts +2 -2
  221. package/lib/core/index.d.ts.map +1 -1
  222. package/lib/core/index.js +2 -2
  223. package/lib/core/index.js.map +1 -1
  224. package/lib/core/rebase/index.d.ts +2 -2
  225. package/lib/core/rebase/index.d.ts.map +1 -1
  226. package/lib/core/rebase/index.js +2 -2
  227. package/lib/core/rebase/index.js.map +1 -1
  228. package/lib/core/rebase/types.d.ts +5 -4
  229. package/lib/core/rebase/types.d.ts.map +1 -1
  230. package/lib/core/rebase/types.js +26 -1
  231. package/lib/core/rebase/types.js.map +1 -1
  232. package/lib/core/rebase/utils.d.ts +10 -0
  233. package/lib/core/rebase/utils.d.ts.map +1 -1
  234. package/lib/core/rebase/utils.js +20 -0
  235. package/lib/core/rebase/utils.js.map +1 -1
  236. package/lib/core/tree/delta.d.ts +21 -26
  237. package/lib/core/tree/delta.d.ts.map +1 -1
  238. package/lib/core/tree/delta.js.map +1 -1
  239. package/lib/core/tree/deltaUtil.d.ts +1 -3
  240. package/lib/core/tree/deltaUtil.d.ts.map +1 -1
  241. package/lib/core/tree/deltaUtil.js +1 -12
  242. package/lib/core/tree/deltaUtil.js.map +1 -1
  243. package/lib/core/tree/index.d.ts +1 -1
  244. package/lib/core/tree/index.d.ts.map +1 -1
  245. package/lib/core/tree/index.js +1 -1
  246. package/lib/core/tree/index.js.map +1 -1
  247. package/lib/core/tree/visitDelta.d.ts.map +1 -1
  248. package/lib/core/tree/visitDelta.js +82 -80
  249. package/lib/core/tree/visitDelta.js.map +1 -1
  250. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +10 -0
  251. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  252. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +3 -0
  253. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  254. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  255. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  256. package/lib/feature-libraries/deltaUtils.d.ts.map +1 -1
  257. package/lib/feature-libraries/deltaUtils.js +13 -0
  258. package/lib/feature-libraries/deltaUtils.js.map +1 -1
  259. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  260. package/lib/feature-libraries/forest-summary/forestSummarizer.js +1 -6
  261. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  262. package/lib/feature-libraries/index.d.ts +0 -1
  263. package/lib/feature-libraries/index.d.ts.map +1 -1
  264. package/lib/feature-libraries/index.js +0 -1
  265. package/lib/feature-libraries/index.js.map +1 -1
  266. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +5 -5
  267. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  268. package/lib/feature-libraries/modular-schema/crossFieldQueries.js +2 -3
  269. package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  270. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +30 -6
  271. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  272. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  273. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  274. package/lib/feature-libraries/modular-schema/genericFieldKind.js +2 -1
  275. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  276. package/lib/feature-libraries/modular-schema/index.d.ts +2 -2
  277. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  278. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  279. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts +1 -1
  280. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  281. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +4 -4
  282. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  283. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +5 -4
  284. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  285. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +158 -186
  286. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  287. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +23 -20
  288. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  289. package/lib/feature-libraries/modular-schema/modularChangeTypes.js +18 -1
  290. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  291. package/lib/feature-libraries/optional-field/optionalField.d.ts +3 -3
  292. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  293. package/lib/feature-libraries/optional-field/optionalField.js +24 -4
  294. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  295. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts +1 -1
  296. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  297. package/lib/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  298. package/lib/feature-libraries/sequence-field/rebase.js +4 -4
  299. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  300. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js +1 -1
  301. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV1.js.map +1 -1
  302. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +1 -1
  303. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  304. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  305. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  306. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  307. package/lib/feature-libraries/sequence-field/utils.d.ts +2 -2
  308. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  309. package/lib/feature-libraries/sequence-field/utils.js +50 -9
  310. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  311. package/lib/feature-libraries/treeCursorUtils.d.ts.map +1 -1
  312. package/lib/feature-libraries/treeCursorUtils.js +4 -1
  313. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  314. package/lib/index.d.ts +27 -3
  315. package/lib/index.d.ts.map +1 -1
  316. package/lib/index.js +2 -2
  317. package/lib/index.js.map +1 -1
  318. package/lib/legacy.d.ts +2 -0
  319. package/lib/packageVersion.d.ts +1 -1
  320. package/lib/packageVersion.js +1 -1
  321. package/lib/packageVersion.js.map +1 -1
  322. package/lib/public.d.ts +2 -0
  323. package/lib/shared-tree/index.d.ts +3 -2
  324. package/lib/shared-tree/index.d.ts.map +1 -1
  325. package/lib/shared-tree/index.js +3 -2
  326. package/lib/shared-tree/index.js.map +1 -1
  327. package/lib/shared-tree/schematizingTreeView.d.ts +10 -1
  328. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  329. package/lib/shared-tree/schematizingTreeView.js +46 -3
  330. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  331. package/lib/shared-tree/sharedTree.d.ts +44 -21
  332. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  333. package/lib/shared-tree/sharedTree.js +40 -34
  334. package/lib/shared-tree/sharedTree.js.map +1 -1
  335. package/lib/shared-tree/transactionTypes.d.ts +105 -0
  336. package/lib/shared-tree/transactionTypes.d.ts.map +1 -0
  337. package/lib/shared-tree/transactionTypes.js +10 -0
  338. package/lib/shared-tree/transactionTypes.js.map +1 -0
  339. package/lib/shared-tree/treeApi.d.ts +1 -25
  340. package/lib/shared-tree/treeApi.d.ts.map +1 -1
  341. package/lib/shared-tree/treeApi.js +1 -5
  342. package/lib/shared-tree/treeApi.js.map +1 -1
  343. package/lib/shared-tree/treeCheckout.d.ts +4 -1
  344. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  345. package/lib/shared-tree/treeCheckout.js +143 -24
  346. package/lib/shared-tree/treeCheckout.js.map +1 -1
  347. package/lib/shared-tree-core/sharedTreeCore.js +1 -1
  348. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  349. package/lib/simple-tree/api/index.d.ts +1 -0
  350. package/lib/simple-tree/api/index.d.ts.map +1 -1
  351. package/lib/simple-tree/api/index.js +1 -0
  352. package/lib/simple-tree/api/index.js.map +1 -1
  353. package/lib/simple-tree/api/jsonSchema.d.ts +6 -0
  354. package/lib/simple-tree/api/jsonSchema.d.ts.map +1 -1
  355. package/lib/simple-tree/api/jsonSchema.js.map +1 -1
  356. package/lib/simple-tree/api/schemaFactory.d.ts +21 -12
  357. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  358. package/lib/simple-tree/api/schemaFactory.js +5 -2
  359. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  360. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +83 -0
  361. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -0
  362. package/lib/simple-tree/api/schemaFactoryAlpha.js +86 -0
  363. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -0
  364. package/lib/simple-tree/api/simpleSchema.d.ts +5 -1
  365. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
  366. package/lib/simple-tree/api/simpleSchema.js.map +1 -1
  367. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +14 -11
  368. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  369. package/lib/simple-tree/api/testRecursiveDomain.d.ts +5 -5
  370. package/lib/simple-tree/api/tree.d.ts +60 -0
  371. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  372. package/lib/simple-tree/api/tree.js.map +1 -1
  373. package/lib/simple-tree/api/treeNodeApi.js +1 -1
  374. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  375. package/lib/simple-tree/api/viewSchemaToSimpleSchema.d.ts.map +1 -1
  376. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js +12 -12
  377. package/lib/simple-tree/api/viewSchemaToSimpleSchema.js.map +1 -1
  378. package/lib/simple-tree/arrayNode.d.ts +2 -2
  379. package/lib/simple-tree/arrayNode.d.ts.map +1 -1
  380. package/lib/simple-tree/arrayNode.js +3 -2
  381. package/lib/simple-tree/arrayNode.js.map +1 -1
  382. package/lib/simple-tree/core/treeNodeSchema.d.ts +10 -6
  383. package/lib/simple-tree/core/treeNodeSchema.d.ts.map +1 -1
  384. package/lib/simple-tree/core/treeNodeSchema.js.map +1 -1
  385. package/lib/simple-tree/index.d.ts +2 -2
  386. package/lib/simple-tree/index.d.ts.map +1 -1
  387. package/lib/simple-tree/index.js +1 -1
  388. package/lib/simple-tree/index.js.map +1 -1
  389. package/lib/simple-tree/leafNodeSchema.d.ts +5 -5
  390. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  391. package/lib/simple-tree/mapNode.d.ts +2 -2
  392. package/lib/simple-tree/mapNode.d.ts.map +1 -1
  393. package/lib/simple-tree/mapNode.js +2 -1
  394. package/lib/simple-tree/mapNode.js.map +1 -1
  395. package/lib/simple-tree/objectNode.d.ts +2 -2
  396. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  397. package/lib/simple-tree/objectNode.js +2 -1
  398. package/lib/simple-tree/objectNode.js.map +1 -1
  399. package/lib/simple-tree/objectNodeTypes.d.ts +2 -2
  400. package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
  401. package/lib/simple-tree/objectNodeTypes.js.map +1 -1
  402. package/lib/simple-tree/schemaTypes.d.ts +47 -1
  403. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  404. package/lib/simple-tree/schemaTypes.js.map +1 -1
  405. package/lib/simple-tree/toMapTree.js +1 -1
  406. package/lib/simple-tree/toMapTree.js.map +1 -1
  407. package/lib/util/bTreeUtils.d.ts +10 -0
  408. package/lib/util/bTreeUtils.d.ts.map +1 -0
  409. package/lib/util/bTreeUtils.js +47 -0
  410. package/lib/util/bTreeUtils.js.map +1 -0
  411. package/lib/util/idAllocator.d.ts +0 -2
  412. package/lib/util/idAllocator.d.ts.map +1 -1
  413. package/lib/util/idAllocator.js +0 -2
  414. package/lib/util/idAllocator.js.map +1 -1
  415. package/lib/util/index.d.ts +3 -2
  416. package/lib/util/index.d.ts.map +1 -1
  417. package/lib/util/index.js +3 -2
  418. package/lib/util/index.js.map +1 -1
  419. package/lib/util/rangeMap.d.ts +95 -43
  420. package/lib/util/rangeMap.d.ts.map +1 -1
  421. package/lib/util/rangeMap.js +200 -144
  422. package/lib/util/rangeMap.js.map +1 -1
  423. package/lib/util/utils.d.ts +26 -2
  424. package/lib/util/utils.d.ts.map +1 -1
  425. package/lib/util/utils.js +15 -1
  426. package/lib/util/utils.js.map +1 -1
  427. package/package.json +24 -24
  428. package/src/core/index.ts +5 -2
  429. package/src/core/rebase/index.ts +5 -0
  430. package/src/core/rebase/types.ts +33 -5
  431. package/src/core/rebase/utils.ts +27 -0
  432. package/src/core/tree/delta.ts +21 -26
  433. package/src/core/tree/deltaUtil.ts +1 -16
  434. package/src/core/tree/index.ts +0 -2
  435. package/src/core/tree/visitDelta.ts +108 -97
  436. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +14 -1
  437. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +2 -2
  438. package/src/feature-libraries/deltaUtils.ts +13 -0
  439. package/src/feature-libraries/forest-summary/forestSummarizer.ts +1 -6
  440. package/src/feature-libraries/index.ts +0 -1
  441. package/src/feature-libraries/modular-schema/crossFieldQueries.ts +12 -13
  442. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +33 -9
  443. package/src/feature-libraries/modular-schema/genericFieldKind.ts +6 -4
  444. package/src/feature-libraries/modular-schema/index.ts +3 -0
  445. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +12 -11
  446. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +254 -248
  447. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +51 -26
  448. package/src/feature-libraries/optional-field/optionalField.ts +37 -8
  449. package/src/feature-libraries/sequence-field/moveEffectTable.ts +1 -1
  450. package/src/feature-libraries/sequence-field/rebase.ts +9 -3
  451. package/src/feature-libraries/sequence-field/sequenceFieldCodecV1.ts +1 -1
  452. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +1 -1
  453. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +3 -4
  454. package/src/feature-libraries/sequence-field/utils.ts +54 -11
  455. package/src/feature-libraries/treeCursorUtils.ts +6 -1
  456. package/src/index.ts +45 -6
  457. package/src/packageVersion.ts +1 -1
  458. package/src/shared-tree/index.ts +16 -3
  459. package/src/shared-tree/schematizingTreeView.ts +91 -2
  460. package/src/shared-tree/sharedTree.ts +69 -44
  461. package/src/shared-tree/transactionTypes.ts +125 -0
  462. package/src/shared-tree/treeApi.ts +1 -28
  463. package/src/shared-tree/treeCheckout.ts +166 -25
  464. package/src/shared-tree-core/sharedTreeCore.ts +1 -1
  465. package/src/simple-tree/api/index.ts +1 -0
  466. package/src/simple-tree/api/jsonSchema.ts +7 -0
  467. package/src/simple-tree/api/schemaFactory.ts +33 -6
  468. package/src/simple-tree/api/schemaFactoryAlpha.ts +253 -0
  469. package/src/simple-tree/api/simpleSchema.ts +6 -1
  470. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +22 -12
  471. package/src/simple-tree/api/tree.ts +76 -4
  472. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  473. package/src/simple-tree/api/viewSchemaToSimpleSchema.ts +19 -13
  474. package/src/simple-tree/arrayNode.ts +8 -2
  475. package/src/simple-tree/core/treeNodeSchema.ts +51 -7
  476. package/src/simple-tree/index.ts +3 -0
  477. package/src/simple-tree/mapNode.ts +7 -1
  478. package/src/simple-tree/objectNode.ts +7 -1
  479. package/src/simple-tree/objectNodeTypes.ts +4 -1
  480. package/src/simple-tree/schemaTypes.ts +50 -1
  481. package/src/simple-tree/toMapTree.ts +1 -1
  482. package/src/util/bTreeUtils.ts +60 -0
  483. package/src/util/idAllocator.ts +0 -2
  484. package/src/util/index.ts +5 -6
  485. package/src/util/rangeMap.ts +259 -184
  486. package/src/util/utils.ts +57 -4
  487. package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
  488. package/dist/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
  489. package/dist/feature-libraries/memoizedIdRangeAllocator.js +0 -74
  490. package/dist/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
  491. package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts +0 -38
  492. package/lib/feature-libraries/memoizedIdRangeAllocator.d.ts.map +0 -1
  493. package/lib/feature-libraries/memoizedIdRangeAllocator.js +0 -71
  494. package/lib/feature-libraries/memoizedIdRangeAllocator.js.map +0 -1
  495. package/lib/package.json +0 -3
  496. package/src/feature-libraries/memoizedIdRangeAllocator.ts +0 -112
@@ -4,18 +4,18 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.newTupleBTree = exports.newCrossFieldKeyTable = exports.getFieldsForCrossFieldKey = exports.getParentFieldId = exports.ModularEditBuilder = exports.getChangeHandler = exports.getFieldKind = exports.rebaseRevisionMetadataFromInfo = exports.intoDelta = exports.updateRefreshers = exports.relevantRemovedRoots = exports.ModularChangeFamily = void 0;
7
+ exports.normalizeFieldId = exports.getParentFieldId = exports.ModularEditBuilder = exports.getChangeHandler = exports.getFieldKind = exports.rebaseRevisionMetadataFromInfo = exports.intoDelta = exports.updateRefreshers = exports.relevantRemovedRoots = exports.ModularChangeFamily = void 0;
8
8
  const internal_1 = require("@fluidframework/core-utils/internal");
9
9
  const sorted_btree_es6_1 = require("@tylerbu/sorted-btree-es6");
10
10
  const index_js_1 = require("../../core/index.js");
11
11
  const index_js_2 = require("../../util/index.js");
12
12
  const index_js_3 = require("../chunked-forest/index.js");
13
13
  const mapTreeCursor_js_1 = require("../mapTreeCursor.js");
14
- const memoizedIdRangeAllocator_js_1 = require("../memoizedIdRangeAllocator.js");
15
14
  const crossFieldQueries_js_1 = require("./crossFieldQueries.js");
16
15
  const fieldChangeHandler_js_1 = require("./fieldChangeHandler.js");
17
16
  const fieldKindWithEditor_js_1 = require("./fieldKindWithEditor.js");
18
17
  const genericFieldKind_js_1 = require("./genericFieldKind.js");
18
+ const modularChangeTypes_js_1 = require("./modularChangeTypes.js");
19
19
  /**
20
20
  * Implementation of ChangeFamily which delegates work in a given field to the appropriate FieldKind
21
21
  * as determined by the schema.
@@ -102,10 +102,10 @@ class ModularChangeFamily {
102
102
  if (hasConflicts(change1) && hasConflicts(change2)) {
103
103
  return {
104
104
  fieldChanges: new Map(),
105
- nodeChanges: newTupleBTree(),
106
- nodeToParent: newTupleBTree(),
107
- nodeAliases: newTupleBTree(),
108
- crossFieldKeys: newTupleBTree(),
105
+ nodeChanges: (0, index_js_2.newTupleBTree)(),
106
+ nodeToParent: (0, index_js_2.newTupleBTree)(),
107
+ nodeAliases: (0, index_js_2.newTupleBTree)(),
108
+ crossFieldKeys: (0, modularChangeTypes_js_1.newCrossFieldKeyTable)(),
109
109
  };
110
110
  }
111
111
  else if (hasConflicts(change1)) {
@@ -124,20 +124,20 @@ class ModularChangeFamily {
124
124
  // A collision for a node ID means that that node is referenced in both changesets
125
125
  // (since we assume that if two changesets use the same node ID they are referring to the same node),
126
126
  // therefore all collisions will be addressed when processing the intersection of the changesets.
127
- const composedNodeChanges = (0, index_js_2.brand)(mergeBTrees(change1.nodeChanges, change2.nodeChanges));
128
- const composedNodeToParent = (0, index_js_2.brand)(mergeBTrees(change1.nodeToParent, change2.nodeToParent));
129
- const composedNodeAliases = (0, index_js_2.brand)(mergeBTrees(change1.nodeAliases, change2.nodeAliases));
127
+ const composedNodeChanges = (0, index_js_2.brand)((0, index_js_2.mergeTupleBTrees)(change1.nodeChanges, change2.nodeChanges));
128
+ const composedNodeToParent = (0, index_js_2.brand)((0, index_js_2.mergeTupleBTrees)(change1.nodeToParent, change2.nodeToParent));
129
+ const composedNodeAliases = (0, index_js_2.brand)((0, index_js_2.mergeTupleBTrees)(change1.nodeAliases, change2.nodeAliases));
130
130
  const crossFieldTable = newComposeTable(change1, change2, composedNodeToParent);
131
131
  const composedFields = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, undefined, genId, crossFieldTable, revisionMetadata);
132
132
  this.composeInvalidatedElements(crossFieldTable, composedFields, composedNodeChanges, composedNodeToParent, composedNodeAliases, genId, revisionMetadata);
133
133
  // Currently no field kinds require making changes to cross-field keys during composition, so we can just merge the two tables.
134
- const composedCrossFieldKeys = mergeBTrees(change1.crossFieldKeys, change2.crossFieldKeys);
134
+ const composedCrossFieldKeys = index_js_2.RangeMap.union(change1.crossFieldKeys, change2.crossFieldKeys);
135
135
  return {
136
136
  fieldChanges: composedFields,
137
137
  nodeChanges: composedNodeChanges,
138
138
  nodeToParent: composedNodeToParent,
139
139
  nodeAliases: composedNodeAliases,
140
- crossFieldKeys: (0, index_js_2.brand)(composedCrossFieldKeys),
140
+ crossFieldKeys: composedCrossFieldKeys,
141
141
  };
142
142
  }
143
143
  composeInvalidatedField(fieldChange, crossFieldTable, genId, revisionMetadata) {
@@ -303,7 +303,18 @@ class ModularChangeFamily {
303
303
  crossFieldTable.composedNodes.add(composedNodeChangeset);
304
304
  }
305
305
  composeNodeChanges(nodeId, change1, change2, genId, crossFieldTable, revisionMetadata) {
306
+ // WARNING: this composition logic assumes that we never make compositions of the following form:
307
+ // change1: a changeset that impact the existence of a node
308
+ // change2: a node-exists constraint on that node.
309
+ // This is currently enforced by the fact that constraints which apply to the input context are included first in the composition.
310
+ // If that weren't the case, we would need to rebase the status of the constraint backward over the changes from change1.
306
311
  const nodeExistsConstraint = change1.nodeExistsConstraint ?? change2.nodeExistsConstraint;
312
+ // WARNING: this composition logic assumes that we never make compositions of the following form:
313
+ // change1: a node-exists-on-revert constraint on a node
314
+ // change2: a changeset that impacts the existence of that node
315
+ // This is currently enforced by the fact that constraints which apply to the revert are included last in the composition.
316
+ // If that weren't the case, we would need to rebase the status of the constraint forward over the changes from change2.
317
+ const nodeExistsConstraintOnRevert = change1.nodeExistsConstraintOnRevert ?? change2.nodeExistsConstraintOnRevert;
307
318
  const composedFieldChanges = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, nodeId, genId, crossFieldTable, revisionMetadata);
308
319
  const composedNodeChange = {};
309
320
  if (composedFieldChanges.size > 0) {
@@ -312,6 +323,9 @@ class ModularChangeFamily {
312
323
  if (nodeExistsConstraint !== undefined) {
313
324
  composedNodeChange.nodeExistsConstraint = nodeExistsConstraint;
314
325
  }
326
+ if (nodeExistsConstraintOnRevert !== undefined) {
327
+ composedNodeChange.nodeExistsConstraintOnRevert = nodeExistsConstraintOnRevert;
328
+ }
315
329
  return composedNodeChange;
316
330
  }
317
331
  /**
@@ -344,7 +358,7 @@ class ModularChangeFamily {
344
358
  const { revInfos: oldRevInfos } = getRevInfoFromTaggedChanges([change]);
345
359
  const revisionMetadata = (0, index_js_1.revisionMetadataSourceFromInfo)(oldRevInfos);
346
360
  const invertedFields = this.invertFieldMap(change.change.fieldChanges, undefined, isRollback, genId, crossFieldTable, revisionMetadata, revisionForInvert);
347
- const invertedNodes = newTupleBTree();
361
+ const invertedNodes = (0, index_js_2.newTupleBTree)();
348
362
  change.change.nodeChanges.forEachPair(([revision, localId], nodeChangeset) => {
349
363
  invertedNodes.set([revision, localId], this.invertNodeChange(nodeChangeset, { revision, localId }, isRollback, genId, crossFieldTable, revisionMetadata, revisionForInvert));
350
364
  });
@@ -369,7 +383,8 @@ class ModularChangeFamily {
369
383
  crossFieldKeys,
370
384
  maxId: genId.getMaxId(),
371
385
  revisions: revInfos,
372
- constraintViolationCount: change.change.constraintViolationCount,
386
+ constraintViolationCount: change.change.constraintViolationCountOnRevert,
387
+ constraintViolationCountOnRevert: change.change.constraintViolationCount,
373
388
  destroys,
374
389
  });
375
390
  }
@@ -393,6 +408,17 @@ class ModularChangeFamily {
393
408
  }
394
409
  invertNodeChange(change, id, isRollback, genId, crossFieldTable, revisionMetadata, revisionForInvert) {
395
410
  const inverse = {};
411
+ // If the node has a constraint, it should be inverted to a node-exist-on-revert constraint. This ensure that if
412
+ // the inverse is inverted again, the original input constraint will be restored.
413
+ if (change.nodeExistsConstraint !== undefined) {
414
+ inverse.nodeExistsConstraintOnRevert = change.nodeExistsConstraint;
415
+ }
416
+ // The node-exist-on-revert constraint of a node is the constraint that should apply when the a change is reverted.
417
+ // So, it should become the constraint in the inverse. If this constraint is violated when applying the inverse,
418
+ // it will be discarded.
419
+ if (change.nodeExistsConstraintOnRevert !== undefined) {
420
+ inverse.nodeExistsConstraint = change.nodeExistsConstraintOnRevert;
421
+ }
396
422
  if (change.fieldChanges !== undefined) {
397
423
  inverse.fieldChanges = this.invertFieldMap(change.fieldChanges, id, isRollback, genId, crossFieldTable, revisionMetadata, revisionForInvert);
398
424
  }
@@ -411,15 +437,14 @@ class ModularChangeFamily {
411
437
  newChange: change,
412
438
  baseChange: over.change,
413
439
  baseFieldToContext: new Map(),
414
- baseToRebasedNodeId: newTupleBTree(),
440
+ baseToRebasedNodeId: (0, index_js_2.newTupleBTree)(),
415
441
  rebasedFields: new Set(),
416
442
  rebasedNodeToParent: (0, index_js_2.brand)(change.nodeToParent.clone()),
417
- rebasedCrossFieldKeys: (0, index_js_2.brand)(change.crossFieldKeys.clone()),
443
+ rebasedCrossFieldKeys: change.crossFieldKeys.clone(),
418
444
  nodeIdPairs: [],
419
- affectedBaseFields: newTupleBTree(),
445
+ affectedBaseFields: (0, index_js_2.newTupleBTree)(),
420
446
  fieldsWithUnattachedChild: new Set(),
421
447
  };
422
- const constraintState = newConstraintState(change.constraintViolationCount ?? 0);
423
448
  const getBaseRevisions = () => revisionInfoFromTaggedChange(over).map((info) => info.revision);
424
449
  const rebaseMetadata = {
425
450
  ...revisionMetadata,
@@ -427,9 +452,11 @@ class ModularChangeFamily {
427
452
  getBaseRevisions,
428
453
  };
429
454
  const rebasedNodes = (0, index_js_2.brand)(change.nodeChanges.clone());
430
- const rebasedFields = this.rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, constraintState, rebaseMetadata);
455
+ const rebasedFields = this.rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, rebaseMetadata);
431
456
  this.rebaseInvalidatedElements(rebasedFields, rebasedNodes, crossFieldTable, rebaseMetadata, genId);
432
- this.updateConstraintsForFields(rebasedFields, fieldChangeHandler_js_1.NodeAttachState.Attached, constraintState, rebasedNodes);
457
+ const constraintState = newConstraintState(change.constraintViolationCount ?? 0);
458
+ const revertConstraintState = newConstraintState(change.constraintViolationCountOnRevert ?? 0);
459
+ this.updateConstraintsForFields(rebasedFields, fieldChangeHandler_js_1.NodeAttachState.Attached, fieldChangeHandler_js_1.NodeAttachState.Attached, constraintState, revertConstraintState, rebasedNodes);
433
460
  const rebased = makeModularChangeset({
434
461
  fieldChanges: this.pruneFieldMap(rebasedFields, rebasedNodes),
435
462
  nodeChanges: rebasedNodes,
@@ -439,6 +466,7 @@ class ModularChangeFamily {
439
466
  maxId: idState.maxId,
440
467
  revisions: change.revisions,
441
468
  constraintViolationCount: constraintState.violationCount,
469
+ constraintViolationCountOnRevert: revertConstraintState.violationCount,
442
470
  builds: change.builds,
443
471
  destroys: change.destroys,
444
472
  refreshers: change.refreshers,
@@ -447,14 +475,14 @@ class ModularChangeFamily {
447
475
  }
448
476
  // This performs a first pass on all fields which have both new and base changes.
449
477
  // TODO: Can we also handle additional passes in this method?
450
- rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, constraintState, metadata) {
478
+ rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, metadata) {
451
479
  const change = crossFieldTable.newChange;
452
480
  const baseChange = crossFieldTable.baseChange;
453
481
  const rebasedFields = this.rebaseFieldMap(change.fieldChanges, baseChange.fieldChanges, undefined, genId, crossFieldTable, metadata);
454
482
  // This loop processes all fields which have both base and new changes.
455
483
  // Note that the call to `rebaseNodeChange` can add entries to `crossFieldTable.nodeIdPairs`.
456
484
  for (const [newId, baseId, _attachState] of crossFieldTable.nodeIdPairs) {
457
- const rebasedNode = this.rebaseNodeChange(newId, baseId, genId, crossFieldTable, metadata, constraintState);
485
+ const rebasedNode = this.rebaseNodeChange(newId, baseId, genId, crossFieldTable, metadata);
458
486
  setInChangeAtomIdMap(rebasedNodes, newId, rebasedNode);
459
487
  }
460
488
  return rebasedFields;
@@ -629,7 +657,7 @@ class ModularChangeFamily {
629
657
  }
630
658
  return rebasedFields;
631
659
  }
632
- rebaseNodeChange(newId, baseId, genId, crossFieldTable, revisionMetadata, constraintState) {
660
+ rebaseNodeChange(newId, baseId, genId, crossFieldTable, revisionMetadata) {
633
661
  const change = nodeChangeFromId(crossFieldTable.newChange.nodeChanges, newId);
634
662
  const over = nodeChangeFromId(crossFieldTable.baseChange.nodeChanges, baseId);
635
663
  const baseMap = over?.fieldChanges ?? new Map();
@@ -643,25 +671,32 @@ class ModularChangeFamily {
643
671
  if (change?.nodeExistsConstraint !== undefined) {
644
672
  rebasedChange.nodeExistsConstraint = change.nodeExistsConstraint;
645
673
  }
674
+ if (change?.nodeExistsConstraintOnRevert !== undefined) {
675
+ rebasedChange.nodeExistsConstraintOnRevert = change.nodeExistsConstraintOnRevert;
676
+ }
646
677
  setInChangeAtomIdMap(crossFieldTable.baseToRebasedNodeId, baseId, newId);
647
678
  return rebasedChange;
648
679
  }
649
- updateConstraintsForFields(fields, parentAttachState, constraintState, nodes) {
680
+ updateConstraintsForFields(fields, parentInputAttachState, parentOutputAttachState, constraintState, revertConstraintState, nodes) {
650
681
  for (const field of fields.values()) {
651
682
  const handler = getChangeHandler(this.fieldKinds, field.fieldKind);
652
- for (const [nodeId, index] of handler.getNestedChanges(field.change)) {
653
- const isDetached = index === undefined;
654
- const attachState = parentAttachState === fieldChangeHandler_js_1.NodeAttachState.Detached || isDetached
683
+ for (const [nodeId, inputIndex, outputIndex] of handler.getNestedChanges(field.change)) {
684
+ const isInputDetached = inputIndex === undefined;
685
+ const inputAttachState = parentInputAttachState === fieldChangeHandler_js_1.NodeAttachState.Detached || isInputDetached
655
686
  ? fieldChangeHandler_js_1.NodeAttachState.Detached
656
687
  : fieldChangeHandler_js_1.NodeAttachState.Attached;
657
- this.updateConstraintsForNode(nodeId, attachState, constraintState, nodes);
688
+ const isOutputDetached = outputIndex === undefined;
689
+ const outputAttachState = parentOutputAttachState === fieldChangeHandler_js_1.NodeAttachState.Detached || isOutputDetached
690
+ ? fieldChangeHandler_js_1.NodeAttachState.Detached
691
+ : fieldChangeHandler_js_1.NodeAttachState.Attached;
692
+ this.updateConstraintsForNode(nodeId, inputAttachState, outputAttachState, nodes, constraintState, revertConstraintState);
658
693
  }
659
694
  }
660
695
  }
661
- updateConstraintsForNode(nodeId, attachState, constraintState, nodes) {
696
+ updateConstraintsForNode(nodeId, inputAttachState, outputAttachState, nodes, constraintState, revertConstraintState) {
662
697
  const node = nodes.get([nodeId.revision, nodeId.localId]) ?? (0, index_js_2.fail)("Unknown node ID");
663
698
  if (node.nodeExistsConstraint !== undefined) {
664
- const isNowViolated = attachState === fieldChangeHandler_js_1.NodeAttachState.Detached;
699
+ const isNowViolated = inputAttachState === fieldChangeHandler_js_1.NodeAttachState.Detached;
665
700
  if (node.nodeExistsConstraint.violated !== isNowViolated) {
666
701
  node.nodeExistsConstraint = {
667
702
  ...node.nodeExistsConstraint,
@@ -670,8 +705,18 @@ class ModularChangeFamily {
670
705
  constraintState.violationCount += isNowViolated ? 1 : -1;
671
706
  }
672
707
  }
708
+ if (node.nodeExistsConstraintOnRevert !== undefined) {
709
+ const isNowViolated = outputAttachState === fieldChangeHandler_js_1.NodeAttachState.Detached;
710
+ if (node.nodeExistsConstraintOnRevert.violated !== isNowViolated) {
711
+ node.nodeExistsConstraintOnRevert = {
712
+ ...node.nodeExistsConstraintOnRevert,
713
+ violated: isNowViolated,
714
+ };
715
+ revertConstraintState.violationCount += isNowViolated ? 1 : -1;
716
+ }
717
+ }
673
718
  if (node.fieldChanges !== undefined) {
674
- this.updateConstraintsForFields(node.fieldChanges, attachState, constraintState, nodes);
719
+ this.updateConstraintsForFields(node.fieldChanges, inputAttachState, outputAttachState, constraintState, revertConstraintState, nodes);
675
720
  }
676
721
  }
677
722
  pruneFieldMap(changeset, nodeMap) {
@@ -711,11 +756,11 @@ class ModularChangeFamily {
711
756
  ? [undefined]
712
757
  : change.revisions.map((revInfo) => revInfo.revision));
713
758
  const updatedFields = this.replaceFieldMapRevisions(change.fieldChanges, oldRevisions, newRevision);
714
- const updatedNodes = newTupleBTree();
759
+ const updatedNodes = (0, index_js_2.newTupleBTree)();
715
760
  for (const [[revision, id], nodeChangeset] of change.nodeChanges.entries()) {
716
761
  updatedNodes.set([replaceRevision(revision, oldRevisions, newRevision), id], this.replaceNodeChangesetRevisions(nodeChangeset, oldRevisions, newRevision));
717
762
  }
718
- const updatedNodeToParent = newTupleBTree();
763
+ const updatedNodeToParent = (0, index_js_2.newTupleBTree)();
719
764
  for (const [[revision, id], fieldId] of change.nodeToParent.entries()) {
720
765
  updatedNodeToParent.set([replaceRevision(revision, oldRevisions, newRevision), id], replaceFieldIdRevision(normalizeFieldId(fieldId, change.nodeAliases), oldRevisions, newRevision));
721
766
  }
@@ -725,7 +770,7 @@ class ModularChangeFamily {
725
770
  nodeChanges: updatedNodes,
726
771
  nodeToParent: updatedNodeToParent,
727
772
  // We've updated all references to old node IDs, so we no longer need an alias table.
728
- nodeAliases: newTupleBTree(),
773
+ nodeAliases: (0, index_js_2.newTupleBTree)(),
729
774
  crossFieldKeys: replaceCrossFieldKeyTableRevisions(change.crossFieldKeys, oldRevisions, newRevision, change.nodeAliases),
730
775
  };
731
776
  if (change.builds !== undefined) {
@@ -765,7 +810,7 @@ class ModularChangeFamily {
765
810
  return updatedFields;
766
811
  }
767
812
  makeCrossFieldKeyTable(fields, nodes) {
768
- const keys = newCrossFieldKeyTable();
813
+ const keys = (0, modularChangeTypes_js_1.newCrossFieldKeyTable)();
769
814
  this.populateCrossFieldKeyTableForFieldMap(keys, fields, undefined);
770
815
  nodes.forEachPair(([revision, localId], node) => {
771
816
  if (node.fieldChanges !== undefined) {
@@ -780,8 +825,8 @@ class ModularChangeFamily {
780
825
  populateCrossFieldKeyTableForFieldMap(table, fields, parent) {
781
826
  for (const [fieldKey, fieldChange] of fields) {
782
827
  const keys = getChangeHandler(this.fieldKinds, fieldChange.fieldKind).getCrossFieldKeys(fieldChange.change);
783
- for (const key of keys) {
784
- table.set(key, { nodeId: parent, field: fieldKey });
828
+ for (const { key, count } of keys) {
829
+ table.set(key, count, { nodeId: parent, field: fieldKey });
785
830
  }
786
831
  }
787
832
  }
@@ -820,7 +865,7 @@ class ModularChangeFamily {
820
865
  numChildren += 1;
821
866
  }
822
867
  for (const keyRange of handler.getCrossFieldKeys(fieldChange.change)) {
823
- const fields = getFieldsForCrossFieldKey(change, keyRange);
868
+ const fields = getFieldsForCrossFieldKey(change, keyRange.key, keyRange.count);
824
869
  (0, internal_1.assert)(fields.length === 1 &&
825
870
  fields[0] !== undefined &&
826
871
  areEqualFieldIds(fields[0], fieldId), 0xa4f /* Inconsistent cross field keys */);
@@ -832,14 +877,15 @@ class ModularChangeFamily {
832
877
  exports.ModularChangeFamily = ModularChangeFamily;
833
878
  ModularChangeFamily.emptyChange = makeModularChangeset();
834
879
  function replaceCrossFieldKeyTableRevisions(table, oldRevisions, newRevision, nodeAliases) {
835
- const updated = newTupleBTree();
836
- table.forEachPair(([target, revision, id, count], field) => {
837
- const updatedKey = [
838
- target,
839
- replaceRevision(revision, oldRevisions, newRevision),
840
- id,
841
- count,
842
- ];
880
+ const updated = (0, modularChangeTypes_js_1.newCrossFieldKeyTable)();
881
+ for (const entry of table.entries()) {
882
+ const key = entry.start;
883
+ const updatedKey = {
884
+ target: key.target,
885
+ revision: replaceRevision(key.revision, oldRevisions, newRevision),
886
+ localId: key.localId,
887
+ };
888
+ const field = entry.value;
843
889
  const normalizedFieldId = normalizeFieldId(field, nodeAliases);
844
890
  const updatedNodeId = normalizedFieldId.nodeId !== undefined
845
891
  ? (0, index_js_1.replaceAtomRevisions)(normalizedFieldId.nodeId, oldRevisions, newRevision)
@@ -848,15 +894,15 @@ function replaceCrossFieldKeyTableRevisions(table, oldRevisions, newRevision, no
848
894
  ...normalizedFieldId,
849
895
  nodeId: updatedNodeId,
850
896
  };
851
- updated.set(updatedKey, updatedValue);
852
- });
897
+ updated.set(updatedKey, entry.length, updatedValue);
898
+ }
853
899
  return updated;
854
900
  }
855
901
  function replaceRevision(revision, oldRevisions, newRevision) {
856
902
  return oldRevisions.has(revision) ? newRevision : revision;
857
903
  }
858
904
  function replaceIdMapRevisions(map, oldRevisions, newRevision) {
859
- const updated = newTupleBTree();
905
+ const updated = (0, index_js_2.newTupleBTree)();
860
906
  for (const [[revision, id], value] of map.entries()) {
861
907
  updated.set([replaceRevision(revision, oldRevisions, newRevision), id], value);
862
908
  }
@@ -873,9 +919,9 @@ function composeBuildsDestroysAndRefreshers(change1, change2) {
873
919
  // Note that it would in principle be possible to adopt the later build and exclude from the
874
920
  // composition all the changes already reflected on the tree, but that is not something we
875
921
  // care to support at this time.
876
- const allBuilds = (0, index_js_2.brand)(mergeBTrees(change1.builds ?? newTupleBTree(), change2.builds ?? newTupleBTree(), true));
877
- const allDestroys = (0, index_js_2.brand)(mergeBTrees(change1.destroys ?? newTupleBTree(), change2.destroys ?? newTupleBTree()));
878
- const allRefreshers = (0, index_js_2.brand)(mergeBTrees(change1.refreshers ?? newTupleBTree(), change2.refreshers ?? newTupleBTree(), true));
922
+ const allBuilds = (0, index_js_2.brand)((0, index_js_2.mergeTupleBTrees)(change1.builds ?? (0, index_js_2.newTupleBTree)(), change2.builds ?? (0, index_js_2.newTupleBTree)(), true));
923
+ const allDestroys = (0, index_js_2.brand)((0, index_js_2.mergeTupleBTrees)(change1.destroys ?? (0, index_js_2.newTupleBTree)(), change2.destroys ?? (0, index_js_2.newTupleBTree)()));
924
+ const allRefreshers = (0, index_js_2.brand)((0, index_js_2.mergeTupleBTrees)(change1.refreshers ?? (0, index_js_2.newTupleBTree)(), change2.refreshers ?? (0, index_js_2.newTupleBTree)(), true));
879
925
  if (change1.destroys !== undefined && change2.builds !== undefined) {
880
926
  for (const [key, chunk] of change2.builds.entries()) {
881
927
  const destroyCount = change1.destroys.get(key);
@@ -947,7 +993,7 @@ function* relevantRemovedRootsFromFields(change, nodeChanges, fieldKinds) {
947
993
  * corresponding build or refresher.
948
994
  */
949
995
  function updateRefreshers(change, getDetachedNode, removedRoots, requireRefreshers = true) {
950
- const refreshers = newTupleBTree();
996
+ const refreshers = (0, index_js_2.newTupleBTree)();
951
997
  const chunkLengths = new Map();
952
998
  if (change.builds !== undefined) {
953
999
  for (const [[revision, id], chunk] of change.builds.entries()) {
@@ -978,7 +1024,7 @@ function updateRefreshers(change, getDetachedNode, removedRoots, requireRefreshe
978
1024
  refreshers.set([root.major, (0, index_js_2.brand)(root.minor)], node);
979
1025
  }
980
1026
  }
981
- const { fieldChanges, nodeChanges, maxId, revisions, constraintViolationCount, builds, destroys, } = change;
1027
+ const { fieldChanges, nodeChanges, maxId, revisions, constraintViolationCount, constraintViolationCountOnRevert, builds, destroys, } = change;
982
1028
  return makeModularChangeset({
983
1029
  fieldChanges,
984
1030
  nodeChanges,
@@ -988,6 +1034,7 @@ function updateRefreshers(change, getDetachedNode, removedRoots, requireRefreshe
988
1034
  maxId: maxId,
989
1035
  revisions,
990
1036
  constraintViolationCount,
1037
+ constraintViolationCountOnRevert,
991
1038
  builds,
992
1039
  destroys,
993
1040
  refreshers,
@@ -995,19 +1042,28 @@ function updateRefreshers(change, getDetachedNode, removedRoots, requireRefreshe
995
1042
  }
996
1043
  exports.updateRefreshers = updateRefreshers;
997
1044
  /**
1045
+ * Converts a change into the delta format.
1046
+ *
998
1047
  * @param change - The change to convert into a delta.
999
1048
  * @param fieldKinds - The field kinds to delegate to.
1000
1049
  */
1001
1050
  function intoDelta(taggedChange, fieldKinds) {
1002
1051
  const change = taggedChange.change;
1003
- const idAllocator = memoizedIdRangeAllocator_js_1.MemoizedIdRangeAllocator.fromNextId();
1004
1052
  const rootDelta = {};
1053
+ const global = [];
1054
+ const rename = [];
1005
1055
  if (!hasConflicts(change)) {
1006
1056
  // If there are no constraint violations, then tree changes apply.
1007
- const fieldDeltas = intoDeltaImpl(change.fieldChanges, change.nodeChanges, idAllocator, fieldKinds);
1057
+ const fieldDeltas = intoDeltaImpl(change.fieldChanges, change.nodeChanges, fieldKinds, global, rename);
1008
1058
  if (fieldDeltas.size > 0) {
1009
1059
  rootDelta.fields = fieldDeltas;
1010
1060
  }
1061
+ if (global.length > 0) {
1062
+ rootDelta.global = global;
1063
+ }
1064
+ if (rename.length > 0) {
1065
+ rootDelta.rename = rename;
1066
+ }
1011
1067
  }
1012
1068
  // Constraint violations should not prevent nodes from being built
1013
1069
  if (change.builds && change.builds.size > 0) {
@@ -1045,22 +1101,24 @@ function copyDetachedNodes(detachedNodes) {
1045
1101
  /**
1046
1102
  * @param change - The change to convert into a delta.
1047
1103
  */
1048
- function intoDeltaImpl(change, nodeChanges, idAllocator, fieldKinds) {
1104
+ function intoDeltaImpl(change, nodeChanges, fieldKinds, global, rename) {
1049
1105
  const delta = new Map();
1050
1106
  for (const [field, fieldChange] of change) {
1051
- const deltaField = getChangeHandler(fieldKinds, fieldChange.fieldKind).intoDelta(fieldChange.change, (childChange) => {
1107
+ const { local: fieldChanges, global: fieldGlobal, rename: fieldRename, } = getChangeHandler(fieldKinds, fieldChange.fieldKind).intoDelta(fieldChange.change, (childChange) => {
1052
1108
  const nodeChange = nodeChangeFromId(nodeChanges, childChange);
1053
- return deltaFromNodeChange(nodeChange, nodeChanges, idAllocator, fieldKinds);
1054
- }, idAllocator);
1055
- if (!(0, index_js_1.isEmptyFieldChanges)(deltaField)) {
1056
- delta.set(field, deltaField);
1109
+ return deltaFromNodeChange(nodeChange, nodeChanges, fieldKinds, global, rename);
1110
+ });
1111
+ if (fieldChanges !== undefined && fieldChanges.length > 0) {
1112
+ delta.set(field, fieldChanges);
1057
1113
  }
1114
+ fieldGlobal?.forEach((c) => global.push(c));
1115
+ fieldRename?.forEach((r) => rename.push(r));
1058
1116
  }
1059
1117
  return delta;
1060
1118
  }
1061
- function deltaFromNodeChange(change, nodeChanges, idAllocator, fieldKinds) {
1119
+ function deltaFromNodeChange(change, nodeChanges, fieldKinds, global, rename) {
1062
1120
  if (change.fieldChanges !== undefined) {
1063
- return intoDeltaImpl(change.fieldChanges, nodeChanges, idAllocator, fieldKinds);
1121
+ return intoDeltaImpl(change.fieldChanges, nodeChanges, fieldKinds, global, rename);
1064
1122
  }
1065
1123
  // TODO: update the API to allow undefined to be returned here
1066
1124
  return new Map();
@@ -1093,7 +1151,9 @@ function rebaseRevisionMetadataFromInfo(revInfos, revisionToRebase, baseRevision
1093
1151
  }
1094
1152
  exports.rebaseRevisionMetadataFromInfo = rebaseRevisionMetadataFromInfo;
1095
1153
  function isEmptyNodeChangeset(change) {
1096
- return change.fieldChanges === undefined && change.nodeExistsConstraint === undefined;
1154
+ return (change.fieldChanges === undefined &&
1155
+ change.nodeExistsConstraint === undefined &&
1156
+ change.nodeExistsConstraintOnRevert === undefined);
1097
1157
  }
1098
1158
  function getFieldKind(fieldKinds, kind) {
1099
1159
  if (kind === genericFieldKind_js_1.genericFieldKind.identifier) {
@@ -1115,22 +1175,22 @@ function newComposeTable(baseChange, newChange, composedNodeToParent) {
1115
1175
  newChange,
1116
1176
  fieldToContext: new Map(),
1117
1177
  newFieldToBaseField: new Map(),
1118
- newToBaseNodeId: newTupleBTree(),
1178
+ newToBaseNodeId: (0, index_js_2.newTupleBTree)(),
1119
1179
  composedNodes: new Set(),
1120
1180
  composedNodeToParent,
1121
1181
  pendingCompositions: {
1122
1182
  nodeIdsToCompose: [],
1123
- affectedBaseFields: newTupleBTree(),
1124
- affectedNewFields: newTupleBTree(),
1183
+ affectedBaseFields: (0, index_js_2.newTupleBTree)(),
1184
+ affectedNewFields: (0, index_js_2.newTupleBTree)(),
1125
1185
  },
1126
1186
  };
1127
1187
  }
1128
1188
  function newCrossFieldTable() {
1129
1189
  return {
1130
- srcTable: new Map(),
1131
- dstTable: new Map(),
1132
- srcDependents: new Map(),
1133
- dstDependents: new Map(),
1190
+ srcTable: (0, index_js_1.newChangeAtomIdRangeMap)(),
1191
+ dstTable: (0, index_js_1.newChangeAtomIdRangeMap)(),
1192
+ srcDependents: (0, index_js_1.newChangeAtomIdRangeMap)(),
1193
+ dstDependents: (0, index_js_1.newChangeAtomIdRangeMap)(),
1134
1194
  invalidatedFields: new Set(),
1135
1195
  };
1136
1196
  }
@@ -1201,19 +1261,17 @@ class RebaseManager extends CrossFieldManagerI {
1201
1261
  }
1202
1262
  set(target, revision, id, count, newValue, invalidateDependents) {
1203
1263
  if (invalidateDependents && this.allowInval) {
1204
- const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, [
1264
+ const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, {
1205
1265
  target,
1206
1266
  revision,
1207
- id,
1208
- count,
1209
- ]);
1267
+ localId: id,
1268
+ }, count);
1210
1269
  (0, internal_1.assert)(newFieldIds.length === 0, 0x9c6 /* TODO: Modifying a cross-field key from the new changeset is currently unsupported */);
1211
- const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, [
1270
+ const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, {
1212
1271
  target,
1213
1272
  revision,
1214
- id,
1215
- count,
1216
- ]);
1273
+ localId: id,
1274
+ }, count);
1217
1275
  (0, internal_1.assert)(baseFieldIds.length > 0, 0x9c7 /* Cross field key not registered in base or new change */);
1218
1276
  for (const baseFieldId of baseFieldIds) {
1219
1277
  this.table.affectedBaseFields.set([baseFieldId.nodeId?.revision, baseFieldId.nodeId?.localId, baseFieldId.field], true);
@@ -1225,7 +1283,7 @@ class RebaseManager extends CrossFieldManagerI {
1225
1283
  setInChangeAtomIdMap(this.table.rebasedNodeToParent, id, this.fieldId);
1226
1284
  }
1227
1285
  moveKey(target, revision, id, count) {
1228
- setInCrossFieldKeyTable(this.table.rebasedCrossFieldKeys, target, revision, id, count, this.fieldId);
1286
+ this.table.rebasedCrossFieldKeys.set({ target, revision, localId: id }, count, this.fieldId);
1229
1287
  }
1230
1288
  get table() {
1231
1289
  return this.crossFieldTable;
@@ -1239,24 +1297,22 @@ class ComposeManager extends CrossFieldManagerI {
1239
1297
  }
1240
1298
  set(target, revision, id, count, newValue, invalidateDependents) {
1241
1299
  if (invalidateDependents && this.allowInval) {
1242
- const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, [
1300
+ const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, {
1243
1301
  target,
1244
1302
  revision,
1245
- id,
1246
- count,
1247
- ]);
1303
+ localId: id,
1304
+ }, count);
1248
1305
  if (newFieldIds.length > 0) {
1249
1306
  for (const newFieldId of newFieldIds) {
1250
1307
  this.table.pendingCompositions.affectedNewFields.set([newFieldId.nodeId?.revision, newFieldId.nodeId?.localId, newFieldId.field], true);
1251
1308
  }
1252
1309
  }
1253
1310
  else {
1254
- const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, [
1311
+ const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, {
1255
1312
  target,
1256
1313
  revision,
1257
- id,
1258
- count,
1259
- ]);
1314
+ localId: id,
1315
+ }, count);
1260
1316
  (0, internal_1.assert)(baseFieldIds.length > 0, 0x9c8 /* Cross field key not registered in base or new change */);
1261
1317
  for (const baseFieldId of baseFieldIds) {
1262
1318
  this.table.pendingCompositions.affectedBaseFields.set([baseFieldId.nodeId?.revision, baseFieldId.nodeId?.localId, baseFieldId.field], true);
@@ -1280,10 +1336,10 @@ function makeModularChangeset(props = {
1280
1336
  }) {
1281
1337
  const changeset = {
1282
1338
  fieldChanges: props.fieldChanges ?? new Map(),
1283
- nodeChanges: props.nodeChanges ?? newTupleBTree(),
1284
- nodeToParent: props.nodeToParent ?? newTupleBTree(),
1285
- nodeAliases: props.nodeAliases ?? newTupleBTree(),
1286
- crossFieldKeys: props.crossFieldKeys ?? newCrossFieldKeyTable(),
1339
+ nodeChanges: props.nodeChanges ?? (0, index_js_2.newTupleBTree)(),
1340
+ nodeToParent: props.nodeToParent ?? (0, index_js_2.newTupleBTree)(),
1341
+ nodeAliases: props.nodeAliases ?? (0, index_js_2.newTupleBTree)(),
1342
+ crossFieldKeys: props.crossFieldKeys ?? (0, modularChangeTypes_js_1.newCrossFieldKeyTable)(),
1287
1343
  };
1288
1344
  if (props.revisions !== undefined && props.revisions.length > 0) {
1289
1345
  changeset.revisions = props.revisions;
@@ -1294,6 +1350,10 @@ function makeModularChangeset(props = {
1294
1350
  if (props.constraintViolationCount !== undefined && props.constraintViolationCount > 0) {
1295
1351
  changeset.constraintViolationCount = props.constraintViolationCount;
1296
1352
  }
1353
+ if (props.constraintViolationCountOnRevert !== undefined &&
1354
+ props.constraintViolationCountOnRevert > 0) {
1355
+ changeset.constraintViolationCountOnRevert = props.constraintViolationCountOnRevert;
1356
+ }
1297
1357
  if (props.builds !== undefined && props.builds.size > 0) {
1298
1358
  changeset.builds = props.builds;
1299
1359
  }
@@ -1335,7 +1395,7 @@ class ModularEditBuilder extends index_js_1.EditBuilder {
1335
1395
  if (content.mode === 1 /* CursorLocationType.Fields */ && content.getFieldLength() === 0) {
1336
1396
  return { type: "global", revision };
1337
1397
  }
1338
- const builds = newTupleBTree();
1398
+ const builds = (0, index_js_2.newTupleBTree)();
1339
1399
  const chunkCompressor = {
1340
1400
  policy: index_js_3.defaultChunkPolicy,
1341
1401
  idCompressor,
@@ -1362,9 +1422,9 @@ class ModularEditBuilder extends index_js_1.EditBuilder {
1362
1422
  const modularChange = buildModularChangesetFromField({
1363
1423
  path: field,
1364
1424
  fieldChange: { fieldKind, change },
1365
- nodeChanges: newTupleBTree(),
1366
- nodeToParent: newTupleBTree(),
1367
- crossFieldKeys: newCrossFieldKeyTable(),
1425
+ nodeChanges: (0, index_js_2.newTupleBTree)(),
1426
+ nodeToParent: (0, index_js_2.newTupleBTree)(),
1427
+ crossFieldKeys: (0, modularChangeTypes_js_1.newCrossFieldKeyTable)(),
1368
1428
  idAllocator: this.idAllocator,
1369
1429
  localCrossFieldKeys,
1370
1430
  revision,
@@ -1391,9 +1451,9 @@ class ModularEditBuilder extends index_js_1.EditBuilder {
1391
1451
  fieldKind: change.fieldKind,
1392
1452
  change: change.change,
1393
1453
  },
1394
- nodeChanges: newTupleBTree(),
1395
- nodeToParent: newTupleBTree(),
1396
- crossFieldKeys: newCrossFieldKeyTable(),
1454
+ nodeChanges: (0, index_js_2.newTupleBTree)(),
1455
+ nodeToParent: (0, index_js_2.newTupleBTree)(),
1456
+ crossFieldKeys: (0, modularChangeTypes_js_1.newCrossFieldKeyTable)(),
1397
1457
  idAllocator: this.idAllocator,
1398
1458
  localCrossFieldKeys: getChangeHandler(this.fieldKinds, change.fieldKind).getCrossFieldKeys(change.change),
1399
1459
  revision: change.revision,
@@ -1420,9 +1480,23 @@ class ModularEditBuilder extends index_js_1.EditBuilder {
1420
1480
  this.applyChange((0, index_js_1.tagChange)(buildModularChangesetFromNode({
1421
1481
  path,
1422
1482
  nodeChange,
1423
- nodeChanges: newTupleBTree(),
1424
- nodeToParent: newTupleBTree(),
1425
- crossFieldKeys: newCrossFieldKeyTable(),
1483
+ nodeChanges: (0, index_js_2.newTupleBTree)(),
1484
+ nodeToParent: (0, index_js_2.newTupleBTree)(),
1485
+ crossFieldKeys: (0, modularChangeTypes_js_1.newCrossFieldKeyTable)(),
1486
+ idAllocator: this.idAllocator,
1487
+ revision,
1488
+ }), revision));
1489
+ }
1490
+ addNodeExistsConstraintOnRevert(path, revision) {
1491
+ const nodeChange = {
1492
+ nodeExistsConstraintOnRevert: { violated: false },
1493
+ };
1494
+ this.applyChange((0, index_js_1.tagChange)(buildModularChangesetFromNode({
1495
+ path,
1496
+ nodeChange,
1497
+ nodeChanges: (0, index_js_2.newTupleBTree)(),
1498
+ nodeToParent: (0, index_js_2.newTupleBTree)(),
1499
+ crossFieldKeys: (0, modularChangeTypes_js_1.newCrossFieldKeyTable)(),
1426
1500
  idAllocator: this.idAllocator,
1427
1501
  revision,
1428
1502
  }), revision));
@@ -1433,8 +1507,8 @@ function buildModularChangesetFromField(props) {
1433
1507
  const { path, fieldChange, nodeChanges, nodeToParent, crossFieldKeys, idAllocator = (0, index_js_2.idAllocatorFromMaxId)(), localCrossFieldKeys = [], childId, revision, } = props;
1434
1508
  const fieldChanges = new Map([[path.field, fieldChange]]);
1435
1509
  if (path.parent === undefined) {
1436
- for (const key of localCrossFieldKeys) {
1437
- crossFieldKeys.set(key, { nodeId: undefined, field: path.field });
1510
+ for (const { key, count } of localCrossFieldKeys) {
1511
+ crossFieldKeys.set(key, count, { nodeId: undefined, field: path.field });
1438
1512
  }
1439
1513
  if (childId !== undefined) {
1440
1514
  setInChangeAtomIdMap(nodeToParent, childId, {
@@ -1455,8 +1529,8 @@ function buildModularChangesetFromField(props) {
1455
1529
  fieldChanges,
1456
1530
  };
1457
1531
  const parentId = { localId: (0, index_js_2.brand)(idAllocator.allocate()), revision };
1458
- for (const key of localCrossFieldKeys) {
1459
- crossFieldKeys.set(key, { nodeId: parentId, field: path.field });
1532
+ for (const { key, count } of localCrossFieldKeys) {
1533
+ crossFieldKeys.set(key, count, { nodeId: parentId, field: path.field });
1460
1534
  }
1461
1535
  if (childId !== undefined) {
1462
1536
  setInChangeAtomIdMap(nodeToParent, childId, {
@@ -1529,19 +1603,6 @@ function revisionInfoFromTaggedChange(taggedChange) {
1529
1603
  }
1530
1604
  return revInfos;
1531
1605
  }
1532
- function mergeBTrees(tree1, tree2, preferLeft = true) {
1533
- if (tree1 === undefined) {
1534
- return tree2 !== undefined ? (0, index_js_2.brand)(tree2.clone()) : newTupleBTree();
1535
- }
1536
- const result = (0, index_js_2.brand)(tree1.clone());
1537
- if (tree2 === undefined) {
1538
- return result;
1539
- }
1540
- for (const [key, value] of tree2.entries()) {
1541
- result.set(key, value, !preferLeft);
1542
- }
1543
- return result;
1544
- }
1545
1606
  function fieldChangeFromId(fields, nodes, id) {
1546
1607
  const fieldMap = fieldMapFromNodeId(fields, nodes, id.nodeId);
1547
1608
  return fieldMap.get(id.field) ?? (0, index_js_2.fail)("No field exists for the given ID");
@@ -1593,77 +1654,18 @@ function getParentFieldId(changeset, nodeId) {
1593
1654
  return normalizeFieldId(parentId, changeset.nodeAliases);
1594
1655
  }
1595
1656
  exports.getParentFieldId = getParentFieldId;
1596
- function getFieldsForCrossFieldKey(changeset, [target, revision, id, count]) {
1597
- let firstLocalId = id;
1598
- const lastLocalId = id + count - 1;
1599
- const fields = [];
1600
- // eslint-disable-next-line no-constant-condition
1601
- while (true) {
1602
- const entry = getFirstIntersectingCrossFieldEntry(changeset.crossFieldKeys, [
1603
- target,
1604
- revision,
1605
- (0, index_js_2.brand)(firstLocalId),
1606
- count,
1607
- ]);
1608
- if (entry === undefined) {
1609
- return fields;
1610
- }
1611
- const [[_target, _revision, entryId, entryCount], fieldId] = entry;
1612
- fields.push(normalizeFieldId(fieldId, changeset.nodeAliases));
1613
- const entryLastId = entryId + entryCount - 1;
1614
- if (entryLastId >= lastLocalId) {
1615
- return fields;
1616
- }
1617
- firstLocalId = entryLastId + 1;
1618
- }
1619
- }
1620
- exports.getFieldsForCrossFieldKey = getFieldsForCrossFieldKey;
1621
- function getFirstIntersectingCrossFieldEntry(table, [target, revision, id, count]) {
1622
- const entry = table.nextLowerPair([target, revision, id, Number.POSITIVE_INFINITY]);
1623
- if (entry === undefined) {
1624
- return undefined;
1625
- }
1626
- const [entryTarget, entryRevision, entryId, entryCount] = entry[0];
1627
- if (entryTarget !== target || entryRevision !== revision) {
1628
- return undefined;
1629
- }
1630
- const lastQueryId = id + count - 1;
1631
- const entryLastId = entryId + entryCount - 1;
1632
- if (entryId > lastQueryId || entryLastId < id) {
1633
- return undefined;
1634
- }
1635
- return entry;
1636
- }
1637
- function setInCrossFieldKeyTable(table, target, revision, id, count, value) {
1638
- let entry = getFirstIntersectingCrossFieldEntry(table, [target, revision, id, count]);
1639
- const lastQueryId = id + count - 1;
1640
- while (entry !== undefined) {
1641
- const [entryKey, entryValue] = entry;
1642
- table.delete(entryKey);
1643
- const [_target, _revision, entryId, entryCount] = entryKey;
1644
- if (entryId < id) {
1645
- table.set([target, revision, entryId, id - entryId], entryValue);
1646
- }
1647
- const lastEntryId = entryId + entryCount - 1;
1648
- if (lastEntryId > lastQueryId) {
1649
- table.set([target, revision, (0, index_js_2.brand)(lastQueryId + 1), lastEntryId - lastQueryId], entryValue);
1650
- break;
1651
- }
1652
- const nextId = (0, index_js_2.brand)(lastEntryId + 1);
1653
- entry = getFirstIntersectingCrossFieldEntry(table, [
1654
- target,
1655
- revision,
1656
- nextId,
1657
- lastQueryId - nextId + 1,
1658
- ]);
1659
- }
1660
- table.set([target, revision, id, count], value);
1657
+ function getFieldsForCrossFieldKey(changeset, key, count) {
1658
+ return changeset.crossFieldKeys
1659
+ .getAll(key, count)
1660
+ .map(({ value: fieldId }) => normalizeFieldId(fieldId, changeset.nodeAliases));
1661
1661
  }
1662
+ // This is only exported for use in test utilities.
1662
1663
  function normalizeFieldId(fieldId, nodeAliases) {
1663
1664
  return fieldId.nodeId !== undefined
1664
1665
  ? { ...fieldId, nodeId: normalizeNodeId(fieldId.nodeId, nodeAliases) }
1665
1666
  : fieldId;
1666
1667
  }
1668
+ exports.normalizeFieldId = normalizeFieldId;
1667
1669
  /**
1668
1670
  * @returns The canonical form of nodeId, according to nodeAliases
1669
1671
  */
@@ -1681,38 +1683,6 @@ function normalizeNodeId(nodeId, nodeAliases) {
1681
1683
  function hasConflicts(change) {
1682
1684
  return (change.constraintViolationCount ?? 0) > 0;
1683
1685
  }
1684
- function newCrossFieldKeyTable() {
1685
- return newTupleBTree();
1686
- }
1687
- exports.newCrossFieldKeyTable = newCrossFieldKeyTable;
1688
- function newTupleBTree(entries) {
1689
- return (0, index_js_2.brand)(new sorted_btree_es6_1.BTree(entries, compareTuples));
1690
- }
1691
- exports.newTupleBTree = newTupleBTree;
1692
- // This assumes that the arrays are the same length.
1693
- function compareTuples(arrayA, arrayB) {
1694
- for (let i = 0; i < arrayA.length; i++) {
1695
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1696
- const a = arrayA[i];
1697
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1698
- const b = arrayB[i];
1699
- // Less-than and greater-than always return false if either value is undefined,
1700
- // so we handle undefined separately, treating it as less than all other values.
1701
- if (a === undefined && b !== undefined) {
1702
- return -1;
1703
- }
1704
- else if (b === undefined && a !== undefined) {
1705
- return 1;
1706
- }
1707
- else if (a < b) {
1708
- return -1;
1709
- }
1710
- else if (a > b) {
1711
- return 1;
1712
- }
1713
- }
1714
- return 0;
1715
- }
1716
1686
  function getFromChangeAtomIdMap(map, id) {
1717
1687
  return map.get([id.revision, id.localId]);
1718
1688
  }