@fluidframework/tree 2.116.1 → 2.118.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 (421) hide show
  1. package/CHANGELOG.md +202 -0
  2. package/api-report/tree.alpha.api.md +122 -31
  3. package/api-report/tree.beta.api.md +50 -9
  4. package/api-report/tree.legacy.beta.api.md +50 -9
  5. package/dist/codec/codec.d.ts +18 -0
  6. package/dist/codec/codec.d.ts.map +1 -1
  7. package/dist/codec/codec.js +18 -0
  8. package/dist/codec/codec.js.map +1 -1
  9. package/dist/core/index.d.ts +2 -2
  10. package/dist/core/index.d.ts.map +1 -1
  11. package/dist/core/index.js +3 -2
  12. package/dist/core/index.js.map +1 -1
  13. package/dist/core/rebase/index.d.ts +1 -1
  14. package/dist/core/rebase/index.d.ts.map +1 -1
  15. package/dist/core/rebase/index.js +2 -1
  16. package/dist/core/rebase/index.js.map +1 -1
  17. package/dist/core/rebase/types.d.ts +39 -2
  18. package/dist/core/rebase/types.d.ts.map +1 -1
  19. package/dist/core/rebase/types.js +37 -2
  20. package/dist/core/rebase/types.js.map +1 -1
  21. package/dist/core/rebase/utils.d.ts.map +1 -1
  22. package/dist/core/rebase/utils.js +1 -0
  23. package/dist/core/rebase/utils.js.map +1 -1
  24. package/dist/core/revertible.d.ts +62 -6
  25. package/dist/core/revertible.d.ts.map +1 -1
  26. package/dist/core/revertible.js.map +1 -1
  27. package/dist/entrypoints/alpha.d.ts +1 -1
  28. package/dist/entrypoints/alpha.d.ts.map +1 -1
  29. package/dist/entrypoints/alpha.js.map +1 -1
  30. package/dist/entrypoints/beta.d.ts +1 -1
  31. package/dist/entrypoints/beta.d.ts.map +1 -1
  32. package/dist/entrypoints/beta.js.map +1 -1
  33. package/dist/entrypoints/legacy.d.ts +1 -1
  34. package/dist/entrypoints/legacy.d.ts.map +1 -1
  35. package/dist/entrypoints/legacy.js.map +1 -1
  36. package/dist/feature-libraries/index.d.ts +1 -1
  37. package/dist/feature-libraries/index.js.map +1 -1
  38. package/dist/feature-libraries/indexing/types.d.ts +1 -1
  39. package/dist/feature-libraries/indexing/types.js.map +1 -1
  40. package/dist/feature-libraries/schemaChecker.d.ts +9 -19
  41. package/dist/feature-libraries/schemaChecker.d.ts.map +1 -1
  42. package/dist/feature-libraries/schemaChecker.js +130 -46
  43. package/dist/feature-libraries/schemaChecker.js.map +1 -1
  44. package/dist/index.d.ts +2 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/packageVersion.d.ts +1 -1
  48. package/dist/packageVersion.js +1 -1
  49. package/dist/packageVersion.js.map +1 -1
  50. package/dist/shared-tree/history.d.ts +22 -0
  51. package/dist/shared-tree/history.d.ts.map +1 -0
  52. package/dist/shared-tree/history.js +66 -0
  53. package/dist/shared-tree/history.js.map +1 -0
  54. package/dist/shared-tree/schematizingTreeView.d.ts +24 -9
  55. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  56. package/dist/shared-tree/schematizingTreeView.js +61 -11
  57. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  58. package/dist/shared-tree/sharedTree.d.ts +3 -2
  59. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  60. package/dist/shared-tree/sharedTree.js +2 -0
  61. package/dist/shared-tree/sharedTree.js.map +1 -1
  62. package/dist/shared-tree/tree.js +1 -1
  63. package/dist/shared-tree/tree.js.map +1 -1
  64. package/dist/shared-tree/treeAlpha.d.ts +8 -20
  65. package/dist/shared-tree/treeAlpha.d.ts.map +1 -1
  66. package/dist/shared-tree/treeAlpha.js +9 -12
  67. package/dist/shared-tree/treeAlpha.js.map +1 -1
  68. package/dist/shared-tree/treeCheckout.d.ts +16 -9
  69. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  70. package/dist/shared-tree/treeCheckout.js +122 -25
  71. package/dist/shared-tree/treeCheckout.js.map +1 -1
  72. package/dist/shared-tree/unhydratedTreeContext.d.ts +3 -2
  73. package/dist/shared-tree/unhydratedTreeContext.d.ts.map +1 -1
  74. package/dist/shared-tree/unhydratedTreeContext.js +3 -0
  75. package/dist/shared-tree/unhydratedTreeContext.js.map +1 -1
  76. package/dist/shared-tree-core/branch.d.ts +16 -2
  77. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  78. package/dist/shared-tree-core/branch.js +20 -2
  79. package/dist/shared-tree-core/branch.js.map +1 -1
  80. package/dist/shared-tree-core/branchCommitCounter.d.ts +31 -0
  81. package/dist/shared-tree-core/branchCommitCounter.d.ts.map +1 -0
  82. package/dist/shared-tree-core/branchCommitCounter.js +79 -0
  83. package/dist/shared-tree-core/branchCommitCounter.js.map +1 -0
  84. package/dist/shared-tree-core/customMetadataCodec.d.ts +9 -0
  85. package/dist/shared-tree-core/customMetadataCodec.d.ts.map +1 -0
  86. package/dist/shared-tree-core/customMetadataCodec.js +37 -0
  87. package/dist/shared-tree-core/customMetadataCodec.js.map +1 -0
  88. package/dist/shared-tree-core/customMetadataFormat.d.ts +18 -0
  89. package/dist/shared-tree-core/customMetadataFormat.d.ts.map +1 -0
  90. package/dist/shared-tree-core/customMetadataFormat.js +15 -0
  91. package/dist/shared-tree-core/customMetadataFormat.js.map +1 -0
  92. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  93. package/dist/shared-tree-core/editManager.js +15 -3
  94. package/dist/shared-tree-core/editManager.js.map +1 -1
  95. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  96. package/dist/shared-tree-core/editManagerCodecs.js +5 -0
  97. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  98. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +1 -1
  99. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  100. package/dist/shared-tree-core/editManagerCodecsCommons.js +17 -5
  101. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  102. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  103. package/dist/shared-tree-core/editManagerCodecsV1toV4.js +4 -2
  104. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  105. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  106. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js +2 -2
  107. package/dist/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  108. package/dist/shared-tree-core/editManagerFormatCommons.d.ts +17 -6
  109. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  110. package/dist/shared-tree-core/editManagerFormatCommons.js +18 -8
  111. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  112. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +7 -5
  113. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  114. package/dist/shared-tree-core/editManagerFormatV1toV4.js +4 -3
  115. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  116. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts +4 -0
  117. package/dist/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
  118. package/dist/shared-tree-core/editManagerFormatVSharedBranches.js +2 -2
  119. package/dist/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
  120. package/dist/shared-tree-core/index.d.ts +2 -1
  121. package/dist/shared-tree-core/index.d.ts.map +1 -1
  122. package/dist/shared-tree-core/index.js +3 -1
  123. package/dist/shared-tree-core/index.js.map +1 -1
  124. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +2 -2
  125. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  126. package/dist/shared-tree-core/messageCodecV1ToV4.js +12 -3
  127. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  128. package/dist/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  129. package/dist/shared-tree-core/messageCodecVSharedBranches.js +8 -2
  130. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  131. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  132. package/dist/shared-tree-core/messageCodecs.js +5 -0
  133. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  134. package/dist/shared-tree-core/messageFormat.d.ts +1 -0
  135. package/dist/shared-tree-core/messageFormat.d.ts.map +1 -1
  136. package/dist/shared-tree-core/messageFormat.js +6 -0
  137. package/dist/shared-tree-core/messageFormat.js.map +1 -1
  138. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts +10 -3
  139. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  140. package/dist/shared-tree-core/messageFormatV1ToV4.js +10 -2
  141. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  142. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts +7 -0
  143. package/dist/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  144. package/dist/shared-tree-core/messageFormatVSharedBranches.js +2 -0
  145. package/dist/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  146. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  147. package/dist/shared-tree-core/sharedTreeCore.js +4 -2
  148. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  149. package/dist/shared-tree-core/transaction.d.ts +9 -0
  150. package/dist/shared-tree-core/transaction.d.ts.map +1 -1
  151. package/dist/shared-tree-core/transaction.js +26 -4
  152. package/dist/shared-tree-core/transaction.js.map +1 -1
  153. package/dist/simple-tree/api/configuration.d.ts +4 -4
  154. package/dist/simple-tree/api/configuration.d.ts.map +1 -1
  155. package/dist/simple-tree/api/configuration.js.map +1 -1
  156. package/dist/simple-tree/api/discrepancies.d.ts +36 -3
  157. package/dist/simple-tree/api/discrepancies.d.ts.map +1 -1
  158. package/dist/simple-tree/api/discrepancies.js +40 -14
  159. package/dist/simple-tree/api/discrepancies.js.map +1 -1
  160. package/dist/simple-tree/api/index.d.ts +3 -2
  161. package/dist/simple-tree/api/index.d.ts.map +1 -1
  162. package/dist/simple-tree/api/index.js +3 -2
  163. package/dist/simple-tree/api/index.js.map +1 -1
  164. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts +22 -3
  165. package/dist/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  166. package/dist/simple-tree/api/schemaCompatibilityTester.js +140 -10
  167. package/dist/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  168. package/dist/simple-tree/api/transactionTypes.d.ts +28 -2
  169. package/dist/simple-tree/api/transactionTypes.d.ts.map +1 -1
  170. package/dist/simple-tree/api/transactionTypes.js.map +1 -1
  171. package/dist/simple-tree/api/tree.d.ts +353 -68
  172. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  173. package/dist/simple-tree/api/tree.js.map +1 -1
  174. package/dist/simple-tree/core/toStored.d.ts +7 -0
  175. package/dist/simple-tree/core/toStored.d.ts.map +1 -1
  176. package/dist/simple-tree/core/toStored.js.map +1 -1
  177. package/dist/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  178. package/dist/simple-tree/core/treeNodeValid.js +2 -2
  179. package/dist/simple-tree/core/treeNodeValid.js.map +1 -1
  180. package/dist/simple-tree/index.d.ts +1 -1
  181. package/dist/simple-tree/index.d.ts.map +1 -1
  182. package/dist/simple-tree/index.js +4 -3
  183. package/dist/simple-tree/index.js.map +1 -1
  184. package/dist/tableSchema.js +10 -10
  185. package/dist/tableSchema.js.map +1 -1
  186. package/docs/main/glossary.md +163 -0
  187. package/lib/codec/codec.d.ts +18 -0
  188. package/lib/codec/codec.d.ts.map +1 -1
  189. package/lib/codec/codec.js +18 -0
  190. package/lib/codec/codec.js.map +1 -1
  191. package/lib/core/index.d.ts +2 -2
  192. package/lib/core/index.d.ts.map +1 -1
  193. package/lib/core/index.js +1 -1
  194. package/lib/core/index.js.map +1 -1
  195. package/lib/core/rebase/index.d.ts +1 -1
  196. package/lib/core/rebase/index.d.ts.map +1 -1
  197. package/lib/core/rebase/index.js +1 -1
  198. package/lib/core/rebase/index.js.map +1 -1
  199. package/lib/core/rebase/types.d.ts +39 -2
  200. package/lib/core/rebase/types.d.ts.map +1 -1
  201. package/lib/core/rebase/types.js +35 -1
  202. package/lib/core/rebase/types.js.map +1 -1
  203. package/lib/core/rebase/utils.d.ts.map +1 -1
  204. package/lib/core/rebase/utils.js +1 -0
  205. package/lib/core/rebase/utils.js.map +1 -1
  206. package/lib/core/revertible.d.ts +62 -6
  207. package/lib/core/revertible.d.ts.map +1 -1
  208. package/lib/core/revertible.js.map +1 -1
  209. package/lib/entrypoints/alpha.d.ts +1 -1
  210. package/lib/entrypoints/alpha.d.ts.map +1 -1
  211. package/lib/entrypoints/alpha.js.map +1 -1
  212. package/lib/entrypoints/beta.d.ts +1 -1
  213. package/lib/entrypoints/beta.d.ts.map +1 -1
  214. package/lib/entrypoints/beta.js.map +1 -1
  215. package/lib/entrypoints/legacy.d.ts +1 -1
  216. package/lib/entrypoints/legacy.d.ts.map +1 -1
  217. package/lib/entrypoints/legacy.js.map +1 -1
  218. package/lib/feature-libraries/index.d.ts +1 -1
  219. package/lib/feature-libraries/index.js.map +1 -1
  220. package/lib/feature-libraries/indexing/types.d.ts +1 -1
  221. package/lib/feature-libraries/indexing/types.js.map +1 -1
  222. package/lib/feature-libraries/schemaChecker.d.ts +9 -19
  223. package/lib/feature-libraries/schemaChecker.d.ts.map +1 -1
  224. package/lib/feature-libraries/schemaChecker.js +133 -49
  225. package/lib/feature-libraries/schemaChecker.js.map +1 -1
  226. package/lib/index.d.ts +2 -2
  227. package/lib/index.d.ts.map +1 -1
  228. package/lib/index.js.map +1 -1
  229. package/lib/packageVersion.d.ts +1 -1
  230. package/lib/packageVersion.js +1 -1
  231. package/lib/packageVersion.js.map +1 -1
  232. package/lib/shared-tree/history.d.ts +22 -0
  233. package/lib/shared-tree/history.d.ts.map +1 -0
  234. package/lib/shared-tree/history.js +62 -0
  235. package/lib/shared-tree/history.js.map +1 -0
  236. package/lib/shared-tree/schematizingTreeView.d.ts +24 -9
  237. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  238. package/lib/shared-tree/schematizingTreeView.js +62 -12
  239. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  240. package/lib/shared-tree/sharedTree.d.ts +3 -2
  241. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  242. package/lib/shared-tree/sharedTree.js +2 -0
  243. package/lib/shared-tree/sharedTree.js.map +1 -1
  244. package/lib/shared-tree/tree.js +1 -1
  245. package/lib/shared-tree/tree.js.map +1 -1
  246. package/lib/shared-tree/treeAlpha.d.ts +8 -20
  247. package/lib/shared-tree/treeAlpha.d.ts.map +1 -1
  248. package/lib/shared-tree/treeAlpha.js +9 -12
  249. package/lib/shared-tree/treeAlpha.js.map +1 -1
  250. package/lib/shared-tree/treeCheckout.d.ts +16 -9
  251. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  252. package/lib/shared-tree/treeCheckout.js +123 -26
  253. package/lib/shared-tree/treeCheckout.js.map +1 -1
  254. package/lib/shared-tree/unhydratedTreeContext.d.ts +3 -2
  255. package/lib/shared-tree/unhydratedTreeContext.d.ts.map +1 -1
  256. package/lib/shared-tree/unhydratedTreeContext.js +3 -0
  257. package/lib/shared-tree/unhydratedTreeContext.js.map +1 -1
  258. package/lib/shared-tree-core/branch.d.ts +16 -2
  259. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  260. package/lib/shared-tree-core/branch.js +20 -2
  261. package/lib/shared-tree-core/branch.js.map +1 -1
  262. package/lib/shared-tree-core/branchCommitCounter.d.ts +31 -0
  263. package/lib/shared-tree-core/branchCommitCounter.d.ts.map +1 -0
  264. package/lib/shared-tree-core/branchCommitCounter.js +75 -0
  265. package/lib/shared-tree-core/branchCommitCounter.js.map +1 -0
  266. package/lib/shared-tree-core/customMetadataCodec.d.ts +9 -0
  267. package/lib/shared-tree-core/customMetadataCodec.d.ts.map +1 -0
  268. package/lib/shared-tree-core/customMetadataCodec.js +32 -0
  269. package/lib/shared-tree-core/customMetadataCodec.js.map +1 -0
  270. package/lib/shared-tree-core/customMetadataFormat.d.ts +18 -0
  271. package/lib/shared-tree-core/customMetadataFormat.d.ts.map +1 -0
  272. package/lib/shared-tree-core/customMetadataFormat.js +11 -0
  273. package/lib/shared-tree-core/customMetadataFormat.js.map +1 -0
  274. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  275. package/lib/shared-tree-core/editManager.js +16 -4
  276. package/lib/shared-tree-core/editManager.js.map +1 -1
  277. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  278. package/lib/shared-tree-core/editManagerCodecs.js +5 -0
  279. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  280. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +1 -1
  281. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -1
  282. package/lib/shared-tree-core/editManagerCodecsCommons.js +17 -5
  283. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -1
  284. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -1
  285. package/lib/shared-tree-core/editManagerCodecsV1toV4.js +4 -2
  286. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -1
  287. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.d.ts.map +1 -1
  288. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js +2 -2
  289. package/lib/shared-tree-core/editManagerCodecsVSharedBranches.js.map +1 -1
  290. package/lib/shared-tree-core/editManagerFormatCommons.d.ts +17 -6
  291. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -1
  292. package/lib/shared-tree-core/editManagerFormatCommons.js +18 -8
  293. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  294. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +7 -5
  295. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -1
  296. package/lib/shared-tree-core/editManagerFormatV1toV4.js +4 -3
  297. package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  298. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts +4 -0
  299. package/lib/shared-tree-core/editManagerFormatVSharedBranches.d.ts.map +1 -1
  300. package/lib/shared-tree-core/editManagerFormatVSharedBranches.js +2 -2
  301. package/lib/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
  302. package/lib/shared-tree-core/index.d.ts +2 -1
  303. package/lib/shared-tree-core/index.d.ts.map +1 -1
  304. package/lib/shared-tree-core/index.js +1 -0
  305. package/lib/shared-tree-core/index.js.map +1 -1
  306. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +2 -2
  307. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -1
  308. package/lib/shared-tree-core/messageCodecV1ToV4.js +12 -3
  309. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -1
  310. package/lib/shared-tree-core/messageCodecVSharedBranches.d.ts.map +1 -1
  311. package/lib/shared-tree-core/messageCodecVSharedBranches.js +8 -2
  312. package/lib/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  313. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  314. package/lib/shared-tree-core/messageCodecs.js +5 -0
  315. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  316. package/lib/shared-tree-core/messageFormat.d.ts +1 -0
  317. package/lib/shared-tree-core/messageFormat.d.ts.map +1 -1
  318. package/lib/shared-tree-core/messageFormat.js +6 -0
  319. package/lib/shared-tree-core/messageFormat.js.map +1 -1
  320. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts +10 -3
  321. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -1
  322. package/lib/shared-tree-core/messageFormatV1ToV4.js +10 -2
  323. package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  324. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts +7 -0
  325. package/lib/shared-tree-core/messageFormatVSharedBranches.d.ts.map +1 -1
  326. package/lib/shared-tree-core/messageFormatVSharedBranches.js +2 -0
  327. package/lib/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  328. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  329. package/lib/shared-tree-core/sharedTreeCore.js +5 -3
  330. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  331. package/lib/shared-tree-core/transaction.d.ts +9 -0
  332. package/lib/shared-tree-core/transaction.d.ts.map +1 -1
  333. package/lib/shared-tree-core/transaction.js +27 -5
  334. package/lib/shared-tree-core/transaction.js.map +1 -1
  335. package/lib/simple-tree/api/configuration.d.ts +4 -4
  336. package/lib/simple-tree/api/configuration.d.ts.map +1 -1
  337. package/lib/simple-tree/api/configuration.js.map +1 -1
  338. package/lib/simple-tree/api/discrepancies.d.ts +36 -3
  339. package/lib/simple-tree/api/discrepancies.d.ts.map +1 -1
  340. package/lib/simple-tree/api/discrepancies.js +40 -14
  341. package/lib/simple-tree/api/discrepancies.js.map +1 -1
  342. package/lib/simple-tree/api/index.d.ts +3 -2
  343. package/lib/simple-tree/api/index.d.ts.map +1 -1
  344. package/lib/simple-tree/api/index.js +1 -1
  345. package/lib/simple-tree/api/index.js.map +1 -1
  346. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts +22 -3
  347. package/lib/simple-tree/api/schemaCompatibilityTester.d.ts.map +1 -1
  348. package/lib/simple-tree/api/schemaCompatibilityTester.js +136 -7
  349. package/lib/simple-tree/api/schemaCompatibilityTester.js.map +1 -1
  350. package/lib/simple-tree/api/transactionTypes.d.ts +28 -2
  351. package/lib/simple-tree/api/transactionTypes.d.ts.map +1 -1
  352. package/lib/simple-tree/api/transactionTypes.js.map +1 -1
  353. package/lib/simple-tree/api/tree.d.ts +353 -68
  354. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  355. package/lib/simple-tree/api/tree.js.map +1 -1
  356. package/lib/simple-tree/core/toStored.d.ts +7 -0
  357. package/lib/simple-tree/core/toStored.d.ts.map +1 -1
  358. package/lib/simple-tree/core/toStored.js.map +1 -1
  359. package/lib/simple-tree/core/treeNodeValid.d.ts.map +1 -1
  360. package/lib/simple-tree/core/treeNodeValid.js +3 -3
  361. package/lib/simple-tree/core/treeNodeValid.js.map +1 -1
  362. package/lib/simple-tree/index.d.ts +1 -1
  363. package/lib/simple-tree/index.d.ts.map +1 -1
  364. package/lib/simple-tree/index.js +1 -1
  365. package/lib/simple-tree/index.js.map +1 -1
  366. package/lib/tableSchema.js +10 -10
  367. package/lib/tableSchema.js.map +1 -1
  368. package/package.json +22 -22
  369. package/src/codec/codec.ts +19 -0
  370. package/src/core/index.ts +4 -0
  371. package/src/core/rebase/index.ts +2 -0
  372. package/src/core/rebase/types.ts +72 -2
  373. package/src/core/rebase/utils.ts +1 -0
  374. package/src/core/revertible.ts +67 -6
  375. package/src/entrypoints/alpha.ts +11 -0
  376. package/src/entrypoints/beta.ts +3 -0
  377. package/src/entrypoints/legacy.ts +3 -0
  378. package/src/feature-libraries/index.ts +1 -1
  379. package/src/feature-libraries/indexing/types.ts +1 -1
  380. package/src/feature-libraries/schemaChecker.ts +198 -82
  381. package/src/index.ts +11 -0
  382. package/src/packageVersion.ts +1 -1
  383. package/src/shared-tree/history.ts +99 -0
  384. package/src/shared-tree/schematizingTreeView.ts +100 -29
  385. package/src/shared-tree/sharedTree.ts +5 -2
  386. package/src/shared-tree/tree.ts +1 -1
  387. package/src/shared-tree/treeAlpha.ts +17 -35
  388. package/src/shared-tree/treeCheckout.ts +170 -31
  389. package/src/shared-tree/unhydratedTreeContext.ts +6 -2
  390. package/src/shared-tree-core/branch.ts +34 -2
  391. package/src/shared-tree-core/branchCommitCounter.ts +103 -0
  392. package/src/shared-tree-core/customMetadataCodec.ts +42 -0
  393. package/src/shared-tree-core/customMetadataFormat.ts +39 -0
  394. package/src/shared-tree-core/editManager.ts +22 -3
  395. package/src/shared-tree-core/editManagerCodecs.ts +12 -0
  396. package/src/shared-tree-core/editManagerCodecsCommons.ts +41 -15
  397. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +7 -1
  398. package/src/shared-tree-core/editManagerCodecsVSharedBranches.ts +2 -0
  399. package/src/shared-tree-core/editManagerFormatCommons.ts +46 -12
  400. package/src/shared-tree-core/editManagerFormatV1toV4.ts +13 -5
  401. package/src/shared-tree-core/editManagerFormatVSharedBranches.ts +2 -2
  402. package/src/shared-tree-core/index.ts +3 -0
  403. package/src/shared-tree-core/messageCodecV1ToV4.ts +18 -5
  404. package/src/shared-tree-core/messageCodecVSharedBranches.ts +9 -2
  405. package/src/shared-tree-core/messageCodecs.ts +12 -0
  406. package/src/shared-tree-core/messageFormat.ts +6 -0
  407. package/src/shared-tree-core/messageFormatV1ToV4.ts +21 -3
  408. package/src/shared-tree-core/messageFormatVSharedBranches.ts +8 -0
  409. package/src/shared-tree-core/sharedTreeCore.ts +5 -2
  410. package/src/shared-tree-core/transaction.ts +56 -4
  411. package/src/simple-tree/api/configuration.ts +4 -4
  412. package/src/simple-tree/api/discrepancies.ts +100 -5
  413. package/src/simple-tree/api/index.ts +12 -1
  414. package/src/simple-tree/api/schemaCompatibilityTester.ts +185 -11
  415. package/src/simple-tree/api/transactionTypes.ts +29 -2
  416. package/src/simple-tree/api/tree.ts +384 -68
  417. package/src/simple-tree/core/toStored.ts +8 -0
  418. package/src/simple-tree/core/treeNodeValid.ts +3 -1
  419. package/src/simple-tree/index.ts +9 -0
  420. package/src/tableSchema.ts +9 -9
  421. package/docs/main/runtime-schema-upgrade.md +0 -208
