@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,15 +4,15 @@
4
4
  */
5
5
  import { assert } from "@fluidframework/core-utils/internal";
6
6
  import { BTree } from "@tylerbu/sorted-btree-es6";
7
- import { EditBuilder, isEmptyFieldChanges, makeDetachedNodeId, mapCursorField, replaceAtomRevisions, revisionMetadataSourceFromInfo, areEqualChangeAtomIds, areEqualChangeAtomIdOpts, tagChange, makeAnonChange, } from "../../core/index.js";
8
- import { brand, fail, idAllocatorFromMaxId, idAllocatorFromState, getOrAddInMapLazy, } from "../../util/index.js";
7
+ import { EditBuilder, makeDetachedNodeId, mapCursorField, replaceAtomRevisions, revisionMetadataSourceFromInfo, areEqualChangeAtomIds, areEqualChangeAtomIdOpts, tagChange, makeAnonChange, newChangeAtomIdRangeMap, } from "../../core/index.js";
8
+ import { brand, fail, idAllocatorFromMaxId, idAllocatorFromState, getOrAddInMapLazy, newTupleBTree, mergeTupleBTrees, RangeMap, } from "../../util/index.js";
9
9
  import { chunkFieldSingle, chunkTree, defaultChunkPolicy, } from "../chunked-forest/index.js";
10
10
  import { cursorForMapTreeNode, mapTreeFromCursor } from "../mapTreeCursor.js";
11
- import { MemoizedIdRangeAllocator } from "../memoizedIdRangeAllocator.js";
12
11
  import { CrossFieldTarget, getFirstFromCrossFieldMap, setInCrossFieldMap, } from "./crossFieldQueries.js";
13
12
  import { NodeAttachState, } from "./fieldChangeHandler.js";
14
13
  import { withEditor } from "./fieldKindWithEditor.js";
15
14
  import { convertGenericChange, genericFieldKind } from "./genericFieldKind.js";
