@fluid-experimental/tree 2.118.1 → 3.0.1

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 (164) hide show
  1. package/CHANGELOG.md +22 -4
  2. package/README.md +52 -48
  3. package/{api-extractor.json → api-extractor/api-extractor-model.json} +1 -6
  4. package/api-extractor/api-extractor-report.json +9 -0
  5. package/dist/ChangeCompression.js +4 -3
  6. package/dist/ChangeCompression.js.map +1 -1
  7. package/dist/ChangeTypes.d.ts.map +1 -1
  8. package/dist/Checkout.js +28 -1
  9. package/dist/Checkout.js.map +1 -1
  10. package/dist/Common.js +27 -27
  11. package/dist/Common.js.map +1 -1
  12. package/dist/EditLog.d.ts.map +1 -1
  13. package/dist/EditLog.js +15 -11
  14. package/dist/EditLog.js.map +1 -1
  15. package/dist/EditUtilities.js +18 -18
  16. package/dist/EditUtilities.js.map +1 -1
  17. package/dist/Forest.js +12 -3
  18. package/dist/Forest.js.map +1 -1
  19. package/dist/HistoryEditFactory.js +2 -2
  20. package/dist/HistoryEditFactory.js.map +1 -1
  21. package/dist/IdConversion.js +4 -5
  22. package/dist/IdConversion.js.map +1 -1
  23. package/dist/Identifiers.js +1 -2
  24. package/dist/Identifiers.js.map +1 -1
  25. package/dist/LazyCheckout.js +1 -0
  26. package/dist/LazyCheckout.js.map +1 -1
  27. package/dist/LogViewer.js +50 -16
  28. package/dist/LogViewer.js.map +1 -1
  29. package/dist/MergeHealth.js +121 -123
  30. package/dist/MergeHealth.js.map +1 -1
  31. package/dist/NodeIdUtilities.js +4 -5
  32. package/dist/NodeIdUtilities.js.map +1 -1
  33. package/dist/PayloadUtilities.js +1 -2
  34. package/dist/PayloadUtilities.js.map +1 -1
  35. package/dist/RevisionValueCache.js +18 -6
  36. package/dist/RevisionValueCache.js.map +1 -1
  37. package/dist/RevisionView.js +3 -3
  38. package/dist/RevisionView.js.map +1 -1
  39. package/dist/SerializationUtilities.js +4 -5
  40. package/dist/SerializationUtilities.js.map +1 -1
  41. package/dist/SharedTree.js +69 -33
  42. package/dist/SharedTree.js.map +1 -1
  43. package/dist/SharedTreeEncoder.js +4 -2
  44. package/dist/SharedTreeEncoder.js.map +1 -1
  45. package/dist/StringInterner.js +2 -2
  46. package/dist/StringInterner.js.map +1 -1
  47. package/dist/Summary.js +1 -2
  48. package/dist/Summary.js.map +1 -1
  49. package/dist/SummaryBackCompatibility.js +2 -3
  50. package/dist/SummaryBackCompatibility.js.map +1 -1
  51. package/dist/SummaryTestUtilities.js +2 -3
  52. package/dist/SummaryTestUtilities.js.map +1 -1
  53. package/dist/Transaction.js +4 -0
  54. package/dist/Transaction.js.map +1 -1
  55. package/dist/TransactionInternal.js +8 -7
  56. package/dist/TransactionInternal.js.map +1 -1
  57. package/dist/TreeCompressor.js +2 -0
  58. package/dist/TreeCompressor.js.map +1 -1
  59. package/dist/TreeNodeHandle.js +2 -0
  60. package/dist/TreeNodeHandle.js.map +1 -1
  61. package/dist/TreeView.js +9 -0
  62. package/dist/TreeView.js.map +1 -1
  63. package/dist/TreeViewUtilities.js +3 -4
  64. package/dist/TreeViewUtilities.js.map +1 -1
  65. package/dist/UndoRedoHandler.js +9 -6
  66. package/dist/UndoRedoHandler.js.map +1 -1
  67. package/dist/UuidUtilities.js +6 -6
  68. package/dist/UuidUtilities.js.map +1 -1
  69. package/dist/id-compressor/AppendOnlySortedMap.js +11 -8
  70. package/dist/id-compressor/AppendOnlySortedMap.js.map +1 -1
  71. package/dist/id-compressor/IdCompressor.js +73 -61
  72. package/dist/id-compressor/IdCompressor.js.map +1 -1
  73. package/dist/id-compressor/IdRange.js +1 -2
  74. package/dist/id-compressor/IdRange.js.map +1 -1
  75. package/dist/id-compressor/NumericUuid.js +7 -8
  76. package/dist/id-compressor/NumericUuid.js.map +1 -1
  77. package/dist/id-compressor/SessionIdNormalizer.js +9 -8
  78. package/dist/id-compressor/SessionIdNormalizer.js.map +1 -1
  79. package/dist/migration-shim/migrationDeltaHandler.js +6 -1
  80. package/dist/migration-shim/migrationDeltaHandler.js.map +1 -1
  81. package/dist/migration-shim/migrationShim.js +46 -30
  82. package/dist/migration-shim/migrationShim.js.map +1 -1
  83. package/dist/migration-shim/migrationShimFactory.js +3 -0
  84. package/dist/migration-shim/migrationShimFactory.js.map +1 -1
  85. package/dist/migration-shim/sharedTreeDeltaHandler.js +3 -1
  86. package/dist/migration-shim/sharedTreeDeltaHandler.js.map +1 -1
  87. package/dist/migration-shim/sharedTreeShim.js +7 -0
  88. package/dist/migration-shim/sharedTreeShim.js.map +1 -1
  89. package/dist/migration-shim/sharedTreeShimFactory.js +1 -0
  90. package/dist/migration-shim/sharedTreeShimFactory.js.map +1 -1
  91. package/dist/migration-shim/shimChannelServices.js +1 -0
  92. package/dist/migration-shim/shimChannelServices.js.map +1 -1
  93. package/dist/migration-shim/shimDeltaConnection.js +6 -1
  94. package/dist/migration-shim/shimDeltaConnection.js.map +1 -1
  95. package/dist/migration-shim/shimHandle.js +1 -0
  96. package/dist/migration-shim/shimHandle.js.map +1 -1
  97. package/dist/migration-shim/utils.js +3 -4
  98. package/dist/migration-shim/utils.js.map +1 -1
  99. package/dist/persisted-types/0.1.1.d.ts.map +1 -1
  100. package/lib/ChangeCompression.js +1 -0
  101. package/lib/ChangeCompression.js.map +1 -1
  102. package/lib/ChangeTypes.d.ts.map +1 -1
  103. package/lib/Checkout.js +28 -1
  104. package/lib/Checkout.js.map +1 -1
  105. package/lib/Common.js +1 -1
  106. package/lib/Common.js.map +1 -1
  107. package/lib/EditLog.d.ts.map +1 -1
  108. package/lib/EditLog.js +12 -8
  109. package/lib/EditLog.js.map +1 -1
  110. package/lib/Forest.js +9 -0
  111. package/lib/Forest.js.map +1 -1
  112. package/lib/LazyCheckout.js +1 -0
  113. package/lib/LazyCheckout.js.map +1 -1
  114. package/lib/LogViewer.js +50 -16
  115. package/lib/LogViewer.js.map +1 -1
  116. package/lib/MergeHealth.js +119 -121
  117. package/lib/MergeHealth.js.map +1 -1
  118. package/lib/RevisionValueCache.js +18 -6
  119. package/lib/RevisionValueCache.js.map +1 -1
  120. package/lib/SharedTree.js +69 -33
  121. package/lib/SharedTree.js.map +1 -1
  122. package/lib/SharedTreeEncoder.js +4 -2
  123. package/lib/SharedTreeEncoder.js.map +1 -1
  124. package/lib/StringInterner.js +2 -2
  125. package/lib/StringInterner.js.map +1 -1
  126. package/lib/Transaction.js +4 -0
  127. package/lib/Transaction.js.map +1 -1
  128. package/lib/TransactionInternal.js +8 -7
  129. package/lib/TransactionInternal.js.map +1 -1
  130. package/lib/TreeCompressor.js +2 -0
  131. package/lib/TreeCompressor.js.map +1 -1
  132. package/lib/TreeNodeHandle.js +2 -0
  133. package/lib/TreeNodeHandle.js.map +1 -1
  134. package/lib/TreeView.js +9 -0
  135. package/lib/TreeView.js.map +1 -1
  136. package/lib/UndoRedoHandler.js +9 -6
  137. package/lib/UndoRedoHandler.js.map +1 -1
  138. package/lib/id-compressor/AppendOnlySortedMap.js +11 -8
  139. package/lib/id-compressor/AppendOnlySortedMap.js.map +1 -1
  140. package/lib/id-compressor/IdCompressor.js +69 -57
  141. package/lib/id-compressor/IdCompressor.js.map +1 -1
  142. package/lib/id-compressor/SessionIdNormalizer.js +9 -8
  143. package/lib/id-compressor/SessionIdNormalizer.js.map +1 -1
  144. package/lib/migration-shim/migrationDeltaHandler.js +6 -1
  145. package/lib/migration-shim/migrationDeltaHandler.js.map +1 -1
  146. package/lib/migration-shim/migrationShim.js +46 -30
  147. package/lib/migration-shim/migrationShim.js.map +1 -1
  148. package/lib/migration-shim/migrationShimFactory.js +3 -0
  149. package/lib/migration-shim/migrationShimFactory.js.map +1 -1
  150. package/lib/migration-shim/sharedTreeDeltaHandler.js +3 -1
  151. package/lib/migration-shim/sharedTreeDeltaHandler.js.map +1 -1
  152. package/lib/migration-shim/sharedTreeShim.js +7 -0
  153. package/lib/migration-shim/sharedTreeShim.js.map +1 -1
  154. package/lib/migration-shim/sharedTreeShimFactory.js +1 -0
  155. package/lib/migration-shim/sharedTreeShimFactory.js.map +1 -1
  156. package/lib/migration-shim/shimChannelServices.js +1 -0
  157. package/lib/migration-shim/shimChannelServices.js.map +1 -1
  158. package/lib/migration-shim/shimDeltaConnection.js +6 -1
  159. package/lib/migration-shim/shimDeltaConnection.js.map +1 -1
  160. package/lib/migration-shim/shimHandle.js +1 -0
  161. package/lib/migration-shim/shimHandle.js.map +1 -1
  162. package/lib/persisted-types/0.1.1.d.ts.map +1 -1
  163. package/package.json +37 -41
  164. package/tsconfig.json +3 -4
