@fluidframework/tree 2.102.0 → 2.110.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 (495) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/api-report/tree.alpha.api.md +12 -3
  3. package/api-report/tree.beta.api.md +11 -3
  4. package/api-report/tree.legacy.beta.api.md +11 -3
  5. package/dist/codec/versioned/format.d.ts +5 -4
  6. package/dist/codec/versioned/format.d.ts.map +1 -1
  7. package/dist/codec/versioned/format.js +4 -3
  8. package/dist/codec/versioned/format.js.map +1 -1
  9. package/dist/core/rebase/types.d.ts +4 -3
  10. package/dist/core/rebase/types.d.ts.map +1 -1
  11. package/dist/core/rebase/types.js +5 -4
  12. package/dist/core/rebase/types.js.map +1 -1
  13. package/dist/core/schema-stored/formatV1.d.ts +16 -15
  14. package/dist/core/schema-stored/formatV1.d.ts.map +1 -1
  15. package/dist/core/schema-stored/formatV1.js +9 -8
  16. package/dist/core/schema-stored/formatV1.js.map +1 -1
  17. package/dist/core/schema-stored/formatV2.d.ts +29 -28
  18. package/dist/core/schema-stored/formatV2.d.ts.map +1 -1
  19. package/dist/core/schema-stored/formatV2.js +11 -10
  20. package/dist/core/schema-stored/formatV2.js.map +1 -1
  21. package/dist/core/schema-stored/index.js +3 -25
  22. package/dist/core/schema-stored/index.js.map +1 -1
  23. package/dist/core/tree/anchorSet.js +4 -8
  24. package/dist/core/tree/anchorSet.js.map +1 -1
  25. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts +11 -10
  26. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -1
  27. package/dist/core/tree/detachedFieldIndexFormatCommon.js +11 -10
  28. package/dist/core/tree/detachedFieldIndexFormatCommon.js.map +1 -1
  29. package/dist/core/tree/detachedFieldIndexFormatV2.d.ts +7 -6
  30. package/dist/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -1
  31. package/dist/core/tree/detachedFieldIndexFormatV2.js +3 -2
  32. package/dist/core/tree/detachedFieldIndexFormatV2.js.map +1 -1
  33. package/dist/core/tree/persistedTreeTextFormat.d.ts +19 -18
  34. package/dist/core/tree/persistedTreeTextFormat.d.ts.map +1 -1
  35. package/dist/core/tree/persistedTreeTextFormat.js +11 -10
  36. package/dist/core/tree/persistedTreeTextFormat.js.map +1 -1
  37. package/dist/entrypoints/internal.js +2 -15
  38. package/dist/entrypoints/internal.js.map +1 -1
  39. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  40. package/dist/feature-libraries/chunked-forest/chunkTree.js +1 -1
  41. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  42. package/dist/feature-libraries/chunked-forest/chunkedForest.js +7 -11
  43. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  44. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts +13 -12
  45. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts.map +1 -1
  46. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.js +14 -13
  47. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.js.map +1 -1
  48. package/dist/feature-libraries/chunked-forest/codec/format/formatV1.d.ts +36 -35
  49. package/dist/feature-libraries/chunked-forest/codec/format/formatV1.d.ts.map +1 -1
  50. package/dist/feature-libraries/chunked-forest/codec/format/formatV1.js +19 -18
  51. package/dist/feature-libraries/chunked-forest/codec/format/formatV1.js.map +1 -1
  52. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.d.ts +26 -25
  53. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.d.ts.map +1 -1
  54. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js +5 -4
  55. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
  56. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.d.ts +24 -23
  57. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.d.ts.map +1 -1
  58. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js +8 -7
  59. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -1
  60. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts +66 -14
  61. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  62. package/dist/feature-libraries/chunked-forest/uniformChunk.js +101 -36
  63. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  64. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  65. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +36 -14
  66. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  67. package/dist/feature-libraries/flex-tree/lazyEntity.js +9 -19
  68. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  69. package/dist/feature-libraries/flex-tree/lazyNode.js +3 -13
  70. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  71. package/dist/feature-libraries/forest-summary/formatCommon.d.ts +6 -5
  72. package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  73. package/dist/feature-libraries/forest-summary/formatCommon.js +4 -3
  74. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  75. package/dist/feature-libraries/index.js +2 -24
  76. package/dist/feature-libraries/index.js.map +1 -1
  77. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.d.ts +4 -3
  78. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.d.ts.map +1 -1
  79. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.js +4 -3
  80. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.js.map +1 -1
  81. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  82. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +10 -30
  83. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  84. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +45 -44
  85. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  86. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js +26 -25
  87. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  88. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +23 -22
  89. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  90. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js +7 -6
  91. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -1
  92. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +0 -5
  93. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  94. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  95. package/dist/feature-libraries/object-forest/objectForest.js +11 -55
  96. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  97. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +9 -8
  98. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  99. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.js +9 -8
  100. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.js.map +1 -1
  101. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +14 -13
  102. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  103. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.js +12 -11
  104. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.js.map +1 -1
  105. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +5 -4
  106. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  107. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js +3 -2
  108. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  109. package/dist/feature-libraries/schema-index/formatV1.d.ts +15 -14
  110. package/dist/feature-libraries/schema-index/formatV1.d.ts.map +1 -1
  111. package/dist/feature-libraries/schema-index/formatV1.js +5 -4
  112. package/dist/feature-libraries/schema-index/formatV1.js.map +1 -1
  113. package/dist/feature-libraries/schema-index/formatV2.d.ts +20 -19
  114. package/dist/feature-libraries/schema-index/formatV2.d.ts.map +1 -1
  115. package/dist/feature-libraries/schema-index/formatV2.js +5 -4
  116. package/dist/feature-libraries/schema-index/formatV2.js.map +1 -1
  117. package/dist/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  118. package/dist/feature-libraries/sequence-field/compose.js +1 -3
  119. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  120. package/dist/feature-libraries/sequence-field/formatV1.d.ts +283 -282
  121. package/dist/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  122. package/dist/feature-libraries/sequence-field/formatV1.js +41 -40
  123. package/dist/feature-libraries/sequence-field/formatV1.js.map +1 -1
  124. package/dist/feature-libraries/sequence-field/formatV2.d.ts +180 -179
  125. package/dist/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  126. package/dist/feature-libraries/sequence-field/formatV2.js +33 -32
  127. package/dist/feature-libraries/sequence-field/formatV2.js.map +1 -1
  128. package/dist/feature-libraries/sequence-field/formatV3.d.ts +126 -125
  129. package/dist/feature-libraries/sequence-field/formatV3.d.ts.map +1 -1
  130. package/dist/feature-libraries/sequence-field/formatV3.js +5 -4
  131. package/dist/feature-libraries/sequence-field/formatV3.js.map +1 -1
  132. package/dist/index.js +2 -24
  133. package/dist/index.js.map +1 -1
  134. package/dist/packageVersion.d.ts +1 -1
  135. package/dist/packageVersion.js +1 -1
  136. package/dist/packageVersion.js.map +1 -1
  137. package/dist/shared-tree/schematizingTreeView.d.ts +1 -0
  138. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  139. package/dist/shared-tree/schematizingTreeView.js +7 -41
  140. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  141. package/dist/shared-tree/sharedTree.d.ts +2 -3
  142. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  143. package/dist/shared-tree/sharedTree.js +6 -45
  144. package/dist/shared-tree/sharedTree.js.map +1 -1
  145. package/dist/shared-tree/sharedTreeChangeFormat.d.ts +8 -7
  146. package/dist/shared-tree/sharedTreeChangeFormat.d.ts.map +1 -1
  147. package/dist/shared-tree/sharedTreeChangeFormat.js +6 -5
  148. package/dist/shared-tree/sharedTreeChangeFormat.js.map +1 -1
  149. package/dist/shared-tree/treeCheckout.d.ts +14 -5
  150. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  151. package/dist/shared-tree/treeCheckout.js +106 -136
  152. package/dist/shared-tree/treeCheckout.js.map +1 -1
  153. package/dist/shared-tree-core/branch.js +13 -17
  154. package/dist/shared-tree-core/branch.js.map +1 -1
  155. package/dist/shared-tree-core/editManager.d.ts +2 -2
  156. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  157. package/dist/shared-tree-core/editManager.js.map +1 -1
  158. package/dist/shared-tree-core/editManagerFormatCommons.d.ts +35 -34
  159. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  160. package/dist/shared-tree-core/editManagerFormatCommons.js +17 -16
  161. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  162. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +15 -15
  163. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  164. package/dist/shared-tree-core/editManagerFormatV1toV4.js +11 -10
  165. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  166. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts +40 -40
  167. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
  168. package/dist/shared-tree-core/editManagerFormatVSharedBranches.js +5 -4
  169. package/dist/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
  170. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  171. package/dist/shared-tree-core/messageCodecVSharedBranches.js +3 -2
  172. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  173. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts +5 -5
  174. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  175. package/dist/shared-tree-core/messageFormatV1ToV4.js +9 -8
  176. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  177. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts +7 -7
  178. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  179. package/dist/shared-tree-core/messageFormatVSharedBranches.js +7 -6
  180. package/dist/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  181. package/dist/shared-tree-core/sharedTreeCore.js +6 -43
  182. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  183. package/dist/shared-tree-core/transaction.js +20 -30
  184. package/dist/shared-tree-core/transaction.js.map +1 -1
  185. package/dist/simple-tree/api/simpleSchemaCodec.js +2 -24
  186. package/dist/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  187. package/dist/simple-tree/api/snapshotCompatibilityChecker.js +2 -24
  188. package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  189. package/dist/simple-tree/api/tree.d.ts +10 -0
  190. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  191. package/dist/simple-tree/api/tree.js.map +1 -1
  192. package/dist/simple-tree/core/treeNodeKernel.d.ts +5 -0
  193. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  194. package/dist/simple-tree/core/treeNodeKernel.js +119 -105
  195. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  196. package/dist/simple-tree/core/unhydratedFlexTree.js +6 -10
  197. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  198. package/dist/simple-tree/leafNodeSchema.js +2 -12
  199. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  200. package/dist/simple-tree/node-kinds/array/arrayNode.js +2 -6
  201. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  202. package/dist/simple-tree/simpleSchemaFormatV1.d.ts +121 -120
  203. package/dist/simple-tree/simpleSchemaFormatV1.d.ts.map +1 -1
  204. package/dist/simple-tree/simpleSchemaFormatV1.js +32 -31
  205. package/dist/simple-tree/simpleSchemaFormatV1.js.map +1 -1
  206. package/dist/tableSchema.d.ts +50 -4
  207. package/dist/tableSchema.d.ts.map +1 -1
  208. package/dist/tableSchema.js +202 -106
  209. package/dist/tableSchema.js.map +1 -1
  210. package/dist/util/arrayUtilities.d.ts +20 -0
  211. package/dist/util/arrayUtilities.d.ts.map +1 -1
  212. package/dist/util/arrayUtilities.js +24 -1
  213. package/dist/util/arrayUtilities.js.map +1 -1
  214. package/dist/util/index.d.ts +1 -1
  215. package/dist/util/index.d.ts.map +1 -1
  216. package/dist/util/index.js +3 -2
  217. package/dist/util/index.js.map +1 -1
  218. package/dist/util/rangeMap.d.ts +13 -0
  219. package/dist/util/rangeMap.d.ts.map +1 -1
  220. package/dist/util/rangeMap.js +69 -8
  221. package/dist/util/rangeMap.js.map +1 -1
  222. package/dist/util/typeboxBrand.d.ts +1 -1
  223. package/dist/util/typeboxBrand.d.ts.map +1 -1
  224. package/dist/util/typeboxBrand.js +4 -3
  225. package/dist/util/typeboxBrand.js.map +1 -1
  226. package/dist/util/utils.d.ts +2 -2
  227. package/dist/util/utils.d.ts.map +1 -1
  228. package/dist/util/utils.js +3 -2
  229. package/dist/util/utils.js.map +1 -1
  230. package/eslint.config.mts +14 -0
  231. package/lib/codec/versioned/format.d.ts +5 -4
  232. package/lib/codec/versioned/format.d.ts.map +1 -1
  233. package/lib/codec/versioned/format.js +1 -1
  234. package/lib/codec/versioned/format.js.map +1 -1
  235. package/lib/core/rebase/types.d.ts +4 -3
  236. package/lib/core/rebase/types.d.ts.map +1 -1
  237. package/lib/core/rebase/types.js +1 -1
  238. package/lib/core/rebase/types.js.map +1 -1
  239. package/lib/core/schema-stored/formatV1.d.ts +16 -15
  240. package/lib/core/schema-stored/formatV1.d.ts.map +1 -1
  241. package/lib/core/schema-stored/formatV1.js +1 -1
  242. package/lib/core/schema-stored/formatV1.js.map +1 -1
  243. package/lib/core/schema-stored/formatV2.d.ts +29 -28
  244. package/lib/core/schema-stored/formatV2.d.ts.map +1 -1
  245. package/lib/core/schema-stored/formatV2.js +1 -1
  246. package/lib/core/schema-stored/formatV2.js.map +1 -1
  247. package/lib/core/tree/anchorSet.js +1 -5
  248. package/lib/core/tree/anchorSet.js.map +1 -1
  249. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts +11 -10
  250. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -1
  251. package/lib/core/tree/detachedFieldIndexFormatCommon.js +1 -1
  252. package/lib/core/tree/detachedFieldIndexFormatCommon.js.map +1 -1
  253. package/lib/core/tree/detachedFieldIndexFormatV2.d.ts +7 -6
  254. package/lib/core/tree/detachedFieldIndexFormatV2.d.ts.map +1 -1
  255. package/lib/core/tree/detachedFieldIndexFormatV2.js +1 -1
  256. package/lib/core/tree/detachedFieldIndexFormatV2.js.map +1 -1
  257. package/lib/core/tree/persistedTreeTextFormat.d.ts +19 -18
  258. package/lib/core/tree/persistedTreeTextFormat.d.ts.map +1 -1
  259. package/lib/core/tree/persistedTreeTextFormat.js +1 -1
  260. package/lib/core/tree/persistedTreeTextFormat.js.map +1 -1
  261. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  262. package/lib/feature-libraries/chunked-forest/chunkTree.js +1 -1
  263. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  264. package/lib/feature-libraries/chunked-forest/chunkedForest.js +1 -5
  265. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  266. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts +13 -12
  267. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.d.ts.map +1 -1
  268. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.js +1 -1
  269. package/lib/feature-libraries/chunked-forest/codec/format/formatGeneric.js.map +1 -1
  270. package/lib/feature-libraries/chunked-forest/codec/format/formatV1.d.ts +36 -35
  271. package/lib/feature-libraries/chunked-forest/codec/format/formatV1.d.ts.map +1 -1
  272. package/lib/feature-libraries/chunked-forest/codec/format/formatV1.js +1 -1
  273. package/lib/feature-libraries/chunked-forest/codec/format/formatV1.js.map +1 -1
  274. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.d.ts +26 -25
  275. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.d.ts.map +1 -1
  276. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.js +1 -1
  277. package/lib/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
  278. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.d.ts +24 -23
  279. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.d.ts.map +1 -1
  280. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.js +1 -1
  281. package/lib/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -1
  282. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts +66 -14
  283. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  284. package/lib/feature-libraries/chunked-forest/uniformChunk.js +101 -36
  285. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  286. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  287. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +36 -14
  288. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  289. package/lib/feature-libraries/flex-tree/lazyEntity.js +1 -11
  290. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  291. package/lib/feature-libraries/flex-tree/lazyNode.js +1 -11
  292. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  293. package/lib/feature-libraries/forest-summary/formatCommon.d.ts +6 -5
  294. package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -1
  295. package/lib/feature-libraries/forest-summary/formatCommon.js +1 -1
  296. package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  297. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.d.ts +4 -3
  298. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.d.ts.map +1 -1
  299. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.js +1 -1
  300. package/lib/feature-libraries/modular-schema/genericFieldKindFormat.js.map +1 -1
  301. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  302. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +10 -30
  303. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  304. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +45 -44
  305. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  306. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js +1 -1
  307. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  308. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +23 -22
  309. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  310. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.js +1 -1
  311. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -1
  312. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +0 -5
  313. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  314. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  315. package/lib/feature-libraries/object-forest/objectForest.js +1 -45
  316. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  317. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +9 -8
  318. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  319. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.js +1 -1
  320. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.js.map +1 -1
  321. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +14 -13
  322. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  323. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.js +1 -1
  324. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.js.map +1 -1
  325. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +5 -4
  326. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts.map +1 -1
  327. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js +1 -1
  328. package/lib/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  329. package/lib/feature-libraries/schema-index/formatV1.d.ts +15 -14
  330. package/lib/feature-libraries/schema-index/formatV1.d.ts.map +1 -1
  331. package/lib/feature-libraries/schema-index/formatV1.js +1 -1
  332. package/lib/feature-libraries/schema-index/formatV1.js.map +1 -1
  333. package/lib/feature-libraries/schema-index/formatV2.d.ts +20 -19
  334. package/lib/feature-libraries/schema-index/formatV2.d.ts.map +1 -1
  335. package/lib/feature-libraries/schema-index/formatV2.js +1 -1
  336. package/lib/feature-libraries/schema-index/formatV2.js.map +1 -1
  337. package/lib/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  338. package/lib/feature-libraries/sequence-field/compose.js +1 -3
  339. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  340. package/lib/feature-libraries/sequence-field/formatV1.d.ts +283 -282
  341. package/lib/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  342. package/lib/feature-libraries/sequence-field/formatV1.js +1 -1
  343. package/lib/feature-libraries/sequence-field/formatV1.js.map +1 -1
  344. package/lib/feature-libraries/sequence-field/formatV2.d.ts +180 -179
  345. package/lib/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  346. package/lib/feature-libraries/sequence-field/formatV2.js +1 -1
  347. package/lib/feature-libraries/sequence-field/formatV2.js.map +1 -1
  348. package/lib/feature-libraries/sequence-field/formatV3.d.ts +126 -125
  349. package/lib/feature-libraries/sequence-field/formatV3.d.ts.map +1 -1
  350. package/lib/feature-libraries/sequence-field/formatV3.js +1 -1
  351. package/lib/feature-libraries/sequence-field/formatV3.js.map +1 -1
  352. package/lib/packageVersion.d.ts +1 -1
  353. package/lib/packageVersion.js +1 -1
  354. package/lib/packageVersion.js.map +1 -1
  355. package/lib/shared-tree/schematizingTreeView.d.ts +1 -0
  356. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  357. package/lib/shared-tree/schematizingTreeView.js +4 -38
  358. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  359. package/lib/shared-tree/sharedTree.d.ts +2 -3
  360. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  361. package/lib/shared-tree/sharedTree.js +2 -41
  362. package/lib/shared-tree/sharedTree.js.map +1 -1
  363. package/lib/shared-tree/sharedTreeChangeFormat.d.ts +8 -7
  364. package/lib/shared-tree/sharedTreeChangeFormat.d.ts.map +1 -1
  365. package/lib/shared-tree/sharedTreeChangeFormat.js +1 -1
  366. package/lib/shared-tree/sharedTreeChangeFormat.js.map +1 -1
  367. package/lib/shared-tree/treeCheckout.d.ts +14 -5
  368. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  369. package/lib/shared-tree/treeCheckout.js +63 -93
  370. package/lib/shared-tree/treeCheckout.js.map +1 -1
  371. package/lib/shared-tree-core/branch.js +1 -5
  372. package/lib/shared-tree-core/branch.js.map +1 -1
  373. package/lib/shared-tree-core/editManager.d.ts +2 -2
  374. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  375. package/lib/shared-tree-core/editManager.js.map +1 -1
  376. package/lib/shared-tree-core/editManagerFormatCommons.d.ts +35 -34
  377. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  378. package/lib/shared-tree-core/editManagerFormatCommons.js +1 -1
  379. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  380. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +15 -15
  381. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  382. package/lib/shared-tree-core/editManagerFormatV1toV4.js +1 -1
  383. package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  384. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts +40 -40
  385. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
  386. package/lib/shared-tree-core/editManagerFormatVSharedBranches.js +1 -1
  387. package/lib/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
  388. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  389. package/lib/shared-tree-core/messageCodecVSharedBranches.js +1 -1
  390. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  391. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts +5 -5
  392. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  393. package/lib/shared-tree-core/messageFormatV1ToV4.js +1 -1
  394. package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  395. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts +7 -7
  396. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  397. package/lib/shared-tree-core/messageFormatVSharedBranches.js +1 -1
  398. package/lib/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  399. package/lib/shared-tree-core/sharedTreeCore.js +1 -38
  400. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  401. package/lib/shared-tree-core/transaction.js +1 -11
  402. package/lib/shared-tree-core/transaction.js.map +1 -1
  403. package/lib/simple-tree/api/tree.d.ts +10 -0
  404. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  405. package/lib/simple-tree/api/tree.js.map +1 -1
  406. package/lib/simple-tree/core/treeNodeKernel.d.ts +5 -0
  407. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  408. package/lib/simple-tree/core/treeNodeKernel.js +36 -23
  409. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  410. package/lib/simple-tree/core/unhydratedFlexTree.js +1 -5
  411. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  412. package/lib/simple-tree/leafNodeSchema.js +1 -11
  413. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  414. package/lib/simple-tree/node-kinds/array/arrayNode.js +1 -5
  415. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  416. package/lib/simple-tree/simpleSchemaFormatV1.d.ts +121 -120
  417. package/lib/simple-tree/simpleSchemaFormatV1.d.ts.map +1 -1
  418. package/lib/simple-tree/simpleSchemaFormatV1.js +1 -1
  419. package/lib/simple-tree/simpleSchemaFormatV1.js.map +1 -1
  420. package/lib/tableSchema.d.ts +50 -4
  421. package/lib/tableSchema.d.ts.map +1 -1
  422. package/lib/tableSchema.js +171 -75
  423. package/lib/tableSchema.js.map +1 -1
  424. package/lib/util/arrayUtilities.d.ts +20 -0
  425. package/lib/util/arrayUtilities.d.ts.map +1 -1
  426. package/lib/util/arrayUtilities.js +22 -0
  427. package/lib/util/arrayUtilities.js.map +1 -1
  428. package/lib/util/index.d.ts +1 -1
  429. package/lib/util/index.d.ts.map +1 -1
  430. package/lib/util/index.js +1 -1
  431. package/lib/util/index.js.map +1 -1
  432. package/lib/util/rangeMap.d.ts +13 -0
  433. package/lib/util/rangeMap.d.ts.map +1 -1
  434. package/lib/util/rangeMap.js +69 -8
  435. package/lib/util/rangeMap.js.map +1 -1
  436. package/lib/util/typeboxBrand.d.ts +1 -1
  437. package/lib/util/typeboxBrand.d.ts.map +1 -1
  438. package/lib/util/typeboxBrand.js +1 -1
  439. package/lib/util/typeboxBrand.js.map +1 -1
  440. package/lib/util/utils.d.ts +2 -2
  441. package/lib/util/utils.d.ts.map +1 -1
  442. package/lib/util/utils.js +1 -1
  443. package/lib/util/utils.js.map +1 -1
  444. package/package.json +24 -23
  445. package/src/codec/versioned/format.ts +2 -1
  446. package/src/core/rebase/types.ts +1 -1
  447. package/src/core/schema-stored/formatV1.ts +2 -1
  448. package/src/core/schema-stored/formatV2.ts +2 -1
  449. package/src/core/tree/detachedFieldIndexFormatCommon.ts +2 -1
  450. package/src/core/tree/detachedFieldIndexFormatV2.ts +2 -1
  451. package/src/core/tree/persistedTreeTextFormat.ts +2 -1
  452. package/src/feature-libraries/chunked-forest/chunkTree.ts +3 -2
  453. package/src/feature-libraries/chunked-forest/codec/format/formatGeneric.ts +2 -1
  454. package/src/feature-libraries/chunked-forest/codec/format/formatV1.ts +2 -1
  455. package/src/feature-libraries/chunked-forest/codec/format/formatV2.ts +2 -1
  456. package/src/feature-libraries/chunked-forest/codec/format/formatVText.ts +2 -1
  457. package/src/feature-libraries/chunked-forest/uniformChunk.ts +131 -44
  458. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +36 -14
  459. package/src/feature-libraries/forest-summary/formatCommon.ts +2 -1
  460. package/src/feature-libraries/modular-schema/genericFieldKindFormat.ts +2 -1
  461. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +14 -47
  462. package/src/feature-libraries/modular-schema/modularChangeFormatV1.ts +2 -1
  463. package/src/feature-libraries/modular-schema/modularChangeFormatV2.ts +2 -1
  464. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +0 -5
  465. package/src/feature-libraries/optional-field/optionalFieldChangeFormatV1.ts +2 -1
  466. package/src/feature-libraries/optional-field/optionalFieldChangeFormatV2.ts +2 -1
  467. package/src/feature-libraries/schema-edits/schemaChangeFormat.ts +2 -1
  468. package/src/feature-libraries/schema-index/formatV1.ts +2 -1
  469. package/src/feature-libraries/schema-index/formatV2.ts +2 -1
  470. package/src/feature-libraries/sequence-field/compose.ts +1 -4
  471. package/src/feature-libraries/sequence-field/formatV1.ts +2 -1
  472. package/src/feature-libraries/sequence-field/formatV2.ts +2 -1
  473. package/src/feature-libraries/sequence-field/formatV3.ts +2 -1
  474. package/src/packageVersion.ts +1 -1
  475. package/src/shared-tree/schematizingTreeView.ts +4 -0
  476. package/src/shared-tree/sharedTree.ts +3 -10
  477. package/src/shared-tree/sharedTreeChangeFormat.ts +2 -1
  478. package/src/shared-tree/treeCheckout.ts +61 -56
  479. package/src/shared-tree-core/editManager.ts +2 -2
  480. package/src/shared-tree-core/editManagerFormatCommons.ts +2 -1
  481. package/src/shared-tree-core/editManagerFormatV1toV4.ts +2 -1
  482. package/src/shared-tree-core/editManagerFormatVSharedBranches.ts +2 -1
  483. package/src/shared-tree-core/messageCodecVSharedBranches.ts +2 -1
  484. package/src/shared-tree-core/messageFormatV1ToV4.ts +2 -1
  485. package/src/shared-tree-core/messageFormatVSharedBranches.ts +2 -1
  486. package/src/simple-tree/api/tree.ts +11 -0
  487. package/src/simple-tree/core/treeNodeKernel.ts +39 -15
  488. package/src/simple-tree/simpleSchemaFormatV1.ts +2 -1
  489. package/src/tableSchema.ts +306 -80
  490. package/src/util/arrayUtilities.ts +35 -0
  491. package/src/util/index.ts +2 -0
  492. package/src/util/rangeMap.ts +108 -9
  493. package/src/util/typeboxBrand.ts +2 -1
  494. package/src/util/utils.ts +2 -1
  495. package/tsconfig.json +5 -0
