@fluidframework/tree 2.74.0-370705 → 2.80.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (1421) hide show
  1. package/.eslintrc.cjs +1 -16
  2. package/.vscode/settings.json +2 -0
  3. package/CHANGELOG.md +29 -0
  4. package/api-report/tree.alpha.api.md +39 -17
  5. package/assertTagging.config.mjs +1 -1
  6. package/dist/alpha.d.ts +7 -0
  7. package/dist/codec/codec.d.ts +63 -20
  8. package/dist/codec/codec.d.ts.map +1 -1
  9. package/dist/codec/codec.js +50 -24
  10. package/dist/codec/codec.js.map +1 -1
  11. package/dist/codec/index.d.ts +2 -2
  12. package/dist/codec/index.d.ts.map +1 -1
  13. package/dist/codec/index.js +2 -2
  14. package/dist/codec/index.js.map +1 -1
  15. package/dist/codec/versioned/codec.d.ts +80 -22
  16. package/dist/codec/versioned/codec.d.ts.map +1 -1
  17. package/dist/codec/versioned/codec.js +137 -15
  18. package/dist/codec/versioned/codec.js.map +1 -1
  19. package/dist/codec/versioned/index.d.ts +1 -1
  20. package/dist/codec/versioned/index.d.ts.map +1 -1
  21. package/dist/codec/versioned/index.js +2 -2
  22. package/dist/codec/versioned/index.js.map +1 -1
  23. package/dist/core/change-family/changeFamily.d.ts +1 -4
  24. package/dist/core/change-family/changeFamily.d.ts.map +1 -1
  25. package/dist/core/change-family/changeFamily.js.map +1 -1
  26. package/dist/core/change-family/index.d.ts +1 -1
  27. package/dist/core/change-family/index.d.ts.map +1 -1
  28. package/dist/core/change-family/index.js.map +1 -1
  29. package/dist/core/index.d.ts +3 -3
  30. package/dist/core/index.d.ts.map +1 -1
  31. package/dist/core/index.js +5 -8
  32. package/dist/core/index.js.map +1 -1
  33. package/dist/core/rebase/changeRebaser.d.ts +37 -8
  34. package/dist/core/rebase/changeRebaser.d.ts.map +1 -1
  35. package/dist/core/rebase/changeRebaser.js.map +1 -1
  36. package/dist/core/rebase/index.d.ts +2 -2
  37. package/dist/core/rebase/index.d.ts.map +1 -1
  38. package/dist/core/rebase/index.js +1 -3
  39. package/dist/core/rebase/index.js.map +1 -1
  40. package/dist/core/rebase/types.d.ts +27 -5
  41. package/dist/core/rebase/types.d.ts.map +1 -1
  42. package/dist/core/rebase/types.js +1 -16
  43. package/dist/core/rebase/types.js.map +1 -1
  44. package/dist/core/rebase/utils.d.ts.map +1 -1
  45. package/dist/core/rebase/utils.js +10 -28
  46. package/dist/core/rebase/utils.js.map +1 -1
  47. package/dist/core/schema-stored/schema.d.ts +4 -7
  48. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  49. package/dist/core/schema-stored/schema.js +5 -5
  50. package/dist/core/schema-stored/schema.js.map +1 -1
  51. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  52. package/dist/core/tree/anchorSet.js +3 -4
  53. package/dist/core/tree/anchorSet.js.map +1 -1
  54. package/dist/core/tree/detachedFieldIndex.d.ts +1 -8
  55. package/dist/core/tree/detachedFieldIndex.d.ts.map +1 -1
  56. package/dist/core/tree/detachedFieldIndex.js +12 -65
  57. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  58. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts +18 -10
  59. package/dist/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -1
  60. package/dist/core/tree/detachedFieldIndexCodecCommon.js +6 -6
  61. package/dist/core/tree/detachedFieldIndexCodecCommon.js.map +1 -1
  62. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts +2 -3
  63. package/dist/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  64. package/dist/core/tree/detachedFieldIndexCodecV1.js +4 -5
  65. package/dist/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  66. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts +2 -3
  67. package/dist/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  68. package/dist/core/tree/detachedFieldIndexCodecV2.js +4 -6
  69. package/dist/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  70. package/dist/core/tree/detachedFieldIndexCodecs.d.ts +5 -6
  71. package/dist/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  72. package/dist/core/tree/detachedFieldIndexCodecs.js +11 -41
  73. package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  74. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts +4 -4
  75. package/dist/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -1
  76. package/dist/core/tree/detachedFieldIndexFormatCommon.js +2 -2
  77. package/dist/core/tree/detachedFieldIndexFormatCommon.js.map +1 -1
  78. package/dist/core/tree/index.d.ts +2 -2
  79. package/dist/core/tree/index.d.ts.map +1 -1
  80. package/dist/core/tree/index.js +4 -5
  81. package/dist/core/tree/index.js.map +1 -1
  82. package/dist/core/tree/mapTree.js +1 -1
  83. package/dist/core/tree/mapTree.js.map +1 -1
  84. package/dist/core/tree/pathTree.d.ts +3 -11
  85. package/dist/core/tree/pathTree.d.ts.map +1 -1
  86. package/dist/core/tree/pathTree.js +2 -14
  87. package/dist/core/tree/pathTree.js.map +1 -1
  88. package/dist/core/tree/sparseTree.d.ts.map +1 -1
  89. package/dist/core/tree/sparseTree.js +1 -0
  90. package/dist/core/tree/sparseTree.js.map +1 -1
  91. package/dist/core/tree/treeTextFormat.d.ts.map +1 -1
  92. package/dist/core/tree/treeTextFormat.js +5 -9
  93. package/dist/core/tree/treeTextFormat.js.map +1 -1
  94. package/dist/feature-libraries/changeAtomIdBTree.d.ts +10 -0
  95. package/dist/feature-libraries/changeAtomIdBTree.d.ts.map +1 -0
  96. package/dist/feature-libraries/changeAtomIdBTree.js +16 -0
  97. package/dist/feature-libraries/changeAtomIdBTree.js.map +1 -0
  98. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  99. package/dist/feature-libraries/chunked-forest/basicChunk.js +1 -8
  100. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  101. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  102. package/dist/feature-libraries/chunked-forest/chunkTree.js +1 -4
  103. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  104. package/dist/feature-libraries/chunked-forest/chunkedForest.js +6 -6
  105. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  106. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  107. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js +7 -4
  108. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  109. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  110. package/dist/feature-libraries/chunked-forest/codec/codecs.js +19 -11
  111. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  112. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js +3 -3
  113. package/dist/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  114. package/dist/feature-libraries/chunked-forest/codec/format.d.ts +5 -5
  115. package/dist/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  116. package/dist/feature-libraries/chunked-forest/codec/format.js +4 -4
  117. package/dist/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  118. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +9 -5
  119. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  120. package/dist/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  121. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  122. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts +54 -93
  123. package/dist/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  124. package/dist/feature-libraries/default-schema/defaultEditBuilder.js +81 -245
  125. package/dist/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  126. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -1
  127. package/dist/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  128. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +6 -5
  129. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  130. package/dist/feature-libraries/default-schema/index.d.ts +1 -2
  131. package/dist/feature-libraries/default-schema/index.d.ts.map +1 -1
  132. package/dist/feature-libraries/default-schema/index.js +2 -5
  133. package/dist/feature-libraries/default-schema/index.js.map +1 -1
  134. package/dist/feature-libraries/default-schema/mappedEditBuilder.d.ts +8 -7
  135. package/dist/feature-libraries/default-schema/mappedEditBuilder.d.ts.map +1 -1
  136. package/dist/feature-libraries/default-schema/mappedEditBuilder.js +6 -15
  137. package/dist/feature-libraries/default-schema/mappedEditBuilder.js.map +1 -1
  138. package/dist/feature-libraries/deltaUtils.d.ts +0 -1
  139. package/dist/feature-libraries/deltaUtils.d.ts.map +1 -1
  140. package/dist/feature-libraries/deltaUtils.js +1 -6
  141. package/dist/feature-libraries/deltaUtils.js.map +1 -1
  142. package/dist/feature-libraries/flex-tree/context.d.ts +0 -9
  143. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  144. package/dist/feature-libraries/flex-tree/context.js +0 -6
  145. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  146. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +6 -6
  147. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  148. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  149. package/dist/feature-libraries/flex-tree/lazyField.d.ts +7 -8
  150. package/dist/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  151. package/dist/feature-libraries/flex-tree/lazyField.js +16 -47
  152. package/dist/feature-libraries/flex-tree/lazyField.js.map +1 -1
  153. package/dist/feature-libraries/forest-summary/codec.d.ts +8 -2
  154. package/dist/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  155. package/dist/feature-libraries/forest-summary/codec.js +13 -11
  156. package/dist/feature-libraries/forest-summary/codec.js.map +1 -1
  157. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +3 -2
  158. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  159. package/dist/feature-libraries/forest-summary/forestSummarizer.js +18 -9
  160. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  161. package/dist/feature-libraries/forest-summary/formatCommon.d.ts +61 -0
  162. package/dist/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -0
  163. package/dist/feature-libraries/forest-summary/{format.js → formatCommon.js} +9 -6
  164. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -0
  165. package/dist/feature-libraries/forest-summary/{format.d.ts → formatV1.d.ts} +6 -14
  166. package/dist/feature-libraries/forest-summary/formatV1.d.ts.map +1 -0
  167. package/dist/feature-libraries/forest-summary/formatV1.js +11 -0
  168. package/dist/feature-libraries/forest-summary/formatV1.js.map +1 -0
  169. package/dist/feature-libraries/forest-summary/formatV2.d.ts +51 -0
  170. package/dist/feature-libraries/forest-summary/formatV2.d.ts.map +1 -0
  171. package/dist/feature-libraries/forest-summary/formatV2.js +11 -0
  172. package/dist/feature-libraries/forest-summary/formatV2.js.map +1 -0
  173. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +7 -15
  174. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  175. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +11 -20
  176. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  177. package/dist/feature-libraries/forest-summary/index.d.ts +1 -2
  178. package/dist/feature-libraries/forest-summary/index.d.ts.map +1 -1
  179. package/dist/feature-libraries/forest-summary/index.js +3 -5
  180. package/dist/feature-libraries/forest-summary/index.js.map +1 -1
  181. package/dist/feature-libraries/forest-summary/summaryFormatCommon.d.ts +35 -0
  182. package/dist/feature-libraries/forest-summary/summaryFormatCommon.d.ts.map +1 -0
  183. package/dist/feature-libraries/forest-summary/summaryFormatCommon.js +43 -0
  184. package/dist/feature-libraries/forest-summary/summaryFormatCommon.js.map +1 -0
  185. package/dist/feature-libraries/forest-summary/summaryFormatV1ToV2.d.ts +11 -0
  186. package/dist/feature-libraries/forest-summary/summaryFormatV1ToV2.d.ts.map +1 -0
  187. package/dist/feature-libraries/forest-summary/summaryFormatV1ToV2.js +14 -0
  188. package/dist/feature-libraries/forest-summary/summaryFormatV1ToV2.js.map +1 -0
  189. package/dist/feature-libraries/forest-summary/summaryFormatV3.d.ts +18 -0
  190. package/dist/feature-libraries/forest-summary/summaryFormatV3.d.ts.map +1 -0
  191. package/dist/feature-libraries/forest-summary/summaryFormatV3.js +21 -0
  192. package/dist/feature-libraries/forest-summary/summaryFormatV3.js.map +1 -0
  193. package/dist/feature-libraries/forest-summary/summaryTypes.d.ts +7 -37
  194. package/dist/feature-libraries/forest-summary/summaryTypes.d.ts.map +1 -1
  195. package/dist/feature-libraries/forest-summary/summaryTypes.js +23 -45
  196. package/dist/feature-libraries/forest-summary/summaryTypes.js.map +1 -1
  197. package/dist/feature-libraries/index.d.ts +5 -4
  198. package/dist/feature-libraries/index.d.ts.map +1 -1
  199. package/dist/feature-libraries/index.js +10 -12
  200. package/dist/feature-libraries/index.js.map +1 -1
  201. package/dist/feature-libraries/indexing/anchorTreeIndex.js +6 -6
  202. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  203. package/dist/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  204. package/dist/feature-libraries/mapTreeCursor.js +0 -1
  205. package/dist/feature-libraries/mapTreeCursor.js.map +1 -1
  206. package/dist/feature-libraries/mitigatedChangeFamily.d.ts.map +1 -1
  207. package/dist/feature-libraries/mitigatedChangeFamily.js +12 -3
  208. package/dist/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  209. package/dist/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  210. package/dist/feature-libraries/modular-schema/comparison.js +13 -10
  211. package/dist/feature-libraries/modular-schema/comparison.js.map +1 -1
  212. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts +21 -97
  213. package/dist/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  214. package/dist/feature-libraries/modular-schema/crossFieldQueries.js +7 -4
  215. package/dist/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  216. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +25 -0
  217. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -0
  218. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js +59 -0
  219. package/dist/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -0
  220. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts +52 -20
  221. package/dist/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  222. package/dist/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  223. package/dist/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  224. package/dist/feature-libraries/modular-schema/genericFieldKind.js +13 -7
  225. package/dist/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  226. package/dist/feature-libraries/modular-schema/index.d.ts +7 -5
  227. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  228. package/dist/feature-libraries/modular-schema/index.js +7 -7
  229. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  230. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +41 -9
  231. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  232. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js +263 -336
  233. package/dist/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  234. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.d.ts +7 -9
  235. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.d.ts.map +1 -1
  236. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js +8 -390
  237. package/dist/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -1
  238. package/dist/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  239. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js +24 -11
  240. package/dist/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  241. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts +27 -55
  242. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  243. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +622 -1433
  244. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  245. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +3 -4
  246. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  247. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js +4 -4
  248. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  249. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +14 -48
  250. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  251. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js +10 -21
  252. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -1
  253. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +18 -48
  254. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  255. package/dist/feature-libraries/modular-schema/modularChangeTypes.js +3 -24
  256. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  257. package/dist/feature-libraries/node-identifier/mockNodeIdentifierManager.js +1 -1
  258. package/dist/feature-libraries/node-identifier/mockNodeIdentifierManager.js.map +1 -1
  259. package/dist/feature-libraries/object-forest/objectForest.js +4 -4
  260. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  261. package/dist/feature-libraries/optional-field/index.d.ts +2 -2
  262. package/dist/feature-libraries/optional-field/index.d.ts.map +1 -1
  263. package/dist/feature-libraries/optional-field/index.js +2 -1
  264. package/dist/feature-libraries/optional-field/index.js.map +1 -1
  265. package/dist/feature-libraries/optional-field/optionalField.d.ts +26 -5
  266. package/dist/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  267. package/dist/feature-libraries/optional-field/optionalField.js +447 -218
  268. package/dist/feature-libraries/optional-field/optionalField.js.map +1 -1
  269. package/dist/feature-libraries/optional-field/optionalFieldChangeTypes.d.ts +33 -24
  270. package/dist/feature-libraries/optional-field/optionalFieldChangeTypes.d.ts.map +1 -1
  271. package/dist/feature-libraries/optional-field/optionalFieldChangeTypes.js.map +1 -1
  272. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.d.ts +1 -1
  273. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.d.ts.map +1 -1
  274. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.js +28 -57
  275. package/dist/feature-libraries/optional-field/optionalFieldCodecV2.js.map +1 -1
  276. package/dist/feature-libraries/optional-field/optionalFieldCodecs.d.ts.map +1 -1
  277. package/dist/feature-libraries/optional-field/optionalFieldCodecs.js +1 -5
  278. package/dist/feature-libraries/optional-field/optionalFieldCodecs.js.map +1 -1
  279. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  280. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js +15 -4
  281. package/dist/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  282. package/dist/feature-libraries/schema-index/codec.d.ts +7 -21
  283. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  284. package/dist/feature-libraries/schema-index/codec.js +28 -70
  285. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  286. package/dist/feature-libraries/schema-index/formatV1.d.ts +1 -1
  287. package/dist/feature-libraries/schema-index/formatV2.d.ts +1 -1
  288. package/dist/feature-libraries/schema-index/index.d.ts +2 -2
  289. package/dist/feature-libraries/schema-index/index.d.ts.map +1 -1
  290. package/dist/feature-libraries/schema-index/index.js +2 -5
  291. package/dist/feature-libraries/schema-index/index.js.map +1 -1
  292. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts +1 -9
  293. package/dist/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  294. package/dist/feature-libraries/schema-index/schemaSummarizer.js +1 -12
  295. package/dist/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  296. package/dist/feature-libraries/schemaChecker.d.ts.map +1 -1
  297. package/dist/feature-libraries/schemaChecker.js +11 -6
  298. package/dist/feature-libraries/schemaChecker.js.map +1 -1
  299. package/dist/feature-libraries/sequence-field/compose.d.ts +7 -6
  300. package/dist/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  301. package/dist/feature-libraries/sequence-field/compose.js +264 -84
  302. package/dist/feature-libraries/sequence-field/compose.js.map +1 -1
  303. package/dist/feature-libraries/sequence-field/helperTypes.d.ts +10 -14
  304. package/dist/feature-libraries/sequence-field/helperTypes.d.ts.map +1 -1
  305. package/dist/feature-libraries/sequence-field/helperTypes.js.map +1 -1
  306. package/dist/feature-libraries/sequence-field/index.d.ts +3 -2
  307. package/dist/feature-libraries/sequence-field/index.d.ts.map +1 -1
  308. package/dist/feature-libraries/sequence-field/index.js +3 -1
  309. package/dist/feature-libraries/sequence-field/index.js.map +1 -1
  310. package/dist/feature-libraries/sequence-field/invert.d.ts +3 -3
  311. package/dist/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  312. package/dist/feature-libraries/sequence-field/invert.js +169 -66
  313. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  314. package/dist/feature-libraries/sequence-field/markQueue.d.ts +2 -2
  315. package/dist/feature-libraries/sequence-field/markQueue.d.ts.map +1 -1
  316. package/dist/feature-libraries/sequence-field/markQueue.js.map +1 -1
  317. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts +56 -4
  318. package/dist/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  319. package/dist/feature-libraries/sequence-field/moveEffectTable.js +93 -8
  320. package/dist/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  321. package/dist/feature-libraries/sequence-field/rebase.d.ts +3 -3
  322. package/dist/feature-libraries/sequence-field/rebase.d.ts.map +1 -1
  323. package/dist/feature-libraries/sequence-field/rebase.js +127 -113
  324. package/dist/feature-libraries/sequence-field/rebase.js.map +1 -1
  325. package/dist/feature-libraries/sequence-field/relevantRemovedRoots.d.ts +9 -0
  326. package/dist/feature-libraries/sequence-field/relevantRemovedRoots.d.ts.map +1 -0
  327. package/dist/feature-libraries/sequence-field/relevantRemovedRoots.js +50 -0
  328. package/dist/feature-libraries/sequence-field/relevantRemovedRoots.js.map +1 -0
  329. package/dist/feature-libraries/sequence-field/replaceRevisions.d.ts +2 -2
  330. package/dist/feature-libraries/sequence-field/replaceRevisions.d.ts.map +1 -1
  331. package/dist/feature-libraries/sequence-field/replaceRevisions.js +49 -27
  332. package/dist/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  333. package/dist/feature-libraries/sequence-field/sequenceFieldChangeHandler.d.ts.map +1 -1
  334. package/dist/feature-libraries/sequence-field/sequenceFieldChangeHandler.js +2 -0
  335. package/dist/feature-libraries/sequence-field/sequenceFieldChangeHandler.js.map +1 -1
  336. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +4 -22
  337. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  338. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js +187 -358
  339. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  340. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  341. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js +62 -20
  342. package/dist/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  343. package/dist/feature-libraries/sequence-field/sequenceFieldEditor.d.ts +2 -2
  344. package/dist/feature-libraries/sequence-field/sequenceFieldEditor.d.ts.map +1 -1
  345. package/dist/feature-libraries/sequence-field/sequenceFieldEditor.js +10 -10
  346. package/dist/feature-libraries/sequence-field/sequenceFieldEditor.js.map +1 -1
  347. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  348. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  349. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +115 -17
  350. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  351. package/dist/feature-libraries/sequence-field/types.d.ts +59 -30
  352. package/dist/feature-libraries/sequence-field/types.d.ts.map +1 -1
  353. package/dist/feature-libraries/sequence-field/types.js.map +1 -1
  354. package/dist/feature-libraries/sequence-field/utils.d.ts +24 -15
  355. package/dist/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  356. package/dist/feature-libraries/sequence-field/utils.js +334 -127
  357. package/dist/feature-libraries/sequence-field/utils.js.map +1 -1
  358. package/dist/feature-libraries/treeCursorUtils.js +7 -7
  359. package/dist/feature-libraries/treeCursorUtils.js.map +1 -1
  360. package/dist/feature-libraries/treeTextCursor.js +2 -2
  361. package/dist/feature-libraries/treeTextCursor.js.map +1 -1
  362. package/dist/feature-libraries/valueUtilities.d.ts.map +1 -1
  363. package/dist/feature-libraries/valueUtilities.js +16 -8
  364. package/dist/feature-libraries/valueUtilities.js.map +1 -1
  365. package/dist/index.d.ts +3 -3
  366. package/dist/index.d.ts.map +1 -1
  367. package/dist/index.js +3 -1
  368. package/dist/index.js.map +1 -1
  369. package/dist/packageVersion.d.ts +1 -1
  370. package/dist/packageVersion.d.ts.map +1 -1
  371. package/dist/packageVersion.js +1 -1
  372. package/dist/packageVersion.js.map +1 -1
  373. package/dist/shared-tree/independentView.d.ts.map +1 -1
  374. package/dist/shared-tree/independentView.js +1 -1
  375. package/dist/shared-tree/independentView.js.map +1 -1
  376. package/dist/shared-tree/index.d.ts +1 -1
  377. package/dist/shared-tree/index.d.ts.map +1 -1
  378. package/dist/shared-tree/index.js.map +1 -1
  379. package/dist/shared-tree/schematizeTree.d.ts +4 -4
  380. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  381. package/dist/shared-tree/schematizeTree.js +1 -2
  382. package/dist/shared-tree/schematizeTree.js.map +1 -1
  383. package/dist/shared-tree/schematizingTreeView.d.ts +9 -5
  384. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  385. package/dist/shared-tree/schematizingTreeView.js +56 -41
  386. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  387. package/dist/shared-tree/sharedTree.d.ts +3 -9
  388. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  389. package/dist/shared-tree/sharedTree.js +57 -50
  390. package/dist/shared-tree/sharedTree.js.map +1 -1
  391. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts +1 -1
  392. package/dist/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  393. package/dist/shared-tree/sharedTreeChangeCodecs.js +11 -11
  394. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  395. package/dist/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  396. package/dist/shared-tree/sharedTreeChangeEnricher.js +5 -3
  397. package/dist/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  398. package/dist/shared-tree/sharedTreeChangeFamily.d.ts +7 -6
  399. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  400. package/dist/shared-tree/sharedTreeChangeFamily.js +23 -24
  401. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  402. package/dist/shared-tree/sharedTreeEditBuilder.d.ts +6 -16
  403. package/dist/shared-tree/sharedTreeEditBuilder.d.ts.map +1 -1
  404. package/dist/shared-tree/sharedTreeEditBuilder.js +7 -14
  405. package/dist/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  406. package/dist/shared-tree/treeAlpha.d.ts +35 -29
  407. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  408. package/dist/shared-tree/treeAlpha.js +21 -23
  409. package/dist/shared-tree/treeAlpha.js.map +1 -1
  410. package/dist/shared-tree/treeCheckout.d.ts +17 -12
  411. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  412. package/dist/shared-tree/treeCheckout.js +85 -66
  413. package/dist/shared-tree/treeCheckout.js.map +1 -1
  414. package/dist/shared-tree-core/branch.d.ts +5 -4
  415. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  416. package/dist/shared-tree-core/branch.js +7 -6
  417. package/dist/shared-tree-core/branch.js.map +1 -1
  418. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  419. package/dist/shared-tree-core/branchCommitEnricher.js +1 -1
  420. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  421. package/dist/shared-tree-core/editManager.d.ts +2 -2
  422. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  423. package/dist/shared-tree-core/editManager.js +10 -10
  424. package/dist/shared-tree-core/editManager.js.map +1 -1
  425. package/dist/shared-tree-core/editManagerCodecs.d.ts +0 -4
  426. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  427. package/dist/shared-tree-core/editManagerCodecs.js +13 -16
  428. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  429. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js +1 -1
  430. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  431. package/dist/shared-tree-core/editManagerFormatCommons.d.ts +9 -44
  432. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  433. package/dist/shared-tree-core/editManagerFormatCommons.js +8 -8
  434. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  435. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +2 -2
  436. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  437. package/dist/shared-tree-core/editManagerFormatV1toV4.js +1 -1
  438. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  439. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts +1 -1
  440. package/dist/shared-tree-core/editManagerSummarizer.js +3 -3
  441. package/dist/shared-tree-core/editManagerSummarizer.js.map +1 -1
  442. package/dist/shared-tree-core/index.d.ts +3 -2
  443. package/dist/shared-tree-core/index.d.ts.map +1 -1
  444. package/dist/shared-tree-core/index.js +2 -3
  445. package/dist/shared-tree-core/index.js.map +1 -1
  446. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +1 -1
  447. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  448. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  449. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  450. package/dist/shared-tree-core/messageCodecVSharedBranches.js +2 -1
  451. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  452. package/dist/shared-tree-core/messageCodecs.d.ts +0 -4
  453. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  454. package/dist/shared-tree-core/messageCodecs.js +15 -19
  455. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  456. package/dist/shared-tree-core/messageFormat.d.ts +10 -50
  457. package/dist/shared-tree-core/messageFormat.d.ts.map +1 -1
  458. package/dist/shared-tree-core/messageFormat.js +9 -8
  459. package/dist/shared-tree-core/messageFormat.js.map +1 -1
  460. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts +2 -2
  461. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  462. package/dist/shared-tree-core/messageFormatV1ToV4.js +1 -1
  463. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  464. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts +1 -1
  465. package/dist/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  466. package/dist/shared-tree-core/sequenceIdUtils.js +4 -4
  467. package/dist/shared-tree-core/sequenceIdUtils.js.map +1 -1
  468. package/dist/shared-tree-core/sharedTreeCore.d.ts +0 -1
  469. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  470. package/dist/shared-tree-core/sharedTreeCore.js +13 -9
  471. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  472. package/dist/shared-tree-core/transaction.d.ts +25 -8
  473. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  474. package/dist/shared-tree-core/transaction.js +65 -30
  475. package/dist/shared-tree-core/transaction.js.map +1 -1
  476. package/dist/shared-tree-core/transactionEnricher.d.ts +2 -2
  477. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  478. package/dist/shared-tree-core/transactionEnricher.js +3 -3
  479. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  480. package/dist/shared-tree-core/versionedSummarizer.d.ts +6 -1
  481. package/dist/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  482. package/dist/shared-tree-core/versionedSummarizer.js +4 -3
  483. package/dist/shared-tree-core/versionedSummarizer.js.map +1 -1
  484. package/dist/simple-tree/api/configuration.js +1 -1
  485. package/dist/simple-tree/api/configuration.js.map +1 -1
  486. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  487. package/dist/simple-tree/api/customTree.js +13 -9
  488. package/dist/simple-tree/api/customTree.js.map +1 -1
  489. package/dist/simple-tree/api/discrepancies.d.ts.map +1 -1
  490. package/dist/simple-tree/api/discrepancies.js +21 -17
  491. package/dist/simple-tree/api/discrepancies.js.map +1 -1
  492. package/dist/simple-tree/api/eraseSchemaDetails.d.ts +89 -0
  493. package/dist/simple-tree/api/eraseSchemaDetails.d.ts.map +1 -0
  494. package/dist/simple-tree/api/eraseSchemaDetails.js +97 -0
  495. package/dist/simple-tree/api/eraseSchemaDetails.js.map +1 -0
  496. package/dist/simple-tree/api/index.d.ts +2 -1
  497. package/dist/simple-tree/api/index.d.ts.map +1 -1
  498. package/dist/simple-tree/api/index.js +5 -1
  499. package/dist/simple-tree/api/index.js.map +1 -1
  500. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  501. package/dist/simple-tree/api/schemaFactory.js +12 -8
  502. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  503. package/dist/simple-tree/api/schemaFromSimple.js +18 -9
  504. package/dist/simple-tree/api/schemaFromSimple.js.map +1 -1
  505. package/dist/simple-tree/api/simpleSchemaCodec.js +10 -5
  506. package/dist/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  507. package/dist/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  508. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +15 -11
  509. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  510. package/dist/simple-tree/api/simpleTreeIndex.js +10 -10
  511. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -1
  512. package/dist/simple-tree/api/storedSchema.d.ts +1 -1
  513. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  514. package/dist/simple-tree/api/storedSchema.js +3 -5
  515. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  516. package/dist/simple-tree/api/transactionTypes.d.ts +17 -4
  517. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  518. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  519. package/dist/simple-tree/api/tree.d.ts +15 -2
  520. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  521. package/dist/simple-tree/api/tree.js.map +1 -1
  522. package/dist/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  523. package/dist/simple-tree/api/treeNodeApi.js +21 -13
  524. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  525. package/dist/simple-tree/api/verboseTree.d.ts.map +1 -1
  526. package/dist/simple-tree/api/verboseTree.js +14 -9
  527. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  528. package/dist/simple-tree/core/treeNode.d.ts.map +1 -1
  529. package/dist/simple-tree/core/treeNode.js +1 -0
  530. package/dist/simple-tree/core/treeNode.js.map +1 -1
  531. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  532. package/dist/simple-tree/core/treeNodeKernel.js +6 -3
  533. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  534. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +15 -15
  535. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  536. package/dist/simple-tree/core/unhydratedFlexTree.js +28 -74
  537. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  538. package/dist/simple-tree/createContext.d.ts.map +1 -1
  539. package/dist/simple-tree/createContext.js +1 -1
  540. package/dist/simple-tree/createContext.js.map +1 -1
  541. package/dist/simple-tree/fieldSchema.d.ts +4 -4
  542. package/dist/simple-tree/fieldSchema.d.ts.map +1 -1
  543. package/dist/simple-tree/fieldSchema.js.map +1 -1
  544. package/dist/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  545. package/dist/simple-tree/getTreeNodeForField.js +2 -1
  546. package/dist/simple-tree/getTreeNodeForField.js.map +1 -1
  547. package/dist/simple-tree/index.d.ts +3 -3
  548. package/dist/simple-tree/index.d.ts.map +1 -1
  549. package/dist/simple-tree/index.js +5 -3
  550. package/dist/simple-tree/index.js.map +1 -1
  551. package/dist/simple-tree/leafNodeSchema.js +9 -6
  552. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  553. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  554. package/dist/simple-tree/node-kinds/array/arrayNode.js +18 -20
  555. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  556. package/dist/simple-tree/node-kinds/common.d.ts.map +1 -1
  557. package/dist/simple-tree/node-kinds/common.js +1 -1
  558. package/dist/simple-tree/node-kinds/common.js.map +1 -1
  559. package/dist/simple-tree/node-kinds/map/mapNode.js +2 -2
  560. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  561. package/dist/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  562. package/dist/simple-tree/node-kinds/object/objectNode.js +21 -22
  563. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  564. package/dist/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  565. package/dist/simple-tree/node-kinds/record/recordNode.js +4 -7
  566. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  567. package/dist/simple-tree/prepareForInsertion.d.ts +47 -54
  568. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  569. package/dist/simple-tree/prepareForInsertion.js +125 -183
  570. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  571. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  572. package/dist/simple-tree/toStoredSchema.js +12 -8
  573. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  574. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +4 -13
  575. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
  576. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js +11 -29
  577. package/dist/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  578. package/dist/tableSchema.d.ts +3 -14
  579. package/dist/tableSchema.d.ts.map +1 -1
  580. package/dist/tableSchema.js +2 -2
  581. package/dist/tableSchema.js.map +1 -1
  582. package/dist/treeFactory.d.ts.map +1 -1
  583. package/dist/treeFactory.js +2 -12
  584. package/dist/treeFactory.js.map +1 -1
  585. package/dist/util/bTreeUtils.js +1 -1
  586. package/dist/util/bTreeUtils.js.map +1 -1
  587. package/dist/util/brand.d.ts +49 -0
  588. package/dist/util/brand.d.ts.map +1 -1
  589. package/dist/util/brand.js +47 -1
  590. package/dist/util/brand.js.map +1 -1
  591. package/dist/util/breakable.js +7 -9
  592. package/dist/util/breakable.js.map +1 -1
  593. package/dist/util/idAllocator.d.ts.map +1 -1
  594. package/dist/util/idAllocator.js +1 -2
  595. package/dist/util/idAllocator.js.map +1 -1
  596. package/dist/util/index.d.ts +2 -2
  597. package/dist/util/index.d.ts.map +1 -1
  598. package/dist/util/index.js +4 -3
  599. package/dist/util/index.js.map +1 -1
  600. package/dist/util/nestedMap.d.ts.map +1 -1
  601. package/dist/util/nestedMap.js +1 -1
  602. package/dist/util/nestedMap.js.map +1 -1
  603. package/dist/util/rangeMap.d.ts +12 -24
  604. package/dist/util/rangeMap.d.ts.map +1 -1
  605. package/dist/util/rangeMap.js +6 -46
  606. package/dist/util/rangeMap.js.map +1 -1
  607. package/dist/util/utils.d.ts.map +1 -1
  608. package/dist/util/utils.js +16 -15
  609. package/dist/util/utils.js.map +1 -1
  610. package/docs/main/sequence-field/move-composition.md +46 -0
  611. package/eslint.config.mts +83 -0
  612. package/lib/alpha.d.ts +7 -0
  613. package/lib/codec/codec.d.ts +63 -20
  614. package/lib/codec/codec.d.ts.map +1 -1
  615. package/lib/codec/codec.js +44 -18
  616. package/lib/codec/codec.js.map +1 -1
  617. package/lib/codec/index.d.ts +2 -2
  618. package/lib/codec/index.d.ts.map +1 -1
  619. package/lib/codec/index.js +1 -1
  620. package/lib/codec/index.js.map +1 -1
  621. package/lib/codec/versioned/codec.d.ts +80 -22
  622. package/lib/codec/versioned/codec.d.ts.map +1 -1
  623. package/lib/codec/versioned/codec.js +138 -15
  624. package/lib/codec/versioned/codec.js.map +1 -1
  625. package/lib/codec/versioned/index.d.ts +1 -1
  626. package/lib/codec/versioned/index.d.ts.map +1 -1
  627. package/lib/codec/versioned/index.js +1 -1
  628. package/lib/codec/versioned/index.js.map +1 -1
  629. package/lib/core/change-family/changeFamily.d.ts +1 -4
  630. package/lib/core/change-family/changeFamily.d.ts.map +1 -1
  631. package/lib/core/change-family/changeFamily.js.map +1 -1
  632. package/lib/core/change-family/index.d.ts +1 -1
  633. package/lib/core/change-family/index.d.ts.map +1 -1
  634. package/lib/core/change-family/index.js.map +1 -1
  635. package/lib/core/index.d.ts +3 -3
  636. package/lib/core/index.d.ts.map +1 -1
  637. package/lib/core/index.js +2 -2
  638. package/lib/core/index.js.map +1 -1
  639. package/lib/core/rebase/changeRebaser.d.ts +37 -8
  640. package/lib/core/rebase/changeRebaser.d.ts.map +1 -1
  641. package/lib/core/rebase/changeRebaser.js.map +1 -1
  642. package/lib/core/rebase/index.d.ts +2 -2
  643. package/lib/core/rebase/index.d.ts.map +1 -1
  644. package/lib/core/rebase/index.js +1 -1
  645. package/lib/core/rebase/index.js.map +1 -1
  646. package/lib/core/rebase/types.d.ts +27 -5
  647. package/lib/core/rebase/types.d.ts.map +1 -1
  648. package/lib/core/rebase/types.js +0 -13
  649. package/lib/core/rebase/types.js.map +1 -1
  650. package/lib/core/rebase/utils.d.ts.map +1 -1
  651. package/lib/core/rebase/utils.js +10 -28
  652. package/lib/core/rebase/utils.js.map +1 -1
  653. package/lib/core/schema-stored/schema.d.ts +4 -7
  654. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  655. package/lib/core/schema-stored/schema.js +6 -6
  656. package/lib/core/schema-stored/schema.js.map +1 -1
  657. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  658. package/lib/core/tree/anchorSet.js +3 -4
  659. package/lib/core/tree/anchorSet.js.map +1 -1
  660. package/lib/core/tree/detachedFieldIndex.d.ts +1 -8
  661. package/lib/core/tree/detachedFieldIndex.d.ts.map +1 -1
  662. package/lib/core/tree/detachedFieldIndex.js +14 -67
  663. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  664. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts +18 -10
  665. package/lib/core/tree/detachedFieldIndexCodecCommon.d.ts.map +1 -1
  666. package/lib/core/tree/detachedFieldIndexCodecCommon.js +4 -4
  667. package/lib/core/tree/detachedFieldIndexCodecCommon.js.map +1 -1
  668. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts +2 -3
  669. package/lib/core/tree/detachedFieldIndexCodecV1.d.ts.map +1 -1
  670. package/lib/core/tree/detachedFieldIndexCodecV1.js +4 -5
  671. package/lib/core/tree/detachedFieldIndexCodecV1.js.map +1 -1
  672. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts +2 -3
  673. package/lib/core/tree/detachedFieldIndexCodecV2.d.ts.map +1 -1
  674. package/lib/core/tree/detachedFieldIndexCodecV2.js +4 -6
  675. package/lib/core/tree/detachedFieldIndexCodecV2.js.map +1 -1
  676. package/lib/core/tree/detachedFieldIndexCodecs.d.ts +5 -6
  677. package/lib/core/tree/detachedFieldIndexCodecs.d.ts.map +1 -1
  678. package/lib/core/tree/detachedFieldIndexCodecs.js +12 -39
  679. package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  680. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts +4 -4
  681. package/lib/core/tree/detachedFieldIndexFormatCommon.d.ts.map +1 -1
  682. package/lib/core/tree/detachedFieldIndexFormatCommon.js +3 -3
  683. package/lib/core/tree/detachedFieldIndexFormatCommon.js.map +1 -1
  684. package/lib/core/tree/index.d.ts +2 -2
  685. package/lib/core/tree/index.d.ts.map +1 -1
  686. package/lib/core/tree/index.js +2 -2
  687. package/lib/core/tree/index.js.map +1 -1
  688. package/lib/core/tree/mapTree.js +1 -1
  689. package/lib/core/tree/mapTree.js.map +1 -1
  690. package/lib/core/tree/pathTree.d.ts +3 -11
  691. package/lib/core/tree/pathTree.d.ts.map +1 -1
  692. package/lib/core/tree/pathTree.js +1 -12
  693. package/lib/core/tree/pathTree.js.map +1 -1
  694. package/lib/core/tree/sparseTree.d.ts.map +1 -1
  695. package/lib/core/tree/sparseTree.js +1 -0
  696. package/lib/core/tree/sparseTree.js.map +1 -1
  697. package/lib/core/tree/treeTextFormat.d.ts.map +1 -1
  698. package/lib/core/tree/treeTextFormat.js +5 -9
  699. package/lib/core/tree/treeTextFormat.js.map +1 -1
  700. package/lib/feature-libraries/changeAtomIdBTree.d.ts +10 -0
  701. package/lib/feature-libraries/changeAtomIdBTree.d.ts.map +1 -0
  702. package/lib/feature-libraries/changeAtomIdBTree.js +11 -0
  703. package/lib/feature-libraries/changeAtomIdBTree.js.map +1 -0
  704. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  705. package/lib/feature-libraries/chunked-forest/basicChunk.js +2 -9
  706. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  707. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  708. package/lib/feature-libraries/chunked-forest/chunkTree.js +1 -4
  709. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  710. package/lib/feature-libraries/chunked-forest/chunkedForest.js +6 -6
  711. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  712. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  713. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +7 -4
  714. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  715. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  716. package/lib/feature-libraries/chunked-forest/codec/codecs.js +20 -12
  717. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  718. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js +3 -3
  719. package/lib/feature-libraries/chunked-forest/codec/compressedEncode.js.map +1 -1
  720. package/lib/feature-libraries/chunked-forest/codec/format.d.ts +5 -5
  721. package/lib/feature-libraries/chunked-forest/codec/format.d.ts.map +1 -1
  722. package/lib/feature-libraries/chunked-forest/codec/format.js +5 -5
  723. package/lib/feature-libraries/chunked-forest/codec/format.js.map +1 -1
  724. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +9 -5
  725. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  726. package/lib/feature-libraries/chunked-forest/uniformChunk.js +1 -1
  727. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  728. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts +54 -93
  729. package/lib/feature-libraries/default-schema/defaultEditBuilder.d.ts.map +1 -1
  730. package/lib/feature-libraries/default-schema/defaultEditBuilder.js +82 -243
  731. package/lib/feature-libraries/default-schema/defaultEditBuilder.js.map +1 -1
  732. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts +1 -1
  733. package/lib/feature-libraries/default-schema/defaultFieldKinds.d.ts.map +1 -1
  734. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +6 -5
  735. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  736. package/lib/feature-libraries/default-schema/index.d.ts +1 -2
  737. package/lib/feature-libraries/default-schema/index.d.ts.map +1 -1
  738. package/lib/feature-libraries/default-schema/index.js +1 -2
  739. package/lib/feature-libraries/default-schema/index.js.map +1 -1
  740. package/lib/feature-libraries/default-schema/mappedEditBuilder.d.ts +8 -7
  741. package/lib/feature-libraries/default-schema/mappedEditBuilder.d.ts.map +1 -1
  742. package/lib/feature-libraries/default-schema/mappedEditBuilder.js +6 -15
  743. package/lib/feature-libraries/default-schema/mappedEditBuilder.js.map +1 -1
  744. package/lib/feature-libraries/deltaUtils.d.ts +0 -1
  745. package/lib/feature-libraries/deltaUtils.d.ts.map +1 -1
  746. package/lib/feature-libraries/deltaUtils.js +1 -5
  747. package/lib/feature-libraries/deltaUtils.js.map +1 -1
  748. package/lib/feature-libraries/flex-tree/context.d.ts +0 -9
  749. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  750. package/lib/feature-libraries/flex-tree/context.js +0 -6
  751. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  752. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +6 -6
  753. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  754. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  755. package/lib/feature-libraries/flex-tree/lazyField.d.ts +7 -8
  756. package/lib/feature-libraries/flex-tree/lazyField.d.ts.map +1 -1
  757. package/lib/feature-libraries/flex-tree/lazyField.js +17 -48
  758. package/lib/feature-libraries/flex-tree/lazyField.js.map +1 -1
  759. package/lib/feature-libraries/forest-summary/codec.d.ts +8 -2
  760. package/lib/feature-libraries/forest-summary/codec.d.ts.map +1 -1
  761. package/lib/feature-libraries/forest-summary/codec.js +12 -11
  762. package/lib/feature-libraries/forest-summary/codec.js.map +1 -1
  763. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +3 -2
  764. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  765. package/lib/feature-libraries/forest-summary/forestSummarizer.js +19 -10
  766. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  767. package/lib/feature-libraries/forest-summary/formatCommon.d.ts +61 -0
  768. package/lib/feature-libraries/forest-summary/formatCommon.d.ts.map +1 -0
  769. package/lib/feature-libraries/forest-summary/{format.js → formatCommon.js} +8 -6
  770. package/lib/feature-libraries/forest-summary/formatCommon.js.map +1 -0
  771. package/lib/feature-libraries/forest-summary/{format.d.ts → formatV1.d.ts} +6 -14
  772. package/lib/feature-libraries/forest-summary/formatV1.d.ts.map +1 -0
  773. package/lib/feature-libraries/forest-summary/formatV1.js +8 -0
  774. package/lib/feature-libraries/forest-summary/formatV1.js.map +1 -0
  775. package/lib/feature-libraries/forest-summary/formatV2.d.ts +51 -0
  776. package/lib/feature-libraries/forest-summary/formatV2.d.ts.map +1 -0
  777. package/lib/feature-libraries/forest-summary/formatV2.js +8 -0
  778. package/lib/feature-libraries/forest-summary/formatV2.js.map +1 -0
  779. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +7 -15
  780. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  781. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +11 -20
  782. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  783. package/lib/feature-libraries/forest-summary/index.d.ts +1 -2
  784. package/lib/feature-libraries/forest-summary/index.d.ts.map +1 -1
  785. package/lib/feature-libraries/forest-summary/index.js +1 -2
  786. package/lib/feature-libraries/forest-summary/index.js.map +1 -1
  787. package/lib/feature-libraries/forest-summary/summaryFormatCommon.d.ts +35 -0
  788. package/lib/feature-libraries/forest-summary/summaryFormatCommon.d.ts.map +1 -0
  789. package/lib/feature-libraries/forest-summary/summaryFormatCommon.js +40 -0
  790. package/lib/feature-libraries/forest-summary/summaryFormatCommon.js.map +1 -0
  791. package/lib/feature-libraries/forest-summary/summaryFormatV1ToV2.d.ts +11 -0
  792. package/lib/feature-libraries/forest-summary/summaryFormatV1ToV2.d.ts.map +1 -0
  793. package/lib/feature-libraries/forest-summary/summaryFormatV1ToV2.js +11 -0
  794. package/lib/feature-libraries/forest-summary/summaryFormatV1ToV2.js.map +1 -0
  795. package/lib/feature-libraries/forest-summary/summaryFormatV3.d.ts +18 -0
  796. package/lib/feature-libraries/forest-summary/summaryFormatV3.d.ts.map +1 -0
  797. package/lib/feature-libraries/forest-summary/summaryFormatV3.js +18 -0
  798. package/lib/feature-libraries/forest-summary/summaryFormatV3.js.map +1 -0
  799. package/lib/feature-libraries/forest-summary/summaryTypes.d.ts +7 -37
  800. package/lib/feature-libraries/forest-summary/summaryTypes.d.ts.map +1 -1
  801. package/lib/feature-libraries/forest-summary/summaryTypes.js +20 -43
  802. package/lib/feature-libraries/forest-summary/summaryTypes.js.map +1 -1
  803. package/lib/feature-libraries/index.d.ts +5 -4
  804. package/lib/feature-libraries/index.d.ts.map +1 -1
  805. package/lib/feature-libraries/index.js +5 -4
  806. package/lib/feature-libraries/index.js.map +1 -1
  807. package/lib/feature-libraries/indexing/anchorTreeIndex.js +6 -6
  808. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -1
  809. package/lib/feature-libraries/mapTreeCursor.d.ts.map +1 -1
  810. package/lib/feature-libraries/mapTreeCursor.js +1 -2
  811. package/lib/feature-libraries/mapTreeCursor.js.map +1 -1
  812. package/lib/feature-libraries/mitigatedChangeFamily.d.ts.map +1 -1
  813. package/lib/feature-libraries/mitigatedChangeFamily.js +12 -3
  814. package/lib/feature-libraries/mitigatedChangeFamily.js.map +1 -1
  815. package/lib/feature-libraries/modular-schema/comparison.d.ts.map +1 -1
  816. package/lib/feature-libraries/modular-schema/comparison.js +13 -10
  817. package/lib/feature-libraries/modular-schema/comparison.js.map +1 -1
  818. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts +21 -97
  819. package/lib/feature-libraries/modular-schema/crossFieldQueries.d.ts.map +1 -1
  820. package/lib/feature-libraries/modular-schema/crossFieldQueries.js +5 -3
  821. package/lib/feature-libraries/modular-schema/crossFieldQueries.js.map +1 -1
  822. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts +25 -0
  823. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.d.ts.map +1 -0
  824. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js +55 -0
  825. package/lib/feature-libraries/modular-schema/defaultRevisionReplacer.js.map +1 -0
  826. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts +52 -20
  827. package/lib/feature-libraries/modular-schema/fieldChangeHandler.d.ts.map +1 -1
  828. package/lib/feature-libraries/modular-schema/fieldChangeHandler.js.map +1 -1
  829. package/lib/feature-libraries/modular-schema/genericFieldKind.d.ts.map +1 -1
  830. package/lib/feature-libraries/modular-schema/genericFieldKind.js +14 -8
  831. package/lib/feature-libraries/modular-schema/genericFieldKind.js.map +1 -1
  832. package/lib/feature-libraries/modular-schema/index.d.ts +7 -5
  833. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  834. package/lib/feature-libraries/modular-schema/index.js +5 -4
  835. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  836. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts +41 -9
  837. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.d.ts.map +1 -1
  838. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js +248 -334
  839. package/lib/feature-libraries/modular-schema/modularChangeCodecV1.js.map +1 -1
  840. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.d.ts +7 -9
  841. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.d.ts.map +1 -1
  842. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.js +10 -392
  843. package/lib/feature-libraries/modular-schema/modularChangeCodecV2.js.map +1 -1
  844. package/lib/feature-libraries/modular-schema/modularChangeCodecs.d.ts.map +1 -1
  845. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js +24 -11
  846. package/lib/feature-libraries/modular-schema/modularChangeCodecs.js.map +1 -1
  847. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts +27 -55
  848. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  849. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +549 -1352
  850. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  851. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts +3 -4
  852. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.d.ts.map +1 -1
  853. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -2
  854. package/lib/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  855. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts +14 -48
  856. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.d.ts.map +1 -1
  857. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.js +10 -21
  858. package/lib/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -1
  859. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +18 -48
  860. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  861. package/lib/feature-libraries/modular-schema/modularChangeTypes.js +2 -20
  862. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  863. package/lib/feature-libraries/node-identifier/mockNodeIdentifierManager.js +1 -1
  864. package/lib/feature-libraries/node-identifier/mockNodeIdentifierManager.js.map +1 -1
  865. package/lib/feature-libraries/object-forest/objectForest.js +4 -4
  866. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  867. package/lib/feature-libraries/optional-field/index.d.ts +2 -2
  868. package/lib/feature-libraries/optional-field/index.d.ts.map +1 -1
  869. package/lib/feature-libraries/optional-field/index.js +1 -1
  870. package/lib/feature-libraries/optional-field/index.js.map +1 -1
  871. package/lib/feature-libraries/optional-field/optionalField.d.ts +26 -5
  872. package/lib/feature-libraries/optional-field/optionalField.d.ts.map +1 -1
  873. package/lib/feature-libraries/optional-field/optionalField.js +445 -218
  874. package/lib/feature-libraries/optional-field/optionalField.js.map +1 -1
  875. package/lib/feature-libraries/optional-field/optionalFieldChangeTypes.d.ts +33 -24
  876. package/lib/feature-libraries/optional-field/optionalFieldChangeTypes.d.ts.map +1 -1
  877. package/lib/feature-libraries/optional-field/optionalFieldChangeTypes.js.map +1 -1
  878. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.d.ts +1 -1
  879. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.d.ts.map +1 -1
  880. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.js +26 -55
  881. package/lib/feature-libraries/optional-field/optionalFieldCodecV2.js.map +1 -1
  882. package/lib/feature-libraries/optional-field/optionalFieldCodecs.d.ts.map +1 -1
  883. package/lib/feature-libraries/optional-field/optionalFieldCodecs.js +1 -5
  884. package/lib/feature-libraries/optional-field/optionalFieldCodecs.js.map +1 -1
  885. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.d.ts.map +1 -1
  886. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js +16 -5
  887. package/lib/feature-libraries/schema-edits/schemaChangeCodecs.js.map +1 -1
  888. package/lib/feature-libraries/schema-index/codec.d.ts +7 -21
  889. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  890. package/lib/feature-libraries/schema-index/codec.js +29 -67
  891. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  892. package/lib/feature-libraries/schema-index/formatV1.d.ts +1 -1
  893. package/lib/feature-libraries/schema-index/formatV2.d.ts +1 -1
  894. package/lib/feature-libraries/schema-index/index.d.ts +2 -2
  895. package/lib/feature-libraries/schema-index/index.d.ts.map +1 -1
  896. package/lib/feature-libraries/schema-index/index.js +2 -2
  897. package/lib/feature-libraries/schema-index/index.js.map +1 -1
  898. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts +1 -9
  899. package/lib/feature-libraries/schema-index/schemaSummarizer.d.ts.map +1 -1
  900. package/lib/feature-libraries/schema-index/schemaSummarizer.js +0 -10
  901. package/lib/feature-libraries/schema-index/schemaSummarizer.js.map +1 -1
  902. package/lib/feature-libraries/schemaChecker.d.ts.map +1 -1
  903. package/lib/feature-libraries/schemaChecker.js +11 -6
  904. package/lib/feature-libraries/schemaChecker.js.map +1 -1
  905. package/lib/feature-libraries/sequence-field/compose.d.ts +7 -6
  906. package/lib/feature-libraries/sequence-field/compose.d.ts.map +1 -1
  907. package/lib/feature-libraries/sequence-field/compose.js +266 -86
  908. package/lib/feature-libraries/sequence-field/compose.js.map +1 -1
  909. package/lib/feature-libraries/sequence-field/helperTypes.d.ts +10 -14
  910. package/lib/feature-libraries/sequence-field/helperTypes.d.ts.map +1 -1
  911. package/lib/feature-libraries/sequence-field/helperTypes.js.map +1 -1
  912. package/lib/feature-libraries/sequence-field/index.d.ts +3 -2
  913. package/lib/feature-libraries/sequence-field/index.d.ts.map +1 -1
  914. package/lib/feature-libraries/sequence-field/index.js +1 -0
  915. package/lib/feature-libraries/sequence-field/index.js.map +1 -1
  916. package/lib/feature-libraries/sequence-field/invert.d.ts +3 -3
  917. package/lib/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  918. package/lib/feature-libraries/sequence-field/invert.js +171 -68
  919. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  920. package/lib/feature-libraries/sequence-field/markQueue.d.ts +2 -2
  921. package/lib/feature-libraries/sequence-field/markQueue.d.ts.map +1 -1
  922. package/lib/feature-libraries/sequence-field/markQueue.js.map +1 -1
  923. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts +56 -4
  924. package/lib/feature-libraries/sequence-field/moveEffectTable.d.ts.map +1 -1
  925. package/lib/feature-libraries/sequence-field/moveEffectTable.js +87 -7
  926. package/lib/feature-libraries/sequence-field/moveEffectTable.js.map +1 -1
  927. package/lib/feature-libraries/sequence-field/rebase.d.ts +3 -3
  928. package/lib/feature-libraries/sequence-field/rebase.d.ts.map +1 -1
  929. package/lib/feature-libraries/sequence-field/rebase.js +129 -115
  930. package/lib/feature-libraries/sequence-field/rebase.js.map +1 -1
  931. package/lib/feature-libraries/sequence-field/relevantRemovedRoots.d.ts +9 -0
  932. package/lib/feature-libraries/sequence-field/relevantRemovedRoots.d.ts.map +1 -0
  933. package/lib/feature-libraries/sequence-field/relevantRemovedRoots.js +46 -0
  934. package/lib/feature-libraries/sequence-field/relevantRemovedRoots.js.map +1 -0
  935. package/lib/feature-libraries/sequence-field/replaceRevisions.d.ts +2 -2
  936. package/lib/feature-libraries/sequence-field/replaceRevisions.d.ts.map +1 -1
  937. package/lib/feature-libraries/sequence-field/replaceRevisions.js +50 -28
  938. package/lib/feature-libraries/sequence-field/replaceRevisions.js.map +1 -1
  939. package/lib/feature-libraries/sequence-field/sequenceFieldChangeHandler.d.ts.map +1 -1
  940. package/lib/feature-libraries/sequence-field/sequenceFieldChangeHandler.js +2 -0
  941. package/lib/feature-libraries/sequence-field/sequenceFieldChangeHandler.js.map +1 -1
  942. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts +4 -22
  943. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.d.ts.map +1 -1
  944. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js +183 -350
  945. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV2.js.map +1 -1
  946. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.d.ts.map +1 -1
  947. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js +63 -21
  948. package/lib/feature-libraries/sequence-field/sequenceFieldCodecV3.js.map +1 -1
  949. package/lib/feature-libraries/sequence-field/sequenceFieldEditor.d.ts +2 -2
  950. package/lib/feature-libraries/sequence-field/sequenceFieldEditor.d.ts.map +1 -1
  951. package/lib/feature-libraries/sequence-field/sequenceFieldEditor.js +10 -10
  952. package/lib/feature-libraries/sequence-field/sequenceFieldEditor.js.map +1 -1
  953. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts +2 -3
  954. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.d.ts.map +1 -1
  955. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +115 -17
  956. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  957. package/lib/feature-libraries/sequence-field/types.d.ts +59 -30
  958. package/lib/feature-libraries/sequence-field/types.d.ts.map +1 -1
  959. package/lib/feature-libraries/sequence-field/types.js.map +1 -1
  960. package/lib/feature-libraries/sequence-field/utils.d.ts +24 -15
  961. package/lib/feature-libraries/sequence-field/utils.d.ts.map +1 -1
  962. package/lib/feature-libraries/sequence-field/utils.js +327 -123
  963. package/lib/feature-libraries/sequence-field/utils.js.map +1 -1
  964. package/lib/feature-libraries/treeCursorUtils.js +7 -7
  965. package/lib/feature-libraries/treeCursorUtils.js.map +1 -1
  966. package/lib/feature-libraries/treeTextCursor.js +2 -2
  967. package/lib/feature-libraries/treeTextCursor.js.map +1 -1
  968. package/lib/feature-libraries/valueUtilities.d.ts.map +1 -1
  969. package/lib/feature-libraries/valueUtilities.js +16 -8
  970. package/lib/feature-libraries/valueUtilities.js.map +1 -1
  971. package/lib/index.d.ts +3 -3
  972. package/lib/index.d.ts.map +1 -1
  973. package/lib/index.js +1 -1
  974. package/lib/index.js.map +1 -1
  975. package/lib/packageVersion.d.ts +1 -1
  976. package/lib/packageVersion.d.ts.map +1 -1
  977. package/lib/packageVersion.js +1 -1
  978. package/lib/packageVersion.js.map +1 -1
  979. package/lib/shared-tree/independentView.d.ts.map +1 -1
  980. package/lib/shared-tree/independentView.js +2 -2
  981. package/lib/shared-tree/independentView.js.map +1 -1
  982. package/lib/shared-tree/index.d.ts +1 -1
  983. package/lib/shared-tree/index.d.ts.map +1 -1
  984. package/lib/shared-tree/index.js.map +1 -1
  985. package/lib/shared-tree/schematizeTree.d.ts +4 -4
  986. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  987. package/lib/shared-tree/schematizeTree.js +2 -3
  988. package/lib/shared-tree/schematizeTree.js.map +1 -1
  989. package/lib/shared-tree/schematizingTreeView.d.ts +9 -5
  990. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  991. package/lib/shared-tree/schematizingTreeView.js +59 -44
  992. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  993. package/lib/shared-tree/sharedTree.d.ts +3 -9
  994. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  995. package/lib/shared-tree/sharedTree.js +26 -19
  996. package/lib/shared-tree/sharedTree.js.map +1 -1
  997. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts +1 -1
  998. package/lib/shared-tree/sharedTreeChangeCodecs.d.ts.map +1 -1
  999. package/lib/shared-tree/sharedTreeChangeCodecs.js +11 -11
  1000. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  1001. package/lib/shared-tree/sharedTreeChangeEnricher.d.ts.map +1 -1
  1002. package/lib/shared-tree/sharedTreeChangeEnricher.js +6 -4
  1003. package/lib/shared-tree/sharedTreeChangeEnricher.js.map +1 -1
  1004. package/lib/shared-tree/sharedTreeChangeFamily.d.ts +7 -6
  1005. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  1006. package/lib/shared-tree/sharedTreeChangeFamily.js +24 -25
  1007. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  1008. package/lib/shared-tree/sharedTreeEditBuilder.d.ts +6 -16
  1009. package/lib/shared-tree/sharedTreeEditBuilder.d.ts.map +1 -1
  1010. package/lib/shared-tree/sharedTreeEditBuilder.js +6 -12
  1011. package/lib/shared-tree/sharedTreeEditBuilder.js.map +1 -1
  1012. package/lib/shared-tree/treeAlpha.d.ts +35 -29
  1013. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  1014. package/lib/shared-tree/treeAlpha.js +21 -23
  1015. package/lib/shared-tree/treeAlpha.js.map +1 -1
  1016. package/lib/shared-tree/treeCheckout.d.ts +17 -12
  1017. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  1018. package/lib/shared-tree/treeCheckout.js +89 -70
  1019. package/lib/shared-tree/treeCheckout.js.map +1 -1
  1020. package/lib/shared-tree-core/branch.d.ts +5 -4
  1021. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  1022. package/lib/shared-tree-core/branch.js +7 -6
  1023. package/lib/shared-tree-core/branch.js.map +1 -1
  1024. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  1025. package/lib/shared-tree-core/branchCommitEnricher.js +2 -2
  1026. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  1027. package/lib/shared-tree-core/editManager.d.ts +2 -2
  1028. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  1029. package/lib/shared-tree-core/editManager.js +10 -10
  1030. package/lib/shared-tree-core/editManager.js.map +1 -1
  1031. package/lib/shared-tree-core/editManagerCodecs.d.ts +0 -4
  1032. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  1033. package/lib/shared-tree-core/editManagerCodecs.js +13 -15
  1034. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  1035. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js +1 -1
  1036. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  1037. package/lib/shared-tree-core/editManagerFormatCommons.d.ts +9 -44
  1038. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  1039. package/lib/shared-tree-core/editManagerFormatCommons.js +9 -9
  1040. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  1041. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +2 -2
  1042. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  1043. package/lib/shared-tree-core/editManagerFormatV1toV4.js +1 -1
  1044. package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  1045. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts +1 -1
  1046. package/lib/shared-tree-core/editManagerSummarizer.js +3 -3
  1047. package/lib/shared-tree-core/editManagerSummarizer.js.map +1 -1
  1048. package/lib/shared-tree-core/index.d.ts +3 -2
  1049. package/lib/shared-tree-core/index.d.ts.map +1 -1
  1050. package/lib/shared-tree-core/index.js +2 -2
  1051. package/lib/shared-tree-core/index.js.map +1 -1
  1052. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +1 -1
  1053. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  1054. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  1055. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  1056. package/lib/shared-tree-core/messageCodecVSharedBranches.js +2 -1
  1057. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  1058. package/lib/shared-tree-core/messageCodecs.d.ts +0 -4
  1059. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  1060. package/lib/shared-tree-core/messageCodecs.js +15 -18
  1061. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  1062. package/lib/shared-tree-core/messageFormat.d.ts +10 -50
  1063. package/lib/shared-tree-core/messageFormat.d.ts.map +1 -1
  1064. package/lib/shared-tree-core/messageFormat.js +9 -8
  1065. package/lib/shared-tree-core/messageFormat.js.map +1 -1
  1066. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts +2 -2
  1067. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  1068. package/lib/shared-tree-core/messageFormatV1ToV4.js +1 -1
  1069. package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  1070. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts +1 -1
  1071. package/lib/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  1072. package/lib/shared-tree-core/sequenceIdUtils.js +4 -4
  1073. package/lib/shared-tree-core/sequenceIdUtils.js.map +1 -1
  1074. package/lib/shared-tree-core/sharedTreeCore.d.ts +0 -1
  1075. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  1076. package/lib/shared-tree-core/sharedTreeCore.js +13 -9
  1077. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  1078. package/lib/shared-tree-core/transaction.d.ts +25 -8
  1079. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  1080. package/lib/shared-tree-core/transaction.js +67 -32
  1081. package/lib/shared-tree-core/transaction.js.map +1 -1
  1082. package/lib/shared-tree-core/transactionEnricher.d.ts +2 -2
  1083. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  1084. package/lib/shared-tree-core/transactionEnricher.js +3 -3
  1085. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  1086. package/lib/shared-tree-core/versionedSummarizer.d.ts +6 -1
  1087. package/lib/shared-tree-core/versionedSummarizer.d.ts.map +1 -1
  1088. package/lib/shared-tree-core/versionedSummarizer.js +4 -3
  1089. package/lib/shared-tree-core/versionedSummarizer.js.map +1 -1
  1090. package/lib/simple-tree/api/configuration.js +1 -1
  1091. package/lib/simple-tree/api/configuration.js.map +1 -1
  1092. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  1093. package/lib/simple-tree/api/customTree.js +13 -9
  1094. package/lib/simple-tree/api/customTree.js.map +1 -1
  1095. package/lib/simple-tree/api/discrepancies.d.ts.map +1 -1
  1096. package/lib/simple-tree/api/discrepancies.js +21 -17
  1097. package/lib/simple-tree/api/discrepancies.js.map +1 -1
  1098. package/lib/simple-tree/api/eraseSchemaDetails.d.ts +89 -0
  1099. package/lib/simple-tree/api/eraseSchemaDetails.d.ts.map +1 -0
  1100. package/lib/simple-tree/api/eraseSchemaDetails.js +92 -0
  1101. package/lib/simple-tree/api/eraseSchemaDetails.js.map +1 -0
  1102. package/lib/simple-tree/api/index.d.ts +2 -1
  1103. package/lib/simple-tree/api/index.d.ts.map +1 -1
  1104. package/lib/simple-tree/api/index.js +1 -0
  1105. package/lib/simple-tree/api/index.js.map +1 -1
  1106. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  1107. package/lib/simple-tree/api/schemaFactory.js +12 -8
  1108. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  1109. package/lib/simple-tree/api/schemaFromSimple.js +18 -9
  1110. package/lib/simple-tree/api/schemaFromSimple.js.map +1 -1
  1111. package/lib/simple-tree/api/simpleSchemaCodec.js +10 -5
  1112. package/lib/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  1113. package/lib/simple-tree/api/simpleSchemaToJsonSchema.d.ts.map +1 -1
  1114. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +15 -11
  1115. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  1116. package/lib/simple-tree/api/simpleTreeIndex.js +10 -10
  1117. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -1
  1118. package/lib/simple-tree/api/storedSchema.d.ts +1 -1
  1119. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  1120. package/lib/simple-tree/api/storedSchema.js +5 -9
  1121. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  1122. package/lib/simple-tree/api/transactionTypes.d.ts +17 -4
  1123. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  1124. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  1125. package/lib/simple-tree/api/tree.d.ts +15 -2
  1126. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  1127. package/lib/simple-tree/api/tree.js.map +1 -1
  1128. package/lib/simple-tree/api/treeNodeApi.d.ts.map +1 -1
  1129. package/lib/simple-tree/api/treeNodeApi.js +21 -13
  1130. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  1131. package/lib/simple-tree/api/verboseTree.d.ts.map +1 -1
  1132. package/lib/simple-tree/api/verboseTree.js +14 -9
  1133. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  1134. package/lib/simple-tree/core/treeNode.d.ts.map +1 -1
  1135. package/lib/simple-tree/core/treeNode.js +1 -0
  1136. package/lib/simple-tree/core/treeNode.js.map +1 -1
  1137. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  1138. package/lib/simple-tree/core/treeNodeKernel.js +6 -3
  1139. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  1140. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +15 -15
  1141. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  1142. package/lib/simple-tree/core/unhydratedFlexTree.js +28 -73
  1143. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  1144. package/lib/simple-tree/createContext.d.ts.map +1 -1
  1145. package/lib/simple-tree/createContext.js +1 -1
  1146. package/lib/simple-tree/createContext.js.map +1 -1
  1147. package/lib/simple-tree/fieldSchema.d.ts +4 -4
  1148. package/lib/simple-tree/fieldSchema.d.ts.map +1 -1
  1149. package/lib/simple-tree/fieldSchema.js.map +1 -1
  1150. package/lib/simple-tree/getTreeNodeForField.d.ts.map +1 -1
  1151. package/lib/simple-tree/getTreeNodeForField.js +2 -1
  1152. package/lib/simple-tree/getTreeNodeForField.js.map +1 -1
  1153. package/lib/simple-tree/index.d.ts +3 -3
  1154. package/lib/simple-tree/index.d.ts.map +1 -1
  1155. package/lib/simple-tree/index.js +2 -2
  1156. package/lib/simple-tree/index.js.map +1 -1
  1157. package/lib/simple-tree/leafNodeSchema.js +9 -6
  1158. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  1159. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  1160. package/lib/simple-tree/node-kinds/array/arrayNode.js +19 -21
  1161. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  1162. package/lib/simple-tree/node-kinds/common.d.ts.map +1 -1
  1163. package/lib/simple-tree/node-kinds/common.js +2 -2
  1164. package/lib/simple-tree/node-kinds/common.js.map +1 -1
  1165. package/lib/simple-tree/node-kinds/map/mapNode.js +2 -2
  1166. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  1167. package/lib/simple-tree/node-kinds/object/objectNode.d.ts.map +1 -1
  1168. package/lib/simple-tree/node-kinds/object/objectNode.js +22 -23
  1169. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  1170. package/lib/simple-tree/node-kinds/record/recordNode.d.ts.map +1 -1
  1171. package/lib/simple-tree/node-kinds/record/recordNode.js +4 -7
  1172. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  1173. package/lib/simple-tree/prepareForInsertion.d.ts +47 -54
  1174. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  1175. package/lib/simple-tree/prepareForInsertion.js +124 -183
  1176. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  1177. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  1178. package/lib/simple-tree/toStoredSchema.js +12 -8
  1179. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  1180. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts +4 -13
  1181. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.d.ts.map +1 -1
  1182. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js +9 -26
  1183. package/lib/simple-tree/unhydratedFlexTreeFromInsertable.js.map +1 -1
  1184. package/lib/tableSchema.d.ts +3 -14
  1185. package/lib/tableSchema.d.ts.map +1 -1
  1186. package/lib/tableSchema.js +3 -3
  1187. package/lib/tableSchema.js.map +1 -1
  1188. package/lib/treeFactory.d.ts.map +1 -1
  1189. package/lib/treeFactory.js +3 -13
  1190. package/lib/treeFactory.js.map +1 -1
  1191. package/lib/util/bTreeUtils.js +1 -1
  1192. package/lib/util/bTreeUtils.js.map +1 -1
  1193. package/lib/util/brand.d.ts +49 -0
  1194. package/lib/util/brand.d.ts.map +1 -1
  1195. package/lib/util/brand.js +44 -0
  1196. package/lib/util/brand.js.map +1 -1
  1197. package/lib/util/breakable.js +7 -9
  1198. package/lib/util/breakable.js.map +1 -1
  1199. package/lib/util/idAllocator.d.ts.map +1 -1
  1200. package/lib/util/idAllocator.js +1 -2
  1201. package/lib/util/idAllocator.js.map +1 -1
  1202. package/lib/util/index.d.ts +2 -2
  1203. package/lib/util/index.d.ts.map +1 -1
  1204. package/lib/util/index.js +2 -2
  1205. package/lib/util/index.js.map +1 -1
  1206. package/lib/util/nestedMap.d.ts.map +1 -1
  1207. package/lib/util/nestedMap.js +1 -1
  1208. package/lib/util/nestedMap.js.map +1 -1
  1209. package/lib/util/rangeMap.d.ts +12 -24
  1210. package/lib/util/rangeMap.d.ts.map +1 -1
  1211. package/lib/util/rangeMap.js +5 -44
  1212. package/lib/util/rangeMap.js.map +1 -1
  1213. package/lib/util/utils.d.ts.map +1 -1
  1214. package/lib/util/utils.js +16 -15
  1215. package/lib/util/utils.js.map +1 -1
  1216. package/package.json +33 -32
  1217. package/src/codec/codec.ts +82 -26
  1218. package/src/codec/index.ts +4 -1
  1219. package/src/codec/versioned/codec.ts +340 -22
  1220. package/src/codec/versioned/index.ts +3 -1
  1221. package/src/core/change-family/changeFamily.ts +0 -5
  1222. package/src/core/change-family/index.ts +0 -1
  1223. package/src/core/index.ts +4 -6
  1224. package/src/core/rebase/changeRebaser.ts +41 -12
  1225. package/src/core/rebase/index.ts +2 -2
  1226. package/src/core/rebase/types.ts +32 -26
  1227. package/src/core/rebase/utils.ts +10 -34
  1228. package/src/core/schema-stored/schema.ts +8 -10
  1229. package/src/core/tree/anchorSet.ts +3 -4
  1230. package/src/core/tree/detachedFieldIndex.ts +14 -91
  1231. package/src/core/tree/detachedFieldIndexCodecCommon.ts +4 -8
  1232. package/src/core/tree/detachedFieldIndexCodecV1.ts +3 -7
  1233. package/src/core/tree/detachedFieldIndexCodecV2.ts +5 -9
  1234. package/src/core/tree/detachedFieldIndexCodecs.ts +21 -64
  1235. package/src/core/tree/detachedFieldIndexFormatCommon.ts +4 -7
  1236. package/src/core/tree/index.ts +2 -3
  1237. package/src/core/tree/mapTree.ts +1 -1
  1238. package/src/core/tree/pathTree.ts +4 -16
  1239. package/src/core/tree/sparseTree.ts +1 -0
  1240. package/src/core/tree/treeTextFormat.ts +5 -9
  1241. package/src/feature-libraries/changeAtomIdBTree.ts +24 -0
  1242. package/src/feature-libraries/chunked-forest/basicChunk.ts +2 -8
  1243. package/src/feature-libraries/chunked-forest/chunkTree.ts +1 -6
  1244. package/src/feature-libraries/chunked-forest/chunkedForest.ts +5 -5
  1245. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +7 -4
  1246. package/src/feature-libraries/chunked-forest/codec/codecs.ts +20 -11
  1247. package/src/feature-libraries/chunked-forest/codec/compressedEncode.ts +3 -3
  1248. package/src/feature-libraries/chunked-forest/codec/format.ts +6 -9
  1249. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +9 -5
  1250. package/src/feature-libraries/chunked-forest/uniformChunk.ts +1 -1
  1251. package/src/feature-libraries/default-schema/defaultEditBuilder.ts +163 -403
  1252. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +9 -7
  1253. package/src/feature-libraries/default-schema/index.ts +5 -17
  1254. package/src/feature-libraries/default-schema/mappedEditBuilder.ts +15 -35
  1255. package/src/feature-libraries/deltaUtils.ts +1 -6
  1256. package/src/feature-libraries/flex-tree/context.ts +0 -17
  1257. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +8 -7
  1258. package/src/feature-libraries/flex-tree/lazyField.ts +31 -74
  1259. package/src/feature-libraries/forest-summary/codec.ts +25 -13
  1260. package/src/feature-libraries/forest-summary/forestSummarizer.ts +37 -12
  1261. package/src/feature-libraries/forest-summary/{format.ts → formatCommon.ts} +10 -11
  1262. package/src/feature-libraries/forest-summary/formatV1.ts +12 -0
  1263. package/src/feature-libraries/forest-summary/formatV2.ts +12 -0
  1264. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +18 -21
  1265. package/src/feature-libraries/forest-summary/index.ts +1 -2
  1266. package/src/feature-libraries/forest-summary/summaryFormatCommon.ts +41 -0
  1267. package/src/feature-libraries/forest-summary/summaryFormatV1ToV2.ts +11 -0
  1268. package/src/feature-libraries/forest-summary/summaryFormatV3.ts +18 -0
  1269. package/src/feature-libraries/forest-summary/summaryTypes.ts +26 -46
  1270. package/src/feature-libraries/index.ts +18 -27
  1271. package/src/feature-libraries/indexing/anchorTreeIndex.ts +5 -5
  1272. package/src/feature-libraries/mapTreeCursor.ts +1 -2
  1273. package/src/feature-libraries/mitigatedChangeFamily.ts +12 -9
  1274. package/src/feature-libraries/modular-schema/comparison.ts +14 -10
  1275. package/src/feature-libraries/modular-schema/crossFieldQueries.ts +44 -142
  1276. package/src/feature-libraries/modular-schema/defaultRevisionReplacer.ts +70 -0
  1277. package/src/feature-libraries/modular-schema/fieldChangeHandler.ts +58 -40
  1278. package/src/feature-libraries/modular-schema/genericFieldKind.ts +23 -13
  1279. package/src/feature-libraries/modular-schema/index.ts +18 -21
  1280. package/src/feature-libraries/modular-schema/modularChangeCodecV1.ts +543 -572
  1281. package/src/feature-libraries/modular-schema/modularChangeCodecV2.ts +44 -745
  1282. package/src/feature-libraries/modular-schema/modularChangeCodecs.ts +37 -51
  1283. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +862 -2636
  1284. package/src/feature-libraries/modular-schema/modularChangeFormatV1.ts +3 -4
  1285. package/src/feature-libraries/modular-schema/modularChangeFormatV2.ts +17 -45
  1286. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +18 -97
  1287. package/src/feature-libraries/node-identifier/mockNodeIdentifierManager.ts +1 -1
  1288. package/src/feature-libraries/object-forest/objectForest.ts +4 -4
  1289. package/src/feature-libraries/optional-field/index.ts +3 -1
  1290. package/src/feature-libraries/optional-field/optionalField.ts +566 -321
  1291. package/src/feature-libraries/optional-field/optionalFieldChangeTypes.ts +38 -24
  1292. package/src/feature-libraries/optional-field/optionalFieldCodecV2.ts +35 -89
  1293. package/src/feature-libraries/optional-field/optionalFieldCodecs.ts +1 -5
  1294. package/src/feature-libraries/schema-edits/schemaChangeCodecs.ts +19 -5
  1295. package/src/feature-libraries/schema-index/codec.ts +30 -92
  1296. package/src/feature-libraries/schema-index/index.ts +2 -4
  1297. package/src/feature-libraries/schema-index/schemaSummarizer.ts +0 -17
  1298. package/src/feature-libraries/schemaChecker.ts +11 -6
  1299. package/src/feature-libraries/sequence-field/compose.ts +527 -138
  1300. package/src/feature-libraries/sequence-field/helperTypes.ts +19 -34
  1301. package/src/feature-libraries/sequence-field/index.ts +9 -0
  1302. package/src/feature-libraries/sequence-field/invert.ts +229 -103
  1303. package/src/feature-libraries/sequence-field/markQueue.ts +2 -2
  1304. package/src/feature-libraries/sequence-field/moveEffectTable.ts +198 -9
  1305. package/src/feature-libraries/sequence-field/rebase.ts +218 -175
  1306. package/src/feature-libraries/sequence-field/relevantRemovedRoots.ts +57 -0
  1307. package/src/feature-libraries/sequence-field/replaceRevisions.ts +76 -59
  1308. package/src/feature-libraries/sequence-field/sequenceFieldChangeHandler.ts +2 -0
  1309. package/src/feature-libraries/sequence-field/sequenceFieldCodecV2.ts +228 -643
  1310. package/src/feature-libraries/sequence-field/sequenceFieldCodecV3.ts +70 -56
  1311. package/src/feature-libraries/sequence-field/sequenceFieldEditor.ts +27 -25
  1312. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +135 -22
  1313. package/src/feature-libraries/sequence-field/types.ts +64 -34
  1314. package/src/feature-libraries/sequence-field/utils.ts +382 -150
  1315. package/src/feature-libraries/treeCursorUtils.ts +7 -7
  1316. package/src/feature-libraries/treeTextCursor.ts +2 -2
  1317. package/src/feature-libraries/valueUtilities.ts +16 -8
  1318. package/src/index.ts +7 -0
  1319. package/src/packageVersion.ts +1 -1
  1320. package/src/shared-tree/independentView.ts +1 -2
  1321. package/src/shared-tree/index.ts +2 -3
  1322. package/src/shared-tree/schematizeTree.ts +8 -21
  1323. package/src/shared-tree/schematizingTreeView.ts +96 -63
  1324. package/src/shared-tree/sharedTree.ts +29 -29
  1325. package/src/shared-tree/sharedTreeChangeCodecs.ts +12 -15
  1326. package/src/shared-tree/sharedTreeChangeEnricher.ts +4 -4
  1327. package/src/shared-tree/sharedTreeChangeFamily.ts +34 -34
  1328. package/src/shared-tree/sharedTreeEditBuilder.ts +9 -39
  1329. package/src/shared-tree/treeAlpha.ts +60 -51
  1330. package/src/shared-tree/treeCheckout.ts +158 -132
  1331. package/src/shared-tree-core/branch.ts +10 -11
  1332. package/src/shared-tree-core/branchCommitEnricher.ts +3 -8
  1333. package/src/shared-tree-core/editManager.ts +3 -17
  1334. package/src/shared-tree-core/editManagerCodecs.ts +13 -18
  1335. package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +1 -1
  1336. package/src/shared-tree-core/editManagerFormatCommons.ts +12 -15
  1337. package/src/shared-tree-core/editManagerFormatV1toV4.ts +2 -2
  1338. package/src/shared-tree-core/editManagerSummarizer.ts +3 -3
  1339. package/src/shared-tree-core/index.ts +3 -2
  1340. package/src/shared-tree-core/messageCodecV1ToV4.ts +1 -1
  1341. package/src/shared-tree-core/messageCodecVSharedBranches.ts +2 -1
  1342. package/src/shared-tree-core/messageCodecs.ts +15 -21
  1343. package/src/shared-tree-core/messageFormat.ts +12 -15
  1344. package/src/shared-tree-core/messageFormatV1ToV4.ts +2 -2
  1345. package/src/shared-tree-core/sequenceIdUtils.ts +4 -4
  1346. package/src/shared-tree-core/sharedTreeCore.ts +12 -11
  1347. package/src/shared-tree-core/transaction.ts +115 -56
  1348. package/src/shared-tree-core/transactionEnricher.ts +5 -6
  1349. package/src/shared-tree-core/versionedSummarizer.ts +10 -3
  1350. package/src/simple-tree/api/configuration.ts +1 -1
  1351. package/src/simple-tree/api/customTree.ts +14 -10
  1352. package/src/simple-tree/api/discrepancies.ts +23 -17
  1353. package/src/simple-tree/api/eraseSchemaDetails.ts +123 -0
  1354. package/src/simple-tree/api/index.ts +6 -0
  1355. package/src/simple-tree/api/schemaFactory.ts +11 -7
  1356. package/src/simple-tree/api/schemaFromSimple.ts +18 -9
  1357. package/src/simple-tree/api/simpleSchemaCodec.ts +10 -5
  1358. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +17 -13
  1359. package/src/simple-tree/api/simpleTreeIndex.ts +8 -8
  1360. package/src/simple-tree/api/storedSchema.ts +12 -9
  1361. package/src/simple-tree/api/transactionTypes.ts +19 -4
  1362. package/src/simple-tree/api/tree.ts +16 -1
  1363. package/src/simple-tree/api/treeNodeApi.ts +21 -13
  1364. package/src/simple-tree/api/verboseTree.ts +14 -9
  1365. package/src/simple-tree/core/treeNode.ts +1 -0
  1366. package/src/simple-tree/core/treeNodeKernel.ts +6 -3
  1367. package/src/simple-tree/core/unhydratedFlexTree.ts +58 -104
  1368. package/src/simple-tree/createContext.ts +4 -1
  1369. package/src/simple-tree/fieldSchema.ts +4 -6
  1370. package/src/simple-tree/getTreeNodeForField.ts +2 -1
  1371. package/src/simple-tree/index.ts +5 -2
  1372. package/src/simple-tree/leafNodeSchema.ts +8 -5
  1373. package/src/simple-tree/node-kinds/array/arrayNode.ts +28 -30
  1374. package/src/simple-tree/node-kinds/common.ts +5 -2
  1375. package/src/simple-tree/node-kinds/map/mapNode.ts +4 -4
  1376. package/src/simple-tree/node-kinds/object/objectNode.ts +28 -29
  1377. package/src/simple-tree/node-kinds/record/recordNode.ts +11 -13
  1378. package/src/simple-tree/prepareForInsertion.ts +200 -343
  1379. package/src/simple-tree/toStoredSchema.ts +12 -8
  1380. package/src/simple-tree/unhydratedFlexTreeFromInsertable.ts +14 -42
  1381. package/src/tableSchema.ts +13 -18
  1382. package/src/treeFactory.ts +5 -14
  1383. package/src/util/bTreeUtils.ts +1 -1
  1384. package/src/util/brand.ts +61 -0
  1385. package/src/util/breakable.ts +9 -9
  1386. package/src/util/idAllocator.ts +1 -2
  1387. package/src/util/index.ts +3 -3
  1388. package/src/util/nestedMap.ts +1 -3
  1389. package/src/util/rangeMap.ts +18 -72
  1390. package/src/util/utils.ts +14 -13
  1391. package/dist/feature-libraries/default-schema/locationBasedEditBuilder.d.ts +0 -36
  1392. package/dist/feature-libraries/default-schema/locationBasedEditBuilder.d.ts.map +0 -1
  1393. package/dist/feature-libraries/default-schema/locationBasedEditBuilder.js +0 -126
  1394. package/dist/feature-libraries/default-schema/locationBasedEditBuilder.js.map +0 -1
  1395. package/dist/feature-libraries/forest-summary/format.d.ts.map +0 -1
  1396. package/dist/feature-libraries/forest-summary/format.js.map +0 -1
  1397. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV3.d.ts +0 -23
  1398. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV3.d.ts.map +0 -1
  1399. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV3.js +0 -31
  1400. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV3.js.map +0 -1
  1401. package/dist/feature-libraries/optional-field/optionalFieldCodecV3.d.ts +0 -12
  1402. package/dist/feature-libraries/optional-field/optionalFieldCodecV3.d.ts.map +0 -1
  1403. package/dist/feature-libraries/optional-field/optionalFieldCodecV3.js +0 -57
  1404. package/dist/feature-libraries/optional-field/optionalFieldCodecV3.js.map +0 -1
  1405. package/lib/feature-libraries/default-schema/locationBasedEditBuilder.d.ts +0 -36
  1406. package/lib/feature-libraries/default-schema/locationBasedEditBuilder.d.ts.map +0 -1
  1407. package/lib/feature-libraries/default-schema/locationBasedEditBuilder.js +0 -122
  1408. package/lib/feature-libraries/default-schema/locationBasedEditBuilder.js.map +0 -1
  1409. package/lib/feature-libraries/forest-summary/format.d.ts.map +0 -1
  1410. package/lib/feature-libraries/forest-summary/format.js.map +0 -1
  1411. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV3.d.ts +0 -23
  1412. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV3.d.ts.map +0 -1
  1413. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV3.js +0 -27
  1414. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV3.js.map +0 -1
  1415. package/lib/feature-libraries/optional-field/optionalFieldCodecV3.d.ts +0 -12
  1416. package/lib/feature-libraries/optional-field/optionalFieldCodecV3.d.ts.map +0 -1
  1417. package/lib/feature-libraries/optional-field/optionalFieldCodecV3.js +0 -53
  1418. package/lib/feature-libraries/optional-field/optionalFieldCodecV3.js.map +0 -1
  1419. package/src/feature-libraries/default-schema/locationBasedEditBuilder.ts +0 -180
  1420. package/src/feature-libraries/optional-field/optionalFieldChangeFormatV3.ts +0 -45
  1421. package/src/feature-libraries/optional-field/optionalFieldCodecV3.ts +0 -94