@@ -1 +1 @@
1
- {"version":3,"file":"RevisionView.js","sourceRoot":"","sources":["../src/RevisionView.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAGH,2CAA+E;AAC/E,2CAAqC;AAGrC,+CAAqF;AAGrF;;;GAGG;AACH,MAAa,YAAa,SAAQ,sBAAQ;IAmBlC,MAAM,CAAC,QAAQ,CACrB,IAAO,EACP,gCAA4D,EAC5D,mBAAmB,GAAG,KAAK;QAE3B,IAAI,OAAO,gCAAgC,KAAK,QAAQ,EAAE,CAAC;YAC1D,MAAM,MAAM,GAAG,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC,CAAC;YAEjG,MAAM,aAAa,GAAG,2BAA2B,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChE,MAAM,UAAU,GAAG,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC,CAAC;gBACrG,MAAM,QAAQ,GAAG;oBAChB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,UAAU;iBACV,CAAC;gBACF,IAAA,iCAAqB,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,QAAQ,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,kBAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;QACxF,C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MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACtE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC/B,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;wBAC3B,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;oBACpC,CAAC;gBACF,CAAC;qBAAM,CAAC;oBACP,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAdD,0CAcC;AAED,SAAS,kBAAkB,CAAS,QAA2C;IAC9E,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { HasVariadicTraits } from './ChangeTypes.js';\nimport { Mutable, MutableMap, copyPropertyIfDefined, fail } from './Common.js';\nimport { Forest } from './Forest.js';\nimport { NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView, TreeViewNode, TreeViewPlace, TreeViewRange } from './TreeView.js';\nimport { Payload, TreeNode, TreeNodeSequence } from './persisted-types/index.js';\n\n/**\n * An immutable view of a distributed tree.\n * @alpha\n */\nexport class RevisionView extends TreeView {\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the {@link RevisionView}\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the `RevisionView`\n\t * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverter: NodeIdConverter,\n\t\texpensiveValidation?: boolean\n\t): RevisionView;\n\n\tpublic static fromTree<T extends TreeNode<T, NodeId> | TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverterOrExpensiveValidation?: NodeIdConverter | boolean,\n\t\texpensiveValidation = false\n\t): RevisionView {\n\t\tif (typeof idConverterOrExpensiveValidation === 'object') {\n\t\t\tconst rootId = idConverterOrExpensiveValidation.convertToNodeId(root.identifier as StableNodeId);\n\n\t\t\tconst treeViewNodes = convertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\tconst identifier = idConverterOrExpensiveValidation.convertToNodeId(node.identifier as StableNodeId);\n\t\t\t\tconst viewNode = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\treturn viewNode;\n\t\t\t});\n\n\t\t\treturn new RevisionView(rootId, Forest.create(expensiveValidation).add(treeViewNodes));\n\t\t} else {\n\t\t\treturn new RevisionView(\n\t\t\t\troot.identifier as NodeId,\n\t\t\t\tForest.create(expensiveValidation).add(\n\t\t\t\t\tconvertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\t\t\tconst viewNode = {\n\t\t\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\t\t\tidentifier: node.identifier as NodeId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\t\t\treturn viewNode;\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Begin a transaction by generating a mutable `TransactionView` from this view */\n\tpublic openForTransaction(): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest);\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof RevisionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.\n * @alpha\n */\nexport class TransactionView extends TreeView {\n\t/** Conclude a transaction by generating an immutable `RevisionView` from this view */\n\tpublic close(): RevisionView {\n\t\treturn new RevisionView(this.root, this.forest);\n\t}\n\n\t/** Inserts all nodes in a NodeSequence into the view */\n\tpublic addNodes(sequence: Iterable<TreeViewNode>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.add(sequence));\n\t}\n\n\t/** Remove all nodes with the given ids from the view */\n\tpublic deleteNodes(nodes: Iterable<NodeId>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.delete(nodes, true));\n\t}\n\n\t/**\n\t * Parents a set of detached nodes at a specified place.\n\t * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.\n\t * @param place - the location to insert the nodes.\n\t */\n\tpublic attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView {\n\t\tconst { parent, label } = place.trait;\n\t\tconst index = this.findIndexWithinTrait(place);\n\t\treturn new TransactionView(this.root, this.forest.attachRangeOfChildren(parent, label, index, nodesToAttach));\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the view.\n\t * @param rangeToDetach - the range of nodes to detach\n\t */\n\tpublic detachRange(rangeToDetach: TreeViewRange): {\n\t\tview: TransactionView;\n\t\tdetached: readonly NodeId[];\n\t} {\n\t\tconst { start, end } = rangeToDetach;\n\t\tconst { trait: traitLocation } = start;\n\t\tconst { parent, label } = traitLocation;\n\t\tconst startIndex = this.findIndexWithinTrait(start);\n\t\tconst endIndex = this.findIndexWithinTrait(end);\n\t\tconst { forest, detached } = this.forest.detachRangeOfChildren(parent, label, startIndex, endIndex);\n\t\treturn { view: new TransactionView(this.root, forest), detached };\n\t}\n\n\t/**\n\t * Sets or overwrites a node's value. The node must exist in this view.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\tpublic setNodeValue(nodeId: NodeId, value: Payload): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.setValue(nodeId, value));\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof TransactionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'>): TOut[];\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined;\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined {\n\tconst convertedRoot = convert(root) as Mutable<TOut>;\n\tif (convertedRoot === undefined || root.traits === undefined) {\n\t\treturn undefined;\n\t}\n\t// `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`\n\tconst rootTraits = (root as unknown as TOut) === convertedRoot ? { traits: root.traits } : root;\n\tconvertedRoot.traits = new Map();\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\n\tconst resultNodes: TOut[] = [];\n\n\twhile (pendingNodes.length > 0) {\n\t\tconst { childIterator, newNode } = pendingNodes[pendingNodes.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tresultNodes.push(\n\t\t\t\tpendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')\n\t\t\t);\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value;\n\t\t\tconst convertedChild = convert(child) as TOut;\n\t\t\tif (convertedChild === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (child.traits !== undefined) {\n\t\t\t\tconst childTraits = (child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = new Map();\n\t\t\t\tpendingNodes.push({\n\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newTraits = newNode.traits as MutableMap<TOut['traits']>;\n\t\t\tlet newTrait = newTraits.get(traitLabel);\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits.set(traitLabel, newTrait);\n\t\t\t}\n\t\t\t(newTrait as NodeId[]).push(convertedChild.identifier);\n\t\t}\n\t}\n\n\treturn resultNodes;\n}\n\n/**\n * Returns an iterable of the supplied node's traits in a stable order.\n */\nexport function* iterateChildren<T>(hasTraits: HasVariadicTraits<T>): Iterable<[TraitLabel, T]> {\n\tif (hasTraits.traits !== undefined) {\n\t\tfor (const [label, trait] of Object.entries(hasTraits.traits).sort()) {\n\t\t\tif (trait !== undefined) {\n\t\t\t\tif (isTreeNodeSequence(trait)) {\n\t\t\t\t\tfor (const child of trait) {\n\t\t\t\t\t\tyield [label as TraitLabel, child];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tyield [label as TraitLabel, trait];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isTreeNodeSequence<TChild>(sequence: TreeNodeSequence<TChild> | TChild): sequence is TreeNodeSequence<TChild> {\n\treturn Array.isArray(sequence);\n}\n"]}
1
+ {"version":3,"file":"RevisionView.js","sourceRoot":"","sources":["../src/RevisionView.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAkLH,kEAkDC;AAKD,0CAcC;AApPD,2CAA+E;AAC/E,2CAAqC;AAGrC,+CAAqF;AAGrF;;;GAGG;AACH,MAAa,YAAa,SAAQ,sBAAQ;IAmBlC,MAAM,CAAC,QAAQ,CACrB,IAAO,EACP,gCAA4D,EAC5D,mBAAmB,GAAG,KAAK;QAE3B,IAAI,OAAO,gCAAgC,KAAK,QAAQ,EAAE,CAAC;YAC1D,MAAM,MAAM,GAAG,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC,CAAC;YAEjG,MAAM,aAAa,GAAG,2BAA2B,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE;gBAChE,MAAM,UAAU,GAAG,gCAAgC,CAAC,eAAe,CAAC,IAAI,CAAC,UAA0B,CAAC,CAAC;gBACrG,MAAM,QAAQ,GAAG;oBAChB,UAAU,EAAE,IAAI,CAAC,UAAU;oBAC3B,UAAU;iBACV,CAAC;gBACF,IAAA,iCAAqB,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;gBACjD,OAAO,QAAQ,CAAC;YACjB,CAAC,CAAC,CAAC;YAEH,OAAO,IAAI,YAAY,CAAC,MAAM,EAAE,kBAAM,CAAC,MAAM,CAAC,mBA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K,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;YACtE,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;gBACzB,IAAI,kBAAkB,CAAC,KAAK,CAAC,EAAE,CAAC;oBAC/B,KAAK,MAAM,KAAK,IAAI,KAAK,EAAE,CAAC;wBAC3B,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;oBACpC,CAAC;gBACF,CAAC;qBAAM,CAAC;oBACP,MAAM,CAAC,KAAmB,EAAE,KAAK,CAAC,CAAC;gBACpC,CAAC;YACF,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED,SAAS,kBAAkB,CAAS,QAA2C;IAC9E,OAAO,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;AAChC,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { HasVariadicTraits } from './ChangeTypes.js';\nimport { Mutable, MutableMap, copyPropertyIfDefined, fail } from './Common.js';\nimport { Forest } from './Forest.js';\nimport { NodeId, StableNodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView, TreeViewNode, TreeViewPlace, TreeViewRange } from './TreeView.js';\nimport { Payload, TreeNode, TreeNodeSequence } from './persisted-types/index.js';\n\n/**\n * An immutable view of a distributed tree.\n * @alpha\n */\nexport class RevisionView extends TreeView {\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the {@link RevisionView}\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, NodeId>>(root: T, expensiveValidation?: boolean): RevisionView;\n\t/**\n\t * Constructs a {@link RevisionView} using the supplied tree.\n\t * @param root - the root of the tree to use as the contents of the `RevisionView`\n\t * @param idConverter - the {@link NodeIdConverter} that will recompress the IDs the in the tree\n\t * @param expensiveValidation - whether or not to perform additional validation, e.g. to catch errors when testing\n\t */\n\tpublic static fromTree<T extends TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverter: NodeIdConverter,\n\t\texpensiveValidation?: boolean\n\t): RevisionView;\n\n\tpublic static fromTree<T extends TreeNode<T, NodeId> | TreeNode<T, StableNodeId>>(\n\t\troot: T,\n\t\tidConverterOrExpensiveValidation?: NodeIdConverter | boolean,\n\t\texpensiveValidation = false\n\t): RevisionView {\n\t\tif (typeof idConverterOrExpensiveValidation === 'object') {\n\t\t\tconst rootId = idConverterOrExpensiveValidation.convertToNodeId(root.identifier as StableNodeId);\n\n\t\t\tconst treeViewNodes = convertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\tconst identifier = idConverterOrExpensiveValidation.convertToNodeId(node.identifier as StableNodeId);\n\t\t\t\tconst viewNode = {\n\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\tidentifier,\n\t\t\t\t};\n\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\treturn viewNode;\n\t\t\t});\n\n\t\t\treturn new RevisionView(rootId, Forest.create(expensiveValidation).add(treeViewNodes));\n\t\t} else {\n\t\t\treturn new RevisionView(\n\t\t\t\troot.identifier as NodeId,\n\t\t\t\tForest.create(expensiveValidation).add(\n\t\t\t\t\tconvertTreeNodesToViewNodes(root, (node) => {\n\t\t\t\t\t\tconst viewNode = {\n\t\t\t\t\t\t\tdefinition: node.definition,\n\t\t\t\t\t\t\tidentifier: node.identifier as NodeId,\n\t\t\t\t\t\t};\n\t\t\t\t\t\tcopyPropertyIfDefined(node, viewNode, 'payload');\n\t\t\t\t\t\treturn viewNode;\n\t\t\t\t\t})\n\t\t\t\t)\n\t\t\t);\n\t\t}\n\t}\n\n\t/** Begin a transaction by generating a mutable `TransactionView` from this view */\n\tpublic openForTransaction(): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest);\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof RevisionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * An view of a distributed tree that is part of an ongoing transaction between `RevisionView`s.\n * @alpha\n */\nexport class TransactionView extends TreeView {\n\t/** Conclude a transaction by generating an immutable `RevisionView` from this view */\n\tpublic close(): RevisionView {\n\t\treturn new RevisionView(this.root, this.forest);\n\t}\n\n\t/** Inserts all nodes in a NodeSequence into the view */\n\tpublic addNodes(sequence: Iterable<TreeViewNode>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.add(sequence));\n\t}\n\n\t/** Remove all nodes with the given ids from the view */\n\tpublic deleteNodes(nodes: Iterable<NodeId>): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.delete(nodes, true));\n\t}\n\n\t/**\n\t * Parents a set of detached nodes at a specified place.\n\t * @param nodesToAttach - the nodes to parent in the specified place. The nodes must already be present in the view.\n\t * @param place - the location to insert the nodes.\n\t */\n\tpublic attachRange(nodesToAttach: readonly NodeId[], place: TreeViewPlace): TransactionView {\n\t\tconst { parent, label } = place.trait;\n\t\tconst index = this.findIndexWithinTrait(place);\n\t\treturn new TransactionView(this.root, this.forest.attachRangeOfChildren(parent, label, index, nodesToAttach));\n\t}\n\n\t/**\n\t * Detaches a range of nodes from their parent. The detached nodes remain in the view.\n\t * @param rangeToDetach - the range of nodes to detach\n\t */\n\tpublic detachRange(rangeToDetach: TreeViewRange): {\n\t\tview: TransactionView;\n\t\tdetached: readonly NodeId[];\n\t} {\n\t\tconst { start, end } = rangeToDetach;\n\t\tconst { trait: traitLocation } = start;\n\t\tconst { parent, label } = traitLocation;\n\t\tconst startIndex = this.findIndexWithinTrait(start);\n\t\tconst endIndex = this.findIndexWithinTrait(end);\n\t\tconst { forest, detached } = this.forest.detachRangeOfChildren(parent, label, startIndex, endIndex);\n\t\treturn { view: new TransactionView(this.root, forest), detached };\n\t}\n\n\t/**\n\t * Sets or overwrites a node's value. The node must exist in this view.\n\t * @param nodeId - the id of the node\n\t * @param value - the new value\n\t */\n\tpublic setNodeValue(nodeId: NodeId, value: Payload): TransactionView {\n\t\treturn new TransactionView(this.root, this.forest.setValue(nodeId, value));\n\t}\n\n\tpublic equals(view: TreeView): boolean {\n\t\tif (!(view instanceof TransactionView)) {\n\t\t\treturn false;\n\t\t}\n\n\t\treturn this.hasEqualForest(view);\n\t}\n}\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'>): TOut[];\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined;\n\n/**\n * Transform an input tree into a list of {@link TreeViewNode}s.\n * @param tree - the input tree\n * @param convert - a conversion function that will run on each node in the input tree to produce the output nodes.\n * Returning undefined means that conversion for the given node was impossible, at which time the entire tree conversion will be aborted\n * and return undefined.\n */\nexport function convertTreeNodesToViewNodes<\n\tTIn extends HasVariadicTraits<TIn>,\n\tTOut extends TreeViewNode = TreeViewNode,\n>(root: TIn, convert: (node: TIn) => Omit<TOut, 'traits'> | undefined): TOut[] | undefined {\n\tconst convertedRoot = convert(root) as Mutable<TOut>;\n\tif (convertedRoot === undefined || root.traits === undefined) {\n\t\treturn undefined;\n\t}\n\t// `convertedRoot` might be the same as `root`, in which case stash the children of `root` before wiping them from `convertedRoot`\n\tconst rootTraits = (root as unknown as TOut) === convertedRoot ? { traits: root.traits } : root;\n\tconvertedRoot.traits = new Map();\n\tconst pendingNodes: {\n\t\tchildIterator: Iterator<[TraitLabel, TIn]>;\n\t\tnewNode: Mutable<TOut>;\n\t}[] = [{ childIterator: iterateChildren(rootTraits)[Symbol.iterator](), newNode: convertedRoot }];\n\tconst resultNodes: TOut[] = [];\n\n\twhile (pendingNodes.length > 0) {\n\t\tconst { childIterator, newNode } = pendingNodes[pendingNodes.length - 1] ?? fail('Undefined node');\n\t\tconst { value, done } = childIterator.next();\n\t\tif (done === true) {\n\t\t\tresultNodes.push(\n\t\t\t\tpendingNodes.pop()?.newNode ?? fail('covertTreeNodesToViewNodes incorrectly coordinated parentage')\n\t\t\t);\n\t\t} else {\n\t\t\tconst [traitLabel, child] = value;\n\t\t\tconst convertedChild = convert(child) as TOut;\n\t\t\tif (convertedChild === undefined) {\n\t\t\t\treturn undefined;\n\t\t\t}\n\t\t\tif (child.traits !== undefined) {\n\t\t\t\tconst childTraits = (child as unknown as TOut) === convertedChild ? { traits: child.traits } : child;\n\t\t\t\t(convertedChild as Mutable<TOut>).traits = new Map();\n\t\t\t\tpendingNodes.push({\n\t\t\t\t\tchildIterator: iterateChildren(childTraits)[Symbol.iterator](),\n\t\t\t\t\tnewNode: convertedChild,\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst newTraits = newNode.traits as MutableMap<TOut['traits']>;\n\t\t\tlet newTrait = newTraits.get(traitLabel);\n\t\t\tif (newTrait === undefined) {\n\t\t\t\tnewTrait = [];\n\t\t\t\tnewTraits.set(traitLabel, newTrait);\n\t\t\t}\n\t\t\t(newTrait as NodeId[]).push(convertedChild.identifier);\n\t\t}\n\t}\n\n\treturn resultNodes;\n}\n\n/**\n * Returns an iterable of the supplied node's traits in a stable order.\n */\nexport function* iterateChildren<T>(hasTraits: HasVariadicTraits<T>): Iterable<[TraitLabel, T]> {\n\tif (hasTraits.traits !== undefined) {\n\t\tfor (const [label, trait] of Object.entries(hasTraits.traits).sort()) {\n\t\t\tif (trait !== undefined) {\n\t\t\t\tif (isTreeNodeSequence(trait)) {\n\t\t\t\t\tfor (const child of trait) {\n\t\t\t\t\t\tyield [label as TraitLabel, child];\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tyield [label as TraitLabel, trait];\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n\nfunction isTreeNodeSequence<TChild>(sequence: TreeNodeSequence<TChild> | TChild): sequence is TreeNodeSequence<TChild> {\n\treturn Array.isArray(sequence);\n}\n"]}
@@ -4,7 +4,10 @@
4
4
  * Licensed under the MIT License.
