@fluidframework/tree 2.63.0-359734 → 2.63.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 (328) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/api-report/tree.alpha.api.md +42 -8
  3. package/dist/alpha.d.ts +7 -0
  4. package/dist/codec/codec.d.ts +10 -27
  5. package/dist/codec/codec.d.ts.map +1 -1
  6. package/dist/codec/codec.js +9 -28
  7. package/dist/codec/codec.js.map +1 -1
  8. package/dist/codec/versioned/codec.d.ts +6 -5
  9. package/dist/codec/versioned/codec.d.ts.map +1 -1
  10. package/dist/codec/versioned/codec.js +4 -4
  11. package/dist/codec/versioned/codec.js.map +1 -1
  12. package/dist/core/tree/detachedFieldIndex.js +1 -1
  13. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  14. package/dist/core/tree/detachedFieldIndexCodecs.js +1 -1
  15. package/dist/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  16. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts +67 -13
  17. package/dist/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  18. package/dist/feature-libraries/chunked-forest/chunkTree.js +70 -35
  19. package/dist/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  20. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +9 -8
  21. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  22. package/dist/feature-libraries/chunked-forest/codec/codecs.js +2 -2
  23. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  24. package/dist/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.d.ts +23 -0
  25. package/dist/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.d.ts.map +1 -0
  26. package/dist/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.js +15 -0
  27. package/dist/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.js.map +1 -0
  28. package/dist/feature-libraries/chunked-forest/codec/index.d.ts +1 -0
  29. package/dist/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
  30. package/dist/feature-libraries/chunked-forest/codec/index.js +3 -1
  31. package/dist/feature-libraries/chunked-forest/codec/index.js.map +1 -1
  32. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +3 -2
  34. package/dist/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  35. package/dist/feature-libraries/chunked-forest/index.d.ts +1 -1
  36. package/dist/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  37. package/dist/feature-libraries/chunked-forest/index.js +2 -1
  38. package/dist/feature-libraries/chunked-forest/index.js.map +1 -1
  39. package/dist/feature-libraries/default-schema/defaultFieldKinds.js +1 -1
  40. package/dist/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  41. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +1 -1
  42. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  43. package/dist/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  44. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts +3 -3
  45. package/dist/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  46. package/dist/feature-libraries/forest-summary/forestSummarizer.js +3 -3
  47. package/dist/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  48. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +4 -11
  49. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  50. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js +2 -6
  51. package/dist/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  52. package/dist/feature-libraries/index.d.ts +1 -1
  53. package/dist/feature-libraries/index.d.ts.map +1 -1
  54. package/dist/feature-libraries/index.js +2 -1
  55. package/dist/feature-libraries/index.js.map +1 -1
  56. package/dist/feature-libraries/schema-index/codec.d.ts +6 -5
  57. package/dist/feature-libraries/schema-index/codec.d.ts.map +1 -1
  58. package/dist/feature-libraries/schema-index/codec.js +3 -3
  59. package/dist/feature-libraries/schema-index/codec.js.map +1 -1
  60. package/dist/index.d.ts +1 -1
  61. package/dist/index.d.ts.map +1 -1
  62. package/dist/index.js.map +1 -1
  63. package/dist/packageVersion.d.ts +1 -1
  64. package/dist/packageVersion.d.ts.map +1 -1
  65. package/dist/packageVersion.js +1 -1
  66. package/dist/packageVersion.js.map +1 -1
  67. package/dist/shared-tree/independentView.d.ts.map +1 -1
  68. package/dist/shared-tree/independentView.js +2 -2
  69. package/dist/shared-tree/independentView.js.map +1 -1
  70. package/dist/shared-tree/schematizingTreeView.d.ts +5 -0
  71. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  72. package/dist/shared-tree/schematizingTreeView.js +37 -7
  73. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  74. package/dist/shared-tree/sharedTree.d.ts +6 -8
  75. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  76. package/dist/shared-tree/sharedTree.js +7 -9
  77. package/dist/shared-tree/sharedTree.js.map +1 -1
  78. package/dist/shared-tree/sharedTreeChangeCodecs.js +1 -1
  79. package/dist/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  80. package/dist/shared-tree/tree.js +1 -1
  81. package/dist/shared-tree/tree.js.map +1 -1
  82. package/dist/shared-tree/treeAlpha.d.ts +1 -1
  83. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  84. package/dist/shared-tree/treeAlpha.js +3 -3
  85. package/dist/shared-tree/treeAlpha.js.map +1 -1
  86. package/dist/shared-tree/treeCheckout.js +1 -1
  87. package/dist/shared-tree/treeCheckout.js.map +1 -1
  88. package/dist/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  89. package/dist/shared-tree-core/defaultResubmitMachine.js +3 -2
  90. package/dist/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  91. package/dist/simple-tree/api/index.d.ts +1 -1
  92. package/dist/simple-tree/api/index.d.ts.map +1 -1
  93. package/dist/simple-tree/api/index.js.map +1 -1
  94. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +37 -2
  95. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  96. package/dist/simple-tree/api/schemaFactoryAlpha.js +34 -14
  97. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  98. package/dist/simple-tree/api/schemaStatics.js +3 -0
  99. package/dist/simple-tree/api/schemaStatics.js.map +1 -1
  100. package/dist/simple-tree/api/storedSchema.d.ts +4 -3
  101. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  102. package/dist/simple-tree/api/storedSchema.js +3 -3
  103. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  104. package/dist/simple-tree/api/treeBeta.js +2 -2
  105. package/dist/simple-tree/api/treeBeta.js.map +1 -1
  106. package/dist/simple-tree/api/treeNodeApi.js +3 -3
  107. package/dist/simple-tree/api/treeNodeApi.js.map +1 -1
  108. package/dist/simple-tree/api/typesUnsafe.d.ts +60 -1
  109. package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  110. package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
  111. package/dist/simple-tree/core/allowedTypes.d.ts.map +1 -1
  112. package/dist/simple-tree/core/allowedTypes.js +1 -1
  113. package/dist/simple-tree/core/allowedTypes.js.map +1 -1
  114. package/dist/simple-tree/core/index.d.ts +1 -1
  115. package/dist/simple-tree/core/index.d.ts.map +1 -1
  116. package/dist/simple-tree/core/index.js +2 -2
  117. package/dist/simple-tree/core/index.js.map +1 -1
  118. package/dist/simple-tree/core/treeNodeKernel.d.ts +7 -11
  119. package/dist/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  120. package/dist/simple-tree/core/treeNodeKernel.js +24 -47
  121. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  122. package/dist/simple-tree/getTreeNodeForField.js +1 -1
  123. package/dist/simple-tree/getTreeNodeForField.js.map +1 -1
  124. package/dist/simple-tree/index.d.ts +2 -2
  125. package/dist/simple-tree/index.d.ts.map +1 -1
  126. package/dist/simple-tree/index.js +2 -2
  127. package/dist/simple-tree/index.js.map +1 -1
  128. package/dist/simple-tree/node-kinds/array/arrayNode.js +2 -2
  129. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  130. package/dist/simple-tree/node-kinds/map/mapNode.js +2 -2
  131. package/dist/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  132. package/dist/simple-tree/node-kinds/object/objectNode.js +3 -3
  133. package/dist/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  134. package/dist/simple-tree/node-kinds/record/recordNode.js +6 -6
  135. package/dist/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  136. package/dist/simple-tree/prepareForInsertion.d.ts +36 -4
  137. package/dist/simple-tree/prepareForInsertion.d.ts.map +1 -1
  138. package/dist/simple-tree/prepareForInsertion.js +43 -15
  139. package/dist/simple-tree/prepareForInsertion.js.map +1 -1
  140. package/dist/treeFactory.d.ts.map +1 -1
  141. package/dist/treeFactory.js +13 -4
  142. package/dist/treeFactory.js.map +1 -1
  143. package/lib/alpha.d.ts +7 -0
  144. package/lib/codec/codec.d.ts +10 -27
  145. package/lib/codec/codec.d.ts.map +1 -1
  146. package/lib/codec/codec.js +8 -27
  147. package/lib/codec/codec.js.map +1 -1
  148. package/lib/codec/versioned/codec.d.ts +6 -5
  149. package/lib/codec/versioned/codec.d.ts.map +1 -1
  150. package/lib/codec/versioned/codec.js +4 -4
  151. package/lib/codec/versioned/codec.js.map +1 -1
  152. package/lib/core/tree/detachedFieldIndex.js +1 -1
  153. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  154. package/lib/core/tree/detachedFieldIndexCodecs.js +1 -1
  155. package/lib/core/tree/detachedFieldIndexCodecs.js.map +1 -1
  156. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts +67 -13
  157. package/lib/feature-libraries/chunked-forest/chunkTree.d.ts.map +1 -1
  158. package/lib/feature-libraries/chunked-forest/chunkTree.js +68 -32
  159. package/lib/feature-libraries/chunked-forest/chunkTree.js.map +1 -1
  160. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +9 -8
  161. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  162. package/lib/feature-libraries/chunked-forest/codec/codecs.js +2 -2
  163. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  164. package/lib/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.d.ts +23 -0
  165. package/lib/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.d.ts.map +1 -0
  166. package/lib/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.js +11 -0
  167. package/lib/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.js.map +1 -0
  168. package/lib/feature-libraries/chunked-forest/codec/index.d.ts +1 -0
  169. package/lib/feature-libraries/chunked-forest/codec/index.d.ts.map +1 -1
  170. package/lib/feature-libraries/chunked-forest/codec/index.js +1 -0
  171. package/lib/feature-libraries/chunked-forest/codec/index.js.map +1 -1
  172. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.d.ts.map +1 -1
  173. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js +3 -2
  174. package/lib/feature-libraries/chunked-forest/codec/schemaBasedEncode.js.map +1 -1
  175. package/lib/feature-libraries/chunked-forest/index.d.ts +1 -1
  176. package/lib/feature-libraries/chunked-forest/index.d.ts.map +1 -1
  177. package/lib/feature-libraries/chunked-forest/index.js +1 -1
  178. package/lib/feature-libraries/chunked-forest/index.js.map +1 -1
  179. package/lib/feature-libraries/default-schema/defaultFieldKinds.js +1 -1
  180. package/lib/feature-libraries/default-schema/defaultFieldKinds.js.map +1 -1
  181. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +1 -1
  182. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  183. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  184. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts +3 -3
  185. package/lib/feature-libraries/forest-summary/forestSummarizer.d.ts.map +1 -1
  186. package/lib/feature-libraries/forest-summary/forestSummarizer.js +3 -3
  187. package/lib/feature-libraries/forest-summary/forestSummarizer.js.map +1 -1
  188. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts +4 -11
  189. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.d.ts.map +1 -1
  190. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js +2 -6
  191. package/lib/feature-libraries/forest-summary/incrementalSummaryBuilder.js.map +1 -1
  192. package/lib/feature-libraries/index.d.ts +1 -1
  193. package/lib/feature-libraries/index.d.ts.map +1 -1
  194. package/lib/feature-libraries/index.js +1 -1
  195. package/lib/feature-libraries/index.js.map +1 -1
  196. package/lib/feature-libraries/schema-index/codec.d.ts +6 -5
  197. package/lib/feature-libraries/schema-index/codec.d.ts.map +1 -1
  198. package/lib/feature-libraries/schema-index/codec.js +3 -3
  199. package/lib/feature-libraries/schema-index/codec.js.map +1 -1
  200. package/lib/index.d.ts +1 -1
  201. package/lib/index.d.ts.map +1 -1
  202. package/lib/index.js.map +1 -1
  203. package/lib/packageVersion.d.ts +1 -1
  204. package/lib/packageVersion.d.ts.map +1 -1
  205. package/lib/packageVersion.js +1 -1
  206. package/lib/packageVersion.js.map +1 -1
  207. package/lib/shared-tree/independentView.d.ts.map +1 -1
  208. package/lib/shared-tree/independentView.js +3 -3
  209. package/lib/shared-tree/independentView.js.map +1 -1
  210. package/lib/shared-tree/schematizingTreeView.d.ts +5 -0
  211. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  212. package/lib/shared-tree/schematizingTreeView.js +40 -10
  213. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  214. package/lib/shared-tree/sharedTree.d.ts +6 -8
  215. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  216. package/lib/shared-tree/sharedTree.js +8 -10
  217. package/lib/shared-tree/sharedTree.js.map +1 -1
  218. package/lib/shared-tree/sharedTreeChangeCodecs.js +1 -1
  219. package/lib/shared-tree/sharedTreeChangeCodecs.js.map +1 -1
  220. package/lib/shared-tree/tree.js +2 -2
  221. package/lib/shared-tree/tree.js.map +1 -1
  222. package/lib/shared-tree/treeAlpha.d.ts +1 -1
  223. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  224. package/lib/shared-tree/treeAlpha.js +4 -4
  225. package/lib/shared-tree/treeAlpha.js.map +1 -1
  226. package/lib/shared-tree/treeCheckout.js +1 -1
  227. package/lib/shared-tree/treeCheckout.js.map +1 -1
  228. package/lib/shared-tree-core/defaultResubmitMachine.d.ts.map +1 -1
  229. package/lib/shared-tree-core/defaultResubmitMachine.js +3 -2
  230. package/lib/shared-tree-core/defaultResubmitMachine.js.map +1 -1
  231. package/lib/simple-tree/api/index.d.ts +1 -1
  232. package/lib/simple-tree/api/index.d.ts.map +1 -1
  233. package/lib/simple-tree/api/index.js.map +1 -1
  234. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +37 -2
  235. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  236. package/lib/simple-tree/api/schemaFactoryAlpha.js +34 -14
  237. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  238. package/lib/simple-tree/api/schemaStatics.js +3 -0
  239. package/lib/simple-tree/api/schemaStatics.js.map +1 -1
  240. package/lib/simple-tree/api/storedSchema.d.ts +4 -3
  241. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  242. package/lib/simple-tree/api/storedSchema.js +3 -3
  243. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  244. package/lib/simple-tree/api/treeBeta.js +2 -2
  245. package/lib/simple-tree/api/treeBeta.js.map +1 -1
  246. package/lib/simple-tree/api/treeNodeApi.js +4 -4
  247. package/lib/simple-tree/api/treeNodeApi.js.map +1 -1
  248. package/lib/simple-tree/api/typesUnsafe.d.ts +60 -1
  249. package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  250. package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
  251. package/lib/simple-tree/core/allowedTypes.d.ts.map +1 -1
  252. package/lib/simple-tree/core/allowedTypes.js +1 -1
  253. package/lib/simple-tree/core/allowedTypes.js.map +1 -1
  254. package/lib/simple-tree/core/index.d.ts +1 -1
  255. package/lib/simple-tree/core/index.d.ts.map +1 -1
  256. package/lib/simple-tree/core/index.js +1 -1
  257. package/lib/simple-tree/core/index.js.map +1 -1
  258. package/lib/simple-tree/core/treeNodeKernel.d.ts +7 -11
  259. package/lib/simple-tree/core/treeNodeKernel.d.ts.map +1 -1
  260. package/lib/simple-tree/core/treeNodeKernel.js +23 -46
  261. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  262. package/lib/simple-tree/getTreeNodeForField.js +1 -1
  263. package/lib/simple-tree/getTreeNodeForField.js.map +1 -1
  264. package/lib/simple-tree/index.d.ts +2 -2
  265. package/lib/simple-tree/index.d.ts.map +1 -1
  266. package/lib/simple-tree/index.js +1 -1
  267. package/lib/simple-tree/index.js.map +1 -1
  268. package/lib/simple-tree/node-kinds/array/arrayNode.js +3 -3
  269. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  270. package/lib/simple-tree/node-kinds/map/mapNode.js +3 -3
  271. package/lib/simple-tree/node-kinds/map/mapNode.js.map +1 -1
  272. package/lib/simple-tree/node-kinds/object/objectNode.js +4 -4
  273. package/lib/simple-tree/node-kinds/object/objectNode.js.map +1 -1
  274. package/lib/simple-tree/node-kinds/record/recordNode.js +7 -7
  275. package/lib/simple-tree/node-kinds/record/recordNode.js.map +1 -1
  276. package/lib/simple-tree/prepareForInsertion.d.ts +36 -4
  277. package/lib/simple-tree/prepareForInsertion.d.ts.map +1 -1
  278. package/lib/simple-tree/prepareForInsertion.js +45 -17
  279. package/lib/simple-tree/prepareForInsertion.js.map +1 -1
  280. package/lib/treeFactory.d.ts.map +1 -1
  281. package/lib/treeFactory.js +13 -4
  282. package/lib/treeFactory.js.map +1 -1
  283. package/package.json +21 -20
  284. package/src/codec/codec.ts +11 -29
  285. package/src/codec/versioned/codec.ts +6 -6
  286. package/src/core/tree/detachedFieldIndex.ts +1 -1
  287. package/src/core/tree/detachedFieldIndexCodecs.ts +1 -1
  288. package/src/feature-libraries/chunked-forest/chunkTree.ts +112 -45
  289. package/src/feature-libraries/chunked-forest/codec/codecs.ts +7 -12
  290. package/src/feature-libraries/chunked-forest/codec/incrementalEncodingPolicy.ts +33 -0
  291. package/src/feature-libraries/chunked-forest/codec/index.ts +4 -0
  292. package/src/feature-libraries/chunked-forest/codec/schemaBasedEncode.ts +4 -7
  293. package/src/feature-libraries/chunked-forest/index.ts +2 -0
  294. package/src/feature-libraries/default-schema/defaultFieldKinds.ts +1 -1
  295. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +1 -1
  296. package/src/feature-libraries/forest-summary/forestSummarizer.ts +8 -12
  297. package/src/feature-libraries/forest-summary/incrementalSummaryBuilder.ts +3 -12
  298. package/src/feature-libraries/index.ts +2 -0
  299. package/src/feature-libraries/schema-index/codec.ts +5 -5
  300. package/src/index.ts +7 -0
  301. package/src/packageVersion.ts +1 -1
  302. package/src/shared-tree/independentView.ts +3 -0
  303. package/src/shared-tree/schematizingTreeView.ts +63 -8
  304. package/src/shared-tree/sharedTree.ts +34 -21
  305. package/src/shared-tree/sharedTreeChangeCodecs.ts +1 -1
  306. package/src/shared-tree/tree.ts +2 -2
  307. package/src/shared-tree/treeAlpha.ts +6 -12
  308. package/src/shared-tree/treeCheckout.ts +1 -1
  309. package/src/shared-tree-core/defaultResubmitMachine.ts +3 -2
  310. package/src/simple-tree/api/index.ts +7 -0
  311. package/src/simple-tree/api/schemaFactoryAlpha.ts +79 -19
  312. package/src/simple-tree/api/schemaStatics.ts +3 -0
  313. package/src/simple-tree/api/storedSchema.ts +5 -4
  314. package/src/simple-tree/api/treeBeta.ts +2 -2
  315. package/src/simple-tree/api/treeNodeApi.ts +4 -4
  316. package/src/simple-tree/api/typesUnsafe.ts +81 -0
  317. package/src/simple-tree/core/TreeNodeBinding.md +14 -70
  318. package/src/simple-tree/core/allowedTypes.ts +4 -1
  319. package/src/simple-tree/core/index.ts +1 -1
  320. package/src/simple-tree/core/treeNodeKernel.ts +25 -59
  321. package/src/simple-tree/getTreeNodeForField.ts +1 -1
  322. package/src/simple-tree/index.ts +8 -1
  323. package/src/simple-tree/node-kinds/array/arrayNode.ts +3 -3
  324. package/src/simple-tree/node-kinds/map/mapNode.ts +3 -3
  325. package/src/simple-tree/node-kinds/object/objectNode.ts +4 -4
  326. package/src/simple-tree/node-kinds/record/recordNode.ts +7 -7
  327. package/src/simple-tree/prepareForInsertion.ts +87 -25
  328. package/src/treeFactory.ts +17 -4
