@fluidframework/tree 2.61.0 → 2.62.0-356644

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 (237) hide show
  1. package/api-report/tree.alpha.api.md +3 -0
  2. package/dist/core/index.d.ts +1 -1
  3. package/dist/core/index.d.ts.map +1 -1
  4. package/dist/core/index.js +2 -1
  5. package/dist/core/index.js.map +1 -1
  6. package/dist/core/rebase/index.d.ts +1 -1
  7. package/dist/core/rebase/index.d.ts.map +1 -1
  8. package/dist/core/rebase/index.js +2 -1
  9. package/dist/core/rebase/index.js.map +1 -1
  10. package/dist/core/rebase/utils.d.ts +10 -0
  11. package/dist/core/rebase/utils.d.ts.map +1 -1
  12. package/dist/core/rebase/utils.js +20 -1
  13. package/dist/core/rebase/utils.js.map +1 -1
  14. package/dist/packageVersion.d.ts +1 -1
  15. package/dist/packageVersion.d.ts.map +1 -1
  16. package/dist/packageVersion.js +1 -1
  17. package/dist/packageVersion.js.map +1 -1
  18. package/dist/shared-tree/schematizingTreeView.js +2 -2
  19. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  20. package/dist/shared-tree/sharedTree.d.ts +12 -2
  21. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  22. package/dist/shared-tree/sharedTree.js +71 -33
  23. package/dist/shared-tree/sharedTree.js.map +1 -1
  24. package/dist/shared-tree/treeCheckout.d.ts +13 -7
  25. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  26. package/dist/shared-tree/treeCheckout.js +114 -84
  27. package/dist/shared-tree/treeCheckout.js.map +1 -1
  28. package/dist/shared-tree-core/branch.d.ts +3 -0
  29. package/dist/shared-tree-core/branch.d.ts.map +1 -1
  30. package/dist/shared-tree-core/branch.js.map +1 -1
  31. package/dist/shared-tree-core/branchIdCodec.d.ts +11 -0
  32. package/dist/shared-tree-core/branchIdCodec.d.ts.map +1 -0
  33. package/dist/shared-tree-core/branchIdCodec.js +18 -0
  34. package/dist/shared-tree-core/branchIdCodec.js.map +1 -0
  35. package/dist/shared-tree-core/editManager.d.ts +33 -63
  36. package/dist/shared-tree-core/editManager.d.ts.map +1 -1
  37. package/dist/shared-tree-core/editManager.js +437 -290
  38. package/dist/shared-tree-core/editManager.js.map +1 -1
  39. package/dist/shared-tree-core/editManagerCodecs.d.ts +1 -1
  40. package/dist/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  41. package/dist/shared-tree-core/editManagerCodecs.js +7 -96
  42. package/dist/shared-tree-core/editManagerCodecs.js.map +1 -1
  43. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts +17 -0
  44. package/dist/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -0
  45. package/dist/shared-tree-core/editManagerCodecsCommons.js +139 -0
  46. package/dist/shared-tree-core/editManagerCodecsCommons.js.map +1 -0
  47. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts +16 -0
  48. package/dist/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -0
  49. package/dist/shared-tree-core/editManagerCodecsV1toV4.js +39 -0
  50. package/dist/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -0
  51. package/dist/shared-tree-core/editManagerCodecsV5.d.ts +16 -0
  52. package/dist/shared-tree-core/editManagerCodecsV5.d.ts.map +1 -0
  53. package/dist/shared-tree-core/editManagerCodecsV5.js +58 -0
  54. package/dist/shared-tree-core/editManagerCodecsV5.js.map +1 -0
  55. package/dist/shared-tree-core/{editManagerFormat.d.ts → editManagerFormatCommons.d.ts} +31 -7
  56. package/dist/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -0
  57. package/dist/shared-tree-core/{editManagerFormat.js → editManagerFormatCommons.js} +13 -12
  58. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -0
  59. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts +31 -0
  60. package/dist/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -0
  61. package/dist/shared-tree-core/editManagerFormatV1toV4.js +24 -0
  62. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -0
  63. package/dist/shared-tree-core/editManagerFormatV5.d.ts +62 -0
  64. package/dist/shared-tree-core/editManagerFormatV5.d.ts.map +1 -0
  65. package/dist/shared-tree-core/editManagerFormatV5.js +20 -0
  66. package/dist/shared-tree-core/editManagerFormatV5.js.map +1 -0
  67. package/dist/shared-tree-core/index.d.ts +3 -3
  68. package/dist/shared-tree-core/index.d.ts.map +1 -1
  69. package/dist/shared-tree-core/index.js.map +1 -1
  70. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts +11 -0
  71. package/dist/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -0
  72. package/dist/shared-tree-core/messageCodecV1ToV4.js +59 -0
  73. package/dist/shared-tree-core/messageCodecV1ToV4.js.map +1 -0
  74. package/dist/shared-tree-core/messageCodecV5.d.ts +11 -0
  75. package/dist/shared-tree-core/messageCodecV5.d.ts.map +1 -0
  76. package/dist/shared-tree-core/messageCodecV5.js +78 -0
  77. package/dist/shared-tree-core/messageCodecV5.js.map +1 -0
  78. package/dist/shared-tree-core/messageCodecs.d.ts.map +1 -1
  79. package/dist/shared-tree-core/messageCodecs.js +16 -47
  80. package/dist/shared-tree-core/messageCodecs.js.map +1 -1
  81. package/dist/shared-tree-core/{messageFormat.d.ts → messageFormatV1ToV4.d.ts} +1 -1
  82. package/dist/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -0
  83. package/dist/shared-tree-core/{messageFormat.js → messageFormatV1ToV4.js} +1 -1
  84. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -0
  85. package/dist/shared-tree-core/messageFormatV5.d.ts +42 -0
  86. package/dist/shared-tree-core/messageFormatV5.d.ts.map +1 -0
  87. package/dist/shared-tree-core/messageFormatV5.js +20 -0
  88. package/dist/shared-tree-core/messageFormatV5.js.map +1 -0
  89. package/dist/shared-tree-core/messageTypes.d.ts +12 -2
  90. package/dist/shared-tree-core/messageTypes.d.ts.map +1 -1
  91. package/dist/shared-tree-core/messageTypes.js.map +1 -1
  92. package/dist/shared-tree-core/sequenceIdUtils.d.ts +1 -1
  93. package/dist/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  94. package/dist/shared-tree-core/sequenceIdUtils.js.map +1 -1
  95. package/dist/shared-tree-core/sharedTreeCore.d.ts +18 -5
  96. package/dist/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  97. package/dist/shared-tree-core/sharedTreeCore.js +175 -56
  98. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  99. package/dist/simple-tree/api/tree.d.ts +10 -0
  100. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  101. package/dist/simple-tree/api/tree.js.map +1 -1
  102. package/lib/core/index.d.ts +1 -1
  103. package/lib/core/index.d.ts.map +1 -1
  104. package/lib/core/index.js +1 -1
  105. package/lib/core/index.js.map +1 -1
  106. package/lib/core/rebase/index.d.ts +1 -1
  107. package/lib/core/rebase/index.d.ts.map +1 -1
  108. package/lib/core/rebase/index.js +1 -1
  109. package/lib/core/rebase/index.js.map +1 -1
  110. package/lib/core/rebase/utils.d.ts +10 -0
  111. package/lib/core/rebase/utils.d.ts.map +1 -1
  112. package/lib/core/rebase/utils.js +18 -0
  113. package/lib/core/rebase/utils.js.map +1 -1
  114. package/lib/packageVersion.d.ts +1 -1
  115. package/lib/packageVersion.d.ts.map +1 -1
  116. package/lib/packageVersion.js +1 -1
  117. package/lib/packageVersion.js.map +1 -1
  118. package/lib/shared-tree/schematizingTreeView.js +2 -2
  119. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  120. package/lib/shared-tree/sharedTree.d.ts +12 -2
  121. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  122. package/lib/shared-tree/sharedTree.js +72 -34
  123. package/lib/shared-tree/sharedTree.js.map +1 -1
  124. package/lib/shared-tree/treeCheckout.d.ts +13 -7
  125. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  126. package/lib/shared-tree/treeCheckout.js +115 -85
  127. package/lib/shared-tree/treeCheckout.js.map +1 -1
  128. package/lib/shared-tree-core/branch.d.ts +3 -0
  129. package/lib/shared-tree-core/branch.d.ts.map +1 -1
  130. package/lib/shared-tree-core/branch.js.map +1 -1
  131. package/lib/shared-tree-core/branchIdCodec.d.ts +11 -0
  132. package/lib/shared-tree-core/branchIdCodec.d.ts.map +1 -0
  133. package/lib/shared-tree-core/branchIdCodec.js +13 -0
  134. package/lib/shared-tree-core/branchIdCodec.js.map +1 -0
  135. package/lib/shared-tree-core/editManager.d.ts +33 -63
  136. package/lib/shared-tree-core/editManager.d.ts.map +1 -1
  137. package/lib/shared-tree-core/editManager.js +437 -290
  138. package/lib/shared-tree-core/editManager.js.map +1 -1
  139. package/lib/shared-tree-core/editManagerCodecs.d.ts +1 -1
  140. package/lib/shared-tree-core/editManagerCodecs.d.ts.map +1 -1
  141. package/lib/shared-tree-core/editManagerCodecs.js +4 -93
  142. package/lib/shared-tree-core/editManagerCodecs.js.map +1 -1
  143. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts +17 -0
  144. package/lib/shared-tree-core/editManagerCodecsCommons.d.ts.map +1 -0
  145. package/lib/shared-tree-core/editManagerCodecsCommons.js +134 -0
  146. package/lib/shared-tree-core/editManagerCodecsCommons.js.map +1 -0
  147. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts +16 -0
  148. package/lib/shared-tree-core/editManagerCodecsV1toV4.d.ts.map +1 -0
  149. package/lib/shared-tree-core/editManagerCodecsV1toV4.js +35 -0
  150. package/lib/shared-tree-core/editManagerCodecsV1toV4.js.map +1 -0
  151. package/lib/shared-tree-core/editManagerCodecsV5.d.ts +16 -0
  152. package/lib/shared-tree-core/editManagerCodecsV5.d.ts.map +1 -0
  153. package/lib/shared-tree-core/editManagerCodecsV5.js +54 -0
  154. package/lib/shared-tree-core/editManagerCodecsV5.js.map +1 -0
  155. package/lib/shared-tree-core/{editManagerFormat.d.ts → editManagerFormatCommons.d.ts} +31 -7
  156. package/lib/shared-tree-core/editManagerFormatCommons.d.ts.map +1 -0
  157. package/lib/shared-tree-core/{editManagerFormat.js → editManagerFormatCommons.js} +10 -11
  158. package/lib/shared-tree-core/editManagerFormatCommons.js.map +1 -0
  159. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts +31 -0
  160. package/lib/shared-tree-core/editManagerFormatV1toV4.d.ts.map +1 -0
  161. package/lib/shared-tree-core/editManagerFormatV1toV4.js +20 -0
  162. package/lib/shared-tree-core/editManagerFormatV1toV4.js.map +1 -0
  163. package/lib/shared-tree-core/editManagerFormatV5.d.ts +62 -0
  164. package/lib/shared-tree-core/editManagerFormatV5.d.ts.map +1 -0
  165. package/lib/shared-tree-core/editManagerFormatV5.js +16 -0
  166. package/lib/shared-tree-core/editManagerFormatV5.js.map +1 -0
  167. package/lib/shared-tree-core/index.d.ts +3 -3
  168. package/lib/shared-tree-core/index.d.ts.map +1 -1
  169. package/lib/shared-tree-core/index.js.map +1 -1
  170. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts +11 -0
  171. package/lib/shared-tree-core/messageCodecV1ToV4.d.ts.map +1 -0
  172. package/lib/shared-tree-core/messageCodecV1ToV4.js +55 -0
  173. package/lib/shared-tree-core/messageCodecV1ToV4.js.map +1 -0
  174. package/lib/shared-tree-core/messageCodecV5.d.ts +11 -0
  175. package/lib/shared-tree-core/messageCodecV5.d.ts.map +1 -0
  176. package/lib/shared-tree-core/messageCodecV5.js +74 -0
  177. package/lib/shared-tree-core/messageCodecV5.js.map +1 -0
  178. package/lib/shared-tree-core/messageCodecs.d.ts.map +1 -1
  179. package/lib/shared-tree-core/messageCodecs.js +17 -48
  180. package/lib/shared-tree-core/messageCodecs.js.map +1 -1
  181. package/lib/shared-tree-core/{messageFormat.d.ts → messageFormatV1ToV4.d.ts} +1 -1
  182. package/lib/shared-tree-core/messageFormatV1ToV4.d.ts.map +1 -0
  183. package/lib/shared-tree-core/{messageFormat.js → messageFormatV1ToV4.js} +1 -1
  184. package/lib/shared-tree-core/messageFormatV1ToV4.js.map +1 -0
  185. package/lib/shared-tree-core/messageFormatV5.d.ts +42 -0
  186. package/lib/shared-tree-core/messageFormatV5.d.ts.map +1 -0
  187. package/lib/shared-tree-core/messageFormatV5.js +16 -0
  188. package/lib/shared-tree-core/messageFormatV5.js.map +1 -0
  189. package/lib/shared-tree-core/messageTypes.d.ts +12 -2
  190. package/lib/shared-tree-core/messageTypes.d.ts.map +1 -1
  191. package/lib/shared-tree-core/messageTypes.js.map +1 -1
  192. package/lib/shared-tree-core/sequenceIdUtils.d.ts +1 -1
  193. package/lib/shared-tree-core/sequenceIdUtils.d.ts.map +1 -1
  194. package/lib/shared-tree-core/sequenceIdUtils.js.map +1 -1
  195. package/lib/shared-tree-core/sharedTreeCore.d.ts +18 -5
  196. package/lib/shared-tree-core/sharedTreeCore.d.ts.map +1 -1
  197. package/lib/shared-tree-core/sharedTreeCore.js +176 -57
  198. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  199. package/lib/simple-tree/api/tree.d.ts +10 -0
  200. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  201. package/lib/simple-tree/api/tree.js.map +1 -1
  202. package/package.json +20 -20
  203. package/src/core/index.ts +1 -0
  204. package/src/core/rebase/index.ts +1 -0
  205. package/src/core/rebase/utils.ts +27 -0
  206. package/src/packageVersion.ts +1 -1
  207. package/src/shared-tree/schematizingTreeView.ts +2 -2
  208. package/src/shared-tree/sharedTree.ts +103 -46
  209. package/src/shared-tree/treeCheckout.ts +147 -98
  210. package/src/shared-tree-core/branch.ts +7 -0
  211. package/src/shared-tree-core/branchIdCodec.ts +28 -0
  212. package/src/shared-tree-core/editManager.ts +709 -437
  213. package/src/shared-tree-core/editManagerCodecs.ts +4 -164
  214. package/src/shared-tree-core/editManagerCodecsCommons.ts +236 -0
  215. package/src/shared-tree-core/editManagerCodecsV1toV4.ts +108 -0
  216. package/src/shared-tree-core/editManagerCodecsV5.ts +150 -0
  217. package/src/shared-tree-core/{editManagerFormat.ts → editManagerFormatCommons.ts} +17 -13
  218. package/src/shared-tree-core/editManagerFormatV1toV4.ts +42 -0
  219. package/src/shared-tree-core/editManagerFormatV5.ts +35 -0
  220. package/src/shared-tree-core/index.ts +3 -1
  221. package/src/shared-tree-core/messageCodecV1ToV4.ts +101 -0
  222. package/src/shared-tree-core/messageCodecV5.ts +128 -0
  223. package/src/shared-tree-core/messageCodecs.ts +16 -85
  224. package/src/shared-tree-core/messageFormatV5.ts +50 -0
  225. package/src/shared-tree-core/messageTypes.ts +15 -2
  226. package/src/shared-tree-core/sequenceIdUtils.ts +1 -1
  227. package/src/shared-tree-core/sharedTreeCore.ts +270 -84
  228. package/src/simple-tree/api/tree.ts +15 -0
  229. package/dist/shared-tree-core/editManagerFormat.d.ts.map +0 -1
  230. package/dist/shared-tree-core/editManagerFormat.js.map +0 -1
  231. package/dist/shared-tree-core/messageFormat.d.ts.map +0 -1
  232. package/dist/shared-tree-core/messageFormat.js.map +0 -1
  233. package/lib/shared-tree-core/editManagerFormat.d.ts.map +0 -1
  234. package/lib/shared-tree-core/editManagerFormat.js.map +0 -1
  235. package/lib/shared-tree-core/messageFormat.d.ts.map +0 -1
  236. package/lib/shared-tree-core/messageFormat.js.map +0 -1
  237. /package/src/shared-tree-core/{messageFormat.ts → messageFormatV1ToV4.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAigBH;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAuB;IAEvB,OAAO,IAA8B,CAAC;AACvC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, IDisposable, Listenable } from \"@fluidframework/core-interfaces\";\n\nimport type {\n\tCommitMetadata,\n\tRevertibleAlphaFactory,\n\tRevertibleFactory,\n} from \"../../core/index.js\";\nimport type {\n\t// This is referenced by doc comments.\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports\n\tTreeAlpha,\n} from \"../../shared-tree/index.js\";\nimport type {\n\tImplicitFieldSchema,\n\tInsertableField,\n\tInsertableTreeFieldFromImplicitField,\n\tReadableField,\n\tReadSchema,\n\tTreeFieldFromImplicitField,\n} from \"../fieldSchema.js\";\nimport type { UnsafeUnknownSchema } from \"../unsafeUnknownSchema.js\";\nimport type { SimpleTreeSchema } from \"../simpleSchema.js\";\n\nimport type { TreeViewConfiguration } from \"./configuration.js\";\nimport type {\n\tRunTransactionParams,\n\tTransactionCallbackStatus,\n\tTransactionResult,\n\tTransactionResultExt,\n\tVoidTransactionCallbackStatus,\n} from \"./transactionTypes.js\";\nimport type { VerboseTree } from \"./verboseTree.js\";\n\n/**\n * A tree from which a {@link TreeView} can be created.\n *\n * @privateRemarks\n * TODO:\n * Add stored key versions of {@link (TreeAlpha:interface).(exportVerbose:2)}, {@link (TreeAlpha:interface).(exportConcise:2)} and {@link (TreeAlpha:interface).exportCompressed} here so tree content can be accessed without a view schema.\n * Add exportSimpleSchema and exportJsonSchema methods (which should exactly match the concise format, and match the free functions for exporting view schema).\n * Maybe rename \"exportJsonSchema\" to align on \"concise\" terminology.\n * Ensure schema exporting APIs here align and reference APIs for exporting view schema to the same formats (which should include stored vs property key choice).\n * Make sure users of independentView can use these export APIs (maybe provide a reference back to the ViewableTree from the TreeView to accomplish that).\n * @system @sealed @public\n */\nexport interface ViewableTree {\n\t/**\n\t * Returns a {@link TreeView} using the provided schema.\n\t * If the stored schema is compatible with the view schema specified by `config`,\n\t * the returned {@link TreeView} will expose the root with a schema-aware API based on the provided view schema.\n\t * If the provided schema is incompatible with the stored schema, the view will instead expose a status indicating the incompatibility.\n\t *\n\t * @remarks\n\t * If the tree is uninitialized (has no schema and no content), use {@link TreeView.initialize} on the returned view to set the schema and content together.\n\t * Using `viewWith` followed by {@link TreeView.upgradeSchema} to initialize only the schema for a document is technically valid when the schema\n\t * permits trees with no content.\n\t *\n\t * Note that other clients can modify the document at any time, causing the view to change its compatibility status: see {@link TreeView.events} for how to handle invalidation in these cases.\n\t *\n\t * Only one schematized view may exist for a given ITree at a time.\n\t * If creating a second, the first must be disposed before calling `viewWith` again.\n\t *\n\t * @privateRemarks\n\t * TODO: Support adapters for handling out-of-schema data.\n\t */\n\tviewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n}\n\n/**\n * Channel for a Fluid Tree DDS.\n * @remarks\n * Allows storing and collaboratively editing schema-aware hierarchial data.\n * @sealed @public\n */\nexport interface ITree extends ViewableTree, IFluidLoadable {}\n\n/**\n * {@link ITree} extended with some alpha APIs.\n * @sealed @alpha\n */\nexport interface ITreeAlpha extends ITree {\n\t/**\n\t * Exports root in the same format as {@link (TreeAlpha:interface).(exportVerbose:1)} using stored keys.\n\t * @remarks\n\t * This is `undefined` if and only if the root field is empty (this can only happen if the root field is optional).\n\t */\n\texportVerbose(): VerboseTree | undefined;\n\n\t/**\n\t * Exports the SimpleTreeSchema that is stored in the tree, using stored keys for object fields.\n\t * @remarks\n\t * To get the schema using property keys, use {@link getSimpleSchema} on the view schema.\n\t */\n\texportSimpleSchema(): SimpleTreeSchema;\n}\n\n/**\n * A collection of functionality associated with a (version-control-style) branch of a SharedTree.\n * @remarks A `TreeBranch` allows for the {@link TreeBranch.fork | creation of branches} and for those branches to later be {@link TreeBranch.merge | merged}.\n *\n * The `TreeBranch` for a specific {@link TreeNode} may be acquired by calling `TreeAlpha.branch`.\n *\n * A branch does not necessarily know the schema of its SharedTree - to convert a branch to a {@link TreeViewAlpha | view with a schema}, use {@link TreeBranch.hasRootSchema | hasRootSchema()}.\n *\n * The branch associated directly with the {@link ITree | SharedTree} is the \"main\" branch, and all other branches fork (directly or transitively) from that main branch.\n * @sealed @alpha\n */\nexport interface TreeBranch extends IDisposable {\n\t/**\n\t * Events for the branch\n\t */\n\treadonly events: Listenable<TreeBranchEvents>;\n\n\t/**\n\t * Returns true if this branch has the given schema as its root schema.\n\t * @remarks This is a type guard which allows this branch to become strongly typed as a {@link TreeViewAlpha | view} of the given schema.\n\t *\n\t * To succeed, the given schema must be invariant to the schema of the view - it must include exactly the same allowed types.\n\t * For example, a schema of `Foo | Bar` will not match a view schema of `Foo`, and likewise a schema of `Foo` will not match a view schema of `Foo | Bar`.\n\t * @example\n\t * ```typescript\n\t * if (branch.hasRootSchema(MySchema)) {\n\t * const { root } = branch; // `branch` is now a TreeViewAlpha<MySchema>\n\t * // ...\n\t * }\n\t * ```\n\t */\n\thasRootSchema<TSchema extends ImplicitFieldSchema>(\n\t\tschema: TSchema,\n\t): this is TreeViewAlpha<TSchema>;\n\n\t/**\n\t * Fork a new branch off of this branch which is based off of this branch's current state.\n\t * @remarks Any changes to the tree on the new branch will not apply to this branch until the new branch is e.g. {@link TreeBranch.merge | merged} back into this branch.\n\t * The branch should be disposed when no longer needed, either {@link TreeBranch.dispose | explicitly} or {@link TreeBranch.merge | implicitly when merging} into another branch.\n\t */\n\tfork(): TreeBranch;\n\n\t/**\n\t * Apply all the new changes on the given branch to this branch.\n\t * @param branch - a branch which was created by a call to `branch()`.\n\t * @param disposeMerged - whether or not to dispose `branch` after the merge completes.\n\t * Defaults to true.\n\t * The {@link TreeBranch | main branch} cannot be disposed - attempting to do so will have no effect.\n\t * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.\n\t */\n\tmerge(branch: TreeBranch, disposeMerged?: boolean): void;\n\n\t/**\n\t * Advance this branch forward such that all new changes on the target branch become part of this branch.\n\t * @param branch - The branch to rebase onto.\n\t * @remarks After rebasing, this branch will be \"ahead\" of the target branch, that is, its unique changes will have been recreated as if they happened after all changes on the target branch.\n\t * This method may only be called on branches produced via {@link TreeBranch.fork | branch} - attempting to rebase the main branch will throw.\n\t *\n\t * Rebasing long-lived branches is important to avoid consuming memory unnecessarily.\n\t * In particular, the SharedTree retains all sequenced changes made to the tree since the \"most-behind\" branch was created or last rebased.\n\t *\n\t * The {@link TreeBranch | main branch} cannot be rebased onto another branch - attempting to do so will throw an error.\n\t */\n\trebaseOnto(branch: TreeBranch): void;\n\n\t/**\n\t * Run a transaction which applies one or more edits to the tree as a single atomic unit.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * It should return a status object of {@link TransactionCallbackStatus | TransactionCallbackStatus } type.\n\t * It includes a \"rollback\" property which may be returned as true at any point during the transaction. This will\n\t * abort the transaction and discard any changes it made so far.\n\t * \"rollback\" can be set to false or left undefined to indicate that the body of the transaction has successfully run.\n\t * @param params - The optional parameters for the transaction. It includes the constraints that will be checked before the transaction begins.\n\t * @returns A result object of {@link TransactionResultExt | TransactionResultExt} type. It includes the following:\n\t *\n\t * - A \"success\" flag indicating whether the transaction was successful or not.\n\t * - The success or failure value as returned by the transaction function.\n\t *\n\t * @remarks\n\t * This API will throw an error if the constraints are not met or something unexpected happens.\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t *\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t *\n\t * Nested transactions:\n\t * This API can be called from within the transaction callback of another runTransaction call. That will have slightly different behavior:\n\t *\n\t * - If the inner transaction fails, only the inner transaction will be rolled back and the outer transaction will continue.\n\t * - Constraints will apply to the outermost transaction. Constraints are applied per commit and there will be one commit generated\n\t * for the outermost transaction which includes all inner transactions.\n\t * - Undo will undo the outermost transaction and all inner transactions.\n\t */\n\trunTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue>;\n\t/**\n\t * Run a transaction which applies one or more edits to the tree as a single atomic unit.\n\t * @param transaction - The function to run as the body of the transaction. It may return the following:\n\t *\n\t * - Nothing to indicate that the body of the transaction has successfully run.\n\t * - A status object of {@link VoidTransactionCallbackStatus | VoidTransactionCallbackStatus } type. It includes a \"rollback\" property which\n\t * may be returned as true at any point during the transaction. This will abort the transaction and discard any changes it made so\n\t * far. \"rollback\" can be set to false or left undefined to indicate that the body of the transaction has successfully run.\n\t *\n\t * @param params - The optional parameters for the transaction. It includes the constraints that will be checked before the transaction begins.\n\t * @returns A result object of {@link TransactionResult | TransactionResult} type. It includes a \"success\" flag indicating whether the\n\t * transaction was successful or not.\n\t *\n\t * @remarks\n\t * This API will throw an error if the constraints are not met or something unexpected happens.\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t *\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t *\n\t * Nested transactions:\n\t * This API can be called from within the transaction callback of another runTransaction call. That will have slightly different behavior:\n\t *\n\t * - If the inner transaction fails, only the inner transaction will be rolled back and the outer transaction will continue.\n\t * - Constraints will apply to the outermost transaction. Constraints are applied per commit and there will be one commit generated\n\t * for the outermost transaction which includes all inner transactions.\n\t * - Undo will undo the outermost transaction and all inner transactions.\n\t */\n\trunTransaction(\n\t\ttransaction: () => VoidTransactionCallbackStatus | void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResult;\n\n\t/**\n\t * Dispose of this branch, cleaning up any resources associated with it.\n\t * @param error - Optional error indicating the reason for the disposal, if the object was disposed as the result of an error.\n\t * @remarks Branches can also be automatically disposed when {@link TreeBranch.merge | they are merged} into another branch.\n\t *\n\t * Disposing branches is important to avoid consuming memory unnecessarily.\n\t * In particular, the SharedTree retains all sequenced changes made to the tree since the \"most-behind\" branch was created or last {@link TreeBranch.rebaseOnto | rebased}.\n\t *\n\t * The {@link TreeBranch | main branch} cannot be disposed - attempting to do so will have no effect.\n\t */\n\tdispose(error?: Error): void;\n}\n\n/**\n * An editable view of a (version control style) branch of a shared tree based on some schema.\n *\n * @remarks\n * This schema (known as the view schema) may or may not align with the stored schema of the document.\n * Information about discrepancies between the two schemas is available via {@link TreeView.compatibility | compatibility}.\n *\n * Application authors are encouraged to read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/docs/user-facing/schema-evolution.md | schema-evolution.md}\n * and choose a schema compatibility policy that aligns with their application's needs.\n *\n * @privateRemarks\n * From an API design perspective, `upgradeSchema` could be merged into `viewWith` and/or `viewWith` could return errors explicitly on incompatible documents.\n * Such approaches would make it discoverable that out of schema handling may need to be done.\n * Doing that would however complicate trivial \"hello world\" style example slightly, as well as be a breaking API change.\n * It also seems more complex to handle invalidation with that pattern.\n * Thus this design was chosen at the risk of apps blindly accessing `root` then breaking unexpectedly when the document is incompatible.\n *\n * @see {@link TreeViewAlpha}\n * @see {@link asTreeViewAlpha}\n *\n * @sealed @public\n */\nexport interface TreeView<in out TSchema extends ImplicitFieldSchema> extends IDisposable {\n\t/**\n\t * The current root of the tree.\n\t *\n\t * If the view schema not sufficiently compatible with the stored schema, accessing this will throw.\n\t * To handle this case, check {@link TreeView.compatibility | compatibility}'s {@link SchemaCompatibilityStatus.canView | canView} before using.\n\t *\n\t * To get notified about changes to this field,\n\t * use {@link TreeViewEvents.rootChanged} via `view.events.on(\"rootChanged\", callback)`.\n\t *\n\t * To get notified about changes to stored schema (which may affect compatibility between this view's schema and\n\t * the stored schema), use {@link TreeViewEvents.schemaChanged} via `view.events.on(\"schemaChanged\", callback)`.\n\t */\n\tget root(): TreeFieldFromImplicitField<TSchema>;\n\n\tset root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);\n\n\t/**\n\t * Description of the current compatibility status between the view schema and stored schema.\n\t *\n\t * {@link TreeViewEvents.schemaChanged} is fired when the compatibility status changes.\n\t */\n\treadonly compatibility: SchemaCompatibilityStatus;\n\n\t/**\n\t * When the schemas are not an exact match and {@link SchemaCompatibilityStatus.canUpgrade} is true,\n\t * this can be used to modify the stored schema to make it match the view schema.\n\t * This will update the compatibility state, and allow access to `root`.\n\t * Beware that this may impact other clients' ability to view the document depending on the application's schema compatibility policy!\n\t * @remarks\n\t * It is an error to call this when {@link SchemaCompatibilityStatus.canUpgrade} is false, and a no-op when the stored and view schema are already an exact match.\n\t * @privateRemarks\n\t * In the future, more upgrade options could be provided here.\n\t * Some options that could be added:\n\t * - check the actual document contents (not just the schema) and attempt an atomic document update if the data is compatible.\n\t * - apply converters and upgrade the document.\n\t * - apply converters to lazily to adapt the document to the requested view schema (with optional lazy schema updates or transparent conversions on write).\n\t */\n\tupgradeSchema(): void;\n\n\t/**\n\t * Initialize the tree, setting the stored schema to match this view's schema and setting the tree content.\n\t *\n\t * Only valid to call when this view's {@link SchemaCompatibilityStatus.canInitialize} is true.\n\t *\n\t * Applications should typically call this function before attaching a `SharedTree`.\n\t * @param content - The content to initialize the tree with.\n\t */\n\tinitialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;\n\n\t/**\n\t * Events for the tree.\n\t */\n\treadonly events: Listenable<TreeViewEvents>;\n\n\t/**\n\t * The view schema used by this TreeView.\n\t */\n\treadonly schema: TSchema;\n}\n\n/**\n * {@link TreeView} with proposed changes to the schema aware typing to allow use with `UnsafeUnknownSchema`.\n * @sealed @alpha\n */\nexport interface TreeViewAlpha<\n\tin out TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema,\n> extends Omit<TreeView<ReadSchema<TSchema>>, \"root\" | \"initialize\">,\n\t\tTreeBranch {\n\tget root(): ReadableField<TSchema>;\n\n\tset root(newRoot: InsertableField<TSchema>);\n\n\treadonly events: Listenable<TreeViewEvents & TreeBranchEvents>;\n\n\tinitialize(content: InsertableField<TSchema>): void;\n\n\t// Override the base branch method to return a typed view rather than merely a branch.\n\tfork(): ReturnType<TreeBranch[\"fork\"]> & TreeViewAlpha<TSchema>;\n}\n\n/**\n * Information about a view schema's compatibility with the document's stored schema.\n *\n * See SharedTree's README for more information about choosing a compatibility policy.\n * @sealed @public\n */\nexport interface SchemaCompatibilityStatus {\n\t/**\n\t * Whether the view schema allows exactly the same set of documents as the stored schema.\n\t *\n\t * @remarks\n\t * Equivalence here is defined in terms of allowed documents because there are some degenerate cases where schemas are not\n\t * exact matches in a strict (schema-based) sense but still allow the same documents, and the document notion is more useful to applications.\n\t *\n\t * Examples which are expressible where this may occur include:\n\t *\n\t * - schema repository `A` has extra schema which schema `B` doesn't have, but they are unused (i.e. not reachable from the root schema)\n\t *\n\t * - field in schema `A` has allowed field members which the corresponding field in schema `B` does not have, but those types are not constructible (ex: an object node type containing a required field with no allowed types)\n\t *\n\t * These cases are typically not interesting to applications.\n\t */\n\treadonly isEquivalent: boolean;\n\n\t/**\n\t * Whether the current view schema is sufficiently compatible with the stored schema to allow viewing tree data.\n\t * If false, {@link TreeView.root} will throw upon access.\n\t *\n\t * Currently, this field is true iff `isEquivalent` is true.\n\t * Do not rely on this:\n\t * there are near-term plans to extend support for viewing documents when the stored schema contains additional optional fields not present in the view schema.\n\t * The other two types of backward-compatible changes (field relaxations and addition of allowed field types) will eventually be supported as well,\n\t * likely through out-of-schema content adapters that the application can provide alongside their view schema.\n\t *\n\t * Be aware that even with these SharedTree limitations fixed, application logic may not correctly tolerate the documents allowable by the stored schema!\n\t * Application authors are encouraged to read docs/user-facing/schema-evolution.md and choose a schema compatibility policy that\n\t * aligns with their application's needs.\n\t *\n\t * @remarks\n\t * When the documents allowed by the view schema is a strict superset of those by the stored schema,\n\t * this is false because writes to the document using the view schema could make the document violate its stored schema.\n\t * In this case, the stored schema could be updated to match the provided view schema, allowing read-write access to the tree.\n\t * See {@link SchemaCompatibilityStatus.canUpgrade}.\n\t *\n\t * Future version of SharedTree may provide readonly access to the document in this case because that would be safe,\n\t * but this is not currently supported.\n\t *\n\t * @privateRemarks\n\t * A necessary condition for this to be true is that the documents allowed by the view schema are a subset of those allowed by the stored schema.\n\t * This is not sufficient: the simple-tree layer's read APIs do not tolerate out-of-schema data.\n\t * For example, if the view schema for a node has a required `Point` field but the stored schema has an optional `Point` field,\n\t * read APIs on the view schema do not work correctly when the document has a node with a missing `Point` field.\n\t * Similar issues happen when the view schema has a field with less allowed types than the stored schema and the document actually leverages those types.\n\t */\n\treadonly canView: boolean;\n\n\t/**\n\t * True iff the view schema supports all possible documents permitted by the stored schema.\n\t * When true, it is valid to call {@link TreeView.upgradeSchema} (though if the stored schema is already an exact match, this is a no-op).\n\t */\n\treadonly canUpgrade: boolean;\n\n\t/**\n\t * True iff the document is uninitialized (i.e. it has no schema and no content).\n\t *\n\t * To initialize the document, call {@link TreeView.initialize}.\n\t *\n\t * @remarks\n\t * It's not necessary to check this field before calling {@link TreeView.initialize} in most scenarios; application authors typically know from\n\t * branch that they're in a flow which creates a new `SharedTree` and would like to initialize it.\n\t */\n\treadonly canInitialize: boolean;\n\n\t// TODO: Consider extending this status to include:\n\t// - application-defined metadata about the stored schema\n\t// - details about the differences between the stored and view schema sufficient for implementing \"safe mismatch\" policies\n}\n\n/**\n * Events for {@link TreeBranch}.\n * @sealed @alpha\n */\nexport interface TreeBranchEvents extends Omit<TreeViewEvents, \"commitApplied\"> {\n\t/**\n\t * Fired when a change is made to the branch. Includes data about the change that is made which listeners\n\t * can use to filter on changes they care about (e.g. local vs. remote changes).\n\t *\n\t * @param data - information about the change\n\t * @param getRevertible - a function that allows users to get a revertible for the change. If not provided,\n\t * this change is not revertible.\n\t */\n\tchanged(data: CommitMetadata, getRevertible?: RevertibleAlphaFactory): void;\n\n\t/**\n\t * Fired when:\n\t *\n\t * - a local commit is applied outside of a transaction\n\t *\n\t * - a local transaction is committed\n\t *\n\t * The event is not fired when:\n\t *\n\t * - a local commit is applied within a transaction\n\t *\n\t * - a remote commit is applied\n\t *\n\t * @param data - information about the commit that was applied\n\t * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,\n\t * this commit is not revertible.\n\t */\n\tcommitApplied(data: CommitMetadata, getRevertible?: RevertibleAlphaFactory): void;\n}\n\n/**\n * Events for {@link TreeView}.\n * @sealed @public\n */\nexport interface TreeViewEvents {\n\t/**\n\t * Raised whenever {@link TreeView.root} is invalidated.\n\t *\n\t * This includes changes to the document schema.\n\t * It also includes changes to the field containing the root such as setting or clearing an optional root or changing which node is the root.\n\t * This does NOT include changes to the content (fields/children) of the root node: for that case subscribe to events on the root node.\n\t */\n\trootChanged(): void;\n\n\t/**\n\t * The stored schema for the document has changed.\n\t * This may affect the compatibility between the view schema and the stored schema, and thus the ability to use the view.\n\t *\n\t * @remarks\n\t * This event implies that the old {@link TreeView.root} is no longer valid, but applications need not handle that separately:\n\t * {@link TreeViewEvents.rootChanged} will be fired after this event.\n\t */\n\tschemaChanged(): void;\n\n\t/**\n\t * Fired when:\n\t *\n\t * - a local commit is applied outside of a transaction\n\t *\n\t * - a local transaction is committed\n\t *\n\t * The event is not fired when:\n\t *\n\t * - a local commit is applied within a transaction\n\t *\n\t * - a remote commit is applied\n\t *\n\t * @param data - information about the commit that was applied\n\t * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,\n\t * this commit is not revertible.\n\t */\n\tcommitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;\n}\n\n/**\n * Retrieve the {@link TreeViewAlpha | alpha API} for a {@link TreeView}.\n * @alpha\n */\nexport function asTreeViewAlpha<TSchema extends ImplicitFieldSchema>(\n\tview: TreeView<TSchema>,\n): TreeViewAlpha<TSchema> {\n\treturn view as TreeViewAlpha<TSchema>;\n}\n"]}
