@fluidframework/tree 2.103.0 → 2.110.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 (224) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/api-report/tree.alpha.api.md +12 -3
  3. package/api-report/tree.beta.api.md +11 -3
  4. package/api-report/tree.legacy.beta.api.md +11 -3
  5. package/dist/codec/versioned/format.js +2 -24
  6. package/dist/codec/versioned/format.js.map +1 -1
  7. package/dist/core/rebase/types.js +2 -24
  8. package/dist/core/rebase/types.js.map +1 -1
  9. package/dist/core/schema-stored/formatV1.js +2 -24
  10. package/dist/core/schema-stored/formatV1.js.map +1 -1
  11. package/dist/core/schema-stored/formatV2.js +2 -24
  12. package/dist/core/schema-stored/formatV2.js.map +1 -1
  13. package/dist/core/schema-stored/index.js +3 -25
  14. package/dist/core/schema-stored/index.js.map +1 -1
  15. package/dist/core/tree/anchorSet.js +4 -8
  16. package/dist/core/tree/anchorSet.js.map +1 -1
  17. package/dist/core/tree/detachedFieldIndexFormatCommon.js +2 -24
  18. package/dist/core/tree/detachedFieldIndexFormatCommon.js.map +1 -1
  19. package/dist/core/tree/detachedFieldIndexFormatV2.js +2 -24
  20. package/dist/core/tree/detachedFieldIndexFormatV2.js.map +1 -1
  21. package/dist/core/tree/persistedTreeTextFormat.js +2 -24
  22. package/dist/core/tree/persistedTreeTextFormat.js.map +1 -1
  23. package/dist/entrypoints/internal.js +2 -15
  24. package/dist/entrypoints/internal.js.map +1 -1
  25. package/dist/feature-libraries/chunked-forest/chunkedForest.js +7 -11
  26. package/dist/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  27. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.js +2 -24
  28. package/dist/feature-libraries/chunked-forest/codec/format/formatGeneric.js.map +1 -1
  29. package/dist/feature-libraries/chunked-forest/codec/format/formatV1.js +2 -24
  30. package/dist/feature-libraries/chunked-forest/codec/format/formatV1.js.map +1 -1
  31. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js +2 -24
  32. package/dist/feature-libraries/chunked-forest/codec/format/formatV2.js.map +1 -1
  33. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js +2 -24
  34. package/dist/feature-libraries/chunked-forest/codec/format/formatVText.js.map +1 -1
  35. package/dist/feature-libraries/flex-tree/lazyEntity.js +9 -19
  36. package/dist/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  37. package/dist/feature-libraries/flex-tree/lazyNode.js +3 -13
  38. package/dist/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  39. package/dist/feature-libraries/forest-summary/formatCommon.js +2 -24
  40. package/dist/feature-libraries/forest-summary/formatCommon.js.map +1 -1
  41. package/dist/feature-libraries/index.js +2 -24
  42. package/dist/feature-libraries/index.js.map +1 -1
  43. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.js +2 -24
  44. package/dist/feature-libraries/modular-schema/genericFieldKindFormat.js.map +1 -1
  45. package/dist/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  46. package/dist/feature-libraries/modular-schema/modularChangeFamily.js +10 -30
  47. package/dist/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  48. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js +2 -24
  49. package/dist/feature-libraries/modular-schema/modularChangeFormatV1.js.map +1 -1
  50. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js +2 -24
  51. package/dist/feature-libraries/modular-schema/modularChangeFormatV2.js.map +1 -1
  52. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts +0 -5
  53. package/dist/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  54. package/dist/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  55. package/dist/feature-libraries/object-forest/objectForest.js +11 -55
  56. package/dist/feature-libraries/object-forest/objectForest.js.map +1 -1
  57. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.js +2 -24
  58. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV1.js.map +1 -1
  59. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.js +2 -24
  60. package/dist/feature-libraries/optional-field/optionalFieldChangeFormatV2.js.map +1 -1
  61. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js +2 -24
  62. package/dist/feature-libraries/schema-edits/schemaChangeFormat.js.map +1 -1
  63. package/dist/feature-libraries/schema-index/formatV1.js +2 -24
  64. package/dist/feature-libraries/schema-index/formatV1.js.map +1 -1
  65. package/dist/feature-libraries/schema-index/formatV2.js +2 -24
  66. package/dist/feature-libraries/schema-index/formatV2.js.map +1 -1
  67. package/dist/feature-libraries/sequence-field/formatV1.js +2 -24
  68. package/dist/feature-libraries/sequence-field/formatV1.js.map +1 -1
  69. package/dist/feature-libraries/sequence-field/formatV2.js +2 -24
  70. package/dist/feature-libraries/sequence-field/formatV2.js.map +1 -1
  71. package/dist/feature-libraries/sequence-field/formatV3.js +2 -24
  72. package/dist/feature-libraries/sequence-field/formatV3.js.map +1 -1
  73. package/dist/index.js +2 -24
  74. package/dist/index.js.map +1 -1
  75. package/dist/packageVersion.d.ts +1 -1
  76. package/dist/packageVersion.js +1 -1
  77. package/dist/packageVersion.js.map +1 -1
  78. package/dist/shared-tree/schematizingTreeView.d.ts +1 -0
  79. package/dist/shared-tree/schematizingTreeView.d.ts.map +1 -1
  80. package/dist/shared-tree/schematizingTreeView.js +7 -41
  81. package/dist/shared-tree/schematizingTreeView.js.map +1 -1
  82. package/dist/shared-tree/sharedTree.d.ts +0 -1
  83. package/dist/shared-tree/sharedTree.d.ts.map +1 -1
  84. package/dist/shared-tree/sharedTree.js +6 -45
  85. package/dist/shared-tree/sharedTree.js.map +1 -1
  86. package/dist/shared-tree/sharedTreeChangeFormat.js +2 -24
  87. package/dist/shared-tree/sharedTreeChangeFormat.js.map +1 -1
  88. package/dist/shared-tree/treeCheckout.d.ts +12 -3
  89. package/dist/shared-tree/treeCheckout.d.ts.map +1 -1
  90. package/dist/shared-tree/treeCheckout.js +106 -136
  91. package/dist/shared-tree/treeCheckout.js.map +1 -1
  92. package/dist/shared-tree-core/branch.js +13 -17
  93. package/dist/shared-tree-core/branch.js.map +1 -1
  94. package/dist/shared-tree-core/editManagerFormatCommons.js +2 -24
  95. package/dist/shared-tree-core/editManagerFormatCommons.js.map +1 -1
  96. package/dist/shared-tree-core/editManagerFormatV1toV4.js +2 -24
  97. package/dist/shared-tree-core/editManagerFormatV1toV4.js.map +1 -1
  98. package/dist/shared-tree-core/editManagerFormatVSharedBranches.js +2 -24
  99. package/dist/shared-tree-core/editManagerFormatVSharedBranches.js.map +1 -1
  100. package/dist/shared-tree-core/messageCodecVSharedBranches.js +2 -24
  101. package/dist/shared-tree-core/messageCodecVSharedBranches.js.map +1 -1
  102. package/dist/shared-tree-core/messageFormatV1ToV4.js +2 -24
  103. package/dist/shared-tree-core/messageFormatV1ToV4.js.map +1 -1
  104. package/dist/shared-tree-core/messageFormatVSharedBranches.js +2 -24
  105. package/dist/shared-tree-core/messageFormatVSharedBranches.js.map +1 -1
  106. package/dist/shared-tree-core/sharedTreeCore.js +6 -43
  107. package/dist/shared-tree-core/sharedTreeCore.js.map +1 -1
  108. package/dist/shared-tree-core/transaction.js +20 -30
  109. package/dist/shared-tree-core/transaction.js.map +1 -1
  110. package/dist/simple-tree/api/simpleSchemaCodec.js +2 -24
  111. package/dist/simple-tree/api/simpleSchemaCodec.js.map +1 -1
  112. package/dist/simple-tree/api/snapshotCompatibilityChecker.js +2 -24
  113. package/dist/simple-tree/api/snapshotCompatibilityChecker.js.map +1 -1
  114. package/dist/simple-tree/api/tree.d.ts +10 -0
  115. package/dist/simple-tree/api/tree.d.ts.map +1 -1
  116. package/dist/simple-tree/api/tree.js.map +1 -1
  117. package/dist/simple-tree/core/treeNodeKernel.js +83 -93
  118. package/dist/simple-tree/core/treeNodeKernel.js.map +1 -1
  119. package/dist/simple-tree/core/unhydratedFlexTree.js +6 -10
  120. package/dist/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  121. package/dist/simple-tree/leafNodeSchema.js +2 -12
  122. package/dist/simple-tree/leafNodeSchema.js.map +1 -1
  123. package/dist/simple-tree/node-kinds/array/arrayNode.js +2 -6
  124. package/dist/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  125. package/dist/simple-tree/simpleSchemaFormatV1.js +2 -24
  126. package/dist/simple-tree/simpleSchemaFormatV1.js.map +1 -1
  127. package/dist/tableSchema.d.ts +50 -4
  128. package/dist/tableSchema.d.ts.map +1 -1
  129. package/dist/tableSchema.js +202 -106
  130. package/dist/tableSchema.js.map +1 -1
  131. package/dist/util/arrayUtilities.d.ts +20 -0
  132. package/dist/util/arrayUtilities.d.ts.map +1 -1
  133. package/dist/util/arrayUtilities.js +24 -1
  134. package/dist/util/arrayUtilities.js.map +1 -1
  135. package/dist/util/index.d.ts +1 -1
  136. package/dist/util/index.d.ts.map +1 -1
  137. package/dist/util/index.js +3 -2
  138. package/dist/util/index.js.map +1 -1
  139. package/dist/util/rangeMap.d.ts +13 -0
  140. package/dist/util/rangeMap.d.ts.map +1 -1
  141. package/dist/util/rangeMap.js +69 -8
  142. package/dist/util/rangeMap.js.map +1 -1
  143. package/dist/util/typeboxBrand.js +2 -24
  144. package/dist/util/typeboxBrand.js.map +1 -1
  145. package/dist/util/utils.js +2 -24
  146. package/dist/util/utils.js.map +1 -1
  147. package/eslint.config.mts +0 -30
  148. package/lib/core/tree/anchorSet.js +1 -5
  149. package/lib/core/tree/anchorSet.js.map +1 -1
  150. package/lib/feature-libraries/chunked-forest/chunkedForest.js +1 -5
  151. package/lib/feature-libraries/chunked-forest/chunkedForest.js.map +1 -1
  152. package/lib/feature-libraries/flex-tree/lazyEntity.js +1 -11
  153. package/lib/feature-libraries/flex-tree/lazyEntity.js.map +1 -1
  154. package/lib/feature-libraries/flex-tree/lazyNode.js +1 -11
  155. package/lib/feature-libraries/flex-tree/lazyNode.js.map +1 -1
  156. package/lib/feature-libraries/modular-schema/modularChangeFamily.d.ts.map +1 -1
  157. package/lib/feature-libraries/modular-schema/modularChangeFamily.js +10 -30
  158. package/lib/feature-libraries/modular-schema/modularChangeFamily.js.map +1 -1
  159. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts +0 -5
  160. package/lib/feature-libraries/modular-schema/modularChangeTypes.d.ts.map +1 -1
  161. package/lib/feature-libraries/modular-schema/modularChangeTypes.js.map +1 -1
  162. package/lib/feature-libraries/object-forest/objectForest.js +1 -45
  163. package/lib/feature-libraries/object-forest/objectForest.js.map +1 -1
  164. package/lib/packageVersion.d.ts +1 -1
  165. package/lib/packageVersion.js +1 -1
  166. package/lib/packageVersion.js.map +1 -1
  167. package/lib/shared-tree/schematizingTreeView.d.ts +1 -0
  168. package/lib/shared-tree/schematizingTreeView.d.ts.map +1 -1
  169. package/lib/shared-tree/schematizingTreeView.js +4 -38
  170. package/lib/shared-tree/schematizingTreeView.js.map +1 -1
  171. package/lib/shared-tree/sharedTree.d.ts +0 -1
  172. package/lib/shared-tree/sharedTree.d.ts.map +1 -1
  173. package/lib/shared-tree/sharedTree.js +1 -40
  174. package/lib/shared-tree/sharedTree.js.map +1 -1
  175. package/lib/shared-tree/treeCheckout.d.ts +12 -3
  176. package/lib/shared-tree/treeCheckout.d.ts.map +1 -1
  177. package/lib/shared-tree/treeCheckout.js +62 -92
  178. package/lib/shared-tree/treeCheckout.js.map +1 -1
  179. package/lib/shared-tree-core/branch.js +1 -5
  180. package/lib/shared-tree-core/branch.js.map +1 -1
  181. package/lib/shared-tree-core/sharedTreeCore.js +1 -38
  182. package/lib/shared-tree-core/sharedTreeCore.js.map +1 -1
  183. package/lib/shared-tree-core/transaction.js +1 -11
  184. package/lib/shared-tree-core/transaction.js.map +1 -1
  185. package/lib/simple-tree/api/tree.d.ts +10 -0
  186. package/lib/simple-tree/api/tree.d.ts.map +1 -1
  187. package/lib/simple-tree/api/tree.js.map +1 -1
  188. package/lib/simple-tree/core/treeNodeKernel.js +1 -11
  189. package/lib/simple-tree/core/treeNodeKernel.js.map +1 -1
  190. package/lib/simple-tree/core/unhydratedFlexTree.js +1 -5
  191. package/lib/simple-tree/core/unhydratedFlexTree.js.map +1 -1
  192. package/lib/simple-tree/leafNodeSchema.js +1 -11
  193. package/lib/simple-tree/leafNodeSchema.js.map +1 -1
  194. package/lib/simple-tree/node-kinds/array/arrayNode.js +1 -5
  195. package/lib/simple-tree/node-kinds/array/arrayNode.js.map +1 -1
  196. package/lib/tableSchema.d.ts +50 -4
  197. package/lib/tableSchema.d.ts.map +1 -1
  198. package/lib/tableSchema.js +171 -75
  199. package/lib/tableSchema.js.map +1 -1
  200. package/lib/util/arrayUtilities.d.ts +20 -0
  201. package/lib/util/arrayUtilities.d.ts.map +1 -1
  202. package/lib/util/arrayUtilities.js +22 -0
  203. package/lib/util/arrayUtilities.js.map +1 -1
  204. package/lib/util/index.d.ts +1 -1
  205. package/lib/util/index.d.ts.map +1 -1
  206. package/lib/util/index.js +1 -1
  207. package/lib/util/index.js.map +1 -1
  208. package/lib/util/rangeMap.d.ts +13 -0
  209. package/lib/util/rangeMap.d.ts.map +1 -1
  210. package/lib/util/rangeMap.js +69 -8
  211. package/lib/util/rangeMap.js.map +1 -1
  212. package/package.json +24 -23
  213. package/src/feature-libraries/modular-schema/modularChangeFamily.ts +14 -47
  214. package/src/feature-libraries/modular-schema/modularChangeTypes.ts +0 -5
  215. package/src/packageVersion.ts +1 -1
  216. package/src/shared-tree/schematizingTreeView.ts +4 -0
  217. package/src/shared-tree/sharedTree.ts +2 -6
  218. package/src/shared-tree/treeCheckout.ts +59 -51
  219. package/src/simple-tree/api/tree.ts +11 -0
  220. package/src/tableSchema.ts +306 -80
  221. package/src/util/arrayUtilities.ts +35 -0
  222. package/src/util/index.ts +2 -0
  223. package/src/util/rangeMap.ts +108 -9
  224. package/tsconfig.json +5 -0
@@ -3,35 +3,13 @@
3
3
  * Copyright (c) Microsoft Corporation and contributors. All rights reserved.
4
4
  * Licensed under the MIT License.
5
5
  */
6
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
- if (k2 === undefined) k2 = k;
8
- var desc = Object.getOwnPropertyDescriptor(m, k);
9
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
10
- desc = { enumerable: true, get: function() { return m[k]; } };
11
- }
12
- Object.defineProperty(o, k2, desc);
13
- }) : (function(o, m, k, k2) {
14
- if (k2 === undefined) k2 = k;
15
- o[k2] = m[k];
16
- }));
17
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
18
- Object.defineProperty(o, "default", { enumerable: true, value: v });
19
- }) : function(o, v) {
20
- o["default"] = v;
21
- });
22
- var __importStar = (this && this.__importStar) || function (mod) {
23
- if (mod && mod.__esModule) return mod;
24
- var result = {};
25
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
26
- __setModuleDefault(result, mod);
27
- return result;
28
- };
29
6
  Object.defineProperty(exports, "__esModule", { value: true });
30
7
  exports.getCompatibility = exports.SnapshotCompatibilityChecker = exports.snapshotSchemaCompatibility = exports.importCompatibilitySchemaSnapshot = exports.exportCompatibilitySchemaSnapshot = exports.checkCompatibility = void 0;
8
+ const tslib_1 = require("tslib");
31
9
  const internal_1 = require("@fluidframework/core-utils/internal");
32
10
  const internal_2 = require("@fluidframework/runtime-utils/internal");
33
11
  const internal_3 = require("@fluidframework/telemetry-utils/internal");