@@ -1 +1 @@
1
- {"version":3,"file":"prepareForInsertion.js","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAEN,kBAAkB,EAElB,UAAU,EAGV,gBAAgB,GAChB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAEN,gCAAgC,GAChC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACzC,OAAO,EACN,SAAS,GAIT,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,MAAM,qCAAqC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,cAAc,GAAG,IAAI,CAAC;AAE5B;;;;;;;GAOG;AACH,MAAM,UAAU,mBAAmB,CAClC,IAAS,EACT,MAA2B,EAC3B,kBAAmC,EACnC,iBAAwC;IAExC,OAAO,8BAA8B,CACpC,IAAI,EACJ,MAAM,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EAAE,EAAE;YAClE,kIAAkI;YAClI,MAAM,KAAK,GAAG,YAAY,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC;YACvC,WAAW,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,KAAK,cAAc,CAAC,CAAC;YACjE,KAAK,CAAC,QAAQ,CAAC,WAAW,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC;YAC7C,KAAK,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;gBAC1C,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;YAC/C,CAAC;YACD,IAAI,EAAE,CAAC,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;gBACjC,GAAG,EAAE,CAAC;YACP,CAAC;QACF,CAAC,CAAC,CAAC;IACJ,CAAC;AACF,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tSchemaAndPolicy,\n\tIForestSubscription,\n\tUpPath,\n\tNodeIndex,\n\tFieldKey,\n\tDetachedField,\n\tTreeFieldStoredSchema,\n\tTreeTypeSet,\n} from \"../core/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tgetSchemaAndPolicy,\n\ttype FlexTreeHydratedContextMinimal,\n\tFieldKinds,\n\ttype FlexibleFieldContent,\n\ttype FlexibleNodeContent,\n\tthrowOutOfSchema,\n} from \"../feature-libraries/index.js\";\nimport type { ImplicitFieldSchema } from \"./fieldSchema.js\";\nimport {\n\ttype InsertableContent,\n\tunhydratedFlexTreeFromInsertable,\n} from \"./unhydratedFlexTreeFromInsertable.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { brand } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype ImplicitAllowedTypes,\n\ttype TreeNode,\n\ttype UnhydratedFlexTreeNode,\n} from \"./core/index.js\";\nimport { debugAssert, oob } from \"@fluidframework/core-utils/internal\";\nimport { isFieldInSchema } from \"../feature-libraries/index.js\";\n\n/**\n * For now, schema validation for inserted content is always enabled.\n * @remarks\n * If this ends up being too much of a performance overhead, AND nothing depends on it (like staged allowed types likely will),\n * this could be changed.\n */\nconst validateSchema = true;\n\n/**\n * Prepare content from a user for insertion into a tree.\n * @remarks\n * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.\n *\n * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,\n * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.\n */\nexport function prepareForInsertion<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tdestinationContext: FlexTreeContext,\n\tdestinationSchema: TreeFieldStoredSchema,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\treturn prepareForInsertionContextless(\n\t\tdata,\n\t\tschema,\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\tdestinationSchema,\n\t);\n}\n\n/**\n * {@link prepareForInsertion} but batched for array content.\n * @remarks\n * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).\n *\n * The next edits made to `destinationContext`'s forest must be the creation of a detached field.\n * One edit for each item in `data`, in order.\n *\n * @privateRemarks\n * This has to be done as a single operation for all items in data\n * (as opposed to mapping {@link prepareForInsertion} over the array)\n * due to how the eventing in prepareContentForHydration works.\n */\nexport function prepareArrayContentForInsertion(\n\tdata: readonly InsertableContent[],\n\tschema: ImplicitAllowedTypes,\n\tdestinationContext: FlexTreeContext,\n\tdestinationSchema: TreeTypeSet,\n): FlexibleFieldContent {\n\tconst mapTrees: UnhydratedFlexTreeNode[] = data.map((item) =>\n\t\tunhydratedFlexTreeFromInsertable(item, schema),\n\t);\n\n\tvalidateAndPrepare(\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\t{\n\t\t\tkind: FieldKinds.sequence.identifier,\n\t\t\ttypes: destinationSchema,\n\t\t\tpersistedMetadata: undefined,\n\t\t},\n\t\tmapTrees,\n\t);\n\n\treturn mapTrees;\n}\n\n/**\n * Split out from {@link prepareForInsertion} as to allow use without a context.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n *\n * @remarks\n * Adding this entry point is a workaround for initialize not currently having a context.\n */\nexport function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tdestinationSchema: TreeFieldStoredSchema,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\tconst mapTree = unhydratedFlexTreeFromInsertable(data, schema);\n\n\tconst contentArray = mapTree === undefined ? [] : [mapTree];\n\tvalidateAndPrepare(schemaAndPolicy, hydratedData, destinationSchema, contentArray);\n\n\treturn mapTree;\n}\n\n/**\n * If hydrating, do a final validation against the schema and prepare the content for hydration.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n */\nfunction validateAndPrepare(\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tfieldSchema: TreeFieldStoredSchema,\n\tmapTrees: readonly UnhydratedFlexTreeNode[],\n): void {\n\tif (hydratedData !== undefined) {\n\t\t// Run `prepareContentForHydration` before walking the tree in `isFieldInSchema`.\n\t\t// This ensures that when `isFieldInSchema` requests identifiers (or any other contextual defaults),\n\t\t// they were already creating used the more specific context we have access to from `hydratedData`.\n\t\tprepareContentForHydration(mapTrees, hydratedData.checkout.forest, hydratedData);\n\t\t// TODO: AB#45723\n\t\t// Now that staged schema rely on this validation, its a bit odd we don't do it for insertion into unhydrated contexts.\n\t\t// We can't simply enable it for them however due to contextual default fields which would not have been created yet (see comment above).\n\t\t// Specifically at least clone can result in unhydrated trees which can end up violating their stored schema (but not view schema) just using the type safe APIs.\n\t\tif (validateSchema === true) {\n\t\t\tisFieldInSchema(mapTrees, fieldSchema, schemaAndPolicy, throwOutOfSchema);\n\t\t}\n\t}\n}\n\n/**\n * An {@link UpPath} that is just index zero in a {@link DetachedField} which can be modified at a later time.\n */\ninterface Root extends UpPath {\n\treadonly parent: undefined;\n\tparentField: DetachedField & FieldKey;\n\treadonly parentIndex: NodeIndex & 0;\n}\n\n/**\n * The path from the included node to the root of the content tree it was inserted as part of.\n */\ninterface RelativeNodePath {\n\treadonly path: UpPath;\n\treadonly node: TreeNode;\n}\n\n/**\n * {@link RelativeNodePath}s for every {@link TreeNode} in the content tree inserted as an atomic operation.\n */\ninterface LocatedNodesBatch {\n\t/**\n\t * UpPath shared by all {@link RelativeNodePath}s in this batch corresponding to the root of the inserted content.\n\t */\n\treadonly rootPath: Root;\n\treadonly paths: RelativeNodePath[];\n}\n\n/**\n * A dummy key value used in {@link LocatedNodesBatch.rootPath} which will be replaced with the actual detached field once it is known.\n */\nconst placeholderKey: DetachedField & FieldKey = brand(\"placeholder\" as const);\n\n/**\n * Records any {@link TreeNode}s in the given `content` tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * Additionally populates any {@link UnhydratedFlexTreeField.pendingDefault}s using the provided `context`.\n *\n * @remarks If the content tree contains has any associated {@link TreeNode}s, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n *\n * Exported for testing purposes: otherwise should not be used outside this module.\n * @param content - the content subsequence to be inserted, of which might deeply contain {@link TreeNode}s which need to be hydrated.\n * @param forest - the forest the content is being inserted into.\n */\nexport function prepareContentForHydration(\n\tcontent: readonly UnhydratedFlexTreeNode[],\n\tforest: IForestSubscription,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tconst batches: LocatedNodesBatch[] = [];\n\tfor (const item of content) {\n\t\tconst batch: LocatedNodesBatch = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: placeholderKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tpaths: [],\n\t\t};\n\t\tbatches.push(batch);\n\t\twalkMapTree(\n\t\t\titem,\n\t\t\tbatch.rootPath,\n\t\t\t(p, node) => {\n\t\t\t\tbatch.paths.push({ path: p, node });\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tscheduleHydration(batches, forest);\n}\n\nfunction walkMapTree(\n\troot: UnhydratedFlexTreeNode,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tif (root.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: UnhydratedFlexTreeNode];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, root]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, node] = next;\n\t\tif (node !== undefined) {\n\t\t\tconst treeNode = node.treeNode;\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of node.allFieldsLazy) {\n\t\t\tfield.fillPendingDefaults(context);\n\t\t\tfor (const [i, child] of field.children.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * Register events which will hydrate batches of nodes when they are inserted.\n * The next edits to forest must be their insertions, in order, or data corruption can occur.\n * @param locatedNodes - the nodes to register with the forest.\n * Each index in this array expects its content to be added and produce its own `afterRootFieldCreated` event.\n * If array subsequence insertion is optimized to produce a single event, this will not work correctly as is, and will need to be modified to take in a single {@link LocatedNodesBatch}.\n */\nfunction scheduleHydration(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n): void {\n\t// Only subscribe to the event if there is at least one TreeNode tree to hydrate - this is not the case when inserting an empty array [].\n\tif (locatedNodes.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet i = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Indexing is safe here because of the length check above. This assumes the array has not been modified which should be the case.\n\t\t\tconst batch = locatedNodes[i] ?? oob();\n\t\t\tdebugAssert(() => batch.rootPath.parentField === placeholderKey);\n\t\t\tbatch.rootPath.parentField = brand(fieldKey);\n\t\t\tfor (const { path, node } of batch.paths) {\n\t\t\t\tgetKernel(node).hydrate(forest.anchors, path);\n\t\t\t}\n\t\t\tif (++i === locatedNodes.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n"]}
1
+ {"version":3,"file":"prepareForInsertion.js","sourceRoot":"","sources":["../../src/simple-tree/prepareForInsertion.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAWH,OAAO,EAEN,kBAAkB,EAElB,UAAU,EAGV,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,+BAA+B,EAC/B,4BAA4B,GAC5B,MAAM,+BAA+B,CAAC;AAEvC,OAAO,EAEN,gCAAgC,GAChC,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AACtE,OAAO,EAAE,KAAK,EAAgB,MAAM,kBAAkB,CAAC;AACvD,OAAO,EACN,SAAS,GAIT,MAAM,iBAAi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ors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type {\n\tSchemaAndPolicy,\n\tIForestSubscription,\n\tUpPath,\n\tFieldKey,\n\tDetachedField,\n\tTreeFieldStoredSchema,\n\tTreeTypeSet,\n} from \"../core/index.js\";\nimport {\n\ttype FlexTreeContext,\n\tgetSchemaAndPolicy,\n\ttype FlexTreeHydratedContextMinimal,\n\tFieldKinds,\n\ttype FlexibleFieldContent,\n\ttype FlexibleNodeContent,\n\tthrowOutOfSchema,\n\tflexTreeSlot,\n\tContextSlot,\n\tgetOrCreateHydratedFlexTreeNode,\n\tassertFlexTreeEntityNotFreed,\n} from \"../feature-libraries/index.js\";\nimport type { ImplicitFieldSchema } from \"./fieldSchema.js\";\nimport {\n\ttype InsertableContent,\n\tunhydratedFlexTreeFromInsertable,\n} from \"./unhydratedFlexTreeFromInsertable.js\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport { brand, type Mutable } from \"../util/index.js\";\nimport {\n\tgetKernel,\n\ttype ImplicitAllowedTypes,\n\ttype TreeNode,\n\ttype UnhydratedFlexTreeNode,\n} from \"./core/index.js\";\nimport { debugAssert, fail, oob } from \"@fluidframework/core-utils/internal\";\nimport { isFieldInSchema } from \"../feature-libraries/index.js\";\n\n/**\n * For now, schema validation for inserted content is always enabled.\n * @remarks\n * If this ends up being too much of a performance overhead, AND nothing depends on it (like staged allowed types likely will),\n * this could be changed.\n */\nconst validateSchema = true;\n\n/**\n * Prepare content from a user for insertion into a tree.\n * @remarks\n * This validates and converts the input, and if necessary invokes {@link prepareContentForHydration}.\n *\n * The next edit made to `destinationContext`'s forest must be the creation of a detached field containing this content,\n * (Triggering {@link ForestEvents.afterRootFieldCreated}) otherwise hydration will break.\n */\nexport function prepareForInsertion<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tdestinationContext: FlexTreeContext,\n\tdestinationSchema: TreeFieldStoredSchema,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\treturn prepareForInsertionContextless(\n\t\tdata,\n\t\tschema,\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\tdestinationSchema,\n\t);\n}\n\n/**\n * {@link prepareForInsertion} but batched for array content.\n * @remarks\n * This is for inserting items into an array, not a inserting a {@link TreeArrayNode} (that would use {@link prepareForInsertion}).\n *\n * The next edits made to `destinationContext`'s forest must be the creation of a detached field.\n * One edit for each item in `data`, in order.\n *\n * @privateRemarks\n * This has to be done as a single operation for all items in data\n * (as opposed to mapping {@link prepareForInsertion} over the array)\n * due to how the eventing in prepareContentForHydration works.\n */\nexport function prepareArrayContentForInsertion(\n\tdata: readonly InsertableContent[],\n\tschema: ImplicitAllowedTypes,\n\tdestinationContext: FlexTreeContext,\n\tdestinationSchema: TreeTypeSet,\n): FlexibleFieldContent {\n\tconst mapTrees: UnhydratedFlexTreeNode[] = data.map((item) =>\n\t\tunhydratedFlexTreeFromInsertable(item, schema),\n\t);\n\n\tvalidateAndPrepare(\n\t\tgetSchemaAndPolicy(destinationContext),\n\t\tdestinationContext.isHydrated() ? destinationContext : undefined,\n\t\t{\n\t\t\tkind: FieldKinds.sequence.identifier,\n\t\t\ttypes: destinationSchema,\n\t\t\tpersistedMetadata: undefined,\n\t\t},\n\t\tmapTrees,\n\t);\n\n\treturn mapTrees;\n}\n\n/**\n * Split out from {@link prepareForInsertion} as to allow use without a context.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n *\n * @remarks\n * Adding this entry point is a workaround for initialize not currently having a context.\n */\nexport function prepareForInsertionContextless<TIn extends InsertableContent | undefined>(\n\tdata: TIn,\n\tschema: ImplicitFieldSchema,\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tdestinationSchema: TreeFieldStoredSchema,\n\tscheduleHydrationOverride?: HydrationScheduler,\n): TIn extends undefined ? undefined : FlexibleNodeContent {\n\tconst mapTree = unhydratedFlexTreeFromInsertable(data, schema);\n\n\tconst contentArray = mapTree === undefined ? [] : [mapTree];\n\tvalidateAndPrepare(\n\t\tschemaAndPolicy,\n\t\thydratedData,\n\t\tdestinationSchema,\n\t\tcontentArray,\n\t\tscheduleHydrationOverride,\n\t);\n\n\treturn mapTree;\n}\n\n/**\n * If hydrating, do a final validation against the schema and prepare the content for hydration.\n *\n * @param hydratedData - If specified, the `mapTrees` will be prepared for hydration into this context.\n * `undefined` when `mapTrees` are being inserted into an {@link Unhydrated} tree.\n */\nfunction validateAndPrepare(\n\tschemaAndPolicy: SchemaAndPolicy,\n\thydratedData: FlexTreeHydratedContextMinimal | undefined,\n\tfieldSchema: TreeFieldStoredSchema,\n\tmapTrees: readonly UnhydratedFlexTreeNode[],\n\tscheduleHydrationOverride?: HydrationScheduler,\n): void {\n\tif (hydratedData !== undefined) {\n\t\t// Run `prepareContentForHydration` before walking the tree in `isFieldInSchema`.\n\t\t// This ensures that when `isFieldInSchema` requests identifiers (or any other contextual defaults),\n\t\t// they were already creating used the more specific context we have access to from `hydratedData`.\n\t\tprepareContentForHydration(\n\t\t\tmapTrees,\n\t\t\tscheduleHydrationOverride ??\n\t\t\t\t((batch, doHydration) =>\n\t\t\t\t\tscheduleHydration(batch, hydratedData.checkout.forest, doHydration)),\n\t\t\thydratedData,\n\t\t);\n\t\t// TODO: AB#45723\n\t\t// Now that staged schema rely on this validation, its a bit odd we don't do it for insertion into unhydrated contexts.\n\t\t// We can't simply enable it for them however due to contextual default fields which would not have been created yet (see comment above).\n\t\t// Specifically at least clone can result in unhydrated trees which can end up violating their stored schema (but not view schema) just using the type safe APIs.\n\t\tif (validateSchema === true) {\n\t\t\tisFieldInSchema(mapTrees, fieldSchema, schemaAndPolicy, throwOutOfSchema);\n\t\t}\n\t}\n}\n\n/**\n * The path from the included node to the root of the content tree it was inserted as part of.\n */\ninterface RelativeNodePath {\n\treadonly path: UpPath;\n\treadonly node: TreeNode;\n}\n\n/**\n * {@link RelativeNodePath}s for every {@link TreeNode} in the content tree inserted as an atomic operation.\n */\ninterface LocatedNodesBatch {\n\t/**\n\t * UpPath shared by all {@link RelativeNodePath}s in this batch corresponding to the root of the inserted content.\n\t */\n\treadonly rootPath: Mutable<UpPath>;\n\treadonly paths: RelativeNodePath[];\n}\n\n/**\n * A dummy key value used in {@link LocatedNodesBatch.rootPath} which will be replaced with the actual detached field once it is known.\n */\nconst placeholderKey: DetachedField & FieldKey = brand(\"placeholder\" as const);\n\n/**\n * Records any {@link TreeNode}s in the given `content` tree and does the necessary bookkeeping to ensure they are synchronized with subsequent reads of the tree.\n * Additionally populates any {@link UnhydratedFlexTreeField.pendingDefault}s using the provided `context`.\n *\n * @remarks If the content tree contains has any associated {@link TreeNode}s, this function must be called just prior to inserting the content into the tree.\n * Specifically, no other content may be inserted into the tree between the invocation of this function and the insertion of `content`.\n * The insertion of `content` must occur or else this function will cause memory leaks.\n *\n * Exported for testing purposes: otherwise should not be used outside this module.\n * @param content - the content subsequence to be inserted, of which might deeply contain {@link TreeNode}s which need to be hydrated.\n * @param forest - the forest the content is being inserted into.\n */\nexport function prepareContentForHydration(\n\tcontent: readonly UnhydratedFlexTreeNode[],\n\tscheduler: HydrationScheduler,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tconst batches: LocatedNodesBatch[] = [];\n\tfor (const item of content) {\n\t\tconst batch: LocatedNodesBatch = {\n\t\t\trootPath: {\n\t\t\t\tparent: undefined,\n\t\t\t\tparentField: placeholderKey,\n\t\t\t\tparentIndex: 0,\n\t\t\t},\n\t\t\tpaths: [],\n\t\t};\n\t\tbatches.push(batch);\n\t\twalkMapTree(\n\t\t\titem,\n\t\t\tbatch.rootPath,\n\t\t\t(p, node) => {\n\t\t\t\tbatch.paths.push({ path: p, node });\n\t\t\t},\n\t\t\tcontext,\n\t\t);\n\t}\n\n\tconst doHydration = hydrator(batches, context.checkout.forest);\n\tscheduler(batches, doHydration);\n}\n\nfunction walkMapTree(\n\troot: UnhydratedFlexTreeNode,\n\tpath: UpPath,\n\tonVisitTreeNode: (path: UpPath, treeNode: TreeNode) => void,\n\tcontext: FlexTreeHydratedContextMinimal,\n): void {\n\tif (root.parentField.parent.parent !== undefined) {\n\t\tthrow new UsageError(\n\t\t\t\"Attempted to insert a node which is already under a parent. If this is desired, remove the node from its parent before inserting it elsewhere.\",\n\t\t);\n\t}\n\n\ttype Next = [path: UpPath, tree: UnhydratedFlexTreeNode];\n\tconst nexts: Next[] = [];\n\tfor (let next: Next | undefined = [path, root]; next !== undefined; next = nexts.pop()) {\n\t\tconst [p, node] = next;\n\t\tif (node !== undefined) {\n\t\t\tconst treeNode = node.treeNode;\n\t\t\tif (treeNode !== undefined) {\n\t\t\t\tonVisitTreeNode(p, treeNode);\n\t\t\t}\n\t\t}\n\n\t\tfor (const [key, field] of node.allFieldsLazy) {\n\t\t\tfield.fillPendingDefaults(context);\n\t\t\tfor (const [i, child] of field.children.entries()) {\n\t\t\t\tnexts.push([\n\t\t\t\t\t{\n\t\t\t\t\t\tparent: p,\n\t\t\t\t\t\tparentField: key,\n\t\t\t\t\t\tparentIndex: i,\n\t\t\t\t\t},\n\t\t\t\t\tchild,\n\t\t\t\t]);\n\t\t\t}\n\t\t}\n\t}\n}\n\n/**\n * A function which can schedule hydration of batches of nodes to occur at a later time (which must be after they have been inserted into the tree).\n */\ntype HydrationScheduler = (\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\t/**\n\t * Does the actual hydration. Should be called for each index in `locatedNodes` once the corresponding content has been inserted into the tree.\n\t */\n\tdoHydration: Hydrator,\n) => void;\n\n/**\n * Does the actual hydration.\n * The provided `attachPath` is the path the content is currently under (where it was attached in the tree).\n */\ntype Hydrator = (batch: LocatedNodesBatch, attachPath: UpPath) => void;\n\n/**\n * Register events which will hydrate batches of nodes when they are inserted.\n * The next edits to forest must be their insertions, in order, or data corruption can occur.\n * @param locatedNodes - the nodes to register with the forest.\n * Each index in this array expects its content to be added and produce its own `afterRootFieldCreated` event.\n * If array subsequence insertion is optimized to produce a single event, this will not work correctly as is, and will need to be modified to take in a single {@link LocatedNodesBatch}.\n */\nfunction scheduleHydration(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n\tdoHydration: Hydrator,\n): void {\n\t// Only subscribe to the event if there is at least one TreeNode tree to hydrate - this is not the case when inserting an empty array [].\n\tif (locatedNodes.length > 0) {\n\t\t// Creating a new array emits one event per element in the array, so listen to the event once for each element\n\t\tlet index = 0;\n\t\tconst off = forest.events.on(\"afterRootFieldCreated\", (fieldKey) => {\n\t\t\t// Indexing is safe here because of the length check above. This assumes the array has not been modified which should be the case.\n\t\t\tconst batch = locatedNodes[index] ?? oob();\n\t\t\tdoHydration(batch, { parent: undefined, parentField: fieldKey, parentIndex: 0 });\n\t\t\tif (++index === locatedNodes.length) {\n\t\t\t\toff();\n\t\t\t}\n\t\t});\n\t}\n}\n\n/**\n * Implementation of {@link Hydrator}.\n */\nfunction hydrator(\n\tlocatedNodes: readonly LocatedNodesBatch[],\n\tforest: IForestSubscription,\n): (batch: LocatedNodesBatch, attachedPath: UpPath) => void {\n\treturn (batch: LocatedNodesBatch, attachedPath: UpPath) => {\n\t\tconst context = forest.anchors.slots.get(ContextSlot) ?? fail(0xb41 /* missing context */);\n\n\t\t// Modify paths in batch to point to correct location:\n\t\tdebugAssert(() => batch.rootPath.parentField === placeholderKey);\n\t\tbatch.rootPath.parentField = attachedPath.parentField;\n\t\tbatch.rootPath.parent = attachedPath.parent;\n\t\tbatch.rootPath.parentIndex = attachedPath.parentIndex;\n\n\t\t// To hydrate a TreeNode, it must be associated with a HydratedFlexTreeNode.\n\t\t// Find or create one as necessary.\n\t\tfor (const { path, node } of batch.paths) {\n\t\t\tconst anchor = forest.anchors.track(path);\n\t\t\tconst anchorNode = forest.anchors.locate(anchor) ?? fail(0xc7b /* missing anchor */);\n\n\t\t\tlet flexNode = anchorNode.slots.get(flexTreeSlot);\n\t\t\tif (flexNode === undefined) {\n\t\t\t\t// the flex node must be created\n\t\t\t\tconst cursor = forest.allocateCursor(\"getFlexNode\");\n\t\t\t\tforest.moveCursorToPath(anchorNode, cursor);\n\n\t\t\t\tflexNode = getOrCreateHydratedFlexTreeNode(context, cursor);\n\t\t\t\tcursor.free();\n\t\t\t\tassertFlexTreeEntityNotFreed(flexNode);\n\t\t\t}\n\n\t\t\tgetKernel(node).hydrate(flexNode);\n\t\t\tforest.anchors.forget(anchor);\n\t\t}\n\t};\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"treeFactory.d.ts","sourceRoot":"","sources":["../src/treeFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAMtB,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAG1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAIpD;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,aAAa,EAAE,YAAY;CAAG;AAgDnE;;;;GAIG;AACH,eAAO,MAAM,UAAU,oDAA2B,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,qBAAqB,GAC5B,gBAAgB,CAAC,KAAK,CAAC,CAEzB;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,qBAAqB,GAC5B,iBAAiB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAEpD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,iBAAiB,GACxB,iBAAiB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,CASpD"}
1
+ {"version":3,"file":"treeFactory.d.ts","sourceRoot":"","sources":["../src/treeFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oCAAoC,CAAC;AAC3E,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,iBAAiB,EAMtB,MAAM,6CAA6C,CAAC;AAGrD,OAAO,EAEN,KAAK,YAAY,EACjB,KAAK,iBAAiB,EACtB,KAAK,qBAAqB,EAG1B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,wBAAwB,CAAC;AAIpD;;;;GAIG;AACH,MAAM,WAAW,WAAY,SAAQ,aAAa,EAAE,YAAY;CAAG;AA6DnE;;;;GAIG;AACH,eAAO,MAAM,UAAU,oDAA2B,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,wBAAwB,CACvC,OAAO,EAAE,qBAAqB,GAC5B,gBAAgB,CAAC,KAAK,CAAC,CAEzB;AAED;;;;;GAKG;AACH,wBAAgB,8BAA8B,CAC7C,OAAO,EAAE,qBAAqB,GAC5B,iBAAiB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,CAEpD;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CACnC,OAAO,EAAE,iBAAiB,GACxB,iBAAiB,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC,KAAK,CAAC,CASpD"}
@@ -19,10 +19,19 @@ function treeKernelFactory(options) {
19
19
  if (args.idCompressor === undefined) {
20
20
  throw new UsageError("IdCompressor must be enabled to use SharedTree");
21
21
  }
22
- const adjustedOptions = { ...options };
23
- // TODO: get default from runtime once something like runtime.oldestCompatibleClient exists.
24
- // Using default of 2.0 since that is the oldest version that supports SharedTree.
25
- adjustedOptions.oldestCompatibleClient ??= FluidClientVersion.v2_0;
22
+ const { minVersionForCollab, ...otherOptions } = options;
23
+ const adjustedOptions = {
24
+ ...otherOptions,
25
+ // Cases:
26
+ // A. If options specifies minVersionForCollab, it takes precedence over args.minVersionForCollab.
27
+ // This value is set when:
28
+ // - A customer using the declarative SharedTree API specifies the setting at the Shared Tree level.
29
+ // There is currently no way to set it via the declarative API, but it could be added in the future.
30
+ // - treeKernelFactory is invoked in a fuzz test with a specific minVersionForCollab
31
+ // B. Otherwise, we use args.minVersionForCollab, which is propagated from the ContainerRuntime.
32
+ // C. If neither specifies it, we fall back to a default value default of 2.0 since that is the oldest version that supports SharedTree.
33
+ minVersionForCollab: minVersionForCollab ?? args.minVersionForCollab ?? FluidClientVersion.v2_0,
34
+ };
26
35
  return new SharedTreeKernel(new Breakable("SharedTree"), args.sharedObject, args.serializer, args.submitLocalMessage, args.lastSequenceNumber, args.logger, args.idCompressor, adjustedOptions);
27
36
  }
28
37
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"treeFactory.js","sourceRoot":"","sources":["../src/treeFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAGN,oBAAoB,GAKpB,MAAM,6CAA6C,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,0CAA0C,CAAC;AAEtE,OAAO,EACN,gBAAgB,GAMhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAExF,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAStD;;;;;GAKG;AACH,SAAS,iBAAiB,CACzB,OAAkC;IAElC,SAAS,kBAAkB,CAAC,IAAgB;QAC3C,IAAI,IAAI,CAAC,YAAY,KAAK,SAAS,EAAE,CAAC;YACrC,MAAM,IAAI,UAAU,CAAC,gDAAgD,CAAC,CAAC;QACxE,CAAC;QACD,MAAM,e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;AACH,MAAM,UAAU,oBAAoB,CACnC,OAA0B;IAE1B,MAAM,mBAAmB,GAA+B;QACvD,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE,oBAAoB;QAChC,sBAAsB,EAAE,mBAAmB;QAC3C,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC;KACnC,CAAC;IAEF,OAAO,oBAAoB,CAAQ,mBAAmB,CAAC,CAAC;AACzD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base\";\nimport {\n\ttype ISharedObject,\n\ttype ISharedObjectKind,\n\tmakeSharedObjectKind,\n\ttype KernelArgs,\n\ttype SharedKernelFactory,\n\ttype SharedObjectOptions,\n\ttype FactoryOut,\n} from \"@fluidframework/shared-object-base/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tSharedTreeKernel,\n\ttype ITreePrivate,\n\ttype SharedTreeOptions,\n\ttype SharedTreeOptionsBeta,\n\ttype SharedTreeOptionsInternal,\n\ttype SharedTreeKernelView,\n} from \"./shared-tree/index.js\";\nimport { SharedTreeFactoryType, SharedTreeAttributes } from \"./sharedTreeAttributes.js\";\nimport type { ITree } from \"./simple-tree/index.js\";\nimport { Breakable } from \"./util/index.js\";\nimport { FluidClientVersion } from \"./codec/index.js\";\n\n/**\n * {@link ITreePrivate} extended with ISharedObject.\n * @remarks\n * This is used when integration testing this package with the Fluid runtime as it exposes the APIs the runtime consumes to manipulate the tree.\n */\nexport interface ISharedTree extends ISharedObject, ITreePrivate {}\n\n/**\n * Creates a factory for shared tree kernels with the given options.\n * @remarks\n * Exposes {@link ITreePrivate} to allow access to internals in tests without a cast.\n * Code exposing this beyond this package will need to update to a more public type.\n */\nfunction treeKernelFactory(\n\toptions: SharedTreeOptionsInternal,\n): SharedKernelFactory<SharedTreeKernelView> {\n\tfunction treeFromKernelArgs(args: KernelArgs): SharedTreeKernel {\n\t\tif (args.idCompressor === undefined) {\n\t\t\tthrow new UsageError(\"IdCompressor must be enabled to use SharedTree\");\n\t\t}\n\t\tconst adjustedOptions = { ...options };\n\t\t// TODO: get default from runtime once something like runtime.oldestCompatibleClient exists.\n\t\t// Using default of 2.0 since that is the oldest version that supports SharedTree.\n\t\tadjustedOptions.oldestCompatibleClient ??= FluidClientVersion.v2_0;\n\t\treturn new SharedTreeKernel(\n\t\t\tnew Breakable(\"SharedTree\"),\n\t\t\targs.sharedObject,\n\t\t\targs.serializer,\n\t\t\targs.submitLocalMessage,\n\t\t\targs.lastSequenceNumber,\n\t\t\targs.logger,\n\t\t\targs.idCompressor,\n\t\t\tadjustedOptions,\n\t\t);\n\t}\n\n\treturn {\n\t\tcreate: (args: KernelArgs): FactoryOut<SharedTreeKernelView> => {\n\t\t\tconst k = treeFromKernelArgs(args);\n\t\t\treturn { kernel: k, view: k.view };\n\t\t},\n\n\t\tasync loadCore(\n\t\t\targs: KernelArgs,\n\t\t\tstorage: IChannelStorageService,\n\t\t): Promise<FactoryOut<SharedTreeKernelView>> {\n\t\t\tconst k = treeFromKernelArgs(args);\n\t\t\tawait k.loadCore(storage);\n\t\t\treturn { kernel: k, view: k.view };\n\t\t},\n\t};\n}\n\n/**\n * SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees\n * of objects, arrays, and other data types.\n * @legacy @beta\n */\nexport const SharedTree = configuredSharedTree({});\n\n/**\n * {@link SharedTree} but allowing a non-default configuration.\n * @remarks\n * This is useful for debugging and testing.\n * For example it can be used to opt into extra validation or see if opting out of some optimizations fixes an issue.\n *\n * With great care, and knowledge of the support and stability of the options exposed here,\n * this can also be used to opt into some features early or for performance tuning.\n *\n * @example\n * ```typescript\n * import {\n * \tconfiguredSharedTreeBeta,\n * \tForestTypeReference,\n * } from \"fluid-framework/beta\";\n * const SharedTree = configuredSharedTree({\n * \tforest: ForestTypeReference,\n * });\n * ```\n * @privateRemarks\n * The Legacy `ISharedObjectKind<ITree>` type is omitted here for simplicity.\n * @beta\n */\nexport function configuredSharedTreeBeta(\n\toptions: SharedTreeOptionsBeta,\n): SharedObjectKind<ITree> {\n\treturn configuredSharedTree(options);\n}\n\n/**\n * {@link configuredSharedTreeBeta} including the legacy `ISharedObjectKind` type.\n * @privateRemarks\n * This is given a different export name (with legacy appended) to avoid the need to do the special reexport with different types from the fluid-framework package.\n * @legacy @beta\n */\nexport function configuredSharedTreeBetaLegacy(\n\toptions: SharedTreeOptionsBeta,\n): ISharedObjectKind<ITree> & SharedObjectKind<ITree> {\n\treturn configuredSharedTree(options);\n}\n\n/**\n * {@link configuredSharedTreeBetaLegacy} but including `@alpha` options.\n *\n * @example\n * ```typescript\n * import {\n * \tTreeCompressionStrategy,\n * \tconfiguredSharedTree,\n * \tFormatValidatorBasic,\n * \tForestTypeReference,\n * } from \"@fluidframework/tree/internal\";\n * const SharedTree = configuredSharedTree({\n * \tforest: ForestTypeReference,\n * \tjsonValidator: FormatValidatorBasic,\n * \ttreeEncodeType: TreeCompressionStrategy.Uncompressed,\n * });\n * ```\n * @privateRemarks\n * This should be legacy, but has to be internal due to no alpha+legacy being setup yet.\n *\n * This should be renamed to `configuredSharedTreeAlpha` to avoid colliding with the eventual public version which will have less options.\n * @internal\n */\nexport function configuredSharedTree(\n\toptions: SharedTreeOptions,\n): ISharedObjectKind<ITree> & SharedObjectKind<ITree> {\n\tconst sharedObjectOptions: SharedObjectOptions<ITree> = {\n\t\ttype: SharedTreeFactoryType,\n\t\tattributes: SharedTreeAttributes,\n\t\ttelemetryContextPrefix: \"fluid_sharedTree_\",\n\t\tfactory: treeKernelFactory(options),\n\t};\n\n\treturn makeSharedObjectKind<ITree>(sharedObjectOptions);\n}\n"]}
1
+ {"version":3,"file":"treeFactory.js","sourceRoot":"","sources":["../src/treeFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAGN,oBAAoB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AE,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,CAAC;QAED,KAAK,CAAC,QAAQ,CACb,IAAgB,EAChB,OAA+B;YAE/B,MAAM,CAAC,GAAG,kBAAkB,CAAC,IAAI,CAAC,CAAC;YACnC,MAAM,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAC1B,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QACpC,CAAC;KACD,CAAC;AACH,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC,EAAE,CAAC,CAAC;AAEnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,wBAAwB,CACvC,OAA8B;IAE9B,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,8BAA8B,CAC7C,OAA8B;IAE9B,OAAO,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACtC,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,oBAAoB,CACnC,OAA0B;IAE1B,MAAM,mBAAmB,GAA+B;QACvD,IAAI,EAAE,qBAAqB;QAC3B,UAAU,EAAE,oBAAoB;QAChC,sBAAsB,EAAE,mBAAmB;QAC3C,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC;KACnC,CAAC;IAEF,OAAO,oBAAoB,CAAQ,mBAAmB,CAAC,CAAC;AACzD,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IChannelStorageService } from \"@fluidframework/datastore-definitions/internal\";\nimport type { SharedObjectKind } from \"@fluidframework/shared-object-base\";\nimport {\n\ttype ISharedObject,\n\ttype ISharedObjectKind,\n\tmakeSharedObjectKind,\n\ttype KernelArgs,\n\ttype SharedKernelFactory,\n\ttype SharedObjectOptions,\n\ttype FactoryOut,\n} from \"@fluidframework/shared-object-base/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\n\nimport {\n\tSharedTreeKernel,\n\ttype ITreePrivate,\n\ttype SharedTreeOptions,\n\ttype SharedTreeOptionsBeta,\n\ttype SharedTreeOptionsInternal,\n\ttype SharedTreeKernelView,\n} from \"./shared-tree/index.js\";\nimport { SharedTreeFactoryType, SharedTreeAttributes } from \"./sharedTreeAttributes.js\";\nimport type { ITree } from \"./simple-tree/index.js\";\nimport { Breakable } from \"./util/index.js\";\nimport { FluidClientVersion } from \"./codec/index.js\";\n\n/**\n * {@link ITreePrivate} extended with ISharedObject.\n * @remarks\n * This is used when integration testing this package with the Fluid runtime as it exposes the APIs the runtime consumes to manipulate the tree.\n */\nexport interface ISharedTree extends ISharedObject, ITreePrivate {}\n\n/**\n * Creates a factory for shared tree kernels with the given options.\n * @remarks\n * Exposes {@link ITreePrivate} to allow access to internals in tests without a cast.\n * Code exposing this beyond this package will need to update to a more public type.\n */\nfunction treeKernelFactory(\n\toptions: SharedTreeOptionsInternal,\n): SharedKernelFactory<SharedTreeKernelView> {\n\tfunction treeFromKernelArgs(args: KernelArgs): SharedTreeKernel {\n\t\tif (args.idCompressor === undefined) {\n\t\t\tthrow new UsageError(\"IdCompressor must be enabled to use SharedTree\");\n\t\t}\n\n\t\tconst { minVersionForCollab, ...otherOptions } = options;\n\n\t\tconst adjustedOptions = {\n\t\t\t...otherOptions,\n\t\t\t// Cases:\n\t\t\t// A. If options specifies minVersionForCollab, it takes precedence over args.minVersionForCollab.\n\t\t\t// This value is set when:\n\t\t\t// - A customer using the declarative SharedTree API specifies the setting at the Shared Tree level.\n\t\t\t// There is currently no way to set it via the declarative API, but it could be added in the future.\n\t\t\t// - treeKernelFactory is invoked in a fuzz test with a specific minVersionForCollab\n\t\t\t// B. Otherwise, we use args.minVersionForCollab, which is propagated from the ContainerRuntime.\n\t\t\t// C. If neither specifies it, we fall back to a default value default of 2.0 since that is the oldest version that supports SharedTree.\n\t\t\tminVersionForCollab:\n\t\t\t\tminVersionForCollab ?? args.minVersionForCollab ?? FluidClientVersion.v2_0,\n\t\t};\n\n\t\treturn new SharedTreeKernel(\n\t\t\tnew Breakable(\"SharedTree\"),\n\t\t\targs.sharedObject,\n\t\t\targs.serializer,\n\t\t\targs.submitLocalMessage,\n\t\t\targs.lastSequenceNumber,\n\t\t\targs.logger,\n\t\t\targs.idCompressor,\n\t\t\tadjustedOptions,\n\t\t);\n\t}\n\n\treturn {\n\t\tcreate: (args: KernelArgs): FactoryOut<SharedTreeKernelView> => {\n\t\t\tconst k = treeFromKernelArgs(args);\n\t\t\treturn { kernel: k, view: k.view };\n\t\t},\n\n\t\tasync loadCore(\n\t\t\targs: KernelArgs,\n\t\t\tstorage: IChannelStorageService,\n\t\t): Promise<FactoryOut<SharedTreeKernelView>> {\n\t\t\tconst k = treeFromKernelArgs(args);\n\t\t\tawait k.loadCore(storage);\n\t\t\treturn { kernel: k, view: k.view };\n\t\t},\n\t};\n}\n\n/**\n * SharedTree is a hierarchical data structure for collaboratively editing strongly typed JSON-like trees\n * of objects, arrays, and other data types.\n * @legacy @beta\n */\nexport const SharedTree = configuredSharedTree({});\n\n/**\n * {@link SharedTree} but allowing a non-default configuration.\n * @remarks\n * This is useful for debugging and testing.\n * For example it can be used to opt into extra validation or see if opting out of some optimizations fixes an issue.\n *\n * With great care, and knowledge of the support and stability of the options exposed here,\n * this can also be used to opt into some features early or for performance tuning.\n *\n * @example\n * ```typescript\n * import {\n * \tconfiguredSharedTreeBeta,\n * \tForestTypeReference,\n * } from \"fluid-framework/beta\";\n * const SharedTree = configuredSharedTree({\n * \tforest: ForestTypeReference,\n * });\n * ```\n * @privateRemarks\n * The Legacy `ISharedObjectKind<ITree>` type is omitted here for simplicity.\n * @beta\n */\nexport function configuredSharedTreeBeta(\n\toptions: SharedTreeOptionsBeta,\n): SharedObjectKind<ITree> {\n\treturn configuredSharedTree(options);\n}\n\n/**\n * {@link configuredSharedTreeBeta} including the legacy `ISharedObjectKind` type.\n * @privateRemarks\n * This is given a different export name (with legacy appended) to avoid the need to do the special reexport with different types from the fluid-framework package.\n * @legacy @beta\n */\nexport function configuredSharedTreeBetaLegacy(\n\toptions: SharedTreeOptionsBeta,\n): ISharedObjectKind<ITree> & SharedObjectKind<ITree> {\n\treturn configuredSharedTree(options);\n}\n\n/**\n * {@link configuredSharedTreeBetaLegacy} but including `@alpha` options.\n *\n * @example\n * ```typescript\n * import {\n * \tTreeCompressionStrategy,\n * \tconfiguredSharedTree,\n * \tFormatValidatorBasic,\n * \tForestTypeReference,\n * } from \"@fluidframework/tree/internal\";\n * const SharedTree = configuredSharedTree({\n * \tforest: ForestTypeReference,\n * \tjsonValidator: FormatValidatorBasic,\n * \ttreeEncodeType: TreeCompressionStrategy.Uncompressed,\n * });\n * ```\n * @privateRemarks\n * This should be legacy, but has to be internal due to no alpha+legacy being setup yet.\n *\n * This should be renamed to `configuredSharedTreeAlpha` to avoid colliding with the eventual public version which will have less options.\n * @internal\n */\nexport function configuredSharedTree(\n\toptions: SharedTreeOptions,\n): ISharedObjectKind<ITree> & SharedObjectKind<ITree> {\n\tconst sharedObjectOptions: SharedObjectOptions<ITree> = {\n\t\ttype: SharedTreeFactoryType,\n\t\tattributes: SharedTreeAttributes,\n\t\ttelemetryContextPrefix: \"fluid_sharedTree_\",\n\t\tfactory: treeKernelFactory(options),\n\t};\n\n\treturn makeSharedObjectKind<ITree>(sharedObjectOptions);\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree",
3
- "version": "2.63.0-359734",
3
+ "version": "2.63.0",
4
4
  "description": "Distributed tree",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -101,39 +101,40 @@
101
101
  "temp-directory": "nyc/.nyc_output"
102
102
  },
103
103
  "dependencies": {
104
- "@fluid-internal/client-utils": "2.63.0-359734",
105
- "@fluidframework/container-runtime": "2.63.0-359734",
106
- "@fluidframework/core-interfaces": "2.63.0-359734",
107
- "@fluidframework/core-utils": "2.63.0-359734",
108
- "@fluidframework/datastore-definitions": "2.63.0-359734",
109
- "@fluidframework/driver-definitions": "2.63.0-359734",
110
- "@fluidframework/id-compressor": "2.63.0-359734",
111
- "@fluidframework/runtime-definitions": "2.63.0-359734",
112
- "@fluidframework/runtime-utils": "2.63.0-359734",
113
- "@fluidframework/shared-object-base": "2.63.0-359734",
114
- "@fluidframework/telemetry-utils": "2.63.0-359734",
104
+ "@fluid-internal/client-utils": "~2.63.0",
105
+ "@fluidframework/container-runtime": "~2.63.0",
106
+ "@fluidframework/core-interfaces": "~2.63.0",
107
+ "@fluidframework/core-utils": "~2.63.0",
108
+ "@fluidframework/datastore-definitions": "~2.63.0",
109
+ "@fluidframework/driver-definitions": "~2.63.0",
110
+ "@fluidframework/id-compressor": "~2.63.0",
111
+ "@fluidframework/runtime-definitions": "~2.63.0",
112
+ "@fluidframework/runtime-utils": "~2.63.0",
113
+ "@fluidframework/shared-object-base": "~2.63.0",
114
+ "@fluidframework/telemetry-utils": "~2.63.0",
115
115
  "@sinclair/typebox": "^0.34.13",
116
116
  "@tylerbu/sorted-btree-es6": "^1.8.0",
117
117
  "@types/ungap__structured-clone": "^1.2.0",
118
118
  "@ungap/structured-clone": "^1.2.0",
119
+ "semver-ts": "^1.0.3",
119
120
  "uuid": "^11.1.0"
120
121
  },
121
122
  "devDependencies": {
122
123
  "@arethetypeswrong/cli": "^0.17.1",
123
124
  "@biomejs/biome": "~1.9.3",
124
- "@fluid-internal/mocha-test-setup": "2.63.0-359734",
125
- "@fluid-private/stochastic-test-utils": "2.63.0-359734",
126
- "@fluid-private/test-dds-utils": "2.63.0-359734",
127
- "@fluid-private/test-drivers": "2.63.0-359734",
125
+ "@fluid-internal/mocha-test-setup": "~2.63.0",
126
+ "@fluid-private/stochastic-test-utils": "~2.63.0",
127
+ "@fluid-private/test-dds-utils": "~2.63.0",
128
+ "@fluid-private/test-drivers": "~2.63.0",
128
129
  "@fluid-tools/benchmark": "^0.51.0",
129
130
  "@fluid-tools/build-cli": "^0.58.3",
130
131
  "@fluidframework/build-common": "^2.0.3",
131
132
  "@fluidframework/build-tools": "^0.58.3",
132
- "@fluidframework/container-definitions": "2.63.0-359734",
133
- "@fluidframework/container-loader": "2.63.0-359734",
133
+ "@fluidframework/container-definitions": "~2.63.0",
134
+ "@fluidframework/container-loader": "~2.63.0",
134
135
  "@fluidframework/eslint-config-fluid": "^6.0.0",
135
- "@fluidframework/test-runtime-utils": "2.63.0-359734",
136
- "@fluidframework/test-utils": "2.63.0-359734",
136
+ "@fluidframework/test-runtime-utils": "~2.63.0",
137
+ "@fluidframework/test-utils": "~2.63.0",
137
138
  "@fluidframework/tree-previous": "npm:@fluidframework/tree@2.62.0",
138
139
  "@microsoft/api-extractor": "7.52.11",
139
140
  "@types/diff": "^3.5.1",
@@ -10,6 +10,7 @@ import type { Static, TAnySchema, TSchema } from "@sinclair/typebox";
10
10
 
11
11
  import type { ChangeEncodingContext } from "../core/index.js";
12
12
  import type { JsonCompatibleReadOnly } from "../util/index.js";
13
+ import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
13
14
 
14
15
  /**
15
16
  * Translates decoded data to encoded data.
@@ -151,7 +152,7 @@ export interface CodecWriteOptions extends ICodecOptions {
151
152
  * Note that versions older than this should not result in data corruption if they access the data:
152
153
  * the data's format should be versioned and if they can't handle the format they should error.
153
154
  */
154
- readonly oldestCompatibleClient: FluidClientVersion;
155
+ readonly minVersionForCollab: MinimumVersionForCollab;
155
156
  }
156
157
 
157
158
  /**
@@ -286,7 +287,7 @@ export class MappedDependentFormatVersion<
286
287
  {
287
288
  public constructor(private readonly map: ReadonlyMap<TParentVersion, TChildVersion>) {}
288
289
  public lookup(parent: TParentVersion): TChildVersion {
289
- return this.map.get(parent) ?? fail("Unknown parent version");
290
+ return this.map.get(parent) ?? fail(0xc73 /* Unknown parent version */);
290
291
  }
291
292
  }