1
+ {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAghBH;;;GAGG;AACH,MAAM,UAAU,eAAe,CAC9B,IAAuB;IAEvB,OAAO,IAA8B,CAAC;AACvC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport type { IFluidLoadable, IDisposable, Listenable } from \"@fluidframework/core-interfaces\";\n\nimport type {\n\tCommitMetadata,\n\tRevertibleAlphaFactory,\n\tRevertibleFactory,\n} from \"../../core/index.js\";\nimport type {\n\t// This is referenced by doc comments.\n\t// eslint-disable-next-line @typescript-eslint/no-unused-vars, unused-imports/no-unused-imports\n\tTreeAlpha,\n} from \"../../shared-tree/index.js\";\nimport type {\n\tImplicitFieldSchema,\n\tInsertableField,\n\tInsertableTreeFieldFromImplicitField,\n\tReadableField,\n\tReadSchema,\n\tTreeFieldFromImplicitField,\n} from \"../fieldSchema.js\";\nimport type { UnsafeUnknownSchema } from \"../unsafeUnknownSchema.js\";\nimport type { SimpleTreeSchema } from \"../simpleSchema.js\";\n\nimport type { TreeViewConfiguration } from \"./configuration.js\";\nimport type {\n\tRunTransactionParams,\n\tTransactionCallbackStatus,\n\tTransactionResult,\n\tTransactionResultExt,\n\tVoidTransactionCallbackStatus,\n} from \"./transactionTypes.js\";\nimport type { VerboseTree } from \"./verboseTree.js\";\n\n/**\n * A tree from which a {@link TreeView} can be created.\n *\n * @privateRemarks\n * TODO:\n * Add stored key versions of {@link (TreeAlpha:interface).(exportVerbose:2)}, {@link (TreeAlpha:interface).(exportConcise:2)} and {@link (TreeAlpha:interface).exportCompressed} here so tree content can be accessed without a view schema.\n * Add exportSimpleSchema and exportJsonSchema methods (which should exactly match the concise format, and match the free functions for exporting view schema).\n * Maybe rename \"exportJsonSchema\" to align on \"concise\" terminology.\n * Ensure schema exporting APIs here align and reference APIs for exporting view schema to the same formats (which should include stored vs property key choice).\n * Make sure users of independentView can use these export APIs (maybe provide a reference back to the ViewableTree from the TreeView to accomplish that).\n * @system @sealed @public\n */\nexport interface ViewableTree {\n\t/**\n\t * Returns a {@link TreeView} using the provided schema.\n\t * If the stored schema is compatible with the view schema specified by `config`,\n\t * the returned {@link TreeView} will expose the root with a schema-aware API based on the provided view schema.\n\t * If the provided schema is incompatible with the stored schema, the view will instead expose a status indicating the incompatibility.\n\t *\n\t * @remarks\n\t * If the tree is uninitialized (has no schema and no content), use {@link TreeView.initialize} on the returned view to set the schema and content together.\n\t * Using `viewWith` followed by {@link TreeView.upgradeSchema} to initialize only the schema for a document is technically valid when the schema\n\t * permits trees with no content.\n\t *\n\t * Note that other clients can modify the document at any time, causing the view to change its compatibility status: see {@link TreeView.events} for how to handle invalidation in these cases.\n\t *\n\t * Only one schematized view may exist for a given ITree at a time.\n\t * If creating a second, the first must be disposed before calling `viewWith` again.\n\t *\n\t * @privateRemarks\n\t * TODO: Support adapters for handling out-of-schema data.\n\t */\n\tviewWith<TRoot extends ImplicitFieldSchema>(\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n}\n\n/**\n * Channel for a Fluid Tree DDS.\n * @remarks\n * Allows storing and collaboratively editing schema-aware hierarchial data.\n * @sealed @public\n */\nexport interface ITree extends ViewableTree, IFluidLoadable {}\n\n/**\n * {@link ITree} extended with some alpha APIs.\n * @sealed @alpha\n */\nexport interface ITreeAlpha extends ITree {\n\t/**\n\t * Exports root in the same format as {@link (TreeAlpha:interface).(exportVerbose:1)} using stored keys.\n\t * @remarks\n\t * This is `undefined` if and only if the root field is empty (this can only happen if the root field is optional).\n\t */\n\texportVerbose(): VerboseTree | undefined;\n\n\t/**\n\t * Exports the SimpleTreeSchema that is stored in the tree, using stored keys for object fields.\n\t * @remarks\n\t * To get the schema using property keys, use {@link getSimpleSchema} on the view schema.\n\t */\n\texportSimpleSchema(): SimpleTreeSchema;\n\n\t/**\n\t * Creates a fork of the current state of the main branch.\n\t * This new branch will be shared with and editable by all clients.\n\t */\n\tcreateSharedBranch(): string;\n\n\t/**\n\t * Returns a view of the tree on the specified shared branch, using the provided schema.\n\t * See {@link ViewableTree.viewWith}.\n\t */\n\tviewSharedBranchWith<TRoot extends ImplicitFieldSchema>(\n\t\tbranchId: string,\n\t\tconfig: TreeViewConfiguration<TRoot>,\n\t): TreeView<TRoot>;\n}\n\n/**\n * A collection of functionality associated with a (version-control-style) branch of a SharedTree.\n * @remarks A `TreeBranch` allows for the {@link TreeBranch.fork | creation of branches} and for those branches to later be {@link TreeBranch.merge | merged}.\n *\n * The `TreeBranch` for a specific {@link TreeNode} may be acquired by calling `TreeAlpha.branch`.\n *\n * A branch does not necessarily know the schema of its SharedTree - to convert a branch to a {@link TreeViewAlpha | view with a schema}, use {@link TreeBranch.hasRootSchema | hasRootSchema()}.\n *\n * The branch associated directly with the {@link ITree | SharedTree} is the \"main\" branch, and all other branches fork (directly or transitively) from that main branch.\n * @sealed @alpha\n */\nexport interface TreeBranch extends IDisposable {\n\t/**\n\t * Events for the branch\n\t */\n\treadonly events: Listenable<TreeBranchEvents>;\n\n\t/**\n\t * Returns true if this branch has the given schema as its root schema.\n\t * @remarks This is a type guard which allows this branch to become strongly typed as a {@link TreeViewAlpha | view} of the given schema.\n\t *\n\t * To succeed, the given schema must be invariant to the schema of the view - it must include exactly the same allowed types.\n\t * For example, a schema of `Foo | Bar` will not match a view schema of `Foo`, and likewise a schema of `Foo` will not match a view schema of `Foo | Bar`.\n\t * @example\n\t * ```typescript\n\t * if (branch.hasRootSchema(MySchema)) {\n\t * const { root } = branch; // `branch` is now a TreeViewAlpha<MySchema>\n\t * // ...\n\t * }\n\t * ```\n\t */\n\thasRootSchema<TSchema extends ImplicitFieldSchema>(\n\t\tschema: TSchema,\n\t): this is TreeViewAlpha<TSchema>;\n\n\t/**\n\t * Fork a new branch off of this branch which is based off of this branch's current state.\n\t * @remarks Any changes to the tree on the new branch will not apply to this branch until the new branch is e.g. {@link TreeBranch.merge | merged} back into this branch.\n\t * The branch should be disposed when no longer needed, either {@link TreeBranch.dispose | explicitly} or {@link TreeBranch.merge | implicitly when merging} into another branch.\n\t */\n\tfork(): TreeBranch;\n\n\t/**\n\t * Apply all the new changes on the given branch to this branch.\n\t * @param branch - a branch which was created by a call to `branch()`.\n\t * @param disposeMerged - whether or not to dispose `branch` after the merge completes.\n\t * Defaults to true.\n\t * The {@link TreeBranch | main branch} cannot be disposed - attempting to do so will have no effect.\n\t * @remarks All ongoing transactions (if any) in `branch` will be committed before the merge.\n\t */\n\tmerge(branch: TreeBranch, disposeMerged?: boolean): void;\n\n\t/**\n\t * Advance this branch forward such that all new changes on the target branch become part of this branch.\n\t * @param branch - The branch to rebase onto.\n\t * @remarks After rebasing, this branch will be \"ahead\" of the target branch, that is, its unique changes will have been recreated as if they happened after all changes on the target branch.\n\t * This method may only be called on branches produced via {@link TreeBranch.fork | branch} - attempting to rebase the main branch will throw.\n\t *\n\t * Rebasing long-lived branches is important to avoid consuming memory unnecessarily.\n\t * In particular, the SharedTree retains all sequenced changes made to the tree since the \"most-behind\" branch was created or last rebased.\n\t *\n\t * The {@link TreeBranch | main branch} cannot be rebased onto another branch - attempting to do so will throw an error.\n\t */\n\trebaseOnto(branch: TreeBranch): void;\n\n\t/**\n\t * Run a transaction which applies one or more edits to the tree as a single atomic unit.\n\t * @param transaction - The function to run as the body of the transaction.\n\t * It should return a status object of {@link TransactionCallbackStatus | TransactionCallbackStatus } type.\n\t * It includes a \"rollback\" property which may be returned as true at any point during the transaction. This will\n\t * abort the transaction and discard any changes it made so far.\n\t * \"rollback\" can be set to false or left undefined to indicate that the body of the transaction has successfully run.\n\t * @param params - The optional parameters for the transaction. It includes the constraints that will be checked before the transaction begins.\n\t * @returns A result object of {@link TransactionResultExt | TransactionResultExt} type. It includes the following:\n\t *\n\t * - A \"success\" flag indicating whether the transaction was successful or not.\n\t * - The success or failure value as returned by the transaction function.\n\t *\n\t * @remarks\n\t * This API will throw an error if the constraints are not met or something unexpected happens.\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t *\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t *\n\t * Nested transactions:\n\t * This API can be called from within the transaction callback of another runTransaction call. That will have slightly different behavior:\n\t *\n\t * - If the inner transaction fails, only the inner transaction will be rolled back and the outer transaction will continue.\n\t * - Constraints will apply to the outermost transaction. Constraints are applied per commit and there will be one commit generated\n\t * for the outermost transaction which includes all inner transactions.\n\t * - Undo will undo the outermost transaction and all inner transactions.\n\t */\n\trunTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue>;\n\t/**\n\t * Run a transaction which applies one or more edits to the tree as a single atomic unit.\n\t * @param transaction - The function to run as the body of the transaction. It may return the following:\n\t *\n\t * - Nothing to indicate that the body of the transaction has successfully run.\n\t * - A status object of {@link VoidTransactionCallbackStatus | VoidTransactionCallbackStatus } type. It includes a \"rollback\" property which\n\t * may be returned as true at any point during the transaction. This will abort the transaction and discard any changes it made so\n\t * far. \"rollback\" can be set to false or left undefined to indicate that the body of the transaction has successfully run.\n\t *\n\t * @param params - The optional parameters for the transaction. It includes the constraints that will be checked before the transaction begins.\n\t * @returns A result object of {@link TransactionResult | TransactionResult} type. It includes a \"success\" flag indicating whether the\n\t * transaction was successful or not.\n\t *\n\t * @remarks\n\t * This API will throw an error if the constraints are not met or something unexpected happens.\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes (either from this client or from a remote client) can be interleaved with those changes.\n\t * Note that this is guaranteed by Fluid for any sequence of changes that are submitted synchronously, whether in a transaction or not.\n\t * However, using a transaction has the following additional consequences:\n\t *\n\t * - If reverted (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * - The internal data representation of a transaction with many changes is generally smaller and more efficient than that of the changes when separate.\n\t *\n\t * Local change events will be emitted for each change as the transaction is being applied.\n\t * If the transaction is rolled back, a corresponding change event will also be emitted for the rollback.\n\t *\n\t * Nested transactions:\n\t * This API can be called from within the transaction callback of another runTransaction call. That will have slightly different behavior:\n\t *\n\t * - If the inner transaction fails, only the inner transaction will be rolled back and the outer transaction will continue.\n\t * - Constraints will apply to the outermost transaction. Constraints are applied per commit and there will be one commit generated\n\t * for the outermost transaction which includes all inner transactions.\n\t * - Undo will undo the outermost transaction and all inner transactions.\n\t */\n\trunTransaction(\n\t\ttransaction: () => VoidTransactionCallbackStatus | void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResult;\n\n\t/**\n\t * Dispose of this branch, cleaning up any resources associated with it.\n\t * @param error - Optional error indicating the reason for the disposal, if the object was disposed as the result of an error.\n\t * @remarks Branches can also be automatically disposed when {@link TreeBranch.merge | they are merged} into another branch.\n\t *\n\t * Disposing branches is important to avoid consuming memory unnecessarily.\n\t * In particular, the SharedTree retains all sequenced changes made to the tree since the \"most-behind\" branch was created or last {@link TreeBranch.rebaseOnto | rebased}.\n\t *\n\t * The {@link TreeBranch | main branch} cannot be disposed - attempting to do so will have no effect.\n\t */\n\tdispose(error?: Error): void;\n}\n\n/**\n * An editable view of a (version control style) branch of a shared tree based on some schema.\n *\n * @remarks\n * This schema (known as the view schema) may or may not align with the stored schema of the document.\n * Information about discrepancies between the two schemas is available via {@link TreeView.compatibility | compatibility}.\n *\n * Application authors are encouraged to read {@link https://github.com/microsoft/FluidFramework/blob/main/packages/dds/tree/docs/user-facing/schema-evolution.md | schema-evolution.md}\n * and choose a schema compatibility policy that aligns with their application's needs.\n *\n * @privateRemarks\n * From an API design perspective, `upgradeSchema` could be merged into `viewWith` and/or `viewWith` could return errors explicitly on incompatible documents.\n * Such approaches would make it discoverable that out of schema handling may need to be done.\n * Doing that would however complicate trivial \"hello world\" style example slightly, as well as be a breaking API change.\n * It also seems more complex to handle invalidation with that pattern.\n * Thus this design was chosen at the risk of apps blindly accessing `root` then breaking unexpectedly when the document is incompatible.\n *\n * @see {@link TreeViewAlpha}\n * @see {@link asTreeViewAlpha}\n *\n * @sealed @public\n */\nexport interface TreeView<in out TSchema extends ImplicitFieldSchema> extends IDisposable {\n\t/**\n\t * The current root of the tree.\n\t *\n\t * If the view schema not sufficiently compatible with the stored schema, accessing this will throw.\n\t * To handle this case, check {@link TreeView.compatibility | compatibility}'s {@link SchemaCompatibilityStatus.canView | canView} before using.\n\t *\n\t * To get notified about changes to this field,\n\t * use {@link TreeViewEvents.rootChanged} via `view.events.on(\"rootChanged\", callback)`.\n\t *\n\t * To get notified about changes to stored schema (which may affect compatibility between this view's schema and\n\t * the stored schema), use {@link TreeViewEvents.schemaChanged} via `view.events.on(\"schemaChanged\", callback)`.\n\t */\n\tget root(): TreeFieldFromImplicitField<TSchema>;\n\n\tset root(newRoot: InsertableTreeFieldFromImplicitField<TSchema>);\n\n\t/**\n\t * Description of the current compatibility status between the view schema and stored schema.\n\t *\n\t * {@link TreeViewEvents.schemaChanged} is fired when the compatibility status changes.\n\t */\n\treadonly compatibility: SchemaCompatibilityStatus;\n\n\t/**\n\t * When the schemas are not an exact match and {@link SchemaCompatibilityStatus.canUpgrade} is true,\n\t * this can be used to modify the stored schema to make it match the view schema.\n\t * This will update the compatibility state, and allow access to `root`.\n\t * Beware that this may impact other clients' ability to view the document depending on the application's schema compatibility policy!\n\t * @remarks\n\t * It is an error to call this when {@link SchemaCompatibilityStatus.canUpgrade} is false, and a no-op when the stored and view schema are already an exact match.\n\t * @privateRemarks\n\t * In the future, more upgrade options could be provided here.\n\t * Some options that could be added:\n\t * - check the actual document contents (not just the schema) and attempt an atomic document update if the data is compatible.\n\t * - apply converters and upgrade the document.\n\t * - apply converters to lazily to adapt the document to the requested view schema (with optional lazy schema updates or transparent conversions on write).\n\t */\n\tupgradeSchema(): void;\n\n\t/**\n\t * Initialize the tree, setting the stored schema to match this view's schema and setting the tree content.\n\t *\n\t * Only valid to call when this view's {@link SchemaCompatibilityStatus.canInitialize} is true.\n\t *\n\t * Applications should typically call this function before attaching a `SharedTree`.\n\t * @param content - The content to initialize the tree with.\n\t */\n\tinitialize(content: InsertableTreeFieldFromImplicitField<TSchema>): void;\n\n\t/**\n\t * Events for the tree.\n\t */\n\treadonly events: Listenable<TreeViewEvents>;\n\n\t/**\n\t * The view schema used by this TreeView.\n\t */\n\treadonly schema: TSchema;\n}\n\n/**\n * {@link TreeView} with proposed changes to the schema aware typing to allow use with `UnsafeUnknownSchema`.\n * @sealed @alpha\n */\nexport interface TreeViewAlpha<\n\tin out TSchema extends ImplicitFieldSchema | UnsafeUnknownSchema,\n> extends Omit<TreeView<ReadSchema<TSchema>>, \"root\" | \"initialize\">,\n\t\tTreeBranch {\n\tget root(): ReadableField<TSchema>;\n\n\tset root(newRoot: InsertableField<TSchema>);\n\n\treadonly events: Listenable<TreeViewEvents & TreeBranchEvents>;\n\n\tinitialize(content: InsertableField<TSchema>): void;\n\n\t// Override the base branch method to return a typed view rather than merely a branch.\n\tfork(): ReturnType<TreeBranch[\"fork\"]> & TreeViewAlpha<TSchema>;\n}\n\n/**\n * Information about a view schema's compatibility with the document's stored schema.\n *\n * See SharedTree's README for more information about choosing a compatibility policy.\n * @sealed @public\n */\nexport interface SchemaCompatibilityStatus {\n\t/**\n\t * Whether the view schema allows exactly the same set of documents as the stored schema.\n\t *\n\t * @remarks\n\t * Equivalence here is defined in terms of allowed documents because there are some degenerate cases where schemas are not\n\t * exact matches in a strict (schema-based) sense but still allow the same documents, and the document notion is more useful to applications.\n\t *\n\t * Examples which are expressible where this may occur include:\n\t *\n\t * - schema repository `A` has extra schema which schema `B` doesn't have, but they are unused (i.e. not reachable from the root schema)\n\t *\n\t * - field in schema `A` has allowed field members which the corresponding field in schema `B` does not have, but those types are not constructible (ex: an object node type containing a required field with no allowed types)\n\t *\n\t * These cases are typically not interesting to applications.\n\t */\n\treadonly isEquivalent: boolean;\n\n\t/**\n\t * Whether the current view schema is sufficiently compatible with the stored schema to allow viewing tree data.\n\t * If false, {@link TreeView.root} will throw upon access.\n\t *\n\t * Currently, this field is true iff `isEquivalent` is true.\n\t * Do not rely on this:\n\t * there are near-term plans to extend support for viewing documents when the stored schema contains additional optional fields not present in the view schema.\n\t * The other two types of backward-compatible changes (field relaxations and addition of allowed field types) will eventually be supported as well,\n\t * likely through out-of-schema content adapters that the application can provide alongside their view schema.\n\t *\n\t * Be aware that even with these SharedTree limitations fixed, application logic may not correctly tolerate the documents allowable by the stored schema!\n\t * Application authors are encouraged to read docs/user-facing/schema-evolution.md and choose a schema compatibility policy that\n\t * aligns with their application's needs.\n\t *\n\t * @remarks\n\t * When the documents allowed by the view schema is a strict superset of those by the stored schema,\n\t * this is false because writes to the document using the view schema could make the document violate its stored schema.\n\t * In this case, the stored schema could be updated to match the provided view schema, allowing read-write access to the tree.\n\t * See {@link SchemaCompatibilityStatus.canUpgrade}.\n\t *\n\t * Future version of SharedTree may provide readonly access to the document in this case because that would be safe,\n\t * but this is not currently supported.\n\t *\n\t * @privateRemarks\n\t * A necessary condition for this to be true is that the documents allowed by the view schema are a subset of those allowed by the stored schema.\n\t * This is not sufficient: the simple-tree layer's read APIs do not tolerate out-of-schema data.\n\t * For example, if the view schema for a node has a required `Point` field but the stored schema has an optional `Point` field,\n\t * read APIs on the view schema do not work correctly when the document has a node with a missing `Point` field.\n\t * Similar issues happen when the view schema has a field with less allowed types than the stored schema and the document actually leverages those types.\n\t */\n\treadonly canView: boolean;\n\n\t/**\n\t * True iff the view schema supports all possible documents permitted by the stored schema.\n\t * When true, it is valid to call {@link TreeView.upgradeSchema} (though if the stored schema is already an exact match, this is a no-op).\n\t */\n\treadonly canUpgrade: boolean;\n\n\t/**\n\t * True iff the document is uninitialized (i.e. it has no schema and no content).\n\t *\n\t * To initialize the document, call {@link TreeView.initialize}.\n\t *\n\t * @remarks\n\t * It's not necessary to check this field before calling {@link TreeView.initialize} in most scenarios; application authors typically know from\n\t * branch that they're in a flow which creates a new `SharedTree` and would like to initialize it.\n\t */\n\treadonly canInitialize: boolean;\n\n\t// TODO: Consider extending this status to include:\n\t// - application-defined metadata about the stored schema\n\t// - details about the differences between the stored and view schema sufficient for implementing \"safe mismatch\" policies\n}\n\n/**\n * Events for {@link TreeBranch}.\n * @sealed @alpha\n */\nexport interface TreeBranchEvents extends Omit<TreeViewEvents, \"commitApplied\"> {\n\t/**\n\t * Fired when a change is made to the branch. Includes data about the change that is made which listeners\n\t * can use to filter on changes they care about (e.g. local vs. remote changes).\n\t *\n\t * @param data - information about the change\n\t * @param getRevertible - a function that allows users to get a revertible for the change. If not provided,\n\t * this change is not revertible.\n\t */\n\tchanged(data: CommitMetadata, getRevertible?: RevertibleAlphaFactory): void;\n\n\t/**\n\t * Fired when:\n\t *\n\t * - a local commit is applied outside of a transaction\n\t *\n\t * - a local transaction is committed\n\t *\n\t * The event is not fired when:\n\t *\n\t * - a local commit is applied within a transaction\n\t *\n\t * - a remote commit is applied\n\t *\n\t * @param data - information about the commit that was applied\n\t * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,\n\t * this commit is not revertible.\n\t */\n\tcommitApplied(data: CommitMetadata, getRevertible?: RevertibleAlphaFactory): void;\n}\n\n/**\n * Events for {@link TreeView}.\n * @sealed @public\n */\nexport interface TreeViewEvents {\n\t/**\n\t * Raised whenever {@link TreeView.root} is invalidated.\n\t *\n\t * This includes changes to the document schema.\n\t * It also includes changes to the field containing the root such as setting or clearing an optional root or changing which node is the root.\n\t * This does NOT include changes to the content (fields/children) of the root node: for that case subscribe to events on the root node.\n\t */\n\trootChanged(): void;\n\n\t/**\n\t * The stored schema for the document has changed.\n\t * This may affect the compatibility between the view schema and the stored schema, and thus the ability to use the view.\n\t *\n\t * @remarks\n\t * This event implies that the old {@link TreeView.root} is no longer valid, but applications need not handle that separately:\n\t * {@link TreeViewEvents.rootChanged} will be fired after this event.\n\t */\n\tschemaChanged(): void;\n\n\t/**\n\t * Fired when:\n\t *\n\t * - a local commit is applied outside of a transaction\n\t *\n\t * - a local transaction is committed\n\t *\n\t * The event is not fired when:\n\t *\n\t * - a local commit is applied within a transaction\n\t *\n\t * - a remote commit is applied\n\t *\n\t * @param data - information about the commit that was applied\n\t * @param getRevertible - a function provided that allows users to get a revertible for the commit that was applied. If not provided,\n\t * this commit is not revertible.\n\t */\n\tcommitApplied(data: CommitMetadata, getRevertible?: RevertibleFactory): void;\n}\n\n/**\n * Retrieve the {@link TreeViewAlpha | alpha API} for a {@link TreeView}.\n * @alpha\n */\nexport function asTreeViewAlpha<TSchema extends ImplicitFieldSchema>(\n\tview: TreeView<TSchema>,\n): TreeViewAlpha<TSchema> {\n\treturn view as TreeViewAlpha<TSchema>;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fluidframework/tree",
3
- "version": "2.61.0",
3
+ "version": "2.62.0-356644",
4
4
  "description": "Distributed tree",
5
5
  "homepage": "https://fluidframework.com",
6
6
  "repository": {
@@ -101,17 +101,17 @@
101
101
  "temp-directory": "nyc/.nyc_output"
102
102
  },
103
103
  "dependencies": {
104
- "@fluid-internal/client-utils": "~2.61.0",
105
- "@fluidframework/container-runtime": "~2.61.0",
106
- "@fluidframework/core-interfaces": "~2.61.0",
107
- "@fluidframework/core-utils": "~2.61.0",
108
- "@fluidframework/datastore-definitions": "~2.61.0",
109
- "@fluidframework/driver-definitions": "~2.61.0",
110
- "@fluidframework/id-compressor": "~2.61.0",
111
- "@fluidframework/runtime-definitions": "~2.61.0",
112
- "@fluidframework/runtime-utils": "~2.61.0",
113
- "@fluidframework/shared-object-base": "~2.61.0",
114
- "@fluidframework/telemetry-utils": "~2.61.0",
104
+ "@fluid-internal/client-utils": "2.62.0-356644",
105
+ "@fluidframework/container-runtime": "2.62.0-356644",
106
+ "@fluidframework/core-interfaces": "2.62.0-356644",
107
+ "@fluidframework/core-utils": "2.62.0-356644",
108
+ "@fluidframework/datastore-definitions": "2.62.0-356644",
109
+ "@fluidframework/driver-definitions": "2.62.0-356644",
110
+ "@fluidframework/id-compressor": "2.62.0-356644",
111
+ "@fluidframework/runtime-definitions": "2.62.0-356644",
112
+ "@fluidframework/runtime-utils": "2.62.0-356644",
113
+ "@fluidframework/shared-object-base": "2.62.0-356644",
114
+ "@fluidframework/telemetry-utils": "2.62.0-356644",
115
115
  "@sinclair/typebox": "^0.34.13",
116
116
  "@tylerbu/sorted-btree-es6": "^1.8.0",
117
117
  "@types/ungap__structured-clone": "^1.2.0",
@@ -121,19 +121,19 @@
121
121
  "devDependencies": {
122
122
  "@arethetypeswrong/cli": "^0.17.1",
123
123
  "@biomejs/biome": "~1.9.3",
124
- "@fluid-internal/mocha-test-setup": "~2.61.0",
125
- "@fluid-private/stochastic-test-utils": "~2.61.0",
126
- "@fluid-private/test-dds-utils": "~2.61.0",
127
- "@fluid-private/test-drivers": "~2.61.0",
124
+ "@fluid-internal/mocha-test-setup": "2.62.0-356644",
125
+ "@fluid-private/stochastic-test-utils": "2.62.0-356644",
126
+ "@fluid-private/test-dds-utils": "2.62.0-356644",
127
+ "@fluid-private/test-drivers": "2.62.0-356644",
128
128
  "@fluid-tools/benchmark": "^0.51.0",
129
129
  "@fluid-tools/build-cli": "^0.58.3",
130
130
  "@fluidframework/build-common": "^2.0.3",
131
131
  "@fluidframework/build-tools": "^0.58.3",
132
- "@fluidframework/container-definitions": "~2.61.0",
133
- "@fluidframework/container-loader": "~2.61.0",
132
+ "@fluidframework/container-definitions": "2.62.0-356644",
133
+ "@fluidframework/container-loader": "2.62.0-356644",
134
134
  "@fluidframework/eslint-config-fluid": "^6.0.0",
135
- "@fluidframework/test-runtime-utils": "~2.61.0",
136
- "@fluidframework/test-utils": "~2.61.0",
135
+ "@fluidframework/test-runtime-utils": "2.62.0-356644",
136
+ "@fluidframework/test-utils": "2.62.0-356644",
137
137
  "@fluidframework/tree-previous": "npm:@fluidframework/tree@2.60.0",
138
138
  "@microsoft/api-extractor": "7.52.11",
139
139
  "@types/diff": "^3.5.1",
package/src/core/index.ts CHANGED
@@ -207,6 +207,7 @@ export {
207
207
  type ChangeAtomIdRangeMap,
208
208
  newChangeAtomIdRangeMap,
209
209
  compareRevisions,
210
+ diffHistories,
210
211
  } from "./rebase/index.js";
211
212
 
212
213
  export {
@@ -56,4 +56,5 @@ export {
56
56
  type RebaseStatsWithDuration,
57
57
  replaceChange,
58
58
  isAncestor,
59
+ diffHistories,
59
60
  } from "./utils.js";
@@ -678,3 +678,30 @@ export function isAncestor<TNode extends { readonly parent?: TNode }>(
678
678
 
679
679
  return false;
680
680
  }
681
+
682
+ /**
683
+ * Returns a change that represents the different between two places in a commit graph.
684
+ * Applying this change to the state at `sourceCommit` will yield the state at `targetCommit`.
685
+ * @param changeRebaser - the change rebaser responsible for providing inverses to the changes in the commits.
686
+ * @param sourceCommit - the commit representing the initial state.
687
+ * @param targetCommit - the commit representing the final state.
688
+ * @param mintRevisionTag - a function which can be called to create revision tags for any rollback changes that need to be generated.
689
+ * @returns a change representing the difference between `sourceCommit` and `targetCommit`.
690
+ */
691
+ export function diffHistories<TChange>(
692
+ changeRebaser: ChangeRebaser<TChange>,
693
+ sourceCommit: GraphCommit<TChange>,
694
+ targetCommit: GraphCommit<TChange>,
695
+ mintRevisionTag: () => RevisionTag,
696
+ ): TChange {
697
+ const sourcePath: GraphCommit<TChange>[] = [];
698
+ const targetPath: GraphCommit<TChange>[] = [];
699
+ const ancestor = findCommonAncestor([sourceCommit, sourcePath], [targetCommit, targetPath]);
700
+ assert(ancestor !== undefined, "Branches must be related");
701
+ const inverses = sourcePath.map((commit) =>
702
+ rollbackFromCommit(changeRebaser, commit, mintRevisionTag),
703
+ );
704
+
705
+ inverses.reverse();
706
+ return changeRebaser.compose([...inverses, ...targetPath]);
707
+ }
@@ -6,4 +6,4 @@
6
6
  */
7
7
 
8
8
  export const pkgName = "@fluidframework/tree";
9
- export const pkgVersion = "2.61.0";
9
+ export const pkgVersion = "2.62.0-356644";
@@ -420,8 +420,8 @@ export class SchematizingSimpleTreeView<
420
420
  this.checkout.forest.anchors.slots.delete(ViewSlot);
421
421
  this.currentCompatibility = undefined;
422
422
  this.onDispose?.();
423
- if (this.checkout.isBranch && !this.checkout.disposed) {
424
- // All (non-main) branches are 1:1 with views, so if a user manually disposes a view, we should also dispose the checkout/branch.
423
+ if (!this.checkout.isSharedBranch && !this.checkout.disposed) {
424
+ // All non-shared branches are 1:1 with views, so if a user manually disposes a view, we should also dispose the checkout/branch.
425
425
  this.checkout.dispose();
426
426
  }
427
427
  }
@@ -6,7 +6,7 @@
6
6
  import type { ErasedType, IFluidLoadable } from "@fluidframework/core-interfaces/internal";
7
7
  import { assert, fail } from "@fluidframework/core-utils/internal";
8
8
  import type { IChannelStorageService } from "@fluidframework/datastore-definitions/internal";
9
- import type { IIdCompressor } from "@fluidframework/id-compressor";
9
+ import type { IIdCompressor, StableId } from "@fluidframework/id-compressor";
10
10
  import type {
11
11
  IChannelView,
12
12
  IFluidSerializer,
@@ -33,7 +33,6 @@ import {
33
33
  ObjectNodeStoredSchema,
34
34
  RevisionTagCodec,
35
35
  SchemaVersion,
36
- type TaggedChange,
37
36
  type TreeFieldStoredSchema,
38
37
  type TreeNodeSchemaIdentifier,
39
38
  type TreeNodeStoredSchema,
@@ -62,8 +61,8 @@ import {
62
61
  // eslint-disable-next-line import/no-internal-modules
63
62
  import type { FormatV1 } from "../feature-libraries/schema-index/index.js";
64
63
  import {
64
+ type BranchId,
65
65
  type ClonableSchemaAndPolicy,
66
- DefaultResubmitMachine,
67
66
  type ExplicitCoreCodecVersions,
68
67
  SharedTreeCore,
69
68
  } from "../shared-tree-core/index.js";
@@ -189,6 +188,10 @@ const formatVersionToTopLevelCodecVersions = new Map<number, ExplicitCodecVersio
189
188
  5,
190
189
  { forest: 1, schema: 2, detachedFieldIndex: 1, editManager: 4, message: 4, fieldBatch: 1 },
191
190
  ],
191
+ [
192
+ 100, // SharedTreeFormatVersion.vSharedBranches
193
+ { forest: 1, schema: 2, detachedFieldIndex: 1, editManager: 5, message: 5, fieldBatch: 1 },
194
+ ],
192
195
  ]);
193
196
 
194
197
  function getCodecVersions(formatVersion: number): ExplicitCodecVersions {
@@ -217,6 +220,8 @@ export class SharedTreeKernel
217
220
  return this.checkout.storedSchema;
218
221
  }
219
222
 
223
+ private readonly checkouts: Map<BranchId, TreeCheckout> = new Map();
224
+
220
225
  /**
221
226
  * The app-facing API for SharedTree implemented by this Kernel.
222
227
  * @remarks
@@ -232,7 +237,7 @@ export class SharedTreeKernel
232
237
  serializer: IFluidSerializer,
233
238
  submitLocalMessage: (content: unknown, localOpMetadata?: unknown) => void,
234
239
  lastSequenceNumber: () => number | undefined,
235
- logger: ITelemetryLoggerExt | undefined,
240
+ private readonly logger: ITelemetryLoggerExt | undefined,
236
241
  idCompressor: IIdCompressor,
237
242
  optionsParam: SharedTreeOptionsInternal,
238
243
  ) {
@@ -319,16 +324,12 @@ export class SharedTreeKernel
319
324
  idCompressor,
320
325
  schema,
321
326
  defaultSchemaPolicy,
322
- new DefaultResubmitMachine(
323
- (change: TaggedChange<SharedTreeChange>) =>
324
- changeFamily.rebaser.invert(change, true, this.mintRevisionTag()),
325
- changeEnricher,
326
- ),
327
+ undefined,
327
328
  changeEnricher,
328
329
  );
329
- const localBranch = this.getLocalBranch();
330
+
330
331
  this.checkout = createTreeCheckout(idCompressor, this.mintRevisionTag, revisionTagCodec, {
331
- branch: localBranch,
332
+ branch: this.getLocalBranch(),
332
333
  changeFamily,
333
334
  schema,
334
335
  forest,
@@ -340,39 +341,48 @@ export class SharedTreeKernel
340
341
  disposeForksAfterTransaction: options.disposeForksAfterTransaction,
341
342
  });
342
343
 
343
- this.checkout.transaction.events.on("started", () => {
344
- if (sharedObject.isAttached()) {
344
+ this.registerCheckout("main", this.checkout);
345
+
346
+ this.view = {
347
+ contentSnapshot: () => this.contentSnapshot(),
348
+ exportSimpleSchema: () => this.exportSimpleSchema(),
349
+ exportVerbose: () => this.exportVerbose(),
350
+ viewWith: this.viewWith.bind(this),
351
+ viewSharedBranchWith: this.viewBranchWith.bind(this),
352
+ createSharedBranch: this.createSharedBranch.bind(this),
353
+ kernel: this,
354
+ };
355
+ }
356
+
357
+ private registerCheckout(branchId: BranchId, checkout: TreeCheckout): void {
358
+ this.checkouts.set(branchId, checkout);
359
+ const enricher = this.getCommitEnricher(branchId);
360
+ checkout.transaction.events.on("started", () => {
361
+ if (this.sharedObject.isAttached()) {
345
362
  // It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.
346
- this.commitEnricher.startTransaction();
363
+ enricher.startTransaction();
347
364
  }
348
365
  });
349
- this.checkout.transaction.events.on("aborting", () => {
350
- if (sharedObject.isAttached()) {
366
+
367
+ checkout.transaction.events.on("aborting", () => {
368
+ if (this.sharedObject.isAttached()) {
351
369
  // It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.
352
- this.commitEnricher.abortTransaction();
370
+ enricher.abortTransaction();
353
371
  }
354
372
  });
355
- this.checkout.transaction.events.on("committing", () => {
356
- if (sharedObject.isAttached()) {
373
+ checkout.transaction.events.on("committing", () => {
374
+ if (this.sharedObject.isAttached()) {
357
375
  // It is currently forbidden to attach during a transaction, so transaction state changes can be ignored until after attaching.
358
- this.commitEnricher.commitTransaction();
376
+ enricher.commitTransaction();
359
377
  }
360
378
  });
361
- this.checkout.events.on("beforeBatch", (event) => {
362
- if (event.type === "append" && sharedObject.isAttached()) {
363
- if (this.checkout.transaction.isInProgress()) {
364
- this.commitEnricher.addTransactionCommits(event.newCommits);
379
+ checkout.events.on("beforeBatch", (event) => {
380
+ if (event.type === "append" && this.sharedObject.isAttached()) {
381
+ if (checkout.transaction.isInProgress()) {
382
+ enricher.addTransactionCommits(event.newCommits);
365
383
  }
366
384
  }
367
385
  });
368
-
369
- this.view = {
370
- contentSnapshot: () => this.contentSnapshot(),
371
- exportSimpleSchema: () => this.exportSimpleSchema(),
372
- exportVerbose: () => this.exportVerbose(),
373
- viewWith: this.viewWith.bind(this),
374
- kernel: this,
375
- };
376
386
  }
377
387
 
378
388
  public exportVerbose(): VerboseTree | undefined {
@@ -415,18 +425,56 @@ export class SharedTreeKernel
415
425
  TreeView<ReadSchema<TRoot>>;
416
426
  }
417
427
 
428
+ public viewBranchWith<TRoot extends ImplicitFieldSchema>(
429
+ branchId: string,
430
+ config: TreeViewConfiguration<TRoot>,
431
+ ): TreeView<TRoot>;
432
+
433
+ public viewBranchWith<TRoot extends ImplicitFieldSchema | UnsafeUnknownSchema>(
434
+ branchId: string,
435
+ config: TreeViewConfiguration<ReadSchema<TRoot>>,
436
+ ): SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>> {
437
+ const compressedId = this.idCompressor.tryRecompress(branchId as StableId);
438
+ if (compressedId === undefined) {
439
+ throw new UsageError(`No branch found with id: ${branchId}`);
440
+ }
441
+ return this.getCheckout(compressedId).viewWith(
442
+ config,
443
+ ) as SchematizingSimpleTreeView<TRoot> & TreeView<ReadSchema<TRoot>>;
444
+ }
445
+
446
+ private getCheckout(branchId: BranchId): TreeCheckout {
447
+ return this.checkouts.get(branchId) ?? this.checkoutBranch(branchId);
448
+ }
449
+
450
+ private checkoutBranch(branchId: BranchId): TreeCheckout {
451
+ const checkout = this.checkout.branch();
452
+ checkout.switchBranch(this.getSharedBranch(branchId));
453
+ const enricher = new SharedTreeReadonlyChangeEnricher(
454
+ checkout.forest,
455
+ checkout.storedSchema,
456
+ checkout.removedRoots,
457
+ );
458
+
459
+ this.registerSharedBranchForEditing(branchId, enricher);
460
+ this.registerCheckout(branchId, checkout);
461
+ return checkout;
462
+ }
463
+
418
464
  public override async loadCore(services: IChannelStorageService): Promise<void> {
419
465
  await super.loadCore(services);
420
466
  this.checkout.load();
421
467
  }
422
468
 
423
469
  public override didAttach(): void {
424
- if (this.checkout.transaction.isInProgress()) {
425
- // Attaching during a transaction is not currently supported.
426
- // At least part of of the system is known to not handle this case correctly - commit enrichment - and there may be others.
427
- throw new UsageError(
428
- "Cannot attach while a transaction is in progress. Commit or abort the transaction before attaching.",
429
- );
470
+ for (const checkout of this.checkouts.values()) {
471
+ if (checkout.transaction.isInProgress()) {
472
+ // Attaching during a transaction is not currently supported.
473
+ // At least part of of the system is known to not handle this case correctly - commit enrichment - and there may be others.
474
+ throw new UsageError(
475
+ "Cannot attach while a transaction is in progress. Commit or abort the transaction before attaching.",
476
+ );
477
+ }
430
478
  }
431
479
  super.didAttach();
432
480
  }
@@ -436,31 +484,35 @@ export class SharedTreeKernel
436
484
  SharedTreeCore<SharedTreeEditBuilder, SharedTreeChange>["applyStashedOp"]
437
485
  >
438
486
  ): void {
439
- assert(
440
- !this.checkout.transaction.isInProgress(),
441
- 0x674 /* Unexpected transaction is open while applying stashed ops */,
442
- );
487
+ for (const checkout of this.checkouts.values()) {
488
+ assert(
489
+ !checkout.transaction.isInProgress(),
490
+ 0x674 /* Unexpected transaction is open while applying stashed ops */,
491
+ );
492
+ }
443
493
  super.applyStashedOp(...args);
444
494
  }
445
495
 
446
496
  protected override submitCommit(
497
+ branchId: BranchId,
447
498
  commit: GraphCommit<SharedTreeChange>,
448
499
  schemaAndPolicy: ClonableSchemaAndPolicy,
449
500
  isResubmit: boolean,
450
501
  ): void {
502
+ const checkout = this.getCheckout(branchId);
451
503
  assert(
452
- !this.checkout.transaction.isInProgress(),
504
+ !checkout.transaction.isInProgress(),
453
505
  0xaa6 /* Cannot submit a commit while a transaction is in progress */,
454
506
  );
455
507
  if (isResubmit) {
456
- return super.submitCommit(commit, schemaAndPolicy, isResubmit);
508
+ return super.submitCommit(branchId, commit, schemaAndPolicy, isResubmit);
457
509
  }
458
510
 
459
511
  // Refrain from submitting new commits until they are validated by the checkout.
460
512
  // This is not a strict requirement for correctness in our system, but in the event that there is a bug when applying commits to the checkout
461
513
  // that causes a crash (e.g. in the forest), this will at least prevent this client from sending the problematic commit to any other clients.
462
- this.checkout.onCommitValid(commit, () =>
463
- super.submitCommit(commit, schemaAndPolicy, isResubmit),
514
+ checkout.onCommitValid(commit, () =>
515
+ super.submitCommit(branchId, commit, schemaAndPolicy, isResubmit),
464
516
  );
465
517
  }
466
518
 
@@ -561,6 +613,11 @@ export const SharedTreeFormatVersion = {
561
613
  * Requires \@fluidframework/tree \>= 2.0.0.
562
614
  */
563
615
  v5: 5,
616
+
617
+ /**
618
+ * For testing purposes only.
619
+ */
620
+ vSharedBranches: 100,
564
621
  } as const;
565
622
 
566
623
  /**