@@ -2,10 +2,26 @@
2
2
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
3
3
  * Licensed under the MIT License.
4
4
  */
5
- import type { TreeStoredSchema } from "../../core/index.js";
5
+ import { type TreeStoredSchema } from "../../core/index.js";
6
6
  import type { SchemaUpgrade, StagedSchemaUpgradePolicy } from "../core/index.js";
7
7
  import type { TreeSchema } from "../treeSchema.js";
8
- import type { SchemaCompatibilityStatus } from "./tree.js";
8
+ import type { SchemaCompatibilityStatusBeta, SchemaDiscrepancy } from "./tree.js";
9
+ /**
10
+ * Describes the discrepancies that prevent a view schema from viewing a stored schema as a
11
+ * readonly array.
12
+ */
13
+ export declare function getSchemaIncompatibilityDetails(viewSchema: TreeSchema, stored: TreeStoredSchema): readonly SchemaDiscrepancy[] | undefined;
14
+ /**
15
+ * The enablement status of a staged schema upgrade in a document's stored schema.
16
+ *
17
+ * @remarks
18
+ * - `"disabled"` — no locations guarded by the upgrade are enabled in stored schema.
19
+ * - `"partial"` — at least one location is enabled but not all of them.
20
+ * - `"enabled"` — all locations guarded by the upgrade are enabled in stored schema.
21
+ *
22
+ * @alpha
23
+ */
24
+ export type StagedUpgradeStatus = "disabled" | "partial" | "enabled";
9
25
  /**
10
26
  * Determines the compatibility of a stored document (based on its stored schema) with a viewer (based on its view schema).
11
27
  *
@@ -18,6 +34,9 @@ import type { SchemaCompatibilityStatus } from "./tree.js";
18
34
  * @param viewSchema - Schema for the view
19
35
  * @param stored - The stored schema to check compatibility against
20
36
  * @param stagedSchemaUpgrades - Staged schema upgrades enabled for this view, or explicit stored-schema generation options
37
+ *
21
38
  */
