@fluidframework/tree 2.10.0 → 2.12.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 (776) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/api-report/tree.alpha.api.md +49 -18
  3. package/api-report/tree.beta.api.md +6 -15
  4. package/api-report/tree.legacy.alpha.api.md +6 -15
  5. package/api-report/tree.legacy.public.api.md +6 -15
  6. package/api-report/tree.public.api.md +6 -15
  7. package/dist/alpha.d.ts +9 -0
  8. package/dist/core/forest/forest.d.ts +10 -2
  9. package/dist/core/forest/forest.d.ts.map +1 -1
  10. package/dist/core/forest/forest.js.map +1 -1
  11. package/dist/core/index.d.ts +3 -3
  12. package/dist/core/index.d.ts.map +1 -1
  13. package/dist/core/index.js +6 -3
  14. package/dist/core/index.js.map +1 -1
  15. package/dist/core/rebase/utils.d.ts +1 -1
  16. package/dist/core/rebase/utils.d.ts.map +1 -1
  17. package/dist/core/rebase/utils.js +13 -17
  18. package/dist/core/rebase/utils.js.map +1 -1
  19. package/dist/core/revertible.d.ts +30 -1
  20. package/dist/core/revertible.d.ts.map +1 -1
  21. package/dist/core/revertible.js.map +1 -1
  22. package/dist/core/schema-stored/format.d.ts +0 -3
  23. package/dist/core/schema-stored/format.d.ts.map +1 -1
  24. package/dist/core/schema-stored/format.js.map +1 -1
  25. package/dist/core/schema-stored/schema.d.ts +12 -10
  26. package/dist/core/schema-stored/schema.d.ts.map +1 -1
  27. package/dist/core/schema-stored/schema.js +3 -5
  28. package/dist/core/schema-stored/schema.js.map +1 -1
  29. package/dist/core/schema-stored/storedSchemaRepository.d.ts +2 -2
  30. package/dist/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  31. package/dist/core/schema-stored/storedSchemaRepository.js +5 -5
  32. package/dist/core/schema-stored/storedSchemaRepository.js.map +1 -1
  33. package/dist/core/schema-view/index.d.ts +1 -1
  34. package/dist/core/schema-view/index.d.ts.map +1 -1
  35. package/dist/core/schema-view/index.js +1 -2
  36. package/dist/core/schema-view/index.js.map +1 -1
  37. package/dist/core/schema-view/view.d.ts +0 -7
  38. package/dist/core/schema-view/view.d.ts.map +1 -1
  39. package/dist/core/schema-view/view.js +1 -12
  40. package/dist/core/schema-view/view.js.map +1 -1
  41. package/dist/core/tree/anchorSet.d.ts +2 -2
  42. package/dist/core/tree/anchorSet.d.ts.map +1 -1
  43. package/dist/core/tree/anchorSet.js +21 -21
  44. package/dist/core/tree/anchorSet.js.map +1 -1
  45. package/{lib/feature-libraries/chunked-forest → dist/core/tree}/chunk.d.ts +2 -1
  46. package/dist/core/tree/chunk.d.ts.map +1 -0
  47. package/dist/{feature-libraries/chunked-forest → core/tree}/chunk.js +2 -2
  48. package/dist/core/tree/chunk.js.map +1 -0
  49. package/dist/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  50. package/dist/core/tree/detachedFieldIndexCodec.js +3 -2
  51. package/dist/core/tree/detachedFieldIndexCodec.js.map +1 -1
  52. package/dist/core/tree/index.d.ts +2 -1
  53. package/dist/core/tree/index.d.ts.map +1 -1
  54. package/dist/core/tree/index.js +6 -1
  55. package/dist/core/tree/index.js.map +1 -1
  56. package/dist/core/tree/treeTextFormat.d.ts +0 -5
  57. package/dist/core/tree/treeTextFormat.d.ts.map +1 -1
  58. package/dist/core/tree/treeTextFormat.js.map +1 -1
  59. package/dist/core/tree/types.d.ts +0 -5
  60. package/dist/core/tree/types.d.ts.map +1 -1
  61. package/dist/core/tree/types.js +0 -1
  62. package/dist/core/tree/types.js.map +1 -1
  63. package/dist/core/tree/visitorUtils.d.ts +25 -1
  64. package/dist/core/tree/visitorUtils.d.ts.map +1 -1
  65. package/dist/core/tree/visitorUtils.js +29 -1
  66. package/dist/core/tree/visitorUtils.js.map +1 -1
  67. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts +1 -2
  68. package/dist/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  69. package/dist/feature-libraries/chunked-forest/basicChunk.js +14 -14
  70. package/dist/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  71. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts +1 -2
  72. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  73. package/dist/feature-libraries/chunked-forest/chunkTree.js +2 -3
  74. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  75. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts +5 -3
  76. package/dist/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  77. package/dist/feature-libraries/chunked-forest/chunkedForest.js +24 -14
  78. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  79. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts +1 -2
  80. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts.map +1 -1
  81. package/dist/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  82. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +1 -2
  83. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  84. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  85. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +1 -1
  86. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  87. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  88. package/dist/feature-libraries/chunked-forest/emptyChunk.d.ts +1 -1
  89. package/dist/feature-libraries/chunked-forest/emptyChunk.d.ts.map +1 -1
  90. package/dist/feature-libraries/chunked-forest/emptyChunk.js +2 -3
  91. package/dist/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  92. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
  93. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  94. package/dist/feature-libraries/chunked-forest/index.js +5 -5
  95. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  96. package/dist/feature-libraries/chunked-forest/sequenceChunk.d.ts +1 -1
  97. package/dist/feature-libraries/chunked-forest/sequenceChunk.d.ts.map +1 -1
  98. package/dist/feature-libraries/chunked-forest/sequenceChunk.js +2 -2
  99. package/dist/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  100. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts +1 -2
  101. package/dist/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  102. package/dist/feature-libraries/chunked-forest/uniformChunk.js +14 -14
  103. package/dist/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  104. package/dist/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
  105. package/dist/feature-libraries/default-schema/defaultSchema.js +1 -0
  106. package/dist/feature-libraries/default-schema/defaultSchema.js.map +1 -1
  107. package/dist/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  108. package/dist/feature-libraries/default-schema/schemaChecker.js +2 -1
  109. package/dist/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  110. package/dist/feature-libraries/flex-tree/context.d.ts +1 -1
  111. package/dist/feature-libraries/flex-tree/context.d.ts.map +1 -1
  112. package/dist/feature-libraries/flex-tree/context.js.map +1 -1
  113. package/dist/feature-libraries/index.d.ts +2 -1
  114. package/dist/feature-libraries/index.d.ts.map +1 -1
  115. package/dist/feature-libraries/index.js +9 -2
  116. package/dist/feature-libraries/index.js.map +1 -1
  117. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts +139 -0
  118. package/dist/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -0
  119. package/dist/feature-libraries/indexing/anchorTreeIndex.js +387 -0
  120. package/dist/feature-libraries/indexing/anchorTreeIndex.js.map +1 -0
  121. package/dist/feature-libraries/indexing/index.d.ts +7 -0
  122. package/dist/feature-libraries/indexing/index.d.ts.map +1 -0
  123. package/dist/feature-libraries/indexing/index.js +11 -0
  124. package/dist/feature-libraries/indexing/index.js.map +1 -0
  125. package/dist/feature-libraries/indexing/types.d.ts +32 -0
  126. package/dist/feature-libraries/indexing/types.d.ts.map +1 -0
  127. package/dist/{events/interop.js → feature-libraries/indexing/types.js} +1 -1
  128. package/dist/feature-libraries/indexing/types.js.map +1 -0
  129. package/dist/feature-libraries/modular-schema/discrepancies.d.ts +84 -24
  130. package/dist/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  131. package/dist/feature-libraries/modular-schema/discrepancies.js +32 -33
  132. package/dist/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  133. package/dist/feature-libraries/modular-schema/index.d.ts +1 -1
  134. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  135. package/dist/feature-libraries/modular-schema/index.js +5 -1
  136. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  137. package/dist/feature-libraries/modular-schema/isNeverTree.d.ts +0 -1
  138. package/dist/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  139. package/dist/feature-libraries/modular-schema/isNeverTree.js +0 -1
  140. package/dist/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  141. package/dist/feature-libraries/object-forest/objectForest.d.ts +5 -2
  142. package/dist/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  143. package/dist/feature-libraries/object-forest/objectForest.js +21 -11
  144. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  145. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +6 -6
  146. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  147. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +7 -7
  148. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  149. package/dist/feature-libraries/schema-edits/schemaChangeFormat.d.ts +12 -12
  150. package/dist/feature-libraries/sequence-field/formatV1.d.ts +99 -99
  151. package/dist/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  152. package/dist/feature-libraries/sequence-field/formatV2.d.ts +76 -76
  153. package/dist/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  154. package/dist/feature-libraries/sequence-field/formatV3.d.ts +54 -54
  155. package/dist/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  156. package/dist/feature-libraries/sequence-field/invert.js +2 -2
  157. package/dist/feature-libraries/sequence-field/invert.js.map +1 -1
  158. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js +3 -2
  159. package/dist/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  160. package/dist/feature-libraries/sequence-field/types.d.ts +0 -1
  161. package/dist/feature-libraries/sequence-field/types.d.ts.map +1 -1
  162. package/dist/feature-libraries/sequence-field/types.js.map +1 -1
  163. package/dist/index.d.ts +6 -7
  164. package/dist/index.d.ts.map +1 -1
  165. package/dist/index.js +3 -13
  166. package/dist/index.js.map +1 -1
  167. package/dist/packageVersion.d.ts +1 -1
  168. package/dist/packageVersion.js +1 -1
  169. package/dist/packageVersion.js.map +1 -1
  170. package/dist/shared-tree/index.d.ts +2 -2
  171. package/dist/shared-tree/index.d.ts.map +1 -1
  172. package/dist/shared-tree/index.js +1 -2
  173. package/dist/shared-tree/index.js.map +1 -1
  174. package/dist/shared-tree/schematizeTree.d.ts +1 -1
  175. package/dist/shared-tree/schematizeTree.d.ts.map +1 -1
  176. package/dist/shared-tree/schematizeTree.js +6 -6
  177. package/dist/shared-tree/schematizeTree.js.map +1 -1
  178. package/dist/shared-tree/schematizingTreeView.d.ts +7 -1
  179. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  180. package/dist/shared-tree/schematizingTreeView.js +35 -38
  181. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  182. package/dist/shared-tree/sharedTree.d.ts +27 -6
  183. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  184. package/dist/shared-tree/sharedTree.js +146 -21
  185. package/dist/shared-tree/sharedTree.js.map +1 -1
  186. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  187. package/dist/shared-tree/sharedTreeChangeFamily.js +3 -3
  188. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  189. package/dist/shared-tree/treeCheckout.d.ts +59 -72
  190. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  191. package/dist/shared-tree/treeCheckout.js +243 -188
  192. package/dist/shared-tree/treeCheckout.js.map +1 -1
  193. package/dist/shared-tree-core/branch.d.ts +29 -107
  194. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  195. package/dist/shared-tree-core/branch.js +51 -195
  196. package/dist/shared-tree-core/branch.js.map +1 -1
  197. package/dist/shared-tree-core/branchCommitEnricher.d.ts +24 -32
  198. package/dist/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  199. package/dist/shared-tree-core/branchCommitEnricher.js +70 -53
  200. package/dist/shared-tree-core/branchCommitEnricher.js.map +1 -1
  201. package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  202. package/dist/shared-tree-core/defaultResubmitMachine.js +2 -1
  203. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  204. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  205. package/dist/shared-tree-core/editManager.js +4 -4
  206. package/dist/shared-tree-core/editManager.js.map +1 -1
  207. package/dist/shared-tree-core/index.d.ts +3 -3
  208. package/dist/shared-tree-core/index.d.ts.map +1 -1
  209. package/dist/shared-tree-core/index.js +5 -4
  210. package/dist/shared-tree-core/index.js.map +1 -1
  211. package/dist/shared-tree-core/sharedTreeCore.d.ts +3 -10
  212. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  213. package/dist/shared-tree-core/sharedTreeCore.js +14 -67
  214. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  215. package/dist/shared-tree-core/transaction.d.ts +146 -0
  216. package/dist/shared-tree-core/transaction.d.ts.map +1 -0
  217. package/dist/shared-tree-core/transaction.js +211 -0
  218. package/dist/shared-tree-core/transaction.js.map +1 -0
  219. package/dist/shared-tree-core/transactionEnricher.d.ts +8 -13
  220. package/dist/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  221. package/dist/shared-tree-core/transactionEnricher.js +41 -21
  222. package/dist/shared-tree-core/transactionEnricher.js.map +1 -1
  223. package/dist/simple-tree/api/conciseTree.d.ts.map +1 -1
  224. package/dist/simple-tree/api/conciseTree.js +1 -1
  225. package/dist/simple-tree/api/conciseTree.js.map +1 -1
  226. package/dist/simple-tree/api/create.d.ts.map +1 -1
  227. package/dist/simple-tree/api/create.js +5 -1
  228. package/dist/simple-tree/api/create.js.map +1 -1
  229. package/dist/simple-tree/api/customTree.d.ts +14 -2
  230. package/dist/simple-tree/api/customTree.d.ts.map +1 -1
  231. package/dist/simple-tree/api/customTree.js +53 -3
  232. package/dist/simple-tree/api/customTree.js.map +1 -1
  233. package/dist/simple-tree/api/identifierIndex.d.ts +21 -0
  234. package/dist/simple-tree/api/identifierIndex.d.ts.map +1 -0
  235. package/dist/simple-tree/api/identifierIndex.js +45 -0
  236. package/dist/simple-tree/api/identifierIndex.js.map +1 -0
  237. package/dist/simple-tree/api/index.d.ts +4 -2
  238. package/dist/simple-tree/api/index.d.ts.map +1 -1
  239. package/dist/simple-tree/api/index.js +8 -1
  240. package/dist/simple-tree/api/index.js.map +1 -1
  241. package/dist/simple-tree/api/schemaFactory.d.ts +48 -0
  242. package/dist/simple-tree/api/schemaFactory.d.ts.map +1 -1
  243. package/dist/simple-tree/api/schemaFactory.js +5 -2
  244. package/dist/simple-tree/api/schemaFactory.js.map +1 -1
  245. package/dist/simple-tree/api/simpleSchema.d.ts +3 -1
  246. package/dist/simple-tree/api/simpleSchema.d.ts.map +1 -1
  247. package/dist/simple-tree/api/simpleSchema.js.map +1 -1
  248. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js +9 -7
  249. package/dist/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  250. package/dist/simple-tree/api/simpleTreeIndex.d.ts +65 -0
  251. package/dist/simple-tree/api/simpleTreeIndex.d.ts.map +1 -0
  252. package/dist/simple-tree/api/simpleTreeIndex.js +93 -0
  253. package/dist/simple-tree/api/simpleTreeIndex.js.map +1 -0
  254. package/dist/simple-tree/api/storedSchema.d.ts +4 -4
  255. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  256. package/dist/simple-tree/api/storedSchema.js +8 -21
  257. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  258. package/dist/simple-tree/api/tree.d.ts +5 -5
  259. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  260. package/dist/simple-tree/api/tree.js.map +1 -1
  261. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  262. package/dist/simple-tree/api/verboseTree.js +1 -1
  263. package/dist/simple-tree/api/verboseTree.js.map +1 -1
  264. package/dist/simple-tree/api/view.d.ts +14 -9
  265. package/dist/simple-tree/api/view.d.ts.map +1 -1
  266. package/dist/simple-tree/api/view.js +129 -40
  267. package/dist/simple-tree/api/view.js.map +1 -1
  268. package/dist/simple-tree/core/index.d.ts +1 -1
  269. package/dist/simple-tree/core/index.d.ts.map +1 -1
  270. package/dist/simple-tree/core/index.js +2 -1
  271. package/dist/simple-tree/core/index.js.map +1 -1
  272. package/dist/simple-tree/core/treeNodeKernel.d.ts +6 -2
  273. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  274. package/dist/simple-tree/core/treeNodeKernel.js +53 -22
  275. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  276. package/dist/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
  277. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  278. package/dist/simple-tree/core/unhydratedFlexTree.js +2 -2
  279. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  280. package/dist/simple-tree/index.d.ts +2 -2
  281. package/dist/simple-tree/index.d.ts.map +1 -1
  282. package/dist/simple-tree/index.js +7 -2
  283. package/dist/simple-tree/index.js.map +1 -1
  284. package/dist/simple-tree/leafNodeSchema.d.ts +0 -15
  285. package/dist/simple-tree/leafNodeSchema.d.ts.map +1 -1
  286. package/dist/simple-tree/leafNodeSchema.js +0 -15
  287. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  288. package/dist/simple-tree/objectNode.d.ts +15 -5
  289. package/dist/simple-tree/objectNode.d.ts.map +1 -1
  290. package/dist/simple-tree/objectNode.js +18 -2
  291. package/dist/simple-tree/objectNode.js.map +1 -1
  292. package/dist/simple-tree/objectNodeTypes.d.ts +4 -0
  293. package/dist/simple-tree/objectNodeTypes.d.ts.map +1 -1
  294. package/dist/simple-tree/objectNodeTypes.js.map +1 -1
  295. package/dist/simple-tree/schemaTypes.d.ts +4 -2
  296. package/dist/simple-tree/schemaTypes.d.ts.map +1 -1
  297. package/dist/simple-tree/schemaTypes.js.map +1 -1
  298. package/dist/simple-tree/toMapTree.js +3 -3
  299. package/dist/simple-tree/toMapTree.js.map +1 -1
  300. package/dist/simple-tree/toStoredSchema.d.ts.map +1 -1
  301. package/dist/simple-tree/toStoredSchema.js +18 -13
  302. package/dist/simple-tree/toStoredSchema.js.map +1 -1
  303. package/dist/util/brand.d.ts +0 -2
  304. package/dist/util/brand.d.ts.map +1 -1
  305. package/dist/util/brand.js +0 -1
  306. package/dist/util/brand.js.map +1 -1
  307. package/dist/util/index.d.ts +1 -2
  308. package/dist/util/index.d.ts.map +1 -1
  309. package/dist/util/index.js +6 -4
  310. package/dist/util/index.js.map +1 -1
  311. package/dist/util/typeCheck.d.ts +6 -3
  312. package/dist/util/typeCheck.d.ts.map +1 -1
  313. package/dist/util/typeCheck.js.map +1 -1
  314. package/dist/util/typeCheckTests.d.ts +14 -2
  315. package/dist/util/typeCheckTests.d.ts.map +1 -1
  316. package/dist/util/typeCheckTests.js.map +1 -1
  317. package/dist/util/utils.d.ts +42 -0
  318. package/dist/util/utils.d.ts.map +1 -1
  319. package/dist/util/utils.js +35 -1
  320. package/dist/util/utils.js.map +1 -1
  321. package/lib/alpha.d.ts +9 -0
  322. package/lib/core/forest/forest.d.ts +10 -2
  323. package/lib/core/forest/forest.d.ts.map +1 -1
  324. package/lib/core/forest/forest.js.map +1 -1
  325. package/lib/core/index.d.ts +3 -3
  326. package/lib/core/index.d.ts.map +1 -1
  327. package/lib/core/index.js +3 -3
  328. package/lib/core/index.js.map +1 -1
  329. package/lib/core/rebase/utils.d.ts +1 -1
  330. package/lib/core/rebase/utils.d.ts.map +1 -1
  331. package/lib/core/rebase/utils.js +13 -17
  332. package/lib/core/rebase/utils.js.map +1 -1
  333. package/lib/core/revertible.d.ts +30 -1
  334. package/lib/core/revertible.d.ts.map +1 -1
  335. package/lib/core/revertible.js.map +1 -1
  336. package/lib/core/schema-stored/format.d.ts +0 -3
  337. package/lib/core/schema-stored/format.d.ts.map +1 -1
  338. package/lib/core/schema-stored/format.js.map +1 -1
  339. package/lib/core/schema-stored/schema.d.ts +12 -10
  340. package/lib/core/schema-stored/schema.d.ts.map +1 -1
  341. package/lib/core/schema-stored/schema.js +3 -5
  342. package/lib/core/schema-stored/schema.js.map +1 -1
  343. package/lib/core/schema-stored/storedSchemaRepository.d.ts +2 -2
  344. package/lib/core/schema-stored/storedSchemaRepository.d.ts.map +1 -1
  345. package/lib/core/schema-stored/storedSchemaRepository.js +1 -1
  346. package/lib/core/schema-stored/storedSchemaRepository.js.map +1 -1
  347. package/lib/core/schema-view/index.d.ts +1 -1
  348. package/lib/core/schema-view/index.d.ts.map +1 -1
  349. package/lib/core/schema-view/index.js +1 -1
  350. package/lib/core/schema-view/index.js.map +1 -1
  351. package/lib/core/schema-view/view.d.ts +0 -7
  352. package/lib/core/schema-view/view.d.ts.map +1 -1
  353. package/lib/core/schema-view/view.js +0 -11
  354. package/lib/core/schema-view/view.js.map +1 -1
  355. package/lib/core/tree/anchorSet.d.ts +2 -2
  356. package/lib/core/tree/anchorSet.d.ts.map +1 -1
  357. package/lib/core/tree/anchorSet.js +1 -1
  358. package/lib/core/tree/anchorSet.js.map +1 -1
  359. package/{dist/feature-libraries/chunked-forest → lib/core/tree}/chunk.d.ts +2 -1
  360. package/lib/core/tree/chunk.d.ts.map +1 -0
  361. package/lib/{feature-libraries/chunked-forest → core/tree}/chunk.js +1 -1
  362. package/lib/core/tree/chunk.js.map +1 -0
  363. package/lib/core/tree/detachedFieldIndexCodec.d.ts.map +1 -1
  364. package/lib/core/tree/detachedFieldIndexCodec.js +4 -3
  365. package/lib/core/tree/detachedFieldIndexCodec.js.map +1 -1
  366. package/lib/core/tree/index.d.ts +2 -1
  367. package/lib/core/tree/index.d.ts.map +1 -1
  368. package/lib/core/tree/index.js +2 -1
  369. package/lib/core/tree/index.js.map +1 -1
  370. package/lib/core/tree/treeTextFormat.d.ts +0 -5
  371. package/lib/core/tree/treeTextFormat.d.ts.map +1 -1
  372. package/lib/core/tree/treeTextFormat.js.map +1 -1
  373. package/lib/core/tree/types.d.ts +0 -5
  374. package/lib/core/tree/types.d.ts.map +1 -1
  375. package/lib/core/tree/types.js +0 -1
  376. package/lib/core/tree/types.js.map +1 -1
  377. package/lib/core/tree/visitorUtils.d.ts +25 -1
  378. package/lib/core/tree/visitorUtils.d.ts.map +1 -1
  379. package/lib/core/tree/visitorUtils.js +27 -0
  380. package/lib/core/tree/visitorUtils.js.map +1 -1
  381. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts +1 -2
  382. package/lib/feature-libraries/chunked-forest/basicChunk.d.ts.map +1 -1
  383. package/lib/feature-libraries/chunked-forest/basicChunk.js +1 -1
  384. package/lib/feature-libraries/chunked-forest/basicChunk.js.map +1 -1
  385. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts +1 -2
  386. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  387. package/lib/feature-libraries/chunked-forest/chunkTree.js +1 -2
  388. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  389. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts +5 -3
  390. package/lib/feature-libraries/chunked-forest/chunkedForest.d.ts.map +1 -1
  391. package/lib/feature-libraries/chunked-forest/chunkedForest.js +18 -8
  392. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  393. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts +1 -2
  394. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.d.ts.map +1 -1
  395. package/lib/feature-libraries/chunked-forest/codec/chunkCodecUtilities.js.map +1 -1
  396. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +1 -2
  397. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  398. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  399. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +1 -1
  400. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  401. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  402. package/lib/feature-libraries/chunked-forest/emptyChunk.d.ts +1 -1
  403. package/lib/feature-libraries/chunked-forest/emptyChunk.d.ts.map +1 -1
  404. package/lib/feature-libraries/chunked-forest/emptyChunk.js +1 -2
  405. package/lib/feature-libraries/chunked-forest/emptyChunk.js.map +1 -1
  406. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
  407. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  408. package/lib/feature-libraries/chunked-forest/index.js +1 -1
  409. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  410. package/lib/feature-libraries/chunked-forest/sequenceChunk.d.ts +1 -1
  411. package/lib/feature-libraries/chunked-forest/sequenceChunk.d.ts.map +1 -1
  412. package/lib/feature-libraries/chunked-forest/sequenceChunk.js +1 -1
  413. package/lib/feature-libraries/chunked-forest/sequenceChunk.js.map +1 -1
  414. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts +1 -2
  415. package/lib/feature-libraries/chunked-forest/uniformChunk.d.ts.map +1 -1
  416. package/lib/feature-libraries/chunked-forest/uniformChunk.js +4 -4
  417. package/lib/feature-libraries/chunked-forest/uniformChunk.js.map +1 -1
  418. package/lib/feature-libraries/default-schema/defaultSchema.d.ts.map +1 -1
  419. package/lib/feature-libraries/default-schema/defaultSchema.js +1 -0
  420. package/lib/feature-libraries/default-schema/defaultSchema.js.map +1 -1
  421. package/lib/feature-libraries/default-schema/schemaChecker.d.ts.map +1 -1
  422. package/lib/feature-libraries/default-schema/schemaChecker.js +2 -1
  423. package/lib/feature-libraries/default-schema/schemaChecker.js.map +1 -1
  424. package/lib/feature-libraries/flex-tree/context.d.ts +1 -1
  425. package/lib/feature-libraries/flex-tree/context.d.ts.map +1 -1
  426. package/lib/feature-libraries/flex-tree/context.js.map +1 -1
  427. package/lib/feature-libraries/index.d.ts +2 -1
  428. package/lib/feature-libraries/index.d.ts.map +1 -1
  429. package/lib/feature-libraries/index.js +2 -1
  430. package/lib/feature-libraries/index.js.map +1 -1
  431. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts +139 -0
  432. package/lib/feature-libraries/indexing/anchorTreeIndex.d.ts.map +1 -0
  433. package/lib/feature-libraries/indexing/anchorTreeIndex.js +382 -0
  434. package/lib/feature-libraries/indexing/anchorTreeIndex.js.map +1 -0
  435. package/lib/feature-libraries/indexing/index.d.ts +7 -0
  436. package/lib/feature-libraries/indexing/index.d.ts.map +1 -0
  437. package/lib/{events → feature-libraries/indexing}/index.js +1 -1
  438. package/lib/feature-libraries/indexing/index.js.map +1 -0
  439. package/lib/feature-libraries/indexing/types.d.ts +32 -0
  440. package/lib/feature-libraries/indexing/types.d.ts.map +1 -0
  441. package/lib/{events/interop.js → feature-libraries/indexing/types.js} +1 -1
  442. package/lib/feature-libraries/indexing/types.js.map +1 -0
  443. package/lib/feature-libraries/modular-schema/discrepancies.d.ts +84 -24
  444. package/lib/feature-libraries/modular-schema/discrepancies.d.ts.map +1 -1
  445. package/lib/feature-libraries/modular-schema/discrepancies.js +25 -28
  446. package/lib/feature-libraries/modular-schema/discrepancies.js.map +1 -1
  447. package/lib/feature-libraries/modular-schema/index.d.ts +1 -1
  448. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  449. package/lib/feature-libraries/modular-schema/index.js +1 -1
  450. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  451. package/lib/feature-libraries/modular-schema/isNeverTree.d.ts +0 -1
  452. package/lib/feature-libraries/modular-schema/isNeverTree.d.ts.map +1 -1
  453. package/lib/feature-libraries/modular-schema/isNeverTree.js +0 -1
  454. package/lib/feature-libraries/modular-schema/isNeverTree.js.map +1 -1
  455. package/lib/feature-libraries/object-forest/objectForest.d.ts +5 -2
  456. package/lib/feature-libraries/object-forest/objectForest.d.ts.map +1 -1
  457. package/lib/feature-libraries/object-forest/objectForest.js +15 -5
  458. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  459. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts +6 -6
  460. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV1.d.ts.map +1 -1
  461. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts +7 -7
  462. package/lib/feature-libraries/optional-field/optionalFieldChangeFormatV2.d.ts.map +1 -1
  463. package/lib/feature-libraries/schema-edits/schemaChangeFormat.d.ts +12 -12
  464. package/lib/feature-libraries/sequence-field/formatV1.d.ts +99 -99
  465. package/lib/feature-libraries/sequence-field/formatV1.d.ts.map +1 -1
  466. package/lib/feature-libraries/sequence-field/formatV2.d.ts +76 -76
  467. package/lib/feature-libraries/sequence-field/formatV2.d.ts.map +1 -1
  468. package/lib/feature-libraries/sequence-field/formatV3.d.ts +54 -54
  469. package/lib/feature-libraries/sequence-field/invert.d.ts.map +1 -1
  470. package/lib/feature-libraries/sequence-field/invert.js +4 -4
  471. package/lib/feature-libraries/sequence-field/invert.js.map +1 -1
  472. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js +4 -3
  473. package/lib/feature-libraries/sequence-field/sequenceFieldToDelta.js.map +1 -1
  474. package/lib/feature-libraries/sequence-field/types.d.ts +0 -1
  475. package/lib/feature-libraries/sequence-field/types.d.ts.map +1 -1
  476. package/lib/feature-libraries/sequence-field/types.js.map +1 -1
  477. package/lib/index.d.ts +6 -7
  478. package/lib/index.d.ts.map +1 -1
  479. package/lib/index.js +3 -4
  480. package/lib/index.js.map +1 -1
  481. package/lib/packageVersion.d.ts +1 -1
  482. package/lib/packageVersion.js +1 -1
  483. package/lib/packageVersion.js.map +1 -1
  484. package/lib/shared-tree/index.d.ts +2 -2
  485. package/lib/shared-tree/index.d.ts.map +1 -1
  486. package/lib/shared-tree/index.js +1 -1
  487. package/lib/shared-tree/index.js.map +1 -1
  488. package/lib/shared-tree/schematizeTree.d.ts +1 -1
  489. package/lib/shared-tree/schematizeTree.d.ts.map +1 -1
  490. package/lib/shared-tree/schematizeTree.js +7 -7
  491. package/lib/shared-tree/schematizeTree.js.map +1 -1
  492. package/lib/shared-tree/schematizingTreeView.d.ts +7 -1
  493. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  494. package/lib/shared-tree/schematizingTreeView.js +12 -16
  495. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  496. package/lib/shared-tree/sharedTree.d.ts +27 -6
  497. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  498. package/lib/shared-tree/sharedTree.js +135 -10
  499. package/lib/shared-tree/sharedTree.js.map +1 -1
  500. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  501. package/lib/shared-tree/sharedTreeChangeFamily.js +5 -5
  502. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  503. package/lib/shared-tree/treeCheckout.d.ts +59 -72
  504. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  505. package/lib/shared-tree/treeCheckout.js +233 -177
  506. package/lib/shared-tree/treeCheckout.js.map +1 -1
  507. package/lib/shared-tree-core/branch.d.ts +29 -107
  508. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  509. package/lib/shared-tree-core/branch.js +50 -193
  510. package/lib/shared-tree-core/branch.js.map +1 -1
  511. package/lib/shared-tree-core/branchCommitEnricher.d.ts +24 -32
  512. package/lib/shared-tree-core/branchCommitEnricher.d.ts.map +1 -1
  513. package/lib/shared-tree-core/branchCommitEnricher.js +71 -54
  514. package/lib/shared-tree-core/branchCommitEnricher.js.map +1 -1
  515. package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  516. package/lib/shared-tree-core/defaultResubmitMachine.js +3 -2
  517. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  518. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  519. package/lib/shared-tree-core/editManager.js +4 -4
  520. package/lib/shared-tree-core/editManager.js.map +1 -1
  521. package/lib/shared-tree-core/index.d.ts +3 -3
  522. package/lib/shared-tree-core/index.d.ts.map +1 -1
  523. package/lib/shared-tree-core/index.js +2 -2
  524. package/lib/shared-tree-core/index.js.map +1 -1
  525. package/lib/shared-tree-core/sharedTreeCore.d.ts +3 -10
  526. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  527. package/lib/shared-tree-core/sharedTreeCore.js +15 -68
  528. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  529. package/lib/shared-tree-core/transaction.d.ts +146 -0
  530. package/lib/shared-tree-core/transaction.d.ts.map +1 -0
  531. package/lib/shared-tree-core/transaction.js +206 -0
  532. package/lib/shared-tree-core/transaction.js.map +1 -0
  533. package/lib/shared-tree-core/transactionEnricher.d.ts +8 -13
  534. package/lib/shared-tree-core/transactionEnricher.d.ts.map +1 -1
  535. package/lib/shared-tree-core/transactionEnricher.js +41 -21
  536. package/lib/shared-tree-core/transactionEnricher.js.map +1 -1
  537. package/lib/simple-tree/api/conciseTree.d.ts.map +1 -1
  538. package/lib/simple-tree/api/conciseTree.js +2 -2
  539. package/lib/simple-tree/api/conciseTree.js.map +1 -1
  540. package/lib/simple-tree/api/create.d.ts.map +1 -1
  541. package/lib/simple-tree/api/create.js +5 -1
  542. package/lib/simple-tree/api/create.js.map +1 -1
  543. package/lib/simple-tree/api/customTree.d.ts +14 -2
  544. package/lib/simple-tree/api/customTree.d.ts.map +1 -1
  545. package/lib/simple-tree/api/customTree.js +50 -2
  546. package/lib/simple-tree/api/customTree.js.map +1 -1
  547. package/lib/simple-tree/api/identifierIndex.d.ts +21 -0
  548. package/lib/simple-tree/api/identifierIndex.d.ts.map +1 -0
  549. package/lib/simple-tree/api/identifierIndex.js +41 -0
  550. package/lib/simple-tree/api/identifierIndex.js.map +1 -0
  551. package/lib/simple-tree/api/index.d.ts +4 -2
  552. package/lib/simple-tree/api/index.d.ts.map +1 -1
  553. package/lib/simple-tree/api/index.js +4 -1
  554. package/lib/simple-tree/api/index.js.map +1 -1
  555. package/lib/simple-tree/api/schemaFactory.d.ts +48 -0
  556. package/lib/simple-tree/api/schemaFactory.d.ts.map +1 -1
  557. package/lib/simple-tree/api/schemaFactory.js +4 -1
  558. package/lib/simple-tree/api/schemaFactory.js.map +1 -1
  559. package/lib/simple-tree/api/simpleSchema.d.ts +3 -1
  560. package/lib/simple-tree/api/simpleSchema.d.ts.map +1 -1
  561. package/lib/simple-tree/api/simpleSchema.js.map +1 -1
  562. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js +11 -9
  563. package/lib/simple-tree/api/simpleSchemaToJsonSchema.js.map +1 -1
  564. package/lib/simple-tree/api/simpleTreeIndex.d.ts +65 -0
  565. package/lib/simple-tree/api/simpleTreeIndex.d.ts.map +1 -0
  566. package/lib/simple-tree/api/simpleTreeIndex.js +89 -0
  567. package/lib/simple-tree/api/simpleTreeIndex.js.map +1 -0
  568. package/lib/simple-tree/api/storedSchema.d.ts +4 -4
  569. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  570. package/lib/simple-tree/api/storedSchema.js +5 -18
  571. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  572. package/lib/simple-tree/api/tree.d.ts +5 -5
  573. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  574. package/lib/simple-tree/api/tree.js.map +1 -1
  575. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  576. package/lib/simple-tree/api/verboseTree.js +2 -2
  577. package/lib/simple-tree/api/verboseTree.js.map +1 -1
  578. package/lib/simple-tree/api/view.d.ts +14 -9
  579. package/lib/simple-tree/api/view.d.ts.map +1 -1
  580. package/lib/simple-tree/api/view.js +131 -42
  581. package/lib/simple-tree/api/view.js.map +1 -1
  582. package/lib/simple-tree/core/index.d.ts +1 -1
  583. package/lib/simple-tree/core/index.d.ts.map +1 -1
  584. package/lib/simple-tree/core/index.js +1 -1
  585. package/lib/simple-tree/core/index.js.map +1 -1
  586. package/lib/simple-tree/core/treeNodeKernel.d.ts +6 -2
  587. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  588. package/lib/simple-tree/core/treeNodeKernel.js +31 -1
  589. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  590. package/lib/simple-tree/core/unhydratedFlexTree.d.ts +1 -1
  591. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  592. package/lib/simple-tree/core/unhydratedFlexTree.js +1 -1
  593. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  594. package/lib/simple-tree/index.d.ts +2 -2
  595. package/lib/simple-tree/index.d.ts.map +1 -1
  596. package/lib/simple-tree/index.js +2 -2
  597. package/lib/simple-tree/index.js.map +1 -1
  598. package/lib/simple-tree/leafNodeSchema.d.ts +0 -15
  599. package/lib/simple-tree/leafNodeSchema.d.ts.map +1 -1
  600. package/lib/simple-tree/leafNodeSchema.js +0 -15
  601. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  602. package/lib/simple-tree/objectNode.d.ts +15 -5
  603. package/lib/simple-tree/objectNode.d.ts.map +1 -1
  604. package/lib/simple-tree/objectNode.js +16 -1
  605. package/lib/simple-tree/objectNode.js.map +1 -1
  606. package/lib/simple-tree/objectNodeTypes.d.ts +4 -0
  607. package/lib/simple-tree/objectNodeTypes.d.ts.map +1 -1
  608. package/lib/simple-tree/objectNodeTypes.js.map +1 -1
  609. package/lib/simple-tree/schemaTypes.d.ts +4 -2
  610. package/lib/simple-tree/schemaTypes.d.ts.map +1 -1
  611. package/lib/simple-tree/schemaTypes.js.map +1 -1
  612. package/lib/simple-tree/toMapTree.js +5 -5
  613. package/lib/simple-tree/toMapTree.js.map +1 -1
  614. package/lib/simple-tree/toStoredSchema.d.ts.map +1 -1
  615. package/lib/simple-tree/toStoredSchema.js +19 -14
  616. package/lib/simple-tree/toStoredSchema.js.map +1 -1
  617. package/lib/util/brand.d.ts +0 -2
  618. package/lib/util/brand.d.ts.map +1 -1
  619. package/lib/util/brand.js +0 -1
  620. package/lib/util/brand.js.map +1 -1
  621. package/lib/util/index.d.ts +1 -2
  622. package/lib/util/index.d.ts.map +1 -1
  623. package/lib/util/index.js +1 -2
  624. package/lib/util/index.js.map +1 -1
  625. package/lib/util/typeCheck.d.ts +6 -3
  626. package/lib/util/typeCheck.d.ts.map +1 -1
  627. package/lib/util/typeCheck.js.map +1 -1
  628. package/lib/util/typeCheckTests.d.ts +14 -2
  629. package/lib/util/typeCheckTests.d.ts.map +1 -1
  630. package/lib/util/typeCheckTests.js.map +1 -1
  631. package/lib/util/utils.d.ts +42 -0
  632. package/lib/util/utils.d.ts.map +1 -1
  633. package/lib/util/utils.js +30 -0
  634. package/lib/util/utils.js.map +1 -1
  635. package/package.json +23 -23
  636. package/src/core/forest/forest.ts +12 -1
  637. package/src/core/index.ts +13 -2
  638. package/src/core/rebase/utils.ts +28 -29
  639. package/src/core/revertible.ts +35 -1
  640. package/src/core/schema-stored/format.ts +0 -3
  641. package/src/core/schema-stored/schema.ts +13 -10
  642. package/src/core/schema-stored/storedSchemaRepository.ts +2 -1
  643. package/src/core/schema-view/index.ts +0 -1
  644. package/src/core/schema-view/view.ts +0 -11
  645. package/src/core/tree/anchorSet.ts +2 -1
  646. package/src/{feature-libraries/chunked-forest → core/tree}/chunk.ts +4 -4
  647. package/src/core/tree/detachedFieldIndexCodec.ts +4 -3
  648. package/src/core/tree/index.ts +9 -0
  649. package/src/core/tree/treeTextFormat.ts +0 -5
  650. package/src/core/tree/types.ts +0 -5
  651. package/src/core/tree/visitorUtils.ts +56 -1
  652. package/src/feature-libraries/chunked-forest/basicChunk.ts +4 -2
  653. package/src/feature-libraries/chunked-forest/chunkTree.ts +2 -1
  654. package/src/feature-libraries/chunked-forest/chunkedForest.ts +35 -8
  655. package/src/feature-libraries/chunked-forest/codec/chunkCodecUtilities.ts +1 -2
  656. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +6 -2
  657. package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +1 -1
  658. package/src/feature-libraries/chunked-forest/emptyChunk.ts +4 -2
  659. package/src/feature-libraries/chunked-forest/index.ts +1 -1
  660. package/src/feature-libraries/chunked-forest/sequenceChunk.ts +1 -1
  661. package/src/feature-libraries/chunked-forest/uniformChunk.ts +7 -4
  662. package/src/feature-libraries/default-schema/defaultSchema.ts +1 -0
  663. package/src/feature-libraries/default-schema/schemaChecker.ts +4 -1
  664. package/src/feature-libraries/flex-tree/context.ts +1 -1
  665. package/src/feature-libraries/index.ts +22 -0
  666. package/src/feature-libraries/indexing/anchorTreeIndex.ts +482 -0
  667. package/src/feature-libraries/indexing/index.ts +11 -0
  668. package/src/feature-libraries/indexing/types.ts +37 -0
  669. package/src/feature-libraries/modular-schema/discrepancies.ts +76 -38
  670. package/src/feature-libraries/modular-schema/index.ts +13 -0
  671. package/src/feature-libraries/modular-schema/isNeverTree.ts +0 -2
  672. package/src/feature-libraries/object-forest/objectForest.ts +22 -4
  673. package/src/feature-libraries/sequence-field/invert.ts +4 -4
  674. package/src/feature-libraries/sequence-field/sequenceFieldToDelta.ts +4 -4
  675. package/src/feature-libraries/sequence-field/types.ts +0 -1
  676. package/src/index.ts +17 -35
  677. package/src/packageVersion.ts +1 -1
  678. package/src/shared-tree/index.ts +1 -2
  679. package/src/shared-tree/schematizeTree.ts +6 -10
  680. package/src/shared-tree/schematizingTreeView.ts +18 -28
  681. package/src/shared-tree/sharedTree.ts +216 -30
  682. package/src/shared-tree/sharedTreeChangeFamily.ts +5 -4
  683. package/src/shared-tree/treeCheckout.ts +341 -299
  684. package/src/shared-tree-core/branch.ts +80 -300
  685. package/src/shared-tree-core/branchCommitEnricher.ts +66 -62
  686. package/src/shared-tree-core/defaultResubmitMachine.ts +3 -2
  687. package/src/shared-tree-core/editManager.ts +4 -9
  688. package/src/shared-tree-core/index.ts +11 -3
  689. package/src/shared-tree-core/sharedTreeCore.ts +23 -79
  690. package/src/shared-tree-core/transaction.ts +310 -0
  691. package/src/shared-tree-core/transactionEnricher.ts +30 -24
  692. package/src/simple-tree/api/conciseTree.ts +2 -2
  693. package/src/simple-tree/api/create.ts +5 -1
  694. package/src/simple-tree/api/customTree.ts +69 -1
  695. package/src/simple-tree/api/identifierIndex.ts +64 -0
  696. package/src/simple-tree/api/index.ts +17 -2
  697. package/src/simple-tree/api/schemaFactory.ts +62 -1
  698. package/src/simple-tree/api/simpleSchema.ts +3 -1
  699. package/src/simple-tree/api/simpleSchemaToJsonSchema.ts +17 -18
  700. package/src/simple-tree/api/simpleTreeIndex.ts +233 -0
  701. package/src/simple-tree/api/storedSchema.ts +7 -22
  702. package/src/simple-tree/api/tree.ts +14 -5
  703. package/src/simple-tree/api/treeNodeApi.ts +1 -1
  704. package/src/simple-tree/api/verboseTree.ts +2 -2
  705. package/src/simple-tree/api/view.ts +197 -51
  706. package/src/simple-tree/core/index.ts +1 -0
  707. package/src/simple-tree/core/treeNodeKernel.ts +37 -2
  708. package/src/simple-tree/core/unhydratedFlexTree.ts +2 -1
  709. package/src/simple-tree/index.ts +10 -0
  710. package/src/simple-tree/leafNodeSchema.ts +0 -19
  711. package/src/simple-tree/objectNode.ts +45 -14
  712. package/src/simple-tree/objectNodeTypes.ts +5 -0
  713. package/src/simple-tree/schemaTypes.ts +7 -2
  714. package/src/simple-tree/toMapTree.ts +5 -5
  715. package/src/simple-tree/toStoredSchema.ts +25 -19
  716. package/src/util/brand.ts +0 -2
  717. package/src/util/index.ts +4 -1
  718. package/src/util/typeCheck.ts +6 -3
  719. package/src/util/typeCheckTests.ts +11 -1
  720. package/src/util/utils.ts +64 -0
  721. package/dist/events/emitter.d.ts +0 -139
  722. package/dist/events/emitter.d.ts.map +0 -1
  723. package/dist/events/emitter.js +0 -165
  724. package/dist/events/emitter.js.map +0 -1
  725. package/dist/events/index.d.ts +0 -7
  726. package/dist/events/index.d.ts.map +0 -1
  727. package/dist/events/index.js +0 -11
  728. package/dist/events/index.js.map +0 -1
  729. package/dist/events/interop.d.ts +0 -30
  730. package/dist/events/interop.d.ts.map +0 -1
  731. package/dist/events/interop.js.map +0 -1
  732. package/dist/events/listeners.d.ts +0 -76
  733. package/dist/events/listeners.d.ts.map +0 -1
  734. package/dist/events/listeners.js +0 -7
  735. package/dist/events/listeners.js.map +0 -1
  736. package/dist/feature-libraries/chunked-forest/chunk.d.ts.map +0 -1
  737. package/dist/feature-libraries/chunked-forest/chunk.js.map +0 -1
  738. package/dist/shared-tree-core/transactionStack.d.ts +0 -29
  739. package/dist/shared-tree-core/transactionStack.d.ts.map +0 -1
  740. package/dist/shared-tree-core/transactionStack.js +0 -41
  741. package/dist/shared-tree-core/transactionStack.js.map +0 -1
  742. package/dist/util/transactionResult.d.ts +0 -19
  743. package/dist/util/transactionResult.d.ts.map +0 -1
  744. package/dist/util/transactionResult.js +0 -23
  745. package/dist/util/transactionResult.js.map +0 -1
  746. package/lib/events/emitter.d.ts +0 -139
  747. package/lib/events/emitter.d.ts.map +0 -1
  748. package/lib/events/emitter.js +0 -160
  749. package/lib/events/emitter.js.map +0 -1
  750. package/lib/events/index.d.ts +0 -7
  751. package/lib/events/index.d.ts.map +0 -1
  752. package/lib/events/index.js.map +0 -1
  753. package/lib/events/interop.d.ts +0 -30
  754. package/lib/events/interop.d.ts.map +0 -1
  755. package/lib/events/interop.js.map +0 -1
  756. package/lib/events/listeners.d.ts +0 -76
  757. package/lib/events/listeners.d.ts.map +0 -1
  758. package/lib/events/listeners.js +0 -6
  759. package/lib/events/listeners.js.map +0 -1
  760. package/lib/feature-libraries/chunked-forest/chunk.d.ts.map +0 -1
  761. package/lib/feature-libraries/chunked-forest/chunk.js.map +0 -1
  762. package/lib/shared-tree-core/transactionStack.d.ts +0 -29
  763. package/lib/shared-tree-core/transactionStack.d.ts.map +0 -1
  764. package/lib/shared-tree-core/transactionStack.js +0 -37
  765. package/lib/shared-tree-core/transactionStack.js.map +0 -1
  766. package/lib/util/transactionResult.d.ts +0 -19
  767. package/lib/util/transactionResult.d.ts.map +0 -1
  768. package/lib/util/transactionResult.js +0 -20
  769. package/lib/util/transactionResult.js.map +0 -1
  770. package/src/events/README.md +0 -3
  771. package/src/events/emitter.ts +0 -256
  772. package/src/events/index.ts +0 -19
  773. package/src/events/interop.ts +0 -38
  774. package/src/events/listeners.ts +0 -80
  775. package/src/shared-tree-core/transactionStack.ts +0 -45
  776. package/src/util/transactionResult.ts +0 -19