5
5
  */
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.getChangeNode_0_0_2FromViewNode = exports.getChangeNode_0_0_2FromView = exports.getChangeNodeFromViewNode = exports.getChangeNodeFromView = void 0;
7
+ exports.getChangeNodeFromView = getChangeNodeFromView;
8
+ exports.getChangeNodeFromViewNode = getChangeNodeFromViewNode;
9
+ exports.getChangeNode_0_0_2FromView = getChangeNode_0_0_2FromView;
10
+ exports.getChangeNode_0_0_2FromViewNode = getChangeNode_0_0_2FromViewNode;
8
11
  const Common_js_1 = require("./Common.js");
9
12
  /**
10
13
  * Converts this tree view to an equivalent `ChangeNode`.
@@ -13,7 +16,6 @@ const Common_js_1 = require("./Common.js");
13
16
  function getChangeNodeFromView(view) {
14
17
  return getChangeNodeFromViewNode(view, view.root);
15
18
  }
16
- exports.getChangeNodeFromView = getChangeNodeFromView;
17
19
  /**
18
20
  * Converts a node in this tree view to an equivalent `ChangeNode`.
19
21
  * @param view - the view of the tree that contains the node to convert
@@ -41,7 +43,6 @@ function getChangeNodeFromViewNode(view, id, lazyTraits = false) {
41
43
  traits: makeTraits(view, node.traits, lazyTraits),
42
44
  };
43
45
  }
44
- exports.getChangeNodeFromViewNode = getChangeNodeFromViewNode;
45
46
  /** Given the traits of a TreeViewNode, return the corresponding traits on a Node */