22
- export declare function checkSchemaCompatibility(viewSchema: TreeSchema, stored: TreeStoredSchema, stagedSchemaUpgrades?: Iterable<SchemaUpgrade> | StagedSchemaUpgradePolicy): Omit<SchemaCompatibilityStatus, "canInitialize">;
39
+ export declare function checkSchemaCompatibility(viewSchema: TreeSchema, stored: TreeStoredSchema, stagedSchemaUpgrades?: Iterable<SchemaUpgrade> | StagedSchemaUpgradePolicy): Omit<SchemaCompatibilityStatusBeta, "canInitialize"> & {
40
+ enabledUpgrades: ReadonlyMap<SchemaUpgrade, StagedUpgradeStatus>;
41
+ };
23
42
  //# sourceMappingURL=schemaCompatibilityTester.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaCompatibilityTester.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCompatibilityTester.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,K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AAC,aAAa,EAAE,mBAAmB,CAAC,CAAC;CACjE,CA4DA"}
@@ -4,10 +4,86 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.checkSchemaCompatibility = void 0;
8
- const index_js_1 = require("../../feature-libraries/index.js");
7
+ exports.checkSchemaCompatibility = exports.getSchemaIncompatibilityDetails = void 0;
8
+ const internal_1 = require("@fluidframework/core-utils/internal");
9
+ const index_js_1 = require("../../core/index.js");
10
+ const index_js_2 = require("../core/index.js");
11
+ const index_js_3 = require("../../feature-libraries/index.js");
9
12
  const toStoredSchema_js_1 = require("../toStoredSchema.js");
10
13
  const discrepancies_js_1 = require("./discrepancies.js");