@@ -1 +1 @@
1
- {"version":3,"file":"chunkTree.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkTree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAIN,oBAAoB,EACpB,sBAAsB,EAQtB,eAAe,EACf,YAAY,EACZ,WAAW,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAkB,WAAW,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,M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8B,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,YAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tCursorLocationType,\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\tLeafNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype StoredSchemaCollection,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchema,\n\ttype TreeStoredSchemaSubscription,\n\ttype TreeValue,\n\ttype Value,\n\tmapCursorFields,\n\tMultiplicity,\n\tValueSchema,\n} from \"../../core/index.js\";\nimport { fail, getOrCreate } from \"../../util/index.js\";\nimport type { FullSchemaPolicy } from \"../modular-schema/index.js\";\n\nimport { BasicChunk } from \"./basicChunk.js\";\nimport { type TreeChunk, tryGetChunk } from \"./chunk.js\";\nimport { SequenceChunk } from \"./sequenceChunk.js\";\nimport { type FieldShape, TreeShape, UniformChunk } from \"./uniformChunk.js\";\nimport { isStableNodeKey } from \"../node-key/index.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\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/**\n * Creates a ChunkPolicy which responds to schema changes.\n */\nexport function makeTreeChunker(\n\tschema: TreeStoredSchemaSubscription,\n\tpolicy: FullSchemaPolicy,\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\ttryShapeFromSchema,\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 `tryShapeFromSchema` 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: FullSchemaPolicy,\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 tryShapeFromSchema: (\n\t\t\tschema: TreeStoredSchema,\n\t\t\tpolicy: FullSchemaPolicy,\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.tryShapeFromSchema,\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.tryShapeFromSchema(this.schema, this.policy, 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\tassert(started, 0x57c /* field to chunk should have at least one node */);\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\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 function shapesFromSchema(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n): Map<TreeNodeSchemaIdentifier, ShapeInfo> {\n\tconst shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo> = new Map();\n\tfor (const identifier of schema.nodeSchema.keys()) {\n\t\ttryShapeFromSchema(schema, policy, identifier, shapes);\n\t}\n\treturn shapes;\n}\n\n/**\n * If `schema` has only one shape, return it.\n *\n * Note that this does not tolerate optional or sequence fields, nor does it optimize for patterns of specific values.\n */\nexport function tryShapeFromSchema(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\ttype: TreeNodeSchemaIdentifier,\n\tshapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>,\n): ShapeInfo {\n\treturn getOrCreate(shapes, type, () => {\n\t\tconst treeSchema = schema.nodeSchema.get(type) ?? fail(\"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(type, true, [], true)\n\t\t\t\t: new TreeShape(type, true, [], false);\n\t\t}\n\t\tif (treeSchema instanceof ObjectNodeStoredSchema) {\n\t\t\tconst fieldsArray: FieldShape[] = [];\n\t\t\tfor (const [key, field] of treeSchema.objectNodeFields) {\n\t\t\t\tconst fieldShape = tryShapeFromFieldSchema(schema, policy, field, key, shapes);\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(type, false, fieldsArray);\n\t\t}\n\t\treturn polymorphic;\n\t});\n}\n\n/**\n * If `schema` has only one shape, return it.\n *\n * Note that this does not tolerate optional or sequence fields, nor does it optimize for patterns of specific values.\n */\nexport function tryShapeFromFieldSchema(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\ttype: TreeFieldStoredSchema,\n\tkey: FieldKey,\n\tshapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>,\n): FieldShape | undefined {\n\tconst kind = policy.fieldKinds.get(type.kind) ?? fail(\"missing FieldKind\");\n\tif (kind.multiplicity !== Multiplicity.Single) {\n\t\treturn undefined;\n\t}\n\tif (type.types?.size !== 1) {\n\t\treturn undefined;\n\t}\n\tconst childType = [...type.types][0] ?? oob();\n\tconst childShape = tryShapeFromSchema(schema, policy, childType, shapes);\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 * @param cursor - cursor in nodes mode\n * @param policy - heuristics to impact chunking\n * @param length - how many nodes to process (at the top level)\n * @param skipLastNavigation - if true, leaves the cursor at the last node instead of moving off of it.\n */\nexport function chunkRange(\n\tcursor: ITreeCursorSynchronous,\n\tchunkCompressor: ChunkCompressor,\n\tlength: number,\n\tskipLastNavigation: boolean,\n): TreeChunk[] {\n\tassert(cursor.mode === CursorLocationType.Nodes, 0x57e /* should be in nodes */);\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 * @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 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\tisStableNodeKey(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,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAIN,oBAAoB,EACpB,sBAAsB,EAQtB,eAAe,EACf,YAAY,EACZ,WAAW,EAEX,WAAW,GACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAGxD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAmB,SAAS,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAUvD;;GAEG;AACH,MAAM,UAAU,eAAe,CAC9B,MAAoC,EACpC,MAAwB;IAExB,OAAO,IAAI,OAAO,CACjB,MAAM,EACN,MAAM,EACN,kBAAkB,CAAC,4BAA4B,EAC/C,kBAAkB,CAAC,4BAA4B,EAC/C,kBAAkB,CAAC,qBAAqB,EACxC,kBAAkB,CAClB,CAAC;AACH,CAAC;AAaD;;;;;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AY,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,YAAY,CAAC,KAAK,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,YAAY,CAAC,CAAC;AACzF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tCursorLocationType,\n\ttype FieldKey,\n\ttype ITreeCursorSynchronous,\n\tLeafNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype StoredSchemaCollection,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeStoredSchema,\n\ttype TreeStoredSchemaSubscription,\n\ttype TreeValue,\n\ttype Value,\n\tmapCursorFields,\n\tMultiplicity,\n\tValueSchema,\n\ttype TreeChunk,\n\ttryGetChunk,\n} from \"../../core/index.js\";\nimport { fail, getOrCreate } from \"../../util/index.js\";\nimport type { FullSchemaPolicy } from \"../modular-schema/index.js\";\n\nimport { BasicChunk } from \"./basicChunk.js\";\nimport { SequenceChunk } from \"./sequenceChunk.js\";\nimport { type FieldShape, TreeShape, UniformChunk } from \"./uniformChunk.js\";\nimport { isStableNodeKey } from \"../node-key/index.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\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/**\n * Creates a ChunkPolicy which responds to schema changes.\n */\nexport function makeTreeChunker(\n\tschema: TreeStoredSchemaSubscription,\n\tpolicy: FullSchemaPolicy,\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\ttryShapeFromSchema,\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 `tryShapeFromSchema` 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: FullSchemaPolicy,\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 tryShapeFromSchema: (\n\t\t\tschema: TreeStoredSchema,\n\t\t\tpolicy: FullSchemaPolicy,\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.tryShapeFromSchema,\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.tryShapeFromSchema(this.schema, this.policy, 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\tassert(started, 0x57c /* field to chunk should have at least one node */);\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\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 function shapesFromSchema(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n): Map<TreeNodeSchemaIdentifier, ShapeInfo> {\n\tconst shapes: Map<TreeNodeSchemaIdentifier, ShapeInfo> = new Map();\n\tfor (const identifier of schema.nodeSchema.keys()) {\n\t\ttryShapeFromSchema(schema, policy, identifier, shapes);\n\t}\n\treturn shapes;\n}\n\n/**\n * If `schema` has only one shape, return it.\n *\n * Note that this does not tolerate optional or sequence fields, nor does it optimize for patterns of specific values.\n */\nexport function tryShapeFromSchema(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\ttype: TreeNodeSchemaIdentifier,\n\tshapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>,\n): ShapeInfo {\n\treturn getOrCreate(shapes, type, () => {\n\t\tconst treeSchema = schema.nodeSchema.get(type) ?? fail(\"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(type, true, [], true)\n\t\t\t\t: new TreeShape(type, true, [], false);\n\t\t}\n\t\tif (treeSchema instanceof ObjectNodeStoredSchema) {\n\t\t\tconst fieldsArray: FieldShape[] = [];\n\t\t\tfor (const [key, field] of treeSchema.objectNodeFields) {\n\t\t\t\tconst fieldShape = tryShapeFromFieldSchema(schema, policy, field, key, shapes);\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(type, false, fieldsArray);\n\t\t}\n\t\treturn polymorphic;\n\t});\n}\n\n/**\n * If `schema` has only one shape, return it.\n *\n * Note that this does not tolerate optional or sequence fields, nor does it optimize for patterns of specific values.\n */\nexport function tryShapeFromFieldSchema(\n\tschema: StoredSchemaCollection,\n\tpolicy: FullSchemaPolicy,\n\ttype: TreeFieldStoredSchema,\n\tkey: FieldKey,\n\tshapes: Map<TreeNodeSchemaIdentifier, ShapeInfo>,\n): FieldShape | undefined {\n\tconst kind = policy.fieldKinds.get(type.kind) ?? fail(\"missing FieldKind\");\n\tif (kind.multiplicity !== Multiplicity.Single) {\n\t\treturn undefined;\n\t}\n\tif (type.types?.size !== 1) {\n\t\treturn undefined;\n\t}\n\tconst childType = [...type.types][0] ?? oob();\n\tconst childShape = tryShapeFromSchema(schema, policy, childType, shapes);\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 * @param cursor - cursor in nodes mode\n * @param policy - heuristics to impact chunking\n * @param length - how many nodes to process (at the top level)\n * @param skipLastNavigation - if true, leaves the cursor at the last node instead of moving off of it.\n */\nexport function chunkRange(\n\tcursor: ITreeCursorSynchronous,\n\tchunkCompressor: ChunkCompressor,\n\tlength: number,\n\tskipLastNavigation: boolean,\n): TreeChunk[] {\n\tassert(cursor.mode === CursorLocationType.Nodes, 0x57e /* should be in nodes */);\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 * @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 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\tisStableNodeKey(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"]}
@@ -2,10 +2,9 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import { type Anchor, AnchorSet, type DeltaVisitor, type DetachedField, type FieldAnchor, type FieldKey, type ForestEvents, type IEditableForest, type ITreeCursorSynchronous, type ITreeSubscriptionCursor, ITreeSubscriptionCursorState, TreeNavigationResult, type TreeStoredSchemaSubscription, type UpPath } from "../../core/index.js";
6
- import { type Listenable } from "../../events/index.js";
5
+ import type { Listenable } from "@fluidframework/core-interfaces";
6
+ import { type Anchor, AnchorSet, type AnnouncedVisitor, type DeltaVisitor, type DetachedField, type FieldAnchor, type FieldKey, type ForestEvents, type IEditableForest, type ITreeCursorSynchronous, type ITreeSubscriptionCursor, ITreeSubscriptionCursorState, TreeNavigationResult, type TreeStoredSchemaSubscription, type UpPath, type ChunkedCursor, type TreeChunk } from "../../core/index.js";
7
7
  import { BasicChunk, BasicChunkCursor, type SiblingsOrKey } from "./basicChunk.js";