15
+ import { newCrossFieldKeyTable, } from "./modularChangeTypes.js";
16
16
  /**
17
17
  * Implementation of ChangeFamily which delegates work in a given field to the appropriate FieldKind
18
18
  * as determined by the schema.
@@ -102,7 +102,7 @@ export class ModularChangeFamily {
102
102
  nodeChanges: newTupleBTree(),
103
103
  nodeToParent: newTupleBTree(),
104
104
  nodeAliases: newTupleBTree(),
105
- crossFieldKeys: newTupleBTree(),
105
+ crossFieldKeys: newCrossFieldKeyTable(),
106
106
  };
107
107
  }
108
108
  else if (hasConflicts(change1)) {
@@ -121,20 +121,20 @@ export class ModularChangeFamily {
121
121
  // A collision for a node ID means that that node is referenced in both changesets
122
122
  // (since we assume that if two changesets use the same node ID they are referring to the same node),
123
123
  // therefore all collisions will be addressed when processing the intersection of the changesets.
124
- const composedNodeChanges = brand(mergeBTrees(change1.nodeChanges, change2.nodeChanges));
125
- const composedNodeToParent = brand(mergeBTrees(change1.nodeToParent, change2.nodeToParent));
126
- const composedNodeAliases = brand(mergeBTrees(change1.nodeAliases, change2.nodeAliases));
124
+ const composedNodeChanges = brand(mergeTupleBTrees(change1.nodeChanges, change2.nodeChanges));
125
+ const composedNodeToParent = brand(mergeTupleBTrees(change1.nodeToParent, change2.nodeToParent));
126
+ const composedNodeAliases = brand(mergeTupleBTrees(change1.nodeAliases, change2.nodeAliases));
127
127
  const crossFieldTable = newComposeTable(change1, change2, composedNodeToParent);
128
128
  const composedFields = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, undefined, genId, crossFieldTable, revisionMetadata);
129
129
  this.composeInvalidatedElements(crossFieldTable, composedFields, composedNodeChanges, composedNodeToParent, composedNodeAliases, genId, revisionMetadata);
130
130
  // Currently no field kinds require making changes to cross-field keys during composition, so we can just merge the two tables.
131
- const composedCrossFieldKeys = mergeBTrees(change1.crossFieldKeys, change2.crossFieldKeys);
131
+ const composedCrossFieldKeys = RangeMap.union(change1.crossFieldKeys, change2.crossFieldKeys);
132
132
  return {
133
133
  fieldChanges: composedFields,
134
134
  nodeChanges: composedNodeChanges,
135
135
  nodeToParent: composedNodeToParent,
136
136
  nodeAliases: composedNodeAliases,
137
- crossFieldKeys: brand(composedCrossFieldKeys),
137
+ crossFieldKeys: composedCrossFieldKeys,
138
138
  };
139
139
  }
140
140
  composeInvalidatedField(fieldChange, crossFieldTable, genId, revisionMetadata) {
@@ -300,7 +300,18 @@ export class ModularChangeFamily {
300
300
  crossFieldTable.composedNodes.add(composedNodeChangeset);
301
301
  }
302
302
  composeNodeChanges(nodeId, change1, change2, genId, crossFieldTable, revisionMetadata) {
303
+ // WARNING: this composition logic assumes that we never make compositions of the following form:
304
+ // change1: a changeset that impact the existence of a node
305
+ // change2: a node-exists constraint on that node.
306
+ // This is currently enforced by the fact that constraints which apply to the input context are included first in the composition.
307
+ // If that weren't the case, we would need to rebase the status of the constraint backward over the changes from change1.
303
308
  const nodeExistsConstraint = change1.nodeExistsConstraint ?? change2.nodeExistsConstraint;
309
+ // WARNING: this composition logic assumes that we never make compositions of the following form:
310
+ // change1: a node-exists-on-revert constraint on a node
311
+ // change2: a changeset that impacts the existence of that node
312
+ // This is currently enforced by the fact that constraints which apply to the revert are included last in the composition.
313
+ // If that weren't the case, we would need to rebase the status of the constraint forward over the changes from change2.
314
+ const nodeExistsConstraintOnRevert = change1.nodeExistsConstraintOnRevert ?? change2.nodeExistsConstraintOnRevert;
304
315
  const composedFieldChanges = this.composeFieldMaps(change1.fieldChanges, change2.fieldChanges, nodeId, genId, crossFieldTable, revisionMetadata);
305
316
  const composedNodeChange = {};
306
317
  if (composedFieldChanges.size > 0) {
@@ -309,6 +320,9 @@ export class ModularChangeFamily {
309
320
  if (nodeExistsConstraint !== undefined) {
310
321
  composedNodeChange.nodeExistsConstraint = nodeExistsConstraint;
311
322
  }
323
+ if (nodeExistsConstraintOnRevert !== undefined) {
324
+ composedNodeChange.nodeExistsConstraintOnRevert = nodeExistsConstraintOnRevert;
325
+ }
312
326
  return composedNodeChange;
313
327
  }
314
328
  /**
@@ -366,7 +380,8 @@ export class ModularChangeFamily {
366
380
  crossFieldKeys,
367
381
  maxId: genId.getMaxId(),
368
382
  revisions: revInfos,
369
- constraintViolationCount: change.change.constraintViolationCount,
383
+ constraintViolationCount: change.change.constraintViolationCountOnRevert,
384
+ constraintViolationCountOnRevert: change.change.constraintViolationCount,
370
385
  destroys,
371
386
  });
372
387
  }
@@ -390,6 +405,17 @@ export class ModularChangeFamily {
390
405
  }
391
406
  invertNodeChange(change, id, isRollback, genId, crossFieldTable, revisionMetadata, revisionForInvert) {
392
407
  const inverse = {};
408
+ // If the node has a constraint, it should be inverted to a node-exist-on-revert constraint. This ensure that if
409
+ // the inverse is inverted again, the original input constraint will be restored.
410
+ if (change.nodeExistsConstraint !== undefined) {
411
+ inverse.nodeExistsConstraintOnRevert = change.nodeExistsConstraint;
412
+ }
413
+ // The node-exist-on-revert constraint of a node is the constraint that should apply when the a change is reverted.
414
+ // So, it should become the constraint in the inverse. If this constraint is violated when applying the inverse,
415
+ // it will be discarded.
416
+ if (change.nodeExistsConstraintOnRevert !== undefined) {
417
+ inverse.nodeExistsConstraint = change.nodeExistsConstraintOnRevert;
418
+ }
393
419
  if (change.fieldChanges !== undefined) {
394
420
  inverse.fieldChanges = this.invertFieldMap(change.fieldChanges, id, isRollback, genId, crossFieldTable, revisionMetadata, revisionForInvert);
395
421
  }
@@ -411,12 +437,11 @@ export class ModularChangeFamily {
411
437
  baseToRebasedNodeId: newTupleBTree(),
412
438
  rebasedFields: new Set(),
413
439
  rebasedNodeToParent: brand(change.nodeToParent.clone()),
414
- rebasedCrossFieldKeys: brand(change.crossFieldKeys.clone()),
440
+ rebasedCrossFieldKeys: change.crossFieldKeys.clone(),
415
441
  nodeIdPairs: [],
416
442
  affectedBaseFields: newTupleBTree(),
417
443
  fieldsWithUnattachedChild: new Set(),
418
444
  };
419
- const constraintState = newConstraintState(change.constraintViolationCount ?? 0);
420
445
  const getBaseRevisions = () => revisionInfoFromTaggedChange(over).map((info) => info.revision);
421
446
  const rebaseMetadata = {
422
447
  ...revisionMetadata,
@@ -424,9 +449,11 @@ export class ModularChangeFamily {
424
449
  getBaseRevisions,
425
450
  };
426
451
  const rebasedNodes = brand(change.nodeChanges.clone());
427
- const rebasedFields = this.rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, constraintState, rebaseMetadata);
452
+ const rebasedFields = this.rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, rebaseMetadata);
428
453
  this.rebaseInvalidatedElements(rebasedFields, rebasedNodes, crossFieldTable, rebaseMetadata, genId);
429
- this.updateConstraintsForFields(rebasedFields, NodeAttachState.Attached, constraintState, rebasedNodes);
454
+ const constraintState = newConstraintState(change.constraintViolationCount ?? 0);
455
+ const revertConstraintState = newConstraintState(change.constraintViolationCountOnRevert ?? 0);
456
+ this.updateConstraintsForFields(rebasedFields, NodeAttachState.Attached, NodeAttachState.Attached, constraintState, revertConstraintState, rebasedNodes);
430
457
  const rebased = makeModularChangeset({
431
458
  fieldChanges: this.pruneFieldMap(rebasedFields, rebasedNodes),
432
459
  nodeChanges: rebasedNodes,
@@ -436,6 +463,7 @@ export class ModularChangeFamily {
436
463
  maxId: idState.maxId,
437
464
  revisions: change.revisions,
438
465
  constraintViolationCount: constraintState.violationCount,
466
+ constraintViolationCountOnRevert: revertConstraintState.violationCount,
439
467
  builds: change.builds,
440
468
  destroys: change.destroys,
441
469
  refreshers: change.refreshers,
@@ -444,14 +472,14 @@ export class ModularChangeFamily {
444
472
  }
445
473
  // This performs a first pass on all fields which have both new and base changes.
446
474
  // TODO: Can we also handle additional passes in this method?
447
- rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, constraintState, metadata) {
475
+ rebaseIntersectingFields(crossFieldTable, rebasedNodes, genId, metadata) {
448
476
  const change = crossFieldTable.newChange;
449
477
  const baseChange = crossFieldTable.baseChange;
450
478
  const rebasedFields = this.rebaseFieldMap(change.fieldChanges, baseChange.fieldChanges, undefined, genId, crossFieldTable, metadata);
451
479
  // This loop processes all fields which have both base and new changes.
452
480
  // Note that the call to `rebaseNodeChange` can add entries to `crossFieldTable.nodeIdPairs`.
453
481
  for (const [newId, baseId, _attachState] of crossFieldTable.nodeIdPairs) {
454
- const rebasedNode = this.rebaseNodeChange(newId, baseId, genId, crossFieldTable, metadata, constraintState);
482
+ const rebasedNode = this.rebaseNodeChange(newId, baseId, genId, crossFieldTable, metadata);
455
483
  setInChangeAtomIdMap(rebasedNodes, newId, rebasedNode);
456
484
  }
457
485
  return rebasedFields;
@@ -626,7 +654,7 @@ export class ModularChangeFamily {
626
654
  }
627
655
  return rebasedFields;
628
656
  }
629
- rebaseNodeChange(newId, baseId, genId, crossFieldTable, revisionMetadata, constraintState) {
657
+ rebaseNodeChange(newId, baseId, genId, crossFieldTable, revisionMetadata) {
630
658
  const change = nodeChangeFromId(crossFieldTable.newChange.nodeChanges, newId);
631
659
  const over = nodeChangeFromId(crossFieldTable.baseChange.nodeChanges, baseId);
632
660
  const baseMap = over?.fieldChanges ?? new Map();
@@ -640,25 +668,32 @@ export class ModularChangeFamily {
640
668
  if (change?.nodeExistsConstraint !== undefined) {
641
669
  rebasedChange.nodeExistsConstraint = change.nodeExistsConstraint;
642
670
  }
671
+ if (change?.nodeExistsConstraintOnRevert !== undefined) {
672
+ rebasedChange.nodeExistsConstraintOnRevert = change.nodeExistsConstraintOnRevert;
673
+ }
643
674
  setInChangeAtomIdMap(crossFieldTable.baseToRebasedNodeId, baseId, newId);
644
675
  return rebasedChange;
645
676
  }
646
- updateConstraintsForFields(fields, parentAttachState, constraintState, nodes) {
677
+ updateConstraintsForFields(fields, parentInputAttachState, parentOutputAttachState, constraintState, revertConstraintState, nodes) {
647
678
  for (const field of fields.values()) {
648
679
  const handler = getChangeHandler(this.fieldKinds, field.fieldKind);
649
- for (const [nodeId, index] of handler.getNestedChanges(field.change)) {
650
- const isDetached = index === undefined;
651
- const attachState = parentAttachState === NodeAttachState.Detached || isDetached
680
+ for (const [nodeId, inputIndex, outputIndex] of handler.getNestedChanges(field.change)) {
681
+ const isInputDetached = inputIndex === undefined;
682
+ const inputAttachState = parentInputAttachState === NodeAttachState.Detached || isInputDetached
683
+ ? NodeAttachState.Detached
684
+ : NodeAttachState.Attached;
685
+ const isOutputDetached = outputIndex === undefined;
686
+ const outputAttachState = parentOutputAttachState === NodeAttachState.Detached || isOutputDetached
652
687
  ? NodeAttachState.Detached
653
688
  : NodeAttachState.Attached;
654
- this.updateConstraintsForNode(nodeId, attachState, constraintState, nodes);
689
+ this.updateConstraintsForNode(nodeId, inputAttachState, outputAttachState, nodes, constraintState, revertConstraintState);
655
690
  }
656
691
  }
657
692
  }
658
- updateConstraintsForNode(nodeId, attachState, constraintState, nodes) {
693
+ updateConstraintsForNode(nodeId, inputAttachState, outputAttachState, nodes, constraintState, revertConstraintState) {
659
694
  const node = nodes.get([nodeId.revision, nodeId.localId]) ?? fail("Unknown node ID");
660
695
  if (node.nodeExistsConstraint !== undefined) {
661
- const isNowViolated = attachState === NodeAttachState.Detached;
696
+ const isNowViolated = inputAttachState === NodeAttachState.Detached;
662
697
  if (node.nodeExistsConstraint.violated !== isNowViolated) {
663
698
  node.nodeExistsConstraint = {
664
699
  ...node.nodeExistsConstraint,
@@ -667,8 +702,18 @@ export class ModularChangeFamily {
667
702
  constraintState.violationCount += isNowViolated ? 1 : -1;
668
703
  }
669
704
  }
705
+ if (node.nodeExistsConstraintOnRevert !== undefined) {
706
+ const isNowViolated = outputAttachState === NodeAttachState.Detached;
707
+ if (node.nodeExistsConstraintOnRevert.violated !== isNowViolated) {
708
+ node.nodeExistsConstraintOnRevert = {
709
+ ...node.nodeExistsConstraintOnRevert,
710
+ violated: isNowViolated,
711
+ };
712
+ revertConstraintState.violationCount += isNowViolated ? 1 : -1;
713
+ }
714
+ }
670
715
  if (node.fieldChanges !== undefined) {
671
- this.updateConstraintsForFields(node.fieldChanges, attachState, constraintState, nodes);
716
+ this.updateConstraintsForFields(node.fieldChanges, inputAttachState, outputAttachState, constraintState, revertConstraintState, nodes);
672
717
  }
673
718
  }
674
719
  pruneFieldMap(changeset, nodeMap) {
@@ -777,8 +822,8 @@ export class ModularChangeFamily {
777
822
  populateCrossFieldKeyTableForFieldMap(table, fields, parent) {
778
823
  for (const [fieldKey, fieldChange] of fields) {
779
824
  const keys = getChangeHandler(this.fieldKinds, fieldChange.fieldKind).getCrossFieldKeys(fieldChange.change);
780
- for (const key of keys) {
781
- table.set(key, { nodeId: parent, field: fieldKey });
825
+ for (const { key, count } of keys) {
826
+ table.set(key, count, { nodeId: parent, field: fieldKey });
782
827
  }
783
828
  }
784
829
  }
@@ -817,7 +862,7 @@ export class ModularChangeFamily {
817
862
  numChildren += 1;
818
863
  }
819
864
  for (const keyRange of handler.getCrossFieldKeys(fieldChange.change)) {
820
- const fields = getFieldsForCrossFieldKey(change, keyRange);
865
+ const fields = getFieldsForCrossFieldKey(change, keyRange.key, keyRange.count);
821
866
  assert(fields.length === 1 &&
822
867
  fields[0] !== undefined &&
823
868
  areEqualFieldIds(fields[0], fieldId), 0xa4f /* Inconsistent cross field keys */);