14
+ /**
15
+ * Describes the discrepancies that prevent a view schema from viewing a stored schema as a
16
+ * readonly array.
17
+ */
18
+ function getSchemaIncompatibilityDetails(viewSchema, stored) {
19
+ const discrepancies = [...(0, discrepancies_js_1.getDiscrepanciesInAllowedContent)(viewSchema, stored)];
20
+ if (discrepancies.length === 0) {
21
+ return undefined;
22
+ }
23
+ return discrepancies.map(formatSchemaDiscrepancy);
24
+ }
25
+ exports.getSchemaIncompatibilityDetails = getSchemaIncompatibilityDetails;
26
+ function formatSchemaDiscrepancy(value) {
27
+ switch (value.mismatch) {
28
+ case "allowedTypes": {
29
+ return {
30
+ mismatch: value.mismatch,
31
+ location: value.identifier === undefined
32
+ ? "root"
33
+ : {
34
+ nodeType: value.identifier,
35
+ fieldKey: value.fieldKey,
36
+ },
37
+ view: value.view.map(({ type }) => type.identifier).sort(),
38
+ ...(value.stagedView === undefined
39
+ ? {}
40
+ : {
41
+ stagedView: value.stagedView.map(({ type }) => type.identifier).sort(),
42
+ }),
43
+ stored: [...value.stored].sort(),
44
+ ...(value.viewIsStagedOptional === true ? { viewIsStagedOptional: true } : {}),
45
+ };
46
+ }
47
+ case "fieldKind": {
48
+ return {
49
+ mismatch: value.mismatch,
50
+ location: value.identifier === undefined
51
+ ? "root"
52
+ : {
53
+ nodeType: value.identifier,
54
+ fieldKey: value.fieldKey,
55
+ },
56
+ view: value.view,
57
+ stored: value.stored,
58
+ ...(value.viewIsStagedOptional === true ? { viewIsStagedOptional: true } : {}),
59
+ };
60
+ }
61
+ case "valueSchema": {
62
+ return {
63
+ mismatch: value.mismatch,
64
+ nodeType: value.identifier,
65
+ view: value.view === undefined ? undefined : index_js_1.ValueSchema[value.view],
66
+ stored: value.stored === undefined ? undefined : index_js_1.ValueSchema[value.stored],
67
+ };
68
+ }
69
+ case "nodeKind": {
70
+ const storedNodeKind = value.stored === index_js_1.ObjectNodeStoredSchema
71
+ ? "Object"
72
+ : value.stored === index_js_1.MapNodeStoredSchema
73
+ ? "Map"
74
+ : "Leaf";
75
+ return {
76
+ mismatch: value.mismatch,
77
+ nodeType: value.identifier,
78
+ view: index_js_2.NodeKind[value.view],
79
+ stored: storedNodeKind,
80
+ };
81
+ }
82
+ default: {
83
+ return (0, internal_1.unreachableCase)(value);
84
+ }
85
+ }
86
+ }
11
87
  /**
12
88
  * Determines the compatibility of a stored document (based on its stored schema) with a viewer (based on its view schema).
13
89
  *
@@ -20,29 +96,83 @@ const discrepancies_js_1 = require("./discrepancies.js");
20
96
  * @param viewSchema - Schema for the view
21
97
  * @param stored - The stored schema to check compatibility against
22
98
  * @param stagedSchemaUpgrades - Staged schema upgrades enabled for this view, or explicit stored-schema generation options
99
+ *
23
100
  */
