@fluidframework/tree 2.61.0 → 2.62.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 (388) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/api-report/tree.alpha.api.md +26 -21
  3. package/api-report/tree.beta.api.md +15 -0
  4. package/api-report/tree.legacy.beta.api.md +18 -0
  5. package/dist/alpha.d.ts +8 -8
  6. package/dist/api.d.ts +17 -0
  7. package/dist/api.d.ts.map +1 -0
  8. package/dist/api.js +24 -0
  9. package/dist/api.js.map +1 -0
  10. package/dist/beta.d.ts +5 -0
  11. package/dist/codec/codec.d.ts +3 -5
  12. package/dist/codec/codec.d.ts.map +1 -1
  13. package/dist/codec/codec.js +9 -2
  14. package/dist/codec/codec.js.map +1 -1
  15. package/dist/codec/index.d.ts +0 -1
  16. package/dist/codec/index.d.ts.map +1 -1
  17. package/dist/codec/index.js +1 -3
  18. package/dist/codec/index.js.map +1 -1
  19. package/dist/core/index.d.ts +1 -1
  20. package/dist/core/index.d.ts.map +1 -1
  21. package/dist/core/index.js +2 -1
  22. package/dist/core/index.js.map +1 -1
  23. package/dist/core/rebase/index.d.ts +1 -1
  24. package/dist/core/rebase/index.d.ts.map +1 -1
  25. package/dist/core/rebase/index.js +2 -1
  26. package/dist/core/rebase/index.js.map +1 -1
  27. package/dist/core/rebase/utils.d.ts +10 -0
  28. package/dist/core/rebase/utils.d.ts.map +1 -1
  29. package/dist/core/rebase/utils.js +20 -1
  30. package/dist/core/rebase/utils.js.map +1 -1
  31. package/dist/core/tree/detachedFieldIndex.js +1 -1
  32. package/dist/core/tree/detachedFieldIndex.js.map +1 -1
  33. package/dist/external-utilities/index.d.ts +1 -1
  34. package/dist/external-utilities/index.d.ts.map +1 -1
  35. package/dist/external-utilities/index.js +1 -2
  36. package/dist/external-utilities/index.js.map +1 -1
  37. package/dist/external-utilities/typeboxValidator.d.ts +0 -13
  38. package/dist/external-utilities/typeboxValidator.d.ts.map +1 -1
  39. package/dist/external-utilities/typeboxValidator.js +3 -5
  40. package/dist/external-utilities/typeboxValidator.js.map +1 -1
  41. package/dist/feature-libraries/flex-tree/flexTreeTypes.d.ts +2 -0
  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/flex-tree/index.d.ts +1 -0
  45. package/dist/feature-libraries/flex-tree/index.d.ts.map +1 -1
  46. package/dist/feature-libraries/flex-tree/index.js +4 -1
  47. package/dist/feature-libraries/flex-tree/index.js.map +1 -1
  48. package/dist/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  49. package/dist/feature-libraries/flex-tree/lazyNode.js +15 -8
  50. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  51. package/dist/feature-libraries/flex-tree/observer.d.ts +32 -0
  52. package/dist/feature-libraries/flex-tree/observer.d.ts.map +1 -0
  53. package/dist/feature-libraries/flex-tree/observer.js +33 -0
  54. package/dist/feature-libraries/flex-tree/observer.js.map +1 -0
  55. package/dist/feature-libraries/index.d.ts +1 -1
  56. package/dist/feature-libraries/index.d.ts.map +1 -1
  57. package/dist/feature-libraries/index.js +3 -1
  58. package/dist/feature-libraries/index.js.map +1 -1
  59. package/dist/index.d.ts +5 -5
  60. package/dist/index.d.ts.map +1 -1
  61. package/dist/index.js +9 -8
  62. package/dist/index.js.map +1 -1
  63. package/dist/legacy.d.ts +7 -1
  64. package/dist/packageVersion.d.ts +1 -1
  65. package/dist/packageVersion.js +1 -1
  66. package/dist/packageVersion.js.map +1 -1
  67. package/dist/shared-tree/index.d.ts +2 -2
  68. package/dist/shared-tree/index.d.ts.map +1 -1
  69. package/dist/shared-tree/index.js.map +1 -1
  70. package/dist/shared-tree/schematizingTreeView.js +2 -2
  71. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  72. package/dist/shared-tree/sharedTree.d.ts +21 -6
  73. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  74. package/dist/shared-tree/sharedTree.js +76 -37
  75. package/dist/shared-tree/sharedTree.js.map +1 -1
  76. package/dist/shared-tree/treeAlpha.d.ts +114 -1
  77. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  78. package/dist/shared-tree/treeAlpha.js +140 -1
  79. package/dist/shared-tree/treeAlpha.js.map +1 -1
  80. package/dist/shared-tree/treeCheckout.d.ts +13 -7
  81. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  82. package/dist/shared-tree/treeCheckout.js +115 -85
  83. package/dist/shared-tree/treeCheckout.js.map +1 -1
  84. package/dist/shared-tree-core/branch.d.ts +3 -0
  85. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  86. package/dist/shared-tree-core/branch.js.map +1 -1
  87. package/dist/shared-tree-core/branchIdCodec.d.ts +11 -0
  88. package/dist/shared-tree-core/branchIdCodec.d.ts.map +1 -0
  89. package/dist/shared-tree-core/branchIdCodec.js +18 -0
  90. package/dist/shared-tree-core/branchIdCodec.js.map +1 -0
  91. package/dist/shared-tree-core/editManager.d.ts +39 -64
  92. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  93. package/dist/shared-tree-core/editManager.js +455 -295
  94. package/dist/shared-tree-core/editManager.js.map +1 -1
  95. package/dist/shared-tree-core/editManagerCodecs.d.ts +1 -1
  96. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  97. package/dist/shared-tree-core/editManagerCodecs.js +7 -96
  98. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  99. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +17 -0
  100. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -0
  101. package/dist/shared-tree-core/editManagerCodecsCommons.js +139 -0
  102. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -0
  103. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +16 -0
  104. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -0
  105. package/dist/shared-tree-core/editManagerCodecsV1toV4.js +39 -0
  106. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -0
  107. package/dist/shared-tree-core/editManagerCodecsV5.d.ts +16 -0
  108. package/dist/shared-tree-core/editManagerCodecsV5.d.ts.map +1 -0
  109. package/dist/shared-tree-core/editManagerCodecsV5.js +58 -0
  110. package/dist/shared-tree-core/editManagerCodecsV5.js.map +1 -0
  111. package/dist/shared-tree-core/{editManagerFormat.d.ts → editManagerFormatCommons.d.ts} +31 -7
  112. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -0
  113. package/dist/shared-tree-core/{editManagerFormat.js → editManagerFormatCommons.js} +13 -12
  114. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -0
  115. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +31 -0
  116. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -0
  117. package/dist/shared-tree-core/editManagerFormatV1toV4.js +24 -0
  118. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -0
  119. package/dist/shared-tree-core/editManagerFormatV5.d.ts +62 -0
  120. package/dist/shared-tree-core/editManagerFormatV5.d.ts.map +1 -0
  121. package/dist/shared-tree-core/editManagerFormatV5.js +20 -0
  122. package/dist/shared-tree-core/editManagerFormatV5.js.map +1 -0
  123. package/dist/shared-tree-core/index.d.ts +3 -3
  124. package/dist/shared-tree-core/index.d.ts.map +1 -1
  125. package/dist/shared-tree-core/index.js.map +1 -1
  126. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +11 -0
  127. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -0
  128. package/dist/shared-tree-core/messageCodecV1ToV4.js +59 -0
  129. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -0
  130. package/dist/shared-tree-core/messageCodecV5.d.ts +11 -0
  131. package/dist/shared-tree-core/messageCodecV5.d.ts.map +1 -0
  132. package/dist/shared-tree-core/messageCodecV5.js +78 -0
  133. package/dist/shared-tree-core/messageCodecV5.js.map +1 -0
  134. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  135. package/dist/shared-tree-core/messageCodecs.js +16 -47
  136. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  137. package/dist/shared-tree-core/{messageFormat.d.ts → messageFormatV1ToV4.d.ts} +1 -1
  138. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -0
  139. package/dist/shared-tree-core/{messageFormat.js → messageFormatV1ToV4.js} +1 -1
  140. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -0
  141. package/dist/shared-tree-core/messageFormatV5.d.ts +42 -0
  142. package/dist/shared-tree-core/messageFormatV5.d.ts.map +1 -0
  143. package/dist/shared-tree-core/messageFormatV5.js +20 -0
  144. package/dist/shared-tree-core/messageFormatV5.js.map +1 -0
  145. package/dist/shared-tree-core/messageTypes.d.ts +12 -2
  146. package/dist/shared-tree-core/messageTypes.d.ts.map +1 -1
  147. package/dist/shared-tree-core/messageTypes.js.map +1 -1
  148. package/dist/shared-tree-core/sequenceIdUtils.d.ts +1 -1
  149. package/dist/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  150. package/dist/shared-tree-core/sequenceIdUtils.js.map +1 -1
  151. package/dist/shared-tree-core/sharedTreeCore.d.ts +19 -5
  152. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  153. package/dist/shared-tree-core/sharedTreeCore.js +182 -58
  154. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  155. package/dist/simple-tree/api/tree.d.ts +17 -0
  156. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  157. package/dist/simple-tree/api/tree.js +2 -0
  158. package/dist/simple-tree/api/tree.js.map +1 -1
  159. package/dist/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  160. package/dist/simple-tree/core/unhydratedFlexTree.js +7 -1
  161. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  162. package/dist/treeFactory.d.ts +38 -9
  163. package/dist/treeFactory.d.ts.map +1 -1
  164. package/dist/treeFactory.js +44 -9
  165. package/dist/treeFactory.js.map +1 -1
  166. package/lib/alpha.d.ts +8 -8
  167. package/lib/api.d.ts +17 -0
  168. package/lib/api.d.ts.map +1 -0
  169. package/lib/api.js +22 -0
  170. package/lib/api.js.map +1 -0
  171. package/lib/beta.d.ts +5 -0
  172. package/lib/codec/codec.d.ts +3 -5
  173. package/lib/codec/codec.d.ts.map +1 -1
  174. package/lib/codec/codec.js +8 -1
  175. package/lib/codec/codec.js.map +1 -1
  176. package/lib/codec/index.d.ts +0 -1
  177. package/lib/codec/index.d.ts.map +1 -1
  178. package/lib/codec/index.js +0 -1
  179. package/lib/codec/index.js.map +1 -1
  180. package/lib/core/index.d.ts +1 -1
  181. package/lib/core/index.d.ts.map +1 -1
  182. package/lib/core/index.js +1 -1
  183. package/lib/core/index.js.map +1 -1
  184. package/lib/core/rebase/index.d.ts +1 -1
  185. package/lib/core/rebase/index.d.ts.map +1 -1
  186. package/lib/core/rebase/index.js +1 -1
  187. package/lib/core/rebase/index.js.map +1 -1
  188. package/lib/core/rebase/utils.d.ts +10 -0
  189. package/lib/core/rebase/utils.d.ts.map +1 -1
  190. package/lib/core/rebase/utils.js +18 -0
  191. package/lib/core/rebase/utils.js.map +1 -1
  192. package/lib/core/tree/detachedFieldIndex.js +2 -2
  193. package/lib/core/tree/detachedFieldIndex.js.map +1 -1
  194. package/lib/external-utilities/index.d.ts +1 -1
  195. package/lib/external-utilities/index.d.ts.map +1 -1
  196. package/lib/external-utilities/index.js +1 -1
  197. package/lib/external-utilities/index.js.map +1 -1
  198. package/lib/external-utilities/typeboxValidator.d.ts +0 -13
  199. package/lib/external-utilities/typeboxValidator.d.ts.map +1 -1
  200. package/lib/external-utilities/typeboxValidator.js +1 -3
  201. package/lib/external-utilities/typeboxValidator.js.map +1 -1
  202. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts +2 -0
  203. package/lib/feature-libraries/flex-tree/flexTreeTypes.d.ts.map +1 -1
  204. package/lib/feature-libraries/flex-tree/flexTreeTypes.js.map +1 -1
  205. package/lib/feature-libraries/flex-tree/index.d.ts +1 -0
  206. package/lib/feature-libraries/flex-tree/index.d.ts.map +1 -1
  207. package/lib/feature-libraries/flex-tree/index.js +1 -0
  208. package/lib/feature-libraries/flex-tree/index.js.map +1 -1
  209. package/lib/feature-libraries/flex-tree/lazyNode.d.ts.map +1 -1
  210. package/lib/feature-libraries/flex-tree/lazyNode.js +15 -8
  211. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  212. package/lib/feature-libraries/flex-tree/observer.d.ts +32 -0
  213. package/lib/feature-libraries/flex-tree/observer.d.ts.map +1 -0
  214. package/lib/feature-libraries/flex-tree/observer.js +40 -0
  215. package/lib/feature-libraries/flex-tree/observer.js.map +1 -0
  216. package/lib/feature-libraries/index.d.ts +1 -1
  217. package/lib/feature-libraries/index.d.ts.map +1 -1
  218. package/lib/feature-libraries/index.js +1 -1
  219. package/lib/feature-libraries/index.js.map +1 -1
  220. package/lib/index.d.ts +5 -5
  221. package/lib/index.d.ts.map +1 -1
  222. package/lib/index.js +3 -3
  223. package/lib/index.js.map +1 -1
  224. package/lib/legacy.d.ts +7 -1
  225. package/lib/packageVersion.d.ts +1 -1
  226. package/lib/packageVersion.js +1 -1
  227. package/lib/packageVersion.js.map +1 -1
  228. package/lib/shared-tree/index.d.ts +2 -2
  229. package/lib/shared-tree/index.d.ts.map +1 -1
  230. package/lib/shared-tree/index.js.map +1 -1
  231. package/lib/shared-tree/schematizingTreeView.js +2 -2
  232. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  233. package/lib/shared-tree/sharedTree.d.ts +21 -6
  234. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  235. package/lib/shared-tree/sharedTree.js +78 -39
  236. package/lib/shared-tree/sharedTree.js.map +1 -1
  237. package/lib/shared-tree/treeAlpha.d.ts +114 -1
  238. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  239. package/lib/shared-tree/treeAlpha.js +143 -4
  240. package/lib/shared-tree/treeAlpha.js.map +1 -1
  241. package/lib/shared-tree/treeCheckout.d.ts +13 -7
  242. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  243. package/lib/shared-tree/treeCheckout.js +117 -87
  244. package/lib/shared-tree/treeCheckout.js.map +1 -1
  245. package/lib/shared-tree-core/branch.d.ts +3 -0
  246. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  247. package/lib/shared-tree-core/branch.js.map +1 -1
  248. package/lib/shared-tree-core/branchIdCodec.d.ts +11 -0
  249. package/lib/shared-tree-core/branchIdCodec.d.ts.map +1 -0
  250. package/lib/shared-tree-core/branchIdCodec.js +13 -0
  251. package/lib/shared-tree-core/branchIdCodec.js.map +1 -0
  252. package/lib/shared-tree-core/editManager.d.ts +39 -64
  253. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  254. package/lib/shared-tree-core/editManager.js +455 -295
  255. package/lib/shared-tree-core/editManager.js.map +1 -1
  256. package/lib/shared-tree-core/editManagerCodecs.d.ts +1 -1
  257. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  258. package/lib/shared-tree-core/editManagerCodecs.js +4 -93
  259. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  260. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +17 -0
  261. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -0
  262. package/lib/shared-tree-core/editManagerCodecsCommons.js +134 -0
  263. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -0
  264. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +16 -0
  265. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -0
  266. package/lib/shared-tree-core/editManagerCodecsV1toV4.js +35 -0
  267. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -0
  268. package/lib/shared-tree-core/editManagerCodecsV5.d.ts +16 -0
  269. package/lib/shared-tree-core/editManagerCodecsV5.d.ts.map +1 -0
  270. package/lib/shared-tree-core/editManagerCodecsV5.js +54 -0
  271. package/lib/shared-tree-core/editManagerCodecsV5.js.map +1 -0
  272. package/lib/shared-tree-core/{editManagerFormat.d.ts → editManagerFormatCommons.d.ts} +31 -7
  273. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -0
  274. package/lib/shared-tree-core/{editManagerFormat.js → editManagerFormatCommons.js} +10 -11
  275. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -0
  276. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +31 -0
  277. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -0
  278. package/lib/shared-tree-core/editManagerFormatV1toV4.js +20 -0
  279. package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -0
  280. package/lib/shared-tree-core/editManagerFormatV5.d.ts +62 -0
  281. package/lib/shared-tree-core/editManagerFormatV5.d.ts.map +1 -0
  282. package/lib/shared-tree-core/editManagerFormatV5.js +16 -0
  283. package/lib/shared-tree-core/editManagerFormatV5.js.map +1 -0
  284. package/lib/shared-tree-core/index.d.ts +3 -3
  285. package/lib/shared-tree-core/index.d.ts.map +1 -1
  286. package/lib/shared-tree-core/index.js.map +1 -1
  287. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +11 -0
  288. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -0
  289. package/lib/shared-tree-core/messageCodecV1ToV4.js +55 -0
  290. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -0
  291. package/lib/shared-tree-core/messageCodecV5.d.ts +11 -0
  292. package/lib/shared-tree-core/messageCodecV5.d.ts.map +1 -0
  293. package/lib/shared-tree-core/messageCodecV5.js +74 -0
  294. package/lib/shared-tree-core/messageCodecV5.js.map +1 -0
  295. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  296. package/lib/shared-tree-core/messageCodecs.js +17 -48
  297. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  298. package/lib/shared-tree-core/{messageFormat.d.ts → messageFormatV1ToV4.d.ts} +1 -1
  299. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -0
  300. package/lib/shared-tree-core/{messageFormat.js → messageFormatV1ToV4.js} +1 -1
  301. package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -0
  302. package/lib/shared-tree-core/messageFormatV5.d.ts +42 -0
  303. package/lib/shared-tree-core/messageFormatV5.d.ts.map +1 -0
  304. package/lib/shared-tree-core/messageFormatV5.js +16 -0
  305. package/lib/shared-tree-core/messageFormatV5.js.map +1 -0
  306. package/lib/shared-tree-core/messageTypes.d.ts +12 -2
  307. package/lib/shared-tree-core/messageTypes.d.ts.map +1 -1
  308. package/lib/shared-tree-core/messageTypes.js.map +1 -1
  309. package/lib/shared-tree-core/sequenceIdUtils.d.ts +1 -1
  310. package/lib/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  311. package/lib/shared-tree-core/sequenceIdUtils.js.map +1 -1
  312. package/lib/shared-tree-core/sharedTreeCore.d.ts +19 -5
  313. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  314. package/lib/shared-tree-core/sharedTreeCore.js +183 -59
  315. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  316. package/lib/simple-tree/api/tree.d.ts +17 -0
  317. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  318. package/lib/simple-tree/api/tree.js +2 -0
  319. package/lib/simple-tree/api/tree.js.map +1 -1
  320. package/lib/simple-tree/core/unhydratedFlexTree.d.ts.map +1 -1
  321. package/lib/simple-tree/core/unhydratedFlexTree.js +8 -2
  322. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  323. package/lib/treeFactory.d.ts +38 -9
  324. package/lib/treeFactory.d.ts.map +1 -1
  325. package/lib/treeFactory.js +41 -8
  326. package/lib/treeFactory.js.map +1 -1
  327. package/package.json +25 -25
  328. package/src/api.ts +30 -0
  329. package/src/codec/codec.ts +12 -6
  330. package/src/codec/index.ts +0 -1
  331. package/src/core/index.ts +1 -0
  332. package/src/core/rebase/index.ts +1 -0
  333. package/src/core/rebase/utils.ts +27 -0
  334. package/src/core/tree/detachedFieldIndex.ts +2 -2
  335. package/src/external-utilities/index.ts +1 -1
  336. package/src/external-utilities/typeboxValidator.ts +1 -3
  337. package/src/feature-libraries/flex-tree/flexTreeTypes.ts +2 -0
  338. package/src/feature-libraries/flex-tree/index.ts +2 -0
  339. package/src/feature-libraries/flex-tree/lazyNode.ts +13 -3
  340. package/src/feature-libraries/flex-tree/observer.ts +64 -0
  341. package/src/feature-libraries/index.ts +3 -0
  342. package/src/index.ts +6 -4
  343. package/src/packageVersion.ts +1 -1
  344. package/src/shared-tree/index.ts +2 -0
  345. package/src/shared-tree/schematizingTreeView.ts +2 -2
  346. package/src/shared-tree/sharedTree.ts +116 -52
  347. package/src/shared-tree/treeAlpha.ts +309 -4
  348. package/src/shared-tree/treeCheckout.ts +152 -100
  349. package/src/shared-tree-core/branch.ts +7 -0
  350. package/src/shared-tree-core/branchIdCodec.ts +28 -0
  351. package/src/shared-tree-core/editManager.ts +729 -430
  352. package/src/shared-tree-core/editManagerCodecs.ts +4 -164
  353. package/src/shared-tree-core/editManagerCodecsCommons.ts +245 -0
  354. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +108 -0
  355. package/src/shared-tree-core/editManagerCodecsV5.ts +156 -0
  356. package/src/shared-tree-core/{editManagerFormat.ts → editManagerFormatCommons.ts} +17 -13
  357. package/src/shared-tree-core/editManagerFormatV1toV4.ts +42 -0
  358. package/src/shared-tree-core/editManagerFormatV5.ts +35 -0
  359. package/src/shared-tree-core/index.ts +3 -1
  360. package/src/shared-tree-core/messageCodecV1ToV4.ts +104 -0
  361. package/src/shared-tree-core/messageCodecV5.ts +131 -0
  362. package/src/shared-tree-core/messageCodecs.ts +16 -85
  363. package/src/shared-tree-core/messageFormatV5.ts +50 -0
  364. package/src/shared-tree-core/messageTypes.ts +15 -2
  365. package/src/shared-tree-core/sequenceIdUtils.ts +1 -1
  366. package/src/shared-tree-core/sharedTreeCore.ts +281 -85
  367. package/src/simple-tree/api/tree.ts +23 -0
  368. package/src/simple-tree/core/unhydratedFlexTree.ts +11 -2
  369. package/src/treeFactory.ts +48 -8
  370. package/dist/codec/noopValidator.d.ts +0 -13
  371. package/dist/codec/noopValidator.d.ts.map +0 -1
  372. package/dist/codec/noopValidator.js +0 -17
  373. package/dist/codec/noopValidator.js.map +0 -1
  374. package/dist/shared-tree-core/editManagerFormat.d.ts.map +0 -1
  375. package/dist/shared-tree-core/editManagerFormat.js.map +0 -1
  376. package/dist/shared-tree-core/messageFormat.d.ts.map +0 -1
  377. package/dist/shared-tree-core/messageFormat.js.map +0 -1
  378. package/docs/user-facing/schema-evolution.md +0 -309
  379. package/lib/codec/noopValidator.d.ts +0 -13
  380. package/lib/codec/noopValidator.d.ts.map +0 -1
  381. package/lib/codec/noopValidator.js +0 -14
  382. package/lib/codec/noopValidator.js.map +0 -1
  383. package/lib/shared-tree-core/editManagerFormat.d.ts.map +0 -1
  384. package/lib/shared-tree-core/editManagerFormat.js.map +0 -1
  385. package/lib/shared-tree-core/messageFormat.d.ts.map +0 -1
  386. package/lib/shared-tree-core/messageFormat.js.map +0 -1
  387. package/src/codec/noopValidator.ts +0 -18
  388. /package/src/shared-tree-core/{messageFormat.ts → messageFormatV1ToV4.ts} +0 -0