34
- const semver = __importStar(require("semver-ts"));
12
+ const semver = tslib_1.__importStar(require("semver-ts"));
35
13
  const toStoredSchema_js_1 = require("../toStoredSchema.js");
36
14
  const treeSchema_js_1 = require("../treeSchema.js");
37
15
  const configuration_js_1 = require("./configuration.js");
@@ -1 +1 @@
1
- {"version":3,"file":"snapshotCompatibilityChecker.js","sourceRoot":"","sources":["../../../src/simple-tree/api/snapshotCompatibilityChecker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,kEAAu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B,GAAG,kBAAkB,CACrD,iBAAiB,EACjB,kBAAkB,CAClB,CAAC;IAEF,IAAA,iBAAM,EACL,4BAA4B,CAAC,YAAY,KAAK,2BAA2B,CAAC,YAAY,EACtF,KAAK,CAAC,kCAAkC,CACxC,CAAC;IAEF,yHAAyH;IACzH,MAAM,sBAAsB,GAC3B,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC,iBAAiB,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAEvE,IAAI,sBAAsB,EAAE,CAAC;QAC5B,IAAA,iBAAM,EACL,4BAA4B,CAAC,YAAY,EACzC,KAAK,CAAC,iEAAiE,CACvE,CAAC;IACH,CAAC;IAED,OAAO;QACN,6BAA6B,EAAE,4BAA4B;QAC3D,6BAA6B,EAAE,2BAA2B;QAC1D,sBAAsB;KACtB,CAAC;AACH,CAAC;AApCD,4CAoCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail, transformMapValues } from \"@fluidframework/core-utils/internal\";\nimport { selectVersionRoundedDown } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport * as semver from \"semver-ts\";\n\nimport type { JsonCompatibleReadOnly } from \"../../util/index.js\";\nimport { toInitialSchema } from \"../toStoredSchema.js\";\nimport { createTreeSchema } from \"../treeSchema.js\";\n\nimport { TreeViewConfigurationAlpha, TreeViewConfiguration } from \"./configuration.js\";\nimport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nimport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nimport {\n\tdecodeSchemaCompatibilitySnapshot,\n\tencodeSchemaCompatibilitySnapshot,\n} from \"./simpleSchemaCodec.js\";\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * Compute the compatibility of using `view` to {@link ViewableTree.viewWith | view a tree} who's {@link ITreeAlpha.exportSimpleSchema | stored schema} could be derived from `viewWhichCreatedStoredSchema` via either {@link TreeView.initialize} or {@link TreeView.upgradeSchema}.\n *\n * @remarks See {@link SchemaCompatibilityStatus} for details on the compatibility results.\n *\n * @example This example demonstrates checking the compatibility of a historical schema against a current schema.\n * In this case, the historical schema is a Point2D object with x and y fields, while the current schema is a Point3D object\n * that adds an optional z field.\n *\n * ```ts\n * // This snapshot is assumed to be the same as Point3D, except missing `z`.\n * const encodedSchema = JSON.parse(fs.readFileSync(\"PointSchema.json\", \"utf8\"));\n * const oldViewSchema = importCompatibilitySchemaSnapshot(encodedSchema);\n *\n * // Build the current view schema\n * class Point3D extends factory.object(\"Point\", {\n * \tx: factory.number,\n * \ty: factory.number,\n *\n * \t// The current schema has a new optional field that was not present on Point2D\n * \tz: factory.optional(factory.number),\n * }) {}\n * const currentViewSchema = new TreeViewConfiguration({ schema: Point3D });\n *\n * // Check to see if the document created by the historical view schema can be opened with the current view schema\n * const backwardsCompatibilityStatus = checkCompatibility(oldViewSchema, currentViewSchema);\n *\n * // z is not present in Point2D, so the schema must be upgraded\n * assert.equal(backwardsCompatibilityStatus.canView, false);\n *\n * // The schema can be upgraded to add the new optional field\n * assert.equal(backwardsCompatibilityStatus.canUpgrade, true);\n *\n * // Test what the old version of the application would do with a tree using the new schema:\n * const forwardsCompatibilityStatus = checkCompatibility(currentViewSchema, oldViewSchema);\n *\n * // If the old schema set allowUnknownOptionalFields, this would be true, but since it did not,\n * // this assert will fail, detecting the forwards compatibility break:\n * // this means these two versions of the application cannot collaborate on content using these schema.\n * assert.equal(forwardsCompatibilityStatus.canView, true);\n * ```\n *\n * @param viewWhichCreatedStoredSchema - From which to derive the stored schema, as if it initialized or upgraded a tree via {@link TreeView}.\n * @param view - The view being tested to see if it could view tree created or initialized using `viewWhichCreatedStoredSchema`.\n * @returns The compatibility status.\n *\n * @privateRemarks\n * TODO: a simple high level API for snapshot based schema compatibility checking should replace the need to export this.\n *\n * @alpha\n */\nexport function checkCompatibility(\n\tviewWhichCreatedStoredSchema: TreeViewConfiguration,\n\tview: TreeViewConfiguration,\n): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\tconst viewAsAlpha = new TreeViewConfigurationAlpha({ schema: view.schema });\n\tconst stored = toInitialSchema(viewWhichCreatedStoredSchema.schema);\n\tconst tester = new SchemaCompatibilityTester(viewAsAlpha);\n\treturn tester.checkCompatibility(stored);\n}\n\n/**\n * Returns a JSON compatible representation of the tree schema for snapshot compatibility checking.\n *\n * Snapshots can be loaded by the same or newer package versions, but not necessarily older versions.\n *\n * @see {@link importCompatibilitySchemaSnapshot} which loads these snapshots.\n *\n * @param config - The schema to snapshot. Only the schema field of the `TreeViewConfiguration` is used.\n * @returns The JSON representation of the schema.\n *\n * @example This example creates and persists a snapshot of a Point2D schema.\n *\n * ```ts\n * const schemaFactory = new SchemaFactory(\"test\");\n * class Point2D extends schemaFactory.object(\"Point\", {\n * \tx: factory.number,\n * \ty: factory.number,\n * }) {}\n * const viewSchema = new TreeViewConfiguration({ schema: Point2D });\n * const encodedSchema = JSON.stringify(exportCompatibilitySchemaSnapshot(viewSchema));\n * fs.writeFileSync(\"PointSchema.json\", encodedSchema);\n * ```\n *\n * @privateRemarks\n * TODO: a simple high level API for snapshot based schema compatibility checking should replace the need to export this.\n *\n * @alpha\n */\nexport function exportCompatibilitySchemaSnapshot(\n\tconfig: Pick<TreeViewConfiguration, \"schema\">,\n): JsonCompatibleReadOnly {\n\tconst treeSchema = createTreeSchema(config.schema);\n\treturn encodeSchemaCompatibilitySnapshot(treeSchema);\n}\n\n/**\n * Parse the format exported by {@link exportCompatibilitySchemaSnapshot} into a schema.\n *\n * Can load snapshots created by the same or older package versions, but not necessarily newer versions.\n *\n * @see {@link exportCompatibilitySchemaSnapshot} which creates these snapshots.\n *\n * @param config - The JSON representation of the schema.\n * @returns The schema. Only the schema field of the {@link TreeViewConfiguration} is populated.\n * @throws Will throw a usage error if the encoded schema is not in the expected format.\n *\n * @example This example loads and parses a snapshot of a Point2D schema.\n *\n * ```ts;\n * const oldViewSchema = importCompatibilitySchemaSnapshot(fs.readFileSync(\"PointSchema.json\", \"utf8\"));\n * ```\n * @privateRemarks\n * TODO: a simple high level API for snapshot based schema compatibility checking should replace the need to export this.\n * @alpha\n */\nexport function importCompatibilitySchemaSnapshot(\n\tconfig: JsonCompatibleReadOnly,\n): TreeViewConfiguration {\n\tconst simpleSchema = decodeSchemaCompatibilitySnapshot(config);\n\tconst viewSchema = generateSchemaFromSimpleSchema(simpleSchema);\n\n\t// We construct a TreeViewConfiguration here with the default parameters. The default set of validation parameters are fine for\n\t// a schema produced by `generateSchemaFromSimpleSchema`.\n\treturn new TreeViewConfiguration({ schema: viewSchema.root });\n}\n\n/**\n * The file system methods required by {@link snapshotSchemaCompatibility}.\n * @remarks\n * Implemented by both Node.js `fs` and `path` modules, but other implementations can be provided as needed.\n *\n * @example\n * ```typescript\n * import path from \"node:path\";\n * import fs from \"node:fs\";\n *\n * const nodeFileSystem: SnapshotFileSystem = { ...fs, ...path };\n * ```\n *\n * @privateRemarks\n * This interface is designed to be compatible with Node.js `fs` and `path` modules.\n * It is needed to avoid direct dependencies on Node.js APIs in the core library code,\n * allowing for greater portability and easier testing.\n *\n * @input\n * @beta\n */\nexport interface SnapshotFileSystem {\n\t/**\n\t * Writes a UTF-8 encoded file to disk, replacing the file if it already exists.\n\t *\n\t * @param file - Path to the file to write.\n\t * @param data - String data to be written.\n\t * @param options - Options specifying that the encoding is UTF-8.\n\t */\n\twriteFileSync(file: string, data: string, options: { encoding: \"utf8\" }): void;\n\n\t/**\n\t * Reads a UTF-8 encoded file from disk and returns its contents as a string.\n\t *\n\t * @param file - Path to the file to read.\n\t * @param encoding - The text encoding to use when reading the file. Must be `\"utf8\"`.\n\t * @returns The contents of the file as a string.\n\t */\n\t// We include the encoding here to match the function overload for readFileSync that returns a string.\n\treadFileSync(file: string, encoding: \"utf8\"): string;\n\n\t/**\n\t * How a {@link TreeView} using the snapshotted schema would report its compatibility with a document created with the current schema.\n\t *\n\t * @param dir - Path of the directory to create.\n\t * @param options - Options indicating that creation should be recursive.\n\t */\n\tmkdirSync(dir: string, options: { recursive: true }): void;\n\n\t/**\n\t * Reads the contents of a directory.\n\t *\n\t * @param dir - Path of the directory to read.\n\t * @returns An array of names of the directory entries.\n\t */\n\treaddirSync(dir: string): readonly string[];\n\n\t/**\n\t * Joins two path segments into a single path string.\n\t *\n\t * @param parentPath - The directory path.\n\t * @param childPath - Filename within `parentPath` directory.\n\t * @returns The combined path string.\n\t */\n\tjoin(parentPath: string, childPath: string): string;\n}\n\n/**\n * The combined compatibility status for both backwards and forwards compatibility checks.\n */\nexport interface CombinedSchemaCompatibilityStatus {\n\t/**\n\t * How a {@link TreeView} using the current schema would report its compatibility with the historical snapshot.\n\t */\n\treadonly currentViewOfSnapshotDocument: Omit<SchemaCompatibilityStatus, \"canInitialize\">;\n\t/**\n\t * How a {@link TreeView} using the snapshotted schema would report its compatibility with a document created with the current schema.\n\t */\n\treadonly snapshotViewOfCurrentDocument: Omit<SchemaCompatibilityStatus, \"canInitialize\">;\n\n\t/**\n\t * True if and only if the schema have identical compatibility.\n\t * @remarks\n\t * This includes producing the equivalent stored schema (which currentViewOfSnapshotDocument and snapshotViewOfCurrentDocument also measure)\n\t * as well as equivalent compatibility with potential future schema changes beyond just those in these two schema.\n\t *\n\t * This includes compatibility with all potential future schema changes.\n\t * For example two schema different only in compatibility with future optional fields via allow unknown optional fields or staged schema\n\t * would be considered non-equivalent, even though they are forwards and backwards compatible with each other, and both status above report them as equivalent\n\t * since they would produce the same stored schema upon schema upgrade.\n\t */\n\treadonly identicalCompatibility: boolean;\n}\n\n/**\n * The options for {@link snapshotSchemaCompatibility}.\n * @input\n * @beta\n */\nexport interface SnapshotSchemaCompatibilityOptions {\n\t/**\n\t * Directory where historical schema snapshots are stored.\n\t * @remarks\n\t * As the contents of this directory (specifically historical snapshots) cannot be regenerated,\n\t * a directory appropriate for test data should be used.\n\t * Generally this means that this directory should be versioned like code,\n\t * and not erased when regenerating snapshots.\n\t *\n\t * This directory will be created if it does not already exist.\n\t * All \".json\" files in this directory will be treated as schema snapshots.\n\t * It is recommended to use a dedicated directory for each {@link snapshotSchemaCompatibility} powered test.\n\t *\n\t * This can use any path syntax supported by the provided {@link SnapshotSchemaCompatibilityOptions.fileSystem}.\n\t */\n\treadonly snapshotDirectory: string;\n\n\t/**\n\t * How the `snapshotDirectory` is accessed.\n\t */\n\treadonly fileSystem: SnapshotFileSystem;\n\n\t/**\n\t * The current view schema.\n\t */\n\treadonly schema: TreeViewConfiguration;\n\n\t/**\n\t * The version which will be associated with this version of the schema.\n\t * @remarks\n\t * Often the easiest way to ensure this is to simply use the next version which will be released for the package or application itself, and set the `minVersionForCollaboration` based on telemetry about which versions are still in use.\n\t * To do this, it is recommended that this version be programmatically derived from the application version rather than hard coded inline.\n\t * For example, reading it from the `package.json` or some other source of truth can be done to ensure it is kept up to date, and thus snapshots always have the correct version.\n\t * The version used should typically be the _next_ production version (whose formats must be supported long term) that will be released (but is not yet released).\n\t * This usually means that the correct version to use is the same version that would be used when releasing the application or library, but with any prerelease version tags removed.\n\t * If an automated way to keep this version up to date is not used, be very careful when reviewing changes to snapshot files to ensure the version is correct.\n\t * If incorrectly versioned snapshots were committed accidentally, rename the snapshot files to have the correct version, and restore the old files from, version control.\n\t *\n\t * It is possible to use a different versioning scheme, for example one specific to the schema in question.\n\t * This can be done robustly as long as care is taken to ensure the version increases such that every released version has a unique `version` (and therefore unique snapshot),\n\t * and `minVersionForCollaboration` is set appropriately using the same versioning scheme.\n\t * {@link SnapshotSchemaCompatibilityOptions.rejectVersionsWithNoSchemaChange} and\n\t * {@link SnapshotSchemaCompatibilityOptions.rejectSchemaChangesWithNoVersionChange}\n\t * can be used to help enforce the expected relationship between version changes and schema changes in such cases.\n\t *\n\t * Can use any format supported by {@link SnapshotSchemaCompatibilityOptions.versionComparer}.\n\t * Only compared against the version from previous snapshots (taken from this version when they were created by setting `mode` to \"update\") and the `minVersionForCollaboration`.\n\t *\n\t * Typically `minVersionForCollaboration` should be set to the oldest version currently in use, so it's helpful to use a version which can be easily measured to tell if clients are still using it.\n\t */\n\treadonly version: string;\n\n\t/**\n\t * The minimum version that the current version is expected to be able to collaborate with.\n\t * @remarks\n\t * Can use any format supported by {@link SnapshotSchemaCompatibilityOptions.versionComparer}.\n\t *\n\t * This defines a range of versions whose schema must be forwards compatible with trees using the current schema:\n\t * Any schema from snapshots with a version greater than or equal to this must be able to view documents created with the current schema.\n\t * This means that if the current `schema` is used to create a {@link TreeView}, then {@link TreeView.upgradeSchema} is used, the older clients,\n\t * all the way back to this `minVersionForCollaboration` will be able to view and edit the tree using their schema and thus collaborate.\n\t *\n\t * Typically applications will attempt to manage their deployment/update schedule such that all versions concurrently deployed can\n\t * collaborate to avoid users losing access to documents when other users upgrade the schema.\n\t * Such applications can set this to the oldest version currently deployed,\n\t * then rely on {@link snapshotSchemaCompatibility} to verify that no schema changes are made which would break collaboration with that (or newer) versions.\n\t *\n\t * This is the same approach used by {@link @fluidframework/runtime-definitions#MinimumVersionForCollab}\n\t * except that type is specifically for use with the version of the Fluid Framework client packages,\n\t * and this corresponds to whatever versioning scheme is used with {@link SnapshotSchemaCompatibilityOptions.version}.\n\t */\n\treadonly minVersionForCollaboration: string;\n\n\t/**\n\t * A comparison function for version strings.\n\t * @remarks\n\t * A comparison function like that provided to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#comparefn | Array.sort}.\n\t * This is used to partition snapshots into those less than `minVersionForCollaboration` and those greater than or equal to it, as well as to sanity check `version` against the versions of the snapshots.\n\t * If not provided, the ordering is defined by {@link https://semver.org/#spec-item-11|semver}.\n\t * @returns A negative number if `a` is less than `b`, zero if they are equal, or a positive number if `a` is greater than `b`.\n\t */\n\treadonly versionComparer?: (a: string, b: string) => number;\n\n\t/**\n\t * When true, every version must be snapshotted, and an increased version number will require a new snapshot.\n\t * @remarks\n\t * If this is true, it is assumed there is a snapshot for every release, and thus it is required that the `minVersionForCollaboration` refer to a version which has a snapshot.\n\t * When this is not true, versions without snapshots are assumed to have the same schema as the latest previous version which has a snapshot, and thus `minVersionForCollaboration`\n\t * can refer to versions between snapshots and will get its schema from the preceding version.\n\t */\n\treadonly snapshotUnchangedVersions?: true;\n\n\t/**\n\t * When true, it is an error if a new a snapshot for a new version would be created, but the schema compatibility is identical to the previous snapshot.\n\t * @remarks\n\t * This prevents creating a snapshot with the same schema compatibility results as the previous one.\n\t *\n\t * Applications and libraries which do not have versioned releases can make up a version specific to the compatibility of the schema, and use this option to help ensure they manage that version correctly.\n\t * Such cases can also opt into {@link SnapshotSchemaCompatibilityOptions.rejectSchemaChangesWithNoVersionChange} if they want additional strictness.\n\t */\n\treadonly rejectVersionsWithNoSchemaChange?: true;\n\n\t/**\n\t * When true, it is an error if a schema change occurs without a corresponding version change.\n\t * @remarks\n\t * This disables overwriting existing snapshots.\n\t * This option is recommended if the {@link SnapshotSchemaCompatibilityOptions.version} is not automatically updated ahead of releasing a version which must be supported.\n\t * If updating the snapshot is still desired, the preceding one which needs to be overwritten can be manually deleted before running the update.\n\t *\n\t * This option does not impact the behavior of assert mode (other than impacting what error is given).\n\t * This option simply makes update mode more strict, converting cases that would overwrite a snapshot in place into errors.\n\t */\n\treadonly rejectSchemaChangesWithNoVersionChange?: true;\n\n\t/**\n\t * The mode of operation, either \"assert\" or \"update\".\n\t * @remarks\n\t * Both modes will throw errors if any compatibility issues are detected (but after updating snapshots in \"update\" mode so the diff can be used to help debug).\n\t *\n\t * In \"assert\" mode, an error is additionally thrown if the latest snapshot is not up to date (meaning \"update\" mode would make a change).\n\t *\n\t * In \"update\" mode, a new snapshot is created if the current schema differs from the latest existing snapshot.\n\t * If {@link SnapshotSchemaCompatibilityOptions.rejectVersionsWithNoSchemaChange} or\n\t * {@link SnapshotSchemaCompatibilityOptions.rejectSchemaChangesWithNoVersionChange} disallows the update, an error is thrown instead.\n\t *\n\t * It is recommended that \"assert\" mode be used in automated tests to verify schema compatibility,\n\t * and \"update\" mode only be used manually to update snapshots when making schema or version changes.\n\t *\n\t * @privateRemarks\n\t * Modes we might want to add in the future:\n\t * - normalize: update the latest snapshot (or maybe all of them) to the latest encoded format.\n\t * - some mode like assert but returns information instead of throwing.\n\t */\n\treadonly mode: \"assert\" | \"update\";\n}\n\n/**\n * Check `currentViewSchema` for compatibility with a collection of historical schema snapshots stored in `snapshotDirectory`.\n *\n * @throws Throws errors if the input version strings (including those in snapshot file names) are not valid semver versions when using default semver version comparison.\n * @throws Throws errors if the input version strings (including those in snapshot file names) are not ordered as expected (current being the highest, and `minVersionForCollaboration` corresponding to the current version or a lower snapshotted version).\n * @throws In `test` mode, throws an error if there is not an up to date snapshot for the current version.\n * @throws Throws an error if any snapshotted schema cannot be upgraded to the current schema.\n * @throws Throws an error if any snapshotted schema with a version greater than or equal to `minVersionForCollaboration` cannot view documents created with the current schema.\n * @remarks\n * This is intended for use in snapshot-based schema compatibility tests.\n * Every SharedTree-based component or application with a schema is recommended to use this to verify schema compatibility across versions.\n *\n * Schema snapshots should be added to `snapshotDirectory` using this function in \"update\" mode whenever the schema changes in a compatibility impacting way\n * (or when `snapshotUnchangedVersions` is true and a new version about to be released is getting prepared for release (and thus `version` changed)).\n *\n * This will throw an exception if any snapshotted schema would result in documents that cannot be viewed (after using {@link TreeView.upgradeSchema}), or if any schema with a version greater than or equal to `minVersionForCollaboration` cannot view documents created with the `currentViewSchema`.\n * See {@link TreeView.compatibility} for more information.\n *\n * Proper use of this utility should do a good job at detecting schema compatibility issues,\n * however it currently does not do a good job of explaining exactly what change to the schema is causing the compatibility issues.\n * This is a known limitation that will be improved in future releases.\n * These improvements, as well as other changes, may change the exact messages produced by this function in the error cases: no stability of these messages should be assumed.\n *\n * Unlike some other snapshot based testing tools, this stores more than just the current snapshot: historical snapshots are retained as well.\n * Retention of these additional historical snapshots, whose content can't be regenerated from the current schema, is necessary to properly test compatibility across versions.\n * Since there is content in the snapshots which cannot be regenerated, tools which assume all snapshotted content can be regenerated cannot be used here.\n * This means that tools like Jest's built in snapshot testing are not suitable for this purpose.\n * These snapshots behave partly like test data, and partly like snapshots.\n * Typically the easiest way to manage this is to place {@link SnapshotSchemaCompatibilityOptions.snapshotDirectory} inside a directory appropriate for test data,\n * and use node to provide the filesystem access via {@link SnapshotSchemaCompatibilityOptions.fileSystem}.\n *\n * For now, locating what change broke compatibility is likely best discovered by making small schema changes one at a time and updating the snapshot and reviewing the diffs.\n * Details for what kinds of changes are breaking and in which ways can be found in the documentation for {@link TreeView.compatibility} and\n * {@link https://fluidframework.com/docs/data-structures/tree/schema-evolution/ | schema-evolution}.\n *\n * This utility does not enforce anything with respect to API compatibility, or special semantics for major, minor, or patch versions.\n * Libraries which export schema for use by others will need to take special care to ensure the stability contract they offer their users aligns which what is validated by this utility.\n *\n * This utility only tests compatibility of the historical snapshots against the current schema; it does not test them against each-other.\n * Generally any historical schema should have been tested against the ones before them at the time they were current.\n * If for some reason a version of a schema made it into production that was not compatible with a previous version,\n * that can still be represented here (but may require manually generating a snapshot for that version)\n * and this will still allow testing that all historical version can be upgraded to the current one.\n * If a sufficiently incompatible historical schema were used in production, it may be impossible to make a single schema which can accommodate all of them:\n * this utility can be used to confirm that is the case, as well as to avoid the problem in the first place by testing schema before each one is deployed.\n *\n * @example Mocha test which validates the current `config` can collaborate with all historical version back to 2.0.0, and load and update any versions older than that.\n * ```typescript\n * it(\"schema compatibility\", () => {\n * \tsnapshotSchemaCompatibility({\n * \t\tversion: pkgVersion,\n * \t\tschema: config,\n * \t\tfileSystem: { ...fs, ...path },\n * \t\tminVersionForCollaboration: \"2.0.0\",\n * \t\tmode: process.argv.includes(\"--snapshot\") ? \"update\" : \"test\",\n * \t\tsnapshotDirectory,\n * \t});\n * });\n * ```\n * @example Complete Mocha test file\n * ```typescript\n * import fs from \"node:fs\";\n * import path from \"node:path\";\n *\n * import { snapshotSchemaCompatibility } from \"@fluidframework/tree/beta\";\n *\n * // The TreeViewConfiguration the application uses, which contains the application's schema.\n * import { treeViewConfiguration } from \"./schema.js\";\n * // The next version of the application which will be released.\n * import { packageVersion } from \"./version.js\";\n *\n * // Provide some way to run the check in \"update\" mode when updating snapshots is intended.\n * const regenerateSnapshots = process.argv.includes(\"--snapshot\");\n *\n * // Setup the actual test. In this case using Mocha syntax.\n * describe(\"schema\", () => {\n * \tit(\"schema compatibility\", () => {\n * \t\t// Select a path to save the snapshots in.\n * \t\t// This will depend on how your application organizes its test data.\n * \t\tconst snapshotDirectory = path.join(\n * \t\t\timport.meta.dirname,\n * \t\t\t\"../../../src/test/schema-snapshots\",\n * \t\t);\n * \t\tsnapshotSchemaCompatibility({\n * \t\t\tschema: config,\n * \t\t\tfileSystem: { ...fs, ...path },\n * \t\t\tversion: pkgVersion,\n * \t\t\tminVersionForCollaboration: \"2.0.0\",\n * \t\t\tmode: process.argv.includes(\"--snapshot\") ? \"update\" : \"assert\",\n * \t\t\tsnapshotDirectory,\n * \t\t});\n * \t});\n * });\n * ```\n * @privateRemarks\n * Use of this function within this package (for schema libraries released as part of this package) should use {@link testSchemaCompatibilitySnapshots} instead.\n *\n * This uses the format defined in simpleSchemaCodec.ts.\n * This does include versioning information in the snapshot format,\n * but it would be nice to better unify how we do that versioning and format validation with our codecs.\n *\n * See snapshotCompatibilityChecker.example.mts for the large example included above.\n * @beta\n */\nexport function snapshotSchemaCompatibility(\n\toptions: SnapshotSchemaCompatibilityOptions,\n): void {\n\tconst checker = new SnapshotCompatibilityChecker(\n\t\toptions.snapshotDirectory,\n\t\toptions.fileSystem,\n\t);\n\tconst {\n\t\tversion: currentVersion,\n\t\tschema: currentViewSchema,\n\t\tmode,\n\t\tminVersionForCollaboration,\n\t\tsnapshotUnchangedVersions,\n\t\trejectVersionsWithNoSchemaChange,\n\t\trejectSchemaChangesWithNoVersionChange,\n\t} = options;\n\n\tconst validateVersion =\n\t\toptions.versionComparer === undefined ? semver.valid : (v: string) => v;\n\tconst versionComparer = options.versionComparer ?? semver.compare;\n\n\tif (validateVersion(currentVersion) === null) {\n\t\tthrow new UsageError(\n\t\t\t`Invalid version: ${JSON.stringify(currentVersion)}. Must be a valid semver version.`,\n\t\t);\n\t}\n\tif (validateVersion(minVersionForCollaboration) === null) {\n\t\tthrow new UsageError(\n\t\t\t`Invalid minVersionForCollaboration: ${JSON.stringify(minVersionForCollaboration)}. Must be a valid semver version.`,\n\t\t);\n\t}\n\n\tif (versionComparer(minVersionForCollaboration, currentVersion) > 0) {\n\t\tthrow new UsageError(\n\t\t\t`Invalid minVersionForCollaboration: ${JSON.stringify(minVersionForCollaboration)}. Must be less than or equal to current version ${JSON.stringify(currentVersion)}.`,\n\t\t);\n\t}\n\n\tif (mode !== \"assert\" && mode !== \"update\") {\n\t\tthrow new UsageError(\n\t\t\t`Invalid mode: ${JSON.stringify(mode)}. Must be either \"assert\" or \"update\".`,\n\t\t);\n\t}\n\n\tconst currentEncodedForSnapshotting = exportCompatibilitySchemaSnapshot(currentViewSchema);\n\tconst snapshots = checker.readAllSchemaSnapshots(versionComparer);\n\n\tconst compatibilityErrors: string[] = [];\n\n\tconst contextNotes: string[] = [];\n\n\tfunction errorWithContext(message: string): Error {\n\t\treturn new Error(\n\t\t\t[\n\t\t\t\t\"Schema compatibility check failed:\",\n\t\t\t\tmessage,\n\t\t\t\t`Snapshots in: ${JSON.stringify(options.snapshotDirectory)}`,\n\t\t\t\t`Snapshots exist for versions: ${JSON.stringify([...snapshots.keys()], undefined, \"\\t\")}.`,\n\t\t\t\t...contextNotes,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t}\n\n\tconst compatibilityMap = transformMapValues(snapshots, (snapshot) =>\n\t\tgetCompatibility(currentViewSchema, snapshot),\n\t);\n\n\t// Either:\n\t// - false: no update needed\n\t// - the updateError message (update in update mode, error otherwise)\n\t// - an error if the update is disallowed by the flags\n\tlet wouldUpdate: false | string | Error;\n\n\t// Set wouldUpdate\n\t{\n\t\tconst latestSnapshot = [...snapshots][snapshots.size - 1];\n\t\tif (latestSnapshot === undefined) {\n\t\t\twouldUpdate = `No snapshots found.`;\n\t\t} else {\n\t\t\tconst latestCompatibility =\n\t\t\t\tcompatibilityMap.get(latestSnapshot[0]) ??\n\t\t\t\tfail(0xcd1 /* missing compatibilityMap entry */);\n\n\t\t\tconst schemaChange = !latestCompatibility.identicalCompatibility;\n\t\t\tconst versionChange = versionComparer(latestSnapshot[0], currentVersion) !== 0;\n\n\t\t\tif (rejectVersionsWithNoSchemaChange === true && versionChange && !schemaChange) {\n\t\t\t\twouldUpdate = errorWithContext(\n\t\t\t\t\t`Rejecting version change (${JSON.stringify(latestSnapshot[0])} to ${JSON.stringify(currentVersion)}) due to rejectVersionsWithNoSchemaChange being set.`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\trejectSchemaChangesWithNoVersionChange === true &&\n\t\t\t\tschemaChange &&\n\t\t\t\t!versionChange\n\t\t\t) {\n\t\t\t\twouldUpdate = errorWithContext(\n\t\t\t\t\t`Rejecting schema change without version change due to existing non-equivalent snapshot for version (${JSON.stringify(latestSnapshot[0])} due to rejectSchemaChangesWithNoVersionChange being set.`,\n\t\t\t\t);\n\t\t\t} else if (snapshotUnchangedVersions === true) {\n\t\t\t\tconst currentRead = snapshots.get(currentVersion);\n\t\t\t\tif (currentRead === undefined) {\n\t\t\t\t\twouldUpdate = `No snapshot found for version ${JSON.stringify(currentVersion)}: snapshotUnchangedVersions is true, so every version must be snapshotted.`;\n\t\t\t\t} else if (\n\t\t\t\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(currentRead)) ===\n\t\t\t\t\tJSON.stringify(currentEncodedForSnapshotting)\n\t\t\t\t) {\n\t\t\t\t\twouldUpdate = false;\n\t\t\t\t} else {\n\t\t\t\t\twouldUpdate = `Snapshot for current version ${JSON.stringify(currentVersion)} is out of date.`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (versionComparer(latestSnapshot[0], currentVersion) <= 0) {\n\t\t\t\t\twouldUpdate = schemaChange\n\t\t\t\t\t\t? `Snapshot for current version ${JSON.stringify(currentVersion)} is out of date: schema has changed since latest existing snapshot version ${JSON.stringify(latestSnapshot[0])}.`\n\t\t\t\t\t\t: false;\n\t\t\t\t} else {\n\t\t\t\t\twouldUpdate = errorWithContext(\n\t\t\t\t\t\t`Current version ${JSON.stringify(currentVersion)} is less than latest existing snapshot version ${JSON.stringify(latestSnapshot[0])}: version is expected to increase monotonically.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!schemaChange && (snapshotUnchangedVersions !== true || !versionChange)) {\n\t\t\t\t// eslint-disable-next-line unicorn/no-lonely-if\n\t\t\t\tif (\n\t\t\t\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(latestSnapshot[1])) !==\n\t\t\t\t\tJSON.stringify(currentEncodedForSnapshotting)\n\t\t\t\t) {\n\t\t\t\t\t// Schema are compatibility wise equivalent, but differ in some way (excluding json formatting).\n\t\t\t\t\t// TODO: add a \"normalize\" mode, which do an update only in this case (or maybe even normalize json formatting as well and just always rewrite when !schemaChange)\n\t\t\t\t\t// This would be useful to minimize diffs from future schema changes.\n\t\t\t\t\t// This would be particularly useful if adding a second version of the format used in the snapshots.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (wouldUpdate !== false) {\n\t\tif (wouldUpdate instanceof Error) {\n\t\t\tthrow wouldUpdate;\n\t\t}\n\t\tif (mode === \"update\") {\n\t\t\tchecker.writeSchemaSnapshot(currentVersion, currentEncodedForSnapshotting);\n\t\t\t// Update so errors below will reflect the new snapshot.\n\t\t\tcompatibilityMap.set(\n\t\t\t\tcurrentVersion,\n\t\t\t\tgetCompatibility(currentViewSchema, currentViewSchema),\n\t\t\t);\n\t\t} else {\n\t\t\tcompatibilityErrors.push(\n\t\t\t\t`${wouldUpdate} If this is expected, snapshotSchemaCompatibility can be rerun in \"update\" mode to update or create the snapshot.`,\n\t\t\t);\n\n\t\t\t// This case could update compatibilityMap as well, but it would hide some information about how the existing snapshot might be incompatible with the proposed new one.\n\t\t\t// This lost information could be annoying if the user's intention was not to edit the schema (which is what we assume in assert mode),\n\t\t\t// especially once we produce more detailed error messages that can help users understand what changed in the schema.\n\t\t}\n\t}\n\n\t// Add compatibilityErrors and contextNotes as needed regarding minVersionForCollaboration.\n\t// This is only done when minVersionForCollaboration is not the current version to avoid extra noise in \"assert\" mode\n\t// (which is the only case that could error when minVersionForCollaboration === currentVersion).\n\tif (minVersionForCollaboration !== currentVersion) {\n\t\tif (snapshotUnchangedVersions === true) {\n\t\t\tconst minSnapshot = compatibilityMap.get(minVersionForCollaboration);\n\t\t\tif (minSnapshot === undefined) {\n\t\t\t\tcompatibilityErrors.push(\n\t\t\t\t\t`Using snapshotUnchangedVersions: a snapshot of the exact minVersionForCollaboration ${JSON.stringify(minVersionForCollaboration)} is required. No snapshot found.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst selectedMinVersionForCollaborationSnapshot = selectVersionRoundedDown(\n\t\t\t\tminVersionForCollaboration,\n\t\t\t\tcompatibilityMap,\n\t\t\t\tversionComparer,\n\t\t\t);\n\t\t\tif (selectedMinVersionForCollaborationSnapshot === undefined) {\n\t\t\t\tcompatibilityErrors.push(\n\t\t\t\t\t`No snapshot found with version less than or equal to minVersionForCollaboration ${JSON.stringify(minVersionForCollaboration)}.`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\tselectedMinVersionForCollaborationSnapshot[0] !== minVersionForCollaboration\n\t\t\t) {\n\t\t\t\t// Add an entry to ensure that the version which spans from before until after the cutoff for collaboration is included in the compatibility checks.\n\t\t\t\tcompatibilityMap.set(\n\t\t\t\t\tminVersionForCollaboration,\n\t\t\t\t\tselectedMinVersionForCollaborationSnapshot[1],\n\t\t\t\t);\n\t\t\t\tcontextNotes.push(\n\t\t\t\t\t`Due to snapshotUnchangedVersions being false and minVersionForCollaboration (${JSON.stringify(minVersionForCollaboration)}) not having an exact snapshot, the last snapshot before that version (which is ${JSON.stringify(\n\t\t\t\t\t\tselectedMinVersionForCollaborationSnapshot[0],\n\t\t\t\t\t)}) is being also being checked as if it is version ${JSON.stringify(minVersionForCollaboration)}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Compare all snapshots against the current schema, using the compatibilityMap.\n\tfor (const [snapshotVersion, compatibility] of compatibilityMap) {\n\t\t// Current should be able to view all versions.\n\t\tif (!compatibility.currentViewOfSnapshotDocument.canUpgrade) {\n\t\t\tcompatibilityErrors.push(\n\t\t\t\t`Current version ${JSON.stringify(currentVersion)} cannot upgrade documents from ${JSON.stringify(snapshotVersion)}.`,\n\t\t\t);\n\t\t}\n\n\t\tconst versionComparisonToCurrent = versionComparer(snapshotVersion, currentVersion);\n\t\tif (versionComparisonToCurrent === 0) {\n\t\t\tif (currentVersion !== snapshotVersion) {\n\t\t\t\tthrow errorWithContext(\n\t\t\t\t\t`Snapshot version ${JSON.stringify(snapshotVersion)} is semantically equal but not string equal to current version ${JSON.stringify(currentVersion)}: this is not supported.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (compatibility.identicalCompatibility === false) {\n\t\t\t\tassert(\n\t\t\t\t\twouldUpdate !== false,\n\t\t\t\t\t0xcd2 /* there should have been an error for the snapshot being out of date */,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (versionComparisonToCurrent < 0) {\n\t\t\t// Collaboration with this version is expected to work.\n\t\t\tif (versionComparer(snapshotVersion, minVersionForCollaboration) >= 0) {\n\t\t\t\t// Check that the historical version can view documents from the current version, since collaboration with this one is expected to work.\n\t\t\t\tif (!compatibility.snapshotViewOfCurrentDocument.canView) {\n\t\t\t\t\tcompatibilityErrors.push(\n\t\t\t\t\t\t`Historical version ${JSON.stringify(snapshotVersion)} cannot view documents from ${JSON.stringify(currentVersion)}: these versions are expected to be able to collaborate due to the selected minVersionForCollaboration ${JSON.stringify(minVersionForCollaboration)}.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This is the case where the historical version is less than the minimum version for collaboration.\n\t\t\t\t// No additional validation is needed here currently, since forwards document compat from these versions is already tested above (since it applies to all snapshots).\n\t\t\t}\n\t\t} else {\n\t\t\tcompatibilityErrors.push(\n\t\t\t\t`Snapshot exists for version ${JSON.stringify(snapshotVersion)} which is greater than the current version ${JSON.stringify(currentVersion)}. This is not supported.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (compatibilityErrors.length > 0) {\n\t\tthrow errorWithContext(compatibilityErrors.map((e) => ` - ${e}`).join(\"\\n\"));\n\t}\n}\n\n/**\n * The high-level API for checking snapshot compatibility and generating new snapshots.\n */\nexport class SnapshotCompatibilityChecker {\n\tpublic constructor(\n\t\t/**\n\t\t * Directory where historical schema snapshots are stored.\n\t\t */\n\t\tprivate readonly snapshotDirectory: string,\n\t\t/**\n\t\t * How the `snapshotDirectory` is accessed.\n\t\t */\n\t\tprivate readonly fileSystemMethods: SnapshotFileSystem,\n\t) {}\n\n\tpublic writeSchemaSnapshot(snapshotName: string, snapshot: JsonCompatibleReadOnly): void {\n\t\tconst fullPath = this.fileSystemMethods.join(\n\t\t\tthis.snapshotDirectory,\n\t\t\t`${snapshotName}.json`,\n\t\t);\n\t\tthis.ensureSnapshotDirectoryExists();\n\t\tthis.fileSystemMethods.writeFileSync(fullPath, JSON.stringify(snapshot, undefined, \"\\t\"), {\n\t\t\tencoding: \"utf8\",\n\t\t});\n\t}\n\n\tpublic readSchemaSnapshot(snapshotName: string): TreeViewConfiguration {\n\t\tconst snapshot = this.readSchemaSnapshotRaw(snapshotName);\n\t\treturn importCompatibilitySchemaSnapshot(snapshot);\n\t}\n\n\tpublic readSchemaSnapshotRaw(snapshotName: string): JsonCompatibleReadOnly {\n\t\tconst fullPath = this.fileSystemMethods.join(\n\t\t\tthis.snapshotDirectory,\n\t\t\t`${snapshotName}.json`,\n\t\t);\n\t\tconst snapshot = JSON.parse(\n\t\t\tthis.fileSystemMethods.readFileSync(fullPath, \"utf8\"),\n\t\t) as JsonCompatibleReadOnly;\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Returns all schema snapshots stored in the snapshot directory, sorted in order of increasing version.\n\t */\n\tpublic readAllSchemaSnapshots(\n\t\tcompare: (a: string, b: string) => number,\n\t): Map<string, TreeViewConfiguration> {\n\t\tthis.ensureSnapshotDirectoryExists();\n\t\tconst files = this.fileSystemMethods.readdirSync(this.snapshotDirectory);\n\t\tconst versions: string[] = [];\n\t\tfor (const file of files) {\n\t\t\tif (file.endsWith(\".json\")) {\n\t\t\t\tconst snapshotName = file.slice(0, \".json\".length * -1);\n\t\t\t\tversions.push(snapshotName);\n\t\t\t}\n\t\t}\n\t\t// Ensures that errors are in a consistent and friendly order, independent of file system order.\n\t\tversions.sort(compare);\n\n\t\tconst snapshots: Map<string, TreeViewConfiguration> = new Map();\n\t\tfor (const version of versions) {\n\t\t\tsnapshots.set(version, this.readSchemaSnapshot(version));\n\t\t}\n\t\treturn snapshots;\n\t}\n\n\tpublic ensureSnapshotDirectoryExists(): void {\n\t\tthis.fileSystemMethods.mkdirSync(this.snapshotDirectory, { recursive: true });\n\t}\n}\n\n/**\n * Gets the compatibility of the current view schema against a historical snapshot.\n * @param currentViewSchema - The current view schema.\n * @param previousViewSchema - The historical view schema.\n * @returns The combined compatibility status.\n */\nexport function getCompatibility(\n\tcurrentViewSchema: TreeViewConfiguration,\n\tpreviousViewSchema: TreeViewConfiguration,\n): CombinedSchemaCompatibilityStatus {\n\tconst backwardsCompatibilityStatus = checkCompatibility(\n\t\tpreviousViewSchema,\n\t\tcurrentViewSchema,\n\t);\n\n\tconst forwardsCompatibilityStatus = checkCompatibility(\n\t\tcurrentViewSchema,\n\t\tpreviousViewSchema,\n\t);\n\n\tassert(\n\t\tbackwardsCompatibilityStatus.isEquivalent === forwardsCompatibilityStatus.isEquivalent,\n\t\t0xcd3 /* equality should be symmetric */,\n\t);\n\n\t// This relies on exportCompatibilitySchemaSnapshot being well normalized, and not differing for non-significant changes.\n\tconst identicalCompatibility =\n\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(currentViewSchema)) ===\n\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(previousViewSchema));\n\n\tif (identicalCompatibility) {\n\t\tassert(\n\t\t\tbackwardsCompatibilityStatus.isEquivalent,\n\t\t\t0xcd4 /* identicalCompatibility should have equivalent stored schema */,\n\t\t);\n\t}\n\n\treturn {\n\t\tcurrentViewOfSnapshotDocument: backwardsCompatibilityStatus,\n\t\tsnapshotViewOfCurrentDocument: forwardsCompatibilityStatus,\n\t\tidenticalCompatibility,\n\t};\n}\n"]}
1
+ {"version":3,"file":"snapshotCompatibilityChecker.js","sourceRoot":"","sources":["../../../src/simple-tree/api/snapshotCompatibilityChecker.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;AAEH,kEAAuF;AACvF,qEAAkF;AAClF,uEAAsE;AACtE,0DAAoC;AAGpC,4DAAuD;AACvD,oDAAoD;AAEpD,yDAAuF;AACvF,iFAA2E;AAC3E,+DAAuE;AACvE,iEAGgC;AAGhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkDG;AACH,SAAgB,kBAAkB,CACjC,4BAAmD,EACnD,IAA2B;IAE3B,MAAM,WAAW,GAAG,IAAI,6CAA0B,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5E,MAAM,MAAM,GAAG,IAAA,mCAAe,EAAC,4BAA4B,CAAC,MAAM,CAAC,CAAC;IACpE,MAAM,MAAM,GAAG,IAAI,wDAAyB,CAAC,WAAW,CAAC,CAAC;IAC1D,OAAO,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;AAC1C,CAAC;AARD,gDAQC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,iCAAiC,CAChD,MAA6C;IAE7C,MAAM,UAAU,GAAG,IAAA,gCAAgB,EAAC,MAAM,CAAC,MAAM,CAAC,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KAAK,MAAM,OAAO,IAAI,QAAQ,EAAE,CAAC;YAChC,SAAS,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;QAC1D,CAAC;QACD,OAAO,SAAS,CAAC;IAClB,CAAC;IAEM,6BAA6B;QACnC,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,CAAC,iBAAiB,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;IAC/E,CAAC;CACD;AAnED,oEAmEC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAC/B,iBAAwC,EACxC,kBAAyC;IAEzC,MAAM,4BAA4B,GAAG,kBAAkB,CACtD,kBAAkB,EAClB,iBAAiB,CACjB,CAAC;IAEF,MAAM,2BAA2B,GAAG,kBAAkB,CACrD,iBAAiB,EACjB,kBAAkB,CAClB,CAAC;IAEF,IAAA,iBAAM,EACL,4BAA4B,CAAC,YAAY,KAAK,2BAA2B,CAAC,YAAY,EACtF,KAAK,CAAC,kCAAkC,CACxC,CAAC;IAEF,yHAAyH;IACzH,MAAM,sBAAsB,GAC3B,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC,iBAAiB,CAAC,CAAC;QACpE,IAAI,CAAC,SAAS,CAAC,iCAAiC,CAAC,kBAAkB,CAAC,CAAC,CAAC;IAEvE,IAAI,sBAAsB,EAAE,CAAC;QAC5B,IAAA,iBAAM,EACL,4BAA4B,CAAC,YAAY,EACzC,KAAK,CAAC,iEAAiE,CACvE,CAAC;IACH,CAAC;IAED,OAAO;QACN,6BAA6B,EAAE,4BAA4B;QAC3D,6BAA6B,EAAE,2BAA2B;QAC1D,sBAAsB;KACtB,CAAC;AACH,CAAC;AApCD,4CAoCC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { assert, fail, transformMapValues } from \"@fluidframework/core-utils/internal\";\nimport { selectVersionRoundedDown } from \"@fluidframework/runtime-utils/internal\";\nimport { UsageError } from \"@fluidframework/telemetry-utils/internal\";\nimport * as semver from \"semver-ts\";\n\nimport type { JsonCompatibleReadOnly } from \"../../util/index.js\";\nimport { toInitialSchema } from \"../toStoredSchema.js\";\nimport { createTreeSchema } from \"../treeSchema.js\";\n\nimport { TreeViewConfigurationAlpha, TreeViewConfiguration } from \"./configuration.js\";\nimport { SchemaCompatibilityTester } from \"./schemaCompatibilityTester.js\";\nimport { generateSchemaFromSimpleSchema } from \"./schemaFromSimple.js\";\nimport {\n\tdecodeSchemaCompatibilitySnapshot,\n\tencodeSchemaCompatibilitySnapshot,\n} from \"./simpleSchemaCodec.js\";\nimport type { SchemaCompatibilityStatus } from \"./tree.js\";\n\n/**\n * Compute the compatibility of using `view` to {@link ViewableTree.viewWith | view a tree} who's {@link ITreeAlpha.exportSimpleSchema | stored schema} could be derived from `viewWhichCreatedStoredSchema` via either {@link TreeView.initialize} or {@link TreeView.upgradeSchema}.\n *\n * @remarks See {@link SchemaCompatibilityStatus} for details on the compatibility results.\n *\n * @example This example demonstrates checking the compatibility of a historical schema against a current schema.\n * In this case, the historical schema is a Point2D object with x and y fields, while the current schema is a Point3D object\n * that adds an optional z field.\n *\n * ```ts\n * // This snapshot is assumed to be the same as Point3D, except missing `z`.\n * const encodedSchema = JSON.parse(fs.readFileSync(\"PointSchema.json\", \"utf8\"));\n * const oldViewSchema = importCompatibilitySchemaSnapshot(encodedSchema);\n *\n * // Build the current view schema\n * class Point3D extends factory.object(\"Point\", {\n * \tx: factory.number,\n * \ty: factory.number,\n *\n * \t// The current schema has a new optional field that was not present on Point2D\n * \tz: factory.optional(factory.number),\n * }) {}\n * const currentViewSchema = new TreeViewConfiguration({ schema: Point3D });\n *\n * // Check to see if the document created by the historical view schema can be opened with the current view schema\n * const backwardsCompatibilityStatus = checkCompatibility(oldViewSchema, currentViewSchema);\n *\n * // z is not present in Point2D, so the schema must be upgraded\n * assert.equal(backwardsCompatibilityStatus.canView, false);\n *\n * // The schema can be upgraded to add the new optional field\n * assert.equal(backwardsCompatibilityStatus.canUpgrade, true);\n *\n * // Test what the old version of the application would do with a tree using the new schema:\n * const forwardsCompatibilityStatus = checkCompatibility(currentViewSchema, oldViewSchema);\n *\n * // If the old schema set allowUnknownOptionalFields, this would be true, but since it did not,\n * // this assert will fail, detecting the forwards compatibility break:\n * // this means these two versions of the application cannot collaborate on content using these schema.\n * assert.equal(forwardsCompatibilityStatus.canView, true);\n * ```\n *\n * @param viewWhichCreatedStoredSchema - From which to derive the stored schema, as if it initialized or upgraded a tree via {@link TreeView}.\n * @param view - The view being tested to see if it could view tree created or initialized using `viewWhichCreatedStoredSchema`.\n * @returns The compatibility status.\n *\n * @privateRemarks\n * TODO: a simple high level API for snapshot based schema compatibility checking should replace the need to export this.\n *\n * @alpha\n */\nexport function checkCompatibility(\n\tviewWhichCreatedStoredSchema: TreeViewConfiguration,\n\tview: TreeViewConfiguration,\n): Omit<SchemaCompatibilityStatus, \"canInitialize\"> {\n\tconst viewAsAlpha = new TreeViewConfigurationAlpha({ schema: view.schema });\n\tconst stored = toInitialSchema(viewWhichCreatedStoredSchema.schema);\n\tconst tester = new SchemaCompatibilityTester(viewAsAlpha);\n\treturn tester.checkCompatibility(stored);\n}\n\n/**\n * Returns a JSON compatible representation of the tree schema for snapshot compatibility checking.\n *\n * Snapshots can be loaded by the same or newer package versions, but not necessarily older versions.\n *\n * @see {@link importCompatibilitySchemaSnapshot} which loads these snapshots.\n *\n * @param config - The schema to snapshot. Only the schema field of the `TreeViewConfiguration` is used.\n * @returns The JSON representation of the schema.\n *\n * @example This example creates and persists a snapshot of a Point2D schema.\n *\n * ```ts\n * const schemaFactory = new SchemaFactory(\"test\");\n * class Point2D extends schemaFactory.object(\"Point\", {\n * \tx: factory.number,\n * \ty: factory.number,\n * }) {}\n * const viewSchema = new TreeViewConfiguration({ schema: Point2D });\n * const encodedSchema = JSON.stringify(exportCompatibilitySchemaSnapshot(viewSchema));\n * fs.writeFileSync(\"PointSchema.json\", encodedSchema);\n * ```\n *\n * @privateRemarks\n * TODO: a simple high level API for snapshot based schema compatibility checking should replace the need to export this.\n *\n * @alpha\n */\nexport function exportCompatibilitySchemaSnapshot(\n\tconfig: Pick<TreeViewConfiguration, \"schema\">,\n): JsonCompatibleReadOnly {\n\tconst treeSchema = createTreeSchema(config.schema);\n\treturn encodeSchemaCompatibilitySnapshot(treeSchema);\n}\n\n/**\n * Parse the format exported by {@link exportCompatibilitySchemaSnapshot} into a schema.\n *\n * Can load snapshots created by the same or older package versions, but not necessarily newer versions.\n *\n * @see {@link exportCompatibilitySchemaSnapshot} which creates these snapshots.\n *\n * @param config - The JSON representation of the schema.\n * @returns The schema. Only the schema field of the {@link TreeViewConfiguration} is populated.\n * @throws Will throw a usage error if the encoded schema is not in the expected format.\n *\n * @example This example loads and parses a snapshot of a Point2D schema.\n *\n * ```ts;\n * const oldViewSchema = importCompatibilitySchemaSnapshot(fs.readFileSync(\"PointSchema.json\", \"utf8\"));\n * ```\n * @privateRemarks\n * TODO: a simple high level API for snapshot based schema compatibility checking should replace the need to export this.\n * @alpha\n */\nexport function importCompatibilitySchemaSnapshot(\n\tconfig: JsonCompatibleReadOnly,\n): TreeViewConfiguration {\n\tconst simpleSchema = decodeSchemaCompatibilitySnapshot(config);\n\tconst viewSchema = generateSchemaFromSimpleSchema(simpleSchema);\n\n\t// We construct a TreeViewConfiguration here with the default parameters. The default set of validation parameters are fine for\n\t// a schema produced by `generateSchemaFromSimpleSchema`.\n\treturn new TreeViewConfiguration({ schema: viewSchema.root });\n}\n\n/**\n * The file system methods required by {@link snapshotSchemaCompatibility}.\n * @remarks\n * Implemented by both Node.js `fs` and `path` modules, but other implementations can be provided as needed.\n *\n * @example\n * ```typescript\n * import path from \"node:path\";\n * import fs from \"node:fs\";\n *\n * const nodeFileSystem: SnapshotFileSystem = { ...fs, ...path };\n * ```\n *\n * @privateRemarks\n * This interface is designed to be compatible with Node.js `fs` and `path` modules.\n * It is needed to avoid direct dependencies on Node.js APIs in the core library code,\n * allowing for greater portability and easier testing.\n *\n * @input\n * @beta\n */\nexport interface SnapshotFileSystem {\n\t/**\n\t * Writes a UTF-8 encoded file to disk, replacing the file if it already exists.\n\t *\n\t * @param file - Path to the file to write.\n\t * @param data - String data to be written.\n\t * @param options - Options specifying that the encoding is UTF-8.\n\t */\n\twriteFileSync(file: string, data: string, options: { encoding: \"utf8\" }): void;\n\n\t/**\n\t * Reads a UTF-8 encoded file from disk and returns its contents as a string.\n\t *\n\t * @param file - Path to the file to read.\n\t * @param encoding - The text encoding to use when reading the file. Must be `\"utf8\"`.\n\t * @returns The contents of the file as a string.\n\t */\n\t// We include the encoding here to match the function overload for readFileSync that returns a string.\n\treadFileSync(file: string, encoding: \"utf8\"): string;\n\n\t/**\n\t * How a {@link TreeView} using the snapshotted schema would report its compatibility with a document created with the current schema.\n\t *\n\t * @param dir - Path of the directory to create.\n\t * @param options - Options indicating that creation should be recursive.\n\t */\n\tmkdirSync(dir: string, options: { recursive: true }): void;\n\n\t/**\n\t * Reads the contents of a directory.\n\t *\n\t * @param dir - Path of the directory to read.\n\t * @returns An array of names of the directory entries.\n\t */\n\treaddirSync(dir: string): readonly string[];\n\n\t/**\n\t * Joins two path segments into a single path string.\n\t *\n\t * @param parentPath - The directory path.\n\t * @param childPath - Filename within `parentPath` directory.\n\t * @returns The combined path string.\n\t */\n\tjoin(parentPath: string, childPath: string): string;\n}\n\n/**\n * The combined compatibility status for both backwards and forwards compatibility checks.\n */\nexport interface CombinedSchemaCompatibilityStatus {\n\t/**\n\t * How a {@link TreeView} using the current schema would report its compatibility with the historical snapshot.\n\t */\n\treadonly currentViewOfSnapshotDocument: Omit<SchemaCompatibilityStatus, \"canInitialize\">;\n\t/**\n\t * How a {@link TreeView} using the snapshotted schema would report its compatibility with a document created with the current schema.\n\t */\n\treadonly snapshotViewOfCurrentDocument: Omit<SchemaCompatibilityStatus, \"canInitialize\">;\n\n\t/**\n\t * True if and only if the schema have identical compatibility.\n\t * @remarks\n\t * This includes producing the equivalent stored schema (which currentViewOfSnapshotDocument and snapshotViewOfCurrentDocument also measure)\n\t * as well as equivalent compatibility with potential future schema changes beyond just those in these two schema.\n\t *\n\t * This includes compatibility with all potential future schema changes.\n\t * For example two schema different only in compatibility with future optional fields via allow unknown optional fields or staged schema\n\t * would be considered non-equivalent, even though they are forwards and backwards compatible with each other, and both status above report them as equivalent\n\t * since they would produce the same stored schema upon schema upgrade.\n\t */\n\treadonly identicalCompatibility: boolean;\n}\n\n/**\n * The options for {@link snapshotSchemaCompatibility}.\n * @input\n * @beta\n */\nexport interface SnapshotSchemaCompatibilityOptions {\n\t/**\n\t * Directory where historical schema snapshots are stored.\n\t * @remarks\n\t * As the contents of this directory (specifically historical snapshots) cannot be regenerated,\n\t * a directory appropriate for test data should be used.\n\t * Generally this means that this directory should be versioned like code,\n\t * and not erased when regenerating snapshots.\n\t *\n\t * This directory will be created if it does not already exist.\n\t * All \".json\" files in this directory will be treated as schema snapshots.\n\t * It is recommended to use a dedicated directory for each {@link snapshotSchemaCompatibility} powered test.\n\t *\n\t * This can use any path syntax supported by the provided {@link SnapshotSchemaCompatibilityOptions.fileSystem}.\n\t */\n\treadonly snapshotDirectory: string;\n\n\t/**\n\t * How the `snapshotDirectory` is accessed.\n\t */\n\treadonly fileSystem: SnapshotFileSystem;\n\n\t/**\n\t * The current view schema.\n\t */\n\treadonly schema: TreeViewConfiguration;\n\n\t/**\n\t * The version which will be associated with this version of the schema.\n\t * @remarks\n\t * Often the easiest way to ensure this is to simply use the next version which will be released for the package or application itself, and set the `minVersionForCollaboration` based on telemetry about which versions are still in use.\n\t * To do this, it is recommended that this version be programmatically derived from the application version rather than hard coded inline.\n\t * For example, reading it from the `package.json` or some other source of truth can be done to ensure it is kept up to date, and thus snapshots always have the correct version.\n\t * The version used should typically be the _next_ production version (whose formats must be supported long term) that will be released (but is not yet released).\n\t * This usually means that the correct version to use is the same version that would be used when releasing the application or library, but with any prerelease version tags removed.\n\t * If an automated way to keep this version up to date is not used, be very careful when reviewing changes to snapshot files to ensure the version is correct.\n\t * If incorrectly versioned snapshots were committed accidentally, rename the snapshot files to have the correct version, and restore the old files from, version control.\n\t *\n\t * It is possible to use a different versioning scheme, for example one specific to the schema in question.\n\t * This can be done robustly as long as care is taken to ensure the version increases such that every released version has a unique `version` (and therefore unique snapshot),\n\t * and `minVersionForCollaboration` is set appropriately using the same versioning scheme.\n\t * {@link SnapshotSchemaCompatibilityOptions.rejectVersionsWithNoSchemaChange} and\n\t * {@link SnapshotSchemaCompatibilityOptions.rejectSchemaChangesWithNoVersionChange}\n\t * can be used to help enforce the expected relationship between version changes and schema changes in such cases.\n\t *\n\t * Can use any format supported by {@link SnapshotSchemaCompatibilityOptions.versionComparer}.\n\t * Only compared against the version from previous snapshots (taken from this version when they were created by setting `mode` to \"update\") and the `minVersionForCollaboration`.\n\t *\n\t * Typically `minVersionForCollaboration` should be set to the oldest version currently in use, so it's helpful to use a version which can be easily measured to tell if clients are still using it.\n\t */\n\treadonly version: string;\n\n\t/**\n\t * The minimum version that the current version is expected to be able to collaborate with.\n\t * @remarks\n\t * Can use any format supported by {@link SnapshotSchemaCompatibilityOptions.versionComparer}.\n\t *\n\t * This defines a range of versions whose schema must be forwards compatible with trees using the current schema:\n\t * Any schema from snapshots with a version greater than or equal to this must be able to view documents created with the current schema.\n\t * This means that if the current `schema` is used to create a {@link TreeView}, then {@link TreeView.upgradeSchema} is used, the older clients,\n\t * all the way back to this `minVersionForCollaboration` will be able to view and edit the tree using their schema and thus collaborate.\n\t *\n\t * Typically applications will attempt to manage their deployment/update schedule such that all versions concurrently deployed can\n\t * collaborate to avoid users losing access to documents when other users upgrade the schema.\n\t * Such applications can set this to the oldest version currently deployed,\n\t * then rely on {@link snapshotSchemaCompatibility} to verify that no schema changes are made which would break collaboration with that (or newer) versions.\n\t *\n\t * This is the same approach used by {@link @fluidframework/runtime-definitions#MinimumVersionForCollab}\n\t * except that type is specifically for use with the version of the Fluid Framework client packages,\n\t * and this corresponds to whatever versioning scheme is used with {@link SnapshotSchemaCompatibilityOptions.version}.\n\t */\n\treadonly minVersionForCollaboration: string;\n\n\t/**\n\t * A comparison function for version strings.\n\t * @remarks\n\t * A comparison function like that provided to {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#comparefn | Array.sort}.\n\t * This is used to partition snapshots into those less than `minVersionForCollaboration` and those greater than or equal to it, as well as to sanity check `version` against the versions of the snapshots.\n\t * If not provided, the ordering is defined by {@link https://semver.org/#spec-item-11|semver}.\n\t * @returns A negative number if `a` is less than `b`, zero if they are equal, or a positive number if `a` is greater than `b`.\n\t */\n\treadonly versionComparer?: (a: string, b: string) => number;\n\n\t/**\n\t * When true, every version must be snapshotted, and an increased version number will require a new snapshot.\n\t * @remarks\n\t * If this is true, it is assumed there is a snapshot for every release, and thus it is required that the `minVersionForCollaboration` refer to a version which has a snapshot.\n\t * When this is not true, versions without snapshots are assumed to have the same schema as the latest previous version which has a snapshot, and thus `minVersionForCollaboration`\n\t * can refer to versions between snapshots and will get its schema from the preceding version.\n\t */\n\treadonly snapshotUnchangedVersions?: true;\n\n\t/**\n\t * When true, it is an error if a new a snapshot for a new version would be created, but the schema compatibility is identical to the previous snapshot.\n\t * @remarks\n\t * This prevents creating a snapshot with the same schema compatibility results as the previous one.\n\t *\n\t * Applications and libraries which do not have versioned releases can make up a version specific to the compatibility of the schema, and use this option to help ensure they manage that version correctly.\n\t * Such cases can also opt into {@link SnapshotSchemaCompatibilityOptions.rejectSchemaChangesWithNoVersionChange} if they want additional strictness.\n\t */\n\treadonly rejectVersionsWithNoSchemaChange?: true;\n\n\t/**\n\t * When true, it is an error if a schema change occurs without a corresponding version change.\n\t * @remarks\n\t * This disables overwriting existing snapshots.\n\t * This option is recommended if the {@link SnapshotSchemaCompatibilityOptions.version} is not automatically updated ahead of releasing a version which must be supported.\n\t * If updating the snapshot is still desired, the preceding one which needs to be overwritten can be manually deleted before running the update.\n\t *\n\t * This option does not impact the behavior of assert mode (other than impacting what error is given).\n\t * This option simply makes update mode more strict, converting cases that would overwrite a snapshot in place into errors.\n\t */\n\treadonly rejectSchemaChangesWithNoVersionChange?: true;\n\n\t/**\n\t * The mode of operation, either \"assert\" or \"update\".\n\t * @remarks\n\t * Both modes will throw errors if any compatibility issues are detected (but after updating snapshots in \"update\" mode so the diff can be used to help debug).\n\t *\n\t * In \"assert\" mode, an error is additionally thrown if the latest snapshot is not up to date (meaning \"update\" mode would make a change).\n\t *\n\t * In \"update\" mode, a new snapshot is created if the current schema differs from the latest existing snapshot.\n\t * If {@link SnapshotSchemaCompatibilityOptions.rejectVersionsWithNoSchemaChange} or\n\t * {@link SnapshotSchemaCompatibilityOptions.rejectSchemaChangesWithNoVersionChange} disallows the update, an error is thrown instead.\n\t *\n\t * It is recommended that \"assert\" mode be used in automated tests to verify schema compatibility,\n\t * and \"update\" mode only be used manually to update snapshots when making schema or version changes.\n\t *\n\t * @privateRemarks\n\t * Modes we might want to add in the future:\n\t * - normalize: update the latest snapshot (or maybe all of them) to the latest encoded format.\n\t * - some mode like assert but returns information instead of throwing.\n\t */\n\treadonly mode: \"assert\" | \"update\";\n}\n\n/**\n * Check `currentViewSchema` for compatibility with a collection of historical schema snapshots stored in `snapshotDirectory`.\n *\n * @throws Throws errors if the input version strings (including those in snapshot file names) are not valid semver versions when using default semver version comparison.\n * @throws Throws errors if the input version strings (including those in snapshot file names) are not ordered as expected (current being the highest, and `minVersionForCollaboration` corresponding to the current version or a lower snapshotted version).\n * @throws In `test` mode, throws an error if there is not an up to date snapshot for the current version.\n * @throws Throws an error if any snapshotted schema cannot be upgraded to the current schema.\n * @throws Throws an error if any snapshotted schema with a version greater than or equal to `minVersionForCollaboration` cannot view documents created with the current schema.\n * @remarks\n * This is intended for use in snapshot-based schema compatibility tests.\n * Every SharedTree-based component or application with a schema is recommended to use this to verify schema compatibility across versions.\n *\n * Schema snapshots should be added to `snapshotDirectory` using this function in \"update\" mode whenever the schema changes in a compatibility impacting way\n * (or when `snapshotUnchangedVersions` is true and a new version about to be released is getting prepared for release (and thus `version` changed)).\n *\n * This will throw an exception if any snapshotted schema would result in documents that cannot be viewed (after using {@link TreeView.upgradeSchema}), or if any schema with a version greater than or equal to `minVersionForCollaboration` cannot view documents created with the `currentViewSchema`.\n * See {@link TreeView.compatibility} for more information.\n *\n * Proper use of this utility should do a good job at detecting schema compatibility issues,\n * however it currently does not do a good job of explaining exactly what change to the schema is causing the compatibility issues.\n * This is a known limitation that will be improved in future releases.\n * These improvements, as well as other changes, may change the exact messages produced by this function in the error cases: no stability of these messages should be assumed.\n *\n * Unlike some other snapshot based testing tools, this stores more than just the current snapshot: historical snapshots are retained as well.\n * Retention of these additional historical snapshots, whose content can't be regenerated from the current schema, is necessary to properly test compatibility across versions.\n * Since there is content in the snapshots which cannot be regenerated, tools which assume all snapshotted content can be regenerated cannot be used here.\n * This means that tools like Jest's built in snapshot testing are not suitable for this purpose.\n * These snapshots behave partly like test data, and partly like snapshots.\n * Typically the easiest way to manage this is to place {@link SnapshotSchemaCompatibilityOptions.snapshotDirectory} inside a directory appropriate for test data,\n * and use node to provide the filesystem access via {@link SnapshotSchemaCompatibilityOptions.fileSystem}.\n *\n * For now, locating what change broke compatibility is likely best discovered by making small schema changes one at a time and updating the snapshot and reviewing the diffs.\n * Details for what kinds of changes are breaking and in which ways can be found in the documentation for {@link TreeView.compatibility} and\n * {@link https://fluidframework.com/docs/data-structures/tree/schema-evolution/ | schema-evolution}.\n *\n * This utility does not enforce anything with respect to API compatibility, or special semantics for major, minor, or patch versions.\n * Libraries which export schema for use by others will need to take special care to ensure the stability contract they offer their users aligns which what is validated by this utility.\n *\n * This utility only tests compatibility of the historical snapshots against the current schema; it does not test them against each-other.\n * Generally any historical schema should have been tested against the ones before them at the time they were current.\n * If for some reason a version of a schema made it into production that was not compatible with a previous version,\n * that can still be represented here (but may require manually generating a snapshot for that version)\n * and this will still allow testing that all historical version can be upgraded to the current one.\n * If a sufficiently incompatible historical schema were used in production, it may be impossible to make a single schema which can accommodate all of them:\n * this utility can be used to confirm that is the case, as well as to avoid the problem in the first place by testing schema before each one is deployed.\n *\n * @example Mocha test which validates the current `config` can collaborate with all historical version back to 2.0.0, and load and update any versions older than that.\n * ```typescript\n * it(\"schema compatibility\", () => {\n * \tsnapshotSchemaCompatibility({\n * \t\tversion: pkgVersion,\n * \t\tschema: config,\n * \t\tfileSystem: { ...fs, ...path },\n * \t\tminVersionForCollaboration: \"2.0.0\",\n * \t\tmode: process.argv.includes(\"--snapshot\") ? \"update\" : \"test\",\n * \t\tsnapshotDirectory,\n * \t});\n * });\n * ```\n * @example Complete Mocha test file\n * ```typescript\n * import fs from \"node:fs\";\n * import path from \"node:path\";\n *\n * import { snapshotSchemaCompatibility } from \"@fluidframework/tree/beta\";\n *\n * // The TreeViewConfiguration the application uses, which contains the application's schema.\n * import { treeViewConfiguration } from \"./schema.js\";\n * // The next version of the application which will be released.\n * import { packageVersion } from \"./version.js\";\n *\n * // Provide some way to run the check in \"update\" mode when updating snapshots is intended.\n * const regenerateSnapshots = process.argv.includes(\"--snapshot\");\n *\n * // Setup the actual test. In this case using Mocha syntax.\n * describe(\"schema\", () => {\n * \tit(\"schema compatibility\", () => {\n * \t\t// Select a path to save the snapshots in.\n * \t\t// This will depend on how your application organizes its test data.\n * \t\tconst snapshotDirectory = path.join(\n * \t\t\timport.meta.dirname,\n * \t\t\t\"../../../src/test/schema-snapshots\",\n * \t\t);\n * \t\tsnapshotSchemaCompatibility({\n * \t\t\tschema: config,\n * \t\t\tfileSystem: { ...fs, ...path },\n * \t\t\tversion: pkgVersion,\n * \t\t\tminVersionForCollaboration: \"2.0.0\",\n * \t\t\tmode: process.argv.includes(\"--snapshot\") ? \"update\" : \"assert\",\n * \t\t\tsnapshotDirectory,\n * \t\t});\n * \t});\n * });\n * ```\n * @privateRemarks\n * Use of this function within this package (for schema libraries released as part of this package) should use {@link testSchemaCompatibilitySnapshots} instead.\n *\n * This uses the format defined in simpleSchemaCodec.ts.\n * This does include versioning information in the snapshot format,\n * but it would be nice to better unify how we do that versioning and format validation with our codecs.\n *\n * See snapshotCompatibilityChecker.example.mts for the large example included above.\n * @beta\n */\nexport function snapshotSchemaCompatibility(\n\toptions: SnapshotSchemaCompatibilityOptions,\n): void {\n\tconst checker = new SnapshotCompatibilityChecker(\n\t\toptions.snapshotDirectory,\n\t\toptions.fileSystem,\n\t);\n\tconst {\n\t\tversion: currentVersion,\n\t\tschema: currentViewSchema,\n\t\tmode,\n\t\tminVersionForCollaboration,\n\t\tsnapshotUnchangedVersions,\n\t\trejectVersionsWithNoSchemaChange,\n\t\trejectSchemaChangesWithNoVersionChange,\n\t} = options;\n\n\tconst validateVersion =\n\t\toptions.versionComparer === undefined ? semver.valid : (v: string) => v;\n\tconst versionComparer = options.versionComparer ?? semver.compare;\n\n\tif (validateVersion(currentVersion) === null) {\n\t\tthrow new UsageError(\n\t\t\t`Invalid version: ${JSON.stringify(currentVersion)}. Must be a valid semver version.`,\n\t\t);\n\t}\n\tif (validateVersion(minVersionForCollaboration) === null) {\n\t\tthrow new UsageError(\n\t\t\t`Invalid minVersionForCollaboration: ${JSON.stringify(minVersionForCollaboration)}. Must be a valid semver version.`,\n\t\t);\n\t}\n\n\tif (versionComparer(minVersionForCollaboration, currentVersion) > 0) {\n\t\tthrow new UsageError(\n\t\t\t`Invalid minVersionForCollaboration: ${JSON.stringify(minVersionForCollaboration)}. Must be less than or equal to current version ${JSON.stringify(currentVersion)}.`,\n\t\t);\n\t}\n\n\tif (mode !== \"assert\" && mode !== \"update\") {\n\t\tthrow new UsageError(\n\t\t\t`Invalid mode: ${JSON.stringify(mode)}. Must be either \"assert\" or \"update\".`,\n\t\t);\n\t}\n\n\tconst currentEncodedForSnapshotting = exportCompatibilitySchemaSnapshot(currentViewSchema);\n\tconst snapshots = checker.readAllSchemaSnapshots(versionComparer);\n\n\tconst compatibilityErrors: string[] = [];\n\n\tconst contextNotes: string[] = [];\n\n\tfunction errorWithContext(message: string): Error {\n\t\treturn new Error(\n\t\t\t[\n\t\t\t\t\"Schema compatibility check failed:\",\n\t\t\t\tmessage,\n\t\t\t\t`Snapshots in: ${JSON.stringify(options.snapshotDirectory)}`,\n\t\t\t\t`Snapshots exist for versions: ${JSON.stringify([...snapshots.keys()], undefined, \"\\t\")}.`,\n\t\t\t\t...contextNotes,\n\t\t\t].join(\"\\n\"),\n\t\t);\n\t}\n\n\tconst compatibilityMap = transformMapValues(snapshots, (snapshot) =>\n\t\tgetCompatibility(currentViewSchema, snapshot),\n\t);\n\n\t// Either:\n\t// - false: no update needed\n\t// - the updateError message (update in update mode, error otherwise)\n\t// - an error if the update is disallowed by the flags\n\tlet wouldUpdate: false | string | Error;\n\n\t// Set wouldUpdate\n\t{\n\t\tconst latestSnapshot = [...snapshots][snapshots.size - 1];\n\t\tif (latestSnapshot === undefined) {\n\t\t\twouldUpdate = `No snapshots found.`;\n\t\t} else {\n\t\t\tconst latestCompatibility =\n\t\t\t\tcompatibilityMap.get(latestSnapshot[0]) ??\n\t\t\t\tfail(0xcd1 /* missing compatibilityMap entry */);\n\n\t\t\tconst schemaChange = !latestCompatibility.identicalCompatibility;\n\t\t\tconst versionChange = versionComparer(latestSnapshot[0], currentVersion) !== 0;\n\n\t\t\tif (rejectVersionsWithNoSchemaChange === true && versionChange && !schemaChange) {\n\t\t\t\twouldUpdate = errorWithContext(\n\t\t\t\t\t`Rejecting version change (${JSON.stringify(latestSnapshot[0])} to ${JSON.stringify(currentVersion)}) due to rejectVersionsWithNoSchemaChange being set.`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\trejectSchemaChangesWithNoVersionChange === true &&\n\t\t\t\tschemaChange &&\n\t\t\t\t!versionChange\n\t\t\t) {\n\t\t\t\twouldUpdate = errorWithContext(\n\t\t\t\t\t`Rejecting schema change without version change due to existing non-equivalent snapshot for version (${JSON.stringify(latestSnapshot[0])} due to rejectSchemaChangesWithNoVersionChange being set.`,\n\t\t\t\t);\n\t\t\t} else if (snapshotUnchangedVersions === true) {\n\t\t\t\tconst currentRead = snapshots.get(currentVersion);\n\t\t\t\tif (currentRead === undefined) {\n\t\t\t\t\twouldUpdate = `No snapshot found for version ${JSON.stringify(currentVersion)}: snapshotUnchangedVersions is true, so every version must be snapshotted.`;\n\t\t\t\t} else if (\n\t\t\t\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(currentRead)) ===\n\t\t\t\t\tJSON.stringify(currentEncodedForSnapshotting)\n\t\t\t\t) {\n\t\t\t\t\twouldUpdate = false;\n\t\t\t\t} else {\n\t\t\t\t\twouldUpdate = `Snapshot for current version ${JSON.stringify(currentVersion)} is out of date.`;\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tif (versionComparer(latestSnapshot[0], currentVersion) <= 0) {\n\t\t\t\t\twouldUpdate = schemaChange\n\t\t\t\t\t\t? `Snapshot for current version ${JSON.stringify(currentVersion)} is out of date: schema has changed since latest existing snapshot version ${JSON.stringify(latestSnapshot[0])}.`\n\t\t\t\t\t\t: false;\n\t\t\t\t} else {\n\t\t\t\t\twouldUpdate = errorWithContext(\n\t\t\t\t\t\t`Current version ${JSON.stringify(currentVersion)} is less than latest existing snapshot version ${JSON.stringify(latestSnapshot[0])}: version is expected to increase monotonically.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!schemaChange && (snapshotUnchangedVersions !== true || !versionChange)) {\n\t\t\t\t// eslint-disable-next-line unicorn/no-lonely-if\n\t\t\t\tif (\n\t\t\t\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(latestSnapshot[1])) !==\n\t\t\t\t\tJSON.stringify(currentEncodedForSnapshotting)\n\t\t\t\t) {\n\t\t\t\t\t// Schema are compatibility wise equivalent, but differ in some way (excluding json formatting).\n\t\t\t\t\t// TODO: add a \"normalize\" mode, which do an update only in this case (or maybe even normalize json formatting as well and just always rewrite when !schemaChange)\n\t\t\t\t\t// This would be useful to minimize diffs from future schema changes.\n\t\t\t\t\t// This would be particularly useful if adding a second version of the format used in the snapshots.\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (wouldUpdate !== false) {\n\t\tif (wouldUpdate instanceof Error) {\n\t\t\tthrow wouldUpdate;\n\t\t}\n\t\tif (mode === \"update\") {\n\t\t\tchecker.writeSchemaSnapshot(currentVersion, currentEncodedForSnapshotting);\n\t\t\t// Update so errors below will reflect the new snapshot.\n\t\t\tcompatibilityMap.set(\n\t\t\t\tcurrentVersion,\n\t\t\t\tgetCompatibility(currentViewSchema, currentViewSchema),\n\t\t\t);\n\t\t} else {\n\t\t\tcompatibilityErrors.push(\n\t\t\t\t`${wouldUpdate} If this is expected, snapshotSchemaCompatibility can be rerun in \"update\" mode to update or create the snapshot.`,\n\t\t\t);\n\n\t\t\t// This case could update compatibilityMap as well, but it would hide some information about how the existing snapshot might be incompatible with the proposed new one.\n\t\t\t// This lost information could be annoying if the user's intention was not to edit the schema (which is what we assume in assert mode),\n\t\t\t// especially once we produce more detailed error messages that can help users understand what changed in the schema.\n\t\t}\n\t}\n\n\t// Add compatibilityErrors and contextNotes as needed regarding minVersionForCollaboration.\n\t// This is only done when minVersionForCollaboration is not the current version to avoid extra noise in \"assert\" mode\n\t// (which is the only case that could error when minVersionForCollaboration === currentVersion).\n\tif (minVersionForCollaboration !== currentVersion) {\n\t\tif (snapshotUnchangedVersions === true) {\n\t\t\tconst minSnapshot = compatibilityMap.get(minVersionForCollaboration);\n\t\t\tif (minSnapshot === undefined) {\n\t\t\t\tcompatibilityErrors.push(\n\t\t\t\t\t`Using snapshotUnchangedVersions: a snapshot of the exact minVersionForCollaboration ${JSON.stringify(minVersionForCollaboration)} is required. No snapshot found.`,\n\t\t\t\t);\n\t\t\t}\n\t\t} else {\n\t\t\tconst selectedMinVersionForCollaborationSnapshot = selectVersionRoundedDown(\n\t\t\t\tminVersionForCollaboration,\n\t\t\t\tcompatibilityMap,\n\t\t\t\tversionComparer,\n\t\t\t);\n\t\t\tif (selectedMinVersionForCollaborationSnapshot === undefined) {\n\t\t\t\tcompatibilityErrors.push(\n\t\t\t\t\t`No snapshot found with version less than or equal to minVersionForCollaboration ${JSON.stringify(minVersionForCollaboration)}.`,\n\t\t\t\t);\n\t\t\t} else if (\n\t\t\t\tselectedMinVersionForCollaborationSnapshot[0] !== minVersionForCollaboration\n\t\t\t) {\n\t\t\t\t// Add an entry to ensure that the version which spans from before until after the cutoff for collaboration is included in the compatibility checks.\n\t\t\t\tcompatibilityMap.set(\n\t\t\t\t\tminVersionForCollaboration,\n\t\t\t\t\tselectedMinVersionForCollaborationSnapshot[1],\n\t\t\t\t);\n\t\t\t\tcontextNotes.push(\n\t\t\t\t\t`Due to snapshotUnchangedVersions being false and minVersionForCollaboration (${JSON.stringify(minVersionForCollaboration)}) not having an exact snapshot, the last snapshot before that version (which is ${JSON.stringify(\n\t\t\t\t\t\tselectedMinVersionForCollaborationSnapshot[0],\n\t\t\t\t\t)}) is being also being checked as if it is version ${JSON.stringify(minVersionForCollaboration)}.`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\t// Compare all snapshots against the current schema, using the compatibilityMap.\n\tfor (const [snapshotVersion, compatibility] of compatibilityMap) {\n\t\t// Current should be able to view all versions.\n\t\tif (!compatibility.currentViewOfSnapshotDocument.canUpgrade) {\n\t\t\tcompatibilityErrors.push(\n\t\t\t\t`Current version ${JSON.stringify(currentVersion)} cannot upgrade documents from ${JSON.stringify(snapshotVersion)}.`,\n\t\t\t);\n\t\t}\n\n\t\tconst versionComparisonToCurrent = versionComparer(snapshotVersion, currentVersion);\n\t\tif (versionComparisonToCurrent === 0) {\n\t\t\tif (currentVersion !== snapshotVersion) {\n\t\t\t\tthrow errorWithContext(\n\t\t\t\t\t`Snapshot version ${JSON.stringify(snapshotVersion)} is semantically equal but not string equal to current version ${JSON.stringify(currentVersion)}: this is not supported.`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (compatibility.identicalCompatibility === false) {\n\t\t\t\tassert(\n\t\t\t\t\twouldUpdate !== false,\n\t\t\t\t\t0xcd2 /* there should have been an error for the snapshot being out of date */,\n\t\t\t\t);\n\t\t\t}\n\t\t} else if (versionComparisonToCurrent < 0) {\n\t\t\t// Collaboration with this version is expected to work.\n\t\t\tif (versionComparer(snapshotVersion, minVersionForCollaboration) >= 0) {\n\t\t\t\t// Check that the historical version can view documents from the current version, since collaboration with this one is expected to work.\n\t\t\t\tif (!compatibility.snapshotViewOfCurrentDocument.canView) {\n\t\t\t\t\tcompatibilityErrors.push(\n\t\t\t\t\t\t`Historical version ${JSON.stringify(snapshotVersion)} cannot view documents from ${JSON.stringify(currentVersion)}: these versions are expected to be able to collaborate due to the selected minVersionForCollaboration ${JSON.stringify(minVersionForCollaboration)}.`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// This is the case where the historical version is less than the minimum version for collaboration.\n\t\t\t\t// No additional validation is needed here currently, since forwards document compat from these versions is already tested above (since it applies to all snapshots).\n\t\t\t}\n\t\t} else {\n\t\t\tcompatibilityErrors.push(\n\t\t\t\t`Snapshot exists for version ${JSON.stringify(snapshotVersion)} which is greater than the current version ${JSON.stringify(currentVersion)}. This is not supported.`,\n\t\t\t);\n\t\t}\n\t}\n\n\tif (compatibilityErrors.length > 0) {\n\t\tthrow errorWithContext(compatibilityErrors.map((e) => ` - ${e}`).join(\"\\n\"));\n\t}\n}\n\n/**\n * The high-level API for checking snapshot compatibility and generating new snapshots.\n */\nexport class SnapshotCompatibilityChecker {\n\tpublic constructor(\n\t\t/**\n\t\t * Directory where historical schema snapshots are stored.\n\t\t */\n\t\tprivate readonly snapshotDirectory: string,\n\t\t/**\n\t\t * How the `snapshotDirectory` is accessed.\n\t\t */\n\t\tprivate readonly fileSystemMethods: SnapshotFileSystem,\n\t) {}\n\n\tpublic writeSchemaSnapshot(snapshotName: string, snapshot: JsonCompatibleReadOnly): void {\n\t\tconst fullPath = this.fileSystemMethods.join(\n\t\t\tthis.snapshotDirectory,\n\t\t\t`${snapshotName}.json`,\n\t\t);\n\t\tthis.ensureSnapshotDirectoryExists();\n\t\tthis.fileSystemMethods.writeFileSync(fullPath, JSON.stringify(snapshot, undefined, \"\\t\"), {\n\t\t\tencoding: \"utf8\",\n\t\t});\n\t}\n\n\tpublic readSchemaSnapshot(snapshotName: string): TreeViewConfiguration {\n\t\tconst snapshot = this.readSchemaSnapshotRaw(snapshotName);\n\t\treturn importCompatibilitySchemaSnapshot(snapshot);\n\t}\n\n\tpublic readSchemaSnapshotRaw(snapshotName: string): JsonCompatibleReadOnly {\n\t\tconst fullPath = this.fileSystemMethods.join(\n\t\t\tthis.snapshotDirectory,\n\t\t\t`${snapshotName}.json`,\n\t\t);\n\t\tconst snapshot = JSON.parse(\n\t\t\tthis.fileSystemMethods.readFileSync(fullPath, \"utf8\"),\n\t\t) as JsonCompatibleReadOnly;\n\t\treturn snapshot;\n\t}\n\n\t/**\n\t * Returns all schema snapshots stored in the snapshot directory, sorted in order of increasing version.\n\t */\n\tpublic readAllSchemaSnapshots(\n\t\tcompare: (a: string, b: string) => number,\n\t): Map<string, TreeViewConfiguration> {\n\t\tthis.ensureSnapshotDirectoryExists();\n\t\tconst files = this.fileSystemMethods.readdirSync(this.snapshotDirectory);\n\t\tconst versions: string[] = [];\n\t\tfor (const file of files) {\n\t\t\tif (file.endsWith(\".json\")) {\n\t\t\t\tconst snapshotName = file.slice(0, \".json\".length * -1);\n\t\t\t\tversions.push(snapshotName);\n\t\t\t}\n\t\t}\n\t\t// Ensures that errors are in a consistent and friendly order, independent of file system order.\n\t\tversions.sort(compare);\n\n\t\tconst snapshots: Map<string, TreeViewConfiguration> = new Map();\n\t\tfor (const version of versions) {\n\t\t\tsnapshots.set(version, this.readSchemaSnapshot(version));\n\t\t}\n\t\treturn snapshots;\n\t}\n\n\tpublic ensureSnapshotDirectoryExists(): void {\n\t\tthis.fileSystemMethods.mkdirSync(this.snapshotDirectory, { recursive: true });\n\t}\n}\n\n/**\n * Gets the compatibility of the current view schema against a historical snapshot.\n * @param currentViewSchema - The current view schema.\n * @param previousViewSchema - The historical view schema.\n * @returns The combined compatibility status.\n */\nexport function getCompatibility(\n\tcurrentViewSchema: TreeViewConfiguration,\n\tpreviousViewSchema: TreeViewConfiguration,\n): CombinedSchemaCompatibilityStatus {\n\tconst backwardsCompatibilityStatus = checkCompatibility(\n\t\tpreviousViewSchema,\n\t\tcurrentViewSchema,\n\t);\n\n\tconst forwardsCompatibilityStatus = checkCompatibility(\n\t\tcurrentViewSchema,\n\t\tpreviousViewSchema,\n\t);\n\n\tassert(\n\t\tbackwardsCompatibilityStatus.isEquivalent === forwardsCompatibilityStatus.isEquivalent,\n\t\t0xcd3 /* equality should be symmetric */,\n\t);\n\n\t// This relies on exportCompatibilitySchemaSnapshot being well normalized, and not differing for non-significant changes.\n\tconst identicalCompatibility =\n\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(currentViewSchema)) ===\n\t\tJSON.stringify(exportCompatibilitySchemaSnapshot(previousViewSchema));\n\n\tif (identicalCompatibility) {\n\t\tassert(\n\t\t\tbackwardsCompatibilityStatus.isEquivalent,\n\t\t\t0xcd4 /* identicalCompatibility should have equivalent stored schema */,\n\t\t);\n\t}\n\n\treturn {\n\t\tcurrentViewOfSnapshotDocument: backwardsCompatibilityStatus,\n\t\tsnapshotViewOfCurrentDocument: forwardsCompatibilityStatus,\n\t\tidenticalCompatibility,\n\t};\n}\n"]}
@@ -256,6 +256,16 @@ export interface TreeBranchAlpha extends TreeBranch, TreeContextAlpha {
256
256
  * Update the tests and docs to match when that is done.
257
257
  */
258
258
  applyChange(change: JsonCompatibleReadOnly): void;
259
+ /**
260
+ * Determines if there are changes on the given branch that are not present on this branch.
261
+ * @param branch - The branch to compare to.
262
+ *
263
+ * The new edits, if any, can be applied to this branch by {@link TreeBranch.rebaseOnto | rebasing this branch onto the given branch}
264
+ * or by {@link TreeBranch.merge | merging the given branch into this branch}.
265
+ *
266
+ * @throws UsageError if the branches are unrelated.
267
+ */
268
+ isMissingEditsFrom(branch: TreeBranch): boolean;
259
269
  }