24
101
  function checkSchemaCompatibility(viewSchema, stored, stagedSchemaUpgrades) {
25
102
  // The public API surface assumes defaultSchemaPolicy
26
- const policy = index_js_1.defaultSchemaPolicy;
103
+ const policy = index_js_3.defaultSchemaPolicy;
104
+ const configuredPolicy = (0, toStoredSchema_js_1.resolveStoredSchemaGenerationOptions)(stagedSchemaUpgrades);
105
+ const includeAlreadyEnabledUpgrades = configuredPolicy.includeAlreadyEnabledUpgrades ?? true;
106
+ // Collect upgrade locations during the discrepancy walk (single pass).
107
+ const totalLocations = new Map();
108
+ const enabledLocations = new Map();
109
+ const upgradeCollector = {
110
+ allowedType(upgrade, isEnabled) {
111
+ totalLocations.set(upgrade, (totalLocations.get(upgrade) ?? 0) + 1);
112
+ if (isEnabled) {
113
+ enabledLocations.set(upgrade, (enabledLocations.get(upgrade) ?? 0) + 1);
114
+ }
115
+ },
116
+ optionalField(upgrade, isEnabled) {
117
+ totalLocations.set(upgrade, (totalLocations.get(upgrade) ?? 0) + 1);
118
+ if (isEnabled) {
119
+ enabledLocations.set(upgrade, (enabledLocations.get(upgrade) ?? 0) + 1);
120
+ }
121
+ },
122
+ };
27
123
  // View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy
28
124
  // determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.
29
125
  // In the future, this would also include things like:
30
126
  // - fields with more allowed types in the stored schema than in the view schema have out-of-schema "unknown content" adapters
31
- let canView = true;
32
- for (const _discrepancy of (0, discrepancies_js_1.getDiscrepanciesInAllowedContent)(viewSchema, stored)) {
33
- canView = false;
34
- break;
127
+ // Complete the full walk even after finding an incompatibility so discrepancy details and
128
+ // staged-upgrade status contain all available information for debugging.
129
+ const discrepancies = [];
130
+ for (const discrepancy of (0, discrepancies_js_1.getDiscrepanciesInAllowedContent)(viewSchema, stored, upgradeCollector)) {
131
+ discrepancies.push(formatSchemaDiscrepancy(discrepancy));
35
132
  }
36
- const wouldUpgradeTo = (0, toStoredSchema_js_1.toUpgradeSchema)(viewSchema.root, stagedSchemaUpgrades);
37
- const canUpgrade = (0, index_js_1.allowsRepoSuperset)(policy, stored, wouldUpgradeTo);
133
+ const canView = discrepancies.length === 0;
134
+ const enabledUpgrades = computeUpgradeStatuses(totalLocations, enabledLocations);
135
+ const upgradePolicy = includeAlreadyEnabledUpgrades
136
+ ? includeEnabledUpgrades(configuredPolicy, enabledUpgrades)
137
+ : configuredPolicy;
138
+ const wouldUpgradeTo = (0, toStoredSchema_js_1.toUpgradeSchema)(viewSchema.root, upgradePolicy);
139
+ const canUpgrade = (0, index_js_3.allowsRepoSuperset)(policy, stored, wouldUpgradeTo);
38
140
  // If true, then upgrading has no effect on what can be stored in the document.
39
141
  // TODO: This should likely be changed to indicate up a schema upgrade would be a no-op, including stored schema metadata.
40
- const isEquivalent = canView && canUpgrade && (0, index_js_1.allowsRepoSuperset)(policy, wouldUpgradeTo, stored);
142
+ const isEquivalent = canView && canUpgrade && (0, index_js_3.allowsRepoSuperset)(policy, wouldUpgradeTo, stored);
41
143
  return {
42
144
  canView,
43
145
  canUpgrade,
44
146
  isEquivalent,
147
+ discrepancies: canView ? undefined : discrepancies,
148
+ enabledUpgrades,
45
149
  };
46
150
  }
47
151
  exports.checkSchemaCompatibility = checkSchemaCompatibility;
152
+ function includeEnabledUpgrades(configuredPolicy, enabledUpgrades) {
153
+ if (enabledUpgrades.size === 0) {
154
+ return configuredPolicy;
155
+ }
156
+ return {
157
+ includeStaged: (upgrade) => configuredPolicy.includeStaged(upgrade) || enabledUpgrades.has(upgrade),
158
+ includeStagedOptional: (upgrade) => configuredPolicy.includeStagedOptional(upgrade) || enabledUpgrades.has(upgrade),
159
+ };
160
+ }
161
+ /**
162
+ * Computes the {@link StagedUpgradeStatus} for each upgrade token from total and enabled location counts.
163
+ * Only tokens with at least one enabled location are included in the returned map.
164
+ */
165
+ function computeUpgradeStatuses(totalLocations, enabledLocations) {
166
+ const result = new Map();
167
+ for (const [upgrade, total] of totalLocations) {
168
+ const enabled = enabledLocations.get(upgrade) ?? 0;
169
+ if (enabled > 0 && enabled < total) {
170
+ result.set(upgrade, "partial");
171
+ }
172
+ else if (enabled >= total && enabled > 0) {
173
+ result.set(upgrade, "enabled");
174
+ }
175
+ }
176
+ return result;
177
+ }
48
178
  //# sourceMappingURL=schemaCompatibilityTester.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schemaCompatibilityTester.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCompatibilityTester.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,+DAA2F;AAC3F,4DAAuD;AAGvD,yDAAsE;AAGtE;;;;;;;;;;;;GAYG;AACH,SAAgB,wBAAwB,CACvC,UAAsB,EACtB,MAAwB,EACxB,oBAA0E;IAE1E,qDAAqD;IACrD,MAAM,MAAM,GAAG,8BAAmB,CAAC;IAEnC,gHAAgH;IAChH,6HAA6H;IAC7H,sDAAsD;IACtD,8HAA8H;IAC9H,IAAI,OAAO,GAAG,IAAI,CAAC;IAEnB,KAAK,MAAM,YAAY,IAAI,IAAA,mDAAgC,EAAC,UAAU,EAAE,MAAM,CAAC,EAAE,CAAC;QACjF,OAAO,GAAG,KAAK,CAAC;QAChB,MAAM;IACP,CAAC;IAED,MAAM,cAAc,GAAG,IAAA,mCAAe,EAAC,UAAU,CAAC,IAAI,EAAE,oBAAoB,CAAC,CAAC;IAE9E,MAAM,UAAU,GAAG,IAAA,6BAAkB,EAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;IAEtE,+EAA+E;IAC/E,0HAA0H;IAC1H,MAAM,YAAY,GACjB,OAAO,IAAI,UAAU,IAAI,IAAA,6BAAkB,EAAC,MAAM,EAAE,cAAc,EAAE,MAAM,CAAC,CAAC;IAE7E,OAAO;QACN,OAAO;QACP,UAAU;QACV,YAAY;KACZ,CAAC;AACH,CAAC;AAjCD,4DAiCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { TreeStoredSchema } from \"../../core/index.js\";\nimport type { SchemaUpgrade, StagedSchemaUpgradePolicy } from \"../core/index.js\";\nimport { allowsRepoSuperset, defaultSchemaPolicy } from \"../../feature-libraries/index.js\";\nimport { toUpgradeSchema } from \"../toStoredSchema.js\";\nimport type { TreeSchema } from \"../treeSchema.js\";\n\nimport { getDiscrepanciesInAllowedContent } from \"./discrepancies.js\";\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * Determines the compatibility of a stored document (based on its stored schema) with a viewer (based on its view schema).\n *\n * Adapters can be provided to handle differences between the two schema.\n * Adapters should only use to types in the `view` SchemaRepository.\n *\n * TODO: this API violates the parse don't validate design philosophy.\n * It should be wrapped with (or replaced by) a parse style API.\n *\n * @param viewSchema - Schema for the view\n * @param stored - The stored schema to check compatibility against\n * @param stagedSchemaUpgrades - Staged schema upgrades enabled for this view, or explicit stored-schema generation options\n */\nexport function checkSchemaCompatibility(\n\tviewSchema: TreeSchema,\n\tstored: TreeStoredSchema,\n\tstagedSchemaUpgrades?: Iterable<SchemaUpgrade> | StagedSchemaUpgradePolicy,\n): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\t// The public API surface assumes defaultSchemaPolicy\n\tconst policy = defaultSchemaPolicy;\n\n\t// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy\n\t// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.\n\t// In the future, this would also include things like:\n\t// - fields with more allowed types in the stored schema than in the view schema have out-of-schema \"unknown content\" adapters\n\tlet canView = true;\n\n\tfor (const _discrepancy of getDiscrepanciesInAllowedContent(viewSchema, stored)) {\n\t\tcanView = false;\n\t\tbreak;\n\t}\n\n\tconst wouldUpgradeTo = toUpgradeSchema(viewSchema.root, stagedSchemaUpgrades);\n\n\tconst canUpgrade = allowsRepoSuperset(policy, stored, wouldUpgradeTo);\n\n\t// If true, then upgrading has no effect on what can be stored in the document.\n\t// TODO: This should likely be changed to indicate up a schema upgrade would be a no-op, including stored schema metadata.\n\tconst isEquivalent =\n\t\tcanView && canUpgrade && allowsRepoSuperset(policy, wouldUpgradeTo, stored);\n\n\treturn {\n\t\tcanView,\n\t\tcanUpgrade,\n\t\tisEquivalent,\n\t};\n}\n"]}
1
+ {"version":3,"file":"schemaCompatibilityTester.js","sourceRoot":"","sources":["../../../src/simple-tree/api/schemaCompatibilityTester.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,kEAAsE;AAEtE,kDAK6B;AAE7B,+CAA4C;AAC5C,+DAA2F;AAC3F,4DAA6F;AAG7F,yDAI4B;AAG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AC3C,eAAgE;IAEhE,IAAI,eAAe,CAAC,IAAI,KAAK,CAAC,EAAE,CAAC;QAChC,OAAO,gBAAgB,CAAC;IACzB,CAAC;IACD,OAAO;QACN,aAAa,EAAE,CAAC,OAAO,EAAE,EAAE,CAC1B,gBAAgB,CAAC,aAAa,CAAC,OAAO,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC;QACxE,qBAAqB,EAAE,CAAC,OAAO,EAAE,EAAE,CAClC,gBAAgB,CAAC,qBAAqB,CAAC,OAAO,CAAC,IAAI,eAAe,CAAC,GAAG,CAAC,OAAO,CAAC;KAChF,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,sBAAsB,CAC9B,cAAkD,EAClD,gBAAoD;IAEpD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAsC,CAAC;IAC7D,KAAK,MAAM,CAAC,OAAO,EAAE,KAAK,CAAC,IAAI,cAAc,EAAE,CAAC;QAC/C,MAAM,OAAO,GAAG,gBAAgB,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QACnD,IAAI,OAAO,GAAG,CAAC,IAAI,OAAO,GAAG,KAAK,EAAE,CAAC;YACpC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAChC,CAAC;aAAM,IAAI,OAAO,IAAI,KAAK,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAC5C,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,SAAS,CAAC,CAAC;QAChC,CAAC;IACF,CAAC;IACD,OAAO,MAAM,CAAC;AACf,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { unreachableCase } from \"@fluidframework/core-utils/internal\";\n\nimport {\n\tMapNodeStoredSchema,\n\tObjectNodeStoredSchema,\n\ttype TreeStoredSchema,\n\tValueSchema,\n} from \"../../core/index.js\";\nimport type { SchemaUpgrade, StagedSchemaUpgradePolicy } from \"../core/index.js\";\nimport { NodeKind } from \"../core/index.js\";\nimport { allowsRepoSuperset, defaultSchemaPolicy } from \"../../feature-libraries/index.js\";\nimport { resolveStoredSchemaGenerationOptions, toUpgradeSchema } from \"../toStoredSchema.js\";\nimport type { TreeSchema } from \"../treeSchema.js\";\n\nimport {\n\tgetDiscrepanciesInAllowedContent,\n\ttype Discrepancy,\n\ttype UpgradeLocationCollector,\n} from \"./discrepancies.js\";\nimport type { SchemaCompatibilityStatusBeta, SchemaDiscrepancy } from \"./tree.js\";\n\n/**\n * Describes the discrepancies that prevent a view schema from viewing a stored schema as a\n * readonly array.\n */\nexport function getSchemaIncompatibilityDetails(\n\tviewSchema: TreeSchema,\n\tstored: TreeStoredSchema,\n): readonly SchemaDiscrepancy[] | undefined {\n\tconst discrepancies = [...getDiscrepanciesInAllowedContent(viewSchema, stored)];\n\tif (discrepancies.length === 0) {\n\t\treturn undefined;\n\t}\n\n\treturn discrepancies.map(formatSchemaDiscrepancy);\n}\n\nfunction formatSchemaDiscrepancy(value: Discrepancy): SchemaDiscrepancy {\n\tswitch (value.mismatch) {\n\t\tcase \"allowedTypes\": {\n\t\t\treturn {\n\t\t\t\tmismatch: value.mismatch,\n\t\t\t\tlocation:\n\t\t\t\t\tvalue.identifier === undefined\n\t\t\t\t\t\t? \"root\"\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tnodeType: value.identifier,\n\t\t\t\t\t\t\t\tfieldKey: value.fieldKey,\n\t\t\t\t\t\t\t},\n\t\t\t\tview: value.view.map(({ type }) => type.identifier).sort(),\n\t\t\t\t...(value.stagedView === undefined\n\t\t\t\t\t? {}\n\t\t\t\t\t: {\n\t\t\t\t\t\t\tstagedView: value.stagedView.map(({ type }) => type.identifier).sort(),\n\t\t\t\t\t\t}),\n\t\t\t\tstored: [...value.stored].sort(),\n\t\t\t\t...(value.viewIsStagedOptional === true ? { viewIsStagedOptional: true } : {}),\n\t\t\t};\n\t\t}\n\t\tcase \"fieldKind\": {\n\t\t\treturn {\n\t\t\t\tmismatch: value.mismatch,\n\t\t\t\tlocation:\n\t\t\t\t\tvalue.identifier === undefined\n\t\t\t\t\t\t? \"root\"\n\t\t\t\t\t\t: {\n\t\t\t\t\t\t\t\tnodeType: value.identifier,\n\t\t\t\t\t\t\t\tfieldKey: value.fieldKey,\n\t\t\t\t\t\t\t},\n\t\t\t\tview: value.view,\n\t\t\t\tstored: value.stored,\n\t\t\t\t...(value.viewIsStagedOptional === true ? { viewIsStagedOptional: true } : {}),\n\t\t\t};\n\t\t}\n\t\tcase \"valueSchema\": {\n\t\t\treturn {\n\t\t\t\tmismatch: value.mismatch,\n\t\t\t\tnodeType: value.identifier,\n\t\t\t\tview: value.view === undefined ? undefined : ValueSchema[value.view],\n\t\t\t\tstored: value.stored === undefined ? undefined : ValueSchema[value.stored],\n\t\t\t};\n\t\t}\n\t\tcase \"nodeKind\": {\n\t\t\tconst storedNodeKind =\n\t\t\t\tvalue.stored === ObjectNodeStoredSchema\n\t\t\t\t\t? \"Object\"\n\t\t\t\t\t: value.stored === MapNodeStoredSchema\n\t\t\t\t\t\t? \"Map\"\n\t\t\t\t\t\t: \"Leaf\";\n\t\t\treturn {\n\t\t\t\tmismatch: value.mismatch,\n\t\t\t\tnodeType: value.identifier,\n\t\t\t\tview: NodeKind[value.view],\n\t\t\t\tstored: storedNodeKind,\n\t\t\t};\n\t\t}\n\t\tdefault: {\n\t\t\treturn unreachableCase(value);\n\t\t}\n\t}\n}\n\n/**\n * The enablement status of a staged schema upgrade in a document's stored schema.\n *\n * @remarks\n * - `\"disabled\"` — no locations guarded by the upgrade are enabled in stored schema.\n * - `\"partial\"` — at least one location is enabled but not all of them.\n * - `\"enabled\"` — all locations guarded by the upgrade are enabled in stored schema.\n *\n * @alpha\n */\nexport type StagedUpgradeStatus = \"disabled\" | \"partial\" | \"enabled\";\n\n/**\n * Determines the compatibility of a stored document (based on its stored schema) with a viewer (based on its view schema).\n *\n * Adapters can be provided to handle differences between the two schema.\n * Adapters should only use to types in the `view` SchemaRepository.\n *\n * TODO: this API violates the parse don't validate design philosophy.\n * It should be wrapped with (or replaced by) a parse style API.\n *\n * @param viewSchema - Schema for the view\n * @param stored - The stored schema to check compatibility against\n * @param stagedSchemaUpgrades - Staged schema upgrades enabled for this view, or explicit stored-schema generation options\n *\n */\nexport function checkSchemaCompatibility(\n\tviewSchema: TreeSchema,\n\tstored: TreeStoredSchema,\n\tstagedSchemaUpgrades?: Iterable<SchemaUpgrade> | StagedSchemaUpgradePolicy,\n): Omit<SchemaCompatibilityStatusBeta, \"canInitialize\"> & {\n\tenabledUpgrades: ReadonlyMap<SchemaUpgrade, StagedUpgradeStatus>;\n} {\n\t// The public API surface assumes defaultSchemaPolicy\n\tconst policy = defaultSchemaPolicy;\n\tconst configuredPolicy = resolveStoredSchemaGenerationOptions(stagedSchemaUpgrades);\n\tconst includeAlreadyEnabledUpgrades = configuredPolicy.includeAlreadyEnabledUpgrades ?? true;\n\n\t// Collect upgrade locations during the discrepancy walk (single pass).\n\tconst totalLocations = new Map<SchemaUpgrade, number>();\n\tconst enabledLocations = new Map<SchemaUpgrade, number>();\n\tconst upgradeCollector: UpgradeLocationCollector = {\n\t\tallowedType(upgrade, isEnabled) {\n\t\t\ttotalLocations.set(upgrade, (totalLocations.get(upgrade) ?? 0) + 1);\n\t\t\tif (isEnabled) {\n\t\t\t\tenabledLocations.set(upgrade, (enabledLocations.get(upgrade) ?? 0) + 1);\n\t\t\t}\n\t\t},\n\t\toptionalField(upgrade, isEnabled) {\n\t\t\ttotalLocations.set(upgrade, (totalLocations.get(upgrade) ?? 0) + 1);\n\t\t\tif (isEnabled) {\n\t\t\t\tenabledLocations.set(upgrade, (enabledLocations.get(upgrade) ?? 0) + 1);\n\t\t\t}\n\t\t},\n\t};\n\n\t// View schema allows a subset of documents that stored schema does, and the discrepancies are allowed by policy\n\t// determined by the view schema (i.e. objects with extra optional fields in the stored schema have opted into allowing this.\n\t// In the future, this would also include things like:\n\t// - fields with more allowed types in the stored schema than in the view schema have out-of-schema \"unknown content\" adapters\n\t// Complete the full walk even after finding an incompatibility so discrepancy details and\n\t// staged-upgrade status contain all available information for debugging.\n\tconst discrepancies: SchemaDiscrepancy[] = [];\n\tfor (const discrepancy of getDiscrepanciesInAllowedContent(\n\t\tviewSchema,\n\t\tstored,\n\t\tupgradeCollector,\n\t)) {\n\t\tdiscrepancies.push(formatSchemaDiscrepancy(discrepancy));\n\t}\n\tconst canView = discrepancies.length === 0;\n\n\tconst enabledUpgrades = computeUpgradeStatuses(totalLocations, enabledLocations);\n\tconst upgradePolicy = includeAlreadyEnabledUpgrades\n\t\t? includeEnabledUpgrades(configuredPolicy, enabledUpgrades)\n\t\t: configuredPolicy;\n\tconst wouldUpgradeTo = toUpgradeSchema(viewSchema.root, upgradePolicy);\n\n\tconst canUpgrade = allowsRepoSuperset(policy, stored, wouldUpgradeTo);\n\n\t// If true, then upgrading has no effect on what can be stored in the document.\n\t// TODO: This should likely be changed to indicate up a schema upgrade would be a no-op, including stored schema metadata.\n\tconst isEquivalent =\n\t\tcanView && canUpgrade && allowsRepoSuperset(policy, wouldUpgradeTo, stored);\n\n\treturn {\n\t\tcanView,\n\t\tcanUpgrade,\n\t\tisEquivalent,\n\t\tdiscrepancies: canView ? undefined : discrepancies,\n\t\tenabledUpgrades,\n\t};\n}\n\nfunction includeEnabledUpgrades(\n\tconfiguredPolicy: StagedSchemaUpgradePolicy,\n\tenabledUpgrades: ReadonlyMap<SchemaUpgrade, StagedUpgradeStatus>,\n): StagedSchemaUpgradePolicy {\n\tif (enabledUpgrades.size === 0) {\n\t\treturn configuredPolicy;\n\t}\n\treturn {\n\t\tincludeStaged: (upgrade) =>\n\t\t\tconfiguredPolicy.includeStaged(upgrade) || enabledUpgrades.has(upgrade),\n\t\tincludeStagedOptional: (upgrade) =>\n\t\t\tconfiguredPolicy.includeStagedOptional(upgrade) || enabledUpgrades.has(upgrade),\n\t};\n}\n\n/**\n * Computes the {@link StagedUpgradeStatus} for each upgrade token from total and enabled location counts.\n * Only tokens with at least one enabled location are included in the returned map.\n */\nfunction computeUpgradeStatuses(\n\ttotalLocations: ReadonlyMap<SchemaUpgrade, number>,\n\tenabledLocations: ReadonlyMap<SchemaUpgrade, number>,\n): ReadonlyMap<SchemaUpgrade, StagedUpgradeStatus> {\n\tconst result = new Map<SchemaUpgrade, StagedUpgradeStatus>();\n\tfor (const [upgrade, total] of totalLocations) {\n\t\tconst enabled = enabledLocations.get(upgrade) ?? 0;\n\t\tif (enabled > 0 && enabled < total) {\n\t\t\tresult.set(upgrade, \"partial\");\n\t\t} else if (enabled >= total && enabled > 0) {\n\t\t\tresult.set(upgrade, \"enabled\");\n\t\t}\n\t}\n\treturn result;\n}\n"]}
@@ -4,6 +4,7 @@
4
4
  */
5
5
  import type { ErasedType } from "@fluidframework/core-interfaces";
6
6
  import type { TreeNode } from "../core/index.js";
7
+ import type { JsonCompatibleReadOnlyObject } from "../../util/index.js";
7
8
  /**
8
9
  * A special object that signifies when a SharedTree {@link RunTransaction | transaction} should "roll back".
9
10
  * @public
@@ -85,7 +86,7 @@ export type TransactionCallbackStatusAlpha<TSuccessValue, TFailureValue> = Trans
85
86
  readonly preconditionsOnRevert?: readonly TransactionConstraintAlpha[];
86
87
  };
87
88
  /**
88
- * The result of a {@link TreeBranchAlpha.(runTransaction:2) | transaction} that doesn't return a value.
89
+ * The result of a {@link UntypedTreeViewAlpha.(runTransaction:2) | transaction} that doesn't return a value.
89
90
  * @input
90
91
  * @alpha
91
92
  */
@@ -150,7 +151,7 @@ export interface RunTransactionParamsBeta {
150
151
  /**
151
152
  * A label for this transaction that allows it to be correlated with later edits (e.g. for controlling undo/redo grouping).
152
153
  * @remarks
153
- * If this transaction is applied to a {@link TreeBranchAlpha | branch}, the label will be available in the {@link LocalChangeMetadata.label | metadata} of the {@link TreeBranchEvents.changed | `changed`} event.
154
+ * If this transaction is applied to an {@link UntypedTreeViewAlpha | untyped view}, the label will be available in the {@link LocalChangeMetadata.label | metadata} of the {@link TreeBranchEvents.changed | `changed`} event.
154
155
  *
155
156
  * If there is a nested transaction, only the outermost transaction label will be used.
156
157
  */
@@ -185,5 +186,30 @@ export interface RunTransactionParamsAlpha extends RunTransactionParamsBeta {
185
186
  * reserving the behavior; a real post-processor will be provided in a future change.
186
187
  */
187
188
  readonly postProcessor?: TransactionPostProcessor;
189
+ /**
190
+ * Arbitrary, application-defined metadata to persist alongside the commit that this transaction produces.
191
+ * @remarks
192
+ * The metadata is replicated to all collaborating clients and persisted in the document, and is readable
193
+ * via {@link TreeBranchCommitMetadata.custom} while walking the branch's
194
+ * {@link UntypedTreeViewAlpha.branchHistory | history}. It shares the lifetime of the commit it is attached
195
+ * to: once that commit is trimmed from the trunk, the metadata goes with it. If the transaction produces no
196
+ * commit — because its body made no changes, or because it was rolled back — the metadata is discarded.
197
+ *
198
+ * Nested transactions all contribute to the single commit they produce, and their metadata is available
199
+ * both flattened via {@link TreeBranchCommitMetadata.custom} and structurally via
200
+ * {@link TreeBranchCommitMetadata.customTree}.
201
+ *
202
+ * To attach metadata to the commit produced by
203
+ * {@link RevertibleAlpha.(revert:3) | reverting}, use {@link RevertOptionsAlpha.customMetadata} instead.
204
+ *
205
+ * The value is snapshotted when the transaction starts and normalized as `JSON.stringify` would. An error is
206
+ * thrown if it cannot be represented as a JSON object at all, such as when it contains a cycle or a
207
+ * `bigint`. Because it is persisted, it should be kept small; it is also bounded by the runtime's maximum
208
+ * op size.
209
+ *
210
+ * Metadata is only written to the document when `minVersionForCollab` is set to `"2.117.0"` or later.
211
+ * Otherwise it is retained in memory for the local session but not persisted or replicated.
212
+ */
213
+ readonly customMetadata?: JsonCompatibleReadOnlyObject;
188
214
  }
189
215
  //# sourceMappingURL=transactionTypes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transactionTypes.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/transactionTypes.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UA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C,aAAa,CAAC,EAAE,SAAS,0BAA0B,EAAE,CAAC;IAE/D;;;;;;;;;;;;;;OAcG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,wBAAwB,CAAC;IAElD;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,QAAQ,CAAC,cAAc,CAAC,EAAE,4BAA4B,CAAC;CACvD"}
@@ -1 +1 @@
1
- {"version":3,"file":"transactionTypes.js","sourceRoot":"","sources":["../../../src/simple-tree/api/transactionTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAMH;;;GAGG;AACU,QAAA,QAAQ,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType } from \"@fluidframework/core-interfaces\";\n\nimport type { TreeNode } from \"../core/index.js\";\n\n/**\n * A special object that signifies when a SharedTree {@link RunTransaction | transaction} should \"roll back\".\n * @public\n */\nexport const rollback = Symbol(\"SharedTree Transaction Rollback\");\n\n/**\n * A requirement for a SharedTree transaction to succeed.\n * @remarks Transaction constraints are useful for validating that the state of the tree meets some requirement when a transaction runs.\n * In general, when running a transaction a client can validate their tree state in whatever way they wish and decide to either proceed with the transaction or not.\n * However, they cannot know what the tree state will be when the transaction is _sequenced_.\n * There may have been any number of edits from other clients that get sequenced before the transaction is eventually sequenced.\n * Constraints provide a way to validate the tree state after the transaction has been sequenced and abort the transaction if the constraints are not met.\n * All clients will validate the constraints of a transaction when it is sequenced, so all clients will agree on whether the transaction succeeds or not.\n * @public\n */\nexport type TransactionConstraint = NodeInDocumentConstraint; // TODO: Add more constraint types here\n\n/**\n * Type for alpha version {@link TransactionConstraint | constraint}s\n * @sealed @alpha\n */\nexport type TransactionConstraintAlpha = TransactionConstraint | NoChangeConstraint; // TODO: Add more constraint types here\n\n/**\n * A transaction {@link TransactionConstraint | constraint} which requires that the given node exists in the tree.\n * @remarks The node must be in the document (its {@link TreeStatus | status} must be {@link TreeStatus.InDocument | InDocument}) to qualify as \"existing\".\n * @public\n */\nexport interface NodeInDocumentConstraint {\n\treadonly type: \"nodeInDocument\";\n\treadonly node: TreeNode;\n}\n\n/**\n * A {@link TransactionConstraintAlpha | constraint} which requires that, for this transaction to apply, the document must be in the same state immediately before the transaction is applied as it was before the transaction was authored.\n * When used as a revert precondition it requires that, for the revert to apply, the document must be in the same state immediately before the revert is applied as it was after the transaction was applied.\n * @alpha\n */\nexport interface NoChangeConstraint {\n\treadonly type: \"noChange\";\n}\n\n/**\n * Contains a value returned from a transaction.\n * @input\n * @beta\n */\nexport interface WithValue<TValue> {\n\t/** The user-supplied value. */\n\treadonly value: TValue;\n}\n\n/**\n * Contains a value and status returned from a user-supplied {@link TreeViewBeta.runTransaction | transaction callback}.\n * @input\n * @beta\n */\nexport type TransactionCallbackStatusBeta<TSuccessValue, TFailureValue> =\n\t| (WithValue<TSuccessValue> & {\n\t\t\t/** Indicates that the transaction callback ran successfully. */\n\t\t\treadonly rollback?: false;\n\t })\n\t| (WithValue<TFailureValue> & {\n\t\t\t/** Indicates that the transaction callback failed and the transaction should be rolled back. */\n\t\t\treadonly rollback: true;\n\t });\n\n/**\n * The result of a {@link TreeViewBeta.runTransaction | transaction} that doesn't return a value.\n * @input\n * @beta\n */\nexport type VoidTransactionCallbackStatusBeta = Omit<\n\tTransactionCallbackStatusBeta<unknown, unknown>,\n\t\"value\"\n>;\n\n/**\n * {@link TransactionCallbackStatusBeta} extended with alpha-only {@link TransactionConstraintAlpha | constraint} options.\n * @input\n * @alpha\n */\nexport type TransactionCallbackStatusAlpha<TSuccessValue, TFailureValue> =\n\tTransactionCallbackStatusBeta<TSuccessValue, TFailureValue> & {\n\t\t/**\n\t\t * An optional list of {@link TransactionConstraintAlpha | constraints} that will be checked when the commit corresponding\n\t\t * to this transaction is reverted. If any of these constraints are not met when the revert is being applied either\n\t\t * locally or on remote clients, the revert will be ignored.\n\t\t * These constraints must also be met at the time they are first introduced. If they are not met after the transaction\n\t\t * callback returns, then `runTransaction` (which invokes the transaction callback) will throw a `UsageError`.\n\t\t */\n\t\treadonly preconditionsOnRevert?: readonly TransactionConstraintAlpha[];\n\t};\n\n/**\n * The result of a {@link TreeBranchAlpha.(runTransaction:2) | transaction} that doesn't return a value.\n * @input\n * @alpha\n */\nexport type VoidTransactionCallbackStatusAlpha = Omit<\n\tTransactionCallbackStatusAlpha<unknown, unknown>,\n\t\"value\"\n>;\n\n/**\n * The result of a {@link TreeViewBeta.(runTransaction:1) | transaction} that completed successfully.\n * @sealed\n * @beta\n */\nexport interface TransactionResultSuccess<TSuccessValue> extends WithValue<TSuccessValue> {\n\t/** The success flag for a transaction that completed without being {@link TransactionCallbackStatusBeta | rolled back}. */\n\treadonly success: true;\n}\n\n/**\n * The result of a {@link TreeViewBeta.runTransaction | transaction} that was rolled back.\n * @sealed\n * @beta\n */\nexport interface TransactionResultFailed<TFailureValue> extends WithValue<TFailureValue> {\n\t/** The failure flag for a transaction that was {@link TransactionCallbackStatusBeta | rolled back}. */\n\treadonly success: false;\n}\n\n/**\n * The result of the {@link RunTransaction | RunTransaction} API.\n * @sealed\n * @beta\n */\nexport type TransactionValueResult<TSuccessValue, TFailureValue> =\n\t| TransactionResultSuccess<TSuccessValue>\n\t| TransactionResultFailed<TFailureValue>;\n\n/**\n * The result of the {@link RunTransaction | RunTransaction} API. This is the same as {@link TransactionValueResult}\n * but with the `value` field omitted. This is useful when the transaction callback doesn't need to return a value.\n * @sealed\n * @beta\n */\nexport type TransactionVoidResult =\n\t| Omit<TransactionResultSuccess<unknown>, \"value\">\n\t| Omit<TransactionResultFailed<unknown>, \"value\">;\n\n/**\n * A type-erased function that post-processes the change produced when a transaction is committed.\n *\n * @remarks\n * Supply one via {@link RunTransactionParamsAlpha.postProcessor} to process/alter\n * the change that a transaction produces. For example a post-processor could\n * remove extraneous information, so that the resulting squashed change contains\n * no extraneous information.\n *\n * This type intentionally hides its internal representation: its concrete shape\n * is an implementation detail of `@fluidframework/tree`. Obtain a value of this\n * type from a `@fluidframework/tree` helper or constant rather than constructing\n * one directly.\n *\n * @alpha\n * @sealed\n * @system\n */\nexport interface TransactionPostProcessor\n\textends ErasedType<\"@fluidframework/tree.TransactionPostProcessor\"> {}\n\n/**\n * The parameters for the {@link RunTransaction | RunTransaction} API.\n * @input\n * @beta\n */\nexport interface RunTransactionParamsBeta {\n\t/**\n\t * A label for this transaction that allows it to be correlated with later edits (e.g. for controlling undo/redo grouping).\n\t * @remarks\n\t * If this transaction is applied to a {@link TreeBranchAlpha | branch}, the label will be available in the {@link LocalChangeMetadata.label | metadata} of the {@link TreeBranchEvents.changed | `changed`} event.\n\t *\n\t * If there is a nested transaction, only the outermost transaction label will be used.\n\t */\n\treadonly label?: unknown;\n}\n\n/**\n * The parameters for the {@link RunTransaction | RunTransaction} API, extended with alpha-only {@link TransactionConstraintAlpha | constraint} options.\n * @input\n * @alpha\n */\nexport interface RunTransactionParamsAlpha extends RunTransactionParamsBeta {\n\t/**\n\t * An optional list of {@link TransactionConstraintAlpha | constraints} that are checked just before the transaction begins.\n\t * @remarks\n\t * If any of the constraints are not met when `runTransaction` is called, an error will be thrown.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t */\n\treadonly preconditions?: readonly TransactionConstraintAlpha[];\n\n\t/**\n\t * An optional {@link TransactionPostProcessor | post-processor} applied to\n\t * the change produced when this transaction is committed.\n\t * @remarks\n\t * When omitted, the transaction's edits are squashed without any such processing.\n\t *\n\t * Specific post-processors are applied according to their own rules for\n\t * optimization and other post-processing tasks in a transaction stack. For\n\t * example a \"minimization\" post-processor may be applied once for the\n\t * outermost transaction in a stack as it will process all nested edits and\n\t * there is no benefit from multiple applications.\n\t *\n\t * Note: minimization is not yet implemented. Supplying a post-processor currently has no observable effect beyond\n\t * reserving the behavior; a real post-processor will be provided in a future change.\n\t */\n\treadonly postProcessor?: TransactionPostProcessor;\n}\n"]}
1
+ {"version":3,"file":"transactionTypes.js","sourceRoot":"","sources":["../../../src/simple-tree/api/transactionTypes.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAOH;;;GAGG;AACU,QAAA,QAAQ,GAAG,MAAM,CAAC,iCAAiC,CAAC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { ErasedType } from \"@fluidframework/core-interfaces\";\n\nimport type { TreeNode } from \"../core/index.js\";\nimport type { JsonCompatibleReadOnlyObject } from \"../../util/index.js\";\n\n/**\n * A special object that signifies when a SharedTree {@link RunTransaction | transaction} should \"roll back\".\n * @public\n */\nexport const rollback = Symbol(\"SharedTree Transaction Rollback\");\n\n/**\n * A requirement for a SharedTree transaction to succeed.\n * @remarks Transaction constraints are useful for validating that the state of the tree meets some requirement when a transaction runs.\n * In general, when running a transaction a client can validate their tree state in whatever way they wish and decide to either proceed with the transaction or not.\n * However, they cannot know what the tree state will be when the transaction is _sequenced_.\n * There may have been any number of edits from other clients that get sequenced before the transaction is eventually sequenced.\n * Constraints provide a way to validate the tree state after the transaction has been sequenced and abort the transaction if the constraints are not met.\n * All clients will validate the constraints of a transaction when it is sequenced, so all clients will agree on whether the transaction succeeds or not.\n * @public\n */\nexport type TransactionConstraint = NodeInDocumentConstraint; // TODO: Add more constraint types here\n\n/**\n * Type for alpha version {@link TransactionConstraint | constraint}s\n * @sealed @alpha\n */\nexport type TransactionConstraintAlpha = TransactionConstraint | NoChangeConstraint; // TODO: Add more constraint types here\n\n/**\n * A transaction {@link TransactionConstraint | constraint} which requires that the given node exists in the tree.\n * @remarks The node must be in the document (its {@link TreeStatus | status} must be {@link TreeStatus.InDocument | InDocument}) to qualify as \"existing\".\n * @public\n */\nexport interface NodeInDocumentConstraint {\n\treadonly type: \"nodeInDocument\";\n\treadonly node: TreeNode;\n}\n\n/**\n * A {@link TransactionConstraintAlpha | constraint} which requires that, for this transaction to apply, the document must be in the same state immediately before the transaction is applied as it was before the transaction was authored.\n * When used as a revert precondition it requires that, for the revert to apply, the document must be in the same state immediately before the revert is applied as it was after the transaction was applied.\n * @alpha\n */\nexport interface NoChangeConstraint {\n\treadonly type: \"noChange\";\n}\n\n/**\n * Contains a value returned from a transaction.\n * @input\n * @beta\n */\nexport interface WithValue<TValue> {\n\t/** The user-supplied value. */\n\treadonly value: TValue;\n}\n\n/**\n * Contains a value and status returned from a user-supplied {@link TreeViewBeta.runTransaction | transaction callback}.\n * @input\n * @beta\n */\nexport type TransactionCallbackStatusBeta<TSuccessValue, TFailureValue> =\n\t| (WithValue<TSuccessValue> & {\n\t\t\t/** Indicates that the transaction callback ran successfully. */\n\t\t\treadonly rollback?: false;\n\t })\n\t| (WithValue<TFailureValue> & {\n\t\t\t/** Indicates that the transaction callback failed and the transaction should be rolled back. */\n\t\t\treadonly rollback: true;\n\t });\n\n/**\n * The result of a {@link TreeViewBeta.runTransaction | transaction} that doesn't return a value.\n * @input\n * @beta\n */\nexport type VoidTransactionCallbackStatusBeta = Omit<\n\tTransactionCallbackStatusBeta<unknown, unknown>,\n\t\"value\"\n>;\n\n/**\n * {@link TransactionCallbackStatusBeta} extended with alpha-only {@link TransactionConstraintAlpha | constraint} options.\n * @input\n * @alpha\n */\nexport type TransactionCallbackStatusAlpha<TSuccessValue, TFailureValue> =\n\tTransactionCallbackStatusBeta<TSuccessValue, TFailureValue> & {\n\t\t/**\n\t\t * An optional list of {@link TransactionConstraintAlpha | constraints} that will be checked when the commit corresponding\n\t\t * to this transaction is reverted. If any of these constraints are not met when the revert is being applied either\n\t\t * locally or on remote clients, the revert will be ignored.\n\t\t * These constraints must also be met at the time they are first introduced. If they are not met after the transaction\n\t\t * callback returns, then `runTransaction` (which invokes the transaction callback) will throw a `UsageError`.\n\t\t */\n\t\treadonly preconditionsOnRevert?: readonly TransactionConstraintAlpha[];\n\t};\n\n/**\n * The result of a {@link UntypedTreeViewAlpha.(runTransaction:2) | transaction} that doesn't return a value.\n * @input\n * @alpha\n */\nexport type VoidTransactionCallbackStatusAlpha = Omit<\n\tTransactionCallbackStatusAlpha<unknown, unknown>,\n\t\"value\"\n>;\n\n/**\n * The result of a {@link TreeViewBeta.(runTransaction:1) | transaction} that completed successfully.\n * @sealed\n * @beta\n */\nexport interface TransactionResultSuccess<TSuccessValue> extends WithValue<TSuccessValue> {\n\t/** The success flag for a transaction that completed without being {@link TransactionCallbackStatusBeta | rolled back}. */\n\treadonly success: true;\n}\n\n/**\n * The result of a {@link TreeViewBeta.runTransaction | transaction} that was rolled back.\n * @sealed\n * @beta\n */\nexport interface TransactionResultFailed<TFailureValue> extends WithValue<TFailureValue> {\n\t/** The failure flag for a transaction that was {@link TransactionCallbackStatusBeta | rolled back}. */\n\treadonly success: false;\n}\n\n/**\n * The result of the {@link RunTransaction | RunTransaction} API.\n * @sealed\n * @beta\n */\nexport type TransactionValueResult<TSuccessValue, TFailureValue> =\n\t| TransactionResultSuccess<TSuccessValue>\n\t| TransactionResultFailed<TFailureValue>;\n\n/**\n * The result of the {@link RunTransaction | RunTransaction} API. This is the same as {@link TransactionValueResult}\n * but with the `value` field omitted. This is useful when the transaction callback doesn't need to return a value.\n * @sealed\n * @beta\n */\nexport type TransactionVoidResult =\n\t| Omit<TransactionResultSuccess<unknown>, \"value\">\n\t| Omit<TransactionResultFailed<unknown>, \"value\">;\n\n/**\n * A type-erased function that post-processes the change produced when a transaction is committed.\n *\n * @remarks\n * Supply one via {@link RunTransactionParamsAlpha.postProcessor} to process/alter\n * the change that a transaction produces. For example a post-processor could\n * remove extraneous information, so that the resulting squashed change contains\n * no extraneous information.\n *\n * This type intentionally hides its internal representation: its concrete shape\n * is an implementation detail of `@fluidframework/tree`. Obtain a value of this\n * type from a `@fluidframework/tree` helper or constant rather than constructing\n * one directly.\n *\n * @alpha\n * @sealed\n * @system\n */\nexport interface TransactionPostProcessor\n\textends ErasedType<\"@fluidframework/tree.TransactionPostProcessor\"> {}\n\n/**\n * The parameters for the {@link RunTransaction | RunTransaction} API.\n * @input\n * @beta\n */\nexport interface RunTransactionParamsBeta {\n\t/**\n\t * A label for this transaction that allows it to be correlated with later edits (e.g. for controlling undo/redo grouping).\n\t * @remarks\n\t * If this transaction is applied to an {@link UntypedTreeViewAlpha | untyped view}, the label will be available in the {@link LocalChangeMetadata.label | metadata} of the {@link TreeBranchEvents.changed | `changed`} event.\n\t *\n\t * If there is a nested transaction, only the outermost transaction label will be used.\n\t */\n\treadonly label?: unknown;\n}\n\n/**\n * The parameters for the {@link RunTransaction | RunTransaction} API, extended with alpha-only {@link TransactionConstraintAlpha | constraint} options.\n * @input\n * @alpha\n */\nexport interface RunTransactionParamsAlpha extends RunTransactionParamsBeta {\n\t/**\n\t * An optional list of {@link TransactionConstraintAlpha | constraints} that are checked just before the transaction begins.\n\t * @remarks\n\t * If any of the constraints are not met when `runTransaction` is called, an error will be thrown.\n\t * If any of the constraints are not met after the transaction has been ordered by the service, it will be rolled back on this client and ignored by all other clients.\n\t */\n\treadonly preconditions?: readonly TransactionConstraintAlpha[];\n\n\t/**\n\t * An optional {@link TransactionPostProcessor | post-processor} applied to\n\t * the change produced when this transaction is committed.\n\t * @remarks\n\t * When omitted, the transaction's edits are squashed without any such processing.\n\t *\n\t * Specific post-processors are applied according to their own rules for\n\t * optimization and other post-processing tasks in a transaction stack. For\n\t * example a \"minimization\" post-processor may be applied once for the\n\t * outermost transaction in a stack as it will process all nested edits and\n\t * there is no benefit from multiple applications.\n\t *\n\t * Note: minimization is not yet implemented. Supplying a post-processor currently has no observable effect beyond\n\t * reserving the behavior; a real post-processor will be provided in a future change.\n\t */\n\treadonly postProcessor?: TransactionPostProcessor;\n\n\t/**\n\t * Arbitrary, application-defined metadata to persist alongside the commit that this transaction produces.\n\t * @remarks\n\t * The metadata is replicated to all collaborating clients and persisted in the document, and is readable\n\t * via {@link TreeBranchCommitMetadata.custom} while walking the branch's\n\t * {@link UntypedTreeViewAlpha.branchHistory | history}. It shares the lifetime of the commit it is attached\n\t * to: once that commit is trimmed from the trunk, the metadata goes with it. If the transaction produces no\n\t * commit — because its body made no changes, or because it was rolled back — the metadata is discarded.\n\t *\n\t * Nested transactions all contribute to the single commit they produce, and their metadata is available\n\t * both flattened via {@link TreeBranchCommitMetadata.custom} and structurally via\n\t * {@link TreeBranchCommitMetadata.customTree}.\n\t *\n\t * To attach metadata to the commit produced by\n\t * {@link RevertibleAlpha.(revert:3) | reverting}, use {@link RevertOptionsAlpha.customMetadata} instead.\n\t *\n\t * The value is snapshotted when the transaction starts and normalized as `JSON.stringify` would. An error is\n\t * thrown if it cannot be represented as a JSON object at all, such as when it contains a cycle or a\n\t * `bigint`. Because it is persisted, it should be kept small; it is also bounded by the runtime's maximum\n\t * op size.\n\t *\n\t * Metadata is only written to the document when `minVersionForCollab` is set to `\"2.117.0\"` or later.\n\t * Otherwise it is retained in memory for the local session but not persisted or replicated.\n\t */\n\treadonly customMetadata?: JsonCompatibleReadOnlyObject;\n}\n"]}