@@ -9,9 +9,7 @@ import {
9
9
  type ICodecFamily,
10
10
  type ICodecOptions,
11
11
  type IJsonCodec,
12
- type IMultiFormatCodec,
13
12
  makeCodecFamily,
14
- withSchemaValidation,
15
13
  } from "../codec/index.js";
16
14
  import { makeVersionDispatchingCodec } from "../codec/index.js";
17
15
  import type {
@@ -20,19 +18,11 @@ import type {
20
18
  RevisionTag,
21
19
  SchemaAndPolicy,
22
20
  } from "../core/index.js";
23
- import {
24
- type JsonCompatibleReadOnly,
25
- JsonCompatibleReadOnlySchema,
26
- mapIterable,
27
- } from "../util/index.js";
21
+ import type { JsonCompatibleReadOnly } from "../util/index.js";
28
22
 
29
23
  import type { SummaryData } from "./editManager.js";
30
- import {
31
- type Commit,
32
- type EncodedCommit,
33
- EncodedEditManager,
34
- type SequencedCommit,
35
- } from "./editManagerFormat.js";
24
+ import { makeV1CodecWithVersion } from "./editManagerCodecsV1toV4.js";
25
+ import { makeV5CodecWithVersion } from "./editManagerCodecsV5.js";
36
26
 
37
27
  export interface EditManagerEncodingContext {
38
28
  idCompressor: IIdCompressor;
@@ -74,156 +64,6 @@ export function makeEditManagerCodecs<TChangeset>(
74
64
  [2, makeV1CodecWithVersion(changeCodecs.resolve(2), revisionTagCodec, options, 2)],
75
65
  [3, makeV1CodecWithVersion(changeCodecs.resolve(3), revisionTagCodec, options, 3)],
76
66
  [4, makeV1CodecWithVersion(changeCodecs.resolve(4), revisionTagCodec, options, 4)],
67
+ [5, makeV5CodecWithVersion(changeCodecs.resolve(4), revisionTagCodec, options, 5)],
77
68
  ]);
78
69
  }
