@fluidframework/tree 2.111.0 → 2.112.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 (375) hide show
  1. package/CHANGELOG.md +145 -0
  2. package/api-report/tree.alpha.api.md +48 -5
  3. package/api-report/tree.beta.api.md +1 -1
  4. package/api-report/tree.legacy.beta.api.md +1 -1
  5. package/api-report/tree.legacy.public.api.md +1 -1
  6. package/api-report/tree.public.api.md +1 -1
  7. package/dist/componentApi.d.ts +198 -0
  8. package/dist/componentApi.d.ts.map +1 -0
  9. package/dist/componentApi.js +138 -0
  10. package/dist/componentApi.js.map +1 -0
  11. package/dist/entrypoints/alpha.d.ts +1 -1
  12. package/dist/entrypoints/alpha.d.ts.map +1 -1
  13. package/dist/entrypoints/alpha.js +4 -2
  14. package/dist/entrypoints/alpha.js.map +1 -1
  15. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +1 -25
  16. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  17. package/dist/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  18. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +1 -2
  19. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  20. package/dist/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  21. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts +6 -18
  22. package/dist/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  23. package/dist/feature-libraries/chunked-forest/codec/codecs.js +9 -16
  24. package/dist/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  25. package/dist/feature-libraries/index.d.ts +2 -2
  26. package/dist/feature-libraries/index.d.ts.map +1 -1
  27. package/dist/feature-libraries/index.js +3 -2
  28. package/dist/feature-libraries/index.js.map +1 -1
  29. package/dist/feature-libraries/modular-schema/index.d.ts +1 -0
  30. package/dist/feature-libraries/modular-schema/index.d.ts.map +1 -1
  31. package/dist/feature-libraries/modular-schema/index.js +3 -1
  32. package/dist/feature-libraries/modular-schema/index.js.map +1 -1
  33. package/dist/feature-libraries/modular-schema/minimizeModularChange.d.ts +25 -0
  34. package/dist/feature-libraries/modular-schema/minimizeModularChange.d.ts.map +1 -0
  35. package/dist/feature-libraries/modular-schema/minimizeModularChange.js +29 -0
  36. package/dist/feature-libraries/modular-schema/minimizeModularChange.js.map +1 -0
  37. package/dist/feature-libraries/schemaChecker.d.ts +22 -3
  38. package/dist/feature-libraries/schemaChecker.d.ts.map +1 -1
  39. package/dist/feature-libraries/schemaChecker.js +48 -5
  40. package/dist/feature-libraries/schemaChecker.js.map +1 -1
  41. package/dist/index.d.ts +2 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +5 -2
  44. package/dist/index.js.map +1 -1
  45. package/dist/packageVersion.d.ts +1 -1
  46. package/dist/packageVersion.js +1 -1
  47. package/dist/packageVersion.js.map +1 -1
  48. package/dist/shared-tree/independentView.d.ts +17 -4
  49. package/dist/shared-tree/independentView.d.ts.map +1 -1
  50. package/dist/shared-tree/independentView.js +11 -5
  51. package/dist/shared-tree/independentView.js.map +1 -1
  52. package/dist/shared-tree/index.d.ts +2 -1
  53. package/dist/shared-tree/index.d.ts.map +1 -1
  54. package/dist/shared-tree/index.js +3 -1
  55. package/dist/shared-tree/index.js.map +1 -1
  56. package/dist/shared-tree/schematizingTreeView.d.ts +1 -0
  57. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  58. package/dist/shared-tree/schematizingTreeView.js +6 -3
  59. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  60. package/dist/shared-tree/serializedChange.d.ts +41 -0
  61. package/dist/shared-tree/serializedChange.d.ts.map +1 -0
  62. package/dist/shared-tree/serializedChange.js +87 -0
  63. package/dist/shared-tree/serializedChange.js.map +1 -0
  64. package/dist/shared-tree/sharedTree.d.ts +13 -0
  65. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  66. package/dist/shared-tree/sharedTree.js +2 -0
  67. package/dist/shared-tree/sharedTree.js.map +1 -1
  68. package/dist/shared-tree/sharedTreeChangeFamily.d.ts +7 -0
  69. package/dist/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  70. package/dist/shared-tree/sharedTreeChangeFamily.js +8 -1
  71. package/dist/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  72. package/dist/shared-tree/transactionMinimize.d.ts +35 -0
  73. package/dist/shared-tree/transactionMinimize.d.ts.map +1 -0
  74. package/dist/shared-tree/transactionMinimize.js +65 -0
  75. package/dist/shared-tree/transactionMinimize.js.map +1 -0
  76. package/dist/shared-tree/treeCheckout.d.ts +3 -1
  77. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  78. package/dist/shared-tree/treeCheckout.js +36 -62
  79. package/dist/shared-tree/treeCheckout.js.map +1 -1
  80. package/dist/shared-tree-core/editManager.d.ts +6 -3
  81. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  82. package/dist/shared-tree-core/editManager.js +35 -14
  83. package/dist/shared-tree-core/editManager.js.map +1 -1
  84. package/dist/shared-tree-core/editManagerFormatCommons.d.ts +1 -1
  85. package/dist/shared-tree-core/editManagerFormatCommons.js +1 -1
  86. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  87. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts +1 -1
  88. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  89. package/dist/shared-tree-core/messageCodecVSharedBranches.js +8 -2
  90. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  91. package/dist/shared-tree-core/messageFormat.d.ts +1 -1
  92. package/dist/shared-tree-core/messageFormat.js +1 -1
  93. package/dist/shared-tree-core/messageFormat.js.map +1 -1
  94. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts +10 -1
  95. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  96. package/dist/shared-tree-core/messageFormatVSharedBranches.js +1 -0
  97. package/dist/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  98. package/dist/shared-tree-core/messageTypes.d.ts +1 -0
  99. package/dist/shared-tree-core/messageTypes.d.ts.map +1 -1
  100. package/dist/shared-tree-core/messageTypes.js.map +1 -1
  101. package/dist/shared-tree-core/sharedTreeCore.d.ts +9 -3
  102. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  103. package/dist/shared-tree-core/sharedTreeCore.js +24 -11
  104. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  105. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  106. package/dist/shared-tree-core/transaction.js +16 -2
  107. package/dist/shared-tree-core/transaction.js.map +1 -1
  108. package/dist/simple-tree/api/index.d.ts +1 -1
  109. package/dist/simple-tree/api/index.d.ts.map +1 -1
  110. package/dist/simple-tree/api/index.js +2 -2
  111. package/dist/simple-tree/api/index.js.map +1 -1
  112. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +9 -24
  113. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  114. package/dist/simple-tree/api/schemaCompatibilityTester.js +31 -44
  115. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  116. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts +56 -15
  117. package/dist/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  118. package/dist/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  119. package/dist/simple-tree/api/schemaFactoryBeta.d.ts +0 -3
  120. package/dist/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
  121. package/dist/simple-tree/api/schemaFactoryBeta.js.map +1 -1
  122. package/dist/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
  123. package/dist/simple-tree/api/snapshotCompatibilityChecker.js +1 -2
  124. package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  125. package/dist/simple-tree/api/storedSchema.d.ts.map +1 -1
  126. package/dist/simple-tree/api/storedSchema.js +1 -2
  127. package/dist/simple-tree/api/storedSchema.js.map +1 -1
  128. package/dist/simple-tree/api/tree.d.ts +22 -2
  129. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  130. package/dist/simple-tree/api/tree.js.map +1 -1
  131. package/dist/simple-tree/api/typesUnsafe.d.ts +2 -2
  132. package/dist/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  133. package/dist/simple-tree/api/typesUnsafe.js.map +1 -1
  134. package/dist/simple-tree/index.d.ts +1 -1
  135. package/dist/simple-tree/index.d.ts.map +1 -1
  136. package/dist/simple-tree/index.js +2 -2
  137. package/dist/simple-tree/index.js.map +1 -1
  138. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts +83 -4
  139. package/dist/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  140. package/dist/simple-tree/node-kinds/array/arrayNode.js +39 -0
  141. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  142. package/dist/simple-tree/simpleSchemaFormatV1.js +1 -1
  143. package/dist/simple-tree/simpleSchemaFormatV1.js.map +1 -1
  144. package/dist/treeFactory.js +1 -1
  145. package/dist/treeFactory.js.map +1 -1
  146. package/dist/util/breakable.d.ts +16 -1
  147. package/dist/util/breakable.d.ts.map +1 -1
  148. package/dist/util/breakable.js +9 -1
  149. package/dist/util/breakable.js.map +1 -1
  150. package/dist/util/compressedIds.d.ts +69 -2
  151. package/dist/util/compressedIds.d.ts.map +1 -1
  152. package/dist/util/compressedIds.js +32 -1
  153. package/dist/util/compressedIds.js.map +1 -1
  154. package/dist/util/index.d.ts +2 -2
  155. package/dist/util/index.d.ts.map +1 -1
  156. package/dist/util/index.js +2 -2
  157. package/dist/util/index.js.map +1 -1
  158. package/dist/util/nestedMap.d.ts.map +1 -1
  159. package/dist/util/nestedMap.js +16 -3
  160. package/dist/util/nestedMap.js.map +1 -1
  161. package/dist/util/nestedSet.d.ts +1 -1
  162. package/dist/util/nestedSet.d.ts.map +1 -1
  163. package/dist/util/nestedSet.js.map +1 -1
  164. package/dist/util/utils.d.ts +0 -6
  165. package/dist/util/utils.d.ts.map +1 -1
  166. package/dist/util/utils.js +1 -15
  167. package/dist/util/utils.js.map +1 -1
  168. package/lib/componentApi.d.ts +198 -0
  169. package/lib/componentApi.d.ts.map +1 -0
  170. package/lib/componentApi.js +135 -0
  171. package/lib/componentApi.js.map +1 -0
  172. package/lib/entrypoints/alpha.d.ts +1 -1
  173. package/lib/entrypoints/alpha.d.ts.map +1 -1
  174. package/lib/entrypoints/alpha.js +1 -1
  175. package/lib/entrypoints/alpha.js.map +1 -1
  176. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts +1 -25
  177. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.d.ts.map +1 -1
  178. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js +1 -1
  179. package/lib/feature-libraries/chunked-forest/codec/chunkDecoding.js.map +1 -1
  180. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts +1 -2
  181. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.d.ts.map +1 -1
  182. package/lib/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.js.map +1 -1
  183. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts +6 -18
  184. package/lib/feature-libraries/chunked-forest/codec/codecs.d.ts.map +1 -1
  185. package/lib/feature-libraries/chunked-forest/codec/codecs.js +10 -17
  186. package/lib/feature-libraries/chunked-forest/codec/codecs.js.map +1 -1
  187. package/lib/feature-libraries/index.d.ts +2 -2
  188. package/lib/feature-libraries/index.d.ts.map +1 -1
  189. package/lib/feature-libraries/index.js +1 -1
  190. package/lib/feature-libraries/index.js.map +1 -1
  191. package/lib/feature-libraries/modular-schema/index.d.ts +1 -0
  192. package/lib/feature-libraries/modular-schema/index.d.ts.map +1 -1
  193. package/lib/feature-libraries/modular-schema/index.js +1 -0
  194. package/lib/feature-libraries/modular-schema/index.js.map +1 -1
  195. package/lib/feature-libraries/modular-schema/minimizeModularChange.d.ts +25 -0
  196. package/lib/feature-libraries/modular-schema/minimizeModularChange.d.ts.map +1 -0
  197. package/lib/feature-libraries/modular-schema/minimizeModularChange.js +25 -0
  198. package/lib/feature-libraries/modular-schema/minimizeModularChange.js.map +1 -0
  199. package/lib/feature-libraries/schemaChecker.d.ts +22 -3
  200. package/lib/feature-libraries/schemaChecker.d.ts.map +1 -1
  201. package/lib/feature-libraries/schemaChecker.js +48 -5
  202. package/lib/feature-libraries/schemaChecker.js.map +1 -1
  203. package/lib/index.d.ts +2 -1
  204. package/lib/index.d.ts.map +1 -1
  205. package/lib/index.js +2 -1
  206. package/lib/index.js.map +1 -1
  207. package/lib/packageVersion.d.ts +1 -1
  208. package/lib/packageVersion.js +1 -1
  209. package/lib/packageVersion.js.map +1 -1
  210. package/lib/shared-tree/independentView.d.ts +17 -4
  211. package/lib/shared-tree/independentView.d.ts.map +1 -1
  212. package/lib/shared-tree/independentView.js +9 -3
  213. package/lib/shared-tree/independentView.js.map +1 -1
  214. package/lib/shared-tree/index.d.ts +2 -1
  215. package/lib/shared-tree/index.d.ts.map +1 -1
  216. package/lib/shared-tree/index.js +1 -0
  217. package/lib/shared-tree/index.js.map +1 -1
  218. package/lib/shared-tree/schematizingTreeView.d.ts +1 -0
  219. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  220. package/lib/shared-tree/schematizingTreeView.js +7 -4
  221. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  222. package/lib/shared-tree/serializedChange.d.ts +41 -0
  223. package/lib/shared-tree/serializedChange.d.ts.map +1 -0
  224. package/lib/shared-tree/serializedChange.js +84 -0
  225. package/lib/shared-tree/serializedChange.js.map +1 -0
  226. package/lib/shared-tree/sharedTree.d.ts +13 -0
  227. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  228. package/lib/shared-tree/sharedTree.js +2 -0
  229. package/lib/shared-tree/sharedTree.js.map +1 -1
  230. package/lib/shared-tree/sharedTreeChangeFamily.d.ts +7 -0
  231. package/lib/shared-tree/sharedTreeChangeFamily.d.ts.map +1 -1
  232. package/lib/shared-tree/sharedTreeChangeFamily.js +7 -1
  233. package/lib/shared-tree/sharedTreeChangeFamily.js.map +1 -1
  234. package/lib/shared-tree/transactionMinimize.d.ts +35 -0
  235. package/lib/shared-tree/transactionMinimize.d.ts.map +1 -0
  236. package/lib/shared-tree/transactionMinimize.js +62 -0
  237. package/lib/shared-tree/transactionMinimize.js.map +1 -0
  238. package/lib/shared-tree/treeCheckout.d.ts +3 -1
  239. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  240. package/lib/shared-tree/treeCheckout.js +18 -44
  241. package/lib/shared-tree/treeCheckout.js.map +1 -1
  242. package/lib/shared-tree-core/editManager.d.ts +6 -3
  243. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  244. package/lib/shared-tree-core/editManager.js +36 -15
  245. package/lib/shared-tree-core/editManager.js.map +1 -1
  246. package/lib/shared-tree-core/editManagerFormatCommons.d.ts +1 -1
  247. package/lib/shared-tree-core/editManagerFormatCommons.js +1 -1
  248. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  249. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts +1 -1
  250. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  251. package/lib/shared-tree-core/messageCodecVSharedBranches.js +8 -2
  252. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  253. package/lib/shared-tree-core/messageFormat.d.ts +1 -1
  254. package/lib/shared-tree-core/messageFormat.js +1 -1
  255. package/lib/shared-tree-core/messageFormat.js.map +1 -1
  256. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts +10 -1
  257. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  258. package/lib/shared-tree-core/messageFormatVSharedBranches.js +1 -0
  259. package/lib/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  260. package/lib/shared-tree-core/messageTypes.d.ts +1 -0
  261. package/lib/shared-tree-core/messageTypes.d.ts.map +1 -1
  262. package/lib/shared-tree-core/messageTypes.js.map +1 -1
  263. package/lib/shared-tree-core/sharedTreeCore.d.ts +9 -3
  264. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  265. package/lib/shared-tree-core/sharedTreeCore.js +25 -12
  266. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  267. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  268. package/lib/shared-tree-core/transaction.js +16 -2
  269. package/lib/shared-tree-core/transaction.js.map +1 -1
  270. package/lib/simple-tree/api/index.d.ts +1 -1
  271. package/lib/simple-tree/api/index.d.ts.map +1 -1
  272. package/lib/simple-tree/api/index.js +1 -1
  273. package/lib/simple-tree/api/index.js.map +1 -1
  274. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +9 -24
  275. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  276. package/lib/simple-tree/api/schemaCompatibilityTester.js +29 -42
  277. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  278. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts +56 -15
  279. package/lib/simple-tree/api/schemaFactoryAlpha.d.ts.map +1 -1
  280. package/lib/simple-tree/api/schemaFactoryAlpha.js.map +1 -1
  281. package/lib/simple-tree/api/schemaFactoryBeta.d.ts +0 -3
  282. package/lib/simple-tree/api/schemaFactoryBeta.d.ts.map +1 -1
  283. package/lib/simple-tree/api/schemaFactoryBeta.js.map +1 -1
  284. package/lib/simple-tree/api/snapshotCompatibilityChecker.d.ts.map +1 -1
  285. package/lib/simple-tree/api/snapshotCompatibilityChecker.js +2 -3
  286. package/lib/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  287. package/lib/simple-tree/api/storedSchema.d.ts.map +1 -1
  288. package/lib/simple-tree/api/storedSchema.js +2 -3
  289. package/lib/simple-tree/api/storedSchema.js.map +1 -1
  290. package/lib/simple-tree/api/tree.d.ts +22 -2
  291. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  292. package/lib/simple-tree/api/tree.js.map +1 -1
  293. package/lib/simple-tree/api/typesUnsafe.d.ts +2 -2
  294. package/lib/simple-tree/api/typesUnsafe.d.ts.map +1 -1
  295. package/lib/simple-tree/api/typesUnsafe.js.map +1 -1
  296. package/lib/simple-tree/index.d.ts +1 -1
  297. package/lib/simple-tree/index.d.ts.map +1 -1
  298. package/lib/simple-tree/index.js +1 -1
  299. package/lib/simple-tree/index.js.map +1 -1
  300. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts +83 -4
  301. package/lib/simple-tree/node-kinds/array/arrayNode.d.ts.map +1 -1
  302. package/lib/simple-tree/node-kinds/array/arrayNode.js +39 -0
  303. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  304. package/lib/simple-tree/simpleSchemaFormatV1.js +1 -1
  305. package/lib/simple-tree/simpleSchemaFormatV1.js.map +1 -1
  306. package/lib/treeFactory.js +1 -1
  307. package/lib/treeFactory.js.map +1 -1
  308. package/lib/util/breakable.d.ts +16 -1
  309. package/lib/util/breakable.d.ts.map +1 -1
  310. package/lib/util/breakable.js +9 -1
  311. package/lib/util/breakable.js.map +1 -1
  312. package/lib/util/compressedIds.d.ts +69 -2
  313. package/lib/util/compressedIds.d.ts.map +1 -1
  314. package/lib/util/compressedIds.js +30 -0
  315. package/lib/util/compressedIds.js.map +1 -1
  316. package/lib/util/index.d.ts +2 -2
  317. package/lib/util/index.d.ts.map +1 -1
  318. package/lib/util/index.js +2 -2
  319. package/lib/util/index.js.map +1 -1
  320. package/lib/util/nestedMap.d.ts.map +1 -1
  321. package/lib/util/nestedMap.js +17 -4
  322. package/lib/util/nestedMap.js.map +1 -1
  323. package/lib/util/nestedSet.d.ts +1 -1
  324. package/lib/util/nestedSet.d.ts.map +1 -1
  325. package/lib/util/nestedSet.js.map +1 -1
  326. package/lib/util/utils.d.ts +0 -6
  327. package/lib/util/utils.d.ts.map +1 -1
  328. package/lib/util/utils.js +0 -13
  329. package/lib/util/utils.js.map +1 -1
  330. package/package.json +22 -22
  331. package/src/componentApi.ts +354 -0
  332. package/src/entrypoints/alpha.ts +3 -0
  333. package/src/feature-libraries/chunked-forest/codec/chunkDecoding.ts +6 -27
  334. package/src/feature-libraries/chunked-forest/codec/chunkDecodingGeneric.ts +1 -2
  335. package/src/feature-libraries/chunked-forest/codec/codecs.ts +17 -44
  336. package/src/feature-libraries/index.ts +2 -0
  337. package/src/feature-libraries/modular-schema/index.ts +1 -0
  338. package/src/feature-libraries/modular-schema/minimizeModularChange.ts +33 -0
  339. package/src/feature-libraries/schemaChecker.ts +86 -9
  340. package/src/index.ts +3 -0
  341. package/src/packageVersion.ts +1 -1
  342. package/src/shared-tree/independentView.ts +35 -5
  343. package/src/shared-tree/index.ts +3 -0
  344. package/src/shared-tree/schematizingTreeView.ts +15 -5
  345. package/src/shared-tree/serializedChange.ts +127 -0
  346. package/src/shared-tree/sharedTree.ts +16 -0
  347. package/src/shared-tree/sharedTreeChangeFamily.ts +7 -1
  348. package/src/shared-tree/transactionMinimize.ts +74 -0
  349. package/src/shared-tree/treeCheckout.ts +42 -57
  350. package/src/shared-tree-core/editManager.ts +42 -6
  351. package/src/shared-tree-core/editManagerFormatCommons.ts +1 -1
  352. package/src/shared-tree-core/messageCodecVSharedBranches.ts +8 -1
  353. package/src/shared-tree-core/messageFormat.ts +1 -1
  354. package/src/shared-tree-core/messageFormatVSharedBranches.ts +10 -0
  355. package/src/shared-tree-core/messageTypes.ts +1 -0
  356. package/src/shared-tree-core/sharedTreeCore.ts +33 -10
  357. package/src/shared-tree-core/transaction.ts +19 -2
  358. package/src/simple-tree/api/index.ts +1 -1
  359. package/src/simple-tree/api/schemaCompatibilityTester.ts +36 -48
  360. package/src/simple-tree/api/schemaFactoryAlpha.ts +56 -15
  361. package/src/simple-tree/api/schemaFactoryBeta.ts +0 -3
  362. package/src/simple-tree/api/snapshotCompatibilityChecker.ts +2 -3
  363. package/src/simple-tree/api/storedSchema.ts +2 -3
  364. package/src/simple-tree/api/tree.ts +24 -2
  365. package/src/simple-tree/api/typesUnsafe.ts +2 -1
  366. package/src/simple-tree/index.ts +1 -1
  367. package/src/simple-tree/node-kinds/array/arrayNode.ts +168 -4
  368. package/src/simple-tree/simpleSchemaFormatV1.ts +1 -1
  369. package/src/treeFactory.ts +1 -1
  370. package/src/util/breakable.ts +8 -1
  371. package/src/util/compressedIds.ts +90 -2
  372. package/src/util/index.ts +3 -1
  373. package/src/util/nestedMap.ts +21 -4
  374. package/src/util/nestedSet.ts +1 -1
  375. package/src/util/utils.ts +0 -18