@@ -828,14 +873,15 @@ export class ModularChangeFamily {
828
873
  }
829
874
  ModularChangeFamily.emptyChange = makeModularChangeset();
830
875
  function replaceCrossFieldKeyTableRevisions(table, oldRevisions, newRevision, nodeAliases) {
831
- const updated = newTupleBTree();
832
- table.forEachPair(([target, revision, id, count], field) => {
833
- const updatedKey = [
834
- target,
835
- replaceRevision(revision, oldRevisions, newRevision),
836
- id,
837
- count,
838
- ];
876
+ const updated = newCrossFieldKeyTable();
877
+ for (const entry of table.entries()) {
878
+ const key = entry.start;
879
+ const updatedKey = {
880
+ target: key.target,
881
+ revision: replaceRevision(key.revision, oldRevisions, newRevision),
882
+ localId: key.localId,
883
+ };
884
+ const field = entry.value;
839
885
  const normalizedFieldId = normalizeFieldId(field, nodeAliases);
840
886
  const updatedNodeId = normalizedFieldId.nodeId !== undefined
841
887
  ? replaceAtomRevisions(normalizedFieldId.nodeId, oldRevisions, newRevision)
@@ -844,8 +890,8 @@ function replaceCrossFieldKeyTableRevisions(table, oldRevisions, newRevision, no
844
890
  ...normalizedFieldId,
845
891
  nodeId: updatedNodeId,
846
892
  };
847
- updated.set(updatedKey, updatedValue);
848
- });
893
+ updated.set(updatedKey, entry.length, updatedValue);
894
+ }
849
895
  return updated;
850
896
  }