79
-
80
- function makeV1CodecWithVersion<TChangeset>(
81
- changeCodec: IMultiFormatCodec<
82
- TChangeset,
83
- JsonCompatibleReadOnly,
84
- JsonCompatibleReadOnly,
85
- ChangeEncodingContext
86
- >,
87
- revisionTagCodec: IJsonCodec<
88
- RevisionTag,
89
- EncodedRevisionTag,
90
- EncodedRevisionTag,
91
- ChangeEncodingContext
92
- >,
93
- options: ICodecOptions,
94
- version: EncodedEditManager<TChangeset>["version"],
95
- ): IJsonCodec<
96
- SummaryData<TChangeset>,
97
- JsonCompatibleReadOnly,
98
- JsonCompatibleReadOnly,
99
- EditManagerEncodingContext
100
- > {
101
- const format = EncodedEditManager(
102
- changeCodec.json.encodedSchema ?? JsonCompatibleReadOnlySchema,
103
- );
104
-
105
- const encodeCommit = <T extends Commit<TChangeset>>(
106
- commit: T,
107
- context: ChangeEncodingContext,
108
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
109
- ) => ({
110
- ...commit,
111
- revision: revisionTagCodec.encode(commit.revision, {
112
- originatorId: commit.sessionId,
113
- idCompressor: context.idCompressor,
114
- revision: undefined,
115
- }),
116
- change: changeCodec.json.encode(commit.change, { ...context, revision: commit.revision }),
117
- });
118
-
119
- const decodeCommit = <T extends EncodedCommit<JsonCompatibleReadOnly>>(
120
- commit: T,
121
- context: ChangeEncodingContext,
122
- // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
123
- ) => {
124
- const revision = revisionTagCodec.decode(commit.revision, {
125
- originatorId: commit.sessionId,
126
- idCompressor: context.idCompressor,
127
- revision: undefined,
128
- });
129
-
130
- return {
131
- ...commit,
132
- revision,
133
- change: changeCodec.json.decode(commit.change, { ...context, revision }),
134
- };
135
- };
136
-
137
- const codec: IJsonCodec<
138
- SummaryData<TChangeset>,
139
- EncodedEditManager<TChangeset>,
140
- EncodedEditManager<TChangeset>,
141
- EditManagerEncodingContext
142
- > = withSchemaValidation(
143
- format,
144
- {
145
- encode: (data, context: EditManagerEncodingContext) => {
146
- const json: EncodedEditManager<TChangeset> = {
147
- trunk: data.trunk.map((commit) =>
148
- encodeCommit(commit, {
149
- originatorId: commit.sessionId,
150
- idCompressor: context.idCompressor,
151
- schema: context.schema,
152
- revision: undefined,
153
- }),
154
- ),
155
- branches: Array.from(data.peerLocalBranches.entries(), ([sessionId, branch]) => [
156
- sessionId,
157
- {
158
- base: revisionTagCodec.encode(branch.base, {
159
- originatorId: sessionId,
160
- idCompressor: context.idCompressor,
161
- revision: undefined,
162
- }),
163
- commits: branch.commits.map((commit) =>
164
- encodeCommit(commit, {
165
- originatorId: commit.sessionId,
166
- idCompressor: context.idCompressor,
167
- schema: context.schema,
168
- revision: undefined,
169
- }),
170
- ),
171
- },
172
- ]),
173
- version,
174
- };
175
- return json;
176
- },
177
- decode: (
178
- json: EncodedEditManager<TChangeset>,
179
- context: EditManagerEncodingContext,
180
- ): SummaryData<TChangeset> => {
181
- // TODO: sort out EncodedCommit vs Commit, and make this type check without `any`.
182
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
183
- const trunk: readonly any[] = json.trunk;
184
- return {
185
- trunk: trunk.map(
186
- (commit): SequencedCommit<TChangeset> =>
187
- // TODO: sort out EncodedCommit vs Commit, and make this type check without `as`.
188
- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
189
- decodeCommit(commit, {
190
- originatorId: commit.sessionId,
191
- idCompressor: context.idCompressor,
192
- revision: undefined,
193
- }),
194
- ),
195
- peerLocalBranches: new Map(
196
- mapIterable(json.branches, ([sessionId, branch]) => [
197
- sessionId,
198
- {
199
- base: revisionTagCodec.decode(branch.base, {
200
- originatorId: sessionId,
201
- idCompressor: context.idCompressor,
202
- revision: undefined,
203
- }),
204
- commits: branch.commits.map((commit) =>
205
- // TODO: sort out EncodedCommit vs Commit, and make this type check without `as`.
206
- decodeCommit(commit as EncodedCommit<JsonCompatibleReadOnly>, {
207
- originatorId: commit.sessionId,
208
- idCompressor: context.idCompressor,
209
- revision: undefined,
210
- }),
211
- ),
212
- },
213
- ]),
214
- ),
215
- };
216
- },
217
- },
218
- options.jsonValidator,
219
- );
220
- // TODO: makeVersionedValidatedCodec and withSchemaValidation should allow the codec to decode JsonCompatibleReadOnly, or Versioned or something like that,
221
- // and not leak the internal encoded format in the API surface.
222
- // Fixing that would remove the need for this cast.
223
- return codec as unknown as IJsonCodec<
224
- SummaryData<TChangeset>,
225
- JsonCompatibleReadOnly,
226
- JsonCompatibleReadOnly,
227
- EditManagerEncodingContext
228
- >;
229
- }
@@ -0,0 +1,245 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { IIdCompressor, SessionId } from "@fluidframework/id-compressor";
7
+ import { assert } from "@fluidframework/core-utils/internal";
8
+
9
+ import type { IJsonCodec, IMultiFormatCodec } from "../codec/index.js";
10
+ import type {
11
+ ChangeEncodingContext,
12
+ EncodedRevisionTag,
13
+ RevisionTag,
14
+ SchemaAndPolicy,
15
+ } from "../core/index.js";
16
+ import { mapIterable, type JsonCompatibleReadOnly, type Mutable } from "../util/index.js";
17
+ import type {
18
+ Commit,
19
+ EncodedCommit,
20
+ EncodedSharedBranch,
21
+ SequencedCommit,
22
+ } from "./editManagerFormatCommons.js";
23
+ import type { SharedBranchSummaryData } from "./editManager.js";
24
+ import { decodeBranchId, encodeBranchId } from "./branchIdCodec.js";
25
+
26
+ export interface EditManagerEncodingContext {
27
+ idCompressor: IIdCompressor;
28
+ readonly schema?: SchemaAndPolicy;
29
+ }
30
+
31
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
32
+ function encodeCommit<TChangeset, T extends Commit<TChangeset>>(
33
+ changeCodec: IMultiFormatCodec<
34
+ TChangeset,
35
+ JsonCompatibleReadOnly,
36
+ JsonCompatibleReadOnly,
37
+ ChangeEncodingContext
38
+ >,
39
+ revisionTagCodec: IJsonCodec<
40
+ RevisionTag,
41
+ EncodedRevisionTag,
42
+ EncodedRevisionTag,
43
+ ChangeEncodingContext
44
+ >,
45
+ commit: T,
46
+ context: ChangeEncodingContext,
47
+ ) {
48
+ return {
49
+ ...commit,
50
+ revision: revisionTagCodec.encode(commit.revision, {
51
+ originatorId: commit.sessionId,
52
+ idCompressor: context.idCompressor,
53
+ revision: undefined,
54
+ }),
55
+ change: changeCodec.json.encode(commit.change, { ...context, revision: commit.revision }),
56
+ };
57
+ }
58
+
59
+ // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
60
+ function decodeCommit<TChangeset, T extends EncodedCommit<JsonCompatibleReadOnly>>(
61
+ changeCodec: IMultiFormatCodec<
62
+ TChangeset,
63
+ JsonCompatibleReadOnly,
64
+ JsonCompatibleReadOnly,
65
+ ChangeEncodingContext
66
+ >,
67
+ revisionTagCodec: IJsonCodec<
68
+ RevisionTag,
69
+ EncodedRevisionTag,
70
+ EncodedRevisionTag,
71
+ ChangeEncodingContext
72
+ >,
73
+ commit: T,
74
+ context: ChangeEncodingContext,
75
+ ) {
76
+ const revision = revisionTagCodec.decode(commit.revision, {
77
+ originatorId: commit.sessionId,
78
+ idCompressor: context.idCompressor,
79
+ revision: undefined,
80
+ });
81
+
82
+ return {
83
+ ...commit,
84
+ revision,
85
+ change: changeCodec.json.decode(commit.change, { ...context, revision }),
86
+ };
87
+ }
88
+
89
+ export function encodeSharedBranch<TChangeset>(
90
+ changeCodec: IMultiFormatCodec<
91
+ TChangeset,
92
+ JsonCompatibleReadOnly,
93
+ JsonCompatibleReadOnly,
94
+ ChangeEncodingContext
95
+ >,
96
+ revisionTagCodec: IJsonCodec<
97
+ RevisionTag,
98
+ EncodedRevisionTag,
99
+ EncodedRevisionTag,
100
+ ChangeEncodingContext
101
+ >,
102
+ data: SharedBranchSummaryData<TChangeset>,
103
+ context: EditManagerEncodingContext,
104
+ originatorId: SessionId | undefined,
105
+ ): EncodedSharedBranch<TChangeset> {
106
+ const json: Mutable<EncodedSharedBranch<TChangeset>> = {
107
+ trunk: data.trunk.map((commit) =>
108
+ encodeCommit(changeCodec, revisionTagCodec, commit, {
109
+ originatorId: commit.sessionId,
110
+ idCompressor: context.idCompressor,
111
+ schema: context.schema,
112
+ revision: undefined,
113
+ }),
114
+ ),
115
+ peers: Array.from(data.peerLocalBranches.entries(), ([sessionId, branch]) => [
116
+ sessionId,
117
+ {
118
+ base: revisionTagCodec.encode(branch.base, {
119
+ originatorId: sessionId,
120
+ idCompressor: context.idCompressor,
121
+ revision: undefined,
122
+ }),
123
+ commits: branch.commits.map((commit) =>
124
+ encodeCommit(changeCodec, revisionTagCodec, commit, {
125
+ originatorId: commit.sessionId,
126
+ idCompressor: context.idCompressor,
127
+ schema: context.schema,
128
+ revision: undefined,
129
+ }),
130
+ ),
131
+ },
132
+ ]),
133
+ };
134
+ if (data.session !== undefined) {
135
+ json.session = data.session;
136
+ }
137
+ if (data.id !== undefined) {
138
+ json.id = encodeBranchId(context.idCompressor, data.id);
139
+ }
140
+ if (data.name !== undefined) {
141
+ json.name = data.name;
142
+ }
143
+ if (data.author !== undefined) {
144
+ json.author = data.author;
145
+ }
146
+ if (data.base !== undefined) {
147
+ assert(
148
+ originatorId !== undefined,
149
+ 0xc62 /* Cannot encode branch base without originatorId */,
150
+ );
151
+ json.base = revisionTagCodec.encode(data.base, {
152
+ originatorId,
153
+ idCompressor: context.idCompressor,
154
+ revision: undefined,
155
+ });
156
+ }
157
+ return json;
158
+ }
159
+
160
+ export function decodeSharedBranch<TChangeset>(
161
+ changeCodec: IMultiFormatCodec<
162
+ TChangeset,
163
+ JsonCompatibleReadOnly,
164
+ JsonCompatibleReadOnly,
165
+ ChangeEncodingContext
166
+ >,
167
+ revisionTagCodec: IJsonCodec<
168
+ RevisionTag,
169
+ EncodedRevisionTag,
170
+ EncodedRevisionTag,
171
+ ChangeEncodingContext
172
+ >,
173
+ json: EncodedSharedBranch<TChangeset>,
174
+ context: EditManagerEncodingContext,
175
+ originatorId: SessionId | undefined,
176
+ ): SharedBranchSummaryData<TChangeset> {
177
+ // TODO: sort out EncodedCommit vs Commit, and make this type check without `any`.
178
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
179
+ const trunk: readonly any[] = json.trunk;
180
+ const data: Mutable<SharedBranchSummaryData<TChangeset>> = {
181
+ trunk: trunk.map(
182
+ (commit): SequencedCommit<TChangeset> =>
183
+ // TODO: sort out EncodedCommit vs Commit, and make this type check without `as`.
184
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return
185
+ decodeCommit(changeCodec, revisionTagCodec, commit, {
186
+ originatorId: commit.sessionId,
187
+ idCompressor: context.idCompressor,
188
+ revision: undefined,
189
+ }),
190
+ ),
191
+ peerLocalBranches: new Map(
192
+ mapIterable(json.peers, ([sessionId, branch]) => [
193
+ sessionId,
194
+ {
195
+ base: revisionTagCodec.decode(branch.base, {
196
+ originatorId: sessionId,
197
+ idCompressor: context.idCompressor,
198
+ revision: undefined,
199
+ }),
200
+ commits: branch.commits.map((commit) =>
201
+ // TODO: sort out EncodedCommit vs Commit, and make this type check without `as`.
202
+ decodeCommit(
203
+ changeCodec,
204
+ revisionTagCodec,
205
+ commit as EncodedCommit<JsonCompatibleReadOnly>,
206
+ {
207
+ originatorId: commit.sessionId,
208
+ idCompressor: context.idCompressor,
209
+ revision: undefined,
210
+ },
211
+ ),
212
+ ),
213
+ },
214
+ ]),
215
+ ),
216
+ };
217
+ if (json.session !== undefined) {
218
+ data.session = json.session;
219
+ }
220
+ if (json.name !== undefined) {
221
+ data.name = json.name;
222
+ }
223
+ if (json.author !== undefined) {
224
+ data.author = json.author;
225
+ }
226
+ if (json.id !== undefined) {
227
+ assert(
228
+ originatorId !== undefined,
229
+ 0xc63 /* Cannot decode branch id without originatorId */,
230
+ );
231
+ data.id = decodeBranchId(context.idCompressor, json.id, { originatorId });
232
+ }
233
+ if (json.base !== undefined) {
234
+ assert(
235
+ originatorId !== undefined,
236
+ 0xc64 /* Cannot decode branch base without originatorId */,
237
+ );
238
+ data.base = revisionTagCodec.decode(json.base, {
239
+ originatorId,
240
+ idCompressor: context.idCompressor,
241
+ revision: undefined,
242
+ });
243
+ }
244
+ return data;
245
+ }
@@ -0,0 +1,108 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import type { IIdCompressor } from "@fluidframework/id-compressor";
7
+
8
+ import {
9
+ type ICodecOptions,
10
+ type IJsonCodec,
11
+ type IMultiFormatCodec,
12
+ withSchemaValidation,
13
+ } from "../codec/index.js";
14
+ import type {
15
+ ChangeEncodingContext,
16
+ EncodedRevisionTag,
17
+ RevisionTag,
18
+ SchemaAndPolicy,
19
+ } from "../core/index.js";
20
+ import { type JsonCompatibleReadOnly, JsonCompatibleReadOnlySchema } from "../util/index.js";
21
+
22
+ import type { SummaryData } from "./editManager.js";
23
+ import { EncodedEditManager } from "./editManagerFormatV1toV4.js";
24
+ import { decodeSharedBranch, encodeSharedBranch } from "./editManagerCodecsCommons.js";
25
+
26
+ export interface EditManagerEncodingContext {
27
+ idCompressor: IIdCompressor;
28
+ readonly schema?: SchemaAndPolicy;
29
+ }
30
+
31
+ export function makeV1CodecWithVersion<TChangeset>(
32
+ changeCodec: IMultiFormatCodec<
33
+ TChangeset,
34
+ JsonCompatibleReadOnly,
35
+ JsonCompatibleReadOnly,
36
+ ChangeEncodingContext
37
+ >,
38
+ revisionTagCodec: IJsonCodec<
39
+ RevisionTag,
40
+ EncodedRevisionTag,
41
+ EncodedRevisionTag,
42
+ ChangeEncodingContext
43
+ >,
44
+ options: ICodecOptions,
45
+ version: EncodedEditManager<TChangeset>["version"],
46
+ ): IJsonCodec<
47
+ SummaryData<TChangeset>,
48
+ JsonCompatibleReadOnly,
49
+ JsonCompatibleReadOnly,
50
+ EditManagerEncodingContext
51
+ > {
52
+ const format = EncodedEditManager(
53
+ changeCodec.json.encodedSchema ?? JsonCompatibleReadOnlySchema,
54
+ );
55
+
56
+ const codec: IJsonCodec<
57
+ SummaryData<TChangeset>,
58
+ EncodedEditManager<TChangeset>,
59
+ EncodedEditManager<TChangeset>,
60
+ EditManagerEncodingContext
61
+ > = withSchemaValidation(
62
+ format,
63
+ {
64
+ encode: (data, context: EditManagerEncodingContext) => {
65
+ const mainBranch = encodeSharedBranch(
66
+ changeCodec,
67
+ revisionTagCodec,
68
+ data.main,
69
+ context,
70
+ data.originator,
71
+ );
72
+ const json: EncodedEditManager<TChangeset> = {
73
+ trunk: mainBranch.trunk,
74
+ branches: mainBranch.peers,
75
+ version,
76
+ };
77
+ return json;
78
+ },
79
+ decode: (
80
+ json: EncodedEditManager<TChangeset>,
81
+ context: EditManagerEncodingContext,
82
+ ): SummaryData<TChangeset> => {
83
+ return {
84
+ main: decodeSharedBranch(
85
+ changeCodec,
86
+ revisionTagCodec,
87
+ {
88
+ trunk: json.trunk,
89
+ peers: json.branches,
90
+ },
91
+ context,
92
+ undefined, // originatorId is not encoded in v1
93
+ ),
94
+ };
95
+ },
96
+ },
97
+ options.jsonValidator,
98
+ );
99
+ // TODO: makeVersionedValidatedCodec and withSchemaValidation should allow the codec to decode JsonCompatibleReadOnly, or Versioned or something like that,
100
+ // and not leak the internal encoded format in the API surface.
101
+ // Fixing that would remove the need for this cast.
102
+ return codec as unknown as IJsonCodec<
103
+ SummaryData<TChangeset>,
104
+ JsonCompatibleReadOnly,
105
+ JsonCompatibleReadOnly,
106
+ EditManagerEncodingContext
107
+ >;
108
+ }
@@ -0,0 +1,156 @@
1
+ /*!
2
+ * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
+ * Licensed under the MIT License.
4
+ */
5
+
6
+ import { assert } from "@fluidframework/core-utils/internal";
7
+ import type { IIdCompressor } from "@fluidframework/id-compressor";
8
+
9
+ import {
10
+ type ICodecOptions,
11
+ type IJsonCodec,
12
+ type IMultiFormatCodec,
13
+ withSchemaValidation,
14
+ } from "../codec/index.js";
15
+ import type {
16
+ ChangeEncodingContext,
17
+ EncodedRevisionTag,
18
+ RevisionTag,
19
+ SchemaAndPolicy,
20
+ } from "../core/index.js";
21
+ import {
22
+ type JsonCompatibleReadOnly,
23
+ JsonCompatibleReadOnlySchema,
24
+ type Mutable,
25
+ } from "../util/index.js";
26
+
27
+ import type { SharedBranchSummaryData, SummaryData } from "./editManager.js";
28
+ import { EncodedEditManager } from "./editManagerFormatV5.js";
29
+ import { decodeSharedBranch, encodeSharedBranch } from "./editManagerCodecsCommons.js";
30
+ import type { EncodedSharedBranch } from "./editManagerFormatCommons.js";
31
+ import type { BranchId } from "./branch.js";
32
+
33
+ export interface EditManagerEncodingContext {
34
+ idCompressor: IIdCompressor;
35
+ readonly schema?: SchemaAndPolicy;
36
+ }
37
+
38
+ export function makeV5CodecWithVersion<TChangeset>(
39
+ changeCodec: IMultiFormatCodec<
40
+ TChangeset,
41
+ JsonCompatibleReadOnly,
42
+ JsonCompatibleReadOnly,
43
+ ChangeEncodingContext
44
+ >,
45
+ revisionTagCodec: IJsonCodec<
46
+ RevisionTag,
47
+ EncodedRevisionTag,
48
+ EncodedRevisionTag,
49
+ ChangeEncodingContext
50
+ >,
51
+ options: ICodecOptions,
52
+ version: EncodedEditManager<TChangeset>["version"],
53
+ ): IJsonCodec<
54
+ SummaryData<TChangeset>,
55
+ JsonCompatibleReadOnly,
56
+ JsonCompatibleReadOnly,
57
+ EditManagerEncodingContext
58
+ > {
59
+ const format = EncodedEditManager(
60
+ changeCodec.json.encodedSchema ?? JsonCompatibleReadOnlySchema,
61
+ );
62
+
63
+ const codec: IJsonCodec<
64
+ SummaryData<TChangeset>,
65
+ EncodedEditManager<TChangeset>,
66
+ EncodedEditManager<TChangeset>,
67
+ EditManagerEncodingContext
68
+ > = withSchemaValidation(
69
+ format,
70
+ {
71
+ encode: (data: SummaryData<TChangeset>, context: EditManagerEncodingContext) => {
72
+ const mainBranch = encodeSharedBranch(
73
+ changeCodec,
74
+ revisionTagCodec,
75
+ data.main,
76
+ context,
77
+ data.originator,
78
+ );
79
+ assert(
80
+ data.originator !== undefined,
81
+ 0xc65 /* Cannot encode V5 summary without originator */,
82
+ );
83
+ const json: Mutable<EncodedEditManager<TChangeset>> = {
84
+ main: mainBranch,
85
+ originator: data.originator,
86
+ version,
87
+ };
88
+ if (data.branches !== undefined && data.branches.size > 0) {
89
+ const branches: EncodedSharedBranch<TChangeset>[] = [];
90
+ for (const [_, branch] of data.branches) {
91
+ branches.push(
92
+ encodeSharedBranch(
93
+ changeCodec,
94
+ revisionTagCodec,
95
+ branch,
96
+ context,
97
+ data.originator,
98
+ ),
99
+ );
100
+ }
101
+ json.branches = branches;
102
+ }
103
+ return json;
104
+ },
105
+ decode: (
106
+ json: EncodedEditManager<TChangeset>,
107
+ context: EditManagerEncodingContext,
108
+ ): SummaryData<TChangeset> => {
109
+ const mainBranch = decodeSharedBranch(
110
+ changeCodec,
111
+ revisionTagCodec,
112
+ json.main,
113
+ context,
114
+ json.originator,
115
+ );
116
+
117
+ const decoded: Mutable<SummaryData<TChangeset>> = {
118
+ main: mainBranch,
119
+ originator: json.originator,
120
+ };
121
+
122
+ if (json.branches !== undefined) {
123
+ const branches = new Map<BranchId, SharedBranchSummaryData<TChangeset>>();
124
+ for (const branch of json.branches) {
125
+ const decodedBranch = decodeSharedBranch(
126
+ changeCodec,
127
+ revisionTagCodec,
128
+ branch,
129
+ context,
130
+ json.originator,
131
+ );
132
+ assert(
133
+ decodedBranch.id !== undefined,
134
+ 0xc66 /* Shared branches must have an id */,
135
+ );
136
+ assert(!branches.has(decodedBranch.id), 0xc67 /* Duplicate shared branch id */);
137
+ branches.set(decodedBranch.id, decodedBranch);
138
+ }
139
+
140
+ decoded.branches = branches;
141
+ }
142
+ return decoded;
143
+ },
144
+ },
145
+ options.jsonValidator,
146
+ );
147
+ // TODO: makeVersionedValidatedCodec and withSchemaValidation should allow the codec to decode JsonCompatibleReadOnly, or Versioned or something like that,
148
+ // and not leak the internal encoded format in the API surface.
149
+ // Fixing that would remove the need for this cast.
150
+ return codec as unknown as IJsonCodec<
151
+ SummaryData<TChangeset>,
152
+ JsonCompatibleReadOnly,
153
+ JsonCompatibleReadOnly,
154
+ EditManagerEncodingContext
155
+ >;
156
+ }