package/CHANGELOG.md CHANGED
@@ -1,5 +1,150 @@
1
1
  # @fluidframework/tree
2
2
 
3
+ ## 2.112.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Add Component utilities for composing open-polymorphic schema ([#27628](https://github.com/microsoft/FluidFramework/pull/27628)) [7a56d096bf](https://github.com/microsoft/FluidFramework/commit/7a56d096bffab133ab4e7ab9c8f9c465b7ba9e81)
8
+
9
+ A new `@alpha` `Component` namespace is now exported from `@fluidframework/tree` (and re-exported from `fluid-framework`). It provides utilities for composing independently authored application "components" that contribute to a shared configuration, which is useful for implementing ["open polymorphism"](<https://en.wikipedia.org/wiki/Polymorphism_(computer_science)>) schema patterns where the set of allowed types for a field or collection can be extended by separate libraries.
10
+
11
+ Each component is expressed as a `Component.Factory`: a function which receives a lazy reference to the composed configuration and returns the content that component contributes. Because the configuration is provided lazily, components may reference (including recursively) types contributed by other components. `Component.compose` combines a set of components into a `Component.Composed`, from which the aggregated configuration and per-component content can be read.
12
+
13
+ ```typescript
14
+ /** Example application component content type. */
15
+ interface MyAppComponentContent {
16
+ /**
17
+ * Item types contributed by this component.
18
+ * We are just typing them as TreeNodeSchema here to keep things simple.
19
+ * Real use would often provide some static factory to be able to create instances, as well as some APIs all item nodes should implement.
20
+ */
21
+ readonly items: Component.LazyArray<TreeNodeSchema>;
22
+ }
23
+
24
+ type MyAppComponent = Component.Factory<MyAppComponentContent>;
25
+
26
+ // A simple component, which does not depend on any other context.
27
+ const textComponent: MyAppComponent = () => ({
28
+ items: () => [() => TextItem],
29
+ });
30
+
31
+ // A component which creates an item type which recursively depends on all item types.
32
+ const containerComponent: MyAppComponent = (config) => ({
33
+ items: () => [
34
+ () =>
35
+ class extends sf.array("Container", config().getComposed("items")) {},
36
+ ],
37
+ });
38
+
39
+ const appConfig = Component.compose([containerComponent, textComponent]);
40
+
41
+ // The config's items can now be used to create a TreeViewConfiguration, root schema, or whatever else is needed.
42
+ class Root extends sf.object("Root", {
43
+ content: appConfig.getComposed("items"),
44
+ }) {}
45
+ ```
46
+
47
+ See the worked examples in [openPolymorphism.integration.ts](https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/openPolymorphism.integration.ts) for end-to-end usage with SharedTree schema.
48
+
49
+ - Independent tree views now accept an optional telemetry logger ([#27567](https://github.com/microsoft/FluidFramework/pull/27567)) [5fbbcab0af](https://github.com/microsoft/FluidFramework/commit/5fbbcab0aff87519ae6f112611f0c1e62f30d97e)
50
+
51
+ The alpha `independentView`, `independentInitializedView`, and `createIndependentTreeAlpha` APIs now accept an optional `logger` on their options.
52
+ Previously these standalone (non-`SharedTree`) views had no way to surface telemetry,
53
+ so internal events—including those emitted when the tree enters a broken state—were dropped.
54
+ Passing a logger forwards those events to the caller's telemetry pipeline.
55
+ This makes it possible to diagnose failures in scenarios that use independent tree views, such as snapshot import/export, schema migration, and other out-of-container workflows.
56
+
57
+ Events emitted by an independent tree view are tagged with the `independentView` namespace.
58
+ If no logger is provided, behavior is unchanged and telemetry events continue to be dropped.
59
+
60
+ The `logger` option is typed as `ITelemetryBaseLogger` from `@fluidframework/core-interfaces`,
61
+ so any standard Fluid telemetry logger can be passed directly.
62
+
63
+ ```typescript
64
+ // ...
65
+ const view = independentView(
66
+ new TreeViewConfiguration({ schema: MySchema }),
67
+ {
68
+ logger: myTelemetryLogger,
69
+ },
70
+ );
71
+ // ...
72
+ ```
73
+
74
+ - Shared branch names ([#27708](https://github.com/microsoft/FluidFramework/pull/27708)) [1f08b9210b](https://github.com/microsoft/FluidFramework/commit/1f08b9210bf7ba3adbc98c45b02ab8a6a58929f5)
75
+
76
+ The existing [`createSharedBranch`](https://fluidframework.com/docs/api/tree/itreealpha-interface#createsharedbranch-methodsignature) alpha API now takes an optional `name` string parameter that is associated with the shared branch.
77
+ This name can be retrieved by passing the shared branch ID to `getSharedBranchName`.
78
+
79
+ Note that, unlike the shared branch IDs, shared branch names are not guaranteed to be unique.
80
+
81
+ #### Compatibility Implications
82
+
83
+ This change breaks compatibility in the following ways:
84
+ - A document written by a client running an earlier FF version cannot be opened by a client running this version.
85
+ - A document written by a client running this version cannot be opened by a client running an earlier FF version.
86
+ - Clients running earlier FF versions will crash upon receiving ops from clients running this version.
87
+ - Clients running this version will crash upon receiving ops from clients running earlier FF versions.
88
+
89
+ These breaks are only applicable for clients with `enableSharedBranches` turned on. Other clients are unaffected.
90
+
91
+ - Add at, pop, shift, unshift, findLast, and findLastIndex methods to TreeArrayNodeAlpha ([#27686](https://github.com/microsoft/FluidFramework/pull/27686)) [59669008b9](https://github.com/microsoft/FluidFramework/commit/59669008b9f9f70ccb94030a6382afcdf8f28cd4)
92
+
93
+ `TreeArrayNodeAlpha` now has `at`, `pop`, `shift`, `unshift`, `findLast`, and `findLastIndex` methods, further aligning it with JavaScript's built-in Array API:
94
+ - `at(index)` `at` was already implemented at runtime, and consumers compiling with `lib: ES2022` or later could already see it through the inherited `ReadonlyArray` typings. This change adds no new runtime behavior, but makes `at` an explicitly declared, documented part of the API, independent of the consumer's TypeScript `lib` configuration.
95
+ - `unshift(...items)` is an alias for `insertAtStart`, mirroring how `push` aliases `insertAtEnd`: it inserts new item(s) at the start of the array. Unlike `Array.prototype.unshift`, it does not return the new length of the array.
96
+ - `pop()` removes and returns the last item in the array, or returns `undefined` (without modifying the array) if it is empty.
97
+ - `shift()` removes and returns the first item in the array, or returns `undefined` (without modifying the array) if it is empty.
98
+ - `findLast(predicate, thisArg?)` and `findLastIndex(predicate, thisArg?)` search the array from the last item to the first, returning the last matching item (or `undefined`) and its index (or `-1`) respectively, like their `Array.prototype` equivalents. As with `Array.prototype.findLast`, passing a type guard as the `findLast` predicate narrows the returned item's type.
99
+
100
+ These methods are available on `TreeArrayNodeAlpha`, which can be obtained from an existing `TreeArrayNode` via `asAlpha`, or by declaring the schema with `SchemaFactoryAlpha`'s `arrayAlpha`.
101
+
102
+ #### Usage
103
+
104
+ ```typescript
105
+ import { SchemaFactory, asAlpha } from "@fluidframework/tree/alpha";
106
+
107
+ const sf = new SchemaFactory("example");
108
+ const Inventory = sf.array("Inventory", sf.string);
109
+ const inventory = asAlpha(new Inventory(["Apples", "Bananas", "Pears"]));
110
+
111
+ // inventory: ["Apples", "Bananas", "Pears"]
112
+ inventory.unshift("Oranges", "Grapes");
113
+ // inventory: ["Oranges", "Grapes", "Apples", "Bananas", "Pears"]
114
+
115
+ inventory.at(0); // "Oranges"
116
+ inventory.at(-1); // "Pears"
117
+ inventory.at(10); // undefined
118
+
119
+ inventory.findLast((item) => item.startsWith("G")); // "Grapes"
120
+ inventory.findLastIndex((item) => item.startsWith("G")); // 1
121
+
122
+ // inventory: ["Oranges", "Grapes", "Apples", "Bananas", "Pears"]
123
+ inventory.pop(); // "Pears"
124
+ // inventory ["Oranges", "Grapes", "Apples", "Bananas"]
125
+
126
+ inventory.shift(); // "Oranges"
127
+ // inventory: ["Grapes", "Apples", "Bananas"]
128
+ ```
129
+
130
+ - Retain history option ([#27696](https://github.com/microsoft/FluidFramework/pull/27696)) [2fa44c6ed2](https://github.com/microsoft/FluidFramework/commit/2fa44c6ed222a8ed88a632a0bf3cad0c26e72514)
131
+
132
+ Adds a new `retainHistory` flag to [`SharedTreeOptions`](https://fluidframework.com/docs/api/tree/sharedtreeoptions-interface) (defaults to `false`).
133
+ Setting `retainHistory` to `true` will prevent SharedTree from garbage-collecting historical data about old changes.
134
+ Note that this will cause unbounded growth both in memory on the client and in summaries/snapshots (the at-rest data representing a Fluid document).
135
+ For these reasons, this option is only intended for debugging and experimentation.
136
+
137
+ ### Patch Changes
138
+
139
+ - Fix insertable types when using typesRecursive with multiple allowed types ([#27698](https://github.com/microsoft/FluidFramework/pull/27698)) [b72f836d09](https://github.com/microsoft/FluidFramework/commit/b72f836d09437654e0ef5787625073f9da41cf9f)
140
+
141
+ The allowed types produced by `SchemaFactoryBeta.typesRecursive` (and `SchemaFactoryAlpha.typesRecursive`) are now processed correctly when used in a recursive schema that permits more than one type.
142
+
143
+ Previously, passing their output to a recursive schema (for example `factory.arrayRecursive` or `factory.mapRecursive`) computed the node's insertable content type as `never`.
144
+ This caused valid insertions to fail to compile.
145
+ Recursive schemas built from a `typesRecursive` list with two or more types now accept insertable content for each of the allowed types as expected.
146
+ Recursive schemas that use a single type were unaffected.
147
+
3
148
  ## 2.111.0
4
149
 
5
150
  ### Minor Changes
@@ -218,6 +218,31 @@ export interface CommitMetadata {
218
218
  // @alpha
219
219
  export function comparePersistedSchema(persisted: JsonCompatible, view: ImplicitFieldSchema, options: ICodecOptions): Omit<SchemaCompatibilityStatus, "canInitialize">;
220
220
 
221
+ // @alpha
222
+ export namespace Component {
223
+ export function compose<TComponent>(allComponents: readonly Factory<TComponent>[]): Composed<TComponent>;
224
+ export function compose<TComponent, TConfig>(allComponents: readonly Factory<TComponent, TConfig>[], lazyConfiguration: (composed: Composed<TComponent, TConfig>) => TConfig): Composed<TComponent, TConfig>;
225
+ const memoize: <T>(factory: () => T) => (() => T);
226
+ // @sealed
227
+ export interface Composed<TComponent, TConfig = ComposedDefault<TComponent>> {
228
+ readonly components: readonly TComponent[];
229
+ readonly config: TConfig;
230
+ getComponent<TFactory extends Factory<TComponent, TConfig>>(factory: TFactory): ReturnType<TFactory>;
231
+ getComposed<TKey extends keyof {
232
+ [Property in keyof TComponent as TComponent[Property] extends LazyArray<unknown> | undefined ? Property : never]: boolean;
233
+ }>(property: TKey): readonly (Exclude<TComponent[TKey], undefined> extends LazyArray<infer U> ? () => U : never)[];
234
+ getConfigured<TConfigurable extends Configurable<TConfig, unknown, TComponent>>(configurable: TConfigurable): ReturnType<TConfigurable["configure"]>;
235
+ }
236
+ // @sealed
237
+ export type ComposedDefault<TComponent> = Composed<TComponent, ComposedDefault<TComponent>>;
238
+ export interface Configurable<TConfigPartial, out TResult, TComponent> {
239
+ configure(config: TConfigPartial, components: Composed<TComponent, TConfigPartial>): TResult;
240
+ }
241
+ // @input
242
+ export type Factory<TComponent, TConfig = ComposedDefault<TComponent>> = (lazyConfiguration: () => TConfig) => TComponent;
243
+ export type LazyArray<T> = () => readonly (() => T)[];
244
+ }
245
+
221
246
  // @beta
222
247
  export type ConciseTree<THandle = IFluidHandle> = Exclude<TreeLeafValue, IFluidHandle> | THandle | ConciseTree<THandle>[] | {
223
248
  [key: string]: ConciseTree<THandle>;
@@ -242,7 +267,7 @@ export function createIdentifierIndex<TSchema extends ImplicitFieldSchema>(view:
242
267
  export function createIndependentTreeAlpha<const TSchema extends ImplicitFieldSchema>(options?: CreateIndependentTreeAlphaOptions): ViewableTree & Pick<ITreeAlpha, "exportVerbose" | "exportSimpleSchema">;
243
268
 
244
269
  // @alpha
245
- export type CreateIndependentTreeAlphaOptions = ForestOptions & ((IndependentViewOptions & {
270
+ export type CreateIndependentTreeAlphaOptions = ForestOptions & IndependentViewTelemetryOptions & ((IndependentViewOptions & {
246
271
  content?: never;
247
272
  }) | (ICodecOptions & {
248
273
  content: ViewContent;
@@ -538,16 +563,21 @@ export function incrementalEncodingPolicyForAllowedTypes(rootSchema: TreeSchema)
538
563
  export const incrementalSummaryHint: unique symbol;
539
564
 
540
565
  // @alpha
541
- export function independentInitializedView<const TSchema extends ImplicitFieldSchema>(config: TreeViewConfiguration<TSchema>, options: ForestOptions & ICodecOptions, content: ViewContent): TreeViewAlpha<TSchema>;
566
+ export function independentInitializedView<const TSchema extends ImplicitFieldSchema>(config: TreeViewConfiguration<TSchema>, options: ForestOptions & ICodecOptions & IndependentViewTelemetryOptions, content: ViewContent): TreeViewAlpha<TSchema>;
542
567
 
543
568
  // @alpha
544
569
  export function independentView<const TSchema extends ImplicitFieldSchema>(config: TreeViewConfiguration<TSchema>, options?: IndependentViewOptions): TreeViewAlpha<TSchema>;
545
570
 
546
571
  // @alpha @input
547
- export interface IndependentViewOptions extends ForestOptions, Partial<CodecWriteOptions> {
572
+ export interface IndependentViewOptions extends ForestOptions, Partial<CodecWriteOptions>, IndependentViewTelemetryOptions {
548
573
  idCompressor?: IIdCompressor | undefined;
549
574
  }
550
575
 
576
+ // @alpha @input
577
+ export interface IndependentViewTelemetryOptions {
578
+ readonly logger?: ITelemetryBaseLogger | undefined;
579
+ }
580
+
551
581
  // @public @system
552
582
  type _InlineTrick = 0;
553
583
 
@@ -648,10 +678,11 @@ export interface ITree extends ViewableTree, IFluidLoadable {
648
678
 
649
679
  // @alpha @sealed
650
680
  export interface ITreeAlpha extends ITree {
651
- createSharedBranch(): string;
681
+ createSharedBranch(name?: string): string;
652
682
  exportSimpleSchema(): SimpleTreeSchema;
653
683
  exportVerbose(): VerboseTree | undefined;
654
684
  getSharedBranchIds(): string[];
685
+ getSharedBranchName(branchId: string): string | undefined;
655
686
  viewSharedBranchWith<TRoot extends ImplicitFieldSchema>(branchId: string, config: TreeViewConfiguration<TRoot>): TreeView<TRoot>;
656
687
  }
657
688
 
@@ -844,6 +875,9 @@ export const MapNodeSchema: {
844
875
  readonly [Symbol.hasInstance]: (value: TreeNodeSchema) => value is MapNodeSchema;
845
876
  };
846
877
 
878
+ // @alpha @deprecated
879
+ export const minimize: TransactionPostProcessor;
880
+
847
881
  // @alpha
848
882
  export interface NoChangeConstraint {
849
883
  // (undocumented)
@@ -1248,6 +1282,7 @@ export interface SharedTreeFormatOptions {
1248
1282
  // @alpha @input
1249
1283
  export interface SharedTreeOptions extends SharedTreeOptionsBeta, Partial<CodecWriteOptions>, Partial<SharedTreeFormatOptions> {
1250
1284
  readonly enableSharedBranches?: boolean;
1285
+ readonly retainHistory?: boolean;
1251
1286
  shouldEncodeIncrementally?: IncrementalEncodingPolicy;
1252
1287
  }
1253
1288
 
@@ -1454,7 +1489,7 @@ export namespace System_Unsafe {
1454
1489
  // @system
1455
1490
  export type InsertableTreeNodeFromAllowedTypesUnsafe<TList extends AllowedTypesUnsafe> = IsUnion<TList> extends true ? never : {
1456
1491
  readonly [Property in keyof TList]: TList[Property] extends LazyItem<infer TSchema extends TreeNodeSchemaUnsafe> ? InsertableTypedNodeUnsafe<TSchema> : never;
1457
- }[number];
1492
+ }[NumberKeys<TList>];
1458
1493
  // @system
1459
1494
  export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends ImplicitAllowedTypesUnsafe> = [TSchema] extends [TreeNodeSchemaUnsafe] ? InsertableTypedNodeUnsafe<TSchema> : [TSchema] extends [AllowedTypesUnsafe] ? InsertableTreeNodeFromAllowedTypesUnsafe<TSchema> : never;
1460
1495
  // @system
@@ -1749,7 +1784,14 @@ export const TreeArrayNode: {
1749
1784
 
1750
1785
  // @alpha @sealed
1751
1786
  export interface TreeArrayNodeAlpha<TAllowedTypes extends System_Unsafe.ImplicitAllowedTypesUnsafe = ImplicitAllowedTypes, out T = [TAllowedTypes] extends [ImplicitAllowedTypes] ? TreeNodeFromImplicitAllowedTypes<TAllowedTypes> : TreeNodeFromImplicitAllowedTypes<ImplicitAllowedTypes>, in TNew = [TAllowedTypes] extends [ImplicitAllowedTypes] ? InsertableTreeNodeFromImplicitAllowedTypes<TAllowedTypes> : InsertableTreeNodeFromImplicitAllowedTypes<ImplicitAllowedTypes>> extends TreeArrayNode<TAllowedTypes, T, TNew> {
1787
+ at(index: number): T | undefined;
1788
+ findLast<S extends T>(predicate: (value: T, index: number, array: readonly T[]) => value is S, thisArg?: unknown): S | undefined;
1789
+ findLast(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: unknown): T | undefined;
1790
+ findLastIndex(predicate: (value: T, index: number, array: readonly T[]) => unknown, thisArg?: unknown): number;
1791
+ pop(): T | undefined;
1792
+ shift(): T | undefined;
1752
1793
  splice(start: number, deleteCount?: number, ...items: readonly (TNew | IterableTreeArrayContent<TNew>)[]): T[];
1794
+ unshift(...value: readonly (TNew | IterableTreeArrayContent<TNew>)[]): void;
1753
1795
  }
1754
1796
 
1755
1797
  // @beta @sealed
@@ -1776,6 +1818,7 @@ export interface TreeBranch extends IDisposable {
1776
1818
  // @alpha @sealed
1777
1819
  export interface TreeBranchAlpha extends TreeBranch, TreeContextAlpha {
1778
1820
  applyChange(change: JsonCompatibleReadOnly): void;
1821
+ computeNetChangeIfRebasedOnto(branch: TreeBranch): JsonCompatibleReadOnly | undefined;
1779
1822
  readonly events: Listenable_2<TreeBranchEvents>;
1780
1823
  // (undocumented)
1781
1824
  fork(): TreeBranchAlpha;
@@ -737,7 +737,7 @@ export namespace System_Unsafe {
737
737
  // @system
738
738
  export type InsertableTreeNodeFromAllowedTypesUnsafe<TList extends AllowedTypesUnsafe> = IsUnion<TList> extends true ? never : {
739
739
  readonly [Property in keyof TList]: TList[Property] extends LazyItem<infer TSchema extends TreeNodeSchemaUnsafe> ? InsertableTypedNodeUnsafe<TSchema> : never;
740
- }[number];
740
+ }[NumberKeys<TList>];
741
741
  // @system
742
742
  export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends ImplicitAllowedTypesUnsafe> = [TSchema] extends [TreeNodeSchemaUnsafe] ? InsertableTypedNodeUnsafe<TSchema> : [TSchema] extends [AllowedTypesUnsafe] ? InsertableTreeNodeFromAllowedTypesUnsafe<TSchema> : never;
743
743
  // @system
@@ -749,7 +749,7 @@ export namespace System_Unsafe {
749
749
  // @system
750
750
  export type InsertableTreeNodeFromAllowedTypesUnsafe<TList extends AllowedTypesUnsafe> = IsUnion<TList> extends true ? never : {
751
751
  readonly [Property in keyof TList]: TList[Property] extends LazyItem<infer TSchema extends TreeNodeSchemaUnsafe> ? InsertableTypedNodeUnsafe<TSchema> : never;
752
- }[number];
752
+ }[NumberKeys<TList>];
753
753
  // @system
754
754
  export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends ImplicitAllowedTypesUnsafe> = [TSchema] extends [TreeNodeSchemaUnsafe] ? InsertableTypedNodeUnsafe<TSchema> : [TSchema] extends [AllowedTypesUnsafe] ? InsertableTreeNodeFromAllowedTypesUnsafe<TSchema> : never;
755
755
  // @system
@@ -391,7 +391,7 @@ export namespace System_Unsafe {
391
391
  // @system
392
392
  export type InsertableTreeNodeFromAllowedTypesUnsafe<TList extends AllowedTypesUnsafe> = IsUnion<TList> extends true ? never : {
393
393
  readonly [Property in keyof TList]: TList[Property] extends LazyItem<infer TSchema extends TreeNodeSchemaUnsafe> ? InsertableTypedNodeUnsafe<TSchema> : never;
394
- }[number];
394
+ }[NumberKeys<TList>];
395
395
  // @system
396
396
  export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends ImplicitAllowedTypesUnsafe> = [TSchema] extends [TreeNodeSchemaUnsafe] ? InsertableTypedNodeUnsafe<TSchema> : [TSchema] extends [AllowedTypesUnsafe] ? InsertableTreeNodeFromAllowedTypesUnsafe<TSchema> : never;
397
397
  // @system
@@ -391,7 +391,7 @@ export namespace System_Unsafe {
391
391
  // @system
392
392
  export type InsertableTreeNodeFromAllowedTypesUnsafe<TList extends AllowedTypesUnsafe> = IsUnion<TList> extends true ? never : {
393
393
  readonly [Property in keyof TList]: TList[Property] extends LazyItem<infer TSchema extends TreeNodeSchemaUnsafe> ? InsertableTypedNodeUnsafe<TSchema> : never;
394
- }[number];
394
+ }[NumberKeys<TList>];
395
395
  // @system
396
396
  export type InsertableTreeNodeFromImplicitAllowedTypesUnsafe<TSchema extends ImplicitAllowedTypesUnsafe> = [TSchema] extends [TreeNodeSchemaUnsafe] ? InsertableTypedNodeUnsafe<TSchema> : [TSchema] extends [AllowedTypesUnsafe] ? InsertableTreeNodeFromAllowedTypesUnsafe<TSchema> : never;
397
397
  // @system
@@ -0,0 +1,198 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+ /**
6
+ * Utilities for composing application "components" which contribute to a shared configuration.
7
+ *
8
+ * @remarks
9
+ * Nothing in this namespace is specific to tree schema,
10
+ * however it is designed to be able to handle the needs of components which work with {@link TreeSchema}.
11
+ *
12
+ * This is mainly used to implement "open polymorphism", where the set of allowed types
13
+ * for a field or collection can be extended by independently authored libraries (components) instead of being
14
+ * fixed up front.
15
+ *
16
+ * This basically amounts to dependency injection, where the "injection" is done at "composition" time to build the schema.
17
+ *
18
+ * Tree's schema do not natively support open polymorphism: all possible implementations must be explicitly listed.
19
+ * These tools work around these limitations by carefully controlling evaluation order:
20
+ * the source code can be structured in an open polymorphism style which at runtime evaluates into closed polymorphism
21
+ * by having each component register its implementations into a central collection (typically an
22
+ * {@link AllowedTypes} array).
23
+ *
24
+ * Each component is expressed as a {@link Component.Factory}: a function which receives a lazy reference to the
25
+ * composed configuration and returns the content that component contributes.
26
+ * Because the configuration is provided lazily, components may reference (including recursively) types contributed by
27
+ * other components, as long as nothing evaluates the lazy references until composition has completed.
28
+ * Use {@link Component.(compose:1)} to combine a set of components into a {@link Component.Composed}.
29
+ *
30
+ * See {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/src/test/openPolymorphism.integration.ts|openPolymorphism.integration.ts} for worked examples of this pattern.
31
+ *
32
+ * @privateRemarks
33
+ * The examples and integration tests for this pattern live in `openPolymorphism.integration.ts`.
34
+ * Those tests and the docs here should be kept in sync.
35
+ *
36
+ * @alpha
37
+ */
38
+ export declare namespace Component {
39
+ /**
40
+ * A function which takes in a lazy configuration and returns the content a component contributes.
41
+ *
42
+ * @remarks
43
+ * The lazy configuration allows the component to reference items from the composed configuration, which can
44
+ * include items the component itself contributes (allowing recursive references between components).
45
+ *
46
+ * The execution of the factory must not evaluate `lazyConfiguration` (doing so will error):
47
+ * instead the returned `TComponent` can capture `lazyConfiguration` and evaluate it at a later time
48
+ * (after all components have been composed).
49
+ *
50
+ * @typeParam TComponent - The content a component contributes.
51
+ * @typeParam TConfig - The composed configuration type made available to components.
52
+ * Defaults to the {@link Component.Composed} produced by composition: the common case where
53
+ * components read composed content directly from the composition and no custom configuration type is needed.
54
+ *
55
+ * @input
56
+ * @alpha
57
+ */
58
+ type Factory<TComponent, TConfig = ComposedDefault<TComponent>> = (lazyConfiguration: () => TConfig) => TComponent;
59
+ /**
60
+ * A function which returns an array of lazy values which each evaluate to `T`.
61
+ *
62
+ * @remarks
63
+ * This mirrors the shape of {@link AllowedTypes} where all of the values are lazy:
64
+ * the outer function and inner functions defer evaluation until after composition is complete.
65
+ *
66
+ * @typeParam T - The type each lazy value evaluates to.
67
+ *
68
+ * @alpha
69
+ */
70
+ type LazyArray<T> = () => readonly (() => T)[];
71
+ /**
72
+ * Wrap a 0 argument function to cache the result.
73
+ * @remarks
74
+ * Do not use for impure functions.
75
+ *
76
+ * Generally {@link Component} utilities have built in caching in most cases,
77
+ * but this is occasionally helpful when manually implementing laziness.
78
+ *
79
+ * Note that this takes a different approach than use in {@link evaluateLazySchema} where the function evaluation is done using a utility that adds caching.
80
+ *
81
+ * @param factory - The factory function to memoize.
82
+ * @returns A function that returns the cached result of the factory.
83
+ * @alpha
84
+ */
85
+ const memoize: <T>(factory: () => T) => (() => T);
86
+ /**
87
+ * An item which can be configured (evaluated) against a composed configuration to produce a result.
88
+ *
89
+ * @remarks
90
+ * Use {@link Component.Composed.getConfigured} to evaluate a `Configurable`.
91
+ * The result is cached, so a given `Configurable` is only evaluated once per composition.
92
+ *
93
+ * @typeParam TConfigPartial - The configuration type made available when configuring.
94
+ * @typeParam TResult - The result produced by configuring.
95
+ * @typeParam TComponent - The content components contribute.
96
+ *
97
+ * @alpha
98
+ */
99
+ interface Configurable<TConfigPartial, out TResult, TComponent> {
100
+ /**
101
+ * Produce the configured result.
102
+ * @param config - The composed configuration.
103
+ * @param components - The composed components.
104
+ */
105
+ configure(config: TConfigPartial, components: Composed<TComponent, TConfigPartial>): TResult;
106
+ }
107
+ /**
108
+ * Combine multiple {@link Component.Factory|components} into a single {@link Component.Composed}.
109
+ *
110
+ * @remarks
111
+ * The {@link Component.Composed} itself is used as the configuration made available to components:
112
+ * the simple case where components read composed content directly from the composition.
113
+ * To produce a custom aggregated configuration, use the overload which takes a `lazyConfiguration` builder.
114
+ *
115
+ * @param allComponents - The components to compose.
116
+ * @returns The composed components, from which configuration and per-component content can be read.
117
+ *
118
+ * @typeParam TComponent - The content each component contributes.
119
+ *
120
+ * @alpha
121
+ */
122
+ function compose<TComponent>(allComponents: readonly Factory<TComponent>[]): Composed<TComponent>;
123
+ /**
124
+ * Combine multiple {@link Component.Factory|components} into a single {@link Component.Composed}.
125
+ *
126
+ * @param allComponents - The components to compose.
127
+ * @param lazyConfiguration - Builds the composed configuration from the composed components.
128
+ * This is invoked once, after all components have been created, and can aggregate content contributed by the
129
+ * components (for example via {@link Component.Composed.getComposed}).
130
+ * @returns The composed components, from which configuration and per-component content can be read.
131
+ *
132
+ * @typeParam TComponent - The content each component contributes.
133
+ * @typeParam TConfig - The composed configuration type made available to components.
134
+ *
135
+ * @alpha
136
+ */
137
+ function compose<TComponent, TConfig>(allComponents: readonly Factory<TComponent, TConfig>[], lazyConfiguration: (composed: Composed<TComponent, TConfig>) => TConfig): Composed<TComponent, TConfig>;
138
+ /**
139
+ * The default configuration type for a composition.
140
+ * Also the type of Composed when using the default composition.
141
+ * @privateRemarks
142
+ * Declaring this as its own type makes the recursion possible instead of having to list the config parameter as unknown.
143
+ * This makes it easier to understand what is going on when seeing this type in the intellisense.
144
+ * @sealed @alpha
145
+ */
146
+ type ComposedDefault<TComponent> = Composed<TComponent, ComposedDefault<TComponent>>;
147
+ /**
148
+ * The result of composing multiple components.
149
+ *
150
+ * @remarks
151
+ * Create using {@link Component.(compose:1)}.
152
+ *
153
+ * @typeParam TComponent - The content each component contributes.
154
+ * @typeParam TConfig - The composed configuration type made available to components.
155
+ * Defaults to the composition itself: the common case where no custom configuration type is needed.
156
+ *
157
+ * @sealed @alpha
158
+ */
159
+ interface Composed<TComponent, TConfig = ComposedDefault<TComponent>> {
160
+ /**
161
+ * The components which were composed.
162
+ */
163
+ readonly components: readonly TComponent[];
164
+ /**
165
+ * The configuration which was produced when composing.
166
+ */
167
+ readonly config: TConfig;
168
+ /**
169
+ * Get a component by its factory.
170
+ *
171
+ * @param factory - The factory used to look up the component. Must have been provided when composing.
172
+ * @returns The content created by the provided factory.
173
+ * This result is cached during composition and not reevaluated.
174
+ */
175
+ getComponent<TFactory extends Factory<TComponent, TConfig>>(factory: TFactory): ReturnType<TFactory>;
176
+ /**
177
+ * Configure a {@link Component.Configurable}.
178
+ * @remarks
179
+ * The result is cached when first evaluated, so subsequent calls with the same `configurable` return the
180
+ * same result.
181
+ * @param configurable - The item to configure against this composition.
182
+ */
183
+ getConfigured<TConfigurable extends Configurable<TConfig, unknown, TComponent>>(configurable: TConfigurable): ReturnType<TConfigurable["configure"]>;
184
+ /**
185
+ * Compose the contents of a {@link Component.LazyArray} property from all components.
186
+ * @remarks
187
+ * The result is cached when first evaluated, so subsequent calls with the same `property` return the
188
+ * same result.
189
+ * @param property - The property of the components to compose.
190
+ * @returns The concatenation of the lazy values contributed by each component for `property`.
191
+ * Components which omit the property contribute nothing.
192
+ */
193
+ getComposed<TKey extends keyof {
194
+ [Property in keyof TComponent as TComponent[Property] extends LazyArray<unknown> | undefined ? Property : never]: boolean;
195
+ }>(property: TKey): readonly (Exclude<TComponent[TKey], undefined> extends LazyArray<infer U> ? () => U : never)[];
196
+ }
197
+ }
198
+ //# sourceMappingURL=componentApi.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"componentApi.d.ts","sourceRoot":"","sources":["../src/componentApi.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,yBAAiB,SAAS,CAAC;IAC1B;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAY,OAAO,CAAC,UAAU,EAAE,OAAO,GAAG,eAAe,CAAC,UAAU,CAAC,IAAI,CACxE,iBAAiB,EAAE,MAAM,OAAO,KAC5B,UAAU,CAAC;IAEhB;;;;;;;;;;OAUG;IACH,KAAY,SAAS,CAAC,CAAC,IAAI,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAEtD;;;;;;;;;;;;;OAaG;IACI,MAAM,OAAO,eAAgB,MAAM,CAAC,KAAG,CAAC,MAAM,CAAC,CAUrD,CAAC;IAEF;;;;;;;;;;;;OAYG;IACH,UAAiB,YAAY,CAAC,cAAc,EAAE,GAAG,CAAC,OAAO,EAAE,UAAU;QACpE;;;;WAIG;QACH,SAAS,CACR,MAAM,EAAE,cAAc,EACtB,UAAU,EAAE,QAAQ,CAAC,UAAU,EAAE,cAAc,CAAC,GAC9C,OAAO,CAAC;KACX;IAuGD;;;;;;;;;;;;;;OAcG;IACH,SAAgB,OAAO,CAAC,UAAU,EACjC,aAAa,EAAE,SAAS,OAAO,CAAC,UAAU,CAAC,EAAE,GAC3C,QAAQ,CAAC,UAAU,CAAC,CAAC;IACxB;;;;;;;;;;;;;OAaG;IACH,SAAgB,OAAO,CAAC,UAAU,EAAE,OAAO,EAC1C,aAAa,EAAE,SAAS,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,EAAE,EACtD,iBAAiB,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,KAAK,OAAO,GACrE,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;IASjC;;;;;;;OAOG;IACH,KAAY,eAAe,CAAC,UAAU,IAAI,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC,UAAU,CAAC,CAAC,CAAC;IAE5F;;;;;;;;;;;OAWG;IACH,UAAiB,QAAQ,CAAC,UAAU,EAAE,OAAO,GAAG,eAAe,CAAC,UAAU,CAAC;QAC1E;;WAEG;QACH,QAAQ,CAAC,UAAU,EAAE,SAAS,UAAU,EAAE,CAAC;QAE3C;;WAEG;QACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;QAEzB;;;;;;WAMG;QACH,YAAY,CAAC,QAAQ,SAAS,OAAO,CAAC,UAAU,EAAE,OAAO,CAAC,EACzD,OAAO,EAAE,QAAQ,GACf,UAAU,CAAC,QAAQ,CAAC,CAAC;QAExB;;;;;;WAMG;QACH,aAAa,CAAC,aAAa,SAAS,YAAY,CAAC,OAAO,EAAE,OAAO,EAAE,UAAU,CAAC,EAC7E,YAAY,EAAE,aAAa,GACzB,UAAU,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;QAE1C;;;;;;;;WAQG;QACH,WAAW,CACV,IAAI,SAAS,MAAM;aACjB,QAAQ,IAAI,MAAM,UAAU,IAAI,UAAU,CAAC,QAAQ,CAAC,SAClD,SAAS,CAAC,OAAO,CAAC,GAClB,SAAS,GACT,QAAQ,GACR,KAAK,GAAG,OAAO;SAClB,EAED,QAAQ,EAAE,IAAI,GACZ,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,GACzE,MAAM,CAAC,GACP,KAAK,CAAC,EAAE,CAAC;KACZ;CACD"}