260
270
  /**
261
271
  * An editable view of a (version control style) branch of a shared tree based on some schema.
@@ -1 +1 @@
1
- {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../../src/simple-tree/api/tree.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAE/F,OAAO,KAAK,EACX,cAAc,EACd,cAAc,EACd,sBAAsB,EACtB,iBAAiB,EACjB,MAAM,qBAAqB,CAAC;AAS7B,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,qBAAqB,CAAC;AAIlE,OAAO,KAAK,EACX,mBAAmB,EACnB,eAAe,EACf,oCAAoC,EACpC,aAAa,EACb,UAAU,EACV,0BAA0B,EAC1B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAErE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChE,OAAO,KAAK,EACX,oBAAoB,EACpB,yBAAyB,EACzB,iBAAiB,EACjB,oBAAoB,EACpB,6BAA6B,EAC7B,SAAS,EACT,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC5B;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,CAAC,KAAK,SAAS,mBAAmB,EACzC,MAAM,EAAE,qBAAqB,CAAC,KAAK,CAAC,GAClC,QAAQ,CAAC,KAAK,CAAC,CAAC;CACnB;AAED;;;;;GAKG;AACH,MAAM,WAAW,KAAM,SAAQ,YAAY,EAAE,cAAc;CAAG;AAE9D;;;GAGG;AACH,MAAM,WAAW,UAA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,IAAI,EAAE,cAAc,EAAE,aAAa,CAAC,EAAE,iBAAiB,GAAG,IAAI,CAAC;CAC7E;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,SAAS,mBAAmB,EAClE,IAAI,EAAE,QAAQ,CAAC,OAAO,CAAC,GACrB,aAAa,CAAC,OAAO,CAAC,CAExB"}
@@ -1 +1 @@
1
- {"version":3,"file":"tree.js","sourceRoot":"","sources":["../../../src/simple-tree/api/tree.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA4mBH;;;;;GAKG;AACH,SAAgB,eAAe,CAC9B,IAAuB;IAEvB,OAAO,IAA8B,CAAC;AACvC,CAAC;AAJD,0CAIC","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\tChangeMetadata,\n\tCommitMetadata,\n\tRevertibleAlphaFactory,\n\tRevertibleFactory,\n} from \"../../core/index.js\";\n// This is referenced by doc comments.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { TreeStatus } from \"../../feature-libraries/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 { JsonCompatibleReadOnly } from \"../../util/index.js\";\n// This is referenced by doc comments.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { Unhydrated } from \"../core/index.js\";\nimport type {\n\tImplicitFieldSchema,\n\tInsertableField,\n\tInsertableTreeFieldFromImplicitField,\n\tReadableField,\n\tReadSchema,\n\tTreeFieldFromImplicitField,\n} from \"../fieldSchema.js\";\nimport type { SimpleTreeSchema } from \"../simpleSchema.js\";\nimport type { UnsafeUnknownSchema } from \"../unsafeUnknownSchema.js\";\n\nimport type { TreeViewConfiguration } from \"./configuration.js\";\nimport type {\n\tRunTransactionParams,\n\tTransactionCallbackStatus,\n\tTransactionResult,\n\tTransactionResultExt,\n\tVoidTransactionCallbackStatus,\n\tWithValue,\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 list of all shared branches that currently exist on this tree.\n\t * Any one of them can be checked out using {@link ITreeAlpha.viewSharedBranchWith}.\n\t */\n\tgetSharedBranchIds(): 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 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 *\n * See {@link TreeBranchAlpha} for additional APIs that are in an earlier stage of development.\n * @sealed @beta\n */\nexport interface TreeBranch extends IDisposable {\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 * 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 * Provides additional APIs that may be used to interact with a tree node or a tree node's SharedTree.\n * @alpha\n */\nexport interface TreeContextAlpha {\n\t/**\n\t * Run a synchronous transaction which groups sequential edits to the tree into a single atomic edit if possible.\n\t * @param transaction - A callback run during the transaction to perform user-supplied operations.\n\t * It may optionally return a {@link WithValue | value }, which will be returned by the `runTransaction` call.\n\t * @param params - Optional {@link RunTransactionParams | parameters} for the transaction.\n\t * @returns A {@link TransactionResultExt | value } indicating whether or not the transaction succeeded, and containing the value returned by `transaction`.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes 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 *\n\t * {@link (TreeBeta:interface).on | Change events } will be emitted for changed nodes on this client _as each edit happens_, just as they would be if the changes were made outside of a transaction.\n\t * Any other/future clients or contexts will process the transaction \"squashed\", i.e. they will apply its changes all at once, emitting only a single event per node (even if that node was edited multiple times in the transaction).\n\t * Edits to the tree are not permitted within these event callbacks, therefore no other local changes from this client will be interleaved with the changes in this transaction.\n\t *\n\t * Using a transaction has the following additional consequences:\n\t *\n\t * - If {@link Revertible | reverted } (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * Only the \"outermost\" transaction commits a change to the synchronized tree state and therefore only the outermost transaction can be reverted.\n\t * If a transaction is started and completed while another transaction is already in progress, then the inner transaction will be reverted together with the outer transaction.\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 * `runTransaction` may be invoked on the context of a {@link TreeStatus.InDocument | hydrated } or {@link Unhydrated | unhydrated } node.\n\t * Use {@link TreeContextAlpha.isBranch | isBranch() } to check whether this context is associated with a branch and gain {@link TreeBranchAlpha.(runTransaction:1) | access to more transaction capabilities} if so.\n\t */\n\trunTransaction<TValue>(\n\t\ttransaction: () => WithValue<TValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TValue, TValue>;\n\n\t/** An overload of {@link TreeContextAlpha.(runTransaction:1) | runTransaction } which does not return a value. */\n\trunTransaction(transaction: () => void, params?: RunTransactionParams): TransactionResult;\n\n\t/**\n\t * An asynchronous version of {@link TreeContextAlpha.(runTransaction:1) | runTransaction}.\n\t * @remarks\n\t * As with synchronous transactions, all of the changes in an asynchronous transaction are treated as a unit.\n\t * Therefore, no other changes (either from this client or from a remote client) can be interleaved with the transaction changes.\n\t *\n\t * Unlike with synchronous transactions, it is possible that other changes (e.g. from a remote client) may be applied to the branch while this transaction is in progress.\n\t * Those other changes will be not be reflected on the branch until after this transaction completes, at which point the transaction changes will be applied after those other changes.\n\t *\n\t * An asynchronous transaction may not be started while any other transaction is in progress in this context.\n\t */\n\trunTransactionAsync<TValue>(\n\t\ttransaction: () => Promise<WithValue<TValue>>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResultExt<TValue, TValue>>;\n\n\t/** An overload of {@link TreeContextAlpha.(runTransactionAsync:1) | runTransactionAsync } which does not return a value. */\n\trunTransactionAsync(\n\t\ttransaction: () => Promise<void>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResult>;\n\n\t/**\n\t * True if this context is associated with a {@link TreeBranchAlpha | branch} and false if it is associated with an {@link Unhydrated | unhydrated } node.\n\t * @remarks If this returns true, the context can be safely inferred or cast to {@link TreeBranchAlpha} to access additional branch-specific APIs.\n\t * @example\n\t * ```typescript\n\t * const context = tree.context(someNode);\n\t * if (context.isBranch()) {\n\t * assert(context.hasRootSchema(MySchema)) // `hasRootSchema` is a method on TreeBranchAlpha, so this is only accessible if `context` is a branch context.\n\t * context.root.foo = \"bar\"; // Edit the root of the SharedTree that `someNode` belongs to.\n\t * }\n\t * ```\n\t */\n\tisBranch(): this is TreeBranchAlpha;\n}\n\n/**\n * {@link TreeBranch} with alpha-level APIs.\n * @remarks\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 TreeBranchAlpha.hasRootSchema | hasRootSchema()}.\n * @sealed @alpha\n */\nexport interface TreeBranchAlpha extends TreeBranch, TreeContextAlpha {\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// Override the base fork method to return the alpha variant.\n\tfork(): TreeBranchAlpha;\n\n\t/**\n\t * {@link TreeContextAlpha.(runTransaction:1) | Run a transaction} on a branch of the SharedTree.\n\t * @param transaction - The function to run as the body of the transaction, which may optionally return a {@link TransactionCallbackStatus | value or rollback signal}.\n\t * @remarks\n\t * If the transaction is rolled back, a corresponding {@link TreeBranchEvents.changed | `changed`} event will also be emitted for the rollback.\n\t */\n\trunTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue>;\n\n\t/**\n\t * An overload of {@link TreeBranchAlpha.(runTransaction:1) | runTransaction } which does not return a value.\n\t */\n\trunTransaction(\n\t\ttransaction: () => VoidTransactionCallbackStatus | void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResult;\n\n\t/**\n\t * An asynchronous version of {@link TreeBranchAlpha.(runTransaction:1) | runTransaction}.\n\t * @remarks See {@link TreeContextAlpha.(runTransactionAsync:1) | runTransactionAsync} for additional information about asynchronous transactions.\n\t */\n\n\trunTransactionAsync<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => Promise<TransactionCallbackStatus<TSuccessValue, TFailureValue>>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResultExt<TSuccessValue, TFailureValue>>;\n\n\t/**\n\t * An overload of {@link TreeBranchAlpha.(runTransactionAsync:1) | runTransactionAsync } which does not return a value.\n\t */\n\trunTransactionAsync(\n\t\ttransaction: () => Promise<VoidTransactionCallbackStatus | void>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResult>;\n\n\t/**\n\t * Apply a serialized change to this branch.\n\t * @param change - the change to apply.\n\t * Changes are acquired via `getChange` in a branch's {@link TreeBranchEvents.changed | \"changed\"} event.\n\t * @remarks Changes may only be applied to a SharedTree with the same IdCompressor instance and branch state from which they were generated.\n\t * They may be created by one branch and applied to another, but only if both branches share the same history at the time of creation and application.\n\t *\n\t * @privateRemarks\n\t * TODO: This method will support applying changes from different IdCompressor instances as long as they have the same local session ID.\n\t * Update the tests and docs to match when that is done.\n\t */\n\tapplyChange(change: JsonCompatibleReadOnly): 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 * See also {@link TreeViewAlpha}, {@link TreeViewBeta} and {@link TreeBranch} for additional APIs that are in earlier stages of development.\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 * @remarks\n\t * {@link TreeViewEvents.schemaChanged} is fired when the compatibility status changes.\n\t * See {@link https://fluidframework.com/docs/data-structures/tree/schema-evolution/ | schema-evolution} for more guidance on how to change schema while maintaining compatibility.\n\t * Use {@link snapshotSchemaCompatibility} to write tests to validate that this compatibility behaves as desired across schema changes.\n\t */\n\treadonly compatibility: SchemaCompatibilityStatus;\n\n\t/**\n\t * When {@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 * @remarks\n\t * This will update the {@link TreeView.compatibility}, allowing access to `root`.\n\t * Beware that this may impact other clients' ability to view the document: see {@link SchemaCompatibilityStatus.canView} for more information.\n\t *\n\t * It is an error to call this when {@link SchemaCompatibilityStatus.canUpgrade} is false.\n\t * {@link SchemaCompatibilityStatus.canUpgrade} being true does not mean that an upgrade is required, nor that an upgrade will have any effect.\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 * - update only a specific change (add an optional field, or apply a staged upgrade)\n\t * - update persistedMetadata or not\n\t *\n\t * As persisted metadata becomes more supported, how it interacts with isEquivalent and upgradeSchema should be clarified:\n\t * for now the docs are being left somewhat vague to allow flexibility in this area.\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<TreeViewBeta<ReadSchema<TSchema>>, \"root\" | \"initialize\" | \"fork\">,\n\t\tTreeBranchAlpha {\n\tget root(): ReadableField<TSchema>;\n\n\tset root(newRoot: InsertableField<TSchema>);\n\n\tinitialize(content: InsertableField<TSchema>): void;\n\n\treadonly events: Listenable<TreeViewEvents & TreeBranchEvents>;\n\n\t// Override the base fork method to return a TreeViewAlpha.\n\tfork(): ReturnType<TreeBranch[\"fork\"]> & TreeViewAlpha<TSchema>;\n}\n\n/**\n * {@link TreeView} with additional beta APIs.\n * @sealed @beta\n */\nexport interface TreeViewBeta<in out TSchema extends ImplicitFieldSchema>\n\textends TreeView<TSchema>,\n\t\tTreeBranch {\n\t// Override the base branch method to return a typed view rather than merely a branch.\n\tfork(): ReturnType<TreeBranch[\"fork\"]> & TreeViewBeta<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 * @privateRemarks\n * See {@link SchemaCompatibilityTester} for the implementation of this compatibility checking.\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 (for example: 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\t * Note that other content in the stored schema that does not impact document compatibility, like {@link NodeSchemaOptionsAlpha.persistedMetadata}, does not affect this field.\n\t *\n\t * For the computation of this equivalence, {@link SchemaStaticsBeta.staged | staged} schemas are not included.\n\t * If there are any unknown optional fields, even if allowed by {@link ObjectSchemaOptions.allowUnknownOptionalFields}, `isEquivalent` will be false.\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 * @remarks\n\t * If the view schema does not opt into supporting any additional cases, then `canView` is only true when `isEquivalent` is also true.\n\t * The view schema can however opt into supporting additional cases, and thus can also view documents with stored schema which would be equivalent, except for the following discrepancies:\n\t *\n\t * - An object node with {@link ObjectSchemaOptions.allowUnknownOptionalFields} to set to true that has additional optional fields in the stored schema beyond those mentioned in its view schema.\n\t *\n\t * - An additional type allowed at a location in the stored schema where it is {@link SchemaStaticsBeta.staged | staged} in the view schema.\n\t *\n\t * In these cases `canUpgrade` and `isEquivalent` will be false.\n\t *\n\t * When the set of documents allowed by the view schema is a strict superset of those allowed by the stored schema,\n\t * `canView` 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 versions 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 only tolerate very specific cases beyond their schema (unknown optional fields).\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 when {@link TreeView.upgradeSchema} can add support for all content required to be supported by the view schema.\n\t * @remarks\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\t * When adding optional fields to schema which previously were marked with {@link ObjectSchemaOptions.allowUnknownOptionalFields}\n\t * the schema upgrade (assuming no other changes are included) will allow the previous version to view.\n\t * Even this case must still must be done with caution however as only clients with the newly added field will be able to do future upgrades.\n\t * Thus if a version of an application is shipped that adds an unknown optional field, all future versions should include it, even if its no longer used,\n\t * to ensure that documents containing it can still be upgraded.\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 {\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: ChangeMetadata, getRevertible?: RevertibleAlphaFactory): void;\n}\n\n/**\n * Events for {@link TreeView}.\n * @remarks\n * See {@link TreeBranchEvents} for more events related to the underlying branch of the SharedTree.\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 * @deprecated Use {@link (asAlpha:1)} instead.\n * @privateRemarks Despite being deprecated, this function should be used within the tree package (outside of tests) rather than `asAlpha` in order to avoid circular import dependencies.\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;;;AAunBH;;;;;GAKG;AACH,SAAgB,eAAe,CAC9B,IAAuB;IAEvB,OAAO,IAA8B,CAAC;AACvC,CAAC;AAJD,0CAIC","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\tChangeMetadata,\n\tCommitMetadata,\n\tRevertibleAlphaFactory,\n\tRevertibleFactory,\n} from \"../../core/index.js\";\n// This is referenced by doc comments.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { TreeStatus } from \"../../feature-libraries/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 { JsonCompatibleReadOnly } from \"../../util/index.js\";\n// This is referenced by doc comments.\n// eslint-disable-next-line @typescript-eslint/no-unused-vars\nimport type { Unhydrated } from \"../core/index.js\";\nimport type {\n\tImplicitFieldSchema,\n\tInsertableField,\n\tInsertableTreeFieldFromImplicitField,\n\tReadableField,\n\tReadSchema,\n\tTreeFieldFromImplicitField,\n} from \"../fieldSchema.js\";\nimport type { SimpleTreeSchema } from \"../simpleSchema.js\";\nimport type { UnsafeUnknownSchema } from \"../unsafeUnknownSchema.js\";\n\nimport type { TreeViewConfiguration } from \"./configuration.js\";\nimport type {\n\tRunTransactionParams,\n\tTransactionCallbackStatus,\n\tTransactionResult,\n\tTransactionResultExt,\n\tVoidTransactionCallbackStatus,\n\tWithValue,\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 list of all shared branches that currently exist on this tree.\n\t * Any one of them can be checked out using {@link ITreeAlpha.viewSharedBranchWith}.\n\t */\n\tgetSharedBranchIds(): 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 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 *\n * See {@link TreeBranchAlpha} for additional APIs that are in an earlier stage of development.\n * @sealed @beta\n */\nexport interface TreeBranch extends IDisposable {\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 * 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 * Provides additional APIs that may be used to interact with a tree node or a tree node's SharedTree.\n * @alpha\n */\nexport interface TreeContextAlpha {\n\t/**\n\t * Run a synchronous transaction which groups sequential edits to the tree into a single atomic edit if possible.\n\t * @param transaction - A callback run during the transaction to perform user-supplied operations.\n\t * It may optionally return a {@link WithValue | value }, which will be returned by the `runTransaction` call.\n\t * @param params - Optional {@link RunTransactionParams | parameters} for the transaction.\n\t * @returns A {@link TransactionResultExt | value } indicating whether or not the transaction succeeded, and containing the value returned by `transaction`.\n\t * @remarks\n\t * All of the changes in the transaction are applied synchronously and therefore no other changes 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 *\n\t * {@link (TreeBeta:interface).on | Change events } will be emitted for changed nodes on this client _as each edit happens_, just as they would be if the changes were made outside of a transaction.\n\t * Any other/future clients or contexts will process the transaction \"squashed\", i.e. they will apply its changes all at once, emitting only a single event per node (even if that node was edited multiple times in the transaction).\n\t * Edits to the tree are not permitted within these event callbacks, therefore no other local changes from this client will be interleaved with the changes in this transaction.\n\t *\n\t * Using a transaction has the following additional consequences:\n\t *\n\t * - If {@link Revertible | reverted } (e.g. via an \"undo\" operation), all the changes in the transaction are reverted together.\n\t * Only the \"outermost\" transaction commits a change to the synchronized tree state and therefore only the outermost transaction can be reverted.\n\t * If a transaction is started and completed while another transaction is already in progress, then the inner transaction will be reverted together with the outer transaction.\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 * `runTransaction` may be invoked on the context of a {@link TreeStatus.InDocument | hydrated } or {@link Unhydrated | unhydrated } node.\n\t * Use {@link TreeContextAlpha.isBranch | isBranch() } to check whether this context is associated with a branch and gain {@link TreeBranchAlpha.(runTransaction:1) | access to more transaction capabilities} if so.\n\t */\n\trunTransaction<TValue>(\n\t\ttransaction: () => WithValue<TValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TValue, TValue>;\n\n\t/** An overload of {@link TreeContextAlpha.(runTransaction:1) | runTransaction } which does not return a value. */\n\trunTransaction(transaction: () => void, params?: RunTransactionParams): TransactionResult;\n\n\t/**\n\t * An asynchronous version of {@link TreeContextAlpha.(runTransaction:1) | runTransaction}.\n\t * @remarks\n\t * As with synchronous transactions, all of the changes in an asynchronous transaction are treated as a unit.\n\t * Therefore, no other changes (either from this client or from a remote client) can be interleaved with the transaction changes.\n\t *\n\t * Unlike with synchronous transactions, it is possible that other changes (e.g. from a remote client) may be applied to the branch while this transaction is in progress.\n\t * Those other changes will be not be reflected on the branch until after this transaction completes, at which point the transaction changes will be applied after those other changes.\n\t *\n\t * An asynchronous transaction may not be started while any other transaction is in progress in this context.\n\t */\n\trunTransactionAsync<TValue>(\n\t\ttransaction: () => Promise<WithValue<TValue>>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResultExt<TValue, TValue>>;\n\n\t/** An overload of {@link TreeContextAlpha.(runTransactionAsync:1) | runTransactionAsync } which does not return a value. */\n\trunTransactionAsync(\n\t\ttransaction: () => Promise<void>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResult>;\n\n\t/**\n\t * True if this context is associated with a {@link TreeBranchAlpha | branch} and false if it is associated with an {@link Unhydrated | unhydrated } node.\n\t * @remarks If this returns true, the context can be safely inferred or cast to {@link TreeBranchAlpha} to access additional branch-specific APIs.\n\t * @example\n\t * ```typescript\n\t * const context = tree.context(someNode);\n\t * if (context.isBranch()) {\n\t * assert(context.hasRootSchema(MySchema)) // `hasRootSchema` is a method on TreeBranchAlpha, so this is only accessible if `context` is a branch context.\n\t * context.root.foo = \"bar\"; // Edit the root of the SharedTree that `someNode` belongs to.\n\t * }\n\t * ```\n\t */\n\tisBranch(): this is TreeBranchAlpha;\n}\n\n/**\n * {@link TreeBranch} with alpha-level APIs.\n * @remarks\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 TreeBranchAlpha.hasRootSchema | hasRootSchema()}.\n * @sealed @alpha\n */\nexport interface TreeBranchAlpha extends TreeBranch, TreeContextAlpha {\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// Override the base fork method to return the alpha variant.\n\tfork(): TreeBranchAlpha;\n\n\t/**\n\t * {@link TreeContextAlpha.(runTransaction:1) | Run a transaction} on a branch of the SharedTree.\n\t * @param transaction - The function to run as the body of the transaction, which may optionally return a {@link TransactionCallbackStatus | value or rollback signal}.\n\t * @remarks\n\t * If the transaction is rolled back, a corresponding {@link TreeBranchEvents.changed | `changed`} event will also be emitted for the rollback.\n\t */\n\trunTransaction<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => TransactionCallbackStatus<TSuccessValue, TFailureValue>,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResultExt<TSuccessValue, TFailureValue>;\n\n\t/**\n\t * An overload of {@link TreeBranchAlpha.(runTransaction:1) | runTransaction } which does not return a value.\n\t */\n\trunTransaction(\n\t\ttransaction: () => VoidTransactionCallbackStatus | void,\n\t\tparams?: RunTransactionParams,\n\t): TransactionResult;\n\n\t/**\n\t * An asynchronous version of {@link TreeBranchAlpha.(runTransaction:1) | runTransaction}.\n\t * @remarks See {@link TreeContextAlpha.(runTransactionAsync:1) | runTransactionAsync} for additional information about asynchronous transactions.\n\t */\n\n\trunTransactionAsync<TSuccessValue, TFailureValue>(\n\t\ttransaction: () => Promise<TransactionCallbackStatus<TSuccessValue, TFailureValue>>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResultExt<TSuccessValue, TFailureValue>>;\n\n\t/**\n\t * An overload of {@link TreeBranchAlpha.(runTransactionAsync:1) | runTransactionAsync } which does not return a value.\n\t */\n\trunTransactionAsync(\n\t\ttransaction: () => Promise<VoidTransactionCallbackStatus | void>,\n\t\tparams?: RunTransactionParams,\n\t): Promise<TransactionResult>;\n\n\t/**\n\t * Apply a serialized change to this branch.\n\t * @param change - the change to apply.\n\t * Changes are acquired via `getChange` in a branch's {@link TreeBranchEvents.changed | \"changed\"} event.\n\t * @remarks Changes may only be applied to a SharedTree with the same IdCompressor instance and branch state from which they were generated.\n\t * They may be created by one branch and applied to another, but only if both branches share the same history at the time of creation and application.\n\t *\n\t * @privateRemarks\n\t * TODO: This method will support applying changes from different IdCompressor instances as long as they have the same local session ID.\n\t * Update the tests and docs to match when that is done.\n\t */\n\tapplyChange(change: JsonCompatibleReadOnly): void;\n\n\t/**\n\t * Determines if there are changes on the given branch that are not present on this branch.\n\t * @param branch - The branch to compare to.\n\t *\n\t * The new edits, if any, can be applied to this branch by {@link TreeBranch.rebaseOnto | rebasing this branch onto the given branch}\n\t * or by {@link TreeBranch.merge | merging the given branch into this branch}.\n\t *\n\t * @throws UsageError if the branches are unrelated.\n\t */\n\tisMissingEditsFrom(branch: TreeBranch): boolean;\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 * See also {@link TreeViewAlpha}, {@link TreeViewBeta} and {@link TreeBranch} for additional APIs that are in earlier stages of development.\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 * @remarks\n\t * {@link TreeViewEvents.schemaChanged} is fired when the compatibility status changes.\n\t * See {@link https://fluidframework.com/docs/data-structures/tree/schema-evolution/ | schema-evolution} for more guidance on how to change schema while maintaining compatibility.\n\t * Use {@link snapshotSchemaCompatibility} to write tests to validate that this compatibility behaves as desired across schema changes.\n\t */\n\treadonly compatibility: SchemaCompatibilityStatus;\n\n\t/**\n\t * When {@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 * @remarks\n\t * This will update the {@link TreeView.compatibility}, allowing access to `root`.\n\t * Beware that this may impact other clients' ability to view the document: see {@link SchemaCompatibilityStatus.canView} for more information.\n\t *\n\t * It is an error to call this when {@link SchemaCompatibilityStatus.canUpgrade} is false.\n\t * {@link SchemaCompatibilityStatus.canUpgrade} being true does not mean that an upgrade is required, nor that an upgrade will have any effect.\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 * - update only a specific change (add an optional field, or apply a staged upgrade)\n\t * - update persistedMetadata or not\n\t *\n\t * As persisted metadata becomes more supported, how it interacts with isEquivalent and upgradeSchema should be clarified:\n\t * for now the docs are being left somewhat vague to allow flexibility in this area.\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<TreeViewBeta<ReadSchema<TSchema>>, \"root\" | \"initialize\" | \"fork\">,\n\t\tTreeBranchAlpha {\n\tget root(): ReadableField<TSchema>;\n\n\tset root(newRoot: InsertableField<TSchema>);\n\n\tinitialize(content: InsertableField<TSchema>): void;\n\n\treadonly events: Listenable<TreeViewEvents & TreeBranchEvents>;\n\n\t// Override the base fork method to return a TreeViewAlpha.\n\tfork(): ReturnType<TreeBranch[\"fork\"]> & TreeViewAlpha<TSchema>;\n}\n\n/**\n * {@link TreeView} with additional beta APIs.\n * @sealed @beta\n */\nexport interface TreeViewBeta<in out TSchema extends ImplicitFieldSchema>\n\textends TreeView<TSchema>,\n\t\tTreeBranch {\n\t// Override the base branch method to return a typed view rather than merely a branch.\n\tfork(): ReturnType<TreeBranch[\"fork\"]> & TreeViewBeta<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 * @privateRemarks\n * See {@link SchemaCompatibilityTester} for the implementation of this compatibility checking.\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 (for example: 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\t * Note that other content in the stored schema that does not impact document compatibility, like {@link NodeSchemaOptionsAlpha.persistedMetadata}, does not affect this field.\n\t *\n\t * For the computation of this equivalence, {@link SchemaStaticsBeta.staged | staged} schemas are not included.\n\t * If there are any unknown optional fields, even if allowed by {@link ObjectSchemaOptions.allowUnknownOptionalFields}, `isEquivalent` will be false.\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 * @remarks\n\t * If the view schema does not opt into supporting any additional cases, then `canView` is only true when `isEquivalent` is also true.\n\t * The view schema can however opt into supporting additional cases, and thus can also view documents with stored schema which would be equivalent, except for the following discrepancies:\n\t *\n\t * - An object node with {@link ObjectSchemaOptions.allowUnknownOptionalFields} to set to true that has additional optional fields in the stored schema beyond those mentioned in its view schema.\n\t *\n\t * - An additional type allowed at a location in the stored schema where it is {@link SchemaStaticsBeta.staged | staged} in the view schema.\n\t *\n\t * In these cases `canUpgrade` and `isEquivalent` will be false.\n\t *\n\t * When the set of documents allowed by the view schema is a strict superset of those allowed by the stored schema,\n\t * `canView` 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 versions 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 only tolerate very specific cases beyond their schema (unknown optional fields).\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 when {@link TreeView.upgradeSchema} can add support for all content required to be supported by the view schema.\n\t * @remarks\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\t * When adding optional fields to schema which previously were marked with {@link ObjectSchemaOptions.allowUnknownOptionalFields}\n\t * the schema upgrade (assuming no other changes are included) will allow the previous version to view.\n\t * Even this case must still must be done with caution however as only clients with the newly added field will be able to do future upgrades.\n\t * Thus if a version of an application is shipped that adds an unknown optional field, all future versions should include it, even if its no longer used,\n\t * to ensure that documents containing it can still be upgraded.\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 {\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: ChangeMetadata, getRevertible?: RevertibleAlphaFactory): void;\n}\n\n/**\n * Events for {@link TreeView}.\n * @remarks\n * See {@link TreeBranchEvents} for more events related to the underlying branch of the SharedTree.\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 * @deprecated Use {@link (asAlpha:1)} instead.\n * @privateRemarks Despite being deprecated, this function should be used within the tree package (outside of tests) rather than `asAlpha` in order to avoid circular import dependencies.\n */\nexport function asTreeViewAlpha<TSchema extends ImplicitFieldSchema>(\n\tview: TreeView<TSchema>,\n): TreeViewAlpha<TSchema> {\n\treturn view as TreeViewAlpha<TSchema>;\n}\n"]}