8
- import type { ChunkedCursor, TreeChunk } from "./chunk.js";
9
8
  import { type IChunker } from "./chunkTree.js";
10
9
  import type { IIdCompressor } from "@fluidframework/id-compressor";
11
10
  /**
@@ -21,6 +20,7 @@ export declare class ChunkedForest implements IEditableForest {
21
20
  readonly anchors: AnchorSet;
22
21
  readonly idCompressor?: IIdCompressor | undefined;
23
22
  private activeVisitor?;
23
+ private readonly deltaVisitors;
24
24
  readonly events: Listenable<ForestEvents>;
25
25
  /**
26
26
  * @param roots - dummy node above the root under which detached fields are stored. All content of the forest is reachable from this.
@@ -32,6 +32,8 @@ export declare class ChunkedForest implements IEditableForest {
32
32
  get isEmpty(): boolean;
33
33
  clone(schema: TreeStoredSchemaSubscription, anchors: AnchorSet): ChunkedForest;
34
34
  forgetAnchor(anchor: Anchor): void;
35
+ registerAnnouncedVisitor(visitor: () => AnnouncedVisitor): void;
36
+ deregisterAnnouncedVisitor(visitor: () => AnnouncedVisitor): void;
35
37
  acquireVisitor(): DeltaVisitor;
36
38
  private nextDetachedFieldIdentifier;
37
39
  newDetachedField(): DetachedField;
@@ -1 +1 @@
1
- {"version":3,"file":"chunkedForest.d.ts","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkedForest.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EACN,KAAK,MAAM,EACX,SAAS,EACT,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,KAAK,uBAAuB,EAC5B,4BAA4B,EAI5B,oBAAoB,EACpB,KAAK,4BAA4B,EACjC,KAAK,MAAM,EAKX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGvE,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,iBAAiB,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAC3D,OAAO,EAAE,KAAK,QAAQ,EAA6B,MAAM,gBAAgB,CAAC;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAWnE;;;;GAIG;AACH,qBAAa,aAAc,YAAW,eAAe;;IAa5C,KAAK,EAAE,UAAU;aACR,MAAM,EAAE,4BAA4B;aACpC,OAAO,EAAE,QAAQ;aACjB,OAAO,EAAE,SAAS;aAClB,YAAY,CAAC;IAhB9B,OAAO,CAAC,aAAa,CAAC,CAAe;IAGrC,SAAgB,MAAM,EAAE,UAAU,CAAC,YAAY,CAAC,CAAgB;IAEhE;;;;;OAKG;gBAEK,KAAK,EAA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,MAAM,EACxB,YAAY,EAAE,aAAa,GAAG,SAAS;IAgBjC,qBAAqB,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IAajC,IAAI,IAAI,MAAM;IAmBvB,gBAAgB,IAAI,WAAW;IAO/B,IAAI,IAAI,IAAI;IAIZ,WAAW,IAAI,MAAM;IAIrB,KAAK,IAAI,IAAI;CAIpB;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CACjC,OAAO,EAAE,QAAQ,EACjB,OAAO,CAAC,EAAE,SAAS,EACnB,YAAY,CAAC,EAAE,aAAa,GAC1B,aAAa,CAEf"}
@@ -9,9 +9,9 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  };
10
10
  var _ChunkedForest_events;
11
11
  import { assert, oob } from "@fluidframework/core-utils/internal";
12
- import { AnchorSet, ITreeSubscriptionCursorState, aboveRootPlaceholder, detachedFieldAsKey, mapCursorField, rootFieldKey, } from "../../core/index.js";
13
- import { createEmitter } from "../../events/index.js";
14
- import { assertValidRange, brand, fail, getOrAddEmptyToMap } from "../../util/index.js";
12
+ import { createEmitter } from "@fluid-internal/client-utils";
13
+ import { AnchorSet, ITreeSubscriptionCursorState, aboveRootPlaceholder, combineVisitors, detachedFieldAsKey, mapCursorField, rootFieldKey, } from "../../core/index.js";
14
+ import { assertValidRange, brand, fail, getLast, getOrAddEmptyToMap, hasSome, } from "../../util/index.js";
15
15
  import { BasicChunk, BasicChunkCursor } from "./basicChunk.js";
16
16
  import { basicChunkTree, chunkTree } from "./chunkTree.js";
17
17
  function makeRoot() {
@@ -35,6 +35,7 @@ export class ChunkedForest {
35
35
  this.chunker = chunker;
36
36
  this.anchors = anchors;
37
37
  this.idCompressor = idCompressor;
38
+ this.deltaVisitors = new Set();
38
39
  _ChunkedForest_events.set(this, createEmitter());
39
40
  this.events = __classPrivateFieldGet(this, _ChunkedForest_events, "f");
40
41
  this.nextDetachedFieldIdentifier = 0;
@@ -49,20 +50,26 @@ export class ChunkedForest {
49
50
  forgetAnchor(anchor) {
50
51
  this.anchors.forget(anchor);
51
52
  }
53
+ registerAnnouncedVisitor(visitor) {
54
+ this.deltaVisitors.add(visitor);
55
+ }
56
+ deregisterAnnouncedVisitor(visitor) {
57
+ this.deltaVisitors.delete(visitor);
58
+ }
52
59
  acquireVisitor() {
53
60
  assert(this.activeVisitor === undefined, 0x76a /* Must release existing visitor before acquiring another */);