292
293
 
@@ -466,16 +467,6 @@ export function withSchemaValidation<
466
467
  * For example, document if there is an encoding efficiency improvement of oping into that version or newer.
467
468
  * Versions with no notable impact can be omitted.
468
469
  *
469
- * These use numeric values for easy threshold comparisons.
470
- * Without zero padding, version 2.10 is treated as 2.1, which is numerically less than 2.2.
471
- * Adding leading zeros to the minor version ensures correct comparisons.
472
- * For example, version 2.20.0 is encoded as 2.020, and version 2.2.0 is encoded as 2.002.
473
- * For example FF 2.20.0 is encoded as 2.020 and FF 2.2.0 is encoded as 2.002.
474
- *
475
- * Three digits was selected as that will likely be enough, while two digits could easily be too few.
476
- * If three digits ends up being too few, minor releases of 1000 and higher
477
- * could still be handled using something like 2.999_00001 without having to change the lower releases.
478
- *
479
470
  * This scheme assumes a single version will always be enough to communicate compatibility.
480
471
  * For this to work, compatibility has to be strictly increasing.
481
472
  * If this is violated (for example a subset of incompatible features from 3.x that are not in 3.0 are back ported to 2.x),
@@ -487,7 +478,7 @@ export function withSchemaValidation<
487
478
  * For example, if needed, would adding more leading zeros to the minor version break things.