@@ -1 +1 @@
1
- {"version":3,"file":"chunkTree.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAqF;AAGrF,kDAkB6B;AAC7B,kDAAkD;AAClD,0DAAqE;AAErE,mDAA6C;AAC7C,yDAAmD;AACnD,uDAA6E;AAS7E;;GAEG;AACH,SAAgB,eAAe,CAC9B,MAAoC,EACpC,MAAoB,EACpB,yBAAoD;IAEpD,OAAO,IAAI,OAAO,CACjB,MAAM,EACN,MAAM,EACN,0BAAkB,CAAC,4BAA4B,EAC/C,0BAAkB,CAAC,4BAA4B,EAC/C,0BAAkB,CAAC,qBAAqB,EACxC,CAAC,IAA8B,EAAE,MAAgD,EAAE,EAAE,CACpF,sBAAsB,CACrB;QACC,MAAM;QACN,MAAM;QACN,yBAAyB;QACzB,MAAM;KACN,EACD,IAAI,CACJ,CACF,CAAC;AACH,CAAC;AAtBD,0CAsBC;AAaD;;;;;;;;GAQG;AACH,kEAAkE;AAClE,MAAa,WAAW;CAAG;AAA3B,kCAA2B;AAE3B;;;GAGG;AACU,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAQ7C,MAAa,OAAO;IAUnB,YACiB,MAAoC,EACpC,MAAoB,EACpB,2BAAmC,EACnC,4BAAoC,EACpC,qBAA6B;IAC7C,wDAAwD;IACvC,sBAGH;QATE,WAAM,GAAN,MAAM,CAA8B;QACpC,WAAM,GAAN,MAAM,CAAc;QACpB,gCAA2B,GAA3B,2BAA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;;;;;;;;;GAYG;AACH,SAAgB,sBAAsB,CACrC,MAA8B,EAC9B,KAAgB,EAChB,iBAAyB,EACzB,kBAA2B,EAC3B,YAA4B;IAE5B,QAAQ;IACR,gGAAgG;IAEhG,MAAM,MAAM,GAAgB,EAAE,CAAC;IAC/B,IAAI,cAAc,GAAG,CAAC,CAAC;IACvB,OAAO,cAAc,IAAI,iBAAiB,EAAE,CAAC;QAC5C,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;QAClD,IAAI,cAAc,KAAK,iBAAiB,EAAE,CAAC;YAC1C,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACzB,MAAM,CAAC,QAAQ,EAAE,CAAC;YACnB,CAAC;YACD,MAAM;QACP,CAAC;QACD,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;YAChC,MAAM;QACP,CAAC;QACD,cAAc,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,8BAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AACzF,CAAC;AA3BD,wDA2BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, debugAssert, oob, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport {\n\tCursorLocationType,\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\tLeafNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchemaSubscription,\n\ttype TreeValue,\n\ttype Value,\n\tmapCursorFields,\n\tMultiplicity,\n\tValueSchema,\n\ttype TreeChunk,\n\ttryGetChunk,\n\ttype SchemaAndPolicy,\n\ttype SchemaPolicy,\n} from \"../../core/index.js\";\nimport { getOrCreate } from \"../../util/index.js\";\nimport { isStableNodeIdentifier } from \"../node-identifier/index.js\";\n\nimport { BasicChunk } from \"./basicChunk.js\";\nimport { SequenceChunk } from \"./sequenceChunk.js\";\nimport { type FieldShape, TreeShape, UniformChunk } from \"./uniformChunk.js\";\nimport type { IncrementalEncodingPolicy } from \"./codec/index.js\";\n\nexport interface Disposable {\n\t/**\n\t * Cleans up resources used by this, such as inbound event registrations.\n\t */\n\tdispose(): void;\n}\n/**\n * Creates a ChunkPolicy which responds to schema changes.\n */\nexport function makeTreeChunker(\n\tschema: TreeStoredSchemaSubscription,\n\tpolicy: SchemaPolicy,\n\tshouldEncodeIncrementally: IncrementalEncodingPolicy,\n): IChunker {\n\treturn new Chunker(\n\t\tschema,\n\t\tpolicy,\n\t\tdefaultChunkPolicy.sequenceChunkInlineThreshold,\n\t\tdefaultChunkPolicy.sequenceChunkInlineThreshold,\n\t\tdefaultChunkPolicy.uniformChunkNodeCount,\n\t\t(type: TreeNodeSchemaIdentifier, shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>) =>\n\t\t\ttryShapeFromNodeSchema(\n\t\t\t\t{\n\t\t\t\t\tschema,\n\t\t\t\t\tpolicy,\n\t\t\t\t\tshouldEncodeIncrementally,\n\t\t\t\t\tshapes,\n\t\t\t\t},\n\t\t\t\ttype,\n\t\t\t),\n\t);\n}\n\n/**\n * Extends ChunkPolicy to include stateful details required by ChunkedForest.\n *\n * This extra complexity is mostly due to the fact that schema can change over time,\n * and that chunk policy uses caching which thus needs invalidation.\n */\nexport interface IChunker extends ChunkPolicy, Disposable {\n\treadonly schema: TreeStoredSchemaSubscription;\n\tclone(schema: TreeStoredSchemaSubscription): IChunker;\n}\n\n/**\n * Indicates that there are multiple possible `TreeShape` trees with a given type can have.\n *\n * @remarks\n * For example, a schema transitively containing a sequence field, optional field, or allowing multiple child types will be Polymorphic.\n * See `tryShapeFromNodeSchema` for how to tell if a type is Polymorphic.\n *\n * TODO: cache some of the possible shapes here.\n */\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class Polymorphic {}\n\n/**\n * See `Polymorphic`.\n * For now Polymorphic is stateless, so just use a singleton.\n */\nexport const polymorphic = new Polymorphic();\n\n/**\n * Information about the possible shapes a tree could take based on its type.\n * Note that this information is for a specific version of the schema.\n */\nexport type ShapeInfo = TreeShape | Polymorphic;\n\nexport class Chunker implements IChunker {\n\t/**\n\t * Cache for information about possible shapes for types.\n\t * Corresponds to the version of the schema in `schema`.\n\t * Cleared when `schema` changes.\n\t */\n\tprivate readonly typeShapes: Map<TreeNodeSchemaIdentifier, ShapeInfo> = new Map();\n\n\tprivate unregisterSchemaCallback: (() => void) | undefined;\n\n\tpublic constructor(\n\t\tpublic readonly schema: TreeStoredSchemaSubscription,\n\t\tpublic readonly policy: SchemaPolicy,\n\t\tpublic readonly sequenceChunkSplitThreshold: number,\n\t\tpublic readonly sequenceChunkInlineThreshold: number,\n\t\tpublic readonly uniformChunkNodeCount: number,\n\t\t// eslint-disable-next-line @typescript-eslint/no-shadow\n\t\tprivate readonly tryShapeFromNodeSchema: (\n\t\t\ttype: TreeNodeSchemaIdentifier,\n\t\t\tshapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>,\n\t\t) => ShapeInfo,\n\t) {}\n\n\tpublic clone(schema: TreeStoredSchemaSubscription): IChunker {\n\t\t// This does not preserve the cache.\n\t\t// This is probably fine, but is a potential way it could be optimized in the future (with care to ensure invalidation work properly).\n\t\treturn new Chunker(\n\t\t\tschema,\n\t\t\tthis.policy,\n\t\t\tthis.sequenceChunkSplitThreshold,\n\t\t\tthis.sequenceChunkInlineThreshold,\n\t\t\tthis.uniformChunkNodeCount,\n\t\t\tthis.tryShapeFromNodeSchema,\n\t\t);\n\t}\n\n\tpublic shapeFromSchema(schema: TreeNodeSchemaIdentifier): ShapeInfo {\n\t\tconst cached = this.typeShapes.get(schema);\n\t\tif (cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\t\tthis.unregisterSchemaCallback = this.schema.events.on(\"afterSchemaChange\", () =>\n\t\t\tthis.schemaChanged(),\n\t\t);\n\t\treturn this.tryShapeFromNodeSchema(schema, this.typeShapes);\n\t}\n\n\tpublic dispose(): void {\n\t\t// Remove subscription for changes via dependent.\n\t\tthis.schemaChanged();\n\t}\n\n\tprivate schemaChanged(): void {\n\t\tthis.typeShapes.clear();\n\t\tif (this.unregisterSchemaCallback) {\n\t\t\tthis.unregisterSchemaCallback();\n\t\t\tthis.unregisterSchemaCallback = undefined;\n\t\t}\n\t}\n}\n\n/**\n * Get a TreeChunk for the current node (and its children) of cursor.\n * This will copy if needed, but add refs to existing chunks which hold the data.\n *\n * @param cursor - cursor in nodes mode\n */\nexport function chunkTree(cursor: ITreeCursorSynchronous, policy: ChunkCompressor): TreeChunk {\n\treturn chunkRange(cursor, policy, 1, true)[0] ?? oob();\n}\n\n/**\n * Get a TreeChunk[] for the current field (and its children) of cursor.\n * This will copy if needed, but add refs to existing chunks which hold the data.\n */\nexport function chunkField(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): TreeChunk[] {\n\tconst length = cursor.getFieldLength();\n\tconst started = cursor.firstNode();\n\tdebugAssert(\n\t\t() => started === (length !== 0) || \"only 0 length fields should not have nodes\",\n\t);\n\treturn chunkRange(cursor, policy, length, false);\n}\n\n/**\n * Get a TreeChunk for the current field (and its children) of cursor.\n * Like {@link chunkField}, but forces the results into a single TreeChunk.\n */\nexport function chunkFieldSingle(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): TreeChunk {\n\tconst chunks = chunkField(cursor, policy);\n\treturn combineChunks(chunks);\n}\n\n/**\n * Create a single TreeChunk from an array of TreeChunks.\n * @remarks\n * This takes ownership of the provided TreeChunk references, and returns an owned referenced.\n */\nexport function combineChunks(chunks: TreeChunk[]): TreeChunk {\n\tif (chunks.length === 1) {\n\t\treturn chunks[0] ?? oob();\n\t}\n\treturn new SequenceChunk(chunks);\n}\n\n/**\n * Get a BasicChunk for the current node (and its children) of cursor.\n * This will copy if needed, and add refs to existing chunks which hold the data.\n */\nexport function basicChunkTree(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): BasicChunk {\n\t// symbol based fast path to check for BasicChunk:\n\t// return existing chunk with a increased ref count if possible.\n\tconst chunk = tryGetChunk(cursor);\n\tif (chunk instanceof BasicChunk) {\n\t\tchunk.referenceAdded();\n\t\treturn chunk;\n\t}\n\n\treturn newBasicChunkTree(cursor, policy);\n}\n\nexport function makePolicy(policy?: Partial<ChunkPolicy>): ChunkPolicy {\n\tconst withDefaults = { ...defaultChunkPolicy, ...policy };\n\t// TODO: move this to a top level policy validation\n\tassert(\n\t\twithDefaults.sequenceChunkSplitThreshold >= 2,\n\t\t0x57d /* sequenceChunkThreshold must be at least 2 */,\n\t);\n\n\treturn withDefaults;\n}\n\nexport interface ShapeFromSchemaParameters extends SchemaAndPolicy {\n\t/**\n\t * Policy function to determine if a field should be encoded incrementally.\n\t * Incrementally encoding requires the subtree to not start in the middle of a larger uniform chunk.\n\t * Thus returning true from this callback indicates that shapes should not be produced which could\n\t *contain the incremental portion as a part of a larger shape.\n\t */\n\treadonly shouldEncodeIncrementally: IncrementalEncodingPolicy;\n\t/**\n\t * A cache for shapes which may be read and/or updated.\n\t * As the shape is a function of the other members of `ShapeFromSchemaParameters`,\n\t * it must be replaced or cleared if any of the properties other than this cache are modified.\n\t */\n\treadonly shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>;\n}\n\n/**\n * A TreeFieldStoredSchema with some additional context about where it is in the tree.\n */\nexport interface FieldSchemaWithContext {\n\t/**\n\t * The identifier of the specific field schema to analyze for shape uniformity.\n\t */\n\treadonly fieldSchema: TreeFieldStoredSchema;\n\t/**\n\t * The identifier of the parent node schema containing this field.\n\t * If undefined, this is a root field.\n\t */\n\treadonly parentNodeSchema?: TreeNodeSchemaIdentifier;\n\t/**\n\t * The field key/name used to identify this field within the parent node.\n\t */\n\treadonly key: FieldKey;\n}\n\n/**\n * Analyzes a tree node schema to determine if it has a single, uniform shape that can be optimized for chunking.\n * If the schema defines a tree structure with a deterministic, fixed shape (no optional fields, no sequences,\n * single child types), returns a TreeShape that can be used for efficient uniform chunking. Otherwise,\n * returns Polymorphic to indicate the shape varies and should use basic chunking.\n *\n * @param context - {@link ShapeFromSchemaParameters}.\n * @param nodeSchema - The identifier of the specific node schema to analyze for shape uniformity.\n * @returns TreeShape if the schema has a uniform shape, or Polymorphic if shape varies.\n *\n * @remarks\n * The determination here is conservative. `shouldEncodeIncrementally` is used to split up shapes so incrementally\n * encoded schema are not part of larger shapes. It also does not tolerate optional or sequence fields, nor does it\n * optimize for patterns of specific values.\n */\nexport function tryShapeFromNodeSchema(\n\tcontext: ShapeFromSchemaParameters,\n\tnodeSchema: TreeNodeSchemaIdentifier,\n): ShapeInfo {\n\tconst { schema, shapes } = context;\n\treturn getOrCreate(shapes, nodeSchema, () => {\n\t\tconst treeSchema = schema.nodeSchema.get(nodeSchema) ?? fail(0xaf9 /* missing schema */);\n\t\tif (treeSchema instanceof LeafNodeStoredSchema) {\n\t\t\t// Allow all string values (but only string values) to be compressed by the id compressor.\n\t\t\t// This allows compressing all compressible identifiers without requiring additional context to know which values could be identifiers.\n\t\t\t// Attempting to compress other string shouldn't have significant overhead,\n\t\t\t// and if any of them do end up compressing, that's a benefit not a bug.\n\t\t\treturn treeSchema.leafValue === ValueSchema.String\n\t\t\t\t? new TreeShape(nodeSchema, true, [], true)\n\t\t\t\t: new TreeShape(nodeSchema, true, [], false);\n\t\t}\n\t\tif (treeSchema instanceof ObjectNodeStoredSchema) {\n\t\t\tconst fieldsArray: FieldShape[] = [];\n\t\t\tfor (const [key, fieldSchema] of treeSchema.objectNodeFields) {\n\t\t\t\tconst fieldShape = tryShapeFromFieldSchema(context, {\n\t\t\t\t\tfieldSchema,\n\t\t\t\t\tparentNodeSchema: nodeSchema,\n\t\t\t\t\tkey,\n\t\t\t\t});\n\t\t\t\tif (fieldShape === undefined) {\n\t\t\t\t\treturn polymorphic;\n\t\t\t\t}\n\t\t\t\tfieldsArray.push(fieldShape);\n\t\t\t}\n\t\t\treturn new TreeShape(nodeSchema, false, fieldsArray);\n\t\t}\n\t\treturn polymorphic;\n\t});\n}\n\n/**\n * Same as {@link tryShapeFromNodeSchema} but for fields with {@link FieldSchemaWithContext} instead of a nodeSchema.\n *\n * @param context - {@link ShapeFromFieldSchemaParameters}.\n * @param fieldSchemaWithContext - {@link FieldSchemaWithContext}.\n * @returns FieldShape if the field has a uniform shape, or undefined if the field is polymorphic.\n */\nexport function tryShapeFromFieldSchema(\n\tcontext: ShapeFromSchemaParameters,\n\tfieldSchemaWithContext: FieldSchemaWithContext,\n): FieldShape | undefined {\n\tconst { schema, policy, shouldEncodeIncrementally, shapes } = context;\n\tconst { fieldSchema, parentNodeSchema, key } = fieldSchemaWithContext;\n\t// If this field should be encoded incrementally, use polymorphic shape so that they\n\t// are chunked separately and can be re-used across encodings if they do not change.\n\tif (shouldEncodeIncrementally(parentNodeSchema, key)) {\n\t\treturn undefined;\n\t}\n\tconst kind = policy.fieldKinds.get(fieldSchema.kind) ?? fail(0xafa /* missing FieldKind */);\n\tif (kind.multiplicity !== Multiplicity.Single) {\n\t\treturn undefined;\n\t}\n\tif (fieldSchema.types?.size !== 1) {\n\t\treturn undefined;\n\t}\n\tconst childType = [...fieldSchema.types][0] ?? oob();\n\tconst childShape = tryShapeFromNodeSchema(\n\t\t{\n\t\t\tschema,\n\t\t\tpolicy,\n\t\t\tshouldEncodeIncrementally,\n\t\t\tshapes,\n\t\t},\n\t\tchildType,\n\t);\n\tif (childShape instanceof Polymorphic) {\n\t\treturn undefined;\n\t}\n\treturn [key, childShape, 1];\n}\n\n/**\n * Default settings for use for {@link ChunkPolicy}.\n * Use `makeTreeChunker` to create a policy with the defaults, but leverages to schema.\n */\nexport const defaultChunkPolicy: ChunkPolicy = {\n\t// Currently ChunkedForest and BasicTreeCursor don't handle SequenceChunks very efficiently:\n\t// they likely add more overhead than they save for now, so don't create them.\n\tsequenceChunkSplitThreshold: Number.POSITIVE_INFINITY,\n\tsequenceChunkInlineThreshold: Number.POSITIVE_INFINITY,\n\t// Current UniformChunk handling doesn't scale well to large chunks, so set a modest size limit:\n\tuniformChunkNodeCount: 400,\n\t// Without knowing what the schema is, all shapes are possible.\n\t// Use `makeTreeChunker` to do better.\n\tshapeFromSchema: () => polymorphic,\n};\n\nexport const basicOnlyChunkPolicy: ChunkPolicy = {\n\tsequenceChunkSplitThreshold: Number.POSITIVE_INFINITY,\n\tsequenceChunkInlineThreshold: Number.POSITIVE_INFINITY,\n\tuniformChunkNodeCount: 0,\n\tshapeFromSchema: () => polymorphic,\n};\n\n/**\n * Policy for how to chunk a tree.\n */\nexport interface ChunkPolicy {\n\t/**\n\t * Group sequences longer than this into into sequence chunks of this length or less.\n\t *\n\t * Must be at least 2.\n\t * Can be set to `Number.POSITIVE_INFINITY` to never introduce extra sequence chunks.\n\t */\n\treadonly sequenceChunkSplitThreshold: number;\n\n\t/**\n\t * SequenceChunks this long or shorter may get inlined into their parent chunk.\n\t */\n\treadonly sequenceChunkInlineThreshold: number;\n\n\t/**\n\t * Maximum total nodes to put in a UniformChunk.\n\t */\n\treadonly uniformChunkNodeCount: number;\n\n\t/**\n\t * Returns information about the shapes trees of type `schema` can take.\n\t */\n\tshapeFromSchema(schema: TreeNodeSchemaIdentifier): ShapeInfo;\n}\n\nexport interface ChunkCompressor {\n\treadonly policy: ChunkPolicy;\n\t/**\n\t * If the idCompressor is provided, {@link UniformChunk}s with identifiers will be encoded for its in-memory representation.\n\t * @remarks\n\t * This compression applies to {@link UniformChunk}s when {@link TreeShape.maybeDecompressedStringAsNumber} is set.\n\t * If the `policy` does not use UniformChunks or does not set `maybeDecompressedStringAsNumber`, then no compression will be applied even when providing `idCompressor`.\n\t */\n\treadonly idCompressor: IIdCompressor | undefined;\n}\n\nfunction newBasicChunkTree(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): BasicChunk {\n\treturn new BasicChunk(\n\t\tcursor.type,\n\t\tnew Map(\n\t\t\tmapCursorFields(cursor, () => {\n\t\t\t\tdebugAssert(() => cursor.getFieldLength() > 0 || \"field must have at least one child\");\n\t\t\t\treturn [cursor.getFieldKey(), chunkField(cursor, policy)];\n\t\t\t}),\n\t\t),\n\t\tcursor.value,\n\t);\n}\n\n/**\n * Chunk a portion of a field.\n *\n * @param cursor - cursor at the starting node in the field.\n * @param policy - heuristics to impact chunking\n * @param length - how many nodes to process (at the top level). When 0, the cursor is not moved, and may be at the end of the field (and thus in Fields mode)\n * @param skipLastNavigation - if true, leaves the cursor at the last node instead of moving off of it. Invalid if length is 0.\n */\nexport function chunkRange(\n\tcursor: ITreeCursorSynchronous,\n\tchunkCompressor: ChunkCompressor,\n\tlength: number,\n\tskipLastNavigation: boolean,\n): TreeChunk[] {\n\tassert(\n\t\t!(skipLastNavigation && length === 0),\n\t\t0xb58 /* Cannot skip last navigation if length is 0 and thus last navigation already occurred. */,\n\t);\n\tassert(\n\t\t(cursor.mode === CursorLocationType.Nodes) === length > 0,\n\t\t0xb59 /* Should be in nodes mode if not past end */,\n\t);\n\tlet output: TreeChunk[] = [];\n\tlet remaining = length;\n\twhile (remaining > 0) {\n\t\tassert(cursor.mode === CursorLocationType.Nodes, 0x57f /* should be in nodes */);\n\t\tconst start = cursor.chunkStart;\n\t\tlet reusedChunk = false;\n\t\t// symbol based fast path to check for chunk:\n\t\t// return existing chunk with a increased ref count if possible.\n\t\tif (start === cursor.fieldIndex) {\n\t\t\tconst chunkLength = cursor.chunkLength;\n\t\t\tif (chunkLength <= remaining) {\n\t\t\t\tconst chunk = tryGetChunk(cursor);\n\t\t\t\tif (chunk !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tchunk instanceof SequenceChunk &&\n\t\t\t\t\t\tchunk.subChunks.length <= chunkCompressor.policy.sequenceChunkInlineThreshold\n\t\t\t\t\t) {\n\t\t\t\t\t\t// If sequence chunk, and its very short, inline it.\n\t\t\t\t\t\t// Note that this is not recursive: there may be short sequences nested below this which are not inlined.\n\t\t\t\t\t\tfor (const subChunk of chunk.subChunks) {\n\t\t\t\t\t\t\tsubChunk.referenceAdded();\n\t\t\t\t\t\t\toutput.push(subChunk);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tchunk.referenceAdded();\n\t\t\t\t\toutput.push(chunk);\n\t\t\t\t\tremaining -= chunkLength;\n\t\t\t\t\treusedChunk = true;\n\t\t\t\t\tlet seek = chunkLength;\n\t\t\t\t\tif (skipLastNavigation && remaining === 0) {\n\t\t\t\t\t\tseek -= 1;\n\t\t\t\t\t}\n\t\t\t\t\tcursor.seekNodes(seek);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!reusedChunk) {\n\t\t\tassert(cursor.mode === CursorLocationType.Nodes, 0x580 /* should be in nodes */);\n\t\t\t// TODO: if provided, use schema to consider using UniformChunks\n\t\t\tconst type = cursor.type;\n\t\t\tconst shape = chunkCompressor.policy.shapeFromSchema(type);\n\t\t\tif (shape instanceof TreeShape) {\n\t\t\t\tconst nodesPerTopLevelNode = shape.positions.length;\n\t\t\t\tconst maxTopLevelLength = Math.ceil(\n\t\t\t\t\tnodesPerTopLevelNode / chunkCompressor.policy.uniformChunkNodeCount,\n\t\t\t\t);\n\t\t\t\tconst maxLength = Math.min(maxTopLevelLength, remaining);\n\t\t\t\tconst newChunk = uniformChunkFromCursor(\n\t\t\t\t\tcursor,\n\t\t\t\t\tshape,\n\t\t\t\t\tmaxLength,\n\t\t\t\t\tmaxLength === remaining && skipLastNavigation,\n\t\t\t\t\tchunkCompressor.idCompressor,\n\t\t\t\t);\n\t\t\t\tremaining -= newChunk.topLevelLength;\n\t\t\t\toutput.push(newChunk);\n\t\t\t} else {\n\t\t\t\t// Slow path: copy tree into new basic chunk\n\t\t\t\toutput.push(newBasicChunkTree(cursor, chunkCompressor));\n\t\t\t\tremaining -= 1;\n\t\t\t\tif (!skipLastNavigation || remaining !== 0) {\n\t\t\t\t\tcursor.nextNode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: maybe make a pass over output to coalesce UniformChunks and/or convert other formats to UniformChunks where possible.\n\n\t// If output is large, group it into a tree of sequence chunks.\n\twhile (output.length > chunkCompressor.policy.sequenceChunkSplitThreshold) {\n\t\tconst chunkCount = Math.ceil(\n\t\t\toutput.length / chunkCompressor.policy.sequenceChunkSplitThreshold,\n\t\t);\n\t\tconst newOutput: TreeChunk[] = [];\n\t\t// Rounding down, and add an extra item to some of the chunks.\n\t\tconst chunkSize = Math.floor(output.length / chunkCount);\n\t\t// number of chunks to add an extra item to to make total line up.\n\t\tconst extra = output.length % chunkCount;\n\t\tlet previousEnd = 0;\n\t\tfor (let index = 0; index < chunkCount; index++) {\n\t\t\t// If we are in the first `extra` items, add an extra to this chunk.\n\t\t\tconst end = previousEnd + chunkSize + (index < extra ? 1 : 0);\n\t\t\tnewOutput.push(new SequenceChunk(output.slice(previousEnd, end)));\n\t\t\tpreviousEnd = end;\n\t\t}\n\t\tassert(previousEnd === output.length, 0x581 /* chunks should add up to total */);\n\t\toutput = newOutput;\n\t}\n\n\treturn output;\n}\n/**\n * Extracts values from the current cursor position according to the provided tree shape.\n *\n * Walks through the tree structure defined by the shape, extracting values from leaf nodes\n * and recursively processing child fields. If an ID compressor is provided, compressible\n * string values (stable node identifiers) will be recompressed for optimal storage.\n *\n * @param cursor - Tree cursor positioned at the node to extract values from\n * @param shape - The tree shape defining the structure to extract\n * @param values - Array to append the extracted values to\n * @param idCompressor - Optional compressor used to encode string values that are compressible by the idCompressor for in-memory representation.\n * If the idCompressor is not provided, the values will be the original uncompressed values.\n */\nexport function insertValues(\n\tcursor: ITreeCursorSynchronous,\n\tshape: TreeShape,\n\tvalues: Value[],\n\tidCompressor?: IIdCompressor,\n): void {\n\tassert(shape.type === cursor.type, 0x582 /* shape and type must match */);\n\n\t// TODO:Perf:\n\t// Fast path for already part of a uniform chunk with matching shape\n\n\t// Slow path: walk shape and cursor together, inserting values.\n\tif (shape.hasValue) {\n\t\tif (\n\t\t\ttypeof cursor.value === \"string\" &&\n\t\t\tidCompressor !== undefined &&\n\t\t\tisStableNodeIdentifier(cursor.value)\n\t\t) {\n\t\t\tvalues.push(idCompressor.tryRecompress(cursor.value) ?? cursor.value);\n\t\t} else {\n\t\t\tvalues.push(cursor.value);\n\t\t}\n\t}\n\tfor (const [key, childShape, length] of shape.fieldsArray) {\n\t\tcursor.enterField(key);\n\t\tlet count = 0;\n\t\tfor (let inNodes = cursor.firstNode(); inNodes; inNodes = cursor.nextNode()) {\n\t\t\tinsertValues(cursor, childShape, values, idCompressor);\n\t\t\tcount++;\n\t\t}\n\t\tcursor.exitField();\n\t\tassert(length === count, 0x583 /* unexpected field length */);\n\t}\n}\n\n/**\n * Read up to `maxTopLevelLength` nodes from `cursor`, stopping when limit is hit or type of node changes.\n *\n * This requires that the all trees with matching type match the provided shape.\n * This cannot be used if other shapes are possible for this type.\n *\n * If this stops early due to the type changing, `skipLastNavigation` is not involved:\n * `skipLastNavigation` only determines if the cursor will be left on the node after the last one (possibly exiting the field)\n * if the full length is used.\n *\n * @param idCompressor - compressor used to encoded string values that are compressible by the idCompressor for in-memory representation.\n * If the idCompressor is not provided, the values will be the original uncompressed values.\n */\nexport function uniformChunkFromCursor(\n\tcursor: ITreeCursorSynchronous,\n\tshape: TreeShape,\n\tmaxTopLevelLength: number,\n\tskipLastNavigation: boolean,\n\tidCompressor?: IIdCompressor,\n): UniformChunk {\n\t// TODO:\n\t// This could have a fast path for consuming already uniformly chunked data with matching shape.\n\n\tconst values: TreeValue[] = [];\n\tlet topLevelLength = 1;\n\twhile (topLevelLength <= maxTopLevelLength) {\n\t\tinsertValues(cursor, shape, values, idCompressor);\n\t\tif (topLevelLength === maxTopLevelLength) {\n\t\t\tif (!skipLastNavigation) {\n\t\t\t\tcursor.nextNode();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcursor.nextNode();\n\t\tif (cursor.type !== shape.type) {\n\t\t\tbreak;\n\t\t}\n\t\ttopLevelLength += 1;\n\t}\n\treturn new UniformChunk(shape.withTopLevelLength(topLevelLength), values, idCompressor);\n}\n"]}
1
+ {"version":3,"file":"chunkTree.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAqF;AAGrF,kDAkB6B;AAC7B,kDAAkD;AAClD,0DAAqE;AAErE,mDAA6C;AAC7C,yDAAmD;AACnD,uDAA6E;AAS7E;;GAEG;AACH,SAAgB,eAAe,CAC9B,MAAoC,EACpC,MAAoB,EACpB,yBAAoD;IAEpD,OAAO,IAAI,OAAO,CACjB,MAAM,EACN,MAAM,EACN,0BAAkB,CAAC,4BAA4B,EAC/C,0BAAkB,CAAC,4BAA4B,EAC/C,0BAAkB,CAAC,qBAAqB,EACxC,CAAC,IAA8B,EAAE,MAAgD,EAAE,EAAE,CACpF,sBAAsB,CACrB;QACC,MAAM;QACN,MAAM;QACN,yBAAyB;QACzB,MAAM;KACN,EACD,IAAI,CACJ,CACF,CAAC;AACH,CAAC;AAtBD,0CAsBC;AAaD;;;;;;;;GAQG;AACH,kEAAkE;AAClE,MAAa,WAAW;CAAG;AAA3B,kCAA2B;AAE3B;;;GAGG;AACU,QAAA,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AAQ7C,MAAa,OAAO;IAUnB,YACiB,MAAoC,EACpC,MAAoB,EACpB,2BAAmC,EACnC,4BAAoC,EACpC,qBAA6B;IAC7C,wDAAwD;IACvC,sBAGH;QATE,WAAM,GAAN,MAAM,CAA8B;QACpC,WAAM,GAAN,MAAM,CAAc;QACpB,gCAA2B,GAA3B,2BAA2B,CAAQ;QACnC,iCAA4B,GAA5B,4BAA4B,CAAQ;QACpC,0BAAqB,GAArB,qBAAqB,CAAQ;QAE5B,2BAAsB,GAAtB,s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iBAAiB,EAAE,CAAC;QAC5C,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;QAClD,IAAI,cAAc,KAAK,iBAAiB,EAAE,CAAC;YAC1C,IAAI,CAAC,kBAAkB,EAAE,CAAC;gBACzB,MAAM,CAAC,QAAQ,EAAE,CAAC;YACnB,CAAC;YACD,MAAM;QACP,CAAC;QACD,MAAM,CAAC,QAAQ,EAAE,CAAC;QAClB,IAAI,MAAM,CAAC,IAAI,KAAK,KAAK,CAAC,IAAI,EAAE,CAAC;YAChC,MAAM;QACP,CAAC;QACD,cAAc,IAAI,CAAC,CAAC;IACrB,CAAC;IACD,OAAO,IAAI,8BAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AACzF,CAAC;AA3BD,wDA2BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, debugAssert, oob, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport {\n\tCursorLocationType,\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\tLeafNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchemaSubscription,\n\ttype TreeValue,\n\ttype Value,\n\tmapCursorFields,\n\tMultiplicity,\n\tValueSchema,\n\ttype TreeChunk,\n\ttryGetChunk,\n\ttype SchemaAndPolicy,\n\ttype SchemaPolicy,\n} from \"../../core/index.js\";\nimport { getOrCreate } from \"../../util/index.js\";\nimport { isStableNodeIdentifier } from \"../node-identifier/index.js\";\n\nimport { BasicChunk } from \"./basicChunk.js\";\nimport { SequenceChunk } from \"./sequenceChunk.js\";\nimport { type FieldShape, TreeShape, UniformChunk } from \"./uniformChunk.js\";\nimport type { IncrementalEncodingPolicy } from \"./codec/index.js\";\n\nexport interface Disposable {\n\t/**\n\t * Cleans up resources used by this, such as inbound event registrations.\n\t */\n\tdispose(): void;\n}\n/**\n * Creates a ChunkPolicy which responds to schema changes.\n */\nexport function makeTreeChunker(\n\tschema: TreeStoredSchemaSubscription,\n\tpolicy: SchemaPolicy,\n\tshouldEncodeIncrementally: IncrementalEncodingPolicy,\n): IChunker {\n\treturn new Chunker(\n\t\tschema,\n\t\tpolicy,\n\t\tdefaultChunkPolicy.sequenceChunkInlineThreshold,\n\t\tdefaultChunkPolicy.sequenceChunkInlineThreshold,\n\t\tdefaultChunkPolicy.uniformChunkNodeCount,\n\t\t(type: TreeNodeSchemaIdentifier, shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>) =>\n\t\t\ttryShapeFromNodeSchema(\n\t\t\t\t{\n\t\t\t\t\tschema,\n\t\t\t\t\tpolicy,\n\t\t\t\t\tshouldEncodeIncrementally,\n\t\t\t\t\tshapes,\n\t\t\t\t},\n\t\t\t\ttype,\n\t\t\t),\n\t);\n}\n\n/**\n * Extends ChunkPolicy to include stateful details required by ChunkedForest.\n *\n * This extra complexity is mostly due to the fact that schema can change over time,\n * and that chunk policy uses caching which thus needs invalidation.\n */\nexport interface IChunker extends ChunkPolicy, Disposable {\n\treadonly schema: TreeStoredSchemaSubscription;\n\tclone(schema: TreeStoredSchemaSubscription): IChunker;\n}\n\n/**\n * Indicates that there are multiple possible `TreeShape` trees with a given type can have.\n *\n * @remarks\n * For example, a schema transitively containing a sequence field, optional field, or allowing multiple child types will be Polymorphic.\n * See `tryShapeFromNodeSchema` for how to tell if a type is Polymorphic.\n *\n * TODO: cache some of the possible shapes here.\n */\n// eslint-disable-next-line @typescript-eslint/no-extraneous-class\nexport class Polymorphic {}\n\n/**\n * See `Polymorphic`.\n * For now Polymorphic is stateless, so just use a singleton.\n */\nexport const polymorphic = new Polymorphic();\n\n/**\n * Information about the possible shapes a tree could take based on its type.\n * Note that this information is for a specific version of the schema.\n */\nexport type ShapeInfo = TreeShape | Polymorphic;\n\nexport class Chunker implements IChunker {\n\t/**\n\t * Cache for information about possible shapes for types.\n\t * Corresponds to the version of the schema in `schema`.\n\t * Cleared when `schema` changes.\n\t */\n\tprivate readonly typeShapes: Map<TreeNodeSchemaIdentifier, ShapeInfo> = new Map();\n\n\tprivate unregisterSchemaCallback: (() => void) | undefined;\n\n\tpublic constructor(\n\t\tpublic readonly schema: TreeStoredSchemaSubscription,\n\t\tpublic readonly policy: SchemaPolicy,\n\t\tpublic readonly sequenceChunkSplitThreshold: number,\n\t\tpublic readonly sequenceChunkInlineThreshold: number,\n\t\tpublic readonly uniformChunkNodeCount: number,\n\t\t// eslint-disable-next-line @typescript-eslint/no-shadow\n\t\tprivate readonly tryShapeFromNodeSchema: (\n\t\t\ttype: TreeNodeSchemaIdentifier,\n\t\t\tshapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>,\n\t\t) => ShapeInfo,\n\t) {}\n\n\tpublic clone(schema: TreeStoredSchemaSubscription): IChunker {\n\t\t// This does not preserve the cache.\n\t\t// This is probably fine, but is a potential way it could be optimized in the future (with care to ensure invalidation work properly).\n\t\treturn new Chunker(\n\t\t\tschema,\n\t\t\tthis.policy,\n\t\t\tthis.sequenceChunkSplitThreshold,\n\t\t\tthis.sequenceChunkInlineThreshold,\n\t\t\tthis.uniformChunkNodeCount,\n\t\t\tthis.tryShapeFromNodeSchema,\n\t\t);\n\t}\n\n\tpublic shapeFromSchema(schema: TreeNodeSchemaIdentifier): ShapeInfo {\n\t\tconst cached = this.typeShapes.get(schema);\n\t\tif (cached !== undefined) {\n\t\t\treturn cached;\n\t\t}\n\t\tthis.unregisterSchemaCallback = this.schema.events.on(\"afterSchemaChange\", () =>\n\t\t\tthis.schemaChanged(),\n\t\t);\n\t\treturn this.tryShapeFromNodeSchema(schema, this.typeShapes);\n\t}\n\n\tpublic dispose(): void {\n\t\t// Remove subscription for changes via dependent.\n\t\tthis.schemaChanged();\n\t}\n\n\tprivate schemaChanged(): void {\n\t\tthis.typeShapes.clear();\n\t\tif (this.unregisterSchemaCallback) {\n\t\t\tthis.unregisterSchemaCallback();\n\t\t\tthis.unregisterSchemaCallback = undefined;\n\t\t}\n\t}\n}\n\n/**\n * Get a TreeChunk for the current node (and its children) of cursor.\n * This will copy if needed, but add refs to existing chunks which hold the data.\n *\n * @param cursor - cursor in nodes mode\n */\nexport function chunkTree(cursor: ITreeCursorSynchronous, policy: ChunkCompressor): TreeChunk {\n\treturn chunkRange(cursor, policy, 1, true)[0] ?? oob();\n}\n\n/**\n * Get a TreeChunk[] for the current field (and its children) of cursor.\n * This will copy if needed, but add refs to existing chunks which hold the data.\n */\nexport function chunkField(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): TreeChunk[] {\n\tconst length = cursor.getFieldLength();\n\tconst started = cursor.firstNode();\n\tdebugAssert(\n\t\t() => started === (length !== 0) || \"only 0 length fields should not have nodes\",\n\t);\n\treturn chunkRange(cursor, policy, length, false);\n}\n\n/**\n * Get a TreeChunk for the current field (and its children) of cursor.\n * Like {@link chunkField}, but forces the results into a single TreeChunk.\n */\nexport function chunkFieldSingle(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): TreeChunk {\n\tconst chunks = chunkField(cursor, policy);\n\treturn combineChunks(chunks);\n}\n\n/**\n * Create a single TreeChunk from an array of TreeChunks.\n * @remarks\n * This takes ownership of the provided TreeChunk references, and returns an owned referenced.\n */\nexport function combineChunks(chunks: TreeChunk[]): TreeChunk {\n\tif (chunks.length === 1) {\n\t\treturn chunks[0] ?? oob();\n\t}\n\treturn new SequenceChunk(chunks);\n}\n\n/**\n * Get a BasicChunk for the current node (and its children) of cursor.\n * This will copy if needed, and add refs to existing chunks which hold the data.\n */\nexport function basicChunkTree(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): BasicChunk {\n\t// symbol based fast path to check for BasicChunk:\n\t// return existing chunk with a increased ref count if possible.\n\tconst chunk = tryGetChunk(cursor);\n\tif (chunk instanceof BasicChunk) {\n\t\tchunk.referenceAdded();\n\t\treturn chunk;\n\t}\n\n\treturn newBasicChunkTree(cursor, policy);\n}\n\nexport function makePolicy(policy?: Partial<ChunkPolicy>): ChunkPolicy {\n\tconst withDefaults = { ...defaultChunkPolicy, ...policy };\n\t// TODO: move this to a top level policy validation\n\tassert(\n\t\twithDefaults.sequenceChunkSplitThreshold >= 2,\n\t\t0x57d /* sequenceChunkThreshold must be at least 2 */,\n\t);\n\n\treturn withDefaults;\n}\n\nexport interface ShapeFromSchemaParameters extends SchemaAndPolicy {\n\t/**\n\t * Policy function to determine if a field should be encoded incrementally.\n\t * Incrementally encoding requires the subtree to not start in the middle of a larger uniform chunk.\n\t * Thus returning true from this callback indicates that shapes should not be produced which could\n\t *contain the incremental portion as a part of a larger shape.\n\t */\n\treadonly shouldEncodeIncrementally: IncrementalEncodingPolicy;\n\t/**\n\t * A cache for shapes which may be read and/or updated.\n\t * As the shape is a function of the other members of `ShapeFromSchemaParameters`,\n\t * it must be replaced or cleared if any of the properties other than this cache are modified.\n\t */\n\treadonly shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>;\n}\n\n/**\n * A TreeFieldStoredSchema with some additional context about where it is in the tree.\n */\nexport interface FieldSchemaWithContext {\n\t/**\n\t * The identifier of the specific field schema to analyze for shape uniformity.\n\t */\n\treadonly fieldSchema: TreeFieldStoredSchema;\n\t/**\n\t * The identifier of the parent node schema containing this field.\n\t * If undefined, this is a root field.\n\t */\n\treadonly parentNodeSchema?: TreeNodeSchemaIdentifier;\n\t/**\n\t * The field key/name used to identify this field within the parent node.\n\t */\n\treadonly key: FieldKey;\n}\n\n/**\n * Analyzes a tree node schema to determine if it has a single, uniform shape that can be optimized for chunking.\n * If the schema defines a tree structure with a deterministic, fixed shape (no optional fields, no sequences,\n * single child types), returns a TreeShape that can be used for efficient uniform chunking. Otherwise,\n * returns Polymorphic to indicate the shape varies and should use basic chunking.\n *\n * @param context - {@link ShapeFromSchemaParameters}.\n * @param nodeSchema - The identifier of the specific node schema to analyze for shape uniformity.\n * @returns TreeShape if the schema has a uniform shape, or Polymorphic if shape varies.\n *\n * @remarks\n * The determination here is conservative. `shouldEncodeIncrementally` is used to split up shapes so incrementally\n * encoded schema are not part of larger shapes. It also does not tolerate optional or sequence fields, nor does it\n * optimize for patterns of specific values.\n */\nexport function tryShapeFromNodeSchema(\n\tcontext: ShapeFromSchemaParameters,\n\tnodeSchema: TreeNodeSchemaIdentifier,\n): ShapeInfo {\n\tconst { schema, shapes } = context;\n\treturn getOrCreate(shapes, nodeSchema, () => {\n\t\tconst treeSchema = schema.nodeSchema.get(nodeSchema) ?? fail(0xaf9 /* missing schema */);\n\t\tif (treeSchema instanceof LeafNodeStoredSchema) {\n\t\t\t// Allow all string values (but only string values) to be compressed by the id compressor.\n\t\t\t// This allows compressing all compressible identifiers without requiring additional context to know which values could be identifiers.\n\t\t\t// Attempting to compress other string shouldn't have significant overhead,\n\t\t\t// and if any of them do end up compressing, that's a benefit not a bug.\n\t\t\treturn treeSchema.leafValue === ValueSchema.String\n\t\t\t\t? new TreeShape(nodeSchema, true, [], true)\n\t\t\t\t: new TreeShape(nodeSchema, true, [], false);\n\t\t}\n\t\tif (treeSchema instanceof ObjectNodeStoredSchema) {\n\t\t\tconst fieldsArray: FieldShape[] = [];\n\t\t\tfor (const [key, fieldSchema] of treeSchema.objectNodeFields) {\n\t\t\t\tconst fieldShape = tryShapeFromFieldSchema(context, {\n\t\t\t\t\tfieldSchema,\n\t\t\t\t\tparentNodeSchema: nodeSchema,\n\t\t\t\t\tkey,\n\t\t\t\t});\n\t\t\t\tif (fieldShape === undefined) {\n\t\t\t\t\treturn polymorphic;\n\t\t\t\t}\n\t\t\t\tfieldsArray.push(fieldShape);\n\t\t\t}\n\t\t\treturn new TreeShape(nodeSchema, false, fieldsArray);\n\t\t}\n\t\treturn polymorphic;\n\t});\n}\n\n/**\n * Same as {@link tryShapeFromNodeSchema} but for fields with {@link FieldSchemaWithContext} instead of a nodeSchema.\n *\n * @param context - {@link ShapeFromFieldSchemaParameters}.\n * @param fieldSchemaWithContext - {@link FieldSchemaWithContext}.\n * @returns FieldShape if the field has a uniform shape, or undefined if the field is polymorphic.\n */\nexport function tryShapeFromFieldSchema(\n\tcontext: ShapeFromSchemaParameters,\n\tfieldSchemaWithContext: FieldSchemaWithContext,\n): FieldShape | undefined {\n\tconst { schema, policy, shouldEncodeIncrementally, shapes } = context;\n\tconst { fieldSchema, parentNodeSchema, key } = fieldSchemaWithContext;\n\t// If this field should be encoded incrementally, use polymorphic shape so that they\n\t// are chunked separately and can be re-used across encodings if they do not change.\n\tif (shouldEncodeIncrementally(parentNodeSchema, key)) {\n\t\treturn undefined;\n\t}\n\tconst kind = policy.fieldKinds.get(fieldSchema.kind) ?? fail(0xafa /* missing FieldKind */);\n\tif (kind.multiplicity !== Multiplicity.Single) {\n\t\treturn undefined;\n\t}\n\tif (fieldSchema.types?.size !== 1) {\n\t\treturn undefined;\n\t}\n\tconst childType = [...fieldSchema.types][0] ?? oob();\n\tconst childShape = tryShapeFromNodeSchema(\n\t\t{\n\t\t\tschema,\n\t\t\tpolicy,\n\t\t\tshouldEncodeIncrementally,\n\t\t\tshapes,\n\t\t},\n\t\tchildType,\n\t);\n\tif (childShape instanceof Polymorphic) {\n\t\treturn undefined;\n\t}\n\treturn [key, childShape, 1];\n}\n\n/**\n * Default settings for use for {@link ChunkPolicy}.\n * Use `makeTreeChunker` to create a policy with the defaults, but leverages to schema.\n */\nexport const defaultChunkPolicy: ChunkPolicy = {\n\t// Currently ChunkedForest and BasicTreeCursor don't handle SequenceChunks very efficiently:\n\t// they likely add more overhead than they save for now, so don't create them.\n\tsequenceChunkSplitThreshold: Number.POSITIVE_INFINITY,\n\tsequenceChunkInlineThreshold: Number.POSITIVE_INFINITY,\n\t// Current UniformChunk handling doesn't scale well to large chunks, so set a modest size limit:\n\tuniformChunkNodeCount: 400,\n\t// Without knowing what the schema is, all shapes are possible.\n\t// Use `makeTreeChunker` to do better.\n\tshapeFromSchema: () => polymorphic,\n};\n\nexport const basicOnlyChunkPolicy: ChunkPolicy = {\n\tsequenceChunkSplitThreshold: Number.POSITIVE_INFINITY,\n\tsequenceChunkInlineThreshold: Number.POSITIVE_INFINITY,\n\tuniformChunkNodeCount: 0,\n\tshapeFromSchema: () => polymorphic,\n};\n\n/**\n * Policy for how to chunk a tree.\n */\nexport interface ChunkPolicy {\n\t/**\n\t * Group sequences longer than this into into sequence chunks of this length or less.\n\t *\n\t * Must be at least 2.\n\t * Can be set to `Number.POSITIVE_INFINITY` to never introduce extra sequence chunks.\n\t */\n\treadonly sequenceChunkSplitThreshold: number;\n\n\t/**\n\t * SequenceChunks this long or shorter may get inlined into their parent chunk.\n\t */\n\treadonly sequenceChunkInlineThreshold: number;\n\n\t/**\n\t * Maximum total nodes to put in a UniformChunk.\n\t */\n\treadonly uniformChunkNodeCount: number;\n\n\t/**\n\t * Returns information about the shapes trees of type `schema` can take.\n\t */\n\tshapeFromSchema(schema: TreeNodeSchemaIdentifier): ShapeInfo;\n}\n\nexport interface ChunkCompressor {\n\treadonly policy: ChunkPolicy;\n\t/**\n\t * If the idCompressor is provided, {@link UniformChunk}s with identifiers will be encoded for its in-memory representation.\n\t * @remarks\n\t * This compression applies to {@link UniformChunk}s when {@link TreeShape.maybeDecompressedStringAsNumber} is set.\n\t * If the `policy` does not use UniformChunks or does not set `maybeDecompressedStringAsNumber`, then no compression will be applied even when providing `idCompressor`.\n\t */\n\treadonly idCompressor: IIdCompressor | undefined;\n}\n\nfunction newBasicChunkTree(\n\tcursor: ITreeCursorSynchronous,\n\tpolicy: ChunkCompressor,\n): BasicChunk {\n\treturn new BasicChunk(\n\t\tcursor.type,\n\t\tnew Map(mapCursorFields(cursor, () => [cursor.getFieldKey(), chunkField(cursor, policy)])),\n\t\tcursor.value,\n\t);\n}\n\n/**\n * Chunk a portion of a field.\n *\n * @param cursor - cursor at the starting node in the field.\n * @param policy - heuristics to impact chunking\n * @param length - how many nodes to process (at the top level). When 0, the cursor is not moved, and may be at the end of the field (and thus in Fields mode)\n * @param skipLastNavigation - if true, leaves the cursor at the last node instead of moving off of it. Invalid if length is 0.\n */\nexport function chunkRange(\n\tcursor: ITreeCursorSynchronous,\n\tchunkCompressor: ChunkCompressor,\n\tlength: number,\n\tskipLastNavigation: boolean,\n): TreeChunk[] {\n\tassert(\n\t\t!(skipLastNavigation && length === 0),\n\t\t0xb58 /* Cannot skip last navigation if length is 0 and thus last navigation already occurred. */,\n\t);\n\tassert(\n\t\t(cursor.mode === CursorLocationType.Nodes) === length > 0,\n\t\t0xb59 /* Should be in nodes mode if not past end */,\n\t);\n\tlet output: TreeChunk[] = [];\n\tlet remaining = length;\n\twhile (remaining > 0) {\n\t\tassert(cursor.mode === CursorLocationType.Nodes, 0x57f /* should be in nodes */);\n\t\tconst start = cursor.chunkStart;\n\t\tlet reusedChunk = false;\n\t\t// symbol based fast path to check for chunk:\n\t\t// return existing chunk with a increased ref count if possible.\n\t\tif (start === cursor.fieldIndex) {\n\t\t\tconst chunkLength = cursor.chunkLength;\n\t\t\tif (chunkLength <= remaining) {\n\t\t\t\tconst chunk = tryGetChunk(cursor);\n\t\t\t\tif (chunk !== undefined) {\n\t\t\t\t\tif (\n\t\t\t\t\t\tchunk instanceof SequenceChunk &&\n\t\t\t\t\t\tchunk.subChunks.length <= chunkCompressor.policy.sequenceChunkInlineThreshold\n\t\t\t\t\t) {\n\t\t\t\t\t\t// If sequence chunk, and its very short, inline it.\n\t\t\t\t\t\t// Note that this is not recursive: there may be short sequences nested below this which are not inlined.\n\t\t\t\t\t\tfor (const subChunk of chunk.subChunks) {\n\t\t\t\t\t\t\tsubChunk.referenceAdded();\n\t\t\t\t\t\t\toutput.push(subChunk);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tchunk.referenceAdded();\n\t\t\t\t\toutput.push(chunk);\n\t\t\t\t\tremaining -= chunkLength;\n\t\t\t\t\treusedChunk = true;\n\t\t\t\t\tlet seek = chunkLength;\n\t\t\t\t\tif (skipLastNavigation && remaining === 0) {\n\t\t\t\t\t\tseek -= 1;\n\t\t\t\t\t}\n\t\t\t\t\tcursor.seekNodes(seek);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif (!reusedChunk) {\n\t\t\tassert(cursor.mode === CursorLocationType.Nodes, 0x580 /* should be in nodes */);\n\t\t\t// TODO: if provided, use schema to consider using UniformChunks\n\t\t\tconst type = cursor.type;\n\t\t\tconst shape = chunkCompressor.policy.shapeFromSchema(type);\n\t\t\tif (shape instanceof TreeShape) {\n\t\t\t\tconst nodesPerTopLevelNode = shape.positions.length;\n\t\t\t\tconst maxTopLevelLength = Math.ceil(\n\t\t\t\t\tnodesPerTopLevelNode / chunkCompressor.policy.uniformChunkNodeCount,\n\t\t\t\t);\n\t\t\t\tconst maxLength = Math.min(maxTopLevelLength, remaining);\n\t\t\t\tconst newChunk = uniformChunkFromCursor(\n\t\t\t\t\tcursor,\n\t\t\t\t\tshape,\n\t\t\t\t\tmaxLength,\n\t\t\t\t\tmaxLength === remaining && skipLastNavigation,\n\t\t\t\t\tchunkCompressor.idCompressor,\n\t\t\t\t);\n\t\t\t\tremaining -= newChunk.topLevelLength;\n\t\t\t\toutput.push(newChunk);\n\t\t\t} else {\n\t\t\t\t// Slow path: copy tree into new basic chunk\n\t\t\t\toutput.push(newBasicChunkTree(cursor, chunkCompressor));\n\t\t\t\tremaining -= 1;\n\t\t\t\tif (!skipLastNavigation || remaining !== 0) {\n\t\t\t\t\tcursor.nextNode();\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// TODO: maybe make a pass over output to coalesce UniformChunks and/or convert other formats to UniformChunks where possible.\n\n\t// If output is large, group it into a tree of sequence chunks.\n\twhile (output.length > chunkCompressor.policy.sequenceChunkSplitThreshold) {\n\t\tconst chunkCount = Math.ceil(\n\t\t\toutput.length / chunkCompressor.policy.sequenceChunkSplitThreshold,\n\t\t);\n\t\tconst newOutput: TreeChunk[] = [];\n\t\t// Rounding down, and add an extra item to some of the chunks.\n\t\tconst chunkSize = Math.floor(output.length / chunkCount);\n\t\t// number of chunks to add an extra item to to make total line up.\n\t\tconst extra = output.length % chunkCount;\n\t\tlet previousEnd = 0;\n\t\tfor (let index = 0; index < chunkCount; index++) {\n\t\t\t// If we are in the first `extra` items, add an extra to this chunk.\n\t\t\tconst end = previousEnd + chunkSize + (index < extra ? 1 : 0);\n\t\t\tnewOutput.push(new SequenceChunk(output.slice(previousEnd, end)));\n\t\t\tpreviousEnd = end;\n\t\t}\n\t\tassert(previousEnd === output.length, 0x581 /* chunks should add up to total */);\n\t\toutput = newOutput;\n\t}\n\n\treturn output;\n}\n/**\n * Extracts values from the current cursor position according to the provided tree shape.\n *\n * Walks through the tree structure defined by the shape, extracting values from leaf nodes\n * and recursively processing child fields. If an ID compressor is provided, compressible\n * string values (stable node identifiers) will be recompressed for optimal storage.\n *\n * @param cursor - Tree cursor positioned at the node to extract values from\n * @param shape - The tree shape defining the structure to extract\n * @param values - Array to append the extracted values to\n * @param idCompressor - Optional compressor used to encode string values that are compressible by the idCompressor for in-memory representation.\n * If the idCompressor is not provided, the values will be the original uncompressed values.\n */\nexport function insertValues(\n\tcursor: ITreeCursorSynchronous,\n\tshape: TreeShape,\n\tvalues: Value[],\n\tidCompressor?: IIdCompressor,\n): void {\n\tassert(shape.type === cursor.type, 0x582 /* shape and type must match */);\n\n\t// TODO:Perf:\n\t// Fast path for already part of a uniform chunk with matching shape\n\n\t// Slow path: walk shape and cursor together, inserting values.\n\tif (shape.hasValue) {\n\t\tif (\n\t\t\ttypeof cursor.value === \"string\" &&\n\t\t\tidCompressor !== undefined &&\n\t\t\tisStableNodeIdentifier(cursor.value)\n\t\t) {\n\t\t\tvalues.push(idCompressor.tryRecompress(cursor.value) ?? cursor.value);\n\t\t} else {\n\t\t\tvalues.push(cursor.value);\n\t\t}\n\t}\n\tfor (const [key, childShape, length] of shape.fieldsArray) {\n\t\tcursor.enterField(key);\n\t\tlet count = 0;\n\t\tfor (let inNodes = cursor.firstNode(); inNodes; inNodes = cursor.nextNode()) {\n\t\t\tinsertValues(cursor, childShape, values, idCompressor);\n\t\t\tcount++;\n\t\t}\n\t\tcursor.exitField();\n\t\tassert(length === count, 0x583 /* unexpected field length */);\n\t}\n}\n\n/**\n * Read up to `maxTopLevelLength` nodes from `cursor`, stopping when limit is hit or type of node changes.\n *\n * This requires that the all trees with matching type match the provided shape.\n * This cannot be used if other shapes are possible for this type.\n *\n * If this stops early due to the type changing, `skipLastNavigation` is not involved:\n * `skipLastNavigation` only determines if the cursor will be left on the node after the last one (possibly exiting the field)\n * if the full length is used.\n *\n * @param idCompressor - compressor used to encoded string values that are compressible by the idCompressor for in-memory representation.\n * If the idCompressor is not provided, the values will be the original uncompressed values.\n */\nexport function uniformChunkFromCursor(\n\tcursor: ITreeCursorSynchronous,\n\tshape: TreeShape,\n\tmaxTopLevelLength: number,\n\tskipLastNavigation: boolean,\n\tidCompressor?: IIdCompressor,\n): UniformChunk {\n\t// TODO:\n\t// This could have a fast path for consuming already uniformly chunked data with matching shape.\n\n\tconst values: TreeValue[] = [];\n\tlet topLevelLength = 1;\n\twhile (topLevelLength <= maxTopLevelLength) {\n\t\tinsertValues(cursor, shape, values, idCompressor);\n\t\tif (topLevelLength === maxTopLevelLength) {\n\t\t\tif (!skipLastNavigation) {\n\t\t\t\tcursor.nextNode();\n\t\t\t}\n\t\t\tbreak;\n\t\t}\n\t\tcursor.nextNode();\n\t\tif (cursor.type !== shape.type) {\n\t\t\tbreak;\n\t\t}\n\t\ttopLevelLength += 1;\n\t}\n\treturn new UniformChunk(shape.withTopLevelLength(topLevelLength), values, idCompressor);\n}\n"]}
@@ -138,15 +138,15 @@ class ChunkedForest {
138
138
  const sourceField = parent.mutableChunk.fields.get(parent.key) ?? [];
139
139
  (0, index_js_2.assertValidRange)(source, sourceField);
140
140
  const newField = sourceField.splice(source.start, source.end - source.start);
141
- if (destination !== undefined) {
142
- (0, internal_1.assert)(!this.forest.roots.fields.has(destination), 0x7af /* Destination must be a new empty detached field */);
143
- if (newField.length > 0) {
144
- this.forest.roots.fields.set(destination, newField);
141
+ if (destination === undefined) {
142
+ for (const child of newField) {
143
+ child.referenceRemoved();
145
144
  }
146
145
  }
147
146
  else {
148
- for (const child of newField) {
149
- child.referenceRemoved();
147
+ (0, internal_1.assert)(!this.forest.roots.fields.has(destination), 0x7af /* Destination must be a new empty detached field */);
148
+ if (newField.length > 0) {
149
+ this.forest.roots.fields.set(destination, newField);
150
150
  }
151
151
  }
152
152
  // This check is performed after the transfer to ensure that the field is not removed in scenarios
@@ -1 +1 @@
1
- {"version":3,"file":"chunkedForest.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkedForest.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,+DAA6D;AAE7D,kEAAwE;AAGxE,kDA0B6B;AAC7B,kDAM6B;AAE7B,mDAAmF;AACnF,iDAAsF;AAEtF,SAAS,QAAQ;IAChB,OAAO,IAAI,0BAAU,CAAC,+BAAoB,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AACxD,CAAC;AAOD;;;;GAIG;AACH,MAAa,aAAa;IAOzB;;;;;OAKG;IACH,YACQ,KAAiB,EACR,MAAoC,EACpC,OAAiB,EACjB,UAAqB,IAAI,oBAAS,EAAE,EACpC,YAA4B;QAJrC,UAAK,GAAL,KAAK,CAAY;QACR,WAAM,GAAN,MAAM,CAA8B;QACpC,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAA6B;QACpC,iBAAY,GAAZ,YAAY,CAAgB;QAf5B,kBAAa,GAAgC,IAAI,GAAG,EAAE,CAAC;QAC/D,gCAAU,IAAA,4BAAa,GAAgB,EAAC;QACjC,WAAM,GAA6B,uBAAA,IAAI,6BAAQ,CAAC;QAyNxD,gCAA2B,GAAG,CAAC,CAAC;IA3MrC,CAAC;IAEJ,IAAW,OAAO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O,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,KAAK,GAAG,uCAA4B,CAAC,OAAO,CAAC;QAClD,IAAI,CAAC,qBAAqB,CAAC,uBAAY,CAAC,CAAC;IAC1C,CAAC;CACD;AAED;;GAEG;AACH,SAAgB,kBAAkB,CACjC,OAAiB,EACjB,OAAmB,EACnB,YAA4B;IAE5B,OAAO,IAAI,aAAa,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AACtF,CAAC;AAND,gDAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert, oob, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport {\n\ttype Anchor,\n\tAnchorSet,\n\ttype AnnouncedVisitor,\n\ttype DeltaVisitor,\n\ttype DetachedField,\n\ttype FieldAnchor,\n\ttype FieldKey,\n\ttype ForestEvents,\n\ttype IEditableForest,\n\ttype ITreeCursorSynchronous,\n\ttype ITreeSubscriptionCursor,\n\tITreeSubscriptionCursorState,\n\ttype PlaceIndex,\n\ttype Range,\n\tTreeNavigationResult,\n\ttype TreeStoredSchemaSubscription,\n\ttype UpPath,\n\taboveRootPlaceholder,\n\tcombineVisitors,\n\tdetachedFieldAsKey,\n\tmapCursorField,\n\trootFieldKey,\n\ttype ChunkedCursor,\n\ttype TreeChunk,\n\ttype DeltaDetachedNodeId,\n} from \"../../core/index.js\";\nimport {\n\tassertValidRange,\n\tbrand,\n\tgetLast,\n\tgetOrAddEmptyToMap,\n\thasSome,\n} from \"../../util/index.js\";\n\nimport { BasicChunk, BasicChunkCursor, type SiblingsOrKey } from \"./basicChunk.js\";\nimport { type IChunker, basicChunkTree, chunkField, chunkTree } from \"./chunkTree.js\";\n\nfunction makeRoot(): BasicChunk {\n\treturn new BasicChunk(aboveRootPlaceholder, new Map());\n}\n\ninterface StackNode {\n\tmutableChunk: BasicChunk;\n\tkey: FieldKey;\n}\n\n/**\n * Implementation of IEditableForest based on copy on write chunks.\n *\n * This implementation focuses on performance.\n */\nexport class ChunkedForest implements IEditableForest {\n\tprivate activeVisitor?: DeltaVisitor;\n\n\tprivate readonly deltaVisitors: Set<() => AnnouncedVisitor> = new Set();\n\treadonly #events = createEmitter<ForestEvents>();\n\tpublic readonly events: Listenable<ForestEvents> = this.#events;\n\n\t/**\n\t * @param roots - dummy node above the root under which detached fields are stored. All content of the forest is reachable from this.\n\t * @param schema - schema which all content in this forest is assumed to comply with.\n\t * @param chunker - Chunking policy. TODO: dispose of this when forest is disposed.\n\t * @param anchors - anchorSet used to track location in this forest across changes. Callers of applyDelta must ensure this is updated accordingly.\n\t */\n\tpublic constructor(\n\t\tpublic roots: BasicChunk,\n\t\tpublic readonly schema: TreeStoredSchemaSubscription,\n\t\tpublic readonly chunker: IChunker,\n\t\tpublic readonly anchors: AnchorSet = new AnchorSet(),\n\t\tpublic readonly idCompressor?: IIdCompressor,\n\t) {}\n\n\tpublic get isEmpty(): boolean {\n\t\treturn this.roots.fields.size === 0;\n\t}\n\n\tpublic clone(schema: TreeStoredSchemaSubscription, anchors: AnchorSet): ChunkedForest {\n\t\tthis.roots.referenceAdded();\n\t\treturn new ChunkedForest(this.roots, schema, this.chunker.clone(schema), anchors);\n\t}\n\n\tpublic chunkField(cursor: ITreeCursorSynchronous): TreeChunk[] {\n\t\treturn chunkField(cursor, { idCompressor: this.idCompressor, policy: this.chunker });\n\t}\n\n\tpublic forgetAnchor(anchor: Anchor): void {\n\t\tthis.anchors.forget(anchor);\n\t}\n\n\tpublic registerAnnouncedVisitor(visitor: () => AnnouncedVisitor): void {\n\t\tthis.deltaVisitors.add(visitor);\n\t}\n\n\tpublic deregisterAnnouncedVisitor(visitor: () => AnnouncedVisitor): void {\n\t\tthis.deltaVisitors.delete(visitor);\n\t}\n\n\tpublic acquireVisitor(): DeltaVisitor {\n\t\tassert(\n\t\t\tthis.activeVisitor === undefined,\n\t\t\t0x76a /* Must release existing visitor before acquiring another */,\n\t\t);\n\n\t\tif (this.roots.isShared()) {\n\t\t\tthis.roots = this.roots.clone();\n\t\t}\n\n\t\tconst forestVisitor = {\n\t\t\tforest: this,\n\t\t\t// Current location in the tree, as a non-shared BasicChunk (TODO: support in-place modification of other chunk formats when possible).\n\t\t\t// Start above root detached sequences.\n\t\t\tmutableChunkStack: [] as StackNode[],\n\t\t\tmutableChunk: this.roots as BasicChunk | undefined,\n\t\t\tgetParent(): StackNode {\n\t\t\t\tassert(hasSome(this.mutableChunkStack), 0x532 /* invalid access to root's parent */);\n\t\t\t\treturn getLast(this.mutableChunkStack);\n\t\t\t},\n\t\t\tfree(): void {\n\t\t\t\tthis.mutableChunk = undefined;\n\t\t\t\tthis.mutableChunkStack.length = 0;\n\t\t\t\tassert(\n\t\t\t\t\tthis.forest.activeVisitor !== undefined,\n\t\t\t\t\t0x76b /* Multiple free calls for same visitor */,\n\t\t\t\t);\n\t\t\t\tthis.forest.activeVisitor = undefined;\n\t\t\t},\n\t\t\tdestroy(detachedField: FieldKey, count: number): void {\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tthis.forest.roots.fields.delete(detachedField);\n\t\t\t},\n\t\t\tcreate(content: readonly ITreeCursorSynchronous[], destination: FieldKey): void {\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tconst chunks: TreeChunk[] = content.map((c) =>\n\t\t\t\t\tchunkTree(c, {\n\t\t\t\t\t\tpolicy: this.forest.chunker,\n\t\t\t\t\t\tidCompressor: this.forest.idCompressor,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.forest.roots.fields.set(destination, chunks);\n\t\t\t\tthis.forest.#events.emit(\"afterRootFieldCreated\", destination);\n\t\t\t},\n\t\t\tattach(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.attachEdit(source, count, destination);\n\t\t\t},\n\t\t\tdetach(source: Range, destination: FieldKey, id: DeltaDetachedNodeId): void {\n\t\t\t\tthis.detachEdit(source, destination);\n\t\t\t},\n\t\t\t/**\n\t\t\t * Attaches the range into the current field by transferring it from the given source path.\n\t\t\t * Does not invalidate dependents.\n\t\t\t * @param source - The the range to be attached.\n\t\t\t * @param destination - The index in the current field at which to attach the content.\n\t\t\t */\n\t\t\tattachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tconst sourceField = this.forest.roots.fields.get(source) ?? [];\n\t\t\t\tthis.forest.roots.fields.delete(source);\n\t\t\t\tif (sourceField.length === 0) {\n\t\t\t\t\treturn; // Prevent creating 0 sized fields when inserting empty into empty.\n\t\t\t\t}\n\n\t\t\t\tconst parent = this.getParent();\n\t\t\t\tconst destinationField = getOrAddEmptyToMap(parent.mutableChunk.fields, parent.key);\n\t\t\t\t// TODO: this will fail for very large moves due to argument limits.\n\t\t\t\tdestinationField.splice(destination, 0, ...sourceField);\n\t\t\t},\n\t\t\t/**\n\t\t\t * Detaches the range from the current field and transfers it to the given destination if any.\n\t\t\t * Does not invalidate dependents.\n\t\t\t * @param source - The bounds of the range to be detached from the current field.\n\t\t\t * @param destination - If specified, the destination to transfer the detached range to.\n\t\t\t * If not specified, the detached range is destroyed.\n\t\t\t */\n\t\t\tdetachEdit(source: Range, destination: FieldKey | undefined): void {\n\t\t\t\t// TODO: optimize this to perform in-place replace in uniform chunks when attach edits bring the chunk back to its original shape.\n\t\t\t\t// This should result in 3 cases:\n\t\t\t\t// 1. In-place update of uniform chunk. No allocations, no ref count changes, no new TreeChunks.\n\t\t\t\t// 2. Uniform chunk is shared: copy it (and parent path as needed), and update the copy.\n\t\t\t\t// 3. Fallback to detach then attach (Which will copy parents and convert to basic chunks as needed).\n\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tconst parent = this.getParent();\n\t\t\t\tconst sourceField = parent.mutableChunk.fields.get(parent.key) ?? [];\n\n\t\t\t\tassertValidRange(source, sourceField);\n\t\t\t\tconst newField = sourceField.splice(source.start, source.end - source.start);\n\n\t\t\t\tif (destination !== undefined) {\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!this.forest.roots.fields.has(destination),\n\t\t\t\t\t\t0x7af /* Destination must be a new empty detached field */,\n\t\t\t\t\t);\n\t\t\t\t\tif (newField.length > 0) {\n\t\t\t\t\t\tthis.forest.roots.fields.set(destination, newField);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tfor (const child of newField) {\n\t\t\t\t\t\tchild.referenceRemoved();\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// This check is performed after the transfer to ensure that the field is not removed in scenarios\n\t\t\t\t// where the source and destination are the same.\n\t\t\t\tif (sourceField.length === 0) {\n\t\t\t\t\tparent.mutableChunk.fields.delete(parent.key);\n\t\t\t\t}\n\t\t\t},\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(this.mutableChunk === undefined, 0x535 /* should be in field */);\n\t\t\t\tconst parent = this.getParent();\n\t\t\t\tconst chunks =\n\t\t\t\t\tparent.mutableChunk.fields.get(parent.key) ?? fail(0xaf6 /* missing edited field */);\n\t\t\t\tlet indexWithinChunk = index;\n\t\t\t\tlet indexOfChunk = 0;\n\t\t\t\tlet chunk = chunks[indexOfChunk] ?? oob();\n\t\t\t\twhile (indexWithinChunk >= chunk.topLevelLength) {\n\t\t\t\t\tchunk = chunks[indexOfChunk] ?? oob();\n\t\t\t\t\tindexWithinChunk -= chunk.topLevelLength;\n\t\t\t\t\tindexOfChunk++;\n\t\t\t\t\tif (indexOfChunk === chunks.length) {\n\t\t\t\t\t\tfail(0xaf7 /* missing edited node */);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlet found = chunks[indexOfChunk] ?? oob();\n\t\t\t\tif (!(found instanceof BasicChunk)) {\n\t\t\t\t\t// TODO:Perf: support in place editing of other chunk formats when possible:\n\t\t\t\t\t// 1. Support updating values in uniform chunks.\n\t\t\t\t\t// 2. Support traversing sequence chunks.\n\t\t\t\t\t//\n\t\t\t\t\t// Maybe build path when visitor navigates then lazily sync to chunk tree when editing?\n\t\t\t\t\tconst newChunks = mapCursorField(found.cursor(), (cursor) =>\n\t\t\t\t\t\tbasicChunkTree(cursor, {\n\t\t\t\t\t\t\tpolicy: this.forest.chunker,\n\t\t\t\t\t\t\tidCompressor: this.forest.idCompressor,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\t// TODO: this could fail for really long chunks being split (due to argument count limits).\n\t\t\t\t\t// Current implementations of chunks shouldn't ever be that long, but it could be an issue if they get bigger.\n\t\t\t\t\tchunks.splice(indexOfChunk, 1, ...newChunks);\n\t\t\t\t\tfound.referenceRemoved();\n\n\t\t\t\t\tfound = newChunks[indexWithinChunk] ?? oob();\n\t\t\t\t}\n\t\t\t\tassert(found instanceof BasicChunk, 0x536 /* chunk should have been normalized */);\n\t\t\t\tif (found.isShared()) {\n\t\t\t\t\tthis.mutableChunk = chunks[indexOfChunk] = found.clone();\n\t\t\t\t\tfound.referenceRemoved();\n\t\t\t\t} else {\n\t\t\t\t\tthis.mutableChunk = found;\n\t\t\t\t}\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(this.mutableChunk !== undefined, 0x537 /* should be in node */);\n\t\t\t\tthis.mutableChunk = undefined;\n\t\t\t},\n\t\t\tenterField(key: FieldKey): void {\n\t\t\t\tassert(this.mutableChunk !== undefined, 0x538 /* should be in node */);\n\t\t\t\tthis.mutableChunkStack.push({ key, mutableChunk: this.mutableChunk });\n\t\t\t\tthis.mutableChunk = undefined;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tconst top = this.mutableChunkStack.pop() ?? fail(0xaf8 /* should not be at root */);\n\t\t\t\tassert(this.mutableChunk === undefined, 0x539 /* should be in field */);\n\t\t\t\tthis.mutableChunk = top.mutableChunk;\n\t\t\t},\n\t\t};\n\n\t\tconst announcedVisitors: AnnouncedVisitor[] = [];\n\t\tthis.deltaVisitors.forEach((getVisitor) => announcedVisitors.push(getVisitor()));\n\t\tconst combinedVisitor = combineVisitors([forestVisitor, ...announcedVisitors]);\n\t\tthis.activeVisitor = combinedVisitor;\n\t\treturn combinedVisitor;\n\t}\n\n\tprivate nextDetachedFieldIdentifier = 0;\n\tpublic newDetachedField(): DetachedField {\n\t\tconst field: DetachedField = brand(String(this.nextDetachedFieldIdentifier));\n\t\tassert(\n\t\t\t!this.roots.fields.has(detachedFieldAsKey(field)),\n\t\t\t0x53a /* new field must not already exist */,\n\t\t);\n\t\tthis.nextDetachedFieldIdentifier += 1;\n\t\treturn field;\n\t}\n\n\tpublic allocateCursor(): Cursor {\n\t\treturn new Cursor(\n\t\t\tthis,\n\t\t\tITreeSubscriptionCursorState.Cleared,\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t0,\n\t\t\t0,\n\t\t\t0,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\tpublic tryMoveCursorToNode(\n\t\tdestination: Anchor,\n\t\tcursorToMove: ITreeSubscriptionCursor,\n\t): TreeNavigationResult {\n\t\tconst path = this.anchors.locate(destination);\n\t\tif (path === undefined) {\n\t\t\treturn TreeNavigationResult.NotFound;\n\t\t}\n\t\tthis.moveCursorToPath(path, cursorToMove);\n\t\treturn TreeNavigationResult.Ok;\n\t}\n\n\tpublic tryMoveCursorToField(\n\t\tdestination: FieldAnchor,\n\t\tcursorToMove: ITreeSubscriptionCursor,\n\t): TreeNavigationResult {\n\t\tassert(\n\t\t\tcursorToMove instanceof Cursor,\n\t\t\t0x53b /* ChunkedForest must only be given its own Cursor type */,\n\t\t);\n\t\tif (destination.parent === undefined) {\n\t\t\tcursorToMove.setToDetachedSequence(destination.fieldKey);\n\t\t\treturn TreeNavigationResult.Ok;\n\t\t}\n\t\tconst result = this.tryMoveCursorToNode(destination.parent, cursorToMove);\n\t\tif (result !== TreeNavigationResult.Ok) {\n\t\t\treturn result;\n\t\t}\n\n\t\tcursorToMove.enterField(destination.fieldKey);\n\t\treturn TreeNavigationResult.Ok;\n\t}\n\n\tpublic moveCursorToPath(destination: UpPath, cursorToMove: ITreeSubscriptionCursor): void {\n\t\tassert(\n\t\t\tcursorToMove instanceof Cursor,\n\t\t\t0x53c /* ChunkedForest must only be given its own Cursor type */,\n\t\t);\n\t\tassert(\n\t\t\tcursorToMove.forest === this,\n\t\t\t0x53d /* ChunkedForest must only be given its own Cursor */,\n\t\t);\n\n\t\tconst indexStack: number[] = [];\n\t\tconst keyStack: FieldKey[] = [];\n\n\t\tlet path: UpPath | undefined = destination;\n\t\twhile (path !== undefined) {\n\t\t\tindexStack.push(path.parentIndex);\n\t\t\tkeyStack.push(path.parentField);\n\t\t\tpath = path.parent;\n\t\t}\n\t\tcursorToMove.clear();\n\t\twhile (keyStack.length > 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst key = keyStack.pop()!;\n\t\t\tif (cursorToMove.state === ITreeSubscriptionCursorState.Cleared) {\n\t\t\t\tcursorToMove.setToDetachedSequence(key);\n\t\t\t\tcursorToMove.state = ITreeSubscriptionCursorState.Current;\n\t\t\t} else {\n\t\t\t\tcursorToMove.enterField(key);\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tcursorToMove.enterNode(indexStack.pop()!);\n\t\t}\n\t}\n\n\tpublic getCursorAboveDetachedFields(): ITreeCursorSynchronous {\n\t\tconst rootCursor = this.roots.cursor();\n\t\trootCursor.enterNode(0);\n\t\treturn rootCursor;\n\t}\n}\n\nclass Cursor extends BasicChunkCursor implements ITreeSubscriptionCursor {\n\tpublic constructor(\n\t\tpublic readonly forest: ChunkedForest,\n\t\tpublic state: ITreeSubscriptionCursorState,\n\t\troot: readonly TreeChunk[],\n\t\tsiblingStack: SiblingsOrKey[],\n\t\tindexStack: number[],\n\t\tindexOfChunkStack: number[],\n\t\tindexWithinChunkStack: number[],\n\t\tsiblings: SiblingsOrKey,\n\t\tindex: number,\n\t\tindexOfChunk: number,\n\t\tindexWithinChunk: number,\n\t\tnestedCursor: ChunkedCursor | undefined,\n\t) {\n\t\tsuper(\n\t\t\troot,\n\t\t\tsiblingStack,\n\t\t\tindexStack,\n\t\t\tindexOfChunkStack,\n\t\t\tindexWithinChunkStack,\n\t\t\tsiblings,\n\t\t\tindex,\n\t\t\tindexOfChunk,\n\t\t\tindexWithinChunk,\n\t\t\tnestedCursor,\n\t\t);\n\t}\n\n\tpublic setToDetachedSequence(key: FieldKey): void {\n\t\tthis.root = (this.forest.roots.fields.get(key) ?? []) as BasicChunk[];\n\t\tthis.siblingStack.length = 0;\n\t\tthis.indexStack.length = 0;\n\t\tthis.indexOfChunkStack.length = 0;\n\t\tthis.indexWithinChunkStack.length = 0;\n\t\tthis.siblings = [key];\n\t\tthis.index = 0;\n\t\tthis.indexOfChunk = 0;\n\t\tthis.indexWithinChunk = 0;\n\t\tthis.nestedCursor = undefined;\n\t}\n\n\tpublic override fork(): Cursor {\n\t\t// Siblings arrays are not modified during navigation and do not need be be copied.\n\t\t// This allows this copy to be shallow, and `this.siblings` below to not be copied as all.\n\t\treturn new Cursor(\n\t\t\tthis.forest,\n\t\t\tthis.state,\n\t\t\tthis.root,\n\t\t\t[...this.siblingStack],\n\t\t\t[...this.indexStack],\n\t\t\t[...this.indexOfChunkStack],\n\t\t\t[...this.indexWithinChunkStack],\n\t\t\tthis.siblings,\n\t\t\tthis.index,\n\t\t\tthis.indexOfChunk,\n\t\t\tthis.indexWithinChunk,\n\t\t\tthis.nestedCursor?.fork(),\n\t\t);\n\t}\n\n\tpublic buildFieldAnchor(): FieldAnchor {\n\t\tconst path = this.getFieldPath();\n\t\tconst anchor =\n\t\t\tpath.parent === undefined ? undefined : this.forest.anchors.track(path.parent);\n\t\treturn { parent: anchor, fieldKey: path.field };\n\t}\n\n\tpublic free(): void {\n\t\tthis.state = ITreeSubscriptionCursorState.Freed;\n\t}\n\n\tpublic buildAnchor(): Anchor {\n\t\treturn this.forest.anchors.track(this.getPath());\n\t}\n\n\tpublic clear(): void {\n\t\tthis.state = ITreeSubscriptionCursorState.Cleared;\n\t\tthis.setToDetachedSequence(rootFieldKey);\n\t}\n}\n\n/**\n * Creates an implementation of {@link IEditableForest} with no data or schema.\n */\nexport function buildChunkedForest(\n\tchunker: IChunker,\n\tanchors?: AnchorSet,\n\tidCompressor?: IIdCompressor,\n): ChunkedForest {\n\treturn new ChunkedForest(makeRoot(), chunker.schema, chunker, anchors, idCompressor);\n}\n"]}
1
+ {"version":3,"file":"chunkedForest.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkedForest.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;AAEH,+DAA6D;AAE7D,kEAAwE;AAGxE,kDA0B6B;AAC7B,kDAM6B;AAE7B,mDAAmF;AACnF,iDAAsF;AAEtF,SAAS,QAAQ;IAChB,OAAO,IAAI,0BAAU,CAAC,+BAAoB,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;AACxD,CAAC;AAOD;;;;GAIG;AACH,MAAa,aAAa;IAOzB;;;;;OAKG;IACH,YACQ,KAAiB,EACR,MAAoC,EACpC,OAAiB,EACjB,UAAqB,IAAI,oBAAS,EAAE,EACpC,YAA4B;QAJrC,UAAK,GAAL,KAAK,CAAY;QACR,WAAM,GAAN,MAAM,CAA8B;QACpC,YAAO,GAAP,OAAO,CAAU;QACjB,YAAO,GAAP,OAAO,CAA6B;QACpC,iBAAY,GAAZ,YAAY,CAAgB;QAf5B,kBAAa,GAAgC,IAAI,GAAG,EAAE,CAAC;QAC/D,gCAAU,IAAA,4BAAa,GAAgB,EAAC;QACjC,WAAM,GAA6B,u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AG,uCAA4B,CAAC,KAAK,CAAC;IACjD,CAAC;IAEM,WAAW;QACjB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC;IAClD,CAAC;IAEM,KAAK;QACX,IAAI,CAAC,KAAK,GAAG,uCAA4B,CAAC,OAAO,CAAC;QAClD,IAAI,CAAC,qBAAqB,CAAC,uBAAY,CAAC,CAAC;IAC1C,CAAC;CACD;AAED;;GAEG;AACH,SAAgB,kBAAkB,CACjC,OAAiB,EACjB,OAAmB,EACnB,YAA4B;IAE5B,OAAO,IAAI,aAAa,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,YAAY,CAAC,CAAC;AACtF,CAAC;AAND,gDAMC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { createEmitter } from \"@fluid-internal/client-utils\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { assert, oob, fail } from \"@fluidframework/core-utils/internal\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\nimport {\n\ttype Anchor,\n\tAnchorSet,\n\ttype AnnouncedVisitor,\n\ttype DeltaVisitor,\n\ttype DetachedField,\n\ttype FieldAnchor,\n\ttype FieldKey,\n\ttype ForestEvents,\n\ttype IEditableForest,\n\ttype ITreeCursorSynchronous,\n\ttype ITreeSubscriptionCursor,\n\tITreeSubscriptionCursorState,\n\ttype PlaceIndex,\n\ttype Range,\n\tTreeNavigationResult,\n\ttype TreeStoredSchemaSubscription,\n\ttype UpPath,\n\taboveRootPlaceholder,\n\tcombineVisitors,\n\tdetachedFieldAsKey,\n\tmapCursorField,\n\trootFieldKey,\n\ttype ChunkedCursor,\n\ttype TreeChunk,\n\ttype DeltaDetachedNodeId,\n} from \"../../core/index.js\";\nimport {\n\tassertValidRange,\n\tbrand,\n\tgetLast,\n\tgetOrAddEmptyToMap,\n\thasSome,\n} from \"../../util/index.js\";\n\nimport { BasicChunk, BasicChunkCursor, type SiblingsOrKey } from \"./basicChunk.js\";\nimport { type IChunker, basicChunkTree, chunkField, chunkTree } from \"./chunkTree.js\";\n\nfunction makeRoot(): BasicChunk {\n\treturn new BasicChunk(aboveRootPlaceholder, new Map());\n}\n\ninterface StackNode {\n\tmutableChunk: BasicChunk;\n\tkey: FieldKey;\n}\n\n/**\n * Implementation of IEditableForest based on copy on write chunks.\n *\n * This implementation focuses on performance.\n */\nexport class ChunkedForest implements IEditableForest {\n\tprivate activeVisitor?: DeltaVisitor;\n\n\tprivate readonly deltaVisitors: Set<() => AnnouncedVisitor> = new Set();\n\treadonly #events = createEmitter<ForestEvents>();\n\tpublic readonly events: Listenable<ForestEvents> = this.#events;\n\n\t/**\n\t * @param roots - dummy node above the root under which detached fields are stored. All content of the forest is reachable from this.\n\t * @param schema - schema which all content in this forest is assumed to comply with.\n\t * @param chunker - Chunking policy. TODO: dispose of this when forest is disposed.\n\t * @param anchors - anchorSet used to track location in this forest across changes. Callers of applyDelta must ensure this is updated accordingly.\n\t */\n\tpublic constructor(\n\t\tpublic roots: BasicChunk,\n\t\tpublic readonly schema: TreeStoredSchemaSubscription,\n\t\tpublic readonly chunker: IChunker,\n\t\tpublic readonly anchors: AnchorSet = new AnchorSet(),\n\t\tpublic readonly idCompressor?: IIdCompressor,\n\t) {}\n\n\tpublic get isEmpty(): boolean {\n\t\treturn this.roots.fields.size === 0;\n\t}\n\n\tpublic clone(schema: TreeStoredSchemaSubscription, anchors: AnchorSet): ChunkedForest {\n\t\tthis.roots.referenceAdded();\n\t\treturn new ChunkedForest(this.roots, schema, this.chunker.clone(schema), anchors);\n\t}\n\n\tpublic chunkField(cursor: ITreeCursorSynchronous): TreeChunk[] {\n\t\treturn chunkField(cursor, { idCompressor: this.idCompressor, policy: this.chunker });\n\t}\n\n\tpublic forgetAnchor(anchor: Anchor): void {\n\t\tthis.anchors.forget(anchor);\n\t}\n\n\tpublic registerAnnouncedVisitor(visitor: () => AnnouncedVisitor): void {\n\t\tthis.deltaVisitors.add(visitor);\n\t}\n\n\tpublic deregisterAnnouncedVisitor(visitor: () => AnnouncedVisitor): void {\n\t\tthis.deltaVisitors.delete(visitor);\n\t}\n\n\tpublic acquireVisitor(): DeltaVisitor {\n\t\tassert(\n\t\t\tthis.activeVisitor === undefined,\n\t\t\t0x76a /* Must release existing visitor before acquiring another */,\n\t\t);\n\n\t\tif (this.roots.isShared()) {\n\t\t\tthis.roots = this.roots.clone();\n\t\t}\n\n\t\tconst forestVisitor = {\n\t\t\tforest: this,\n\t\t\t// Current location in the tree, as a non-shared BasicChunk (TODO: support in-place modification of other chunk formats when possible).\n\t\t\t// Start above root detached sequences.\n\t\t\tmutableChunkStack: [] as StackNode[],\n\t\t\tmutableChunk: this.roots as BasicChunk | undefined,\n\t\t\tgetParent(): StackNode {\n\t\t\t\tassert(hasSome(this.mutableChunkStack), 0x532 /* invalid access to root's parent */);\n\t\t\t\treturn getLast(this.mutableChunkStack);\n\t\t\t},\n\t\t\tfree(): void {\n\t\t\t\tthis.mutableChunk = undefined;\n\t\t\t\tthis.mutableChunkStack.length = 0;\n\t\t\t\tassert(\n\t\t\t\t\tthis.forest.activeVisitor !== undefined,\n\t\t\t\t\t0x76b /* Multiple free calls for same visitor */,\n\t\t\t\t);\n\t\t\t\tthis.forest.activeVisitor = undefined;\n\t\t\t},\n\t\t\tdestroy(detachedField: FieldKey, count: number): void {\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tthis.forest.roots.fields.delete(detachedField);\n\t\t\t},\n\t\t\tcreate(content: readonly ITreeCursorSynchronous[], destination: FieldKey): void {\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tconst chunks: TreeChunk[] = content.map((c) =>\n\t\t\t\t\tchunkTree(c, {\n\t\t\t\t\t\tpolicy: this.forest.chunker,\n\t\t\t\t\t\tidCompressor: this.forest.idCompressor,\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t\tthis.forest.roots.fields.set(destination, chunks);\n\t\t\t\tthis.forest.#events.emit(\"afterRootFieldCreated\", destination);\n\t\t\t},\n\t\t\tattach(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.attachEdit(source, count, destination);\n\t\t\t},\n\t\t\tdetach(source: Range, destination: FieldKey, id: DeltaDetachedNodeId): void {\n\t\t\t\tthis.detachEdit(source, destination);\n\t\t\t},\n\t\t\t/**\n\t\t\t * Attaches the range into the current field by transferring it from the given source path.\n\t\t\t * Does not invalidate dependents.\n\t\t\t * @param source - The the range to be attached.\n\t\t\t * @param destination - The index in the current field at which to attach the content.\n\t\t\t */\n\t\t\tattachEdit(source: FieldKey, count: number, destination: PlaceIndex): void {\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tconst sourceField = this.forest.roots.fields.get(source) ?? [];\n\t\t\t\tthis.forest.roots.fields.delete(source);\n\t\t\t\tif (sourceField.length === 0) {\n\t\t\t\t\treturn; // Prevent creating 0 sized fields when inserting empty into empty.\n\t\t\t\t}\n\n\t\t\t\tconst parent = this.getParent();\n\t\t\t\tconst destinationField = getOrAddEmptyToMap(parent.mutableChunk.fields, parent.key);\n\t\t\t\t// TODO: this will fail for very large moves due to argument limits.\n\t\t\t\tdestinationField.splice(destination, 0, ...sourceField);\n\t\t\t},\n\t\t\t/**\n\t\t\t * Detaches the range from the current field and transfers it to the given destination if any.\n\t\t\t * Does not invalidate dependents.\n\t\t\t * @param source - The bounds of the range to be detached from the current field.\n\t\t\t * @param destination - If specified, the destination to transfer the detached range to.\n\t\t\t * If not specified, the detached range is destroyed.\n\t\t\t */\n\t\t\tdetachEdit(source: Range, destination: FieldKey | undefined): void {\n\t\t\t\t// TODO: optimize this to perform in-place replace in uniform chunks when attach edits bring the chunk back to its original shape.\n\t\t\t\t// This should result in 3 cases:\n\t\t\t\t// 1. In-place update of uniform chunk. No allocations, no ref count changes, no new TreeChunks.\n\t\t\t\t// 2. Uniform chunk is shared: copy it (and parent path as needed), and update the copy.\n\t\t\t\t// 3. Fallback to detach then attach (Which will copy parents and convert to basic chunks as needed).\n\n\t\t\t\tthis.forest.#events.emit(\"beforeChange\");\n\t\t\t\tconst parent = this.getParent();\n\t\t\t\tconst sourceField = parent.mutableChunk.fields.get(parent.key) ?? [];\n\n\t\t\t\tassertValidRange(source, sourceField);\n\t\t\t\tconst newField = sourceField.splice(source.start, source.end - source.start);\n\n\t\t\t\tif (destination === undefined) {\n\t\t\t\t\tfor (const child of newField) {\n\t\t\t\t\t\tchild.referenceRemoved();\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tassert(\n\t\t\t\t\t\t!this.forest.roots.fields.has(destination),\n\t\t\t\t\t\t0x7af /* Destination must be a new empty detached field */,\n\t\t\t\t\t);\n\t\t\t\t\tif (newField.length > 0) {\n\t\t\t\t\t\tthis.forest.roots.fields.set(destination, newField);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// This check is performed after the transfer to ensure that the field is not removed in scenarios\n\t\t\t\t// where the source and destination are the same.\n\t\t\t\tif (sourceField.length === 0) {\n\t\t\t\t\tparent.mutableChunk.fields.delete(parent.key);\n\t\t\t\t}\n\t\t\t},\n\t\t\tenterNode(index: number): void {\n\t\t\t\tassert(this.mutableChunk === undefined, 0x535 /* should be in field */);\n\t\t\t\tconst parent = this.getParent();\n\t\t\t\tconst chunks =\n\t\t\t\t\tparent.mutableChunk.fields.get(parent.key) ?? fail(0xaf6 /* missing edited field */);\n\t\t\t\tlet indexWithinChunk = index;\n\t\t\t\tlet indexOfChunk = 0;\n\t\t\t\tlet chunk = chunks[indexOfChunk] ?? oob();\n\t\t\t\twhile (indexWithinChunk >= chunk.topLevelLength) {\n\t\t\t\t\tchunk = chunks[indexOfChunk] ?? oob();\n\t\t\t\t\tindexWithinChunk -= chunk.topLevelLength;\n\t\t\t\t\tindexOfChunk++;\n\t\t\t\t\tif (indexOfChunk === chunks.length) {\n\t\t\t\t\t\tfail(0xaf7 /* missing edited node */);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tlet found = chunks[indexOfChunk] ?? oob();\n\t\t\t\tif (!(found instanceof BasicChunk)) {\n\t\t\t\t\t// TODO:Perf: support in place editing of other chunk formats when possible:\n\t\t\t\t\t// 1. Support updating values in uniform chunks.\n\t\t\t\t\t// 2. Support traversing sequence chunks.\n\t\t\t\t\t//\n\t\t\t\t\t// Maybe build path when visitor navigates then lazily sync to chunk tree when editing?\n\t\t\t\t\tconst newChunks = mapCursorField(found.cursor(), (cursor) =>\n\t\t\t\t\t\tbasicChunkTree(cursor, {\n\t\t\t\t\t\t\tpolicy: this.forest.chunker,\n\t\t\t\t\t\t\tidCompressor: this.forest.idCompressor,\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t\t// TODO: this could fail for really long chunks being split (due to argument count limits).\n\t\t\t\t\t// Current implementations of chunks shouldn't ever be that long, but it could be an issue if they get bigger.\n\t\t\t\t\tchunks.splice(indexOfChunk, 1, ...newChunks);\n\t\t\t\t\tfound.referenceRemoved();\n\n\t\t\t\t\tfound = newChunks[indexWithinChunk] ?? oob();\n\t\t\t\t}\n\t\t\t\tassert(found instanceof BasicChunk, 0x536 /* chunk should have been normalized */);\n\t\t\t\tif (found.isShared()) {\n\t\t\t\t\tthis.mutableChunk = chunks[indexOfChunk] = found.clone();\n\t\t\t\t\tfound.referenceRemoved();\n\t\t\t\t} else {\n\t\t\t\t\tthis.mutableChunk = found;\n\t\t\t\t}\n\t\t\t},\n\t\t\texitNode(index: number): void {\n\t\t\t\tassert(this.mutableChunk !== undefined, 0x537 /* should be in node */);\n\t\t\t\tthis.mutableChunk = undefined;\n\t\t\t},\n\t\t\tenterField(key: FieldKey): void {\n\t\t\t\tassert(this.mutableChunk !== undefined, 0x538 /* should be in node */);\n\t\t\t\tthis.mutableChunkStack.push({ key, mutableChunk: this.mutableChunk });\n\t\t\t\tthis.mutableChunk = undefined;\n\t\t\t},\n\t\t\texitField(key: FieldKey): void {\n\t\t\t\tconst top = this.mutableChunkStack.pop() ?? fail(0xaf8 /* should not be at root */);\n\t\t\t\tassert(this.mutableChunk === undefined, 0x539 /* should be in field */);\n\t\t\t\tthis.mutableChunk = top.mutableChunk;\n\t\t\t},\n\t\t};\n\n\t\tconst announcedVisitors: AnnouncedVisitor[] = [];\n\t\tthis.deltaVisitors.forEach((getVisitor) => announcedVisitors.push(getVisitor()));\n\t\tconst combinedVisitor = combineVisitors([forestVisitor, ...announcedVisitors]);\n\t\tthis.activeVisitor = combinedVisitor;\n\t\treturn combinedVisitor;\n\t}\n\n\tprivate nextDetachedFieldIdentifier = 0;\n\tpublic newDetachedField(): DetachedField {\n\t\tconst field: DetachedField = brand(String(this.nextDetachedFieldIdentifier));\n\t\tassert(\n\t\t\t!this.roots.fields.has(detachedFieldAsKey(field)),\n\t\t\t0x53a /* new field must not already exist */,\n\t\t);\n\t\tthis.nextDetachedFieldIdentifier += 1;\n\t\treturn field;\n\t}\n\n\tpublic allocateCursor(): Cursor {\n\t\treturn new Cursor(\n\t\t\tthis,\n\t\t\tITreeSubscriptionCursorState.Cleared,\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t[],\n\t\t\t0,\n\t\t\t0,\n\t\t\t0,\n\t\t\tundefined,\n\t\t);\n\t}\n\n\tpublic tryMoveCursorToNode(\n\t\tdestination: Anchor,\n\t\tcursorToMove: ITreeSubscriptionCursor,\n\t): TreeNavigationResult {\n\t\tconst path = this.anchors.locate(destination);\n\t\tif (path === undefined) {\n\t\t\treturn TreeNavigationResult.NotFound;\n\t\t}\n\t\tthis.moveCursorToPath(path, cursorToMove);\n\t\treturn TreeNavigationResult.Ok;\n\t}\n\n\tpublic tryMoveCursorToField(\n\t\tdestination: FieldAnchor,\n\t\tcursorToMove: ITreeSubscriptionCursor,\n\t): TreeNavigationResult {\n\t\tassert(\n\t\t\tcursorToMove instanceof Cursor,\n\t\t\t0x53b /* ChunkedForest must only be given its own Cursor type */,\n\t\t);\n\t\tif (destination.parent === undefined) {\n\t\t\tcursorToMove.setToDetachedSequence(destination.fieldKey);\n\t\t\treturn TreeNavigationResult.Ok;\n\t\t}\n\t\tconst result = this.tryMoveCursorToNode(destination.parent, cursorToMove);\n\t\tif (result !== TreeNavigationResult.Ok) {\n\t\t\treturn result;\n\t\t}\n\n\t\tcursorToMove.enterField(destination.fieldKey);\n\t\treturn TreeNavigationResult.Ok;\n\t}\n\n\tpublic moveCursorToPath(destination: UpPath, cursorToMove: ITreeSubscriptionCursor): void {\n\t\tassert(\n\t\t\tcursorToMove instanceof Cursor,\n\t\t\t0x53c /* ChunkedForest must only be given its own Cursor type */,\n\t\t);\n\t\tassert(\n\t\t\tcursorToMove.forest === this,\n\t\t\t0x53d /* ChunkedForest must only be given its own Cursor */,\n\t\t);\n\n\t\tconst indexStack: number[] = [];\n\t\tconst keyStack: FieldKey[] = [];\n\n\t\tlet path: UpPath | undefined = destination;\n\t\twhile (path !== undefined) {\n\t\t\tindexStack.push(path.parentIndex);\n\t\t\tkeyStack.push(path.parentField);\n\t\t\tpath = path.parent;\n\t\t}\n\t\tcursorToMove.clear();\n\t\twhile (keyStack.length > 0) {\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tconst key = keyStack.pop()!;\n\t\t\tif (cursorToMove.state === ITreeSubscriptionCursorState.Cleared) {\n\t\t\t\tcursorToMove.setToDetachedSequence(key);\n\t\t\t\tcursorToMove.state = ITreeSubscriptionCursorState.Current;\n\t\t\t} else {\n\t\t\t\tcursorToMove.enterField(key);\n\t\t\t}\n\n\t\t\t// eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n\t\t\tcursorToMove.enterNode(indexStack.pop()!);\n\t\t}\n\t}\n\n\tpublic getCursorAboveDetachedFields(): ITreeCursorSynchronous {\n\t\tconst rootCursor = this.roots.cursor();\n\t\trootCursor.enterNode(0);\n\t\treturn rootCursor;\n\t}\n}\n\nclass Cursor extends BasicChunkCursor implements ITreeSubscriptionCursor {\n\tpublic constructor(\n\t\tpublic readonly forest: ChunkedForest,\n\t\tpublic state: ITreeSubscriptionCursorState,\n\t\troot: readonly TreeChunk[],\n\t\tsiblingStack: SiblingsOrKey[],\n\t\tindexStack: number[],\n\t\tindexOfChunkStack: number[],\n\t\tindexWithinChunkStack: number[],\n\t\tsiblings: SiblingsOrKey,\n\t\tindex: number,\n\t\tindexOfChunk: number,\n\t\tindexWithinChunk: number,\n\t\tnestedCursor: ChunkedCursor | undefined,\n\t) {\n\t\tsuper(\n\t\t\troot,\n\t\t\tsiblingStack,\n\t\t\tindexStack,\n\t\t\tindexOfChunkStack,\n\t\t\tindexWithinChunkStack,\n\t\t\tsiblings,\n\t\t\tindex,\n\t\t\tindexOfChunk,\n\t\t\tindexWithinChunk,\n\t\t\tnestedCursor,\n\t\t);\n\t}\n\n\tpublic setToDetachedSequence(key: FieldKey): void {\n\t\tthis.root = (this.forest.roots.fields.get(key) ?? []) as BasicChunk[];\n\t\tthis.siblingStack.length = 0;\n\t\tthis.indexStack.length = 0;\n\t\tthis.indexOfChunkStack.length = 0;\n\t\tthis.indexWithinChunkStack.length = 0;\n\t\tthis.siblings = [key];\n\t\tthis.index = 0;\n\t\tthis.indexOfChunk = 0;\n\t\tthis.indexWithinChunk = 0;\n\t\tthis.nestedCursor = undefined;\n\t}\n\n\tpublic override fork(): Cursor {\n\t\t// Siblings arrays are not modified during navigation and do not need be be copied.\n\t\t// This allows this copy to be shallow, and `this.siblings` below to not be copied as all.\n\t\treturn new Cursor(\n\t\t\tthis.forest,\n\t\t\tthis.state,\n\t\t\tthis.root,\n\t\t\t[...this.siblingStack],\n\t\t\t[...this.indexStack],\n\t\t\t[...this.indexOfChunkStack],\n\t\t\t[...this.indexWithinChunkStack],\n\t\t\tthis.siblings,\n\t\t\tthis.index,\n\t\t\tthis.indexOfChunk,\n\t\t\tthis.indexWithinChunk,\n\t\t\tthis.nestedCursor?.fork(),\n\t\t);\n\t}\n\n\tpublic buildFieldAnchor(): FieldAnchor {\n\t\tconst path = this.getFieldPath();\n\t\tconst anchor =\n\t\t\tpath.parent === undefined ? undefined : this.forest.anchors.track(path.parent);\n\t\treturn { parent: anchor, fieldKey: path.field };\n\t}\n\n\tpublic free(): void {\n\t\tthis.state = ITreeSubscriptionCursorState.Freed;\n\t}\n\n\tpublic buildAnchor(): Anchor {\n\t\treturn this.forest.anchors.track(this.getPath());\n\t}\n\n\tpublic clear(): void {\n\t\tthis.state = ITreeSubscriptionCursorState.Cleared;\n\t\tthis.setToDetachedSequence(rootFieldKey);\n\t}\n}\n\n/**\n * Creates an implementation of {@link IEditableForest} with no data or schema.\n */\nexport function buildChunkedForest(\n\tchunker: IChunker,\n\tanchors?: AnchorSet,\n\tidCompressor?: IIdCompressor,\n): ChunkedForest {\n\treturn new ChunkedForest(makeRoot(), chunker.schema, chunker, anchors, idCompressor);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"chunkDecoding.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkDecoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,aAAa,EAEb,SAAS,EACT,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAGX,KAAK,EACL,SAAS,EACT,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,YAAY,EAOjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,cAAc,EAGd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEN,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAEtB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAGtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW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G;AACH,eAAO,MAAM,UAAU,EAAE,YAMxB,CAAC;AAyBF;;GAEG;AACH,qBAAa,WAAY,YAAW,YAAY;IAI9C,OAAO,CAAC,QAAQ,CAAC,KAAK;IACtB,OAAO,CAAC,QAAQ,CAAC,OAAO;IAJzB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAC,CAA2B;IACjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+B;gBAE3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,cAAc,CAAC,iBAAiB,CAAC;IAWrD,MAAM,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS;CAmCjF"}
1
+ {"version":3,"file":"chunkDecoding.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkDecoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EACX,aAAa,EAEb,SAAS,EACT,MAAM,+BAA+B,CAAC;AAGvC,OAAO,KAAK,EAGX,KAAK,EACL,SAAS,EACT,MAAM,wBAAwB,CAAC;AAMhC,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,YAAY,EAOjB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,cAAc,EAGd,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAEN,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAEtB,KAAK,uBAAuB,EAC5B,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAGtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,WAAW,iBAAiB;IACjC,YAAY,EAAE,aAAa,CAAC;IAC5B;;OAEG;IACH,YAAY,EAAE,SAAS,CAAC;CACxB;AACD;;GAEG;AACH,wBAAgB,MAAM,CACrB,KAAK,EAAE,iBAAiB,EACxB,iBAAiB,EAAE;IAAE,YAAY,EAAE,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AAQ,CAAC,IAAI,CAAC,CAA2B;IACjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+B;gBAE3C,KAAK,EAAE,gBAAgB,EACvB,OAAO,EAAE,cAAc,CAAC,iBAAiB,CAAC;IAWrD,MAAM,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS;CAmCjF"}
@@ -110,12 +110,15 @@ exports.deaggregateChunks = deaggregateChunks;
110
110
  function aggregateChunks(input) {
111
111
  const chunks = input.flatMap(deaggregateChunks);
112
112
  switch (chunks.length) {
113
- case 0:
113
+ case 0: {
114
114
  return emptyChunk_js_1.emptyChunk;
115
- case 1:
115
+ }
116
+ case 1: {
116
117
  return chunks[0] ?? (0, internal_1.oob)();
117
- default:
118
+ }
119
+ default: {
118
120
  return new sequenceChunk_js_1.SequenceChunk(chunks);
121
+ }
119
122
  }
120
123
  }
121
124
  exports.aggregateChunks = aggregateChunks;
@@ -232,7 +235,7 @@ class NodeDecoder {
232
235
  // TODO: when handling of ArrayChunks has better performance (for example in cursors),
233
236
  // consider keeping array chunks here if they are longer than some threshold.
234
237
  const chunks = deaggregateChunks(data);
235
- if (chunks.length !== 0) {
238
+ if (chunks.length > 0) {
236
239
  fields.set(key, chunks);
237
240
  }
238
241
  }
@@ -1 +1 @@
1
- {"version":3,"file":"chunkDecoding.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkDecoding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAmF;AAOnF,sDAAuE;AAOvE,qDAAiE;AACjE,oDAA8C;AAC9C,oDAA8C;AAC9C,0DAAoD;AAEpD,qEASkC;AAClC,uEAImC;AACnC,2CAWqB;AAUrB;;GAEG;AACH,SAAgB,MAAM,CACrB,KAAwB,EACxB,iBAA2E,EAC3E,kBAAuC;IAEvC,OAAO,IAAA,gCAAa,EACnB,cAAc,EACd,IAAI,wCAAc,CAAC,KAAK,CAAC,WAAW,EAAE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C;QACF,CAAC;QAED,OAAO,IAAI,0BAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;CACD;AAnDD,kCAmDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase, oob } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIIdCompressor,\n\tOpSpaceCompressedId,\n\tSessionId,\n} from \"@fluidframework/id-compressor\";\n\nimport { DiscriminatedUnionDispatcher } from \"../../../codec/index.js\";\nimport type {\n\tFieldKey,\n\tTreeNodeSchemaIdentifier,\n\tValue,\n\tTreeChunk,\n} from \"../../../core/index.js\";\nimport { assertValidIndex, brand } from \"../../../util/index.js\";\nimport { BasicChunk } from \"../basicChunk.js\";\nimport { emptyChunk } from \"../emptyChunk.js\";\nimport { SequenceChunk } from \"../sequenceChunk.js\";\n\nimport {\n\ttype ChunkDecoder,\n\ttype StreamCursor,\n\tgetChecked,\n\treadStream,\n\treadStreamBoolean,\n\treadStreamNumber,\n\treadStreamStream,\n\treadStreamValue,\n} from \"./chunkCodecUtilities.js\";\nimport {\n\tDecoderContext,\n\tdecode as genericDecode,\n\treadStreamIdentifier,\n} from \"./chunkDecodingGeneric.js\";\nimport {\n\ttype EncodedAnyShape,\n\ttype EncodedChunkShape,\n\ttype EncodedFieldBatch,\n\ttype EncodedIncrementalChunkShape,\n\ttype EncodedInlineArrayShape,\n\ttype EncodedNestedArrayShape,\n\ttype EncodedNodeShape,\n\ttype EncodedValueShape,\n\tFieldBatchFormatVersion,\n\tSpecialField,\n} from \"./format.js\";\nimport type { IncrementalDecoder } from \"./codecs.js\";\n\nexport interface IdDecodingContext {\n\tidCompressor: IIdCompressor;\n\t/**\n\t * The creator of any local Ids to be decoded.\n\t */\n\toriginatorId: SessionId;\n}\n/**\n * Decode `chunk` into a TreeChunk.\n */\nexport function decode(\n\tchunk: EncodedFieldBatch,\n\tidDecodingContext: { idCompressor: IIdCompressor; originatorId: SessionId },\n\tincrementalDecoder?: IncrementalDecoder,\n): TreeChunk[] {\n\treturn genericDecode(\n\t\tdecoderLibrary,\n\t\tnew DecoderContext(chunk.identifiers, chunk.shapes, idDecodingContext, incrementalDecoder),\n\t\tchunk,\n\t\tanyDecoder,\n\t);\n}\n\nconst decoderLibrary = new DiscriminatedUnionDispatcher<\n\tEncodedChunkShape,\n\t[context: DecoderContext<EncodedChunkShape>],\n\tChunkDecoder\n>({\n\ta(shape: EncodedNestedArrayShape, context): ChunkDecoder {\n\t\treturn new NestedArrayDecoder(shape);\n\t},\n\tb(shape: EncodedInlineArrayShape, context): ChunkDecoder {\n\t\treturn new InlineArrayDecoder(shape);\n\t},\n\tc(shape: EncodedNodeShape, context): ChunkDecoder {\n\t\treturn new NodeDecoder(shape, context);\n\t},\n\td(shape: EncodedAnyShape): ChunkDecoder {\n\t\treturn anyDecoder;\n\t},\n\te(shape: EncodedIncrementalChunkShape, cache): ChunkDecoder {\n\t\treturn new IncrementalChunkDecoder(cache);\n\t},\n});\n\n/**\n * Decode a node's value from `stream` using its shape.\n */\nexport function readValue(\n\tstream: StreamCursor,\n\tshape: EncodedValueShape,\n\tidDecodingContext: IdDecodingContext,\n): Value {\n\tif (shape === undefined) {\n\t\treturn readStreamBoolean(stream) ? readStreamValue(stream) : undefined;\n\t} else {\n\t\tif (shape === true) {\n\t\t\treturn readStreamValue(stream);\n\t\t} else if (shape === false) {\n\t\t\treturn undefined;\n\t\t} else if (Array.isArray(shape)) {\n\t\t\tassert(shape.length === 1, 0x734 /* expected a single constant for value */);\n\t\t\treturn shape[0] as Value;\n\t\t} else if (shape === SpecialField.Identifier) {\n\t\t\t// This case is a special case handling the decoding of identifier fields.\n\t\t\tconst streamValue = readStream(stream);\n\t\t\tassert(\n\t\t\t\ttypeof streamValue === \"number\" || typeof streamValue === \"string\",\n\t\t\t\t0x997 /* identifier must be string or number. */,\n\t\t\t);\n\t\t\tconst idCompressor = idDecodingContext.idCompressor;\n\t\t\treturn typeof streamValue === \"number\"\n\t\t\t\t? idCompressor.decompress(\n\t\t\t\t\t\tidCompressor.normalizeToSessionSpace(\n\t\t\t\t\t\t\tstreamValue as OpSpaceCompressedId,\n\t\t\t\t\t\t\tidDecodingContext.originatorId,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t: streamValue;\n\t\t} else {\n\t\t\t// EncodedCounter case:\n\t\t\tunreachableCase(shape, \"decoding values as deltas is not yet supported\");\n\t\t}\n\t}\n}\n\n/**\n * Normalize a {@link TreeChunk} into an array.\n *\n * Unwraps {@link SequenceChunk}s, and wraps other chunks.\n */\nexport function deaggregateChunks(chunk: TreeChunk): TreeChunk[] {\n\tif (chunk === emptyChunk) {\n\t\treturn [];\n\t}\n\t// TODO: when handling of SequenceChunks has better performance (for example in cursors),\n\t// consider keeping SequenceChunks here if they are longer than some threshold.\n\tif (chunk instanceof SequenceChunk) {\n\t\t// Could return [] here, however the logic in this file is designed to never produce an empty SequenceChunk, so its better to throw an error here to detect bugs.\n\t\tassert(chunk.subChunks.length > 0, 0x735 /* Unexpected empty sequence */);\n\t\t// Logic in this file is designed to never produce an unneeded (single item) SequenceChunks, so its better to throw an error here to detect bugs.\n\t\tassert(chunk.subChunks.length > 1, 0x736 /* Unexpected single item sequence */);\n\n\t\tfor (const sub of chunk.subChunks) {\n\t\t\t// The logic in this file is designed to never produce an nested SequenceChunks or emptyChunk, so its better to throw an error here to detect bugs.\n\t\t\tassert(!(sub instanceof SequenceChunk), 0x737 /* unexpected nested sequence */);\n\t\t\tassert(sub !== emptyChunk, 0x738 /* unexpected empty chunk */);\n\n\t\t\tsub.referenceAdded();\n\t\t}\n\n\t\tchunk.referenceRemoved();\n\t\treturn chunk.subChunks;\n\t} else {\n\t\treturn [chunk];\n\t}\n}\n\n/**\n * Normalize a {@link TreeChunk}[] into a single TreeChunk.\n *\n * Avoids creating nested or less than 2 child {@link SequenceChunk}s.\n */\nexport function aggregateChunks(input: TreeChunk[]): TreeChunk {\n\tconst chunks = input.flatMap(deaggregateChunks);\n\tswitch (chunks.length) {\n\t\tcase 0:\n\t\t\treturn emptyChunk;\n\t\tcase 1:\n\t\t\treturn chunks[0] ?? oob();\n\t\tdefault:\n\t\t\treturn new SequenceChunk(chunks);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedNestedArrayShape}s.\n */\nexport class NestedArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedNestedArrayShape) {}\n\tpublic decode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst decoder = decoders[this.shape] ?? oob();\n\n\t\t// TODO: uniform chunk fast path\n\t\tconst chunks: TreeChunk[] = [];\n\n\t\tconst data = readStream(stream);\n\t\tif (typeof data === \"number\") {\n\t\t\t// This case means that the array contained only 0-sized items, and was thus encoded as the length of the array.\n\t\t\tconst inner = { data: [], offset: 0 };\n\t\t\tfor (let index = 0; index < data; index++) {\n\t\t\t\tchunks.push(decoder.decode(decoders, inner));\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tArray.isArray(data),\n\t\t\t\t0x739 /* expected number of array for encoding of nested array */,\n\t\t\t);\n\t\t\tconst inner = { data, offset: 0 };\n\t\t\twhile (inner.offset !== inner.data.length) {\n\t\t\t\tchunks.push(decoder.decode(decoders, inner));\n\t\t\t}\n\t\t}\n\n\t\treturn aggregateChunks(chunks);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedInlineArrayShape}s.\n */\nexport class InlineArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedInlineArrayShape) {}\n\tpublic decode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst length = this.shape.length;\n\t\tconst decoder = decoders[this.shape.shape] ?? oob();\n\t\tconst chunks: TreeChunk[] = [];\n\t\tfor (let index = 0; index < length; index++) {\n\t\t\tchunks.push(decoder.decode(decoders, stream));\n\t\t}\n\t\treturn aggregateChunks(chunks);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedIncrementalChunkShape}s.\n */\nexport class IncrementalChunkDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly context: DecoderContext<EncodedChunkShape>) {}\n\tpublic decode(_: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tassert(\n\t\t\tthis.context.incrementalDecoder !== undefined,\n\t\t\t0xc27 /* incremental decoder not available for incremental field decoding */,\n\t\t);\n\n\t\tconst chunkDecoder = (batch: EncodedFieldBatch): TreeChunk => {\n\t\t\tassert(\n\t\t\t\tbatch.version >= FieldBatchFormatVersion.v2,\n\t\t\t\t0xc9f /* Unsupported FieldBatchFormatVersion for incremental chunks; must be v2 or higher */,\n\t\t\t);\n\t\t\tconst context = new DecoderContext(\n\t\t\t\tbatch.identifiers,\n\t\t\t\tbatch.shapes,\n\t\t\t\tthis.context.idDecodingContext,\n\t\t\t\tthis.context.incrementalDecoder,\n\t\t\t);\n\t\t\tconst chunks = genericDecode(decoderLibrary, context, batch, anyDecoder);\n\t\t\treturn aggregateChunks(chunks);\n\t\t};\n\n\t\tconst chunkReferenceId = readStreamNumber(stream);\n\t\treturn this.context.incrementalDecoder.decodeIncrementalChunk(\n\t\t\tbrand(chunkReferenceId),\n\t\t\tchunkDecoder,\n\t\t);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedAnyShape}s.\n */\nexport const anyDecoder: ChunkDecoder = {\n\tdecode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst shapeIndex = readStreamNumber(stream);\n\t\tconst decoder = getChecked(decoders, shapeIndex);\n\t\treturn decoder.decode(decoders, stream);\n\t},\n};\n\n/**\n * Decoder for field.\n */\ntype BasicFieldDecoder = (\n\tdecoders: readonly ChunkDecoder[],\n\tstream: StreamCursor,\n) => [FieldKey, TreeChunk];\n\n/**\n * Get a decoder for fields of a provided (via `shape` and `context`) {@link EncodedChunkShape}.\n */\nfunction fieldDecoder(\n\tcontext: DecoderContext<EncodedChunkShape>,\n\tkey: FieldKey,\n\tshape: number,\n): BasicFieldDecoder {\n\tassertValidIndex(shape, context.shapes);\n\treturn (decoders, stream) => {\n\t\tconst decoder = decoders[shape] ?? oob();\n\t\treturn [key, decoder.decode(decoders, stream)];\n\t};\n}\n\n/**\n * Decoder for {@link EncodedNodeShape}s.\n */\nexport class NodeDecoder implements ChunkDecoder {\n\tprivate readonly type?: TreeNodeSchemaIdentifier;\n\tprivate readonly fieldDecoders: readonly BasicFieldDecoder[];\n\tpublic constructor(\n\t\tprivate readonly shape: EncodedNodeShape,\n\t\tprivate readonly context: DecoderContext<EncodedChunkShape>,\n\t) {\n\t\tthis.type = shape.type === undefined ? undefined : context.identifier(shape.type);\n\n\t\tconst fieldDecoders: BasicFieldDecoder[] = [];\n\t\tfor (const [fieldKey, fieldShape] of shape.fields ?? []) {\n\t\t\tconst key: FieldKey = context.identifier(fieldKey);\n\t\t\tfieldDecoders.push(fieldDecoder(context, key, fieldShape));\n\t\t}\n\t\tthis.fieldDecoders = fieldDecoders;\n\t}\n\tpublic decode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst type: TreeNodeSchemaIdentifier =\n\t\t\tthis.type ?? readStreamIdentifier(stream, this.context);\n\t\t// TODO: Consider typechecking against stored schema in here somewhere.\n\n\t\tconst value = readValue(stream, this.shape.value, this.context.idDecodingContext);\n\t\tconst fields: Map<FieldKey, TreeChunk[]> = new Map();\n\n\t\t// Helper to add fields, but with unneeded array chunks removed.\n\t\tfunction addField(key: FieldKey, data: TreeChunk): void {\n\t\t\t// TODO: when handling of ArrayChunks has better performance (for example in cursors),\n\t\t\t// consider keeping array chunks here if they are longer than some threshold.\n\t\t\tconst chunks = deaggregateChunks(data);\n\n\t\t\tif (chunks.length !== 0) {\n\t\t\t\tfields.set(key, chunks);\n\t\t\t}\n\t\t}\n\n\t\tfor (const decoder of this.fieldDecoders) {\n\t\t\tconst [key, content] = decoder(decoders, stream);\n\t\t\taddField(key, content);\n\t\t}\n\n\t\tif (this.shape.extraFields !== undefined) {\n\t\t\tconst decoder = decoders[this.shape.extraFields] ?? oob();\n\t\t\tconst inner = readStreamStream(stream);\n\t\t\twhile (inner.offset !== inner.data.length) {\n\t\t\t\tconst key: FieldKey = readStreamIdentifier(inner, this.context);\n\t\t\t\taddField(key, decoder.decode(decoders, inner));\n\t\t\t}\n\t\t}\n\n\t\treturn new BasicChunk(type, fields, value);\n\t}\n}\n"]}
1
+ {"version":3,"file":"chunkDecoding.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkDecoding.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAmF;AAOnF,sDAAuE;AAOvE,qDAAiE;AACjE,oDAA8C;AAC9C,oDAA8C;AAC9C,0DAAoD;AAEpD,qEASkC;AAClC,uEAImC;AACnC,2CAWqB;AAUrB;;GAEG;AACH,SAAgB,MAAM,CACrB,KAAwB,EACxB,iBAA2E,EAC3E,kBAAuC;IAEvC,OAAO,IAAA,gCAAa,EACnB,cAAc,EACd,IAAI,wCAAc,CAAC,KAAK,CAAC,WAAW,EAAE,KAAK,CAAC,MAAM,EAAE,iBAAiB,EAAE,kBAAkB,CAAC,EAC1F,KAAK,EACL,kBAAU,CACV,CAAC;AACH,CAAC;AAXD,wBAWC;AAED,MAAM,cAAc,GAAG,IAAI,uCAA4B,CAIrD;IACD,CAAC,CAAC,KAA8B,EAAE,OAAO;QACxC,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IACD,CAAC,CAAC,KAA8B,EAAE,OAAO;QACxC,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACtC,CAAC;IACD,CAAC,CAAC,KAAuB,EAAE,OAAO;QACjC,OAAO,IAAI,WAAW,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACxC,CAAC;IACD,CAAC,CAAC,KAAsB;QACvB,OAAO,kBAAU,CAAC;IACnB,CAAC;IACD,CAAC,CAAC,KAA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G,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;YACzB,CAAC;QACF,CAAC;QAED,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,aAAa,EAAE,CAAC;YAC1C,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC;YACjD,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACxB,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YAC1C,MAAM,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,IAAA,cAAG,GAAE,CAAC;YAC1D,MAAM,KAAK,GAAG,IAAA,yCAAgB,EAAC,MAAM,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC3C,MAAM,GAAG,GAAa,IAAA,8CAAoB,EAAC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;gBAChE,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;YAChD,CAAC;QACF,CAAC;QAED,OAAO,IAAI,0BAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;CACD;AAnDD,kCAmDC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase, oob } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIIdCompressor,\n\tOpSpaceCompressedId,\n\tSessionId,\n} from \"@fluidframework/id-compressor\";\n\nimport { DiscriminatedUnionDispatcher } from \"../../../codec/index.js\";\nimport type {\n\tFieldKey,\n\tTreeNodeSchemaIdentifier,\n\tValue,\n\tTreeChunk,\n} from \"../../../core/index.js\";\nimport { assertValidIndex, brand } from \"../../../util/index.js\";\nimport { BasicChunk } from \"../basicChunk.js\";\nimport { emptyChunk } from \"../emptyChunk.js\";\nimport { SequenceChunk } from \"../sequenceChunk.js\";\n\nimport {\n\ttype ChunkDecoder,\n\ttype StreamCursor,\n\tgetChecked,\n\treadStream,\n\treadStreamBoolean,\n\treadStreamNumber,\n\treadStreamStream,\n\treadStreamValue,\n} from \"./chunkCodecUtilities.js\";\nimport {\n\tDecoderContext,\n\tdecode as genericDecode,\n\treadStreamIdentifier,\n} from \"./chunkDecodingGeneric.js\";\nimport {\n\ttype EncodedAnyShape,\n\ttype EncodedChunkShape,\n\ttype EncodedFieldBatch,\n\ttype EncodedIncrementalChunkShape,\n\ttype EncodedInlineArrayShape,\n\ttype EncodedNestedArrayShape,\n\ttype EncodedNodeShape,\n\ttype EncodedValueShape,\n\tFieldBatchFormatVersion,\n\tSpecialField,\n} from \"./format.js\";\nimport type { IncrementalDecoder } from \"./codecs.js\";\n\nexport interface IdDecodingContext {\n\tidCompressor: IIdCompressor;\n\t/**\n\t * The creator of any local Ids to be decoded.\n\t */\n\toriginatorId: SessionId;\n}\n/**\n * Decode `chunk` into a TreeChunk.\n */\nexport function decode(\n\tchunk: EncodedFieldBatch,\n\tidDecodingContext: { idCompressor: IIdCompressor; originatorId: SessionId },\n\tincrementalDecoder?: IncrementalDecoder,\n): TreeChunk[] {\n\treturn genericDecode(\n\t\tdecoderLibrary,\n\t\tnew DecoderContext(chunk.identifiers, chunk.shapes, idDecodingContext, incrementalDecoder),\n\t\tchunk,\n\t\tanyDecoder,\n\t);\n}\n\nconst decoderLibrary = new DiscriminatedUnionDispatcher<\n\tEncodedChunkShape,\n\t[context: DecoderContext<EncodedChunkShape>],\n\tChunkDecoder\n>({\n\ta(shape: EncodedNestedArrayShape, context): ChunkDecoder {\n\t\treturn new NestedArrayDecoder(shape);\n\t},\n\tb(shape: EncodedInlineArrayShape, context): ChunkDecoder {\n\t\treturn new InlineArrayDecoder(shape);\n\t},\n\tc(shape: EncodedNodeShape, context): ChunkDecoder {\n\t\treturn new NodeDecoder(shape, context);\n\t},\n\td(shape: EncodedAnyShape): ChunkDecoder {\n\t\treturn anyDecoder;\n\t},\n\te(shape: EncodedIncrementalChunkShape, cache): ChunkDecoder {\n\t\treturn new IncrementalChunkDecoder(cache);\n\t},\n});\n\n/**\n * Decode a node's value from `stream` using its shape.\n */\nexport function readValue(\n\tstream: StreamCursor,\n\tshape: EncodedValueShape,\n\tidDecodingContext: IdDecodingContext,\n): Value {\n\tif (shape === undefined) {\n\t\treturn readStreamBoolean(stream) ? readStreamValue(stream) : undefined;\n\t} else {\n\t\tif (shape === true) {\n\t\t\treturn readStreamValue(stream);\n\t\t} else if (shape === false) {\n\t\t\treturn undefined;\n\t\t} else if (Array.isArray(shape)) {\n\t\t\tassert(shape.length === 1, 0x734 /* expected a single constant for value */);\n\t\t\treturn shape[0] as Value;\n\t\t} else if (shape === SpecialField.Identifier) {\n\t\t\t// This case is a special case handling the decoding of identifier fields.\n\t\t\tconst streamValue = readStream(stream);\n\t\t\tassert(\n\t\t\t\ttypeof streamValue === \"number\" || typeof streamValue === \"string\",\n\t\t\t\t0x997 /* identifier must be string or number. */,\n\t\t\t);\n\t\t\tconst idCompressor = idDecodingContext.idCompressor;\n\t\t\treturn typeof streamValue === \"number\"\n\t\t\t\t? idCompressor.decompress(\n\t\t\t\t\t\tidCompressor.normalizeToSessionSpace(\n\t\t\t\t\t\t\tstreamValue as OpSpaceCompressedId,\n\t\t\t\t\t\t\tidDecodingContext.originatorId,\n\t\t\t\t\t\t),\n\t\t\t\t\t)\n\t\t\t\t: streamValue;\n\t\t} else {\n\t\t\t// EncodedCounter case:\n\t\t\tunreachableCase(shape, \"decoding values as deltas is not yet supported\");\n\t\t}\n\t}\n}\n\n/**\n * Normalize a {@link TreeChunk} into an array.\n *\n * Unwraps {@link SequenceChunk}s, and wraps other chunks.\n */\nexport function deaggregateChunks(chunk: TreeChunk): TreeChunk[] {\n\tif (chunk === emptyChunk) {\n\t\treturn [];\n\t}\n\t// TODO: when handling of SequenceChunks has better performance (for example in cursors),\n\t// consider keeping SequenceChunks here if they are longer than some threshold.\n\tif (chunk instanceof SequenceChunk) {\n\t\t// Could return [] here, however the logic in this file is designed to never produce an empty SequenceChunk, so its better to throw an error here to detect bugs.\n\t\tassert(chunk.subChunks.length > 0, 0x735 /* Unexpected empty sequence */);\n\t\t// Logic in this file is designed to never produce an unneeded (single item) SequenceChunks, so its better to throw an error here to detect bugs.\n\t\tassert(chunk.subChunks.length > 1, 0x736 /* Unexpected single item sequence */);\n\n\t\tfor (const sub of chunk.subChunks) {\n\t\t\t// The logic in this file is designed to never produce an nested SequenceChunks or emptyChunk, so its better to throw an error here to detect bugs.\n\t\t\tassert(!(sub instanceof SequenceChunk), 0x737 /* unexpected nested sequence */);\n\t\t\tassert(sub !== emptyChunk, 0x738 /* unexpected empty chunk */);\n\n\t\t\tsub.referenceAdded();\n\t\t}\n\n\t\tchunk.referenceRemoved();\n\t\treturn chunk.subChunks;\n\t} else {\n\t\treturn [chunk];\n\t}\n}\n\n/**\n * Normalize a {@link TreeChunk}[] into a single TreeChunk.\n *\n * Avoids creating nested or less than 2 child {@link SequenceChunk}s.\n */\nexport function aggregateChunks(input: TreeChunk[]): TreeChunk {\n\tconst chunks = input.flatMap(deaggregateChunks);\n\tswitch (chunks.length) {\n\t\tcase 0: {\n\t\t\treturn emptyChunk;\n\t\t}\n\t\tcase 1: {\n\t\t\treturn chunks[0] ?? oob();\n\t\t}\n\t\tdefault: {\n\t\t\treturn new SequenceChunk(chunks);\n\t\t}\n\t}\n}\n\n/**\n * Decoder for {@link EncodedNestedArrayShape}s.\n */\nexport class NestedArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedNestedArrayShape) {}\n\tpublic decode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst decoder = decoders[this.shape] ?? oob();\n\n\t\t// TODO: uniform chunk fast path\n\t\tconst chunks: TreeChunk[] = [];\n\n\t\tconst data = readStream(stream);\n\t\tif (typeof data === \"number\") {\n\t\t\t// This case means that the array contained only 0-sized items, and was thus encoded as the length of the array.\n\t\t\tconst inner = { data: [], offset: 0 };\n\t\t\tfor (let index = 0; index < data; index++) {\n\t\t\t\tchunks.push(decoder.decode(decoders, inner));\n\t\t\t}\n\t\t} else {\n\t\t\tassert(\n\t\t\t\tArray.isArray(data),\n\t\t\t\t0x739 /* expected number of array for encoding of nested array */,\n\t\t\t);\n\t\t\tconst inner = { data, offset: 0 };\n\t\t\twhile (inner.offset !== inner.data.length) {\n\t\t\t\tchunks.push(decoder.decode(decoders, inner));\n\t\t\t}\n\t\t}\n\n\t\treturn aggregateChunks(chunks);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedInlineArrayShape}s.\n */\nexport class InlineArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedInlineArrayShape) {}\n\tpublic decode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst length = this.shape.length;\n\t\tconst decoder = decoders[this.shape.shape] ?? oob();\n\t\tconst chunks: TreeChunk[] = [];\n\t\tfor (let index = 0; index < length; index++) {\n\t\t\tchunks.push(decoder.decode(decoders, stream));\n\t\t}\n\t\treturn aggregateChunks(chunks);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedIncrementalChunkShape}s.\n */\nexport class IncrementalChunkDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly context: DecoderContext<EncodedChunkShape>) {}\n\tpublic decode(_: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tassert(\n\t\t\tthis.context.incrementalDecoder !== undefined,\n\t\t\t0xc27 /* incremental decoder not available for incremental field decoding */,\n\t\t);\n\n\t\tconst chunkDecoder = (batch: EncodedFieldBatch): TreeChunk => {\n\t\t\tassert(\n\t\t\t\tbatch.version >= FieldBatchFormatVersion.v2,\n\t\t\t\t0xc9f /* Unsupported FieldBatchFormatVersion for incremental chunks; must be v2 or higher */,\n\t\t\t);\n\t\t\tconst context = new DecoderContext(\n\t\t\t\tbatch.identifiers,\n\t\t\t\tbatch.shapes,\n\t\t\t\tthis.context.idDecodingContext,\n\t\t\t\tthis.context.incrementalDecoder,\n\t\t\t);\n\t\t\tconst chunks = genericDecode(decoderLibrary, context, batch, anyDecoder);\n\t\t\treturn aggregateChunks(chunks);\n\t\t};\n\n\t\tconst chunkReferenceId = readStreamNumber(stream);\n\t\treturn this.context.incrementalDecoder.decodeIncrementalChunk(\n\t\t\tbrand(chunkReferenceId),\n\t\t\tchunkDecoder,\n\t\t);\n\t}\n}\n\n/**\n * Decoder for {@link EncodedAnyShape}s.\n */\nexport const anyDecoder: ChunkDecoder = {\n\tdecode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst shapeIndex = readStreamNumber(stream);\n\t\tconst decoder = getChecked(decoders, shapeIndex);\n\t\treturn decoder.decode(decoders, stream);\n\t},\n};\n\n/**\n * Decoder for field.\n */\ntype BasicFieldDecoder = (\n\tdecoders: readonly ChunkDecoder[],\n\tstream: StreamCursor,\n) => [FieldKey, TreeChunk];\n\n/**\n * Get a decoder for fields of a provided (via `shape` and `context`) {@link EncodedChunkShape}.\n */\nfunction fieldDecoder(\n\tcontext: DecoderContext<EncodedChunkShape>,\n\tkey: FieldKey,\n\tshape: number,\n): BasicFieldDecoder {\n\tassertValidIndex(shape, context.shapes);\n\treturn (decoders, stream) => {\n\t\tconst decoder = decoders[shape] ?? oob();\n\t\treturn [key, decoder.decode(decoders, stream)];\n\t};\n}\n\n/**\n * Decoder for {@link EncodedNodeShape}s.\n */\nexport class NodeDecoder implements ChunkDecoder {\n\tprivate readonly type?: TreeNodeSchemaIdentifier;\n\tprivate readonly fieldDecoders: readonly BasicFieldDecoder[];\n\tpublic constructor(\n\t\tprivate readonly shape: EncodedNodeShape,\n\t\tprivate readonly context: DecoderContext<EncodedChunkShape>,\n\t) {\n\t\tthis.type = shape.type === undefined ? undefined : context.identifier(shape.type);\n\n\t\tconst fieldDecoders: BasicFieldDecoder[] = [];\n\t\tfor (const [fieldKey, fieldShape] of shape.fields ?? []) {\n\t\t\tconst key: FieldKey = context.identifier(fieldKey);\n\t\t\tfieldDecoders.push(fieldDecoder(context, key, fieldShape));\n\t\t}\n\t\tthis.fieldDecoders = fieldDecoders;\n\t}\n\tpublic decode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk {\n\t\tconst type: TreeNodeSchemaIdentifier =\n\t\t\tthis.type ?? readStreamIdentifier(stream, this.context);\n\t\t// TODO: Consider typechecking against stored schema in here somewhere.\n\n\t\tconst value = readValue(stream, this.shape.value, this.context.idDecodingContext);\n\t\tconst fields: Map<FieldKey, TreeChunk[]> = new Map();\n\n\t\t// Helper to add fields, but with unneeded array chunks removed.\n\t\tfunction addField(key: FieldKey, data: TreeChunk): void {\n\t\t\t// TODO: when handling of ArrayChunks has better performance (for example in cursors),\n\t\t\t// consider keeping array chunks here if they are longer than some threshold.\n\t\t\tconst chunks = deaggregateChunks(data);\n\n\t\t\tif (chunks.length > 0) {\n\t\t\t\tfields.set(key, chunks);\n\t\t\t}\n\t\t}\n\n\t\tfor (const decoder of this.fieldDecoders) {\n\t\t\tconst [key, content] = decoder(decoders, stream);\n\t\t\taddField(key, content);\n\t\t}\n\n\t\tif (this.shape.extraFields !== undefined) {\n\t\t\tconst decoder = decoders[this.shape.extraFields] ?? oob();\n\t\t\tconst inner = readStreamStream(stream);\n\t\t\twhile (inner.offset !== inner.data.length) {\n\t\t\t\tconst key: FieldKey = readStreamIdentifier(inner, this.context);\n\t\t\t\taddField(key, decoder.decode(decoders, inner));\n\t\t\t}\n\t\t}\n\n\t\treturn new BasicChunk(type, fields, value);\n\t}\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/codecs.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,aAAa,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AACH,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,MAAM,EAAE,yBAAyB,CAAC,CAAC;AAGxE;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;OAGG;IACH,yBAAyB,EAAE,yBAAyB,CAAC;IACrD;;;;;;;OAOG;IACH,sBAAsB,CACrB,MAAM,EAAE,sBAAsB,EAC9B,YAAY,EAAE,CAAC,KAAK,EAAE,SAAS,KAAK,iBAAiB,GACnD,gBAAgB,EAAE,CAAC;CACtB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,kBAAkB;IAClC;;;;;OAKG;IACH,sBAAsB,CACrB,WAAW,EAAE,gBAAgB,EAC7B,YAAY,EAAE,CAAC,OAAO,EAAE,iBAAiB,KAAK,SAAS,GACrD,SAAS,CAAC;CACb;AACD;;GAEG;AACH,MAAM,WAAW,yBAA0B,SAAQ,kBAAkB,EAAE,kBAAkB;CAAG;AAE5F,MAAM,WAAW,yBAAyB;IACzC,QAAQ,CAAC,UAAU,EAAE,uBAAuB,CAAC;IAC7C,QAAQ,CAAC,YAAY,EAAE,aAAa,CAAC;IACrC,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC;IACjC,QAAQ,CAAC,MAAM,CAAC,EAAE,eAAe,CAAC;IAClC;;;OAGG;IACH,QAAQ,CAAC,yBAAyB,CAAC,EAAE,yBAAyB,CAAC;CAC/D;AACD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,UAAU,CACvC,UAAU,EACV,iBAAiB,EACjB,sBAAsB,EACtB,yBAAyB,CACzB,CAAC;AAiBF,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,eAAe,CA+F/E;AAED,wBAAgB,+BAA+B,CAC9C,aAAa,EAAE,uBAAuB,GACpC,SAAS,CAEX"}
@@ -36,18 +36,21 @@ function makeFieldBatchCodec(options) {
36
36
  let schemaCompressedEncodeFn;
37
37
  let encodedFieldBatchType;
38
38
  switch (writeVersion) {
39
- case format_js_1.FieldBatchFormatVersion.v1:
39
+ case (0, index_js_2.unbrand)(format_js_1.FieldBatchFormatVersion.v1): {
40
40
  uncompressedEncodeFn = uncompressedEncode_js_1.uncompressedEncodeV1;
41
41
  schemaCompressedEncodeFn = schemaBasedEncode_js_1.schemaCompressedEncodeV1;
42
42
  encodedFieldBatchType = format_js_1.EncodedFieldBatchV1;
43
43
  break;
44
- case format_js_1.FieldBatchFormatVersion.v2:
44
+ }
45
+ case (0, index_js_2.unbrand)(format_js_1.FieldBatchFormatVersion.v2): {
45
46
  uncompressedEncodeFn = uncompressedEncode_js_1.uncompressedEncodeV2;
46
47
  schemaCompressedEncodeFn = schemaBasedEncode_js_1.schemaCompressedEncodeV2;
47
48
  encodedFieldBatchType = format_js_1.EncodedFieldBatchV2;
48
49
  break;
49
- default:
50
+ }
51
+ default: {
50
52
  (0, internal_1.unreachableCase)(writeVersion);
53
+ }
51
54
  }
52
55
  return (0, index_js_1.makeVersionedValidatedCodec)(options, format_js_1.validVersions, encodedFieldBatchType, {
53
56
  encode: (data, context) => {
@@ -57,25 +60,30 @@ function makeFieldBatchCodec(options) {
57
60
  let encoded;
58
61
  let incrementalEncoder;
59
62
  switch (context.encodeType) {
60
- case treeCompressionUtils_js_1.TreeCompressionStrategy.Uncompressed:
63
+ case treeCompressionUtils_js_1.TreeCompressionStrategy.Uncompressed: {
61
64
  encoded = uncompressedEncodeFn(data);
62
65
  break;
63
- case treeCompressionUtils_js_1.TreeCompressionStrategy.CompressedIncremental:
66
+ }
67
+ case treeCompressionUtils_js_1.TreeCompressionStrategy.CompressedIncremental: {
64
68
  (0, internal_1.assert)(writeVersion >= format_js_1.FieldBatchFormatVersion.v2, 0xca0 /* Unsupported FieldBatchFormatVersion for incremental encoding; must be v2 or higher */);
65
69
  // Incremental encoding is only supported for CompressedIncremental.
66
70
  incrementalEncoder = context.incrementalEncoderDecoder;
67
- case treeCompressionUtils_js_1.TreeCompressionStrategy.Compressed:
71
+ }
72
+ // fallthrough
73
+ case treeCompressionUtils_js_1.TreeCompressionStrategy.Compressed: {
68
74
  // eslint-disable-next-line unicorn/prefer-ternary
69
- if (context.schema !== undefined) {
70
- encoded = schemaCompressedEncodeFn(context.schema.schema, context.schema.policy, data, context.idCompressor, incrementalEncoder);
71
- }
72
- else {
75
+ if (context.schema === undefined) {
73
76
  // TODO: consider enabling a somewhat compressed but not schema accelerated encode.
74
77
  encoded = uncompressedEncodeFn(data);
75
78
  }
79
+ else {
80
+ encoded = schemaCompressedEncodeFn(context.schema.schema, context.schema.policy, data, context.idCompressor, incrementalEncoder);
81
+ }
76
82
  break;
77
- default:
83
+ }
84
+ default: {
78
85
  (0, internal_1.unreachableCase)(context.encodeType);
86
+ }
79
87
  }
80
88
  // TODO: consider checking input data was in schema.
81
89
  return encoded;