54
61
  if (this.roots.isShared()) {
55
62
  this.roots = this.roots.clone();
56
63
  }
57
- const visitor = {
64
+ const forestVisitor = {
58
65
  forest: this,
59
66
  // Current location in the tree, as a non-shared BasicChunk (TODO: support in-place modification of other chunk formats when possible).
60
67
  // Start above root detached sequences.
61
68
  mutableChunkStack: [],
62
69
  mutableChunk: this.roots,
63
70
  getParent() {
64
- assert(this.mutableChunkStack.length > 0, 0x532 /* invalid access to root's parent */);
65
- return this.mutableChunkStack[this.mutableChunkStack.length - 1] ?? oob();
71
+ assert(hasSome(this.mutableChunkStack), 0x532 /* invalid access to root's parent */);
72
+ return getLast(this.mutableChunkStack);
66
73
  },
67
74
  free() {
68
75
  this.mutableChunk = undefined;
@@ -203,8 +210,11 @@ export class ChunkedForest {
203
210
  this.mutableChunk = top.mutableChunk;
204
211
  },
205
212
  };
206
- this.activeVisitor = visitor;
207
- return visitor;
213
+ const announcedVisitors = [];
214
+ this.deltaVisitors.forEach((getVisitor) => announcedVisitors.push(getVisitor()));
215
+ const combinedVisitor = combineVisitors([forestVisitor, ...announcedVisitors], announcedVisitors);
216
+ this.activeVisitor = combinedVisitor;
217
+ return combinedVisitor;
208
218
  }
209
219
  newDetachedField() {
210
220
  const field = brand(String(this.nextDetachedFieldIdentifier));
@@ -1 +1 @@
1
- {"version":3,"file":"chunkedForest.js","sourceRoot":"","sources":["../../../src/feature-libraries/chunked-forest/chunkedForest.ts"],"names":[],"mappings":"AAAA;;;GAGG;;;;;;;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,O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AI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,MAAM,MAAM,GACX,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IACjD,CAAC;IAEM,IAAI;QACV,IAAI,CAAC,KAAK,GAAG,4BAA4B,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,4BAA4B,CAAC,OAAO,CAAC;QAClD,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\ttype Anchor,\n\tAnchorSet,\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 ProtoNodes,\n\ttype Range,\n\tTreeNavigationResult,\n\ttype TreeStoredSchemaSubscription,\n\ttype UpPath,\n\taboveRootPlaceholder,\n\tdetachedFieldAsKey,\n\tmapCursorField,\n\trootFieldKey,\n} from \"../../core/index.js\";\nimport { createEmitter, type Listenable } from \"../../events/index.js\";\nimport { assertValidRange, brand, fail, getOrAddEmptyToMap } from \"../../util/index.js\";\n\nimport { BasicChunk, BasicChunkCursor, type SiblingsOrKey } from \"./basicChunk.js\";\nimport type { ChunkedCursor, TreeChunk } from \"./chunk.js\";\nimport { type IChunker, basicChunkTree, chunkTree } from \"./chunkTree.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\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\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 forgetAnchor(anchor: Anchor): void {\n\t\tthis.anchors.forget(anchor);\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 visitor = {\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(this.mutableChunkStack.length > 0, 0x532 /* invalid access to root's parent */);\n\t\t\t\treturn this.mutableChunkStack[this.mutableChunkStack.length - 1] ?? oob();\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: ProtoNodes, 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): 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\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\treplace(\n\t\t\t\tnewContentSource: FieldKey,\n\t\t\t\trange: Range,\n\t\t\t\toldContentDestination: FieldKey,\n\t\t\t): void {\n\t\t\t\tassert(\n\t\t\t\t\tnewContentSource !== oldContentDestination,\n\t\t\t\t\t0x7b0 /* Replace detached source field and detached destination field must be different */,\n\t\t\t\t);\n\t\t\t\t// TODO: optimize this to: perform in-place replace in uniform chunks when possible.\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\t\t\t\tthis.detachEdit(range, oldContentDestination);\n\t\t\t\tthis.attachEdit(newContentSource, range.end - range.start, range.start);\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(\"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(\"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(\"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\t\tthis.activeVisitor = visitor;\n\t\treturn visitor;\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 * @returns 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,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAElE,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D,OAAO,EAEN,SAAS,EAUT,4BAA4B,EAO5B,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,YAAY,GAGZ,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACN,gBAAgB,EAChB,KAAK,EACL,IAAI,EACJ,OAAO,EACP,kBAAkB,EAClB,OAAO,GACP,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAsB,MAAM,iBAAiB,CAAC;AACnF,OAAO,EAAiB,cAAc,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAG1E,SAAS,QAAQ;IAChB,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IACH,CAAC;IAEM,gBAAgB;QACtB,MAAM,IAAI,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACjC,MAAM,MAAM,GACX,IAAI,CAAC,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChF,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,CAAC,KAAK,EAAE,CAAC;IACjD,CAAC;IAEM,IAAI;QACV,IAAI,CAAC,KAAK,GAAG,4BAA4B,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,4BAA4B,CAAC,OAAO,CAAC;QAClD,IAAI,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAC1C,CAAC;CACD;AAED;;GAEG;AACH,MAAM,UAAU,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","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\nimport type { Listenable } from \"@fluidframework/core-interfaces\";\nimport { createEmitter } from \"@fluid-internal/client-utils\";\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 ProtoNodes,\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} from \"../../core/index.js\";\nimport {\n\tassertValidRange,\n\tbrand,\n\tfail,\n\tgetLast,\n\tgetOrAddEmptyToMap,\n\thasSome,\n} from \"../../util/index.js\";\n\nimport { BasicChunk, BasicChunkCursor, type SiblingsOrKey } from \"./basicChunk.js\";\nimport { type IChunker, basicChunkTree, chunkTree } from \"./chunkTree.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\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 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: ProtoNodes, 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): 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\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\treplace(\n\t\t\t\tnewContentSource: FieldKey,\n\t\t\t\trange: Range,\n\t\t\t\toldContentDestination: FieldKey,\n\t\t\t): void {\n\t\t\t\tassert(\n\t\t\t\t\tnewContentSource !== oldContentDestination,\n\t\t\t\t\t0x7b0 /* Replace detached source field and detached destination field must be different */,\n\t\t\t\t);\n\t\t\t\t// TODO: optimize this to: perform in-place replace in uniform chunks when possible.\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\t\t\t\tthis.detachEdit(range, oldContentDestination);\n\t\t\t\tthis.attachEdit(newContentSource, range.end - range.start, range.start);\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(\"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(\"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(\"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(\n\t\t\t[forestVisitor, ...announcedVisitors],\n\t\t\tannouncedVisitors,\n\t\t);\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 * @returns 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"]}
@@ -2,9 +2,8 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { TreeValue } from "../../../core/index.js";
5
+ import type { TreeValue, TreeChunk } from "../../../core/index.js";
6
6
  import { type FluidSerializableReadOnly } from "../../valueUtilities.js";
7
- import type { TreeChunk } from "../chunk.js";
8
7
  /**
9
8
  * Utilities related to chunk encoding and decoding that do not depend on specific chunk types or formats.
10
9
  */
@@ -1 +1 @@
1
- {"version":3,"file":"chunkCodecUtilities.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkCodecUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAExD,OAAO,EAAE,KAAK,yBAAyB,EAAsB,MAAM,yBAAyB,CAAC;AAC7F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAE7C;;GAEG;AAEH;;;;GAIG;AACH,qBAAa,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA6B;IAC7C,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,SAAI,GAAG,IAAI;IAKjC;;;;;OAKG;IACI,UAAU,CAAC,MAAM,GAAE,aAAa,CAAC,CAAC,CAAuB,GAAG,kBAAkB,CAAC,CAAC,CAAC;CAiBxF;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;AAE/E;;;GAGG;AACH,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACpC;;OAEG;IACH,QAAQ,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;IAC9C;;;;OAIG;IACH,QAAQ,CAAC,YAAY,EAAE,SAAS,CAAC,EAAE,CAAC;CACpC;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAWrF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,CAGlE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,yBAAyB,EAAE,CAAC;IACpD;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;CACf;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,YAAY,GAAG,yBAAyB,CAI1E;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,MAAM,CAI7D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAI/D;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,GAAG,SAAS,CAI/D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAInE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;CAC3E"}
1
+ {"version":3,"file":"chunkCodecUtilities.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkCodecUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEnE,OAAO,EAAE,KAAK,yBAAyB,EAAsB,MAAM,yBAAyB,CAAC;AAE7F;;GAEG;AAEH;;;;GAIG;AACH,qBAAa,OAAO,CAAC,CAAC;IACrB,OAAO,CAAC,QAAQ,CAAC,MAAM,CA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,EAAE,YAAY,GAAG,SAAS,CAI/D;AAED;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,YAAY,GAAG,YAAY,CAInE;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;OAKG;IACH,MAAM,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS,CAAC;CAC3E"}
@@ -1 +1 @@
1
- {"version":3,"file":"chunkCodecUtilities.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkCodecUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAkC,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAG7F;;GAEG;AAEH;;;;GAIG;AACH,MAAM,OAAO,OAAO;IAApB;QACkB,WAAM,GAAmB,IAAI,GAAG,EAAE,CAAC;IA6BrD,CAAC;IA5BO,GAAG,CAAC,CAAI,EAAE,KAAK,GAAG,CAAC;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QACpC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,GAAG,KAAK,CAAC,CAAC;IACjC,CAAC;IAED;;;;;OAKG;IACI,UAAU,CAAC,SAA2B,GAAY,EAAE,CAAC,IAAI;QAC/D,MAAM,IAAI,GAAQ,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1C,qGAAqG;QACrG,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC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n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport type { TreeValue } from \"../../../core/index.js\";\nimport { assertValidIndex } from \"../../../util/index.js\";\nimport { type FluidSerializableReadOnly, assertAllowedValue } from \"../../valueUtilities.js\";\nimport type { TreeChunk } from \"../chunk.js\";\n\n/**\n * Utilities related to chunk encoding and decoding that do not depend on specific chunk types or formats.\n */\n\n/**\n * Counts usages of some `T`, then generates tables for replacing those `T` values with small numbers.\n *\n * Can be used to deduplicate objects when encoding via {@link https://go-compression.github.io/algorithms/dictionary/ | Dictionary Coding}.\n */\nexport class Counter<T> {\n\tprivate readonly counts: Map<T, number> = new Map();\n\tpublic add(t: T, count = 1): void {\n\t\tconst old = this.counts.get(t) ?? 0;\n\t\tthis.counts.set(t, old + count);\n\t}\n\n\t/**\n\t * Generate a table which can be used to deduplicate the items added via `add`.\n\t * Table is sorted from most used to least used so that more commonly added items will get smaller indexes.\n\t *\n\t * @param filter - determines which items should be included in the table.\n\t */\n\tpublic buildTable(filter: CounterFilter<T> = (): boolean => true): DeduplicationTable<T> {\n\t\tconst data: T[] = [...this.counts.keys()];\n\t\t// Sort in descending order by count, giving priority (smaller indexes) to more commonly used values.\n\t\tdata.sort((a, b) => (this.counts.get(b) ?? 0) - (this.counts.get(a) ?? 0));\n\t\t// Since the index needed is the output index not the input one, data.filter doesn't quite work here.\n\t\tconst filtered: T[] = [];\n\t\tfor (const t of data) {\n\t\t\tconst include = filter(t, filtered.length, this.counts.get(t) ?? 0);\n\t\t\tif (include) {\n\t\t\t\tfiltered.push(t);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tindexToValue: filtered,\n\t\t\tvalueToIndex: new Map(filtered.map((t, index) => [t, index])),\n\t\t};\n\t}\n}\n\n/**\n * Returns true iff a given item `t` (of which there are `count` usages) is worth substituting with the number `value`.\n */\nexport type CounterFilter<T> = (t: T, value: number, count: number) => boolean;\n\n/**\n * Table for dictionary compression.\n * See {@link Counter}.\n */\nexport interface DeduplicationTable<T> {\n\t/**\n\t * Lookup table derived from indexToValue,\n\t */\n\treadonly valueToIndex: ReadonlyMap<T, number>;\n\t/**\n\t * Deduplication table: lookup values by their index.\n\t *\n\t * This is the portion of the table that should be included in persisted data.\n\t */\n\treadonly indexToValue: readonly T[];\n}\n\n/**\n * Filter for use with Counter.buildTable that minimizes the size of the produced JSON.\n *\n * @remarks\n * This minimizes the number of UTF-16 code units in the produced JSON.\n * This is not ideal: minimizing UTF-8 bytes would be better.\n * For ascii text these are the same, and in worst cases they correlate pretty well (accurate to within a small constant factor).\n * This is thus good enough for a heuristic.\n *\n * Also the use of this filter doesn't take into account the length cost of keeping a value in the table possibly\n * making some of the entries at higher indexes in the table get a larger number.\n * For example, if keeping an entry at index 9 saves one character this will keep it,\n * even if that means the next entry (at index 10) loses more than one character due to 10 being two digits instead of the one digit it would have been at index 9.\n * This means that this filter is not guaranteed to be optimal, but it should always be quite close.\n */\nexport function jsonMinimizingFilter(s: string, value: number, count: number): boolean {\n\t// The most practical way to compute how long s will be with quoting and escaping\n\t// is to actually quote and escape it with JSON.stringify:\n\tconst quotedAndEscaped = JSON.stringify(s);\n\t// Account for count instances of value, and one instance of a `,s` which would go in the table.\n\tconst lengthUsingTable = String(value).length * count + quotedAndEscaped.length + 1;\n\t// Account for count instances of s.\n\tconst lengthWithoutTable = quotedAndEscaped.length * count;\n\t// Break ties to not use the table to avoid needing a lookup,\n\t// and save table entries for other uses.\n\treturn lengthUsingTable < lengthWithoutTable;\n}\n\n/**\n * Read from an array, but error if index is not valid.\n */\nexport function getChecked<T>(data: readonly T[], index: number): T {\n\tassertValidIndex(index, data);\n\treturn data[index] ?? oob();\n}\n\n/**\n * A readable stream.\n */\nexport interface StreamCursor {\n\t/**\n\t * The data to read.\n\t */\n\treadonly data: readonly FluidSerializableReadOnly[];\n\t/**\n\t * Location in the data.\n\t */\n\toffset: number;\n}\n\n/**\n * Read one item from the stream, advancing the stream offset.\n */\nexport function readStream(stream: StreamCursor): FluidSerializableReadOnly {\n\tconst content = getChecked(stream.data, stream.offset);\n\tstream.offset++;\n\treturn content;\n}\n\n/**\n * Read one number from the stream, advancing the stream offset.\n */\nexport function readStreamNumber(stream: StreamCursor): number {\n\tconst content = readStream(stream);\n\tassert(typeof content === \"number\", 0x730 /* expected number in stream */);\n\treturn content;\n}\n\n/**\n * Read one boolean from the stream, advancing the stream offset.\n */\nexport function readStreamBoolean(stream: StreamCursor): boolean {\n\tconst content = readStream(stream);\n\tassert(typeof content === \"boolean\", 0x731 /* expected boolean in stream */);\n\treturn content;\n}\n\n/**\n * Read one TreeValue from the stream, advancing the stream offset.\n */\nexport function readStreamValue(stream: StreamCursor): TreeValue {\n\tconst content = readStream(stream);\n\tassertAllowedValue(content);\n\treturn content;\n}\n\n/**\n * Read one nested array from the stream, advancing the stream offset.\n *\n * @returns the nested array as a stream.\n */\nexport function readStreamStream(stream: StreamCursor): StreamCursor {\n\tconst content = readStream(stream);\n\tassert(Array.isArray(content), 0x732 /* expected Array in stream */);\n\treturn { data: content, offset: 0 };\n}\n\n/**\n * Decodes a chunk within a FieldBatch.\n */\nexport interface ChunkDecoder {\n\t/**\n\t * Read from stream, updating the offset.\n\t *\n\t * @returns a TreeChunk made from the data from `stream`.\n\t * This chunk is allowed to reference/take ownership of content it reads from the stream.\n\t */\n\tdecode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk;\n}\n"]}
1
+ {"version":3,"file":"chunkCodecUtilities.js","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkCodecUtilities.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAkC,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7F;;GAEG;AAE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,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,OAAO,OAAO,KAAK,SAAS,EAAE,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC7E,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,MAAoB;IACnD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,kBAAkB,CAAC,OAAO,CAAC,CAAC;IAC5B,OAAO,OAAO,CAAC;AAChB,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAoB;IACpD,MAAM,OAAO,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IACnC,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC,8BAA8B,CAAC,CAAC;IACrE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;AACrC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, oob } from \"@fluidframework/core-utils/internal\";\n\nimport type { TreeValue, TreeChunk } from \"../../../core/index.js\";\nimport { assertValidIndex } from \"../../../util/index.js\";\nimport { type FluidSerializableReadOnly, assertAllowedValue } from \"../../valueUtilities.js\";\n\n/**\n * Utilities related to chunk encoding and decoding that do not depend on specific chunk types or formats.\n */\n\n/**\n * Counts usages of some `T`, then generates tables for replacing those `T` values with small numbers.\n *\n * Can be used to deduplicate objects when encoding via {@link https://go-compression.github.io/algorithms/dictionary/ | Dictionary Coding}.\n */\nexport class Counter<T> {\n\tprivate readonly counts: Map<T, number> = new Map();\n\tpublic add(t: T, count = 1): void {\n\t\tconst old = this.counts.get(t) ?? 0;\n\t\tthis.counts.set(t, old + count);\n\t}\n\n\t/**\n\t * Generate a table which can be used to deduplicate the items added via `add`.\n\t * Table is sorted from most used to least used so that more commonly added items will get smaller indexes.\n\t *\n\t * @param filter - determines which items should be included in the table.\n\t */\n\tpublic buildTable(filter: CounterFilter<T> = (): boolean => true): DeduplicationTable<T> {\n\t\tconst data: T[] = [...this.counts.keys()];\n\t\t// Sort in descending order by count, giving priority (smaller indexes) to more commonly used values.\n\t\tdata.sort((a, b) => (this.counts.get(b) ?? 0) - (this.counts.get(a) ?? 0));\n\t\t// Since the index needed is the output index not the input one, data.filter doesn't quite work here.\n\t\tconst filtered: T[] = [];\n\t\tfor (const t of data) {\n\t\t\tconst include = filter(t, filtered.length, this.counts.get(t) ?? 0);\n\t\t\tif (include) {\n\t\t\t\tfiltered.push(t);\n\t\t\t}\n\t\t}\n\t\treturn {\n\t\t\tindexToValue: filtered,\n\t\t\tvalueToIndex: new Map(filtered.map((t, index) => [t, index])),\n\t\t};\n\t}\n}\n\n/**\n * Returns true iff a given item `t` (of which there are `count` usages) is worth substituting with the number `value`.\n */\nexport type CounterFilter<T> = (t: T, value: number, count: number) => boolean;\n\n/**\n * Table for dictionary compression.\n * See {@link Counter}.\n */\nexport interface DeduplicationTable<T> {\n\t/**\n\t * Lookup table derived from indexToValue,\n\t */\n\treadonly valueToIndex: ReadonlyMap<T, number>;\n\t/**\n\t * Deduplication table: lookup values by their index.\n\t *\n\t * This is the portion of the table that should be included in persisted data.\n\t */\n\treadonly indexToValue: readonly T[];\n}\n\n/**\n * Filter for use with Counter.buildTable that minimizes the size of the produced JSON.\n *\n * @remarks\n * This minimizes the number of UTF-16 code units in the produced JSON.\n * This is not ideal: minimizing UTF-8 bytes would be better.\n * For ascii text these are the same, and in worst cases they correlate pretty well (accurate to within a small constant factor).\n * This is thus good enough for a heuristic.\n *\n * Also the use of this filter doesn't take into account the length cost of keeping a value in the table possibly\n * making some of the entries at higher indexes in the table get a larger number.\n * For example, if keeping an entry at index 9 saves one character this will keep it,\n * even if that means the next entry (at index 10) loses more than one character due to 10 being two digits instead of the one digit it would have been at index 9.\n * This means that this filter is not guaranteed to be optimal, but it should always be quite close.\n */\nexport function jsonMinimizingFilter(s: string, value: number, count: number): boolean {\n\t// The most practical way to compute how long s will be with quoting and escaping\n\t// is to actually quote and escape it with JSON.stringify:\n\tconst quotedAndEscaped = JSON.stringify(s);\n\t// Account for count instances of value, and one instance of a `,s` which would go in the table.\n\tconst lengthUsingTable = String(value).length * count + quotedAndEscaped.length + 1;\n\t// Account for count instances of s.\n\tconst lengthWithoutTable = quotedAndEscaped.length * count;\n\t// Break ties to not use the table to avoid needing a lookup,\n\t// and save table entries for other uses.\n\treturn lengthUsingTable < lengthWithoutTable;\n}\n\n/**\n * Read from an array, but error if index is not valid.\n */\nexport function getChecked<T>(data: readonly T[], index: number): T {\n\tassertValidIndex(index, data);\n\treturn data[index] ?? oob();\n}\n\n/**\n * A readable stream.\n */\nexport interface StreamCursor {\n\t/**\n\t * The data to read.\n\t */\n\treadonly data: readonly FluidSerializableReadOnly[];\n\t/**\n\t * Location in the data.\n\t */\n\toffset: number;\n}\n\n/**\n * Read one item from the stream, advancing the stream offset.\n */\nexport function readStream(stream: StreamCursor): FluidSerializableReadOnly {\n\tconst content = getChecked(stream.data, stream.offset);\n\tstream.offset++;\n\treturn content;\n}\n\n/**\n * Read one number from the stream, advancing the stream offset.\n */\nexport function readStreamNumber(stream: StreamCursor): number {\n\tconst content = readStream(stream);\n\tassert(typeof content === \"number\", 0x730 /* expected number in stream */);\n\treturn content;\n}\n\n/**\n * Read one boolean from the stream, advancing the stream offset.\n */\nexport function readStreamBoolean(stream: StreamCursor): boolean {\n\tconst content = readStream(stream);\n\tassert(typeof content === \"boolean\", 0x731 /* expected boolean in stream */);\n\treturn content;\n}\n\n/**\n * Read one TreeValue from the stream, advancing the stream offset.\n */\nexport function readStreamValue(stream: StreamCursor): TreeValue {\n\tconst content = readStream(stream);\n\tassertAllowedValue(content);\n\treturn content;\n}\n\n/**\n * Read one nested array from the stream, advancing the stream offset.\n *\n * @returns the nested array as a stream.\n */\nexport function readStreamStream(stream: StreamCursor): StreamCursor {\n\tconst content = readStream(stream);\n\tassert(Array.isArray(content), 0x732 /* expected Array in stream */);\n\treturn { data: content, offset: 0 };\n}\n\n/**\n * Decodes a chunk within a FieldBatch.\n */\nexport interface ChunkDecoder {\n\t/**\n\t * Read from stream, updating the offset.\n\t *\n\t * @returns a TreeChunk made from the data from `stream`.\n\t * This chunk is allowed to reference/take ownership of content it reads from the stream.\n\t */\n\tdecode(decoders: readonly ChunkDecoder[], stream: StreamCursor): TreeChunk;\n}\n"]}
@@ -2,8 +2,7 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { Value } from "../../../core/index.js";
6
- import type { TreeChunk } from "../chunk.js";
5
+ import type { Value, TreeChunk } from "../../../core/index.js";
7
6
  import { type ChunkDecoder, type StreamCursor } from "./chunkCodecUtilities.js";