851
897
  function replaceRevision(revision, oldRevisions, newRevision) {
@@ -869,9 +915,9 @@ function composeBuildsDestroysAndRefreshers(change1, change2) {
869
915
  // Note that it would in principle be possible to adopt the later build and exclude from the
870
916
  // composition all the changes already reflected on the tree, but that is not something we
871
917
  // care to support at this time.
872
- const allBuilds = brand(mergeBTrees(change1.builds ?? newTupleBTree(), change2.builds ?? newTupleBTree(), true));
873
- const allDestroys = brand(mergeBTrees(change1.destroys ?? newTupleBTree(), change2.destroys ?? newTupleBTree()));
874
- const allRefreshers = brand(mergeBTrees(change1.refreshers ?? newTupleBTree(), change2.refreshers ?? newTupleBTree(), true));
918
+ const allBuilds = brand(mergeTupleBTrees(change1.builds ?? newTupleBTree(), change2.builds ?? newTupleBTree(), true));
919
+ const allDestroys = brand(mergeTupleBTrees(change1.destroys ?? newTupleBTree(), change2.destroys ?? newTupleBTree()));
920
+ const allRefreshers = brand(mergeTupleBTrees(change1.refreshers ?? newTupleBTree(), change2.refreshers ?? newTupleBTree(), true));
875
921
  if (change1.destroys !== undefined && change2.builds !== undefined) {
876
922
  for (const [key, chunk] of change2.builds.entries()) {
877
923
  const destroyCount = change1.destroys.get(key);
@@ -973,7 +1019,7 @@ export function updateRefreshers(change, getDetachedNode, removedRoots, requireR
973
1019
  refreshers.set([root.major, brand(root.minor)], node);
974
1020
  }
975
1021
  }
976
- const { fieldChanges, nodeChanges, maxId, revisions, constraintViolationCount, builds, destroys, } = change;
1022
+ const { fieldChanges, nodeChanges, maxId, revisions, constraintViolationCount, constraintViolationCountOnRevert, builds, destroys, } = change;
977
1023
  return makeModularChangeset({
978
1024
  fieldChanges,
979
1025
  nodeChanges,
@@ -983,25 +1029,35 @@ export function updateRefreshers(change, getDetachedNode, removedRoots, requireR
983
1029
  maxId: maxId,
984
1030
  revisions,
985
1031
  constraintViolationCount,
1032
+ constraintViolationCountOnRevert,
986
1033
  builds,
987
1034
  destroys,
988
1035
  refreshers,
989
1036
  });
990
1037
  }
991
1038
  /**
1039
+ * Converts a change into the delta format.
1040
+ *
992
1041
  * @param change - The change to convert into a delta.
993
1042
  * @param fieldKinds - The field kinds to delegate to.
994
1043
  */
995
1044
  export function intoDelta(taggedChange, fieldKinds) {
996
1045
  const change = taggedChange.change;
997
- const idAllocator = MemoizedIdRangeAllocator.fromNextId();
998
1046
  const rootDelta = {};
1047
+ const global = [];
1048
+ const rename = [];
999
1049
  if (!hasConflicts(change)) {
1000
1050
  // If there are no constraint violations, then tree changes apply.
1001
- const fieldDeltas = intoDeltaImpl(change.fieldChanges, change.nodeChanges, idAllocator, fieldKinds);
1051
+ const fieldDeltas = intoDeltaImpl(change.fieldChanges, change.nodeChanges, fieldKinds, global, rename);
1002
1052
  if (fieldDeltas.size > 0) {
1003
1053
  rootDelta.fields = fieldDeltas;
1004
1054
  }
1055
+ if (global.length > 0) {
1056
+ rootDelta.global = global;
1057
+ }
1058
+ if (rename.length > 0) {
1059
+ rootDelta.rename = rename;
1060
+ }
1005
1061
  }
1006
1062
  // Constraint violations should not prevent nodes from being built
1007
1063
  if (change.builds && change.builds.size > 0) {
@@ -1038,22 +1094,24 @@ function copyDetachedNodes(detachedNodes) {
1038
1094
  /**
1039
1095
  * @param change - The change to convert into a delta.
1040
1096
  */
1041
- function intoDeltaImpl(change, nodeChanges, idAllocator, fieldKinds) {
1097
+ function intoDeltaImpl(change, nodeChanges, fieldKinds, global, rename) {
1042
1098
  const delta = new Map();
1043
1099
  for (const [field, fieldChange] of change) {
1044
- const deltaField = getChangeHandler(fieldKinds, fieldChange.fieldKind).intoDelta(fieldChange.change, (childChange) => {
1100
+ const { local: fieldChanges, global: fieldGlobal, rename: fieldRename, } = getChangeHandler(fieldKinds, fieldChange.fieldKind).intoDelta(fieldChange.change, (childChange) => {
1045
1101
  const nodeChange = nodeChangeFromId(nodeChanges, childChange);
1046
- return deltaFromNodeChange(nodeChange, nodeChanges, idAllocator, fieldKinds);
1047
- }, idAllocator);
1048
- if (!isEmptyFieldChanges(deltaField)) {
1049
- delta.set(field, deltaField);
1102
+ return deltaFromNodeChange(nodeChange, nodeChanges, fieldKinds, global, rename);
1103
+ });
1104
+ if (fieldChanges !== undefined && fieldChanges.length > 0) {
1105
+ delta.set(field, fieldChanges);
1050
1106
  }
1107
+ fieldGlobal?.forEach((c) => global.push(c));
1108
+ fieldRename?.forEach((r) => rename.push(r));
1051
1109
  }
1052
1110
  return delta;
1053
1111
  }
1054
- function deltaFromNodeChange(change, nodeChanges, idAllocator, fieldKinds) {
1112
+ function deltaFromNodeChange(change, nodeChanges, fieldKinds, global, rename) {
1055
1113
  if (change.fieldChanges !== undefined) {
1056
- return intoDeltaImpl(change.fieldChanges, nodeChanges, idAllocator, fieldKinds);
1114
+ return intoDeltaImpl(change.fieldChanges, nodeChanges, fieldKinds, global, rename);
1057
1115
  }
1058
1116
  // TODO: update the API to allow undefined to be returned here
1059
1117
  return new Map();
@@ -1085,7 +1143,9 @@ export function rebaseRevisionMetadataFromInfo(revInfos, revisionToRebase, baseR
1085
1143
  };
1086
1144
  }
1087
1145
  function isEmptyNodeChangeset(change) {
1088
- return change.fieldChanges === undefined && change.nodeExistsConstraint === undefined;
1146
+ return (change.fieldChanges === undefined &&
1147
+ change.nodeExistsConstraint === undefined &&
1148
+ change.nodeExistsConstraintOnRevert === undefined);
1089
1149
  }
1090
1150
  export function getFieldKind(fieldKinds, kind) {
1091
1151
  if (kind === genericFieldKind.identifier) {
@@ -1117,10 +1177,10 @@ function newComposeTable(baseChange, newChange, composedNodeToParent) {
1117
1177
  }
1118
1178
  function newCrossFieldTable() {
1119
1179
  return {
1120
- srcTable: new Map(),
1121
- dstTable: new Map(),
1122
- srcDependents: new Map(),
1123
- dstDependents: new Map(),
1180
+ srcTable: newChangeAtomIdRangeMap(),
1181
+ dstTable: newChangeAtomIdRangeMap(),
1182
+ srcDependents: newChangeAtomIdRangeMap(),
1183
+ dstDependents: newChangeAtomIdRangeMap(),
1124
1184
  invalidatedFields: new Set(),
1125
1185
  };
1126
1186
  }
@@ -1191,19 +1251,17 @@ class RebaseManager extends CrossFieldManagerI {
1191
1251
  }
1192
1252
  set(target, revision, id, count, newValue, invalidateDependents) {
1193
1253
  if (invalidateDependents && this.allowInval) {
1194
- const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, [
1254
+ const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, {
1195
1255
  target,
1196
1256
  revision,
1197
- id,
1198
- count,
1199
- ]);
1257
+ localId: id,
1258
+ }, count);
1200
1259
  assert(newFieldIds.length === 0, 0x9c6 /* TODO: Modifying a cross-field key from the new changeset is currently unsupported */);
1201
- const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, [
1260
+ const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, {
1202
1261
  target,
1203
1262
  revision,
1204
- id,
1205
- count,
1206
- ]);
1263
+ localId: id,
1264
+ }, count);
1207
1265
  assert(baseFieldIds.length > 0, 0x9c7 /* Cross field key not registered in base or new change */);
1208
1266
  for (const baseFieldId of baseFieldIds) {
1209
1267
  this.table.affectedBaseFields.set([baseFieldId.nodeId?.revision, baseFieldId.nodeId?.localId, baseFieldId.field], true);
@@ -1215,7 +1273,7 @@ class RebaseManager extends CrossFieldManagerI {
1215
1273
  setInChangeAtomIdMap(this.table.rebasedNodeToParent, id, this.fieldId);
1216
1274
  }
1217
1275
  moveKey(target, revision, id, count) {
1218
- setInCrossFieldKeyTable(this.table.rebasedCrossFieldKeys, target, revision, id, count, this.fieldId);
1276
+ this.table.rebasedCrossFieldKeys.set({ target, revision, localId: id }, count, this.fieldId);
1219
1277
  }
1220
1278
  get table() {
1221
1279
  return this.crossFieldTable;
@@ -1229,24 +1287,22 @@ class ComposeManager extends CrossFieldManagerI {
1229
1287
  }
1230
1288
  set(target, revision, id, count, newValue, invalidateDependents) {
1231
1289
  if (invalidateDependents && this.allowInval) {
1232
- const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, [
1290
+ const newFieldIds = getFieldsForCrossFieldKey(this.table.newChange, {
1233
1291
  target,
1234
1292
  revision,
1235
- id,
1236
- count,
1237
- ]);
1293
+ localId: id,
1294
+ }, count);
1238
1295
  if (newFieldIds.length > 0) {
1239
1296
  for (const newFieldId of newFieldIds) {
1240
1297
  this.table.pendingCompositions.affectedNewFields.set([newFieldId.nodeId?.revision, newFieldId.nodeId?.localId, newFieldId.field], true);
1241
1298
  }
1242
1299
  }
1243
1300
  else {
1244
- const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, [
1301
+ const baseFieldIds = getFieldsForCrossFieldKey(this.table.baseChange, {
1245
1302
  target,
1246
1303
  revision,
1247
- id,
1248
- count,
1249
- ]);
1304
+ localId: id,
1305
+ }, count);
1250
1306
  assert(baseFieldIds.length > 0, 0x9c8 /* Cross field key not registered in base or new change */);
1251
1307
  for (const baseFieldId of baseFieldIds) {
1252
1308
  this.table.pendingCompositions.affectedBaseFields.set([baseFieldId.nodeId?.revision, baseFieldId.nodeId?.localId, baseFieldId.field], true);
@@ -1284,6 +1340,10 @@ function makeModularChangeset(props = {
1284
1340
  if (props.constraintViolationCount !== undefined && props.constraintViolationCount > 0) {
1285
1341
  changeset.constraintViolationCount = props.constraintViolationCount;
1286
1342
  }
1343
+ if (props.constraintViolationCountOnRevert !== undefined &&
1344
+ props.constraintViolationCountOnRevert > 0) {
1345
+ changeset.constraintViolationCountOnRevert = props.constraintViolationCountOnRevert;
1346
+ }
1287
1347
  if (props.builds !== undefined && props.builds.size > 0) {
1288
1348
  changeset.builds = props.builds;
1289
1349
  }
@@ -1417,13 +1477,27 @@ export class ModularEditBuilder extends EditBuilder {
1417
1477
  revision,
1418
1478
  }), revision));
1419
1479
  }
1480
+ addNodeExistsConstraintOnRevert(path, revision) {
1481
+ const nodeChange = {
1482
+ nodeExistsConstraintOnRevert: { violated: false },
1483
+ };
1484
+ this.applyChange(tagChange(buildModularChangesetFromNode({
1485
+ path,
1486
+ nodeChange,
1487
+ nodeChanges: newTupleBTree(),
1488
+ nodeToParent: newTupleBTree(),
1489
+ crossFieldKeys: newCrossFieldKeyTable(),
1490
+ idAllocator: this.idAllocator,
1491
+ revision,
1492
+ }), revision));
1493
+ }
1420
1494
  }
1421
1495
  function buildModularChangesetFromField(props) {
1422
1496
  const { path, fieldChange, nodeChanges, nodeToParent, crossFieldKeys, idAllocator = idAllocatorFromMaxId(), localCrossFieldKeys = [], childId, revision, } = props;
1423
1497
  const fieldChanges = new Map([[path.field, fieldChange]]);
1424
1498
  if (path.parent === undefined) {
1425
- for (const key of localCrossFieldKeys) {
1426
- crossFieldKeys.set(key, { nodeId: undefined, field: path.field });
1499
+ for (const { key, count } of localCrossFieldKeys) {
1500
+ crossFieldKeys.set(key, count, { nodeId: undefined, field: path.field });
1427
1501
  }
1428
1502
  if (childId !== undefined) {
1429
1503
  setInChangeAtomIdMap(nodeToParent, childId, {
@@ -1444,8 +1518,8 @@ function buildModularChangesetFromField(props) {
1444
1518
  fieldChanges,
1445
1519
  };
1446
1520
  const parentId = { localId: brand(idAllocator.allocate()), revision };
1447
- for (const key of localCrossFieldKeys) {
1448
- crossFieldKeys.set(key, { nodeId: parentId, field: path.field });
1521
+ for (const { key, count } of localCrossFieldKeys) {
1522
+ crossFieldKeys.set(key, count, { nodeId: parentId, field: path.field });
1449
1523
  }
1450
1524
  if (childId !== undefined) {
1451
1525
  setInChangeAtomIdMap(nodeToParent, childId, {
@@ -1518,19 +1592,6 @@ function revisionInfoFromTaggedChange(taggedChange) {
1518
1592
  }
1519
1593
  return revInfos;
1520
1594
  }
1521
- function mergeBTrees(tree1, tree2, preferLeft = true) {
1522
- if (tree1 === undefined) {
1523
- return tree2 !== undefined ? brand(tree2.clone()) : newTupleBTree();
1524
- }
1525
- const result = brand(tree1.clone());
1526
- if (tree2 === undefined) {
1527
- return result;
1528
- }
1529
- for (const [key, value] of tree2.entries()) {
1530
- result.set(key, value, !preferLeft);
1531
- }
1532
- return result;
1533
- }
1534
1595
  function fieldChangeFromId(fields, nodes, id) {
1535
1596
  const fieldMap = fieldMapFromNodeId(fields, nodes, id.nodeId);
1536
1597
  return fieldMap.get(id.field) ?? fail("No field exists for the given ID");
@@ -1581,72 +1642,13 @@ export function getParentFieldId(changeset, nodeId) {
1581
1642
  assert(parentId !== undefined, 0x9cb /* Parent field should be defined */);
1582
1643
  return normalizeFieldId(parentId, changeset.nodeAliases);
1583
1644
  }
1584
- export function getFieldsForCrossFieldKey(changeset, [target, revision, id, count]) {
1585
- let firstLocalId = id;
1586
- const lastLocalId = id + count - 1;
1587
- const fields = [];
1588
- // eslint-disable-next-line no-constant-condition
1589
- while (true) {
1590
- const entry = getFirstIntersectingCrossFieldEntry(changeset.crossFieldKeys, [
1591
- target,
1592
- revision,
1593
- brand(firstLocalId),
1594
- count,
1595
- ]);
1596
- if (entry === undefined) {
1597
- return fields;
1598
- }
1599
- const [[_target, _revision, entryId, entryCount], fieldId] = entry;
1600
- fields.push(normalizeFieldId(fieldId, changeset.nodeAliases));
1601
- const entryLastId = entryId + entryCount - 1;
1602
- if (entryLastId >= lastLocalId) {
1603
- return fields;
1604
- }
1605
- firstLocalId = entryLastId + 1;
1606
- }
1607
- }
1608
- function getFirstIntersectingCrossFieldEntry(table, [target, revision, id, count]) {
1609
- const entry = table.nextLowerPair([target, revision, id, Number.POSITIVE_INFINITY]);
1610
- if (entry === undefined) {
1611
- return undefined;
1612
- }
1613
- const [entryTarget, entryRevision, entryId, entryCount] = entry[0];
1614
- if (entryTarget !== target || entryRevision !== revision) {
1615
- return undefined;
1616
- }
1617
- const lastQueryId = id + count - 1;
1618
- const entryLastId = entryId + entryCount - 1;
1619
- if (entryId > lastQueryId || entryLastId < id) {
1620
- return undefined;
1621
- }
1622
- return entry;
1623
- }
1624
- function setInCrossFieldKeyTable(table, target, revision, id, count, value) {
1625
- let entry = getFirstIntersectingCrossFieldEntry(table, [target, revision, id, count]);
1626
- const lastQueryId = id + count - 1;
1627
- while (entry !== undefined) {
1628
- const [entryKey, entryValue] = entry;
1629
- table.delete(entryKey);
1630
- const [_target, _revision, entryId, entryCount] = entryKey;
1631
- if (entryId < id) {
1632
- table.set([target, revision, entryId, id - entryId], entryValue);
1633
- }
1634
- const lastEntryId = entryId + entryCount - 1;
1635
- if (lastEntryId > lastQueryId) {
1636
- table.set([target, revision, brand(lastQueryId + 1), lastEntryId - lastQueryId], entryValue);
1637
- break;
1638
- }
1639
- const nextId = brand(lastEntryId + 1);
1640
- entry = getFirstIntersectingCrossFieldEntry(table, [
1641
- target,
1642
- revision,
1643
- nextId,
1644
- lastQueryId - nextId + 1,
1645
- ]);
1646
- }
1647
- table.set([target, revision, id, count], value);
1645
+ function getFieldsForCrossFieldKey(changeset, key, count) {
1646
+ return changeset.crossFieldKeys
1647
+ .getAll(key, count)
1648
+ .map(({ value: fieldId }) => normalizeFieldId(fieldId, changeset.nodeAliases));
1648
1649
  }
1649
- function normalizeFieldId(fieldId, nodeAliases) {
1650
+ // This is only exported for use in test utilities.
1651
+ export function normalizeFieldId(fieldId, nodeAliases) {
1650
1652
  return fieldId.nodeId !== undefined
1651
1653
  ? { ...fieldId, nodeId: normalizeNodeId(fieldId.nodeId, nodeAliases) }
1652
1654
  : fieldId;
@@ -1668,36 +1670,6 @@ function normalizeNodeId(nodeId, nodeAliases) {
1668
1670
  function hasConflicts(change) {
1669
1671
  return (change.constraintViolationCount ?? 0) > 0;
1670
1672
  }
1671
- export function newCrossFieldKeyTable() {
1672
- return newTupleBTree();
1673
- }
1674
- export function newTupleBTree(entries) {
1675
- return brand(new BTree(entries, compareTuples));
1676
- }
1677
- // This assumes that the arrays are the same length.
1678
- function compareTuples(arrayA, arrayB) {
1679
- for (let i = 0; i < arrayA.length; i++) {
1680
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1681
- const a = arrayA[i];
1682
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
1683
- const b = arrayB[i];
1684
- // Less-than and greater-than always return false if either value is undefined,
1685
- // so we handle undefined separately, treating it as less than all other values.
1686
- if (a === undefined && b !== undefined) {
1687
- return -1;
1688
- }
1689
- else if (b === undefined && a !== undefined) {
1690
- return 1;
1691
- }
1692
- else if (a < b) {
1693
- return -1;
1694
- }
1695
- else if (a > b) {
1696
- return 1;
1697
- }
1698
- }
1699
- return 0;
1700
- }
1701
1673
  function getFromChangeAtomIdMap(map, id) {
1702
1674
  return map.get([id.revision, id.localId]);
1703
1675
  }