@@ -113,7 +113,15 @@ export class TreeShape {
113
113
  public readonly fieldsOffsetArray: readonly OffsetShape[];
114
114
  public readonly valuesPerTopLevelNode: number;
115
115
 
116
- // TODO: this is only needed at chunk roots. Optimize it base on that.
116
+ /**
117
+ * Information about every node in this shape.
118
+ * The root is first, and all indexes it uses to refer to other nodes are indexes into this array.
119
+ * Beyond that the ordering is an implementation detail of this shape.
120
+ * @remarks
121
+ * Use of this in contexts where there might be multiple top-level nodes requires some additional care.
122
+ * For example {@link Cursor} derives each node's actual position info from this shared
123
+ * array plus the node's top-level index within the chunk.
124
+ */
117
125
  public readonly positions: readonly NodePositionInfo[];
118
126
 
119
127
  /**
@@ -246,25 +254,19 @@ function clonePositions(
246
254
  /**
247
255
  * The shape (see `TreeShape`) of a sequence of trees, all with the same shape (like `FieldShape`, but without a field key).
248
256
  *
249
- * This shape is optimized (by caching derived data like the positions array),
250
- * so that when paired with a value array it can be efficiently traversed like a tree by an {@link ITreeCursorSynchronous}.
251
- * See {@link uniformChunk} for how to do this.
257
+ * @remarks
258
+ * Paired with a value array, this lets a {@link UniformChunk} be traversed like a tree by an
259
+ * {@link ITreeCursorSynchronous}. The {@link Cursor} derives each node's position info from the
260
+ * shared {@link TreeShape.positions} plus the node's top-level index.
252
261
  *
253
262
  * TODO: consider storing shape information in WASM
254
263
  */
255
264
  export class ChunkShape {
256
- public readonly positions: readonly (NodePositionInfo | undefined)[];
257
-
258
265
  public constructor(
259
266
  public readonly treeShape: TreeShape,
260
267
  public readonly topLevelLength: number,
261
268
  ) {
262
269
  assert(topLevelLength > 0, 0x4c6 /* topLevelLength must be greater than 0 */);
263
-
264
- // TODO: avoid duplication from inner loop
265
- const positions: (NodePositionInfo | undefined)[] = [undefined];
266
- clonePositions(0, [dummyRoot, treeShape, topLevelLength], 0, 0, positions);
267
- this.positions = positions;
268
270
  }
269
271
 
270
272
  public equals(other: ChunkShape): boolean {
@@ -295,17 +297,19 @@ class OffsetShape {
295
297
  }
296
298
 
297
299
  /**
298
- * Information about a node at a specific position within a uniform chunk.
300
+ * Information about a node at a specific position within one top-level tree of a {@link TreeShape}.
299
301
  */
300
302
  class NodePositionInfo implements UpPath {
301
303
  /**
302
- * @param parent - TODO
303
- * @param parentField - TODO
304
+ * @param parent - The parent node's {@link NodePositionInfo} or `undefined` for a root.
305
+ * @param parentField - The {@link FieldKey} of the field this node occupies within its parent.
304
306
  * @param parentIndex - indexWithinParentField
305
- * @param indexOfParentField - which field of the parent `parentIndex` is indexing into to locate this.
306
- * @param indexOfParentPosition - Index of parent NodePositionInfo in positions array. TODO: use offsets to avoid copying at top level?
307
+ * @param indexOfParentField - Which field of the parent `parentIndex` is indexing into to locate this.
308
+ * @param indexOfParentPosition - Index of this node's parent in {@link TreeShape.positions}
307
309
  * @param shape - Shape of the top level sequence this node is part of
308
- * @param valueOffset - TODO
310
+ * @param topLevelLength - Number of siblings in this node's field. For a root this is unused
311
+ * @param valueOffset - Offset of this node's value within one top-level tree's slice of the chunk's flat `values` array;
312
+ * only valid when `shape.hasValue` (otherwise it's where the value would have gone, and should not be used to read a value).
309
313
  */
310
314
  public constructor(
311
315
  public readonly parent: NodePositionInfo | undefined, // TODO; general UpPath to allow prefixing here?
@@ -322,16 +326,28 @@ class NodePositionInfo implements UpPath {
322
326
  /**
323
327
  * The cursor implementation for `UniformChunk`.
324
328
  *
325
- * Works by tracking its location in the chunk's `positions` array.
329
+ * @remarks
330
+ * Tracks a flat `positionIndex` and derives each node's position info from the shape's shared
331
+ * {@link TreeShape.positions} plus the node's top-level index.
326
332
  */
327
333
  class Cursor extends SynchronousCursor implements ChunkedCursor {
328
334
  private positionIndex!: number; // When in fields mode, this points to the parent node.
329
- // Undefined when in root field
335
+
336
+ /** Position info for the current node, or `undefined` when in root field. */
330
337
  private nodePositionInfo: NodePositionInfo | undefined;
331
338
 
332
- // Cached constants for faster access
339
+ /** Which top-level node of the chunk the current position is within. Valid when nodePositionInfo !== undefined. */
340
+ private topLevelIndex: number = 0;
341
+
342
+ // Cached constants for faster access.
343
+ /** The chunk's shape. */
333
344
  private readonly shape: ChunkShape;
334
- private readonly positions: readonly (NodePositionInfo | undefined)[];
345
+ /** The chunk's per-tree shape (shape of each top-level tree). */
346
+ private readonly treeShape: TreeShape;
347
+ /** Number of positions in one top-level tree (treeShape.positions.length). */
348
+ private readonly nodeLength: number;
349
+ /** Number of values per top-level node (treeShape.valuesPerTopLevelNode). */
350
+ private readonly stride: number;
335
351
 
336
352
  public mode: CursorLocationType = CursorLocationType.Fields;
337
353
 
@@ -346,7 +362,9 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
346
362
  public constructor(private readonly chunk: UniformChunk) {
347
363
  super();
348
364
  this.shape = this.chunk.shape;
349
- this.positions = this.shape.positions;
365
+ this.treeShape = this.shape.treeShape;
366
+ this.nodeLength = this.treeShape.positions.length;
367
+ this.stride = this.treeShape.valuesPerTopLevelNode;
350
368
  this.fieldKey = dummyRoot;
351
369
  this.moveToPosition(0);
352
370
  }
@@ -377,18 +395,70 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
377
395
 
378
396
  /**
379
397
  * Change the current node within the chunk.
398
+ *
399
+ * @param positionIndex - flat position index of the newly selected node. This is NOT an index
400
+ * within a field, and is not bounds checked.
401
+ *
402
+ * @remarks
403
+ * Decomposes the index into {@link Cursor.topLevelIndex} and {@link Cursor.nodePositionInfo}.
380
404
  * See `nodeInfo` for getting data about the current node.
381
405
  *
382
- * @param positionIndex - index of the position of the newly selected node in `positions`.
383
- * This is NOT an index within a field, and is not bounds checked.
384
406
  */
385
407
  private moveToPosition(positionIndex: number): void {
386
- this.nodePositionInfo = this.positions[positionIndex];
387
408
  this.positionIndex = positionIndex;
388
- if (this.nodePositionInfo === undefined) {
389
- assert(positionIndex === 0, 0x561 /* expected root at start */);
409
+ if (positionIndex === 0) {
410
+ this.nodePositionInfo = undefined;
390
411
  assert(this.mode === CursorLocationType.Fields, 0x562 /* expected root to be a field */);
412
+ return;
391
413
  }
414
+ const decoded = this.decodePosition(positionIndex);
415
+ this.topLevelIndex = decoded.topLevelIndex;
416
+ this.nodePositionInfo = decoded.info;
417
+ }
418
+
419
+ /**
420
+ * Decode a flat `positionIndex` into its components.
421
+ *
422
+ * @param positionIndex - flat position index of the node to decode. Must be greater than 0;
423
+ * @returns the node's index within {@link TreeShape.positions} (`withinTree`), which top-level
424
+ * tree holds it (`topLevelIndex`), and the corresponding shared {@link NodePositionInfo} (`info`).
425
+ */
426
+ private decodePosition(positionIndex: number): {
427
+ withinTree: number;
428
+ topLevelIndex: number;
429
+ info: NodePositionInfo;
430
+ } {
431
+ const offset = positionIndex - 1;
432
+ // Find the node's index within treeShape.positions, then which top-level tree holds it.
433
+ const withinTree = offset % this.nodeLength; // remainder
434
+ const topLevelIndex = (offset - withinTree) / this.nodeLength; // quotient
435
+ const info = this.treeShape.positions[withinTree] ?? oob();
436
+ return { withinTree, topLevelIndex, info };
437
+ }
438
+
439
+ /**
440
+ * Build a standalone {@link UpPath} for the node at `positionIndex`. O(depth) allocation.
441
+ *
442
+ * @remarks
443
+ * walks the shared per-tree {@link TreeShape.positions} and applies the top-level index
444
+ * at each level. Mirrors how the `BasicChunk` cursor allocates paths.
445
+ */
446
+ private materializePath(positionIndex: number): UpPath | undefined {
447
+ if (positionIndex === 0) {
448
+ return undefined;
449
+ }
450
+ const { withinTree, topLevelIndex, info } = this.decodePosition(positionIndex);
451
+ if (info.parent === undefined) {
452
+ // Top-level node: its parent is the (prefixed) chunk root.
453
+ return { parent: undefined, parentField: info.parentField, parentIndex: topLevelIndex };
454
+ }
455
+ return {
456
+ parent: this.materializePath(
457
+ positionIndex - withinTree + (info.indexOfParentPosition ?? oob()),
458
+ ),
459
+ parentField: info.parentField,
460
+ parentIndex: info.parentIndex,
461
+ };
392
462
  }
393
463
 
394
464
  /**
@@ -505,36 +575,51 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
505
575
  private enterRootNodeInner(childIndex: number): void {
506
576
  this.mode = CursorLocationType.Nodes;
507
577
  this.fieldKey = undefined;
508
- // 1 for the "undefined" at the beginning of the positions array, then stride by top level tree shape.
509
- this.moveToPosition(1 + childIndex * this.shape.treeShape.positions.length);
578
+ // 1 for the "undefined" root-field marker at position 0, then stride by one top-level tree (nodeLength).
579
+ this.moveToPosition(1 + childIndex * this.nodeLength);
510
580
  assert(this.fieldIndex === childIndex, 0x543 /* should be at selected child */);
511
581
  }
512
582
 
513
583
  public getFieldPath(prefix?: PathRootPrefix): FieldUpPath {
514
584
  return prefixFieldPath(prefix, {
515
585
  field: this.getFieldKey(),
516
- parent: this.nodePositionInfo,
586
+ parent: this.materializePath(this.positionIndex),
517
587
  });
518
588
  }
519
589
 
520
590
  public getPath(prefix?: PathRootPrefix): UpPath | undefined {
521
- return prefixPath(prefix, this.nodeInfo(CursorLocationType.Nodes));
591
+ this.nodeInfo(CursorLocationType.Nodes); // assert: in nodes mode at a node
592
+ return prefixPath(prefix, this.materializePath(this.positionIndex));
522
593
  }
523
594
 
524
595
  public get fieldIndex(): number {
525
- return this.nodeInfo(CursorLocationType.Nodes).parentIndex;
596
+ const info = this.nodeInfo(CursorLocationType.Nodes);
597
+ return info.parent === undefined ? this.topLevelIndex : info.parentIndex;
526
598
  }
527
599
 
528
600
  public readonly chunkStart: number = 0;
529
601
 
602
+ /**
603
+ * Number of nodes in `info`'s field including `info` itself.
604
+ *
605
+ * @remarks
606
+ * For top-level nodes this is the chunk's `topLevelLength`, read from the chunk
607
+ * rather than the node, so the shared per-tree {@link TreeShape.positions} stays independent of
608
+ * chunk length; the root entry's own `topLevelLength` field is unused. Nested nodes use the
609
+ * field length stored on the node.
610
+ */
611
+ private siblingCount(info: NodePositionInfo): number {
612
+ return info.parent === undefined ? this.shape.topLevelLength : info.topLevelLength;
613
+ }
614
+
530
615
  public get chunkLength(): number {
531
- return this.nodeInfo(CursorLocationType.Nodes).topLevelLength;
616
+ return this.siblingCount(this.nodeInfo(CursorLocationType.Nodes));
532
617
  }
533
618
 
534
619
  public seekNodes(offset: number): boolean {
535
620
  const info = this.nodeInfo(CursorLocationType.Nodes);
536
- const index = offset + info.parentIndex;
537
- if (index >= 0 && index < info.topLevelLength) {
621
+ const index = offset + this.fieldIndex;
622
+ if (index >= 0 && index < this.siblingCount(info)) {
538
623
  this.moveToPosition(this.positionIndex + offset * info.shape.positions.length);
539
624
  return true;
540
625
  }
@@ -546,8 +631,8 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
546
631
  // This is the same as `return this.seekNodes(1);` but slightly faster.
547
632
 
548
633
  const info = this.nodeInfo(CursorLocationType.Nodes);
549
- const index = info.parentIndex + 1;
550
- if (index === info.topLevelLength) {
634
+ const index = this.fieldIndex + 1;
635
+ if (index === this.siblingCount(info)) {
551
636
  this.exitNode();
552
637
  return false;
553
638
  }
@@ -557,15 +642,17 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
557
642
 
558
643
  public exitNode(): void {
559
644
  const info = this.nodeInfo(CursorLocationType.Nodes);
560
- this.indexOfField =
561
- info.indexOfParentField ??
562
- fail(0xb0a /* navigation up to root field not yet supported */); // TODO;
645
+ const withinTree = this.positionIndex - 1 - this.topLevelIndex * this.nodeLength;
646
+ // Top-level nodes (no parent) exit to the root field at position 0;
647
+ // nested nodes' parent is `indexOfParentPosition` within the same top-level instance.
648
+ this.indexOfField = info.indexOfParentField ?? 0;
563
649
  this.fieldKey = info.parentField;
564
650
  this.mode = CursorLocationType.Fields;
565
651
  this.moveToPosition(
566
- info.indexOfParentPosition ??
567
- fail(0xb0b /* navigation up to root field not yet supported */),
568
- ); // TODO
652
+ info.indexOfParentPosition === undefined
653
+ ? 0
654
+ : this.positionIndex - withinTree + info.indexOfParentPosition,
655
+ );
569
656
  }
570
657
 
571
658
  public firstField(): boolean {
@@ -598,7 +685,7 @@ class Cursor extends SynchronousCursor implements ChunkedCursor {
598
685
  public get value(): Value {
599
686
  const info = this.nodeInfo(CursorLocationType.Nodes);
600
687
  if (info.shape.hasValue) {
601
- const value = this.chunk.values[info.valueOffset];
688
+ const value = this.chunk.values[info.valueOffset + this.topLevelIndex * this.stride];
602
689
  // If mayContainCompressedIds is set, check if the value is a number (i.e. a compressed ID that needs decompression).
603
690
  if (info.shape.mayContainCompressedIds && typeof value === "number") {
604
691
  const idCompressor = this.chunk.idCompressor;
@@ -316,6 +316,7 @@ export class DefaultEditBuilder implements ChangeFamilyEditor, IDefaultEditBuild
316
316
  const detachCellId = this.modularBuilder.generateId(count);
317
317
  const attachCellId: CellId = { localId: this.modularBuilder.generateId(count), revision };
318
318
  if (compareFieldUpPaths(sourceField, destinationField)) {
319
+ // The source and destination fields are the same.
319
320
  const change = sequence.changeHandler.editor.move(
320
321
  sourceIndex,
321
322
  count,
@@ -331,32 +332,53 @@ export class DefaultEditBuilder implements ChangeFamilyEditor, IDefaultEditBuild
331
332
  revision,
332
333
  );
333
334
  } else {
335
+ // The source and destination fields are different.
334
336
  const detachPath = topDownPath(sourceField.parent);
335
337
  const attachPath = topDownPath(destinationField.parent);
338
+ /**
339
+ * The number of elements, starting from the root, that both paths have in common.
340
+ * This defines the lowest common ancestor node (LCA) of the source and destination fields.
341
+ */
336
342
  const sharedDepth = getSharedPrefixLength(detachPath, attachPath);
337
343
  let adjustedAttachField = destinationField;
338
- // After the above loop, `sharedDepth` is the number of elements, starting from the root,
339
- // that both paths have in common.
344
+ // Check if the detach parent
345
+ // (the node directly above the location of detach)
346
+ // is along the attach path,
347
+ // in which case the attach path might need to be adjusted.
348
+ // This is synonymous with checking if the attach parent
349
+ // (the node directly above the location of attach)
350
+ // is either below or the same as the detach parent.
351
+ // If not, then the move does not need to be adjusted
352
+ // as the attach path will not be affected by the detach.
340
353
  if (sharedDepth === detachPath.length) {
341
- const attachField = attachPath[sharedDepth]?.parentField ?? destinationField.field;
342
- if (attachField === sourceField.field) {
343
- // The detach occurs in an ancestor field of the field where the attach occurs.
344
- let attachAncestorIndex = attachPath[sharedDepth]?.parentIndex ?? sourceIndex;
345
- if (attachAncestorIndex < sourceIndex) {
354
+ const fieldOnDetachPathUnderLCA = sourceField.field;
355
+ const firstDifferentAttachAncestor = attachPath[sharedDepth];
356
+ // Check if the detach location uses the same field as in
357
+ // the attach path.
358
+ // Note that when `firstDifferentAttachAncestor` is undefined,
359
+ // that means the parents are the same. Since earlier call
360
+ // to `compareFieldUpPaths` returned false, we know that the
361
+ // fields must be different AND thus no adjustment is needed.
362
+ if (fieldOnDetachPathUnderLCA === firstDifferentAttachAncestor?.parentField) {
363
+ // Now working at the level where detach happens along the
364
+ // attach path.
365
+ if (firstDifferentAttachAncestor.parentIndex < sourceIndex) {
346
366
  // The attach path runs through a node located before the detached nodes.
347
367
  // No need to adjust the attach path.
348
- } else if (sourceIndex + count <= attachAncestorIndex) {
368
+ } else if (sourceIndex + count <= firstDifferentAttachAncestor.parentIndex) {
349
369
  // The attach path runs through a node located after the detached nodes.
350
- // adjust the index for the node at that depth of the path, so that it is interpreted correctly
370
+ // Adjust the index for the node at that depth of the path, so that it is interpreted correctly
351
371
  // in the composition performed by `submitChanges`.
352
- attachAncestorIndex -= count;
353
- let parent: UpPath | undefined = attachPath[sharedDepth - 1];
354
- const parentField = attachPath[sharedDepth] ?? oob();
372
+ // Start with path to root that remains intact.
373
+ let parent = firstDifferentAttachAncestor.parent;
374
+ // Extend with index-adjusted parent.
355
375
  parent = {
356
376
  parent,
357
- parentIndex: attachAncestorIndex,
358
- parentField: parentField.parentField,
377
+ parentIndex: firstDifferentAttachAncestor.parentIndex - count,
378
+ parentField: firstDifferentAttachAncestor.parentField,
359
379
  };
380
+ // Extend with the rest of the attach path, which is unaffected
381
+ // apart from parentage replacements.
360
382
  for (let i = sharedDepth + 1; i < attachPath.length; i += 1) {
361
383
  parent = {
362
384
  ...(attachPath[i] ?? oob()),
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type Static, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { Static } from "@sinclair/typebox";
7
8
 
8
9
  import { versionField } from "../../codec/index.js";
9
10
  import { schemaFormatV1 } from "../../core/index.js";
@@ -6,7 +6,8 @@
6
6
  // Many of the return types in this module are intentionally derived, rather than explicitly specified.
7
7
  /* eslint-disable @typescript-eslint/explicit-function-return-type */
8
8
 
9
- import { type Static, type TAnySchema, type TSchema, Type } from "@sinclair/typebox";
9
+ import * as Type from "@sinclair/typebox";
10
+ import type { Static, TAnySchema, TSchema } from "@sinclair/typebox";
10
11
 
11
12
  export const EncodedGenericChange = <NodeChangesetSchema extends TSchema>(
12
13
  tNodeChangeset: NodeChangesetSchema,
@@ -782,6 +782,14 @@ export class ModularChangeFamily
782
782
 
783
783
  const crossFieldKeys = this.makeCrossFieldKeyTable(invertedFields, invertedNodes);
784
784
 
785
+ const constraintState = newConstraintState(0);
786
+ this.updateConstraintsForFields(
787
+ invertedFields,
788
+ NodeAttachState.Attached,
789
+ constraintState,
790
+ invertedNodes,
791
+ );
792
+
785
793
  return makeModularChangeset({
786
794
  fieldChanges: invertedFields,
787
795
  nodeChanges: invertedNodes,
@@ -790,8 +798,7 @@ export class ModularChangeFamily
790
798
  crossFieldKeys,
791
799
  maxId: genId.getMaxId(),
792
800
  revisions: revInfos,
793
- constraintViolationCount: change.change.constraintViolationCountOnRevert,
794
- constraintViolationCountOnRevert: change.change.constraintViolationCount,
801
+ constraintViolationCount: constraintState.violationCount,
795
802
  noChangeConstraint,
796
803
  noChangeConstraintOnRevert,
797
804
  destroys,
@@ -939,9 +946,6 @@ export class ModularChangeFamily
939
946
  );
940
947
 
941
948
  const constraintState = newConstraintState(change.constraintViolationCount ?? 0);
942
- const revertConstraintState = newConstraintState(
943
- change.constraintViolationCountOnRevert ?? 0,
944
- );
945
949
 
946
950
  let noChangeConstraint = change.noChangeConstraint;
947
951
  if (
@@ -956,9 +960,7 @@ export class ModularChangeFamily
956
960
  this.updateConstraintsForFields(
957
961
  rebasedFields,
958
962
  NodeAttachState.Attached,
959
- NodeAttachState.Attached,
960
963
  constraintState,
961
- revertConstraintState,
962
964
  rebasedNodes,
963
965
  );
964
966
 
@@ -971,7 +973,6 @@ export class ModularChangeFamily
971
973
  maxId: idState.maxId,
972
974
  revisions: change.revisions,
973
975
  constraintViolationCount: constraintState.violationCount,
974
- constraintViolationCountOnRevert: revertConstraintState.violationCount,
975
976
  noChangeConstraint,
976
977
  noChangeConstraintOnRevert: change.noChangeConstraintOnRevert,
977
978
  builds: change.builds,
@@ -1410,32 +1411,21 @@ export class ModularChangeFamily
1410
1411
  private updateConstraintsForFields(
1411
1412
  fields: FieldChangeMap,
1412
1413
  parentInputAttachState: NodeAttachState,
1413
- parentOutputAttachState: NodeAttachState,
1414
1414
  constraintState: ConstraintState,
1415
- revertConstraintState: ConstraintState,
1416
1415
  nodes: ChangeAtomIdBTree<NodeChangeset>,
1417
1416
  ): void {
1418
1417
  for (const field of fields.values()) {
1419
1418
  const handler = getChangeHandler(this.fieldKinds, field.fieldKind);
1420
- for (const [nodeId, inputIndex, outputIndex] of handler.getNestedChanges(field.change)) {
1419
+ for (const [nodeId, inputIndex, _outputIndex] of handler.getNestedChanges(
1420
+ field.change,
1421
+ )) {
1421
1422
  const isInputDetached = inputIndex === undefined;
1422
1423
  const inputAttachState =
1423
1424
  parentInputAttachState === NodeAttachState.Detached || isInputDetached
1424
1425
  ? NodeAttachState.Detached
1425
1426
  : NodeAttachState.Attached;
1426
- const isOutputDetached = outputIndex === undefined;
1427
- const outputAttachState =
1428
- parentOutputAttachState === NodeAttachState.Detached || isOutputDetached
1429
- ? NodeAttachState.Detached
1430
- : NodeAttachState.Attached;
1431
- this.updateConstraintsForNode(
1432
- nodeId,
1433
- inputAttachState,
1434
- outputAttachState,
1435
- nodes,
1436
- constraintState,
1437
- revertConstraintState,
1438
- );
1427
+
1428
+ this.updateConstraintsForNode(nodeId, inputAttachState, nodes, constraintState);
1439
1429
  }
1440
1430
  }
1441
1431
  }
@@ -1443,10 +1433,8 @@ export class ModularChangeFamily
1443
1433
  private updateConstraintsForNode(
1444
1434
  nodeId: NodeId,
1445
1435
  inputAttachState: NodeAttachState,
1446
- outputAttachState: NodeAttachState,
1447
1436
  nodes: ChangeAtomIdBTree<NodeChangeset>,
1448
1437
  constraintState: ConstraintState,
1449
- revertConstraintState: ConstraintState,
1450
1438
  ): void {
1451
1439
  const node =
1452
1440
  nodes.get([nodeId.revision, nodeId.localId]) ?? fail(0xb24 /* Unknown node ID */);
@@ -1460,24 +1448,12 @@ export class ModularChangeFamily
1460
1448
  constraintState.violationCount += isNowViolated ? 1 : -1;
1461
1449
  }
1462
1450
  }
1463
- if (node.nodeExistsConstraintOnRevert !== undefined) {
1464
- const isNowViolated = outputAttachState === NodeAttachState.Detached;
1465
- if (node.nodeExistsConstraintOnRevert.violated !== isNowViolated) {
1466
- node.nodeExistsConstraintOnRevert = {
1467
- ...node.nodeExistsConstraintOnRevert,
1468
- violated: isNowViolated,
1469
- };
1470
- revertConstraintState.violationCount += isNowViolated ? 1 : -1;
1471
- }
1472
- }
1473
1451
 
1474
1452
  if (node.fieldChanges !== undefined) {
1475
1453
  this.updateConstraintsForFields(
1476
1454
  node.fieldChanges,
1477
1455
  inputAttachState,
1478
- outputAttachState,
1479
1456
  constraintState,
1480
- revertConstraintState,
1481
1457
  nodes,
1482
1458
  );
1483
1459
  }
@@ -2003,7 +1979,6 @@ export function updateRefreshers(
2003
1979
  maxId,
2004
1980
  revisions,
2005
1981
  constraintViolationCount,
2006
- constraintViolationCountOnRevert,
2007
1982
  builds,
2008
1983
  destroys,
2009
1984
  } = change;
@@ -2017,7 +1992,6 @@ export function updateRefreshers(
2017
1992
  maxId: maxId as number,
2018
1993
  revisions,
2019
1994
  constraintViolationCount,
2020
- constraintViolationCountOnRevert,
2021
1995
  builds,
2022
1996
  destroys,
2023
1997
  refreshers,
@@ -2632,7 +2606,6 @@ function makeModularChangeset(props?: {
2632
2606
  maxId: number;
2633
2607
  revisions?: readonly RevisionInfo[];
2634
2608
  constraintViolationCount?: number;
2635
- constraintViolationCountOnRevert?: number;
2636
2609
  noChangeConstraint?: NoChangeConstraint;
2637
2610
  noChangeConstraintOnRevert?: NoChangeConstraint;
2638
2611
  builds?: ChangeAtomIdBTree<TreeChunk>;
@@ -2657,12 +2630,6 @@ function makeModularChangeset(props?: {
2657
2630
  if (p.constraintViolationCount !== undefined && p.constraintViolationCount > 0) {
2658
2631
  changeset.constraintViolationCount = p.constraintViolationCount;
2659
2632
  }
2660
- if (
2661
- p.constraintViolationCountOnRevert !== undefined &&
2662
- p.constraintViolationCountOnRevert > 0
2663
- ) {
2664
- changeset.constraintViolationCountOnRevert = p.constraintViolationCountOnRevert;
2665
- }
2666
2633
  if (p.noChangeConstraint !== undefined) {
2667
2634
  changeset.noChangeConstraint = p.noChangeConstraint;
2668
2635
  }
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type ObjectOptions, type Static, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { ObjectOptions, Static } from "@sinclair/typebox";
7
8
 
8
9
  import { type ChangesetLocalId, RevisionTagSchema, schemaFormatV1 } from "../../core/index.js";
9
10
  import {
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type ObjectOptions, type Static, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { ObjectOptions, Static } from "@sinclair/typebox";
7
8
 
8
9
  import { EncodedModularChangesetV1 } from "./modularChangeFormatV1.js";
9
10
 
@@ -64,11 +64,6 @@ export interface ModularChangeset extends Readonly<HasFieldChanges> {
64
64
  readonly noChangeConstraint?: NoChangeConstraint;
65
65
  /** Constraint that the document must be in the same state before the revert of this change is applied as it was after this change was applied */
66
66
  readonly noChangeConstraintOnRevert?: NoChangeConstraint;
67
- /**
68
- * The number of constraint violations that apply to the revert of the changeset. If this count is greater than 0, it will
69
- * prevent the changeset from being reverted or undone.
70
- */
71
- readonly constraintViolationCountOnRevert?: number;
72
67
  readonly builds?: ChangeAtomIdBTree<TreeChunk>;
73
68
  readonly destroys?: ChangeAtomIdBTree<number>;
74
69
  readonly refreshers?: ChangeAtomIdBTree<TreeChunk>;
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type ObjectOptions, type Static, type TSchema, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { ObjectOptions, Static, TSchema } from "@sinclair/typebox";
7
8
 
8
9
  import { EncodedChangeAtomId } from "../modular-schema/index.js";
9
10
 
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type ObjectOptions, type Static, type TSchema, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { ObjectOptions, Static, TSchema } from "@sinclair/typebox";
7
8
 
8
9
  import { EncodedChangeAtomId } from "../modular-schema/index.js";
9
10
 
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type Static, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { Static } from "@sinclair/typebox";
7
8
 
8
9
  import { JsonCompatibleReadOnlySchema } from "../../util/index.js";
9
10
 
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type ObjectOptions, type Static, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { ObjectOptions, Static } from "@sinclair/typebox";
7
8
 
8
9
  import { SchemaFormatVersion, schemaFormatV1 } from "../../core/index.js";
9
10
 
@@ -3,7 +3,8 @@
3
3
  * Licensed under the MIT License.
4
4
  */
5
5
 
6
- import { type ObjectOptions, type Static, Type } from "@sinclair/typebox";
6
+ import * as Type from "@sinclair/typebox";
7
+ import type { ObjectOptions, Static } from "@sinclair/typebox";
7
8
 
8
9
  import { SchemaFormatVersion, schemaFormatV2 } from "../../core/index.js";
9
10
 
@@ -473,6 +473,7 @@ function handleNodeChanges(
473
473
  moveEffects: MoveEffectTable,
474
474
  ): NodeId | undefined {
475
475
  if (newMark.changes !== undefined) {
476
+ moveEffects.onMoveIn(newMark.changes);
476
477
  const baseSource = getMoveIn(baseMark);
477
478
 
478
479
  // TODO: Make sure composeChild is not called twice on the node changes.
@@ -589,10 +590,6 @@ export class ComposeQueue {
589
590
  private dequeueBase(length: number = Number.POSITIVE_INFINITY): ComposeMarks {
590
591
  const baseMark = this.baseMarks.dequeueUpTo(length);
591
592
  const movedChanges = getMovedChangesFromMark(this.moveEffects, baseMark);
592
- if (movedChanges !== undefined) {
593
- this.moveEffects.onMoveIn(movedChanges);
594
- }
595
-
596
593
  const newMark = createNoopMark(baseMark.count, movedChanges, getOutputCellId(baseMark));
597
594
  return { baseMark, newMark };
598
595
  }