8
7
  import { DecoderContext } from "./chunkDecodingGeneric.js";
9
8
  import { type EncodedChunkShape, type EncodedFieldBatch, type EncodedInlineArray, type EncodedNestedArray, type EncodedTreeShape, type EncodedValueShape } from "./format.js";
@@ -1 +1 @@
1
- {"version":3,"file":"chunkDecoding.d.ts","sourceRoot":"","sources":["../../../../src/feature-libraries/chunked-forest/codec/chunkDecoding.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAsC,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAGxF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,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,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAEtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,aA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AI,CAAC,CAA2B;IACjD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAA+B;gBAE3C,KAAK,EAAE,gBAAgB,EACvB,KAAK,EAAE,cAAc,CAAC,iBAAiB,CAAC;IAWnD,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;AAKH,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,EACtB,KAAK,kBAAkB,EACvB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EAEtB,MAAM,aAAa,CAAC;AACrB,OAAO,KAAK,EACX,aAAa,EAEb,SAAS,EACT,MAAM,+BAA+B,CAAC;AAEvC,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,aAAa,CAAC;IAAC,YAAY,EAAE,SAAS,CAAA;CAAE,GACzE,SAAS,EAAE,CAOb;AAqBD;;GAEG;AACH,wBAAgB,SAAS,CACxB,MAAM,EAAE,YAAY,EACpB,KAAK,EAAE,iBAAiB,EACxB,iBAAiB,EAAE,iBAAiB,GAClC,KAAK,CAgCP;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,SA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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,GAAG,EAAE,CAAC;YAC1D,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC3C,MAAM,GAAG,GAAa,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC9D,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;YAChD,CAAC;QACF,CAAC;QAED,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;CACD","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\";\n\nimport { DiscriminatedUnionDispatcher } from \"../../../codec/index.js\";\nimport type { FieldKey, TreeNodeSchemaIdentifier, Value } from \"../../../core/index.js\";\nimport { assertValidIndex } from \"../../../util/index.js\";\nimport { BasicChunk } from \"../basicChunk.js\";\nimport type { TreeChunk } from \"../chunk.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 EncodedInlineArray,\n\ttype EncodedNestedArray,\n\ttype EncodedTreeShape,\n\ttype EncodedValueShape,\n\tSpecialField,\n} from \"./format.js\";\nimport type {\n\tIIdCompressor,\n\tOpSpaceCompressedId,\n\tSessionId,\n} from \"@fluidframework/id-compressor\";\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): TreeChunk[] {\n\treturn genericDecode(\n\t\tdecoderLibrary,\n\t\tnew DecoderContext(chunk.identifiers, chunk.shapes, idDecodingContext),\n\t\tchunk,\n\t\tanyDecoder,\n\t);\n}\n\nconst decoderLibrary = new DiscriminatedUnionDispatcher<\n\tEncodedChunkShape,\n\t[cache: DecoderContext<EncodedChunkShape>],\n\tChunkDecoder\n>({\n\ta(shape: EncodedNestedArray, cache): ChunkDecoder {\n\t\treturn new NestedArrayDecoder(shape);\n\t},\n\tb(shape: EncodedInlineArray, cache): ChunkDecoder {\n\t\treturn new InlineArrayDecoder(shape);\n\t},\n\tc(shape: EncodedTreeShape, cache): ChunkDecoder {\n\t\treturn new TreeDecoder(shape, cache);\n\t},\n\td(shape: EncodedAnyShape): ChunkDecoder {\n\t\treturn anyDecoder;\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 EncodedNestedArray}s.\n */\nexport class NestedArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedNestedArray) {}\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 EncodedInlineArray}s.\n */\nexport class InlineArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedInlineArray) {}\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 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 `cache`) {@link EncodedChunkShape}.\n */\nfunction fieldDecoder(\n\tcache: DecoderContext<EncodedChunkShape>,\n\tkey: FieldKey,\n\tshape: number,\n): BasicFieldDecoder {\n\tassertValidIndex(shape, cache.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 EncodedTreeShape}s.\n */\nexport class TreeDecoder implements ChunkDecoder {\n\tprivate readonly type?: TreeNodeSchemaIdentifier;\n\tprivate readonly fieldDecoders: readonly BasicFieldDecoder[];\n\tpublic constructor(\n\t\tprivate readonly shape: EncodedTreeShape,\n\t\tprivate readonly cache: DecoderContext<EncodedChunkShape>,\n\t) {\n\t\tthis.type = shape.type === undefined ? undefined : cache.identifier(shape.type);\n\n\t\tconst fieldDecoders: BasicFieldDecoder[] = [];\n\t\tfor (const [fieldKey, fieldShape] of shape.fields ?? []) {\n\t\t\tconst key: FieldKey = cache.identifier(fieldKey);\n\t\t\tfieldDecoders.push(fieldDecoder(cache, 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.cache);\n\t\t// TODO: Consider typechecking against stored schema in here somewhere.\n\n\t\tconst value = readValue(stream, this.shape.value, this.cache.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 field of this.fieldDecoders) {\n\t\t\tconst [key, content] = field(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.cache);\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,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AAEnF,OAAO,EAAE,4BAA4B,EAAE,MAAM,yB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C,CAAC;YAC/C,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,GAAG,EAAE,CAAC;YAC1D,MAAM,KAAK,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;YACvC,OAAO,KAAK,CAAC,MAAM,KAAK,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;gBAC3C,MAAM,GAAG,GAAa,oBAAoB,CAAC,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;gBAC9D,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC,CAAC;YAChD,CAAC;QACF,CAAC;QAED,OAAO,IAAI,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;CACD","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\";\n\nimport { DiscriminatedUnionDispatcher } from \"../../../codec/index.js\";\nimport type {\n\tFieldKey,\n\tTreeNodeSchemaIdentifier,\n\tValue,\n\tTreeChunk,\n} from \"../../../core/index.js\";\nimport { assertValidIndex } 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 EncodedInlineArray,\n\ttype EncodedNestedArray,\n\ttype EncodedTreeShape,\n\ttype EncodedValueShape,\n\tSpecialField,\n} from \"./format.js\";\nimport type {\n\tIIdCompressor,\n\tOpSpaceCompressedId,\n\tSessionId,\n} from \"@fluidframework/id-compressor\";\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): TreeChunk[] {\n\treturn genericDecode(\n\t\tdecoderLibrary,\n\t\tnew DecoderContext(chunk.identifiers, chunk.shapes, idDecodingContext),\n\t\tchunk,\n\t\tanyDecoder,\n\t);\n}\n\nconst decoderLibrary = new DiscriminatedUnionDispatcher<\n\tEncodedChunkShape,\n\t[cache: DecoderContext<EncodedChunkShape>],\n\tChunkDecoder\n>({\n\ta(shape: EncodedNestedArray, cache): ChunkDecoder {\n\t\treturn new NestedArrayDecoder(shape);\n\t},\n\tb(shape: EncodedInlineArray, cache): ChunkDecoder {\n\t\treturn new InlineArrayDecoder(shape);\n\t},\n\tc(shape: EncodedTreeShape, cache): ChunkDecoder {\n\t\treturn new TreeDecoder(shape, cache);\n\t},\n\td(shape: EncodedAnyShape): ChunkDecoder {\n\t\treturn anyDecoder;\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 EncodedNestedArray}s.\n */\nexport class NestedArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedNestedArray) {}\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 EncodedInlineArray}s.\n */\nexport class InlineArrayDecoder implements ChunkDecoder {\n\tpublic constructor(private readonly shape: EncodedInlineArray) {}\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 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 `cache`) {@link EncodedChunkShape}.\n */\nfunction fieldDecoder(\n\tcache: DecoderContext<EncodedChunkShape>,\n\tkey: FieldKey,\n\tshape: number,\n): BasicFieldDecoder {\n\tassertValidIndex(shape, cache.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 EncodedTreeShape}s.\n */\nexport class TreeDecoder implements ChunkDecoder {\n\tprivate readonly type?: TreeNodeSchemaIdentifier;\n\tprivate readonly fieldDecoders: readonly BasicFieldDecoder[];\n\tpublic constructor(\n\t\tprivate readonly shape: EncodedTreeShape,\n\t\tprivate readonly cache: DecoderContext<EncodedChunkShape>,\n\t) {\n\t\tthis.type = shape.type === undefined ? undefined : cache.identifier(shape.type);\n\n\t\tconst fieldDecoders: BasicFieldDecoder[] = [];\n\t\tfor (const [fieldKey, fieldShape] of shape.fields ?? []) {\n\t\t\tconst key: FieldKey = cache.identifier(fieldKey);\n\t\t\tfieldDecoders.push(fieldDecoder(cache, 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.cache);\n\t\t// TODO: Consider typechecking against stored schema in here somewhere.\n\n\t\tconst value = readValue(stream, this.shape.value, this.cache.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 field of this.fieldDecoders) {\n\t\t\tconst [key, content] = field(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.cache);\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"]}
@@ -4,7 +4,7 @@
4
4
  */
5
5
  import type { DiscriminatedUnionDispatcher } from "../../../codec/index.js";
6
6
  import type { BrandedType } from "../../../util/index.js";
7
- import type { TreeChunk } from "../chunk.js";
7
+ import type { TreeChunk } from "../../../core/index.js";
8
8
  import { type ChunkDecoder, type StreamCursor } from "./chunkCodecUtilities.js";
9
9
  import type { EncodedFieldBatchGeneric, IdentifierOrIndex } from "./formatGeneric.js";
10
10
  import type { IdDecodingContext } from "./chunkDecoding.js";