46
47
  function makeTraits(view, traits, lazyTraits = false) {
47
48
  const traitMap = {};
@@ -72,7 +73,6 @@ function makeTraits(view, traits, lazyTraits = false) {
72
73
  function getChangeNode_0_0_2FromView(view, idConverter) {
73
74
  return getChangeNode_0_0_2FromViewNode(view, view.root, idConverter);
74
75
  }
75
- exports.getChangeNode_0_0_2FromView = getChangeNode_0_0_2FromView;
76
76
  /**
77
77
  * Converts a node in this tree view to an equivalent `ChangeNode`.
78
78
  * @param view - the view of the tree that contains the node to convert
@@ -93,7 +93,6 @@ function getChangeNode_0_0_2FromViewNode(view, id, idConverter) {
93
93
  traits: makeTraits_0_0_2(view, node.traits, idConverter),
94
94
  };
95
95
  }
96
- exports.getChangeNode_0_0_2FromViewNode = getChangeNode_0_0_2FromViewNode;
97
96
  /**
98
97
  * Given the traits of a TreeViewNode, return the corresponding traits on a Node
99
98
  * @deprecated Remove by march 2022
@@ -1 +1 @@
1
- {"version":3,"file":"SerializationUtilities.js","sourceRoot":"","sources":["../src/SerializationUtilities.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,2CAAmE;AAMnE;;;GAGG;AACH,SAAgB,qBAAqB,CAAC,IAAc;IACnD,OAAO,yBAAyB,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;AACnD,CAAC;AAFD,sDAEC;AAED;;;;;;GAMG;AACH,SAAgB,yBAAyB,CAAC,IAAc,EAAE,EAAU,EAAE,UAAU,GAAG,KAAK;IACvF,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG;QAChB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,IAAI,CAAC,UAAU;KAC3B,CAAC;IACF,IAAA,iCAAqB,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEjD,IAAI,UAAU,EAAE,CAAC;QAChB,OAAO;YACN,GAAG,QAAQ;YACX,IA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AED;;;GAGG;AACH,SAAgB,2BAA2B,CAAC,IAAc,EAAE,WAA4B;IACvF,OAAO,+BAA+B,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AACtE,CAAC;AAFD,kEAEC;AAED;;;;;;;GAOG;AACH,SAAgB,+BAA+B,CAC9C,IAAc,EACd,EAAU,EACV,WAA4B;IAE5B,MAAM,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC,CAAC;IAClC,MAAM,QAAQ,GAAG;QAChB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,UAAU,EAAE,WAAW,CAAC,qBAAqB,CAAC,IAAI,CAAC,UAAU,CAAC;KAC9D,CAAC;IACF,IAAA,iCAAqB,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC;IAEjD,OAAO;QACN,GAAG,QAAQ;QACX,MAAM,EAAE,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC;KACxD,CAAC;AACH,CAAC;AAhBD,0EAgBC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACxB,IAAc,EACd,MAAkD,EAClD,WAA4B;IAE5B,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/C,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE;YACtC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,+BAA+B,CAAC,IAAI,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;YAChF,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { copyPropertyIfDefined, memoizeGetter } from './Common.js';\nimport { NodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView } from './TreeView.js';\nimport { ChangeNode, ChangeNode_0_0_2, TraitMap } from './persisted-types/index.js';\n\n/**\n * Converts this tree view to an equivalent `ChangeNode`.\n * @param view - the view to convert\n */\nexport function getChangeNodeFromView(view: TreeView): ChangeNode {\n\treturn getChangeNodeFromViewNode(view, view.root);\n}\n\n/**\n * Converts a node in this tree view to an equivalent `ChangeNode`.\n * @param view - the view of the tree that contains the node to convert\n * @param id - the id of the node to convert\n * @param lazyTraits - whether or not traits should be populated lazily. If true, the subtrees under each trait will not be read until\n * the trait is first accessed.\n */\nexport function getChangeNodeFromViewNode(view: TreeView, id: NodeId, lazyTraits = false): ChangeNode {\n\tconst node = view.getViewNode(id);\n\tconst nodeData = {\n\t\tdefinition: node.definition,\n\t\tidentifier: node.identifier,\n\t};\n\tcopyPropertyIfDefined(node, nodeData, 'payload');\n\n\tif (lazyTraits) {\n\t\treturn {\n\t\t\t...nodeData,\n\t\t\tget traits() {\n\t\t\t\treturn memoizeGetter(this, 'traits', makeTraits(view, node.traits, lazyTraits));\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\t...nodeData,\n\t\ttraits: makeTraits(view, node.traits, lazyTraits),\n\t};\n}\n\n/** Given the traits of a TreeViewNode, return the corresponding traits on a Node */\nfunction makeTraits(\n\tview: TreeView,\n\ttraits: ReadonlyMap<TraitLabel, readonly NodeId[]>,\n\tlazyTraits = false\n): TraitMap<ChangeNode> {\n\tconst traitMap = {};\n\tfor (const [label, trait] of traits.entries()) {\n\t\tif (lazyTraits) {\n\t\t\tObject.defineProperty(traitMap, label, {\n\t\t\t\tget() {\n\t\t\t\t\tconst treeNodeTrait = trait.map((id) => getChangeNodeFromViewNode(view, id, lazyTraits));\n\t\t\t\t\treturn memoizeGetter(this as TraitMap<ChangeNode>, label, treeNodeTrait);\n\t\t\t\t},\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t} else {\n\t\t\tObject.defineProperty(traitMap, label, {\n\t\t\t\tvalue: trait.map((id) => getChangeNodeFromViewNode(view, id, lazyTraits)),\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn traitMap;\n}\n\n/**\n * Converts this tree view to an equivalent `ChangeNode`.\n * @param view - the view to convert\n */\nexport function getChangeNode_0_0_2FromView(view: TreeView, idConverter: NodeIdConverter): ChangeNode_0_0_2 {\n\treturn getChangeNode_0_0_2FromViewNode(view, view.root, idConverter);\n}\n\n/**\n * Converts a node in this tree view to an equivalent `ChangeNode`.\n * @param view - the view of the tree that contains the node to convert\n * @param id - the id of the node to convert\n * @param lazyTraits - whether or not traits should be populated lazily. If true, the subtrees under each trait will not be read until\n * the trait is first accessed.\n * @deprecated Remove by March 2022\n */\nexport function getChangeNode_0_0_2FromViewNode(\n\tview: TreeView,\n\tid: NodeId,\n\tidConverter: NodeIdConverter\n): ChangeNode_0_0_2 {\n\tconst node = view.getViewNode(id);\n\tconst nodeData = {\n\t\tdefinition: node.definition,\n\t\tidentifier: idConverter.convertToStableNodeId(node.identifier),\n\t};\n\tcopyPropertyIfDefined(node, nodeData, 'payload');\n\n\treturn {\n\t\t...nodeData,\n\t\ttraits: makeTraits_0_0_2(view, node.traits, idConverter),\n\t};\n}\n\n/**\n * Given the traits of a TreeViewNode, return the corresponding traits on a Node\n * @deprecated Remove by march 2022\n */\nfunction makeTraits_0_0_2(\n\tview: TreeView,\n\ttraits: ReadonlyMap<TraitLabel, readonly NodeId[]>,\n\tidConverter: NodeIdConverter\n): TraitMap<ChangeNode_0_0_2> {\n\tconst traitMap = {};\n\tfor (const [label, trait] of traits.entries()) {\n\t\tObject.defineProperty(traitMap, label, {\n\t\t\tvalue: trait.map((id) => getChangeNode_0_0_2FromViewNode(view, id, idConverter)),\n\t\t\tenumerable: true,\n\t\t});\n\t}\n\n\treturn traitMap;\n}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M,EAAE,gBAAgB,CAAC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC;KACxD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,SAAS,gBAAgB,CACxB,IAAc,EACd,MAAkD,EAClD,WAA4B;IAE5B,MAAM,QAAQ,GAAG,EAAE,CAAC;IACpB,KAAK,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,EAAE,CAAC;QAC/C,MAAM,CAAC,cAAc,CAAC,QAAQ,EAAE,KAAK,EAAE;YACtC,KAAK,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,+BAA+B,CAAC,IAAI,EAAE,EAAE,EAAE,WAAW,CAAC,CAAC;YAChF,UAAU,EAAE,IAAI;SAChB,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC;AACjB,CAAC","sourcesContent":["/*!\n * Copyright (c) Microsoft Corporation and contributors. All rights reserved.\n * Licensed under the MIT License.\n */\n\nimport { copyPropertyIfDefined, memoizeGetter } from './Common.js';\nimport { NodeId, TraitLabel } from './Identifiers.js';\nimport { NodeIdConverter } from './NodeIdUtilities.js';\nimport { TreeView } from './TreeView.js';\nimport { ChangeNode, ChangeNode_0_0_2, TraitMap } from './persisted-types/index.js';\n\n/**\n * Converts this tree view to an equivalent `ChangeNode`.\n * @param view - the view to convert\n */\nexport function getChangeNodeFromView(view: TreeView): ChangeNode {\n\treturn getChangeNodeFromViewNode(view, view.root);\n}\n\n/**\n * Converts a node in this tree view to an equivalent `ChangeNode`.\n * @param view - the view of the tree that contains the node to convert\n * @param id - the id of the node to convert\n * @param lazyTraits - whether or not traits should be populated lazily. If true, the subtrees under each trait will not be read until\n * the trait is first accessed.\n */\nexport function getChangeNodeFromViewNode(view: TreeView, id: NodeId, lazyTraits = false): ChangeNode {\n\tconst node = view.getViewNode(id);\n\tconst nodeData = {\n\t\tdefinition: node.definition,\n\t\tidentifier: node.identifier,\n\t};\n\tcopyPropertyIfDefined(node, nodeData, 'payload');\n\n\tif (lazyTraits) {\n\t\treturn {\n\t\t\t...nodeData,\n\t\t\tget traits() {\n\t\t\t\treturn memoizeGetter(this, 'traits', makeTraits(view, node.traits, lazyTraits));\n\t\t\t},\n\t\t};\n\t}\n\n\treturn {\n\t\t...nodeData,\n\t\ttraits: makeTraits(view, node.traits, lazyTraits),\n\t};\n}\n\n/** Given the traits of a TreeViewNode, return the corresponding traits on a Node */\nfunction makeTraits(\n\tview: TreeView,\n\ttraits: ReadonlyMap<TraitLabel, readonly NodeId[]>,\n\tlazyTraits = false\n): TraitMap<ChangeNode> {\n\tconst traitMap = {};\n\tfor (const [label, trait] of traits.entries()) {\n\t\tif (lazyTraits) {\n\t\t\tObject.defineProperty(traitMap, label, {\n\t\t\t\tget() {\n\t\t\t\t\tconst treeNodeTrait = trait.map((id) => getChangeNodeFromViewNode(view, id, lazyTraits));\n\t\t\t\t\treturn memoizeGetter(this as TraitMap<ChangeNode>, label, treeNodeTrait);\n\t\t\t\t},\n\t\t\t\tconfigurable: true,\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t} else {\n\t\t\tObject.defineProperty(traitMap, label, {\n\t\t\t\tvalue: trait.map((id) => getChangeNodeFromViewNode(view, id, lazyTraits)),\n\t\t\t\tenumerable: true,\n\t\t\t});\n\t\t}\n\t}\n\n\treturn traitMap;\n}\n\n/**\n * Converts this tree view to an equivalent `ChangeNode`.\n * @param view - the view to convert\n */\nexport function getChangeNode_0_0_2FromView(view: TreeView, idConverter: NodeIdConverter): ChangeNode_0_0_2 {\n\treturn getChangeNode_0_0_2FromViewNode(view, view.root, idConverter);\n}\n\n/**\n * Converts a node in this tree view to an equivalent `ChangeNode`.\n * @param view - the view of the tree that contains the node to convert\n * @param id - the id of the node to convert\n * @param lazyTraits - whether or not traits should be populated lazily. If true, the subtrees under each trait will not be read until\n * the trait is first accessed.\n * @deprecated Remove by March 2022\n */\nexport function getChangeNode_0_0_2FromViewNode(\n\tview: TreeView,\n\tid: NodeId,\n\tidConverter: NodeIdConverter\n): ChangeNode_0_0_2 {\n\tconst node = view.getViewNode(id);\n\tconst nodeData = {\n\t\tdefinition: node.definition,\n\t\tidentifier: idConverter.convertToStableNodeId(node.identifier),\n\t};\n\tcopyPropertyIfDefined(node, nodeData, 'payload');\n\n\treturn {\n\t\t...nodeData,\n\t\ttraits: makeTraits_0_0_2(view, node.traits, idConverter),\n\t};\n}\n\n/**\n * Given the traits of a TreeViewNode, return the corresponding traits on a Node\n * @deprecated Remove by march 2022\n */\nfunction makeTraits_0_0_2(\n\tview: TreeView,\n\ttraits: ReadonlyMap<TraitLabel, readonly NodeId[]>,\n\tidConverter: NodeIdConverter\n): TraitMap<ChangeNode_0_0_2> {\n\tconst traitMap = {};\n\tfor (const [label, trait] of traits.entries()) {\n\t\tObject.defineProperty(traitMap, label, {\n\t\t\tvalue: trait.map((id) => getChangeNode_0_0_2FromViewNode(view, id, idConverter)),\n\t\t\tenumerable: true,\n\t\t});\n\t}\n\n\treturn traitMap;\n}\n"]}
@@ -36,6 +36,15 @@ const publicContracts_js_1 = require("./publicContracts.js");
36
36
  * @alpha
37
37
  */
38
38
  class SharedTreeFactory {
39
+ /**
40
+ * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory."type"}
41
+ */
42
+ static Type = publicContracts_js_1.SharedTreeFactoryType;
43
+ /**
44
+ * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory.attributes}
45
+ */
46
+ static Attributes = publicContracts_js_1.SharedTreeAttributes;
47
+ args;
39
48
  /**
40
49
  * Get a factory for SharedTree to register with the data store.
41
50
  * @param writeFormat - Determines the format version the SharedTree will write ops and summaries in. See {@link https://github.com/microsoft/FluidFramework/blob/main/experimental/dds/tree/docs/Write-Format.md | the write format
@@ -89,14 +98,6 @@ class SharedTreeFactory {
89
98
  }
90
99
  }
91
100
  exports.SharedTreeFactory = SharedTreeFactory;
92
- /**
93
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory."type"}
94
- */
95
- SharedTreeFactory.Type = publicContracts_js_1.SharedTreeFactoryType;
96
- /**
97
- * {@inheritDoc @fluidframework/shared-object-base#ISharedObjectFactory.attributes}
98
- */
99
- SharedTreeFactory.Attributes = publicContracts_js_1.SharedTreeAttributes;
100
101
  /**
101
102
  * Filename where the snapshot is stored.
102
103
  */
@@ -115,6 +116,7 @@ const stashedSessionId = '8477b8d5-cf6c-4673-8345-8f076a8f9bc6';
115
116
  * @alpha
116
117
  */
117
118
  class SharedTree extends internal_2.SharedObject {
119
+ writeFormat;
118
120
  /**
119
121
  * Create a new SharedTree. It will contain the default value (see initialTree).
120
122
  */
@@ -148,12 +150,71 @@ class SharedTree extends internal_2.SharedObject {
148
150
  }
149
151
  }
150
152
  }
153
+ /**
154
+ * This is SharedTree's internal IdCompressor that predates the one in the runtime. If access
155
+ * to the IdCompressor is needed, this is the one that should be used.
156
+ */
157
+ idCompressor;
158
+ idNormalizer = {
159
+ tree: this,
160
+ get localSessionId() {
161
+ return this.tree.idCompressor.localSessionId;
162
+ },
163
+ normalizeToOpSpace: (id) => this.idCompressor.normalizeToOpSpace(id),
164
+ normalizeToSessionSpace: (id, sessionId) => this.idCompressor.normalizeToSessionSpace(id, sessionId),
165
+ };
166
+ /** Temporarily created to apply stashed ops from a previous session */
167
+ stashedIdCompressor;
168
+ // The initial tree's definition isn't included in any op by default but it should still be interned. Including it here ensures that.
169
+ interner = new StringInterner_js_1.MutableStringInterner([InitialTree_js_1.initialTree.definition]);
170
+ /**
171
+ * The log of completed edits for this SharedTree.
172
+ */
173
+ editLog;
174
+ editLogSize;
175
+ editEvictionFrequency;
176
+ /**
177
+ * As an implementation detail, SharedTree uses a log viewer that caches views of different revisions.
178
+ * It is not exposed to avoid accidental correctness issues, but `logViewer` is exposed in order to give clients a way
179
+ * to access the revision history.
180
+ */
181
+ cachingLogViewer;
151
182
  /**
152
183
  * Viewer for trees defined by editLog. This allows access to views of the tree at different revisions (various points in time).
153
184
  */
154
185
  get logViewer() {
155
186
  return this.cachingLogViewer;
156
187
  }
188
+ /**
189
+ * logger for SharedTree events.
190
+ */
191
+ logger;
192
+ /**
193
+ * Internal and only viable logger for SharedTree events.
194
+ * @privateRemarks
195
+ * `logger` is public and remains typed for external use with mostly deprecated methods.
196
+ * Internally, only loggerInternal should be used and it provides the full set of logging methods.
197
+ */
198
+ loggerInternal;
199
+ sequencedEditAppliedLogger;
200
+ encoder_0_0_2;
201
+ encoder_0_1_1;
202
+ processEditResult = (editResult, editId) => {
203
+ // TODO:#44859: Invalid results should be handled by the app
204
+ this.emit(SharedTree.eventFromEditResult(editResult), editId);
205
+ };
206
+ processSequencedEditResult = ({ edit, wasLocal, result, reconciliationPath, }) => {
207
+ const eventArguments = {
208
+ edit,
209
+ wasLocal,
210
+ tree: this,
211
+ logger: this.sequencedEditAppliedLogger,
212
+ reconciliationPath,
213
+ outcome: result,
214
+ };
215
+ this.emit(EventTypes_js_1.SharedTreeEvent.SequencedEditApplied, eventArguments);
216
+ };
217
+ summarizeHistory;
157
218
  getHistoryPolicy(options) {
158
219
  const noCompatOptions = options;
159
220
  return typeof noCompatOptions.summarizeHistory === 'object'
@@ -167,31 +228,6 @@ class SharedTree extends internal_2.SharedObject {
167
228
  constructor(runtime, id, writeFormat, options = {}) {
168
229
  super(id, runtime, SharedTreeFactory.Attributes, 'fluid_legacySharedTree_');
169
230
  this.writeFormat = writeFormat;
170
- this.idNormalizer = {
171
- tree: this,
172
- get localSessionId() {
173
- return this.tree.idCompressor.localSessionId;
174
- },
175
- normalizeToOpSpace: (id) => this.idCompressor.normalizeToOpSpace(id),
176
- normalizeToSessionSpace: (id, sessionId) => this.idCompressor.normalizeToSessionSpace(id, sessionId),
177
- };
178
- // The initial tree's definition isn't included in any op by default but it should still be interned. Including it here ensures that.
179
- this.interner = new StringInterner_js_1.MutableStringInterner([InitialTree_js_1.initialTree.definition]);
180
- this.processEditResult = (editResult, editId) => {
181
- // TODO:#44859: Invalid results should be handled by the app
182
- this.emit(SharedTree.eventFromEditResult(editResult), editId);
183
- };
184
- this.processSequencedEditResult = ({ edit, wasLocal, result, reconciliationPath, }) => {
185
- const eventArguments = {
186
- edit,
187
- wasLocal,
188
- tree: this,
189
- logger: this.sequencedEditAppliedLogger,
190
- reconciliationPath,
191
- outcome: result,
192
- };
193
- this.emit(EventTypes_js_1.SharedTreeEvent.SequencedEditApplied, eventArguments);
194
- };
195
231
  const historyPolicy = this.getHistoryPolicy(options);
196
232
  this.summarizeHistory = historyPolicy.summarizeHistory;
197
233
  this.loggerInternal = (0, internal_3.createChildLogger)({