488
479
  * @alpha
489
480
  */
490
- export enum FluidClientVersion {
481
+ export const FluidClientVersion = {
491
482
  /**
492
483
  * Fluid Framework Client 1.4 and newer.
493
484
  * @remarks
@@ -497,8 +488,10 @@ export enum FluidClientVersion {
497
488
  */
498
489
  // v1_4 = 1.004,
499
490
 
500
- /** Fluid Framework Client 2.0 and newer. */
501
- v2_0 = 2.0,
491
+ /**
492
+ * Fluid Framework Client 2.0 and newer.
493
+ */
494
+ v2_0: "2.0.0",
502
495
 
503
496
  /** Fluid Framework Client 2.1 and newer. */
504
497
  // If we think we might want to start allowing opting into something that landed in 2.1 (without opting into something newer),
@@ -509,19 +502,8 @@ export enum FluidClientVersion {
509
502
  /** Fluid Framework Client 2.52 and newer. */
510
503
  // New formats introduced in 2.52:
511
504
  // - DetachedFieldIndex FormatV2
512
- v2_52 = 2.052,
513
-
514
- /**
515
- * Enable unreleased and unfinished features.
516
- * @remarks
517
- * Using this value can result in documents which can not be opened in future versions of the framework.
518
- * It can also result in data corruption by enabling unfinished features which may not handle all cases correctly.
519
- *
520
- * This can be used with specific APIs when the caller has knowledge of what specific features those APIs will be opted into with it.
521
- * This is useful for testing features before they are released, but should not be used in production code.
522
- */
523
- EnableUnstableFeatures = Number.POSITIVE_INFINITY,
524
- }
505
+ v2_52: "2.52.0",
506
+ } as const satisfies Record<string, MinimumVersionForCollab>;
525
507
 
526
508
  /**
527
509
  * An up to date version which includes all the important stable features.
@@ -532,7 +514,7 @@ export enum FluidClientVersion {
532
514
  * Update as needed.
533
515
  * TODO: Consider using packageVersion.ts to keep this current.
534
516
  */
535
- export const currentVersion: FluidClientVersion = FluidClientVersion.v2_0;
517
+ export const currentVersion: MinimumVersionForCollab = FluidClientVersion.v2_0;
536
518
 
537
519
  export interface CodecTree {
538
520
  readonly name: string;
@@ -14,12 +14,12 @@ import {
14
14
  type IJsonCodec,
15
15
  withSchemaValidation,
16
16
  type FormatVersion,
17
- type FluidClientVersion,
18
17
  type CodecWriteOptions,
19
18
  } from "../codec.js";
20
19
 
21
20
  import { Versioned } from "./format.js";
22
21
  import { pkgVersion } from "../../packageVersion.js";
22
+ import type { MinimumVersionForCollab } from "@fluidframework/runtime-definitions/internal";
23
23
 
24
24
  export function makeVersionedCodec<
25
25
  TDecoded,
@@ -45,7 +45,7 @@ export function makeVersionedCodec<
45
45
  if (!supportedVersions.has(versioned.version)) {
46
46
  throw new UsageError(
47
47
  `Unsupported version ${versioned.version} encountered while decoding data. Supported versions for this data are: ${Array.from(supportedVersions).join(", ")}.
48
- The client which encoded this data likely specified an "oldestCompatibleClient" value which corresponds to a version newer than the version of this client ("${pkgVersion}").`,
48
+ The client which encoded this data likely specified an "minVersionForCollab" value which corresponds to a version newer than the version of this client ("${pkgVersion}").`,
49
49
  );
50
50
  }
51
51
  const decoded = inner.decode(data, context);
@@ -103,7 +103,7 @@ export function makeVersionDispatchingCodec<TDecoded, TContext>(
103
103
  }
104
104
 
105
105
  /**
106
- * Creates a codec which dispatches to the appropriate member of a codec family based on the `oldestCompatibleClient` for encode and the
106
+ * Creates a codec which dispatches to the appropriate member of a codec family based on the `minVersionForCollab` for encode and the
107
107
  * version number in data it encounters for decode.
108
108
  * @privateRemarks
109
109
  * This is a two stage builder so the first stage can encapsulate all codec specific details and the second can bring in configuration.
@@ -115,17 +115,17 @@ export class ClientVersionDispatchingCodecBuilder<TDecoded, TContext> {
115
115
  */
116
116
  private readonly family: ICodecFamily<TDecoded, TContext>,
117
117
  /**
118
- * A function which maps a {@link FluidClientVersion} to a version number for the codec family which is supported by that version.
118
+ * A function which maps a {@link MinimumVersionForCollab} to a version number for the codec family which is supported by that version.
119
119
  * This can (and typically does) pick the newest version of the codec which is known to be compatible with the client version so that
120
120
  * any improvements in newer versions of the codec can be used when allowed.
121
121
  */
122
- private readonly versionMapping: (oldestCompatibleClient: FluidClientVersion) => number,
122
+ private readonly versionMapping: (minVersionForCollab: MinimumVersionForCollab) => number,
123
123
  ) {}
124
124
 
125
125
  public build(
126
126
  options: CodecWriteOptions,
127
127
  ): IJsonCodec<TDecoded, JsonCompatibleReadOnly, JsonCompatibleReadOnly, TContext> {
128
- const writeVersion = this.versionMapping(options.oldestCompatibleClient);
128
+ const writeVersion = this.versionMapping(options.minVersionForCollab);
129
129
  return makeVersionDispatchingCodec(this.family, { ...options, writeVersion });
130
130
  }
131
131
  }
@@ -84,7 +84,7 @@ export class DetachedFieldIndex {
84
84
  ) {
85
85
  this.options = options ?? {
86
86
  jsonValidator: FormatValidatorNoOp,
87
- oldestCompatibleClient: FluidClientVersion.v2_0,
87
+ minVersionForCollab: FluidClientVersion.v2_0,
88
88
  };
89
89
  this.codec = makeDetachedFieldIndexCodec(revisionTagCodec, this.options, idCompressor);
90
90
  }
@@ -30,7 +30,7 @@ export function makeDetachedFieldIndexCodec(
30
30
  ): IJsonCodec<DetachedFieldSummaryData> {
31
31
  const family = makeDetachedFieldIndexCodecFamily(revisionTagCodec, options, idCompressor);
32
32
  const writeVersion =
33
- options.oldestCompatibleClient < FluidClientVersion.v2_52 ? version1 : version2;
33
+ options.minVersionForCollab < FluidClientVersion.v2_52 ? version1 : version2;
34
34
  return makeVersionDispatchingCodec(family, { ...options, writeVersion });
35
35
  }
36
36