@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
@@ -47,9 +47,9 @@ const internal_1 = require("@fluidframework/core-utils/internal");
47
47
  const internal_2 = require("@fluidframework/telemetry-utils/internal");
48
48
  const index_js_1 = require("../codec/index.js");
49
49
  const index_js_2 = require("../core/index.js");
50
- const index_js_3 = require("../events/index.js");
51
- const index_js_4 = require("../feature-libraries/index.js");
52
- const index_js_5 = require("../shared-tree-core/index.js");
50
+ const index_js_3 = require("../feature-libraries/index.js");
51
+ const index_js_4 = require("../shared-tree-core/index.js");
52
+ const index_js_5 = require("../simple-tree/index.js");
53
53
  const schematizingTreeView_js_1 = require("./schematizingTreeView.js");
54
54
  const sharedTreeChangeEnricher_js_1 = require("./sharedTreeChangeEnricher.js");
55
55
  const sharedTreeChangeFamily_js_1 = require("./sharedTreeChangeFamily.js");
@@ -84,11 +84,11 @@ function getCodecVersions(formatVersion) {
84
84
  function buildConfiguredForest(type, schema, idCompressor) {
85
85
  switch (type) {
86
86
  case ForestType.Optimized:
87
- return (0, index_js_4.buildChunkedForest)((0, index_js_4.makeTreeChunker)(schema, index_js_4.defaultSchemaPolicy), undefined, idCompressor);
87
+ return (0, index_js_3.buildChunkedForest)((0, index_js_3.makeTreeChunker)(schema, index_js_3.defaultSchemaPolicy), undefined, idCompressor);
88
88
  case ForestType.Reference:
89
- return (0, index_js_4.buildForest)();
89
+ return (0, index_js_3.buildForest)();
90
90
  case ForestType.Expensive:
91
- return (0, index_js_4.buildForest)(undefined, true);
91
+ return (0, index_js_3.buildForest)(undefined, true);
92
92
  default:
93
93
  (0, internal_1.unreachableCase)(type);
94
94
  }
@@ -104,7 +104,7 @@ let SharedTree = (() => {
104
104
  let _classDescriptor;
105
105
  let _classExtraInitializers = [];
106
106
  let _classThis;
107
- let _classSuper = index_js_5.SharedTreeCore;
107
+ let _classSuper = index_js_4.SharedTreeCore;
108
108
  let _instanceExtraInitializers = [];
109
109
  let _contentSnapshot_decorators;
110
110
  var SharedTree = _classThis = class extends _classSuper {
@@ -121,23 +121,23 @@ let SharedTree = (() => {
121
121
  const forest = buildConfiguredForest(options.forest, schema, runtime.idCompressor);
122
122
  const revisionTagCodec = new index_js_2.RevisionTagCodec(runtime.idCompressor);
123
123
  const removedRoots = (0, index_js_2.makeDetachedFieldIndex)("repair", revisionTagCodec, runtime.idCompressor, options);
124
- const schemaSummarizer = new index_js_4.SchemaSummarizer(runtime, schema, options, {
124
+ const schemaSummarizer = new index_js_3.SchemaSummarizer(runtime, schema, options, {
125
125
  getCurrentSeq: () => this.deltaManager.lastSequenceNumber,
126
126
  });
127
- const fieldBatchCodec = (0, index_js_4.makeFieldBatchCodec)(options, codecVersions.fieldBatch);
127
+ const fieldBatchCodec = (0, index_js_3.makeFieldBatchCodec)(options, codecVersions.fieldBatch);
128
128
  const encoderContext = {
129
129
  schema: {
130
130
  schema,
131
- policy: index_js_4.defaultSchemaPolicy,
131
+ policy: index_js_3.defaultSchemaPolicy,
132
132
  },
133
133
  encodeType: options.treeEncodeType,
134
134
  originatorId: runtime.idCompressor.localSessionId,
135
135
  idCompressor: runtime.idCompressor,
136
136
  };
137
- const forestSummarizer = new index_js_4.ForestSummarizer(forest, revisionTagCodec, fieldBatchCodec, encoderContext, options, runtime.idCompressor);
138
- const removedRootsSummarizer = new index_js_4.DetachedFieldIndexSummarizer(removedRoots);
137
+ const forestSummarizer = new index_js_3.ForestSummarizer(forest, revisionTagCodec, fieldBatchCodec, encoderContext, options, runtime.idCompressor);
138
+ const removedRootsSummarizer = new index_js_3.DetachedFieldIndexSummarizer(removedRoots);
139
139
  const innerChangeFamily = new sharedTreeChangeFamily_js_1.SharedTreeChangeFamily(revisionTagCodec, fieldBatchCodec, options, options.treeEncodeType, runtime.idCompressor);
140
- const changeFamily = (0, index_js_4.makeMitigatedChangeFamily)(innerChangeFamily, sharedTreeChangeFamily_js_1.SharedTreeChangeFamily.emptyChange, (error) => {
140
+ const changeFamily = (0, index_js_3.makeMitigatedChangeFamily)(innerChangeFamily, sharedTreeChangeFamily_js_1.SharedTreeChangeFamily.emptyChange, (error) => {
141
141
  // TODO:6344 Add telemetry for these errors.
142
142
  // Rethrowing the error has a different effect depending on the context in which the
143
143
  // ChangeFamily was invoked:
@@ -156,9 +156,8 @@ let SharedTree = (() => {
156
156
  throw error;
157
157
  });
158
158
  const changeEnricher = new sharedTreeChangeEnricher_js_1.SharedTreeReadonlyChangeEnricher(forest, schema, removedRoots);
159
- super([schemaSummarizer, forestSummarizer, removedRootsSummarizer], changeFamily, options, codecVersions, id, runtime, attributes, telemetryContextPrefix, schema, index_js_4.defaultSchemaPolicy, new index_js_5.DefaultResubmitMachine((change) => changeFamily.rebaser.invert(change, true, this.mintRevisionTag()), changeEnricher), changeEnricher);
160
- this._events = __runInitializers(this, _instanceExtraInitializers);
161
- this._events = (0, index_js_3.createEmitter)();
159
+ super([schemaSummarizer, forestSummarizer, removedRootsSummarizer], changeFamily, options, codecVersions, id, runtime, attributes, telemetryContextPrefix, schema, index_js_3.defaultSchemaPolicy, new index_js_4.DefaultResubmitMachine((change) => changeFamily.rebaser.invert(change, true, this.mintRevisionTag()), changeEnricher), changeEnricher);
160
+ this.checkout = __runInitializers(this, _instanceExtraInitializers);
162
161
  const localBranch = this.getLocalBranch();
163
162
  this.checkout = (0, treeCheckout_js_1.createTreeCheckout)(runtime.idCompressor, this.mintRevisionTag, revisionTagCodec, {
164
163
  branch: localBranch,
@@ -166,12 +165,64 @@ let SharedTree = (() => {
166
165
  schema,
167
166
  forest,
168
167
  fieldBatchCodec,
169
- events: this._events,
170
168
  removedRoots,
171
169
  chunkCompressionStrategy: options.treeEncodeType,
172
170
  logger: this.logger,
173
171
  breaker: this.breaker,
174
172
  });
173
+ this.checkout.transaction.events.on("started", () => {
174
+ if (this.isAttached()) {
175
+ // It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.
176
+ this.commitEnricher.startTransaction();
177
+ }
178
+ });
179
+ this.checkout.transaction.events.on("aborting", () => {
180
+ if (this.isAttached()) {
181
+ // It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.
182
+ this.commitEnricher.abortTransaction();
183
+ }
184
+ });
185
+ this.checkout.transaction.events.on("committing", () => {
186
+ if (this.isAttached()) {
187
+ // It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.
188
+ this.commitEnricher.commitTransaction();
189
+ }
190
+ });
191
+ this.checkout.events.on("beforeBatch", (event) => {
192
+ if (event.type === "append" && this.isAttached()) {
193
+ if (this.checkout.transaction.isInProgress()) {
194
+ this.commitEnricher.addTransactionCommits(event.newCommits);
195
+ }
196
+ }
197
+ });
198
+ }
199
+ exportVerbose() {
200
+ const cursor = this.checkout.forest.allocateCursor("contentSnapshot");
201
+ try {
202
+ (0, index_js_2.moveToDetachedField)(this.checkout.forest, cursor);
203
+ const length = cursor.getFieldLength();
204
+ if (length === 0) {
205
+ return undefined;
206
+ }
207
+ else if (length === 1) {
208
+ cursor.enterNode(0);
209
+ return verboseFromCursor(cursor, this.storedSchema.nodeSchema);
210
+ }
211
+ else {
212
+ (0, index_js_6.fail)("Invalid document root length");
213
+ }
214
+ }
215
+ finally {
216
+ cursor.free();
217
+ }
218
+ }
219
+ exportSimpleSchema() {
220
+ return {
221
+ ...exportSimpleFieldSchemaStored(this.storedSchema.rootFieldSchema),
222
+ definitions: new Map([...this.storedSchema.nodeSchema].map(([key, schema]) => {
223
+ return [key, exportSimpleNodeSchemaStored(schema)];
224
+ })),
225
+ };
175
226
  }
176
227
  contentSnapshot() {
177
228
  const cursor = this.checkout.forest.allocateCursor("contentSnapshot");
@@ -179,7 +230,7 @@ let SharedTree = (() => {
179
230
  (0, index_js_2.moveToDetachedField)(this.checkout.forest, cursor);
180
231
  return {
181
232
  schema: this.storedSchema.clone(),
182
- tree: (0, index_js_4.jsonableTreeFromFieldCursor)(cursor),
233
+ tree: (0, index_js_3.jsonableTreeFromFieldCursor)(cursor),
183
234
  removed: this.checkout.getRemovedRoots(),
184
235
  };
185
236
  }
@@ -192,8 +243,29 @@ let SharedTree = (() => {
192
243
  }
193
244
  async loadCore(services) {
194
245
  await super.loadCore(services);
195
- this.checkout.setTipRevisionForLoadedData(this.trunkHeadRevision);
196
- this._events.emit("afterBatch");
246
+ this.checkout.load();
247
+ }
248
+ didAttach() {
249
+ if (this.checkout.transaction.isInProgress()) {
250
+ // Attaching during a transaction is not currently supported.
251
+ // At least part of of the system is known to not handle this case correctly - commit enrichment - and there may be others.
252
+ throw new internal_2.UsageError("Cannot attach while a transaction is in progress. Commit or abort the transaction before attaching.");
253
+ }
254
+ super.didAttach();
255
+ }
256
+ applyStashedOp(...args) {
257
+ (0, internal_1.assert)(!this.checkout.transaction.isInProgress(), 0x674 /* Unexpected transaction is open while applying stashed ops */);
258
+ super.applyStashedOp(...args);
259
+ }
260
+ submitCommit(commit, schemaAndPolicy, isResubmit) {
261
+ (0, internal_1.assert)(!this.checkout.transaction.isInProgress(), "Cannot submit a commit while a transaction is in progress");
262
+ if (isResubmit) {
263
+ return super.submitCommit(commit, schemaAndPolicy, isResubmit);
264
+ }
265
+ // Refrain from submitting new commits until they are validated by the checkout.
266
+ // This is not a strict requirement for correctness in our system, but in the event that there is a bug when applying commits to the checkout
267
+ // that causes a crash (e.g. in the forest), this will at least prevent this client from sending the problematic commit to any other clients.
268
+ this.checkout.onCommitValid(commit, () => super.submitCommit(commit, schemaAndPolicy, isResubmit));
197
269
  }
198
270
  };
199
271
  __setFunctionName(_classThis, "SharedTree");
@@ -261,7 +333,7 @@ var ForestType;
261
333
  exports.defaultSharedTreeOptions = {
262
334
  jsonValidator: index_js_1.noopValidator,
263
335
  forest: ForestType.Reference,
264
- treeEncodeType: index_js_4.TreeCompressionStrategy.Compressed,
336
+ treeEncodeType: index_js_3.TreeCompressionStrategy.Compressed,
265
337
  formatVersion: exports.SharedTreeFormatVersion.v3,
266
338
  };
267
339
  /**
@@ -289,4 +361,57 @@ class SharedTreeFactory {
289
361
  }
290
362
  }
291
363
  exports.SharedTreeFactory = SharedTreeFactory;
364
+ function verboseFromCursor(reader, schema) {
365
+ const fields = (0, index_js_5.customFromCursorStored)(reader, schema, verboseFromCursor);
366
+ const nodeSchema = schema.get(reader.type) ?? (0, index_js_6.fail)("missing schema for type in cursor");
367
+ if (nodeSchema instanceof index_js_2.LeafNodeStoredSchema) {
368
+ return fields;
369
+ }
370
+ return {
371
+ type: reader.type,
372
+ fields: fields,
373
+ };
374
+ }
375
+ function exportSimpleFieldSchemaStored(schema) {
376
+ let kind;
377
+ switch (schema.kind) {
378
+ case index_js_3.FieldKinds.identifier.identifier:
379
+ kind = index_js_5.FieldKind.Identifier;
380
+ break;
381
+ case index_js_3.FieldKinds.optional.identifier:
382
+ kind = index_js_5.FieldKind.Optional;
383
+ break;
384
+ case index_js_3.FieldKinds.required.identifier:
385
+ kind = index_js_5.FieldKind.Required;
386
+ break;
387
+ case index_js_3.FieldKinds.forbidden.identifier:
388
+ kind = index_js_5.FieldKind.Optional;
389
+ (0, internal_1.assert)(schema.types.size === 0, 0xa94 /* invalid forbidden field */);
390
+ break;
391
+ default:
392
+ (0, index_js_6.fail)("invalid field kind");
393
+ }
394
+ return { kind, allowedTypes: schema.types };
395
+ }
396
+ function exportSimpleNodeSchemaStored(schema) {
397
+ const arrayTypes = (0, index_js_5.tryStoredSchemaAsArray)(schema);
398
+ if (arrayTypes !== undefined) {
399
+ return { kind: index_js_5.NodeKind.Array, allowedTypes: arrayTypes };
400
+ }
401
+ if (schema instanceof index_js_2.ObjectNodeStoredSchema) {
402
+ const fields = {};
403
+ for (const [key, field] of schema.objectNodeFields) {
404
+ fields[key] = exportSimpleFieldSchemaStored(field);
405
+ }
406
+ return { kind: index_js_5.NodeKind.Object, fields };
407
+ }
408
+ if (schema instanceof index_js_2.MapNodeStoredSchema) {
409
+ (0, internal_1.assert)(schema.mapFields.kind === index_js_3.FieldKinds.optional.identifier, 0xa95 /* Invalid map schema */);
410
+ return { kind: index_js_5.NodeKind.Map, allowedTypes: schema.mapFields.types };
411
+ }
412
+ if (schema instanceof index_js_2.LeafNodeStoredSchema) {
413
+ return { kind: index_js_5.NodeKind.Leaf, leafKind: schema.leafValue };
414
+ }
415
+ (0, index_js_6.fail)("invalid schema kind");
416
+ }
292
417
  //# sourceMappingURL=sharedTree.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"sharedTree.js","sourceRoot":"","sources":["../../src/shared-tree/sharedTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAA8E;AAS9E,uEAAsE;AAEtE,gDAAsE;AACtE,+CAU0B;AAC1B,iDAK4B;AAC5B,4DAYuC;AACvC,2DAIsC;AAWtC,uEAAuE;AACvE,+EAAiF;AACjF,2EAAqE;AAGrE,uDAK2B;AAC3B,+CAAgE;AA4DhE,MAAM,oCAAoC,GAAG,IAAI,GAAG,CAAgC;IACnF;QACC,CAAC;QACD,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,kBAAkB,EAAE,CA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B;IAS7B,YAAoC,UAA6B,EAAE;QAA/B,YAAO,GAAP,OAAO,CAAwB;QARnD,SAAI,GAAW,wCAAwC,CAAC;QAExD,eAAU,GAAuB;YAChD,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,qBAAqB,EAAE,OAAO;YAC9B,cAAc,EAAE,OAAO;SACvB,CAAC;IAEoE,CAAC;IAEhE,KAAK,CAAC,IAAI,CAChB,OAA+B,EAC/B,EAAU,EACV,QAA0B,EAC1B,iBAA+C;QAE/C,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,iBAAiB,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1E,MAAM,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC1B,OAAO,IAAI,CAAC;IACb,CAAC;IAEM,MAAM,CAAC,OAA+B,EAAE,EAAU;QACxD,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACxE,IAAI,CAAC,eAAe,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC;IACb,CAAC;CACD;AA3BD,8CA2BC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { ISharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { type ICodecOptions, noopValidator } from \"../codec/index.js\";\nimport {\n\ttype IEditableForest,\n\ttype JsonableTree,\n\tRevisionTagCodec,\n\ttype TaggedChange,\n\ttype TreeStoredSchema,\n\tTreeStoredSchemaRepository,\n\ttype TreeStoredSchemaSubscription,\n\tmakeDetachedFieldIndex,\n\tmoveToDetachedField,\n} from \"../core/index.js\";\nimport {\n\ttype HasListeners,\n\ttype IEmitter,\n\ttype Listenable,\n\tcreateEmitter,\n} from \"../events/index.js\";\nimport {\n\tDetachedFieldIndexSummarizer,\n\tForestSummarizer,\n\tSchemaSummarizer,\n\tTreeCompressionStrategy,\n\tbuildChunkedForest,\n\tbuildForest,\n\tdefaultSchemaPolicy,\n\tjsonableTreeFromFieldCursor,\n\tmakeFieldBatchCodec,\n\tmakeMitigatedChangeFamily,\n\tmakeTreeChunker,\n} from \"../feature-libraries/index.js\";\nimport {\n\tDefaultResubmitMachine,\n\ttype ExplicitCoreCodecVersions,\n\tSharedTreeCore,\n} from \"../shared-tree-core/index.js\";\nimport type {\n\tITree,\n\tImplicitFieldSchema,\n\tReadSchema,\n\tTreeView,\n\tTreeViewAlpha,\n\tTreeViewConfiguration,\n\tUnsafeUnknownSchema,\n} from \"../simple-tree/index.js\";\n\nimport { SchematizingSimpleTreeView } from \"./schematizingTreeView.js\";\nimport { SharedTreeReadonlyChangeEnricher } from \"./sharedTreeChangeEnricher.js\";\nimport { SharedTreeChangeFamily } from \"./sharedTreeChangeFamily.js\";\nimport type { SharedTreeChange } from \"./sharedTreeChangeTypes.js\";\nimport type { SharedTreeEditBuilder } from \"./sharedTreeEditBuilder.js\";\nimport {\n\ttype CheckoutEvents,\n\ttype TreeCheckout,\n\ttype BranchableTree,\n\tcreateTreeCheckout,\n} from \"./treeCheckout.js\";\nimport { breakingClass, throwIfBroken } from \"../util/index.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\n/**\n * Copy of data from an {@link ISharedTree} at some point in time.\n * @remarks\n * This is unrelated to Fluids concept of \"snapshots\".\n * @internal\n */\nexport interface SharedTreeContentSnapshot {\n\t/**\n\t * The schema stored in the document.\n\t *\n\t * @remarks\n\t * Edits to the schema can mutate the schema stored of the tree which took this snapshot (but this snapshot will remain the same)\n\t * This is mainly useful for debugging cases where schematize reports an incompatible view schema.\n\t */\n\treadonly schema: TreeStoredSchema;\n\t/**\n\t * All {@link TreeStatus.InDocument} content.\n\t */\n\treadonly tree: JsonableTree[];\n\t/**\n\t * All {@link TreeStatus.Removed} content.\n\t */\n\treadonly removed: [string | number | undefined, number, JsonableTree][];\n}\n\n/**\n * {@link ITree} extended with some non-public APIs.\n * @internal\n */\nexport interface ISharedTree extends ISharedObject, ITree {\n\t/**\n\t * Provides a copy of the current content of the tree.\n\t * This can be useful for inspecting the tree when no suitable view schema is available.\n\t * This is only intended for use in testing and exceptional code paths: it is not performant.\n\t *\n\t * This does not include everything that is included in a tree summary, since information about how to merge future edits is omitted.\n\t */\n\tcontentSnapshot(): SharedTreeContentSnapshot;\n}\n\n/**\n * Has an entry for each codec which writes an explicit version into its data.\n *\n * This is used to map the single API entrypoint controlling the format {@link SharedTreeOptions.formatVersion}\n * to a list of write versions that for each codec that should be used for that format.\n *\n * Note that all explicitly versioned codecs should be using the format version from the data to read encoded data.\n *\n * TODO: Plumb these write versions into forest, schema, detached field index codec creation.\n */\ninterface ExplicitCodecVersions extends ExplicitCoreCodecVersions {\n\tforest: number;\n\tschema: number;\n\tdetachedFieldIndex: number;\n\tfieldBatch: number;\n}\n\nconst formatVersionToTopLevelCodecVersions = new Map<number, ExplicitCodecVersions>([\n\t[\n\t\t1,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 1, message: 1, fieldBatch: 1 },\n\t],\n\t[\n\t\t2,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 2, message: 2, fieldBatch: 1 },\n\t],\n\t[\n\t\t3,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 3, message: 3, fieldBatch: 1 },\n\t],\n\t[\n\t\t4,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 4, message: 4, fieldBatch: 1 },\n\t],\n]);\n\nfunction getCodecVersions(formatVersion: number): ExplicitCodecVersions {\n\tconst versions = formatVersionToTopLevelCodecVersions.get(formatVersion);\n\tassert(versions !== undefined, 0x90e /* Unknown format version */);\n\treturn versions;\n}\n\n/**\n * Build and return a forest of the requested type.\n */\nexport function buildConfiguredForest(\n\ttype: ForestType,\n\tschema: TreeStoredSchemaSubscription,\n\tidCompressor: IIdCompressor,\n): IEditableForest {\n\tswitch (type) {\n\t\tcase ForestType.Optimized:\n\t\t\treturn buildChunkedForest(\n\t\t\t\tmakeTreeChunker(schema, defaultSchemaPolicy),\n\t\t\t\tundefined,\n\t\t\t\tidCompressor,\n\t\t\t);\n\t\tcase ForestType.Reference:\n\t\t\treturn buildForest();\n\t\tcase ForestType.Expensive:\n\t\t\treturn buildForest(undefined, true);\n\t\tdefault:\n\t\t\tunreachableCase(type);\n\t}\n}\n\n/**\n * Shared tree, configured with a good set of indexes and field kinds which will maintain compatibility over time.\n *\n * TODO: detail compatibility requirements.\n */\n@breakingClass\nexport class SharedTree\n\textends SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange>\n\timplements ISharedTree\n{\n\tprivate readonly _events: Listenable<CheckoutEvents> &\n\t\tIEmitter<CheckoutEvents> &\n\t\tHasListeners<CheckoutEvents>;\n\tpublic readonly checkout: TreeCheckout;\n\tpublic get storedSchema(): TreeStoredSchemaRepository {\n\t\treturn this.checkout.storedSchema;\n\t}\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\toptionsParam: SharedTreeOptions,\n\t\ttelemetryContextPrefix: string = \"fluid_sharedTree_\",\n\t) {\n\t\tif (runtime.idCompressor === undefined) {\n\t\t\tthrow new UsageError(\"IdCompressor must be enabled to use SharedTree\");\n\t\t}\n\n\t\tconst options = { ...defaultSharedTreeOptions, ...optionsParam };\n\t\tconst codecVersions = getCodecVersions(options.formatVersion);\n\t\tconst schema = new TreeStoredSchemaRepository();\n\t\tconst forest = buildConfiguredForest(options.forest, schema, runtime.idCompressor);\n\t\tconst revisionTagCodec = new RevisionTagCodec(runtime.idCompressor);\n\t\tconst removedRoots = makeDetachedFieldIndex(\n\t\t\t\"repair\",\n\t\t\trevisionTagCodec,\n\t\t\truntime.idCompressor,\n\t\t\toptions,\n\t\t);\n\t\tconst schemaSummarizer = new SchemaSummarizer(runtime, schema, options, {\n\t\t\tgetCurrentSeq: () => this.deltaManager.lastSequenceNumber,\n\t\t});\n\t\tconst fieldBatchCodec = makeFieldBatchCodec(options, codecVersions.fieldBatch);\n\n\t\tconst encoderContext = {\n\t\t\tschema: {\n\t\t\t\tschema,\n\t\t\t\tpolicy: defaultSchemaPolicy,\n\t\t\t},\n\t\t\tencodeType: options.treeEncodeType,\n\t\t\toriginatorId: runtime.idCompressor.localSessionId,\n\t\t\tidCompressor: runtime.idCompressor,\n\t\t};\n\t\tconst forestSummarizer = new ForestSummarizer(\n\t\t\tforest,\n\t\t\trevisionTagCodec,\n\t\t\tfieldBatchCodec,\n\t\t\tencoderContext,\n\t\t\toptions,\n\t\t\truntime.idCompressor,\n\t\t);\n\t\tconst removedRootsSummarizer = new DetachedFieldIndexSummarizer(removedRoots);\n\t\tconst innerChangeFamily = new SharedTreeChangeFamily(\n\t\t\trevisionTagCodec,\n\t\t\tfieldBatchCodec,\n\t\t\toptions,\n\t\t\toptions.treeEncodeType,\n\t\t\truntime.idCompressor,\n\t\t);\n\t\tconst changeFamily = makeMitigatedChangeFamily(\n\t\t\tinnerChangeFamily,\n\t\t\tSharedTreeChangeFamily.emptyChange,\n\t\t\t(error: unknown) => {\n\t\t\t\t// TODO:6344 Add telemetry for these errors.\n\t\t\t\t// Rethrowing the error has a different effect depending on the context in which the\n\t\t\t\t// ChangeFamily was invoked:\n\t\t\t\t// - If the ChangeFamily was invoked as part of incoming op processing, rethrowing the error\n\t\t\t\t// will cause the runtime to disconnect the client, log a severe error, and not reconnect.\n\t\t\t\t// This will not cause the host application to crash because it is not on the stack at that time.\n\t\t\t\t// TODO: let the host application know that the client is now disconnected.\n\t\t\t\t// - If the ChangeFamily was invoked as part of dealing with a local change, rethrowing the\n\t\t\t\t// error will cause the host application to crash. This is not ideal, but is better than\n\t\t\t\t// letting the application either send an invalid change to the server or allowing the\n\t\t\t\t// application to continue working when its local branches contain edits that cannot be\n\t\t\t\t// reflected in its views.\n\t\t\t\t// The best course of action for a host application in such a state is to restart.\n\t\t\t\t// TODO: let the host application know about this situation and provide a way to\n\t\t\t\t// programmatically reload the SharedTree container.\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tconst changeEnricher = new SharedTreeReadonlyChangeEnricher(forest, schema, removedRoots);\n\t\tsuper(\n\t\t\t[schemaSummarizer, forestSummarizer, removedRootsSummarizer],\n\t\t\tchangeFamily,\n\t\t\toptions,\n\t\t\tcodecVersions,\n\t\t\tid,\n\t\t\truntime,\n\t\t\tattributes,\n\t\t\ttelemetryContextPrefix,\n\t\t\tschema,\n\t\t\tdefaultSchemaPolicy,\n\t\t\tnew DefaultResubmitMachine(\n\t\t\t\t(change: TaggedChange<SharedTreeChange>) =>\n\t\t\t\t\tchangeFamily.rebaser.invert(change, true, this.mintRevisionTag()),\n\t\t\t\tchangeEnricher,\n\t\t\t),\n\t\t\tchangeEnricher,\n\t\t);\n\t\tthis._events = createEmitter<CheckoutEvents>();\n\t\tconst localBranch = this.getLocalBranch();\n\t\tthis.checkout = createTreeCheckout(\n\t\t\truntime.idCompressor,\n\t\t\tthis.mintRevisionTag,\n\t\t\trevisionTagCodec,\n\t\t\t{\n\t\t\t\tbranch: localBranch,\n\t\t\t\tchangeFamily,\n\t\t\t\tschema,\n\t\t\t\tforest,\n\t\t\t\tfieldBatchCodec,\n\t\t\t\tevents: this._events,\n\t\t\t\tremovedRoots,\n\t\t\t\tchunkCompressionStrategy: options.treeEncodeType,\n\t\t\t\tlogger: this.logger,\n\t\t\t\tbreaker: this.breaker,\n\t\t\t},\n\t\t);\n\t}\n\n\t@throwIfBroken\n\tpublic contentSnapshot(): SharedTreeContentSnapshot {\n\t\tconst cursor = this.checkout.forest.allocateCursor(\"contentSnapshot\");\n\t\ttry {\n\t\t\tmoveToDetachedField(this.checkout.forest, cursor);\n\t\t\treturn {\n\t\t\t\tschema: this.storedSchema.clone(),\n\t\t\t\ttree: jsonableTreeFromFieldCursor(cursor),\n\t\t\t\tremoved: this.checkout.getRemovedRoots(),\n\t\t\t};\n\t\t} finally {\n\t\t\tcursor.free();\n\t\t}\n\t}\n\n\t// For the new TreeViewAlpha API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>>;\n\n\t// For the old TreeView API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): SchematizingSimpleTreeView<TRoot> & TreeView<TRoot>;\n\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>> {\n\t\treturn this.checkout.viewWith(config) as SchematizingSimpleTreeView<TRoot> &\n\t\t\tTreeView<ReadSchema<TRoot>>;\n\t}\n\n\tprotected override async loadCore(services: IChannelStorageService): Promise<void> {\n\t\tawait super.loadCore(services);\n\t\tthis.checkout.setTipRevisionForLoadedData(this.trunkHeadRevision);\n\t\tthis._events.emit(\"afterBatch\");\n\t}\n}\n\n/**\n * Get a {@link BranchableTree} from a {@link ITree}.\n * @remarks The branch can be used for \"version control\"-style coordination of edits on the tree.\n * @privateRemarks This function will be removed if/when the branching API becomes public,\n * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.\n * @alpha\n * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.\n */\nexport function getBranch(tree: ITree): BranchableTree;\n/**\n * Get a {@link BranchableTree} from a {@link TreeView}.\n * @remarks The branch can be used for \"version control\"-style coordination of edits on the tree.\n * Branches are currently an unstable \"alpha\" API and are subject to change in the future.\n * @privateRemarks This function will be removed if/when the branching API becomes public,\n * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.\n * @alpha\n * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.\n */\nexport function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\tview: TreeViewAlpha<T>,\n): BranchableTree;\nexport function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\ttreeOrView: ITree | TreeViewAlpha<T>,\n): BranchableTree {\n\tassert(\n\t\ttreeOrView instanceof SharedTree || treeOrView instanceof SchematizingSimpleTreeView,\n\t\t0xa48 /* Unsupported implementation */,\n\t);\n\tconst checkout: TreeCheckout = treeOrView.checkout;\n\t// This cast is safe so long as TreeCheckout supports all the operations on the branch interface.\n\treturn checkout as unknown as BranchableTree;\n}\n\n/**\n * Format versions supported by SharedTree.\n *\n * Each version documents a required minimum version of the \\@fluidframework/tree package.\n * @alpha\n */\nexport const SharedTreeFormatVersion = {\n\t/**\n\t * Requires \\@fluidframework/tree \\>= 2.0.0.\n\t *\n\t * @deprecated - FF does not currently plan on supporting this format long-term.\n\t * Do not write production documents using this format, as they may not be loadable in the future.\n\t */\n\tv1: 1,\n\n\t/**\n\t * Requires \\@fluidframework/tree \\>= 2.0.0.\n\t */\n\tv2: 2,\n\n\t/**\n\t * Requires \\@fluidframework/tree \\>= 2.0.0.\n\t */\n\tv3: 3,\n} as const;\n\n/**\n * Format versions supported by SharedTree.\n *\n * Each version documents a required minimum version of the \\@fluidframework/tree package.\n * @alpha\n * @privateRemarks\n * See packages/dds/tree/docs/main/compatibility.md for information on how to add support for a new format.\n *\n * TODO: Before this gets promoted past Alpha,\n * a separate abstraction more suited for use in the public API should be adopted rather than reusing the same types used internally.\n * Such an abstraction should probably be in the form of a Fluid-Framework wide compatibility enum.\n */\nexport type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;\n\n/**\n * Configuration options for SharedTree.\n * @alpha\n */\nexport type SharedTreeOptions = Partial<ICodecOptions> &\n\tPartial<SharedTreeFormatOptions> &\n\tForestOptions;\n\n/**\n * Configuration options for SharedTree's internal tree storage.\n * @alpha\n */\nexport interface ForestOptions {\n\t/**\n\t * The {@link ForestType} indicating which forest type should be created for the SharedTree.\n\t */\n\treadonly forest?: ForestType;\n}\n\n/**\n * Options for configuring the persisted format SharedTree uses.\n * @alpha\n */\nexport interface SharedTreeFormatOptions {\n\t/**\n\t * See {@link TreeCompressionStrategy}.\n\t * default: TreeCompressionStrategy.Compressed\n\t */\n\ttreeEncodeType: TreeCompressionStrategy;\n\t/**\n\t * The format version SharedTree should use to persist documents.\n\t *\n\t * This option has compatibility implications for applications using SharedTree.\n\t * Each version documents a required minimum version of \\@fluidframework/tree.\n\t * If this minimum version fails to be met, the SharedTree may fail to load.\n\t * To be safe, application authors should verify that they have saturated this version\n\t * of \\@fluidframework/tree in their ecosystem before changing the format version.\n\t *\n\t * This option defaults to SharedTreeFormatVersion.v2.\n\t */\n\tformatVersion: SharedTreeFormatVersion[keyof SharedTreeFormatVersion];\n}\n\n/**\n * Used to distinguish between different forest types.\n * @alpha\n */\nexport enum ForestType {\n\t/**\n\t * The \"ObjectForest\" forest type.\n\t */\n\tReference = 0,\n\t/**\n\t * The \"ChunkedForest\" forest type.\n\t */\n\tOptimized = 1,\n\t/**\n\t * The \"ObjectForest\" forest type with expensive asserts for debugging.\n\t */\n\tExpensive = 2,\n}\n\nexport const defaultSharedTreeOptions: Required<SharedTreeOptions> = {\n\tjsonValidator: noopValidator,\n\tforest: ForestType.Reference,\n\ttreeEncodeType: TreeCompressionStrategy.Compressed,\n\tformatVersion: SharedTreeFormatVersion.v3,\n};\n\n/**\n * A channel factory that creates {@link ISharedTree}s.\n */\nexport class SharedTreeFactory implements IChannelFactory<ISharedTree> {\n\tpublic readonly type: string = \"https://graph.microsoft.com/types/tree\";\n\n\tpublic readonly attributes: IChannelAttributes = {\n\t\ttype: this.type,\n\t\tsnapshotFormatVersion: \"0.0.0\",\n\t\tpackageVersion: \"0.0.0\",\n\t};\n\n\tpublic constructor(private readonly options: SharedTreeOptions = {}) {}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tchannelAttributes: Readonly<IChannelAttributes>,\n\t): Promise<SharedTree> {\n\t\tconst tree = new SharedTree(id, runtime, channelAttributes, this.options);\n\t\tawait tree.load(services);\n\t\treturn tree;\n\t}\n\n\tpublic create(runtime: IFluidDataStoreRuntime, id: string): SharedTree {\n\t\tconst tree = new SharedTree(id, runtime, this.attributes, this.options);\n\t\ttree.initializeLocal();\n\t\treturn tree;\n\t}\n}\n"]}
1
+ {"version":3,"file":"sharedTree.js","sourceRoot":"","sources":["../../src/shared-tree/sharedTree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAA8E;AAU9E,uEAAsE;AAEtE,gDAAsE;AACtE,+CAkB0B;AAE1B,4DAauC;AACvC,2DAKsC;AACtC,sDAkBiC;AAEjC,uEAAuE;AACvE,+EAAiF;AACjF,2EAAqE;AAGrE,uDAA+F;AAC/F,+CAAsE;AA+EtE,MAAM,oCAAoC,GAAG,IAAI,GAAG,CAAgC;IACnF;QACC,CAAC;QACD,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;KAC1F;IACD;QACC,CAAC;QACD,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,kBAAkB,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,EAAE;KAC1F;IACD;QACC,CAAC;QACD,EAAE,MAAM,EAAE,C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gB,EAAE,CAAC;YACpD,MAAM,CAAC,GAAG,CAAC,GAAG,6BAA6B,CAAC,KAAK,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,EAAE,IAAI,EAAE,mBAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC;IAC1C,CAAC;IACD,IAAI,MAAM,YAAY,8BAAmB,EAAE,CAAC;QAC3C,IAAA,iBAAM,EACL,MAAM,CAAC,SAAS,CAAC,IAAI,KAAK,qBAAU,CAAC,QAAQ,CAAC,UAAU,EACxD,KAAK,CAAC,wBAAwB,CAC9B,CAAC;QACF,OAAO,EAAE,IAAI,EAAE,mBAAQ,CAAC,GAAG,EAAE,YAAY,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACrE,CAAC;IACD,IAAI,MAAM,YAAY,+BAAoB,EAAE,CAAC;QAC5C,OAAO,EAAE,IAAI,EAAE,mBAAQ,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,SAAS,EAAE,CAAC;IAC5D,CAAC;IACD,IAAA,eAAI,EAAC,qBAAqB,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, unreachableCase } from \"@fluidframework/core-utils/internal\";\nimport type { IFluidHandle } from \"@fluidframework/core-interfaces/internal\";\nimport type {\n\tIChannelAttributes,\n\tIChannelFactory,\n\tIFluidDataStoreRuntime,\n\tIChannelServices,\n\tIChannelStorageService,\n} from \"@fluidframework/datastore-definitions/internal\";\nimport type { ISharedObject } from \"@fluidframework/shared-object-base/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport { type ICodecOptions, noopValidator } from \"../codec/index.js\";\nimport {\n\ttype GraphCommit,\n\ttype IEditableForest,\n\ttype ITreeCursor,\n\ttype JsonableTree,\n\tLeafNodeStoredSchema,\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\tRevisionTagCodec,\n\ttype TaggedChange,\n\ttype TreeFieldStoredSchema,\n\ttype TreeNodeSchemaIdentifier,\n\ttype TreeNodeStoredSchema,\n\ttype TreeStoredSchema,\n\tTreeStoredSchemaRepository,\n\ttype TreeStoredSchemaSubscription,\n\tmakeDetachedFieldIndex,\n\tmoveToDetachedField,\n} from \"../core/index.js\";\n\nimport {\n\tDetachedFieldIndexSummarizer,\n\tFieldKinds,\n\tForestSummarizer,\n\tSchemaSummarizer,\n\tTreeCompressionStrategy,\n\tbuildChunkedForest,\n\tbuildForest,\n\tdefaultSchemaPolicy,\n\tjsonableTreeFromFieldCursor,\n\tmakeFieldBatchCodec,\n\tmakeMitigatedChangeFamily,\n\tmakeTreeChunker,\n} from \"../feature-libraries/index.js\";\nimport {\n\ttype ClonableSchemaAndPolicy,\n\tDefaultResubmitMachine,\n\ttype ExplicitCoreCodecVersions,\n\tSharedTreeCore,\n} from \"../shared-tree-core/index.js\";\nimport {\n\ttype ITree,\n\ttype ImplicitFieldSchema,\n\tNodeKind,\n\ttype ReadSchema,\n\ttype SimpleFieldSchema,\n\ttype SimpleTreeSchema,\n\ttype TreeView,\n\ttype TreeViewAlpha,\n\ttype TreeViewConfiguration,\n\ttype UnsafeUnknownSchema,\n\ttype VerboseTree,\n\ttryStoredSchemaAsArray,\n\ttype SimpleNodeSchema,\n\tcustomFromCursorStored,\n\tFieldKind,\n\ttype CustomTreeNode,\n\ttype CustomTreeValue,\n} from \"../simple-tree/index.js\";\n\nimport { SchematizingSimpleTreeView } from \"./schematizingTreeView.js\";\nimport { SharedTreeReadonlyChangeEnricher } from \"./sharedTreeChangeEnricher.js\";\nimport { SharedTreeChangeFamily } from \"./sharedTreeChangeFamily.js\";\nimport type { SharedTreeChange } from \"./sharedTreeChangeTypes.js\";\nimport type { SharedTreeEditBuilder } from \"./sharedTreeEditBuilder.js\";\nimport { type TreeCheckout, type BranchableTree, createTreeCheckout } from \"./treeCheckout.js\";\nimport { breakingClass, fail, throwIfBroken } from \"../util/index.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\n/**\n * Copy of data from an {@link ISharedTree} at some point in time.\n * @remarks\n * This is unrelated to Fluids concept of \"snapshots\".\n */\nexport interface SharedTreeContentSnapshot {\n\t/**\n\t * The schema stored in the document.\n\t *\n\t * @remarks\n\t * Edits to the schema can mutate the schema stored of the tree which took this snapshot (but this snapshot will remain the same)\n\t * This is mainly useful for debugging cases where schematize reports an incompatible view schema.\n\t */\n\treadonly schema: TreeStoredSchema;\n\t/**\n\t * All {@link TreeStatus.InDocument} content.\n\t */\n\treadonly tree: JsonableTree[];\n\t/**\n\t * All {@link TreeStatus.Removed} content.\n\t */\n\treadonly removed: [string | number | undefined, number, JsonableTree][];\n}\n\n/**\n * {@link ITree} extended with some non-public APIs.\n * @internal\n */\nexport interface ITreeInternal extends ISharedObject, ITree {\n\t/**\n\t * Exports root in the same format as {@link TreeAlpha.(exportVerbose:1)} using stored keys.\n\t * @privateRemarks\n\t * TODO:\n\t * This should probably get promoted to a public API on ITree eventually.\n\t */\n\texportVerbose(): VerboseTree | undefined;\n\n\t/**\n\t * Exports the SimpleTreeSchema that is stored in the tree, using stored keys for object fields.\n\t * @remarks\n\t * To get the schema using property keys, use {@link getSimpleSchema} on the view schema.\n\t */\n\texportSimpleSchema(): SimpleTreeSchema;\n}\n\n/**\n * {@link ITreeInternal} extended with some non-exported APIs.\n */\nexport interface ISharedTree extends ISharedObject, ITreeInternal {\n\t/**\n\t * Provides a copy of the current content of the tree.\n\t * This can be useful for inspecting the tree when no suitable view schema is available.\n\t * This is only intended for use in testing and exceptional code paths: it is not performant.\n\t *\n\t * This does not include everything that is included in a tree summary, since information about how to merge future edits is omitted.\n\t */\n\tcontentSnapshot(): SharedTreeContentSnapshot;\n}\n\n/**\n * Has an entry for each codec which writes an explicit version into its data.\n *\n * This is used to map the single API entrypoint controlling the format {@link SharedTreeOptions.formatVersion}\n * to a list of write versions that for each codec that should be used for that format.\n *\n * Note that all explicitly versioned codecs should be using the format version from the data to read encoded data.\n *\n * TODO: Plumb these write versions into forest, schema, detached field index codec creation.\n */\ninterface ExplicitCodecVersions extends ExplicitCoreCodecVersions {\n\tforest: number;\n\tschema: number;\n\tdetachedFieldIndex: number;\n\tfieldBatch: number;\n}\n\nconst formatVersionToTopLevelCodecVersions = new Map<number, ExplicitCodecVersions>([\n\t[\n\t\t1,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 1, message: 1, fieldBatch: 1 },\n\t],\n\t[\n\t\t2,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 2, message: 2, fieldBatch: 1 },\n\t],\n\t[\n\t\t3,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 3, message: 3, fieldBatch: 1 },\n\t],\n\t[\n\t\t4,\n\t\t{ forest: 1, schema: 1, detachedFieldIndex: 1, editManager: 4, message: 4, fieldBatch: 1 },\n\t],\n]);\n\nfunction getCodecVersions(formatVersion: number): ExplicitCodecVersions {\n\tconst versions = formatVersionToTopLevelCodecVersions.get(formatVersion);\n\tassert(versions !== undefined, 0x90e /* Unknown format version */);\n\treturn versions;\n}\n\n/**\n * Build and return a forest of the requested type.\n */\nexport function buildConfiguredForest(\n\ttype: ForestType,\n\tschema: TreeStoredSchemaSubscription,\n\tidCompressor: IIdCompressor,\n): IEditableForest {\n\tswitch (type) {\n\t\tcase ForestType.Optimized:\n\t\t\treturn buildChunkedForest(\n\t\t\t\tmakeTreeChunker(schema, defaultSchemaPolicy),\n\t\t\t\tundefined,\n\t\t\t\tidCompressor,\n\t\t\t);\n\t\tcase ForestType.Reference:\n\t\t\treturn buildForest();\n\t\tcase ForestType.Expensive:\n\t\t\treturn buildForest(undefined, true);\n\t\tdefault:\n\t\t\tunreachableCase(type);\n\t}\n}\n\n/**\n * Shared tree, configured with a good set of indexes and field kinds which will maintain compatibility over time.\n *\n * TODO: detail compatibility requirements.\n */\n@breakingClass\nexport class SharedTree\n\textends SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange>\n\timplements ISharedTree\n{\n\tpublic readonly checkout: TreeCheckout;\n\tpublic get storedSchema(): TreeStoredSchemaRepository {\n\t\treturn this.checkout.storedSchema;\n\t}\n\n\tpublic constructor(\n\t\tid: string,\n\t\truntime: IFluidDataStoreRuntime,\n\t\tattributes: IChannelAttributes,\n\t\toptionsParam: SharedTreeOptions,\n\t\ttelemetryContextPrefix: string = \"fluid_sharedTree_\",\n\t) {\n\t\tif (runtime.idCompressor === undefined) {\n\t\t\tthrow new UsageError(\"IdCompressor must be enabled to use SharedTree\");\n\t\t}\n\n\t\tconst options = { ...defaultSharedTreeOptions, ...optionsParam };\n\t\tconst codecVersions = getCodecVersions(options.formatVersion);\n\t\tconst schema = new TreeStoredSchemaRepository();\n\t\tconst forest = buildConfiguredForest(options.forest, schema, runtime.idCompressor);\n\t\tconst revisionTagCodec = new RevisionTagCodec(runtime.idCompressor);\n\t\tconst removedRoots = makeDetachedFieldIndex(\n\t\t\t\"repair\",\n\t\t\trevisionTagCodec,\n\t\t\truntime.idCompressor,\n\t\t\toptions,\n\t\t);\n\t\tconst schemaSummarizer = new SchemaSummarizer(runtime, schema, options, {\n\t\t\tgetCurrentSeq: () => this.deltaManager.lastSequenceNumber,\n\t\t});\n\t\tconst fieldBatchCodec = makeFieldBatchCodec(options, codecVersions.fieldBatch);\n\n\t\tconst encoderContext = {\n\t\t\tschema: {\n\t\t\t\tschema,\n\t\t\t\tpolicy: defaultSchemaPolicy,\n\t\t\t},\n\t\t\tencodeType: options.treeEncodeType,\n\t\t\toriginatorId: runtime.idCompressor.localSessionId,\n\t\t\tidCompressor: runtime.idCompressor,\n\t\t};\n\t\tconst forestSummarizer = new ForestSummarizer(\n\t\t\tforest,\n\t\t\trevisionTagCodec,\n\t\t\tfieldBatchCodec,\n\t\t\tencoderContext,\n\t\t\toptions,\n\t\t\truntime.idCompressor,\n\t\t);\n\t\tconst removedRootsSummarizer = new DetachedFieldIndexSummarizer(removedRoots);\n\t\tconst innerChangeFamily = new SharedTreeChangeFamily(\n\t\t\trevisionTagCodec,\n\t\t\tfieldBatchCodec,\n\t\t\toptions,\n\t\t\toptions.treeEncodeType,\n\t\t\truntime.idCompressor,\n\t\t);\n\t\tconst changeFamily = makeMitigatedChangeFamily(\n\t\t\tinnerChangeFamily,\n\t\t\tSharedTreeChangeFamily.emptyChange,\n\t\t\t(error: unknown) => {\n\t\t\t\t// TODO:6344 Add telemetry for these errors.\n\t\t\t\t// Rethrowing the error has a different effect depending on the context in which the\n\t\t\t\t// ChangeFamily was invoked:\n\t\t\t\t// - If the ChangeFamily was invoked as part of incoming op processing, rethrowing the error\n\t\t\t\t// will cause the runtime to disconnect the client, log a severe error, and not reconnect.\n\t\t\t\t// This will not cause the host application to crash because it is not on the stack at that time.\n\t\t\t\t// TODO: let the host application know that the client is now disconnected.\n\t\t\t\t// - If the ChangeFamily was invoked as part of dealing with a local change, rethrowing the\n\t\t\t\t// error will cause the host application to crash. This is not ideal, but is better than\n\t\t\t\t// letting the application either send an invalid change to the server or allowing the\n\t\t\t\t// application to continue working when its local branches contain edits that cannot be\n\t\t\t\t// reflected in its views.\n\t\t\t\t// The best course of action for a host application in such a state is to restart.\n\t\t\t\t// TODO: let the host application know about this situation and provide a way to\n\t\t\t\t// programmatically reload the SharedTree container.\n\t\t\t\tthrow error;\n\t\t\t},\n\t\t);\n\t\tconst changeEnricher = new SharedTreeReadonlyChangeEnricher(forest, schema, removedRoots);\n\t\tsuper(\n\t\t\t[schemaSummarizer, forestSummarizer, removedRootsSummarizer],\n\t\t\tchangeFamily,\n\t\t\toptions,\n\t\t\tcodecVersions,\n\t\t\tid,\n\t\t\truntime,\n\t\t\tattributes,\n\t\t\ttelemetryContextPrefix,\n\t\t\tschema,\n\t\t\tdefaultSchemaPolicy,\n\t\t\tnew DefaultResubmitMachine(\n\t\t\t\t(change: TaggedChange<SharedTreeChange>) =>\n\t\t\t\t\tchangeFamily.rebaser.invert(change, true, this.mintRevisionTag()),\n\t\t\t\tchangeEnricher,\n\t\t\t),\n\t\t\tchangeEnricher,\n\t\t);\n\t\tconst localBranch = this.getLocalBranch();\n\t\tthis.checkout = createTreeCheckout(\n\t\t\truntime.idCompressor,\n\t\t\tthis.mintRevisionTag,\n\t\t\trevisionTagCodec,\n\t\t\t{\n\t\t\t\tbranch: localBranch,\n\t\t\t\tchangeFamily,\n\t\t\t\tschema,\n\t\t\t\tforest,\n\t\t\t\tfieldBatchCodec,\n\t\t\t\tremovedRoots,\n\t\t\t\tchunkCompressionStrategy: options.treeEncodeType,\n\t\t\t\tlogger: this.logger,\n\t\t\t\tbreaker: this.breaker,\n\t\t\t},\n\t\t);\n\n\t\tthis.checkout.transaction.events.on(\"started\", () => {\n\t\t\tif (this.isAttached()) {\n\t\t\t\t// It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.\n\t\t\t\tthis.commitEnricher.startTransaction();\n\t\t\t}\n\t\t});\n\t\tthis.checkout.transaction.events.on(\"aborting\", () => {\n\t\t\tif (this.isAttached()) {\n\t\t\t\t// It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.\n\t\t\t\tthis.commitEnricher.abortTransaction();\n\t\t\t}\n\t\t});\n\t\tthis.checkout.transaction.events.on(\"committing\", () => {\n\t\t\tif (this.isAttached()) {\n\t\t\t\t// It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.\n\t\t\t\tthis.commitEnricher.commitTransaction();\n\t\t\t}\n\t\t});\n\t\tthis.checkout.events.on(\"beforeBatch\", (event) => {\n\t\t\tif (event.type === \"append\" && this.isAttached()) {\n\t\t\t\tif (this.checkout.transaction.isInProgress()) {\n\t\t\t\t\tthis.commitEnricher.addTransactionCommits(event.newCommits);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tpublic exportVerbose(): VerboseTree | undefined {\n\t\tconst cursor = this.checkout.forest.allocateCursor(\"contentSnapshot\");\n\t\ttry {\n\t\t\tmoveToDetachedField(this.checkout.forest, cursor);\n\t\t\tconst length = cursor.getFieldLength();\n\t\t\tif (length === 0) {\n\t\t\t\treturn undefined;\n\t\t\t} else if (length === 1) {\n\t\t\t\tcursor.enterNode(0);\n\t\t\t\treturn verboseFromCursor(cursor, this.storedSchema.nodeSchema);\n\t\t\t} else {\n\t\t\t\tfail(\"Invalid document root length\");\n\t\t\t}\n\t\t} finally {\n\t\t\tcursor.free();\n\t\t}\n\t}\n\n\tpublic exportSimpleSchema(): SimpleTreeSchema {\n\t\treturn {\n\t\t\t...exportSimpleFieldSchemaStored(this.storedSchema.rootFieldSchema),\n\t\t\tdefinitions: new Map(\n\t\t\t\t[...this.storedSchema.nodeSchema].map(([key, schema]) => {\n\t\t\t\t\treturn [key, exportSimpleNodeSchemaStored(schema)];\n\t\t\t\t}),\n\t\t\t),\n\t\t};\n\t}\n\n\t@throwIfBroken\n\tpublic contentSnapshot(): SharedTreeContentSnapshot {\n\t\tconst cursor = this.checkout.forest.allocateCursor(\"contentSnapshot\");\n\t\ttry {\n\t\t\tmoveToDetachedField(this.checkout.forest, cursor);\n\t\t\treturn {\n\t\t\t\tschema: this.storedSchema.clone(),\n\t\t\t\ttree: jsonableTreeFromFieldCursor(cursor),\n\t\t\t\tremoved: this.checkout.getRemovedRoots(),\n\t\t\t};\n\t\t} finally {\n\t\t\tcursor.free();\n\t\t}\n\t}\n\n\t// For the new TreeViewAlpha API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>>;\n\n\t// For the old TreeView API\n\tpublic viewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): SchematizingSimpleTreeView<TRoot> & TreeView<TRoot>;\n\n\tpublic viewWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\t\tconfig: TreeViewConfiguration<ReadSchema<TRoot>>,\n\t): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>> {\n\t\treturn this.checkout.viewWith(config) as SchematizingSimpleTreeView<TRoot> &\n\t\t\tTreeView<ReadSchema<TRoot>>;\n\t}\n\n\tprotected override async loadCore(services: IChannelStorageService): Promise<void> {\n\t\tawait super.loadCore(services);\n\t\tthis.checkout.load();\n\t}\n\n\tprotected override didAttach(): void {\n\t\tif (this.checkout.transaction.isInProgress()) {\n\t\t\t// Attaching during a transaction is not currently supported.\n\t\t\t// At least part of of the system is known to not handle this case correctly - commit enrichment - and there may be others.\n\t\t\tthrow new UsageError(\n\t\t\t\t\"Cannot attach while a transaction is in progress. Commit or abort the transaction before attaching.\",\n\t\t\t);\n\t\t}\n\t\tsuper.didAttach();\n\t}\n\n\tprotected override applyStashedOp(\n\t\t...args: Parameters<\n\t\t\tSharedTreeCore<SharedTreeEditBuilder, SharedTreeChange>[\"applyStashedOp\"]\n\t\t>\n\t): void {\n\t\tassert(\n\t\t\t!this.checkout.transaction.isInProgress(),\n\t\t\t0x674 /* Unexpected transaction is open while applying stashed ops */,\n\t\t);\n\t\tsuper.applyStashedOp(...args);\n\t}\n\n\tprotected override submitCommit(\n\t\tcommit: GraphCommit<SharedTreeChange>,\n\t\tschemaAndPolicy: ClonableSchemaAndPolicy,\n\t\tisResubmit: boolean,\n\t): void {\n\t\tassert(\n\t\t\t!this.checkout.transaction.isInProgress(),\n\t\t\t\"Cannot submit a commit while a transaction is in progress\",\n\t\t);\n\t\tif (isResubmit) {\n\t\t\treturn super.submitCommit(commit, schemaAndPolicy, isResubmit);\n\t\t}\n\n\t\t// Refrain from submitting new commits until they are validated by the checkout.\n\t\t// This is not a strict requirement for correctness in our system, but in the event that there is a bug when applying commits to the checkout\n\t\t// that causes a crash (e.g. in the forest), this will at least prevent this client from sending the problematic commit to any other clients.\n\t\tthis.checkout.onCommitValid(commit, () =>\n\t\t\tsuper.submitCommit(commit, schemaAndPolicy, isResubmit),\n\t\t);\n\t}\n}\n\n/**\n * Get a {@link BranchableTree} from a {@link ITree}.\n * @remarks The branch can be used for \"version control\"-style coordination of edits on the tree.\n * @privateRemarks This function will be removed if/when the branching API becomes public,\n * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.\n * @alpha\n * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.\n */\nexport function getBranch(tree: ITree): BranchableTree;\n/**\n * Get a {@link BranchableTree} from a {@link TreeView}.\n * @remarks The branch can be used for \"version control\"-style coordination of edits on the tree.\n * Branches are currently an unstable \"alpha\" API and are subject to change in the future.\n * @privateRemarks This function will be removed if/when the branching API becomes public,\n * but it (or something like it) is necessary in the meantime to prevent the alpha types from being exposed as public.\n * @alpha\n * @deprecated This API is superseded by {@link TreeBranch}, which should be used instead.\n */\nexport function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\tview: TreeViewAlpha<T>,\n): BranchableTree;\nexport function getBranch<T extends ImplicitFieldSchema | UnsafeUnknownSchema>(\n\ttreeOrView: ITree | TreeViewAlpha<T>,\n): BranchableTree {\n\tassert(\n\t\ttreeOrView instanceof SharedTree || treeOrView instanceof SchematizingSimpleTreeView,\n\t\t0xa48 /* Unsupported implementation */,\n\t);\n\tconst checkout: TreeCheckout = treeOrView.checkout;\n\t// This cast is safe so long as TreeCheckout supports all the operations on the branch interface.\n\treturn checkout as unknown as BranchableTree;\n}\n\n/**\n * Format versions supported by SharedTree.\n *\n * Each version documents a required minimum version of the \\@fluidframework/tree package.\n * @alpha\n */\nexport const SharedTreeFormatVersion = {\n\t/**\n\t * Requires \\@fluidframework/tree \\>= 2.0.0.\n\t *\n\t * @deprecated - FF does not currently plan on supporting this format long-term.\n\t * Do not write production documents using this format, as they may not be loadable in the future.\n\t */\n\tv1: 1,\n\n\t/**\n\t * Requires \\@fluidframework/tree \\>= 2.0.0.\n\t */\n\tv2: 2,\n\n\t/**\n\t * Requires \\@fluidframework/tree \\>= 2.0.0.\n\t */\n\tv3: 3,\n} as const;\n\n/**\n * Format versions supported by SharedTree.\n *\n * Each version documents a required minimum version of the \\@fluidframework/tree package.\n * @alpha\n * @privateRemarks\n * See packages/dds/tree/docs/main/compatibility.md for information on how to add support for a new format.\n *\n * TODO: Before this gets promoted past Alpha,\n * a separate abstraction more suited for use in the public API should be adopted rather than reusing the same types used internally.\n * Such an abstraction should probably be in the form of a Fluid-Framework wide compatibility enum.\n */\nexport type SharedTreeFormatVersion = typeof SharedTreeFormatVersion;\n\n/**\n * Configuration options for SharedTree.\n * @alpha\n */\nexport type SharedTreeOptions = Partial<ICodecOptions> &\n\tPartial<SharedTreeFormatOptions> &\n\tForestOptions;\n\n/**\n * Configuration options for SharedTree's internal tree storage.\n * @alpha\n */\nexport interface ForestOptions {\n\t/**\n\t * The {@link ForestType} indicating which forest type should be created for the SharedTree.\n\t */\n\treadonly forest?: ForestType;\n}\n\n/**\n * Options for configuring the persisted format SharedTree uses.\n * @alpha\n */\nexport interface SharedTreeFormatOptions {\n\t/**\n\t * See {@link TreeCompressionStrategy}.\n\t * default: TreeCompressionStrategy.Compressed\n\t */\n\ttreeEncodeType: TreeCompressionStrategy;\n\t/**\n\t * The format version SharedTree should use to persist documents.\n\t *\n\t * This option has compatibility implications for applications using SharedTree.\n\t * Each version documents a required minimum version of \\@fluidframework/tree.\n\t * If this minimum version fails to be met, the SharedTree may fail to load.\n\t * To be safe, application authors should verify that they have saturated this version\n\t * of \\@fluidframework/tree in their ecosystem before changing the format version.\n\t *\n\t * This option defaults to SharedTreeFormatVersion.v2.\n\t */\n\tformatVersion: SharedTreeFormatVersion[keyof SharedTreeFormatVersion];\n}\n\n/**\n * Used to distinguish between different forest types.\n * @alpha\n */\nexport enum ForestType {\n\t/**\n\t * The \"ObjectForest\" forest type.\n\t */\n\tReference = 0,\n\t/**\n\t * The \"ChunkedForest\" forest type.\n\t */\n\tOptimized = 1,\n\t/**\n\t * The \"ObjectForest\" forest type with expensive asserts for debugging.\n\t */\n\tExpensive = 2,\n}\n\nexport const defaultSharedTreeOptions: Required<SharedTreeOptions> = {\n\tjsonValidator: noopValidator,\n\tforest: ForestType.Reference,\n\ttreeEncodeType: TreeCompressionStrategy.Compressed,\n\tformatVersion: SharedTreeFormatVersion.v3,\n};\n\n/**\n * A channel factory that creates {@link ISharedTree}s.\n */\nexport class SharedTreeFactory implements IChannelFactory<ISharedTree> {\n\tpublic readonly type: string = \"https://graph.microsoft.com/types/tree\";\n\n\tpublic readonly attributes: IChannelAttributes = {\n\t\ttype: this.type,\n\t\tsnapshotFormatVersion: \"0.0.0\",\n\t\tpackageVersion: \"0.0.0\",\n\t};\n\n\tpublic constructor(private readonly options: SharedTreeOptions = {}) {}\n\n\tpublic async load(\n\t\truntime: IFluidDataStoreRuntime,\n\t\tid: string,\n\t\tservices: IChannelServices,\n\t\tchannelAttributes: Readonly<IChannelAttributes>,\n\t): Promise<SharedTree> {\n\t\tconst tree = new SharedTree(id, runtime, channelAttributes, this.options);\n\t\tawait tree.load(services);\n\t\treturn tree;\n\t}\n\n\tpublic create(runtime: IFluidDataStoreRuntime, id: string): SharedTree {\n\t\tconst tree = new SharedTree(id, runtime, this.attributes, this.options);\n\t\ttree.initializeLocal();\n\t\treturn tree;\n\t}\n}\n\nfunction verboseFromCursor(\n\treader: ITreeCursor,\n\tschema: ReadonlyMap<TreeNodeSchemaIdentifier, TreeNodeStoredSchema>,\n): VerboseTree {\n\tconst fields = customFromCursorStored(reader, schema, verboseFromCursor);\n\tconst nodeSchema = schema.get(reader.type) ?? fail(\"missing schema for type in cursor\");\n\tif (nodeSchema instanceof LeafNodeStoredSchema) {\n\t\treturn fields as CustomTreeValue<IFluidHandle>;\n\t}\n\n\treturn {\n\t\ttype: reader.type,\n\t\tfields: fields as CustomTreeNode<IFluidHandle>,\n\t};\n}\n\nfunction exportSimpleFieldSchemaStored(schema: TreeFieldStoredSchema): SimpleFieldSchema {\n\tlet kind: FieldKind;\n\tswitch (schema.kind) {\n\t\tcase FieldKinds.identifier.identifier:\n\t\t\tkind = FieldKind.Identifier;\n\t\t\tbreak;\n\t\tcase FieldKinds.optional.identifier:\n\t\t\tkind = FieldKind.Optional;\n\t\t\tbreak;\n\t\tcase FieldKinds.required.identifier:\n\t\t\tkind = FieldKind.Required;\n\t\t\tbreak;\n\t\tcase FieldKinds.forbidden.identifier:\n\t\t\tkind = FieldKind.Optional;\n\t\t\tassert(schema.types.size === 0, 0xa94 /* invalid forbidden field */);\n\t\t\tbreak;\n\t\tdefault:\n\t\t\tfail(\"invalid field kind\");\n\t}\n\treturn { kind, allowedTypes: schema.types };\n}\n\nfunction exportSimpleNodeSchemaStored(schema: TreeNodeStoredSchema): SimpleNodeSchema {\n\tconst arrayTypes = tryStoredSchemaAsArray(schema);\n\tif (arrayTypes !== undefined) {\n\t\treturn { kind: NodeKind.Array, allowedTypes: arrayTypes };\n\t}\n\tif (schema instanceof ObjectNodeStoredSchema) {\n\t\tconst fields: Record<string, SimpleFieldSchema> = {};\n\t\tfor (const [key, field] of schema.objectNodeFields) {\n\t\t\tfields[key] = exportSimpleFieldSchemaStored(field);\n\t\t}\n\t\treturn { kind: NodeKind.Object, fields };\n\t}\n\tif (schema instanceof MapNodeStoredSchema) {\n\t\tassert(\n\t\t\tschema.mapFields.kind === FieldKinds.optional.identifier,\n\t\t\t0xa95 /* Invalid map schema */,\n\t\t);\n\t\treturn { kind: NodeKind.Map, allowedTypes: schema.mapFields.types };\n\t}\n\tif (schema instanceof LeafNodeStoredSchema) {\n\t\treturn { kind: NodeKind.Leaf, leafKind: schema.leafValue };\n\t}\n\tfail(\"invalid schema kind\");\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"sharedTreeChangeFamily.d.ts","sourceRoot":"","sources":["../../src/shared-tree/sharedTreeChangeFamily.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AACrE,OAAO,EACN,KAAK,qBAAqB,EAC1B,KAAK,YAAY,EACjB,KAAK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AM,EAAE,gBAAgB,EACxB,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,UAAU,CAAC,EAAE,WAAW,GACtB,gBAAgB;IAiBnB,IAAW,OAAO,IAAI,aAAa,CAAC,gBAAgB,CAAC,CAEpD;CACD;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAEjE;AAmBD;;;;;;GAMG;AACH,wBAAgB,gBAAgB,CAC/B,MAAM,EAAE,gBAAgB,EACxB,eAAe,EAAE,CAAC,EAAE,EAAE,mBAAmB,KAAK,SAAS,GAAG,SAAS,EACnE,kCAAkC,EAAE,CACnC,YAAY,EAAE,gBAAgB,KAC1B,QAAQ,CAAC,mBAAmB,CAAC,EAClC,0BAA0B,EAAE,CAC3B,MAAM,EAAE,gBAAgB,EACxB,eAAe,EAAE,CAAC,EAAE,EAAE,mBAAmB,KAAK,SAAS,GAAG,SAAS,EACnE,YAAY,EAAE,QAAQ,CAAC,mBAAmB,CAAC,EAC3C,iBAAiB,EAAE,OAAO,KACtB,gBAAgB,GACnB,gBAAgB,CAsDlB"}
@@ -95,9 +95,9 @@ class SharedTreeChangeFamily {
95
95
  // will result in rebase never being called.
96
96
  return SharedTreeChangeFamily.emptyChange;
97
97
  }
98
- (0, internal_1.assert)(change.change.changes.length === 1 && over.change.changes.length === 1, 0x884 /* SharedTreeChange should have exactly one inner change if no schema change is present. */);
99
- const dataChangeIntention = change.change.changes[0] ?? (0, internal_1.oob)();
100
- const dataChangeOver = over.change.changes[0] ?? (0, internal_1.oob)();
98
+ (0, internal_1.assert)((0, index_js_3.hasSingle)(change.change.changes) && (0, index_js_3.hasSingle)(over.change.changes), 0x884 /* SharedTreeChange should have exactly one inner change if no schema change is present. */);
99
+ const dataChangeIntention = change.change.changes[0];
100
+ const dataChangeOver = over.change.changes[0];
101
101
  (0, internal_1.assert)(dataChangeIntention.type === "data" && dataChangeOver.type === "data", 0x885 /* Data change should be present. */);
102
102
  return {
103
103
  changes: [
@@ -1 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U,EACV,0BAA0B,EAC1B,YAAY,EACZ,IAAI,CACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACP,OAAO,0BAA0B,CAChC,UAAU,EACV,0BAA0B,EAC1B,mBAAmB,CAAC,YAAY,CAAC,EACjC,KAAK,CACL,CAAC;QACH,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAlED,4CAkEC","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 { ICodecFamily, ICodecOptions } from \"../codec/index.js\";\nimport {\n\ttype ChangeEncodingContext,\n\ttype ChangeFamily,\n\ttype ChangeRebaser,\n\ttype DeltaDetachedNodeId,\n\ttype RevisionMetadataSource,\n\ttype RevisionTag,\n\ttype RevisionTagCodec,\n\ttype TaggedChange,\n\tmapTaggedChange,\n} from \"../core/index.js\";\nimport {\n\ttype FieldBatchCodec,\n\tModularChangeFamily,\n\ttype ModularChangeset,\n\ttype TreeChunk,\n\ttype TreeCompressionStrategy,\n\tfieldKindConfigurations,\n\tfieldKinds,\n\tmakeModularChangeCodecFamily,\n} from \"../feature-libraries/index.js\";\nimport {\n\ttype Mutable,\n\ttype NestedSet,\n\taddToNestedSet,\n\tfail,\n\tnestedSetContains,\n} from \"../util/index.js\";\n\nimport { makeSharedTreeChangeCodecFamily } from \"./sharedTreeChangeCodecs.js\";\nimport type { SharedTreeChange } from \"./sharedTreeChangeTypes.js\";\nimport { SharedTreeEditBuilder } from \"./sharedTreeEditBuilder.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\n/**\n * Implementation of {@link ChangeFamily} that combines edits to fields and schema changes.\n *\n * @sealed\n */\nexport class SharedTreeChangeFamily\n\timplements\n\t\tChangeFamily<SharedTreeEditBuilder, SharedTreeChange>,\n\t\tChangeRebaser<SharedTreeChange>\n{\n\tpublic static readonly emptyChange: SharedTreeChange = {\n\t\tchanges: [],\n\t};\n\n\tpublic readonly codecs: ICodecFamily<SharedTreeChange, ChangeEncodingContext>;\n\tprivate readonly modularChangeFamily: ModularChangeFamily;\n\n\tpublic constructor(\n\t\trevisionTagCodec: RevisionTagCodec,\n\t\tfieldBatchCodec: FieldBatchCodec,\n\t\tcodecOptions: ICodecOptions,\n\t\tchunkCompressionStrategy?: TreeCompressionStrategy,\n\t\tprivate readonly idCompressor?: IIdCompressor,\n\t) {\n\t\tconst modularChangeCodec = makeModularChangeCodecFamily(\n\t\t\tfieldKindConfigurations,\n\t\t\trevisionTagCodec,\n\t\t\tfieldBatchCodec,\n\t\t\tcodecOptions,\n\t\t\tchunkCompressionStrategy,\n\t\t);\n\t\tthis.modularChangeFamily = new ModularChangeFamily(fieldKinds, modularChangeCodec);\n\t\tthis.codecs = makeSharedTreeChangeCodecFamily(\n\t\t\tthis.modularChangeFamily.codecs,\n\t\t\tcodecOptions,\n\t\t);\n\t}\n\n\tpublic buildEditor(\n\t\tmintRevisionTag: () => RevisionTag,\n\t\tchangeReceiver: (change: TaggedChange<SharedTreeChange>) => void,\n\t): SharedTreeEditBuilder {\n\t\treturn new SharedTreeEditBuilder(\n\t\t\tthis.modularChangeFamily,\n\t\t\tmintRevisionTag,\n\t\t\tchangeReceiver,\n\t\t\tthis.idCompressor,\n\t\t);\n\t}\n\n\tpublic compose(changes: TaggedChange<SharedTreeChange>[]): SharedTreeChange {\n\t\tconst newChanges: Mutable<SharedTreeChange[\"changes\"]> = [];\n\t\tconst dataChangeRun: TaggedChange<ModularChangeset>[] = [];\n\n\t\tconst flushDataChangeRun = (): void => {\n\t\t\tif (dataChangeRun.length > 0) {\n\t\t\t\tnewChanges.push({\n\t\t\t\t\ttype: \"data\",\n\t\t\t\t\tinnerChange: this.modularChangeFamily.compose(dataChangeRun),\n\t\t\t\t});\n\t\t\t\tdataChangeRun.length = 0;\n\t\t\t}\n\t\t};\n\n\t\tfor (const topChange of changes) {\n\t\t\tfor (const change of topChange.change.changes) {\n\t\t\t\tif (change.type === \"schema\") {\n\t\t\t\t\tflushDataChangeRun();\n\t\t\t\t\tnewChanges.push(change);\n\t\t\t\t} else {\n\t\t\t\t\tdataChangeRun.push(mapTaggedChange(topChange, change.innerChange));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tflushDataChangeRun();\n\t\treturn { changes: newChanges };\n\t}\n\n\tpublic invert(\n\t\tchange: TaggedChange<SharedTreeChange>,\n\t\tisRollback: boolean,\n\t\trevision: RevisionTag,\n\t): SharedTreeChange {\n\t\tconst invertInnerChange: (\n\t\t\tinnerChange: SharedTreeChange[\"changes\"][number],\n\t\t) => SharedTreeChange[\"changes\"][number] = (innerChange) => {\n\t\t\tswitch (innerChange.type) {\n\t\t\t\tcase \"data\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"data\",\n\t\t\t\t\t\tinnerChange: this.modularChangeFamily.invert(\n\t\t\t\t\t\t\tmapTaggedChange(change, innerChange.innerChange),\n\t\t\t\t\t\t\tisRollback,\n\t\t\t\t\t\t\trevision,\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\tcase \"schema\": {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"schema\",\n\t\t\t\t\t\tinnerChange: {\n\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\tnew: innerChange.innerChange.schema.old,\n\t\t\t\t\t\t\t\told: innerChange.innerChange.schema.new,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tisInverse: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tfail(\"Unknown SharedTree change type.\");\n\t\t\t}\n\t\t};\n\t\treturn {\n\t\t\tchanges: change.change.changes.map(invertInnerChange).reverse(),\n\t\t};\n\t}\n\n\tpublic rebase(\n\t\tchange: TaggedChange<SharedTreeChange>,\n\t\tover: TaggedChange<SharedTreeChange>,\n\t\trevisionMetadata: RevisionMetadataSource,\n\t): SharedTreeChange {\n\t\tif (change.change.changes.length === 0 || over.change.changes.length === 0) {\n\t\t\treturn change.change;\n\t\t}\n\n\t\tif (hasSchemaChange(change.change) || hasSchemaChange(over.change)) {\n\t\t\t// Any SharedTreeChange (a list of sub-changes) that contains a schema change will cause ANY change that rebases over it to conflict.\n\t\t\t// Similarly, any SharedTreeChange containing a schema change will fail to rebase over ANY change.\n\t\t\t// Those two combine to mean: no concurrency with schema changes is supported.\n\t\t\t// This is fine because it's an open problem. Example: a tree with an A at the root and a schema that allows an A | B at the root will\n\t\t\t// become out of schema if a schema changes to restrict root types to just A is concurrent with a data change that sets it to a B.\n\t\t\t// We don't have an efficient way to detect this document-wide and there are varying opinions on restricting schema changes to prevent this.\n\t\t\t// A SharedTreeChange containing a schema change will NOT conflict in a non-concurrency case, as the \"meatless sandwich\" optimization\n\t\t\t// will result in rebase never being called.\n\t\t\treturn SharedTreeChangeFamily.emptyChange;\n\t\t}\n\t\tassert(\n\t\t\tchange.change.changes.length === 1 && over.change.changes.length === 1,\n\t\t\t0x884 /* SharedTreeChange should have exactly one inner change if no schema change is present. */,\n\t\t);\n\n\t\tconst dataChangeIntention = change.change.changes[0] ?? oob();\n\t\tconst dataChangeOver = over.change.changes[0] ?? oob();\n\t\tassert(\n\t\t\tdataChangeIntention.type === \"data\" && dataChangeOver.type === \"data\",\n\t\t\t0x885 /* Data change should be present. */,\n\t\t);\n\n\t\treturn {\n\t\t\tchanges: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"data\",\n\t\t\t\t\tinnerChange: this.modularChangeFamily.rebase(\n\t\t\t\t\t\tmapTaggedChange(change, dataChangeIntention.innerChange),\n\t\t\t\t\t\tmapTaggedChange(over, dataChangeOver.innerChange),\n\t\t\t\t\t\trevisionMetadata,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\n\tpublic changeRevision(\n\t\tchange: SharedTreeChange,\n\t\tnewRevision: RevisionTag | undefined,\n\t\trollbackOf?: RevisionTag,\n\t): SharedTreeChange {\n\t\treturn {\n\t\t\tchanges: change.changes.map((inner) => {\n\t\t\t\treturn inner.type === \"data\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...inner,\n\t\t\t\t\t\t\tinnerChange: this.modularChangeFamily.rebaser.changeRevision(\n\t\t\t\t\t\t\t\tinner.innerChange,\n\t\t\t\t\t\t\t\tnewRevision,\n\t\t\t\t\t\t\t\trollbackOf,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t: inner;\n\t\t\t}),\n\t\t};\n\t}\n\n\tpublic get rebaser(): ChangeRebaser<SharedTreeChange> {\n\t\treturn this;\n\t}\n}\n\nexport function hasSchemaChange(change: SharedTreeChange): boolean {\n\treturn change.changes.some((innerChange) => innerChange.type === \"schema\");\n}\n\nfunction mapDataChanges(\n\tchange: SharedTreeChange,\n\tmap: (change: ModularChangeset) => ModularChangeset,\n): SharedTreeChange {\n\treturn {\n\t\tchanges: change.changes.map((dataOrSchemaChange) => {\n\t\t\tif (dataOrSchemaChange.type === \"data\") {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"data\",\n\t\t\t\t\tinnerChange: map(dataOrSchemaChange.innerChange),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn dataOrSchemaChange;\n\t\t}),\n\t};\n}\n\n/**\n * Produces an equivalent change with an updated set of appropriate refreshers.\n * @param change - The change to compute refreshers for. Not mutated.\n * @param getDetachedNode - retrieves a {@link TreeChunk} for the corresponding detached node id.\n * Is expected to read from a forest in a state that corresponds to the input context of the given change.\n * @returns An equivalent change with an updated set of appropriate refreshers.\n */\nexport function updateRefreshers(\n\tchange: SharedTreeChange,\n\tgetDetachedNode: (id: DeltaDetachedNodeId) => TreeChunk | undefined,\n\trelevantRemovedRootsFromDataChange: (\n\t\ttaggedChange: ModularChangeset,\n\t) => Iterable<DeltaDetachedNodeId>,\n\tupdateDataChangeRefreshers: (\n\t\tchange: ModularChangeset,\n\t\tgetDetachedNode: (id: DeltaDetachedNodeId) => TreeChunk | undefined,\n\t\tremovedRoots: Iterable<DeltaDetachedNodeId>,\n\t\trequireRefreshers: boolean,\n\t) => ModularChangeset,\n): SharedTreeChange {\n\t// Adding refreshers to a SharedTreeChange is not as simple as adding refreshers to each of its data changes.\n\t// This is because earlier data changes affect the state of the forest in ways that can influence the refreshers\n\t// needed for later data changes. This can happen in two ways:\n\t// 1. By removing a tree that is a relevant root to a later data change.\n\t// 2. By changing the contents of a tree that is a relevant root to a later data change.\n\t// (Note that these two cases can compound)\n\t// Thankfully, in both of these cases, refreshers can be omitted from the later data changes because the forest\n\t// applying those data changes is guaranteed to still have have the relevant trees in memory.\n\t// This means that for the first data change, all required refreshers should be added (and none should be missing).\n\t// While for later data changes, we should not include refreshers that either:\n\t// A) were already included in the earlier data changes\n\t// B) correspond to trees that were removed by earlier data changes\n\t// Set A is excluded by tracking which roots have already been included in the earlier data changes, and filtering\n\t// them out from the relevant removed roots.\n\t// Set B is excluded because the `getDetachedNode` is bound to return `undefined` for them, which tell\n\t// `defaultUpdateRefreshers` to ignore. One downside of this approach is that it prevents `defaultUpdateRefreshers`\n\t// from detecting cases where a detached node is missing for another reason (which would be a bug).\n\n\t// The roots that have been included as refreshers across all data changes so far.\n\tconst includedRoots: NestedSet<RevisionTag | undefined, number> = new Map();\n\tfunction getAndRememberDetachedNode(id: DeltaDetachedNodeId): TreeChunk | undefined {\n\t\taddToNestedSet(includedRoots, id.major, id.minor);\n\t\treturn getDetachedNode(id);\n\t}\n\tfunction* filterIncludedRoots(\n\t\ttoFilter: Iterable<DeltaDetachedNodeId>,\n\t): Iterable<DeltaDetachedNodeId> {\n\t\tfor (const id of toFilter) {\n\t\t\tif (!nestedSetContains(includedRoots, id.major, id.minor)) {\n\t\t\t\tyield id;\n\t\t\t}\n\t\t}\n\t}\n\tlet isFirstDataChange = true;\n\treturn mapDataChanges(change, (dataChange) => {\n\t\tconst removedRoots = relevantRemovedRootsFromDataChange(dataChange);\n\t\tif (isFirstDataChange) {\n\t\t\tisFirstDataChange = false;\n\t\t\treturn updateDataChangeRefreshers(\n\t\t\t\tdataChange,\n\t\t\t\tgetAndRememberDetachedNode,\n\t\t\t\tremovedRoots,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t} else {\n\t\t\treturn updateDataChangeRefreshers(\n\t\t\t\tdataChange,\n\t\t\t\tgetAndRememberDetachedNode,\n\t\t\t\tfilterIncludedRoots(removedRoots),\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t});\n}\n"]}
1
+ {"version":3,"file":"sharedTreeChangeFamily.js","sourceRoot":"","sources":["../../src/shared-tree/sharedTreeChangeFamily.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAA6D;AAG7D,+CAU0B;AAC1B,4DASuC;AACvC,+CAO0B;AAE1B,2EAA8E;AAE9E,yEAAmE;AAGnE;;;;GAIG;AACH,MAAa,sBAAsB;IAYlC,YACC,gBAAkC,EAClC,eAAgC,EAChC,YAA2B,EAC3B,wBAAkD,EACjC,YAA4B;QAA5B,iBAAY,GAAZ,YAAY,CAAgB;QAE7C,MAAM,kBAAkB,GAAG,IAAA,uCAA4B,EACtD,kCAAuB,EACvB,gBAAgB,EAChB,eAAe,EACf,YAAY,EACZ,wBAAwB,CACxB,CAAC;QACF,IAAI,CAAC,mBAAmB,GAAG,IAAI,8BAAmB,CAAC,qBAAU,EAAE,kBAAkB,CAAC,CAAC;QACnF,IAAI,CAAC,MAAM,GAAG,IAAA,2DAA+B,EAC5C,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAC/B,YAAY,CACZ,CAAC;IACH,CAAC;IAEM,WAAW,CACjB,eAAkC,EAClC,cAAgE;QAEhE,OAAO,IAAI,gDAAqB,CAC/B,IAAI,CAAC,mBAAmB,EACxB,eAAe,EACf,cAAc,EACd,IAAI,CAAC,YAAY,CACjB,CAAC;IACH,CAAC;IAEM,OAAO,CAAC,OAAyC;QACvD,MAAM,UAAU,GAAyC,EAAE,CAAC;QAC5D,MAAM,a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;IACF,CAAC;IACD,IAAI,iBAAiB,GAAG,IAAI,CAAC;IAC7B,OAAO,cAAc,CAAC,MAAM,EAAE,CAAC,UAAU,EAAE,EAAE;QAC5C,MAAM,YAAY,GAAG,kCAAkC,CAAC,UAAU,CAAC,CAAC;QACpE,IAAI,iBAAiB,EAAE,CAAC;YACvB,iBAAiB,GAAG,KAAK,CAAC;YAC1B,OAAO,0BAA0B,CAChC,UAAU,EACV,0BAA0B,EAC1B,YAAY,EACZ,IAAI,CACJ,CAAC;QACH,CAAC;aAAM,CAAC;YACP,OAAO,0BAA0B,CAChC,UAAU,EACV,0BAA0B,EAC1B,mBAAmB,CAAC,YAAY,CAAC,EACjC,KAAK,CACL,CAAC;QACH,CAAC;IACF,CAAC,CAAC,CAAC;AACJ,CAAC;AAlED,4CAkEC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert } from \"@fluidframework/core-utils/internal\";\n\nimport type { ICodecFamily, ICodecOptions } from \"../codec/index.js\";\nimport {\n\ttype ChangeEncodingContext,\n\ttype ChangeFamily,\n\ttype ChangeRebaser,\n\ttype DeltaDetachedNodeId,\n\ttype RevisionMetadataSource,\n\ttype RevisionTag,\n\ttype RevisionTagCodec,\n\ttype TaggedChange,\n\tmapTaggedChange,\n} from \"../core/index.js\";\nimport {\n\ttype FieldBatchCodec,\n\tModularChangeFamily,\n\ttype ModularChangeset,\n\ttype TreeChunk,\n\ttype TreeCompressionStrategy,\n\tfieldKindConfigurations,\n\tfieldKinds,\n\tmakeModularChangeCodecFamily,\n} from \"../feature-libraries/index.js\";\nimport {\n\ttype Mutable,\n\ttype NestedSet,\n\taddToNestedSet,\n\tfail,\n\thasSingle,\n\tnestedSetContains,\n} from \"../util/index.js\";\n\nimport { makeSharedTreeChangeCodecFamily } from \"./sharedTreeChangeCodecs.js\";\nimport type { SharedTreeChange } from \"./sharedTreeChangeTypes.js\";\nimport { SharedTreeEditBuilder } from \"./sharedTreeEditBuilder.js\";\nimport type { IIdCompressor } from \"@fluidframework/id-compressor\";\n\n/**\n * Implementation of {@link ChangeFamily} that combines edits to fields and schema changes.\n *\n * @sealed\n */\nexport class SharedTreeChangeFamily\n\timplements\n\t\tChangeFamily<SharedTreeEditBuilder, SharedTreeChange>,\n\t\tChangeRebaser<SharedTreeChange>\n{\n\tpublic static readonly emptyChange: SharedTreeChange = {\n\t\tchanges: [],\n\t};\n\n\tpublic readonly codecs: ICodecFamily<SharedTreeChange, ChangeEncodingContext>;\n\tprivate readonly modularChangeFamily: ModularChangeFamily;\n\n\tpublic constructor(\n\t\trevisionTagCodec: RevisionTagCodec,\n\t\tfieldBatchCodec: FieldBatchCodec,\n\t\tcodecOptions: ICodecOptions,\n\t\tchunkCompressionStrategy?: TreeCompressionStrategy,\n\t\tprivate readonly idCompressor?: IIdCompressor,\n\t) {\n\t\tconst modularChangeCodec = makeModularChangeCodecFamily(\n\t\t\tfieldKindConfigurations,\n\t\t\trevisionTagCodec,\n\t\t\tfieldBatchCodec,\n\t\t\tcodecOptions,\n\t\t\tchunkCompressionStrategy,\n\t\t);\n\t\tthis.modularChangeFamily = new ModularChangeFamily(fieldKinds, modularChangeCodec);\n\t\tthis.codecs = makeSharedTreeChangeCodecFamily(\n\t\t\tthis.modularChangeFamily.codecs,\n\t\t\tcodecOptions,\n\t\t);\n\t}\n\n\tpublic buildEditor(\n\t\tmintRevisionTag: () => RevisionTag,\n\t\tchangeReceiver: (change: TaggedChange<SharedTreeChange>) => void,\n\t): SharedTreeEditBuilder {\n\t\treturn new SharedTreeEditBuilder(\n\t\t\tthis.modularChangeFamily,\n\t\t\tmintRevisionTag,\n\t\t\tchangeReceiver,\n\t\t\tthis.idCompressor,\n\t\t);\n\t}\n\n\tpublic compose(changes: TaggedChange<SharedTreeChange>[]): SharedTreeChange {\n\t\tconst newChanges: Mutable<SharedTreeChange[\"changes\"]> = [];\n\t\tconst dataChangeRun: TaggedChange<ModularChangeset>[] = [];\n\n\t\tconst flushDataChangeRun = (): void => {\n\t\t\tif (dataChangeRun.length > 0) {\n\t\t\t\tnewChanges.push({\n\t\t\t\t\ttype: \"data\",\n\t\t\t\t\tinnerChange: this.modularChangeFamily.compose(dataChangeRun),\n\t\t\t\t});\n\t\t\t\tdataChangeRun.length = 0;\n\t\t\t}\n\t\t};\n\n\t\tfor (const topChange of changes) {\n\t\t\tfor (const change of topChange.change.changes) {\n\t\t\t\tif (change.type === \"schema\") {\n\t\t\t\t\tflushDataChangeRun();\n\t\t\t\t\tnewChanges.push(change);\n\t\t\t\t} else {\n\t\t\t\t\tdataChangeRun.push(mapTaggedChange(topChange, change.innerChange));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tflushDataChangeRun();\n\t\treturn { changes: newChanges };\n\t}\n\n\tpublic invert(\n\t\tchange: TaggedChange<SharedTreeChange>,\n\t\tisRollback: boolean,\n\t\trevision: RevisionTag,\n\t): SharedTreeChange {\n\t\tconst invertInnerChange: (\n\t\t\tinnerChange: SharedTreeChange[\"changes\"][number],\n\t\t) => SharedTreeChange[\"changes\"][number] = (innerChange) => {\n\t\t\tswitch (innerChange.type) {\n\t\t\t\tcase \"data\":\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"data\",\n\t\t\t\t\t\tinnerChange: this.modularChangeFamily.invert(\n\t\t\t\t\t\t\tmapTaggedChange(change, innerChange.innerChange),\n\t\t\t\t\t\t\tisRollback,\n\t\t\t\t\t\t\trevision,\n\t\t\t\t\t\t),\n\t\t\t\t\t};\n\t\t\t\tcase \"schema\": {\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttype: \"schema\",\n\t\t\t\t\t\tinnerChange: {\n\t\t\t\t\t\t\tschema: {\n\t\t\t\t\t\t\t\tnew: innerChange.innerChange.schema.old,\n\t\t\t\t\t\t\t\told: innerChange.innerChange.schema.new,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tisInverse: true,\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t}\n\t\t\t\tdefault:\n\t\t\t\t\tfail(\"Unknown SharedTree change type.\");\n\t\t\t}\n\t\t};\n\t\treturn {\n\t\t\tchanges: change.change.changes.map(invertInnerChange).reverse(),\n\t\t};\n\t}\n\n\tpublic rebase(\n\t\tchange: TaggedChange<SharedTreeChange>,\n\t\tover: TaggedChange<SharedTreeChange>,\n\t\trevisionMetadata: RevisionMetadataSource,\n\t): SharedTreeChange {\n\t\tif (change.change.changes.length === 0 || over.change.changes.length === 0) {\n\t\t\treturn change.change;\n\t\t}\n\n\t\tif (hasSchemaChange(change.change) || hasSchemaChange(over.change)) {\n\t\t\t// Any SharedTreeChange (a list of sub-changes) that contains a schema change will cause ANY change that rebases over it to conflict.\n\t\t\t// Similarly, any SharedTreeChange containing a schema change will fail to rebase over ANY change.\n\t\t\t// Those two combine to mean: no concurrency with schema changes is supported.\n\t\t\t// This is fine because it's an open problem. Example: a tree with an A at the root and a schema that allows an A | B at the root will\n\t\t\t// become out of schema if a schema changes to restrict root types to just A is concurrent with a data change that sets it to a B.\n\t\t\t// We don't have an efficient way to detect this document-wide and there are varying opinions on restricting schema changes to prevent this.\n\t\t\t// A SharedTreeChange containing a schema change will NOT conflict in a non-concurrency case, as the \"meatless sandwich\" optimization\n\t\t\t// will result in rebase never being called.\n\t\t\treturn SharedTreeChangeFamily.emptyChange;\n\t\t}\n\t\tassert(\n\t\t\thasSingle(change.change.changes) && hasSingle(over.change.changes),\n\t\t\t0x884 /* SharedTreeChange should have exactly one inner change if no schema change is present. */,\n\t\t);\n\n\t\tconst dataChangeIntention = change.change.changes[0];\n\t\tconst dataChangeOver = over.change.changes[0];\n\t\tassert(\n\t\t\tdataChangeIntention.type === \"data\" && dataChangeOver.type === \"data\",\n\t\t\t0x885 /* Data change should be present. */,\n\t\t);\n\n\t\treturn {\n\t\t\tchanges: [\n\t\t\t\t{\n\t\t\t\t\ttype: \"data\",\n\t\t\t\t\tinnerChange: this.modularChangeFamily.rebase(\n\t\t\t\t\t\tmapTaggedChange(change, dataChangeIntention.innerChange),\n\t\t\t\t\t\tmapTaggedChange(over, dataChangeOver.innerChange),\n\t\t\t\t\t\trevisionMetadata,\n\t\t\t\t\t),\n\t\t\t\t},\n\t\t\t],\n\t\t};\n\t}\n\n\tpublic changeRevision(\n\t\tchange: SharedTreeChange,\n\t\tnewRevision: RevisionTag | undefined,\n\t\trollbackOf?: RevisionTag,\n\t): SharedTreeChange {\n\t\treturn {\n\t\t\tchanges: change.changes.map((inner) => {\n\t\t\t\treturn inner.type === \"data\"\n\t\t\t\t\t? {\n\t\t\t\t\t\t\t...inner,\n\t\t\t\t\t\t\tinnerChange: this.modularChangeFamily.rebaser.changeRevision(\n\t\t\t\t\t\t\t\tinner.innerChange,\n\t\t\t\t\t\t\t\tnewRevision,\n\t\t\t\t\t\t\t\trollbackOf,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t}\n\t\t\t\t\t: inner;\n\t\t\t}),\n\t\t};\n\t}\n\n\tpublic get rebaser(): ChangeRebaser<SharedTreeChange> {\n\t\treturn this;\n\t}\n}\n\nexport function hasSchemaChange(change: SharedTreeChange): boolean {\n\treturn change.changes.some((innerChange) => innerChange.type === \"schema\");\n}\n\nfunction mapDataChanges(\n\tchange: SharedTreeChange,\n\tmap: (change: ModularChangeset) => ModularChangeset,\n): SharedTreeChange {\n\treturn {\n\t\tchanges: change.changes.map((dataOrSchemaChange) => {\n\t\t\tif (dataOrSchemaChange.type === \"data\") {\n\t\t\t\treturn {\n\t\t\t\t\ttype: \"data\",\n\t\t\t\t\tinnerChange: map(dataOrSchemaChange.innerChange),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn dataOrSchemaChange;\n\t\t}),\n\t};\n}\n\n/**\n * Produces an equivalent change with an updated set of appropriate refreshers.\n * @param change - The change to compute refreshers for. Not mutated.\n * @param getDetachedNode - retrieves a {@link TreeChunk} for the corresponding detached node id.\n * Is expected to read from a forest in a state that corresponds to the input context of the given change.\n * @returns An equivalent change with an updated set of appropriate refreshers.\n */\nexport function updateRefreshers(\n\tchange: SharedTreeChange,\n\tgetDetachedNode: (id: DeltaDetachedNodeId) => TreeChunk | undefined,\n\trelevantRemovedRootsFromDataChange: (\n\t\ttaggedChange: ModularChangeset,\n\t) => Iterable<DeltaDetachedNodeId>,\n\tupdateDataChangeRefreshers: (\n\t\tchange: ModularChangeset,\n\t\tgetDetachedNode: (id: DeltaDetachedNodeId) => TreeChunk | undefined,\n\t\tremovedRoots: Iterable<DeltaDetachedNodeId>,\n\t\trequireRefreshers: boolean,\n\t) => ModularChangeset,\n): SharedTreeChange {\n\t// Adding refreshers to a SharedTreeChange is not as simple as adding refreshers to each of its data changes.\n\t// This is because earlier data changes affect the state of the forest in ways that can influence the refreshers\n\t// needed for later data changes. This can happen in two ways:\n\t// 1. By removing a tree that is a relevant root to a later data change.\n\t// 2. By changing the contents of a tree that is a relevant root to a later data change.\n\t// (Note that these two cases can compound)\n\t// Thankfully, in both of these cases, refreshers can be omitted from the later data changes because the forest\n\t// applying those data changes is guaranteed to still have have the relevant trees in memory.\n\t// This means that for the first data change, all required refreshers should be added (and none should be missing).\n\t// While for later data changes, we should not include refreshers that either:\n\t// A) were already included in the earlier data changes\n\t// B) correspond to trees that were removed by earlier data changes\n\t// Set A is excluded by tracking which roots have already been included in the earlier data changes, and filtering\n\t// them out from the relevant removed roots.\n\t// Set B is excluded because the `getDetachedNode` is bound to return `undefined` for them, which tell\n\t// `defaultUpdateRefreshers` to ignore. One downside of this approach is that it prevents `defaultUpdateRefreshers`\n\t// from detecting cases where a detached node is missing for another reason (which would be a bug).\n\n\t// The roots that have been included as refreshers across all data changes so far.\n\tconst includedRoots: NestedSet<RevisionTag | undefined, number> = new Map();\n\tfunction getAndRememberDetachedNode(id: DeltaDetachedNodeId): TreeChunk | undefined {\n\t\taddToNestedSet(includedRoots, id.major, id.minor);\n\t\treturn getDetachedNode(id);\n\t}\n\tfunction* filterIncludedRoots(\n\t\ttoFilter: Iterable<DeltaDetachedNodeId>,\n\t): Iterable<DeltaDetachedNodeId> {\n\t\tfor (const id of toFilter) {\n\t\t\tif (!nestedSetContains(includedRoots, id.major, id.minor)) {\n\t\t\t\tyield id;\n\t\t\t}\n\t\t}\n\t}\n\tlet isFirstDataChange = true;\n\treturn mapDataChanges(change, (dataChange) => {\n\t\tconst removedRoots = relevantRemovedRootsFromDataChange(dataChange);\n\t\tif (isFirstDataChange) {\n\t\t\tisFirstDataChange = false;\n\t\t\treturn updateDataChangeRefreshers(\n\t\t\t\tdataChange,\n\t\t\t\tgetAndRememberDetachedNode,\n\t\t\t\tremovedRoots,\n\t\t\t\ttrue,\n\t\t\t);\n\t\t} else {\n\t\t\treturn updateDataChangeRefreshers(\n\t\t\t\tdataChange,\n\t\t\t\tgetAndRememberDetachedNode,\n\t\t\t\tfilterIncludedRoots(removedRoots),\n\t\t\t\tfalse,\n\t\t\t);\n\t\t}\n\t});\n}\n"]}